@rexezuge/tooling 1.3.0 → 1.4.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.
Files changed (128) hide show
  1. package/dist/eslint-boundaries.d.ts +12 -4
  2. package/dist/eslint-boundaries.d.ts.map +1 -1
  3. package/dist/eslint-boundaries.js +1 -224
  4. package/dist/eslint-boundaries.js.map +7 -1
  5. package/dist/eslint-rules.js +1 -273
  6. package/dist/eslint-rules.js.map +7 -1
  7. package/dist/eslint.js +1 -194
  8. package/dist/eslint.js.map +7 -1
  9. package/dist/functions/pages-proxy.d.ts.map +1 -1
  10. package/dist/functions/pages-proxy.js +1 -131
  11. package/dist/functions/pages-proxy.js.map +7 -1
  12. package/dist/index.js +1 -31
  13. package/dist/index.js.map +7 -1
  14. package/dist/scripts/backup/d1-target.d.ts +15 -5
  15. package/dist/scripts/backup/d1-target.d.ts.map +1 -1
  16. package/dist/scripts/backup/d1-target.js +1 -31
  17. package/dist/scripts/backup/d1-target.js.map +7 -1
  18. package/dist/scripts/backup/destination-config.d.ts +24 -8
  19. package/dist/scripts/backup/destination-config.d.ts.map +1 -1
  20. package/dist/scripts/backup/destination-config.js +1 -57
  21. package/dist/scripts/backup/destination-config.js.map +7 -1
  22. package/dist/scripts/backup/encrypt-backup.js +2 -97
  23. package/dist/scripts/backup/encrypt-backup.js.map +7 -1
  24. package/dist/scripts/backup/naming.d.ts +3 -1
  25. package/dist/scripts/backup/naming.d.ts.map +1 -1
  26. package/dist/scripts/backup/naming.js +1 -58
  27. package/dist/scripts/backup/naming.js.map +7 -1
  28. package/dist/scripts/check-god-files.d.ts +40 -14
  29. package/dist/scripts/check-god-files.d.ts.map +1 -1
  30. package/dist/scripts/check-god-files.js +2 -271
  31. package/dist/scripts/check-god-files.js.map +7 -1
  32. package/dist/scripts/ensure-spa-shell-stub.js +1 -29
  33. package/dist/scripts/ensure-spa-shell-stub.js.map +7 -1
  34. package/dist/scripts/init-secrets.d.ts +0 -16
  35. package/dist/scripts/init-secrets.d.ts.map +1 -1
  36. package/dist/scripts/init-secrets.js +2 -239
  37. package/dist/scripts/init-secrets.js.map +7 -1
  38. package/dist/scripts/lib/cli-args.d.ts.map +1 -1
  39. package/dist/scripts/lib/cli-args.js +1 -116
  40. package/dist/scripts/lib/cli-args.js.map +7 -1
  41. package/dist/scripts/lib/github-actions.js +3 -38
  42. package/dist/scripts/lib/github-actions.js.map +7 -1
  43. package/dist/scripts/lib/wrangler-table.d.ts.map +1 -1
  44. package/dist/scripts/lib/wrangler-table.js +2 -99
  45. package/dist/scripts/lib/wrangler-table.js.map +7 -1
  46. package/dist/scripts/migrations-lock.js +1 -44
  47. package/dist/scripts/migrations-lock.js.map +7 -1
  48. package/dist/scripts/prepare-wrangler-config.js +1 -49
  49. package/dist/scripts/prepare-wrangler-config.js.map +7 -1
  50. package/dist/scripts/spa-shell.d.ts +12 -4
  51. package/dist/scripts/spa-shell.d.ts.map +1 -1
  52. package/dist/scripts/spa-shell.js +3 -160
  53. package/dist/scripts/spa-shell.js.map +7 -1
  54. package/dist/scripts/validate-locales.d.ts +13 -5
  55. package/dist/scripts/validate-locales.d.ts.map +1 -1
  56. package/dist/scripts/validate-locales.js +4 -350
  57. package/dist/scripts/validate-locales.js.map +7 -1
  58. package/dist/scripts/verify-migrations.d.ts +27 -9
  59. package/dist/scripts/verify-migrations.d.ts.map +1 -1
  60. package/dist/scripts/verify-migrations.js +2 -312
  61. package/dist/scripts/verify-migrations.js.map +7 -1
  62. package/dist/scripts/verify-spa-shell.js +1 -52
  63. package/dist/scripts/verify-spa-shell.js.map +7 -1
  64. package/dist/scripts/wrangler-config/cli.js +3 -51
  65. package/dist/scripts/wrangler-config/cli.js.map +7 -1
  66. package/dist/scripts/wrangler-config/patches.d.ts +9 -3
  67. package/dist/scripts/wrangler-config/patches.d.ts.map +1 -1
  68. package/dist/scripts/wrangler-config/patches.js +4 -141
  69. package/dist/scripts/wrangler-config/patches.js.map +7 -1
  70. package/dist/scripts/wrangler-config/resources.d.ts +18 -6
  71. package/dist/scripts/wrangler-config/resources.d.ts.map +1 -1
  72. package/dist/scripts/wrangler-config/resources.js +1 -290
  73. package/dist/scripts/wrangler-config/resources.js.map +7 -1
  74. package/dist/scripts/wrangler-config/types.d.ts +24 -8
  75. package/dist/scripts/wrangler-config/types.d.ts.map +1 -1
  76. package/dist/scripts/wrangler-config/types.js +1 -49
  77. package/dist/scripts/wrangler-config/types.js.map +7 -1
  78. package/dist/test/integration-migrations.d.ts +29 -12
  79. package/dist/test/integration-migrations.d.ts.map +1 -1
  80. package/dist/test/integration-migrations.js +2 -171
  81. package/dist/test/integration-migrations.js.map +7 -1
  82. package/dist/test/mocks/cloudflare-workers.js +1 -90
  83. package/dist/test/mocks/cloudflare-workers.js.map +7 -1
  84. package/dist/vite.d.ts +5 -3
  85. package/dist/vite.d.ts.map +1 -1
  86. package/dist/vite.js +3 -125
  87. package/dist/vite.js.map +7 -1
  88. package/dist/vitest-aliases.d.ts.map +1 -1
  89. package/dist/vitest-aliases.js +1 -81
  90. package/dist/vitest-aliases.js.map +7 -1
  91. package/dist/vitest-integration.js +1 -64
  92. package/dist/vitest-integration.js.map +7 -1
  93. package/dist/vitest-repo.js +1 -146
  94. package/dist/vitest-repo.js.map +7 -1
  95. package/dist/vitest-web.js +1 -109
  96. package/dist/vitest-web.js.map +7 -1
  97. package/dist/vitest.js +1 -133
  98. package/dist/vitest.js.map +7 -1
  99. package/package.json +3 -3
  100. package/src/eslint-boundaries.ts +13 -5
  101. package/src/eslint.test.ts +18 -8
  102. package/src/functions/pages-proxy.test.ts +1 -1
  103. package/src/functions/pages-proxy.ts +4 -2
  104. package/src/scripts/backup/backup-rules.test.ts +1 -1
  105. package/src/scripts/backup/d1-target.ts +15 -5
  106. package/src/scripts/backup/destination-config.ts +27 -9
  107. package/src/scripts/backup/encrypt-backup.ts +10 -8
  108. package/src/scripts/backup/naming.ts +3 -1
  109. package/src/scripts/check-god-files.test.ts +18 -18
  110. package/src/scripts/check-god-files.ts +60 -31
  111. package/src/scripts/init-secrets.ts +17 -7
  112. package/src/scripts/lib/cli-args.ts +6 -3
  113. package/src/scripts/lib/wrangler-table.ts +5 -3
  114. package/src/scripts/migrations-lock.ts +1 -1
  115. package/src/scripts/spa-shell.test.ts +17 -17
  116. package/src/scripts/spa-shell.ts +26 -14
  117. package/src/scripts/validate-locales.test.ts +17 -17
  118. package/src/scripts/validate-locales.ts +43 -25
  119. package/src/scripts/verify-migrations.test.ts +7 -7
  120. package/src/scripts/verify-migrations.ts +47 -24
  121. package/src/scripts/wrangler-config/patches.ts +12 -4
  122. package/src/scripts/wrangler-config/resources.ts +30 -14
  123. package/src/scripts/wrangler-config/types.ts +24 -8
  124. package/src/test/integration-migrations.test.ts +6 -6
  125. package/src/test/integration-migrations.ts +33 -14
  126. package/src/vite.test.ts +24 -13
  127. package/src/vite.ts +5 -5
  128. package/src/vitest-aliases.ts +1 -3
