@uniformdev/assets 20.48.1-alpha.28 → 20.48.1-alpha.48.sha-989c5a3792

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/index.esm.js CHANGED
@@ -1,5 +1,5 @@
1
1
  // src/AssetClient.ts
2
- import { ApiClient } from "@uniformdev/context/api";
2
+ import { ApiClient, rewriteFiltersForApi } from "@uniformdev/context/api";
3
3
  var ASSET_BASE_PATH = "/api/v1/assets";
4
4
  var AssetClient = class extends ApiClient {
5
5
  constructor(options) {
@@ -7,13 +7,30 @@ var AssetClient = class extends ApiClient {
7
7
  }
8
8
  async get(options) {
9
9
  const { projectId } = this.options;
10
+ const { filters, ...params } = options;
11
+ const rewrittenFilters = rewriteFiltersForApi(filters);
10
12
  const fetchUri = this.createUrl(ASSET_BASE_PATH, {
11
- ...options,
12
- projectId
13
+ ...params,
14
+ projectId,
15
+ ...rewrittenFilters
13
16
  });
14
17
  return this.apiClient(fetchUri);
15
18
  }
16
- async upsert(options) {
19
+ /**
20
+ * Fetches a list of assets
21
+ */
22
+ async list(options = {}) {
23
+ const { projectId } = this.options;
24
+ const { filters, ...params } = options;
25
+ const rewrittenFilters = rewriteFiltersForApi(filters);
26
+ const fetchUri = this.createUrl(ASSET_BASE_PATH, {
27
+ ...params,
28
+ projectId,
29
+ ...rewrittenFilters
30
+ });
31
+ return this.apiClient(fetchUri);
32
+ }
33
+ async save(options) {
17
34
  const { projectId } = this.options;
18
35
  const fetchUri = this.createUrl(ASSET_BASE_PATH);
19
36
  await this.apiClient(fetchUri, {
@@ -22,7 +39,11 @@ var AssetClient = class extends ApiClient {
22
39
  expectNoContent: true
23
40
  });
24
41
  }
25
- async delete(options) {
42
+ /** @deprecated Use {@link save} instead. */
43
+ async upsert(options) {
44
+ return this.save(options);
45
+ }
46
+ async remove(options) {
26
47
  const { projectId } = this.options;
27
48
  const fetchUri = this.createUrl(ASSET_BASE_PATH);
28
49
  await this.apiClient(fetchUri, {
@@ -31,6 +52,10 @@ var AssetClient = class extends ApiClient {
31
52
  expectNoContent: true
32
53
  });
33
54
  }
55
+ /** @deprecated Use {@link remove} instead. */
56
+ async delete(options) {
57
+ return this.remove(options);
58
+ }
34
59
  };
35
60
  var UncachedAssetClient = class extends AssetClient {
36
61
  constructor(options) {
@@ -39,6 +64,12 @@ var UncachedAssetClient = class extends AssetClient {
39
64
  };
40
65
 
41
66
  // src/definitions.ts
67
+ import {
68
+ FILE_MIME_TYPES_AUDIO,
69
+ FILE_MIME_TYPES_IMAGE,
70
+ FILE_MIME_TYPES_OTHER,
71
+ FILE_MIME_TYPES_VIDEO
72
+ } from "@uniformdev/files";
42
73
  var assetDefinitions = {
43
74
  image: {
44
75
  id: "image",
@@ -61,6 +92,24 @@ var assetDefinitions = {
61
92
  namePlural: "Other Assets"
62
93
  }
63
94
  };
95
+ var assetDefinitionMimeTypes = {
96
+ image: FILE_MIME_TYPES_IMAGE,
97
+ video: FILE_MIME_TYPES_VIDEO,
98
+ audio: FILE_MIME_TYPES_AUDIO,
99
+ other: FILE_MIME_TYPES_OTHER
100
+ };
101
+ var getAssetDefinitionType = (mimeType) => {
102
+ if (assetDefinitionMimeTypes.image.includes(mimeType)) {
103
+ return assetDefinitions.image.id;
104
+ }
105
+ if (assetDefinitionMimeTypes.video.includes(mimeType)) {
106
+ return assetDefinitions.video.id;
107
+ }
108
+ if (assetDefinitionMimeTypes.audio.includes(mimeType)) {
109
+ return assetDefinitions.audio.id;
110
+ }
111
+ return assetDefinitions.other.id;
112
+ };
64
113
 
65
114
  // src/imageDelivery.ts
66
115
  var isUniformImageUrl = (imageUrl) => {
@@ -68,7 +117,7 @@ var isUniformImageUrl = (imageUrl) => {
68
117
  if (typeof imageUrl !== "string") {
69
118
  return false;
70
119
  }
71
- return /(img)\.(eu\.)?uniform\.(rocks|global)$/.test(new URL(imageUrl).hostname);
120
+ return /(img)\.(eu([1-9]\d*)?\.)?uniform\.(rocks|global)$/.test(new URL(imageUrl).hostname);
72
121
  } catch (e) {
73
122
  return false;
74
123
  }
@@ -134,20 +183,29 @@ var imageFrom = (asset) => {
134
183
  };
135
184
 
136
185
  // src/utils/assetConverter.ts
186
+ var WRITABLE_ASSET_FIELDS = [
187
+ "title",
188
+ "description",
189
+ "file",
190
+ "focalPoint"
191
+ ];
192
+ var selectProperties = (source, names) => {
193
+ const selected = {};
194
+ for (const name of names) {
195
+ selected[name] = source[name];
196
+ }
197
+ return selected;
198
+ };
199
+ var selectWritableAssetFields = (fields = {}) => selectProperties(fields, WRITABLE_ASSET_FIELDS);
137
200
  function convertAssetToPutAsset(asset) {
138
- var _a, _b, _c, _d;
139
201
  return {
140
202
  asset: {
141
203
  _id: asset.asset._id,
142
204
  _dataResources: asset.asset._dataResources,
143
205
  _name: asset.asset._name,
144
206
  type: asset.asset.type,
145
- fields: {
146
- title: (_a = asset.asset.fields) == null ? void 0 : _a.title,
147
- description: (_b = asset.asset.fields) == null ? void 0 : _b.description,
148
- file: (_c = asset.asset.fields) == null ? void 0 : _c.file,
149
- focalPoint: (_d = asset.asset.fields) == null ? void 0 : _d.focalPoint
150
- }
207
+ labels: asset.asset.labels,
208
+ fields: selectWritableAssetFields(asset.asset.fields)
151
209
  },
152
210
  projectId: asset.projectId
153
211
  };
@@ -155,7 +213,11 @@ function convertAssetToPutAsset(asset) {
155
213
  export {
156
214
  AssetClient,
157
215
  UncachedAssetClient,
216
+ WRITABLE_ASSET_FIELDS,
217
+ assetDefinitionMimeTypes,
158
218
  assetDefinitions,
159
219
  convertAssetToPutAsset,
160
- imageFrom
220
+ getAssetDefinitionType,
221
+ imageFrom,
222
+ selectWritableAssetFields
161
223
  };
package/dist/index.js CHANGED
@@ -18,15 +18,19 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
 
20
20
  // src/index.ts
21
- var src_exports = {};
22
- __export(src_exports, {
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
23
  AssetClient: () => AssetClient,
24
24
  UncachedAssetClient: () => UncachedAssetClient,
25
+ WRITABLE_ASSET_FIELDS: () => WRITABLE_ASSET_FIELDS,
26
+ assetDefinitionMimeTypes: () => assetDefinitionMimeTypes,
25
27
  assetDefinitions: () => assetDefinitions,
26
28
  convertAssetToPutAsset: () => convertAssetToPutAsset,
27
- imageFrom: () => imageFrom
29
+ getAssetDefinitionType: () => getAssetDefinitionType,
30
+ imageFrom: () => imageFrom,
31
+ selectWritableAssetFields: () => selectWritableAssetFields
28
32
  });
29
- module.exports = __toCommonJS(src_exports);
33
+ module.exports = __toCommonJS(index_exports);
30
34
 
31
35
  // src/AssetClient.ts
32
36
  var import_api = require("@uniformdev/context/api");
@@ -37,13 +41,30 @@ var AssetClient = class extends import_api.ApiClient {
37
41
  }
38
42
  async get(options) {
39
43
  const { projectId } = this.options;
44
+ const { filters, ...params } = options;
45
+ const rewrittenFilters = (0, import_api.rewriteFiltersForApi)(filters);
40
46
  const fetchUri = this.createUrl(ASSET_BASE_PATH, {
41
- ...options,
42
- projectId
47
+ ...params,
48
+ projectId,
49
+ ...rewrittenFilters
43
50
  });
44
51
  return this.apiClient(fetchUri);
45
52
  }
46
- async upsert(options) {
53
+ /**
54
+ * Fetches a list of assets
55
+ */
56
+ async list(options = {}) {
57
+ const { projectId } = this.options;
58
+ const { filters, ...params } = options;
59
+ const rewrittenFilters = (0, import_api.rewriteFiltersForApi)(filters);
60
+ const fetchUri = this.createUrl(ASSET_BASE_PATH, {
61
+ ...params,
62
+ projectId,
63
+ ...rewrittenFilters
64
+ });
65
+ return this.apiClient(fetchUri);
66
+ }
67
+ async save(options) {
47
68
  const { projectId } = this.options;
48
69
  const fetchUri = this.createUrl(ASSET_BASE_PATH);
49
70
  await this.apiClient(fetchUri, {
@@ -52,7 +73,11 @@ var AssetClient = class extends import_api.ApiClient {
52
73
  expectNoContent: true
53
74
  });
54
75
  }
55
- async delete(options) {
76
+ /** @deprecated Use {@link save} instead. */
77
+ async upsert(options) {
78
+ return this.save(options);
79
+ }
80
+ async remove(options) {
56
81
  const { projectId } = this.options;
57
82
  const fetchUri = this.createUrl(ASSET_BASE_PATH);
58
83
  await this.apiClient(fetchUri, {
@@ -61,6 +86,10 @@ var AssetClient = class extends import_api.ApiClient {
61
86
  expectNoContent: true
62
87
  });
63
88
  }
89
+ /** @deprecated Use {@link remove} instead. */
90
+ async delete(options) {
91
+ return this.remove(options);
92
+ }
64
93
  };
65
94
  var UncachedAssetClient = class extends AssetClient {
66
95
  constructor(options) {
@@ -69,6 +98,7 @@ var UncachedAssetClient = class extends AssetClient {
69
98
  };
70
99
 
71
100
  // src/definitions.ts
101
+ var import_files = require("@uniformdev/files");
72
102
  var assetDefinitions = {
73
103
  image: {
74
104
  id: "image",
@@ -91,6 +121,24 @@ var assetDefinitions = {
91
121
  namePlural: "Other Assets"
92
122
  }
93
123
  };
124
+ var assetDefinitionMimeTypes = {
125
+ image: import_files.FILE_MIME_TYPES_IMAGE,
126
+ video: import_files.FILE_MIME_TYPES_VIDEO,
127
+ audio: import_files.FILE_MIME_TYPES_AUDIO,
128
+ other: import_files.FILE_MIME_TYPES_OTHER
129
+ };
130
+ var getAssetDefinitionType = (mimeType) => {
131
+ if (assetDefinitionMimeTypes.image.includes(mimeType)) {
132
+ return assetDefinitions.image.id;
133
+ }
134
+ if (assetDefinitionMimeTypes.video.includes(mimeType)) {
135
+ return assetDefinitions.video.id;
136
+ }
137
+ if (assetDefinitionMimeTypes.audio.includes(mimeType)) {
138
+ return assetDefinitions.audio.id;
139
+ }
140
+ return assetDefinitions.other.id;
141
+ };
94
142
 
95
143
  // src/imageDelivery.ts
96
144
  var isUniformImageUrl = (imageUrl) => {
@@ -98,7 +146,7 @@ var isUniformImageUrl = (imageUrl) => {
98
146
  if (typeof imageUrl !== "string") {
99
147
  return false;
100
148
  }
101
- return /(img)\.(eu\.)?uniform\.(rocks|global)$/.test(new URL(imageUrl).hostname);
149
+ return /(img)\.(eu([1-9]\d*)?\.)?uniform\.(rocks|global)$/.test(new URL(imageUrl).hostname);
102
150
  } catch (e) {
103
151
  return false;
104
152
  }
@@ -164,20 +212,29 @@ var imageFrom = (asset) => {
164
212
  };
165
213
 
166
214
  // src/utils/assetConverter.ts
215
+ var WRITABLE_ASSET_FIELDS = [
216
+ "title",
217
+ "description",
218
+ "file",
219
+ "focalPoint"
220
+ ];
221
+ var selectProperties = (source, names) => {
222
+ const selected = {};
223
+ for (const name of names) {
224
+ selected[name] = source[name];
225
+ }
226
+ return selected;
227
+ };
228
+ var selectWritableAssetFields = (fields = {}) => selectProperties(fields, WRITABLE_ASSET_FIELDS);
167
229
  function convertAssetToPutAsset(asset) {
168
- var _a, _b, _c, _d;
169
230
  return {
170
231
  asset: {
171
232
  _id: asset.asset._id,
172
233
  _dataResources: asset.asset._dataResources,
173
234
  _name: asset.asset._name,
174
235
  type: asset.asset.type,
175
- fields: {
176
- title: (_a = asset.asset.fields) == null ? void 0 : _a.title,
177
- description: (_b = asset.asset.fields) == null ? void 0 : _b.description,
178
- file: (_c = asset.asset.fields) == null ? void 0 : _c.file,
179
- focalPoint: (_d = asset.asset.fields) == null ? void 0 : _d.focalPoint
180
- }
236
+ labels: asset.asset.labels,
237
+ fields: selectWritableAssetFields(asset.asset.fields)
181
238
  },
182
239
  projectId: asset.projectId
183
240
  };
@@ -186,7 +243,11 @@ function convertAssetToPutAsset(asset) {
186
243
  0 && (module.exports = {
187
244
  AssetClient,
188
245
  UncachedAssetClient,
246
+ WRITABLE_ASSET_FIELDS,
247
+ assetDefinitionMimeTypes,
189
248
  assetDefinitions,
190
249
  convertAssetToPutAsset,
191
- imageFrom
250
+ getAssetDefinitionType,
251
+ imageFrom,
252
+ selectWritableAssetFields
192
253
  });
package/dist/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  // src/AssetClient.ts
2
- import { ApiClient } from "@uniformdev/context/api";
2
+ import { ApiClient, rewriteFiltersForApi } from "@uniformdev/context/api";
3
3
  var ASSET_BASE_PATH = "/api/v1/assets";
4
4
  var AssetClient = class extends ApiClient {
5
5
  constructor(options) {
@@ -7,13 +7,30 @@ var AssetClient = class extends ApiClient {
7
7
  }
8
8
  async get(options) {
9
9
  const { projectId } = this.options;
10
+ const { filters, ...params } = options;
11
+ const rewrittenFilters = rewriteFiltersForApi(filters);
10
12
  const fetchUri = this.createUrl(ASSET_BASE_PATH, {
11
- ...options,
12
- projectId
13
+ ...params,
14
+ projectId,
15
+ ...rewrittenFilters
13
16
  });
14
17
  return this.apiClient(fetchUri);
15
18
  }
16
- async upsert(options) {
19
+ /**
20
+ * Fetches a list of assets
21
+ */
22
+ async list(options = {}) {
23
+ const { projectId } = this.options;
24
+ const { filters, ...params } = options;
25
+ const rewrittenFilters = rewriteFiltersForApi(filters);
26
+ const fetchUri = this.createUrl(ASSET_BASE_PATH, {
27
+ ...params,
28
+ projectId,
29
+ ...rewrittenFilters
30
+ });
31
+ return this.apiClient(fetchUri);
32
+ }
33
+ async save(options) {
17
34
  const { projectId } = this.options;
18
35
  const fetchUri = this.createUrl(ASSET_BASE_PATH);
19
36
  await this.apiClient(fetchUri, {
@@ -22,7 +39,11 @@ var AssetClient = class extends ApiClient {
22
39
  expectNoContent: true
23
40
  });
24
41
  }
25
- async delete(options) {
42
+ /** @deprecated Use {@link save} instead. */
43
+ async upsert(options) {
44
+ return this.save(options);
45
+ }
46
+ async remove(options) {
26
47
  const { projectId } = this.options;
27
48
  const fetchUri = this.createUrl(ASSET_BASE_PATH);
28
49
  await this.apiClient(fetchUri, {
@@ -31,6 +52,10 @@ var AssetClient = class extends ApiClient {
31
52
  expectNoContent: true
32
53
  });
33
54
  }
55
+ /** @deprecated Use {@link remove} instead. */
56
+ async delete(options) {
57
+ return this.remove(options);
58
+ }
34
59
  };
35
60
  var UncachedAssetClient = class extends AssetClient {
36
61
  constructor(options) {
@@ -39,6 +64,12 @@ var UncachedAssetClient = class extends AssetClient {
39
64
  };
40
65
 
41
66
  // src/definitions.ts
67
+ import {
68
+ FILE_MIME_TYPES_AUDIO,
69
+ FILE_MIME_TYPES_IMAGE,
70
+ FILE_MIME_TYPES_OTHER,
71
+ FILE_MIME_TYPES_VIDEO
72
+ } from "@uniformdev/files";
42
73
  var assetDefinitions = {
43
74
  image: {
44
75
  id: "image",
@@ -61,6 +92,24 @@ var assetDefinitions = {
61
92
  namePlural: "Other Assets"
62
93
  }
63
94
  };
95
+ var assetDefinitionMimeTypes = {
96
+ image: FILE_MIME_TYPES_IMAGE,
97
+ video: FILE_MIME_TYPES_VIDEO,
98
+ audio: FILE_MIME_TYPES_AUDIO,
99
+ other: FILE_MIME_TYPES_OTHER
100
+ };
101
+ var getAssetDefinitionType = (mimeType) => {
102
+ if (assetDefinitionMimeTypes.image.includes(mimeType)) {
103
+ return assetDefinitions.image.id;
104
+ }
105
+ if (assetDefinitionMimeTypes.video.includes(mimeType)) {
106
+ return assetDefinitions.video.id;
107
+ }
108
+ if (assetDefinitionMimeTypes.audio.includes(mimeType)) {
109
+ return assetDefinitions.audio.id;
110
+ }
111
+ return assetDefinitions.other.id;
112
+ };
64
113
 
65
114
  // src/imageDelivery.ts
66
115
  var isUniformImageUrl = (imageUrl) => {
@@ -68,7 +117,7 @@ var isUniformImageUrl = (imageUrl) => {
68
117
  if (typeof imageUrl !== "string") {
69
118
  return false;
70
119
  }
71
- return /(img)\.(eu\.)?uniform\.(rocks|global)$/.test(new URL(imageUrl).hostname);
120
+ return /(img)\.(eu([1-9]\d*)?\.)?uniform\.(rocks|global)$/.test(new URL(imageUrl).hostname);
72
121
  } catch (e) {
73
122
  return false;
74
123
  }
@@ -134,20 +183,29 @@ var imageFrom = (asset) => {
134
183
  };
135
184
 
136
185
  // src/utils/assetConverter.ts
186
+ var WRITABLE_ASSET_FIELDS = [
187
+ "title",
188
+ "description",
189
+ "file",
190
+ "focalPoint"
191
+ ];
192
+ var selectProperties = (source, names) => {
193
+ const selected = {};
194
+ for (const name of names) {
195
+ selected[name] = source[name];
196
+ }
197
+ return selected;
198
+ };
199
+ var selectWritableAssetFields = (fields = {}) => selectProperties(fields, WRITABLE_ASSET_FIELDS);
137
200
  function convertAssetToPutAsset(asset) {
138
- var _a, _b, _c, _d;
139
201
  return {
140
202
  asset: {
141
203
  _id: asset.asset._id,
142
204
  _dataResources: asset.asset._dataResources,
143
205
  _name: asset.asset._name,
144
206
  type: asset.asset.type,
145
- fields: {
146
- title: (_a = asset.asset.fields) == null ? void 0 : _a.title,
147
- description: (_b = asset.asset.fields) == null ? void 0 : _b.description,
148
- file: (_c = asset.asset.fields) == null ? void 0 : _c.file,
149
- focalPoint: (_d = asset.asset.fields) == null ? void 0 : _d.focalPoint
150
- }
207
+ labels: asset.asset.labels,
208
+ fields: selectWritableAssetFields(asset.asset.fields)
151
209
  },
152
210
  projectId: asset.projectId
153
211
  };
@@ -155,7 +213,11 @@ function convertAssetToPutAsset(asset) {
155
213
  export {
156
214
  AssetClient,
157
215
  UncachedAssetClient,
216
+ WRITABLE_ASSET_FIELDS,
217
+ assetDefinitionMimeTypes,
158
218
  assetDefinitions,
159
219
  convertAssetToPutAsset,
160
- imageFrom
220
+ getAssetDefinitionType,
221
+ imageFrom,
222
+ selectWritableAssetFields
161
223
  };
package/package.json CHANGED
@@ -1,11 +1,12 @@
1
1
  {
2
2
  "name": "@uniformdev/assets",
3
- "version": "20.48.1-alpha.28+77388717bf",
3
+ "version": "20.48.1-alpha.48.sha-989c5a3792",
4
4
  "description": "Uniform Assets",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "main": "./dist/index.js",
7
7
  "module": "./dist/index.esm.js",
8
8
  "exports": {
9
+ "source": "./src/index.ts",
9
10
  "import": {
10
11
  "types": "./dist/index.d.ts",
11
12
  "node": "./dist/index.mjs",
@@ -20,12 +21,13 @@
20
21
  "sideEffects": false,
21
22
  "scripts": {
22
23
  "build": "run-s update-openapi build:ts",
23
- "build:ts": "tsup",
24
+ "build:ts": "tsup && pnpm test:types",
24
25
  "dev": "run-s update-openapi dev:ts",
25
26
  "dev:ts": "tsup --watch",
26
27
  "clean": "rimraf dist",
27
28
  "test": "vitest run",
28
- "lint": "eslint \"src/**/*.{js,ts,tsx}\"",
29
+ "lint": "tsc7 --noEmit",
30
+ "test:types": "tsc --ignoreConfig --noEmit --strict --skipLibCheck --module esnext --moduleResolution bundler --target es2018 type-tests/imageFrom.ts",
29
31
  "format": "prettier --write \"src/**/*.{js,ts,tsx}\"",
30
32
  "update-openapi": "tsx ./scripts/update-openapi.cts"
31
33
  },
@@ -36,10 +38,12 @@
36
38
  "access": "public"
37
39
  },
38
40
  "dependencies": {
39
- "@uniformdev/context": "20.48.1-alpha.28+77388717bf"
41
+ "@uniformdev/context": "20.48.1-alpha.48.sha-989c5a3792",
42
+ "@uniformdev/files": "20.48.1-alpha.48.sha-989c5a3792"
40
43
  },
41
44
  "devDependencies": {
45
+ "@uniformdev/tsc7": "20.87.0",
42
46
  "ts-xor": "^1.3.0"
43
47
  },
44
- "gitHead": "77388717bfa6e82a2443accdfc896c8e137b2185"
48
+ "gitHead": "989c5a3792acdbac74cf9fa97ec4a60e0a1c3d0d"
45
49
  }