monorise 1.15.0 → 2.0.0-dev.2
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 +382 -0
- package/dist/base/index.js.map +1 -1
- package/dist/cli/cli.js +300 -131
- 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 +785 -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 +47 -189
- 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,405 @@ 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;
|
|
184
|
+
const config = entityConfig[entityType];
|
|
185
|
+
const fields = (config == null ? void 0 : config.search) ? config.search.fields.map(({ field }) => field) : (_a = config == null ? void 0 : config.searchableFields) != null ? _a : [];
|
|
186
|
+
return checkFields(
|
|
187
|
+
key,
|
|
188
|
+
key.access.entity(entityType).read,
|
|
189
|
+
fields.map(String),
|
|
190
|
+
`search on '${entityType}', which matches these fields it cannot read`
|
|
191
|
+
);
|
|
192
|
+
};
|
|
193
|
+
const checkUniqueLookup = (key, entityType, field) => checkFields(
|
|
194
|
+
key,
|
|
195
|
+
key.access.entity(entityType).read,
|
|
196
|
+
[field],
|
|
197
|
+
`a lookup on '${entityType}' by a field it cannot read`
|
|
198
|
+
);
|
|
199
|
+
const checkTag = (key, entityType, tagName) => {
|
|
200
|
+
const { tags } = key.access.entity(entityType);
|
|
201
|
+
if (tags === "*" || (tags == null ? void 0 : tags.has(tagName))) return null;
|
|
202
|
+
return {
|
|
203
|
+
status: 403,
|
|
204
|
+
message: `API key policy '${key.policy}' does not allow reading tag '${tagName}' of '${entityType}'`
|
|
205
|
+
};
|
|
206
|
+
};
|
|
207
|
+
const entity = (route) => routeGuard(
|
|
208
|
+
`entity:${route}`,
|
|
209
|
+
createMiddleware((c, next) => __async(null, null, function* () {
|
|
210
|
+
var _a, _b, _c, _d;
|
|
211
|
+
const key = restrictedKey(c);
|
|
212
|
+
if (key) {
|
|
213
|
+
const entityType = (_a = c.req.param("entityType")) != null ? _a : "";
|
|
214
|
+
for (const action of ENTITY_ROUTE_ACTIONS[route]) {
|
|
215
|
+
const denial2 = checkEntity(key, entityType, action);
|
|
216
|
+
if (denial2) return deny(c, denial2);
|
|
217
|
+
}
|
|
218
|
+
let denial = null;
|
|
219
|
+
if (route === "list" && c.req.query("query")) {
|
|
220
|
+
denial = checkSearch(key, entityType);
|
|
221
|
+
} else if (route === "unique") {
|
|
222
|
+
denial = checkUniqueLookup(
|
|
223
|
+
key,
|
|
224
|
+
entityType,
|
|
225
|
+
(_b = c.req.param("uniqueField")) != null ? _b : ""
|
|
226
|
+
);
|
|
227
|
+
} else if (route === "tag") {
|
|
228
|
+
denial = checkTag(key, entityType, (_c = c.req.param("tagName")) != null ? _c : "");
|
|
229
|
+
} else if (route === "create") {
|
|
230
|
+
denial = checkCreate(key, entityType, yield jsonBody(c), false);
|
|
231
|
+
} else if (route === "update") {
|
|
232
|
+
denial = checkUpdate(key, entityType, yield jsonBody(c));
|
|
233
|
+
} else if (route === "upsert") {
|
|
234
|
+
const body = yield jsonBody(c);
|
|
235
|
+
denial = (_d = checkCreate(key, entityType, body, true)) != null ? _d : checkUpdate(key, entityType, body);
|
|
236
|
+
} else if (route === "adjust") {
|
|
237
|
+
denial = checkAdjust(key, entityType, yield jsonBody(c));
|
|
238
|
+
}
|
|
239
|
+
if (denial) return deny(c, denial);
|
|
240
|
+
}
|
|
241
|
+
yield next();
|
|
242
|
+
}))
|
|
243
|
+
);
|
|
244
|
+
const checkMutualData = (key, byEntityType, entityType, action, payload) => {
|
|
245
|
+
var _a, _b;
|
|
246
|
+
return typeof payload === "object" && payload !== null ? checkFields(
|
|
247
|
+
key,
|
|
248
|
+
(_b = (_a = key.access.mutual(byEntityType, entityType)) == null ? void 0 : _a[action]) != null ? _b : null,
|
|
249
|
+
Object.keys(payload),
|
|
250
|
+
`${action} on these mutualData fields of ${byEntityType}\u2192${entityType}`
|
|
251
|
+
) : null;
|
|
252
|
+
};
|
|
253
|
+
const mutual = (action) => routeGuard(
|
|
254
|
+
`mutual:${action}`,
|
|
255
|
+
createMiddleware((c, next) => __async(null, null, function* () {
|
|
256
|
+
var _a, _b;
|
|
257
|
+
const key = restrictedKey(c);
|
|
258
|
+
if (key) {
|
|
259
|
+
const byEntityType = (_a = c.req.param("byEntityType")) != null ? _a : "";
|
|
260
|
+
const entityType = (_b = c.req.param("entityType")) != null ? _b : "";
|
|
261
|
+
const chain = c.req.query("chainEntityQuery");
|
|
262
|
+
const path = action === "read" && chain ? [byEntityType, ...chain.split(","), entityType] : [byEntityType, entityType];
|
|
263
|
+
const requestedAsEntity = action === "create" ? c.req.query("asEntity") : void 0;
|
|
264
|
+
for (let hop = 1; hop < path.length; hop++) {
|
|
265
|
+
const denial = checkDirection(
|
|
266
|
+
key,
|
|
267
|
+
path[hop - 1],
|
|
268
|
+
path[hop],
|
|
269
|
+
action,
|
|
270
|
+
requestedAsEntity
|
|
271
|
+
);
|
|
272
|
+
if (denial) return deny(c, denial);
|
|
273
|
+
}
|
|
274
|
+
if (action === "create" || action === "update") {
|
|
275
|
+
const denial = checkMutualData(
|
|
276
|
+
key,
|
|
277
|
+
byEntityType,
|
|
278
|
+
entityType,
|
|
279
|
+
action,
|
|
280
|
+
yield jsonBody(c)
|
|
281
|
+
);
|
|
282
|
+
if (denial) return deny(c, denial);
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
yield next();
|
|
286
|
+
}))
|
|
287
|
+
);
|
|
288
|
+
const checkOperation = (key, operation) => {
|
|
289
|
+
var _a, _b, _c, _d, _e;
|
|
290
|
+
switch (operation == null ? void 0 : operation.operation) {
|
|
291
|
+
case "createEntity":
|
|
292
|
+
return (_a = checkEntity(key, operation.entityType, "create")) != null ? _a : checkCreate(
|
|
293
|
+
key,
|
|
294
|
+
operation.entityType,
|
|
295
|
+
operation.payload,
|
|
296
|
+
Boolean(operation.entityId)
|
|
297
|
+
);
|
|
298
|
+
case "updateEntity":
|
|
299
|
+
return (_b = checkEntity(key, operation.entityType, "update")) != null ? _b : checkUpdate(key, operation.entityType, operation.payload);
|
|
300
|
+
case "adjustEntity":
|
|
301
|
+
return (_c = checkEntity(key, operation.entityType, "update")) != null ? _c : checkAdjust(key, operation.entityType, operation.adjustments);
|
|
302
|
+
case "deleteEntity":
|
|
303
|
+
return checkEntity(key, operation.entityType, "delete");
|
|
304
|
+
case "createMutual":
|
|
305
|
+
return (_d = checkDirection(
|
|
306
|
+
key,
|
|
307
|
+
operation.byEntityType,
|
|
308
|
+
operation.entityType,
|
|
309
|
+
"create"
|
|
310
|
+
)) != null ? _d : checkMutualData(
|
|
311
|
+
key,
|
|
312
|
+
operation.byEntityType,
|
|
313
|
+
operation.entityType,
|
|
314
|
+
"create",
|
|
315
|
+
operation.payload
|
|
316
|
+
);
|
|
317
|
+
case "updateMutual":
|
|
318
|
+
return (_e = checkDirection(
|
|
319
|
+
key,
|
|
320
|
+
operation.byEntityType,
|
|
321
|
+
operation.entityType,
|
|
322
|
+
"update"
|
|
323
|
+
)) != null ? _e : checkMutualData(
|
|
324
|
+
key,
|
|
325
|
+
operation.byEntityType,
|
|
326
|
+
operation.entityType,
|
|
327
|
+
"update",
|
|
328
|
+
operation.payload
|
|
329
|
+
);
|
|
330
|
+
case "deleteMutual":
|
|
331
|
+
return checkDirection(
|
|
332
|
+
key,
|
|
333
|
+
operation.byEntityType,
|
|
334
|
+
operation.entityType,
|
|
335
|
+
"delete"
|
|
336
|
+
);
|
|
337
|
+
default:
|
|
338
|
+
return null;
|
|
339
|
+
}
|
|
340
|
+
};
|
|
341
|
+
const transaction = () => routeGuard(
|
|
342
|
+
"transaction",
|
|
343
|
+
createMiddleware((c, next) => __async(null, null, function* () {
|
|
344
|
+
var _a;
|
|
345
|
+
const key = restrictedKey(c);
|
|
346
|
+
if (!key) return next();
|
|
347
|
+
const operations = (_a = yield jsonBody(c)) == null ? void 0 : _a.operations;
|
|
348
|
+
if (!Array.isArray(operations)) return next();
|
|
349
|
+
for (const [operationIndex, operation] of operations.entries()) {
|
|
350
|
+
const denial = checkOperation(key, operation);
|
|
351
|
+
if (denial) return deny(c, denial, { operationIndex });
|
|
352
|
+
}
|
|
353
|
+
yield next();
|
|
354
|
+
}))
|
|
355
|
+
);
|
|
356
|
+
return { entity, mutual, transaction };
|
|
357
|
+
};
|
|
358
|
+
var requireFullPolicy = () => routeGuard(
|
|
359
|
+
"full",
|
|
360
|
+
createMiddleware((c, next) => __async(null, null, function* () {
|
|
361
|
+
const key = restrictedKey(c);
|
|
362
|
+
if (key) {
|
|
363
|
+
return forbidden(
|
|
364
|
+
c,
|
|
365
|
+
`API key policy '${key.policy}' cannot call this route; only 'full' can`
|
|
366
|
+
);
|
|
367
|
+
}
|
|
368
|
+
yield next();
|
|
369
|
+
}))
|
|
370
|
+
);
|
|
371
|
+
var requires = (permission) => Object.defineProperty(
|
|
372
|
+
createMiddleware((c, next) => __async(null, null, function* () {
|
|
373
|
+
const key = restrictedKey(c);
|
|
374
|
+
if (key && !key.has(permission)) {
|
|
375
|
+
return forbidden(
|
|
376
|
+
c,
|
|
377
|
+
`API key policy '${key.policy}' does not grant '${permission}'`
|
|
378
|
+
);
|
|
379
|
+
}
|
|
380
|
+
yield next();
|
|
381
|
+
})),
|
|
382
|
+
ROUTE_PERMISSION,
|
|
383
|
+
{ value: permission }
|
|
384
|
+
);
|
|
385
|
+
var customRouteGate = () => createMiddleware((c, next) => __async(null, null, function* () {
|
|
386
|
+
const key = restrictedKey(c);
|
|
387
|
+
if (key) {
|
|
388
|
+
const permissions = c.req.matchedRoutes.flatMap((route) => {
|
|
389
|
+
const permission = route.handler[ROUTE_PERMISSION];
|
|
390
|
+
return typeof permission === "string" ? [permission] : [];
|
|
391
|
+
});
|
|
392
|
+
if (!permissions.length) {
|
|
393
|
+
return forbidden(
|
|
394
|
+
c,
|
|
395
|
+
"This route declares no permission with requires(), so only 'full' keys can call it"
|
|
396
|
+
);
|
|
397
|
+
}
|
|
398
|
+
const missing = permissions.find((permission) => !key.has(permission));
|
|
399
|
+
if (missing !== void 0) {
|
|
400
|
+
return forbidden(
|
|
401
|
+
c,
|
|
402
|
+
`API key policy '${key.policy}' does not grant '${missing}'`
|
|
403
|
+
);
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
yield next();
|
|
407
|
+
}));
|
|
408
|
+
|
|
409
|
+
// middlewares/entity-type-check.ts
|
|
410
|
+
import { createMiddleware as createMiddleware2 } from "hono/factory";
|
|
411
|
+
import httpStatus2 from "http-status";
|
|
412
|
+
var entityTypeCheck = (container) => createMiddleware2((c, next) => __async(null, null, function* () {
|
|
21
413
|
const { entityType } = c.req.param();
|
|
22
414
|
if (!container.config.AllowedEntityTypes.includes(entityType)) {
|
|
23
|
-
c.status(
|
|
415
|
+
c.status(httpStatus2.NOT_FOUND);
|
|
24
416
|
return c.json({
|
|
25
417
|
code: "NOT_FOUND"
|
|
26
418
|
});
|
|
@@ -28,13 +420,65 @@ var entityTypeCheck = (container) => createMiddleware((c, next) => __async(null,
|
|
|
28
420
|
yield next();
|
|
29
421
|
}));
|
|
30
422
|
|
|
423
|
+
// middlewares/mask.ts
|
|
424
|
+
import { createMiddleware as createMiddleware3 } from "hono/factory";
|
|
425
|
+
var isPlainObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
426
|
+
var maskFields = (data, granted) => granted === "*" ? data : Object.fromEntries(
|
|
427
|
+
Object.entries(data).filter(([field]) => granted == null ? void 0 : granted.has(field))
|
|
428
|
+
);
|
|
429
|
+
var maskRecord = (record, access) => {
|
|
430
|
+
var _a, _b;
|
|
431
|
+
const entityType = record.entityType;
|
|
432
|
+
const masked = __spreadValues({}, record);
|
|
433
|
+
if (isPlainObject(record.data)) {
|
|
434
|
+
masked.data = maskFields(record.data, access.entity(entityType).read);
|
|
435
|
+
}
|
|
436
|
+
if (typeof record.byEntityType === "string" && isPlainObject(record.mutualData)) {
|
|
437
|
+
masked.mutualData = maskFields(
|
|
438
|
+
record.mutualData,
|
|
439
|
+
(_b = (_a = access.mutual(record.byEntityType, entityType)) == null ? void 0 : _a.read) != null ? _b : null
|
|
440
|
+
);
|
|
441
|
+
}
|
|
442
|
+
return masked;
|
|
443
|
+
};
|
|
444
|
+
var maskResponseBody = (body, access) => {
|
|
445
|
+
if (Array.isArray(body))
|
|
446
|
+
return body.map((item) => maskResponseBody(item, access));
|
|
447
|
+
if (!isPlainObject(body)) return body;
|
|
448
|
+
if (typeof body.entityType === "string" && ("data" in body || "mutualData" in body)) {
|
|
449
|
+
return maskRecord(body, access);
|
|
450
|
+
}
|
|
451
|
+
return Object.fromEntries(
|
|
452
|
+
Object.entries(body).map(([key, value]) => [
|
|
453
|
+
key,
|
|
454
|
+
maskResponseBody(value, access)
|
|
455
|
+
])
|
|
456
|
+
);
|
|
457
|
+
};
|
|
458
|
+
var maskResponses = () => createMiddleware3((c, next) => __async(null, null, function* () {
|
|
459
|
+
var _a;
|
|
460
|
+
yield next();
|
|
461
|
+
const key = c.get("apiKey");
|
|
462
|
+
if (!key || key.access.full || !c.res.ok) return;
|
|
463
|
+
if (!((_a = c.res.headers.get("content-type")) == null ? void 0 : _a.includes("application/json"))) {
|
|
464
|
+
return;
|
|
465
|
+
}
|
|
466
|
+
const body = yield c.res.json();
|
|
467
|
+
const headers = new Headers(c.res.headers);
|
|
468
|
+
headers.delete("content-length");
|
|
469
|
+
c.res = new Response(JSON.stringify(maskResponseBody(body, key.access)), {
|
|
470
|
+
status: c.res.status,
|
|
471
|
+
headers
|
|
472
|
+
});
|
|
473
|
+
}));
|
|
474
|
+
|
|
31
475
|
// middlewares/mutual-type-check.ts
|
|
32
|
-
import { createMiddleware as
|
|
33
|
-
import
|
|
34
|
-
var mutualTypeCheck = (container) =>
|
|
476
|
+
import { createMiddleware as createMiddleware4 } from "hono/factory";
|
|
477
|
+
import httpStatus3 from "http-status";
|
|
478
|
+
var mutualTypeCheck = (container) => createMiddleware4((c, next) => __async(null, null, function* () {
|
|
35
479
|
const { entityType, byEntityType } = c.req.param();
|
|
36
480
|
if (!container.config.AllowedEntityTypes.includes(entityType) || !container.config.AllowedEntityTypes.includes(byEntityType)) {
|
|
37
|
-
c.status(
|
|
481
|
+
c.status(httpStatus3.NOT_FOUND);
|
|
38
482
|
return c.json({
|
|
39
483
|
code: "NOT_FOUND"
|
|
40
484
|
});
|
|
@@ -45,61 +489,91 @@ var mutualTypeCheck = (container) => createMiddleware2((c, next) => __async(null
|
|
|
45
489
|
// controllers/setupRoutes.ts
|
|
46
490
|
var setupCommonRoutes = (container) => {
|
|
47
491
|
const app = new Hono();
|
|
492
|
+
const guard = createRouteGuards(container.config.EntityConfig);
|
|
493
|
+
app.use("*", maskResponses());
|
|
48
494
|
app.use(
|
|
49
495
|
"/mutual/:byEntityType/:byEntityId/:entityType",
|
|
50
496
|
mutualTypeCheck(container)
|
|
51
497
|
);
|
|
52
498
|
app.get(
|
|
53
499
|
"/mutual/:byEntityType/:byEntityId/:entityType",
|
|
500
|
+
guard.mutual("read"),
|
|
54
501
|
container.listEntitiesByEntityController.controller
|
|
55
502
|
);
|
|
56
503
|
app.post(
|
|
57
504
|
"/mutual/:byEntityType/:byEntityId/:entityType/:entityId",
|
|
505
|
+
guard.mutual("create"),
|
|
58
506
|
container.createMutualController.controller
|
|
59
507
|
);
|
|
60
508
|
app.get(
|
|
61
509
|
"/mutual/:byEntityType/:byEntityId/:entityType/:entityId",
|
|
510
|
+
guard.mutual("read"),
|
|
62
511
|
container.getMutualController.controller
|
|
63
512
|
);
|
|
64
513
|
app.patch(
|
|
65
514
|
"/mutual/:byEntityType/:byEntityId/:entityType/:entityId",
|
|
515
|
+
guard.mutual("update"),
|
|
66
516
|
container.updateMutualController.controller
|
|
67
517
|
);
|
|
68
518
|
app.delete(
|
|
69
519
|
"/mutual/:byEntityType/:byEntityId/:entityType/:entityId",
|
|
520
|
+
guard.mutual("delete"),
|
|
70
521
|
container.deleteMutualController.controller
|
|
71
522
|
);
|
|
72
523
|
app.use("/entity/:entityType", entityTypeCheck(container));
|
|
73
|
-
app.get(
|
|
74
|
-
|
|
524
|
+
app.get(
|
|
525
|
+
"/entity/:entityType",
|
|
526
|
+
guard.entity("list"),
|
|
527
|
+
container.listEntitiesController.controller
|
|
528
|
+
);
|
|
529
|
+
app.post(
|
|
530
|
+
"/entity/:entityType",
|
|
531
|
+
guard.entity("create"),
|
|
532
|
+
container.createEntityController.controller
|
|
533
|
+
);
|
|
75
534
|
app.get(
|
|
76
535
|
"/entity/:entityType/unique/:uniqueField/:uniqueFieldValue",
|
|
536
|
+
guard.entity("unique"),
|
|
77
537
|
container.getEntityByUniqueFieldController.controller
|
|
78
538
|
);
|
|
79
539
|
app.post(
|
|
80
540
|
"/entity/:entityType/:entityId/adjust",
|
|
541
|
+
guard.entity("adjust"),
|
|
81
542
|
container.adjustEntityController.controller
|
|
82
543
|
);
|
|
83
544
|
app.get(
|
|
84
545
|
"/entity/:entityType/:entityId",
|
|
546
|
+
guard.entity("read"),
|
|
85
547
|
container.getEntityController.controller
|
|
86
548
|
);
|
|
87
549
|
app.put(
|
|
88
550
|
"/entity/:entityType/:entityId",
|
|
551
|
+
guard.entity("upsert"),
|
|
89
552
|
container.upsertEntityController.controller
|
|
90
553
|
);
|
|
91
554
|
app.patch(
|
|
92
555
|
"/entity/:entityType/:entityId",
|
|
556
|
+
guard.entity("update"),
|
|
93
557
|
container.updateEntityController.controller
|
|
94
558
|
);
|
|
95
559
|
app.delete(
|
|
96
560
|
"/entity/:entityType/:entityId",
|
|
561
|
+
guard.entity("delete"),
|
|
97
562
|
container.deleteEntityController.controller
|
|
98
563
|
);
|
|
99
|
-
app.get(
|
|
100
|
-
|
|
564
|
+
app.get(
|
|
565
|
+
"/tag/:entityType/:tagName",
|
|
566
|
+
guard.entity("tag"),
|
|
567
|
+
container.listTagsController.controller
|
|
568
|
+
);
|
|
569
|
+
app.post(
|
|
570
|
+
"/transaction",
|
|
571
|
+
guard.transaction(),
|
|
572
|
+
container.executeTransactionController.controller
|
|
573
|
+
);
|
|
101
574
|
app.post(
|
|
102
575
|
"/ws/ticket/:entityType/:entityId",
|
|
576
|
+
requireFullPolicy(),
|
|
103
577
|
container.createTicketController.controller
|
|
104
578
|
);
|
|
105
579
|
return app;
|
|
@@ -523,7 +997,10 @@ var EntityRepository = class extends Repository {
|
|
|
523
997
|
var _a;
|
|
524
998
|
const resp = yield this.dynamodbClient.query({
|
|
525
999
|
TableName: this.TABLE_NAME,
|
|
526
|
-
|
|
1000
|
+
// Exact match: a unique item's SK is the bare entity type, so a prefix
|
|
1001
|
+
// match would also return another type whose name starts with this one
|
|
1002
|
+
// (e.g. 'user' matching 'user-profile').
|
|
1003
|
+
KeyConditionExpression: "#PK = :PK and #SK = :SK",
|
|
527
1004
|
ExpressionAttributeNames: {
|
|
528
1005
|
"#PK": "PK",
|
|
529
1006
|
"#SK": "SK"
|
|
@@ -541,7 +1018,8 @@ var EntityRepository = class extends Repository {
|
|
|
541
1018
|
var _a;
|
|
542
1019
|
const resp = yield this.dynamodbClient.query({
|
|
543
1020
|
TableName: this.TABLE_NAME,
|
|
544
|
-
|
|
1021
|
+
// Exact match, as in getEntityByUniqueField.
|
|
1022
|
+
KeyConditionExpression: "#PK = :PK and #SK = :SK",
|
|
545
1023
|
ExpressionAttributeNames: {
|
|
546
1024
|
"#PK": "PK",
|
|
547
1025
|
"#SK": "SK"
|
|
@@ -2593,25 +3071,164 @@ import { cors } from "hono/cors";
|
|
|
2593
3071
|
import { secureHeaders } from "hono/secure-headers";
|
|
2594
3072
|
|
|
2595
3073
|
// middlewares/api-key-auth.ts
|
|
3074
|
+
import { createHash } from "crypto";
|
|
3075
|
+
import {
|
|
3076
|
+
DEFAULT_API_KEY_POLICY,
|
|
3077
|
+
FULL_API_KEY_POLICY,
|
|
3078
|
+
compileApiKeyPolicy,
|
|
3079
|
+
validateApiKeyPolicies
|
|
3080
|
+
} from "../base/index.js";
|
|
2596
3081
|
import { createFactory } from "hono/factory";
|
|
2597
|
-
import
|
|
3082
|
+
import httpStatus4 from "http-status";
|
|
3083
|
+
|
|
3084
|
+
// helpers/request-context.ts
|
|
3085
|
+
import { AsyncLocalStorage } from "async_hooks";
|
|
3086
|
+
var storage = new AsyncLocalStorage();
|
|
3087
|
+
var runWithApiKey = (apiKey, fn) => storage.run(apiKey, fn);
|
|
3088
|
+
var currentApiKey = () => storage.getStore();
|
|
3089
|
+
|
|
3090
|
+
// middlewares/api-key-auth.ts
|
|
3091
|
+
var SHA256_PREFIX = "sha256:";
|
|
3092
|
+
var createPrincipal = (policy, access) => ({
|
|
3093
|
+
policy,
|
|
3094
|
+
access,
|
|
3095
|
+
can: (action, entityType, fields) => {
|
|
3096
|
+
const entity = access.entity(entityType);
|
|
3097
|
+
if (action === "delete") return entity.delete;
|
|
3098
|
+
if (action === "list" && !entity.list) return false;
|
|
3099
|
+
const granted = entity[action === "list" ? "read" : action];
|
|
3100
|
+
if (granted === null) return false;
|
|
3101
|
+
return !fields || granted === "*" || fields.every((f) => granted.has(f));
|
|
3102
|
+
},
|
|
3103
|
+
has: (permission) => access.allowsRoute(permission),
|
|
3104
|
+
mask: (entityType, entity) => {
|
|
3105
|
+
const record = typeof entity.toJSON === "function" ? entity.toJSON() : entity;
|
|
3106
|
+
return maskRecord(__spreadProps(__spreadValues({}, record), { entityType }), access);
|
|
3107
|
+
}
|
|
3108
|
+
});
|
|
3109
|
+
var fingerprintApiKey = (key) => createHash("sha256").update(key).digest("hex");
|
|
3110
|
+
var SHA256_DIGEST = /^[0-9a-f]{64}$/i;
|
|
3111
|
+
var toFingerprint = (entry, where) => {
|
|
3112
|
+
if (!entry.startsWith(SHA256_PREFIX)) return fingerprintApiKey(entry);
|
|
3113
|
+
const digest = entry.slice(SHA256_PREFIX.length);
|
|
3114
|
+
if (!SHA256_DIGEST.test(digest)) {
|
|
3115
|
+
console.error(
|
|
3116
|
+
`[monorise] API_KEYS: a '${SHA256_PREFIX}' entry in ${where} isn't a 64-character hex SHA-256 digest and will be rejected`
|
|
3117
|
+
);
|
|
3118
|
+
return void 0;
|
|
3119
|
+
}
|
|
3120
|
+
return digest.toLowerCase();
|
|
3121
|
+
};
|
|
3122
|
+
var assertKeyList = (value, where) => {
|
|
3123
|
+
if (!Array.isArray(value) || !value.every((key) => typeof key === "string" && key.length > 0)) {
|
|
3124
|
+
throw new Error(
|
|
3125
|
+
`[monorise] API_KEYS: ${where} must be an array of non-empty strings`
|
|
3126
|
+
);
|
|
3127
|
+
}
|
|
3128
|
+
return value;
|
|
3129
|
+
};
|
|
3130
|
+
var BUILT_IN_POLICIES = [
|
|
3131
|
+
FULL_API_KEY_POLICY,
|
|
3132
|
+
DEFAULT_API_KEY_POLICY
|
|
3133
|
+
];
|
|
3134
|
+
var parseApiKeys = (raw, definedPolicies = BUILT_IN_POLICIES) => {
|
|
3135
|
+
var _a;
|
|
3136
|
+
const fingerprints = /* @__PURE__ */ new Map();
|
|
3137
|
+
if (!raw) return fingerprints;
|
|
3138
|
+
const parsed = JSON.parse(raw);
|
|
3139
|
+
if (Array.isArray(parsed)) {
|
|
3140
|
+
for (const key of assertKeyList(parsed, "the array form")) {
|
|
3141
|
+
const fingerprint = toFingerprint(key, "the array form");
|
|
3142
|
+
if (fingerprint) fingerprints.set(fingerprint, FULL_API_KEY_POLICY);
|
|
3143
|
+
}
|
|
3144
|
+
return fingerprints;
|
|
3145
|
+
}
|
|
3146
|
+
if (typeof parsed !== "object" || parsed === null) {
|
|
3147
|
+
throw new Error(
|
|
3148
|
+
"[monorise] API_KEYS must be a JSON array of keys or an object mapping policy names to keys"
|
|
3149
|
+
);
|
|
3150
|
+
}
|
|
3151
|
+
const policiesByFingerprint = /* @__PURE__ */ new Map();
|
|
3152
|
+
for (const [policy, keys] of Object.entries(parsed)) {
|
|
3153
|
+
const keyList = assertKeyList(keys, `policy '${policy}'`);
|
|
3154
|
+
if (!definedPolicies.includes(policy)) {
|
|
3155
|
+
console.error(
|
|
3156
|
+
`[monorise] API_KEYS: policy '${policy}' is not defined; its ${keyList.length} key(s) will be rejected`
|
|
3157
|
+
);
|
|
3158
|
+
}
|
|
3159
|
+
for (const key of keyList) {
|
|
3160
|
+
const fingerprint = toFingerprint(key, `policy '${policy}'`);
|
|
3161
|
+
if (!fingerprint) continue;
|
|
3162
|
+
const policies = (_a = policiesByFingerprint.get(fingerprint)) != null ? _a : /* @__PURE__ */ new Set();
|
|
3163
|
+
policies.add(policy);
|
|
3164
|
+
policiesByFingerprint.set(fingerprint, policies);
|
|
3165
|
+
}
|
|
3166
|
+
}
|
|
3167
|
+
for (const [fingerprint, policies] of policiesByFingerprint) {
|
|
3168
|
+
if (policies.size > 1) {
|
|
3169
|
+
console.error(
|
|
3170
|
+
`[monorise] API_KEYS: key ${fingerprint.slice(0, 12)}\u2026 is listed under more than one policy (${[...policies].join(", ")}) and will be rejected`
|
|
3171
|
+
);
|
|
3172
|
+
continue;
|
|
3173
|
+
}
|
|
3174
|
+
const [policy] = policies;
|
|
3175
|
+
if (definedPolicies.includes(policy)) fingerprints.set(fingerprint, policy);
|
|
3176
|
+
}
|
|
3177
|
+
return fingerprints;
|
|
3178
|
+
};
|
|
2598
3179
|
var factory = createFactory();
|
|
2599
|
-
var
|
|
2600
|
-
|
|
2601
|
-
const
|
|
2602
|
-
|
|
2603
|
-
|
|
2604
|
-
|
|
2605
|
-
|
|
2606
|
-
|
|
2607
|
-
|
|
2608
|
-
|
|
2609
|
-
|
|
2610
|
-
|
|
3180
|
+
var createApiKeyAuth = (fingerprints, policies = {}) => {
|
|
3181
|
+
const principals = /* @__PURE__ */ new Map();
|
|
3182
|
+
const principalFor = (name) => {
|
|
3183
|
+
let principal = principals.get(name);
|
|
3184
|
+
if (!principal) {
|
|
3185
|
+
principal = createPrincipal(
|
|
3186
|
+
name,
|
|
3187
|
+
compileApiKeyPolicy(name, policies[name])
|
|
3188
|
+
);
|
|
3189
|
+
principals.set(name, principal);
|
|
3190
|
+
}
|
|
3191
|
+
return principal;
|
|
3192
|
+
};
|
|
3193
|
+
return factory.createMiddleware((c, next) => __async(null, null, function* () {
|
|
3194
|
+
const xApiKey = c.req.header("x-api-key");
|
|
3195
|
+
const fingerprint = xApiKey ? fingerprintApiKey(xApiKey) : void 0;
|
|
3196
|
+
const policy = fingerprint ? fingerprints.get(fingerprint) : void 0;
|
|
3197
|
+
if (!fingerprint || !policy) {
|
|
3198
|
+
c.status(httpStatus4.UNAUTHORIZED);
|
|
3199
|
+
return c.json({
|
|
3200
|
+
status: httpStatus4.UNAUTHORIZED,
|
|
3201
|
+
message: httpStatus4["401_MESSAGE"]
|
|
3202
|
+
});
|
|
3203
|
+
}
|
|
3204
|
+
c.set("apiKey", __spreadProps(__spreadValues({}, principalFor(policy)), { fingerprint }));
|
|
3205
|
+
return yield runWithApiKey({ policy, fingerprint }, () => next());
|
|
3206
|
+
}));
|
|
3207
|
+
};
|
|
3208
|
+
var apiKeyAuth = ({
|
|
3209
|
+
policies = {},
|
|
3210
|
+
entityConfig,
|
|
3211
|
+
apiKeys: apiKeys2 = process.env.API_KEYS
|
|
3212
|
+
}) => {
|
|
3213
|
+
const errors = validateApiKeyPolicies(policies, entityConfig);
|
|
3214
|
+
if (errors.length) {
|
|
3215
|
+
console.error(
|
|
3216
|
+
`[monorise] Invalid API key policies; every key under them will be rejected:
|
|
3217
|
+
- ${errors.join("\n - ")}`
|
|
3218
|
+
);
|
|
2611
3219
|
}
|
|
2612
|
-
|
|
2613
|
-
|
|
2614
|
-
|
|
3220
|
+
const projectDefinesDefault = Object.prototype.hasOwnProperty.call(
|
|
3221
|
+
policies,
|
|
3222
|
+
DEFAULT_API_KEY_POLICY
|
|
3223
|
+
);
|
|
3224
|
+
return createApiKeyAuth(
|
|
3225
|
+
parseApiKeys(
|
|
3226
|
+
apiKeys2,
|
|
3227
|
+
errors.length ? projectDefinesDefault ? [FULL_API_KEY_POLICY] : BUILT_IN_POLICIES : [...BUILT_IN_POLICIES, ...Object.keys(policies)]
|
|
3228
|
+
),
|
|
3229
|
+
policies
|
|
3230
|
+
);
|
|
3231
|
+
};
|
|
2615
3232
|
|
|
2616
3233
|
// middlewares/general-error-handler.ts
|
|
2617
3234
|
import { createFactory as createFactory2 } from "hono/factory";
|
|
@@ -2716,10 +3333,11 @@ function publishEvent(_0) {
|
|
|
2716
3333
|
payload,
|
|
2717
3334
|
event
|
|
2718
3335
|
}) {
|
|
3336
|
+
const apiKey = currentApiKey();
|
|
2719
3337
|
const params = {
|
|
2720
3338
|
Entries: [
|
|
2721
3339
|
__spreadProps(__spreadValues({}, event), {
|
|
2722
|
-
Detail: JSON.stringify(payload),
|
|
3340
|
+
Detail: JSON.stringify(apiKey ? __spreadProps(__spreadValues({}, payload), { apiKey }) : payload),
|
|
2723
3341
|
EventBusName: CORE_EVENT_BUS
|
|
2724
3342
|
})
|
|
2725
3343
|
]
|
|
@@ -2768,7 +3386,7 @@ var getDependencies = () => {
|
|
|
2768
3386
|
// middlewares/general-error-handler.ts
|
|
2769
3387
|
var factory2 = createFactory2();
|
|
2770
3388
|
var generalErrorHandler = (dependencies = getDependencies()) => factory2.createMiddleware((c) => __async(null, null, function* () {
|
|
2771
|
-
var _a, _b, _c, _d;
|
|
3389
|
+
var _a, _b, _c, _d, _e;
|
|
2772
3390
|
if (c.error) {
|
|
2773
3391
|
const { nanoid: nanoid2, publishErrorEvent: publishErrorEvent2 } = dependencies;
|
|
2774
3392
|
const errorId = nanoid2();
|
|
@@ -2786,14 +3404,15 @@ var generalErrorHandler = (dependencies = getDependencies()) => factory2.createM
|
|
|
2786
3404
|
errorId,
|
|
2787
3405
|
method: c.req.method,
|
|
2788
3406
|
path: c.req.path,
|
|
3407
|
+
apiKeyPolicy: (_a = c.get("apiKey")) == null ? void 0 : _a.policy,
|
|
2789
3408
|
errorName: error == null ? void 0 : error.name,
|
|
2790
3409
|
errorMessage: error == null ? void 0 : error.message,
|
|
2791
3410
|
errorCode: error == null ? void 0 : error.code,
|
|
2792
3411
|
errorStack: error == null ? void 0 : error.stack,
|
|
2793
|
-
errorConstructor: (
|
|
3412
|
+
errorConstructor: (_b = error == null ? void 0 : error.constructor) == null ? void 0 : _b.name,
|
|
2794
3413
|
hasLastError: !!(error == null ? void 0 : error.lastError),
|
|
2795
|
-
lastErrorName: (
|
|
2796
|
-
lastErrorMessage: (
|
|
3414
|
+
lastErrorName: (_d = (_c = error == null ? void 0 : error.lastError) == null ? void 0 : _c.constructor) == null ? void 0 : _d.name,
|
|
3415
|
+
lastErrorMessage: (_e = error == null ? void 0 : error.lastError) == null ? void 0 : _e.message,
|
|
2797
3416
|
context: error == null ? void 0 : error.context
|
|
2798
3417
|
});
|
|
2799
3418
|
c.status(500);
|
|
@@ -2819,8 +3438,14 @@ var appHandler = (container) => ({ routes }) => {
|
|
|
2819
3438
|
origin: process.env.ALLOWED_ORIGIN ? JSON.parse(process.env.ALLOWED_ORIGIN) : []
|
|
2820
3439
|
})
|
|
2821
3440
|
);
|
|
2822
|
-
app.use(
|
|
3441
|
+
app.use(
|
|
3442
|
+
apiKeyAuth({
|
|
3443
|
+
policies: container.config.ApiKeyPolicies,
|
|
3444
|
+
entityConfig: container.config.EntityConfig
|
|
3445
|
+
})
|
|
3446
|
+
);
|
|
2823
3447
|
if (routes) {
|
|
3448
|
+
app.use("/app/*", customRouteGate());
|
|
2824
3449
|
if (typeof routes !== "function") {
|
|
2825
3450
|
app.route("/app", routes);
|
|
2826
3451
|
} else {
|
|
@@ -2841,10 +3466,10 @@ import {
|
|
|
2841
3466
|
StopQueryExecutionCommand
|
|
2842
3467
|
} from "@aws-sdk/client-athena";
|
|
2843
3468
|
import { DynamoDBClient, GetItemCommand, PutItemCommand } from "@aws-sdk/client-dynamodb";
|
|
2844
|
-
import { createHash } from "crypto";
|
|
3469
|
+
import { createHash as createHash2 } from "crypto";
|
|
2845
3470
|
import { handle as handle2 } from "hono/aws-lambda";
|
|
2846
3471
|
import { Hono as Hono3 } from "hono";
|
|
2847
|
-
import
|
|
3472
|
+
import httpStatus5 from "http-status";
|
|
2848
3473
|
var athena = new AthenaClient();
|
|
2849
3474
|
var dynamo = new DynamoDBClient();
|
|
2850
3475
|
function required(name) {
|
|
@@ -2873,7 +3498,7 @@ function apiKeys() {
|
|
|
2873
3498
|
return process.env.ANALYTICS_API_KEYS ? JSON.parse(process.env.ANALYTICS_API_KEYS) : [];
|
|
2874
3499
|
}
|
|
2875
3500
|
function keyFingerprint(key) {
|
|
2876
|
-
return
|
|
3501
|
+
return createHash2("sha256").update(key).digest("hex");
|
|
2877
3502
|
}
|
|
2878
3503
|
function ownedExecution(id, key) {
|
|
2879
3504
|
return __async(this, null, function* () {
|
|
@@ -2891,7 +3516,7 @@ var analyticsQueryHandler = () => {
|
|
|
2891
3516
|
app.use("*", (c, next) => __async(null, null, function* () {
|
|
2892
3517
|
const key = c.req.header("x-api-key");
|
|
2893
3518
|
if (!key || !apiKeys().includes(key)) {
|
|
2894
|
-
return c.json({ status:
|
|
3519
|
+
return c.json({ status: httpStatus5.UNAUTHORIZED, message: httpStatus5["401_MESSAGE"] }, httpStatus5.UNAUTHORIZED);
|
|
2895
3520
|
}
|
|
2896
3521
|
return next();
|
|
2897
3522
|
}));
|
|
@@ -2904,11 +3529,11 @@ var analyticsQueryHandler = () => {
|
|
|
2904
3529
|
app.post("/queries/:name/executions", (c) => __async(null, null, function* () {
|
|
2905
3530
|
var _a, _b;
|
|
2906
3531
|
const query = queries()[c.req.param("name")];
|
|
2907
|
-
if (!query) return c.json({ message: "Unknown analytics query." },
|
|
3532
|
+
if (!query) return c.json({ message: "Unknown analytics query." }, httpStatus5.NOT_FOUND);
|
|
2908
3533
|
const body = yield c.req.json().catch(() => ({}));
|
|
2909
3534
|
const declared = (_a = query.parameters) != null ? _a : {};
|
|
2910
3535
|
if (Object.keys(body).some((name) => !(name in declared))) {
|
|
2911
|
-
return c.json({ message: "Unexpected query parameter." },
|
|
3536
|
+
return c.json({ message: "Unexpected query parameter." }, httpStatus5.BAD_REQUEST);
|
|
2912
3537
|
}
|
|
2913
3538
|
try {
|
|
2914
3539
|
const parameters = Object.entries(declared).map(([name, definition]) => {
|
|
@@ -2934,10 +3559,10 @@ var analyticsQueryHandler = () => {
|
|
|
2934
3559
|
expiresAt: { N: String(Math.floor(Date.now() / 1e3) + 86400) }
|
|
2935
3560
|
}
|
|
2936
3561
|
}));
|
|
2937
|
-
return c.json({ queryExecutionId: started.QueryExecutionId, state: "QUEUED" },
|
|
3562
|
+
return c.json({ queryExecutionId: started.QueryExecutionId, state: "QUEUED" }, httpStatus5.ACCEPTED);
|
|
2938
3563
|
} catch (error) {
|
|
2939
3564
|
if (error instanceof Error && error.message.startsWith("Invalid or missing parameter:")) {
|
|
2940
|
-
return c.json({ message: error.message },
|
|
3565
|
+
return c.json({ message: error.message }, httpStatus5.BAD_REQUEST);
|
|
2941
3566
|
}
|
|
2942
3567
|
throw error;
|
|
2943
3568
|
}
|
|
@@ -2945,7 +3570,7 @@ var analyticsQueryHandler = () => {
|
|
|
2945
3570
|
app.get("/executions/:id", (c) => __async(null, null, function* () {
|
|
2946
3571
|
var _a, _b, _c, _d, _e, _f;
|
|
2947
3572
|
const id = c.req.param("id");
|
|
2948
|
-
if (!(yield ownedExecution(id, (_a = c.req.header("x-api-key")) != null ? _a : ""))) return c.json({ message: "Unknown analytics execution." },
|
|
3573
|
+
if (!(yield ownedExecution(id, (_a = c.req.header("x-api-key")) != null ? _a : ""))) return c.json({ message: "Unknown analytics execution." }, httpStatus5.NOT_FOUND);
|
|
2949
3574
|
const execution = yield athena.send(new GetQueryExecutionCommand({ QueryExecutionId: id }));
|
|
2950
3575
|
const status = (_b = execution.QueryExecution) == null ? void 0 : _b.Status;
|
|
2951
3576
|
return c.json({
|
|
@@ -2959,7 +3584,7 @@ var analyticsQueryHandler = () => {
|
|
|
2959
3584
|
app.get("/executions/:id/results", (c) => __async(null, null, function* () {
|
|
2960
3585
|
var _a, _b, _c, _d, _e, _f, _g;
|
|
2961
3586
|
const id = c.req.param("id");
|
|
2962
|
-
if (!(yield ownedExecution(id, (_a = c.req.header("x-api-key")) != null ? _a : ""))) return c.json({ message: "Unknown analytics execution." },
|
|
3587
|
+
if (!(yield ownedExecution(id, (_a = c.req.header("x-api-key")) != null ? _a : ""))) return c.json({ message: "Unknown analytics execution." }, httpStatus5.NOT_FOUND);
|
|
2963
3588
|
const requested = Number((_b = c.req.query("maxResults")) != null ? _b : 100);
|
|
2964
3589
|
const maxResults = Number.isFinite(requested) ? Math.min(Math.max(requested, 1), 1e3) : 100;
|
|
2965
3590
|
const nextToken = c.req.query("nextToken");
|
|
@@ -2985,9 +3610,9 @@ var analyticsQueryHandler = () => {
|
|
|
2985
3610
|
app.post("/executions/:id/cancel", (c) => __async(null, null, function* () {
|
|
2986
3611
|
var _a;
|
|
2987
3612
|
const id = c.req.param("id");
|
|
2988
|
-
if (!(yield ownedExecution(id, (_a = c.req.header("x-api-key")) != null ? _a : ""))) return c.json({ message: "Unknown analytics execution." },
|
|
3613
|
+
if (!(yield ownedExecution(id, (_a = c.req.header("x-api-key")) != null ? _a : ""))) return c.json({ message: "Unknown analytics execution." }, httpStatus5.NOT_FOUND);
|
|
2989
3614
|
yield athena.send(new StopQueryExecutionCommand({ QueryExecutionId: id }));
|
|
2990
|
-
return c.body(null,
|
|
3615
|
+
return c.body(null, httpStatus5.NO_CONTENT);
|
|
2991
3616
|
}));
|
|
2992
3617
|
return handle2(app);
|
|
2993
3618
|
};
|
|
@@ -3000,7 +3625,7 @@ var handler = (container) => (ev) => __async(null, null, function* () {
|
|
|
3000
3625
|
const errorContext = {};
|
|
3001
3626
|
const body = parseSQSBusEvent(record.body);
|
|
3002
3627
|
const { detail } = body;
|
|
3003
|
-
const { entityType, entityId, entityPayload,
|
|
3628
|
+
const { entityType, entityId, entityPayload, options } = detail;
|
|
3004
3629
|
errorContext.body = body;
|
|
3005
3630
|
try {
|
|
3006
3631
|
if (!entityType) {
|
|
@@ -3010,7 +3635,6 @@ var handler = (container) => (ev) => __async(null, null, function* () {
|
|
|
3010
3635
|
entityType,
|
|
3011
3636
|
entityId,
|
|
3012
3637
|
entityPayload,
|
|
3013
|
-
accountId,
|
|
3014
3638
|
options
|
|
3015
3639
|
});
|
|
3016
3640
|
} catch (err) {
|
|
@@ -7830,8 +8454,7 @@ var MutualService = class {
|
|
|
7830
8454
|
byEntityId,
|
|
7831
8455
|
entityType,
|
|
7832
8456
|
entityId,
|
|
7833
|
-
mutualPayload
|
|
7834
|
-
accountId
|
|
8457
|
+
mutualPayload
|
|
7835
8458
|
} = params;
|
|
7836
8459
|
const { mutual, entity, transactItems, parsedMutualPayload } = yield this.prepareCreateMutual(params);
|
|
7837
8460
|
debugLog("[MONORISE_DEBUG] createMutual executing transaction:", {
|
|
@@ -7844,8 +8467,7 @@ var MutualService = class {
|
|
|
7844
8467
|
if (entity) {
|
|
7845
8468
|
yield this.entityServiceLifeCycle.afterCreateEntityHook(
|
|
7846
8469
|
entity,
|
|
7847
|
-
mutualPayload
|
|
7848
|
-
accountId
|
|
8470
|
+
mutualPayload
|
|
7849
8471
|
);
|
|
7850
8472
|
}
|
|
7851
8473
|
const eventPayload = {
|
|
@@ -7854,7 +8476,6 @@ var MutualService = class {
|
|
|
7854
8476
|
entityType,
|
|
7855
8477
|
entityId,
|
|
7856
8478
|
parsedMutualPayload,
|
|
7857
|
-
accountId,
|
|
7858
8479
|
publishedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
7859
8480
|
};
|
|
7860
8481
|
const eventPromises = [
|
|
@@ -7929,7 +8550,6 @@ var MutualService = class {
|
|
|
7929
8550
|
entityType,
|
|
7930
8551
|
entityId,
|
|
7931
8552
|
mutualPayload,
|
|
7932
|
-
accountId,
|
|
7933
8553
|
options
|
|
7934
8554
|
}) {
|
|
7935
8555
|
debugLog("[MONORISE_DEBUG] updateMutual service start:", {
|
|
@@ -7964,8 +8584,7 @@ var MutualService = class {
|
|
|
7964
8584
|
byEntityId,
|
|
7965
8585
|
entityType,
|
|
7966
8586
|
entityId,
|
|
7967
|
-
parsedMutualPayload
|
|
7968
|
-
updatedByAccountId: accountId
|
|
8587
|
+
parsedMutualPayload
|
|
7969
8588
|
}
|
|
7970
8589
|
});
|
|
7971
8590
|
debugLog("[MONORISE_DEBUG] updateMutual service complete");
|
|
@@ -8005,8 +8624,7 @@ var MutualService = class {
|
|
|
8005
8624
|
byEntityType,
|
|
8006
8625
|
byEntityId,
|
|
8007
8626
|
entityType,
|
|
8008
|
-
entityId
|
|
8009
|
-
accountId
|
|
8627
|
+
entityId
|
|
8010
8628
|
}) {
|
|
8011
8629
|
const mutual = yield this.mutualRepository.deleteMutual(
|
|
8012
8630
|
byEntityType,
|
|
@@ -8020,8 +8638,7 @@ var MutualService = class {
|
|
|
8020
8638
|
byEntityType,
|
|
8021
8639
|
byEntityId,
|
|
8022
8640
|
entityType,
|
|
8023
|
-
entityId
|
|
8024
|
-
deletedByAccountId: accountId
|
|
8641
|
+
entityId
|
|
8025
8642
|
}
|
|
8026
8643
|
});
|
|
8027
8644
|
return mutual;
|
|
@@ -9532,13 +10149,12 @@ var EventUtils = class {
|
|
|
9532
10149
|
};
|
|
9533
10150
|
|
|
9534
10151
|
// controllers/entity/create-entity.controller.ts
|
|
9535
|
-
import { createMiddleware as
|
|
9536
|
-
import
|
|
10152
|
+
import { createMiddleware as createMiddleware5 } from "hono/factory";
|
|
10153
|
+
import httpStatus6 from "http-status";
|
|
9537
10154
|
var CreateEntityController = class {
|
|
9538
10155
|
constructor(entityService) {
|
|
9539
10156
|
this.entityService = entityService;
|
|
9540
|
-
this.controller =
|
|
9541
|
-
const accountId = c.req.header("account-id");
|
|
10157
|
+
this.controller = createMiddleware5((c) => __async(this, null, function* () {
|
|
9542
10158
|
const { entityType } = c.req.param();
|
|
9543
10159
|
const body = yield c.req.json();
|
|
9544
10160
|
try {
|
|
@@ -9546,16 +10162,15 @@ var CreateEntityController = class {
|
|
|
9546
10162
|
entityType,
|
|
9547
10163
|
entityPayload: body,
|
|
9548
10164
|
entityId: body.entityId,
|
|
9549
|
-
accountId,
|
|
9550
10165
|
options: {
|
|
9551
10166
|
createAndUpdateDatetime: body.createdAt
|
|
9552
10167
|
}
|
|
9553
10168
|
});
|
|
9554
|
-
c.status(
|
|
10169
|
+
c.status(httpStatus6.OK);
|
|
9555
10170
|
return c.json(entity);
|
|
9556
10171
|
} catch (err) {
|
|
9557
10172
|
if ((err == null ? void 0 : err.name) === "ZodError") {
|
|
9558
|
-
c.status(
|
|
10173
|
+
c.status(httpStatus6.BAD_REQUEST);
|
|
9559
10174
|
return c.json({
|
|
9560
10175
|
code: "API_VALIDATION_ERROR",
|
|
9561
10176
|
message: "API validation failed",
|
|
@@ -9563,11 +10178,11 @@ var CreateEntityController = class {
|
|
|
9563
10178
|
});
|
|
9564
10179
|
}
|
|
9565
10180
|
if (err instanceof StandardError && err.code === StandardErrorCode.EMAIL_EXISTS) {
|
|
9566
|
-
c.status(
|
|
10181
|
+
c.status(httpStatus6.BAD_REQUEST);
|
|
9567
10182
|
return c.json(__spreadValues({}, err.toJSON()));
|
|
9568
10183
|
}
|
|
9569
10184
|
if (err instanceof StandardError && err.code === StandardErrorCode.UNIQUE_VALUE_EXISTS) {
|
|
9570
|
-
c.status(
|
|
10185
|
+
c.status(httpStatus6.BAD_REQUEST);
|
|
9571
10186
|
return c.json(__spreadValues({}, err.toJSON()));
|
|
9572
10187
|
}
|
|
9573
10188
|
console.log("===create-entity error:", {
|
|
@@ -9582,24 +10197,22 @@ var CreateEntityController = class {
|
|
|
9582
10197
|
};
|
|
9583
10198
|
|
|
9584
10199
|
// controllers/entity/delete-entity.controller.ts
|
|
9585
|
-
import { createMiddleware as
|
|
9586
|
-
import
|
|
10200
|
+
import { createMiddleware as createMiddleware6 } from "hono/factory";
|
|
10201
|
+
import httpStatus7 from "http-status";
|
|
9587
10202
|
var DeleteEntityController = class {
|
|
9588
10203
|
constructor(entityService) {
|
|
9589
10204
|
this.entityService = entityService;
|
|
9590
|
-
this.controller =
|
|
9591
|
-
const accountId = c.req.header("account-id");
|
|
10205
|
+
this.controller = createMiddleware6((c) => __async(this, null, function* () {
|
|
9592
10206
|
const { entityType, entityId } = c.req.param();
|
|
9593
10207
|
try {
|
|
9594
10208
|
yield this.entityService.deleteEntity({
|
|
9595
10209
|
entityType,
|
|
9596
|
-
entityId
|
|
9597
|
-
accountId
|
|
10210
|
+
entityId
|
|
9598
10211
|
});
|
|
9599
10212
|
return c.json({ message: "entity deleted" });
|
|
9600
10213
|
} catch (err) {
|
|
9601
10214
|
if (err instanceof StandardError && err.code === StandardErrorCode.ENTITY_NOT_FOUND) {
|
|
9602
|
-
c.status(
|
|
10215
|
+
c.status(httpStatus7.NOT_FOUND);
|
|
9603
10216
|
return c.json(__spreadValues({}, err.toJSON()));
|
|
9604
10217
|
}
|
|
9605
10218
|
throw err;
|
|
@@ -9609,12 +10222,12 @@ var DeleteEntityController = class {
|
|
|
9609
10222
|
};
|
|
9610
10223
|
|
|
9611
10224
|
// controllers/entity/get-entity-by-unique-field-value.controller.ts
|
|
9612
|
-
import { createMiddleware as
|
|
9613
|
-
import
|
|
10225
|
+
import { createMiddleware as createMiddleware7 } from "hono/factory";
|
|
10226
|
+
import httpStatus8 from "http-status";
|
|
9614
10227
|
var GetEntityByUniqueFieldValueController = class {
|
|
9615
10228
|
constructor(entityRepository) {
|
|
9616
10229
|
this.entityRepository = entityRepository;
|
|
9617
|
-
this.controller =
|
|
10230
|
+
this.controller = createMiddleware7((c) => __async(this, null, function* () {
|
|
9618
10231
|
const { entityType, uniqueField, uniqueFieldValue } = c.req.param();
|
|
9619
10232
|
try {
|
|
9620
10233
|
const entity = yield this.entityRepository.getEntityByUniqueField(
|
|
@@ -9625,7 +10238,7 @@ var GetEntityByUniqueFieldValueController = class {
|
|
|
9625
10238
|
return c.json(entity);
|
|
9626
10239
|
} catch (err) {
|
|
9627
10240
|
if (err instanceof StandardError && err.code === StandardErrorCode.ENTITY_IS_UNDEFINED) {
|
|
9628
|
-
c.status(
|
|
10241
|
+
c.status(httpStatus8.NOT_FOUND);
|
|
9629
10242
|
return c.json({
|
|
9630
10243
|
code: "ENTITY_NOT_FOUND",
|
|
9631
10244
|
message: "Entity not found"
|
|
@@ -9638,23 +10251,23 @@ var GetEntityByUniqueFieldValueController = class {
|
|
|
9638
10251
|
};
|
|
9639
10252
|
|
|
9640
10253
|
// controllers/entity/get-entity.controller.ts
|
|
9641
|
-
import { createMiddleware as
|
|
9642
|
-
import
|
|
10254
|
+
import { createMiddleware as createMiddleware8 } from "hono/factory";
|
|
10255
|
+
import httpStatus9 from "http-status";
|
|
9643
10256
|
var GetEntityController = class {
|
|
9644
10257
|
constructor(entityRepository) {
|
|
9645
10258
|
this.entityRepository = entityRepository;
|
|
9646
|
-
this.controller =
|
|
10259
|
+
this.controller = createMiddleware8((c) => __async(this, null, function* () {
|
|
9647
10260
|
const { entityType, entityId } = c.req.param();
|
|
9648
10261
|
try {
|
|
9649
10262
|
const entity = yield this.entityRepository.getEntity(
|
|
9650
10263
|
entityType,
|
|
9651
10264
|
entityId
|
|
9652
10265
|
);
|
|
9653
|
-
c.status(
|
|
10266
|
+
c.status(httpStatus9.OK);
|
|
9654
10267
|
return c.json(entity);
|
|
9655
10268
|
} catch (err) {
|
|
9656
10269
|
if (err instanceof StandardError && err.code === StandardErrorCode.ENTITY_IS_UNDEFINED) {
|
|
9657
|
-
c.status(
|
|
10270
|
+
c.status(httpStatus9.NOT_FOUND);
|
|
9658
10271
|
return c.json({
|
|
9659
10272
|
code: "ENTITY_NOT_FOUND",
|
|
9660
10273
|
message: "Entity not found"
|
|
@@ -9667,7 +10280,7 @@ var GetEntityController = class {
|
|
|
9667
10280
|
};
|
|
9668
10281
|
|
|
9669
10282
|
// controllers/entity/list-entities.controller.ts
|
|
9670
|
-
import { createMiddleware as
|
|
10283
|
+
import { createMiddleware as createMiddleware9 } from "hono/factory";
|
|
9671
10284
|
var querySchema = external_exports.object({
|
|
9672
10285
|
limit: external_exports.string().optional(),
|
|
9673
10286
|
lastKey: external_exports.string().optional(),
|
|
@@ -9679,16 +10292,11 @@ var ListEntitiesController = class {
|
|
|
9679
10292
|
constructor(entityRepository, searchRepository) {
|
|
9680
10293
|
this.entityRepository = entityRepository;
|
|
9681
10294
|
this.searchRepository = searchRepository;
|
|
9682
|
-
this.controller =
|
|
10295
|
+
this.controller = createMiddleware9((c) => __async(this, null, function* () {
|
|
9683
10296
|
const errorContext = {};
|
|
9684
10297
|
try {
|
|
9685
|
-
const accountId = c.req.header("account-id") || "";
|
|
9686
|
-
if (Array.isArray(accountId)) {
|
|
9687
|
-
throw new Error("multiple account-id detected");
|
|
9688
|
-
}
|
|
9689
10298
|
const params = c.req.param();
|
|
9690
10299
|
const queries2 = c.req.query();
|
|
9691
|
-
errorContext.accountId = accountId;
|
|
9692
10300
|
errorContext.params = params;
|
|
9693
10301
|
errorContext.query = queries2;
|
|
9694
10302
|
const { entityType } = params;
|
|
@@ -9724,19 +10332,18 @@ var ListEntitiesController = class {
|
|
|
9724
10332
|
};
|
|
9725
10333
|
|
|
9726
10334
|
// controllers/entity/update-entity.controller.ts
|
|
9727
|
-
import { createMiddleware as
|
|
9728
|
-
import
|
|
10335
|
+
import { createMiddleware as createMiddleware10 } from "hono/factory";
|
|
10336
|
+
import httpStatus10 from "http-status";
|
|
9729
10337
|
var UpdateEntityController = class {
|
|
9730
10338
|
constructor(entityService) {
|
|
9731
10339
|
this.entityService = entityService;
|
|
9732
|
-
this.controller =
|
|
9733
|
-
const accountId = c.req.header("account-id");
|
|
10340
|
+
this.controller = createMiddleware10((c) => __async(this, null, function* () {
|
|
9734
10341
|
const { entityType, entityId } = c.req.param();
|
|
9735
10342
|
const body = yield c.req.json();
|
|
9736
10343
|
const _a = body, { $condition: condition, $where: where } = _a, entityPayload = __objRest(_a, ["$condition", "$where"]);
|
|
9737
10344
|
if (condition !== void 0) {
|
|
9738
10345
|
if (typeof condition !== "string" || condition.trim().length === 0) {
|
|
9739
|
-
c.status(
|
|
10346
|
+
c.status(httpStatus10.BAD_REQUEST);
|
|
9740
10347
|
return c.json({
|
|
9741
10348
|
code: "API_VALIDATION_ERROR",
|
|
9742
10349
|
message: "$condition must be a non-empty string"
|
|
@@ -9744,7 +10351,6 @@ var UpdateEntityController = class {
|
|
|
9744
10351
|
}
|
|
9745
10352
|
}
|
|
9746
10353
|
const errorContext = {
|
|
9747
|
-
accountId,
|
|
9748
10354
|
"req.params": c.req.param(),
|
|
9749
10355
|
"req.body": body
|
|
9750
10356
|
};
|
|
@@ -9753,16 +10359,15 @@ var UpdateEntityController = class {
|
|
|
9753
10359
|
entityType,
|
|
9754
10360
|
entityId,
|
|
9755
10361
|
entityPayload,
|
|
9756
|
-
accountId,
|
|
9757
10362
|
condition,
|
|
9758
10363
|
where
|
|
9759
10364
|
});
|
|
9760
10365
|
errorContext.entity = entity;
|
|
9761
|
-
c.status(
|
|
10366
|
+
c.status(httpStatus10.OK);
|
|
9762
10367
|
return c.json(entity);
|
|
9763
10368
|
} catch (err) {
|
|
9764
10369
|
if ((err == null ? void 0 : err.name) === "ZodError") {
|
|
9765
|
-
c.status(
|
|
10370
|
+
c.status(httpStatus10.BAD_REQUEST);
|
|
9766
10371
|
return c.json({
|
|
9767
10372
|
code: "API_VALIDATION_ERROR",
|
|
9768
10373
|
message: "API validation failed",
|
|
@@ -9770,19 +10375,19 @@ var UpdateEntityController = class {
|
|
|
9770
10375
|
});
|
|
9771
10376
|
}
|
|
9772
10377
|
if (err instanceof StandardError && (err.code === StandardErrorCode.ENTITY_NOT_FOUND || err.code === StandardErrorCode.ENTITY_IS_UNDEFINED)) {
|
|
9773
|
-
c.status(
|
|
10378
|
+
c.status(httpStatus10.NOT_FOUND);
|
|
9774
10379
|
return c.json(__spreadValues({}, err.toJSON()));
|
|
9775
10380
|
}
|
|
9776
10381
|
if (err instanceof StandardError && err.code === StandardErrorCode.INVALID_CONDITION) {
|
|
9777
|
-
c.status(
|
|
10382
|
+
c.status(httpStatus10.BAD_REQUEST);
|
|
9778
10383
|
return c.json(__spreadValues({}, err.toJSON()));
|
|
9779
10384
|
}
|
|
9780
10385
|
if (err instanceof StandardError && err.code === StandardErrorCode.UNIQUE_VALUE_EXISTS) {
|
|
9781
|
-
c.status(
|
|
10386
|
+
c.status(httpStatus10.BAD_REQUEST);
|
|
9782
10387
|
return c.json(__spreadValues({}, err.toJSON()));
|
|
9783
10388
|
}
|
|
9784
10389
|
if (err instanceof StandardError && err.code === StandardErrorCode.CONDITIONAL_CHECK_FAILED) {
|
|
9785
|
-
c.status(
|
|
10390
|
+
c.status(httpStatus10.CONFLICT);
|
|
9786
10391
|
return c.json(__spreadValues({}, err.toJSON()));
|
|
9787
10392
|
}
|
|
9788
10393
|
console.log(
|
|
@@ -9797,20 +10402,19 @@ var UpdateEntityController = class {
|
|
|
9797
10402
|
};
|
|
9798
10403
|
|
|
9799
10404
|
// controllers/entity/adjust-entity.controller.ts
|
|
9800
|
-
import { createMiddleware as
|
|
9801
|
-
import
|
|
10405
|
+
import { createMiddleware as createMiddleware11 } from "hono/factory";
|
|
10406
|
+
import httpStatus11 from "http-status";
|
|
9802
10407
|
var AdjustEntityController = class {
|
|
9803
10408
|
constructor(entityService) {
|
|
9804
10409
|
this.entityService = entityService;
|
|
9805
|
-
this.controller =
|
|
10410
|
+
this.controller = createMiddleware11((c) => __async(this, null, function* () {
|
|
9806
10411
|
var _b;
|
|
9807
|
-
const accountId = c.req.header("account-id") || "";
|
|
9808
10412
|
const { entityType, entityId } = c.req.param();
|
|
9809
10413
|
const body = yield c.req.json();
|
|
9810
10414
|
const _a = body, { $condition: condition } = _a, adjustments = __objRest(_a, ["$condition"]);
|
|
9811
10415
|
if (condition !== void 0) {
|
|
9812
10416
|
if (typeof condition !== "string" || condition.trim().length === 0) {
|
|
9813
|
-
c.status(
|
|
10417
|
+
c.status(httpStatus11.BAD_REQUEST);
|
|
9814
10418
|
return c.json({
|
|
9815
10419
|
code: "API_VALIDATION_ERROR",
|
|
9816
10420
|
message: "$condition must be a non-empty string"
|
|
@@ -9819,7 +10423,7 @@ var AdjustEntityController = class {
|
|
|
9819
10423
|
}
|
|
9820
10424
|
for (const [key, value] of Object.entries(adjustments)) {
|
|
9821
10425
|
if (typeof value !== "number") {
|
|
9822
|
-
c.status(
|
|
10426
|
+
c.status(httpStatus11.BAD_REQUEST);
|
|
9823
10427
|
return c.json({
|
|
9824
10428
|
code: "API_VALIDATION_ERROR",
|
|
9825
10429
|
message: `Field "${key}" must be a number, got ${typeof value}`
|
|
@@ -9831,22 +10435,21 @@ var AdjustEntityController = class {
|
|
|
9831
10435
|
entityType,
|
|
9832
10436
|
entityId,
|
|
9833
10437
|
adjustments,
|
|
9834
|
-
accountId,
|
|
9835
10438
|
condition
|
|
9836
10439
|
});
|
|
9837
|
-
c.status(
|
|
10440
|
+
c.status(httpStatus11.OK);
|
|
9838
10441
|
return c.json(entity.toJSON());
|
|
9839
10442
|
} catch (err) {
|
|
9840
10443
|
if (err instanceof StandardError && err.code === StandardErrorCode.ENTITY_IS_UNDEFINED) {
|
|
9841
|
-
c.status(
|
|
10444
|
+
c.status(httpStatus11.NOT_FOUND);
|
|
9842
10445
|
return c.json(__spreadValues({}, err.toJSON()));
|
|
9843
10446
|
}
|
|
9844
10447
|
if (err instanceof StandardError && err.code === StandardErrorCode.INVALID_CONDITION) {
|
|
9845
|
-
c.status(
|
|
10448
|
+
c.status(httpStatus11.BAD_REQUEST);
|
|
9846
10449
|
return c.json(__spreadValues({}, err.toJSON()));
|
|
9847
10450
|
}
|
|
9848
10451
|
if ((err == null ? void 0 : err.name) === "ConditionalCheckFailedException" || ((_b = err == null ? void 0 : err.__type) == null ? void 0 : _b.includes("ConditionalCheckFailed"))) {
|
|
9849
|
-
c.status(
|
|
10452
|
+
c.status(httpStatus11.CONFLICT);
|
|
9850
10453
|
return c.json({
|
|
9851
10454
|
code: "ADJUSTMENT_CONSTRAINT_VIOLATED",
|
|
9852
10455
|
message: "Adjustment would violate entity constraints"
|
|
@@ -9860,16 +10463,15 @@ var AdjustEntityController = class {
|
|
|
9860
10463
|
};
|
|
9861
10464
|
|
|
9862
10465
|
// controllers/entity/upsert-entity.controller.ts
|
|
9863
|
-
import { createMiddleware as
|
|
9864
|
-
import
|
|
10466
|
+
import { createMiddleware as createMiddleware12 } from "hono/factory";
|
|
10467
|
+
import httpStatus12 from "http-status";
|
|
9865
10468
|
var UpsertEntityController = class {
|
|
9866
10469
|
constructor(EntityConfig, entityRepository, publishEvent2) {
|
|
9867
10470
|
this.EntityConfig = EntityConfig;
|
|
9868
10471
|
this.entityRepository = entityRepository;
|
|
9869
10472
|
this.publishEvent = publishEvent2;
|
|
9870
|
-
this.controller =
|
|
10473
|
+
this.controller = createMiddleware12((c) => __async(this, null, function* () {
|
|
9871
10474
|
var _a;
|
|
9872
|
-
const accountId = c.req.header("account-id");
|
|
9873
10475
|
const { entityType, entityId } = c.req.param();
|
|
9874
10476
|
try {
|
|
9875
10477
|
const entityConfig = this.EntityConfig[entityType];
|
|
@@ -9925,14 +10527,13 @@ var UpsertEntityController = class {
|
|
|
9925
10527
|
payload: {
|
|
9926
10528
|
entityType,
|
|
9927
10529
|
entityId: entity.entityId,
|
|
9928
|
-
payload: body
|
|
9929
|
-
createdByAccountId: accountId
|
|
10530
|
+
payload: body
|
|
9930
10531
|
}
|
|
9931
10532
|
});
|
|
9932
10533
|
return c.json(entity);
|
|
9933
10534
|
} catch (err) {
|
|
9934
10535
|
if (err instanceof ZodError) {
|
|
9935
|
-
c.status(
|
|
10536
|
+
c.status(httpStatus12.BAD_REQUEST);
|
|
9936
10537
|
return c.json({
|
|
9937
10538
|
code: "API_VALIDATION_ERROR",
|
|
9938
10539
|
message: "API validation failed",
|
|
@@ -9940,7 +10541,7 @@ var UpsertEntityController = class {
|
|
|
9940
10541
|
});
|
|
9941
10542
|
}
|
|
9942
10543
|
if (err instanceof StandardError && err.code === StandardErrorCode.EMAIL_EXISTS) {
|
|
9943
|
-
c.status(
|
|
10544
|
+
c.status(httpStatus12.BAD_REQUEST);
|
|
9944
10545
|
return c.json(__spreadValues({}, err.toJSON()));
|
|
9945
10546
|
}
|
|
9946
10547
|
throw err;
|
|
@@ -9950,13 +10551,12 @@ var UpsertEntityController = class {
|
|
|
9950
10551
|
};
|
|
9951
10552
|
|
|
9952
10553
|
// controllers/mutual/create-mutual.controller.ts
|
|
9953
|
-
import { createMiddleware as
|
|
9954
|
-
import
|
|
10554
|
+
import { createMiddleware as createMiddleware13 } from "hono/factory";
|
|
10555
|
+
import httpStatus13 from "http-status";
|
|
9955
10556
|
var CreateMutualController = class {
|
|
9956
10557
|
constructor(mutualService) {
|
|
9957
10558
|
this.mutualService = mutualService;
|
|
9958
|
-
this.controller =
|
|
9959
|
-
const accountId = c.req.header("account-id");
|
|
10559
|
+
this.controller = createMiddleware13((c) => __async(this, null, function* () {
|
|
9960
10560
|
const { byEntityType, byEntityId, entityType, entityId } = c.req.param();
|
|
9961
10561
|
const asEntity = c.req.query("asEntity");
|
|
9962
10562
|
const body = yield c.req.json();
|
|
@@ -9967,7 +10567,6 @@ var CreateMutualController = class {
|
|
|
9967
10567
|
entityType,
|
|
9968
10568
|
entityId,
|
|
9969
10569
|
mutualPayload: body,
|
|
9970
|
-
accountId,
|
|
9971
10570
|
options: {
|
|
9972
10571
|
asEntity
|
|
9973
10572
|
}
|
|
@@ -9975,7 +10574,7 @@ var CreateMutualController = class {
|
|
|
9975
10574
|
return c.json(mutual);
|
|
9976
10575
|
} catch (err) {
|
|
9977
10576
|
if (err instanceof ZodError) {
|
|
9978
|
-
c.status(
|
|
10577
|
+
c.status(httpStatus13.BAD_REQUEST);
|
|
9979
10578
|
return c.json({
|
|
9980
10579
|
code: "API_VALIDATION_ERROR",
|
|
9981
10580
|
message: "API validation failed",
|
|
@@ -9983,11 +10582,11 @@ var CreateMutualController = class {
|
|
|
9983
10582
|
});
|
|
9984
10583
|
}
|
|
9985
10584
|
if (err instanceof StandardError && err.code === StandardErrorCode.MUTUAL_EXISTS) {
|
|
9986
|
-
c.status(
|
|
10585
|
+
c.status(httpStatus13.BAD_REQUEST);
|
|
9987
10586
|
return c.json(__spreadValues({}, err.toJSON()));
|
|
9988
10587
|
}
|
|
9989
10588
|
if (err instanceof StandardError && err.code === StandardErrorCode.ENTITY_IS_UNDEFINED) {
|
|
9990
|
-
c.status(
|
|
10589
|
+
c.status(httpStatus13.BAD_REQUEST);
|
|
9991
10590
|
return c.json(__spreadValues({}, err.toJSON()));
|
|
9992
10591
|
}
|
|
9993
10592
|
throw err;
|
|
@@ -9997,26 +10596,24 @@ var CreateMutualController = class {
|
|
|
9997
10596
|
};
|
|
9998
10597
|
|
|
9999
10598
|
// controllers/mutual/delete-mutual.controller.ts
|
|
10000
|
-
import { createMiddleware as
|
|
10001
|
-
import
|
|
10599
|
+
import { createMiddleware as createMiddleware14 } from "hono/factory";
|
|
10600
|
+
import httpStatus14 from "http-status";
|
|
10002
10601
|
var DeleteMutualController = class {
|
|
10003
10602
|
constructor(mutualService) {
|
|
10004
10603
|
this.mutualService = mutualService;
|
|
10005
|
-
this.controller =
|
|
10006
|
-
const accountId = c.req.header("account-id");
|
|
10604
|
+
this.controller = createMiddleware14((c) => __async(this, null, function* () {
|
|
10007
10605
|
const { byEntityType, byEntityId, entityType, entityId } = c.req.param();
|
|
10008
10606
|
try {
|
|
10009
10607
|
const mutual = yield this.mutualService.deleteMutual({
|
|
10010
10608
|
byEntityType,
|
|
10011
10609
|
byEntityId,
|
|
10012
10610
|
entityType,
|
|
10013
|
-
entityId
|
|
10014
|
-
accountId
|
|
10611
|
+
entityId
|
|
10015
10612
|
});
|
|
10016
10613
|
return c.json(mutual);
|
|
10017
10614
|
} catch (err) {
|
|
10018
10615
|
if (err instanceof StandardError && err.code === StandardErrorCode.MUTUAL_NOT_FOUND) {
|
|
10019
|
-
c.status(
|
|
10616
|
+
c.status(httpStatus14.BAD_REQUEST);
|
|
10020
10617
|
return c.json(__spreadValues({}, err.toJSON()));
|
|
10021
10618
|
}
|
|
10022
10619
|
throw err;
|
|
@@ -10026,12 +10623,12 @@ var DeleteMutualController = class {
|
|
|
10026
10623
|
};
|
|
10027
10624
|
|
|
10028
10625
|
// controllers/mutual/get-mutual.controller.ts
|
|
10029
|
-
import { createMiddleware as
|
|
10030
|
-
import
|
|
10626
|
+
import { createMiddleware as createMiddleware15 } from "hono/factory";
|
|
10627
|
+
import httpStatus15 from "http-status";
|
|
10031
10628
|
var GetMutualController = class {
|
|
10032
10629
|
constructor(associateRepository) {
|
|
10033
10630
|
this.associateRepository = associateRepository;
|
|
10034
|
-
this.controller =
|
|
10631
|
+
this.controller = createMiddleware15((c) => __async(this, null, function* () {
|
|
10035
10632
|
const { byEntityType, byEntityId, entityType, entityId } = c.req.param();
|
|
10036
10633
|
try {
|
|
10037
10634
|
const associate = yield this.associateRepository.getMutual(
|
|
@@ -10043,7 +10640,7 @@ var GetMutualController = class {
|
|
|
10043
10640
|
return c.json(associate);
|
|
10044
10641
|
} catch (err) {
|
|
10045
10642
|
if (err instanceof StandardError && err.code === StandardErrorCode.MUTUAL_IS_UNDEFINED) {
|
|
10046
|
-
c.status(
|
|
10643
|
+
c.status(httpStatus15.NOT_FOUND);
|
|
10047
10644
|
return c.json({
|
|
10048
10645
|
code: "MUTUAL_NOT_FOUND",
|
|
10049
10646
|
message: "Mutual not found"
|
|
@@ -10056,11 +10653,11 @@ var GetMutualController = class {
|
|
|
10056
10653
|
};
|
|
10057
10654
|
|
|
10058
10655
|
// controllers/mutual/list-entities-by-entity.controller.ts
|
|
10059
|
-
import { createMiddleware as
|
|
10656
|
+
import { createMiddleware as createMiddleware16 } from "hono/factory";
|
|
10060
10657
|
var ListEntitiesByEntityController = class {
|
|
10061
10658
|
constructor(associateRepository) {
|
|
10062
10659
|
this.associateRepository = associateRepository;
|
|
10063
|
-
this.controller =
|
|
10660
|
+
this.controller = createMiddleware16((c) => __async(this, null, function* () {
|
|
10064
10661
|
const { byEntityType, byEntityId, entityType } = c.req.param();
|
|
10065
10662
|
const querySchema3 = external_exports.object({
|
|
10066
10663
|
chainEntityQuery: external_exports.string().optional(),
|
|
@@ -10118,13 +10715,12 @@ var ListEntitiesByEntityController = class {
|
|
|
10118
10715
|
};
|
|
10119
10716
|
|
|
10120
10717
|
// controllers/mutual/update-mutual.controller.ts
|
|
10121
|
-
import { createMiddleware as
|
|
10122
|
-
import
|
|
10718
|
+
import { createMiddleware as createMiddleware17 } from "hono/factory";
|
|
10719
|
+
import httpStatus16 from "http-status";
|
|
10123
10720
|
var UpdateMutualController = class {
|
|
10124
10721
|
constructor(mutualService) {
|
|
10125
10722
|
this.mutualService = mutualService;
|
|
10126
|
-
this.controller =
|
|
10127
|
-
const accountId = c.req.header("account-id");
|
|
10723
|
+
this.controller = createMiddleware17((c) => __async(this, null, function* () {
|
|
10128
10724
|
const { byEntityType, byEntityId, entityType, entityId } = c.req.param();
|
|
10129
10725
|
const body = yield c.req.json();
|
|
10130
10726
|
try {
|
|
@@ -10134,7 +10730,6 @@ var UpdateMutualController = class {
|
|
|
10134
10730
|
entityType,
|
|
10135
10731
|
entityId,
|
|
10136
10732
|
mutualPayload: body,
|
|
10137
|
-
accountId,
|
|
10138
10733
|
options: {
|
|
10139
10734
|
returnUpdatedValue: true
|
|
10140
10735
|
}
|
|
@@ -10142,7 +10737,7 @@ var UpdateMutualController = class {
|
|
|
10142
10737
|
return c.json(mutual);
|
|
10143
10738
|
} catch (err) {
|
|
10144
10739
|
if (err instanceof ZodError) {
|
|
10145
|
-
c.status(
|
|
10740
|
+
c.status(httpStatus16.BAD_REQUEST);
|
|
10146
10741
|
return c.json({
|
|
10147
10742
|
code: "API_VALIDATION_ERROR",
|
|
10148
10743
|
message: "API validation failed",
|
|
@@ -10150,7 +10745,7 @@ var UpdateMutualController = class {
|
|
|
10150
10745
|
});
|
|
10151
10746
|
}
|
|
10152
10747
|
if (err instanceof StandardError && err.code === StandardErrorCode.MUTUAL_NOT_FOUND) {
|
|
10153
|
-
c.status(
|
|
10748
|
+
c.status(httpStatus16.BAD_REQUEST);
|
|
10154
10749
|
return c.json(__spreadValues({}, err.toJSON()));
|
|
10155
10750
|
}
|
|
10156
10751
|
throw err;
|
|
@@ -10310,7 +10905,6 @@ var EntityService = class {
|
|
|
10310
10905
|
entityType,
|
|
10311
10906
|
entityId,
|
|
10312
10907
|
entityPayload,
|
|
10313
|
-
accountId,
|
|
10314
10908
|
options
|
|
10315
10909
|
}) {
|
|
10316
10910
|
var _a, _b;
|
|
@@ -10344,8 +10938,7 @@ var EntityService = class {
|
|
|
10344
10938
|
);
|
|
10345
10939
|
yield this.entityServiceLifeCycle.afterCreateEntityHook(
|
|
10346
10940
|
entity,
|
|
10347
|
-
entityPayload
|
|
10348
|
-
accountId
|
|
10941
|
+
entityPayload
|
|
10349
10942
|
);
|
|
10350
10943
|
return entity;
|
|
10351
10944
|
});
|
|
@@ -10353,7 +10946,6 @@ var EntityService = class {
|
|
|
10353
10946
|
entityType,
|
|
10354
10947
|
entityId,
|
|
10355
10948
|
adjustments,
|
|
10356
|
-
accountId,
|
|
10357
10949
|
condition
|
|
10358
10950
|
}) {
|
|
10359
10951
|
var _a, _b, _c;
|
|
@@ -10419,7 +11011,6 @@ var EntityService = class {
|
|
|
10419
11011
|
entityType,
|
|
10420
11012
|
entityId,
|
|
10421
11013
|
data: entity.data,
|
|
10422
|
-
updatedByAccountId: accountId,
|
|
10423
11014
|
publishedAt: entity.updatedAt || (/* @__PURE__ */ new Date()).toISOString()
|
|
10424
11015
|
}
|
|
10425
11016
|
});
|
|
@@ -10429,7 +11020,6 @@ var EntityService = class {
|
|
|
10429
11020
|
entityType,
|
|
10430
11021
|
entityId,
|
|
10431
11022
|
entityPayload,
|
|
10432
|
-
accountId,
|
|
10433
11023
|
condition,
|
|
10434
11024
|
where
|
|
10435
11025
|
}) {
|
|
@@ -10531,7 +11121,6 @@ var EntityService = class {
|
|
|
10531
11121
|
entityType,
|
|
10532
11122
|
entityId,
|
|
10533
11123
|
data: entity.data,
|
|
10534
|
-
updatedByAccountId: accountId,
|
|
10535
11124
|
publishedAt: entity.updatedAt || (/* @__PURE__ */ new Date()).toISOString()
|
|
10536
11125
|
}
|
|
10537
11126
|
});
|
|
@@ -10545,16 +11134,14 @@ var EntityService = class {
|
|
|
10545
11134
|
});
|
|
10546
11135
|
this.deleteEntity = (_0) => __async(this, [_0], function* ({
|
|
10547
11136
|
entityType,
|
|
10548
|
-
entityId
|
|
10549
|
-
accountId
|
|
11137
|
+
entityId
|
|
10550
11138
|
}) {
|
|
10551
11139
|
yield this.entityRepository.deleteEntity(entityType, entityId);
|
|
10552
11140
|
yield this.publishEvent({
|
|
10553
11141
|
event: EVENT.CORE.ENTITY_DELETED,
|
|
10554
11142
|
payload: {
|
|
10555
11143
|
entityType,
|
|
10556
|
-
entityId
|
|
10557
|
-
deletedByAccountId: accountId
|
|
11144
|
+
entityId
|
|
10558
11145
|
}
|
|
10559
11146
|
});
|
|
10560
11147
|
});
|
|
@@ -10591,7 +11178,7 @@ var EntityService = class {
|
|
|
10591
11178
|
};
|
|
10592
11179
|
|
|
10593
11180
|
// controllers/tag/list-tags.controller.ts
|
|
10594
|
-
import { createMiddleware as
|
|
11181
|
+
import { createMiddleware as createMiddleware18 } from "hono/factory";
|
|
10595
11182
|
var querySchema2 = external_exports.object({
|
|
10596
11183
|
group: external_exports.string().optional(),
|
|
10597
11184
|
query: external_exports.string().optional(),
|
|
@@ -10603,7 +11190,7 @@ var querySchema2 = external_exports.object({
|
|
|
10603
11190
|
var ListTagsController = class {
|
|
10604
11191
|
constructor(tagRepository) {
|
|
10605
11192
|
this.tagRepository = tagRepository;
|
|
10606
|
-
this.controller =
|
|
11193
|
+
this.controller = createMiddleware18((c) => __async(this, null, function* () {
|
|
10607
11194
|
const errorContext = {};
|
|
10608
11195
|
try {
|
|
10609
11196
|
errorContext.params = c.req.param();
|
|
@@ -10638,32 +11225,30 @@ var ListTagsController = class {
|
|
|
10638
11225
|
};
|
|
10639
11226
|
|
|
10640
11227
|
// controllers/transaction/execute-transaction.controller.ts
|
|
10641
|
-
import { createMiddleware as
|
|
10642
|
-
import
|
|
11228
|
+
import { createMiddleware as createMiddleware19 } from "hono/factory";
|
|
11229
|
+
import httpStatus17 from "http-status";
|
|
10643
11230
|
var ExecuteTransactionController = class {
|
|
10644
11231
|
constructor(transactionService) {
|
|
10645
11232
|
this.transactionService = transactionService;
|
|
10646
11233
|
// biome-ignore lint/suspicious/noExplicitAny: Hono createMiddleware requires consistent return types
|
|
10647
|
-
this.controller =
|
|
10648
|
-
const accountId = c.req.header("account-id") || "";
|
|
11234
|
+
this.controller = createMiddleware19((c) => __async(this, null, function* () {
|
|
10649
11235
|
try {
|
|
10650
11236
|
const body = yield c.req.json();
|
|
10651
11237
|
if (!body.operations || !Array.isArray(body.operations)) {
|
|
10652
|
-
c.status(
|
|
11238
|
+
c.status(httpStatus17.BAD_REQUEST);
|
|
10653
11239
|
return c.json({
|
|
10654
11240
|
code: "API_VALIDATION_ERROR",
|
|
10655
11241
|
message: 'Request body must contain an "operations" array'
|
|
10656
11242
|
});
|
|
10657
11243
|
}
|
|
10658
11244
|
const result = yield this.transactionService.executeTransaction(
|
|
10659
|
-
body.operations
|
|
10660
|
-
accountId
|
|
11245
|
+
body.operations
|
|
10661
11246
|
);
|
|
10662
|
-
c.status(
|
|
11247
|
+
c.status(httpStatus17.OK);
|
|
10663
11248
|
return c.json(result);
|
|
10664
11249
|
} catch (err) {
|
|
10665
11250
|
if ((err == null ? void 0 : err.name) === "ZodError") {
|
|
10666
|
-
c.status(
|
|
11251
|
+
c.status(httpStatus17.BAD_REQUEST);
|
|
10667
11252
|
return c.json({
|
|
10668
11253
|
code: "API_VALIDATION_ERROR",
|
|
10669
11254
|
message: "Validation failed",
|
|
@@ -10671,7 +11256,7 @@ var ExecuteTransactionController = class {
|
|
|
10671
11256
|
});
|
|
10672
11257
|
}
|
|
10673
11258
|
if (err instanceof SyntaxError) {
|
|
10674
|
-
c.status(
|
|
11259
|
+
c.status(httpStatus17.BAD_REQUEST);
|
|
10675
11260
|
return c.json({
|
|
10676
11261
|
code: "API_VALIDATION_ERROR",
|
|
10677
11262
|
message: "Request body must be valid JSON"
|
|
@@ -10680,15 +11265,15 @@ var ExecuteTransactionController = class {
|
|
|
10680
11265
|
if (err instanceof StandardError) {
|
|
10681
11266
|
const code = err.code;
|
|
10682
11267
|
if (code === StandardErrorCode.ENTITY_IS_UNDEFINED || code === StandardErrorCode.ENTITY_NOT_FOUND || code === StandardErrorCode.MUTUAL_NOT_FOUND) {
|
|
10683
|
-
c.status(
|
|
11268
|
+
c.status(httpStatus17.NOT_FOUND);
|
|
10684
11269
|
return c.json(__spreadValues({}, err.toJSON()));
|
|
10685
11270
|
}
|
|
10686
11271
|
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) {
|
|
10687
|
-
c.status(
|
|
11272
|
+
c.status(httpStatus17.BAD_REQUEST);
|
|
10688
11273
|
return c.json(__spreadValues({}, err.toJSON()));
|
|
10689
11274
|
}
|
|
10690
11275
|
if (code === StandardErrorCode.TRANSACTION_FAILED || code === StandardErrorCode.CONDITIONAL_CHECK_FAILED || code === StandardErrorCode.UNIQUE_VALUE_EXISTS || code === StandardErrorCode.MUTUAL_EXISTS) {
|
|
10691
|
-
c.status(
|
|
11276
|
+
c.status(httpStatus17.CONFLICT);
|
|
10692
11277
|
return c.json(__spreadValues({}, err.toJSON()));
|
|
10693
11278
|
}
|
|
10694
11279
|
}
|
|
@@ -10699,13 +11284,13 @@ var ExecuteTransactionController = class {
|
|
|
10699
11284
|
};
|
|
10700
11285
|
|
|
10701
11286
|
// controllers/ws/create-ticket.controller.ts
|
|
10702
|
-
import { createMiddleware as
|
|
11287
|
+
import { createMiddleware as createMiddleware20 } from "hono/factory";
|
|
10703
11288
|
import { ulid as ulid6 } from "ulid";
|
|
10704
11289
|
var TICKET_TTL_SECONDS = 30 * 60;
|
|
10705
11290
|
var CreateTicketController = class {
|
|
10706
11291
|
constructor(container) {
|
|
10707
11292
|
this.container = container;
|
|
10708
|
-
this.controller =
|
|
11293
|
+
this.controller = createMiddleware20((c) => __async(this, null, function* () {
|
|
10709
11294
|
var _a, _b;
|
|
10710
11295
|
const { entityType, entityId } = c.req.param();
|
|
10711
11296
|
let feedTypes;
|
|
@@ -10771,7 +11356,7 @@ var EntityServiceLifeCycle = class {
|
|
|
10771
11356
|
this.publishEvent = publishEvent2;
|
|
10772
11357
|
this.eventUtils = eventUtils;
|
|
10773
11358
|
}
|
|
10774
|
-
afterCreateEntityHook(entity, entityPayload
|
|
11359
|
+
afterCreateEntityHook(entity, entityPayload) {
|
|
10775
11360
|
return __async(this, null, function* () {
|
|
10776
11361
|
var _a, _b;
|
|
10777
11362
|
const config = this.EntityConfig[entity.entityType];
|
|
@@ -10789,7 +11374,6 @@ var EntityServiceLifeCycle = class {
|
|
|
10789
11374
|
entityType: entity.entityType,
|
|
10790
11375
|
entityId: entity.entityId,
|
|
10791
11376
|
data: entity.data,
|
|
10792
|
-
createdByAccountId: accountId,
|
|
10793
11377
|
publishedAt: entity.updatedAt || (/* @__PURE__ */ new Date()).toISOString()
|
|
10794
11378
|
}
|
|
10795
11379
|
});
|
|
@@ -10811,7 +11395,7 @@ var TransactionService = class {
|
|
|
10811
11395
|
this.entityServiceLifeCycle = entityServiceLifeCycle;
|
|
10812
11396
|
this.eventUtils = eventUtils;
|
|
10813
11397
|
this.mutualService = mutualService;
|
|
10814
|
-
this.executeTransaction = (operations
|
|
11398
|
+
this.executeTransaction = (operations) => __async(this, null, function* () {
|
|
10815
11399
|
var _a;
|
|
10816
11400
|
if (!operations || operations.length === 0) {
|
|
10817
11401
|
throw new StandardError(
|
|
@@ -10823,7 +11407,7 @@ var TransactionService = class {
|
|
|
10823
11407
|
const pendingEvents = [];
|
|
10824
11408
|
const resultEntries = [];
|
|
10825
11409
|
const processed = yield Promise.all(
|
|
10826
|
-
operations.map((op) => this.processOperation(op
|
|
11410
|
+
operations.map((op) => this.processOperation(op))
|
|
10827
11411
|
);
|
|
10828
11412
|
const afterCommits = [];
|
|
10829
11413
|
for (const { items, events, afterCommit, resultEntry } of processed) {
|
|
@@ -10942,14 +11526,14 @@ var TransactionService = class {
|
|
|
10942
11526
|
return { results: resultEntries };
|
|
10943
11527
|
});
|
|
10944
11528
|
}
|
|
10945
|
-
processOperation(op
|
|
11529
|
+
processOperation(op) {
|
|
10946
11530
|
return __async(this, null, function* () {
|
|
10947
11531
|
switch (op.operation) {
|
|
10948
11532
|
case "createEntity": {
|
|
10949
11533
|
const { items, entity } = yield this.buildCreateItems(op);
|
|
10950
11534
|
return {
|
|
10951
11535
|
items,
|
|
10952
|
-
events: this.collectCreateEvents(entity, op.payload
|
|
11536
|
+
events: this.collectCreateEvents(entity, op.payload),
|
|
10953
11537
|
resultEntry: {
|
|
10954
11538
|
operation: "createEntity",
|
|
10955
11539
|
entityType: op.entityType,
|
|
@@ -10964,7 +11548,7 @@ var TransactionService = class {
|
|
|
10964
11548
|
const { item, updatedAt } = yield this.buildUpdateItem(op);
|
|
10965
11549
|
return {
|
|
10966
11550
|
items: [item],
|
|
10967
|
-
events: this.collectUpdateEvents(op, updatedAt
|
|
11551
|
+
events: this.collectUpdateEvents(op, updatedAt),
|
|
10968
11552
|
resultEntry: {
|
|
10969
11553
|
operation: "updateEntity",
|
|
10970
11554
|
entityType: op.entityType,
|
|
@@ -10983,7 +11567,6 @@ var TransactionService = class {
|
|
|
10983
11567
|
payload: {
|
|
10984
11568
|
entityType: op.entityType,
|
|
10985
11569
|
entityId: op.entityId,
|
|
10986
|
-
updatedByAccountId: accountId,
|
|
10987
11570
|
publishedAt: updatedAt
|
|
10988
11571
|
}
|
|
10989
11572
|
}
|
|
@@ -11005,8 +11588,7 @@ var TransactionService = class {
|
|
|
11005
11588
|
event: EVENT.CORE.ENTITY_DELETED,
|
|
11006
11589
|
payload: {
|
|
11007
11590
|
entityType: op.entityType,
|
|
11008
|
-
entityId: op.entityId
|
|
11009
|
-
deletedByAccountId: accountId
|
|
11591
|
+
entityId: op.entityId
|
|
11010
11592
|
}
|
|
11011
11593
|
}
|
|
11012
11594
|
],
|
|
@@ -11018,11 +11600,11 @@ var TransactionService = class {
|
|
|
11018
11600
|
};
|
|
11019
11601
|
}
|
|
11020
11602
|
case "createMutual":
|
|
11021
|
-
return this.processCreateMutual(op
|
|
11603
|
+
return this.processCreateMutual(op);
|
|
11022
11604
|
case "updateMutual":
|
|
11023
|
-
return this.processUpdateMutual(op
|
|
11605
|
+
return this.processUpdateMutual(op);
|
|
11024
11606
|
case "deleteMutual":
|
|
11025
|
-
return this.processDeleteMutual(op
|
|
11607
|
+
return this.processDeleteMutual(op);
|
|
11026
11608
|
default:
|
|
11027
11609
|
throw new StandardError(
|
|
11028
11610
|
StandardErrorCode.TRANSACTION_INVALID_OPERATION,
|
|
@@ -11035,7 +11617,7 @@ var TransactionService = class {
|
|
|
11035
11617
|
// the write is deferred into this transaction. A mutual created here
|
|
11036
11618
|
// publishes the same MUTUAL_CREATED event, and an asEntity mutual's
|
|
11037
11619
|
// projection is written in the same transaction.
|
|
11038
|
-
processCreateMutual(op
|
|
11620
|
+
processCreateMutual(op) {
|
|
11039
11621
|
return __async(this, null, function* () {
|
|
11040
11622
|
var _a, _b;
|
|
11041
11623
|
this.assertMutualOperation(op);
|
|
@@ -11058,15 +11640,13 @@ var TransactionService = class {
|
|
|
11058
11640
|
entityType: op.entityType,
|
|
11059
11641
|
entityId: op.entityId,
|
|
11060
11642
|
parsedMutualPayload,
|
|
11061
|
-
accountId,
|
|
11062
11643
|
publishedAt: (_b = mutual.createdAt) != null ? _b : (/* @__PURE__ */ new Date()).toISOString()
|
|
11063
11644
|
}
|
|
11064
11645
|
}
|
|
11065
11646
|
],
|
|
11066
11647
|
afterCommit: entity ? () => this.entityServiceLifeCycle.afterCreateEntityHook(
|
|
11067
11648
|
entity,
|
|
11068
|
-
mutualPayload
|
|
11069
|
-
accountId
|
|
11649
|
+
mutualPayload
|
|
11070
11650
|
) : void 0,
|
|
11071
11651
|
resultEntry: {
|
|
11072
11652
|
operation: "createMutual",
|
|
@@ -11087,7 +11667,7 @@ var TransactionService = class {
|
|
|
11087
11667
|
// Same validation and records as MutualService.updateMutual, and the same
|
|
11088
11668
|
// MUTUAL_UPDATED event. The stored values are read back after the commit
|
|
11089
11669
|
// (Phase 4), as a standalone PATCH /mutual/... returns them.
|
|
11090
|
-
processUpdateMutual(op
|
|
11670
|
+
processUpdateMutual(op) {
|
|
11091
11671
|
return __async(this, null, function* () {
|
|
11092
11672
|
this.assertMutualOperation(op);
|
|
11093
11673
|
if (!op.payload || typeof op.payload !== "object") {
|
|
@@ -11113,8 +11693,7 @@ var TransactionService = class {
|
|
|
11113
11693
|
byEntityId: op.byEntityId,
|
|
11114
11694
|
entityType: op.entityType,
|
|
11115
11695
|
entityId: op.entityId,
|
|
11116
|
-
parsedMutualPayload
|
|
11117
|
-
updatedByAccountId: accountId
|
|
11696
|
+
parsedMutualPayload
|
|
11118
11697
|
}
|
|
11119
11698
|
}
|
|
11120
11699
|
],
|
|
@@ -11130,7 +11709,7 @@ var TransactionService = class {
|
|
|
11130
11709
|
});
|
|
11131
11710
|
}
|
|
11132
11711
|
// Same soft delete as MutualService.deleteMutual, and the same event.
|
|
11133
|
-
processDeleteMutual(op
|
|
11712
|
+
processDeleteMutual(op) {
|
|
11134
11713
|
return __async(this, null, function* () {
|
|
11135
11714
|
this.assertMutualOperation(op);
|
|
11136
11715
|
const { mutual, TransactItems } = yield this.requireMutualService(
|
|
@@ -11150,8 +11729,7 @@ var TransactionService = class {
|
|
|
11150
11729
|
byEntityType: op.byEntityType,
|
|
11151
11730
|
byEntityId: op.byEntityId,
|
|
11152
11731
|
entityType: op.entityType,
|
|
11153
|
-
entityId: op.entityId
|
|
11154
|
-
deletedByAccountId: accountId
|
|
11732
|
+
entityId: op.entityId
|
|
11155
11733
|
}
|
|
11156
11734
|
}
|
|
11157
11735
|
],
|
|
@@ -11394,7 +11972,7 @@ var TransactionService = class {
|
|
|
11394
11972
|
}
|
|
11395
11973
|
};
|
|
11396
11974
|
}
|
|
11397
|
-
collectCreateEvents(entity, payload
|
|
11975
|
+
collectCreateEvents(entity, payload) {
|
|
11398
11976
|
var _a, _b, _c;
|
|
11399
11977
|
const events = [];
|
|
11400
11978
|
const publishedAt = entity.updatedAt || (/* @__PURE__ */ new Date()).toISOString();
|
|
@@ -11430,13 +12008,12 @@ var TransactionService = class {
|
|
|
11430
12008
|
entityType: entity.entityType,
|
|
11431
12009
|
entityId: entity.entityId,
|
|
11432
12010
|
data: entity.data,
|
|
11433
|
-
createdByAccountId: accountId,
|
|
11434
12011
|
publishedAt
|
|
11435
12012
|
}
|
|
11436
12013
|
});
|
|
11437
12014
|
return events;
|
|
11438
12015
|
}
|
|
11439
|
-
collectUpdateEvents(op, updatedAt
|
|
12016
|
+
collectUpdateEvents(op, updatedAt) {
|
|
11440
12017
|
var _a, _b;
|
|
11441
12018
|
const events = [];
|
|
11442
12019
|
const config = this.EntityConfig[op.entityType];
|
|
@@ -11472,7 +12049,6 @@ var TransactionService = class {
|
|
|
11472
12049
|
payload: {
|
|
11473
12050
|
entityType: op.entityType,
|
|
11474
12051
|
entityId: op.entityId,
|
|
11475
|
-
updatedByAccountId: accountId,
|
|
11476
12052
|
publishedAt: updatedAt
|
|
11477
12053
|
}
|
|
11478
12054
|
});
|
|
@@ -11807,6 +12383,7 @@ export {
|
|
|
11807
12383
|
handler7 as mutualProcessor,
|
|
11808
12384
|
handler8 as prejoinProcessor,
|
|
11809
12385
|
handler10 as replicationProcessor,
|
|
12386
|
+
requires,
|
|
11810
12387
|
handler9 as searchReindexProcessor,
|
|
11811
12388
|
setupCommonRoutes,
|
|
11812
12389
|
startBackfill as startAnalyticsBackfill,
|