@gusto/baerly-storage 0.5.0 → 0.6.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/dist/API.md +3 -2
- package/dist/CHANGELOG.md +82 -0
- package/dist/THIRD-PARTY-LICENSES.txt +1 -1
- package/dist/auth.d.ts +1 -1
- package/dist/aws4fetch.esm-CXE5ZbAa.js +460 -0
- package/dist/aws4fetch.esm-CXE5ZbAa.js.map +1 -0
- package/dist/baerly.js +10 -10
- package/dist/baerly.spec.json +1 -1
- package/dist/client-react.d.ts +2 -2
- package/dist/{client-Fe8CwB73.d.ts → client-ypCm3zjt.d.ts} +2 -2
- package/dist/client.d.ts +2 -2
- package/dist/{cloudflare-DzKBrUlg.js → cloudflare-wrVYf4bb.js} +457 -56
- package/dist/cloudflare-wrVYf4bb.js.map +1 -0
- package/dist/cloudflare.d.ts +3 -3
- package/dist/cloudflare.js +5 -5
- package/dist/{config-1tv0-Yzm.js → config-B6nTy8e2.js} +435 -33
- package/dist/config-B6nTy8e2.js.map +1 -0
- package/dist/constants-CfeMWQWk.js.map +1 -1
- package/dist/{cost-DSMIVqzL.js → cost-_SE_SVgZ.js} +4 -4
- package/dist/{cost-DSMIVqzL.js.map → cost-_SE_SVgZ.js.map} +1 -1
- package/dist/{db-DsPkOVEH.d.ts → db-DjjthkTi.d.ts} +2 -2
- package/dist/{deploy-DonTr-CV.js → deploy-Di_Q01qx.js} +5 -5
- package/dist/deploy-Di_Q01qx.js.map +1 -0
- package/dist/dev-vite.d.ts +31 -27
- package/dist/dev-vite.js +60 -30
- package/dist/dev-vite.js.map +1 -1
- package/dist/dev.d.ts +1 -1
- package/dist/doctor-RWVRpvat.js +102 -0
- package/dist/doctor-RWVRpvat.js.map +1 -0
- package/dist/{dump-Bh5k26VQ.js → dump-m2vEYDNY.js} +4 -4
- package/dist/{dump-Bh5k26VQ.js.map → dump-m2vEYDNY.js.map} +1 -1
- package/dist/{export-DtF5tDIM.js → export-DenKwEQu.js} +4 -4
- package/dist/{export-DtF5tDIM.js.map → export-DenKwEQu.js.map} +1 -1
- package/dist/{fsck-D_djMO5D.js → fsck-2Vq-7-e2.js} +5 -5
- package/dist/{fsck-D_djMO5D.js.map → fsck-2Vq-7-e2.js.map} +1 -1
- package/dist/gcs-admin-Bx6xSNJj.d.ts +123 -0
- package/dist/gcs.d.ts +18 -0
- package/dist/gcs.js +2 -0
- package/dist/goog4-signer-Z7KnJ1su.js +321 -0
- package/dist/goog4-signer-Z7KnJ1su.js.map +1 -0
- package/dist/{http-DGd5tbNs.js → http-7zT29K3P.js} +4 -4
- package/dist/{http-DGd5tbNs.js.map → http-7zT29K3P.js.map} +1 -1
- package/dist/{aws4fetch.esm-p7eEzLCs.js → http-transport-BTgVCY5r.js} +24 -476
- package/dist/http-transport-BTgVCY5r.js.map +1 -0
- package/dist/http.d.ts +2 -2
- package/dist/http.js +2 -2
- package/dist/{index-BNRh23K9.d.ts → index-BHz92Acj.d.ts} +2 -2
- package/dist/{index-BYk9oCNf.d.ts → index-CEZKQsKt.d.ts} +3 -2
- package/dist/{index-CuA9Mi3K.d.ts → index-DP3ClvcA.d.ts} +7 -7
- package/dist/{index-0rZcMBwy.d.ts → index-uE-w2dgj.d.ts} +2 -2
- package/dist/index.d.ts +3 -3
- package/dist/index.js +3 -3
- package/dist/{inspect-6WZ-pC7-.js → inspect-BpYbH1DM.js} +5 -5
- package/dist/{inspect-6WZ-pC7-.js.map → inspect-BpYbH1DM.js.map} +1 -1
- package/dist/{log-tail-D98U1JBo.js → log-tail-QWU4wlu-.js} +3 -11
- package/dist/log-tail-QWU4wlu-.js.map +1 -0
- package/dist/{maintenance-B_e0T99L.d.ts → maintenance-BGHGt2Yg.d.ts} +2 -2
- package/dist/{maintenance-B4Dki6Ig.js → maintenance-DULFcpd1.js} +4 -17
- package/dist/maintenance-DULFcpd1.js.map +1 -0
- package/dist/{maintenance-C7coQp4c.js → maintenance-fEi-UZ2o.js} +5 -11
- package/dist/maintenance-fEi-UZ2o.js.map +1 -0
- package/dist/maintenance.d.ts +1 -1
- package/dist/maintenance.js +1 -1
- package/dist/node.d.ts +21 -60
- package/dist/node.js +4 -3
- package/dist/{observability-BmflLCdF.js → observability-Ch-VQJyE.js} +38 -16
- package/dist/{observability-BmflLCdF.js.map → observability-Ch-VQJyE.js.map} +1 -1
- package/dist/observability.d.ts +2 -2
- package/dist/observability.js +1 -1
- package/dist/{plan-a7PJHBCy.js → plan-C4qgiXSg.js} +2 -2
- package/dist/{plan-a7PJHBCy.js.map → plan-C4qgiXSg.js.map} +1 -1
- package/dist/{query-rAtXNQQB.js → query-C43r-6ib.js} +2 -2
- package/dist/{query-rAtXNQQB.js.map → query-C43r-6ib.js.map} +1 -1
- package/dist/{rebuild-index-BVzQSZlm.js → rebuild-index-BH1dc1p6.js} +4 -4
- package/dist/{rebuild-index-BVzQSZlm.js.map → rebuild-index-BH1dc1p6.js.map} +1 -1
- package/dist/{restore-R-4rbciV.js → restore-D0VYWzfP.js} +5 -5
- package/dist/{restore-R-4rbciV.js.map → restore-D0VYWzfP.js.map} +1 -1
- package/dist/{runtime-spec-Dsw2-n8S.js → runtime-spec--LykAdl1.js} +2 -2
- package/dist/{runtime-spec-Dsw2-n8S.js.map → runtime-spec--LykAdl1.js.map} +1 -1
- package/dist/{s3-http-B-z8th6O.d.ts → s3-http-DD5gDc7t.d.ts} +6 -4
- package/dist/s3.d.ts +1 -1
- package/dist/s3.js +1 -1
- package/dist/sha256-CqcKTjw9.js +22 -0
- package/dist/sha256-CqcKTjw9.js.map +1 -0
- package/dist/{src-BL_JoPTn.js → src-BMFfDUI2.js} +68 -28
- package/dist/{src-BL_JoPTn.js.map → src-BMFfDUI2.js.map} +1 -1
- package/dist/{src-CYHFDrKz.js → src-DvbTEya2.js} +3 -3
- package/dist/{src-CYHFDrKz.js.map → src-DvbTEya2.js.map} +1 -1
- package/dist/{subcommand-DoDA-K7d.js → subcommand-BV68pqwJ.js} +2 -2
- package/dist/{subcommand-DoDA-K7d.js.map → subcommand-BV68pqwJ.js.map} +1 -1
- package/dist/{usage-DBV1eQHC.js → usage-BMZR8o6U.js} +3 -3
- package/dist/{usage-DBV1eQHC.js.map → usage-BMZR8o6U.js.map} +1 -1
- package/package.json +10 -4
- package/dist/aws4fetch.esm-p7eEzLCs.js.map +0 -1
- package/dist/cloudflare-DzKBrUlg.js.map +0 -1
- package/dist/config-1tv0-Yzm.js.map +0 -1
- package/dist/deploy-DonTr-CV.js.map +0 -1
- package/dist/doctor-DSIyCDg_.js +0 -346
- package/dist/doctor-DSIyCDg_.js.map +0 -1
- package/dist/log-tail-D98U1JBo.js.map +0 -1
- package/dist/maintenance-B4Dki6Ig.js.map +0 -1
- package/dist/maintenance-C7coQp4c.js.map +0 -1
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import { t as __commonJSMin } from "./rolldown-runtime-EAsCxrDo.js";
|
|
2
|
-
import { g as RATE_LIMIT_BACKOFF_MILLIS } from "./constants-CfeMWQWk.js";
|
|
3
2
|
import { t as BaerlyError } from "./errors-Dfa3p78c.js";
|
|
4
|
-
import { t as assertValidStorageKey } from "./key-Di6yyxFu.js";
|
|
5
3
|
import { t as delay } from "./time-DUqvFMHq.js";
|
|
6
4
|
/*! @rgrove/parse-xml v4.2.1 | ISC License | Copyright Ryan Grove */
|
|
7
5
|
//#endregion
|
|
@@ -1141,14 +1139,15 @@ const parseListObjectsV2CommandOutput = (xml) => {
|
|
|
1141
1139
|
return {
|
|
1142
1140
|
ETag: rawXmlVal(contentEl, "ETag"),
|
|
1143
1141
|
Key: xmlVal(contentEl, "Key"),
|
|
1144
|
-
LastModified: parseLastModified(rawXmlVal(contentEl, "LastModified"))
|
|
1142
|
+
LastModified: parseLastModified(rawXmlVal(contentEl, "LastModified")),
|
|
1143
|
+
Generation: rawXmlVal(contentEl, "Generation")
|
|
1145
1144
|
};
|
|
1146
1145
|
}),
|
|
1147
1146
|
NextContinuationToken: rawXmlVal(root, "NextContinuationToken")
|
|
1148
1147
|
};
|
|
1149
1148
|
};
|
|
1150
1149
|
//#endregion
|
|
1151
|
-
//#region packages/adapter-node/src/
|
|
1150
|
+
//#region packages/adapter-node/src/http-transport.ts
|
|
1152
1151
|
/**
|
|
1153
1152
|
* Permanent {@link BaerlyError} codes that must short-circuit `retry`.
|
|
1154
1153
|
* These represent caller- or environment-level faults where retrying
|
|
@@ -1200,7 +1199,7 @@ const retryAfterCause = (res) => {
|
|
|
1200
1199
|
const hint = parseRetryAfter(res.headers.get("Retry-After"));
|
|
1201
1200
|
return hint !== void 0 ? { retryAfterSeconds: hint } : {};
|
|
1202
1201
|
};
|
|
1203
|
-
const
|
|
1202
|
+
const xmlErrorDetail = (status, body) => {
|
|
1204
1203
|
const parsed = parseS3Error(body);
|
|
1205
1204
|
if (parsed !== void 0) {
|
|
1206
1205
|
const code = parsed.Code ?? "UnknownError";
|
|
@@ -1208,6 +1207,23 @@ const s3ErrorDetail = (status, body) => {
|
|
|
1208
1207
|
}
|
|
1209
1208
|
return `${status} ${body}`;
|
|
1210
1209
|
};
|
|
1210
|
+
/**
|
|
1211
|
+
* Shared status→{@link BaerlyError} mapping for the S3/GCS XML adapters, so
|
|
1212
|
+
* the retryable set (`429`/`≥500`) can't drift between them. Store-specific
|
|
1213
|
+
* statuses (GCS `412`; S3 `409`/`404`-with-`If-Match`) are handled inline
|
|
1214
|
+
* first; the rest route here: `403`→AccessDenied (permanent), `429`/`≥500`→
|
|
1215
|
+
* retryable NetworkError carrying `{status, retryAfterSeconds?}`, else
|
|
1216
|
+
* InvalidResponse. Callers `throw` the result; consumes `res.text()` on the
|
|
1217
|
+
* non-`403` paths.
|
|
1218
|
+
*/
|
|
1219
|
+
const mapStorageError = async (res, verb, key) => {
|
|
1220
|
+
if (res.status === 403) return new BaerlyError("AccessDenied", `${verb} ${key}: 403`);
|
|
1221
|
+
if (res.status === 429 || res.status >= 500) return new BaerlyError("NetworkError", `${verb} ${key}: ${res.status} ${await res.text()}`, {
|
|
1222
|
+
status: res.status,
|
|
1223
|
+
...retryAfterCause(res)
|
|
1224
|
+
});
|
|
1225
|
+
return new BaerlyError("InvalidResponse", `${verb} ${key}: ${xmlErrorDetail(res.status, await res.text())}`);
|
|
1226
|
+
};
|
|
1211
1227
|
const retry = async (fn, { retries = 8, backoffMs = 100, maxDelayMs = 1e4 } = {}) => {
|
|
1212
1228
|
let wait = backoffMs;
|
|
1213
1229
|
for (let attempt = 0; attempt <= retries; attempt++) try {
|
|
@@ -1220,7 +1236,7 @@ const retry = async (fn, { retries = 8, backoffMs = 100, maxDelayMs = 1e4 } = {}
|
|
|
1220
1236
|
if (hintMs === void 0) wait = Math.min(wait * 1.5, maxDelayMs);
|
|
1221
1237
|
else wait = backoffMs;
|
|
1222
1238
|
}
|
|
1223
|
-
throw new BaerlyError("Internal", "
|
|
1239
|
+
throw new BaerlyError("Internal", "http-transport retry loop exited without returning or throwing");
|
|
1224
1240
|
};
|
|
1225
1241
|
const retryAfterHintMs = (e, maxDelayMs) => {
|
|
1226
1242
|
if (!(e instanceof BaerlyError)) return;
|
|
@@ -1228,475 +1244,7 @@ const retryAfterHintMs = (e, maxDelayMs) => {
|
|
|
1228
1244
|
if (cause?.retryAfterSeconds === void 0) return;
|
|
1229
1245
|
return Math.min(cause.retryAfterSeconds * 1e3, maxDelayMs);
|
|
1230
1246
|
};
|
|
1231
|
-
/**
|
|
1232
|
-
* `Storage` impl that speaks the S3 REST API directly. Works against
|
|
1233
|
-
* any S3-compatible endpoint — AWS S3, R2 (S3-compat), GCS (S3-compat),
|
|
1234
|
-
* Minio. Does not depend on any AWS SDK.
|
|
1235
|
-
*
|
|
1236
|
-
* Authentication is plugged in via the `sign` callback; this class
|
|
1237
|
-
* itself does no SigV4. For Cloudflare Workers, the R2 binding fast
|
|
1238
|
-
* path lives in `@baerly/adapter-cloudflare`.
|
|
1239
|
-
*/
|
|
1240
|
-
var S3HttpStorage = class {
|
|
1241
|
-
#endpoint;
|
|
1242
|
-
#bucket;
|
|
1243
|
-
#fetch;
|
|
1244
|
-
#sign;
|
|
1245
|
-
#retries;
|
|
1246
|
-
#backoffMs;
|
|
1247
|
-
constructor(options) {
|
|
1248
|
-
this.#endpoint = options.endpoint.replace(/\/+$/, "");
|
|
1249
|
-
this.#bucket = options.bucket;
|
|
1250
|
-
this.#fetch = options.fetch ?? globalThis.fetch.bind(globalThis);
|
|
1251
|
-
this.#sign = options.sign;
|
|
1252
|
-
this.#retries = options.retries ?? 8;
|
|
1253
|
-
this.#backoffMs = options.backoffMs ?? 100;
|
|
1254
|
-
}
|
|
1255
|
-
#objectUrl(key, versionId) {
|
|
1256
|
-
assertValidStorageKey(key);
|
|
1257
|
-
const base = `${this.#endpoint}/${this.#bucket}/${encodeURIComponent(key)}`;
|
|
1258
|
-
return versionId !== void 0 ? `${base}?versionId=${encodeURIComponent(versionId)}` : base;
|
|
1259
|
-
}
|
|
1260
|
-
async #dispatch(req) {
|
|
1261
|
-
const signed = this.#sign ? await this.#sign(req) : req;
|
|
1262
|
-
try {
|
|
1263
|
-
return await this.#fetch(signed);
|
|
1264
|
-
} catch (error) {
|
|
1265
|
-
if (error instanceof BaerlyError) throw error;
|
|
1266
|
-
throw new BaerlyError("NetworkError", error instanceof Error ? error.message : String(error), error);
|
|
1267
|
-
}
|
|
1268
|
-
}
|
|
1269
|
-
#retry(fn) {
|
|
1270
|
-
return retry(fn, {
|
|
1271
|
-
retries: this.#retries,
|
|
1272
|
-
backoffMs: this.#backoffMs
|
|
1273
|
-
});
|
|
1274
|
-
}
|
|
1275
|
-
async get(key, opts) {
|
|
1276
|
-
opts?.signal?.throwIfAborted();
|
|
1277
|
-
const url = this.#objectUrl(key, opts?.versionId);
|
|
1278
|
-
const headers = new Headers();
|
|
1279
|
-
if (opts?.ifNoneMatch !== void 0) headers.set("If-None-Match", opts.ifNoneMatch);
|
|
1280
|
-
return this.#retry(async () => {
|
|
1281
|
-
const res = await this.#dispatch(new Request(url, {
|
|
1282
|
-
method: "GET",
|
|
1283
|
-
headers,
|
|
1284
|
-
signal: opts?.signal ?? null
|
|
1285
|
-
}));
|
|
1286
|
-
switch (res.status) {
|
|
1287
|
-
case 200: {
|
|
1288
|
-
const etag = res.headers.get("ETag");
|
|
1289
|
-
if (etag === null) throw new BaerlyError("InvalidResponse", `GET ${key}: missing ETag`);
|
|
1290
|
-
const body = new Uint8Array(await res.arrayBuffer());
|
|
1291
|
-
const versionId = res.headers.get("x-amz-version-id") ?? void 0;
|
|
1292
|
-
return versionId !== void 0 ? {
|
|
1293
|
-
body,
|
|
1294
|
-
etag,
|
|
1295
|
-
versionId
|
|
1296
|
-
} : {
|
|
1297
|
-
body,
|
|
1298
|
-
etag
|
|
1299
|
-
};
|
|
1300
|
-
}
|
|
1301
|
-
case 304:
|
|
1302
|
-
case 404: return null;
|
|
1303
|
-
case 403: throw new BaerlyError("AccessDenied", `GET ${key}: 403`);
|
|
1304
|
-
default:
|
|
1305
|
-
if (res.status === 429 || res.status >= 500) throw new BaerlyError("NetworkError", `GET ${key}: ${res.status} ${await res.text()}`, {
|
|
1306
|
-
status: res.status,
|
|
1307
|
-
...retryAfterCause(res)
|
|
1308
|
-
});
|
|
1309
|
-
throw new BaerlyError("InvalidResponse", `GET ${key}: ${s3ErrorDetail(res.status, await res.text())}`);
|
|
1310
|
-
}
|
|
1311
|
-
});
|
|
1312
|
-
}
|
|
1313
|
-
async put(key, body, opts) {
|
|
1314
|
-
opts?.signal?.throwIfAborted();
|
|
1315
|
-
const url = this.#objectUrl(key);
|
|
1316
|
-
const headers = new Headers();
|
|
1317
|
-
headers.set("Content-Type", opts?.contentType ?? "application/octet-stream");
|
|
1318
|
-
if (opts?.ifMatch !== void 0) headers.set("If-Match", opts.ifMatch);
|
|
1319
|
-
if (opts?.ifNoneMatch === "*") headers.set("If-None-Match", "*");
|
|
1320
|
-
return this.#retry(async () => {
|
|
1321
|
-
const res = await this.#dispatch(new Request(url, {
|
|
1322
|
-
method: "PUT",
|
|
1323
|
-
headers,
|
|
1324
|
-
body,
|
|
1325
|
-
signal: opts?.signal ?? null
|
|
1326
|
-
}));
|
|
1327
|
-
if (res.status === 412) throw new BaerlyError("Conflict", `PUT ${key}: precondition failed`);
|
|
1328
|
-
if (res.status === 409 && opts?.ifNoneMatch === "*") throw new BaerlyError("NetworkError", `PUT ${key}: 409 ConditionalRequestConflict (contended conditional create; retryable)`, {
|
|
1329
|
-
status: res.status,
|
|
1330
|
-
...retryAfterCause(res)
|
|
1331
|
-
});
|
|
1332
|
-
if (res.status === 404 && opts?.ifMatch !== void 0) throw new BaerlyError("Conflict", `PUT ${key}: precondition failed (ifMatch=${opts.ifMatch} but key does not exist)`);
|
|
1333
|
-
if (res.status === 403) throw new BaerlyError("AccessDenied", `PUT ${key}: 403`);
|
|
1334
|
-
if (res.status === 429 || res.status >= 500) throw new BaerlyError("NetworkError", `PUT ${key}: ${res.status} ${await res.text()}`, {
|
|
1335
|
-
status: res.status,
|
|
1336
|
-
...retryAfterCause(res)
|
|
1337
|
-
});
|
|
1338
|
-
if (res.status !== 200 && res.status !== 204) throw new BaerlyError("InvalidResponse", `PUT ${key}: ${s3ErrorDetail(res.status, await res.text())}`);
|
|
1339
|
-
const etag = res.headers.get("ETag");
|
|
1340
|
-
if (etag === null) throw new BaerlyError("InvalidResponse", `PUT ${key}: missing ETag`);
|
|
1341
|
-
const dateStr = res.headers.get("Date");
|
|
1342
|
-
const versionId = res.headers.get("x-amz-version-id") ?? void 0;
|
|
1343
|
-
const result = { etag };
|
|
1344
|
-
if (dateStr !== null) result.serverDate = new Date(dateStr);
|
|
1345
|
-
if (versionId !== void 0) result.versionId = versionId;
|
|
1346
|
-
return result;
|
|
1347
|
-
});
|
|
1348
|
-
}
|
|
1349
|
-
async delete(key, opts) {
|
|
1350
|
-
opts?.signal?.throwIfAborted();
|
|
1351
|
-
const url = this.#objectUrl(key);
|
|
1352
|
-
await this.#retry(async () => {
|
|
1353
|
-
const res = await this.#dispatch(new Request(url, {
|
|
1354
|
-
method: "DELETE",
|
|
1355
|
-
signal: opts?.signal ?? null
|
|
1356
|
-
}));
|
|
1357
|
-
if (res.status === 403) throw new BaerlyError("AccessDenied", `DELETE ${key}: 403`);
|
|
1358
|
-
if (res.status === 429 || res.status >= 500) throw new BaerlyError("NetworkError", `DELETE ${key}: ${res.status} ${await res.text()}`, {
|
|
1359
|
-
status: res.status,
|
|
1360
|
-
...retryAfterCause(res)
|
|
1361
|
-
});
|
|
1362
|
-
});
|
|
1363
|
-
}
|
|
1364
|
-
async *list(prefix, opts) {
|
|
1365
|
-
opts?.signal?.throwIfAborted();
|
|
1366
|
-
let yielded = 0;
|
|
1367
|
-
let continuationToken;
|
|
1368
|
-
const startAfter = opts?.startAfter ?? "";
|
|
1369
|
-
while (true) {
|
|
1370
|
-
opts?.signal?.throwIfAborted();
|
|
1371
|
-
const params = new URLSearchParams();
|
|
1372
|
-
params.set("list-type", "2");
|
|
1373
|
-
params.set("prefix", prefix);
|
|
1374
|
-
params.set("encoding-type", "url");
|
|
1375
|
-
if (continuationToken !== void 0) params.set("continuation-token", continuationToken);
|
|
1376
|
-
else if (startAfter !== "") params.set("start-after", startAfter);
|
|
1377
|
-
if (opts?.maxKeys !== void 0) {
|
|
1378
|
-
const remaining = opts.maxKeys - yielded;
|
|
1379
|
-
params.set("max-keys", String(Math.min(remaining, 1e3)));
|
|
1380
|
-
}
|
|
1381
|
-
const url = `${this.#endpoint}/${this.#bucket}/?${params.toString()}`;
|
|
1382
|
-
let parsed;
|
|
1383
|
-
let lastHint;
|
|
1384
|
-
for (let attempt = 0; attempt < 10; attempt++) {
|
|
1385
|
-
const outcome = await this.#retry(async () => {
|
|
1386
|
-
const res = await this.#dispatch(new Request(url, {
|
|
1387
|
-
method: "GET",
|
|
1388
|
-
signal: opts?.signal ?? null
|
|
1389
|
-
}));
|
|
1390
|
-
if (res.status === 200) return {
|
|
1391
|
-
kind: "ok",
|
|
1392
|
-
body: await res.text()
|
|
1393
|
-
};
|
|
1394
|
-
if (res.status === 429) return {
|
|
1395
|
-
kind: "ratelimited",
|
|
1396
|
-
retryAfterSeconds: parseRetryAfter(res.headers.get("Retry-After"))
|
|
1397
|
-
};
|
|
1398
|
-
if (res.status === 403) throw new BaerlyError("AccessDenied", `LIST ${prefix}: 403`);
|
|
1399
|
-
if (res.status >= 500) throw new BaerlyError("NetworkError", `LIST ${prefix}: ${res.status} ${await res.text()}`, {
|
|
1400
|
-
status: res.status,
|
|
1401
|
-
...retryAfterCause(res)
|
|
1402
|
-
});
|
|
1403
|
-
throw new BaerlyError("InvalidResponse", `LIST ${prefix}: ${s3ErrorDetail(res.status, await res.text())}`);
|
|
1404
|
-
});
|
|
1405
|
-
if (outcome.kind === "ok") {
|
|
1406
|
-
parsed = parseListObjectsV2CommandOutput(outcome.body);
|
|
1407
|
-
break;
|
|
1408
|
-
}
|
|
1409
|
-
lastHint = outcome.retryAfterSeconds;
|
|
1410
|
-
const hintMs = outcome.retryAfterSeconds !== void 0 ? outcome.retryAfterSeconds * 1e3 : 0;
|
|
1411
|
-
await delay(Math.max(hintMs, RATE_LIMIT_BACKOFF_MILLIS));
|
|
1412
|
-
}
|
|
1413
|
-
if (parsed === void 0) throw new BaerlyError("NetworkError", `LIST ${prefix}: rate-limited`, {
|
|
1414
|
-
status: 429,
|
|
1415
|
-
...lastHint !== void 0 ? { retryAfterSeconds: lastHint } : {}
|
|
1416
|
-
});
|
|
1417
|
-
for (const entry of parsed.Contents ?? []) {
|
|
1418
|
-
if (entry.Key === void 0) continue;
|
|
1419
|
-
yield {
|
|
1420
|
-
key: entry.Key,
|
|
1421
|
-
etag: entry.ETag ?? "",
|
|
1422
|
-
...entry.LastModified !== void 0 && { lastModified: entry.LastModified }
|
|
1423
|
-
};
|
|
1424
|
-
yielded += 1;
|
|
1425
|
-
if (opts?.maxKeys !== void 0 && yielded >= opts.maxKeys) return;
|
|
1426
|
-
}
|
|
1427
|
-
continuationToken = parsed.NextContinuationToken;
|
|
1428
|
-
if (continuationToken === void 0 || continuationToken === "") return;
|
|
1429
|
-
}
|
|
1430
|
-
}
|
|
1431
|
-
};
|
|
1432
|
-
//#endregion
|
|
1433
|
-
//#region node_modules/.pnpm/aws4fetch@1.0.20/node_modules/aws4fetch/dist/aws4fetch.esm.mjs
|
|
1434
|
-
/**
|
|
1435
|
-
* @license MIT <https://opensource.org/licenses/MIT>
|
|
1436
|
-
* @copyright Michael Hart 2024
|
|
1437
|
-
*/
|
|
1438
|
-
const encoder = new TextEncoder();
|
|
1439
|
-
const HOST_SERVICES = {
|
|
1440
|
-
appstream2: "appstream",
|
|
1441
|
-
cloudhsmv2: "cloudhsm",
|
|
1442
|
-
email: "ses",
|
|
1443
|
-
marketplace: "aws-marketplace",
|
|
1444
|
-
mobile: "AWSMobileHubService",
|
|
1445
|
-
pinpoint: "mobiletargeting",
|
|
1446
|
-
queue: "sqs",
|
|
1447
|
-
"git-codecommit": "codecommit",
|
|
1448
|
-
"mturk-requester-sandbox": "mturk-requester",
|
|
1449
|
-
"personalize-runtime": "personalize"
|
|
1450
|
-
};
|
|
1451
|
-
const UNSIGNABLE_HEADERS = /* @__PURE__ */ new Set([
|
|
1452
|
-
"authorization",
|
|
1453
|
-
"content-type",
|
|
1454
|
-
"content-length",
|
|
1455
|
-
"user-agent",
|
|
1456
|
-
"presigned-expires",
|
|
1457
|
-
"expect",
|
|
1458
|
-
"x-amzn-trace-id",
|
|
1459
|
-
"range",
|
|
1460
|
-
"connection"
|
|
1461
|
-
]);
|
|
1462
|
-
var AwsClient = class {
|
|
1463
|
-
constructor({ accessKeyId, secretAccessKey, sessionToken, service, region, cache, retries, initRetryMs }) {
|
|
1464
|
-
if (accessKeyId == null) throw new TypeError("accessKeyId is a required option");
|
|
1465
|
-
if (secretAccessKey == null) throw new TypeError("secretAccessKey is a required option");
|
|
1466
|
-
this.accessKeyId = accessKeyId;
|
|
1467
|
-
this.secretAccessKey = secretAccessKey;
|
|
1468
|
-
this.sessionToken = sessionToken;
|
|
1469
|
-
this.service = service;
|
|
1470
|
-
this.region = region;
|
|
1471
|
-
this.cache = cache || /* @__PURE__ */ new Map();
|
|
1472
|
-
this.retries = retries != null ? retries : 10;
|
|
1473
|
-
this.initRetryMs = initRetryMs || 50;
|
|
1474
|
-
}
|
|
1475
|
-
async sign(input, init) {
|
|
1476
|
-
if (input instanceof Request) {
|
|
1477
|
-
const { method, url, headers, body } = input;
|
|
1478
|
-
init = Object.assign({
|
|
1479
|
-
method,
|
|
1480
|
-
url,
|
|
1481
|
-
headers
|
|
1482
|
-
}, init);
|
|
1483
|
-
if (init.body == null && headers.has("Content-Type")) init.body = body != null && headers.has("X-Amz-Content-Sha256") ? body : await input.clone().arrayBuffer();
|
|
1484
|
-
input = url;
|
|
1485
|
-
}
|
|
1486
|
-
const signer = new AwsV4Signer(Object.assign({ url: input.toString() }, init, this, init && init.aws));
|
|
1487
|
-
const signed = Object.assign({}, init, await signer.sign());
|
|
1488
|
-
delete signed.aws;
|
|
1489
|
-
try {
|
|
1490
|
-
return new Request(signed.url.toString(), signed);
|
|
1491
|
-
} catch (e) {
|
|
1492
|
-
if (e instanceof TypeError) return new Request(signed.url.toString(), Object.assign({ duplex: "half" }, signed));
|
|
1493
|
-
throw e;
|
|
1494
|
-
}
|
|
1495
|
-
}
|
|
1496
|
-
async fetch(input, init) {
|
|
1497
|
-
for (let i = 0; i <= this.retries; i++) {
|
|
1498
|
-
const fetched = fetch(await this.sign(input, init));
|
|
1499
|
-
if (i === this.retries) return fetched;
|
|
1500
|
-
const res = await fetched;
|
|
1501
|
-
if (res.status < 500 && res.status !== 429) return res;
|
|
1502
|
-
await new Promise((resolve) => setTimeout(resolve, Math.random() * this.initRetryMs * Math.pow(2, i)));
|
|
1503
|
-
}
|
|
1504
|
-
throw new Error("An unknown error occurred, ensure retries is not negative");
|
|
1505
|
-
}
|
|
1506
|
-
};
|
|
1507
|
-
var AwsV4Signer = class {
|
|
1508
|
-
constructor({ method, url, headers, body, accessKeyId, secretAccessKey, sessionToken, service, region, cache, datetime, signQuery, appendSessionToken, allHeaders, singleEncode }) {
|
|
1509
|
-
if (url == null) throw new TypeError("url is a required option");
|
|
1510
|
-
if (accessKeyId == null) throw new TypeError("accessKeyId is a required option");
|
|
1511
|
-
if (secretAccessKey == null) throw new TypeError("secretAccessKey is a required option");
|
|
1512
|
-
this.method = method || (body ? "POST" : "GET");
|
|
1513
|
-
this.url = new URL(url);
|
|
1514
|
-
this.headers = new Headers(headers || {});
|
|
1515
|
-
this.body = body;
|
|
1516
|
-
this.accessKeyId = accessKeyId;
|
|
1517
|
-
this.secretAccessKey = secretAccessKey;
|
|
1518
|
-
this.sessionToken = sessionToken;
|
|
1519
|
-
let guessedService, guessedRegion;
|
|
1520
|
-
if (!service || !region) [guessedService, guessedRegion] = guessServiceRegion(this.url, this.headers);
|
|
1521
|
-
this.service = service || guessedService || "";
|
|
1522
|
-
this.region = region || guessedRegion || "us-east-1";
|
|
1523
|
-
this.cache = cache || /* @__PURE__ */ new Map();
|
|
1524
|
-
this.datetime = datetime || (/* @__PURE__ */ new Date()).toISOString().replace(/[:-]|\.\d{3}/g, "");
|
|
1525
|
-
this.signQuery = signQuery;
|
|
1526
|
-
this.appendSessionToken = appendSessionToken || this.service === "iotdevicegateway";
|
|
1527
|
-
this.headers.delete("Host");
|
|
1528
|
-
if (this.service === "s3" && !this.signQuery && !this.headers.has("X-Amz-Content-Sha256")) this.headers.set("X-Amz-Content-Sha256", "UNSIGNED-PAYLOAD");
|
|
1529
|
-
const params = this.signQuery ? this.url.searchParams : this.headers;
|
|
1530
|
-
params.set("X-Amz-Date", this.datetime);
|
|
1531
|
-
if (this.sessionToken && !this.appendSessionToken) params.set("X-Amz-Security-Token", this.sessionToken);
|
|
1532
|
-
this.signableHeaders = ["host", ...this.headers.keys()].filter((header) => allHeaders || !UNSIGNABLE_HEADERS.has(header)).sort();
|
|
1533
|
-
this.signedHeaders = this.signableHeaders.join(";");
|
|
1534
|
-
this.canonicalHeaders = this.signableHeaders.map((header) => header + ":" + (header === "host" ? this.url.host : (this.headers.get(header) || "").replace(/\s+/g, " "))).join("\n");
|
|
1535
|
-
this.credentialString = [
|
|
1536
|
-
this.datetime.slice(0, 8),
|
|
1537
|
-
this.region,
|
|
1538
|
-
this.service,
|
|
1539
|
-
"aws4_request"
|
|
1540
|
-
].join("/");
|
|
1541
|
-
if (this.signQuery) {
|
|
1542
|
-
if (this.service === "s3" && !params.has("X-Amz-Expires")) params.set("X-Amz-Expires", "86400");
|
|
1543
|
-
params.set("X-Amz-Algorithm", "AWS4-HMAC-SHA256");
|
|
1544
|
-
params.set("X-Amz-Credential", this.accessKeyId + "/" + this.credentialString);
|
|
1545
|
-
params.set("X-Amz-SignedHeaders", this.signedHeaders);
|
|
1546
|
-
}
|
|
1547
|
-
if (this.service === "s3") try {
|
|
1548
|
-
this.encodedPath = decodeURIComponent(this.url.pathname.replace(/\+/g, " "));
|
|
1549
|
-
} catch (e) {
|
|
1550
|
-
this.encodedPath = this.url.pathname;
|
|
1551
|
-
}
|
|
1552
|
-
else this.encodedPath = this.url.pathname.replace(/\/+/g, "/");
|
|
1553
|
-
if (!singleEncode) this.encodedPath = encodeURIComponent(this.encodedPath).replace(/%2F/g, "/");
|
|
1554
|
-
this.encodedPath = encodeRfc3986(this.encodedPath);
|
|
1555
|
-
const seenKeys = /* @__PURE__ */ new Set();
|
|
1556
|
-
this.encodedSearch = [...this.url.searchParams].filter(([k]) => {
|
|
1557
|
-
if (!k) return false;
|
|
1558
|
-
if (this.service === "s3") {
|
|
1559
|
-
if (seenKeys.has(k)) return false;
|
|
1560
|
-
seenKeys.add(k);
|
|
1561
|
-
}
|
|
1562
|
-
return true;
|
|
1563
|
-
}).map((pair) => pair.map((p) => encodeRfc3986(encodeURIComponent(p)))).sort(([k1, v1], [k2, v2]) => k1 < k2 ? -1 : k1 > k2 ? 1 : v1 < v2 ? -1 : v1 > v2 ? 1 : 0).map((pair) => pair.join("=")).join("&");
|
|
1564
|
-
}
|
|
1565
|
-
async sign() {
|
|
1566
|
-
if (this.signQuery) {
|
|
1567
|
-
this.url.searchParams.set("X-Amz-Signature", await this.signature());
|
|
1568
|
-
if (this.sessionToken && this.appendSessionToken) this.url.searchParams.set("X-Amz-Security-Token", this.sessionToken);
|
|
1569
|
-
} else this.headers.set("Authorization", await this.authHeader());
|
|
1570
|
-
return {
|
|
1571
|
-
method: this.method,
|
|
1572
|
-
url: this.url,
|
|
1573
|
-
headers: this.headers,
|
|
1574
|
-
body: this.body
|
|
1575
|
-
};
|
|
1576
|
-
}
|
|
1577
|
-
async authHeader() {
|
|
1578
|
-
return [
|
|
1579
|
-
"AWS4-HMAC-SHA256 Credential=" + this.accessKeyId + "/" + this.credentialString,
|
|
1580
|
-
"SignedHeaders=" + this.signedHeaders,
|
|
1581
|
-
"Signature=" + await this.signature()
|
|
1582
|
-
].join(", ");
|
|
1583
|
-
}
|
|
1584
|
-
async signature() {
|
|
1585
|
-
const date = this.datetime.slice(0, 8);
|
|
1586
|
-
const cacheKey = [
|
|
1587
|
-
this.secretAccessKey,
|
|
1588
|
-
date,
|
|
1589
|
-
this.region,
|
|
1590
|
-
this.service
|
|
1591
|
-
].join();
|
|
1592
|
-
let kCredentials = this.cache.get(cacheKey);
|
|
1593
|
-
if (!kCredentials) {
|
|
1594
|
-
kCredentials = await hmac(await hmac(await hmac(await hmac("AWS4" + this.secretAccessKey, date), this.region), this.service), "aws4_request");
|
|
1595
|
-
this.cache.set(cacheKey, kCredentials);
|
|
1596
|
-
}
|
|
1597
|
-
return buf2hex(await hmac(kCredentials, await this.stringToSign()));
|
|
1598
|
-
}
|
|
1599
|
-
async stringToSign() {
|
|
1600
|
-
return [
|
|
1601
|
-
"AWS4-HMAC-SHA256",
|
|
1602
|
-
this.datetime,
|
|
1603
|
-
this.credentialString,
|
|
1604
|
-
buf2hex(await hash(await this.canonicalString()))
|
|
1605
|
-
].join("\n");
|
|
1606
|
-
}
|
|
1607
|
-
async canonicalString() {
|
|
1608
|
-
return [
|
|
1609
|
-
this.method.toUpperCase(),
|
|
1610
|
-
this.encodedPath,
|
|
1611
|
-
this.encodedSearch,
|
|
1612
|
-
this.canonicalHeaders + "\n",
|
|
1613
|
-
this.signedHeaders,
|
|
1614
|
-
await this.hexBodyHash()
|
|
1615
|
-
].join("\n");
|
|
1616
|
-
}
|
|
1617
|
-
async hexBodyHash() {
|
|
1618
|
-
let hashHeader = this.headers.get("X-Amz-Content-Sha256") || (this.service === "s3" && this.signQuery ? "UNSIGNED-PAYLOAD" : null);
|
|
1619
|
-
if (hashHeader == null) {
|
|
1620
|
-
if (this.body && typeof this.body !== "string" && !("byteLength" in this.body)) throw new Error("body must be a string, ArrayBuffer or ArrayBufferView, unless you include the X-Amz-Content-Sha256 header");
|
|
1621
|
-
hashHeader = buf2hex(await hash(this.body || ""));
|
|
1622
|
-
}
|
|
1623
|
-
return hashHeader;
|
|
1624
|
-
}
|
|
1625
|
-
};
|
|
1626
|
-
async function hmac(key, string) {
|
|
1627
|
-
const cryptoKey = await crypto.subtle.importKey("raw", typeof key === "string" ? encoder.encode(key) : key, {
|
|
1628
|
-
name: "HMAC",
|
|
1629
|
-
hash: { name: "SHA-256" }
|
|
1630
|
-
}, false, ["sign"]);
|
|
1631
|
-
return crypto.subtle.sign("HMAC", cryptoKey, encoder.encode(string));
|
|
1632
|
-
}
|
|
1633
|
-
async function hash(content) {
|
|
1634
|
-
return crypto.subtle.digest("SHA-256", typeof content === "string" ? encoder.encode(content) : content);
|
|
1635
|
-
}
|
|
1636
|
-
const HEX_CHARS = [
|
|
1637
|
-
"0",
|
|
1638
|
-
"1",
|
|
1639
|
-
"2",
|
|
1640
|
-
"3",
|
|
1641
|
-
"4",
|
|
1642
|
-
"5",
|
|
1643
|
-
"6",
|
|
1644
|
-
"7",
|
|
1645
|
-
"8",
|
|
1646
|
-
"9",
|
|
1647
|
-
"a",
|
|
1648
|
-
"b",
|
|
1649
|
-
"c",
|
|
1650
|
-
"d",
|
|
1651
|
-
"e",
|
|
1652
|
-
"f"
|
|
1653
|
-
];
|
|
1654
|
-
function buf2hex(arrayBuffer) {
|
|
1655
|
-
const buffer = new Uint8Array(arrayBuffer);
|
|
1656
|
-
let out = "";
|
|
1657
|
-
for (let idx = 0; idx < buffer.length; idx++) {
|
|
1658
|
-
const n = buffer[idx];
|
|
1659
|
-
out += HEX_CHARS[n >>> 4 & 15];
|
|
1660
|
-
out += HEX_CHARS[n & 15];
|
|
1661
|
-
}
|
|
1662
|
-
return out;
|
|
1663
|
-
}
|
|
1664
|
-
function encodeRfc3986(urlEncodedStr) {
|
|
1665
|
-
return urlEncodedStr.replace(/[!'()*]/g, (c) => "%" + c.charCodeAt(0).toString(16).toUpperCase());
|
|
1666
|
-
}
|
|
1667
|
-
function guessServiceRegion(url, headers) {
|
|
1668
|
-
const { hostname, pathname } = url;
|
|
1669
|
-
if (hostname.endsWith(".on.aws")) {
|
|
1670
|
-
const match = hostname.match(/^[^.]{1,63}\.lambda-url\.([^.]{1,63})\.on\.aws$/);
|
|
1671
|
-
return match != null ? ["lambda", match[1] || ""] : ["", ""];
|
|
1672
|
-
}
|
|
1673
|
-
if (hostname.endsWith(".r2.cloudflarestorage.com")) return ["s3", "auto"];
|
|
1674
|
-
if (hostname.endsWith(".backblazeb2.com")) {
|
|
1675
|
-
const match = hostname.match(/^(?:[^.]{1,63}\.)?s3\.([^.]{1,63})\.backblazeb2\.com$/);
|
|
1676
|
-
return match != null ? ["s3", match[1] || ""] : ["", ""];
|
|
1677
|
-
}
|
|
1678
|
-
const match = hostname.replace("dualstack.", "").match(/([^.]{1,63})\.(?:([^.]{0,63})\.)?amazonaws\.com(?:\.cn)?$/);
|
|
1679
|
-
let service = match && match[1] || "";
|
|
1680
|
-
let region = match && match[2];
|
|
1681
|
-
if (region === "us-gov") region = "us-gov-west-1";
|
|
1682
|
-
else if (region === "s3" || region === "s3-accelerate") {
|
|
1683
|
-
region = "us-east-1";
|
|
1684
|
-
service = "s3";
|
|
1685
|
-
} else if (service === "iot") if (hostname.startsWith("iot.")) service = "execute-api";
|
|
1686
|
-
else if (hostname.startsWith("data.jobs.iot.")) service = "iot-jobs-data";
|
|
1687
|
-
else service = pathname === "/mqtt" ? "iotdevicegateway" : "iotdata";
|
|
1688
|
-
else if (service === "autoscaling") {
|
|
1689
|
-
const targetPrefix = (headers.get("X-Amz-Target") || "").split(".")[0];
|
|
1690
|
-
if (targetPrefix === "AnyScaleFrontendService") service = "application-autoscaling";
|
|
1691
|
-
else if (targetPrefix === "AnyScaleScalingPlannerFrontendService") service = "autoscaling-plans";
|
|
1692
|
-
} else if (region == null && service.startsWith("s3-")) {
|
|
1693
|
-
region = service.slice(3).replace(/^fips-|^external-1/, "");
|
|
1694
|
-
service = "s3";
|
|
1695
|
-
} else if (service.endsWith("-fips")) service = service.slice(0, -5);
|
|
1696
|
-
else if (region && /-\d$/.test(service) && !/-\d$/.test(region)) [service, region] = [region, service];
|
|
1697
|
-
return [HOST_SERVICES[service] || service, region || ""];
|
|
1698
|
-
}
|
|
1699
1247
|
//#endregion
|
|
1700
|
-
export {
|
|
1248
|
+
export { parseAssumeRoleWithWebIdentity as a, retryAfterCause as i, parseRetryAfter as n, parseListObjectsV2CommandOutput as o, retry as r, parseStsError as s, mapStorageError as t };
|
|
1701
1249
|
|
|
1702
|
-
//# sourceMappingURL=
|
|
1250
|
+
//# sourceMappingURL=http-transport-BTgVCY5r.js.map
|