@geekmidas/constructs 10.0.0-alpha.166 → 10.0.0-alpha.168
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/Construct-127M7yrl.d.cts.map +1 -1
- package/dist/Construct-BMk_CRSD.d.mts.map +1 -1
- package/dist/{Cron-D_sfaMGz.d.cts → Cron-Ca_qHQu2.d.cts} +2 -2
- package/dist/{Cron-D6Y7BBt3.d.mts.map → Cron-Ca_qHQu2.d.cts.map} +1 -1
- package/dist/{Cron-D6Y7BBt3.d.mts → Cron-DPJiR7Lt.d.mts} +2 -2
- package/dist/{Cron-D_sfaMGz.d.cts.map → Cron-DPJiR7Lt.d.mts.map} +1 -1
- package/dist/{CronBuilder-4BZhkChG.d.mts → CronBuilder-BC4za5Bx.d.mts} +4 -4
- package/dist/{CronBuilder-4BZhkChG.d.mts.map → CronBuilder-BC4za5Bx.d.mts.map} +1 -1
- package/dist/{CronBuilder-C91MVLSr.d.cts → CronBuilder-C3RrAF1-.d.cts} +4 -4
- package/dist/{CronBuilder-C91MVLSr.d.cts.map → CronBuilder-C3RrAF1-.d.cts.map} +1 -1
- package/dist/{Endpoint-YYwjqtS1.d.cts → Endpoint-BlIZLsBQ.d.cts} +5 -5
- package/dist/{Endpoint-BUoDD96P.d.mts.map → Endpoint-BlIZLsBQ.d.cts.map} +1 -1
- package/dist/{Endpoint-BUoDD96P.d.mts → Endpoint-DC7mreOr.d.mts} +5 -5
- package/dist/{Endpoint-YYwjqtS1.d.cts.map → Endpoint-DC7mreOr.d.mts.map} +1 -1
- package/dist/{EndpointFactory-BbVOeryo.d.mts → EndpointFactory-DCmnCmkX.d.mts} +5 -5
- package/dist/{EndpointFactory-BbVOeryo.d.mts.map → EndpointFactory-DCmnCmkX.d.mts.map} +1 -1
- package/dist/{EndpointFactory-Hh1r6J_C.d.cts → EndpointFactory-cVTb8kCc.d.cts} +5 -5
- package/dist/{EndpointFactory-Hh1r6J_C.d.cts.map → EndpointFactory-cVTb8kCc.d.cts.map} +1 -1
- package/dist/{ObjectSubscriberBuilder-DfzXQEKW.d.mts → ObjectSubscriberBuilder-AwGKoUKy.d.mts} +2 -2
- package/dist/{ObjectSubscriberBuilder-DfzXQEKW.d.mts.map → ObjectSubscriberBuilder-AwGKoUKy.d.mts.map} +1 -1
- package/dist/{ObjectSubscriberBuilder-LWkey_oq.d.cts → ObjectSubscriberBuilder-CB6imsX4.d.cts} +2 -2
- package/dist/{ObjectSubscriberBuilder-LWkey_oq.d.cts.map → ObjectSubscriberBuilder-CB6imsX4.d.cts.map} +1 -1
- package/dist/{ProcessorBuilder-_jdZlbfW.d.cts → ProcessorBuilder-CeEZ2vCx.d.cts} +2 -2
- package/dist/{ProcessorBuilder-D4oYvZeG.d.mts.map → ProcessorBuilder-CeEZ2vCx.d.cts.map} +1 -1
- package/dist/{ProcessorBuilder-D4oYvZeG.d.mts → ProcessorBuilder-CwIlm75W.d.mts} +2 -2
- package/dist/{ProcessorBuilder-_jdZlbfW.d.cts.map → ProcessorBuilder-CwIlm75W.d.mts.map} +1 -1
- package/dist/{Queue-u8w8_HpE.mjs → Queue-9Hh20ZCk.mjs} +3 -3
- package/dist/Queue-9Hh20ZCk.mjs.map +1 -0
- package/dist/Queue-B8HGg439.d.mts.map +1 -1
- package/dist/Queue-C4rijiM7.d.cts.map +1 -1
- package/dist/{Queue-D4Iaidrs.cjs → Queue-W1wueijP.cjs} +2 -2
- package/dist/Queue-W1wueijP.cjs.map +1 -0
- package/dist/{QueueBuilder-BxsZ9o5z.cjs → QueueBuilder-BDcv9B71.cjs} +2 -2
- package/dist/{QueueBuilder-BxsZ9o5z.cjs.map → QueueBuilder-BDcv9B71.cjs.map} +1 -1
- package/dist/{QueueBuilder-CVS_qPuo.d.mts → QueueBuilder-CUERv8jt.d.mts} +2 -2
- package/dist/{QueueBuilder-CVS_qPuo.d.mts.map → QueueBuilder-CUERv8jt.d.mts.map} +1 -1
- package/dist/{QueueBuilder-SQli59An.d.cts → QueueBuilder-CmB1vOgn.d.cts} +2 -2
- package/dist/{QueueBuilder-SQli59An.d.cts.map → QueueBuilder-CmB1vOgn.d.cts.map} +1 -1
- package/dist/{QueueBuilder-2wP5lEC8.mjs → QueueBuilder-CrZL8HHs.mjs} +2 -2
- package/dist/{QueueBuilder-2wP5lEC8.mjs.map → QueueBuilder-CrZL8HHs.mjs.map} +1 -1
- package/dist/{Topic-DN2gYJ-p.mjs → Topic-BGoOeCT6.mjs} +3 -3
- package/dist/Topic-BGoOeCT6.mjs.map +1 -0
- package/dist/{Topic-Dp9Q7Lj2.cjs → Topic-DLCZBNwK.cjs} +2 -2
- package/dist/Topic-DLCZBNwK.cjs.map +1 -0
- 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.cjs +15 -15
- package/dist/adaptors/testing.cjs.map +1 -1
- package/dist/adaptors/testing.d.cts +5 -5
- package/dist/adaptors/testing.d.cts.map +1 -1
- package/dist/adaptors/testing.d.mts +5 -5
- package/dist/adaptors/testing.d.mts.map +1 -1
- package/dist/adaptors/testing.mjs +16 -16
- package/dist/adaptors/testing.mjs.map +1 -1
- package/dist/{auth-DnB9H9KL.d.mts → auth-1yI2wR-4.d.cts} +6 -6
- package/dist/{auth-BqWz2JxC.d.cts.map → auth-1yI2wR-4.d.cts.map} +1 -1
- package/dist/{auth-BqWz2JxC.d.cts → auth-D4NMXgLt.d.mts} +6 -6
- package/dist/{auth-DnB9H9KL.d.mts.map → auth-D4NMXgLt.d.mts.map} +1 -1
- package/dist/auth.cjs +5 -5
- package/dist/auth.cjs.map +1 -1
- package/dist/auth.d.cts +1 -1
- package/dist/auth.d.mts +1 -1
- package/dist/auth.mjs +6 -6
- package/dist/auth.mjs.map +1 -1
- package/dist/{cache-CCHcO9Oo.d.mts → cache-0VoeOTF9.d.mts} +2 -2
- package/dist/{cache-CCHcO9Oo.d.mts.map → cache-0VoeOTF9.d.mts.map} +1 -1
- package/dist/{cache-CQjMNPrC.d.cts → cache-CW-sArzS.d.cts} +2 -2
- package/dist/{cache-CQjMNPrC.d.cts.map → cache-CW-sArzS.d.cts.map} +1 -1
- package/dist/cache.cjs +1 -1
- package/dist/cache.cjs.map +1 -1
- package/dist/cache.d.cts +1 -1
- package/dist/cache.d.mts +1 -1
- package/dist/cache.mjs +2 -2
- package/dist/cache.mjs.map +1 -1
- package/dist/{construct-interface-CSA9VeWM.d.mts → construct-interface-DhbaONW2.d.cts} +20 -4
- package/dist/construct-interface-DhbaONW2.d.cts.map +1 -0
- package/dist/{construct-interface-DugP0E5q.d.cts → construct-interface-DxfkFxkl.d.mts} +20 -4
- package/dist/construct-interface-DxfkFxkl.d.mts.map +1 -0
- package/dist/construct-interface.cjs +9 -0
- 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 +9 -1
- package/dist/construct-interface.mjs.map +1 -1
- package/dist/{credential-DfSAOOdY.mjs → credential-B80mOxwT.mjs} +3 -3
- package/dist/credential-B80mOxwT.mjs.map +1 -0
- package/dist/{credential-DYymbp_7.cjs → credential-RlgbzZAc.cjs} +2 -2
- package/dist/credential-RlgbzZAc.cjs.map +1 -0
- package/dist/credential.cjs +1 -1
- package/dist/credential.d.cts +1 -1
- package/dist/credential.d.mts +1 -1
- package/dist/credential.mjs +1 -1
- package/dist/crons/index.d.cts +2 -2
- package/dist/crons/index.d.mts +2 -2
- package/dist/database/kysely.cjs +1 -1
- package/dist/database/kysely.d.cts +1 -1
- package/dist/database/kysely.d.mts +1 -1
- package/dist/database/kysely.mjs +1 -1
- package/dist/email.cjs +2 -2
- package/dist/email.cjs.map +1 -1
- package/dist/email.d.cts +1 -1
- package/dist/email.d.mts +1 -1
- package/dist/email.mjs +3 -3
- package/dist/email.mjs.map +1 -1
- package/dist/encryption.cjs +1 -1
- package/dist/encryption.cjs.map +1 -1
- package/dist/encryption.d.cts +1 -1
- package/dist/encryption.d.mts +1 -1
- package/dist/encryption.mjs +2 -2
- package/dist/encryption.mjs.map +1 -1
- package/dist/endpoints/index.d.cts +2 -2
- package/dist/endpoints/index.d.mts +2 -2
- package/dist/external-api.cjs +3 -3
- package/dist/external-api.cjs.map +1 -1
- package/dist/external-api.d.cts +1 -1
- package/dist/external-api.d.mts +1 -1
- package/dist/external-api.mjs +4 -4
- package/dist/external-api.mjs.map +1 -1
- package/dist/{fake-BqhP8RRQ.d.mts → fake-BvOXkZmj.d.mts} +2 -2
- package/dist/{fake-BqhP8RRQ.d.mts.map → fake-BvOXkZmj.d.mts.map} +1 -1
- package/dist/{fake-DqieDYYA.d.cts → fake-Djx8E0o1.d.cts} +2 -2
- package/dist/{fake-DqieDYYA.d.cts.map → fake-Djx8E0o1.d.cts.map} +1 -1
- package/dist/file-server.cjs +79 -20
- package/dist/file-server.cjs.map +1 -1
- package/dist/file-server.d.cts +35 -17
- package/dist/file-server.d.cts.map +1 -1
- package/dist/file-server.d.mts +35 -17
- package/dist/file-server.d.mts.map +1 -1
- package/dist/file-server.mjs +80 -22
- 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-CR3L1fOI.d.cts → inbox-BjvMs7EJ.d.cts} +2 -2
- package/dist/{inbox-CR3L1fOI.d.cts.map → inbox-BjvMs7EJ.d.cts.map} +1 -1
- package/dist/{inbox-YOdxlyfj.d.mts → inbox-C8bOR9UL.d.mts} +2 -2
- package/dist/{inbox-YOdxlyfj.d.mts.map → inbox-C8bOR9UL.d.mts.map} +1 -1
- package/dist/inbox.cjs +3 -3
- package/dist/inbox.cjs.map +1 -1
- package/dist/inbox.d.cts +1 -1
- package/dist/inbox.d.mts +1 -1
- package/dist/inbox.mjs +4 -4
- package/dist/inbox.mjs.map +1 -1
- package/dist/{index-DPTHa6Ud.d.cts → index-DaK-C7N3.d.cts} +2 -2
- package/dist/{index-BoQ3-M-K.d.mts.map → index-DaK-C7N3.d.cts.map} +1 -1
- package/dist/{index-BoQ3-M-K.d.mts → index-vCS4HBEG.d.mts} +2 -2
- package/dist/{index-DPTHa6Ud.d.cts.map → index-vCS4HBEG.d.mts.map} +1 -1
- package/dist/{kysely-CebjCWTl.d.cts → kysely-2HqIQ2fC.d.cts} +3 -3
- package/dist/{kysely-CebjCWTl.d.cts.map → kysely-2HqIQ2fC.d.cts.map} +1 -1
- package/dist/{kysely-De5rAC-E.d.mts → kysely-BGvpd_ZH.d.mts} +3 -3
- package/dist/{kysely-De5rAC-E.d.mts.map → kysely-BGvpd_ZH.d.mts.map} +1 -1
- package/dist/{kysely-Cs4uPO8k.mjs → kysely-Bc9xzaik.mjs} +4 -4
- package/dist/kysely-Bc9xzaik.mjs.map +1 -0
- package/dist/{kysely-CukArHJ0.cjs → kysely-D7f6J2lh.cjs} +3 -3
- package/dist/kysely-D7f6J2lh.cjs.map +1 -0
- package/dist/mobile-app.cjs +6 -2
- package/dist/mobile-app.cjs.map +1 -1
- package/dist/mobile-app.d.cts +5 -1
- package/dist/mobile-app.d.cts.map +1 -1
- package/dist/mobile-app.d.mts +5 -1
- package/dist/mobile-app.d.mts.map +1 -1
- package/dist/mobile-app.mjs +8 -4
- package/dist/mobile-app.mjs.map +1 -1
- package/dist/object-storage.cjs +6 -6
- package/dist/object-storage.cjs.map +1 -1
- package/dist/object-storage.d.cts +3 -3
- package/dist/object-storage.d.cts.map +1 -1
- package/dist/object-storage.d.mts +3 -3
- package/dist/object-storage.d.mts.map +1 -1
- package/dist/object-storage.mjs +7 -7
- 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.cjs +2 -2
- package/dist/queue/index.d.cts +1 -1
- package/dist/queue/index.d.mts +1 -1
- package/dist/queue/index.mjs +2 -2
- package/dist/random-password.d.cts +1 -1
- package/dist/random-password.d.mts +1 -1
- package/dist/rest-api.cjs +3 -3
- package/dist/rest-api.cjs.map +1 -1
- package/dist/rest-api.d.cts +4 -4
- package/dist/rest-api.d.mts +4 -4
- package/dist/rest-api.mjs +4 -4
- package/dist/rest-api.mjs.map +1 -1
- package/dist/site.cjs +8 -3
- package/dist/site.cjs.map +1 -1
- package/dist/site.d.cts +7 -2
- package/dist/site.d.cts.map +1 -1
- package/dist/site.d.mts +7 -2
- package/dist/site.d.mts.map +1 -1
- package/dist/site.mjs +10 -5
- 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-CObow3Dn.d.mts → telemetry-BirKau0X.d.mts} +2 -2
- package/dist/{telemetry-C1oqncFY.d.cts.map → telemetry-BirKau0X.d.mts.map} +1 -1
- package/dist/{telemetry-C1oqncFY.d.cts → telemetry-DjJgtQ_N.d.cts} +2 -2
- package/dist/{telemetry-CObow3Dn.d.mts.map → telemetry-DjJgtQ_N.d.cts.map} +1 -1
- package/dist/telemetry.d.cts +1 -1
- package/dist/telemetry.d.mts +1 -1
- package/dist/topic/index.cjs +1 -1
- package/dist/topic/index.mjs +1 -1
- package/dist/{websocket-api-DkF8Hva-.d.cts → websocket-api-B1Wl3tg4.d.cts} +3 -3
- package/dist/{websocket-api-CPEzJyDt.d.mts.map → websocket-api-B1Wl3tg4.d.cts.map} +1 -1
- package/dist/{websocket-api-CPEzJyDt.d.mts → websocket-api-CvnPDSZB.d.mts} +3 -3
- package/dist/{websocket-api-DkF8Hva-.d.cts.map → websocket-api-CvnPDSZB.d.mts.map} +1 -1
- package/dist/{websocket-api-czxhekGG.cjs → websocket-api-Zy2U-Qyh.cjs} +4 -4
- package/dist/websocket-api-Zy2U-Qyh.cjs.map +1 -0
- package/dist/{websocket-api-Bg9SowJ5.mjs → websocket-api-svBCnOAE.mjs} +5 -5
- package/dist/{websocket-api-Bg9SowJ5.mjs.map → websocket-api-svBCnOAE.mjs.map} +1 -1
- package/dist/websocket-api.cjs +1 -1
- package/dist/websocket-api.d.cts +1 -1
- package/dist/websocket-api.d.mts +1 -1
- package/dist/websocket-api.mjs +1 -1
- package/dist/worker.cjs +1 -1
- package/dist/worker.d.cts +8 -8
- package/dist/worker.d.mts +8 -8
- package/dist/worker.mjs +1 -1
- package/package.json +31 -31
- package/dist/Queue-D4Iaidrs.cjs.map +0 -1
- package/dist/Queue-u8w8_HpE.mjs.map +0 -1
- package/dist/Topic-DN2gYJ-p.mjs.map +0 -1
- package/dist/Topic-Dp9Q7Lj2.cjs.map +0 -1
- package/dist/construct-interface-CSA9VeWM.d.mts.map +0 -1
- package/dist/construct-interface-DugP0E5q.d.cts.map +0 -1
- package/dist/credential-DYymbp_7.cjs.map +0 -1
- package/dist/credential-DfSAOOdY.mjs.map +0 -1
- package/dist/kysely-Cs4uPO8k.mjs.map +0 -1
- package/dist/kysely-CukArHJ0.cjs.map +0 -1
- package/dist/websocket-api-czxhekGG.cjs.map +0 -1
package/dist/email.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"email.cjs","names":["canonicalId","
|
|
1
|
+
{"version":3,"file":"email.cjs","names":["canonicalId","providedKeyFor","serviceKey","loadEmailkit"],"sources":["../src/email.ts"],"sourcesContent":["/**\n * `Email` — declared outbound mail.\n *\n * The same three-package meeting point as `ObjectStorage`: it implements the\n * construct contract, derives its env key through `@geekmidas/manifest`, and\n * hands back an `@geekmidas/emailkit` client. It names no provider — locally the\n * injected URL points at Mailpit, deployed it points at SES or whichever service\n * config selected.\n *\n * Where object storage needs a driver per provider, this needs none: mail is\n * delivered over SMTP whoever delivers it, so there is one client and one URL\n * shape, and the provider survives only as a host and a credential.\n */\n\nimport type { EmailClient, TemplateRecord } from '@geekmidas/emailkit';\nimport {\n\ttype ConstructName,\n\tcanonicalId,\n\ttype Declaration,\n\tprovidedKeyFor,\n\tserviceKey,\n} from '@geekmidas/manifest';\nimport type { Service, ServiceRegisterOptions } from '@geekmidas/services';\nimport type { Construct } from './construct-interface';\nimport { loadEmailkit } from './optionalPeers';\n\nexport interface EmailOptions<TTemplates extends TemplateRecord> {\n\t/**\n\t * The React templates this app can send.\n\t *\n\t * Structural — they are code, they ship with the handler, and which ones\n\t * exist cannot differ between stages. They are also what types\n\t * `sendTemplate`, so passing them here is what makes the client's call sites\n\t * checkable.\n\t */\n\ttemplates: TTemplates;\n\t/**\n\t * A reply-to address for every send.\n\t *\n\t * `from` is deliberately absent: it belongs to the verified sending domain,\n\t * which is `myapp.test` locally and the real domain deployed, so it arrives\n\t * as stage config rather than being written here.\n\t */\n\treplyTo?: string;\n}\n\nexport class Email<\n\tTName extends string = string,\n\tTTemplates extends TemplateRecord = TemplateRecord,\n> implements Construct<TName, EmailClient<TTemplates>>\n{\n\treadonly id: TName;\n\treadonly service: Service<Uncapitalize<TName>, EmailClient<TTemplates>>;\n\n\t/**\n\t * Declared once and read by both `declare()` and `connect()`, so the key the\n\t * build publishes and the key the client reads cannot drift.\n\t */\n\tprivate readonly keys: { url: string; from: string };\n\n\tconstructor(\n\t\tid: ConstructName<TName>,\n\t\tprivate readonly options: EmailOptions<TTemplates>,\n\t) {\n\t\tconst canonical = canonicalId(id as string);\n\n\t\tthis.id = canonical as TName;\n\t\tthis.keys = {\n\t\t\turl: providedKeyFor(canonical, 'email', 'url'),\n\t\t\t// The sending identity travels with the URL rather than being a second\n\t\t\t// construct option, for the same reason the URL does: it is the one\n\t\t\t// thing about mail that differs per stage.\n\t\t\tfrom: providedKeyFor(canonical, 'email', 'from'),\n\t\t};\n\n\t\t// A field, not a getter: consumers cache services by object identity.\n\t\tthis.service = {\n\t\t\tserviceName: serviceKey(canonical) as Uncapitalize<TName>,\n\t\t\tregister: (options) => this.connect(options),\n\t\t};\n\t}\n\n\tdeclare(): Declaration[] {\n\t\treturn [\n\t\t\t{\n\t\t\t\tkind: 'email',\n\t\t\t\tid: this.id,\n\t\t\t\tprovides: [this.keys.url, this.keys.from],\n\t\t\t},\n\t\t];\n\t}\n\n\t/**\n\t * Builds the client from the URL the adapter supplied.\n\t *\n\t * No provider branch and no driver lookup — `parseEmailUrl` turns any of\n\t * Mailpit, SES, or Resend into the same transport config, which is the whole\n\t * reason the scheme is always `smtp://`.\n\t */\n\tprivate async connect({\n\t\tenvParser,\n\t}: ServiceRegisterOptions): Promise<EmailClient<TTemplates>> {\n\t\tconst { url, from } = envParser\n\t\t\t.create((get) => ({\n\t\t\t\turl: get(this.keys.url).string(),\n\t\t\t\tfrom: get(this.keys.from).string(),\n\t\t\t}))\n\t\t\t.parse();\n\n\t\t// Loaded here, not at the top: the test harness names this construct in\n\t\t// every app, and an app that sends no mail does not install emailkit.\n\t\tconst { createEmailClient, parseEmailUrl } = await loadEmailkit();\n\t\treturn createEmailClient({\n\t\t\tsmtp: parseEmailUrl(url),\n\t\t\ttemplates: this.options.templates,\n\t\t\tdefaults: {\n\t\t\t\tfrom,\n\t\t\t\t...(this.options.replyTo ? { replyTo: this.options.replyTo } : {}),\n\t\t\t},\n\t\t});\n\t}\n}\n"],"mappings":";;;;AA8CA,IAAa,QAAb,MAIA;CAYmB;CAXlB;CACA;;;;;CAMA;CAEA,YACC,IACA,SACC;EADgB,KAAA,UAAA;EAEjB,MAAM,aAAA,GAAYA,oBAAAA,YAAAA,CAAY,EAAY;EAE1C,KAAK,KAAK;EACV,KAAK,OAAO;GACX,MAAA,GAAKC,oBAAAA,eAAAA,CAAe,WAAW,SAAS,KAAK;GAI7C,OAAA,GAAMA,oBAAAA,eAAAA,CAAe,WAAW,SAAS,MAAM;EAChD;EAGA,KAAK,UAAU;GACd,cAAA,GAAaC,oBAAAA,WAAAA,CAAW,SAAS;GACjC,WAAW,YAAY,KAAK,QAAQ,OAAO;EAC5C;CACD;CAEA,UAAyB;EACxB,OAAO,CACN;GACC,MAAM;GACN,IAAI,KAAK;GACT,UAAU,CAAC,KAAK,KAAK,KAAK,KAAK,KAAK,IAAI;EACzC,CACD;CACD;;;;;;;;CASA,MAAc,QAAQ,EACrB,aAC4D;EAC5D,MAAM,EAAE,KAAK,SAAS,UACpB,QAAQ,SAAS;GACjB,KAAK,IAAI,KAAK,KAAK,GAAG,CAAC,CAAC,OAAO;GAC/B,MAAM,IAAI,KAAK,KAAK,IAAI,CAAC,CAAC,OAAO;EAClC,EAAE,CAAC,CACF,MAAM;EAIR,MAAM,EAAE,mBAAmB,kBAAkB,MAAMC,sBAAAA,aAAa;EAChE,OAAO,kBAAkB;GACxB,MAAM,cAAc,GAAG;GACvB,WAAW,KAAK,QAAQ;GACxB,UAAU;IACT;IACA,GAAI,KAAK,QAAQ,UAAU,EAAE,SAAS,KAAK,QAAQ,QAAQ,IAAI,CAAC;GACjE;EACD,CAAC;CACF;AACD"}
|
package/dist/email.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as Construct } from "./construct-interface-
|
|
1
|
+
import { n as Construct } from "./construct-interface-DhbaONW2.cjs";
|
|
2
2
|
import { Service } from "@geekmidas/services";
|
|
3
3
|
import { ConstructName, Declaration } from "@geekmidas/manifest";
|
|
4
4
|
import { EmailClient, TemplateRecord } from "@geekmidas/emailkit";
|
package/dist/email.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as Construct } from "./construct-interface-
|
|
1
|
+
import { n as Construct } from "./construct-interface-DxfkFxkl.mjs";
|
|
2
2
|
import { ConstructName, Declaration } from "@geekmidas/manifest";
|
|
3
3
|
import { Service } from "@geekmidas/services";
|
|
4
4
|
import { EmailClient, TemplateRecord } from "@geekmidas/emailkit";
|
package/dist/email.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { s as loadEmailkit } from "./optionalPeers-D7Wt6dnF.mjs";
|
|
2
|
-
import { canonicalId,
|
|
2
|
+
import { canonicalId, providedKeyFor, serviceKey } from "@geekmidas/manifest";
|
|
3
3
|
//#region src/email.ts
|
|
4
4
|
var Email = class {
|
|
5
5
|
options;
|
|
@@ -15,8 +15,8 @@ var Email = class {
|
|
|
15
15
|
const canonical = canonicalId(id);
|
|
16
16
|
this.id = canonical;
|
|
17
17
|
this.keys = {
|
|
18
|
-
url:
|
|
19
|
-
from:
|
|
18
|
+
url: providedKeyFor(canonical, "email", "url"),
|
|
19
|
+
from: providedKeyFor(canonical, "email", "from")
|
|
20
20
|
};
|
|
21
21
|
this.service = {
|
|
22
22
|
serviceName: serviceKey(canonical),
|
package/dist/email.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"email.mjs","names":[],"sources":["../src/email.ts"],"sourcesContent":["/**\n * `Email` — declared outbound mail.\n *\n * The same three-package meeting point as `ObjectStorage`: it implements the\n * construct contract, derives its env key through `@geekmidas/manifest`, and\n * hands back an `@geekmidas/emailkit` client. It names no provider — locally the\n * injected URL points at Mailpit, deployed it points at SES or whichever service\n * config selected.\n *\n * Where object storage needs a driver per provider, this needs none: mail is\n * delivered over SMTP whoever delivers it, so there is one client and one URL\n * shape, and the provider survives only as a host and a credential.\n */\n\nimport type { EmailClient, TemplateRecord } from '@geekmidas/emailkit';\nimport {\n\ttype ConstructName,\n\tcanonicalId,\n\ttype Declaration,\n\
|
|
1
|
+
{"version":3,"file":"email.mjs","names":[],"sources":["../src/email.ts"],"sourcesContent":["/**\n * `Email` — declared outbound mail.\n *\n * The same three-package meeting point as `ObjectStorage`: it implements the\n * construct contract, derives its env key through `@geekmidas/manifest`, and\n * hands back an `@geekmidas/emailkit` client. It names no provider — locally the\n * injected URL points at Mailpit, deployed it points at SES or whichever service\n * config selected.\n *\n * Where object storage needs a driver per provider, this needs none: mail is\n * delivered over SMTP whoever delivers it, so there is one client and one URL\n * shape, and the provider survives only as a host and a credential.\n */\n\nimport type { EmailClient, TemplateRecord } from '@geekmidas/emailkit';\nimport {\n\ttype ConstructName,\n\tcanonicalId,\n\ttype Declaration,\n\tprovidedKeyFor,\n\tserviceKey,\n} from '@geekmidas/manifest';\nimport type { Service, ServiceRegisterOptions } from '@geekmidas/services';\nimport type { Construct } from './construct-interface';\nimport { loadEmailkit } from './optionalPeers';\n\nexport interface EmailOptions<TTemplates extends TemplateRecord> {\n\t/**\n\t * The React templates this app can send.\n\t *\n\t * Structural — they are code, they ship with the handler, and which ones\n\t * exist cannot differ between stages. They are also what types\n\t * `sendTemplate`, so passing them here is what makes the client's call sites\n\t * checkable.\n\t */\n\ttemplates: TTemplates;\n\t/**\n\t * A reply-to address for every send.\n\t *\n\t * `from` is deliberately absent: it belongs to the verified sending domain,\n\t * which is `myapp.test` locally and the real domain deployed, so it arrives\n\t * as stage config rather than being written here.\n\t */\n\treplyTo?: string;\n}\n\nexport class Email<\n\tTName extends string = string,\n\tTTemplates extends TemplateRecord = TemplateRecord,\n> implements Construct<TName, EmailClient<TTemplates>>\n{\n\treadonly id: TName;\n\treadonly service: Service<Uncapitalize<TName>, EmailClient<TTemplates>>;\n\n\t/**\n\t * Declared once and read by both `declare()` and `connect()`, so the key the\n\t * build publishes and the key the client reads cannot drift.\n\t */\n\tprivate readonly keys: { url: string; from: string };\n\n\tconstructor(\n\t\tid: ConstructName<TName>,\n\t\tprivate readonly options: EmailOptions<TTemplates>,\n\t) {\n\t\tconst canonical = canonicalId(id as string);\n\n\t\tthis.id = canonical as TName;\n\t\tthis.keys = {\n\t\t\turl: providedKeyFor(canonical, 'email', 'url'),\n\t\t\t// The sending identity travels with the URL rather than being a second\n\t\t\t// construct option, for the same reason the URL does: it is the one\n\t\t\t// thing about mail that differs per stage.\n\t\t\tfrom: providedKeyFor(canonical, 'email', 'from'),\n\t\t};\n\n\t\t// A field, not a getter: consumers cache services by object identity.\n\t\tthis.service = {\n\t\t\tserviceName: serviceKey(canonical) as Uncapitalize<TName>,\n\t\t\tregister: (options) => this.connect(options),\n\t\t};\n\t}\n\n\tdeclare(): Declaration[] {\n\t\treturn [\n\t\t\t{\n\t\t\t\tkind: 'email',\n\t\t\t\tid: this.id,\n\t\t\t\tprovides: [this.keys.url, this.keys.from],\n\t\t\t},\n\t\t];\n\t}\n\n\t/**\n\t * Builds the client from the URL the adapter supplied.\n\t *\n\t * No provider branch and no driver lookup — `parseEmailUrl` turns any of\n\t * Mailpit, SES, or Resend into the same transport config, which is the whole\n\t * reason the scheme is always `smtp://`.\n\t */\n\tprivate async connect({\n\t\tenvParser,\n\t}: ServiceRegisterOptions): Promise<EmailClient<TTemplates>> {\n\t\tconst { url, from } = envParser\n\t\t\t.create((get) => ({\n\t\t\t\turl: get(this.keys.url).string(),\n\t\t\t\tfrom: get(this.keys.from).string(),\n\t\t\t}))\n\t\t\t.parse();\n\n\t\t// Loaded here, not at the top: the test harness names this construct in\n\t\t// every app, and an app that sends no mail does not install emailkit.\n\t\tconst { createEmailClient, parseEmailUrl } = await loadEmailkit();\n\t\treturn createEmailClient({\n\t\t\tsmtp: parseEmailUrl(url),\n\t\t\ttemplates: this.options.templates,\n\t\t\tdefaults: {\n\t\t\t\tfrom,\n\t\t\t\t...(this.options.replyTo ? { replyTo: this.options.replyTo } : {}),\n\t\t\t},\n\t\t});\n\t}\n}\n"],"mappings":";;;AA8CA,IAAa,QAAb,MAIA;CAYmB;CAXlB;CACA;;;;;CAMA;CAEA,YACC,IACA,SACC;EADgB,KAAA,UAAA;EAEjB,MAAM,YAAY,YAAY,EAAY;EAE1C,KAAK,KAAK;EACV,KAAK,OAAO;GACX,KAAK,eAAe,WAAW,SAAS,KAAK;GAI7C,MAAM,eAAe,WAAW,SAAS,MAAM;EAChD;EAGA,KAAK,UAAU;GACd,aAAa,WAAW,SAAS;GACjC,WAAW,YAAY,KAAK,QAAQ,OAAO;EAC5C;CACD;CAEA,UAAyB;EACxB,OAAO,CACN;GACC,MAAM;GACN,IAAI,KAAK;GACT,UAAU,CAAC,KAAK,KAAK,KAAK,KAAK,KAAK,IAAI;EACzC,CACD;CACD;;;;;;;;CASA,MAAc,QAAQ,EACrB,aAC4D;EAC5D,MAAM,EAAE,KAAK,SAAS,UACpB,QAAQ,SAAS;GACjB,KAAK,IAAI,KAAK,KAAK,GAAG,CAAC,CAAC,OAAO;GAC/B,MAAM,IAAI,KAAK,KAAK,IAAI,CAAC,CAAC,OAAO;EAClC,EAAE,CAAC,CACF,MAAM;EAIR,MAAM,EAAE,mBAAmB,kBAAkB,MAAM,aAAa;EAChE,OAAO,kBAAkB;GACxB,MAAM,cAAc,GAAG;GACvB,WAAW,KAAK,QAAQ;GACxB,UAAU;IACT;IACA,GAAI,KAAK,QAAQ,UAAU,EAAE,SAAS,KAAK,QAAQ,QAAQ,IAAI,CAAC;GACjE;EACD,CAAC;CACF;AACD"}
|
package/dist/encryption.cjs
CHANGED
|
@@ -69,7 +69,7 @@ var Encryption = class {
|
|
|
69
69
|
constructor(id) {
|
|
70
70
|
const canonical = (0, _geekmidas_manifest.canonicalId)(id);
|
|
71
71
|
this.id = canonical;
|
|
72
|
-
this.key = (0, _geekmidas_manifest.
|
|
72
|
+
this.key = (0, _geekmidas_manifest.providedKeyFor)(canonical, "encryption", "url");
|
|
73
73
|
this.service = {
|
|
74
74
|
serviceName: (0, _geekmidas_manifest.serviceKey)(canonical),
|
|
75
75
|
register: (options) => this.connect(options)
|
package/dist/encryption.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"encryption.cjs","names":["KMS_SCHEME","canonicalId","
|
|
1
|
+
{"version":3,"file":"encryption.cjs","names":["KMS_SCHEME","canonicalId","providedKeyFor","serviceKey","keyringCipher","UnknownEncryptionScheme"],"sources":["../src/encryption.ts"],"sourcesContent":["/**\n * `Encryption` — a key that encrypts what the application stores.\n *\n * ```ts\n * export const pii = new Encryption('Pii');\n *\n * // an endpoint that `.dependsOn([pii])`\n * const email = await services.pii.encrypt(body.email);\n * const emailIndex = await services.pii.index(body.email);\n * await db.insertInto('users').values({ email, emailIndex }).execute();\n *\n * // and to find them again, without decrypting a column\n * db.selectFrom('users').where('emailIndex', '=', await services.pii.index(q));\n * ```\n *\n * The app names no cipher and holds no key. The construct provides one URL,\n * `<ID>_URL`, and its scheme picks the backend the way a queue's connection\n * string picks its broker:\n *\n * - **AWS** — `kms://`: envelope encryption under a KMS key that rotates\n * yearly, and a KMS HMAC key for the index. Only a function that depends on\n * the construct is granted either key.\n * - **Server, local, tests** — `aes256gcm://`: a keyring the process holds.\n * Derived locally, so `gkm dev` and `gkm test` need nothing set; generated\n * into a server stage's secrets on its first deploy, and rotated there with\n * `gkm encryption:rotate`.\n *\n * Every ciphertext names the key that wrote it, so a rotated key still opens\n * what it wrote. Retiring one is explicit — `reencrypt` the column, then\n * `gkm encryption:retire` — and a value still under an old key says so when it\n * is decrypted, once per key per process.\n */\n\nimport {\n\ttype ConstructName,\n\tcanonicalId,\n\ttype Declaration,\n\tKMS_SCHEME,\n\tprovidedKeyFor,\n\tserviceKey,\n} from '@geekmidas/manifest';\nimport type { Service, ServiceRegisterOptions } from '@geekmidas/services';\nimport type { Construct } from './construct-interface';\nimport {\n\ttype Cipher,\n\ttype CipherDriver,\n\tkeyringCipher,\n\tLOCAL_SCHEME,\n\tUnknownEncryptionScheme,\n} from './encryption/cipher';\n\nexport type { Cipher, CipherDriver } from './encryption/cipher';\nexport {\n\tCiphertextMalformed,\n\tCiphertextNotAuthentic,\n\tCurrentKeyCannotRetire,\n\tEncryptionKeyRetired,\n\tEncryptionUrlInvalid,\n\tformatKeyring,\n\tgenerateKeyring,\n\ttype Keyring,\n\tkeyringCipher,\n\tparseKeyring,\n\tretireKey,\n\trotateKeyring,\n\tUnknownEncryptionScheme,\n} from './encryption/cipher';\n\nconst drivers = new Map<string, CipherDriver>();\n\n/** Make a cipher available for its scheme. Idempotent. */\nexport function registerCipherDriver(driver: CipherDriver): void {\n\tdrivers.set(driver.scheme, driver);\n}\n\n/**\n * A key whose URL names a cipher this process registered no driver for —\n * `kms:` in an entry built for a target whose keys are local.\n */\nexport class UnregisteredEncryptionScheme extends Error {\n\tconstructor(\n\t\treadonly construct: string,\n\t\treadonly scheme: string,\n\t) {\n\t\tsuper(\n\t\t\t`${construct}'s key is a '${scheme}' URL, and this build registered no cipher for it. ` +\n\t\t\t\t(scheme === KMS_SCHEME\n\t\t\t\t\t? \"A KMS key is an AWS target's: build for it (gkm build --provider aws), which registers the KMS cipher and needs @aws-sdk/client-kms installed.\"\n\t\t\t\t\t: 'Register its driver with registerCipherDriver before the first request.'),\n\t\t);\n\t\tthis.name = 'UnregisteredEncryptionScheme';\n\t}\n}\n\nexport class Encryption<TName extends string = string>\n\timplements Construct<TName, Cipher>\n{\n\treadonly id: TName;\n\treadonly service: Service<Uncapitalize<TName>, Cipher>;\n\n\t/**\n\t * Declared once and read by both `declare()` and `connect()`, so the key the\n\t * target publishes and the key the client reads cannot drift.\n\t */\n\tprivate readonly key: string;\n\n\t/**\n\t * One cipher per process, held as the promise: a keyring is parsed once and\n\t * a KMS client is built once, however many handlers register it at once.\n\t */\n\tprivate cipher?: Promise<Cipher>;\n\n\tconstructor(id: ConstructName<TName>) {\n\t\tconst canonical = canonicalId(id as string);\n\n\t\tthis.id = canonical as TName;\n\t\tthis.key = providedKeyFor(canonical, 'encryption', 'url');\n\n\t\t// A field, not a getter: consumers cache services by object identity.\n\t\tthis.service = {\n\t\t\tserviceName: serviceKey(canonical) as Uncapitalize<TName>,\n\t\t\tregister: (options) => this.connect(options),\n\t\t};\n\t}\n\n\tdeclare(): Declaration[] {\n\t\treturn [{ kind: 'encryption', id: this.id, provides: [this.key] }];\n\t}\n\n\tprivate connect(options: ServiceRegisterOptions): Promise<Cipher> {\n\t\tthis.cipher ??= this.open(options);\n\t\treturn this.cipher;\n\t}\n\n\tprivate async open(options: ServiceRegisterOptions): Promise<Cipher> {\n\t\tconst { url } = options.envParser\n\t\t\t.create((get) => ({ url: get(this.key).string() }))\n\t\t\t.parse();\n\t\tconst scheme = url.slice(0, url.indexOf(':') + 1);\n\n\t\tif (scheme === LOCAL_SCHEME) {\n\t\t\treturn keyringCipher(this.id, url, (stale, current) =>\n\t\t\t\tconsole.warn(\n\t\t\t\t\t`${this.id} decrypted a value still under '${stale}' (current: '${current}'). reencrypt it, and retire '${stale}' once nothing is left under it.`,\n\t\t\t\t),\n\t\t\t);\n\t\t}\n\n\t\t// Registered by the entry a build generates, only for a target whose\n\t\t// keys live there — so no other process imports that cipher's SDK.\n\t\tconst driver = drivers.get(scheme);\n\t\tif (driver) return driver.open(this.id, url);\n\t\tif (scheme === KMS_SCHEME) {\n\t\t\tthrow new UnregisteredEncryptionScheme(this.id, scheme);\n\t\t}\n\n\t\tthrow new UnknownEncryptionScheme(this.id, scheme);\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoEA,MAAM,0BAAU,IAAI,IAA0B;;AAG9C,SAAgB,qBAAqB,QAA4B;CAChE,QAAQ,IAAI,OAAO,QAAQ,MAAM;AAClC;;;;;AAMA,IAAa,+BAAb,cAAkD,MAAM;CAE7C;CACA;CAFV,YACC,WACA,QACC;EACD,MACC,GAAG,UAAU,eAAe,OAAO,wDACjC,WAAWA,oBAAAA,aACT,mJACA,0EACL;EARS,KAAA,YAAA;EACA,KAAA,SAAA;EAQT,KAAK,OAAO;CACb;AACD;AAEA,IAAa,aAAb,MAEA;CACC;CACA;;;;;CAMA;;;;;CAMA;CAEA,YAAY,IAA0B;EACrC,MAAM,aAAA,GAAYC,oBAAAA,YAAAA,CAAY,EAAY;EAE1C,KAAK,KAAK;EACV,KAAK,OAAA,GAAMC,oBAAAA,eAAAA,CAAe,WAAW,cAAc,KAAK;EAGxD,KAAK,UAAU;GACd,cAAA,GAAaC,oBAAAA,WAAAA,CAAW,SAAS;GACjC,WAAW,YAAY,KAAK,QAAQ,OAAO;EAC5C;CACD;CAEA,UAAyB;EACxB,OAAO,CAAC;GAAE,MAAM;GAAc,IAAI,KAAK;GAAI,UAAU,CAAC,KAAK,GAAG;EAAE,CAAC;CAClE;CAEA,QAAgB,SAAkD;EACjE,KAAK,WAAW,KAAK,KAAK,OAAO;EACjC,OAAO,KAAK;CACb;CAEA,MAAc,KAAK,SAAkD;EACpE,MAAM,EAAE,QAAQ,QAAQ,UACtB,QAAQ,SAAS,EAAE,KAAK,IAAI,KAAK,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,CAClD,MAAM;EACR,MAAM,SAAS,IAAI,MAAM,GAAG,IAAI,QAAQ,GAAG,IAAI,CAAC;EAEhD,IAAI,WAAA,cACH,OAAOC,eAAAA,cAAc,KAAK,IAAI,MAAM,OAAO,YAC1C,QAAQ,KACP,GAAG,KAAK,GAAG,kCAAkC,MAAM,eAAe,QAAQ,gCAAgC,MAAM,iCACjH,CACD;EAKD,MAAM,SAAS,QAAQ,IAAI,MAAM;EACjC,IAAI,QAAQ,OAAO,OAAO,KAAK,KAAK,IAAI,GAAG;EAC3C,IAAI,WAAWJ,oBAAAA,YACd,MAAM,IAAI,6BAA6B,KAAK,IAAI,MAAM;EAGvD,MAAM,IAAIK,eAAAA,wBAAwB,KAAK,IAAI,MAAM;CAClD;AACD"}
|
package/dist/encryption.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as Construct } from "./construct-interface-
|
|
1
|
+
import { n as Construct } from "./construct-interface-DhbaONW2.cjs";
|
|
2
2
|
import { a as CurrentKeyCannotRetire, c as Keyring, d as generateKeyring, f as keyringCipher, h as rotateKeyring, i as CiphertextNotAuthentic, l as UnknownEncryptionScheme, m as retireKey, n as CipherDriver, o as EncryptionKeyRetired, p as parseKeyring, r as CiphertextMalformed, s as EncryptionUrlInvalid, t as Cipher, u as formatKeyring } from "./cipher-DSDxPRIp.cjs";
|
|
3
3
|
import { Service } from "@geekmidas/services";
|
|
4
4
|
import { ConstructName, Declaration } from "@geekmidas/manifest";
|
package/dist/encryption.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as Construct } from "./construct-interface-
|
|
1
|
+
import { n as Construct } from "./construct-interface-DxfkFxkl.mjs";
|
|
2
2
|
import { a as CurrentKeyCannotRetire, c as Keyring, d as generateKeyring, f as keyringCipher, h as rotateKeyring, i as CiphertextNotAuthentic, l as UnknownEncryptionScheme, m as retireKey, n as CipherDriver, o as EncryptionKeyRetired, p as parseKeyring, r as CiphertextMalformed, s as EncryptionUrlInvalid, t as Cipher, u as formatKeyring } from "./cipher-DSDxPRIp.mjs";
|
|
3
3
|
import { ConstructName, Declaration } from "@geekmidas/manifest";
|
|
4
4
|
import { Service } from "@geekmidas/services";
|
package/dist/encryption.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { _ as rotateKeyring, a as EncryptionUrlInvalid, d as generateKeyring, f as keyringCipher, g as retireKey, h as parseKeyring, i as EncryptionKeyRetired, n as CiphertextNotAuthentic, r as CurrentKeyCannotRetire, s as UnknownEncryptionScheme, t as CiphertextMalformed, u as formatKeyring } from "./cipher-C1lEFX63.mjs";
|
|
2
|
-
import { KMS_SCHEME, canonicalId,
|
|
2
|
+
import { KMS_SCHEME, canonicalId, providedKeyFor, serviceKey } from "@geekmidas/manifest";
|
|
3
3
|
//#region src/encryption.ts
|
|
4
4
|
/**
|
|
5
5
|
* `Encryption` — a key that encrypts what the application stores.
|
|
@@ -68,7 +68,7 @@ var Encryption = class {
|
|
|
68
68
|
constructor(id) {
|
|
69
69
|
const canonical = canonicalId(id);
|
|
70
70
|
this.id = canonical;
|
|
71
|
-
this.key =
|
|
71
|
+
this.key = providedKeyFor(canonical, "encryption", "url");
|
|
72
72
|
this.service = {
|
|
73
73
|
serviceName: serviceKey(canonical),
|
|
74
74
|
register: (options) => this.connect(options)
|
package/dist/encryption.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"encryption.mjs","names":[],"sources":["../src/encryption.ts"],"sourcesContent":["/**\n * `Encryption` — a key that encrypts what the application stores.\n *\n * ```ts\n * export const pii = new Encryption('Pii');\n *\n * // an endpoint that `.dependsOn([pii])`\n * const email = await services.pii.encrypt(body.email);\n * const emailIndex = await services.pii.index(body.email);\n * await db.insertInto('users').values({ email, emailIndex }).execute();\n *\n * // and to find them again, without decrypting a column\n * db.selectFrom('users').where('emailIndex', '=', await services.pii.index(q));\n * ```\n *\n * The app names no cipher and holds no key. The construct provides one URL,\n * `<ID>_URL`, and its scheme picks the backend the way a queue's connection\n * string picks its broker:\n *\n * - **AWS** — `kms://`: envelope encryption under a KMS key that rotates\n * yearly, and a KMS HMAC key for the index. Only a function that depends on\n * the construct is granted either key.\n * - **Server, local, tests** — `aes256gcm://`: a keyring the process holds.\n * Derived locally, so `gkm dev` and `gkm test` need nothing set; generated\n * into a server stage's secrets on its first deploy, and rotated there with\n * `gkm encryption:rotate`.\n *\n * Every ciphertext names the key that wrote it, so a rotated key still opens\n * what it wrote. Retiring one is explicit — `reencrypt` the column, then\n * `gkm encryption:retire` — and a value still under an old key says so when it\n * is decrypted, once per key per process.\n */\n\nimport {\n\ttype ConstructName,\n\tcanonicalId,\n\ttype Declaration,\n\tKMS_SCHEME,\n\
|
|
1
|
+
{"version":3,"file":"encryption.mjs","names":[],"sources":["../src/encryption.ts"],"sourcesContent":["/**\n * `Encryption` — a key that encrypts what the application stores.\n *\n * ```ts\n * export const pii = new Encryption('Pii');\n *\n * // an endpoint that `.dependsOn([pii])`\n * const email = await services.pii.encrypt(body.email);\n * const emailIndex = await services.pii.index(body.email);\n * await db.insertInto('users').values({ email, emailIndex }).execute();\n *\n * // and to find them again, without decrypting a column\n * db.selectFrom('users').where('emailIndex', '=', await services.pii.index(q));\n * ```\n *\n * The app names no cipher and holds no key. The construct provides one URL,\n * `<ID>_URL`, and its scheme picks the backend the way a queue's connection\n * string picks its broker:\n *\n * - **AWS** — `kms://`: envelope encryption under a KMS key that rotates\n * yearly, and a KMS HMAC key for the index. Only a function that depends on\n * the construct is granted either key.\n * - **Server, local, tests** — `aes256gcm://`: a keyring the process holds.\n * Derived locally, so `gkm dev` and `gkm test` need nothing set; generated\n * into a server stage's secrets on its first deploy, and rotated there with\n * `gkm encryption:rotate`.\n *\n * Every ciphertext names the key that wrote it, so a rotated key still opens\n * what it wrote. Retiring one is explicit — `reencrypt` the column, then\n * `gkm encryption:retire` — and a value still under an old key says so when it\n * is decrypted, once per key per process.\n */\n\nimport {\n\ttype ConstructName,\n\tcanonicalId,\n\ttype Declaration,\n\tKMS_SCHEME,\n\tprovidedKeyFor,\n\tserviceKey,\n} from '@geekmidas/manifest';\nimport type { Service, ServiceRegisterOptions } from '@geekmidas/services';\nimport type { Construct } from './construct-interface';\nimport {\n\ttype Cipher,\n\ttype CipherDriver,\n\tkeyringCipher,\n\tLOCAL_SCHEME,\n\tUnknownEncryptionScheme,\n} from './encryption/cipher';\n\nexport type { Cipher, CipherDriver } from './encryption/cipher';\nexport {\n\tCiphertextMalformed,\n\tCiphertextNotAuthentic,\n\tCurrentKeyCannotRetire,\n\tEncryptionKeyRetired,\n\tEncryptionUrlInvalid,\n\tformatKeyring,\n\tgenerateKeyring,\n\ttype Keyring,\n\tkeyringCipher,\n\tparseKeyring,\n\tretireKey,\n\trotateKeyring,\n\tUnknownEncryptionScheme,\n} from './encryption/cipher';\n\nconst drivers = new Map<string, CipherDriver>();\n\n/** Make a cipher available for its scheme. Idempotent. */\nexport function registerCipherDriver(driver: CipherDriver): void {\n\tdrivers.set(driver.scheme, driver);\n}\n\n/**\n * A key whose URL names a cipher this process registered no driver for —\n * `kms:` in an entry built for a target whose keys are local.\n */\nexport class UnregisteredEncryptionScheme extends Error {\n\tconstructor(\n\t\treadonly construct: string,\n\t\treadonly scheme: string,\n\t) {\n\t\tsuper(\n\t\t\t`${construct}'s key is a '${scheme}' URL, and this build registered no cipher for it. ` +\n\t\t\t\t(scheme === KMS_SCHEME\n\t\t\t\t\t? \"A KMS key is an AWS target's: build for it (gkm build --provider aws), which registers the KMS cipher and needs @aws-sdk/client-kms installed.\"\n\t\t\t\t\t: 'Register its driver with registerCipherDriver before the first request.'),\n\t\t);\n\t\tthis.name = 'UnregisteredEncryptionScheme';\n\t}\n}\n\nexport class Encryption<TName extends string = string>\n\timplements Construct<TName, Cipher>\n{\n\treadonly id: TName;\n\treadonly service: Service<Uncapitalize<TName>, Cipher>;\n\n\t/**\n\t * Declared once and read by both `declare()` and `connect()`, so the key the\n\t * target publishes and the key the client reads cannot drift.\n\t */\n\tprivate readonly key: string;\n\n\t/**\n\t * One cipher per process, held as the promise: a keyring is parsed once and\n\t * a KMS client is built once, however many handlers register it at once.\n\t */\n\tprivate cipher?: Promise<Cipher>;\n\n\tconstructor(id: ConstructName<TName>) {\n\t\tconst canonical = canonicalId(id as string);\n\n\t\tthis.id = canonical as TName;\n\t\tthis.key = providedKeyFor(canonical, 'encryption', 'url');\n\n\t\t// A field, not a getter: consumers cache services by object identity.\n\t\tthis.service = {\n\t\t\tserviceName: serviceKey(canonical) as Uncapitalize<TName>,\n\t\t\tregister: (options) => this.connect(options),\n\t\t};\n\t}\n\n\tdeclare(): Declaration[] {\n\t\treturn [{ kind: 'encryption', id: this.id, provides: [this.key] }];\n\t}\n\n\tprivate connect(options: ServiceRegisterOptions): Promise<Cipher> {\n\t\tthis.cipher ??= this.open(options);\n\t\treturn this.cipher;\n\t}\n\n\tprivate async open(options: ServiceRegisterOptions): Promise<Cipher> {\n\t\tconst { url } = options.envParser\n\t\t\t.create((get) => ({ url: get(this.key).string() }))\n\t\t\t.parse();\n\t\tconst scheme = url.slice(0, url.indexOf(':') + 1);\n\n\t\tif (scheme === LOCAL_SCHEME) {\n\t\t\treturn keyringCipher(this.id, url, (stale, current) =>\n\t\t\t\tconsole.warn(\n\t\t\t\t\t`${this.id} decrypted a value still under '${stale}' (current: '${current}'). reencrypt it, and retire '${stale}' once nothing is left under it.`,\n\t\t\t\t),\n\t\t\t);\n\t\t}\n\n\t\t// Registered by the entry a build generates, only for a target whose\n\t\t// keys live there — so no other process imports that cipher's SDK.\n\t\tconst driver = drivers.get(scheme);\n\t\tif (driver) return driver.open(this.id, url);\n\t\tif (scheme === KMS_SCHEME) {\n\t\t\tthrow new UnregisteredEncryptionScheme(this.id, scheme);\n\t\t}\n\n\t\tthrow new UnknownEncryptionScheme(this.id, scheme);\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoEA,MAAM,0BAAU,IAAI,IAA0B;;AAG9C,SAAgB,qBAAqB,QAA4B;CAChE,QAAQ,IAAI,OAAO,QAAQ,MAAM;AAClC;;;;;AAMA,IAAa,+BAAb,cAAkD,MAAM;CAE7C;CACA;CAFV,YACC,WACA,QACC;EACD,MACC,GAAG,UAAU,eAAe,OAAO,wDACjC,WAAW,aACT,mJACA,0EACL;EARS,KAAA,YAAA;EACA,KAAA,SAAA;EAQT,KAAK,OAAO;CACb;AACD;AAEA,IAAa,aAAb,MAEA;CACC;CACA;;;;;CAMA;;;;;CAMA;CAEA,YAAY,IAA0B;EACrC,MAAM,YAAY,YAAY,EAAY;EAE1C,KAAK,KAAK;EACV,KAAK,MAAM,eAAe,WAAW,cAAc,KAAK;EAGxD,KAAK,UAAU;GACd,aAAa,WAAW,SAAS;GACjC,WAAW,YAAY,KAAK,QAAQ,OAAO;EAC5C;CACD;CAEA,UAAyB;EACxB,OAAO,CAAC;GAAE,MAAM;GAAc,IAAI,KAAK;GAAI,UAAU,CAAC,KAAK,GAAG;EAAE,CAAC;CAClE;CAEA,QAAgB,SAAkD;EACjE,KAAK,WAAW,KAAK,KAAK,OAAO;EACjC,OAAO,KAAK;CACb;CAEA,MAAc,KAAK,SAAkD;EACpE,MAAM,EAAE,QAAQ,QAAQ,UACtB,QAAQ,SAAS,EAAE,KAAK,IAAI,KAAK,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,CAClD,MAAM;EACR,MAAM,SAAS,IAAI,MAAM,GAAG,IAAI,QAAQ,GAAG,IAAI,CAAC;EAEhD,IAAI,WAAA,cACH,OAAO,cAAc,KAAK,IAAI,MAAM,OAAO,YAC1C,QAAQ,KACP,GAAG,KAAK,GAAG,kCAAkC,MAAM,eAAe,QAAQ,gCAAgC,MAAM,iCACjH,CACD;EAKD,MAAM,SAAS,QAAQ,IAAI,MAAM;EACjC,IAAI,QAAQ,OAAO,OAAO,KAAK,KAAK,IAAI,GAAG;EAC3C,IAAI,WAAW,YACd,MAAM,IAAI,6BAA6B,KAAK,IAAI,MAAM;EAGvD,MAAM,IAAI,wBAAwB,KAAK,IAAI,MAAM;CAClD;AACD"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { s as publishConstructEvents } from "../Construct-127M7yrl.cjs";
|
|
2
|
-
import { A as SecurityScheme, C as ActorExtractor, D as BuiltInSecuritySchemeId, E as BUILT_IN_SECURITY_SCHEMES, M as getSecurityScheme, N as isBuiltInSecurityScheme, O as OAuthFlow, S as RlsContextExtractor, T as Authorizer, _ as SessionAuth, a as EndpointContext, b as RlsConfig, c as EndpointSchemas, d as HeaderFn, f as RedirectStatus, g as NoAuthenticator, h as SuccessStatus, i as Endpoint, j as createAuthorizer, k as OAuthFlows, l as EndpointStatus, n as ConvertRouteParams, o as EndpointHandler, p as ResponseBuilder, r as CookieFn, s as EndpointOutput, u as EndpointSurface, v as RLS_BYPASS, w as MappedAudit, x as RlsContext, y as RlsBypass } from "../Endpoint-
|
|
3
|
-
import { a as UPLOAD_POST_SCHEMA, c as UploadContentTypeUnresolved, d as UploadOptions, f as UploadPost, i as UploadHandler, l as UploadExpiryInvalid, n as EndpointBuilder, o as UploadAcceptInvalid, r as UploadEndpointBuilder, s as UploadContentTypeRefused, t as EndpointFactory, u as UploadMaxSizeInvalid } from "../EndpointFactory-
|
|
2
|
+
import { A as SecurityScheme, C as ActorExtractor, D as BuiltInSecuritySchemeId, E as BUILT_IN_SECURITY_SCHEMES, M as getSecurityScheme, N as isBuiltInSecurityScheme, O as OAuthFlow, S as RlsContextExtractor, T as Authorizer, _ as SessionAuth, a as EndpointContext, b as RlsConfig, c as EndpointSchemas, d as HeaderFn, f as RedirectStatus, g as NoAuthenticator, h as SuccessStatus, i as Endpoint, j as createAuthorizer, k as OAuthFlows, l as EndpointStatus, n as ConvertRouteParams, o as EndpointHandler, p as ResponseBuilder, r as CookieFn, s as EndpointOutput, u as EndpointSurface, v as RLS_BYPASS, w as MappedAudit, x as RlsContext, y as RlsBypass } from "../Endpoint-BlIZLsBQ.cjs";
|
|
3
|
+
import { a as UPLOAD_POST_SCHEMA, c as UploadContentTypeUnresolved, d as UploadOptions, f as UploadPost, i as UploadHandler, l as UploadExpiryInvalid, n as EndpointBuilder, o as UploadAcceptInvalid, r as UploadEndpointBuilder, s as UploadContentTypeRefused, t as EndpointFactory, u as UploadMaxSizeInvalid } from "../EndpointFactory-cVTb8kCc.cjs";
|
|
4
4
|
import { EnvironmentParser } from "@geekmidas/envkit";
|
|
5
5
|
import { trustsOrigin } from "@geekmidas/manifest";
|
|
6
6
|
import { Context } from "hono";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { s as publishConstructEvents } from "../Construct-BMk_CRSD.mjs";
|
|
2
|
-
import { A as SecurityScheme, C as ActorExtractor, D as BuiltInSecuritySchemeId, E as BUILT_IN_SECURITY_SCHEMES, M as getSecurityScheme, N as isBuiltInSecurityScheme, O as OAuthFlow, S as RlsContextExtractor, T as Authorizer, _ as SessionAuth, a as EndpointContext, b as RlsConfig, c as EndpointSchemas, d as HeaderFn, f as RedirectStatus, g as NoAuthenticator, h as SuccessStatus, i as Endpoint, j as createAuthorizer, k as OAuthFlows, l as EndpointStatus, n as ConvertRouteParams, o as EndpointHandler, p as ResponseBuilder, r as CookieFn, s as EndpointOutput, u as EndpointSurface, v as RLS_BYPASS, w as MappedAudit, x as RlsContext, y as RlsBypass } from "../Endpoint-
|
|
3
|
-
import { a as UPLOAD_POST_SCHEMA, c as UploadContentTypeUnresolved, d as UploadOptions, f as UploadPost, i as UploadHandler, l as UploadExpiryInvalid, n as EndpointBuilder, o as UploadAcceptInvalid, r as UploadEndpointBuilder, s as UploadContentTypeRefused, t as EndpointFactory, u as UploadMaxSizeInvalid } from "../EndpointFactory-
|
|
2
|
+
import { A as SecurityScheme, C as ActorExtractor, D as BuiltInSecuritySchemeId, E as BUILT_IN_SECURITY_SCHEMES, M as getSecurityScheme, N as isBuiltInSecurityScheme, O as OAuthFlow, S as RlsContextExtractor, T as Authorizer, _ as SessionAuth, a as EndpointContext, b as RlsConfig, c as EndpointSchemas, d as HeaderFn, f as RedirectStatus, g as NoAuthenticator, h as SuccessStatus, i as Endpoint, j as createAuthorizer, k as OAuthFlows, l as EndpointStatus, n as ConvertRouteParams, o as EndpointHandler, p as ResponseBuilder, r as CookieFn, s as EndpointOutput, u as EndpointSurface, v as RLS_BYPASS, w as MappedAudit, x as RlsContext, y as RlsBypass } from "../Endpoint-DC7mreOr.mjs";
|
|
3
|
+
import { a as UPLOAD_POST_SCHEMA, c as UploadContentTypeUnresolved, d as UploadOptions, f as UploadPost, i as UploadHandler, l as UploadExpiryInvalid, n as EndpointBuilder, o as UploadAcceptInvalid, r as UploadEndpointBuilder, s as UploadContentTypeRefused, t as EndpointFactory, u as UploadMaxSizeInvalid } from "../EndpointFactory-DCmnCmkX.mjs";
|
|
4
4
|
import { trustsOrigin } from "@geekmidas/manifest";
|
|
5
5
|
import { HttpError } from "@geekmidas/errors";
|
|
6
6
|
import { EnvironmentParser } from "@geekmidas/envkit";
|
package/dist/external-api.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_credential = require("./credential-
|
|
2
|
+
const require_credential = require("./credential-RlgbzZAc.cjs");
|
|
3
3
|
const require_tracing = require("./tracing-C0ooU0V2.cjs");
|
|
4
4
|
let _geekmidas_manifest = require("@geekmidas/manifest");
|
|
5
5
|
//#region src/external-api.ts
|
|
@@ -53,8 +53,8 @@ var ExternalApi = class {
|
|
|
53
53
|
const canonical = (0, _geekmidas_manifest.canonicalId)(id);
|
|
54
54
|
this.id = canonical;
|
|
55
55
|
this.keys = {
|
|
56
|
-
url: (0, _geekmidas_manifest.
|
|
57
|
-
credentials: (0, _geekmidas_manifest.
|
|
56
|
+
url: (0, _geekmidas_manifest.providedKeyFor)(canonical, "external-api", "url"),
|
|
57
|
+
credentials: (0, _geekmidas_manifest.providedKeyFor)(canonical, "external-api", "credentials")
|
|
58
58
|
};
|
|
59
59
|
this.service = {
|
|
60
60
|
serviceName: (0, _geekmidas_manifest.serviceKey)(canonical),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"external-api.cjs","names":["canonicalId","
|
|
1
|
+
{"version":3,"file":"external-api.cjs","names":["canonicalId","providedKeyFor","serviceKey","readCredentials","traceClient"],"sources":["../src/external-api.ts"],"sourcesContent":["/**\n * `ExternalApi` — an HTTP API somebody else runs.\n *\n * Polar, Stripe, a payment gateway: nothing to provision, but an address that\n * changes by stage and credentials the provider issued for each one. Without a\n * construct every integration writes that switching by hand — an optional\n * `POLAR_URL`, a fake started somewhere, a client built in a service — and the\n * target cannot see any of it.\n *\n * ```ts\n * // constructs/polar.ts\n * export const polar = new ExternalApi('Polar', {\n * url: 'https://www.polaraccesslink.com',\n * credentials: z.object({ clientId: z.string(), clientSecret: z.string() }),\n * client: ({ url, credentials }) => new PolarClient(url, credentials),\n * });\n *\n * // test/fakes/polar.ts\n * export default fake.app(new Hono().post('/v3/oauth2/token', …), {\n * credentials: { clientId: 'fake', clientSecret: 'fake' },\n * });\n *\n * // in a handler — the real API deployed, the fake locally and in tests\n * .dependsOn([polar])\n * .handle(({ services }) => services.polar.exchangeCode(code))\n * ```\n *\n * Deployed, the URL is `url` — one for every stage, or one per stage name with\n * a `default` — and the credentials are the stage's `<ID>_CREDENTIALS`, one\n * JSON value read the way a `Credential`'s is. Locally and in tests both come\n * from the fake.\n *\n * **The construct never names its fake.** It is found by convention, at\n * `test/fakes/<id>.ts`, and read only by gkm and the generated test harness —\n * so a fake, and the recorded responses it answers from, cannot end up in a\n * deployed bundle however the bundler follows imports.\n */\n\nimport {\n\ttype ConstructName,\n\tcanonicalId,\n\ttype Declaration,\n\tprovidedKeyFor,\n\tserviceKey,\n} from '@geekmidas/manifest';\nimport type { Service, ServiceRegisterOptions } from '@geekmidas/services';\nimport type { StandardSchemaV1 } from '@standard-schema/spec';\nimport type { Consumable } from './construct-interface';\nimport { readCredentials } from './credential';\nimport type { DeployedStage, LocalStage } from './stages';\nimport { traceClient } from './tracing';\n\n/** What a credentials schema yields. */\ntype Value<TSchema extends StandardSchemaV1> =\n\tStandardSchemaV1.InferOutput<TSchema>;\n\n/**\n * Where an external API answers: one URL for every stage, or one per stage\n * name with `default` for any stage not listed.\n *\n * Keyed by the stages `gkm.config.ts` declares once `.gkm/stages.d.ts` exists,\n * so a key that names no stage — `prodution` — is a type error rather than a\n * URL nothing reads. Without the file any key goes, as before.\n */\nexport type ExternalApiUrl =\n\t| string\n\t| (string extends LocalStage | DeployedStage\n\t\t\t? Readonly<Record<string, string>>\n\t\t\t: { readonly [S in LocalStage | DeployedStage]?: string } & {\n\t\t\t\t\treadonly default?: string;\n\t\t\t\t});\n\nexport interface ExternalApiOptions<TSchema extends StandardSchemaV1, TClient> {\n\t/**\n\t * Where it answers deployed: one URL for every stage, or one per stage\n\t * name, with `default` for any stage not listed.\n\t */\n\turl: ExternalApiUrl;\n\t/** What the stage's `<ID>_CREDENTIALS` must look like. */\n\tcredentials: TSchema;\n\t/** What a handler is handed, built from where it answers and the credentials. */\n\tclient: (connection: {\n\t\turl: string;\n\t\tcredentials: Value<TSchema>;\n\t}) => TClient | Promise<TClient>;\n}\n\nexport class ExternalApi<\n\tTName extends string = string,\n\tTSchema extends StandardSchemaV1 = StandardSchemaV1,\n\tTClient = unknown,\n> implements Consumable<TName, TClient>\n{\n\t// `Consumable` for the reason `Credential` gives: a client generic in\n\t// `TClient` cannot satisfy `Construct`'s conditional service type.\n\treadonly id: TName;\n\treadonly service: Service<Uncapitalize<TName>, TClient>;\n\n\t/** Read by both `declare()` and `connect()`, so the two cannot drift. */\n\tprivate readonly keys: { url: string; credentials: string };\n\n\t/** The promise, so concurrent registrations share one client. */\n\tprivate connected?: Promise<TClient>;\n\n\tconstructor(\n\t\tid: ConstructName<TName>,\n\t\tprivate readonly options: ExternalApiOptions<TSchema, TClient>,\n\t) {\n\t\tconst canonical = canonicalId(id as string);\n\n\t\tthis.id = canonical as TName;\n\t\tthis.keys = {\n\t\t\turl: providedKeyFor(canonical, 'external-api', 'url'),\n\t\t\tcredentials: providedKeyFor(canonical, 'external-api', 'credentials'),\n\t\t};\n\n\t\t// A field, not a getter: consumers cache services by object identity.\n\t\tthis.service = {\n\t\t\tserviceName: serviceKey(canonical) as Uncapitalize<TName>,\n\t\t\tregister: (registerOptions) => {\n\t\t\t\tthis.connected ??= this.connect(registerOptions);\n\t\t\t\treturn this.connected;\n\t\t\t},\n\t\t};\n\t}\n\n\t/**\n\t * What the stage's `<ID>_CREDENTIALS` must look like — the schema the value\n\t * is validated against where it is read. Public so a tool setting the value\n\t * (`gkm secrets:add`) can check it, and describe its fields, before it is\n\t * stored rather than at the first request.\n\t */\n\tget credentialsSchema(): TSchema {\n\t\treturn this.options.credentials;\n\t}\n\n\tdeclare(): Declaration[] {\n\t\treturn [\n\t\t\t{\n\t\t\t\tkind: 'external-api',\n\t\t\t\tid: this.id,\n\t\t\t\t// The stage-keyed map is a record of URLs to the manifest, which\n\t\t\t\t// reads it by whatever stage it is resolving.\n\t\t\t\turl: this.options.url as Readonly<Record<string, string>> | string,\n\t\t\t\tprovides: [this.keys.url, this.keys.credentials],\n\t\t\t},\n\t\t];\n\t}\n\n\tprivate async connect(options: ServiceRegisterOptions): Promise<TClient> {\n\t\tconst { url } = options.envParser\n\t\t\t.create((get) => ({ url: get(this.keys.url).string() }))\n\t\t\t.parse();\n\t\tconst credentials = await readCredentials(\n\t\t\tthis.id,\n\t\t\tthis.keys.credentials,\n\t\t\tthis.options.credentials,\n\t\t\toptions.envParser,\n\t\t);\n\n\t\tconst client = await this.options.client({ url, credentials });\n\t\t// Each call a span carrying this API's name — the parent of the fetch\n\t\t// it makes, which is traced already.\n\t\treturn traceClient(this.id, client, {\n\t\t\t'server.address': hostOf(url),\n\t\t});\n\t}\n}\n\nfunction hostOf(url: string): string {\n\ttry {\n\t\treturn new URL(url).host;\n\t} catch {\n\t\treturn url;\n\t}\n}\n\nexport {\n\ttype Fake,\n\ttype FetchHandler,\n\tfake,\n\tisFake,\n} from './fake';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuFA,IAAa,cAAb,MAKA;CAcmB;CAXlB;CACA;;CAGA;;CAGA;CAEA,YACC,IACA,SACC;EADgB,KAAA,UAAA;EAEjB,MAAM,aAAA,GAAYA,oBAAAA,YAAAA,CAAY,EAAY;EAE1C,KAAK,KAAK;EACV,KAAK,OAAO;GACX,MAAA,GAAKC,oBAAAA,eAAAA,CAAe,WAAW,gBAAgB,KAAK;GACpD,cAAA,GAAaA,oBAAAA,eAAAA,CAAe,WAAW,gBAAgB,aAAa;EACrE;EAGA,KAAK,UAAU;GACd,cAAA,GAAaC,oBAAAA,WAAAA,CAAW,SAAS;GACjC,WAAW,oBAAoB;IAC9B,KAAK,cAAc,KAAK,QAAQ,eAAe;IAC/C,OAAO,KAAK;GACb;EACD;CACD;;;;;;;CAQA,IAAI,oBAA6B;EAChC,OAAO,KAAK,QAAQ;CACrB;CAEA,UAAyB;EACxB,OAAO,CACN;GACC,MAAM;GACN,IAAI,KAAK;GAGT,KAAK,KAAK,QAAQ;GAClB,UAAU,CAAC,KAAK,KAAK,KAAK,KAAK,KAAK,WAAW;EAChD,CACD;CACD;CAEA,MAAc,QAAQ,SAAmD;EACxE,MAAM,EAAE,QAAQ,QAAQ,UACtB,QAAQ,SAAS,EAAE,KAAK,IAAI,KAAK,KAAK,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,CACvD,MAAM;EACR,MAAM,cAAc,MAAMC,mBAAAA,gBACzB,KAAK,IACL,KAAK,KAAK,aACV,KAAK,QAAQ,aACb,QAAQ,SACT;EAEA,MAAM,SAAS,MAAM,KAAK,QAAQ,OAAO;GAAE;GAAK;EAAY,CAAC;EAG7D,OAAOC,gBAAAA,YAAY,KAAK,IAAI,QAAQ,EACnC,kBAAkB,OAAO,GAAG,EAC7B,CAAC;CACF;AACD;AAEA,SAAS,OAAO,KAAqB;CACpC,IAAI;EACH,OAAO,IAAI,IAAI,GAAG,CAAC,CAAC;CACrB,QAAQ;EACP,OAAO;CACR;AACD"}
|
package/dist/external-api.d.cts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as ExternalApi, i as isFake, n as FetchHandler, o as ExternalApiOptions, r as fake, s as ExternalApiUrl, t as Fake } from "./fake-
|
|
1
|
+
import { a as ExternalApi, i as isFake, n as FetchHandler, o as ExternalApiOptions, r as fake, s as ExternalApiUrl, t as Fake } from "./fake-Djx8E0o1.cjs";
|
|
2
2
|
export { ExternalApi, ExternalApiOptions, ExternalApiUrl, type Fake, type FetchHandler, fake, isFake };
|
package/dist/external-api.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as ExternalApi, i as isFake, n as FetchHandler, o as ExternalApiOptions, r as fake, s as ExternalApiUrl, t as Fake } from "./fake-
|
|
1
|
+
import { a as ExternalApi, i as isFake, n as FetchHandler, o as ExternalApiOptions, r as fake, s as ExternalApiUrl, t as Fake } from "./fake-BvOXkZmj.mjs";
|
|
2
2
|
export { ExternalApi, ExternalApiOptions, ExternalApiUrl, type Fake, type FetchHandler, fake, isFake };
|
package/dist/external-api.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { a as fake, i as readCredentials, o as isFake } from "./credential-
|
|
1
|
+
import { a as fake, i as readCredentials, o as isFake } from "./credential-B80mOxwT.mjs";
|
|
2
2
|
import { i as traceClient } from "./tracing-Bbj1uoFJ.mjs";
|
|
3
|
-
import { canonicalId,
|
|
3
|
+
import { canonicalId, providedKeyFor, serviceKey } from "@geekmidas/manifest";
|
|
4
4
|
//#region src/external-api.ts
|
|
5
5
|
/**
|
|
6
6
|
* `ExternalApi` — an HTTP API somebody else runs.
|
|
@@ -52,8 +52,8 @@ var ExternalApi = class {
|
|
|
52
52
|
const canonical = canonicalId(id);
|
|
53
53
|
this.id = canonical;
|
|
54
54
|
this.keys = {
|
|
55
|
-
url:
|
|
56
|
-
credentials:
|
|
55
|
+
url: providedKeyFor(canonical, "external-api", "url"),
|
|
56
|
+
credentials: providedKeyFor(canonical, "external-api", "credentials")
|
|
57
57
|
};
|
|
58
58
|
this.service = {
|
|
59
59
|
serviceName: serviceKey(canonical),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"external-api.mjs","names":[],"sources":["../src/external-api.ts"],"sourcesContent":["/**\n * `ExternalApi` — an HTTP API somebody else runs.\n *\n * Polar, Stripe, a payment gateway: nothing to provision, but an address that\n * changes by stage and credentials the provider issued for each one. Without a\n * construct every integration writes that switching by hand — an optional\n * `POLAR_URL`, a fake started somewhere, a client built in a service — and the\n * target cannot see any of it.\n *\n * ```ts\n * // constructs/polar.ts\n * export const polar = new ExternalApi('Polar', {\n * url: 'https://www.polaraccesslink.com',\n * credentials: z.object({ clientId: z.string(), clientSecret: z.string() }),\n * client: ({ url, credentials }) => new PolarClient(url, credentials),\n * });\n *\n * // test/fakes/polar.ts\n * export default fake.app(new Hono().post('/v3/oauth2/token', …), {\n * credentials: { clientId: 'fake', clientSecret: 'fake' },\n * });\n *\n * // in a handler — the real API deployed, the fake locally and in tests\n * .dependsOn([polar])\n * .handle(({ services }) => services.polar.exchangeCode(code))\n * ```\n *\n * Deployed, the URL is `url` — one for every stage, or one per stage name with\n * a `default` — and the credentials are the stage's `<ID>_CREDENTIALS`, one\n * JSON value read the way a `Credential`'s is. Locally and in tests both come\n * from the fake.\n *\n * **The construct never names its fake.** It is found by convention, at\n * `test/fakes/<id>.ts`, and read only by gkm and the generated test harness —\n * so a fake, and the recorded responses it answers from, cannot end up in a\n * deployed bundle however the bundler follows imports.\n */\n\nimport {\n\ttype ConstructName,\n\tcanonicalId,\n\ttype Declaration,\n\
|
|
1
|
+
{"version":3,"file":"external-api.mjs","names":[],"sources":["../src/external-api.ts"],"sourcesContent":["/**\n * `ExternalApi` — an HTTP API somebody else runs.\n *\n * Polar, Stripe, a payment gateway: nothing to provision, but an address that\n * changes by stage and credentials the provider issued for each one. Without a\n * construct every integration writes that switching by hand — an optional\n * `POLAR_URL`, a fake started somewhere, a client built in a service — and the\n * target cannot see any of it.\n *\n * ```ts\n * // constructs/polar.ts\n * export const polar = new ExternalApi('Polar', {\n * url: 'https://www.polaraccesslink.com',\n * credentials: z.object({ clientId: z.string(), clientSecret: z.string() }),\n * client: ({ url, credentials }) => new PolarClient(url, credentials),\n * });\n *\n * // test/fakes/polar.ts\n * export default fake.app(new Hono().post('/v3/oauth2/token', …), {\n * credentials: { clientId: 'fake', clientSecret: 'fake' },\n * });\n *\n * // in a handler — the real API deployed, the fake locally and in tests\n * .dependsOn([polar])\n * .handle(({ services }) => services.polar.exchangeCode(code))\n * ```\n *\n * Deployed, the URL is `url` — one for every stage, or one per stage name with\n * a `default` — and the credentials are the stage's `<ID>_CREDENTIALS`, one\n * JSON value read the way a `Credential`'s is. Locally and in tests both come\n * from the fake.\n *\n * **The construct never names its fake.** It is found by convention, at\n * `test/fakes/<id>.ts`, and read only by gkm and the generated test harness —\n * so a fake, and the recorded responses it answers from, cannot end up in a\n * deployed bundle however the bundler follows imports.\n */\n\nimport {\n\ttype ConstructName,\n\tcanonicalId,\n\ttype Declaration,\n\tprovidedKeyFor,\n\tserviceKey,\n} from '@geekmidas/manifest';\nimport type { Service, ServiceRegisterOptions } from '@geekmidas/services';\nimport type { StandardSchemaV1 } from '@standard-schema/spec';\nimport type { Consumable } from './construct-interface';\nimport { readCredentials } from './credential';\nimport type { DeployedStage, LocalStage } from './stages';\nimport { traceClient } from './tracing';\n\n/** What a credentials schema yields. */\ntype Value<TSchema extends StandardSchemaV1> =\n\tStandardSchemaV1.InferOutput<TSchema>;\n\n/**\n * Where an external API answers: one URL for every stage, or one per stage\n * name with `default` for any stage not listed.\n *\n * Keyed by the stages `gkm.config.ts` declares once `.gkm/stages.d.ts` exists,\n * so a key that names no stage — `prodution` — is a type error rather than a\n * URL nothing reads. Without the file any key goes, as before.\n */\nexport type ExternalApiUrl =\n\t| string\n\t| (string extends LocalStage | DeployedStage\n\t\t\t? Readonly<Record<string, string>>\n\t\t\t: { readonly [S in LocalStage | DeployedStage]?: string } & {\n\t\t\t\t\treadonly default?: string;\n\t\t\t\t});\n\nexport interface ExternalApiOptions<TSchema extends StandardSchemaV1, TClient> {\n\t/**\n\t * Where it answers deployed: one URL for every stage, or one per stage\n\t * name, with `default` for any stage not listed.\n\t */\n\turl: ExternalApiUrl;\n\t/** What the stage's `<ID>_CREDENTIALS` must look like. */\n\tcredentials: TSchema;\n\t/** What a handler is handed, built from where it answers and the credentials. */\n\tclient: (connection: {\n\t\turl: string;\n\t\tcredentials: Value<TSchema>;\n\t}) => TClient | Promise<TClient>;\n}\n\nexport class ExternalApi<\n\tTName extends string = string,\n\tTSchema extends StandardSchemaV1 = StandardSchemaV1,\n\tTClient = unknown,\n> implements Consumable<TName, TClient>\n{\n\t// `Consumable` for the reason `Credential` gives: a client generic in\n\t// `TClient` cannot satisfy `Construct`'s conditional service type.\n\treadonly id: TName;\n\treadonly service: Service<Uncapitalize<TName>, TClient>;\n\n\t/** Read by both `declare()` and `connect()`, so the two cannot drift. */\n\tprivate readonly keys: { url: string; credentials: string };\n\n\t/** The promise, so concurrent registrations share one client. */\n\tprivate connected?: Promise<TClient>;\n\n\tconstructor(\n\t\tid: ConstructName<TName>,\n\t\tprivate readonly options: ExternalApiOptions<TSchema, TClient>,\n\t) {\n\t\tconst canonical = canonicalId(id as string);\n\n\t\tthis.id = canonical as TName;\n\t\tthis.keys = {\n\t\t\turl: providedKeyFor(canonical, 'external-api', 'url'),\n\t\t\tcredentials: providedKeyFor(canonical, 'external-api', 'credentials'),\n\t\t};\n\n\t\t// A field, not a getter: consumers cache services by object identity.\n\t\tthis.service = {\n\t\t\tserviceName: serviceKey(canonical) as Uncapitalize<TName>,\n\t\t\tregister: (registerOptions) => {\n\t\t\t\tthis.connected ??= this.connect(registerOptions);\n\t\t\t\treturn this.connected;\n\t\t\t},\n\t\t};\n\t}\n\n\t/**\n\t * What the stage's `<ID>_CREDENTIALS` must look like — the schema the value\n\t * is validated against where it is read. Public so a tool setting the value\n\t * (`gkm secrets:add`) can check it, and describe its fields, before it is\n\t * stored rather than at the first request.\n\t */\n\tget credentialsSchema(): TSchema {\n\t\treturn this.options.credentials;\n\t}\n\n\tdeclare(): Declaration[] {\n\t\treturn [\n\t\t\t{\n\t\t\t\tkind: 'external-api',\n\t\t\t\tid: this.id,\n\t\t\t\t// The stage-keyed map is a record of URLs to the manifest, which\n\t\t\t\t// reads it by whatever stage it is resolving.\n\t\t\t\turl: this.options.url as Readonly<Record<string, string>> | string,\n\t\t\t\tprovides: [this.keys.url, this.keys.credentials],\n\t\t\t},\n\t\t];\n\t}\n\n\tprivate async connect(options: ServiceRegisterOptions): Promise<TClient> {\n\t\tconst { url } = options.envParser\n\t\t\t.create((get) => ({ url: get(this.keys.url).string() }))\n\t\t\t.parse();\n\t\tconst credentials = await readCredentials(\n\t\t\tthis.id,\n\t\t\tthis.keys.credentials,\n\t\t\tthis.options.credentials,\n\t\t\toptions.envParser,\n\t\t);\n\n\t\tconst client = await this.options.client({ url, credentials });\n\t\t// Each call a span carrying this API's name — the parent of the fetch\n\t\t// it makes, which is traced already.\n\t\treturn traceClient(this.id, client, {\n\t\t\t'server.address': hostOf(url),\n\t\t});\n\t}\n}\n\nfunction hostOf(url: string): string {\n\ttry {\n\t\treturn new URL(url).host;\n\t} catch {\n\t\treturn url;\n\t}\n}\n\nexport {\n\ttype Fake,\n\ttype FetchHandler,\n\tfake,\n\tisFake,\n} from './fake';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuFA,IAAa,cAAb,MAKA;CAcmB;CAXlB;CACA;;CAGA;;CAGA;CAEA,YACC,IACA,SACC;EADgB,KAAA,UAAA;EAEjB,MAAM,YAAY,YAAY,EAAY;EAE1C,KAAK,KAAK;EACV,KAAK,OAAO;GACX,KAAK,eAAe,WAAW,gBAAgB,KAAK;GACpD,aAAa,eAAe,WAAW,gBAAgB,aAAa;EACrE;EAGA,KAAK,UAAU;GACd,aAAa,WAAW,SAAS;GACjC,WAAW,oBAAoB;IAC9B,KAAK,cAAc,KAAK,QAAQ,eAAe;IAC/C,OAAO,KAAK;GACb;EACD;CACD;;;;;;;CAQA,IAAI,oBAA6B;EAChC,OAAO,KAAK,QAAQ;CACrB;CAEA,UAAyB;EACxB,OAAO,CACN;GACC,MAAM;GACN,IAAI,KAAK;GAGT,KAAK,KAAK,QAAQ;GAClB,UAAU,CAAC,KAAK,KAAK,KAAK,KAAK,KAAK,WAAW;EAChD,CACD;CACD;CAEA,MAAc,QAAQ,SAAmD;EACxE,MAAM,EAAE,QAAQ,QAAQ,UACtB,QAAQ,SAAS,EAAE,KAAK,IAAI,KAAK,KAAK,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,CACvD,MAAM;EACR,MAAM,cAAc,MAAM,gBACzB,KAAK,IACL,KAAK,KAAK,aACV,KAAK,QAAQ,aACb,QAAQ,SACT;EAEA,MAAM,SAAS,MAAM,KAAK,QAAQ,OAAO;GAAE;GAAK;EAAY,CAAC;EAG7D,OAAO,YAAY,KAAK,IAAI,QAAQ,EACnC,kBAAkB,OAAO,GAAG,EAC7B,CAAC;CACF;AACD;AAEA,SAAS,OAAO,KAAqB;CACpC,IAAI;EACH,OAAO,IAAI,IAAI,GAAG,CAAC,CAAC;CACrB,QAAQ;EACP,OAAO;CACR;AACD"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { n as StandardSchemaV1 } from "./index-DdRjYhiJ.mjs";
|
|
2
|
-
import { r as Consumable } from "./construct-interface-
|
|
2
|
+
import { r as Consumable } from "./construct-interface-DxfkFxkl.mjs";
|
|
3
3
|
import { n as DeployedStage, r as LocalStage } from "./stages-DaTaoQei.mjs";
|
|
4
4
|
import { ConstructName, Declaration } from "@geekmidas/manifest";
|
|
5
5
|
import { Service, ServiceRegisterOptions } from "@geekmidas/services";
|
|
@@ -198,4 +198,4 @@ declare const fake: {
|
|
|
198
198
|
declare function isFake(value: unknown): value is Fake;
|
|
199
199
|
//#endregion
|
|
200
200
|
export { ExternalApi as a, Credential as c, decodeCredentials as d, readCredentials as f, isFake as i, CredentialOptions as l, FetchHandler as n, ExternalApiOptions as o, fake as r, ExternalApiUrl as s, Fake as t, MalformedCredential as u };
|
|
201
|
-
//# sourceMappingURL=fake-
|
|
201
|
+
//# sourceMappingURL=fake-BvOXkZmj.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fake-
|
|
1
|
+
{"version":3,"file":"fake-BvOXkZmj.d.mts","names":["Value"],"sources":["../src/credential.ts","../src/external-api.ts","../src/fake.ts"],"mappings":";;;;;;;KAiEKA,QAAM,gBAAgB,oBAC1B,iBAAiB,YAAY;UAEb,kBAAkB,gBAAgB;;;;;;;;EAQlD,QAAQ;;;;;;;;;;EAUR;;cAGY,WACZ,+BACA,gBAAgB,mBAAmB,6BACvB,WAAW,OAAOA,QAAM;mBA6BlB;WApBT,IAAI;WACJ,SAAS,QAAQ,aAAa,QAAQA,QAAM;;;;;mBAMpC;;;;;;;;UAST;EAER,YACC,IAAI,cAAc,QACD,SAAS,kBAAkB;;;;;;;MAsBzC,qBAAqB;EAIzB,WAAW;UAUH;UAQA;;;;;;;;;;;iBAmBa,gBAAgB,gBAAgB,kBACrD,YACA,aACA,QAAQ,SACR,WAAW,sCACT,QAAQA,QAAM;;;;;;;;;;;iBAsBD,kBAAkB;;cAoBrB,4BAA4B;WAE9B;WACA;WACA;EAHV,YACU,YACA,aACA;;;;;KCtLN,MAAM,gBAAgB,oBAC1B,iBAAiB,YAAY;;;;;;;;;KAUlB,0CAEO,aAAa,gBAC3B,SAAS,sCACG,KAAK,aAAa;WACrB;;UAGG,mBAAmB,gBAAgB,kBAAkB;;;;;EAKrE,KAAK;;EAEL,aAAa;;EAEb,SAAS;IACR;IACA,aAAa,MAAM;QACd,UAAU,QAAQ;;cAGZ,YACZ,+BACA,gBAAgB,mBAAmB,kBACnC,8BACY,WAAW,OAAO;mBAeZ;WAXT,IAAI;WACJ,SAAS,QAAQ,aAAa,QAAQ;;mBAG9B;;UAGT;EAER,YACC,IAAI,cAAc,QACD,SAAS,mBAAmB,SAAS;;;;;;;MA0BnD,qBAAqB;EAIzB,WAAW;UAaG;;;;;;;;cCjHT;;UAGW;EAChB,MAAM,SAAS,UAAU,WAAW,QAAQ;;;;;;KAOxC,cAAc,cAClB,mBAAmB,0BAA0B,oBAC1C,iBAAiB,WAAW,WAC5B,mBAAmB,yBAAyB,WAC3C,iBAAiB,WAAW;;;;;;;;KAUrB;YACD;WACD;;WAGE;;WAEA,SAAS;;WAGT;;WAEA;;WAEA;;;WAIA;;;;;;;;cAUC;;EAEZ,IAAI,gBAAc,SACR,cAAY;IACV,aAAa,cAAc;MACpC;;EAUH,MAAM,gBAAc,eACN;IACF;IAAc,aAAa,cAAc;MAClD;;;;;;EAeH,WAAW,uBAAqB,aAClB,cAAc,eACzB;;;iBAMY,OAAO,iBAAiB,SAAS"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { n as StandardSchemaV1 } from "./index-DdRjYhiJ.cjs";
|
|
2
|
-
import { r as Consumable } from "./construct-interface-
|
|
2
|
+
import { r as Consumable } from "./construct-interface-DhbaONW2.cjs";
|
|
3
3
|
import { n as DeployedStage, r as LocalStage } from "./stages-DaTaoQei.cjs";
|
|
4
4
|
import { Service, ServiceRegisterOptions } from "@geekmidas/services";
|
|
5
5
|
import { ConstructName, Declaration } from "@geekmidas/manifest";
|
|
@@ -198,4 +198,4 @@ declare const fake: {
|
|
|
198
198
|
declare function isFake(value: unknown): value is Fake;
|
|
199
199
|
//#endregion
|
|
200
200
|
export { ExternalApi as a, Credential as c, decodeCredentials as d, readCredentials as f, isFake as i, CredentialOptions as l, FetchHandler as n, ExternalApiOptions as o, fake as r, ExternalApiUrl as s, Fake as t, MalformedCredential as u };
|
|
201
|
-
//# sourceMappingURL=fake-
|
|
201
|
+
//# sourceMappingURL=fake-Djx8E0o1.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fake-
|
|
1
|
+
{"version":3,"file":"fake-Djx8E0o1.d.cts","names":["Value"],"sources":["../src/credential.ts","../src/external-api.ts","../src/fake.ts"],"mappings":";;;;;;;KAiEKA,QAAM,gBAAgB,oBAC1B,iBAAiB,YAAY;UAEb,kBAAkB,gBAAgB;;;;;;;;EAQlD,QAAQ;;;;;;;;;;EAUR;;cAGY,WACZ,+BACA,gBAAgB,mBAAmB,6BACvB,WAAW,OAAOA,QAAM;mBA6BlB;WApBT,IAAI;WACJ,SAAS,QAAQ,aAAa,QAAQA,QAAM;;;;;mBAMpC;;;;;;;;UAST;EAER,YACC,IAAI,cAAc,QACD,SAAS,kBAAkB;;;;;;;MAsBzC,qBAAqB;EAIzB,WAAW;UAUH;UAQA;;;;;;;;;;;iBAmBa,gBAAgB,gBAAgB,kBACrD,YACA,aACA,QAAQ,SACR,WAAW,sCACT,QAAQA,QAAM;;;;;;;;;;;iBAsBD,kBAAkB;;cAoBrB,4BAA4B;WAE9B;WACA;WACA;EAHV,YACU,YACA,aACA;;;;;KCtLN,MAAM,gBAAgB,oBAC1B,iBAAiB,YAAY;;;;;;;;;KAUlB,0CAEO,aAAa,gBAC3B,SAAS,sCACG,KAAK,aAAa;WACrB;;UAGG,mBAAmB,gBAAgB,kBAAkB;;;;;EAKrE,KAAK;;EAEL,aAAa;;EAEb,SAAS;IACR;IACA,aAAa,MAAM;QACd,UAAU,QAAQ;;cAGZ,YACZ,+BACA,gBAAgB,mBAAmB,kBACnC,8BACY,WAAW,OAAO;mBAeZ;WAXT,IAAI;WACJ,SAAS,QAAQ,aAAa,QAAQ;;mBAG9B;;UAGT;EAER,YACC,IAAI,cAAc,QACD,SAAS,mBAAmB,SAAS;;;;;;;MA0BnD,qBAAqB;EAIzB,WAAW;UAaG;;;;;;;;cCjHT;;UAGW;EAChB,MAAM,SAAS,UAAU,WAAW,QAAQ;;;;;;KAOxC,cAAc,cAClB,mBAAmB,0BAA0B,oBAC1C,iBAAiB,WAAW,WAC5B,mBAAmB,yBAAyB,WAC3C,iBAAiB,WAAW;;;;;;;;KAUrB;YACD;WACD;;WAGE;;WAEA,SAAS;;WAGT;;WAEA;;WAEA;;;WAIA;;;;;;;;cAUC;;EAEZ,IAAI,gBAAc,SACR,cAAY;IACV,aAAa,cAAc;MACpC;;EAUH,MAAM,gBAAc,eACN;IACF;IAAc,aAAa,cAAc;MAClD;;;;;;EAeH,WAAW,uBAAqB,aAClB,cAAc,eACzB;;;iBAMY,OAAO,iBAAiB,SAAS"}
|
package/dist/file-server.cjs
CHANGED
|
@@ -47,6 +47,49 @@ var BucketOptionOnOrigin = class extends Error {
|
|
|
47
47
|
this.name = "BucketOptionOnOrigin";
|
|
48
48
|
}
|
|
49
49
|
};
|
|
50
|
+
/**
|
|
51
|
+
* A bucket method called on a file server's client that was handed only its
|
|
52
|
+
* public address — a frontend's plain edge.
|
|
53
|
+
*/
|
|
54
|
+
var FileServerReadOnly = class extends Error {
|
|
55
|
+
id;
|
|
56
|
+
method;
|
|
57
|
+
key;
|
|
58
|
+
constructor(id, method, key) {
|
|
59
|
+
super(`'${id}' was reached through its public address only, so it serves and cannot ${method}(): ${key} is not in this process's environment. A site or app whose server half writes or presigns depends on '${id}'.server instead — .dependsOn([${id.charAt(0).toLowerCase()}${id.slice(1)}.server]).`);
|
|
60
|
+
this.id = id;
|
|
61
|
+
this.method = method;
|
|
62
|
+
this.key = key;
|
|
63
|
+
this.name = "FileServerReadOnly";
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
/** Names asked of any object, which a read-only client must not answer. */
|
|
67
|
+
const INTROSPECTED = /* @__PURE__ */ new Set([
|
|
68
|
+
"then",
|
|
69
|
+
"toJSON",
|
|
70
|
+
"constructor",
|
|
71
|
+
"asymmetricMatch",
|
|
72
|
+
"$$typeof",
|
|
73
|
+
"nodeType",
|
|
74
|
+
"inspect"
|
|
75
|
+
]);
|
|
76
|
+
/**
|
|
77
|
+
* The bucket half of a client that has no bucket: every method throws
|
|
78
|
+
* {@link FileServerReadOnly}, naming itself.
|
|
79
|
+
*
|
|
80
|
+
* A proxy rather than a list of stubs, so a method the storage client grows
|
|
81
|
+
* later refuses the same way. What a runtime asks of any object is left
|
|
82
|
+
* alone: `then`, because a client is resolved from a promise, and the names a
|
|
83
|
+
* serialiser or a test's printer looks for.
|
|
84
|
+
*/
|
|
85
|
+
function readOnlyStorage(id, key) {
|
|
86
|
+
return new Proxy({}, { get(_target, property) {
|
|
87
|
+
if (typeof property !== "string" || INTROSPECTED.has(property)) return;
|
|
88
|
+
return () => {
|
|
89
|
+
throw new FileServerReadOnly(id, property, key);
|
|
90
|
+
};
|
|
91
|
+
} });
|
|
92
|
+
}
|
|
50
93
|
/** A key was asked to be served unsigned, and no open pattern admits it. */
|
|
51
94
|
var NotOpen = class extends Error {
|
|
52
95
|
key;
|
|
@@ -92,10 +135,10 @@ var FileServer = class {
|
|
|
92
135
|
if (options.origin && options.expire) throw new BucketOptionOnOrigin(canonical, originId, "expire");
|
|
93
136
|
this.expire = require_expire.expiryDays(canonical, options.expire);
|
|
94
137
|
this.derivedDays = options.derived ? require_expire.expiryDays(canonical, { [_geekmidas_manifest.DERIVED_PREFIX]: options.derived })?.[_geekmidas_manifest.DERIVED_PREFIX] : void 0;
|
|
95
|
-
this.surfaceId =
|
|
138
|
+
this.surfaceId = (0, _geekmidas_manifest.fileServerSurfaceId)(canonical);
|
|
96
139
|
this.keys = {
|
|
97
|
-
origin: (0, _geekmidas_manifest.
|
|
98
|
-
server: (0, _geekmidas_manifest.
|
|
140
|
+
origin: (0, _geekmidas_manifest.providedKeyFor)(originId, "objects", "connectionString"),
|
|
141
|
+
server: (0, _geekmidas_manifest.providedKeyFor)(this.surfaceId, "file-server", "url")
|
|
99
142
|
};
|
|
100
143
|
this.service = {
|
|
101
144
|
serviceName: (0, _geekmidas_manifest.serviceKey)(canonical),
|
|
@@ -145,20 +188,14 @@ var FileServer = class {
|
|
|
145
188
|
});
|
|
146
189
|
}
|
|
147
190
|
/**
|
|
148
|
-
* The served surface
|
|
149
|
-
*
|
|
150
|
-
* Depending on the `FileServer` itself points at the **bucket** — its
|
|
151
|
-
* canonical node — which is right for a handler: it presigns and writes. But
|
|
152
|
-
* a bucket's URL is never public, so a site depending on it gets nothing
|
|
153
|
-
* inlined, which is correct and also useless.
|
|
191
|
+
* The served surface: what a site's or a mobile app's plain
|
|
192
|
+
* `.dependsOn([uploads])` points at.
|
|
154
193
|
*
|
|
155
|
-
*
|
|
156
|
-
*
|
|
157
|
-
*
|
|
158
|
-
* `database.reader()` uses, and for the same reason — one construct owning
|
|
159
|
-
* two addresses needs a way to name the second.
|
|
194
|
+
* Its address is public, so the frontend is built with it
|
|
195
|
+
* (`VITE_UPLOADS_URL`) — and it is all the frontend gets: no bucket, no
|
|
196
|
+
* key. A backend's plain edge is to the bucket, as it presigns and writes.
|
|
160
197
|
*/
|
|
161
|
-
get
|
|
198
|
+
get publicFace() {
|
|
162
199
|
const surface = this.declare().find((declaration) => declaration.id === this.surfaceId);
|
|
163
200
|
return {
|
|
164
201
|
id: this.surfaceId,
|
|
@@ -166,6 +203,23 @@ var FileServer = class {
|
|
|
166
203
|
};
|
|
167
204
|
}
|
|
168
205
|
/**
|
|
206
|
+
* Everything: the bucket, its credentials, and the address it is served
|
|
207
|
+
* on.
|
|
208
|
+
*
|
|
209
|
+
* What a backend's plain edge already is. A frontend asks for it by name —
|
|
210
|
+
* `.dependsOn([uploads.server])` — when its server half uploads or
|
|
211
|
+
* presigns: a full-stack site's, never a bundle's. The bucket's connection
|
|
212
|
+
* is never inlined into a bundle either way; only the served address is.
|
|
213
|
+
*/
|
|
214
|
+
get server() {
|
|
215
|
+
const originId = this.options.origin?.id ?? this.id;
|
|
216
|
+
const declarations = this.options.origin ? this.options.origin.declare() : this.declare();
|
|
217
|
+
return {
|
|
218
|
+
id: originId,
|
|
219
|
+
declare: () => declarations
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
169
223
|
* The bucket and the surface over it — or just the surface, when the bucket
|
|
170
224
|
* was declared elsewhere.
|
|
171
225
|
*
|
|
@@ -198,17 +252,21 @@ var FileServer = class {
|
|
|
198
252
|
/**
|
|
199
253
|
* The bucket's client, with the serving half added.
|
|
200
254
|
*
|
|
201
|
-
* Both
|
|
255
|
+
* Both keys are read here, which is also how the environment reaches a
|
|
202
256
|
* handler: the sniffer records what this reads, so `.dependsOn([uploads])`
|
|
203
|
-
* carries the bucket
|
|
204
|
-
* down beside the handler.
|
|
257
|
+
* carries the bucket's connection and the server's address without either
|
|
258
|
+
* being written down beside the handler.
|
|
259
|
+
*
|
|
260
|
+
* Without the connection — a site's or an app's plain edge, which is to
|
|
261
|
+
* the public face — the client serves and does nothing else: its bucket
|
|
262
|
+
* methods throw {@link FileServerReadOnly}.
|
|
205
263
|
*/
|
|
206
264
|
async connect(options) {
|
|
207
265
|
const { origin, server } = options.envParser.create((get) => ({
|
|
208
|
-
origin: get(this.keys.origin).string(),
|
|
266
|
+
origin: get(this.keys.origin).string().optional(),
|
|
209
267
|
server: get(this.keys.server).string()
|
|
210
268
|
})).parse();
|
|
211
|
-
const storage = (0, _geekmidas_storage.createStorageClient)(origin);
|
|
269
|
+
const storage = origin ? (0, _geekmidas_storage.createStorageClient)(origin) : readOnlyStorage(this.id, this.keys.origin);
|
|
212
270
|
const base = server.replace(/\/+$/, "");
|
|
213
271
|
const serve = (key) => {
|
|
214
272
|
if (!this.serves(key)) throw new NotOpen(key, this.open);
|
|
@@ -272,6 +330,7 @@ function globToRegExp(pattern) {
|
|
|
272
330
|
//#endregion
|
|
273
331
|
exports.BucketOptionOnOrigin = BucketOptionOnOrigin;
|
|
274
332
|
exports.FileServer = FileServer;
|
|
333
|
+
exports.FileServerReadOnly = FileServerReadOnly;
|
|
275
334
|
exports.ImmutableNotOpen = ImmutableNotOpen;
|
|
276
335
|
exports.NotOpen = NotOpen;
|
|
277
336
|
exports.ProcessorNotOnThisServer = ProcessorNotOnThisServer;
|