@rebasepro/server 0.22.0 → 0.24.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 (211) hide show
  1. package/README.md +1 -1
  2. package/bin/rebase-server.js +4 -2
  3. package/dist/{GCSStorageController-CLIJXwGS.js → GCSStorageController-BSiP1c-f.js} +57 -29
  4. package/dist/GCSStorageController-BSiP1c-f.js.map +1 -0
  5. package/dist/{S3StorageController-Dcuf8lMA.js → S3StorageController-CAwFRgjV.js} +19 -7
  6. package/dist/S3StorageController-CAwFRgjV.js.map +1 -0
  7. package/dist/api/ast-schema-editor.d.ts +127 -1
  8. package/dist/api/errors.d.ts +9 -0
  9. package/dist/api/live-schema-routes.d.ts +52 -8
  10. package/dist/api/logs-routes.d.ts +39 -1
  11. package/dist/api/openapi-generator.d.ts +17 -0
  12. package/dist/api/rest/api-generator.d.ts +158 -42
  13. package/dist/api/rest/auth-collection-writes.d.ts +85 -0
  14. package/dist/api/rest/field-access-query.d.ts +6 -2
  15. package/dist/api/rest/idempotency.d.ts +7 -1
  16. package/dist/api/rest/nested-write-access.d.ts +46 -0
  17. package/dist/api/rest/write-validation.d.ts +34 -2
  18. package/dist/api/types.d.ts +17 -1
  19. package/dist/{ast-schema-editor-CslO8Oje.js → ast-schema-editor-CWqS_sLJ.js} +411 -13
  20. package/dist/ast-schema-editor-CWqS_sLJ.js.map +1 -0
  21. package/dist/auth/access.d.ts +105 -0
  22. package/dist/auth/adapter-middleware.d.ts +2 -1
  23. package/dist/auth/address-ownership.d.ts +68 -0
  24. package/dist/auth/admin-roles-route.d.ts +4 -2
  25. package/dist/auth/admin-roles.d.ts +17 -20
  26. package/dist/auth/admin-user-ops.d.ts +35 -2
  27. package/dist/auth/admin-users-route.d.ts +1 -0
  28. package/dist/auth/api-keys/api-key-middleware.d.ts +56 -55
  29. package/dist/auth/api-keys/api-key-routes.d.ts +41 -11
  30. package/dist/auth/api-keys/api-key-store.d.ts +31 -8
  31. package/dist/auth/api-keys/api-key-types.d.ts +14 -16
  32. package/dist/auth/api-keys/http-operation.d.ts +19 -0
  33. package/dist/auth/api-keys/index.d.ts +11 -11
  34. package/dist/auth/api-keys/key-grant.d.ts +41 -0
  35. package/dist/auth/api-keys/legacy-permissions.d.ts +33 -0
  36. package/dist/auth/auth-hooks.d.ts +50 -7
  37. package/dist/auth/builtin-auth-adapter.d.ts +8 -0
  38. package/dist/auth/captcha.d.ts +5 -0
  39. package/dist/auth/cookie-utils.d.ts +7 -0
  40. package/dist/auth/deliverable-address.d.ts +6 -0
  41. package/dist/auth/email-change-routes.d.ts +41 -0
  42. package/dist/auth/expired-token-sweep.d.ts +67 -0
  43. package/dist/auth/impersonation.d.ts +110 -0
  44. package/dist/auth/index.d.ts +4 -2
  45. package/dist/auth/interfaces.d.ts +146 -65
  46. package/dist/auth/jwt.d.ts +66 -3
  47. package/dist/auth/magic-link-routes.d.ts +2 -6
  48. package/dist/auth/mfa-routes.d.ts +2 -9
  49. package/dist/auth/middleware.d.ts +17 -5
  50. package/dist/auth/oauth-signin-policy.d.ts +25 -8
  51. package/dist/auth/otp-routes.d.ts +2 -6
  52. package/dist/auth/passwordless-signup.d.ts +27 -0
  53. package/dist/auth/platform-token.d.ts +122 -0
  54. package/dist/auth/rate-limiter.d.ts +72 -1
  55. package/dist/auth/routes.d.ts +45 -0
  56. package/dist/auth/scope-routes.d.ts +22 -0
  57. package/dist/auth/session-routes.d.ts +18 -6
  58. package/dist/auth/token-revocation.d.ts +53 -1
  59. package/dist/auth/verify-credential.d.ts +28 -0
  60. package/dist/{auth-CCDpk2rn.js → auth-DMLngxn_.js} +2712 -711
  61. package/dist/auth-DMLngxn_.js.map +1 -0
  62. package/dist/backend-DTAOsLQc.js +30 -0
  63. package/dist/backend-DTAOsLQc.js.map +1 -0
  64. package/dist/backup/backup-common.d.ts +29 -0
  65. package/dist/backup/backup-routes.d.ts +24 -4
  66. package/dist/backup/backup-schedule.d.ts +33 -0
  67. package/dist/backup/backup-storage.d.ts +14 -0
  68. package/dist/backup/index.d.ts +2 -0
  69. package/dist/backup-CN0s50D2.js +444 -0
  70. package/dist/backup-CN0s50D2.js.map +1 -0
  71. package/dist/boot/bundle.d.ts +19 -0
  72. package/dist/boot/driver.d.ts +10 -0
  73. package/dist/boot/env.d.ts +51 -6
  74. package/dist/boot/fetch-bundle.d.ts +18 -1
  75. package/dist/boot/rls-audit-option.d.ts +26 -0
  76. package/dist/boot/security-headers.d.ts +26 -0
  77. package/dist/boot/sources.d.ts +1 -0
  78. package/dist/boot/static-routing.d.ts +56 -0
  79. package/dist/collection_patch-BRu-BvDv.js +472 -0
  80. package/dist/collection_patch-BRu-BvDv.js.map +1 -0
  81. package/dist/{contract-routes-eLxV0le1.js → contract-routes-fz8i4pxs.js} +17 -4
  82. package/dist/contract-routes-fz8i4pxs.js.map +1 -0
  83. package/dist/cron/cron-routes.d.ts +7 -2
  84. package/dist/cron/cron-scheduler.d.ts +146 -21
  85. package/dist/cron/cron-store.d.ts +76 -8
  86. package/dist/cron/index.d.ts +1 -1
  87. package/dist/{cron-loader-CQjvjpEw.js → cron-loader-CwaANlOG.js} +4 -4
  88. package/dist/cron-loader-CwaANlOG.js.map +1 -0
  89. package/dist/cron-routes-Bc-SB0Se.js +96 -0
  90. package/dist/cron-routes-Bc-SB0Se.js.map +1 -0
  91. package/dist/{cron-scheduler-COPQxlEq.js → cron-scheduler-CYQgco86.js} +427 -83
  92. package/dist/cron-scheduler-CYQgco86.js.map +1 -0
  93. package/dist/{cron-store-BYGZFNWk.js → cron-store-D2Q9-Aco.js} +139 -23
  94. package/dist/cron-store-D2Q9-Aco.js.map +1 -0
  95. package/dist/{ddl-bootstrap-CfNvxMuK.js → ddl-bootstrap-BaqMSa4Y.js} +3 -26
  96. package/dist/ddl-bootstrap-BaqMSa4Y.js.map +1 -0
  97. package/dist/email/index.d.ts +2 -2
  98. package/dist/email/link-base.d.ts +5 -4
  99. package/dist/email/smtp-email-service.d.ts +13 -1
  100. package/dist/email/templates.d.ts +31 -0
  101. package/dist/email/types.d.ts +29 -2
  102. package/dist/env.d.ts +25 -7
  103. package/dist/{errors-DWsX4yTd.js → errors-D6_y86c5.js} +102 -8
  104. package/dist/errors-D6_y86c5.js.map +1 -0
  105. package/dist/{function-loader-xnbDAPfa.js → function-loader-D7o5Epjj.js} +2 -2
  106. package/dist/{function-loader-xnbDAPfa.js.map → function-loader-D7o5Epjj.js.map} +1 -1
  107. package/dist/{function-routes-Chet4-lB.js → function-routes-CaNG4waN.js} +24 -12
  108. package/dist/function-routes-CaNG4waN.js.map +1 -0
  109. package/dist/functions/context.d.ts +17 -6
  110. package/dist/functions/guards.d.ts +22 -5
  111. package/dist/functions/index.d.ts +2 -2
  112. package/dist/functions/index.js +90 -36
  113. package/dist/functions/index.js.map +1 -1
  114. package/dist/{history-recorder-BQmB0P_j.js → history-recorder-Nr8zLvoU.js} +9 -7
  115. package/dist/history-recorder-Nr8zLvoU.js.map +1 -0
  116. package/dist/{history-store-CetkrBBD.js → history-store-rcAm_xFR.js} +2 -2
  117. package/dist/{history-store-CetkrBBD.js.map → history-store-rcAm_xFR.js.map} +1 -1
  118. package/dist/index.d.ts +14 -4
  119. package/dist/index.es.js +5733 -1551
  120. package/dist/index.es.js.map +1 -1
  121. package/dist/init/docs.d.ts +5 -2
  122. package/dist/init/health.d.ts +17 -2
  123. package/dist/init/shutdown.d.ts +18 -3
  124. package/dist/init.d.ts +54 -0
  125. package/dist/jobs/index.d.ts +2 -2
  126. package/dist/jobs/job-queue.d.ts +23 -2
  127. package/dist/jobs/job-store.d.ts +37 -5
  128. package/dist/jobs/types.d.ts +8 -6
  129. package/dist/{jobs-Bjr8DZAi.js → jobs-DqYNfquG.js} +306 -167
  130. package/dist/jobs-DqYNfquG.js.map +1 -0
  131. package/dist/{jwt-C4OW-DNq.js → jwt-R6bSPMjk.js} +114 -38
  132. package/dist/{jwt-C4OW-DNq.js.map → jwt-R6bSPMjk.js.map} +1 -1
  133. package/dist/{keys-Qfc4XieN.js → keys-GAVZqbqx.js} +18 -17
  134. package/dist/{keys-Qfc4XieN.js.map → keys-GAVZqbqx.js.map} +1 -1
  135. package/dist/{logger-DO2PZc4i.js → logger-D-S-hO5e.js} +26 -3
  136. package/dist/logger-D-S-hO5e.js.map +1 -0
  137. package/dist/{logs-routes-3EEzPjhl.js → logs-routes-DAdv37GI.js} +54 -11
  138. package/dist/logs-routes-DAdv37GI.js.map +1 -0
  139. package/dist/mcp/consent-page.d.ts +1 -1
  140. package/dist/mcp/mcp-routes.d.ts +45 -2
  141. package/dist/mcp/mcp-tools.d.ts +22 -10
  142. package/dist/mcp/oauth-metadata.d.ts +21 -16
  143. package/dist/mcp/oauth-routes.d.ts +34 -1
  144. package/dist/mcp/oauth-store.d.ts +29 -13
  145. package/dist/metrics/history-recorder.d.ts +1 -1
  146. package/dist/{openapi-generator-D8uFz-LW.js → openapi-generator-DAq_XVDu.js} +135 -22
  147. package/dist/openapi-generator-DAq_XVDu.js.map +1 -0
  148. package/dist/{proxy-Czngl3p9.js → proxy-qRlqeUmO.js} +2 -2
  149. package/dist/{proxy-Czngl3p9.js.map → proxy-qRlqeUmO.js.map} +1 -1
  150. package/dist/{query-parser-BleZmY18.js → query-parser-BgiKJKvc.js} +41 -82
  151. package/dist/query-parser-BgiKJKvc.js.map +1 -0
  152. package/dist/{request-timeout-C_4C2BeR.js → request-timeout-DgH7j8qO.js} +3 -3
  153. package/dist/{request-timeout-C_4C2BeR.js.map → request-timeout-DgH7j8qO.js.map} +1 -1
  154. package/dist/rls-audit/index.d.ts +4 -0
  155. package/dist/schema-edit/apply-schema-change.d.ts +63 -3
  156. package/dist/schema-edit/project-root.d.ts +3 -2
  157. package/dist/schema-edit/remote-source.d.ts +9 -4
  158. package/dist/{schema-editor-routes-DdLihzp0.js → schema-editor-routes-oIyuWl3L.js} +12 -7
  159. package/dist/schema-editor-routes-oIyuWl3L.js.map +1 -0
  160. package/dist/serve-spa.d.ts +58 -0
  161. package/dist/services/routed-realtime-service.d.ts +11 -0
  162. package/dist/soft-delete-params-BWPilMPF.js +59 -0
  163. package/dist/soft-delete-params-BWPilMPF.js.map +1 -0
  164. package/dist/{src-Br6ARbs6.js → src-CatHFUym.js} +439 -45
  165. package/dist/src-CatHFUym.js.map +1 -0
  166. package/dist/{src-1vL-I1Po.js → src-I3aG1PcY.js} +371 -81
  167. package/dist/src-I3aG1PcY.js.map +1 -0
  168. package/dist/storage/GCSStorageController.d.ts +13 -1
  169. package/dist/storage/LocalStorageController.d.ts +2 -0
  170. package/dist/storage/S3StorageController.d.ts +2 -0
  171. package/dist/storage/index.d.ts +2 -2
  172. package/dist/storage/keys.d.ts +12 -0
  173. package/dist/storage/property-limits.d.ts +41 -6
  174. package/dist/storage/rendition-cache.d.ts +11 -1
  175. package/dist/storage/request-keys.d.ts +82 -0
  176. package/dist/storage/requested-object.d.ts +74 -0
  177. package/dist/storage/routes.d.ts +36 -18
  178. package/dist/storage/tus-handler.d.ts +30 -5
  179. package/dist/storage/types.d.ts +36 -1
  180. package/dist/types-BfKcm9do.js.map +1 -1
  181. package/dist/utils/logger.d.ts +12 -0
  182. package/package.json +9 -9
  183. package/dist/GCSStorageController-CLIJXwGS.js.map +0 -1
  184. package/dist/S3StorageController-Dcuf8lMA.js.map +0 -1
  185. package/dist/admin-roles-vYdp_Pil.js +0 -36
  186. package/dist/admin-roles-vYdp_Pil.js.map +0 -1
  187. package/dist/admin_block-DxKLmdiv.js +0 -206
  188. package/dist/admin_block-DxKLmdiv.js.map +0 -1
  189. package/dist/ast-schema-editor-CslO8Oje.js.map +0 -1
  190. package/dist/auth/api-keys/api-key-permission-guard.d.ts +0 -65
  191. package/dist/auth-CCDpk2rn.js.map +0 -1
  192. package/dist/backup-DzI9jLwc.js +0 -192
  193. package/dist/backup-DzI9jLwc.js.map +0 -1
  194. package/dist/contract-routes-eLxV0le1.js.map +0 -1
  195. package/dist/cron-loader-CQjvjpEw.js.map +0 -1
  196. package/dist/cron-routes-B7CRGfiq.js +0 -72
  197. package/dist/cron-routes-B7CRGfiq.js.map +0 -1
  198. package/dist/cron-scheduler-COPQxlEq.js.map +0 -1
  199. package/dist/cron-store-BYGZFNWk.js.map +0 -1
  200. package/dist/ddl-bootstrap-CfNvxMuK.js.map +0 -1
  201. package/dist/errors-DWsX4yTd.js.map +0 -1
  202. package/dist/function-routes-Chet4-lB.js.map +0 -1
  203. package/dist/history-recorder-BQmB0P_j.js.map +0 -1
  204. package/dist/jobs-Bjr8DZAi.js.map +0 -1
  205. package/dist/logger-DO2PZc4i.js.map +0 -1
  206. package/dist/logs-routes-3EEzPjhl.js.map +0 -1
  207. package/dist/openapi-generator-D8uFz-LW.js.map +0 -1
  208. package/dist/query-parser-BleZmY18.js.map +0 -1
  209. package/dist/schema-editor-routes-DdLihzp0.js.map +0 -1
  210. package/dist/src-1vL-I1Po.js.map +0 -1
  211. package/dist/src-Br6ARbs6.js.map +0 -1
