@axiom-lattice/gateway 3.0.10 → 4.0.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/dist/A2AAuthService-DK5X6VIL.mjs +11 -0
- package/dist/A2AAuthService-DK5X6VIL.mjs.map +1 -0
- package/dist/a2a-7N3WDAOP.mjs +147 -0
- package/dist/a2a-7N3WDAOP.mjs.map +1 -0
- package/dist/a2a-standard-U2XYG45L.mjs +1376 -0
- package/dist/a2a-standard-U2XYG45L.mjs.map +1 -0
- package/dist/chunk-2HOCF46L.mjs +143 -0
- package/dist/chunk-2HOCF46L.mjs.map +1 -0
- package/dist/chunk-IDOEIBCF.mjs +165 -0
- package/dist/chunk-IDOEIBCF.mjs.map +1 -0
- package/dist/index.js +3445 -1633
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1625 -1056
- package/dist/index.mjs.map +1 -1
- package/package.json +8 -6
- package/dist/a2a-QMHEH3ZT.mjs +0 -615
- package/dist/a2a-QMHEH3ZT.mjs.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import {
|
|
2
|
+
A2AAuthError
|
|
3
|
+
} from "./chunk-2HOCF46L.mjs";
|
|
4
|
+
|
|
5
|
+
// src/routes/a2a.ts
|
|
6
|
+
var _a2aKeyStore = null;
|
|
7
|
+
var _a2aAuthService = null;
|
|
8
|
+
function setA2AKeyStore(store) {
|
|
9
|
+
_a2aKeyStore = store;
|
|
10
|
+
}
|
|
11
|
+
function setA2AAuthService(service) {
|
|
12
|
+
_a2aAuthService = service;
|
|
13
|
+
}
|
|
14
|
+
async function refreshStoreKeyMap() {
|
|
15
|
+
if (_a2aAuthService) await _a2aAuthService.refresh();
|
|
16
|
+
}
|
|
17
|
+
async function requireTenantSession(request, reply) {
|
|
18
|
+
if (!getUserTenantId(request)) {
|
|
19
|
+
await reply.status(401).send({ success: false, error: "Unauthorized" });
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
async function authorizeKeyMutation(request, reply) {
|
|
23
|
+
if (!_a2aKeyStore) {
|
|
24
|
+
await reply.status(501).send({ error: "Key store not configured" });
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
const record = await _a2aKeyStore.findById(request.params.id);
|
|
28
|
+
if (!record) {
|
|
29
|
+
await reply.status(404).send({ success: false, error: "A2A API key not found" });
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
if (record.tenantId !== getUserTenantId(request)) {
|
|
33
|
+
await reply.status(403).send({ success: false, error: "Forbidden" });
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
return true;
|
|
37
|
+
}
|
|
38
|
+
function getUserTenantId(request) {
|
|
39
|
+
return request.user?.tenantId;
|
|
40
|
+
}
|
|
41
|
+
async function handleApiKeyList(request, reply) {
|
|
42
|
+
if (!_a2aKeyStore) {
|
|
43
|
+
reply.status(501).send({ error: "Key store not configured" });
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
const records = await _a2aKeyStore.list({
|
|
47
|
+
tenantId: getUserTenantId(request),
|
|
48
|
+
limit: request.query.limit ? parseInt(request.query.limit, 10) : void 0,
|
|
49
|
+
offset: request.query.offset ? parseInt(request.query.offset, 10) : void 0
|
|
50
|
+
});
|
|
51
|
+
reply.status(200).send({
|
|
52
|
+
success: true,
|
|
53
|
+
data: {
|
|
54
|
+
records: records.map((r) => ({ ...r, key: r.key.slice(0, 8) + "..." })),
|
|
55
|
+
total: records.length
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
async function handleApiKeyCreate(request, reply) {
|
|
60
|
+
if (!_a2aKeyStore || !_a2aAuthService) {
|
|
61
|
+
reply.status(501).send({ error: "Key store not configured" });
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
const body = request.body;
|
|
65
|
+
const tenantId = getUserTenantId(request);
|
|
66
|
+
try {
|
|
67
|
+
const record = await _a2aAuthService.createKeyScoped({
|
|
68
|
+
tenantId,
|
|
69
|
+
projectId: body.projectId,
|
|
70
|
+
assistantIds: body.assistantIds,
|
|
71
|
+
label: body.label
|
|
72
|
+
});
|
|
73
|
+
await refreshStoreKeyMap();
|
|
74
|
+
reply.status(201).send({ success: true, data: record });
|
|
75
|
+
} catch (err) {
|
|
76
|
+
if (err instanceof A2AAuthError) {
|
|
77
|
+
reply.status(err.statusCode).send({ success: false, error: err.message });
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
request.log.error({ err }, "a2a:keys:create");
|
|
81
|
+
reply.status(500).send({ success: false, error: "Failed to create key" });
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
async function handleApiKeyDelete(request, reply) {
|
|
85
|
+
if (!await authorizeKeyMutation(request, reply)) return;
|
|
86
|
+
await _a2aKeyStore.delete(request.params.id);
|
|
87
|
+
await refreshStoreKeyMap();
|
|
88
|
+
reply.status(200).send({ success: true });
|
|
89
|
+
}
|
|
90
|
+
async function handleApiKeyDisable(request, reply) {
|
|
91
|
+
if (!await authorizeKeyMutation(request, reply)) return;
|
|
92
|
+
await _a2aKeyStore.disable(request.params.id);
|
|
93
|
+
await refreshStoreKeyMap();
|
|
94
|
+
reply.status(200).send({ success: true });
|
|
95
|
+
}
|
|
96
|
+
async function handleApiKeyEnable(request, reply) {
|
|
97
|
+
if (!await authorizeKeyMutation(request, reply)) return;
|
|
98
|
+
await _a2aKeyStore.enable(request.params.id);
|
|
99
|
+
await refreshStoreKeyMap();
|
|
100
|
+
reply.status(200).send({ success: true });
|
|
101
|
+
}
|
|
102
|
+
async function handleApiKeyRotate(request, reply) {
|
|
103
|
+
if (!await authorizeKeyMutation(request, reply)) return;
|
|
104
|
+
const record = await _a2aKeyStore.rotate(request.params.id);
|
|
105
|
+
await refreshStoreKeyMap();
|
|
106
|
+
reply.status(200).send({ success: true, data: record });
|
|
107
|
+
}
|
|
108
|
+
function registerA2ARoutes(app) {
|
|
109
|
+
const options = { preHandler: requireTenantSession };
|
|
110
|
+
app.get(
|
|
111
|
+
"/api/a2a/keys",
|
|
112
|
+
options,
|
|
113
|
+
handleApiKeyList
|
|
114
|
+
);
|
|
115
|
+
app.post(
|
|
116
|
+
"/api/a2a/keys",
|
|
117
|
+
options,
|
|
118
|
+
handleApiKeyCreate
|
|
119
|
+
);
|
|
120
|
+
app.delete(
|
|
121
|
+
"/api/a2a/keys/:id",
|
|
122
|
+
options,
|
|
123
|
+
handleApiKeyDelete
|
|
124
|
+
);
|
|
125
|
+
app.post(
|
|
126
|
+
"/api/a2a/keys/:id/disable",
|
|
127
|
+
options,
|
|
128
|
+
handleApiKeyDisable
|
|
129
|
+
);
|
|
130
|
+
app.post(
|
|
131
|
+
"/api/a2a/keys/:id/enable",
|
|
132
|
+
options,
|
|
133
|
+
handleApiKeyEnable
|
|
134
|
+
);
|
|
135
|
+
app.post(
|
|
136
|
+
"/api/a2a/keys/:id/rotate",
|
|
137
|
+
options,
|
|
138
|
+
handleApiKeyRotate
|
|
139
|
+
);
|
|
140
|
+
}
|
|
141
|
+
export {
|
|
142
|
+
refreshStoreKeyMap,
|
|
143
|
+
registerA2ARoutes,
|
|
144
|
+
setA2AAuthService,
|
|
145
|
+
setA2AKeyStore
|
|
146
|
+
};
|
|
147
|
+
//# sourceMappingURL=a2a-7N3WDAOP.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/routes/a2a.ts"],"sourcesContent":["import type { FastifyInstance, FastifyRequest, FastifyReply } from \"fastify\";\nimport type {\n A2AApiKeyStore,\n CreateA2AApiKeyInput,\n} from \"@axiom-lattice/protocols\";\nimport { A2AAuthError } from \"../services/a2a/A2AAuthService\";\nimport type { A2AAuthService } from \"../services/a2a/A2AAuthService\";\n\n// ─── Key Store ────────────────────────────────────────────────────────────\n\nlet _a2aKeyStore: A2AApiKeyStore | null = null;\nlet _a2aAuthService: A2AAuthService | null = null;\n\n/** Inject the A2A key store used by the keys management routes. */\nexport function setA2AKeyStore(store: A2AApiKeyStore): void {\n _a2aKeyStore = store;\n}\n\n/** Inject the A2A auth service used to create keys and refresh the key cache. */\nexport function setA2AAuthService(service: A2AAuthService): void {\n _a2aAuthService = service;\n}\n\n/**\n * Reload cached key maps after a keys CRUD mutation. Delegates to the auth\n * service's key-map cache so authentication reflects the latest keys without\n * hitting the store on every request.\n */\nexport async function refreshStoreKeyMap(): Promise<void> {\n if (_a2aAuthService) await _a2aAuthService.refresh();\n}\n\ninterface RequestWithUser extends FastifyRequest {\n user?: { id: string; tenantId?: string };\n}\n\nasync function requireTenantSession(\n request: FastifyRequest,\n reply: FastifyReply,\n): Promise<void> {\n if (!getUserTenantId(request)) {\n await reply.status(401).send({ success: false, error: \"Unauthorized\" });\n }\n}\n\nasync function authorizeKeyMutation(\n request: FastifyRequest<{ Params: { id: string } }>,\n reply: FastifyReply,\n): Promise<boolean> {\n if (!_a2aKeyStore) {\n await reply.status(501).send({ error: \"Key store not configured\" });\n return false;\n }\n const record = await _a2aKeyStore.findById(request.params.id);\n if (!record) {\n await reply.status(404).send({ success: false, error: \"A2A API key not found\" });\n return false;\n }\n if (record.tenantId !== getUserTenantId(request)) {\n await reply.status(403).send({ success: false, error: \"Forbidden\" });\n return false;\n }\n return true;\n}\n\nfunction getUserTenantId(request: FastifyRequest): string | undefined {\n return (request as RequestWithUser).user?.tenantId;\n}\n\n// ─── API Key Management Handlers ─────────────────────────────────────────\n\nasync function handleApiKeyList(\n request: FastifyRequest<{ Querystring: { tenantId?: string; limit?: string; offset?: string } }>,\n reply: FastifyReply,\n): Promise<void> {\n if (!_a2aKeyStore) {\n reply.status(501).send({ error: \"Key store not configured\" });\n return;\n }\n\n const records = await _a2aKeyStore.list({\n tenantId: getUserTenantId(request),\n limit: request.query.limit ? parseInt(request.query.limit, 10) : undefined,\n offset: request.query.offset ? parseInt(request.query.offset, 10) : undefined,\n });\n\n reply.status(200).send({\n success: true,\n data: {\n records: records.map((r) => ({ ...r, key: r.key.slice(0, 8) + \"...\" })),\n total: records.length,\n },\n });\n}\n\nasync function handleApiKeyCreate(\n request: FastifyRequest<{ Body: Partial<CreateA2AApiKeyInput> }>,\n reply: FastifyReply,\n): Promise<void> {\n if (!_a2aKeyStore || !_a2aAuthService) {\n reply.status(501).send({ error: \"Key store not configured\" });\n return;\n }\n\n const body = request.body as Partial<CreateA2AApiKeyInput>;\n const tenantId = getUserTenantId(request)!;\n\n try {\n const record = await _a2aAuthService.createKeyScoped({\n tenantId,\n projectId: body.projectId,\n assistantIds: body.assistantIds,\n label: body.label,\n });\n await refreshStoreKeyMap();\n reply.status(201).send({ success: true, data: record });\n } catch (err) {\n if (err instanceof A2AAuthError) {\n reply.status(err.statusCode).send({ success: false, error: err.message });\n return;\n }\n request.log.error({ err }, \"a2a:keys:create\");\n reply.status(500).send({ success: false, error: \"Failed to create key\" });\n }\n}\n\nasync function handleApiKeyDelete(\n request: FastifyRequest<{ Params: { id: string } }>,\n reply: FastifyReply,\n): Promise<void> {\n if (!(await authorizeKeyMutation(request, reply))) return;\n\n await _a2aKeyStore!.delete(request.params.id);\n await refreshStoreKeyMap();\n\n reply.status(200).send({ success: true });\n}\n\nasync function handleApiKeyDisable(\n request: FastifyRequest<{ Params: { id: string } }>,\n reply: FastifyReply,\n): Promise<void> {\n if (!(await authorizeKeyMutation(request, reply))) return;\n\n await _a2aKeyStore!.disable(request.params.id);\n await refreshStoreKeyMap();\n\n reply.status(200).send({ success: true });\n}\n\nasync function handleApiKeyEnable(\n request: FastifyRequest<{ Params: { id: string } }>,\n reply: FastifyReply,\n): Promise<void> {\n if (!(await authorizeKeyMutation(request, reply))) return;\n\n await _a2aKeyStore!.enable(request.params.id);\n await refreshStoreKeyMap();\n\n reply.status(200).send({ success: true });\n}\n\nasync function handleApiKeyRotate(\n request: FastifyRequest<{ Params: { id: string } }>,\n reply: FastifyReply,\n): Promise<void> {\n if (!(await authorizeKeyMutation(request, reply))) return;\n\n const record = await _a2aKeyStore!.rotate(request.params.id);\n await refreshStoreKeyMap();\n\n reply.status(200).send({ success: true, data: record });\n}\n\n// ─── Route Registration ───────────────────────────────────────────────────\n\n/** Register the internal A2A API key management routes. */\nexport function registerA2ARoutes(app: FastifyInstance): void {\n const options = { preHandler: requireTenantSession };\n app.get<{ Querystring: { tenantId?: string; limit?: string; offset?: string } }>(\n \"/api/a2a/keys\",\n options,\n handleApiKeyList,\n );\n\n app.post<{ Body: Partial<CreateA2AApiKeyInput> }>(\n \"/api/a2a/keys\",\n options,\n handleApiKeyCreate,\n );\n\n app.delete<{ Params: { id: string } }>(\n \"/api/a2a/keys/:id\",\n options,\n handleApiKeyDelete,\n );\n\n app.post<{ Params: { id: string } }>(\n \"/api/a2a/keys/:id/disable\",\n options,\n handleApiKeyDisable,\n );\n\n app.post<{ Params: { id: string } }>(\n \"/api/a2a/keys/:id/enable\",\n options,\n handleApiKeyEnable,\n );\n\n app.post<{ Params: { id: string } }>(\n \"/api/a2a/keys/:id/rotate\",\n options,\n handleApiKeyRotate,\n );\n}\n"],"mappings":";;;;;AAUA,IAAI,eAAsC;AAC1C,IAAI,kBAAyC;AAGtC,SAAS,eAAe,OAA6B;AAC1D,iBAAe;AACjB;AAGO,SAAS,kBAAkB,SAA+B;AAC/D,oBAAkB;AACpB;AAOA,eAAsB,qBAAoC;AACxD,MAAI,gBAAiB,OAAM,gBAAgB,QAAQ;AACrD;AAMA,eAAe,qBACb,SACA,OACe;AACf,MAAI,CAAC,gBAAgB,OAAO,GAAG;AAC7B,UAAM,MAAM,OAAO,GAAG,EAAE,KAAK,EAAE,SAAS,OAAO,OAAO,eAAe,CAAC;AAAA,EACxE;AACF;AAEA,eAAe,qBACb,SACA,OACkB;AAClB,MAAI,CAAC,cAAc;AACjB,UAAM,MAAM,OAAO,GAAG,EAAE,KAAK,EAAE,OAAO,2BAA2B,CAAC;AAClE,WAAO;AAAA,EACT;AACA,QAAM,SAAS,MAAM,aAAa,S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