@shipfox/api-integration-core 12.4.0 → 12.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. package/.turbo/turbo-build.log +4 -4
  2. package/CHANGELOG.md +32 -0
  3. package/dist/metrics/instance.d.ts +5 -0
  4. package/dist/metrics/instance.d.ts.map +1 -1
  5. package/dist/metrics/instance.js +21 -1
  6. package/dist/metrics/instance.js.map +1 -1
  7. package/dist/presentation/routes/agent-tools-gateway/audit.d.ts +4 -1
  8. package/dist/presentation/routes/agent-tools-gateway/audit.d.ts.map +1 -1
  9. package/dist/presentation/routes/agent-tools-gateway/audit.js +6 -1
  10. package/dist/presentation/routes/agent-tools-gateway/audit.js.map +1 -1
  11. package/dist/presentation/routes/agent-tools-gateway/dispatch.d.ts +9 -1
  12. package/dist/presentation/routes/agent-tools-gateway/dispatch.d.ts.map +1 -1
  13. package/dist/presentation/routes/agent-tools-gateway/dispatch.js +55 -17
  14. package/dist/presentation/routes/agent-tools-gateway/dispatch.js.map +1 -1
  15. package/dist/presentation/routes/agent-tools-gateway/index.d.ts.map +1 -1
  16. package/dist/presentation/routes/agent-tools-gateway/index.js +6 -5
  17. package/dist/presentation/routes/agent-tools-gateway/index.js.map +1 -1
  18. package/dist/presentation/routes/agent-tools-gateway/mcp-server.d.ts.map +1 -1
  19. package/dist/presentation/routes/agent-tools-gateway/mcp-server.js +27 -5
  20. package/dist/presentation/routes/agent-tools-gateway/mcp-server.js.map +1 -1
  21. package/dist/presentation/routes/errors.d.ts.map +1 -1
  22. package/dist/presentation/routes/errors.js +1 -1
  23. package/dist/presentation/routes/errors.js.map +1 -1
  24. package/dist/tsconfig.test.tsbuildinfo +1 -1
  25. package/package.json +10 -10
  26. package/src/metrics/instance.ts +40 -1
  27. package/src/presentation/routes/agent-tools-gateway/agent-tools-gateway.route.test.ts +11 -4
  28. package/src/presentation/routes/agent-tools-gateway/audit.test.ts +51 -0
  29. package/src/presentation/routes/agent-tools-gateway/audit.ts +8 -0
  30. package/src/presentation/routes/agent-tools-gateway/dispatch.test.ts +167 -0
  31. package/src/presentation/routes/agent-tools-gateway/dispatch.ts +93 -20
  32. package/src/presentation/routes/agent-tools-gateway/index.ts +3 -4
  33. package/src/presentation/routes/agent-tools-gateway/mcp-server.test.ts +41 -4
  34. package/src/presentation/routes/agent-tools-gateway/mcp-server.ts +35 -1
  35. package/src/presentation/routes/errors.ts +1 -0
  36. package/tsconfig.build.tsbuildinfo +1 -1
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/presentation/routes/agent-tools-gateway/mcp-server.ts"],"sourcesContent":["import {Server} from '@modelcontextprotocol/sdk/server/index.js';\nimport {\n CallToolRequestSchema,\n type CallToolResult,\n ListToolsRequestSchema,\n} from '@modelcontextprotocol/sdk/types.js';\nimport {reportError} from '@shipfox/node-error-monitoring';\nimport {logger} from '@shipfox/node-opentelemetry';\nimport {INVALID_METHOD_LABEL, type IntegrationToolCallRecorder, NO_METHOD_LABEL} from './audit.js';\nimport type {\n AuthorizedIntegrationTool,\n AuthorizedIntegrationToolMap,\n} from './resolve-authorized-tools.js';\n\nexport interface IntegrationToolDispatchInput {\n authorizedTool: AuthorizedIntegrationTool;\n arguments: Record<string, unknown>;\n method?: string | undefined;\n}\n\nexport type IntegrationToolDispatcher = (\n input: IntegrationToolDispatchInput,\n) => Promise<CallToolResult>;\n\nexport interface BuildAgentToolsMcpServerParams {\n authorizedTools: AuthorizedIntegrationToolMap;\n dispatch: IntegrationToolDispatcher;\n recordCall?: IntegrationToolCallRecorder | undefined;\n}\n\nexport function buildAgentToolsMcpServer(params: BuildAgentToolsMcpServerParams): Server {\n const server = new Server(\n {name: 'shipfox-integration-tools', version: '0.0.0'},\n {capabilities: {tools: {}}},\n );\n server.setRequestHandler(ListToolsRequestSchema, () => ({\n tools: [...params.authorizedTools.values()].map((authorizedTool) => ({\n name: authorizedTool.mcpName,\n description: authorizedTool.description,\n inputSchema: authorizedTool.inputSchema as {\n type: 'object';\n properties?: Record<string, object> | undefined;\n required?: string[] | undefined;\n },\n ...(authorizedTool.outputSchema\n ? {\n outputSchema: authorizedTool.outputSchema as {\n type: 'object';\n properties?: Record<string, object> | undefined;\n required?: string[] | undefined;\n },\n }\n : {}),\n })),\n }));\n\n server.setRequestHandler(CallToolRequestSchema, async (request) => {\n const authorizedTool = params.authorizedTools.get(request.params.name);\n if (!authorizedTool) {\n recordToolCall(params.recordCall, {\n arguments: request.params.arguments ?? {},\n method: NO_METHOD_LABEL,\n outcome: 'invalid-request',\n });\n return toolError(`Unknown integration tool: ${request.params.name}`);\n }\n\n const args = request.params.arguments ?? {};\n if (!isRecord(args)) {\n recordToolCall(params.recordCall, {\n authorizedTool,\n arguments: args,\n method: NO_METHOD_LABEL,\n outcome: 'invalid-request',\n });\n return toolError('Tool arguments must be an object');\n }\n\n const methodValidation = validateMethod(authorizedTool, args);\n if (methodValidation.kind === 'error') {\n recordToolCall(params.recordCall, {\n authorizedTool,\n arguments: args,\n method: INVALID_METHOD_LABEL,\n outcome: 'invalid-request',\n });\n return toolError(methodValidation.message);\n }\n const method = methodValidation.method ?? NO_METHOD_LABEL;\n\n try {\n const result = await params.dispatch({\n authorizedTool,\n arguments: args,\n method: methodValidation.method,\n });\n recordToolCall(params.recordCall, {\n authorizedTool,\n arguments: args,\n method,\n outcome: result.isError === true ? 'tool-error' : 'success',\n });\n return result;\n } catch (error) {\n recordToolCall(params.recordCall, {\n authorizedTool,\n arguments: args,\n method,\n outcome: 'exception',\n });\n throw error;\n }\n });\n\n return server;\n}\n\nfunction recordToolCall(\n recordCall: IntegrationToolCallRecorder | undefined,\n record: Parameters<IntegrationToolCallRecorder>[0],\n): void {\n try {\n recordCall?.(record);\n } catch (error) {\n // Audit and metrics must not affect MCP responses.\n logger().error({err: error}, 'Failed to record integration agent tool audit event');\n reportError(error, {boundary: 'integration.agent-tool', operation: 'audit'});\n }\n}\n\nfunction validateMethod(\n authorizedTool: AuthorizedIntegrationTool,\n args: Record<string, unknown>,\n): {kind: 'ok'; method?: string | undefined} | {kind: 'error'; message: string} {\n if (!authorizedTool.tool.methods) return {kind: 'ok'};\n\n const method = args.method;\n if (typeof method !== 'string') {\n return {kind: 'error', message: 'Method-family tools require a string method argument'};\n }\n\n const allowedMethods = new Set(authorizedTool.tool.methods.map((candidate) => candidate.id));\n if (!allowedMethods.has(method)) {\n return {kind: 'error', message: `Unauthorized integration tool method: ${method}`};\n }\n\n return {kind: 'ok', method};\n}\n\nfunction toolError(message: string): CallToolResult {\n return {\n isError: true,\n content: [{type: 'text', text: message}],\n };\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null && !Array.isArray(value);\n}\n"],"names":["Server","CallToolRequestSchema","ListToolsRequestSchema","reportError","logger","INVALID_METHOD_LABEL","NO_METHOD_LABEL","buildAgentToolsMcpServer","params","server","name","version","capabilities","tools","setRequestHandler","authorizedTools","values","map","authorizedTool","mcpName","description","inputSchema","outputSchema","request","get","recordToolCall","recordCall","arguments","method","outcome","toolError","args","isRecord","methodValidation","validateMethod","kind","message","result","dispatch","isError","error","record","err","boundary","operation","tool","methods","allowedMethods","Set","candidate","id","has","content","type","text","value","Array","isArray"],"mappings":"AAAA,SAAQA,MAAM,QAAO,4CAA4C;AACjE,SACEC,qBAAqB,EAErBC,sBAAsB,QACjB,qCAAqC;AAC5C,SAAQC,WAAW,QAAO,iCAAiC;AAC3D,SAAQC,MAAM,QAAO,8BAA8B;AACnD,SAAQC,oBAAoB,EAAoCC,eAAe,QAAO,aAAa;AAsBnG,OAAO,SAASC,yBAAyBC,MAAsC;IAC7E,MAAMC,SAAS,IAAIT,OACjB;QAACU,MAAM;QAA6BC,SAAS;IAAO,GACpD;QAACC,cAAc;YAACC,OAAO,CAAC;QAAC;IAAC;IAE5BJ,OAAOK,iBAAiB,CAACZ,wBAAwB,IAAO,CAAA;YACtDW,OAAO;mBAAIL,OAAOO,eAAe,CAACC,MAAM;aAAG,C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AWI;gBACXH;gBACAC,SAASQ,OAAOE,OAAO,KAAK,OAAO,eAAe;YACpD;YACA,OAAOF;QACT,EAAE,OAAOG,OAAO;YACdf,eAAejB,OAAOkB,UAAU,EAAE;gBAChCR;gBACAS,WAAWI;gBACXH;gBACAC,SAAS;YACX;YACA,MAAMW;QACR;IACF;IAEA,OAAO/B;AACT;AAEA,SAASgB,eACPC,UAAmD,EACnDe,MAAkD;IAElD,IAAI;QACFf,aAAae;IACf,EAAE,OAAOD,OAAO;QACd,mDAAmD;QACnDpC,SAASoC,KAAK,CAAC;YAACE,KAAKF;QAAK,GAAG;QAC7BrC,YAAYqC,OAAO;YAACG,UAAU;YAA0BC,WAAW;QAAO;IAC5E;AACF;AAEA,SAASV,eACPhB,cAAyC,EACzCa,IAA6B;IAE7B,IAAI,CAACb,eAAe2B,IAAI,CAACC,OAAO,EAAE,OAAO;QAACX,MAAM;IAAI;IAEpD,MAAMP,SAASG,KAAKH,MAAM;IAC1B,IAAI,OAAOA,WAAW,UAAU;QAC9B,OAAO;YAACO,MAAM;YAASC,SAAS;QAAsD;IACxF;IAEA,MAAMW,iBAAiB,IAAIC,IAAI9B,eAAe2B,IAAI,CAACC,OAAO,CAAC7B,GAAG,CAAC,CAACgC,YAAcA,UAAUC,EAAE;IAC1F,IAAI,CAACH,eAAeI,GAAG,CAACvB,SAAS;QAC/B,OAAO;YAACO,MAAM;YAASC,SAAS,CAAC,sCAAsC,EAAER,QAAQ;QAAA;IACnF;IAEA,OAAO;QAACO,MAAM;QAAMP;IAAM;AAC5B;AAEA,SAASE,UAAUM,OAAe;IAChC,OAAO;QACLG,SAAS;QACTa,SAAS;YAAC;gBAACC,MAAM;gBAAQC,MAAMlB;YAAO;SAAE;IAC1C;AACF;AAEA,SAASJ,SAASuB,KAAc;IAC9B,OAAO,OAAOA,UAAU,YAAYA,UAAU,QAAQ,CAACC,MAAMC,OAAO,CAACF;AACvE"}
1
+ {"version":3,"sources":["../../../../src/presentation/routes/agent-tools-gateway/mcp-server.ts"],"sourcesContent":["import {Server} from '@modelcontextprotocol/sdk/server/index.js';\nimport {\n CallToolRequestSchema,\n type CallToolResult,\n ListToolsRequestSchema,\n} from '@modelcontextprotocol/sdk/types.js';\nimport {reportError} from '@shipfox/node-error-monitoring';\nimport {logger} from '@shipfox/node-opentelemetry';\nimport {normalizeIntegrationAgentToolCallErrorCode} from '#metrics/index.js';\nimport {\n INVALID_METHOD_LABEL,\n type IntegrationAgentToolCallErrorCode,\n type IntegrationToolCallRecorder,\n NO_METHOD_LABEL,\n} from './audit.js';\nimport type {\n AuthorizedIntegrationTool,\n AuthorizedIntegrationToolMap,\n} from './resolve-authorized-tools.js';\n\nexport interface IntegrationToolDispatchInput {\n authorizedTool: AuthorizedIntegrationTool;\n arguments: Record<string, unknown>;\n method?: string | undefined;\n}\n\nexport type IntegrationToolDispatcher = (\n input: IntegrationToolDispatchInput,\n) => Promise<CallToolResult>;\n\nexport interface BuildAgentToolsMcpServerParams {\n authorizedTools: AuthorizedIntegrationToolMap;\n dispatch: IntegrationToolDispatcher;\n recordCall?: IntegrationToolCallRecorder | undefined;\n}\n\nexport function buildAgentToolsMcpServer(params: BuildAgentToolsMcpServerParams): Server {\n const server = new Server(\n {name: 'shipfox-integration-tools', version: '0.0.0'},\n {capabilities: {tools: {}}},\n );\n server.setRequestHandler(ListToolsRequestSchema, () => ({\n tools: [...params.authorizedTools.values()].map((authorizedTool) => ({\n name: authorizedTool.mcpName,\n description: authorizedTool.description,\n inputSchema: authorizedTool.inputSchema as {\n type: 'object';\n properties?: Record<string, object> | undefined;\n required?: string[] | undefined;\n },\n ...(authorizedTool.outputSchema\n ? {\n outputSchema: authorizedTool.outputSchema as {\n type: 'object';\n properties?: Record<string, object> | undefined;\n required?: string[] | undefined;\n },\n }\n : {}),\n })),\n }));\n\n server.setRequestHandler(CallToolRequestSchema, async (request) => {\n const authorizedTool = params.authorizedTools.get(request.params.name);\n if (!authorizedTool) {\n recordToolCall(params.recordCall, {\n arguments: request.params.arguments ?? {},\n method: NO_METHOD_LABEL,\n outcome: 'invalid-request',\n errorCode: 'invalid-request',\n });\n return toolError(`Unknown integration tool: ${request.params.name}`);\n }\n\n const args = request.params.arguments ?? {};\n if (!isRecord(args)) {\n recordToolCall(params.recordCall, {\n authorizedTool,\n arguments: args,\n method: NO_METHOD_LABEL,\n outcome: 'invalid-request',\n errorCode: 'invalid-request',\n });\n return toolError('Tool arguments must be an object');\n }\n\n const methodValidation = validateMethod(authorizedTool, args);\n if (methodValidation.kind === 'error') {\n recordToolCall(params.recordCall, {\n authorizedTool,\n arguments: args,\n method: INVALID_METHOD_LABEL,\n outcome: 'invalid-request',\n errorCode: 'invalid-request',\n });\n return toolError(methodValidation.message);\n }\n const method = methodValidation.method ?? NO_METHOD_LABEL;\n\n try {\n const result = await params.dispatch({\n authorizedTool,\n arguments: args,\n method: methodValidation.method,\n });\n recordToolCall(params.recordCall, {\n authorizedTool,\n arguments: args,\n method,\n outcome: result.isError === true ? 'tool-error' : 'success',\n ...toolCallErrorDetails(result),\n });\n return result;\n } catch (error) {\n recordToolCall(params.recordCall, {\n authorizedTool,\n arguments: args,\n method,\n outcome: 'exception',\n errorCode: 'unknown',\n });\n throw error;\n }\n });\n\n return server;\n}\n\nfunction toolCallErrorDetails(result: CallToolResult): {\n errorCode: IntegrationAgentToolCallErrorCode | 'none';\n providerStatus?: number | undefined;\n} {\n if (result.isError !== true) return {errorCode: 'none'};\n\n const structuredContent = isRecord(result.structuredContent)\n ? result.structuredContent\n : undefined;\n const providerStatus = statusCode(structuredContent?.status);\n\n return {\n errorCode: normalizeIntegrationAgentToolCallErrorCode(structuredContent?.code),\n ...(providerStatus === undefined ? {} : {providerStatus}),\n };\n}\n\nfunction recordToolCall(\n recordCall: IntegrationToolCallRecorder | undefined,\n record: Parameters<IntegrationToolCallRecorder>[0],\n): void {\n try {\n recordCall?.(record);\n } catch (error) {\n // Audit and metrics must not affect MCP responses.\n logger().error({err: error}, 'Failed to record integration agent tool audit event');\n reportError(error, {boundary: 'integration.agent-tool', operation: 'audit'});\n }\n}\n\nfunction validateMethod(\n authorizedTool: AuthorizedIntegrationTool,\n args: Record<string, unknown>,\n): {kind: 'ok'; method?: string | undefined} | {kind: 'error'; message: string} {\n if (!authorizedTool.tool.methods) return {kind: 'ok'};\n\n const method = args.method;\n if (typeof method !== 'string') {\n return {kind: 'error', message: 'Method-family tools require a string method argument'};\n }\n\n const allowedMethods = new Set(authorizedTool.tool.methods.map((candidate) => candidate.id));\n if (!allowedMethods.has(method)) {\n return {kind: 'error', message: `Unauthorized integration tool method: ${method}`};\n }\n\n return {kind: 'ok', method};\n}\n\nfunction toolError(message: string): CallToolResult {\n return {\n isError: true,\n content: [{type: 'text', text: message}],\n };\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null && !Array.isArray(value);\n}\n\nfunction statusCode(value: unknown): number | undefined {\n return typeof value === 'number' && Number.isInteger(value) && value >= 100 && value <= 599\n ? value\n : undefined;\n}\n"],"names":["Server","CallToolRequestSchema","ListToolsRequestSchema","reportError","logger","normalizeIntegrationAgentToolCallErrorCode","INVALID_METHOD_LABEL","NO_METHOD_LABEL","buildAgentToolsMcpServer","params","server","name","version","capabilities","tools","setRequestHandler","authorizedTools","values","map","authorizedTool","mcpName","description","inputSchema","outputSchema","request","get","recordToolCall","recordCall","arguments","method","outcome","errorCode","toolError","args","isRecord","methodValidation","validateMethod","kind","message","result","dispatch","isError","toolCallErrorDetails","error","structuredContent","undefined","providerStatus","statusCode","status","code","record","err","boundary","operation","tool","methods","allowedMethods","Set","candidate","id","has","content","type","text","value","Array","isArray","Number","isInteger"],"mappings":"AAAA,SAAQA,MAAM,QAAO,4CAA4C;AACjE,SACEC,qBAAqB,EAErBC,sBAAsB,QACjB,qCAAqC;AAC5C,SAAQC,WAAW,QAAO,iCAAiC;AAC3D,SAAQC,MAAM,QAAO,8BAA8B;AACnD,SAAQC,0CAA0C,QAAO,oBAAoB;AAC7E,SACEC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I,CAACC,OAAO,EAAE,OAAO;QAAClB,MAAM;IAAI;IAEpD,MAAMR,SAASI,KAAKJ,MAAM;IAC1B,IAAI,OAAOA,WAAW,UAAU;QAC9B,OAAO;YAACQ,MAAM;YAASC,SAAS;QAAsD;IACxF;IAEA,MAAMkB,iBAAiB,IAAIC,IAAItC,eAAemC,IAAI,CAACC,OAAO,CAACrC,GAAG,CAAC,CAACwC,YAAcA,UAAUC,EAAE;IAC1F,IAAI,CAACH,eAAeI,GAAG,CAAC/B,SAAS;QAC/B,OAAO;YAACQ,MAAM;YAASC,SAAS,CAAC,sCAAsC,EAAET,QAAQ;QAAA;IACnF;IAEA,OAAO;QAACQ,MAAM;QAAMR;IAAM;AAC5B;AAEA,SAASG,UAAUM,OAAe;IAChC,OAAO;QACLG,SAAS;QACToB,SAAS;YAAC;gBAACC,MAAM;gBAAQC,MAAMzB;YAAO;SAAE;IAC1C;AACF;AAEA,SAASJ,SAAS8B,KAAc;IAC9B,OAAO,OAAOA,UAAU,YAAYA,UAAU,QAAQ,CAACC,MAAMC,OAAO,CAACF;AACvE;AAEA,SAASjB,WAAWiB,KAAc;IAChC,OAAO,OAAOA,UAAU,YAAYG,OAAOC,SAAS,CAACJ,UAAUA,SAAS,OAAOA,SAAS,MACpFA,QACAnB;AACN"}
@@ -1 +1 @@
1
- {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../../src/presentation/routes/errors.ts"],"names":[],"mappings":"AAoCA,wBAAgB,4BAA4B,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,CA0BlE"}
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../../src/presentation/routes/errors.ts"],"names":[],"mappings":"AAqCA,wBAAgB,4BAA4B,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,CA0BlE"}
@@ -6,7 +6,7 @@ function providerStatus(reason) {
6
6
  return 422;
7
7
  }
8
8
  function isProviderError(error) {
9
- return error instanceof IntegrationProviderError || error instanceof Error && 'reason' in error && typeof error.reason === 'string' && (error.reason === 'repository-not-found' || error.reason === 'file-not-found' || error.reason === 'access-denied' || error.reason === 'rate-limited' || error.reason === 'timeout' || error.reason === 'provider-unavailable' || error.reason === 'malformed-provider-response' || error.reason === 'content-too-large' || error.reason === 'too-many-files');
9
+ return error instanceof IntegrationProviderError || error instanceof Error && 'reason' in error && typeof error.reason === 'string' && (error.reason === 'repository-not-found' || error.reason === 'file-not-found' || error.reason === 'access-denied' || error.reason === 'rate-limited' || error.reason === 'timeout' || error.reason === 'provider-unavailable' || error.reason === 'provider-rejected' || error.reason === 'malformed-provider-response' || error.reason === 'content-too-large' || error.reason === 'too-many-files');
10
10
  }
11
11
  export function integrationRouteErrorHandler(error) {
12
12
  if (error instanceof IntegrationConnectionNotFoundError) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/presentation/routes/errors.ts"],"sourcesContent":["import {ClientError} from '@shipfox/node-fastify';\nimport {\n IntegrationCapabilityUnavailableError,\n IntegrationCheckoutUnsupportedError,\n IntegrationConnectionInactiveError,\n IntegrationConnectionNotFoundError,\n IntegrationConnectionWorkspaceMismatchError,\n IntegrationProviderError,\n type IntegrationProviderErrorReason,\n IntegrationProviderUnavailableError,\n} from '#core/errors.js';\n\nfunction providerStatus(reason: IntegrationProviderErrorReason): number {\n if (reason === 'rate-limited') return 429;\n if (reason === 'timeout' || reason === 'provider-unavailable') return 503;\n return 422;\n}\n\nfunction isProviderError(error: unknown): error is IntegrationProviderError {\n return (\n error instanceof IntegrationProviderError ||\n (error instanceof Error &&\n 'reason' in error &&\n typeof error.reason === 'string' &&\n (error.reason === 'repository-not-found' ||\n error.reason === 'file-not-found' ||\n error.reason === 'access-denied' ||\n error.reason === 'rate-limited' ||\n error.reason === 'timeout' ||\n error.reason === 'provider-unavailable' ||\n error.reason === 'malformed-provider-response' ||\n error.reason === 'content-too-large' ||\n error.reason === 'too-many-files'))\n );\n}\n\nexport function integrationRouteErrorHandler(error: unknown): never {\n if (error instanceof IntegrationConnectionNotFoundError) {\n throw new ClientError(error.message, 'integration-connection-not-found', {status: 404});\n }\n if (error instanceof IntegrationConnectionInactiveError) {\n throw new ClientError(error.message, 'integration-connection-inactive', {status: 422});\n }\n if (error instanceof IntegrationConnectionWorkspaceMismatchError) {\n throw new ClientError(error.message, 'forbidden', {status: 403});\n }\n if (error instanceof IntegrationProviderUnavailableError) {\n throw new ClientError(error.message, 'integration-provider-unavailable', {status: 422});\n }\n if (error instanceof IntegrationCapabilityUnavailableError) {\n throw new ClientError(error.message, 'integration-capability-unavailable', {status: 422});\n }\n if (error instanceof IntegrationCheckoutUnsupportedError) {\n throw new ClientError(error.message, 'integration-checkout-unsupported', {status: 422});\n }\n if (isProviderError(error)) {\n throw new ClientError(error.message, error.reason, {\n details: {retry_after_seconds: error.retryAfterSeconds},\n status: providerStatus(error.reason),\n });\n }\n throw error;\n}\n"],"names":["ClientError","IntegrationCapabilityUnavailableError","IntegrationCheckoutUnsupportedError","IntegrationConnectionInactiveError","IntegrationConnectionNotFoundError","IntegrationConnectionWorkspaceMismatchError","IntegrationProviderError","IntegrationProviderUnavailableError","providerStatus","reason","isProviderError","error","Error","integrationRouteErrorHandler","message","status","details","retry_after_seconds","retryAfterSeconds"],"mappings":"AAAA,SAAQA,WAAW,QAAO,wBAAwB;AAClD,SACEC,qCAAqC,EACrCC,mCAAmC,EACnCC,kCAAkC,EAClCC,kCAAkC,EAClCC,2CAA2C,EAC3CC,wBAAwB,EAExBC,mCAAmC,QAC9B,kBAAkB;AAEzB,SAASC,eAAeC,MAAsC;IAC5D,IAAIA,WAAW,gBAAgB,OAAO;IACtC,IAAIA,WAAW,aAAaA,WAAW,wBAAwB,OAAO;IACtE,OAAO;AACT;AAEA,SAASC,gBAAgBC,KAAc;IACrC,OACEA,iBAAiBL,4BAChBK,iBAAiBC,SAChB,YAAYD,SACZ,OAAOA,MAAMF,MAAM,KAAK,YACvBE,CAAAA,MAAMF,MAAM,KAAK,0BAChBE,MAAMF,MAAM,KAAK,oBACjBE,MAAMF,MAAM,KAAK,mBACjBE,MAAMF,MAAM,KAAK,kBACjBE,MAAMF,MAAM,KAAK,aACjBE,MAAMF,MAAM,KAAK,0BACjBE,MAAMF,MAAM,KAAK,iCACjBE,MAAMF,MAAM,KAAK,uBACjBE,MAAMF,MAAM,KAAK,gBAAe;AAExC;AAEA,OAAO,SAASI,6BAA6BF,KAAc;IACzD,IAAIA,iBAAiBP,oCAAoC;QACvD,MAAM,IAAIJ,YAAYW,MAAMG,OAAO,EAAE,oCAAoC;YAACC,QAAQ;QAAG;IACvF;IACA,IAAIJ,iBAAiBR,oCAAoC;QACvD,MAAM,IAAIH,YAAYW,MAAMG,OAAO,EAAE,mCAAmC;YAACC,QAAQ;QAAG;IACtF;IACA,IAAIJ,iBAAiBN,6CAA6C;QAChE,MAAM,IAAIL,YAAYW,MAAMG,OAAO,EAAE,aAAa;YAACC,QAAQ;QAAG;IAChE;IACA,IAAIJ,iBAAiBJ,qCAAqC;QACxD,MAAM,IAAIP,YAAYW,MAAMG,OAAO,EAAE,oCAAoC;YAACC,QAAQ;QAAG;IACvF;IACA,IAAIJ,iBAAiBV,uCAAuC;QAC1D,MAAM,IAAID,YAAYW,MAAMG,OAAO,EAAE,sCAAsC;YAACC,QAAQ;QAAG;IACzF;IACA,IAAIJ,iBAAiBT,qCAAqC;QACxD,MAAM,IAAIF,YAAYW,MAAMG,OAAO,EAAE,oCAAoC;YAACC,QAAQ;QAAG;IACvF;IACA,IAAIL,gBAAgBC,QAAQ;QAC1B,MAAM,IAAIX,YAAYW,MAAMG,OAAO,EAAEH,MAAMF,MAAM,EAAE;YACjDO,SAAS;gBAACC,qBAAqBN,MAAMO,iBAAiB;YAAA;YACtDH,QAAQP,eAAeG,MAAMF,MAAM;QACrC;IACF;IACA,MAAME;AACR"}
1
+ {"version":3,"sources":["../../../src/presentation/routes/errors.ts"],"sourcesContent":["import {ClientError} from '@shipfox/node-fastify';\nimport {\n IntegrationCapabilityUnavailableError,\n IntegrationCheckoutUnsupportedError,\n IntegrationConnectionInactiveError,\n IntegrationConnectionNotFoundError,\n IntegrationConnectionWorkspaceMismatchError,\n IntegrationProviderError,\n type IntegrationProviderErrorReason,\n IntegrationProviderUnavailableError,\n} from '#core/errors.js';\n\nfunction providerStatus(reason: IntegrationProviderErrorReason): number {\n if (reason === 'rate-limited') return 429;\n if (reason === 'timeout' || reason === 'provider-unavailable') return 503;\n return 422;\n}\n\nfunction isProviderError(error: unknown): error is IntegrationProviderError {\n return (\n error instanceof IntegrationProviderError ||\n (error instanceof Error &&\n 'reason' in error &&\n typeof error.reason === 'string' &&\n (error.reason === 'repository-not-found' ||\n error.reason === 'file-not-found' ||\n error.reason === 'access-denied' ||\n error.reason === 'rate-limited' ||\n error.reason === 'timeout' ||\n error.reason === 'provider-unavailable' ||\n error.reason === 'provider-rejected' ||\n error.reason === 'malformed-provider-response' ||\n error.reason === 'content-too-large' ||\n error.reason === 'too-many-files'))\n );\n}\n\nexport function integrationRouteErrorHandler(error: unknown): never {\n if (error instanceof IntegrationConnectionNotFoundError) {\n throw new ClientError(error.message, 'integration-connection-not-found', {status: 404});\n }\n if (error instanceof IntegrationConnectionInactiveError) {\n throw new ClientError(error.message, 'integration-connection-inactive', {status: 422});\n }\n if (error instanceof IntegrationConnectionWorkspaceMismatchError) {\n throw new ClientError(error.message, 'forbidden', {status: 403});\n }\n if (error instanceof IntegrationProviderUnavailableError) {\n throw new ClientError(error.message, 'integration-provider-unavailable', {status: 422});\n }\n if (error instanceof IntegrationCapabilityUnavailableError) {\n throw new ClientError(error.message, 'integration-capability-unavailable', {status: 422});\n }\n if (error instanceof IntegrationCheckoutUnsupportedError) {\n throw new ClientError(error.message, 'integration-checkout-unsupported', {status: 422});\n }\n if (isProviderError(error)) {\n throw new ClientError(error.message, error.reason, {\n details: {retry_after_seconds: error.retryAfterSeconds},\n status: providerStatus(error.reason),\n });\n }\n throw error;\n}\n"],"names":["ClientError","IntegrationCapabilityUnavailableError","IntegrationCheckoutUnsupportedError","IntegrationConnectionInactiveError","IntegrationConnectionNotFoundError","IntegrationConnectionWorkspaceMismatchError","IntegrationProviderError","IntegrationProviderUnavailableError","providerStatus","reason","isProviderError","error","Error","integrationRouteErrorHandler","message","status","details","retry_after_seconds","retryAfterSeconds"],"mappings":"AAAA,SAAQA,WAAW,QAAO,wBAAwB;AAClD,SACEC,qCAAqC,EACrCC,mCAAmC,EACnCC,kCAAkC,EAClCC,kCAAkC,EAClCC,2CAA2C,EAC3CC,wBAAwB,EAExBC,mCAAmC,QAC9B,kBAAkB;AAEzB,SAASC,eAAeC,MAAsC;IAC5D,IAAIA,WAAW,gBAAgB,OAAO;IACtC,IAAIA,WAAW,aAAaA,WAAW,wBAAwB,OAAO;IACtE,OAAO;AACT;AAEA,SAASC,gBAAgBC,KAAc;IACrC,OACEA,iBAAiBL,4BAChBK,iBAAiBC,SAChB,YAAYD,SACZ,OAAOA,MAAMF,MAAM,KAAK,YACvBE,CAAAA,MAAMF,MAAM,KAAK,0BAChBE,MAAMF,MAAM,KAAK,oBACjBE,MAAMF,MAAM,KAAK,mBACjBE,MAAMF,MAAM,KAAK,kBACjBE,MAAMF,MAAM,KAAK,aACjBE,MAAMF,MAAM,KAAK,0BACjBE,MAAMF,MAAM,KAAK,uBACjBE,MAAMF,MAAM,KAAK,iCACjBE,MAAMF,MAAM,KAAK,uBACjBE,MAAMF,MAAM,KAAK,gBAAe;AAExC;AAEA,OAAO,SAASI,6BAA6BF,KAAc;IACzD,IAAIA,iBAAiBP,oCAAoC;QACvD,MAAM,IAAIJ,YAAYW,MAAMG,OAAO,EAAE,oCAAoC;YAACC,QAAQ;QAAG;IACvF;IACA,IAAIJ,iBAAiBR,oCAAoC;QACvD,MAAM,IAAIH,YAAYW,MAAMG,OAAO,EAAE,mCAAmC;YAACC,QAAQ;QAAG;IACtF;IACA,IAAIJ,iBAAiBN,6CAA6C;QAChE,MAAM,IAAIL,YAAYW,MAAMG,OAAO,EAAE,aAAa;YAACC,QAAQ;QAAG;IAChE;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