@@ -6,7 +6,7 @@
6
6
  * import cost or need it installed.
7
7
  */
8
8
  import { StorageController, GCSStorageConfig } from "./types.js";
9
- import { UploadFileProps, UploadFileResult, DownloadConfig, StorageListResult } from "@rebasepro/types";
9
+ import { UploadFileProps, UploadFileResult, DownloadConfig, DownloadMetadata, StorageListResult } from "@rebasepro/types";
10
10
  /**
11
11
  * Google Cloud Storage implementation of `StorageController`.
12
12
  *
@@ -25,6 +25,16 @@ export declare class GCSStorageController implements StorageController {
25
25
  */
26
26
  knownBuckets(): string[];
27
27
  putObject({ file, key, metadata, bucket }: UploadFileProps): Promise<UploadFileResult>;
28
+ /**
29
+ * Read the object's metadata and nothing else — no signing.
30
+ *
31
+ * Signing needs a private key. With `keyFilename` or `credentials` the
32
+ * client has one; on Cloud Run, GKE or GCE it has only the metadata
33
+ * server's token, and falls back to the IAM Credentials `signBlob` API,
34
+ * which the runtime account may call on itself only when it holds
35
+ * `iam.serviceAccounts.signBlob` there. That is not a default grant.
36
+ */
37
+ getMetadata(key: string, bucket?: string): Promise<DownloadMetadata | null>;
28
38
  getSignedUrl(key: string, bucket?: string): Promise<DownloadConfig>;
