@ankhorage/api 0.3.1 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @ankhorage/api
2
2
 
3
+ ## 0.4.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 0581f54: Compose manifest-declared API operations with approved handlers, explicit app/project scope, and fail-closed authorization.
8
+
3
9
  ## 0.3.1
4
10
 
5
11
  ### Patch Changes
package/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
 
4
4
  # @ankhorage/api
5
5
 
6
- ![license: MIT](././paradox/badges/license.svg) ![npm: v0.3.1](././paradox/badges/npm.svg) ![runtime: bun](././paradox/badges/runtime.svg) ![typescript: strict](././paradox/badges/typescript.svg) ![eslint: checked](././paradox/badges/eslint.svg) ![prettier: checked](././paradox/badges/prettier.svg) ![build: checked](././paradox/badges/build.svg) ![tests: checked](././paradox/badges/tests.svg) ![paradox: canonical](././paradox/badges/docs.svg)
6
+ ![license: MIT](././paradox/badges/license.svg) ![npm: v0.4.0](././paradox/badges/npm.svg) ![runtime: bun](././paradox/badges/runtime.svg) ![typescript: strict](././paradox/badges/typescript.svg) ![eslint: checked](././paradox/badges/eslint.svg) ![prettier: checked](././paradox/badges/prettier.svg) ![build: checked](././paradox/badges/build.svg) ![tests: checked](././paradox/badges/tests.svg) ![paradox: canonical](././paradox/badges/docs.svg)
7
7
 
8
8
  Framework-neutral executable API runtime for Ankhorage.
9
9
 
