@ankhorage/api 0.6.1 → 0.7.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 CHANGED
@@ -1,5 +1,11 @@
1
1
  # @ankhorage/api
2
2
 
3
+ ## 0.7.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 4e6596d: Preserve server-resolved trusted external API operation context through broker validation, credential resolution, and execution.
8
+
3
9
  ## 0.6.1
4
10
 
5
11
  ### Patch Changes
package/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
 
4
4
  # @ankhorage/api
5
5
 
6
- ![license: MIT](././paradox/badges/license.svg) ![npm: v0.6.1](././paradox/badges/npm.svg) ![runtime: bun](././paradox/badges/runtime.svg) ![typescript: strict](././paradox/badges/typescript.svg) ![eslint: checked](././paradox/badges/eslint.svg) ![prettier: checked](././paradox/badges/prettier.svg) ![build: checked](././paradox/badges/build.svg) ![tests: configured](././paradox/badges/tests.svg) ![paradox: canonical](././paradox/badges/docs.svg)
6
+ ![license: MIT](././paradox/badges/license.svg) ![npm: v0.7.0](././paradox/badges/npm.svg) ![runtime: bun](././paradox/badges/runtime.svg) ![typescript: strict](././paradox/badges/typescript.svg) ![eslint: checked](././paradox/badges/eslint.svg) ![prettier: checked](././paradox/badges/prettier.svg) ![build: checked](././paradox/badges/build.svg) ![tests: configured](././paradox/badges/tests.svg) ![paradox: canonical](././paradox/badges/docs.svg)
7
7
 
8
8
  Framework-neutral executable API runtime for Ankhorage.
9
9
 
@@ -1,4 +1,4 @@
1
- import type { CreateTrustedExternalApiBrokerOptions, TrustedExternalApiBroker } from '../../types/api.js';
1
+ import type { CreateTrustedExternalApiBrokerOptions, TrustedExternalApiBroker, TrustedExternalApiOperation } from '../../types/api.js';
2
2
  /***
3
3
  * Create a framework-neutral, fail-closed boundary for generated-app external API operations.
4
4
  *
@@ -6,5 +6,5 @@ import type { CreateTrustedExternalApiBrokerOptions, TrustedExternalApiBroker }
6
6
  * credentials, authorization, validation, and caller-safe result projection.
7
7
  * @security createTrustedExternalApiBroker.test.ts#denies before resolving secrets or executing network work
8
8
  */
9
- export declare function createTrustedExternalApiBroker(options: CreateTrustedExternalApiBrokerOptions): TrustedExternalApiBroker;
9
+ export declare function createTrustedExternalApiBroker<TResolvedOperation extends TrustedExternalApiOperation>(options: CreateTrustedExternalApiBrokerOptions<TResolvedOperation>): TrustedExternalApiBroker;
10
10
  //# sourceMappingURL=createTrustedExternalApiBroker.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"createTrustedExternalApiBroker.d.ts","sourceRoot":"","sources":["../../../src/features/execution/createTrustedExternalApiBroker.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,qCAAqC,EACrC,wBAAwB,EAIzB,MAAM,oBAAoB,CAAC;AAE5B;;;;;;GAMG;AACH,wBAAgB,8BAA8B,CAC5C,OAAO,EAAE,qCAAqC,GAC7C,wBAAwB,CAK1B"}
1
+ {"version":3,"file":"createTrustedExternalApiBroker.d.ts","sourceRoot":"","sources":["../../../src/features/execution/createTrustedExternalApiBroker.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,qCAAqC,EACrC,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"}
@@ -1 +1 @@
1
- {"version":3,"file":"createTrustedExternalApiBroker.js","sourceRoot":"","sources":["../../../src/features/execution/createTrustedExternalApiBroker.ts"],"names":[],"mappings":"AASA;;;;;;GAMG;AACH,MAAM,UAAU,8BAA8B,CAC5C,OAA8C;IAE9C,OAAO;QACL,YAAY,EAAE,KAAK,EAAE,EAAE,OAAO,EAAE,OAAO,EAAE,EAAE,EAAE,CAC3C,4BAA4B,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,C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,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 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 options: CreateTrustedExternalApiBrokerOptions,\n): 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(\n options: CreateTrustedExternalApiBrokerOptions,\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(\n options: CreateTrustedExternalApiBrokerOptions,\n context: TrustedExternalApiBrokerContext,\n operation: TrustedExternalApiOperation,\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(\n options: CreateTrustedExternalApiBrokerOptions,\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(\n options: CreateTrustedExternalApiBrokerOptions,\n context: TrustedExternalApiBrokerContext,\n request: TrustedExternalApiBrokerRequest,\n): Promise<TrustedExternalApiOperation | 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":"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,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;QAC1D,OAAO,mBAAmB,CAAC,GAAG,EAAE,WAAW,CAAC,CAAC;IAC/C,CAAC;IAED,MAAM,SAAS,GAAG,MAAM,qBAAqB,CAAC,OAAO,EAAE,OAAO,EAAE,OA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,EACtC,OAAwC;IAExC,OAAO,CACL,SAAS,CAAC,KAAK,KAAK,OAAO,CAAC,KAAK;QACjC,SAAS,CAAC,UAAU,KAAK,OAAO,CAAC,UAAU;QAC3C,SAAS,CAAC,WAAW,KAAK,OAAO,CAAC,WAAW,CAC9C,CAAC;AACJ,CAAC;AAED,+FAA+F;AAC/F,SAAS,cAAc,CAAC,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 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"]}
@@ -117,7 +117,7 @@ export interface TrustedExternalApiBroker {
117
117
  readonly request: TrustedExternalApiBrokerRequest;
118
118
  }): Promise<ApiResponse>;
