@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.
Files changed (84) hide show
  1. package/package.json +63 -0
  2. package/src/event/event.interface.ts +18 -0
  3. package/src/event/index.ts +1 -0
  4. package/src/execution/context.constants.ts +9 -0
  5. package/src/execution/context.interface.ts +39 -0
  6. package/src/execution/context.ts +72 -0
  7. package/src/execution/context.utils.ts +53 -0
  8. package/src/execution/index.ts +2 -0
  9. package/src/index.ts +6 -0
  10. package/src/integration/custom-integration.interface.ts +20 -0
  11. package/src/integration/index.ts +2 -0
  12. package/src/integration/integration-config.interface.ts +19 -0
  13. package/src/integration/integration.interface.ts +16 -0
  14. package/src/operator/index.ts +2 -0
  15. package/src/operator/operator.interface.ts +6 -0
  16. package/src/operator/operators/BooleanTrue.ts +20 -0
  17. package/src/operator/operators/StringContains.ts +27 -0
  18. package/src/resolvers/index.ts +2 -0
  19. package/src/resolvers/resolver.utils.ts +157 -0
  20. package/src/resolvers/resolvers.interface.ts +369 -0
  21. package/src/secret/index.ts +1 -0
  22. package/src/secret/secret.interface.ts +4 -0
  23. package/src/stateMachine/index.ts +2 -0
  24. package/src/stateMachine/stateMachine.constants.ts +12 -0
  25. package/src/stateMachine/stateMachine.interface.ts +145 -0
  26. package/src/stateMachine/stateMachine.utils.ts +733 -0
  27. package/src/steps/index.ts +3 -0
  28. package/src/steps/library/action/action.interface.ts +69 -0
  29. package/src/steps/library/action/action.step.ts +70 -0
  30. package/src/steps/library/action/index.ts +2 -0
  31. package/src/steps/library/conditional/conditional.interface.ts +82 -0
  32. package/src/steps/library/conditional/conditional.step.ts +96 -0
  33. package/src/steps/library/conditional/conditional.utils.ts +110 -0
  34. package/src/steps/library/conditional/index.ts +2 -0
  35. package/src/steps/library/delay/delay.interface.ts +71 -0
  36. package/src/steps/library/delay/delay.step.ts +51 -0
  37. package/src/steps/library/delay/index.ts +2 -0
  38. package/src/steps/library/fanout/fanout.interface.ts +46 -0
  39. package/src/steps/library/fanout/fanout.step.ts +68 -0
  40. package/src/steps/library/fanout/index.ts +2 -0
  41. package/src/steps/library/function/function.interface.ts +69 -0
  42. package/src/steps/library/function/function.step.ts +55 -0
  43. package/src/steps/library/function/index.ts +2 -0
  44. package/src/steps/library/index.ts +7 -0
  45. package/src/steps/library/integrationRequest/index.ts +2 -0
  46. package/src/steps/library/integrationRequest/integrationRequest.interface.ts +79 -0
  47. package/src/steps/library/integrationRequest/integrationRequest.step.ts +100 -0
  48. package/src/steps/library/request/index.ts +2 -0
  49. package/src/steps/library/request/request.interface.ts +159 -0
  50. package/src/steps/library/request/request.step.ts +117 -0
  51. package/src/steps/library/response/index.ts +2 -0
  52. package/src/steps/library/response/response.interface.ts +50 -0
  53. package/src/steps/library/response/response.step.ts +68 -0
  54. package/src/steps/step.constants.ts +4 -0
  55. package/src/steps/step.interface-base.ts +81 -0
  56. package/src/steps/step.interface.ts +31 -0
  57. package/src/steps/step.ts +136 -0
  58. package/src/steps/step.utils.ts +103 -0
  59. package/src/triggers/cron/cron.interface.ts +94 -0
  60. package/src/triggers/cron/cron.step.ts +52 -0
  61. package/src/triggers/cron/cron.utils.ts +117 -0
  62. package/src/triggers/cron/index.ts +3 -0
  63. package/src/triggers/endpoint/endpoint.interface.ts +66 -0
  64. package/src/triggers/endpoint/endpoint.step.ts +61 -0
  65. package/src/triggers/endpoint/index.ts +2 -0
  66. package/src/triggers/event/event.interface.ts +43 -0
  67. package/src/triggers/event/event.step.ts +41 -0
  68. package/src/triggers/event/index.ts +2 -0
  69. package/src/triggers/index.ts +4 -0
  70. package/src/triggers/integrationEnabled/index.ts +2 -0
  71. package/src/triggers/integrationEnabled/integrationEnabled.interface.ts +29 -0
  72. package/src/triggers/integrationEnabled/integrationEnabled.step.ts +33 -0
  73. package/src/triggers/trigger.interface.ts +28 -0
  74. package/src/triggers/trigger.ts +25 -0
  75. package/src/user/index.ts +2 -0
  76. package/src/user/user.interface.ts +4 -0
  77. package/src/user/user.ts +6 -0
  78. package/src/utils/index.ts +1 -0
  79. package/src/utils/utils.ts +10 -0
  80. package/src/workflow/index.ts +2 -0
  81. package/src/workflow/workflow.interface.ts +50 -0
  82. package/src/workflow/workflow.ts +132 -0
  83. package/tsconfig.json +9 -0
  84. package/tsconfig.release.json +8 -0
