@superdurable/connector-aqara 0.1.0 → 0.2.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 +2 -0
- package/dex-connector.json +1 -1
- package/dist/{chunk-PQNVHYKW.js → chunk-SQKNBBEM.js} +57 -4
- package/dist/{connection-D6DWLUrD.d.ts → connection-BGW8j110.d.ts} +33 -10
- package/dist/index.d.ts +2 -2
- package/dist/index.js +89 -24
- package/dist/mock.d.ts +2 -1
- package/dist/mock.js +4 -3
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -5,3 +5,5 @@
|
|
|
5
5
|
Use the [runnable Flow and Worker](examples/device-list/) with a static `aqara` connection. In Dex Web Connections, create an approved project at [Aqara Developer Platform](https://developer.aqara.com), then enter its AppID, KeyID, AppKey, and authorized access token. The AppKey and token remain private and are resolved for each request. The connector signs requests using the documented [Aqara signature rules](https://opendoc.aqara.com/en/docs/developmanual/apiIntroduction/signGenerationRules.html). The endpoint, timeout, and response limit have manifest defaults.
|
|
6
6
|
|
|
7
7
|
The checked-in conformance scenarios replay Go-recorded requests, signatures, and outcomes. The integration test exercises a real Dex Worker and Client with a local provider that returns 503 before succeeding. Real Aqara authorization, token refresh, and device discovery remain unverified without a user-controlled account and approved project.
|
|
8
|
+
|
|
9
|
+
Version 0.2.0 represents integers in `Device` and `DevicePage` with `SignedInteger`. It returns safe values as numbers and preserves larger values as decimal tokens in `rawJSON`. Use `exactIntegerJSONCodec` for a receiving Step, Attribute, or client read. The example uses the codec at all three boundaries. [Flow](examples/device-list/flow.ts) · [Client](examples/device-list/start.ts)
|
package/dex-connector.json
CHANGED
|
@@ -1,6 +1,55 @@
|
|
|
1
1
|
// src/generated/models.ts
|
|
2
2
|
import { z } from "zod";
|
|
3
3
|
import { SecretString } from "@superdurable/connectors-sdk";
|
|
4
|
+
var nativeJSON = JSON;
|
|
5
|
+
var signedIntegerToken = /^-?(?:0|[1-9][0-9]*)$/;
|
|
6
|
+
var minimumSignedInteger = -(1n << 63n);
|
|
7
|
+
var maximumSignedInteger = (1n << 63n) - 1n;
|
|
8
|
+
function decodeSignedInteger(value) {
|
|
9
|
+
if (typeof value === "number" && Number.isSafeInteger(value)) return value === 0 ? 0 : value;
|
|
10
|
+
if (!nativeJSON.isRawJSON(value) || value.rawJSON.length > 20 || !signedIntegerToken.test(value.rawJSON)) {
|
|
11
|
+
throw new TypeError("expected a signed 64-bit integer");
|
|
12
|
+
}
|
|
13
|
+
const integer = BigInt(value.rawJSON);
|
|
14
|
+
if (integer < minimumSignedInteger || integer > maximumSignedInteger) throw new RangeError("signed 64-bit integer out of range");
|
|
15
|
+
const number = Number(integer);
|
|
16
|
+
return Number.isSafeInteger(number) ? number : value;
|
|
17
|
+
}
|
|
18
|
+
var signedIntegerSchema = z.unknown().transform((value, context) => {
|
|
19
|
+
try {
|
|
20
|
+
return decodeSignedInteger(value);
|
|
21
|
+
} catch {
|
|
22
|
+
context.addIssue({ code: "custom", message: "expected a signed 64-bit integer" });
|
|
23
|
+
return z.NEVER;
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
function parseJSONNumberTokens(text) {
|
|
27
|
+
return JSON.parse(text, (_key, value, context) => typeof value === "number" && context?.source !== void 0 ? nativeJSON.rawJSON(context.source) : value);
|
|
28
|
+
}
|
|
29
|
+
function parseExactIntegerJSON(text) {
|
|
30
|
+
return JSON.parse(text, (_key, field, context) => typeof field === "number" && !Number.isSafeInteger(field) && context?.source && signedIntegerToken.test(context.source) ? nativeJSON.rawJSON(context.source) : field);
|
|
31
|
+
}
|
|
32
|
+
function exactIntegerJSONCodec(decode) {
|
|
33
|
+
return {
|
|
34
|
+
typeName: "json",
|
|
35
|
+
wireKind: "json",
|
|
36
|
+
encode(value) {
|
|
37
|
+
const data = JSON.stringify(value, (_key, field) => {
|
|
38
|
+
if (typeof field === "number" && Number.isInteger(field) && !Number.isSafeInteger(field)) {
|
|
39
|
+
throw new RangeError("use a raw JSON token for integers outside the safe number range");
|
|
40
|
+
}
|
|
41
|
+
return field;
|
|
42
|
+
});
|
|
43
|
+
if (data === void 0) throw new TypeError("value cannot be encoded as JSON");
|
|
44
|
+
return { kind: "json", data };
|
|
45
|
+
},
|
|
46
|
+
decode(wire) {
|
|
47
|
+
if (wire.kind !== "json" || typeof wire.data !== "string") throw new TypeError("expected Dex JSON wire data");
|
|
48
|
+
const value = parseExactIntegerJSON(wire.data);
|
|
49
|
+
return decode ? decode(value) : value;
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
}
|
|
4
53
|
var ConfigSchema = z.object({
|
|
5
54
|
"baseUrl": z.string().optional(),
|
|
6
55
|
"timeoutMs": z.number().int().optional(),
|
|
@@ -48,7 +97,7 @@ var DeviceSchema = z.strictObject({
|
|
|
48
97
|
"deviceId": z.string(),
|
|
49
98
|
"deviceName": z.string(),
|
|
50
99
|
"model": z.string(),
|
|
51
|
-
"modelType":
|
|
100
|
+
"modelType": signedIntegerSchema,
|
|
52
101
|
"online": z.boolean(),
|
|
53
102
|
"firmwareVersion": z.string(),
|
|
54
103
|
"positionId": z.string(),
|
|
@@ -56,9 +105,9 @@ var DeviceSchema = z.strictObject({
|
|
|
56
105
|
"timeZone": z.string()
|
|
57
106
|
});
|
|
58
107
|
var DevicePageSchema = z.strictObject({
|
|
59
|
-
"totalCount":
|
|
60
|
-
"pageNum":
|
|
61
|
-
"pageSize":
|
|
108
|
+
"totalCount": signedIntegerSchema,
|
|
109
|
+
"pageNum": signedIntegerSchema,
|
|
110
|
+
"pageSize": signedIntegerSchema,
|
|
62
111
|
"devices": z.array(DeviceSchema).nullable()
|
|
63
112
|
});
|
|
64
113
|
|
|
@@ -118,6 +167,10 @@ function newProjectConnection(project, connectionName, createClient) {
|
|
|
118
167
|
}
|
|
119
168
|
|
|
120
169
|
export {
|
|
170
|
+
decodeSignedInteger,
|
|
171
|
+
parseJSONNumberTokens,
|
|
172
|
+
parseExactIntegerJSON,
|
|
173
|
+
exactIntegerJSONCodec,
|
|
121
174
|
ConfigSchema,
|
|
122
175
|
CredentialMaterialError,
|
|
123
176
|
isCredentialMaterialError,
|
|
@@ -1,6 +1,19 @@
|
|
|
1
1
|
import { SecretString, CredentialProvider, Query, ConnectionRef } from '@superdurable/connectors-sdk';
|
|
2
2
|
import { z } from 'zod';
|
|
3
|
+
import { Codec } from '@superdurable/dex';
|
|
3
4
|
|
|
5
|
+
/** A signed 64-bit JSON integer. Values outside the safe number range retain their decimal token. */
|
|
6
|
+
type SignedInteger = number | Readonly<{
|
|
7
|
+
rawJSON: string;
|
|
8
|
+
}>;
|
|
9
|
+
/** Decode one signed Go integer from a safe number or a native raw JSON number token. */
|
|
10
|
+
declare function decodeSignedInteger(value: unknown): SignedInteger;
|
|
11
|
+
/** Read provider JSON with the original syntax of every numeric token for typed field validation. */
|
|
12
|
+
declare function parseJSONNumberTokens(text: string): unknown;
|
|
13
|
+
/** Decode JSON while retaining exact decimal tokens for integers outside JavaScript's safe range. */
|
|
14
|
+
declare function parseExactIntegerJSON(text: string): unknown;
|
|
15
|
+
/** JSON-wire codec for records with signed integer fields. An optional decoder validates the application type. */
|
|
16
|
+
declare function exactIntegerJSONCodec<T>(decode?: (value: unknown) => T): Codec<T>;
|
|
4
17
|
/** Connector configuration; omitted fields use manifest defaults. */
|
|
5
18
|
interface Config {
|
|
6
19
|
/** HTTPS origin for the mainland China Aqara Cloud API. Leave blank for the displayed public endpoint; override only for a trusted test server. */
|
|
@@ -53,7 +66,7 @@ interface Device {
|
|
|
53
66
|
/** Model is Aqara's device model identifier. */
|
|
54
67
|
"model": string;
|
|
55
68
|
/** ModelType is 1 or 2 for a gateway and 3 for a child device. */
|
|
56
|
-
"modelType":
|
|
69
|
+
"modelType": SignedInteger;
|
|
57
70
|
/** Online reports the documented state value 1. */
|
|
58
71
|
"online": boolean;
|
|
59
72
|
/** FirmwareVersion is the installed firmware version if reported. */
|
|
@@ -68,11 +81,11 @@ interface Device {
|
|
|
68
81
|
/** DevicePage contains one page and the provider's total matching count. */
|
|
69
82
|
interface DevicePage {
|
|
70
83
|
/** TotalCount is the provider's total device count. */
|
|
71
|
-
"totalCount":
|
|
84
|
+
"totalCount": SignedInteger;
|
|
72
85
|
/** PageNum is the one-based page number requested. */
|
|
73
|
-
"pageNum":
|
|
86
|
+
"pageNum": SignedInteger;
|
|
74
87
|
/** PageSize is the page size requested. */
|
|
75
|
-
"pageSize":
|
|
88
|
+
"pageSize": SignedInteger;
|
|
76
89
|
/** Devices contains no more than PageSize entries. */
|
|
77
90
|
"devices": Array<Device> | null;
|
|
78
91
|
}
|
|
@@ -86,7 +99,9 @@ declare const DeviceSchema: z.ZodObject<{
|
|
|
86
99
|
deviceId: z.ZodString;
|
|
87
100
|
deviceName: z.ZodString;
|
|
88
101
|
model: z.ZodString;
|
|
89
|
-
modelType: z.
|
|
102
|
+
modelType: z.ZodPipe<z.ZodUnknown, z.ZodTransform<number | Readonly<{
|
|
103
|
+
rawJSON: string;
|
|
104
|
+
}>, unknown>>;
|
|
90
105
|
online: z.ZodBoolean;
|
|
91
106
|
firmwareVersion: z.ZodString;
|
|
92
107
|
positionId: z.ZodString;
|
|
@@ -95,14 +110,22 @@ declare const DeviceSchema: z.ZodObject<{
|
|
|
95
110
|
}, z.core.$strict>;
|
|
96
111
|
/** Runtime validator for DevicePage. */
|
|
97
112
|
declare const DevicePageSchema: z.ZodObject<{
|
|
98
|
-
totalCount: z.
|
|
99
|
-
|
|
100
|
-
|
|
113
|
+
totalCount: z.ZodPipe<z.ZodUnknown, z.ZodTransform<number | Readonly<{
|
|
114
|
+
rawJSON: string;
|
|
115
|
+
}>, unknown>>;
|
|
116
|
+
pageNum: z.ZodPipe<z.ZodUnknown, z.ZodTransform<number | Readonly<{
|
|
117
|
+
rawJSON: string;
|
|
118
|
+
}>, unknown>>;
|
|
119
|
+
pageSize: z.ZodPipe<z.ZodUnknown, z.ZodTransform<number | Readonly<{
|
|
120
|
+
rawJSON: string;
|
|
121
|
+
}>, unknown>>;
|
|
101
122
|
devices: z.ZodNullable<z.ZodArray<z.ZodObject<{
|
|
102
123
|
deviceId: z.ZodString;
|
|
103
124
|
deviceName: z.ZodString;
|
|
104
125
|
model: z.ZodString;
|
|
105
|
-
modelType: z.
|
|
126
|
+
modelType: z.ZodPipe<z.ZodUnknown, z.ZodTransform<number | Readonly<{
|
|
127
|
+
rawJSON: string;
|
|
128
|
+
}>, unknown>>;
|
|
106
129
|
online: z.ZodBoolean;
|
|
107
130
|
firmwareVersion: z.ZodString;
|
|
108
131
|
positionId: z.ZodString;
|
|
@@ -130,4 +153,4 @@ declare function newConnection(client: Operations, reference: ConnectionRef): Co
|
|
|
130
153
|
/** Bind scripted operations to a named connection. */
|
|
131
154
|
declare function newConnectionWithOperations(operations: Operations, reference: ConnectionRef): Connection;
|
|
132
155
|
|
|
133
|
-
export { Connection as C, type DevicePage as D, type ListDevicesInput as L, type Operations as O, type Credentials as a, type Config as b, ConfigSchema as c, CredentialMaterialError as d, type CredentialSource as e, type Device as f, DevicePageSchema as g, DeviceSchema as h, ListDevicesInputSchema as i, decodeCredentials as j,
|
|
156
|
+
export { Connection as C, type DevicePage as D, type ListDevicesInput as L, type Operations as O, type SignedInteger as S, type Credentials as a, type Config as b, ConfigSchema as c, CredentialMaterialError as d, type CredentialSource as e, type Device as f, DevicePageSchema as g, DeviceSchema as h, ListDevicesInputSchema as i, decodeCredentials as j, decodeSignedInteger as k, exactIntegerJSONCodec as l, isCredentialMaterialError as m, newConnection as n, newConnectionWithOperations as o, parseExactIntegerJSON as p, parseJSONNumberTokens as q };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { L as ListDevicesInput, D as DevicePage, C as Connection, O as Operations, a as Credentials, b as Config } from './connection-
|
|
2
|
-
export { c as ConfigSchema, d as CredentialMaterialError, e as CredentialSource, f as Device, g as DevicePageSchema, h as DeviceSchema, i as ListDevicesInputSchema, j as decodeCredentials, k as isCredentialMaterialError, n as newConnection,
|
|
1
|
+
import { L as ListDevicesInput, D as DevicePage, C as Connection, O as Operations, a as Credentials, b as Config } from './connection-BGW8j110.js';
|
|
2
|
+
export { c as ConfigSchema, d as CredentialMaterialError, e as CredentialSource, f as Device, g as DevicePageSchema, h as DeviceSchema, i as ListDevicesInputSchema, S as SignedInteger, j as decodeCredentials, k as decodeSignedInteger, l as exactIntegerJSONCodec, m as isCredentialMaterialError, n as newConnection, o as newConnectionWithOperations, p as parseExactIntegerJSON, q as parseJSONNumberTokens } from './connection-BGW8j110.js';
|
|
3
3
|
import { QueryDefinition, QueryStepConfig, Query, QueryResult, QueryStep, CredentialProvider, Call, QueryAttempt } from '@superdurable/connectors-sdk';
|
|
4
4
|
import { StepTarget } from '@superdurable/dex';
|
|
5
5
|
import { LoadedProject } from '@superdurable/connectors-sdk/projectconfig';
|
package/dist/index.js
CHANGED
|
@@ -15,11 +15,15 @@ import {
|
|
|
15
15
|
ListDevicesMetadata,
|
|
16
16
|
ProviderID,
|
|
17
17
|
decodeCredentials,
|
|
18
|
+
decodeSignedInteger,
|
|
19
|
+
exactIntegerJSONCodec,
|
|
18
20
|
isCredentialMaterialError,
|
|
19
21
|
newConnection,
|
|
20
22
|
newConnectionWithOperations,
|
|
21
|
-
newProjectConnection
|
|
22
|
-
|
|
23
|
+
newProjectConnection,
|
|
24
|
+
parseExactIntegerJSON,
|
|
25
|
+
parseJSONNumberTokens
|
|
26
|
+
} from "./chunk-SQKNBBEM.js";
|
|
23
27
|
|
|
24
28
|
// src/generated/steps.ts
|
|
25
29
|
import { goToBranch, newQueryStep } from "@superdurable/connectors-sdk";
|
|
@@ -43,6 +47,71 @@ import { randomBytes } from "crypto";
|
|
|
43
47
|
import { SecretString, newQueryBranch, newQueryRetry } from "@superdurable/connectors-sdk";
|
|
44
48
|
import { BodyTooLargeError, parseRetryAfter, sendProviderRequest, validateBaseURL } from "@superdurable/connectors-sdk/providerhttp";
|
|
45
49
|
|
|
50
|
+
// src/device-response.ts
|
|
51
|
+
import { parseTree } from "jsonc-parser";
|
|
52
|
+
var schemas = {
|
|
53
|
+
envelope: { code: "?int", result: "result" },
|
|
54
|
+
result: { totalcount: "int", data: "[]device" },
|
|
55
|
+
device: {
|
|
56
|
+
did: "string",
|
|
57
|
+
parentdid: "string",
|
|
58
|
+
positionid: "string",
|
|
59
|
+
model: "string",
|
|
60
|
+
modeltype: "int",
|
|
61
|
+
state: "?int",
|
|
62
|
+
firmwareversion: "string",
|
|
63
|
+
devicename: "string",
|
|
64
|
+
timezone: "string"
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
function fold(name) {
|
|
68
|
+
return name.replace(/[A-ZſK]/g, (c) => c === "\u017F" ? "s" : c === "\u212A" ? "k" : c.toLowerCase());
|
|
69
|
+
}
|
|
70
|
+
function members(node) {
|
|
71
|
+
if (node.type === "null") return [];
|
|
72
|
+
if (node.type !== "object") throw new TypeError("invalid Aqara object");
|
|
73
|
+
return (node.children ?? []).map((property) => {
|
|
74
|
+
const [key, value] = property.children ?? [];
|
|
75
|
+
if (typeof key?.value !== "string" || !value) throw new TypeError("invalid Aqara field");
|
|
76
|
+
return [fold(key.value), value];
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
function deviceResponse(body) {
|
|
80
|
+
const text = Buffer.from(body).toString("utf8");
|
|
81
|
+
const errors = [];
|
|
82
|
+
const root = parseTree(text, errors, { disallowComments: true, allowTrailingComma: false });
|
|
83
|
+
if (!root || errors.length) throw new TypeError("invalid Aqara JSON");
|
|
84
|
+
return readFields(text, "envelope", root, {});
|
|
85
|
+
}
|
|
86
|
+
function readFields(text, shape, node, record) {
|
|
87
|
+
const schema = schemas[shape];
|
|
88
|
+
for (const [key, member] of members(node)) {
|
|
89
|
+
if (Object.hasOwn(schema, key)) record[key] = readValue(text, schema[key], member, record[key]);
|
|
90
|
+
}
|
|
91
|
+
return record;
|
|
92
|
+
}
|
|
93
|
+
function readValue(text, shape, node, previous) {
|
|
94
|
+
if (shape.startsWith("?"))
|
|
95
|
+
return node.type === "null" ? null : readValue(text, shape.slice(1), node, previous);
|
|
96
|
+
if (shape.startsWith("[]")) {
|
|
97
|
+
if (node.type === "null") return null;
|
|
98
|
+
if (node.type !== "array") throw new TypeError("invalid Aqara array");
|
|
99
|
+
return (node.children ?? []).map(
|
|
100
|
+
(item, index) => readValue(text, shape.slice(2), item, Array.isArray(previous) ? previous[index] : void 0)
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
if (node.type === "null") return previous;
|
|
104
|
+
if (shape === "int") {
|
|
105
|
+
if (node.type !== "number") throw new TypeError("invalid Aqara integer");
|
|
106
|
+
return decodeSignedInteger(parseJSONNumberTokens(text.slice(node.offset, node.offset + node.length)));
|
|
107
|
+
}
|
|
108
|
+
if (shape === "string") {
|
|
109
|
+
if (typeof node.value !== "string") throw new TypeError("invalid Aqara string");
|
|
110
|
+
return Buffer.from(node.value).toString();
|
|
111
|
+
}
|
|
112
|
+
return readFields(text, shape, node, previous ?? {});
|
|
113
|
+
}
|
|
114
|
+
|
|
46
115
|
// src/signature.ts
|
|
47
116
|
import { createHash } from "crypto";
|
|
48
117
|
function signDeviceRequest(accessToken, appId, keyId, nonce, timestamp, appKey) {
|
|
@@ -112,7 +181,7 @@ var ListDevicesOperation = class {
|
|
|
112
181
|
return retry("AVAILABILITY", "secure nonce generation failed");
|
|
113
182
|
}
|
|
114
183
|
const timestamp = String(this.client.clock().getTime());
|
|
115
|
-
if (
|
|
184
|
+
if (!/^-?\d+$/.test(timestamp)) return branch("defect", "VALIDATION", "device request is invalid");
|
|
116
185
|
const body = Buffer.from(JSON.stringify({ intent: "query.device.info", data: { pageNum, pageSize } }), "utf8");
|
|
117
186
|
let response;
|
|
118
187
|
try {
|
|
@@ -151,30 +220,30 @@ var ListDevicesOperation = class {
|
|
|
151
220
|
}
|
|
152
221
|
let document;
|
|
153
222
|
try {
|
|
154
|
-
document =
|
|
223
|
+
document = deviceResponse(response.body);
|
|
155
224
|
} catch {
|
|
156
225
|
return branch("invalidResponse", "PROTOCOL", "Aqara returned an invalid device response");
|
|
157
226
|
}
|
|
158
|
-
if (!isRecord(document) ||
|
|
227
|
+
if (!isRecord(document) || document.code == null) return branch("invalidResponse", "PROTOCOL", "Aqara returned an invalid device response");
|
|
159
228
|
const code = document.code;
|
|
160
229
|
if (code !== 0) return classifyProviderCode(code, retryAfter(response.headers));
|
|
161
230
|
const result = document.result;
|
|
162
231
|
if (!isRecord(result) || !Array.isArray(result.data)) return branch("invalidResponse", "PROTOCOL", "Aqara returned an invalid device response");
|
|
163
|
-
const totalCount = result.
|
|
164
|
-
if (
|
|
232
|
+
const totalCount = result.totalcount ?? 0;
|
|
233
|
+
if (BigInt(typeof totalCount === "number" ? totalCount : totalCount.rawJSON) < 0n || result.data.length > pageSize) return branch("invalidResponse", "PROTOCOL", "Aqara returned an invalid device count");
|
|
165
234
|
const devices = [];
|
|
166
235
|
for (const row of result.data) {
|
|
167
|
-
if (!isRecord(row) || typeof row.did !== "string" || !row.did || typeof row.model !== "string" || !row.model ||
|
|
236
|
+
if (!isRecord(row) || typeof row.did !== "string" || !row.did || typeof row.model !== "string" || !row.model || row.state !== 0 && row.state !== 1) return branch("invalidResponse", "PROTOCOL", "Aqara returned an invalid device response");
|
|
168
237
|
devices.push({
|
|
169
238
|
deviceId: row.did,
|
|
170
|
-
deviceName: optionalString(row.
|
|
239
|
+
deviceName: optionalString(row.devicename),
|
|
171
240
|
model: row.model,
|
|
172
|
-
modelType:
|
|
241
|
+
modelType: row.modeltype ?? 0,
|
|
173
242
|
online: row.state === 1,
|
|
174
|
-
firmwareVersion: optionalString(row.
|
|
175
|
-
positionId: optionalString(row.
|
|
176
|
-
parentDeviceId: optionalString(row.
|
|
177
|
-
timeZone: optionalString(row.
|
|
243
|
+
firmwareVersion: optionalString(row.firmwareversion),
|
|
244
|
+
positionId: optionalString(row.positionid),
|
|
245
|
+
parentDeviceId: optionalString(row.parentdid),
|
|
246
|
+
timeZone: optionalString(row.timezone)
|
|
178
247
|
});
|
|
179
248
|
}
|
|
180
249
|
return newQueryBranch("listed", { totalCount, pageNum, pageSize, devices });
|
|
@@ -187,6 +256,7 @@ function classifyEarlyStatus(status, headers) {
|
|
|
187
256
|
return void 0;
|
|
188
257
|
}
|
|
189
258
|
function classifyProviderCode(code, delay) {
|
|
259
|
+
if (typeof code !== "number") return branch("providerRejected", "PROVIDER_REJECTION", `Aqara rejected the query with code ${code.rawJSON}`);
|
|
190
260
|
if (code === 429) return retry("RATE_LIMIT", "Aqara rate limited the request", delay);
|
|
191
261
|
if ([100, 104, 500, 501].includes(code)) return retry("AVAILABILITY", "Aqara is temporarily unavailable", delay);
|
|
192
262
|
const kind = [106, 107, 108, 109, 804, 2002, 2004, 2005].includes(code) ? "AUTHENTICATION" : [403, 603, 706, 717, 755, 756, 803, 2008, 2010, 2013, 2014].includes(code) ? "AUTHORIZATION" : [101, 102, 103, 105, 302, 303, 304, 305, 306, 604].includes(code) ? "VALIDATION" : "PROVIDER_REJECTION";
|
|
@@ -199,15 +269,6 @@ function retryAfter(headers) {
|
|
|
199
269
|
function optionalString(value) {
|
|
200
270
|
return typeof value === "string" ? value : "";
|
|
201
271
|
}
|
|
202
|
-
function optionalInteger(value) {
|
|
203
|
-
return Number.isSafeInteger(value) ? value : 0;
|
|
204
|
-
}
|
|
205
|
-
function isOptionalString(value) {
|
|
206
|
-
return value === void 0 || value === null || typeof value === "string";
|
|
207
|
-
}
|
|
208
|
-
function isOptionalInteger(value) {
|
|
209
|
-
return value === void 0 || value === null || Number.isSafeInteger(value);
|
|
210
|
-
}
|
|
211
272
|
function isRecord(value) {
|
|
212
273
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
213
274
|
}
|
|
@@ -278,9 +339,13 @@ export {
|
|
|
278
339
|
ListDevicesOperation,
|
|
279
340
|
ProviderID,
|
|
280
341
|
decodeCredentials,
|
|
342
|
+
decodeSignedInteger,
|
|
343
|
+
exactIntegerJSONCodec,
|
|
281
344
|
isCredentialMaterialError,
|
|
282
345
|
newConnection,
|
|
283
346
|
newConnectionWithOperations,
|
|
284
347
|
newListDevicesStep,
|
|
285
|
-
newProjectConnection2 as newProjectConnection
|
|
348
|
+
newProjectConnection2 as newProjectConnection,
|
|
349
|
+
parseExactIntegerJSON,
|
|
350
|
+
parseJSONNumberTokens
|
|
286
351
|
};
|
package/dist/mock.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { MockQuery, Case } from '@superdurable/connectors-sdk/connectormock';
|
|
2
2
|
import { Failure } from '@superdurable/connectors-sdk';
|
|
3
|
-
import { O as Operations, C as Connection, L as ListDevicesInput, D as DevicePage, f as Device } from './connection-
|
|
3
|
+
import { O as Operations, C as Connection, L as ListDevicesInput, D as DevicePage, f as Device } from './connection-BGW8j110.js';
|
|
4
4
|
import 'zod';
|
|
5
|
+
import '@superdurable/dex';
|
|
5
6
|
|
|
6
7
|
/** Go zero value for ListDevicesInput in scripted cases. */
|
|
7
8
|
declare const emptyListDevicesInput: ListDevicesInput;
|
package/dist/mock.js
CHANGED
|
@@ -4,8 +4,9 @@ import {
|
|
|
4
4
|
ListDevicesDefinition,
|
|
5
5
|
ListDevicesInputSchema,
|
|
6
6
|
ProviderID,
|
|
7
|
-
newConnectionWithOperations
|
|
8
|
-
|
|
7
|
+
newConnectionWithOperations,
|
|
8
|
+
parseExactIntegerJSON
|
|
9
|
+
} from "./chunk-SQKNBBEM.js";
|
|
9
10
|
|
|
10
11
|
// src/generated/mock.ts
|
|
11
12
|
import { branchCase, retryCase, newQuery } from "@superdurable/connectors-sdk/connectormock";
|
|
@@ -46,7 +47,7 @@ function listDevicesRetry(failure, retryAfterMs = 0) {
|
|
|
46
47
|
return retryCase(failure, retryAfterMs);
|
|
47
48
|
}
|
|
48
49
|
function listDevicesListedDevices() {
|
|
49
|
-
const value = DevicePageSchema.parse({
|
|
50
|
+
const value = DevicePageSchema.parse(parseExactIntegerJSON('{"devices":[{"deviceId":"lumi.07737309957642","deviceName":"Aqara Hub","firmwareVersion":"3.2.6","model":"lumi.gateway.aqhm01","modelType":1,"online":true,"parentDeviceId":"","positionId":"real2.730432352746111072","timeZone":"GMT+08:00"}],"pageNum":1,"pageSize":50,"totalCount":1}'));
|
|
50
51
|
return branchCase("listed", value);
|
|
51
52
|
}
|
|
52
53
|
function listDevicesDefault() {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@superdurable/connector-aqara",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "Aqara device catalog connector for Dex TypeScript applications",
|
|
6
6
|
"repository": {
|
|
@@ -45,7 +45,8 @@
|
|
|
45
45
|
"dependencies": {
|
|
46
46
|
"@superdurable/connectors-sdk": "0.11.0",
|
|
47
47
|
"@superdurable/dex": ">=1.28.0",
|
|
48
|
-
"zod": "^4.1.0"
|
|
48
|
+
"zod": "^4.1.0",
|
|
49
|
+
"jsonc-parser": "^3.3.1"
|
|
49
50
|
},
|
|
50
51
|
"devDependencies": {
|
|
51
52
|
"@eslint/js": "^9.0.0",
|