@aep-foundation/hono 0.1.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 +17 -0
- package/LICENSE +21 -0
- package/README.md +7 -0
- package/dist/index.cjs +106 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +33 -0
- package/dist/index.d.ts +33 -0
- package/dist/index.js +75 -0
- package/dist/index.js.map +1 -0
- package/package.json +54 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# @aep-foundation/hono
|
|
2
|
+
|
|
3
|
+
## 0.1.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#1](https://github.com/aep-foundation/aep-node/pull/1) [`3d4713e`](https://github.com/aep-foundation/aep-node/commit/3d4713e2a9cf85478a415192c7c0abc90c374073) Thanks [@nkavian](https://github.com/nkavian)! - Add the initial AEP Node SDK packages, framework adapters, and conformance helpers.
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- Updated dependencies [[`3d4713e`](https://github.com/aep-foundation/aep-node/commit/3d4713e2a9cf85478a415192c7c0abc90c374073)]:
|
|
12
|
+
- @aep-foundation/core@0.1.0
|
|
13
|
+
- @aep-foundation/service@0.1.0
|
|
14
|
+
|
|
15
|
+
## 0.0.0
|
|
16
|
+
|
|
17
|
+
Initial development version.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 AEP Foundation
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
# @aep-foundation/hono
|
|
2
|
+
|
|
3
|
+
Thin Hono adapter for `@aep-foundation/service`.
|
|
4
|
+
|
|
5
|
+
`registerHonoAepRoute()` registers only the Inspect route. Use
|
|
6
|
+
`registerHonoAepRoutes()` to register Inspect plus Enroll, Status, Grant, and
|
|
7
|
+
Revoke command routes from the Service Inspect metadata.
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
AEP_HONO_MEDIA_TYPE: () => AEP_HONO_MEDIA_TYPE,
|
|
24
|
+
AEP_HONO_WELL_KNOWN_PATH: () => AEP_HONO_WELL_KNOWN_PATH,
|
|
25
|
+
createHonoAepHandler: () => createHonoAepHandler,
|
|
26
|
+
createHonoAepHandlers: () => createHonoAepHandlers,
|
|
27
|
+
packageName: () => packageName,
|
|
28
|
+
registerHonoAepRoute: () => registerHonoAepRoute,
|
|
29
|
+
registerHonoAepRoutes: () => registerHonoAepRoutes
|
|
30
|
+
});
|
|
31
|
+
module.exports = __toCommonJS(index_exports);
|
|
32
|
+
var import_core = require("@aep-foundation/core");
|
|
33
|
+
var import_service = require("@aep-foundation/service");
|
|
34
|
+
var packageName = "@aep-foundation/hono";
|
|
35
|
+
var AEP_HONO_WELL_KNOWN_PATH = "/.well-known/aep";
|
|
36
|
+
var AEP_HONO_MEDIA_TYPE = "application/aep+json";
|
|
37
|
+
function createHonoAepHandler(input) {
|
|
38
|
+
const service = resolveService(input);
|
|
39
|
+
return (context) => context.json(service.inspectDocument(), 200, {
|
|
40
|
+
"Content-Type": AEP_HONO_MEDIA_TYPE
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
function createHonoAepHandlers(input) {
|
|
44
|
+
const service = resolveService(input);
|
|
45
|
+
return {
|
|
46
|
+
enroll: createHonoCommandHandler(service, "enroll"),
|
|
47
|
+
grant: createHonoCommandHandler(service, "grant"),
|
|
48
|
+
inspect: createHonoAepHandler(service),
|
|
49
|
+
revoke: createHonoCommandHandler(service, "revoke"),
|
|
50
|
+
status: createHonoCommandHandler(service, "status")
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
function registerHonoAepRoute(app, input, path = AEP_HONO_WELL_KNOWN_PATH) {
|
|
54
|
+
app.get(path, createHonoAepHandler(input));
|
|
55
|
+
return app;
|
|
56
|
+
}
|
|
57
|
+
function registerHonoAepRoutes(app, input, inspectPath = AEP_HONO_WELL_KNOWN_PATH) {
|
|
58
|
+
const service = resolveService(input);
|
|
59
|
+
const handlers = createHonoAepHandlers(service);
|
|
60
|
+
const inspect = service.inspectDocument();
|
|
61
|
+
app.get(inspectPath, handlers.inspect);
|
|
62
|
+
app.post((0, import_core.commandPathFromInspect)(inspect, "enroll"), handlers.enroll);
|
|
63
|
+
app.get((0, import_core.commandPathFromInspect)(inspect, "status"), handlers.status);
|
|
64
|
+
app.post((0, import_core.commandPathFromInspect)(inspect, "grant"), handlers.grant);
|
|
65
|
+
app.post((0, import_core.commandPathFromInspect)(inspect, "revoke"), handlers.revoke);
|
|
66
|
+
return app;
|
|
67
|
+
}
|
|
68
|
+
function createHonoCommandHandler(service, command) {
|
|
69
|
+
return async (context) => {
|
|
70
|
+
const clientAssertion = parseAepAuthorization(context.req?.header("Authorization"));
|
|
71
|
+
const idempotencyKey = context.req?.header("Idempotency-Key");
|
|
72
|
+
const body = command === "status" ? void 0 : await context.req?.json();
|
|
73
|
+
const commandOptions = authenticatedOptions(clientAssertion, idempotencyKey);
|
|
74
|
+
const result = command === "enroll" ? await service.enroll(body, commandOptions) : command === "status" ? await service.status({ clientAssertion }) : command === "grant" ? await service.grant(body, commandOptions) : await service.revoke(body, commandOptions);
|
|
75
|
+
return context.json(result.body, result.status, {
|
|
76
|
+
"Content-Type": result.contentType
|
|
77
|
+
});
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
function authenticatedOptions(clientAssertion, idempotencyKey) {
|
|
81
|
+
return {
|
|
82
|
+
clientAssertion,
|
|
83
|
+
...idempotencyKey === void 0 ? {} : { idempotencyKey }
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
function parseAepAuthorization(authorization) {
|
|
87
|
+
const prefix = "AEP ";
|
|
88
|
+
if (authorization?.startsWith(prefix)) {
|
|
89
|
+
return authorization.slice(prefix.length);
|
|
90
|
+
}
|
|
91
|
+
return "";
|
|
92
|
+
}
|
|
93
|
+
function resolveService(input) {
|
|
94
|
+
return "inspectDocument" in input ? input : (0, import_service.createAepService)(input);
|
|
95
|
+
}
|
|
96
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
97
|
+
0 && (module.exports = {
|
|
98
|
+
AEP_HONO_MEDIA_TYPE,
|
|
99
|
+
AEP_HONO_WELL_KNOWN_PATH,
|
|
100
|
+
createHonoAepHandler,
|
|
101
|
+
createHonoAepHandlers,
|
|
102
|
+
packageName,
|
|
103
|
+
registerHonoAepRoute,
|
|
104
|
+
registerHonoAepRoutes
|
|
105
|
+
});
|
|
106
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import { commandPathFromInspect } from \"@aep-foundation/core\";\nimport { createAepService } from \"@aep-foundation/service\";\nimport type {\n AepAuthenticatedServiceOptions,\n AepService,\n AepServiceOptions\n} from \"@aep-foundation/service\";\n\nexport const packageName = \"@aep-foundation/hono\";\nexport const AEP_HONO_WELL_KNOWN_PATH = \"/.well-known/aep\";\nexport const AEP_HONO_MEDIA_TYPE = \"application/aep+json\";\n\nexport interface HonoAepContext {\n json(body: unknown, status?: number, headers?: Record<string, string>): unknown;\n req?: {\n header(name: string): string | undefined;\n json(): Promise<unknown>;\n };\n}\n\nexport type HonoAepHandler = (context: HonoAepContext) => unknown;\n\nexport interface HonoAepInspectAppLike {\n get(path: string, handler: HonoAepHandler): unknown;\n}\n\nexport interface HonoAepAppLike extends HonoAepInspectAppLike {\n post(path: string, handler: HonoAepHandler): unknown;\n}\n\nexport type HonoAepServiceInput = AepService | AepServiceOptions;\n\nexport interface HonoAepRouteHandlers {\n enroll: HonoAepHandler;\n grant: HonoAepHandler;\n inspect: HonoAepHandler;\n revoke: HonoAepHandler;\n status: HonoAepHandler;\n}\n\nexport function createHonoAepHandler(input: HonoAepServiceInput): HonoAepHandler {\n const service = resolveService(input);\n\n return (context) =>\n context.json(service.inspectDocument(), 200, {\n \"Content-Type\": AEP_HONO_MEDIA_TYPE\n });\n}\n\nexport function createHonoAepHandlers(input: HonoAepServiceInput): HonoAepRouteHandlers {\n const service = resolveService(input);\n\n return {\n enroll: createHonoCommandHandler(service, \"enroll\"),\n grant: createHonoCommandHandler(service, \"grant\"),\n inspect: createHonoAepHandler(service),\n revoke: createHonoCommandHandler(service, \"revoke\"),\n status: createHonoCommandHandler(service, \"status\")\n };\n}\n\nexport function registerHonoAepRoute(\n app: HonoAepInspectAppLike,\n input: HonoAepServiceInput,\n path = AEP_HONO_WELL_KNOWN_PATH\n): HonoAepInspectAppLike {\n app.get(path, createHonoAepHandler(input));\n return app;\n}\n\nexport function registerHonoAepRoutes(\n app: HonoAepAppLike,\n input: HonoAepServiceInput,\n inspectPath = AEP_HONO_WELL_KNOWN_PATH\n): HonoAepAppLike {\n const service = resolveService(input);\n const handlers = createHonoAepHandlers(service);\n const inspect = service.inspectDocument();\n\n app.get(inspectPath, handlers.inspect);\n app.post(commandPathFromInspect(inspect, \"enroll\"), handlers.enroll);\n app.get(commandPathFromInspect(inspect, \"status\"), handlers.status);\n app.post(commandPathFromInspect(inspect, \"grant\"), handlers.grant);\n app.post(commandPathFromInspect(inspect, \"revoke\"), handlers.revoke);\n return app;\n}\n\nfunction createHonoCommandHandler(\n service: AepService,\n command: \"enroll\" | \"grant\" | \"revoke\" | \"status\"\n): HonoAepHandler {\n return async (context) => {\n const clientAssertion = parseAepAuthorization(context.req?.header(\"Authorization\"));\n const idempotencyKey = context.req?.header(\"Idempotency-Key\");\n const body = command === \"status\" ? undefined : await context.req?.json();\n const commandOptions = authenticatedOptions(clientAssertion, idempotencyKey);\n const result =\n command === \"enroll\"\n ? await service.enroll(body, commandOptions)\n : command === \"status\"\n ? await service.status({ clientAssertion })\n : command === \"grant\"\n ? await service.grant(body, commandOptions)\n : await service.revoke(body, commandOptions);\n\n return context.json(result.body, result.status, {\n \"Content-Type\": result.contentType\n });\n };\n}\n\nfunction authenticatedOptions(\n clientAssertion: string,\n idempotencyKey: string | undefined\n): AepAuthenticatedServiceOptions {\n return {\n clientAssertion,\n ...(idempotencyKey === undefined ? {} : { idempotencyKey })\n };\n}\n\nfunction parseAepAuthorization(authorization: string | undefined): string {\n const prefix = \"AEP \";\n\n if (authorization?.startsWith(prefix)) {\n return authorization.slice(prefix.length);\n }\n\n return \"\";\n}\n\nfunction resolveService(input: HonoAepServiceInput): AepService {\n return \"inspectDocument\" in input ? input : createAepService(input);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAAuC;AACvC,qBAAiC;AAO1B,IAAM,cAAc;AACpB,IAAM,2BAA2B;AACjC,IAAM,sBAAsB;AA8B5B,SAAS,qBAAqB,OAA4C;AAC/E,QAAM,UAAU,eAAe,KAAK;AAEpC,SAAO,CAAC,YACN,QAAQ,KAAK,QAAQ,gBAAgB,GAAG,KAAK;AAAA,IAC3C,gBAAgB;AAAA,EAClB,CAAC;AACL;AAEO,SAAS,sBAAsB,OAAkD;AACtF,QAAM,UAAU,eAAe,KAAK;AAEpC,SAAO;AAAA,IACL,QAAQ,yBAAyB,SAAS,QAAQ;AAAA,IAClD,OAAO,yBAAyB,SAAS,OAAO;AAAA,IAChD,SAAS,qBAAqB,OAAO;AAAA,IACrC,QAAQ,yBAAyB,SAAS,QAAQ;AAAA,IAClD,QAAQ,yBAAyB,SAAS,QAAQ;AAAA,EACpD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D;AACF;AAEA,SAAS,sBAAsB,eAA2C;AACxE,QAAM,SAAS;AAEf,MAAI,eAAe,WAAW,MAAM,GAAG;AACrC,WAAO,cAAc,MAAM,OAAO,MAAM;AAAA,EAC1C;AAEA,SAAO;AACT;AAEA,SAAS,eAAe,OAAwC;AAC9D,SAAO,qBAAqB,QAAQ,YAAQ,iCAAiB,KAAK;AACpE;","names":[]}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { AepService, AepServiceOptions } from '@aep-foundation/service';
|
|
2
|
+
|
|
3
|
+
declare const packageName = "@aep-foundation/hono";
|
|
4
|
+
declare const AEP_HONO_WELL_KNOWN_PATH = "/.well-known/aep";
|
|
5
|
+
declare const AEP_HONO_MEDIA_TYPE = "application/aep+json";
|
|
6
|
+
interface HonoAepContext {
|
|
7
|
+
json(body: unknown, status?: number, headers?: Record<string, string>): unknown;
|
|
8
|
+
req?: {
|
|
9
|
+
header(name: string): string | undefined;
|
|
10
|
+
json(): Promise<unknown>;
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
type HonoAepHandler = (context: HonoAepContext) => unknown;
|
|
14
|
+
interface HonoAepInspectAppLike {
|
|
15
|
+
get(path: string, handler: HonoAepHandler): unknown;
|
|
16
|
+
}
|
|
17
|
+
interface HonoAepAppLike extends HonoAepInspectAppLike {
|
|
18
|
+
post(path: string, handler: HonoAepHandler): unknown;
|
|
19
|
+
}
|
|
20
|
+
type HonoAepServiceInput = AepService | AepServiceOptions;
|
|
21
|
+
interface HonoAepRouteHandlers {
|
|
22
|
+
enroll: HonoAepHandler;
|
|
23
|
+
grant: HonoAepHandler;
|
|
24
|
+
inspect: HonoAepHandler;
|
|
25
|
+
revoke: HonoAepHandler;
|
|
26
|
+
status: HonoAepHandler;
|
|
27
|
+
}
|
|
28
|
+
declare function createHonoAepHandler(input: HonoAepServiceInput): HonoAepHandler;
|
|
29
|
+
declare function createHonoAepHandlers(input: HonoAepServiceInput): HonoAepRouteHandlers;
|
|
30
|
+
declare function registerHonoAepRoute(app: HonoAepInspectAppLike, input: HonoAepServiceInput, path?: string): HonoAepInspectAppLike;
|
|
31
|
+
declare function registerHonoAepRoutes(app: HonoAepAppLike, input: HonoAepServiceInput, inspectPath?: string): HonoAepAppLike;
|
|
32
|
+
|
|
33
|
+
export { AEP_HONO_MEDIA_TYPE, AEP_HONO_WELL_KNOWN_PATH, type HonoAepAppLike, type HonoAepContext, type HonoAepHandler, type HonoAepInspectAppLike, type HonoAepRouteHandlers, type HonoAepServiceInput, createHonoAepHandler, createHonoAepHandlers, packageName, registerHonoAepRoute, registerHonoAepRoutes };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { AepService, AepServiceOptions } from '@aep-foundation/service';
|
|
2
|
+
|
|
3
|
+
declare const packageName = "@aep-foundation/hono";
|
|
4
|
+
declare const AEP_HONO_WELL_KNOWN_PATH = "/.well-known/aep";
|
|
5
|
+
declare const AEP_HONO_MEDIA_TYPE = "application/aep+json";
|
|
6
|
+
interface HonoAepContext {
|
|
7
|
+
json(body: unknown, status?: number, headers?: Record<string, string>): unknown;
|
|
8
|
+
req?: {
|
|
9
|
+
header(name: string): string | undefined;
|
|
10
|
+
json(): Promise<unknown>;
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
type HonoAepHandler = (context: HonoAepContext) => unknown;
|
|
14
|
+
interface HonoAepInspectAppLike {
|
|
15
|
+
get(path: string, handler: HonoAepHandler): unknown;
|
|
16
|
+
}
|
|
17
|
+
interface HonoAepAppLike extends HonoAepInspectAppLike {
|
|
18
|
+
post(path: string, handler: HonoAepHandler): unknown;
|
|
19
|
+
}
|
|
20
|
+
type HonoAepServiceInput = AepService | AepServiceOptions;
|
|
21
|
+
interface HonoAepRouteHandlers {
|
|
22
|
+
enroll: HonoAepHandler;
|
|
23
|
+
grant: HonoAepHandler;
|
|
24
|
+
inspect: HonoAepHandler;
|
|
25
|
+
revoke: HonoAepHandler;
|
|
26
|
+
status: HonoAepHandler;
|
|
27
|
+
}
|
|
28
|
+
declare function createHonoAepHandler(input: HonoAepServiceInput): HonoAepHandler;
|
|
29
|
+
declare function createHonoAepHandlers(input: HonoAepServiceInput): HonoAepRouteHandlers;
|
|
30
|
+
declare function registerHonoAepRoute(app: HonoAepInspectAppLike, input: HonoAepServiceInput, path?: string): HonoAepInspectAppLike;
|
|
31
|
+
declare function registerHonoAepRoutes(app: HonoAepAppLike, input: HonoAepServiceInput, inspectPath?: string): HonoAepAppLike;
|
|
32
|
+
|
|
33
|
+
export { AEP_HONO_MEDIA_TYPE, AEP_HONO_WELL_KNOWN_PATH, type HonoAepAppLike, type HonoAepContext, type HonoAepHandler, type HonoAepInspectAppLike, type HonoAepRouteHandlers, type HonoAepServiceInput, createHonoAepHandler, createHonoAepHandlers, packageName, registerHonoAepRoute, registerHonoAepRoutes };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import { commandPathFromInspect } from "@aep-foundation/core";
|
|
3
|
+
import { createAepService } from "@aep-foundation/service";
|
|
4
|
+
var packageName = "@aep-foundation/hono";
|
|
5
|
+
var AEP_HONO_WELL_KNOWN_PATH = "/.well-known/aep";
|
|
6
|
+
var AEP_HONO_MEDIA_TYPE = "application/aep+json";
|
|
7
|
+
function createHonoAepHandler(input) {
|
|
8
|
+
const service = resolveService(input);
|
|
9
|
+
return (context) => context.json(service.inspectDocument(), 200, {
|
|
10
|
+
"Content-Type": AEP_HONO_MEDIA_TYPE
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
function createHonoAepHandlers(input) {
|
|
14
|
+
const service = resolveService(input);
|
|
15
|
+
return {
|
|
16
|
+
enroll: createHonoCommandHandler(service, "enroll"),
|
|
17
|
+
grant: createHonoCommandHandler(service, "grant"),
|
|
18
|
+
inspect: createHonoAepHandler(service),
|
|
19
|
+
revoke: createHonoCommandHandler(service, "revoke"),
|
|
20
|
+
status: createHonoCommandHandler(service, "status")
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
function registerHonoAepRoute(app, input, path = AEP_HONO_WELL_KNOWN_PATH) {
|
|
24
|
+
app.get(path, createHonoAepHandler(input));
|
|
25
|
+
return app;
|
|
26
|
+
}
|
|
27
|
+
function registerHonoAepRoutes(app, input, inspectPath = AEP_HONO_WELL_KNOWN_PATH) {
|
|
28
|
+
const service = resolveService(input);
|
|
29
|
+
const handlers = createHonoAepHandlers(service);
|
|
30
|
+
const inspect = service.inspectDocument();
|
|
31
|
+
app.get(inspectPath, handlers.inspect);
|
|
32
|
+
app.post(commandPathFromInspect(inspect, "enroll"), handlers.enroll);
|
|
33
|
+
app.get(commandPathFromInspect(inspect, "status"), handlers.status);
|
|
34
|
+
app.post(commandPathFromInspect(inspect, "grant"), handlers.grant);
|
|
35
|
+
app.post(commandPathFromInspect(inspect, "revoke"), handlers.revoke);
|
|
36
|
+
return app;
|
|
37
|
+
}
|
|
38
|
+
function createHonoCommandHandler(service, command) {
|
|
39
|
+
return async (context) => {
|
|
40
|
+
const clientAssertion = parseAepAuthorization(context.req?.header("Authorization"));
|
|
41
|
+
const idempotencyKey = context.req?.header("Idempotency-Key");
|
|
42
|
+
const body = command === "status" ? void 0 : await context.req?.json();
|
|
43
|
+
const commandOptions = authenticatedOptions(clientAssertion, idempotencyKey);
|
|
44
|
+
const result = command === "enroll" ? await service.enroll(body, commandOptions) : command === "status" ? await service.status({ clientAssertion }) : command === "grant" ? await service.grant(body, commandOptions) : await service.revoke(body, commandOptions);
|
|
45
|
+
return context.json(result.body, result.status, {
|
|
46
|
+
"Content-Type": result.contentType
|
|
47
|
+
});
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
function authenticatedOptions(clientAssertion, idempotencyKey) {
|
|
51
|
+
return {
|
|
52
|
+
clientAssertion,
|
|
53
|
+
...idempotencyKey === void 0 ? {} : { idempotencyKey }
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
function parseAepAuthorization(authorization) {
|
|
57
|
+
const prefix = "AEP ";
|
|
58
|
+
if (authorization?.startsWith(prefix)) {
|
|
59
|
+
return authorization.slice(prefix.length);
|
|
60
|
+
}
|
|
61
|
+
return "";
|
|
62
|
+
}
|
|
63
|
+
function resolveService(input) {
|
|
64
|
+
return "inspectDocument" in input ? input : createAepService(input);
|
|
65
|
+
}
|
|
66
|
+
export {
|
|
67
|
+
AEP_HONO_MEDIA_TYPE,
|
|
68
|
+
AEP_HONO_WELL_KNOWN_PATH,
|
|
69
|
+
createHonoAepHandler,
|
|
70
|
+
createHonoAepHandlers,
|
|
71
|
+
packageName,
|
|
72
|
+
registerHonoAepRoute,
|
|
73
|
+
registerHonoAepRoutes
|
|
74
|
+
};
|
|
75
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import { commandPathFromInspect } from \"@aep-foundation/core\";\nimport { createAepService } from \"@aep-foundation/service\";\nimport type {\n AepAuthenticatedServiceOptions,\n AepService,\n AepServiceOptions\n} from \"@aep-foundation/service\";\n\nexport const packageName = \"@aep-foundation/hono\";\nexport const AEP_HONO_WELL_KNOWN_PATH = \"/.well-known/aep\";\nexport const AEP_HONO_MEDIA_TYPE = \"application/aep+json\";\n\nexport interface HonoAepContext {\n json(body: unknown, status?: number, headers?: Record<string, string>): unknown;\n req?: {\n header(name: string): string | undefined;\n json(): Promise<unknown>;\n };\n}\n\nexport type HonoAepHandler = (context: HonoAepContext) => unknown;\n\nexport interface HonoAepInspectAppLike {\n get(path: string, handler: HonoAepHandler): unknown;\n}\n\nexport interface HonoAepAppLike extends HonoAepInspectAppLike {\n post(path: string, handler: HonoAepHandler): unknown;\n}\n\nexport type HonoAepServiceInput = AepService | AepServiceOptions;\n\nexport interface HonoAepRouteHandlers {\n enroll: HonoAepHandler;\n grant: HonoAepHandler;\n inspect: HonoAepHandler;\n revoke: HonoAepHandler;\n status: HonoAepHandler;\n}\n\nexport function createHonoAepHandler(input: HonoAepServiceInput): HonoAepHandler {\n const service = resolveService(input);\n\n return (context) =>\n context.json(service.inspectDocument(), 200, {\n \"Content-Type\": AEP_HONO_MEDIA_TYPE\n });\n}\n\nexport function createHonoAepHandlers(input: HonoAepServiceInput): HonoAepRouteHandlers {\n const service = resolveService(input);\n\n return {\n enroll: createHonoCommandHandler(service, \"enroll\"),\n grant: createHonoCommandHandler(service, \"grant\"),\n inspect: createHonoAepHandler(service),\n revoke: createHonoCommandHandler(service, \"revoke\"),\n status: createHonoCommandHandler(service, \"status\")\n };\n}\n\nexport function registerHonoAepRoute(\n app: HonoAepInspectAppLike,\n input: HonoAepServiceInput,\n path = AEP_HONO_WELL_KNOWN_PATH\n): HonoAepInspectAppLike {\n app.get(path, createHonoAepHandler(input));\n return app;\n}\n\nexport function registerHonoAepRoutes(\n app: HonoAepAppLike,\n input: HonoAepServiceInput,\n inspectPath = AEP_HONO_WELL_KNOWN_PATH\n): HonoAepAppLike {\n const service = resolveService(input);\n const handlers = createHonoAepHandlers(service);\n const inspect = service.inspectDocument();\n\n app.get(inspectPath, handlers.inspect);\n app.post(commandPathFromInspect(inspect, \"enroll\"), handlers.enroll);\n app.get(commandPathFromInspect(inspect, \"status\"), handlers.status);\n app.post(commandPathFromInspect(inspect, \"grant\"), handlers.grant);\n app.post(commandPathFromInspect(inspect, \"revoke\"), handlers.revoke);\n return app;\n}\n\nfunction createHonoCommandHandler(\n service: AepService,\n command: \"enroll\" | \"grant\" | \"revoke\" | \"status\"\n): HonoAepHandler {\n return async (context) => {\n const clientAssertion = parseAepAuthorization(context.req?.header(\"Authorization\"));\n const idempotencyKey = context.req?.header(\"Idempotency-Key\");\n const body = command === \"status\" ? undefined : await context.req?.json();\n const commandOptions = authenticatedOptions(clientAssertion, idempotencyKey);\n const result =\n command === \"enroll\"\n ? await service.enroll(body, commandOptions)\n : command === \"status\"\n ? await service.status({ clientAssertion })\n : command === \"grant\"\n ? await service.grant(body, commandOptions)\n : await service.revoke(body, commandOptions);\n\n return context.json(result.body, result.status, {\n \"Content-Type\": result.contentType\n });\n };\n}\n\nfunction authenticatedOptions(\n clientAssertion: string,\n idempotencyKey: string | undefined\n): AepAuthenticatedServiceOptions {\n return {\n clientAssertion,\n ...(idempotencyKey === undefined ? {} : { idempotencyKey })\n };\n}\n\nfunction parseAepAuthorization(authorization: string | undefined): string {\n const prefix = \"AEP \";\n\n if (authorization?.startsWith(prefix)) {\n return authorization.slice(prefix.length);\n }\n\n return \"\";\n}\n\nfunction resolveService(input: HonoAepServiceInput): AepService {\n return \"inspectDocument\" in input ? input : createAepService(input);\n}\n"],"mappings":";AAAA,SAAS,8BAA8B;AACvC,SAAS,wBAAwB;AAO1B,IAAM,cAAc;AACpB,IAAM,2BAA2B;AACjC,IAAM,sBAAsB;AA8B5B,SAAS,qBAAqB,OAA4C;AAC/E,QAAM,UAAU,eAAe,KAAK;AAEpC,SAAO,CAAC,YACN,QAAQ,KAAK,QAAQ,gBAAgB,GAAG,KAAK;AAAA,IAC3C,gBAAgB;AAAA,EAClB,CAAC;AACL;AAEO,SAAS,sBAAsB,OAAkD;AACtF,QAAM,UAAU,eAAe,KAAK;AAEpC,SAAO;AAAA,IACL,QAAQ,yBAAyB,SAAS,QAAQ;AAAA,IAClD,OAAO,yBAAyB,SAAS,OAAO;AAAA,IAChD,SAAS,qBAAqB,OAAO;AAAA,IACrC,QAAQ,yBAAyB,SAAS,QAAQ;AAAA,IAClD,QAAQ,yBAAyB,SAAS,QAAQ;AAAA,EACpD;AACF;AAEO,SAAS,qBACd,KACA,OACA,OAAO,0BACgB;AACvB,MAAI,IAAI,MAAM,qBAAqB,KAAK,CAAC;AACzC,SAAO;AACT;AAEO,SAAS,sBACd,KACA,OACA,cAAc,0BACE;AAChB,QAAM,UAAU,eAAe,KAAK;AACpC,QAAM,WAAW,sBAAsB,OAAO;AAC9C,QAAM,UAAU,QAAQ,gBAAgB;AAExC,MAAI,IAAI,aAAa,SAA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+1,54 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@aep-foundation/hono",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Hono adapter for AEP Service handlers.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.cjs",
|
|
7
|
+
"module": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"sideEffects": false,
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"node": {
|
|
14
|
+
"import": "./dist/index.js",
|
|
15
|
+
"require": "./dist/index.cjs"
|
|
16
|
+
},
|
|
17
|
+
"default": "./dist/index.js"
|
|
18
|
+
},
|
|
19
|
+
"./package.json": "./package.json"
|
|
20
|
+
},
|
|
21
|
+
"files": [
|
|
22
|
+
"dist",
|
|
23
|
+
"CHANGELOG.md",
|
|
24
|
+
"README.md",
|
|
25
|
+
"LICENSE"
|
|
26
|
+
],
|
|
27
|
+
"engines": {
|
|
28
|
+
"node": ">=22.0.0"
|
|
29
|
+
},
|
|
30
|
+
"license": "MIT",
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"@aep-foundation/core": "^0.1.0",
|
|
33
|
+
"@aep-foundation/service": "^0.1.0"
|
|
34
|
+
},
|
|
35
|
+
"peerDependencies": {
|
|
36
|
+
"hono": ">=4"
|
|
37
|
+
},
|
|
38
|
+
"publishConfig": {
|
|
39
|
+
"access": "public",
|
|
40
|
+
"provenance": true
|
|
41
|
+
},
|
|
42
|
+
"devDependencies": {
|
|
43
|
+
"hono": "^4.12.27"
|
|
44
|
+
},
|
|
45
|
+
"scripts": {
|
|
46
|
+
"build": "tsup",
|
|
47
|
+
"dev": "tsup --watch",
|
|
48
|
+
"test": "vitest run --coverage",
|
|
49
|
+
"test:watch": "vitest",
|
|
50
|
+
"lint": "eslint src test --max-warnings 0",
|
|
51
|
+
"typecheck": "tsc --noEmit && tsc --noEmit -p tsconfig.test.json",
|
|
52
|
+
"clean": "rm -rf dist .turbo coverage"
|
|
53
|
+
}
|
|
54
|
+
}
|