@ankhorage/api 0.4.0 → 0.5.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 +12 -0
- package/README.md +1 -1
- package/dist/api.d.ts +1 -1
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js.map +1 -1
- package/dist/features/execution/composeAuthorizedApiRuntime.d.ts +2 -2
- package/dist/features/execution/composeAuthorizedApiRuntime.d.ts.map +1 -1
- package/dist/features/execution/composeAuthorizedApiRuntime.js +87 -7
- package/dist/features/execution/composeAuthorizedApiRuntime.js.map +1 -1
- package/dist/types/api.d.ts +19 -2
- package/dist/types/api.d.ts.map +1 -1
- package/dist/types/api.js.map +1 -1
- package/package.json +5 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @ankhorage/api
|
|
2
2
|
|
|
3
|
+
## 0.5.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 6aa2056: Add canonical repository metadata.
|
|
8
|
+
|
|
9
|
+
## 0.5.0
|
|
10
|
+
|
|
11
|
+
### Minor Changes
|
|
12
|
+
|
|
13
|
+
- aff38ca: Resolve declared internal API operation capabilities through host-approved executable owner handlers before exposing routes.
|
|
14
|
+
|
|
3
15
|
## 0.4.0
|
|
4
16
|
|
|
5
17
|
### Minor Changes
|
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
|
|
package/dist/api.d.ts
CHANGED
|
@@ -4,5 +4,5 @@ export { createApiRuntime } from "./features/execution/createApiRuntime.js";
|
|
|
4
4
|
export { createApiTransportHandler } from "./features/execution/createApiTransportHandler.js";
|
|
5
5
|
export { projectApiCapabilities } from "./features/execution/projectApiCapabilities.js";
|
|
6
6
|
export { resolveApiOperationBindings } from "./features/execution/resolveApiOperationBindings.js";
|
|
7
|
-
export type { ApiAuthorizationPolicy, ApiAuthorizationRequest, ApiCompositionContext, ApiHandler, ApiHandlerContext, ApiHandlerRegistry, ApiHandlerResolutionRequest, ApiHandlerResolver, ApiHandlerResponse, ApiOperationBinding, ApiRequest, ApiResponse, ApiRuntime, ApiTransportAdapter, ComposeAuthorizedApiRuntimeOptions, } from "./types/api.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
8
|
//# 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,sBAAsB,EACtB,uBAAuB,EACvB,qBAAqB,EACrB,UAAU,EACV,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,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"}
|
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 ApiAuthorizationPolicy,\n ApiAuthorizationRequest,\n ApiCompositionContext,\n ApiHandler,\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,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,6 +1,6 @@
|
|
|
1
|
-
import type { ComposeAuthorizedApiRuntimeOptions } from "../../types/api.js";
|
|
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
|
*/
|
|
5
|
-
export declare function composeAuthorizedApiRuntime(options: ComposeAuthorizedApiRuntimeOptions):
|
|
5
|
+
export declare function composeAuthorizedApiRuntime(options: ComposeAuthorizedApiRuntimeOptions): ApiRuntime;
|
|
6
6
|
//# sourceMappingURL=composeAuthorizedApiRuntime.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"composeAuthorizedApiRuntime.d.ts","sourceRoot":"","sources":["../../../src/features/execution/composeAuthorizedApiRuntime.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"composeAuthorizedApiRuntime.d.ts","sourceRoot":"","sources":["../../../src/features/execution/composeAuthorizedApiRuntime.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAMV,UAAU,EACV,kCAAkC,EACnC,MAAM,oBAAoB,CAAC;AAI5B;;GAEG;AACH,wBAAgB,2BAA2B,CACzC,OAAO,EAAE,kCAAkC,GAC1C,UAAU,CAKZ"}
|
|
@@ -10,27 +10,107 @@ export function composeAuthorizedApiRuntime(options) {
|
|
|
10
10
|
}
|
|
11
11
|
/*** Resolve every declared operation before exposing the API runtime. */
|
|
12
12
|
function resolveAuthorizedHandlers(options) {
|
|
13
|
+
const declarations = resolveHandlerDeclarations(options.definition);
|
|
13
14
|
return Object.fromEntries(resolveApiOperationBindings(options.definition).map((binding) => {
|
|
14
|
-
const
|
|
15
|
+
const declaration = declarations.get(binding.operationId);
|
|
16
|
+
if (!declaration) {
|
|
17
|
+
throw new Error(`No declared handler targets API operation ${binding.operationId}.`);
|
|
18
|
+
}
|
|
19
|
+
const approvedHandler = options.resolveHandler({
|
|
15
20
|
binding,
|
|
21
|
+
declaration,
|
|
16
22
|
context: options.context,
|
|
17
23
|
});
|
|
18
|
-
|
|
19
|
-
throw new Error(`No approved handler is registered for API operation ${binding.operationId}.`);
|
|
20
|
-
}
|
|
24
|
+
assertApprovedHandler(binding, declaration.capability, options.context, approvedHandler);
|
|
21
25
|
return [
|
|
22
26
|
binding.operationId,
|
|
23
|
-
createAuthorizedHandler(binding,
|
|
27
|
+
createAuthorizedHandler(binding, approvedHandler, options),
|
|
24
28
|
];
|
|
25
29
|
}));
|
|
26
30
|
}
|
|
31
|
+
/*** Resolve one exact declared capability target for every executable API operation. */
|
|
32
|
+
function resolveHandlerDeclarations(definition) {
|
|
33
|
+
const bindings = resolveApiOperationBindings(definition);
|
|
34
|
+
const bindingIds = new Set(bindings.map((binding) => binding.operationId));
|
|
35
|
+
if (bindingIds.size !== bindings.length) {
|
|
36
|
+
throw new Error("API definition declares duplicate endpoint operation ids.");
|
|
37
|
+
}
|
|
38
|
+
const declarations = Object.entries(definition.handlers ?? {});
|
|
39
|
+
const declaredOperationIds = new Set();
|
|
40
|
+
const declaredCapabilityIds = new Set();
|
|
41
|
+
for (const [registryOperationId, declaration] of declarations) {
|
|
42
|
+
if (registryOperationId !== declaration.operationId) {
|
|
43
|
+
throw new Error(`Handler declaration key does not match its operation id: ${registryOperationId}.`);
|
|
44
|
+
}
|
|
45
|
+
if (!bindingIds.has(declaration.operationId)) {
|
|
46
|
+
throw new Error(`Handler declaration targets unknown API operation ${declaration.operationId}.`);
|
|
47
|
+
}
|
|
48
|
+
if (declaredOperationIds.has(declaration.operationId)) {
|
|
49
|
+
throw new Error(`Duplicate handler declaration for API operation ${declaration.operationId}.`);
|
|
50
|
+
}
|
|
51
|
+
if (declaredCapabilityIds.has(declaration.capability)) {
|
|
52
|
+
throw new Error(`Duplicate handler declaration for capability ${declaration.capability}.`);
|
|
53
|
+
}
|
|
54
|
+
declaredOperationIds.add(declaration.operationId);
|
|
55
|
+
declaredCapabilityIds.add(declaration.capability);
|
|
56
|
+
}
|
|
57
|
+
if (declaredOperationIds.size !== bindingIds.size) {
|
|
58
|
+
throw new Error("Every API operation requires exactly one handler declaration.");
|
|
59
|
+
}
|
|
60
|
+
return new Map(declarations.map(([, declaration]) => [
|
|
61
|
+
declaration.operationId,
|
|
62
|
+
declaration,
|
|
63
|
+
]));
|
|
64
|
+
}
|
|
65
|
+
/*** Reject a handler unless the host-approved owner capability exactly matches the declaration. */
|
|
66
|
+
function assertApprovedHandler(binding, capabilityId, context, approvedHandler) {
|
|
67
|
+
if (!approvedHandler || typeof approvedHandler.handler !== "function") {
|
|
68
|
+
throw new Error(`No approved handler is registered for API operation ${binding.operationId}.`);
|
|
69
|
+
}
|
|
70
|
+
if (approvedHandler.capability.id !== capabilityId) {
|
|
71
|
+
throw new Error(`Approved handler capability does not match API operation ${binding.operationId}.`);
|
|
72
|
+
}
|
|
73
|
+
if (!approvedHandler.capability.owner.trim()) {
|
|
74
|
+
throw new Error(`Approved handler has no owner for API operation ${binding.operationId}.`);
|
|
75
|
+
}
|
|
76
|
+
if (approvedHandler.approval.operationId !== binding.operationId ||
|
|
77
|
+
approvedHandler.approval.intent !== binding.operation.intent ||
|
|
78
|
+
approvedHandler.approval.method !== binding.method ||
|
|
79
|
+
approvedHandler.approval.capabilityId !== capabilityId ||
|
|
80
|
+
approvedHandler.approval.owner !== approvedHandler.capability.owner ||
|
|
81
|
+
approvedHandler.approval.scope.appId !== context.appId ||
|
|
82
|
+
approvedHandler.approval.scope.projectId !== context.projectId) {
|
|
83
|
+
throw new Error(`Approved handler does not authorize API operation ${binding.operationId}.`);
|
|
84
|
+
}
|
|
85
|
+
const requiredAccess = accessForIntent(binding.operation.intent);
|
|
86
|
+
if (!approvedHandler.capability.access.includes(requiredAccess)) {
|
|
87
|
+
throw new Error(`Approved handler does not grant ${requiredAccess} access for API operation ${binding.operationId}.`);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
/*** Resolve the one capability access verb that may execute a declared API intent. */
|
|
91
|
+
function accessForIntent(intent) {
|
|
92
|
+
switch (intent) {
|
|
93
|
+
case "action":
|
|
94
|
+
return "invoke";
|
|
95
|
+
case "read":
|
|
96
|
+
return "read";
|
|
97
|
+
case "create":
|
|
98
|
+
case "delete":
|
|
99
|
+
case "update":
|
|
100
|
+
return "write";
|
|
101
|
+
}
|
|
102
|
+
}
|
|
27
103
|
/*** Deny a request unless the host authorization policy explicitly approves it. */
|
|
28
|
-
function createAuthorizedHandler(binding,
|
|
104
|
+
function createAuthorizedHandler(binding, approvedHandler, options) {
|
|
29
105
|
return async (request) => {
|
|
30
106
|
const authorized = await isAuthorizedAsync(binding, request, options);
|
|
31
107
|
if (!authorized)
|
|
32
108
|
return forbiddenResponse(binding.operationId);
|
|
33
|
-
return handler(request, {
|
|
109
|
+
return approvedHandler.handler(request, {
|
|
110
|
+
binding,
|
|
111
|
+
composition: options.context,
|
|
112
|
+
capability: approvedHandler.capability,
|
|
113
|
+
});
|
|
34
114
|
};
|
|
35
115
|
}
|
|
36
116
|
/*** Treat a failing authorization policy exactly like an explicit denial. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"composeAuthorizedApiRuntime.js","sourceRoot":"","sources":["../../../src/features/execution/composeAuthorizedApiRuntime.ts"],"names":[],"mappings":"AAOA,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;IAE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EAAE,OAAO,CAAC,OAAO;YACxB,OAAO;SACR,CAAC,CAAC;IACL,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC;AAED,oFAAoF;AACpF,SAAS,wBAAwB,CAC/B,OAAsD;IAEtD,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,IAAI,EAAE,EAAE,CAAC;QACvD,MAAM,IAAI,KAAK,CACb,oEAAoE,CACrE,CAAC;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 ApiHandler,\n ApiHandlerRegistry,\n ApiOperationBinding,\n ApiResponse,\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) {\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 return Object.fromEntries(\n resolveApiOperationBindings(options.definition).map((binding) => {\n const handler = options.resolveHandler({\n binding,\n context: options.context,\n });\n if (!handler) {\n throw new Error(\n `No approved handler is registered for API operation ${binding.operationId}.`,\n );\n }\n\n return [\n binding.operationId,\n createAuthorizedHandler(binding, handler, options),\n ];\n }),\n );\n}\n\n/*** Deny a request unless the host authorization policy explicitly approves it. */\nfunction createAuthorizedHandler(\n binding: ApiOperationBinding,\n handler: ApiHandler,\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 handler(request, { binding, composition: options.context });\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,EAA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O;SACR,CAAC,CAAC;IACL,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC;AAED,oFAAoF;AACpF,SAAS,wBAAwB,CAC/B,OAAsD;IAEtD,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,IAAI,EAAE,EAAE,CAAC;QACvD,MAAM,IAAI,KAAK,CACb,oEAAoE,CACrE,CAAC;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"]}
|
package/dist/types/api.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Capability } from "@ankhorage/contracts/capability";
|
|
2
|
+
import type { DataEndpointConfig, DataOperationConfig, DataOperationIntent, DataOperationMethod, InternalApiOperationHandlerDeclaration, InternalRestApiDefinition } from "@ankhorage/contracts/data";
|
|
2
3
|
export interface ApiOperationBinding {
|
|
3
4
|
readonly definition: InternalRestApiDefinition;
|
|
4
5
|
readonly endpoint: DataEndpointConfig;
|
|
@@ -28,6 +29,7 @@ export interface ApiResponse {
|
|
|
28
29
|
export interface ApiHandlerContext {
|
|
29
30
|
readonly binding: ApiOperationBinding;
|
|
30
31
|
readonly composition?: ApiCompositionContext;
|
|
32
|
+
readonly capability?: Capability;
|
|
31
33
|
}
|
|
32
34
|
export type ApiHandler = (request: ApiRequest, context: ApiHandlerContext) => ApiHandlerResponse | Promise<ApiHandlerResponse>;
|
|
33
35
|
export type ApiHandlerRegistry = Readonly<Record<string, ApiHandler>>;
|
|
@@ -37,9 +39,24 @@ export interface ApiCompositionContext {
|
|
|
37
39
|
}
|
|
38
40
|
export interface ApiHandlerResolutionRequest {
|
|
39
41
|
readonly binding: ApiOperationBinding;
|
|
42
|
+
readonly declaration: InternalApiOperationHandlerDeclaration;
|
|
40
43
|
readonly context: ApiCompositionContext;
|
|
41
44
|
}
|
|
42
|
-
export
|
|
45
|
+
export interface ApiApprovedHandler {
|
|
46
|
+
readonly capability: Capability;
|
|
47
|
+
readonly approval: ApiHandlerApproval;
|
|
48
|
+
readonly handler: ApiHandler;
|
|
49
|
+
}
|
|
50
|
+
/*** Bind one host-approved owner handler to its exact API operation and application scope. */
|
|
51
|
+
export interface ApiHandlerApproval {
|
|
52
|
+
readonly operationId: string;
|
|
53
|
+
readonly intent: DataOperationIntent;
|
|
54
|
+
readonly method: DataOperationMethod;
|
|
55
|
+
readonly capabilityId: Capability["id"];
|
|
56
|
+
readonly owner: string;
|
|
57
|
+
readonly scope: ApiCompositionContext;
|
|
58
|
+
}
|
|
59
|
+
export type ApiHandlerResolver = (request: ApiHandlerResolutionRequest) => ApiApprovedHandler | undefined;
|
|
43
60
|
export interface ApiAuthorizationRequest {
|
|
44
61
|
readonly binding: ApiOperationBinding;
|
|
45
62
|
readonly context: ApiCompositionContext;
|
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,EACV,kBAAkB,EAClB,mBAAmB,EACnB,mBAAmB,EACnB,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;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Root":"","sources":["../../src/types/api.ts"],"names":[],"mappings":"","sourcesContent":["import type {\n DataEndpointConfig,\n DataOperationConfig,\n DataOperationMethod,\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}\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 context: ApiCompositionContext;\n}\n\nexport type ApiHandlerResolver = (\n request: ApiHandlerResolutionRequest,\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"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ankhorage/api",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Framework-neutral executable API runtime and transport contract for Ankhorage.",
|
|
6
6
|
"license": "MIT",
|
|
@@ -63,14 +63,15 @@
|
|
|
63
63
|
},
|
|
64
64
|
"dependencies": {
|
|
65
65
|
"@ankhorage/capability": "^0.2.1",
|
|
66
|
-
"@ankhorage/contracts": "^26.
|
|
66
|
+
"@ankhorage/contracts": "^26.10.0"
|
|
67
67
|
},
|
|
68
68
|
"devDependencies": {
|
|
69
69
|
"@ankhorage/devtools": "^2.1.11",
|
|
70
|
+
"@ankhorage/paradox": "^0.2.28",
|
|
71
|
+
"@ankhorage/projects": "^0.1.0",
|
|
70
72
|
"@types/bun": "^1.4.2",
|
|
71
73
|
"@types/node": "^26.6.4",
|
|
72
|
-
"typescript": "^6.0.3"
|
|
73
|
-
"@ankhorage/paradox": "^0.2.28"
|
|
74
|
+
"typescript": "^6.0.3"
|
|
74
75
|
},
|
|
75
76
|
"packageManager": "bun@1.4.2"
|
|
76
77
|
}
|