headroom-cms 0.1.11 → 0.2.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/admin/.well-known/headroom.json +9 -0
- package/admin/assets/{AdminsPage-BnzH9TL3.js → AdminsPage-DUMTsCEp.js} +1 -1
- package/admin/assets/{AllContentPage-BtObN6oy.js → AllContentPage-D5ey5AOV.js} +1 -1
- package/admin/assets/{ApiKeysPage-DEAa8eyC.js → ApiKeysPage-CzUOSoz_.js} +1 -1
- package/admin/assets/{AuditPage-BN9yNsxh.js → AuditPage-CYAg4dbI.js} +1 -1
- package/admin/assets/BackupsPage-04_oMy3v.js +1 -0
- package/admin/assets/{BlockEditor-3wnisTOZ.js → BlockEditor-s0CRZsjy.js} +3 -3
- package/admin/assets/BlockTypeEditPage-D1OFIlJZ.js +1 -0
- package/admin/assets/{BlockTypesPage-Dhkho6T_.js → BlockTypesPage-cJNR25fN.js} +1 -1
- package/admin/assets/{BulkActionBar-BxdfUSrN.js → BulkActionBar-BWysX7Wo.js} +1 -1
- package/admin/assets/{CollectionEditPage-lOb4hEZy.js → CollectionEditPage-DRmCA_73.js} +1 -1
- package/admin/assets/{CollectionsPage-CgtOloa1.js → CollectionsPage-CeQB5e9u.js} +1 -1
- package/admin/assets/{ContentCreatePage-LeQjahp_.js → ContentCreatePage-Cq8Pi8EF.js} +1 -1
- package/admin/assets/ContentEditPage-CEJ7I3WH.js +1 -0
- package/admin/assets/{ContentField-pilCbdnA.js → ContentField-BZT4OUfI.js} +1 -1
- package/admin/assets/ContentListPage-BCEQrYVs.js +1 -0
- package/admin/assets/{CustomBlockPreview-DNnTFM0z.js → CustomBlockPreview-Kc6bb3oq.js} +1 -1
- package/admin/assets/FieldRenderer-CT-DgCbC.js +2 -0
- package/admin/assets/FileTypeIcon-CNHtffHC.js +1 -0
- package/admin/assets/FloatingComposerController-D4uLQfUX-0_Y8mkGU.js +1 -0
- package/admin/assets/{IconPicker-CpIgiQTC.js → IconPicker-BpPlHJO0.js} +2 -2
- package/admin/assets/{LoginPage-D9ZsGLIi.js → LoginPage-Dya8sF_P.js} +1 -1
- package/admin/assets/MediaField-C3qFf3g5.js +1 -0
- package/admin/assets/MediaPage-BNxc0wLq.js +1 -0
- package/admin/assets/{Pagination-Df9nQ7Z0.js → Pagination-Dx8h11Rn.js} +1 -1
- package/admin/assets/{RelationshipPicker-B3Ftmqxp.js → RelationshipPicker-C2MTxrhl.js} +1 -1
- package/admin/assets/{SiteSettingsPage-6NvH7CiQ.js → SiteSettingsPage-BDZaUBmf.js} +1 -1
- package/admin/assets/{SiteUserEditPage-D5VaQ1Xq.js → SiteUserEditPage-MfzhPW7v.js} +1 -1
- package/admin/assets/{SiteUsersPage-BYVduiqs.js → SiteUsersPage-CrYugXpx.js} +1 -1
- package/admin/assets/{SitesPage-rfWWE0yK.js → SitesPage-Cl8V3Hb7.js} +1 -1
- package/admin/assets/SubmissionDetailPage-BnVlsGb-.js +1 -0
- package/admin/assets/SubmissionEditPage-B0Kq52fb.js +1 -0
- package/admin/assets/SubmissionListPage-K665VwMp.js +1 -0
- package/admin/assets/{TagInput-57c4DG1w.js → TagInput-C6tcB5Xw.js} +1 -1
- package/admin/assets/{TagsPage-BEO5AwCv.js → TagsPage-BONR6bSu.js} +1 -1
- package/admin/assets/{UsersPage-BpIRorJ1.js → UsersPage-C2iCy0UR.js} +1 -1
- package/admin/assets/{WebhookEditPage-D5xgi56h.js → WebhookEditPage-DjZFxT72.js} +1 -1
- package/admin/assets/{WebhooksPage-BY7AaiGr.js → WebhooksPage-g_a224a4.js} +1 -1
- package/admin/assets/{card-C9hfyHXf.js → card-DlfsF8lU.js} +1 -1
- package/admin/assets/{checkbox-DVJcwUt1.js → checkbox-BX8EcGFf.js} +1 -1
- package/admin/assets/{command-Bfmj0MEL.js → command-DaTsImUa.js} +1 -1
- package/admin/assets/{contentStatus-CkPi9Dh6.js → contentStatus-WXGfd7vX.js} +1 -1
- package/admin/assets/format-BRcflvs9.js +1 -0
- package/admin/assets/index-9sbb3-yI.css +1 -0
- package/admin/assets/{index-Ce5pmRMj.js → index-DC1UyCW2.js} +10 -10
- package/admin/assets/listCellValue-CBqXAwce.js +1 -0
- package/admin/assets/{popover-CzaQYEEP.js → popover-BA-47SRI.js} +1 -1
- package/admin/assets/{select-CrRhFGIi.js → select-waaVyoQ5.js} +1 -1
- package/admin/assets/{serializeToText-2VrsuRUh.js → serializeToText-CjHhyvXp.js} +1 -1
- package/admin/assets/{table-_3bMY0_z.js → table-Br-QgtTL.js} +1 -1
- package/admin/assets/{textarea-6fq0R6VV.js → textarea-BILv1DQB.js} +1 -1
- package/admin/assets/useAdminResolver-CbDzGoDp.js +1 -0
- package/admin/assets/useContent-Bp4f9qe0.js +1 -0
- package/admin/assets/{useContentSearch-B3aTjuCu.js → useContentSearch-DbiA8aG-.js} +1 -1
- package/admin/assets/{usePageTitle-C1r1-C00.js → usePageTitle-DOEFrHbj.js} +1 -1
- package/admin/assets/{useSiteUsers-DIaqgNSp.js → useSiteUsers-BFYAbJNT.js} +1 -1
- package/admin/assets/{useTags-B-HgMVwo.js → useTags-DJlXwDyc.js} +1 -1
- package/admin/assets/{useWebhooks-BvZjUJkJ.js → useWebhooks-BkpJKNLN.js} +1 -1
- package/admin/index.html +2 -2
- package/admin/sw.js +1 -1
- package/admin/workbox-362996ec.js +1 -0
- package/dist/admin-site.d.ts.map +1 -1
- package/dist/admin-site.js +46 -3
- package/dist/admin-site.js.map +1 -1
- package/dist/api.d.ts +2 -0
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js +57 -5
- package/dist/api.js.map +1 -1
- package/dist/backup.d.ts +29 -0
- package/dist/backup.d.ts.map +1 -0
- package/dist/backup.js +95 -0
- package/dist/backup.js.map +1 -0
- package/dist/cdn-api.d.ts.map +1 -1
- package/dist/cdn-api.js +20 -19
- package/dist/cdn-api.js.map +1 -1
- package/dist/image.d.ts +8 -1
- package/dist/image.d.ts.map +1 -1
- package/dist/image.js +26 -6
- package/dist/image.js.map +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +33 -1
- package/dist/index.js.map +1 -1
- package/dist/storage.d.ts +1 -0
- package/dist/storage.d.ts.map +1 -1
- package/dist/storage.js +21 -0
- package/dist/storage.js.map +1 -1
- package/dist/webhooks.d.ts +4 -3
- package/dist/webhooks.d.ts.map +1 -1
- package/dist/webhooks.js +22 -35
- package/dist/webhooks.js.map +1 -1
- package/lambda/api/bootstrap +0 -0
- package/lambda/backup-worker/bootstrap +0 -0
- package/lambda/image-lambda/index.mjs +30 -6
- package/lambda/image-lambda/node_modules/.package-lock.json +3 -3
- package/lambda/image-lambda/node_modules/semver/classes/range.js +7 -0
- package/lambda/image-lambda/node_modules/semver/package.json +1 -1
- package/lambda/image-lambda/node_modules/semver/ranges/subset.js +2 -2
- package/lambda/webhook-worker/bootstrap +0 -0
- package/package.json +1 -1
- package/src/admin-site.ts +46 -3
- package/src/api.ts +58 -5
- package/src/backup.ts +114 -0
- package/src/cdn-api.ts +20 -22
- package/src/image.ts +30 -6
- package/src/index.ts +37 -1
- package/src/sst-env.d.ts +4 -0
- package/src/storage.ts +22 -0
- package/src/webhooks.ts +22 -39
- package/admin/assets/BlockTypeEditPage-C2evAESK.js +0 -1
- package/admin/assets/ContentEditPage-xczr4d_h.js +0 -1
- package/admin/assets/ContentListPage-BAKDn1Xy.js +0 -1
- package/admin/assets/FieldRenderer-DiOKvkWV.js +0 -2
- package/admin/assets/FilterBar-BZoa63zh.js +0 -1
- package/admin/assets/FloatingComposerController-D4uLQfUX-BMIvFCoE.js +0 -1
- package/admin/assets/MediaField-CxccCFGQ.js +0 -1
- package/admin/assets/MediaPage-QvMaH2YJ.js +0 -1
- package/admin/assets/SubmissionDetailPage-BSUR685F.js +0 -1
- package/admin/assets/SubmissionEditPage-DjLXHjWU.js +0 -1
- package/admin/assets/SubmissionListPage-DBxNEvde.js +0 -1
- package/admin/assets/format-C88SDH8g.js +0 -1
- package/admin/assets/index-BB9Syqw2.css +0 -1
- package/admin/assets/useAdminResolver-BJNPz3OG.js +0 -1
- package/admin/assets/useContent-Bs7nel7C.js +0 -1
- package/admin/assets/useMedia-ae3s_ajC.js +0 -1
- package/admin/workbox-7d58179f.js +0 -1
package/dist/webhooks.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Webhook Infrastructure
|
|
3
3
|
*
|
|
4
|
-
* 2 DynamoDB tables +
|
|
5
|
-
*
|
|
4
|
+
* 2 DynamoDB tables + webhook worker Lambda (async-invoked by the API) + DLQ
|
|
5
|
+
* (Lambda async on-failure destination). The API directly invokes the worker
|
|
6
|
+
* via lambda:InvokeFunction; there is no SQS queue between them.
|
|
6
7
|
*/
|
|
7
8
|
import path from "path";
|
|
8
9
|
export function createWebhooks(name, args) {
|
|
@@ -21,6 +22,9 @@ export function createWebhooks(name, args) {
|
|
|
21
22
|
primaryIndex: { hashKey: "pk", rangeKey: "sk" },
|
|
22
23
|
ttl: "ttl",
|
|
23
24
|
});
|
|
25
|
+
// DLQ retained as Lambda async OnFailure destination. Lambda writes a
|
|
26
|
+
// failure envelope (not the original payload verbatim) when retries are
|
|
27
|
+
// exhausted. No consumer polls this queue — it's a sink only.
|
|
24
28
|
const webhookDeliveryDLQ = new sst.aws.Queue(`${name}WebhookDeliveryDLQ`, {
|
|
25
29
|
transform: {
|
|
26
30
|
queue: (queueArgs) => {
|
|
@@ -28,22 +32,6 @@ export function createWebhooks(name, args) {
|
|
|
28
32
|
},
|
|
29
33
|
},
|
|
30
34
|
});
|
|
31
|
-
const webhookDeliveryQueue = new sst.aws.Queue(`${name}WebhookDeliveryQueue`, {
|
|
32
|
-
dlq: {
|
|
33
|
-
queue: webhookDeliveryDLQ.arn,
|
|
34
|
-
retry: 5,
|
|
35
|
-
},
|
|
36
|
-
transform: {
|
|
37
|
-
queue: (queueArgs) => {
|
|
38
|
-
queueArgs.visibilityTimeoutSeconds = 60;
|
|
39
|
-
queueArgs.messageRetentionSeconds = 4 * 24 * 60 * 60; // 4 days
|
|
40
|
-
},
|
|
41
|
-
},
|
|
42
|
-
});
|
|
43
|
-
// Webhook worker Lambda: processes SQS messages and delivers webhooks.
|
|
44
|
-
// Note: We use a manual Function + EventSourceMapping instead of
|
|
45
|
-
// queue.subscribe() to avoid a duplicate LambdaEncryptionKey issue
|
|
46
|
-
// caused by SST's dynamic import creating a separate Function class instance.
|
|
47
35
|
const workerConfig = args.dev
|
|
48
36
|
? {
|
|
49
37
|
handler: args.dev.handler,
|
|
@@ -61,30 +49,29 @@ export function createWebhooks(name, args) {
|
|
|
61
49
|
timeout: "30 seconds",
|
|
62
50
|
environment: {
|
|
63
51
|
WEBHOOK_DELIVERIES_TABLE: webhookDeliveries.name,
|
|
64
|
-
WEBHOOKS_TABLE: webhooks.name,
|
|
65
|
-
SITES_TABLE: args.sites.name,
|
|
66
52
|
},
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
"sqs:GetQueueAttributes",
|
|
74
|
-
],
|
|
75
|
-
resources: [webhookDeliveryQueue.arn],
|
|
76
|
-
},
|
|
77
|
-
],
|
|
53
|
+
// webhookDeliveryDLQ is linked so SST auto-grants sqs:SendMessage on the
|
|
54
|
+
// worker's execution role. Lambda async OnFailure delivery uses the
|
|
55
|
+
// function's own role to write the failure envelope to the DLQ — without
|
|
56
|
+
// this grant, AWS accepts the FunctionEventInvokeConfig at deploy time but
|
|
57
|
+
// silently drops failure envelopes at runtime.
|
|
58
|
+
link: [webhookDeliveries, webhookDeliveryDLQ],
|
|
78
59
|
});
|
|
79
|
-
|
|
80
|
-
|
|
60
|
+
// Lambda async retry + DLQ on terminal failure. MaximumRetryAttempts is
|
|
61
|
+
// 0–2 (industry standard for webhook delivery — Stripe/GitHub publish
|
|
62
|
+
// similar caps). Total attempts = initial + 2 retries = 3.
|
|
63
|
+
new aws.lambda.FunctionEventInvokeConfig(`${name}WebhookWorkerAsyncConfig`, {
|
|
81
64
|
functionName: webhookWorker.name,
|
|
82
|
-
|
|
65
|
+
maximumRetryAttempts: 2,
|
|
66
|
+
maximumEventAgeInSeconds: 6 * 60 * 60, // 6 hours
|
|
67
|
+
destinationConfig: {
|
|
68
|
+
onFailure: { destination: webhookDeliveryDLQ.arn },
|
|
69
|
+
},
|
|
83
70
|
});
|
|
84
71
|
return {
|
|
85
72
|
webhooks,
|
|
86
73
|
webhookDeliveries,
|
|
87
|
-
|
|
74
|
+
webhookWorker,
|
|
88
75
|
webhookDeliveryDLQ,
|
|
89
76
|
};
|
|
90
77
|
}
|
package/dist/webhooks.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"webhooks.js","sourceRoot":"","sources":["../src/webhooks.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"webhooks.js","sourceRoot":"","sources":["../src/webhooks.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,IAAI,MAAM,MAAM,CAAC;AAYxB,MAAM,UAAU,cAAc,CAAC,IAAY,EAAE,IAAiB;IAC5D,MAAM,QAAQ,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG,IAAI,UAAU,EAAE;QACrD,MAAM,EAAE;YACN,EAAE,EAAE,QAAQ;YACZ,EAAE,EAAE,QAAQ;SACb;QACD,YAAY,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE;KAChD,CAAC,CAAC;IAEH,MAAM,iBAAiB,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG,IAAI,mBAAmB,EAAE;QACvE,MAAM,EAAE;YACN,EAAE,EAAE,QAAQ;YACZ,EAAE,EAAE,QAAQ;SACb;QACD,YAAY,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE;QAC/C,GAAG,EAAE,KAAK;KACX,CAAC,CAAC;IAEH,sEAAsE;IACtE,wEAAwE;IACxE,8DAA8D;IAC9D,MAAM,kBAAkB,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,IAAI,oBAAoB,EAAE;QACxE,SAAS,EAAE;YACT,KAAK,EAAE,CAAC,SAAc,EAAE,EAAE;gBACxB,SAAS,CAAC,uBAAuB,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,CAAC,UAAU;YACnE,CAAC;SACF;KACF,CAAC,CAAC;IAEH,MAAM,YAAY,GAAG,IAAI,CAAC,GAAG;QAC3B,CAAC,CAAC;YACE,OAAO,EAAE,IAAI,CAAC,GAAG,CAAC,OAAO;YACzB,OAAO,EAAE,IAAa;SACvB;QACH,CAAC,CAAC;YACE,MAAM,EAAE,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,uBAAuB,CAAC;YACxD,OAAO,EAAE,WAAW;YACpB,OAAO,EAAE,iBAA0B;YACnC,YAAY,EAAE,OAAgB;SAC/B,CAAC;IAEN,MAAM,aAAa,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,QAAQ,CAAC,GAAG,IAAI,eAAe,EAAE;QACjE,GAAG,YAAY;QACf,MAAM,EAAE,QAAQ;QAChB,OAAO,EAAE,YAAY;QACrB,WAAW,EAAE;YACX,wBAAwB,EAAE,iBAAiB,CAAC,IAAI;SACjD;QACD,yEAAyE;QACzE,oEAAoE;QACpE,yEAAyE;QACzE,2EAA2E;QAC3E,+CAA+C;QAC/C,IAAI,EAAE,CAAC,iBAAiB,EAAE,kBAAkB,CAAC;KAC9C,CAAC,CAAC;IAEH,wEAAwE;IACxE,sEAAsE;IACtE,2DAA2D;IAC3D,IAAI,GAAG,CAAC,MAAM,CAAC,yBAAyB,CAAC,GAAG,IAAI,0BAA0B,EAAE;QAC1E,YAAY,EAAE,aAAa,CAAC,IAAI;QAChC,oBAAoB,EAAE,CAAC;QACvB,wBAAwB,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,UAAU;QACjD,iBAAiB,EAAE;YACjB,SAAS,EAAE,EAAE,WAAW,EAAE,kBAAkB,CAAC,GAAG,EAAE;SACnD;KACF,CAAC,CAAC;IAEH,OAAO;QACL,QAAQ;QACR,iBAAiB;QACjB,aAAa;QACb,kBAAkB;KACnB,CAAC;AACJ,CAAC"}
|
package/lambda/api/bootstrap
CHANGED
|
Binary file
|
|
Binary file
|
|
@@ -4,7 +4,17 @@ import { S3Client, GetObjectCommand, PutObjectCommand } from "@aws-sdk/client-s3
|
|
|
4
4
|
import { createHmac, timingSafeEqual } from "crypto";
|
|
5
5
|
var s3 = new S3Client({});
|
|
6
6
|
var BUCKET = process.env.CONTENT_BUCKET;
|
|
7
|
-
var
|
|
7
|
+
var MASTER_SECRET = process.env.IMAGE_SIGNING_MASTER_SECRET;
|
|
8
|
+
var MASTER_SECRET_OLD = process.env.IMAGE_SIGNING_MASTER_SECRET_OLD;
|
|
9
|
+
var _timingSafeEqualCallCount = { count: 0 };
|
|
10
|
+
function _timingSafeEqual(a, b) {
|
|
11
|
+
_timingSafeEqualCallCount.count++;
|
|
12
|
+
return timingSafeEqual(a, b);
|
|
13
|
+
}
|
|
14
|
+
function deriveSiteSecret(master, siteHost) {
|
|
15
|
+
if (!master) return null;
|
|
16
|
+
return createHmac("sha256", master).update(siteHost).digest("hex").substring(0, 32);
|
|
17
|
+
}
|
|
8
18
|
var MAX_WIDTH = 2048;
|
|
9
19
|
var MAX_HEIGHT = 2048;
|
|
10
20
|
var MAX_PIXELS = 4e6;
|
|
@@ -31,6 +41,11 @@ async function handler(event) {
|
|
|
31
41
|
if (!match) {
|
|
32
42
|
return { statusCode: 400, body: "Invalid image path" };
|
|
33
43
|
}
|
|
44
|
+
const [, site, mediaId, ext] = match;
|
|
45
|
+
const sitePrimary = deriveSiteSecret(MASTER_SECRET, site);
|
|
46
|
+
if (!sitePrimary) {
|
|
47
|
+
return { statusCode: 503, body: "Image transforms not configured" };
|
|
48
|
+
}
|
|
34
49
|
const params = new URLSearchParams(rawQuery);
|
|
35
50
|
const sig = params.get("sig");
|
|
36
51
|
if (!sig) {
|
|
@@ -44,11 +59,18 @@ async function handler(event) {
|
|
|
44
59
|
if (!hasTransform) {
|
|
45
60
|
return { statusCode: 400, body: "No transform requested. Use /media/ path for originals." };
|
|
46
61
|
}
|
|
47
|
-
const
|
|
48
|
-
|
|
62
|
+
const siteOld = deriveSiteSecret(MASTER_SECRET_OLD, site);
|
|
63
|
+
const sigBuf = Buffer.from(sig);
|
|
64
|
+
const expectedPrimary = computeSignature(rawPath, params, sitePrimary);
|
|
65
|
+
const primaryMatch = _timingSafeEqual(sigBuf, Buffer.from(expectedPrimary));
|
|
66
|
+
let oldMatch = false;
|
|
67
|
+
if (siteOld) {
|
|
68
|
+
const expectedOld = computeSignature(rawPath, params, siteOld);
|
|
69
|
+
oldMatch = _timingSafeEqual(sigBuf, Buffer.from(expectedOld));
|
|
70
|
+
}
|
|
71
|
+
if (!primaryMatch && !oldMatch) {
|
|
49
72
|
return { statusCode: 403, body: "Invalid signature" };
|
|
50
73
|
}
|
|
51
|
-
const [, site, mediaId, ext] = match;
|
|
52
74
|
const s3Key = `sites/${site}/media/${mediaId}/original${ext}`;
|
|
53
75
|
const w = clamp(parseInt(params.get("w")) || null, 1, MAX_WIDTH);
|
|
54
76
|
const h = clamp(parseInt(params.get("h")) || null, 1, MAX_HEIGHT);
|
|
@@ -139,11 +161,11 @@ async function handler(event) {
|
|
|
139
161
|
return { statusCode: 500, body: "Image processing failed" };
|
|
140
162
|
}
|
|
141
163
|
}
|
|
142
|
-
function computeSignature(path, params) {
|
|
164
|
+
function computeSignature(path, params, key) {
|
|
143
165
|
const sorted = new URLSearchParams([...params.entries()].sort());
|
|
144
166
|
const qs = sorted.toString();
|
|
145
167
|
const canonical = qs ? `${path}?${qs}` : path;
|
|
146
|
-
return createHmac("sha256",
|
|
168
|
+
return createHmac("sha256", key).update(canonical).digest("hex").substring(0, 32);
|
|
147
169
|
}
|
|
148
170
|
function clamp(val, min, max) {
|
|
149
171
|
if (val == null) return null;
|
|
@@ -180,8 +202,10 @@ export {
|
|
|
180
202
|
MAX_WIDTH,
|
|
181
203
|
PATH_REGEX,
|
|
182
204
|
SHARP_MIME_TYPES,
|
|
205
|
+
_timingSafeEqualCallCount,
|
|
183
206
|
clamp,
|
|
184
207
|
computeSignature,
|
|
208
|
+
deriveSiteSecret,
|
|
185
209
|
extToFormat,
|
|
186
210
|
formatToMime,
|
|
187
211
|
handler
|
|
@@ -97,9 +97,9 @@
|
|
|
97
97
|
"license": "MIT"
|
|
98
98
|
},
|
|
99
99
|
"node_modules/semver": {
|
|
100
|
-
"version": "7.8.
|
|
101
|
-
"resolved": "https://registry.npmjs.org/semver/-/semver-7.8.
|
|
102
|
-
"integrity": "sha512-
|
|
100
|
+
"version": "7.8.1",
|
|
101
|
+
"resolved": "https://registry.npmjs.org/semver/-/semver-7.8.1.tgz",
|
|
102
|
+
"integrity": "sha512-rkVq3IXh+4FDGch+KwzX3aV9W3kO54GyEgpvBzSyctDA6Xtd7RJQV1xmXbeQp5v7+VzLOfVqiutSE6GICgPFvg==",
|
|
103
103
|
"license": "ISC",
|
|
104
104
|
"bin": {
|
|
105
105
|
"semver": "bin/semver.js"
|
|
@@ -98,6 +98,9 @@ class Range {
|
|
|
98
98
|
}
|
|
99
99
|
|
|
100
100
|
parseRange (range) {
|
|
101
|
+
// strip build metadata so it can't bleed into the version
|
|
102
|
+
range = range.replace(BUILDSTRIPRE, '')
|
|
103
|
+
|
|
101
104
|
// memoize range parsing for performance.
|
|
102
105
|
// this is a very hot path, and fully deterministic.
|
|
103
106
|
const memoOpts =
|
|
@@ -223,6 +226,7 @@ const debug = require('../internal/debug')
|
|
|
223
226
|
const SemVer = require('./semver')
|
|
224
227
|
const {
|
|
225
228
|
safeRe: re,
|
|
229
|
+
src,
|
|
226
230
|
t,
|
|
227
231
|
comparatorTrimReplace,
|
|
228
232
|
tildeTrimReplace,
|
|
@@ -230,6 +234,9 @@ const {
|
|
|
230
234
|
} = require('../internal/re')
|
|
231
235
|
const { FLAG_INCLUDE_PRERELEASE, FLAG_LOOSE } = require('../internal/constants')
|
|
232
236
|
|
|
237
|
+
// unbounded global build-metadata stripper used by parseRange
|
|
238
|
+
const BUILDSTRIPRE = new RegExp(src[t.BUILD], 'g')
|
|
239
|
+
|
|
233
240
|
const isNullSet = c => c.value === '<0.0.0-0'
|
|
234
241
|
const isAny = c => c.value === ''
|
|
235
242
|
|
|
@@ -174,7 +174,7 @@ const simpleSubset = (sub, dom, options) => {
|
|
|
174
174
|
if (higher === c && higher !== gt) {
|
|
175
175
|
return false
|
|
176
176
|
}
|
|
177
|
-
} else if (gt.operator === '>=' && !
|
|
177
|
+
} else if (gt.operator === '>=' && !c.test(gt.semver)) {
|
|
178
178
|
return false
|
|
179
179
|
}
|
|
180
180
|
}
|
|
@@ -192,7 +192,7 @@ const simpleSubset = (sub, dom, options) => {
|
|
|
192
192
|
if (lower === c && lower !== lt) {
|
|
193
193
|
return false
|
|
194
194
|
}
|
|
195
|
-
} else if (lt.operator === '<=' && !
|
|
195
|
+
} else if (lt.operator === '<=' && !c.test(lt.semver)) {
|
|
196
196
|
return false
|
|
197
197
|
}
|
|
198
198
|
}
|
|
Binary file
|
package/package.json
CHANGED
package/src/admin-site.ts
CHANGED
|
@@ -55,7 +55,18 @@ export function createAdminSite(name: string, args: AdminSiteArgs) {
|
|
|
55
55
|
: undefined;
|
|
56
56
|
|
|
57
57
|
if (args.dev) {
|
|
58
|
-
// Dev mode: standard StaticSite with Vite build
|
|
58
|
+
// Dev mode: standard StaticSite with Vite build.
|
|
59
|
+
//
|
|
60
|
+
// VITE_ADMIN_URL is set from the configured custom domain when present
|
|
61
|
+
// (we know it before the StaticSite is constructed). Without a custom
|
|
62
|
+
// domain the admin URL is only known *after* the StaticSite resolves —
|
|
63
|
+
// which would be circular at the `environment` map. In that case we
|
|
64
|
+
// leave VITE_ADMIN_URL empty; the discovery doc emits adminUrl: "" and
|
|
65
|
+
// the CLI tolerates the empty value. See:
|
|
66
|
+
// steering/CLI_BOOSTRAP_DESIGN.md §1.2 (env-injection circularity)
|
|
67
|
+
const viteAdminUrl = args.domain
|
|
68
|
+
? `https://${args.domain.name}`
|
|
69
|
+
: "";
|
|
59
70
|
const site = new sst.aws.StaticSite(`${name}Admin`, {
|
|
60
71
|
path: args.dev.adminPath,
|
|
61
72
|
dev: {
|
|
@@ -73,6 +84,7 @@ export function createAdminSite(name: string, args: AdminSiteArgs) {
|
|
|
73
84
|
VITE_AWS_REGION: aws.getRegionOutput().name,
|
|
74
85
|
VITE_COLLAB_WS_URL: collab.wsUrl,
|
|
75
86
|
VITE_COLLAB_ENABLED: collabEnabledStr,
|
|
87
|
+
VITE_ADMIN_URL: viteAdminUrl,
|
|
76
88
|
},
|
|
77
89
|
domain: domainConfig,
|
|
78
90
|
});
|
|
@@ -90,10 +102,22 @@ export function createAdminSite(name: string, args: AdminSiteArgs) {
|
|
|
90
102
|
fs.mkdirSync(workDir, { recursive: true });
|
|
91
103
|
fs.cpSync(adminSrc, workDir, { recursive: true });
|
|
92
104
|
|
|
105
|
+
// Compute the admin URL for placeholder substitution. When a custom domain
|
|
106
|
+
// is configured, use it directly; otherwise fall back to the CloudFront-
|
|
107
|
+
// distribution URL the StaticSite resolves to. Using `$interpolate` keeps
|
|
108
|
+
// the value as an SST Output until deploy time, where it's safely inlined
|
|
109
|
+
// into the node script via the existing $-interpolated template.
|
|
110
|
+
const adminUrlForSubstitution = args.domain
|
|
111
|
+
? `https://${args.domain.name}`
|
|
112
|
+
: "";
|
|
93
113
|
const site = new sst.aws.StaticSite(`${name}Admin`, {
|
|
94
114
|
path: workDir,
|
|
95
115
|
build: {
|
|
96
|
-
// Replace placeholder env vars in the pre-built JS/HTML files
|
|
116
|
+
// Replace placeholder env vars in the pre-built JS/HTML/discovery files.
|
|
117
|
+
//
|
|
118
|
+
// The walk filter intentionally only matches the exact path
|
|
119
|
+
// `.well-known/headroom.json` (not any *.json) so we don't touch
|
|
120
|
+
// manifest.webmanifest, asset manifests, or other runtime JSON files.
|
|
97
121
|
command: $interpolate`node -e "
|
|
98
122
|
const fs = require('fs');
|
|
99
123
|
const path = require('path');
|
|
@@ -105,12 +129,18 @@ export function createAdminSite(name: string, args: AdminSiteArgs) {
|
|
|
105
129
|
'__HEADROOM_AWS_REGION__': '${aws.getRegionOutput().name}',
|
|
106
130
|
'__HEADROOM_COLLAB_WS_URL__': '${collab.wsUrl}',
|
|
107
131
|
'__HEADROOM_COLLAB_ENABLED__': '${collabEnabledStr}',
|
|
132
|
+
'__HEADROOM_ADMIN_URL__': '${adminUrlForSubstitution}',
|
|
108
133
|
};
|
|
134
|
+
const discoveryFile = path.join('.well-known', 'headroom.json');
|
|
109
135
|
function walk(d) {
|
|
110
136
|
for (const f of fs.readdirSync(d)) {
|
|
111
137
|
const full = path.join(d, f);
|
|
112
138
|
if (fs.statSync(full).isDirectory()) walk(full);
|
|
113
|
-
else
|
|
139
|
+
else {
|
|
140
|
+
const isSubstitutable = f.endsWith('.js')
|
|
141
|
+
|| f.endsWith('.html')
|
|
142
|
+
|| full.endsWith(discoveryFile);
|
|
143
|
+
if (!isSubstitutable) continue;
|
|
114
144
|
let content = fs.readFileSync(full, 'utf8');
|
|
115
145
|
for (const [k, v] of Object.entries(replacements)) {
|
|
116
146
|
content = content.replaceAll(k, v);
|
|
@@ -120,6 +150,19 @@ export function createAdminSite(name: string, args: AdminSiteArgs) {
|
|
|
120
150
|
}
|
|
121
151
|
}
|
|
122
152
|
walk('.');
|
|
153
|
+
// Regression guard: the discovery doc must have all placeholders
|
|
154
|
+
// substituted by now. A surviving __HEADROOM_*__ would indicate a
|
|
155
|
+
// mismatch between the Vite-emitted file and the replacements map.
|
|
156
|
+
try {
|
|
157
|
+
const body = fs.readFileSync(discoveryFile, 'utf8');
|
|
158
|
+
if (/__HEADROOM_[A-Z_]+__/.test(body)) {
|
|
159
|
+
console.error('headroom: unsubstituted placeholders survive in ' + discoveryFile);
|
|
160
|
+
console.error(body);
|
|
161
|
+
process.exit(1);
|
|
162
|
+
}
|
|
163
|
+
} catch (e) {
|
|
164
|
+
if (e && e.code !== 'ENOENT') throw e;
|
|
165
|
+
}
|
|
123
166
|
"`,
|
|
124
167
|
output: ".",
|
|
125
168
|
},
|
package/src/api.ts
CHANGED
|
@@ -6,16 +6,40 @@
|
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
import path from "path";
|
|
9
|
+
import { execSync } from "child_process";
|
|
9
10
|
import type { StorageResources } from "./storage.js";
|
|
10
11
|
import type { AuthResources } from "./auth.js";
|
|
11
12
|
import type { WebhookResources } from "./webhooks.js";
|
|
13
|
+
import type { BackupResources } from "./backup.js";
|
|
12
14
|
import type { ImageResources } from "./image.js";
|
|
13
15
|
import type { CollabTableResources } from "./collaboration.js";
|
|
14
16
|
|
|
17
|
+
/**
|
|
18
|
+
* Capture the deploying commit SHA so the API can self-report which build is
|
|
19
|
+
* running. Read at infra-eval time (once per `sst deploy` / `sst dev`) and
|
|
20
|
+
* baked into the Lambda's env. Falls back to "unknown" outside a git repo —
|
|
21
|
+
* never throws, since failing the deploy over a missing SHA would be hostile.
|
|
22
|
+
*/
|
|
23
|
+
function captureGitSha(): string {
|
|
24
|
+
// Allow CI to inject a specific SHA — useful when builds happen on a
|
|
25
|
+
// detached checkout where `git rev-parse HEAD` returns the wrong value.
|
|
26
|
+
const fromEnv = process.env.HEADROOM_GIT_SHA;
|
|
27
|
+
if (fromEnv) return fromEnv.trim();
|
|
28
|
+
try {
|
|
29
|
+
return execSync("git rev-parse HEAD", {
|
|
30
|
+
encoding: "utf-8",
|
|
31
|
+
stdio: ["ignore", "pipe", "ignore"],
|
|
32
|
+
}).trim();
|
|
33
|
+
} catch {
|
|
34
|
+
return "unknown";
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
15
38
|
export interface ApiArgs {
|
|
16
39
|
storage: StorageResources;
|
|
17
40
|
auth: AuthResources;
|
|
18
41
|
webhooks: WebhookResources;
|
|
42
|
+
backup: BackupResources;
|
|
19
43
|
image: ImageResources;
|
|
20
44
|
/**
|
|
21
45
|
* Just the collab DynamoDB table — the API Lambda only links the table
|
|
@@ -32,7 +56,7 @@ export interface ApiArgs {
|
|
|
32
56
|
}
|
|
33
57
|
|
|
34
58
|
export function createApi(name: string, args: ApiArgs) {
|
|
35
|
-
const { storage, auth, webhooks, image, collab } = args;
|
|
59
|
+
const { storage, auth, webhooks, backup, image, collab } = args;
|
|
36
60
|
|
|
37
61
|
const handlerConfig = args.dev
|
|
38
62
|
? {
|
|
@@ -68,8 +92,17 @@ export function createApi(name: string, args: ApiArgs) {
|
|
|
68
92
|
AWS_REGION_NAME: aws.getRegionOutput().name,
|
|
69
93
|
WEBHOOKS_TABLE: webhooks.webhooks.name,
|
|
70
94
|
WEBHOOK_DELIVERIES_TABLE: webhooks.webhookDeliveries.name,
|
|
71
|
-
|
|
72
|
-
|
|
95
|
+
WEBHOOK_WORKER_FUNCTION_NAME: webhooks.webhookWorker.name,
|
|
96
|
+
// Backup admin endpoints (Phases 3+4): the API Lambda async-invokes
|
|
97
|
+
// the backup worker and serves list/presign/delete from the backup
|
|
98
|
+
// bucket directly. Both env vars must be present for /v1/admin/...
|
|
99
|
+
// backup endpoints to function; unset = 503 from the service layer.
|
|
100
|
+
BACKUP_BUCKET: storage.backupBucket.name,
|
|
101
|
+
BACKUP_WORKER_FUNCTION_NAME: backup.backupWorker.name,
|
|
102
|
+
// The Go API only signs with the primary master and derives the
|
|
103
|
+
// per-site key per request. It never receives the OLD master —
|
|
104
|
+
// only the Sharp Lambda's verifier needs it.
|
|
105
|
+
IMAGE_SIGNING_MASTER_SECRET: image.imageSigningMasterSecret.value,
|
|
73
106
|
IMAGE_LAMBDA_NAME: image.imageLambda.name,
|
|
74
107
|
RELATIONSHIPS_TABLE: storage.relationships.name,
|
|
75
108
|
SITE_USERS_TABLE: storage.siteUsers.name,
|
|
@@ -79,6 +112,9 @@ export function createApi(name: string, args: ApiArgs) {
|
|
|
79
112
|
// `X-Headroom-Internal` against this on internal service calls
|
|
80
113
|
// (collab → draft snapshot). See packages/api/internal/middleware/jwt.go.
|
|
81
114
|
INTERNAL_SECRET: storage.internalSecret.value,
|
|
115
|
+
// Commit SHA of the source tree at infra-eval time. Surfaced on
|
|
116
|
+
// /health so operators can map deploys → commits without tagging.
|
|
117
|
+
GIT_SHA: captureGitSha(),
|
|
82
118
|
},
|
|
83
119
|
link: [
|
|
84
120
|
storage.sites,
|
|
@@ -92,12 +128,16 @@ export function createApi(name: string, args: ApiArgs) {
|
|
|
92
128
|
storage.contentBucket,
|
|
93
129
|
webhooks.webhooks,
|
|
94
130
|
webhooks.webhookDeliveries,
|
|
95
|
-
|
|
96
|
-
image.imageSigningSecret,
|
|
131
|
+
image.imageSigningMasterSecret,
|
|
97
132
|
storage.relationships,
|
|
98
133
|
storage.siteUsers,
|
|
99
134
|
collab.collabTable,
|
|
100
135
|
storage.internalSecret,
|
|
136
|
+
// Backup bucket — admin endpoints list/presign-get/delete here. The
|
|
137
|
+
// worker writes here (already linked via backup.ts); the API only
|
|
138
|
+
// needs read + delete + presign-get + list-bucket, which are all
|
|
139
|
+
// covered by the SST `link` IAM grant for the bucket.
|
|
140
|
+
storage.backupBucket,
|
|
101
141
|
],
|
|
102
142
|
permissions: [
|
|
103
143
|
{
|
|
@@ -123,6 +163,19 @@ export function createApi(name: string, args: ApiArgs) {
|
|
|
123
163
|
actions: ["lambda:InvokeFunction"],
|
|
124
164
|
resources: [image.imageLambda.arn],
|
|
125
165
|
},
|
|
166
|
+
{
|
|
167
|
+
// Async invoke of the webhook worker. Replaces the old SQS
|
|
168
|
+
// SendMessage permission that was previously auto-derived from
|
|
169
|
+
// linking the queue.
|
|
170
|
+
actions: ["lambda:InvokeFunction"],
|
|
171
|
+
resources: [webhooks.webhookWorker.arn],
|
|
172
|
+
},
|
|
173
|
+
{
|
|
174
|
+
// Async invoke of the backup worker — admin endpoints for trigger
|
|
175
|
+
// backup / restore call lambda:Invoke with InvocationType=Event.
|
|
176
|
+
actions: ["lambda:InvokeFunction"],
|
|
177
|
+
resources: [backup.backupWorker.arn],
|
|
178
|
+
},
|
|
126
179
|
{
|
|
127
180
|
actions: ["ses:SendEmail", "ses:SendRawEmail"],
|
|
128
181
|
resources: ["*"],
|
package/src/backup.ts
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Backup Infrastructure
|
|
3
|
+
*
|
|
4
|
+
* A single Go Lambda that handles both backup export and restore import.
|
|
5
|
+
* The API service invokes it synchronously via lambda:InvokeFunction for the
|
|
6
|
+
* "scheduled" entry point this will gain a daily EventBridge cron (Phase 4).
|
|
7
|
+
*
|
|
8
|
+
* The Lambda links every site-scoped table plus the content + backup buckets.
|
|
9
|
+
* Deliberately NOT linked: Collab, collabStateBucket, SchedulerLock,
|
|
10
|
+
* WebhookDeliveries — these are transient / operational and excluded from
|
|
11
|
+
* backup payloads (see steering doc "What's in scope vs. out of scope").
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import path from "path";
|
|
15
|
+
import type { StorageResources } from "./storage.js";
|
|
16
|
+
import type { WebhookResources } from "./webhooks.js";
|
|
17
|
+
|
|
18
|
+
export interface BackupArgs {
|
|
19
|
+
storage: StorageResources;
|
|
20
|
+
webhooks: WebhookResources;
|
|
21
|
+
pkgRoot: string;
|
|
22
|
+
dev?: {
|
|
23
|
+
/** Go source path, e.g. "packages/backup-worker" */
|
|
24
|
+
handler: string;
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function createBackup(name: string, args: BackupArgs) {
|
|
29
|
+
const { storage, webhooks } = args;
|
|
30
|
+
|
|
31
|
+
const workerConfig = args.dev
|
|
32
|
+
? {
|
|
33
|
+
handler: args.dev.handler,
|
|
34
|
+
runtime: "go" as const,
|
|
35
|
+
}
|
|
36
|
+
: {
|
|
37
|
+
bundle: path.join(args.pkgRoot, "lambda/backup-worker"),
|
|
38
|
+
handler: "bootstrap",
|
|
39
|
+
runtime: "provided.al2023" as const,
|
|
40
|
+
architecture: "arm64" as const,
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
const backupWorker = new sst.aws.Function(`${name}BackupWorker`, {
|
|
44
|
+
...workerConfig,
|
|
45
|
+
// 15-minute Lambda budget. Large sites with many media files may bump up
|
|
46
|
+
// against this; see Deferred "Step Functions for very large sites" for
|
|
47
|
+
// the escape hatch.
|
|
48
|
+
timeout: "15 minutes",
|
|
49
|
+
// Higher than default — the worker holds tar/gzip pipes, an in-memory
|
|
50
|
+
// 25-row BatchWriteItem buffer, and parallel S3 GetObject buffers.
|
|
51
|
+
memory: "1024 MB",
|
|
52
|
+
environment: {
|
|
53
|
+
SITES_TABLE: storage.sites.name,
|
|
54
|
+
CONTENT_TABLE: storage.content.name,
|
|
55
|
+
DRAFT_CONTENT_TABLE: storage.draftContent.name,
|
|
56
|
+
BLOCKS_TABLE: storage.blocks.name,
|
|
57
|
+
MEDIA_TABLE: storage.media.name,
|
|
58
|
+
COLLECTIONS_TABLE: storage.collections.name,
|
|
59
|
+
BLOCK_TYPES_TABLE: storage.blockTypes.name,
|
|
60
|
+
ADMIN_AUDIT_TABLE: storage.adminAudit.name,
|
|
61
|
+
RELATIONSHIPS_TABLE: storage.relationships.name,
|
|
62
|
+
SITE_USERS_TABLE: storage.siteUsers.name,
|
|
63
|
+
WEBHOOKS_TABLE: webhooks.webhooks.name,
|
|
64
|
+
CONTENT_BUCKET: storage.contentBucket.name,
|
|
65
|
+
BACKUP_BUCKET: storage.backupBucket.name,
|
|
66
|
+
KVS_ARN: storage.kvs.arn,
|
|
67
|
+
AWS_REGION_NAME: aws.getRegionOutput().name,
|
|
68
|
+
},
|
|
69
|
+
link: [
|
|
70
|
+
storage.sites,
|
|
71
|
+
storage.content,
|
|
72
|
+
storage.draftContent,
|
|
73
|
+
storage.blocks,
|
|
74
|
+
storage.media,
|
|
75
|
+
storage.collections,
|
|
76
|
+
storage.blockTypes,
|
|
77
|
+
storage.adminAudit,
|
|
78
|
+
storage.relationships,
|
|
79
|
+
storage.siteUsers,
|
|
80
|
+
webhooks.webhooks,
|
|
81
|
+
storage.contentBucket,
|
|
82
|
+
storage.backupBucket,
|
|
83
|
+
],
|
|
84
|
+
permissions: [
|
|
85
|
+
{
|
|
86
|
+
// CloudFront KVS resync on restore: re-publish API key hashes so the
|
|
87
|
+
// edge function recognizes them. Fail-loud per steering §2.1 step 18.
|
|
88
|
+
actions: [
|
|
89
|
+
"cloudfront-keyvaluestore:DescribeKeyValueStore",
|
|
90
|
+
"cloudfront-keyvaluestore:PutKey",
|
|
91
|
+
"cloudfront-keyvaluestore:DeleteKey",
|
|
92
|
+
"cloudfront-keyvaluestore:GetKey",
|
|
93
|
+
],
|
|
94
|
+
resources: [storage.kvs.arn],
|
|
95
|
+
},
|
|
96
|
+
],
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
// Phase 4 — daily EventBridge cron that invokes the worker with a
|
|
100
|
+
// "scheduled" event. The handler scans the Sites table, runs backup +
|
|
101
|
+
// retention cleanup for every site with backupSchedule.enabled. 02:00
|
|
102
|
+
// UTC is a low-traffic window for most public sites; tune in the
|
|
103
|
+
// steering doc if needed. Cost is one Lambda invocation per day per
|
|
104
|
+
// stack, regardless of site count.
|
|
105
|
+
const backupCron = new sst.aws.Cron(`${name}BackupSchedule`, {
|
|
106
|
+
schedule: "cron(0 2 * * ? *)",
|
|
107
|
+
function: backupWorker.arn,
|
|
108
|
+
event: { type: "scheduled" },
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
return { backupWorker, backupCron };
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export type BackupResources = ReturnType<typeof createBackup>;
|
package/src/cdn-api.ts
CHANGED
|
@@ -143,23 +143,14 @@ export function createApiCdn(name: string, args: ApiCdnArgs) {
|
|
|
143
143
|
},
|
|
144
144
|
);
|
|
145
145
|
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
parametersInCacheKeyAndForwardedToOrigin: {
|
|
155
|
-
cookiesConfig: { cookieBehavior: "none" },
|
|
156
|
-
headersConfig: { headerBehavior: "none" },
|
|
157
|
-
queryStringsConfig: { queryStringBehavior: "none" },
|
|
158
|
-
enableAcceptEncodingBrotli: true,
|
|
159
|
-
enableAcceptEncodingGzip: true,
|
|
160
|
-
},
|
|
161
|
-
},
|
|
162
|
-
);
|
|
146
|
+
// NOTE: the old `versionCachePolicy` (custom 2-second TTL) was deleted
|
|
147
|
+
// when /version began returning the per-site image signing secret.
|
|
148
|
+
// CloudFront custom cache policies do not honor `Cache-Control: private`
|
|
149
|
+
// from the origin — the explicit TTLs would win and the response (with
|
|
150
|
+
// the secret) would be edge-cached for 2s. We now use the AWS-managed
|
|
151
|
+
// `CachingDisabled` policy below for /v1/*/version, so the origin's
|
|
152
|
+
// `Cache-Control: private, max-age=2` is what reaches the browser
|
|
153
|
+
// (short-window in-browser cache) while the edge bypasses caching.
|
|
163
154
|
|
|
164
155
|
// =========================================================================
|
|
165
156
|
// Origin Request Policy
|
|
@@ -321,10 +312,17 @@ export function createApiCdn(name: string, args: ApiCdnArgs) {
|
|
|
321
312
|
},
|
|
322
313
|
],
|
|
323
314
|
},
|
|
324
|
-
// Version endpoint:
|
|
325
|
-
//
|
|
326
|
-
//
|
|
327
|
-
//
|
|
315
|
+
// Version endpoint: caching DISABLED at the edge. /version now
|
|
316
|
+
// carries a per-site image signing secret in the body, so the
|
|
317
|
+
// shared edge cache must not hold it. The origin sets
|
|
318
|
+
// `Cache-Control: private, max-age=2` so browsers may still cache
|
|
319
|
+
// for the 2-second window — that absorbs single-flight contention
|
|
320
|
+
// from the same client without exposing the secret to any other
|
|
321
|
+
// viewer.
|
|
322
|
+
//
|
|
323
|
+
// Tradeoff: origin Lambda invocations on /version are now one per
|
|
324
|
+
// client poll instead of one per 2-second edge window. The SDK
|
|
325
|
+
// polls every 10s by default, so the impact is bounded.
|
|
328
326
|
//
|
|
329
327
|
// NOTE: pathPattern "/v1/*/version" matches exact "/version" only.
|
|
330
328
|
// CloudFront's `*` wildcard does not span path segments, so any
|
|
@@ -336,7 +334,7 @@ export function createApiCdn(name: string, args: ApiCdnArgs) {
|
|
|
336
334
|
allowedMethods: ["GET", "HEAD", "OPTIONS"],
|
|
337
335
|
cachedMethods: ["GET", "HEAD", "OPTIONS"],
|
|
338
336
|
compress: true,
|
|
339
|
-
cachePolicyId:
|
|
337
|
+
cachePolicyId: cachingDisabledPolicyId,
|
|
340
338
|
originRequestPolicyId: originRequestPolicy.id,
|
|
341
339
|
functionAssociations: [
|
|
342
340
|
{
|