@superdurable/connector-chuanglan 0.1.0 → 0.1.1
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/index.js +17 -10
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -7,3 +7,5 @@ Create a Dex Web connection named `chuanglan`. Open <https://zz.253.com>, then *
|
|
|
7
7
|
A successful provider `code` of numeric or string `0` selects `fetched` with a nonnegative count. A definite provider rejection selects the optional `providerRejected` branch. Malformed or oversized responses select `invalidResponse`; missing credentials select `defect` without a request. HTTP 408, 429, 5xx, and transport errors Retry through Dex. Unwired optional branches fail the Flow.
|
|
8
8
|
|
|
9
9
|
[Run the balance Flow](examples/balance/README.md). Its real Dex integration test exercises a provider 503 followed by success and verifies persistence. Eleven Go-recorded [conformance scenarios](../../../conformance/connectors/chuanglan/scenarios.json) check exact requests and outcomes. A real Chuanglan account and live balance lookup have not been verified.
|
|
10
|
+
|
|
11
|
+
The TypeScript `remainingMessages` field uses a JavaScript number. Counts above `Number.MAX_SAFE_INTEGER` select `invalidResponse` to prevent rounding.
|
package/dex-connector.json
CHANGED
package/dist/index.js
CHANGED
|
@@ -119,23 +119,30 @@ var GetBalanceOperation = class {
|
|
|
119
119
|
if (response.status !== 200) return terminal("providerRejected", httpFailureKind(response.status), "Chuanglan rejected the balance lookup");
|
|
120
120
|
let wire;
|
|
121
121
|
try {
|
|
122
|
-
wire = JSON.parse(
|
|
122
|
+
wire = JSON.parse(Buffer.from(response.body).toString("utf8"), (name, value, context) => {
|
|
123
|
+
if (name.toLowerCase() === "code") return context?.source?.replace(/^"+|"+$/g, "");
|
|
124
|
+
if (value && typeof value === "object" && !Array.isArray(value)) return Object.fromEntries(Object.entries(value).map(([key, field]) => [key.toLowerCase(), field]));
|
|
125
|
+
return value;
|
|
126
|
+
});
|
|
123
127
|
} catch {
|
|
124
128
|
return terminal("invalidResponse", "PROTOCOL", "Chuanglan returned an invalid balance response");
|
|
125
129
|
}
|
|
126
|
-
if (!wire || typeof wire !== "object" || Array.isArray(wire)) return terminal("invalidResponse", "PROTOCOL", "
|
|
130
|
+
if (!wire || typeof wire !== "object" || Array.isArray(wire)) return terminal("invalidResponse", "PROTOCOL", "Invalid balance envelope");
|
|
127
131
|
const fields = wire;
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
if (
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
const remainingMessages = Number(balance);
|
|
135
|
-
if (!Number.isSafeInteger(remainingMessages) || remainingMessages < 0) return terminal("invalidResponse", "PROTOCOL", "Chuanglan returned an invalid remaining-message count");
|
|
132
|
+
const code = parseCount(fields.code);
|
|
133
|
+
if (code === void 0 || fields.balance != null && typeof fields.balance !== "string") return terminal("invalidResponse", "PROTOCOL", "Invalid Chuanglan response fields");
|
|
134
|
+
if (fields.code !== "0") return terminal("providerRejected", "PROVIDER_REJECTION", "Chuanglan rejected the balance lookup");
|
|
135
|
+
const count = parseCount(fields.balance);
|
|
136
|
+
if (count === void 0 || count < 0n || count > BigInt(Number.MAX_SAFE_INTEGER)) return terminal("invalidResponse", "PROTOCOL", "Invalid remaining-message count");
|
|
137
|
+
const remainingMessages = Number(count);
|
|
136
138
|
return newQueryBranch("fetched", { remainingMessages });
|
|
137
139
|
}
|
|
138
140
|
};
|
|
141
|
+
function parseCount(value) {
|
|
142
|
+
if (typeof value !== "string" || !/^[+-]?[0-9]+$/.test(value)) return void 0;
|
|
143
|
+
const count = BigInt(value);
|
|
144
|
+
return count >= -(1n << 63n) && count < 1n << 63n ? count : void 0;
|
|
145
|
+
}
|
|
139
146
|
function validCredential(value) {
|
|
140
147
|
return value.length > 0 && value.length <= 512 && /^[!-~]+$/.test(value);
|
|
141
148
|
}
|