@texturehq/device 1.18.0 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/common/cache.d.ts +20 -0
- package/dist/common/cache.d.ts.map +1 -0
- package/dist/common/cache.js +40 -0
- package/dist/common/cache.js.map +1 -0
- package/dist/common/constants.d.ts +1 -1
- package/dist/common/constants.d.ts.map +1 -1
- package/dist/common/constants.js +1 -1
- package/dist/common/constants.js.map +1 -1
- package/dist/common/fetch.d.ts +10 -0
- package/dist/common/fetch.d.ts.map +1 -0
- package/dist/common/fetch.js +39 -0
- package/dist/common/fetch.js.map +1 -0
- package/dist/deviceModel/getDeviceModel/index.d.ts +5 -10
- package/dist/deviceModel/getDeviceModel/index.d.ts.map +1 -1
- package/dist/deviceModel/getDeviceModel/index.js +39 -22
- package/dist/deviceModel/getDeviceModel/index.js.map +1 -1
- package/dist/deviceModel/getDeviceModel/response.interfaces.d.ts +5 -94
- package/dist/deviceModel/getDeviceModel/response.interfaces.d.ts.map +1 -1
- package/dist/deviceModel/getDeviceModel/response.interfaces.js +0 -249
- package/dist/deviceModel/getDeviceModel/response.interfaces.js.map +1 -1
- package/dist/deviceModel/getDeviceModelByManufacturerSlug/index.d.ts +6 -11
- package/dist/deviceModel/getDeviceModelByManufacturerSlug/index.d.ts.map +1 -1
- package/dist/deviceModel/getDeviceModelByManufacturerSlug/index.js +39 -29
- package/dist/deviceModel/getDeviceModelByManufacturerSlug/index.js.map +1 -1
- package/dist/deviceModel/getDeviceModelByManufacturerSlug/response.interfaces.d.ts +5 -52
- package/dist/deviceModel/getDeviceModelByManufacturerSlug/response.interfaces.d.ts.map +1 -1
- package/dist/deviceModel/getDeviceModelByManufacturerSlug/response.interfaces.js +0 -207
- package/dist/deviceModel/getDeviceModelByManufacturerSlug/response.interfaces.js.map +1 -1
- package/dist/deviceModel/getDeviceModels/index.d.ts +5 -10
- package/dist/deviceModel/getDeviceModels/index.d.ts.map +1 -1
- package/dist/deviceModel/getDeviceModels/index.js +50 -28
- package/dist/deviceModel/getDeviceModels/index.js.map +1 -1
- package/dist/deviceModel/getDeviceModels/response.interfaces.d.ts +15 -84
- package/dist/deviceModel/getDeviceModels/response.interfaces.d.ts.map +1 -1
- package/dist/deviceModel/getDeviceModels/response.interfaces.js +0 -249
- package/dist/deviceModel/getDeviceModels/response.interfaces.js.map +1 -1
- package/dist/deviceModel/getDeviceModels/test.success.js +0 -1
- package/dist/deviceModel/getDeviceModels/test.success.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/manufacturer/getManufacturer/index.d.ts +7 -16
- package/dist/manufacturer/getManufacturer/index.d.ts.map +1 -1
- package/dist/manufacturer/getManufacturer/index.js +24 -21
- package/dist/manufacturer/getManufacturer/index.js.map +1 -1
- package/dist/manufacturer/getManufacturer/response.interfaces.d.ts +6 -76
- package/dist/manufacturer/getManufacturer/response.interfaces.d.ts.map +1 -1
- package/dist/manufacturer/getManufacturer/response.interfaces.js +0 -231
- package/dist/manufacturer/getManufacturer/response.interfaces.js.map +1 -1
- package/dist/manufacturer/getManufacturers/index.d.ts +4 -10
- package/dist/manufacturer/getManufacturers/index.d.ts.map +1 -1
- package/dist/manufacturer/getManufacturers/index.js +37 -20
- package/dist/manufacturer/getManufacturers/index.js.map +1 -1
- package/dist/manufacturer/getManufacturers/response.interfaces.d.ts +12 -74
- package/dist/manufacturer/getManufacturers/response.interfaces.d.ts.map +1 -1
- package/dist/manufacturer/getManufacturers/response.interfaces.js +0 -239
- package/dist/manufacturer/getManufacturers/response.interfaces.js.map +1 -1
- package/dist/manufacturer/getManufacturers/test.success.js +1 -1
- package/dist/manufacturer/getManufacturers/test.success.js.map +1 -1
- package/dist/manufacturer/parseManufacturer/index.d.ts +5 -2
- package/dist/manufacturer/parseManufacturer/index.d.ts.map +1 -1
- package/dist/manufacturer/parseManufacturer/index.js +18 -23
- package/dist/manufacturer/parseManufacturer/index.js.map +1 -1
- package/package.json +1 -7
- package/dist/common/axios.d.ts +0 -3
- package/dist/common/axios.d.ts.map +0 -1
- package/dist/common/axios.js +0 -29
- package/dist/common/axios.js.map +0 -1
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Simple in-memory TTL cache for API responses.
|
|
3
|
+
*
|
|
4
|
+
* Since manufacturer and device model data changes infrequently (a few times
|
|
5
|
+
* per month), caching responses avoids tens of thousands of redundant API calls
|
|
6
|
+
* per day from OEM adapters. Cache clears naturally on container restart.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Get a value from cache if it exists and hasn't expired.
|
|
10
|
+
*/
|
|
11
|
+
export declare function cacheGet<T>(key: string): T | undefined;
|
|
12
|
+
/**
|
|
13
|
+
* Store a value in cache with a TTL.
|
|
14
|
+
*/
|
|
15
|
+
export declare function cacheSet<T>(key: string, data: T, ttlMs?: number): void;
|
|
16
|
+
/**
|
|
17
|
+
* Clear all cached entries. Useful for testing.
|
|
18
|
+
*/
|
|
19
|
+
export declare function cacheClear(): void;
|
|
20
|
+
//# sourceMappingURL=cache.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cache.d.ts","sourceRoot":"","sources":["../../src/common/cache.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAWH;;GAEG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,GAAG,CAAC,GAAG,SAAS,CAQtD;AAED;;GAEG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,EAAE,KAAK,GAAE,MAAuB,GAAG,IAAI,CAEtF;AAED;;GAEG;AACH,wBAAgB,UAAU,IAAI,IAAI,CAEjC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Simple in-memory TTL cache for API responses.
|
|
4
|
+
*
|
|
5
|
+
* Since manufacturer and device model data changes infrequently (a few times
|
|
6
|
+
* per month), caching responses avoids tens of thousands of redundant API calls
|
|
7
|
+
* per day from OEM adapters. Cache clears naturally on container restart.
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.cacheGet = cacheGet;
|
|
11
|
+
exports.cacheSet = cacheSet;
|
|
12
|
+
exports.cacheClear = cacheClear;
|
|
13
|
+
const DEFAULT_TTL_MS = 60 * 60 * 1000; // 1 hour (matches API Cache-Control)
|
|
14
|
+
const store = new Map();
|
|
15
|
+
/**
|
|
16
|
+
* Get a value from cache if it exists and hasn't expired.
|
|
17
|
+
*/
|
|
18
|
+
function cacheGet(key) {
|
|
19
|
+
const entry = store.get(key);
|
|
20
|
+
if (!entry)
|
|
21
|
+
return undefined;
|
|
22
|
+
if (Date.now() > entry.expiresAt) {
|
|
23
|
+
store.delete(key);
|
|
24
|
+
return undefined;
|
|
25
|
+
}
|
|
26
|
+
return entry.data;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Store a value in cache with a TTL.
|
|
30
|
+
*/
|
|
31
|
+
function cacheSet(key, data, ttlMs = DEFAULT_TTL_MS) {
|
|
32
|
+
store.set(key, { data, expiresAt: Date.now() + ttlMs });
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Clear all cached entries. Useful for testing.
|
|
36
|
+
*/
|
|
37
|
+
function cacheClear() {
|
|
38
|
+
store.clear();
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=cache.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cache.js","sourceRoot":"","sources":["../../src/common/cache.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;AAcH,4BAQC;AAKD,4BAEC;AAKD,gCAEC;AA7BD,MAAM,cAAc,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC,qCAAqC;AAE5E,MAAM,KAAK,GAAG,IAAI,GAAG,EAA+B,CAAC;AAErD;;GAEG;AACH,SAAgB,QAAQ,CAAI,GAAW;IACrC,MAAM,KAAK,GAAG,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IAC7B,IAAI,CAAC,KAAK;QAAE,OAAO,SAAS,CAAC;IAC7B,IAAI,IAAI,CAAC,GAAG,EAAE,GAAG,KAAK,CAAC,SAAS,EAAE,CAAC;QACjC,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QAClB,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,OAAO,KAAK,CAAC,IAAS,CAAC;AACzB,CAAC;AAED;;GAEG;AACH,SAAgB,QAAQ,CAAI,GAAW,EAAE,IAAO,EAAE,QAAgB,cAAc;IAC9E,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,KAAK,EAAE,CAAC,CAAC;AAC1D,CAAC;AAED;;GAEG;AACH,SAAgB,UAAU;IACxB,KAAK,CAAC,KAAK,EAAE,CAAC;AAChB,CAAC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const PRODUCTION_BASE_URL: "https://
|
|
1
|
+
export declare const PRODUCTION_BASE_URL: "https://api.texturehq.com";
|
|
2
2
|
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/common/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,mBAAmB,EAAG,
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/common/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,mBAAmB,EAAG,2BAAoC,CAAC"}
|
package/dist/common/constants.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.PRODUCTION_BASE_URL = void 0;
|
|
4
|
-
exports.PRODUCTION_BASE_URL = "https://
|
|
4
|
+
exports.PRODUCTION_BASE_URL = "https://api.texturehq.com";
|
|
5
5
|
//# sourceMappingURL=constants.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/common/constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,mBAAmB,GAAG,
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/common/constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,mBAAmB,GAAG,2BAAoC,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export interface FetchWithRetryOptions {
|
|
2
|
+
retries?: number;
|
|
3
|
+
baseDelayMs?: number;
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* Fetch with exponential backoff retry logic.
|
|
7
|
+
* Retries on 5xx status codes and network errors.
|
|
8
|
+
*/
|
|
9
|
+
export declare function fetchWithRetry(url: string, options?: FetchWithRetryOptions): Promise<Response>;
|
|
10
|
+
//# sourceMappingURL=fetch.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fetch.d.ts","sourceRoot":"","sources":["../../src/common/fetch.ts"],"names":[],"mappings":"AAIA,MAAM,WAAW,qBAAqB;IACpC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED;;;GAGG;AACH,wBAAsB,cAAc,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,GAAE,qBAA0B,GAAG,OAAO,CAAC,QAAQ,CAAC,CA4BxG"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.fetchWithRetry = fetchWithRetry;
|
|
4
|
+
const logger_1 = require("./logger");
|
|
5
|
+
const logger = logger_1.baseLogger.function("fetchWithRetry");
|
|
6
|
+
/**
|
|
7
|
+
* Fetch with exponential backoff retry logic.
|
|
8
|
+
* Retries on 5xx status codes and network errors.
|
|
9
|
+
*/
|
|
10
|
+
async function fetchWithRetry(url, options = {}) {
|
|
11
|
+
const { retries = 3, baseDelayMs = 300 } = options;
|
|
12
|
+
let lastError;
|
|
13
|
+
for (let attempt = 0; attempt <= retries; attempt++) {
|
|
14
|
+
try {
|
|
15
|
+
const response = await fetch(url);
|
|
16
|
+
// Don't retry on client errors (4xx), only on server errors (5xx)
|
|
17
|
+
if (response.status >= 500 && attempt < retries) {
|
|
18
|
+
logger.warn("retryCount", { retryCount: attempt + 1, status: response.status });
|
|
19
|
+
await sleep(baseDelayMs * Math.pow(2, attempt));
|
|
20
|
+
continue;
|
|
21
|
+
}
|
|
22
|
+
return response;
|
|
23
|
+
}
|
|
24
|
+
catch (error) {
|
|
25
|
+
lastError = error;
|
|
26
|
+
if (attempt < retries) {
|
|
27
|
+
logger.warn("retryCount", { retryCount: attempt + 1 });
|
|
28
|
+
logger.warn("error", { error: error instanceof Error ? error.message : String(error) });
|
|
29
|
+
await sleep(baseDelayMs * Math.pow(2, attempt));
|
|
30
|
+
continue;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
throw lastError;
|
|
35
|
+
}
|
|
36
|
+
function sleep(ms) {
|
|
37
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=fetch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fetch.js","sourceRoot":"","sources":["../../src/common/fetch.ts"],"names":[],"mappings":";;AAaA,wCA4BC;AAzCD,qCAAsC;AAEtC,MAAM,MAAM,GAAG,mBAAU,CAAC,QAAQ,CAAC,gBAAgB,CAAC,CAAC;AAOrD;;;GAGG;AACI,KAAK,UAAU,cAAc,CAAC,GAAW,EAAE,UAAiC,EAAE;IACnF,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C,EAAU;IACvB,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAC;AAC3D,CAAC"}
|
|
@@ -2,19 +2,14 @@ import { Logger } from "../../common/logger";
|
|
|
2
2
|
import { DeviceModel } from "../entities";
|
|
3
3
|
export interface GetDeviceModelOptions {
|
|
4
4
|
/**
|
|
5
|
-
* The slug of the device model to retrieve
|
|
5
|
+
* The slug of the device model to retrieve.
|
|
6
6
|
*/
|
|
7
7
|
slug: string;
|
|
8
8
|
/**
|
|
9
|
-
* The base URL of the
|
|
10
|
-
* @default "https://
|
|
9
|
+
* The base URL of the Texture REST API.
|
|
10
|
+
* @default "https://api.texturehq.com"
|
|
11
11
|
*/
|
|
12
12
|
baseApiUrl?: string;
|
|
13
|
-
/**
|
|
14
|
-
* The base URL for images coming from Payload CMS.
|
|
15
|
-
* @default "https://device.cms.texture.energy"
|
|
16
|
-
*/
|
|
17
|
-
baseImageUrl?: string;
|
|
18
13
|
/**
|
|
19
14
|
* The logger instance to use during the getDeviceModel operation.
|
|
20
15
|
*/
|
|
@@ -24,9 +19,9 @@ type CachedDeviceModel = (DeviceModel & {
|
|
|
24
19
|
cached?: boolean;
|
|
25
20
|
}) | null;
|
|
26
21
|
/**
|
|
27
|
-
* Retrieves a device model from the
|
|
22
|
+
* Retrieves a device model from the Texture REST API.
|
|
28
23
|
* @param options The options to use during the getDeviceModel operation.
|
|
29
|
-
* @returns {Promise<DeviceModel | null>} The device model retrieved from the
|
|
24
|
+
* @returns {Promise<DeviceModel | null>} The device model retrieved from the API or null if not found.
|
|
30
25
|
*/
|
|
31
26
|
export declare const getDeviceModel: (options: GetDeviceModelOptions) => Promise<CachedDeviceModel>;
|
|
32
27
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/deviceModel/getDeviceModel/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAGzD,OAAO,EAAE,WAAW,EAAqB,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/deviceModel/getDeviceModel/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAGzD,OAAO,EAAE,WAAW,EAAqB,MAAM,aAAa,CAAC;AAO7D,MAAM,WAAW,qBAAqB;IACpC;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IACb;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,KAAK,iBAAiB,GAAG,CAAC,WAAW,GAAG;IAAE,MAAM,CAAC,EAAE,OAAO,CAAA;CAAE,CAAC,GAAG,IAAI,CAAC;AAErE;;;;GAIG;AACH,eAAO,MAAM,cAAc,GAAU,SAAS,qBAAqB,KAAG,OAAO,CAAC,iBAAiB,CAsD9F,CAAC"}
|
|
@@ -5,44 +5,61 @@ const logger_1 = require("../../common/logger");
|
|
|
5
5
|
const exceptions_1 = require("../../common/exceptions");
|
|
6
6
|
const entities_1 = require("../entities");
|
|
7
7
|
const constants_1 = require("../../common/constants");
|
|
8
|
-
const
|
|
9
|
-
const
|
|
8
|
+
const fetch_1 = require("../../common/fetch");
|
|
9
|
+
const cache_1 = require("../../common/cache");
|
|
10
|
+
const parseManufacturer_1 = require("../../manufacturer/parseManufacturer");
|
|
10
11
|
/**
|
|
11
|
-
* Retrieves a device model from the
|
|
12
|
+
* Retrieves a device model from the Texture REST API.
|
|
12
13
|
* @param options The options to use during the getDeviceModel operation.
|
|
13
|
-
* @returns {Promise<DeviceModel | null>} The device model retrieved from the
|
|
14
|
+
* @returns {Promise<DeviceModel | null>} The device model retrieved from the API or null if not found.
|
|
14
15
|
*/
|
|
15
16
|
const getDeviceModel = async (options) => {
|
|
16
17
|
const defaultLogger = logger_1.baseLogger.function("getDeviceModel");
|
|
17
|
-
const { slug, baseApiUrl = constants_1.PRODUCTION_BASE_URL,
|
|
18
|
-
const operation = logger.operation("get device model from
|
|
19
|
-
const axios = (0, axios_1.getAxios)();
|
|
18
|
+
const { slug, baseApiUrl = constants_1.PRODUCTION_BASE_URL, logger = defaultLogger } = options;
|
|
19
|
+
const operation = logger.operation("get device model from Texture REST API");
|
|
20
20
|
try {
|
|
21
21
|
operation.start({ options });
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
22
|
+
const modelsUrl = `${baseApiUrl}/v1/public/device-models?slug=${encodeURIComponent(slug)}`;
|
|
23
|
+
let modelsData = (0, cache_1.cacheGet)(modelsUrl);
|
|
24
|
+
if (!modelsData) {
|
|
25
|
+
const modelsResponse = await (0, fetch_1.fetchWithRetry)(modelsUrl);
|
|
26
|
+
if (!modelsResponse.ok) {
|
|
27
|
+
const errorMessage = `Request to ${modelsUrl} failed with status ${modelsResponse.status}`;
|
|
28
|
+
operation.fail(errorMessage);
|
|
29
|
+
throw new exceptions_1.NetworkError(errorMessage, modelsResponse.status);
|
|
30
|
+
}
|
|
31
|
+
modelsData = (await modelsResponse.json());
|
|
32
|
+
(0, cache_1.cacheSet)(modelsUrl, modelsData);
|
|
27
33
|
}
|
|
28
|
-
if (
|
|
29
|
-
operation.fail({
|
|
34
|
+
if (!modelsData.data || modelsData.data.length === 0) {
|
|
35
|
+
operation.fail({ slug });
|
|
30
36
|
return null;
|
|
31
37
|
}
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
|
|
38
|
+
const doc = modelsData.data[0];
|
|
39
|
+
const manufacturersUrl = `${baseApiUrl}/v1/public/manufacturers`;
|
|
40
|
+
let manufacturersData = (0, cache_1.cacheGet)(manufacturersUrl);
|
|
41
|
+
if (!manufacturersData) {
|
|
42
|
+
const manufacturersResponse = await (0, fetch_1.fetchWithRetry)(manufacturersUrl);
|
|
43
|
+
if (!manufacturersResponse.ok) {
|
|
44
|
+
const errorMessage = `Request to ${manufacturersUrl} failed with status ${manufacturersResponse.status}`;
|
|
45
|
+
operation.fail(errorMessage);
|
|
46
|
+
throw new exceptions_1.NetworkError(errorMessage, manufacturersResponse.status);
|
|
47
|
+
}
|
|
48
|
+
manufacturersData = (await manufacturersResponse.json());
|
|
49
|
+
(0, cache_1.cacheSet)(manufacturersUrl, manufacturersData);
|
|
50
|
+
}
|
|
51
|
+
const fullManufacturer = manufacturersData.find((m) => m.slug === doc.manufacturer.slug);
|
|
52
|
+
if (!fullManufacturer)
|
|
53
|
+
throw new Error(`Manufacturer not found for slug: ${doc.manufacturer.slug}`);
|
|
35
54
|
const deviceModel = entities_1.DeviceModelSchema.parse({
|
|
36
|
-
...
|
|
37
|
-
manufacturer: (0,
|
|
55
|
+
...doc,
|
|
56
|
+
manufacturer: (0, parseManufacturer_1.parseManufacturer)(fullManufacturer),
|
|
38
57
|
});
|
|
39
|
-
// @ts-expect-error Property 'cached' does not exist
|
|
40
|
-
deviceModel.cached = response?.cached;
|
|
41
58
|
operation.end({ deviceModel });
|
|
42
59
|
return deviceModel;
|
|
43
60
|
}
|
|
44
61
|
catch (error) {
|
|
45
|
-
operation.fail("Unknown error occurred while fetching device model from
|
|
62
|
+
operation.fail("Unknown error occurred while fetching device model from Texture REST API.");
|
|
46
63
|
throw error;
|
|
47
64
|
}
|
|
48
65
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/deviceModel/getDeviceModel/index.ts"],"names":[],"mappings":";;;AAAA,gDAAyD;AAEzD,wDAAuD;AACvD,0CAA6D;AAC7D,sDAA6D;AAC7D,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/deviceModel/getDeviceModel/index.ts"],"names":[],"mappings":";;;AAAA,gDAAyD;AAEzD,wDAAuD;AACvD,0CAA6D;AAC7D,sDAA6D;AAC7D,8CAA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CAAC;IACrB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,SAAS,CAAC,IAAI,CAAC,2EAA2E,CAAC,CAAC;QAC5F,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC,CAAC;AAtDW,QAAA,cAAc,kBAsDzB"}
|
|
@@ -1,95 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
page: number;
|
|
7
|
-
pagingCounter: number;
|
|
8
|
-
hasPrevPage: boolean;
|
|
9
|
-
hasNextPage: boolean;
|
|
10
|
-
prevPage: null;
|
|
11
|
-
nextPage: null;
|
|
12
|
-
}
|
|
13
|
-
export interface Doc {
|
|
14
|
-
id: string;
|
|
15
|
-
slug: string;
|
|
16
|
-
name: string;
|
|
17
|
-
manufacturer: Manufacturer;
|
|
18
|
-
type: string;
|
|
19
|
-
support_level: string;
|
|
20
|
-
available_commands: AvailableCommand[];
|
|
21
|
-
createdAt: Date;
|
|
22
|
-
updatedAt: Date;
|
|
23
|
-
}
|
|
24
|
-
export interface AvailableCommand {
|
|
25
|
-
id: string;
|
|
26
|
-
slug: string;
|
|
27
|
-
support_level: string;
|
|
28
|
-
createdAt: Date;
|
|
29
|
-
updatedAt: Date;
|
|
30
|
-
}
|
|
31
|
-
export interface Manufacturer {
|
|
32
|
-
id: string;
|
|
33
|
-
slug: string;
|
|
34
|
-
name: string;
|
|
35
|
-
logo: Logo;
|
|
36
|
-
support_level: string;
|
|
37
|
-
createdAt: Date;
|
|
38
|
-
updatedAt: Date;
|
|
39
|
-
icon: Icon;
|
|
40
|
-
vector_icon: Logo;
|
|
41
|
-
}
|
|
42
|
-
export interface Icon {
|
|
43
|
-
id: string;
|
|
44
|
-
alt: string;
|
|
45
|
-
filename: string;
|
|
46
|
-
mimeType: string;
|
|
47
|
-
filesize: number;
|
|
48
|
-
width: number;
|
|
49
|
-
height: number;
|
|
50
|
-
focalX: number;
|
|
51
|
-
focalY: number;
|
|
52
|
-
sizes: IconSizes;
|
|
53
|
-
createdAt: Date;
|
|
54
|
-
updatedAt: Date;
|
|
55
|
-
url: string;
|
|
56
|
-
}
|
|
57
|
-
export interface IconSizes {
|
|
58
|
-
thumbnail: PurpleCard;
|
|
59
|
-
card: PurpleCard;
|
|
60
|
-
tablet: PurpleCard;
|
|
61
|
-
}
|
|
62
|
-
export interface PurpleCard {
|
|
63
|
-
width: number;
|
|
64
|
-
height: number;
|
|
65
|
-
mimeType: string;
|
|
66
|
-
filesize: number;
|
|
67
|
-
filename: string;
|
|
68
|
-
url: string;
|
|
69
|
-
}
|
|
70
|
-
export interface Logo {
|
|
71
|
-
id: string;
|
|
72
|
-
alt: string;
|
|
73
|
-
filename: string;
|
|
74
|
-
mimeType: string;
|
|
75
|
-
filesize: number;
|
|
76
|
-
width: number;
|
|
77
|
-
height: number;
|
|
78
|
-
sizes: LogoSizes;
|
|
79
|
-
createdAt: Date;
|
|
80
|
-
updatedAt: Date;
|
|
81
|
-
url: string;
|
|
82
|
-
}
|
|
83
|
-
export interface LogoSizes {
|
|
84
|
-
thumbnail: FluffyCard;
|
|
85
|
-
card: FluffyCard;
|
|
86
|
-
tablet: FluffyCard;
|
|
87
|
-
}
|
|
88
|
-
export interface FluffyCard {
|
|
89
|
-
url: null;
|
|
90
|
-
}
|
|
91
|
-
export declare class Convert {
|
|
92
|
-
static toResponseInterfaces(json: string): ResponseInterfaces;
|
|
93
|
-
static responseInterfacesToJson(value: ResponseInterfaces): string;
|
|
94
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* REST API response shape for GET /v1/public/device-models.
|
|
3
|
+
* Re-exported from the shared type for consistency.
|
|
4
|
+
*/
|
|
5
|
+
export { DeviceModelsApiResponse, DeviceModelApiItem, DeviceModelApiCommand } from "../getDeviceModels/response.interfaces";
|
|
95
6
|
//# sourceMappingURL=response.interfaces.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"response.interfaces.d.ts","sourceRoot":"","sources":["../../../src/deviceModel/getDeviceModel/response.interfaces.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"response.interfaces.d.ts","sourceRoot":"","sources":["../../../src/deviceModel/getDeviceModel/response.interfaces.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,uBAAuB,EAAE,kBAAkB,EAAE,qBAAqB,EAAE,MAAM,wCAAwC,CAAC"}
|