@shipfox/api-integration-core 5.0.0 → 6.0.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.
Files changed (73) hide show
  1. package/.turbo/turbo-build.log +4 -4
  2. package/CHANGELOG.md +65 -0
  3. package/dist/core/entities/provider.d.ts +7 -2
  4. package/dist/core/entities/provider.d.ts.map +1 -1
  5. package/dist/core/entities/provider.js.map +1 -1
  6. package/dist/core/errors.d.ts +7 -0
  7. package/dist/core/errors.d.ts.map +1 -1
  8. package/dist/core/errors.js +8 -2
  9. package/dist/core/errors.js.map +1 -1
  10. package/dist/index.d.ts +17 -4
  11. package/dist/index.d.ts.map +1 -1
  12. package/dist/index.js +50 -5
  13. package/dist/index.js.map +1 -1
  14. package/dist/presentation/inter-module.d.ts +9 -0
  15. package/dist/presentation/inter-module.d.ts.map +1 -0
  16. package/dist/presentation/inter-module.js +121 -0
  17. package/dist/presentation/inter-module.js.map +1 -0
  18. package/dist/presentation/routes/agent-tools-gateway/index.d.ts +1 -0
  19. package/dist/presentation/routes/agent-tools-gateway/index.d.ts.map +1 -1
  20. package/dist/presentation/routes/agent-tools-gateway/index.js +1 -0
  21. package/dist/presentation/routes/agent-tools-gateway/index.js.map +1 -1
  22. package/dist/presentation/routes/agent-tools-gateway/resolve-authorized-tools.d.ts +5 -2
  23. package/dist/presentation/routes/agent-tools-gateway/resolve-authorized-tools.d.ts.map +1 -1
  24. package/dist/presentation/routes/agent-tools-gateway/resolve-authorized-tools.js +53 -17
  25. package/dist/presentation/routes/agent-tools-gateway/resolve-authorized-tools.js.map +1 -1
  26. package/dist/presentation/routes/index.d.ts +2 -3
  27. package/dist/presentation/routes/index.d.ts.map +1 -1
  28. package/dist/presentation/routes/index.js +2 -2
  29. package/dist/presentation/routes/index.js.map +1 -1
  30. package/dist/providers/gitea.d.ts.map +1 -1
  31. package/dist/providers/gitea.js +10 -8
  32. package/dist/providers/gitea.js.map +1 -1
  33. package/dist/providers/github.d.ts.map +1 -1
  34. package/dist/providers/github.js +18 -13
  35. package/dist/providers/github.js.map +1 -1
  36. package/dist/providers/jira.d.ts.map +1 -1
  37. package/dist/providers/jira.js +4 -1
  38. package/dist/providers/jira.js.map +1 -1
  39. package/dist/providers/linear.d.ts.map +1 -1
  40. package/dist/providers/linear.js +34 -29
  41. package/dist/providers/linear.js.map +1 -1
  42. package/dist/providers/sentry.d.ts.map +1 -1
  43. package/dist/providers/sentry.js +13 -11
  44. package/dist/providers/sentry.js.map +1 -1
  45. package/dist/providers/slack.d.ts.map +1 -1
  46. package/dist/providers/slack.js +34 -29
  47. package/dist/providers/slack.js.map +1 -1
  48. package/dist/providers/types.d.ts +12 -0
  49. package/dist/providers/types.d.ts.map +1 -1
  50. package/dist/providers/types.js.map +1 -1
  51. package/dist/providers/webhook.d.ts.map +1 -1
  52. package/dist/providers/webhook.js +11 -9
  53. package/dist/providers/webhook.js.map +1 -1
  54. package/dist/tsconfig.test.tsbuildinfo +1 -1
  55. package/package.json +22 -17
  56. package/src/core/entities/provider.ts +7 -1
  57. package/src/core/errors.ts +12 -2
  58. package/src/index.test.ts +112 -0
  59. package/src/index.ts +102 -9
  60. package/src/presentation/inter-module.ts +155 -0
  61. package/src/presentation/routes/agent-tools-gateway/index.ts +1 -0
  62. package/src/presentation/routes/agent-tools-gateway/resolve-authorized-tools.test.ts +36 -0
  63. package/src/presentation/routes/agent-tools-gateway/resolve-authorized-tools.ts +64 -22
  64. package/src/presentation/routes/index.ts +4 -5
  65. package/src/providers/gitea.ts +11 -8
  66. package/src/providers/github.ts +17 -11
  67. package/src/providers/jira.ts +3 -0
  68. package/src/providers/linear.ts +30 -24
  69. package/src/providers/sentry.ts +15 -12
  70. package/src/providers/slack.ts +31 -25
  71. package/src/providers/types.ts +15 -0
  72. package/src/providers/webhook.ts +11 -9
  73. package/tsconfig.build.tsbuildinfo +1 -1
@@ -1,6 +1,6 @@
1
1
  $ shipfox-swc && shipfox-temporal-bundle dist/temporal/workflows/index.js
2
- Successfully compiled: 49 files with swc (158.39ms)
3
- 2026-07-19T19:41:21.630Z [INFO] asset workflow-bundle-fe8baaf5b68e0b2328d8.js 1.45 MiB [emitted] [immutable] (name: main)
2
+ Successfully compiled: 50 files with swc (537.34ms)
3
+ 2026-07-21T08:11:11.281Z [INFO] asset workflow-bundle-fe8baaf5b68e0b2328d8.js 1.45 MiB [emitted] [immutable] (name: main)
4
4
  runtime modules 670 bytes 3 modules
5
5
  modules by path ../../../../node_modules/.pnpm/ 424 KiB
6
6
  modules by path ../../../../node_modules/.pnpm/@temporalio+common@1.18.1/node_modules/@temporal...(truncated) 155 KiB 34 modules
@@ -15,6 +15,6 @@ modules by path ./dist/temporal/workflows/ 1020 bytes
15
15
  optional modules 30 bytes [optional]
16
16
  __temporal_custom_payload_converter (ignored) 15 bytes [optional] [built] [code generated]
17
17
  __temporal_custom_failure_converter (ignored) 15 bytes [optional] [built] [code generated]
18
- webpack 5.107.2 compiled successfully in 1227 ms
19
- 2026-07-19T19:41:21.634Z [INFO] Workflow bundle created { size: '1.45MB' }
18
+ webpack 5.107.2 compiled successfully in 3023 ms
19
+ 2026-07-21T08:11:11.298Z [INFO] Workflow bundle created { size: '1.45MB' }
20
20
  /home/runner/work/shipfox/shipfox/libs/api/integration/core/dist/temporal/workflows/index.js: 1516260 bytes
package/CHANGELOG.md CHANGED
@@ -1,5 +1,70 @@
1
1
  # @shipfox/api-integration-core
2
2
 
3
+ ## 6.0.0
4
+
5
+ ### Major Changes
6
+
7
+ - 23a4dc2: Moves Logs and Integrations to injected Workflows inter-module clients with minimal log and leased agent-tool queries.
8
+
9
+ ### Minor Changes
10
+
11
+ - 0bb82a4: Adds the Agent and Integrations inter-module APIs, moving Workflows agent configuration, runtime credential resolution, and integration consumers behind producer-owned clients.
12
+ - f262539: Adds a composed webhook processor and optional provider-neutral delivery source for hosted API runtimes.
13
+ - 3bb4e26: Fixes composed webhook processing and exposes Slack URL-verification responses through the shared contract.
14
+
15
+ ### Patch Changes
16
+
17
+ - 7ac43a4: Consolidates packed-consumer validation around stable publication and composition contracts instead of package-state snapshots.
18
+ - f73da5d: Enforces bounded API context imports and routes inter-module consumers through producer contracts.
19
+ - 326f4c0: Exposes Workspaces inter-module operations and moves Auth and OAuth providers onto injected clients.
20
+ - Updated dependencies [0bb82a4]
21
+ - Updated dependencies [23563de]
22
+ - Updated dependencies [54ce48b]
23
+ - Updated dependencies [f4bc2eb]
24
+ - Updated dependencies [40a6e0f]
25
+ - Updated dependencies [c0162b0]
26
+ - Updated dependencies [7ac43a4]
27
+ - Updated dependencies [f262539]
28
+ - Updated dependencies [a01e917]
29
+ - Updated dependencies [3bb4e26]
30
+ - Updated dependencies [1b79cda]
31
+ - Updated dependencies [e3b6338]
32
+ - Updated dependencies [c2db8c3]
33
+ - Updated dependencies [a42b575]
34
+ - Updated dependencies [8390468]
35
+ - Updated dependencies [a869cfd]
36
+ - Updated dependencies [8bdc149]
37
+ - Updated dependencies [f73da5d]
38
+ - Updated dependencies [3810996]
39
+ - Updated dependencies [0649d62]
40
+ - Updated dependencies [23a4dc2]
41
+ - Updated dependencies [b00ed29]
42
+ - Updated dependencies [8aa7cd3]
43
+ - Updated dependencies [326f4c0]
44
+ - Updated dependencies [1820feb]
45
+ - Updated dependencies [4a91956]
46
+ - Updated dependencies [81f9544]
47
+ - Updated dependencies [4604a06]
48
+ - @shipfox/api-agent-dto@6.0.0
49
+ - @shipfox/api-integration-core-dto@6.0.0
50
+ - @shipfox/api-workflows-dto@6.0.0
51
+ - @shipfox/node-module@0.4.0
52
+ - @shipfox/node-temporal@0.3.2
53
+ - @shipfox/api-integration-slack@6.0.0
54
+ - @shipfox/node-drizzle@0.3.2
55
+ - @shipfox/node-outbox@0.2.4
56
+ - @shipfox/redact@0.2.3
57
+ - @shipfox/api-integration-gitea@6.0.0
58
+ - @shipfox/api-integration-github@6.0.0
59
+ - @shipfox/api-integration-linear@6.0.0
60
+ - @shipfox/api-integration-sentry@6.0.0
61
+ - @shipfox/api-integration-webhook@6.0.0
62
+ - @shipfox/api-workspaces-dto@6.0.0
63
+ - @shipfox/api-integration-jira@6.0.0
64
+ - @shipfox/api-auth-context@6.0.0
65
+ - @shipfox/node-fastify@0.2.4
66
+ - @shipfox/inter-module@0.2.0
67
+
3
68
  ## 5.0.0
4
69
 
5
70
  ### Minor Changes
@@ -1,6 +1,11 @@
1
- import type { IntegrationProvider as CoreIntegrationProvider, RegisteredIntegrationProvider as CoreRegisteredIntegrationProvider } from '@shipfox/api-integration-core-dto';
1
+ import type { IntegrationProvider as CoreIntegrationProvider, RegisteredIntegrationProvider as CoreRegisteredIntegrationProvider, WebhookRequestProcessor, WebhookRouteId } from '@shipfox/api-integration-core-dto';
2
2
  import type { RouteExport } from '@shipfox/node-fastify';
3
3
  export type { AgentToolCallInput, AgentToolCatalogEntry, AgentToolJsonSchema, AgentToolSensitivity, AgentToolSession, AgentToolsProvider, IntegrationCapability, IntegrationProviderAdapters, IntegrationProviderKind, OpenAgentToolsSessionInput, } from '@shipfox/api-integration-core-dto';
