@antelopejs/dms-media 0.7.0 → 0.7.2

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 (176) hide show
  1. package/README.md +18 -24
  2. package/dist/acl/entries.js +2 -1
  3. package/dist/acl/entries.js.map +1 -1
  4. package/dist/asset-lifecycle.js.map +1 -1
  5. package/dist/config.js.map +1 -1
  6. package/dist/db/models/mediaAssets.model.d.ts +7 -5
  7. package/dist/db/models/mediaDeclarations.model.d.ts +7 -5
  8. package/dist/db/models/mediaEvents.model.d.ts +7 -5
  9. package/dist/db/models/mediaFavorites.model.d.ts +7 -5
  10. package/dist/db/models/mediaFolders.model.d.ts +7 -5
  11. package/dist/db/models/mediaUploads.model.d.ts +7 -5
  12. package/dist/declared/assets.js +3 -7
  13. package/dist/declared/assets.js.map +1 -1
  14. package/dist/declared/records.d.ts +2 -1
  15. package/dist/declared/records.js.map +1 -1
  16. package/dist/library/activity.d.ts +1 -1
  17. package/dist/library/activity.js +2 -1
  18. package/dist/library/activity.js.map +1 -1
  19. package/dist/pages/uploads.js +1 -1
  20. package/dist/pages/uploads.js.map +1 -1
  21. package/dist/routes/media/asset-actions.js +12 -4
  22. package/dist/routes/media/asset-actions.js.map +1 -1
  23. package/dist/routes/media/manage.js +2 -2
  24. package/dist/routes/media/manage.js.map +1 -1
  25. package/dist/routes/media/overview.js +5 -1
  26. package/dist/routes/media/overview.js.map +1 -1
  27. package/dist/routes/media/storage-keys.js.map +1 -1
  28. package/dist/routes/media/upload.js +1 -3
  29. package/dist/routes/media/upload.js.map +1 -1
  30. package/dist/test/antelope.test.js +13 -6
  31. package/dist/test/antelope.test.js.map +1 -1
  32. package/dist/test/helpers/assets.d.ts +24 -5
  33. package/dist/test/helpers/assets.js +22 -7
  34. package/dist/test/helpers/assets.js.map +1 -1
  35. package/dist/test/helpers/bodies.d.ts +31 -0
  36. package/dist/test/helpers/bodies.js +16 -0
  37. package/dist/test/helpers/bodies.js.map +1 -0
  38. package/dist/test/helpers/folders.d.ts +50 -0
  39. package/dist/test/helpers/folders.js +4 -2
  40. package/dist/test/helpers/folders.js.map +1 -1
  41. package/dist/test/helpers/members.js +10 -3
  42. package/dist/test/helpers/members.js.map +1 -1
  43. package/dist/test/helpers/owner.js +6 -1
  44. package/dist/test/helpers/owner.js.map +1 -1
  45. package/dist/test/helpers/permissions-world.d.ts +132 -11
  46. package/dist/test/helpers/permissions-world.js +21 -2
  47. package/dist/test/helpers/permissions-world.js.map +1 -1
  48. package/dist/test/helpers/setup-token.d.ts +1 -0
  49. package/dist/test/helpers/setup-token.js +5 -0
  50. package/dist/test/helpers/setup-token.js.map +1 -0
  51. package/dist/test/integration/derivative-sweep-query.test.js +1 -2
  52. package/dist/test/integration/derivative-sweep-query.test.js.map +1 -1
  53. package/dist/test/integration/folder-cascade.test.js +3 -1
  54. package/dist/test/integration/folder-cascade.test.js.map +1 -1
  55. package/dist/test/integration/media-activity-overview.test.js +39 -12
  56. package/dist/test/integration/media-activity-overview.test.js.map +1 -1
  57. package/dist/test/integration/media-api.test.js +22 -21
  58. package/dist/test/integration/media-api.test.js.map +1 -1
  59. package/dist/test/integration/media-bindings.test.js +6 -5
  60. package/dist/test/integration/media-bindings.test.js.map +1 -1
  61. package/dist/test/integration/media-declared-content.test.js +2 -1
  62. package/dist/test/integration/media-declared-content.test.js.map +1 -1
  63. package/dist/test/integration/media-delivery-editing.test.js +12 -2
  64. package/dist/test/integration/media-delivery-editing.test.js.map +1 -1
  65. package/dist/test/integration/media-delivery.test.js +5 -3
  66. package/dist/test/integration/media-delivery.test.js.map +1 -1
  67. package/dist/test/integration/media-explorer-writes.test.js +27 -4
  68. package/dist/test/integration/media-explorer-writes.test.js.map +1 -1
  69. package/dist/test/integration/media-file-history.test.d.ts +1 -0
  70. package/dist/test/integration/media-file-history.test.js +33 -0
  71. package/dist/test/integration/media-file-history.test.js.map +1 -0
  72. package/dist/test/integration/media-guards.test.js +11 -16
  73. package/dist/test/integration/media-guards.test.js.map +1 -1
  74. package/dist/test/integration/media-library.test.js +73 -23
  75. package/dist/test/integration/media-library.test.js.map +1 -1
  76. package/dist/test/integration/media-linked-subfolders.test.js +38 -2
  77. package/dist/test/integration/media-linked-subfolders.test.js.map +1 -1
  78. package/dist/test/integration/media-member-access.test.js +18 -2
  79. package/dist/test/integration/media-member-access.test.js.map +1 -1
  80. package/dist/test/integration/media-permissions.test.js +7 -2
  81. package/dist/test/integration/media-permissions.test.js.map +1 -1
  82. package/dist/test/integration/media-project-field.test.js +17 -2
  83. package/dist/test/integration/media-project-field.test.js.map +1 -1
  84. package/dist/test/integration/media-search-views.test.js +24 -10
  85. package/dist/test/integration/media-search-views.test.js.map +1 -1
  86. package/dist/test/integration/media-storage-origin-unreachable.test.js +2 -1
  87. package/dist/test/integration/media-storage-origin-unreachable.test.js.map +1 -1
  88. package/dist/test/integration/media-transform.test.js +8 -9
  89. package/dist/test/integration/media-transform.test.js.map +1 -1
  90. package/dist/test/integration/media-upload-history-filters.test.d.ts +1 -0
  91. package/dist/test/integration/media-upload-history-filters.test.js +67 -0
  92. package/dist/test/integration/media-upload-history-filters.test.js.map +1 -0
  93. package/dist/test/integration/media-upload-policy.test.js +70 -20
  94. package/dist/test/integration/media-upload-policy.test.js.map +1 -1
  95. package/dist/test/integration/permissions-management.js +15 -4
  96. package/dist/test/integration/permissions-management.js.map +1 -1
  97. package/dist/test/stack-modules.json +7 -0
  98. package/dist/test/unit/declared.test.js +1 -1
  99. package/dist/test/unit/declared.test.js.map +1 -1
  100. package/dist/test/unit/library/activity-overview.test.js +9 -0
  101. package/dist/test/unit/library/activity-overview.test.js.map +1 -1
  102. package/dist/test/unit/library/zip-names.test.js +22 -4
  103. package/dist/test/unit/library/zip-names.test.js.map +1 -1
  104. package/dist/test/unit/pages/toolbar.test.js +4 -4
  105. package/dist/test/unit/pages/toolbar.test.js.map +1 -1
  106. package/dist/test/unit/upload-rules.test.js +10 -0
  107. package/dist/test/unit/upload-rules.test.js.map +1 -1
  108. package/dist/transform-ops.js.map +1 -1
  109. package/dist/upload-checks.d.ts +1 -3
  110. package/dist/upload-checks.js +12 -14
  111. package/dist/upload-checks.js.map +1 -1
  112. package/dist/upload-policy.js +11 -11
  113. package/dist/upload-policy.js.map +1 -1
  114. package/dist/validation/declared.schema.d.ts +4 -4
  115. package/dist/validation/library.schema.d.ts +10 -10
  116. package/dist/validation/media.schema.d.ts +9 -9
  117. package/dist/validation/media.schema.js +5 -6
  118. package/dist/validation/media.schema.js.map +1 -1
  119. package/frontend-vue/app/components/explorer/ExplorerShell.vue +11 -7
  120. package/frontend-vue/i18n/locales/media-en-GB.json +1 -0
  121. package/frontend-vue/i18n/locales/media-fr-FR.json +1 -0
  122. package/frontend-vue/package.json +39 -39
  123. package/package.json +14 -12
  124. package/skills/dms-media/SKILL.md +3 -3
  125. package/src/acl/entries.ts +5 -2
  126. package/src/asset-lifecycle.ts +2 -1
  127. package/src/config.ts +4 -3
  128. package/src/declared/assets.ts +8 -10
  129. package/src/declared/records.ts +5 -1
  130. package/src/library/activity.ts +9 -3
  131. package/src/pages/uploads.ts +1 -1
  132. package/src/routes/media/asset-actions.ts +24 -3
  133. package/src/routes/media/manage.ts +2 -2
  134. package/src/routes/media/overview.ts +5 -4
  135. package/src/routes/media/storage-keys.ts +1 -0
  136. package/src/routes/media/upload.ts +2 -5
  137. package/src/test/antelope.test.ts +10 -6
  138. package/src/test/helpers/assets.ts +28 -15
  139. package/src/test/helpers/bodies.ts +22 -0
  140. package/src/test/helpers/folders.ts +6 -3
  141. package/src/test/helpers/members.ts +11 -3
  142. package/src/test/helpers/owner.ts +6 -1
  143. package/src/test/helpers/permissions-world.ts +23 -19
  144. package/src/test/helpers/setup-token.ts +6 -0
  145. package/src/test/integration/derivative-sweep-query.test.ts +4 -3
  146. package/src/test/integration/folder-cascade.test.ts +3 -1
  147. package/src/test/integration/media-activity-overview.test.ts +52 -37
  148. package/src/test/integration/media-api.test.ts +25 -27
  149. package/src/test/integration/media-bindings.test.ts +10 -16
  150. package/src/test/integration/media-declared-content.test.ts +2 -1
  151. package/src/test/integration/media-delivery-editing.test.ts +13 -2
  152. package/src/test/integration/media-delivery.test.ts +8 -3
  153. package/src/test/integration/media-explorer-writes.test.ts +28 -4
  154. package/src/test/integration/media-file-history.test.ts +38 -0
  155. package/src/test/integration/media-guards.test.ts +18 -13
  156. package/src/test/integration/media-library.test.ts +101 -47
  157. package/src/test/integration/media-linked-subfolders.test.ts +48 -3
  158. package/src/test/integration/media-member-access.test.ts +22 -24
  159. package/src/test/integration/media-permissions.test.ts +11 -5
  160. package/src/test/integration/media-project-field.test.ts +21 -9
  161. package/src/test/integration/media-search-views.test.ts +35 -31
  162. package/src/test/integration/media-storage-origin-unreachable.test.ts +2 -1
  163. package/src/test/integration/media-transform.test.ts +8 -9
  164. package/src/test/integration/media-upload-history-filters.test.ts +77 -0
  165. package/src/test/integration/media-upload-policy.test.ts +84 -30
  166. package/src/test/integration/permissions-management.ts +16 -4
  167. package/src/test/stack-modules.json +7 -0
  168. package/src/test/unit/declared.test.ts +4 -1
  169. package/src/test/unit/library/activity-overview.test.ts +15 -0
  170. package/src/test/unit/library/zip-names.test.ts +26 -7
  171. package/src/test/unit/pages/toolbar.test.ts +4 -4
  172. package/src/test/unit/upload-rules.test.ts +11 -0
  173. package/src/transform-ops.ts +1 -0
  174. package/src/upload-checks.ts +22 -18
  175. package/src/upload-policy.ts +11 -11
  176. package/src/validation/media.schema.ts +9 -8
