@trayio/cdk-runtime 5.18.0-unstable → 5.18.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.
@@ -2,18 +2,12 @@ import { OperationHandlerAuth, OperationHandlerContext, OperationHandlerResult,
2
2
  import { CompositeOperationHandler } from '@trayio/cdk-dsl/connector/operation/CompositeOperationHandler';
3
3
  import AbstractOperationExecution from './AbstractOperationExecution';
4
4
  import { OperationHandlerInvocationFactory } from './OperationHandlerInvocationFactory';
5
- import { PollingServiceClient } from '../polling/PollingServiceClient';
6
5
  export declare class CompositeOperationExecution<AUTH extends OperationHandlerAuth<unknown, unknown>, IN, OUT> extends AbstractOperationExecution<AUTH, IN, OUT> {
7
6
  private handlerInvocationFactory;
8
7
  private handler;
9
8
  handlerType: OperationHandlerType;
10
- private operationName;
11
- private pollingServiceClient;
12
- constructor(handlerInvocationFactory: OperationHandlerInvocationFactory, handler: CompositeOperationHandler<AUTH, IN, OUT>, handlerType: OperationHandlerType, operationName: string, pollingServiceClient: PollingServiceClient);
9
+ constructor(handlerInvocationFactory: OperationHandlerInvocationFactory, handler: CompositeOperationHandler<AUTH, IN, OUT>, handlerType: OperationHandlerType);
13
10
  execute(ctx: OperationHandlerContext<AUTH>, input: IN): Promise<OperationHandlerResult<OUT>>;
14
- private executePollingLifecycle;
15
- private invokePollingLifecycleCall;
16
- private mapCaughtError;
17
11
  private isError;
18
12
  }
19
13
  //# sourceMappingURL=CompositeOperationExecution.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"CompositeOperationExecution.d.ts","sourceRoot":"","sources":["../../../src/connector/operation/CompositeOperationExecution.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,oBAAoB,EACpB,uBAAuB,EACvB,sBAAsB,EAEtB,oBAAoB,EACpB,MAAM,sDAAsD,CAAC;AAC9D,OAAO,EAAE,yBAAyB,EAAE,MAAM,+DAA+D,CAAC;AAG1G,OAAO,0BAA0B,MAAM,8BAA8B,CAAC;AACtE,OAAO,EAAE,iCAAiC,EAAE,MAAM,qCAAqC,CAAC;AACxF,OAAO,EAAE,oBAAoB,EAAE,MAAM,iCAAiC,CAAC;AA0CvE,qBAAa,2BAA2B,CACvC,IAAI,SAAS,oBAAoB,CAAC,OAAO,EAAE,OAAO,CAAC,EACnD,EAAE,EACF,GAAG,CACF,SAAQ,0BAA0B,CAAC,IAAI,EAAE,EAAE,EAAE,GAAG,CAAC;IAClD,OAAO,CAAC,wBAAwB,CAAoC;IACpE,OAAO,CAAC,OAAO,CAA2C;IAC1D,WAAW,EAAE,oBAAoB,CAAC;IAClC,OAAO,CAAC,aAAa,CAAS;IAC9B,OAAO,CAAC,oBAAoB,CAAuB;gBAGlD,wBAAwB,EAAE,iCAAiC,EAC3D,OAAO,EAAE,yBAAyB,CAAC,IAAI,EAAE,EAAE,EAAE,GAAG,CAAC,EACjD,WAAW,EAAE,oBAAoB,EACjC,aAAa,EAAE,MAAM,EACrB,oBAAoB,EAAE,oBAAoB;IAUrC,OAAO,CACZ,GAAG,EAAE,uBAAuB,CAAC,IAAI,CAAC,EAClC,KAAK,EAAE,EAAE,GACP,OAAO,CAAC,sBAAsB,CAAC,GAAG,CAAC,CAAC;YAqBzB,uBAAuB;IAgBrC,OAAO,CAAC,0BAA0B;IAuClC,OAAO,CAAC,cAAc;IAmBtB,OAAO,CAAC,OAAO;CAQf"}
1
+ {"version":3,"file":"CompositeOperationExecution.d.ts","sourceRoot":"","sources":["../../../src/connector/operation/CompositeOperationExecution.ts"],"names":[],"mappings":"AAEA,OAAO,EACN,oBAAoB,EACpB,uBAAuB,EACvB,sBAAsB,EAEtB,oBAAoB,EACpB,MAAM,sDAAsD,CAAC;AAC9D,OAAO,EAAE,yBAAyB,EAAE,MAAM,+DAA+D,CAAC;AAE1G,OAAO,0BAA0B,MAAM,8BAA8B,CAAC;AACtE,OAAO,EAAE,iCAAiC,EAAE,MAAM,qCAAqC,CAAC;AAExF,qBAAa,2BAA2B,CACvC,IAAI,SAAS,oBAAoB,CAAC,OAAO,EAAE,OAAO,CAAC,EACnD,EAAE,EACF,GAAG,CACF,SAAQ,0BAA0B,CAAC,IAAI,EAAE,EAAE,EAAE,GAAG,CAAC;IAClD,OAAO,CAAC,wBAAwB,CAAoC;IACpE,OAAO,CAAC,OAAO,CAA2C;IAC1D,WAAW,EAAE,oBAAoB,CAAC;gBAGjC,wBAAwB,EAAE,iCAAiC,EAC3D,OAAO,EAAE,yBAAyB,CAAC,IAAI,EAAE,EAAE,EAAE,GAAG,CAAC,EACjD,WAAW,EAAE,oBAAoB;IAQ5B,OAAO,CACZ,GAAG,EAAE,uBAAuB,CAAC,IAAI,CAAC,EAClC,KAAK,EAAE,EAAE,GACP,OAAO,CAAC,sBAAsB,CAAC,GAAG,CAAC,CAAC;IAgCvC,OAAO,CAAC,OAAO;CAQf"}
@@ -6,46 +6,17 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.CompositeOperationExecution = void 0;
7
7
  const OperationHandler_1 = require("@trayio/cdk-dsl/connector/operation/OperationHandler");
8
8
  const AbstractOperationExecution_1 = __importDefault(require("./AbstractOperationExecution"));
9
- const requirePollingCtxFields = (ctx) => {
10
- const missing = [];
11
- if (!ctx.connectorName)
12
- missing.push('ctx.connectorName');
13
- if (!ctx.connectorVersion)
14
- missing.push('ctx.connectorVersion');
15
- if (!ctx.executionToken)
16
- missing.push('ctx.executionToken');
17
- if (!ctx.publicUrl)
18
- missing.push('ctx.publicUrl');
19
- if (missing.length > 0) {
20
- throw new Error(`polling lifecycle is missing required context fields: ${missing.join(', ')}`);
21
- }
22
- return {
23
- connectorName: ctx.connectorName,
24
- connectorVersion: ctx.connectorVersion,
25
- executionToken: ctx.executionToken,
26
- publicUrl: ctx.publicUrl,
27
- };
28
- };
29
- const isPollingLifecycle = (handlerType) => handlerType === OperationHandler_1.OperationHandlerType.TriggerPollCreate ||
30
- handlerType === OperationHandler_1.OperationHandlerType.TriggerPollDestroy;
31
9
  class CompositeOperationExecution extends AbstractOperationExecution_1.default {
32
10
  handlerInvocationFactory;
33
11
  handler;
34
12
  handlerType;
35
- operationName;
36
- pollingServiceClient;
37
- constructor(handlerInvocationFactory, handler, handlerType, operationName, pollingServiceClient) {
13
+ constructor(handlerInvocationFactory, handler, handlerType) {
38
14
  super();
39
15
  this.handlerInvocationFactory = handlerInvocationFactory;
40
16
  this.handler = handler;
41
17
  this.handlerType = handlerType;
42
- this.operationName = operationName;
43
- this.pollingServiceClient = pollingServiceClient;
44
18
  }
45
19
  async execute(ctx, input) {
46
- if (isPollingLifecycle(this.handlerType)) {
47
- return this.executePollingLifecycle(ctx, input);
48
- }
49
20
  const handlerInvocation = this.handlerInvocationFactory(ctx);
50
21
  try {
51
22
  const result = await this.handler.handlerFunction(ctx, input, handlerInvocation);
@@ -53,53 +24,14 @@ class CompositeOperationExecution extends AbstractOperationExecution_1.default {
53
24
  return result;
54
25
  }
55
26
  catch (error) {
56
- return this.mapCaughtError(error);
57
- }
58
- }
59
- async executePollingLifecycle(ctx, input) {
60
- try {
61
- const pollingInput = (input ?? {});
62
- const requiredCtx = requirePollingCtxFields(ctx);
63
- await this.invokePollingLifecycleCall(requiredCtx, pollingInput);
64
- return OperationHandler_1.OperationHandlerResult.success({});
65
- }
66
- catch (error) {
67
- return this.mapCaughtError(error);
68
- }
69
- }
70
- invokePollingLifecycleCall(requiredCtx, pollingInput) {
71
- const { connectorName, connectorVersion, executionToken, publicUrl } = requiredCtx;
72
- const registeredHandlerName = this.operationName;
73
- switch (this.handlerType) {
74
- case OperationHandler_1.OperationHandlerType.TriggerPollCreate:
75
- return this.pollingServiceClient.register({
76
- connectorName,
77
- connectorVersion,
78
- registeredHandlerName,
79
- publicUrl,
80
- pollingInterval: pollingInput.pollingInterval,
81
- maxFailureCount: pollingInput.maxFailureCount,
82
- initialCursor: pollingInput.initialCursor,
83
- }, executionToken);
84
- case OperationHandler_1.OperationHandlerType.TriggerPollDestroy:
85
- return this.pollingServiceClient.deregister({
86
- connectorName,
87
- connectorVersion,
88
- registeredHandlerName,
89
- publicUrl,
90
- }, executionToken);
91
- default:
92
- throw new Error(`polling lifecycle called for non-polling handler type: ${this.handlerType}`);
93
- }
94
- }
95
- mapCaughtError(error) {
96
- if (this.isError(error)) {
97
- return OperationHandler_1.OperationHandlerResult.failure(OperationHandler_1.OperationHandlerError.connectorError(error.message));
98
- }
99
- if (typeof error === 'string') {
100
- return OperationHandler_1.OperationHandlerResult.failure(OperationHandler_1.OperationHandlerError.connectorError(error));
27
+ if (this.isError(error)) {
28
+ return OperationHandler_1.OperationHandlerResult.failure(OperationHandler_1.OperationHandlerError.connectorError(error.message));
29
+ }
30
+ if (typeof error === 'string') {
31
+ return OperationHandler_1.OperationHandlerResult.failure(OperationHandler_1.OperationHandlerError.connectorError(error));
32
+ }
33
+ return OperationHandler_1.OperationHandlerResult.failure(OperationHandler_1.OperationHandlerError.connectorError('Operation failed with unknown error'));
101
34
  }
102
- return OperationHandler_1.OperationHandlerResult.failure(OperationHandler_1.OperationHandlerError.connectorError('Operation failed with unknown error'));
103
35
  }
104
36
  // TODO: Move to commons
105
37
  isError(error) {
@@ -2,11 +2,9 @@ import { OperationHandlerAuth, OperationHandlerType } from '@trayio/cdk-dsl/conn
2
2
  import { CompositeOperationHandler } from '@trayio/cdk-dsl/connector/operation/CompositeOperationHandler';
3
3
  import { OperationExecution } from './OperationExecution';
4
4
  import { OperationHandlerInvocationFactory } from './OperationHandlerInvocationFactory';
5
- import { PollingServiceClient } from '../polling/PollingServiceClient';
6
5
  export declare class CompositeOperationExecutionFactory {
7
6
  private handlerInvocationFactory;
8
- private pollingServiceClient;
9
- constructor(handlerInvocationFactory: OperationHandlerInvocationFactory, pollingServiceClient: PollingServiceClient);
10
- executionFrom<AUTH extends OperationHandlerAuth<unknown, unknown>, IN, OUT>(handler: CompositeOperationHandler<AUTH, IN, OUT>, handlerType: OperationHandlerType, operationName: string): OperationExecution<AUTH, IN, OUT>;
7
+ constructor(handlerInvocationFactory: OperationHandlerInvocationFactory);
8
+ executionFrom<AUTH extends OperationHandlerAuth<unknown, unknown>, IN, OUT>(handler: CompositeOperationHandler<AUTH, IN, OUT>, handlerType: OperationHandlerType): OperationExecution<AUTH, IN, OUT>;
11
9
  }
12
10
  //# sourceMappingURL=CompositeOperationExecutionFactory.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"CompositeOperationExecutionFactory.d.ts","sourceRoot":"","sources":["../../../src/connector/operation/CompositeOperationExecutionFactory.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,oBAAoB,EACpB,oBAAoB,EACpB,MAAM,sDAAsD,CAAC;AAC9D,OAAO,EAAE,yBAAyB,EAAE,MAAM,+DAA+D,CAAC;AAC1G,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAE1D,OAAO,EAAE,iCAAiC,EAAE,MAAM,qCAAqC,CAAC;AACxF,OAAO,EAAE,oBAAoB,EAAE,MAAM,iCAAiC,CAAC;AAEvE,qBAAa,kCAAkC;IAC9C,OAAO,CAAC,wBAAwB,CAAoC;IACpE,OAAO,CAAC,oBAAoB,CAAuB;gBAGlD,wBAAwB,EAAE,iCAAiC,EAC3D,oBAAoB,EAAE,oBAAoB;IAM3C,aAAa,CAAC,IAAI,SAAS,oBAAoB,CAAC,OAAO,EAAE,OAAO,CAAC,EAAE,EAAE,EAAE,GAAG,EACzE,OAAO,EAAE,yBAAyB,CAAC,IAAI,EAAE,EAAE,EAAE,GAAG,CAAC,EACjD,WAAW,EAAE,oBAAoB,EACjC,aAAa,EAAE,MAAM,GACnB,kBAAkB,CAAC,IAAI,EAAE,EAAE,EAAE,GAAG,CAAC;CASpC"}
1
+ {"version":3,"file":"CompositeOperationExecutionFactory.d.ts","sourceRoot":"","sources":["../../../src/connector/operation/CompositeOperationExecutionFactory.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,oBAAoB,EACpB,oBAAoB,EACpB,MAAM,sDAAsD,CAAC;AAC9D,OAAO,EAAE,yBAAyB,EAAE,MAAM,+DAA+D,CAAC;AAC1G,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAE1D,OAAO,EAAE,iCAAiC,EAAE,MAAM,qCAAqC,CAAC;AAExF,qBAAa,kCAAkC;IAC9C,OAAO,CAAC,wBAAwB,CAAoC;gBAExD,wBAAwB,EAAE,iCAAiC;IAIvE,aAAa,CAAC,IAAI,SAAS,oBAAoB,CAAC,OAAO,EAAE,OAAO,CAAC,EAAE,EAAE,EAAE,GAAG,EACzE,OAAO,EAAE,yBAAyB,CAAC,IAAI,EAAE,EAAE,EAAE,GAAG,CAAC,EACjD,WAAW,EAAE,oBAAoB,GAC/B,kBAAkB,CAAC,IAAI,EAAE,EAAE,EAAE,GAAG,CAAC;CAOpC"}
@@ -4,13 +4,11 @@ exports.CompositeOperationExecutionFactory = void 0;
4
4
  const CompositeOperationExecution_1 = require("./CompositeOperationExecution");
5
5
  class CompositeOperationExecutionFactory {
6
6
  handlerInvocationFactory;
7
- pollingServiceClient;
8
- constructor(handlerInvocationFactory, pollingServiceClient) {
7
+ constructor(handlerInvocationFactory) {
9
8
  this.handlerInvocationFactory = handlerInvocationFactory;
10
- this.pollingServiceClient = pollingServiceClient;
11
9
  }
12
- executionFrom(handler, handlerType, operationName) {
13
- return new CompositeOperationExecution_1.CompositeOperationExecution(this.handlerInvocationFactory, handler, handlerType, operationName, this.pollingServiceClient);
10
+ executionFrom(handler, handlerType) {
11
+ return new CompositeOperationExecution_1.CompositeOperationExecution(this.handlerInvocationFactory, handler, handlerType);
14
12
  }
15
13
  }
16
14
  exports.CompositeOperationExecutionFactory = CompositeOperationExecutionFactory;
@@ -1 +1 @@
1
- {"version":3,"file":"OperationExecutionFactory.d.ts","sourceRoot":"","sources":["../../../src/connector/operation/OperationExecutionFactory.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,gBAAgB,EAEhB,MAAM,2DAA2D,CAAC;AACnE,OAAO,EACN,oBAAoB,EAEpB,MAAM,sDAAsD,CAAC;AAC9D,OAAO,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAC7D,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AACxD,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAG1D,OAAO,EAAE,iCAAiC,EAAE,MAAM,qCAAqC,CAAC;AAIxF,qBAAa,yBAAyB;IACrC,OAAO,CAAC,mCAAmC,CAAsC;IACjF,OAAO,CAAC,6BAA6B,CAAgC;IACrE,OAAO,CAAC,kCAAkC,CAAqC;gBAG9E,UAAU,EAAE,UAAU,EACtB,WAAW,EAAE,WAAW,EACxB,iCAAiC,EAAE,iCAAiC;IAerE,aAAa,CAAC,IAAI,SAAS,oBAAoB,CAAC,OAAO,EAAE,OAAO,CAAC,EAAE,EAAE,EAAE,GAAG,EACzE,OAAO,EAAE,gBAAgB,CAAC,IAAI,EAAE,EAAE,EAAE,GAAG,CAAC,GACtC,kBAAkB,CAAC,IAAI,EAAE,EAAE,EAAE,GAAG,CAAC;IAWpC,OAAO,CAAC,2BAA2B;CAsBnC"}
1
+ {"version":3,"file":"OperationExecutionFactory.d.ts","sourceRoot":"","sources":["../../../src/connector/operation/OperationExecutionFactory.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,gBAAgB,EAEhB,MAAM,2DAA2D,CAAC;AACnE,OAAO,EACN,oBAAoB,EAEpB,MAAM,sDAAsD,CAAC;AAC9D,OAAO,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAC7D,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AACxD,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAG1D,OAAO,EAAE,iCAAiC,EAAE,MAAM,qCAAqC,CAAC;AAGxF,qBAAa,yBAAyB;IACrC,OAAO,CAAC,mCAAmC,CAAsC;IACjF,OAAO,CAAC,6BAA6B,CAAgC;IACrE,OAAO,CAAC,kCAAkC,CAAqC;gBAG9E,UAAU,EAAE,UAAU,EACtB,WAAW,EAAE,WAAW,EACxB,iCAAiC,EAAE,iCAAiC;IAYrE,aAAa,CAAC,IAAI,SAAS,oBAAoB,CAAC,OAAO,EAAE,OAAO,CAAC,EAAE,EAAE,EAAE,GAAG,EACzE,OAAO,EAAE,gBAAgB,CAAC,IAAI,EAAE,EAAE,EAAE,GAAG,CAAC,GACtC,kBAAkB,CAAC,IAAI,EAAE,EAAE,EAAE,GAAG,CAAC;IAWpC,OAAO,CAAC,2BAA2B;CAsBnC"}
@@ -4,7 +4,6 @@ exports.OperationExecutionFactory = void 0;
4
4
  const HttpOperationExecutionFactory_1 = require("./HttpOperationExecutionFactory");
5
5
  const CompositeOperationExecutionFactory_1 = require("./CompositeOperationExecutionFactory");
6
6
  const OperationExecutionValidationFactory_1 = require("./OperationExecutionValidationFactory");
7
- const PollingServiceClient_1 = require("../polling/PollingServiceClient");
8
7
  class OperationExecutionFactory {
9
8
  operationExecutionValidationFactory;
10
9
  httpOperationExecutionFactory;
@@ -14,7 +13,7 @@ class OperationExecutionFactory {
14
13
  new OperationExecutionValidationFactory_1.OperationExecutionValidationFactory();
15
14
  this.httpOperationExecutionFactory = new HttpOperationExecutionFactory_1.HttpOperationExecutionFactory(httpClient, fileStorage);
16
15
  this.compositeOperationExecutionFactory =
17
- new CompositeOperationExecutionFactory_1.CompositeOperationExecutionFactory(operationHandlerInvocationFactory, new PollingServiceClient_1.PollingServiceClient(httpClient));
16
+ new CompositeOperationExecutionFactory_1.CompositeOperationExecutionFactory(operationHandlerInvocationFactory);
18
17
  }
19
18
  executionFrom(handler) {
20
19
  const executionFromImplementation = this.executionFromImplementation(handler);
@@ -26,7 +25,7 @@ class OperationExecutionFactory {
26
25
  case 'HttpOperationHandler':
27
26
  return this.httpOperationExecutionFactory.executionFrom(handler.implementation, handler.globalConfiguration, handler.handlerType);
28
27
  case 'CompositeOperationHandler':
29
- return this.compositeOperationExecutionFactory.executionFrom(handler.implementation, handler.handlerType, handler.name);
28
+ return this.compositeOperationExecutionFactory.executionFrom(handler.implementation, handler.handlerType);
30
29
  }
31
30
  }
32
31
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trayio/cdk-runtime",
3
- "version": "5.18.0-unstable",
3
+ "version": "5.18.0",
4
4
  "description": "A Runtime that executes connector operations defined using the CDK DSL",
5
5
  "exports": {
6
6
  "./*": "./dist/*.js"
@@ -14,10 +14,10 @@
14
14
  "node": ">=18.x"
15
15
  },
16
16
  "dependencies": {
17
- "@trayio/axios": "5.18.0-unstable",
18
- "@trayio/cdk-dsl": "5.18.0-unstable",
19
- "@trayio/express": "5.18.0-unstable",
20
- "@trayio/winston": "5.18.0-unstable",
17
+ "@trayio/axios": "5.18.0",
18
+ "@trayio/cdk-dsl": "5.18.0",
19
+ "@trayio/express": "5.18.0",
20
+ "@trayio/winston": "5.18.0",
21
21
  "mime": "3.0.0",
22
22
  "uuid": "9.0.0"
23
23
  },
@@ -34,6 +34,5 @@
34
34
  ],
35
35
  "devDependencies": {
36
36
  "just-permutations": "^2.2.1"
37
- },
38
- "stableVersion": "0.0.0"
37
+ }
39
38
  }
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=CompositeOperationExecution.unit.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"CompositeOperationExecution.unit.test.d.ts","sourceRoot":"","sources":["../../../src/connector/operation/CompositeOperationExecution.unit.test.ts"],"names":[],"mappings":""}
@@ -1,125 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const OperationHandler_1 = require("@trayio/cdk-dsl/connector/operation/OperationHandler");
4
- const CompositeOperationHandler_1 = require("@trayio/cdk-dsl/connector/operation/CompositeOperationHandler");
5
- const PollOperationHandler_1 = require("@trayio/cdk-dsl/connector/operation/PollOperationHandler");
6
- const CompositeOperationExecution_1 = require("./CompositeOperationExecution");
7
- const noopHandlerInvocationFactory = () => (() => undefined);
8
- const fakePollingContext = () => ({
9
- connectorName: 'salesforce',
10
- connectorVersion: '7.2.0',
11
- executionToken: 'exec-jwt',
12
- publicUrl: 'https://trigger.example.test/tab-123',
13
- });
14
- const createFakePollingServiceClient = () => {
15
- const registerCalls = [];
16
- const deregisterCalls = [];
17
- const client = {
18
- register: jest.fn((payload, token) => {
19
- registerCalls.push([payload, token]);
20
- return Promise.resolve();
21
- }),
22
- deregister: jest.fn((payload, token) => {
23
- deregisterCalls.push([payload, token]);
24
- return Promise.resolve();
25
- }),
26
- };
27
- return { client, registerCalls, deregisterCalls };
28
- };
29
- describe('CompositeOperationExecution polling lifecycle branch', () => {
30
- it('calls PollingServiceClient.register with ctx + input fields on TriggerPollCreate, never invoking handlerFunction', async () => {
31
- const { client, registerCalls } = createFakePollingServiceClient();
32
- const handlerFunction = jest.fn();
33
- const handler = new CompositeOperationHandler_1.CompositeOperationHandler(handlerFunction);
34
- const execution = new CompositeOperationExecution_1.CompositeOperationExecution(noopHandlerInvocationFactory, handler, OperationHandler_1.OperationHandlerType.TriggerPollCreate, 'new_records_poll', client);
35
- const input = {
36
- pollingInterval: { value: 15, unit: PollOperationHandler_1.PollingIntervalUnit.Minutes },
37
- maxFailureCount: 50,
38
- initialCursor: { since: 't0' },
39
- };
40
- const result = await execution.execute(fakePollingContext(), input);
41
- expect(result.isSuccess).toBe(true);
42
- expect(handlerFunction).not.toHaveBeenCalled();
43
- expect(registerCalls).toHaveLength(1);
44
- const [payload, token] = registerCalls[0];
45
- expect(payload).toEqual({
46
- connectorName: 'salesforce',
47
- connectorVersion: '7.2.0',
48
- registeredHandlerName: 'new_records_poll',
49
- publicUrl: 'https://trigger.example.test/tab-123',
50
- pollingInterval: {
51
- value: 15,
52
- unit: PollOperationHandler_1.PollingIntervalUnit.Minutes,
53
- },
54
- maxFailureCount: 50,
55
- initialCursor: { since: 't0' },
56
- });
57
- expect(token).toBe('exec-jwt');
58
- });
59
- it('calls PollingServiceClient.deregister on TriggerPollDestroy, never invoking handlerFunction', async () => {
60
- const { client, deregisterCalls } = createFakePollingServiceClient();
61
- const handlerFunction = jest.fn();
62
- const handler = new CompositeOperationHandler_1.CompositeOperationHandler(handlerFunction);
63
- const execution = new CompositeOperationExecution_1.CompositeOperationExecution(noopHandlerInvocationFactory, handler, OperationHandler_1.OperationHandlerType.TriggerPollDestroy, 'new_records_poll_destroy', client);
64
- const result = await execution.execute(fakePollingContext(), {});
65
- expect(result.isSuccess).toBe(true);
66
- expect(handlerFunction).not.toHaveBeenCalled();
67
- expect(deregisterCalls).toHaveLength(1);
68
- const [payload, token] = deregisterCalls[0];
69
- expect(payload).toEqual({
70
- connectorName: 'salesforce',
71
- connectorVersion: '7.2.0',
72
- registeredHandlerName: 'new_records_poll_destroy',
73
- publicUrl: 'https://trigger.example.test/tab-123',
74
- });
75
- expect(token).toBe('exec-jwt');
76
- });
77
- it('surfaces a consolidated failure listing every missing ctx field', async () => {
78
- const { client, registerCalls } = createFakePollingServiceClient();
79
- const handler = new CompositeOperationHandler_1.CompositeOperationHandler(jest.fn());
80
- const execution = new CompositeOperationExecution_1.CompositeOperationExecution(noopHandlerInvocationFactory, handler, OperationHandler_1.OperationHandlerType.TriggerPollCreate, 'new_records_poll', client);
81
- const result = await execution.execute({}, {});
82
- expect(registerCalls).toHaveLength(0);
83
- expect(result.isFailure).toBe(true);
84
- const error = result._tag === 'Failure' ? result.error.message : '';
85
- expect(error).toMatch(/ctx\.connectorName/);
86
- expect(error).toMatch(/ctx\.connectorVersion/);
87
- expect(error).toMatch(/ctx\.executionToken/);
88
- expect(error).toMatch(/ctx\.publicUrl/);
89
- });
90
- it('maps a PollingServiceClient error into an OperationHandlerResult failure', async () => {
91
- const client = {
92
- register: jest.fn(() => Promise.reject(new Error('boom'))),
93
- deregister: jest.fn(),
94
- };
95
- const handler = new CompositeOperationHandler_1.CompositeOperationHandler(jest.fn());
96
- const execution = new CompositeOperationExecution_1.CompositeOperationExecution(noopHandlerInvocationFactory, handler, OperationHandler_1.OperationHandlerType.TriggerPollCreate, 'new_records_poll', client);
97
- const result = await execution.execute(fakePollingContext(), {});
98
- expect(result.isFailure).toBe(true);
99
- const message = result._tag === 'Failure' ? result.error.message : '';
100
- expect(message).toBe('boom');
101
- });
102
- });
103
- describe('CompositeOperationExecution non-polling path (regression baseline)', () => {
104
- it('invokes handlerFunction for non-polling handler types and returns its result', async () => {
105
- const { client } = createFakePollingServiceClient();
106
- const success = OperationHandler_1.OperationHandlerResult.success({ echoed: 42 });
107
- const handlerFunction = jest.fn().mockResolvedValue(success);
108
- const handler = new CompositeOperationHandler_1.CompositeOperationHandler(handlerFunction);
109
- const execution = new CompositeOperationExecution_1.CompositeOperationExecution(noopHandlerInvocationFactory, handler, OperationHandler_1.OperationHandlerType.TriggerRequest, 'some_request_op', client);
110
- const ctx = {};
111
- const input = { foo: 'bar' };
112
- const result = await execution.execute(ctx, input);
113
- expect(handlerFunction).toHaveBeenCalledTimes(1);
114
- expect(handlerFunction).toHaveBeenCalledWith(ctx, input, expect.any(Function));
115
- expect(result).toBe(success);
116
- });
117
- it('does not call the PollingServiceClient for non-polling handler types', async () => {
118
- const { client, registerCalls, deregisterCalls } = createFakePollingServiceClient();
119
- const handler = new CompositeOperationHandler_1.CompositeOperationHandler(jest.fn().mockResolvedValue(OperationHandler_1.OperationHandlerResult.success({})));
120
- const execution = new CompositeOperationExecution_1.CompositeOperationExecution(noopHandlerInvocationFactory, handler, OperationHandler_1.OperationHandlerType.Regular, 'plain_regular_op', client);
121
- await execution.execute({}, {});
122
- expect(registerCalls).toHaveLength(0);
123
- expect(deregisterCalls).toHaveLength(0);
124
- });
125
- });
@@ -1,38 +0,0 @@
1
- import { HttpClient } from '@trayio/commons/http/HttpClient';
2
- import { PollingInterval } from '@trayio/cdk-dsl/connector/operation/PollOperationHandler';
3
- export type PollingServiceRegisterPayload = {
4
- connectorName: string;
5
- connectorVersion: string;
6
- /**
7
- * The registered handler name (e.g. `"new_records_poll"`). The client
8
- * normalizes to the canonical `_poll`-suffixed form before sending.
9
- */
10
- registeredHandlerName: string;
11
- publicUrl: string;
12
- pollingInterval?: PollingInterval;
13
- maxFailureCount?: number;
14
- initialCursor?: unknown;
15
- };
16
- export type PollingServiceDeregisterPayload = {
17
- connectorName: string;
18
- connectorVersion: string;
19
- /**
20
- * The registered handler name (e.g. `"new_records_poll_destroy"`). The
21
- * client normalizes to the canonical `_poll`-suffixed form before sending.
22
- */
23
- registeredHandlerName: string;
24
- publicUrl: string;
25
- };
26
- /**
27
- * Internal HTTP client used by the runtime when invoking polling trigger
28
- * create / destroy operations. Not exported from the public `@trayio/cdk-runtime`
29
- * surface; connector developers must not call this directly.
30
- */
31
- export declare class PollingServiceClient {
32
- private httpClient;
33
- constructor(httpClient: HttpClient);
34
- register(payload: PollingServiceRegisterPayload, executionToken: string): Promise<void>;
35
- deregister(payload: PollingServiceDeregisterPayload, executionToken: string): Promise<void>;
36
- private sendJson;
37
- }
38
- //# sourceMappingURL=PollingServiceClient.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"PollingServiceClient.d.ts","sourceRoot":"","sources":["../../../src/connector/polling/PollingServiceClient.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAE7D,OAAO,EAGN,eAAe,EAEf,MAAM,0DAA0D,CAAC;AA0BlE,MAAM,MAAM,6BAA6B,GAAG;IAC3C,aAAa,EAAE,MAAM,CAAC;IACtB,gBAAgB,EAAE,MAAM,CAAC;IACzB;;;OAGG;IACH,qBAAqB,EAAE,MAAM,CAAC;IAC9B,SAAS,EAAE,MAAM,CAAC;IAClB,eAAe,CAAC,EAAE,eAAe,CAAC;IAClC,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,aAAa,CAAC,EAAE,OAAO,CAAC;CACxB,CAAC;AAEF,MAAM,MAAM,+BAA+B,GAAG;IAC7C,aAAa,EAAE,MAAM,CAAC;IACtB,gBAAgB,EAAE,MAAM,CAAC;IACzB;;;OAGG;IACH,qBAAqB,EAAE,MAAM,CAAC;IAC9B,SAAS,EAAE,MAAM,CAAC;CAClB,CAAC;AA4BF;;;;GAIG;AACH,qBAAa,oBAAoB;IACpB,OAAO,CAAC,UAAU;gBAAV,UAAU,EAAE,UAAU;IAEpC,QAAQ,CACb,OAAO,EAAE,6BAA6B,EACtC,cAAc,EAAE,MAAM,GACpB,OAAO,CAAC,IAAI,CAAC;IAoBV,UAAU,CACf,OAAO,EAAE,+BAA+B,EACxC,cAAc,EAAE,MAAM,GACpB,OAAO,CAAC,IAAI,CAAC;YAYF,QAAQ;CAgCtB"}
@@ -1,123 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.PollingServiceClient = void 0;
27
- const stream_1 = require("stream");
28
- const E = __importStar(require("fp-ts/Either"));
29
- const Http_1 = require("@trayio/commons/http/Http");
30
- const PollOperationHandler_1 = require("@trayio/cdk-dsl/connector/operation/PollOperationHandler");
31
- const POLLING_SERVICE_URL_ENV = 'TRAY_POLLING_SERVICE_URL';
32
- const EXECUTION_TOKEN_HEADER = 'X-Tray-Execution-Token';
33
- const TRIGGERS_REGISTER_PATH = '/triggers/register';
34
- const POLL_SUFFIX = '_poll';
35
- const POLL_DESTROY_SUFFIX = '_poll_destroy';
36
- /**
37
- * PS keys register+deregister against the canonical `_poll`-suffixed
38
- * operation name. `_poll_destroy` handlers rewrite to the matching `_poll`
39
- * name so both sides of the lifecycle target the same PS record.
40
- */
41
- const toCanonicalPollOperationName = (registeredHandlerName) => {
42
- if (registeredHandlerName.endsWith(POLL_DESTROY_SUFFIX)) {
43
- return `${registeredHandlerName.slice(0, -POLL_DESTROY_SUFFIX.length)}${POLL_SUFFIX}`;
44
- }
45
- return registeredHandlerName;
46
- };
47
- const pollingIntervalToSeconds = (interval) => {
48
- switch (interval.unit) {
49
- case PollOperationHandler_1.PollingIntervalUnit.Minutes:
50
- return interval.value * 60;
51
- case PollOperationHandler_1.PollingIntervalUnit.Hours:
52
- return interval.value * 3600;
53
- default:
54
- throw new Error(`Unsupported pollingInterval.unit: ${interval.unit}`);
55
- }
56
- };
57
- const resolveEndpoint = () => {
58
- const baseUrl = process.env[POLLING_SERVICE_URL_ENV];
59
- if (!baseUrl) {
60
- throw new Error(`${POLLING_SERVICE_URL_ENV} env var is not set; the polling service cannot be reached`);
61
- }
62
- return `${baseUrl.replace(/\/$/, '')}${TRIGGERS_REGISTER_PATH}`;
63
- };
64
- const bodyToReadable = (payload) => stream_1.Readable.from(JSON.stringify(payload));
65
- /**
66
- * Internal HTTP client used by the runtime when invoking polling trigger
67
- * create / destroy operations. Not exported from the public `@trayio/cdk-runtime`
68
- * surface; connector developers must not call this directly.
69
- */
70
- class PollingServiceClient {
71
- httpClient;
72
- constructor(httpClient) {
73
- this.httpClient = httpClient;
74
- }
75
- async register(payload, executionToken) {
76
- const intervalSeconds = pollingIntervalToSeconds(payload.pollingInterval ?? PollOperationHandler_1.DEFAULT_POLLING_INTERVAL);
77
- const maxFailureCount = payload.maxFailureCount ?? PollOperationHandler_1.DEFAULT_MAX_FAILURE_COUNT;
78
- const body = {
79
- connectorName: payload.connectorName,
80
- connectorVersion: payload.connectorVersion,
81
- operationName: toCanonicalPollOperationName(payload.registeredHandlerName),
82
- publicUrl: payload.publicUrl,
83
- interval: intervalSeconds,
84
- maxFailureCount,
85
- initialCursor: payload.initialCursor ?? null,
86
- };
87
- await this.sendJson(Http_1.HttpMethod.Post, executionToken, body);
88
- }
89
- async deregister(payload, executionToken) {
90
- const body = {
91
- connectorName: payload.connectorName,
92
- connectorVersion: payload.connectorVersion,
93
- operationName: toCanonicalPollOperationName(payload.registeredHandlerName),
94
- publicUrl: payload.publicUrl,
95
- };
96
- await this.sendJson(Http_1.HttpMethod.Delete, executionToken, body);
97
- }
98
- async sendJson(method, executionToken, body) {
99
- if (!executionToken) {
100
- throw new Error('polling service call requires an execution token (ctx.executionToken)');
101
- }
102
- const url = resolveEndpoint();
103
- const request = Http_1.HttpRequest.create({
104
- headers: {
105
- [Http_1.HttpHeader.ContentType]: 'application/json',
106
- [EXECUTION_TOKEN_HEADER]: executionToken,
107
- },
108
- body: bodyToReadable(body),
109
- });
110
- const responseE = await this.httpClient.execute(method, url, request)();
111
- if (E.isLeft(responseE)) {
112
- throw responseE.left;
113
- }
114
- const response = responseE.right;
115
- if (response.statusCode < 200 || response.statusCode >= 300) {
116
- throw new Error(`polling service ${method} ${url} failed with status ${response.statusCode}`);
117
- }
118
- // Drain the body so the underlying HTTP connection can be released.
119
- // We don't need the payload; the status code is authoritative.
120
- response.body.resume();
121
- }
122
- }
123
- exports.PollingServiceClient = PollingServiceClient;
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=PollingServiceClient.unit.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"PollingServiceClient.unit.test.d.ts","sourceRoot":"","sources":["../../../src/connector/polling/PollingServiceClient.unit.test.ts"],"names":[],"mappings":""}
@@ -1,214 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- Object.defineProperty(exports, "__esModule", { value: true });
26
- const stream_1 = require("stream");
27
- const TE = __importStar(require("fp-ts/TaskEither"));
28
- const Http_1 = require("@trayio/commons/http/Http");
29
- const PollOperationHandler_1 = require("@trayio/cdk-dsl/connector/operation/PollOperationHandler");
30
- const PollingServiceClient_1 = require("./PollingServiceClient");
31
- const BASE_URL = 'https://polling.example.test';
32
- const ENDPOINT_PATH = '/triggers/register';
33
- const ENV_VAR = 'TRAY_POLLING_SERVICE_URL';
34
- const createMockHttpClient = (capture) => ({
35
- execute: jest.fn().mockImplementation((method, url, request) => TE.tryCatch(async () => {
36
- const chunks = [];
37
- for await (const chunk of request.body) {
38
- chunks.push(typeof chunk === 'string' ? Buffer.from(chunk) : chunk);
39
- }
40
- const raw = Buffer.concat(chunks).toString('utf8');
41
- capture.push({
42
- method,
43
- url,
44
- headers: request.headers,
45
- body: raw.length > 0 ? JSON.parse(raw) : undefined,
46
- });
47
- return {
48
- statusCode: 200,
49
- headers: {},
50
- body: stream_1.Readable.from(''),
51
- };
52
- }, (reason) => new Error(String(reason)))),
53
- });
54
- describe('PollingServiceClient', () => {
55
- let originalEnv;
56
- beforeEach(() => {
57
- originalEnv = process.env[ENV_VAR];
58
- process.env[ENV_VAR] = BASE_URL;
59
- });
60
- afterEach(() => {
61
- if (originalEnv === undefined) {
62
- delete process.env[ENV_VAR];
63
- }
64
- else {
65
- process.env[ENV_VAR] = originalEnv;
66
- }
67
- });
68
- describe('register', () => {
69
- it('POSTs to /triggers/register with normalized payload and execution token header', async () => {
70
- const captured = [];
71
- const client = new PollingServiceClient_1.PollingServiceClient(createMockHttpClient(captured));
72
- await client.register({
73
- connectorName: 'salesforce',
74
- connectorVersion: '7.2.0',
75
- registeredHandlerName: 'new_records_poll',
76
- publicUrl: 'https://trigger.example.test/abc',
77
- pollingInterval: {
78
- value: 10,
79
- unit: PollOperationHandler_1.PollingIntervalUnit.Minutes,
80
- },
81
- maxFailureCount: 42,
82
- initialCursor: { since: 'cursor-0' },
83
- }, 'exec-jwt-token');
84
- expect(captured).toHaveLength(1);
85
- const call = captured[0];
86
- expect(call.method).toBe(Http_1.HttpMethod.Post);
87
- expect(call.url).toBe(`${BASE_URL}${ENDPOINT_PATH}`);
88
- expect(call.headers).toMatchObject({
89
- 'Content-Type': 'application/json',
90
- 'X-Tray-Execution-Token': 'exec-jwt-token',
91
- });
92
- expect(call.body).toEqual({
93
- connectorName: 'salesforce',
94
- connectorVersion: '7.2.0',
95
- operationName: 'new_records_poll',
96
- publicUrl: 'https://trigger.example.test/abc',
97
- interval: 600,
98
- maxFailureCount: 42,
99
- initialCursor: { since: 'cursor-0' },
100
- });
101
- });
102
- it('converts hours to seconds', async () => {
103
- const captured = [];
104
- const client = new PollingServiceClient_1.PollingServiceClient(createMockHttpClient(captured));
105
- await client.register({
106
- connectorName: 'x',
107
- connectorVersion: '1.0.0',
108
- registeredHandlerName: 'x_poll',
109
- publicUrl: 'u',
110
- pollingInterval: { value: 2, unit: PollOperationHandler_1.PollingIntervalUnit.Hours },
111
- }, 'tok');
112
- expect(captured[0].body.interval).toBe(7200);
113
- });
114
- it('falls back to defaults (5 min, maxFailureCount 30, null cursor) when omitted', async () => {
115
- const captured = [];
116
- const client = new PollingServiceClient_1.PollingServiceClient(createMockHttpClient(captured));
117
- await client.register({
118
- connectorName: 'x',
119
- connectorVersion: '1.0.0',
120
- registeredHandlerName: 'x_poll',
121
- publicUrl: 'u',
122
- }, 'tok');
123
- expect(captured[0].body).toMatchObject({
124
- interval: 300,
125
- maxFailureCount: 30,
126
- initialCursor: null,
127
- });
128
- });
129
- it('trims trailing slashes from the PS base URL', async () => {
130
- process.env[ENV_VAR] = `${BASE_URL}/`;
131
- const captured = [];
132
- const client = new PollingServiceClient_1.PollingServiceClient(createMockHttpClient(captured));
133
- await client.register({
134
- connectorName: 'x',
135
- connectorVersion: '1.0.0',
136
- registeredHandlerName: 'x_poll',
137
- publicUrl: 'u',
138
- }, 'tok');
139
- expect(captured[0].url).toBe(`${BASE_URL}${ENDPOINT_PATH}`);
140
- });
141
- it('throws when TRAY_POLLING_SERVICE_URL env var is unset', async () => {
142
- delete process.env[ENV_VAR];
143
- const client = new PollingServiceClient_1.PollingServiceClient(createMockHttpClient([]));
144
- await expect(client.register({
145
- connectorName: 'x',
146
- connectorVersion: '1.0.0',
147
- registeredHandlerName: 'x_poll',
148
- publicUrl: 'u',
149
- }, 'tok')).rejects.toThrow(/TRAY_POLLING_SERVICE_URL/);
150
- });
151
- it('throws when execution token is an empty string', async () => {
152
- const client = new PollingServiceClient_1.PollingServiceClient(createMockHttpClient([]));
153
- await expect(client.register({
154
- connectorName: 'x',
155
- connectorVersion: '1.0.0',
156
- registeredHandlerName: 'x_poll',
157
- publicUrl: 'u',
158
- }, '')).rejects.toThrow(/execution token/);
159
- });
160
- it('throws when PS returns a non-2xx status', async () => {
161
- const errorClient = {
162
- execute: () => TE.right({
163
- statusCode: 500,
164
- headers: {},
165
- body: stream_1.Readable.from(''),
166
- }),
167
- };
168
- const client = new PollingServiceClient_1.PollingServiceClient(errorClient);
169
- await expect(client.register({
170
- connectorName: 'x',
171
- connectorVersion: '1.0.0',
172
- registeredHandlerName: 'x_poll',
173
- publicUrl: 'u',
174
- }, 'tok')).rejects.toThrow(/failed with status 500/);
175
- });
176
- });
177
- describe('deregister', () => {
178
- it('DELETEs /triggers/register with minimal payload and execution token header', async () => {
179
- const captured = [];
180
- const client = new PollingServiceClient_1.PollingServiceClient(createMockHttpClient(captured));
181
- await client.deregister({
182
- connectorName: 'salesforce',
183
- connectorVersion: '7.2.0',
184
- registeredHandlerName: 'new_records_poll_destroy',
185
- publicUrl: 'https://trigger.example.test/abc',
186
- }, 'exec-jwt-token');
187
- expect(captured).toHaveLength(1);
188
- const call = captured[0];
189
- expect(call.method).toBe(Http_1.HttpMethod.Delete);
190
- expect(call.url).toBe(`${BASE_URL}${ENDPOINT_PATH}`);
191
- expect(call.headers).toMatchObject({
192
- 'X-Tray-Execution-Token': 'exec-jwt-token',
193
- });
194
- // operationName is normalised back to the canonical _poll-suffixed name.
195
- expect(call.body).toEqual({
196
- connectorName: 'salesforce',
197
- connectorVersion: '7.2.0',
198
- operationName: 'new_records_poll',
199
- publicUrl: 'https://trigger.example.test/abc',
200
- });
201
- });
202
- it('leaves an already-canonical _poll name unchanged', async () => {
203
- const captured = [];
204
- const client = new PollingServiceClient_1.PollingServiceClient(createMockHttpClient(captured));
205
- await client.deregister({
206
- connectorName: 'x',
207
- connectorVersion: '1.0.0',
208
- registeredHandlerName: 'x_poll',
209
- publicUrl: 'u',
210
- }, 'tok');
211
- expect(captured[0].body.operationName).toBe('x_poll');
212
- });
213
- });
214
- });