@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.
- package/dex-connector.json +1 -1
- package/dist/index.js +31 -17
- package/package.json +1 -1
package/dex-connector.json
CHANGED
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
|
|
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
|
-
|
|
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(
|
|
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
|
|
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
|
-
|
|
176
|
-
|
|
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
|
|
188
|
-
|
|
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);
|