119
119
  }
120
- export interface CreateTrustedExternalApiBrokerOptions {
120
+ export interface CreateTrustedExternalApiBrokerOptions<TResolvedOperation extends TrustedExternalApiOperation = TrustedExternalApiOperation> {
121
121
  readonly authorizeAsync: (input: {
122
122
  readonly context: TrustedExternalApiBrokerContext;
123
123
  readonly request: TrustedExternalApiBrokerRequest;
@@ -125,18 +125,18 @@ export interface CreateTrustedExternalApiBrokerOptions {
125
125
  readonly resolveOperationAsync: (input: {
126
126
  readonly scope: TrustedExternalApiBrokerContext['scope'];
127
127
  readonly request: TrustedExternalApiBrokerRequest;
128
- }) => TrustedExternalApiOperation | undefined | Promise<TrustedExternalApiOperation | undefined>;
128
+ }) => TResolvedOperation | undefined | Promise<TResolvedOperation | undefined>;
129
129
  readonly validateInputAsync: (input: {
130
- readonly operation: TrustedExternalApiOperation;
130
+ readonly operation: TResolvedOperation;
131
131
  readonly input: unknown;
132
132
  }) => unknown;
133
133
  readonly resolveCredentialsAsync: (input: {
134
134
  readonly caller: TrustedExternalApiBrokerContext['caller'];
135
135
  readonly scope: TrustedExternalApiBrokerContext['scope'];
136
- readonly operation: TrustedExternalApiOperation;
136
+ readonly operation: TResolvedOperation;
137
137
  }) => TrustedExternalApiCredentials | undefined | Promise<TrustedExternalApiCredentials | undefined>;
138
138
  readonly executeOperationAsync: (input: {
139
- readonly operation: TrustedExternalApiOperation;
139
+ readonly operation: TResolvedOperation;
140
140
  readonly input: unknown;
141
141
  readonly credentials?: TrustedExternalApiCredentials;
142
142
  }) => TrustedExternalApiExecutionResult | Promise<TrustedExternalApiExecutionResult>;
@@ -1 +1 @@
1
- {"version":3,"file":"api.d.ts","sourceR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,CAAC,KAAK,EAAE,OAAO,CAAC;QACxB,QAAQ,CAAC,WAAW,CAAC,EAAE,6BAA6B,CAAC;KACtD,KAAK,iCAAiC,GAAG,OAAO,CAAC,iCAAiC,CAAC,CAAC;CACtF"}
@@ -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 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 }) => TrustedExternalApiOperation | undefined | Promise<TrustedExternalApiOperation | undefined>;\n readonly validateInputAsync: (input: {\n readonly operation: TrustedExternalApiOperation;\n readonly input: unknown;\n }) => unknown;\n readonly resolveCredentialsAsync: (input: {\n readonly caller: TrustedExternalApiBrokerContext['caller'];\n readonly scope: TrustedExternalApiBrokerContext['scope'];\n readonly operation: TrustedExternalApiOperation;\n }) =>\n TrustedExternalApiCredentials | undefined | Promise<TrustedExternalApiCredentials | undefined>;\n readonly executeOperationAsync: (input: {\n readonly operation: TrustedExternalApiOperation;\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\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"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ankhorage/api",
3
- "version": "0.6.1",
3
+ "version": "0.7.0",
4
4
  "type": "module",
5
5
  "description": "Framework-neutral executable API runtime and transport contract for Ankhorage.",
6
6
  "ankh": {