package/dist/index.js.map CHANGED
@@ -1 +1,7 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAGnD,OAAO,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AAGrD,OAAO,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AAGxD,OAAO,EAAE,sBAAsB,EAAE,MAAM,kBAAkB,CAAC;AAG1D,OAAO,EAAE,6BAA6B,EAAE,MAAM,yBAAyB,CAAC;AAGxE,OAAO,EAAE,wBAAwB,EAAE,0BAA0B,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAG9H,OAAO,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AAGrE,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAG9D,6EAA6E;AAC7E,EAAE;AACF,kFAAkF;AAClF,mCAAmC;AAEnC,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,kBAAkB,EAAE,MAAM,oCAAoC,CAAC;AAGlG,OAAO,EAAE,qBAAqB,EAAE,kBAAkB,EAAE,QAAQ,EAAE,MAAM,kCAAkC,CAAC","sourcesContent":["/**\n * `@rexezuge/tooling` — the tooling layer of the kit.\n *\n * The config factories and the test helpers are re-exported here, so a consumer has\n * one import for everything its `*.config.mts` files and its mocks need. The\n * scripts under `scripts/` are **not** re-exported: they resolve paths relative to\n * the repository they run in, so they are run from disk with `tsx`, not imported.\n * See `README.md` for the copy-in recipe and the per-script usage.\n *\n * The zero-dependency rule: nothing here imports another `@rexezuge/*` package. The\n * one exception in the tree is `scripts/backup/encrypt-backup.ts`, which uses\n * `@rexezuge/d1`'s AES-GCM so the backup and the workers share one definition of\n * \"what an encryption key looks like\"; that dependency is declared on the package\n * and is only ever resolved in the consumer's repo, where the kit is installed\n * alongside `@rexezuge/d1`.\n */\n\nexport { defineRepoLintConfig } from './eslint.ts';\nexport type { RepoLintConfigOptions } from './eslint.ts';\n\nexport { defineUnitVitestConfig } from './vitest.ts';\nexport type { CoverageThresholds, UnitVitestConfigOptions, VitestAlias } from './vitest.ts';\n\nexport { defineWebVitestConfig } from './vitest-web.ts';\nexport type { WebVitestConfigOptions } from './vitest-web.ts';\n\nexport { defineRepoVitestConfig } from './vitest-repo.ts';\nexport type { RepoBackendOptions, RepoVitestConfigOptions, RepoWebOptions } from './vitest-repo.ts';\n\nexport { defineIntegrationVitestConfig } from './vitest-integration.ts';\nexport type { IntegrationVitestConfigOptions } from './vitest-integration.ts';\n\nexport { DEFAULT_CLOUDFLARE_MOCKS, DEFAULT_WORKSPACE_PACKAGES, KIT_NO_EXTERNAL, workspaceAliases } from './vitest-aliases.ts';\nexport type { VitestAlias as WorkspaceAlias, WorkspaceAliasesOptions } from './vitest-aliases.ts';\n\nexport { defineWebViteConfig, spaShellEmbedPlugin } from './vite.ts';\nexport type { ProxyEntry, SpaShellTarget, WebViteConfigOptions } from './vite.ts';\n\nexport { createPagesProxy } from './functions/pages-proxy.ts';\nexport type { Fetcher, PagesFunction, PagesFunctionContext, PagesProxyEnv, PagesProxyOptions } from './functions/pages-proxy.ts';\n\n// --- Test helpers ---------------------------------------------------------\n//\n// Aliased in a Vitest config, not imported by application code, so the mocks stay\n// where the suites can reach them.\n\nexport { DurableObject, RpcTarget, WorkflowEntrypoint } from './test/mocks/cloudflare-workers.ts';\nexport type { DurableObjectState, ExecutionContext } from './test/mocks/cloudflare-workers.ts';\n\nexport { createMigrationHelper, readMigrationFiles, splitSql } from './test/integration-migrations.ts';\nexport type {\n D1DatabaseLike,\n D1PreparedStatementLike,\n MigrationFile,\n MigrationHelper,\n MigrationHelperOptions,\n MigrationRange,\n} from './test/integration-migrations.ts';\n"]}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/index.ts"],
4
+ "sourcesContent": ["/**\n * `@rexezuge/tooling` — the tooling layer of the kit.\n *\n * The config factories and the test helpers are re-exported here, so a consumer has\n * one import for everything its `*.config.mts` files and its mocks need. The\n * scripts under `scripts/` are **not** re-exported: they resolve paths relative to\n * the repository they run in, so they are run from disk with `tsx`, not imported.\n * See `README.md` for the copy-in recipe and the per-script usage.\n *\n * The zero-dependency rule: nothing here imports another `@rexezuge/*` package. The\n * one exception in the tree is `scripts/backup/encrypt-backup.ts`, which uses\n * `@rexezuge/d1`'s AES-GCM so the backup and the workers share one definition of\n * \"what an encryption key looks like\"; that dependency is declared on the package\n * and is only ever resolved in the consumer's repo, where the kit is installed\n * alongside `@rexezuge/d1`.\n */\n\nexport { defineRepoLintConfig } from './eslint.ts';\nexport type { RepoLintConfigOptions } from './eslint.ts';\n\nexport { defineUnitVitestConfig } from './vitest.ts';\nexport type { CoverageThresholds, UnitVitestConfigOptions, VitestAlias } from './vitest.ts';\n\nexport { defineWebVitestConfig } from './vitest-web.ts';\nexport type { WebVitestConfigOptions } from './vitest-web.ts';\n\nexport { defineRepoVitestConfig } from './vitest-repo.ts';\nexport type { RepoBackendOptions, RepoVitestConfigOptions, RepoWebOptions } from './vitest-repo.ts';\n\nexport { defineIntegrationVitestConfig } from './vitest-integration.ts';\nexport type { IntegrationVitestConfigOptions } from './vitest-integration.ts';\n\nexport { DEFAULT_CLOUDFLARE_MOCKS, DEFAULT_WORKSPACE_PACKAGES, KIT_NO_EXTERNAL, workspaceAliases } from './vitest-aliases.ts';\nexport type { VitestAlias as WorkspaceAlias, WorkspaceAliasesOptions } from './vitest-aliases.ts';\n\nexport { defineWebViteConfig, spaShellEmbedPlugin } from './vite.ts';\nexport type { ProxyEntry, SpaShellTarget, WebViteConfigOptions } from './vite.ts';\n\nexport { createPagesProxy } from './functions/pages-proxy.ts';\nexport type { Fetcher, PagesFunction, PagesFunctionContext, PagesProxyEnv, PagesProxyOptions } from './functions/pages-proxy.ts';\n\n// --- Test helpers ---------------------------------------------------------\n//\n// Aliased in a Vitest config, not imported by application code, so the mocks stay\n// where the suites can reach them.\n\nexport { DurableObject, RpcTarget, WorkflowEntrypoint } from './test/mocks/cloudflare-workers.ts';\nexport type { DurableObjectState, ExecutionContext } from './test/mocks/cloudflare-workers.ts';\n\nexport { createMigrationHelper, readMigrationFiles, splitSql } from './test/integration-migrations.ts';\nexport type {\n D1DatabaseLike,\n D1PreparedStatementLike,\n MigrationFile,\n MigrationHelper,\n MigrationHelperOptions,\n MigrationRange,\n} from './test/integration-migrations.ts';\n"],
5
+ "mappings": "AAiBA,OAAS,wBAAAA,MAA4B,cAGrC,OAAS,0BAAAC,MAA8B,cAGvC,OAAS,yBAAAC,MAA6B,kBAGtC,OAAS,0BAAAC,MAA8B,mBAGvC,OAAS,iCAAAC,MAAqC,0BAG9C,OAAS,4BAAAC,EAA0B,8BAAAC,EAA4B,mBAAAC,EAAiB,oBAAAC,MAAwB,sBAGxG,OAAS,uBAAAC,EAAqB,uBAAAC,MAA2B,YAGzD,OAAS,oBAAAC,MAAwB,6BAQjC,OAAS,iBAAAC,EAAe,aAAAC,EAAW,sBAAAC,MAA0B,qCAG7D,OAAS,yBAAAC,EAAuB,sBAAAC,EAAoB,YAAAC,MAAgB",
6
+ "names": ["defineRepoLintConfig", "defineUnitVitestConfig", "defineWebVitestConfig", "defineRepoVitestConfig", "defineIntegrationVitestConfig", "DEFAULT_CLOUDFLARE_MOCKS", "DEFAULT_WORKSPACE_PACKAGES", "KIT_NO_EXTERNAL", "workspaceAliases", "defineWebViteConfig", "spaShellEmbedPlugin", "createPagesProxy", "DurableObject", "RpcTarget", "WorkflowEntrypoint", "createMigrationHelper", "readMigrationFiles", "splitSql"]
7
+ }
@@ -5,19 +5,29 @@
5
5
  * empty-database guard is asserted without running Actions or touching a real
6
6
  * account.
7
7
  */
8
- /** A D1 binding as a parsed wrangler config carries one. */
8
+ /**
9
+ A D1 binding as a parsed wrangler config carries one.
10
+ */
9
11
  export interface D1DatabaseBinding {
10
12
  binding?: string;
11
13
  database_id?: string;
12
14
  database_name?: string;
13
15
  }
14
- /** The resolved export target. */
16
+ /**
17
+ The resolved export target.
18
+ */
15
19
  export interface D1Target {
16
- /** The binding name, used for log output and as the export fallback. */
20
+ /**
21
+ The binding name, used for log output and as the export fallback.
22
+ */
17
23
  binding: string;
18
- /** The database id, verified against Cloudflare by the caller. */
24
+ /**
25
+ The database id, verified against Cloudflare by the caller.
26
+ */
19
27
  databaseId: string;
20
- /** What `wrangler d1 export` should be pointed at. */
28
+ /**
29
+ What `wrangler d1 export` should be pointed at.
30
+ */
21
31
  target: string;
22
32
  }
