polyapi 0.9.0 → 0.10.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.
@@ -56,6 +56,6 @@ interface PolyCustom {
56
56
  executionApiKey: string | undefined | null;
57
57
  userSessionId: string | undefined;
58
58
  responseStatusCode: number;
59
- contentType: string;
59
+ responseContentType: string;
60
60
  }
61
61
  export const polyCustom: PolyCustom;
@@ -11,17 +11,34 @@ const webhookHandles = [
11
11
  {{/each}}
12
12
  ];
13
13
 
14
- const registerWebhookEventListener = (clientID, getSocket, getApiKey, webhookHandleID, callback) => {
14
+ const registerWebhookEventListener = (clientID, getSocket, getApiKey, webhookHandleID, options, callback) => {
15
15
  const socket = getSocket();
16
16
  socket.emit('registerWebhookEventHandler', {
17
17
  clientID,
18
18
  webhookHandleID,
19
19
  apiKey: getApiKey(),
20
+ waitForResponse: options.waitForResponse || false
20
21
  }, registered => {
21
22
  if (registered) {
22
23
  socket.on(
23
24
  `handleWebhookEvent:${webhookHandleID}`,
24
- ({ body, headers, params }) => callback(body, headers, params)
25
+ async ({ body, headers, params, executionId }) => {
26
+ const polyCustom = {};
27
+ const data = await callback(body, headers, params, polyCustom);
28
+
29
+ if(typeof data !== 'undefined' && options.waitForResponse) {
30
+ socket.emit('setWebhookListenerResponse', {
31
+ webhookHandleID,
32
+ apiKey: getApiKey(),
33
+ clientID,
34
+ executionId,
35
+ response: {
36
+ data,
37
+ statusCode: polyCustom.responseStatusCode || 200
38
+ },
39
+ })
40
+ }
41
+ }
25
42
  );
26
43
  } else {
27
44
  console.log(`Could not register webhook event handler for ${webhookHandleID}`);
@@ -40,7 +57,7 @@ const registerWebhookEventListener = (clientID, getSocket, getApiKey, webhookHan
40
57
  module.exports = (clientID, getSocket, getApiKey) => merge(
41
58
  {},
42
59
  webhookHandles.reduce(
43
- (acc, [path, id]) => set(acc, path, (callback) => registerWebhookEventListener(clientID, getSocket, getApiKey, id, callback)),
60
+ (acc, [path, id]) => set(acc, path, (callback, options = {}) => registerWebhookEventListener(clientID, getSocket, getApiKey, id, options, callback)),
44
61
  {}
45
62
  ),
46
63
  );
@@ -4,5 +4,6 @@ export declare class TriggerResponseDto {
4
4
  statusCode: number;
5
5
  functionId?: string;
6
6
  environmentId?: string;
7
+ contentType?: string;
7
8
  }
8
9
  //# sourceMappingURL=trigger-response.dto.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"trigger-response.dto.d.ts","sourceRoot":"","sources":["../../../../../../model/src/dto/trigger/trigger-response.dto.ts"],"names":[],"mappings":"AAAA,qBAAa,kBAAkB;IAC7B,WAAW,EAAE,MAAM,CAAC;IACpB,IAAI,EAAE,OAAO,CAAC;IACd,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB"}
1
+ {"version":3,"file":"trigger-response.dto.d.ts","sourceRoot":"","sources":["../../../../../../model/src/dto/trigger/trigger-response.dto.ts"],"names":[],"mappings":"AAAA,qBAAa,kBAAkB;IAC7B,WAAW,EAAE,MAAM,CAAC;IACpB,IAAI,EAAE,OAAO,CAAC;IACd,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB"}
@@ -1 +1 @@
1
- {"version":3,"file":"trigger-response.dto.js","sourceRoot":"","sources":["../../../../../../model/src/dto/trigger/trigger-response.dto.ts"],"names":[],"mappings":";;;AAAA,MAAa,kBAAkB;CAM9B;AAND,gDAMC"}
1
+ {"version":3,"file":"trigger-response.dto.js","sourceRoot":"","sources":["../../../../../../model/src/dto/trigger/trigger-response.dto.ts"],"names":[],"mappings":";;;AAAA,MAAa,kBAAkB;CAO9B;AAPD,gDAOC"}
@@ -2,5 +2,6 @@ export interface WebhookEventHandlerDto {
2
2
  webhookHandleID: string;
3
3
  apiKey: string;
4
4
  clientID: string;
5
+ waitForResponse?: boolean;
5
6
  }
6
7
  //# sourceMappingURL=webhook-event-handler.dto.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"webhook-event-handler.dto.d.ts","sourceRoot":"","sources":["../../../../../../model/src/dto/webhook/webhook-event-handler.dto.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,sBAAsB;IACrC,eAAe,EAAE,MAAM,CAAC;IACxB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;CAClB"}
1
+ {"version":3,"file":"webhook-event-handler.dto.d.ts","sourceRoot":"","sources":["../../../../../../model/src/dto/webhook/webhook-event-handler.dto.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,sBAAsB;IACrC,eAAe,EAAE,MAAM,CAAC;IACxB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,eAAe,CAAC,EAAE,OAAO,CAAC;CAC3B"}