4
- export type IntegrationProvider = CoreIntegrationProvider<string, RouteExport>;
4
+ export type IntegrationProvider = CoreIntegrationProvider<string, RouteExport> & {
5
+ webhookProcessors?: Array<{
6
+ routeIds: readonly WebhookRouteId[];
7
+ processor: WebhookRequestProcessor;
8
+ }> | undefined;
9
+ };
5
10
  export type RegisteredIntegrationProvider = CoreRegisteredIntegrationProvider<string, RouteExport>;
6
11
  //# sourceMappingURL=provider.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../../../src/core/entities/provider.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,mBAAmB,IAAI,uBAAuB,EAC9C,6BAA6B,IAAI,iCAAiC,EACnE,MAAM,mCAAmC,CAAC;AAC3C,OAAO,KAAK,EAAC,WAAW,EAAC,MAAM,uBAAuB,CAAC;AAEvD,YAAY,EACV,kBAAkB,EAClB,qBAAqB,EACrB,mBAAmB,EACnB,oBAAoB,EACpB,gBAAgB,EAChB,kBAAkB,EAClB,qBAAqB,EACrB,2BAA2B,EAC3B,uBAAuB,EACvB,0BAA0B,GAC3B,MAAM,mCAAmC,CAAC;AAE3C,MAAM,MAAM,mBAAmB,GAAG,uBAAuB,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;AAC/E,MAAM,MAAM,6BAA6B,GAAG,iCAAiC,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC"}
1
+ {"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../../../src/core/entities/provider.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,mBAAmB,IAAI,uBAAuB,EAC9C,6BAA6B,IAAI,iCAAiC,EAClE,uBAAuB,EACvB,cAAc,EACf,MAAM,mCAAmC,CAAC;AAC3C,OAAO,KAAK,EAAC,WAAW,EAAC,MAAM,uBAAuB,CAAC;AAEvD,YAAY,EACV,kBAAkB,EAClB,qBAAqB,EACrB,mBAAmB,EACnB,oBAAoB,EACpB,gBAAgB,EAChB,kBAAkB,EAClB,qBAAqB,EACrB,2BAA2B,EAC3B,uBAAuB,EACvB,0BAA0B,GAC3B,MAAM,mCAAmC,CAAC;AAE3C,MAAM,MAAM,mBAAmB,GAAG,uBAAuB,CAAC,MAAM,EAAE,WAAW,CAAC,GAAG;IAC/E,iBAAiB,CAAC,EACd,KAAK,CAAC;QAAC,QAAQ,EAAE,SAAS,cAAc,EAAE,CAAC;QAAC,SAAS,EAAE,uBAAuB,CAAA;KAAC,CAAC,GAChF,SAAS,CAAC;CACf,CAAC;AACF,MAAM,MAAM,6BAA6B,GAAG,iCAAiC,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/core/entities/provider.ts"],"sourcesContent":["import type {\n IntegrationProvider as CoreIntegrationProvider,\n RegisteredIntegrationProvider as CoreRegisteredIntegrationProvider,\n} from '@shipfox/api-integration-core-dto';\nimport type {RouteExport} from '@shipfox/node-fastify';\n\nexport type {\n AgentToolCallInput,\n AgentToolCatalogEntry,\n AgentToolJsonSchema,\n AgentToolSensitivity,\n AgentToolSession,\n AgentToolsProvider,\n IntegrationCapability,\n IntegrationProviderAdapters,\n IntegrationProviderKind,\n OpenAgentToolsSessionInput,\n} from '@shipfox/api-integration-core-dto';\n\nexport type IntegrationProvider = CoreIntegrationProvider<string, RouteExport>;\nexport type RegisteredIntegrationProvider = CoreRegisteredIntegrationProvider<string, RouteExport>;\n"],"names":[],"mappings":"AAoBA,WAAmG"}
1
+ {"version":3,"sources":["../../../src/core/entities/provider.ts"],"sourcesContent":["import type {\n IntegrationProvider as CoreIntegrationProvider,\n RegisteredIntegrationProvider as CoreRegisteredIntegrationProvider,\n WebhookRequestProcessor,\n WebhookRouteId,\n} from '@shipfox/api-integration-core-dto';\nimport type {RouteExport} from '@shipfox/node-fastify';\n\nexport type {\n AgentToolCallInput,\n AgentToolCatalogEntry,\n AgentToolJsonSchema,\n AgentToolSensitivity,\n AgentToolSession,\n AgentToolsProvider,\n IntegrationCapability,\n IntegrationProviderAdapters,\n IntegrationProviderKind,\n OpenAgentToolsSessionInput,\n} from '@shipfox/api-integration-core-dto';\n\nexport type IntegrationProvider = CoreIntegrationProvider<string, RouteExport> & {\n webhookProcessors?:\n | Array<{routeIds: readonly WebhookRouteId[]; processor: WebhookRequestProcessor}>\n | undefined;\n};\nexport type RegisteredIntegrationProvider = CoreRegisteredIntegrationProvider<string, RouteExport>;\n"],"names":[],"mappings":"AA0BA,WAAmG"}
@@ -16,6 +16,8 @@ export declare class IntegrationConnectionAlreadyExistsError extends Error {
16
16
  constructor(workspaceId: string, provider: IntegrationProviderKind, externalAccountId: string);
17
17
  }
18
18
  export declare class IntegrationCapabilityUnavailableError extends Error {
19
+ readonly capability: IntegrationCapability;
20
+ readonly provider: IntegrationProviderKind;
19
21
  constructor(capability: IntegrationCapability, provider: IntegrationProviderKind);
20
22
  }
