@gusto/baerly-storage 0.5.0 → 0.7.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/README.md +47 -124
- package/dist/API.md +161 -511
- package/dist/CHANGELOG.md +1148 -307
- package/dist/RECIPES.md +398 -80
- package/dist/THIRD-PARTY-LICENSES.txt +5 -26
- package/dist/{app-config-DyiFK3_k.d.ts → app-config-C6qW7m8S.d.ts} +119 -111
- package/dist/app-config.d.ts +31 -1
- package/dist/app-config.js +1 -2
- package/dist/app-config.js.map +1 -1
- package/dist/auth.d.ts +33 -28
- package/dist/auth.js +549 -985
- package/dist/auth.js.map +1 -1
- package/dist/baerly.js +130 -138
- package/dist/baerly.js.map +1 -1
- package/dist/baerly.spec.json +97 -22
- package/dist/capacity-warning-header-BlVopyiI.js +16 -0
- package/dist/capacity-warning-header-BlVopyiI.js.map +1 -0
- package/dist/{client-Fe8CwB73.d.ts → client-CHQTXpef.d.ts} +121 -36
- package/dist/client-react.d.ts +67 -20
- package/dist/client-react.js +240 -54
- package/dist/client-react.js.map +1 -1
- package/dist/client.d.ts +5 -4
- package/dist/client.js +51 -16
- package/dist/client.js.map +1 -1
- package/dist/{cloudflare-DzKBrUlg.js → cloudflare-CKHYXccw.js} +504 -124
- package/dist/cloudflare-CKHYXccw.js.map +1 -0
- package/dist/cloudflare.d.ts +106 -71
- package/dist/cloudflare.js +334 -271
- package/dist/cloudflare.js.map +1 -1
- package/dist/code-resolution-CL_7L0wS.js +22 -0
- package/dist/code-resolution-CL_7L0wS.js.map +1 -0
- package/dist/collection-api-DbyhLAY8.d.ts +1001 -0
- package/dist/config-DEzInG6M.js +4035 -0
- package/dist/config-DEzInG6M.js.map +1 -0
- package/dist/constants-D3GSH3tc.js +469 -0
- package/dist/constants-D3GSH3tc.js.map +1 -0
- package/dist/{context-DRZ3tZ5l.js → context-rlpSnHFA.js} +17 -17
- package/dist/context-rlpSnHFA.js.map +1 -0
- package/dist/cost-B52llVDx.js +330 -0
- package/dist/cost-B52llVDx.js.map +1 -0
- package/dist/{current-json-C6nhPOm1.js → current-json-CC6lE4Aj.js} +115 -32
- package/dist/current-json-CC6lE4Aj.js.map +1 -0
- package/dist/db-plFUNTSF.d.ts +130 -0
- package/dist/db-read-seams-BSs0m1z1.js +3261 -0
- package/dist/db-read-seams-BSs0m1z1.js.map +1 -0
- package/dist/{deploy-DonTr-CV.js → deploy-Obj4nE-Z.js} +12 -16
- package/dist/deploy-Obj4nE-Z.js.map +1 -0
- package/dist/{dev-banner-CWHIk8tH.d.ts → dev-banner-B5AUHmu1.d.ts} +1 -4
- package/dist/dev-landing-BI5UdmOb.d.ts +32 -0
- package/dist/dev-landing-CD-si4dW.js +50 -0
- package/dist/dev-landing-CD-si4dW.js.map +1 -0
- package/dist/dev-vite.d.ts +38 -39
- package/dist/dev-vite.js +67 -36
- package/dist/dev-vite.js.map +1 -1
- package/dist/dev.d.ts +3 -2
- package/dist/dev.js +2 -1
- package/dist/doctor-BA0i-YAN.js +270 -0
- package/dist/doctor-BA0i-YAN.js.map +1 -0
- package/dist/dump-D1vX8ozg.js +133 -0
- package/dist/dump-D1vX8ozg.js.map +1 -0
- package/dist/errors-7Rk1HGCE.js +160 -0
- package/dist/errors-7Rk1HGCE.js.map +1 -0
- package/dist/{validate-DtljsCh1.js → export-BVL2EvYE.js} +409 -19
- package/dist/export-BVL2EvYE.js.map +1 -0
- package/dist/fsck-BWkPgov4.js +145 -0
- package/dist/fsck-BWkPgov4.js.map +1 -0
- package/dist/gcs-admin-Dso1HWQj.d.ts +127 -0
- package/dist/gcs.d.ts +30 -0
- package/dist/gcs.js +1 -0
- package/dist/goog4-signer-CeLIABoE.js +331 -0
- package/dist/goog4-signer-CeLIABoE.js.map +1 -0
- package/dist/{http-DGd5tbNs.js → http-Z5rZyYMX.js} +898 -271
- package/dist/http-Z5rZyYMX.js.map +1 -0
- package/dist/http-transport-DNUM8kU-.js +1299 -0
- package/dist/http-transport-DNUM8kU-.js.map +1 -0
- package/dist/http.d.ts +366 -294
- package/dist/http.js +2 -2
- package/dist/index-JJrIu1pO.d.ts +135 -0
- package/dist/index-LEgHN0qJ.d.ts +50 -0
- package/dist/{index-CuA9Mi3K.d.ts → index-RiEYj8t0.d.ts} +291 -78
- package/dist/index.d.ts +27 -6
- package/dist/index.js +3 -5
- package/dist/inspect-BTsVYZKd.js +196 -0
- package/dist/inspect-BTsVYZKd.js.map +1 -0
- package/dist/{key-Di6yyxFu.js → key-C4FPZ9Io.js} +3 -4
- package/dist/{key-Di6yyxFu.js.map → key-C4FPZ9Io.js.map} +1 -1
- package/dist/ledger-Dj_bGgo0.js +192 -0
- package/dist/ledger-Dj_bGgo0.js.map +1 -0
- package/dist/legacy-names-DgZBtgOh.js +47 -0
- package/dist/legacy-names-DgZBtgOh.js.map +1 -0
- package/dist/log-C9W15Dfo.d.ts +94 -0
- package/dist/log-tail-DWJbneBF.js +142 -0
- package/dist/log-tail-DWJbneBF.js.map +1 -0
- package/dist/log-walk-C-vA-WGJ.js +111 -0
- package/dist/log-walk-C-vA-WGJ.js.map +1 -0
- package/dist/maintenance-Dd-Yakqj.js +1709 -0
- package/dist/maintenance-Dd-Yakqj.js.map +1 -0
- package/dist/maintenance-DevB6z4e.js +2237 -0
- package/dist/maintenance-DevB6z4e.js.map +1 -0
- package/dist/maintenance.d.ts +100 -3
- package/dist/maintenance.js +1 -3
- package/dist/node.d.ts +130 -142
- package/dist/node.js +4 -3
- package/dist/{observability-BmflLCdF.js → observability-C-ISCCLE.js} +1275 -332
- package/dist/observability-C-ISCCLE.js.map +1 -0
- package/dist/observability.d.ts +27 -3
- package/dist/observability.js +3 -3
- package/dist/path-segment-DBXG26PW.js +363 -0
- package/dist/path-segment-DBXG26PW.js.map +1 -0
- package/dist/{plan-a7PJHBCy.js → plan-BvQbaNMe.js} +19 -11
- package/dist/plan-BvQbaNMe.js.map +1 -0
- package/dist/request-CRWiTrza.js +272 -0
- package/dist/request-CRWiTrza.js.map +1 -0
- package/dist/restore-U6Im8V1V.js +1467 -0
- package/dist/restore-U6Im8V1V.js.map +1 -0
- package/dist/retry-OBtLB2GC.js +126 -0
- package/dist/retry-OBtLB2GC.js.map +1 -0
- package/dist/rolldown-runtime-D3KUYPsf.js +12 -0
- package/dist/{runtime-spec-Dsw2-n8S.js → runtime-spec-B5mg3pHF.js} +189 -28
- package/dist/runtime-spec-B5mg3pHF.js.map +1 -0
- package/dist/{s3-http-B-z8th6O.d.ts → s3-http-DBC_wiCL.d.ts} +18 -10
- package/dist/s3.d.ts +20 -7
- package/dist/s3.js +4 -5
- package/dist/s3.js.map +1 -1
- package/dist/sha256-4FfGQNPw.js +22 -0
- package/dist/sha256-4FfGQNPw.js.map +1 -0
- package/dist/{shared-secret-DgEicd3x.js → shared-secret-Vkur-8r0.js} +27 -15
- package/dist/shared-secret-Vkur-8r0.js.map +1 -0
- package/dist/sigv4-sign-5IUflUD_.js +507 -0
- package/dist/sigv4-sign-5IUflUD_.js.map +1 -0
- package/dist/snapshot-CknzkDM0.js +148 -0
- package/dist/snapshot-CknzkDM0.js.map +1 -0
- package/dist/{src-BL_JoPTn.js → src-Actga-bO.js} +1004 -378
- package/dist/src-Actga-bO.js.map +1 -0
- package/dist/src-D0MQfvOp.js +812 -0
- package/dist/src-D0MQfvOp.js.map +1 -0
- package/dist/src-Dr9uo3dc.js +501 -0
- package/dist/src-Dr9uo3dc.js.map +1 -0
- package/dist/{subcommand-DoDA-K7d.js → subcommand-BLoF66dG.js} +89 -16
- package/dist/subcommand-BLoF66dG.js.map +1 -0
- package/dist/{time-DUqvFMHq.js → time-DRxTP9iv.js} +15 -34
- package/dist/time-DRxTP9iv.js.map +1 -0
- package/dist/types-suVbsEWS.d.ts +116 -0
- package/dist/{usage-DBV1eQHC.js → usage-CPzVhrQr.js} +40 -45
- package/dist/usage-CPzVhrQr.js.map +1 -0
- package/dist/uuid-BuT_c404.js +333 -0
- package/dist/uuid-BuT_c404.js.map +1 -0
- package/dist/verifier-Bmlmndzo.d.ts +95 -0
- package/dist/{wire-izfGZDvr.js → wire-DndvKU-K.js} +2 -3
- package/dist/wire-DndvKU-K.js.map +1 -0
- package/package.json +96 -69
- package/dist/aws4fetch.esm-p7eEzLCs.js +0 -1702
- package/dist/aws4fetch.esm-p7eEzLCs.js.map +0 -1
- package/dist/bytes-BXdamO3L.js +0 -11
- package/dist/bytes-BXdamO3L.js.map +0 -1
- package/dist/cloudflare-DzKBrUlg.js.map +0 -1
- package/dist/config-1tv0-Yzm.js +0 -2693
- package/dist/config-1tv0-Yzm.js.map +0 -1
- package/dist/constants-CfeMWQWk.js +0 -222
- package/dist/constants-CfeMWQWk.js.map +0 -1
- package/dist/context-DRZ3tZ5l.js.map +0 -1
- package/dist/cost-DSMIVqzL.js +0 -203
- package/dist/cost-DSMIVqzL.js.map +0 -1
- package/dist/current-json-C6nhPOm1.js.map +0 -1
- package/dist/db-DsPkOVEH.d.ts +0 -254
- 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/dump-Bh5k26VQ.js +0 -94
- package/dist/dump-Bh5k26VQ.js.map +0 -1
- package/dist/errors-Dfa3p78c.js +0 -78
- package/dist/errors-Dfa3p78c.js.map +0 -1
- package/dist/export-DtF5tDIM.js +0 -401
- package/dist/export-DtF5tDIM.js.map +0 -1
- package/dist/fsck-D_djMO5D.js +0 -279
- package/dist/fsck-D_djMO5D.js.map +0 -1
- package/dist/http-DGd5tbNs.js.map +0 -1
- package/dist/index-0rZcMBwy.d.ts +0 -115
- package/dist/index-BNRh23K9.d.ts +0 -162
- package/dist/index-BYk9oCNf.d.ts +0 -1112
- package/dist/indexes-Dn9hbGQG.d.ts +0 -22
- package/dist/inspect-6WZ-pC7-.js +0 -133
- package/dist/inspect-6WZ-pC7-.js.map +0 -1
- package/dist/log-tail-D98U1JBo.js +0 -522
- package/dist/log-tail-D98U1JBo.js.map +0 -1
- package/dist/maintenance-B4Dki6Ig.js +0 -2157
- package/dist/maintenance-B4Dki6Ig.js.map +0 -1
- package/dist/maintenance-B_e0T99L.d.ts +0 -537
- package/dist/maintenance-C7coQp4c.js +0 -1418
- package/dist/maintenance-C7coQp4c.js.map +0 -1
- package/dist/normalize-rjnZLwS4.js +0 -133
- package/dist/normalize-rjnZLwS4.js.map +0 -1
- package/dist/observability-BmflLCdF.js.map +0 -1
- package/dist/plan-a7PJHBCy.js.map +0 -1
- package/dist/query-rAtXNQQB.js +0 -1773
- package/dist/query-rAtXNQQB.js.map +0 -1
- package/dist/rebuild-index-BVzQSZlm.js +0 -81
- package/dist/rebuild-index-BVzQSZlm.js.map +0 -1
- package/dist/request-u0M51mhJ.js +0 -72
- package/dist/request-u0M51mhJ.js.map +0 -1
- package/dist/restore-R-4rbciV.js +0 -778
- package/dist/restore-R-4rbciV.js.map +0 -1
- package/dist/rolldown-runtime-EAsCxrDo.js +0 -14
- package/dist/runtime-spec-Dsw2-n8S.js.map +0 -1
- package/dist/shared-secret-DgEicd3x.js.map +0 -1
- package/dist/src-BL_JoPTn.js.map +0 -1
- package/dist/src-CYHFDrKz.js +0 -536
- package/dist/src-CYHFDrKz.js.map +0 -1
- package/dist/src-DYZ4H1aF.js +0 -392
- package/dist/src-DYZ4H1aF.js.map +0 -1
- package/dist/subcommand-DoDA-K7d.js.map +0 -1
- package/dist/time-DUqvFMHq.js.map +0 -1
- package/dist/usage-DBV1eQHC.js.map +0 -1
- package/dist/validate-DtljsCh1.js.map +0 -1
- package/dist/wire-izfGZDvr.js.map +0 -1
|
@@ -1,1702 +0,0 @@
|
|
|
1
|
-
import { t as __commonJSMin } from "./rolldown-runtime-EAsCxrDo.js";
|
|
2
|
-
import { g as RATE_LIMIT_BACKOFF_MILLIS } from "./constants-CfeMWQWk.js";
|
|
3
|
-
import { t as BaerlyError } from "./errors-Dfa3p78c.js";
|
|
4
|
-
import { t as assertValidStorageKey } from "./key-Di6yyxFu.js";
|
|
5
|
-
import { t as delay } from "./time-DUqvFMHq.js";
|
|
6
|
-
/*! @rgrove/parse-xml v4.2.1 | ISC License | Copyright Ryan Grove */
|
|
7
|
-
//#endregion
|
|
8
|
-
//#region packages/adapter-node/src/xml.ts
|
|
9
|
-
var import_browser = (/* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
10
|
-
var __defProp = Object.defineProperty;
|
|
11
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
12
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
13
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
14
|
-
var __export = (target, all) => {
|
|
15
|
-
for (var name in all) __defProp(target, name, {
|
|
16
|
-
get: all[name],
|
|
17
|
-
enumerable: true
|
|
18
|
-
});
|
|
19
|
-
};
|
|
20
|
-
var __copyProps = (to, from, except, desc) => {
|
|
21
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
22
|
-
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
23
|
-
get: () => from[key],
|
|
24
|
-
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
return to;
|
|
28
|
-
};
|
|
29
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
30
|
-
var src_exports = {};
|
|
31
|
-
__export(src_exports, {
|
|
32
|
-
XmlCdata: () => XmlCdata,
|
|
33
|
-
XmlComment: () => XmlComment,
|
|
34
|
-
XmlDeclaration: () => XmlDeclaration,
|
|
35
|
-
XmlDocument: () => XmlDocument,
|
|
36
|
-
XmlDocumentType: () => XmlDocumentType,
|
|
37
|
-
XmlElement: () => XmlElement,
|
|
38
|
-
XmlError: () => XmlError,
|
|
39
|
-
XmlNode: () => XmlNode,
|
|
40
|
-
XmlProcessingInstruction: () => XmlProcessingInstruction,
|
|
41
|
-
XmlText: () => XmlText,
|
|
42
|
-
parseXml: () => parseXml
|
|
43
|
-
});
|
|
44
|
-
module.exports = __toCommonJS(src_exports);
|
|
45
|
-
var emptyString = "";
|
|
46
|
-
var surrogatePair = /[\uD800-\uDBFF][\uDC00-\uDFFF]/g;
|
|
47
|
-
var StringScanner = class {
|
|
48
|
-
constructor(string) {
|
|
49
|
-
this.k = this.u(string, true);
|
|
50
|
-
this.d = 0;
|
|
51
|
-
this.length = string.length;
|
|
52
|
-
this.l = this.k !== this.length;
|
|
53
|
-
this.h = string;
|
|
54
|
-
if (this.l) {
|
|
55
|
-
let charsToBytes = [];
|
|
56
|
-
for (let byteIndex = 0, charIndex = 0; charIndex < this.k; ++charIndex) {
|
|
57
|
-
charsToBytes[charIndex] = byteIndex;
|
|
58
|
-
byteIndex += string.codePointAt(byteIndex) > 65535 ? 2 : 1;
|
|
59
|
-
}
|
|
60
|
-
this.A = charsToBytes;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
/**
|
|
64
|
-
* Whether the current character index is at the end of the input string.
|
|
65
|
-
*/
|
|
66
|
-
get B() {
|
|
67
|
-
return this.d >= this.k;
|
|
68
|
-
}
|
|
69
|
-
/**
|
|
70
|
-
* Returns the number of characters in the given string, which may differ from
|
|
71
|
-
* the byte length if the string contains multibyte characters.
|
|
72
|
-
*/
|
|
73
|
-
u(string, multiByteSafe = this.l) {
|
|
74
|
-
return multiByteSafe ? string.replace(surrogatePair, "_").length : string.length;
|
|
75
|
-
}
|
|
76
|
-
/**
|
|
77
|
-
* Advances the scanner by the given number of characters, stopping if the end
|
|
78
|
-
* of the string is reached.
|
|
79
|
-
*/
|
|
80
|
-
p(count = 1) {
|
|
81
|
-
this.d = Math.min(this.k, this.d + count);
|
|
82
|
-
}
|
|
83
|
-
/**
|
|
84
|
-
* Returns the byte index of the given character index in the string. The two
|
|
85
|
-
* may differ in strings that contain multibyte characters.
|
|
86
|
-
*/
|
|
87
|
-
f(charIndex = this.d) {
|
|
88
|
-
var _a;
|
|
89
|
-
return this.l ? (_a = this.A[charIndex]) != null ? _a : Infinity : charIndex;
|
|
90
|
-
}
|
|
91
|
-
/**
|
|
92
|
-
* Consumes and returns the given number of characters if possible, advancing
|
|
93
|
-
* the scanner and stopping if the end of the string is reached.
|
|
94
|
-
*
|
|
95
|
-
* If no characters could be consumed, an empty string will be returned.
|
|
96
|
-
*/
|
|
97
|
-
G(charCount = 1) {
|
|
98
|
-
let chars = this.m(charCount);
|
|
99
|
-
this.p(charCount);
|
|
100
|
-
return chars;
|
|
101
|
-
}
|
|
102
|
-
/**
|
|
103
|
-
* Consumes and returns the given number of bytes if possible, advancing the
|
|
104
|
-
* scanner and stopping if the end of the string is reached.
|
|
105
|
-
*
|
|
106
|
-
* It's up to the caller to ensure that the given byte count doesn't split a
|
|
107
|
-
* multibyte character.
|
|
108
|
-
*
|
|
109
|
-
* If no bytes could be consumed, an empty string will be returned.
|
|
110
|
-
*/
|
|
111
|
-
v(byteCount) {
|
|
112
|
-
let byteIndex = this.f();
|
|
113
|
-
let result = this.h.slice(byteIndex, byteIndex + byteCount);
|
|
114
|
-
this.p(this.u(result));
|
|
115
|
-
return result;
|
|
116
|
-
}
|
|
117
|
-
/**
|
|
118
|
-
* Consumes and returns all characters for which the given function returns
|
|
119
|
-
* `true`, stopping when `false` is returned or the end of the input is
|
|
120
|
-
* reached.
|
|
121
|
-
*/
|
|
122
|
-
w(fn) {
|
|
123
|
-
let { length, l: multiByteMode, h: string } = this;
|
|
124
|
-
let startByteIndex = this.f();
|
|
125
|
-
let endByteIndex = startByteIndex;
|
|
126
|
-
if (multiByteMode) while (endByteIndex < length) {
|
|
127
|
-
let char = string[endByteIndex];
|
|
128
|
-
let isSurrogatePair = char >= "\ud800" && char <= "\udbff";
|
|
129
|
-
if (isSurrogatePair) char += string[endByteIndex + 1];
|
|
130
|
-
if (!fn(char)) break;
|
|
131
|
-
endByteIndex += isSurrogatePair ? 2 : 1;
|
|
132
|
-
}
|
|
133
|
-
else while (endByteIndex < length && fn(string[endByteIndex])) ++endByteIndex;
|
|
134
|
-
return this.v(endByteIndex - startByteIndex);
|
|
135
|
-
}
|
|
136
|
-
/**
|
|
137
|
-
* Consumes the given string if it exists at the current character index, and
|
|
138
|
-
* advances the scanner.
|
|
139
|
-
*
|
|
140
|
-
* If the given string doesn't exist at the current character index, an empty
|
|
141
|
-
* string will be returned and the scanner will not be advanced.
|
|
142
|
-
*/
|
|
143
|
-
b(stringToConsume) {
|
|
144
|
-
let { length } = stringToConsume;
|
|
145
|
-
let byteIndex = this.f();
|
|
146
|
-
if (stringToConsume === this.h.slice(byteIndex, byteIndex + length)) {
|
|
147
|
-
this.p(length === 1 ? 1 : this.u(stringToConsume));
|
|
148
|
-
return stringToConsume;
|
|
149
|
-
}
|
|
150
|
-
return emptyString;
|
|
151
|
-
}
|
|
152
|
-
/**
|
|
153
|
-
* Consumes characters until the given global regex is matched, advancing the
|
|
154
|
-
* scanner up to (but not beyond) the beginning of the match. If the regex
|
|
155
|
-
* doesn't match, nothing will be consumed.
|
|
156
|
-
*
|
|
157
|
-
* Returns the consumed string, or an empty string if nothing was consumed.
|
|
158
|
-
*/
|
|
159
|
-
x(regex) {
|
|
160
|
-
let matchByteIndex = this.h.slice(this.f()).search(regex);
|
|
161
|
-
return matchByteIndex > 0 ? this.v(matchByteIndex) : emptyString;
|
|
162
|
-
}
|
|
163
|
-
/**
|
|
164
|
-
* Consumes characters until the given string is found, advancing the scanner
|
|
165
|
-
* up to (but not beyond) that point. If the string is never found, nothing
|
|
166
|
-
* will be consumed.
|
|
167
|
-
*
|
|
168
|
-
* Returns the consumed string, or an empty string if nothing was consumed.
|
|
169
|
-
*/
|
|
170
|
-
s(searchString) {
|
|
171
|
-
let byteIndex = this.f();
|
|
172
|
-
let matchByteIndex = this.h.indexOf(searchString, byteIndex);
|
|
173
|
-
return matchByteIndex > 0 ? this.v(matchByteIndex - byteIndex) : emptyString;
|
|
174
|
-
}
|
|
175
|
-
/**
|
|
176
|
-
* Returns the given number of characters starting at the current character
|
|
177
|
-
* index, without advancing the scanner and without exceeding the end of the
|
|
178
|
-
* input string.
|
|
179
|
-
*/
|
|
180
|
-
m(count = 1) {
|
|
181
|
-
let { d: charIndex, h: string } = this;
|
|
182
|
-
return this.l ? string.slice(this.f(charIndex), this.f(charIndex + count)) : string.slice(charIndex, charIndex + count);
|
|
183
|
-
}
|
|
184
|
-
/**
|
|
185
|
-
* Resets the scanner position to the given character _index_, or to the start
|
|
186
|
-
* of the input string if no index is given.
|
|
187
|
-
*
|
|
188
|
-
* If _index_ is negative, the scanner position will be moved backward by that
|
|
189
|
-
* many characters, stopping if the beginning of the string is reached.
|
|
190
|
-
*/
|
|
191
|
-
n(index = 0) {
|
|
192
|
-
this.d = index >= 0 ? Math.min(this.k, index) : Math.max(0, this.d + index);
|
|
193
|
-
}
|
|
194
|
-
};
|
|
195
|
-
var attValueCharDoubleQuote = /["&<]/;
|
|
196
|
-
var attValueCharSingleQuote = /['&<]/;
|
|
197
|
-
var attValueNormalizedWhitespace = /\r\n|[\n\r\t]/g;
|
|
198
|
-
var endCharData = /<|&|]]>/;
|
|
199
|
-
var predefinedEntities = Object.freeze(Object.assign(/* @__PURE__ */ Object.create(null), {
|
|
200
|
-
amp: "&",
|
|
201
|
-
apos: "'",
|
|
202
|
-
gt: ">",
|
|
203
|
-
lt: "<",
|
|
204
|
-
quot: "\""
|
|
205
|
-
}));
|
|
206
|
-
function isNameChar(char) {
|
|
207
|
-
let cp = char.codePointAt(0);
|
|
208
|
-
return cp >= 97 && cp <= 122 || cp >= 65 && cp <= 90 || cp >= 48 && cp <= 57 || cp === 45 || cp === 46 || cp === 183 || cp >= 768 && cp <= 879 || cp === 8255 || cp === 8256 || isNameStartChar(char, cp);
|
|
209
|
-
}
|
|
210
|
-
function isNameStartChar(char, cp = char.codePointAt(0)) {
|
|
211
|
-
return cp >= 97 && cp <= 122 || cp >= 65 && cp <= 90 || cp === 58 || cp === 95 || cp >= 192 && cp <= 214 || cp >= 216 && cp <= 246 || cp >= 248 && cp <= 767 || cp >= 880 && cp <= 893 || cp >= 895 && cp <= 8191 || cp === 8204 || cp === 8205 || cp >= 8304 && cp <= 8591 || cp >= 11264 && cp <= 12271 || cp >= 12289 && cp <= 55295 || cp >= 63744 && cp <= 64975 || cp >= 65008 && cp <= 65533 || cp >= 65536 && cp <= 983039;
|
|
212
|
-
}
|
|
213
|
-
function isReferenceChar(char) {
|
|
214
|
-
return char === "#" || isNameChar(char);
|
|
215
|
-
}
|
|
216
|
-
function isWhitespace(char) {
|
|
217
|
-
let cp = char.codePointAt(0);
|
|
218
|
-
return cp === 32 || cp === 9 || cp === 10 || cp === 13;
|
|
219
|
-
}
|
|
220
|
-
function isXmlCodePoint(cp) {
|
|
221
|
-
return cp >= 32 && cp <= 55295 || cp === 10 || cp === 9 || cp === 13 || cp >= 57344 && cp <= 65533 || cp >= 65536 && cp <= 1114111;
|
|
222
|
-
}
|
|
223
|
-
var _XmlNode = class _XmlNode {
|
|
224
|
-
constructor() {
|
|
225
|
-
/**
|
|
226
|
-
* Parent node of this node, or `null` if this node has no parent.
|
|
227
|
-
*/
|
|
228
|
-
this.parent = null;
|
|
229
|
-
/**
|
|
230
|
-
* Starting byte offset of this node in the original XML string, or `-1` if
|
|
231
|
-
* the offset is unknown.
|
|
232
|
-
*/
|
|
233
|
-
this.start = -1;
|
|
234
|
-
/**
|
|
235
|
-
* Ending byte offset of this node in the original XML string, or `-1` if the
|
|
236
|
-
* offset is unknown.
|
|
237
|
-
*/
|
|
238
|
-
this.end = -1;
|
|
239
|
-
}
|
|
240
|
-
/**
|
|
241
|
-
* Document that contains this node, or `null` if this node is not associated
|
|
242
|
-
* with a document.
|
|
243
|
-
*/
|
|
244
|
-
get document() {
|
|
245
|
-
var _a, _b;
|
|
246
|
-
return (_b = (_a = this.parent) == null ? void 0 : _a.document) != null ? _b : null;
|
|
247
|
-
}
|
|
248
|
-
/**
|
|
249
|
-
* Whether this node is the root node of the document (also known as the
|
|
250
|
-
* document element).
|
|
251
|
-
*/
|
|
252
|
-
get isRootNode() {
|
|
253
|
-
return this.parent !== null && this.parent === this.document && this.type === _XmlNode.TYPE_ELEMENT;
|
|
254
|
-
}
|
|
255
|
-
/**
|
|
256
|
-
* Whether whitespace should be preserved in the content of this element and
|
|
257
|
-
* its children.
|
|
258
|
-
*
|
|
259
|
-
* This is influenced by the value of the special `xml:space` attribute, and
|
|
260
|
-
* will be `true` for any node whose `xml:space` attribute is set to
|
|
261
|
-
* "preserve". If a node has no such attribute, it will inherit the value of
|
|
262
|
-
* the nearest ancestor that does (if any).
|
|
263
|
-
*
|
|
264
|
-
* @see https://www.w3.org/TR/2008/REC-xml-20081126/#sec-white-space
|
|
265
|
-
*/
|
|
266
|
-
get preserveWhitespace() {
|
|
267
|
-
var _a;
|
|
268
|
-
return !!((_a = this.parent) == null ? void 0 : _a.preserveWhitespace);
|
|
269
|
-
}
|
|
270
|
-
/**
|
|
271
|
-
* Type of this node.
|
|
272
|
-
*
|
|
273
|
-
* The value of this property is a string that matches one of the static
|
|
274
|
-
* `TYPE_*` properties on the `XmlNode` class (e.g. `TYPE_ELEMENT`,
|
|
275
|
-
* `TYPE_TEXT`, etc.).
|
|
276
|
-
*
|
|
277
|
-
* The `XmlNode` class itself is a base class and doesn't have its own type
|
|
278
|
-
* name.
|
|
279
|
-
*/
|
|
280
|
-
get type() {
|
|
281
|
-
return "";
|
|
282
|
-
}
|
|
283
|
-
/**
|
|
284
|
-
* Returns a JSON-serializable object representing this node, minus properties
|
|
285
|
-
* that could result in circular references.
|
|
286
|
-
*/
|
|
287
|
-
toJSON() {
|
|
288
|
-
let json = { type: this.type };
|
|
289
|
-
if (this.isRootNode) json.isRootNode = true;
|
|
290
|
-
if (this.preserveWhitespace) json.preserveWhitespace = true;
|
|
291
|
-
if (this.start !== -1) {
|
|
292
|
-
json.start = this.start;
|
|
293
|
-
json.end = this.end;
|
|
294
|
-
}
|
|
295
|
-
return json;
|
|
296
|
-
}
|
|
297
|
-
};
|
|
298
|
-
/**
|
|
299
|
-
* Type value for an `XmlCdata` node.
|
|
300
|
-
*/
|
|
301
|
-
_XmlNode.TYPE_CDATA = "cdata";
|
|
302
|
-
/**
|
|
303
|
-
* Type value for an `XmlComment` node.
|
|
304
|
-
*/
|
|
305
|
-
_XmlNode.TYPE_COMMENT = "comment";
|
|
306
|
-
/**
|
|
307
|
-
* Type value for an `XmlDocument` node.
|
|
308
|
-
*/
|
|
309
|
-
_XmlNode.TYPE_DOCUMENT = "document";
|
|
310
|
-
/**
|
|
311
|
-
* Type value for an `XmlDocumentType` node.
|
|
312
|
-
*/
|
|
313
|
-
_XmlNode.TYPE_DOCUMENT_TYPE = "doctype";
|
|
314
|
-
/**
|
|
315
|
-
* Type value for an `XmlElement` node.
|
|
316
|
-
*/
|
|
317
|
-
_XmlNode.TYPE_ELEMENT = "element";
|
|
318
|
-
/**
|
|
319
|
-
* Type value for an `XmlProcessingInstruction` node.
|
|
320
|
-
*/
|
|
321
|
-
_XmlNode.TYPE_PROCESSING_INSTRUCTION = "pi";
|
|
322
|
-
/**
|
|
323
|
-
* Type value for an `XmlText` node.
|
|
324
|
-
*/
|
|
325
|
-
_XmlNode.TYPE_TEXT = "text";
|
|
326
|
-
/**
|
|
327
|
-
* Type value for an `XmlDeclaration` node.
|
|
328
|
-
*/
|
|
329
|
-
_XmlNode.TYPE_XML_DECLARATION = "xmldecl";
|
|
330
|
-
var XmlNode = _XmlNode;
|
|
331
|
-
var XmlText = class extends XmlNode {
|
|
332
|
-
constructor(text = "") {
|
|
333
|
-
super();
|
|
334
|
-
this.text = text;
|
|
335
|
-
}
|
|
336
|
-
get type() {
|
|
337
|
-
return XmlNode.TYPE_TEXT;
|
|
338
|
-
}
|
|
339
|
-
toJSON() {
|
|
340
|
-
return Object.assign(XmlNode.prototype.toJSON.call(this), { text: this.text });
|
|
341
|
-
}
|
|
342
|
-
};
|
|
343
|
-
var XmlCdata = class extends XmlText {
|
|
344
|
-
get type() {
|
|
345
|
-
return XmlNode.TYPE_CDATA;
|
|
346
|
-
}
|
|
347
|
-
};
|
|
348
|
-
var XmlComment = class extends XmlNode {
|
|
349
|
-
constructor(content = "") {
|
|
350
|
-
super();
|
|
351
|
-
this.content = content;
|
|
352
|
-
}
|
|
353
|
-
get type() {
|
|
354
|
-
return XmlNode.TYPE_COMMENT;
|
|
355
|
-
}
|
|
356
|
-
toJSON() {
|
|
357
|
-
return Object.assign(XmlNode.prototype.toJSON.call(this), { content: this.content });
|
|
358
|
-
}
|
|
359
|
-
};
|
|
360
|
-
var XmlDeclaration = class extends XmlNode {
|
|
361
|
-
constructor(version, encoding, standalone) {
|
|
362
|
-
super();
|
|
363
|
-
this.version = version;
|
|
364
|
-
this.encoding = encoding != null ? encoding : null;
|
|
365
|
-
this.standalone = standalone != null ? standalone : null;
|
|
366
|
-
}
|
|
367
|
-
get type() {
|
|
368
|
-
return XmlNode.TYPE_XML_DECLARATION;
|
|
369
|
-
}
|
|
370
|
-
toJSON() {
|
|
371
|
-
let json = XmlNode.prototype.toJSON.call(this);
|
|
372
|
-
json.version = this.version;
|
|
373
|
-
for (let key of ["encoding", "standalone"]) if (this[key] !== null) json[key] = this[key];
|
|
374
|
-
return json;
|
|
375
|
-
}
|
|
376
|
-
};
|
|
377
|
-
var XmlElement = class _XmlElement extends XmlNode {
|
|
378
|
-
constructor(name, attributes = /* @__PURE__ */ Object.create(null), children = []) {
|
|
379
|
-
super();
|
|
380
|
-
this.name = name;
|
|
381
|
-
this.attributes = attributes;
|
|
382
|
-
this.children = children;
|
|
383
|
-
}
|
|
384
|
-
/**
|
|
385
|
-
* Whether this element is empty (meaning it has no children).
|
|
386
|
-
*/
|
|
387
|
-
get isEmpty() {
|
|
388
|
-
return this.children.length === 0;
|
|
389
|
-
}
|
|
390
|
-
get preserveWhitespace() {
|
|
391
|
-
let node = this;
|
|
392
|
-
while (node instanceof _XmlElement) {
|
|
393
|
-
if ("xml:space" in node.attributes) return node.attributes["xml:space"] === "preserve";
|
|
394
|
-
node = node.parent;
|
|
395
|
-
}
|
|
396
|
-
return false;
|
|
397
|
-
}
|
|
398
|
-
/**
|
|
399
|
-
* Text content of this element and all its descendants.
|
|
400
|
-
*/
|
|
401
|
-
get text() {
|
|
402
|
-
return this.children.map((child) => "text" in child ? child.text : "").join("");
|
|
403
|
-
}
|
|
404
|
-
get type() {
|
|
405
|
-
return XmlNode.TYPE_ELEMENT;
|
|
406
|
-
}
|
|
407
|
-
toJSON() {
|
|
408
|
-
return Object.assign(XmlNode.prototype.toJSON.call(this), {
|
|
409
|
-
name: this.name,
|
|
410
|
-
attributes: this.attributes,
|
|
411
|
-
children: this.children.map((child) => child.toJSON())
|
|
412
|
-
});
|
|
413
|
-
}
|
|
414
|
-
};
|
|
415
|
-
var XmlDocument = class extends XmlNode {
|
|
416
|
-
constructor(children = []) {
|
|
417
|
-
super();
|
|
418
|
-
this.children = children;
|
|
419
|
-
}
|
|
420
|
-
get document() {
|
|
421
|
-
return this;
|
|
422
|
-
}
|
|
423
|
-
/**
|
|
424
|
-
* Root element of this document, or `null` if this document is empty.
|
|
425
|
-
*/
|
|
426
|
-
get root() {
|
|
427
|
-
for (let child of this.children) if (child instanceof XmlElement) return child;
|
|
428
|
-
return null;
|
|
429
|
-
}
|
|
430
|
-
/**
|
|
431
|
-
* Text content of this document and all its descendants.
|
|
432
|
-
*/
|
|
433
|
-
get text() {
|
|
434
|
-
return this.children.map((child) => "text" in child ? child.text : "").join("");
|
|
435
|
-
}
|
|
436
|
-
get type() {
|
|
437
|
-
return XmlNode.TYPE_DOCUMENT;
|
|
438
|
-
}
|
|
439
|
-
toJSON() {
|
|
440
|
-
return Object.assign(XmlNode.prototype.toJSON.call(this), { children: this.children.map((child) => child.toJSON()) });
|
|
441
|
-
}
|
|
442
|
-
};
|
|
443
|
-
var XmlDocumentType = class extends XmlNode {
|
|
444
|
-
constructor(name, publicId, systemId, internalSubset) {
|
|
445
|
-
super();
|
|
446
|
-
this.name = name;
|
|
447
|
-
this.publicId = publicId != null ? publicId : null;
|
|
448
|
-
this.systemId = systemId != null ? systemId : null;
|
|
449
|
-
this.internalSubset = internalSubset != null ? internalSubset : null;
|
|
450
|
-
}
|
|
451
|
-
get type() {
|
|
452
|
-
return XmlNode.TYPE_DOCUMENT_TYPE;
|
|
453
|
-
}
|
|
454
|
-
toJSON() {
|
|
455
|
-
let json = XmlNode.prototype.toJSON.call(this);
|
|
456
|
-
json.name = this.name;
|
|
457
|
-
for (let key of [
|
|
458
|
-
"publicId",
|
|
459
|
-
"systemId",
|
|
460
|
-
"internalSubset"
|
|
461
|
-
]) if (this[key] !== null) json[key] = this[key];
|
|
462
|
-
return json;
|
|
463
|
-
}
|
|
464
|
-
};
|
|
465
|
-
var XmlError = class extends Error {
|
|
466
|
-
constructor(message, charIndex, xml) {
|
|
467
|
-
let column = 1;
|
|
468
|
-
let excerpt = "";
|
|
469
|
-
let line = 1;
|
|
470
|
-
for (let i = 0; i < charIndex; ++i) {
|
|
471
|
-
let char = xml[i];
|
|
472
|
-
if (char === "\n") {
|
|
473
|
-
column = 1;
|
|
474
|
-
excerpt = "";
|
|
475
|
-
line += 1;
|
|
476
|
-
} else {
|
|
477
|
-
column += 1;
|
|
478
|
-
excerpt += char;
|
|
479
|
-
}
|
|
480
|
-
}
|
|
481
|
-
let eol = xml.indexOf("\n", charIndex);
|
|
482
|
-
excerpt += eol === -1 ? xml.slice(charIndex) : xml.slice(charIndex, eol);
|
|
483
|
-
let excerptStart = 0;
|
|
484
|
-
if (excerpt.length > 50) if (column < 40) excerpt = excerpt.slice(0, 50);
|
|
485
|
-
else {
|
|
486
|
-
excerptStart = column - 20;
|
|
487
|
-
excerpt = excerpt.slice(excerptStart, column + 30);
|
|
488
|
-
}
|
|
489
|
-
super(`${message} (line ${line}, column ${column})
|
|
490
|
-
${excerpt}
|
|
491
|
-
` + " ".repeat(column - excerptStart + 1) + "^\n");
|
|
492
|
-
this.column = column;
|
|
493
|
-
this.excerpt = excerpt;
|
|
494
|
-
this.line = line;
|
|
495
|
-
this.name = "XmlError";
|
|
496
|
-
this.pos = charIndex;
|
|
497
|
-
}
|
|
498
|
-
};
|
|
499
|
-
var XmlProcessingInstruction = class extends XmlNode {
|
|
500
|
-
constructor(name, content = "") {
|
|
501
|
-
super();
|
|
502
|
-
this.name = name;
|
|
503
|
-
this.content = content;
|
|
504
|
-
}
|
|
505
|
-
get type() {
|
|
506
|
-
return XmlNode.TYPE_PROCESSING_INSTRUCTION;
|
|
507
|
-
}
|
|
508
|
-
toJSON() {
|
|
509
|
-
return Object.assign(XmlNode.prototype.toJSON.call(this), {
|
|
510
|
-
name: this.name,
|
|
511
|
-
content: this.content
|
|
512
|
-
});
|
|
513
|
-
}
|
|
514
|
-
};
|
|
515
|
-
var emptyString2 = "";
|
|
516
|
-
var Parser = class {
|
|
517
|
-
/**
|
|
518
|
-
* @param xml XML string to parse.
|
|
519
|
-
* @param options Parser options.
|
|
520
|
-
*/
|
|
521
|
-
constructor(xml, options = {}) {
|
|
522
|
-
let doc = this.document = new XmlDocument();
|
|
523
|
-
this.j = doc;
|
|
524
|
-
this.g = options;
|
|
525
|
-
this.c = new StringScanner(xml);
|
|
526
|
-
if (this.g.includeOffsets) {
|
|
527
|
-
doc.start = 0;
|
|
528
|
-
doc.end = xml.length;
|
|
529
|
-
}
|
|
530
|
-
this.parse();
|
|
531
|
-
}
|
|
532
|
-
/**
|
|
533
|
-
* Adds the given `XmlNode` as a child of `this.currentNode`.
|
|
534
|
-
*/
|
|
535
|
-
i(node, charIndex) {
|
|
536
|
-
node.parent = this.j;
|
|
537
|
-
if (this.g.includeOffsets) {
|
|
538
|
-
node.start = this.c.f(charIndex);
|
|
539
|
-
node.end = this.c.f();
|
|
540
|
-
}
|
|
541
|
-
this.j.children.push(node);
|
|
542
|
-
return true;
|
|
543
|
-
}
|
|
544
|
-
/**
|
|
545
|
-
* Adds the given _text_ to the document, either by appending it to a
|
|
546
|
-
* preceding `XmlText` node (if possible) or by creating a new `XmlText` node.
|
|
547
|
-
*
|
|
548
|
-
* When _normalize_ is `true` (the default), line breaks in _text_ are
|
|
549
|
-
* normalized per section 2.11 of the XML spec. This must be `false` for text
|
|
550
|
-
* that comes from a character or entity reference, since references aren't
|
|
551
|
-
* subject to line break normalization.
|
|
552
|
-
*/
|
|
553
|
-
y(text, charIndex, normalize = true) {
|
|
554
|
-
let { children } = this.j;
|
|
555
|
-
let { length } = children;
|
|
556
|
-
if (normalize) text = normalizeLineBreaks(text);
|
|
557
|
-
if (length > 0) {
|
|
558
|
-
let prevNode = children[length - 1];
|
|
559
|
-
if ((prevNode == null ? void 0 : prevNode.type) === XmlNode.TYPE_TEXT) {
|
|
560
|
-
let textNode = prevNode;
|
|
561
|
-
textNode.text += text;
|
|
562
|
-
if (this.g.includeOffsets) textNode.end = this.c.f();
|
|
563
|
-
return true;
|
|
564
|
-
}
|
|
565
|
-
}
|
|
566
|
-
return this.i(new XmlText(text), charIndex);
|
|
567
|
-
}
|
|
568
|
-
/**
|
|
569
|
-
* Consumes element attributes.
|
|
570
|
-
*
|
|
571
|
-
* @see https://www.w3.org/TR/2008/REC-xml-20081126/#sec-starttags
|
|
572
|
-
*/
|
|
573
|
-
H() {
|
|
574
|
-
let attributes = /* @__PURE__ */ Object.create(null);
|
|
575
|
-
while (this.e()) {
|
|
576
|
-
let attrName = this.q();
|
|
577
|
-
if (!attrName) break;
|
|
578
|
-
let attrValue = this.t() && this.I();
|
|
579
|
-
if (attrValue === false) throw this.a("Attribute value expected");
|
|
580
|
-
if (attrName in attributes) throw this.a(`Duplicate attribute: ${attrName}`);
|
|
581
|
-
if (attrName === "xml:space" && attrValue !== "default" && attrValue !== "preserve") throw this.a("Value of the `xml:space` attribute must be \"default\" or \"preserve\"");
|
|
582
|
-
attributes[attrName] = attrValue;
|
|
583
|
-
}
|
|
584
|
-
if (this.g.sortAttributes) {
|
|
585
|
-
let attrNames = Object.keys(attributes).sort();
|
|
586
|
-
let sortedAttributes = /* @__PURE__ */ Object.create(null);
|
|
587
|
-
for (let i = 0; i < attrNames.length; ++i) {
|
|
588
|
-
let attrName = attrNames[i];
|
|
589
|
-
sortedAttributes[attrName] = attributes[attrName];
|
|
590
|
-
}
|
|
591
|
-
attributes = sortedAttributes;
|
|
592
|
-
}
|
|
593
|
-
return attributes;
|
|
594
|
-
}
|
|
595
|
-
/**
|
|
596
|
-
* Consumes an `AttValue` (attribute value) if possible.
|
|
597
|
-
*
|
|
598
|
-
* @returns
|
|
599
|
-
* Contents of the `AttValue` minus quotes, or `false` if nothing was
|
|
600
|
-
* consumed. An empty string indicates that an `AttValue` was consumed but
|
|
601
|
-
* was empty.
|
|
602
|
-
*
|
|
603
|
-
* @see https://www.w3.org/TR/2008/REC-xml-20081126/#NT-AttValue
|
|
604
|
-
*/
|
|
605
|
-
I() {
|
|
606
|
-
let { c: scanner } = this;
|
|
607
|
-
let quote = scanner.m();
|
|
608
|
-
if (quote !== "\"" && quote !== "'") return false;
|
|
609
|
-
scanner.p();
|
|
610
|
-
let chars;
|
|
611
|
-
let isClosed = false;
|
|
612
|
-
let value = emptyString2;
|
|
613
|
-
let regex = quote === "\"" ? attValueCharDoubleQuote : attValueCharSingleQuote;
|
|
614
|
-
matchLoop: while (!scanner.B) {
|
|
615
|
-
chars = scanner.x(regex);
|
|
616
|
-
if (chars) {
|
|
617
|
-
this.o(chars);
|
|
618
|
-
value += chars.replace(attValueNormalizedWhitespace, " ");
|
|
619
|
-
}
|
|
620
|
-
switch (scanner.m()) {
|
|
621
|
-
case quote:
|
|
622
|
-
isClosed = true;
|
|
623
|
-
break matchLoop;
|
|
624
|
-
case "&":
|
|
625
|
-
value += this.C();
|
|
626
|
-
continue;
|
|
627
|
-
case "<": throw this.a("Unescaped `<` is not allowed in an attribute value");
|
|
628
|
-
default: break matchLoop;
|
|
629
|
-
}
|
|
630
|
-
}
|
|
631
|
-
if (!isClosed) throw this.a("Unclosed attribute");
|
|
632
|
-
scanner.p();
|
|
633
|
-
return value;
|
|
634
|
-
}
|
|
635
|
-
/**
|
|
636
|
-
* Consumes a CDATA section if possible.
|
|
637
|
-
*
|
|
638
|
-
* @returns Whether a CDATA section was consumed.
|
|
639
|
-
* @see https://www.w3.org/TR/2008/REC-xml-20081126/#sec-cdata-sect
|
|
640
|
-
*/
|
|
641
|
-
J() {
|
|
642
|
-
let { c: scanner } = this;
|
|
643
|
-
let startIndex = scanner.d;
|
|
644
|
-
if (!scanner.b("<![CDATA[")) return false;
|
|
645
|
-
let text = scanner.s("]]>");
|
|
646
|
-
this.o(text);
|
|
647
|
-
if (!scanner.b("]]>")) throw this.a("Unclosed CDATA section");
|
|
648
|
-
return this.g.preserveCdata ? this.i(new XmlCdata(normalizeLineBreaks(text)), startIndex) : this.y(text, startIndex);
|
|
649
|
-
}
|
|
650
|
-
/**
|
|
651
|
-
* Consumes character data if possible.
|
|
652
|
-
*
|
|
653
|
-
* @returns Whether character data was consumed.
|
|
654
|
-
* @see https://www.w3.org/TR/2008/REC-xml-20081126/#dt-chardata
|
|
655
|
-
*/
|
|
656
|
-
K() {
|
|
657
|
-
let { c: scanner } = this;
|
|
658
|
-
let startIndex = scanner.d;
|
|
659
|
-
let charData = scanner.x(endCharData);
|
|
660
|
-
if (!charData) return false;
|
|
661
|
-
this.o(charData);
|
|
662
|
-
if (scanner.m(3) === "]]>") throw this.a("Element content may not contain the CDATA section close delimiter `]]>`");
|
|
663
|
-
return this.y(charData, startIndex);
|
|
664
|
-
}
|
|
665
|
-
/**
|
|
666
|
-
* Consumes a comment if possible.
|
|
667
|
-
*
|
|
668
|
-
* @returns Whether a comment was consumed.
|
|
669
|
-
* @see https://www.w3.org/TR/2008/REC-xml-20081126/#NT-Comment
|
|
670
|
-
*/
|
|
671
|
-
D() {
|
|
672
|
-
let { c: scanner } = this;
|
|
673
|
-
let startIndex = scanner.d;
|
|
674
|
-
if (!scanner.b("<!--")) return false;
|
|
675
|
-
let content = scanner.s("--");
|
|
676
|
-
this.o(content);
|
|
677
|
-
if (!scanner.b("-->")) {
|
|
678
|
-
if (scanner.m(2) === "--") throw this.a("The string `--` isn't allowed inside a comment");
|
|
679
|
-
throw this.a("Unclosed comment");
|
|
680
|
-
}
|
|
681
|
-
return this.g.preserveComments ? this.i(new XmlComment(normalizeLineBreaks(content)), startIndex) : true;
|
|
682
|
-
}
|
|
683
|
-
/**
|
|
684
|
-
* Consumes a reference in a content context if possible.
|
|
685
|
-
*
|
|
686
|
-
* This differs from `consumeReference()` in that a consumed reference will be
|
|
687
|
-
* added to the document as a text node instead of returned.
|
|
688
|
-
*
|
|
689
|
-
* @returns Whether a reference was consumed.
|
|
690
|
-
* @see https://www.w3.org/TR/2008/REC-xml-20081126/#entproc
|
|
691
|
-
*/
|
|
692
|
-
L() {
|
|
693
|
-
let startIndex = this.c.d;
|
|
694
|
-
let ref = this.C();
|
|
695
|
-
return ref ? this.y(ref, startIndex, false) : false;
|
|
696
|
-
}
|
|
697
|
-
/**
|
|
698
|
-
* Consumes a doctype declaration if possible.
|
|
699
|
-
*
|
|
700
|
-
* This is a loose implementation since doctype declarations are currently
|
|
701
|
-
* discarded without further parsing.
|
|
702
|
-
*
|
|
703
|
-
* @returns Whether a doctype declaration was consumed.
|
|
704
|
-
* @see https://www.w3.org/TR/2008/REC-xml-20081126/#dtd
|
|
705
|
-
*/
|
|
706
|
-
M() {
|
|
707
|
-
let { c: scanner } = this;
|
|
708
|
-
let startIndex = scanner.d;
|
|
709
|
-
if (!scanner.b("<!DOCTYPE")) return false;
|
|
710
|
-
let name = this.e() && this.q();
|
|
711
|
-
if (!name) throw this.a("Expected a name");
|
|
712
|
-
let publicId;
|
|
713
|
-
let systemId;
|
|
714
|
-
if (this.e()) {
|
|
715
|
-
if (scanner.b("PUBLIC")) {
|
|
716
|
-
publicId = this.e() && this.N();
|
|
717
|
-
if (publicId === false) throw this.a("Expected a public identifier");
|
|
718
|
-
this.e();
|
|
719
|
-
}
|
|
720
|
-
if (publicId !== void 0 || scanner.b("SYSTEM")) {
|
|
721
|
-
this.e();
|
|
722
|
-
systemId = this.r();
|
|
723
|
-
if (systemId === false) throw this.a("Expected a system identifier");
|
|
724
|
-
this.e();
|
|
725
|
-
}
|
|
726
|
-
}
|
|
727
|
-
let internalSubset;
|
|
728
|
-
if (scanner.b("[")) {
|
|
729
|
-
internalSubset = scanner.x(/\][\x20\t\r\n]*>/);
|
|
730
|
-
if (!scanner.b("]")) throw this.a("Unclosed internal subset");
|
|
731
|
-
this.e();
|
|
732
|
-
}
|
|
733
|
-
if (!scanner.b(">")) throw this.a("Unclosed doctype declaration");
|
|
734
|
-
return this.g.preserveDocumentType ? this.i(new XmlDocumentType(name, publicId, systemId, internalSubset), startIndex) : true;
|
|
735
|
-
}
|
|
736
|
-
/**
|
|
737
|
-
* Consumes an element if possible.
|
|
738
|
-
*
|
|
739
|
-
* @returns Whether an element was consumed.
|
|
740
|
-
* @see https://www.w3.org/TR/2008/REC-xml-20081126/#NT-element
|
|
741
|
-
*/
|
|
742
|
-
E() {
|
|
743
|
-
let { c: scanner } = this;
|
|
744
|
-
let startIndex = scanner.d;
|
|
745
|
-
if (!scanner.b("<")) return false;
|
|
746
|
-
let name = this.q();
|
|
747
|
-
if (!name) {
|
|
748
|
-
scanner.n(startIndex);
|
|
749
|
-
return false;
|
|
750
|
-
}
|
|
751
|
-
let attributes = this.H();
|
|
752
|
-
let isEmpty = !!scanner.b("/>");
|
|
753
|
-
let element = new XmlElement(name, attributes);
|
|
754
|
-
element.parent = this.j;
|
|
755
|
-
if (!isEmpty) {
|
|
756
|
-
if (!scanner.b(">")) throw this.a(`Unclosed start tag for element \`${name}\``);
|
|
757
|
-
this.j = element;
|
|
758
|
-
do
|
|
759
|
-
this.K();
|
|
760
|
-
while (this.E() || this.L() || this.J() || this.F() || this.D());
|
|
761
|
-
let endTagMark = scanner.d;
|
|
762
|
-
let endTagName;
|
|
763
|
-
if (!scanner.b("</") || !(endTagName = this.q()) || endTagName !== name) {
|
|
764
|
-
scanner.n(endTagMark);
|
|
765
|
-
throw this.a(`Missing end tag for element ${name}`);
|
|
766
|
-
}
|
|
767
|
-
this.e();
|
|
768
|
-
if (!scanner.b(">")) throw this.a(`Unclosed end tag for element ${name}`);
|
|
769
|
-
this.j = element.parent;
|
|
770
|
-
}
|
|
771
|
-
return this.i(element, startIndex);
|
|
772
|
-
}
|
|
773
|
-
/**
|
|
774
|
-
* Consumes an `Eq` production if possible.
|
|
775
|
-
*
|
|
776
|
-
* @returns Whether an `Eq` production was consumed.
|
|
777
|
-
* @see https://www.w3.org/TR/2008/REC-xml-20081126/#NT-Eq
|
|
778
|
-
*/
|
|
779
|
-
t() {
|
|
780
|
-
this.e();
|
|
781
|
-
if (this.c.b("=")) {
|
|
782
|
-
this.e();
|
|
783
|
-
return true;
|
|
784
|
-
}
|
|
785
|
-
return false;
|
|
786
|
-
}
|
|
787
|
-
/**
|
|
788
|
-
* Consumes `Misc` content if possible.
|
|
789
|
-
*
|
|
790
|
-
* @returns Whether anything was consumed.
|
|
791
|
-
* @see https://www.w3.org/TR/2008/REC-xml-20081126/#NT-Misc
|
|
792
|
-
*/
|
|
793
|
-
z() {
|
|
794
|
-
return this.D() || this.F() || this.e();
|
|
795
|
-
}
|
|
796
|
-
/**
|
|
797
|
-
* Consumes one or more `Name` characters if possible.
|
|
798
|
-
*
|
|
799
|
-
* @returns `Name` characters, or an empty string if none were consumed.
|
|
800
|
-
* @see https://www.w3.org/TR/2008/REC-xml-20081126/#NT-Name
|
|
801
|
-
*/
|
|
802
|
-
q() {
|
|
803
|
-
return isNameStartChar(this.c.m()) ? this.c.w(isNameChar) : emptyString2;
|
|
804
|
-
}
|
|
805
|
-
/**
|
|
806
|
-
* Consumes a processing instruction if possible.
|
|
807
|
-
*
|
|
808
|
-
* @returns Whether a processing instruction was consumed.
|
|
809
|
-
* @see https://www.w3.org/TR/2008/REC-xml-20081126/#sec-pi
|
|
810
|
-
*/
|
|
811
|
-
F() {
|
|
812
|
-
let { c: scanner } = this;
|
|
813
|
-
let startIndex = scanner.d;
|
|
814
|
-
if (!scanner.b("<?")) return false;
|
|
815
|
-
let name = this.q();
|
|
816
|
-
if (name) {
|
|
817
|
-
if (name.toLowerCase() === "xml") {
|
|
818
|
-
scanner.n(startIndex);
|
|
819
|
-
throw this.a("XML declaration isn't allowed here");
|
|
820
|
-
}
|
|
821
|
-
} else throw this.a("Invalid processing instruction");
|
|
822
|
-
if (!this.e()) {
|
|
823
|
-
if (scanner.b("?>")) return this.i(new XmlProcessingInstruction(name), startIndex);
|
|
824
|
-
throw this.a("Whitespace is required after a processing instruction name");
|
|
825
|
-
}
|
|
826
|
-
let content = scanner.s("?>");
|
|
827
|
-
this.o(content);
|
|
828
|
-
if (!scanner.b("?>")) throw this.a("Unterminated processing instruction");
|
|
829
|
-
return this.i(new XmlProcessingInstruction(name, normalizeLineBreaks(content)), startIndex);
|
|
830
|
-
}
|
|
831
|
-
/**
|
|
832
|
-
* Consumes a prolog if possible.
|
|
833
|
-
*
|
|
834
|
-
* @returns Whether a prolog was consumed.
|
|
835
|
-
* @see https://www.w3.org/TR/2008/REC-xml-20081126/#sec-prolog-dtd
|
|
836
|
-
*/
|
|
837
|
-
O() {
|
|
838
|
-
let { c: scanner } = this;
|
|
839
|
-
let startIndex = scanner.d;
|
|
840
|
-
this.P();
|
|
841
|
-
while (this.z());
|
|
842
|
-
if (this.M()) while (this.z());
|
|
843
|
-
return startIndex < scanner.d;
|
|
844
|
-
}
|
|
845
|
-
/**
|
|
846
|
-
* Consumes a public identifier literal if possible.
|
|
847
|
-
*
|
|
848
|
-
* @returns
|
|
849
|
-
* Value of the public identifier literal minus quotes, or `false` if
|
|
850
|
-
* nothing was consumed. An empty string indicates that a public id literal
|
|
851
|
-
* was consumed but was empty.
|
|
852
|
-
*
|
|
853
|
-
* @see https://www.w3.org/TR/2008/REC-xml-20081126/#NT-PubidLiteral
|
|
854
|
-
*/
|
|
855
|
-
N() {
|
|
856
|
-
let startIndex = this.c.d;
|
|
857
|
-
let value = this.r();
|
|
858
|
-
if (value !== false && !/^[-\x20\r\na-zA-Z0-9'()+,./:=?;!*#@$_%]*$/.test(value)) {
|
|
859
|
-
this.c.n(startIndex);
|
|
860
|
-
throw this.a("Invalid character in public identifier");
|
|
861
|
-
}
|
|
862
|
-
return value;
|
|
863
|
-
}
|
|
864
|
-
/**
|
|
865
|
-
* Consumes a reference if possible.
|
|
866
|
-
*
|
|
867
|
-
* This differs from `consumeContentReference()` in that a consumed reference
|
|
868
|
-
* will be returned rather than added to the document.
|
|
869
|
-
*
|
|
870
|
-
* @returns
|
|
871
|
-
* Parsed reference value, or `false` if nothing was consumed (to
|
|
872
|
-
* distinguish from a reference that resolves to an empty string).
|
|
873
|
-
*
|
|
874
|
-
* @see https://www.w3.org/TR/2008/REC-xml-20081126/#NT-Reference
|
|
875
|
-
*/
|
|
876
|
-
C() {
|
|
877
|
-
let { c: scanner } = this;
|
|
878
|
-
if (!scanner.b("&")) return false;
|
|
879
|
-
let ref = scanner.w(isReferenceChar);
|
|
880
|
-
if (scanner.G() !== ";") throw this.a("Unterminated reference (a reference must end with `;`)");
|
|
881
|
-
let parsedValue;
|
|
882
|
-
if (ref[0] === "#") {
|
|
883
|
-
let codePoint = ref[1] === "x" ? parseInt(ref.slice(2), 16) : parseInt(ref.slice(1), 10);
|
|
884
|
-
if (isNaN(codePoint)) throw this.a("Invalid character reference");
|
|
885
|
-
if (!isXmlCodePoint(codePoint)) throw this.a("Character reference resolves to an invalid character");
|
|
886
|
-
parsedValue = String.fromCodePoint(codePoint);
|
|
887
|
-
} else {
|
|
888
|
-
parsedValue = predefinedEntities[ref];
|
|
889
|
-
if (parsedValue === void 0) {
|
|
890
|
-
let { ignoreUndefinedEntities, resolveUndefinedEntity } = this.g;
|
|
891
|
-
let wrappedRef = `&${ref};`;
|
|
892
|
-
if (resolveUndefinedEntity) {
|
|
893
|
-
let resolvedValue = resolveUndefinedEntity(wrappedRef);
|
|
894
|
-
if (resolvedValue !== null && resolvedValue !== void 0) {
|
|
895
|
-
let type = typeof resolvedValue;
|
|
896
|
-
if (type !== "string") throw new TypeError(`\`resolveUndefinedEntity()\` must return a string, \`null\`, or \`undefined\`, but returned a value of type ${type}`);
|
|
897
|
-
return resolvedValue;
|
|
898
|
-
}
|
|
899
|
-
}
|
|
900
|
-
if (ignoreUndefinedEntities) return wrappedRef;
|
|
901
|
-
scanner.n(-wrappedRef.length);
|
|
902
|
-
throw this.a(`Named entity isn't defined: ${wrappedRef}`);
|
|
903
|
-
}
|
|
904
|
-
}
|
|
905
|
-
return parsedValue;
|
|
906
|
-
}
|
|
907
|
-
/**
|
|
908
|
-
* Consumes a `SystemLiteral` if possible.
|
|
909
|
-
*
|
|
910
|
-
* A `SystemLiteral` is similar to an attribute value, but allows the
|
|
911
|
-
* characters `<` and `&` and doesn't replace references.
|
|
912
|
-
*
|
|
913
|
-
* @returns
|
|
914
|
-
* Value of the `SystemLiteral` minus quotes, or `false` if nothing was
|
|
915
|
-
* consumed. An empty string indicates that a `SystemLiteral` was consumed
|
|
916
|
-
* but was empty.
|
|
917
|
-
*
|
|
918
|
-
* @see https://www.w3.org/TR/2008/REC-xml-20081126/#NT-SystemLiteral
|
|
919
|
-
*/
|
|
920
|
-
r() {
|
|
921
|
-
let { c: scanner } = this;
|
|
922
|
-
let quote = scanner.b("\"") || scanner.b("'");
|
|
923
|
-
if (!quote) return false;
|
|
924
|
-
let value = scanner.s(quote);
|
|
925
|
-
this.o(value);
|
|
926
|
-
if (!scanner.b(quote)) throw this.a("Missing end quote");
|
|
927
|
-
return value;
|
|
928
|
-
}
|
|
929
|
-
/**
|
|
930
|
-
* Consumes one or more whitespace characters if possible.
|
|
931
|
-
*
|
|
932
|
-
* @returns Whether any whitespace characters were consumed.
|
|
933
|
-
* @see https://www.w3.org/TR/2008/REC-xml-20081126/#white
|
|
934
|
-
*/
|
|
935
|
-
e() {
|
|
936
|
-
return !!this.c.w(isWhitespace);
|
|
937
|
-
}
|
|
938
|
-
/**
|
|
939
|
-
* Consumes an XML declaration if possible.
|
|
940
|
-
*
|
|
941
|
-
* @returns Whether an XML declaration was consumed.
|
|
942
|
-
* @see https://www.w3.org/TR/2008/REC-xml-20081126/#NT-XMLDecl
|
|
943
|
-
*/
|
|
944
|
-
P() {
|
|
945
|
-
let { c: scanner } = this;
|
|
946
|
-
let startIndex = scanner.d;
|
|
947
|
-
if (!scanner.b("<?xml")) return false;
|
|
948
|
-
if (!this.e()) throw this.a("Invalid XML declaration");
|
|
949
|
-
let version = !!scanner.b("version") && this.t() && this.r();
|
|
950
|
-
if (version === false) throw this.a("XML version is missing or invalid");
|
|
951
|
-
else if (!/^1\.[0-9]+$/.test(version)) throw this.a("Invalid character in version number");
|
|
952
|
-
let encoding;
|
|
953
|
-
let standalone;
|
|
954
|
-
if (this.e()) {
|
|
955
|
-
encoding = !!scanner.b("encoding") && this.t() && this.r();
|
|
956
|
-
if (encoding) {
|
|
957
|
-
if (!/^[A-Za-z][\w.-]*$/.test(encoding)) throw this.a("Invalid character in encoding name");
|
|
958
|
-
this.e();
|
|
959
|
-
}
|
|
960
|
-
standalone = !!scanner.b("standalone") && this.t() && this.r();
|
|
961
|
-
if (standalone) {
|
|
962
|
-
if (standalone !== "yes" && standalone !== "no") throw this.a("Only \"yes\" and \"no\" are permitted as values of `standalone`");
|
|
963
|
-
this.e();
|
|
964
|
-
}
|
|
965
|
-
}
|
|
966
|
-
if (!scanner.b("?>")) throw this.a("Invalid or unclosed XML declaration");
|
|
967
|
-
return this.g.preserveXmlDeclaration ? this.i(new XmlDeclaration(version, encoding || void 0, standalone || void 0), startIndex) : true;
|
|
968
|
-
}
|
|
969
|
-
/**
|
|
970
|
-
* Returns an `XmlError` for the current scanner position.
|
|
971
|
-
*/
|
|
972
|
-
a(message) {
|
|
973
|
-
let { c: scanner } = this;
|
|
974
|
-
return new XmlError(message, scanner.d, scanner.h);
|
|
975
|
-
}
|
|
976
|
-
/**
|
|
977
|
-
* Parses the XML input.
|
|
978
|
-
*/
|
|
979
|
-
parse() {
|
|
980
|
-
this.c.b("");
|
|
981
|
-
this.O();
|
|
982
|
-
if (!this.E()) throw this.a("Root element is missing or invalid");
|
|
983
|
-
while (this.z());
|
|
984
|
-
if (!this.c.B) throw this.a("Extra content at the end of the document");
|
|
985
|
-
}
|
|
986
|
-
/**
|
|
987
|
-
* Throws an invalid character error if any character in the given _string_
|
|
988
|
-
* isn't a valid XML character.
|
|
989
|
-
*/
|
|
990
|
-
o(string) {
|
|
991
|
-
let { length } = string;
|
|
992
|
-
for (let i = 0; i < length; ++i) {
|
|
993
|
-
let cp = string.codePointAt(i);
|
|
994
|
-
if (!isXmlCodePoint(cp)) {
|
|
995
|
-
this.c.n(-([...string].length - i));
|
|
996
|
-
throw this.a("Invalid character");
|
|
997
|
-
}
|
|
998
|
-
if (cp > 65535) i += 1;
|
|
999
|
-
}
|
|
1000
|
-
}
|
|
1001
|
-
};
|
|
1002
|
-
function normalizeLineBreaks(text) {
|
|
1003
|
-
let i = 0;
|
|
1004
|
-
while ((i = text.indexOf("\r", i)) !== -1) text = text[i + 1] === "\n" ? text.slice(0, i) + text.slice(i + 1) : text.slice(0, i) + "\n" + text.slice(i + 1);
|
|
1005
|
-
return text;
|
|
1006
|
-
}
|
|
1007
|
-
function parseXml(xml, options) {
|
|
1008
|
-
return new Parser(xml, options).document;
|
|
1009
|
-
}
|
|
1010
|
-
})))();
|
|
1011
|
-
const localName = (name) => name.includes(":") ? name.split(":")[1] : name;
|
|
1012
|
-
const isElement = (node) => node.type === "element";
|
|
1013
|
-
const isText = (node) => node.type === "text";
|
|
1014
|
-
const child = (el, name) => {
|
|
1015
|
-
for (const node of el.children) if (isElement(node) && localName(node.name) === name) return node;
|
|
1016
|
-
};
|
|
1017
|
-
const textOf = (el) => {
|
|
1018
|
-
if (el === void 0) return;
|
|
1019
|
-
let result = "";
|
|
1020
|
-
for (const node of el.children) if (isText(node)) result += node.text;
|
|
1021
|
-
return result === "" ? void 0 : result;
|
|
1022
|
-
};
|
|
1023
|
-
const docRoot = (doc) => doc.root ?? void 0;
|
|
1024
|
-
const xmlVal = (el, name) => {
|
|
1025
|
-
const v = el !== void 0 ? textOf(child(el, name)) : void 0;
|
|
1026
|
-
if (v === void 0 || v === "") return;
|
|
1027
|
-
try {
|
|
1028
|
-
return decodeURIComponent(v.replace(/\+/g, " "));
|
|
1029
|
-
} catch {
|
|
1030
|
-
throw new BaerlyError("InvalidResponse", `Malformed percent-escape in S3 <${name}>: ${v}`);
|
|
1031
|
-
}
|
|
1032
|
-
};
|
|
1033
|
-
const rawXmlVal = (el, name) => {
|
|
1034
|
-
return el !== void 0 ? textOf(child(el, name)) : void 0;
|
|
1035
|
-
};
|
|
1036
|
-
/**
|
|
1037
|
-
* Build a {@link ParsedS3Error} from the element that directly carries
|
|
1038
|
-
* the `<Code>` / `<Message>` children — `<Error>` for S3, the inner
|
|
1039
|
-
* `<Error>` for STS. Returns `undefined` when neither child is present
|
|
1040
|
-
* so callers can fall back to the raw status. Shared by
|
|
1041
|
-
* {@link parseS3Error} and {@link parseStsError}, which differ only in
|
|
1042
|
-
* how they locate that element.
|
|
1043
|
-
*/
|
|
1044
|
-
const codeMessageFrom = (el) => {
|
|
1045
|
-
const code = rawXmlVal(el, "Code");
|
|
1046
|
-
const message = rawXmlVal(el, "Message");
|
|
1047
|
-
if (code === void 0 && message === void 0) return;
|
|
1048
|
-
return {
|
|
1049
|
-
...code !== void 0 && { Code: code },
|
|
1050
|
-
...message !== void 0 && { Message: message }
|
|
1051
|
-
};
|
|
1052
|
-
};
|
|
1053
|
-
/**
|
|
1054
|
-
* Parse an S3 `<Error><Code>…</Code><Message>…</Message></Error>`
|
|
1055
|
-
* body. Returns `undefined` when the body is not a recognizable S3
|
|
1056
|
-
* error document (empty, HTML, a success payload, or a DTD), so
|
|
1057
|
-
* callers can fall back to the raw response text. This never throws:
|
|
1058
|
-
* it runs on a path that is already reporting an error.
|
|
1059
|
-
*/
|
|
1060
|
-
const parseS3Error = (xml) => {
|
|
1061
|
-
if (!/<Error\b/i.test(xml) || /<!DOCTYPE\b/i.test(xml)) return;
|
|
1062
|
-
let root;
|
|
1063
|
-
try {
|
|
1064
|
-
root = docRoot((0, import_browser.parseXml)(xml));
|
|
1065
|
-
} catch {
|
|
1066
|
-
return;
|
|
1067
|
-
}
|
|
1068
|
-
if (root === void 0) return;
|
|
1069
|
-
if (localName(root.name) !== "Error") return;
|
|
1070
|
-
return codeMessageFrom(root);
|
|
1071
|
-
};
|
|
1072
|
-
/**
|
|
1073
|
-
* Parse an STS `<ErrorResponse><Error><Code>…</Code><Message>…</Message>
|
|
1074
|
-
* </Error></ErrorResponse>` body (the shape STS returns on a failed
|
|
1075
|
-
* `AssumeRoleWithWebIdentity` — e.g. `InvalidIdentityToken`,
|
|
1076
|
-
* `ExpiredTokenException`, `AccessDenied`). Returns `undefined` when the body
|
|
1077
|
-
* is not a recognizable STS error document (empty, HTML, a success payload, or
|
|
1078
|
-
* a DTD), so callers can fall back to the bare status. Like {@link parseS3Error}
|
|
1079
|
-
* this never throws — it runs on a path that is already reporting an error.
|
|
1080
|
-
*
|
|
1081
|
-
* Note the nesting differs from S3: STS wraps `<Error>` inside `<ErrorResponse>`.
|
|
1082
|
-
*/
|
|
1083
|
-
const parseStsError = (xml) => {
|
|
1084
|
-
if (!/<Error\b/i.test(xml) || /<!DOCTYPE\b/i.test(xml)) return;
|
|
1085
|
-
let root;
|
|
1086
|
-
try {
|
|
1087
|
-
root = docRoot((0, import_browser.parseXml)(xml));
|
|
1088
|
-
} catch {
|
|
1089
|
-
return;
|
|
1090
|
-
}
|
|
1091
|
-
if (root === void 0) return;
|
|
1092
|
-
const errorEl = child(root, "Error");
|
|
1093
|
-
if (errorEl === void 0) return;
|
|
1094
|
-
return codeMessageFrom(errorEl);
|
|
1095
|
-
};
|
|
1096
|
-
/**
|
|
1097
|
-
* Parse an STS `AssumeRoleWithWebIdentity` success body, returning the
|
|
1098
|
-
* `<Credentials>` block. Reuses the hardened, DTD-guarded parser;
|
|
1099
|
-
* throws `InvalidResponse` on a DTD or unparseable XML. Missing fields come
|
|
1100
|
-
* back `undefined` so the caller can map them to its own `InvalidResponse`.
|
|
1101
|
-
*
|
|
1102
|
-
* Unlike {@link parseListObjectsV2CommandOutput}, the error on unparseable
|
|
1103
|
-
* XML must NOT echo the body: a success-shaped STS body carries the plaintext
|
|
1104
|
-
* `SecretAccessKey`/`SessionToken`, so folding it into a thrown-then-logged
|
|
1105
|
-
* error would leak live credentials.
|
|
1106
|
-
*/
|
|
1107
|
-
const parseAssumeRoleWithWebIdentity = (xml) => {
|
|
1108
|
-
if (/<!DOCTYPE\b/i.test(xml)) throw new BaerlyError("InvalidResponse", "DTD not allowed in STS XML responses");
|
|
1109
|
-
let root;
|
|
1110
|
-
try {
|
|
1111
|
-
root = docRoot((0, import_browser.parseXml)(xml));
|
|
1112
|
-
} catch {
|
|
1113
|
-
throw new BaerlyError("InvalidResponse", "unparseable STS credentials response");
|
|
1114
|
-
}
|
|
1115
|
-
const resultEl = root !== void 0 ? child(root, "AssumeRoleWithWebIdentityResult") : void 0;
|
|
1116
|
-
const credsEl = resultEl !== void 0 ? child(resultEl, "Credentials") : void 0;
|
|
1117
|
-
return {
|
|
1118
|
-
AccessKeyId: rawXmlVal(credsEl, "AccessKeyId"),
|
|
1119
|
-
SecretAccessKey: rawXmlVal(credsEl, "SecretAccessKey"),
|
|
1120
|
-
SessionToken: rawXmlVal(credsEl, "SessionToken"),
|
|
1121
|
-
Expiration: rawXmlVal(credsEl, "Expiration")
|
|
1122
|
-
};
|
|
1123
|
-
};
|
|
1124
|
-
const parseLastModified = (lm) => {
|
|
1125
|
-
if (lm === void 0) return;
|
|
1126
|
-
const d = new Date(lm);
|
|
1127
|
-
return Number.isNaN(d.getTime()) ? void 0 : d;
|
|
1128
|
-
};
|
|
1129
|
-
const parseListObjectsV2CommandOutput = (xml) => {
|
|
1130
|
-
if (/<!DOCTYPE\b/i.test(xml)) throw new BaerlyError("InvalidResponse", "DTD not allowed in S3 XML responses");
|
|
1131
|
-
let root;
|
|
1132
|
-
try {
|
|
1133
|
-
root = docRoot((0, import_browser.parseXml)(xml));
|
|
1134
|
-
} catch {
|
|
1135
|
-
throw new BaerlyError("InvalidResponse", `Invalid XML: ${xml}`);
|
|
1136
|
-
}
|
|
1137
|
-
if (root === void 0) return {};
|
|
1138
|
-
if (localName(root.name) !== "ListBucketResult") return {};
|
|
1139
|
-
return {
|
|
1140
|
-
Contents: root.children.filter(isElement).filter((c) => localName(c.name) === "Contents").map((contentEl) => {
|
|
1141
|
-
return {
|
|
1142
|
-
ETag: rawXmlVal(contentEl, "ETag"),
|
|
1143
|
-
Key: xmlVal(contentEl, "Key"),
|
|
1144
|
-
LastModified: parseLastModified(rawXmlVal(contentEl, "LastModified"))
|
|
1145
|
-
};
|
|
1146
|
-
}),
|
|
1147
|
-
NextContinuationToken: rawXmlVal(root, "NextContinuationToken")
|
|
1148
|
-
};
|
|
1149
|
-
};
|
|
1150
|
-
//#endregion
|
|
1151
|
-
//#region packages/adapter-node/src/s3-http.ts
|
|
1152
|
-
/**
|
|
1153
|
-
* Permanent {@link BaerlyError} codes that must short-circuit `retry`.
|
|
1154
|
-
* These represent caller- or environment-level faults where retrying
|
|
1155
|
-
* cannot succeed: `AccessDenied` (403 — credentials/policy),
|
|
1156
|
-
* `InvalidConfig` (bad bucket / unsupported credential type),
|
|
1157
|
-
* `InvalidResponse` (server returned unparseable data), and
|
|
1158
|
-
* `Conflict` (CAS guard lost — retrying would just re-lose against
|
|
1159
|
-
* the same state). `NetworkError` is intentionally absent — it covers
|
|
1160
|
-
* transient transport faults and stays retryable.
|
|
1161
|
-
*
|
|
1162
|
-
* Transport-layer set, distinct from `RETRIABLE_CODES` in `@baerly/protocol`'s
|
|
1163
|
-
* `errors.ts` (the default wire `retriable` hint). `Conflict` is "permanent"
|
|
1164
|
-
* here (a blind re-PUT re-loses the CAS race) yet retryable for logical CAS
|
|
1165
|
-
* callers that can fresh-read + re-apply. Same code, two different questions.
|
|
1166
|
-
*/
|
|
1167
|
-
const PERMANENT_ERROR_CODES = /* @__PURE__ */ new Set([
|
|
1168
|
-
"AccessDenied",
|
|
1169
|
-
"InvalidConfig",
|
|
1170
|
-
"InvalidResponse",
|
|
1171
|
-
"Conflict"
|
|
1172
|
-
]);
|
|
1173
|
-
/**
|
|
1174
|
-
* Parse an HTTP `Retry-After` header into a non-negative seconds value,
|
|
1175
|
-
* clamped to {@link RETRY_AFTER_MAX_SECONDS}. Returns `undefined` if
|
|
1176
|
-
* the header is absent, malformed, or whitespace.
|
|
1177
|
-
*
|
|
1178
|
-
* RFC 7231 §7.1.3 admits two forms: delta-seconds (non-negative
|
|
1179
|
-
* integer) and HTTP-date. Both are accepted; dates in the past return
|
|
1180
|
-
* `0`. Fractional seconds, negatives, and arbitrary strings reject.
|
|
1181
|
-
*
|
|
1182
|
-
* The `now` injection point exists for the unit test; production
|
|
1183
|
-
* callers should pass nothing.
|
|
1184
|
-
*/
|
|
1185
|
-
function parseRetryAfter(header, now = Date.now) {
|
|
1186
|
-
if (header === null) return;
|
|
1187
|
-
const trimmed = header.trim();
|
|
1188
|
-
if (trimmed === "") return;
|
|
1189
|
-
if (/^\d+$/.test(trimmed)) {
|
|
1190
|
-
const n = Number.parseInt(trimmed, 10);
|
|
1191
|
-
return Number.isFinite(n) ? Math.min(n, 60) : void 0;
|
|
1192
|
-
}
|
|
1193
|
-
if (!/[a-z]/i.test(trimmed)) return;
|
|
1194
|
-
const t = Date.parse(trimmed);
|
|
1195
|
-
if (Number.isNaN(t)) return;
|
|
1196
|
-
const seconds = Math.max(0, Math.ceil((t - now()) / 1e3));
|
|
1197
|
-
return Math.min(seconds, 60);
|
|
1198
|
-
}
|
|
1199
|
-
const retryAfterCause = (res) => {
|
|
1200
|
-
const hint = parseRetryAfter(res.headers.get("Retry-After"));
|
|
1201
|
-
return hint !== void 0 ? { retryAfterSeconds: hint } : {};
|
|
1202
|
-
};
|
|
1203
|
-
const s3ErrorDetail = (status, body) => {
|
|
1204
|
-
const parsed = parseS3Error(body);
|
|
1205
|
-
if (parsed !== void 0) {
|
|
1206
|
-
const code = parsed.Code ?? "UnknownError";
|
|
1207
|
-
return parsed.Message !== void 0 ? `${status} ${code}: ${parsed.Message}` : `${status} ${code}`;
|
|
1208
|
-
}
|
|
1209
|
-
return `${status} ${body}`;
|
|
1210
|
-
};
|
|
1211
|
-
const retry = async (fn, { retries = 8, backoffMs = 100, maxDelayMs = 1e4 } = {}) => {
|
|
1212
|
-
let wait = backoffMs;
|
|
1213
|
-
for (let attempt = 0; attempt <= retries; attempt++) try {
|
|
1214
|
-
return await fn();
|
|
1215
|
-
} catch (error) {
|
|
1216
|
-
if (error instanceof BaerlyError && PERMANENT_ERROR_CODES.has(error.code)) throw error;
|
|
1217
|
-
if (attempt === retries) throw error;
|
|
1218
|
-
const hintMs = retryAfterHintMs(error, maxDelayMs);
|
|
1219
|
-
await delay(hintMs ?? wait);
|
|
1220
|
-
if (hintMs === void 0) wait = Math.min(wait * 1.5, maxDelayMs);
|
|
1221
|
-
else wait = backoffMs;
|
|
1222
|
-
}
|
|
1223
|
-
throw new BaerlyError("Internal", "s3-http retry loop exited without returning or throwing");
|
|
1224
|
-
};
|
|
1225
|
-
const retryAfterHintMs = (e, maxDelayMs) => {
|
|
1226
|
-
if (!(e instanceof BaerlyError)) return;
|
|
1227
|
-
const cause = e.cause;
|
|
1228
|
-
if (cause?.retryAfterSeconds === void 0) return;
|
|
1229
|
-
return Math.min(cause.retryAfterSeconds * 1e3, maxDelayMs);
|
|
1230
|
-
};
|
|
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
|
-
//#endregion
|
|
1700
|
-
export { parseStsError as i, S3HttpStorage as n, parseAssumeRoleWithWebIdentity as r, AwsClient as t };
|
|
1701
|
-
|
|
1702
|
-
//# sourceMappingURL=aws4fetch.esm-p7eEzLCs.js.map
|