@@ -59,5 +59,6 @@ const definition = {
59
59
  - [Architecture overview](././paradox/diagrams/architecture-overview.mmd)
60
60
  - [Module relationships](././paradox/diagrams/module-relationships.mmd)
61
61
  - [Export graph](././paradox/diagrams/export-graph.mmd)
62
+ - [composeAuthorizedApiRuntime sequence](././paradox/diagrams/sequences/compose-authorized-api-runtime.mmd)
62
63
  - [createApiRuntime sequence](././paradox/diagrams/sequences/create-api-runtime.mmd)
63
64
  - [projectApiCapabilities sequence](././paradox/diagrams/sequences/project-api-capabilities.mmd)
package/dist/api.d.ts CHANGED
@@ -1,7 +1,8 @@
1
1
  export { CAPABILITIES } from "./capabilities/index.js";
2
+ export { composeAuthorizedApiRuntime } from "./features/execution/composeAuthorizedApiRuntime.js";
2
3
  export { createApiRuntime } from "./features/execution/createApiRuntime.js";
3
4
  export { createApiTransportHandler } from "./features/execution/createApiTransportHandler.js";
4
5
  export { projectApiCapabilities } from "./features/execution/projectApiCapabilities.js";
5
6
  export { resolveApiOperationBindings } from "./features/execution/resolveApiOperationBindings.js";
6
- export type { ApiHandler, ApiHandlerContext, ApiHandlerRegistry, ApiHandlerResponse, ApiOperationBinding, ApiRequest, ApiResponse, ApiRuntime, ApiTransportAdapter, } from "./types/api.js";
7
+ export type { ApiAuthorizationPolicy, ApiAuthorizationRequest, ApiCompositionContext, ApiHandler, ApiHandlerContext, ApiHandlerRegistry, ApiHandlerResolutionRequest, ApiHandlerResolver, ApiHandlerResponse, ApiOperationBinding, ApiRequest, ApiResponse, ApiRuntime, ApiTransportAdapter, ComposeAuthorizedApiRuntimeOptions, } from "./types/api.js";
7
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,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,UAAU,EACV,iBAAiB,EACjB,kBAAkB,EAClB,kBAAkB,EAClB,mBAAmB,EACnB,UAAU,EACV,WAAW,EACX,UAAU,EACV,mBAAmB,GACpB,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,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"}
package/dist/api.js CHANGED
@@ -1,4 +1,5 @@
1
1
  export { CAPABILITIES } from "./capabilities/index.js";
2
+ export { composeAuthorizedApiRuntime } from "./features/execution/composeAuthorizedApiRuntime.js";
2
3
  export { createApiRuntime } from "./features/execution/createApiRuntime.js";
3
4
  export { createApiTransportHandler } from "./features/execution/createApiTransportHandler.js";
4
5
  export { projectApiCapabilities } from "./features/execution/projectApiCapabilities.js";
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,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 { 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 ApiHandler,\n ApiHandlerContext,\n ApiHandlerRegistry,\n ApiHandlerResponse,\n ApiOperationBinding,\n ApiRequest,\n ApiResponse,\n ApiRuntime,\n ApiTransportAdapter,\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 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"]}
@@ -0,0 +1,6 @@
1
+ import type { ComposeAuthorizedApiRuntimeOptions } from "../../types/api.js";
2
+ /***
3
+ * Compose declared API operations with host-approved handlers and deny-by-default authorization.
4
+ */
5
+ export declare function composeAuthorizedApiRuntime(options: ComposeAuthorizedApiRuntimeOptions): import("../../api.js").ApiRuntime;
6
+ //# sourceMappingURL=composeAuthorizedApiRuntime.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"composeAuthorizedApiRuntime.d.ts","sourceRoot":"","sources":["../../../src/features/execution/composeAuthorizedApiRuntime.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAKV,kCAAkC,EACnC,MAAM,oBAAoB,CAAC;AAI5B;;GAEG;AACH,wBAAgB,2BAA2B,CACzC,OAAO,EAAE,kCAAkC,qCAM5C"}
@@ -0,0 +1,63 @@
1
+ import { createApiRuntime } from "./createApiRuntime.js";
2
+ import { resolveApiOperationBindings } from "./resolveApiOperationBindings.js";
3
+ /***
4
+ * Compose declared API operations with host-approved handlers and deny-by-default authorization.
5
+ */
6
+ export function composeAuthorizedApiRuntime(options) {
7
+ assertCompositionContext(options.context);
8
+ const handlers = resolveAuthorizedHandlers(options);
9
+ return createApiRuntime({ definition: options.definition, handlers });
10
+ }
11
+ /*** Resolve every declared operation before exposing the API runtime. */
12
+ function resolveAuthorizedHandlers(options) {
13
+ return Object.fromEntries(resolveApiOperationBindings(options.definition).map((binding) => {
14
+ const handler = options.resolveHandler({
15
+ binding,
16
+ context: options.context,
17
+ });
18
+ if (!handler) {
19
+ throw new Error(`No approved handler is registered for API operation ${binding.operationId}.`);
20
+ }
21
+ return [
22
+ binding.operationId,
23
+ createAuthorizedHandler(binding, handler, options),
24
+ ];
25
+ }));
26
+ }
27
+ /*** Deny a request unless the host authorization policy explicitly approves it. */
28
+ function createAuthorizedHandler(binding, handler, options) {
29
+ return async (request) => {
30
+ const authorized = await isAuthorizedAsync(binding, request, options);
31
+ if (!authorized)
32
+ return forbiddenResponse(binding.operationId);
33
+ return handler(request, { binding, composition: options.context });
34
+ };
35
+ }
36
+ /*** Treat a failing authorization policy exactly like an explicit denial. */
37
+ async function isAuthorizedAsync(binding, request, options) {
38
+ try {
39
+ return await options.authorizeAsync({
40
+ binding,
41
+ context: options.context,
42
+ request,
43
+ });
44
+ }
45
+ catch {
46
+ return false;
47
+ }
48
+ }
49
+ /*** Reject incomplete composition scope before any HTTP route can be registered. */
50
+ function assertCompositionContext(context) {
51
+ if (!context.appId.trim() || !context.projectId.trim()) {
52
+ throw new Error("Authorized API composition requires non-empty app and project ids.");
53
+ }
54
+ }
55
+ /*** Return a normalized authorization failure without invoking the selected handler. */
56
+ function forbiddenResponse(operationId) {
57
+ return {
58
+ status: 403,
59
+ headers: { "content-type": "application/json" },
60
+ body: { error: { code: "forbidden", operationId } },
61
+ };
62
+ }
63
+ //# sourceMappingURL=composeAuthorizedApiRuntime.js.map
@@ -0,0 +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;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,OAAO,MAAM,CAAC,WAAW,CACvB,2BAA2B,C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O,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"]}
@@ -27,9 +27,31 @@ export interface ApiResponse {
27
27
  }
28
28
  export interface ApiHandlerContext {
29
29
  readonly binding: ApiOperationBinding;
30
+ readonly composition?: ApiCompositionContext;
30
31
  }
31
32
  export type ApiHandler = (request: ApiRequest, context: ApiHandlerContext) => ApiHandlerResponse | Promise<ApiHandlerResponse>;
32
33
  export type ApiHandlerRegistry = Readonly<Record<string, ApiHandler>>;
34
+ export interface ApiCompositionContext {
35
+ readonly appId: string;
36
+ readonly projectId: string;
37
+ }
38
+ export interface ApiHandlerResolutionRequest {
39
+ readonly binding: ApiOperationBinding;
40
+ readonly context: ApiCompositionContext;
41
+ }
42
+ export type ApiHandlerResolver = (request: ApiHandlerResolutionRequest) => ApiHandler | undefined;
43
+ export interface ApiAuthorizationRequest {
44
+ readonly binding: ApiOperationBinding;
45
+ readonly context: ApiCompositionContext;
46
+ readonly request: ApiRequest;
47
+ }
48
+ export type ApiAuthorizationPolicy = (request: ApiAuthorizationRequest) => boolean | Promise<boolean>;
49
+ export interface ComposeAuthorizedApiRuntimeOptions {
50
+ readonly definition: InternalRestApiDefinition;
51
+ readonly context: ApiCompositionContext;
52
+ readonly resolveHandler: ApiHandlerResolver;
53
+ readonly authorizeAsync: ApiAuthorizationPolicy;
54
+ }
33
55
  export interface ApiRuntime {
34
56
  readonly definition: InternalRestApiDefinition;
35
57
  readonly bindings: readonly ApiOperationBinding[];
@@ -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;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,CAAC,KAAK,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,MAAM,EAAE,CAAC,CAAC,CAAC;IACrE,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IACnD,QAAQ,CAAC,IAAI,CAAC,EAAE,OAAO,CAAC;CACzB;AAED,MAAM,WAAW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AAQ,CAAC,UAAU,EAAE,yBAAyB,CAAC;IAC/C,QAAQ,CAAC,OAAO,EAAE,qBAAqB,CAAC;IACxC,QAAQ,CAAC,cAAc,EAAE,kBAAkB,CAAC;IAC5C,QAAQ,CAAC,cAAc,EAAE,sBAAsB,CAAC;CACjD;AAED,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,UAAU,EAAE,yBAAyB,CAAC;IAC/C,QAAQ,CAAC,QAAQ,EAAE,SAAS,mBAAmB,EAAE,CAAC;IAClD,aAAa,CAAC,OAAO,EAAE,UAAU,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC;IACzD,UAAU,CAAC,WAAW,EAAE,MAAM,GAAG,mBAAmB,GAAG,SAAS,CAAC;CAClE;AAED,MAAM,WAAW,mBAAmB,CAAC,QAAQ,EAAE,SAAS;IACtD,iBAAiB,CACf,OAAO,EAAE,QAAQ,EACjB,OAAO,EAAE,mBAAmB,GAC3B,OAAO,CAAC,UAAU,CAAC,CAAC;IACvB,oBAAoB,CAClB,QAAQ,EAAE,WAAW,EACrB,OAAO,EAAE,QAAQ,EACjB,OAAO,EAAE,mBAAmB,GAC3B,OAAO,CAAC,SAAS,CAAC,CAAC;CACvB"}
@@ -1 +1 @@
1
- {"version":3,"file":"api.js","sourceRoot":"","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}\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 ApiRuntime {\n readonly definition: InternalRestApiDefinition;\n readonly bindings: readonly ApiOperationBinding[];\n dispatchAsync(request: ApiRequest): Promise<ApiResponse>;\n getBinding(operationId: string): ApiOperationBinding | undefined;\n}\n\nexport interface ApiTransportAdapter<TRequest, TResponse> {\n toApiRequestAsync(\n request: TRequest,\n binding: ApiOperationBinding,\n ): Promise<ApiRequest>;\n fromApiResponseAsync(\n response: ApiResponse,\n request: TRequest,\n binding: ApiOperationBinding,\n ): Promise<TResponse>;\n}\n"]}
1
+ {"version":3,"file":"api.js","sourceRoot":"","sources":["../../src/types/api.ts"],"names":[],"mappings":"","sourcesContent":["import type {\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) => ApiHandler | 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.1",
3
+ "version": "0.4.0",
4
4
  "type": "module",
5
5
  "description": "Framework-neutral executable API runtime and transport contract for Ankhorage.",
6
6
  "license": "MIT",