@nymbalhq/platform 1.2.0 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-UBEGSSFI.js → chunk-2PLYK5RU.js} +567 -38
- package/dist/chunk-2PLYK5RU.js.map +1 -0
- package/dist/{chunk-XVUH34US.js → chunk-QN56IB4G.js} +11 -3
- package/dist/chunk-QN56IB4G.js.map +1 -0
- package/dist/db/schema/index.d.ts +136 -0
- package/dist/db/schema/index.js +1 -1
- package/dist/index.d.ts +15 -0
- package/dist/index.js +96 -18
- package/dist/index.js.map +1 -1
- package/dist/register-UUQ64HZP.js +8 -0
- package/migrations/postgres/0012_event_subject.sql +27 -0
- package/migrations/postgres/meta/0012_snapshot.json +1926 -0
- package/migrations/postgres/meta/_journal.json +7 -0
- package/migrations/sqlite/0012_event_subject.sql +27 -0
- package/migrations/sqlite/meta/0012_snapshot.json +1728 -0
- package/migrations/sqlite/meta/_journal.json +7 -0
- package/package.json +19 -19
- package/dist/chunk-UBEGSSFI.js.map +0 -1
- package/dist/chunk-XVUH34US.js.map +0 -1
- package/dist/register-NHG3TIRQ.js +0 -8
- /package/dist/{register-NHG3TIRQ.js.map → register-UUQ64HZP.js.map} +0 -0
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
settings,
|
|
6
6
|
settings2,
|
|
7
7
|
sqlite_exports
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-QN56IB4G.js";
|
|
9
9
|
|
|
10
10
|
// src/routes/register.ts
|
|
11
11
|
import {
|
|
@@ -1827,6 +1827,66 @@ function createRefundService(deps) {
|
|
|
1827
1827
|
};
|
|
1828
1828
|
}
|
|
1829
1829
|
|
|
1830
|
+
// src/history/http.ts
|
|
1831
|
+
var DEFAULT_LIMIT = 50;
|
|
1832
|
+
var MAX_LIMIT = 200;
|
|
1833
|
+
var ISO_INSTANT = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}(:\d{2}(\.\d{1,9})?)?(Z|[+-]\d{2}:\d{2})$/i;
|
|
1834
|
+
function one(ctx, name) {
|
|
1835
|
+
const value = ctx.query[name];
|
|
1836
|
+
return Array.isArray(value) ? value[0] : value;
|
|
1837
|
+
}
|
|
1838
|
+
function atOf(ctx) {
|
|
1839
|
+
return one(ctx, "at");
|
|
1840
|
+
}
|
|
1841
|
+
async function answerAsOf(reader, at, resolve2, notFound2) {
|
|
1842
|
+
try {
|
|
1843
|
+
const instant = new Date(at);
|
|
1844
|
+
if (!ISO_INSTANT.test(at) || Number.isNaN(instant.getTime())) {
|
|
1845
|
+
return fail("history.invalid_at", "at must be an ISO 8601 date-time with a zone", 400, { at });
|
|
1846
|
+
}
|
|
1847
|
+
const outcome = await reader.asOf(await resolve2(), instant);
|
|
1848
|
+
switch (outcome.kind) {
|
|
1849
|
+
case "record":
|
|
1850
|
+
return ok(outcome.read);
|
|
1851
|
+
case "not_found":
|
|
1852
|
+
return notFound2();
|
|
1853
|
+
case "deleted":
|
|
1854
|
+
return fail("history.deleted", `Deleted at ${outcome.deletedAt}`, 410, {
|
|
1855
|
+
deletedAt: outcome.deletedAt
|
|
1856
|
+
});
|
|
1857
|
+
case "before_start":
|
|
1858
|
+
return fail(
|
|
1859
|
+
"history.before_start",
|
|
1860
|
+
outcome.historyStartsAt === null ? "The record predates the event log\u2019s window (events.retentionDays)" : `The event log holds this record from ${outcome.historyStartsAt}`,
|
|
1861
|
+
409,
|
|
1862
|
+
{ historyStartsAt: outcome.historyStartsAt }
|
|
1863
|
+
);
|
|
1864
|
+
}
|
|
1865
|
+
} catch (err) {
|
|
1866
|
+
return renderError(err);
|
|
1867
|
+
}
|
|
1868
|
+
}
|
|
1869
|
+
async function answerHistory(reader, ctx, resolve2, notFound2) {
|
|
1870
|
+
try {
|
|
1871
|
+
const limitRaw = one(ctx, "limit");
|
|
1872
|
+
const limit = limitRaw === void 0 || limitRaw === "" ? DEFAULT_LIMIT : Number(limitRaw);
|
|
1873
|
+
if (!Number.isInteger(limit) || limit < 1) {
|
|
1874
|
+
return fail("history.invalid", "limit must be a whole number of at least 1", 400);
|
|
1875
|
+
}
|
|
1876
|
+
const cursor = one(ctx, "cursor");
|
|
1877
|
+
if (cursor !== void 0 && cursor !== "" && !/^\d+$/.test(cursor)) {
|
|
1878
|
+
return fail("history.invalid", "cursor is not one this API issued", 400);
|
|
1879
|
+
}
|
|
1880
|
+
const page = await reader.list(await resolve2(), {
|
|
1881
|
+
limit: Math.min(limit, MAX_LIMIT),
|
|
1882
|
+
...cursor !== void 0 && cursor !== "" && { beforeSeq: Number(cursor) }
|
|
1883
|
+
});
|
|
1884
|
+
return page === null ? notFound2() : ok(page);
|
|
1885
|
+
} catch (err) {
|
|
1886
|
+
return renderError(err);
|
|
1887
|
+
}
|
|
1888
|
+
}
|
|
1889
|
+
|
|
1830
1890
|
// src/routes/admin-orders.ts
|
|
1831
1891
|
function parseNotes(rawNotes, createdAt) {
|
|
1832
1892
|
if (!rawNotes) return [];
|
|
@@ -1839,7 +1899,7 @@ function parseNotes(rawNotes, createdAt) {
|
|
|
1839
1899
|
}
|
|
1840
1900
|
}
|
|
1841
1901
|
function registerAdminOrdersRoutes(adapter, deps) {
|
|
1842
|
-
const { order, checkout, refund, repos } = deps;
|
|
1902
|
+
const { order, checkout, refund, repos, history } = deps;
|
|
1843
1903
|
const { store } = repos.order;
|
|
1844
1904
|
async function withPayments(tx, orders) {
|
|
1845
1905
|
const refunds = await repos.orderRefund.listByOrders(
|
|
@@ -1855,6 +1915,11 @@ function registerAdminOrdersRoutes(adapter, deps) {
|
|
|
1855
1915
|
async function findOrder(tx, idOrNumber) {
|
|
1856
1916
|
return await repos.order.findById(tx, idOrNumber) ?? await repos.order.findByOrderNumber(tx, idOrNumber);
|
|
1857
1917
|
}
|
|
1918
|
+
async function historySubject(idOrNumber) {
|
|
1919
|
+
const found = await store.read((tx) => findOrder(tx, idOrNumber));
|
|
1920
|
+
return { kind: "order", id: found?.id ?? idOrNumber, live: found !== null };
|
|
1921
|
+
}
|
|
1922
|
+
const notFound2 = (idOrNumber) => () => fail("orders.not_found", `Order not found: ${idOrNumber}`, 404);
|
|
1858
1923
|
adapter.registerRoute(
|
|
1859
1924
|
"GET",
|
|
1860
1925
|
"/api/admin/orders",
|
|
@@ -1911,6 +1976,10 @@ function registerAdminOrdersRoutes(adapter, deps) {
|
|
|
1911
1976
|
try {
|
|
1912
1977
|
const orderNumber = ctx.params.orderNumber;
|
|
1913
1978
|
if (!orderNumber) return fail("admin.invalid", "orderNumber required", 400);
|
|
1979
|
+
const at = atOf(ctx);
|
|
1980
|
+
if (at !== void 0) {
|
|
1981
|
+
return answerAsOf(history, at, () => historySubject(orderNumber), notFound2(orderNumber));
|
|
1982
|
+
}
|
|
1914
1983
|
const detail = await store.read(async (tx) => {
|
|
1915
1984
|
const found = await repos.order.findByOrderNumber(tx, orderNumber);
|
|
1916
1985
|
if (!found) return null;
|
|
@@ -2035,8 +2104,8 @@ function registerAdminOrdersRoutes(adapter, deps) {
|
|
|
2035
2104
|
const id2 = ctx.params.id;
|
|
2036
2105
|
if (!id2) return fail("admin.invalid", "id required", 400);
|
|
2037
2106
|
const body = ctx.body;
|
|
2038
|
-
const
|
|
2039
|
-
const requestId = body.requestId ?? ("key" in
|
|
2107
|
+
const keyed2 = idempotencyKeyOf(ctx);
|
|
2108
|
+
const requestId = body.requestId ?? ("key" in keyed2 ? keyed2.key : void 0);
|
|
2040
2109
|
const result = await refund.refund({
|
|
2041
2110
|
orderId: id2,
|
|
2042
2111
|
amountMinor: body.amountMinor,
|
|
@@ -2050,6 +2119,15 @@ function registerAdminOrdersRoutes(adapter, deps) {
|
|
|
2050
2119
|
}
|
|
2051
2120
|
})
|
|
2052
2121
|
);
|
|
2122
|
+
adapter.registerRoute(
|
|
2123
|
+
"GET",
|
|
2124
|
+
"/api/admin/orders/:id/history",
|
|
2125
|
+
requireRole("admin", async (ctx) => {
|
|
2126
|
+
const id2 = ctx.params.id;
|
|
2127
|
+
if (!id2) return fail("admin.invalid", "id required", 400);
|
|
2128
|
+
return answerHistory(history, ctx, () => historySubject(id2), notFound2(id2));
|
|
2129
|
+
})
|
|
2130
|
+
);
|
|
2053
2131
|
adapter.registerRoute(
|
|
2054
2132
|
"GET",
|
|
2055
2133
|
"/api/admin/orders/:id/timeline",
|
|
@@ -2057,12 +2135,12 @@ function registerAdminOrdersRoutes(adapter, deps) {
|
|
|
2057
2135
|
try {
|
|
2058
2136
|
const id2 = ctx.params.id;
|
|
2059
2137
|
if (!id2) return fail("admin.invalid", "id required", 400);
|
|
2060
|
-
const
|
|
2138
|
+
const history2 = await store.read(async (tx) => {
|
|
2061
2139
|
const found = await findOrder(tx, id2);
|
|
2062
2140
|
return found ? repos.orderHistory.listByOrder(tx, found.id) : null;
|
|
2063
2141
|
});
|
|
2064
|
-
if (!
|
|
2065
|
-
return ok(
|
|
2142
|
+
if (!history2) return fail("orders.not_found", `Order not found: ${id2}`, 404);
|
|
2143
|
+
return ok(history2);
|
|
2066
2144
|
} catch (err) {
|
|
2067
2145
|
return renderError(err);
|
|
2068
2146
|
}
|
|
@@ -2131,8 +2209,27 @@ function registerAdminOrdersRoutes(adapter, deps) {
|
|
|
2131
2209
|
}
|
|
2132
2210
|
|
|
2133
2211
|
// src/routes/admin-products.ts
|
|
2212
|
+
import {
|
|
2213
|
+
NotFoundError as NotFoundError5
|
|
2214
|
+
} from "@nymbalhq/types";
|
|
2215
|
+
async function orNull(found) {
|
|
2216
|
+
try {
|
|
2217
|
+
return await found;
|
|
2218
|
+
} catch (err) {
|
|
2219
|
+
if (err instanceof NotFoundError5) return null;
|
|
2220
|
+
throw err;
|
|
2221
|
+
}
|
|
2222
|
+
}
|
|
2134
2223
|
function registerAdminProductsRoutes(adapter, deps) {
|
|
2135
|
-
const { product } = deps;
|
|
2224
|
+
const { product, history } = deps;
|
|
2225
|
+
async function findProduct(idOrSlug) {
|
|
2226
|
+
return await orNull(product.getById(idOrSlug)) ?? await orNull(product.getBySlug(idOrSlug));
|
|
2227
|
+
}
|
|
2228
|
+
async function historySubject(idOrSlug) {
|
|
2229
|
+
const live = await findProduct(idOrSlug);
|
|
2230
|
+
return { kind: "product", id: live?.id ?? idOrSlug, live: live !== null };
|
|
2231
|
+
}
|
|
2232
|
+
const notFound2 = (idOrSlug) => () => fail("not_found", `product not found: ${idOrSlug}`, 404);
|
|
2136
2233
|
adapter.registerRoute(
|
|
2137
2234
|
"GET",
|
|
2138
2235
|
"/api/admin/products",
|
|
@@ -2174,6 +2271,33 @@ function registerAdminProductsRoutes(adapter, deps) {
|
|
|
2174
2271
|
}
|
|
2175
2272
|
})
|
|
2176
2273
|
);
|
|
2274
|
+
adapter.registerRoute(
|
|
2275
|
+
"GET",
|
|
2276
|
+
"/api/admin/products/:id",
|
|
2277
|
+
requireRole("admin", async (ctx) => {
|
|
2278
|
+
try {
|
|
2279
|
+
const idOrSlug = ctx.params.id;
|
|
2280
|
+
if (!idOrSlug) return fail("admin.invalid", "id required", 400);
|
|
2281
|
+
const at = atOf(ctx);
|
|
2282
|
+
if (at !== void 0) {
|
|
2283
|
+
return answerAsOf(history, at, () => historySubject(idOrSlug), notFound2(idOrSlug));
|
|
2284
|
+
}
|
|
2285
|
+
const found = await findProduct(idOrSlug);
|
|
2286
|
+
return found === null ? notFound2(idOrSlug)() : ok(found);
|
|
2287
|
+
} catch (err) {
|
|
2288
|
+
return renderError(err);
|
|
2289
|
+
}
|
|
2290
|
+
})
|
|
2291
|
+
);
|
|
2292
|
+
adapter.registerRoute(
|
|
2293
|
+
"GET",
|
|
2294
|
+
"/api/admin/products/:id/history",
|
|
2295
|
+
requireRole("admin", async (ctx) => {
|
|
2296
|
+
const idOrSlug = ctx.params.id;
|
|
2297
|
+
if (!idOrSlug) return fail("admin.invalid", "id required", 400);
|
|
2298
|
+
return answerHistory(history, ctx, () => historySubject(idOrSlug), notFound2(idOrSlug));
|
|
2299
|
+
})
|
|
2300
|
+
);
|
|
2177
2301
|
adapter.registerRoute(
|
|
2178
2302
|
"PATCH",
|
|
2179
2303
|
"/api/admin/products/:id",
|
|
@@ -2181,10 +2305,7 @@ function registerAdminProductsRoutes(adapter, deps) {
|
|
|
2181
2305
|
try {
|
|
2182
2306
|
const id2 = ctx.params.id;
|
|
2183
2307
|
if (!id2) return fail("admin.invalid", "id required", 400);
|
|
2184
|
-
const snap = await product.update(
|
|
2185
|
-
id2,
|
|
2186
|
-
ctx.body
|
|
2187
|
-
);
|
|
2308
|
+
const snap = await product.update(id2, ctx.body);
|
|
2188
2309
|
return ok(snap);
|
|
2189
2310
|
} catch (err) {
|
|
2190
2311
|
return renderError(err);
|
|
@@ -2464,8 +2585,13 @@ function computeStats(orders) {
|
|
|
2464
2585
|
};
|
|
2465
2586
|
}
|
|
2466
2587
|
function registerAdminCustomersRoutes(adapter, deps) {
|
|
2467
|
-
const { repos } = deps;
|
|
2588
|
+
const { repos, history } = deps;
|
|
2468
2589
|
const { store } = repos.customer;
|
|
2590
|
+
async function historySubject(id2) {
|
|
2591
|
+
const found = await store.read((tx) => repos.customer.findById(tx, id2));
|
|
2592
|
+
return { kind: "customer", id: id2, live: found !== null };
|
|
2593
|
+
}
|
|
2594
|
+
const notFound2 = (id2) => () => fail("customers.not_found", `Customer not found: ${id2}`, 404);
|
|
2469
2595
|
adapter.registerRoute(
|
|
2470
2596
|
"GET",
|
|
2471
2597
|
"/api/admin/customers",
|
|
@@ -2516,6 +2642,8 @@ function registerAdminCustomersRoutes(adapter, deps) {
|
|
|
2516
2642
|
try {
|
|
2517
2643
|
const id2 = ctx.params.id;
|
|
2518
2644
|
if (!id2) return fail("admin.invalid", "id required", 400);
|
|
2645
|
+
const at = atOf(ctx);
|
|
2646
|
+
if (at !== void 0) return answerAsOf(history, at, () => historySubject(id2), notFound2(id2));
|
|
2519
2647
|
const found = await store.read(async (tx) => {
|
|
2520
2648
|
const raw = await repos.customer.findById(tx, id2);
|
|
2521
2649
|
return raw ? { raw, orders: await repos.order.listByCustomer(tx, id2) } : null;
|
|
@@ -2530,6 +2658,15 @@ function registerAdminCustomersRoutes(adapter, deps) {
|
|
|
2530
2658
|
}
|
|
2531
2659
|
})
|
|
2532
2660
|
);
|
|
2661
|
+
adapter.registerRoute(
|
|
2662
|
+
"GET",
|
|
2663
|
+
"/api/admin/customers/:id/history",
|
|
2664
|
+
requireRole("admin", async (ctx) => {
|
|
2665
|
+
const id2 = ctx.params.id;
|
|
2666
|
+
if (!id2) return fail("admin.invalid", "id required", 400);
|
|
2667
|
+
return answerHistory(history, ctx, () => historySubject(id2), notFound2(id2));
|
|
2668
|
+
})
|
|
2669
|
+
);
|
|
2533
2670
|
adapter.registerRoute(
|
|
2534
2671
|
"GET",
|
|
2535
2672
|
"/api/admin/customers/:id/orders",
|
|
@@ -3335,7 +3472,7 @@ function createSqliteSearchIndex(raw) {
|
|
|
3335
3472
|
}
|
|
3336
3473
|
|
|
3337
3474
|
// src/adapters/search/native-adapter.ts
|
|
3338
|
-
var
|
|
3475
|
+
var DEFAULT_LIMIT2 = 20;
|
|
3339
3476
|
function encodeSearchCursor(offset) {
|
|
3340
3477
|
return Buffer.from(String(offset), "utf8").toString("base64url");
|
|
3341
3478
|
}
|
|
@@ -3387,8 +3524,8 @@ function createNativeSearchAdapter(deps) {
|
|
|
3387
3524
|
},
|
|
3388
3525
|
async search(query, params) {
|
|
3389
3526
|
const offset = params?.cursor === void 0 ? 0 : decodeSearchCursor(params.cursor);
|
|
3390
|
-
const requested = params?.limit ??
|
|
3391
|
-
const limit = Number.isFinite(requested) ? Math.max(1, Math.floor(requested)) :
|
|
3527
|
+
const requested = params?.limit ?? DEFAULT_LIMIT2;
|
|
3528
|
+
const limit = Number.isFinite(requested) ? Math.max(1, Math.floor(requested)) : DEFAULT_LIMIT2;
|
|
3392
3529
|
const terms = uniqueTerms(query);
|
|
3393
3530
|
if (terms.length === 0) return { items: [], total: 0, nextCursor: null };
|
|
3394
3531
|
const categories = categoryFilter(params?.filters);
|
|
@@ -4100,24 +4237,387 @@ function registerAdminSettingsRoutes(adapter, deps) {
|
|
|
4100
4237
|
);
|
|
4101
4238
|
}
|
|
4102
4239
|
|
|
4240
|
+
// src/history/fold.ts
|
|
4241
|
+
import {
|
|
4242
|
+
canTransitionOrder as canTransitionOrder3,
|
|
4243
|
+
paymentState as paymentState3
|
|
4244
|
+
} from "@nymbalhq/types";
|
|
4245
|
+
|
|
4246
|
+
// src/history/views.ts
|
|
4247
|
+
import {
|
|
4248
|
+
paymentState as paymentState2
|
|
4249
|
+
} from "@nymbalhq/types";
|
|
4250
|
+
function orderViewOf(order) {
|
|
4251
|
+
const {
|
|
4252
|
+
notes: _notes,
|
|
4253
|
+
metadata: _metadata,
|
|
4254
|
+
updatedAt: _updatedAt,
|
|
4255
|
+
capturedAt: _capturedAt,
|
|
4256
|
+
captureMethod: _captureMethod,
|
|
4257
|
+
...rest
|
|
4258
|
+
} = order;
|
|
4259
|
+
const { payment: _payment, history: _history, ...view } = rest;
|
|
4260
|
+
return {
|
|
4261
|
+
...view,
|
|
4262
|
+
payment: {
|
|
4263
|
+
state: paymentState2(order),
|
|
4264
|
+
capturedMinor: order.capturedMinor,
|
|
4265
|
+
refundedMinor: order.refundedMinor,
|
|
4266
|
+
currency: order.currency
|
|
4267
|
+
}
|
|
4268
|
+
};
|
|
4269
|
+
}
|
|
4270
|
+
function toProductAsOf(snapshot) {
|
|
4271
|
+
return {
|
|
4272
|
+
...snapshot,
|
|
4273
|
+
variants: snapshot.variants.map(({ updatedAt: _updatedAt, ...variant }) => variant),
|
|
4274
|
+
// A set: product.created keeps the order it was sent in, a read the repository's.
|
|
4275
|
+
categoryIds: [...snapshot.categoryIds].sort()
|
|
4276
|
+
};
|
|
4277
|
+
}
|
|
4278
|
+
function toCustomerSnapshot(customer) {
|
|
4279
|
+
return {
|
|
4280
|
+
id: customer.id,
|
|
4281
|
+
email: customer.email,
|
|
4282
|
+
firstName: customer.firstName,
|
|
4283
|
+
lastName: customer.lastName,
|
|
4284
|
+
phone: customer.phone,
|
|
4285
|
+
addresses: customer.addresses,
|
|
4286
|
+
createdAt: customer.createdAt
|
|
4287
|
+
};
|
|
4288
|
+
}
|
|
4289
|
+
|
|
4290
|
+
// src/history/fold.ts
|
|
4291
|
+
function eventName(type) {
|
|
4292
|
+
return type.replace(/\.v\d+$/, "");
|
|
4293
|
+
}
|
|
4294
|
+
function payloadOf(row) {
|
|
4295
|
+
const payload = row.event.payload;
|
|
4296
|
+
return payload !== null && typeof payload === "object" ? payload : {};
|
|
4297
|
+
}
|
|
4298
|
+
function objectAt(payload, key) {
|
|
4299
|
+
const value = payload[key];
|
|
4300
|
+
return value !== null && typeof value === "object" ? value : null;
|
|
4301
|
+
}
|
|
4302
|
+
var BASE_EVENTS = {
|
|
4303
|
+
product: { names: ["product.created", "product.updated"], snapshot: "product" },
|
|
4304
|
+
order: { names: ["order.placed"], snapshot: "order" },
|
|
4305
|
+
customer: { names: ["customer.created", "customer.updated"], snapshot: "customer" }
|
|
4306
|
+
};
|
|
4307
|
+
function isBaseEvent(kind, row) {
|
|
4308
|
+
const base = BASE_EVENTS[kind];
|
|
4309
|
+
return base.names.includes(eventName(row.event.type)) && objectAt(payloadOf(row), base.snapshot) !== null;
|
|
4310
|
+
}
|
|
4311
|
+
function isDeleted(view) {
|
|
4312
|
+
return view !== null && view.deleted === true;
|
|
4313
|
+
}
|
|
4314
|
+
function applyProduct(view, row) {
|
|
4315
|
+
if (isDeleted(view)) return view;
|
|
4316
|
+
const name = eventName(row.event.type);
|
|
4317
|
+
const payload = payloadOf(row);
|
|
4318
|
+
if (isBaseEvent("product", row)) return toProductAsOf(payload["product"]);
|
|
4319
|
+
if (name === "product.deleted") return { deleted: true, deletedAt: row.createdAt.toISOString() };
|
|
4320
|
+
if (view === null || name !== "inventory.changed") return view;
|
|
4321
|
+
const product = view;
|
|
4322
|
+
const variantId = payload["variantId"];
|
|
4323
|
+
const newQty = payload["newQty"];
|
|
4324
|
+
if (typeof newQty !== "number" || !product.variants.some((v) => v.id === variantId)) return view;
|
|
4325
|
+
return {
|
|
4326
|
+
...product,
|
|
4327
|
+
variants: product.variants.map((v) => v.id === variantId ? { ...v, stock: newQty } : v)
|
|
4328
|
+
};
|
|
4329
|
+
}
|
|
4330
|
+
function refundedStatus(status, target) {
|
|
4331
|
+
return status !== target && canTransitionOrder3(status, target) ? target : status;
|
|
4332
|
+
}
|
|
4333
|
+
function applyOrder(view, row, context2) {
|
|
4334
|
+
const name = eventName(row.event.type);
|
|
4335
|
+
const payload = payloadOf(row);
|
|
4336
|
+
if (isBaseEvent("order", row)) return orderViewOf(payload["order"]);
|
|
4337
|
+
if (view === null || isDeleted(view)) return view;
|
|
4338
|
+
const order = view;
|
|
4339
|
+
let next;
|
|
4340
|
+
switch (name) {
|
|
4341
|
+
case "order.status_changed":
|
|
4342
|
+
next = { ...order, status: payload["to"] };
|
|
4343
|
+
break;
|
|
4344
|
+
case "order.shipped":
|
|
4345
|
+
next = { ...order, status: "shipped" };
|
|
4346
|
+
break;
|
|
4347
|
+
case "order.delivered":
|
|
4348
|
+
next = { ...order, status: "delivered" };
|
|
4349
|
+
break;
|
|
4350
|
+
case "order.cancelled":
|
|
4351
|
+
next = { ...order, status: "cancelled" };
|
|
4352
|
+
break;
|
|
4353
|
+
case "payment.intent_created":
|
|
4354
|
+
next = { ...order, paymentIntentId: payload["paymentId"] };
|
|
4355
|
+
break;
|
|
4356
|
+
case "payment.captured":
|
|
4357
|
+
next = { ...order, capturedMinor: payload["amountMinor"] };
|
|
4358
|
+
break;
|
|
4359
|
+
case "order.paid":
|
|
4360
|
+
next = {
|
|
4361
|
+
...order,
|
|
4362
|
+
capturedMinor: payload["amountMinor"],
|
|
4363
|
+
status: order.status === "pending" ? "confirmed" : order.status
|
|
4364
|
+
};
|
|
4365
|
+
break;
|
|
4366
|
+
case "payment.refunded": {
|
|
4367
|
+
const refundId = payload["refundId"];
|
|
4368
|
+
if (context2.countedRefunds.has(refundId)) return view;
|
|
4369
|
+
context2.countedRefunds.add(refundId);
|
|
4370
|
+
next = { ...order, refundedMinor: order.refundedMinor + payload["amountMinor"] };
|
|
4371
|
+
break;
|
|
4372
|
+
}
|
|
4373
|
+
case "order.refunded":
|
|
4374
|
+
case "order.partially_refunded":
|
|
4375
|
+
context2.countedRefunds.add(payload["refundId"]);
|
|
4376
|
+
next = {
|
|
4377
|
+
...order,
|
|
4378
|
+
refundedMinor: order.refundedMinor + payload["amountMinor"],
|
|
4379
|
+
status: refundedStatus(
|
|
4380
|
+
order.status,
|
|
4381
|
+
name === "order.refunded" ? "refunded" : "partially_refunded"
|
|
4382
|
+
)
|
|
4383
|
+
};
|
|
4384
|
+
break;
|
|
4385
|
+
default:
|
|
4386
|
+
return view;
|
|
4387
|
+
}
|
|
4388
|
+
return {
|
|
4389
|
+
...next,
|
|
4390
|
+
payment: {
|
|
4391
|
+
...next.payment,
|
|
4392
|
+
state: paymentState3(next),
|
|
4393
|
+
capturedMinor: next.capturedMinor,
|
|
4394
|
+
refundedMinor: next.refundedMinor
|
|
4395
|
+
}
|
|
4396
|
+
};
|
|
4397
|
+
}
|
|
4398
|
+
function applyCustomer(view, row) {
|
|
4399
|
+
if (!isBaseEvent("customer", row)) return view;
|
|
4400
|
+
return toCustomerSnapshot(payloadOf(row)["customer"]);
|
|
4401
|
+
}
|
|
4402
|
+
function startFold(kind) {
|
|
4403
|
+
let view = null;
|
|
4404
|
+
const context2 = { countedRefunds: /* @__PURE__ */ new Set() };
|
|
4405
|
+
return {
|
|
4406
|
+
apply(row) {
|
|
4407
|
+
if (kind === "order") view = applyOrder(view, row, context2);
|
|
4408
|
+
else if (kind === "product") view = applyProduct(view, row);
|
|
4409
|
+
else view = applyCustomer(view, row);
|
|
4410
|
+
return view;
|
|
4411
|
+
}
|
|
4412
|
+
};
|
|
4413
|
+
}
|
|
4414
|
+
|
|
4415
|
+
// src/history/diff.ts
|
|
4416
|
+
function isPlain(value) {
|
|
4417
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
4418
|
+
}
|
|
4419
|
+
function equal(a, b) {
|
|
4420
|
+
if (a === b) return true;
|
|
4421
|
+
if (Array.isArray(a) && Array.isArray(b)) {
|
|
4422
|
+
return a.length === b.length && a.every((item, i) => equal(item, b[i]));
|
|
4423
|
+
}
|
|
4424
|
+
if (isPlain(a) && isPlain(b)) {
|
|
4425
|
+
const keys = /* @__PURE__ */ new Set([...Object.keys(a), ...Object.keys(b)]);
|
|
4426
|
+
return [...keys].every((key) => equal(a[key], b[key]));
|
|
4427
|
+
}
|
|
4428
|
+
return false;
|
|
4429
|
+
}
|
|
4430
|
+
var join3 = (path, key) => path === "" ? key : `${path}.${key}`;
|
|
4431
|
+
function keyed(items) {
|
|
4432
|
+
const byId = /* @__PURE__ */ new Map();
|
|
4433
|
+
for (const item of items) {
|
|
4434
|
+
const id2 = isPlain(item) ? item["id"] : void 0;
|
|
4435
|
+
if (typeof id2 !== "string" || byId.has(id2)) return null;
|
|
4436
|
+
byId.set(id2, item);
|
|
4437
|
+
}
|
|
4438
|
+
return byId;
|
|
4439
|
+
}
|
|
4440
|
+
function entriesOf(a, b) {
|
|
4441
|
+
const ka = keyed(a);
|
|
4442
|
+
const kb = keyed(b);
|
|
4443
|
+
if (ka !== null && kb !== null) return [ka, kb];
|
|
4444
|
+
const byIndex = (items) => new Map(items.map((item, i) => [String(i), item]));
|
|
4445
|
+
return [byIndex(a), byIndex(b)];
|
|
4446
|
+
}
|
|
4447
|
+
function diffMaps(path, a, b, out) {
|
|
4448
|
+
for (const key of /* @__PURE__ */ new Set([...a.keys(), ...b.keys()])) {
|
|
4449
|
+
const from = a.get(key);
|
|
4450
|
+
const to = b.get(key);
|
|
4451
|
+
if (from !== void 0 && to !== void 0) diffValue(join3(path, key), from, to, out);
|
|
4452
|
+
else if (!equal(from ?? null, to ?? null)) {
|
|
4453
|
+
out.push({ path: join3(path, key), from: from ?? null, to: to ?? null });
|
|
4454
|
+
}
|
|
4455
|
+
}
|
|
4456
|
+
}
|
|
4457
|
+
function diffValue(path, a, b, out) {
|
|
4458
|
+
if (isPlain(a) && isPlain(b)) {
|
|
4459
|
+
diffMaps(path, new Map(Object.entries(a)), new Map(Object.entries(b)), out);
|
|
4460
|
+
} else if (Array.isArray(a) && Array.isArray(b)) {
|
|
4461
|
+
diffMaps(path, ...entriesOf(a, b), out);
|
|
4462
|
+
} else if (!equal(a, b)) {
|
|
4463
|
+
out.push({ path, from: a ?? null, to: b ?? null });
|
|
4464
|
+
}
|
|
4465
|
+
}
|
|
4466
|
+
function diffViews(before, after) {
|
|
4467
|
+
if (before === null || after === null || isDeleted(before)) return [];
|
|
4468
|
+
if (isDeleted(after)) return [{ path: "deletedAt", from: null, to: after.deletedAt }];
|
|
4469
|
+
const out = [];
|
|
4470
|
+
diffValue("", before, after, out);
|
|
4471
|
+
return out;
|
|
4472
|
+
}
|
|
4473
|
+
|
|
4474
|
+
// src/history/read.ts
|
|
4475
|
+
var DAY_MS = 24 * 60 * 60 * 1e3;
|
|
4476
|
+
var READ_PAGE = 1e3;
|
|
4477
|
+
function createHistoryReader(deps) {
|
|
4478
|
+
const { eventLog, auditEntries: auditEntries3, retentionDays } = deps;
|
|
4479
|
+
const { store } = eventLog;
|
|
4480
|
+
async function readAll(tx, subjects) {
|
|
4481
|
+
const rows = [];
|
|
4482
|
+
for (; ; ) {
|
|
4483
|
+
const last = rows[rows.length - 1];
|
|
4484
|
+
const page = await eventLog.listBySubjects(tx, subjects, {
|
|
4485
|
+
limit: READ_PAGE,
|
|
4486
|
+
...last !== void 0 && { afterSeq: last.seq }
|
|
4487
|
+
});
|
|
4488
|
+
rows.push(...page);
|
|
4489
|
+
if (page.length < READ_PAGE) return rows;
|
|
4490
|
+
}
|
|
4491
|
+
}
|
|
4492
|
+
async function rowsOf(tx, kind, id2) {
|
|
4493
|
+
const own = await readAll(tx, [{ type: kind, id: id2 }]);
|
|
4494
|
+
if (kind !== "product") return own;
|
|
4495
|
+
const variantIds = /* @__PURE__ */ new Set();
|
|
4496
|
+
for (const row of own) {
|
|
4497
|
+
if (!isBaseEvent("product", row)) continue;
|
|
4498
|
+
const product = row.event.payload.product;
|
|
4499
|
+
for (const variant of product.variants ?? []) {
|
|
4500
|
+
if (typeof variant.id === "string") variantIds.add(variant.id);
|
|
4501
|
+
}
|
|
4502
|
+
}
|
|
4503
|
+
if (variantIds.size === 0) return own;
|
|
4504
|
+
return readAll(tx, [
|
|
4505
|
+
{ type: "product", id: id2 },
|
|
4506
|
+
...[...variantIds].map((variantId) => ({ type: "variant", id: variantId }))
|
|
4507
|
+
]);
|
|
4508
|
+
}
|
|
4509
|
+
function startOf(kind, rows) {
|
|
4510
|
+
const horizon = Date.now() - retentionDays * DAY_MS;
|
|
4511
|
+
return rows.findIndex((row) => isBaseEvent(kind, row) && row.createdAt.getTime() >= horizon);
|
|
4512
|
+
}
|
|
4513
|
+
async function actorsOf(tx, entries) {
|
|
4514
|
+
const byCorrelation = /* @__PURE__ */ new Map();
|
|
4515
|
+
for (const correlation of new Set(entries.map((e) => e.correlationId))) {
|
|
4516
|
+
const [applied] = await auditEntries3.list(tx, {
|
|
4517
|
+
correlation,
|
|
4518
|
+
outcome: "applied",
|
|
4519
|
+
order: "asc",
|
|
4520
|
+
limit: 1
|
|
4521
|
+
});
|
|
4522
|
+
byCorrelation.set(
|
|
4523
|
+
correlation,
|
|
4524
|
+
applied === void 0 ? { actor: null, command: null } : { actor: applied.actor, command: applied.command }
|
|
4525
|
+
);
|
|
4526
|
+
}
|
|
4527
|
+
for (const entry of entries) Object.assign(entry, byCorrelation.get(entry.correlationId));
|
|
4528
|
+
}
|
|
4529
|
+
return {
|
|
4530
|
+
asOf(subject, at) {
|
|
4531
|
+
return store.read(async (tx) => {
|
|
4532
|
+
const rows = await rowsOf(tx, subject.kind, subject.id);
|
|
4533
|
+
if (rows.length === 0 && !subject.live) return { kind: "not_found" };
|
|
4534
|
+
const start = startOf(subject.kind, rows);
|
|
4535
|
+
if (start < 0) return { kind: "before_start", historyStartsAt: null };
|
|
4536
|
+
const startsAt = rows[start].createdAt;
|
|
4537
|
+
if (at.getTime() < startsAt.getTime()) {
|
|
4538
|
+
return { kind: "before_start", historyStartsAt: startsAt.toISOString() };
|
|
4539
|
+
}
|
|
4540
|
+
const fold = startFold(subject.kind);
|
|
4541
|
+
let view = null;
|
|
4542
|
+
for (const row of rows.slice(start)) {
|
|
4543
|
+
if (row.createdAt.getTime() <= at.getTime()) view = fold.apply(row);
|
|
4544
|
+
}
|
|
4545
|
+
if (isDeleted(view)) return { kind: "deleted", deletedAt: view.deletedAt };
|
|
4546
|
+
return {
|
|
4547
|
+
kind: "record",
|
|
4548
|
+
read: { asOf: at.toISOString(), historyStartsAt: startsAt.toISOString(), record: view }
|
|
4549
|
+
};
|
|
4550
|
+
});
|
|
4551
|
+
},
|
|
4552
|
+
list(subject, page) {
|
|
4553
|
+
return store.read(async (tx) => {
|
|
4554
|
+
const rows = await rowsOf(tx, subject.kind, subject.id);
|
|
4555
|
+
if (rows.length === 0 && !subject.live) return null;
|
|
4556
|
+
const start = startOf(subject.kind, rows);
|
|
4557
|
+
if (start < 0)
|
|
4558
|
+
return { historyStartsAt: null, retentionDays, entries: [], nextCursor: null };
|
|
4559
|
+
const entries = [];
|
|
4560
|
+
const fold = startFold(subject.kind);
|
|
4561
|
+
let view = null;
|
|
4562
|
+
for (const [i, row] of rows.slice(start).entries()) {
|
|
4563
|
+
const before = view;
|
|
4564
|
+
view = fold.apply(row);
|
|
4565
|
+
const changes = diffViews(before, view);
|
|
4566
|
+
if (i > 0 && changes.length === 0) continue;
|
|
4567
|
+
entries.push({
|
|
4568
|
+
seq: row.seq,
|
|
4569
|
+
at: row.createdAt.toISOString(),
|
|
4570
|
+
type: row.event.type,
|
|
4571
|
+
correlationId: row.event.correlationId,
|
|
4572
|
+
actor: null,
|
|
4573
|
+
command: null,
|
|
4574
|
+
base: i === 0,
|
|
4575
|
+
changes
|
|
4576
|
+
});
|
|
4577
|
+
}
|
|
4578
|
+
const newest = entries.reverse().filter((e) => page.beforeSeq === void 0 || e.seq < page.beforeSeq);
|
|
4579
|
+
const shown = newest.slice(0, page.limit);
|
|
4580
|
+
await actorsOf(tx, shown);
|
|
4581
|
+
const last = shown[shown.length - 1];
|
|
4582
|
+
return {
|
|
4583
|
+
historyStartsAt: rows[start].createdAt.toISOString(),
|
|
4584
|
+
retentionDays,
|
|
4585
|
+
entries: shown,
|
|
4586
|
+
nextCursor: newest.length > shown.length && last !== void 0 ? String(last.seq) : null
|
|
4587
|
+
};
|
|
4588
|
+
});
|
|
4589
|
+
}
|
|
4590
|
+
};
|
|
4591
|
+
}
|
|
4592
|
+
|
|
4103
4593
|
// src/routes/admin.ts
|
|
4104
4594
|
function registerAdminRoutes(adapter, deps) {
|
|
4105
4595
|
const { config, services, repos, adapters } = deps;
|
|
4596
|
+
const history = createHistoryReader({
|
|
4597
|
+
eventLog: repos.eventLog,
|
|
4598
|
+
auditEntries: repos.auditEntry,
|
|
4599
|
+
retentionDays: config.events.retentionDays
|
|
4600
|
+
});
|
|
4106
4601
|
registerAdminMeRoute(adapter, { config });
|
|
4107
4602
|
registerAdminDashboardRoute(adapter, { repos, config });
|
|
4108
4603
|
registerAdminOrdersRoutes(adapter, {
|
|
4109
4604
|
order: services.order,
|
|
4110
4605
|
checkout: services.checkout,
|
|
4111
4606
|
refund: services.refund,
|
|
4112
|
-
repos
|
|
4607
|
+
repos,
|
|
4608
|
+
history
|
|
4609
|
+
});
|
|
4610
|
+
registerAdminProductsRoutes(adapter, {
|
|
4611
|
+
product: services.product,
|
|
4612
|
+
ai: adapters.ai,
|
|
4613
|
+
history
|
|
4113
4614
|
});
|
|
4114
|
-
registerAdminProductsRoutes(adapter, { product: services.product, ai: adapters.ai });
|
|
4115
4615
|
registerAdminInventoryRoutes(adapter, {
|
|
4116
4616
|
inventory: services.inventory,
|
|
4117
4617
|
product: services.product,
|
|
4118
4618
|
repos
|
|
4119
4619
|
});
|
|
4120
|
-
registerAdminCustomersRoutes(adapter, { order: services.order, repos });
|
|
4620
|
+
registerAdminCustomersRoutes(adapter, { order: services.order, repos, history });
|
|
4121
4621
|
registerAdminSearchRoute(adapter, {
|
|
4122
4622
|
order: services.order,
|
|
4123
4623
|
product: services.product,
|
|
@@ -4406,6 +4906,8 @@ import { PRODUCT_SORT_KEYS as PRODUCT_SORT_KEYS2 } from "@nymbalhq/types";
|
|
|
4406
4906
|
var id = z.string().min(1);
|
|
4407
4907
|
var queryValue = z.union([z.string(), z.array(z.string())]).optional();
|
|
4408
4908
|
var paging = { limit: queryValue, offset: queryValue };
|
|
4909
|
+
var asOfQuery = z.object({ at: queryValue });
|
|
4910
|
+
var historyQuery = z.object({ cursor: queryValue, limit: queryValue });
|
|
4409
4911
|
var idParams = z.object({ id });
|
|
4410
4912
|
var orderIdParams = idParams;
|
|
4411
4913
|
var variantIdParams = z.object({ variantId: id });
|
|
@@ -4655,8 +5157,15 @@ var routeSchemas = {
|
|
|
4655
5157
|
},
|
|
4656
5158
|
"GET /api/admin/orders/:orderNumber": {
|
|
4657
5159
|
name: "admin.orders.get",
|
|
4658
|
-
description: "Get one order with its status history.",
|
|
4659
|
-
params: orderNumberParams
|
|
5160
|
+
description: "Get one order with its status history; with `at`, the order as the event log folds it at that time.",
|
|
5161
|
+
params: orderNumberParams,
|
|
5162
|
+
query: asOfQuery
|
|
5163
|
+
},
|
|
5164
|
+
"GET /api/admin/orders/:id/history": {
|
|
5165
|
+
name: "admin.orders.history",
|
|
5166
|
+
description: "List an order's changes from the event log, newest first.",
|
|
5167
|
+
params: orderIdParams,
|
|
5168
|
+
query: historyQuery
|
|
4660
5169
|
},
|
|
4661
5170
|
"POST /api/admin/orders/:id/confirm": {
|
|
4662
5171
|
name: "admin.orders.confirm",
|
|
@@ -4750,6 +5259,18 @@ var routeSchemas = {
|
|
|
4750
5259
|
variants: z.array(productVariant).optional()
|
|
4751
5260
|
})
|
|
4752
5261
|
},
|
|
5262
|
+
"GET /api/admin/products/:id": {
|
|
5263
|
+
name: "admin.products.get",
|
|
5264
|
+
description: "Get one product by id or slug; with `at`, the product as the event log folds it at that time.",
|
|
5265
|
+
params: idParams,
|
|
5266
|
+
query: asOfQuery
|
|
5267
|
+
},
|
|
5268
|
+
"GET /api/admin/products/:id/history": {
|
|
5269
|
+
name: "admin.products.history",
|
|
5270
|
+
description: "List a product's changes from the event log, newest first.",
|
|
5271
|
+
params: idParams,
|
|
5272
|
+
query: historyQuery
|
|
5273
|
+
},
|
|
4753
5274
|
"PATCH /api/admin/products/:id": {
|
|
4754
5275
|
name: "admin.products.update",
|
|
4755
5276
|
command: "product.update",
|
|
@@ -4833,8 +5354,15 @@ var routeSchemas = {
|
|
|
4833
5354
|
},
|
|
4834
5355
|
"GET /api/admin/customers/:id": {
|
|
4835
5356
|
name: "admin.customers.get",
|
|
4836
|
-
description: "Get one customer with order statistics.",
|
|
4837
|
-
params: idParams
|
|
5357
|
+
description: "Get one customer with order statistics; with `at`, the customer as the event log folds it at that time.",
|
|
5358
|
+
params: idParams,
|
|
5359
|
+
query: asOfQuery
|
|
5360
|
+
},
|
|
5361
|
+
"GET /api/admin/customers/:id/history": {
|
|
5362
|
+
name: "admin.customers.history",
|
|
5363
|
+
description: "List a customer's changes from the event log, newest first.",
|
|
5364
|
+
params: idParams,
|
|
5365
|
+
query: historyQuery
|
|
4838
5366
|
},
|
|
4839
5367
|
"GET /api/admin/customers/:id/orders": {
|
|
4840
5368
|
name: "admin.customers.orders",
|
|
@@ -5007,17 +5535,17 @@ function validatedAdapter(adapter) {
|
|
|
5007
5535
|
// src/routes/admin-activity.ts
|
|
5008
5536
|
import { Readable } from "stream";
|
|
5009
5537
|
var OUTCOMES = /* @__PURE__ */ new Set(["applied", "refused", "replayed"]);
|
|
5010
|
-
var
|
|
5011
|
-
var
|
|
5538
|
+
var DEFAULT_LIMIT3 = 50;
|
|
5539
|
+
var MAX_LIMIT2 = 200;
|
|
5012
5540
|
var QueryError = class extends Error {
|
|
5013
5541
|
};
|
|
5014
|
-
function
|
|
5542
|
+
function one2(ctx, name) {
|
|
5015
5543
|
const value = ctx.query[name];
|
|
5016
5544
|
const first = Array.isArray(value) ? value[0] : value;
|
|
5017
5545
|
return first === void 0 || first === "" ? void 0 : first;
|
|
5018
5546
|
}
|
|
5019
5547
|
function time(ctx, name) {
|
|
5020
|
-
const value =
|
|
5548
|
+
const value = one2(ctx, name);
|
|
5021
5549
|
if (value === void 0) return void 0;
|
|
5022
5550
|
const at = new Date(value);
|
|
5023
5551
|
if (Number.isNaN(at.getTime())) throw new QueryError(`${name} must be an ISO 8601 time`);
|
|
@@ -5026,10 +5554,10 @@ function time(ctx, name) {
|
|
|
5026
5554
|
function filterOf(ctx, names) {
|
|
5027
5555
|
const filter = {};
|
|
5028
5556
|
for (const name of ["actor", "command", "subject", "correlation"]) {
|
|
5029
|
-
const value = names.includes(name) ?
|
|
5557
|
+
const value = names.includes(name) ? one2(ctx, name) : void 0;
|
|
5030
5558
|
if (value !== void 0) filter[name] = value;
|
|
5031
5559
|
}
|
|
5032
|
-
const outcome = names.includes("outcome") ?
|
|
5560
|
+
const outcome = names.includes("outcome") ? one2(ctx, "outcome") : void 0;
|
|
5033
5561
|
if (outcome !== void 0) {
|
|
5034
5562
|
if (!OUTCOMES.has(outcome)) throw new QueryError("outcome must be applied, refused or replayed");
|
|
5035
5563
|
filter.outcome = outcome;
|
|
@@ -5055,12 +5583,12 @@ function decodeCursor(value) {
|
|
|
5055
5583
|
throw new QueryError("cursor is not one this API issued");
|
|
5056
5584
|
}
|
|
5057
5585
|
function limitOf(ctx) {
|
|
5058
|
-
const value =
|
|
5059
|
-
if (value === void 0) return
|
|
5586
|
+
const value = one2(ctx, "limit");
|
|
5587
|
+
if (value === void 0) return DEFAULT_LIMIT3;
|
|
5060
5588
|
const n = Number(value);
|
|
5061
5589
|
if (!Number.isInteger(n) || n < 1)
|
|
5062
5590
|
throw new QueryError("limit must be a whole number of at least 1");
|
|
5063
|
-
return Math.min(n,
|
|
5591
|
+
return Math.min(n, MAX_LIMIT2);
|
|
5064
5592
|
}
|
|
5065
5593
|
function answerError(err) {
|
|
5066
5594
|
return err instanceof QueryError ? fail("activity.invalid", err.message, 400) : renderError(err);
|
|
@@ -5075,7 +5603,7 @@ function registerAdminActivityRoutes(adapter, deps) {
|
|
|
5075
5603
|
try {
|
|
5076
5604
|
const filter = filterOf(ctx, ["actor", "command", "subject", "correlation", "outcome"]);
|
|
5077
5605
|
const limit = limitOf(ctx);
|
|
5078
|
-
const cursor = decodeCursor(
|
|
5606
|
+
const cursor = decodeCursor(one2(ctx, "cursor"));
|
|
5079
5607
|
const rows = await store.read(
|
|
5080
5608
|
(tx) => auditEntries3.list(tx, {
|
|
5081
5609
|
...filter,
|
|
@@ -5169,15 +5697,15 @@ function auditedAdapter(adapter, store) {
|
|
|
5169
5697
|
(ctx) => {
|
|
5170
5698
|
const actor = actorOf(ctx.auth);
|
|
5171
5699
|
return runAsActor(actor, async () => {
|
|
5172
|
-
const
|
|
5173
|
-
if ("malformed" in
|
|
5700
|
+
const keyed2 = adminWrite ? idempotencyKeyOf(ctx) : { key: void 0 };
|
|
5701
|
+
if ("malformed" in keyed2) return malformedKey();
|
|
5174
5702
|
if (!command) return handler(ctx);
|
|
5175
5703
|
const run = async () => handler(ctx);
|
|
5176
|
-
if (
|
|
5704
|
+
if (keyed2.key === void 0) return auditedRoute(store, command, run);
|
|
5177
5705
|
return idempotentCommand(
|
|
5178
5706
|
store,
|
|
5179
5707
|
command,
|
|
5180
|
-
{ actor, key:
|
|
5708
|
+
{ actor, key: keyed2.key, hash: requestHash(ctx), provider },
|
|
5181
5709
|
run
|
|
5182
5710
|
);
|
|
5183
5711
|
});
|
|
@@ -5324,9 +5852,10 @@ export {
|
|
|
5324
5852
|
listStoredSettings,
|
|
5325
5853
|
settingValues,
|
|
5326
5854
|
loadBootSettings,
|
|
5855
|
+
toCustomerSnapshot,
|
|
5327
5856
|
registerAdminStaticRoute,
|
|
5328
5857
|
inOrderScope,
|
|
5329
5858
|
routeSchemas,
|
|
5330
5859
|
registerAllRoutes
|
|
5331
5860
|
};
|
|
5332
|
-
//# sourceMappingURL=chunk-
|
|
5861
|
+
//# sourceMappingURL=chunk-2PLYK5RU.js.map
|