@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 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.
@@ -4,7 +4,7 @@
4
4
  "package": {
5
5
  "ecosystem": "npm",
6
6
  "name": "@superdurable/connector-chuanglan",
7
- "version": "0.1.0"
7
+ "version": "0.1.1"
8
8
  },
9
9
  "factories": [
10
10
  {
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(new TextDecoder("utf-8", { fatal: true }).decode(response.body));
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", "Chuanglan returned an invalid balance response");
130
+ if (!wire || typeof wire !== "object" || Array.isArray(wire)) return terminal("invalidResponse", "PROTOCOL", "Invalid balance envelope");
127
131
  const fields = wire;
128
- if (fields.code === void 0 || fields.code === null) return terminal("invalidResponse", "PROTOCOL", "Chuanglan returned an invalid balance response");
129
- const code = fields.code;
130
- if (!(typeof code === "string" || typeof code === "number") || !/^-?\d+$/.test(String(code))) return terminal("invalidResponse", "PROTOCOL", "Chuanglan returned an invalid status code");
131
- if (String(code) !== "0") return terminal("providerRejected", "PROVIDER_REJECTION", "Chuanglan rejected the balance lookup");
132
- const balance = fields.balance;
133
- if (typeof balance !== "string" || !/^\d+$/.test(balance)) return terminal("invalidResponse", "PROTOCOL", "Chuanglan returned an invalid remaining-message count");
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
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@superdurable/connector-chuanglan",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "license": "MIT",
5
5
  "description": "Chuanglan 253 SMS balance connector for Dex TypeScript applications",
6
6
  "repository": {