@ankhorage/api 0.7.0 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/README.md +2 -1
- package/dist/api.d.ts +3 -1
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js +1 -0
- package/dist/api.js.map +1 -1
- package/dist/features/execution/createTrustedExternalApiBroker.d.ts.map +1 -1
- package/dist/features/execution/createTrustedExternalApiBroker.js +28 -8
- package/dist/features/execution/createTrustedExternalApiBroker.js.map +1 -1
- package/dist/features/execution/createWorkerTrustedApiHandler.d.ts +5 -0
- package/dist/features/execution/createWorkerTrustedApiHandler.d.ts.map +1 -0
- package/dist/features/execution/createWorkerTrustedApiHandler.js +49 -0
- package/dist/features/execution/createWorkerTrustedApiHandler.js.map +1 -0
- package/dist/features/execution/readWorkerBrokerRequestAsync.d.ts +4 -0
- package/dist/features/execution/readWorkerBrokerRequestAsync.d.ts.map +1 -0
- package/dist/features/execution/readWorkerBrokerRequestAsync.js +64 -0
- package/dist/features/execution/readWorkerBrokerRequestAsync.js.map +1 -0
- package/dist/types/api.d.ts +14 -0
- package/dist/types/api.d.ts.map +1 -1
- package/dist/types/api.js.map +1 -1
- package/dist/types/worker.d.ts +9 -0
- package/dist/types/worker.d.ts.map +1 -0
- package/dist/types/worker.js +2 -0
- package/dist/types/worker.js.map +1 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
# @ankhorage/api
|
|
5
5
|
|
|
6
|
-
         