@@ -1,6 +1,8 @@
1
1
  import type { AxiosInstance } from "axios";
2
2
  import { expect } from "chai";
3
+ import { z } from "zod";
3
4
  import { uploadAsset } from "../helpers/assets";
5
+ import { createdBody, readBody } from "../helpers/bodies";
4
6
  import { authorizedClient } from "../helpers/http";
5
7
  import { createRole, registerMember } from "../helpers/members";
6
8
  import { ensureOwnerSession } from "../helpers/owner";
@@ -11,25 +13,35 @@ const TEXT_MIMETYPE = "text/plain";
11
13
  const BODY = Buffer.alloc(10, 1);
12
14
  const BATCH_ID = "overview-retried-batch";
13
15
 
14
- interface ModuleEntry {
15
- id: string;
16
- landingSlug: string;
17
- readout?: Array<{ text: string; tone?: string }>;
18
- status?: string;
19
- }
16
+ const moduleEntrySchema = z.object({
17
+ id: z.string(),
18
+ landingSlug: z.string(),
19
+ readout: z
20
+ .array(z.object({ text: z.string(), tone: z.string().optional() }))
21
+ .optional(),
22
+ status: z.string().optional(),
23
+ });
24
+
25
+ const modulesBody = z.union([
26
+ z.array(moduleEntrySchema),
27
+ z.object({ modules: z.array(moduleEntrySchema) }),
28
+ ]);
20
29
 
