@ankhorage/api 0.5.1 → 0.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @ankhorage/api
2
2
 
3
+ ## 0.6.0
4
+
5
+ ### Minor Changes
6
+
7
+ - bf3fe6d: Add a framework-neutral trusted generated-app external API broker with injected authorization, operation resolution, credential resolution, validation, and execution ports.
8
+
9
+ ## 0.5.2
10
+
11
+ ### Patch Changes
12
+
13
+ - 293ef6e: Document the existing empty API capability catalog in package metadata.
14
+
3
15
  ## 0.5.1
4
16
 
5
17
  ### 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.5.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: checked](././paradox/badges/tests.svg) ![paradox: canonical](././paradox/badges/docs.svg)
6
+ ![license: MIT](././paradox/badges/license.svg) ![npm: v0.6.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
 
package/dist/api.d.ts CHANGED
@@ -2,7 +2,8 @@ export { CAPABILITIES } from "./capabilities/index.js";
2
2
  export { composeAuthorizedApiRuntime } from "./features/execution/composeAuthorizedApiRuntime.js";
3
3
  export { createApiRuntime } from "./features/execution/createApiRuntime.js";
4
4
  export { createApiTransportHandler } from "./features/execution/createApiTransportHandler.js";
5
+ export { createTrustedExternalApiBroker } from "./features/execution/createTrustedExternalApiBroker.js";
5
6
  export { projectApiCapabilities } from "./features/execution/projectApiCapabilities.js";
6
7
  export { resolveApiOperationBindings } from "./features/execution/resolveApiOperationBindings.js";
7
- export type { ApiApprovedHandler, ApiAuthorizationPolicy, ApiAuthorizationRequest, ApiCompositionContext, ApiHandler, ApiHandlerApproval, ApiHandlerContext, ApiHandlerRegistry, ApiHandlerResolutionRequest, ApiHandlerResolver, ApiHandlerResponse, ApiOperationBinding, ApiRequest, ApiResponse, ApiRuntime, ApiTransportAdapter, ComposeAuthorizedApiRuntimeOptions, } from "./types/api.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";
8
9
  //# 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,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,GACnC,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,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"}
package/dist/api.js CHANGED
@@ -2,6 +2,7 @@ export { CAPABILITIES } from "./capabilities/index.js";
2
2
  export { composeAuthorizedApiRuntime } from "./features/execution/composeAuthorizedApiRuntime.js";
3
3
  export { createApiRuntime } from "./features/execution/createApiRuntime.js";
4
4
  export { createApiTransportHandler } from "./features/execution/createApiTransportHandler.js";
5
+ export { createTrustedExternalApiBroker } from "./features/execution/createTrustedExternalApiBroker.js";
5
6
  export { projectApiCapabilities } from "./features/execution/projectApiCapabilities.js";
6
7
  export { resolveApiOperationBindings } from "./features/execution/resolveApiOperationBindings.js";
7
8
  //# 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,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 { 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} 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,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"]}
@@ -0,0 +1,10 @@
1
+ import type { CreateTrustedExternalApiBrokerOptions, TrustedExternalApiBroker } from "../../types/api.js";
2
+ /***
3
+ * Create a framework-neutral, fail-closed boundary for generated-app external API operations.
4
+ *
5
+ * The caller supplies operation identity and input only; trusted host ports own target,
6
+ * credentials, authorization, validation, and caller-safe result projection.
7
+ * @security createTrustedExternalApiBroker.test.ts#denies before resolving secrets or executing network work
8
+ */
9
+ export declare function createTrustedExternalApiBroker(options: CreateTrustedExternalApiBrokerOptions): TrustedExternalApiBroker;
10
+ //# sourceMappingURL=createTrustedExternalApiBroker.d.ts.map
@@ -0,0 +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"}
@@ -0,0 +1,113 @@
1
+ /***
2
+ * Create a framework-neutral, fail-closed boundary for generated-app external API operations.
3
+ *
4
+ * The caller supplies operation identity and input only; trusted host ports own target,
5
+ * credentials, authorization, validation, and caller-safe result projection.
6
+ * @security createTrustedExternalApiBroker.test.ts#denies before resolving secrets or executing network work
7
+ */
8
+ export function createTrustedExternalApiBroker(options) {
9
+ return {
10
+ executeAsync: async ({ context, request }) => executeTrustedOperationAsync(options, context, request),
11
+ };
12
+ }
13
+ /*** Authorize before resolving any operation, credential, or outbound execution resource. */
14
+ async function executeTrustedOperationAsync(options, context, request) {
15
+ if (!isTrustedBrokerContext(context) || hasCallerSuppliedTarget(request)) {
16
+ return brokerErrorResponse(403, "forbidden");
17
+ }
18
+ if (!(await isAuthorizedAsync(options, context, request))) {
19
+ return brokerErrorResponse(403, "forbidden");
20
+ }
21
+ const operation = await resolveOperationAsync(options, context, request);
22
+ if (!operation)
23
+ return brokerErrorResponse(404, "operation_not_found");
24
+ try {
25
+ const input = await options.validateInputAsync({
26
+ operation,
27
+ input: request.input,
28
+ });
29
+ const credentials = await resolveCredentialsAsync(options, context, operation);
30
+ if (operation.credentialsRequired === true && credentials === undefined) {
31
+ return brokerErrorResponse(424, "credential_unavailable");
32
+ }
33
+ const result = await options.executeOperationAsync({
34
+ operation,
35
+ input,
36
+ ...(credentials === undefined ? {} : { credentials }),
37
+ });
38
+ return publicResponse(result.status, result.publicBody);
39
+ }
40
+ catch {
41
+ return brokerErrorResponse(502, "external_operation_failed");
42
+ }
43
+ }
44
+ /*** Resolve a secret only for an operation whose trusted definition explicitly requires one. */
45
+ async function resolveCredentialsAsync(options, context, operation) {
46
+ if (operation.credentialsRequired !== true)
47
+ return undefined;
48
+ return options.resolveCredentialsAsync({ scope: context.scope, operation });
49
+ }
50
+ /*** Treat absent caller identity or incomplete project scope as a denial. */
51
+ function isTrustedBrokerContext(context) {
52
+ return (context.caller !== undefined &&
53
+ context.caller !== null &&
54
+ isNonEmpty(context.scope.appId) &&
55
+ isNonEmpty(context.scope.projectId) &&
56
+ isNonEmpty(context.scope.environment));
57
+ }
58
+ /*** Reject target-selection fields that are never part of the broker's public request contract. */
59
+ function hasCallerSuppliedTarget(request) {
60
+ return ["url", "host", "baseUrl", "upstreamUrl", "target"].some((key) => Object.hasOwn(request, key));
61
+ }
62
+ /*** Treat a missing, throwing, or false authorization decision as a denial. */
63
+ async function isAuthorizedAsync(options, context, request) {
64
+ try {
65
+ return await options.authorizeAsync({ context, request });
66
+ }
67
+ catch {
68
+ return false;
69
+ }
70
+ }
71
+ /*** Resolve only the exact operation whose server-side identity matches the caller request. */
72
+ async function resolveOperationAsync(options, context, request) {
73
+ try {
74
+ const operation = await options.resolveOperationAsync({
75
+ scope: context.scope,
76
+ request,
77
+ });
78
+ return operation !== undefined &&
79
+ operationMatchesRequest(operation, request)
80
+ ? operation
81
+ : undefined;
82
+ }
83
+ catch {
84
+ return undefined;
85
+ }
86
+ }
87
+ /*** Prevent a resolver from substituting another declared API, endpoint, or operation. */
88
+ function operationMatchesRequest(operation, request) {
89
+ return (operation.apiId === request.apiId &&
90
+ operation.endpointId === request.endpointId &&
91
+ operation.operationId === request.operationId);
92
+ }
93
+ /*** Return a result contract that never exposes credential headers or provider diagnostics. */
94
+ function publicResponse(status, publicBody) {
95
+ return {
96
+ status: Number.isInteger(status) && status >= 100 && status <= 599 ? status : 502,
97
+ headers: {},
98
+ ...(publicBody === undefined ? {} : { body: publicBody }),
99
+ };
100
+ }
101
+ /*** Produce a stable caller-visible error without leaking upstream configuration or exception text. */
102
+ function brokerErrorResponse(status, code) {
103
+ return {
104
+ status,
105
+ headers: { "content-type": "application/json" },
106
+ body: { error: { code } },
107
+ };
108
+ }
109
+ /*** Identify one non-blank trusted scope segment. */
110
+ function isNonEmpty(value) {
111
+ return value.trim().length > 0;
112
+ }
113
+ //# sourceMappingURL=createTrustedExternalApiBroker.js.map
@@ -0,0 +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,CAAC;KAC1D,CAAC;AACJ,CAAC;AAED,6FAA6F;AAC7F,KAAK,UAAU,4BAA4B,CACzC,OAA8C,EAC9C,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,OA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X,CAAC,CAAC,SAAS,CAAC;IAChB,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,SAAS,CAAC;IACnB,CAAC;AACH,CAAC;AAED,0FAA0F;AAC1F,SAAS,uBAAuB,CAC9B,SAAsC,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,EACJ,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI,MAAM,IAAI,GAAG,IAAI,MAAM,IAAI,GAAG,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG;QAC3E,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 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(\n options,\n context,\n operation,\n );\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({ scope: context.scope, operation });\n}\n\n/*** Treat absent caller identity or incomplete project scope as a denial. */\nfunction isTrustedBrokerContext(\n context: TrustedExternalApiBrokerContext,\n): 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(\n request: TrustedExternalApiBrokerRequest,\n): 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 &&\n 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:\n 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"]}
@@ -79,4 +79,65 @@ export interface ApiTransportAdapter<TRequest, TResponse> {
79
79
  toApiRequestAsync(request: TRequest, binding: ApiOperationBinding): Promise<ApiRequest>;
80
80
  fromApiResponseAsync(response: ApiResponse, request: TRequest, binding: ApiOperationBinding): Promise<TResponse>;
81
81
  }
