@ankhorage/api 0.6.0 → 0.6.1
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 +13 -13
- package/dist/api.d.ts +8 -8
- package/dist/api.js +7 -7
- package/dist/api.js.map +1 -1
- package/dist/capabilities/index.js.map +1 -1
- package/dist/features/execution/composeAuthorizedApiRuntime.d.ts +1 -1
- package/dist/features/execution/composeAuthorizedApiRuntime.js +18 -24
- package/dist/features/execution/composeAuthorizedApiRuntime.js.map +1 -1
- package/dist/features/execution/createApiRuntime.d.ts +2 -2
- package/dist/features/execution/createApiRuntime.d.ts.map +1 -1
- package/dist/features/execution/createApiRuntime.js +6 -6
- package/dist/features/execution/createApiRuntime.js.map +1 -1
- package/dist/features/execution/createApiTransportHandler.d.ts +1 -1
- package/dist/features/execution/createApiTransportHandler.d.ts.map +1 -1
- package/dist/features/execution/createApiTransportHandler.js.map +1 -1
- package/dist/features/execution/createTrustedExternalApiBroker.d.ts +1 -1
- package/dist/features/execution/createTrustedExternalApiBroker.js +13 -10
- package/dist/features/execution/createTrustedExternalApiBroker.js.map +1 -1
- package/dist/features/execution/projectApiCapabilities.d.ts +2 -2
- package/dist/features/execution/projectApiCapabilities.d.ts.map +1 -1
- package/dist/features/execution/projectApiCapabilities.js +8 -14
- package/dist/features/execution/projectApiCapabilities.js.map +1 -1
- package/dist/features/execution/resolveApiOperationBindings.d.ts +2 -2
- package/dist/features/execution/resolveApiOperationBindings.d.ts.map +1 -1
- package/dist/features/execution/resolveApiOperationBindings.js +12 -12
- package/dist/features/execution/resolveApiOperationBindings.js.map +1 -1
- package/dist/types/api.d.ts +6 -5
- package/dist/types/api.d.ts.map +1 -1
- package/dist/types/api.js.map +1 -1
- package/package.json +4 -4
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
|
|
|
@@ -29,21 +29,21 @@ responses at the transport edge while this runtime owns operation lookup and dis
|
|
|
29
29
|
|
|
30
30
|
```ts
|
|
31
31
|
const definition = {
|
|
32
|
-
id:
|
|
33
|
-
origin:
|
|
34
|
-
protocol:
|
|
35
|
-
basePath:
|
|
32
|
+
id: 'health-api',
|
|
33
|
+
origin: 'internal',
|
|
34
|
+
protocol: 'rest',
|
|
35
|
+
basePath: '/api',
|
|
36
36
|
endpoints: {
|
|
37
37
|
health: {
|
|
38
|
-
id:
|
|
39
|
-
kind:
|
|
38
|
+
id: 'health',
|
|
39
|
+
kind: 'http',
|
|
40
40
|
operations: {
|
|
41
|
-
|
|
42
|
-
id:
|
|
43
|
-
protocol:
|
|
44
|
-
intent:
|
|
45
|
-
method:
|
|
46
|
-
path:
|
|
41
|
+
'health.read': {
|
|
42
|
+
id: 'health.read',
|
|
43
|
+
protocol: 'http',
|
|
44
|
+
intent: 'read',
|
|
45
|
+
method: 'GET',
|
|
46
|
+
path: '/health',
|
|
47
47
|
},
|
|
48
48
|
},
|
|
49
49
|
},
|
package/dist/api.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
export { CAPABILITIES } from
|
|
2
|
-
export { composeAuthorizedApiRuntime } from
|
|
3
|
-
export { createApiRuntime } from
|
|
4
|
-
export { createApiTransportHandler } from
|
|
5
|
-
export { createTrustedExternalApiBroker } from
|
|
6
|
-
export { projectApiCapabilities } from
|
|
7
|
-
export { resolveApiOperationBindings } from
|
|
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
|
|
1
|
+
export { CAPABILITIES } from './capabilities/index.js';
|
|
2
|
+
export { composeAuthorizedApiRuntime } from './features/execution/composeAuthorizedApiRuntime.js';
|
|
3
|
+
export { createApiRuntime } from './features/execution/createApiRuntime.js';
|
|
4
|
+
export { createApiTransportHandler } from './features/execution/createApiTransportHandler.js';
|
|
5
|
+
export { createTrustedExternalApiBroker } from './features/execution/createTrustedExternalApiBroker.js';
|
|
6
|
+
export { projectApiCapabilities } from './features/execution/projectApiCapabilities.js';
|
|
7
|
+
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
9
|
//# sourceMappingURL=api.d.ts.map
|
package/dist/api.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
export { CAPABILITIES } from
|
|
2
|
-
export { composeAuthorizedApiRuntime } from
|
|
3
|
-
export { createApiRuntime } from
|
|
4
|
-
export { createApiTransportHandler } from
|
|
5
|
-
export { createTrustedExternalApiBroker } from
|
|
6
|
-
export { projectApiCapabilities } from
|
|
7
|
-
export { resolveApiOperationBindings } from
|
|
1
|
+
export { CAPABILITIES } from './capabilities/index.js';
|
|
2
|
+
export { composeAuthorizedApiRuntime } from './features/execution/composeAuthorizedApiRuntime.js';
|
|
3
|
+
export { createApiRuntime } from './features/execution/createApiRuntime.js';
|
|
4
|
+
export { createApiTransportHandler } from './features/execution/createApiTransportHandler.js';
|
|
5
|
+
export { createTrustedExternalApiBroker } from './features/execution/createTrustedExternalApiBroker.js';
|
|
6
|
+
export { projectApiCapabilities } from './features/execution/projectApiCapabilities.js';
|
|
7
|
+
export { resolveApiOperationBindings } from './features/execution/resolveApiOperationBindings.js';
|
|
8
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,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
|
|
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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/capabilities/index.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,EAA2C,CAAC","sourcesContent":["import type { Capability } from
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/capabilities/index.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,EAA2C,CAAC","sourcesContent":["import type { Capability } from '@ankhorage/contracts/capability';\n\n/**\n * Static API package capabilities.\n *\n * Executable API operations are dynamic and are projected from authored API definitions by\n * `projectApiCapabilities`; they are intentionally not duplicated in this static catalog.\n */\nexport const CAPABILITIES = [] as const satisfies readonly Capability[];\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ApiRuntime, ComposeAuthorizedApiRuntimeOptions } from
|
|
1
|
+
import type { ApiRuntime, ComposeAuthorizedApiRuntimeOptions } from '../../types/api.js';
|
|
2
2
|
/***
|
|
3
3
|
* Compose declared API operations with host-approved handlers and deny-by-default authorization.
|
|
4
4
|
*/
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { createApiRuntime } from
|
|
2
|
-
import { resolveApiOperationBindings } from
|
|
1
|
+
import { createApiRuntime } from './createApiRuntime.js';
|
|
2
|
+
import { resolveApiOperationBindings } from './resolveApiOperationBindings.js';
|
|
3
3
|
/***
|
|
4
4
|
* Compose declared API operations with host-approved handlers and deny-by-default authorization.
|
|
5
5
|
*/
|
|
@@ -22,10 +22,7 @@ function resolveAuthorizedHandlers(options) {
|
|
|
22
22
|
context: options.context,
|
|
23
23
|
});
|
|
24
24
|
assertApprovedHandler(binding, declaration.capability, options.context, approvedHandler);
|
|
25
|
-
return [
|
|
26
|
-
binding.operationId,
|
|
27
|
-
createAuthorizedHandler(binding, approvedHandler, options),
|
|
28
|
-
];
|
|
25
|
+
return [binding.operationId, createAuthorizedHandler(binding, approvedHandler, options)];
|
|
29
26
|
}));
|
|
30
27
|
}
|
|
31
28
|
/*** Resolve one exact declared capability target for every executable API operation. */
|
|
@@ -33,7 +30,7 @@ function resolveHandlerDeclarations(definition) {
|
|
|
33
30
|
const bindings = resolveApiOperationBindings(definition);
|
|
34
31
|
const bindingIds = new Set(bindings.map((binding) => binding.operationId));
|
|
35
32
|
if (bindingIds.size !== bindings.length) {
|
|
36
|
-
throw new Error(
|
|
33
|
+
throw new Error('API definition declares duplicate endpoint operation ids.');
|
|
37
34
|
}
|
|
38
35
|
const declarations = Object.entries(definition.handlers ?? {});
|
|
39
36
|
const declaredOperationIds = new Set();
|
|
@@ -55,16 +52,13 @@ function resolveHandlerDeclarations(definition) {
|
|
|
55
52
|
declaredCapabilityIds.add(declaration.capability);
|
|
56
53
|
}
|
|
57
54
|
if (declaredOperationIds.size !== bindingIds.size) {
|
|
58
|
-
throw new Error(
|
|
55
|
+
throw new Error('Every API operation requires exactly one handler declaration.');
|
|
59
56
|
}
|
|
60
|
-
return new Map(declarations.map(([, declaration]) => [
|
|
61
|
-
declaration.operationId,
|
|
62
|
-
declaration,
|
|
63
|
-
]));
|
|
57
|
+
return new Map(declarations.map(([, declaration]) => [declaration.operationId, declaration]));
|
|
64
58
|
}
|
|
65
59
|
/*** Reject a handler unless the host-approved owner capability exactly matches the declaration. */
|
|
66
60
|
function assertApprovedHandler(binding, capabilityId, context, approvedHandler) {
|
|
67
|
-
if (!approvedHandler || typeof approvedHandler.handler !==
|
|
61
|
+
if (!approvedHandler || typeof approvedHandler.handler !== 'function') {
|
|
68
62
|
throw new Error(`No approved handler is registered for API operation ${binding.operationId}.`);
|
|
69
63
|
}
|
|
70
64
|
if (approvedHandler.capability.id !== capabilityId) {
|
|
@@ -90,14 +84,14 @@ function assertApprovedHandler(binding, capabilityId, context, approvedHandler)
|
|
|
90
84
|
/*** Resolve the one capability access verb that may execute a declared API intent. */
|
|
91
85
|
function accessForIntent(intent) {
|
|
92
86
|
switch (intent) {
|
|
93
|
-
case
|
|
94
|
-
return
|
|
95
|
-
case
|
|
96
|
-
return
|
|
97
|
-
case
|
|
98
|
-
case
|
|
99
|
-
case
|
|
100
|
-
return
|
|
87
|
+
case 'action':
|
|
88
|
+
return 'invoke';
|
|
89
|
+
case 'read':
|
|
90
|
+
return 'read';
|
|
91
|
+
case 'create':
|
|
92
|
+
case 'delete':
|
|
93
|
+
case 'update':
|
|
94
|
+
return 'write';
|
|
101
95
|
}
|
|
102
96
|
}
|
|
103
97
|
/*** Deny a request unless the host authorization policy explicitly approves it. */
|
|
@@ -129,15 +123,15 @@ async function isAuthorizedAsync(binding, request, options) {
|
|
|
129
123
|
/*** Reject incomplete composition scope before any HTTP route can be registered. */
|
|
130
124
|
function assertCompositionContext(context) {
|
|
131
125
|
if (!context.appId.trim() || !context.projectId.trim()) {
|
|
132
|
-
throw new Error(
|
|
126
|
+
throw new Error('Authorized API composition requires non-empty app and project ids.');
|
|
133
127
|
}
|
|
134
128
|
}
|
|
135
129
|
/*** Return a normalized authorization failure without invoking the selected handler. */
|
|
136
130
|
function forbiddenResponse(operationId) {
|
|
137
131
|
return {
|
|
138
132
|
status: 403,
|
|
139
|
-
headers: {
|
|
140
|
-
body: { error: { code:
|
|
133
|
+
headers: { 'content-type': 'application/json' },
|
|
134
|
+
body: { error: { code: 'forbidden', operationId } },
|
|
141
135
|
};
|
|
142
136
|
}
|
|
143
137
|
//# sourceMappingURL=composeAuthorizedApiRuntime.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"composeAuthorizedApiRuntime.js","sourceRoot":"","sources":["../../../src/features/execution/composeAuthorizedApiRuntime.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,2BAA2B,EAAE,MAAM,kCAAkC,CAAC;AAE/E;;GAEG;AACH,MAAM,UAAU,2BAA2B,CACzC,OAA2C;IAE3C,wBAAwB,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;IAC1C,MAAM,QAAQ,GAAG,yBAAyB,CAAC,OAAO,CAAC,CAAC;IAEpD,OAAO,gBAAgB,CAAC,EAAE,UAAU,EAAE,OAAO,CAAC,UAAU,EAAE,QAAQ,EAAE,CAAC,CAAC;AACxE,CAAC;AAED,yEAAyE;AACzE,SAAS,yBAAyB,CAChC,OAA2C;IAE3C,MAAM,YAAY,GAAG,0BAA0B,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;IAEpE,OAAO,MAAM,CAAC,WAAW,CACvB,2BAA2B,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,GAAG,CAAC,CAAC,OAAO,EAA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AC;IACJ,CAAC;AACH,CAAC;AAED,wFAAwF;AACxF,SAAS,iBAAiB,CAAC,WAAmB;IAC5C,OAAO;QACL,MAAM,EAAE,GAAG;QACX,OAAO,EAAE,EAAE,cAAc,EAAE,kBAAkB,EAAE;QAC/C,IAAI,EAAE,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,WAAW,EAAE,WAAW,EAAE,EAAE;KACpD,CAAC;AACJ,CAAC","sourcesContent":["import type {\n ApiApprovedHandler,\n ApiHandler,\n ApiHandlerRegistry,\n ApiOperationBinding,\n ApiResponse,\n ApiRuntime,\n ComposeAuthorizedApiRuntimeOptions,\n} from \"../../types/api.js\";\nimport { createApiRuntime } from \"./createApiRuntime.js\";\nimport { resolveApiOperationBindings } from \"./resolveApiOperationBindings.js\";\n\n/***\n * Compose declared API operations with host-approved handlers and deny-by-default authorization.\n */\nexport function composeAuthorizedApiRuntime(\n options: ComposeAuthorizedApiRuntimeOptions,\n): ApiRuntime {\n assertCompositionContext(options.context);\n const handlers = resolveAuthorizedHandlers(options);\n\n return createApiRuntime({ definition: options.definition, handlers });\n}\n\n/*** Resolve every declared operation before exposing the API runtime. */\nfunction resolveAuthorizedHandlers(\n options: ComposeAuthorizedApiRuntimeOptions,\n): ApiHandlerRegistry {\n const declarations = resolveHandlerDeclarations(options.definition);\n\n return Object.fromEntries(\n resolveApiOperationBindings(options.definition).map((binding) => {\n const declaration = declarations.get(binding.operationId);\n if (!declaration) {\n throw new Error(\n `No declared handler targets API operation ${binding.operationId}.`,\n );\n }\n\n const approvedHandler = options.resolveHandler({\n binding,\n declaration,\n context: options.context,\n });\n assertApprovedHandler(\n binding,\n declaration.capability,\n options.context,\n approvedHandler,\n );\n\n return [\n binding.operationId,\n createAuthorizedHandler(binding, approvedHandler, options),\n ];\n }),\n );\n}\n\n/*** Resolve one exact declared capability target for every executable API operation. */\nfunction resolveHandlerDeclarations(\n definition: ComposeAuthorizedApiRuntimeOptions[\"definition\"],\n): ReadonlyMap<string, NonNullable<typeof definition.handlers>[string]> {\n const bindings = resolveApiOperationBindings(definition);\n const bindingIds = new Set(bindings.map((binding) => binding.operationId));\n if (bindingIds.size !== bindings.length) {\n throw new Error(\n \"API definition declares duplicate endpoint operation ids.\",\n );\n }\n\n const declarations = Object.entries(definition.handlers ?? {});\n const declaredOperationIds = new Set<string>();\n const declaredCapabilityIds = new Set<string>();\n for (const [registryOperationId, declaration] of declarations) {\n if (registryOperationId !== declaration.operationId) {\n throw new Error(\n `Handler declaration key does not match its operation id: ${registryOperationId}.`,\n );\n }\n if (!bindingIds.has(declaration.operationId)) {\n throw new Error(\n `Handler declaration targets unknown API operation ${declaration.operationId}.`,\n );\n }\n if (declaredOperationIds.has(declaration.operationId)) {\n throw new Error(\n `Duplicate handler declaration for API operation ${declaration.operationId}.`,\n );\n }\n if (declaredCapabilityIds.has(declaration.capability)) {\n throw new Error(\n `Duplicate handler declaration for capability ${declaration.capability}.`,\n );\n }\n declaredOperationIds.add(declaration.operationId);\n declaredCapabilityIds.add(declaration.capability);\n }\n\n if (declaredOperationIds.size !== bindingIds.size) {\n throw new Error(\n \"Every API operation requires exactly one handler declaration.\",\n );\n }\n\n return new Map(\n declarations.map(([, declaration]) => [\n declaration.operationId,\n declaration,\n ]),\n );\n}\n\n/*** Reject a handler unless the host-approved owner capability exactly matches the declaration. */\nfunction assertApprovedHandler(\n binding: ApiOperationBinding,\n capabilityId: string,\n context: ComposeAuthorizedApiRuntimeOptions[\"context\"],\n approvedHandler: ApiApprovedHandler | undefined,\n): asserts approvedHandler is ApiApprovedHandler {\n if (!approvedHandler || typeof approvedHandler.handler !== \"function\") {\n throw new Error(\n `No approved handler is registered for API operation ${binding.operationId}.`,\n );\n }\n if (approvedHandler.capability.id !== capabilityId) {\n throw new Error(\n `Approved handler capability does not match API operation ${binding.operationId}.`,\n );\n }\n if (!approvedHandler.capability.owner.trim()) {\n throw new Error(\n `Approved handler has no owner for API operation ${binding.operationId}.`,\n );\n }\n if (\n approvedHandler.approval.operationId !== binding.operationId ||\n approvedHandler.approval.intent !== binding.operation.intent ||\n approvedHandler.approval.method !== binding.method ||\n approvedHandler.approval.capabilityId !== capabilityId ||\n approvedHandler.approval.owner !== approvedHandler.capability.owner ||\n approvedHandler.approval.scope.appId !== context.appId ||\n approvedHandler.approval.scope.projectId !== context.projectId\n ) {\n throw new Error(\n `Approved handler does not authorize API operation ${binding.operationId}.`,\n );\n }\n const requiredAccess = accessForIntent(binding.operation.intent);\n if (!approvedHandler.capability.access.includes(requiredAccess)) {\n throw new Error(\n `Approved handler does not grant ${requiredAccess} access for API operation ${binding.operationId}.`,\n );\n }\n}\n\n/*** Resolve the one capability access verb that may execute a declared API intent. */\nfunction accessForIntent(\n intent: ApiOperationBinding[\"operation\"][\"intent\"],\n): \"invoke\" | \"read\" | \"write\" {\n switch (intent) {\n case \"action\":\n return \"invoke\";\n case \"read\":\n return \"read\";\n case \"create\":\n case \"delete\":\n case \"update\":\n return \"write\";\n }\n}\n\n/*** Deny a request unless the host authorization policy explicitly approves it. */\nfunction createAuthorizedHandler(\n binding: ApiOperationBinding,\n approvedHandler: ApiApprovedHandler,\n options: ComposeAuthorizedApiRuntimeOptions,\n): ApiHandler {\n return async (request) => {\n const authorized = await isAuthorizedAsync(binding, request, options);\n if (!authorized) return forbiddenResponse(binding.operationId);\n\n return approvedHandler.handler(request, {\n binding,\n composition: options.context,\n capability: approvedHandler.capability,\n });\n };\n}\n\n/*** Treat a failing authorization policy exactly like an explicit denial. */\nasync function isAuthorizedAsync(\n binding: ApiOperationBinding,\n request: Parameters<ApiHandler>[0],\n options: ComposeAuthorizedApiRuntimeOptions,\n): Promise<boolean> {\n try {\n return await options.authorizeAsync({\n binding,\n context: options.context,\n request,\n });\n } catch {\n return false;\n }\n}\n\n/*** Reject incomplete composition scope before any HTTP route can be registered. */\nfunction assertCompositionContext(\n context: ComposeAuthorizedApiRuntimeOptions[\"context\"],\n): void {\n if (!context.appId.trim() || !context.projectId.trim()) {\n throw new Error(\n \"Authorized API composition requires non-empty app and project ids.\",\n );\n }\n}\n\n/*** Return a normalized authorization failure without invoking the selected handler. */\nfunction forbiddenResponse(operationId: string): ApiResponse {\n return {\n status: 403,\n headers: { \"content-type\": \"application/json\" },\n body: { error: { code: \"forbidden\", operationId } },\n };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"composeAuthorizedApiRuntime.js","sourceRoot":"","sources":["../../../src/features/execution/composeAuthorizedApiRuntime.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,2BAA2B,EAAE,MAAM,kCAAkC,CAAC;AAE/E;;GAEG;AACH,MAAM,UAAU,2BAA2B,CACzC,OAA2C;IAE3C,wBAAwB,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;IAC1C,MAAM,QAAQ,GAAG,yBAAyB,CAAC,OAAO,CAAC,CAAC;IAEpD,OAAO,gBAAgB,CAAC,EAAE,UAAU,EAAE,OAAO,CAAC,UAAU,EAAE,QAAQ,EAAE,CAAC,CAAC;AACxE,CAAC;AAED,yEAAyE;AACzE,SAAS,yBAAyB,CAChC,OAA2C;IAE3C,MAAM,YAAY,GAAG,0BAA0B,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;IAEpE,OAAO,MAAM,CAAC,WAAW,CACvB,2BAA2B,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE;QAC9D,MAAM,WAAW,GAAG,YAAY,CAAC,GAAG,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;QAC1D,IAAI,CAAC,WAAW,EAAE,CAAC;YACjB,MAAM,IAAI,KAAK,CAAC,6CAA6C,OAAO,CAAC,WAAW,GAAG,CAAC,CAAC;QACvF,CAAC;QAED,MAAM,eAAe,GAAG,OAAO,CAAC,cAAc,CAAC;YAC7C,OAAO;YACP,WAAW;YACX,OAAO,EAAE,OAAO,CAAC,OAAO;SACzB,CAAC,CAAC;QACH,qB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OperationBinding,\n ApiResponse,\n ApiRuntime,\n ComposeAuthorizedApiRuntimeOptions,\n} from '../../types/api.js';\nimport { createApiRuntime } from './createApiRuntime.js';\nimport { resolveApiOperationBindings } from './resolveApiOperationBindings.js';\n\n/***\n * Compose declared API operations with host-approved handlers and deny-by-default authorization.\n */\nexport function composeAuthorizedApiRuntime(\n options: ComposeAuthorizedApiRuntimeOptions,\n): ApiRuntime {\n assertCompositionContext(options.context);\n const handlers = resolveAuthorizedHandlers(options);\n\n return createApiRuntime({ definition: options.definition, handlers });\n}\n\n/*** Resolve every declared operation before exposing the API runtime. */\nfunction resolveAuthorizedHandlers(\n options: ComposeAuthorizedApiRuntimeOptions,\n): ApiHandlerRegistry {\n const declarations = resolveHandlerDeclarations(options.definition);\n\n return Object.fromEntries(\n resolveApiOperationBindings(options.definition).map((binding) => {\n const declaration = declarations.get(binding.operationId);\n if (!declaration) {\n throw new Error(`No declared handler targets API operation ${binding.operationId}.`);\n }\n\n const approvedHandler = options.resolveHandler({\n binding,\n declaration,\n context: options.context,\n });\n assertApprovedHandler(binding, declaration.capability, options.context, approvedHandler);\n\n return [binding.operationId, createAuthorizedHandler(binding, approvedHandler, options)];\n }),\n );\n}\n\n/*** Resolve one exact declared capability target for every executable API operation. */\nfunction resolveHandlerDeclarations(\n definition: ComposeAuthorizedApiRuntimeOptions['definition'],\n): ReadonlyMap<string, NonNullable<typeof definition.handlers>[string]> {\n const bindings = resolveApiOperationBindings(definition);\n const bindingIds = new Set(bindings.map((binding) => binding.operationId));\n if (bindingIds.size !== bindings.length) {\n throw new Error('API definition declares duplicate endpoint operation ids.');\n }\n\n const declarations = Object.entries(definition.handlers ?? {});\n const declaredOperationIds = new Set<string>();\n const declaredCapabilityIds = new Set<string>();\n for (const [registryOperationId, declaration] of declarations) {\n if (registryOperationId !== declaration.operationId) {\n throw new Error(\n `Handler declaration key does not match its operation id: ${registryOperationId}.`,\n );\n }\n if (!bindingIds.has(declaration.operationId)) {\n throw new Error(\n `Handler declaration targets unknown API operation ${declaration.operationId}.`,\n );\n }\n if (declaredOperationIds.has(declaration.operationId)) {\n throw new Error(\n `Duplicate handler declaration for API operation ${declaration.operationId}.`,\n );\n }\n if (declaredCapabilityIds.has(declaration.capability)) {\n throw new Error(`Duplicate handler declaration for capability ${declaration.capability}.`);\n }\n declaredOperationIds.add(declaration.operationId);\n declaredCapabilityIds.add(declaration.capability);\n }\n\n if (declaredOperationIds.size !== bindingIds.size) {\n throw new Error('Every API operation requires exactly one handler declaration.');\n }\n\n return new Map(declarations.map(([, declaration]) => [declaration.operationId, declaration]));\n}\n\n/*** Reject a handler unless the host-approved owner capability exactly matches the declaration. */\nfunction assertApprovedHandler(\n binding: ApiOperationBinding,\n capabilityId: string,\n context: ComposeAuthorizedApiRuntimeOptions['context'],\n approvedHandler: ApiApprovedHandler | undefined,\n): asserts approvedHandler is ApiApprovedHandler {\n if (!approvedHandler || typeof approvedHandler.handler !== 'function') {\n throw new Error(`No approved handler is registered for API operation ${binding.operationId}.`);\n }\n if (approvedHandler.capability.id !== capabilityId) {\n throw new Error(\n `Approved handler capability does not match API operation ${binding.operationId}.`,\n );\n }\n if (!approvedHandler.capability.owner.trim()) {\n throw new Error(`Approved handler has no owner for API operation ${binding.operationId}.`);\n }\n if (\n approvedHandler.approval.operationId !== binding.operationId ||\n approvedHandler.approval.intent !== binding.operation.intent ||\n approvedHandler.approval.method !== binding.method ||\n approvedHandler.approval.capabilityId !== capabilityId ||\n approvedHandler.approval.owner !== approvedHandler.capability.owner ||\n approvedHandler.approval.scope.appId !== context.appId ||\n approvedHandler.approval.scope.projectId !== context.projectId\n ) {\n throw new Error(`Approved handler does not authorize API operation ${binding.operationId}.`);\n }\n const requiredAccess = accessForIntent(binding.operation.intent);\n if (!approvedHandler.capability.access.includes(requiredAccess)) {\n throw new Error(\n `Approved handler does not grant ${requiredAccess} access for API operation ${binding.operationId}.`,\n );\n }\n}\n\n/*** Resolve the one capability access verb that may execute a declared API intent. */\nfunction accessForIntent(\n intent: ApiOperationBinding['operation']['intent'],\n): 'invoke' | 'read' | 'write' {\n switch (intent) {\n case 'action':\n return 'invoke';\n case 'read':\n return 'read';\n case 'create':\n case 'delete':\n case 'update':\n return 'write';\n }\n}\n\n/*** Deny a request unless the host authorization policy explicitly approves it. */\nfunction createAuthorizedHandler(\n binding: ApiOperationBinding,\n approvedHandler: ApiApprovedHandler,\n options: ComposeAuthorizedApiRuntimeOptions,\n): ApiHandler {\n return async (request) => {\n const authorized = await isAuthorizedAsync(binding, request, options);\n if (!authorized) return forbiddenResponse(binding.operationId);\n\n return approvedHandler.handler(request, {\n binding,\n composition: options.context,\n capability: approvedHandler.capability,\n });\n };\n}\n\n/*** Treat a failing authorization policy exactly like an explicit denial. */\nasync function isAuthorizedAsync(\n binding: ApiOperationBinding,\n request: Parameters<ApiHandler>[0],\n options: ComposeAuthorizedApiRuntimeOptions,\n): Promise<boolean> {\n try {\n return await options.authorizeAsync({\n binding,\n context: options.context,\n request,\n });\n } catch {\n return false;\n }\n}\n\n/*** Reject incomplete composition scope before any HTTP route can be registered. */\nfunction assertCompositionContext(context: ComposeAuthorizedApiRuntimeOptions['context']): void {\n if (!context.appId.trim() || !context.projectId.trim()) {\n throw new Error('Authorized API composition requires non-empty app and project ids.');\n }\n}\n\n/*** Return a normalized authorization failure without invoking the selected handler. */\nfunction forbiddenResponse(operationId: string): ApiResponse {\n return {\n status: 403,\n headers: { 'content-type': 'application/json' },\n body: { error: { code: 'forbidden', operationId } },\n };\n}\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { InternalRestApiDefinition } from
|
|
2
|
-
import type { ApiHandlerRegistry, ApiRuntime } from
|
|
1
|
+
import type { InternalRestApiDefinition } from '@ankhorage/contracts/data';
|
|
2
|
+
import type { ApiHandlerRegistry, ApiRuntime } from '../../types/api.js';
|
|
3
3
|
/*** Create the canonical executable API runtime for one portable internal REST definition. */
|
|
4
4
|
export declare function createApiRuntime(input: {
|
|
5
5
|
readonly definition: InternalRestApiDefinition;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createApiRuntime.d.ts","sourceRoot":"","sources":["../../../src/features/execution/createApiRuntime.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,2BAA2B,CAAC;AAE3E,OAAO,KAAK,EACV,kBAAkB,EAIlB,UAAU,EACX,MAAM,oBAAoB,CAAC;AAG5B,8FAA8F;AAC9F,wBAAgB,gBAAgB,CAAC,KAAK,EAAE;IACtC,QAAQ,CAAC,UAAU,EAAE,yBAAyB,CAAC;IAC/C,QAAQ,CAAC,QAAQ,EAAE,kBAAkB,CAAC;CACvC,GAAG,UAAU,
|
|
1
|
+
{"version":3,"file":"createApiRuntime.d.ts","sourceRoot":"","sources":["../../../src/features/execution/createApiRuntime.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,2BAA2B,CAAC;AAE3E,OAAO,KAAK,EACV,kBAAkB,EAIlB,UAAU,EACX,MAAM,oBAAoB,CAAC;AAG5B,8FAA8F;AAC9F,wBAAgB,gBAAgB,CAAC,KAAK,EAAE;IACtC,QAAQ,CAAC,UAAU,EAAE,yBAAyB,CAAC;IAC/C,QAAQ,CAAC,QAAQ,EAAE,kBAAkB,CAAC;CACvC,GAAG,UAAU,CAWb"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { resolveApiOperationBindings } from
|
|
1
|
+
import { resolveApiOperationBindings } from './resolveApiOperationBindings.js';
|
|
2
2
|
/*** Create the canonical executable API runtime for one portable internal REST definition. */
|
|
3
3
|
export function createApiRuntime(input) {
|
|
4
4
|
const bindings = resolveApiOperationBindings(input.definition);
|
|
@@ -14,20 +14,20 @@ export function createApiRuntime(input) {
|
|
|
14
14
|
async function dispatchApiRequestAsync(request, bindingsByOperation, handlers) {
|
|
15
15
|
const binding = bindingsByOperation.get(request.operationId);
|
|
16
16
|
if (!binding) {
|
|
17
|
-
return errorResponse(404,
|
|
17
|
+
return errorResponse(404, 'operation_not_found', request.operationId);
|
|
18
18
|
}
|
|
19
19
|
if (request.method !== binding.method) {
|
|
20
|
-
return errorResponse(405,
|
|
20
|
+
return errorResponse(405, 'method_not_allowed', request.operationId);
|
|
21
21
|
}
|
|
22
22
|
const handler = handlers[request.operationId];
|
|
23
23
|
if (!handler) {
|
|
24
|
-
return errorResponse(501,
|
|
24
|
+
return errorResponse(501, 'handler_not_registered', request.operationId);
|
|
25
25
|
}
|
|
26
26
|
try {
|
|
27
27
|
return normalizeResponse(await handler(request, { binding }));
|
|
28
28
|
}
|
|
29
29
|
catch {
|
|
30
|
-
return errorResponse(500,
|
|
30
|
+
return errorResponse(500, 'handler_failed', request.operationId);
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
33
|
/*** Normalize handler responses to the stable runtime response contract. */
|
|
@@ -42,7 +42,7 @@ function normalizeResponse(response) {
|
|
|
42
42
|
function errorResponse(status, code, operationId) {
|
|
43
43
|
return {
|
|
44
44
|
status,
|
|
45
|
-
headers: {
|
|
45
|
+
headers: { 'content-type': 'application/json' },
|
|
46
46
|
body: {
|
|
47
47
|
error: {
|
|
48
48
|
code,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createApiRuntime.js","sourceRoot":"","sources":["../../../src/features/execution/createApiRuntime.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,2BAA2B,EAAE,MAAM,kCAAkC,CAAC;AAE/E,8FAA8F;AAC9F,MAAM,UAAU,gBAAgB,CAAC,KAGhC;IACC,MAAM,QAAQ,GAAG,2BAA2B,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;IAC/D,MAAM,mBAAmB,GAAG,IAAI,GAAG,
|
|
1
|
+
{"version":3,"file":"createApiRuntime.js","sourceRoot":"","sources":["../../../src/features/execution/createApiRuntime.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,2BAA2B,EAAE,MAAM,kCAAkC,CAAC;AAE/E,8FAA8F;AAC9F,MAAM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B,CAAC,MAAM,OAAO,CAAC,OAAO,EAAE,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC;IAChE,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,aAAa,CAAC,GAAG,EAAE,gBAAgB,EAAE,OAAO,CAAC,WAAW,CAAC,CAAC;IACnE,CAAC;AACH,CAAC;AAED,4EAA4E;AAC5E,SAAS,iBAAiB,CAAC,QAA4B;IACrD,OAAO;QACL,MAAM,EAAE,QAAQ,CAAC,MAAM,IAAI,GAAG;QAC9B,OAAO,EAAE,QAAQ,CAAC,OAAO,IAAI,EAAE;QAC/B,GAAG,CAAC,QAAQ,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,QAAQ,CAAC,IAAI,EAAE,CAAC;KAChE,CAAC;AACJ,CAAC;AAED,wDAAwD;AACxD,SAAS,aAAa,CAAC,MAAc,EAAE,IAAY,EAAE,WAAmB;IACtE,OAAO;QACL,MAAM;QACN,OAAO,EAAE,EAAE,cAAc,EAAE,kBAAkB,EAAE;QAC/C,IAAI,EAAE;YACJ,KAAK,EAAE;gBACL,IAAI;gBACJ,WAAW;aACZ;SACF;KACF,CAAC;AACJ,CAAC","sourcesContent":["import type { InternalRestApiDefinition } from '@ankhorage/contracts/data';\n\nimport type {\n ApiHandlerRegistry,\n ApiHandlerResponse,\n ApiRequest,\n ApiResponse,\n ApiRuntime,\n} from '../../types/api.js';\nimport { resolveApiOperationBindings } from './resolveApiOperationBindings.js';\n\n/*** Create the canonical executable API runtime for one portable internal REST definition. */\nexport function createApiRuntime(input: {\n readonly definition: InternalRestApiDefinition;\n readonly handlers: ApiHandlerRegistry;\n}): ApiRuntime {\n const bindings = resolveApiOperationBindings(input.definition);\n const bindingsByOperation = new Map(bindings.map((binding) => [binding.operationId, binding]));\n\n return {\n definition: input.definition,\n bindings,\n getBinding: (operationId) => bindingsByOperation.get(operationId),\n dispatchAsync: async (request) =>\n dispatchApiRequestAsync(request, bindingsByOperation, input.handlers),\n };\n}\n\n/*** Dispatch one normalized request to its registered operation handler. */\nasync function dispatchApiRequestAsync(\n request: ApiRequest,\n bindingsByOperation: ReadonlyMap<string, ReturnType<typeof resolveApiOperationBindings>[number]>,\n handlers: ApiHandlerRegistry,\n): Promise<ApiResponse> {\n const binding = bindingsByOperation.get(request.operationId);\n if (!binding) {\n return errorResponse(404, 'operation_not_found', request.operationId);\n }\n if (request.method !== binding.method) {\n return errorResponse(405, 'method_not_allowed', request.operationId);\n }\n\n const handler = handlers[request.operationId];\n if (!handler) {\n return errorResponse(501, 'handler_not_registered', request.operationId);\n }\n\n try {\n return normalizeResponse(await handler(request, { binding }));\n } catch {\n return errorResponse(500, 'handler_failed', request.operationId);\n }\n}\n\n/*** Normalize handler responses to the stable runtime response contract. */\nfunction normalizeResponse(response: ApiHandlerResponse): ApiResponse {\n return {\n status: response.status ?? 200,\n headers: response.headers ?? {},\n ...(response.body === undefined ? {} : { body: response.body }),\n };\n}\n\n/*** Create one deterministic runtime error response. */\nfunction errorResponse(status: number, code: string, operationId: string): ApiResponse {\n return {\n status,\n headers: { 'content-type': 'application/json' },\n body: {\n error: {\n code,\n operationId,\n },\n },\n };\n}\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ApiOperationBinding, ApiRuntime, ApiTransportAdapter } from
|
|
1
|
+
import type { ApiOperationBinding, ApiRuntime, ApiTransportAdapter } from '../../types/api.js';
|
|
2
2
|
/*** Compose one framework adapter with the canonical runtime for a single operation binding. */
|
|
3
3
|
export declare function createApiTransportHandler<TRequest, TResponse>(runtime: ApiRuntime, adapter: ApiTransportAdapter<TRequest, TResponse>, binding: ApiOperationBinding): (request: TRequest) => Promise<TResponse>;
|
|
4
4
|
//# sourceMappingURL=createApiTransportHandler.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createApiTransportHandler.d.ts","sourceRoot":"","sources":["../../../src/features/execution/createApiTransportHandler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"createApiTransportHandler.d.ts","sourceRoot":"","sources":["../../../src/features/execution/createApiTransportHandler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,UAAU,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAE/F,gGAAgG;AAChG,wBAAgB,yBAAyB,CAAC,QAAQ,EAAE,SAAS,EAC3D,OAAO,EAAE,UAAU,EACnB,OAAO,EAAE,mBAAmB,CAAC,QAAQ,EAAE,SAAS,CAAC,EACjD,OAAO,EAAE,mBAAmB,GAC3B,CAAC,OAAO,EAAE,QAAQ,KAAK,OAAO,CAAC,SAAS,CAAC,CAM3C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createApiTransportHandler.js","sourceRoot":"","sources":["../../../src/features/execution/createApiTransportHandler.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"createApiTransportHandler.js","sourceRoot":"","sources":["../../../src/features/execution/createApiTransportHandler.ts"],"names":[],"mappings":"AAEA,gGAAgG;AAChG,MAAM,UAAU,yBAAyB,CACvC,OAAmB,EACnB,OAAiD,EACjD,OAA4B;IAE5B,OAAO,KAAK,EAAE,OAAO,EAAE,EAAE;QACvB,MAAM,UAAU,GAAG,MAAM,OAAO,CAAC,iBAAiB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QACrE,MAAM,WAAW,GAAG,MAAM,OAAO,CAAC,aAAa,CAAC,UAAU,CAAC,CAAC;QAC5D,OAAO,OAAO,CAAC,oBAAoB,CAAC,WAAW,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;IACrE,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import type { ApiOperationBinding, ApiRuntime, ApiTransportAdapter } from '../../types/api.js';\n\n/*** Compose one framework adapter with the canonical runtime for a single operation binding. */\nexport function createApiTransportHandler<TRequest, TResponse>(\n runtime: ApiRuntime,\n adapter: ApiTransportAdapter<TRequest, TResponse>,\n binding: ApiOperationBinding,\n): (request: TRequest) => Promise<TResponse> {\n return async (request) => {\n const apiRequest = await adapter.toApiRequestAsync(request, binding);\n const apiResponse = await runtime.dispatchAsync(apiRequest);\n return adapter.fromApiResponseAsync(apiResponse, request, binding);\n };\n}\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { CreateTrustedExternalApiBrokerOptions, TrustedExternalApiBroker } from
|
|
1
|
+
import type { CreateTrustedExternalApiBrokerOptions, TrustedExternalApiBroker } from '../../types/api.js';
|
|
2
2
|
/***
|
|
3
3
|
* Create a framework-neutral, fail-closed boundary for generated-app external API operations.
|
|
4
4
|
*
|
|
@@ -13,14 +13,14 @@ export function createTrustedExternalApiBroker(options) {
|
|
|
13
13
|
/*** Authorize before resolving any operation, credential, or outbound execution resource. */
|
|
14
14
|
async function executeTrustedOperationAsync(options, context, request) {
|
|
15
15
|
if (!isTrustedBrokerContext(context) || hasCallerSuppliedTarget(request)) {
|
|
16
|
-
return brokerErrorResponse(403,
|
|
16
|
+
return brokerErrorResponse(403, 'forbidden');
|
|
17
17
|
}
|
|
18
18
|
if (!(await isAuthorizedAsync(options, context, request))) {
|
|
19
|
-
return brokerErrorResponse(403,
|
|
19
|
+
return brokerErrorResponse(403, 'forbidden');
|
|
20
20
|
}
|
|
21
21
|
const operation = await resolveOperationAsync(options, context, request);
|
|
22
22
|
if (!operation)
|
|
23
|
-
return brokerErrorResponse(404,
|
|
23
|
+
return brokerErrorResponse(404, 'operation_not_found');
|
|
24
24
|
try {
|
|
25
25
|
const input = await options.validateInputAsync({
|
|
26
26
|
operation,
|
|
@@ -28,7 +28,7 @@ async function executeTrustedOperationAsync(options, context, request) {
|
|
|
28
28
|
});
|
|
29
29
|
const credentials = await resolveCredentialsAsync(options, context, operation);
|
|
30
30
|
if (operation.credentialsRequired === true && credentials === undefined) {
|
|
31
|
-
return brokerErrorResponse(424,
|
|
31
|
+
return brokerErrorResponse(424, 'credential_unavailable');
|
|
32
32
|
}
|
|
33
33
|
const result = await options.executeOperationAsync({
|
|
34
34
|
operation,
|
|
@@ -38,14 +38,18 @@ async function executeTrustedOperationAsync(options, context, request) {
|
|
|
38
38
|
return publicResponse(result.status, result.publicBody);
|
|
39
39
|
}
|
|
40
40
|
catch {
|
|
41
|
-
return brokerErrorResponse(502,
|
|
41
|
+
return brokerErrorResponse(502, 'external_operation_failed');
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
44
|
/*** Resolve a secret only for an operation whose trusted definition explicitly requires one. */
|
|
45
45
|
async function resolveCredentialsAsync(options, context, operation) {
|
|
46
46
|
if (operation.credentialsRequired !== true)
|
|
47
47
|
return undefined;
|
|
48
|
-
return options.resolveCredentialsAsync({
|
|
48
|
+
return options.resolveCredentialsAsync({
|
|
49
|
+
caller: context.caller,
|
|
50
|
+
scope: context.scope,
|
|
51
|
+
operation,
|
|
52
|
+
});
|
|
49
53
|
}
|
|
50
54
|
/*** Treat absent caller identity or incomplete project scope as a denial. */
|
|
51
55
|
function isTrustedBrokerContext(context) {
|
|
@@ -57,7 +61,7 @@ function isTrustedBrokerContext(context) {
|
|
|
57
61
|
}
|
|
58
62
|
/*** Reject target-selection fields that are never part of the broker's public request contract. */
|
|
59
63
|
function hasCallerSuppliedTarget(request) {
|
|
60
|
-
return [
|
|
64
|
+
return ['url', 'host', 'baseUrl', 'upstreamUrl', 'target'].some((key) => Object.hasOwn(request, key));
|
|
61
65
|
}
|
|
62
66
|
/*** Treat a missing, throwing, or false authorization decision as a denial. */
|
|
63
67
|
async function isAuthorizedAsync(options, context, request) {
|
|
@@ -75,8 +79,7 @@ async function resolveOperationAsync(options, context, request) {
|
|
|
75
79
|
scope: context.scope,
|
|
76
80
|
request,
|
|
77
81
|
});
|
|
78
|
-
return operation !== undefined &&
|
|
79
|
-
operationMatchesRequest(operation, request)
|
|
82
|
+
return operation !== undefined && operationMatchesRequest(operation, request)
|
|
80
83
|
? operation
|
|
81
84
|
: undefined;
|
|
82
85
|
}
|
|
@@ -102,7 +105,7 @@ function publicResponse(status, publicBody) {
|
|
|
102
105
|
function brokerErrorResponse(status, code) {
|
|
103
106
|
return {
|
|
104
107
|
status,
|
|
105
|
-
headers: {
|
|
108
|
+
headers: { 'content-type': 'application/json' },
|
|
106
109
|
body: { error: { code } },
|
|
107
110
|
};
|
|
108
111
|
}
|
|
@@ -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,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,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,OAAO,CAAC,CAAC;IACzE,IAAI,CAAC,SAAS;QAAE,OAAO,mBAAmB,CAAC,GAAG,EAAE,qBAAqB,CAAC,CAAC;IAEvE,IAAI,CAAC;QACH,MAAM,KAAK,GAAG,MAAM,OAAO,CAAC,kBAAkB,CAAC;YAC7C,SAAS;YACT,KAAK,EAAE,OAAO,CAAC,KAAK;SACrB,CAAC,CAAC;QACH,MAAM,WAAW,GAAG,MAAM,uBAAuB,
|
|
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,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,OAAO,CAAC,CAAC;IACzE,IAAI,CAAC,SAAS;QAAE,OAAO,mBAAmB,CAAC,GAAG,EAAE,qBAAqB,CAAC,CAAC;IAEvE,IAAI,CAAC;QACH,MAAM,KAAK,GAAG,MAAM,OAAO,CAAC,kBAAkB,CAAC;YAC7C,SAAS;YACT,KAAK,EAAE,OAAO,CAAC,KAAK;SACrB,CAAC,CAAC;QACH,MAAM,WAAW,GAAG,MAAM,uBAAuB,CAAC,OAAO,EAAE,OAAO,EAAE,SAAS,CAAC,CA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,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 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,5 +1,5 @@
|
|
|
1
|
-
import type { Capability } from
|
|
2
|
-
import type { InternalRestApiDefinition } from
|
|
1
|
+
import type { Capability } from '@ankhorage/contracts/capability';
|
|
2
|
+
import type { InternalRestApiDefinition } from '@ankhorage/contracts/data';
|
|
3
3
|
/*** Project one internal REST API definition into canonical invocable API capabilities. */
|
|
4
4
|
export declare function projectApiCapabilities(definition: InternalRestApiDefinition): readonly Capability[];
|
|
5
5
|
//# sourceMappingURL=projectApiCapabilities.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"projectApiCapabilities.d.ts","sourceRoot":"","sources":["../../../src/features/execution/projectApiCapabilities.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAClE,OAAO,KAAK,EAMV,yBAAyB,EAC1B,MAAM,2BAA2B,CAAC;AAEnC,2FAA2F;AAC3F,wBAAgB,sBAAsB,CACpC,UAAU,EAAE,yBAAyB,GACpC,SAAS,UAAU,EAAE,
|
|
1
|
+
{"version":3,"file":"projectApiCapabilities.d.ts","sourceRoot":"","sources":["../../../src/features/execution/projectApiCapabilities.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAClE,OAAO,KAAK,EAMV,yBAAyB,EAC1B,MAAM,2BAA2B,CAAC;AAEnC,2FAA2F;AAC3F,wBAAgB,sBAAsB,CACpC,UAAU,EAAE,yBAAyB,GACpC,SAAS,UAAU,EAAE,CASvB"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isCapabilityId } from
|
|
1
|
+
import { isCapabilityId } from '@ankhorage/capability';
|
|
2
2
|
/*** Project one internal REST API definition into canonical invocable API capabilities. */
|
|
3
3
|
export function projectApiCapabilities(definition) {
|
|
4
4
|
const capabilities = Object.values(definition.endpoints).flatMap((endpoint) => Object.values(endpoint.operations).map((operation) => projectApiOperationCapability(definition, operation)));
|
|
@@ -15,13 +15,11 @@ function projectApiOperationCapability(definition, operation) {
|
|
|
15
15
|
const output = projectSchemaSlot(operation.response);
|
|
16
16
|
return {
|
|
17
17
|
id,
|
|
18
|
-
owner:
|
|
19
|
-
access: [
|
|
20
|
-
binding: { kind:
|
|
18
|
+
owner: '@ankhorage/api',
|
|
19
|
+
access: ['invoke'],
|
|
20
|
+
binding: { kind: 'api', bindableAs: ['target'] },
|
|
21
21
|
label: operation.name ?? operation.id,
|
|
22
|
-
...(operation.description === undefined
|
|
23
|
-
? {}
|
|
24
|
-
: { description: operation.description }),
|
|
22
|
+
...(operation.description === undefined ? {} : { description: operation.description }),
|
|
25
23
|
...(input === undefined ? {} : { input }),
|
|
26
24
|
...(output === undefined ? {} : { output }),
|
|
27
25
|
};
|
|
@@ -33,9 +31,7 @@ function projectOperationInput(request) {
|
|
|
33
31
|
const bodySchema = projectSchemaSlotAsSchema(request);
|
|
34
32
|
const parameterSchema = projectOperationParameters(request.parameters);
|
|
35
33
|
if (bodySchema === undefined) {
|
|
36
|
-
return parameterSchema === undefined
|
|
37
|
-
? undefined
|
|
38
|
-
: { schema: parameterSchema };
|
|
34
|
+
return parameterSchema === undefined ? undefined : { schema: parameterSchema };
|
|
39
35
|
}
|
|
40
36
|
if (parameterSchema === undefined)
|
|
41
37
|
return projectSchemaSlot(request);
|
|
@@ -60,7 +56,7 @@ function projectOperationParameters(parameters) {
|
|
|
60
56
|
required.push(parameter.name);
|
|
61
57
|
}
|
|
62
58
|
return {
|
|
63
|
-
type:
|
|
59
|
+
type: 'object',
|
|
64
60
|
properties,
|
|
65
61
|
...(required.length === 0 ? {} : { required: [...required].sort() }),
|
|
66
62
|
};
|
|
@@ -70,9 +66,7 @@ function projectOperationParameterSchema(parameter) {
|
|
|
70
66
|
const schema = projectSchemaSlotAsSchema(parameter) ?? {};
|
|
71
67
|
return {
|
|
72
68
|
...schema,
|
|
73
|
-
...(parameter.description === undefined
|
|
74
|
-
? {}
|
|
75
|
-
: { description: parameter.description }),
|
|
69
|
+
...(parameter.description === undefined ? {} : { description: parameter.description }),
|
|
76
70
|
...(parameter.default === undefined ? {} : { default: parameter.default }),
|
|
77
71
|
};
|
|
78
72
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"projectApiCapabilities.js","sourceRoot":"","sources":["../../../src/features/execution/projectApiCapabilities.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAWvD,2FAA2F;AAC3F,MAAM,UAAU,sBAAsB,CACpC,UAAqC;IAErC,MAAM,YAAY,GAAG,MAAM,CAAC,MAAM,CAAC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C","sourcesContent":["import { isCapabilityId } from '@ankhorage/capability';\nimport type { Capability } from '@ankhorage/contracts/capability';\nimport type {\n DataOperationConfig,\n DataOperationParameter,\n DataOperationRequest,\n DataSchema,\n DataSchemaSlot,\n InternalRestApiDefinition,\n} from '@ankhorage/contracts/data';\n\n/*** Project one internal REST API definition into canonical invocable API capabilities. */\nexport function projectApiCapabilities(\n definition: InternalRestApiDefinition,\n): readonly Capability[] {\n const capabilities = Object.values(definition.endpoints).flatMap((endpoint) =>\n Object.values(endpoint.operations).map((operation) =>\n projectApiOperationCapability(definition, operation),\n ),\n );\n\n assertUniqueCapabilityIds(capabilities);\n return [...capabilities].sort((left, right) => left.id.localeCompare(right.id));\n}\n\n/*** Project one authored API operation into its stable semantic capability descriptor. */\nfunction projectApiOperationCapability(\n definition: InternalRestApiDefinition,\n operation: DataOperationConfig,\n): Capability {\n const id = `api.${definition.id}.${operation.id}`;\n if (!isCapabilityId(id)) {\n throw new Error(\n `API operation projects to an invalid capability id: ${definition.id} / ${operation.id}`,\n );\n }\n\n const input = projectOperationInput(operation.request);\n const output = projectSchemaSlot(operation.response);\n\n return {\n id,\n owner: '@ankhorage/api',\n access: ['invoke'],\n binding: { kind: 'api', bindableAs: ['target'] },\n label: operation.name ?? operation.id,\n ...(operation.description === undefined ? {} : { description: operation.description }),\n ...(input === undefined ? {} : { input }),\n ...(output === undefined ? {} : { output }),\n };\n}\n\n/*** Project request parameters and request body into the flat operation input value space. */\nfunction projectOperationInput(\n request: DataOperationRequest | undefined,\n): DataSchemaSlot | undefined {\n if (request === undefined) return undefined;\n\n const bodySchema = projectSchemaSlotAsSchema(request);\n const parameterSchema = projectOperationParameters(request.parameters);\n\n if (bodySchema === undefined) {\n return parameterSchema === undefined ? undefined : { schema: parameterSchema };\n }\n if (parameterSchema === undefined) return projectSchemaSlot(request);\n\n return {\n schema: {\n allOf: [bodySchema, parameterSchema],\n },\n };\n}\n\n/*** Project transport parameters into the flat object consumed by Runtime operation bindings. */\nfunction projectOperationParameters(\n parameters: readonly DataOperationParameter[] | undefined,\n): DataSchema | undefined {\n if (parameters === undefined || parameters.length === 0) return undefined;\n\n const properties: Record<string, DataSchema> = {};\n const required: string[] = [];\n for (const parameter of parameters) {\n if (Object.hasOwn(properties, parameter.name)) {\n throw new Error(`Duplicate API operation input parameter: ${parameter.name}`);\n }\n properties[parameter.name] = projectOperationParameterSchema(parameter);\n if (parameter.required === true) required.push(parameter.name);\n }\n\n return {\n type: 'object',\n properties,\n ...(required.length === 0 ? {} : { required: [...required].sort() }),\n };\n}\n\n/*** Preserve one parameter's schema reference plus parameter-specific description/default metadata. */\nfunction projectOperationParameterSchema(parameter: DataOperationParameter): DataSchema {\n const schema = projectSchemaSlotAsSchema(parameter) ?? {};\n return {\n ...schema,\n ...(parameter.description === undefined ? {} : { description: parameter.description }),\n ...(parameter.default === undefined ? {} : { default: parameter.default }),\n };\n}\n\n/*** Preserve exactly one portable schema slot when the operation already owns one. */\nfunction projectSchemaSlot(slot: DataSchemaSlot | undefined): DataSchemaSlot | undefined {\n if (slot?.schema !== undefined) return { schema: slot.schema };\n if (slot?.schemaRef !== undefined) return { schemaRef: slot.schemaRef };\n return undefined;\n}\n\n/*** Convert a schema slot to an embeddable schema while preserving authored schema references. */\nfunction projectSchemaSlotAsSchema(slot: DataSchemaSlot | undefined): DataSchema | undefined {\n if (slot?.schema !== undefined) return slot.schema;\n if (slot?.schemaRef !== undefined) return { ref: slot.schemaRef };\n return undefined;\n}\n\n/*** Reject API definitions whose endpoint operations collide in the projected capability namespace. */\nfunction assertUniqueCapabilityIds(capabilities: readonly Capability[]): void {\n const seen = new Set<Capability['id']>();\n for (const capability of capabilities) {\n if (seen.has(capability.id)) {\n throw new Error(`Duplicate projected API capability id: ${capability.id}`);\n }\n seen.add(capability.id);\n }\n}\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { InternalRestApiDefinition } from
|
|
2
|
-
import type { ApiOperationBinding } from
|
|
1
|
+
import type { InternalRestApiDefinition } from '@ankhorage/contracts/data';
|
|
2
|
+
import type { ApiOperationBinding } from '../../types/api.js';
|
|
3
3
|
/***
|
|
4
4
|
* Resolve one portable internal REST definition into deterministic executable operation bindings.
|
|
5
5
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolveApiOperationBindings.d.ts","sourceRoot":"","sources":["../../../src/features/execution/resolveApiOperationBindings.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"resolveApiOperationBindings.d.ts","sourceRoot":"","sources":["../../../src/features/execution/resolveApiOperationBindings.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAuB,yBAAyB,EAAE,MAAM,2BAA2B,CAAC;AAEhG,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAE9D;;GAEG;AACH,wBAAgB,2BAA2B,CACzC,UAAU,EAAE,yBAAyB,GACpC,SAAS,mBAAmB,EAAE,CAgBhC"}
|
|
@@ -19,24 +19,24 @@ export function resolveApiOperationBindings(definition) {
|
|
|
19
19
|
/*** Infer the conventional HTTP method for an operation intent when the contract omits one. */
|
|
20
20
|
function inferMethod(intent) {
|
|
21
21
|
switch (intent) {
|
|
22
|
-
case
|
|
23
|
-
return
|
|
24
|
-
case
|
|
25
|
-
return
|
|
26
|
-
case
|
|
27
|
-
return
|
|
28
|
-
case
|
|
29
|
-
return
|
|
22
|
+
case 'create':
|
|
23
|
+
return 'POST';
|
|
24
|
+
case 'delete':
|
|
25
|
+
return 'DELETE';
|
|
26
|
+
case 'read':
|
|
27
|
+
return 'GET';
|
|
28
|
+
case 'update':
|
|
29
|
+
return 'PATCH';
|
|
30
30
|
default:
|
|
31
|
-
return
|
|
31
|
+
return 'POST';
|
|
32
32
|
}
|
|
33
33
|
}
|
|
34
34
|
/*** Join API, endpoint, and operation paths into one normalized absolute route path. */
|
|
35
35
|
function joinRoutePath(...parts) {
|
|
36
36
|
const segments = parts
|
|
37
|
-
.filter((part) => typeof part ===
|
|
38
|
-
.flatMap((part) => part.split(
|
|
37
|
+
.filter((part) => typeof part === 'string')
|
|
38
|
+
.flatMap((part) => part.split('/'))
|
|
39
39
|
.filter(Boolean);
|
|
40
|
-
return
|
|
40
|
+
return '/' + segments.join('/');
|
|
41
41
|
}
|
|
42
42
|
//# sourceMappingURL=resolveApiOperationBindings.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolveApiOperationBindings.js","sourceRoot":"","sources":["../../../src/features/execution/resolveApiOperationBindings.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"resolveApiOperationBindings.js","sourceRoot":"","sources":["../../../src/features/execution/resolveApiOperationBindings.ts"],"names":[],"mappings":"AAIA;;GAEG;AACH,MAAM,UAAU,2BAA2B,CACzC,UAAqC;IAErC,OAAO,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,SAAS,CAAC;SACvC,OAAO,CAAC,CAAC,QAAQ,EAAE,EAAE,CACpB,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC,GAAG,CAAC,CAAC,SAAS,EAAE,EAAE;QACnD,MAAM,MAAM,GAAG,SAAS,CAAC,MAAM,IAAI,WAAW,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;QACjE,OAAO;YACL,UAAU;YACV,QAAQ;YACR,SAAS;YACT,WAAW,EAAE,SAAS,CAAC,EAAE;YACzB,MAAM;YACN,IAAI,EAAE,aAAa,CAAC,UAAU,CAAC,QAAQ,EAAE,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC,IAAI,CAAC;SAC1C,CAAC;IAClC,CAAC,CAAC,CACH;SACA,IAAI,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC,IAAI,CAAC,WAAW,CAAC,aAAa,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC,CAAC;AAC9E,CAAC;AAED,+FAA+F;AAC/F,SAAS,WAAW,CAAC,MAAc;IACjC,QAAQ,MAAM,EAAE,CAAC;QACf,KAAK,QAAQ;YACX,OAAO,MAAM,CAAC;QAChB,KAAK,QAAQ;YACX,OAAO,QAAQ,CAAC;QAClB,KAAK,MAAM;YACT,OAAO,KAAK,CAAC;QACf,KAAK,QAAQ;YACX,OAAO,OAAO,CAAC;QACjB;YACE,OAAO,MAAM,CAAC;IAClB,CAAC;AACH,CAAC;AAED,wFAAwF;AACxF,SAAS,aAAa,CAAC,GAAG,KAAsC;IAC9D,MAAM,QAAQ,GAAG,KAAK;SACnB,MAAM,CAAC,CAAC,IAAI,EAAkB,EAAE,CAAC,OAAO,IAAI,KAAK,QAAQ,CAAC;SAC1D,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;SAClC,MAAM,CAAC,OAAO,CAAC,CAAC;IACnB,OAAO,GAAG,GAAG,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAClC,CAAC","sourcesContent":["import type { DataOperationMethod, InternalRestApiDefinition } from '@ankhorage/contracts/data';\n\nimport type { ApiOperationBinding } from '../../types/api.js';\n\n/***\n * Resolve one portable internal REST definition into deterministic executable operation bindings.\n */\nexport function resolveApiOperationBindings(\n definition: InternalRestApiDefinition,\n): readonly ApiOperationBinding[] {\n return Object.values(definition.endpoints)\n .flatMap((endpoint) =>\n Object.values(endpoint.operations).map((operation) => {\n const method = operation.method ?? inferMethod(operation.intent);\n return {\n definition,\n endpoint,\n operation,\n operationId: operation.id,\n method,\n path: joinRoutePath(definition.basePath, endpoint.path, operation.path),\n } satisfies ApiOperationBinding;\n }),\n )\n .sort((left, right) => left.operationId.localeCompare(right.operationId));\n}\n\n/*** Infer the conventional HTTP method for an operation intent when the contract omits one. */\nfunction inferMethod(intent: string): DataOperationMethod {\n switch (intent) {\n case 'create':\n return 'POST';\n case 'delete':\n return 'DELETE';\n case 'read':\n return 'GET';\n case 'update':\n return 'PATCH';\n default:\n return 'POST';\n }\n}\n\n/*** Join API, endpoint, and operation paths into one normalized absolute route path. */\nfunction joinRoutePath(...parts: readonly (string | undefined)[]): string {\n const segments = parts\n .filter((part): part is string => typeof part === 'string')\n .flatMap((part) => part.split('/'))\n .filter(Boolean);\n return '/' + segments.join('/');\n}\n"]}
|
package/dist/types/api.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { Capability } from
|
|
2
|
-
import type { DataEndpointConfig, DataOperationConfig, DataOperationIntent, DataOperationMethod, InternalApiOperationHandlerDeclaration, InternalRestApiDefinition } from
|
|
1
|
+
import type { Capability } from '@ankhorage/contracts/capability';
|
|
2
|
+
import type { DataEndpointConfig, DataOperationConfig, DataOperationIntent, DataOperationMethod, InternalApiOperationHandlerDeclaration, InternalRestApiDefinition } from '@ankhorage/contracts/data';
|
|
3
3
|
export interface ApiOperationBinding {
|
|
4
4
|
readonly definition: InternalRestApiDefinition;
|
|
5
5
|
readonly endpoint: DataEndpointConfig;
|
|
@@ -52,7 +52,7 @@ export interface ApiHandlerApproval {
|
|
|
52
52
|
readonly operationId: string;
|
|
53
53
|
readonly intent: DataOperationIntent;
|
|
54
54
|
readonly method: DataOperationMethod;
|
|
55
|
-
readonly capabilityId: Capability[
|
|
55
|
+
readonly capabilityId: Capability['id'];
|
|
56
56
|
readonly owner: string;
|
|
57
57
|
readonly scope: ApiCompositionContext;
|
|
58
58
|
}
|
|
@@ -123,7 +123,7 @@ export interface CreateTrustedExternalApiBrokerOptions {
|
|
|
123
123
|
readonly request: TrustedExternalApiBrokerRequest;
|
|
124
124
|
}) => boolean | Promise<boolean>;
|
|
125
125
|
readonly resolveOperationAsync: (input: {
|
|
126
|
-
readonly scope: TrustedExternalApiBrokerContext[
|
|
126
|
+
readonly scope: TrustedExternalApiBrokerContext['scope'];
|
|
127
127
|
readonly request: TrustedExternalApiBrokerRequest;
|
|
128
128
|
}) => TrustedExternalApiOperation | undefined | Promise<TrustedExternalApiOperation | undefined>;
|
|
129
129
|
readonly validateInputAsync: (input: {
|
|
@@ -131,7 +131,8 @@ export interface CreateTrustedExternalApiBrokerOptions {
|
|
|
131
131
|
readonly input: unknown;
|
|
132
132
|
}) => unknown;
|
|
133
133
|
readonly resolveCredentialsAsync: (input: {
|
|
134
|
-
readonly
|
|
134
|
+
readonly caller: TrustedExternalApiBrokerContext['caller'];
|
|
135
|
+
readonly scope: TrustedExternalApiBrokerContext['scope'];
|
|
135
136
|
readonly operation: TrustedExternalApiOperation;
|
|
136
137
|
}) => TrustedExternalApiCredentials | undefined | Promise<TrustedExternalApiCredentials | undefined>;
|
|
137
138
|
readonly executeOperationAsync: (input: {
|
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,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;IAC7B,QAAQ,CAAC,MAAM,EAAE,mBAAmB,CAAC;IACrC,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IAClD,QAAQ,C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KAAK,EAAE,+BAA+B,CAAC,OAAO,CAAC,CAAC;QACzD,QAAQ,CAAC,SAAS,EAAE,2BAA2B,CAAC;KACjD,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,2BAA2B,CAAC;QAChD,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;QACxB,QAAQ,CAAC,WAAW,CAAC,EAAE,6BAA6B,CAAC;KACtD,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
|
|
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"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ankhorage/api",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Framework-neutral executable API runtime and transport contract for Ankhorage.",
|
|
6
6
|
"ankh": {
|
|
@@ -71,12 +71,12 @@
|
|
|
71
71
|
"@ankhorage/contracts": "^26.10.0"
|
|
72
72
|
},
|
|
73
73
|
"devDependencies": {
|
|
74
|
-
"@ankhorage/devtools": "^2.
|
|
74
|
+
"@ankhorage/devtools": "^2.12.5",
|
|
75
75
|
"@ankhorage/paradox": "^0.2.28",
|
|
76
76
|
"@ankhorage/projects": "^0.1.0",
|
|
77
|
-
"@types/bun": "^1.4.
|
|
77
|
+
"@types/bun": "^1.4.5",
|
|
78
78
|
"@types/node": "^26.6.4",
|
|
79
79
|
"typescript": "^6.0.3"
|
|
80
80
|
},
|
|
81
|
-
"packageManager": "bun@1.4.
|
|
81
|
+
"packageManager": "bun@1.4.5"
|
|
82
82
|
}
|