@geekmidas/constructs 10.0.0-alpha.170 → 10.0.0-alpha.172
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/{Cron-Ca_qHQu2.d.cts → Cron-BcA8F0S-.d.cts} +2 -2
- package/dist/{Cron-Ca_qHQu2.d.cts.map → Cron-BcA8F0S-.d.cts.map} +1 -1
- package/dist/{Cron-DPJiR7Lt.d.mts → Cron-z2CiuQT_.d.mts} +2 -2
- package/dist/{Cron-DPJiR7Lt.d.mts.map → Cron-z2CiuQT_.d.mts.map} +1 -1
- package/dist/{CronBuilder-C3RrAF1-.d.cts → CronBuilder-BZvo34X2.d.cts} +4 -4
- package/dist/{CronBuilder-BC4za5Bx.d.mts.map → CronBuilder-BZvo34X2.d.cts.map} +1 -1
- package/dist/{CronBuilder-BC4za5Bx.d.mts → CronBuilder-BbgKo8OI.d.mts} +4 -4
- package/dist/{CronBuilder-C3RrAF1-.d.cts.map → CronBuilder-BbgKo8OI.d.mts.map} +1 -1
- package/dist/{Endpoint-DC7mreOr.d.mts → Endpoint-CIDUreMW.d.mts} +5 -5
- package/dist/{Endpoint-BlIZLsBQ.d.cts.map → Endpoint-CIDUreMW.d.mts.map} +1 -1
- package/dist/{Endpoint-BlIZLsBQ.d.cts → Endpoint-COisi9jw.d.cts} +5 -5
- package/dist/{Endpoint-DC7mreOr.d.mts.map → Endpoint-COisi9jw.d.cts.map} +1 -1
- package/dist/{EndpointFactory-DCmnCmkX.d.mts → EndpointFactory-CIM80WIK.d.mts} +5 -5
- package/dist/{EndpointFactory-DCmnCmkX.d.mts.map → EndpointFactory-CIM80WIK.d.mts.map} +1 -1
- package/dist/{EndpointFactory-cVTb8kCc.d.cts → EndpointFactory-CfBg6jJE.d.cts} +5 -5
- package/dist/{EndpointFactory-cVTb8kCc.d.cts.map → EndpointFactory-CfBg6jJE.d.cts.map} +1 -1
- package/dist/{ObjectSubscriberBuilder-AwGKoUKy.d.mts → ObjectSubscriberBuilder-Ci_Cc-WZ.d.mts} +2 -2
- package/dist/{ObjectSubscriberBuilder-AwGKoUKy.d.mts.map → ObjectSubscriberBuilder-Ci_Cc-WZ.d.mts.map} +1 -1
- package/dist/{ObjectSubscriberBuilder-CB6imsX4.d.cts → ObjectSubscriberBuilder-DWtLxfAJ.d.cts} +2 -2
- package/dist/{ObjectSubscriberBuilder-CB6imsX4.d.cts.map → ObjectSubscriberBuilder-DWtLxfAJ.d.cts.map} +1 -1
- package/dist/{ProcessorBuilder-CwIlm75W.d.mts → ProcessorBuilder-CdLwJK4k.d.mts} +2 -2
- package/dist/{ProcessorBuilder-CeEZ2vCx.d.cts.map → ProcessorBuilder-CdLwJK4k.d.mts.map} +1 -1
- package/dist/{ProcessorBuilder-CeEZ2vCx.d.cts → ProcessorBuilder-ClD7tmEe.d.cts} +2 -2
- package/dist/{ProcessorBuilder-CwIlm75W.d.mts.map → ProcessorBuilder-ClD7tmEe.d.cts.map} +1 -1
- package/dist/{QueueBuilder-CUERv8jt.d.mts → QueueBuilder-CjULiiDN.d.mts} +2 -2
- package/dist/{QueueBuilder-CUERv8jt.d.mts.map → QueueBuilder-CjULiiDN.d.mts.map} +1 -1
- package/dist/{QueueBuilder-CmB1vOgn.d.cts → QueueBuilder-Dacm9qAv.d.cts} +2 -2
- package/dist/{QueueBuilder-CmB1vOgn.d.cts.map → QueueBuilder-Dacm9qAv.d.cts.map} +1 -1
- package/dist/adaptors/aws.d.cts +2 -2
- package/dist/adaptors/aws.d.mts +2 -2
- package/dist/adaptors/awsWebsocket.d.cts +1 -1
- package/dist/adaptors/awsWebsocket.d.mts +1 -1
- package/dist/adaptors/hono.d.cts +1 -1
- package/dist/adaptors/hono.d.mts +1 -1
- package/dist/adaptors/testing.d.cts +5 -5
- package/dist/adaptors/testing.d.mts +5 -5
- package/dist/{auth-1yI2wR-4.d.cts → auth-CutSfNlr.d.mts} +6 -6
- package/dist/{auth-1yI2wR-4.d.cts.map → auth-CutSfNlr.d.mts.map} +1 -1
- package/dist/{auth-D4NMXgLt.d.mts → auth-b9ADezz9.d.cts} +6 -6
- package/dist/{auth-D4NMXgLt.d.mts.map → auth-b9ADezz9.d.cts.map} +1 -1
- package/dist/auth.d.cts +1 -1
- package/dist/auth.d.mts +1 -1
- package/dist/{cache-0VoeOTF9.d.mts → cache-9wLNSy3O.d.cts} +3 -3
- package/dist/{cache-0VoeOTF9.d.mts.map → cache-9wLNSy3O.d.cts.map} +1 -1
- package/dist/{cache-CW-sArzS.d.cts → cache-BFPs_CGs.d.mts} +3 -3
- package/dist/{cache-CW-sArzS.d.cts.map → cache-BFPs_CGs.d.mts.map} +1 -1
- package/dist/cache.d.cts +1 -1
- package/dist/cache.d.mts +1 -1
- package/dist/{construct-interface-DhbaONW2.d.cts → construct-interface-CVoejIpo.d.cts} +20 -4
- package/dist/construct-interface-CVoejIpo.d.cts.map +1 -0
- package/dist/{construct-interface-DxfkFxkl.d.mts → construct-interface-Nw5Dt9AC.d.mts} +20 -4
- package/dist/construct-interface-Nw5Dt9AC.d.mts.map +1 -0
- package/dist/construct-interface.cjs +17 -2
- package/dist/construct-interface.cjs.map +1 -1
- package/dist/construct-interface.d.cts +2 -2
- package/dist/construct-interface.d.mts +2 -2
- package/dist/construct-interface.mjs +17 -3
- package/dist/construct-interface.mjs.map +1 -1
- package/dist/credential.d.cts +1 -1
- package/dist/credential.d.mts +1 -1
- package/dist/crons/index.d.cts +2 -2
- package/dist/crons/index.d.mts +2 -2
- package/dist/database/kysely.d.cts +1 -1
- package/dist/database/kysely.d.mts +1 -1
- package/dist/email.d.cts +1 -1
- package/dist/email.d.mts +1 -1
- package/dist/encryption.d.cts +1 -1
- package/dist/encryption.d.mts +1 -1
- package/dist/endpoints/index.d.cts +2 -2
- package/dist/endpoints/index.d.mts +2 -2
- package/dist/external-api.d.cts +1 -1
- package/dist/external-api.d.mts +1 -1
- package/dist/{fake-Djx8E0o1.d.cts → fake-JI5uN1SF.d.cts} +2 -2
- package/dist/{fake-BvOXkZmj.d.mts.map → fake-JI5uN1SF.d.cts.map} +1 -1
- package/dist/{fake-BvOXkZmj.d.mts → fake-zpuXpBmY.d.mts} +2 -2
- package/dist/{fake-Djx8E0o1.d.cts.map → fake-zpuXpBmY.d.mts.map} +1 -1
- package/dist/file-server.cjs +6 -37
- package/dist/file-server.cjs.map +1 -1
- package/dist/file-server.d.cts +4 -4
- package/dist/file-server.d.cts.map +1 -1
- package/dist/file-server.d.mts +4 -4
- package/dist/file-server.d.mts.map +1 -1
- package/dist/file-server.mjs +4 -35
- package/dist/file-server.mjs.map +1 -1
- package/dist/functions/index.d.cts +1 -1
- package/dist/functions/index.d.mts +1 -1
- package/dist/{inbox-BjvMs7EJ.d.cts → inbox-CXLU7h_8.d.cts} +2 -2
- package/dist/{inbox-BjvMs7EJ.d.cts.map → inbox-CXLU7h_8.d.cts.map} +1 -1
- package/dist/{inbox-C8bOR9UL.d.mts → inbox-DYFsLd9A.d.mts} +2 -2
- package/dist/{inbox-C8bOR9UL.d.mts.map → inbox-DYFsLd9A.d.mts.map} +1 -1
- package/dist/inbox.d.cts +1 -1
- package/dist/inbox.d.mts +1 -1
- package/dist/{index-vCS4HBEG.d.mts → index-BpE9_6l5.d.mts} +2 -2
- package/dist/{index-DaK-C7N3.d.cts.map → index-BpE9_6l5.d.mts.map} +1 -1
- package/dist/{index-DaK-C7N3.d.cts → index-zRChehJ9.d.cts} +2 -2
- package/dist/{index-vCS4HBEG.d.mts.map → index-zRChehJ9.d.cts.map} +1 -1
- package/dist/{kysely-BGvpd_ZH.d.mts → kysely-5PAqFBzo.d.mts} +3 -3
- package/dist/{kysely-2HqIQ2fC.d.cts.map → kysely-5PAqFBzo.d.mts.map} +1 -1
- package/dist/{kysely-2HqIQ2fC.d.cts → kysely-lxNUBSTP.d.cts} +3 -3
- package/dist/{kysely-BGvpd_ZH.d.mts.map → kysely-lxNUBSTP.d.cts.map} +1 -1
- package/dist/mobile-app.cjs +2 -1
- package/dist/mobile-app.cjs.map +1 -1
- package/dist/mobile-app.d.cts +3 -2
- package/dist/mobile-app.d.cts.map +1 -1
- package/dist/mobile-app.d.mts +3 -2
- package/dist/mobile-app.d.mts.map +1 -1
- package/dist/mobile-app.mjs +2 -1
- package/dist/mobile-app.mjs.map +1 -1
- package/dist/object-storage.cjs +42 -6
- package/dist/object-storage.cjs.map +1 -1
- package/dist/object-storage.d.cts +27 -2
- package/dist/object-storage.d.cts.map +1 -1
- package/dist/object-storage.d.mts +27 -2
- package/dist/object-storage.d.mts.map +1 -1
- package/dist/object-storage.mjs +39 -4
- package/dist/object-storage.mjs.map +1 -1
- package/dist/processors/index.d.cts +1 -1
- package/dist/processors/index.d.mts +1 -1
- package/dist/queue/index.d.cts +1 -1
- package/dist/queue/index.d.mts +1 -1
- package/dist/random-password.d.cts +1 -1
- package/dist/random-password.d.mts +1 -1
- package/dist/{expire-CieftS01.cjs → readOnlyStorage-C7bCe-z5.cjs} +35 -1
- package/dist/readOnlyStorage-C7bCe-z5.cjs.map +1 -0
- package/dist/{expire-CpzUAfr9.mjs → readOnlyStorage-DMCeLuS2.mjs} +30 -2
- package/dist/readOnlyStorage-DMCeLuS2.mjs.map +1 -0
- package/dist/rest-api.d.cts +4 -4
- package/dist/rest-api.d.mts +4 -4
- package/dist/site.cjs +5 -2
- package/dist/site.cjs.map +1 -1
- package/dist/site.d.cts +7 -4
- package/dist/site.d.cts.map +1 -1
- package/dist/site.d.mts +7 -4
- package/dist/site.d.mts.map +1 -1
- package/dist/site.mjs +5 -2
- package/dist/site.mjs.map +1 -1
- package/dist/subscribers/index.d.cts +1 -1
- package/dist/subscribers/index.d.mts +1 -1
- package/dist/{telemetry-DjJgtQ_N.d.cts → telemetry-BbLyS7ln.d.cts} +22 -5
- package/dist/telemetry-BbLyS7ln.d.cts.map +1 -0
- package/dist/{telemetry-BirKau0X.d.mts → telemetry-DWX-qKUh.d.mts} +22 -5
- package/dist/telemetry-DWX-qKUh.d.mts.map +1 -0
- package/dist/telemetry.cjs +11 -3
- package/dist/telemetry.cjs.map +1 -1
- package/dist/telemetry.d.cts +1 -1
- package/dist/telemetry.d.mts +1 -1
- package/dist/telemetry.mjs +12 -4
- package/dist/telemetry.mjs.map +1 -1
- package/dist/{websocket-api-CD-E5Ogr.d.cts → websocket-api-9ndLBolx.d.cts} +3 -3
- package/dist/{websocket-api-CD-E5Ogr.d.cts.map → websocket-api-9ndLBolx.d.cts.map} +1 -1
- package/dist/{websocket-api-pJJfeTcm.d.mts → websocket-api-BPPXF79i.d.mts} +3 -3
- package/dist/{websocket-api-pJJfeTcm.d.mts.map → websocket-api-BPPXF79i.d.mts.map} +1 -1
- package/dist/websocket-api.d.cts +1 -1
- package/dist/websocket-api.d.mts +1 -1
- package/dist/worker.d.cts +8 -8
- package/dist/worker.d.mts +8 -8
- package/package.json +31 -31
- package/dist/construct-interface-DhbaONW2.d.cts.map +0 -1
- package/dist/construct-interface-DxfkFxkl.d.mts.map +0 -1
- package/dist/expire-CieftS01.cjs.map +0 -1
- package/dist/expire-CpzUAfr9.mjs.map +0 -1
- package/dist/telemetry-BirKau0X.d.mts.map +0 -1
- package/dist/telemetry-DjJgtQ_N.d.cts.map +0 -1
|
@@ -45,6 +45,34 @@ function expiryDays(bucket, expire) {
|
|
|
45
45
|
return Object.keys(days).length > 0 ? days : void 0;
|
|
46
46
|
}
|
|
47
47
|
//#endregion
|
|
48
|
+
//#region src/readOnlyStorage.ts
|
|
49
|
+
/** Names asked of any object, which a read-only client must not answer. */
|
|
50
|
+
const INTROSPECTED = /* @__PURE__ */ new Set([
|
|
51
|
+
"then",
|
|
52
|
+
"toJSON",
|
|
53
|
+
"constructor",
|
|
54
|
+
"asymmetricMatch",
|
|
55
|
+
"$$typeof",
|
|
56
|
+
"nodeType",
|
|
57
|
+
"inspect"
|
|
58
|
+
]);
|
|
59
|
+
/**
|
|
60
|
+
* A client whose every method throws what `refuse` makes of its name.
|
|
61
|
+
*
|
|
62
|
+
* A proxy rather than a list of stubs, so a method the storage client grows
|
|
63
|
+
* later refuses the same way. What a runtime asks of any object is left
|
|
64
|
+
* alone: `then`, because a client is resolved from a promise, and the names a
|
|
65
|
+
* serialiser or a test's printer looks for.
|
|
66
|
+
*/
|
|
67
|
+
function readOnlyStorage(refuse) {
|
|
68
|
+
return new Proxy({}, { get(_target, property) {
|
|
69
|
+
if (typeof property !== "string" || INTROSPECTED.has(property)) return;
|
|
70
|
+
return () => {
|
|
71
|
+
throw refuse(property);
|
|
72
|
+
};
|
|
73
|
+
} });
|
|
74
|
+
}
|
|
75
|
+
//#endregion
|
|
48
76
|
Object.defineProperty(exports, "ExpiryDaysInvalid", {
|
|
49
77
|
enumerable: true,
|
|
50
78
|
get: function() {
|
|
@@ -63,5 +91,11 @@ Object.defineProperty(exports, "expiryDays", {
|
|
|
63
91
|
return expiryDays;
|
|
64
92
|
}
|
|
65
93
|
});
|
|
94
|
+
Object.defineProperty(exports, "readOnlyStorage", {
|
|
95
|
+
enumerable: true,
|
|
96
|
+
get: function() {
|
|
97
|
+
return readOnlyStorage;
|
|
98
|
+
}
|
|
99
|
+
});
|
|
66
100
|
|
|
67
|
-
//# sourceMappingURL=
|
|
101
|
+
//# sourceMappingURL=readOnlyStorage-C7bCe-z5.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"readOnlyStorage-C7bCe-z5.cjs","names":[],"sources":["../src/expire.ts","../src/readOnlyStorage.ts"],"sourcesContent":["/**\n * How long a bucket keeps the objects under a prefix.\n *\n * Shared by `ObjectStorage` and the bucket a `FileServer` vends, because it is\n * a fact about the bucket rather than about who serves it: a prefix of\n * generated files that nobody reads back grows for ever unless the bucket\n * itself is told to drop them.\n *\n * ```ts\n * new ObjectStorage('Private', { expire: { 'quotes/': { days: 30 } } });\n * ```\n *\n * Whole days, because that is the unit S3's lifecycle — and MinIO's — counts\n * in. Prefixes are literal: a lifecycle rule matches the start of a key and\n * has no globs, so a pattern that looks like one is refused rather than\n * silently matching nothing.\n */\nexport type ObjectExpiry = Readonly<Record<string, { readonly days: number }>>;\n\n/** An expiry prefix the bucket could not match the way it reads. */\nexport class ExpiryPrefixInvalid extends Error {\n\tconstructor(\n\t\treadonly bucket: string,\n\t\treadonly prefix: string,\n\t\treadonly reason: string,\n\t) {\n\t\tsuper(\n\t\t\t`'${bucket}' expires objects under '${prefix}', which ${reason}. ` +\n\t\t\t\t`Name the start of the keys as they are stored, e.g. 'quotes/'.`,\n\t\t);\n\t\tthis.name = 'ExpiryPrefixInvalid';\n\t}\n}\n\n/** An expiry that is not a whole number of days, one or more. */\nexport class ExpiryDaysInvalid extends Error {\n\tconstructor(\n\t\treadonly bucket: string,\n\t\treadonly prefix: string,\n\t\treadonly days: unknown,\n\t) {\n\t\tsuper(\n\t\t\t`'${bucket}' expires '${prefix}' after ${String(days)} days. A bucket ` +\n\t\t\t\t`counts lifecycle in whole days, so give an integer of 1 or more.`,\n\t\t);\n\t\tthis.name = 'ExpiryDaysInvalid';\n\t}\n}\n\n/**\n * The expiry as the manifest records it — prefix → days — after checking\n * each entry, or nothing when there is none.\n *\n * @throws {ExpiryPrefixInvalid} for an empty, rooted or globbed prefix\n * @throws {ExpiryDaysInvalid} for anything but a positive integer of days\n */\nexport function expiryDays(\n\tbucket: string,\n\texpire: ObjectExpiry | undefined,\n): Record<string, number> | undefined {\n\tif (!expire) return undefined;\n\n\tconst days: Record<string, number> = {};\n\tfor (const [prefix, { days: count }] of Object.entries(expire)) {\n\t\tif (prefix.length === 0) {\n\t\t\tthrow new ExpiryPrefixInvalid(bucket, prefix, 'is empty');\n\t\t}\n\t\tif (prefix.startsWith('/')) {\n\t\t\tthrow new ExpiryPrefixInvalid(\n\t\t\t\tbucket,\n\t\t\t\tprefix,\n\t\t\t\t\"starts with '/', which no stored key does\",\n\t\t\t);\n\t\t}\n\t\tif (/[*?]/.test(prefix)) {\n\t\t\tthrow new ExpiryPrefixInvalid(\n\t\t\t\tbucket,\n\t\t\t\tprefix,\n\t\t\t\t'is a pattern, and a lifecycle prefix is matched literally',\n\t\t\t);\n\t\t}\n\t\tif (!Number.isInteger(count) || count < 1) {\n\t\t\tthrow new ExpiryDaysInvalid(bucket, prefix, count);\n\t\t}\n\t\tdays[prefix] = count;\n\t}\n\n\treturn Object.keys(days).length > 0 ? days : undefined;\n}\n","/**\n * A storage client with no bucket behind it: what a frontend's plain edge to\n * a bucket registers, as it holds where the bucket's links are signed and\n * nothing that writes to it.\n */\n\nimport type { StorageClient } from '@geekmidas/storage';\n\n/** Names asked of any object, which a read-only client must not answer. */\nconst INTROSPECTED = new Set([\n\t'then',\n\t'toJSON',\n\t'constructor',\n\t'asymmetricMatch',\n\t'$$typeof',\n\t'nodeType',\n\t'inspect',\n]);\n\n/**\n * A client whose every method throws what `refuse` makes of its name.\n *\n * A proxy rather than a list of stubs, so a method the storage client grows\n * later refuses the same way. What a runtime asks of any object is left\n * alone: `then`, because a client is resolved from a promise, and the names a\n * serialiser or a test's printer looks for.\n */\nexport function readOnlyStorage(\n\trefuse: (method: string) => Error,\n): StorageClient {\n\treturn new Proxy({} as StorageClient, {\n\t\tget(_target, property) {\n\t\t\tif (typeof property !== 'string' || INTROSPECTED.has(property)) return;\n\t\t\treturn () => {\n\t\t\t\tthrow refuse(property);\n\t\t\t};\n\t\t},\n\t});\n}\n"],"mappings":";;AAoBA,IAAa,sBAAb,cAAyC,MAAM;CAEpC;CACA;CACA;CAHV,YACC,QACA,QACA,QACC;EACD,MACC,IAAI,OAAO,2BAA2B,OAAO,WAAW,OAAO,iEAEhE;EAPS,KAAA,SAAA;EACA,KAAA,SAAA;EACA,KAAA,SAAA;EAMT,KAAK,OAAO;CACb;AACD;;AAGA,IAAa,oBAAb,cAAuC,MAAM;CAElC;CACA;CACA;CAHV,YACC,QACA,QACA,MACC;EACD,MACC,IAAI,OAAO,aAAa,OAAO,UAAU,OAAO,IAAI,EAAE,iFAEvD;EAPS,KAAA,SAAA;EACA,KAAA,SAAA;EACA,KAAA,OAAA;EAMT,KAAK,OAAO;CACb;AACD;;;;;;;;AASA,SAAgB,WACf,QACA,QACqC;CACrC,IAAI,CAAC,QAAQ,OAAO,KAAA;CAEpB,MAAM,OAA+B,CAAC;CACtC,KAAK,MAAM,CAAC,QAAQ,EAAE,MAAM,YAAY,OAAO,QAAQ,MAAM,GAAG;EAC/D,IAAI,OAAO,WAAW,GACrB,MAAM,IAAI,oBAAoB,QAAQ,QAAQ,UAAU;EAEzD,IAAI,OAAO,WAAW,GAAG,GACxB,MAAM,IAAI,oBACT,QACA,QACA,2CACD;EAED,IAAI,OAAO,KAAK,MAAM,GACrB,MAAM,IAAI,oBACT,QACA,QACA,2DACD;EAED,IAAI,CAAC,OAAO,UAAU,KAAK,KAAK,QAAQ,GACvC,MAAM,IAAI,kBAAkB,QAAQ,QAAQ,KAAK;EAElD,KAAK,UAAU;CAChB;CAEA,OAAO,OAAO,KAAK,IAAI,CAAC,CAAC,SAAS,IAAI,OAAO,KAAA;AAC9C;;;;AC/EA,MAAM,+BAAe,IAAI,IAAI;CAC5B;CACA;CACA;CACA;CACA;CACA;CACA;AACD,CAAC;;;;;;;;;AAUD,SAAgB,gBACf,QACgB;CAChB,OAAO,IAAI,MAAM,CAAC,GAAoB,EACrC,IAAI,SAAS,UAAU;EACtB,IAAI,OAAO,aAAa,YAAY,aAAa,IAAI,QAAQ,GAAG;EAChE,aAAa;GACZ,MAAM,OAAO,QAAQ;EACtB;CACD,EACD,CAAC;AACF"}
|
|
@@ -45,6 +45,34 @@ function expiryDays(bucket, expire) {
|
|
|
45
45
|
return Object.keys(days).length > 0 ? days : void 0;
|
|
46
46
|
}
|
|
47
47
|
//#endregion
|
|
48
|
-
|
|
48
|
+
//#region src/readOnlyStorage.ts
|
|
49
|
+
/** Names asked of any object, which a read-only client must not answer. */
|
|
50
|
+
const INTROSPECTED = /* @__PURE__ */ new Set([
|
|
51
|
+
"then",
|
|
52
|
+
"toJSON",
|
|
53
|
+
"constructor",
|
|
54
|
+
"asymmetricMatch",
|
|
55
|
+
"$$typeof",
|
|
56
|
+
"nodeType",
|
|
57
|
+
"inspect"
|
|
58
|
+
]);
|
|
59
|
+
/**
|
|
60
|
+
* A client whose every method throws what `refuse` makes of its name.
|
|
61
|
+
*
|
|
62
|
+
* A proxy rather than a list of stubs, so a method the storage client grows
|
|
63
|
+
* later refuses the same way. What a runtime asks of any object is left
|
|
64
|
+
* alone: `then`, because a client is resolved from a promise, and the names a
|
|
65
|
+
* serialiser or a test's printer looks for.
|
|
66
|
+
*/
|
|
67
|
+
function readOnlyStorage(refuse) {
|
|
68
|
+
return new Proxy({}, { get(_target, property) {
|
|
69
|
+
if (typeof property !== "string" || INTROSPECTED.has(property)) return;
|
|
70
|
+
return () => {
|
|
71
|
+
throw refuse(property);
|
|
72
|
+
};
|
|
73
|
+
} });
|
|
74
|
+
}
|
|
75
|
+
//#endregion
|
|
76
|
+
export { expiryDays as i, ExpiryDaysInvalid as n, ExpiryPrefixInvalid as r, readOnlyStorage as t };
|
|
49
77
|
|
|
50
|
-
//# sourceMappingURL=
|
|
78
|
+
//# sourceMappingURL=readOnlyStorage-DMCeLuS2.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"readOnlyStorage-DMCeLuS2.mjs","names":[],"sources":["../src/expire.ts","../src/readOnlyStorage.ts"],"sourcesContent":["/**\n * How long a bucket keeps the objects under a prefix.\n *\n * Shared by `ObjectStorage` and the bucket a `FileServer` vends, because it is\n * a fact about the bucket rather than about who serves it: a prefix of\n * generated files that nobody reads back grows for ever unless the bucket\n * itself is told to drop them.\n *\n * ```ts\n * new ObjectStorage('Private', { expire: { 'quotes/': { days: 30 } } });\n * ```\n *\n * Whole days, because that is the unit S3's lifecycle — and MinIO's — counts\n * in. Prefixes are literal: a lifecycle rule matches the start of a key and\n * has no globs, so a pattern that looks like one is refused rather than\n * silently matching nothing.\n */\nexport type ObjectExpiry = Readonly<Record<string, { readonly days: number }>>;\n\n/** An expiry prefix the bucket could not match the way it reads. */\nexport class ExpiryPrefixInvalid extends Error {\n\tconstructor(\n\t\treadonly bucket: string,\n\t\treadonly prefix: string,\n\t\treadonly reason: string,\n\t) {\n\t\tsuper(\n\t\t\t`'${bucket}' expires objects under '${prefix}', which ${reason}. ` +\n\t\t\t\t`Name the start of the keys as they are stored, e.g. 'quotes/'.`,\n\t\t);\n\t\tthis.name = 'ExpiryPrefixInvalid';\n\t}\n}\n\n/** An expiry that is not a whole number of days, one or more. */\nexport class ExpiryDaysInvalid extends Error {\n\tconstructor(\n\t\treadonly bucket: string,\n\t\treadonly prefix: string,\n\t\treadonly days: unknown,\n\t) {\n\t\tsuper(\n\t\t\t`'${bucket}' expires '${prefix}' after ${String(days)} days. A bucket ` +\n\t\t\t\t`counts lifecycle in whole days, so give an integer of 1 or more.`,\n\t\t);\n\t\tthis.name = 'ExpiryDaysInvalid';\n\t}\n}\n\n/**\n * The expiry as the manifest records it — prefix → days — after checking\n * each entry, or nothing when there is none.\n *\n * @throws {ExpiryPrefixInvalid} for an empty, rooted or globbed prefix\n * @throws {ExpiryDaysInvalid} for anything but a positive integer of days\n */\nexport function expiryDays(\n\tbucket: string,\n\texpire: ObjectExpiry | undefined,\n): Record<string, number> | undefined {\n\tif (!expire) return undefined;\n\n\tconst days: Record<string, number> = {};\n\tfor (const [prefix, { days: count }] of Object.entries(expire)) {\n\t\tif (prefix.length === 0) {\n\t\t\tthrow new ExpiryPrefixInvalid(bucket, prefix, 'is empty');\n\t\t}\n\t\tif (prefix.startsWith('/')) {\n\t\t\tthrow new ExpiryPrefixInvalid(\n\t\t\t\tbucket,\n\t\t\t\tprefix,\n\t\t\t\t\"starts with '/', which no stored key does\",\n\t\t\t);\n\t\t}\n\t\tif (/[*?]/.test(prefix)) {\n\t\t\tthrow new ExpiryPrefixInvalid(\n\t\t\t\tbucket,\n\t\t\t\tprefix,\n\t\t\t\t'is a pattern, and a lifecycle prefix is matched literally',\n\t\t\t);\n\t\t}\n\t\tif (!Number.isInteger(count) || count < 1) {\n\t\t\tthrow new ExpiryDaysInvalid(bucket, prefix, count);\n\t\t}\n\t\tdays[prefix] = count;\n\t}\n\n\treturn Object.keys(days).length > 0 ? days : undefined;\n}\n","/**\n * A storage client with no bucket behind it: what a frontend's plain edge to\n * a bucket registers, as it holds where the bucket's links are signed and\n * nothing that writes to it.\n */\n\nimport type { StorageClient } from '@geekmidas/storage';\n\n/** Names asked of any object, which a read-only client must not answer. */\nconst INTROSPECTED = new Set([\n\t'then',\n\t'toJSON',\n\t'constructor',\n\t'asymmetricMatch',\n\t'$$typeof',\n\t'nodeType',\n\t'inspect',\n]);\n\n/**\n * A client whose every method throws what `refuse` makes of its name.\n *\n * A proxy rather than a list of stubs, so a method the storage client grows\n * later refuses the same way. What a runtime asks of any object is left\n * alone: `then`, because a client is resolved from a promise, and the names a\n * serialiser or a test's printer looks for.\n */\nexport function readOnlyStorage(\n\trefuse: (method: string) => Error,\n): StorageClient {\n\treturn new Proxy({} as StorageClient, {\n\t\tget(_target, property) {\n\t\t\tif (typeof property !== 'string' || INTROSPECTED.has(property)) return;\n\t\t\treturn () => {\n\t\t\t\tthrow refuse(property);\n\t\t\t};\n\t\t},\n\t});\n}\n"],"mappings":";;AAoBA,IAAa,sBAAb,cAAyC,MAAM;CAEpC;CACA;CACA;CAHV,YACC,QACA,QACA,QACC;EACD,MACC,IAAI,OAAO,2BAA2B,OAAO,WAAW,OAAO,iEAEhE;EAPS,KAAA,SAAA;EACA,KAAA,SAAA;EACA,KAAA,SAAA;EAMT,KAAK,OAAO;CACb;AACD;;AAGA,IAAa,oBAAb,cAAuC,MAAM;CAElC;CACA;CACA;CAHV,YACC,QACA,QACA,MACC;EACD,MACC,IAAI,OAAO,aAAa,OAAO,UAAU,OAAO,IAAI,EAAE,iFAEvD;EAPS,KAAA,SAAA;EACA,KAAA,SAAA;EACA,KAAA,OAAA;EAMT,KAAK,OAAO;CACb;AACD;;;;;;;;AASA,SAAgB,WACf,QACA,QACqC;CACrC,IAAI,CAAC,QAAQ,OAAO,KAAA;CAEpB,MAAM,OAA+B,CAAC;CACtC,KAAK,MAAM,CAAC,QAAQ,EAAE,MAAM,YAAY,OAAO,QAAQ,MAAM,GAAG;EAC/D,IAAI,OAAO,WAAW,GACrB,MAAM,IAAI,oBAAoB,QAAQ,QAAQ,UAAU;EAEzD,IAAI,OAAO,WAAW,GAAG,GACxB,MAAM,IAAI,oBACT,QACA,QACA,2CACD;EAED,IAAI,OAAO,KAAK,MAAM,GACrB,MAAM,IAAI,oBACT,QACA,QACA,2DACD;EAED,IAAI,CAAC,OAAO,UAAU,KAAK,KAAK,QAAQ,GACvC,MAAM,IAAI,kBAAkB,QAAQ,QAAQ,KAAK;EAElD,KAAK,UAAU;CAChB;CAEA,OAAO,OAAO,KAAK,IAAI,CAAC,CAAC,SAAS,IAAI,OAAO,KAAA;AAC9C;;;;AC/EA,MAAM,+BAAe,IAAI,IAAI;CAC5B;CACA;CACA;CACA;CACA;CACA;CACA;AACD,CAAC;;;;;;;;;AAUD,SAAgB,gBACf,QACgB;CAChB,OAAO,IAAI,MAAM,CAAC,GAAoB,EACrC,IAAI,SAAS,UAAU;EACtB,IAAI,OAAO,aAAa,YAAY,aAAa,IAAI,QAAQ,GAAG;EAChE,aAAa;GACZ,MAAM,OAAO,QAAQ;EACtB;CACD,EACD,CAAC;AACF"}
|
package/dist/rest-api.d.cts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { i as Declarable, n as Construct, t as Authenticator } from "./construct-interface-
|
|
2
|
-
import { n as Telemetry } from "./telemetry-
|
|
3
|
-
import { D as BuiltInSecuritySchemeId } from "./Endpoint-
|
|
4
|
-
import { t as EndpointFactory } from "./EndpointFactory-
|
|
1
|
+
import { i as Declarable, n as Construct, t as Authenticator } from "./construct-interface-CVoejIpo.cjs";
|
|
2
|
+
import { n as Telemetry } from "./telemetry-BbLyS7ln.cjs";
|
|
3
|
+
import { D as BuiltInSecuritySchemeId } from "./Endpoint-COisi9jw.cjs";
|
|
4
|
+
import { t as EndpointFactory } from "./EndpointFactory-CfBg6jJE.cjs";
|
|
5
5
|
import { EnvironmentParser } from "@geekmidas/envkit";
|
|
6
6
|
import { Logger } from "@geekmidas/logger";
|
|
7
7
|
import { Service } from "@geekmidas/services";
|
package/dist/rest-api.d.mts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { i as Declarable, n as Construct, t as Authenticator } from "./construct-interface-
|
|
2
|
-
import { n as Telemetry } from "./telemetry-
|
|
3
|
-
import { D as BuiltInSecuritySchemeId } from "./Endpoint-
|
|
4
|
-
import { t as EndpointFactory } from "./EndpointFactory-
|
|
1
|
+
import { i as Declarable, n as Construct, t as Authenticator } from "./construct-interface-Nw5Dt9AC.mjs";
|
|
2
|
+
import { n as Telemetry } from "./telemetry-DWX-qKUh.mjs";
|
|
3
|
+
import { D as BuiltInSecuritySchemeId } from "./Endpoint-CIDUreMW.mjs";
|
|
4
|
+
import { t as EndpointFactory } from "./EndpointFactory-CIM80WIK.mjs";
|
|
5
5
|
import { ConstructName, Declaration, InvalidHostLabel } from "@geekmidas/manifest";
|
|
6
6
|
import { Service } from "@geekmidas/services";
|
|
7
7
|
import { EnvironmentParser } from "@geekmidas/envkit";
|
package/dist/site.cjs
CHANGED
|
@@ -134,8 +134,11 @@ var StaticSite = class StaticSite {
|
|
|
134
134
|
*
|
|
135
135
|
* A plain edge to a `FileServer` is to its public face: the site is built
|
|
136
136
|
* with the address its objects are served on, and handed nothing that
|
|
137
|
-
* writes to the bucket.
|
|
138
|
-
*
|
|
137
|
+
* writes to the bucket. A plain edge to an `ObjectStorage` is to where its
|
|
138
|
+
* links are signed (`<PREFIX><T>_SIGNED_ORIGIN`), and to nothing else of
|
|
139
|
+
* it. `.dependsOn([assets.server])` or `.dependsOn([documents.server])`
|
|
140
|
+
* asks for the bucket and its credentials too, for a server half that
|
|
141
|
+
* uploads or presigns.
|
|
139
142
|
*/
|
|
140
143
|
dependsOn(constructs) {
|
|
141
144
|
return new StaticSite(this.id, this.config, [...this.dependencies, ...constructs.map(require_construct_interface.frontendEdgeTo)]);
|
package/dist/site.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"site.cjs","names":["canonicalId","providedKeyFor","serviceKey","publicUrl","WILDCARD_SUBDOMAIN","frontendEdgeTo"],"sources":["../src/site.ts"],"sourcesContent":["/**\n * `StaticSite` — a frontend, declared like anything else.\n *\n * The point is not that a site needs provisioning; it is that a site is the\n * *consumer* whose edges make four hand-maintained lists derivable. Declaring it\n * is what turns \"which origins does the API allow\" from something a person keeps\n * in step into something the graph already knows.\n *\n * ```ts\n * export const console = new StaticSite('Console', { path: 'apps/console' })\n * .dependsOn([api, auth]);\n * ```\n *\n * A site consumes addresses, not connections: it is built, and the values it\n * needs are inlined or fetched by its own framework, so its own edges take any\n * {@link Declarable}. Its `.service` is its public address — what a worker's\n * cron or an endpoint that builds links to it reads:\n *\n * ```ts\n * export const digest = worker\n * .cron('rate(1 day)')\n * .dependsOn([web])\n * .handle(async ({ services }) => link(services.web, '/inbox'));\n * ```\n *\n * Only the static variant ships. SSR deploy shapes are unstable and each one is\n * its own maintenance, so they follow rather than arrive together. A mobile app\n * is not a site — it is reached by a scheme, not a URL — and is its own\n * construct: see `MobileApp`.\n */\n\nimport {\n\tassertHostLabels,\n\ttype ConstructName,\n\tcanonicalId,\n\ttype Declaration,\n\ttype Dependency,\n\tprovidedKeyFor,\n\ttype SiteDeclaration,\n\tserviceKey,\n\tWILDCARD_SUBDOMAIN,\n} from '@geekmidas/manifest';\n\n/** Thrown at construction for an alias or redirect that cannot be a host label. */\nexport {\n\tHostLabelBothAliasAndRedirect,\n\tInvalidHostLabel,\n\tWildcardSiteCannotHaveAliases,\n} from '@geekmidas/manifest';\n\nimport type { Service } from '@geekmidas/services';\nimport {\n\ttype Construct,\n\ttype Declarable,\n\tfrontendEdgeTo,\n\tpublicUrl,\n} from './construct-interface';\nimport type { RandomPassword } from './random-password';\nimport type { DeployedStage } from './stages';\nimport type { Telemetry } from './telemetry';\n\n/**\n * Where a site's source lives, and the little else a layout can differ by.\n *\n * Only `path` is required: `new StaticSite('Web', { path: 'apps/web' })` is a\n * complete site.\n */\nexport interface StaticSiteConfig {\n\t/**\n\t * Where its source lives, relative to the workspace root — `'apps/web'`.\n\t *\n\t * Required, the same field `RestApi` and `BetterAuth` take. It was\n\t * inferred from the id, which made a site's home whatever was on disk.\n\t */\n\tpath: string;\n\t/**\n\t * The label it answers on under a stage's domain — `api` for\n\t * `api.myapp.com`, from `domains` — and under the project locally,\n\t * `api.myapp.localhost`. Absent, its id kebab-cased.\n\t *\n\t * `'*'` answers on every subdomain nothing else does — one host per\n\t * tenant, `acme.myapp.com` — and then `hosts` names which of them are\n\t * real. Every other app keeps its own host, and a project has at most one\n\t * such site.\n\t */\n\tsubdomain?: string;\n\t/**\n\t * More labels it answers on under the stage's domain, exactly as on its\n\t * own: each a host the site really serves, and an origin every surface it\n\t * depends on trusts. Its own host stays canonical (`<ID>_URL`).\n\t */\n\taliases?: readonly string[];\n\t/**\n\t * Labels that answer with a permanent (301) redirect to its own host,\n\t * path and query kept — `['www']` sends `www.myapp.com` to `myapp.com`.\n\t * Nothing answers on a host unless a construct names it, so there is no\n\t * automatic `www`. Sites only: an API client does not reliably follow a\n\t * redirect on a `POST`.\n\t */\n\tredirects?: readonly string[];\n\t/**\n\t * With `subdomain: '*'`, the route that says which hosts are tenants: an\n\t * exported `GET` endpoint the edge asks before it serves a host,\n\t * `?domain=<host>`, answering `200` for a tenant and `404` otherwise.\n\t *\n\t * It runs without a session and belongs to no public API.\n\t */\n\thosts?: SiteHostsEndpoint;\n\t/**\n\t * The port it answers on locally.\n\t *\n\t * Normally omitted: ports are assigned in a stable order, so adding a site\n\t * does not renumber the ones already running.\n\t */\n\tport?: number;\n\t/**\n\t * Modules to import when sniffing which env vars this site reads.\n\t *\n\t * A frontend's values are inlined at build time, so the build has to know\n\t * which ones it reads before it reads them.\n\t */\n\tconfig?: { client?: string; server?: string };\n\t/**\n\t * Whether the base domain points at this site.\n\t *\n\t * A project with one site needs this no more than a project with one\n\t * database needs to say which database. It matters when there are several\n\t * and none is called `web`: the base domain then belongs to whichever site\n\t * says so, rather than to whichever file the glob happened to reach first.\n\t */\n\troot?: boolean;\n\t/**\n\t * Which framework builds it.\n\t *\n\t * It selects how values are delivered — `VITE_`, `NEXT_PUBLIC_`, a fetched\n\t * `config.json` — and never which values there are. One neutral name from the\n\t * construct, one serialisation per framework, the same rule as everywhere\n\t * else.\n\t */\n\tvariant?: SiteDeclaration['variant'];\n\t/**\n\t * What the site emits — the `Telemetry` construct. An edge to the node and\n\t * nothing more for now: a site is handed none of its server keys, and the\n\t * browser half (propagation from the generated client, then a browser SDK\n\t * exporting through the API) builds on this edge.\n\t */\n\ttelemetry?: Telemetry;\n\t/**\n\t * A login the site is served behind on the stages named, so a staging\n\t * build is not public while it is tried.\n\t *\n\t * ```ts\n\t * export const sitePassword = new RandomPassword('SitePassword');\n\t *\n\t * export const web = new StaticSite('Web', {\n\t * path: 'apps/web',\n\t * password: { secret: sitePassword, stages: ['staging'] },\n\t * });\n\t * ```\n\t *\n\t * The edge asks for it with HTTP basic auth before a request reaches the\n\t * site: the user is the stage's name, the password the `RandomPassword`'s\n\t * value on that stage. Like any `RandomPassword` it is generated on the\n\t * first deploy and kept, and one set by hand wins. It is not an edge — the\n\t * site is handed none of it — so export it from a constructs file of its\n\t * own, as any construct is.\n\t *\n\t * The compose target alone serves it so far; another refuses the stage\n\t * rather than serving it publicly.\n\t */\n\tpassword?: {\n\t\tsecret: RandomPassword;\n\t\tstages: readonly [DeployedStage, ...DeployedStage[]];\n\t};\n\t/**\n\t * `'stage'` for a `static` site that pre-renders data at build time\n\t * (vite-ssg and similar): its build fetches from the APIs it\n\t * `.dependsOn()`, and bakes their answers into its files.\n\t *\n\t * ```ts\n\t * new StaticSite('Web', {\n\t * path: 'apps/web',\n\t * variant: 'static',\n\t * prerender: 'stage',\n\t * }).dependsOn([api]);\n\t * ```\n\t *\n\t * The deploy then builds the site only once those APIs are up and\n\t * healthy on the stage, and the build reaches them at their public\n\t * addresses, as a browser would. Without it, a site is built offline,\n\t * before its stage runs (`GKM_BUILD_OFFLINE=1`), and nothing at runtime\n\t * can fill a page built without its data.\n\t *\n\t * Opt-in, because the image then holds that stage's data: the same commit\n\t * builds a different image per stage, and `gkm compose --build --push`\n\t * needs the stage it builds for already running.\n\t */\n\tprerender?: 'stage';\n}\n\n/**\n * The shape of the endpoint `hosts` names — read structurally, so a site\n * module never loads the endpoint machinery to say which route it means.\n */\nexport interface SiteHostsEndpoint {\n\troute: string;\n\tmethod: string;\n\tsurface: { id: string };\n}\n\n/** `subdomain: '*'` without `hosts`: nothing would say which hosts are tenants. */\nexport class WildcardSiteNeedsHosts extends Error {\n\tconstructor(readonly id: string) {\n\t\tsuper(\n\t\t\t`'${id}' answers on every subdomain, so it has to say which of them ` +\n\t\t\t\t`are tenants: pass \\`hosts\\`, a GET endpoint answering 200 for a ` +\n\t\t\t\t`host it serves and 404 otherwise.`,\n\t\t);\n\t\tthis.name = 'WildcardSiteNeedsHosts';\n\t}\n}\n\n/** `hosts` on a site with one host, where there is nothing to check. */\nexport class SiteHostsNeedsWildcard extends Error {\n\tconstructor(readonly id: string) {\n\t\tsuper(\n\t\t\t`'${id}' names a \\`hosts\\` check but answers on one host. ` +\n\t\t\t\t`Declare \\`subdomain: '*'\\` to serve every subdomain, or drop \\`hosts\\`.`,\n\t\t);\n\t\tthis.name = 'SiteHostsNeedsWildcard';\n\t}\n}\n\n/** A `hosts` endpoint that is not a `GET`: the edge only ever asks with one. */\nexport class SiteHostsNotGet extends Error {\n\tconstructor(\n\t\treadonly id: string,\n\t\treadonly method: string,\n\t\treadonly route: string,\n\t) {\n\t\tsuper(\n\t\t\t`'${id}' checks its hosts with ${method} ${route}, but the edge asks ` +\n\t\t\t\t`with GET ${route}?domain=<host>. Make it a GET endpoint.`,\n\t\t);\n\t\tthis.name = 'SiteHostsNotGet';\n\t}\n}\n\n/**\n * `prerender: 'stage'` on a site that renders its pages on a server, where a\n * page renders on its first request — which the deploy's warm-up makes — and\n * needs no data at build.\n */\nexport class PrerenderNeedsStaticSite extends Error {\n\tconstructor(\n\t\treadonly id: string,\n\t\treadonly variant: SiteDeclaration['variant'],\n\t) {\n\t\tsuper(\n\t\t\t`'${id}' is a '${variant}' site, which renders its pages on its own ` +\n\t\t\t\t`server, so it never needs its APIs at build: drop \\`prerender\\`, ` +\n\t\t\t\t`and render data-backed pages on request (the deploy warms them). ` +\n\t\t\t\t`\\`prerender: 'stage'\\` is for a 'static' site that bakes data into ` +\n\t\t\t\t`its files.`,\n\t\t);\n\t\tthis.name = 'PrerenderNeedsStaticSite';\n\t}\n}\n\n/** A wildcard site that says it holds the base domain. */\nexport class WildcardSiteCannotBeRoot extends Error {\n\tconstructor(readonly id: string) {\n\t\tsuper(\n\t\t\t`'${id}' answers on every subdomain, so it cannot also hold the base ` +\n\t\t\t\t`domain. Drop \\`root: true\\`, and declare the site the base domain ` +\n\t\t\t\t`points at separately.`,\n\t\t);\n\t\tthis.name = 'WildcardSiteCannotBeRoot';\n\t}\n}\n\nexport class StaticSite<TName extends string = string>\n\timplements Declarable<TName>, Construct<TName, string>\n{\n\treadonly id: TName;\n\treadonly keys: { url: string };\n\n\t/**\n\t * Its public address, `https://web.example.com` — a string, no await. The\n\t * same `<ID>_URL` on every command and stage, so a link built from it opens\n\t * in a browser.\n\t */\n\treadonly service: Service<Uncapitalize<TName>, string>;\n\n\tconstructor(\n\t\tid: ConstructName<TName>,\n\t\tprivate readonly config: StaticSiteConfig,\n\t\t/**\n\t\t * Internal: how `.dependsOn()` carries edges into the copy it returns.\n\t\t * Written as a parameter rather than a mutable field so the builder can\n\t\t * stay immutable without a clone method, the same shape\n\t\t * `KyselyDatabase` uses for its derived forms.\n\t\t */\n\t\tprivate readonly dependencies: readonly Dependency[] = [],\n\t) {\n\t\tthis.id = canonicalId(id as string) as TName;\n\t\tthis.keys = { url: providedKeyFor(this.id, 'site', 'url') };\n\t\t// A field, not a getter: consumers cache services by object identity.\n\t\tthis.service = {\n\t\t\tserviceName: serviceKey(this.id) as Uncapitalize<TName>,\n\t\t\tregister: (options) => publicUrl(options, this.keys.url),\n\t\t};\n\n\t\tconst wildcard = config.subdomain === WILDCARD_SUBDOMAIN;\n\t\tif (wildcard && !config.hosts) throw new WildcardSiteNeedsHosts(this.id);\n\t\tif (!wildcard && config.hosts) throw new SiteHostsNeedsWildcard(this.id);\n\t\tif (wildcard && config.root) throw new WildcardSiteCannotBeRoot(this.id);\n\t\tassertHostLabels({\n\t\t\tid: this.id,\n\t\t\t...(config.subdomain ? { subdomain: config.subdomain } : {}),\n\t\t\t...(config.aliases ? { aliases: config.aliases } : {}),\n\t\t\t...(config.redirects ? { redirects: config.redirects } : {}),\n\t\t});\n\t\tconst variant = config.variant ?? 'static';\n\t\tif (config.prerender && variant !== 'static') {\n\t\t\tthrow new PrerenderNeedsStaticSite(this.id, variant);\n\t\t}\n\t\tif (config.hosts && config.hosts.method.toUpperCase() !== 'GET') {\n\t\t\tthrow new SiteHostsNotGet(\n\t\t\t\tthis.id,\n\t\t\t\tconfig.hosts.method,\n\t\t\t\tconfig.hosts.route,\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * What this site calls.\n\t *\n\t * Immutable, like every other builder here: it returns a new site rather than\n\t * mutating this one, so a module that exports both a base and a variant of it\n\t * cannot have the second silently change the first.\n\t *\n\t * Takes {@link Declarable} rather than {@link Consumable} because a site's\n\t * edge is a build-time link and not a service injection — requiring a client\n\t * would exclude exactly the surfaces a frontend actually depends on.\n\t *\n\t * A plain edge to a `FileServer` is to its public face: the site is built\n\t * with the address its objects are served on, and handed nothing that\n\t * writes to the bucket. `.dependsOn([assets.server])` asks for the bucket\n\t * too, for a server half that uploads.\n\t */\n\tdependsOn(constructs: readonly Declarable[]): StaticSite<TName> {\n\t\treturn new StaticSite<TName>(this.id as ConstructName<TName>, this.config, [\n\t\t\t...this.dependencies,\n\t\t\t...constructs.map(frontendEdgeTo),\n\t\t]);\n\t}\n\n\tdeclare(): Declaration[] {\n\t\tconst { hosts } = this.config;\n\t\treturn [\n\t\t\t{\n\t\t\t\tkind: 'site',\n\t\t\t\tid: this.id,\n\t\t\t\tvariant: this.config.variant ?? 'static',\n\t\t\t\t...(this.config.subdomain ? { subdomain: this.config.subdomain } : {}),\n\t\t\t\t...(this.config.aliases?.length\n\t\t\t\t\t? { aliases: [...this.config.aliases] }\n\t\t\t\t\t: {}),\n\t\t\t\t...(this.config.redirects?.length\n\t\t\t\t\t? { redirects: [...this.config.redirects] }\n\t\t\t\t\t: {}),\n\t\t\t\t...(hosts\n\t\t\t\t\t? {\n\t\t\t\t\t\t\thosts: {\n\t\t\t\t\t\t\t\tsurface: canonicalId(hosts.surface.id),\n\t\t\t\t\t\t\t\tpath: hosts.route,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t}\n\t\t\t\t\t: {}),\n\t\t\t\tapp: {\n\t\t\t\t\tpath: this.config.path,\n\t\t\t\t\t...(this.config.port ? { port: this.config.port } : {}),\n\t\t\t\t\t...(this.config.config ? { config: this.config.config } : {}),\n\t\t\t\t},\n\t\t\t\t...(this.config.root ? { root: true } : {}),\n\t\t\t\tdependencies: this.dependencies,\n\t\t\t\t...(this.config.telemetry\n\t\t\t\t\t? { telemetry: this.config.telemetry.id }\n\t\t\t\t\t: {}),\n\t\t\t\t...(this.config.password\n\t\t\t\t\t? {\n\t\t\t\t\t\t\tpassword: {\n\t\t\t\t\t\t\t\tsecret: this.config.password.secret.id,\n\t\t\t\t\t\t\t\tstages: [...this.config.password.stages],\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t}\n\t\t\t\t\t: {}),\n\t\t\t\t...(this.config.prerender ? { prerender: this.config.prerender } : {}),\n\t\t\t\tprovides: [\n\t\t\t\t\tthis.keys.url,\n\t\t\t\t\t...(hosts\n\t\t\t\t\t\t? [\n\t\t\t\t\t\t\t\tprovidedKeyFor(this.id, 'site', 'domain'),\n\t\t\t\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AAW,KAAK,OAAO,UAAU,IAAI,CAAC;GACpE,GAAI,KAAK,OAAO,SAAS,SACtB,EAAE,SAAS,CAAC,GAAG,KAAK,OAAO,OAAO,EAAE,IACpC,CAAC;GACJ,GAAI,KAAK,OAAO,WAAW,SACxB,EAAE,WAAW,CAAC,GAAG,KAAK,OAAO,SAAS,EAAE,IACxC,CAAC;GACJ,GAAI,QACD,EACA,OAAO;IACN,UAAA,GAASL,oBAAAA,YAAAA,CAAY,MAAM,QAAQ,EAAE;IACrC,MAAM,MAAM;GACb,EACD,IACC,CAAC;GACJ,KAAK;IACJ,MAAM,KAAK,OAAO;IAClB,GAAI,KAAK,OAAO,OAAO,EAAE,MAAM,KAAK,OAAO,KAAK,IAAI,CAAC;IACrD,GAAI,KAAK,OAAO,SAAS,EAAE,QAAQ,KAAK,OAAO,OAAO,IAAI,CAAC;GAC5D;GACA,GAAI,KAAK,OAAO,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;GACzC,cAAc,KAAK;GACnB,GAAI,KAAK,OAAO,YACb,EAAE,WAAW,KAAK,OAAO,UAAU,GAAG,IACtC,CAAC;GACJ,GAAI,KAAK,OAAO,WACb,EACA,UAAU;IACT,QAAQ,KAAK,OAAO,SAAS,OAAO;IACpC,QAAQ,CAAC,GAAG,KAAK,OAAO,SAAS,MAAM;GACxC,EACD,IACC,CAAC;GACJ,GAAI,KAAK,OAAO,YAAY,EAAE,WAAW,KAAK,OAAO,UAAU,IAAI,CAAC;GACpE,UAAU,CACT,KAAK,KAAK,KACV,GAAI,QACD,EAAA,GACAC,oBAAAA,eAAAA,CAAe,KAAK,IAAI,QAAQ,QAAQ,IAAA,GACxCA,oBAAAA,eAAAA,CAAe,KAAK,IAAI,QAAQ,qBAAqB,CACtD,IACC,CAAC,CACL;EACD,CACD;CACD;AACD"}
|
|
1
|
+
{"version":3,"file":"site.cjs","names":["canonicalId","providedKeyFor","serviceKey","publicUrl","WILDCARD_SUBDOMAIN","frontendEdgeTo"],"sources":["../src/site.ts"],"sourcesContent":["/**\n * `StaticSite` — a frontend, declared like anything else.\n *\n * The point is not that a site needs provisioning; it is that a site is the\n * *consumer* whose edges make four hand-maintained lists derivable. Declaring it\n * is what turns \"which origins does the API allow\" from something a person keeps\n * in step into something the graph already knows.\n *\n * ```ts\n * export const console = new StaticSite('Console', { path: 'apps/console' })\n * .dependsOn([api, auth]);\n * ```\n *\n * A site consumes addresses, not connections: it is built, and the values it\n * needs are inlined or fetched by its own framework, so its own edges take any\n * {@link Declarable}. Its `.service` is its public address — what a worker's\n * cron or an endpoint that builds links to it reads:\n *\n * ```ts\n * export const digest = worker\n * .cron('rate(1 day)')\n * .dependsOn([web])\n * .handle(async ({ services }) => link(services.web, '/inbox'));\n * ```\n *\n * Only the static variant ships. SSR deploy shapes are unstable and each one is\n * its own maintenance, so they follow rather than arrive together. A mobile app\n * is not a site — it is reached by a scheme, not a URL — and is its own\n * construct: see `MobileApp`.\n */\n\nimport {\n\tassertHostLabels,\n\ttype ConstructName,\n\tcanonicalId,\n\ttype Declaration,\n\ttype Dependency,\n\tprovidedKeyFor,\n\ttype SiteDeclaration,\n\tserviceKey,\n\tWILDCARD_SUBDOMAIN,\n} from '@geekmidas/manifest';\n\n/** Thrown at construction for an alias or redirect that cannot be a host label. */\nexport {\n\tHostLabelBothAliasAndRedirect,\n\tInvalidHostLabel,\n\tWildcardSiteCannotHaveAliases,\n} from '@geekmidas/manifest';\n\nimport type { Service } from '@geekmidas/services';\nimport {\n\ttype Construct,\n\ttype Declarable,\n\tfrontendEdgeTo,\n\tpublicUrl,\n} from './construct-interface';\nimport type { RandomPassword } from './random-password';\nimport type { DeployedStage } from './stages';\nimport type { Telemetry } from './telemetry';\n\n/**\n * Where a site's source lives, and the little else a layout can differ by.\n *\n * Only `path` is required: `new StaticSite('Web', { path: 'apps/web' })` is a\n * complete site.\n */\nexport interface StaticSiteConfig {\n\t/**\n\t * Where its source lives, relative to the workspace root — `'apps/web'`.\n\t *\n\t * Required, the same field `RestApi` and `BetterAuth` take. It was\n\t * inferred from the id, which made a site's home whatever was on disk.\n\t */\n\tpath: string;\n\t/**\n\t * The label it answers on under a stage's domain — `api` for\n\t * `api.myapp.com`, from `domains` — and under the project locally,\n\t * `api.myapp.localhost`. Absent, its id kebab-cased.\n\t *\n\t * `'*'` answers on every subdomain nothing else does — one host per\n\t * tenant, `acme.myapp.com` — and then `hosts` names which of them are\n\t * real. Every other app keeps its own host, and a project has at most one\n\t * such site.\n\t */\n\tsubdomain?: string;\n\t/**\n\t * More labels it answers on under the stage's domain, exactly as on its\n\t * own: each a host the site really serves, and an origin every surface it\n\t * depends on trusts. Its own host stays canonical (`<ID>_URL`).\n\t */\n\taliases?: readonly string[];\n\t/**\n\t * Labels that answer with a permanent (301) redirect to its own host,\n\t * path and query kept — `['www']` sends `www.myapp.com` to `myapp.com`.\n\t * Nothing answers on a host unless a construct names it, so there is no\n\t * automatic `www`. Sites only: an API client does not reliably follow a\n\t * redirect on a `POST`.\n\t */\n\tredirects?: readonly string[];\n\t/**\n\t * With `subdomain: '*'`, the route that says which hosts are tenants: an\n\t * exported `GET` endpoint the edge asks before it serves a host,\n\t * `?domain=<host>`, answering `200` for a tenant and `404` otherwise.\n\t *\n\t * It runs without a session and belongs to no public API.\n\t */\n\thosts?: SiteHostsEndpoint;\n\t/**\n\t * The port it answers on locally.\n\t *\n\t * Normally omitted: ports are assigned in a stable order, so adding a site\n\t * does not renumber the ones already running.\n\t */\n\tport?: number;\n\t/**\n\t * Modules to import when sniffing which env vars this site reads.\n\t *\n\t * A frontend's values are inlined at build time, so the build has to know\n\t * which ones it reads before it reads them.\n\t */\n\tconfig?: { client?: string; server?: string };\n\t/**\n\t * Whether the base domain points at this site.\n\t *\n\t * A project with one site needs this no more than a project with one\n\t * database needs to say which database. It matters when there are several\n\t * and none is called `web`: the base domain then belongs to whichever site\n\t * says so, rather than to whichever file the glob happened to reach first.\n\t */\n\troot?: boolean;\n\t/**\n\t * Which framework builds it.\n\t *\n\t * It selects how values are delivered — `VITE_`, `NEXT_PUBLIC_`, a fetched\n\t * `config.json` — and never which values there are. One neutral name from the\n\t * construct, one serialisation per framework, the same rule as everywhere\n\t * else.\n\t */\n\tvariant?: SiteDeclaration['variant'];\n\t/**\n\t * What the site emits — the `Telemetry` construct. An edge to the node and\n\t * nothing more for now: a site is handed none of its server keys, and the\n\t * browser half (propagation from the generated client, then a browser SDK\n\t * exporting through the API) builds on this edge.\n\t */\n\ttelemetry?: Telemetry;\n\t/**\n\t * A login the site is served behind on the stages named, so a staging\n\t * build is not public while it is tried.\n\t *\n\t * ```ts\n\t * export const sitePassword = new RandomPassword('SitePassword');\n\t *\n\t * export const web = new StaticSite('Web', {\n\t * path: 'apps/web',\n\t * password: { secret: sitePassword, stages: ['staging'] },\n\t * });\n\t * ```\n\t *\n\t * The edge asks for it with HTTP basic auth before a request reaches the\n\t * site: the user is the stage's name, the password the `RandomPassword`'s\n\t * value on that stage. Like any `RandomPassword` it is generated on the\n\t * first deploy and kept, and one set by hand wins. It is not an edge — the\n\t * site is handed none of it — so export it from a constructs file of its\n\t * own, as any construct is.\n\t *\n\t * The compose target alone serves it so far; another refuses the stage\n\t * rather than serving it publicly.\n\t */\n\tpassword?: {\n\t\tsecret: RandomPassword;\n\t\tstages: readonly [DeployedStage, ...DeployedStage[]];\n\t};\n\t/**\n\t * `'stage'` for a `static` site that pre-renders data at build time\n\t * (vite-ssg and similar): its build fetches from the APIs it\n\t * `.dependsOn()`, and bakes their answers into its files.\n\t *\n\t * ```ts\n\t * new StaticSite('Web', {\n\t * path: 'apps/web',\n\t * variant: 'static',\n\t * prerender: 'stage',\n\t * }).dependsOn([api]);\n\t * ```\n\t *\n\t * The deploy then builds the site only once those APIs are up and\n\t * healthy on the stage, and the build reaches them at their public\n\t * addresses, as a browser would. Without it, a site is built offline,\n\t * before its stage runs (`GKM_BUILD_OFFLINE=1`), and nothing at runtime\n\t * can fill a page built without its data.\n\t *\n\t * Opt-in, because the image then holds that stage's data: the same commit\n\t * builds a different image per stage, and `gkm compose --build --push`\n\t * needs the stage it builds for already running.\n\t */\n\tprerender?: 'stage';\n}\n\n/**\n * The shape of the endpoint `hosts` names — read structurally, so a site\n * module never loads the endpoint machinery to say which route it means.\n */\nexport interface SiteHostsEndpoint {\n\troute: string;\n\tmethod: string;\n\tsurface: { id: string };\n}\n\n/** `subdomain: '*'` without `hosts`: nothing would say which hosts are tenants. */\nexport class WildcardSiteNeedsHosts extends Error {\n\tconstructor(readonly id: string) {\n\t\tsuper(\n\t\t\t`'${id}' answers on every subdomain, so it has to say which of them ` +\n\t\t\t\t`are tenants: pass \\`hosts\\`, a GET endpoint answering 200 for a ` +\n\t\t\t\t`host it serves and 404 otherwise.`,\n\t\t);\n\t\tthis.name = 'WildcardSiteNeedsHosts';\n\t}\n}\n\n/** `hosts` on a site with one host, where there is nothing to check. */\nexport class SiteHostsNeedsWildcard extends Error {\n\tconstructor(readonly id: string) {\n\t\tsuper(\n\t\t\t`'${id}' names a \\`hosts\\` check but answers on one host. ` +\n\t\t\t\t`Declare \\`subdomain: '*'\\` to serve every subdomain, or drop \\`hosts\\`.`,\n\t\t);\n\t\tthis.name = 'SiteHostsNeedsWildcard';\n\t}\n}\n\n/** A `hosts` endpoint that is not a `GET`: the edge only ever asks with one. */\nexport class SiteHostsNotGet extends Error {\n\tconstructor(\n\t\treadonly id: string,\n\t\treadonly method: string,\n\t\treadonly route: string,\n\t) {\n\t\tsuper(\n\t\t\t`'${id}' checks its hosts with ${method} ${route}, but the edge asks ` +\n\t\t\t\t`with GET ${route}?domain=<host>. Make it a GET endpoint.`,\n\t\t);\n\t\tthis.name = 'SiteHostsNotGet';\n\t}\n}\n\n/**\n * `prerender: 'stage'` on a site that renders its pages on a server, where a\n * page renders on its first request — which the deploy's warm-up makes — and\n * needs no data at build.\n */\nexport class PrerenderNeedsStaticSite extends Error {\n\tconstructor(\n\t\treadonly id: string,\n\t\treadonly variant: SiteDeclaration['variant'],\n\t) {\n\t\tsuper(\n\t\t\t`'${id}' is a '${variant}' site, which renders its pages on its own ` +\n\t\t\t\t`server, so it never needs its APIs at build: drop \\`prerender\\`, ` +\n\t\t\t\t`and render data-backed pages on request (the deploy warms them). ` +\n\t\t\t\t`\\`prerender: 'stage'\\` is for a 'static' site that bakes data into ` +\n\t\t\t\t`its files.`,\n\t\t);\n\t\tthis.name = 'PrerenderNeedsStaticSite';\n\t}\n}\n\n/** A wildcard site that says it holds the base domain. */\nexport class WildcardSiteCannotBeRoot extends Error {\n\tconstructor(readonly id: string) {\n\t\tsuper(\n\t\t\t`'${id}' answers on every subdomain, so it cannot also hold the base ` +\n\t\t\t\t`domain. Drop \\`root: true\\`, and declare the site the base domain ` +\n\t\t\t\t`points at separately.`,\n\t\t);\n\t\tthis.name = 'WildcardSiteCannotBeRoot';\n\t}\n}\n\nexport class StaticSite<TName extends string = string>\n\timplements Declarable<TName>, Construct<TName, string>\n{\n\treadonly id: TName;\n\treadonly keys: { url: string };\n\n\t/**\n\t * Its public address, `https://web.example.com` — a string, no await. The\n\t * same `<ID>_URL` on every command and stage, so a link built from it opens\n\t * in a browser.\n\t */\n\treadonly service: Service<Uncapitalize<TName>, string>;\n\n\tconstructor(\n\t\tid: ConstructName<TName>,\n\t\tprivate readonly config: StaticSiteConfig,\n\t\t/**\n\t\t * Internal: how `.dependsOn()` carries edges into the copy it returns.\n\t\t * Written as a parameter rather than a mutable field so the builder can\n\t\t * stay immutable without a clone method, the same shape\n\t\t * `KyselyDatabase` uses for its derived forms.\n\t\t */\n\t\tprivate readonly dependencies: readonly Dependency[] = [],\n\t) {\n\t\tthis.id = canonicalId(id as string) as TName;\n\t\tthis.keys = { url: providedKeyFor(this.id, 'site', 'url') };\n\t\t// A field, not a getter: consumers cache services by object identity.\n\t\tthis.service = {\n\t\t\tserviceName: serviceKey(this.id) as Uncapitalize<TName>,\n\t\t\tregister: (options) => publicUrl(options, this.keys.url),\n\t\t};\n\n\t\tconst wildcard = config.subdomain === WILDCARD_SUBDOMAIN;\n\t\tif (wildcard && !config.hosts) throw new WildcardSiteNeedsHosts(this.id);\n\t\tif (!wildcard && config.hosts) throw new SiteHostsNeedsWildcard(this.id);\n\t\tif (wildcard && config.root) throw new WildcardSiteCannotBeRoot(this.id);\n\t\tassertHostLabels({\n\t\t\tid: this.id,\n\t\t\t...(config.subdomain ? { subdomain: config.subdomain } : {}),\n\t\t\t...(config.aliases ? { aliases: config.aliases } : {}),\n\t\t\t...(config.redirects ? { redirects: config.redirects } : {}),\n\t\t});\n\t\tconst variant = config.variant ?? 'static';\n\t\tif (config.prerender && variant !== 'static') {\n\t\t\tthrow new PrerenderNeedsStaticSite(this.id, variant);\n\t\t}\n\t\tif (config.hosts && config.hosts.method.toUpperCase() !== 'GET') {\n\t\t\tthrow new SiteHostsNotGet(\n\t\t\t\tthis.id,\n\t\t\t\tconfig.hosts.method,\n\t\t\t\tconfig.hosts.route,\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * What this site calls.\n\t *\n\t * Immutable, like every other builder here: it returns a new site rather than\n\t * mutating this one, so a module that exports both a base and a variant of it\n\t * cannot have the second silently change the first.\n\t *\n\t * Takes {@link Declarable} rather than {@link Consumable} because a site's\n\t * edge is a build-time link and not a service injection — requiring a client\n\t * would exclude exactly the surfaces a frontend actually depends on.\n\t *\n\t * A plain edge to a `FileServer` is to its public face: the site is built\n\t * with the address its objects are served on, and handed nothing that\n\t * writes to the bucket. A plain edge to an `ObjectStorage` is to where its\n\t * links are signed (`<PREFIX><T>_SIGNED_ORIGIN`), and to nothing else of\n\t * it. `.dependsOn([assets.server])` or `.dependsOn([documents.server])`\n\t * asks for the bucket and its credentials too, for a server half that\n\t * uploads or presigns.\n\t */\n\tdependsOn(constructs: readonly Declarable[]): StaticSite<TName> {\n\t\treturn new StaticSite<TName>(this.id as ConstructName<TName>, this.config, [\n\t\t\t...this.dependencies,\n\t\t\t...constructs.map(frontendEdgeTo),\n\t\t]);\n\t}\n\n\tdeclare(): Declaration[] {\n\t\tconst { hosts } = this.config;\n\t\treturn [\n\t\t\t{\n\t\t\t\tkind: 'site',\n\t\t\t\tid: this.id,\n\t\t\t\tvariant: this.config.variant ?? 'static',\n\t\t\t\t...(this.config.subdomain ? { subdomain: this.config.subdomain } : {}),\n\t\t\t\t...(this.config.aliases?.length\n\t\t\t\t\t? { aliases: [...this.config.aliases] }\n\t\t\t\t\t: {}),\n\t\t\t\t...(this.config.redirects?.length\n\t\t\t\t\t? { redirects: [...this.config.redirects] }\n\t\t\t\t\t: {}),\n\t\t\t\t...(hosts\n\t\t\t\t\t? {\n\t\t\t\t\t\t\thosts: {\n\t\t\t\t\t\t\t\tsurface: canonicalId(hosts.surface.id),\n\t\t\t\t\t\t\t\tpath: hosts.route,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t}\n\t\t\t\t\t: {}),\n\t\t\t\tapp: {\n\t\t\t\t\tpath: this.config.path,\n\t\t\t\t\t...(this.config.port ? { port: this.config.port } : {}),\n\t\t\t\t\t...(this.config.config ? { config: this.config.config } : {}),\n\t\t\t\t},\n\t\t\t\t...(this.config.root ? { root: true } : {}),\n\t\t\t\tdependencies: this.dependencies,\n\t\t\t\t...(this.config.telemetry\n\t\t\t\t\t? { telemetry: this.config.telemetry.id }\n\t\t\t\t\t: {}),\n\t\t\t\t...(this.config.password\n\t\t\t\t\t? {\n\t\t\t\t\t\t\tpassword: {\n\t\t\t\t\t\t\t\tsecret: this.config.password.secret.id,\n\t\t\t\t\t\t\t\tstages: [...this.config.password.stages],\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t}\n\t\t\t\t\t: {}),\n\t\t\t\t...(this.config.prerender ? { prerender: this.config.prerender } : {}),\n\t\t\t\tprovides: [\n\t\t\t\t\tthis.keys.url,\n\t\t\t\t\t...(hosts\n\t\t\t\t\t\t? [\n\t\t\t\t\t\t\t\tprovidedKeyFor(this.id, 'site', 'domain'),\n\t\t\t\t\t\t\t\tprovidedKeyFor(this.id, 'site', 'protectedSubdomains'),\n\t\t\t\t\t\t\t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S,SACtB,EAAE,SAAS,CAAC,GAAG,KAAK,OAAO,OAAO,EAAE,IACpC,CAAC;GACJ,GAAI,KAAK,OAAO,WAAW,SACxB,EAAE,WAAW,CAAC,GAAG,KAAK,OAAO,SAAS,EAAE,IACxC,CAAC;GACJ,GAAI,QACD,EACA,OAAO;IACN,UAAA,GAASL,oBAAAA,YAAAA,CAAY,MAAM,QAAQ,EAAE;IACrC,MAAM,MAAM;GACb,EACD,IACC,CAAC;GACJ,KAAK;IACJ,MAAM,KAAK,OAAO;IAClB,GAAI,KAAK,OAAO,OAAO,EAAE,MAAM,KAAK,OAAO,KAAK,IAAI,CAAC;IACrD,GAAI,KAAK,OAAO,SAAS,EAAE,QAAQ,KAAK,OAAO,OAAO,IAAI,CAAC;GAC5D;GACA,GAAI,KAAK,OAAO,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;GACzC,cAAc,KAAK;GACnB,GAAI,KAAK,OAAO,YACb,EAAE,WAAW,KAAK,OAAO,UAAU,GAAG,IACtC,CAAC;GACJ,GAAI,KAAK,OAAO,WACb,EACA,UAAU;IACT,QAAQ,KAAK,OAAO,SAAS,OAAO;IACpC,QAAQ,CAAC,GAAG,KAAK,OAAO,SAAS,MAAM;GACxC,EACD,IACC,CAAC;GACJ,GAAI,KAAK,OAAO,YAAY,EAAE,WAAW,KAAK,OAAO,UAAU,IAAI,CAAC;GACpE,UAAU,CACT,KAAK,KAAK,KACV,GAAI,QACD,EAAA,GACAC,oBAAAA,eAAAA,CAAe,KAAK,IAAI,QAAQ,QAAQ,IAAA,GACxCA,oBAAAA,eAAAA,CAAe,KAAK,IAAI,QAAQ,qBAAqB,CACtD,IACC,CAAC,CACL;EACD,CACD;CACD;AACD"}
|
package/dist/site.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { i as Declarable, n as Construct } from "./construct-interface-
|
|
2
|
-
import { n as Telemetry } from "./telemetry-
|
|
1
|
+
import { i as Declarable, n as Construct } from "./construct-interface-CVoejIpo.cjs";
|
|
2
|
+
import { n as Telemetry } from "./telemetry-BbLyS7ln.cjs";
|
|
3
3
|
import { n as DeployedStage } from "./stages-DaTaoQei.cjs";
|
|
4
4
|
import { RandomPassword } from "./random-password.cjs";
|
|
5
5
|
import { Service } from "@geekmidas/services";
|
|
@@ -229,8 +229,11 @@ export declare class StaticSite<TName extends string = string> implements Declar
|
|
|
229
229
|
*
|
|
230
230
|
* A plain edge to a `FileServer` is to its public face: the site is built
|
|
231
231
|
* with the address its objects are served on, and handed nothing that
|
|
232
|
-
* writes to the bucket.
|
|
233
|
-
*
|
|
232
|
+
* writes to the bucket. A plain edge to an `ObjectStorage` is to where its
|
|
233
|
+
* links are signed (`<PREFIX><T>_SIGNED_ORIGIN`), and to nothing else of
|
|
234
|
+
* it. `.dependsOn([assets.server])` or `.dependsOn([documents.server])`
|
|
235
|
+
* asks for the bucket and its credentials too, for a server half that
|
|
236
|
+
* uploads or presigns.
|
|
234
237
|
*/
|
|
235
238
|
dependsOn(constructs: readonly Declarable[]): StaticSite<TName>;
|
|
236
239
|
declare(): Declaration[];
|
package/dist/site.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"site.d.cts","names":[],"sources":["../src/site.ts"],"mappings":";;;;;;;;;;;;;iBAmEiB;;;;;;;EAOhB;;;;;;;;;;;EAWA;;;;;;EAMA;;;;;;;;EAQA;;;;;;;;EAQA,QAAQ;;;;;;;EAOR;;;;;;;EAOA;IAAW;IAAiB;;;;;;;;;;EAS5B;;;;;;;;;EASA,UAAU;;;;;;;EAOV,YAAY;;;;;;;;;;;;;;;;;;;;;;;;EAwBZ;IACC,QAAQ;IACR,kBAAkB,kBAAkB;;;;;;;;;;;;;;;;;;;;;;;;;EAyBrC;;;;;;iBAOgB;EAChB;EACA;EACA;IAAW;;;;qBAIC,+BAA+B;WACtB;EAArB,YAAqB;;;qBAWT,+BAA+B;WACtB;EAArB,YAAqB;;;qBAUT,wBAAwB;WAE1B;WACA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ANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { i as Declarable, n as Construct } from "./construct-interface-
|
|
2
|
-
import { n as Telemetry } from "./telemetry-
|
|
1
|
+
import { i as Declarable, n as Construct } from "./construct-interface-Nw5Dt9AC.mjs";
|
|
2
|
+
import { n as Telemetry } from "./telemetry-DWX-qKUh.mjs";
|
|
3
3
|
import { n as DeployedStage } from "./stages-DaTaoQei.mjs";
|
|
4
4
|
import { RandomPassword } from "./random-password.mjs";
|
|
5
5
|
import { ConstructName, Declaration, Dependency, HostLabelBothAliasAndRedirect, InvalidHostLabel, SiteDeclaration, WildcardSiteCannotHaveAliases } from "@geekmidas/manifest";
|
|
@@ -229,8 +229,11 @@ export declare class StaticSite<TName extends string = string> implements Declar
|
|
|
229
229
|
*
|
|
230
230
|
* A plain edge to a `FileServer` is to its public face: the site is built
|
|
231
231
|
* with the address its objects are served on, and handed nothing that
|
|
232
|
-
* writes to the bucket.
|
|
233
|
-
*
|
|
232
|
+
* writes to the bucket. A plain edge to an `ObjectStorage` is to where its
|
|
233
|
+
* links are signed (`<PREFIX><T>_SIGNED_ORIGIN`), and to nothing else of
|
|
234
|
+
* it. `.dependsOn([assets.server])` or `.dependsOn([documents.server])`
|
|
235
|
+
* asks for the bucket and its credentials too, for a server half that
|
|
236
|
+
* uploads or presigns.
|
|
234
237
|
*/
|
|
235
238
|
dependsOn(constructs: readonly Declarable[]): StaticSite<TName>;
|
|
236
239
|
declare(): Declaration[];
|
package/dist/site.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"site.d.mts","names":[],"sources":["../src/site.ts"],"mappings":";;;;;;;;;;;;;iBAmEiB;;;;;;;EAOhB;;;;;;;;;;;EAWA;;;;;;EAMA;;;;;;;;EAQA;;;;;;;;EAQA,QAAQ;;;;;;;EAOR;;;;;;;EAOA;IAAW;IAAiB;;;;;;;;;;EAS5B;;;;;;;;;EASA,UAAU;;;;;;;EAOV,YAAY;;;;;;;;;;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mBActB;;;;;;;mBAOA;WAnBT,IAAI;WACJ;IAAQ;;;;;;;WAOR,SAAS,QAAQ,aAAa;EAEvC,YACC,IAAI,cAAc,QACD,QAAQ,kBAOR;;;;;;;EAAA,wBAAuB;;;;;;;;;;;;;;;;;;;;EAoDzC,UAAU,qBAAqB,eAAe,WAAW;EAOzD,WAAW"}
|
package/dist/site.mjs
CHANGED
|
@@ -133,8 +133,11 @@ var StaticSite = class StaticSite {
|
|
|
133
133
|
*
|
|
134
134
|
* A plain edge to a `FileServer` is to its public face: the site is built
|
|
135
135
|
* with the address its objects are served on, and handed nothing that
|
|
136
|
-
* writes to the bucket.
|
|
137
|
-
*
|
|
136
|
+
* writes to the bucket. A plain edge to an `ObjectStorage` is to where its
|
|
137
|
+
* links are signed (`<PREFIX><T>_SIGNED_ORIGIN`), and to nothing else of
|
|
138
|
+
* it. `.dependsOn([assets.server])` or `.dependsOn([documents.server])`
|
|
139
|
+
* asks for the bucket and its credentials too, for a server half that
|
|
140
|
+
* uploads or presigns.
|
|
138
141
|
*/
|
|
139
142
|
dependsOn(constructs) {
|
|
140
143
|
return new StaticSite(this.id, this.config, [...this.dependencies, ...constructs.map(frontendEdgeTo)]);
|
package/dist/site.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"site.mjs","names":[],"sources":["../src/site.ts"],"sourcesContent":["/**\n * `StaticSite` — a frontend, declared like anything else.\n *\n * The point is not that a site needs provisioning; it is that a site is the\n * *consumer* whose edges make four hand-maintained lists derivable. Declaring it\n * is what turns \"which origins does the API allow\" from something a person keeps\n * in step into something the graph already knows.\n *\n * ```ts\n * export const console = new StaticSite('Console', { path: 'apps/console' })\n * .dependsOn([api, auth]);\n * ```\n *\n * A site consumes addresses, not connections: it is built, and the values it\n * needs are inlined or fetched by its own framework, so its own edges take any\n * {@link Declarable}. Its `.service` is its public address — what a worker's\n * cron or an endpoint that builds links to it reads:\n *\n * ```ts\n * export const digest = worker\n * .cron('rate(1 day)')\n * .dependsOn([web])\n * .handle(async ({ services }) => link(services.web, '/inbox'));\n * ```\n *\n * Only the static variant ships. SSR deploy shapes are unstable and each one is\n * its own maintenance, so they follow rather than arrive together. A mobile app\n * is not a site — it is reached by a scheme, not a URL — and is its own\n * construct: see `MobileApp`.\n */\n\nimport {\n\tassertHostLabels,\n\ttype ConstructName,\n\tcanonicalId,\n\ttype Declaration,\n\ttype Dependency,\n\tprovidedKeyFor,\n\ttype SiteDeclaration,\n\tserviceKey,\n\tWILDCARD_SUBDOMAIN,\n} from '@geekmidas/manifest';\n\n/** Thrown at construction for an alias or redirect that cannot be a host label. */\nexport {\n\tHostLabelBothAliasAndRedirect,\n\tInvalidHostLabel,\n\tWildcardSiteCannotHaveAliases,\n} from '@geekmidas/manifest';\n\nimport type { Service } from '@geekmidas/services';\nimport {\n\ttype Construct,\n\ttype Declarable,\n\tfrontendEdgeTo,\n\tpublicUrl,\n} from './construct-interface';\nimport type { RandomPassword } from './random-password';\nimport type { DeployedStage } from './stages';\nimport type { Telemetry } from './telemetry';\n\n/**\n * Where a site's source lives, and the little else a layout can differ by.\n *\n * Only `path` is required: `new StaticSite('Web', { path: 'apps/web' })` is a\n * complete site.\n */\nexport interface StaticSiteConfig {\n\t/**\n\t * Where its source lives, relative to the workspace root — `'apps/web'`.\n\t *\n\t * Required, the same field `RestApi` and `BetterAuth` take. It was\n\t * inferred from the id, which made a site's home whatever was on disk.\n\t */\n\tpath: string;\n\t/**\n\t * The label it answers on under a stage's domain — `api` for\n\t * `api.myapp.com`, from `domains` — and under the project locally,\n\t * `api.myapp.localhost`. Absent, its id kebab-cased.\n\t *\n\t * `'*'` answers on every subdomain nothing else does — one host per\n\t * tenant, `acme.myapp.com` — and then `hosts` names which of them are\n\t * real. Every other app keeps its own host, and a project has at most one\n\t * such site.\n\t */\n\tsubdomain?: string;\n\t/**\n\t * More labels it answers on under the stage's domain, exactly as on its\n\t * own: each a host the site really serves, and an origin every surface it\n\t * depends on trusts. Its own host stays canonical (`<ID>_URL`).\n\t */\n\taliases?: readonly string[];\n\t/**\n\t * Labels that answer with a permanent (301) redirect to its own host,\n\t * path and query kept — `['www']` sends `www.myapp.com` to `myapp.com`.\n\t * Nothing answers on a host unless a construct names it, so there is no\n\t * automatic `www`. Sites only: an API client does not reliably follow a\n\t * redirect on a `POST`.\n\t */\n\tredirects?: readonly string[];\n\t/**\n\t * With `subdomain: '*'`, the route that says which hosts are tenants: an\n\t * exported `GET` endpoint the edge asks before it serves a host,\n\t * `?domain=<host>`, answering `200` for a tenant and `404` otherwise.\n\t *\n\t * It runs without a session and belongs to no public API.\n\t */\n\thosts?: SiteHostsEndpoint;\n\t/**\n\t * The port it answers on locally.\n\t *\n\t * Normally omitted: ports are assigned in a stable order, so adding a site\n\t * does not renumber the ones already running.\n\t */\n\tport?: number;\n\t/**\n\t * Modules to import when sniffing which env vars this site reads.\n\t *\n\t * A frontend's values are inlined at build time, so the build has to know\n\t * which ones it reads before it reads them.\n\t */\n\tconfig?: { client?: string; server?: string };\n\t/**\n\t * Whether the base domain points at this site.\n\t *\n\t * A project with one site needs this no more than a project with one\n\t * database needs to say which database. It matters when there are several\n\t * and none is called `web`: the base domain then belongs to whichever site\n\t * says so, rather than to whichever file the glob happened to reach first.\n\t */\n\troot?: boolean;\n\t/**\n\t * Which framework builds it.\n\t *\n\t * It selects how values are delivered — `VITE_`, `NEXT_PUBLIC_`, a fetched\n\t * `config.json` — and never which values there are. One neutral name from the\n\t * construct, one serialisation per framework, the same rule as everywhere\n\t * else.\n\t */\n\tvariant?: SiteDeclaration['variant'];\n\t/**\n\t * What the site emits — the `Telemetry` construct. An edge to the node and\n\t * nothing more for now: a site is handed none of its server keys, and the\n\t * browser half (propagation from the generated client, then a browser SDK\n\t * exporting through the API) builds on this edge.\n\t */\n\ttelemetry?: Telemetry;\n\t/**\n\t * A login the site is served behind on the stages named, so a staging\n\t * build is not public while it is tried.\n\t *\n\t * ```ts\n\t * export const sitePassword = new RandomPassword('SitePassword');\n\t *\n\t * export const web = new StaticSite('Web', {\n\t * path: 'apps/web',\n\t * password: { secret: sitePassword, stages: ['staging'] },\n\t * });\n\t * ```\n\t *\n\t * The edge asks for it with HTTP basic auth before a request reaches the\n\t * site: the user is the stage's name, the password the `RandomPassword`'s\n\t * value on that stage. Like any `RandomPassword` it is generated on the\n\t * first deploy and kept, and one set by hand wins. It is not an edge — the\n\t * site is handed none of it — so export it from a constructs file of its\n\t * own, as any construct is.\n\t *\n\t * The compose target alone serves it so far; another refuses the stage\n\t * rather than serving it publicly.\n\t */\n\tpassword?: {\n\t\tsecret: RandomPassword;\n\t\tstages: readonly [DeployedStage, ...DeployedStage[]];\n\t};\n\t/**\n\t * `'stage'` for a `static` site that pre-renders data at build time\n\t * (vite-ssg and similar): its build fetches from the APIs it\n\t * `.dependsOn()`, and bakes their answers into its files.\n\t *\n\t * ```ts\n\t * new StaticSite('Web', {\n\t * path: 'apps/web',\n\t * variant: 'static',\n\t * prerender: 'stage',\n\t * }).dependsOn([api]);\n\t * ```\n\t *\n\t * The deploy then builds the site only once those APIs are up and\n\t * healthy on the stage, and the build reaches them at their public\n\t * addresses, as a browser would. Without it, a site is built offline,\n\t * before its stage runs (`GKM_BUILD_OFFLINE=1`), and nothing at runtime\n\t * can fill a page built without its data.\n\t *\n\t * Opt-in, because the image then holds that stage's data: the same commit\n\t * builds a different image per stage, and `gkm compose --build --push`\n\t * needs the stage it builds for already running.\n\t */\n\tprerender?: 'stage';\n}\n\n/**\n * The shape of the endpoint `hosts` names — read structurally, so a site\n * module never loads the endpoint machinery to say which route it means.\n */\nexport interface SiteHostsEndpoint {\n\troute: string;\n\tmethod: string;\n\tsurface: { id: string };\n}\n\n/** `subdomain: '*'` without `hosts`: nothing would say which hosts are tenants. */\nexport class WildcardSiteNeedsHosts extends Error {\n\tconstructor(readonly id: string) {\n\t\tsuper(\n\t\t\t`'${id}' answers on every subdomain, so it has to say which of them ` +\n\t\t\t\t`are tenants: pass \\`hosts\\`, a GET endpoint answering 200 for a ` +\n\t\t\t\t`host it serves and 404 otherwise.`,\n\t\t);\n\t\tthis.name = 'WildcardSiteNeedsHosts';\n\t}\n}\n\n/** `hosts` on a site with one host, where there is nothing to check. */\nexport class SiteHostsNeedsWildcard extends Error {\n\tconstructor(readonly id: string) {\n\t\tsuper(\n\t\t\t`'${id}' names a \\`hosts\\` check but answers on one host. ` +\n\t\t\t\t`Declare \\`subdomain: '*'\\` to serve every subdomain, or drop \\`hosts\\`.`,\n\t\t);\n\t\tthis.name = 'SiteHostsNeedsWildcard';\n\t}\n}\n\n/** A `hosts` endpoint that is not a `GET`: the edge only ever asks with one. */\nexport class SiteHostsNotGet extends Error {\n\tconstructor(\n\t\treadonly id: string,\n\t\treadonly method: string,\n\t\treadonly route: string,\n\t) {\n\t\tsuper(\n\t\t\t`'${id}' checks its hosts with ${method} ${route}, but the edge asks ` +\n\t\t\t\t`with GET ${route}?domain=<host>. Make it a GET endpoint.`,\n\t\t);\n\t\tthis.name = 'SiteHostsNotGet';\n\t}\n}\n\n/**\n * `prerender: 'stage'` on a site that renders its pages on a server, where a\n * page renders on its first request — which the deploy's warm-up makes — and\n * needs no data at build.\n */\nexport class PrerenderNeedsStaticSite extends Error {\n\tconstructor(\n\t\treadonly id: string,\n\t\treadonly variant: SiteDeclaration['variant'],\n\t) {\n\t\tsuper(\n\t\t\t`'${id}' is a '${variant}' site, which renders its pages on its own ` +\n\t\t\t\t`server, so it never needs its APIs at build: drop \\`prerender\\`, ` +\n\t\t\t\t`and render data-backed pages on request (the deploy warms them). ` +\n\t\t\t\t`\\`prerender: 'stage'\\` is for a 'static' site that bakes data into ` +\n\t\t\t\t`its files.`,\n\t\t);\n\t\tthis.name = 'PrerenderNeedsStaticSite';\n\t}\n}\n\n/** A wildcard site that says it holds the base domain. */\nexport class WildcardSiteCannotBeRoot extends Error {\n\tconstructor(readonly id: string) {\n\t\tsuper(\n\t\t\t`'${id}' answers on every subdomain, so it cannot also hold the base ` +\n\t\t\t\t`domain. Drop \\`root: true\\`, and declare the site the base domain ` +\n\t\t\t\t`points at separately.`,\n\t\t);\n\t\tthis.name = 'WildcardSiteCannotBeRoot';\n\t}\n}\n\nexport class StaticSite<TName extends string = string>\n\timplements Declarable<TName>, Construct<TName, string>\n{\n\treadonly id: TName;\n\treadonly keys: { url: string };\n\n\t/**\n\t * Its public address, `https://web.example.com` — a string, no await. The\n\t * same `<ID>_URL` on every command and stage, so a link built from it opens\n\t * in a browser.\n\t */\n\treadonly service: Service<Uncapitalize<TName>, string>;\n\n\tconstructor(\n\t\tid: ConstructName<TName>,\n\t\tprivate readonly config: StaticSiteConfig,\n\t\t/**\n\t\t * Internal: how `.dependsOn()` carries edges into the copy it returns.\n\t\t * Written as a parameter rather than a mutable field so the builder can\n\t\t * stay immutable without a clone method, the same shape\n\t\t * `KyselyDatabase` uses for its derived forms.\n\t\t */\n\t\tprivate readonly dependencies: readonly Dependency[] = [],\n\t) {\n\t\tthis.id = canonicalId(id as string) as TName;\n\t\tthis.keys = { url: providedKeyFor(this.id, 'site', 'url') };\n\t\t// A field, not a getter: consumers cache services by object identity.\n\t\tthis.service = {\n\t\t\tserviceName: serviceKey(this.id) as Uncapitalize<TName>,\n\t\t\tregister: (options) => publicUrl(options, this.keys.url),\n\t\t};\n\n\t\tconst wildcard = config.subdomain === WILDCARD_SUBDOMAIN;\n\t\tif (wildcard && !config.hosts) throw new WildcardSiteNeedsHosts(this.id);\n\t\tif (!wildcard && config.hosts) throw new SiteHostsNeedsWildcard(this.id);\n\t\tif (wildcard && config.root) throw new WildcardSiteCannotBeRoot(this.id);\n\t\tassertHostLabels({\n\t\t\tid: this.id,\n\t\t\t...(config.subdomain ? { subdomain: config.subdomain } : {}),\n\t\t\t...(config.aliases ? { aliases: config.aliases } : {}),\n\t\t\t...(config.redirects ? { redirects: config.redirects } : {}),\n\t\t});\n\t\tconst variant = config.variant ?? 'static';\n\t\tif (config.prerender && variant !== 'static') {\n\t\t\tthrow new PrerenderNeedsStaticSite(this.id, variant);\n\t\t}\n\t\tif (config.hosts && config.hosts.method.toUpperCase() !== 'GET') {\n\t\t\tthrow new SiteHostsNotGet(\n\t\t\t\tthis.id,\n\t\t\t\tconfig.hosts.method,\n\t\t\t\tconfig.hosts.route,\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * What this site calls.\n\t *\n\t * Immutable, like every other builder here: it returns a new site rather than\n\t * mutating this one, so a module that exports both a base and a variant of it\n\t * cannot have the second silently change the first.\n\t *\n\t * Takes {@link Declarable} rather than {@link Consumable} because a site's\n\t * edge is a build-time link and not a service injection — requiring a client\n\t * would exclude exactly the surfaces a frontend actually depends on.\n\t *\n\t * A plain edge to a `FileServer` is to its public face: the site is built\n\t * with the address its objects are served on, and handed nothing that\n\t * writes to the bucket. `.dependsOn([assets.server])` asks for the bucket\n\t * too, for a server half that uploads.\n\t */\n\tdependsOn(constructs: readonly Declarable[]): StaticSite<TName> {\n\t\treturn new StaticSite<TName>(this.id as ConstructName<TName>, this.config, [\n\t\t\t...this.dependencies,\n\t\t\t...constructs.map(frontendEdgeTo),\n\t\t]);\n\t}\n\n\tdeclare(): Declaration[] {\n\t\tconst { hosts } = this.config;\n\t\treturn [\n\t\t\t{\n\t\t\t\tkind: 'site',\n\t\t\t\tid: this.id,\n\t\t\t\tvariant: this.config.variant ?? 'static',\n\t\t\t\t...(this.config.subdomain ? { subdomain: this.config.subdomain } : {}),\n\t\t\t\t...(this.config.aliases?.length\n\t\t\t\t\t? { aliases: [...this.config.aliases] }\n\t\t\t\t\t: {}),\n\t\t\t\t...(this.config.redirects?.length\n\t\t\t\t\t? { redirects: [...this.config.redirects] }\n\t\t\t\t\t: {}),\n\t\t\t\t...(hosts\n\t\t\t\t\t? {\n\t\t\t\t\t\t\thosts: {\n\t\t\t\t\t\t\t\tsurface: canonicalId(hosts.surface.id),\n\t\t\t\t\t\t\t\tpath: hosts.route,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t}\n\t\t\t\t\t: {}),\n\t\t\t\tapp: {\n\t\t\t\t\tpath: this.config.path,\n\t\t\t\t\t...(this.config.port ? { port: this.config.port } : {}),\n\t\t\t\t\t...(this.config.config ? { config: this.config.config } : {}),\n\t\t\t\t},\n\t\t\t\t...(this.config.root ? { root: true } : {}),\n\t\t\t\tdependencies: this.dependencies,\n\t\t\t\t...(this.config.telemetry\n\t\t\t\t\t? { telemetry: this.config.telemetry.id }\n\t\t\t\t\t: {}),\n\t\t\t\t...(this.config.password\n\t\t\t\t\t? {\n\t\t\t\t\t\t\tpassword: {\n\t\t\t\t\t\t\t\tsecret: this.config.password.secret.id,\n\t\t\t\t\t\t\t\tstages: [...this.config.password.stages],\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t}\n\t\t\t\t\t: {}),\n\t\t\t\t...(this.config.prerender ? { prerender: this.config.prerender } : {}),\n\t\t\t\tprovides: [\n\t\t\t\t\tthis.keys.url,\n\t\t\t\t\t...(hosts\n\t\t\t\t\t\t? [\n\t\t\t\t\t\t\t\tprovidedKeyFor(this.id, 'site', 'domain'),\n\t\t\t\t\t\t\t\tprovidedKeyFor(this.id, 'site', 'protectedSubdomains'),\n\t\t\t\t\t\t\t]\n\t\t\t\t\t\t: []),\n\t\t\t\t],\n\t\t\t},\n\t\t];\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmNA,IAAa,yBAAb,cAA4C,MAAM;CAC5B;CAArB,YAAY,IAAqB;EAChC,MACC,IAAI,GAAG,+JAGR;EALoB,KAAA,KAAA;EAMpB,KAAK,OAAO;CACb;AACD;;AAGA,IAAa,yBAAb,cAA4C,MAAM;CAC5B;CAArB,YAAY,IAAqB;EAChC,MACC,IAAI,GAAG,2HAER;EAJoB,KAAA,KAAA;EAKpB,KAAK,OAAO;CACb;AACD;;AAGA,IAAa,kBAAb,cAAqC,MAAM;CAEhC;CACA;CACA;CAHV,YACC,IACA,QACA,OACC;EACD,MACC,IAAI,GAAG,0BAA0B,OAAO,GAAG,MAAM,+BACp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AU;IACT,QAAQ,KAAK,OAAO,SAAS,OAAO;IACpC,QAAQ,CAAC,GAAG,KAAK,OAAO,SAAS,MAAM;GACxC,EACD,IACC,CAAC;GACJ,GAAI,KAAK,OAAO,YAAY,EAAE,WAAW,KAAK,OAAO,UAAU,IAAI,CAAC;GACpE,UAAU,CACT,KAAK,KAAK,KACV,GAAI,QACD,CACA,eAAe,KAAK,IAAI,QAAQ,QAAQ,GACxC,eAAe,KAAK,IAAI,QAAQ,qBAAqB,CACtD,IACC,CAAC,CACL;EACD,CACD;CACD;AACD"}
|
|
1
|
+
{"version":3,"file":"site.mjs","names":[],"sources":["../src/site.ts"],"sourcesContent":["/**\n * `StaticSite` — a frontend, declared like anything else.\n *\n * The point is not that a site needs provisioning; it is that a site is the\n * *consumer* whose edges make four hand-maintained lists derivable. Declaring it\n * is what turns \"which origins does the API allow\" from something a person keeps\n * in step into something the graph already knows.\n *\n * ```ts\n * export const console = new StaticSite('Console', { path: 'apps/console' })\n * .dependsOn([api, auth]);\n * ```\n *\n * A site consumes addresses, not connections: it is built, and the values it\n * needs are inlined or fetched by its own framework, so its own edges take any\n * {@link Declarable}. Its `.service` is its public address — what a worker's\n * cron or an endpoint that builds links to it reads:\n *\n * ```ts\n * export const digest = worker\n * .cron('rate(1 day)')\n * .dependsOn([web])\n * .handle(async ({ services }) => link(services.web, '/inbox'));\n * ```\n *\n * Only the static variant ships. SSR deploy shapes are unstable and each one is\n * its own maintenance, so they follow rather than arrive together. A mobile app\n * is not a site — it is reached by a scheme, not a URL — and is its own\n * construct: see `MobileApp`.\n */\n\nimport {\n\tassertHostLabels,\n\ttype ConstructName,\n\tcanonicalId,\n\ttype Declaration,\n\ttype Dependency,\n\tprovidedKeyFor,\n\ttype SiteDeclaration,\n\tserviceKey,\n\tWILDCARD_SUBDOMAIN,\n} from '@geekmidas/manifest';\n\n/** Thrown at construction for an alias or redirect that cannot be a host label. */\nexport {\n\tHostLabelBothAliasAndRedirect,\n\tInvalidHostLabel,\n\tWildcardSiteCannotHaveAliases,\n} from '@geekmidas/manifest';\n\nimport type { Service } from '@geekmidas/services';\nimport {\n\ttype Construct,\n\ttype Declarable,\n\tfrontendEdgeTo,\n\tpublicUrl,\n} from './construct-interface';\nimport type { RandomPassword } from './random-password';\nimport type { DeployedStage } from './stages';\nimport type { Telemetry } from './telemetry';\n\n/**\n * Where a site's source lives, and the little else a layout can differ by.\n *\n * Only `path` is required: `new StaticSite('Web', { path: 'apps/web' })` is a\n * complete site.\n */\nexport interface StaticSiteConfig {\n\t/**\n\t * Where its source lives, relative to the workspace root — `'apps/web'`.\n\t *\n\t * Required, the same field `RestApi` and `BetterAuth` take. It was\n\t * inferred from the id, which made a site's home whatever was on disk.\n\t */\n\tpath: string;\n\t/**\n\t * The label it answers on under a stage's domain — `api` for\n\t * `api.myapp.com`, from `domains` — and under the project locally,\n\t * `api.myapp.localhost`. Absent, its id kebab-cased.\n\t *\n\t * `'*'` answers on every subdomain nothing else does — one host per\n\t * tenant, `acme.myapp.com` — and then `hosts` names which of them are\n\t * real. Every other app keeps its own host, and a project has at most one\n\t * such site.\n\t */\n\tsubdomain?: string;\n\t/**\n\t * More labels it answers on under the stage's domain, exactly as on its\n\t * own: each a host the site really serves, and an origin every surface it\n\t * depends on trusts. Its own host stays canonical (`<ID>_URL`).\n\t */\n\taliases?: readonly string[];\n\t/**\n\t * Labels that answer with a permanent (301) redirect to its own host,\n\t * path and query kept — `['www']` sends `www.myapp.com` to `myapp.com`.\n\t * Nothing answers on a host unless a construct names it, so there is no\n\t * automatic `www`. Sites only: an API client does not reliably follow a\n\t * redirect on a `POST`.\n\t */\n\tredirects?: readonly string[];\n\t/**\n\t * With `subdomain: '*'`, the route that says which hosts are tenants: an\n\t * exported `GET` endpoint the edge asks before it serves a host,\n\t * `?domain=<host>`, answering `200` for a tenant and `404` otherwise.\n\t *\n\t * It runs without a session and belongs to no public API.\n\t */\n\thosts?: SiteHostsEndpoint;\n\t/**\n\t * The port it answers on locally.\n\t *\n\t * Normally omitted: ports are assigned in a stable order, so adding a site\n\t * does not renumber the ones already running.\n\t */\n\tport?: number;\n\t/**\n\t * Modules to import when sniffing which env vars this site reads.\n\t *\n\t * A frontend's values are inlined at build time, so the build has to know\n\t * which ones it reads before it reads them.\n\t */\n\tconfig?: { client?: string; server?: string };\n\t/**\n\t * Whether the base domain points at this site.\n\t *\n\t * A project with one site needs this no more than a project with one\n\t * database needs to say which database. It matters when there are several\n\t * and none is called `web`: the base domain then belongs to whichever site\n\t * says so, rather than to whichever file the glob happened to reach first.\n\t */\n\troot?: boolean;\n\t/**\n\t * Which framework builds it.\n\t *\n\t * It selects how values are delivered — `VITE_`, `NEXT_PUBLIC_`, a fetched\n\t * `config.json` — and never which values there are. One neutral name from the\n\t * construct, one serialisation per framework, the same rule as everywhere\n\t * else.\n\t */\n\tvariant?: SiteDeclaration['variant'];\n\t/**\n\t * What the site emits — the `Telemetry` construct. An edge to the node and\n\t * nothing more for now: a site is handed none of its server keys, and the\n\t * browser half (propagation from the generated client, then a browser SDK\n\t * exporting through the API) builds on this edge.\n\t */\n\ttelemetry?: Telemetry;\n\t/**\n\t * A login the site is served behind on the stages named, so a staging\n\t * build is not public while it is tried.\n\t *\n\t * ```ts\n\t * export const sitePassword = new RandomPassword('SitePassword');\n\t *\n\t * export const web = new StaticSite('Web', {\n\t * path: 'apps/web',\n\t * password: { secret: sitePassword, stages: ['staging'] },\n\t * });\n\t * ```\n\t *\n\t * The edge asks for it with HTTP basic auth before a request reaches the\n\t * site: the user is the stage's name, the password the `RandomPassword`'s\n\t * value on that stage. Like any `RandomPassword` it is generated on the\n\t * first deploy and kept, and one set by hand wins. It is not an edge — the\n\t * site is handed none of it — so export it from a constructs file of its\n\t * own, as any construct is.\n\t *\n\t * The compose target alone serves it so far; another refuses the stage\n\t * rather than serving it publicly.\n\t */\n\tpassword?: {\n\t\tsecret: RandomPassword;\n\t\tstages: readonly [DeployedStage, ...DeployedStage[]];\n\t};\n\t/**\n\t * `'stage'` for a `static` site that pre-renders data at build time\n\t * (vite-ssg and similar): its build fetches from the APIs it\n\t * `.dependsOn()`, and bakes their answers into its files.\n\t *\n\t * ```ts\n\t * new StaticSite('Web', {\n\t * path: 'apps/web',\n\t * variant: 'static',\n\t * prerender: 'stage',\n\t * }).dependsOn([api]);\n\t * ```\n\t *\n\t * The deploy then builds the site only once those APIs are up and\n\t * healthy on the stage, and the build reaches them at their public\n\t * addresses, as a browser would. Without it, a site is built offline,\n\t * before its stage runs (`GKM_BUILD_OFFLINE=1`), and nothing at runtime\n\t * can fill a page built without its data.\n\t *\n\t * Opt-in, because the image then holds that stage's data: the same commit\n\t * builds a different image per stage, and `gkm compose --build --push`\n\t * needs the stage it builds for already running.\n\t */\n\tprerender?: 'stage';\n}\n\n/**\n * The shape of the endpoint `hosts` names — read structurally, so a site\n * module never loads the endpoint machinery to say which route it means.\n */\nexport interface SiteHostsEndpoint {\n\troute: string;\n\tmethod: string;\n\tsurface: { id: string };\n}\n\n/** `subdomain: '*'` without `hosts`: nothing would say which hosts are tenants. */\nexport class WildcardSiteNeedsHosts extends Error {\n\tconstructor(readonly id: string) {\n\t\tsuper(\n\t\t\t`'${id}' answers on every subdomain, so it has to say which of them ` +\n\t\t\t\t`are tenants: pass \\`hosts\\`, a GET endpoint answering 200 for a ` +\n\t\t\t\t`host it serves and 404 otherwise.`,\n\t\t);\n\t\tthis.name = 'WildcardSiteNeedsHosts';\n\t}\n}\n\n/** `hosts` on a site with one host, where there is nothing to check. */\nexport class SiteHostsNeedsWildcard extends Error {\n\tconstructor(readonly id: string) {\n\t\tsuper(\n\t\t\t`'${id}' names a \\`hosts\\` check but answers on one host. ` +\n\t\t\t\t`Declare \\`subdomain: '*'\\` to serve every subdomain, or drop \\`hosts\\`.`,\n\t\t);\n\t\tthis.name = 'SiteHostsNeedsWildcard';\n\t}\n}\n\n/** A `hosts` endpoint that is not a `GET`: the edge only ever asks with one. */\nexport class SiteHostsNotGet extends Error {\n\tconstructor(\n\t\treadonly id: string,\n\t\treadonly method: string,\n\t\treadonly route: string,\n\t) {\n\t\tsuper(\n\t\t\t`'${id}' checks its hosts with ${method} ${route}, but the edge asks ` +\n\t\t\t\t`with GET ${route}?domain=<host>. Make it a GET endpoint.`,\n\t\t);\n\t\tthis.name = 'SiteHostsNotGet';\n\t}\n}\n\n/**\n * `prerender: 'stage'` on a site that renders its pages on a server, where a\n * page renders on its first request — which the deploy's warm-up makes — and\n * needs no data at build.\n */\nexport class PrerenderNeedsStaticSite extends Error {\n\tconstructor(\n\t\treadonly id: string,\n\t\treadonly variant: SiteDeclaration['variant'],\n\t) {\n\t\tsuper(\n\t\t\t`'${id}' is a '${variant}' site, which renders its pages on its own ` +\n\t\t\t\t`server, so it never needs its APIs at build: drop \\`prerender\\`, ` +\n\t\t\t\t`and render data-backed pages on request (the deploy warms them). ` +\n\t\t\t\t`\\`prerender: 'stage'\\` is for a 'static' site that bakes data into ` +\n\t\t\t\t`its files.`,\n\t\t);\n\t\tthis.name = 'PrerenderNeedsStaticSite';\n\t}\n}\n\n/** A wildcard site that says it holds the base domain. */\nexport class WildcardSiteCannotBeRoot extends Error {\n\tconstructor(readonly id: string) {\n\t\tsuper(\n\t\t\t`'${id}' answers on every subdomain, so it cannot also hold the base ` +\n\t\t\t\t`domain. Drop \\`root: true\\`, and declare the site the base domain ` +\n\t\t\t\t`points at separately.`,\n\t\t);\n\t\tthis.name = 'WildcardSiteCannotBeRoot';\n\t}\n}\n\nexport class StaticSite<TName extends string = string>\n\timplements Declarable<TName>, Construct<TName, string>\n{\n\treadonly id: TName;\n\treadonly keys: { url: string };\n\n\t/**\n\t * Its public address, `https://web.example.com` — a string, no await. The\n\t * same `<ID>_URL` on every command and stage, so a link built from it opens\n\t * in a browser.\n\t */\n\treadonly service: Service<Uncapitalize<TName>, string>;\n\n\tconstructor(\n\t\tid: ConstructName<TName>,\n\t\tprivate readonly config: StaticSiteConfig,\n\t\t/**\n\t\t * Internal: how `.dependsOn()` carries edges into the copy it returns.\n\t\t * Written as a parameter rather than a mutable field so the builder can\n\t\t * stay immutable without a clone method, the same shape\n\t\t * `KyselyDatabase` uses for its derived forms.\n\t\t */\n\t\tprivate readonly dependencies: readonly Dependency[] = [],\n\t) {\n\t\tthis.id = canonicalId(id as string) as TName;\n\t\tthis.keys = { url: providedKeyFor(this.id, 'site', 'url') };\n\t\t// A field, not a getter: consumers cache services by object identity.\n\t\tthis.service = {\n\t\t\tserviceName: serviceKey(this.id) as Uncapitalize<TName>,\n\t\t\tregister: (options) => publicUrl(options, this.keys.url),\n\t\t};\n\n\t\tconst wildcard = config.subdomain === WILDCARD_SUBDOMAIN;\n\t\tif (wildcard && !config.hosts) throw new WildcardSiteNeedsHosts(this.id);\n\t\tif (!wildcard && config.hosts) throw new SiteHostsNeedsWildcard(this.id);\n\t\tif (wildcard && config.root) throw new WildcardSiteCannotBeRoot(this.id);\n\t\tassertHostLabels({\n\t\t\tid: this.id,\n\t\t\t...(config.subdomain ? { subdomain: config.subdomain } : {}),\n\t\t\t...(config.aliases ? { aliases: config.aliases } : {}),\n\t\t\t...(config.redirects ? { redirects: config.redirects } : {}),\n\t\t});\n\t\tconst variant = config.variant ?? 'static';\n\t\tif (config.prerender && variant !== 'static') {\n\t\t\tthrow new PrerenderNeedsStaticSite(this.id, variant);\n\t\t}\n\t\tif (config.hosts && config.hosts.method.toUpperCase() !== 'GET') {\n\t\t\tthrow new SiteHostsNotGet(\n\t\t\t\tthis.id,\n\t\t\t\tconfig.hosts.method,\n\t\t\t\tconfig.hosts.route,\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * What this site calls.\n\t *\n\t * Immutable, like every other builder here: it returns a new site rather than\n\t * mutating this one, so a module that exports both a base and a variant of it\n\t * cannot have the second silently change the first.\n\t *\n\t * Takes {@link Declarable} rather than {@link Consumable} because a site's\n\t * edge is a build-time link and not a service injection — requiring a client\n\t * would exclude exactly the surfaces a frontend actually depends on.\n\t *\n\t * A plain edge to a `FileServer` is to its public face: the site is built\n\t * with the address its objects are served on, and handed nothing that\n\t * writes to the bucket. A plain edge to an `ObjectStorage` is to where its\n\t * links are signed (`<PREFIX><T>_SIGNED_ORIGIN`), and to nothing else of\n\t * it. `.dependsOn([assets.server])` or `.dependsOn([documents.server])`\n\t * asks for the bucket and its credentials too, for a server half that\n\t * uploads or presigns.\n\t */\n\tdependsOn(constructs: readonly Declarable[]): StaticSite<TName> {\n\t\treturn new StaticSite<TName>(this.id as ConstructName<TName>, this.config, [\n\t\t\t...this.dependencies,\n\t\t\t...constructs.map(frontendEdgeTo),\n\t\t]);\n\t}\n\n\tdeclare(): Declaration[] {\n\t\tconst { hosts } = this.config;\n\t\treturn [\n\t\t\t{\n\t\t\t\tkind: 'site',\n\t\t\t\tid: this.id,\n\t\t\t\tvariant: this.config.variant ?? 'static',\n\t\t\t\t...(this.config.subdomain ? { subdomain: this.config.subdomain } : {}),\n\t\t\t\t...(this.config.aliases?.length\n\t\t\t\t\t? { aliases: [...this.config.aliases] }\n\t\t\t\t\t: {}),\n\t\t\t\t...(this.config.redirects?.length\n\t\t\t\t\t? { redirects: [...this.config.redirects] }\n\t\t\t\t\t: {}),\n\t\t\t\t...(hosts\n\t\t\t\t\t? {\n\t\t\t\t\t\t\thosts: {\n\t\t\t\t\t\t\t\tsurface: canonicalId(hosts.surface.id),\n\t\t\t\t\t\t\t\tpath: hosts.route,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t}\n\t\t\t\t\t: {}),\n\t\t\t\tapp: {\n\t\t\t\t\tpath: this.config.path,\n\t\t\t\t\t...(this.config.port ? { port: this.config.port } : {}),\n\t\t\t\t\t...(this.config.config ? { config: this.config.config } : {}),\n\t\t\t\t},\n\t\t\t\t...(this.config.root ? { root: true } : {}),\n\t\t\t\tdependencies: this.dependencies,\n\t\t\t\t...(this.config.telemetry\n\t\t\t\t\t? { telemetry: this.config.telemetry.id }\n\t\t\t\t\t: {}),\n\t\t\t\t...(this.config.password\n\t\t\t\t\t? {\n\t\t\t\t\t\t\tpassword: {\n\t\t\t\t\t\t\t\tsecret: this.config.password.secret.id,\n\t\t\t\t\t\t\t\tstages: [...this.config.password.stages],\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t}\n\t\t\t\t\t: {}),\n\t\t\t\t...(this.config.prerender ? { prerender: this.config.prerender } : {}),\n\t\t\t\tprovides: [\n\t\t\t\t\tthis.keys.url,\n\t\t\t\t\t...(hosts\n\t\t\t\t\t\t? [\n\t\t\t\t\t\t\t\tprovidedKeyFor(this.id, 'site', 'domain'),\n\t\t\t\t\t\t\t\tprovidedKeyFor(this.id, 'site', 'protectedSubdomains'),\n\t\t\t\t\t\t\t]\n\t\t\t\t\t\t: []),\n\t\t\t\t],\n\t\t\t},\n\t\t];\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmNA,IAAa,yBAAb,cAA4C,MAAM;CAC5B;CAArB,YAAY,IAAqB;EAChC,MACC,IAAI,GAAG,+JAGR;EALoB,KAAA,KAAA;EAMpB,KAAK,OAAO;CACb;AACD;;AAGA,IAAa,yBAAb,cAA4C,MAAM;CAC5B;CAArB,YAAY,IAAqB;EAChC,MACC,IAAI,GAAG,2HAER;EAJoB,KAAA,KAAA;EAKpB,KAAK,OAAO;CACb;AACD;;AAGA,IAAa,kBAAb,cAAqC,MAAM;CAEhC;CACA;CACA;CAHV,YACC,IACA,QACA,OACC;EACD,MACC,IAAI,GAAG,0BAA0B,OAAO,GAAG,MAAM,+BACpC,MAAM,wCACpB;EAPS,KAAA,KAAA;EACA,KAAA,SAAA;EACA,KAAA,QAAA;EAMT,KAAK,OAAO;CACb;AACD;;;;;;AAOA,IAAa,2BAAb,cAA8C,MAAM;CAEzC;CACA;CAFV,YACC,IACA,SACC;EACD,MACC,IAAI,GAAG,UAAU,QAAQ,2PAK1B;EATS,KAAA,KAAA;EACA,KAAA,UAAA;EAST,KAAK,OAAO;CACb;AACD;;AAGA,IAAa,2BAAb,cAA8C,MAAM;CAC9B;CAArB,YAAY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AC,CACL;EACD,CACD;CACD;AACD"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { t as Subscriber } from "../Subscriber-5rCX1Nph.cjs";
|
|
2
|
-
import { a as ObjectSubscriberHasNoEvents, i as ObjectSubscriberHandler, n as ObjectSubscriberBuilder, o as SubscriberBuilder, r as ObjectSubscriberContext, t as ObjectSubscriber } from "../ObjectSubscriberBuilder-
|
|
2
|
+
import { a as ObjectSubscriberHasNoEvents, i as ObjectSubscriberHandler, n as ObjectSubscriberBuilder, o as SubscriberBuilder, r as ObjectSubscriberContext, t as ObjectSubscriber } from "../ObjectSubscriberBuilder-DWtLxfAJ.cjs";
|
|
3
3
|
import { EnvironmentParser } from "@geekmidas/envkit";
|
|
4
4
|
import { SnsHttpMessage } from "@geekmidas/events/sns/message";
|
|
5
5
|
//#region src/subscribers/SnsPushSubscriberAdaptor.d.ts
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { t as Subscriber } from "../Subscriber-CtQXhcL7.mjs";
|
|
2
|
-
import { a as ObjectSubscriberHasNoEvents, i as ObjectSubscriberHandler, n as ObjectSubscriberBuilder, o as SubscriberBuilder, r as ObjectSubscriberContext, t as ObjectSubscriber } from "../ObjectSubscriberBuilder-
|
|
2
|
+
import { a as ObjectSubscriberHasNoEvents, i as ObjectSubscriberHandler, n as ObjectSubscriberBuilder, o as SubscriberBuilder, r as ObjectSubscriberContext, t as ObjectSubscriber } from "../ObjectSubscriberBuilder-Ci_Cc-WZ.mjs";
|
|
3
3
|
import { EnvironmentParser } from "@geekmidas/envkit";
|
|
4
4
|
import { SnsHttpMessage } from "@geekmidas/events/sns/message";
|
|
5
5
|
//#region src/subscribers/SnsPushSubscriberAdaptor.d.ts
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { i as Declarable } from "./construct-interface-
|
|
1
|
+
import { i as Declarable } from "./construct-interface-CVoejIpo.cjs";
|
|
2
2
|
import { ConstructName, Declaration } from "@geekmidas/manifest";
|
|
3
3
|
//#region src/telemetry.d.ts
|
|
4
4
|
interface TelemetryConfig {
|
|
@@ -15,16 +15,33 @@ interface TelemetryConfig {
|
|
|
15
15
|
* them: it is the app's, set per process.
|
|
16
16
|
*/
|
|
17
17
|
attributes?: Readonly<Record<string, string>>;
|
|
18
|
+
/**
|
|
19
|
+
* The label the log UI answers on under the stage's domain, where a stage
|
|
20
|
+
* serves it publicly (`deploy.telemetry.<stage>.public`). Defaults to the
|
|
21
|
+
* id kebab-cased — `telemetry.<stage domain>` for `Telemetry`.
|
|
22
|
+
*
|
|
23
|
+
* Here rather than in the stage's config because it is the same on every
|
|
24
|
+
* stage; whether it is served, and to whom, is the stage's.
|
|
25
|
+
*/
|
|
26
|
+
subdomain?: string;
|
|
27
|
+
/**
|
|
28
|
+
* The image the self-hosted provider runs — OpenObserve, taken verbatim.
|
|
29
|
+
* Defaults to the version gkm pins.
|
|
30
|
+
*/
|
|
31
|
+
image?: string;
|
|
18
32
|
}
|
|
19
33
|
declare class Telemetry<TName extends string = string> implements Declarable<TName> {
|
|
20
34
|
readonly id: TName;
|
|
21
35
|
readonly ignorePaths: readonly string[];
|
|
22
36
|
readonly attributes: Readonly<Record<string, string>>;
|
|
37
|
+
readonly subdomain: string | undefined;
|
|
38
|
+
readonly image: string | undefined;
|
|
23
39
|
constructor(id: ConstructName<TName>, config?: TelemetryConfig);
|
|
24
40
|
/**
|
|
25
|
-
* One node, providing OpenTelemetry's own variables.
|
|
26
|
-
*
|
|
27
|
-
*
|
|
41
|
+
* One node, providing OpenTelemetry's own variables. Where the telemetry
|
|
42
|
+
* goes is the deploy's, resolved by the target for each stage; what is
|
|
43
|
+
* declared is only what is the same on every stage — the log UI's label
|
|
44
|
+
* and the image that runs it.
|
|
28
45
|
*/
|
|
29
46
|
declare(): Declaration[];
|
|
30
47
|
}
|
|
@@ -37,4 +54,4 @@ interface EndpointTelemetry {
|
|
|
37
54
|
}
|
|
38
55
|
//#endregion
|
|
39
56
|
export { Telemetry as n, TelemetryConfig as r, EndpointTelemetry as t };
|
|
40
|
-
//# sourceMappingURL=telemetry-
|
|
57
|
+
//# sourceMappingURL=telemetry-BbLyS7ln.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"telemetry-BbLyS7ln.d.cts","names":[],"sources":["../src/telemetry.ts"],"mappings":";;;UAmCiB;;;;;;;EAOhB;;;;;;EAMA,aAAa,SAAS;;;;;;;;;EAStB;;;;;EAKA;;cAGY,UAAU,0CACX,WAAW;WAEb,IAAI;WACJ;WACA,YAAY,SAAS;WACrB;WACA;EAET,YAAY,IAAI,cAAc,QAAQ,SAAQ;;;;;;;EAiB9C,WAAW;;;UAkBK;;EAEhB;;EAEA,aAAa,SAAS"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { i as Declarable } from "./construct-interface-
|
|
1
|
+
import { i as Declarable } from "./construct-interface-Nw5Dt9AC.mjs";
|
|
2
2
|
import { ConstructName, Declaration } from "@geekmidas/manifest";
|
|
3
3
|
//#region src/telemetry.d.ts
|
|
4
4
|
interface TelemetryConfig {
|
|
@@ -15,16 +15,33 @@ interface TelemetryConfig {
|
|
|
15
15
|
* them: it is the app's, set per process.
|
|
16
16
|
*/
|
|
17
17
|
attributes?: Readonly<Record<string, string>>;
|
|
18
|
+
/**
|
|
19
|
+
* The label the log UI answers on under the stage's domain, where a stage
|
|
20
|
+
* serves it publicly (`deploy.telemetry.<stage>.public`). Defaults to the
|
|
21
|
+
* id kebab-cased — `telemetry.<stage domain>` for `Telemetry`.
|
|
22
|
+
*
|
|
23
|
+
* Here rather than in the stage's config because it is the same on every
|
|
24
|
+
* stage; whether it is served, and to whom, is the stage's.
|
|
25
|
+
*/
|
|
26
|
+
subdomain?: string;
|
|
27
|
+
/**
|
|
28
|
+
* The image the self-hosted provider runs — OpenObserve, taken verbatim.
|
|
29
|
+
* Defaults to the version gkm pins.
|
|
30
|
+
*/
|
|
31
|
+
image?: string;
|
|
18
32
|
}
|
|
19
33
|
declare class Telemetry<TName extends string = string> implements Declarable<TName> {
|
|
20
34
|
readonly id: TName;
|
|
21
35
|
readonly ignorePaths: readonly string[];
|
|
22
36
|
readonly attributes: Readonly<Record<string, string>>;
|
|
37
|
+
readonly subdomain: string | undefined;
|
|
38
|
+
readonly image: string | undefined;
|
|
23
39
|
constructor(id: ConstructName<TName>, config?: TelemetryConfig);
|
|
24
40
|
/**
|
|
25
|
-
* One node, providing OpenTelemetry's own variables.
|
|
26
|
-
*
|
|
27
|
-
*
|
|
41
|
+
* One node, providing OpenTelemetry's own variables. Where the telemetry
|
|
42
|
+
* goes is the deploy's, resolved by the target for each stage; what is
|
|
43
|
+
* declared is only what is the same on every stage — the log UI's label
|
|
44
|
+
* and the image that runs it.
|
|
28
45
|
*/
|
|
29
46
|
declare(): Declaration[];
|
|
30
47
|
}
|
|
@@ -37,4 +54,4 @@ interface EndpointTelemetry {
|
|
|
37
54
|
}
|
|
38
55
|
//#endregion
|
|
39
56
|
export { Telemetry as n, TelemetryConfig as r, EndpointTelemetry as t };
|
|
40
|
-
//# sourceMappingURL=telemetry-
|
|
57
|
+
//# sourceMappingURL=telemetry-DWX-qKUh.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"telemetry-DWX-qKUh.d.mts","names":[],"sources":["../src/telemetry.ts"],"mappings":";;;UAmCiB;;;;;;;EAOhB;;;;;;EAMA,aAAa,SAAS;;;;;;;;;EAStB;;;;;EAKA;;cAGY,UAAU,0CACX,WAAW;WAEb,IAAI;WACJ;WACA,YAAY,SAAS;WACrB;WACA;EAET,YAAY,IAAI,cAAc,QAAQ,SAAQ;;;;;;;EAiB9C,WAAW;;;UAkBK;;EAEhB;;EAEA,aAAa,SAAS"}
|
package/dist/telemetry.cjs
CHANGED
|
@@ -30,15 +30,21 @@ var Telemetry = class {
|
|
|
30
30
|
id;
|
|
31
31
|
ignorePaths;
|
|
32
32
|
attributes;
|
|
33
|
+
subdomain;
|
|
34
|
+
image;
|
|
33
35
|
constructor(id, config = {}) {
|
|
34
36
|
this.id = (0, _geekmidas_manifest.canonicalId)(id);
|
|
37
|
+
if (config.subdomain !== void 0) (0, _geekmidas_manifest.assertSubdomainLabel)(this.id, config.subdomain);
|
|
35
38
|
this.ignorePaths = [...config.ignorePaths ?? []];
|
|
36
39
|
this.attributes = { ...config.attributes };
|
|
40
|
+
this.subdomain = config.subdomain;
|
|
41
|
+
this.image = config.image;
|
|
37
42
|
}
|
|
38
43
|
/**
|
|
39
|
-
* One node, providing OpenTelemetry's own variables.
|
|
40
|
-
*
|
|
41
|
-
*
|
|
44
|
+
* One node, providing OpenTelemetry's own variables. Where the telemetry
|
|
45
|
+
* goes is the deploy's, resolved by the target for each stage; what is
|
|
46
|
+
* declared is only what is the same on every stage — the log UI's label
|
|
47
|
+
* and the image that runs it.
|
|
42
48
|
*/
|
|
43
49
|
declare() {
|
|
44
50
|
return [{
|
|
@@ -46,6 +52,8 @@ var Telemetry = class {
|
|
|
46
52
|
id: this.id,
|
|
47
53
|
...this.ignorePaths.length ? { ignorePaths: this.ignorePaths } : {},
|
|
48
54
|
...Object.keys(this.attributes).length ? { attributes: this.attributes } : {},
|
|
55
|
+
...this.subdomain ? { subdomain: this.subdomain } : {},
|
|
56
|
+
...this.image ? { image: this.image } : {},
|
|
49
57
|
provides: [..._geekmidas_manifest.TELEMETRY_KEYS]
|
|
50
58
|
}];
|
|
51
59
|
}
|
package/dist/telemetry.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"telemetry.cjs","names":["canonicalId","TELEMETRY_KEYS"],"sources":["../src/telemetry.ts"],"sourcesContent":["/**\n * `Telemetry` — what an application emits, declared.\n *\n * Traces and logs over OTLP, from every process that is given it. The\n * construct says *what* is emitted — which requests are noise, which\n * attributes every span carries — and never where it goes or how much of it:\n * the provider and the sample rate are the deploy's, per stage\n * (`deploy.telemetry` in `gkm.config.ts`), and locally `gkm dev` runs\n * OpenObserve and sends everything there.\n *\n * ```ts\n * export const telemetry = new Telemetry('Telemetry', {\n * ignorePaths: ['/health', '/ready'],\n * attributes: { 'service.namespace': 'shop' },\n * });\n *\n * // passed like the logger: a fact about the process\n * new RestApi('Api', { path: 'apps/api', defaultAuthorizer: 'none', telemetry });\n * new Worker('Jobs', { logger, telemetry });\n * ```\n *\n * Each process given it is an edge to this node, so the `OTEL_*` keys it\n * provides reach exactly those processes, and the build of each one fails\n * without the OpenTelemetry packages it needs.\n */\n\nimport {\n\ttype ConstructName,\n\tcanonicalId,\n\ttype Declaration,\n\tTELEMETRY_KEYS,\n} from '@geekmidas/manifest';\nimport type { Declarable } from './construct-interface';\n\nexport interface TelemetryConfig {\n\t/**\n\t * Request paths no span is recorded for, on every surface that uses this —\n\t * health checks, by default the only noise worth naming. A trailing `*`\n\t * matches a prefix. One route on one surface says so itself:\n\t * `.telemetry({ ignore: true })`.\n\t */\n\tignorePaths?: readonly string[];\n\t/**\n\t * Resource attributes every span and log record carries —\n\t * `{ 'service.namespace': 'shop' }`. The service's name is not one of\n\t * them: it is the app's, set per process.\n\t */\n\tattributes?: Readonly<Record<string, string>>;\n}\n\nexport class Telemetry<TName extends string = string>\n\timplements Declarable<TName>\n{\n\treadonly id: TName;\n\treadonly ignorePaths: readonly string[];\n\treadonly attributes: Readonly<Record<string, string>>;\n\n\tconstructor(id: ConstructName<TName>, config: TelemetryConfig = {}) {\n\t\tthis.id = canonicalId(id as string) as TName;\n\t\tthis.ignorePaths = [...(config.ignorePaths ?? [])];\n\t\tthis.attributes = { ...config.attributes };\n\t}\n\n\t/**\n\t * One node, providing OpenTelemetry's own variables.
|
|
1
|
+
{"version":3,"file":"telemetry.cjs","names":["canonicalId","TELEMETRY_KEYS"],"sources":["../src/telemetry.ts"],"sourcesContent":["/**\n * `Telemetry` — what an application emits, declared.\n *\n * Traces and logs over OTLP, from every process that is given it. The\n * construct says *what* is emitted — which requests are noise, which\n * attributes every span carries — and never where it goes or how much of it:\n * the provider and the sample rate are the deploy's, per stage\n * (`deploy.telemetry` in `gkm.config.ts`), and locally `gkm dev` runs\n * OpenObserve and sends everything there.\n *\n * ```ts\n * export const telemetry = new Telemetry('Telemetry', {\n * ignorePaths: ['/health', '/ready'],\n * attributes: { 'service.namespace': 'shop' },\n * });\n *\n * // passed like the logger: a fact about the process\n * new RestApi('Api', { path: 'apps/api', defaultAuthorizer: 'none', telemetry });\n * new Worker('Jobs', { logger, telemetry });\n * ```\n *\n * Each process given it is an edge to this node, so the `OTEL_*` keys it\n * provides reach exactly those processes, and the build of each one fails\n * without the OpenTelemetry packages it needs.\n */\n\nimport {\n\tassertSubdomainLabel,\n\ttype ConstructName,\n\tcanonicalId,\n\ttype Declaration,\n\tTELEMETRY_KEYS,\n} from '@geekmidas/manifest';\nimport type { Declarable } from './construct-interface';\n\nexport interface TelemetryConfig {\n\t/**\n\t * Request paths no span is recorded for, on every surface that uses this —\n\t * health checks, by default the only noise worth naming. A trailing `*`\n\t * matches a prefix. One route on one surface says so itself:\n\t * `.telemetry({ ignore: true })`.\n\t */\n\tignorePaths?: readonly string[];\n\t/**\n\t * Resource attributes every span and log record carries —\n\t * `{ 'service.namespace': 'shop' }`. The service's name is not one of\n\t * them: it is the app's, set per process.\n\t */\n\tattributes?: Readonly<Record<string, string>>;\n\t/**\n\t * The label the log UI answers on under the stage's domain, where a stage\n\t * serves it publicly (`deploy.telemetry.<stage>.public`). Defaults to the\n\t * id kebab-cased — `telemetry.<stage domain>` for `Telemetry`.\n\t *\n\t * Here rather than in the stage's config because it is the same on every\n\t * stage; whether it is served, and to whom, is the stage's.\n\t */\n\tsubdomain?: string;\n\t/**\n\t * The image the self-hosted provider runs — OpenObserve, taken verbatim.\n\t * Defaults to the version gkm pins.\n\t */\n\timage?: string;\n}\n\nexport class Telemetry<TName extends string = string>\n\timplements Declarable<TName>\n{\n\treadonly id: TName;\n\treadonly ignorePaths: readonly string[];\n\treadonly attributes: Readonly<Record<string, string>>;\n\treadonly subdomain: string | undefined;\n\treadonly image: string | undefined;\n\n\tconstructor(id: ConstructName<TName>, config: TelemetryConfig = {}) {\n\t\tthis.id = canonicalId(id as string) as TName;\n\t\tif (config.subdomain !== undefined) {\n\t\t\tassertSubdomainLabel(this.id, config.subdomain);\n\t\t}\n\t\tthis.ignorePaths = [...(config.ignorePaths ?? [])];\n\t\tthis.attributes = { ...config.attributes };\n\t\tthis.subdomain = config.subdomain;\n\t\tthis.image = config.image;\n\t}\n\n\t/**\n\t * One node, providing OpenTelemetry's own variables. Where the telemetry\n\t * goes is the deploy's, resolved by the target for each stage; what is\n\t * declared is only what is the same on every stage — the log UI's label\n\t * and the image that runs it.\n\t */\n\tdeclare(): Declaration[] {\n\t\treturn [\n\t\t\t{\n\t\t\t\tkind: 'telemetry',\n\t\t\t\tid: this.id,\n\t\t\t\t...(this.ignorePaths.length ? { ignorePaths: this.ignorePaths } : {}),\n\t\t\t\t...(Object.keys(this.attributes).length\n\t\t\t\t\t? { attributes: this.attributes }\n\t\t\t\t\t: {}),\n\t\t\t\t...(this.subdomain ? { subdomain: this.subdomain } : {}),\n\t\t\t\t...(this.image ? { image: this.image } : {}),\n\t\t\t\tprovides: [...TELEMETRY_KEYS],\n\t\t\t},\n\t\t];\n\t}\n}\n\n/** Per-route telemetry, on the endpoint builder — `.telemetry({ ignore: true })`. */\nexport interface EndpointTelemetry {\n\t/** Record no span for this route. */\n\tignore?: boolean;\n\t/** Attributes this route's request span carries. */\n\tattributes?: Readonly<Record<string, string>>;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiEA,IAAa,YAAb,MAEA;CACC;CACA;CACA;CACA;CACA;CAEA,YAAY,IAA0B,SAA0B,CAAC,GAAG;EACnE,KAAK,MAAA,GAAKA,oBAAAA,YAAAA,CAAY,EAAY;EAClC,IAAI,OAAO,cAAc,KAAA,GACxB,CAAA,GAAA,oBAAA,qBAAA,CAAqB,KAAK,IAAI,OAAO,SAAS;EAE/C,KAAK,cAAc,CAAC,GAAI,OAAO,eAAe,CAAC,CAAE;EACjD,KAAK,aAAa,EAAE,GAAG,OAAO,WAAW;EACzC,KAAK,YAAY,OAAO;EACxB,KAAK,QAAQ,OAAO;CACrB;;;;;;;CAQA,UAAyB;EACxB,OAAO,CACN;GACC,MAAM;GACN,IAAI,KAAK;GACT,GAAI,KAAK,YAAY,SAAS,EAAE,aAAa,KAAK,YAAY,IAAI,CAAC;GACnE,GAAI,OAAO,KAAK,KAAK,UAAU,CAAC,CAAC,SAC9B,EAAE,YAAY,KAAK,WAAW,IAC9B,CAAC;GACJ,GAAI,KAAK,YAAY,EAAE,WAAW,KAAK,UAAU,IAAI,CAAC;GACtD,GAAI,KAAK,QAAQ,EAAE,OAAO,KAAK,MAAM,IAAI,CAAC;GAC1C,UAAU,CAAC,GAAGC,oBAAAA,cAAc;EAC7B,CACD;CACD;AACD"}
|
package/dist/telemetry.d.cts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as Telemetry, r as TelemetryConfig, t as EndpointTelemetry } from "./telemetry-
|
|
1
|
+
import { n as Telemetry, r as TelemetryConfig, t as EndpointTelemetry } from "./telemetry-BbLyS7ln.cjs";
|
|
2
2
|
export { EndpointTelemetry, Telemetry, TelemetryConfig };
|