monorise 1.14.0 → 1.15.0-dev.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/base/index.d.ts +219 -1
- package/dist/base/index.js +381 -1
- package/dist/base/index.js.map +1 -1
- package/dist/cli/cli.js +291 -122
- package/dist/cli/cli.js.map +1 -1
- package/dist/cli/templates/files/proxy-route.ts +12 -22
- package/dist/cli/templates/files/sst.config.ts +4 -1
- package/dist/cli/templates/files/ws-ticket-route.ts +21 -0
- package/dist/core/index.d.ts +55 -20
- package/dist/core/index.js +743 -128
- package/dist/core/index.js.map +1 -1
- package/dist/index.d.ts +23 -0
- package/dist/proxy/index.d.ts +270 -2
- package/dist/proxy/index.js +645 -37
- package/dist/proxy/index.js.map +1 -1
- package/dist/react/actions/core.action.d.ts.map +1 -1
- package/dist/react/index.d.ts.map +1 -1
- package/dist/react/index.js +33 -60
- package/dist/react/index.js.map +1 -1
- package/package.json +1 -1
- package/dist/cli/templates/files/proxy-request.ts +0 -50
package/dist/core/index.js
CHANGED
|
@@ -14,13 +14,403 @@ import {
|
|
|
14
14
|
// controllers/setupRoutes.ts
|
|
15
15
|
import { Hono } from "hono";
|
|
16
16
|
|
|
17
|
-
// middlewares/
|
|
17
|
+
// middlewares/authorize.ts
|
|
18
18
|
import { createMiddleware } from "hono/factory";
|
|
19
19
|
import httpStatus from "http-status";
|
|
20
|
-
var
|
|
20
|
+
var ENTITY_ROUTE_ACTIONS = {
|
|
21
|
+
read: ["read"],
|
|
22
|
+
list: ["read", "list"],
|
|
23
|
+
unique: ["read"],
|
|
24
|
+
tag: ["read", "list"],
|
|
25
|
+
create: ["create"],
|
|
26
|
+
update: ["update"],
|
|
27
|
+
// Upsert creates or updates depending on whether the entity exists, and
|
|
28
|
+
// checking which before the write would race, so it needs both.
|
|
29
|
+
upsert: ["create", "update"],
|
|
30
|
+
adjust: ["update"],
|
|
31
|
+
delete: ["delete"]
|
|
32
|
+
};
|
|
33
|
+
var ROUTE_GUARD = /* @__PURE__ */ Symbol.for("monorise.routeGuard");
|
|
34
|
+
var ROUTE_PERMISSION = /* @__PURE__ */ Symbol.for("monorise.routePermission");
|
|
35
|
+
var NOT_DATA = /* @__PURE__ */ new Set(["$condition", "$where"]);
|
|
36
|
+
var routeGuard = (requirement, middleware) => Object.defineProperty(middleware, ROUTE_GUARD, { value: requirement });
|
|
37
|
+
var forbidden = (c, message, details) => {
|
|
38
|
+
c.status(httpStatus.FORBIDDEN);
|
|
39
|
+
return c.json(__spreadValues({ code: "FORBIDDEN", message }, details));
|
|
40
|
+
};
|
|
41
|
+
var deny = (c, denial, details) => {
|
|
42
|
+
if (denial.status === 403 && denial.fields) {
|
|
43
|
+
c.status(httpStatus.FORBIDDEN);
|
|
44
|
+
return c.json(__spreadValues({
|
|
45
|
+
code: "FORBIDDEN_FIELDS",
|
|
46
|
+
message: denial.message,
|
|
47
|
+
fields: denial.fields
|
|
48
|
+
}, details));
|
|
49
|
+
}
|
|
50
|
+
if (denial.status === 403) return forbidden(c, denial.message, details);
|
|
51
|
+
c.status(httpStatus.NOT_FOUND);
|
|
52
|
+
return c.json(__spreadValues({ code: "NOT_FOUND" }, details));
|
|
53
|
+
};
|
|
54
|
+
var allowsEntityAction = (access, action) => action === "delete" || action === "list" ? access[action] : access[action] !== null;
|
|
55
|
+
var restrictedKey = (c) => {
|
|
56
|
+
const key = c.get("apiKey");
|
|
57
|
+
return key && !key.access.full ? key : void 0;
|
|
58
|
+
};
|
|
59
|
+
var jsonBody = (c) => __async(null, null, function* () {
|
|
60
|
+
try {
|
|
61
|
+
return yield c.req.json();
|
|
62
|
+
} catch (e) {
|
|
63
|
+
return void 0;
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
var createRouteGuards = (entityConfig) => {
|
|
67
|
+
const checkEntity = (key, entityType, action) => {
|
|
68
|
+
const access = key.access.entity(entityType);
|
|
69
|
+
if (!access.visible) return { status: 404 };
|
|
70
|
+
if (allowsEntityAction(access, action)) return null;
|
|
71
|
+
return {
|
|
72
|
+
status: 403,
|
|
73
|
+
message: `API key policy '${key.policy}' does not allow ${action} on '${entityType}'`
|
|
74
|
+
};
|
|
75
|
+
};
|
|
76
|
+
const asEntityType = (byEntityType, entityType) => {
|
|
77
|
+
var _a;
|
|
78
|
+
const declared = (from, to) => {
|
|
79
|
+
var _a2, _b, _c, _d, _e, _f;
|
|
80
|
+
return (_f = (_e = (_d = Object.values((_c = (_b = (_a2 = entityConfig[from]) == null ? void 0 : _a2.mutual) == null ? void 0 : _b.mutualFields) != null ? _c : {}).find(
|
|
81
|
+
(field) => field.entityType === to && field.mutual
|
|
82
|
+
)) == null ? void 0 : _d.mutual) == null ? void 0 : _e.asEntity) == null ? void 0 : _f.name;
|
|
83
|
+
};
|
|
84
|
+
return (_a = declared(byEntityType, entityType)) != null ? _a : declared(entityType, byEntityType);
|
|
85
|
+
};
|
|
86
|
+
const checkDirection = (key, byEntityType, entityType, action, requestedAsEntity) => {
|
|
87
|
+
const access = key.access.mutual(byEntityType, entityType);
|
|
88
|
+
if (!access) return { status: 404 };
|
|
89
|
+
const granted = action === "delete" ? access.delete : access[action] !== null;
|
|
90
|
+
if (!granted) {
|
|
91
|
+
return {
|
|
92
|
+
status: 403,
|
|
93
|
+
message: `API key policy '${key.policy}' does not allow ${action} on ${byEntityType}\u2192${entityType}`
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
const asEntity = action === "create" ? requestedAsEntity || asEntityType(byEntityType, entityType) : void 0;
|
|
97
|
+
if (asEntity && !key.access.entity(asEntity).create) {
|
|
98
|
+
return {
|
|
99
|
+
status: 403,
|
|
100
|
+
message: `API key policy '${key.policy}' does not allow create on '${asEntity}', which ${byEntityType}\u2192${entityType} creates`
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
return null;
|
|
104
|
+
};
|
|
105
|
+
const quoted = (fields) => fields.map((field) => `'${field}'`).join(", ");
|
|
106
|
+
const checkFields = (key, granted, fields, what) => {
|
|
107
|
+
const disallowed = granted === "*" ? [] : fields.filter((field) => !(granted == null ? void 0 : granted.has(field)));
|
|
108
|
+
if (!disallowed.length) return null;
|
|
109
|
+
return {
|
|
110
|
+
status: 403,
|
|
111
|
+
message: `API key policy '${key.policy}' does not allow ${what}: ${quoted(disallowed)}`,
|
|
112
|
+
fields: disallowed
|
|
113
|
+
};
|
|
114
|
+
};
|
|
115
|
+
const relationshipFieldNames = (entityType) => {
|
|
116
|
+
var _a, _b, _c;
|
|
117
|
+
return new Set(Object.keys((_c = (_b = (_a = entityConfig[entityType]) == null ? void 0 : _a.mutual) == null ? void 0 : _b.mutualFields) != null ? _c : {}));
|
|
118
|
+
};
|
|
119
|
+
const dataFields = (entityType, payload) => {
|
|
120
|
+
if (typeof payload !== "object" || payload === null) return [];
|
|
121
|
+
const relationships = relationshipFieldNames(entityType);
|
|
122
|
+
return Object.keys(payload).filter(
|
|
123
|
+
(field) => !NOT_DATA.has(field) && !relationships.has(field)
|
|
124
|
+
);
|
|
125
|
+
};
|
|
126
|
+
const createFields = (entityType, payload, choosesEntityId) => {
|
|
127
|
+
const fields = dataFields(entityType, payload).map(
|
|
128
|
+
(field) => field === "entityId" ? "$entityId" : field === "createdAt" ? "$createdAt" : field
|
|
129
|
+
);
|
|
130
|
+
if (choosesEntityId && !fields.includes("$entityId")) {
|
|
131
|
+
fields.push("$entityId");
|
|
132
|
+
}
|
|
133
|
+
return fields;
|
|
134
|
+
};
|
|
135
|
+
const checkRelationshipFields = (key, entityType, payload, write) => {
|
|
136
|
+
var _a, _b, _c;
|
|
137
|
+
if (typeof payload !== "object" || payload === null) return null;
|
|
138
|
+
const relationshipFields = (_b = (_a = entityConfig[entityType]) == null ? void 0 : _a.mutual) == null ? void 0 : _b.mutualFields;
|
|
139
|
+
if (!relationshipFields) return null;
|
|
140
|
+
const actions = write === "create" ? ["create"] : ["create", "delete"];
|
|
141
|
+
for (const field of Object.keys(payload)) {
|
|
142
|
+
const target = (_c = relationshipFields[field]) == null ? void 0 : _c.entityType;
|
|
143
|
+
if (!target) continue;
|
|
144
|
+
for (const action of actions) {
|
|
145
|
+
const denial = checkDirection(key, entityType, target, action);
|
|
146
|
+
if (denial) return denial;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
return null;
|
|
150
|
+
};
|
|
151
|
+
const checkCreate = (key, entityType, payload, choosesEntityId) => {
|
|
152
|
+
var _a;
|
|
153
|
+
return (_a = checkRelationshipFields(key, entityType, payload, "create")) != null ? _a : checkFields(
|
|
154
|
+
key,
|
|
155
|
+
key.access.entity(entityType).create,
|
|
156
|
+
createFields(entityType, payload, choosesEntityId),
|
|
157
|
+
`create on these fields of '${entityType}'`
|
|
158
|
+
);
|
|
159
|
+
};
|
|
160
|
+
const checkUpdate = (key, entityType, payload) => {
|
|
161
|
+
var _a, _b;
|
|
162
|
+
const access = key.access.entity(entityType);
|
|
163
|
+
const where = payload == null ? void 0 : payload.$where;
|
|
164
|
+
return (_b = (_a = checkRelationshipFields(key, entityType, payload, "update")) != null ? _a : checkFields(
|
|
165
|
+
key,
|
|
166
|
+
access.update,
|
|
167
|
+
dataFields(entityType, payload),
|
|
168
|
+
`update on these fields of '${entityType}'`
|
|
169
|
+
)) != null ? _b : typeof where === "object" && where !== null ? checkFields(
|
|
170
|
+
key,
|
|
171
|
+
access.read,
|
|
172
|
+
Object.keys(where),
|
|
173
|
+
`$where on these fields of '${entityType}', which it cannot read`
|
|
174
|
+
) : null;
|
|
175
|
+
};
|
|
176
|
+
const checkAdjust = (key, entityType, adjustments) => checkFields(
|
|
177
|
+
key,
|
|
178
|
+
key.access.entity(entityType).update,
|
|
179
|
+
dataFields(entityType, adjustments),
|
|
180
|
+
`adjust on these fields of '${entityType}'`
|
|
181
|
+
);
|
|
182
|
+
const checkSearch = (key, entityType) => {
|
|
183
|
+
var _a, _b;
|
|
184
|
+
return checkFields(
|
|
185
|
+
key,
|
|
186
|
+
key.access.entity(entityType).read,
|
|
187
|
+
((_b = (_a = entityConfig[entityType]) == null ? void 0 : _a.searchableFields) != null ? _b : []).map(String),
|
|
188
|
+
`search on '${entityType}', which matches these fields it cannot read`
|
|
189
|
+
);
|
|
190
|
+
};
|
|
191
|
+
const checkUniqueLookup = (key, entityType, field) => checkFields(
|
|
192
|
+
key,
|
|
193
|
+
key.access.entity(entityType).read,
|
|
194
|
+
[field],
|
|
195
|
+
`a lookup on '${entityType}' by a field it cannot read`
|
|
196
|
+
);
|
|
197
|
+
const checkTag = (key, entityType, tagName) => {
|
|
198
|
+
const { tags } = key.access.entity(entityType);
|
|
199
|
+
if (tags === "*" || (tags == null ? void 0 : tags.has(tagName))) return null;
|
|
200
|
+
return {
|
|
201
|
+
status: 403,
|
|
202
|
+
message: `API key policy '${key.policy}' does not allow reading tag '${tagName}' of '${entityType}'`
|
|
203
|
+
};
|
|
204
|
+
};
|
|
205
|
+
const entity = (route) => routeGuard(
|
|
206
|
+
`entity:${route}`,
|
|
207
|
+
createMiddleware((c, next) => __async(null, null, function* () {
|
|
208
|
+
var _a, _b, _c, _d;
|
|
209
|
+
const key = restrictedKey(c);
|
|
210
|
+
if (key) {
|
|
211
|
+
const entityType = (_a = c.req.param("entityType")) != null ? _a : "";
|
|
212
|
+
for (const action of ENTITY_ROUTE_ACTIONS[route]) {
|
|
213
|
+
const denial2 = checkEntity(key, entityType, action);
|
|
214
|
+
if (denial2) return deny(c, denial2);
|
|
215
|
+
}
|
|
216
|
+
let denial = null;
|
|
217
|
+
if (route === "list" && c.req.query("query")) {
|
|
218
|
+
denial = checkSearch(key, entityType);
|
|
219
|
+
} else if (route === "unique") {
|
|
220
|
+
denial = checkUniqueLookup(
|
|
221
|
+
key,
|
|
222
|
+
entityType,
|
|
223
|
+
(_b = c.req.param("uniqueField")) != null ? _b : ""
|
|
224
|
+
);
|
|
225
|
+
} else if (route === "tag") {
|
|
226
|
+
denial = checkTag(key, entityType, (_c = c.req.param("tagName")) != null ? _c : "");
|
|
227
|
+
} else if (route === "create") {
|
|
228
|
+
denial = checkCreate(key, entityType, yield jsonBody(c), false);
|
|
229
|
+
} else if (route === "update") {
|
|
230
|
+
denial = checkUpdate(key, entityType, yield jsonBody(c));
|
|
231
|
+
} else if (route === "upsert") {
|
|
232
|
+
const body = yield jsonBody(c);
|
|
233
|
+
denial = (_d = checkCreate(key, entityType, body, true)) != null ? _d : checkUpdate(key, entityType, body);
|
|
234
|
+
} else if (route === "adjust") {
|
|
235
|
+
denial = checkAdjust(key, entityType, yield jsonBody(c));
|
|
236
|
+
}
|
|
237
|
+
if (denial) return deny(c, denial);
|
|
238
|
+
}
|
|
239
|
+
yield next();
|
|
240
|
+
}))
|
|
241
|
+
);
|
|
242
|
+
const checkMutualData = (key, byEntityType, entityType, action, payload) => {
|
|
243
|
+
var _a, _b;
|
|
244
|
+
return typeof payload === "object" && payload !== null ? checkFields(
|
|
245
|
+
key,
|
|
246
|
+
(_b = (_a = key.access.mutual(byEntityType, entityType)) == null ? void 0 : _a[action]) != null ? _b : null,
|
|
247
|
+
Object.keys(payload),
|
|
248
|
+
`${action} on these mutualData fields of ${byEntityType}\u2192${entityType}`
|
|
249
|
+
) : null;
|
|
250
|
+
};
|
|
251
|
+
const mutual = (action) => routeGuard(
|
|
252
|
+
`mutual:${action}`,
|
|
253
|
+
createMiddleware((c, next) => __async(null, null, function* () {
|
|
254
|
+
var _a, _b;
|
|
255
|
+
const key = restrictedKey(c);
|
|
256
|
+
if (key) {
|
|
257
|
+
const byEntityType = (_a = c.req.param("byEntityType")) != null ? _a : "";
|
|
258
|
+
const entityType = (_b = c.req.param("entityType")) != null ? _b : "";
|
|
259
|
+
const chain = c.req.query("chainEntityQuery");
|
|
260
|
+
const path = action === "read" && chain ? [byEntityType, ...chain.split(","), entityType] : [byEntityType, entityType];
|
|
261
|
+
const requestedAsEntity = action === "create" ? c.req.query("asEntity") : void 0;
|
|
262
|
+
for (let hop = 1; hop < path.length; hop++) {
|
|
263
|
+
const denial = checkDirection(
|
|
264
|
+
key,
|
|
265
|
+
path[hop - 1],
|
|
266
|
+
path[hop],
|
|
267
|
+
action,
|
|
268
|
+
requestedAsEntity
|
|
269
|
+
);
|
|
270
|
+
if (denial) return deny(c, denial);
|
|
271
|
+
}
|
|
272
|
+
if (action === "create" || action === "update") {
|
|
273
|
+
const denial = checkMutualData(
|
|
274
|
+
key,
|
|
275
|
+
byEntityType,
|
|
276
|
+
entityType,
|
|
277
|
+
action,
|
|
278
|
+
yield jsonBody(c)
|
|
279
|
+
);
|
|
280
|
+
if (denial) return deny(c, denial);
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
yield next();
|
|
284
|
+
}))
|
|
285
|
+
);
|
|
286
|
+
const checkOperation = (key, operation) => {
|
|
287
|
+
var _a, _b, _c, _d, _e;
|
|
288
|
+
switch (operation == null ? void 0 : operation.operation) {
|
|
289
|
+
case "createEntity":
|
|
290
|
+
return (_a = checkEntity(key, operation.entityType, "create")) != null ? _a : checkCreate(
|
|
291
|
+
key,
|
|
292
|
+
operation.entityType,
|
|
293
|
+
operation.payload,
|
|
294
|
+
Boolean(operation.entityId)
|
|
295
|
+
);
|
|
296
|
+
case "updateEntity":
|
|
297
|
+
return (_b = checkEntity(key, operation.entityType, "update")) != null ? _b : checkUpdate(key, operation.entityType, operation.payload);
|
|
298
|
+
case "adjustEntity":
|
|
299
|
+
return (_c = checkEntity(key, operation.entityType, "update")) != null ? _c : checkAdjust(key, operation.entityType, operation.adjustments);
|
|
300
|
+
case "deleteEntity":
|
|
301
|
+
return checkEntity(key, operation.entityType, "delete");
|
|
302
|
+
case "createMutual":
|
|
303
|
+
return (_d = checkDirection(
|
|
304
|
+
key,
|
|
305
|
+
operation.byEntityType,
|
|
306
|
+
operation.entityType,
|
|
307
|
+
"create"
|
|
308
|
+
)) != null ? _d : checkMutualData(
|
|
309
|
+
key,
|
|
310
|
+
operation.byEntityType,
|
|
311
|
+
operation.entityType,
|
|
312
|
+
"create",
|
|
313
|
+
operation.payload
|
|
314
|
+
);
|
|
315
|
+
case "updateMutual":
|
|
316
|
+
return (_e = checkDirection(
|
|
317
|
+
key,
|
|
318
|
+
operation.byEntityType,
|
|
319
|
+
operation.entityType,
|
|
320
|
+
"update"
|
|
321
|
+
)) != null ? _e : checkMutualData(
|
|
322
|
+
key,
|
|
323
|
+
operation.byEntityType,
|
|
324
|
+
operation.entityType,
|
|
325
|
+
"update",
|
|
326
|
+
operation.payload
|
|
327
|
+
);
|
|
328
|
+
case "deleteMutual":
|
|
329
|
+
return checkDirection(
|
|
330
|
+
key,
|
|
331
|
+
operation.byEntityType,
|
|
332
|
+
operation.entityType,
|
|
333
|
+
"delete"
|
|
334
|
+
);
|
|
335
|
+
default:
|
|
336
|
+
return null;
|
|
337
|
+
}
|
|
338
|
+
};
|
|
339
|
+
const transaction = () => routeGuard(
|
|
340
|
+
"transaction",
|
|
341
|
+
createMiddleware((c, next) => __async(null, null, function* () {
|
|
342
|
+
var _a;
|
|
343
|
+
const key = restrictedKey(c);
|
|
344
|
+
if (!key) return next();
|
|
345
|
+
const operations = (_a = yield jsonBody(c)) == null ? void 0 : _a.operations;
|
|
346
|
+
if (!Array.isArray(operations)) return next();
|
|
347
|
+
for (const [operationIndex, operation] of operations.entries()) {
|
|
348
|
+
const denial = checkOperation(key, operation);
|
|
349
|
+
if (denial) return deny(c, denial, { operationIndex });
|
|
350
|
+
}
|
|
351
|
+
yield next();
|
|
352
|
+
}))
|
|
353
|
+
);
|
|
354
|
+
return { entity, mutual, transaction };
|
|
355
|
+
};
|
|
356
|
+
var requireFullPolicy = () => routeGuard(
|
|
357
|
+
"full",
|
|
358
|
+
createMiddleware((c, next) => __async(null, null, function* () {
|
|
359
|
+
const key = restrictedKey(c);
|
|
360
|
+
if (key) {
|
|
361
|
+
return forbidden(
|
|
362
|
+
c,
|
|
363
|
+
`API key policy '${key.policy}' cannot call this route; only 'full' can`
|
|
364
|
+
);
|
|
365
|
+
}
|
|
366
|
+
yield next();
|
|
367
|
+
}))
|
|
368
|
+
);
|
|
369
|
+
var requires = (permission) => Object.defineProperty(
|
|
370
|
+
createMiddleware((c, next) => __async(null, null, function* () {
|
|
371
|
+
const key = restrictedKey(c);
|
|
372
|
+
if (key && !key.has(permission)) {
|
|
373
|
+
return forbidden(
|
|
374
|
+
c,
|
|
375
|
+
`API key policy '${key.policy}' does not grant '${permission}'`
|
|
376
|
+
);
|
|
377
|
+
}
|
|
378
|
+
yield next();
|
|
379
|
+
})),
|
|
380
|
+
ROUTE_PERMISSION,
|
|
381
|
+
{ value: permission }
|
|
382
|
+
);
|
|
383
|
+
var customRouteGate = () => createMiddleware((c, next) => __async(null, null, function* () {
|
|
384
|
+
const key = restrictedKey(c);
|
|
385
|
+
if (key) {
|
|
386
|
+
const permissions = c.req.matchedRoutes.flatMap((route) => {
|
|
387
|
+
const permission = route.handler[ROUTE_PERMISSION];
|
|
388
|
+
return typeof permission === "string" ? [permission] : [];
|
|
389
|
+
});
|
|
390
|
+
if (!permissions.length) {
|
|
391
|
+
return forbidden(
|
|
392
|
+
c,
|
|
393
|
+
"This route declares no permission with requires(), so only 'full' keys can call it"
|
|
394
|
+
);
|
|
395
|
+
}
|
|
396
|
+
const missing = permissions.find((permission) => !key.has(permission));
|
|
397
|
+
if (missing !== void 0) {
|
|
398
|
+
return forbidden(
|
|
399
|
+
c,
|
|
400
|
+
`API key policy '${key.policy}' does not grant '${missing}'`
|
|
401
|
+
);
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
yield next();
|
|
405
|
+
}));
|
|
406
|
+
|
|
407
|
+
// middlewares/entity-type-check.ts
|
|
408
|
+
import { createMiddleware as createMiddleware2 } from "hono/factory";
|
|
409
|
+
import httpStatus2 from "http-status";
|
|
410
|
+
var entityTypeCheck = (container) => createMiddleware2((c, next) => __async(null, null, function* () {
|
|
21
411
|
const { entityType } = c.req.param();
|
|
22
412
|
if (!container.config.AllowedEntityTypes.includes(entityType)) {
|
|
23
|
-
c.status(
|
|
413
|
+
c.status(httpStatus2.NOT_FOUND);
|
|
24
414
|
return c.json({
|
|
25
415
|
code: "NOT_FOUND"
|
|
26
416
|
});
|
|
@@ -28,13 +418,65 @@ var entityTypeCheck = (container) => createMiddleware((c, next) => __async(null,
|
|
|
28
418
|
yield next();
|
|
29
419
|
}));
|
|
30
420
|
|
|
421
|
+
// middlewares/mask.ts
|
|
422
|
+
import { createMiddleware as createMiddleware3 } from "hono/factory";
|
|
423
|
+
var isPlainObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
424
|
+
var maskFields = (data, granted) => granted === "*" ? data : Object.fromEntries(
|
|
425
|
+
Object.entries(data).filter(([field]) => granted == null ? void 0 : granted.has(field))
|
|
426
|
+
);
|
|
427
|
+
var maskRecord = (record, access) => {
|
|
428
|
+
var _a, _b;
|
|
429
|
+
const entityType = record.entityType;
|
|
430
|
+
const masked = __spreadValues({}, record);
|
|
431
|
+
if (isPlainObject(record.data)) {
|
|
432
|
+
masked.data = maskFields(record.data, access.entity(entityType).read);
|
|
433
|
+
}
|
|
434
|
+
if (typeof record.byEntityType === "string" && isPlainObject(record.mutualData)) {
|
|
435
|
+
masked.mutualData = maskFields(
|
|
436
|
+
record.mutualData,
|
|
437
|
+
(_b = (_a = access.mutual(record.byEntityType, entityType)) == null ? void 0 : _a.read) != null ? _b : null
|
|
438
|
+
);
|
|
439
|
+
}
|
|
440
|
+
return masked;
|
|
441
|
+
};
|
|
442
|
+
var maskResponseBody = (body, access) => {
|
|
443
|
+
if (Array.isArray(body))
|
|
444
|
+
return body.map((item) => maskResponseBody(item, access));
|
|
445
|
+
if (!isPlainObject(body)) return body;
|
|
446
|
+
if (typeof body.entityType === "string" && ("data" in body || "mutualData" in body)) {
|
|
447
|
+
return maskRecord(body, access);
|
|
448
|
+
}
|
|
449
|
+
return Object.fromEntries(
|
|
450
|
+
Object.entries(body).map(([key, value]) => [
|
|
451
|
+
key,
|
|
452
|
+
maskResponseBody(value, access)
|
|
453
|
+
])
|
|
454
|
+
);
|
|
455
|
+
};
|
|
456
|
+
var maskResponses = () => createMiddleware3((c, next) => __async(null, null, function* () {
|
|
457
|
+
var _a;
|
|
458
|
+
yield next();
|
|
459
|
+
const key = c.get("apiKey");
|
|
460
|
+
if (!key || key.access.full || !c.res.ok) return;
|
|
461
|
+
if (!((_a = c.res.headers.get("content-type")) == null ? void 0 : _a.includes("application/json"))) {
|
|
462
|
+
return;
|
|
463
|
+
}
|
|
464
|
+
const body = yield c.res.json();
|
|
465
|
+
const headers = new Headers(c.res.headers);
|
|
466
|
+
headers.delete("content-length");
|
|
467
|
+
c.res = new Response(JSON.stringify(maskResponseBody(body, key.access)), {
|
|
468
|
+
status: c.res.status,
|
|
469
|
+
headers
|
|
470
|
+
});
|
|
471
|
+
}));
|
|
472
|
+
|
|
31
473
|
// middlewares/mutual-type-check.ts
|
|
32
|
-
import { createMiddleware as
|
|
33
|
-
import
|
|
34
|
-
var mutualTypeCheck = (container) =>
|
|
474
|
+
import { createMiddleware as createMiddleware4 } from "hono/factory";
|
|
475
|
+
import httpStatus3 from "http-status";
|
|
476
|
+
var mutualTypeCheck = (container) => createMiddleware4((c, next) => __async(null, null, function* () {
|
|
35
477
|
const { entityType, byEntityType } = c.req.param();
|
|
36
478
|
if (!container.config.AllowedEntityTypes.includes(entityType) || !container.config.AllowedEntityTypes.includes(byEntityType)) {
|
|
37
|
-
c.status(
|
|
479
|
+
c.status(httpStatus3.NOT_FOUND);
|
|
38
480
|
return c.json({
|
|
39
481
|
code: "NOT_FOUND"
|
|
40
482
|
});
|
|
@@ -45,61 +487,91 @@ var mutualTypeCheck = (container) => createMiddleware2((c, next) => __async(null
|
|
|
45
487
|
// controllers/setupRoutes.ts
|
|
46
488
|
var setupCommonRoutes = (container) => {
|
|
47
489
|
const app = new Hono();
|
|
490
|
+
const guard = createRouteGuards(container.config.EntityConfig);
|
|
491
|
+
app.use("*", maskResponses());
|
|
48
492
|
app.use(
|
|
49
493
|
"/mutual/:byEntityType/:byEntityId/:entityType",
|
|
50
494
|
mutualTypeCheck(container)
|
|
51
495
|
);
|
|
52
496
|
app.get(
|
|
53
497
|
"/mutual/:byEntityType/:byEntityId/:entityType",
|
|
498
|
+
guard.mutual("read"),
|
|
54
499
|
container.listEntitiesByEntityController.controller
|
|
55
500
|
);
|
|
56
501
|
app.post(
|
|
57
502
|
"/mutual/:byEntityType/:byEntityId/:entityType/:entityId",
|
|
503
|
+
guard.mutual("create"),
|
|
58
504
|
container.createMutualController.controller
|
|
59
505
|
);
|
|
60
506
|
app.get(
|
|
61
507
|
"/mutual/:byEntityType/:byEntityId/:entityType/:entityId",
|
|
508
|
+
guard.mutual("read"),
|
|
62
509
|
container.getMutualController.controller
|
|
63
510
|
);
|
|
64
511
|
app.patch(
|
|
65
512
|
"/mutual/:byEntityType/:byEntityId/:entityType/:entityId",
|
|
513
|
+
guard.mutual("update"),
|
|
66
514
|
container.updateMutualController.controller
|
|
67
515
|
);
|
|
68
516
|
app.delete(
|
|
69
517
|
"/mutual/:byEntityType/:byEntityId/:entityType/:entityId",
|
|
518
|
+
guard.mutual("delete"),
|
|
70
519
|
container.deleteMutualController.controller
|
|
71
520
|
);
|
|
72
521
|
app.use("/entity/:entityType", entityTypeCheck(container));
|
|
73
|
-
app.get(
|
|
74
|
-
|
|
522
|
+
app.get(
|
|
523
|
+
"/entity/:entityType",
|
|
524
|
+
guard.entity("list"),
|
|
525
|
+
container.listEntitiesController.controller
|
|
526
|
+
);
|
|
527
|
+
app.post(
|
|
528
|
+
"/entity/:entityType",
|
|
529
|
+
guard.entity("create"),
|
|
530
|
+
container.createEntityController.controller
|
|
531
|
+
);
|
|
75
532
|
app.get(
|
|
76
533
|
"/entity/:entityType/unique/:uniqueField/:uniqueFieldValue",
|
|
534
|
+
guard.entity("unique"),
|
|
77
535
|
container.getEntityByUniqueFieldController.controller
|
|
78
536
|
);
|
|
79
537
|
app.post(
|
|
80
538
|
"/entity/:entityType/:entityId/adjust",
|
|
539
|
+
guard.entity("adjust"),
|
|
81
540
|
container.adjustEntityController.controller
|
|
82
541
|
);
|
|
83
542
|
app.get(
|
|
84
543
|
"/entity/:entityType/:entityId",
|
|
544
|
+
guard.entity("read"),
|
|
85
545
|
container.getEntityController.controller
|
|
86
546
|
);
|
|
87
547
|
app.put(
|
|
88
548
|
"/entity/:entityType/:entityId",
|
|
549
|
+
guard.entity("upsert"),
|
|
89
550
|
container.upsertEntityController.controller
|
|
90
551
|
);
|
|
91
552
|
app.patch(
|
|
92
553
|
"/entity/:entityType/:entityId",
|
|
554
|
+
guard.entity("update"),
|
|
93
555
|
container.updateEntityController.controller
|
|
94
556
|
);
|
|
95
557
|
app.delete(
|
|
96
558
|
"/entity/:entityType/:entityId",
|
|
559
|
+
guard.entity("delete"),
|
|
97
560
|
container.deleteEntityController.controller
|
|
98
561
|
);
|
|
99
|
-
app.get(
|
|
100
|
-
|
|
562
|
+
app.get(
|
|
563
|
+
"/tag/:entityType/:tagName",
|
|
564
|
+
guard.entity("tag"),
|
|
565
|
+
container.listTagsController.controller
|
|
566
|
+
);
|
|
567
|
+
app.post(
|
|
568
|
+
"/transaction",
|
|
569
|
+
guard.transaction(),
|
|
570
|
+
container.executeTransactionController.controller
|
|
571
|
+
);
|
|
101
572
|
app.post(
|
|
102
573
|
"/ws/ticket/:entityType/:entityId",
|
|
574
|
+
requireFullPolicy(),
|
|
103
575
|
container.createTicketController.controller
|
|
104
576
|
);
|
|
105
577
|
return app;
|
|
@@ -523,7 +995,10 @@ var EntityRepository = class extends Repository {
|
|
|
523
995
|
var _a;
|
|
524
996
|
const resp = yield this.dynamodbClient.query({
|
|
525
997
|
TableName: this.TABLE_NAME,
|
|
526
|
-
|
|
998
|
+
// Exact match: a unique item's SK is the bare entity type, so a prefix
|
|
999
|
+
// match would also return another type whose name starts with this one
|
|
1000
|
+
// (e.g. 'user' matching 'user-profile').
|
|
1001
|
+
KeyConditionExpression: "#PK = :PK and #SK = :SK",
|
|
527
1002
|
ExpressionAttributeNames: {
|
|
528
1003
|
"#PK": "PK",
|
|
529
1004
|
"#SK": "SK"
|
|
@@ -541,7 +1016,8 @@ var EntityRepository = class extends Repository {
|
|
|
541
1016
|
var _a;
|
|
542
1017
|
const resp = yield this.dynamodbClient.query({
|
|
543
1018
|
TableName: this.TABLE_NAME,
|
|
544
|
-
|
|
1019
|
+
// Exact match, as in getEntityByUniqueField.
|
|
1020
|
+
KeyConditionExpression: "#PK = :PK and #SK = :SK",
|
|
545
1021
|
ExpressionAttributeNames: {
|
|
546
1022
|
"#PK": "PK",
|
|
547
1023
|
"#SK": "SK"
|
|
@@ -2298,25 +2774,155 @@ import { cors } from "hono/cors";
|
|
|
2298
2774
|
import { secureHeaders } from "hono/secure-headers";
|
|
2299
2775
|
|
|
2300
2776
|
// middlewares/api-key-auth.ts
|
|
2777
|
+
import { createHash } from "crypto";
|
|
2778
|
+
import {
|
|
2779
|
+
FULL_API_KEY_POLICY,
|
|
2780
|
+
compileApiKeyPolicy,
|
|
2781
|
+
validateApiKeyPolicies
|
|
2782
|
+
} from "../base/index.js";
|
|
2301
2783
|
import { createFactory } from "hono/factory";
|
|
2302
|
-
import
|
|
2784
|
+
import httpStatus4 from "http-status";
|
|
2785
|
+
|
|
2786
|
+
// helpers/request-context.ts
|
|
2787
|
+
import { AsyncLocalStorage } from "async_hooks";
|
|
2788
|
+
var storage = new AsyncLocalStorage();
|
|
2789
|
+
var runWithApiKey = (apiKey, fn) => storage.run(apiKey, fn);
|
|
2790
|
+
var currentApiKey = () => storage.getStore();
|
|
2791
|
+
|
|
2792
|
+
// middlewares/api-key-auth.ts
|
|
2793
|
+
var SHA256_PREFIX = "sha256:";
|
|
2794
|
+
var createPrincipal = (policy, access) => ({
|
|
2795
|
+
policy,
|
|
2796
|
+
access,
|
|
2797
|
+
can: (action, entityType, fields) => {
|
|
2798
|
+
const entity = access.entity(entityType);
|
|
2799
|
+
if (action === "delete") return entity.delete;
|
|
2800
|
+
if (action === "list" && !entity.list) return false;
|
|
2801
|
+
const granted = entity[action === "list" ? "read" : action];
|
|
2802
|
+
if (granted === null) return false;
|
|
2803
|
+
return !fields || granted === "*" || fields.every((f) => granted.has(f));
|
|
2804
|
+
},
|
|
2805
|
+
has: (permission) => access.allowsRoute(permission),
|
|
2806
|
+
mask: (entityType, entity) => {
|
|
2807
|
+
const record = typeof entity.toJSON === "function" ? entity.toJSON() : entity;
|
|
2808
|
+
return maskRecord(__spreadProps(__spreadValues({}, record), { entityType }), access);
|
|
2809
|
+
}
|
|
2810
|
+
});
|
|
2811
|
+
var fingerprintApiKey = (key) => createHash("sha256").update(key).digest("hex");
|
|
2812
|
+
var SHA256_DIGEST = /^[0-9a-f]{64}$/i;
|
|
2813
|
+
var toFingerprint = (entry, where) => {
|
|
2814
|
+
if (!entry.startsWith(SHA256_PREFIX)) return fingerprintApiKey(entry);
|
|
2815
|
+
const digest = entry.slice(SHA256_PREFIX.length);
|
|
2816
|
+
if (!SHA256_DIGEST.test(digest)) {
|
|
2817
|
+
console.error(
|
|
2818
|
+
`[monorise] API_KEYS: a '${SHA256_PREFIX}' entry in ${where} isn't a 64-character hex SHA-256 digest and will be rejected`
|
|
2819
|
+
);
|
|
2820
|
+
return void 0;
|
|
2821
|
+
}
|
|
2822
|
+
return digest.toLowerCase();
|
|
2823
|
+
};
|
|
2824
|
+
var assertKeyList = (value, where) => {
|
|
2825
|
+
if (!Array.isArray(value) || !value.every((key) => typeof key === "string" && key.length > 0)) {
|
|
2826
|
+
throw new Error(
|
|
2827
|
+
`[monorise] API_KEYS: ${where} must be an array of non-empty strings`
|
|
2828
|
+
);
|
|
2829
|
+
}
|
|
2830
|
+
return value;
|
|
2831
|
+
};
|
|
2832
|
+
var parseApiKeys = (raw, definedPolicies = [FULL_API_KEY_POLICY]) => {
|
|
2833
|
+
var _a;
|
|
2834
|
+
const fingerprints = /* @__PURE__ */ new Map();
|
|
2835
|
+
if (!raw) return fingerprints;
|
|
2836
|
+
const parsed = JSON.parse(raw);
|
|
2837
|
+
if (Array.isArray(parsed)) {
|
|
2838
|
+
for (const key of assertKeyList(parsed, "the array form")) {
|
|
2839
|
+
const fingerprint = toFingerprint(key, "the array form");
|
|
2840
|
+
if (fingerprint) fingerprints.set(fingerprint, FULL_API_KEY_POLICY);
|
|
2841
|
+
}
|
|
2842
|
+
return fingerprints;
|
|
2843
|
+
}
|
|
2844
|
+
if (typeof parsed !== "object" || parsed === null) {
|
|
2845
|
+
throw new Error(
|
|
2846
|
+
"[monorise] API_KEYS must be a JSON array of keys or an object mapping policy names to keys"
|
|
2847
|
+
);
|
|
2848
|
+
}
|
|
2849
|
+
const policiesByFingerprint = /* @__PURE__ */ new Map();
|
|
2850
|
+
for (const [policy, keys] of Object.entries(parsed)) {
|
|
2851
|
+
const keyList = assertKeyList(keys, `policy '${policy}'`);
|
|
2852
|
+
if (!definedPolicies.includes(policy)) {
|
|
2853
|
+
console.error(
|
|
2854
|
+
`[monorise] API_KEYS: policy '${policy}' is not defined; its ${keyList.length} key(s) will be rejected`
|
|
2855
|
+
);
|
|
2856
|
+
}
|
|
2857
|
+
for (const key of keyList) {
|
|
2858
|
+
const fingerprint = toFingerprint(key, `policy '${policy}'`);
|
|
2859
|
+
if (!fingerprint) continue;
|
|
2860
|
+
const policies = (_a = policiesByFingerprint.get(fingerprint)) != null ? _a : /* @__PURE__ */ new Set();
|
|
2861
|
+
policies.add(policy);
|
|
2862
|
+
policiesByFingerprint.set(fingerprint, policies);
|
|
2863
|
+
}
|
|
2864
|
+
}
|
|
2865
|
+
for (const [fingerprint, policies] of policiesByFingerprint) {
|
|
2866
|
+
if (policies.size > 1) {
|
|
2867
|
+
console.error(
|
|
2868
|
+
`[monorise] API_KEYS: key ${fingerprint.slice(0, 12)}\u2026 is listed under more than one policy (${[...policies].join(", ")}) and will be rejected`
|
|
2869
|
+
);
|
|
2870
|
+
continue;
|
|
2871
|
+
}
|
|
2872
|
+
const [policy] = policies;
|
|
2873
|
+
if (definedPolicies.includes(policy)) fingerprints.set(fingerprint, policy);
|
|
2874
|
+
}
|
|
2875
|
+
return fingerprints;
|
|
2876
|
+
};
|
|
2303
2877
|
var factory = createFactory();
|
|
2304
|
-
var
|
|
2305
|
-
|
|
2306
|
-
const
|
|
2307
|
-
|
|
2308
|
-
|
|
2309
|
-
|
|
2310
|
-
|
|
2311
|
-
|
|
2312
|
-
|
|
2313
|
-
|
|
2314
|
-
|
|
2315
|
-
|
|
2878
|
+
var createApiKeyAuth = (fingerprints, policies = {}) => {
|
|
2879
|
+
const principals = /* @__PURE__ */ new Map();
|
|
2880
|
+
const principalFor = (name) => {
|
|
2881
|
+
let principal = principals.get(name);
|
|
2882
|
+
if (!principal) {
|
|
2883
|
+
principal = createPrincipal(
|
|
2884
|
+
name,
|
|
2885
|
+
compileApiKeyPolicy(name, policies[name])
|
|
2886
|
+
);
|
|
2887
|
+
principals.set(name, principal);
|
|
2888
|
+
}
|
|
2889
|
+
return principal;
|
|
2890
|
+
};
|
|
2891
|
+
return factory.createMiddleware((c, next) => __async(null, null, function* () {
|
|
2892
|
+
const xApiKey = c.req.header("x-api-key");
|
|
2893
|
+
const fingerprint = xApiKey ? fingerprintApiKey(xApiKey) : void 0;
|
|
2894
|
+
const policy = fingerprint ? fingerprints.get(fingerprint) : void 0;
|
|
2895
|
+
if (!fingerprint || !policy) {
|
|
2896
|
+
c.status(httpStatus4.UNAUTHORIZED);
|
|
2897
|
+
return c.json({
|
|
2898
|
+
status: httpStatus4.UNAUTHORIZED,
|
|
2899
|
+
message: httpStatus4["401_MESSAGE"]
|
|
2900
|
+
});
|
|
2901
|
+
}
|
|
2902
|
+
c.set("apiKey", __spreadProps(__spreadValues({}, principalFor(policy)), { fingerprint }));
|
|
2903
|
+
return yield runWithApiKey({ policy, fingerprint }, () => next());
|
|
2904
|
+
}));
|
|
2905
|
+
};
|
|
2906
|
+
var apiKeyAuth = ({
|
|
2907
|
+
policies = {},
|
|
2908
|
+
entityConfig,
|
|
2909
|
+
apiKeys: apiKeys2 = process.env.API_KEYS
|
|
2910
|
+
}) => {
|
|
2911
|
+
const errors = validateApiKeyPolicies(policies, entityConfig);
|
|
2912
|
+
if (errors.length) {
|
|
2913
|
+
console.error(
|
|
2914
|
+
`[monorise] Invalid API key policies; every key under them will be rejected:
|
|
2915
|
+
- ${errors.join("\n - ")}`
|
|
2916
|
+
);
|
|
2316
2917
|
}
|
|
2317
|
-
return
|
|
2318
|
-
|
|
2319
|
-
|
|
2918
|
+
return createApiKeyAuth(
|
|
2919
|
+
parseApiKeys(
|
|
2920
|
+
apiKeys2,
|
|
2921
|
+
errors.length ? [FULL_API_KEY_POLICY] : [FULL_API_KEY_POLICY, ...Object.keys(policies)]
|
|
2922
|
+
),
|
|
2923
|
+
policies
|
|
2924
|
+
);
|
|
2925
|
+
};
|
|
2320
2926
|
|
|
2321
2927
|
// middlewares/general-error-handler.ts
|
|
2322
2928
|
import { createFactory as createFactory2 } from "hono/factory";
|
|
@@ -2421,10 +3027,11 @@ function publishEvent(_0) {
|
|
|
2421
3027
|
payload,
|
|
2422
3028
|
event
|
|
2423
3029
|
}) {
|
|
3030
|
+
const apiKey = currentApiKey();
|
|
2424
3031
|
const params = {
|
|
2425
3032
|
Entries: [
|
|
2426
3033
|
__spreadProps(__spreadValues({}, event), {
|
|
2427
|
-
Detail: JSON.stringify(payload),
|
|
3034
|
+
Detail: JSON.stringify(apiKey ? __spreadProps(__spreadValues({}, payload), { apiKey }) : payload),
|
|
2428
3035
|
EventBusName: CORE_EVENT_BUS
|
|
2429
3036
|
})
|
|
2430
3037
|
]
|
|
@@ -2473,7 +3080,7 @@ var getDependencies = () => {
|
|
|
2473
3080
|
// middlewares/general-error-handler.ts
|
|
2474
3081
|
var factory2 = createFactory2();
|
|
2475
3082
|
var generalErrorHandler = (dependencies = getDependencies()) => factory2.createMiddleware((c) => __async(null, null, function* () {
|
|
2476
|
-
var _a, _b, _c, _d;
|
|
3083
|
+
var _a, _b, _c, _d, _e;
|
|
2477
3084
|
if (c.error) {
|
|
2478
3085
|
const { nanoid: nanoid2, publishErrorEvent: publishErrorEvent2 } = dependencies;
|
|
2479
3086
|
const errorId = nanoid2();
|
|
@@ -2491,14 +3098,15 @@ var generalErrorHandler = (dependencies = getDependencies()) => factory2.createM
|
|
|
2491
3098
|
errorId,
|
|
2492
3099
|
method: c.req.method,
|
|
2493
3100
|
path: c.req.path,
|
|
3101
|
+
apiKeyPolicy: (_a = c.get("apiKey")) == null ? void 0 : _a.policy,
|
|
2494
3102
|
errorName: error == null ? void 0 : error.name,
|
|
2495
3103
|
errorMessage: error == null ? void 0 : error.message,
|
|
2496
3104
|
errorCode: error == null ? void 0 : error.code,
|
|
2497
3105
|
errorStack: error == null ? void 0 : error.stack,
|
|
2498
|
-
errorConstructor: (
|
|
3106
|
+
errorConstructor: (_b = error == null ? void 0 : error.constructor) == null ? void 0 : _b.name,
|
|
2499
3107
|
hasLastError: !!(error == null ? void 0 : error.lastError),
|
|
2500
|
-
lastErrorName: (
|
|
2501
|
-
lastErrorMessage: (
|
|
3108
|
+
lastErrorName: (_d = (_c = error == null ? void 0 : error.lastError) == null ? void 0 : _c.constructor) == null ? void 0 : _d.name,
|
|
3109
|
+
lastErrorMessage: (_e = error == null ? void 0 : error.lastError) == null ? void 0 : _e.message,
|
|
2502
3110
|
context: error == null ? void 0 : error.context
|
|
2503
3111
|
});
|
|
2504
3112
|
c.status(500);
|
|
@@ -2524,8 +3132,14 @@ var appHandler = (container) => ({ routes }) => {
|
|
|
2524
3132
|
origin: process.env.ALLOWED_ORIGIN ? JSON.parse(process.env.ALLOWED_ORIGIN) : []
|
|
2525
3133
|
})
|
|
2526
3134
|
);
|
|
2527
|
-
app.use(
|
|
3135
|
+
app.use(
|
|
3136
|
+
apiKeyAuth({
|
|
3137
|
+
policies: container.config.ApiKeyPolicies,
|
|
3138
|
+
entityConfig: container.config.EntityConfig
|
|
3139
|
+
})
|
|
3140
|
+
);
|
|
2528
3141
|
if (routes) {
|
|
3142
|
+
app.use("/app/*", customRouteGate());
|
|
2529
3143
|
if (typeof routes !== "function") {
|
|
2530
3144
|
app.route("/app", routes);
|
|
2531
3145
|
} else {
|
|
@@ -2546,10 +3160,10 @@ import {
|
|
|
2546
3160
|
StopQueryExecutionCommand
|
|
2547
3161
|
} from "@aws-sdk/client-athena";
|
|
2548
3162
|
import { DynamoDBClient, GetItemCommand, PutItemCommand } from "@aws-sdk/client-dynamodb";
|
|
2549
|
-
import { createHash } from "crypto";
|
|
3163
|
+
import { createHash as createHash2 } from "crypto";
|
|
2550
3164
|
import { handle as handle2 } from "hono/aws-lambda";
|
|
2551
3165
|
import { Hono as Hono3 } from "hono";
|
|
2552
|
-
import
|
|
3166
|
+
import httpStatus5 from "http-status";
|
|
2553
3167
|
var athena = new AthenaClient();
|
|
2554
3168
|
var dynamo = new DynamoDBClient();
|
|
2555
3169
|
function required(name) {
|
|
@@ -2578,7 +3192,7 @@ function apiKeys() {
|
|
|
2578
3192
|
return process.env.ANALYTICS_API_KEYS ? JSON.parse(process.env.ANALYTICS_API_KEYS) : [];
|
|
2579
3193
|
}
|
|
2580
3194
|
function keyFingerprint(key) {
|
|
2581
|
-
return
|
|
3195
|
+
return createHash2("sha256").update(key).digest("hex");
|
|
2582
3196
|
}
|
|
2583
3197
|
function ownedExecution(id, key) {
|
|
2584
3198
|
return __async(this, null, function* () {
|
|
@@ -2596,7 +3210,7 @@ var analyticsQueryHandler = () => {
|
|
|
2596
3210
|
app.use("*", (c, next) => __async(null, null, function* () {
|
|
2597
3211
|
const key = c.req.header("x-api-key");
|
|
2598
3212
|
if (!key || !apiKeys().includes(key)) {
|
|
2599
|
-
return c.json({ status:
|
|
3213
|
+
return c.json({ status: httpStatus5.UNAUTHORIZED, message: httpStatus5["401_MESSAGE"] }, httpStatus5.UNAUTHORIZED);
|
|
2600
3214
|
}
|
|
2601
3215
|
return next();
|
|
2602
3216
|
}));
|
|
@@ -2609,11 +3223,11 @@ var analyticsQueryHandler = () => {
|
|
|
2609
3223
|
app.post("/queries/:name/executions", (c) => __async(null, null, function* () {
|
|
2610
3224
|
var _a, _b;
|
|
2611
3225
|
const query = queries()[c.req.param("name")];
|
|
2612
|
-
if (!query) return c.json({ message: "Unknown analytics query." },
|
|
3226
|
+
if (!query) return c.json({ message: "Unknown analytics query." }, httpStatus5.NOT_FOUND);
|
|
2613
3227
|
const body = yield c.req.json().catch(() => ({}));
|
|
2614
3228
|
const declared = (_a = query.parameters) != null ? _a : {};
|
|
2615
3229
|
if (Object.keys(body).some((name) => !(name in declared))) {
|
|
2616
|
-
return c.json({ message: "Unexpected query parameter." },
|
|
3230
|
+
return c.json({ message: "Unexpected query parameter." }, httpStatus5.BAD_REQUEST);
|
|
2617
3231
|
}
|
|
2618
3232
|
try {
|
|
2619
3233
|
const parameters = Object.entries(declared).map(([name, definition]) => {
|
|
@@ -2639,10 +3253,10 @@ var analyticsQueryHandler = () => {
|
|
|
2639
3253
|
expiresAt: { N: String(Math.floor(Date.now() / 1e3) + 86400) }
|
|
2640
3254
|
}
|
|
2641
3255
|
}));
|
|
2642
|
-
return c.json({ queryExecutionId: started.QueryExecutionId, state: "QUEUED" },
|
|
3256
|
+
return c.json({ queryExecutionId: started.QueryExecutionId, state: "QUEUED" }, httpStatus5.ACCEPTED);
|
|
2643
3257
|
} catch (error) {
|
|
2644
3258
|
if (error instanceof Error && error.message.startsWith("Invalid or missing parameter:")) {
|
|
2645
|
-
return c.json({ message: error.message },
|
|
3259
|
+
return c.json({ message: error.message }, httpStatus5.BAD_REQUEST);
|
|
2646
3260
|
}
|
|
2647
3261
|
throw error;
|
|
2648
3262
|
}
|
|
@@ -2650,7 +3264,7 @@ var analyticsQueryHandler = () => {
|
|
|
2650
3264
|
app.get("/executions/:id", (c) => __async(null, null, function* () {
|
|
2651
3265
|
var _a, _b, _c, _d, _e, _f;
|
|
2652
3266
|
const id = c.req.param("id");
|
|
2653
|
-
if (!(yield ownedExecution(id, (_a = c.req.header("x-api-key")) != null ? _a : ""))) return c.json({ message: "Unknown analytics execution." },
|
|
3267
|
+
if (!(yield ownedExecution(id, (_a = c.req.header("x-api-key")) != null ? _a : ""))) return c.json({ message: "Unknown analytics execution." }, httpStatus5.NOT_FOUND);
|
|
2654
3268
|
const execution = yield athena.send(new GetQueryExecutionCommand({ QueryExecutionId: id }));
|
|
2655
3269
|
const status = (_b = execution.QueryExecution) == null ? void 0 : _b.Status;
|
|
2656
3270
|
return c.json({
|
|
@@ -2664,7 +3278,7 @@ var analyticsQueryHandler = () => {
|
|
|
2664
3278
|
app.get("/executions/:id/results", (c) => __async(null, null, function* () {
|
|
2665
3279
|
var _a, _b, _c, _d, _e, _f, _g;
|
|
2666
3280
|
const id = c.req.param("id");
|
|
2667
|
-
if (!(yield ownedExecution(id, (_a = c.req.header("x-api-key")) != null ? _a : ""))) return c.json({ message: "Unknown analytics execution." },
|
|
3281
|
+
if (!(yield ownedExecution(id, (_a = c.req.header("x-api-key")) != null ? _a : ""))) return c.json({ message: "Unknown analytics execution." }, httpStatus5.NOT_FOUND);
|
|
2668
3282
|
const requested = Number((_b = c.req.query("maxResults")) != null ? _b : 100);
|
|
2669
3283
|
const maxResults = Number.isFinite(requested) ? Math.min(Math.max(requested, 1), 1e3) : 100;
|
|
2670
3284
|
const nextToken = c.req.query("nextToken");
|
|
@@ -2690,9 +3304,9 @@ var analyticsQueryHandler = () => {
|
|
|
2690
3304
|
app.post("/executions/:id/cancel", (c) => __async(null, null, function* () {
|
|
2691
3305
|
var _a;
|
|
2692
3306
|
const id = c.req.param("id");
|
|
2693
|
-
if (!(yield ownedExecution(id, (_a = c.req.header("x-api-key")) != null ? _a : ""))) return c.json({ message: "Unknown analytics execution." },
|
|
3307
|
+
if (!(yield ownedExecution(id, (_a = c.req.header("x-api-key")) != null ? _a : ""))) return c.json({ message: "Unknown analytics execution." }, httpStatus5.NOT_FOUND);
|
|
2694
3308
|
yield athena.send(new StopQueryExecutionCommand({ QueryExecutionId: id }));
|
|
2695
|
-
return c.body(null,
|
|
3309
|
+
return c.body(null, httpStatus5.NO_CONTENT);
|
|
2696
3310
|
}));
|
|
2697
3311
|
return handle2(app);
|
|
2698
3312
|
};
|
|
@@ -9096,12 +9710,12 @@ var EventUtils = class {
|
|
|
9096
9710
|
};
|
|
9097
9711
|
|
|
9098
9712
|
// controllers/entity/create-entity.controller.ts
|
|
9099
|
-
import { createMiddleware as
|
|
9100
|
-
import
|
|
9713
|
+
import { createMiddleware as createMiddleware5 } from "hono/factory";
|
|
9714
|
+
import httpStatus6 from "http-status";
|
|
9101
9715
|
var CreateEntityController = class {
|
|
9102
9716
|
constructor(entityService) {
|
|
9103
9717
|
this.entityService = entityService;
|
|
9104
|
-
this.controller =
|
|
9718
|
+
this.controller = createMiddleware5((c) => __async(this, null, function* () {
|
|
9105
9719
|
const accountId = c.req.header("account-id");
|
|
9106
9720
|
const { entityType } = c.req.param();
|
|
9107
9721
|
const body = yield c.req.json();
|
|
@@ -9115,11 +9729,11 @@ var CreateEntityController = class {
|
|
|
9115
9729
|
createAndUpdateDatetime: body.createdAt
|
|
9116
9730
|
}
|
|
9117
9731
|
});
|
|
9118
|
-
c.status(
|
|
9732
|
+
c.status(httpStatus6.OK);
|
|
9119
9733
|
return c.json(entity);
|
|
9120
9734
|
} catch (err) {
|
|
9121
9735
|
if ((err == null ? void 0 : err.name) === "ZodError") {
|
|
9122
|
-
c.status(
|
|
9736
|
+
c.status(httpStatus6.BAD_REQUEST);
|
|
9123
9737
|
return c.json({
|
|
9124
9738
|
code: "API_VALIDATION_ERROR",
|
|
9125
9739
|
message: "API validation failed",
|
|
@@ -9127,11 +9741,11 @@ var CreateEntityController = class {
|
|
|
9127
9741
|
});
|
|
9128
9742
|
}
|
|
9129
9743
|
if (err instanceof StandardError && err.code === StandardErrorCode.EMAIL_EXISTS) {
|
|
9130
|
-
c.status(
|
|
9744
|
+
c.status(httpStatus6.BAD_REQUEST);
|
|
9131
9745
|
return c.json(__spreadValues({}, err.toJSON()));
|
|
9132
9746
|
}
|
|
9133
9747
|
if (err instanceof StandardError && err.code === StandardErrorCode.UNIQUE_VALUE_EXISTS) {
|
|
9134
|
-
c.status(
|
|
9748
|
+
c.status(httpStatus6.BAD_REQUEST);
|
|
9135
9749
|
return c.json(__spreadValues({}, err.toJSON()));
|
|
9136
9750
|
}
|
|
9137
9751
|
console.log("===create-entity error:", {
|
|
@@ -9148,12 +9762,12 @@ var CreateEntityController = class {
|
|
|
9148
9762
|
};
|
|
9149
9763
|
|
|
9150
9764
|
// controllers/entity/delete-entity.controller.ts
|
|
9151
|
-
import { createMiddleware as
|
|
9152
|
-
import
|
|
9765
|
+
import { createMiddleware as createMiddleware6 } from "hono/factory";
|
|
9766
|
+
import httpStatus7 from "http-status";
|
|
9153
9767
|
var DeleteEntityController = class {
|
|
9154
9768
|
constructor(entityService) {
|
|
9155
9769
|
this.entityService = entityService;
|
|
9156
|
-
this.controller =
|
|
9770
|
+
this.controller = createMiddleware6((c) => __async(this, null, function* () {
|
|
9157
9771
|
const accountId = c.req.header("account-id");
|
|
9158
9772
|
const { entityType, entityId } = c.req.param();
|
|
9159
9773
|
try {
|
|
@@ -9165,7 +9779,7 @@ var DeleteEntityController = class {
|
|
|
9165
9779
|
return c.json({ message: "entity deleted" });
|
|
9166
9780
|
} catch (err) {
|
|
9167
9781
|
if (err instanceof StandardError && err.code === StandardErrorCode.ENTITY_NOT_FOUND) {
|
|
9168
|
-
c.status(
|
|
9782
|
+
c.status(httpStatus7.NOT_FOUND);
|
|
9169
9783
|
return c.json(__spreadValues({}, err.toJSON()));
|
|
9170
9784
|
}
|
|
9171
9785
|
throw err;
|
|
@@ -9175,12 +9789,12 @@ var DeleteEntityController = class {
|
|
|
9175
9789
|
};
|
|
9176
9790
|
|
|
9177
9791
|
// controllers/entity/get-entity-by-unique-field-value.controller.ts
|
|
9178
|
-
import { createMiddleware as
|
|
9179
|
-
import
|
|
9792
|
+
import { createMiddleware as createMiddleware7 } from "hono/factory";
|
|
9793
|
+
import httpStatus8 from "http-status";
|
|
9180
9794
|
var GetEntityByUniqueFieldValueController = class {
|
|
9181
9795
|
constructor(entityRepository) {
|
|
9182
9796
|
this.entityRepository = entityRepository;
|
|
9183
|
-
this.controller =
|
|
9797
|
+
this.controller = createMiddleware7((c) => __async(this, null, function* () {
|
|
9184
9798
|
const { entityType, uniqueField, uniqueFieldValue } = c.req.param();
|
|
9185
9799
|
try {
|
|
9186
9800
|
const entity = yield this.entityRepository.getEntityByUniqueField(
|
|
@@ -9191,7 +9805,7 @@ var GetEntityByUniqueFieldValueController = class {
|
|
|
9191
9805
|
return c.json(entity);
|
|
9192
9806
|
} catch (err) {
|
|
9193
9807
|
if (err instanceof StandardError && err.code === StandardErrorCode.ENTITY_IS_UNDEFINED) {
|
|
9194
|
-
c.status(
|
|
9808
|
+
c.status(httpStatus8.NOT_FOUND);
|
|
9195
9809
|
return c.json({
|
|
9196
9810
|
code: "ENTITY_NOT_FOUND",
|
|
9197
9811
|
message: "Entity not found"
|
|
@@ -9204,23 +9818,23 @@ var GetEntityByUniqueFieldValueController = class {
|
|
|
9204
9818
|
};
|
|
9205
9819
|
|
|
9206
9820
|
// controllers/entity/get-entity.controller.ts
|
|
9207
|
-
import { createMiddleware as
|
|
9208
|
-
import
|
|
9821
|
+
import { createMiddleware as createMiddleware8 } from "hono/factory";
|
|
9822
|
+
import httpStatus9 from "http-status";
|
|
9209
9823
|
var GetEntityController = class {
|
|
9210
9824
|
constructor(entityRepository) {
|
|
9211
9825
|
this.entityRepository = entityRepository;
|
|
9212
|
-
this.controller =
|
|
9826
|
+
this.controller = createMiddleware8((c) => __async(this, null, function* () {
|
|
9213
9827
|
const { entityType, entityId } = c.req.param();
|
|
9214
9828
|
try {
|
|
9215
9829
|
const entity = yield this.entityRepository.getEntity(
|
|
9216
9830
|
entityType,
|
|
9217
9831
|
entityId
|
|
9218
9832
|
);
|
|
9219
|
-
c.status(
|
|
9833
|
+
c.status(httpStatus9.OK);
|
|
9220
9834
|
return c.json(entity);
|
|
9221
9835
|
} catch (err) {
|
|
9222
9836
|
if (err instanceof StandardError && err.code === StandardErrorCode.ENTITY_IS_UNDEFINED) {
|
|
9223
|
-
c.status(
|
|
9837
|
+
c.status(httpStatus9.NOT_FOUND);
|
|
9224
9838
|
return c.json({
|
|
9225
9839
|
code: "ENTITY_NOT_FOUND",
|
|
9226
9840
|
message: "Entity not found"
|
|
@@ -9233,7 +9847,7 @@ var GetEntityController = class {
|
|
|
9233
9847
|
};
|
|
9234
9848
|
|
|
9235
9849
|
// controllers/entity/list-entities.controller.ts
|
|
9236
|
-
import { createMiddleware as
|
|
9850
|
+
import { createMiddleware as createMiddleware9 } from "hono/factory";
|
|
9237
9851
|
var querySchema = external_exports.object({
|
|
9238
9852
|
limit: external_exports.string().optional(),
|
|
9239
9853
|
lastKey: external_exports.string().optional(),
|
|
@@ -9244,7 +9858,7 @@ var querySchema = external_exports.object({
|
|
|
9244
9858
|
var ListEntitiesController = class {
|
|
9245
9859
|
constructor(entityRepository) {
|
|
9246
9860
|
this.entityRepository = entityRepository;
|
|
9247
|
-
this.controller =
|
|
9861
|
+
this.controller = createMiddleware9((c) => __async(this, null, function* () {
|
|
9248
9862
|
const errorContext = {};
|
|
9249
9863
|
try {
|
|
9250
9864
|
const accountId = c.req.header("account-id") || "";
|
|
@@ -9292,19 +9906,19 @@ var ListEntitiesController = class {
|
|
|
9292
9906
|
};
|
|
9293
9907
|
|
|
9294
9908
|
// controllers/entity/update-entity.controller.ts
|
|
9295
|
-
import { createMiddleware as
|
|
9296
|
-
import
|
|
9909
|
+
import { createMiddleware as createMiddleware10 } from "hono/factory";
|
|
9910
|
+
import httpStatus10 from "http-status";
|
|
9297
9911
|
var UpdateEntityController = class {
|
|
9298
9912
|
constructor(entityService) {
|
|
9299
9913
|
this.entityService = entityService;
|
|
9300
|
-
this.controller =
|
|
9914
|
+
this.controller = createMiddleware10((c) => __async(this, null, function* () {
|
|
9301
9915
|
const accountId = c.req.header("account-id");
|
|
9302
9916
|
const { entityType, entityId } = c.req.param();
|
|
9303
9917
|
const body = yield c.req.json();
|
|
9304
9918
|
const _a = body, { $condition: condition, $where: where } = _a, entityPayload = __objRest(_a, ["$condition", "$where"]);
|
|
9305
9919
|
if (condition !== void 0) {
|
|
9306
9920
|
if (typeof condition !== "string" || condition.trim().length === 0) {
|
|
9307
|
-
c.status(
|
|
9921
|
+
c.status(httpStatus10.BAD_REQUEST);
|
|
9308
9922
|
return c.json({
|
|
9309
9923
|
code: "API_VALIDATION_ERROR",
|
|
9310
9924
|
message: "$condition must be a non-empty string"
|
|
@@ -9326,11 +9940,11 @@ var UpdateEntityController = class {
|
|
|
9326
9940
|
where
|
|
9327
9941
|
});
|
|
9328
9942
|
errorContext.entity = entity;
|
|
9329
|
-
c.status(
|
|
9943
|
+
c.status(httpStatus10.OK);
|
|
9330
9944
|
return c.json(entity);
|
|
9331
9945
|
} catch (err) {
|
|
9332
9946
|
if ((err == null ? void 0 : err.name) === "ZodError") {
|
|
9333
|
-
c.status(
|
|
9947
|
+
c.status(httpStatus10.BAD_REQUEST);
|
|
9334
9948
|
return c.json({
|
|
9335
9949
|
code: "API_VALIDATION_ERROR",
|
|
9336
9950
|
message: "API validation failed",
|
|
@@ -9338,19 +9952,19 @@ var UpdateEntityController = class {
|
|
|
9338
9952
|
});
|
|
9339
9953
|
}
|
|
9340
9954
|
if (err instanceof StandardError && (err.code === StandardErrorCode.ENTITY_NOT_FOUND || err.code === StandardErrorCode.ENTITY_IS_UNDEFINED)) {
|
|
9341
|
-
c.status(
|
|
9955
|
+
c.status(httpStatus10.NOT_FOUND);
|
|
9342
9956
|
return c.json(__spreadValues({}, err.toJSON()));
|
|
9343
9957
|
}
|
|
9344
9958
|
if (err instanceof StandardError && err.code === StandardErrorCode.INVALID_CONDITION) {
|
|
9345
|
-
c.status(
|
|
9959
|
+
c.status(httpStatus10.BAD_REQUEST);
|
|
9346
9960
|
return c.json(__spreadValues({}, err.toJSON()));
|
|
9347
9961
|
}
|
|
9348
9962
|
if (err instanceof StandardError && err.code === StandardErrorCode.UNIQUE_VALUE_EXISTS) {
|
|
9349
|
-
c.status(
|
|
9963
|
+
c.status(httpStatus10.BAD_REQUEST);
|
|
9350
9964
|
return c.json(__spreadValues({}, err.toJSON()));
|
|
9351
9965
|
}
|
|
9352
9966
|
if (err instanceof StandardError && err.code === StandardErrorCode.CONDITIONAL_CHECK_FAILED) {
|
|
9353
|
-
c.status(
|
|
9967
|
+
c.status(httpStatus10.CONFLICT);
|
|
9354
9968
|
return c.json(__spreadValues({}, err.toJSON()));
|
|
9355
9969
|
}
|
|
9356
9970
|
console.log(
|
|
@@ -9365,12 +9979,12 @@ var UpdateEntityController = class {
|
|
|
9365
9979
|
};
|
|
9366
9980
|
|
|
9367
9981
|
// controllers/entity/adjust-entity.controller.ts
|
|
9368
|
-
import { createMiddleware as
|
|
9369
|
-
import
|
|
9982
|
+
import { createMiddleware as createMiddleware11 } from "hono/factory";
|
|
9983
|
+
import httpStatus11 from "http-status";
|
|
9370
9984
|
var AdjustEntityController = class {
|
|
9371
9985
|
constructor(entityService) {
|
|
9372
9986
|
this.entityService = entityService;
|
|
9373
|
-
this.controller =
|
|
9987
|
+
this.controller = createMiddleware11((c) => __async(this, null, function* () {
|
|
9374
9988
|
var _b;
|
|
9375
9989
|
const accountId = c.req.header("account-id") || "";
|
|
9376
9990
|
const { entityType, entityId } = c.req.param();
|
|
@@ -9378,7 +9992,7 @@ var AdjustEntityController = class {
|
|
|
9378
9992
|
const _a = body, { $condition: condition } = _a, adjustments = __objRest(_a, ["$condition"]);
|
|
9379
9993
|
if (condition !== void 0) {
|
|
9380
9994
|
if (typeof condition !== "string" || condition.trim().length === 0) {
|
|
9381
|
-
c.status(
|
|
9995
|
+
c.status(httpStatus11.BAD_REQUEST);
|
|
9382
9996
|
return c.json({
|
|
9383
9997
|
code: "API_VALIDATION_ERROR",
|
|
9384
9998
|
message: "$condition must be a non-empty string"
|
|
@@ -9387,7 +10001,7 @@ var AdjustEntityController = class {
|
|
|
9387
10001
|
}
|
|
9388
10002
|
for (const [key, value] of Object.entries(adjustments)) {
|
|
9389
10003
|
if (typeof value !== "number") {
|
|
9390
|
-
c.status(
|
|
10004
|
+
c.status(httpStatus11.BAD_REQUEST);
|
|
9391
10005
|
return c.json({
|
|
9392
10006
|
code: "API_VALIDATION_ERROR",
|
|
9393
10007
|
message: `Field "${key}" must be a number, got ${typeof value}`
|
|
@@ -9402,19 +10016,19 @@ var AdjustEntityController = class {
|
|
|
9402
10016
|
accountId,
|
|
9403
10017
|
condition
|
|
9404
10018
|
});
|
|
9405
|
-
c.status(
|
|
10019
|
+
c.status(httpStatus11.OK);
|
|
9406
10020
|
return c.json(entity.toJSON());
|
|
9407
10021
|
} catch (err) {
|
|
9408
10022
|
if (err instanceof StandardError && err.code === StandardErrorCode.ENTITY_IS_UNDEFINED) {
|
|
9409
|
-
c.status(
|
|
10023
|
+
c.status(httpStatus11.NOT_FOUND);
|
|
9410
10024
|
return c.json(__spreadValues({}, err.toJSON()));
|
|
9411
10025
|
}
|
|
9412
10026
|
if (err instanceof StandardError && err.code === StandardErrorCode.INVALID_CONDITION) {
|
|
9413
|
-
c.status(
|
|
10027
|
+
c.status(httpStatus11.BAD_REQUEST);
|
|
9414
10028
|
return c.json(__spreadValues({}, err.toJSON()));
|
|
9415
10029
|
}
|
|
9416
10030
|
if ((err == null ? void 0 : err.name) === "ConditionalCheckFailedException" || ((_b = err == null ? void 0 : err.__type) == null ? void 0 : _b.includes("ConditionalCheckFailed"))) {
|
|
9417
|
-
c.status(
|
|
10031
|
+
c.status(httpStatus11.CONFLICT);
|
|
9418
10032
|
return c.json({
|
|
9419
10033
|
code: "ADJUSTMENT_CONSTRAINT_VIOLATED",
|
|
9420
10034
|
message: "Adjustment would violate entity constraints"
|
|
@@ -9428,14 +10042,14 @@ var AdjustEntityController = class {
|
|
|
9428
10042
|
};
|
|
9429
10043
|
|
|
9430
10044
|
// controllers/entity/upsert-entity.controller.ts
|
|
9431
|
-
import { createMiddleware as
|
|
9432
|
-
import
|
|
10045
|
+
import { createMiddleware as createMiddleware12 } from "hono/factory";
|
|
10046
|
+
import httpStatus12 from "http-status";
|
|
9433
10047
|
var UpsertEntityController = class {
|
|
9434
10048
|
constructor(EntityConfig, entityRepository, publishEvent2) {
|
|
9435
10049
|
this.EntityConfig = EntityConfig;
|
|
9436
10050
|
this.entityRepository = entityRepository;
|
|
9437
10051
|
this.publishEvent = publishEvent2;
|
|
9438
|
-
this.controller =
|
|
10052
|
+
this.controller = createMiddleware12((c) => __async(this, null, function* () {
|
|
9439
10053
|
var _a;
|
|
9440
10054
|
const accountId = c.req.header("account-id");
|
|
9441
10055
|
const { entityType, entityId } = c.req.param();
|
|
@@ -9500,7 +10114,7 @@ var UpsertEntityController = class {
|
|
|
9500
10114
|
return c.json(entity);
|
|
9501
10115
|
} catch (err) {
|
|
9502
10116
|
if (err instanceof ZodError) {
|
|
9503
|
-
c.status(
|
|
10117
|
+
c.status(httpStatus12.BAD_REQUEST);
|
|
9504
10118
|
return c.json({
|
|
9505
10119
|
code: "API_VALIDATION_ERROR",
|
|
9506
10120
|
message: "API validation failed",
|
|
@@ -9508,7 +10122,7 @@ var UpsertEntityController = class {
|
|
|
9508
10122
|
});
|
|
9509
10123
|
}
|
|
9510
10124
|
if (err instanceof StandardError && err.code === StandardErrorCode.EMAIL_EXISTS) {
|
|
9511
|
-
c.status(
|
|
10125
|
+
c.status(httpStatus12.BAD_REQUEST);
|
|
9512
10126
|
return c.json(__spreadValues({}, err.toJSON()));
|
|
9513
10127
|
}
|
|
9514
10128
|
throw err;
|
|
@@ -9518,12 +10132,12 @@ var UpsertEntityController = class {
|
|
|
9518
10132
|
};
|
|
9519
10133
|
|
|
9520
10134
|
// controllers/mutual/create-mutual.controller.ts
|
|
9521
|
-
import { createMiddleware as
|
|
9522
|
-
import
|
|
10135
|
+
import { createMiddleware as createMiddleware13 } from "hono/factory";
|
|
10136
|
+
import httpStatus13 from "http-status";
|
|
9523
10137
|
var CreateMutualController = class {
|
|
9524
10138
|
constructor(mutualService) {
|
|
9525
10139
|
this.mutualService = mutualService;
|
|
9526
|
-
this.controller =
|
|
10140
|
+
this.controller = createMiddleware13((c) => __async(this, null, function* () {
|
|
9527
10141
|
const accountId = c.req.header("account-id");
|
|
9528
10142
|
const { byEntityType, byEntityId, entityType, entityId } = c.req.param();
|
|
9529
10143
|
const asEntity = c.req.query("asEntity");
|
|
@@ -9543,7 +10157,7 @@ var CreateMutualController = class {
|
|
|
9543
10157
|
return c.json(mutual);
|
|
9544
10158
|
} catch (err) {
|
|
9545
10159
|
if (err instanceof ZodError) {
|
|
9546
|
-
c.status(
|
|
10160
|
+
c.status(httpStatus13.BAD_REQUEST);
|
|
9547
10161
|
return c.json({
|
|
9548
10162
|
code: "API_VALIDATION_ERROR",
|
|
9549
10163
|
message: "API validation failed",
|
|
@@ -9551,11 +10165,11 @@ var CreateMutualController = class {
|
|
|
9551
10165
|
});
|
|
9552
10166
|
}
|
|
9553
10167
|
if (err instanceof StandardError && err.code === StandardErrorCode.MUTUAL_EXISTS) {
|
|
9554
|
-
c.status(
|
|
10168
|
+
c.status(httpStatus13.BAD_REQUEST);
|
|
9555
10169
|
return c.json(__spreadValues({}, err.toJSON()));
|
|
9556
10170
|
}
|
|
9557
10171
|
if (err instanceof StandardError && err.code === StandardErrorCode.ENTITY_IS_UNDEFINED) {
|
|
9558
|
-
c.status(
|
|
10172
|
+
c.status(httpStatus13.BAD_REQUEST);
|
|
9559
10173
|
return c.json(__spreadValues({}, err.toJSON()));
|
|
9560
10174
|
}
|
|
9561
10175
|
throw err;
|
|
@@ -9565,12 +10179,12 @@ var CreateMutualController = class {
|
|
|
9565
10179
|
};
|
|
9566
10180
|
|
|
9567
10181
|
// controllers/mutual/delete-mutual.controller.ts
|
|
9568
|
-
import { createMiddleware as
|
|
9569
|
-
import
|
|
10182
|
+
import { createMiddleware as createMiddleware14 } from "hono/factory";
|
|
10183
|
+
import httpStatus14 from "http-status";
|
|
9570
10184
|
var DeleteMutualController = class {
|
|
9571
10185
|
constructor(mutualService) {
|
|
9572
10186
|
this.mutualService = mutualService;
|
|
9573
|
-
this.controller =
|
|
10187
|
+
this.controller = createMiddleware14((c) => __async(this, null, function* () {
|
|
9574
10188
|
const accountId = c.req.header("account-id");
|
|
9575
10189
|
const { byEntityType, byEntityId, entityType, entityId } = c.req.param();
|
|
9576
10190
|
try {
|
|
@@ -9584,7 +10198,7 @@ var DeleteMutualController = class {
|
|
|
9584
10198
|
return c.json(mutual);
|
|
9585
10199
|
} catch (err) {
|
|
9586
10200
|
if (err instanceof StandardError && err.code === StandardErrorCode.MUTUAL_NOT_FOUND) {
|
|
9587
|
-
c.status(
|
|
10201
|
+
c.status(httpStatus14.BAD_REQUEST);
|
|
9588
10202
|
return c.json(__spreadValues({}, err.toJSON()));
|
|
9589
10203
|
}
|
|
9590
10204
|
throw err;
|
|
@@ -9594,12 +10208,12 @@ var DeleteMutualController = class {
|
|
|
9594
10208
|
};
|
|
9595
10209
|
|
|
9596
10210
|
// controllers/mutual/get-mutual.controller.ts
|
|
9597
|
-
import { createMiddleware as
|
|
9598
|
-
import
|
|
10211
|
+
import { createMiddleware as createMiddleware15 } from "hono/factory";
|
|
10212
|
+
import httpStatus15 from "http-status";
|
|
9599
10213
|
var GetMutualController = class {
|
|
9600
10214
|
constructor(associateRepository) {
|
|
9601
10215
|
this.associateRepository = associateRepository;
|
|
9602
|
-
this.controller =
|
|
10216
|
+
this.controller = createMiddleware15((c) => __async(this, null, function* () {
|
|
9603
10217
|
const { byEntityType, byEntityId, entityType, entityId } = c.req.param();
|
|
9604
10218
|
try {
|
|
9605
10219
|
const associate = yield this.associateRepository.getMutual(
|
|
@@ -9611,7 +10225,7 @@ var GetMutualController = class {
|
|
|
9611
10225
|
return c.json(associate);
|
|
9612
10226
|
} catch (err) {
|
|
9613
10227
|
if (err instanceof StandardError && err.code === StandardErrorCode.MUTUAL_IS_UNDEFINED) {
|
|
9614
|
-
c.status(
|
|
10228
|
+
c.status(httpStatus15.NOT_FOUND);
|
|
9615
10229
|
return c.json({
|
|
9616
10230
|
code: "MUTUAL_NOT_FOUND",
|
|
9617
10231
|
message: "Mutual not found"
|
|
@@ -9624,11 +10238,11 @@ var GetMutualController = class {
|
|
|
9624
10238
|
};
|
|
9625
10239
|
|
|
9626
10240
|
// controllers/mutual/list-entities-by-entity.controller.ts
|
|
9627
|
-
import { createMiddleware as
|
|
10241
|
+
import { createMiddleware as createMiddleware16 } from "hono/factory";
|
|
9628
10242
|
var ListEntitiesByEntityController = class {
|
|
9629
10243
|
constructor(associateRepository) {
|
|
9630
10244
|
this.associateRepository = associateRepository;
|
|
9631
|
-
this.controller =
|
|
10245
|
+
this.controller = createMiddleware16((c) => __async(this, null, function* () {
|
|
9632
10246
|
const { byEntityType, byEntityId, entityType } = c.req.param();
|
|
9633
10247
|
const querySchema3 = external_exports.object({
|
|
9634
10248
|
chainEntityQuery: external_exports.string().optional(),
|
|
@@ -9686,12 +10300,12 @@ var ListEntitiesByEntityController = class {
|
|
|
9686
10300
|
};
|
|
9687
10301
|
|
|
9688
10302
|
// controllers/mutual/update-mutual.controller.ts
|
|
9689
|
-
import { createMiddleware as
|
|
9690
|
-
import
|
|
10303
|
+
import { createMiddleware as createMiddleware17 } from "hono/factory";
|
|
10304
|
+
import httpStatus16 from "http-status";
|
|
9691
10305
|
var UpdateMutualController = class {
|
|
9692
10306
|
constructor(mutualService) {
|
|
9693
10307
|
this.mutualService = mutualService;
|
|
9694
|
-
this.controller =
|
|
10308
|
+
this.controller = createMiddleware17((c) => __async(this, null, function* () {
|
|
9695
10309
|
const accountId = c.req.header("account-id");
|
|
9696
10310
|
const { byEntityType, byEntityId, entityType, entityId } = c.req.param();
|
|
9697
10311
|
const body = yield c.req.json();
|
|
@@ -9710,7 +10324,7 @@ var UpdateMutualController = class {
|
|
|
9710
10324
|
return c.json(mutual);
|
|
9711
10325
|
} catch (err) {
|
|
9712
10326
|
if (err instanceof ZodError) {
|
|
9713
|
-
c.status(
|
|
10327
|
+
c.status(httpStatus16.BAD_REQUEST);
|
|
9714
10328
|
return c.json({
|
|
9715
10329
|
code: "API_VALIDATION_ERROR",
|
|
9716
10330
|
message: "API validation failed",
|
|
@@ -9718,7 +10332,7 @@ var UpdateMutualController = class {
|
|
|
9718
10332
|
});
|
|
9719
10333
|
}
|
|
9720
10334
|
if (err instanceof StandardError && err.code === StandardErrorCode.MUTUAL_NOT_FOUND) {
|
|
9721
|
-
c.status(
|
|
10335
|
+
c.status(httpStatus16.BAD_REQUEST);
|
|
9722
10336
|
return c.json(__spreadValues({}, err.toJSON()));
|
|
9723
10337
|
}
|
|
9724
10338
|
throw err;
|
|
@@ -10159,7 +10773,7 @@ var EntityService = class {
|
|
|
10159
10773
|
};
|
|
10160
10774
|
|
|
10161
10775
|
// controllers/tag/list-tags.controller.ts
|
|
10162
|
-
import { createMiddleware as
|
|
10776
|
+
import { createMiddleware as createMiddleware18 } from "hono/factory";
|
|
10163
10777
|
var querySchema2 = external_exports.object({
|
|
10164
10778
|
group: external_exports.string().optional(),
|
|
10165
10779
|
query: external_exports.string().optional(),
|
|
@@ -10171,7 +10785,7 @@ var querySchema2 = external_exports.object({
|
|
|
10171
10785
|
var ListTagsController = class {
|
|
10172
10786
|
constructor(tagRepository) {
|
|
10173
10787
|
this.tagRepository = tagRepository;
|
|
10174
|
-
this.controller =
|
|
10788
|
+
this.controller = createMiddleware18((c) => __async(this, null, function* () {
|
|
10175
10789
|
const errorContext = {};
|
|
10176
10790
|
try {
|
|
10177
10791
|
errorContext.params = c.req.param();
|
|
@@ -10206,18 +10820,18 @@ var ListTagsController = class {
|
|
|
10206
10820
|
};
|
|
10207
10821
|
|
|
10208
10822
|
// controllers/transaction/execute-transaction.controller.ts
|
|
10209
|
-
import { createMiddleware as
|
|
10210
|
-
import
|
|
10823
|
+
import { createMiddleware as createMiddleware19 } from "hono/factory";
|
|
10824
|
+
import httpStatus17 from "http-status";
|
|
10211
10825
|
var ExecuteTransactionController = class {
|
|
10212
10826
|
constructor(transactionService) {
|
|
10213
10827
|
this.transactionService = transactionService;
|
|
10214
10828
|
// biome-ignore lint/suspicious/noExplicitAny: Hono createMiddleware requires consistent return types
|
|
10215
|
-
this.controller =
|
|
10829
|
+
this.controller = createMiddleware19((c) => __async(this, null, function* () {
|
|
10216
10830
|
const accountId = c.req.header("account-id") || "";
|
|
10217
10831
|
try {
|
|
10218
10832
|
const body = yield c.req.json();
|
|
10219
10833
|
if (!body.operations || !Array.isArray(body.operations)) {
|
|
10220
|
-
c.status(
|
|
10834
|
+
c.status(httpStatus17.BAD_REQUEST);
|
|
10221
10835
|
return c.json({
|
|
10222
10836
|
code: "API_VALIDATION_ERROR",
|
|
10223
10837
|
message: 'Request body must contain an "operations" array'
|
|
@@ -10227,11 +10841,11 @@ var ExecuteTransactionController = class {
|
|
|
10227
10841
|
body.operations,
|
|
10228
10842
|
accountId
|
|
10229
10843
|
);
|
|
10230
|
-
c.status(
|
|
10844
|
+
c.status(httpStatus17.OK);
|
|
10231
10845
|
return c.json(result);
|
|
10232
10846
|
} catch (err) {
|
|
10233
10847
|
if ((err == null ? void 0 : err.name) === "ZodError") {
|
|
10234
|
-
c.status(
|
|
10848
|
+
c.status(httpStatus17.BAD_REQUEST);
|
|
10235
10849
|
return c.json({
|
|
10236
10850
|
code: "API_VALIDATION_ERROR",
|
|
10237
10851
|
message: "Validation failed",
|
|
@@ -10239,7 +10853,7 @@ var ExecuteTransactionController = class {
|
|
|
10239
10853
|
});
|
|
10240
10854
|
}
|
|
10241
10855
|
if (err instanceof SyntaxError) {
|
|
10242
|
-
c.status(
|
|
10856
|
+
c.status(httpStatus17.BAD_REQUEST);
|
|
10243
10857
|
return c.json({
|
|
10244
10858
|
code: "API_VALIDATION_ERROR",
|
|
10245
10859
|
message: "Request body must be valid JSON"
|
|
@@ -10248,15 +10862,15 @@ var ExecuteTransactionController = class {
|
|
|
10248
10862
|
if (err instanceof StandardError) {
|
|
10249
10863
|
const code = err.code;
|
|
10250
10864
|
if (code === StandardErrorCode.ENTITY_IS_UNDEFINED || code === StandardErrorCode.ENTITY_NOT_FOUND || code === StandardErrorCode.MUTUAL_NOT_FOUND) {
|
|
10251
|
-
c.status(
|
|
10865
|
+
c.status(httpStatus17.NOT_FOUND);
|
|
10252
10866
|
return c.json(__spreadValues({}, err.toJSON()));
|
|
10253
10867
|
}
|
|
10254
10868
|
if (code === StandardErrorCode.TRANSACTION_EMPTY || code === StandardErrorCode.TRANSACTION_ITEM_LIMIT_EXCEEDED || code === StandardErrorCode.TRANSACTION_UNIQUE_FIELD_UPDATE || code === StandardErrorCode.TRANSACTION_INVALID_OPERATION || code === StandardErrorCode.TRANSACTION_VALIDATION_ERROR || code === StandardErrorCode.INVALID_ENTITY_TYPE || code === StandardErrorCode.INVALID_CONDITION || code === StandardErrorCode.INVALID_UNIQUE_VALUE_TYPE) {
|
|
10255
|
-
c.status(
|
|
10869
|
+
c.status(httpStatus17.BAD_REQUEST);
|
|
10256
10870
|
return c.json(__spreadValues({}, err.toJSON()));
|
|
10257
10871
|
}
|
|
10258
10872
|
if (code === StandardErrorCode.TRANSACTION_FAILED || code === StandardErrorCode.CONDITIONAL_CHECK_FAILED || code === StandardErrorCode.UNIQUE_VALUE_EXISTS || code === StandardErrorCode.MUTUAL_EXISTS) {
|
|
10259
|
-
c.status(
|
|
10873
|
+
c.status(httpStatus17.CONFLICT);
|
|
10260
10874
|
return c.json(__spreadValues({}, err.toJSON()));
|
|
10261
10875
|
}
|
|
10262
10876
|
}
|
|
@@ -10267,13 +10881,13 @@ var ExecuteTransactionController = class {
|
|
|
10267
10881
|
};
|
|
10268
10882
|
|
|
10269
10883
|
// controllers/ws/create-ticket.controller.ts
|
|
10270
|
-
import { createMiddleware as
|
|
10884
|
+
import { createMiddleware as createMiddleware20 } from "hono/factory";
|
|
10271
10885
|
import { ulid as ulid6 } from "ulid";
|
|
10272
10886
|
var TICKET_TTL_SECONDS = 30 * 60;
|
|
10273
10887
|
var CreateTicketController = class {
|
|
10274
10888
|
constructor(container) {
|
|
10275
10889
|
this.container = container;
|
|
10276
|
-
this.controller =
|
|
10890
|
+
this.controller = createMiddleware20((c) => __async(this, null, function* () {
|
|
10277
10891
|
var _a, _b;
|
|
10278
10892
|
const { entityType, entityId } = c.req.param();
|
|
10279
10893
|
let feedTypes;
|
|
@@ -11362,6 +11976,7 @@ export {
|
|
|
11362
11976
|
handler7 as mutualProcessor,
|
|
11363
11977
|
handler8 as prejoinProcessor,
|
|
11364
11978
|
handler9 as replicationProcessor,
|
|
11979
|
+
requires,
|
|
11365
11980
|
setupCommonRoutes,
|
|
11366
11981
|
startBackfill as startAnalyticsBackfill,
|
|
11367
11982
|
handler10 as tagProcessor,
|