23
33
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"d1-target.d.ts","sourceRoot":"","sources":["../../../src/scripts/backup/d1-target.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH,4DAA4D;AAC5D,MAAM,WAAW,iBAAiB;IAChC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,kCAAkC;AAClC,MAAM,WAAW,QAAQ;IACvB,wEAAwE;IACxE,OAAO,EAAE,MAAM,CAAC;IAChB,kEAAkE;IAClE,UAAU,EAAE,MAAM,CAAC;IACnB,sDAAsD;IACtD,MAAM,EAAE,MAAM,CAAC;CAChB;AAED;;;;;;;;GAQG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE;IAAE,YAAY,CAAC,EAAE,iBAAiB,EAAE,CAAA;CAAE,GAAG,QAAQ,CAiBxF"}
1
+ {"version":3,"file":"d1-target.d.ts","sourceRoot":"","sources":["../../../src/scripts/backup/d1-target.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH;;EAEE;AACF,MAAM,WAAW,iBAAiB;IAChC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED;;EAEE;AACF,MAAM,WAAW,QAAQ;IACvB;;MAEE;IACF,OAAO,EAAE,MAAM,CAAC;IAChB;;MAEE;IACF,UAAU,EAAE,MAAM,CAAC;IACnB;;MAEE;IACF,MAAM,EAAE,MAAM,CAAC;CAChB;AAED;;;;;;;;GAQG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE;IAAE,YAAY,CAAC,EAAE,iBAAiB,EAAE,CAAA;CAAE,GAAG,QAAQ,CAiBxF"}
@@ -1,31 +1 @@
1
- /**
2
- * Choosing which D1 database the backup workflow exports.
3
- *
4
- * Provenance: ported from Edge-Sonic's `scripts/backup/d1-target.ts`. Pure, so the
5
- * empty-database guard is asserted without running Actions or touching a real
6
- * account.
7
- */
8
- import { DEFAULT_UUID } from "../wrangler-config/types.js";
9
- /**
10
- * Pick the export target from a parsed wrangler config.
11
- *
12
- * `wrangler d1 export` takes a database *name*, so `database_name` wins when
13
- * present. Hand-written configs that omit it fall back to the binding name.
14
- *
15
- * @throws when there is no binding, or when `database_id` is still the template
16
- * placeholder — meaning the database was auto-provisioned and holds no data.
17
- */
18
- export function resolveD1Target(config) {
19
- const database = config.d1_databases?.[0];
20
- const binding = database?.binding?.trim();
21
- if (binding === undefined || binding === '') {
22
- throw new Error('No d1_databases entry with a binding found in wrangler.jsonc.');
23
- }
24
- const databaseId = database?.database_id?.trim() ?? '';
25
- if (databaseId === DEFAULT_UUID) {
26
- throw new Error(`D1 database_id for ${binding} is still the template placeholder. The database does not exist yet, so there is nothing to back up.`);
27
- }
28
- const target = database?.database_name?.trim() || binding;
29
- return { binding, databaseId, target };
30
- }
31
- //# sourceMappingURL=d1-target.js.map
1
+ import{DEFAULT_UUID as i}from"../wrangler-config/types.js";function s(n){const a=n.d1_databases?.[0],t=a?.binding?.trim();if(t===void 0||t==="")throw new Error("No d1_databases entry with a binding found in wrangler.jsonc.");const e=a?.database_id?.trim()??"";if(e===i)throw new Error(`D1 database_id for ${t} is still the template placeholder. The database does not exist yet, so there is nothing to back up.`);const r=a?.database_name?.trim()||t;return{binding:t,databaseId:e,target:r}}export{s as resolveD1Target};
@@ -1 +1,7 @@
1
- {"version":3,"file":"d1-target.js","sourceRoot":"","sources":["../../../src/scripts/backup/d1-target.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAmB3D;;;;;;;;GAQG;AACH,MAAM,UAAU,eAAe,CAAC,MAA8C;IAC5E,MAAM,QAAQ,GAAG,MAAM,CAAC,YAAY,EAAE,CAAC,CAAC,CAAC,CAAC;IAE1C,MAAM,OAAO,GAAG,QAAQ,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;IAC1C,IAAI,OAAO,KAAK,SAAS,IAAI,OAAO,KAAK,EAAE,EAAE,CAAC;QAC5C,MAAM,IAAI,KAAK,CAAC,+DAA+D,CAAC,CAAC;IACnF,CAAC;IAED,MAAM,UAAU,GAAG,QAAQ,EAAE,WAAW,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;IACvD,IAAI,UAAU,KAAK,YAAY,EAAE,CAAC;QAChC,MAAM,IAAI,KAAK,CACb,sBAAsB,OAAO,sGAAsG,CACpI,CAAC;IACJ,CAAC;IAED,MAAM,MAAM,GAAG,QAAQ,EAAE,aAAa,EAAE,IAAI,EAAE,IAAI,OAAO,CAAC;IAC1D,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,CAAC;AACzC,CAAC","sourcesContent":["/**\n * Choosing which D1 database the backup workflow exports.\n *\n * Provenance: ported from Edge-Sonic's `scripts/backup/d1-target.ts`. Pure, so the\n * empty-database guard is asserted without running Actions or touching a real\n * account.\n */\n\nimport { DEFAULT_UUID } from '../wrangler-config/types.ts';\n\n/** A D1 binding as a parsed wrangler config carries one. */\nexport interface D1DatabaseBinding {\n binding?: string;\n database_id?: string;\n database_name?: string;\n}\n\n/** The resolved export target. */\nexport interface D1Target {\n /** The binding name, used for log output and as the export fallback. */\n binding: string;\n /** The database id, verified against Cloudflare by the caller. */\n databaseId: string;\n /** What `wrangler d1 export` should be pointed at. */\n target: string;\n}\n\n/**\n * Pick the export target from a parsed wrangler config.\n *\n * `wrangler d1 export` takes a database *name*, so `database_name` wins when\n * present. Hand-written configs that omit it fall back to the binding name.\n *\n * @throws when there is no binding, or when `database_id` is still the template\n * placeholder — meaning the database was auto-provisioned and holds no data.\n */\nexport function resolveD1Target(config: { d1_databases?: D1DatabaseBinding[] }): D1Target {\n const database = config.d1_databases?.[0];\n\n const binding = database?.binding?.trim();\n if (binding === undefined || binding === '') {\n throw new Error('No d1_databases entry with a binding found in wrangler.jsonc.');\n }\n\n const databaseId = database?.database_id?.trim() ?? '';\n if (databaseId === DEFAULT_UUID) {\n throw new Error(\n `D1 database_id for ${binding} is still the template placeholder. The database does not exist yet, so there is nothing to back up.`,\n );\n }\n\n const target = database?.database_name?.trim() || binding;\n return { binding, databaseId, target };\n}\n"]}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/scripts/backup/d1-target.ts"],
4
+ "sourcesContent": ["/**\n * Choosing which D1 database the backup workflow exports.\n *\n * Provenance: ported from Edge-Sonic's `scripts/backup/d1-target.ts`. Pure, so the\n * empty-database guard is asserted without running Actions or touching a real\n * account.\n */\n\nimport { DEFAULT_UUID } from '../wrangler-config/types.ts';\n\n/**\nA D1 binding as a parsed wrangler config carries one.\n*/\nexport interface D1DatabaseBinding {\n binding?: string;\n database_id?: string;\n database_name?: string;\n}\n\n/**\nThe resolved export target.\n*/\nexport interface D1Target {\n /**\n The binding name, used for log output and as the export fallback.\n */\n binding: string;\n /**\n The database id, verified against Cloudflare by the caller.\n */\n databaseId: string;\n /**\n What `wrangler d1 export` should be pointed at.\n */\n target: string;\n}\n\n/**\n * Pick the export target from a parsed wrangler config.\n *\n * `wrangler d1 export` takes a database *name*, so `database_name` wins when\n * present. Hand-written configs that omit it fall back to the binding name.\n *\n * @throws when there is no binding, or when `database_id` is still the template\n * placeholder — meaning the database was auto-provisioned and holds no data.\n */\nexport function resolveD1Target(config: { d1_databases?: D1DatabaseBinding[] }): D1Target {\n const database = config.d1_databases?.[0];\n\n const binding = database?.binding?.trim();\n if (binding === undefined || binding === '') {\n throw new Error('No d1_databases entry with a binding found in wrangler.jsonc.');\n }\n\n const databaseId = database?.database_id?.trim() ?? '';\n if (databaseId === DEFAULT_UUID) {\n throw new Error(\n `D1 database_id for ${binding} is still the template placeholder. The database does not exist yet, so there is nothing to back up.`,\n );\n }\n\n const target = database?.database_name?.trim() || binding;\n return { binding, databaseId, target };\n}\n"],
5
+ "mappings": "AAQA,OAAS,gBAAAA,MAAoB,8BAsCvB,SAAUC,EAAgBC,EAA8C,CAC5E,MAAMC,EAAWD,EAAO,eAAe,CAAC,EAElCE,EAAUD,GAAU,SAAS,KAAI,EACvC,GAAIC,IAAY,QAAaA,IAAY,GACvC,MAAM,IAAI,MAAM,+DAA+D,EAGjF,MAAMC,EAAaF,GAAU,aAAa,KAAI,GAAM,GACpD,GAAIE,IAAeL,EACjB,MAAM,IAAI,MACR,sBAAsBI,CAAO,sGAAsG,EAIvI,MAAME,EAASH,GAAU,eAAe,KAAI,GAAMC,EAClD,MAAO,CAAE,QAAAA,EAAS,WAAAC,EAAY,OAAAC,CAAM,CACtC",
6
+ "names": ["DEFAULT_UUID", "resolveD1Target", "config", "database", "binding", "databaseId", "target"]
7
+ }
@@ -5,7 +5,9 @@
5
5
  * Pure and side-effect free, so the fail-closed rules are asserted without running
6
6
  * Actions.
7
7
  */
8
- /** The environment the `check-secrets` job is given, as repository secrets. */
8
+ /**
9
+ The environment the `check-secrets` job is given, as repository secrets.
10
+ */
9
11
  export interface BackupSecretEnvironment {
10
12
  CLOUDFLARE_API_TOKEN?: string;
11
13
  CLOUDFLARE_ACCOUNT_ID?: string;
@@ -17,19 +19,33 @@ export interface BackupSecretEnvironment {
17
19
  WEBDAV_USER?: string;
18
20
  WEBDAV_PASSWORD?: string;
19
21
  }
20
- /** What is configured, and why the run cannot proceed when it is not. */
22
+ /**
23
+ What is configured, and why the run cannot proceed when it is not.
24
+ */
21
25
  export interface DestinationConfig {
22
- /** Cloudflare credentials present, so the export job can run. */
26
+ /**
27
+ Cloudflare credentials present, so the export job can run.
28
+ */
23
29
  cloudflare: boolean;
24
- /** An encryption passphrase is available. */
30
+ /**
31
+ An encryption passphrase is available.
32
+ */
25
33
  encryption: boolean;
26
- /** At least one upload destination is configured. */
34
+ /**
35
+ At least one upload destination is configured.
36
+ */
27
37
  anyDestination: boolean;
28
- /** The S3 destination is fully configured. */
38
+ /**
39
+ The S3 destination is fully configured.
40
+ */
29
41
  s3: boolean;
30
- /** The WebDAV destination is fully configured. */
42
+ /**
43
+ The WebDAV destination is fully configured.
44
+ */
31
45
  webdav: boolean;
32
- /** Human-readable reasons the run cannot proceed, empty when it can. */
46
+ /**
47
+ Human-readable reasons the run cannot proceed, empty when it can.
48
+ */
33
49
  errors: string[];
34
50
  }
35
51
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"destination-config.d.ts","sourceRoot":"","sources":["../../../src/scripts/backup/destination-config.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,+EAA+E;AAC/E,MAAM,WAAW,uBAAuB;IACtC,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAC/B,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAC/B,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED,yEAAyE;AACzE,MAAM,WAAW,iBAAiB;IAChC,iEAAiE;IACjE,UAAU,EAAE,OAAO,CAAC;IACpB,6CAA6C;IAC7C,UAAU,EAAE,OAAO,CAAC;IACpB,qDAAqD;IACrD,cAAc,EAAE,OAAO,CAAC;IACxB,8CAA8C;IAC9C,EAAE,EAAE,OAAO,CAAC;IACZ,kDAAkD;IAClD,MAAM,EAAE,OAAO,CAAC;IAChB,wEAAwE;IACxE,MAAM,EAAE,MAAM,EAAE,CAAC;CAClB;AAOD;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,uBAAuB,GAAG,iBAAiB,CAwB9E"}
1
+ {"version":3,"file":"destination-config.d.ts","sourceRoot":"","sources":["../../../src/scripts/backup/destination-config.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH;;EAEE;AACF,MAAM,WAAW,uBAAuB;IACtC,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAC/B,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAC/B,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED;;EAEE;AACF,MAAM,WAAW,iBAAiB;IAChC;;MAEE;IACF,UAAU,EAAE,OAAO,CAAC;IACpB;;MAEE;IACF,UAAU,EAAE,OAAO,CAAC;IACpB;;MAEE;IACF,cAAc,EAAE,OAAO,CAAC;IACxB;;MAEE;IACF,EAAE,EAAE,OAAO,CAAC;IACZ;;MAEE;IACF,MAAM,EAAE,OAAO,CAAC;IAChB;;MAEE;IACF,MAAM,EAAE,MAAM,EAAE,CAAC;CAClB;AASD;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,uBAAuB,GAAG,iBAAiB,CAwB9E"}
@@ -1,57 +1 @@
1
- /**
2
- * Destination and encryption policy for the D1 backup workflow.
3
- *
4
- * Provenance: ported from Edge-Sonic's `scripts/backup/destination-config.ts`.
5
- * Pure and side-effect free, so the fail-closed rules are asserted without running
6
- * Actions.
7
- */
8
- /** A secret counts as set only when it has non-whitespace content. */
9
- function isSet(value) {
10
- return typeof value === 'string' && value.trim().length > 0;
11
- }
12
- /**
13
- * Decides which destinations are configured and enforces fail-closed encryption.
14
- *
15
- * ### Why the encryption requirement is not optional here
16
- *
17
- * Two independent reasons, and they have different consequences so both are stated.
18
- *
19
- * **The at-rest protection assumes the dump is not in hand.** Every repo in this
20
- * family seals credentials with AES-256-GCM, and each one's migration notes say the
21
- * same thing: *obfuscation against a D1 dump, not protection against a full worker
22
- * compromise.* An unencrypted backup inverts that assumption — dump plus the
23
- * Secrets Store key is a complete credential set, and the WebDAV key is read on
24
- * every scan and every stream.
25
- *
26
- * **The dump is a listening history.** Stars, ratings, play counts, play queues and
27
- * auth failures record what each user does and when, and the schema records the
28
- * full topology and every file path. None of that is credential material, and all
29
- * of it is nobody else's to read.
30
- *
31
- * `S3_REGION` is deliberately not part of the S3 gate. R2 and MinIO have no
32
- * meaningful region — Cloudflare documents an R2 bucket's region as `auto`, with
33
- * empty and `us-east-1` both aliasing to it — so requiring the secret would
34
- * silently disable backups for anyone using such a provider. The upload script
35
- * defaults `AWS_DEFAULT_REGION` to `auto` instead.
36
- */
37
- export function evaluateConfig(env) {
38
- const cloudflare = isSet(env.CLOUDFLARE_API_TOKEN) && isSet(env.CLOUDFLARE_ACCOUNT_ID);
39
- const encryption = isSet(env.BACKUP_ENCRYPTION_KEY);
40
- const s3 = isSet(env.S3_ACCESS_KEY_ID) && isSet(env.S3_SECRET_ACCESS_KEY) && isSet(env.S3_BUCKET);
41
- const webdav = isSet(env.WEBDAV_URL) && isSet(env.WEBDAV_USER) && isSet(env.WEBDAV_PASSWORD);
42
- const anyDestination = s3 || webdav;
43
- const errors = [];
44
- // Fail closed, but only once someone has opted into a destination. An
45
- // unconfigured repository is a legitimate "I do not want off-site backups" state
46
- // and must not turn the schedule red.
47
- if (anyDestination) {
48
- if (!cloudflare) {
49
- errors.push('A backup destination is configured but CLOUDFLARE_API_TOKEN / CLOUDFLARE_ACCOUNT_ID are missing.');
50
- }
51
- if (!encryption) {
52
- errors.push('BACKUP_ENCRYPTION_KEY is required. The D1 dump holds AES-GCM-obfuscated credentials — obfuscation that, by its own design, assumes the dump is not in hand — plus every user history and the full schema topology.');
53
- }
54
- }
55
- return { cloudflare, encryption, anyDestination, s3, webdav, errors };
56
- }
57
- //# sourceMappingURL=destination-config.js.map
1
+ function s(t){return typeof t=="string"&&t.trim().length>0}function r(t){const o=s(t.CLOUDFLARE_API_TOKEN)&&s(t.CLOUDFLARE_ACCOUNT_ID),n=s(t.BACKUP_ENCRYPTION_KEY),E=s(t.S3_ACCESS_KEY_ID)&&s(t.S3_SECRET_ACCESS_KEY)&&s(t.S3_BUCKET),_=s(t.WEBDAV_URL)&&s(t.WEBDAV_USER)&&s(t.WEBDAV_PASSWORD),e=E||_,i=[];return e&&(o||i.push("A backup destination is configured but CLOUDFLARE_API_TOKEN / CLOUDFLARE_ACCOUNT_ID are missing."),n||i.push("BACKUP_ENCRYPTION_KEY is required. The D1 dump holds AES-GCM-obfuscated credentials \u2014 obfuscation that, by its own design, assumes the dump is not in hand \u2014 plus every user history and the full schema topology.")),{cloudflare:o,encryption:n,anyDestination:e,s3:E,webdav:_,errors:i}}export{r as evaluateConfig};
@@ -1 +1,7 @@
1
- {"version":3,"file":"destination-config.js","sourceRoot":"","sources":["../../../src/scripts/backup/destination-config.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AA+BH,sEAAsE;AACtE,SAAS,KAAK,CAAC,KAAyB;IACtC,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,IAAI,EAAE,CAAC,MAAM,GAAG,CAAC,CAAC;AAC9D,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,MAAM,UAAU,cAAc,CAAC,GAA4B;IACzD,MAAM,UAAU,GAAG,KAAK,CAAC,GAAG,CAAC,oBAAoB,CAAC,IAAI,KAAK,CAAC,GAAG,CAAC,qBAAqB,CAAC,CAAC;IACvF,MAAM,UAAU,GAAG,KAAK,CAAC,GAAG,CAAC,qBAAqB,CAAC,CAAC;IACpD,MAAM,EAAE,GAAG,KAAK,CAAC,GAAG,CAAC,gBAAgB,CAAC,IAAI,KAAK,CAAC,GAAG,CAAC,oBAAoB,CAAC,IAAI,KAAK,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;IAClG,MAAM,MAAM,GAAG,KAAK,CAAC,GAAG,CAAC,UAAU,CAAC,IAAI,KAAK,CAAC,GAAG,CAAC,WAAW,CAAC,IAAI,KAAK,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC;IAC7F,MAAM,cAAc,GAAG,EAAE,IAAI,MAAM,CAAC;IAEpC,MAAM,MAAM,GAAa,EAAE,CAAC;IAE5B,sEAAsE;IACtE,iFAAiF;IACjF,sCAAsC;IACtC,IAAI,cAAc,EAAE,CAAC;QACnB,IAAI,CAAC,UAAU,EAAE,CAAC;YAChB,MAAM,CAAC,IAAI,CAAC,kGAAkG,CAAC,CAAC;QAClH,CAAC;QACD,IAAI,CAAC,UAAU,EAAE,CAAC;YAChB,MAAM,CAAC,IAAI,CACT,oNAAoN,CACrN,CAAC;QACJ,CAAC;IACH,CAAC;IAED,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,cAAc,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC;AACxE,CAAC","sourcesContent":["/**\n * Destination and encryption policy for the D1 backup workflow.\n *\n * Provenance: ported from Edge-Sonic's `scripts/backup/destination-config.ts`.\n * Pure and side-effect free, so the fail-closed rules are asserted without running\n * Actions.\n */\n\n/** The environment the `check-secrets` job is given, as repository secrets. */\nexport interface BackupSecretEnvironment {\n CLOUDFLARE_API_TOKEN?: string;\n CLOUDFLARE_ACCOUNT_ID?: string;\n BACKUP_ENCRYPTION_KEY?: string;\n S3_ACCESS_KEY_ID?: string;\n S3_SECRET_ACCESS_KEY?: string;\n S3_BUCKET?: string;\n WEBDAV_URL?: string;\n WEBDAV_USER?: string;\n WEBDAV_PASSWORD?: string;\n}\n\n/** What is configured, and why the run cannot proceed when it is not. */\nexport interface DestinationConfig {\n /** Cloudflare credentials present, so the export job can run. */\n cloudflare: boolean;\n /** An encryption passphrase is available. */\n encryption: boolean;\n /** At least one upload destination is configured. */\n anyDestination: boolean;\n /** The S3 destination is fully configured. */\n s3: boolean;\n /** The WebDAV destination is fully configured. */\n webdav: boolean;\n /** Human-readable reasons the run cannot proceed, empty when it can. */\n errors: string[];\n}\n\n/** A secret counts as set only when it has non-whitespace content. */\nfunction isSet(value: string | undefined): boolean {\n return typeof value === 'string' && value.trim().length > 0;\n}\n\n/**\n * Decides which destinations are configured and enforces fail-closed encryption.\n *\n * ### Why the encryption requirement is not optional here\n *\n * Two independent reasons, and they have different consequences so both are stated.\n *\n * **The at-rest protection assumes the dump is not in hand.** Every repo in this\n * family seals credentials with AES-256-GCM, and each one's migration notes say the\n * same thing: *obfuscation against a D1 dump, not protection against a full worker\n * compromise.* An unencrypted backup inverts that assumption — dump plus the\n * Secrets Store key is a complete credential set, and the WebDAV key is read on\n * every scan and every stream.\n *\n * **The dump is a listening history.** Stars, ratings, play counts, play queues and\n * auth failures record what each user does and when, and the schema records the\n * full topology and every file path. None of that is credential material, and all\n * of it is nobody else's to read.\n *\n * `S3_REGION` is deliberately not part of the S3 gate. R2 and MinIO have no\n * meaningful region — Cloudflare documents an R2 bucket's region as `auto`, with\n * empty and `us-east-1` both aliasing to it — so requiring the secret would\n * silently disable backups for anyone using such a provider. The upload script\n * defaults `AWS_DEFAULT_REGION` to `auto` instead.\n */\nexport function evaluateConfig(env: BackupSecretEnvironment): DestinationConfig {\n const cloudflare = isSet(env.CLOUDFLARE_API_TOKEN) && isSet(env.CLOUDFLARE_ACCOUNT_ID);\n const encryption = isSet(env.BACKUP_ENCRYPTION_KEY);\n const s3 = isSet(env.S3_ACCESS_KEY_ID) && isSet(env.S3_SECRET_ACCESS_KEY) && isSet(env.S3_BUCKET);\n const webdav = isSet(env.WEBDAV_URL) && isSet(env.WEBDAV_USER) && isSet(env.WEBDAV_PASSWORD);\n const anyDestination = s3 || webdav;\n\n const errors: string[] = [];\n\n // Fail closed, but only once someone has opted into a destination. An\n // unconfigured repository is a legitimate \"I do not want off-site backups\" state\n // and must not turn the schedule red.\n if (anyDestination) {\n if (!cloudflare) {\n errors.push('A backup destination is configured but CLOUDFLARE_API_TOKEN / CLOUDFLARE_ACCOUNT_ID are missing.');\n }\n if (!encryption) {\n errors.push(\n 'BACKUP_ENCRYPTION_KEY is required. The D1 dump holds AES-GCM-obfuscated credentials — obfuscation that, by its own design, assumes the dump is not in hand — plus every user history and the full schema topology.',\n );\n }\n }\n\n return { cloudflare, encryption, anyDestination, s3, webdav, errors };\n}\n"]}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/scripts/backup/destination-config.ts"],
4
+ "sourcesContent": ["/**\n * Destination and encryption policy for the D1 backup workflow.\n *\n * Provenance: ported from Edge-Sonic's `scripts/backup/destination-config.ts`.\n * Pure and side-effect free, so the fail-closed rules are asserted without running\n * Actions.\n */\n\n/**\nThe environment the `check-secrets` job is given, as repository secrets.\n*/\nexport interface BackupSecretEnvironment {\n CLOUDFLARE_API_TOKEN?: string;\n CLOUDFLARE_ACCOUNT_ID?: string;\n BACKUP_ENCRYPTION_KEY?: string;\n S3_ACCESS_KEY_ID?: string;\n S3_SECRET_ACCESS_KEY?: string;\n S3_BUCKET?: string;\n WEBDAV_URL?: string;\n WEBDAV_USER?: string;\n WEBDAV_PASSWORD?: string;\n}\n\n/**\nWhat is configured, and why the run cannot proceed when it is not.\n*/\nexport interface DestinationConfig {\n /**\n Cloudflare credentials present, so the export job can run.\n */\n cloudflare: boolean;\n /**\n An encryption passphrase is available.\n */\n encryption: boolean;\n /**\n At least one upload destination is configured.\n */\n anyDestination: boolean;\n /**\n The S3 destination is fully configured.\n */\n s3: boolean;\n /**\n The WebDAV destination is fully configured.\n */\n webdav: boolean;\n /**\n Human-readable reasons the run cannot proceed, empty when it can.\n */\n errors: string[];\n}\n\n/**\nA secret counts as set only when it has non-whitespace content.\n*/\nfunction isSet(value: string | undefined): boolean {\n return typeof value === 'string' && value.trim().length > 0;\n}\n\n/**\n * Decides which destinations are configured and enforces fail-closed encryption.\n *\n * ### Why the encryption requirement is not optional here\n *\n * Two independent reasons, and they have different consequences so both are stated.\n *\n * **The at-rest protection assumes the dump is not in hand.** Every repo in this\n * family seals credentials with AES-256-GCM, and each one's migration notes say the\n * same thing: *obfuscation against a D1 dump, not protection against a full worker\n * compromise.* An unencrypted backup inverts that assumption — dump plus the\n * Secrets Store key is a complete credential set, and the WebDAV key is read on\n * every scan and every stream.\n *\n * **The dump is a listening history.** Stars, ratings, play counts, play queues and\n * auth failures record what each user does and when, and the schema records the\n * full topology and every file path. None of that is credential material, and all\n * of it is nobody else's to read.\n *\n * `S3_REGION` is deliberately not part of the S3 gate. R2 and MinIO have no\n * meaningful region — Cloudflare documents an R2 bucket's region as `auto`, with\n * empty and `us-east-1` both aliasing to it — so requiring the secret would\n * silently disable backups for anyone using such a provider. The upload script\n * defaults `AWS_DEFAULT_REGION` to `auto` instead.\n */\nexport function evaluateConfig(env: BackupSecretEnvironment): DestinationConfig {\n const cloudflare = isSet(env.CLOUDFLARE_API_TOKEN) && isSet(env.CLOUDFLARE_ACCOUNT_ID);\n const encryption = isSet(env.BACKUP_ENCRYPTION_KEY);\n const s3 = isSet(env.S3_ACCESS_KEY_ID) && isSet(env.S3_SECRET_ACCESS_KEY) && isSet(env.S3_BUCKET);\n const webdav = isSet(env.WEBDAV_URL) && isSet(env.WEBDAV_USER) && isSet(env.WEBDAV_PASSWORD);\n const anyDestination = s3 || webdav;\n\n const errors: string[] = [];\n\n // Fail closed, but only once someone has opted into a destination. An\n // unconfigured repository is a legitimate \"I do not want off-site backups\" state\n // and must not turn the schedule red.\n if (anyDestination) {\n if (!cloudflare) {\n errors.push('A backup destination is configured but CLOUDFLARE_API_TOKEN / CLOUDFLARE_ACCOUNT_ID are missing.');\n }\n if (!encryption) {\n errors.push(\n 'BACKUP_ENCRYPTION_KEY is required. The D1 dump holds AES-GCM-obfuscated credentials — obfuscation that, by its own design, assumes the dump is not in hand — plus every user history and the full schema topology.',\n );\n }\n }\n\n return { cloudflare, encryption, anyDestination, s3, webdav, errors };\n}\n"],
5
+ "mappings": "AAwDA,SAASA,EAAMC,EAAyB,CACtC,OAAO,OAAOA,GAAU,UAAYA,EAAM,KAAI,EAAG,OAAS,CAC5D,CA2BM,SAAUC,EAAeC,EAA4B,CACzD,MAAMC,EAAaJ,EAAMG,EAAI,oBAAoB,GAAKH,EAAMG,EAAI,qBAAqB,EAC/EE,EAAaL,EAAMG,EAAI,qBAAqB,EAC5CG,EAAKN,EAAMG,EAAI,gBAAgB,GAAKH,EAAMG,EAAI,oBAAoB,GAAKH,EAAMG,EAAI,SAAS,EAC1FI,EAASP,EAAMG,EAAI,UAAU,GAAKH,EAAMG,EAAI,WAAW,GAAKH,EAAMG,EAAI,eAAe,EACrFK,EAAiBF,GAAMC,EAEvBE,EAAmB,CAAA,EAKzB,OAAID,IACGJ,GACHK,EAAO,KAAK,kGAAkG,EAE3GJ,GACHI,EAAO,KACL,8NAAoN,GAKnN,CAAE,WAAAL,EAAY,WAAAC,EAAY,eAAAG,EAAgB,GAAAF,EAAI,OAAAC,EAAQ,OAAAE,CAAM,CACrE",
6
+ "names": ["isSet", "value", "evaluateConfig", "env", "cloudflare", "encryption", "s3", "webdav", "anyDestination", "errors"]
7
+ }
@@ -1,98 +1,3 @@
1
1
  #!/usr/bin/env tsx
2
- /**
3
- * Compress and encrypt the exported D1 dump.
4
- *
5
- * Provenance: Edge-Sonic's `scripts/backup/encrypt-backup.ts`, converged with the
6
- * AES-GCM envelope every repo in the family already uses for its secrets. This is
7
- * the one backup script that ported cleanly and changed *for the better* on the way
8
- * in: the source shelled out to `openssl enc -aes-256-cbc -pbkdf2`, which is a
9
- * password-derived key with a KDF whose cost is a constant somebody chose once,
10
- * and which is not authenticated — a flipped byte in the ciphertext is undetectable.
11
- *
12
- * The kit's version uses `@rexezuge/d1`'s `encryptSecret`, the same WebCrypto
13
- * AES-256-GCM primitive the workers use, over a base64 32-byte key — the same key
14
- * format `resolveReplicationKey` reads. One definition of "what an encryption key
15
- * looks like" across the deploy path and the backup path is the point: a second
16
- * implementation is how a deploy ends up generating something the worker cannot
17
- * read, and here it would be how a backup ends up unreadable by the restore path.
18
- *
19
- * Fail-closed: without `BACKUP_ENCRYPTION_KEY` the script refuses to run and
20
- * deletes nothing, so an unencrypted dump can never reach the artifact store the
21
- * upload jobs read from.
22
- *
23
- * The passphrase is read from the environment rather than passed as an argument,
24
- * because command-line arguments are visible to any process on the runner via `ps`.
25
- *
26
- * Emits the resulting file name as the `file` step output.
27
- *
28
- * Usage, from the repo root (after `wrangler d1 export … --output=backup.sql`):
29
- *
30
- * ```bash
31
- * BACKUP_ENCRYPTION_KEY=… pnpm exec tsx scripts/backup/encrypt-backup.ts
32
- * ```
33
- */
34
- import { encryptSecret } from '@rexezuge/d1';
35
- import { execFileSync } from 'node:child_process';
36
- import { existsSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
37
- import { basename } from 'node:path';
38
- import { fail, setOutput } from "../lib/github-actions.js";
39
- import { backupFileName } from "./naming.js";
40
- /** The dump the export step leaves in the working directory. */
41
- const SOURCE_FILE = 'backup.sql';
42
- /**
43
- * xz preset 6, chosen for ratio over speed: this runs once a day against a dump
44
- * that is mostly SQL text and JSON blobs, and LZMA typically beats gzip by 20-30%
45
- * there. `-T0` uses every available thread, which matters because xz is markedly
46
- * slower than gzip and the job is wall-clock bound.
47
- */
48
- const XZ_ARGS = ['-T0', '-6'];
49
- function run(command, args) {
50
- execFileSync(command, [...args], { stdio: ['ignore', 'inherit', 'inherit'] });
51
- }
52
- if (!process.env['BACKUP_ENCRYPTION_KEY']) {
53
- fail('BACKUP_ENCRYPTION_KEY is not set. Refusing to export an unencrypted database.');
54
- }
55
- if (!existsSync(SOURCE_FILE)) {
56
- fail(`Expected ${SOURCE_FILE} from the export step, but it does not exist.`);
57
- }
58
- const key = process.env['BACKUP_ENCRYPTION_KEY'];
59
- const file = backupFileName(new Date());
60
- let plaintext;
61
- try {
62
- plaintext = readFileSync(SOURCE_FILE, 'utf8');
63
- }
64
- catch (error) {
65
- fail(`Could not read ${SOURCE_FILE}: ${error instanceof Error ? error.message : String(error)}`);
66
- }
67
- if (plaintext === '') {
68
- fail(`${SOURCE_FILE} is empty. An empty dump is not a backup, and uploading one is a false sense of safety.`);
69
- }
70
- /**
71
- * Compress first, then encrypt.
72
- *
73
- * The order matters: compression over ciphertext buys nothing, and encrypting the
74
- * compressed bytes means the plaintext is never re-materialised on disk at full
75
- * size. Unlike gzip, xz leaves its input in place, so the plaintext SQL has to be
76
- * removed explicitly here or it survives into the artifact store.
77
- */
78
- let compressed;
79
- try {
80
- compressed = execFileSync('xz', [...XZ_ARGS, '--keep', '--stdout', SOURCE_FILE], { maxBuffer: 512 * 1024 * 1024 });
81
- }
82
- catch (error) {
83
- fail(`xz failed on ${SOURCE_FILE}: ${error instanceof Error ? error.message : String(error)}`);
84
- }
85
- let envelope;
86
- try {
87
- envelope = await encryptSecret(compressed.toString('base64'), key);
88
- }
89
- catch (error) {
90
- // A key that is not 32 base64 bytes, or not valid base64 at all, fails here
91
- // rather than producing a file nothing can open.
92
- fail(`Could not encrypt the dump: ${error instanceof Error ? error.message : String(error)}`);
93
- }
94
- writeFileSync(file, `${JSON.stringify({ ...envelope, source: basename(SOURCE_FILE) }, null, 2)}\n`, 'utf8');
95
- rmSync(SOURCE_FILE, { force: true });
96
- console.log(`Backup encrypted: ${file} (${compressed.byteLength} compressed bytes)`);
97
- setOutput('file', file);
98
- //# sourceMappingURL=encrypt-backup.js.map
2
+ import{encryptSecret as a}from"@rexezuge/d1";import{execFileSync as c}from"node:child_process";import{existsSync as p,readFileSync as f,rmSync as m,writeFileSync as l}from"node:fs";import u from"node:path";import{fail as r,setOutput as y}from"../lib/github-actions.js";import{backupFileName as d}from"./naming.js";const t="backup.sql",S=["-T0","-6"];process.env.BACKUP_ENCRYPTION_KEY||r("BACKUP_ENCRYPTION_KEY is not set. Refusing to export an unencrypted database."),p(t)||r(`Expected ${t} from the export step, but it does not exist.`);const g=process.env.BACKUP_ENCRYPTION_KEY,o=d(new Date);let s;try{s=f(t,"utf8")}catch(e){r(`Could not read ${t}: ${e instanceof Error?e.message:String(e)}`)}s===""&&r(`${t} is empty. An empty dump is not a backup, and uploading one is a false sense of safety.`);let n;try{n=c("xz",[...S,"--keep","--stdout",t],{maxBuffer:512*1024*1024})}catch(e){r(`xz failed on ${t}: ${e instanceof Error?e.message:String(e)}`)}let i;try{i=await a(n.toString("base64"),g)}catch(e){r(`Could not encrypt the dump: ${e instanceof Error?e.message:String(e)}`)}l(o,`${JSON.stringify({...i,source:u.basename(t)},null,2)}
3
+ `,"utf8"),m(t,{force:!0}),console.log(`Backup encrypted: ${o} (${n.byteLength} compressed bytes)`),y("file",o);
@@ -1 +1,7 @@
1
- {"version":3,"file":"encrypt-backup.js","sourceRoot":"","sources":["../../../src/scripts/backup/encrypt-backup.ts"],"names":[],"mappings":";AACA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAC1E,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACrC,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAC3D,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAE7C,gEAAgE;AAChE,MAAM,WAAW,GAAG,YAAY,CAAC;AAEjC;;;;;GAKG;AACH,MAAM,OAAO,GAAG,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;AAE9B,SAAS,GAAG,CAAC,OAAe,EAAE,IAAuB;IACnD,YAAY,CAAC,OAAO,EAAE,CAAC,GAAG,IAAI,CAAC,EAAE,EAAE,KAAK,EAAE,CAAC,QAAQ,EAAE,SAAS,EAAE,SAAS,CAAC,EAAE,CAAC,CAAC;AAChF,CAAC;AAED,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,uBAAuB,CAAC,EAAE,CAAC;IAC1C,IAAI,CAAC,+EAA+E,CAAC,CAAC;AACxF,CAAC;AAED,IAAI,CAAC,UAAU,CAAC,WAAW,CAAC,EAAE,CAAC;IAC7B,IAAI,CAAC,YAAY,WAAW,+CAA+C,CAAC,CAAC;AAC/E,CAAC;AAED,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,uBAAuB,CAAW,CAAC;AAC3D,MAAM,IAAI,GAAG,cAAc,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC;AAExC,IAAI,SAAiB,CAAC;AACtB,IAAI,CAAC;IACH,SAAS,GAAG,YAAY,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC;AAChD,CAAC;AAAC,OAAO,KAAc,EAAE,CAAC;IACxB,IAAI,CAAC,kBAAkB,WAAW,KAAK,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;AACnG,CAAC;AAED,IAAI,SAAS,KAAK,EAAE,EAAE,CAAC;IACrB,IAAI,CAAC,GAAG,WAAW,yFAAyF,CAAC,CAAC;AAChH,CAAC;AAED;;;;;;;GAOG;AACH,IAAI,UAAkB,CAAC;AACvB,IAAI,CAAC;IACH,UAAU,GAAG,YAAY,CAAC,IAAI,EAAE,CAAC,GAAG,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,WAAW,CAAC,EAAE,EAAE,SAAS,EAAE,GAAG,GAAG,IAAI,GAAG,IAAI,EAAE,CAAC,CAAC;AACrH,CAAC;AAAC,OAAO,KAAc,EAAE,CAAC;IACxB,IAAI,CAAC,gBAAgB,WAAW,KAAK,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;AACjG,CAAC;AAED,IAAI,QAA4C,CAAC;AACjD,IAAI,CAAC;IACH,QAAQ,GAAG,MAAM,aAAa,CAAC,UAAU,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE,GAAG,CAAC,CAAC;AACrE,CAAC;AAAC,OAAO,KAAc,EAAE,CAAC;IACxB,4EAA4E;IAC5E,iDAAiD;IACjD,IAAI,CAAC,+BAA+B,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;AAChG,CAAC;AAED,aAAa,CAAC,IAAI,EAAE,GAAG,IAAI,CAAC,SAAS,CAAC,EAAE,GAAG,QAAQ,EAAE,MAAM,EAAE,QAAQ,CAAC,WAAW,CAAC,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;AAC5G,MAAM,CAAC,WAAW,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAErC,OAAO,CAAC,GAAG,CAAC,qBAAqB,IAAI,KAAK,UAAU,CAAC,UAAU,oBAAoB,CAAC,CAAC;AACrF,SAAS,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC","sourcesContent":["#!/usr/bin/env tsx\n/**\n * Compress and encrypt the exported D1 dump.\n *\n * Provenance: Edge-Sonic's `scripts/backup/encrypt-backup.ts`, converged with the\n * AES-GCM envelope every repo in the family already uses for its secrets. This is\n * the one backup script that ported cleanly and changed *for the better* on the way\n * in: the source shelled out to `openssl enc -aes-256-cbc -pbkdf2`, which is a\n * password-derived key with a KDF whose cost is a constant somebody chose once,\n * and which is not authenticated — a flipped byte in the ciphertext is undetectable.\n *\n * The kit's version uses `@rexezuge/d1`'s `encryptSecret`, the same WebCrypto\n * AES-256-GCM primitive the workers use, over a base64 32-byte key — the same key\n * format `resolveReplicationKey` reads. One definition of \"what an encryption key\n * looks like\" across the deploy path and the backup path is the point: a second\n * implementation is how a deploy ends up generating something the worker cannot\n * read, and here it would be how a backup ends up unreadable by the restore path.\n *\n * Fail-closed: without `BACKUP_ENCRYPTION_KEY` the script refuses to run and\n * deletes nothing, so an unencrypted dump can never reach the artifact store the\n * upload jobs read from.\n *\n * The passphrase is read from the environment rather than passed as an argument,\n * because command-line arguments are visible to any process on the runner via `ps`.\n *\n * Emits the resulting file name as the `file` step output.\n *\n * Usage, from the repo root (after `wrangler d1 export … --output=backup.sql`):\n *\n * ```bash\n * BACKUP_ENCRYPTION_KEY=… pnpm exec tsx scripts/backup/encrypt-backup.ts\n * ```\n */\n\nimport { encryptSecret } from '@rexezuge/d1';\nimport { execFileSync } from 'node:child_process';\nimport { existsSync, readFileSync, rmSync, writeFileSync } from 'node:fs';\nimport { basename } from 'node:path';\nimport { fail, setOutput } from '../lib/github-actions.ts';\nimport { backupFileName } from './naming.ts';\n\n/** The dump the export step leaves in the working directory. */\nconst SOURCE_FILE = 'backup.sql';\n\n/**\n * xz preset 6, chosen for ratio over speed: this runs once a day against a dump\n * that is mostly SQL text and JSON blobs, and LZMA typically beats gzip by 20-30%\n * there. `-T0` uses every available thread, which matters because xz is markedly\n * slower than gzip and the job is wall-clock bound.\n */\nconst XZ_ARGS = ['-T0', '-6'];\n\nfunction run(command: string, args: readonly string[]): void {\n execFileSync(command, [...args], { stdio: ['ignore', 'inherit', 'inherit'] });\n}\n\nif (!process.env['BACKUP_ENCRYPTION_KEY']) {\n fail('BACKUP_ENCRYPTION_KEY is not set. Refusing to export an unencrypted database.');\n}\n\nif (!existsSync(SOURCE_FILE)) {\n fail(`Expected ${SOURCE_FILE} from the export step, but it does not exist.`);\n}\n\nconst key = process.env['BACKUP_ENCRYPTION_KEY'] as string;\nconst file = backupFileName(new Date());\n\nlet plaintext: string;\ntry {\n plaintext = readFileSync(SOURCE_FILE, 'utf8');\n} catch (error: unknown) {\n fail(`Could not read ${SOURCE_FILE}: ${error instanceof Error ? error.message : String(error)}`);\n}\n\nif (plaintext === '') {\n fail(`${SOURCE_FILE} is empty. An empty dump is not a backup, and uploading one is a false sense of safety.`);\n}\n\n/**\n * Compress first, then encrypt.\n *\n * The order matters: compression over ciphertext buys nothing, and encrypting the\n * compressed bytes means the plaintext is never re-materialised on disk at full\n * size. Unlike gzip, xz leaves its input in place, so the plaintext SQL has to be\n * removed explicitly here or it survives into the artifact store.\n */\nlet compressed: Buffer;\ntry {\n compressed = execFileSync('xz', [...XZ_ARGS, '--keep', '--stdout', SOURCE_FILE], { maxBuffer: 512 * 1024 * 1024 });\n} catch (error: unknown) {\n fail(`xz failed on ${SOURCE_FILE}: ${error instanceof Error ? error.message : String(error)}`);\n}\n\nlet envelope: { ciphertext: string; iv: string };\ntry {\n envelope = await encryptSecret(compressed.toString('base64'), key);\n} catch (error: unknown) {\n // A key that is not 32 base64 bytes, or not valid base64 at all, fails here\n // rather than producing a file nothing can open.\n fail(`Could not encrypt the dump: ${error instanceof Error ? error.message : String(error)}`);\n}\n\nwriteFileSync(file, `${JSON.stringify({ ...envelope, source: basename(SOURCE_FILE) }, null, 2)}\\n`, 'utf8');\nrmSync(SOURCE_FILE, { force: true });\n\nconsole.log(`Backup encrypted: ${file} (${compressed.byteLength} compressed bytes)`);\nsetOutput('file', file);\n"]}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/scripts/backup/encrypt-backup.ts"],
4
+ "sourcesContent": ["#!/usr/bin/env tsx\n/**\n * Compress and encrypt the exported D1 dump.\n *\n * Provenance: Edge-Sonic's `scripts/backup/encrypt-backup.ts`, converged with the\n * AES-GCM envelope every repo in the family already uses for its secrets. This is\n * the one backup script that ported cleanly and changed *for the better* on the way\n * in: the source shelled out to `openssl enc -aes-256-cbc -pbkdf2`, which is a\n * password-derived key with a KDF whose cost is a constant somebody chose once,\n * and which is not authenticated — a flipped byte in the ciphertext is undetectable.\n *\n * The kit's version uses `@rexezuge/d1`'s `encryptSecret`, the same WebCrypto\n * AES-256-GCM primitive the workers use, over a base64 32-byte key — the same key\n * format `resolveReplicationKey` reads. One definition of \"what an encryption key\n * looks like\" across the deploy path and the backup path is the point: a second\n * implementation is how a deploy ends up generating something the worker cannot\n * read, and here it would be how a backup ends up unreadable by the restore path.\n *\n * Fail-closed: without `BACKUP_ENCRYPTION_KEY` the script refuses to run and\n * deletes nothing, so an unencrypted dump can never reach the artifact store the\n * upload jobs read from.\n *\n * The passphrase is read from the environment rather than passed as an argument,\n * because command-line arguments are visible to any process on the runner via `ps`.\n *\n * Emits the resulting file name as the `file` step output.\n *\n * Usage, from the repo root (after `wrangler d1 export … --output=backup.sql`):\n *\n * ```bash\n * BACKUP_ENCRYPTION_KEY=… pnpm exec tsx scripts/backup/encrypt-backup.ts\n * ```\n */\n\nimport { encryptSecret } from '@rexezuge/d1';\nimport { execFileSync } from 'node:child_process';\nimport { existsSync, readFileSync, rmSync, writeFileSync } from 'node:fs';\nimport path from 'node:path';\nimport { fail, setOutput } from '../lib/github-actions.ts';\nimport { backupFileName } from './naming.ts';\n\n/**\nThe dump the export step leaves in the working directory.\n*/\nconst SOURCE_FILE = 'backup.sql';\n\n/**\n * xz preset 6, chosen for ratio over speed: this runs once a day against a dump\n * that is mostly SQL text and JSON blobs, and LZMA typically beats gzip by 20-30%\n * there. `-T0` uses every available thread, which matters because xz is markedly\n * slower than gzip and the job is wall-clock bound.\n */\nconst XZ_ARGS = ['-T0', '-6'];\n\nif (!process.env['BACKUP_ENCRYPTION_KEY']) {\n fail('BACKUP_ENCRYPTION_KEY is not set. Refusing to export an unencrypted database.');\n}\n\nif (!existsSync(SOURCE_FILE)) {\n fail(`Expected ${SOURCE_FILE} from the export step, but it does not exist.`);\n}\n\nconst key = process.env['BACKUP_ENCRYPTION_KEY'];\nconst file = backupFileName(new Date());\n\nlet plaintext: string;\ntry {\n plaintext = readFileSync(SOURCE_FILE, 'utf8');\n} catch (error: unknown) {\n fail(`Could not read ${SOURCE_FILE}: ${error instanceof Error ? error.message : String(error)}`);\n}\n\nif (plaintext === '') {\n fail(`${SOURCE_FILE} is empty. An empty dump is not a backup, and uploading one is a false sense of safety.`);\n}\n\n/**\n * Compress first, then encrypt.\n *\n * The order matters: compression over ciphertext buys nothing, and encrypting the\n * compressed bytes means the plaintext is never re-materialised on disk at full\n * size. Unlike gzip, xz leaves its input in place, so the plaintext SQL has to be\n * removed explicitly here or it survives into the artifact store.\n */\nlet compressed: Buffer;\ntry {\n // `xz` is resolved from PATH deliberately: the script runs wherever the\n // operator compresses backups, and pinning an absolute path would break\n // every platform but one.\n // eslint-disable-next-line sonarjs/no-os-command-from-path\n compressed = execFileSync('xz', [...XZ_ARGS, '--keep', '--stdout', SOURCE_FILE], { maxBuffer: 512 * 1024 * 1024 });\n} catch (error: unknown) {\n fail(`xz failed on ${SOURCE_FILE}: ${error instanceof Error ? error.message : String(error)}`);\n}\n\nlet envelope: { ciphertext: string; iv: string };\ntry {\n envelope = await encryptSecret(compressed.toString('base64'), key);\n} catch (error: unknown) {\n // A key that is not 32 base64 bytes, or not valid base64 at all, fails here\n // rather than producing a file nothing can open.\n fail(`Could not encrypt the dump: ${error instanceof Error ? error.message : String(error)}`);\n}\n\nwriteFileSync(file, `${JSON.stringify({ ...envelope, source: path.basename(SOURCE_FILE) }, null, 2)}\\n`, 'utf8');\nrmSync(SOURCE_FILE, { force: true });\n\nconsole.log(`Backup encrypted: ${file} (${compressed.byteLength} compressed bytes)`);\nsetOutput('file', file);\n"],
5
+ "mappings": ";AAkCA,OAAS,iBAAAA,MAAqB,eAC9B,OAAS,gBAAAC,MAAoB,qBAC7B,OAAS,cAAAC,EAAY,gBAAAC,EAAc,UAAAC,EAAQ,iBAAAC,MAAqB,UAChE,OAAOC,MAAU,YACjB,OAAS,QAAAC,EAAM,aAAAC,MAAiB,2BAChC,OAAS,kBAAAC,MAAsB,cAK/B,MAAMC,EAAc,aAQdC,EAAU,CAAC,MAAO,IAAI,EAEvB,QAAQ,IAAI,uBACfJ,EAAK,+EAA+E,EAGjFL,EAAWQ,CAAW,GACzBH,EAAK,YAAYG,CAAW,+CAA+C,EAG7E,MAAME,EAAM,QAAQ,IAAI,sBAClBC,EAAOJ,EAAe,IAAI,IAAM,EAEtC,IAAIK,EACJ,GAAI,CACFA,EAAYX,EAAaO,EAAa,MAAM,CAC9C,OAASK,EAAgB,CACvBR,EAAK,kBAAkBG,CAAW,KAAKK,aAAiB,MAAQA,EAAM,QAAU,OAAOA,CAAK,CAAC,EAAE,CACjG,CAEID,IAAc,IAChBP,EAAK,GAAGG,CAAW,yFAAyF,EAW9G,IAAIM,EACJ,GAAI,CAKFA,EAAaf,EAAa,KAAM,CAAC,GAAGU,EAAS,SAAU,WAAYD,CAAW,EAAG,CAAE,UAAW,IAAM,KAAO,IAAI,CAAE,CACnH,OAASK,EAAgB,CACvBR,EAAK,gBAAgBG,CAAW,KAAKK,aAAiB,MAAQA,EAAM,QAAU,OAAOA,CAAK,CAAC,EAAE,CAC/F,CAEA,IAAIE,EACJ,GAAI,CACFA,EAAW,MAAMjB,EAAcgB,EAAW,SAAS,QAAQ,EAAGJ,CAAG,CACnE,OAASG,EAAgB,CAGvBR,EAAK,+BAA+BQ,aAAiB,MAAQA,EAAM,QAAU,OAAOA,CAAK,CAAC,EAAE,CAC9F,CAEAV,EAAcQ,EAAM,GAAG,KAAK,UAAU,CAAE,GAAGI,EAAU,OAAQX,EAAK,SAASI,CAAW,CAAC,EAAI,KAAM,CAAC,CAAC;EAAM,MAAM,EAC/GN,EAAOM,EAAa,CAAE,MAAO,EAAI,CAAE,EAEnC,QAAQ,IAAI,qBAAqBG,CAAI,KAAKG,EAAW,UAAU,oBAAoB,EACnFR,EAAU,OAAQK,CAAI",
6
+ "names": ["encryptSecret", "execFileSync", "existsSync", "readFileSync", "rmSync", "writeFileSync", "path", "fail", "setOutput", "backupFileName", "SOURCE_FILE", "XZ_ARGS", "key", "file", "plaintext", "error", "compressed", "envelope"]
7
+ }
@@ -24,7 +24,9 @@ export declare const BACKUP_FILE_PREFIX = "backup_prod_";
24
24
  * never needed.
25
25
  */
26
26
  export declare function backupStamp(date: Date): string;
27
- /** The full artifact name: `<prefix><stamp>.sql.xz.enc`. */
27
+ /**
28
+ The full artifact name: `<prefix><stamp>.sql.xz.enc`.
29
+ */
28
30
  export declare function backupFileName(date: Date): string;
29
31
  /**
30
32
  * `YYYY-MM-DD`, `days` before `now`.
@@ -1 +1 @@
1
- {"version":3,"file":"naming.d.ts","sourceRoot":"","sources":["../../../src/scripts/backup/naming.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH;;;;;;;;GAQG;AACH,eAAO,MAAM,kBAAkB,iBAAiB,CAAC;AAEjD;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,CAG9C;AAED,4DAA4D;AAC5D,wBAAgB,cAAc,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,CAEjD;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAE/D;AAED;;;;;;;;;GASG;AACH,wBAAgB,oBAAoB,IAAI,MAAM,CAO7C"}
1
+ {"version":3,"file":"naming.d.ts","sourceRoot":"","sources":["../../../src/scripts/backup/naming.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH;;;;;;;;GAQG;AACH,eAAO,MAAM,kBAAkB,iBAAiB,CAAC;AAEjD;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,CAG9C;AAED;;EAEE;AACF,wBAAgB,cAAc,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,CAEjD;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAE/D;AAED;;;;;;;;;GASG;AACH,wBAAgB,oBAAoB,IAAI,MAAM,CAO7C"}
@@ -1,58 +1 @@
1
- /**
2
- * Backup artifact naming and retention-window handling.
3
- *
4
- * Provenance: Edge-Sonic's `scripts/backup/naming.ts` and `retention.ts`,
5
- * converged into one module because the two answer the same question from either
6
- * side — what a file is called, and which of them are still worth keeping — and a
7
- * consumer only ever imports one.
8
- */
9
- /**
10
- * The filename prefix.
11
- *
12
- * Exported rather than inlined, because the workflow uploads with
13
- * `<prefix>_*.sql.xz.enc` and `if-no-files-found: error`. That glob and this prefix
14
- * are one fact written in two places — the failure mode being a rename here that
15
- * silently stops every upload while each upload job still reports success, since
16
- * the upload jobs skip on `needs` rather than failing.
17
- */
18
- export const BACKUP_FILE_PREFIX = 'backup_prod_';
19
- /**
20
- * `2026-10-01_04-15-00` — sortable, filename-safe, and UTC.
21
- *
22
- * UTC rather than local: a retention window computed across a DST boundary is one
23
- * day wide in one direction, and a backup pruned a day early is a backup that was
24
- * never needed.
25
- */
26
- export function backupStamp(date) {
27
- const iso = date.toISOString();
28
- return `${iso.slice(0, 10)}_${iso.slice(11, 19).replaceAll(':', '-')}`;
29
- }
30
- /** The full artifact name: `<prefix><stamp>.sql.xz.enc`. */
31
- export function backupFileName(date) {
32
- return `${BACKUP_FILE_PREFIX}${backupStamp(date)}.sql.xz.enc`;
33
- }
34
- /**
35
- * `YYYY-MM-DD`, `days` before `now`.
36
- */
37
- export function retentionCutoff(now, days) {
38
- return new Date(now.getTime() - days * 24 * 60 * 60 * 1000).toISOString().slice(0, 10);
39
- }
40
- /**
41
- * Read `BACKUP_RETENTION_DAYS` from the environment, rejecting bad values.
42
- *
43
- * Rejected rather than defaulted: silently falling back would either prune
44
- * everything or keep backups forever, and both are worse than a failed run that
45
- * names the problem.
46
- *
47
- * `Number()` rather than `parseInt()`: `parseInt('30d')` yields 30, which would
48
- * silently accept a mistyped value and prune against the wrong window.
49
- */
50
- export function requireRetentionDays() {
51
- const raw = process.env['BACKUP_RETENTION_DAYS'];
52
- const days = Number(raw);
53
- if (!Number.isFinite(days) || days <= 0) {
54
- throw new Error(`BACKUP_RETENTION_DAYS must be a positive number, got ${JSON.stringify(raw)}.`);
55
- }
56
- return days;
57
- }
58
- //# sourceMappingURL=naming.js.map
1
+ const r="backup_prod_";function n(e){const t=e.toISOString();return`${t.slice(0,10)}_${t.slice(11,19).replaceAll(":","-")}`}function o(e){return`${r}${n(e)}.sql.xz.enc`}function i(e,t){return new Date(e.getTime()-t*24*60*60*1e3).toISOString().slice(0,10)}function c(){const e=process.env.BACKUP_RETENTION_DAYS,t=Number(e);if(!Number.isFinite(t)||t<=0)throw new Error(`BACKUP_RETENTION_DAYS must be a positive number, got ${JSON.stringify(e)}.`);return t}export{r as BACKUP_FILE_PREFIX,o as backupFileName,n as backupStamp,c as requireRetentionDays,i as retentionCutoff};
@@ -1 +1,7 @@
1
- {"version":3,"file":"naming.js","sourceRoot":"","sources":["../../../src/scripts/backup/naming.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,cAAc,CAAC;AAEjD;;;;;;GAMG;AACH,MAAM,UAAU,WAAW,CAAC,IAAU;IACpC,MAAM,GAAG,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC;IAC/B,OAAO,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,GAAG,CAAC,KAAK,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,UAAU,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE,CAAC;AACzE,CAAC;AAED,4DAA4D;AAC5D,MAAM,UAAU,cAAc,CAAC,IAAU;IACvC,OAAO,GAAG,kBAAkB,GAAG,WAAW,CAAC,IAAI,CAAC,aAAa,CAAC;AAChE,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,eAAe,CAAC,GAAS,EAAE,IAAY;IACrD,OAAO,IAAI,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE,GAAG,IAAI,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC,WAAW,EAAE,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;AACzF,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,oBAAoB;IAClC,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,uBAAuB,CAAC,CAAC;IACjD,MAAM,IAAI,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC;IACzB,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,EAAE,CAAC;QACxC,MAAM,IAAI,KAAK,CAAC,wDAAwD,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IAClG,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC","sourcesContent":["/**\n * Backup artifact naming and retention-window handling.\n *\n * Provenance: Edge-Sonic's `scripts/backup/naming.ts` and `retention.ts`,\n * converged into one module because the two answer the same question from either\n * side — what a file is called, and which of them are still worth keeping — and a\n * consumer only ever imports one.\n */\n\n/**\n * The filename prefix.\n *\n * Exported rather than inlined, because the workflow uploads with\n * `<prefix>_*.sql.xz.enc` and `if-no-files-found: error`. That glob and this prefix\n * are one fact written in two places — the failure mode being a rename here that\n * silently stops every upload while each upload job still reports success, since\n * the upload jobs skip on `needs` rather than failing.\n */\nexport const BACKUP_FILE_PREFIX = 'backup_prod_';\n\n/**\n * `2026-10-01_04-15-00` — sortable, filename-safe, and UTC.\n *\n * UTC rather than local: a retention window computed across a DST boundary is one\n * day wide in one direction, and a backup pruned a day early is a backup that was\n * never needed.\n */\nexport function backupStamp(date: Date): string {\n const iso = date.toISOString();\n return `${iso.slice(0, 10)}_${iso.slice(11, 19).replaceAll(':', '-')}`;\n}\n\n/** The full artifact name: `<prefix><stamp>.sql.xz.enc`. */\nexport function backupFileName(date: Date): string {\n return `${BACKUP_FILE_PREFIX}${backupStamp(date)}.sql.xz.enc`;\n}\n\n/**\n * `YYYY-MM-DD`, `days` before `now`.\n */\nexport function retentionCutoff(now: Date, days: number): string {\n return new Date(now.getTime() - days * 24 * 60 * 60 * 1000).toISOString().slice(0, 10);\n}\n\n/**\n * Read `BACKUP_RETENTION_DAYS` from the environment, rejecting bad values.\n *\n * Rejected rather than defaulted: silently falling back would either prune\n * everything or keep backups forever, and both are worse than a failed run that\n * names the problem.\n *\n * `Number()` rather than `parseInt()`: `parseInt('30d')` yields 30, which would\n * silently accept a mistyped value and prune against the wrong window.\n */\nexport function requireRetentionDays(): number {\n const raw = process.env['BACKUP_RETENTION_DAYS'];\n const days = Number(raw);\n if (!Number.isFinite(days) || days <= 0) {\n throw new Error(`BACKUP_RETENTION_DAYS must be a positive number, got ${JSON.stringify(raw)}.`);\n }\n return days;\n}\n"]}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/scripts/backup/naming.ts"],
4
+ "sourcesContent": ["/**\n * Backup artifact naming and retention-window handling.\n *\n * Provenance: Edge-Sonic's `scripts/backup/naming.ts` and `retention.ts`,\n * converged into one module because the two answer the same question from either\n * side — what a file is called, and which of them are still worth keeping — and a\n * consumer only ever imports one.\n */\n\n/**\n * The filename prefix.\n *\n * Exported rather than inlined, because the workflow uploads with\n * `<prefix>_*.sql.xz.enc` and `if-no-files-found: error`. That glob and this prefix\n * are one fact written in two places — the failure mode being a rename here that\n * silently stops every upload while each upload job still reports success, since\n * the upload jobs skip on `needs` rather than failing.\n */\nexport const BACKUP_FILE_PREFIX = 'backup_prod_';\n\n/**\n * `2026-10-01_04-15-00` — sortable, filename-safe, and UTC.\n *\n * UTC rather than local: a retention window computed across a DST boundary is one\n * day wide in one direction, and a backup pruned a day early is a backup that was\n * never needed.\n */\nexport function backupStamp(date: Date): string {\n const iso = date.toISOString();\n return `${iso.slice(0, 10)}_${iso.slice(11, 19).replaceAll(':', '-')}`;\n}\n\n/**\nThe full artifact name: `<prefix><stamp>.sql.xz.enc`.\n*/\nexport function backupFileName(date: Date): string {\n return `${BACKUP_FILE_PREFIX}${backupStamp(date)}.sql.xz.enc`;\n}\n\n/**\n * `YYYY-MM-DD`, `days` before `now`.\n */\nexport function retentionCutoff(now: Date, days: number): string {\n return new Date(now.getTime() - days * 24 * 60 * 60 * 1000).toISOString().slice(0, 10);\n}\n\n/**\n * Read `BACKUP_RETENTION_DAYS` from the environment, rejecting bad values.\n *\n * Rejected rather than defaulted: silently falling back would either prune\n * everything or keep backups forever, and both are worse than a failed run that\n * names the problem.\n *\n * `Number()` rather than `parseInt()`: `parseInt('30d')` yields 30, which would\n * silently accept a mistyped value and prune against the wrong window.\n */\nexport function requireRetentionDays(): number {\n const raw = process.env['BACKUP_RETENTION_DAYS'];\n const days = Number(raw);\n if (!Number.isFinite(days) || days <= 0) {\n throw new Error(`BACKUP_RETENTION_DAYS must be a positive number, got ${JSON.stringify(raw)}.`);\n }\n return days;\n}\n"],
5
+ "mappings": "AAkBO,MAAMA,EAAqB,eAS5B,SAAUC,EAAYC,EAAU,CACpC,MAAMC,EAAMD,EAAK,YAAW,EAC5B,MAAO,GAAGC,EAAI,MAAM,EAAG,EAAE,CAAC,IAAIA,EAAI,MAAM,GAAI,EAAE,EAAE,WAAW,IAAK,GAAG,CAAC,EACtE,CAKM,SAAUC,EAAeF,EAAU,CACvC,MAAO,GAAGF,CAAkB,GAAGC,EAAYC,CAAI,CAAC,aAClD,CAKM,SAAUG,EAAgBC,EAAWC,EAAY,CACrD,OAAO,IAAI,KAAKD,EAAI,QAAO,EAAKC,EAAO,GAAK,GAAK,GAAK,GAAI,EAAE,YAAW,EAAG,MAAM,EAAG,EAAE,CACvF,CAYM,SAAUC,GAAoB,CAClC,MAAMC,EAAM,QAAQ,IAAI,sBAClBF,EAAO,OAAOE,CAAG,EACvB,GAAI,CAAC,OAAO,SAASF,CAAI,GAAKA,GAAQ,EACpC,MAAM,IAAI,MAAM,wDAAwD,KAAK,UAAUE,CAAG,CAAC,GAAG,EAEhG,OAAOF,CACT",
6
+ "names": ["BACKUP_FILE_PREFIX", "backupStamp", "date", "iso", "backupFileName", "retentionCutoff", "now", "days", "requireRetentionDays", "raw"]
7
+ }
@@ -49,22 +49,34 @@
49
49
  * A file past a size the guard reports on.
50
50
  */
51
51
  export interface GodFileFinding {
52
- /** Path relative to the root the check ran against. */
52
+ /**
53
+ Path relative to the root the check ran against.
54
+ */
53
55
  readonly file: string;
54
- /** Lines it has. */
56
+ /**
57
+ Lines it has.
58
+ */
55
59
  readonly lines: number;
56
- /** `warn` past the soft limit, `critical` past the hard one. */
60
+ /**
61
+ `warn` past the soft limit, `critical` past the hard one.
62
+ */
57
63
  readonly level: 'warn' | 'critical';
58
64
  }
59
65
  /**
60
66
  * The outcome of one run.
61
67
  */
62
68
  export interface GodFileReport {
63
- /** Files over a limit, worst first, minus the allowlisted. */
69
+ /**
70
+ Files over a limit, worst first, minus the allowlisted.
71
+ */
64
72
  readonly findings: readonly GodFileFinding[];
65
- /** How many files the walk measured. */
73
+ /**
74
+ How many files the walk measured.
75
+ */
66
76
  readonly scanned: number;
67
- /** Allowlisted files that are over a limit — reported, never counted. */
77
+ /**
78
+ Allowlisted files that are over a limit — reported, never counted.
79
+ */
68
80
  readonly allowlisted: readonly GodFileFinding[];
69
81
  /**
70
82
  * Whether the tree may be committed as it stands.
@@ -73,14 +85,18 @@ export interface GodFileReport {
73
85
  * only when the caller asked for the gate.
74
86
  */
75
87
  readonly passed: boolean;
76
- /** The message to print, either way. */
88
+ /**
89
+ The message to print, either way.
90
+ */
77
91
  readonly reported: string;
78
92
  }
79
93
  /**
80
94
  * What `checkGodFiles` accepts.
81
95
  */
82
96
  export interface GodFileOptions {
83
- /** Directory to walk. */
97
+ /**
98
+ Directory to walk.
99
+ */
84
100
  readonly root: string;
85
101
  /**
86
102
  * Repo-relative paths (or directory prefixes ending in `/`) exempt from the
@@ -88,16 +104,26 @@ export interface GodFileOptions {
88
104
  * when that file exists — see `readAllowlist`.
89
105
  */
90
106
  readonly allowlist?: readonly string[];
91
- /** Soft limit, past which a file is reported as `warn`. */
107
+ /**
108
+ Soft limit, past which a file is reported as `warn`.
109
+ */
92
110
  readonly soft?: number;
93
- /** Hard limit, past which a file is reported as `critical`. */
111
+ /**
112
+ Hard limit, past which a file is reported as `critical`.
113
+ */
94
114
  readonly hard?: number;
95
- /** Make a `critical` finding fail the run. */
115
+ /**
116
+ Make a `critical` finding fail the run.
117
+ */
96
118
  readonly failOnHard?: boolean;
97
119
  }
98
- /** Default soft limit, as every source repo uses. */
120
+ /**
121
+ Default soft limit, as every source repo uses.
122
+ */
99
123
  export declare const SOFT_LIMIT = 300;
100
- /** Default hard limit, as every source repo uses. */
124
+ /**
125
+ Default hard limit, as every source repo uses.
126
+ */
101
127
  export declare const HARD_LIMIT = 400;
102
128
  /**
103
129
  * Whether a repo-relative path is exempt from the guard.
@@ -146,7 +172,7 @@ export declare function checkGodFiles(options: GodFileOptions): GodFileReport;
146
172
  * A malformed file is an error rather than an empty list, because "the allowlist
147
173
  * is empty" silently un-reports every known offender.
148
174
  */
149
- export declare function readAllowlist(path: string): string[];
175
+ export declare function readAllowlist(file: string): string[];
150
176
  /**
151
177
  * CLI entry: `checkGodFilesCli(['.', '--fail-on-hard'])`.
152
178
  *