@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
|
@@ -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;AAO7D,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,CAoE3G,CAAC"}
|
|
@@ -5,54 +5,76 @@ 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 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
|
|
12
|
+
* Retrieves a collection of device models from the Texture REST API.
|
|
13
|
+
* @param options The options to use during the getDeviceModels operation.
|
|
14
|
+
* @returns {Promise<GetDeviceModelsResponse>} The collection of device models retrieved from the API.
|
|
14
15
|
*/
|
|
15
16
|
const getDeviceModels = async (options = {}) => {
|
|
16
17
|
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)();
|
|
18
|
+
const { limit = 10, page = 1, baseApiUrl = constants_1.PRODUCTION_BASE_URL, logger = defaultLogger, slugs = [] } = options;
|
|
19
|
+
const operation = logger.operation("get device models from Texture REST API");
|
|
20
20
|
try {
|
|
21
21
|
operation.start({ options });
|
|
22
|
-
|
|
22
|
+
const params = new URLSearchParams({ limit: String(limit), page: String(page) });
|
|
23
23
|
if (options.manufacturer) {
|
|
24
|
-
|
|
24
|
+
params.set("manufacturer", options.manufacturer);
|
|
25
25
|
}
|
|
26
|
-
else {
|
|
27
|
-
|
|
28
|
-
response = await axios.get(`${baseApiUrl}/api/device_models?limit=${limit}&page=${page}${slugQuery}`);
|
|
26
|
+
else if (slugs.length === 1) {
|
|
27
|
+
params.set("slug", slugs[0]);
|
|
29
28
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
29
|
+
const modelsUrl = `${baseApiUrl}/v1/public/device-models?${params.toString()}`;
|
|
30
|
+
let modelsData = (0, cache_1.cacheGet)(modelsUrl);
|
|
31
|
+
if (!modelsData) {
|
|
32
|
+
const modelsResponse = await (0, fetch_1.fetchWithRetry)(modelsUrl);
|
|
33
|
+
if (!modelsResponse.ok) {
|
|
34
|
+
const errorMessage = `Request to ${modelsUrl} failed with status ${modelsResponse.status}`;
|
|
35
|
+
operation.fail(errorMessage);
|
|
36
|
+
throw new exceptions_1.NetworkError(errorMessage, modelsResponse.status);
|
|
37
|
+
}
|
|
38
|
+
modelsData = (await modelsResponse.json());
|
|
39
|
+
(0, cache_1.cacheSet)(modelsUrl, modelsData);
|
|
40
|
+
}
|
|
41
|
+
const manufacturersUrl = `${baseApiUrl}/v1/public/manufacturers`;
|
|
42
|
+
let manufacturersData = (0, cache_1.cacheGet)(manufacturersUrl);
|
|
43
|
+
if (!manufacturersData) {
|
|
44
|
+
const manufacturersResponse = await (0, fetch_1.fetchWithRetry)(manufacturersUrl);
|
|
45
|
+
if (!manufacturersResponse.ok) {
|
|
46
|
+
const errorMessage = `Request to ${manufacturersUrl} failed with status ${manufacturersResponse.status}`;
|
|
47
|
+
operation.fail(errorMessage);
|
|
48
|
+
throw new exceptions_1.NetworkError(errorMessage, manufacturersResponse.status);
|
|
49
|
+
}
|
|
50
|
+
manufacturersData = (await manufacturersResponse.json());
|
|
51
|
+
(0, cache_1.cacheSet)(manufacturersUrl, manufacturersData);
|
|
52
|
+
}
|
|
53
|
+
const manufacturersBySlug = new Map(manufacturersData.map((m) => [m.slug, m]));
|
|
54
|
+
let items = modelsData.data;
|
|
55
|
+
if (slugs.length > 1) {
|
|
56
|
+
items = items.filter((item) => slugs.includes(item.slug));
|
|
34
57
|
}
|
|
35
58
|
const result = {
|
|
36
|
-
deviceModels:
|
|
37
|
-
|
|
38
|
-
|
|
59
|
+
deviceModels: items.map((doc) => {
|
|
60
|
+
const fullManufacturer = manufacturersBySlug.get(doc.manufacturer.slug);
|
|
61
|
+
if (!fullManufacturer)
|
|
62
|
+
throw new Error(`Manufacturer not found for slug: ${doc.manufacturer.slug}`);
|
|
39
63
|
return entities_1.DeviceModelSchema.parse({
|
|
40
64
|
...doc,
|
|
41
|
-
manufacturer: (0,
|
|
65
|
+
manufacturer: (0, parseManufacturer_1.parseManufacturer)(fullManufacturer),
|
|
42
66
|
});
|
|
43
67
|
}),
|
|
44
|
-
count:
|
|
45
|
-
limit:
|
|
46
|
-
page:
|
|
47
|
-
pageCount:
|
|
68
|
+
count: modelsData.total,
|
|
69
|
+
limit: modelsData.limit,
|
|
70
|
+
page: modelsData.page,
|
|
71
|
+
pageCount: modelsData.pageCount,
|
|
48
72
|
};
|
|
49
|
-
// @ts-expect-error Property 'cached' does not exist
|
|
50
|
-
result.cached = response?.cached;
|
|
51
73
|
operation.end({ result });
|
|
52
74
|
return result;
|
|
53
75
|
}
|
|
54
76
|
catch (error) {
|
|
55
|
-
operation.fail("Unknown error occurred while fetching
|
|
77
|
+
operation.fail("Unknown error occurred while fetching device models from Texture REST API.");
|
|
56
78
|
throw error;
|
|
57
79
|
}
|
|
58
80
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/deviceModel/getDeviceModels/index.ts"],"names":[],"mappings":";;;AAAA,gDAAyD;AAEzD,wDAAuD;AACvD,0CAA6D;AAC7D,sDAA6D;AAC7D,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/deviceModel/getDeviceModels/index.ts"],"names":[],"mappings":";;;AAAA,gDAAyD;AAEzD,wDAAuD;AACvD,0CAA6D;AAC7D,sDAA6D;AAC7D,8CAAoD;AACpD,8CAAwD;AAExD,4EAAyE;AAyCzE;;;;GAIG;AACI,MAAM,eAAe,GAAG,KAAK,EAAE,UAAkC,EAAE,EAAoC,EAAE;IAC9G,MAAM,aAAa,GAAG,mBAAU,CAAC,QAAQ,CAAC,iBAAiB,CAAC,CAAC;IAC7D,MAAM,EAAE,KAAK,GAAG,EAAE,EAAE,IAAI,GAAG,CAAC,EAAE,UAAU,GAAG,+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gB,GAAG,mBAAmB,CAAC,GAAG,CAAC,GAAG,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC;gBACxE,IAAI,CAAC,gBAAgB;oBAAE,MAAM,IAAI,KAAK,CAAC,oCAAoC,GAAG,CAAC,YAAY,CAAC,IAAI,EAAE,CAAC,CAAC;gBACpG,OAAO,4BAAiB,CAAC,KAAK,CAAC;oBAC7B,GAAG,GAAG;oBACN,YAAY,EAAE,IAAA,qCAAiB,EAAC,gBAAgB,CAAC;iBAClD,CAAC,CAAC;YACL,CAAC,CAAC;YACF,KAAK,EAAE,UAAU,CAAC,KAAK;YACvB,KAAK,EAAE,UAAU,CAAC,KAAK;YACvB,IAAI,EAAE,UAAU,CAAC,IAAI;YACrB,SAAS,EAAE,UAAU,CAAC,SAAS;SAChC,CAAC;QAEF,SAAS,CAAC,GAAG,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC;QAC1B,OAAO,MAAM,CAAC;IAChB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,SAAS,CAAC,IAAI,CAAC,4EAA4E,CAAC,CAAC;QAC7F,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC,CAAC;AApEW,QAAA,eAAe,mBAoE1B"}
|
|
@@ -1,95 +1,26 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
/**
|
|
2
|
+
* REST API response shape for GET /v1/public/device-models.
|
|
3
|
+
* Returns paginated device model data.
|
|
4
|
+
*/
|
|
5
|
+
export interface DeviceModelsApiResponse {
|
|
6
|
+
data: DeviceModelApiItem[];
|
|
7
|
+
total: number;
|
|
4
8
|
limit: number;
|
|
5
|
-
totalPages: number;
|
|
6
9
|
page: number;
|
|
7
|
-
|
|
8
|
-
hasPrevPage: boolean;
|
|
9
|
-
hasNextPage: boolean;
|
|
10
|
-
prevPage: null;
|
|
11
|
-
nextPage: number;
|
|
10
|
+
pageCount: number;
|
|
12
11
|
}
|
|
13
|
-
export interface
|
|
14
|
-
id: string;
|
|
12
|
+
export interface DeviceModelApiItem {
|
|
15
13
|
slug: string;
|
|
16
14
|
name: string;
|
|
17
|
-
manufacturer: Manufacturer;
|
|
18
15
|
type: string;
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
export interface AvailableCommand {
|
|
25
|
-
id: string;
|
|
26
|
-
slug: string;
|
|
27
|
-
support_level: string;
|
|
28
|
-
createdAt: Date;
|
|
29
|
-
updatedAt: Date;
|
|
16
|
+
manufacturer: {
|
|
17
|
+
slug: string;
|
|
18
|
+
name: string;
|
|
19
|
+
};
|
|
20
|
+
available_commands: DeviceModelApiCommand[];
|
|
30
21
|
}
|
|
31
|
-
export interface
|
|
32
|
-
id: string;
|
|
22
|
+
export interface DeviceModelApiCommand {
|
|
33
23
|
slug: string;
|
|
34
|
-
name: string;
|
|
35
|
-
logo: Logo;
|
|
36
24
|
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
25
|
}
|
|
95
26
|
//# sourceMappingURL=response.interfaces.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"response.interfaces.d.ts","sourceRoot":"","sources":["../../../src/deviceModel/getDeviceModels/response.interfaces.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"response.interfaces.d.ts","sourceRoot":"","sources":["../../../src/deviceModel/getDeviceModels/response.interfaces.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,WAAW,uBAAuB;IACtC,IAAI,EAAE,kBAAkB,EAAE,CAAC;IAC3B,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,YAAY,EAAE;QACZ,IAAI,EAAE,MAAM,CAAC;QACb,IAAI,EAAE,MAAM,CAAC;KACd,CAAC;IACF,kBAAkB,EAAE,qBAAqB,EAAE,CAAC;CAC7C;AAED,MAAM,WAAW,qBAAqB;IACpC,IAAI,EAAE,MAAM,CAAC;IACb,aAAa,EAAE,MAAM,CAAC;CACvB"}
|