21
23
  export declare class IntegrationCheckoutUnsupportedError extends Error {
@@ -23,7 +25,12 @@ export declare class IntegrationCheckoutUnsupportedError extends Error {
23
25
  constructor(provider: IntegrationProviderKind);
24
26
  }
25
27
  export declare class IntegrationProviderUnavailableError extends Error {
28
+ readonly provider: IntegrationProviderKind;
26
29
  constructor(provider: IntegrationProviderKind);
27
30
  }
31
+ export declare class WebhookProcessorNotConfiguredError extends Error {
32
+ readonly routeId: string;
33
+ constructor(routeId: string);
34
+ }
28
35
  export { ConnectionSlugConflictError, IntegrationProviderError, type IntegrationProviderErrorReason };
29
36
  //# sourceMappingURL=errors.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/core/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,2BAA2B,EAC3B,wBAAwB,EACxB,KAAK,8BAA8B,EACpC,MAAM,mCAAmC,CAAC;AAC3C,OAAO,KAAK,EAAC,qBAAqB,EAAE,uBAAuB,EAAC,MAAM,4BAA4B,CAAC;AAE/F,qBAAa,kCAAmC,SAAQ,KAAK;gBAC/C,YAAY,EAAE,MAAM;CAGjC;AAED,qBAAa,kCAAmC,SAAQ,KAAK;gBAC/C,YAAY,EAAE,MAAM;CAGjC;AAED,qBAAa,2CAA4C,SAAQ,KAAK;gBACxD,YAAY,EAAE,MAAM;CAGjC;AAED,qBAAa,uCAAwC,SAAQ,KAAK;aAE9C,WAAW,EAAE,MAAM;aACnB,QAAQ,EAAE,uBAAuB;aACjC,iBAAiB,EAAE,MAAM;gBAFzB,WAAW,EAAE,MAAM,EACnB,QAAQ,EAAE,uBAAuB,EACjC,iBAAiB,EAAE,MAAM;CAK5C;AAED,qBAAa,qCAAsC,SAAQ,KAAK;gBAClD,UAAU,EAAE,qBAAqB,EAAE,QAAQ,EAAE,uBAAuB;CAGjF;AAED,qBAAa,mCAAoC,SAAQ,KAAK;aAChC,QAAQ,EAAE,uBAAuB;gBAAjC,QAAQ,EAAE,uBAAuB;CAG9D;AAED,qBAAa,mCAAoC,SAAQ,KAAK;gBAChD,QAAQ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8B,EAAC,CAAC"}
@@ -22,7 +22,7 @@ export class IntegrationConnectionAlreadyExistsError extends Error {
22
22
  }
23
23
  export class IntegrationCapabilityUnavailableError extends Error {
24
24
  constructor(capability, provider){
25
- super(`Integration provider ${provider} does not expose ${capability}`);
25
+ super(`Integration provider ${provider} does not expose ${capability}`), this.capability = capability, this.provider = provider;
26
26
  }
27
27
  }
28
28
  export class IntegrationCheckoutUnsupportedError extends Error {
@@ -32,7 +32,13 @@ export class IntegrationCheckoutUnsupportedError extends Error {
32
32
  }
33
33
  export class IntegrationProviderUnavailableError extends Error {
34
34
  constructor(provider){
35
- super(`No integration provider registered for ${provider}`);
35
+ super(`No integration provider registered for ${provider}`), this.provider = provider;
36
+ }
37
+ }
38
+ export class WebhookProcessorNotConfiguredError extends Error {
39
+ constructor(routeId){
40
+ super(`No webhook processor is configured for ${routeId}`), this.routeId = routeId;
41
+ this.name = 'WebhookProcessorNotConfiguredError';
36
42
  }
37
43
  }
38
44
  export { ConnectionSlugConflictError, IntegrationProviderError };
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/core/errors.ts"],"sourcesContent":["import {\n ConnectionSlugConflictError,\n IntegrationProviderError,\n type IntegrationProviderErrorReason,\n} from '@shipfox/api-integration-core-dto';\nimport type {IntegrationCapability, IntegrationProviderKind} from '#core/entities/provider.js';\n\nexport class IntegrationConnectionNotFoundError extends Error {\n constructor(connectionId: string) {\n super(`Integration connection not found: ${connectionId}`);\n }\n}\n\nexport class IntegrationConnectionInactiveError extends Error {\n constructor(connectionId: string) {\n super(`Integration connection is not active: ${connectionId}`);\n }\n}\n\nexport class IntegrationConnectionWorkspaceMismatchError extends Error {\n constructor(connectionId: string) {\n super(`Integration connection does not belong to the requested workspace: ${connectionId}`);\n }\n}\n\nexport class IntegrationConnectionAlreadyExistsError extends Error {\n constructor(\n public readonly workspaceId: string,\n public readonly provider: IntegrationProviderKind,\n public readonly externalAccountId: string,\n ) {\n super(`Integration connection already exists: ${workspaceId}/${provider}/${externalAccountId}`);\n this.name = 'IntegrationConnectionAlreadyExistsError';\n }\n}\n\nexport class IntegrationCapabilityUnavailableError extends Error {\n constructor(capability: IntegrationCapability, provider: IntegrationProviderKind) {\n super(`Integration provider ${provider} does not expose ${capability}`);\n }\n}\n\nexport class IntegrationCheckoutUnsupportedError extends Error {\n constructor(public readonly provider: IntegrationProviderKind) {\n super(`Integration provider ${provider} cannot create a checkout spec`);\n }\n}\n\nexport class IntegrationProviderUnavailableError extends Error {\n constructor(provider: IntegrationProviderKind) {\n super(`No integration provider registered for ${provider}`);\n }\n}\n\nexport {ConnectionSlugConflictError, IntegrationProviderError, type IntegrationProviderErrorReason};\n"],"names":["ConnectionSlugConflictError","IntegrationProviderError","IntegrationConnectionNotFoundError","Error","connectionId","IntegrationConnectionInactiveError","IntegrationConnectionWorkspaceMismatchError","IntegrationConnectionAlreadyExistsError","workspaceId","provider","externalAccountId","name","IntegrationCapabilityUnavailableError","capability","IntegrationCheckoutUnsupportedError","IntegrationProviderUnavailableError"],"mappings":"AAAA,SACEA,2BAA2B,EAC3BC,wBAAwB,QAEnB,oCAAoC;AAG3C,OAAO,MAAMC,2CAA2CC;IACtD,YAAYC,YAAoB,CAAE;QAChC,KAAK,CAAC,CAAC,kCAAkC,EAAEA,cAAc;IAC3D;AACF;AAEA,OAAO,MAAMC,2CAA2CF;IACtD,YAAYC,YAAoB,CAAE;QAChC,KAAK,CAAC,CAAC,sCAAsC,EAAEA,cAAc;IAC/D;AACF;AAEA,OAAO,MAAME,oDAAoDH;IAC/D,YAAYC,YAAoB,CAAE;QAChC,KAAK,CAAC,CAAC,mEAAmE,EAAEA,cAAc;IAC5F;AACF;AAEA,OAAO,MAAMG,gDAAgDJ;IAC3D,YACE,AAAgBK,WAAmB,EACnC,AAAgBC,QAAiC,EACjD,AAAgBC,iBAAyB,CACzC;QACA,KAAK,CAAC,CAAC,uCAAuC,EAAEF,YAAY,CAAC,EAAEC,SAAS,CAAC,EAAEC,mBAAmB,QAJ9EF,cAAAA,kBACAC,WAAAA,eACAC,oBAAAA;QAGhB,IAAI,CAACC,IAAI,GAAG;IACd;AACF;AAEA,OAAO,MAAMC,8CAA8CT;IACzD,YAAYU,UAAiC,EAAEJ,QAAiC,CAAE;QAChF,KAAK,CAAC,CAAC,qBAAqB,EAAEA,SAAS,iBAAiB,EAAEI,YAAY;IACxE;AACF;AAEA,OAAO,MAAMC,4CAA4CX;IACvD,YAAY,AAAgBM,QAAiC,CAAE;QAC7D,KAAK,CAAC,CAAC,qBAAqB,EAAEA,SAAS,8BAA8B,CAAC,QAD5CA,WAAAA;IAE5B;AACF;AAEA,OAAO,MAAMM,4CAA4CZ;IACvD,YAAYM,QAAiC,CAAE;QAC7C,KAAK,CAAC,CAAC,uCAAuC,EAAEA,UAAU;IAC5D;AACF;AAEA,SAAQT,2BAA2B,EAAEC,wBAAwB,GAAuC"}
1
+ {"version":3,"sources":["../../src/core/errors.ts"],"sourcesContent":["import {\n ConnectionSlugConflictError,\n IntegrationProviderError,\n type IntegrationProviderErrorReason,\n} from '@shipfox/api-integration-core-dto';\nimport type {IntegrationCapability, IntegrationProviderKind} from '#core/entities/provider.js';\n\nexport class IntegrationConnectionNotFoundError extends Error {\n constructor(connectionId: string) {\n super(`Integration connection not found: ${connectionId}`);\n }\n}\n\nexport class IntegrationConnectionInactiveError extends Error {\n constructor(connectionId: string) {\n super(`Integration connection is not active: ${connectionId}`);\n }\n}\n\nexport class IntegrationConnectionWorkspaceMismatchError extends Error {\n constructor(connectionId: string) {\n super(`Integration connection does not belong to the requested workspace: ${connectionId}`);\n }\n}\n\nexport class IntegrationConnectionAlreadyExistsError extends Error {\n constructor(\n public readonly workspaceId: string,\n public readonly provider: IntegrationProviderKind,\n public readonly externalAccountId: string,\n ) {\n super(`Integration connection already exists: ${workspaceId}/${provider}/${externalAccountId}`);\n this.name = 'IntegrationConnectionAlreadyExistsError';\n }\n}\n\nexport class IntegrationCapabilityUnavailableError extends Error {\n constructor(\n public readonly capability: IntegrationCapability,\n public readonly provider: IntegrationProviderKind,\n ) {\n super(`Integration provider ${provider} does not expose ${capability}`);\n }\n}\n\nexport class IntegrationCheckoutUnsupportedError extends Error {\n constructor(public readonly provider: IntegrationProviderKind) {\n super(`Integration provider ${provider} cannot create a checkout spec`);\n }\n}\n\nexport class IntegrationProviderUnavailableError extends Error {\n constructor(public readonly provider: IntegrationProviderKind) {\n super(`No integration provider registered for ${provider}`);\n }\n}\n\nexport class WebhookProcessorNotConfiguredError extends Error {\n constructor(public readonly routeId: string) {\n super(`No webhook processor is configured for ${routeId}`);\n this.name = 'WebhookProcessorNotConfiguredError';\n }\n}\n\nexport {ConnectionSlugConflictError, IntegrationProviderError, type IntegrationProviderErrorReason};\n"],"names":["ConnectionSlugConflictError","IntegrationProviderError","IntegrationConnectionNotFoundError","Error","connectionId","IntegrationConnectionInactiveError","IntegrationConnectionWorkspaceMismatchError","IntegrationConnectionAlreadyExistsError","workspaceId","provider","externalAccountId","name","IntegrationCapabilityUnavailableError","capability","IntegrationCheckoutUnsupportedError","IntegrationProviderUnavailableError","WebhookProcessorNotConfiguredError","routeId"],"mappings":"AAAA,SACEA,2BAA2B,EAC3BC,wBAAwB,QAEnB,oCAAoC;AAG3C,OAAO,MAAMC,2CAA2CC;IACtD,YAAYC,YAAoB,CAAE;QAChC,KAAK,CAAC,CAAC,kCAAkC,EAAEA,cAAc;IAC3D;AACF;AAEA,OAAO,MAAMC,2CAA2CF;IACtD,YAAYC,YAAoB,CAAE;QAChC,KAAK,CAAC,CAAC,sCAAsC,EAAEA,cAAc;IAC/D;AACF;AAEA,OAAO,MAAME,oDAAoDH;IAC/D,YAAYC,YAAoB,CAAE;QAChC,KAAK,CAAC,CAAC,mEAAmE,EAAEA,cAAc;IAC5F;AACF;AAEA,OAAO,MAAMG,gDAAgDJ;IAC3D,YACE,AAAgBK,WAAmB,EACnC,AAAgBC,QAAiC,EACjD,AAAgBC,iBAAyB,CACzC;QACA,KAAK,CAAC,CAAC,uCAAuC,EAAEF,YAAY,CAAC,EAAEC,SAAS,CAAC,EAAEC,mBAAmB,QAJ9EF,cAAAA,kBACAC,WAAAA,eACAC,oBAAAA;QAGhB,IAAI,CAACC,IAAI,GAAG;IACd;AACF;AAEA,OAAO,MAAMC,8CAA8CT;IACzD,YACE,AAAgBU,UAAiC,EACjD,AAAgBJ,QAAiC,CACjD;QACA,KAAK,CAAC,CAAC,qBAAqB,EAAEA,SAAS,iBAAiB,EAAEI,YAAY,QAHtDA,aAAAA,iBACAJ,WAAAA;IAGlB;AACF;AAEA,OAAO,MAAMK,4CAA4CX;IACvD,YAAY,AAAgBM,QAAiC,CAAE;QAC7D,KAAK,CAAC,CAAC,qBAAqB,EAAEA,SAAS,8BAA8B,CAAC,QAD5CA,WAAAA;IAE5B;AACF;AAEA,OAAO,MAAMM,4CAA4CZ;IACvD,YAAY,AAAgBM,QAAiC,CAAE;QAC7D,KAAK,CAAC,CAAC,uCAAuC,EAAEA,UAAU,QADhCA,WAAAA;IAE5B;AACF;AAEA,OAAO,MAAMO,2CAA2Cb;IACtD,YAAY,AAAgBc,OAAe,CAAE;QAC3C,KAAK,CAAC,CAAC,uCAAuC,EAAEA,SAAS,QAD/BA,UAAAA;QAE1B,IAAI,CAACN,IAAI,GAAG;IACd;AACF;AAEA,SAAQX,2BAA2B,EAAEC,wBAAwB,GAAuC"}
package/dist/index.d.ts CHANGED
@@ -1,16 +1,19 @@
1
- import type { ShipfoxModule } from '@shipfox/node-module';
1
+ import { type WebhookRequestProcessor } from '@shipfox/api-integration-core-dto';
2
+ import type { WorkflowsModuleClient } from '@shipfox/api-workflows-dto/inter-module';
3
+ import type { WorkspacesInterModuleClient } from '@shipfox/api-workspaces-dto/inter-module';
4
+ import type { ModuleService, ShipfoxModule } from '@shipfox/node-module';
2
5
  import type { IntegrationProvider } from '#core/entities/provider.js';
3
6
  import { type IntegrationProviderRegistry } from '#core/providers/registry.js';
4
7
  import { type IntegrationSourceControlService } from '#core/source-control-service.js';
5
- import { type LeasedAgentStepLoader } from '#presentation/routes/index.js';
6
8
  import type { IntegrationModuleParts, IntegrationProviderSecrets } from '#providers/types.js';
9
+ export type { StoredWebhookRequest, WebhookProcessingResult, WebhookRequestProcessor, WebhookRouteId, } from '@shipfox/api-integration-core-dto';
7
10
  export { buildProviderRepositoryId, MAX_REPOSITORY_FILE_BYTES, parseProviderRepositoryId, } from '@shipfox/api-integration-core-dto';
8
11
  export type { AgentToolCatalogs, AgentToolSelectionCatalogs, LoadWorkspaceConnectionSnapshot, WorkspaceConnectionSnapshot, WorkspaceConnectionSnapshotEntry, } from '#core/agent-tool-selection.js';
9
12
  export { buildAgentToolCatalogs, buildAgentToolSelectionCatalogs, createWorkspaceConnectionSnapshotLoader, } from '#core/agent-tool-selection.js';
10
13
  export type { IntegrationConnection, IntegrationConnectionLifecycleStatus, } from '#core/entities/connection.js';
11
14
  export type { IntegrationCapability, IntegrationProvider, IntegrationProviderAdapters, IntegrationProviderKind, RegisteredIntegrationProvider, } from '#core/entities/provider.js';
12
15
  export type { IntegrationProviderErrorReason } from '#core/errors.js';
13
- export { ConnectionSlugConflictError, IntegrationCapabilityUnavailableError, IntegrationCheckoutUnsupportedError, IntegrationConnectionInactiveError, IntegrationConnectionNotFoundError, IntegrationConnectionWorkspaceMismatchError, IntegrationProviderError, IntegrationProviderUnavailableError, } from '#core/errors.js';
16
+ export { ConnectionSlugConflictError, IntegrationCapabilityUnavailableError, IntegrationCheckoutUnsupportedError, IntegrationConnectionInactiveError, IntegrationConnectionNotFoundError, IntegrationConnectionWorkspaceMismatchError, IntegrationProviderError, IntegrationProviderUnavailableError, WebhookProcessorNotConfiguredError, } from '#core/errors.js';
14
17
  export type { AgentToolCallInput, AgentToolCatalogEntry, AgentToolCatalogMethod, AgentToolJsonSchema, AgentToolSensitivity, AgentToolSession, AgentToolsProvider, OpenAgentToolsSessionInput, } from '#core/providers/agent-tools.js';
15
18
  export { redactCheckoutSpec } from '#core/providers/redact-checkout-spec.js';
16
19
  export type { IntegrationProviderRegistry } from '#core/providers/registry.js';
@@ -31,9 +34,18 @@ export interface CreateIntegrationsModuleOptions {
31
34
  */
32
35
  parts?: IntegrationModuleParts[] | undefined;
33
36
  secrets?: IntegrationProviderSecrets | undefined;
37
+ workspaces?: WorkspacesInterModuleClient | undefined;
34
38
  agentTools?: {
35
- loadLeasedAgentStep: LeasedAgentStepLoader;
39
+ workflows: WorkflowsModuleClient;
36
40
  } | undefined;
41
+ webhookDeliverySource?: WebhookDeliverySource | undefined;
42
+ }
43
+ /**
44
+ * Hosted runtimes implement this port to receive stored webhook requests. The
45
+ * integration module starts its returned service after migrations complete.
46
+ */
47
+ export interface WebhookDeliverySource {
48
+ createService(processor: WebhookRequestProcessor): ModuleService;
37
49
  }
38
50
  export interface IntegrationsContext {
39
51
  module: ShipfoxModule;
@@ -42,6 +54,7 @@ export interface IntegrationsContext {
42
54
  sourceControl: IntegrationSourceControlService;
43
55
  };
44
56
  sourceControl: IntegrationSourceControlService;
57
+ webhookProcessor: WebhookRequestProcessor;
45
58
  /**
46
59
  * Runs every enabled provider's one-shot boot-time tasks, after modules are initialized
47
60
  * (migrations done). Failures are isolated and logged, never rethrown, so a provider task
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAC,aAAa,EAAC,MAAM,sBAAsB,CAAC;AAExD,OAAO,KAAK,EAAC,mBAAmB,EAAC,MAAM,4BAA4B,CAAC;AACpE,OAAO,EAEL,KAAK,2BAA2B,EACjC,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAEL,KAAK,+BAA+B,EACrC,MAAM,iCAAiC,CAAC;AAKzC,OAAO,EAA0B,KAAK,qBAAqB,EAAC,MAAM,+BAA+B,CAAC;AAElG,OAAO,KAAK,EAAC,sBAAsB,EAAE,0BAA0B,EAAC,MAAM,qBAAqB,CAAC;AAO5F,OAAO,EACL,yBAAyB,EACzB,yBAAyB,EACzB,yBAAyB,GAC1B,M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S,EAAE,qBAAqB,CAAC;KAClC,GACD,SAAS,CAAC;IACd,qBAAqB,CAAC,EAAE,qBAAqB,GAAG,SAAS,CAAC;CAC3D;AAED;;;GAGG;AACH,MAAM,WAAW,qBAAqB;IACpC,aAAa,CAAC,SAAS,EAAE,uBAAuB,GAAG,aAAa,CAAC;CAClE;AAED,MAAM,WAAW,mBAAmB;IAClC,MAAM,EAAE,aAAa,CAAC;IACtB,QAAQ,EAAE,2BAA2B,CAAC;IACtC,YAAY,EAAE;QACZ,aAAa,EAAE,+BAA+B,CAAC;KAChD,CAAC;IACF,aAAa,EAAE,+BAA+B,CAAC;IAC/C,gBAAgB,EAAE,uBAAuB,CAAC;IAC1C;;;;OAIG;IACH,eAAe,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CACtC;AAED,wBAAsB,wBAAwB,CAC5C,OAAO,GAAE,+BAAoC,GAC5C,OAAO,CAAC,aAAa,CAAC,CAExB;AAED,wBAAsB,yBAAyB,CAC7C,OAAO,GAAE,+BAAoC,GAC5C,OAAO,CAAC,mBAAmB,CAAC,CAkG9B"}
package/dist/index.js CHANGED
@@ -2,12 +2,14 @@ import { dirname, resolve } from 'node:path';
2
2
  import { fileURLToPath } from 'node:url';
3
3
  import { integrationsEventSchemas } from '@shipfox/api-integration-core-dto';
4
4
  import { logger } from '@shipfox/node-opentelemetry';
5
+ import { WebhookProcessorNotConfiguredError } from '#core/errors.js';
5
6
  import { createIntegrationProviderRegistry } from '#core/providers/registry.js';
6
7
  import { createSourceControlIntegrationService } from '#core/source-control-service.js';
7
8
  import { getIntegrationConnectionById } from '#db/connections.js';
8
9
  import { db } from '#db/db.js';
9
10
  import { migrationsPath } from '#db/migrations.js';
10
11
  import { integrationsOutbox } from '#db/schema/outbox.js';
12
+ import { createIntegrationsInterModulePresentation } from '#presentation/inter-module.js';
11
13
  import { createIntegrationRoutes } from '#presentation/routes/index.js';
12
14
  import { loadEnabledProviderModules } from '#providers/modules.js';
13
15
  import { createIntegrationsMaintenanceActivities } from '#temporal/activities/index.js';
@@ -16,7 +18,7 @@ const packageRoot = resolve(dirname(fileURLToPath(import.meta.url)), '..');
16
18
  const maintenanceWorkflowsPath = resolve(packageRoot, 'dist/temporal/workflows/index.js');
17
19
  export { buildProviderRepositoryId, MAX_REPOSITORY_FILE_BYTES, parseProviderRepositoryId } from '@shipfox/api-integration-core-dto';
18
20
  export { buildAgentToolCatalogs, buildAgentToolSelectionCatalogs, createWorkspaceConnectionSnapshotLoader } from '#core/agent-tool-selection.js';
19
- export { ConnectionSlugConflictError, IntegrationCapabilityUnavailableError, IntegrationCheckoutUnsupportedError, IntegrationConnectionInactiveError, IntegrationConnectionNotFoundError, IntegrationConnectionWorkspaceMismatchError, IntegrationProviderError, IntegrationProviderUnavailableError } from '#core/errors.js';
21
+ export { ConnectionSlugConflictError, IntegrationCapabilityUnavailableError, IntegrationCheckoutUnsupportedError, IntegrationConnectionInactiveError, IntegrationConnectionNotFoundError, IntegrationConnectionWorkspaceMismatchError, IntegrationProviderError, IntegrationProviderUnavailableError, WebhookProcessorNotConfiguredError } from '#core/errors.js';
20
22
  export { redactCheckoutSpec } from '#core/providers/redact-checkout-spec.js';
21
23
  export { createSourceControlIntegrationService } from '#core/source-control-service.js';
22
24
  export { getIntegrationConnectionById } from '#db/connections.js';
@@ -26,16 +28,27 @@ export async function createIntegrationsModule(options = {}) {
26
28
  return (await createIntegrationsContext(options)).module;
27
29
  }
28
30
  export async function createIntegrationsContext(options = {}) {
31
+ const workspaces = options.workspaces;
29
32
  const parts = options.parts ?? (options.providers ? options.providers.map((provider)=>({
30
- provider
33
+ provider,
34
+ webhookProcessors: provider.webhookProcessors
31
35
  })) : await loadEnabledProviderModules({
32
- secrets: options.secrets
36
+ secrets: options.secrets,
37
+ ...workspaces ? {
38
+ requireActiveWorkspaceMembership: (input)=>workspaces.requireActiveMembership({
39
+ ...input,
40
+ memberships: [
41
+ ...input.memberships
42
+ ]
43
+ })
44
+ } : {}
33
45
  }));
34
46
  const registry = createIntegrationProviderRegistry(parts.map((part)=>part.provider));
35
47
  const sourceControl = createSourceControlIntegrationService({
36
48
  registry,
37
49
  getIntegrationConnectionById
38
50
  });
51
+ const webhookProcessor = createComposedWebhookProcessor(parts.flatMap((part)=>part.webhookProcessors ?? []));
39
52
  async function runStartupTasks() {
40
53
  for (const task of parts.flatMap((part)=>part.startupTasks ?? [])){
41
54
  // A provider convenience must never gate API boot.
@@ -50,6 +63,12 @@ export async function createIntegrationsContext(options = {}) {
50
63
  }
51
64
  const module = {
52
65
  name: 'integrations',
66
+ interModulePresentations: [
67
+ createIntegrationsInterModulePresentation({
68
+ registry,
69
+ sourceControl
70
+ })
71
+ ],
53
72
  startupTasks: runStartupTasks,
54
73
  database: [
55
74
  {
@@ -62,7 +81,7 @@ export async function createIntegrationsContext(options = {}) {
62
81
  ],
63
82
  routes: createIntegrationRoutes(registry, sourceControl, {
64
83
  agentTools: options.agentTools ? {
65
- loadLeasedAgentStep: options.agentTools.loadLeasedAgentStep,
84
+ workflows: options.agentTools.workflows,
66
85
  getIntegrationConnectionById
67
86
  } : undefined
68
87
  }),
@@ -89,7 +108,12 @@ export async function createIntegrationsContext(options = {}) {
89
108
  ]
90
109
  },
91
110
  ...parts.flatMap((part)=>part.workers ?? [])
92
- ]
111
+ ],
112
+ ...options.webhookDeliverySource ? {
113
+ services: [
114
+ options.webhookDeliverySource.createService(webhookProcessor)
115
+ ]
116
+ } : {}
93
117
  };
94
118
  return {
95
119
  module,
@@ -98,8 +122,29 @@ export async function createIntegrationsContext(options = {}) {
98
122
  sourceControl
99
123
  },
100
124
  sourceControl,
125
+ webhookProcessor,
101
126
  runStartupTasks
102
127
  };
103
128
  }
129
+ function createComposedWebhookProcessor(registrations) {
130
+ const processors = new Map();
131
+ for (const registration of registrations){
132
+ for (const routeId of registration.routeIds){
133
+ if (processors.has(routeId)) {
134
+ throw new Error(`Webhook processor is registered more than once for ${routeId}`);
135
+ }
136
+ processors.set(routeId, registration.processor);
137
+ }
138
+ }
139
+ return {
140
+ async process (request) {
141
+ const processor = processors.get(request.route_id);
142
+ if (!processor) {
143
+ throw new WebhookProcessorNotConfiguredError(request.route_id);
144
+ }
145
+ return await processor.process(request);
146
+ }
147
+ };
148
+ }
104
149
 
105
150
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import {dirname, resolve} from 'node:path';\nimport {fileURLToPath} from 'node:url';\nimport {integrationsEventSchemas} from '@shipfox/api-integration-core-dto';\nimport type {ShipfoxModule} from '@shipfox/node-module';\nimport {logger} from '@shipfox/node-opentelemetry';\nimport type {IntegrationProvider} from '#core/entities/provider.js';\nimport {\n createIntegrationProviderRegistry,\n type IntegrationProviderRegistry,\n} from '#core/providers/registry.js';\nimport {\n createSourceControlIntegrationService,\n type IntegrationSourceControlService,\n} from '#core/source-control-service.js';\nimport {getIntegrationConnectionById} from '#db/connections.js';\nimport {db} from '#db/db.js';\nimport {migrationsPath} from '#db/migrations.js';\nimport {integrationsOutbox} from '#db/schema/outbox.js';\nimport {createIntegrationRoutes, type LeasedAgentStepLoader} from '#presentation/routes/index.js';\nimport {loadEnabledProviderModules} from '#providers/modules.js';\nimport type {IntegrationModuleParts, IntegrationProviderSecrets} from '#providers/types.js';\nimport {createIntegrationsMaintenanceActivities} from '#temporal/activities/index.js';\nimport {INTEGRATIONS_MAINTENANCE_TASK_QUEUE} from '#temporal/constants.js';\n\nconst packageRoot = resolve(dirname(fileURLToPath(import.meta.url)), '..');\nconst maintenanceWorkflowsPath = resolve(packageRoot, 'dist/temporal/workflows/index.js');\n\nexport {\n buildProviderRepositoryId,\n MAX_REPOSITORY_FILE_BYTES,\n parseProviderRepositoryId,\n} from '@shipfox/api-integration-core-dto';\nexport type {\n AgentToolCatalogs,\n AgentToolSelectionCatalogs,\n LoadWorkspaceConnectionSnapshot,\n WorkspaceConnectionSnapshot,\n WorkspaceConnectionSnapshotEntry,\n} from '#core/agent-tool-selection.js';\nexport {\n buildAgentToolCatalogs,\n buildAgentToolSelectionCatalogs,\n createWorkspaceConnectionSnapshotLoader,\n} from '#core/agent-tool-selection.js';\nexport type {\n IntegrationConnection,\n IntegrationConnectionLifecycleStatus,\n} from '#core/entities/connection.js';\nexport type {\n IntegrationCapability,\n IntegrationProvider,\n IntegrationProviderAdapters,\n IntegrationProviderKind,\n RegisteredIntegrationProvider,\n} from '#core/entities/provider.js';\nexport type {IntegrationProviderErrorReason} from '#core/errors.js';\nexport {\n ConnectionSlugConflictError,\n IntegrationCapabilityUnavailableError,\n IntegrationCheckoutUnsupportedError,\n IntegrationConnectionInactiveError,\n IntegrationConnectionNotFoundError,\n IntegrationConnectionWorkspaceMismatchError,\n IntegrationProviderError,\n IntegrationProviderUnavailableError,\n} from '#core/errors.js';\nexport type {\n AgentToolCallInput,\n AgentToolCatalogEntry,\n AgentToolCatalogMethod,\n AgentToolJsonSchema,\n AgentToolSensitivity,\n AgentToolSession,\n AgentToolsProvider,\n OpenAgentToolsSessionInput,\n} from '#core/providers/agent-tools.js';\nexport {redactCheckoutSpec} from '#core/providers/redact-checkout-spec.js';\nexport type {IntegrationProviderRegistry} from '#core/providers/registry.js';\nexport type {\n CheckoutCredentials,\n CheckoutPermissions,\n CheckoutSpec,\n CreateCheckoutSpecInput,\n FetchFileInput,\n FileEntry,\n FilePage,\n FileSnapshot,\n ListFilesInput,\n ListRepositoriesInput,\n RepositoryPage,\n RepositorySnapshot,\n RepositoryVisibility,\n ResolveRepositoryInput,\n SourceControlProvider,\n} from '#core/providers/source-control.js';\nexport type {IntegrationSourceControlService} from '#core/source-control-service.js';\nexport {createSourceControlIntegrationService} from '#core/source-control-service.js';\nexport type {GetIntegrationConnectionByIdFn} from '#db/connections.js';\nexport {getIntegrationConnectionById} from '#db/connections.js';\nexport type {\n ClaimWebhookDeliveryFn,\n PublishIntegrationEventReceivedFn,\n PublishIntegrationEventReceivedParams,\n PublishIntegrationEventReceivedResult,\n PublishSourcePushFn,\n PublishSourcePushParams,\n RecordDeliveryOnlyFn,\n RecordDeliveryOnlyParams,\n} from '#db/webhook-deliveries.js';\nexport {claimWebhookDelivery, pruneWebhookDeliveries} from '#db/webhook-deliveries.js';\nexport {integrationRouteErrorHandler} from '#presentation/routes/errors.js';\n\nexport interface CreateIntegrationsModuleOptions {\n providers?: IntegrationProvider[] | undefined;\n /**\n * Pre-built module parts, bypassing config-gated provider loading. Test-only seam\n * for exercising a provider's database, workers, or startup tasks directly. Takes\n * precedence over `providers`.\n */\n parts?: IntegrationModuleParts[] | undefined;\n secrets?: IntegrationProviderSecrets | undefined;\n agentTools?:\n | {\n loadLeasedAgentStep: LeasedAgentStepLoader;\n }\n | undefined;\n}\n\nexport interface IntegrationsContext {\n module: ShipfoxModule;\n registry: IntegrationProviderRegistry;\n capabilities: {\n sourceControl: IntegrationSourceControlService;\n };\n sourceControl: IntegrationSourceControlService;\n /**\n * Runs every enabled provider's one-shot boot-time tasks, after modules are initialized\n * (migrations done). Failures are isolated and logged, never rethrown, so a provider task\n * can never gate API boot. No-op when no enabled provider contributes a task.\n */\n runStartupTasks: () => Promise<void>;\n}\n\nexport async function createIntegrationsModule(\n options: CreateIntegrationsModuleOptions = {},\n): Promise<ShipfoxModule> {\n return (await createIntegrationsContext(options)).module;\n}\n\nexport async function createIntegrationsContext(\n options: CreateIntegrationsModuleOptions = {},\n): Promise<IntegrationsContext> {\n const parts: IntegrationModuleParts[] =\n options.parts ??\n (options.providers\n ? options.providers.map((provider) => ({provider}))\n : await loadEnabledProviderModules({secrets: options.secrets}));\n\n const registry = createIntegrationProviderRegistry(parts.map((part) => part.provider));\n const sourceControl = createSourceControlIntegrationService({\n registry,\n getIntegrationConnectionById,\n });\n\n async function runStartupTasks(): Promise<void> {\n for (const task of parts.flatMap((part) => part.startupTasks ?? [])) {\n // A provider convenience must never gate API boot.\n try {\n await task();\n } catch (error) {\n logger().error({err: error}, 'Integration startup task failed, continuing boot');\n }\n }\n }\n\n const module: ShipfoxModule = {\n name: 'integrations',\n startupTasks: runStartupTasks,\n database: [\n {db, migrationsPath},\n ...parts.flatMap((part) => (part.database ? [part.database] : [])),\n ],\n routes: createIntegrationRoutes(registry, sourceControl, {\n agentTools: options.agentTools\n ? {\n loadLeasedAgentStep: options.agentTools.loadLeasedAgentStep,\n getIntegrationConnectionById,\n }\n : undefined,\n }),\n e2eRoutes: parts.flatMap((part) => part.e2eRoutes ?? []),\n publishers: [\n {name: 'integrations', table: integrationsOutbox, db, eventSchemas: integrationsEventSchemas},\n ],\n workers: [\n {\n taskQueue: INTEGRATIONS_MAINTENANCE_TASK_QUEUE,\n workflowsPath: maintenanceWorkflowsPath,\n activities: createIntegrationsMaintenanceActivities,\n workflows: [\n {\n name: 'pruneWebhookDeliveriesCron',\n id: 'integrations-prune-webhook-deliveries',\n cronSchedule: '0 3 * * *',\n },\n ],\n },\n ...parts.flatMap((part) => part.workers ?? []),\n ],\n };\n\n return {module, registry, capabilities: {sourceControl}, sourceControl, runStartupTasks};\n}\n"],"names":["dirname","resolve","fileURLToPath","integrationsEventSchemas","logger","createIntegrationProviderRegistry","createSourceControlIntegrationService","getIntegrationConnectionById","db","migrationsPath","integrationsOutbox","createIntegrationRoutes","loadEnabledProviderModules","createIntegrationsMaintenanceActivities","INTEGRATIONS_MAINTENANCE_TASK_QUEUE","packageRoot","url","maintenanceWorkflowsPath","buildProviderRepositoryId","MAX_REPOSITORY_FILE_BYTES","parseProviderRepositoryId","buildAgentToolCatalogs","buildAgentToolSelectionCatalogs","createWorkspaceConnectionSnapshotLoader","ConnectionSlugConflictError","IntegrationCapabilityUnavailableError","IntegrationCheckoutUnsupportedError","IntegrationConnectionInactiveError","IntegrationConnectionNotFoundError","IntegrationConnectionWorkspaceMismatchError","IntegrationProviderError","IntegrationProviderUnavailableError","redactCheckoutSpec","claimWebhookDelivery","pruneWebhookDeliveries","integrationRouteErrorHandler","createIntegrationsModule","options","createIntegrationsContext","module","parts","providers","map","provider","secrets","registry","part","sourceControl","runStartupTasks","task","flatMap","startupTasks","error","err","name","database","routes","agentTools","loadLeasedAgentStep","undefined","e2eRoutes","publishers","table","eventSchemas","workers","taskQueue","workflowsPath","activities","workflows","id","cronSchedule","capabilities"],"mappings":"AAAA,SAAQA,OAAO,EAAEC,OAAO,QAAO,YAAY;AAC3C,SAAQC,aAAa,QAAO,WAAW;AACvC,SAAQC,wBAAwB,QAAO,oCAAoC;AAE3E,SAAQC,MAAM,QAAO,8BAA8B;AAEnD,SACEC,iCAAiC,QAE5B,8BAA8B;AACrC,SACEC,qCAAqC,QAEhC,kCAAkC;AACzC,SAAQC,4BAA4B,QAAO,qBAAqB;AAChE,SAAQC,EAAE,QAAO,YAAY;AAC7B,SAAQC,cAAc,QAAO,oBAAoB;AACjD,SAAQC,kBAAkB,QAAO,uBAAuB;AACxD,SAAQC,uBAAuB,QAAmC,gCAAgC;AAClG,SAAQC,0BAA0B,QAAO,wBAAwB;AAEjE,SAAQC,uCAAuC,QAAO,gCAAgC;AACtF,SAAQC,mCAAmC,QAAO,yBAAyB;AAE3E,MAAMC,cAAcd,QAAQD,QAAQE,cAAc,YAAYc,GAAG,IAAI;AACrE,MAAMC,2BAA2BhB,QAAQc,aAAa;AAEtD,SACEG,yBAAyB,EACzBC,yBAAyB,EACzBC,yBAAyB,QACpB,oCAAoC;AAQ3C,SACEC,sBAAsB,EACtBC,+BAA+B,EAC/BC,uCAAuC,QAClC,gCAAgC;AAavC,SACEC,2BAA2B,EAC3BC,qCAAqC,EACrCC,mCAAmC,EACnCC,kCAAkC,EAClCC,kCAAkC,EAClCC,2CAA2C,EAC3CC,wBAAwB,EACxBC,mCAAmC,QAC9B,kBAAkB;AAWzB,SAAQC,kBAAkB,QAAO,0CAA0C;AAoB3E,SAAQ1B,qCAAqC,QAAO,kCAAkC;AAEtF,SAAQC,4BAA4B,QAAO,qBAAqB;AAWhE,SAAQ0B,oBAAoB,EAAEC,sBAAsB,QAAO,4BAA4B;AACvF,SAAQC,4BAA4B,QAA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AIuD,cAAc5D;YAAwB;SAC7F;QACD6D,SAAS;YACP;gBACEC,WAAWnD;gBACXoD,eAAejD;gBACfkD,YAAYtD;gBACZuD,WAAW;oBACT;wBACEd,MAAM;wBACNe,IAAI;wBACJC,cAAc;oBAChB;iBACD;YACH;eACG9B,MAAMU,OAAO,CAAC,CAACJ,OAASA,KAAKkB,OAAO,IAAI,EAAE;SAC9C;IACH;IAEA,OAAO;QAACzB;QAAQM;QAAU0B,cAAc;YAACxB;QAAa;QAAGA;QAAeC;IAAe;AACzF"}
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import {dirname, resolve} from 'node:path';\nimport {fileURLToPath} from 'node:url';\nimport {\n integrationsEventSchemas,\n type StoredWebhookRequest,\n type WebhookProcessingResult,\n type WebhookRequestProcessor,\n type WebhookRouteId,\n} from '@shipfox/api-integration-core-dto';\nimport type {WorkflowsModuleClient} from '@shipfox/api-workflows-dto/inter-module';\nimport type {WorkspacesInterModuleClient} from '@shipfox/api-workspaces-dto/inter-module';\nimport type {ModuleService, ShipfoxModule} from '@shipfox/node-module';\nimport {logger} from '@shipfox/node-opentelemetry';\nimport type {IntegrationProvider} from '#core/entities/provider.js';\nimport {WebhookProcessorNotConfiguredError} from '#core/errors.js';\nimport {\n createIntegrationProviderRegistry,\n type IntegrationProviderRegistry,\n} from '#core/providers/registry.js';\nimport {\n createSourceControlIntegrationService,\n type IntegrationSourceControlService,\n} from '#core/source-control-service.js';\nimport {getIntegrationConnectionById} from '#db/connections.js';\nimport {db} from '#db/db.js';\nimport {migrationsPath} from '#db/migrations.js';\nimport {integrationsOutbox} from '#db/schema/outbox.js';\nimport {createIntegrationsInterModulePresentation} from '#presentation/inter-module.js';\nimport {createIntegrationRoutes} from '#presentation/routes/index.js';\nimport {loadEnabledProviderModules} from '#providers/modules.js';\nimport type {\n IntegrationModuleParts,\n IntegrationProviderSecrets,\n WebhookProcessorRegistration,\n} from '#providers/types.js';\nimport {createIntegrationsMaintenanceActivities} from '#temporal/activities/index.js';\nimport {INTEGRATIONS_MAINTENANCE_TASK_QUEUE} from '#temporal/constants.js';\n\nconst packageRoot = resolve(dirname(fileURLToPath(import.meta.url)), '..');\nconst maintenanceWorkflowsPath = resolve(packageRoot, 'dist/temporal/workflows/index.js');\n\nexport type {\n StoredWebhookRequest,\n WebhookProcessingResult,\n WebhookRequestProcessor,\n WebhookRouteId,\n} from '@shipfox/api-integration-core-dto';\nexport {\n buildProviderRepositoryId,\n MAX_REPOSITORY_FILE_BYTES,\n parseProviderRepositoryId,\n} from '@shipfox/api-integration-core-dto';\nexport type {\n AgentToolCatalogs,\n AgentToolSelectionCatalogs,\n LoadWorkspaceConnectionSnapshot,\n WorkspaceConnectionSnapshot,\n WorkspaceConnectionSnapshotEntry,\n} from '#core/agent-tool-selection.js';\nexport {\n buildAgentToolCatalogs,\n buildAgentToolSelectionCatalogs,\n createWorkspaceConnectionSnapshotLoader,\n} from '#core/agent-tool-selection.js';\nexport type {\n IntegrationConnection,\n IntegrationConnectionLifecycleStatus,\n} from '#core/entities/connection.js';\nexport type {\n IntegrationCapability,\n IntegrationProvider,\n IntegrationProviderAdapters,\n IntegrationProviderKind,\n RegisteredIntegrationProvider,\n} from '#core/entities/provider.js';\nexport type {IntegrationProviderErrorReason} from '#core/errors.js';\nexport {\n ConnectionSlugConflictError,\n IntegrationCapabilityUnavailableError,\n IntegrationCheckoutUnsupportedError,\n IntegrationConnectionInactiveError,\n IntegrationConnectionNotFoundError,\n IntegrationConnectionWorkspaceMismatchError,\n IntegrationProviderError,\n IntegrationProviderUnavailableError,\n WebhookProcessorNotConfiguredError,\n} from '#core/errors.js';\nexport type {\n AgentToolCallInput,\n AgentToolCatalogEntry,\n AgentToolCatalogMethod,\n AgentToolJsonSchema,\n AgentToolSensitivity,\n AgentToolSession,\n AgentToolsProvider,\n OpenAgentToolsSessionInput,\n} from '#core/providers/agent-tools.js';\nexport {redactCheckoutSpec} from '#core/providers/redact-checkout-spec.js';\nexport type {IntegrationProviderRegistry} from '#core/providers/registry.js';\nexport type {\n CheckoutCredentials,\n CheckoutPermissions,\n CheckoutSpec,\n CreateCheckoutSpecInput,\n FetchFileInput,\n FileEntry,\n FilePage,\n FileSnapshot,\n ListFilesInput,\n ListRepositoriesInput,\n RepositoryPage,\n RepositorySnapshot,\n RepositoryVisibility,\n ResolveRepositoryInput,\n SourceControlProvider,\n} from '#core/providers/source-control.js';\nexport type {IntegrationSourceControlService} from '#core/source-control-service.js';\nexport {createSourceControlIntegrationService} from '#core/source-control-service.js';\nexport type {GetIntegrationConnectionByIdFn} from '#db/connections.js';\nexport {getIntegrationConnectionById} from '#db/connections.js';\nexport type {\n ClaimWebhookDeliveryFn,\n PublishIntegrationEventReceivedFn,\n PublishIntegrationEventReceivedParams,\n PublishIntegrationEventReceivedResult,\n PublishSourcePushFn,\n PublishSourcePushParams,\n RecordDeliveryOnlyFn,\n RecordDeliveryOnlyParams,\n} from '#db/webhook-deliveries.js';\nexport {claimWebhookDelivery, pruneWebhookDeliveries} from '#db/webhook-deliveries.js';\nexport {integrationRouteErrorHandler} from '#presentation/routes/errors.js';\n\nexport interface CreateIntegrationsModuleOptions {\n providers?: IntegrationProvider[] | undefined;\n /**\n * Pre-built module parts, bypassing config-gated provider loading. Test-only seam\n * for exercising a provider's database, workers, or startup tasks directly. Takes\n * precedence over `providers`.\n */\n parts?: IntegrationModuleParts[] | undefined;\n secrets?: IntegrationProviderSecrets | undefined;\n workspaces?: WorkspacesInterModuleClient | undefined;\n agentTools?:\n | {\n workflows: WorkflowsModuleClient;\n }\n | undefined;\n webhookDeliverySource?: WebhookDeliverySource | undefined;\n}\n\n/**\n * Hosted runtimes implement this port to receive stored webhook requests. The\n * integration module starts its returned service after migrations complete.\n */\nexport interface WebhookDeliverySource {\n createService(processor: WebhookRequestProcessor): ModuleService;\n}\n\nexport interface IntegrationsContext {\n module: ShipfoxModule;\n registry: IntegrationProviderRegistry;\n capabilities: {\n sourceControl: IntegrationSourceControlService;\n };\n sourceControl: IntegrationSourceControlService;\n webhookProcessor: WebhookRequestProcessor;\n /**\n * Runs every enabled provider's one-shot boot-time tasks, after modules are initialized\n * (migrations done). Failures are isolated and logged, never rethrown, so a provider task\n * can never gate API boot. No-op when no enabled provider contributes a task.\n */\n runStartupTasks: () => Promise<void>;\n}\n\nexport async function createIntegrationsModule(\n options: CreateIntegrationsModuleOptions = {},\n): Promise<ShipfoxModule> {\n return (await createIntegrationsContext(options)).module;\n}\n\nexport async function createIntegrationsContext(\n options: CreateIntegrationsModuleOptions = {},\n): Promise<IntegrationsContext> {\n const workspaces = options.workspaces;\n const parts: IntegrationModuleParts[] =\n options.parts ??\n (options.providers\n ? options.providers.map((provider) => ({\n provider,\n webhookProcessors: provider.webhookProcessors,\n }))\n : await loadEnabledProviderModules({\n secrets: options.secrets,\n ...(workspaces\n ? {\n requireActiveWorkspaceMembership: (input: {\n workspaceId: string;\n userId: string;\n memberships: ReadonlyArray<\n import('@shipfox/api-auth-context').UserContextMembership\n >;\n }) =>\n workspaces.requireActiveMembership({\n ...input,\n memberships: [...input.memberships],\n }),\n }\n : {}),\n }));\n\n const registry = createIntegrationProviderRegistry(parts.map((part) => part.provider));\n const sourceControl = createSourceControlIntegrationService({\n registry,\n getIntegrationConnectionById,\n });\n const webhookProcessor = createComposedWebhookProcessor(\n parts.flatMap((part) => part.webhookProcessors ?? []),\n );\n\n async function runStartupTasks(): Promise<void> {\n for (const task of parts.flatMap((part) => part.startupTasks ?? [])) {\n // A provider convenience must never gate API boot.\n try {\n await task();\n } catch (error) {\n logger().error({err: error}, 'Integration startup task failed, continuing boot');\n }\n }\n }\n\n const module: ShipfoxModule = {\n name: 'integrations',\n interModulePresentations: [\n createIntegrationsInterModulePresentation({registry, sourceControl}),\n ],\n startupTasks: runStartupTasks,\n database: [\n {db, migrationsPath},\n ...parts.flatMap((part) => (part.database ? [part.database] : [])),\n ],\n routes: createIntegrationRoutes(registry, sourceControl, {\n agentTools: options.agentTools\n ? {\n workflows: options.agentTools.workflows,\n getIntegrationConnectionById,\n }\n : undefined,\n }),\n e2eRoutes: parts.flatMap((part) => part.e2eRoutes ?? []),\n publishers: [\n {name: 'integrations', table: integrationsOutbox, db, eventSchemas: integrationsEventSchemas},\n ],\n workers: [\n {\n taskQueue: INTEGRATIONS_MAINTENANCE_TASK_QUEUE,\n workflowsPath: maintenanceWorkflowsPath,\n activities: createIntegrationsMaintenanceActivities,\n workflows: [\n {\n name: 'pruneWebhookDeliveriesCron',\n id: 'integrations-prune-webhook-deliveries',\n cronSchedule: '0 3 * * *',\n },\n ],\n },\n ...parts.flatMap((part) => part.workers ?? []),\n ],\n ...(options.webhookDeliverySource\n ? {services: [options.webhookDeliverySource.createService(webhookProcessor)]}\n : {}),\n };\n\n return {\n module,\n registry,\n capabilities: {sourceControl},\n sourceControl,\n webhookProcessor,\n runStartupTasks,\n };\n}\n\nfunction createComposedWebhookProcessor(\n registrations: WebhookProcessorRegistration[],\n): WebhookRequestProcessor {\n const processors = new Map<WebhookRouteId, WebhookRequestProcessor>();\n for (const registration of registrations) {\n for (const routeId of registration.routeIds) {\n if (processors.has(routeId)) {\n throw new Error(`Webhook processor is registered more than once for ${routeId}`);\n }\n processors.set(routeId, registration.processor);\n }\n }\n\n return {\n async process(request: StoredWebhookRequest): Promise<WebhookProcessingResult> {\n const processor = processors.get(request.route_id);\n if (!processor) {\n throw new WebhookProcessorNotConfiguredError(request.route_id);\n }\n return await processor.process(request);\n },\n };\n}\n"],"names":["dirname","resolve","fileURLToPath","integrationsEventSchemas","logger","WebhookProcessorNotConfiguredError","createIntegrationProviderRegistry","createSourceControlIntegrationService","getIntegrationConnectionById","db","migrationsPath","integrationsOutbox","createIntegrationsInterModulePresentation","createIntegrationRoutes","loadEnabledProviderModules","createIntegrationsMaintenanceActivities","INTEGRATIONS_MAINTENANCE_TASK_QUEUE","packageRoot","url","maintenanceWorkflowsPath","buildProviderRepositoryId","MAX_REPOSITORY_FILE_BYTES","parseProviderRepositoryId","buildAgentToolCatalogs","buildAgentToolSelectionCatalogs","createWorkspaceConnectionSnapshotLoader","ConnectionSlugConflictError","IntegrationCapabilityUnavailableError","IntegrationCheckoutUnsupportedError","IntegrationConnectionInactiveError","IntegrationConnectionNotFoundError","IntegrationConnectionWorkspaceMismatchError","IntegrationProviderError","IntegrationProviderUnavailableError","redactCheckoutSpec","claimWebhookDelivery","pruneWebhookDeliveries","integrationRouteErrorHandler","createIntegrationsModule","options","createIntegrationsContext","module","workspaces","parts","providers","map","provider","webhookProcessors","secrets","requireActiveWorkspaceMembership","input","requireActiveMembership","memberships","registry","part","sourceControl","webhookProcessor","createComposedWebhookProcessor","flatMap","runStartupTasks","task","startupTasks","error","err","name","interModulePresentations","database","routes","agentTools","workflows","undefined","e2eRoutes","publishers","table","eventSchemas","workers","taskQueue","workflowsPath","activities","id","cronSchedule","webhookDeliverySource","services","createService","capabilities","registrations","processors","Map","registration","routeId","routeIds","has","Error","set","processor","process","request","get","route_id"],"mappings":"AAAA,SAAQA,OAAO,EAAEC,OAAO,QAAO,YAAY;AAC3C,SAAQC,aAAa,QAAO,WAAW;AACvC,SACEC,wBAAwB,QAKnB,oCAAoC;AAI3C,SAAQC,MAAM,QAAO,8BAA8B;AAEnD,SAAQC,kCAAkC,QAAO,kBAAkB;AACnE,SACEC,iCAAiC,QAE5B,8BAA8B;AACrC,SACEC,qCAAqC,QAEhC,kCAAkC;AACzC,SAAQC,4BAA4B,QAAO,qBAAqB;AAChE,SAAQC,EAAE,QAAO,YAAY;AAC7B,SAAQC,cAAc,QAAO,oBAAoB;AACjD,SAAQC,kBAAkB,QAAO,uBAAuB;AACxD,SAAQC,yCAAyC,QAAO,gCAAgC;AACxF,SAAQC,uBAAuB,QAAO,gCAAgC;AACtE,SAAQC,0BAA0B,QAAO,wBAAwB;AAMjE,SAAQC,uCAAuC,QAAO,gCAAgC;AACtF,SAAQC,mCAAmC,QAAO,yBAAyB;AAE3E,MAAMC,cAAchB,QAAQD,QAAQE,cAAc,YAAYgB,GAAG,IAAI;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qBAAqB,CAACE,aAAa,CAAC3B;aAAkB;QAAA,IAC1E,CAAC,CAAC;IACR;IAEA,OAAO;QACLf;QACAY;QACA+B,cAAc;YAAC7B;QAAa;QAC5BA;QACAC;QACAG;IACF;AACF;AAEA,SAASF,+BACP4B,aAA6C;IAE7C,MAAMC,aAAa,IAAIC;IACvB,KAAK,MAAMC,gBAAgBH,cAAe;QACxC,KAAK,MAAMI,WAAWD,aAAaE,QAAQ,CAAE;YAC3C,IAAIJ,WAAWK,GAAG,CAACF,UAAU;gBAC3B,MAAM,IAAIG,MAAM,CAAC,mDAAmD,EAAEH,SAAS;YACjF;YACAH,WAAWO,GAAG,CAACJ,SAASD,aAAaM,SAAS;QAChD;IACF;IAEA,OAAO;QACL,MAAMC,SAAQC,OAA6B;YACzC,MAAMF,YAAYR,WAAWW,GAAG,CAACD,QAAQE,QAAQ;YACjD,IAAI,CAACJ,WAAW;gBACd,MAAM,IAAIzF,mCAAmC2F,QAAQE,QAAQ;YAC/D;YACA,OAAO,MAAMJ,UAAUC,OAAO,CAACC;QACjC;IACF;AACF"}
@@ -0,0 +1,9 @@
1
+ import { integrationsInterModuleContract } from '@shipfox/api-integration-core-dto';
2
+ import { type InterModulePresentation } from '@shipfox/inter-module';
3
+ import type { IntegrationProviderRegistry } from '#core/providers/registry.js';
4
+ import type { IntegrationSourceControlService } from '#core/source-control-service.js';
5
+ export declare function createIntegrationsInterModulePresentation(params: {
6
+ registry: IntegrationProviderRegistry;
7
+ sourceControl: IntegrationSourceControlService;
8
+ }): InterModulePresentation<typeof integrationsInterModuleContract>;
9
+ //# sourceMappingURL=inter-module.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"inter-module.d.ts","sourceRoot":"","sources":["../../src/presentation/inter-module.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,+BAA+B,EAAC,MAAM,mCAAmC,CAAC;AAClF,OAAO,EAIL,KAAK,uBAAuB,EAC7B,MAAM,uBAAuB,CAAC;AAe/B,OAAO,KAAK,EAAC,2BAA2B,EAAC,MAAM,6BAA6B,CAAC;AAC7E,OAAO,KAAK,EAAC,+BAA+B,EAAC,MAAM,iCAAiC,CAAC;AAGrF,wBAAgB,yCAAyC,CAAC,MAAM,EAAE;IAChE,QAAQ,EAAE,2BAA2B,CAAC;IACtC,aAAa,EAAE,+BAA+B,CAAC;CAChD,GAAG,uBAAuB,CAAC,OAAO,+BAA+B,CAAC,CA+ElE"}
@@ -0,0 +1,121 @@
1
+ import { integrationsInterModuleContract } from '@shipfox/api-integration-core-dto';
2
+ import { createInterModuleKnownError, defineInterModulePresentation } from '@shipfox/inter-module';
3
+ import { buildAgentToolCatalogs, buildAgentToolSelectionCatalogs, createWorkspaceConnectionSnapshotLoader } from '#core/agent-tool-selection.js';
4
+ import { IntegrationCapabilityUnavailableError, IntegrationCheckoutUnsupportedError, IntegrationConnectionInactiveError, IntegrationConnectionNotFoundError, IntegrationConnectionWorkspaceMismatchError, IntegrationProviderError, IntegrationProviderUnavailableError } from '#core/errors.js';
5
+ import { getIntegrationConnectionById } from '#db/connections.js';
6
+ export function createIntegrationsInterModulePresentation(params) {
7
+ const contract = integrationsInterModuleContract;
8
+ return defineInterModulePresentation(contract, {
9
+ resolveSourceRepository: async (input)=>await known(contract.methods.resolveSourceRepository, input, async ()=>{
10
+ const resolved = await params.sourceControl.resolveRepository(input);
11
+ return {
12
+ connection: {
13
+ id: resolved.connection.id,
14
+ provider: resolved.connection.provider,
15
+ slug: resolved.connection.slug
16
+ },
17
+ repository: resolved.repository
18
+ };
19
+ }),
20
+ listSourceFiles: async (input)=>await known(contract.methods.listSourceFiles, input, async ()=>await params.sourceControl.listFiles(input)),
21
+ fetchSourceFile: async (input)=>await known(contract.methods.fetchSourceFile, input, async ()=>await params.sourceControl.fetchFile(input)),
22
+ createCheckoutSpec: async (input)=>await known(contract.methods.createCheckoutSpec, input, async ()=>{
23
+ const spec = await params.sourceControl.createCheckoutSpec(input);
24
+ return {
25
+ repositoryUrl: spec.repositoryUrl,
26
+ ref: spec.ref,
27
+ ...spec.credentials ? {
28
+ credentials: {
29
+ ...spec.credentials,
30
+ expiresAt: spec.credentials.expiresAt.toISOString()
31
+ }
32
+ } : {},
33
+ ...spec.gitAuthor === undefined ? {} : {
34
+ gitAuthor: spec.gitAuthor
35
+ }
36
+ };
37
+ }),
38
+ getAgentToolsContext: async (input)=>await known(contract.methods.getAgentToolsContext, input, async ()=>{
39
+ const [selectionCatalogs, catalogs, snapshot, defaultConnection] = await Promise.all([
40
+ buildAgentToolSelectionCatalogs(params.registry),
41
+ buildAgentToolCatalogs(params.registry),
42
+ createWorkspaceConnectionSnapshotLoader(params.registry)(input.workspaceId),
43
+ getIntegrationConnectionById(input.defaultConnectionId)
44
+ ]);
45
+ return {
46
+ selectionCatalogs: [
47
+ ...selectionCatalogs
48
+ ].map(([provider, value])=>({
49
+ provider,
50
+ selectors: value.selectors.map((selector)=>({
51
+ ...selector
52
+ }))
53
+ })),
54
+ catalogs: [
55
+ ...catalogs
56
+ ].map(([provider, tools])=>({
57
+ provider,
58
+ tools: tools.map(({ methods, ...tool })=>({
59
+ ...tool,
60
+ ...methods === undefined ? {} : {
61
+ methods: methods.map((method)=>({
62
+ ...method
63
+ }))
64
+ }
65
+ }))
66
+ })),
67
+ workspaceConnections: [
68
+ ...snapshot
69
+ ].map(([slug, value])=>({
70
+ slug,
71
+ ...value,
72
+ capabilities: [
73
+ ...value.capabilities
74
+ ]
75
+ })),
76
+ defaultConnection: defaultConnection ? {
77
+ id: defaultConnection.id,
78
+ slug: defaultConnection.slug,
79
+ provider: defaultConnection.provider
80
+ } : null
81
+ };
82
+ })
83
+ });
84
+ }
85
+ async function known(method, input, operation) {
86
+ try {
87
+ return await operation();
88
+ } catch (error) {
89
+ throw mapError(method, input, error);
90
+ }
91
+ }
92
+ function mapError(method, input, error) {
93
+ if (error instanceof IntegrationConnectionNotFoundError) return createInterModuleKnownError(method, 'connection-not-found', {
94
+ connectionId: input.connectionId ?? input.defaultConnectionId
95
+ });
96
+ if (error instanceof IntegrationConnectionInactiveError) return createInterModuleKnownError(method, 'connection-inactive', {
97
+ connectionId: input.connectionId
98
+ });
99
+ if (error instanceof IntegrationConnectionWorkspaceMismatchError) return createInterModuleKnownError(method, 'connection-workspace-mismatch', {
100
+ connectionId: input.connectionId
101
+ });
102
+ if (error instanceof IntegrationProviderUnavailableError) return createInterModuleKnownError(method, 'provider-unavailable', {
103
+ provider: error.provider
104
+ });
105
+ if (error instanceof IntegrationCapabilityUnavailableError) return createInterModuleKnownError(method, 'capability-unavailable', {
106
+ provider: error.provider,
107
+ capability: error.capability
108
+ });
109
+ if (error instanceof IntegrationCheckoutUnsupportedError) return createInterModuleKnownError(method, 'checkout-unsupported', {
110
+ provider: error.provider
111
+ });
112
+ if (error instanceof IntegrationProviderError) return createInterModuleKnownError(method, 'provider-failure', {
113
+ reason: error.reason,
114
+ ...error.retryAfterSeconds === undefined ? {} : {
115
+ retryAfterSeconds: error.retryAfterSeconds
116
+ }
117
+ });
118
+ return error;
119
+ }
120
+
121
+ //# sourceMappingURL=inter-module.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/presentation/inter-module.ts"],"sourcesContent":["import {integrationsInterModuleContract} from '@shipfox/api-integration-core-dto';\nimport {\n createInterModuleKnownError,\n defineInterModulePresentation,\n type InterModuleMethodContract,\n type InterModulePresentation,\n} from '@shipfox/inter-module';\nimport {\n buildAgentToolCatalogs,\n buildAgentToolSelectionCatalogs,\n createWorkspaceConnectionSnapshotLoader,\n} from '#core/agent-tool-selection.js';\nimport {\n IntegrationCapabilityUnavailableError,\n IntegrationCheckoutUnsupportedError,\n IntegrationConnectionInactiveError,\n IntegrationConnectionNotFoundError,\n IntegrationConnectionWorkspaceMismatchError,\n IntegrationProviderError,\n IntegrationProviderUnavailableError,\n} from '#core/errors.js';\nimport type {IntegrationProviderRegistry} from '#core/providers/registry.js';\nimport type {IntegrationSourceControlService} from '#core/source-control-service.js';\nimport {getIntegrationConnectionById} from '#db/connections.js';\n\nexport function createIntegrationsInterModulePresentation(params: {\n registry: IntegrationProviderRegistry;\n sourceControl: IntegrationSourceControlService;\n}): InterModulePresentation<typeof integrationsInterModuleContract> {\n const contract = integrationsInterModuleContract;\n return defineInterModulePresentation(contract, {\n resolveSourceRepository: async (input) =>\n await known(contract.methods.resolveSourceRepository, input, async () => {\n const resolved = await params.sourceControl.resolveRepository(input);\n return {\n connection: {\n id: resolved.connection.id,\n provider: resolved.connection.provider,\n slug: resolved.connection.slug,\n },\n repository: resolved.repository,\n };\n }),\n listSourceFiles: async (input) =>\n await known(\n contract.methods.listSourceFiles,\n input,\n async () => await params.sourceControl.listFiles(input),\n ),\n fetchSourceFile: async (input) =>\n await known(\n contract.methods.fetchSourceFile,\n input,\n async () => await params.sourceControl.fetchFile(input),\n ),\n createCheckoutSpec: async (input) =>\n await known(contract.methods.createCheckoutSpec, input, async () => {\n const spec = await params.sourceControl.createCheckoutSpec(input);\n return {\n repositoryUrl: spec.repositoryUrl,\n ref: spec.ref,\n ...(spec.credentials\n ? {\n credentials: {\n ...spec.credentials,\n expiresAt: spec.credentials.expiresAt.toISOString(),\n },\n }\n : {}),\n ...(spec.gitAuthor === undefined ? {} : {gitAuthor: spec.gitAuthor}),\n };\n }),\n getAgentToolsContext: async (input) =>\n await known(contract.methods.getAgentToolsContext, input, async () => {\n const [selectionCatalogs, catalogs, snapshot, defaultConnection] = await Promise.all([\n buildAgentToolSelectionCatalogs(params.registry),\n buildAgentToolCatalogs(params.registry),\n createWorkspaceConnectionSnapshotLoader(params.registry)(input.workspaceId),\n getIntegrationConnectionById(input.defaultConnectionId),\n ]);\n return {\n selectionCatalogs: [...selectionCatalogs].map(([provider, value]) => ({\n provider,\n selectors: value.selectors.map((selector) => ({...selector})),\n })),\n catalogs: [...catalogs].map(([provider, tools]) => ({\n provider,\n tools: tools.map(({methods, ...tool}) => ({\n ...tool,\n ...(methods === undefined ? {} : {methods: methods.map((method) => ({...method}))}),\n })),\n })),\n workspaceConnections: [...snapshot].map(([slug, value]) => ({\n slug,\n ...value,\n capabilities: [...value.capabilities],\n })),\n defaultConnection: defaultConnection\n ? {\n id: defaultConnection.id,\n slug: defaultConnection.slug,\n provider: defaultConnection.provider,\n }\n : null,\n };\n }),\n });\n}\n\nasync function known<Output>(\n method: InterModuleMethodContract,\n input: {connectionId?: string; defaultConnectionId?: string},\n operation: () => Promise<Output>,\n): Promise<Output> {\n try {\n return await operation();\n } catch (error) {\n throw mapError(method, input, error);\n }\n}\nfunction mapError(\n method: InterModuleMethodContract,\n input: {connectionId?: string; defaultConnectionId?: string},\n error: unknown,\n): unknown {\n if (error instanceof IntegrationConnectionNotFoundError)\n return createInterModuleKnownError(method, 'connection-not-found', {\n connectionId: input.connectionId ?? input.defaultConnectionId,\n });\n if (error instanceof IntegrationConnectionInactiveError)\n return createInterModuleKnownError(method, 'connection-inactive', {\n connectionId: input.connectionId,\n });\n if (error instanceof IntegrationConnectionWorkspaceMismatchError)\n return createInterModuleKnownError(method, 'connection-workspace-mismatch', {\n connectionId: input.connectionId,\n });\n if (error instanceof IntegrationProviderUnavailableError)\n return createInterModuleKnownError(method, 'provider-unavailable', {provider: error.provider});\n if (error instanceof IntegrationCapabilityUnavailableError)\n return createInterModuleKnownError(method, 'capability-unavailable', {\n provider: error.provider,\n capability: error.capability,\n });\n if (error instanceof IntegrationCheckoutUnsupportedError)\n return createInterModuleKnownError(method, 'checkout-unsupported', {provider: error.provider});\n if (error instanceof IntegrationProviderError)\n return createInterModuleKnownError(method, 'provider-failure', {\n reason: error.reason,\n ...(error.retryAfterSeconds === undefined\n ? {}\n : {retryAfterSeconds: error.retryAfterSeconds}),\n });\n return error;\n}\n"],"names":["integrationsInterModuleContract","createInterModuleKnownError","defineInterModulePresentation","buildAgentToolCatalogs","buildAgentToolSelectionCatalogs","createWorkspaceConnectionSnapshotLoader","IntegrationCapabilityUnavailableError","IntegrationCheckoutUnsupportedError","IntegrationConnectionInactiveError","IntegrationConnectionNotFoundError","IntegrationConnectionWorkspaceMismatchError","IntegrationProviderError","IntegrationProviderUnavailableError","getIntegrationConnectionById","createIntegrationsInterModulePresentation","params","contract","resolveSourceRepository","input","known","methods","resolved","sourceControl","resolveRepository","connection","id","provider","slug","repository","listSourceFiles","listFiles","fetchSourceFile","fetchFile","createCheckoutSpec","spec","repositoryUrl","ref","credentials","expiresAt","toISOString","gitAuthor","undefined","getAgentToolsContext","selectionCatalogs","catalogs","snapshot","defaultConnection","Promise","all","registry","workspaceId","defaultConnectionId","map","value","selectors","selector","tools","tool","method","workspaceConnections","capabilities","operation","error","mapError","connectionId","capability","reason","retryAfterSeconds"],"mappings":"AAAA,SAAQA,+BAA+B,QAAO,oCAAoC;AAClF,SACEC,2BAA2B,EAC3BC,6BAA6B,QAGxB,wBAAwB;AAC/B,SACEC,sBAAsB,EACtBC,+BAA+B,EAC/BC,uCAAuC,QAClC,gCAAgC;AACvC,SACEC,qCAAqC,EACrCC,mCAAmC,EACnCC,kCAAkC,EAClCC,kCAAkC,EAClCC,2CAA2C,EAC3CC,wBAAwB,EACxBC,mCAAmC,QAC9B,kBAAkB;AAGzB,SAAQC,4BAA4B,QAAO,qBAAqB;AAEhE,OAAO,SAASC,0CAA0CC,MAGzD;IACC,MAAMC,WAAWhB;IACjB,OAAOE,8BAA8Bc,UAAU;QAC7CC,yBAAyB,OAAOC,QAC9B,MAAMC,MAAMH,SAASI,OAAO,CAACH,uBAAuB,EAAEC,OAAO;gBAC3D,MAAMG,WAAW,MAAMN,OAAOO,aAAa,CAACC,iBAAiB,CAACL;gBAC9D,OAAO;oBACLM,YAAY;wBACVC,IAAIJ,SAASG,UAAU,CAACC,EAAE;wBAC1BC,UAAUL,SAASG,UAAU,CAACE,QAAQ;wBACtCC,MAAMN,SAASG,UAAU,CAACG,IAAI;oBAChC;oBACAC,YAAYP,SAASO,UAAU;gBACjC;YACF;QACFC,iBAAiB,OAAOX,QACtB,MAAMC,MACJH,SAASI,OAAO,CAACS,eAAe,EAChCX,OACA,UA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