21
- interface BatchRow {
22
- _id: string;
23
- files: number;
24
- failed: number;
25
- result: string;
26
- attention: string;
27
- }
30
+ const batchRowSchema = z.object({
31
+ _id: z.string(),
32
+ files: z.number(),
33
+ failed: z.number(),
34
+ result: z.string(),
35
+ attention: z.string(),
36
+ });
28
37
 
29
- interface ActivityRow {
30
- title: string;
31
- to?: string;
32
- }
38
+ const batchesBody = z.object({ results: z.array(batchRowSchema) });
39
+ const attentionBody = z.object({
40
+ items: z.array(z.object({ id: z.string(), value: z.number().optional() })),
41
+ });
42
+ const activityBody = z.object({
43
+ items: z.array(z.object({ title: z.string(), to: z.string().optional() })),
44
+ });
33
45
 
34
46
  describe("[integration] media activity and overview — figures, upload history and module catalog", () => {
35
47
  let client: AxiosInstance;
@@ -39,9 +51,10 @@ describe("[integration] media activity and overview — figures, upload history
39
51
  this.timeout(30_000);
40
52
  const session = await ensureOwnerSession();
41
53
  client = authorizedClient(session.accessToken);
42
- folderId = (
43
- await client.post("/api/media/folders", { name: "Overview figures" })
44
- ).data.id;
54
+ folderId = readBody(
55
+ await client.post("/api/media/folders", { name: "Overview figures" }),
56
+ createdBody,
57
+ ).id;
45
58
  });
46
59
 
47
60
  after(async () => {
@@ -51,9 +64,8 @@ describe("[integration] media activity and overview — figures, upload history
51
64
  it("lands the catalog tile on the overview, with a readout", async () => {
52
65
  const response = await client.get("/dms/modules-listing");
53
66
  expect(response.status).to.equal(HTTP_OK);
54
- const entries: ModuleEntry[] = Array.isArray(response.data)
55
- ? response.data
56
- : response.data.modules;
67
+ const listing = readBody(response, modulesBody);
68
+ const entries = Array.isArray(listing) ? listing : listing.modules;
57
69
  const media = entries.find((entry) => entry.id === "media");
58
70
  expect(media?.landingSlug).to.equal("/modules/media/overview");
59
71
  expect(media?.readout).to.have.length(2);
@@ -77,29 +89,30 @@ describe("[integration] media activity and overview — figures, upload history
77
89
  const failedOnly = await client.get("/api/media/upload/batches", {
78
90
  params: { filter_result: "is:partial,failed" },
79
91
  });
80
- expect(failedOnly.data.results.map((row: BatchRow) => row._id)).to.include(
81
- BATCH_ID,
82
- );
92
+ expect(
93
+ readBody(failedOnly, batchesBody).results.map((row) => row._id),
94
+ ).to.include(BATCH_ID);
83
95
  expect((await report(2, 0)).status).to.equal(HTTP_OK);
84
96
  const all = await client.get("/api/media/upload/batches");
85
- const row = all.data.results.find(
86
- (entry: BatchRow) => entry._id === BATCH_ID,
97
+ const row = readBody(all, batchesBody).results.find(
98
+ (entry) => entry._id === BATCH_ID,
87
99
  );
88
100
  expect(row).to.include({ failed: 0, result: "complete" });
89
101
  const stillFailed = await client.get("/api/media/upload/batches", {
90
102
  params: { filter_result: "is:partial,failed" },
91
103
  });
92
104
  expect(
93
- stillFailed.data.results.map((entry: BatchRow) => entry._id),
105
+ readBody(stillFailed, batchesBody).results.map((entry) => entry._id),
94
106
  ).to.not.include(BATCH_ID);
95
107
  });
96
108
 
97
109
  it("counts on the overview exactly the failures the history flags", async () => {
98
- const failingFolder = (
110
+ const failingFolder = readBody(
99
111
  await client.post("/api/media/folders", {
100
112
  name: "Overview failing uploads",
101
- })
102
- ).data.id;
113
+ }),
114
+ createdBody,
115
+ ).id;
103
116
  await client.post("/api/media/upload/batches", {
104
117
  batchId: "overview-failing-batch",
105
118
  folderId: failingFolder,
@@ -112,15 +125,15 @@ describe("[integration] media activity and overview — figures, upload history
112
125
  const rows = await client.get("/api/media/upload/batches", {
113
126
  params: { filter_attention: "is:yes" },
114
127
  });
115
- return rows.data.results.reduce(
116
- (total: number, row: BatchRow) => total + row.failed,
128
+ return readBody(rows, batchesBody).results.reduce(
129
+ (total, row) => total + row.failed,
117
130
  0,
118
131
  );
119
132
  };
120
133
  const counted = async () => {
121
134
  const attention = await client.get("/api/media/stats/attention");
122
- const item = attention.data.items.find(
123
- (entry: { id: string }) => entry.id === "failed-uploads",
135
+ const item = readBody(attention, attentionBody).items.find(
136
+ (entry) => entry.id === "failed-uploads",
124
137
  );
125
138
  return item?.value ?? 0;
126
139
  };
@@ -136,7 +149,9 @@ describe("[integration] media activity and overview — figures, upload history
136
149
  const response = await client.get("/api/media/activity", {
137
150
  params: { limit: 50 },
138
151
  });
139
- const titles = response.data.items.map((item: ActivityRow) => item.title);
152
+ const titles = readBody(response, activityBody).items.map(
153
+ (item) => item.title,
154
+ );
140
155
  expect(titles).to.not.include("$dms_media.activity.upload_batch");
141
156
  expect(titles).to.not.include("$dms_media.activity.upload_batch_partial");
142
157
  });
@@ -1,6 +1,8 @@
1
1
  import type { AxiosInstance } from "axios";
2
- import axios from "axios";
3
2
  import { expect } from "chai";
3
+ import { z } from "zod";
4
+ import { putPresigned } from "../helpers/assets";
5
+ import { createdBody, presignBody, readBody } from "../helpers/bodies";
4
6
  import { authorizedClient } from "../helpers/http";
5
7
  import { ensureOwnerSession } from "../helpers/owner";
6
8
 
@@ -26,18 +28,17 @@ async function waitForMediaApi(client: AxiosInstance): Promise<void> {
26
28
  throw new Error("Timed out waiting for the media API to be ready");
27
29
  }
28
30
 
29
- async function uploadBytes(
30
- uploadUrl: string,
31
- headers: Record<string, string>,
32
- body: Buffer,
33
- ): Promise<number> {
34
- const response = await axios.put(uploadUrl, body, {
35
- headers,
36
- validateStatus: () => true,
37
- transformRequest: [(data) => data],
38
- });
39
- return response.status;
40
- }
31
+ const treeBody = z.object({
32
+ folders: z.array(
33
+ z.object({
34
+ id: z.string(),
35
+ parentId: z.string().nullable(),
36
+ rights: z
37
+ .object({ read: z.boolean(), write: z.boolean(), manage: z.boolean() })
38
+ .strict(),
39
+ }),
40
+ ),
41
+ });
41
42
 
42
43
  describe("[integration] media API — owner lifecycle", () => {
43
44
  let client: AxiosInstance;
@@ -64,7 +65,7 @@ describe("[integration] media API — owner lifecycle", () => {
64
65
  name: "Brand",
65
66
  });
66
67
  expect(created.status).to.equal(HTTP_OK);
67
- brandFolderId = created.data.id;
68
+ brandFolderId = readBody(created, createdBody).id;
68
69
  expect(brandFolderId).to.be.a("string");
69
70
 
70
71
  const sub = await client.post("/api/media/folders", {
@@ -72,15 +73,15 @@ describe("[integration] media API — owner lifecycle", () => {
72
73
  parentId: brandFolderId,
73
74
  });
74
75
  expect(sub.status).to.equal(HTTP_OK);
75
- subFolderId = sub.data.id;
76
+ subFolderId = readBody(sub, createdBody).id;
76
77
 
77
78
  const tree = await client.get("/api/media/tree");
78
79
  expect(tree.data.folders).to.have.length(2);
79
- const subNode = tree.data.folders.find(
80
- (node: { id: string }) => node.id === subFolderId,
80
+ const subNode = readBody(tree, treeBody).folders.find(
81
+ (node) => node.id === subFolderId,
81
82
  );
82
- expect(subNode.parentId).to.equal(brandFolderId);
83
- expect(subNode.rights).to.deep.equal({
83
+ expect(subNode?.parentId).to.equal(brandFolderId);
84
+ expect(subNode?.rights).to.deep.equal({
84
85
  read: true,
85
86
  write: true,
86
87
  manage: true,
@@ -103,22 +104,19 @@ describe("[integration] media API — owner lifecycle", () => {
103
104
  mimetype: FILE_MIMETYPE,
104
105
  });
105
106
  expect(presign.status).to.equal(HTTP_OK);
106
- expect(presign.data.resourceKey).to.be.a("string");
107
+ const presigned = readBody(presign, presignBody);
108
+ expect(presigned.resourceKey).to.be.a("string");
107
109
 
108
- const putStatus = await uploadBytes(
109
- presign.data.uploadUrl,
110
- presign.data.headers,
111
- body,
112
- );
110
+ const putStatus = (await putPresigned(presigned, body)).status;
113
111
  expect(putStatus).to.be.lessThan(300);
114
112
 
115
113
  const confirm = await client.post("/api/media/upload/confirm", {
116
114
  folderId: brandFolderId,
117
- resourceKey: presign.data.resourceKey,
115
+ resourceKey: presigned.resourceKey,
118
116
  filename: FILE_NAME,
119
117
  });
120
118
  expect(confirm.status).to.equal(HTTP_OK);
121
- assetId = confirm.data.asset.id;
119
+ assetId = readBody(confirm, z.object({ asset: createdBody })).asset.id;
122
120
  expect(confirm.data.asset.name).to.equal(FILE_NAME);
123
121
  expect(confirm.data.asset.mimetype).to.equal(FILE_MIMETYPE);
124
122
  expect(confirm.data.asset.size).to.equal(body.byteLength);
@@ -8,7 +8,8 @@ import { CustomComponent } from "@antelopejs/interface-dms/base/custom";
8
8
  import type { AxiosInstance } from "axios";
9
9
  import { assert, expect } from "chai";
10
10
  import { RegisterAssetBinding } from "@antelopejs/interface-dms-media";
11
- import { readFolderAcl } from "../helpers/folders";
11
+ import { readBody } from "../helpers/bodies";
12
+ import { folderTreeBody, readFolderAcl } from "../helpers/folders";
12
13
  import { authorizedClient } from "../helpers/http";
13
14
  import { ensureOwnerSession } from "../helpers/owner";
14
15
 
@@ -28,13 +29,6 @@ class PageBoundProbePage extends PageController("page-bound-probe", {
28
29
  static content = CustomComponent("dms-media-page-bound-probe");
29
30
  }
30
31
 
31
- interface FolderNode {
32
- id: string;
33
- name: string;
34
- parentId: string | null;
35
- bound: boolean;
36
- }
37
-
38
32
  describe("[integration] media bindings — linked folder provisioning", () => {
39
33
  let client: AxiosInstance;
40
34
  let contentRootId: string;
@@ -62,7 +56,7 @@ describe("[integration] media bindings — linked folder provisioning", () => {
62
56
  it("provisions the content root and the linked folder lazily", async () => {
63
57
  const tree = await client.get("/api/media/tree");
64
58
  expect(tree.status).to.equal(HTTP_OK);
65
- const folders: FolderNode[] = tree.data.folders;
59
+ const folders = readBody(tree, folderTreeBody).folders;
66
60
  const contentRoot = folders.find(
67
61
  (folder) => folder.name === "Content" && folder.parentId === null,
68
62
  );
@@ -79,8 +73,8 @@ describe("[integration] media bindings — linked folder provisioning", () => {
79
73
  const first = await client.get("/api/media/tree");
80
74
  const second = await client.get("/api/media/tree");
81
75
  expect(second.data.folders.length).to.equal(first.data.folders.length);
82
- const bound = second.data.folders.filter(
83
- (folder: FolderNode) => folder.name === "Article covers",
76
+ const bound = readBody(second, folderTreeBody).folders.filter(
77
+ (folder) => folder.name === "Article covers",
84
78
  );
85
79
  expect(bound).to.have.length(1);
86
80
  });
@@ -101,10 +95,10 @@ describe("[integration] media bindings — linked folder provisioning", () => {
101
95
  const pagePermission = GetPermissionId(PageBoundProbePage);
102
96
  expect(pagePermission, "probe page permission").to.be.a("string");
103
97
  const tree = await client.get("/api/media/tree");
104
- const folder = tree.data.folders.find(
105
- (node: FolderNode) => node.name === PAGE_BOUND_FOLDER_NAME,
98
+ const folder = readBody(tree, folderTreeBody).folders.find(
99
+ (node) => node.name === PAGE_BOUND_FOLDER_NAME,
106
100
  );
107
- expect(folder, "page-bound folder").to.not.equal(undefined);
101
+ assert.isDefined(folder, "page-bound folder");
108
102
  const entries = await readFolderAcl(folder.id);
109
103
  expect(entries).to.deep.include({
110
104
  subject: { kind: "permission", id: pagePermission },
@@ -150,8 +144,8 @@ describe("[integration] media bindings — linked folder provisioning", () => {
150
144
  expect(response.status).to.equal(HTTP_OK);
151
145
  }
152
146
  const tree = await client.get("/api/media/tree");
153
- const probes = tree.data.folders.filter(
154
- (folder: FolderNode) => folder.name === PROBE_NAME,
147
+ const probes = readBody(tree, folderTreeBody).folders.filter(
148
+ (folder) => folder.name === PROBE_NAME,
155
149
  );
156
150
  expect(probes).to.have.length(1);
157
151
  });
@@ -21,6 +21,7 @@ import {
21
21
  MediaFolderModel,
22
22
  } from "../../db";
23
23
  import { ONE_PIXEL_PNG, PNG_MIMETYPE } from "../helpers/assets";
24
+ import { readBody, urlBody } from "../helpers/bodies";
24
25
  import { readFolderAcl } from "../helpers/folders";
25
26
  import { authorizedClient } from "../helpers/http";
26
27
  import { ensureOwnerSession } from "../helpers/owner";
@@ -336,7 +337,7 @@ describe("[integration] media declared content — folders and files shipped as
336
337
  `/api/media/assets/${first.id}/read-url`,
337
338
  );
338
339
  expect(readUrl.status).to.equal(HTTP_OK);
339
- const stored = await fetch(readUrl.data.url);
340
+ const stored = await fetch(readBody(readUrl, urlBody).url);
340
341
  expect(Buffer.from(await stored.arrayBuffer())).to.deep.equal(
341
342
  ONE_PIXEL_PNG,
342
343
  );
@@ -4,6 +4,7 @@ import { assert, expect } from "chai";
4
4
  import { GetModel } from "@antelopejs/interface-database-decorators";
5
5
  import { DEFAULT_TENANT_ID } from "@antelopejs/interface-dms/constants";
6
6
  import sharp from "sharp";
7
+ import { z } from "zod";
7
8
  import { MediaAssetModel } from "../../db";
8
9
  import { uploadStorageBytes } from "../../derivatives";
9
10
  import {
@@ -12,9 +13,16 @@ import {
12
13
  MediaAssetChangedError,
13
14
  } from "../../transform";
14
15
  import { type UploadedAsset, uploadAsset } from "../helpers/assets";
16
+ import { createdBody, readBody } from "../helpers/bodies";
15
17
  import { authorizedClient, getBaseUrl } from "../helpers/http";
16
18
  import { ensureOwnerSession } from "../helpers/owner";
17
19
 
20
+ const previewsBody = z.object({
21
+ previews: z
22
+ .record(z.string())
23
+ .transform((urls) => new Map(Object.entries(urls))),
24
+ });
25
+
18
26
  const HTTP_OK = 200;
19
27
  const HTTP_FOUND = 302;
20
28
  const HTTP_NOT_MODIFIED = 304;
@@ -153,7 +161,7 @@ describe("[integration] media delivery and editing — cache, orientation, activ
153
161
  name: "Delivery and editing",
154
162
  });
155
163
  expect(folder.status).to.equal(HTTP_OK);
156
- folderId = folder.data.id;
164
+ folderId = readBody(folder, createdBody).id;
157
165
  jpeg = await uploadAsset(
158
166
  client,
159
167
  folderId,
@@ -341,9 +349,12 @@ describe("[integration] media delivery and editing — cache, orientation, activ
341
349
  `/api/media/previews?ids=${logo.id}&ids=${banner.id}`,
342
350
  );
343
351
  expect(answer.status).to.equal(HTTP_OK);
352
+ const { previews } = readBody(answer, previewsBody);
344
353
  const [vector, raster] = await Promise.all(
345
354
  [logo.id, banner.id].map(async (id) => {
346
- const response = await fetch(answer.data.previews[id]);
355
+ const preview = previews.get(id);
356
+ assert.isDefined(preview, `preview of ${id}`);
357
+ const response = await fetch(preview);
347
358
  return sharp(Buffer.from(await response.arrayBuffer())).metadata();
348
359
  }),
349
360
  );
@@ -1,11 +1,13 @@
1
1
  import type { AxiosInstance } from "axios";
2
2
  import { assert, expect } from "chai";
3
+ import { z } from "zod";
3
4
  import {
4
5
  ONE_PIXEL_PNG,
5
6
  PNG_NAME,
6
7
  rawGet,
7
8
  uploadPixelPng,
8
9
  } from "../helpers/assets";
10
+ import { createdBody, readBody, urlBody } from "../helpers/bodies";
9
11
  import { authorizedClient } from "../helpers/http";
10
12
  import { ensureOwnerSession } from "../helpers/owner";
11
13
 
@@ -39,7 +41,7 @@ describe("[integration] media delivery — visibility and derivatives", () => {
39
41
  name: "Delivery",
40
42
  });
41
43
  expect(folder.status).to.equal(HTTP_OK);
42
- folderId = folder.data.id;
44
+ folderId = readBody(folder, createdBody).id;
43
45
  const asset = await uploadPixelPng(client, folderId);
44
46
  assetId = asset.id;
45
47
  });
@@ -115,7 +117,7 @@ describe("[integration] media delivery — visibility and derivatives", () => {
115
117
  `/api/media/assets/${assetId}/read-url?preset=thumb`,
116
118
  );
117
119
  expect(derived.status).to.equal(HTTP_OK);
118
- const bytes = await fetchBytes(derived.data.url);
120
+ const bytes = await fetchBytes(readBody(derived, urlBody).url);
119
121
  expect(bytes.byteLength).to.be.greaterThan(0);
120
122
  });
121
123
 
@@ -123,7 +125,10 @@ describe("[integration] media delivery — visibility and derivatives", () => {
123
125
  const listing = await client.get("/api/media/assets");
124
126
  expect(listing.status).to.equal(HTTP_OK);
125
127
  expect(listing.data.truncated).to.equal(false);
126
- const ids = listing.data.assets.map((asset: { id: string }) => asset.id);
128
+ const ids = readBody(
129
+ listing,
130
+ z.object({ assets: z.array(createdBody) }),
131
+ ).assets.map((asset) => asset.id);
127
132
  expect(ids).to.include(assetId);
128
133
 
129
134
  const secondAsset = await uploadPixelPng(client, folderId);
@@ -1,5 +1,6 @@
1
1
  import type { AxiosInstance } from "axios";
2
2
  import { expect } from "chai";
3
+ import { z } from "zod";
3
4
  import { GetModel } from "@antelopejs/interface-database-decorators";
4
5
  import { DEFAULT_TENANT_ID } from "@antelopejs/interface-dms/constants";
5
6
  import {
@@ -9,6 +10,7 @@ import {
9
10
  import { CONTENT_ROOT_BINDING } from "../../bindings";
10
11
  import { MediaEventModel, MediaFolderModel } from "../../db";
11
12
  import { uploadPixelPng, uploadTextAsset } from "../helpers/assets";
13
+ import { createdBody, readBody } from "../helpers/bodies";
12
14
  import { fetchFolderNodes } from "../helpers/folders";
13
15
  import { authorizedClient } from "../helpers/http";
14
16
  import { ensureOwnerSession } from "../helpers/owner";
@@ -72,12 +74,12 @@ describe("[integration] media explorer writes — names, linked folders, zips",
72
74
  name: "Explorer writes",
73
75
  });
74
76
  expect(root.status).to.equal(HTTP_OK);
75
- rootId = root.data.id;
77
+ rootId = readBody(root, createdBody).id;
76
78
  const other = await client.post("/api/media/folders", {
77
79
  name: "Other",
78
80
  parentId: rootId,
79
81
  });
80
- otherId = other.data.id;
82
+ otherId = readBody(other, createdBody).id;
81
83
  });
82
84
 
83
85
  after(async () => {
@@ -116,7 +118,7 @@ describe("[integration] media explorer writes — names, linked folders, zips",
116
118
  const event = events.find((entry) => entry.targetName === "Traced");
117
119
  expect(event?.folderId).to.equal(rootId);
118
120
  expect(JSON.parse(event?.json_details ?? "{}")).to.deep.equal({
119
- targetId: created.data.id,
121
+ targetId: readBody(created, createdBody).id,
120
122
  });
121
123
  });
122
124
 
@@ -157,6 +159,28 @@ describe("[integration] media explorer writes — names, linked folders, zips",
157
159
  expect(sameNameElsewhere.status).to.equal(HTTP_OK);
158
160
  });
159
161
 
162
+ it("refuses to move a file onto a name the target folder already holds, regardless of case", async () => {
163
+ const held = await uploadTextAsset(client, otherId, "Report.txt");
164
+ const mover = await uploadTextAsset(client, rootId, "report.txt");
165
+ const moved = await client.post(`/api/media/assets/${mover.id}/move`, {
166
+ folderId: otherId,
167
+ });
168
+ expect(moved.status).to.equal(HTTP_CONFLICT);
169
+ expect(moved.data).to.equal(`${ERRORS}.name_taken`);
170
+ const bulk = await client.post("/api/media/assets/bulk/move", {
171
+ ids: [mover.id],
172
+ folderId: otherId,
173
+ });
174
+ expect(bulk.data.done).to.deep.equal([]);
175
+ expect(bulk.data.refused).to.deep.equal([
176
+ { id: mover.id, status: HTTP_CONFLICT, message: `${ERRORS}.name_taken` },
177
+ ]);
178
+ const detail = await client.get(`/api/media/assets/${mover.id}`);
179
+ expect(detail.data.asset.folderId).to.equal(rootId);
180
+ await client.delete(`/api/media/assets/${held.id}`);
181
+ await client.delete(`/api/media/assets/${mover.id}`);
182
+ });
183
+
160
184
  it("answers validation errors with i18n keys instead of zod dumps", async () => {
161
185
  const asset = await uploadPixelPng(client, rootId);
162
186
  const tooLong = await client.post(`/api/media/assets/${asset.id}/update`, {
@@ -190,7 +214,7 @@ describe("[integration] media explorer writes — names, linked folders, zips",
190
214
  expect(zipped.headers["content-disposition"]).to.contain(
191
215
  "Explorer writes.zip",
192
216
  );
193
- const names = zipEntryNames(Buffer.from(zipped.data));
217
+ const names = zipEntryNames(readBody(zipped, z.instanceof(Buffer)));
194
218
  expect(names).to.include.members([
195
219
  "Notes.txt",
196
220
  "other.txt",
@@ -0,0 +1,38 @@
1
+ import { expect } from "chai";
2
+ import { z } from "zod";
3
+ import { uploadPixelPng } from "../helpers/assets";
4
+ import { createdBody, readBody } from "../helpers/bodies";
5
+ import { authorizedClient } from "../helpers/http";
6
+ import { ensureOwnerSession } from "../helpers/owner";
7
+
8
+ const HTTP_OK = 200;
9
+ const RENAMES = 55;
10
+
11
+ const historyBody = z.object({
12
+ items: z.array(z.object({ title: z.string() })),
13
+ });
14
+
15
+ describe("[integration] file history — every event of the file", () => {
16
+ it("lists more than 50 events, the upload last", async function () {
17
+ this.timeout(60_000);
18
+ const session = await ensureOwnerSession();
19
+ const client = authorizedClient(session.accessToken);
20
+ const folderId = readBody(
21
+ await client.post("/api/media/folders", { name: "File history spec" }),
22
+ createdBody,
23
+ ).id;
24
+ const asset = await uploadPixelPng(client, folderId);
25
+ for (let index = 1; index <= RENAMES; index += 1) {
26
+ const rename = await client.post(`/api/media/assets/${asset.id}/update`, {
27
+ name: `history-${index}.png`,
28
+ });
29
+ expect(rename.status, `rename ${index}`).to.equal(HTTP_OK);
30
+ }
31
+ const history = await client.get(`/api/media/assets/${asset.id}/history`);
32
+ const titles = readBody(history, historyBody).items.map(
33
+ (item) => item.title,
34
+ );
35
+ expect(titles).to.have.length(RENAMES + 1);
36
+ expect(titles.at(-1)).to.equal("$dms_media.activity.asset_upload");
37
+ });
38
+ });
@@ -1,6 +1,8 @@
1
1
  import { randomUUID } from "node:crypto";
2
- import axios, { type AxiosInstance } from "axios";
2
+ import type { AxiosInstance } from "axios";
3
3
  import { expect } from "chai";
4
+ import { putPresigned } from "../helpers/assets";
5
+ import { createdBody, presignBody, readBody } from "../helpers/bodies";
4
6
  import { authorizedClient, createClient } from "../helpers/http";
5
7
  import { ensureOwnerSession } from "../helpers/owner";
6
8
 
@@ -99,12 +101,14 @@ describe("[integration] media guards — every endpoint requires auth and rights
99
101
  });
100
102
  expect(folder.status).to.equal(HTTP_OK);
101
103
  const confirm = await owner.post("/api/media/upload/confirm", {
102
- folderId: folder.data.id,
104
+ folderId: readBody(folder, createdBody).id,
103
105
  resourceKey: "media/whatever/not-staged.txt",
104
106
  filename: "not-staged.txt",
105
107
  });
106
108
  expect(confirm.status).to.equal(HTTP_BAD_REQUEST);
107
- await owner.delete(`/api/media/folders/${folder.data.id}`);
109
+ await owner.delete(
110
+ `/api/media/folders/${readBody(folder, createdBody).id}`,
111
+ );
108
112
  });
109
113
 
110
114
  it("filters unreadable assets out of previews instead of failing", async () => {
@@ -120,25 +124,26 @@ describe("[integration] media guards — every endpoint requires auth and rights
120
124
  const folderB = await owner.post("/api/media/folders", { name: "KeyB" });
121
125
  const body = Buffer.from("cross-folder");
122
126
  const presign = await owner.post("/api/media/upload/presign", {
123
- folderId: folderA.data.id,
127
+ folderId: readBody(folderA, createdBody).id,
124
128
  filename: "x.txt",
125
129
  size: body.byteLength,
126
130
  mimetype: "text/plain",
127
131
  });
128
132
  expect(presign.status).to.equal(HTTP_OK);
129
- const put = await axios.put(presign.data.uploadUrl, body, {
130
- headers: presign.data.headers,
131
- validateStatus: () => true,
132
- transformRequest: [(data) => data],
133
- });
133
+ const presigned = readBody(presign, presignBody);
134
+ const put = await putPresigned(presigned, body);
134
135
  expect(put.status).to.be.lessThan(300);
135
136
  const confirm = await owner.post("/api/media/upload/confirm", {
136
- folderId: folderB.data.id,
137
- resourceKey: presign.data.resourceKey,
137
+ folderId: readBody(folderB, createdBody).id,
138
+ resourceKey: presigned.resourceKey,
138
139
  filename: "x.txt",
139
140
  });
140
141
  expect(confirm.status).to.equal(HTTP_BAD_REQUEST);
141
- await owner.delete(`/api/media/folders/${folderA.data.id}`);
142
- await owner.delete(`/api/media/folders/${folderB.data.id}`);
142
+ await owner.delete(
143
+ `/api/media/folders/${readBody(folderA, createdBody).id}`,
144
+ );
145
+ await owner.delete(
146
+ `/api/media/folders/${readBody(folderB, createdBody).id}`,
147
+ );
143
148
  });
144
149
  });