@@ -0,0 +1,66 @@
1
+ import { DataType } from '../../resolvers/resolvers.interface';
2
+ import { IBaseStep, StepType } from '../../steps/step.interface';
3
+ import { ITriggerStepParameters } from '../trigger.interface';
4
+
5
+ /**
6
+ * validation options for request params
7
+ */
8
+ type ParamValidation = { key: string; required: boolean };
9
+
10
+ /**
11
+ * validation options for request headers
12
+ */
13
+
14
+ type HeaderValidation = { key: string; value: string };
15
+
16
+ /**
17
+ * validation options for request body
18
+ */
19
+ type BodyValidation = {
20
+ key: string;
21
+ dataType: keyof typeof DataType;
22
+ required: boolean;
23
+ };
24
+
25
+ /**
26
+ * parameters used for initializing a endpoint step
27
+ */
28
+ export type IEndpointStepInitParameters = ITriggerStepParameters &
29
+ (
30
+ | {
31
+ allowArbitraryPayload: true;
32
+ }
33
+ | {
34
+ allowArbitraryPayload: false;
35
+ paramValidations: ParamValidation[];
36
+ headerValidations: HeaderValidation[];
37
+ bodyValidations: BodyValidation[];
38
+ }
39
+ );
40
+
41
+ /**
42
+ * parameters used for initializing a IntegrationEnabledStep
43
+ */
44
+ export interface IEndpointStepParameters extends ITriggerStepParameters {
45
+ path: string;
46
+ httpMethod: 'POST';
47
+ allowArbitraryPayload: boolean;
48
+ paramValidations: ParamValidation[];
49
+ headerValidations: HeaderValidation[];
50
+ bodyValidations: BodyValidation[];
51
+ }
52
+
53
+ /**
54
+ * a step used for endponit step trigger
55
+ */
56
+ export interface IEndpointStep extends IBaseStep {
57
+ /**
58
+ * the step type
59
+ */
60
+ type: StepType.ENDPOINT;
61
+
62
+ /**
63
+ * configuration for the endpoint step
64
+ */
65
+ parameters: IEndpointStepParameters;
66
+ }
@@ -0,0 +1,61 @@
1
+ import { StepType } from '../../steps/step.interface';
2
+ import { TriggerStep } from '../trigger';
3
+ import {
4
+ IEndpointStep,
5
+ IEndpointStepParameters,
6
+ IEndpointStepInitParameters,
7
+ } from './endpoint.interface';
8
+
9
+ /**
10
+ * a step used for cron trigger
11
+ */
12
+ export class EndpointStep extends TriggerStep implements IEndpointStep {
13
+ /**
14
+ * the step type
15
+ *
16
+ * @type {StepType}
17
+ * @memberof Step
18
+ */
19
+ type: StepType.ENDPOINT = StepType.ENDPOINT;
20
+
21
+ /**
22
+ * initial configuraiton for the endpoint step
23
+ * @type {IEndpointStepInitParameters}
24
+ * @memberof EndpointStep
25
+ */
26
+ private _parameters: IEndpointStepInitParameters;
27
+
28
+ /**
29
+ * configuration for the endpoint step
30
+ */
31
+ parameters: IEndpointStepParameters;
32
+
33
+ constructor(params: IEndpointStepInitParameters) {
34
+ super(params);
35
+ this._parameters = params;
36
+
37
+ this.parameters = this.serializeParameters();
38
+ }
39
+
40
+ /**
41
+ * serialize parameters for storage
42
+ */
43
+ serializeParameters(): IEndpointStepParameters {
44
+ const initParams: IEndpointStepInitParameters = this._parameters;
45
+
46
+ const defaultParams: IEndpointStepParameters = {
47
+ httpMethod: 'POST',
48
+ paramValidations: [],
49
+ headerValidations: [],
50
+ bodyValidations: [],
51
+ allowArbitraryPayload: false,
52
+ path: this.workflowId!,
53
+ };
54
+
55
+ if (initParams.allowArbitraryPayload) {
56
+ return defaultParams;
57
+ }
58
+
59
+ return { ...defaultParams, ...initParams };
60
+ }
61
+ }
@@ -0,0 +1,2 @@
1
+ export * from './endpoint.interface';
2
+ export * from './endpoint.step';
@@ -0,0 +1,43 @@
1
+ import { IEvent } from '../../event';
2
+ import { IBaseStep, StepType } from '../../steps/step.interface';
3
+ import { ITriggerStepParameters } from '../trigger.interface';
4
+
5
+ /**
6
+ * parameters used for initializing an event trigger
7
+ */
8
+ export interface IEventStepInitParameters<
9
+ T extends Record<string, unknown> = Record<string, unknown>,
10
+ > extends IEvent<T>,
11
+ ITriggerStepParameters {}
12
+
13
+ /**
14
+ * parameters used for initializing an event trigger
15
+ */
16
+ export interface IEventStepParameters extends ITriggerStepParameters {
17
+ /**
18
+ * event id of event
19
+ */
20
+ eventId: string;
21
+ }
22
+
23
+ /**
24
+ * an app event trigger
25
+ */
26
+ export interface IEventStep<
27
+ T extends Record<string, unknown> = Record<string, unknown>,
28
+ > extends IBaseStep {
29
+ /**
30
+ * the step type
31
+ */
32
+ type: StepType.EVENT;
33
+
34
+ /**
35
+ * configuration for the event step
36
+ */
37
+ parameters: IEventStepParameters;
38
+
39
+ /**
40
+ * schema of event
41
+ */
42
+ schema: T;
43
+ }
@@ -0,0 +1,41 @@
1
+ import { IEvent } from '../../event/event.interface';
2
+ import { StepType } from '../../steps/step.interface';
3
+ import { TriggerStep } from '../trigger';
4
+ import { IEventStep, IEventStepParameters } from './event.interface';
5
+
6
+ /**
7
+ * an app event trigger
8
+ */
9
+ export class EventStep<E extends Record<string, unknown>>
10
+ extends TriggerStep
11
+ implements IEventStep<E>
12
+ {
13
+ /**
14
+ * the step type
15
+ * @type {StepType}
16
+ * @memberof Step
17
+ */
18
+ type: StepType.EVENT = StepType.EVENT;
19
+
20
+ /**
21
+ * instance of event
22
+ */
23
+ schema: E;
24
+
25
+ /**
26
+ * configuration for the cron step
27
+ */
28
+ parameters: IEventStepParameters;
29
+
30
+ constructor(params: IEvent<E>) {
31
+ super(params);
32
+ this.schema = params.schema as unknown as E;
33
+
34
+ if (!params.id) {
35
+ throw new Error(`id not present in event`);
36
+ }
37
+ this.parameters = {
38
+ eventId: params.id,
39
+ };
40
+ }
41
+ }
@@ -0,0 +1,2 @@
1
+ export * from './event.interface';
2
+ export * from './event.step';
@@ -0,0 +1,4 @@
1
+ export * from './event';
2
+ export * from './cron';
3
+ export * from './integrationEnabled';
4
+ export * from './endpoint';
@@ -0,0 +1,2 @@
1
+ export * from './integrationEnabled.interface';
2
+ export * from './integrationEnabled.step';
@@ -0,0 +1,29 @@
1
+ import { IBaseStep, StepType } from '../../steps/step.interface';
2
+ import { ITriggerStepParameters } from '../trigger.interface';
3
+
4
+ /**
5
+ * parameters used for initializing a IntegrationEnabledStep
6
+ */
7
+ export interface IIntegrationEnabledStepInitParameters
8
+ extends ITriggerStepParameters {}
9
+
10
+ /**
11
+ * parameters used for initializing a IntegrationEnabledStep
12
+ */
13
+ export interface IIntegrationEnabledStepParameters
14
+ extends ITriggerStepParameters {}
15
+
16
+ /**
17
+ * a step used for cron trigger
18
+ */
19
+ export interface IIntegrationEnabledStep extends IBaseStep {
20
+ /**
21
+ * the step type
22
+ */
23
+ type: StepType.INTEGRATION_ENABLED;
24
+
25
+ /**
26
+ * configuration for the integration enabled step
27
+ */
28
+ parameters: IIntegrationEnabledStepParameters;
29
+ }
@@ -0,0 +1,33 @@
1
+ import { StepType } from '../../steps/step.interface';
2
+ import { TriggerStep } from '../trigger';
3
+ import {
4
+ IIntegrationEnabledStep,
5
+ IIntegrationEnabledStepInitParameters,
6
+ IIntegrationEnabledStepParameters,
7
+ } from './integrationEnabled.interface';
8
+
9
+ /**
10
+ * a step used for cron trigger
11
+ */
12
+ export class IntegrationEnabledStep
13
+ extends TriggerStep
14
+ implements IIntegrationEnabledStep
15
+ {
16
+ /**
17
+ * the step type
18
+ *
19
+ * @type {StepType}
20
+ * @memberof Step
21
+ */
22
+ type: StepType.INTEGRATION_ENABLED = StepType.INTEGRATION_ENABLED;
23
+
24
+ /**
25
+ * configuration for the integration enabled step
26
+ */
27
+ parameters: IIntegrationEnabledStepParameters;
28
+
29
+ constructor(params: IIntegrationEnabledStepInitParameters) {
30
+ super(params);
31
+ this.parameters = params;
32
+ }
33
+ }
@@ -0,0 +1,28 @@
1
+ import {
2
+ IBaseStep,
3
+ IBaseStepParameters,
4
+ StepType,
5
+ } from '../steps/step.interface';
6
+
7
+ /**
8
+ * parameters used for initializing a TriggerStep
9
+ */
10
+ export interface ITriggerStepParameters extends IBaseStepParameters {}
11
+
12
+ /**
13
+ * a step used to trigger a workflow
14
+ */
15
+ export interface ITriggerStep extends IBaseStep {
16
+ /**
17
+ * the step type
18
+ *
19
+ * @type {StepType}
20
+ * @memberof TriggerStep
21
+ */
22
+ type: StepType;
23
+
24
+ /**
25
+ * configuration for the trigger step
26
+ */
27
+ parameters: ITriggerStepParameters;
28
+ }
@@ -0,0 +1,25 @@
1
+ import { Step, StepType } from '../steps';
2
+ import { ITriggerStep } from './trigger.interface';
3
+
4
+ /**
5
+ * a step used to trigger a workflow
6
+ */
7
+ export abstract class TriggerStep extends Step implements ITriggerStep {
8
+ /**
9
+ * the step type
10
+ *
11
+ * @type {StepType}
12
+ * @memberof TriggerStep
13
+ */
14
+ type: StepType = StepType.UNSELECTED_TRIGGER;
15
+ }
16
+
17
+ /**
18
+ * class for unselected trigger
19
+ * needed to generate workflow from paragon cloud
20
+ */
21
+ export class UnSelectedTriggerStep extends TriggerStep {
22
+ type: StepType = StepType.UNSELECTED_TRIGGER;
23
+
24
+ parameters: {} = {};
25
+ }
@@ -0,0 +1,2 @@
1
+ export * from './user';
2
+ export * from './user.interface';
@@ -0,0 +1,4 @@
1
+ /**
2
+ * an end-user that has connected an integration for use in a workflow
3
+ */
4
+ export interface IConnectUser {}
@@ -0,0 +1,6 @@
1
+ import { IConnectUser } from './user.interface';
2
+
3
+ /**
4
+ * an end-user that has connected an integration for use in a workflow
5
+ */
6
+ export class ConnectUser implements IConnectUser {}
@@ -0,0 +1 @@
1
+ export * from './utils';
@@ -0,0 +1,10 @@
1
+ /**
2
+ * generates a random number between a range of two numbers
3
+ *
4
+ * @param min
5
+ * @param max
6
+ * @returns
7
+ */
8
+ export function getRandomNumberInRange(min: number, max: number): number {
9
+ return Math.floor(Math.random() * (max - min + 1)) + min;
10
+ }
@@ -0,0 +1,2 @@
1
+ export * from './workflow';
2
+ export * from './workflow.interface';
@@ -0,0 +1,50 @@
1
+ import { IContext } from '../execution';
2
+ import { IIntegration } from '../integration';
3
+ import { StateMachine } from '../stateMachine';
4
+ import { IStep, Step } from '../steps';
5
+ import { IConnectUser } from '../user';
6
+
7
+ /**
8
+ * placeholder for workflow ids
9
+ */
10
+ export const UNSET_WORKFLOW_ID: string = '__UNSET_WORKFLOW_ID__';
11
+
12
+ /**
13
+ * a sequence of activities (steps) meant to be orchestrated and executed
14
+ */
15
+ export interface IWorkflow {
16
+ /**
17
+ * the id of the workflow
18
+ */
19
+ id: string;
20
+
21
+ /**
22
+ * the steps within the workflow
23
+ */
24
+ steps: IStep[];
25
+ }
26
+
27
+ /**
28
+ * a sequence of activities (steps) meant to be orchestrated and executed
29
+ * provides methods for defining itself
30
+ */
31
+ export interface IExecutableWorkflow<I extends IIntegration> extends IWorkflow {
32
+ /**
33
+ * used to define a workflow
34
+ *
35
+ * @param integration the integration being used
36
+ * @param context the execution context
37
+ * @param user the end-user whose data is flowing through the workflow
38
+ */
39
+ define(
40
+ integration: I,
41
+ context: IContext,
42
+ user: IConnectUser,
43
+ ): Promise<StateMachine>;
44
+
45
+ /**
46
+ * associates steps with a workflow
47
+ * @param steps the steps to register
48
+ */
49
+ register(steps: Record<string, Step>): Promise<StateMachine>;
50
+ }
@@ -0,0 +1,132 @@
1
+ import { v4 } from 'uuid';
2
+
3
+ import { IContext } from '../execution';
4
+ import { IIntegration } from '../integration';
5
+ import { StateMachine } from '../stateMachine/stateMachine.interface';
6
+ import { workflowStepsToStateMachine } from '../stateMachine/stateMachine.utils';
7
+ import { IStep, Step } from '../steps';
8
+ import { IConnectUser } from '../user';
9
+ import { IExecutableWorkflow, UNSET_WORKFLOW_ID } from './workflow.interface';
10
+
11
+ /**
12
+ * a sequence of activities meant to be orchestrated and executed
13
+ */
14
+ export abstract class Workflow<I extends IIntegration>
15
+ implements IExecutableWorkflow<I>
16
+ {
17
+ /**
18
+ * the id of the workflow
19
+ *
20
+ * @memberof Workflow
21
+ */
22
+ id = UNSET_WORKFLOW_ID;
23
+
24
+ /**
25
+ * the steps within the workflow
26
+ *
27
+ * @type {IStep[]}
28
+ * @memberof Workflow
29
+ */
30
+ steps: IStep[] = [];
31
+
32
+ /**
33
+ * the previous state machine for the workflow
34
+ * used to reassociate metadata, like step ids
35
+ *
36
+ * @type {StateMachine}
37
+ * @memberof Workflow
38
+ */
39
+ previousStateMachine?: StateMachine;
40
+
41
+ constructor(previousStateMachine?: StateMachine) {
42
+ this.previousStateMachine = previousStateMachine;
43
+ }
44
+
45
+ /**
46
+ * used to define a workflow
47
+ *
48
+ * @param integration the integration being used
49
+ * @param context the execution context
50
+ * @param user the end-user whose data is flowing through the workflow
51
+ */
52
+ abstract define(
53
+ integration: I,
54
+ context: IContext,
55
+ user: IConnectUser,
56
+ ): Promise<StateMachine>;
57
+
58
+ /**
59
+ * associates steps with a workflow and builds a state machine
60
+ *
61
+ * @param steps the steps to register
62
+ */
63
+ public register(steps: Record<string, Step>): Promise<StateMachine> {
64
+ return new Promise(
65
+ (
66
+ resolve: (stateMachine: StateMachine) => void,
67
+ reject: (error: unknown) => void,
68
+ ) => {
69
+ try {
70
+ this.reset();
71
+ steps = this.attemptToRehydrateIdentifiers(steps);
72
+
73
+ const stepList: IStep[] = Object.values(steps)
74
+ .map((step: Step) => step.toObject())
75
+ .map((step: IStep) => {
76
+ this.steps.push(step);
77
+ return step;
78
+ });
79
+
80
+ const stateMachine: StateMachine =
81
+ workflowStepsToStateMachine(stepList);
82
+ resolve(stateMachine);
83
+ } catch (e) {
84
+ reject(e);
85
+ }
86
+ },
87
+ );
88
+ }
89
+
90
+ /**
91
+ * attempts to associate previously used uuids with steps
92
+ * otherwise creates new ones
93
+ *
94
+ * @param steps
95
+ */
96
+ private attemptToRehydrateIdentifiers(
97
+ steps: Record<string, Step>,
98
+ ): Record<string, Step> {
99
+ const previousSteps: IStep[] = this.previousStateMachine
100
+ ? Object.values(this.previousStateMachine.stepMap)
101
+ : [];
102
+ const entries: Array<[key: string, step: Step]> = Object.entries(steps);
103
+ for (const [name, step] of entries) {
104
+ // set workflow id
105
+ step.setWorkflowId(this.id);
106
+
107
+ const previousStep: IStep | undefined = previousSteps.find(
108
+ (s: IStep) => s._migrations?.name === name,
109
+ );
110
+ if (previousStep) {
111
+ step.id = previousStep.id;
112
+ for (const key of Object.keys(previousStep._migrations ?? {})) {
113
+ step.setMigration(key, previousStep._migrations?.[key]);
114
+ }
115
+ } else {
116
+ step.id = v4();
117
+ step.setMigration('name', name);
118
+ }
119
+ }
120
+
121
+ return steps;
122
+ }
123
+
124
+ /**
125
+ * empties the steps array
126
+ */
127
+ private reset(): void {
128
+ while (this.steps.length) {
129
+ this.steps.pop();
130
+ }
131
+ }
132
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,9 @@
1
+ {
2
+ "extends": "../../tsconfig.json",
3
+ "include": ["./src"],
4
+ "compilerOptions": {
5
+ "composite": true,
6
+ "outDir": "./dist",
7
+ "baseUrl": "./"
8
+ }
9
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "extends": "../../tsconfig.release.json",
3
+ "include": ["./src/"],
4
+ "compilerOptions": {
5
+ "outDir": "./dist",
6
+ "baseUrl": "./"
7
+ }
8
+ }