@texturehq/device 1.3.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/README.md +110 -0
- package/dist/common/constants.d.ts +3 -0
- package/dist/common/constants.d.ts.map +1 -0
- package/dist/common/constants.js +6 -0
- package/dist/common/constants.js.map +1 -0
- package/dist/common/exceptions.d.ts +5 -0
- package/dist/common/exceptions.d.ts.map +1 -0
- package/dist/common/exceptions.js +13 -0
- package/dist/common/exceptions.js.map +1 -0
- package/dist/common/logger.d.ts +2 -0
- package/dist/common/logger.d.ts.map +1 -0
- package/dist/common/logger.js +6 -0
- package/dist/common/logger.js.map +1 -0
- package/dist/common/supportLevel.d.ts +6 -0
- package/dist/common/supportLevel.d.ts.map +1 -0
- package/dist/common/supportLevel.js +14 -0
- package/dist/common/supportLevel.js.map +1 -0
- package/dist/common/utils/index.d.ts +2 -0
- package/dist/common/utils/index.d.ts.map +1 -0
- package/dist/common/utils/index.js +8 -0
- package/dist/common/utils/index.js.map +1 -0
- package/dist/common/utils/retryAxios.d.ts +18 -0
- package/dist/common/utils/retryAxios.d.ts.map +1 -0
- package/dist/common/utils/retryAxios.js +32 -0
- package/dist/common/utils/retryAxios.js.map +1 -0
- package/dist/deviceModel/entities.d.ts +211 -0
- package/dist/deviceModel/entities.d.ts.map +1 -0
- package/dist/deviceModel/entities.js +41 -0
- package/dist/deviceModel/entities.js.map +1 -0
- package/dist/deviceModel/getDeviceModel/index.d.ts +29 -0
- package/dist/deviceModel/getDeviceModel/index.d.ts.map +1 -0
- package/dist/deviceModel/getDeviceModel/index.js +50 -0
- package/dist/deviceModel/getDeviceModel/index.js.map +1 -0
- package/dist/deviceModel/getDeviceModel/response.interfaces.d.ts +95 -0
- package/dist/deviceModel/getDeviceModel/response.interfaces.d.ts.map +1 -0
- package/dist/deviceModel/getDeviceModel/response.interfaces.js +252 -0
- package/dist/deviceModel/getDeviceModel/response.interfaces.js.map +1 -0
- package/dist/deviceModel/getDeviceModel/test.fail.d.ts +2 -0
- package/dist/deviceModel/getDeviceModel/test.fail.d.ts.map +1 -0
- package/dist/deviceModel/getDeviceModel/test.fail.js +8 -0
- package/dist/deviceModel/getDeviceModel/test.fail.js.map +1 -0
- package/dist/deviceModel/getDeviceModel/test.success.d.ts +2 -0
- package/dist/deviceModel/getDeviceModel/test.success.d.ts.map +1 -0
- package/dist/deviceModel/getDeviceModel/test.success.js +8 -0
- package/dist/deviceModel/getDeviceModel/test.success.js.map +1 -0
- package/dist/deviceModel/getDeviceModelByManufacturerSlug/index.d.ts +36 -0
- package/dist/deviceModel/getDeviceModelByManufacturerSlug/index.d.ts.map +1 -0
- package/dist/deviceModel/getDeviceModelByManufacturerSlug/index.js +59 -0
- package/dist/deviceModel/getDeviceModelByManufacturerSlug/index.js.map +1 -0
- package/dist/deviceModel/getDeviceModelByManufacturerSlug/response.interfaces.d.ts +53 -0
- package/dist/deviceModel/getDeviceModelByManufacturerSlug/response.interfaces.d.ts.map +1 -0
- package/dist/deviceModel/getDeviceModelByManufacturerSlug/response.interfaces.js +210 -0
- package/dist/deviceModel/getDeviceModelByManufacturerSlug/response.interfaces.js.map +1 -0
- package/dist/deviceModel/getDeviceModelByManufacturerSlug/test.fail.d.ts +2 -0
- package/dist/deviceModel/getDeviceModelByManufacturerSlug/test.fail.d.ts.map +1 -0
- package/dist/deviceModel/getDeviceModelByManufacturerSlug/test.fail.js +8 -0
- package/dist/deviceModel/getDeviceModelByManufacturerSlug/test.fail.js.map +1 -0
- package/dist/deviceModel/getDeviceModelByManufacturerSlug/test.success.d.ts +2 -0
- package/dist/deviceModel/getDeviceModelByManufacturerSlug/test.success.d.ts.map +1 -0
- package/dist/deviceModel/getDeviceModelByManufacturerSlug/test.success.js +8 -0
- package/dist/deviceModel/getDeviceModelByManufacturerSlug/test.success.js.map +1 -0
- package/dist/deviceModel/getDeviceModels/index.d.ts +50 -0
- package/dist/deviceModel/getDeviceModels/index.d.ts.map +1 -0
- package/dist/deviceModel/getDeviceModels/index.js +60 -0
- package/dist/deviceModel/getDeviceModels/index.js.map +1 -0
- package/dist/deviceModel/getDeviceModels/response.interfaces.d.ts +95 -0
- package/dist/deviceModel/getDeviceModels/response.interfaces.d.ts.map +1 -0
- package/dist/deviceModel/getDeviceModels/response.interfaces.js +252 -0
- package/dist/deviceModel/getDeviceModels/response.interfaces.js.map +1 -0
- package/dist/deviceModel/getDeviceModels/test.success.d.ts +2 -0
- package/dist/deviceModel/getDeviceModels/test.success.d.ts.map +1 -0
- package/dist/deviceModel/getDeviceModels/test.success.js +11 -0
- package/dist/deviceModel/getDeviceModels/test.success.js.map +1 -0
- package/dist/deviceModel/index.d.ts +5 -0
- package/dist/deviceModel/index.d.ts.map +1 -0
- package/dist/deviceModel/index.js +21 -0
- package/dist/deviceModel/index.js.map +1 -0
- package/dist/deviceState/battery.d.ts +132 -0
- package/dist/deviceState/battery.d.ts.map +1 -0
- package/dist/deviceState/battery.js +81 -0
- package/dist/deviceState/battery.js.map +1 -0
- package/dist/deviceState/charger.d.ts +44 -0
- package/dist/deviceState/charger.d.ts.map +1 -0
- package/dist/deviceState/charger.js +34 -0
- package/dist/deviceState/charger.js.map +1 -0
- package/dist/deviceState/common.d.ts +50 -0
- package/dist/deviceState/common.d.ts.map +1 -0
- package/dist/deviceState/common.js +75 -0
- package/dist/deviceState/common.js.map +1 -0
- package/dist/deviceState/index.d.ts +7 -0
- package/dist/deviceState/index.d.ts.map +1 -0
- package/dist/deviceState/index.js +23 -0
- package/dist/deviceState/index.js.map +1 -0
- package/dist/deviceState/inverter.d.ts +79 -0
- package/dist/deviceState/inverter.d.ts.map +1 -0
- package/dist/deviceState/inverter.js +30 -0
- package/dist/deviceState/inverter.js.map +1 -0
- package/dist/deviceState/thermostat.d.ts +58 -0
- package/dist/deviceState/thermostat.d.ts.map +1 -0
- package/dist/deviceState/thermostat.js +51 -0
- package/dist/deviceState/thermostat.js.map +1 -0
- package/dist/deviceState/vehicle.d.ts +88 -0
- package/dist/deviceState/vehicle.d.ts.map +1 -0
- package/dist/deviceState/vehicle.js +72 -0
- package/dist/deviceState/vehicle.js.map +1 -0
- package/dist/deviceType/entities.d.ts +6 -0
- package/dist/deviceType/entities.d.ts.map +1 -0
- package/dist/deviceType/entities.js +14 -0
- package/dist/deviceType/entities.js.map +1 -0
- package/dist/deviceType/index.d.ts +2 -0
- package/dist/deviceType/index.d.ts.map +1 -0
- package/dist/deviceType/index.js +18 -0
- package/dist/deviceType/index.js.map +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +25 -0
- package/dist/index.js.map +1 -0
- package/dist/manufacturer/entities.d.ts +124 -0
- package/dist/manufacturer/entities.d.ts.map +1 -0
- package/dist/manufacturer/entities.js +28 -0
- package/dist/manufacturer/entities.js.map +1 -0
- package/dist/manufacturer/getManufacturer/index.d.ts +34 -0
- package/dist/manufacturer/getManufacturer/index.d.ts.map +1 -0
- package/dist/manufacturer/getManufacturer/index.js +47 -0
- package/dist/manufacturer/getManufacturer/index.js.map +1 -0
- package/dist/manufacturer/getManufacturer/response.interfaces.d.ts +77 -0
- package/dist/manufacturer/getManufacturer/response.interfaces.d.ts.map +1 -0
- package/dist/manufacturer/getManufacturer/response.interfaces.js +234 -0
- package/dist/manufacturer/getManufacturer/response.interfaces.js.map +1 -0
- package/dist/manufacturer/getManufacturer/test.fail.d.ts +2 -0
- package/dist/manufacturer/getManufacturer/test.fail.d.ts.map +1 -0
- package/dist/manufacturer/getManufacturer/test.fail.js +8 -0
- package/dist/manufacturer/getManufacturer/test.fail.js.map +1 -0
- package/dist/manufacturer/getManufacturer/test.success.d.ts +2 -0
- package/dist/manufacturer/getManufacturer/test.success.d.ts.map +1 -0
- package/dist/manufacturer/getManufacturer/test.success.js +8 -0
- package/dist/manufacturer/getManufacturer/test.success.js.map +1 -0
- package/dist/manufacturer/getManufacturers/index.d.ts +51 -0
- package/dist/manufacturer/getManufacturers/index.d.ts.map +1 -0
- package/dist/manufacturer/getManufacturers/index.js +46 -0
- package/dist/manufacturer/getManufacturers/index.js.map +1 -0
- package/dist/manufacturer/getManufacturers/response.interfaces.d.ts +77 -0
- package/dist/manufacturer/getManufacturers/response.interfaces.d.ts.map +1 -0
- package/dist/manufacturer/getManufacturers/response.interfaces.js +242 -0
- package/dist/manufacturer/getManufacturers/response.interfaces.js.map +1 -0
- package/dist/manufacturer/getManufacturers/test.success.d.ts +2 -0
- package/dist/manufacturer/getManufacturers/test.success.d.ts.map +1 -0
- package/dist/manufacturer/getManufacturers/test.success.js +8 -0
- package/dist/manufacturer/getManufacturers/test.success.js.map +1 -0
- package/dist/manufacturer/index.d.ts +5 -0
- package/dist/manufacturer/index.d.ts.map +1 -0
- package/dist/manufacturer/index.js +21 -0
- package/dist/manufacturer/index.js.map +1 -0
- package/dist/manufacturer/parseManufacturer/index.d.ts +4 -0
- package/dist/manufacturer/parseManufacturer/index.d.ts.map +1 -0
- package/dist/manufacturer/parseManufacturer/index.js +42 -0
- package/dist/manufacturer/parseManufacturer/index.js.map +1 -0
- package/dist/metrics/aggregations.d.ts +5 -0
- package/dist/metrics/aggregations.d.ts.map +1 -0
- package/dist/metrics/aggregations.js +7 -0
- package/dist/metrics/aggregations.js.map +1 -0
- package/dist/metrics/groupBy.d.ts +5 -0
- package/dist/metrics/groupBy.d.ts.map +1 -0
- package/dist/metrics/groupBy.js +7 -0
- package/dist/metrics/groupBy.js.map +1 -0
- package/dist/metrics/index.d.ts +6 -0
- package/dist/metrics/index.d.ts.map +1 -0
- package/dist/metrics/index.js +22 -0
- package/dist/metrics/index.js.map +1 -0
- package/dist/metrics/range.d.ts +28 -0
- package/dist/metrics/range.d.ts.map +1 -0
- package/dist/metrics/range.js +138 -0
- package/dist/metrics/range.js.map +1 -0
- package/dist/metrics/units.d.ts +5 -0
- package/dist/metrics/units.d.ts.map +1 -0
- package/dist/metrics/units.js +31 -0
- package/dist/metrics/units.js.map +1 -0
- package/dist/metrics/window.d.ts +17 -0
- package/dist/metrics/window.d.ts.map +1 -0
- package/dist/metrics/window.js +28 -0
- package/dist/metrics/window.js.map +1 -0
- package/package.json +37 -0
package/README.md
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
# @texturehq/device
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@texturehq/device)
|
|
4
|
+
|
|
5
|
+
A type-safe TypeScript client for working with device data in the Texture platform. This package provides strongly-typed interfaces and utilities for querying and validating device information, manufacturers, and device models.
|
|
6
|
+
|
|
7
|
+
## Features
|
|
8
|
+
|
|
9
|
+
- Type-safe API for querying device data
|
|
10
|
+
- Comprehensive TypeScript definitions for all device-related entities
|
|
11
|
+
- Built-in validation for device data structures
|
|
12
|
+
- Utilities for working with manufacturers and device models
|
|
13
|
+
- Full TypeScript support
|
|
14
|
+
|
|
15
|
+
## Installation
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
npm install @texturehq/device
|
|
19
|
+
# or
|
|
20
|
+
yarn add @texturehq/device
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Usage
|
|
24
|
+
|
|
25
|
+
### Querying Manufacturers
|
|
26
|
+
|
|
27
|
+
```typescript
|
|
28
|
+
import { getManufacturers, getManufacturer, Manufacturer } from "@texturehq/device";
|
|
29
|
+
|
|
30
|
+
// Get all manufacturers
|
|
31
|
+
const listManufacturers = async () => {
|
|
32
|
+
const response = await getManufacturers();
|
|
33
|
+
const manufacturers: Manufacturer[] = response.manufacturers;
|
|
34
|
+
|
|
35
|
+
// Work with strongly-typed manufacturer data
|
|
36
|
+
manufacturers.forEach(manufacturer => {
|
|
37
|
+
console.log(manufacturer.name, manufacturer.slug);
|
|
38
|
+
});
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
// Get a specific manufacturer
|
|
42
|
+
const getSpecificManufacturer = async () => {
|
|
43
|
+
const manufacturer = await getManufacturer({ slug: "bmw" });
|
|
44
|
+
console.log(manufacturer.name, manufacturer.supportedRegions);
|
|
45
|
+
};
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
### Working with Device Models
|
|
49
|
+
|
|
50
|
+
```typescript
|
|
51
|
+
import { getDeviceModels, getDeviceModel, DeviceModel } from "@texturehq/device";
|
|
52
|
+
|
|
53
|
+
// Get all device models
|
|
54
|
+
const listDeviceModels = async () => {
|
|
55
|
+
const response = await getDeviceModels();
|
|
56
|
+
const models: DeviceModel[] = response.deviceModels;
|
|
57
|
+
|
|
58
|
+
// Access strongly-typed model information
|
|
59
|
+
models.forEach(model => {
|
|
60
|
+
console.log(model.name, model.manufacturer, model.capabilities);
|
|
61
|
+
});
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
// Get a specific device model
|
|
65
|
+
const getSpecificModel = async () => {
|
|
66
|
+
const model = await getDeviceModel({ slug: "i4-edrive40" });
|
|
67
|
+
console.log(model.name, model.specifications);
|
|
68
|
+
};
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
## Available Types
|
|
72
|
+
|
|
73
|
+
The package exports several TypeScript interfaces for working with device data:
|
|
74
|
+
|
|
75
|
+
### Core Types
|
|
76
|
+
- `Manufacturer` - Represents a device manufacturer
|
|
77
|
+
- `DeviceModel` - Represents a specific model from a manufacturer
|
|
78
|
+
- `Device` - Represents an individual device instance
|
|
79
|
+
- `DeviceCapability` - Describes what a device can do
|
|
80
|
+
- `Region` - Represents supported geographical regions
|
|
81
|
+
|
|
82
|
+
### API Response Types
|
|
83
|
+
- `ManufacturersResponse` - Response structure for manufacturer queries
|
|
84
|
+
- `DeviceModelsResponse` - Response structure for device model queries
|
|
85
|
+
|
|
86
|
+
## Error Handling
|
|
87
|
+
|
|
88
|
+
All API methods can throw the following errors:
|
|
89
|
+
|
|
90
|
+
```typescript
|
|
91
|
+
import { DeviceError } from "@texturehq/device";
|
|
92
|
+
|
|
93
|
+
try {
|
|
94
|
+
const manufacturer = await getManufacturer({ slug: "invalid-slug" });
|
|
95
|
+
} catch (error) {
|
|
96
|
+
if (error instanceof DeviceError) {
|
|
97
|
+
// Handle device-specific errors
|
|
98
|
+
console.error(error.message, error.code);
|
|
99
|
+
} else {
|
|
100
|
+
// Handle other errors
|
|
101
|
+
console.error("Unexpected error", error);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
For more details on using this package and integrating with Texture's device ecosystem, consult [our documentation](https://docs.texturehq.com) or [contact us](https://www.texturehq.com/contact/).
|
|
107
|
+
|
|
108
|
+
## License
|
|
109
|
+
|
|
110
|
+
MIT
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/common/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,yBAAyB,oCAA8C,CAAC;AACrF,eAAO,MAAM,mBAAmB,oCAA8C,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PRODUCTION_BASE_URL = exports.PRODUCTION_CACHE_BASE_URL = void 0;
|
|
4
|
+
exports.PRODUCTION_CACHE_BASE_URL = "https://device.cms.texturehq.com";
|
|
5
|
+
exports.PRODUCTION_BASE_URL = "https://texturehq.payloadcms.app";
|
|
6
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/common/constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,yBAAyB,GAAG,kCAA2C,CAAC;AACxE,QAAA,mBAAmB,GAAG,kCAA2C,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"exceptions.d.ts","sourceRoot":"","sources":["../../src/common/exceptions.ts"],"names":[],"mappings":"AAAA,qBAAa,YAAa,SAAQ,KAAK;IACrC,UAAU,EAAE,MAAM,CAAC;gBACP,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM;CAKhD"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NetworkError = void 0;
|
|
4
|
+
class NetworkError extends Error {
|
|
5
|
+
statusCode;
|
|
6
|
+
constructor(message, statusCode) {
|
|
7
|
+
super(message);
|
|
8
|
+
this.name = "NetworkError";
|
|
9
|
+
this.statusCode = statusCode;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
exports.NetworkError = NetworkError;
|
|
13
|
+
//# sourceMappingURL=exceptions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"exceptions.js","sourceRoot":"","sources":["../../src/common/exceptions.ts"],"names":[],"mappings":";;;AAAA,MAAa,YAAa,SAAQ,KAAK;IACrC,UAAU,CAAS;IACnB,YAAY,OAAe,EAAE,UAAkB;QAC7C,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,cAAc,CAAC;QAC3B,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;IAC/B,CAAC;CACF;AAPD,oCAOC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/common/logger.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,UAAU,4CAAgE,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.baseLogger = void 0;
|
|
4
|
+
const logger_1 = require("@texturehq/logger");
|
|
5
|
+
exports.baseLogger = (0, logger_1.createLogger)({ name: "device-package" }).component("package");
|
|
6
|
+
//# sourceMappingURL=logger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../../src/common/logger.ts"],"names":[],"mappings":";;;AAAA,8CAAiD;AAEpC,QAAA,UAAU,GAAG,IAAA,qBAAY,EAAC,EAAE,IAAI,EAAE,gBAAgB,EAAE,CAAC,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export declare const SupportLevels: readonly ["planned", "development", "uat", "production", "blocked"];
|
|
3
|
+
export type SupportLevel = (typeof SupportLevels)[number];
|
|
4
|
+
export declare const SupportLevelEnum: z.ZodEnum<["planned", "development", "uat", "production", "blocked"]>;
|
|
5
|
+
export declare const SupportLevelLabelMap: Record<SupportLevel, string>;
|
|
6
|
+
//# sourceMappingURL=supportLevel.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"supportLevel.d.ts","sourceRoot":"","sources":["../../src/common/supportLevel.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,eAAO,MAAM,aAAa,qEAAsE,CAAC;AACjG,MAAM,MAAM,YAAY,GAAG,CAAC,OAAO,aAAa,CAAC,CAAC,MAAM,CAAC,CAAC;AAC1D,eAAO,MAAM,gBAAgB,uEAAwB,CAAC;AAEtD,eAAO,MAAM,oBAAoB,EAAE,MAAM,CAAC,YAAY,EAAE,MAAM,CAM7D,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SupportLevelLabelMap = exports.SupportLevelEnum = exports.SupportLevels = void 0;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
exports.SupportLevels = ["planned", "development", "uat", "production", "blocked"];
|
|
6
|
+
exports.SupportLevelEnum = zod_1.z.enum(exports.SupportLevels);
|
|
7
|
+
exports.SupportLevelLabelMap = {
|
|
8
|
+
planned: "Planned",
|
|
9
|
+
blocked: "Blocked",
|
|
10
|
+
development: "Development",
|
|
11
|
+
uat: "User Acceptance Testing",
|
|
12
|
+
production: "Production",
|
|
13
|
+
};
|
|
14
|
+
//# sourceMappingURL=supportLevel.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"supportLevel.js","sourceRoot":"","sources":["../../src/common/supportLevel.ts"],"names":[],"mappings":";;;AAAA,6BAAwB;AAEX,QAAA,aAAa,GAAG,CAAC,SAAS,EAAE,aAAa,EAAE,KAAK,EAAE,YAAY,EAAE,SAAS,CAAU,CAAC;AAEpF,QAAA,gBAAgB,GAAG,OAAC,CAAC,IAAI,CAAC,qBAAa,CAAC,CAAC;AAEzC,QAAA,oBAAoB,GAAiC;IAChE,OAAO,EAAE,SAAS;IAClB,OAAO,EAAE,SAAS;IAClB,WAAW,EAAE,aAAa;IAC1B,GAAG,EAAE,yBAAyB;IAC9B,UAAU,EAAE,YAAY;CACzB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/common/utils/index.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,qBAAqB,QAAS,MAAM,KAAG,MAEnD,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.fromGraphQLSafeString = void 0;
|
|
4
|
+
const fromGraphQLSafeString = (str) => {
|
|
5
|
+
return str.replace(/__/g, ":").replace(/_/g, "-");
|
|
6
|
+
};
|
|
7
|
+
exports.fromGraphQLSafeString = fromGraphQLSafeString;
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/common/utils/index.ts"],"names":[],"mappings":";;;AAAO,MAAM,qBAAqB,GAAG,CAAC,GAAW,EAAU,EAAE;IACzD,OAAO,GAAG,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;AACtD,CAAC,CAAC;AAFW,QAAA,qBAAqB,yBAEhC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { AxiosInstance } from "axios";
|
|
2
|
+
import { Logger } from "@texturehq/logger";
|
|
3
|
+
export interface RetryOptions {
|
|
4
|
+
/**
|
|
5
|
+
* The number of retries to attempt before failing.
|
|
6
|
+
* @default 3
|
|
7
|
+
*/
|
|
8
|
+
retries?: number;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Configures axios instance with retry capabilities
|
|
12
|
+
* @param logger Logger instance to use for retry logging
|
|
13
|
+
* @param retryOptions Optional retry configuration
|
|
14
|
+
* @param axiosInstance Optional axios instance to configure (defaults to global axios)
|
|
15
|
+
* @returns The configured axios instance
|
|
16
|
+
*/
|
|
17
|
+
export declare function configureAxiosRetry(logger: Logger, retryOptions?: RetryOptions, axiosInstance?: AxiosInstance): AxiosInstance;
|
|
18
|
+
//# sourceMappingURL=retryAxios.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"retryAxios.d.ts","sourceRoot":"","sources":["../../../src/common/utils/retryAxios.ts"],"names":[],"mappings":"AAAA,OAAc,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAE7C,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAE3C,MAAM,WAAW,YAAY;IAC3B;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,MAAM,EACd,YAAY,CAAC,EAAE,YAAY,EAC3B,aAAa,GAAE,aAAqB,GACnC,aAAa,CAgBf"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.configureAxiosRetry = void 0;
|
|
7
|
+
const axios_1 = __importDefault(require("axios"));
|
|
8
|
+
const axios_retry_1 = __importDefault(require("axios-retry"));
|
|
9
|
+
/**
|
|
10
|
+
* Configures axios instance with retry capabilities
|
|
11
|
+
* @param logger Logger instance to use for retry logging
|
|
12
|
+
* @param retryOptions Optional retry configuration
|
|
13
|
+
* @param axiosInstance Optional axios instance to configure (defaults to global axios)
|
|
14
|
+
* @returns The configured axios instance
|
|
15
|
+
*/
|
|
16
|
+
function configureAxiosRetry(logger, retryOptions, axiosInstance = axios_1.default) {
|
|
17
|
+
if (!retryOptions) {
|
|
18
|
+
return axiosInstance;
|
|
19
|
+
}
|
|
20
|
+
const retryConfig = {
|
|
21
|
+
retries: retryOptions.retries || 3,
|
|
22
|
+
retryDelay: axios_retry_1.default.exponentialDelay,
|
|
23
|
+
onRetry: (retryCount, error) => {
|
|
24
|
+
logger.warn("retryCount", { retryCount });
|
|
25
|
+
logger.warn("error", { error });
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
(0, axios_retry_1.default)(axiosInstance, retryConfig);
|
|
29
|
+
return axiosInstance;
|
|
30
|
+
}
|
|
31
|
+
exports.configureAxiosRetry = configureAxiosRetry;
|
|
32
|
+
//# sourceMappingURL=retryAxios.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"retryAxios.js","sourceRoot":"","sources":["../../../src/common/utils/retryAxios.ts"],"names":[],"mappings":";;;;;;AAAA,kDAA6C;AAC7C,8DAA4D;AAW5D;;;;;;GAMG;AACH,SAAgB,mBAAmB,CACjC,MAAc,EACd,YAA2B,EAC3B,gBAA+B,eAAK;IAEpC,IAAI,CAAC,YAAY,EAAE,CAAC;QAClB,OAAO,aAAa,CAAC;IACvB,CAAC;IAED,MAAM,WAAW,GAAsB;QACrC,OAAO,EAAE,YAAY,CAAC,OAAO,IAAI,CAAC;QAClC,UAAU,EAAE,qBAAU,CAAC,gBAAgB;QACvC,OAAO,EAAE,CAAC,UAAU,EAAE,KAAK,EAAE,EAAE;YAC7B,MAAM,CAAC,IAAI,CAAC,YAAY,EAAE,EAAE,UAAU,EAAE,CAAC,CAAC;YAC1C,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;QAClC,CAAC;KACF,CAAC;IAEF,IAAA,qBAAU,EAAC,aAAa,EAAE,WAAW,CAAC,CAAC;IACvC,OAAO,aAAa,CAAC;AACvB,CAAC;AApBD,kDAoBC"}
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export declare const AvailableCommandSchema: z.ZodObject<{
|
|
3
|
+
/**
|
|
4
|
+
* The unique identifier for the command.
|
|
5
|
+
*/
|
|
6
|
+
slug: z.ZodEffects<z.ZodString, string, string>;
|
|
7
|
+
support_level: z.ZodEnum<["planned", "development", "uat", "production", "blocked"]>;
|
|
8
|
+
}, "strip", z.ZodTypeAny, {
|
|
9
|
+
slug: string;
|
|
10
|
+
support_level: "blocked" | "planned" | "development" | "uat" | "production";
|
|
11
|
+
}, {
|
|
12
|
+
slug: string;
|
|
13
|
+
support_level: "blocked" | "planned" | "development" | "uat" | "production";
|
|
14
|
+
}>;
|
|
15
|
+
export declare const DeviceModelSchema: z.ZodObject<{
|
|
16
|
+
/**
|
|
17
|
+
* The unique identifier for the device model.
|
|
18
|
+
* @example "tesla:panel"
|
|
19
|
+
*/
|
|
20
|
+
slug: z.ZodString;
|
|
21
|
+
/**
|
|
22
|
+
* The human readable name of the manufacturer.
|
|
23
|
+
* @example "PV Panel"
|
|
24
|
+
*/
|
|
25
|
+
name: z.ZodString;
|
|
26
|
+
/**
|
|
27
|
+
* The type of the device.
|
|
28
|
+
* @example "inverter"
|
|
29
|
+
*/
|
|
30
|
+
type: z.ZodEnum<["battery", "charger", "inverter", "thermostat", "vehicle"]>;
|
|
31
|
+
/**
|
|
32
|
+
* The manufacturer of the device.
|
|
33
|
+
*/
|
|
34
|
+
manufacturer: z.ZodObject<{
|
|
35
|
+
slug: z.ZodString;
|
|
36
|
+
name: z.ZodString;
|
|
37
|
+
supportLevel: z.ZodEnum<["planned", "development", "uat", "production", "blocked"]>;
|
|
38
|
+
logo: z.ZodObject<{
|
|
39
|
+
url: z.ZodString;
|
|
40
|
+
alt: z.ZodString;
|
|
41
|
+
width: z.ZodNumber;
|
|
42
|
+
height: z.ZodNumber;
|
|
43
|
+
}, "strip", z.ZodTypeAny, {
|
|
44
|
+
height: number;
|
|
45
|
+
width: number;
|
|
46
|
+
url: string;
|
|
47
|
+
alt: string;
|
|
48
|
+
}, {
|
|
49
|
+
height: number;
|
|
50
|
+
width: number;
|
|
51
|
+
url: string;
|
|
52
|
+
alt: string;
|
|
53
|
+
}>;
|
|
54
|
+
icon: z.ZodObject<{
|
|
55
|
+
url: z.ZodString;
|
|
56
|
+
alt: z.ZodString;
|
|
57
|
+
width: z.ZodNumber;
|
|
58
|
+
height: z.ZodNumber;
|
|
59
|
+
}, "strip", z.ZodTypeAny, {
|
|
60
|
+
height: number;
|
|
61
|
+
width: number;
|
|
62
|
+
url: string;
|
|
63
|
+
alt: string;
|
|
64
|
+
}, {
|
|
65
|
+
height: number;
|
|
66
|
+
width: number;
|
|
67
|
+
url: string;
|
|
68
|
+
alt: string;
|
|
69
|
+
}>;
|
|
70
|
+
vectorIcon: z.ZodObject<{
|
|
71
|
+
url: z.ZodString;
|
|
72
|
+
alt: z.ZodString;
|
|
73
|
+
width: z.ZodNumber;
|
|
74
|
+
height: z.ZodNumber;
|
|
75
|
+
}, "strip", z.ZodTypeAny, {
|
|
76
|
+
height: number;
|
|
77
|
+
width: number;
|
|
78
|
+
url: string;
|
|
79
|
+
alt: string;
|
|
80
|
+
}, {
|
|
81
|
+
height: number;
|
|
82
|
+
width: number;
|
|
83
|
+
url: string;
|
|
84
|
+
alt: string;
|
|
85
|
+
}>;
|
|
86
|
+
}, "strip", z.ZodTypeAny, {
|
|
87
|
+
name: string;
|
|
88
|
+
slug: string;
|
|
89
|
+
logo: {
|
|
90
|
+
height: number;
|
|
91
|
+
width: number;
|
|
92
|
+
url: string;
|
|
93
|
+
alt: string;
|
|
94
|
+
};
|
|
95
|
+
icon: {
|
|
96
|
+
height: number;
|
|
97
|
+
width: number;
|
|
98
|
+
url: string;
|
|
99
|
+
alt: string;
|
|
100
|
+
};
|
|
101
|
+
supportLevel: "blocked" | "planned" | "development" | "uat" | "production";
|
|
102
|
+
vectorIcon: {
|
|
103
|
+
height: number;
|
|
104
|
+
width: number;
|
|
105
|
+
url: string;
|
|
106
|
+
alt: string;
|
|
107
|
+
};
|
|
108
|
+
}, {
|
|
109
|
+
name: string;
|
|
110
|
+
slug: string;
|
|
111
|
+
logo: {
|
|
112
|
+
height: number;
|
|
113
|
+
width: number;
|
|
114
|
+
url: string;
|
|
115
|
+
alt: string;
|
|
116
|
+
};
|
|
117
|
+
icon: {
|
|
118
|
+
height: number;
|
|
119
|
+
width: number;
|
|
120
|
+
url: string;
|
|
121
|
+
alt: string;
|
|
122
|
+
};
|
|
123
|
+
supportLevel: "blocked" | "planned" | "development" | "uat" | "production";
|
|
124
|
+
vectorIcon: {
|
|
125
|
+
height: number;
|
|
126
|
+
width: number;
|
|
127
|
+
url: string;
|
|
128
|
+
alt: string;
|
|
129
|
+
};
|
|
130
|
+
}>;
|
|
131
|
+
/**
|
|
132
|
+
* The commands available for the device.
|
|
133
|
+
*/
|
|
134
|
+
available_commands: z.ZodArray<z.ZodObject<{
|
|
135
|
+
/**
|
|
136
|
+
* The unique identifier for the command.
|
|
137
|
+
*/
|
|
138
|
+
slug: z.ZodEffects<z.ZodString, string, string>;
|
|
139
|
+
support_level: z.ZodEnum<["planned", "development", "uat", "production", "blocked"]>;
|
|
140
|
+
}, "strip", z.ZodTypeAny, {
|
|
141
|
+
slug: string;
|
|
142
|
+
support_level: "blocked" | "planned" | "development" | "uat" | "production";
|
|
143
|
+
}, {
|
|
144
|
+
slug: string;
|
|
145
|
+
support_level: "blocked" | "planned" | "development" | "uat" | "production";
|
|
146
|
+
}>, "many">;
|
|
147
|
+
}, "strip", z.ZodTypeAny, {
|
|
148
|
+
type: "battery" | "charger" | "inverter" | "thermostat" | "vehicle";
|
|
149
|
+
name: string;
|
|
150
|
+
slug: string;
|
|
151
|
+
manufacturer: {
|
|
152
|
+
name: string;
|
|
153
|
+
slug: string;
|
|
154
|
+
logo: {
|
|
155
|
+
height: number;
|
|
156
|
+
width: number;
|
|
157
|
+
url: string;
|
|
158
|
+
alt: string;
|
|
159
|
+
};
|
|
160
|
+
icon: {
|
|
161
|
+
height: number;
|
|
162
|
+
width: number;
|
|
163
|
+
url: string;
|
|
164
|
+
alt: string;
|
|
165
|
+
};
|
|
166
|
+
supportLevel: "blocked" | "planned" | "development" | "uat" | "production";
|
|
167
|
+
vectorIcon: {
|
|
168
|
+
height: number;
|
|
169
|
+
width: number;
|
|
170
|
+
url: string;
|
|
171
|
+
alt: string;
|
|
172
|
+
};
|
|
173
|
+
};
|
|
174
|
+
available_commands: {
|
|
175
|
+
slug: string;
|
|
176
|
+
support_level: "blocked" | "planned" | "development" | "uat" | "production";
|
|
177
|
+
}[];
|
|
178
|
+
}, {
|
|
179
|
+
type: "battery" | "charger" | "inverter" | "thermostat" | "vehicle";
|
|
180
|
+
name: string;
|
|
181
|
+
slug: string;
|
|
182
|
+
manufacturer: {
|
|
183
|
+
name: string;
|
|
184
|
+
slug: string;
|
|
185
|
+
logo: {
|
|
186
|
+
height: number;
|
|
187
|
+
width: number;
|
|
188
|
+
url: string;
|
|
189
|
+
alt: string;
|
|
190
|
+
};
|
|
191
|
+
icon: {
|
|
192
|
+
height: number;
|
|
193
|
+
width: number;
|
|
194
|
+
url: string;
|
|
195
|
+
alt: string;
|
|
196
|
+
};
|
|
197
|
+
supportLevel: "blocked" | "planned" | "development" | "uat" | "production";
|
|
198
|
+
vectorIcon: {
|
|
199
|
+
height: number;
|
|
200
|
+
width: number;
|
|
201
|
+
url: string;
|
|
202
|
+
alt: string;
|
|
203
|
+
};
|
|
204
|
+
};
|
|
205
|
+
available_commands: {
|
|
206
|
+
slug: string;
|
|
207
|
+
support_level: "blocked" | "planned" | "development" | "uat" | "production";
|
|
208
|
+
}[];
|
|
209
|
+
}>;
|
|
210
|
+
export type DeviceModel = z.infer<typeof DeviceModelSchema>;
|
|
211
|
+
//# sourceMappingURL=entities.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entities.d.ts","sourceRoot":"","sources":["../../src/deviceModel/entities.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAMxB,eAAO,MAAM,sBAAsB;IACjC;;OAEG;;;;;;;;;EAGH,CAAC;AAEH,eAAO,MAAM,iBAAiB;IAC5B;;;OAGG;;IAEH;;;OAGG;;IAEH;;;OAGG;;IAEH;;OAEG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAEH;;OAEG;;QA7BH;;WAEG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA6BH,CAAC;AAEH,MAAM,MAAM,WAAW,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,iBAAiB,CAAC,CAAC"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DeviceModelSchema = exports.AvailableCommandSchema = void 0;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
const entities_1 = require("../deviceType/entities");
|
|
6
|
+
const entities_2 = require("../manufacturer/entities");
|
|
7
|
+
const supportLevel_1 = require("../common/supportLevel");
|
|
8
|
+
const utils_1 = require("../common/utils");
|
|
9
|
+
exports.AvailableCommandSchema = zod_1.z.object({
|
|
10
|
+
/**
|
|
11
|
+
* The unique identifier for the command.
|
|
12
|
+
*/
|
|
13
|
+
slug: zod_1.z.string().transform(utils_1.fromGraphQLSafeString),
|
|
14
|
+
support_level: supportLevel_1.SupportLevelEnum,
|
|
15
|
+
});
|
|
16
|
+
exports.DeviceModelSchema = zod_1.z.object({
|
|
17
|
+
/**
|
|
18
|
+
* The unique identifier for the device model.
|
|
19
|
+
* @example "tesla:panel"
|
|
20
|
+
*/
|
|
21
|
+
slug: zod_1.z.string(),
|
|
22
|
+
/**
|
|
23
|
+
* The human readable name of the manufacturer.
|
|
24
|
+
* @example "PV Panel"
|
|
25
|
+
*/
|
|
26
|
+
name: zod_1.z.string(),
|
|
27
|
+
/**
|
|
28
|
+
* The type of the device.
|
|
29
|
+
* @example "inverter"
|
|
30
|
+
*/
|
|
31
|
+
type: entities_1.DeviceTypeEnum,
|
|
32
|
+
/**
|
|
33
|
+
* The manufacturer of the device.
|
|
34
|
+
*/
|
|
35
|
+
manufacturer: entities_2.ManufacturerSchema,
|
|
36
|
+
/**
|
|
37
|
+
* The commands available for the device.
|
|
38
|
+
*/
|
|
39
|
+
available_commands: zod_1.z.array(exports.AvailableCommandSchema),
|
|
40
|
+
});
|
|
41
|
+
//# sourceMappingURL=entities.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entities.js","sourceRoot":"","sources":["../../src/deviceModel/entities.ts"],"names":[],"mappings":";;;AAAA,6BAAwB;AACxB,qDAAwD;AACxD,uDAA8D;AAC9D,yDAA0D;AAC1D,2CAAwD;AAE3C,QAAA,sBAAsB,GAAG,OAAC,CAAC,MAAM,CAAC;IAC7C;;OAEG;IACH,IAAI,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,SAAS,CAAC,6BAAqB,CAAC;IACjD,aAAa,EAAE,+BAAgB;CAChC,CAAC,CAAC;AAEU,QAAA,iBAAiB,GAAG,OAAC,CAAC,MAAM,CAAC;IACxC;;;OAGG;IACH,IAAI,EAAE,OAAC,CAAC,MAAM,EAAE;IAChB;;;OAGG;IACH,IAAI,EAAE,OAAC,CAAC,MAAM,EAAE;IAChB;;;OAGG;IACH,IAAI,EAAE,yBAAc;IACpB;;OAEG;IACH,YAAY,EAAE,6BAAkB;IAChC;;OAEG;IACH,kBAAkB,EAAE,OAAC,CAAC,KAAK,CAAC,8BAAsB,CAAC;CACpD,CAAC,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Logger } from "@texturehq/logger";
|
|
2
|
+
import { DeviceModel } from "../entities";
|
|
3
|
+
export interface GetDeviceModelOptions {
|
|
4
|
+
/**
|
|
5
|
+
* The slug of the device model to retrieve from the CMS.
|
|
6
|
+
*/
|
|
7
|
+
slug: string;
|
|
8
|
+
/**
|
|
9
|
+
* The base URL of the Payload CMS instance.
|
|
10
|
+
* @default "https://device.cms.texturehq.com"
|
|
11
|
+
*/
|
|
12
|
+
baseApiUrl?: string;
|
|
13
|
+
/**
|
|
14
|
+
* The base URL for images coming from Payload CMS.
|
|
15
|
+
* @default "https://texturehq.payloadcms.app"
|
|
16
|
+
*/
|
|
17
|
+
baseImageUrl?: string;
|
|
18
|
+
/**
|
|
19
|
+
* The logger instance to use during the getDeviceModel operation.
|
|
20
|
+
*/
|
|
21
|
+
logger?: Logger;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Retrieves a device model from the Device CMS.
|
|
25
|
+
* @param options The options to use during the getDeviceModel operation.
|
|
26
|
+
* @returns {Promise<DeviceModel | null>} The device model retrieved from the CMS or null if no device model was found.
|
|
27
|
+
*/
|
|
28
|
+
export declare const getDeviceModel: (options: GetDeviceModelOptions) => Promise<DeviceModel | null>;
|
|
29
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/deviceModel/getDeviceModel/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAI3C,OAAO,EAAE,WAAW,EAAqB,MAAM,aAAa,CAAC;AAI7D,MAAM,WAAW,qBAAqB;IACpC;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IACb;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;;OAGG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;;;GAIG;AACH,eAAO,MAAM,cAAc,YAAmB,qBAAqB,KAAG,QAAQ,WAAW,GAAG,IAAI,CAmC/F,CAAC"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.getDeviceModel = void 0;
|
|
7
|
+
const axios_1 = __importDefault(require("axios"));
|
|
8
|
+
const logger_1 = require("../../common/logger");
|
|
9
|
+
const exceptions_1 = require("../../common/exceptions");
|
|
10
|
+
const entities_1 = require("../entities");
|
|
11
|
+
const constants_1 = require("../../common/constants");
|
|
12
|
+
const manufacturer_1 = require("../../manufacturer");
|
|
13
|
+
/**
|
|
14
|
+
* Retrieves a device model from the Device CMS.
|
|
15
|
+
* @param options The options to use during the getDeviceModel operation.
|
|
16
|
+
* @returns {Promise<DeviceModel | null>} The device model retrieved from the CMS or null if no device model was found.
|
|
17
|
+
*/
|
|
18
|
+
const getDeviceModel = async (options) => {
|
|
19
|
+
const defaultLogger = logger_1.baseLogger.function("getDeviceModel");
|
|
20
|
+
const { slug, baseApiUrl = constants_1.PRODUCTION_CACHE_BASE_URL, baseImageUrl = constants_1.PRODUCTION_BASE_URL, logger = defaultLogger, } = options;
|
|
21
|
+
const operation = logger.operation("get device model from Payload CMS API");
|
|
22
|
+
try {
|
|
23
|
+
operation.start({ options });
|
|
24
|
+
const response = await axios_1.default.get(`${baseApiUrl}/api/device_models?where[slug][equals]=${slug}`);
|
|
25
|
+
if (response.status !== 200) {
|
|
26
|
+
const errorMessage = `Request to ${baseApiUrl}/api/device_models failed with status ${response.status}`;
|
|
27
|
+
operation.fail(errorMessage);
|
|
28
|
+
throw new exceptions_1.NetworkError(errorMessage, response.status);
|
|
29
|
+
}
|
|
30
|
+
if (response?.data?.docs?.length !== 1) {
|
|
31
|
+
operation.fail({ response: response.data });
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
const result = response.data.docs[0];
|
|
35
|
+
if (!result.manufacturer)
|
|
36
|
+
throw new Error(`Device (ID: ${result.id}) has no manufacturer.`);
|
|
37
|
+
const deviceModel = entities_1.DeviceModelSchema.parse({
|
|
38
|
+
...result,
|
|
39
|
+
manufacturer: (0, manufacturer_1.parseManufacturer)(result.manufacturer, baseImageUrl),
|
|
40
|
+
});
|
|
41
|
+
operation.end({ deviceModel });
|
|
42
|
+
return deviceModel;
|
|
43
|
+
}
|
|
44
|
+
catch (error) {
|
|
45
|
+
operation.fail("Unknown error occurred while fetching device model from Payload CMS API.");
|
|
46
|
+
throw error;
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
exports.getDeviceModel = getDeviceModel;
|
|
50
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/deviceModel/getDeviceModel/index.ts"],"names":[],"mappings":";;;;;;AAAA,kDAA0B;AAE1B,gDAAiD;AAEjD,wDAAuD;AACvD,0CAA6D;AAC7D,sDAAwF;AACxF,qDAAuD;AAuBvD;;;;GAIG;AACI,MAAM,cAAc,GAAG,KAAK,EAAE,OAA8B,EAA+B,EAAE;IAClG,MAAM,aAAa,GAAG,mBAAU,CAAC,QAAQ,CAAC,gBAAgB,CAAC,CAAC;IAC5D,MAAM,EACJ,IAAI,EACJ,UAAU,GAAG,qCAAyB,EACtC,YAAY,GAAG,+BAAmB,EAClC,MAAM,GAAG,aAAa,GACvB,GAAG,OAAO,CAAC;IACZ,MAAM,SAAS,GAAG,MAAM,CAAC,SAAS,CAAC,uCAAuC,CAAC,CAAC;IAE5E,IAAI,CAAC;QACH,SAAS,CAAC,KAAK,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC;QAC7B,MAAM,QAAQ,GAAG,MAAM,eAAK,CAAC,GAAG,CAAqB,GAAG,UAAU,0CAA0C,IAAI,EAAE,CAAC,CAAC;QACpH,IAAI,QAAQ,CAAC,MAAM,KAAK,GAAG,EAAE,CAAC;YAC5B,MAAM,YAAY,GAAG,cAAc,UAAU,yCAAyC,QAAQ,CAAC,MAAM,EAAE,CAAC;YACxG,SAAS,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;YAC7B,MAAM,IAAI,yBAAY,CAAC,YAAY,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC;QACxD,CAAC;QAED,IAAI,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,KAAK,CAAC,EAAE,CAAC;YACvC,SAAS,CAAC,IAAI,CAAC,EAAE,QAAQ,EAAE,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC;YAC5C,OAAO,IAAI,CAAC;QACd,CAAC;QACD,MAAM,MAAM,GAAG,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QACrC,IAAI,CAAC,MAAM,CAAC,YAAY;YAAE,MAAM,IAAI,KAAK,CAAC,eAAe,MAAM,CAAC,EAAE,wBAAwB,CAAC,CAAC;QAC5F,MAAM,WAAW,GAAG,4BAAiB,CAAC,KAAK,CAAC;YAC1C,GAAG,MAAM;YACT,YAAY,EAAE,IAAA,gCAAiB,EAAC,MAAM,CAAC,YAAY,EAAE,YAAY,CAAC;SACnE,CAAC,CAAC;QACH,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,0EAA0E,CAAC,CAAC;QAC3F,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC,CAAC;AAnCW,QAAA,cAAc,kBAmCzB"}
|