@antelopejs/dms-media 0.7.3 → 0.8.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/README.md +10 -10
- package/dist/acl/entries.js +20 -2
- package/dist/acl/entries.js.map +1 -1
- package/dist/asset-lifecycle.js +5 -1
- package/dist/asset-lifecycle.js.map +1 -1
- package/dist/bindings.d.ts +1 -0
- package/dist/bindings.js +36 -25
- package/dist/bindings.js.map +1 -1
- package/dist/db/models/mediaAssets.model.d.ts +3 -3
- package/dist/db/models/mediaDeclarations.model.d.ts +3 -3
- package/dist/db/models/mediaEvents.model.d.ts +3 -3
- package/dist/db/models/mediaFavorites.model.d.ts +3 -3
- package/dist/db/models/mediaFolders.model.d.ts +3 -3
- package/dist/db/models/mediaUploads.model.d.ts +3 -3
- package/dist/declared/assets.js +39 -25
- package/dist/declared/assets.js.map +1 -1
- package/dist/declared/folders.js +27 -14
- package/dist/declared/folders.js.map +1 -1
- package/dist/declared/records.d.ts +1 -0
- package/dist/declared/records.js +18 -1
- package/dist/declared/records.js.map +1 -1
- package/dist/fixed-id.d.ts +1 -0
- package/dist/fixed-id.js +16 -0
- package/dist/fixed-id.js.map +1 -0
- package/dist/routes/media/assets.d.ts +3 -2
- package/dist/routes/media/assets.js +11 -6
- package/dist/routes/media/assets.js.map +1 -1
- package/dist/routes/media/storage-keys.js +10 -1
- package/dist/routes/media/storage-keys.js.map +1 -1
- package/dist/test/helpers/assets.d.ts +2 -2
- package/dist/test/helpers/folders.d.ts +6 -6
- package/dist/test/helpers/permissions-world.d.ts +6 -6
- package/dist/test/integration/binding-folder-race.test.d.ts +1 -0
- package/dist/test/integration/binding-folder-race.test.js +66 -0
- package/dist/test/integration/binding-folder-race.test.js.map +1 -0
- package/dist/test/integration/declared-asset-race.test.d.ts +1 -0
- package/dist/test/integration/declared-asset-race.test.js +78 -0
- package/dist/test/integration/declared-asset-race.test.js.map +1 -0
- package/dist/test/integration/declared-folder-race.test.d.ts +1 -0
- package/dist/test/integration/declared-folder-race.test.js +43 -0
- package/dist/test/integration/declared-folder-race.test.js.map +1 -0
- package/dist/test/integration/media-activity-overview.test.js +27 -22
- package/dist/test/integration/media-activity-overview.test.js.map +1 -1
- package/dist/test/integration/media-api.test.js +9 -5
- package/dist/test/integration/media-api.test.js.map +1 -1
- package/dist/test/integration/media-bindings.test.js +16 -13
- package/dist/test/integration/media-bindings.test.js.map +1 -1
- package/dist/test/integration/media-cleanup.test.js +14 -5
- package/dist/test/integration/media-cleanup.test.js.map +1 -1
- package/dist/test/integration/media-declared-content.test.js +107 -91
- package/dist/test/integration/media-declared-content.test.js.map +1 -1
- package/dist/test/integration/media-delivery-editing.test.js +238 -215
- package/dist/test/integration/media-delivery-editing.test.js.map +1 -1
- package/dist/test/integration/media-explorer-writes.test.js +131 -112
- package/dist/test/integration/media-explorer-writes.test.js.map +1 -1
- package/dist/test/integration/media-guards.test.js +38 -37
- package/dist/test/integration/media-guards.test.js.map +1 -1
- package/dist/test/integration/media-library.test.js +244 -224
- package/dist/test/integration/media-library.test.js.map +1 -1
- package/dist/test/integration/media-linked-subfolders.test.js +173 -158
- package/dist/test/integration/media-linked-subfolders.test.js.map +1 -1
- package/dist/test/integration/media-permissions.test.js +31 -11
- package/dist/test/integration/media-permissions.test.js.map +1 -1
- package/dist/test/integration/media-search-query.test.js +8 -6
- package/dist/test/integration/media-search-query.test.js.map +1 -1
- package/dist/test/integration/media-search-views.test.js +12 -8
- package/dist/test/integration/media-search-views.test.js.map +1 -1
- package/dist/test/integration/media-upload-policy.test.js +228 -200
- package/dist/test/integration/media-upload-policy.test.js.map +1 -1
- package/dist/test/stack-modules.json +5 -5
- package/dist/test/unit/acl/entries.test.js +19 -0
- package/dist/test/unit/acl/entries.test.js.map +1 -1
- package/dist/test/unit/acl/resolver.test.js +9 -1
- package/dist/test/unit/acl/resolver.test.js.map +1 -1
- package/dist/test/unit/asset-lifecycle.test.d.ts +1 -0
- package/dist/test/unit/asset-lifecycle.test.js +18 -0
- package/dist/test/unit/asset-lifecycle.test.js.map +1 -0
- package/dist/test/unit/routes/storage-keys.test.d.ts +1 -0
- package/dist/test/unit/routes/storage-keys.test.js +18 -0
- package/dist/test/unit/routes/storage-keys.test.js.map +1 -0
- package/dist/test/unit/transform-ops.test.js +19 -0
- package/dist/test/unit/transform-ops.test.js.map +1 -1
- package/dist/transform-ops.js +25 -1
- package/dist/transform-ops.js.map +1 -1
- package/dist/validation/declared.schema.d.ts +6 -6
- package/dist/validation/library.schema.d.ts +4 -4
- package/dist/validation/media.schema.d.ts +4 -4
- package/frontend-vue/app/components/Explorer.vue +2 -0
- package/frontend-vue/app/components/FileProperties.vue +1 -1
- package/frontend-vue/app/components/ImageEditor.vue +5 -5
- package/frontend-vue/app/components/RecentFiles.vue +2 -2
- package/frontend-vue/app/components/UploadQueue.vue +4 -4
- package/frontend-vue/app/components/dialogs/DeleteFilesDialog.vue +1 -1
- package/frontend-vue/app/components/dialogs/ShortcutsDialog.vue +1 -1
- package/frontend-vue/app/components/dialogs/VisibilityDialog.vue +1 -1
- package/frontend-vue/app/components/explorer/ExplorerInspector.vue +1 -1
- package/frontend-vue/app/components/explorer/ExplorerSidebar.vue +2 -2
- package/frontend-vue/app/components/explorer/FolderStrip.vue +1 -1
- package/frontend-vue/app/components/explorer/GridView.vue +1 -1
- package/frontend-vue/app/components/shared/AltTextField.vue +2 -2
- package/frontend-vue/build/backend-boundary.ts +8 -3
- package/frontend-vue/eslint.config.mjs +0 -1
- package/frontend-vue/package.json +2 -2
- package/frontend-vue/pnpm-lock.yaml +45 -14
- package/frontend-vue/tests/backend-boundary.test.ts +6 -4
- package/frontend-vue/tests/fixtures/serverRender.ts +3 -3
- package/frontend-vue/tests/registration.test.ts +5 -0
- package/package.json +15 -15
- package/src/acl/entries.ts +30 -7
- package/src/asset-lifecycle.ts +6 -2
- package/src/bindings.ts +41 -38
- package/src/declared/assets.ts +45 -28
- package/src/declared/folders.ts +30 -21
- package/src/declared/records.ts +31 -2
- package/src/fixed-id.ts +18 -0
- package/src/routes/media/assets.ts +14 -6
- package/src/routes/media/storage-keys.ts +14 -2
- package/src/test/integration/binding-folder-race.test.ts +82 -0
- package/src/test/integration/declared-asset-race.test.ts +115 -0
- package/src/test/integration/declared-folder-race.test.ts +50 -0
- package/src/test/integration/media-activity-overview.test.ts +40 -27
- package/src/test/integration/media-api.test.ts +9 -5
- package/src/test/integration/media-bindings.test.ts +17 -13
- package/src/test/integration/media-cleanup.test.ts +17 -5
- package/src/test/integration/media-declared-content.test.ts +129 -112
- package/src/test/integration/media-delivery-editing.test.ts +323 -299
- package/src/test/integration/media-explorer-writes.test.ts +161 -135
- package/src/test/integration/media-guards.test.ts +40 -38
- package/src/test/integration/media-library.test.ts +325 -296
- package/src/test/integration/media-linked-subfolders.test.ts +207 -186
- package/src/test/integration/media-permissions.test.ts +33 -14
- package/src/test/integration/media-search-query.test.ts +24 -8
- package/src/test/integration/media-search-views.test.ts +39 -32
- package/src/test/integration/media-upload-policy.test.ts +283 -254
- package/src/test/stack-modules.json +5 -5
- package/src/test/unit/acl/entries.test.ts +23 -0
- package/src/test/unit/acl/resolver.test.ts +9 -1
- package/src/test/unit/asset-lifecycle.test.ts +21 -0
- package/src/test/unit/routes/storage-keys.test.ts +23 -0
- package/src/test/unit/transform-ops.test.ts +29 -1
- package/src/transform-ops.ts +32 -2
|
@@ -43,6 +43,43 @@ const activityBody = z.object({
|
|
|
43
43
|
items: z.array(z.object({ title: z.string(), to: z.string().optional() })),
|
|
44
44
|
});
|
|
45
45
|
|
|
46
|
+
function reportRetriedBatch(
|
|
47
|
+
client: AxiosInstance,
|
|
48
|
+
folderId: string,
|
|
49
|
+
uploaded: number,
|
|
50
|
+
failed: number,
|
|
51
|
+
) {
|
|
52
|
+
return client.post("/api/media/upload/batches", {
|
|
53
|
+
batchId: BATCH_ID,
|
|
54
|
+
folderId,
|
|
55
|
+
total: 2,
|
|
56
|
+
uploaded,
|
|
57
|
+
failed,
|
|
58
|
+
size: 10,
|
|
59
|
+
failures: failed
|
|
60
|
+
? [{ name: "overview-b.txt", reason: "Network error" }]
|
|
61
|
+
: [],
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
async function flaggedFailures(client: AxiosInstance): Promise<number> {
|
|
66
|
+
const rows = await client.get("/api/media/upload/batches", {
|
|
67
|
+
params: { filter_attention: "is:yes" },
|
|
68
|
+
});
|
|
69
|
+
return readBody(rows, batchesBody).results.reduce(
|
|
70
|
+
(total, row) => total + row.failed,
|
|
71
|
+
0,
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
async function countedFailures(client: AxiosInstance): Promise<number> {
|
|
76
|
+
const attention = await client.get("/api/media/stats/attention");
|
|
77
|
+
const item = readBody(attention, attentionBody).items.find(
|
|
78
|
+
(entry) => entry.id === "failed-uploads",
|
|
79
|
+
);
|
|
80
|
+
return item?.value ?? 0;
|
|
81
|
+
}
|
|
82
|
+
|
|
46
83
|
describe("[integration] media activity and overview — figures, upload history and module catalog", () => {
|
|
47
84
|
let client: AxiosInstance;
|
|
48
85
|
let folderId: string;
|
|
@@ -74,17 +111,7 @@ describe("[integration] media activity and overview — figures, upload history
|
|
|
74
111
|
it("keeps the newest report of a retried batch only", async () => {
|
|
75
112
|
await uploadAsset(client, folderId, "overview-a.txt", TEXT_MIMETYPE, BODY);
|
|
76
113
|
const report = (uploaded: number, failed: number) =>
|
|
77
|
-
client
|
|
78
|
-
batchId: BATCH_ID,
|
|
79
|
-
folderId,
|
|
80
|
-
total: 2,
|
|
81
|
-
uploaded,
|
|
82
|
-
failed,
|
|
83
|
-
size: 10,
|
|
84
|
-
failures: failed
|
|
85
|
-
? [{ name: "overview-b.txt", reason: "Network error" }]
|
|
86
|
-
: [],
|
|
87
|
-
});
|
|
114
|
+
reportRetriedBatch(client, folderId, uploaded, failed);
|
|
88
115
|
expect((await report(1, 1)).status).to.equal(HTTP_OK);
|
|
89
116
|
const failedOnly = await client.get("/api/media/upload/batches", {
|
|
90
117
|
params: { filter_result: "is:partial,failed" },
|
|
@@ -121,22 +148,8 @@ describe("[integration] media activity and overview — figures, upload history
|
|
|
121
148
|
failed: 3,
|
|
122
149
|
size: 0,
|
|
123
150
|
});
|
|
124
|
-
const flagged =
|
|
125
|
-
|
|
126
|
-
params: { filter_attention: "is:yes" },
|
|
127
|
-
});
|
|
128
|
-
return readBody(rows, batchesBody).results.reduce(
|
|
129
|
-
(total, row) => total + row.failed,
|
|
130
|
-
0,
|
|
131
|
-
);
|
|
132
|
-
};
|
|
133
|
-
const counted = async () => {
|
|
134
|
-
const attention = await client.get("/api/media/stats/attention");
|
|
135
|
-
const item = readBody(attention, attentionBody).items.find(
|
|
136
|
-
(entry) => entry.id === "failed-uploads",
|
|
137
|
-
);
|
|
138
|
-
return item?.value ?? 0;
|
|
139
|
-
};
|
|
151
|
+
const flagged = () => flaggedFailures(client);
|
|
152
|
+
const counted = () => countedFailures(client);
|
|
140
153
|
const before = await counted();
|
|
141
154
|
expect(before).to.equal(await flagged());
|
|
142
155
|
expect(before).to.be.at.least(3);
|
|
@@ -40,12 +40,12 @@ const treeBody = z.object({
|
|
|
40
40
|
),
|
|
41
41
|
});
|
|
42
42
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
let assetId: string;
|
|
43
|
+
let client: AxiosInstance;
|
|
44
|
+
let brandFolderId: string;
|
|
45
|
+
let subFolderId: string;
|
|
46
|
+
let assetId: string;
|
|
48
47
|
|
|
48
|
+
describe("[integration] media API — owner lifecycle: folders", () => {
|
|
49
49
|
before(async function () {
|
|
50
50
|
this.timeout(READY_TIMEOUT_MS + 10_000);
|
|
51
51
|
const session = await ensureOwnerSession();
|
|
@@ -94,7 +94,9 @@ describe("[integration] media API — owner lifecycle", () => {
|
|
|
94
94
|
});
|
|
95
95
|
expect(duplicate.status).to.equal(409);
|
|
96
96
|
});
|
|
97
|
+
});
|
|
97
98
|
|
|
99
|
+
describe("[integration] media API — owner lifecycle: asset", () => {
|
|
98
100
|
it("uploads a file through presign, PUT and confirm", async () => {
|
|
99
101
|
const body = Buffer.from(FILE_CONTENT);
|
|
100
102
|
const presign = await client.post("/api/media/upload/presign", {
|
|
@@ -163,7 +165,9 @@ describe("[integration] media API — owner lifecycle", () => {
|
|
|
163
165
|
expect(detail.data.asset.folderId).to.equal(subFolderId);
|
|
164
166
|
expect(detail.data.asset.effectiveVisibility).to.equal("public");
|
|
165
167
|
});
|
|
168
|
+
});
|
|
166
169
|
|
|
170
|
+
describe("[integration] media API — owner lifecycle: teardown", () => {
|
|
167
171
|
it("moves and renames folders with cycle protection", async () => {
|
|
168
172
|
const renamed = await client.post(
|
|
169
173
|
`/api/media/folders/${subFolderId}/rename`,
|
|
@@ -29,6 +29,22 @@ class PageBoundProbePage extends PageController("page-bound-probe", {
|
|
|
29
29
|
static content = CustomComponent("dms-media-page-bound-probe");
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
+
function registerProbeBindings(): void {
|
|
33
|
+
RegisterAssetBinding({
|
|
34
|
+
id: BINDING_ID,
|
|
35
|
+
folderName: "Article covers",
|
|
36
|
+
permissionMapping: {
|
|
37
|
+
read: ["articles.page"],
|
|
38
|
+
write: ["articles.page.table.edit"],
|
|
39
|
+
},
|
|
40
|
+
});
|
|
41
|
+
RegisterAssetBinding({
|
|
42
|
+
id: PAGE_BOUND_BINDING_ID,
|
|
43
|
+
folderName: PAGE_BOUND_FOLDER_NAME,
|
|
44
|
+
permissionsFromPage: PageBoundProbePage,
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
|
|
32
48
|
describe("[integration] media bindings — linked folder provisioning", () => {
|
|
33
49
|
let client: AxiosInstance;
|
|
34
50
|
let contentRootId: string;
|
|
@@ -36,19 +52,7 @@ describe("[integration] media bindings — linked folder provisioning", () => {
|
|
|
36
52
|
|
|
37
53
|
before(async function () {
|
|
38
54
|
this.timeout(40_000);
|
|
39
|
-
|
|
40
|
-
id: BINDING_ID,
|
|
41
|
-
folderName: "Article covers",
|
|
42
|
-
permissionMapping: {
|
|
43
|
-
read: ["articles.page"],
|
|
44
|
-
write: ["articles.page.table.edit"],
|
|
45
|
-
},
|
|
46
|
-
});
|
|
47
|
-
RegisterAssetBinding({
|
|
48
|
-
id: PAGE_BOUND_BINDING_ID,
|
|
49
|
-
folderName: PAGE_BOUND_FOLDER_NAME,
|
|
50
|
-
permissionsFromPage: PageBoundProbePage,
|
|
51
|
-
});
|
|
55
|
+
registerProbeBindings();
|
|
52
56
|
const session = await ensureOwnerSession();
|
|
53
57
|
client = authorizedClient(session.accessToken);
|
|
54
58
|
});
|
|
@@ -64,12 +64,12 @@ async function insertAsset(model: MediaAssetModel): Promise<MediaAsset> {
|
|
|
64
64
|
return (await model.get(_id))!;
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
let restoreMutation: () => void = () => undefined;
|
|
67
|
+
let model: MediaAssetModel;
|
|
68
|
+
let asset: MediaAsset;
|
|
69
|
+
let compare: MediaAssetModel["compareMedia"];
|
|
70
|
+
let restoreMutation: () => void = () => undefined;
|
|
72
71
|
|
|
72
|
+
function useCleanupFixture(): void {
|
|
73
73
|
beforeEach(async () => {
|
|
74
74
|
model = GetModel(MediaAssetModel, TENANT);
|
|
75
75
|
asset = await insertAsset(model);
|
|
@@ -82,6 +82,10 @@ describe("[integration] replayable media cleanup", () => {
|
|
|
82
82
|
restoreMutation();
|
|
83
83
|
await deleteMediaAsset(model, asset._id);
|
|
84
84
|
});
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
describe("[integration] replayable media cleanup — competing publications", () => {
|
|
88
|
+
useCleanupFixture();
|
|
85
89
|
|
|
86
90
|
it("allows exactly one competing revision and keeps creation/update modifiers", async () => {
|
|
87
91
|
const patches = [{ alt: "first" }, { alt: "second" }];
|
|
@@ -142,6 +146,10 @@ describe("[integration] replayable media cleanup", () => {
|
|
|
142
146
|
});
|
|
143
147
|
expect(await storage.FileExists(key)).to.equal(true);
|
|
144
148
|
});
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
describe("[integration] replayable media cleanup — sweep and replay", () => {
|
|
152
|
+
useCleanupFixture();
|
|
145
153
|
|
|
146
154
|
it("stops on unknown write acknowledgement and replays durable cleanup later", async () => {
|
|
147
155
|
const key = await upload();
|
|
@@ -242,6 +250,10 @@ describe("[integration] replayable media cleanup", () => {
|
|
|
242
250
|
await cleanupAssetFiles(model, asset._id);
|
|
243
251
|
expect(retiredFiles((await model.get(asset._id))!)).to.deep.equal([]);
|
|
244
252
|
});
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
describe("[integration] replayable media cleanup — deletion and replacement", () => {
|
|
256
|
+
useCleanupFixture();
|
|
245
257
|
|
|
246
258
|
it("tombstones before external deletion and rejects late publication", async () => {
|
|
247
259
|
await deleteMediaAsset(model, asset._id, async () => {
|
|
@@ -55,118 +55,10 @@ async function rejectionOf(promise: Promise<unknown>): Promise<Error> {
|
|
|
55
55
|
throw new Error("Expected the declaration to be refused");
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
let tempDir: string;
|
|
61
|
-
|
|
62
|
-
before(async function () {
|
|
63
|
-
this.timeout(40_000);
|
|
64
|
-
RegisterAssetBinding({
|
|
65
|
-
id: BINDING_ID,
|
|
66
|
-
folderName: "Declared covers",
|
|
67
|
-
field: { mimetypes: ["image/*"] },
|
|
68
|
-
});
|
|
69
|
-
const session = await ensureOwnerSession();
|
|
70
|
-
client = authorizedClient(session.accessToken);
|
|
71
|
-
tempDir = await mkdtemp(join(tmpdir(), "dms-media-declared-"));
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
after(async () => {
|
|
75
|
-
await rm(tempDir, { recursive: true, force: true });
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
it("rejects missing or blank tenants before changing the default library", async () => {
|
|
79
|
-
const declarationModel = GetModel(MediaDeclarationModel, DEFAULT_TENANT_ID);
|
|
80
|
-
const eventModel = GetModel(MediaEventModel, DEFAULT_TENANT_ID);
|
|
81
|
-
const before = {
|
|
82
|
-
folders: await folders().getAll(),
|
|
83
|
-
assets: await assets().getAll(),
|
|
84
|
-
declarations: await declarationModel.getAll(),
|
|
85
|
-
events: await eventModel.getAll(),
|
|
86
|
-
};
|
|
87
|
-
const folder = {
|
|
88
|
-
key: "declared.invalid-tenant",
|
|
89
|
-
name: "No implicit tenant",
|
|
90
|
-
};
|
|
91
|
-
const file = {
|
|
92
|
-
key: "declared.invalid-tenant-file",
|
|
93
|
-
folder: { binding: BINDING_ID },
|
|
94
|
-
name: "invalid-tenant.png",
|
|
95
|
-
mimetype: PNG_MIMETYPE,
|
|
96
|
-
source: { bytes: ONE_PIXEL_PNG },
|
|
97
|
-
};
|
|
98
|
-
// @ts-expect-error A JavaScript caller can omit the required tenantId; this call stops compiling if the public contract makes it optional.
|
|
99
|
-
expect((await rejectionOf(EnsureMediaFolder(folder))).message).to.contain(
|
|
100
|
-
"tenantId",
|
|
101
|
-
);
|
|
102
|
-
// @ts-expect-error A JavaScript caller can omit the required tenantId; this call stops compiling if the public contract makes it optional.
|
|
103
|
-
expect((await rejectionOf(ImportMediaAsset(file))).message).to.contain(
|
|
104
|
-
"tenantId",
|
|
105
|
-
);
|
|
106
|
-
for (const tenantId of ["", " \t\n "]) {
|
|
107
|
-
expect(
|
|
108
|
-
(await rejectionOf(EnsureMediaFolder({ ...folder, tenantId }))).message,
|
|
109
|
-
).to.contain("tenantId");
|
|
110
|
-
expect(
|
|
111
|
-
(await rejectionOf(ImportMediaAsset({ ...file, tenantId }))).message,
|
|
112
|
-
).to.contain("tenantId");
|
|
113
|
-
}
|
|
114
|
-
expect(
|
|
115
|
-
(
|
|
116
|
-
await rejectionOf(
|
|
117
|
-
ImportMediaAsset({
|
|
118
|
-
...file,
|
|
119
|
-
tenantId: "",
|
|
120
|
-
source: { filePath: join(tempDir, "does-not-exist.png") },
|
|
121
|
-
}),
|
|
122
|
-
)
|
|
123
|
-
).message,
|
|
124
|
-
"validation precedes source reads, not only the final database write",
|
|
125
|
-
).to.contain("tenantId");
|
|
126
|
-
expect({
|
|
127
|
-
folders: await folders().getAll(),
|
|
128
|
-
assets: await assets().getAll(),
|
|
129
|
-
declarations: await declarationModel.getAll(),
|
|
130
|
-
events: await eventModel.getAll(),
|
|
131
|
-
}).to.deep.equal(before);
|
|
132
|
-
});
|
|
133
|
-
|
|
134
|
-
it("isolates the same declaration keys in two tenant instances", async () => {
|
|
135
|
-
const tenantId = "declared-isolation";
|
|
136
|
-
const schema = Schema.get(TENANT_SCHEMA_NAME);
|
|
137
|
-
if (!schema) throw new Error("Tenant schema is missing");
|
|
138
|
-
await schema.createInstance(tenantId).run();
|
|
139
|
-
try {
|
|
140
|
-
const folder = {
|
|
141
|
-
tenantId: DEFAULT_TENANT_ID,
|
|
142
|
-
key: "declared.isolated",
|
|
143
|
-
name: "Isolated",
|
|
144
|
-
};
|
|
145
|
-
const firstFolder = await EnsureMediaFolder(folder);
|
|
146
|
-
const secondFolder = await EnsureMediaFolder({ ...folder, tenantId });
|
|
147
|
-
expect(firstFolder.id).to.not.equal(secondFolder.id);
|
|
148
|
-
const file = {
|
|
149
|
-
tenantId: DEFAULT_TENANT_ID,
|
|
150
|
-
key: folder.key,
|
|
151
|
-
folder: { key: folder.key },
|
|
152
|
-
name: "isolated.txt",
|
|
153
|
-
mimetype: "text/plain",
|
|
154
|
-
source: { bytes: Buffer.from("Initial") },
|
|
155
|
-
};
|
|
156
|
-
const firstFile = await ImportMediaAsset(file);
|
|
157
|
-
const secondFile = await ImportMediaAsset({ ...file, tenantId });
|
|
158
|
-
expect(firstFile.id).to.not.equal(secondFile.id);
|
|
159
|
-
expect((await EnsureMediaFolder(folder)).status).to.equal("kept");
|
|
160
|
-
expect((await ImportMediaAsset(file)).status).to.equal("kept");
|
|
161
|
-
expect(
|
|
162
|
-
await GetModel(MediaAssetModel, tenantId).get(firstFile.id),
|
|
163
|
-
).to.equal(undefined);
|
|
164
|
-
expect(await assets().get(secondFile.id)).to.equal(undefined);
|
|
165
|
-
} finally {
|
|
166
|
-
await schema.destroyInstance(tenantId).run();
|
|
167
|
-
}
|
|
168
|
-
});
|
|
58
|
+
let client: AxiosInstance;
|
|
59
|
+
let tempDir: string;
|
|
169
60
|
|
|
61
|
+
function describeFolderDeclarations(): void {
|
|
170
62
|
describe("folders", () => {
|
|
171
63
|
it("rejects self-parenting without blocking later declarations of the key", async () => {
|
|
172
64
|
const key = "declared.self-parent";
|
|
@@ -256,7 +148,11 @@ describe("[integration] media declared content — folders and files shipped as
|
|
|
256
148
|
),
|
|
257
149
|
).to.have.length(1);
|
|
258
150
|
});
|
|
151
|
+
});
|
|
152
|
+
}
|
|
259
153
|
|
|
154
|
+
function describeKeptFoldersAndRefusals(): void {
|
|
155
|
+
describe("folders already declared, and refusals", () => {
|
|
260
156
|
it("never changes a folder declared before, even renamed by a member", async () => {
|
|
261
157
|
const declared = await EnsureMediaFolder({
|
|
262
158
|
tenantId: DEFAULT_TENANT_ID,
|
|
@@ -306,8 +202,10 @@ describe("[integration] media declared content — folders and files shipped as
|
|
|
306
202
|
expect(taken.message).to.contain("already exists");
|
|
307
203
|
});
|
|
308
204
|
});
|
|
205
|
+
}
|
|
309
206
|
|
|
310
|
-
|
|
207
|
+
function describeFileImports(): void {
|
|
208
|
+
describe("file imports", () => {
|
|
311
209
|
it("imports bytes once, with their dimensions and an upload event", async () => {
|
|
312
210
|
const declaration = {
|
|
313
211
|
tenantId: DEFAULT_TENANT_ID,
|
|
@@ -385,7 +283,11 @@ describe("[integration] media declared content — folders and files shipped as
|
|
|
385
283
|
);
|
|
386
284
|
expect(refused.message).to.contain("only accepts image/*");
|
|
387
285
|
});
|
|
286
|
+
});
|
|
287
|
+
}
|
|
388
288
|
|
|
289
|
+
function describeKeptFilesAndRefusals(): void {
|
|
290
|
+
describe("files kept, lazy and refused", () => {
|
|
389
291
|
it("names the key when a lazy source fails or returns no bytes", async () => {
|
|
390
292
|
const declaration = {
|
|
391
293
|
tenantId: DEFAULT_TENANT_ID,
|
|
@@ -498,4 +400,119 @@ describe("[integration] media declared content — folders and files shipped as
|
|
|
498
400
|
expect(missing.message).to.contain("cannot read");
|
|
499
401
|
});
|
|
500
402
|
});
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
describe("[integration] media declared content — folders and files shipped as code", () => {
|
|
406
|
+
before(async function () {
|
|
407
|
+
this.timeout(40_000);
|
|
408
|
+
RegisterAssetBinding({
|
|
409
|
+
id: BINDING_ID,
|
|
410
|
+
folderName: "Declared covers",
|
|
411
|
+
field: { mimetypes: ["image/*"] },
|
|
412
|
+
});
|
|
413
|
+
const session = await ensureOwnerSession();
|
|
414
|
+
client = authorizedClient(session.accessToken);
|
|
415
|
+
tempDir = await mkdtemp(join(tmpdir(), "dms-media-declared-"));
|
|
416
|
+
});
|
|
417
|
+
|
|
418
|
+
after(async () => {
|
|
419
|
+
await rm(tempDir, { recursive: true, force: true });
|
|
420
|
+
});
|
|
421
|
+
|
|
422
|
+
it("rejects missing or blank tenants before changing the default library", async () => {
|
|
423
|
+
const declarationModel = GetModel(MediaDeclarationModel, DEFAULT_TENANT_ID);
|
|
424
|
+
const eventModel = GetModel(MediaEventModel, DEFAULT_TENANT_ID);
|
|
425
|
+
const before = {
|
|
426
|
+
folders: await folders().getAll(),
|
|
427
|
+
assets: await assets().getAll(),
|
|
428
|
+
declarations: await declarationModel.getAll(),
|
|
429
|
+
events: await eventModel.getAll(),
|
|
430
|
+
};
|
|
431
|
+
const folder = {
|
|
432
|
+
key: "declared.invalid-tenant",
|
|
433
|
+
name: "No implicit tenant",
|
|
434
|
+
};
|
|
435
|
+
const file = {
|
|
436
|
+
key: "declared.invalid-tenant-file",
|
|
437
|
+
folder: { binding: BINDING_ID },
|
|
438
|
+
name: "invalid-tenant.png",
|
|
439
|
+
mimetype: PNG_MIMETYPE,
|
|
440
|
+
source: { bytes: ONE_PIXEL_PNG },
|
|
441
|
+
};
|
|
442
|
+
// @ts-expect-error A JavaScript caller can omit the required tenantId; this call stops compiling if the public contract makes it optional.
|
|
443
|
+
expect((await rejectionOf(EnsureMediaFolder(folder))).message).to.contain(
|
|
444
|
+
"tenantId",
|
|
445
|
+
);
|
|
446
|
+
// @ts-expect-error A JavaScript caller can omit the required tenantId; this call stops compiling if the public contract makes it optional.
|
|
447
|
+
expect((await rejectionOf(ImportMediaAsset(file))).message).to.contain(
|
|
448
|
+
"tenantId",
|
|
449
|
+
);
|
|
450
|
+
for (const tenantId of ["", " \t\n "]) {
|
|
451
|
+
expect(
|
|
452
|
+
(await rejectionOf(EnsureMediaFolder({ ...folder, tenantId }))).message,
|
|
453
|
+
).to.contain("tenantId");
|
|
454
|
+
expect(
|
|
455
|
+
(await rejectionOf(ImportMediaAsset({ ...file, tenantId }))).message,
|
|
456
|
+
).to.contain("tenantId");
|
|
457
|
+
}
|
|
458
|
+
expect(
|
|
459
|
+
(
|
|
460
|
+
await rejectionOf(
|
|
461
|
+
ImportMediaAsset({
|
|
462
|
+
...file,
|
|
463
|
+
tenantId: "",
|
|
464
|
+
source: { filePath: join(tempDir, "does-not-exist.png") },
|
|
465
|
+
}),
|
|
466
|
+
)
|
|
467
|
+
).message,
|
|
468
|
+
"validation precedes source reads, not only the final database write",
|
|
469
|
+
).to.contain("tenantId");
|
|
470
|
+
expect({
|
|
471
|
+
folders: await folders().getAll(),
|
|
472
|
+
assets: await assets().getAll(),
|
|
473
|
+
declarations: await declarationModel.getAll(),
|
|
474
|
+
events: await eventModel.getAll(),
|
|
475
|
+
}).to.deep.equal(before);
|
|
476
|
+
});
|
|
477
|
+
|
|
478
|
+
it("isolates the same declaration keys in two tenant instances", async () => {
|
|
479
|
+
const tenantId = "declared-isolation";
|
|
480
|
+
const schema = Schema.get(TENANT_SCHEMA_NAME);
|
|
481
|
+
if (!schema) throw new Error("Tenant schema is missing");
|
|
482
|
+
await schema.createInstance(tenantId).run();
|
|
483
|
+
try {
|
|
484
|
+
const folder = {
|
|
485
|
+
tenantId: DEFAULT_TENANT_ID,
|
|
486
|
+
key: "declared.isolated",
|
|
487
|
+
name: "Isolated",
|
|
488
|
+
};
|
|
489
|
+
const firstFolder = await EnsureMediaFolder(folder);
|
|
490
|
+
const secondFolder = await EnsureMediaFolder({ ...folder, tenantId });
|
|
491
|
+
expect(firstFolder.id).to.not.equal(secondFolder.id);
|
|
492
|
+
const file = {
|
|
493
|
+
tenantId: DEFAULT_TENANT_ID,
|
|
494
|
+
key: folder.key,
|
|
495
|
+
folder: { key: folder.key },
|
|
496
|
+
name: "isolated.txt",
|
|
497
|
+
mimetype: "text/plain",
|
|
498
|
+
source: { bytes: Buffer.from("Initial") },
|
|
499
|
+
};
|
|
500
|
+
const firstFile = await ImportMediaAsset(file);
|
|
501
|
+
const secondFile = await ImportMediaAsset({ ...file, tenantId });
|
|
502
|
+
expect(firstFile.id).to.not.equal(secondFile.id);
|
|
503
|
+
expect((await EnsureMediaFolder(folder)).status).to.equal("kept");
|
|
504
|
+
expect((await ImportMediaAsset(file)).status).to.equal("kept");
|
|
505
|
+
expect(
|
|
506
|
+
await GetModel(MediaAssetModel, tenantId).get(firstFile.id),
|
|
507
|
+
).to.equal(undefined);
|
|
508
|
+
expect(await assets().get(secondFile.id)).to.equal(undefined);
|
|
509
|
+
} finally {
|
|
510
|
+
await schema.destroyInstance(tenantId).run();
|
|
511
|
+
}
|
|
512
|
+
});
|
|
513
|
+
|
|
514
|
+
describeFolderDeclarations();
|
|
515
|
+
describeKeptFoldersAndRefusals();
|
|
516
|
+
describeFileImports();
|
|
517
|
+
describeKeptFilesAndRefusals();
|
|
501
518
|
});
|