82
+ /*** Describe the authenticated host context that scopes one generated-app broker request. */
83
+ export interface TrustedExternalApiBrokerContext {
84
+ readonly caller: unknown;
85
+ readonly scope: {
86
+ readonly appId: string;
87
+ readonly projectId: string;
88
+ readonly environment: string;
89
+ };
90
+ }
91
+ /*** Describe the only client-controlled values accepted by the trusted external API broker. */
92
+ export interface TrustedExternalApiBrokerRequest {
93
+ readonly apiId: string;
94
+ readonly endpointId: string;
95
+ readonly operationId: string;
96
+ readonly input?: unknown;
97
+ }
98
+ /*** Describe an operation resolved exclusively from trusted server-side application state. */
99
+ export interface TrustedExternalApiOperation {
100
+ readonly apiId: string;
101
+ readonly endpointId: string;
102
+ readonly operationId: string;
103
+ readonly credentialsRequired?: boolean;
104
+ }
105
+ /*** Describe server-only credentials resolved for a trusted external API operation. */
106
+ export interface TrustedExternalApiCredentials {
107
+ readonly values: Readonly<Record<string, string>>;
108
+ }
109
+ /*** Describe the caller-safe result returned after trusted operation execution. */
110
+ export interface TrustedExternalApiExecutionResult {
111
+ readonly status: number;
112
+ readonly publicBody?: unknown;
113
+ }
114
+ export interface TrustedExternalApiBroker {
115
+ executeAsync(input: {
116
+ readonly context: TrustedExternalApiBrokerContext;
117
+ readonly request: TrustedExternalApiBrokerRequest;
118
+ }): Promise<ApiResponse>;
119
+ }
120
+ export interface CreateTrustedExternalApiBrokerOptions {
121
+ readonly authorizeAsync: (input: {
122
+ readonly context: TrustedExternalApiBrokerContext;
123
+ readonly request: TrustedExternalApiBrokerRequest;
124
+ }) => boolean | Promise<boolean>;
125
+ readonly resolveOperationAsync: (input: {
126
+ readonly scope: TrustedExternalApiBrokerContext["scope"];
127
+ readonly request: TrustedExternalApiBrokerRequest;
128
+ }) => TrustedExternalApiOperation | undefined | Promise<TrustedExternalApiOperation | undefined>;
129
+ readonly validateInputAsync: (input: {
130
+ readonly operation: TrustedExternalApiOperation;
131
+ readonly input: unknown;
132
+ }) => unknown;
133
+ readonly resolveCredentialsAsync: (input: {
134
+ readonly scope: TrustedExternalApiBrokerContext["scope"];
135
+ readonly operation: TrustedExternalApiOperation;
136
+ }) => TrustedExternalApiCredentials | undefined | Promise<TrustedExternalApiCredentials | undefined>;
137
+ readonly executeOperationAsync: (input: {
138
+ readonly operation: TrustedExternalApiOperation;
139
+ readonly input: unknown;
140
+ readonly credentials?: TrustedExternalApiCredentials;
141
+ }) => TrustedExternalApiExecutionResult | Promise<TrustedExternalApiExecutionResult>;
142
+ }
82
143
  //# sourceMappingURL=api.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../src/types/api.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAClE,OAAO,KAAK,EACV,kBAAkB,EAClB,mBAAmB,EACnB,mBAAmB,EACnB,mBAAmB,EACnB,sCAAsC,EACtC,yBAAyB,EAC1B,MAAM,2BAA2B,CAAC;AAEnC,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,UAAU,EAAE,yBAAyB,CAAC;IAC/C,QAAQ,CAAC,QAAQ,EAAE,kBAAkB,CAAC;IACtC,QAAQ,CAAC,SAAS,EAAE,mBAAmB,CAAC;IACxC,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,MAAM,EAAE,mBAAmB,CAAC;IACrC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB;AAED,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC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B,GAC3B,SAAS,GACT,OAAO,CAAC,2BAA2B,GAAG,SAAS,CAAC,CAAC;IACrD,QAAQ,CAAC,kBAAkB,EAAE,CAAC,KAAK,EAAE;QACnC,QAAQ,CAAC,SAAS,EAAE,2BAA2B,CAAC;QAChD,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;KACzB,KAAK,OAAO,CAAC;IACd,QAAQ,CAAC,uBAAuB,EAAE,CAAC,KAAK,EAAE;QACxC,QAAQ,CAAC,KAAK,EAAE,+BAA+B,CAAC,OAAO,CAAC,CAAC;QACzD,QAAQ,CAAC,SAAS,EAAE,2BAA2B,CAAC;KACjD,KACG,6BAA6B,GAC7B,SAAS,GACT,OAAO,CAAC,6BAA6B,GAAG,SAAS,CAAC,CAAC;IACvD,QAAQ,CAAC,qBAAqB,EAAE,CAAC,KAAK,EAAE;QACtC,QAAQ,CAAC,SAAS,EAAE,2BAA2B,CAAC;QAChD,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;QACxB,QAAQ,CAAC,WAAW,CAAC,EAAE,6BAA6B,CAAC;KACtD,KACG,iCAAiC,GACjC,OAAO,CAAC,iCAAiC,CAAC,CAAC;CAChD"}
