Skip to content

Commit

Permalink
fix: add optional parameter to HTTPSend timelineObj: paramsType
Browse files Browse the repository at this point in the history
Used to allow request-body to be either in "json" or "form" type. ref: https://github.com/sindresorhus/got/blob/main/documentation/2-options.md#json
  • Loading branch information
nytamin committed Nov 10, 2022
1 parent 8315531 commit 979dc61
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
6 changes: 6 additions & 0 deletions packages/timeline-state-resolver-types/src/httpSend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ export interface HTTPSendCommandContent {
type: TimelineContentTypeHTTP
url: string
params: { [key: string]: number | string | any }
/** How the params are sent. Ignored for GET since params are sent in querystring. Default is JSON. */
paramsType?: TimelineContentTypeHTTPParamType
temporalPriority?: number // default: 0
/** Commands in the same queue will be sent in order (will wait for the previous to finish before sending next */
queueId?: string
Expand All @@ -28,6 +30,10 @@ export enum TimelineContentTypeHTTP {
PUT = 'put',
DELETE = 'delete',
}
export enum TimelineContentTypeHTTPParamType {
JSON = 'json',
FORM = 'form',
}

export type TimelineObjHTTPSendAny = TimelineObjHTTPRequest
export interface TimelineObjHTTPSendBase extends TSRTimelineObjBase {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
DeviceOptionsHTTPSend,
Mappings,
TimelineContentTypeHTTP,
TimelineContentTypeHTTPParamType
} from 'timeline-state-resolver-types'
import { DoOnTime, SendMode } from '../../devices/doOnTime'
import got, { OptionsOfTextResponseBody, RequestError } from 'got'
Expand Down Expand Up @@ -264,7 +265,13 @@ export class HTTPSendDevice extends DeviceWithState<HTTPSendState, DeviceOptions
if (cmd.type === TimelineContentTypeHTTP.GET) {
options.searchParams = params
} else {
options.json = params
if (cmd.paramsType === TimelineContentTypeHTTPParamType.FORM) {
options.form = params
} else {
// Default is json:
options.json = params
}

}
}

Expand Down

0 comments on commit 979dc61

Please sign in to comment.