@superdurable/connector-alibaba 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.
@@ -4,7 +4,7 @@
4
4
  "package": {
5
5
  "ecosystem": "npm",
6
6
  "name": "@superdurable/connector-alibaba",
7
- "version": "0.1.0"
7
+ "version": "0.1.1"
8
8
  },
9
9
  "factories": [
10
10
  {
package/dist/index.js CHANGED
@@ -149,7 +149,7 @@ var DescribeRegionsOperation = class {
149
149
  },
150
150
  maxResponseBytes: this.client.maxResponseBytes,
151
151
  timeoutMs: this.client.timeoutMs,
152
- addressPolicy: this.client.baseUrl === "https://ecs.cn-hangzhou.aliyuncs.com" ? "publicHTTPS" : "privateNetworkHTTP",
152
+ addressPolicy: this.client.baseUrl.startsWith("http://") ? "privateNetworkHTTP" : "publicHTTPS",
153
153
  signal: call.context.cancellationSignal
154
154
  });
155
155
  } catch (error) {
@@ -158,34 +158,48 @@ var DescribeRegionsOperation = class {
158
158
  if (response.status !== 429 && response.status !== 408 && response.status < 500) return branch("invalidResponse", "RESPONSE_TOO_LARGE", "ECS response exceeded the configured limit");
159
159
  } else return retry("AVAILABILITY", "ECS request failed");
160
160
  }
161
- const retryAfterHeader = response.headers["retry-after"];
161
+ const retryAfterHeader = Object.entries(response.headers).find(([name]) => name.toLowerCase() === "retry-after")?.[1];
162
162
  const retryAfterMs = parseRetryAfter(Array.isArray(retryAfterHeader) ? retryAfterHeader[0] ?? "" : retryAfterHeader ?? "");
163
163
  if (response.status === 429) return retry("RATE_LIMIT", "ECS rate limited the request", retryAfterMs);
164
164
  if (response.status === 408 || response.status >= 500) return retry("AVAILABILITY", "ECS is temporarily unavailable", retryAfterMs);
165
- let document;
165
+ if (response.body.length > this.client.maxResponseBytes) return branch("invalidResponse", "RESPONSE_TOO_LARGE", "ECS response exceeded the configured limit");
166
+ let code;
167
+ let entries;
168
+ const regions = [];
166
169
  try {
167
- document = JSON.parse(new TextDecoder("utf-8", { fatal: true }).decode(response.body));
170
+ const document = objectFields(JSON.parse(new TextDecoder().decode(response.body)));
171
+ code = textField(document.code);
172
+ entries = objectFields(document.regions).region;
173
+ if (entries != null && !Array.isArray(entries)) throw new TypeError("Invalid ECS region list");
174
+ for (const entry of entries ?? []) {
175
+ const region = objectFields(entry);
176
+ regions.push({
177
+ regionId: textField(region.regionid),
178
+ localName: textField(region.localname),
179
+ endpoint: textField(region.regionendpoint),
180
+ status: textField(region.status)
181
+ });
182
+ }
168
183
  } catch {
169
- return branch("invalidResponse", "PROTOCOL", "ECS returned invalid JSON");
184
+ return branch("invalidResponse", "PROTOCOL", "ECS returned an invalid region list");
170
185
  }
171
- if (!isRecord(document) || document.Code !== void 0 && document.Code !== null && typeof document.Code !== "string") return branch("invalidResponse", "PROTOCOL", "ECS returned invalid JSON");
172
- const code = typeof document.Code === "string" ? document.Code : "";
173
186
  if (code.startsWith("Throttling")) return retry("RATE_LIMIT", "ECS rate limited the request", retryAfterMs);
174
187
  if (code || response.status !== 200) return branch("providerRejected", "PROVIDER_REJECTION", "ECS rejected the regions request");
175
- const regionsValue = document.Regions;
176
- if (!isRecord(regionsValue) || !Array.isArray(regionsValue.Region)) return branch("invalidResponse", "PROTOCOL", "ECS omitted its regions list");
177
- const regions = [];
178
- for (const row of regionsValue.Region) {
179
- if (!isRecord(row) || typeof row.RegionId !== "string" || !row.RegionId || typeof row.LocalName !== "string" || !row.LocalName || typeof row.RegionEndpoint !== "string" || !row.RegionEndpoint || row.Status !== "available" && row.Status !== "soldOut") {
180
- return branch("invalidResponse", "PROTOCOL", "ECS returned an incomplete region");
181
- }
182
- regions.push({ regionId: row.RegionId, localName: row.LocalName, endpoint: row.RegionEndpoint, status: row.Status });
188
+ if (!Array.isArray(entries) || regions.some((region) => !region.regionId || !region.localName || !region.endpoint || !["available", "soldOut"].includes(region.status))) {
189
+ return branch("invalidResponse", "PROTOCOL", "ECS returned an incomplete region list");
183
190
  }
184
191
  return newQueryBranch("fetched", { regions });
185
192
  }
186
193
  };
187
- function isRecord(value) {
188
- return typeof value === "object" && value !== null && !Array.isArray(value);
194
+ function objectFields(value) {
195
+ if (value == null) return {};
196
+ if (typeof value !== "object" || Array.isArray(value)) throw new TypeError("Invalid ECS object");
197
+ return Object.fromEntries(Object.entries(value).map(([name, field]) => [name.toLowerCase(), field]));
198
+ }
199
+ function textField(value) {
200
+ if (value == null) return "";
201
+ if (typeof value !== "string") throw new TypeError("Invalid ECS string");
202
+ return value;
189
203
  }
190
204
  function isValidCredential(value) {
191
205
  return /^[!-~]{1,512}$/.test(value);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@superdurable/connector-alibaba",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "license": "MIT",
5
5
  "description": "Alibaba Cloud ECS connector for Dex TypeScript applications",
6
6
  "repository": {