@aphexcms/cms-core 9.9.0 → 10.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api/assets.d.ts +62 -7
- package/dist/api/assets.d.ts.map +1 -1
- package/dist/api/assets.js +116 -9
- package/dist/api/client.d.ts +1 -1
- package/dist/api/client.d.ts.map +1 -1
- package/dist/api/client.js +39 -9
- package/dist/api/limits.d.ts +55 -0
- package/dist/api/limits.d.ts.map +1 -0
- package/dist/api/limits.js +58 -0
- package/dist/api/schemas/assets.d.ts +94 -4
- package/dist/api/schemas/assets.d.ts.map +1 -1
- package/dist/api/schemas/assets.js +82 -5
- package/dist/api/schemas/documents.d.ts +1 -0
- package/dist/api/schemas/documents.d.ts.map +1 -1
- package/dist/api/schemas/documents.js +1 -0
- package/dist/api/types.d.ts +25 -0
- package/dist/api/types.d.ts.map +1 -1
- package/dist/api/upload-timeout.d.ts +17 -0
- package/dist/api/upload-timeout.d.ts.map +1 -0
- package/dist/api/upload-timeout.js +35 -0
- package/dist/api/upload.d.ts +42 -0
- package/dist/api/upload.d.ts.map +1 -0
- package/dist/api/upload.js +144 -0
- package/dist/components/AdminApp.svelte +213 -32
- package/dist/components/AdminApp.svelte.d.ts.map +1 -1
- package/dist/components/admin/AssetBrowserModal.svelte +4 -3
- package/dist/components/admin/AssetBrowserModal.svelte.d.ts +2 -1
- package/dist/components/admin/AssetBrowserModal.svelte.d.ts.map +1 -1
- package/dist/components/admin/MediaBrowser.svelte +1859 -281
- package/dist/components/admin/MediaBrowser.svelte.d.ts +21 -1
- package/dist/components/admin/MediaBrowser.svelte.d.ts.map +1 -1
- package/dist/components/admin/fields/ArrayField.svelte +21 -10
- package/dist/components/admin/fields/ArrayField.svelte.d.ts.map +1 -1
- package/dist/components/admin/fields/FileField.svelte +9 -2
- package/dist/components/admin/fields/FileField.svelte.d.ts.map +1 -1
- package/dist/components/admin/fields/ImageField.svelte +47 -12
- package/dist/components/admin/fields/ImageField.svelte.d.ts.map +1 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +14 -0
- package/dist/db/interfaces/asset.d.ts +114 -5
- package/dist/db/interfaces/asset.d.ts.map +1 -1
- package/dist/db/interfaces/document.d.ts +107 -3
- package/dist/db/interfaces/document.d.ts.map +1 -1
- package/dist/hooks.d.ts.map +1 -1
- package/dist/hooks.js +2 -1
- package/dist/image/Image.svelte +72 -0
- package/dist/image/Image.svelte.d.ts +40 -0
- package/dist/image/Image.svelte.d.ts.map +1 -0
- package/dist/image/index.d.ts +3 -0
- package/dist/image/index.d.ts.map +1 -0
- package/dist/image/index.js +11 -0
- package/dist/image/types.d.ts +28 -0
- package/dist/image/types.d.ts.map +1 -0
- package/dist/image/types.js +1 -0
- package/dist/images/generate.d.ts +55 -0
- package/dist/images/generate.d.ts.map +1 -0
- package/dist/images/generate.js +243 -0
- package/dist/images/index.d.ts +2 -0
- package/dist/images/index.d.ts.map +1 -0
- package/dist/images/index.js +7 -0
- package/dist/images/variants.d.ts +82 -0
- package/dist/images/variants.d.ts.map +1 -0
- package/dist/images/variants.js +124 -0
- package/dist/jobs/asset-reference-jobs.d.ts +49 -0
- package/dist/jobs/asset-reference-jobs.d.ts.map +1 -0
- package/dist/jobs/asset-reference-jobs.js +74 -0
- package/dist/jobs/run-batch.d.ts.map +1 -1
- package/dist/jobs/run-batch.js +5 -0
- package/dist/lib/api/assets.d.ts +62 -7
- package/dist/lib/api/assets.d.ts.map +1 -1
- package/dist/lib/api/assets.js +116 -9
- package/dist/lib/api/assets.js.map +1 -1
- package/dist/lib/api/client.d.ts +1 -1
- package/dist/lib/api/client.d.ts.map +1 -1
- package/dist/lib/api/client.js +39 -9
- package/dist/lib/api/client.js.map +1 -1
- package/dist/lib/api/limits.d.ts +55 -0
- package/dist/lib/api/limits.d.ts.map +1 -0
- package/dist/lib/api/limits.js +59 -0
- package/dist/lib/api/limits.js.map +1 -0
- package/dist/lib/api/schemas/assets.d.ts +94 -4
- package/dist/lib/api/schemas/assets.d.ts.map +1 -1
- package/dist/lib/api/schemas/assets.js +82 -5
- package/dist/lib/api/schemas/assets.js.map +1 -1
- package/dist/lib/api/schemas/documents.d.ts +1 -0
- package/dist/lib/api/schemas/documents.d.ts.map +1 -1
- package/dist/lib/api/schemas/documents.js +1 -0
- package/dist/lib/api/schemas/documents.js.map +1 -1
- package/dist/lib/api/types.d.ts +25 -0
- package/dist/lib/api/types.d.ts.map +1 -1
- package/dist/lib/api/upload-timeout.d.ts +17 -0
- package/dist/lib/api/upload-timeout.d.ts.map +1 -0
- package/dist/lib/api/upload-timeout.js +36 -0
- package/dist/lib/api/upload-timeout.js.map +1 -0
- package/dist/lib/api/upload.d.ts +42 -0
- package/dist/lib/api/upload.d.ts.map +1 -0
- package/dist/lib/api/upload.js +145 -0
- package/dist/lib/api/upload.js.map +1 -0
- package/dist/lib/config.d.ts.map +1 -1
- package/dist/lib/config.js +14 -0
- package/dist/lib/config.js.map +1 -1
- package/dist/lib/db/interfaces/asset.d.ts +114 -5
- package/dist/lib/db/interfaces/asset.d.ts.map +1 -1
- package/dist/lib/db/interfaces/document.d.ts +107 -3
- package/dist/lib/db/interfaces/document.d.ts.map +1 -1
- package/dist/lib/hooks.d.ts.map +1 -1
- package/dist/lib/hooks.js +2 -1
- package/dist/lib/hooks.js.map +1 -1
- package/dist/lib/image/index.d.ts +3 -0
- package/dist/lib/image/index.d.ts.map +1 -0
- package/dist/lib/image/index.js +12 -0
- package/dist/lib/image/index.js.map +1 -0
- package/dist/lib/image/types.d.ts +28 -0
- package/dist/lib/image/types.d.ts.map +1 -0
- package/dist/lib/image/types.js +2 -0
- package/dist/lib/image/types.js.map +1 -0
- package/dist/lib/images/generate.d.ts +55 -0
- package/dist/lib/images/generate.d.ts.map +1 -0
- package/dist/lib/images/generate.js +244 -0
- package/dist/lib/images/generate.js.map +1 -0
- package/dist/lib/images/index.d.ts +2 -0
- package/dist/lib/images/index.d.ts.map +1 -0
- package/dist/lib/images/index.js +8 -0
- package/dist/lib/images/index.js.map +1 -0
- package/dist/lib/images/variants.d.ts +82 -0
- package/dist/lib/images/variants.d.ts.map +1 -0
- package/dist/lib/images/variants.js +125 -0
- package/dist/lib/images/variants.js.map +1 -0
- package/dist/lib/jobs/asset-reference-jobs.d.ts +49 -0
- package/dist/lib/jobs/asset-reference-jobs.d.ts.map +1 -0
- package/dist/lib/jobs/asset-reference-jobs.js +75 -0
- package/dist/lib/jobs/asset-reference-jobs.js.map +1 -0
- package/dist/lib/jobs/run-batch.d.ts.map +1 -1
- package/dist/lib/jobs/run-batch.js +5 -0
- package/dist/lib/jobs/run-batch.js.map +1 -1
- package/dist/lib/local-api/collection-api.d.ts +25 -2
- package/dist/lib/local-api/collection-api.d.ts.map +1 -1
- package/dist/lib/local-api/collection-api.js +107 -20
- package/dist/lib/local-api/collection-api.js.map +1 -1
- package/dist/lib/preview/assets.d.ts +19 -0
- package/dist/lib/preview/assets.d.ts.map +1 -1
- package/dist/lib/preview/assets.js +6 -0
- package/dist/lib/preview/assets.js.map +1 -1
- package/dist/lib/routes/assets-cdn.d.ts +19 -0
- package/dist/lib/routes/assets-cdn.d.ts.map +1 -1
- package/dist/lib/routes/assets-cdn.js +295 -17
- package/dist/lib/routes/assets-cdn.js.map +1 -1
- package/dist/lib/schema-utils/utils.d.ts +31 -1
- package/dist/lib/schema-utils/utils.d.ts.map +1 -1
- package/dist/lib/schema-utils/utils.js +68 -0
- package/dist/lib/schema-utils/utils.js.map +1 -1
- package/dist/lib/server/api/index.d.ts.map +1 -1
- package/dist/lib/server/api/index.js +87 -8
- package/dist/lib/server/api/index.js.map +1 -1
- package/dist/lib/server/api/routes/assets-bulk.d.ts.map +1 -1
- package/dist/lib/server/api/routes/assets-bulk.js +36 -7
- package/dist/lib/server/api/routes/assets-bulk.js.map +1 -1
- package/dist/lib/server/api/routes/assets-by-id.d.ts.map +1 -1
- package/dist/lib/server/api/routes/assets-by-id.js +32 -15
- package/dist/lib/server/api/routes/assets-by-id.js.map +1 -1
- package/dist/lib/server/api/routes/assets-direct-upload.d.ts +4 -0
- package/dist/lib/server/api/routes/assets-direct-upload.d.ts.map +1 -0
- package/dist/lib/server/api/routes/assets-direct-upload.js +164 -0
- package/dist/lib/server/api/routes/assets-direct-upload.js.map +1 -0
- package/dist/lib/server/api/routes/assets-poster.d.ts +4 -0
- package/dist/lib/server/api/routes/assets-poster.d.ts.map +1 -0
- package/dist/lib/server/api/routes/assets-poster.js +120 -0
- package/dist/lib/server/api/routes/assets-poster.js.map +1 -0
- package/dist/lib/server/api/routes/assets-references.d.ts.map +1 -1
- package/dist/lib/server/api/routes/assets-references.js +64 -5
- package/dist/lib/server/api/routes/assets-references.js.map +1 -1
- package/dist/lib/server/api/routes/assets.d.ts.map +1 -1
- package/dist/lib/server/api/routes/assets.js +116 -12
- package/dist/lib/server/api/routes/assets.js.map +1 -1
- package/dist/lib/server/api/routes/clear-asset-references.d.ts +18 -0
- package/dist/lib/server/api/routes/clear-asset-references.d.ts.map +1 -0
- package/dist/lib/server/api/routes/clear-asset-references.js +32 -0
- package/dist/lib/server/api/routes/clear-asset-references.js.map +1 -0
- package/dist/lib/server/api/routes/documents.d.ts.map +1 -1
- package/dist/lib/server/api/routes/documents.js +28 -1
- package/dist/lib/server/api/routes/documents.js.map +1 -1
- package/dist/lib/server/index.d.ts +2 -0
- package/dist/lib/server/index.d.ts.map +1 -1
- package/dist/lib/server/index.js +4 -0
- package/dist/lib/server/index.js.map +1 -1
- package/dist/lib/services/asset-references-service.d.ts +93 -0
- package/dist/lib/services/asset-references-service.d.ts.map +1 -0
- package/dist/lib/services/asset-references-service.js +198 -0
- package/dist/lib/services/asset-references-service.js.map +1 -0
- package/dist/lib/services/asset-service.d.ts +115 -14
- package/dist/lib/services/asset-service.d.ts.map +1 -1
- package/dist/lib/services/asset-service.js +312 -31
- package/dist/lib/services/asset-service.js.map +1 -1
- package/dist/lib/services/references-service.d.ts +19 -15
- package/dist/lib/services/references-service.d.ts.map +1 -1
- package/dist/lib/services/references-service.js +59 -31
- package/dist/lib/services/references-service.js.map +1 -1
- package/dist/lib/services/version-service.d.ts +10 -1
- package/dist/lib/services/version-service.d.ts.map +1 -1
- package/dist/lib/services/version-service.js +26 -4
- package/dist/lib/services/version-service.js.map +1 -1
- package/dist/lib/storage/adapters/local-storage-adapter.d.ts +38 -0
- package/dist/lib/storage/adapters/local-storage-adapter.d.ts.map +1 -1
- package/dist/lib/storage/adapters/local-storage-adapter.js +86 -19
- package/dist/lib/storage/adapters/local-storage-adapter.js.map +1 -1
- package/dist/lib/storage/index.d.ts +1 -0
- package/dist/lib/storage/index.d.ts.map +1 -1
- package/dist/lib/storage/index.js +2 -0
- package/dist/lib/storage/index.js.map +1 -1
- package/dist/lib/storage/interfaces/storage.d.ts +135 -5
- package/dist/lib/storage/interfaces/storage.d.ts.map +1 -1
- package/dist/lib/storage/keys.d.ts +96 -0
- package/dist/lib/storage/keys.d.ts.map +1 -0
- package/dist/lib/storage/keys.js +160 -0
- package/dist/lib/storage/keys.js.map +1 -0
- package/dist/lib/type-gen.d.ts.map +1 -1
- package/dist/lib/type-gen.js +11 -5
- package/dist/lib/type-gen.js.map +1 -1
- package/dist/lib/types/asset.d.ts +92 -12
- package/dist/lib/types/asset.d.ts.map +1 -1
- package/dist/lib/types/capabilities.d.ts +11 -0
- package/dist/lib/types/capabilities.d.ts.map +1 -1
- package/dist/lib/types/capabilities.js +20 -6
- package/dist/lib/types/capabilities.js.map +1 -1
- package/dist/lib/types/config.d.ts +127 -0
- package/dist/lib/types/config.d.ts.map +1 -1
- package/dist/lib/types/filters.d.ts +31 -0
- package/dist/lib/types/filters.d.ts.map +1 -1
- package/dist/lib/types/schemas.d.ts +14 -0
- package/dist/lib/types/schemas.d.ts.map +1 -1
- package/dist/lib/utils/asset-reference-walk.d.ts +44 -0
- package/dist/lib/utils/asset-reference-walk.d.ts.map +1 -0
- package/dist/lib/utils/asset-reference-walk.js +144 -0
- package/dist/lib/utils/asset-reference-walk.js.map +1 -0
- package/dist/lib/utils/image-url.d.ts +61 -26
- package/dist/lib/utils/image-url.d.ts.map +1 -1
- package/dist/lib/utils/image-url.js +143 -26
- package/dist/lib/utils/image-url.js.map +1 -1
- package/dist/lib/utils/video-metadata.d.ts +39 -0
- package/dist/lib/utils/video-metadata.d.ts.map +1 -0
- package/dist/lib/utils/video-metadata.js +161 -0
- package/dist/lib/utils/video-metadata.js.map +1 -0
- package/dist/local-api/collection-api.d.ts +25 -2
- package/dist/local-api/collection-api.d.ts.map +1 -1
- package/dist/local-api/collection-api.js +107 -20
- package/dist/preview/assets.d.ts +19 -0
- package/dist/preview/assets.d.ts.map +1 -1
- package/dist/preview/assets.js +6 -0
- package/dist/routes/assets-cdn.d.ts +19 -0
- package/dist/routes/assets-cdn.d.ts.map +1 -1
- package/dist/routes/assets-cdn.js +295 -17
- package/dist/schema-utils/utils.d.ts +31 -1
- package/dist/schema-utils/utils.d.ts.map +1 -1
- package/dist/schema-utils/utils.js +68 -0
- package/dist/server/api/index.d.ts.map +1 -1
- package/dist/server/api/index.js +87 -8
- package/dist/server/api/routes/assets-bulk.d.ts.map +1 -1
- package/dist/server/api/routes/assets-bulk.js +36 -7
- package/dist/server/api/routes/assets-by-id.d.ts.map +1 -1
- package/dist/server/api/routes/assets-by-id.js +32 -15
- package/dist/server/api/routes/assets-direct-upload.d.ts +4 -0
- package/dist/server/api/routes/assets-direct-upload.d.ts.map +1 -0
- package/dist/server/api/routes/assets-direct-upload.js +163 -0
- package/dist/server/api/routes/assets-poster.d.ts +4 -0
- package/dist/server/api/routes/assets-poster.d.ts.map +1 -0
- package/dist/server/api/routes/assets-poster.js +119 -0
- package/dist/server/api/routes/assets-references.d.ts.map +1 -1
- package/dist/server/api/routes/assets-references.js +64 -5
- package/dist/server/api/routes/assets.d.ts.map +1 -1
- package/dist/server/api/routes/assets.js +116 -12
- package/dist/server/api/routes/clear-asset-references.d.ts +18 -0
- package/dist/server/api/routes/clear-asset-references.d.ts.map +1 -0
- package/dist/server/api/routes/clear-asset-references.js +31 -0
- package/dist/server/api/routes/documents.d.ts.map +1 -1
- package/dist/server/api/routes/documents.js +28 -1
- package/dist/server/index.d.ts +2 -0
- package/dist/server/index.d.ts.map +1 -1
- package/dist/server/index.js +4 -0
- package/dist/services/asset-references-service.d.ts +93 -0
- package/dist/services/asset-references-service.d.ts.map +1 -0
- package/dist/services/asset-references-service.js +197 -0
- package/dist/services/asset-service.d.ts +115 -14
- package/dist/services/asset-service.d.ts.map +1 -1
- package/dist/services/asset-service.js +312 -31
- package/dist/services/references-service.d.ts +19 -15
- package/dist/services/references-service.d.ts.map +1 -1
- package/dist/services/references-service.js +59 -31
- package/dist/services/version-service.d.ts +10 -1
- package/dist/services/version-service.d.ts.map +1 -1
- package/dist/services/version-service.js +26 -4
- package/dist/storage/adapters/local-storage-adapter.d.ts +38 -0
- package/dist/storage/adapters/local-storage-adapter.d.ts.map +1 -1
- package/dist/storage/adapters/local-storage-adapter.js +86 -19
- package/dist/storage/index.d.ts +1 -0
- package/dist/storage/index.d.ts.map +1 -1
- package/dist/storage/index.js +2 -0
- package/dist/storage/interfaces/storage.d.ts +135 -5
- package/dist/storage/interfaces/storage.d.ts.map +1 -1
- package/dist/storage/keys.d.ts +96 -0
- package/dist/storage/keys.d.ts.map +1 -0
- package/dist/storage/keys.js +159 -0
- package/dist/type-gen.d.ts.map +1 -1
- package/dist/type-gen.js +11 -5
- package/dist/types/asset.d.ts +92 -12
- package/dist/types/asset.d.ts.map +1 -1
- package/dist/types/capabilities.d.ts +11 -0
- package/dist/types/capabilities.d.ts.map +1 -1
- package/dist/types/capabilities.js +20 -6
- package/dist/types/config.d.ts +127 -0
- package/dist/types/config.d.ts.map +1 -1
- package/dist/types/filters.d.ts +31 -0
- package/dist/types/filters.d.ts.map +1 -1
- package/dist/types/schemas.d.ts +14 -0
- package/dist/types/schemas.d.ts.map +1 -1
- package/dist/utils/asset-reference-walk.d.ts +44 -0
- package/dist/utils/asset-reference-walk.d.ts.map +1 -0
- package/dist/utils/asset-reference-walk.js +143 -0
- package/dist/utils/image-url.d.ts +61 -26
- package/dist/utils/image-url.d.ts.map +1 -1
- package/dist/utils/image-url.js +143 -26
- package/dist/utils/video-metadata.d.ts +39 -0
- package/dist/utils/video-metadata.d.ts.map +1 -0
- package/dist/utils/video-metadata.js +160 -0
- package/package.json +6 -1
|
@@ -1,4 +1,16 @@
|
|
|
1
1
|
export interface StorageFile {
|
|
2
|
+
/**
|
|
3
|
+
* Adapter-relative key: what the caller asked to be stored, or what the
|
|
4
|
+
* adapter chose. Deliberately distinct from `path`.
|
|
5
|
+
*
|
|
6
|
+
* `path` is whatever the adapter needs to address the object again, and its
|
|
7
|
+
* shape is adapter-private — an absolute filesystem path locally, a
|
|
8
|
+
* `bucket/...` string on S3. `key` is the portable half, relative to the
|
|
9
|
+
* adapter's own root (`basePath` locally, the bucket on S3), which is what
|
|
10
|
+
* makes it possible to derive a sibling key — the variant next to an
|
|
11
|
+
* original — without knowing how a given adapter addresses storage.
|
|
12
|
+
*/
|
|
13
|
+
key: string;
|
|
2
14
|
path: string;
|
|
3
15
|
url: string;
|
|
4
16
|
size: number;
|
|
@@ -8,10 +20,28 @@ export interface UploadFileData {
|
|
|
8
20
|
filename: string;
|
|
9
21
|
mimeType: string;
|
|
10
22
|
size: number;
|
|
23
|
+
/**
|
|
24
|
+
* Store at exactly this adapter-relative key, instead of letting the adapter
|
|
25
|
+
* invent one from `filename`.
|
|
26
|
+
*
|
|
27
|
+
* Without it every adapter derives its own name (the local one appends
|
|
28
|
+
* ` (1)` on collision, S3 appends a timestamp and a random suffix), so
|
|
29
|
+
* `asset.path` can't be predicted from the asset id and there's no way to
|
|
30
|
+
* write a second file — a resized variant — beside the original.
|
|
31
|
+
*
|
|
32
|
+
* The caller owns uniqueness when it passes a key: an adapter given one
|
|
33
|
+
* writes there, overwriting whatever was at that key.
|
|
34
|
+
*/
|
|
35
|
+
key?: string;
|
|
11
36
|
}
|
|
12
37
|
export interface StorageConfig {
|
|
13
38
|
basePath: string;
|
|
14
39
|
baseUrl?: string;
|
|
40
|
+
/**
|
|
41
|
+
* Standalone default only. Inside a CMS this is overwritten at config time by
|
|
42
|
+
* `upload.maxFileSize` (see {@link StorageAdapter.setMaxFileSize}) so the limit
|
|
43
|
+
* has a single home; set it here only when using the adapter on its own.
|
|
44
|
+
*/
|
|
15
45
|
maxFileSize?: number;
|
|
16
46
|
options?: {
|
|
17
47
|
[key: string]: any;
|
|
@@ -44,6 +74,79 @@ export interface StorageAdapter {
|
|
|
44
74
|
delete(path: string): Promise<boolean>;
|
|
45
75
|
exists(path: string): Promise<boolean>;
|
|
46
76
|
getUrl(path: string): string;
|
|
77
|
+
/**
|
|
78
|
+
* Adopt the app's configured upload ceiling.
|
|
79
|
+
*
|
|
80
|
+
* Called once by `createCMSConfig` with the value `upload.maxFileSize`
|
|
81
|
+
* resolves to, so there is exactly one number to set. An adapter's own
|
|
82
|
+
* `maxFileSize` is only a standalone default for use outside a CMS config —
|
|
83
|
+
* when both existed independently, the reference app set `upload.maxFileSize`
|
|
84
|
+
* to 100MB and left the S3 adapter on its 10MB default, so anything between
|
|
85
|
+
* the two passed the request-body check and then died inside the adapter with
|
|
86
|
+
* "File too large" instead of a clean 413.
|
|
87
|
+
*
|
|
88
|
+
* Adapters still enforce it: `bodyLimit` only guards HTTP, and the Local API,
|
|
89
|
+
* MCP `upload_asset`, seeds and plugins all reach `store()` without passing
|
|
90
|
+
* through it. The adapter is the backstop for those, not a second knob.
|
|
91
|
+
*
|
|
92
|
+
* Optional so a third-party adapter that doesn't cap sizes stays valid.
|
|
93
|
+
*/
|
|
94
|
+
setMaxFileSize?(bytes: number): void;
|
|
95
|
+
/**
|
|
96
|
+
* Retrieve file contents as a Buffer.
|
|
97
|
+
*
|
|
98
|
+
* **Required.** `/media/:id/:filename` proxies every asset through this by
|
|
99
|
+
* default, which is what makes its access checks real — the previous
|
|
100
|
+
* behaviour redirected straight to the bucket's public URL, so the checks
|
|
101
|
+
* decided nothing and a private bucket simply broke. An adapter that can't
|
|
102
|
+
* read its own objects back can't serve them.
|
|
103
|
+
*
|
|
104
|
+
* Also used by image processing, backups, and migrations.
|
|
105
|
+
*/
|
|
106
|
+
getObject(path: string): Promise<Buffer>;
|
|
107
|
+
/**
|
|
108
|
+
* Read an object back as a stream.
|
|
109
|
+
*
|
|
110
|
+
* Optional, and purely an optimisation of {@link getObject} — callers must
|
|
111
|
+
* fall back to buffering when an adapter doesn't implement it.
|
|
112
|
+
*
|
|
113
|
+
* It exists because buffering isn't merely wasteful on serverless hosts, it
|
|
114
|
+
* fails: Vercel Functions cap a *response body* at 4.5 MB and return 413
|
|
115
|
+
* `FUNCTION_PAYLOAD_TOO_LARGE` beyond it, while a streamed response has no
|
|
116
|
+
* such cap. So on the deployment target the serverless prep doc aims at, an
|
|
117
|
+
* ordinary 5 MB photo proxied through `getObject` is a hard error rather
|
|
118
|
+
* than a slow request.
|
|
119
|
+
*
|
|
120
|
+
* Implementations should stream from the underlying store rather than
|
|
121
|
+
* buffering and re-wrapping — for an HTTP-backed store that usually means
|
|
122
|
+
* handing back the upstream response body directly, which is less work than
|
|
123
|
+
* `getObject`, not more.
|
|
124
|
+
*/
|
|
125
|
+
getStream?(path: string): Promise<ReadableStream<Uint8Array>>;
|
|
126
|
+
/**
|
|
127
|
+
* Read a byte range of an object as a stream.
|
|
128
|
+
*
|
|
129
|
+
* Optional. Callers must fall back to {@link getStream}/{@link getObject} and
|
|
130
|
+
* slice, which is correct but reads the whole object to serve a few hundred
|
|
131
|
+
* kilobytes of it.
|
|
132
|
+
*
|
|
133
|
+
* It exists for media. Without `206 Partial Content` a browser can still play
|
|
134
|
+
* a video, but only by downloading it progressively from byte zero: seeking to
|
|
135
|
+
* the last minute of a recording means transferring everything before it, and
|
|
136
|
+
* previewing three seconds costs a full-file read plus the egress to match.
|
|
137
|
+
* Small files hide this — a few megabytes over localhost feels instant — so it
|
|
138
|
+
* surfaces as "fine in dev, unusable in production". Both backends support
|
|
139
|
+
* ranged reads natively, so implementing this is *less* work than the buffered
|
|
140
|
+
* path, not more.
|
|
141
|
+
*
|
|
142
|
+
* **`end` is inclusive**, matching HTTP's `Range: bytes=start-end` rather than
|
|
143
|
+
* the half-open convention most APIs use. `getObjectRange(p, 0, 0)` yields one
|
|
144
|
+
* byte. Adapters wrapping an exclusive-end API must add one.
|
|
145
|
+
*
|
|
146
|
+
* Implementations may assume `0 <= start <= end`; the caller validates the
|
|
147
|
+
* range against the object size and answers `416` before calling.
|
|
148
|
+
*/
|
|
149
|
+
getObjectRange?(path: string, start: number, end: number): Promise<ReadableStream<Uint8Array>>;
|
|
47
150
|
getStorageInfo(): Promise<{
|
|
48
151
|
totalSize: number;
|
|
49
152
|
availableSpace?: number;
|
|
@@ -51,11 +154,6 @@ export interface StorageAdapter {
|
|
|
51
154
|
isHealthy(): Promise<boolean>;
|
|
52
155
|
connect?(): Promise<void>;
|
|
53
156
|
disconnect?(): Promise<void>;
|
|
54
|
-
/**
|
|
55
|
-
* Retrieve file contents as Buffer
|
|
56
|
-
* Useful for: image processing, transformations, backups, migrations
|
|
57
|
-
*/
|
|
58
|
-
getObject?(path: string): Promise<Buffer>;
|
|
59
157
|
/**
|
|
60
158
|
* List objects in storage with optional filtering
|
|
61
159
|
* Useful for: admin UI file browser, asset management, cleanup operations
|
|
@@ -79,6 +177,38 @@ export interface StorageAdapter {
|
|
|
79
177
|
* @returns Signed URL that expires after the specified time
|
|
80
178
|
*/
|
|
81
179
|
getSignedUrl?(path: string, expiresIn?: number): Promise<string>;
|
|
180
|
+
/**
|
|
181
|
+
* Generate a URL the browser can PUT a file to, bypassing this application.
|
|
182
|
+
*
|
|
183
|
+
* The reason it exists is a hard platform limit rather than a preference:
|
|
184
|
+
* a serverless host caps the *request* body it will accept (Vercel
|
|
185
|
+
* Functions: 4.5 MB) and, unlike responses, there is no streaming escape.
|
|
186
|
+
* An ordinary large photo therefore cannot reach the app at all, whatever
|
|
187
|
+
* `upload.maxFileSize` says. Sending it straight to the bucket is the only
|
|
188
|
+
* way through.
|
|
189
|
+
*
|
|
190
|
+
* Adapters that can't sign simply omit this; callers fall back to proxying
|
|
191
|
+
* the upload through the app, which works everywhere with no bucket CORS.
|
|
192
|
+
*
|
|
193
|
+
* The `path` is always derived server-side from a freshly minted asset id —
|
|
194
|
+
* a caller-supplied key would let anyone with upload permission write
|
|
195
|
+
* anywhere in the bucket, including over an existing asset.
|
|
196
|
+
*
|
|
197
|
+
* @param path - Destination path, server-derived
|
|
198
|
+
* @param expiresIn - Expiration in seconds. Keep short; this is a write grant.
|
|
199
|
+
* @param contentType - Binds the URL to a Content-Type when supported
|
|
200
|
+
*/
|
|
201
|
+
getSignedUploadUrl?(path: string, expiresIn?: number, contentType?: string): Promise<string>;
|
|
202
|
+
/**
|
|
203
|
+
* Convert an adapter-relative key into this adapter's own path.
|
|
204
|
+
*
|
|
205
|
+
* `store()` normally returns both, but a direct browser upload never goes
|
|
206
|
+
* through `store()` — the server derives a key, hands out a signed URL, and
|
|
207
|
+
* later needs the path to read the object back and to record on the row.
|
|
208
|
+
* Reconstructing it by string surgery on another asset's path happens to
|
|
209
|
+
* work for the current two adapters and breaks on the next one.
|
|
210
|
+
*/
|
|
211
|
+
resolvePath?(key: string): string;
|
|
82
212
|
}
|
|
83
213
|
/**
|
|
84
214
|
* Storage provider factory interface
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"storage.d.ts","sourceRoot":"","sources":["../../../src/lib/storage/interfaces/storage.ts"],"names":[],"mappings":"AACA,MAAM,WAAW,WAAW;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;CACb;AAED,MAAM,WAAW,cAAc;IAC9B,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;CACb;AAED,MAAM,WAAW,aAAa;IAC7B,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AS,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAEjE;;;;;;;;;;;;;;;;;;;;OAoBG;IACH,kBAAkB,CAAC,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAE7F;;;;;;;;OAQG;IACH,WAAW,CAAC,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC;CAClC;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,aAAa,CAAC,MAAM,EAAE,aAAa,GAAG,cAAc,CAAC;CACrD"}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Storage key layout.
|
|
3
|
+
*
|
|
4
|
+
* Every asset owns a directory named by its id, and the file it was uploaded
|
|
5
|
+
* with is `original.{ext}` inside it:
|
|
6
|
+
*
|
|
7
|
+
* {assetId}/original.png
|
|
8
|
+
* {assetId}/w800-a1b2c3.webp ← later, generated variants
|
|
9
|
+
*
|
|
10
|
+
* Two properties matter, and both come from the same decision:
|
|
11
|
+
*
|
|
12
|
+
* - **Derivable.** The key follows from the asset id alone, so a sibling — a
|
|
13
|
+
* resized variant — can be addressed without reading the row back or knowing
|
|
14
|
+
* how the adapter stores things. The previous flat layout invented a name per
|
|
15
|
+
* adapter (` (1)` suffixes locally, timestamp + random on S3), which made
|
|
16
|
+
* `asset.path` unpredictable and left nowhere to put a variant.
|
|
17
|
+
* - **Opaque.** No organization segment and no user-supplied filename. The org
|
|
18
|
+
* lives on the row, so putting it in the key would leak org ids into storage
|
|
19
|
+
* paths and force a copy if an asset ever moved between orgs; user filenames
|
|
20
|
+
* in keys invite collisions and traversal for no benefit, since the display
|
|
21
|
+
* name is `asset.originalFilename` and is free to change independently.
|
|
22
|
+
*
|
|
23
|
+
* Assets stored under the old flat layout keep their existing `path` and keep
|
|
24
|
+
* working — this applies to new uploads only.
|
|
25
|
+
*/
|
|
26
|
+
/**
|
|
27
|
+
* Pick a safe extension for a stored file.
|
|
28
|
+
*
|
|
29
|
+
* Prefers the uploaded filename's own extension, falls back to the MIME type,
|
|
30
|
+
* and finally to `bin`. The result is always lowercase alphanumerics, so it
|
|
31
|
+
* can't introduce a path separator or a leading dot of its own.
|
|
32
|
+
*/
|
|
33
|
+
export declare function extensionFor(originalFilename: string, mimeType?: string): string;
|
|
34
|
+
/**
|
|
35
|
+
* Adapter-relative key for an asset's original file: `{assetId}/original.{ext}`.
|
|
36
|
+
*/
|
|
37
|
+
export declare function buildOriginalKey(assetId: string, originalFilename: string, mimeType?: string): string;
|
|
38
|
+
/**
|
|
39
|
+
* Public URL for an asset: the `/media/:id/:filename` route.
|
|
40
|
+
*
|
|
41
|
+
* The route resolves the asset by id alone — the filename segment is cosmetic,
|
|
42
|
+
* there so a saved file lands with a sensible name and so the URL is readable.
|
|
43
|
+
* That's what lets an asset be renamed without touching storage: only this URL
|
|
44
|
+
* changes, and the bytes stay where they are.
|
|
45
|
+
*/
|
|
46
|
+
export declare function buildAssetUrl(assetId: string, originalFilename: string): string;
|
|
47
|
+
/** Format every derivative is encoded in. Not configurable at V1. */
|
|
48
|
+
/**
|
|
49
|
+
* Filename segment that addresses a video's poster frame rather than the asset
|
|
50
|
+
* itself: `/media/{id}/poster.webp`.
|
|
51
|
+
*
|
|
52
|
+
* A poster is deliberately not an image *variant*. Variants are a responsive
|
|
53
|
+
* ladder keyed by width and config hash, regenerated when the image config
|
|
54
|
+
* changes; a poster is one derived frame whose only input is the video, so it
|
|
55
|
+
* has no ladder, no hash, and nothing to regenerate against.
|
|
56
|
+
*/
|
|
57
|
+
export declare const POSTER_FILENAME = "poster.webp";
|
|
58
|
+
/** Storage key for a video's poster frame, alongside its original. */
|
|
59
|
+
export declare function buildPosterKey(assetId: string): string;
|
|
60
|
+
/** Public URL for a video's poster frame. */
|
|
61
|
+
export declare function buildPosterUrl(assetId: string): string;
|
|
62
|
+
export declare const VARIANT_FORMAT = "webp";
|
|
63
|
+
export interface ParsedVariant {
|
|
64
|
+
width: number;
|
|
65
|
+
configHash: string;
|
|
66
|
+
format: string;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Recognise a variant request in the route's filename segment.
|
|
70
|
+
*
|
|
71
|
+
* Returns null for anything else — an original's real filename, a stale link,
|
|
72
|
+
* or junk — which the route serves as the original. The width is bounded by the
|
|
73
|
+
* pattern itself so an absurd value can't reach a resizer.
|
|
74
|
+
*/
|
|
75
|
+
export declare function parseVariantFilename(filename: string): ParsedVariant | null;
|
|
76
|
+
/** `w800-a1b2c3.webp` */
|
|
77
|
+
export declare function variantFilename(width: number, configHash: string): string;
|
|
78
|
+
/** Adapter-relative key for a derivative, a sibling of the original. */
|
|
79
|
+
export declare function buildVariantKey(assetId: string, width: number, configHash: string): string;
|
|
80
|
+
/** Public URL for a derivative, on the same route as the original. */
|
|
81
|
+
export declare function buildVariantUrl(assetId: string, width: number, configHash: string): string;
|
|
82
|
+
/**
|
|
83
|
+
* Stable short hash of the image config.
|
|
84
|
+
*
|
|
85
|
+
* FNV-1a rather than a crypto digest because this has to run in the browser:
|
|
86
|
+
* `<Image>` builds variant URLs for derivatives that may not exist yet, so it
|
|
87
|
+
* needs the same hash the server will use, and Node's `crypto` isn't available
|
|
88
|
+
* to it. It is a cache key, not a security boundary — a collision would serve
|
|
89
|
+
* a correctly-sized image at a slightly different quality, which is why a
|
|
90
|
+
* 32-bit hash is enough.
|
|
91
|
+
*/
|
|
92
|
+
export declare function imageConfigHash(config: {
|
|
93
|
+
widths: number[];
|
|
94
|
+
quality?: number;
|
|
95
|
+
}): string;
|
|
96
|
+
//# sourceMappingURL=keys.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"keys.d.ts","sourceRoot":"","sources":["../../src/lib/storage/keys.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;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Ae,CAAC,MAAM,EAAE;IAAE,MAAM,EAAE,MAAM,EAAE,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,MAAM,CAStF"}
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Storage key layout.
|
|
3
|
+
*
|
|
4
|
+
* Every asset owns a directory named by its id, and the file it was uploaded
|
|
5
|
+
* with is `original.{ext}` inside it:
|
|
6
|
+
*
|
|
7
|
+
* {assetId}/original.png
|
|
8
|
+
* {assetId}/w800-a1b2c3.webp ← later, generated variants
|
|
9
|
+
*
|
|
10
|
+
* Two properties matter, and both come from the same decision:
|
|
11
|
+
*
|
|
12
|
+
* - **Derivable.** The key follows from the asset id alone, so a sibling — a
|
|
13
|
+
* resized variant — can be addressed without reading the row back or knowing
|
|
14
|
+
* how the adapter stores things. The previous flat layout invented a name per
|
|
15
|
+
* adapter (` (1)` suffixes locally, timestamp + random on S3), which made
|
|
16
|
+
* `asset.path` unpredictable and left nowhere to put a variant.
|
|
17
|
+
* - **Opaque.** No organization segment and no user-supplied filename. The org
|
|
18
|
+
* lives on the row, so putting it in the key would leak org ids into storage
|
|
19
|
+
* paths and force a copy if an asset ever moved between orgs; user filenames
|
|
20
|
+
* in keys invite collisions and traversal for no benefit, since the display
|
|
21
|
+
* name is `asset.originalFilename` and is free to change independently.
|
|
22
|
+
*
|
|
23
|
+
* Assets stored under the old flat layout keep their existing `path` and keep
|
|
24
|
+
* working — this applies to new uploads only.
|
|
25
|
+
*/
|
|
26
|
+
/** Extensions we'll accept straight from a user-supplied filename. */
|
|
27
|
+
const EXTENSION_PATTERN = /^[a-z0-9]{1,12}$/;
|
|
28
|
+
/** Fallbacks for filenames that arrive without a usable extension. */
|
|
29
|
+
const MIME_EXTENSIONS = {
|
|
30
|
+
'image/jpeg': 'jpg',
|
|
31
|
+
'image/png': 'png',
|
|
32
|
+
'image/gif': 'gif',
|
|
33
|
+
'image/webp': 'webp',
|
|
34
|
+
'image/avif': 'avif',
|
|
35
|
+
'image/svg+xml': 'svg',
|
|
36
|
+
'application/pdf': 'pdf'
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* Pick a safe extension for a stored file.
|
|
40
|
+
*
|
|
41
|
+
* Prefers the uploaded filename's own extension, falls back to the MIME type,
|
|
42
|
+
* and finally to `bin`. The result is always lowercase alphanumerics, so it
|
|
43
|
+
* can't introduce a path separator or a leading dot of its own.
|
|
44
|
+
*/
|
|
45
|
+
export function extensionFor(originalFilename, mimeType) {
|
|
46
|
+
const lastDot = originalFilename.lastIndexOf('.');
|
|
47
|
+
if (lastDot > -1) {
|
|
48
|
+
const candidate = originalFilename.slice(lastDot + 1).toLowerCase();
|
|
49
|
+
if (EXTENSION_PATTERN.test(candidate))
|
|
50
|
+
return candidate;
|
|
51
|
+
}
|
|
52
|
+
if (mimeType && MIME_EXTENSIONS[mimeType])
|
|
53
|
+
return MIME_EXTENSIONS[mimeType];
|
|
54
|
+
return 'bin';
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Adapter-relative key for an asset's original file: `{assetId}/original.{ext}`.
|
|
58
|
+
*/
|
|
59
|
+
export function buildOriginalKey(assetId, originalFilename, mimeType) {
|
|
60
|
+
return `${assetId}/original.${extensionFor(originalFilename, mimeType)}`;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Public URL for an asset: the `/media/:id/:filename` route.
|
|
64
|
+
*
|
|
65
|
+
* The route resolves the asset by id alone — the filename segment is cosmetic,
|
|
66
|
+
* there so a saved file lands with a sensible name and so the URL is readable.
|
|
67
|
+
* That's what lets an asset be renamed without touching storage: only this URL
|
|
68
|
+
* changes, and the bytes stay where they are.
|
|
69
|
+
*/
|
|
70
|
+
export function buildAssetUrl(assetId, originalFilename) {
|
|
71
|
+
return `/media/${assetId}/${encodeURIComponent(originalFilename)}`;
|
|
72
|
+
}
|
|
73
|
+
// --- Variants -------------------------------------------------------------
|
|
74
|
+
//
|
|
75
|
+
// A derivative is addressed by the same `/media/{id}/{filename}` route as the
|
|
76
|
+
// original, with the variant encoded in the filename segment: `w800-a1b2c3.webp`.
|
|
77
|
+
//
|
|
78
|
+
// Reusing the route rather than adding one is the security-relevant decision.
|
|
79
|
+
// The route already resolves the asset, checks whether its field is private,
|
|
80
|
+
// and verifies the caller's organization. A separate `/image` endpoint would
|
|
81
|
+
// have to reimplement all of that, and the failure mode if it drifted is ugly:
|
|
82
|
+
// a *public* derivative of a *private* original, sitting in the bucket forever
|
|
83
|
+
// under a guessable key. That is exactly the hole Payload users hit when they
|
|
84
|
+
// hand resizing to Next.js's image optimizer, which bypasses access control.
|
|
85
|
+
//
|
|
86
|
+
// The `configHash` in the name is what makes a variant immutable: change the
|
|
87
|
+
// quality or the ladder and every URL changes, so a cached copy is never
|
|
88
|
+
// stale and old derivatives are simply orphaned rather than overwritten. That
|
|
89
|
+
// in turn is what lets a variant be served `immutable` for a year.
|
|
90
|
+
/** Format every derivative is encoded in. Not configurable at V1. */
|
|
91
|
+
/**
|
|
92
|
+
* Filename segment that addresses a video's poster frame rather than the asset
|
|
93
|
+
* itself: `/media/{id}/poster.webp`.
|
|
94
|
+
*
|
|
95
|
+
* A poster is deliberately not an image *variant*. Variants are a responsive
|
|
96
|
+
* ladder keyed by width and config hash, regenerated when the image config
|
|
97
|
+
* changes; a poster is one derived frame whose only input is the video, so it
|
|
98
|
+
* has no ladder, no hash, and nothing to regenerate against.
|
|
99
|
+
*/
|
|
100
|
+
export const POSTER_FILENAME = 'poster.webp';
|
|
101
|
+
/** Storage key for a video's poster frame, alongside its original. */
|
|
102
|
+
export function buildPosterKey(assetId) {
|
|
103
|
+
return `${assetId}/${POSTER_FILENAME}`;
|
|
104
|
+
}
|
|
105
|
+
/** Public URL for a video's poster frame. */
|
|
106
|
+
export function buildPosterUrl(assetId) {
|
|
107
|
+
return `/media/${assetId}/${POSTER_FILENAME}`;
|
|
108
|
+
}
|
|
109
|
+
export const VARIANT_FORMAT = 'webp';
|
|
110
|
+
/** `w800-a1b2c3.webp` — width, config hash, format. */
|
|
111
|
+
const VARIANT_FILENAME_PATTERN = /^w(\d{1,5})-([a-z0-9]{1,12})\.([a-z0-9]{1,8})$/;
|
|
112
|
+
/**
|
|
113
|
+
* Recognise a variant request in the route's filename segment.
|
|
114
|
+
*
|
|
115
|
+
* Returns null for anything else — an original's real filename, a stale link,
|
|
116
|
+
* or junk — which the route serves as the original. The width is bounded by the
|
|
117
|
+
* pattern itself so an absurd value can't reach a resizer.
|
|
118
|
+
*/
|
|
119
|
+
export function parseVariantFilename(filename) {
|
|
120
|
+
const match = VARIANT_FILENAME_PATTERN.exec(filename);
|
|
121
|
+
if (!match)
|
|
122
|
+
return null;
|
|
123
|
+
const width = Number(match[1]);
|
|
124
|
+
if (!Number.isInteger(width) || width <= 0)
|
|
125
|
+
return null;
|
|
126
|
+
return { width, configHash: match[2], format: match[3] };
|
|
127
|
+
}
|
|
128
|
+
/** `w800-a1b2c3.webp` */
|
|
129
|
+
export function variantFilename(width, configHash) {
|
|
130
|
+
return `w${width}-${configHash}.${VARIANT_FORMAT}`;
|
|
131
|
+
}
|
|
132
|
+
/** Adapter-relative key for a derivative, a sibling of the original. */
|
|
133
|
+
export function buildVariantKey(assetId, width, configHash) {
|
|
134
|
+
return `${assetId}/${variantFilename(width, configHash)}`;
|
|
135
|
+
}
|
|
136
|
+
/** Public URL for a derivative, on the same route as the original. */
|
|
137
|
+
export function buildVariantUrl(assetId, width, configHash) {
|
|
138
|
+
return `/media/${assetId}/${variantFilename(width, configHash)}`;
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Stable short hash of the image config.
|
|
142
|
+
*
|
|
143
|
+
* FNV-1a rather than a crypto digest because this has to run in the browser:
|
|
144
|
+
* `<Image>` builds variant URLs for derivatives that may not exist yet, so it
|
|
145
|
+
* needs the same hash the server will use, and Node's `crypto` isn't available
|
|
146
|
+
* to it. It is a cache key, not a security boundary — a collision would serve
|
|
147
|
+
* a correctly-sized image at a slightly different quality, which is why a
|
|
148
|
+
* 32-bit hash is enough.
|
|
149
|
+
*/
|
|
150
|
+
export function imageConfigHash(config) {
|
|
151
|
+
const canonical = `${[...config.widths].sort((a, b) => a - b).join(',')}|q${config.quality ?? ''}|f${VARIANT_FORMAT}`;
|
|
152
|
+
let hash = 0x811c9dc5;
|
|
153
|
+
for (let i = 0; i < canonical.length; i++) {
|
|
154
|
+
hash ^= canonical.charCodeAt(i);
|
|
155
|
+
// FNV prime, via shifts so this stays in 32-bit integer math.
|
|
156
|
+
hash = (hash + ((hash << 1) + (hash << 4) + (hash << 7) + (hash << 8) + (hash << 24))) >>> 0;
|
|
157
|
+
}
|
|
158
|
+
return hash.toString(36);
|
|
159
|
+
}
|
package/dist/type-gen.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"type-gen.d.ts","sourceRoot":"","sources":["../src/lib/type-gen.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAoJzD;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,UAAU,EAAE,GAAG,MAAM,CAG3E;AA6VD;;GAEG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,UAAU,EAAE,GAAG,MAAM,CA8I3D;AA2GD,wBAAsB,uBAAuB,CAC5C,UAAU,EAAE,MAAM,EAClB,UAAU,EAAE,MAAM,EAClB,WAAW,CAAC,EAAE,MAAM,GAClB,OAAO,CAAC,IAAI,CAAC,
|
|
1
|
+
{"version":3,"file":"type-gen.d.ts","sourceRoot":"","sources":["../src/lib/type-gen.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAoJzD;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,UAAU,EAAE,GAAG,MAAM,CAG3E;AA6VD;;GAEG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,UAAU,EAAE,GAAG,MAAM,CA8I3D;AA2GD,wBAAsB,uBAAuB,CAC5C,UAAU,EAAE,MAAM,EAClB,UAAU,EAAE,MAAM,EAClB,WAAW,CAAC,EAAE,MAAM,GAClB,OAAO,CAAC,IAAI,CAAC,CA0Df"}
|
package/dist/type-gen.js
CHANGED
|
@@ -641,10 +641,14 @@ export async function generateTypesFromConfig(schemaPath, outputPath, pluginsPat
|
|
|
641
641
|
if (!schemas || !Array.isArray(schemas)) {
|
|
642
642
|
throw new Error('Invalid schema file: expected schemaTypes array export');
|
|
643
643
|
}
|
|
644
|
-
//
|
|
645
|
-
//
|
|
646
|
-
//
|
|
647
|
-
// `
|
|
644
|
+
// Merge plugin-contributed document/object schemas (e.g. Plato's `calendar`) and
|
|
645
|
+
// apply plugin schema-transforms (e.g. an SEO field group injected into chosen
|
|
646
|
+
// collections, or a custom field type like `color` desugaring the way it does at
|
|
647
|
+
// runtime) — same order as `createCMSConfig` in config.ts, so codegen sees exactly
|
|
648
|
+
// the schema list the running app does. Without the merge step, any document type
|
|
649
|
+
// that only exists via a plugin's `aphex/schema` part silently never gets a
|
|
650
|
+
// generated interface. `pluginsPath` points at the app's client-safe plugin
|
|
651
|
+
// registry (e.g. `src/lib/plugins.ts`, exporting `plugins`).
|
|
648
652
|
if (pluginsPath) {
|
|
649
653
|
const absolutePluginsPath = path.resolve(process.cwd(), pluginsPath);
|
|
650
654
|
// Resolve cms-core's built dist so the plugins' cms-core runtime imports load
|
|
@@ -661,7 +665,9 @@ export async function generateTypesFromConfig(schemaPath, outputPath, pluginsPat
|
|
|
661
665
|
});
|
|
662
666
|
const plugins = (pluginsModule.plugins || pluginsModule.default);
|
|
663
667
|
if (Array.isArray(plugins)) {
|
|
664
|
-
|
|
668
|
+
const resolver = createPartResolver(plugins);
|
|
669
|
+
const pluginSchemas = resolver.schemaTypes();
|
|
670
|
+
schemas = resolver.applySchemaTransforms([...schemas, ...pluginSchemas]);
|
|
665
671
|
}
|
|
666
672
|
}
|
|
667
673
|
const generatedTypes = generateTypes(schemas);
|
package/dist/types/asset.d.ts
CHANGED
|
@@ -1,3 +1,64 @@
|
|
|
1
|
+
import type { InjectedAsset } from '../image/types.js';
|
|
2
|
+
/** One generated derivative of an image. */
|
|
3
|
+
export interface AssetVariant {
|
|
4
|
+
/** Rendered width in pixels — always one of the configured ladder widths. */
|
|
5
|
+
w: number;
|
|
6
|
+
/** Rendered height, derived from the original's aspect ratio. */
|
|
7
|
+
h: number;
|
|
8
|
+
/** Adapter-relative storage key. */
|
|
9
|
+
key: string;
|
|
10
|
+
/**
|
|
11
|
+
* Adapter-specific path, as `StorageAdapter.store()` reported it.
|
|
12
|
+
*
|
|
13
|
+
* Recorded rather than derived from the original's path, because how an
|
|
14
|
+
* adapter roots storage is its own business — local joins a base directory,
|
|
15
|
+
* S3 prefixes a bucket. Rebuilding it by string surgery on `asset.path`
|
|
16
|
+
* happens to work for both today and breaks on the first adapter that does
|
|
17
|
+
* something else.
|
|
18
|
+
*/
|
|
19
|
+
path: string;
|
|
20
|
+
/**
|
|
21
|
+
* Public URL on the `/media` route.
|
|
22
|
+
*
|
|
23
|
+
* Contains no part of the user's filename — it is `{assetId}/w{width}-{hash}`
|
|
24
|
+
* — so renaming an asset leaves every variant URL and key untouched.
|
|
25
|
+
*/
|
|
26
|
+
url: string;
|
|
27
|
+
bytes: number;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* The derivative record for one asset.
|
|
31
|
+
*
|
|
32
|
+
* Lives on `asset.metadata`, which is already `jsonb` (Postgres) / JSON text
|
|
33
|
+
* (SQLite), so recording variants needs no schema change on either adapter.
|
|
34
|
+
*/
|
|
35
|
+
export interface AssetVariantRecord {
|
|
36
|
+
/**
|
|
37
|
+
* Hash of the image config the variants were generated under. Variants whose
|
|
38
|
+
* hash no longer matches the current config are ignored rather than deleted —
|
|
39
|
+
* they're simply never addressed again, since every URL embeds the hash.
|
|
40
|
+
*/
|
|
41
|
+
config: string;
|
|
42
|
+
generatedAt: string;
|
|
43
|
+
widths: AssetVariant[];
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Known shape of `asset.metadata`.
|
|
47
|
+
*
|
|
48
|
+
* Deliberately open (`[key: string]: any`): metadata also carries whatever the
|
|
49
|
+
* upload path extracted from the image and whatever a caller attached, and
|
|
50
|
+
* narrowing those would break callers for no gain. The point is that the keys
|
|
51
|
+
* the CMS itself depends on are typed, so `variants` isn't reached through a
|
|
52
|
+
* cast at every call site.
|
|
53
|
+
*/
|
|
54
|
+
export interface AssetMetadata {
|
|
55
|
+
variants?: AssetVariantRecord;
|
|
56
|
+
/** Schema type the asset was uploaded into — used for privacy resolution. */
|
|
57
|
+
schemaType?: string;
|
|
58
|
+
/** Field path within that schema type. */
|
|
59
|
+
fieldPath?: string;
|
|
60
|
+
[key: string]: any;
|
|
61
|
+
}
|
|
1
62
|
/**
|
|
2
63
|
* Asset type - represents uploaded files
|
|
3
64
|
*/
|
|
@@ -14,7 +75,12 @@ export interface Asset {
|
|
|
14
75
|
storageAdapter: string;
|
|
15
76
|
width: number | null;
|
|
16
77
|
height: number | null;
|
|
17
|
-
|
|
78
|
+
/**
|
|
79
|
+
* Nullable because the column is: rows predating a given feature, or created
|
|
80
|
+
* without extracted image metadata, genuinely have no value here. Typing it
|
|
81
|
+
* non-null would be a lie the adapters have to cast their way out of.
|
|
82
|
+
*/
|
|
83
|
+
metadata: AssetMetadata | null;
|
|
18
84
|
title: string | null;
|
|
19
85
|
description: string | null;
|
|
20
86
|
alt: string | null;
|
|
@@ -47,18 +113,23 @@ export interface NewAsset {
|
|
|
47
113
|
createdAt?: Date | null;
|
|
48
114
|
updatedAt?: Date | null;
|
|
49
115
|
}
|
|
50
|
-
|
|
116
|
+
/**
|
|
117
|
+
* Sanity-style image reference, plus whatever asset injection has filled in.
|
|
118
|
+
*
|
|
119
|
+
* The injected half is inherited from `InjectedAsset` rather than restated here.
|
|
120
|
+
* They are the same fields at runtime — `injectAssetUrls` writes `url`, `alt`,
|
|
121
|
+
* `width`, `height` and `srcset` — and when this interface listed only `url` and
|
|
122
|
+
* `alt`, a document's own generated type denied the existence of the three the
|
|
123
|
+
* responsive pipeline exists to produce. Reading `image.asset.srcset` off a typed
|
|
124
|
+
* document was a type error even though the value was right there.
|
|
125
|
+
*
|
|
126
|
+
* NOT part of stored data: injection happens at render time (`injectAssetUrls`
|
|
127
|
+
* server-side, the editor's live preview client-side), so all of it is absent
|
|
128
|
+
* until then.
|
|
129
|
+
*/
|
|
130
|
+
export interface ImageAsset extends InjectedAsset {
|
|
51
131
|
_type: 'reference';
|
|
52
132
|
_ref: string;
|
|
53
|
-
/**
|
|
54
|
-
* Resolved public URL. NOT part of stored data — it's injected at render time
|
|
55
|
-
* (by `AssetService.injectAssetUrls` server-side, and by the editor's live preview
|
|
56
|
-
* client-side) so the frontend can read `image.asset.url` directly. Absent until then.
|
|
57
|
-
*/
|
|
58
|
-
url?: string;
|
|
59
|
-
/** The asset's default alt text, injected alongside `url`. Per-placement overrides live
|
|
60
|
-
* on `ImageValue.alt`; render precedence is `value.alt || asset.alt`. */
|
|
61
|
-
alt?: string;
|
|
62
133
|
}
|
|
63
134
|
export interface ImageCrop {
|
|
64
135
|
top: number;
|
|
@@ -85,7 +156,16 @@ export interface ImageValue {
|
|
|
85
156
|
alt?: string;
|
|
86
157
|
[key: string]: any;
|
|
87
158
|
}
|
|
88
|
-
|
|
159
|
+
/**
|
|
160
|
+
* A file reference, with the fields injection adds at render time.
|
|
161
|
+
*
|
|
162
|
+
* Extends `InjectedAsset` for the same reason `ImageAsset` does: `collectAssetRefs`
|
|
163
|
+
* walks `{ asset: { _ref } }` generically, so a file field's `url` is populated
|
|
164
|
+
* exactly like an image's — but the type said otherwise, making
|
|
165
|
+
* `video.asset.url` a type error on a value that was right there. Only `url` is
|
|
166
|
+
* meaningful for a non-image; the dimension fields stay undefined.
|
|
167
|
+
*/
|
|
168
|
+
export interface FileAsset extends InjectedAsset {
|
|
89
169
|
_type: 'reference';
|
|
90
170
|
_ref: string;
|
|
91
171
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"asset.d.ts","sourceRoot":"","sources":["../../src/lib/types/asset.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"asset.d.ts","sourceRoot":"","sources":["../../src/lib/types/asset.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAEpD,4CAA4C;AAC5C,MAAM,WAAW,YAAY;IAC5B,6EAA6E;IAC7E,CAAC,EAAE,MAAM,CAAC;IACV,iEAAiE;IACjE,CAAC,EAAE,MAAM,CAAC;IACV,oCAAoC;IACpC,GAAG,EAAE,MAAM,CAAC;IACZ;;;;;;;;OAQG;IACH,IAAI,EAAE,MAAM,CAAC;IACb;;;;;OAKG;IACH,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;CACd;AAED;;;;;GAKG;AACH,MAAM,WAAW,kBAAkB;IAClC;;;;OAIG;IACH,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,YAAY,EAAE,CAAC;CACvB;AAED;;;;;;;;GAQG;AACH,MAAM,WAAW,aAAa;IAC7B,QAAQ,CAAC,EAAE,kBAAkB,CAAC;IAC9B,6EAA6E;IAC7E,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,0CAA0C;IAC1C,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACnB;AAED;;GAEG;AACH,MAAM,WAAW,KAAK;IACrB,EAAE,EAAE,MAAM,CAAC;IACX,cAAc,EAAE,MAAM,CAAC;IACvB,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAA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pB,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,SAAS,CAAC,EAAE,IAAI,GAAG,IAAI,CAAC;IACxB,SAAS,CAAC,EAAE,IAAI,GAAG,IAAI,CAAC;CACxB;AAED;;;;;;;;;;;;;GAaG;AACH,MAAM,WAAW,UAAW,SAAQ,aAAa;IAChD,KAAK,EAAE,WAAW,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;CACb;AAED,MAAM,WAAW,SAAS;IACzB,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,YAAY;IAC5B,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,UAAU;IAC1B,KAAK,EAAE,OAAO,CAAC;IACf,KAAK,EAAE,UAAU,CAAC;IAClB,IAAI,CAAC,EAAE,SAAS,CAAC;IACjB,OAAO,CAAC,EAAE,YAAY,CAAC;IACvB;;;;OAIG;IACH,GAAG,CAAC,EAAE,MAAM,CAAC;IAEb,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACnB;AAED;;;;;;;;GAQG;AACH,MAAM,WAAW,SAAU,SAAQ,aAAa;IAC/C,KAAK,EAAE,WAAW,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;CACb;AAED,MAAM,WAAW,SAAS;IACzB,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,SAAS,CAAC;IACjB,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACnB"}
|
|
@@ -134,6 +134,17 @@ export declare function coarseApiKeyCapabilities(permissions: readonly string[])
|
|
|
134
134
|
* 3. API keys → derived from `read`/`write` scopes.
|
|
135
135
|
* 4. Session fallback → built-in seed for the org role.
|
|
136
136
|
* 5. Partial session → empty set.
|
|
137
|
+
*
|
|
138
|
+
* Every branch is passed through {@link normalizeCapabilities}, so the
|
|
139
|
+
* write-implies-read invariant holds at *resolve* time and not merely at write
|
|
140
|
+
* time. `normalizeCapabilities` is otherwise only applied by the role and
|
|
141
|
+
* API-key request schemas, which covers the admin UI but not seeds, migrations,
|
|
142
|
+
* plugins, or rows written directly — and the read routes now depend on
|
|
143
|
+
* `asset.read`/`document.read` actually being present. Without this, a role
|
|
144
|
+
* persisted with `asset.upload` alone would be able to upload an asset and then
|
|
145
|
+
* get a 403 listing it. It can only ever add a read cap alongside a write cap
|
|
146
|
+
* that already survived whatever clamp produced the set, so it never widens
|
|
147
|
+
* access beyond what the principal was already granted.
|
|
137
148
|
*/
|
|
138
149
|
export declare function resolveCapabilities(auth: Auth): ReadonlySet<string>;
|
|
139
150
|
/**
|