@uniformdev/assets 20.49.2 → 20.49.3-alpha.47

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,9 +7,12 @@ 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
  }
@@ -39,6 +42,7 @@ var UncachedAssetClient = class extends AssetClient {
39
42
  };
40
43
 
41
44
  // src/definitions.ts
45
+ import { FILE_MIME_TYPES_AUDIO, FILE_MIME_TYPES_IMAGE, FILE_MIME_TYPES_VIDEO } from "@uniformdev/files";
42
46
  var assetDefinitions = {
43
47
  image: {
44
48
  id: "image",
@@ -61,6 +65,18 @@ var assetDefinitions = {
61
65
  namePlural: "Other Assets"
62
66
  }
63
67
  };
68
+ var getAssetDefinitionType = (mimeType) => {
69
+ if (FILE_MIME_TYPES_IMAGE.includes(mimeType)) {
70
+ return assetDefinitions.image.id;
71
+ }
72
+ if (FILE_MIME_TYPES_VIDEO.includes(mimeType)) {
73
+ return assetDefinitions.video.id;
74
+ }
75
+ if (FILE_MIME_TYPES_AUDIO.includes(mimeType)) {
76
+ return assetDefinitions.audio.id;
77
+ }
78
+ return assetDefinitions.other.id;
79
+ };
64
80
 
65
81
  // src/imageDelivery.ts
66
82
  var isUniformImageUrl = (imageUrl) => {
@@ -68,7 +84,7 @@ var isUniformImageUrl = (imageUrl) => {
68
84
  if (typeof imageUrl !== "string") {
69
85
  return false;
70
86
  }
71
- return /(img)\.(eu\.)?uniform\.(rocks|global)$/.test(new URL(imageUrl).hostname);
87
+ return /(img)\.(eu([1-9]\d*)?\.)?uniform\.(rocks|global)$/.test(new URL(imageUrl).hostname);
72
88
  } catch (e) {
73
89
  return false;
74
90
  }
@@ -142,6 +158,7 @@ function convertAssetToPutAsset(asset) {
142
158
  _dataResources: asset.asset._dataResources,
143
159
  _name: asset.asset._name,
144
160
  type: asset.asset.type,
161
+ labels: asset.asset.labels,
145
162
  fields: {
146
163
  title: (_a = asset.asset.fields) == null ? void 0 : _a.title,
147
164
  description: (_b = asset.asset.fields) == null ? void 0 : _b.description,
@@ -157,5 +174,6 @@ export {
157
174
  UncachedAssetClient,
158
175
  assetDefinitions,
159
176
  convertAssetToPutAsset,
177
+ getAssetDefinitionType,
160
178
  imageFrom
161
179
  };
package/dist/index.js CHANGED
@@ -18,15 +18,16 @@ 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
25
  assetDefinitions: () => assetDefinitions,
26
26
  convertAssetToPutAsset: () => convertAssetToPutAsset,
27
+ getAssetDefinitionType: () => getAssetDefinitionType,
27
28
  imageFrom: () => imageFrom
28
29
  });
29
- module.exports = __toCommonJS(src_exports);
30
+ module.exports = __toCommonJS(index_exports);
30
31
 
31
32
  // src/AssetClient.ts
32
33
  var import_api = require("@uniformdev/context/api");
@@ -37,9 +38,12 @@ var AssetClient = class extends import_api.ApiClient {
37
38
  }
38
39
  async get(options) {
39
40
  const { projectId } = this.options;
41
+ const { filters, ...params } = options;
42
+ const rewrittenFilters = (0, import_api.rewriteFiltersForApi)(filters);
40
43
  const fetchUri = this.createUrl(ASSET_BASE_PATH, {
41
- ...options,
42
- projectId
44
+ ...params,
45
+ projectId,
46
+ ...rewrittenFilters
43
47
  });
44
48
  return this.apiClient(fetchUri);
45
49
  }
@@ -69,6 +73,7 @@ var UncachedAssetClient = class extends AssetClient {
69
73
  };
70
74
 
71
75
  // src/definitions.ts
76
+ var import_files = require("@uniformdev/files");
72
77
  var assetDefinitions = {
73
78
  image: {
74
79
  id: "image",
@@ -91,6 +96,18 @@ var assetDefinitions = {
91
96
  namePlural: "Other Assets"
92
97
  }
93
98
  };
99
+ var getAssetDefinitionType = (mimeType) => {
100
+ if (import_files.FILE_MIME_TYPES_IMAGE.includes(mimeType)) {
101
+ return assetDefinitions.image.id;
102
+ }
103
+ if (import_files.FILE_MIME_TYPES_VIDEO.includes(mimeType)) {
104
+ return assetDefinitions.video.id;
105
+ }
106
+ if (import_files.FILE_MIME_TYPES_AUDIO.includes(mimeType)) {
107
+ return assetDefinitions.audio.id;
108
+ }
109
+ return assetDefinitions.other.id;
110
+ };
94
111
 
95
112
  // src/imageDelivery.ts
96
113
  var isUniformImageUrl = (imageUrl) => {
@@ -98,7 +115,7 @@ var isUniformImageUrl = (imageUrl) => {
98
115
  if (typeof imageUrl !== "string") {
99
116
  return false;
100
117
  }
101
- return /(img)\.(eu\.)?uniform\.(rocks|global)$/.test(new URL(imageUrl).hostname);
118
+ return /(img)\.(eu([1-9]\d*)?\.)?uniform\.(rocks|global)$/.test(new URL(imageUrl).hostname);
102
119
  } catch (e) {
103
120
  return false;
104
121
  }
@@ -172,6 +189,7 @@ function convertAssetToPutAsset(asset) {
172
189
  _dataResources: asset.asset._dataResources,
173
190
  _name: asset.asset._name,
174
191
  type: asset.asset.type,
192
+ labels: asset.asset.labels,
175
193
  fields: {
176
194
  title: (_a = asset.asset.fields) == null ? void 0 : _a.title,
177
195
  description: (_b = asset.asset.fields) == null ? void 0 : _b.description,
@@ -188,5 +206,6 @@ function convertAssetToPutAsset(asset) {
188
206
  UncachedAssetClient,
189
207
  assetDefinitions,
190
208
  convertAssetToPutAsset,
209
+ getAssetDefinitionType,
191
210
  imageFrom
192
211
  });
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,9 +7,12 @@ 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
  }
@@ -39,6 +42,7 @@ var UncachedAssetClient = class extends AssetClient {
39
42
  };
40
43
 
41
44
  // src/definitions.ts
45
+ import { FILE_MIME_TYPES_AUDIO, FILE_MIME_TYPES_IMAGE, FILE_MIME_TYPES_VIDEO } from "@uniformdev/files";
42
46
  var assetDefinitions = {
43
47
  image: {
44
48
  id: "image",
@@ -61,6 +65,18 @@ var assetDefinitions = {
61
65
  namePlural: "Other Assets"
62
66
  }
63
67
  };
68
+ var getAssetDefinitionType = (mimeType) => {
69
+ if (FILE_MIME_TYPES_IMAGE.includes(mimeType)) {
70
+ return assetDefinitions.image.id;
71
+ }
72
+ if (FILE_MIME_TYPES_VIDEO.includes(mimeType)) {
73
+ return assetDefinitions.video.id;
74
+ }
75
+ if (FILE_MIME_TYPES_AUDIO.includes(mimeType)) {
76
+ return assetDefinitions.audio.id;
77
+ }
78
+ return assetDefinitions.other.id;
79
+ };
64
80
 
65
81
  // src/imageDelivery.ts
66
82
  var isUniformImageUrl = (imageUrl) => {
@@ -68,7 +84,7 @@ var isUniformImageUrl = (imageUrl) => {
68
84
  if (typeof imageUrl !== "string") {
69
85
  return false;
70
86
  }
71
- return /(img)\.(eu\.)?uniform\.(rocks|global)$/.test(new URL(imageUrl).hostname);
87
+ return /(img)\.(eu([1-9]\d*)?\.)?uniform\.(rocks|global)$/.test(new URL(imageUrl).hostname);
72
88
  } catch (e) {
73
89
  return false;
74
90
  }
@@ -142,6 +158,7 @@ function convertAssetToPutAsset(asset) {
142
158
  _dataResources: asset.asset._dataResources,
143
159
  _name: asset.asset._name,
144
160
  type: asset.asset.type,
161
+ labels: asset.asset.labels,
145
162
  fields: {
146
163
  title: (_a = asset.asset.fields) == null ? void 0 : _a.title,
147
164
  description: (_b = asset.asset.fields) == null ? void 0 : _b.description,
@@ -157,5 +174,6 @@ export {
157
174
  UncachedAssetClient,
158
175
  assetDefinitions,
159
176
  convertAssetToPutAsset,
177
+ getAssetDefinitionType,
160
178
  imageFrom
161
179
  };
package/package.json CHANGED
@@ -1,11 +1,12 @@
1
1
  {
2
2
  "name": "@uniformdev/assets",
3
- "version": "20.49.2",
3
+ "version": "20.49.3-alpha.47+9aed70a64d",
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,12 @@
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
+ "test:types": "tsc --ignoreConfig --noEmit --strict --skipLibCheck --module esnext --moduleResolution bundler --target es2018 type-tests/imageFrom.ts",
29
30
  "format": "prettier --write \"src/**/*.{js,ts,tsx}\"",
30
31
  "update-openapi": "tsx ./scripts/update-openapi.cts"
31
32
  },
@@ -36,10 +37,11 @@
36
37
  "access": "public"
37
38
  },
38
39
  "dependencies": {
39
- "@uniformdev/context": "20.49.2"
40
+ "@uniformdev/context": "20.49.3-alpha.47+9aed70a64d",
41
+ "@uniformdev/files": "20.49.3-alpha.47+9aed70a64d"
40
42
  },
41
43
  "devDependencies": {
42
44
  "ts-xor": "^1.3.0"
43
45
  },
44
- "gitHead": "6236dd13bff34cc8ec526d2e93e344428c1c9541"
46
+ "gitHead": "9aed70a64de0ca177d27ea99dc25f1ad053f87ad"
45
47
  }