29
39
  getObject(key: string, bucket?: string): Promise<File | null>;
30
40
  deleteObject(key: string, bucket?: string): Promise<void>;
@@ -33,6 +43,8 @@ export declare class GCSStorageController implements StorageController {
33
43
  maxResults?: number;
34
44
  pageToken?: string;
35
45
  }): Promise<StorageListResult>;
46
+ /** See {@link StorageController.maxFileSize}. */
47
+ maxFileSize(): number;
36
48
  /**
37
49
  * Validate file before upload
38
50
  */
@@ -63,6 +63,8 @@ export declare class LocalStorageController implements StorageController {
63
63
  * depend on it having run.
64
64
  */
65
65
  private getFullPath;
66
+ /** See {@link StorageController.maxFileSize}. */
67
+ maxFileSize(): number;
66
68
  /**
67
69
  * Validate file before upload
68
70
  */
@@ -24,6 +24,8 @@ export declare class S3StorageController implements StorageController {
24
24
  * can reach — and a mistyped one came back as "file not found".
25
25
  */
26
26
  knownBuckets(): string[];
27
+ /** See {@link StorageController.maxFileSize}. */
28
+ maxFileSize(): number;
27
29
  /**
28
30
  * Validate file before upload
29
31
  */
@@ -21,8 +21,8 @@ export * from "./storage-registry.js";
21
21
  export { parseTransformOptions, transformImage, isTransformableImage, TransformCache } from "./image-transform.js";
22
22
  export type { ImageTransformOptions } from "./image-transform.js";
23
23
  export { TusHandler } from "./tus-handler.js";
24
- export { createUploadConstraintResolver, assertUploadWithinPropertyLimits, isAcceptedFile, readUploadPropertyContext, UPLOAD_COLLECTION_FIELD, UPLOAD_PROPERTY_FIELD } from "./property-limits.js";
25
- export type { UploadConstraints, ResolveUploadConstraints } from "./property-limits.js";
24
+ export { createUploadConstraintResolver, createUploadPathResolver, assertUploadWithinPropertyLimits, assertUploadWithinPathLimits, isAcceptedFile, readUploadPropertyContext, UPLOAD_COLLECTION_FIELD, UPLOAD_PROPERTY_FIELD } from "./property-limits.js";
25
+ export type { UploadConstraints, ResolveUploadConstraints, ResolveUploadPathConstraints } from "./property-limits.js";
26
26
  import { BackendStorageConfig, StorageController } from "./types.js";
27
27
  /**
28
28
  * Create a storage controller from a config object.
@@ -157,3 +157,15 @@ export declare function canonicalStorageBucket(rawBucket: string | undefined | n
157
157
  export declare function listingPrefix(rawPrefix: string): string | undefined;
158
158
  /** @see listingPrefix */
159
159
  export declare function folderKey(rawPrefix: string): string;
160
+ /**
161
+ * A listing asked for paging a controller cannot honour: a page size below one,
162
+ * or a page token it never issued.
163
+ *
164
+ * Refused rather than coerced. A page size of 0 answered an empty page whose
165
+ * next token was the one it had been handed, so `while (pageToken)` never
166
+ * ended; a token of `-1` read before the first entry and crashed. The route
167
+ * turns this into a 400.
168
+ */
169
+ export declare class InvalidListOptionsError extends Error {
170
+ constructor(message: string);
171
+ }
@@ -12,12 +12,14 @@ import type { CollectionConfig } from "@rebasepro/types";
12
12
  * executable in the avatar bucket, and the config that said otherwise was never
13
13
  * consulted.
14
14
  *
15
- * The limits are per *property*, so enforcing them needs to know which property
16
- * a request is for. Uploads carry that as context (a form field on `POST
17
- * /upload`, `Upload-Metadata` on the resumable path); when it is absent the
18
- * global cap is still the ceiling, exactly as before. That is the honest
19
- * fallback: an upload that names no property has no property limit to check,
20
- * and refusing every context-less upload would break every existing client.
15
+ * The limits are per *property*, and the server finds the property two ways.
16
+ * By where the file lands: a property's `storagePath` is where its files go, so
17
+ * every upload into it meets the property's limits (`createUploadPathResolver`)
18
+ * — the panel never named its property, and a direct caller need not. And by
19
+ * name, when the upload carries context (a form field on `POST /upload`,
20
+ * `Upload-Metadata` on the resumable path), which covers a property whose
21
+ * `storagePath` is a function. A key no property claims, uploaded with no
22
+ * context, meets the source's own limit alone.
21
23
  */
22
24
  /** What a property says a file may be. */
23
25
  export interface UploadConstraints {
@@ -39,6 +41,39 @@ export type ResolveUploadConstraints = (collectionSlug: string, propertyPath: st
39
41
  * to choose.
40
42
  */
41
43
  export declare function createUploadConstraintResolver(collections: readonly CollectionConfig[]): ResolveUploadConstraints;
44
+ /**
45
+ * The limits of every property whose storage path a key falls in.
46
+ *
47
+ * @param storageId the source the upload is written to, canonical.
48
+ * @param key the canonical key the upload is written to.
49
+ */
50
+ export type ResolveUploadPathConstraints = (storageId: string, key: string) => UploadConstraints[];
51
+ /**
52
+ * The storage-path rules of the collections this backend serves.
53
+ *
54
+ * A property's `maxSize` and `acceptedFiles` used to be checked only when an
55
+ * upload named the property — which the panel never did, and a direct caller
56
+ * simply does not — so the limits the docs called "enforced by the server"
57
+ * held for nobody. A property's `storagePath` is where its files go, so it is
58
+ * also where its limits hold: every upload into that path, through any door,
59
+ * meets them.
60
+ *
61
+ * A path computed by a function cannot be read without running it, and has no
62
+ * rule; neither has a property that declares no limits.
63
+ */
64
+ export declare function createUploadPathResolver(collections: readonly CollectionConfig[]): ResolveUploadPathConstraints;
65
+ /**
66
+ * Refuse an upload that no property claiming its path would accept.
67
+ *
68
+ * Several properties may share a path; the file is for one of them, so it is
69
+ * enough that one accepts it. When none does, the first one's refusal is the
70
+ * answer, naming its property.
71
+ */
72
+ export declare function assertUploadWithinPathLimits(constraints: readonly UploadConstraints[], file: {
73
+ size?: number;
74
+ type?: string;
75
+ name?: string;
76
+ }): void;
42
77
  /** Is this file one the property accepts? */
43
78
  export declare function isAcceptedFile(accepted: readonly string[] | undefined, contentType: string | undefined, fileName: string | undefined): boolean;
44
79
  /**
@@ -7,7 +7,17 @@ import type { StorageController } from "./types.js";
7
7
  * write down once, in the documentation, for every deployment.
8
8
  */
9
9
  export declare const RENDITION_PREFIX = "_rebase/renditions/";
10
- /** True for a key that names the reserved rendition space. */
10
+ /**
11
+ * True for a key that names the reserved rendition space — the prefix itself,
12
+ * or anything under it.
13
+ *
14
+ * Compared case-folded and with `\` read as a separator, because that is how
15
+ * the filesystem under a local bucket reads it: on macOS and Windows
16
+ * `_REBASE/Renditions/x.webp` is a file in the directory `_rebase/renditions/`
17
+ * names, and on Windows so is `_rebase\renditions\x.webp`. A check that only
18
+ * knew the one spelling refused the key and accepted the same file. NFKC
19
+ * folds the compatibility spellings (`ſ` for `s`) the filesystem folds too.
20
+ */
11
21
  export declare function isRenditionKey(key: string): boolean;
12
22
  export interface RenditionCacheConfig {
13
23
  /** Off unless set. See the module comment for why. */
@@ -0,0 +1,82 @@
1
+ /**
2
+ * The checks a caller-supplied key, bucket and storage source go through
3
+ * before any storage door acts on them, as HTTP answers.
4
+ *
5
+ * Shared by the REST routes and the resumable (TUS) handler, which parses its
6
+ * own `Upload-Metadata` and so cannot lean on the routes. Each door spelling
7
+ * these on its own is how one of them came to canonicalize a key without
8
+ * refusing the reserved rendition prefix — which made TUS the way to write the
9
+ * bytes a later transform serves. One module both doors import keeps every
10
+ * write path's idea of an acceptable key and bucket the same.
11
+ */
12
+ import { ApiError } from "../api/errors.js";
13
+ import { type RequestedStorageObject } from "./requested-object.js";
14
+ import type { StorageController } from "./types.js";
15
+ /**
16
+ * Canonicalize a caller-supplied storage key, answering 400 when it names
17
+ * something other than what it says.
18
+ *
19
+ * The single place a request's key becomes canonical. Every door runs its key
20
+ * through this before anything else touches it, so the authorize hook, the
21
+ * storage controller and the minted download token are all looking at the same
22
+ * string — which is the only thing that makes the hook's answer meaningful.
23
+ * See `keys.ts` for why an unacceptable key is refused rather than repaired.
24
+ */
25
+ export declare function canonicalKeyOrBadRequest(key: string): string;
26
+ /**
27
+ * The object a `/file/*`, `/metadata/*` or `DELETE /file/*` request's wildcard
28
+ * path names, answering 400 when it names none.
29
+ *
30
+ * Derived by {@link requestedStorageObject}, the function `publicObjectAuth`
31
+ * and `fileTokenAuth` derive it with, so the key the route acts on is the key
32
+ * they decided about.
33
+ */
34
+ export declare function requestedObjectOrBadRequest(wildcard: string): RequestedStorageObject;
35
+ /**
36
+ * {@link requestedObjectOrBadRequest} for a path that is already text rather
37
+ * than a URL path — the folder route's JSON body.
38
+ */
39
+ export declare function objectOfPathOrBadRequest(path: string): RequestedStorageObject;
40
+ /**
41
+ * Canonicalize a caller-supplied bucket name, answering 400 when it is not one.
42
+ *
43
+ * The bucket's counterpart to {@link canonicalKeyOrBadRequest}, and it exists
44
+ * for the same reason: the value routes a write, so it has to be checked where
45
+ * it enters rather than where it is used. Applied at every entry point a bucket
46
+ * has — the upload route's multipart body, the folder route's JSON body, the
47
+ * `?bucket=` query, and the TUS `Upload-Metadata` header.
48
+ */
49
+ export declare function canonicalBucketOrBadRequest(bucket: string | undefined | null): string | undefined;
50
+ /**
51
+ * The bucket a read or a listing may use, or a refusal naming what is served.
52
+ *
53
+ * Only checked against a controller that says what it serves
54
+ * ({@link StorageController.knownBuckets}); a custom implementation that does
55
+ * not is handed whatever the caller wrote.
56
+ */
57
+ export declare function servedBucketOrRefuse(bucket: string | undefined, controller: StorageController, sources: string[]): string | undefined;
58
+ /**
59
+ * The bucket a write may use, or a refusal naming what is served.
60
+ *
61
+ * On local storage a write may bring a bucket into existence:
62
+ * `putObject({ bucket: "media" })` creates `<root>/media`, which is deliberate,
63
+ * so only the *shape* of the name is checked there (by
64
+ * {@link canonicalBucketOrBadRequest}, inside the storage root). That reasoning
65
+ * is local's alone. An object store's bucket is not created by a write — the
66
+ * name goes to the provider as given — so on every other controller a write is
67
+ * held to the same list a read is, or `bucket=prod-db-backups` on an upload
68
+ * writes into any bucket the deployment's credentials reach.
69
+ */
70
+ export declare function writableBucketOrRefuse(bucket: string | undefined, controller: StorageController, sources: string[]): string | undefined;
71
+ /**
72
+ * A request that names no storage source, on a deployment with no default one.
73
+ *
74
+ * Reachable on purpose: production drops a `local` default rather than
75
+ * crash-looping, and keeps the named buckets that are bound. Those keep
76
+ * serving; only a request that names none has nowhere to go. 501 rather than
77
+ * 503 for the reason the no-storage stub gives — this is permanent until the
78
+ * project names a default, and the client's offline queue retries 503 forever.
79
+ *
80
+ * @param sources the storage sources this deployment does serve.
81
+ */
82
+ export declare function noDefaultStorageSourceError(sources: string[]): ApiError;
@@ -0,0 +1,74 @@
1
+ /**
2
+ * Which object a storage request's URL path names.
3
+ *
4
+ * Three parties read the path of a `GET /file/*`, `GET /metadata/*` or
5
+ * `DELETE /file/*`: the route, which serves or deletes an object;
6
+ * `publicObjectAuth`, which lets an anonymous caller through when that object
7
+ * is public; and `fileTokenAuth`, which compares it with the path a download
8
+ * token grants. A decision is only about the object acted on if it is made on
9
+ * the same key, so all three derive it here — the wildcard, the decoding, the
10
+ * bucket segment and the canonical key — and none of them spells a step of its
11
+ * own.
12
+ *
13
+ * They used to. `publicObjectAuth` judged the raw path with a check that strips
14
+ * everything up to a `://`, while the route canonicalized it, folding `//` to
15
+ * `/`: `GET /file/notes://public/secret.txt` was public to the one and served
16
+ * the private key `notes:/public/secret.txt` from the other, with the authorize
17
+ * hook never asked.
18
+ *
19
+ * Nothing here parses a scheme. A request path is a key, optionally behind the
20
+ * one bucket segment the routes recognise; a `://` in it is a `:` followed by
21
+ * an empty segment, and canonicalization folds the empty segment away.
22
+ */
23
+ /** The object a request path names. */
24
+ export interface RequestedStorageObject {
25
+ /** The bucket. Always `"default"`: the only bucket a request path can name. */
26
+ bucket: string;
27
+ /** The canonical key — the one the hook is asked about and the controller acts on. */
28
+ key: string;
29
+ }
30
+ /**
31
+ * The wildcard part of a storage route's path, still percent-encoded.
32
+ *
33
+ * Hono's `c.req.param('*')` does not work reliably in sub-routers mounted
34
+ * via `app.route(prefix, subRouter)`. Instead it is derived from the
35
+ * fully-resolved `c.req.path` and `c.req.routePath`.
36
+ *
37
+ * For a route `/metadata/*` mounted at `/api/storage`, a request to
38
+ * `/api/storage/metadata/default/file.jpg` yields routePath
39
+ * `/api/storage/metadata/*`. The prefix (everything before `/*`) is stripped,
40
+ * plus one character for the trailing `/`, to obtain `default/file.jpg`.
41
+ */
42
+ export declare function storageRequestWildcard(c: {
43
+ req: {
44
+ path: string;
45
+ routePath: string;
46
+ };
47
+ }): string;
48
+ /**
49
+ * The object a decoded path names: a key, behind an optional `default/` bucket
50
+ * segment (matched case-insensitively). Throws {@link InvalidStorageKeyError}
51
+ * when the key cannot be canonicalized.
52
+ *
53
+ * For a path that is already text — the folder route's JSON body. A URL path
54
+ * goes through {@link requestedStorageObject}, which decodes it first.
55
+ */
56
+ export declare function storageObjectOfPath(decodedPath: string): RequestedStorageObject;
57
+ /**
58
+ * The object a request's wildcard path names, or {@link InvalidStorageKeyError}.
59
+ *
60
+ * The wildcard arrives as Hono leaves it — `decodeURI`d, with the reserved
61
+ * characters (`/`, `:`, `%25` among them) still escaped — so one
62
+ * `decodeURIComponent` yields the path the client encoded. A `%` that does not
63
+ * begin an escape names no key, and is refused like any other key that cannot be
64
+ * canonicalized rather than thrown as a `URIError`.
65
+ */
66
+ export declare function requestedStorageObject(wildcard: string): RequestedStorageObject;
67
+ /**
68
+ * {@link requestedStorageObject}, or `null` when the path names no object.
69
+ *
70
+ * For the middleware, which must fail closed without an exception: a path that
71
+ * names no object is neither public nor covered by any download token, and the
72
+ * route answers it with a 400 of its own.
73
+ */
74
+ export declare function tryRequestedStorageObject(wildcard: string): RequestedStorageObject | null;
@@ -10,20 +10,35 @@ import { Hono } from "hono";
10
10
  import { StorageController, type StorageAuthorize, type StorageAuthorizeData } from "./types.js";
11
11
  import { type StorageRegistry } from "./storage-registry.js";
12
12
  import { type StorageSourceDefinition, type AuthAdapter } from "@rebasepro/types";
13
- import { type ResolveUploadConstraints } from "./property-limits.js";
13
+ import { type ResolveUploadConstraints, type ResolveUploadPathConstraints } from "./property-limits.js";
14
14
  import { HonoEnv } from "../api/types.js";
15
15
  import { type StorageTrigger } from "./triggers.js";
16
16
  import { type RenditionCacheConfig } from "./rendition-cache.js";
17
+ /**
18
+ * The policy every SVG response carries.
19
+ *
20
+ * An SVG embedded with `<img>` never runs script. Opened directly — a link, a
21
+ * new tab, an `<iframe>` — it is a document on the API origin, and its
22
+ * `<script>` would run there, next to the refresh cookie. `sandbox` gives that
23
+ * document an opaque origin with scripts disabled, and `default-src 'none'`
24
+ * stops it loading anything; `style-src 'unsafe-inline'` keeps the inline
25
+ * styles most SVGs are drawn with. It is what GitHub serves user content
26
+ * under. Serving SVG as a download instead made every SVG logo a broken
27
+ * thumbnail in the panel.
28
+ */
29
+ export declare const SVG_CONTENT_SECURITY_POLICY = "default-src 'none'; style-src 'unsafe-inline'; sandbox";
17
30
  /**
18
31
  * Decide what to actually serve for a stored content type.
19
32
  *
20
- * Returns the type to send and whether to force a download. The check is an
33
+ * Returns the type to send, whether to force a download, and the
34
+ * `Content-Security-Policy` the response must carry, if any. The check is an
21
35
  * allowlist rather than a blocklist of dangerous types: the set of types a
22
36
  * browser will execute grows, and the set we want to render inline does not.
23
37
  */
24
38
  export declare function resolveServedContentType(storedContentType: string): {
25
39
  contentType: string;
26
40
  attachment: boolean;
41
+ contentSecurityPolicy?: string;
27
42
  };
28
43
  export interface StorageRoutesConfig {
29
44
  /**
@@ -73,6 +88,13 @@ export interface StorageRoutesConfig {
73
88
  * to the global cap exactly as before.
74
89
  */
75
90
  uploadConstraints?: ResolveUploadConstraints;
91
+ /**
92
+ * The limits of the properties whose `storagePath` an upload's key falls
93
+ * in, by source and key — see `createUploadPathResolver`. Applied to every
94
+ * upload, whether or not it names a property, so a property's limits hold
95
+ * for every file written where its files go.
96
+ */
97
+ uploadPathConstraints?: ResolveUploadPathConstraints;
76
98
  /**
77
99
  * When provided, storage routes delegate auth to this adapter instead
78
100
  * of the built-in JWT module. This mirrors how data routes use
@@ -105,25 +127,21 @@ export interface StorageRoutesConfig {
105
127
  * Run something when an object lands, or when one goes. See `triggers.ts`.
106
128
  */
107
129
  triggers?: StorageTrigger[];
130
+ /**
131
+ * How long the download token `/metadata` mints for a private object stays
132
+ * valid, in seconds. {@link DEFAULT_DOWNLOAD_TOKEN_TTL_SECONDS} unless set;
133
+ * at most {@link MAX_DOWNLOAD_TOKEN_TTL_SECONDS}.
134
+ */
135
+ downloadTokenTtlSeconds?: number;
108
136
  }
137
+ /** Five minutes: long enough to render a page of thumbnails, short enough to be worthless in a log. */
138
+ export declare const DEFAULT_DOWNLOAD_TOKEN_TTL_SECONDS = 300;
109
139
  /**
110
- * Extract the wildcard portion of a route path from the full request path.
111
- *
112
- * Hono's `c.req.param('*')` does not work reliably in sub-routers mounted
113
- * via `app.route(prefix, subRouter)`. Instead we derive the wildcard value
114
- * from the fully-resolved `c.req.path` and `c.req.routePath`.
115
- *
116
- * For a route `/metadata/*` mounted at `/api/storage`, a request to
117
- * `/api/storage/metadata/default/file.jpg` yields routePath
118
- * `/api/storage/metadata/*`. We strip the prefix (everything before `/*`)
119
- * plus one character for the trailing `/` to obtain `default/file.jpg`.
140
+ * A week. The token travels in a URL — into access logs, Referer headers and
141
+ * browser history — so a lifetime past this is a permanent link to a private
142
+ * file. A file that must be linked forever belongs under the public prefix.
120
143
  */
121
- export declare function extractWildcardPath(c: {
122
- req: {
123
- path: string;
124
- routePath: string;
125
- };
126
- }): string;
144
+ export declare const MAX_DOWNLOAD_TOKEN_TTL_SECONDS: number;
127
145
  /**
128
146
  * Create storage REST API routes
129
147
  */
@@ -10,7 +10,7 @@
10
10
  import type { Context } from "hono";
11
11
  import type { StorageController } from "./types.js";
12
12
  import { type StorageRegistry } from "./storage-registry.js";
13
- import { type ResolveUploadConstraints } from "./property-limits.js";
13
+ import { type ResolveUploadConstraints, type ResolveUploadPathConstraints } from "./property-limits.js";
14
14
  /**
15
15
  * TUS resumable upload handler.
16
16
  *
@@ -65,6 +65,12 @@ export declare class TusHandler {
65
65
  * accept is refused before the first chunk rather than after the last.
66
66
  */
67
67
  private uploadConstraints?;
68
+ /**
69
+ * The limits of the properties whose storage path the upload's key
70
+ * falls in — checked whether or not the upload names a property, as
71
+ * `POST /upload` checks them.
72
+ */
73
+ private uploadPathConstraints?;
68
74
  private uploads;
69
75
  private tusDir;
70
76
  private cleanupTimer?;
@@ -123,7 +129,13 @@ export declare class TusHandler {
123
129
  * and the metadata's content type, so a file the property will not
124
130
  * accept is refused before the first chunk rather than after the last.
125
131
  */
126
- uploadConstraints?: ResolveUploadConstraints | undefined);
132
+ uploadConstraints?: ResolveUploadConstraints | undefined,
133
+ /**
134
+ * The limits of the properties whose storage path the upload's key
135
+ * falls in — checked whether or not the upload names a property, as
136
+ * `POST /upload` checks them.
137
+ */
138
+ uploadPathConstraints?: ResolveUploadPathConstraints | undefined);
127
139
  /** Ensure the temp directory exists. */
128
140
  private ensureDir;
129
141
  /** Start periodic cleanup of stale uploads. */
@@ -136,8 +148,21 @@ export declare class TusHandler {
136
148
  * Format: `key base64value,key2 base64value2`
137
149
  */
138
150
  private parseMetadata;
139
- /** `OPTIONS /tus` — TUS capability discovery. */
140
- options(): Response;
151
+ /** The controller an upload to this storage source is written to. */
152
+ private targetFor;
153
+ /**
154
+ * The largest upload this source takes: the source's own limit, under the
155
+ * deployment's and the protocol ceiling. One function for what `OPTIONS`
156
+ * advertises and what `create` enforces, which used to be 5 GB and 50 MB.
157
+ */
158
+ private limitFor;
159
+ /**
160
+ * `OPTIONS /tus` — TUS capability discovery.
161
+ *
162
+ * `Tus-Max-Size` is the limit `create` holds this source to, for the source
163
+ * named by `?storageId` (the default one otherwise).
164
+ */
165
+ options(c?: Context): Response;
141
166
  /** `POST /tus` — Create a new upload. */
142
167
  create(c: Context): Promise<Response>;
143
168
  /**
@@ -162,7 +187,7 @@ export declare class TusHandler {
162
187
  private ownedUpload;
163
188
  /** `HEAD /tus/:id` — Query upload progress. */
164
189
  head(c: Context, id: string): Response;
165
- /** `PATCH /tus/:id` — Append data to an upload. */
190
+ /** `PATCH /tus/:id` — Write one chunk of an upload, at its offset. */
166
191
  patch(c: Context, id: string): Promise<Response>;
167
192
  /** `DELETE /tus/:id` — Cancel and remove an upload. */
168
193
  delete(c: Context, id: string): Promise<Response>;
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Storage configuration and types for Rebase backend
3
3
  */
4
- import { UploadFileProps, UploadFileResult, DownloadConfig, StorageListResult } from "@rebasepro/types";
4
+ import { UploadFileProps, UploadFileResult, DownloadConfig, DownloadMetadata, StorageListResult } from "@rebasepro/types";
5
5
  /**
6
6
  * Local filesystem storage configuration
7
7
  */
@@ -23,6 +23,14 @@ export interface LocalStorageConfig {
23
23
  * production, where an unbound object store stays unbound.
24
24
  */
25
25
  standsInFor?: string;
26
+ /**
27
+ * Set when nothing chose this backend: no `STORAGE_TYPE` and no declared
28
+ * engine, so local disk is only the default a source falls back to.
29
+ * Production drops a local backend either way. This only decides how that
30
+ * is reported: an implicit default being dropped means the project uses no
31
+ * storage, which is not a misconfiguration.
32
+ */
33
+ implicit?: boolean;
26
34
  }
27
35
  /**
28
36
  * S3-compatible storage configuration (works with AWS S3 and MinIO)
@@ -100,6 +108,22 @@ export interface StorageController {
100
108
  * Get a download URL (signed URL equivalent) for an object
101
109
  */
102
110
  getSignedUrl(key: string, bucket?: string): Promise<DownloadConfig>;
111
+ /**
112
+ * Describe an object — size, type, custom metadata — without producing a
113
+ * URL for it, or `null` when there is no such object.
114
+ *
115
+ * `GET /metadata/*` wants only this: the client builds its own `/file/*`
116
+ * URL and spends the download token the route mints. Asking
117
+ * `getSignedUrl` for it made every metadata read sign a URL nobody used,
118
+ * and on GCS signing is not free — without a key file the client asks the
119
+ * IAM Credentials API to sign, which needs `iam.serviceAccounts.signBlob`
120
+ * on the runtime account itself. Cloud Run does not grant that, so every
121
+ * private object answered 500 there.
122
+ *
123
+ * A controller that does not implement this keeps the old behaviour: the
124
+ * route falls back to `getSignedUrl` and reads its `metadata`.
125
+ */
126
+ getMetadata?(key: string, bucket?: string): Promise<DownloadMetadata | null>;
103
127
  /**
104
128
  * Get object as a File
105
129
  */
@@ -143,6 +167,17 @@ export interface StorageController {
143
167
  * when the caller names none, and each provider maps it to its own.
144
168
  */
145
169
  knownBuckets?(): string[];
170
+ /**
171
+ * The largest file this controller accepts, in bytes.
172
+ *
173
+ * Every door that takes a file reads it, so the number a client is told is
174
+ * the number it is held to: the upload route checks it before anything is
175
+ * stored, the resumable route checks it at creation — before the first
176
+ * chunk rather than after the last — and advertises it as `Tus-Max-Size`,
177
+ * and the server's upload body limit is the largest of them. A controller
178
+ * that does not implement this is held to the deployment-wide limit alone.
179
+ */
180
+ maxFileSize?(): number;
146
181
  }
147
182
  /**
148
183
  * Default maximum file size (50MB)
@@ -1 +1 @@
1
- {"version":3,"file":"types-BfKcm9do.js","names":[],"sources":["../src/storage/types.ts"],"sourcesContent":["/**\n * Storage configuration and types for Rebase backend\n */\n\nimport { StorageSource, UploadFileProps, UploadFileResult, DownloadConfig, StorageListResult, StorageReference } from \"@rebasepro/types\";\n\n/**\n * Local filesystem storage configuration\n */\nexport interface LocalStorageConfig {\n type: \"local\";\n /** Base directory for file storage (e.g., './uploads') */\n basePath: string;\n /** Maximum file size in bytes (default: 50MB) */\n maxFileSize?: number;\n /** Allowed MIME types (if not set, all types allowed) */\n allowedMimeTypes?: string[];\n /** Base URL for generating download URLs (default: auto-detected from request) */\n baseUrl?: string;\n /**\n * Set when this local backend stands in for an object store the source\n * declared and nothing bound — `bucket(\"media\", { engine: \"s3\" })` with no\n * `S3_BUCKET__MEDIA` in a development process. Names the engine it stands\n * in for, so boot can say so and `rebase status` can show it. Never set in\n * production, where an unbound object store stays unbound.\n */\n standsInFor?: string;\n}\n\n/**\n * S3-compatible storage configuration (works with AWS S3 and MinIO)\n */\nexport interface S3StorageConfig {\n type: \"s3\";\n /** S3 bucket name */\n bucket: string;\n /** AWS region (e.g., 'us-east-1') */\n region?: string;\n /** Custom endpoint URL (required for MinIO, Cloudflare R2, Hetzner Object Storage) */\n endpoint?: string;\n /** AWS access key ID */\n accessKeyId: string;\n /** AWS secret access key */\n secretAccessKey: string;\n /** Use path-style URLs (required for MinIO) */\n forcePathStyle?: boolean;\n /** Maximum file size in bytes (default: 50MB) */\n maxFileSize?: number;\n /** Allowed MIME types (if not set, all types allowed) */\n allowedMimeTypes?: string[];\n /** URL expiration time in seconds for signed URLs (default: 3600) */\n signedUrlExpiration?: number;\n}\n\n/**\n * Google Cloud Storage configuration (works with GCS and Firebase Storage)\n */\nexport interface GCSStorageConfig {\n type: \"gcs\";\n /** GCS bucket name (e.g. \"my-project.appspot.com\" for Firebase Storage) */\n bucket: string;\n /** GCP project ID (optional, auto-detected from credentials) */\n projectId?: string;\n /** Path to service account JSON key file */\n keyFilename?: string;\n /** Service account credentials object (alternative to keyFilename) */\n credentials?: { client_email: string; private_key: string; project_id?: string };\n /** Maximum file size in bytes (default: 50MB) */\n maxFileSize?: number;\n /** Allowed MIME types */\n allowedMimeTypes?: string[];\n /** Signed URL expiration in seconds (default: 3600) */\n signedUrlExpiration?: number;\n}\n\n/**\n * Storage configuration — local filesystem, S3-compatible, or Google Cloud Storage.\n *\n * **Built-in providers:**\n * - `local` — Zero-config filesystem storage. Great for dev and single-server deployments (Hetzner, bare metal).\n * - `s3` — Any S3-compatible provider. AWS S3, Cloudflare R2, MinIO, Hetzner Object Storage,\n * Backblaze B2, DigitalOcean Spaces, and even GCS (via its S3-compatible interoperability API).\n * - `gcs` — Native Google Cloud Storage / Firebase Storage via `@google-cloud/storage`.\n *\n * **Custom providers:**\n * For other cloud storage (Azure Blob, etc.), implement the `StorageController`\n * interface and pass the instance directly to the `storage` config.\n */\nexport type BackendStorageConfig = LocalStorageConfig | S3StorageConfig | GCSStorageConfig;\n\n/** What a storage request is trying to do to an object. */\nexport type {\n StorageOperation,\n StorageAuthorizeUser,\n StorageAuthorizeContext,\n StorageAuthorizeData,\n StorageAuthorize\n} from \"@rebasepro/types\";\n\n/**\n * Storage controller interface for backend implementations\n */\nexport interface StorageController {\n /**\n * Upload an object\n */\n putObject(props: UploadFileProps): Promise<UploadFileResult>;\n\n /**\n * Get a download URL (signed URL equivalent) for an object\n */\n getSignedUrl(key: string, bucket?: string): Promise<DownloadConfig>;\n\n /**\n * Get object as a File\n */\n getObject(key: string, bucket?: string): Promise<File | null>;\n\n /**\n * Delete an object\n */\n deleteObject(key: string, bucket?: string): Promise<void>;\n\n /**\n * List objects in a prefix\n */\n listObjects(prefix: string, options?: {\n bucket?: string;\n maxResults?: number;\n pageToken?: string;\n }): Promise<StorageListResult>;\n\n /**\n * Get the storage provider identifier.\n *\n * Built-in values are `'local'` and `'s3'`. Custom implementations\n * should return their own identifier (e.g. `'gcs'`, `'azure'`).\n */\n getType(): string;\n\n /**\n * The buckets this controller serves, if it knows.\n *\n * The `bucket` a request may name is not a free-text field: on S3 and GCS it\n * goes straight to the provider, so an unvalidated one addresses *any*\n * bucket the deployment's credentials can reach, and locally it names a\n * directory the framework would create on demand. Either way, a caller who\n * mistypes it gets \"file not found\" — the same answer as a missing object —\n * with nothing to say the bucket was the problem.\n *\n * So a controller that knows its buckets says so, and the routes refuse\n * anything else with `UNKNOWN_STORAGE_SOURCE` naming what is served. A\n * controller that does not implement this keeps the old behaviour and is\n * handed whatever the caller wrote — a custom implementation may address\n * buckets this framework has no way to enumerate.\n *\n * `\"default\"` is always among them: it is the logical name every route uses\n * when the caller names none, and each provider maps it to its own.\n */\n knownBuckets?(): string[];\n}\n\n/**\n * Default maximum file size (50MB)\n */\nexport const DEFAULT_MAX_FILE_SIZE = 50 * 1024 * 1024;\n\n/**\n * Common image MIME types\n */\nexport const IMAGE_MIME_TYPES = [\n \"image/jpeg\",\n \"image/png\",\n \"image/gif\",\n \"image/webp\",\n \"image/svg+xml\",\n \"image/bmp\",\n \"image/tiff\"\n];\n\n/**\n * Common document MIME types\n */\nexport const DOCUMENT_MIME_TYPES = [\n \"application/pdf\",\n \"application/msword\",\n \"application/vnd.openxmlformats-officedocument.wordprocessingml.document\",\n \"application/vnd.ms-excel\",\n \"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet\",\n \"application/vnd.ms-powerpoint\",\n \"application/vnd.openxmlformats-officedocument.presentationml.presentation\",\n \"text/plain\",\n \"text/csv\"\n];\n"],"mappings":";;;;;;;;AAqKA,IAAa,wBAAwB,KAAK,OAAO;;;;AAKjD,IAAa,mBAAmB;CAC5B;CACA;CACA;CACA;CACA;CACA;CACA;AACJ;;;;AAKA,IAAa,sBAAsB;CAC/B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACJ"}
1
+ {"version":3,"file":"types-BfKcm9do.js","names":[],"sources":["../src/storage/types.ts"],"sourcesContent":["/**\n * Storage configuration and types for Rebase backend\n */\n\nimport { StorageSource, UploadFileProps, UploadFileResult, DownloadConfig, DownloadMetadata, StorageListResult, StorageReference } from \"@rebasepro/types\";\n\n/**\n * Local filesystem storage configuration\n */\nexport interface LocalStorageConfig {\n type: \"local\";\n /** Base directory for file storage (e.g., './uploads') */\n basePath: string;\n /** Maximum file size in bytes (default: 50MB) */\n maxFileSize?: number;\n /** Allowed MIME types (if not set, all types allowed) */\n allowedMimeTypes?: string[];\n /** Base URL for generating download URLs (default: auto-detected from request) */\n baseUrl?: string;\n /**\n * Set when this local backend stands in for an object store the source\n * declared and nothing bound — `bucket(\"media\", { engine: \"s3\" })` with no\n * `S3_BUCKET__MEDIA` in a development process. Names the engine it stands\n * in for, so boot can say so and `rebase status` can show it. Never set in\n * production, where an unbound object store stays unbound.\n */\n standsInFor?: string;\n /**\n * Set when nothing chose this backend: no `STORAGE_TYPE` and no declared\n * engine, so local disk is only the default a source falls back to.\n * Production drops a local backend either way. This only decides how that\n * is reported: an implicit default being dropped means the project uses no\n * storage, which is not a misconfiguration.\n */\n implicit?: boolean;\n}\n\n/**\n * S3-compatible storage configuration (works with AWS S3 and MinIO)\n */\nexport interface S3StorageConfig {\n type: \"s3\";\n /** S3 bucket name */\n bucket: string;\n /** AWS region (e.g., 'us-east-1') */\n region?: string;\n /** Custom endpoint URL (required for MinIO, Cloudflare R2, Hetzner Object Storage) */\n endpoint?: string;\n /** AWS access key ID */\n accessKeyId: string;\n /** AWS secret access key */\n secretAccessKey: string;\n /** Use path-style URLs (required for MinIO) */\n forcePathStyle?: boolean;\n /** Maximum file size in bytes (default: 50MB) */\n maxFileSize?: number;\n /** Allowed MIME types (if not set, all types allowed) */\n allowedMimeTypes?: string[];\n /** URL expiration time in seconds for signed URLs (default: 3600) */\n signedUrlExpiration?: number;\n}\n\n/**\n * Google Cloud Storage configuration (works with GCS and Firebase Storage)\n */\nexport interface GCSStorageConfig {\n type: \"gcs\";\n /** GCS bucket name (e.g. \"my-project.appspot.com\" for Firebase Storage) */\n bucket: string;\n /** GCP project ID (optional, auto-detected from credentials) */\n projectId?: string;\n /** Path to service account JSON key file */\n keyFilename?: string;\n /** Service account credentials object (alternative to keyFilename) */\n credentials?: { client_email: string; private_key: string; project_id?: string };\n /** Maximum file size in bytes (default: 50MB) */\n maxFileSize?: number;\n /** Allowed MIME types */\n allowedMimeTypes?: string[];\n /** Signed URL expiration in seconds (default: 3600) */\n signedUrlExpiration?: number;\n}\n\n/**\n * Storage configuration — local filesystem, S3-compatible, or Google Cloud Storage.\n *\n * **Built-in providers:**\n * - `local` — Zero-config filesystem storage. Great for dev and single-server deployments (Hetzner, bare metal).\n * - `s3` — Any S3-compatible provider. AWS S3, Cloudflare R2, MinIO, Hetzner Object Storage,\n * Backblaze B2, DigitalOcean Spaces, and even GCS (via its S3-compatible interoperability API).\n * - `gcs` — Native Google Cloud Storage / Firebase Storage via `@google-cloud/storage`.\n *\n * **Custom providers:**\n * For other cloud storage (Azure Blob, etc.), implement the `StorageController`\n * interface and pass the instance directly to the `storage` config.\n */\nexport type BackendStorageConfig = LocalStorageConfig | S3StorageConfig | GCSStorageConfig;\n\n/** What a storage request is trying to do to an object. */\nexport type {\n StorageOperation,\n StorageAuthorizeUser,\n StorageAuthorizeContext,\n StorageAuthorizeData,\n StorageAuthorize\n} from \"@rebasepro/types\";\n\n/**\n * Storage controller interface for backend implementations\n */\nexport interface StorageController {\n /**\n * Upload an object\n */\n putObject(props: UploadFileProps): Promise<UploadFileResult>;\n\n /**\n * Get a download URL (signed URL equivalent) for an object\n */\n getSignedUrl(key: string, bucket?: string): Promise<DownloadConfig>;\n\n /**\n * Describe an object — size, type, custom metadata — without producing a\n * URL for it, or `null` when there is no such object.\n *\n * `GET /metadata/*` wants only this: the client builds its own `/file/*`\n * URL and spends the download token the route mints. Asking\n * `getSignedUrl` for it made every metadata read sign a URL nobody used,\n * and on GCS signing is not free — without a key file the client asks the\n * IAM Credentials API to sign, which needs `iam.serviceAccounts.signBlob`\n * on the runtime account itself. Cloud Run does not grant that, so every\n * private object answered 500 there.\n *\n * A controller that does not implement this keeps the old behaviour: the\n * route falls back to `getSignedUrl` and reads its `metadata`.\n */\n getMetadata?(key: string, bucket?: string): Promise<DownloadMetadata | null>;\n\n /**\n * Get object as a File\n */\n getObject(key: string, bucket?: string): Promise<File | null>;\n\n /**\n * Delete an object\n */\n deleteObject(key: string, bucket?: string): Promise<void>;\n\n /**\n * List objects in a prefix\n */\n listObjects(prefix: string, options?: {\n bucket?: string;\n maxResults?: number;\n pageToken?: string;\n }): Promise<StorageListResult>;\n\n /**\n * Get the storage provider identifier.\n *\n * Built-in values are `'local'` and `'s3'`. Custom implementations\n * should return their own identifier (e.g. `'gcs'`, `'azure'`).\n */\n getType(): string;\n\n /**\n * The buckets this controller serves, if it knows.\n *\n * The `bucket` a request may name is not a free-text field: on S3 and GCS it\n * goes straight to the provider, so an unvalidated one addresses *any*\n * bucket the deployment's credentials can reach, and locally it names a\n * directory the framework would create on demand. Either way, a caller who\n * mistypes it gets \"file not found\" — the same answer as a missing object —\n * with nothing to say the bucket was the problem.\n *\n * So a controller that knows its buckets says so, and the routes refuse\n * anything else with `UNKNOWN_STORAGE_SOURCE` naming what is served. A\n * controller that does not implement this keeps the old behaviour and is\n * handed whatever the caller wrote — a custom implementation may address\n * buckets this framework has no way to enumerate.\n *\n * `\"default\"` is always among them: it is the logical name every route uses\n * when the caller names none, and each provider maps it to its own.\n */\n knownBuckets?(): string[];\n\n /**\n * The largest file this controller accepts, in bytes.\n *\n * Every door that takes a file reads it, so the number a client is told is\n * the number it is held to: the upload route checks it before anything is\n * stored, the resumable route checks it at creation — before the first\n * chunk rather than after the last — and advertises it as `Tus-Max-Size`,\n * and the server's upload body limit is the largest of them. A controller\n * that does not implement this is held to the deployment-wide limit alone.\n */\n maxFileSize?(): number;\n}\n\n/**\n * Default maximum file size (50MB)\n */\nexport const DEFAULT_MAX_FILE_SIZE = 50 * 1024 * 1024;\n\n/**\n * Common image MIME types\n */\nexport const IMAGE_MIME_TYPES = [\n \"image/jpeg\",\n \"image/png\",\n \"image/gif\",\n \"image/webp\",\n \"image/svg+xml\",\n \"image/bmp\",\n \"image/tiff\"\n];\n\n/**\n * Common document MIME types\n */\nexport const DOCUMENT_MIME_TYPES = [\n \"application/pdf\",\n \"application/msword\",\n \"application/vnd.openxmlformats-officedocument.wordprocessingml.document\",\n \"application/vnd.ms-excel\",\n \"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet\",\n \"application/vnd.ms-powerpoint\",\n \"application/vnd.openxmlformats-officedocument.presentationml.presentation\",\n \"text/plain\",\n \"text/csv\"\n];\n"],"mappings":";;;;;;;;AA0MA,IAAa,wBAAwB,KAAK,OAAO;;;;AAKjD,IAAa,mBAAmB;CAC5B;CACA;CACA;CACA;CACA;CACA;CACA;AACJ;;;;AAKA,IAAa,sBAAsB;CAC/B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACJ"}
@@ -50,6 +50,18 @@ export declare function rawQueryLoggingEnabled(): boolean;
50
50
  * before persisting and then logs the result.
51
51
  */
52
52
  export declare function redactSensitiveText(text: string): string;
53
+ /**
54
+ * `JSON.stringify`, with the redaction a structured field gets.
55
+ *
56
+ * For a value that has to go *into the message*. Once an object is a string,
57
+ * `emit` can only strip `Failed query:` spans out of it: a sensitive key would
58
+ * pass, and so would the `query` and `params` own-properties `DrizzleQueryError`
59
+ * carries beside its message, which `JSON.stringify` copies and the message
60
+ * redaction never sees. Unlike the structured walk this honours `toJSON`, since
61
+ * the result is read as text. Never throws: a value that cannot be stringified
62
+ * is a marker, not a failed log line.
63
+ */
64
+ export declare function stringifyForLog(value: unknown): string | undefined;
53
65
  /**
54
66
  * Something that wants a copy of every line this logger writes.
55
67
  *