monorise 1.14.1 → 2.0.0-dev.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/base/index.d.ts +227 -1
- package/dist/base/index.js +383 -1
- package/dist/base/index.js.map +1 -1
- package/dist/cli/cli.js +295 -122
- package/dist/cli/cli.js.map +1 -1
- package/dist/cli/templates/files/api-keys.ts +12 -0
- package/dist/cli/templates/files/monorise.config.ts +2 -0
- 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 +63 -36
- package/dist/core/index.js +783 -208
- package/dist/core/index.js.map +1 -1
- package/dist/index.d.ts +24 -7
- package/dist/proxy/index.d.ts +275 -2
- package/dist/proxy/index.js +696 -37
- package/dist/proxy/index.js.map +1 -1
- package/dist/react/index.d.ts +2 -164
- package/dist/react/index.d.ts.map +1 -1
- package/dist/react/index.js +46 -188
- package/dist/react/index.js.map +1 -1
- package/dist/react/lib/api.d.ts +1 -2
- package/dist/react/lib/api.d.ts.map +1 -1
- package/dist/react/store/monorise.store.d.ts +0 -54
- package/dist/react/store/monorise.store.d.ts.map +1 -1
- package/dist/sst/components/monorise-core.d.ts.map +1 -1
- package/dist/sst/index.js +4 -1
- package/dist/sst/index.js.map +1 -1
- package/package.json +1 -1
- package/dist/cli/templates/files/proxy-request.ts +0 -50
- package/dist/react/actions/auth.action.d.ts +0 -24
- package/dist/react/actions/auth.action.d.ts.map +0 -1
- package/dist/react/services/auth.service.d.ts +0 -21
- package/dist/react/services/auth.service.d.ts.map +0 -1
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,164 @@ 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
|
+
DEFAULT_API_KEY_POLICY,
|
|
2780
|
+
FULL_API_KEY_POLICY,
|
|
2781
|
+
compileApiKeyPolicy,
|
|
2782
|
+
validateApiKeyPolicies
|
|
2783
|
+
} from "../base/index.js";
|
|
2301
2784
|
import { createFactory } from "hono/factory";
|
|
2302
|
-
import
|
|
2785
|
+
import httpStatus4 from "http-status";
|
|
2786
|
+
|
|
2787
|
+
// helpers/request-context.ts
|
|
2788
|
+
import { AsyncLocalStorage } from "async_hooks";
|
|
2789
|
+
var storage = new AsyncLocalStorage();
|
|
2790
|
+
var runWithApiKey = (apiKey, fn) => storage.run(apiKey, fn);
|
|
2791
|
+
var currentApiKey = () => storage.getStore();
|
|
2792
|
+
|
|
2793
|
+
// middlewares/api-key-auth.ts
|
|
2794
|
+
var SHA256_PREFIX = "sha256:";
|
|
2795
|
+
var createPrincipal = (policy, access) => ({
|
|
2796
|
+
policy,
|
|
2797
|
+
access,
|
|
2798
|
+
can: (action, entityType, fields) => {
|
|
2799
|
+
const entity = access.entity(entityType);
|
|
2800
|
+
if (action === "delete") return entity.delete;
|
|
2801
|
+
if (action === "list" && !entity.list) return false;
|
|
2802
|
+
const granted = entity[action === "list" ? "read" : action];
|
|
2803
|
+
if (granted === null) return false;
|
|
2804
|
+
return !fields || granted === "*" || fields.every((f) => granted.has(f));
|
|
2805
|
+
},
|
|
2806
|
+
has: (permission) => access.allowsRoute(permission),
|
|
2807
|
+
mask: (entityType, entity) => {
|
|
2808
|
+
const record = typeof entity.toJSON === "function" ? entity.toJSON() : entity;
|
|
2809
|
+
return maskRecord(__spreadProps(__spreadValues({}, record), { entityType }), access);
|
|
2810
|
+
}
|
|
2811
|
+
});
|
|
2812
|
+
var fingerprintApiKey = (key) => createHash("sha256").update(key).digest("hex");
|
|
2813
|
+
var SHA256_DIGEST = /^[0-9a-f]{64}$/i;
|
|
2814
|
+
var toFingerprint = (entry, where) => {
|
|
2815
|
+
if (!entry.startsWith(SHA256_PREFIX)) return fingerprintApiKey(entry);
|
|
2816
|
+
const digest = entry.slice(SHA256_PREFIX.length);
|
|
2817
|
+
if (!SHA256_DIGEST.test(digest)) {
|
|
2818
|
+
console.error(
|
|
2819
|
+
`[monorise] API_KEYS: a '${SHA256_PREFIX}' entry in ${where} isn't a 64-character hex SHA-256 digest and will be rejected`
|
|
2820
|
+
);
|
|
2821
|
+
return void 0;
|
|
2822
|
+
}
|
|
2823
|
+
return digest.toLowerCase();
|
|
2824
|
+
};
|
|
2825
|
+
var assertKeyList = (value, where) => {
|
|
2826
|
+
if (!Array.isArray(value) || !value.every((key) => typeof key === "string" && key.length > 0)) {
|
|
2827
|
+
throw new Error(
|
|
2828
|
+
`[monorise] API_KEYS: ${where} must be an array of non-empty strings`
|
|
2829
|
+
);
|
|
2830
|
+
}
|
|
2831
|
+
return value;
|
|
2832
|
+
};
|
|
2833
|
+
var BUILT_IN_POLICIES = [
|
|
2834
|
+
FULL_API_KEY_POLICY,
|
|
2835
|
+
DEFAULT_API_KEY_POLICY
|
|
2836
|
+
];
|
|
2837
|
+
var parseApiKeys = (raw, definedPolicies = BUILT_IN_POLICIES) => {
|
|
2838
|
+
var _a;
|
|
2839
|
+
const fingerprints = /* @__PURE__ */ new Map();
|
|
2840
|
+
if (!raw) return fingerprints;
|
|
2841
|
+
const parsed = JSON.parse(raw);
|
|
2842
|
+
if (Array.isArray(parsed)) {
|
|
2843
|
+
for (const key of assertKeyList(parsed, "the array form")) {
|
|
2844
|
+
const fingerprint = toFingerprint(key, "the array form");
|
|
2845
|
+
if (fingerprint) fingerprints.set(fingerprint, FULL_API_KEY_POLICY);
|
|
2846
|
+
}
|
|
2847
|
+
return fingerprints;
|
|
2848
|
+
}
|
|
2849
|
+
if (typeof parsed !== "object" || parsed === null) {
|
|
2850
|
+
throw new Error(
|
|
2851
|
+
"[monorise] API_KEYS must be a JSON array of keys or an object mapping policy names to keys"
|
|
2852
|
+
);
|
|
2853
|
+
}
|
|
2854
|
+
const policiesByFingerprint = /* @__PURE__ */ new Map();
|
|
2855
|
+
for (const [policy, keys] of Object.entries(parsed)) {
|
|
2856
|
+
const keyList = assertKeyList(keys, `policy '${policy}'`);
|
|
2857
|
+
if (!definedPolicies.includes(policy)) {
|
|
2858
|
+
console.error(
|
|
2859
|
+
`[monorise] API_KEYS: policy '${policy}' is not defined; its ${keyList.length} key(s) will be rejected`
|
|
2860
|
+
);
|
|
2861
|
+
}
|
|
2862
|
+
for (const key of keyList) {
|
|
2863
|
+
const fingerprint = toFingerprint(key, `policy '${policy}'`);
|
|
2864
|
+
if (!fingerprint) continue;
|
|
2865
|
+
const policies = (_a = policiesByFingerprint.get(fingerprint)) != null ? _a : /* @__PURE__ */ new Set();
|
|
2866
|
+
policies.add(policy);
|
|
2867
|
+
policiesByFingerprint.set(fingerprint, policies);
|
|
2868
|
+
}
|
|
2869
|
+
}
|
|
2870
|
+
for (const [fingerprint, policies] of policiesByFingerprint) {
|
|
2871
|
+
if (policies.size > 1) {
|
|
2872
|
+
console.error(
|
|
2873
|
+
`[monorise] API_KEYS: key ${fingerprint.slice(0, 12)}\u2026 is listed under more than one policy (${[...policies].join(", ")}) and will be rejected`
|
|
2874
|
+
);
|
|
2875
|
+
continue;
|
|
2876
|
+
}
|
|
2877
|
+
const [policy] = policies;
|
|
2878
|
+
if (definedPolicies.includes(policy)) fingerprints.set(fingerprint, policy);
|
|
2879
|
+
}
|
|
2880
|
+
return fingerprints;
|
|
2881
|
+
};
|
|
2303
2882
|
var factory = createFactory();
|
|
2304
|
-
var
|
|
2305
|
-
|
|
2306
|
-
const
|
|
2307
|
-
|
|
2308
|
-
|
|
2309
|
-
|
|
2310
|
-
|
|
2311
|
-
|
|
2312
|
-
|
|
2313
|
-
|
|
2314
|
-
|
|
2315
|
-
|
|
2883
|
+
var createApiKeyAuth = (fingerprints, policies = {}) => {
|
|
2884
|
+
const principals = /* @__PURE__ */ new Map();
|
|
2885
|
+
const principalFor = (name) => {
|
|
2886
|
+
let principal = principals.get(name);
|
|
2887
|
+
if (!principal) {
|
|
2888
|
+
principal = createPrincipal(
|
|
2889
|
+
name,
|
|
2890
|
+
compileApiKeyPolicy(name, policies[name])
|
|
2891
|
+
);
|
|
2892
|
+
principals.set(name, principal);
|
|
2893
|
+
}
|
|
2894
|
+
return principal;
|
|
2895
|
+
};
|
|
2896
|
+
return factory.createMiddleware((c, next) => __async(null, null, function* () {
|
|
2897
|
+
const xApiKey = c.req.header("x-api-key");
|
|
2898
|
+
const fingerprint = xApiKey ? fingerprintApiKey(xApiKey) : void 0;
|
|
2899
|
+
const policy = fingerprint ? fingerprints.get(fingerprint) : void 0;
|
|
2900
|
+
if (!fingerprint || !policy) {
|
|
2901
|
+
c.status(httpStatus4.UNAUTHORIZED);
|
|
2902
|
+
return c.json({
|
|
2903
|
+
status: httpStatus4.UNAUTHORIZED,
|
|
2904
|
+
message: httpStatus4["401_MESSAGE"]
|
|
2905
|
+
});
|
|
2906
|
+
}
|
|
2907
|
+
c.set("apiKey", __spreadProps(__spreadValues({}, principalFor(policy)), { fingerprint }));
|
|
2908
|
+
return yield runWithApiKey({ policy, fingerprint }, () => next());
|
|
2909
|
+
}));
|
|
2910
|
+
};
|
|
2911
|
+
var apiKeyAuth = ({
|
|
2912
|
+
policies = {},
|
|
2913
|
+
entityConfig,
|
|
2914
|
+
apiKeys: apiKeys2 = process.env.API_KEYS
|
|
2915
|
+
}) => {
|
|
2916
|
+
const errors = validateApiKeyPolicies(policies, entityConfig);
|
|
2917
|
+
if (errors.length) {
|
|
2918
|
+
console.error(
|
|
2919
|
+
`[monorise] Invalid API key policies; every key under them will be rejected:
|
|
2920
|
+
- ${errors.join("\n - ")}`
|
|
2921
|
+
);
|
|
2316
2922
|
}
|
|
2317
|
-
|
|
2318
|
-
|
|
2319
|
-
|
|
2923
|
+
const projectDefinesDefault = Object.prototype.hasOwnProperty.call(
|
|
2924
|
+
policies,
|
|
2925
|
+
DEFAULT_API_KEY_POLICY
|
|
2926
|
+
);
|
|
2927
|
+
return createApiKeyAuth(
|
|
2928
|
+
parseApiKeys(
|
|
2929
|
+
apiKeys2,
|
|
2930
|
+
errors.length ? projectDefinesDefault ? [FULL_API_KEY_POLICY] : BUILT_IN_POLICIES : [...BUILT_IN_POLICIES, ...Object.keys(policies)]
|
|
2931
|
+
),
|
|
2932
|
+
policies
|
|
2933
|
+
);
|
|
2934
|
+
};
|
|
2320
2935
|
|
|
2321
2936
|
// middlewares/general-error-handler.ts
|
|
2322
2937
|
import { createFactory as createFactory2 } from "hono/factory";
|
|
@@ -2421,10 +3036,11 @@ function publishEvent(_0) {
|
|
|
2421
3036
|
payload,
|
|
2422
3037
|
event
|
|
2423
3038
|
}) {
|
|
3039
|
+
const apiKey = currentApiKey();
|
|
2424
3040
|
const params = {
|
|
2425
3041
|
Entries: [
|
|
2426
3042
|
__spreadProps(__spreadValues({}, event), {
|
|
2427
|
-
Detail: JSON.stringify(payload),
|
|
3043
|
+
Detail: JSON.stringify(apiKey ? __spreadProps(__spreadValues({}, payload), { apiKey }) : payload),
|
|
2428
3044
|
EventBusName: CORE_EVENT_BUS
|
|
2429
3045
|
})
|
|
2430
3046
|
]
|
|
@@ -2473,7 +3089,7 @@ var getDependencies = () => {
|
|
|
2473
3089
|
// middlewares/general-error-handler.ts
|
|
2474
3090
|
var factory2 = createFactory2();
|
|
2475
3091
|
var generalErrorHandler = (dependencies = getDependencies()) => factory2.createMiddleware((c) => __async(null, null, function* () {
|
|
2476
|
-
var _a, _b, _c, _d;
|
|
3092
|
+
var _a, _b, _c, _d, _e;
|
|
2477
3093
|
if (c.error) {
|
|
2478
3094
|
const { nanoid: nanoid2, publishErrorEvent: publishErrorEvent2 } = dependencies;
|
|
2479
3095
|
const errorId = nanoid2();
|
|
@@ -2491,14 +3107,15 @@ var generalErrorHandler = (dependencies = getDependencies()) => factory2.createM
|
|
|
2491
3107
|
errorId,
|
|
2492
3108
|
method: c.req.method,
|
|
2493
3109
|
path: c.req.path,
|
|
3110
|
+
apiKeyPolicy: (_a = c.get("apiKey")) == null ? void 0 : _a.policy,
|
|
2494
3111
|
errorName: error == null ? void 0 : error.name,
|
|
2495
3112
|
errorMessage: error == null ? void 0 : error.message,
|
|
2496
3113
|
errorCode: error == null ? void 0 : error.code,
|
|
2497
3114
|
errorStack: error == null ? void 0 : error.stack,
|
|
2498
|
-
errorConstructor: (
|
|
3115
|
+
errorConstructor: (_b = error == null ? void 0 : error.constructor) == null ? void 0 : _b.name,
|
|
2499
3116
|
hasLastError: !!(error == null ? void 0 : error.lastError),
|
|
2500
|
-
lastErrorName: (
|
|
2501
|
-
lastErrorMessage: (
|
|
3117
|
+
lastErrorName: (_d = (_c = error == null ? void 0 : error.lastError) == null ? void 0 : _c.constructor) == null ? void 0 : _d.name,
|
|
3118
|
+
lastErrorMessage: (_e = error == null ? void 0 : error.lastError) == null ? void 0 : _e.message,
|
|
2502
3119
|
context: error == null ? void 0 : error.context
|
|
2503
3120
|
});
|
|
2504
3121
|
c.status(500);
|
|
@@ -2524,8 +3141,14 @@ var appHandler = (container) => ({ routes }) => {
|
|
|
2524
3141
|
origin: process.env.ALLOWED_ORIGIN ? JSON.parse(process.env.ALLOWED_ORIGIN) : []
|
|
2525
3142
|
})
|
|
2526
3143
|
);
|
|
2527
|
-
app.use(
|
|
3144
|
+
app.use(
|
|
3145
|
+
apiKeyAuth({
|
|
3146
|
+
policies: container.config.ApiKeyPolicies,
|
|
3147
|
+
entityConfig: container.config.EntityConfig
|
|
3148
|
+
})
|
|
3149
|
+
);
|
|
2528
3150
|
if (routes) {
|
|
3151
|
+
app.use("/app/*", customRouteGate());
|
|
2529
3152
|
if (typeof routes !== "function") {
|
|
2530
3153
|
app.route("/app", routes);
|
|
2531
3154
|
} else {
|
|
@@ -2546,10 +3169,10 @@ import {
|
|
|
2546
3169
|
StopQueryExecutionCommand
|
|
2547
3170
|
} from "@aws-sdk/client-athena";
|
|
2548
3171
|
import { DynamoDBClient, GetItemCommand, PutItemCommand } from "@aws-sdk/client-dynamodb";
|
|
2549
|
-
import { createHash } from "crypto";
|
|
3172
|
+
import { createHash as createHash2 } from "crypto";
|
|
2550
3173
|
import { handle as handle2 } from "hono/aws-lambda";
|
|
2551
3174
|
import { Hono as Hono3 } from "hono";
|
|
2552
|
-
import
|
|
3175
|
+
import httpStatus5 from "http-status";
|
|
2553
3176
|
var athena = new AthenaClient();
|
|
2554
3177
|
var dynamo = new DynamoDBClient();
|
|
2555
3178
|
function required(name) {
|
|
@@ -2578,7 +3201,7 @@ function apiKeys() {
|
|
|
2578
3201
|
return process.env.ANALYTICS_API_KEYS ? JSON.parse(process.env.ANALYTICS_API_KEYS) : [];
|
|
2579
3202
|
}
|
|
2580
3203
|
function keyFingerprint(key) {
|
|
2581
|
-
return
|
|
3204
|
+
return createHash2("sha256").update(key).digest("hex");
|
|
2582
3205
|
}
|
|
2583
3206
|
function ownedExecution(id, key) {
|
|
2584
3207
|
return __async(this, null, function* () {
|
|
@@ -2596,7 +3219,7 @@ var analyticsQueryHandler = () => {
|
|
|
2596
3219
|
app.use("*", (c, next) => __async(null, null, function* () {
|
|
2597
3220
|
const key = c.req.header("x-api-key");
|
|
2598
3221
|
if (!key || !apiKeys().includes(key)) {
|
|
2599
|
-
return c.json({ status:
|
|
3222
|
+
return c.json({ status: httpStatus5.UNAUTHORIZED, message: httpStatus5["401_MESSAGE"] }, httpStatus5.UNAUTHORIZED);
|
|
2600
3223
|
}
|
|
2601
3224
|
return next();
|
|
2602
3225
|
}));
|
|
@@ -2609,11 +3232,11 @@ var analyticsQueryHandler = () => {
|
|
|
2609
3232
|
app.post("/queries/:name/executions", (c) => __async(null, null, function* () {
|
|
2610
3233
|
var _a, _b;
|
|
2611
3234
|
const query = queries()[c.req.param("name")];
|
|
2612
|
-
if (!query) return c.json({ message: "Unknown analytics query." },
|
|
3235
|
+
if (!query) return c.json({ message: "Unknown analytics query." }, httpStatus5.NOT_FOUND);
|
|
2613
3236
|
const body = yield c.req.json().catch(() => ({}));
|
|
2614
3237
|
const declared = (_a = query.parameters) != null ? _a : {};
|
|
2615
3238
|
if (Object.keys(body).some((name) => !(name in declared))) {
|
|
2616
|
-
return c.json({ message: "Unexpected query parameter." },
|
|
3239
|
+
return c.json({ message: "Unexpected query parameter." }, httpStatus5.BAD_REQUEST);
|
|
2617
3240
|
}
|
|
2618
3241
|
try {
|
|
2619
3242
|
const parameters = Object.entries(declared).map(([name, definition]) => {
|
|
@@ -2639,10 +3262,10 @@ var analyticsQueryHandler = () => {
|
|
|
2639
3262
|
expiresAt: { N: String(Math.floor(Date.now() / 1e3) + 86400) }
|
|
2640
3263
|
}
|
|
2641
3264
|
}));
|
|
2642
|
-
return c.json({ queryExecutionId: started.QueryExecutionId, state: "QUEUED" },
|
|
3265
|
+
return c.json({ queryExecutionId: started.QueryExecutionId, state: "QUEUED" }, httpStatus5.ACCEPTED);
|
|
2643
3266
|
} catch (error) {
|
|
2644
3267
|
if (error instanceof Error && error.message.startsWith("Invalid or missing parameter:")) {
|
|
2645
|
-
return c.json({ message: error.message },
|
|
3268
|
+
return c.json({ message: error.message }, httpStatus5.BAD_REQUEST);
|
|
2646
3269
|
}
|
|
2647
3270
|
throw error;
|
|
2648
3271
|
}
|
|
@@ -2650,7 +3273,7 @@ var analyticsQueryHandler = () => {
|
|
|
2650
3273
|
app.get("/executions/:id", (c) => __async(null, null, function* () {
|
|
2651
3274
|
var _a, _b, _c, _d, _e, _f;
|
|
2652
3275
|
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." },
|
|
3276
|
+
if (!(yield ownedExecution(id, (_a = c.req.header("x-api-key")) != null ? _a : ""))) return c.json({ message: "Unknown analytics execution." }, httpStatus5.NOT_FOUND);
|
|
2654
3277
|
const execution = yield athena.send(new GetQueryExecutionCommand({ QueryExecutionId: id }));
|
|
2655
3278
|
const status = (_b = execution.QueryExecution) == null ? void 0 : _b.Status;
|
|
2656
3279
|
return c.json({
|
|
@@ -2664,7 +3287,7 @@ var analyticsQueryHandler = () => {
|
|
|
2664
3287
|
app.get("/executions/:id/results", (c) => __async(null, null, function* () {
|
|
2665
3288
|
var _a, _b, _c, _d, _e, _f, _g;
|
|
2666
3289
|
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." },
|
|
3290
|
+
if (!(yield ownedExecution(id, (_a = c.req.header("x-api-key")) != null ? _a : ""))) return c.json({ message: "Unknown analytics execution." }, httpStatus5.NOT_FOUND);
|
|
2668
3291
|
const requested = Number((_b = c.req.query("maxResults")) != null ? _b : 100);
|
|
2669
3292
|
const maxResults = Number.isFinite(requested) ? Math.min(Math.max(requested, 1), 1e3) : 100;
|
|
2670
3293
|
const nextToken = c.req.query("nextToken");
|
|
@@ -2690,9 +3313,9 @@ var analyticsQueryHandler = () => {
|
|
|
2690
3313
|
app.post("/executions/:id/cancel", (c) => __async(null, null, function* () {
|
|
2691
3314
|
var _a;
|
|
2692
3315
|
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." },
|
|
3316
|
+
if (!(yield ownedExecution(id, (_a = c.req.header("x-api-key")) != null ? _a : ""))) return c.json({ message: "Unknown analytics execution." }, httpStatus5.NOT_FOUND);
|
|
2694
3317
|
yield athena.send(new StopQueryExecutionCommand({ QueryExecutionId: id }));
|
|
2695
|
-
return c.body(null,
|
|
3318
|
+
return c.body(null, httpStatus5.NO_CONTENT);
|
|
2696
3319
|
}));
|
|
2697
3320
|
return handle2(app);
|
|
2698
3321
|
};
|
|
@@ -2705,7 +3328,7 @@ var handler = (container) => (ev) => __async(null, null, function* () {
|
|
|
2705
3328
|
const errorContext = {};
|
|
2706
3329
|
const body = parseSQSBusEvent(record.body);
|
|
2707
3330
|
const { detail } = body;
|
|
2708
|
-
const { entityType, entityId, entityPayload,
|
|
3331
|
+
const { entityType, entityId, entityPayload, options } = detail;
|
|
2709
3332
|
errorContext.body = body;
|
|
2710
3333
|
try {
|
|
2711
3334
|
if (!entityType) {
|
|
@@ -2715,7 +3338,6 @@ var handler = (container) => (ev) => __async(null, null, function* () {
|
|
|
2715
3338
|
entityType,
|
|
2716
3339
|
entityId,
|
|
2717
3340
|
entityPayload,
|
|
2718
|
-
accountId,
|
|
2719
3341
|
options
|
|
2720
3342
|
});
|
|
2721
3343
|
} catch (err) {
|
|
@@ -7535,8 +8157,7 @@ var MutualService = class {
|
|
|
7535
8157
|
byEntityId,
|
|
7536
8158
|
entityType,
|
|
7537
8159
|
entityId,
|
|
7538
|
-
mutualPayload
|
|
7539
|
-
accountId
|
|
8160
|
+
mutualPayload
|
|
7540
8161
|
} = params;
|
|
7541
8162
|
const { mutual, entity, transactItems, parsedMutualPayload } = yield this.prepareCreateMutual(params);
|
|
7542
8163
|
console.log("[MONORISE_DEBUG] createMutual executing transaction:", {
|
|
@@ -7549,8 +8170,7 @@ var MutualService = class {
|
|
|
7549
8170
|
if (entity) {
|
|
7550
8171
|
yield this.entityServiceLifeCycle.afterCreateEntityHook(
|
|
7551
8172
|
entity,
|
|
7552
|
-
mutualPayload
|
|
7553
|
-
accountId
|
|
8173
|
+
mutualPayload
|
|
7554
8174
|
);
|
|
7555
8175
|
}
|
|
7556
8176
|
const eventPayload = {
|
|
@@ -7559,7 +8179,6 @@ var MutualService = class {
|
|
|
7559
8179
|
entityType,
|
|
7560
8180
|
entityId,
|
|
7561
8181
|
parsedMutualPayload,
|
|
7562
|
-
accountId,
|
|
7563
8182
|
publishedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
7564
8183
|
};
|
|
7565
8184
|
const eventPromises = [
|
|
@@ -7634,7 +8253,6 @@ var MutualService = class {
|
|
|
7634
8253
|
entityType,
|
|
7635
8254
|
entityId,
|
|
7636
8255
|
mutualPayload,
|
|
7637
|
-
accountId,
|
|
7638
8256
|
options
|
|
7639
8257
|
}) {
|
|
7640
8258
|
console.log("[MONORISE_DEBUG] updateMutual service start:", {
|
|
@@ -7669,8 +8287,7 @@ var MutualService = class {
|
|
|
7669
8287
|
byEntityId,
|
|
7670
8288
|
entityType,
|
|
7671
8289
|
entityId,
|
|
7672
|
-
parsedMutualPayload
|
|
7673
|
-
updatedByAccountId: accountId
|
|
8290
|
+
parsedMutualPayload
|
|
7674
8291
|
}
|
|
7675
8292
|
});
|
|
7676
8293
|
console.log("[MONORISE_DEBUG] updateMutual service complete");
|
|
@@ -7710,8 +8327,7 @@ var MutualService = class {
|
|
|
7710
8327
|
byEntityType,
|
|
7711
8328
|
byEntityId,
|
|
7712
8329
|
entityType,
|
|
7713
|
-
entityId
|
|
7714
|
-
accountId
|
|
8330
|
+
entityId
|
|
7715
8331
|
}) {
|
|
7716
8332
|
const mutual = yield this.mutualRepository.deleteMutual(
|
|
7717
8333
|
byEntityType,
|
|
@@ -7725,8 +8341,7 @@ var MutualService = class {
|
|
|
7725
8341
|
byEntityType,
|
|
7726
8342
|
byEntityId,
|
|
7727
8343
|
entityType,
|
|
7728
|
-
entityId
|
|
7729
|
-
deletedByAccountId: accountId
|
|
8344
|
+
entityId
|
|
7730
8345
|
}
|
|
7731
8346
|
});
|
|
7732
8347
|
return mutual;
|
|
@@ -9096,13 +9711,12 @@ var EventUtils = class {
|
|
|
9096
9711
|
};
|
|
9097
9712
|
|
|
9098
9713
|
// controllers/entity/create-entity.controller.ts
|
|
9099
|
-
import { createMiddleware as
|
|
9100
|
-
import
|
|
9714
|
+
import { createMiddleware as createMiddleware5 } from "hono/factory";
|
|
9715
|
+
import httpStatus6 from "http-status";
|
|
9101
9716
|
var CreateEntityController = class {
|
|
9102
9717
|
constructor(entityService) {
|
|
9103
9718
|
this.entityService = entityService;
|
|
9104
|
-
this.controller =
|
|
9105
|
-
const accountId = c.req.header("account-id");
|
|
9719
|
+
this.controller = createMiddleware5((c) => __async(this, null, function* () {
|
|
9106
9720
|
const { entityType } = c.req.param();
|
|
9107
9721
|
const body = yield c.req.json();
|
|
9108
9722
|
try {
|
|
@@ -9110,16 +9724,15 @@ var CreateEntityController = class {
|
|
|
9110
9724
|
entityType,
|
|
9111
9725
|
entityPayload: body,
|
|
9112
9726
|
entityId: body.entityId,
|
|
9113
|
-
accountId,
|
|
9114
9727
|
options: {
|
|
9115
9728
|
createAndUpdateDatetime: body.createdAt
|
|
9116
9729
|
}
|
|
9117
9730
|
});
|
|
9118
|
-
c.status(
|
|
9731
|
+
c.status(httpStatus6.OK);
|
|
9119
9732
|
return c.json(entity);
|
|
9120
9733
|
} catch (err) {
|
|
9121
9734
|
if ((err == null ? void 0 : err.name) === "ZodError") {
|
|
9122
|
-
c.status(
|
|
9735
|
+
c.status(httpStatus6.BAD_REQUEST);
|
|
9123
9736
|
return c.json({
|
|
9124
9737
|
code: "API_VALIDATION_ERROR",
|
|
9125
9738
|
message: "API validation failed",
|
|
@@ -9127,11 +9740,11 @@ var CreateEntityController = class {
|
|
|
9127
9740
|
});
|
|
9128
9741
|
}
|
|
9129
9742
|
if (err instanceof StandardError && err.code === StandardErrorCode.EMAIL_EXISTS) {
|
|
9130
|
-
c.status(
|
|
9743
|
+
c.status(httpStatus6.BAD_REQUEST);
|
|
9131
9744
|
return c.json(__spreadValues({}, err.toJSON()));
|
|
9132
9745
|
}
|
|
9133
9746
|
if (err instanceof StandardError && err.code === StandardErrorCode.UNIQUE_VALUE_EXISTS) {
|
|
9134
|
-
c.status(
|
|
9747
|
+
c.status(httpStatus6.BAD_REQUEST);
|
|
9135
9748
|
return c.json(__spreadValues({}, err.toJSON()));
|
|
9136
9749
|
}
|
|
9137
9750
|
console.log("===create-entity error:", {
|
|
@@ -9148,24 +9761,22 @@ var CreateEntityController = class {
|
|
|
9148
9761
|
};
|
|
9149
9762
|
|
|
9150
9763
|
// controllers/entity/delete-entity.controller.ts
|
|
9151
|
-
import { createMiddleware as
|
|
9152
|
-
import
|
|
9764
|
+
import { createMiddleware as createMiddleware6 } from "hono/factory";
|
|
9765
|
+
import httpStatus7 from "http-status";
|
|
9153
9766
|
var DeleteEntityController = class {
|
|
9154
9767
|
constructor(entityService) {
|
|
9155
9768
|
this.entityService = entityService;
|
|
9156
|
-
this.controller =
|
|
9157
|
-
const accountId = c.req.header("account-id");
|
|
9769
|
+
this.controller = createMiddleware6((c) => __async(this, null, function* () {
|
|
9158
9770
|
const { entityType, entityId } = c.req.param();
|
|
9159
9771
|
try {
|
|
9160
9772
|
yield this.entityService.deleteEntity({
|
|
9161
9773
|
entityType,
|
|
9162
|
-
entityId
|
|
9163
|
-
accountId
|
|
9774
|
+
entityId
|
|
9164
9775
|
});
|
|
9165
9776
|
return c.json({ message: "entity deleted" });
|
|
9166
9777
|
} catch (err) {
|
|
9167
9778
|
if (err instanceof StandardError && err.code === StandardErrorCode.ENTITY_NOT_FOUND) {
|
|
9168
|
-
c.status(
|
|
9779
|
+
c.status(httpStatus7.NOT_FOUND);
|
|
9169
9780
|
return c.json(__spreadValues({}, err.toJSON()));
|
|
9170
9781
|
}
|
|
9171
9782
|
throw err;
|
|
@@ -9175,12 +9786,12 @@ var DeleteEntityController = class {
|
|
|
9175
9786
|
};
|
|
9176
9787
|
|
|
9177
9788
|
// controllers/entity/get-entity-by-unique-field-value.controller.ts
|
|
9178
|
-
import { createMiddleware as
|
|
9179
|
-
import
|
|
9789
|
+
import { createMiddleware as createMiddleware7 } from "hono/factory";
|
|
9790
|
+
import httpStatus8 from "http-status";
|
|
9180
9791
|
var GetEntityByUniqueFieldValueController = class {
|
|
9181
9792
|
constructor(entityRepository) {
|
|
9182
9793
|
this.entityRepository = entityRepository;
|
|
9183
|
-
this.controller =
|
|
9794
|
+
this.controller = createMiddleware7((c) => __async(this, null, function* () {
|
|
9184
9795
|
const { entityType, uniqueField, uniqueFieldValue } = c.req.param();
|
|
9185
9796
|
try {
|
|
9186
9797
|
const entity = yield this.entityRepository.getEntityByUniqueField(
|
|
@@ -9191,7 +9802,7 @@ var GetEntityByUniqueFieldValueController = class {
|
|
|
9191
9802
|
return c.json(entity);
|
|
9192
9803
|
} catch (err) {
|
|
9193
9804
|
if (err instanceof StandardError && err.code === StandardErrorCode.ENTITY_IS_UNDEFINED) {
|
|
9194
|
-
c.status(
|
|
9805
|
+
c.status(httpStatus8.NOT_FOUND);
|
|
9195
9806
|
return c.json({
|
|
9196
9807
|
code: "ENTITY_NOT_FOUND",
|
|
9197
9808
|
message: "Entity not found"
|
|
@@ -9204,23 +9815,23 @@ var GetEntityByUniqueFieldValueController = class {
|
|
|
9204
9815
|
};
|
|
9205
9816
|
|
|
9206
9817
|
// controllers/entity/get-entity.controller.ts
|
|
9207
|
-
import { createMiddleware as
|
|
9208
|
-
import
|
|
9818
|
+
import { createMiddleware as createMiddleware8 } from "hono/factory";
|
|
9819
|
+
import httpStatus9 from "http-status";
|
|
9209
9820
|
var GetEntityController = class {
|
|
9210
9821
|
constructor(entityRepository) {
|
|
9211
9822
|
this.entityRepository = entityRepository;
|
|
9212
|
-
this.controller =
|
|
9823
|
+
this.controller = createMiddleware8((c) => __async(this, null, function* () {
|
|
9213
9824
|
const { entityType, entityId } = c.req.param();
|
|
9214
9825
|
try {
|
|
9215
9826
|
const entity = yield this.entityRepository.getEntity(
|
|
9216
9827
|
entityType,
|
|
9217
9828
|
entityId
|
|
9218
9829
|
);
|
|
9219
|
-
c.status(
|
|
9830
|
+
c.status(httpStatus9.OK);
|
|
9220
9831
|
return c.json(entity);
|
|
9221
9832
|
} catch (err) {
|
|
9222
9833
|
if (err instanceof StandardError && err.code === StandardErrorCode.ENTITY_IS_UNDEFINED) {
|
|
9223
|
-
c.status(
|
|
9834
|
+
c.status(httpStatus9.NOT_FOUND);
|
|
9224
9835
|
return c.json({
|
|
9225
9836
|
code: "ENTITY_NOT_FOUND",
|
|
9226
9837
|
message: "Entity not found"
|
|
@@ -9233,7 +9844,7 @@ var GetEntityController = class {
|
|
|
9233
9844
|
};
|
|
9234
9845
|
|
|
9235
9846
|
// controllers/entity/list-entities.controller.ts
|
|
9236
|
-
import { createMiddleware as
|
|
9847
|
+
import { createMiddleware as createMiddleware9 } from "hono/factory";
|
|
9237
9848
|
var querySchema = external_exports.object({
|
|
9238
9849
|
limit: external_exports.string().optional(),
|
|
9239
9850
|
lastKey: external_exports.string().optional(),
|
|
@@ -9244,16 +9855,11 @@ var querySchema = external_exports.object({
|
|
|
9244
9855
|
var ListEntitiesController = class {
|
|
9245
9856
|
constructor(entityRepository) {
|
|
9246
9857
|
this.entityRepository = entityRepository;
|
|
9247
|
-
this.controller =
|
|
9858
|
+
this.controller = createMiddleware9((c) => __async(this, null, function* () {
|
|
9248
9859
|
const errorContext = {};
|
|
9249
9860
|
try {
|
|
9250
|
-
const accountId = c.req.header("account-id") || "";
|
|
9251
|
-
if (Array.isArray(accountId)) {
|
|
9252
|
-
throw new Error("multiple account-id detected");
|
|
9253
|
-
}
|
|
9254
9861
|
const params = c.req.param();
|
|
9255
9862
|
const queries2 = c.req.query();
|
|
9256
|
-
errorContext.accountId = accountId;
|
|
9257
9863
|
errorContext.params = params;
|
|
9258
9864
|
errorContext.query = queries2;
|
|
9259
9865
|
const { entityType } = params;
|
|
@@ -9292,19 +9898,18 @@ var ListEntitiesController = class {
|
|
|
9292
9898
|
};
|
|
9293
9899
|
|
|
9294
9900
|
// controllers/entity/update-entity.controller.ts
|
|
9295
|
-
import { createMiddleware as
|
|
9296
|
-
import
|
|
9901
|
+
import { createMiddleware as createMiddleware10 } from "hono/factory";
|
|
9902
|
+
import httpStatus10 from "http-status";
|
|
9297
9903
|
var UpdateEntityController = class {
|
|
9298
9904
|
constructor(entityService) {
|
|
9299
9905
|
this.entityService = entityService;
|
|
9300
|
-
this.controller =
|
|
9301
|
-
const accountId = c.req.header("account-id");
|
|
9906
|
+
this.controller = createMiddleware10((c) => __async(this, null, function* () {
|
|
9302
9907
|
const { entityType, entityId } = c.req.param();
|
|
9303
9908
|
const body = yield c.req.json();
|
|
9304
9909
|
const _a = body, { $condition: condition, $where: where } = _a, entityPayload = __objRest(_a, ["$condition", "$where"]);
|
|
9305
9910
|
if (condition !== void 0) {
|
|
9306
9911
|
if (typeof condition !== "string" || condition.trim().length === 0) {
|
|
9307
|
-
c.status(
|
|
9912
|
+
c.status(httpStatus10.BAD_REQUEST);
|
|
9308
9913
|
return c.json({
|
|
9309
9914
|
code: "API_VALIDATION_ERROR",
|
|
9310
9915
|
message: "$condition must be a non-empty string"
|
|
@@ -9312,7 +9917,6 @@ var UpdateEntityController = class {
|
|
|
9312
9917
|
}
|
|
9313
9918
|
}
|
|
9314
9919
|
const errorContext = {
|
|
9315
|
-
accountId,
|
|
9316
9920
|
"req.params": c.req.param(),
|
|
9317
9921
|
"req.body": body
|
|
9318
9922
|
};
|
|
@@ -9321,16 +9925,15 @@ var UpdateEntityController = class {
|
|
|
9321
9925
|
entityType,
|
|
9322
9926
|
entityId,
|
|
9323
9927
|
entityPayload,
|
|
9324
|
-
accountId,
|
|
9325
9928
|
condition,
|
|
9326
9929
|
where
|
|
9327
9930
|
});
|
|
9328
9931
|
errorContext.entity = entity;
|
|
9329
|
-
c.status(
|
|
9932
|
+
c.status(httpStatus10.OK);
|
|
9330
9933
|
return c.json(entity);
|
|
9331
9934
|
} catch (err) {
|
|
9332
9935
|
if ((err == null ? void 0 : err.name) === "ZodError") {
|
|
9333
|
-
c.status(
|
|
9936
|
+
c.status(httpStatus10.BAD_REQUEST);
|
|
9334
9937
|
return c.json({
|
|
9335
9938
|
code: "API_VALIDATION_ERROR",
|
|
9336
9939
|
message: "API validation failed",
|
|
@@ -9338,19 +9941,19 @@ var UpdateEntityController = class {
|
|
|
9338
9941
|
});
|
|
9339
9942
|
}
|
|
9340
9943
|
if (err instanceof StandardError && (err.code === StandardErrorCode.ENTITY_NOT_FOUND || err.code === StandardErrorCode.ENTITY_IS_UNDEFINED)) {
|
|
9341
|
-
c.status(
|
|
9944
|
+
c.status(httpStatus10.NOT_FOUND);
|
|
9342
9945
|
return c.json(__spreadValues({}, err.toJSON()));
|
|
9343
9946
|
}
|
|
9344
9947
|
if (err instanceof StandardError && err.code === StandardErrorCode.INVALID_CONDITION) {
|
|
9345
|
-
c.status(
|
|
9948
|
+
c.status(httpStatus10.BAD_REQUEST);
|
|
9346
9949
|
return c.json(__spreadValues({}, err.toJSON()));
|
|
9347
9950
|
}
|
|
9348
9951
|
if (err instanceof StandardError && err.code === StandardErrorCode.UNIQUE_VALUE_EXISTS) {
|
|
9349
|
-
c.status(
|
|
9952
|
+
c.status(httpStatus10.BAD_REQUEST);
|
|
9350
9953
|
return c.json(__spreadValues({}, err.toJSON()));
|
|
9351
9954
|
}
|
|
9352
9955
|
if (err instanceof StandardError && err.code === StandardErrorCode.CONDITIONAL_CHECK_FAILED) {
|
|
9353
|
-
c.status(
|
|
9956
|
+
c.status(httpStatus10.CONFLICT);
|
|
9354
9957
|
return c.json(__spreadValues({}, err.toJSON()));
|
|
9355
9958
|
}
|
|
9356
9959
|
console.log(
|
|
@@ -9365,20 +9968,19 @@ var UpdateEntityController = class {
|
|
|
9365
9968
|
};
|
|
9366
9969
|
|
|
9367
9970
|
// controllers/entity/adjust-entity.controller.ts
|
|
9368
|
-
import { createMiddleware as
|
|
9369
|
-
import
|
|
9971
|
+
import { createMiddleware as createMiddleware11 } from "hono/factory";
|
|
9972
|
+
import httpStatus11 from "http-status";
|
|
9370
9973
|
var AdjustEntityController = class {
|
|
9371
9974
|
constructor(entityService) {
|
|
9372
9975
|
this.entityService = entityService;
|
|
9373
|
-
this.controller =
|
|
9976
|
+
this.controller = createMiddleware11((c) => __async(this, null, function* () {
|
|
9374
9977
|
var _b;
|
|
9375
|
-
const accountId = c.req.header("account-id") || "";
|
|
9376
9978
|
const { entityType, entityId } = c.req.param();
|
|
9377
9979
|
const body = yield c.req.json();
|
|
9378
9980
|
const _a = body, { $condition: condition } = _a, adjustments = __objRest(_a, ["$condition"]);
|
|
9379
9981
|
if (condition !== void 0) {
|
|
9380
9982
|
if (typeof condition !== "string" || condition.trim().length === 0) {
|
|
9381
|
-
c.status(
|
|
9983
|
+
c.status(httpStatus11.BAD_REQUEST);
|
|
9382
9984
|
return c.json({
|
|
9383
9985
|
code: "API_VALIDATION_ERROR",
|
|
9384
9986
|
message: "$condition must be a non-empty string"
|
|
@@ -9387,7 +9989,7 @@ var AdjustEntityController = class {
|
|
|
9387
9989
|
}
|
|
9388
9990
|
for (const [key, value] of Object.entries(adjustments)) {
|
|
9389
9991
|
if (typeof value !== "number") {
|
|
9390
|
-
c.status(
|
|
9992
|
+
c.status(httpStatus11.BAD_REQUEST);
|
|
9391
9993
|
return c.json({
|
|
9392
9994
|
code: "API_VALIDATION_ERROR",
|
|
9393
9995
|
message: `Field "${key}" must be a number, got ${typeof value}`
|
|
@@ -9399,22 +10001,21 @@ var AdjustEntityController = class {
|
|
|
9399
10001
|
entityType,
|
|
9400
10002
|
entityId,
|
|
9401
10003
|
adjustments,
|
|
9402
|
-
accountId,
|
|
9403
10004
|
condition
|
|
9404
10005
|
});
|
|
9405
|
-
c.status(
|
|
10006
|
+
c.status(httpStatus11.OK);
|
|
9406
10007
|
return c.json(entity.toJSON());
|
|
9407
10008
|
} catch (err) {
|
|
9408
10009
|
if (err instanceof StandardError && err.code === StandardErrorCode.ENTITY_IS_UNDEFINED) {
|
|
9409
|
-
c.status(
|
|
10010
|
+
c.status(httpStatus11.NOT_FOUND);
|
|
9410
10011
|
return c.json(__spreadValues({}, err.toJSON()));
|
|
9411
10012
|
}
|
|
9412
10013
|
if (err instanceof StandardError && err.code === StandardErrorCode.INVALID_CONDITION) {
|
|
9413
|
-
c.status(
|
|
10014
|
+
c.status(httpStatus11.BAD_REQUEST);
|
|
9414
10015
|
return c.json(__spreadValues({}, err.toJSON()));
|
|
9415
10016
|
}
|
|
9416
10017
|
if ((err == null ? void 0 : err.name) === "ConditionalCheckFailedException" || ((_b = err == null ? void 0 : err.__type) == null ? void 0 : _b.includes("ConditionalCheckFailed"))) {
|
|
9417
|
-
c.status(
|
|
10018
|
+
c.status(httpStatus11.CONFLICT);
|
|
9418
10019
|
return c.json({
|
|
9419
10020
|
code: "ADJUSTMENT_CONSTRAINT_VIOLATED",
|
|
9420
10021
|
message: "Adjustment would violate entity constraints"
|
|
@@ -9428,16 +10029,15 @@ var AdjustEntityController = class {
|
|
|
9428
10029
|
};
|
|
9429
10030
|
|
|
9430
10031
|
// controllers/entity/upsert-entity.controller.ts
|
|
9431
|
-
import { createMiddleware as
|
|
9432
|
-
import
|
|
10032
|
+
import { createMiddleware as createMiddleware12 } from "hono/factory";
|
|
10033
|
+
import httpStatus12 from "http-status";
|
|
9433
10034
|
var UpsertEntityController = class {
|
|
9434
10035
|
constructor(EntityConfig, entityRepository, publishEvent2) {
|
|
9435
10036
|
this.EntityConfig = EntityConfig;
|
|
9436
10037
|
this.entityRepository = entityRepository;
|
|
9437
10038
|
this.publishEvent = publishEvent2;
|
|
9438
|
-
this.controller =
|
|
10039
|
+
this.controller = createMiddleware12((c) => __async(this, null, function* () {
|
|
9439
10040
|
var _a;
|
|
9440
|
-
const accountId = c.req.header("account-id");
|
|
9441
10041
|
const { entityType, entityId } = c.req.param();
|
|
9442
10042
|
try {
|
|
9443
10043
|
const entityConfig = this.EntityConfig[entityType];
|
|
@@ -9493,14 +10093,13 @@ var UpsertEntityController = class {
|
|
|
9493
10093
|
payload: {
|
|
9494
10094
|
entityType,
|
|
9495
10095
|
entityId: entity.entityId,
|
|
9496
|
-
payload: body
|
|
9497
|
-
createdByAccountId: accountId
|
|
10096
|
+
payload: body
|
|
9498
10097
|
}
|
|
9499
10098
|
});
|
|
9500
10099
|
return c.json(entity);
|
|
9501
10100
|
} catch (err) {
|
|
9502
10101
|
if (err instanceof ZodError) {
|
|
9503
|
-
c.status(
|
|
10102
|
+
c.status(httpStatus12.BAD_REQUEST);
|
|
9504
10103
|
return c.json({
|
|
9505
10104
|
code: "API_VALIDATION_ERROR",
|
|
9506
10105
|
message: "API validation failed",
|
|
@@ -9508,7 +10107,7 @@ var UpsertEntityController = class {
|
|
|
9508
10107
|
});
|
|
9509
10108
|
}
|
|
9510
10109
|
if (err instanceof StandardError && err.code === StandardErrorCode.EMAIL_EXISTS) {
|
|
9511
|
-
c.status(
|
|
10110
|
+
c.status(httpStatus12.BAD_REQUEST);
|
|
9512
10111
|
return c.json(__spreadValues({}, err.toJSON()));
|
|
9513
10112
|
}
|
|
9514
10113
|
throw err;
|
|
@@ -9518,13 +10117,12 @@ var UpsertEntityController = class {
|
|
|
9518
10117
|
};
|
|
9519
10118
|
|
|
9520
10119
|
// controllers/mutual/create-mutual.controller.ts
|
|
9521
|
-
import { createMiddleware as
|
|
9522
|
-
import
|
|
10120
|
+
import { createMiddleware as createMiddleware13 } from "hono/factory";
|
|
10121
|
+
import httpStatus13 from "http-status";
|
|
9523
10122
|
var CreateMutualController = class {
|
|
9524
10123
|
constructor(mutualService) {
|
|
9525
10124
|
this.mutualService = mutualService;
|
|
9526
|
-
this.controller =
|
|
9527
|
-
const accountId = c.req.header("account-id");
|
|
10125
|
+
this.controller = createMiddleware13((c) => __async(this, null, function* () {
|
|
9528
10126
|
const { byEntityType, byEntityId, entityType, entityId } = c.req.param();
|
|
9529
10127
|
const asEntity = c.req.query("asEntity");
|
|
9530
10128
|
const body = yield c.req.json();
|
|
@@ -9535,7 +10133,6 @@ var CreateMutualController = class {
|
|
|
9535
10133
|
entityType,
|
|
9536
10134
|
entityId,
|
|
9537
10135
|
mutualPayload: body,
|
|
9538
|
-
accountId,
|
|
9539
10136
|
options: {
|
|
9540
10137
|
asEntity
|
|
9541
10138
|
}
|
|
@@ -9543,7 +10140,7 @@ var CreateMutualController = class {
|
|
|
9543
10140
|
return c.json(mutual);
|
|
9544
10141
|
} catch (err) {
|
|
9545
10142
|
if (err instanceof ZodError) {
|
|
9546
|
-
c.status(
|
|
10143
|
+
c.status(httpStatus13.BAD_REQUEST);
|
|
9547
10144
|
return c.json({
|
|
9548
10145
|
code: "API_VALIDATION_ERROR",
|
|
9549
10146
|
message: "API validation failed",
|
|
@@ -9551,11 +10148,11 @@ var CreateMutualController = class {
|
|
|
9551
10148
|
});
|
|
9552
10149
|
}
|
|
9553
10150
|
if (err instanceof StandardError && err.code === StandardErrorCode.MUTUAL_EXISTS) {
|
|
9554
|
-
c.status(
|
|
10151
|
+
c.status(httpStatus13.BAD_REQUEST);
|
|
9555
10152
|
return c.json(__spreadValues({}, err.toJSON()));
|
|
9556
10153
|
}
|
|
9557
10154
|
if (err instanceof StandardError && err.code === StandardErrorCode.ENTITY_IS_UNDEFINED) {
|
|
9558
|
-
c.status(
|
|
10155
|
+
c.status(httpStatus13.BAD_REQUEST);
|
|
9559
10156
|
return c.json(__spreadValues({}, err.toJSON()));
|
|
9560
10157
|
}
|
|
9561
10158
|
throw err;
|
|
@@ -9565,26 +10162,24 @@ var CreateMutualController = class {
|
|
|
9565
10162
|
};
|
|
9566
10163
|
|
|
9567
10164
|
// controllers/mutual/delete-mutual.controller.ts
|
|
9568
|
-
import { createMiddleware as
|
|
9569
|
-
import
|
|
10165
|
+
import { createMiddleware as createMiddleware14 } from "hono/factory";
|
|
10166
|
+
import httpStatus14 from "http-status";
|
|
9570
10167
|
var DeleteMutualController = class {
|
|
9571
10168
|
constructor(mutualService) {
|
|
9572
10169
|
this.mutualService = mutualService;
|
|
9573
|
-
this.controller =
|
|
9574
|
-
const accountId = c.req.header("account-id");
|
|
10170
|
+
this.controller = createMiddleware14((c) => __async(this, null, function* () {
|
|
9575
10171
|
const { byEntityType, byEntityId, entityType, entityId } = c.req.param();
|
|
9576
10172
|
try {
|
|
9577
10173
|
const mutual = yield this.mutualService.deleteMutual({
|
|
9578
10174
|
byEntityType,
|
|
9579
10175
|
byEntityId,
|
|
9580
10176
|
entityType,
|
|
9581
|
-
entityId
|
|
9582
|
-
accountId
|
|
10177
|
+
entityId
|
|
9583
10178
|
});
|
|
9584
10179
|
return c.json(mutual);
|
|
9585
10180
|
} catch (err) {
|
|
9586
10181
|
if (err instanceof StandardError && err.code === StandardErrorCode.MUTUAL_NOT_FOUND) {
|
|
9587
|
-
c.status(
|
|
10182
|
+
c.status(httpStatus14.BAD_REQUEST);
|
|
9588
10183
|
return c.json(__spreadValues({}, err.toJSON()));
|
|
9589
10184
|
}
|
|
9590
10185
|
throw err;
|
|
@@ -9594,12 +10189,12 @@ var DeleteMutualController = class {
|
|
|
9594
10189
|
};
|
|
9595
10190
|
|
|
9596
10191
|
// controllers/mutual/get-mutual.controller.ts
|
|
9597
|
-
import { createMiddleware as
|
|
9598
|
-
import
|
|
10192
|
+
import { createMiddleware as createMiddleware15 } from "hono/factory";
|
|
10193
|
+
import httpStatus15 from "http-status";
|
|
9599
10194
|
var GetMutualController = class {
|
|
9600
10195
|
constructor(associateRepository) {
|
|
9601
10196
|
this.associateRepository = associateRepository;
|
|
9602
|
-
this.controller =
|
|
10197
|
+
this.controller = createMiddleware15((c) => __async(this, null, function* () {
|
|
9603
10198
|
const { byEntityType, byEntityId, entityType, entityId } = c.req.param();
|
|
9604
10199
|
try {
|
|
9605
10200
|
const associate = yield this.associateRepository.getMutual(
|
|
@@ -9611,7 +10206,7 @@ var GetMutualController = class {
|
|
|
9611
10206
|
return c.json(associate);
|
|
9612
10207
|
} catch (err) {
|
|
9613
10208
|
if (err instanceof StandardError && err.code === StandardErrorCode.MUTUAL_IS_UNDEFINED) {
|
|
9614
|
-
c.status(
|
|
10209
|
+
c.status(httpStatus15.NOT_FOUND);
|
|
9615
10210
|
return c.json({
|
|
9616
10211
|
code: "MUTUAL_NOT_FOUND",
|
|
9617
10212
|
message: "Mutual not found"
|
|
@@ -9624,11 +10219,11 @@ var GetMutualController = class {
|
|
|
9624
10219
|
};
|
|
9625
10220
|
|
|
9626
10221
|
// controllers/mutual/list-entities-by-entity.controller.ts
|
|
9627
|
-
import { createMiddleware as
|
|
10222
|
+
import { createMiddleware as createMiddleware16 } from "hono/factory";
|
|
9628
10223
|
var ListEntitiesByEntityController = class {
|
|
9629
10224
|
constructor(associateRepository) {
|
|
9630
10225
|
this.associateRepository = associateRepository;
|
|
9631
|
-
this.controller =
|
|
10226
|
+
this.controller = createMiddleware16((c) => __async(this, null, function* () {
|
|
9632
10227
|
const { byEntityType, byEntityId, entityType } = c.req.param();
|
|
9633
10228
|
const querySchema3 = external_exports.object({
|
|
9634
10229
|
chainEntityQuery: external_exports.string().optional(),
|
|
@@ -9686,13 +10281,12 @@ var ListEntitiesByEntityController = class {
|
|
|
9686
10281
|
};
|
|
9687
10282
|
|
|
9688
10283
|
// controllers/mutual/update-mutual.controller.ts
|
|
9689
|
-
import { createMiddleware as
|
|
9690
|
-
import
|
|
10284
|
+
import { createMiddleware as createMiddleware17 } from "hono/factory";
|
|
10285
|
+
import httpStatus16 from "http-status";
|
|
9691
10286
|
var UpdateMutualController = class {
|
|
9692
10287
|
constructor(mutualService) {
|
|
9693
10288
|
this.mutualService = mutualService;
|
|
9694
|
-
this.controller =
|
|
9695
|
-
const accountId = c.req.header("account-id");
|
|
10289
|
+
this.controller = createMiddleware17((c) => __async(this, null, function* () {
|
|
9696
10290
|
const { byEntityType, byEntityId, entityType, entityId } = c.req.param();
|
|
9697
10291
|
const body = yield c.req.json();
|
|
9698
10292
|
try {
|
|
@@ -9702,7 +10296,6 @@ var UpdateMutualController = class {
|
|
|
9702
10296
|
entityType,
|
|
9703
10297
|
entityId,
|
|
9704
10298
|
mutualPayload: body,
|
|
9705
|
-
accountId,
|
|
9706
10299
|
options: {
|
|
9707
10300
|
returnUpdatedValue: true
|
|
9708
10301
|
}
|
|
@@ -9710,7 +10303,7 @@ var UpdateMutualController = class {
|
|
|
9710
10303
|
return c.json(mutual);
|
|
9711
10304
|
} catch (err) {
|
|
9712
10305
|
if (err instanceof ZodError) {
|
|
9713
|
-
c.status(
|
|
10306
|
+
c.status(httpStatus16.BAD_REQUEST);
|
|
9714
10307
|
return c.json({
|
|
9715
10308
|
code: "API_VALIDATION_ERROR",
|
|
9716
10309
|
message: "API validation failed",
|
|
@@ -9718,7 +10311,7 @@ var UpdateMutualController = class {
|
|
|
9718
10311
|
});
|
|
9719
10312
|
}
|
|
9720
10313
|
if (err instanceof StandardError && err.code === StandardErrorCode.MUTUAL_NOT_FOUND) {
|
|
9721
|
-
c.status(
|
|
10314
|
+
c.status(httpStatus16.BAD_REQUEST);
|
|
9722
10315
|
return c.json(__spreadValues({}, err.toJSON()));
|
|
9723
10316
|
}
|
|
9724
10317
|
throw err;
|
|
@@ -9878,7 +10471,6 @@ var EntityService = class {
|
|
|
9878
10471
|
entityType,
|
|
9879
10472
|
entityId,
|
|
9880
10473
|
entityPayload,
|
|
9881
|
-
accountId,
|
|
9882
10474
|
options
|
|
9883
10475
|
}) {
|
|
9884
10476
|
var _a, _b;
|
|
@@ -9912,8 +10504,7 @@ var EntityService = class {
|
|
|
9912
10504
|
);
|
|
9913
10505
|
yield this.entityServiceLifeCycle.afterCreateEntityHook(
|
|
9914
10506
|
entity,
|
|
9915
|
-
entityPayload
|
|
9916
|
-
accountId
|
|
10507
|
+
entityPayload
|
|
9917
10508
|
);
|
|
9918
10509
|
return entity;
|
|
9919
10510
|
});
|
|
@@ -9921,7 +10512,6 @@ var EntityService = class {
|
|
|
9921
10512
|
entityType,
|
|
9922
10513
|
entityId,
|
|
9923
10514
|
adjustments,
|
|
9924
|
-
accountId,
|
|
9925
10515
|
condition
|
|
9926
10516
|
}) {
|
|
9927
10517
|
var _a, _b, _c;
|
|
@@ -9987,7 +10577,6 @@ var EntityService = class {
|
|
|
9987
10577
|
entityType,
|
|
9988
10578
|
entityId,
|
|
9989
10579
|
data: entity.data,
|
|
9990
|
-
updatedByAccountId: accountId,
|
|
9991
10580
|
publishedAt: entity.updatedAt || (/* @__PURE__ */ new Date()).toISOString()
|
|
9992
10581
|
}
|
|
9993
10582
|
});
|
|
@@ -9997,7 +10586,6 @@ var EntityService = class {
|
|
|
9997
10586
|
entityType,
|
|
9998
10587
|
entityId,
|
|
9999
10588
|
entityPayload,
|
|
10000
|
-
accountId,
|
|
10001
10589
|
condition,
|
|
10002
10590
|
where
|
|
10003
10591
|
}) {
|
|
@@ -10099,7 +10687,6 @@ var EntityService = class {
|
|
|
10099
10687
|
entityType,
|
|
10100
10688
|
entityId,
|
|
10101
10689
|
data: entity.data,
|
|
10102
|
-
updatedByAccountId: accountId,
|
|
10103
10690
|
publishedAt: entity.updatedAt || (/* @__PURE__ */ new Date()).toISOString()
|
|
10104
10691
|
}
|
|
10105
10692
|
});
|
|
@@ -10113,16 +10700,14 @@ var EntityService = class {
|
|
|
10113
10700
|
});
|
|
10114
10701
|
this.deleteEntity = (_0) => __async(this, [_0], function* ({
|
|
10115
10702
|
entityType,
|
|
10116
|
-
entityId
|
|
10117
|
-
accountId
|
|
10703
|
+
entityId
|
|
10118
10704
|
}) {
|
|
10119
10705
|
yield this.entityRepository.deleteEntity(entityType, entityId);
|
|
10120
10706
|
yield this.publishEvent({
|
|
10121
10707
|
event: EVENT.CORE.ENTITY_DELETED,
|
|
10122
10708
|
payload: {
|
|
10123
10709
|
entityType,
|
|
10124
|
-
entityId
|
|
10125
|
-
deletedByAccountId: accountId
|
|
10710
|
+
entityId
|
|
10126
10711
|
}
|
|
10127
10712
|
});
|
|
10128
10713
|
});
|
|
@@ -10159,7 +10744,7 @@ var EntityService = class {
|
|
|
10159
10744
|
};
|
|
10160
10745
|
|
|
10161
10746
|
// controllers/tag/list-tags.controller.ts
|
|
10162
|
-
import { createMiddleware as
|
|
10747
|
+
import { createMiddleware as createMiddleware18 } from "hono/factory";
|
|
10163
10748
|
var querySchema2 = external_exports.object({
|
|
10164
10749
|
group: external_exports.string().optional(),
|
|
10165
10750
|
query: external_exports.string().optional(),
|
|
@@ -10171,7 +10756,7 @@ var querySchema2 = external_exports.object({
|
|
|
10171
10756
|
var ListTagsController = class {
|
|
10172
10757
|
constructor(tagRepository) {
|
|
10173
10758
|
this.tagRepository = tagRepository;
|
|
10174
|
-
this.controller =
|
|
10759
|
+
this.controller = createMiddleware18((c) => __async(this, null, function* () {
|
|
10175
10760
|
const errorContext = {};
|
|
10176
10761
|
try {
|
|
10177
10762
|
errorContext.params = c.req.param();
|
|
@@ -10206,32 +10791,30 @@ var ListTagsController = class {
|
|
|
10206
10791
|
};
|
|
10207
10792
|
|
|
10208
10793
|
// controllers/transaction/execute-transaction.controller.ts
|
|
10209
|
-
import { createMiddleware as
|
|
10210
|
-
import
|
|
10794
|
+
import { createMiddleware as createMiddleware19 } from "hono/factory";
|
|
10795
|
+
import httpStatus17 from "http-status";
|
|
10211
10796
|
var ExecuteTransactionController = class {
|
|
10212
10797
|
constructor(transactionService) {
|
|
10213
10798
|
this.transactionService = transactionService;
|
|
10214
10799
|
// biome-ignore lint/suspicious/noExplicitAny: Hono createMiddleware requires consistent return types
|
|
10215
|
-
this.controller =
|
|
10216
|
-
const accountId = c.req.header("account-id") || "";
|
|
10800
|
+
this.controller = createMiddleware19((c) => __async(this, null, function* () {
|
|
10217
10801
|
try {
|
|
10218
10802
|
const body = yield c.req.json();
|
|
10219
10803
|
if (!body.operations || !Array.isArray(body.operations)) {
|
|
10220
|
-
c.status(
|
|
10804
|
+
c.status(httpStatus17.BAD_REQUEST);
|
|
10221
10805
|
return c.json({
|
|
10222
10806
|
code: "API_VALIDATION_ERROR",
|
|
10223
10807
|
message: 'Request body must contain an "operations" array'
|
|
10224
10808
|
});
|
|
10225
10809
|
}
|
|
10226
10810
|
const result = yield this.transactionService.executeTransaction(
|
|
10227
|
-
body.operations
|
|
10228
|
-
accountId
|
|
10811
|
+
body.operations
|
|
10229
10812
|
);
|
|
10230
|
-
c.status(
|
|
10813
|
+
c.status(httpStatus17.OK);
|
|
10231
10814
|
return c.json(result);
|
|
10232
10815
|
} catch (err) {
|
|
10233
10816
|
if ((err == null ? void 0 : err.name) === "ZodError") {
|
|
10234
|
-
c.status(
|
|
10817
|
+
c.status(httpStatus17.BAD_REQUEST);
|
|
10235
10818
|
return c.json({
|
|
10236
10819
|
code: "API_VALIDATION_ERROR",
|
|
10237
10820
|
message: "Validation failed",
|
|
@@ -10239,7 +10822,7 @@ var ExecuteTransactionController = class {
|
|
|
10239
10822
|
});
|
|
10240
10823
|
}
|
|
10241
10824
|
if (err instanceof SyntaxError) {
|
|
10242
|
-
c.status(
|
|
10825
|
+
c.status(httpStatus17.BAD_REQUEST);
|
|
10243
10826
|
return c.json({
|
|
10244
10827
|
code: "API_VALIDATION_ERROR",
|
|
10245
10828
|
message: "Request body must be valid JSON"
|
|
@@ -10248,15 +10831,15 @@ var ExecuteTransactionController = class {
|
|
|
10248
10831
|
if (err instanceof StandardError) {
|
|
10249
10832
|
const code = err.code;
|
|
10250
10833
|
if (code === StandardErrorCode.ENTITY_IS_UNDEFINED || code === StandardErrorCode.ENTITY_NOT_FOUND || code === StandardErrorCode.MUTUAL_NOT_FOUND) {
|
|
10251
|
-
c.status(
|
|
10834
|
+
c.status(httpStatus17.NOT_FOUND);
|
|
10252
10835
|
return c.json(__spreadValues({}, err.toJSON()));
|
|
10253
10836
|
}
|
|
10254
10837
|
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(
|
|
10838
|
+
c.status(httpStatus17.BAD_REQUEST);
|
|
10256
10839
|
return c.json(__spreadValues({}, err.toJSON()));
|
|
10257
10840
|
}
|
|
10258
10841
|
if (code === StandardErrorCode.TRANSACTION_FAILED || code === StandardErrorCode.CONDITIONAL_CHECK_FAILED || code === StandardErrorCode.UNIQUE_VALUE_EXISTS || code === StandardErrorCode.MUTUAL_EXISTS) {
|
|
10259
|
-
c.status(
|
|
10842
|
+
c.status(httpStatus17.CONFLICT);
|
|
10260
10843
|
return c.json(__spreadValues({}, err.toJSON()));
|
|
10261
10844
|
}
|
|
10262
10845
|
}
|
|
@@ -10267,13 +10850,13 @@ var ExecuteTransactionController = class {
|
|
|
10267
10850
|
};
|
|
10268
10851
|
|
|
10269
10852
|
// controllers/ws/create-ticket.controller.ts
|
|
10270
|
-
import { createMiddleware as
|
|
10853
|
+
import { createMiddleware as createMiddleware20 } from "hono/factory";
|
|
10271
10854
|
import { ulid as ulid6 } from "ulid";
|
|
10272
10855
|
var TICKET_TTL_SECONDS = 30 * 60;
|
|
10273
10856
|
var CreateTicketController = class {
|
|
10274
10857
|
constructor(container) {
|
|
10275
10858
|
this.container = container;
|
|
10276
|
-
this.controller =
|
|
10859
|
+
this.controller = createMiddleware20((c) => __async(this, null, function* () {
|
|
10277
10860
|
var _a, _b;
|
|
10278
10861
|
const { entityType, entityId } = c.req.param();
|
|
10279
10862
|
let feedTypes;
|
|
@@ -10339,7 +10922,7 @@ var EntityServiceLifeCycle = class {
|
|
|
10339
10922
|
this.publishEvent = publishEvent2;
|
|
10340
10923
|
this.eventUtils = eventUtils;
|
|
10341
10924
|
}
|
|
10342
|
-
afterCreateEntityHook(entity, entityPayload
|
|
10925
|
+
afterCreateEntityHook(entity, entityPayload) {
|
|
10343
10926
|
return __async(this, null, function* () {
|
|
10344
10927
|
var _a, _b;
|
|
10345
10928
|
const config = this.EntityConfig[entity.entityType];
|
|
@@ -10357,7 +10940,6 @@ var EntityServiceLifeCycle = class {
|
|
|
10357
10940
|
entityType: entity.entityType,
|
|
10358
10941
|
entityId: entity.entityId,
|
|
10359
10942
|
data: entity.data,
|
|
10360
|
-
createdByAccountId: accountId,
|
|
10361
10943
|
publishedAt: entity.updatedAt || (/* @__PURE__ */ new Date()).toISOString()
|
|
10362
10944
|
}
|
|
10363
10945
|
});
|
|
@@ -10379,7 +10961,7 @@ var TransactionService = class {
|
|
|
10379
10961
|
this.entityServiceLifeCycle = entityServiceLifeCycle;
|
|
10380
10962
|
this.eventUtils = eventUtils;
|
|
10381
10963
|
this.mutualService = mutualService;
|
|
10382
|
-
this.executeTransaction = (operations
|
|
10964
|
+
this.executeTransaction = (operations) => __async(this, null, function* () {
|
|
10383
10965
|
var _a;
|
|
10384
10966
|
if (!operations || operations.length === 0) {
|
|
10385
10967
|
throw new StandardError(
|
|
@@ -10391,7 +10973,7 @@ var TransactionService = class {
|
|
|
10391
10973
|
const pendingEvents = [];
|
|
10392
10974
|
const resultEntries = [];
|
|
10393
10975
|
const processed = yield Promise.all(
|
|
10394
|
-
operations.map((op) => this.processOperation(op
|
|
10976
|
+
operations.map((op) => this.processOperation(op))
|
|
10395
10977
|
);
|
|
10396
10978
|
const afterCommits = [];
|
|
10397
10979
|
for (const { items, events, afterCommit, resultEntry } of processed) {
|
|
@@ -10510,14 +11092,14 @@ var TransactionService = class {
|
|
|
10510
11092
|
return { results: resultEntries };
|
|
10511
11093
|
});
|
|
10512
11094
|
}
|
|
10513
|
-
processOperation(op
|
|
11095
|
+
processOperation(op) {
|
|
10514
11096
|
return __async(this, null, function* () {
|
|
10515
11097
|
switch (op.operation) {
|
|
10516
11098
|
case "createEntity": {
|
|
10517
11099
|
const { items, entity } = yield this.buildCreateItems(op);
|
|
10518
11100
|
return {
|
|
10519
11101
|
items,
|
|
10520
|
-
events: this.collectCreateEvents(entity, op.payload
|
|
11102
|
+
events: this.collectCreateEvents(entity, op.payload),
|
|
10521
11103
|
resultEntry: {
|
|
10522
11104
|
operation: "createEntity",
|
|
10523
11105
|
entityType: op.entityType,
|
|
@@ -10532,7 +11114,7 @@ var TransactionService = class {
|
|
|
10532
11114
|
const { item, updatedAt } = yield this.buildUpdateItem(op);
|
|
10533
11115
|
return {
|
|
10534
11116
|
items: [item],
|
|
10535
|
-
events: this.collectUpdateEvents(op, updatedAt
|
|
11117
|
+
events: this.collectUpdateEvents(op, updatedAt),
|
|
10536
11118
|
resultEntry: {
|
|
10537
11119
|
operation: "updateEntity",
|
|
10538
11120
|
entityType: op.entityType,
|
|
@@ -10551,7 +11133,6 @@ var TransactionService = class {
|
|
|
10551
11133
|
payload: {
|
|
10552
11134
|
entityType: op.entityType,
|
|
10553
11135
|
entityId: op.entityId,
|
|
10554
|
-
updatedByAccountId: accountId,
|
|
10555
11136
|
publishedAt: updatedAt
|
|
10556
11137
|
}
|
|
10557
11138
|
}
|
|
@@ -10573,8 +11154,7 @@ var TransactionService = class {
|
|
|
10573
11154
|
event: EVENT.CORE.ENTITY_DELETED,
|
|
10574
11155
|
payload: {
|
|
10575
11156
|
entityType: op.entityType,
|
|
10576
|
-
entityId: op.entityId
|
|
10577
|
-
deletedByAccountId: accountId
|
|
11157
|
+
entityId: op.entityId
|
|
10578
11158
|
}
|
|
10579
11159
|
}
|
|
10580
11160
|
],
|
|
@@ -10586,11 +11166,11 @@ var TransactionService = class {
|
|
|
10586
11166
|
};
|
|
10587
11167
|
}
|
|
10588
11168
|
case "createMutual":
|
|
10589
|
-
return this.processCreateMutual(op
|
|
11169
|
+
return this.processCreateMutual(op);
|
|
10590
11170
|
case "updateMutual":
|
|
10591
|
-
return this.processUpdateMutual(op
|
|
11171
|
+
return this.processUpdateMutual(op);
|
|
10592
11172
|
case "deleteMutual":
|
|
10593
|
-
return this.processDeleteMutual(op
|
|
11173
|
+
return this.processDeleteMutual(op);
|
|
10594
11174
|
default:
|
|
10595
11175
|
throw new StandardError(
|
|
10596
11176
|
StandardErrorCode.TRANSACTION_INVALID_OPERATION,
|
|
@@ -10603,7 +11183,7 @@ var TransactionService = class {
|
|
|
10603
11183
|
// the write is deferred into this transaction. A mutual created here
|
|
10604
11184
|
// publishes the same MUTUAL_CREATED event, and an asEntity mutual's
|
|
10605
11185
|
// projection is written in the same transaction.
|
|
10606
|
-
processCreateMutual(op
|
|
11186
|
+
processCreateMutual(op) {
|
|
10607
11187
|
return __async(this, null, function* () {
|
|
10608
11188
|
var _a, _b;
|
|
10609
11189
|
this.assertMutualOperation(op);
|
|
@@ -10626,15 +11206,13 @@ var TransactionService = class {
|
|
|
10626
11206
|
entityType: op.entityType,
|
|
10627
11207
|
entityId: op.entityId,
|
|
10628
11208
|
parsedMutualPayload,
|
|
10629
|
-
accountId,
|
|
10630
11209
|
publishedAt: (_b = mutual.createdAt) != null ? _b : (/* @__PURE__ */ new Date()).toISOString()
|
|
10631
11210
|
}
|
|
10632
11211
|
}
|
|
10633
11212
|
],
|
|
10634
11213
|
afterCommit: entity ? () => this.entityServiceLifeCycle.afterCreateEntityHook(
|
|
10635
11214
|
entity,
|
|
10636
|
-
mutualPayload
|
|
10637
|
-
accountId
|
|
11215
|
+
mutualPayload
|
|
10638
11216
|
) : void 0,
|
|
10639
11217
|
resultEntry: {
|
|
10640
11218
|
operation: "createMutual",
|
|
@@ -10655,7 +11233,7 @@ var TransactionService = class {
|
|
|
10655
11233
|
// Same validation and records as MutualService.updateMutual, and the same
|
|
10656
11234
|
// MUTUAL_UPDATED event. The stored values are read back after the commit
|
|
10657
11235
|
// (Phase 4), as a standalone PATCH /mutual/... returns them.
|
|
10658
|
-
processUpdateMutual(op
|
|
11236
|
+
processUpdateMutual(op) {
|
|
10659
11237
|
return __async(this, null, function* () {
|
|
10660
11238
|
this.assertMutualOperation(op);
|
|
10661
11239
|
if (!op.payload || typeof op.payload !== "object") {
|
|
@@ -10681,8 +11259,7 @@ var TransactionService = class {
|
|
|
10681
11259
|
byEntityId: op.byEntityId,
|
|
10682
11260
|
entityType: op.entityType,
|
|
10683
11261
|
entityId: op.entityId,
|
|
10684
|
-
parsedMutualPayload
|
|
10685
|
-
updatedByAccountId: accountId
|
|
11262
|
+
parsedMutualPayload
|
|
10686
11263
|
}
|
|
10687
11264
|
}
|
|
10688
11265
|
],
|
|
@@ -10698,7 +11275,7 @@ var TransactionService = class {
|
|
|
10698
11275
|
});
|
|
10699
11276
|
}
|
|
10700
11277
|
// Same soft delete as MutualService.deleteMutual, and the same event.
|
|
10701
|
-
processDeleteMutual(op
|
|
11278
|
+
processDeleteMutual(op) {
|
|
10702
11279
|
return __async(this, null, function* () {
|
|
10703
11280
|
this.assertMutualOperation(op);
|
|
10704
11281
|
const { mutual, TransactItems } = yield this.requireMutualService(
|
|
@@ -10718,8 +11295,7 @@ var TransactionService = class {
|
|
|
10718
11295
|
byEntityType: op.byEntityType,
|
|
10719
11296
|
byEntityId: op.byEntityId,
|
|
10720
11297
|
entityType: op.entityType,
|
|
10721
|
-
entityId: op.entityId
|
|
10722
|
-
deletedByAccountId: accountId
|
|
11298
|
+
entityId: op.entityId
|
|
10723
11299
|
}
|
|
10724
11300
|
}
|
|
10725
11301
|
],
|
|
@@ -10962,7 +11538,7 @@ var TransactionService = class {
|
|
|
10962
11538
|
}
|
|
10963
11539
|
};
|
|
10964
11540
|
}
|
|
10965
|
-
collectCreateEvents(entity, payload
|
|
11541
|
+
collectCreateEvents(entity, payload) {
|
|
10966
11542
|
var _a, _b, _c;
|
|
10967
11543
|
const events = [];
|
|
10968
11544
|
const publishedAt = entity.updatedAt || (/* @__PURE__ */ new Date()).toISOString();
|
|
@@ -10998,13 +11574,12 @@ var TransactionService = class {
|
|
|
10998
11574
|
entityType: entity.entityType,
|
|
10999
11575
|
entityId: entity.entityId,
|
|
11000
11576
|
data: entity.data,
|
|
11001
|
-
createdByAccountId: accountId,
|
|
11002
11577
|
publishedAt
|
|
11003
11578
|
}
|
|
11004
11579
|
});
|
|
11005
11580
|
return events;
|
|
11006
11581
|
}
|
|
11007
|
-
collectUpdateEvents(op, updatedAt
|
|
11582
|
+
collectUpdateEvents(op, updatedAt) {
|
|
11008
11583
|
var _a, _b;
|
|
11009
11584
|
const events = [];
|
|
11010
11585
|
const config = this.EntityConfig[op.entityType];
|
|
@@ -11040,7 +11615,6 @@ var TransactionService = class {
|
|
|
11040
11615
|
payload: {
|
|
11041
11616
|
entityType: op.entityType,
|
|
11042
11617
|
entityId: op.entityId,
|
|
11043
|
-
updatedByAccountId: accountId,
|
|
11044
11618
|
publishedAt: updatedAt
|
|
11045
11619
|
}
|
|
11046
11620
|
});
|
|
@@ -11362,6 +11936,7 @@ export {
|
|
|
11362
11936
|
handler7 as mutualProcessor,
|
|
11363
11937
|
handler8 as prejoinProcessor,
|
|
11364
11938
|
handler9 as replicationProcessor,
|
|
11939
|
+
requires,
|
|
11365
11940
|
setupCommonRoutes,
|
|
11366
11941
|
startBackfill as startAnalyticsBackfill,
|
|
11367
11942
|
handler10 as tagProcessor,
|