@palbase/backend 18.0.1 → 20.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bin/palbase-backend.cjs +36 -17
- package/dist/bin/palbase-backend.cjs.map +1 -1
- package/dist/bin/palbase-backend.js +1 -1
- package/dist/{chunk-VYH4U7ZQ.js → chunk-PFQJYW6C.js} +37 -18
- package/dist/chunk-PFQJYW6C.js.map +1 -0
- package/dist/engine/index.cjs +36 -17
- package/dist/engine/index.cjs.map +1 -1
- package/dist/engine/index.d.cts +1 -1
- package/dist/engine/index.d.ts +1 -1
- package/dist/engine/index.js +1 -1
- package/dist/{index-DZDUMth5.d.ts → index-BeHLq2i-.d.ts} +5 -0
- package/dist/{index-B46CGNvx.d.cts → index-Br9P7yRu.d.cts} +5 -0
- package/dist/index.cjs +189 -129
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +190 -121
- package/dist/index.d.ts +190 -121
- package/dist/index.js +178 -121
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/template/package.json +1 -1
- package/dist/chunk-VYH4U7ZQ.js.map +0 -1
|
@@ -1330,7 +1330,7 @@ function renderPath(template, tokens) {
|
|
|
1330
1330
|
return template.replaceAll("{userId}", sanitizeSegment(tokens.userId ?? "anonymous")).replaceAll("{uploadId}", sanitizeSegment(tokens.uploadId)).replaceAll("{filename}", sanitizeSegment(tokens.filename ?? "file"));
|
|
1331
1331
|
}
|
|
1332
1332
|
function sanitizeSegment(raw) {
|
|
1333
|
-
const cleaned = raw.replace(/[
|
|
1333
|
+
const cleaned = raw.replace(/[\x00-\x1F\x7F]/g, "").replace(/[/\\]/g, "-").replace(/\.{2,}/g, ".").replace(/^\.+/, "").trim();
|
|
1334
1334
|
return cleaned === "" ? "file" : cleaned.slice(0, 200);
|
|
1335
1335
|
}
|
|
1336
1336
|
function grantFor(entry, ctx, bucketLimits) {
|
|
@@ -1428,6 +1428,39 @@ async function createApp(opts) {
|
|
|
1428
1428
|
const requestALS = opts.runtimeHooks?.__requestALS ?? __requestALS;
|
|
1429
1429
|
const uploadSecret = config.uploadSecret ?? "";
|
|
1430
1430
|
const completions = new CompletionLedger();
|
|
1431
|
+
function buildServices(db) {
|
|
1432
|
+
return {
|
|
1433
|
+
Database: db.client,
|
|
1434
|
+
Cache: cache,
|
|
1435
|
+
Log: log,
|
|
1436
|
+
Documents: modules.Documents ?? stubModule("Documents"),
|
|
1437
|
+
Storage: modules.Storage ?? stubModule("Storage"),
|
|
1438
|
+
Notifications: modules.Notifications ?? stubModule("Notifications"),
|
|
1439
|
+
Flags: modules.Flags ?? stubModule("Flags"),
|
|
1440
|
+
Realtime: modules.Realtime ?? stubModule("Realtime"),
|
|
1441
|
+
Purchases: modules.Purchases ?? stubModule("Purchases"),
|
|
1442
|
+
// Named, never undefined. A backend started without a secrets client
|
|
1443
|
+
// that returned `undefined` here would fail inside the handler as
|
|
1444
|
+
// "Cannot read properties of undefined", which says nothing about what
|
|
1445
|
+
// to configure — the stub says the name and the variable.
|
|
1446
|
+
Secrets: modules.Secrets ?? stubModule("Secrets")
|
|
1447
|
+
};
|
|
1448
|
+
}
|
|
1449
|
+
async function runInServiceScope(fn) {
|
|
1450
|
+
const db = createRequestDatabase(sql, {
|
|
1451
|
+
role: config.dbRole,
|
|
1452
|
+
serviceRole: config.dbServiceRole,
|
|
1453
|
+
claimsJson: "{}"
|
|
1454
|
+
});
|
|
1455
|
+
try {
|
|
1456
|
+
const out = await runWithRuntime(buildServices(db), fn);
|
|
1457
|
+
await db.commit();
|
|
1458
|
+
return out;
|
|
1459
|
+
} catch (err) {
|
|
1460
|
+
await db.rollback(err);
|
|
1461
|
+
throw err;
|
|
1462
|
+
}
|
|
1463
|
+
}
|
|
1431
1464
|
async function handleAuthorize(req, requestId) {
|
|
1432
1465
|
if (uploadSecret === "" || !verifySignature(req.headers.get(SIGNATURE_HEADER) ?? "", uploadSecret)) {
|
|
1433
1466
|
return envelope("unauthorized", "This endpoint is not callable directly", 401, requestId);
|
|
@@ -1594,22 +1627,7 @@ async function createApp(opts) {
|
|
|
1594
1627
|
claimsJson: JSON.stringify(claims ?? {})
|
|
1595
1628
|
});
|
|
1596
1629
|
try {
|
|
1597
|
-
const services =
|
|
1598
|
-
Database: db.client,
|
|
1599
|
-
Cache: cache,
|
|
1600
|
-
Log: log,
|
|
1601
|
-
Documents: modules.Documents ?? stubModule("Documents"),
|
|
1602
|
-
Storage: modules.Storage ?? stubModule("Storage"),
|
|
1603
|
-
Notifications: modules.Notifications ?? stubModule("Notifications"),
|
|
1604
|
-
Flags: modules.Flags ?? stubModule("Flags"),
|
|
1605
|
-
Realtime: modules.Realtime ?? stubModule("Realtime"),
|
|
1606
|
-
Purchases: modules.Purchases ?? stubModule("Purchases"),
|
|
1607
|
-
// Named, never undefined. A backend started without a secrets client
|
|
1608
|
-
// that returned `undefined` here would fail inside the handler as
|
|
1609
|
-
// "Cannot read properties of undefined", which says nothing about what
|
|
1610
|
-
// to configure — the stub says the name and the variable.
|
|
1611
|
-
Secrets: modules.Secrets ?? stubModule("Secrets")
|
|
1612
|
-
};
|
|
1630
|
+
const services = buildServices(db);
|
|
1613
1631
|
const result = await runWithRuntime(services, () => {
|
|
1614
1632
|
const box = requestALS.getStore();
|
|
1615
1633
|
if (box) {
|
|
@@ -1672,6 +1690,7 @@ async function createApp(opts) {
|
|
|
1672
1690
|
handle,
|
|
1673
1691
|
routes,
|
|
1674
1692
|
config,
|
|
1693
|
+
runInServiceScope,
|
|
1675
1694
|
async shutdown() {
|
|
1676
1695
|
const closable = sql;
|
|
1677
1696
|
await closable.close?.();
|