@activepieces/pieces-framework 0.4.0 → 0.6.0

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 CHANGED
@@ -1,11 +1,12 @@
1
1
  {
2
2
  "name": "@activepieces/pieces-framework",
3
- "version": "0.4.0",
3
+ "version": "0.6.0",
4
4
  "type": "commonjs",
5
5
  "dependencies": {
6
6
  "@sinclair/typebox": "^0.26.3",
7
7
  "nanoid": "^3.3.4",
8
- "@activepieces/shared": "0.4.0",
8
+ "semver": "7.5.3",
9
+ "@activepieces/shared": "0.5.5",
9
10
  "tslib": "1.14.1"
10
11
  },
11
12
  "main": "./src/index.js",
@@ -1,4 +1,4 @@
1
- import { AppConnectionValue, ExecutionType, PauseMetadata, StopResponse, TriggerPayload } from "@activepieces/shared";
1
+ import { AppConnectionValue, ExecutionType, FlowRunId, PauseMetadata, StopResponse, TriggerPayload } from "@activepieces/shared";
2
2
  import { TriggerStrategy } from "./trigger/trigger";
3
3
  import { NonAuthPiecePropertyMap, PieceAuthProperty, PiecePropValueSchema, PiecePropertyMap, StaticPropsValue } from "./property";
4
4
  type BaseContext<PieceAuth extends PieceAuthProperty, Props extends PiecePropertyMap> = {
@@ -31,19 +31,27 @@ export type StopHookParams = {
31
31
  response: StopResponse;
32
32
  };
33
33
  export type StopHook = (params: StopHookParams) => void;
34
- export type PauseHookPauseMetadata = Omit<PauseMetadata, 'resumeStepMetadata'>;
34
+ type PauseMetadataWithoutResumeStepMetadata<T extends PauseMetadata> = T extends PauseMetadata ? Omit<T, 'resumeStepMetadata'> : never;
35
+ export type PauseHookPauseMetadata = PauseMetadataWithoutResumeStepMetadata<PauseMetadata>;
35
36
  export type PauseHookParams = {
36
37
  pauseMetadata: PauseHookPauseMetadata;
37
38
  };
38
39
  export type PauseHook = (params: PauseHookParams) => void;
39
- export type ActionContext<PieceAuth extends PieceAuthProperty = PieceAuthProperty, ActionProps extends NonAuthPiecePropertyMap = NonAuthPiecePropertyMap> = BaseContext<PieceAuth, ActionProps> & {
40
- executionType: ExecutionType;
40
+ export type BaseActionContext<ET extends ExecutionType, PieceAuth extends PieceAuthProperty, ActionProps extends NonAuthPiecePropertyMap> = BaseContext<PieceAuth, ActionProps> & {
41
+ executionType: ET;
41
42
  connections: ConnectionsManager;
42
43
  run: {
44
+ id: FlowRunId;
45
+ webhookBaseUrl: string;
43
46
  stop: StopHook;
44
47
  pause: PauseHook;
45
48
  };
46
49
  };
50
+ type BeginExecutionActionContext<PieceAuth extends PieceAuthProperty = PieceAuthProperty, ActionProps extends NonAuthPiecePropertyMap = NonAuthPiecePropertyMap> = BaseActionContext<ExecutionType.BEGIN, PieceAuth, ActionProps>;
51
+ type ResumeExecutionActionContext<PieceAuth extends PieceAuthProperty = PieceAuthProperty, ActionProps extends NonAuthPiecePropertyMap = NonAuthPiecePropertyMap> = BaseActionContext<ExecutionType.RESUME, PieceAuth, ActionProps> & {
52
+ resumePayload: unknown;
53
+ };
54
+ export type ActionContext<PieceAuth extends PieceAuthProperty = PieceAuthProperty, ActionProps extends NonAuthPiecePropertyMap = NonAuthPiecePropertyMap> = BeginExecutionActionContext<PieceAuth, ActionProps> | ResumeExecutionActionContext<PieceAuth, ActionProps>;
47
55
  export interface ConnectionsManager {
48
56
  get(key: string): Promise<AppConnectionValue | Record<string, unknown> | string | null>;
49
57
  }
@@ -1 +1 @@
1
- {"version":3,"file":"context.js","sourceRoot":"","sources":["../../../../../../packages/pieces/framework/src/lib/context.ts"],"names":[],"mappings":";;;AAiFA,IAAY,UAIX;AAJD,WAAY,UAAU;IAClB,iDAAiD;IACjD,oCAAsB,CAAA;IACtB,2BAAa,CAAA;AACjB,CAAC,EAJW,UAAU,0BAAV,UAAU,QAIrB"}
1
+ {"version":3,"file":"context.js","sourceRoot":"","sources":["../../../../../../packages/pieces/framework/src/lib/context.ts"],"names":[],"mappings":";;;AAuGA,IAAY,UAIX;AAJD,WAAY,UAAU;IAClB,iDAAiD;IACjD,oCAAsB,CAAA;IACtB,2BAAa,CAAA;AACjB,CAAC,EAJW,UAAU,0BAAV,UAAU,QAIrB"}
@@ -6,6 +6,21 @@ export declare enum TriggerStrategy {
6
6
  WEBHOOK = "WEBHOOK",
7
7
  APP_WEBHOOK = "APP_WEBHOOK"
8
8
  }
9
+ export declare enum WebhookHandshakeStrategy {
10
+ NONE = "NONE",
11
+ HEADER_PRESENT = "HEADER_PRESENT",
12
+ QUERY_PRESENT = "QUERY_PRESENT",
13
+ BODY_PARAM_PRESENT = "BODY_PARAM_PRESENT"
14
+ }
15
+ export interface WebhookHandshakeConfiguration {
16
+ strategy: WebhookHandshakeStrategy;
17
+ paramName?: string;
18
+ }
19
+ export interface WebhookResponse {
20
+ status: number;
21
+ body?: any;
22
+ headers?: Record<string, string>;
23
+ }
9
24
  type CreateTriggerParams<PieceAuth extends PieceAuthProperty, TriggerProps extends NonAuthPiecePropertyMap, TS extends TriggerStrategy> = {
10
25
  /**
11
26
  * A dummy parameter used to infer {@code PieceAuth} type
@@ -16,7 +31,9 @@ type CreateTriggerParams<PieceAuth extends PieceAuthProperty, TriggerProps exten
16
31
  auth?: PieceAuth;
17
32
  props: TriggerProps;
18
33
  type: TS;
34
+ handshakeConfiguration?: WebhookHandshakeConfiguration;
19
35
  onEnable: (context: TriggerHookContext<PieceAuth, TriggerProps, TS>) => Promise<void>;
36
+ onHandshake?: (context: TriggerHookContext<PieceAuth, TriggerProps, TS>) => Promise<WebhookResponse>;
20
37
  onDisable: (context: TriggerHookContext<PieceAuth, TriggerProps, TS>) => Promise<void>;
21
38
  run: (context: TriggerHookContext<PieceAuth, TriggerProps, TS>) => Promise<unknown[]>;
22
39
  test?: (context: TriggerHookContext<PieceAuth, TriggerProps, TS>) => Promise<unknown[]>;
@@ -29,13 +46,15 @@ export declare class ITrigger<TS extends TriggerStrategy, PieceAuth extends Piec
29
46
  readonly description: string;
30
47
  readonly props: TriggerProps;
31
48
  readonly type: TS;
49
+ readonly handshakeConfiguration: WebhookHandshakeConfiguration;
32
50
  readonly onEnable: (ctx: TriggerHookContext<PieceAuth, TriggerProps, TS>) => Promise<void>;
51
+ readonly onHandshake: (ctx: TriggerHookContext<PieceAuth, TriggerProps, TS>) => Promise<WebhookResponse>;
33
52
  readonly onDisable: (ctx: TriggerHookContext<PieceAuth, TriggerProps, TS>) => Promise<void>;
34
53
  readonly run: (ctx: TriggerHookContext<PieceAuth, TriggerProps, TS>) => Promise<unknown[]>;
35
54
  readonly test: (ctx: TriggerHookContext<PieceAuth, TriggerProps, TS>) => Promise<unknown[]>;
36
55
  sampleData: unknown;
37
56
  readonly requireAuth: boolean;
38
- constructor(name: string, displayName: string, description: string, props: TriggerProps, type: TS, onEnable: (ctx: TriggerHookContext<PieceAuth, TriggerProps, TS>) => Promise<void>, onDisable: (ctx: TriggerHookContext<PieceAuth, TriggerProps, TS>) => Promise<void>, run: (ctx: TriggerHookContext<PieceAuth, TriggerProps, TS>) => Promise<unknown[]>, test: (ctx: TriggerHookContext<PieceAuth, TriggerProps, TS>) => Promise<unknown[]>, sampleData: unknown, requireAuth?: boolean);
57
+ constructor(name: string, displayName: string, description: string, props: TriggerProps, type: TS, handshakeConfiguration: WebhookHandshakeConfiguration, onEnable: (ctx: TriggerHookContext<PieceAuth, TriggerProps, TS>) => Promise<void>, onHandshake: (ctx: TriggerHookContext<PieceAuth, TriggerProps, TS>) => Promise<WebhookResponse>, onDisable: (ctx: TriggerHookContext<PieceAuth, TriggerProps, TS>) => Promise<void>, run: (ctx: TriggerHookContext<PieceAuth, TriggerProps, TS>) => Promise<unknown[]>, test: (ctx: TriggerHookContext<PieceAuth, TriggerProps, TS>) => Promise<unknown[]>, sampleData: unknown, requireAuth?: boolean);
39
58
  }
40
59
  export type Trigger<PieceAuth extends PieceAuthProperty = any, TriggerProps extends NonAuthPiecePropertyMap = any, S extends TriggerStrategy = TriggerStrategy> = ITrigger<S, PieceAuth, TriggerProps>;
41
60
  export declare const createTrigger: <TS extends TriggerStrategy, PieceAuth extends PieceAuthProperty, TriggerProps extends NonAuthPiecePropertyMap>(params: CreateTriggerParams<PieceAuth, TriggerProps, TS>) => ITrigger<TS, PieceAuth, TriggerProps>;
@@ -1,20 +1,30 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createTrigger = exports.ITrigger = exports.TriggerStrategy = void 0;
3
+ exports.createTrigger = exports.ITrigger = exports.WebhookHandshakeStrategy = exports.TriggerStrategy = void 0;
4
+ const tslib_1 = require("tslib");
4
5
  var TriggerStrategy;
5
6
  (function (TriggerStrategy) {
6
7
  TriggerStrategy["POLLING"] = "POLLING";
7
8
  TriggerStrategy["WEBHOOK"] = "WEBHOOK";
8
9
  TriggerStrategy["APP_WEBHOOK"] = "APP_WEBHOOK";
9
10
  })(TriggerStrategy || (exports.TriggerStrategy = TriggerStrategy = {}));
11
+ var WebhookHandshakeStrategy;
12
+ (function (WebhookHandshakeStrategy) {
13
+ WebhookHandshakeStrategy["NONE"] = "NONE";
14
+ WebhookHandshakeStrategy["HEADER_PRESENT"] = "HEADER_PRESENT";
15
+ WebhookHandshakeStrategy["QUERY_PRESENT"] = "QUERY_PRESENT";
16
+ WebhookHandshakeStrategy["BODY_PARAM_PRESENT"] = "BODY_PARAM_PRESENT";
17
+ })(WebhookHandshakeStrategy || (exports.WebhookHandshakeStrategy = WebhookHandshakeStrategy = {}));
10
18
  class ITrigger {
11
- constructor(name, displayName, description, props, type, onEnable, onDisable, run, test, sampleData, requireAuth = true) {
19
+ constructor(name, displayName, description, props, type, handshakeConfiguration, onEnable, onHandshake, onDisable, run, test, sampleData, requireAuth = true) {
12
20
  this.name = name;
13
21
  this.displayName = displayName;
14
22
  this.description = description;
15
23
  this.props = props;
16
24
  this.type = type;
25
+ this.handshakeConfiguration = handshakeConfiguration;
17
26
  this.onEnable = onEnable;
27
+ this.onHandshake = onHandshake;
18
28
  this.onDisable = onDisable;
19
29
  this.run = run;
20
30
  this.test = test;
@@ -24,8 +34,8 @@ class ITrigger {
24
34
  }
25
35
  exports.ITrigger = ITrigger;
26
36
  const createTrigger = (params) => {
27
- var _a;
28
- return new ITrigger(params.name, params.displayName, params.description, params.props, params.type, params.onEnable, params.onDisable, params.run, (_a = params.test) !== null && _a !== void 0 ? _a : (() => Promise.resolve([params.sampleData])), params.sampleData, params.requireAuth);
37
+ var _a, _b, _c;
38
+ return new ITrigger(params.name, params.displayName, params.description, params.props, params.type, (_a = params.handshakeConfiguration) !== null && _a !== void 0 ? _a : { strategy: WebhookHandshakeStrategy.NONE }, params.onEnable, (_b = params.onHandshake) !== null && _b !== void 0 ? _b : (() => tslib_1.__awaiter(void 0, void 0, void 0, function* () { return ({ status: 200 }); })), params.onDisable, params.run, (_c = params.test) !== null && _c !== void 0 ? _c : (() => Promise.resolve([params.sampleData])), params.sampleData, params.requireAuth);
29
39
  };
30
40
  exports.createTrigger = createTrigger;
31
41
  //# sourceMappingURL=trigger.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"trigger.js","sourceRoot":"","sources":["../../../../../../../packages/pieces/framework/src/lib/trigger/trigger.ts"],"names":[],"mappings":";;;AAIA,IAAY,eAIX;AAJD,WAAY,eAAe;IACzB,sCAAmB,CAAA;IACnB,sCAAmB,CAAA;IACnB,8CAA2B,CAAA;AAC7B,CAAC,EAJW,eAAe,+BAAf,eAAe,QAI1B;AAwBD,MAAa,QAAQ;IAKnB,YACkB,IAAY,EACZ,WAAmB,EACnB,WAAmB,EACnB,KAAmB,EACnB,IAAQ,EACR,QAAiF,EACjF,SAAkF,EAClF,GAAiF,EACjF,IAAkF,EAC3F,UAAmB,EACV,cAAuB,IAAI;QAV3B,SAAI,GAAJ,IAAI,CAAQ;QACZ,gBAAW,GAAX,WAAW,CAAQ;QACnB,gBAAW,GAAX,WAAW,CAAQ;QACnB,UAAK,GAAL,KAAK,CAAc;QACnB,SAAI,GAAJ,IAAI,CAAI;QACR,aAAQ,GAAR,QAAQ,CAAyE;QACjF,cAAS,GAAT,SAAS,CAAyE;QAClF,QAAG,GAAH,GAAG,CAA8E;QACjF,SAAI,GAAJ,IAAI,CAA8E;QAC3F,eAAU,GAAV,UAAU,CAAS;QACV,gBAAW,GAAX,WAAW,CAAgB;IACzC,CAAC;CACN;AAlBD,4BAkBC;AAQM,MAAM,aAAa,GAAG,CAI3B,MAAwD,EAAE,EAAE;;IAC5D,OAAO,IAAI,QAAQ,CACjB,MAAM,CAAC,IAAI,EACX,MAAM,CAAC,WAAW,EAClB,MAAM,CAAC,WAAW,EAClB,MAAM,CAAC,KAAK,EACZ,MAAM,CAAC,IAAI,EACX,MAAM,CAAC,QAAQ,EACf,MAAM,CAAC,SAAS,EAChB,MAAM,CAAC,GAAG,EACV,MAAA,MAAM,CAAC,IAAI,mCAAI,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC,EAC3D,MAAM,CAAC,UAAU,EACjB,MAAM,CAAC,WAAW,CACnB,CAAA;AACH,CAAC,CAAA;AAlBY,QAAA,aAAa,iBAkBzB"}
1
+ {"version":3,"file":"trigger.js","sourceRoot":"","sources":["../../../../../../../packages/pieces/framework/src/lib/trigger/trigger.ts"],"names":[],"mappings":";;;;AAIA,IAAY,eAIX;AAJD,WAAY,eAAe;IACzB,sCAAmB,CAAA;IACnB,sCAAmB,CAAA;IACnB,8CAA2B,CAAA;AAC7B,CAAC,EAJW,eAAe,+BAAf,eAAe,QAI1B;AAED,IAAY,wBAKX;AALD,WAAY,wBAAwB;IAClC,yCAAa,CAAA;IACb,6DAAiC,CAAA;IACjC,2DAA+B,CAAA;IAC/B,qEAAyC,CAAA;AAC3C,CAAC,EALW,wBAAwB,wCAAxB,wBAAwB,QAKnC;AAqCD,MAAa,QAAQ;IAKnB,YACkB,IAAY,EACZ,WAAmB,EACnB,WAAmB,EACnB,KAAmB,EACnB,IAAQ,EACR,sBAAqD,EACrD,QAAiF,EACjF,WAA+F,EAC/F,SAAkF,EAClF,GAAiF,EACjF,IAA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