@texturehq/device 1.18.0 → 2.0.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/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 +29 -21
- 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 +30 -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 +40 -27
- 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/manufacturer/getManufacturer/index.d.ts +7 -16
- package/dist/manufacturer/getManufacturer/index.d.ts.map +1 -1
- package/dist/manufacturer/getManufacturer/index.js +17 -19
- 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 +29 -18
- 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
|
@@ -5,55 +5,56 @@ 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 parseManufacturer_1 = require("../../manufacturer/parseManufacturer");
|
|
10
10
|
/**
|
|
11
|
-
* Retrieves a device model from the
|
|
12
|
-
* @param options The options to use during the
|
|
13
|
-
* @returns {Promise<DeviceModel | null>} The device model retrieved from the
|
|
11
|
+
* Retrieves a device model from the Texture REST API by manufacturer:model slug.
|
|
12
|
+
* @param options The options to use during the getDeviceModelByManufacturerSlug operation.
|
|
13
|
+
* @returns {Promise<DeviceModel | null>} The device model retrieved from the API or null if not found.
|
|
14
14
|
*/
|
|
15
15
|
const getDeviceModelByManufacturerSlug = async (options) => {
|
|
16
16
|
const defaultLogger = logger_1.baseLogger.function("getDeviceModelByManufacturerSlug");
|
|
17
17
|
const { slug, baseApiUrl = constants_1.PRODUCTION_BASE_URL, logger = defaultLogger } = options;
|
|
18
|
-
const operation = logger.operation("get device model by manufacturer slug from
|
|
19
|
-
const axios = (0, axios_1.getAxios)();
|
|
18
|
+
const operation = logger.operation("get device model by manufacturer slug from Texture REST API");
|
|
20
19
|
try {
|
|
21
20
|
operation.start({ options });
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
21
|
+
const modelsUrl = `${baseApiUrl}/v1/public/device-models?slug=${encodeURIComponent(slug)}`;
|
|
22
|
+
const modelsResponse = await (0, fetch_1.fetchWithRetry)(modelsUrl);
|
|
23
|
+
if (!modelsResponse.ok) {
|
|
24
|
+
const errorMessage = `Request to ${modelsUrl} failed with status ${modelsResponse.status}`;
|
|
25
|
+
operation.fail({ slug, status: modelsResponse.status, errorMessage });
|
|
26
|
+
throw new exceptions_1.NetworkError(errorMessage, modelsResponse.status);
|
|
27
27
|
}
|
|
28
|
-
|
|
29
|
-
|
|
28
|
+
const modelsData = (await modelsResponse.json());
|
|
29
|
+
if (!modelsData.data || modelsData.data.length === 0) {
|
|
30
|
+
operation.fail({ slug });
|
|
30
31
|
return null;
|
|
31
32
|
}
|
|
32
|
-
|
|
33
|
-
|
|
33
|
+
const doc = modelsData.data[0];
|
|
34
|
+
const manufacturersUrl = `${baseApiUrl}/v1/public/manufacturers`;
|
|
35
|
+
const manufacturersResponse = await (0, fetch_1.fetchWithRetry)(manufacturersUrl);
|
|
36
|
+
if (!manufacturersResponse.ok) {
|
|
37
|
+
const errorMessage = `Request to ${manufacturersUrl} failed with status ${manufacturersResponse.status}`;
|
|
38
|
+
operation.fail({ slug, status: manufacturersResponse.status, errorMessage });
|
|
39
|
+
throw new exceptions_1.NetworkError(errorMessage, manufacturersResponse.status);
|
|
34
40
|
}
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
...options,
|
|
40
|
-
slug: result.manufacturer?.slug,
|
|
41
|
-
});
|
|
41
|
+
const manufacturersData = (await manufacturersResponse.json());
|
|
42
|
+
const fullManufacturer = manufacturersData.find((m) => m.slug === doc.manufacturer.slug);
|
|
43
|
+
if (!fullManufacturer)
|
|
44
|
+
throw new Error(`Manufacturer not found for slug: ${doc.manufacturer.slug}`);
|
|
42
45
|
const deviceModel = entities_1.DeviceModelSchema.parse({
|
|
43
|
-
...
|
|
44
|
-
manufacturer,
|
|
46
|
+
...doc,
|
|
47
|
+
manufacturer: (0, parseManufacturer_1.parseManufacturer)(fullManufacturer),
|
|
45
48
|
});
|
|
46
|
-
// @ts-expect-error Property 'cached' does not exist
|
|
47
|
-
deviceModel.cached = response?.cached;
|
|
48
49
|
operation.end({ deviceModel });
|
|
49
50
|
return deviceModel;
|
|
50
51
|
}
|
|
51
52
|
catch (error) {
|
|
52
53
|
operation.fail({
|
|
53
54
|
error,
|
|
54
|
-
slug
|
|
55
|
+
slug,
|
|
55
56
|
baseApiUrl,
|
|
56
|
-
message: "Unknown error occurred while fetching device model from
|
|
57
|
+
message: "Unknown error occurred while fetching device model from Texture REST API.",
|
|
57
58
|
});
|
|
58
59
|
throw error;
|
|
59
60
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/deviceModel/getDeviceModelByManufacturerSlug/index.ts"],"names":[],"mappings":";;;AAAA,gDAAyD;AAEzD,wDAAuD;AACvD,0CAA6D;AAC7D,sDAA6D;AAC7D,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/deviceModel/getDeviceModelByManufacturerSlug/index.ts"],"names":[],"mappings":";;;AAAA,gDAAyD;AAEzD,wDAAuD;AACvD,0CAA6D;AAC7D,sDAA6D;AAC7D,8CAAoD;AAEpD,4EAAyE;AAsBzE;;;;GAIG;AACI,MAAM,gCAAgC,GAAG,KAAK,EACnD,OAAgD,EACpB,EAAE;IAC9B,MAAM,aAAa,GAAG,mBAAU,CAAC,QAAQ,CAAC,kCAAkC,CAAC,CAAC;IAC9E,MAAM,EAAE,IAAI,EAAE,UAAU,GAAG,+BAAmB,EAAE,MAAM,GAAG,aAAa,EAAE,GAAG,OAAO,CAAC;IACnF,MAAM,SAAS,GAAG,MAAM,CAAC,SAAS,CAAC,6DAA6D,CAAC,CAAC;IAElG,IAAI,CAAC;QACH,SAAS,CAAC,KAAK,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC;QAE7B,MAAM,SAAS,GAAG,GAAG,UAAU,iCAAiC,kBAAkB,CAAC,IAAI,CAAC,EAAE,CAAC;QAC3F,MAAM,cAAc,GAAG,MAAM,IAAA,sBAAc,EAAC,SAAS,CAAC,CAAC;QACvD,IAAI,CAAC,cAAc,CAAC,EAAE,EAAE,CAAC;YACvB,MAAM,YAAY,GAAG,cAAc,SAAS,uBAAuB,cAAc,CAAC,MAAM,EAAE,CAAC;YAC3F,SAAS,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,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CAAC,IAAI,EAAE,CAAC,CAAC;QAEpG,MAAM,WAAW,GAAsB,4BAAiB,CAAC,KAAK,CAAC;YAC7D,GAAG,GAAG;YACN,YAAY,EAAE,IAAA,qCAAiB,EAAC,gBAAgB,CAAC;SAClD,CAAC,CAAC;QAEH,SAAS,CAAC,GAAG,CAAC,EAAE,WAAW,EAAE,CAAC,CAAC;QAC/B,OAAO,WAAW,CAAC;IACrB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,SAAS,CAAC,IAAI,CAAC;YACb,KAAK;YACL,IAAI;YACJ,UAAU;YACV,OAAO,EAAE,2EAA2E;SACrF,CAAC,CAAC;QACH,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC,CAAC;AArDW,QAAA,gCAAgC,oCAqD3C"}
|
|
@@ -1,53 +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
|
-
device_model: DeviceModel;
|
|
17
|
-
createdAt: Date;
|
|
18
|
-
updatedAt: Date;
|
|
19
|
-
}
|
|
20
|
-
export interface DeviceModel {
|
|
21
|
-
id: string;
|
|
22
|
-
slug: string;
|
|
23
|
-
name: string;
|
|
24
|
-
manufacturer: Manufacturer;
|
|
25
|
-
type: string;
|
|
26
|
-
support_level: string;
|
|
27
|
-
available_commands: AvailableCommand[];
|
|
28
|
-
createdAt: Date;
|
|
29
|
-
updatedAt: Date;
|
|
30
|
-
}
|
|
31
|
-
export interface AvailableCommand {
|
|
32
|
-
id: string;
|
|
33
|
-
slug: string;
|
|
34
|
-
support_level: string;
|
|
35
|
-
createdAt: Date;
|
|
36
|
-
updatedAt: Date;
|
|
37
|
-
}
|
|
38
|
-
export interface Manufacturer {
|
|
39
|
-
id: string;
|
|
40
|
-
slug: string;
|
|
41
|
-
name: string;
|
|
42
|
-
logo: string;
|
|
43
|
-
support_level: string;
|
|
44
|
-
createdAt: Date;
|
|
45
|
-
updatedAt: Date;
|
|
46
|
-
icon: string;
|
|
47
|
-
vector_icon: string;
|
|
48
|
-
}
|
|
49
|
-
export declare class Convert {
|
|
50
|
-
static toResponseInterfaces(json: string): ResponseInterfaces;
|
|
51
|
-
static responseInterfacesToJson(value: ResponseInterfaces): string;
|
|
52
|
-
}
|
|
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";
|
|
53
6
|
//# sourceMappingURL=response.interfaces.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"response.interfaces.d.ts","sourceRoot":"","sources":["../../../src/deviceModel/getDeviceModelByManufacturerSlug/response.interfaces.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"response.interfaces.d.ts","sourceRoot":"","sources":["../../../src/deviceModel/getDeviceModelByManufacturerSlug/response.interfaces.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,uBAAuB,EAAE,kBAAkB,EAAE,qBAAqB,EAAE,MAAM,wCAAwC,CAAC"}
|
|
@@ -1,210 +1,3 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
// To parse this data:
|
|
3
|
-
//
|
|
4
|
-
// import { Convert, ResponseInterfaces } from "./file";
|
|
5
|
-
//
|
|
6
|
-
// const responseInterfaces = Convert.toResponseInterfaces(json);
|
|
7
|
-
//
|
|
8
|
-
// These functions will throw an error if the JSON doesn't
|
|
9
|
-
// match the expected interface, even if the JSON is valid.
|
|
10
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
-
exports.Convert = void 0;
|
|
12
|
-
// Converts JSON strings to/from your types
|
|
13
|
-
// and asserts the results of JSON.parse at runtime
|
|
14
|
-
class Convert {
|
|
15
|
-
static toResponseInterfaces(json) {
|
|
16
|
-
return cast(JSON.parse(json), r("ResponseInterfaces"));
|
|
17
|
-
}
|
|
18
|
-
static responseInterfacesToJson(value) {
|
|
19
|
-
return JSON.stringify(uncast(value, r("ResponseInterfaces")), null, 2);
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
exports.Convert = Convert;
|
|
23
|
-
function invalidValue(typ, val, key, parent = '') {
|
|
24
|
-
const prettyTyp = prettyTypeName(typ);
|
|
25
|
-
const parentText = parent ? ` on ${parent}` : '';
|
|
26
|
-
const keyText = key ? ` for key "${key}"` : '';
|
|
27
|
-
throw Error(`Invalid value${keyText}${parentText}. Expected ${prettyTyp} but got ${JSON.stringify(val)}`);
|
|
28
|
-
}
|
|
29
|
-
function prettyTypeName(typ) {
|
|
30
|
-
if (Array.isArray(typ)) {
|
|
31
|
-
if (typ.length === 2 && typ[0] === undefined) {
|
|
32
|
-
return `an optional ${prettyTypeName(typ[1])}`;
|
|
33
|
-
}
|
|
34
|
-
else {
|
|
35
|
-
return `one of [${typ.map(a => { return prettyTypeName(a); }).join(", ")}]`;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
else if (typeof typ === "object" && typ.literal !== undefined) {
|
|
39
|
-
return typ.literal;
|
|
40
|
-
}
|
|
41
|
-
else {
|
|
42
|
-
return typeof typ;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
function jsonToJSProps(typ) {
|
|
46
|
-
if (typ.jsonToJS === undefined) {
|
|
47
|
-
const map = {};
|
|
48
|
-
typ.props.forEach((p) => map[p.json] = { key: p.js, typ: p.typ });
|
|
49
|
-
typ.jsonToJS = map;
|
|
50
|
-
}
|
|
51
|
-
return typ.jsonToJS;
|
|
52
|
-
}
|
|
53
|
-
function jsToJSONProps(typ) {
|
|
54
|
-
if (typ.jsToJSON === undefined) {
|
|
55
|
-
const map = {};
|
|
56
|
-
typ.props.forEach((p) => map[p.js] = { key: p.json, typ: p.typ });
|
|
57
|
-
typ.jsToJSON = map;
|
|
58
|
-
}
|
|
59
|
-
return typ.jsToJSON;
|
|
60
|
-
}
|
|
61
|
-
function transform(val, typ, getProps, key = '', parent = '') {
|
|
62
|
-
function transformPrimitive(typ, val) {
|
|
63
|
-
if (typeof typ === typeof val)
|
|
64
|
-
return val;
|
|
65
|
-
return invalidValue(typ, val, key, parent);
|
|
66
|
-
}
|
|
67
|
-
function transformUnion(typs, val) {
|
|
68
|
-
// val must validate against one typ in typs
|
|
69
|
-
const l = typs.length;
|
|
70
|
-
for (let i = 0; i < l; i++) {
|
|
71
|
-
const typ = typs[i];
|
|
72
|
-
try {
|
|
73
|
-
return transform(val, typ, getProps);
|
|
74
|
-
}
|
|
75
|
-
catch (_) { }
|
|
76
|
-
}
|
|
77
|
-
return invalidValue(typs, val, key, parent);
|
|
78
|
-
}
|
|
79
|
-
function transformEnum(cases, val) {
|
|
80
|
-
if (cases.indexOf(val) !== -1)
|
|
81
|
-
return val;
|
|
82
|
-
return invalidValue(cases.map(a => { return l(a); }), val, key, parent);
|
|
83
|
-
}
|
|
84
|
-
function transformArray(typ, val) {
|
|
85
|
-
// val must be an array with no invalid elements
|
|
86
|
-
if (!Array.isArray(val))
|
|
87
|
-
return invalidValue(l("array"), val, key, parent);
|
|
88
|
-
return val.map(el => transform(el, typ, getProps));
|
|
89
|
-
}
|
|
90
|
-
function transformDate(val) {
|
|
91
|
-
if (val === null) {
|
|
92
|
-
return null;
|
|
93
|
-
}
|
|
94
|
-
const d = new Date(val);
|
|
95
|
-
if (isNaN(d.valueOf())) {
|
|
96
|
-
return invalidValue(l("Date"), val, key, parent);
|
|
97
|
-
}
|
|
98
|
-
return d;
|
|
99
|
-
}
|
|
100
|
-
function transformObject(props, additional, val) {
|
|
101
|
-
if (val === null || typeof val !== "object" || Array.isArray(val)) {
|
|
102
|
-
return invalidValue(l(ref || "object"), val, key, parent);
|
|
103
|
-
}
|
|
104
|
-
const result = {};
|
|
105
|
-
Object.getOwnPropertyNames(props).forEach(key => {
|
|
106
|
-
const prop = props[key];
|
|
107
|
-
const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined;
|
|
108
|
-
result[prop.key] = transform(v, prop.typ, getProps, key, ref);
|
|
109
|
-
});
|
|
110
|
-
Object.getOwnPropertyNames(val).forEach(key => {
|
|
111
|
-
if (!Object.prototype.hasOwnProperty.call(props, key)) {
|
|
112
|
-
result[key] = transform(val[key], additional, getProps, key, ref);
|
|
113
|
-
}
|
|
114
|
-
});
|
|
115
|
-
return result;
|
|
116
|
-
}
|
|
117
|
-
if (typ === "any")
|
|
118
|
-
return val;
|
|
119
|
-
if (typ === null) {
|
|
120
|
-
if (val === null)
|
|
121
|
-
return val;
|
|
122
|
-
return invalidValue(typ, val, key, parent);
|
|
123
|
-
}
|
|
124
|
-
if (typ === false)
|
|
125
|
-
return invalidValue(typ, val, key, parent);
|
|
126
|
-
let ref = undefined;
|
|
127
|
-
while (typeof typ === "object" && typ.ref !== undefined) {
|
|
128
|
-
ref = typ.ref;
|
|
129
|
-
typ = typeMap[typ.ref];
|
|
130
|
-
}
|
|
131
|
-
if (Array.isArray(typ))
|
|
132
|
-
return transformEnum(typ, val);
|
|
133
|
-
if (typeof typ === "object") {
|
|
134
|
-
return typ.hasOwnProperty("unionMembers") ? transformUnion(typ.unionMembers, val)
|
|
135
|
-
: typ.hasOwnProperty("arrayItems") ? transformArray(typ.arrayItems, val)
|
|
136
|
-
: typ.hasOwnProperty("props") ? transformObject(getProps(typ), typ.additional, val)
|
|
137
|
-
: invalidValue(typ, val, key, parent);
|
|
138
|
-
}
|
|
139
|
-
// Numbers can be parsed by Date but shouldn't be.
|
|
140
|
-
if (typ === Date && typeof val !== "number")
|
|
141
|
-
return transformDate(val);
|
|
142
|
-
return transformPrimitive(typ, val);
|
|
143
|
-
}
|
|
144
|
-
function cast(val, typ) {
|
|
145
|
-
return transform(val, typ, jsonToJSProps);
|
|
146
|
-
}
|
|
147
|
-
function uncast(val, typ) {
|
|
148
|
-
return transform(val, typ, jsToJSONProps);
|
|
149
|
-
}
|
|
150
|
-
function l(typ) {
|
|
151
|
-
return { literal: typ };
|
|
152
|
-
}
|
|
153
|
-
function a(typ) {
|
|
154
|
-
return { arrayItems: typ };
|
|
155
|
-
}
|
|
156
|
-
function u(...typs) {
|
|
157
|
-
return { unionMembers: typs };
|
|
158
|
-
}
|
|
159
|
-
function o(props, additional) {
|
|
160
|
-
return { props, additional };
|
|
161
|
-
}
|
|
162
|
-
function m(additional) {
|
|
163
|
-
return { props: [], additional };
|
|
164
|
-
}
|
|
165
|
-
function r(name) {
|
|
166
|
-
return { ref: name };
|
|
167
|
-
}
|
|
168
|
-
const typeMap = {
|
|
169
|
-
"ResponseInterfaces": o([
|
|
170
|
-
{ json: "docs", js: "docs", typ: a(r("Doc")) },
|
|
171
|
-
{ json: "totalDocs", js: "totalDocs", typ: 0 },
|
|
172
|
-
{ json: "limit", js: "limit", typ: 0 },
|
|
173
|
-
{ json: "totalPages", js: "totalPages", typ: 0 },
|
|
174
|
-
{ json: "page", js: "page", typ: 0 },
|
|
175
|
-
{ json: "pagingCounter", js: "pagingCounter", typ: 0 },
|
|
176
|
-
{ json: "hasPrevPage", js: "hasPrevPage", typ: true },
|
|
177
|
-
{ json: "hasNextPage", js: "hasNextPage", typ: true },
|
|
178
|
-
{ json: "prevPage", js: "prevPage", typ: null },
|
|
179
|
-
{ json: "nextPage", js: "nextPage", typ: null },
|
|
180
|
-
], false),
|
|
181
|
-
"Doc": o([
|
|
182
|
-
{ json: "id", js: "id", typ: "" },
|
|
183
|
-
{ json: "slug", js: "slug", typ: "" },
|
|
184
|
-
{ json: "device_model", js: "device_model", typ: r("DeviceModel") },
|
|
185
|
-
{ json: "createdAt", js: "createdAt", typ: Date },
|
|
186
|
-
{ json: "updatedAt", js: "updatedAt", typ: Date },
|
|
187
|
-
], false),
|
|
188
|
-
"DeviceModel": o([
|
|
189
|
-
{ json: "id", js: "id", typ: "" },
|
|
190
|
-
{ json: "slug", js: "slug", typ: "" },
|
|
191
|
-
{ json: "name", js: "name", typ: "" },
|
|
192
|
-
{ json: "manufacturer", js: "manufacturer", typ: r("Manufacturer") },
|
|
193
|
-
{ json: "type", js: "type", typ: "" },
|
|
194
|
-
{ json: "support_level", js: "support_level", typ: "" },
|
|
195
|
-
{ json: "createdAt", js: "createdAt", typ: Date },
|
|
196
|
-
{ json: "updatedAt", js: "updatedAt", typ: Date },
|
|
197
|
-
], false),
|
|
198
|
-
"Manufacturer": o([
|
|
199
|
-
{ json: "id", js: "id", typ: "" },
|
|
200
|
-
{ json: "slug", js: "slug", typ: "" },
|
|
201
|
-
{ json: "name", js: "name", typ: "" },
|
|
202
|
-
{ json: "logo", js: "logo", typ: "" },
|
|
203
|
-
{ json: "support_level", js: "support_level", typ: "" },
|
|
204
|
-
{ json: "createdAt", js: "createdAt", typ: Date },
|
|
205
|
-
{ json: "updatedAt", js: "updatedAt", typ: Date },
|
|
206
|
-
{ json: "icon", js: "icon", typ: "" },
|
|
207
|
-
{ json: "vector_icon", js: "vector_icon", typ: "" },
|
|
208
|
-
], false),
|
|
209
|
-
};
|
|
210
3
|
//# sourceMappingURL=response.interfaces.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"response.interfaces.js","sourceRoot":"","sources":["../../../src/deviceModel/getDeviceModelByManufacturerSlug/response.interfaces.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"response.interfaces.js","sourceRoot":"","sources":["../../../src/deviceModel/getDeviceModelByManufacturerSlug/response.interfaces.ts"],"names":[],"mappings":""}
|
|
@@ -2,15 +2,10 @@ import { Logger } from "../../common/logger";
|
|
|
2
2
|
import { DeviceModel } from "../entities";
|
|
3
3
|
export interface GetDeviceModelsOptions {
|
|
4
4
|
/**
|
|
5
|
-
* The base URL of the
|
|
6
|
-
* @default "https://
|
|
5
|
+
* The base URL of the Texture REST API.
|
|
6
|
+
* @default "https://api.texturehq.com"
|
|
7
7
|
*/
|
|
8
8
|
baseApiUrl?: string;
|
|
9
|
-
/**
|
|
10
|
-
* The base URL for images coming from Payload CMS.
|
|
11
|
-
* @default "https://device.cms.texture.energy"
|
|
12
|
-
*/
|
|
13
|
-
baseImageUrl?: string;
|
|
14
9
|
/**
|
|
15
10
|
* Limits the number of device models returned.
|
|
16
11
|
* @default 10
|
|
@@ -43,9 +38,9 @@ export interface GetDeviceModelsResponse {
|
|
|
43
38
|
cached?: boolean;
|
|
44
39
|
}
|
|
45
40
|
/**
|
|
46
|
-
* Retrieves a collection of device models from the
|
|
47
|
-
* @param options The options to use during the
|
|
48
|
-
* @returns {Promise<GetDeviceModelsResponse>} The collection of device models retrieved from the
|
|
41
|
+
* Retrieves a collection of device models from the Texture REST API.
|
|
42
|
+
* @param options The options to use during the getDeviceModels operation.
|
|
43
|
+
* @returns {Promise<GetDeviceModelsResponse>} The collection of device models retrieved from the API.
|
|
49
44
|
*/
|
|
50
45
|
export declare const getDeviceModels: (options?: GetDeviceModelsOptions) => Promise<GetDeviceModelsResponse>;
|
|
51
46
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/deviceModel/getDeviceModels/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/getDeviceModels/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAGzD,OAAO,EAAE,WAAW,EAAqB,MAAM,aAAa,CAAC;AAM7D,MAAM,WAAW,sBAAsB;IACrC;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;;OAGG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;OAEG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;CAClB;AAED,MAAM,WAAW,uBAAuB;IACtC,YAAY,EAAE,WAAW,EAAE,CAAC;IAC5B,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAED;;;;GAIG;AACH,eAAO,MAAM,eAAe,GAAU,UAAS,sBAA2B,KAAG,OAAO,CAAC,uBAAuB,CA4D3G,CAAC"}
|
|
@@ -5,54 +5,67 @@ 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 parseManufacturer_1 = require("../../manufacturer/parseManufacturer");
|
|
10
10
|
/**
|
|
11
|
-
* Retrieves a collection of device models from the
|
|
12
|
-
* @param options The options to use during the
|
|
13
|
-
* @returns {Promise<GetDeviceModelsResponse>} The collection of device models retrieved from the
|
|
11
|
+
* Retrieves a collection of device models from the Texture REST API.
|
|
12
|
+
* @param options The options to use during the getDeviceModels operation.
|
|
13
|
+
* @returns {Promise<GetDeviceModelsResponse>} The collection of device models retrieved from the API.
|
|
14
14
|
*/
|
|
15
15
|
const getDeviceModels = async (options = {}) => {
|
|
16
16
|
const defaultLogger = logger_1.baseLogger.function("getDeviceModels");
|
|
17
|
-
const { limit = 10, page = 1, baseApiUrl = constants_1.PRODUCTION_BASE_URL,
|
|
18
|
-
const operation = logger.operation("get device models from
|
|
19
|
-
const axios = (0, axios_1.getAxios)();
|
|
17
|
+
const { limit = 10, page = 1, baseApiUrl = constants_1.PRODUCTION_BASE_URL, logger = defaultLogger, slugs = [] } = options;
|
|
18
|
+
const operation = logger.operation("get device models from Texture REST API");
|
|
20
19
|
try {
|
|
21
20
|
operation.start({ options });
|
|
22
|
-
|
|
21
|
+
const params = new URLSearchParams({ limit: String(limit), page: String(page) });
|
|
23
22
|
if (options.manufacturer) {
|
|
24
|
-
|
|
23
|
+
params.set("manufacturer", options.manufacturer);
|
|
25
24
|
}
|
|
26
|
-
else {
|
|
27
|
-
|
|
28
|
-
response = await axios.get(`${baseApiUrl}/api/device_models?limit=${limit}&page=${page}${slugQuery}`);
|
|
25
|
+
else if (slugs.length === 1) {
|
|
26
|
+
params.set("slug", slugs[0]);
|
|
29
27
|
}
|
|
30
|
-
|
|
31
|
-
|
|
28
|
+
const modelsUrl = `${baseApiUrl}/v1/public/device-models?${params.toString()}`;
|
|
29
|
+
const modelsResponse = await (0, fetch_1.fetchWithRetry)(modelsUrl);
|
|
30
|
+
if (!modelsResponse.ok) {
|
|
31
|
+
const errorMessage = `Request to ${modelsUrl} failed with status ${modelsResponse.status}`;
|
|
32
32
|
operation.fail(errorMessage);
|
|
33
|
-
throw new exceptions_1.NetworkError(errorMessage,
|
|
33
|
+
throw new exceptions_1.NetworkError(errorMessage, modelsResponse.status);
|
|
34
|
+
}
|
|
35
|
+
const modelsData = (await modelsResponse.json());
|
|
36
|
+
const manufacturersUrl = `${baseApiUrl}/v1/public/manufacturers`;
|
|
37
|
+
const manufacturersResponse = await (0, fetch_1.fetchWithRetry)(manufacturersUrl);
|
|
38
|
+
if (!manufacturersResponse.ok) {
|
|
39
|
+
const errorMessage = `Request to ${manufacturersUrl} failed with status ${manufacturersResponse.status}`;
|
|
40
|
+
operation.fail(errorMessage);
|
|
41
|
+
throw new exceptions_1.NetworkError(errorMessage, manufacturersResponse.status);
|
|
42
|
+
}
|
|
43
|
+
const manufacturersData = (await manufacturersResponse.json());
|
|
44
|
+
const manufacturersBySlug = new Map(manufacturersData.map((m) => [m.slug, m]));
|
|
45
|
+
let items = modelsData.data;
|
|
46
|
+
if (slugs.length > 1) {
|
|
47
|
+
items = items.filter((item) => slugs.includes(item.slug));
|
|
34
48
|
}
|
|
35
49
|
const result = {
|
|
36
|
-
deviceModels:
|
|
37
|
-
|
|
38
|
-
|
|
50
|
+
deviceModels: items.map((doc) => {
|
|
51
|
+
const fullManufacturer = manufacturersBySlug.get(doc.manufacturer.slug);
|
|
52
|
+
if (!fullManufacturer)
|
|
53
|
+
throw new Error(`Manufacturer not found for slug: ${doc.manufacturer.slug}`);
|
|
39
54
|
return entities_1.DeviceModelSchema.parse({
|
|
40
55
|
...doc,
|
|
41
|
-
manufacturer: (0,
|
|
56
|
+
manufacturer: (0, parseManufacturer_1.parseManufacturer)(fullManufacturer),
|
|
42
57
|
});
|
|
43
58
|
}),
|
|
44
|
-
count:
|
|
45
|
-
limit:
|
|
46
|
-
page:
|
|
47
|
-
pageCount:
|
|
59
|
+
count: modelsData.total,
|
|
60
|
+
limit: modelsData.limit,
|
|
61
|
+
page: modelsData.page,
|
|
62
|
+
pageCount: modelsData.pageCount,
|
|
48
63
|
};
|
|
49
|
-
// @ts-expect-error Property 'cached' does not exist
|
|
50
|
-
result.cached = response?.cached;
|
|
51
64
|
operation.end({ result });
|
|
52
65
|
return result;
|
|
53
66
|
}
|
|
54
67
|
catch (error) {
|
|
55
|
-
operation.fail("Unknown error occurred while fetching
|
|
68
|
+
operation.fail("Unknown error occurred while fetching device models from Texture REST API.");
|
|
56
69
|
throw error;
|
|
57
70
|
}
|
|
58
71
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/deviceModel/getDeviceModels/index.ts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