@rebasepro/server 0.31.0-canary.g902a0ce → 0.32.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{GCSStorageController-sCw2c4aA.js → GCSStorageController-B3p3aUX-.js} +5 -5
- package/dist/{GCSStorageController-sCw2c4aA.js.map → GCSStorageController-B3p3aUX-.js.map} +1 -1
- package/dist/{S3StorageController-DDAq8Kt5.js → S3StorageController-C9LjuMhL.js} +5 -5
- package/dist/{S3StorageController-DDAq8Kt5.js.map → S3StorageController-C9LjuMhL.js.map} +1 -1
- package/dist/{access-CSfmyM87.js → access-BxkEYQh1.js} +6 -6
- package/dist/{access-CSfmyM87.js.map → access-BxkEYQh1.js.map} +1 -1
- package/dist/{access-CCsVee6z.js → access-D1CTJSLK.js} +3 -1
- package/dist/access-D1CTJSLK.js.map +1 -0
- package/dist/api/errors.d.ts +4 -0
- package/dist/api/rest/api-generator.d.ts +8 -0
- package/dist/{auth-Blo1R8rc.js → auth-Bfwjg4Bg.js} +37 -13
- package/dist/auth-Bfwjg4Bg.js.map +1 -0
- package/dist/auth-secrets-BZUH9916.js +60 -0
- package/dist/auth-secrets-BZUH9916.js.map +1 -0
- package/dist/backend/create-backend.d.ts +6 -0
- package/dist/backend/options.d.ts +10 -0
- package/dist/backend/services.d.ts +9 -0
- package/dist/{backup-B-1oW6qX.js → backup-g2ohsDe0.js} +7 -7
- package/dist/{backup-B-1oW6qX.js.map → backup-g2ohsDe0.js.map} +1 -1
- package/dist/boot/bundle.d.ts +11 -1
- package/dist/boot/env.d.ts +5 -0
- package/dist/boot/security-headers.d.ts +15 -5
- package/dist/boot/static-routing.d.ts +58 -0
- package/dist/{branch-routes-0xhHXlGq.js → branch-routes-DtNtc0Vh.js} +3 -3
- package/dist/{branch-routes-0xhHXlGq.js.map → branch-routes-DtNtc0Vh.js.map} +1 -1
- package/dist/{contract-routes-WwMWHWS9.js → contract-routes-CZTlAP7p.js} +3 -3
- package/dist/{contract-routes-WwMWHWS9.js.map → contract-routes-CZTlAP7p.js.map} +1 -1
- package/dist/{cron-loader-BDN8plQK.js → cron-loader-BBP0kBIl.js} +2 -2
- package/dist/{cron-loader-BDN8plQK.js.map → cron-loader-BBP0kBIl.js.map} +1 -1
- package/dist/{cron-routes-Cqm5wQsK.js → cron-routes-Du03uJ7K.js} +5 -5
- package/dist/{cron-routes-Cqm5wQsK.js.map → cron-routes-Du03uJ7K.js.map} +1 -1
- package/dist/{cron-scheduler-DgrsqyQQ.js → cron-scheduler-CopTWKYB.js} +2 -2
- package/dist/{cron-scheduler-DgrsqyQQ.js.map → cron-scheduler-CopTWKYB.js.map} +1 -1
- package/dist/{cron-store-91cd9Qzv.js → cron-store-FGaZOdMf.js} +3 -3
- package/dist/{cron-store-91cd9Qzv.js.map → cron-store-FGaZOdMf.js.map} +1 -1
- package/dist/dist-C1vNURUy.js +19354 -0
- package/dist/dist-C1vNURUy.js.map +1 -0
- package/dist/{errors-DpTMfX77.js → errors-NVbAQU25.js} +5 -1
- package/dist/errors-NVbAQU25.js.map +1 -0
- package/dist/{filter-dialect-DAVl1Nsm.js → filter-dialect-XtPJOCbD.js} +2 -2
- package/dist/{filter-dialect-DAVl1Nsm.js.map → filter-dialect-XtPJOCbD.js.map} +1 -1
- package/dist/{function-loader-BeFbN1-A.js → function-loader-D3YEHF6E.js} +2 -2
- package/dist/{function-loader-BeFbN1-A.js.map → function-loader-D3YEHF6E.js.map} +1 -1
- package/dist/{function-routes-CIwLXsZF.js → function-routes-DNDFIa7t.js} +3 -3
- package/dist/{function-routes-CIwLXsZF.js.map → function-routes-DNDFIa7t.js.map} +1 -1
- package/dist/functions/index.d.ts +2 -0
- package/dist/functions/index.js +162 -1
- package/dist/functions/index.js.map +1 -1
- package/dist/functions/rate-limit.d.ts +71 -0
- package/dist/{history-recorder-CNeqtTaR.js → history-recorder-C5RkbKS2.js} +3 -3
- package/dist/{history-recorder-CNeqtTaR.js.map → history-recorder-C5RkbKS2.js.map} +1 -1
- package/dist/{history-store-DseUt_dm.js → history-store-DzrJeEKv.js} +2 -2
- package/dist/{history-store-DseUt_dm.js.map → history-store-DzrJeEKv.js.map} +1 -1
- package/dist/index.d.ts +6 -0
- package/dist/index.es.js +1242 -214
- package/dist/index.es.js.map +1 -1
- package/dist/{internal-tables-CHFJHH7N.js → internal-tables-XxM_NdR_.js} +2 -2
- package/dist/{internal-tables-CHFJHH7N.js.map → internal-tables-XxM_NdR_.js.map} +1 -1
- package/dist/{jobs-WCyKVsUf.js → jobs-CFUwQTao.js} +3 -3
- package/dist/{jobs-WCyKVsUf.js.map → jobs-CFUwQTao.js.map} +1 -1
- package/dist/{jwt-JtQiewBW.js → jwt-CqhXs8Iz.js} +3 -3
- package/dist/{jwt-JtQiewBW.js.map → jwt-CqhXs8Iz.js.map} +1 -1
- package/dist/{keys-BTPoSvUs.js → keys-Btt6ZNqF.js} +2 -2
- package/dist/{keys-BTPoSvUs.js.map → keys-Btt6ZNqF.js.map} +1 -1
- package/dist/{load-schema-CtyLeq-H.js → load-schema-B4Nv1mwq.js} +33 -40
- package/dist/load-schema-B4Nv1mwq.js.map +1 -0
- package/dist/{logs-routes-BT4af1Or.js → logs-routes-C3CLYP-n.js} +3 -3
- package/dist/{logs-routes-BT4af1Or.js.map → logs-routes-C3CLYP-n.js.map} +1 -1
- package/dist/{offline-D_wKJcO3-RV6C9HnX.js → offline-ET6xI1ZO-BQpLQ7wh.js} +124 -7
- package/dist/offline-ET6xI1ZO-BQpLQ7wh.js.map +1 -0
- package/dist/{offline-store-DtmBwmKE-B17N4609.js → offline-store-DtmBwmKE-C9ba2NJv.js} +3 -3
- package/dist/{offline-store-DtmBwmKE-B17N4609.js.map → offline-store-DtmBwmKE-C9ba2NJv.js.map} +1 -1
- package/dist/{openapi-generator-mn6hsEmw.js → openapi-generator-CAhJiwBm.js} +4 -4
- package/dist/{openapi-generator-mn6hsEmw.js.map → openapi-generator-CAhJiwBm.js.map} +1 -1
- package/dist/{project-root-qDQzmsUD.js → project-root-CIrVZi-r.js} +2 -2
- package/dist/{project-root-qDQzmsUD.js.map → project-root-CIrVZi-r.js.map} +1 -1
- package/dist/{proxy-D18_bcQI.js → proxy-clweqa43.js} +3 -3
- package/dist/{proxy-D18_bcQI.js.map → proxy-clweqa43.js.map} +1 -1
- package/dist/push/push-options.d.ts +26 -0
- package/dist/push/push-routes.d.ts +30 -0
- package/dist/push/push-service.d.ts +13 -0
- package/dist/push/push-store.d.ts +45 -0
- package/dist/push/set-up.d.ts +25 -0
- package/dist/push/subscription-input.d.ts +26 -0
- package/dist/push/vapid-config.d.ts +35 -0
- package/dist/push/web-push-crypto.d.ts +44 -0
- package/dist/push/web-push-sender.d.ts +10 -0
- package/dist/{query-parser-CkKSbs1s.js → query-parser-Cd70kZO8.js} +6 -6
- package/dist/{query-parser-CkKSbs1s.js.map → query-parser-Cd70kZO8.js.map} +1 -1
- package/dist/{request-timeout-CpOgfQPK.js → request-timeout-cC3HT1Pf.js} +3 -3
- package/dist/{request-timeout-CpOgfQPK.js.map → request-timeout-cC3HT1Pf.js.map} +1 -1
- package/dist/{rls-simulator-routes-BxzeNXmI.js → rls-simulator-routes-DI2sYaQt.js} +4 -4
- package/dist/{rls-simulator-routes-BxzeNXmI.js.map → rls-simulator-routes-DI2sYaQt.js.map} +1 -1
- package/dist/{schema-editor-routes-mPCyks4X.js → schema-editor-routes-DEGwyQmx.js} +5 -5
- package/dist/{schema-editor-routes-mPCyks4X.js.map → schema-editor-routes-DEGwyQmx.js.map} +1 -1
- package/dist/{schema-tables-D4MEBZFi.js → schema-tables-DKFg6vMV.js} +4 -4
- package/dist/{schema-tables-D4MEBZFi.js.map → schema-tables-DKFg6vMV.js.map} +1 -1
- package/dist/{schema-tables-routes-D3iLb5XU.js → schema-tables-routes-BfsNG4c4.js} +5 -5
- package/dist/{schema-tables-routes-D3iLb5XU.js.map → schema-tables-routes-BfsNG4c4.js.map} +1 -1
- package/dist/{securityRuleToConditions-DD40f3ml.js → securityRuleToConditions-Bk5zRSoa.js} +2 -2
- package/dist/{securityRuleToConditions-DD40f3ml.js.map → securityRuleToConditions-Bk5zRSoa.js.map} +1 -1
- package/dist/{selection-hgC1szl6.js → selection-BOnbJvXD.js} +2 -2
- package/dist/{selection-hgC1szl6.js.map → selection-BOnbJvXD.js.map} +1 -1
- package/dist/serve-spa.d.ts +12 -0
- package/dist/{soft-delete-params-DDRmxT2z.js → soft-delete-params-Dhn0qKFv.js} +2 -2
- package/dist/{soft-delete-params-DDRmxT2z.js.map → soft-delete-params-Dhn0qKFv.js.map} +1 -1
- package/dist/{sql-export-routes-BKmQZ3xh.js → sql-export-routes-B3oqb1Jw.js} +3 -3
- package/dist/{sql-export-routes-BKmQZ3xh.js.map → sql-export-routes-B3oqb1Jw.js.map} +1 -1
- package/dist/{src-DLIb1O9l.js → src-CNZB3fuE.js} +192 -3
- package/dist/src-CNZB3fuE.js.map +1 -0
- package/dist/{table-source-editor-xvccIOH1.js → table-source-editor-D_zNDhEU.js} +3 -3
- package/dist/{table-source-editor-xvccIOH1.js.map → table-source-editor-D_zNDhEU.js.map} +1 -1
- package/dist/{upload-validation-B-psYLaN.js → upload-validation-BnIwo78L.js} +2 -2
- package/dist/{upload-validation-B-psYLaN.js.map → upload-validation-BnIwo78L.js.map} +1 -1
- package/package.json +5 -5
- package/dist/access-CCsVee6z.js.map +0 -1
- package/dist/auth-Blo1R8rc.js.map +0 -1
- package/dist/dist-CDIqWaSr.js +0 -19354
- package/dist/dist-CDIqWaSr.js.map +0 -1
- package/dist/errors-DpTMfX77.js.map +0 -1
- package/dist/load-schema-CtyLeq-H.js.map +0 -1
- package/dist/offline-D_wKJcO3-RV6C9HnX.js.map +0 -1
- package/dist/src-DLIb1O9l.js.map +0 -1
|
@@ -2,7 +2,7 @@ import { createRequire as __rebaseCreateRequire } from "module";
|
|
|
2
2
|
import __rebaseProcess from "process";
|
|
3
3
|
globalThis.process ??= __rebaseProcess;
|
|
4
4
|
__rebaseCreateRequire(import.meta.url);
|
|
5
|
-
import {
|
|
5
|
+
import { en as DEFAULT_COMMIT_PATHS } from "./src-CNZB3fuE.js";
|
|
6
6
|
import path from "node:path";
|
|
7
7
|
import fs from "node:fs";
|
|
8
8
|
//#region src/schema-edit/project-root.ts
|
|
@@ -111,4 +111,4 @@ function holdsMigrations(dir) {
|
|
|
111
111
|
//#endregion
|
|
112
112
|
export { usesVersionedMigrations as i, commitPathsFor as n, findProjectRoot as r, DEFAULT_SCHEMA_PATH as t };
|
|
113
113
|
|
|
114
|
-
//# sourceMappingURL=project-root-
|
|
114
|
+
//# sourceMappingURL=project-root-CIrVZi-r.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"project-root-
|
|
1
|
+
{"version":3,"file":"project-root-CIrVZi-r.js","names":[],"sources":["../src/schema-edit/project-root.ts"],"sourcesContent":["/**\n * Where a project's generated artifacts belong, relative to its repository.\n *\n * `DEFAULT_COMMIT_PATHS` names `backend/src/schema.generated.ts`, which is\n * correct read from the **project** root and wrong read from anywhere else. The repository resolves what it is\n * given against its own root, and those two coincide only when the project is\n * the whole repository.\n *\n * A `rebase init` project is exactly that, so this was invisible. A project in\n * a subdirectory — an app inside a monorepo, this repository's own `app/` —\n * is not: the commit created `backend/` beside `.git`, left the real generated\n * file untouched, and committed a source change alongside a\n * stale schema. That is the failure the commit-the-whole-change design exists\n * to prevent, arriving through the design itself.\n *\n * ## Why `rebase.json`\n *\n * Because the codebase already treats it as the project marker: it is the file\n * the CLI validates as the manifest and the file `rebase resources --write`\n * writes `rebase.resources.json` beside. Using the same anchor means one answer\n * to \"where does this project start\", not two that can disagree.\n */\nimport fs from \"node:fs\";\nimport path from \"node:path\";\nimport { DEFAULT_COMMIT_PATHS, type SchemaCommitPaths } from \"@rebasepro/types\";\n\n/**\n * The nearest ancestor of `startDir` holding a `rebase.json`.\n *\n * Bounded: an unbounded walk from a misconfigured path climbs to the filesystem\n * root and reads whatever it finds there. `undefined` when there is none, which\n * is a project that predates the file — the caller then keeps the historical\n * behaviour rather than guessing.\n */\n/**\n * Where a scaffolded project keeps its schema source, project-relative.\n *\n * A bundle's tables are compiled output, so nothing on the running machine\n * points at this. A deployment committing to a repository states it, and this\n * is the default it states nothing against.\n */\nexport const DEFAULT_SCHEMA_PATH = \"backend/schema\";\n\nexport function findProjectRoot(startDir: string, levels = 5): string | undefined {\n let dir = path.resolve(startDir);\n for (let i = 0; i <= levels; i++) {\n if (fs.existsSync(path.join(dir, \"rebase.json\"))) return dir;\n const parent = path.dirname(dir);\n if (parent === dir) return undefined;\n dir = parent;\n }\n return undefined;\n}\n\n/**\n * The generated-artifact paths for a project, expressed relative to the\n * repository that will hold the commit.\n *\n * Returns `undefined` when there is nothing to correct — no project marker, or\n * a project that *is* the repository — so the caller passes no override and the\n * defaults stand. Saying \"no change needed\" is different from saying\n * \"the change is a no-op prefix\", and only the first leaves the existing\n * behaviour untouched for every project that already worked.\n */\nexport function commitPathsFor(\n schemaDir: string,\n repositoryRoot: string\n): Partial<SchemaCommitPaths> | undefined {\n const projectRoot = findProjectRoot(schemaDir);\n if (!projectRoot) return undefined;\n\n const prefix = path.relative(path.resolve(repositoryRoot), projectRoot);\n // Empty when the project is the repository — the case the defaults were\n // written for. `..` means the project sits *outside* the repository, which\n // is not a layout this can commit for; leaving the defaults alone lets the\n // repository's own write guard refuse it by path rather than inventing one.\n if (prefix === \"\" || prefix.startsWith(\"..\")) return undefined;\n\n const relocate = (p: string) => path.posix.join(...prefix.split(path.sep), p);\n return { schemaFile: relocate(DEFAULT_COMMIT_PATHS.schemaFile) };\n}\n\n/**\n * Does this project keep versioned migrations?\n *\n * It matters because live schema editing does not write one, and cannot: a\n * migration is Atlas's format with an integrity file, minted by an external\n * binary against a throwaway database. A server process has neither.\n *\n * What it *does* write is the schema source, which is exactly what\n * `rebase db generate` renders its desired state from — so the migration is\n * one command away.\n * The hazard is nobody saying so. A project that deploys by replaying\n * migrations would build its next environment without this change, having been\n * told the change was applied.\n */\nexport function usesVersionedMigrations(schemaDir: string): boolean {\n const projectRoot = findProjectRoot(schemaDir);\n if (!projectRoot) return false;\n return MIGRATION_DIRS.some(relative => holdsMigrations(path.join(projectRoot, relative)));\n}\n\n/**\n * Where a project's migrations can be, project-relative.\n *\n * The driver writes `drizzle/migrations/` relative to the directory it runs in,\n * and every `rebase db` subcommand runs it from the backend, which the CLI takes\n * to be `backend/` — so that is where a scaffolded project keeps them. Looking\n * only at the project root answered \"no migrations\" for every one of those, and\n * the warning this feeds never appeared. The root stays on the list because the\n * driver run from there writes there.\n */\nconst MIGRATION_DIRS = [\n path.join(\"backend\", \"drizzle\", \"migrations\"),\n path.join(\"drizzle\", \"migrations\")\n];\n\nfunction holdsMigrations(dir: string): boolean {\n try {\n return fs.existsSync(dir) && fs.readdirSync(dir).some(f => f.endsWith(\".sql\"));\n } catch {\n // Unreadable is not \"absent\": staying quiet about a project that may\n // replay migrations is the failure this exists to prevent.\n return true;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyCA,IAAa,sBAAsB;AAEnC,SAAgB,gBAAgB,UAAkB,SAAS,GAAuB;CAC9E,IAAI,MAAM,KAAK,QAAQ,QAAQ;CAC/B,KAAK,IAAI,IAAI,GAAG,KAAK,QAAQ,KAAK;EAC9B,IAAI,GAAG,WAAW,KAAK,KAAK,KAAK,aAAa,CAAC,GAAG,OAAO;EACzD,MAAM,SAAS,KAAK,QAAQ,GAAG;EAC/B,IAAI,WAAW,KAAK,OAAO,KAAA;EAC3B,MAAM;CACV;AAEJ;;;;;;;;;;;AAYA,SAAgB,eACZ,WACA,gBACsC;CACtC,MAAM,cAAc,gBAAgB,SAAS;CAC7C,IAAI,CAAC,aAAa,OAAO,KAAA;CAEzB,MAAM,SAAS,KAAK,SAAS,KAAK,QAAQ,cAAc,GAAG,WAAW;CAKtE,IAAI,WAAW,MAAM,OAAO,WAAW,IAAI,GAAG,OAAO,KAAA;CAErD,MAAM,YAAY,MAAc,KAAK,MAAM,KAAK,GAAG,OAAO,MAAM,KAAK,GAAG,GAAG,CAAC;CAC5E,OAAO,EAAE,YAAY,SAAS,qBAAqB,UAAU,EAAE;AACnE;;;;;;;;;;;;;;;AAgBA,SAAgB,wBAAwB,WAA4B;CAChE,MAAM,cAAc,gBAAgB,SAAS;CAC7C,IAAI,CAAC,aAAa,OAAO;CACzB,OAAO,eAAe,MAAK,aAAY,gBAAgB,KAAK,KAAK,aAAa,QAAQ,CAAC,CAAC;AAC5F;;;;;;;;;;;AAYA,IAAM,iBAAiB,CACnB,KAAK,KAAK,WAAW,WAAW,YAAY,GAC5C,KAAK,KAAK,WAAW,YAAY,CACrC;AAEA,SAAS,gBAAgB,KAAsB;CAC3C,IAAI;EACA,OAAO,GAAG,WAAW,GAAG,KAAK,GAAG,YAAY,GAAG,CAAC,CAAC,MAAK,MAAK,EAAE,SAAS,MAAM,CAAC;CACjF,QAAQ;EAGJ,OAAO;CACX;AACJ"}
|
|
@@ -2,9 +2,9 @@ import { createRequire as __rebaseCreateRequire } from "module";
|
|
|
2
2
|
import __rebaseProcess from "process";
|
|
3
3
|
globalThis.process ??= __rebaseProcess;
|
|
4
4
|
__rebaseCreateRequire(import.meta.url);
|
|
5
|
-
import {
|
|
5
|
+
import { Rn as __exportAll } from "./src-CNZB3fuE.js";
|
|
6
6
|
import { a as logger } from "./logger-SigQ2oZJ.js";
|
|
7
|
-
import { i as errorHandler, t as ApiError } from "./errors-
|
|
7
|
+
import { i as errorHandler, t as ApiError } from "./errors-NVbAQU25.js";
|
|
8
8
|
import { Hono } from "hono";
|
|
9
9
|
import { getConnInfo } from "@hono/node-server/conninfo";
|
|
10
10
|
//#region src/functions/proxy.ts
|
|
@@ -138,4 +138,4 @@ function socketAddress(c) {
|
|
|
138
138
|
//#endregion
|
|
139
139
|
export { proxy_exports as t };
|
|
140
140
|
|
|
141
|
-
//# sourceMappingURL=proxy-
|
|
141
|
+
//# sourceMappingURL=proxy-clweqa43.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"proxy-D18_bcQI.js","names":[],"sources":["../src/functions/proxy.ts"],"sourcesContent":["/**\n * Forwarding `/api/functions/*` to the process that serves it.\n *\n * A split deployment normally puts a reverse proxy in front and routes the path\n * there. This exists so it does not have to: set `REBASE_FUNCTIONS_UPSTREAM` on\n * the API process and the two-container topology presents the identical URL\n * surface as the one-container one, with nothing new to install and nothing for\n * a client or an SDK to know about.\n *\n * It is a transport hop, not a trust boundary. Nothing is authenticated or\n * authorised here: the upstream runs the same auth middleware against the same\n * `JWT_SECRET` and must see the original `Authorization` header, so re-deciding\n * anything on the way through would put two answers where the system has one.\n */\nimport { Hono, type Context } from \"hono\";\nimport { getConnInfo } from \"@hono/node-server/conninfo\";\nimport type { HonoEnv } from \"../api/types\";\nimport { ApiError, errorHandler } from \"../api/errors\";\nimport { logger } from \"../utils/logger\";\n\n/**\n * Headers that describe *this* connection rather than the request, and so must\n * not be copied onto a new one.\n *\n * `host` is the important one: forwarded unchanged it names the API process, and\n * an upstream doing any virtual-host routing would answer for the wrong service.\n * `content-length` and `transfer-encoding` are recomputed by `fetch` from the\n * body it is actually given, and a stale value is a hang or a truncation.\n */\nconst HOP_BY_HOP = new Set([\n \"connection\",\n \"keep-alive\",\n \"proxy-authenticate\",\n \"proxy-authorization\",\n \"te\",\n \"trailer\",\n \"transfer-encoding\",\n \"upgrade\",\n \"host\",\n \"content-length\"\n]);\n\n/**\n * Additionally dropped from the *response*, because `fetch` has already acted on\n * them by the time we see the body.\n *\n * `Content-Encoding` is the one that matters and the one that is easy to miss:\n * undici decompresses a `gzip` response transparently, but leaves the header on\n * the `Response` object. Copy it onto the body we hand back and the client is\n * told to gunzip bytes that are already plain — which does not fail cleanly. It\n * hangs, or it surfaces as a decode error several layers away from the proxy\n * that caused it. (This is not hypothetical: the runtime compresses its own\n * responses, so *every* forwarded response carries the header.)\n */\nconst RESPONSE_ONLY_DROP = new Set([\"content-encoding\", \"content-length\"]);\n\nexport interface FunctionsProxyOptions {\n /** Base URL of the process serving the functions, e.g. `http://functions:8080`. */\n upstream: string;\n /**\n * The mount path being forwarded, e.g. `/api/functions`. Omitted, it is the\n * `mountPath` the functions group recorded for the request — the path the\n * application mounted it at — so the upstream is asked for the same path.\n */\n basePath?: string;\n}\n\n/**\n * A router that forwards everything under its mount point to `upstream`.\n *\n * Method, path, query string, body and headers travel verbatim, with two\n * deliberate exceptions:\n *\n * 1. Hop-by-hop headers are dropped ({@link HOP_BY_HOP}).\n * 2. `X-Forwarded-For` gains the address this process saw the request come from.\n * This is not decoration — the upstream's rate limiters and the auth routes'\n * IP logging read that chain, and without the append every forwarded request\n * arrives from one address: the API pod's. Every caller would share a single\n * rate-limit bucket and every login would be logged from the same IP.\n *\n * **The upstream must therefore count one more proxy hop than the API process\n * does.** `TRUSTED_PROXY_HOPS` on the functions process is the API's value\n * plus one. Left unset it defaults to 0, and the upstream falls back to the\n * socket address — again, the API pod's — which is safe but useless.\n */\nexport function createFunctionsProxy(options: FunctionsProxyOptions): Hono<HonoEnv> {\n const router = new Hono<HonoEnv>();\n // Trailing slash trimmed once, here: joining it per request is how a proxy\n // ends up asking for `//functions/x`, which some servers route and some 404.\n const upstream = options.upstream.replace(/\\/+$/, \"\");\n\n router.all(\"/*\", async (c) => {\n const incoming = new URL(c.req.url);\n const basePath = options.basePath ?? c.get(\"mountPath\") ?? \"\";\n // The path *below* the mount point. Hono gives the full request path, so\n // taking the suffix is what keeps the upstream's own mount identical:\n // `/api/functions/send-invoice` here becomes `/api/functions/send-invoice`\n // there, not `/api/functions/api/functions/send-invoice`.\n const suffix = incoming.pathname.startsWith(basePath)\n ? incoming.pathname.slice(basePath.length)\n : incoming.pathname;\n const target = `${upstream}${basePath}${suffix}${incoming.search}`;\n\n const headers = new Headers();\n for (const [name, value] of c.req.raw.headers) {\n if (!HOP_BY_HOP.has(name.toLowerCase())) headers.set(name, value);\n }\n\n const seenFrom = socketAddress(c);\n if (seenFrom) {\n const chain = c.req.header(\"x-forwarded-for\");\n headers.set(\"x-forwarded-for\", chain ? `${chain}, ${seenFrom}` : seenFrom);\n }\n\n try {\n const response = await fetch(target, {\n method: c.req.method,\n headers,\n // GET and HEAD may not carry one; everything else streams\n // through rather than being buffered, so a large upload does not\n // have to fit in this process's memory on its way past.\n body: c.req.method === \"GET\" || c.req.method === \"HEAD\" ? undefined : c.req.raw.body,\n // Required by undici whenever the body is a stream. Without it\n // the fetch rejects with a message about duplex that says\n // nothing about what to do.\n duplex: \"half\",\n redirect: \"manual\"\n } as RequestInit);\n\n return new Response(response.body, {\n status: response.status,\n statusText: response.statusText,\n headers: responseHeaders(response.headers)\n });\n } catch (err) {\n // The upstream being down is an infrastructure fact, not a bug in\n // the caller's request, and 502 is the one status that says so.\n // Named explicitly in the body because the alternative — a generic\n // 500 from the API process — sends people reading the wrong logs.\n logger.error(\"Functions upstream unreachable\", {\n upstream,\n path: incoming.pathname,\n error: err instanceof Error ? err : new Error(String(err))\n });\n // Through the error handler, so it is the envelope every other\n // failure answers — with the request id that ties it to the line\n // above. Built by hand, it carried none.\n return errorHandler(new ApiError(\n 502,\n \"FUNCTIONS_UPSTREAM_UNREACHABLE\",\n \"The process serving custom functions could not be reached from this one.\"\n ), c);\n }\n });\n\n return router;\n}\n\n/**\n * Response headers, minus the ones that describe the upstream's connection and\n * the ones `fetch` has already consumed on our behalf.\n */\nfunction responseHeaders(headers: Headers): Headers {\n const out = new Headers();\n for (const [name, value] of headers) {\n const lower = name.toLowerCase();\n if (HOP_BY_HOP.has(lower) || RESPONSE_ONLY_DROP.has(lower)) continue;\n // `append`, not `set`: iterating a `Headers` yields each `Set-Cookie`\n // on its own, and `set` overwrote every one with the next — a sign-in\n // setting a session and a CSRF cookie reached the browser with the\n // CSRF cookie only. Every other header arrives folded, once.\n out.append(name, value);\n }\n return out;\n}\n\n/** The address this process saw, or undefined on a runtime that cannot say. */\nfunction socketAddress(c: Context<HonoEnv>): string | undefined {\n try {\n return getConnInfo(c).remote.address;\n } catch {\n return undefined;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6BA,IAAM,6BAAa,IAAI,IAAI;CACvB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACJ,CAAC;;;;;;;;;;;;;AAcD,IAAM,qCAAqB,IAAI,IAAI,CAAC,oBAAoB,gBAAgB,CAAC;;;;;;;;;;;;;;;;;;;AA+BzE,SAAgB,qBAAqB,SAA+C;CAChF,MAAM,SAAS,IAAI,KAAc;CAGjC,MAAM,WAAW,QAAQ,SAAS,QAAQ,QAAQ,EAAE;CAEpD,OAAO,IAAI,MAAM,OAAO,MAAM;EAC1B,MAAM,WAAW,IAAI,IAAI,EAAE,IAAI,GAAG;EAClC,MAAM,WAAW,QAAQ,YAAY,EAAE,IAAI,WAAW,KAAK;EAK3D,MAAM,SAAS,SAAS,SAAS,WAAW,QAAQ,IAC9C,SAAS,SAAS,MAAM,SAAS,MAAM,IACvC,SAAS;EACf,MAAM,SAAS,GAAG,WAAW,WAAW,SAAS,SAAS;EAE1D,MAAM,UAAU,IAAI,QAAQ;EAC5B,KAAK,MAAM,CAAC,MAAM,UAAU,EAAE,IAAI,IAAI,SAClC,IAAI,CAAC,WAAW,IAAI,KAAK,YAAY,CAAC,GAAG,QAAQ,IAAI,MAAM,KAAK;EAGpE,MAAM,WAAW,cAAc,CAAC;EAChC,IAAI,UAAU;GACV,MAAM,QAAQ,EAAE,IAAI,OAAO,iBAAiB;GAC5C,QAAQ,IAAI,mBAAmB,QAAQ,GAAG,MAAM,IAAI,aAAa,QAAQ;EAC7E;EAEA,IAAI;GACA,MAAM,WAAW,MAAM,MAAM,QAAQ;IACjC,QAAQ,EAAE,IAAI;IACd;IAIA,MAAM,EAAE,IAAI,WAAW,SAAS,EAAE,IAAI,WAAW,SAAS,KAAA,IAAY,EAAE,IAAI,IAAI;IAIhF,QAAQ;IACR,UAAU;GACd,CAAgB;GAEhB,OAAO,IAAI,SAAS,SAAS,MAAM;IAC/B,QAAQ,SAAS;IACjB,YAAY,SAAS;IACrB,SAAS,gBAAgB,SAAS,OAAO;GAC7C,CAAC;EACL,SAAS,KAAK;GAKV,OAAO,MAAM,kCAAkC;IAC3C;IACA,MAAM,SAAS;IACf,OAAO,eAAe,QAAQ,MAAM,IAAI,MAAM,OAAO,GAAG,CAAC;GAC7D,CAAC;GAID,OAAO,aAAa,IAAI,SACpB,KACA,kCACA,0EACJ,GAAG,CAAC;EACR;CACJ,CAAC;CAED,OAAO;AACX;;;;;AAMA,SAAS,gBAAgB,SAA2B;CAChD,MAAM,MAAM,IAAI,QAAQ;CACxB,KAAK,MAAM,CAAC,MAAM,UAAU,SAAS;EACjC,MAAM,QAAQ,KAAK,YAAY;EAC/B,IAAI,WAAW,IAAI,KAAK,KAAK,mBAAmB,IAAI,KAAK,GAAG;EAK5D,IAAI,OAAO,MAAM,KAAK;CAC1B;CACA,OAAO;AACX;;AAGA,SAAS,cAAc,GAAyC;CAC5D,IAAI;EACA,OAAO,YAAY,CAAC,CAAC,CAAC,OAAO;CACjC,QAAQ;EACJ;CACJ;AACJ"}
|
|
1
|
+
{"version":3,"file":"proxy-clweqa43.js","names":[],"sources":["../src/functions/proxy.ts"],"sourcesContent":["/**\n * Forwarding `/api/functions/*` to the process that serves it.\n *\n * A split deployment normally puts a reverse proxy in front and routes the path\n * there. This exists so it does not have to: set `REBASE_FUNCTIONS_UPSTREAM` on\n * the API process and the two-container topology presents the identical URL\n * surface as the one-container one, with nothing new to install and nothing for\n * a client or an SDK to know about.\n *\n * It is a transport hop, not a trust boundary. Nothing is authenticated or\n * authorised here: the upstream runs the same auth middleware against the same\n * `JWT_SECRET` and must see the original `Authorization` header, so re-deciding\n * anything on the way through would put two answers where the system has one.\n */\nimport { Hono, type Context } from \"hono\";\nimport { getConnInfo } from \"@hono/node-server/conninfo\";\nimport type { HonoEnv } from \"../api/types\";\nimport { ApiError, errorHandler } from \"../api/errors\";\nimport { logger } from \"../utils/logger\";\n\n/**\n * Headers that describe *this* connection rather than the request, and so must\n * not be copied onto a new one.\n *\n * `host` is the important one: forwarded unchanged it names the API process, and\n * an upstream doing any virtual-host routing would answer for the wrong service.\n * `content-length` and `transfer-encoding` are recomputed by `fetch` from the\n * body it is actually given, and a stale value is a hang or a truncation.\n */\nconst HOP_BY_HOP = new Set([\n \"connection\",\n \"keep-alive\",\n \"proxy-authenticate\",\n \"proxy-authorization\",\n \"te\",\n \"trailer\",\n \"transfer-encoding\",\n \"upgrade\",\n \"host\",\n \"content-length\"\n]);\n\n/**\n * Additionally dropped from the *response*, because `fetch` has already acted on\n * them by the time we see the body.\n *\n * `Content-Encoding` is the one that matters and the one that is easy to miss:\n * undici decompresses a `gzip` response transparently, but leaves the header on\n * the `Response` object. Copy it onto the body we hand back and the client is\n * told to gunzip bytes that are already plain — which does not fail cleanly. It\n * hangs, or it surfaces as a decode error several layers away from the proxy\n * that caused it. (This is not hypothetical: the runtime compresses its own\n * responses, so *every* forwarded response carries the header.)\n */\nconst RESPONSE_ONLY_DROP = new Set([\"content-encoding\", \"content-length\"]);\n\nexport interface FunctionsProxyOptions {\n /** Base URL of the process serving the functions, e.g. `http://functions:8080`. */\n upstream: string;\n /**\n * The mount path being forwarded, e.g. `/api/functions`. Omitted, it is the\n * `mountPath` the functions group recorded for the request — the path the\n * application mounted it at — so the upstream is asked for the same path.\n */\n basePath?: string;\n}\n\n/**\n * A router that forwards everything under its mount point to `upstream`.\n *\n * Method, path, query string, body and headers travel verbatim, with two\n * deliberate exceptions:\n *\n * 1. Hop-by-hop headers are dropped ({@link HOP_BY_HOP}).\n * 2. `X-Forwarded-For` gains the address this process saw the request come from.\n * This is not decoration — the upstream's rate limiters and the auth routes'\n * IP logging read that chain, and without the append every forwarded request\n * arrives from one address: the API pod's. Every caller would share a single\n * rate-limit bucket and every login would be logged from the same IP.\n *\n * **The upstream must therefore count one more proxy hop than the API process\n * does.** `TRUSTED_PROXY_HOPS` on the functions process is the API's value\n * plus one. Left unset it defaults to 0, and the upstream falls back to the\n * socket address — again, the API pod's — which is safe but useless.\n */\nexport function createFunctionsProxy(options: FunctionsProxyOptions): Hono<HonoEnv> {\n const router = new Hono<HonoEnv>();\n // Trailing slash trimmed once, here: joining it per request is how a proxy\n // ends up asking for `//functions/x`, which some servers route and some 404.\n const upstream = options.upstream.replace(/\\/+$/, \"\");\n\n router.all(\"/*\", async (c) => {\n const incoming = new URL(c.req.url);\n const basePath = options.basePath ?? c.get(\"mountPath\") ?? \"\";\n // The path *below* the mount point. Hono gives the full request path, so\n // taking the suffix is what keeps the upstream's own mount identical:\n // `/api/functions/send-invoice` here becomes `/api/functions/send-invoice`\n // there, not `/api/functions/api/functions/send-invoice`.\n const suffix = incoming.pathname.startsWith(basePath)\n ? incoming.pathname.slice(basePath.length)\n : incoming.pathname;\n const target = `${upstream}${basePath}${suffix}${incoming.search}`;\n\n const headers = new Headers();\n for (const [name, value] of c.req.raw.headers) {\n if (!HOP_BY_HOP.has(name.toLowerCase())) headers.set(name, value);\n }\n\n const seenFrom = socketAddress(c);\n if (seenFrom) {\n const chain = c.req.header(\"x-forwarded-for\");\n headers.set(\"x-forwarded-for\", chain ? `${chain}, ${seenFrom}` : seenFrom);\n }\n\n try {\n const response = await fetch(target, {\n method: c.req.method,\n headers,\n // GET and HEAD may not carry one; everything else streams\n // through rather than being buffered, so a large upload does not\n // have to fit in this process's memory on its way past.\n body: c.req.method === \"GET\" || c.req.method === \"HEAD\" ? undefined : c.req.raw.body,\n // Required by undici whenever the body is a stream. Without it\n // the fetch rejects with a message about duplex that says\n // nothing about what to do.\n duplex: \"half\",\n redirect: \"manual\"\n } as RequestInit);\n\n return new Response(response.body, {\n status: response.status,\n statusText: response.statusText,\n headers: responseHeaders(response.headers)\n });\n } catch (err) {\n // The upstream being down is an infrastructure fact, not a bug in\n // the caller's request, and 502 is the one status that says so.\n // Named explicitly in the body because the alternative — a generic\n // 500 from the API process — sends people reading the wrong logs.\n logger.error(\"Functions upstream unreachable\", {\n upstream,\n path: incoming.pathname,\n error: err instanceof Error ? err : new Error(String(err))\n });\n // Through the error handler, so it is the envelope every other\n // failure answers — with the request id that ties it to the line\n // above. Built by hand, it carried none.\n return errorHandler(new ApiError(\n 502,\n \"FUNCTIONS_UPSTREAM_UNREACHABLE\",\n \"The process serving custom functions could not be reached from this one.\"\n ), c);\n }\n });\n\n return router;\n}\n\n/**\n * Response headers, minus the ones that describe the upstream's connection and\n * the ones `fetch` has already consumed on our behalf.\n */\nfunction responseHeaders(headers: Headers): Headers {\n const out = new Headers();\n for (const [name, value] of headers) {\n const lower = name.toLowerCase();\n if (HOP_BY_HOP.has(lower) || RESPONSE_ONLY_DROP.has(lower)) continue;\n // `append`, not `set`: iterating a `Headers` yields each `Set-Cookie`\n // on its own, and `set` overwrote every one with the next — a sign-in\n // setting a session and a CSRF cookie reached the browser with the\n // CSRF cookie only. Every other header arrives folded, once.\n out.append(name, value);\n }\n return out;\n}\n\n/** The address this process saw, or undefined on a runtime that cannot say. */\nfunction socketAddress(c: Context<HonoEnv>): string | undefined {\n try {\n return getConnInfo(c).remote.address;\n } catch {\n return undefined;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6BA,IAAM,6BAAa,IAAI,IAAI;CACvB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACJ,CAAC;;;;;;;;;;;;;AAcD,IAAM,qCAAqB,IAAI,IAAI,CAAC,oBAAoB,gBAAgB,CAAC;;;;;;;;;;;;;;;;;;;AA+BzE,SAAgB,qBAAqB,SAA+C;CAChF,MAAM,SAAS,IAAI,KAAc;CAGjC,MAAM,WAAW,QAAQ,SAAS,QAAQ,QAAQ,EAAE;CAEpD,OAAO,IAAI,MAAM,OAAO,MAAM;EAC1B,MAAM,WAAW,IAAI,IAAI,EAAE,IAAI,GAAG;EAClC,MAAM,WAAW,QAAQ,YAAY,EAAE,IAAI,WAAW,KAAK;EAK3D,MAAM,SAAS,SAAS,SAAS,WAAW,QAAQ,IAC9C,SAAS,SAAS,MAAM,SAAS,MAAM,IACvC,SAAS;EACf,MAAM,SAAS,GAAG,WAAW,WAAW,SAAS,SAAS;EAE1D,MAAM,UAAU,IAAI,QAAQ;EAC5B,KAAK,MAAM,CAAC,MAAM,UAAU,EAAE,IAAI,IAAI,SAClC,IAAI,CAAC,WAAW,IAAI,KAAK,YAAY,CAAC,GAAG,QAAQ,IAAI,MAAM,KAAK;EAGpE,MAAM,WAAW,cAAc,CAAC;EAChC,IAAI,UAAU;GACV,MAAM,QAAQ,EAAE,IAAI,OAAO,iBAAiB;GAC5C,QAAQ,IAAI,mBAAmB,QAAQ,GAAG,MAAM,IAAI,aAAa,QAAQ;EAC7E;EAEA,IAAI;GACA,MAAM,WAAW,MAAM,MAAM,QAAQ;IACjC,QAAQ,EAAE,IAAI;IACd;IAIA,MAAM,EAAE,IAAI,WAAW,SAAS,EAAE,IAAI,WAAW,SAAS,KAAA,IAAY,EAAE,IAAI,IAAI;IAIhF,QAAQ;IACR,UAAU;GACd,CAAgB;GAEhB,OAAO,IAAI,SAAS,SAAS,MAAM;IAC/B,QAAQ,SAAS;IACjB,YAAY,SAAS;IACrB,SAAS,gBAAgB,SAAS,OAAO;GAC7C,CAAC;EACL,SAAS,KAAK;GAKV,OAAO,MAAM,kCAAkC;IAC3C;IACA,MAAM,SAAS;IACf,OAAO,eAAe,QAAQ,MAAM,IAAI,MAAM,OAAO,GAAG,CAAC;GAC7D,CAAC;GAID,OAAO,aAAa,IAAI,SACpB,KACA,kCACA,0EACJ,GAAG,CAAC;EACR;CACJ,CAAC;CAED,OAAO;AACX;;;;;AAMA,SAAS,gBAAgB,SAA2B;CAChD,MAAM,MAAM,IAAI,QAAQ;CACxB,KAAK,MAAM,CAAC,MAAM,UAAU,SAAS;EACjC,MAAM,QAAQ,KAAK,YAAY;EAC/B,IAAI,WAAW,IAAI,KAAK,KAAK,mBAAmB,IAAI,KAAK,GAAG;EAK5D,IAAI,OAAO,MAAM,KAAK;CAC1B;CACA,OAAO;AACX;;AAGA,SAAS,cAAc,GAAyC;CAC5D,IAAI;EACA,OAAO,YAAY,CAAC,CAAC,CAAC,OAAO;CACjC,QAAQ;EACJ;CACJ;AACJ"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { PushSender } from "@rebasepro/types";
|
|
2
|
+
/**
|
|
3
|
+
* `push` in the backend options: Web Push notifications to browsers.
|
|
4
|
+
*
|
|
5
|
+
* `push: true` is the whole setup in development. The keys come from
|
|
6
|
+
* `REBASE_VAPID_PUBLIC_KEY`, `REBASE_VAPID_PRIVATE_KEY` and
|
|
7
|
+
* `REBASE_VAPID_SUBJECT`, and outside production a pair is generated and
|
|
8
|
+
* kept when they are unset.
|
|
9
|
+
*/
|
|
10
|
+
export interface PushOptions {
|
|
11
|
+
/** The VAPID keys and contact, in place of the environment variables. */
|
|
12
|
+
vapid?: {
|
|
13
|
+
publicKey?: string;
|
|
14
|
+
privateKey?: string;
|
|
15
|
+
/** A `mailto:` address or an `https://` URL the push services can contact. */
|
|
16
|
+
subject?: string;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Hostnames accepted as push services beyond the browsers' own (FCM,
|
|
20
|
+
* Mozilla, Apple, Windows). Exact, https only; an entry may carry a port,
|
|
21
|
+
* for a test push service on `127.0.0.1:8443`.
|
|
22
|
+
*/
|
|
23
|
+
allowedHosts?: string[];
|
|
24
|
+
/** Delivers each message, in place of the built-in sender. */
|
|
25
|
+
sender?: PushSender;
|
|
26
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The browser's side of push, normally under `/api/push`:
|
|
3
|
+
*
|
|
4
|
+
* GET /key the VAPID public key a browser subscribes with -> { key }
|
|
5
|
+
* POST /subscriptions { subscription, lang? } this browser takes notifications, for the caller -> { id }
|
|
6
|
+
* DELETE /subscriptions { endpoint } it does not any more -> { removed }
|
|
7
|
+
*
|
|
8
|
+
* Every route needs a signed-in person. An API key or the service key is
|
|
9
|
+
* refused: a subscription is a browser belonging to an account, and a script
|
|
10
|
+
* has neither.
|
|
11
|
+
*/
|
|
12
|
+
import { Hono, type MiddlewareHandler } from "hono";
|
|
13
|
+
import type { PushService } from "@rebasepro/types";
|
|
14
|
+
import type { HonoEnv } from "../api/types.js";
|
|
15
|
+
import type { PushStore } from "./push-store.js";
|
|
16
|
+
export interface PushRouteOptions {
|
|
17
|
+
/** `rebase.push`. When it is not configured, every route answers 503 `PUSH_NOT_CONFIGURED` with its reason. */
|
|
18
|
+
service: PushService;
|
|
19
|
+
/** Undefined when push is not configured. */
|
|
20
|
+
store?: PushStore;
|
|
21
|
+
/** Why push is not configured, for the 503. */
|
|
22
|
+
unconfiguredReason?: string;
|
|
23
|
+
/** Authenticates the request and sets `user`. */
|
|
24
|
+
auth: MiddlewareHandler<HonoEnv>;
|
|
25
|
+
/** Runs after auth, e.g. the data plane's rate limiter. */
|
|
26
|
+
after?: MiddlewareHandler<HonoEnv>[];
|
|
27
|
+
/** Hosts taken as push services beyond the known ones. */
|
|
28
|
+
allowedHosts?: readonly string[];
|
|
29
|
+
}
|
|
30
|
+
export declare function createPushRoutes(options: PushRouteOptions): Hono<HonoEnv>;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { PushSender, PushService } from "@rebasepro/types";
|
|
2
|
+
import type { PushStore } from "./push-store.js";
|
|
3
|
+
export interface PushServiceDeps {
|
|
4
|
+
store: PushStore;
|
|
5
|
+
sender: PushSender;
|
|
6
|
+
publicKey: string;
|
|
7
|
+
}
|
|
8
|
+
export declare function createPushService({ store, sender, publicKey }: PushServiceDeps): PushService;
|
|
9
|
+
/**
|
|
10
|
+
* `rebase.push` on a backend where push cannot send: off, or without keys.
|
|
11
|
+
* Every call that would send throws `reason`, which names what to set.
|
|
12
|
+
*/
|
|
13
|
+
export declare function createUnconfiguredPushService(reason: string): PushService;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The subscriptions, as SQL against `rebase.push_subscriptions`.
|
|
3
|
+
*
|
|
4
|
+
* One row per browser, keyed by the endpoint's hash and owned by the account it
|
|
5
|
+
* subscribed under. The server reads and writes on the owner connection, with
|
|
6
|
+
* the owner named in every statement that acts for a caller. Row-level
|
|
7
|
+
* security is the second wall: the request roles may only read and delete,
|
|
8
|
+
* and only rows whose `user_id` is `rebase.uid()`, so SQL run as a caller
|
|
9
|
+
* (`getSql`) sees that caller's browsers and nobody else's.
|
|
10
|
+
*/
|
|
11
|
+
import type { PushSubscriptionInfo, PushTarget } from "@rebasepro/types";
|
|
12
|
+
export declare const PUSH_SUBSCRIPTIONS_TABLE = "rebase.push_subscriptions";
|
|
13
|
+
/** The driver's SQL, on the owner connection. */
|
|
14
|
+
export type PushExec = (sql: string, params?: unknown[]) => Promise<Record<string, unknown>[]>;
|
|
15
|
+
/** A stored subscription: what a sender needs and what application code sees. */
|
|
16
|
+
export interface StoredPushSubscription extends PushTarget {
|
|
17
|
+
info: PushSubscriptionInfo;
|
|
18
|
+
}
|
|
19
|
+
export interface PushStore {
|
|
20
|
+
/** Create the table, its index and its policies. */
|
|
21
|
+
ensure(): Promise<void>;
|
|
22
|
+
/** Check the table is there, for a backend that changes nothing in its database. */
|
|
23
|
+
adopt(): Promise<void>;
|
|
24
|
+
/**
|
|
25
|
+
* Insert or take over the row for this endpoint. A browser that signs in to
|
|
26
|
+
* another account moves to it, and starts again as a new subscription.
|
|
27
|
+
*/
|
|
28
|
+
upsert(row: {
|
|
29
|
+
id: string;
|
|
30
|
+
userId: string;
|
|
31
|
+
endpoint: string;
|
|
32
|
+
p256dh: string;
|
|
33
|
+
auth: string;
|
|
34
|
+
lang: string | null;
|
|
35
|
+
userAgent: string | null;
|
|
36
|
+
}): Promise<void>;
|
|
37
|
+
/** Delete the caller's row for this id. `false` when there was none of theirs. */
|
|
38
|
+
removeOwn(id: string, userId: string): Promise<boolean>;
|
|
39
|
+
/** Delete a row the push service said is gone, unless it was re-subscribed with new keys meanwhile. */
|
|
40
|
+
removeGone(id: string, p256dh: string): Promise<void>;
|
|
41
|
+
listForUser(userId: string): Promise<StoredPushSubscription[]>;
|
|
42
|
+
listByIds(ids: readonly string[]): Promise<StoredPushSubscription[]>;
|
|
43
|
+
markSent(ids: readonly string[]): Promise<void>;
|
|
44
|
+
}
|
|
45
|
+
export declare function createPushStore(exec: PushExec): PushStore;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { type DataDriver, type PushService } from "@rebasepro/types";
|
|
2
|
+
import type { PushOptions } from "./push-options.js";
|
|
3
|
+
import { type PushStore } from "./push-store.js";
|
|
4
|
+
/** What boot gets back: `rebase.push`, and the store the routes write to when push can send. */
|
|
5
|
+
export interface PushSetUp {
|
|
6
|
+
/** Whether `push` was switched on at all. Off, no routes are mounted. */
|
|
7
|
+
enabled: boolean;
|
|
8
|
+
service: PushService;
|
|
9
|
+
store?: PushStore;
|
|
10
|
+
/** Why push cannot send, when it cannot. */
|
|
11
|
+
reason?: string;
|
|
12
|
+
allowedHosts: string[];
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Turn `push` in the backend options into `rebase.push`: resolve the keys,
|
|
16
|
+
* create (or, without provisioning, check) the table, and build the service.
|
|
17
|
+
* Never throws: a backend that cannot push still serves everything else, and
|
|
18
|
+
* the reason is logged once and carried by every refusal.
|
|
19
|
+
*/
|
|
20
|
+
export declare function setUpPush(input: {
|
|
21
|
+
push: boolean | PushOptions | undefined;
|
|
22
|
+
driver: DataDriver;
|
|
23
|
+
provision: boolean;
|
|
24
|
+
env?: Record<string, string | undefined>;
|
|
25
|
+
}): Promise<PushSetUp>;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The push services of Chrome and Android (FCM), Firefox (Mozilla autopush),
|
|
3
|
+
* Safari on iOS, iPadOS and macOS (Apple), and Edge (Windows Push Notification
|
|
4
|
+
* Services).
|
|
5
|
+
*/
|
|
6
|
+
export declare const PUSH_SERVICE_HOSTS: readonly RegExp[];
|
|
7
|
+
/**
|
|
8
|
+
* The endpoint, normalised, when it is on a known push service or one of
|
|
9
|
+
* `extraHosts` (exact hostnames; these may name a port, for a local test push
|
|
10
|
+
* service). `null` otherwise.
|
|
11
|
+
*/
|
|
12
|
+
export declare function acceptEndpoint(value: unknown, extraHosts?: readonly string[]): string | null;
|
|
13
|
+
/** The browser's P-256 public key: base64url of an uncompressed point. */
|
|
14
|
+
export declare function acceptP256dh(value: unknown): string | null;
|
|
15
|
+
/** The browser's auth secret: base64url of 16 bytes. */
|
|
16
|
+
export declare function acceptAuthSecret(value: unknown): string | null;
|
|
17
|
+
/** A BCP 47-ish language tag (`en`, `es`, `pt-BR`), or `null`. */
|
|
18
|
+
export declare function acceptLang(value: unknown): string | null;
|
|
19
|
+
/**
|
|
20
|
+
* A subscription's id: the first 24 characters of the endpoint's SHA-256, in
|
|
21
|
+
* base64url. Endpoints are hundreds of characters, and the id is what an
|
|
22
|
+
* application keys its own per-browser rows by.
|
|
23
|
+
*/
|
|
24
|
+
export declare function subscriptionIdOf(endpoint: string): string;
|
|
25
|
+
/** A topic the push services take: up to 32 URL-safe base64 characters. */
|
|
26
|
+
export declare function isValidTopic(topic: string): boolean;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Where the VAPID keys come from.
|
|
3
|
+
*
|
|
4
|
+
* In order: `push.vapid` in the backend options, then `REBASE_VAPID_PUBLIC_KEY`
|
|
5
|
+
* and `REBASE_VAPID_PRIVATE_KEY`. Outside production, with neither, a pair is
|
|
6
|
+
* generated once and kept in `.rebase-dev-secrets.json` beside the other
|
|
7
|
+
* development secrets — kept, because a browser's subscription is bound to the
|
|
8
|
+
* public key it subscribed with, and a new key on every restart would silently
|
|
9
|
+
* orphan every subscription made before it. In production nothing is generated:
|
|
10
|
+
* a production key is one an operator can rotate and back up, so push stays
|
|
11
|
+
* off and says which variables to set.
|
|
12
|
+
*/
|
|
13
|
+
import type { DevSecretStore } from "../dev-secrets.js";
|
|
14
|
+
import { type VapidKeys } from "./web-push-crypto.js";
|
|
15
|
+
export declare const VAPID_PUBLIC_ENV = "REBASE_VAPID_PUBLIC_KEY";
|
|
16
|
+
export declare const VAPID_PRIVATE_ENV = "REBASE_VAPID_PRIVATE_KEY";
|
|
17
|
+
export declare const VAPID_SUBJECT_ENV = "REBASE_VAPID_SUBJECT";
|
|
18
|
+
export type VapidResolution = {
|
|
19
|
+
ok: true;
|
|
20
|
+
keys: VapidKeys;
|
|
21
|
+
subject: string;
|
|
22
|
+
source: "options" | "env" | "dev";
|
|
23
|
+
} | {
|
|
24
|
+
ok: false;
|
|
25
|
+
reason: string;
|
|
26
|
+
};
|
|
27
|
+
export declare function resolveVapid(input: {
|
|
28
|
+
vapid?: Partial<VapidKeys> & {
|
|
29
|
+
subject?: string;
|
|
30
|
+
};
|
|
31
|
+
env: Record<string, string | undefined>;
|
|
32
|
+
isProduction: boolean;
|
|
33
|
+
/** The development secret cache, or undefined where none may be written (production, tests). */
|
|
34
|
+
devStore?: DevSecretStore;
|
|
35
|
+
}): VapidResolution;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/** A VAPID key pair, both halves base64url as `web-push generate-vapid-keys` prints them. */
|
|
2
|
+
export interface VapidKeys {
|
|
3
|
+
/** The uncompressed P-256 point, 65 bytes. Browsers subscribe with it. */
|
|
4
|
+
publicKey: string;
|
|
5
|
+
/** The private scalar, 32 bytes. */
|
|
6
|
+
privateKey: string;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* The largest plaintext one record can carry: the record size less the header,
|
|
10
|
+
* the tag and the one-byte delimiter. Push services refuse bodies over 4096
|
|
11
|
+
* bytes, so this is also the practical limit.
|
|
12
|
+
*/
|
|
13
|
+
export declare const MAX_PAYLOAD_BYTES: number;
|
|
14
|
+
export declare function toBase64Url(bytes: Uint8Array): string;
|
|
15
|
+
/** Decode base64url, tolerating standard base64 and `=` padding, as browsers and libraries vary. */
|
|
16
|
+
export declare function fromBase64Url(text: string): Buffer;
|
|
17
|
+
/** A new VAPID key pair. */
|
|
18
|
+
export declare function generateVapidKeys(): VapidKeys;
|
|
19
|
+
/**
|
|
20
|
+
* Whether a key pair is well formed and its halves belong together. Checked at
|
|
21
|
+
* boot, because a mismatched pair is accepted by every push service at
|
|
22
|
+
* subscribe time and refused at every send.
|
|
23
|
+
*/
|
|
24
|
+
export declare function validateVapidKeys(keys: VapidKeys): string | null;
|
|
25
|
+
/**
|
|
26
|
+
* The `Authorization` header for one push service: `vapid t=<jwt>, k=<key>`.
|
|
27
|
+
*
|
|
28
|
+
* `aud` is the push service's origin and `exp` is at most 24 hours ahead (the
|
|
29
|
+
* RFC's ceiling); twelve leaves room for clock skew.
|
|
30
|
+
*/
|
|
31
|
+
export declare function vapidAuthorization(endpoint: string, keys: VapidKeys, subject: string, now?: Date): string;
|
|
32
|
+
/** Fixed inputs, for reproducing the RFC's example. Never set in production. */
|
|
33
|
+
export interface EncryptionFixture {
|
|
34
|
+
salt: Buffer;
|
|
35
|
+
/** The sender's ephemeral private key. */
|
|
36
|
+
senderPrivateKey: Buffer;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Encrypt `plaintext` to one browser: the `aes128gcm` body, header included.
|
|
40
|
+
*
|
|
41
|
+
* Throws when the plaintext does not fit in one record — the caller's payload
|
|
42
|
+
* is too big for Web Push and nothing can deliver it.
|
|
43
|
+
*/
|
|
44
|
+
export declare function encryptPayload(plaintext: Buffer, p256dh: string, auth: string, fixture?: EncryptionFixture): Buffer;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { PushSender } from "@rebasepro/types";
|
|
2
|
+
import { type VapidKeys } from "./web-push-crypto.js";
|
|
3
|
+
/**
|
|
4
|
+
* The default {@link PushSender}: signs with this backend's VAPID keys,
|
|
5
|
+
* encrypts to the browser's key and posts the message with `fetch`.
|
|
6
|
+
*
|
|
7
|
+
* Redirects are not followed. A push service answers a message itself, and
|
|
8
|
+
* following a `Location` would let an allowed host send this server anywhere.
|
|
9
|
+
*/
|
|
10
|
+
export declare function createWebPushSender(keys: VapidKeys, subject: string): PushSender;
|
|
@@ -2,11 +2,11 @@ import { createRequire as __rebaseCreateRequire } from "module";
|
|
|
2
2
|
import __rebaseProcess from "process";
|
|
3
3
|
globalThis.process ??= __rebaseProcess;
|
|
4
4
|
__rebaseCreateRequire(import.meta.url);
|
|
5
|
-
import { A as isTimeZoneName, B as resolveClientListLimit, D as aggregateAlias, E as FIELDLESS_AGGREGATES,
|
|
6
|
-
import { n as apiHiddenKeys, t as UNSERVED_TABLE, u as restrictedKeys } from "./access-
|
|
7
|
-
import { d as IncludeSpecError, f as deserializeInclude, g as OrderBySpecError, i as deserializeLogicalCondition, m as normalizeInclude, n as UnknownFilterOperatorError, r as deserializeFilter, s as PAGE_WITH_OFFSET_MESSAGE, t as RESERVED_QUERY_KEYS } from "./filter-dialect-
|
|
8
|
-
import { t as ApiError } from "./errors-
|
|
9
|
-
import { i as parseWithDeleted, t as DELETED_QUERY_PARAM } from "./soft-delete-params-
|
|
5
|
+
import { A as isTimeZoneName, An as parseRelationAggregateSort, B as resolveClientListLimit, D as aggregateAlias, E as FIELDLESS_AGGREGATES, O as aggregateGroupKey, R as ListLimitError, T as AGGREGATE_GROUP_TRANSFORMS, k as isPercentileFraction, kn as parseCaseFoldedFieldPath, w as AGGREGATE_FUNCTIONS } from "./src-CNZB3fuE.js";
|
|
6
|
+
import { n as apiHiddenKeys, t as UNSERVED_TABLE, u as restrictedKeys } from "./access-D1CTJSLK.js";
|
|
7
|
+
import { d as IncludeSpecError, f as deserializeInclude, g as OrderBySpecError, i as deserializeLogicalCondition, m as normalizeInclude, n as UnknownFilterOperatorError, r as deserializeFilter, s as PAGE_WITH_OFFSET_MESSAGE, t as RESERVED_QUERY_KEYS } from "./filter-dialect-XtPJOCbD.js";
|
|
8
|
+
import { t as ApiError } from "./errors-NVbAQU25.js";
|
|
9
|
+
import { i as parseWithDeleted, t as DELETED_QUERY_PARAM } from "./soft-delete-params-Dhn0qKFv.js";
|
|
10
10
|
//#region ../common/src/collections/unknown-field.ts
|
|
11
11
|
var validList = (validFields) => validFields.length > 0 ? `. Valid fields: ${validFields.join(", ")}` : "";
|
|
12
12
|
/** A filter key that resolves to nothing on `collectionPath`. */
|
|
@@ -1211,4 +1211,4 @@ function parseQueryOptions(query, limits = {}, access) {
|
|
|
1211
1211
|
//#endregion
|
|
1212
1212
|
export { parseWriteFilter as a, assertQueryFieldsReadable as c, relationOf as d, relationsOfKind as f, reconcileCursorOrder as h, parseQueryOptions as i, assertReadableFields as l, decodeCursor as m, parseAggregateSelect as n, resolveListLimitParam as o, cursorToStartAfter as p, parseGroupBy as r, assertNoHiddenAggregateNames as s, orderByEntriesToTuples as t, requestViewer as u };
|
|
1213
1213
|
|
|
1214
|
-
//# sourceMappingURL=query-parser-
|
|
1214
|
+
//# sourceMappingURL=query-parser-Cd70kZO8.js.map
|