@useparagon/core 0.0.1-canary.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +63 -0
- package/src/event/event.interface.ts +18 -0
- package/src/event/index.ts +1 -0
- package/src/execution/context.constants.ts +9 -0
- package/src/execution/context.interface.ts +39 -0
- package/src/execution/context.ts +72 -0
- package/src/execution/context.utils.ts +53 -0
- package/src/execution/index.ts +2 -0
- package/src/index.ts +6 -0
- package/src/integration/custom-integration.interface.ts +20 -0
- package/src/integration/index.ts +2 -0
- package/src/integration/integration-config.interface.ts +19 -0
- package/src/integration/integration.interface.ts +16 -0
- package/src/operator/index.ts +2 -0
- package/src/operator/operator.interface.ts +6 -0
- package/src/operator/operators/BooleanTrue.ts +20 -0
- package/src/operator/operators/StringContains.ts +27 -0
- package/src/resolvers/index.ts +2 -0
- package/src/resolvers/resolver.utils.ts +157 -0
- package/src/resolvers/resolvers.interface.ts +369 -0
- package/src/secret/index.ts +1 -0
- package/src/secret/secret.interface.ts +4 -0
- package/src/stateMachine/index.ts +2 -0
- package/src/stateMachine/stateMachine.constants.ts +12 -0
- package/src/stateMachine/stateMachine.interface.ts +145 -0
- package/src/stateMachine/stateMachine.utils.ts +733 -0
- package/src/steps/index.ts +3 -0
- package/src/steps/library/action/action.interface.ts +69 -0
- package/src/steps/library/action/action.step.ts +70 -0
- package/src/steps/library/action/index.ts +2 -0
- package/src/steps/library/conditional/conditional.interface.ts +82 -0
- package/src/steps/library/conditional/conditional.step.ts +96 -0
- package/src/steps/library/conditional/conditional.utils.ts +110 -0
- package/src/steps/library/conditional/index.ts +2 -0
- package/src/steps/library/delay/delay.interface.ts +71 -0
- package/src/steps/library/delay/delay.step.ts +51 -0
- package/src/steps/library/delay/index.ts +2 -0
- package/src/steps/library/fanout/fanout.interface.ts +46 -0
- package/src/steps/library/fanout/fanout.step.ts +68 -0
- package/src/steps/library/fanout/index.ts +2 -0
- package/src/steps/library/function/function.interface.ts +69 -0
- package/src/steps/library/function/function.step.ts +55 -0
- package/src/steps/library/function/index.ts +2 -0
- package/src/steps/library/index.ts +7 -0
- package/src/steps/library/integrationRequest/index.ts +2 -0
- package/src/steps/library/integrationRequest/integrationRequest.interface.ts +79 -0
- package/src/steps/library/integrationRequest/integrationRequest.step.ts +100 -0
- package/src/steps/library/request/index.ts +2 -0
- package/src/steps/library/request/request.interface.ts +159 -0
- package/src/steps/library/request/request.step.ts +117 -0
- package/src/steps/library/response/index.ts +2 -0
- package/src/steps/library/response/response.interface.ts +50 -0
- package/src/steps/library/response/response.step.ts +68 -0
- package/src/steps/step.constants.ts +4 -0
- package/src/steps/step.interface-base.ts +81 -0
- package/src/steps/step.interface.ts +31 -0
- package/src/steps/step.ts +136 -0
- package/src/steps/step.utils.ts +103 -0
- package/src/triggers/cron/cron.interface.ts +94 -0
- package/src/triggers/cron/cron.step.ts +52 -0
- package/src/triggers/cron/cron.utils.ts +117 -0
- package/src/triggers/cron/index.ts +3 -0
- package/src/triggers/endpoint/endpoint.interface.ts +66 -0
- package/src/triggers/endpoint/endpoint.step.ts +61 -0
- package/src/triggers/endpoint/index.ts +2 -0
- package/src/triggers/event/event.interface.ts +43 -0
- package/src/triggers/event/event.step.ts +41 -0
- package/src/triggers/event/index.ts +2 -0
- package/src/triggers/index.ts +4 -0
- package/src/triggers/integrationEnabled/index.ts +2 -0
- package/src/triggers/integrationEnabled/integrationEnabled.interface.ts +29 -0
- package/src/triggers/integrationEnabled/integrationEnabled.step.ts +33 -0
- package/src/triggers/trigger.interface.ts +28 -0
- package/src/triggers/trigger.ts +25 -0
- package/src/user/index.ts +2 -0
- package/src/user/user.interface.ts +4 -0
- package/src/user/user.ts +6 -0
- package/src/utils/index.ts +1 -0
- package/src/utils/utils.ts +10 -0
- package/src/workflow/index.ts +2 -0
- package/src/workflow/workflow.interface.ts +50 -0
- package/src/workflow/workflow.ts +132 -0
- package/tsconfig.json +9 -0
- package/tsconfig.release.json +8 -0
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { KeyedSource } from '../../../resolvers/resolvers.interface';
|
|
2
|
+
import {
|
|
3
|
+
IBaseStep,
|
|
4
|
+
IBaseStepParameters,
|
|
5
|
+
StepType,
|
|
6
|
+
} from '../../step.interface-base';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* parameters used for initializing a FunctionStep
|
|
10
|
+
*/
|
|
11
|
+
export interface IFunctionStepParameters extends IBaseStepParameters {
|
|
12
|
+
/**
|
|
13
|
+
* the code executed within the function
|
|
14
|
+
*/
|
|
15
|
+
code: string;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* parameters passed to the function
|
|
19
|
+
*/
|
|
20
|
+
parameters: KeyedSource[];
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* whether or not to retry on failure
|
|
24
|
+
*/
|
|
25
|
+
retryOnFailure?: boolean;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* parameters used to initialize a function step
|
|
30
|
+
*/
|
|
31
|
+
export interface IFunctionStepInit<
|
|
32
|
+
P extends Record<string, unknown> = Record<string, unknown>,
|
|
33
|
+
> extends IBaseStepParameters {
|
|
34
|
+
/**
|
|
35
|
+
* the code executed within the function
|
|
36
|
+
* @param parameters variables passed to the function
|
|
37
|
+
* @param libraries npm libraries
|
|
38
|
+
* @returns
|
|
39
|
+
*/
|
|
40
|
+
code: (
|
|
41
|
+
parameters: P,
|
|
42
|
+
libraries: Record<string, unknown>,
|
|
43
|
+
) => any | Promise<any>;
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* parameters passed to the function
|
|
47
|
+
*/
|
|
48
|
+
parameters: P;
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* whether or not to retry on failure
|
|
52
|
+
*/
|
|
53
|
+
retryOnFailure?: boolean;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* a step used for sending responses to HTTP requests
|
|
58
|
+
*/
|
|
59
|
+
export interface IFunctionStep extends IBaseStep {
|
|
60
|
+
/**
|
|
61
|
+
* the step type
|
|
62
|
+
*/
|
|
63
|
+
type: StepType.FUNCTION;
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* configuration for the function step
|
|
67
|
+
*/
|
|
68
|
+
parameters: IFunctionStepParameters;
|
|
69
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { resolveParamsToSources } from '../../../resolvers/resolver.utils';
|
|
2
|
+
import { Step } from '../../step';
|
|
3
|
+
import { StepType } from '../../step.interface';
|
|
4
|
+
import {
|
|
5
|
+
IFunctionStep,
|
|
6
|
+
IFunctionStepInit,
|
|
7
|
+
IFunctionStepParameters,
|
|
8
|
+
} from './function.interface';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* a step used for executiong custom Node.js code
|
|
12
|
+
*/
|
|
13
|
+
export class FunctionStep<
|
|
14
|
+
P extends Record<string, unknown> = Record<string, unknown>,
|
|
15
|
+
>
|
|
16
|
+
extends Step<IFunctionStepInit<P>, IFunctionStepParameters>
|
|
17
|
+
implements IFunctionStep
|
|
18
|
+
{
|
|
19
|
+
/**
|
|
20
|
+
* the step type
|
|
21
|
+
*
|
|
22
|
+
* @type {StepType}
|
|
23
|
+
* @memberof Step
|
|
24
|
+
*/
|
|
25
|
+
type: StepType.FUNCTION = StepType.FUNCTION;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* configuration for the function step
|
|
29
|
+
*/
|
|
30
|
+
parameters: IFunctionStepParameters;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* initialization parameters
|
|
34
|
+
*/
|
|
35
|
+
private _parameters: IFunctionStepInit<P>;
|
|
36
|
+
|
|
37
|
+
constructor(params: IFunctionStepInit<P>) {
|
|
38
|
+
super(params);
|
|
39
|
+
this._parameters = params;
|
|
40
|
+
this.parameters = this.serializeParameters();
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* serialize parameters for storage
|
|
45
|
+
*/
|
|
46
|
+
serializeParameters(): IFunctionStepParameters {
|
|
47
|
+
const functionParameters = this._parameters.parameters;
|
|
48
|
+
|
|
49
|
+
return {
|
|
50
|
+
...this._parameters,
|
|
51
|
+
parameters: resolveParamsToSources(functionParameters),
|
|
52
|
+
code: this._parameters.code.toString(),
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export * from './action/action.step';
|
|
2
|
+
export * from './conditional/conditional.step';
|
|
3
|
+
export * from './fanout/fanout.step';
|
|
4
|
+
export * from './function/function.step';
|
|
5
|
+
export * from './request/request.step';
|
|
6
|
+
export * from './response/response.step';
|
|
7
|
+
export * from './integrationRequest/integrationRequest.step';
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import {
|
|
2
|
+
DataType,
|
|
3
|
+
OrConditions,
|
|
4
|
+
TokenizedSource,
|
|
5
|
+
} from '../../../resolvers/resolvers.interface';
|
|
6
|
+
import {
|
|
7
|
+
IBaseStep,
|
|
8
|
+
IBaseStepParameters,
|
|
9
|
+
StepType,
|
|
10
|
+
} from '../../step.interface-base';
|
|
11
|
+
import { ConditionalInput } from '../conditional/conditional.interface';
|
|
12
|
+
import {
|
|
13
|
+
HttpMethod,
|
|
14
|
+
IRequestStepParameters,
|
|
15
|
+
} from '../request/request.interface';
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* parameters for initializing request step
|
|
19
|
+
*/
|
|
20
|
+
export type IIntegrationRequestStepInit = IBaseStepParameters & {
|
|
21
|
+
path: string;
|
|
22
|
+
method: keyof typeof HttpMethod;
|
|
23
|
+
params?: Record<string, string>;
|
|
24
|
+
headers?: Record<string, string>;
|
|
25
|
+
pagination?: {
|
|
26
|
+
stopCondition: ConditionalInput;
|
|
27
|
+
outputPath: string;
|
|
28
|
+
pageToken: string;
|
|
29
|
+
};
|
|
30
|
+
} & (
|
|
31
|
+
| {
|
|
32
|
+
/**
|
|
33
|
+
* Specify the kind of format that the `body` object should be transmitted in. Affects the
|
|
34
|
+
* Content-Type header, if it isn't already set.
|
|
35
|
+
*/
|
|
36
|
+
bodyType?: 'json' | 'form-data' | 'x-www-form-urlencoded';
|
|
37
|
+
body?: Record<string, unknown>;
|
|
38
|
+
}
|
|
39
|
+
| {
|
|
40
|
+
bodyType?: 'xml' | 'raw';
|
|
41
|
+
body?: string;
|
|
42
|
+
}
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* pagination options for integration
|
|
47
|
+
*/
|
|
48
|
+
export type PaginationOptions = Partial<{
|
|
49
|
+
enabled: boolean;
|
|
50
|
+
type: 'TOKEN';
|
|
51
|
+
output: TokenizedSource<DataType.STRING | DataType.ANY>;
|
|
52
|
+
pageToken: TokenizedSource<DataType.STRING>;
|
|
53
|
+
stopCondition: OrConditions;
|
|
54
|
+
}>;
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* parameters used for initializing a RequestStep
|
|
58
|
+
*/
|
|
59
|
+
export interface IIntegrationRequestStepParameters
|
|
60
|
+
extends IRequestStepParameters {
|
|
61
|
+
paginations?: PaginationOptions;
|
|
62
|
+
|
|
63
|
+
actionType: string;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* a step used for making HTTP requests in integration
|
|
68
|
+
*/
|
|
69
|
+
export interface IIntegrationRequestStep extends IBaseStep {
|
|
70
|
+
/**
|
|
71
|
+
* the step type
|
|
72
|
+
*/
|
|
73
|
+
type: StepType.CUSTOM_INTEGRATION_REQUEST;
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* configuration for the request step
|
|
77
|
+
*/
|
|
78
|
+
parameters: IIntegrationRequestStepParameters;
|
|
79
|
+
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import {
|
|
2
|
+
resolveParamsToSources,
|
|
3
|
+
resolveToSource,
|
|
4
|
+
} from '../../../resolvers/resolver.utils';
|
|
5
|
+
import {
|
|
6
|
+
DataType,
|
|
7
|
+
OrConditions,
|
|
8
|
+
TokenizedSource,
|
|
9
|
+
} from '../../../resolvers/resolvers.interface';
|
|
10
|
+
import { Step } from '../../step';
|
|
11
|
+
import { StepType } from '../../step.interface';
|
|
12
|
+
import { HttpMethod, RequestBodyType } from '../request/request.interface';
|
|
13
|
+
import {
|
|
14
|
+
IIntegrationRequestStepInit,
|
|
15
|
+
IIntegrationRequestStepParameters,
|
|
16
|
+
IIntegrationRequestStep,
|
|
17
|
+
} from './integrationRequest.interface';
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* a step used for making HTTP requests in integaration
|
|
21
|
+
*/
|
|
22
|
+
export class IntegrationRequestStep
|
|
23
|
+
extends Step
|
|
24
|
+
implements IIntegrationRequestStep
|
|
25
|
+
{
|
|
26
|
+
/**
|
|
27
|
+
* the step type
|
|
28
|
+
* @type {StepType}
|
|
29
|
+
* @memberof Step
|
|
30
|
+
*/
|
|
31
|
+
type: StepType.CUSTOM_INTEGRATION_REQUEST =
|
|
32
|
+
StepType.CUSTOM_INTEGRATION_REQUEST;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* initialization parameters
|
|
36
|
+
*/
|
|
37
|
+
private _parameters: IIntegrationRequestStepInit;
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* configuraiton for the integration request step
|
|
41
|
+
*/
|
|
42
|
+
parameters: IIntegrationRequestStepParameters;
|
|
43
|
+
|
|
44
|
+
constructor(params: IIntegrationRequestStepInit) {
|
|
45
|
+
super(params);
|
|
46
|
+
this._parameters = params;
|
|
47
|
+
this.parameters = this.serializeParameters();
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* serialize parameters for storage
|
|
52
|
+
*/
|
|
53
|
+
serializeParameters(): IIntegrationRequestStepParameters {
|
|
54
|
+
const initParams: IIntegrationRequestStepInit = this._parameters;
|
|
55
|
+
|
|
56
|
+
return {
|
|
57
|
+
actionType: 'pipedrive',
|
|
58
|
+
bodyType: initParams.bodyType as RequestBodyType,
|
|
59
|
+
httpMethod: initParams.method as HttpMethod,
|
|
60
|
+
url: resolveToSource(
|
|
61
|
+
initParams.url,
|
|
62
|
+
DataType.STRING,
|
|
63
|
+
) as TokenizedSource<DataType.STRING>,
|
|
64
|
+
params: resolveParamsToSources(initParams.params || {}, DataType.STRING),
|
|
65
|
+
headers: resolveParamsToSources(
|
|
66
|
+
initParams.headers || {},
|
|
67
|
+
DataType.STRING,
|
|
68
|
+
),
|
|
69
|
+
body:
|
|
70
|
+
typeof initParams.body === 'string'
|
|
71
|
+
? []
|
|
72
|
+
: resolveParamsToSources(initParams.body || {}, DataType.STRING),
|
|
73
|
+
rawBody:
|
|
74
|
+
typeof initParams.body === 'string'
|
|
75
|
+
? (resolveToSource(
|
|
76
|
+
initParams.body || '',
|
|
77
|
+
DataType.STRING,
|
|
78
|
+
) as TokenizedSource<DataType.STRING>)
|
|
79
|
+
: undefined,
|
|
80
|
+
paginations: initParams.pagination
|
|
81
|
+
? {
|
|
82
|
+
enabled: true,
|
|
83
|
+
type: 'TOKEN',
|
|
84
|
+
output: resolveToSource(
|
|
85
|
+
initParams.pagination.outputPath,
|
|
86
|
+
DataType.ANY,
|
|
87
|
+
) as TokenizedSource<DataType.STRING | DataType.ANY>,
|
|
88
|
+
pageToken: resolveToSource(
|
|
89
|
+
initParams.pagination.pageToken,
|
|
90
|
+
DataType.ANY,
|
|
91
|
+
) as TokenizedSource<DataType.STRING>,
|
|
92
|
+
stopCondition: resolveToSource(
|
|
93
|
+
initParams.pagination.stopCondition,
|
|
94
|
+
DataType.ANY,
|
|
95
|
+
)['condition'] as OrConditions,
|
|
96
|
+
}
|
|
97
|
+
: undefined,
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
}
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import {
|
|
2
|
+
DataType,
|
|
3
|
+
KeyedSource,
|
|
4
|
+
TokenizedSource,
|
|
5
|
+
} from '../../../resolvers/resolvers.interface';
|
|
6
|
+
import {
|
|
7
|
+
IBaseStep,
|
|
8
|
+
IBaseStepParameters,
|
|
9
|
+
StepType,
|
|
10
|
+
} from '../../step.interface-base';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* methods for HTTP requests
|
|
14
|
+
*/
|
|
15
|
+
export enum HttpMethod {
|
|
16
|
+
GET = 'GET',
|
|
17
|
+
POST = 'POST',
|
|
18
|
+
PUT = 'PUT',
|
|
19
|
+
PATCH = 'PATCH',
|
|
20
|
+
DELETE = 'DELETE',
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* request body type
|
|
25
|
+
*/
|
|
26
|
+
export enum RequestBodyType {
|
|
27
|
+
JSON = 'json',
|
|
28
|
+
FORM_DATA = 'form-data',
|
|
29
|
+
X_WWW_FORM_URLENCODED = 'x-www-form-urlencoded',
|
|
30
|
+
XML = 'xml',
|
|
31
|
+
RAW = 'raw',
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Specify the kind of request authorization that this request should use. Affects the
|
|
36
|
+
* Authorization header value.
|
|
37
|
+
*/
|
|
38
|
+
export enum RequestAuthorizationType {
|
|
39
|
+
NONE = 'none',
|
|
40
|
+
BEARER_TOKEN = 'bearer',
|
|
41
|
+
BASIC = 'basic',
|
|
42
|
+
QUERY_PARAMS = 'query_params',
|
|
43
|
+
AUTH_HEADER = 'auth_header',
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
type NoAuthorization = {
|
|
47
|
+
type: RequestAuthorizationType.NONE;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
type BearerAuthorization = {
|
|
51
|
+
type: RequestAuthorizationType.BEARER_TOKEN;
|
|
52
|
+
token: TokenizedSource<DataType.STRING>;
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
type BasicAuthorization = {
|
|
56
|
+
type: RequestAuthorizationType.BASIC;
|
|
57
|
+
username: TokenizedSource<DataType.STRING>;
|
|
58
|
+
password: TokenizedSource<DataType.STRING>;
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
type QueryParamAuthorization = {
|
|
62
|
+
type: RequestAuthorizationType.QUERY_PARAMS;
|
|
63
|
+
params: KeyedSource<DataType.STRING>[];
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
type AuthHeaderAuthorization = {
|
|
67
|
+
type: RequestAuthorizationType.AUTH_HEADER;
|
|
68
|
+
headers: KeyedSource<DataType.STRING>[];
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* parameters for initializing request step
|
|
73
|
+
*/
|
|
74
|
+
export type IRequestStepInit = IBaseStepParameters & {
|
|
75
|
+
url: string;
|
|
76
|
+
method: keyof typeof HttpMethod;
|
|
77
|
+
params?: Record<string, string>;
|
|
78
|
+
headers?: Record<string, string>;
|
|
79
|
+
/**
|
|
80
|
+
* An object to represent Authorization options in a request step
|
|
81
|
+
*/
|
|
82
|
+
authorization?:
|
|
83
|
+
| {
|
|
84
|
+
type: 'basic';
|
|
85
|
+
username: string;
|
|
86
|
+
password: string;
|
|
87
|
+
}
|
|
88
|
+
| {
|
|
89
|
+
type: 'bearer';
|
|
90
|
+
token: string;
|
|
91
|
+
};
|
|
92
|
+
} & (
|
|
93
|
+
| {
|
|
94
|
+
/**
|
|
95
|
+
* Specify the kind of format that the `body` object should be transmitted in. Affects the
|
|
96
|
+
* Content-Type header, if it isn't already set.
|
|
97
|
+
*/
|
|
98
|
+
bodyType?: 'json' | 'form-data' | 'x-www-form-urlencoded';
|
|
99
|
+
body?: Record<string, unknown>;
|
|
100
|
+
}
|
|
101
|
+
| {
|
|
102
|
+
bodyType?: 'xml' | 'raw';
|
|
103
|
+
body?: string;
|
|
104
|
+
}
|
|
105
|
+
);
|
|
106
|
+
|
|
107
|
+
export type RequestAuthorization =
|
|
108
|
+
| NoAuthorization
|
|
109
|
+
| BearerAuthorization
|
|
110
|
+
| BasicAuthorization
|
|
111
|
+
| QueryParamAuthorization
|
|
112
|
+
| AuthHeaderAuthorization;
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* parameters used for initializing a RequestStep
|
|
116
|
+
*/
|
|
117
|
+
export interface IRequestStepParameters extends IBaseStepParameters {
|
|
118
|
+
url: TokenizedSource<DataType.STRING>;
|
|
119
|
+
httpMethod: HttpMethod;
|
|
120
|
+
params: KeyedSource<DataType.STRING>[];
|
|
121
|
+
headers: KeyedSource<DataType.STRING>[];
|
|
122
|
+
body: KeyedSource[];
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Specify the kind of format that the `body` object should be transmitted in. Affects the
|
|
126
|
+
* Content-Type header, if it isn't already set.
|
|
127
|
+
*/
|
|
128
|
+
bodyType?: RequestBodyType;
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* If a bodyType is RequestBodyType.RAW, rawBody represents the raw contents to pass through
|
|
132
|
+
* to the body of the request.
|
|
133
|
+
* @since PARA-1969
|
|
134
|
+
*/
|
|
135
|
+
rawBody?: TokenizedSource<DataType.STRING>;
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* An object to represent Authorization options in a request step.
|
|
139
|
+
* - For Basic-type auth, "username" and "password" keys should appear in
|
|
140
|
+
* this object.
|
|
141
|
+
* - For Bearer-type auth, a "token" key should appear in this object.
|
|
142
|
+
*/
|
|
143
|
+
authorization?: RequestAuthorization;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* a step used for making HTTP requests
|
|
148
|
+
*/
|
|
149
|
+
export interface IRequestStep extends IBaseStep {
|
|
150
|
+
/**
|
|
151
|
+
* the step type
|
|
152
|
+
*/
|
|
153
|
+
type: StepType.REQUEST;
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* configuration for the request step
|
|
157
|
+
*/
|
|
158
|
+
parameters: IRequestStepParameters;
|
|
159
|
+
}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import {
|
|
2
|
+
resolveParamsToSources,
|
|
3
|
+
resolveToSource,
|
|
4
|
+
} from '../../../resolvers/resolver.utils';
|
|
5
|
+
import {
|
|
6
|
+
DataType,
|
|
7
|
+
TokenizedSource,
|
|
8
|
+
} from '../../../resolvers/resolvers.interface';
|
|
9
|
+
import { Step } from '../../step';
|
|
10
|
+
import { StepType } from '../../step.interface';
|
|
11
|
+
import {
|
|
12
|
+
HttpMethod,
|
|
13
|
+
IRequestStep,
|
|
14
|
+
IRequestStepInit,
|
|
15
|
+
IRequestStepParameters,
|
|
16
|
+
RequestAuthorization,
|
|
17
|
+
RequestAuthorizationType,
|
|
18
|
+
RequestBodyType,
|
|
19
|
+
} from './request.interface';
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* a step used for making HTTP requests
|
|
23
|
+
*/
|
|
24
|
+
export class RequestStep extends Step implements IRequestStep {
|
|
25
|
+
/**
|
|
26
|
+
* the step type
|
|
27
|
+
* @type {StepType}
|
|
28
|
+
* @memberof Step
|
|
29
|
+
*/
|
|
30
|
+
type: StepType.REQUEST = StepType.REQUEST;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* initialization parameters
|
|
34
|
+
* @type {IRequestStepInit}
|
|
35
|
+
* @memberof RequestStep
|
|
36
|
+
*/
|
|
37
|
+
private _parameters: IRequestStepInit;
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* configuraiton for the request step
|
|
41
|
+
*
|
|
42
|
+
* @type {IRequestStepParameters}
|
|
43
|
+
* @memberof RequestStep
|
|
44
|
+
*/
|
|
45
|
+
parameters: IRequestStepParameters;
|
|
46
|
+
|
|
47
|
+
constructor(params: IRequestStepInit) {
|
|
48
|
+
super(params);
|
|
49
|
+
this._parameters = params;
|
|
50
|
+
this.parameters = this.serializeParameters();
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* serialize parameters for storage
|
|
55
|
+
*/
|
|
56
|
+
serializeParameters(): IRequestStepParameters {
|
|
57
|
+
const initParams: IRequestStepInit = this._parameters;
|
|
58
|
+
|
|
59
|
+
let authorization: RequestAuthorization | undefined;
|
|
60
|
+
if (initParams.authorization) {
|
|
61
|
+
switch (initParams.authorization.type) {
|
|
62
|
+
case 'basic':
|
|
63
|
+
authorization = {
|
|
64
|
+
type: RequestAuthorizationType.BASIC,
|
|
65
|
+
username: resolveToSource(
|
|
66
|
+
initParams.authorization.username,
|
|
67
|
+
DataType.STRING,
|
|
68
|
+
) as TokenizedSource<DataType.STRING>,
|
|
69
|
+
password: resolveToSource(
|
|
70
|
+
initParams.authorization.password,
|
|
71
|
+
DataType.STRING,
|
|
72
|
+
) as TokenizedSource<DataType.STRING>,
|
|
73
|
+
};
|
|
74
|
+
break;
|
|
75
|
+
case 'bearer':
|
|
76
|
+
authorization = {
|
|
77
|
+
type: RequestAuthorizationType.BEARER_TOKEN,
|
|
78
|
+
token: resolveToSource(
|
|
79
|
+
initParams.authorization.token,
|
|
80
|
+
DataType.STRING,
|
|
81
|
+
) as TokenizedSource<DataType.STRING>,
|
|
82
|
+
};
|
|
83
|
+
break;
|
|
84
|
+
default:
|
|
85
|
+
throw new Error(
|
|
86
|
+
`unknown authorization type (${initParams.authorization['type']}) passed for request step.`,
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
return {
|
|
92
|
+
bodyType: initParams.bodyType as RequestBodyType,
|
|
93
|
+
httpMethod: initParams.method as HttpMethod,
|
|
94
|
+
url: resolveToSource(
|
|
95
|
+
initParams.url,
|
|
96
|
+
DataType.STRING,
|
|
97
|
+
) as TokenizedSource<DataType.STRING>,
|
|
98
|
+
params: resolveParamsToSources(initParams.params || {}, DataType.STRING),
|
|
99
|
+
headers: resolveParamsToSources(
|
|
100
|
+
initParams.headers || {},
|
|
101
|
+
DataType.STRING,
|
|
102
|
+
),
|
|
103
|
+
body:
|
|
104
|
+
typeof initParams.body === 'string'
|
|
105
|
+
? []
|
|
106
|
+
: resolveParamsToSources(initParams.body || {}, DataType.STRING),
|
|
107
|
+
rawBody:
|
|
108
|
+
typeof initParams.body === 'string'
|
|
109
|
+
? (resolveToSource(
|
|
110
|
+
initParams.body || '',
|
|
111
|
+
DataType.STRING,
|
|
112
|
+
) as TokenizedSource<DataType.STRING>)
|
|
113
|
+
: undefined,
|
|
114
|
+
authorization,
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import {
|
|
2
|
+
DataType,
|
|
3
|
+
TokenizedSource,
|
|
4
|
+
KeyedSource,
|
|
5
|
+
} from '../../../resolvers/resolvers.interface';
|
|
6
|
+
import {
|
|
7
|
+
IBaseStep,
|
|
8
|
+
IBaseStepParameters,
|
|
9
|
+
StepType,
|
|
10
|
+
} from '../../step.interface-base';
|
|
11
|
+
|
|
12
|
+
export enum ResponseTypeEnum {
|
|
13
|
+
JSON = 'JSON',
|
|
14
|
+
FILE = 'FILE',
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* parameters used for initializing a ResponseStep
|
|
19
|
+
*/
|
|
20
|
+
export type IResponseStepInit = IBaseStepParameters & {
|
|
21
|
+
statusCode: number;
|
|
22
|
+
} & (
|
|
23
|
+
| { responseType: 'FILE'; body: unknown }
|
|
24
|
+
| { responseType: 'JSON'; body: Record<string, unknown> }
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* parameters used for initializing a ResponseStep
|
|
29
|
+
*/
|
|
30
|
+
export interface IResponseStepParameters extends IBaseStepParameters {
|
|
31
|
+
statusCode: number;
|
|
32
|
+
responseType?: ResponseTypeEnum;
|
|
33
|
+
bodyData: KeyedSource[];
|
|
34
|
+
bodyFile?: TokenizedSource<DataType.FILE>;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* a step used for sending responses to HTTP requests
|
|
39
|
+
*/
|
|
40
|
+
export interface IResponseStep extends IBaseStep {
|
|
41
|
+
/**
|
|
42
|
+
* the step type
|
|
43
|
+
*/
|
|
44
|
+
type: StepType.RESPONSE;
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* configuration for the response step
|
|
48
|
+
*/
|
|
49
|
+
parameters: IResponseStepParameters;
|
|
50
|
+
}
|