|
|
7
7
|
|
|
8
8
|
Framework-neutral executable API runtime for Ankhorage.
|
|
9
9
|
|
|
@@ -61,4 +61,5 @@ const definition = {
|
|
|
61
61
|
- [Export graph](././paradox/diagrams/export-graph.mmd)
|
|
62
62
|
- [composeAuthorizedApiRuntime sequence](././paradox/diagrams/sequences/compose-authorized-api-runtime.mmd)
|
|
63
63
|
- [createApiRuntime sequence](././paradox/diagrams/sequences/create-api-runtime.mmd)
|
|
64
|
+
- [createWorkerTrustedApiHandler sequence](././paradox/diagrams/sequences/create-worker-trusted-api-handler.mmd)
|
|
64
65
|
- [projectApiCapabilities sequence](././paradox/diagrams/sequences/project-api-capabilities.mmd)
|
package/dist/api.d.ts
CHANGED
|
@@ -3,7 +3,9 @@ export { composeAuthorizedApiRuntime } from './features/execution/composeAuthori
|
|
|
3
3
|
export { createApiRuntime } from './features/execution/createApiRuntime.js';
|
|
4
4
|
export { createApiTransportHandler } from './features/execution/createApiTransportHandler.js';
|
|
5
5
|
export { createTrustedExternalApiBroker } from './features/execution/createTrustedExternalApiBroker.js';
|
|
6
|
+
export { createWorkerTrustedApiHandler } from './features/execution/createWorkerTrustedApiHandler.js';
|
|
6
7
|
export { projectApiCapabilities } from './features/execution/projectApiCapabilities.js';
|
|
7
8
|
export { resolveApiOperationBindings } from './features/execution/resolveApiOperationBindings.js';
|
|
8
|
-
export type { ApiApprovedHandler, ApiAuthorizationPolicy, ApiAuthorizationRequest, ApiCompositionContext, ApiHandler, ApiHandlerApproval, ApiHandlerContext, ApiHandlerRegistry, ApiHandlerResolutionRequest, ApiHandlerResolver, ApiHandlerResponse, ApiOperationBinding, ApiRequest, ApiResponse, ApiRuntime, ApiTransportAdapter, ComposeAuthorizedApiRuntimeOptions, CreateTrustedExternalApiBrokerOptions, TrustedExternalApiBroker, TrustedExternalApiBrokerContext, TrustedExternalApiBrokerRequest, TrustedExternalApiCredentials, TrustedExternalApiExecutionResult, TrustedExternalApiOperation, } from './types/api.js';
|
|
9
|
+
export type { ApiApprovedHandler, ApiAuthorizationPolicy, ApiAuthorizationRequest, ApiCompositionContext, ApiHandler, ApiHandlerApproval, ApiHandlerContext, ApiHandlerRegistry, ApiHandlerResolutionRequest, ApiHandlerResolver, ApiHandlerResponse, ApiOperationBinding, ApiRequest, ApiResponse, ApiRuntime, ApiTransportAdapter, ComposeAuthorizedApiRuntimeOptions, CreateTrustedExternalApiBrokerOptions, PersistentExternalRequestBudgetPort, PersistentExternalRequestReservation, TrustedExternalApiBroker, TrustedExternalApiBrokerContext, TrustedExternalApiBrokerRequest, TrustedExternalApiCredentials, TrustedExternalApiExecutionResult, TrustedExternalApiOperation, } from './types/api.js';
|
|
10
|
+
export type { CreateWorkerTrustedApiHandlerOptions } from './types/worker.js';
|
|
9
11
|
//# sourceMappingURL=api.d.ts.map
|
package/dist/api.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,2BAA2B,EAAE,MAAM,qDAAqD,CAAC;AAClG,OAAO,EAAE,gBAAgB,EAAE,MAAM,0CAA0C,CAAC;AAC5E,OAAO,EAAE,yBAAyB,EAAE,MAAM,mDAAmD,CAAC;AAC9F,OAAO,EAAE,8BAA8B,EAAE,MAAM,wDAAwD,CAAC;AACxG,OAAO,EAAE,sBAAsB,EAAE,MAAM,gDAAgD,CAAC;AACxF,OAAO,EAAE,2BAA2B,EAAE,MAAM,qDAAqD,CAAC;AAClG,YAAY,EACV,kBAAkB,EAClB,sBAAsB,EACtB,uBAAuB,EACvB,qBAAqB,EACrB,UAAU,EACV,kBAAkB,EAClB,iBAAiB,EACjB,kBAAkB,EAClB,2BAA2B,EAC3B,kBAAkB,EAClB,kBAAkB,EAClB,mBAAmB,EACnB,UAAU,EACV,WAAW,EACX,UAAU,EACV,mBAAmB,EACnB,kCAAkC,EAClC,qCAAqC,EACrC,wBAAwB,EACxB,+BAA+B,EAC/B,+BAA+B,EAC/B,6BAA6B,EAC7B,iCAAiC,EACjC,2BAA2B,GAC5B,MAAM,gBAAgB,CAAC"}
|
|
1
|
+
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,2BAA2B,EAAE,MAAM,qDAAqD,CAAC;AAClG,OAAO,EAAE,gBAAgB,EAAE,MAAM,0CAA0C,CAAC;AAC5E,OAAO,EAAE,yBAAyB,EAAE,MAAM,mDAAmD,CAAC;AAC9F,OAAO,EAAE,8BAA8B,EAAE,MAAM,wDAAwD,CAAC;AACxG,OAAO,EAAE,6BAA6B,EAAE,MAAM,uDAAuD,CAAC;AACtG,OAAO,EAAE,sBAAsB,EAAE,MAAM,gDAAgD,CAAC;AACxF,OAAO,EAAE,2BAA2B,EAAE,MAAM,qDAAqD,CAAC;AAClG,YAAY,EACV,kBAAkB,EAClB,sBAAsB,EACtB,uBAAuB,EACvB,qBAAqB,EACrB,UAAU,EACV,kBAAkB,EAClB,iBAAiB,EACjB,kBAAkB,EAClB,2BAA2B,EAC3B,kBAAkB,EAClB,kBAAkB,EAClB,mBAAmB,EACnB,UAAU,EACV,WAAW,EACX,UAAU,EACV,mBAAmB,EACnB,kCAAkC,EAClC,qCAAqC,EACrC,mCAAmC,EACnC,oCAAoC,EACpC,wBAAwB,EACxB,+BAA+B,EAC/B,+BAA+B,EAC/B,6BAA6B,EAC7B,iCAAiC,EACjC,2BAA2B,GAC5B,MAAM,gBAAgB,CAAC;AACxB,YAAY,EAAE,oCAAoC,EAAE,MAAM,mBAAmB,CAAC"}
|
package/dist/api.js
CHANGED
|
@@ -3,6 +3,7 @@ export { composeAuthorizedApiRuntime } from './features/execution/composeAuthori
|
|
|
3
3
|
export { createApiRuntime } from './features/execution/createApiRuntime.js';
|
|
4
4
|
export { createApiTransportHandler } from './features/execution/createApiTransportHandler.js';
|
|
5
5
|
export { createTrustedExternalApiBroker } from './features/execution/createTrustedExternalApiBroker.js';
|
|
6
|
+
export { createWorkerTrustedApiHandler } from './features/execution/createWorkerTrustedApiHandler.js';
|
|
6
7
|
export { projectApiCapabilities } from './features/execution/projectApiCapabilities.js';
|
|
7
8
|
export { resolveApiOperationBindings } from './features/execution/resolveApiOperationBindings.js';
|
|
8
9
|
//# sourceMappingURL=api.js.map
|
package/dist/api.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.js","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,2BAA2B,EAAE,MAAM,qDAAqD,CAAC;AAClG,OAAO,EAAE,gBAAgB,EAAE,MAAM,0CAA0C,CAAC;AAC5E,OAAO,EAAE,yBAAyB,EAAE,MAAM,mDAAmD,CAAC;AAC9F,OAAO,EAAE,8BAA8B,EAAE,MAAM,wDAAwD,CAAC;AACxG,OAAO,EAAE,sBAAsB,EAAE,MAAM,gDAAgD,CAAC;AACxF,OAAO,EAAE,2BAA2B,EAAE,MAAM,qDAAqD,CAAC","sourcesContent":["export { CAPABILITIES } from './capabilities/index.js';\nexport { composeAuthorizedApiRuntime } from './features/execution/composeAuthorizedApiRuntime.js';\nexport { createApiRuntime } from './features/execution/createApiRuntime.js';\nexport { createApiTransportHandler } from './features/execution/createApiTransportHandler.js';\nexport { createTrustedExternalApiBroker } from './features/execution/createTrustedExternalApiBroker.js';\nexport { projectApiCapabilities } from './features/execution/projectApiCapabilities.js';\nexport { resolveApiOperationBindings } from './features/execution/resolveApiOperationBindings.js';\nexport type {\n ApiApprovedHandler,\n ApiAuthorizationPolicy,\n ApiAuthorizationRequest,\n ApiCompositionContext,\n ApiHandler,\n ApiHandlerApproval,\n ApiHandlerContext,\n ApiHandlerRegistry,\n ApiHandlerResolutionRequest,\n ApiHandlerResolver,\n ApiHandlerResponse,\n ApiOperationBinding,\n ApiRequest,\n ApiResponse,\n ApiRuntime,\n ApiTransportAdapter,\n ComposeAuthorizedApiRuntimeOptions,\n CreateTrustedExternalApiBrokerOptions,\n TrustedExternalApiBroker,\n TrustedExternalApiBrokerContext,\n TrustedExternalApiBrokerRequest,\n TrustedExternalApiCredentials,\n TrustedExternalApiExecutionResult,\n TrustedExternalApiOperation,\n} from './types/api.js';\n"]}
|
|
1
|
+
{"version":3,"file":"api.js","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,2BAA2B,EAAE,MAAM,qDAAqD,CAAC;AAClG,OAAO,EAAE,gBAAgB,EAAE,MAAM,0CAA0C,CAAC;AAC5E,OAAO,EAAE,yBAAyB,EAAE,MAAM,mDAAmD,CAAC;AAC9F,OAAO,EAAE,8BAA8B,EAAE,MAAM,wDAAwD,CAAC;AACxG,OAAO,EAAE,6BAA6B,EAAE,MAAM,uDAAuD,CAAC;AACtG,OAAO,EAAE,sBAAsB,EAAE,MAAM,gDAAgD,CAAC;AACxF,OAAO,EAAE,2BAA2B,EAAE,MAAM,qDAAqD,CAAC","sourcesContent":["export { CAPABILITIES } from './capabilities/index.js';\nexport { composeAuthorizedApiRuntime } from './features/execution/composeAuthorizedApiRuntime.js';\nexport { createApiRuntime } from './features/execution/createApiRuntime.js';\nexport { createApiTransportHandler } from './features/execution/createApiTransportHandler.js';\nexport { createTrustedExternalApiBroker } from './features/execution/createTrustedExternalApiBroker.js';\nexport { createWorkerTrustedApiHandler } from './features/execution/createWorkerTrustedApiHandler.js';\nexport { projectApiCapabilities } from './features/execution/projectApiCapabilities.js';\nexport { resolveApiOperationBindings } from './features/execution/resolveApiOperationBindings.js';\nexport type {\n ApiApprovedHandler,\n ApiAuthorizationPolicy,\n ApiAuthorizationRequest,\n ApiCompositionContext,\n ApiHandler,\n ApiHandlerApproval,\n ApiHandlerContext,\n ApiHandlerRegistry,\n ApiHandlerResolutionRequest,\n ApiHandlerResolver,\n ApiHandlerResponse,\n ApiOperationBinding,\n ApiRequest,\n ApiResponse,\n ApiRuntime,\n ApiTransportAdapter,\n ComposeAuthorizedApiRuntimeOptions,\n CreateTrustedExternalApiBrokerOptions,\n PersistentExternalRequestBudgetPort,\n PersistentExternalRequestReservation,\n TrustedExternalApiBroker,\n TrustedExternalApiBrokerContext,\n TrustedExternalApiBrokerRequest,\n TrustedExternalApiCredentials,\n TrustedExternalApiExecutionResult,\n TrustedExternalApiOperation,\n} from './types/api.js';\nexport type { CreateWorkerTrustedApiHandlerOptions } from './types/worker.js';\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createTrustedExternalApiBroker.d.ts","sourceRoot":"","sources":["../../../src/features/execution/createTrustedExternalApiBroker.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,qCAAqC,
|
|
1
|
+
{"version":3,"file":"createTrustedExternalApiBroker.d.ts","sourceRoot":"","sources":["../../../src/features/execution/createTrustedExternalApiBroker.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,qCAAqC,EAErC,wBAAwB,EAGxB,2BAA2B,EAC5B,MAAM,oBAAoB,CAAC;AAE5B;;;;;;GAMG;AACH,wBAAgB,8BAA8B,CAC5C,kBAAkB,SAAS,2BAA2B,EACtD,OAAO,EAAE,qCAAqC,CAAC,kBAAkB,CAAC,GAAG,wBAAwB,CAK9F"}
|
|
@@ -26,21 +26,41 @@ async function executeTrustedOperationAsync(options, context, request) {
|
|
|
26
26
|
operation,
|
|
27
27
|
input: request.input,
|
|
28
28
|
});
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
return brokerErrorResponse(424, 'credential_unavailable');
|
|
32
|
-
}
|
|
33
|
-
const result = await options.executeOperationAsync({
|
|
29
|
+
const reservation = await options.requestBudget?.reserveAsync({
|
|
30
|
+
scope: context.scope,
|
|
34
31
|
operation,
|
|
35
|
-
input,
|
|
36
|
-
...(credentials === undefined ? {} : { credentials }),
|
|
37
32
|
});
|
|
38
|
-
|
|
33
|
+
if (options.requestBudget !== undefined && reservation === undefined) {
|
|
34
|
+
return brokerErrorResponse(429, 'external_request_budget_exhausted');
|
|
35
|
+
}
|
|
36
|
+
try {
|
|
37
|
+
return await executeReservedOperationAsync(options, context, operation, input, reservation);
|
|
38
|
+
}
|
|
39
|
+
finally {
|
|
40
|
+
await reservation?.releaseAsync();
|
|
41
|
+
}
|
|
39
42
|
}
|
|
40
43
|
catch {
|
|
41
44
|
return brokerErrorResponse(502, 'external_operation_failed');
|
|
42
45
|
}
|
|
43
46
|
}
|
|
47
|
+
/*** Hold the reservation until execution settles, including failed credential resolution. */
|
|
48
|
+
async function executeReservedOperationAsync(options, context, operation, input, reservation) {
|
|
49
|
+
const credentials = await resolveCredentialsAsync(options, context, operation);
|
|
50
|
+
if (operation.credentialsRequired === true && credentials === undefined) {
|
|
51
|
+
return brokerErrorResponse(424, 'credential_unavailable');
|
|
52
|
+
}
|
|
53
|
+
if (reservation?.signal.aborted === true) {
|
|
54
|
+
return brokerErrorResponse(502, 'external_operation_failed');
|
|
55
|
+
}
|
|
56
|
+
const result = await options.executeOperationAsync({
|
|
57
|
+
operation,
|
|
58
|
+
input,
|
|
59
|
+
...(credentials === undefined ? {} : { credentials }),
|
|
60
|
+
...(reservation === undefined ? {} : { signal: reservation.signal }),
|
|
61
|
+
});
|
|
62
|
+
return publicResponse(result.status, result.publicBody);
|
|
63
|
+
}
|
|
44
64
|
/*** Resolve a secret only for an operation whose trusted definition explicitly requires one. */
|
|
45
65
|
async function resolveCredentialsAsync(options, context, operation) {
|
|
46
66
|
if (operation.credentialsRequired !== true)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createTrustedExternalApiBroker.js","sourceRoot":"","sources":["../../../src/features/execution/createTrustedExternalApiBroker.ts"],"names":[],"mappings":"AASA;;;;;;GAMG;AACH,MAAM,UAAU,8BAA8B,CAE5C,OAAkE;IAClE,OAAO;QACL,YAAY,EAAE,KAAK,EAAE,EAAE,OAAO,EAAE,OAAO,EAAE,EAAE,EAAE,CAC3C,4BAA4B,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC;KAC1D,CAAC;AACJ,CAAC;AAED,6FAA6F;AAC7F,KAAK,U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AACJ,CAAC;AAED,qDAAqD;AACrD,SAAS,UAAU,CAAC,KAAa;IAC/B,OAAO,KAAK,CAAC,IAAI,EAAE,CAAC,MAAM,GAAG,CAAC,CAAC;AACjC,CAAC","sourcesContent":["import type {\n ApiResponse,\n CreateTrustedExternalApiBrokerOptions,\n TrustedExternalApiBroker,\n TrustedExternalApiBrokerContext,\n TrustedExternalApiBrokerRequest,\n TrustedExternalApiOperation,\n} from '../../types/api.js';\n\n/***\n * Create a framework-neutral, fail-closed boundary for generated-app external API operations.\n *\n * The caller supplies operation identity and input only; trusted host ports own target,\n * credentials, authorization, validation, and caller-safe result projection.\n * @security createTrustedExternalApiBroker.test.ts#denies before resolving secrets or executing network work\n */\nexport function createTrustedExternalApiBroker<\n TResolvedOperation extends TrustedExternalApiOperation,\n>(options: CreateTrustedExternalApiBrokerOptions<TResolvedOperation>): TrustedExternalApiBroker {\n return {\n executeAsync: async ({ context, request }) =>\n executeTrustedOperationAsync(options, context, request),\n };\n}\n\n/*** Authorize before resolving any operation, credential, or outbound execution resource. */\nasync function executeTrustedOperationAsync<TResolvedOperation extends TrustedExternalApiOperation>(\n options: CreateTrustedExternalApiBrokerOptions<TResolvedOperation>,\n context: TrustedExternalApiBrokerContext,\n request: TrustedExternalApiBrokerRequest,\n): Promise<ApiResponse> {\n if (!isTrustedBrokerContext(context) || hasCallerSuppliedTarget(request)) {\n return brokerErrorResponse(403, 'forbidden');\n }\n if (!(await isAuthorizedAsync(options, context, request))) {\n return brokerErrorResponse(403, 'forbidden');\n }\n\n const operation = await resolveOperationAsync(options, context, request);\n if (!operation) return brokerErrorResponse(404, 'operation_not_found');\n\n try {\n const input = await options.validateInputAsync({\n operation,\n input: request.input,\n });\n const credentials = await resolveCredentialsAsync(options, context, operation);\n if (operation.credentialsRequired === true && credentials === undefined) {\n return brokerErrorResponse(424, 'credential_unavailable');\n }\n const result = await options.executeOperationAsync({\n operation,\n input,\n ...(credentials === undefined ? {} : { credentials }),\n });\n return publicResponse(result.status, result.publicBody);\n } catch {\n return brokerErrorResponse(502, 'external_operation_failed');\n }\n}\n\n/*** Resolve a secret only for an operation whose trusted definition explicitly requires one. */\nasync function resolveCredentialsAsync<TResolvedOperation extends TrustedExternalApiOperation>(\n options: CreateTrustedExternalApiBrokerOptions<TResolvedOperation>,\n context: TrustedExternalApiBrokerContext,\n operation: TResolvedOperation,\n) {\n if (operation.credentialsRequired !== true) return undefined;\n return options.resolveCredentialsAsync({\n caller: context.caller,\n scope: context.scope,\n operation,\n });\n}\n\n/*** Treat absent caller identity or incomplete project scope as a denial. */\nfunction isTrustedBrokerContext(context: TrustedExternalApiBrokerContext): boolean {\n return (\n context.caller !== undefined &&\n context.caller !== null &&\n isNonEmpty(context.scope.appId) &&\n isNonEmpty(context.scope.projectId) &&\n isNonEmpty(context.scope.environment)\n );\n}\n\n/*** Reject target-selection fields that are never part of the broker's public request contract. */\nfunction hasCallerSuppliedTarget(request: TrustedExternalApiBrokerRequest): boolean {\n return ['url', 'host', 'baseUrl', 'upstreamUrl', 'target'].some((key) =>\n Object.hasOwn(request, key),\n );\n}\n\n/*** Treat a missing, throwing, or false authorization decision as a denial. */\nasync function isAuthorizedAsync<TResolvedOperation extends TrustedExternalApiOperation>(\n options: CreateTrustedExternalApiBrokerOptions<TResolvedOperation>,\n context: TrustedExternalApiBrokerContext,\n request: TrustedExternalApiBrokerRequest,\n): Promise<boolean> {\n try {\n return await options.authorizeAsync({ context, request });\n } catch {\n return false;\n }\n}\n\n/*** Resolve only the exact operation whose server-side identity matches the caller request. */\nasync function resolveOperationAsync<TResolvedOperation extends TrustedExternalApiOperation>(\n options: CreateTrustedExternalApiBrokerOptions<TResolvedOperation>,\n context: TrustedExternalApiBrokerContext,\n request: TrustedExternalApiBrokerRequest,\n): Promise<TResolvedOperation | undefined> {\n try {\n const operation = await options.resolveOperationAsync({\n scope: context.scope,\n request,\n });\n return operation !== undefined && operationMatchesRequest(operation, request)\n ? operation\n : undefined;\n } catch {\n return undefined;\n }\n}\n\n/*** Prevent a resolver from substituting another declared API, endpoint, or operation. */\nfunction operationMatchesRequest(\n operation: TrustedExternalApiOperation,\n request: TrustedExternalApiBrokerRequest,\n): boolean {\n return (\n operation.apiId === request.apiId &&\n operation.endpointId === request.endpointId &&\n operation.operationId === request.operationId\n );\n}\n\n/*** Return a result contract that never exposes credential headers or provider diagnostics. */\nfunction publicResponse(status: number, publicBody: unknown): ApiResponse {\n return {\n status: Number.isInteger(status) && status >= 100 && status <= 599 ? status : 502,\n headers: {},\n ...(publicBody === undefined ? {} : { body: publicBody }),\n };\n}\n\n/*** Produce a stable caller-visible error without leaking upstream configuration or exception text. */\nfunction brokerErrorResponse(status: number, code: string): ApiResponse {\n return {\n status,\n headers: { 'content-type': 'application/json' },\n body: { error: { code } },\n };\n}\n\n/*** Identify one non-blank trusted scope segment. */\nfunction isNonEmpty(value: string): boolean {\n return value.trim().length > 0;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"createTrustedExternalApiBroker.js","sourceRoot":"","sources":["../../../src/features/execution/createTrustedExternalApiBroker.ts"],"names":[],"mappings":"AAUA;;;;;;GAMG;AACH,MAAM,UAAU,8BAA8B,CAE5C,OAAkE;IAClE,OAAO;QACL,YAAY,EAAE,KAAK,EAAE,EAAE,OAAO,EAAE,OAAO,EAAE,EAAE,EAAE,CAC3C,4BAA4B,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC;KAC1D,CAAC;AACJ,CAAC;AAED,6FAA6F;AAC7F,KAAK,UAAU,4BAA4B,CACzC,OAAkE,EAClE,OAAwC,EACxC,OAAwC;IAExC,IAAI,CAAC,sBAAsB,CAAC,OAAO,CAAC,IAAI,uBAAuB,CAAC,OAAO,CAAC,EAAE,CAAC;QACzE,OAAO,mBAAmB,CAAC,GAAG,EAAE,WAAW,CAAC,CAAC;IAC/C,CAAC;IACD,IAAI,CAAC,CAAC,MAAM,iBAAiB,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC,EAAE,CAAC;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MAAc,EAAE,UAAmB;IACzD,OAAO;QACL,MAAM,EAAE,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI,MAAM,IAAI,GAAG,IAAI,MAAM,IAAI,GAAG,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG;QACjF,OAAO,EAAE,EAAE;QACX,GAAG,CAAC,UAAU,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,CAAC;KAC1D,CAAC;AACJ,CAAC;AAED,uGAAuG;AACvG,SAAS,mBAAmB,CAAC,MAAc,EAAE,IAAY;IACvD,OAAO;QACL,MAAM;QACN,OAAO,EAAE,EAAE,cAAc,EAAE,kBAAkB,EAAE;QAC/C,IAAI,EAAE,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,EAAE;KAC1B,CAAC;AACJ,CAAC;AAED,qDAAqD;AACrD,SAAS,UAAU,CAAC,KAAa;IAC/B,OAAO,KAAK,CAAC,IAAI,EAAE,CAAC,MAAM,GAAG,CAAC,CAAC;AACjC,CAAC","sourcesContent":["import type {\n ApiResponse,\n CreateTrustedExternalApiBrokerOptions,\n PersistentExternalRequestReservation,\n TrustedExternalApiBroker,\n TrustedExternalApiBrokerContext,\n TrustedExternalApiBrokerRequest,\n TrustedExternalApiOperation,\n} from '../../types/api.js';\n\n/***\n * Create a framework-neutral, fail-closed boundary for generated-app external API operations.\n *\n * The caller supplies operation identity and input only; trusted host ports own target,\n * credentials, authorization, validation, and caller-safe result projection.\n * @security createTrustedExternalApiBroker.test.ts#denies before resolving secrets or executing network work\n */\nexport function createTrustedExternalApiBroker<\n TResolvedOperation extends TrustedExternalApiOperation,\n>(options: CreateTrustedExternalApiBrokerOptions<TResolvedOperation>): TrustedExternalApiBroker {\n return {\n executeAsync: async ({ context, request }) =>\n executeTrustedOperationAsync(options, context, request),\n };\n}\n\n/*** Authorize before resolving any operation, credential, or outbound execution resource. */\nasync function executeTrustedOperationAsync<TResolvedOperation extends TrustedExternalApiOperation>(\n options: CreateTrustedExternalApiBrokerOptions<TResolvedOperation>,\n context: TrustedExternalApiBrokerContext,\n request: TrustedExternalApiBrokerRequest,\n): Promise<ApiResponse> {\n if (!isTrustedBrokerContext(context) || hasCallerSuppliedTarget(request)) {\n return brokerErrorResponse(403, 'forbidden');\n }\n if (!(await isAuthorizedAsync(options, context, request))) {\n return brokerErrorResponse(403, 'forbidden');\n }\n\n const operation = await resolveOperationAsync(options, context, request);\n if (!operation) return brokerErrorResponse(404, 'operation_not_found');\n\n try {\n const input = await options.validateInputAsync({\n operation,\n input: request.input,\n });\n const reservation = await options.requestBudget?.reserveAsync({\n scope: context.scope,\n operation,\n });\n if (options.requestBudget !== undefined && reservation === undefined) {\n return brokerErrorResponse(429, 'external_request_budget_exhausted');\n }\n try {\n return await executeReservedOperationAsync(options, context, operation, input, reservation);\n } finally {\n await reservation?.releaseAsync();\n }\n } catch {\n return brokerErrorResponse(502, 'external_operation_failed');\n }\n}\n\n/*** Hold the reservation until execution settles, including failed credential resolution. */\nasync function executeReservedOperationAsync<\n TResolvedOperation extends TrustedExternalApiOperation,\n>(\n options: CreateTrustedExternalApiBrokerOptions<TResolvedOperation>,\n context: TrustedExternalApiBrokerContext,\n operation: TResolvedOperation,\n input: unknown,\n reservation: PersistentExternalRequestReservation | undefined,\n): Promise<ApiResponse> {\n const credentials = await resolveCredentialsAsync(options, context, operation);\n if (operation.credentialsRequired === true && credentials === undefined) {\n return brokerErrorResponse(424, 'credential_unavailable');\n }\n if (reservation?.signal.aborted === true) {\n return brokerErrorResponse(502, 'external_operation_failed');\n }\n const result = await options.executeOperationAsync({\n operation,\n input,\n ...(credentials === undefined ? {} : { credentials }),\n ...(reservation === undefined ? {} : { signal: reservation.signal }),\n });\n return publicResponse(result.status, result.publicBody);\n}\n\n/*** Resolve a secret only for an operation whose trusted definition explicitly requires one. */\nasync function resolveCredentialsAsync<TResolvedOperation extends TrustedExternalApiOperation>(\n options: CreateTrustedExternalApiBrokerOptions<TResolvedOperation>,\n context: TrustedExternalApiBrokerContext,\n operation: TResolvedOperation,\n) {\n if (operation.credentialsRequired !== true) return undefined;\n return options.resolveCredentialsAsync({\n caller: context.caller,\n scope: context.scope,\n operation,\n });\n}\n\n/*** Treat absent caller identity or incomplete project scope as a denial. */\nfunction isTrustedBrokerContext(context: TrustedExternalApiBrokerContext): boolean {\n return (\n context.caller !== undefined &&\n context.caller !== null &&\n isNonEmpty(context.scope.appId) &&\n isNonEmpty(context.scope.projectId) &&\n isNonEmpty(context.scope.environment)\n );\n}\n\n/*** Reject target-selection fields that are never part of the broker's public request contract. */\nfunction hasCallerSuppliedTarget(request: TrustedExternalApiBrokerRequest): boolean {\n return ['url', 'host', 'baseUrl', 'upstreamUrl', 'target'].some((key) =>\n Object.hasOwn(request, key),\n );\n}\n\n/*** Treat a missing, throwing, or false authorization decision as a denial. */\nasync function isAuthorizedAsync<TResolvedOperation extends TrustedExternalApiOperation>(\n options: CreateTrustedExternalApiBrokerOptions<TResolvedOperation>,\n context: TrustedExternalApiBrokerContext,\n request: TrustedExternalApiBrokerRequest,\n): Promise<boolean> {\n try {\n return await options.authorizeAsync({ context, request });\n } catch {\n return false;\n }\n}\n\n/*** Resolve only the exact operation whose server-side identity matches the caller request. */\nasync function resolveOperationAsync<TResolvedOperation extends TrustedExternalApiOperation>(\n options: CreateTrustedExternalApiBrokerOptions<TResolvedOperation>,\n context: TrustedExternalApiBrokerContext,\n request: TrustedExternalApiBrokerRequest,\n): Promise<TResolvedOperation | undefined> {\n try {\n const operation = await options.resolveOperationAsync({\n scope: context.scope,\n request,\n });\n return operation !== undefined && operationMatchesRequest(operation, request)\n ? operation\n : undefined;\n } catch {\n return undefined;\n }\n}\n\n/*** Prevent a resolver from substituting another declared API, endpoint, or operation. */\nfunction operationMatchesRequest(\n operation: TrustedExternalApiOperation,\n request: TrustedExternalApiBrokerRequest,\n): boolean {\n return (\n operation.apiId === request.apiId &&\n operation.endpointId === request.endpointId &&\n operation.operationId === request.operationId\n );\n}\n\n/*** Return a result contract that never exposes credential headers or provider diagnostics. */\nfunction publicResponse(status: number, publicBody: unknown): ApiResponse {\n return {\n status: Number.isInteger(status) && status >= 100 && status <= 599 ? status : 502,\n headers: {},\n ...(publicBody === undefined ? {} : { body: publicBody }),\n };\n}\n\n/*** Produce a stable caller-visible error without leaking upstream configuration or exception text. */\nfunction brokerErrorResponse(status: number, code: string): ApiResponse {\n return {\n status,\n headers: { 'content-type': 'application/json' },\n body: { error: { code } },\n };\n}\n\n/*** Identify one non-blank trusted scope segment. */\nfunction isNonEmpty(value: string): boolean {\n return value.trim().length > 0;\n}\n"]}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { TrustedExternalApiOperation } from '../../types/api.js';
|
|
2
|
+
import type { CreateWorkerTrustedApiHandlerOptions } from '../../types/worker.js';
|
|
3
|
+
/*** Create a Fetch-standard trusted API handler with mandatory durable request admission. */
|
|
4
|
+
export declare function createWorkerTrustedApiHandler<TResolvedOperation extends TrustedExternalApiOperation>(options: CreateWorkerTrustedApiHandlerOptions<TResolvedOperation>): (request: Request) => Promise<Response>;
|
|
5
|
+
//# sourceMappingURL=createWorkerTrustedApiHandler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createWorkerTrustedApiHandler.d.ts","sourceRoot":"","sources":["../../../src/features/execution/createWorkerTrustedApiHandler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAe,2BAA2B,EAAE,MAAM,oBAAoB,CAAC;AACnF,OAAO,KAAK,EAAE,oCAAoC,EAAE,MAAM,uBAAuB,CAAC;AAIlF,6FAA6F;AAC7F,wBAAgB,6BAA6B,CAC3C,kBAAkB,SAAS,2BAA2B,EAEtD,OAAO,EAAE,oCAAoC,CAAC,kBAAkB,CAAC,GAChE,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC,QAAQ,CAAC,CAqBzC"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { createTrustedExternalApiBroker } from './createTrustedExternalApiBroker.js';
|
|
2
|
+
import { readWorkerBrokerRequestAsync } from './readWorkerBrokerRequestAsync.js';
|
|
3
|
+
/*** Create a Fetch-standard trusted API handler with mandatory durable request admission. */
|
|
4
|
+
export function createWorkerTrustedApiHandler(options) {
|
|
5
|
+
const broker = createTrustedExternalApiBroker(options.broker);
|
|
6
|
+
return async (request) => {
|
|
7
|
+
if (options.broker.requestBudget === undefined) {
|
|
8
|
+
return errorResponse(503, 'external_request_budget_unavailable');
|
|
9
|
+
}
|
|
10
|
+
if (request.method !== 'POST')
|
|
11
|
+
return errorResponse(405, 'method_not_allowed');
|
|
12
|
+
try {
|
|
13
|
+
const caller = await options.authenticateCallerAsync(request);
|
|
14
|
+
if (caller === undefined || caller === null)
|
|
15
|
+
return errorResponse(401, 'unauthorized');
|
|
16
|
+
const input = await readWorkerBrokerRequestAsync(request);
|
|
17
|
+
if (input === undefined)
|
|
18
|
+
return errorResponse(400, 'invalid_request');
|
|
19
|
+
const result = await broker.executeAsync({
|
|
20
|
+
context: { caller, scope: options.scope },
|
|
21
|
+
request: input,
|
|
22
|
+
});
|
|
23
|
+
return toResponse(result);
|
|
24
|
+
}
|
|
25
|
+
catch {
|
|
26
|
+
return errorResponse(502, 'external_operation_failed');
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
/*** Translate the public broker result without exposing exception or provider details. */
|
|
31
|
+
function toResponse(result) {
|
|
32
|
+
if (result.status < 200 || result.status > 599) {
|
|
33
|
+
return errorResponse(502, 'external_operation_failed');
|
|
34
|
+
}
|
|
35
|
+
const bodyForbidden = [204, 205, 304].includes(result.status);
|
|
36
|
+
return new Response(bodyForbidden || result.body === undefined ? null : JSON.stringify(result.body), {
|
|
37
|
+
status: result.status,
|
|
38
|
+
headers: {
|
|
39
|
+
...result.headers,
|
|
40
|
+
'content-type': 'application/json',
|
|
41
|
+
'cache-control': 'no-store',
|
|
42
|
+
},
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
/*** Produce a caller-safe Fetch error response. */
|
|
46
|
+
function errorResponse(status, code) {
|
|
47
|
+
return Response.json({ error: { code } }, { status, headers: { 'cache-control': 'no-store' } });
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=createWorkerTrustedApiHandler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createWorkerTrustedApiHandler.js","sourceRoot":"","sources":["../../../src/features/execution/createWorkerTrustedApiHandler.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,8BAA8B,EAAE,MAAM,qCAAqC,CAAC;AACrF,OAAO,EAAE,4BAA4B,EAAE,MAAM,mCAAmC,CAAC;AAEjF,6FAA6F;AAC7F,MAAM,UAAU,6BAA6B,CAG3C,OAAiE;IAEjE,MAAM,MAAM,GAAG,8BAA8B,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;IAC9D,OAAO,KAAK,EAAE,OAAO,EAAE,EAAE;QACvB,IAAI,OAAO,CAAC,MAAM,CAAC,aAAa,KAAK,SAAS,EAAE,CAAC;YAC/C,OAAO,aAAa,CAAC,GAAG,EAAE,qCAAqC,CAAC,CAAC;QACnE,CAAC;QACD,IAAI,OAAO,CAAC,MAAM,KAAK,MAAM;YAAE,OAAO,aAAa,CAAC,GAAG,EAAE,oBAAoB,CAAC,CAAC;QAC/E,IAAI,CAAC;YACH,MAAM,MAAM,GAAG,MAAM,OAAO,CAAC,uBAAuB,CAAC,OAAO,CAAC,CAAC;YAC9D,IAAI,MAAM,KAAK,SAAS,IAAI,MAAM,KAAK,IAAI;gBAAE,OAAO,aAAa,CAAC,GAAG,EAAE,cAAc,CAAC,CAAC;YACvF,MAAM,KAAK,GAAG,MAAM,4BAA4B,CAAC,OAAO,CAAC,CAAC;YAC1D,IAAI,KAAK,KAAK,SAAS;gBAAE,OAAO,aAAa,CAAC,GAAG,EAAE,iBAAiB,CAAC,CAAC;YACtE,MAAM,MAA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se, TrustedExternalApiOperation } from '../../types/api.js';\nimport type { CreateWorkerTrustedApiHandlerOptions } from '../../types/worker.js';\nimport { createTrustedExternalApiBroker } from './createTrustedExternalApiBroker.js';\nimport { readWorkerBrokerRequestAsync } from './readWorkerBrokerRequestAsync.js';\n\n/*** Create a Fetch-standard trusted API handler with mandatory durable request admission. */\nexport function createWorkerTrustedApiHandler<\n TResolvedOperation extends TrustedExternalApiOperation,\n>(\n options: CreateWorkerTrustedApiHandlerOptions<TResolvedOperation>,\n): (request: Request) => Promise<Response> {\n const broker = createTrustedExternalApiBroker(options.broker);\n return async (request) => {\n if (options.broker.requestBudget === undefined) {\n return errorResponse(503, 'external_request_budget_unavailable');\n }\n if (request.method !== 'POST') return errorResponse(405, 'method_not_allowed');\n try {\n const caller = await options.authenticateCallerAsync(request);\n if (caller === undefined || caller === null) return errorResponse(401, 'unauthorized');\n const input = await readWorkerBrokerRequestAsync(request);\n if (input === undefined) return errorResponse(400, 'invalid_request');\n const result = await broker.executeAsync({\n context: { caller, scope: options.scope },\n request: input,\n });\n return toResponse(result);\n } catch {\n return errorResponse(502, 'external_operation_failed');\n }\n };\n}\n\n/*** Translate the public broker result without exposing exception or provider details. */\nfunction toResponse(result: ApiResponse): Response {\n if (result.status < 200 || result.status > 599) {\n return errorResponse(502, 'external_operation_failed');\n }\n const bodyForbidden = [204, 205, 304].includes(result.status);\n return new Response(\n bodyForbidden || result.body === undefined ? null : JSON.stringify(result.body),\n {\n status: result.status,\n headers: {\n ...result.headers,\n 'content-type': 'application/json',\n 'cache-control': 'no-store',\n },\n },\n );\n}\n\n/*** Produce a caller-safe Fetch error response. */\nfunction errorResponse(status: number, code: string): Response {\n return Response.json({ error: { code } }, { status, headers: { 'cache-control': 'no-store' } });\n}\n"]}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { TrustedExternalApiBrokerRequest } from '../../types/api.js';
|
|
2
|
+
/*** Read only canonical operation identity and bounded JSON input from the Fetch request. */
|
|
3
|
+
export declare function readWorkerBrokerRequestAsync(request: Request): Promise<TrustedExternalApiBrokerRequest | undefined>;
|
|
4
|
+
//# sourceMappingURL=readWorkerBrokerRequestAsync.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"readWorkerBrokerRequestAsync.d.ts","sourceRoot":"","sources":["../../../src/features/execution/readWorkerBrokerRequestAsync.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,+BAA+B,EAAE,MAAM,oBAAoB,CAAC;AAI1E,6FAA6F;AAC7F,wBAAsB,4BAA4B,CAChD,OAAO,EAAE,OAAO,GACf,OAAO,CAAC,+BAA+B,GAAG,SAAS,CAAC,CAuBtD"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
const BODY_LIMIT = 1_048_576;
|
|
2
|
+
/*** Read only canonical operation identity and bounded JSON input from the Fetch request. */
|
|
3
|
+
export async function readWorkerBrokerRequestAsync(request) {
|
|
4
|
+
try {
|
|
5
|
+
const match = /^\/api\/runtime\/external\/([^/]+)\/([^/]+)\/([^/]+)$/.exec(new URL(request.url).pathname);
|
|
6
|
+
if (!match?.[1] || !match[2] || !match[3])
|
|
7
|
+
return undefined;
|
|
8
|
+
const apiId = decodeURIComponent(match[1]);
|
|
9
|
+
const endpointId = decodeURIComponent(match[2]);
|
|
10
|
+
const operationId = decodeURIComponent(match[3]);
|
|
11
|
+
if ([apiId, endpointId, operationId].some((id) => !id.trim() || id.includes('/'))) {
|
|
12
|
+
return undefined;
|
|
13
|
+
}
|
|
14
|
+
const body = await readBoundedBodyAsync(request);
|
|
15
|
+
if (body === undefined || !isInputBody(body))
|
|
16
|
+
return undefined;
|
|
17
|
+
return {
|
|
18
|
+
apiId,
|
|
19
|
+
endpointId,
|
|
20
|
+
operationId,
|
|
21
|
+
...(body.input === undefined ? {} : { input: body.input }),
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
catch {
|
|
25
|
+
return undefined;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
/*** Limit actual streamed bytes independently of caller-controlled Content-Length. */
|
|
29
|
+
async function readBoundedBodyAsync(request) {
|
|
30
|
+
if (request.body === null)
|
|
31
|
+
return {};
|
|
32
|
+
const reader = request.body.getReader();
|
|
33
|
+
const decoder = new TextDecoder('utf-8', { fatal: true });
|
|
34
|
+
const chunks = [];
|
|
35
|
+
// Stream consumption owns the mutable byte counter and buffer.
|
|
36
|
+
let size = 0;
|
|
37
|
+
try {
|
|
38
|
+
for (;;) {
|
|
39
|
+
const chunk = await reader.read();
|
|
40
|
+
if (chunk.done)
|
|
41
|
+
break;
|
|
42
|
+
size += chunk.value.byteLength;
|
|
43
|
+
if (size > BODY_LIMIT) {
|
|
44
|
+
await reader.cancel();
|
|
45
|
+
return undefined;
|
|
46
|
+
}
|
|
47
|
+
chunks.push(decoder.decode(chunk.value, { stream: true }));
|
|
48
|
+
}
|
|
49
|
+
chunks.push(decoder.decode());
|
|
50
|
+
const body = JSON.parse(chunks.join(''));
|
|
51
|
+
return body;
|
|
52
|
+
}
|
|
53
|
+
finally {
|
|
54
|
+
reader.releaseLock();
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
/*** Reject any caller-controlled fields other than input. */
|
|
58
|
+
function isInputBody(value) {
|
|
59
|
+
return (typeof value === 'object' &&
|
|
60
|
+
value !== null &&
|
|
61
|
+
!Array.isArray(value) &&
|
|
62
|
+
Object.keys(value).every((key) => key === 'input'));
|
|
63
|
+
}
|
|
64
|
+
//# sourceMappingURL=readWorkerBrokerRequestAsync.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"readWorkerBrokerRequestAsync.js","sourceRoot":"","sources":["../../../src/features/execution/readWorkerBrokerRequestAsync.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,GAAG,SAAS,CAAC;AAE7B,6FAA6F;AAC7F,MAAM,CAAC,KAAK,UAAU,4BAA4B,CAChD,OAAgB;IAEhB,IAAI,CAAC;QACH,MAAM,KAAK,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AAG,KAAK,OAAO,CAAC,CACnD,CAAC;AACJ,CAAC","sourcesContent":["import type { TrustedExternalApiBrokerRequest } from '../../types/api.js';\n\nconst BODY_LIMIT = 1_048_576;\n\n/*** Read only canonical operation identity and bounded JSON input from the Fetch request. */\nexport async function readWorkerBrokerRequestAsync(\n request: Request,\n): Promise<TrustedExternalApiBrokerRequest | undefined> {\n try {\n const match = /^\\/api\\/runtime\\/external\\/([^/]+)\\/([^/]+)\\/([^/]+)$/.exec(\n new URL(request.url).pathname,\n );\n if (!match?.[1] || !match[2] || !match[3]) return undefined;\n const apiId = decodeURIComponent(match[1]);\n const endpointId = decodeURIComponent(match[2]);\n const operationId = decodeURIComponent(match[3]);\n if ([apiId, endpointId, operationId].some((id) => !id.trim() || id.includes('/'))) {\n return undefined;\n }\n const body = await readBoundedBodyAsync(request);\n if (body === undefined || !isInputBody(body)) return undefined;\n return {\n apiId,\n endpointId,\n operationId,\n ...(body.input === undefined ? {} : { input: body.input }),\n };\n } catch {\n return undefined;\n }\n}\n\n/*** Limit actual streamed bytes independently of caller-controlled Content-Length. */\nasync function readBoundedBodyAsync(request: Request): Promise<unknown> {\n if (request.body === null) return {};\n const reader = request.body.getReader();\n const decoder = new TextDecoder('utf-8', { fatal: true });\n const chunks: string[] = [];\n // Stream consumption owns the mutable byte counter and buffer.\n let size = 0;\n try {\n for (;;) {\n const chunk = await reader.read();\n if (chunk.done) break;\n size += chunk.value.byteLength;\n if (size > BODY_LIMIT) {\n await reader.cancel();\n return undefined;\n }\n chunks.push(decoder.decode(chunk.value, { stream: true }));\n }\n chunks.push(decoder.decode());\n const body: unknown = JSON.parse(chunks.join(''));\n return body;\n } finally {\n reader.releaseLock();\n }\n}\n\n/*** Reject any caller-controlled fields other than input. */\nfunction isInputBody(value: unknown): value is { readonly input?: unknown } {\n return (\n typeof value === 'object' &&\n value !== null &&\n !Array.isArray(value) &&\n Object.keys(value).every((key) => key === 'input')\n );\n}\n"]}
|
package/dist/types/api.d.ts
CHANGED
|
@@ -117,7 +117,20 @@ export interface TrustedExternalApiBroker {
|
|
|
117
117
|
readonly request: TrustedExternalApiBrokerRequest;
|
|
118
118
|
}): Promise<ApiResponse>;
|
|
119
119
|
}
|
|
120
|
+
/*** A durable reservation covers one execution; releasing it never refunds the attempt. */
|
|
121
|
+
export interface PersistentExternalRequestReservation {
|
|
122
|
+
readonly signal: AbortSignal;
|
|
123
|
+
releaseAsync(): Promise<void>;
|
|
124
|
+
}
|
|
125
|
+
/*** Host-owned durable admission shared across callers, processes and runtime isolates. */
|
|
126
|
+
export interface PersistentExternalRequestBudgetPort {
|
|
127
|
+
reserveAsync(input: {
|
|
128
|
+
readonly scope: TrustedExternalApiBrokerContext['scope'];
|
|
129
|
+
readonly operation: TrustedExternalApiOperation;
|
|
130
|
+
}): Promise<PersistentExternalRequestReservation | undefined>;
|
|
131
|
+
}
|
|
120
132
|
export interface CreateTrustedExternalApiBrokerOptions<TResolvedOperation extends TrustedExternalApiOperation = TrustedExternalApiOperation> {
|
|
133
|
+
readonly requestBudget?: PersistentExternalRequestBudgetPort;
|
|
121
134
|
readonly authorizeAsync: (input: {
|
|
122
135
|
readonly context: TrustedExternalApiBrokerContext;
|
|
123
136
|
readonly request: TrustedExternalApiBrokerRequest;
|
|
@@ -139,6 +152,7 @@ export interface CreateTrustedExternalApiBrokerOptions<TResolvedOperation extend
|
|
|
139
152
|
readonly operation: TResolvedOperation;
|
|
140
153
|
readonly input: unknown;
|
|
141
154
|
readonly credentials?: TrustedExternalApiCredentials;
|
|
155
|
+
readonly signal?: AbortSignal;
|
|
142
156
|
}) => TrustedExternalApiExecutionResult | Promise<TrustedExternalApiExecutionResult>;
|
|
143
157
|
}
|
|
144
158
|
//# sourceMappingURL=api.d.ts.map
|
package/dist/types/api.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../src/types/api.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAA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AQ,CAAC,MAAM,EAAE,+BAA+B,CAAC,QAAQ,CAAC,CAAC;QAC3D,QAAQ,CAAC,KAAK,EAAE,+BAA+B,CAAC,OAAO,CAAC,CAAC;QACzD,QAAQ,CAAC,SAAS,EAAE,kBAAkB,CAAC;KACxC,KACC,6BAA6B,GAAG,SAAS,GAAG,OAAO,CAAC,6BAA6B,GAAG,SAAS,CAAC,CAAC;IACjG,QAAQ,CAAC,qBAAqB,EAAE,CAAC,KAAK,EAAE;QACtC,QAAQ,CAAC,SAAS,EAAE,kBAAkB,CAAC;QACvC,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;QACxB,QAAQ,CAAC,WAAW,CAAC,EAAE,6BAA6B,CAAC;QACrD,QAAQ,CAAC,MAAM,CAAC,EAAE,WAAW,CAAC;KAC/B,KAAK,iCAAiC,GAAG,OAAO,CAAC,iCAAiC,CAAC,CAAC;CACtF"}
|
package/dist/types/api.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.js","sourceRoot":"","sources":["../../src/types/api.ts"],"names":[],"mappings":"","sourcesContent":["import type { Capability } from '@ankhorage/contracts/capability';\nimport type {\n DataEndpointConfig,\n DataOperationConfig,\n DataOperationIntent,\n DataOperationMethod,\n InternalApiOperationHandlerDeclaration,\n InternalRestApiDefinition,\n} from '@ankhorage/contracts/data';\n\nexport interface ApiOperationBinding {\n readonly definition: InternalRestApiDefinition;\n readonly endpoint: DataEndpointConfig;\n readonly operation: DataOperationConfig;\n readonly operationId: string;\n readonly method: DataOperationMethod;\n readonly path: string;\n}\n\nexport interface ApiRequest {\n readonly operationId: string;\n readonly method: DataOperationMethod;\n readonly params: Readonly<Record<string, string>>;\n readonly query: Readonly<Record<string, string | readonly string[]>>;\n readonly headers: Readonly<Record<string, string>>;\n readonly body?: unknown;\n}\n\nexport interface ApiHandlerResponse {\n readonly status?: number;\n readonly headers?: Readonly<Record<string, string>>;\n readonly body?: unknown;\n}\n\nexport interface ApiResponse {\n readonly status: number;\n readonly headers: Readonly<Record<string, string>>;\n readonly body?: unknown;\n}\n\nexport interface ApiHandlerContext {\n readonly binding: ApiOperationBinding;\n readonly composition?: ApiCompositionContext;\n readonly capability?: Capability;\n}\n\nexport type ApiHandler = (\n request: ApiRequest,\n context: ApiHandlerContext,\n) => ApiHandlerResponse | Promise<ApiHandlerResponse>;\n\nexport type ApiHandlerRegistry = Readonly<Record<string, ApiHandler>>;\n\nexport interface ApiCompositionContext {\n readonly appId: string;\n readonly projectId: string;\n}\n\nexport interface ApiHandlerResolutionRequest {\n readonly binding: ApiOperationBinding;\n readonly declaration: InternalApiOperationHandlerDeclaration;\n readonly context: ApiCompositionContext;\n}\n\nexport interface ApiApprovedHandler {\n readonly capability: Capability;\n readonly approval: ApiHandlerApproval;\n readonly handler: ApiHandler;\n}\n\n/*** Bind one host-approved owner handler to its exact API operation and application scope. */\nexport interface ApiHandlerApproval {\n readonly operationId: string;\n readonly intent: DataOperationIntent;\n readonly method: DataOperationMethod;\n readonly capabilityId: Capability['id'];\n readonly owner: string;\n readonly scope: ApiCompositionContext;\n}\n\nexport type ApiHandlerResolver = (\n request: ApiHandlerResolutionRequest,\n) => ApiApprovedHandler | undefined;\n\nexport interface ApiAuthorizationRequest {\n readonly binding: ApiOperationBinding;\n readonly context: ApiCompositionContext;\n readonly request: ApiRequest;\n}\n\nexport type ApiAuthorizationPolicy = (\n request: ApiAuthorizationRequest,\n) => boolean | Promise<boolean>;\n\nexport interface ComposeAuthorizedApiRuntimeOptions {\n readonly definition: InternalRestApiDefinition;\n readonly context: ApiCompositionContext;\n readonly resolveHandler: ApiHandlerResolver;\n readonly authorizeAsync: ApiAuthorizationPolicy;\n}\n\nexport interface ApiRuntime {\n readonly definition: InternalRestApiDefinition;\n readonly bindings: readonly ApiOperationBinding[];\n dispatchAsync(request: ApiRequest): Promise<ApiResponse>;\n getBinding(operationId: string): ApiOperationBinding | undefined;\n}\n\nexport interface ApiTransportAdapter<TRequest, TResponse> {\n toApiRequestAsync(request: TRequest, binding: ApiOperationBinding): Promise<ApiRequest>;\n fromApiResponseAsync(\n response: ApiResponse,\n request: TRequest,\n binding: ApiOperationBinding,\n ): Promise<TResponse>;\n}\n\n/*** Describe the authenticated host context that scopes one generated-app broker request. */\nexport interface TrustedExternalApiBrokerContext {\n readonly caller: unknown;\n readonly scope: {\n readonly appId: string;\n readonly projectId: string;\n readonly environment: string;\n };\n}\n\n/*** Describe the only client-controlled values accepted by the trusted external API broker. */\nexport interface TrustedExternalApiBrokerRequest {\n readonly apiId: string;\n readonly endpointId: string;\n readonly operationId: string;\n readonly input?: unknown;\n}\n\n/*** Describe an operation resolved exclusively from trusted server-side application state. */\nexport interface TrustedExternalApiOperation {\n readonly apiId: string;\n readonly endpointId: string;\n readonly operationId: string;\n readonly credentialsRequired?: boolean;\n}\n\n/*** Describe server-only credentials resolved for a trusted external API operation. */\nexport interface TrustedExternalApiCredentials {\n readonly values: Readonly<Record<string, string>>;\n}\n\n/*** Describe the caller-safe result returned after trusted operation execution. */\nexport interface TrustedExternalApiExecutionResult {\n readonly status: number;\n readonly publicBody?: unknown;\n}\n\nexport interface TrustedExternalApiBroker {\n executeAsync(input: {\n readonly context: TrustedExternalApiBrokerContext;\n readonly request: TrustedExternalApiBrokerRequest;\n }): Promise<ApiResponse>;\n}\n\nexport interface CreateTrustedExternalApiBrokerOptions<\n TResolvedOperation extends TrustedExternalApiOperation = TrustedExternalApiOperation,\n> {\n readonly authorizeAsync: (input: {\n readonly context: TrustedExternalApiBrokerContext;\n readonly request: TrustedExternalApiBrokerRequest;\n }) => boolean | Promise<boolean>;\n readonly resolveOperationAsync: (input: {\n readonly scope: TrustedExternalApiBrokerContext['scope'];\n readonly request: TrustedExternalApiBrokerRequest;\n }) => TResolvedOperation | undefined | Promise<TResolvedOperation | undefined>;\n readonly validateInputAsync: (input: {\n readonly operation: TResolvedOperation;\n readonly input: unknown;\n }) => unknown;\n readonly resolveCredentialsAsync: (input: {\n readonly caller: TrustedExternalApiBrokerContext['caller'];\n readonly scope: TrustedExternalApiBrokerContext['scope'];\n readonly operation: TResolvedOperation;\n }) =>\n TrustedExternalApiCredentials | undefined | Promise<TrustedExternalApiCredentials | undefined>;\n readonly executeOperationAsync: (input: {\n readonly operation: TResolvedOperation;\n readonly input: unknown;\n readonly credentials?: TrustedExternalApiCredentials;\n }) => TrustedExternalApiExecutionResult | Promise<TrustedExternalApiExecutionResult>;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"api.js","sourceRoot":"","sources":["../../src/types/api.ts"],"names":[],"mappings":"","sourcesContent":["import type { Capability } from '@ankhorage/contracts/capability';\nimport type {\n DataEndpointConfig,\n DataOperationConfig,\n DataOperationIntent,\n DataOperationMethod,\n InternalApiOperationHandlerDeclaration,\n InternalRestApiDefinition,\n} from '@ankhorage/contracts/data';\n\nexport interface ApiOperationBinding {\n readonly definition: InternalRestApiDefinition;\n readonly endpoint: DataEndpointConfig;\n readonly operation: DataOperationConfig;\n readonly operationId: string;\n readonly method: DataOperationMethod;\n readonly path: string;\n}\n\nexport interface ApiRequest {\n readonly operationId: string;\n readonly method: DataOperationMethod;\n readonly params: Readonly<Record<string, string>>;\n readonly query: Readonly<Record<string, string | readonly string[]>>;\n readonly headers: Readonly<Record<string, string>>;\n readonly body?: unknown;\n}\n\nexport interface ApiHandlerResponse {\n readonly status?: number;\n readonly headers?: Readonly<Record<string, string>>;\n readonly body?: unknown;\n}\n\nexport interface ApiResponse {\n readonly status: number;\n readonly headers: Readonly<Record<string, string>>;\n readonly body?: unknown;\n}\n\nexport interface ApiHandlerContext {\n readonly binding: ApiOperationBinding;\n readonly composition?: ApiCompositionContext;\n readonly capability?: Capability;\n}\n\nexport type ApiHandler = (\n request: ApiRequest,\n context: ApiHandlerContext,\n) => ApiHandlerResponse | Promise<ApiHandlerResponse>;\n\nexport type ApiHandlerRegistry = Readonly<Record<string, ApiHandler>>;\n\nexport interface ApiCompositionContext {\n readonly appId: string;\n readonly projectId: string;\n}\n\nexport interface ApiHandlerResolutionRequest {\n readonly binding: ApiOperationBinding;\n readonly declaration: InternalApiOperationHandlerDeclaration;\n readonly context: ApiCompositionContext;\n}\n\nexport interface ApiApprovedHandler {\n readonly capability: Capability;\n readonly approval: ApiHandlerApproval;\n readonly handler: ApiHandler;\n}\n\n/*** Bind one host-approved owner handler to its exact API operation and application scope. */\nexport interface ApiHandlerApproval {\n readonly operationId: string;\n readonly intent: DataOperationIntent;\n readonly method: DataOperationMethod;\n readonly capabilityId: Capability['id'];\n readonly owner: string;\n readonly scope: ApiCompositionContext;\n}\n\nexport type ApiHandlerResolver = (\n request: ApiHandlerResolutionRequest,\n) => ApiApprovedHandler | undefined;\n\nexport interface ApiAuthorizationRequest {\n readonly binding: ApiOperationBinding;\n readonly context: ApiCompositionContext;\n readonly request: ApiRequest;\n}\n\nexport type ApiAuthorizationPolicy = (\n request: ApiAuthorizationRequest,\n) => boolean | Promise<boolean>;\n\nexport interface ComposeAuthorizedApiRuntimeOptions {\n readonly definition: InternalRestApiDefinition;\n readonly context: ApiCompositionContext;\n readonly resolveHandler: ApiHandlerResolver;\n readonly authorizeAsync: ApiAuthorizationPolicy;\n}\n\nexport interface ApiRuntime {\n readonly definition: InternalRestApiDefinition;\n readonly bindings: readonly ApiOperationBinding[];\n dispatchAsync(request: ApiRequest): Promise<ApiResponse>;\n getBinding(operationId: string): ApiOperationBinding | undefined;\n}\n\nexport interface ApiTransportAdapter<TRequest, TResponse> {\n toApiRequestAsync(request: TRequest, binding: ApiOperationBinding): Promise<ApiRequest>;\n fromApiResponseAsync(\n response: ApiResponse,\n request: TRequest,\n binding: ApiOperationBinding,\n ): Promise<TResponse>;\n}\n\n/*** Describe the authenticated host context that scopes one generated-app broker request. */\nexport interface TrustedExternalApiBrokerContext {\n readonly caller: unknown;\n readonly scope: {\n readonly appId: string;\n readonly projectId: string;\n readonly environment: string;\n };\n}\n\n/*** Describe the only client-controlled values accepted by the trusted external API broker. */\nexport interface TrustedExternalApiBrokerRequest {\n readonly apiId: string;\n readonly endpointId: string;\n readonly operationId: string;\n readonly input?: unknown;\n}\n\n/*** Describe an operation resolved exclusively from trusted server-side application state. */\nexport interface TrustedExternalApiOperation {\n readonly apiId: string;\n readonly endpointId: string;\n readonly operationId: string;\n readonly credentialsRequired?: boolean;\n}\n\n/*** Describe server-only credentials resolved for a trusted external API operation. */\nexport interface TrustedExternalApiCredentials {\n readonly values: Readonly<Record<string, string>>;\n}\n\n/*** Describe the caller-safe result returned after trusted operation execution. */\nexport interface TrustedExternalApiExecutionResult {\n readonly status: number;\n readonly publicBody?: unknown;\n}\n\nexport interface TrustedExternalApiBroker {\n executeAsync(input: {\n readonly context: TrustedExternalApiBrokerContext;\n readonly request: TrustedExternalApiBrokerRequest;\n }): Promise<ApiResponse>;\n}\n\n/*** A durable reservation covers one execution; releasing it never refunds the attempt. */\nexport interface PersistentExternalRequestReservation {\n readonly signal: AbortSignal;\n releaseAsync(): Promise<void>;\n}\n\n/*** Host-owned durable admission shared across callers, processes and runtime isolates. */\nexport interface PersistentExternalRequestBudgetPort {\n reserveAsync(input: {\n readonly scope: TrustedExternalApiBrokerContext['scope'];\n readonly operation: TrustedExternalApiOperation;\n }): Promise<PersistentExternalRequestReservation | undefined>;\n}\n\nexport interface CreateTrustedExternalApiBrokerOptions<\n TResolvedOperation extends TrustedExternalApiOperation = TrustedExternalApiOperation,\n> {\n readonly requestBudget?: PersistentExternalRequestBudgetPort;\n readonly authorizeAsync: (input: {\n readonly context: TrustedExternalApiBrokerContext;\n readonly request: TrustedExternalApiBrokerRequest;\n }) => boolean | Promise<boolean>;\n readonly resolveOperationAsync: (input: {\n readonly scope: TrustedExternalApiBrokerContext['scope'];\n readonly request: TrustedExternalApiBrokerRequest;\n }) => TResolvedOperation | undefined | Promise<TResolvedOperation | undefined>;\n readonly validateInputAsync: (input: {\n readonly operation: TResolvedOperation;\n readonly input: unknown;\n }) => unknown;\n readonly resolveCredentialsAsync: (input: {\n readonly caller: TrustedExternalApiBrokerContext['caller'];\n readonly scope: TrustedExternalApiBrokerContext['scope'];\n readonly operation: TResolvedOperation;\n }) =>\n TrustedExternalApiCredentials | undefined | Promise<TrustedExternalApiCredentials | undefined>;\n readonly executeOperationAsync: (input: {\n readonly operation: TResolvedOperation;\n readonly input: unknown;\n readonly credentials?: TrustedExternalApiCredentials;\n readonly signal?: AbortSignal;\n }) => TrustedExternalApiExecutionResult | Promise<TrustedExternalApiExecutionResult>;\n}\n"]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { CreateTrustedExternalApiBrokerOptions, TrustedExternalApiBrokerContext, TrustedExternalApiOperation } from './api.js';
|
|
2
|
+
export interface CreateWorkerTrustedApiHandlerOptions<TResolvedOperation extends TrustedExternalApiOperation = TrustedExternalApiOperation> {
|
|
3
|
+
readonly scope: TrustedExternalApiBrokerContext['scope'];
|
|
4
|
+
/** The trusted host verifies the session, not a caller-provided identity. */
|
|
5
|
+
readonly authenticateCallerAsync: (request: Request) => Promise<unknown>;
|
|
6
|
+
/** A persistent request budget is mandatory for this serverless transport. */
|
|
7
|
+
readonly broker: CreateTrustedExternalApiBrokerOptions<TResolvedOperation>;
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=worker.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"worker.d.ts","sourceRoot":"","sources":["../../src/types/worker.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,qCAAqC,EACrC,+BAA+B,EAC/B,2BAA2B,EAC5B,MAAM,UAAU,CAAC;AAElB,MAAM,WAAW,oCAAoC,CACnD,kBAAkB,SAAS,2BAA2B,GAAG,2BAA2B;IAEpF,QAAQ,CAAC,KAAK,EAAE,+BAA+B,CAAC,OAAO,CAAC,CAAC;IACzD,6EAA6E;IAC7E,QAAQ,CAAC,uBAAuB,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;IACzE,8EAA8E;IAC9E,QAAQ,CAAC,MAAM,EAAE,qCAAqC,CAAC,kBAAkB,CAAC,CAAC;CAC5E"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"worker.js","sourceRoot":"","sources":["../../src/types/worker.ts"],"names":[],"mappings":"","sourcesContent":["import type {\n CreateTrustedExternalApiBrokerOptions,\n TrustedExternalApiBrokerContext,\n TrustedExternalApiOperation,\n} from './api.js';\n\nexport interface CreateWorkerTrustedApiHandlerOptions<\n TResolvedOperation extends TrustedExternalApiOperation = TrustedExternalApiOperation,\n> {\n readonly scope: TrustedExternalApiBrokerContext['scope'];\n /** The trusted host verifies the session, not a caller-provided identity. */\n readonly authenticateCallerAsync: (request: Request) => Promise<unknown>;\n /** A persistent request budget is mandatory for this serverless transport. */\n readonly broker: CreateTrustedExternalApiBrokerOptions<TResolvedOperation>;\n}\n"]}
|