@@ -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(\n request: TRequest,\n binding: ApiOperationBinding,\n ): Promise<ApiRequest>;\n fromApiResponseAsync(\n response: ApiResponse,\n request: TRequest,\n binding: ApiOperationBinding,\n ): Promise<TResponse>;\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(\n request: TRequest,\n binding: ApiOperationBinding,\n ): 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 }) =>\n | TrustedExternalApiOperation\n | undefined\n | Promise<TrustedExternalApiOperation | undefined>;\n readonly validateInputAsync: (input: {\n readonly operation: TrustedExternalApiOperation;\n readonly input: unknown;\n }) => unknown;\n readonly resolveCredentialsAsync: (input: {\n readonly scope: TrustedExternalApiBrokerContext[\"scope\"];\n readonly operation: TrustedExternalApiOperation;\n }) =>\n | TrustedExternalApiCredentials\n | undefined\n | Promise<TrustedExternalApiCredentials | undefined>;\n readonly executeOperationAsync: (input: {\n readonly operation: TrustedExternalApiOperation;\n readonly input: unknown;\n readonly credentials?: TrustedExternalApiCredentials;\n }) =>\n | TrustedExternalApiExecutionResult\n | Promise<TrustedExternalApiExecutionResult>;\n}\n"]}
package/package.json CHANGED
@@ -1,8 +1,13 @@
1
1
  {
2
2
  "name": "@ankhorage/api",
3
- "version": "0.5.1",
3
+ "version": "0.6.0",
4
4
  "type": "module",
5
5
  "description": "Framework-neutral executable API runtime and transport contract for Ankhorage.",
6
+ "ankh": {
7
+ "category": "api",
8
+ "provider": null,
9
+ "capabilities": []
10
+ },
6
11
  "license": "MIT",
7
12
  "repository": {
8
13
  "type": "git",
@@ -66,7 +71,7 @@
66
71
  "@ankhorage/contracts": "^26.10.0"
67
72
  },
68
73
  "devDependencies": {
69
- "@ankhorage/devtools": "^2.1.11",
74
+ "@ankhorage/devtools": "^2.9.5",
70
75
  "@ankhorage/paradox": "^0.2.28",
71
76
  "@ankhorage/projects": "^0.1.0",
72
77
  "@types/bun": "^1.4.2",