@d1g1tal/transportr 2.0.0 → 2.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -2
- package/dist/OP3JQ447.js +8 -0
- package/dist/OP3JQ447.js.map +7 -0
- package/dist/headers.d.ts +249 -0
- package/dist/headers.js +2 -0
- package/dist/headers.js.map +7 -0
- package/dist/media-types.d.ts +160 -0
- package/dist/media-types.js +2 -0
- package/dist/media-types.js.map +7 -0
- package/dist/methods.d.ts +274 -0
- package/dist/methods.js +2 -0
- package/dist/methods.js.map +7 -0
- package/dist/response-headers.d.ts +345 -0
- package/dist/response-headers.js +2 -0
- package/dist/response-headers.js.map +7 -0
- package/dist/transportr.d.ts +195 -822
- package/dist/transportr.js +2 -3944
- package/dist/transportr.js.map +4 -4
- package/package.json +30 -5
package/dist/transportr.js
CHANGED
|
@@ -1,3945 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
var httpTokenCodePoints = /^[-!#$%&'*+.^_`|~A-Za-z0-9]*$/u;
|
|
3
|
-
var matcher = /(["\\])/ug;
|
|
4
|
-
var httpQuotedStringTokenCodePoints = /^[\t\u0020-\u007E\u0080-\u00FF]*$/u;
|
|
5
|
-
var MediaTypeParameters = class _MediaTypeParameters extends Map {
|
|
6
|
-
/**
|
|
7
|
-
* Create a new MediaTypeParameters instance.
|
|
8
|
-
*
|
|
9
|
-
* @param entries An array of [ name, value ] tuples.
|
|
10
|
-
*/
|
|
11
|
-
constructor(entries2 = []) {
|
|
12
|
-
super(entries2);
|
|
13
|
-
}
|
|
14
|
-
/**
|
|
15
|
-
* Indicates whether the supplied name and value are valid media type parameters.
|
|
16
|
-
*
|
|
17
|
-
* @param name The name of the media type parameter to validate.
|
|
18
|
-
* @param value The media type parameter value to validate.
|
|
19
|
-
* @returns true if the media type parameter is valid, false otherwise.
|
|
20
|
-
*/
|
|
21
|
-
static isValid(name, value) {
|
|
22
|
-
return httpTokenCodePoints.test(name) && httpQuotedStringTokenCodePoints.test(value);
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* Gets the media type parameter value for the supplied name.
|
|
26
|
-
*
|
|
27
|
-
* @param name The name of the media type parameter to retrieve.
|
|
28
|
-
* @returns The media type parameter value.
|
|
29
|
-
*/
|
|
30
|
-
get(name) {
|
|
31
|
-
return super.get(name.toLowerCase());
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* Indicates whether the media type parameter with the specified name exists or not.
|
|
35
|
-
*
|
|
36
|
-
* @param name The name of the media type parameter to check.
|
|
37
|
-
* @returns true if the media type parameter exists, false otherwise.
|
|
38
|
-
*/
|
|
39
|
-
has(name) {
|
|
40
|
-
return super.has(name.toLowerCase());
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* Adds a new media type parameter using the specified name and value to the MediaTypeParameters.
|
|
44
|
-
* If an parameter with the same name already exists, the parameter will be updated.
|
|
45
|
-
*
|
|
46
|
-
* @param name The name of the media type parameter to set.
|
|
47
|
-
* @param value The media type parameter value.
|
|
48
|
-
* @returns This instance.
|
|
49
|
-
*/
|
|
50
|
-
set(name, value) {
|
|
51
|
-
if (!_MediaTypeParameters.isValid(name, value)) {
|
|
52
|
-
throw new Error(`Invalid media type parameter name/value: ${name}/${value}`);
|
|
53
|
-
}
|
|
54
|
-
super.set(name.toLowerCase(), value);
|
|
55
|
-
return this;
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* Removes the media type parameter using the specified name.
|
|
59
|
-
*
|
|
60
|
-
* @param name The name of the media type parameter to delete.
|
|
61
|
-
* @returns true if the parameter existed and has been removed, or false if the parameter does not exist.
|
|
62
|
-
*/
|
|
63
|
-
delete(name) {
|
|
64
|
-
return super.delete(name.toLowerCase());
|
|
65
|
-
}
|
|
66
|
-
/**
|
|
67
|
-
* Returns a string representation of the media type parameters.
|
|
68
|
-
*
|
|
69
|
-
* @returns The string representation of the media type parameters.
|
|
70
|
-
*/
|
|
71
|
-
toString() {
|
|
72
|
-
return Array.from(this).map(([name, value]) => `;${name}=${!value || !httpTokenCodePoints.test(value) ? `"${value.replace(matcher, "\\$1")}"` : value}`).join("");
|
|
73
|
-
}
|
|
74
|
-
/**
|
|
75
|
-
* Returns the name of this class.
|
|
76
|
-
*
|
|
77
|
-
* @returns The name of this class.
|
|
78
|
-
*/
|
|
79
|
-
get [Symbol.toStringTag]() {
|
|
80
|
-
return "MediaTypeParameters";
|
|
81
|
-
}
|
|
82
|
-
};
|
|
83
|
-
var whitespaceChars = /* @__PURE__ */ new Set([" ", " ", "\n", "\r"]);
|
|
84
|
-
var trailingWhitespace = /[ \t\n\r]+$/u;
|
|
85
|
-
var leadingAndTrailingWhitespace = /^[ \t\n\r]+|[ \t\n\r]+$/ug;
|
|
86
|
-
var MediaTypeParser = class _MediaTypeParser {
|
|
87
|
-
/**
|
|
88
|
-
* Function to parse a media type.
|
|
89
|
-
* @param input The media type to parse
|
|
90
|
-
* @returns An object populated with the parsed media type properties and any parameters.
|
|
91
|
-
*/
|
|
92
|
-
static parse(input) {
|
|
93
|
-
input = input.replace(leadingAndTrailingWhitespace, "");
|
|
94
|
-
let position = 0;
|
|
95
|
-
const [type, typeEnd] = _MediaTypeParser.collect(input, position, ["/"]);
|
|
96
|
-
position = typeEnd;
|
|
97
|
-
if (!type.length || position >= input.length || !httpTokenCodePoints.test(type)) {
|
|
98
|
-
throw new TypeError(_MediaTypeParser.generateErrorMessage("type", type));
|
|
99
|
-
}
|
|
100
|
-
++position;
|
|
101
|
-
const [subtype, subtypeEnd] = _MediaTypeParser.collect(input, position, [";"], true, true);
|
|
102
|
-
position = subtypeEnd;
|
|
103
|
-
if (!subtype.length || !httpTokenCodePoints.test(subtype)) {
|
|
104
|
-
throw new TypeError(_MediaTypeParser.generateErrorMessage("subtype", subtype));
|
|
105
|
-
}
|
|
106
|
-
const parameters = new MediaTypeParameters();
|
|
107
|
-
while (position < input.length) {
|
|
108
|
-
++position;
|
|
109
|
-
while (whitespaceChars.has(input[position])) {
|
|
110
|
-
++position;
|
|
111
|
-
}
|
|
112
|
-
let name;
|
|
113
|
-
[name, position] = _MediaTypeParser.collect(input, position, [";", "="], false);
|
|
114
|
-
if (position >= input.length || input[position] === ";") {
|
|
115
|
-
continue;
|
|
116
|
-
}
|
|
117
|
-
++position;
|
|
118
|
-
let value;
|
|
119
|
-
if (input[position] === '"') {
|
|
120
|
-
[value, position] = _MediaTypeParser.collectHttpQuotedString(input, position);
|
|
121
|
-
while (position < input.length && input[position] !== ";") {
|
|
122
|
-
++position;
|
|
123
|
-
}
|
|
124
|
-
} else {
|
|
125
|
-
[value, position] = _MediaTypeParser.collect(input, position, [";"], false, true);
|
|
126
|
-
if (!value) {
|
|
127
|
-
continue;
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
if (name && MediaTypeParameters.isValid(name, value) && !parameters.has(name)) {
|
|
131
|
-
parameters.set(name, value);
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
return { type, subtype, parameters };
|
|
135
|
-
}
|
|
136
|
-
/**
|
|
137
|
-
* Gets the name of this class.
|
|
138
|
-
* @returns The string tag of this class.
|
|
139
|
-
*/
|
|
140
|
-
get [Symbol.toStringTag]() {
|
|
141
|
-
return "MediaTypeParser";
|
|
142
|
-
}
|
|
143
|
-
/**
|
|
144
|
-
* Collects characters from `input` starting at `pos` until a stop character is found.
|
|
145
|
-
* @param input The input string.
|
|
146
|
-
* @param pos The starting position.
|
|
147
|
-
* @param stopChars Characters that end collection.
|
|
148
|
-
* @param lowerCase Whether to ASCII-lowercase the result.
|
|
149
|
-
* @param trim Whether to strip trailing HTTP whitespace.
|
|
150
|
-
* @returns A tuple of the collected string and the updated position.
|
|
151
|
-
*/
|
|
152
|
-
static collect(input, pos, stopChars, lowerCase = true, trim = false) {
|
|
153
|
-
let result = "";
|
|
154
|
-
for (const { length } = input; pos < length && !stopChars.includes(input[pos]); pos++) {
|
|
155
|
-
result += input[pos];
|
|
156
|
-
}
|
|
157
|
-
if (lowerCase) {
|
|
158
|
-
result = result.toLowerCase();
|
|
159
|
-
}
|
|
160
|
-
if (trim) {
|
|
161
|
-
result = result.replace(trailingWhitespace, "");
|
|
162
|
-
}
|
|
163
|
-
return [result, pos];
|
|
164
|
-
}
|
|
165
|
-
/**
|
|
166
|
-
* Collects all the HTTP quoted strings.
|
|
167
|
-
* This variant only implements it with the extract-value flag set.
|
|
168
|
-
* @param input The string to process.
|
|
169
|
-
* @param position The starting position.
|
|
170
|
-
* @returns An array that includes the resulting string and updated position.
|
|
171
|
-
*/
|
|
172
|
-
static collectHttpQuotedString(input, position) {
|
|
173
|
-
let value = "";
|
|
174
|
-
for (let length = input.length, char; ++position < length; ) {
|
|
175
|
-
if ((char = input[position]) === '"') {
|
|
176
|
-
break;
|
|
177
|
-
}
|
|
178
|
-
value += char == "\\" && ++position < length ? input[position] : char;
|
|
179
|
-
}
|
|
180
|
-
return [value, position];
|
|
181
|
-
}
|
|
182
|
-
/**
|
|
183
|
-
* Generates an error message.
|
|
184
|
-
* @param component The component name.
|
|
185
|
-
* @param value The component value.
|
|
186
|
-
* @returns The error message.
|
|
187
|
-
*/
|
|
188
|
-
static generateErrorMessage(component, value) {
|
|
189
|
-
return `Invalid ${component} "${value}": only HTTP token code points are valid.`;
|
|
190
|
-
}
|
|
191
|
-
};
|
|
192
|
-
var MediaType = class _MediaType {
|
|
193
|
-
_type;
|
|
194
|
-
_subtype;
|
|
195
|
-
_parameters;
|
|
196
|
-
/**
|
|
197
|
-
* Create a new MediaType instance from a string representation.
|
|
198
|
-
* @param mediaType The media type to parse.
|
|
199
|
-
* @param parameters Optional parameters.
|
|
200
|
-
*/
|
|
201
|
-
constructor(mediaType, parameters = {}) {
|
|
202
|
-
if (parameters === null || typeof parameters !== "object" || Array.isArray(parameters)) {
|
|
203
|
-
throw new TypeError("The parameters argument must be an object");
|
|
204
|
-
}
|
|
205
|
-
({ type: this._type, subtype: this._subtype, parameters: this._parameters } = MediaTypeParser.parse(mediaType));
|
|
206
|
-
for (const [name, value] of Object.entries(parameters)) {
|
|
207
|
-
this._parameters.set(name, value);
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
/**
|
|
211
|
-
* Parses a media type string.
|
|
212
|
-
* @param mediaType The media type to parse.
|
|
213
|
-
* @returns The parsed media type or null if the mediaType cannot be parsed.
|
|
214
|
-
*/
|
|
215
|
-
static parse(mediaType) {
|
|
216
|
-
try {
|
|
217
|
-
return new _MediaType(mediaType);
|
|
218
|
-
} catch {
|
|
219
|
-
}
|
|
220
|
-
return null;
|
|
221
|
-
}
|
|
222
|
-
/**
|
|
223
|
-
* Gets the type.
|
|
224
|
-
* @returns The type.
|
|
225
|
-
*/
|
|
226
|
-
get type() {
|
|
227
|
-
return this._type;
|
|
228
|
-
}
|
|
229
|
-
/**
|
|
230
|
-
* Gets the subtype.
|
|
231
|
-
* @returns The subtype.
|
|
232
|
-
*/
|
|
233
|
-
get subtype() {
|
|
234
|
-
return this._subtype;
|
|
235
|
-
}
|
|
236
|
-
/**
|
|
237
|
-
* Gets the media type essence (type/subtype).
|
|
238
|
-
* @returns The media type without any parameters
|
|
239
|
-
*/
|
|
240
|
-
get essence() {
|
|
241
|
-
return `${this._type}/${this._subtype}`;
|
|
242
|
-
}
|
|
243
|
-
/**
|
|
244
|
-
* Gets the parameters.
|
|
245
|
-
* @returns The media type parameters.
|
|
246
|
-
*/
|
|
247
|
-
get parameters() {
|
|
248
|
-
return this._parameters;
|
|
249
|
-
}
|
|
250
|
-
/**
|
|
251
|
-
* Checks if the media type matches the specified type.
|
|
252
|
-
*
|
|
253
|
-
* @param mediaType The media type to check.
|
|
254
|
-
* @returns true if the media type matches the specified type, false otherwise.
|
|
255
|
-
*/
|
|
256
|
-
matches(mediaType) {
|
|
257
|
-
return typeof mediaType === "string" ? this.essence.includes(mediaType) : this._type === mediaType._type && this._subtype === mediaType._subtype;
|
|
258
|
-
}
|
|
259
|
-
/**
|
|
260
|
-
* Gets the serialized version of the media type.
|
|
261
|
-
*
|
|
262
|
-
* @returns The serialized media type.
|
|
263
|
-
*/
|
|
264
|
-
toString() {
|
|
265
|
-
return `${this.essence}${this._parameters.toString()}`;
|
|
266
|
-
}
|
|
267
|
-
/**
|
|
268
|
-
* Gets the name of the class.
|
|
269
|
-
* @returns The class name
|
|
270
|
-
*/
|
|
271
|
-
get [Symbol.toStringTag]() {
|
|
272
|
-
return "MediaType";
|
|
273
|
-
}
|
|
274
|
-
};
|
|
275
|
-
|
|
276
|
-
// node_modules/.pnpm/@d1g1tal+subscribr@4.1.8_typescript@5.9.3/node_modules/@d1g1tal/subscribr/dist/subscribr.js
|
|
277
|
-
var SetMultiMap = class extends Map {
|
|
278
|
-
/**
|
|
279
|
-
* Adds a new element with a specified key and value to the SetMultiMap.
|
|
280
|
-
* If an element with the same key already exists, the value will be added to the underlying {@link Set}.
|
|
281
|
-
* If the value already exists in the {@link Set}, it will not be added again.
|
|
282
|
-
*
|
|
283
|
-
* @param key The key to set.
|
|
284
|
-
* @param value The value to add to the SetMultiMap
|
|
285
|
-
* @returns The SetMultiMap with the updated key and value.
|
|
286
|
-
*/
|
|
287
|
-
set(key, value) {
|
|
288
|
-
super.set(key, value instanceof Set ? value : (super.get(key) ?? /* @__PURE__ */ new Set()).add(value));
|
|
289
|
-
return this;
|
|
290
|
-
}
|
|
291
|
-
/**
|
|
292
|
-
* Finds a specific value for a specific key using an iterator function.
|
|
293
|
-
* @param key The key to find the value for.
|
|
294
|
-
* @param iterator The iterator function to use to find the value.
|
|
295
|
-
* @returns The value for the specified key
|
|
296
|
-
*/
|
|
297
|
-
find(key, iterator) {
|
|
298
|
-
const values = this.get(key);
|
|
299
|
-
if (values !== void 0) {
|
|
300
|
-
return Array.from(values).find(iterator);
|
|
301
|
-
}
|
|
302
|
-
return void 0;
|
|
303
|
-
}
|
|
304
|
-
/**
|
|
305
|
-
* Checks if a specific key has a specific value.
|
|
306
|
-
*
|
|
307
|
-
* @param key The key to check.
|
|
308
|
-
* @param value The value to check.
|
|
309
|
-
* @returns True if the key has the value, false otherwise.
|
|
310
|
-
*/
|
|
311
|
-
hasValue(key, value) {
|
|
312
|
-
const values = super.get(key);
|
|
313
|
-
return values ? values.has(value) : false;
|
|
314
|
-
}
|
|
315
|
-
/**
|
|
316
|
-
* Removes a specific value from a specific key.
|
|
317
|
-
* @param key The key to remove the value from.
|
|
318
|
-
* @param value The value to remove.
|
|
319
|
-
* @returns True if the value was removed, false otherwise.
|
|
320
|
-
*/
|
|
321
|
-
deleteValue(key, value) {
|
|
322
|
-
if (value === void 0) {
|
|
323
|
-
return this.delete(key);
|
|
324
|
-
}
|
|
325
|
-
const values = super.get(key);
|
|
326
|
-
if (values) {
|
|
327
|
-
const deleted = values.delete(value);
|
|
328
|
-
if (values.size === 0) {
|
|
329
|
-
super.delete(key);
|
|
330
|
-
}
|
|
331
|
-
return deleted;
|
|
332
|
-
}
|
|
333
|
-
return false;
|
|
334
|
-
}
|
|
335
|
-
/**
|
|
336
|
-
* The string tag of the SetMultiMap.
|
|
337
|
-
* @returns The string tag of the SetMultiMap.
|
|
338
|
-
*/
|
|
339
|
-
get [Symbol.toStringTag]() {
|
|
340
|
-
return "SetMultiMap";
|
|
341
|
-
}
|
|
342
|
-
};
|
|
343
|
-
var ContextEventHandler = class {
|
|
344
|
-
context;
|
|
345
|
-
eventHandler;
|
|
346
|
-
/**
|
|
347
|
-
* @param context The context to bind to the event handler.
|
|
348
|
-
* @param eventHandler The event handler to call when the event is published.
|
|
349
|
-
*/
|
|
350
|
-
constructor(context, eventHandler) {
|
|
351
|
-
this.context = context;
|
|
352
|
-
this.eventHandler = eventHandler;
|
|
353
|
-
}
|
|
354
|
-
/**
|
|
355
|
-
* Call the event handler for the provided event.
|
|
356
|
-
*
|
|
357
|
-
* @param event The event to handle
|
|
358
|
-
* @param data The value to be passed to the event handler as a parameter.
|
|
359
|
-
*/
|
|
360
|
-
handle(event, data) {
|
|
361
|
-
this.eventHandler.call(this.context, event, data);
|
|
362
|
-
}
|
|
363
|
-
/**
|
|
364
|
-
* A String value that is used in the creation of the default string
|
|
365
|
-
* description of an object. Called by the built-in method {@link Object.prototype.toString}.
|
|
366
|
-
*
|
|
367
|
-
* @returns The default string description of this object.
|
|
368
|
-
*/
|
|
369
|
-
get [Symbol.toStringTag]() {
|
|
370
|
-
return "ContextEventHandler";
|
|
371
|
-
}
|
|
372
|
-
};
|
|
373
|
-
var Subscription = class {
|
|
374
|
-
_eventName;
|
|
375
|
-
_contextEventHandler;
|
|
376
|
-
/**
|
|
377
|
-
* @param eventName The event name.
|
|
378
|
-
* @param contextEventHandler The context event handler.
|
|
379
|
-
*/
|
|
380
|
-
constructor(eventName, contextEventHandler) {
|
|
381
|
-
this._eventName = eventName;
|
|
382
|
-
this._contextEventHandler = contextEventHandler;
|
|
383
|
-
}
|
|
384
|
-
/**
|
|
385
|
-
* Gets the event name for the subscription.
|
|
386
|
-
*
|
|
387
|
-
* @returns The event name.
|
|
388
|
-
*/
|
|
389
|
-
get eventName() {
|
|
390
|
-
return this._eventName;
|
|
391
|
-
}
|
|
392
|
-
/**
|
|
393
|
-
* Gets the context event handler.
|
|
394
|
-
*
|
|
395
|
-
* @returns The context event handler
|
|
396
|
-
*/
|
|
397
|
-
get contextEventHandler() {
|
|
398
|
-
return this._contextEventHandler;
|
|
399
|
-
}
|
|
400
|
-
/**
|
|
401
|
-
* A String value that is used in the creation of the default string
|
|
402
|
-
* description of an object. Called by the built-in method {@link Object.prototype.toString}.
|
|
403
|
-
*
|
|
404
|
-
* @returns The default string description of this object.
|
|
405
|
-
*/
|
|
406
|
-
get [Symbol.toStringTag]() {
|
|
407
|
-
return "Subscription";
|
|
408
|
-
}
|
|
409
|
-
};
|
|
410
|
-
var Subscribr = class {
|
|
411
|
-
subscribers = new SetMultiMap();
|
|
412
|
-
errorHandler;
|
|
413
|
-
/**
|
|
414
|
-
* Set a custom error handler for handling errors that occur in event listeners.
|
|
415
|
-
* If not set, errors will be logged to the console.
|
|
416
|
-
*
|
|
417
|
-
* @param errorHandler The error handler function to call when an error occurs in an event listener.
|
|
418
|
-
*/
|
|
419
|
-
setErrorHandler(errorHandler) {
|
|
420
|
-
this.errorHandler = errorHandler;
|
|
421
|
-
}
|
|
422
|
-
/**
|
|
423
|
-
* Subscribe to an event
|
|
424
|
-
*
|
|
425
|
-
* @param eventName The event name to subscribe to.
|
|
426
|
-
* @param eventHandler The event handler to call when the event is published.
|
|
427
|
-
* @param context The context to bind to the event handler.
|
|
428
|
-
* @param options Subscription options.
|
|
429
|
-
* @returns An object used to check if the subscription still exists and to unsubscribe from the event.
|
|
430
|
-
*/
|
|
431
|
-
subscribe(eventName, eventHandler, context = eventHandler, options) {
|
|
432
|
-
this.validateEventName(eventName);
|
|
433
|
-
if (options?.once) {
|
|
434
|
-
const originalHandler = eventHandler;
|
|
435
|
-
eventHandler = (event, data) => {
|
|
436
|
-
originalHandler.call(context, event, data);
|
|
437
|
-
this.unsubscribe(subscription);
|
|
438
|
-
};
|
|
439
|
-
}
|
|
440
|
-
const contextEventHandler = new ContextEventHandler(context, eventHandler);
|
|
441
|
-
this.subscribers.set(eventName, contextEventHandler);
|
|
442
|
-
const subscription = new Subscription(eventName, contextEventHandler);
|
|
443
|
-
return subscription;
|
|
444
|
-
}
|
|
445
|
-
/**
|
|
446
|
-
* Unsubscribe from the event
|
|
447
|
-
*
|
|
448
|
-
* @param subscription The subscription to unsubscribe.
|
|
449
|
-
* @returns true if eventListener has been removed successfully. false if the value is not found or if the value is not an object.
|
|
450
|
-
*/
|
|
451
|
-
unsubscribe({ eventName, contextEventHandler }) {
|
|
452
|
-
const contextEventHandlers = this.subscribers.get(eventName) ?? /* @__PURE__ */ new Set();
|
|
453
|
-
const removed = contextEventHandlers.delete(contextEventHandler);
|
|
454
|
-
if (removed && contextEventHandlers.size === 0) {
|
|
455
|
-
this.subscribers.delete(eventName);
|
|
456
|
-
}
|
|
457
|
-
return removed;
|
|
458
|
-
}
|
|
459
|
-
/**
|
|
460
|
-
* Publish an event
|
|
461
|
-
*
|
|
462
|
-
* @template T
|
|
463
|
-
* @param eventName The name of the event.
|
|
464
|
-
* @param event The event to be handled.
|
|
465
|
-
* @param data The value to be passed to the event handler as a parameter.
|
|
466
|
-
*/
|
|
467
|
-
publish(eventName, event = new CustomEvent(eventName), data) {
|
|
468
|
-
this.validateEventName(eventName);
|
|
469
|
-
this.subscribers.get(eventName)?.forEach((contextEventHandler) => {
|
|
470
|
-
try {
|
|
471
|
-
contextEventHandler.handle(event, data);
|
|
472
|
-
} catch (error) {
|
|
473
|
-
if (this.errorHandler) {
|
|
474
|
-
this.errorHandler(error, eventName, event, data);
|
|
475
|
-
} else {
|
|
476
|
-
console.error(`Error in event handler for '${eventName}':`, error);
|
|
477
|
-
}
|
|
478
|
-
}
|
|
479
|
-
});
|
|
480
|
-
}
|
|
481
|
-
/**
|
|
482
|
-
* Check if the event and handler are subscribed.
|
|
483
|
-
*
|
|
484
|
-
* @param subscription The subscription object.
|
|
485
|
-
* @returns true if the event name and handler are subscribed, false otherwise.
|
|
486
|
-
*/
|
|
487
|
-
isSubscribed({ eventName, contextEventHandler }) {
|
|
488
|
-
return this.subscribers.get(eventName)?.has(contextEventHandler) ?? false;
|
|
489
|
-
}
|
|
490
|
-
/**
|
|
491
|
-
* Validate the event name
|
|
492
|
-
*
|
|
493
|
-
* @param eventName The event name to validate.
|
|
494
|
-
* @throws {TypeError} If the event name is not a non-empty string.
|
|
495
|
-
* @throws {Error} If the event name has leading or trailing whitespace.
|
|
496
|
-
*/
|
|
497
|
-
validateEventName(eventName) {
|
|
498
|
-
if (!eventName || typeof eventName !== "string") {
|
|
499
|
-
throw new TypeError("Event name must be a non-empty string");
|
|
500
|
-
}
|
|
501
|
-
if (eventName.trim() !== eventName) {
|
|
502
|
-
throw new Error("Event name cannot have leading or trailing whitespace");
|
|
503
|
-
}
|
|
504
|
-
}
|
|
505
|
-
/**
|
|
506
|
-
* Clears all subscriptions. The instance should not be used after calling this method.
|
|
507
|
-
*/
|
|
508
|
-
destroy() {
|
|
509
|
-
this.subscribers.clear();
|
|
510
|
-
}
|
|
511
|
-
/**
|
|
512
|
-
* A String value that is used in the creation of the default string
|
|
513
|
-
* description of an object. Called by the built-in method {@link Object.prototype.toString}.
|
|
514
|
-
*
|
|
515
|
-
* @returns The default string description of this object.
|
|
516
|
-
*/
|
|
517
|
-
get [Symbol.toStringTag]() {
|
|
518
|
-
return "Subscribr";
|
|
519
|
-
}
|
|
520
|
-
};
|
|
521
|
-
|
|
522
|
-
// src/http-error.ts
|
|
523
|
-
var HttpError = class extends Error {
|
|
524
|
-
_entity;
|
|
525
|
-
responseStatus;
|
|
526
|
-
_url;
|
|
527
|
-
_method;
|
|
528
|
-
_timing;
|
|
529
|
-
/**
|
|
530
|
-
* Creates an instance of HttpError.
|
|
531
|
-
* @param status The status code and status text of the {@link Response}.
|
|
532
|
-
* @param httpErrorOptions The http error options.
|
|
533
|
-
*/
|
|
534
|
-
constructor(status, { message, cause, entity, url, method, timing } = {}) {
|
|
535
|
-
super(message, { cause });
|
|
536
|
-
this._entity = entity;
|
|
537
|
-
this.responseStatus = status;
|
|
538
|
-
this._url = url;
|
|
539
|
-
this._method = method;
|
|
540
|
-
this._timing = timing;
|
|
541
|
-
}
|
|
542
|
-
/**
|
|
543
|
-
* It returns the value of the private variable #entity.
|
|
544
|
-
* @returns The entity property of the class.
|
|
545
|
-
*/
|
|
546
|
-
get entity() {
|
|
547
|
-
return this._entity;
|
|
548
|
-
}
|
|
549
|
-
/**
|
|
550
|
-
* It returns the status code of the {@link Response}.
|
|
551
|
-
* @returns The status code of the {@link Response}.
|
|
552
|
-
*/
|
|
553
|
-
get statusCode() {
|
|
554
|
-
return this.responseStatus.code;
|
|
555
|
-
}
|
|
556
|
-
/**
|
|
557
|
-
* It returns the status text of the {@link Response}.
|
|
558
|
-
* @returns The status code and status text of the {@link Response}.
|
|
559
|
-
*/
|
|
560
|
-
get statusText() {
|
|
561
|
-
return this.responseStatus?.text;
|
|
562
|
-
}
|
|
563
|
-
/**
|
|
564
|
-
* The request URL that caused the error.
|
|
565
|
-
* @returns The URL or undefined.
|
|
566
|
-
*/
|
|
567
|
-
get url() {
|
|
568
|
-
return this._url;
|
|
569
|
-
}
|
|
570
|
-
/**
|
|
571
|
-
* The HTTP method that was used for the failed request.
|
|
572
|
-
* @returns The method string or undefined.
|
|
573
|
-
*/
|
|
574
|
-
get method() {
|
|
575
|
-
return this._method;
|
|
576
|
-
}
|
|
577
|
-
/**
|
|
578
|
-
* Timing information for the failed request.
|
|
579
|
-
* @returns The timing object or undefined.
|
|
580
|
-
*/
|
|
581
|
-
get timing() {
|
|
582
|
-
return this._timing;
|
|
583
|
-
}
|
|
584
|
-
/**
|
|
585
|
-
* A String value representing the name of the error.
|
|
586
|
-
* @returns The name of the error.
|
|
587
|
-
*/
|
|
588
|
-
get name() {
|
|
589
|
-
return "HttpError";
|
|
590
|
-
}
|
|
591
|
-
/**
|
|
592
|
-
* A String value that is used in the creation of the default string
|
|
593
|
-
* description of an object. Called by the built-in method {@link Object.prototype.toString}.
|
|
594
|
-
* @returns The default string description of this object.
|
|
595
|
-
*/
|
|
596
|
-
get [Symbol.toStringTag]() {
|
|
597
|
-
return this.name;
|
|
598
|
-
}
|
|
599
|
-
};
|
|
600
|
-
|
|
601
|
-
// src/http-media-type.ts
|
|
602
|
-
var HttpMediaType = {
|
|
603
|
-
/** Advanced Audio Coding (AAC) */
|
|
604
|
-
AAC: "audio/aac",
|
|
605
|
-
/** AbiWord */
|
|
606
|
-
ABW: "application/x-abiword",
|
|
607
|
-
/** Archive document (multiple files embedded) */
|
|
608
|
-
ARC: "application/x-freearc",
|
|
609
|
-
/** AVIF image */
|
|
610
|
-
AVIF: "image/avif",
|
|
611
|
-
/** Audio Video Interleave (AVI) */
|
|
612
|
-
AVI: "video/x-msvideo",
|
|
613
|
-
/** Amazon Kindle eBook format */
|
|
614
|
-
AZW: "application/vnd.amazon.ebook",
|
|
615
|
-
/** Binary Data */
|
|
616
|
-
BIN: "application/octet-stream",
|
|
617
|
-
/** Windows OS/2 Bitmap Graphics */
|
|
618
|
-
BMP: "image/bmp",
|
|
619
|
-
/** Bzip Archive */
|
|
620
|
-
BZIP: "application/x-bzip",
|
|
621
|
-
/** Bzip2 Archive */
|
|
622
|
-
BZIP2: "application/x-bzip2",
|
|
623
|
-
/** CD audio */
|
|
624
|
-
CDA: "application/x-cdf",
|
|
625
|
-
/** C Shell Script */
|
|
626
|
-
CSH: "application/x-csh",
|
|
627
|
-
/** Cascading Style Sheets (CSS) */
|
|
628
|
-
CSS: "text/css",
|
|
629
|
-
/** Comma-Separated Values */
|
|
630
|
-
CSV: "text/csv",
|
|
631
|
-
/** Microsoft Office Word Document */
|
|
632
|
-
DOC: "application/msword",
|
|
633
|
-
/** Microsoft Office Word Document (OpenXML) */
|
|
634
|
-
DOCX: "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
|
635
|
-
/** Microsoft Embedded OpenType */
|
|
636
|
-
EOT: "application/vnd.ms-fontobject",
|
|
637
|
-
/** Electronic Publication (EPUB) */
|
|
638
|
-
EPUB: "application/epub+zip",
|
|
639
|
-
/** GZip Compressed Archive */
|
|
640
|
-
GZIP: "application/gzip",
|
|
641
|
-
/** Graphics Interchange Format */
|
|
642
|
-
GIF: "image/gif",
|
|
643
|
-
/** HyperText Markup Language (HTML) */
|
|
644
|
-
HTML: "text/html",
|
|
645
|
-
/** Icon Format */
|
|
646
|
-
ICO: "image/vnd.microsoft.icon",
|
|
647
|
-
/** iCalendar Format */
|
|
648
|
-
ICS: "text/calendar",
|
|
649
|
-
/** Java Archive (JAR) */
|
|
650
|
-
JAR: "application/java-archive",
|
|
651
|
-
/** JPEG Image */
|
|
652
|
-
JPEG: "image/jpeg",
|
|
653
|
-
/** JavaScript */
|
|
654
|
-
JAVA_SCRIPT: "text/javascript",
|
|
655
|
-
/** JavaScript Object Notation Format (JSON) */
|
|
656
|
-
JSON: "application/json",
|
|
657
|
-
/** JavaScript Object Notation LD Format */
|
|
658
|
-
JSON_LD: "application/ld+json",
|
|
659
|
-
/** JavaScript Object Notation (JSON) Merge Patch */
|
|
660
|
-
JSON_MERGE_PATCH: "application/merge-patch+json",
|
|
661
|
-
/** Musical Instrument Digital Interface (MIDI) */
|
|
662
|
-
MID: "audio/midi",
|
|
663
|
-
/** Musical Instrument Digital Interface (MIDI) */
|
|
664
|
-
X_MID: "audio/x-midi",
|
|
665
|
-
/** MP3 Audio */
|
|
666
|
-
MP3: "audio/mpeg",
|
|
667
|
-
/** MPEG-4 Audio */
|
|
668
|
-
MP4A: "audio/mp4",
|
|
669
|
-
/** MPEG-4 Video */
|
|
670
|
-
MP4: "video/mp4",
|
|
671
|
-
/** MPEG Video */
|
|
672
|
-
MPEG: "video/mpeg",
|
|
673
|
-
/** Apple Installer Package */
|
|
674
|
-
MPKG: "application/vnd.apple.installer+xml",
|
|
675
|
-
/** OpenDocument Presentation Document */
|
|
676
|
-
ODP: "application/vnd.oasis.opendocument.presentation",
|
|
677
|
-
/** OpenDocument Spreadsheet Document */
|
|
678
|
-
ODS: "application/vnd.oasis.opendocument.spreadsheet",
|
|
679
|
-
/** OpenDocument Text Document */
|
|
680
|
-
ODT: "application/vnd.oasis.opendocument.text",
|
|
681
|
-
/** Ogg Audio */
|
|
682
|
-
OGA: "audio/ogg",
|
|
683
|
-
/** Ogg Video */
|
|
684
|
-
OGV: "video/ogg",
|
|
685
|
-
/** Ogg */
|
|
686
|
-
OGX: "application/ogg",
|
|
687
|
-
/** Opus audio */
|
|
688
|
-
OPUS: "audio/opus",
|
|
689
|
-
/** OpenType Font File */
|
|
690
|
-
OTF: "font/otf",
|
|
691
|
-
/** Portable Network Graphics (PNG) */
|
|
692
|
-
PNG: "image/png",
|
|
693
|
-
/** Adobe Portable Document Format */
|
|
694
|
-
PDF: "application/pdf",
|
|
695
|
-
/** Hypertext Preprocessor (Personal Home Page) */
|
|
696
|
-
PHP: "application/x-httpd-php",
|
|
697
|
-
/** Microsoft PowerPoint */
|
|
698
|
-
PPT: "application/vnd.ms-powerpoint",
|
|
699
|
-
/** Microsoft Office Presentation (OpenXML) */
|
|
700
|
-
PPTX: "application/vnd.openxmlformats-officedocument.presentationml.presentation",
|
|
701
|
-
/** RAR Archive */
|
|
702
|
-
RAR: "application/vnd.rar",
|
|
703
|
-
/** Rich Text Format */
|
|
704
|
-
RTF: "application/rtf",
|
|
705
|
-
/** Bourne Shell Script */
|
|
706
|
-
SH: "application/x-sh",
|
|
707
|
-
/** Scalable Vector Graphics (SVG) */
|
|
708
|
-
SVG: "image/svg+xml",
|
|
709
|
-
/** Tape Archive (TAR) */
|
|
710
|
-
TAR: "application/x-tar",
|
|
711
|
-
/** Tagged Image File Format (TIFF) */
|
|
712
|
-
TIFF: "image/tiff",
|
|
713
|
-
/** MPEG transport stream */
|
|
714
|
-
TRANSPORT_STREAM: "video/mp2t",
|
|
715
|
-
/** TrueType Font */
|
|
716
|
-
TTF: "font/ttf",
|
|
717
|
-
/** Text, (generally ASCII or ISO 8859-n) */
|
|
718
|
-
TEXT: "text/plain",
|
|
719
|
-
/** Microsoft Visio */
|
|
720
|
-
VSD: "application/vnd.visio",
|
|
721
|
-
/** Waveform Audio Format (WAV) */
|
|
722
|
-
WAV: "audio/wav",
|
|
723
|
-
/** Open Web Media Project - Audio */
|
|
724
|
-
WEBA: "audio/webm",
|
|
725
|
-
/** Open Web Media Project - Video */
|
|
726
|
-
WEBM: "video/webm",
|
|
727
|
-
/** WebP Image */
|
|
728
|
-
WEBP: "image/webp",
|
|
729
|
-
/** Web Open Font Format */
|
|
730
|
-
WOFF: "font/woff",
|
|
731
|
-
/** Web Open Font Format */
|
|
732
|
-
WOFF2: "font/woff2",
|
|
733
|
-
/** Form - Encoded */
|
|
734
|
-
FORM: "application/x-www-form-urlencoded",
|
|
735
|
-
/** Multipart FormData */
|
|
736
|
-
MULTIPART_FORM_DATA: "multipart/form-data",
|
|
737
|
-
/** XHTML - The Extensible HyperText Markup Language */
|
|
738
|
-
XHTML: "application/xhtml+xml",
|
|
739
|
-
/** Microsoft Excel Document */
|
|
740
|
-
XLS: "application/vnd.ms-excel",
|
|
741
|
-
/** Microsoft Office Spreadsheet Document (OpenXML) */
|
|
742
|
-
XLSX: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
|
743
|
-
/** Extensible Markup Language (XML) */
|
|
744
|
-
XML: "application/xml",
|
|
745
|
-
/** XML User Interface Language (XUL) */
|
|
746
|
-
XUL: "application/vnd.mozilla.xul+xml",
|
|
747
|
-
/** Zip Archive */
|
|
748
|
-
ZIP: "application/zip",
|
|
749
|
-
/** 3GPP audio/video container */
|
|
750
|
-
"3GP": "video/3gpp",
|
|
751
|
-
/** 3GPP2 audio/video container */
|
|
752
|
-
"3G2": "video/3gpp2",
|
|
753
|
-
/** 7-Zip Archive */
|
|
754
|
-
"7Z": "application/x-7z-compressed"
|
|
755
|
-
};
|
|
756
|
-
|
|
757
|
-
// src/http-request-headers.ts
|
|
758
|
-
var HttpRequestHeader = {
|
|
759
|
-
/**
|
|
760
|
-
* Content-Types that are acceptable for the response. See Content negotiation. Permanent.
|
|
761
|
-
*
|
|
762
|
-
* @example
|
|
763
|
-
* <code>Accept: text/plain</code>
|
|
764
|
-
*/
|
|
765
|
-
ACCEPT: "accept",
|
|
766
|
-
/**
|
|
767
|
-
* Character sets that are acceptable. Permanent.
|
|
768
|
-
*
|
|
769
|
-
* @example
|
|
770
|
-
* <code>Accept-Charset: utf-8</code>
|
|
771
|
-
*/
|
|
772
|
-
ACCEPT_CHARSET: "accept-charset",
|
|
773
|
-
/**
|
|
774
|
-
* List of acceptable encodings. See HTTP compression. Permanent.
|
|
775
|
-
*
|
|
776
|
-
* @example
|
|
777
|
-
* <code>Accept-Encoding: gzip, deflate</code>
|
|
778
|
-
*/
|
|
779
|
-
ACCEPT_ENCODING: "accept-encoding",
|
|
780
|
-
/**
|
|
781
|
-
* List of acceptable human languages for response. See Content negotiation. Permanent.
|
|
782
|
-
*
|
|
783
|
-
* @example
|
|
784
|
-
* <code>Accept-Language: en-US</code>
|
|
785
|
-
*/
|
|
786
|
-
ACCEPT_LANGUAGE: "accept-language",
|
|
787
|
-
/**
|
|
788
|
-
* Authentication credentials for HTTP authentication. Permanent.
|
|
789
|
-
*
|
|
790
|
-
* @example
|
|
791
|
-
* <code>Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==</code>
|
|
792
|
-
*/
|
|
793
|
-
AUTHORIZATION: "authorization",
|
|
794
|
-
/**
|
|
795
|
-
* Used to specify directives that must be obeyed by all caching mechanisms along the request-response chain.
|
|
796
|
-
* Permanent.
|
|
797
|
-
*
|
|
798
|
-
* @example
|
|
799
|
-
* <code>Cache-Control: no-cache</code>
|
|
800
|
-
*/
|
|
801
|
-
CACHE_CONTROL: "cache-control",
|
|
802
|
-
/**
|
|
803
|
-
* Control options for the current connection and list of hop-by-hop request fields. Permanent.
|
|
804
|
-
*
|
|
805
|
-
* @example
|
|
806
|
-
* <code>Connection: keep-alive</code>
|
|
807
|
-
* <code>Connection: Upgrade</code>
|
|
808
|
-
*/
|
|
809
|
-
CONNECTION: "connection",
|
|
810
|
-
/**
|
|
811
|
-
* An HTTP cookie previously sent by the server with Set-Cookie (below). Permanent: standard.
|
|
812
|
-
*
|
|
813
|
-
* @example
|
|
814
|
-
* <code>Cookie: $Version=1, Skin=new,</code>
|
|
815
|
-
*/
|
|
816
|
-
COOKIE: "cookie",
|
|
817
|
-
/**
|
|
818
|
-
* The length of the request body in octets (8-bit bytes). Permanent.
|
|
819
|
-
*
|
|
820
|
-
* @example
|
|
821
|
-
* <code>Content-Length: 348</code>
|
|
822
|
-
*/
|
|
823
|
-
CONTENT_LENGTH: "content-length",
|
|
824
|
-
/**
|
|
825
|
-
* A Base64-encoded binary MD5 sum of the content of the request body. Obsolete.
|
|
826
|
-
*
|
|
827
|
-
* @example
|
|
828
|
-
* <code>Content-MD5: Q2hlY2sgSW50ZWdyaXR5IQ==</code>
|
|
829
|
-
*/
|
|
830
|
-
CONTENT_MD5: "content-md5",
|
|
831
|
-
/**
|
|
832
|
-
* The MIME type of the body of the request (used with POST and PUT requests). Permanent.
|
|
833
|
-
* <code>Content-Type: application/x-www-form-urlencoded</code>
|
|
834
|
-
*/
|
|
835
|
-
CONTENT_TYPE: "content-type",
|
|
836
|
-
/**
|
|
837
|
-
* The date and time that the message was sent (in "HTTP-date" format as defined by RFC 7231 Date/Time Formats).
|
|
838
|
-
* Permanent.
|
|
839
|
-
*
|
|
840
|
-
* @example
|
|
841
|
-
* <code>Date: Tue, 15 Nov 1994 08:12:31 GMT</code>
|
|
842
|
-
*/
|
|
843
|
-
DATE: "date",
|
|
844
|
-
/**
|
|
845
|
-
* The domain name of the server (for virtual hosting), and the TCP port number on which the server is listening. The
|
|
846
|
-
* port number may be omitted if the port is the standard port for the service requested. Permanent. Mandatory since
|
|
847
|
-
* HTTP/1.1.
|
|
848
|
-
*
|
|
849
|
-
* @example
|
|
850
|
-
* <code>Host: en.wikipedia.org:80</code>
|
|
851
|
-
* <code>Host: en.wikipedia.org</code>
|
|
852
|
-
*/
|
|
853
|
-
HOST: "host",
|
|
854
|
-
/**
|
|
855
|
-
* Only perform the action if the client supplied entity matches the same entity on the server. This is mainly for
|
|
856
|
-
* methods like PUT to only update a resource if it has not been modified since the user last updated it. Permanent.
|
|
857
|
-
*
|
|
858
|
-
* @example
|
|
859
|
-
* <code>If-Match: "737060cd8c284d8af7ad3082f209582d"</code>
|
|
860
|
-
*/
|
|
861
|
-
IF_MATCH: "if-match",
|
|
862
|
-
/**
|
|
863
|
-
* Allows a 304 Not Modified to be returned if content is unchanged. Permanent.
|
|
864
|
-
*
|
|
865
|
-
* @example
|
|
866
|
-
* <code>If-Modified-Since: Sat, 29 Oct 1994 19:43:31 GMT</code>
|
|
867
|
-
*/
|
|
868
|
-
IF_MODIFIED_SINCE: "if-modified-since",
|
|
869
|
-
/**
|
|
870
|
-
* Allows a 304 Not Modified to be returned if content is unchanged, see HTTP ETag. Permanent.
|
|
871
|
-
*
|
|
872
|
-
* @example
|
|
873
|
-
* <code>If-None-Match: "737060cd8c284d8af7ad3082f209582d"</code>
|
|
874
|
-
*/
|
|
875
|
-
IF_NONE_MATCH: "if-none-match",
|
|
876
|
-
/**
|
|
877
|
-
* If the entity is unchanged, send me the part(s) that I am missing, otherwise, send me the entire new entity.
|
|
878
|
-
* Permanent.
|
|
879
|
-
*
|
|
880
|
-
* @example
|
|
881
|
-
* <code>If-Range: "737060cd8c284d8af7ad3082f209582d"</code>
|
|
882
|
-
*/
|
|
883
|
-
IF_RANGE: "if-range",
|
|
884
|
-
/**
|
|
885
|
-
* Only send the response if the entity has not been modified since a specific time. Permanent.
|
|
886
|
-
*
|
|
887
|
-
* @example
|
|
888
|
-
* <code>If-Unmodified-Since: Sat, 29 Oct 1994 19:43:31 GMT</code>
|
|
889
|
-
*/
|
|
890
|
-
IF_UNMODIFIED_SINCE: "if-unmodified-since",
|
|
891
|
-
/**
|
|
892
|
-
* Limit the number of times the message can be forwarded through proxies or gateways. Permanent.
|
|
893
|
-
*
|
|
894
|
-
* @example
|
|
895
|
-
* <code>Max-Forwards: 10</code>
|
|
896
|
-
*/
|
|
897
|
-
MAX_FORWARDS: "max-forwards",
|
|
898
|
-
/**
|
|
899
|
-
* Initiates a request for cross-origin resource sharing (asks server for an 'Access-Control-Allow-Origin' response
|
|
900
|
-
* field). Permanent: standard.
|
|
901
|
-
*
|
|
902
|
-
* @example
|
|
903
|
-
* <code>Origin: http://www.example-social-network.com</code>
|
|
904
|
-
*/
|
|
905
|
-
ORIGIN: "origin",
|
|
906
|
-
/**
|
|
907
|
-
* Implementation-specific fields that may have various effects anywhere along the request-response chain. Permanent.
|
|
908
|
-
*
|
|
909
|
-
* @example
|
|
910
|
-
* <code>Pragma: no-cache</code>
|
|
911
|
-
*/
|
|
912
|
-
PRAGMA: "pragma",
|
|
913
|
-
/**
|
|
914
|
-
* Authorization credentials for connecting to a proxy. Permanent.
|
|
915
|
-
*
|
|
916
|
-
* @example
|
|
917
|
-
* <code>Proxy-Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==</code>
|
|
918
|
-
*/
|
|
919
|
-
PROXY_AUTHORIZATION: "proxy-authorization",
|
|
920
|
-
/**
|
|
921
|
-
* Request only part of an entity. Bytes are numbered from 0. See Byte serving. Permanent.
|
|
922
|
-
*
|
|
923
|
-
* @example
|
|
924
|
-
* <code>Range: bytes=500-999</code>
|
|
925
|
-
*/
|
|
926
|
-
RANGE: "range",
|
|
927
|
-
/**
|
|
928
|
-
* This is the address of the previous web page from which a link to the currently requested page was followed. (The
|
|
929
|
-
* word "referrer" has been misspelled in the RFC as well as in most implementations to the point that it has become
|
|
930
|
-
* standard usage and is considered correct terminology). Permanent.
|
|
931
|
-
*
|
|
932
|
-
* @example
|
|
933
|
-
* <code>Referer: http://en.wikipedia.org/wiki/Main_Page</code>
|
|
934
|
-
*/
|
|
935
|
-
REFERER: "referer",
|
|
936
|
-
/**
|
|
937
|
-
* The transfer encodings the user agent is willing to accept: the same values as for the response header field
|
|
938
|
-
* Transfer-Encoding can be used, plus the "trailers" value (related to the "chunked" transfer method) to notify the
|
|
939
|
-
* server it expects to receive additional fields in the trailer after the last, zero-sized, chunk. Permanent.
|
|
940
|
-
*
|
|
941
|
-
* @example
|
|
942
|
-
* <code>TE: trailers, deflate</code>
|
|
943
|
-
*/
|
|
944
|
-
TE: "te",
|
|
945
|
-
/**
|
|
946
|
-
* The user agent string of the user agent. Permanent.
|
|
947
|
-
*
|
|
948
|
-
* @example
|
|
949
|
-
* <code>User-Agent: Mozilla/5.0 (X11, Linux x86_64, rv:12.0) Gecko/20100101 Firefox/21.0</code>
|
|
950
|
-
*/
|
|
951
|
-
USER_AGENT: "user-agent",
|
|
952
|
-
/**
|
|
953
|
-
* Ask the server to upgrade to another protocol. Permanent.
|
|
954
|
-
*
|
|
955
|
-
* @example
|
|
956
|
-
* <code>Upgrade: HTTP/2.0, SHTTP/1.3, IRC/6.9, RTA/x11</code>
|
|
957
|
-
*/
|
|
958
|
-
UPGRADE: "upgrade",
|
|
959
|
-
/**
|
|
960
|
-
* A general warning about possible problems with the entity body. Permanent.
|
|
961
|
-
*
|
|
962
|
-
* @example
|
|
963
|
-
* <code>Warning: 199 Miscellaneous warning</code>
|
|
964
|
-
*/
|
|
965
|
-
WARNING: "warning",
|
|
966
|
-
/**
|
|
967
|
-
* mainly used to identify Ajax requests. Most JavaScript frameworks send this field with value of XMLHttpRequest.
|
|
968
|
-
*
|
|
969
|
-
* @example
|
|
970
|
-
* <code>X-Requested-With: XMLHttpRequest</code>
|
|
971
|
-
*/
|
|
972
|
-
X_REQUESTED_WITH: "x-requested-with",
|
|
973
|
-
/**
|
|
974
|
-
* A de facto standard for identifying the originating IP address of a client connecting to a web server through an
|
|
975
|
-
* HTTP proxy or load balancer.
|
|
976
|
-
*
|
|
977
|
-
* @example
|
|
978
|
-
* <code>X-Forwarded-For: client1, proxy1, proxy2</code>
|
|
979
|
-
* <code>X-Forwarded-For: 129.78.138.66, 129.78.64.103</code>
|
|
980
|
-
*/
|
|
981
|
-
X_FORWARDED_FOR: "x-forwarded-for",
|
|
982
|
-
/**
|
|
983
|
-
* A de facto standard for identifying the original host requested by the client in the Host HTTP request header, since
|
|
984
|
-
* the host name and/or port of the reverse proxy (load balancer) may differ from the origin server handling the
|
|
985
|
-
* request.
|
|
986
|
-
*
|
|
987
|
-
* @example
|
|
988
|
-
* <code>X-Forwarded-Host: en.wikipedia.org:80</code>
|
|
989
|
-
* <code>X-Forwarded-Host: en.wikipedia.org</code>
|
|
990
|
-
*/
|
|
991
|
-
X_FORWARDED_HOST: "x-forwarded-host",
|
|
992
|
-
/**
|
|
993
|
-
* A de facto standard for identifying the originating protocol of an HTTP request, since a reverse proxy (load
|
|
994
|
-
* balancer) may communicate with a web server using HTTP even if the request to the reverse proxy is HTTPS. An
|
|
995
|
-
* alternative form of the header (X-ProxyUser-Ip) is used by Google clients talking to Google servers.
|
|
996
|
-
*
|
|
997
|
-
* @example
|
|
998
|
-
* <code>X-Forwarded-Proto: https</code>
|
|
999
|
-
*/
|
|
1000
|
-
X_FORWARDED_PROTO: "x-forwarded-proto"
|
|
1001
|
-
};
|
|
1002
|
-
|
|
1003
|
-
// src/http-request-methods.ts
|
|
1004
|
-
var HttpRequestMethod = {
|
|
1005
|
-
/**
|
|
1006
|
-
* The OPTIONS method represents a request for information about the communication options available on the
|
|
1007
|
-
* request/response chain identified by the Request-URI. This method allows the client to determine the options and/or
|
|
1008
|
-
* requirements associated with a resource, or the capabilities of a server, without implying a resource action or
|
|
1009
|
-
* initiating a resource retrieval.
|
|
1010
|
-
*
|
|
1011
|
-
* Responses to this method are not cacheable.
|
|
1012
|
-
*
|
|
1013
|
-
* If the OPTIONS request includes an entity-body (as indicated by the presence of Content-Length or
|
|
1014
|
-
* Transfer-Encoding), then the media type MUST be indicated by a Content-Type field. Although this specification does
|
|
1015
|
-
* not define any use for such a body, future extensions to HTTP might use the OPTIONS body to make more detailed
|
|
1016
|
-
* queries on the server. A server that does not support such an extension MAY discard the request body.
|
|
1017
|
-
*
|
|
1018
|
-
* If the Request-URI is an asterisk ("*"), the OPTIONS request is intended to apply to the server in general rather
|
|
1019
|
-
* than to a specific resource. Since a server's communication options typically depend on the resource, the "*"
|
|
1020
|
-
* request is only useful as a "ping" or "no-op" type of method, it does nothing beyond allowing the client to test the
|
|
1021
|
-
* capabilities of the server. For example, this can be used to test a proxy for HTTP/1.1 compliance (or lack thereof).
|
|
1022
|
-
*
|
|
1023
|
-
* If the Request-URI is not an asterisk, the OPTIONS request applies only to the options that are available when
|
|
1024
|
-
* communicating with that resource.
|
|
1025
|
-
*
|
|
1026
|
-
* A 200 response SHOULD include any header fields that indicate optional features implemented by the server and
|
|
1027
|
-
* applicable to that resource (e.g., Allow), possibly including extensions not defined by this specification. The
|
|
1028
|
-
* response body, if any, SHOULD also include information about the communication options. The format for such a body
|
|
1029
|
-
* is not defined by this specification, but might be defined by future extensions to HTTP. Content negotiation MAY be
|
|
1030
|
-
* used to select the appropriate response format. If no response body is included, the response MUST include a
|
|
1031
|
-
* Content-Length field with a field-value of "0".
|
|
1032
|
-
*
|
|
1033
|
-
* The Max-Forwards request-header field MAY be used to target a specific proxy in the request chain. When a proxy
|
|
1034
|
-
* receives an OPTIONS request on an absoluteURI for which request forwarding is permitted, the proxy MUST check for a
|
|
1035
|
-
* Max-Forwards field. If the Max-Forwards field-value is zero ("0"), the proxy MUST NOT forward the message, instead,
|
|
1036
|
-
* the proxy SHOULD respond with its own communication options. If the Max-Forwards field-value is an integer greater
|
|
1037
|
-
* than zero, the proxy MUST decrement the field-value when it forwards the request. If no Max-Forwards field is
|
|
1038
|
-
* present in the request, then the forwarded request MUST NOT include a Max-Forwards field.
|
|
1039
|
-
*/
|
|
1040
|
-
OPTIONS: "OPTIONS",
|
|
1041
|
-
/**
|
|
1042
|
-
* The GET method means retrieve whatever information (in the form of an entity) is identified by the Request-URI. If
|
|
1043
|
-
* the Request-URI refers to a data-producing process, it is the produced data which shall be returned as the entity in
|
|
1044
|
-
* the response and not the source text of the process, unless that text happens to be the output of the process.
|
|
1045
|
-
*
|
|
1046
|
-
* The semantics of the GET method change to a "conditional GET" if the request message includes an If-Modified-Since;
|
|
1047
|
-
* If-Unmodified-Since, If-Match, If-None-Match, or If-Range header field. A conditional GET method requests that the
|
|
1048
|
-
* entity be transferred only under the circumstances described by the conditional header field(s). The conditional GET
|
|
1049
|
-
* method is intended to reduce unnecessary network usage by allowing cached entities to be refreshed without requiring
|
|
1050
|
-
* multiple requests or transferring data already held by the client.
|
|
1051
|
-
*
|
|
1052
|
-
* The semantics of the GET method change to a "partial GET" if the request message includes a Range header field. A
|
|
1053
|
-
* partial GET requests that only part of the entity be transferred, as described in section 14.35. The partial GET
|
|
1054
|
-
* method is intended to reduce unnecessary network usage by allowing partially-retrieved entities to be completed
|
|
1055
|
-
* without transferring data already held by the client.
|
|
1056
|
-
*
|
|
1057
|
-
* The response to a GET request is cacheable if and only if it meets the requirements for HTTP caching described in
|
|
1058
|
-
* section 13.
|
|
1059
|
-
*
|
|
1060
|
-
* See section 15.1.3 for security considerations when used for forms.
|
|
1061
|
-
*/
|
|
1062
|
-
GET: "GET",
|
|
1063
|
-
/**
|
|
1064
|
-
* The HEAD method is identical to GET except that the server MUST NOT return a message-body in the response. The
|
|
1065
|
-
* meta information contained in the HTTP headers in response to a HEAD request SHOULD be identical to the information
|
|
1066
|
-
* sent in response to a GET request. This method can be used for obtaining meta information about the entity implied by
|
|
1067
|
-
* the request without transferring the entity-body itself. This method is often used for testing hypertext links for
|
|
1068
|
-
* validity, accessibility, and recent modification.
|
|
1069
|
-
*
|
|
1070
|
-
* The response to a HEAD request MAY be cacheable in the sense that the information contained in the response MAY be
|
|
1071
|
-
* used to update a previously cached entity from that resource. If the new field values indicate that the cached
|
|
1072
|
-
* entity differs from the current entity (as would be indicated by a change in Content-Length, Content-MD5, ETag or
|
|
1073
|
-
* Last-Modified), then the cache MUST treat the cache entry as stale.
|
|
1074
|
-
*/
|
|
1075
|
-
HEAD: "HEAD",
|
|
1076
|
-
/**
|
|
1077
|
-
* The POST method is used to request that the origin server accept the entity enclosed in the request as a new
|
|
1078
|
-
* subordinate of the resource identified by the Request-URI in the Request-Line. POST is designed to allow a uniform
|
|
1079
|
-
* method to cover the following functions:
|
|
1080
|
-
* <ul>
|
|
1081
|
-
* <li>Annotation of existing resources,</li>
|
|
1082
|
-
* <li>Posting a message to a bulletin board, newsgroup, mailing list, or similar group of articles,</li>
|
|
1083
|
-
* <li>Providing a block of data, such as the result of submitting a form, to a data-handling process,</li>
|
|
1084
|
-
* <li>Extending a database through an append operation.</li>
|
|
1085
|
-
* </ul>
|
|
1086
|
-
*
|
|
1087
|
-
* The actual function performed by the POST method is determined by the server and is usually dependent on the
|
|
1088
|
-
* Request-URI. The posted entity is subordinate to that URI in the same way that a file is subordinate to a directory
|
|
1089
|
-
* containing it, a news article is subordinate to a newsgroup to which it is posted, or a record is subordinate to a
|
|
1090
|
-
* database.
|
|
1091
|
-
*
|
|
1092
|
-
* The action performed by the POST method might not result in a resource that can be identified by a URI. In this
|
|
1093
|
-
* case, either 200 (OK) or 204 (No Content) is the appropriate response status, depending on whether or not the
|
|
1094
|
-
* response includes an entity that describes the result.
|
|
1095
|
-
*
|
|
1096
|
-
* If a resource has been created on the origin server, the response SHOULD be 201 (Created) and contain an entity
|
|
1097
|
-
* which describes the status of the request and refers to the new resource, and a Location header (see section 14.30).
|
|
1098
|
-
*
|
|
1099
|
-
* Responses to this method are not cacheable, unless the response includes appropriate Cache-Control or Expires header
|
|
1100
|
-
* fields. However, the 303 (See Other) response can be used to direct the user agent to retrieve a cacheable resource.
|
|
1101
|
-
*
|
|
1102
|
-
* POST requests MUST obey the message transmission requirements set out in section 8.2.
|
|
1103
|
-
*
|
|
1104
|
-
* See section 15.1.3 for security considerations.
|
|
1105
|
-
*/
|
|
1106
|
-
POST: "POST",
|
|
1107
|
-
/**
|
|
1108
|
-
* The PUT method requests that the enclosed entity be stored under the supplied Request-URI. If the Request-URI refers
|
|
1109
|
-
* to an already existing resource, the enclosed entity SHOULD be considered as a modified version of the one residing
|
|
1110
|
-
* on the origin server. If the Request-URI does not point to an existing resource, and that URI is capable of being
|
|
1111
|
-
* defined as a new resource by the requesting user agent, the origin server can create the resource with that URI. If
|
|
1112
|
-
* a new resource is created, the origin server MUST inform the user agent via the 201 (Created) response. If an
|
|
1113
|
-
* existing resource is modified, either the 200 (OK) or 204 (No Content) response codes SHOULD be sent to indicate
|
|
1114
|
-
* successful completion of the request. If the resource could not be created or modified with the Request-URI, an
|
|
1115
|
-
* appropriate error response SHOULD be given that reflects the nature of the problem. The recipient of the entity MUST
|
|
1116
|
-
* \NOT ignore any Content-* (e.g. Content-Range) headers that it does not understand or implement and MUST return a
|
|
1117
|
-
* 501 (Not Implemented) response in such cases.
|
|
1118
|
-
*
|
|
1119
|
-
* If the request passes through a cache and the Request-URI identifies one or more currently cached entities, those
|
|
1120
|
-
* entries SHOULD be treated as stale. Responses to this method are not cacheable.
|
|
1121
|
-
*
|
|
1122
|
-
* The fundamental difference between the POST and PUT requests is reflected in the different meaning of the
|
|
1123
|
-
* Request-URI. The URI in a POST request identifies the resource that will handle the enclosed entity. That resource
|
|
1124
|
-
* might be a data-accepting process, a gateway to some other protocol, or a separate entity that accepts annotations.
|
|
1125
|
-
* In contrast, the URI in a PUT request identifies the entity enclosed with the request -- the user agent knows what
|
|
1126
|
-
* URI is intended and the server MUST NOT attempt to apply the request to some other resource. If the server desires
|
|
1127
|
-
* that the request be applied to a different URI, it MUST send a 301 (Moved Permanently) response, the user agent MAY
|
|
1128
|
-
* then make its own decision regarding whether or not to redirect the request.
|
|
1129
|
-
*
|
|
1130
|
-
* A single resource MAY be identified by many different URIs. For example, an article might have a URI for identifying
|
|
1131
|
-
* "the current version" which is separate from the URI identifying each particular version. In this case, a PUT
|
|
1132
|
-
* request on a general URI might result in several other URIs being defined by the origin server.
|
|
1133
|
-
*
|
|
1134
|
-
* HTTP/1.1 does not define how a PUT method affects the state of an origin server.
|
|
1135
|
-
*
|
|
1136
|
-
* PUT requests MUST obey the message transmission requirements set out in section 8.2.
|
|
1137
|
-
*
|
|
1138
|
-
* Unless otherwise specified for a particular entity-header, the entity-headers in the PUT request SHOULD be applied
|
|
1139
|
-
* to the resource created or modified by the PUT.
|
|
1140
|
-
*/
|
|
1141
|
-
PUT: "PUT",
|
|
1142
|
-
/**
|
|
1143
|
-
* The DELETE method requests that the origin server delete the resource identified by the Request-URI. This method MAY
|
|
1144
|
-
* be overridden by human intervention (or other means) on the origin server. The client cannot be guaranteed that the
|
|
1145
|
-
* operation has been carried out, even if the status code returned from the origin server indicates that the action
|
|
1146
|
-
* has been completed successfully. However, the server SHOULD NOT indicate success unless, at the time the response
|
|
1147
|
-
* is given, it intends to delete the resource or move it to an inaccessible location.
|
|
1148
|
-
*
|
|
1149
|
-
* A successful response SHOULD be 200 (OK) if the response includes an entity describing the status, 202 (Accepted) if
|
|
1150
|
-
* the action has not yet been enacted, or 204 (No Content) if the action has been enacted but the response does not
|
|
1151
|
-
* include an entity.
|
|
1152
|
-
*
|
|
1153
|
-
* If the request passes through a cache and the Request-URI identifies one or more currently cached entities, those
|
|
1154
|
-
* entries SHOULD be treated as stale. Responses to this method are not cacheable.
|
|
1155
|
-
*/
|
|
1156
|
-
DELETE: "DELETE",
|
|
1157
|
-
/**
|
|
1158
|
-
* The TRACE method is used to invoke a remote, application-layer loop- back of the request message. The final
|
|
1159
|
-
* recipient of the request SHOULD reflect the message received back to the client as the entity-body of a 200 (OK)
|
|
1160
|
-
* response. The final recipient is either the origin server or the first proxy or gateway to receive a Max-Forwards
|
|
1161
|
-
* value of zero (0) in the request (see section 14.31). A TRACE request MUST NOT include an entity.
|
|
1162
|
-
*
|
|
1163
|
-
* TRACE allows the client to see what is being received at the other end of the request chain and use that data for
|
|
1164
|
-
* testing or diagnostic information. The value of the Via header field (section 14.45) is of particular interest,
|
|
1165
|
-
* since it acts as a trace of the request chain. Use of the Max-Forwards header field allows the client to limit the
|
|
1166
|
-
* length of the request chain, which is useful for testing a chain of proxies forwarding messages in an infinite loop.
|
|
1167
|
-
*
|
|
1168
|
-
* If the request is valid, the response SHOULD contain the entire request message in the entity-body, with a
|
|
1169
|
-
* Content-Type of "message/http". Responses to this method MUST NOT be cached.
|
|
1170
|
-
*/
|
|
1171
|
-
TRACE: "TRACE",
|
|
1172
|
-
/**
|
|
1173
|
-
* This specification reserves the method name CONNECT for use with a proxy that can dynamically switch to being a
|
|
1174
|
-
* tunnel (e.g. SSL tunneling [44]).
|
|
1175
|
-
*/
|
|
1176
|
-
CONNECT: "CONNECT",
|
|
1177
|
-
/**
|
|
1178
|
-
* The PATCH method requests that a set of changes described in the
|
|
1179
|
-
* request entity be applied to the resource identified by the Request-
|
|
1180
|
-
* URI. The set of changes is represented in a format called a "patch
|
|
1181
|
-
* document" identified by a media type. If the Request-URI does not
|
|
1182
|
-
* point to an existing resource, the server MAY create a new resource,
|
|
1183
|
-
* depending on the patch document type (whether it can logically modify
|
|
1184
|
-
* a null resource) and permissions, etc.
|
|
1185
|
-
*
|
|
1186
|
-
* The difference between the PUT and PATCH requests is reflected in the
|
|
1187
|
-
* way the server processes the enclosed entity to modify the resource
|
|
1188
|
-
* identified by the Request-URI. In a PUT request, the enclosed entity
|
|
1189
|
-
* is considered to be a modified version of the resource stored on the
|
|
1190
|
-
* origin server, and the client is requesting that the stored version
|
|
1191
|
-
* be replaced. With PATCH, however, the enclosed entity contains a set
|
|
1192
|
-
* of instructions describing how a resource currently residing on the
|
|
1193
|
-
* origin server should be modified to produce a new version. The PATCH
|
|
1194
|
-
* method affects the resource identified by the Request-URI, and it
|
|
1195
|
-
* also MAY have side effects on other resources; i.e., new resources
|
|
1196
|
-
* may be created, or existing ones modified, by the application of a
|
|
1197
|
-
* PATCH.
|
|
1198
|
-
*
|
|
1199
|
-
* PATCH is neither safe nor idempotent as defined by [RFC2616], Section
|
|
1200
|
-
* 9.1.
|
|
1201
|
-
*
|
|
1202
|
-
* A PATCH request can be issued in such a way as to be idempotent,
|
|
1203
|
-
* which also helps prevent bad outcomes from collisions between two
|
|
1204
|
-
* PATCH requests on the same resource in a similar time frame.
|
|
1205
|
-
* Collisions from multiple PATCH requests may be more dangerous than
|
|
1206
|
-
* PUT collisions because some patch formats need to operate from a
|
|
1207
|
-
* known base-point or else they will corrupt the resource. Clients
|
|
1208
|
-
* using this kind of patch application SHOULD use a conditional request
|
|
1209
|
-
* such that the request will fail if the resource has been updated
|
|
1210
|
-
* since the client last accessed the resource. For example, the client
|
|
1211
|
-
* can use a strong ETag [RFC2616] in an If-Match header on the PATCH
|
|
1212
|
-
* request.
|
|
1213
|
-
*
|
|
1214
|
-
* There are also cases where patch formats do not need to operate from
|
|
1215
|
-
* a known base-point (e.g., appending text lines to log files, or non-
|
|
1216
|
-
* colliding rows to database tables), in which case the same care in
|
|
1217
|
-
* client requests is not needed.
|
|
1218
|
-
*
|
|
1219
|
-
* The server MUST apply the entire set of changes atomically and never
|
|
1220
|
-
* provide (e.g., in response to a GET during this operation) a
|
|
1221
|
-
* partially modified representation. If the entire patch document
|
|
1222
|
-
* cannot be successfully applied, then the server MUST NOT apply any of
|
|
1223
|
-
* the changes. The determination of what constitutes a successful
|
|
1224
|
-
* PATCH can vary depending on the patch document and the type of
|
|
1225
|
-
* resource(s) being modified. For example, the common 'diff' utility
|
|
1226
|
-
* can generate a patch document that applies to multiple files in a
|
|
1227
|
-
* directory hierarchy. The atomicity requirement holds for all
|
|
1228
|
-
* directly affected files. See "Error Handling", Section 2.2, for
|
|
1229
|
-
* details on status codes and possible error conditions.
|
|
1230
|
-
*
|
|
1231
|
-
* If the request passes through a cache and the Request-URI identifies
|
|
1232
|
-
* one or more currently cached entities, those entries SHOULD be
|
|
1233
|
-
* treated as stale. A response to this method is only cacheable if it
|
|
1234
|
-
* contains explicit freshness information (such as an Expires header or
|
|
1235
|
-
* "Cache-Control: max-age" directive) as well as the Content-Location
|
|
1236
|
-
* header matching the Request-URI, indicating that the PATCH response
|
|
1237
|
-
* body is a resource representation. A cached PATCH response can only
|
|
1238
|
-
* be used to respond to subsequent GET and HEAD requests; it MUST NOT
|
|
1239
|
-
* be used to respond to other methods (in particular, PATCH).
|
|
1240
|
-
*
|
|
1241
|
-
* Note that entity-headers contained in the request apply only to the
|
|
1242
|
-
* contained patch document and MUST NOT be applied to the resource
|
|
1243
|
-
* being modified. Thus, a Content-Language header could be present on
|
|
1244
|
-
* the request, but it would only mean (for whatever that's worth) that
|
|
1245
|
-
* the patch document had a language. Servers SHOULD NOT store such
|
|
1246
|
-
* headers except as trace information, and SHOULD NOT use such header
|
|
1247
|
-
* values the same way they might be used on PUT requests. Therefore,
|
|
1248
|
-
* this document does not specify a way to modify a document's Content-
|
|
1249
|
-
* Type or Content-Language value through headers, though a mechanism
|
|
1250
|
-
* could well be designed to achieve this goal through a patch document.
|
|
1251
|
-
*
|
|
1252
|
-
* There is no guarantee that a resource can be modified with PATCH.
|
|
1253
|
-
* Further, it is expected that different patch document formats will be
|
|
1254
|
-
* appropriate for different types of resources and that no single
|
|
1255
|
-
* format will be appropriate for all types of resources. Therefore,
|
|
1256
|
-
* there is no single default patch document format that implementations
|
|
1257
|
-
* are required to support. Servers MUST ensure that a received patch
|
|
1258
|
-
* document is appropriate for the type of resource identified by the
|
|
1259
|
-
* Request-URI.
|
|
1260
|
-
*
|
|
1261
|
-
* Clients need to choose when to use PATCH rather than PUT. For
|
|
1262
|
-
* example, if the patch document size is larger than the size of the
|
|
1263
|
-
* new resource data that would be used in a PUT, then it might make
|
|
1264
|
-
* sense to use PUT instead of PATCH. A comparison to POST is even more
|
|
1265
|
-
* difficult, because POST is used in widely varying ways and can
|
|
1266
|
-
* encompass PUT and PATCH-like operations if the server chooses. If
|
|
1267
|
-
* the operation does not modify the resource identified by the Request-
|
|
1268
|
-
* URI in a predictable way, POST should be considered instead of PATCH
|
|
1269
|
-
* or PUT.
|
|
1270
|
-
*/
|
|
1271
|
-
PATCH: "PATCH"
|
|
1272
|
-
};
|
|
1273
|
-
|
|
1274
|
-
// src/http-response-headers.ts
|
|
1275
|
-
var HttpResponseHeader = {
|
|
1276
|
-
/**
|
|
1277
|
-
* Implemented as a misunderstanding of the HTTP specifications. Common because of mistakes in implementations of early HTTP versions. Has exactly the same functionality as standard Connection field.
|
|
1278
|
-
*
|
|
1279
|
-
* @example
|
|
1280
|
-
* proxy-connection: keep-alive
|
|
1281
|
-
*/
|
|
1282
|
-
PROXY_CONNECTION: "proxy-connection",
|
|
1283
|
-
/**
|
|
1284
|
-
* Server-side deep packet insertion of a unique ID identifying customers of Verizon Wireless, also known as "perma-cookie" or "supercookie"
|
|
1285
|
-
*
|
|
1286
|
-
* @example
|
|
1287
|
-
* x-uidh: ...
|
|
1288
|
-
*/
|
|
1289
|
-
X_UIDH: "x-uidh",
|
|
1290
|
-
/**
|
|
1291
|
-
* Used to prevent cross-site request forgery. Alternative header names are: X-CSRFToken and X-XSRF-TOKEN
|
|
1292
|
-
*
|
|
1293
|
-
* @example
|
|
1294
|
-
* x-csrf-token: i8XNjC4b8KVok4uw5RftR38Wgp2BFwql
|
|
1295
|
-
*/
|
|
1296
|
-
X_CSRF_TOKEN: "x-csrf-token",
|
|
1297
|
-
/**
|
|
1298
|
-
* Specifying which web sites can participate in cross-origin resource sharing
|
|
1299
|
-
*
|
|
1300
|
-
* @example
|
|
1301
|
-
* access-control-allow-origin: *
|
|
1302
|
-
* Provisional
|
|
1303
|
-
*/
|
|
1304
|
-
ACCESS_CONTROL_ALLOW_ORIGIN: "access-control-allow-origin",
|
|
1305
|
-
/**
|
|
1306
|
-
* Specifies which patch document formats this server supports
|
|
1307
|
-
*
|
|
1308
|
-
* @example
|
|
1309
|
-
* accept-patch: text/example,charset=utf-8
|
|
1310
|
-
* Permanent
|
|
1311
|
-
*/
|
|
1312
|
-
ACCEPT_PATCH: "accept-patch",
|
|
1313
|
-
/**
|
|
1314
|
-
* What partial content range types this server supports via byte serving
|
|
1315
|
-
*
|
|
1316
|
-
* @example
|
|
1317
|
-
* accept-ranges: bytes
|
|
1318
|
-
* Permanent
|
|
1319
|
-
*/
|
|
1320
|
-
ACCEPT_RANGES: "accept-ranges",
|
|
1321
|
-
/**
|
|
1322
|
-
* The age the object has been in a proxy cache in seconds
|
|
1323
|
-
*
|
|
1324
|
-
* @example
|
|
1325
|
-
* age: 12
|
|
1326
|
-
* Permanent
|
|
1327
|
-
*/
|
|
1328
|
-
AGE: "age",
|
|
1329
|
-
/**
|
|
1330
|
-
* Valid actions for a specified resource. To be used for a 405 Method not allowed
|
|
1331
|
-
*
|
|
1332
|
-
* @example
|
|
1333
|
-
* allow: GET, HEAD
|
|
1334
|
-
* Permanent
|
|
1335
|
-
*/
|
|
1336
|
-
ALLOW: "allow",
|
|
1337
|
-
/**
|
|
1338
|
-
* Tells all caching mechanisms from server to client whether they may cache this object. It is measured in seconds
|
|
1339
|
-
*
|
|
1340
|
-
* @example
|
|
1341
|
-
* cache-control: max-age=3600
|
|
1342
|
-
* Permanent
|
|
1343
|
-
*/
|
|
1344
|
-
CACHE_CONTROL: "cache-control",
|
|
1345
|
-
/**
|
|
1346
|
-
* Control options for the current connection and list of hop-by-hop response fields
|
|
1347
|
-
*
|
|
1348
|
-
* @example
|
|
1349
|
-
* connection: close
|
|
1350
|
-
* Permanent
|
|
1351
|
-
*/
|
|
1352
|
-
CONNECTION: "connection",
|
|
1353
|
-
/**
|
|
1354
|
-
* An opportunity to raise a "File Download" dialogue box for a known MIME type with binary format or suggest a filename for dynamic content. Quotes are necessary with special characters.
|
|
1355
|
-
*
|
|
1356
|
-
* @example
|
|
1357
|
-
* content-disposition: attachment, filename="fname.ext"
|
|
1358
|
-
* Permanent
|
|
1359
|
-
*/
|
|
1360
|
-
CONTENT_DISPOSITION: "content-disposition",
|
|
1361
|
-
/**
|
|
1362
|
-
* The type of encoding used on the data. See HTTP compression.
|
|
1363
|
-
*
|
|
1364
|
-
* @example
|
|
1365
|
-
* content-encoding: gzip
|
|
1366
|
-
* Permanent
|
|
1367
|
-
*/
|
|
1368
|
-
CONTENT_ENCODING: "content-encoding",
|
|
1369
|
-
/**
|
|
1370
|
-
* The natural language or languages of the intended audience for the enclosed content
|
|
1371
|
-
*
|
|
1372
|
-
* @example
|
|
1373
|
-
* content-language: da
|
|
1374
|
-
* Permanent
|
|
1375
|
-
*/
|
|
1376
|
-
CONTENT_LANGUAGE: "content-language",
|
|
1377
|
-
/**
|
|
1378
|
-
* The length of the response body in octets (8-bit bytes)
|
|
1379
|
-
*
|
|
1380
|
-
* @example
|
|
1381
|
-
* content-length: 348
|
|
1382
|
-
* Permanent
|
|
1383
|
-
*/
|
|
1384
|
-
CONTENT_LENGTH: "content-length",
|
|
1385
|
-
/**
|
|
1386
|
-
* An alternate location for the returned data
|
|
1387
|
-
*
|
|
1388
|
-
* @example
|
|
1389
|
-
* content-location: /index.htm
|
|
1390
|
-
* Permanent
|
|
1391
|
-
*/
|
|
1392
|
-
CONTENT_LOCATION: "content-location",
|
|
1393
|
-
/**
|
|
1394
|
-
* Where in a full body message this partial message belongs
|
|
1395
|
-
*
|
|
1396
|
-
* @example
|
|
1397
|
-
* content-range: bytes 21010-47021/47022
|
|
1398
|
-
* Permanent
|
|
1399
|
-
*/
|
|
1400
|
-
CONTENT_RANGE: "content-range",
|
|
1401
|
-
/**
|
|
1402
|
-
* The MIME type of this content
|
|
1403
|
-
*
|
|
1404
|
-
* @example
|
|
1405
|
-
* content-type: text/html, charset=utf-8
|
|
1406
|
-
* Permanent
|
|
1407
|
-
*/
|
|
1408
|
-
CONTENT_TYPE: "content-type",
|
|
1409
|
-
/**
|
|
1410
|
-
* The date and time that the message was sent (in "HTTP-date" format as defined by RFC 7231)
|
|
1411
|
-
*
|
|
1412
|
-
* @example
|
|
1413
|
-
* date: Tue, 15 Nov 1994 08:12:31 GMT
|
|
1414
|
-
* Permanent
|
|
1415
|
-
*/
|
|
1416
|
-
DATE: "date",
|
|
1417
|
-
/**
|
|
1418
|
-
* An identifier for a specific version of a resource, often a message digest
|
|
1419
|
-
*
|
|
1420
|
-
* @example
|
|
1421
|
-
* etag: "737060cd8c284d8af7ad3082f209582d"
|
|
1422
|
-
* Permanent
|
|
1423
|
-
*/
|
|
1424
|
-
ETAG: "etag",
|
|
1425
|
-
/**
|
|
1426
|
-
* Gives the date/time after which the response is considered stale (in "HTTP-date" format as defined by RFC 7231)
|
|
1427
|
-
*
|
|
1428
|
-
* @example
|
|
1429
|
-
* expires: Thu, 01 Dec 1994 16:00:00 GMT
|
|
1430
|
-
* Permanent
|
|
1431
|
-
*/
|
|
1432
|
-
EXPIRES: "expires",
|
|
1433
|
-
/**
|
|
1434
|
-
* The last modified date for the requested object (in "HTTP-date" format as defined by RFC 7231)
|
|
1435
|
-
*
|
|
1436
|
-
* @example
|
|
1437
|
-
* last-modified: Tue, 15 Nov 1994 12:45:26 GMT
|
|
1438
|
-
* Permanent
|
|
1439
|
-
*/
|
|
1440
|
-
LAST_MODIFIED: "last-modified",
|
|
1441
|
-
/**
|
|
1442
|
-
* Used to express a typed relationship with another resource, where the relation type is defined by RFC 5988
|
|
1443
|
-
*
|
|
1444
|
-
* @example
|
|
1445
|
-
* link: </feed>, rel="alternate"
|
|
1446
|
-
* Permanent
|
|
1447
|
-
*/
|
|
1448
|
-
LINK: "link",
|
|
1449
|
-
/**
|
|
1450
|
-
* Used in redirection, or when a new resource has been created.
|
|
1451
|
-
*
|
|
1452
|
-
* @example
|
|
1453
|
-
* location: http://www.w3.org/pub/WWW/People.html
|
|
1454
|
-
* Permanent
|
|
1455
|
-
*/
|
|
1456
|
-
LOCATION: "location",
|
|
1457
|
-
/**
|
|
1458
|
-
* This field is supposed to set P3P policy, in the form of P3P:CP="your_compact_policy". However, P3P did not take off, most browsers have never fully
|
|
1459
|
-
* implemented it, a lot of websites set this field with fake policy text, that was enough to fool browsers the existence of P3P policy and grant permissions for third party cookies.
|
|
1460
|
-
*
|
|
1461
|
-
* @example
|
|
1462
|
-
* p3p: CP="This is not a P3P policy! See http://www.google.com/support/accounts/bin/answer.py?hl=en&answer=151657 for more info."
|
|
1463
|
-
* Permanent
|
|
1464
|
-
*/
|
|
1465
|
-
P3P: "p3p",
|
|
1466
|
-
/**
|
|
1467
|
-
* Implementation-specific fields that may have various effects anywhere along the request-response chain.
|
|
1468
|
-
*
|
|
1469
|
-
* @example
|
|
1470
|
-
* pragma: no-cache
|
|
1471
|
-
* Permanent
|
|
1472
|
-
*/
|
|
1473
|
-
PRAGMA: "pragma",
|
|
1474
|
-
/**
|
|
1475
|
-
* Request authentication to access the proxy.
|
|
1476
|
-
*
|
|
1477
|
-
* @example
|
|
1478
|
-
* proxy-authenticate: Basic
|
|
1479
|
-
* Permanent
|
|
1480
|
-
*/
|
|
1481
|
-
PROXY_AUTHENTICATION: "proxy-authenticate",
|
|
1482
|
-
/**
|
|
1483
|
-
* HTTP Public Key Pinning, announces hash of website's authentic TLS certificate
|
|
1484
|
-
*
|
|
1485
|
-
* @example
|
|
1486
|
-
* public-key-pins: max-age=2592000, pin-sha256="E9CZ9INDbd+2eRQozYqqbQ2yXLVKB9+xcprMF+44U1g=",
|
|
1487
|
-
* Permanent
|
|
1488
|
-
*/
|
|
1489
|
-
PUBLIC_KEY_PINS: "public-key-pins",
|
|
1490
|
-
/**
|
|
1491
|
-
* If an entity is temporarily unavailable, this instructs the client to try again later. Value could be a specified period of time (in seconds) or a HTTP-date.
|
|
1492
|
-
*
|
|
1493
|
-
* @example
|
|
1494
|
-
* retry-after: 120
|
|
1495
|
-
* retry-after: Fri, 07 Nov 2014 23:59:59 GMT
|
|
1496
|
-
* Permanent
|
|
1497
|
-
*/
|
|
1498
|
-
RETRY_AFTER: "retry-after",
|
|
1499
|
-
/**
|
|
1500
|
-
* A name for the server
|
|
1501
|
-
*
|
|
1502
|
-
* @example
|
|
1503
|
-
* server: Apache/2.4.1 (Unix)
|
|
1504
|
-
* Permanent
|
|
1505
|
-
*/
|
|
1506
|
-
SERVER: "server",
|
|
1507
|
-
/**
|
|
1508
|
-
* An HTTP cookie
|
|
1509
|
-
*
|
|
1510
|
-
* @example
|
|
1511
|
-
* set-cookie: UserID=JohnDoe, Max-Age=3600, Version=1
|
|
1512
|
-
* Permanent
|
|
1513
|
-
*/
|
|
1514
|
-
SET_COOKIE: "set-cookie",
|
|
1515
|
-
/**
|
|
1516
|
-
* CGI header field specifying the status of the HTTP response. Normal HTTP responses use a separate "Status-Line" instead, defined by RFC 7230.
|
|
1517
|
-
*
|
|
1518
|
-
* @example
|
|
1519
|
-
* status: 200 OK
|
|
1520
|
-
*/
|
|
1521
|
-
STATUS: "status",
|
|
1522
|
-
/**
|
|
1523
|
-
* A HSTS Policy informing the HTTP client how long to cache the HTTPS only policy and whether this applies to subdomains.
|
|
1524
|
-
*
|
|
1525
|
-
* @example
|
|
1526
|
-
* strict-transport-security: max-age=16070400, includeSubDomains
|
|
1527
|
-
* Permanent
|
|
1528
|
-
*/
|
|
1529
|
-
STRICT_TRANSPORT_SECURITY: "strict-transport-security",
|
|
1530
|
-
/**
|
|
1531
|
-
* The Trailer general field value indicates that the given set of header fields is present in the trailer of a message encoded with chunked transfer coding.
|
|
1532
|
-
*
|
|
1533
|
-
* @example
|
|
1534
|
-
* trailer: Max-Forwards
|
|
1535
|
-
* Permanent
|
|
1536
|
-
*/
|
|
1537
|
-
TRAILER: "trailer",
|
|
1538
|
-
/**
|
|
1539
|
-
* The form of encoding used to safely transfer the entity to the user. Currently defined methods are: chunked, compress, deflate, gzip, identity.
|
|
1540
|
-
*
|
|
1541
|
-
* @example
|
|
1542
|
-
* transfer-encoding: chunked
|
|
1543
|
-
* Permanent
|
|
1544
|
-
*/
|
|
1545
|
-
TRANSFER_ENCODING: "transfer-encoding",
|
|
1546
|
-
/**
|
|
1547
|
-
* Ask the client to upgrade to another protocol.
|
|
1548
|
-
*
|
|
1549
|
-
* @example
|
|
1550
|
-
* upgrade: HTTP/2.0, SHTTP/1.3, IRC/6.9, RTA/x11
|
|
1551
|
-
* Permanent
|
|
1552
|
-
*/
|
|
1553
|
-
UPGRADE: "upgrade",
|
|
1554
|
-
/**
|
|
1555
|
-
* Tells downstream proxies how to match future request headers to decide whether the cached response can be used rather than requesting a fresh one from the origin server.
|
|
1556
|
-
*
|
|
1557
|
-
* @example
|
|
1558
|
-
* vary: *
|
|
1559
|
-
* Permanent
|
|
1560
|
-
*/
|
|
1561
|
-
VARY: "vary",
|
|
1562
|
-
/**
|
|
1563
|
-
* Informs the client of proxies through which the response was sent.
|
|
1564
|
-
*
|
|
1565
|
-
* @example
|
|
1566
|
-
* via: 1.0 fred, 1.1 example.com (Apache/1.1)
|
|
1567
|
-
* Permanent
|
|
1568
|
-
*/
|
|
1569
|
-
VIA: "via",
|
|
1570
|
-
/**
|
|
1571
|
-
* A general warning about possible problems with the entity body.
|
|
1572
|
-
*
|
|
1573
|
-
* @example
|
|
1574
|
-
* warning: 199 Miscellaneous warning
|
|
1575
|
-
* Permanent
|
|
1576
|
-
*/
|
|
1577
|
-
WARNING: "warning",
|
|
1578
|
-
/**
|
|
1579
|
-
* Indicates the authentication scheme that should be used to access the requested entity.
|
|
1580
|
-
*
|
|
1581
|
-
* @example
|
|
1582
|
-
* www-authenticate: Basic
|
|
1583
|
-
* Permanent
|
|
1584
|
-
*/
|
|
1585
|
-
WWW_AUTHENTICATE: "www-authenticate",
|
|
1586
|
-
/**
|
|
1587
|
-
* Cross-site scripting (XSS) filter
|
|
1588
|
-
*
|
|
1589
|
-
* @example
|
|
1590
|
-
* x-xss-protection: 1, mode=block
|
|
1591
|
-
*/
|
|
1592
|
-
X_XSS_PROTECTION: "x-xss-protection",
|
|
1593
|
-
/**
|
|
1594
|
-
* The HTTP Content-Security-Policy response header allows web site administrators to control resources the user agent is allowed
|
|
1595
|
-
* to load for a given page. With a few exceptions, policies mostly involve specifying server origins and script endpoints.
|
|
1596
|
-
* This helps guard against cross-site scripting attacks (Cross-site_scripting).
|
|
1597
|
-
*
|
|
1598
|
-
* @example
|
|
1599
|
-
* content-security-policy: default-src
|
|
1600
|
-
*/
|
|
1601
|
-
CONTENT_SECURITY_POLICY: "content-security-policy",
|
|
1602
|
-
/**
|
|
1603
|
-
* The only defined value, "nosniff", prevents Internet Explorer from MIME-sniffing a response away from the declared content-type. This also applies to Google Chrome, when downloading extensions.
|
|
1604
|
-
*
|
|
1605
|
-
* @example
|
|
1606
|
-
* x-content-type-options: nosniff
|
|
1607
|
-
*/
|
|
1608
|
-
X_CONTENT_TYPE_OPTIONS: "x-content-type-options",
|
|
1609
|
-
/**
|
|
1610
|
-
* specifies the technology (e.g. ASP.NET, PHP, JBoss) supporting the web application (version details are often in X-Runtime, X-Version, or X-AspNet-Version)
|
|
1611
|
-
*
|
|
1612
|
-
* @example
|
|
1613
|
-
* x-powered-by: PHP/5.4.0
|
|
1614
|
-
*/
|
|
1615
|
-
X_POWERED_BY: "x-powered-by"
|
|
1616
|
-
};
|
|
1617
|
-
|
|
1618
|
-
// src/response-status.ts
|
|
1619
|
-
var ResponseStatus = class {
|
|
1620
|
-
_code;
|
|
1621
|
-
_text;
|
|
1622
|
-
/**
|
|
1623
|
-
*
|
|
1624
|
-
* @param code The status code from the {@link Response}
|
|
1625
|
-
* @param text The status text from the {@link Response}
|
|
1626
|
-
*/
|
|
1627
|
-
constructor(code, text2) {
|
|
1628
|
-
this._code = code;
|
|
1629
|
-
this._text = text2;
|
|
1630
|
-
}
|
|
1631
|
-
/**
|
|
1632
|
-
* Returns the status code from the {@link Response}
|
|
1633
|
-
*
|
|
1634
|
-
* @returns The status code.
|
|
1635
|
-
*/
|
|
1636
|
-
get code() {
|
|
1637
|
-
return this._code;
|
|
1638
|
-
}
|
|
1639
|
-
/**
|
|
1640
|
-
* Returns the status text from the {@link Response}.
|
|
1641
|
-
*
|
|
1642
|
-
* @returns The status text.
|
|
1643
|
-
*/
|
|
1644
|
-
get text() {
|
|
1645
|
-
return this._text;
|
|
1646
|
-
}
|
|
1647
|
-
/**
|
|
1648
|
-
* A String value that is used in the creation of the default string
|
|
1649
|
-
* description of an object. Called by the built-in method {@link Object.prototype.toString}.
|
|
1650
|
-
*
|
|
1651
|
-
* @returns The default string description of this object.
|
|
1652
|
-
*/
|
|
1653
|
-
get [Symbol.toStringTag]() {
|
|
1654
|
-
return "ResponseStatus";
|
|
1655
|
-
}
|
|
1656
|
-
/**
|
|
1657
|
-
* tostring method for the class.
|
|
1658
|
-
*
|
|
1659
|
-
* @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/toString|Object.prototype.toString}
|
|
1660
|
-
* @returns The status code and status text.
|
|
1661
|
-
*/
|
|
1662
|
-
toString() {
|
|
1663
|
-
return `${this._code} ${this._text}`;
|
|
1664
|
-
}
|
|
1665
|
-
};
|
|
1666
|
-
|
|
1667
|
-
// src/constants.ts
|
|
1668
|
-
var charset = { charset: "utf-8" };
|
|
1669
|
-
var endsWithSlashRegEx = /\/$/;
|
|
1670
|
-
var XSRF_COOKIE_NAME = "XSRF-TOKEN";
|
|
1671
|
-
var XSRF_HEADER_NAME = "X-XSRF-TOKEN";
|
|
1672
|
-
var mediaTypes = {
|
|
1673
|
-
PNG: new MediaType(HttpMediaType.PNG),
|
|
1674
|
-
TEXT: new MediaType(HttpMediaType.TEXT, charset),
|
|
1675
|
-
JSON: new MediaType(HttpMediaType.JSON, charset),
|
|
1676
|
-
HTML: new MediaType(HttpMediaType.HTML, charset),
|
|
1677
|
-
JAVA_SCRIPT: new MediaType(HttpMediaType.JAVA_SCRIPT, charset),
|
|
1678
|
-
CSS: new MediaType(HttpMediaType.CSS, charset),
|
|
1679
|
-
XML: new MediaType(HttpMediaType.XML, charset),
|
|
1680
|
-
BIN: new MediaType(HttpMediaType.BIN)
|
|
1681
|
-
};
|
|
1682
|
-
var defaultMediaType = mediaTypes.JSON.toString();
|
|
1683
|
-
var RequestCachingPolicy = {
|
|
1684
|
-
DEFAULT: "default",
|
|
1685
|
-
FORCE_CACHE: "force-cache",
|
|
1686
|
-
NO_CACHE: "no-cache",
|
|
1687
|
-
NO_STORE: "no-store",
|
|
1688
|
-
ONLY_IF_CACHED: "only-if-cached",
|
|
1689
|
-
RELOAD: "reload"
|
|
1690
|
-
};
|
|
1691
|
-
var RequestEvent = {
|
|
1692
|
-
CONFIGURED: "configured",
|
|
1693
|
-
SUCCESS: "success",
|
|
1694
|
-
ERROR: "error",
|
|
1695
|
-
ABORTED: "aborted",
|
|
1696
|
-
TIMEOUT: "timeout",
|
|
1697
|
-
RETRY: "retry",
|
|
1698
|
-
COMPLETE: "complete",
|
|
1699
|
-
ALL_COMPLETE: "all-complete"
|
|
1700
|
-
};
|
|
1701
|
-
var SignalEvents = {
|
|
1702
|
-
ABORT: "abort",
|
|
1703
|
-
TIMEOUT: "timeout"
|
|
1704
|
-
};
|
|
1705
|
-
var SignalErrors = {
|
|
1706
|
-
ABORT: "AbortError",
|
|
1707
|
-
TIMEOUT: "TimeoutError"
|
|
1708
|
-
};
|
|
1709
|
-
var eventListenerOptions = { once: true, passive: true };
|
|
1710
|
-
var abortEvent = () => new CustomEvent(SignalEvents.ABORT, { detail: { cause: SignalErrors.ABORT } });
|
|
1711
|
-
var timeoutEvent = () => new CustomEvent(SignalEvents.TIMEOUT, { detail: { cause: SignalErrors.TIMEOUT } });
|
|
1712
|
-
var requestBodyMethods = [HttpRequestMethod.POST, HttpRequestMethod.PUT, HttpRequestMethod.PATCH, HttpRequestMethod.DELETE];
|
|
1713
|
-
var internalServerError = new ResponseStatus(500, "Internal Server Error");
|
|
1714
|
-
var aborted = new ResponseStatus(499, "Aborted");
|
|
1715
|
-
var timedOut = new ResponseStatus(504, "Request Timeout");
|
|
1716
|
-
var retryStatusCodes = [408, 413, 429, 500, 502, 503, 504];
|
|
1717
|
-
var retryMethods = [HttpRequestMethod.GET, HttpRequestMethod.PUT, HttpRequestMethod.HEAD, HttpRequestMethod.DELETE, HttpRequestMethod.OPTIONS];
|
|
1718
|
-
var retryDelay = 300;
|
|
1719
|
-
var retryBackoffFactor = 2;
|
|
1720
|
-
|
|
1721
|
-
// src/signal-controller.ts
|
|
1722
|
-
var SignalController = class {
|
|
1723
|
-
abortSignal;
|
|
1724
|
-
abortController = new AbortController();
|
|
1725
|
-
events = /* @__PURE__ */ new Map();
|
|
1726
|
-
/**
|
|
1727
|
-
* Creates a new SignalController instance.
|
|
1728
|
-
* @param options - The options for the SignalController.
|
|
1729
|
-
* @param options.signal - The signal to listen for abort events. Defaults to the internal abort signal.
|
|
1730
|
-
* @param options.timeout - The timeout value in milliseconds. Defaults to Infinity.
|
|
1731
|
-
* @throws {RangeError} If the timeout value is negative.
|
|
1732
|
-
*/
|
|
1733
|
-
constructor({ signal, timeout = Infinity } = {}) {
|
|
1734
|
-
if (timeout < 0) {
|
|
1735
|
-
throw new RangeError("The timeout cannot be negative");
|
|
1736
|
-
}
|
|
1737
|
-
const signals = [this.abortController.signal];
|
|
1738
|
-
if (signal != null) {
|
|
1739
|
-
signals.push(signal);
|
|
1740
|
-
}
|
|
1741
|
-
if (timeout !== Infinity) {
|
|
1742
|
-
signals.push(AbortSignal.timeout(timeout));
|
|
1743
|
-
}
|
|
1744
|
-
(this.abortSignal = AbortSignal.any(signals)).addEventListener(SignalEvents.ABORT, this, eventListenerOptions);
|
|
1745
|
-
}
|
|
1746
|
-
/**
|
|
1747
|
-
* Handles the 'abort' event. If the event is caused by a timeout, the 'timeout' event is dispatched.
|
|
1748
|
-
* Guards against a timeout firing after a manual abort to prevent spurious timeout events.
|
|
1749
|
-
* @param event The event to abort with
|
|
1750
|
-
* @see https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener#specifying_this_using_bind
|
|
1751
|
-
*/
|
|
1752
|
-
handleEvent({ target: { reason } }) {
|
|
1753
|
-
if (this.abortController.signal.aborted) {
|
|
1754
|
-
return;
|
|
1755
|
-
}
|
|
1756
|
-
if (reason instanceof DOMException && reason.name === SignalErrors.TIMEOUT) {
|
|
1757
|
-
this.abortSignal.dispatchEvent(timeoutEvent());
|
|
1758
|
-
}
|
|
1759
|
-
}
|
|
1760
|
-
/**
|
|
1761
|
-
* Gets the signal. This signal will be able to abort the request, but will not be notified if the request is aborted by the timeout.
|
|
1762
|
-
* @returns The signal
|
|
1763
|
-
*/
|
|
1764
|
-
get signal() {
|
|
1765
|
-
return this.abortSignal;
|
|
1766
|
-
}
|
|
1767
|
-
/**
|
|
1768
|
-
* Adds an event listener for the 'abort' event.
|
|
1769
|
-
*
|
|
1770
|
-
* @param eventListener The listener to add
|
|
1771
|
-
* @returns The SignalController
|
|
1772
|
-
*/
|
|
1773
|
-
onAbort(eventListener) {
|
|
1774
|
-
return this.addEventListener(SignalEvents.ABORT, eventListener);
|
|
1775
|
-
}
|
|
1776
|
-
/**
|
|
1777
|
-
* Adds an event listener for the 'timeout' event.
|
|
1778
|
-
*
|
|
1779
|
-
* @param eventListener The listener to add
|
|
1780
|
-
* @returns The SignalController
|
|
1781
|
-
*/
|
|
1782
|
-
onTimeout(eventListener) {
|
|
1783
|
-
return this.addEventListener(SignalEvents.TIMEOUT, eventListener);
|
|
1784
|
-
}
|
|
1785
|
-
/**
|
|
1786
|
-
* Aborts the signal.
|
|
1787
|
-
*
|
|
1788
|
-
* @param event The event to abort with
|
|
1789
|
-
*/
|
|
1790
|
-
abort(event = abortEvent()) {
|
|
1791
|
-
this.abortController.abort(event.detail?.cause);
|
|
1792
|
-
}
|
|
1793
|
-
/**
|
|
1794
|
-
* Removes all event listeners from the signal.
|
|
1795
|
-
*
|
|
1796
|
-
* @returns The SignalController
|
|
1797
|
-
*/
|
|
1798
|
-
destroy() {
|
|
1799
|
-
this.abortSignal.removeEventListener(SignalEvents.ABORT, this, eventListenerOptions);
|
|
1800
|
-
for (const [eventListener, type] of this.events) {
|
|
1801
|
-
this.abortSignal.removeEventListener(type, eventListener, eventListenerOptions);
|
|
1802
|
-
}
|
|
1803
|
-
this.events.clear();
|
|
1804
|
-
return this;
|
|
1805
|
-
}
|
|
1806
|
-
/**
|
|
1807
|
-
* Adds an event listener for the specified event type.
|
|
1808
|
-
*
|
|
1809
|
-
* @param type The event type to listen for
|
|
1810
|
-
* @param eventListener The listener to add
|
|
1811
|
-
* @returns The SignalController
|
|
1812
|
-
*/
|
|
1813
|
-
addEventListener(type, eventListener) {
|
|
1814
|
-
this.abortSignal.addEventListener(type, eventListener, eventListenerOptions);
|
|
1815
|
-
this.events.set(eventListener, type);
|
|
1816
|
-
return this;
|
|
1817
|
-
}
|
|
1818
|
-
/**
|
|
1819
|
-
* A String value that is used in the creation of the default string
|
|
1820
|
-
* description of an object. Called by the built-in method {@link Object.prototype.toString}.
|
|
1821
|
-
*
|
|
1822
|
-
* @returns The default string description of this object.
|
|
1823
|
-
*/
|
|
1824
|
-
get [Symbol.toStringTag]() {
|
|
1825
|
-
return "SignalController";
|
|
1826
|
-
}
|
|
1827
|
-
};
|
|
1828
|
-
|
|
1829
|
-
// node_modules/.pnpm/dompurify@3.3.3/node_modules/dompurify/dist/purify.es.mjs
|
|
1830
|
-
var {
|
|
1831
|
-
entries,
|
|
1832
|
-
setPrototypeOf,
|
|
1833
|
-
isFrozen,
|
|
1834
|
-
getPrototypeOf,
|
|
1835
|
-
getOwnPropertyDescriptor
|
|
1836
|
-
} = Object;
|
|
1837
|
-
var {
|
|
1838
|
-
freeze,
|
|
1839
|
-
seal,
|
|
1840
|
-
create
|
|
1841
|
-
} = Object;
|
|
1842
|
-
var {
|
|
1843
|
-
apply,
|
|
1844
|
-
construct
|
|
1845
|
-
} = typeof Reflect !== "undefined" && Reflect;
|
|
1846
|
-
if (!freeze) {
|
|
1847
|
-
freeze = function freeze2(x) {
|
|
1848
|
-
return x;
|
|
1849
|
-
};
|
|
1850
|
-
}
|
|
1851
|
-
if (!seal) {
|
|
1852
|
-
seal = function seal2(x) {
|
|
1853
|
-
return x;
|
|
1854
|
-
};
|
|
1855
|
-
}
|
|
1856
|
-
if (!apply) {
|
|
1857
|
-
apply = function apply2(func, thisArg) {
|
|
1858
|
-
for (var _len = arguments.length, args = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
|
|
1859
|
-
args[_key - 2] = arguments[_key];
|
|
1860
|
-
}
|
|
1861
|
-
return func.apply(thisArg, args);
|
|
1862
|
-
};
|
|
1863
|
-
}
|
|
1864
|
-
if (!construct) {
|
|
1865
|
-
construct = function construct2(Func) {
|
|
1866
|
-
for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
|
|
1867
|
-
args[_key2 - 1] = arguments[_key2];
|
|
1868
|
-
}
|
|
1869
|
-
return new Func(...args);
|
|
1870
|
-
};
|
|
1871
|
-
}
|
|
1872
|
-
var arrayForEach = unapply(Array.prototype.forEach);
|
|
1873
|
-
var arrayLastIndexOf = unapply(Array.prototype.lastIndexOf);
|
|
1874
|
-
var arrayPop = unapply(Array.prototype.pop);
|
|
1875
|
-
var arrayPush = unapply(Array.prototype.push);
|
|
1876
|
-
var arraySplice = unapply(Array.prototype.splice);
|
|
1877
|
-
var stringToLowerCase = unapply(String.prototype.toLowerCase);
|
|
1878
|
-
var stringToString = unapply(String.prototype.toString);
|
|
1879
|
-
var stringMatch = unapply(String.prototype.match);
|
|
1880
|
-
var stringReplace = unapply(String.prototype.replace);
|
|
1881
|
-
var stringIndexOf = unapply(String.prototype.indexOf);
|
|
1882
|
-
var stringTrim = unapply(String.prototype.trim);
|
|
1883
|
-
var objectHasOwnProperty = unapply(Object.prototype.hasOwnProperty);
|
|
1884
|
-
var regExpTest = unapply(RegExp.prototype.test);
|
|
1885
|
-
var typeErrorCreate = unconstruct(TypeError);
|
|
1886
|
-
function unapply(func) {
|
|
1887
|
-
return function(thisArg) {
|
|
1888
|
-
if (thisArg instanceof RegExp) {
|
|
1889
|
-
thisArg.lastIndex = 0;
|
|
1890
|
-
}
|
|
1891
|
-
for (var _len3 = arguments.length, args = new Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) {
|
|
1892
|
-
args[_key3 - 1] = arguments[_key3];
|
|
1893
|
-
}
|
|
1894
|
-
return apply(func, thisArg, args);
|
|
1895
|
-
};
|
|
1896
|
-
}
|
|
1897
|
-
function unconstruct(Func) {
|
|
1898
|
-
return function() {
|
|
1899
|
-
for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
|
|
1900
|
-
args[_key4] = arguments[_key4];
|
|
1901
|
-
}
|
|
1902
|
-
return construct(Func, args);
|
|
1903
|
-
};
|
|
1904
|
-
}
|
|
1905
|
-
function addToSet(set, array) {
|
|
1906
|
-
let transformCaseFunc = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : stringToLowerCase;
|
|
1907
|
-
if (setPrototypeOf) {
|
|
1908
|
-
setPrototypeOf(set, null);
|
|
1909
|
-
}
|
|
1910
|
-
let l = array.length;
|
|
1911
|
-
while (l--) {
|
|
1912
|
-
let element = array[l];
|
|
1913
|
-
if (typeof element === "string") {
|
|
1914
|
-
const lcElement = transformCaseFunc(element);
|
|
1915
|
-
if (lcElement !== element) {
|
|
1916
|
-
if (!isFrozen(array)) {
|
|
1917
|
-
array[l] = lcElement;
|
|
1918
|
-
}
|
|
1919
|
-
element = lcElement;
|
|
1920
|
-
}
|
|
1921
|
-
}
|
|
1922
|
-
set[element] = true;
|
|
1923
|
-
}
|
|
1924
|
-
return set;
|
|
1925
|
-
}
|
|
1926
|
-
function cleanArray(array) {
|
|
1927
|
-
for (let index = 0; index < array.length; index++) {
|
|
1928
|
-
const isPropertyExist = objectHasOwnProperty(array, index);
|
|
1929
|
-
if (!isPropertyExist) {
|
|
1930
|
-
array[index] = null;
|
|
1931
|
-
}
|
|
1932
|
-
}
|
|
1933
|
-
return array;
|
|
1934
|
-
}
|
|
1935
|
-
function clone(object) {
|
|
1936
|
-
const newObject = create(null);
|
|
1937
|
-
for (const [property, value] of entries(object)) {
|
|
1938
|
-
const isPropertyExist = objectHasOwnProperty(object, property);
|
|
1939
|
-
if (isPropertyExist) {
|
|
1940
|
-
if (Array.isArray(value)) {
|
|
1941
|
-
newObject[property] = cleanArray(value);
|
|
1942
|
-
} else if (value && typeof value === "object" && value.constructor === Object) {
|
|
1943
|
-
newObject[property] = clone(value);
|
|
1944
|
-
} else {
|
|
1945
|
-
newObject[property] = value;
|
|
1946
|
-
}
|
|
1947
|
-
}
|
|
1948
|
-
}
|
|
1949
|
-
return newObject;
|
|
1950
|
-
}
|
|
1951
|
-
function lookupGetter(object, prop) {
|
|
1952
|
-
while (object !== null) {
|
|
1953
|
-
const desc = getOwnPropertyDescriptor(object, prop);
|
|
1954
|
-
if (desc) {
|
|
1955
|
-
if (desc.get) {
|
|
1956
|
-
return unapply(desc.get);
|
|
1957
|
-
}
|
|
1958
|
-
if (typeof desc.value === "function") {
|
|
1959
|
-
return unapply(desc.value);
|
|
1960
|
-
}
|
|
1961
|
-
}
|
|
1962
|
-
object = getPrototypeOf(object);
|
|
1963
|
-
}
|
|
1964
|
-
function fallbackValue() {
|
|
1965
|
-
return null;
|
|
1966
|
-
}
|
|
1967
|
-
return fallbackValue;
|
|
1968
|
-
}
|
|
1969
|
-
var html$1 = freeze(["a", "abbr", "acronym", "address", "area", "article", "aside", "audio", "b", "bdi", "bdo", "big", "blink", "blockquote", "body", "br", "button", "canvas", "caption", "center", "cite", "code", "col", "colgroup", "content", "data", "datalist", "dd", "decorator", "del", "details", "dfn", "dialog", "dir", "div", "dl", "dt", "element", "em", "fieldset", "figcaption", "figure", "font", "footer", "form", "h1", "h2", "h3", "h4", "h5", "h6", "head", "header", "hgroup", "hr", "html", "i", "img", "input", "ins", "kbd", "label", "legend", "li", "main", "map", "mark", "marquee", "menu", "menuitem", "meter", "nav", "nobr", "ol", "optgroup", "option", "output", "p", "picture", "pre", "progress", "q", "rp", "rt", "ruby", "s", "samp", "search", "section", "select", "shadow", "slot", "small", "source", "spacer", "span", "strike", "strong", "style", "sub", "summary", "sup", "table", "tbody", "td", "template", "textarea", "tfoot", "th", "thead", "time", "tr", "track", "tt", "u", "ul", "var", "video", "wbr"]);
|
|
1970
|
-
var svg$1 = freeze(["svg", "a", "altglyph", "altglyphdef", "altglyphitem", "animatecolor", "animatemotion", "animatetransform", "circle", "clippath", "defs", "desc", "ellipse", "enterkeyhint", "exportparts", "filter", "font", "g", "glyph", "glyphref", "hkern", "image", "inputmode", "line", "lineargradient", "marker", "mask", "metadata", "mpath", "part", "path", "pattern", "polygon", "polyline", "radialgradient", "rect", "stop", "style", "switch", "symbol", "text", "textpath", "title", "tref", "tspan", "view", "vkern"]);
|
|
1971
|
-
var svgFilters = freeze(["feBlend", "feColorMatrix", "feComponentTransfer", "feComposite", "feConvolveMatrix", "feDiffuseLighting", "feDisplacementMap", "feDistantLight", "feDropShadow", "feFlood", "feFuncA", "feFuncB", "feFuncG", "feFuncR", "feGaussianBlur", "feImage", "feMerge", "feMergeNode", "feMorphology", "feOffset", "fePointLight", "feSpecularLighting", "feSpotLight", "feTile", "feTurbulence"]);
|
|
1972
|
-
var svgDisallowed = freeze(["animate", "color-profile", "cursor", "discard", "font-face", "font-face-format", "font-face-name", "font-face-src", "font-face-uri", "foreignobject", "hatch", "hatchpath", "mesh", "meshgradient", "meshpatch", "meshrow", "missing-glyph", "script", "set", "solidcolor", "unknown", "use"]);
|
|
1973
|
-
var mathMl$1 = freeze(["math", "menclose", "merror", "mfenced", "mfrac", "mglyph", "mi", "mlabeledtr", "mmultiscripts", "mn", "mo", "mover", "mpadded", "mphantom", "mroot", "mrow", "ms", "mspace", "msqrt", "mstyle", "msub", "msup", "msubsup", "mtable", "mtd", "mtext", "mtr", "munder", "munderover", "mprescripts"]);
|
|
1974
|
-
var mathMlDisallowed = freeze(["maction", "maligngroup", "malignmark", "mlongdiv", "mscarries", "mscarry", "msgroup", "mstack", "msline", "msrow", "semantics", "annotation", "annotation-xml", "mprescripts", "none"]);
|
|
1975
|
-
var text = freeze(["#text"]);
|
|
1976
|
-
var html = freeze(["accept", "action", "align", "alt", "autocapitalize", "autocomplete", "autopictureinpicture", "autoplay", "background", "bgcolor", "border", "capture", "cellpadding", "cellspacing", "checked", "cite", "class", "clear", "color", "cols", "colspan", "controls", "controlslist", "coords", "crossorigin", "datetime", "decoding", "default", "dir", "disabled", "disablepictureinpicture", "disableremoteplayback", "download", "draggable", "enctype", "enterkeyhint", "exportparts", "face", "for", "headers", "height", "hidden", "high", "href", "hreflang", "id", "inert", "inputmode", "integrity", "ismap", "kind", "label", "lang", "list", "loading", "loop", "low", "max", "maxlength", "media", "method", "min", "minlength", "multiple", "muted", "name", "nonce", "noshade", "novalidate", "nowrap", "open", "optimum", "part", "pattern", "placeholder", "playsinline", "popover", "popovertarget", "popovertargetaction", "poster", "preload", "pubdate", "radiogroup", "readonly", "rel", "required", "rev", "reversed", "role", "rows", "rowspan", "spellcheck", "scope", "selected", "shape", "size", "sizes", "slot", "span", "srclang", "start", "src", "srcset", "step", "style", "summary", "tabindex", "title", "translate", "type", "usemap", "valign", "value", "width", "wrap", "xmlns", "slot"]);
|
|
1977
|
-
var svg = freeze(["accent-height", "accumulate", "additive", "alignment-baseline", "amplitude", "ascent", "attributename", "attributetype", "azimuth", "basefrequency", "baseline-shift", "begin", "bias", "by", "class", "clip", "clippathunits", "clip-path", "clip-rule", "color", "color-interpolation", "color-interpolation-filters", "color-profile", "color-rendering", "cx", "cy", "d", "dx", "dy", "diffuseconstant", "direction", "display", "divisor", "dur", "edgemode", "elevation", "end", "exponent", "fill", "fill-opacity", "fill-rule", "filter", "filterunits", "flood-color", "flood-opacity", "font-family", "font-size", "font-size-adjust", "font-stretch", "font-style", "font-variant", "font-weight", "fx", "fy", "g1", "g2", "glyph-name", "glyphref", "gradientunits", "gradienttransform", "height", "href", "id", "image-rendering", "in", "in2", "intercept", "k", "k1", "k2", "k3", "k4", "kerning", "keypoints", "keysplines", "keytimes", "lang", "lengthadjust", "letter-spacing", "kernelmatrix", "kernelunitlength", "lighting-color", "local", "marker-end", "marker-mid", "marker-start", "markerheight", "markerunits", "markerwidth", "maskcontentunits", "maskunits", "max", "mask", "mask-type", "media", "method", "mode", "min", "name", "numoctaves", "offset", "operator", "opacity", "order", "orient", "orientation", "origin", "overflow", "paint-order", "path", "pathlength", "patterncontentunits", "patterntransform", "patternunits", "points", "preservealpha", "preserveaspectratio", "primitiveunits", "r", "rx", "ry", "radius", "refx", "refy", "repeatcount", "repeatdur", "restart", "result", "rotate", "scale", "seed", "shape-rendering", "slope", "specularconstant", "specularexponent", "spreadmethod", "startoffset", "stddeviation", "stitchtiles", "stop-color", "stop-opacity", "stroke-dasharray", "stroke-dashoffset", "stroke-linecap", "stroke-linejoin", "stroke-miterlimit", "stroke-opacity", "stroke", "stroke-width", "style", "surfacescale", "systemlanguage", "tabindex", "tablevalues", "targetx", "targety", "transform", "transform-origin", "text-anchor", "text-decoration", "text-rendering", "textlength", "type", "u1", "u2", "unicode", "values", "viewbox", "visibility", "version", "vert-adv-y", "vert-origin-x", "vert-origin-y", "width", "word-spacing", "wrap", "writing-mode", "xchannelselector", "ychannelselector", "x", "x1", "x2", "xmlns", "y", "y1", "y2", "z", "zoomandpan"]);
|
|
1978
|
-
var mathMl = freeze(["accent", "accentunder", "align", "bevelled", "close", "columnsalign", "columnlines", "columnspan", "denomalign", "depth", "dir", "display", "displaystyle", "encoding", "fence", "frame", "height", "href", "id", "largeop", "length", "linethickness", "lspace", "lquote", "mathbackground", "mathcolor", "mathsize", "mathvariant", "maxsize", "minsize", "movablelimits", "notation", "numalign", "open", "rowalign", "rowlines", "rowspacing", "rowspan", "rspace", "rquote", "scriptlevel", "scriptminsize", "scriptsizemultiplier", "selection", "separator", "separators", "stretchy", "subscriptshift", "supscriptshift", "symmetric", "voffset", "width", "xmlns"]);
|
|
1979
|
-
var xml = freeze(["xlink:href", "xml:id", "xlink:title", "xml:space", "xmlns:xlink"]);
|
|
1980
|
-
var MUSTACHE_EXPR = seal(/\{\{[\w\W]*|[\w\W]*\}\}/gm);
|
|
1981
|
-
var ERB_EXPR = seal(/<%[\w\W]*|[\w\W]*%>/gm);
|
|
1982
|
-
var TMPLIT_EXPR = seal(/\$\{[\w\W]*/gm);
|
|
1983
|
-
var DATA_ATTR = seal(/^data-[\-\w.\u00B7-\uFFFF]+$/);
|
|
1984
|
-
var ARIA_ATTR = seal(/^aria-[\-\w]+$/);
|
|
1985
|
-
var IS_ALLOWED_URI = seal(
|
|
1986
|
-
/^(?:(?:(?:f|ht)tps?|mailto|tel|callto|sms|cid|xmpp|matrix):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i
|
|
1987
|
-
// eslint-disable-line no-useless-escape
|
|
1988
|
-
);
|
|
1989
|
-
var IS_SCRIPT_OR_DATA = seal(/^(?:\w+script|data):/i);
|
|
1990
|
-
var ATTR_WHITESPACE = seal(
|
|
1991
|
-
/[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205F\u3000]/g
|
|
1992
|
-
// eslint-disable-line no-control-regex
|
|
1993
|
-
);
|
|
1994
|
-
var DOCTYPE_NAME = seal(/^html$/i);
|
|
1995
|
-
var CUSTOM_ELEMENT = seal(/^[a-z][.\w]*(-[.\w]+)+$/i);
|
|
1996
|
-
var EXPRESSIONS = /* @__PURE__ */ Object.freeze({
|
|
1997
|
-
__proto__: null,
|
|
1998
|
-
ARIA_ATTR,
|
|
1999
|
-
ATTR_WHITESPACE,
|
|
2000
|
-
CUSTOM_ELEMENT,
|
|
2001
|
-
DATA_ATTR,
|
|
2002
|
-
DOCTYPE_NAME,
|
|
2003
|
-
ERB_EXPR,
|
|
2004
|
-
IS_ALLOWED_URI,
|
|
2005
|
-
IS_SCRIPT_OR_DATA,
|
|
2006
|
-
MUSTACHE_EXPR,
|
|
2007
|
-
TMPLIT_EXPR
|
|
2008
|
-
});
|
|
2009
|
-
var NODE_TYPE = {
|
|
2010
|
-
element: 1,
|
|
2011
|
-
attribute: 2,
|
|
2012
|
-
text: 3,
|
|
2013
|
-
cdataSection: 4,
|
|
2014
|
-
entityReference: 5,
|
|
2015
|
-
// Deprecated
|
|
2016
|
-
entityNode: 6,
|
|
2017
|
-
// Deprecated
|
|
2018
|
-
progressingInstruction: 7,
|
|
2019
|
-
comment: 8,
|
|
2020
|
-
document: 9,
|
|
2021
|
-
documentType: 10,
|
|
2022
|
-
documentFragment: 11,
|
|
2023
|
-
notation: 12
|
|
2024
|
-
// Deprecated
|
|
2025
|
-
};
|
|
2026
|
-
var getGlobal = function getGlobal2() {
|
|
2027
|
-
return typeof window === "undefined" ? null : window;
|
|
2028
|
-
};
|
|
2029
|
-
var _createTrustedTypesPolicy = function _createTrustedTypesPolicy2(trustedTypes, purifyHostElement) {
|
|
2030
|
-
if (typeof trustedTypes !== "object" || typeof trustedTypes.createPolicy !== "function") {
|
|
2031
|
-
return null;
|
|
2032
|
-
}
|
|
2033
|
-
let suffix = null;
|
|
2034
|
-
const ATTR_NAME = "data-tt-policy-suffix";
|
|
2035
|
-
if (purifyHostElement && purifyHostElement.hasAttribute(ATTR_NAME)) {
|
|
2036
|
-
suffix = purifyHostElement.getAttribute(ATTR_NAME);
|
|
2037
|
-
}
|
|
2038
|
-
const policyName = "dompurify" + (suffix ? "#" + suffix : "");
|
|
2039
|
-
try {
|
|
2040
|
-
return trustedTypes.createPolicy(policyName, {
|
|
2041
|
-
createHTML(html2) {
|
|
2042
|
-
return html2;
|
|
2043
|
-
},
|
|
2044
|
-
createScriptURL(scriptUrl) {
|
|
2045
|
-
return scriptUrl;
|
|
2046
|
-
}
|
|
2047
|
-
});
|
|
2048
|
-
} catch (_) {
|
|
2049
|
-
console.warn("TrustedTypes policy " + policyName + " could not be created.");
|
|
2050
|
-
return null;
|
|
2051
|
-
}
|
|
2052
|
-
};
|
|
2053
|
-
var _createHooksMap = function _createHooksMap2() {
|
|
2054
|
-
return {
|
|
2055
|
-
afterSanitizeAttributes: [],
|
|
2056
|
-
afterSanitizeElements: [],
|
|
2057
|
-
afterSanitizeShadowDOM: [],
|
|
2058
|
-
beforeSanitizeAttributes: [],
|
|
2059
|
-
beforeSanitizeElements: [],
|
|
2060
|
-
beforeSanitizeShadowDOM: [],
|
|
2061
|
-
uponSanitizeAttribute: [],
|
|
2062
|
-
uponSanitizeElement: [],
|
|
2063
|
-
uponSanitizeShadowNode: []
|
|
2064
|
-
};
|
|
2065
|
-
};
|
|
2066
|
-
function createDOMPurify() {
|
|
2067
|
-
let window2 = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : getGlobal();
|
|
2068
|
-
const DOMPurify = (root) => createDOMPurify(root);
|
|
2069
|
-
DOMPurify.version = "3.3.3";
|
|
2070
|
-
DOMPurify.removed = [];
|
|
2071
|
-
if (!window2 || !window2.document || window2.document.nodeType !== NODE_TYPE.document || !window2.Element) {
|
|
2072
|
-
DOMPurify.isSupported = false;
|
|
2073
|
-
return DOMPurify;
|
|
2074
|
-
}
|
|
2075
|
-
let {
|
|
2076
|
-
document: document2
|
|
2077
|
-
} = window2;
|
|
2078
|
-
const originalDocument = document2;
|
|
2079
|
-
const currentScript = originalDocument.currentScript;
|
|
2080
|
-
const {
|
|
2081
|
-
DocumentFragment: DocumentFragment2,
|
|
2082
|
-
HTMLTemplateElement,
|
|
2083
|
-
Node,
|
|
2084
|
-
Element,
|
|
2085
|
-
NodeFilter,
|
|
2086
|
-
NamedNodeMap = window2.NamedNodeMap || window2.MozNamedAttrMap,
|
|
2087
|
-
HTMLFormElement,
|
|
2088
|
-
DOMParser: DOMParser2,
|
|
2089
|
-
trustedTypes
|
|
2090
|
-
} = window2;
|
|
2091
|
-
const ElementPrototype = Element.prototype;
|
|
2092
|
-
const cloneNode = lookupGetter(ElementPrototype, "cloneNode");
|
|
2093
|
-
const remove = lookupGetter(ElementPrototype, "remove");
|
|
2094
|
-
const getNextSibling = lookupGetter(ElementPrototype, "nextSibling");
|
|
2095
|
-
const getChildNodes = lookupGetter(ElementPrototype, "childNodes");
|
|
2096
|
-
const getParentNode = lookupGetter(ElementPrototype, "parentNode");
|
|
2097
|
-
if (typeof HTMLTemplateElement === "function") {
|
|
2098
|
-
const template = document2.createElement("template");
|
|
2099
|
-
if (template.content && template.content.ownerDocument) {
|
|
2100
|
-
document2 = template.content.ownerDocument;
|
|
2101
|
-
}
|
|
2102
|
-
}
|
|
2103
|
-
let trustedTypesPolicy;
|
|
2104
|
-
let emptyHTML = "";
|
|
2105
|
-
const {
|
|
2106
|
-
implementation,
|
|
2107
|
-
createNodeIterator,
|
|
2108
|
-
createDocumentFragment,
|
|
2109
|
-
getElementsByTagName
|
|
2110
|
-
} = document2;
|
|
2111
|
-
const {
|
|
2112
|
-
importNode
|
|
2113
|
-
} = originalDocument;
|
|
2114
|
-
let hooks = _createHooksMap();
|
|
2115
|
-
DOMPurify.isSupported = typeof entries === "function" && typeof getParentNode === "function" && implementation && implementation.createHTMLDocument !== void 0;
|
|
2116
|
-
const {
|
|
2117
|
-
MUSTACHE_EXPR: MUSTACHE_EXPR2,
|
|
2118
|
-
ERB_EXPR: ERB_EXPR2,
|
|
2119
|
-
TMPLIT_EXPR: TMPLIT_EXPR2,
|
|
2120
|
-
DATA_ATTR: DATA_ATTR2,
|
|
2121
|
-
ARIA_ATTR: ARIA_ATTR2,
|
|
2122
|
-
IS_SCRIPT_OR_DATA: IS_SCRIPT_OR_DATA2,
|
|
2123
|
-
ATTR_WHITESPACE: ATTR_WHITESPACE2,
|
|
2124
|
-
CUSTOM_ELEMENT: CUSTOM_ELEMENT2
|
|
2125
|
-
} = EXPRESSIONS;
|
|
2126
|
-
let {
|
|
2127
|
-
IS_ALLOWED_URI: IS_ALLOWED_URI$1
|
|
2128
|
-
} = EXPRESSIONS;
|
|
2129
|
-
let ALLOWED_TAGS = null;
|
|
2130
|
-
const DEFAULT_ALLOWED_TAGS = addToSet({}, [...html$1, ...svg$1, ...svgFilters, ...mathMl$1, ...text]);
|
|
2131
|
-
let ALLOWED_ATTR = null;
|
|
2132
|
-
const DEFAULT_ALLOWED_ATTR = addToSet({}, [...html, ...svg, ...mathMl, ...xml]);
|
|
2133
|
-
let CUSTOM_ELEMENT_HANDLING = Object.seal(create(null, {
|
|
2134
|
-
tagNameCheck: {
|
|
2135
|
-
writable: true,
|
|
2136
|
-
configurable: false,
|
|
2137
|
-
enumerable: true,
|
|
2138
|
-
value: null
|
|
2139
|
-
},
|
|
2140
|
-
attributeNameCheck: {
|
|
2141
|
-
writable: true,
|
|
2142
|
-
configurable: false,
|
|
2143
|
-
enumerable: true,
|
|
2144
|
-
value: null
|
|
2145
|
-
},
|
|
2146
|
-
allowCustomizedBuiltInElements: {
|
|
2147
|
-
writable: true,
|
|
2148
|
-
configurable: false,
|
|
2149
|
-
enumerable: true,
|
|
2150
|
-
value: false
|
|
2151
|
-
}
|
|
2152
|
-
}));
|
|
2153
|
-
let FORBID_TAGS = null;
|
|
2154
|
-
let FORBID_ATTR = null;
|
|
2155
|
-
const EXTRA_ELEMENT_HANDLING = Object.seal(create(null, {
|
|
2156
|
-
tagCheck: {
|
|
2157
|
-
writable: true,
|
|
2158
|
-
configurable: false,
|
|
2159
|
-
enumerable: true,
|
|
2160
|
-
value: null
|
|
2161
|
-
},
|
|
2162
|
-
attributeCheck: {
|
|
2163
|
-
writable: true,
|
|
2164
|
-
configurable: false,
|
|
2165
|
-
enumerable: true,
|
|
2166
|
-
value: null
|
|
2167
|
-
}
|
|
2168
|
-
}));
|
|
2169
|
-
let ALLOW_ARIA_ATTR = true;
|
|
2170
|
-
let ALLOW_DATA_ATTR = true;
|
|
2171
|
-
let ALLOW_UNKNOWN_PROTOCOLS = false;
|
|
2172
|
-
let ALLOW_SELF_CLOSE_IN_ATTR = true;
|
|
2173
|
-
let SAFE_FOR_TEMPLATES = false;
|
|
2174
|
-
let SAFE_FOR_XML = true;
|
|
2175
|
-
let WHOLE_DOCUMENT = false;
|
|
2176
|
-
let SET_CONFIG = false;
|
|
2177
|
-
let FORCE_BODY = false;
|
|
2178
|
-
let RETURN_DOM = false;
|
|
2179
|
-
let RETURN_DOM_FRAGMENT = false;
|
|
2180
|
-
let RETURN_TRUSTED_TYPE = false;
|
|
2181
|
-
let SANITIZE_DOM = true;
|
|
2182
|
-
let SANITIZE_NAMED_PROPS = false;
|
|
2183
|
-
const SANITIZE_NAMED_PROPS_PREFIX = "user-content-";
|
|
2184
|
-
let KEEP_CONTENT = true;
|
|
2185
|
-
let IN_PLACE = false;
|
|
2186
|
-
let USE_PROFILES = {};
|
|
2187
|
-
let FORBID_CONTENTS = null;
|
|
2188
|
-
const DEFAULT_FORBID_CONTENTS = addToSet({}, ["annotation-xml", "audio", "colgroup", "desc", "foreignobject", "head", "iframe", "math", "mi", "mn", "mo", "ms", "mtext", "noembed", "noframes", "noscript", "plaintext", "script", "style", "svg", "template", "thead", "title", "video", "xmp"]);
|
|
2189
|
-
let DATA_URI_TAGS = null;
|
|
2190
|
-
const DEFAULT_DATA_URI_TAGS = addToSet({}, ["audio", "video", "img", "source", "image", "track"]);
|
|
2191
|
-
let URI_SAFE_ATTRIBUTES = null;
|
|
2192
|
-
const DEFAULT_URI_SAFE_ATTRIBUTES = addToSet({}, ["alt", "class", "for", "id", "label", "name", "pattern", "placeholder", "role", "summary", "title", "value", "style", "xmlns"]);
|
|
2193
|
-
const MATHML_NAMESPACE = "http://www.w3.org/1998/Math/MathML";
|
|
2194
|
-
const SVG_NAMESPACE = "http://www.w3.org/2000/svg";
|
|
2195
|
-
const HTML_NAMESPACE = "http://www.w3.org/1999/xhtml";
|
|
2196
|
-
let NAMESPACE = HTML_NAMESPACE;
|
|
2197
|
-
let IS_EMPTY_INPUT = false;
|
|
2198
|
-
let ALLOWED_NAMESPACES = null;
|
|
2199
|
-
const DEFAULT_ALLOWED_NAMESPACES = addToSet({}, [MATHML_NAMESPACE, SVG_NAMESPACE, HTML_NAMESPACE], stringToString);
|
|
2200
|
-
let MATHML_TEXT_INTEGRATION_POINTS = addToSet({}, ["mi", "mo", "mn", "ms", "mtext"]);
|
|
2201
|
-
let HTML_INTEGRATION_POINTS = addToSet({}, ["annotation-xml"]);
|
|
2202
|
-
const COMMON_SVG_AND_HTML_ELEMENTS = addToSet({}, ["title", "style", "font", "a", "script"]);
|
|
2203
|
-
let PARSER_MEDIA_TYPE = null;
|
|
2204
|
-
const SUPPORTED_PARSER_MEDIA_TYPES = ["application/xhtml+xml", "text/html"];
|
|
2205
|
-
const DEFAULT_PARSER_MEDIA_TYPE = "text/html";
|
|
2206
|
-
let transformCaseFunc = null;
|
|
2207
|
-
let CONFIG = null;
|
|
2208
|
-
const formElement = document2.createElement("form");
|
|
2209
|
-
const isRegexOrFunction = function isRegexOrFunction2(testValue) {
|
|
2210
|
-
return testValue instanceof RegExp || testValue instanceof Function;
|
|
2211
|
-
};
|
|
2212
|
-
const _parseConfig = function _parseConfig2() {
|
|
2213
|
-
let cfg = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
|
2214
|
-
if (CONFIG && CONFIG === cfg) {
|
|
2215
|
-
return;
|
|
2216
|
-
}
|
|
2217
|
-
if (!cfg || typeof cfg !== "object") {
|
|
2218
|
-
cfg = {};
|
|
2219
|
-
}
|
|
2220
|
-
cfg = clone(cfg);
|
|
2221
|
-
PARSER_MEDIA_TYPE = // eslint-disable-next-line unicorn/prefer-includes
|
|
2222
|
-
SUPPORTED_PARSER_MEDIA_TYPES.indexOf(cfg.PARSER_MEDIA_TYPE) === -1 ? DEFAULT_PARSER_MEDIA_TYPE : cfg.PARSER_MEDIA_TYPE;
|
|
2223
|
-
transformCaseFunc = PARSER_MEDIA_TYPE === "application/xhtml+xml" ? stringToString : stringToLowerCase;
|
|
2224
|
-
ALLOWED_TAGS = objectHasOwnProperty(cfg, "ALLOWED_TAGS") ? addToSet({}, cfg.ALLOWED_TAGS, transformCaseFunc) : DEFAULT_ALLOWED_TAGS;
|
|
2225
|
-
ALLOWED_ATTR = objectHasOwnProperty(cfg, "ALLOWED_ATTR") ? addToSet({}, cfg.ALLOWED_ATTR, transformCaseFunc) : DEFAULT_ALLOWED_ATTR;
|
|
2226
|
-
ALLOWED_NAMESPACES = objectHasOwnProperty(cfg, "ALLOWED_NAMESPACES") ? addToSet({}, cfg.ALLOWED_NAMESPACES, stringToString) : DEFAULT_ALLOWED_NAMESPACES;
|
|
2227
|
-
URI_SAFE_ATTRIBUTES = objectHasOwnProperty(cfg, "ADD_URI_SAFE_ATTR") ? addToSet(clone(DEFAULT_URI_SAFE_ATTRIBUTES), cfg.ADD_URI_SAFE_ATTR, transformCaseFunc) : DEFAULT_URI_SAFE_ATTRIBUTES;
|
|
2228
|
-
DATA_URI_TAGS = objectHasOwnProperty(cfg, "ADD_DATA_URI_TAGS") ? addToSet(clone(DEFAULT_DATA_URI_TAGS), cfg.ADD_DATA_URI_TAGS, transformCaseFunc) : DEFAULT_DATA_URI_TAGS;
|
|
2229
|
-
FORBID_CONTENTS = objectHasOwnProperty(cfg, "FORBID_CONTENTS") ? addToSet({}, cfg.FORBID_CONTENTS, transformCaseFunc) : DEFAULT_FORBID_CONTENTS;
|
|
2230
|
-
FORBID_TAGS = objectHasOwnProperty(cfg, "FORBID_TAGS") ? addToSet({}, cfg.FORBID_TAGS, transformCaseFunc) : clone({});
|
|
2231
|
-
FORBID_ATTR = objectHasOwnProperty(cfg, "FORBID_ATTR") ? addToSet({}, cfg.FORBID_ATTR, transformCaseFunc) : clone({});
|
|
2232
|
-
USE_PROFILES = objectHasOwnProperty(cfg, "USE_PROFILES") ? cfg.USE_PROFILES : false;
|
|
2233
|
-
ALLOW_ARIA_ATTR = cfg.ALLOW_ARIA_ATTR !== false;
|
|
2234
|
-
ALLOW_DATA_ATTR = cfg.ALLOW_DATA_ATTR !== false;
|
|
2235
|
-
ALLOW_UNKNOWN_PROTOCOLS = cfg.ALLOW_UNKNOWN_PROTOCOLS || false;
|
|
2236
|
-
ALLOW_SELF_CLOSE_IN_ATTR = cfg.ALLOW_SELF_CLOSE_IN_ATTR !== false;
|
|
2237
|
-
SAFE_FOR_TEMPLATES = cfg.SAFE_FOR_TEMPLATES || false;
|
|
2238
|
-
SAFE_FOR_XML = cfg.SAFE_FOR_XML !== false;
|
|
2239
|
-
WHOLE_DOCUMENT = cfg.WHOLE_DOCUMENT || false;
|
|
2240
|
-
RETURN_DOM = cfg.RETURN_DOM || false;
|
|
2241
|
-
RETURN_DOM_FRAGMENT = cfg.RETURN_DOM_FRAGMENT || false;
|
|
2242
|
-
RETURN_TRUSTED_TYPE = cfg.RETURN_TRUSTED_TYPE || false;
|
|
2243
|
-
FORCE_BODY = cfg.FORCE_BODY || false;
|
|
2244
|
-
SANITIZE_DOM = cfg.SANITIZE_DOM !== false;
|
|
2245
|
-
SANITIZE_NAMED_PROPS = cfg.SANITIZE_NAMED_PROPS || false;
|
|
2246
|
-
KEEP_CONTENT = cfg.KEEP_CONTENT !== false;
|
|
2247
|
-
IN_PLACE = cfg.IN_PLACE || false;
|
|
2248
|
-
IS_ALLOWED_URI$1 = cfg.ALLOWED_URI_REGEXP || IS_ALLOWED_URI;
|
|
2249
|
-
NAMESPACE = cfg.NAMESPACE || HTML_NAMESPACE;
|
|
2250
|
-
MATHML_TEXT_INTEGRATION_POINTS = cfg.MATHML_TEXT_INTEGRATION_POINTS || MATHML_TEXT_INTEGRATION_POINTS;
|
|
2251
|
-
HTML_INTEGRATION_POINTS = cfg.HTML_INTEGRATION_POINTS || HTML_INTEGRATION_POINTS;
|
|
2252
|
-
CUSTOM_ELEMENT_HANDLING = cfg.CUSTOM_ELEMENT_HANDLING || {};
|
|
2253
|
-
if (cfg.CUSTOM_ELEMENT_HANDLING && isRegexOrFunction(cfg.CUSTOM_ELEMENT_HANDLING.tagNameCheck)) {
|
|
2254
|
-
CUSTOM_ELEMENT_HANDLING.tagNameCheck = cfg.CUSTOM_ELEMENT_HANDLING.tagNameCheck;
|
|
2255
|
-
}
|
|
2256
|
-
if (cfg.CUSTOM_ELEMENT_HANDLING && isRegexOrFunction(cfg.CUSTOM_ELEMENT_HANDLING.attributeNameCheck)) {
|
|
2257
|
-
CUSTOM_ELEMENT_HANDLING.attributeNameCheck = cfg.CUSTOM_ELEMENT_HANDLING.attributeNameCheck;
|
|
2258
|
-
}
|
|
2259
|
-
if (cfg.CUSTOM_ELEMENT_HANDLING && typeof cfg.CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements === "boolean") {
|
|
2260
|
-
CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements = cfg.CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements;
|
|
2261
|
-
}
|
|
2262
|
-
if (SAFE_FOR_TEMPLATES) {
|
|
2263
|
-
ALLOW_DATA_ATTR = false;
|
|
2264
|
-
}
|
|
2265
|
-
if (RETURN_DOM_FRAGMENT) {
|
|
2266
|
-
RETURN_DOM = true;
|
|
2267
|
-
}
|
|
2268
|
-
if (USE_PROFILES) {
|
|
2269
|
-
ALLOWED_TAGS = addToSet({}, text);
|
|
2270
|
-
ALLOWED_ATTR = create(null);
|
|
2271
|
-
if (USE_PROFILES.html === true) {
|
|
2272
|
-
addToSet(ALLOWED_TAGS, html$1);
|
|
2273
|
-
addToSet(ALLOWED_ATTR, html);
|
|
2274
|
-
}
|
|
2275
|
-
if (USE_PROFILES.svg === true) {
|
|
2276
|
-
addToSet(ALLOWED_TAGS, svg$1);
|
|
2277
|
-
addToSet(ALLOWED_ATTR, svg);
|
|
2278
|
-
addToSet(ALLOWED_ATTR, xml);
|
|
2279
|
-
}
|
|
2280
|
-
if (USE_PROFILES.svgFilters === true) {
|
|
2281
|
-
addToSet(ALLOWED_TAGS, svgFilters);
|
|
2282
|
-
addToSet(ALLOWED_ATTR, svg);
|
|
2283
|
-
addToSet(ALLOWED_ATTR, xml);
|
|
2284
|
-
}
|
|
2285
|
-
if (USE_PROFILES.mathMl === true) {
|
|
2286
|
-
addToSet(ALLOWED_TAGS, mathMl$1);
|
|
2287
|
-
addToSet(ALLOWED_ATTR, mathMl);
|
|
2288
|
-
addToSet(ALLOWED_ATTR, xml);
|
|
2289
|
-
}
|
|
2290
|
-
}
|
|
2291
|
-
if (!objectHasOwnProperty(cfg, "ADD_TAGS")) {
|
|
2292
|
-
EXTRA_ELEMENT_HANDLING.tagCheck = null;
|
|
2293
|
-
}
|
|
2294
|
-
if (!objectHasOwnProperty(cfg, "ADD_ATTR")) {
|
|
2295
|
-
EXTRA_ELEMENT_HANDLING.attributeCheck = null;
|
|
2296
|
-
}
|
|
2297
|
-
if (cfg.ADD_TAGS) {
|
|
2298
|
-
if (typeof cfg.ADD_TAGS === "function") {
|
|
2299
|
-
EXTRA_ELEMENT_HANDLING.tagCheck = cfg.ADD_TAGS;
|
|
2300
|
-
} else {
|
|
2301
|
-
if (ALLOWED_TAGS === DEFAULT_ALLOWED_TAGS) {
|
|
2302
|
-
ALLOWED_TAGS = clone(ALLOWED_TAGS);
|
|
2303
|
-
}
|
|
2304
|
-
addToSet(ALLOWED_TAGS, cfg.ADD_TAGS, transformCaseFunc);
|
|
2305
|
-
}
|
|
2306
|
-
}
|
|
2307
|
-
if (cfg.ADD_ATTR) {
|
|
2308
|
-
if (typeof cfg.ADD_ATTR === "function") {
|
|
2309
|
-
EXTRA_ELEMENT_HANDLING.attributeCheck = cfg.ADD_ATTR;
|
|
2310
|
-
} else {
|
|
2311
|
-
if (ALLOWED_ATTR === DEFAULT_ALLOWED_ATTR) {
|
|
2312
|
-
ALLOWED_ATTR = clone(ALLOWED_ATTR);
|
|
2313
|
-
}
|
|
2314
|
-
addToSet(ALLOWED_ATTR, cfg.ADD_ATTR, transformCaseFunc);
|
|
2315
|
-
}
|
|
2316
|
-
}
|
|
2317
|
-
if (cfg.ADD_URI_SAFE_ATTR) {
|
|
2318
|
-
addToSet(URI_SAFE_ATTRIBUTES, cfg.ADD_URI_SAFE_ATTR, transformCaseFunc);
|
|
2319
|
-
}
|
|
2320
|
-
if (cfg.FORBID_CONTENTS) {
|
|
2321
|
-
if (FORBID_CONTENTS === DEFAULT_FORBID_CONTENTS) {
|
|
2322
|
-
FORBID_CONTENTS = clone(FORBID_CONTENTS);
|
|
2323
|
-
}
|
|
2324
|
-
addToSet(FORBID_CONTENTS, cfg.FORBID_CONTENTS, transformCaseFunc);
|
|
2325
|
-
}
|
|
2326
|
-
if (cfg.ADD_FORBID_CONTENTS) {
|
|
2327
|
-
if (FORBID_CONTENTS === DEFAULT_FORBID_CONTENTS) {
|
|
2328
|
-
FORBID_CONTENTS = clone(FORBID_CONTENTS);
|
|
2329
|
-
}
|
|
2330
|
-
addToSet(FORBID_CONTENTS, cfg.ADD_FORBID_CONTENTS, transformCaseFunc);
|
|
2331
|
-
}
|
|
2332
|
-
if (KEEP_CONTENT) {
|
|
2333
|
-
ALLOWED_TAGS["#text"] = true;
|
|
2334
|
-
}
|
|
2335
|
-
if (WHOLE_DOCUMENT) {
|
|
2336
|
-
addToSet(ALLOWED_TAGS, ["html", "head", "body"]);
|
|
2337
|
-
}
|
|
2338
|
-
if (ALLOWED_TAGS.table) {
|
|
2339
|
-
addToSet(ALLOWED_TAGS, ["tbody"]);
|
|
2340
|
-
delete FORBID_TAGS.tbody;
|
|
2341
|
-
}
|
|
2342
|
-
if (cfg.TRUSTED_TYPES_POLICY) {
|
|
2343
|
-
if (typeof cfg.TRUSTED_TYPES_POLICY.createHTML !== "function") {
|
|
2344
|
-
throw typeErrorCreate('TRUSTED_TYPES_POLICY configuration option must provide a "createHTML" hook.');
|
|
2345
|
-
}
|
|
2346
|
-
if (typeof cfg.TRUSTED_TYPES_POLICY.createScriptURL !== "function") {
|
|
2347
|
-
throw typeErrorCreate('TRUSTED_TYPES_POLICY configuration option must provide a "createScriptURL" hook.');
|
|
2348
|
-
}
|
|
2349
|
-
trustedTypesPolicy = cfg.TRUSTED_TYPES_POLICY;
|
|
2350
|
-
emptyHTML = trustedTypesPolicy.createHTML("");
|
|
2351
|
-
} else {
|
|
2352
|
-
if (trustedTypesPolicy === void 0) {
|
|
2353
|
-
trustedTypesPolicy = _createTrustedTypesPolicy(trustedTypes, currentScript);
|
|
2354
|
-
}
|
|
2355
|
-
if (trustedTypesPolicy !== null && typeof emptyHTML === "string") {
|
|
2356
|
-
emptyHTML = trustedTypesPolicy.createHTML("");
|
|
2357
|
-
}
|
|
2358
|
-
}
|
|
2359
|
-
if (freeze) {
|
|
2360
|
-
freeze(cfg);
|
|
2361
|
-
}
|
|
2362
|
-
CONFIG = cfg;
|
|
2363
|
-
};
|
|
2364
|
-
const ALL_SVG_TAGS = addToSet({}, [...svg$1, ...svgFilters, ...svgDisallowed]);
|
|
2365
|
-
const ALL_MATHML_TAGS = addToSet({}, [...mathMl$1, ...mathMlDisallowed]);
|
|
2366
|
-
const _checkValidNamespace = function _checkValidNamespace2(element) {
|
|
2367
|
-
let parent = getParentNode(element);
|
|
2368
|
-
if (!parent || !parent.tagName) {
|
|
2369
|
-
parent = {
|
|
2370
|
-
namespaceURI: NAMESPACE,
|
|
2371
|
-
tagName: "template"
|
|
2372
|
-
};
|
|
2373
|
-
}
|
|
2374
|
-
const tagName = stringToLowerCase(element.tagName);
|
|
2375
|
-
const parentTagName = stringToLowerCase(parent.tagName);
|
|
2376
|
-
if (!ALLOWED_NAMESPACES[element.namespaceURI]) {
|
|
2377
|
-
return false;
|
|
2378
|
-
}
|
|
2379
|
-
if (element.namespaceURI === SVG_NAMESPACE) {
|
|
2380
|
-
if (parent.namespaceURI === HTML_NAMESPACE) {
|
|
2381
|
-
return tagName === "svg";
|
|
2382
|
-
}
|
|
2383
|
-
if (parent.namespaceURI === MATHML_NAMESPACE) {
|
|
2384
|
-
return tagName === "svg" && (parentTagName === "annotation-xml" || MATHML_TEXT_INTEGRATION_POINTS[parentTagName]);
|
|
2385
|
-
}
|
|
2386
|
-
return Boolean(ALL_SVG_TAGS[tagName]);
|
|
2387
|
-
}
|
|
2388
|
-
if (element.namespaceURI === MATHML_NAMESPACE) {
|
|
2389
|
-
if (parent.namespaceURI === HTML_NAMESPACE) {
|
|
2390
|
-
return tagName === "math";
|
|
2391
|
-
}
|
|
2392
|
-
if (parent.namespaceURI === SVG_NAMESPACE) {
|
|
2393
|
-
return tagName === "math" && HTML_INTEGRATION_POINTS[parentTagName];
|
|
2394
|
-
}
|
|
2395
|
-
return Boolean(ALL_MATHML_TAGS[tagName]);
|
|
2396
|
-
}
|
|
2397
|
-
if (element.namespaceURI === HTML_NAMESPACE) {
|
|
2398
|
-
if (parent.namespaceURI === SVG_NAMESPACE && !HTML_INTEGRATION_POINTS[parentTagName]) {
|
|
2399
|
-
return false;
|
|
2400
|
-
}
|
|
2401
|
-
if (parent.namespaceURI === MATHML_NAMESPACE && !MATHML_TEXT_INTEGRATION_POINTS[parentTagName]) {
|
|
2402
|
-
return false;
|
|
2403
|
-
}
|
|
2404
|
-
return !ALL_MATHML_TAGS[tagName] && (COMMON_SVG_AND_HTML_ELEMENTS[tagName] || !ALL_SVG_TAGS[tagName]);
|
|
2405
|
-
}
|
|
2406
|
-
if (PARSER_MEDIA_TYPE === "application/xhtml+xml" && ALLOWED_NAMESPACES[element.namespaceURI]) {
|
|
2407
|
-
return true;
|
|
2408
|
-
}
|
|
2409
|
-
return false;
|
|
2410
|
-
};
|
|
2411
|
-
const _forceRemove = function _forceRemove2(node) {
|
|
2412
|
-
arrayPush(DOMPurify.removed, {
|
|
2413
|
-
element: node
|
|
2414
|
-
});
|
|
2415
|
-
try {
|
|
2416
|
-
getParentNode(node).removeChild(node);
|
|
2417
|
-
} catch (_) {
|
|
2418
|
-
remove(node);
|
|
2419
|
-
}
|
|
2420
|
-
};
|
|
2421
|
-
const _removeAttribute = function _removeAttribute2(name, element) {
|
|
2422
|
-
try {
|
|
2423
|
-
arrayPush(DOMPurify.removed, {
|
|
2424
|
-
attribute: element.getAttributeNode(name),
|
|
2425
|
-
from: element
|
|
2426
|
-
});
|
|
2427
|
-
} catch (_) {
|
|
2428
|
-
arrayPush(DOMPurify.removed, {
|
|
2429
|
-
attribute: null,
|
|
2430
|
-
from: element
|
|
2431
|
-
});
|
|
2432
|
-
}
|
|
2433
|
-
element.removeAttribute(name);
|
|
2434
|
-
if (name === "is") {
|
|
2435
|
-
if (RETURN_DOM || RETURN_DOM_FRAGMENT) {
|
|
2436
|
-
try {
|
|
2437
|
-
_forceRemove(element);
|
|
2438
|
-
} catch (_) {
|
|
2439
|
-
}
|
|
2440
|
-
} else {
|
|
2441
|
-
try {
|
|
2442
|
-
element.setAttribute(name, "");
|
|
2443
|
-
} catch (_) {
|
|
2444
|
-
}
|
|
2445
|
-
}
|
|
2446
|
-
}
|
|
2447
|
-
};
|
|
2448
|
-
const _initDocument = function _initDocument2(dirty) {
|
|
2449
|
-
let doc = null;
|
|
2450
|
-
let leadingWhitespace = null;
|
|
2451
|
-
if (FORCE_BODY) {
|
|
2452
|
-
dirty = "<remove></remove>" + dirty;
|
|
2453
|
-
} else {
|
|
2454
|
-
const matches = stringMatch(dirty, /^[\r\n\t ]+/);
|
|
2455
|
-
leadingWhitespace = matches && matches[0];
|
|
2456
|
-
}
|
|
2457
|
-
if (PARSER_MEDIA_TYPE === "application/xhtml+xml" && NAMESPACE === HTML_NAMESPACE) {
|
|
2458
|
-
dirty = '<html xmlns="http://www.w3.org/1999/xhtml"><head></head><body>' + dirty + "</body></html>";
|
|
2459
|
-
}
|
|
2460
|
-
const dirtyPayload = trustedTypesPolicy ? trustedTypesPolicy.createHTML(dirty) : dirty;
|
|
2461
|
-
if (NAMESPACE === HTML_NAMESPACE) {
|
|
2462
|
-
try {
|
|
2463
|
-
doc = new DOMParser2().parseFromString(dirtyPayload, PARSER_MEDIA_TYPE);
|
|
2464
|
-
} catch (_) {
|
|
2465
|
-
}
|
|
2466
|
-
}
|
|
2467
|
-
if (!doc || !doc.documentElement) {
|
|
2468
|
-
doc = implementation.createDocument(NAMESPACE, "template", null);
|
|
2469
|
-
try {
|
|
2470
|
-
doc.documentElement.innerHTML = IS_EMPTY_INPUT ? emptyHTML : dirtyPayload;
|
|
2471
|
-
} catch (_) {
|
|
2472
|
-
}
|
|
2473
|
-
}
|
|
2474
|
-
const body = doc.body || doc.documentElement;
|
|
2475
|
-
if (dirty && leadingWhitespace) {
|
|
2476
|
-
body.insertBefore(document2.createTextNode(leadingWhitespace), body.childNodes[0] || null);
|
|
2477
|
-
}
|
|
2478
|
-
if (NAMESPACE === HTML_NAMESPACE) {
|
|
2479
|
-
return getElementsByTagName.call(doc, WHOLE_DOCUMENT ? "html" : "body")[0];
|
|
2480
|
-
}
|
|
2481
|
-
return WHOLE_DOCUMENT ? doc.documentElement : body;
|
|
2482
|
-
};
|
|
2483
|
-
const _createNodeIterator = function _createNodeIterator2(root) {
|
|
2484
|
-
return createNodeIterator.call(
|
|
2485
|
-
root.ownerDocument || root,
|
|
2486
|
-
root,
|
|
2487
|
-
// eslint-disable-next-line no-bitwise
|
|
2488
|
-
NodeFilter.SHOW_ELEMENT | NodeFilter.SHOW_COMMENT | NodeFilter.SHOW_TEXT | NodeFilter.SHOW_PROCESSING_INSTRUCTION | NodeFilter.SHOW_CDATA_SECTION,
|
|
2489
|
-
null
|
|
2490
|
-
);
|
|
2491
|
-
};
|
|
2492
|
-
const _isClobbered = function _isClobbered2(element) {
|
|
2493
|
-
return element instanceof HTMLFormElement && (typeof element.nodeName !== "string" || typeof element.textContent !== "string" || typeof element.removeChild !== "function" || !(element.attributes instanceof NamedNodeMap) || typeof element.removeAttribute !== "function" || typeof element.setAttribute !== "function" || typeof element.namespaceURI !== "string" || typeof element.insertBefore !== "function" || typeof element.hasChildNodes !== "function");
|
|
2494
|
-
};
|
|
2495
|
-
const _isNode = function _isNode2(value) {
|
|
2496
|
-
return typeof Node === "function" && value instanceof Node;
|
|
2497
|
-
};
|
|
2498
|
-
function _executeHooks(hooks2, currentNode, data) {
|
|
2499
|
-
arrayForEach(hooks2, (hook) => {
|
|
2500
|
-
hook.call(DOMPurify, currentNode, data, CONFIG);
|
|
2501
|
-
});
|
|
2502
|
-
}
|
|
2503
|
-
const _sanitizeElements = function _sanitizeElements2(currentNode) {
|
|
2504
|
-
let content = null;
|
|
2505
|
-
_executeHooks(hooks.beforeSanitizeElements, currentNode, null);
|
|
2506
|
-
if (_isClobbered(currentNode)) {
|
|
2507
|
-
_forceRemove(currentNode);
|
|
2508
|
-
return true;
|
|
2509
|
-
}
|
|
2510
|
-
const tagName = transformCaseFunc(currentNode.nodeName);
|
|
2511
|
-
_executeHooks(hooks.uponSanitizeElement, currentNode, {
|
|
2512
|
-
tagName,
|
|
2513
|
-
allowedTags: ALLOWED_TAGS
|
|
2514
|
-
});
|
|
2515
|
-
if (SAFE_FOR_XML && currentNode.hasChildNodes() && !_isNode(currentNode.firstElementChild) && regExpTest(/<[/\w!]/g, currentNode.innerHTML) && regExpTest(/<[/\w!]/g, currentNode.textContent)) {
|
|
2516
|
-
_forceRemove(currentNode);
|
|
2517
|
-
return true;
|
|
2518
|
-
}
|
|
2519
|
-
if (currentNode.nodeType === NODE_TYPE.progressingInstruction) {
|
|
2520
|
-
_forceRemove(currentNode);
|
|
2521
|
-
return true;
|
|
2522
|
-
}
|
|
2523
|
-
if (SAFE_FOR_XML && currentNode.nodeType === NODE_TYPE.comment && regExpTest(/<[/\w]/g, currentNode.data)) {
|
|
2524
|
-
_forceRemove(currentNode);
|
|
2525
|
-
return true;
|
|
2526
|
-
}
|
|
2527
|
-
if (!(EXTRA_ELEMENT_HANDLING.tagCheck instanceof Function && EXTRA_ELEMENT_HANDLING.tagCheck(tagName)) && (!ALLOWED_TAGS[tagName] || FORBID_TAGS[tagName])) {
|
|
2528
|
-
if (!FORBID_TAGS[tagName] && _isBasicCustomElement(tagName)) {
|
|
2529
|
-
if (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.tagNameCheck, tagName)) {
|
|
2530
|
-
return false;
|
|
2531
|
-
}
|
|
2532
|
-
if (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.tagNameCheck(tagName)) {
|
|
2533
|
-
return false;
|
|
2534
|
-
}
|
|
2535
|
-
}
|
|
2536
|
-
if (KEEP_CONTENT && !FORBID_CONTENTS[tagName]) {
|
|
2537
|
-
const parentNode = getParentNode(currentNode) || currentNode.parentNode;
|
|
2538
|
-
const childNodes = getChildNodes(currentNode) || currentNode.childNodes;
|
|
2539
|
-
if (childNodes && parentNode) {
|
|
2540
|
-
const childCount = childNodes.length;
|
|
2541
|
-
for (let i = childCount - 1; i >= 0; --i) {
|
|
2542
|
-
const childClone = cloneNode(childNodes[i], true);
|
|
2543
|
-
childClone.__removalCount = (currentNode.__removalCount || 0) + 1;
|
|
2544
|
-
parentNode.insertBefore(childClone, getNextSibling(currentNode));
|
|
2545
|
-
}
|
|
2546
|
-
}
|
|
2547
|
-
}
|
|
2548
|
-
_forceRemove(currentNode);
|
|
2549
|
-
return true;
|
|
2550
|
-
}
|
|
2551
|
-
if (currentNode instanceof Element && !_checkValidNamespace(currentNode)) {
|
|
2552
|
-
_forceRemove(currentNode);
|
|
2553
|
-
return true;
|
|
2554
|
-
}
|
|
2555
|
-
if ((tagName === "noscript" || tagName === "noembed" || tagName === "noframes") && regExpTest(/<\/no(script|embed|frames)/i, currentNode.innerHTML)) {
|
|
2556
|
-
_forceRemove(currentNode);
|
|
2557
|
-
return true;
|
|
2558
|
-
}
|
|
2559
|
-
if (SAFE_FOR_TEMPLATES && currentNode.nodeType === NODE_TYPE.text) {
|
|
2560
|
-
content = currentNode.textContent;
|
|
2561
|
-
arrayForEach([MUSTACHE_EXPR2, ERB_EXPR2, TMPLIT_EXPR2], (expr) => {
|
|
2562
|
-
content = stringReplace(content, expr, " ");
|
|
2563
|
-
});
|
|
2564
|
-
if (currentNode.textContent !== content) {
|
|
2565
|
-
arrayPush(DOMPurify.removed, {
|
|
2566
|
-
element: currentNode.cloneNode()
|
|
2567
|
-
});
|
|
2568
|
-
currentNode.textContent = content;
|
|
2569
|
-
}
|
|
2570
|
-
}
|
|
2571
|
-
_executeHooks(hooks.afterSanitizeElements, currentNode, null);
|
|
2572
|
-
return false;
|
|
2573
|
-
};
|
|
2574
|
-
const _isValidAttribute = function _isValidAttribute2(lcTag, lcName, value) {
|
|
2575
|
-
if (FORBID_ATTR[lcName]) {
|
|
2576
|
-
return false;
|
|
2577
|
-
}
|
|
2578
|
-
if (SANITIZE_DOM && (lcName === "id" || lcName === "name") && (value in document2 || value in formElement)) {
|
|
2579
|
-
return false;
|
|
2580
|
-
}
|
|
2581
|
-
if (ALLOW_DATA_ATTR && !FORBID_ATTR[lcName] && regExpTest(DATA_ATTR2, lcName)) ;
|
|
2582
|
-
else if (ALLOW_ARIA_ATTR && regExpTest(ARIA_ATTR2, lcName)) ;
|
|
2583
|
-
else if (EXTRA_ELEMENT_HANDLING.attributeCheck instanceof Function && EXTRA_ELEMENT_HANDLING.attributeCheck(lcName, lcTag)) ;
|
|
2584
|
-
else if (!ALLOWED_ATTR[lcName] || FORBID_ATTR[lcName]) {
|
|
2585
|
-
if (
|
|
2586
|
-
// First condition does a very basic check if a) it's basically a valid custom element tagname AND
|
|
2587
|
-
// b) if the tagName passes whatever the user has configured for CUSTOM_ELEMENT_HANDLING.tagNameCheck
|
|
2588
|
-
// and c) if the attribute name passes whatever the user has configured for CUSTOM_ELEMENT_HANDLING.attributeNameCheck
|
|
2589
|
-
_isBasicCustomElement(lcTag) && (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.tagNameCheck, lcTag) || CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.tagNameCheck(lcTag)) && (CUSTOM_ELEMENT_HANDLING.attributeNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.attributeNameCheck, lcName) || CUSTOM_ELEMENT_HANDLING.attributeNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.attributeNameCheck(lcName, lcTag)) || // Alternative, second condition checks if it's an `is`-attribute, AND
|
|
2590
|
-
// the value passes whatever the user has configured for CUSTOM_ELEMENT_HANDLING.tagNameCheck
|
|
2591
|
-
lcName === "is" && CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements && (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.tagNameCheck, value) || CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.tagNameCheck(value))
|
|
2592
|
-
) ;
|
|
2593
|
-
else {
|
|
2594
|
-
return false;
|
|
2595
|
-
}
|
|
2596
|
-
} else if (URI_SAFE_ATTRIBUTES[lcName]) ;
|
|
2597
|
-
else if (regExpTest(IS_ALLOWED_URI$1, stringReplace(value, ATTR_WHITESPACE2, ""))) ;
|
|
2598
|
-
else if ((lcName === "src" || lcName === "xlink:href" || lcName === "href") && lcTag !== "script" && stringIndexOf(value, "data:") === 0 && DATA_URI_TAGS[lcTag]) ;
|
|
2599
|
-
else if (ALLOW_UNKNOWN_PROTOCOLS && !regExpTest(IS_SCRIPT_OR_DATA2, stringReplace(value, ATTR_WHITESPACE2, ""))) ;
|
|
2600
|
-
else if (value) {
|
|
2601
|
-
return false;
|
|
2602
|
-
} else ;
|
|
2603
|
-
return true;
|
|
2604
|
-
};
|
|
2605
|
-
const _isBasicCustomElement = function _isBasicCustomElement2(tagName) {
|
|
2606
|
-
return tagName !== "annotation-xml" && stringMatch(tagName, CUSTOM_ELEMENT2);
|
|
2607
|
-
};
|
|
2608
|
-
const _sanitizeAttributes = function _sanitizeAttributes2(currentNode) {
|
|
2609
|
-
_executeHooks(hooks.beforeSanitizeAttributes, currentNode, null);
|
|
2610
|
-
const {
|
|
2611
|
-
attributes
|
|
2612
|
-
} = currentNode;
|
|
2613
|
-
if (!attributes || _isClobbered(currentNode)) {
|
|
2614
|
-
return;
|
|
2615
|
-
}
|
|
2616
|
-
const hookEvent = {
|
|
2617
|
-
attrName: "",
|
|
2618
|
-
attrValue: "",
|
|
2619
|
-
keepAttr: true,
|
|
2620
|
-
allowedAttributes: ALLOWED_ATTR,
|
|
2621
|
-
forceKeepAttr: void 0
|
|
2622
|
-
};
|
|
2623
|
-
let l = attributes.length;
|
|
2624
|
-
while (l--) {
|
|
2625
|
-
const attr = attributes[l];
|
|
2626
|
-
const {
|
|
2627
|
-
name,
|
|
2628
|
-
namespaceURI,
|
|
2629
|
-
value: attrValue
|
|
2630
|
-
} = attr;
|
|
2631
|
-
const lcName = transformCaseFunc(name);
|
|
2632
|
-
const initValue = attrValue;
|
|
2633
|
-
let value = name === "value" ? initValue : stringTrim(initValue);
|
|
2634
|
-
hookEvent.attrName = lcName;
|
|
2635
|
-
hookEvent.attrValue = value;
|
|
2636
|
-
hookEvent.keepAttr = true;
|
|
2637
|
-
hookEvent.forceKeepAttr = void 0;
|
|
2638
|
-
_executeHooks(hooks.uponSanitizeAttribute, currentNode, hookEvent);
|
|
2639
|
-
value = hookEvent.attrValue;
|
|
2640
|
-
if (SANITIZE_NAMED_PROPS && (lcName === "id" || lcName === "name")) {
|
|
2641
|
-
_removeAttribute(name, currentNode);
|
|
2642
|
-
value = SANITIZE_NAMED_PROPS_PREFIX + value;
|
|
2643
|
-
}
|
|
2644
|
-
if (SAFE_FOR_XML && regExpTest(/((--!?|])>)|<\/(style|script|title|xmp|textarea|noscript|iframe|noembed|noframes)/i, value)) {
|
|
2645
|
-
_removeAttribute(name, currentNode);
|
|
2646
|
-
continue;
|
|
2647
|
-
}
|
|
2648
|
-
if (lcName === "attributename" && stringMatch(value, "href")) {
|
|
2649
|
-
_removeAttribute(name, currentNode);
|
|
2650
|
-
continue;
|
|
2651
|
-
}
|
|
2652
|
-
if (hookEvent.forceKeepAttr) {
|
|
2653
|
-
continue;
|
|
2654
|
-
}
|
|
2655
|
-
if (!hookEvent.keepAttr) {
|
|
2656
|
-
_removeAttribute(name, currentNode);
|
|
2657
|
-
continue;
|
|
2658
|
-
}
|
|
2659
|
-
if (!ALLOW_SELF_CLOSE_IN_ATTR && regExpTest(/\/>/i, value)) {
|
|
2660
|
-
_removeAttribute(name, currentNode);
|
|
2661
|
-
continue;
|
|
2662
|
-
}
|
|
2663
|
-
if (SAFE_FOR_TEMPLATES) {
|
|
2664
|
-
arrayForEach([MUSTACHE_EXPR2, ERB_EXPR2, TMPLIT_EXPR2], (expr) => {
|
|
2665
|
-
value = stringReplace(value, expr, " ");
|
|
2666
|
-
});
|
|
2667
|
-
}
|
|
2668
|
-
const lcTag = transformCaseFunc(currentNode.nodeName);
|
|
2669
|
-
if (!_isValidAttribute(lcTag, lcName, value)) {
|
|
2670
|
-
_removeAttribute(name, currentNode);
|
|
2671
|
-
continue;
|
|
2672
|
-
}
|
|
2673
|
-
if (trustedTypesPolicy && typeof trustedTypes === "object" && typeof trustedTypes.getAttributeType === "function") {
|
|
2674
|
-
if (namespaceURI) ;
|
|
2675
|
-
else {
|
|
2676
|
-
switch (trustedTypes.getAttributeType(lcTag, lcName)) {
|
|
2677
|
-
case "TrustedHTML": {
|
|
2678
|
-
value = trustedTypesPolicy.createHTML(value);
|
|
2679
|
-
break;
|
|
2680
|
-
}
|
|
2681
|
-
case "TrustedScriptURL": {
|
|
2682
|
-
value = trustedTypesPolicy.createScriptURL(value);
|
|
2683
|
-
break;
|
|
2684
|
-
}
|
|
2685
|
-
}
|
|
2686
|
-
}
|
|
2687
|
-
}
|
|
2688
|
-
if (value !== initValue) {
|
|
2689
|
-
try {
|
|
2690
|
-
if (namespaceURI) {
|
|
2691
|
-
currentNode.setAttributeNS(namespaceURI, name, value);
|
|
2692
|
-
} else {
|
|
2693
|
-
currentNode.setAttribute(name, value);
|
|
2694
|
-
}
|
|
2695
|
-
if (_isClobbered(currentNode)) {
|
|
2696
|
-
_forceRemove(currentNode);
|
|
2697
|
-
} else {
|
|
2698
|
-
arrayPop(DOMPurify.removed);
|
|
2699
|
-
}
|
|
2700
|
-
} catch (_) {
|
|
2701
|
-
_removeAttribute(name, currentNode);
|
|
2702
|
-
}
|
|
2703
|
-
}
|
|
2704
|
-
}
|
|
2705
|
-
_executeHooks(hooks.afterSanitizeAttributes, currentNode, null);
|
|
2706
|
-
};
|
|
2707
|
-
const _sanitizeShadowDOM = function _sanitizeShadowDOM2(fragment) {
|
|
2708
|
-
let shadowNode = null;
|
|
2709
|
-
const shadowIterator = _createNodeIterator(fragment);
|
|
2710
|
-
_executeHooks(hooks.beforeSanitizeShadowDOM, fragment, null);
|
|
2711
|
-
while (shadowNode = shadowIterator.nextNode()) {
|
|
2712
|
-
_executeHooks(hooks.uponSanitizeShadowNode, shadowNode, null);
|
|
2713
|
-
_sanitizeElements(shadowNode);
|
|
2714
|
-
_sanitizeAttributes(shadowNode);
|
|
2715
|
-
if (shadowNode.content instanceof DocumentFragment2) {
|
|
2716
|
-
_sanitizeShadowDOM2(shadowNode.content);
|
|
2717
|
-
}
|
|
2718
|
-
}
|
|
2719
|
-
_executeHooks(hooks.afterSanitizeShadowDOM, fragment, null);
|
|
2720
|
-
};
|
|
2721
|
-
DOMPurify.sanitize = function(dirty) {
|
|
2722
|
-
let cfg = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
|
|
2723
|
-
let body = null;
|
|
2724
|
-
let importedNode = null;
|
|
2725
|
-
let currentNode = null;
|
|
2726
|
-
let returnNode = null;
|
|
2727
|
-
IS_EMPTY_INPUT = !dirty;
|
|
2728
|
-
if (IS_EMPTY_INPUT) {
|
|
2729
|
-
dirty = "<!-->";
|
|
2730
|
-
}
|
|
2731
|
-
if (typeof dirty !== "string" && !_isNode(dirty)) {
|
|
2732
|
-
if (typeof dirty.toString === "function") {
|
|
2733
|
-
dirty = dirty.toString();
|
|
2734
|
-
if (typeof dirty !== "string") {
|
|
2735
|
-
throw typeErrorCreate("dirty is not a string, aborting");
|
|
2736
|
-
}
|
|
2737
|
-
} else {
|
|
2738
|
-
throw typeErrorCreate("toString is not a function");
|
|
2739
|
-
}
|
|
2740
|
-
}
|
|
2741
|
-
if (!DOMPurify.isSupported) {
|
|
2742
|
-
return dirty;
|
|
2743
|
-
}
|
|
2744
|
-
if (!SET_CONFIG) {
|
|
2745
|
-
_parseConfig(cfg);
|
|
2746
|
-
}
|
|
2747
|
-
DOMPurify.removed = [];
|
|
2748
|
-
if (typeof dirty === "string") {
|
|
2749
|
-
IN_PLACE = false;
|
|
2750
|
-
}
|
|
2751
|
-
if (IN_PLACE) {
|
|
2752
|
-
if (dirty.nodeName) {
|
|
2753
|
-
const tagName = transformCaseFunc(dirty.nodeName);
|
|
2754
|
-
if (!ALLOWED_TAGS[tagName] || FORBID_TAGS[tagName]) {
|
|
2755
|
-
throw typeErrorCreate("root node is forbidden and cannot be sanitized in-place");
|
|
2756
|
-
}
|
|
2757
|
-
}
|
|
2758
|
-
} else if (dirty instanceof Node) {
|
|
2759
|
-
body = _initDocument("<!---->");
|
|
2760
|
-
importedNode = body.ownerDocument.importNode(dirty, true);
|
|
2761
|
-
if (importedNode.nodeType === NODE_TYPE.element && importedNode.nodeName === "BODY") {
|
|
2762
|
-
body = importedNode;
|
|
2763
|
-
} else if (importedNode.nodeName === "HTML") {
|
|
2764
|
-
body = importedNode;
|
|
2765
|
-
} else {
|
|
2766
|
-
body.appendChild(importedNode);
|
|
2767
|
-
}
|
|
2768
|
-
} else {
|
|
2769
|
-
if (!RETURN_DOM && !SAFE_FOR_TEMPLATES && !WHOLE_DOCUMENT && // eslint-disable-next-line unicorn/prefer-includes
|
|
2770
|
-
dirty.indexOf("<") === -1) {
|
|
2771
|
-
return trustedTypesPolicy && RETURN_TRUSTED_TYPE ? trustedTypesPolicy.createHTML(dirty) : dirty;
|
|
2772
|
-
}
|
|
2773
|
-
body = _initDocument(dirty);
|
|
2774
|
-
if (!body) {
|
|
2775
|
-
return RETURN_DOM ? null : RETURN_TRUSTED_TYPE ? emptyHTML : "";
|
|
2776
|
-
}
|
|
2777
|
-
}
|
|
2778
|
-
if (body && FORCE_BODY) {
|
|
2779
|
-
_forceRemove(body.firstChild);
|
|
2780
|
-
}
|
|
2781
|
-
const nodeIterator = _createNodeIterator(IN_PLACE ? dirty : body);
|
|
2782
|
-
while (currentNode = nodeIterator.nextNode()) {
|
|
2783
|
-
_sanitizeElements(currentNode);
|
|
2784
|
-
_sanitizeAttributes(currentNode);
|
|
2785
|
-
if (currentNode.content instanceof DocumentFragment2) {
|
|
2786
|
-
_sanitizeShadowDOM(currentNode.content);
|
|
2787
|
-
}
|
|
2788
|
-
}
|
|
2789
|
-
if (IN_PLACE) {
|
|
2790
|
-
return dirty;
|
|
2791
|
-
}
|
|
2792
|
-
if (RETURN_DOM) {
|
|
2793
|
-
if (RETURN_DOM_FRAGMENT) {
|
|
2794
|
-
returnNode = createDocumentFragment.call(body.ownerDocument);
|
|
2795
|
-
while (body.firstChild) {
|
|
2796
|
-
returnNode.appendChild(body.firstChild);
|
|
2797
|
-
}
|
|
2798
|
-
} else {
|
|
2799
|
-
returnNode = body;
|
|
2800
|
-
}
|
|
2801
|
-
if (ALLOWED_ATTR.shadowroot || ALLOWED_ATTR.shadowrootmode) {
|
|
2802
|
-
returnNode = importNode.call(originalDocument, returnNode, true);
|
|
2803
|
-
}
|
|
2804
|
-
return returnNode;
|
|
2805
|
-
}
|
|
2806
|
-
let serializedHTML = WHOLE_DOCUMENT ? body.outerHTML : body.innerHTML;
|
|
2807
|
-
if (WHOLE_DOCUMENT && ALLOWED_TAGS["!doctype"] && body.ownerDocument && body.ownerDocument.doctype && body.ownerDocument.doctype.name && regExpTest(DOCTYPE_NAME, body.ownerDocument.doctype.name)) {
|
|
2808
|
-
serializedHTML = "<!DOCTYPE " + body.ownerDocument.doctype.name + ">\n" + serializedHTML;
|
|
2809
|
-
}
|
|
2810
|
-
if (SAFE_FOR_TEMPLATES) {
|
|
2811
|
-
arrayForEach([MUSTACHE_EXPR2, ERB_EXPR2, TMPLIT_EXPR2], (expr) => {
|
|
2812
|
-
serializedHTML = stringReplace(serializedHTML, expr, " ");
|
|
2813
|
-
});
|
|
2814
|
-
}
|
|
2815
|
-
return trustedTypesPolicy && RETURN_TRUSTED_TYPE ? trustedTypesPolicy.createHTML(serializedHTML) : serializedHTML;
|
|
2816
|
-
};
|
|
2817
|
-
DOMPurify.setConfig = function() {
|
|
2818
|
-
let cfg = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
|
2819
|
-
_parseConfig(cfg);
|
|
2820
|
-
SET_CONFIG = true;
|
|
2821
|
-
};
|
|
2822
|
-
DOMPurify.clearConfig = function() {
|
|
2823
|
-
CONFIG = null;
|
|
2824
|
-
SET_CONFIG = false;
|
|
2825
|
-
};
|
|
2826
|
-
DOMPurify.isValidAttribute = function(tag, attr, value) {
|
|
2827
|
-
if (!CONFIG) {
|
|
2828
|
-
_parseConfig({});
|
|
2829
|
-
}
|
|
2830
|
-
const lcTag = transformCaseFunc(tag);
|
|
2831
|
-
const lcName = transformCaseFunc(attr);
|
|
2832
|
-
return _isValidAttribute(lcTag, lcName, value);
|
|
2833
|
-
};
|
|
2834
|
-
DOMPurify.addHook = function(entryPoint, hookFunction) {
|
|
2835
|
-
if (typeof hookFunction !== "function") {
|
|
2836
|
-
return;
|
|
2837
|
-
}
|
|
2838
|
-
arrayPush(hooks[entryPoint], hookFunction);
|
|
2839
|
-
};
|
|
2840
|
-
DOMPurify.removeHook = function(entryPoint, hookFunction) {
|
|
2841
|
-
if (hookFunction !== void 0) {
|
|
2842
|
-
const index = arrayLastIndexOf(hooks[entryPoint], hookFunction);
|
|
2843
|
-
return index === -1 ? void 0 : arraySplice(hooks[entryPoint], index, 1)[0];
|
|
2844
|
-
}
|
|
2845
|
-
return arrayPop(hooks[entryPoint]);
|
|
2846
|
-
};
|
|
2847
|
-
DOMPurify.removeHooks = function(entryPoint) {
|
|
2848
|
-
hooks[entryPoint] = [];
|
|
2849
|
-
};
|
|
2850
|
-
DOMPurify.removeAllHooks = function() {
|
|
2851
|
-
hooks = _createHooksMap();
|
|
2852
|
-
};
|
|
2853
|
-
return DOMPurify;
|
|
2854
|
-
}
|
|
2855
|
-
var purify = createDOMPurify();
|
|
2856
|
-
|
|
2857
|
-
// src/response-handlers.ts
|
|
2858
|
-
var domReady;
|
|
2859
|
-
var ensureDom = async () => {
|
|
2860
|
-
if (typeof document !== "undefined" && typeof DOMParser !== "undefined" && typeof DocumentFragment !== "undefined") {
|
|
2861
|
-
return Promise.resolve();
|
|
2862
|
-
}
|
|
2863
|
-
return domReady ??= import("jsdom").then(({ JSDOM }) => {
|
|
2864
|
-
const { window: window2 } = new JSDOM("<!DOCTYPE html><html><head></head><body></body></html>");
|
|
2865
|
-
globalThis.window = window2;
|
|
2866
|
-
Object.assign(globalThis, { document: window2.document, DOMParser: window2.DOMParser, DocumentFragment: window2.DocumentFragment });
|
|
2867
|
-
});
|
|
2868
|
-
};
|
|
2869
|
-
var handleText = async (response) => await response.text();
|
|
2870
|
-
var handleScript = async (response) => {
|
|
2871
|
-
await ensureDom();
|
|
2872
|
-
const objectURL = URL.createObjectURL(await response.blob());
|
|
2873
|
-
return new Promise((resolve, reject) => {
|
|
2874
|
-
const script = document.createElement("script");
|
|
2875
|
-
Object.assign(script, { src: objectURL, type: HttpMediaType.JAVA_SCRIPT, async: true });
|
|
2876
|
-
script.onload = () => {
|
|
2877
|
-
URL.revokeObjectURL(objectURL);
|
|
2878
|
-
document.head.removeChild(script);
|
|
2879
|
-
resolve();
|
|
2880
|
-
};
|
|
2881
|
-
script.onerror = () => {
|
|
2882
|
-
URL.revokeObjectURL(objectURL);
|
|
2883
|
-
document.head.removeChild(script);
|
|
2884
|
-
reject(new Error("Script failed to load"));
|
|
2885
|
-
};
|
|
2886
|
-
document.head.appendChild(script);
|
|
2887
|
-
});
|
|
2888
|
-
};
|
|
2889
|
-
var handleCss = async (response) => {
|
|
2890
|
-
await ensureDom();
|
|
2891
|
-
const objectURL = URL.createObjectURL(await response.blob());
|
|
2892
|
-
return new Promise((resolve, reject) => {
|
|
2893
|
-
const link = document.createElement("link");
|
|
2894
|
-
Object.assign(link, { href: objectURL, type: HttpMediaType.CSS, rel: "stylesheet" });
|
|
2895
|
-
link.onload = () => resolve(URL.revokeObjectURL(objectURL));
|
|
2896
|
-
link.onerror = () => {
|
|
2897
|
-
URL.revokeObjectURL(objectURL);
|
|
2898
|
-
document.head.removeChild(link);
|
|
2899
|
-
reject(new Error("Stylesheet load failed"));
|
|
2900
|
-
};
|
|
2901
|
-
document.head.appendChild(link);
|
|
2902
|
-
});
|
|
2903
|
-
};
|
|
2904
|
-
var handleJson = async (response) => await response.json();
|
|
2905
|
-
var handleBlob = async (response) => await response.blob();
|
|
2906
|
-
var handleImage = async (response) => {
|
|
2907
|
-
await ensureDom();
|
|
2908
|
-
const objectURL = URL.createObjectURL(await response.blob());
|
|
2909
|
-
return new Promise((resolve, reject) => {
|
|
2910
|
-
const img = new Image();
|
|
2911
|
-
img.onload = () => {
|
|
2912
|
-
URL.revokeObjectURL(objectURL);
|
|
2913
|
-
resolve(img);
|
|
2914
|
-
};
|
|
2915
|
-
img.onerror = () => {
|
|
2916
|
-
URL.revokeObjectURL(objectURL);
|
|
2917
|
-
reject(new Error("Image failed to load"));
|
|
2918
|
-
};
|
|
2919
|
-
img.src = objectURL;
|
|
2920
|
-
});
|
|
2921
|
-
};
|
|
2922
|
-
var handleBuffer = async (response) => await response.arrayBuffer();
|
|
2923
|
-
var handleReadableStream = async (response) => Promise.resolve(response.body);
|
|
2924
|
-
var handleXml = async (response) => {
|
|
2925
|
-
await ensureDom();
|
|
2926
|
-
return new DOMParser().parseFromString(purify.sanitize(await response.text()), HttpMediaType.XML);
|
|
2927
|
-
};
|
|
2928
|
-
var handleHtml = async (response) => {
|
|
2929
|
-
await ensureDom();
|
|
2930
|
-
return new DOMParser().parseFromString(purify.sanitize(await response.text()), HttpMediaType.HTML);
|
|
2931
|
-
};
|
|
2932
|
-
var handleHtmlFragment = async (response) => {
|
|
2933
|
-
await ensureDom();
|
|
2934
|
-
return document.createRange().createContextualFragment(purify.sanitize(await response.text()));
|
|
2935
|
-
};
|
|
2936
|
-
|
|
2937
|
-
// src/utils.ts
|
|
2938
|
-
var isRequestBodyMethod = (method) => method !== void 0 && requestBodyMethods.includes(method);
|
|
2939
|
-
var isRawBody = (body) => body instanceof FormData || body instanceof Blob || body instanceof ArrayBuffer || body instanceof ReadableStream || body instanceof URLSearchParams || ArrayBuffer.isView(body);
|
|
2940
|
-
var getCookieValue = (name) => {
|
|
2941
|
-
if (typeof document === "undefined" || !document.cookie) {
|
|
2942
|
-
return;
|
|
2943
|
-
}
|
|
2944
|
-
const prefix = `${name}=`;
|
|
2945
|
-
const cookies = document.cookie.split(";");
|
|
2946
|
-
for (let i = 0, length = cookies.length; i < length; i++) {
|
|
2947
|
-
const cookie = cookies[i].trim();
|
|
2948
|
-
if (cookie.startsWith(prefix)) {
|
|
2949
|
-
return decodeURIComponent(cookie.slice(prefix.length));
|
|
2950
|
-
}
|
|
2951
|
-
}
|
|
2952
|
-
return void 0;
|
|
2953
|
-
};
|
|
2954
|
-
var serialize = (data) => JSON.stringify(data);
|
|
2955
|
-
var isString = (value) => value !== null && typeof value === "string";
|
|
2956
|
-
var isObject = (value) => value !== null && typeof value === "object" && !Array.isArray(value) && Object.getPrototypeOf(value) === Object.prototype;
|
|
2957
|
-
var objectMerge = (...objects) => {
|
|
2958
|
-
const length = objects.length;
|
|
2959
|
-
if (length === 0) {
|
|
2960
|
-
return void 0;
|
|
2961
|
-
}
|
|
2962
|
-
if (length === 1) {
|
|
2963
|
-
const [obj] = objects;
|
|
2964
|
-
if (!isObject(obj)) {
|
|
2965
|
-
return obj;
|
|
2966
|
-
}
|
|
2967
|
-
return deepClone(obj);
|
|
2968
|
-
}
|
|
2969
|
-
const target = {};
|
|
2970
|
-
for (const source of objects) {
|
|
2971
|
-
if (!isObject(source)) {
|
|
2972
|
-
return void 0;
|
|
2973
|
-
}
|
|
2974
|
-
for (const [property, sourceValue] of Object.entries(source)) {
|
|
2975
|
-
const targetValue = target[property];
|
|
2976
|
-
if (Array.isArray(sourceValue)) {
|
|
2977
|
-
target[property] = [...sourceValue, ...Array.isArray(targetValue) ? targetValue.filter((item) => !sourceValue.includes(item)) : []];
|
|
2978
|
-
} else if (isObject(sourceValue)) {
|
|
2979
|
-
target[property] = isObject(targetValue) ? objectMerge(targetValue, sourceValue) : deepClone(sourceValue);
|
|
2980
|
-
} else {
|
|
2981
|
-
target[property] = sourceValue;
|
|
2982
|
-
}
|
|
2983
|
-
}
|
|
2984
|
-
}
|
|
2985
|
-
return target;
|
|
2986
|
-
};
|
|
2987
|
-
function deepClone(object) {
|
|
2988
|
-
if (isObject(object)) {
|
|
2989
|
-
const cloned = {};
|
|
2990
|
-
const keys = Object.keys(object);
|
|
2991
|
-
for (let i = 0, length = keys.length, key; i < length; i++) {
|
|
2992
|
-
key = keys[i];
|
|
2993
|
-
cloned[key] = deepClone(object[key]);
|
|
2994
|
-
}
|
|
2995
|
-
return cloned;
|
|
2996
|
-
}
|
|
2997
|
-
return object;
|
|
2998
|
-
}
|
|
2999
|
-
|
|
3000
|
-
// src/transportr.ts
|
|
3001
|
-
var Transportr = class _Transportr {
|
|
3002
|
-
_baseUrl;
|
|
3003
|
-
_options;
|
|
3004
|
-
subscribr;
|
|
3005
|
-
hooks = { beforeRequest: [], afterResponse: [], beforeError: [] };
|
|
3006
|
-
static globalSubscribr = new Subscribr();
|
|
3007
|
-
static globalHooks = { beforeRequest: [], afterResponse: [], beforeError: [] };
|
|
3008
|
-
static signalControllers = /* @__PURE__ */ new Set();
|
|
3009
|
-
/** Map of in-flight deduplicated requests keyed by URL + method */
|
|
3010
|
-
static inflightRequests = /* @__PURE__ */ new Map();
|
|
3011
|
-
/** Cache for parsed MediaType instances to avoid re-parsing the same content-type strings */
|
|
3012
|
-
static mediaTypeCache = new Map(Object.values(mediaTypes).map((mediaType) => [mediaType.toString(), mediaType]));
|
|
3013
|
-
static contentTypeHandlers = [
|
|
3014
|
-
[mediaTypes.TEXT.type, handleText],
|
|
3015
|
-
[mediaTypes.JSON.subtype, handleJson],
|
|
3016
|
-
[mediaTypes.BIN.subtype, handleReadableStream],
|
|
3017
|
-
[mediaTypes.HTML.subtype, handleHtml],
|
|
3018
|
-
[mediaTypes.XML.subtype, handleXml],
|
|
3019
|
-
[mediaTypes.PNG.type, handleImage],
|
|
3020
|
-
[mediaTypes.JAVA_SCRIPT.subtype, handleScript],
|
|
3021
|
-
[mediaTypes.CSS.subtype, handleCss]
|
|
3022
|
-
];
|
|
3023
|
-
/**
|
|
3024
|
-
* Create a new Transportr instance with the provided location or origin and context path.
|
|
3025
|
-
*
|
|
3026
|
-
* @param url The URL for {@link fetch} requests.
|
|
3027
|
-
* @param options The default {@link RequestOptions} for this instance.
|
|
3028
|
-
*/
|
|
3029
|
-
constructor(url = globalThis.location?.origin ?? "http://localhost", options = {}) {
|
|
3030
|
-
if (isObject(url)) {
|
|
3031
|
-
[url, options] = [globalThis.location?.origin ?? "http://localhost", url];
|
|
3032
|
-
}
|
|
3033
|
-
this._baseUrl = _Transportr.getBaseUrl(url);
|
|
3034
|
-
this._options = _Transportr.createOptions(options, _Transportr.defaultRequestOptions);
|
|
3035
|
-
this.subscribr = new Subscribr();
|
|
3036
|
-
}
|
|
3037
|
-
/** HTTP Media Types */
|
|
3038
|
-
static MediaType = HttpMediaType;
|
|
3039
|
-
/** HTTP Request Methods */
|
|
3040
|
-
static RequestMethod = HttpRequestMethod;
|
|
3041
|
-
/** HTTP Request Headers */
|
|
3042
|
-
static RequestHeader = HttpRequestHeader;
|
|
3043
|
-
/** HTTP Response Headers */
|
|
3044
|
-
static ResponseHeader = HttpResponseHeader;
|
|
3045
|
-
/** Request Caching Policy */
|
|
3046
|
-
static CachingPolicy = RequestCachingPolicy;
|
|
3047
|
-
/** Credentials Policy */
|
|
3048
|
-
static CredentialsPolicy = {
|
|
3049
|
-
INCLUDE: "include",
|
|
3050
|
-
OMIT: "omit",
|
|
3051
|
-
SAME_ORIGIN: "same-origin"
|
|
3052
|
-
};
|
|
3053
|
-
/** Request Modes */
|
|
3054
|
-
static RequestModes = {
|
|
3055
|
-
CORS: "cors",
|
|
3056
|
-
NAVIGATE: "navigate",
|
|
3057
|
-
NO_CORS: "no-cors",
|
|
3058
|
-
SAME_ORIGIN: "same-origin"
|
|
3059
|
-
};
|
|
3060
|
-
/** Request Priorities */
|
|
3061
|
-
static RequestPriorities = {
|
|
3062
|
-
HIGH: "high",
|
|
3063
|
-
LOW: "low",
|
|
3064
|
-
AUTO: "auto"
|
|
3065
|
-
};
|
|
3066
|
-
/** Redirect Policies */
|
|
3067
|
-
static RedirectPolicies = {
|
|
3068
|
-
ERROR: "error",
|
|
3069
|
-
FOLLOW: "follow",
|
|
3070
|
-
MANUAL: "manual"
|
|
3071
|
-
};
|
|
3072
|
-
/** Referrer Policies */
|
|
3073
|
-
static ReferrerPolicy = {
|
|
3074
|
-
NO_REFERRER: "no-referrer",
|
|
3075
|
-
NO_REFERRER_WHEN_DOWNGRADE: "no-referrer-when-downgrade",
|
|
3076
|
-
ORIGIN: "origin",
|
|
3077
|
-
ORIGIN_WHEN_CROSS_ORIGIN: "origin-when-cross-origin",
|
|
3078
|
-
SAME_ORIGIN: "same-origin",
|
|
3079
|
-
STRICT_ORIGIN: "strict-origin",
|
|
3080
|
-
STRICT_ORIGIN_WHEN_CROSS_ORIGIN: "strict-origin-when-cross-origin",
|
|
3081
|
-
UNSAFE_URL: "unsafe-url"
|
|
3082
|
-
};
|
|
3083
|
-
/** Request Events */
|
|
3084
|
-
static RequestEvents = RequestEvent;
|
|
3085
|
-
/** Default Request Options */
|
|
3086
|
-
static defaultRequestOptions = {
|
|
3087
|
-
body: void 0,
|
|
3088
|
-
cache: RequestCachingPolicy.NO_STORE,
|
|
3089
|
-
credentials: _Transportr.CredentialsPolicy.SAME_ORIGIN,
|
|
3090
|
-
headers: new Headers({ [HttpRequestHeader.CONTENT_TYPE]: defaultMediaType, [HttpRequestHeader.ACCEPT]: defaultMediaType }),
|
|
3091
|
-
searchParams: void 0,
|
|
3092
|
-
integrity: void 0,
|
|
3093
|
-
keepalive: void 0,
|
|
3094
|
-
method: HttpRequestMethod.GET,
|
|
3095
|
-
mode: _Transportr.RequestModes.CORS,
|
|
3096
|
-
priority: _Transportr.RequestPriorities.AUTO,
|
|
3097
|
-
redirect: _Transportr.RedirectPolicies.FOLLOW,
|
|
3098
|
-
referrer: "about:client",
|
|
3099
|
-
referrerPolicy: _Transportr.ReferrerPolicy.STRICT_ORIGIN_WHEN_CROSS_ORIGIN,
|
|
3100
|
-
signal: void 0,
|
|
3101
|
-
timeout: 3e4,
|
|
3102
|
-
global: true
|
|
3103
|
-
};
|
|
3104
|
-
/**
|
|
3105
|
-
* Returns a {@link EventRegistration} used for subscribing to global events.
|
|
3106
|
-
*
|
|
3107
|
-
* @param event The event to subscribe to.
|
|
3108
|
-
* @param handler The event handler.
|
|
3109
|
-
* @param context The context to bind the handler to.
|
|
3110
|
-
* @returns A new {@link EventRegistration} instance.
|
|
3111
|
-
*/
|
|
3112
|
-
static register(event, handler, context) {
|
|
3113
|
-
return _Transportr.globalSubscribr.subscribe(event, handler, context);
|
|
3114
|
-
}
|
|
3115
|
-
/**
|
|
3116
|
-
* Removes a {@link EventRegistration} from the global event handler.
|
|
3117
|
-
*
|
|
3118
|
-
* @param eventRegistration The {@link EventRegistration} to remove.
|
|
3119
|
-
* @returns True if the {@link EventRegistration} was removed, false otherwise.
|
|
3120
|
-
*/
|
|
3121
|
-
static unregister(eventRegistration) {
|
|
3122
|
-
return _Transportr.globalSubscribr.unsubscribe(eventRegistration);
|
|
3123
|
-
}
|
|
3124
|
-
/**
|
|
3125
|
-
* Aborts all active requests.
|
|
3126
|
-
* This is useful for when the user navigates away from the current page.
|
|
3127
|
-
* This will also clear the {@link Transportr#signalControllers} set.
|
|
3128
|
-
*/
|
|
3129
|
-
static abortAll() {
|
|
3130
|
-
for (const signalController of this.signalControllers) {
|
|
3131
|
-
signalController.abort(abortEvent());
|
|
3132
|
-
}
|
|
3133
|
-
this.signalControllers.clear();
|
|
3134
|
-
}
|
|
3135
|
-
/**
|
|
3136
|
-
* Registers a custom content-type response handler.
|
|
3137
|
-
* The handler will be matched against response content-type headers using MediaType matching.
|
|
3138
|
-
* New handlers are prepended so they take priority over built-in handlers.
|
|
3139
|
-
*
|
|
3140
|
-
* @param contentType The content-type string to match (e.g. 'application/pdf', 'text', 'csv').
|
|
3141
|
-
* @param handler The response handler function.
|
|
3142
|
-
*/
|
|
3143
|
-
static registerContentTypeHandler(contentType, handler) {
|
|
3144
|
-
_Transportr.contentTypeHandlers.unshift([contentType, handler]);
|
|
3145
|
-
}
|
|
3146
|
-
/**
|
|
3147
|
-
* Removes a previously registered content-type response handler.
|
|
3148
|
-
*
|
|
3149
|
-
* @param contentType The content-type string to remove.
|
|
3150
|
-
* @returns True if the handler was found and removed, false otherwise.
|
|
3151
|
-
*/
|
|
3152
|
-
static unregisterContentTypeHandler(contentType) {
|
|
3153
|
-
const index = _Transportr.contentTypeHandlers.findIndex(([type]) => type === contentType);
|
|
3154
|
-
if (index === -1) {
|
|
3155
|
-
return false;
|
|
3156
|
-
}
|
|
3157
|
-
_Transportr.contentTypeHandlers.splice(index, 1);
|
|
3158
|
-
return true;
|
|
3159
|
-
}
|
|
3160
|
-
/**
|
|
3161
|
-
* Registers global lifecycle hooks that run on all requests from all instances.
|
|
3162
|
-
* Global hooks execute before instance and per-request hooks.
|
|
3163
|
-
*
|
|
3164
|
-
* @param hooks The hooks to register globally.
|
|
3165
|
-
*/
|
|
3166
|
-
static addHooks(hooks) {
|
|
3167
|
-
if (hooks.beforeRequest) {
|
|
3168
|
-
_Transportr.globalHooks.beforeRequest.push(...hooks.beforeRequest);
|
|
3169
|
-
}
|
|
3170
|
-
if (hooks.afterResponse) {
|
|
3171
|
-
_Transportr.globalHooks.afterResponse.push(...hooks.afterResponse);
|
|
3172
|
-
}
|
|
3173
|
-
if (hooks.beforeError) {
|
|
3174
|
-
_Transportr.globalHooks.beforeError.push(...hooks.beforeError);
|
|
3175
|
-
}
|
|
3176
|
-
}
|
|
3177
|
-
/**
|
|
3178
|
-
* Removes all global lifecycle hooks.
|
|
3179
|
-
*/
|
|
3180
|
-
static clearHooks() {
|
|
3181
|
-
_Transportr.globalHooks = { beforeRequest: [], afterResponse: [], beforeError: [] };
|
|
3182
|
-
}
|
|
3183
|
-
/**
|
|
3184
|
-
* Tears down all global state: aborts in-flight requests, clears global event subscriptions,
|
|
3185
|
-
* hooks, in-flight deduplication map, and media type cache (retaining built-in entries).
|
|
3186
|
-
*/
|
|
3187
|
-
static unregisterAll() {
|
|
3188
|
-
_Transportr.abortAll();
|
|
3189
|
-
_Transportr.globalSubscribr = new Subscribr();
|
|
3190
|
-
_Transportr.clearHooks();
|
|
3191
|
-
_Transportr.inflightRequests.clear();
|
|
3192
|
-
}
|
|
3193
|
-
/**
|
|
3194
|
-
* It returns the base {@link URL} for the API.
|
|
3195
|
-
*
|
|
3196
|
-
* @returns The baseUrl property.
|
|
3197
|
-
*/
|
|
3198
|
-
get baseUrl() {
|
|
3199
|
-
return this._baseUrl;
|
|
3200
|
-
}
|
|
3201
|
-
/**
|
|
3202
|
-
* Registers an event handler with a {@link Transportr} instance.
|
|
3203
|
-
*
|
|
3204
|
-
* @param event The name of the event to listen for.
|
|
3205
|
-
* @param handler The function to call when the event is triggered.
|
|
3206
|
-
* @param context The context to bind to the handler.
|
|
3207
|
-
* @returns An object that can be used to remove the event handler.
|
|
3208
|
-
*/
|
|
3209
|
-
register(event, handler, context) {
|
|
3210
|
-
return this.subscribr.subscribe(event, handler, context);
|
|
3211
|
-
}
|
|
3212
|
-
/**
|
|
3213
|
-
* Unregisters an event handler from a {@link Transportr} instance.
|
|
3214
|
-
*
|
|
3215
|
-
* @param eventRegistration The event registration to remove.
|
|
3216
|
-
* @returns True if the {@link EventRegistration} was removed, false otherwise.
|
|
3217
|
-
*/
|
|
3218
|
-
unregister(eventRegistration) {
|
|
3219
|
-
return this.subscribr.unsubscribe(eventRegistration);
|
|
3220
|
-
}
|
|
3221
|
-
/**
|
|
3222
|
-
* Registers instance-level lifecycle hooks that run on all requests from this instance.
|
|
3223
|
-
* Instance hooks execute after global hooks but before per-request hooks.
|
|
3224
|
-
*
|
|
3225
|
-
* @param hooks The hooks to register on this instance.
|
|
3226
|
-
* @returns This instance for method chaining.
|
|
3227
|
-
*/
|
|
3228
|
-
addHooks(hooks) {
|
|
3229
|
-
if (hooks.beforeRequest) {
|
|
3230
|
-
this.hooks.beforeRequest.push(...hooks.beforeRequest);
|
|
3231
|
-
}
|
|
3232
|
-
if (hooks.afterResponse) {
|
|
3233
|
-
this.hooks.afterResponse.push(...hooks.afterResponse);
|
|
3234
|
-
}
|
|
3235
|
-
if (hooks.beforeError) {
|
|
3236
|
-
this.hooks.beforeError.push(...hooks.beforeError);
|
|
3237
|
-
}
|
|
3238
|
-
return this;
|
|
3239
|
-
}
|
|
3240
|
-
/**
|
|
3241
|
-
* Removes all instance-level lifecycle hooks.
|
|
3242
|
-
* @returns This instance for method chaining.
|
|
3243
|
-
*/
|
|
3244
|
-
clearHooks() {
|
|
3245
|
-
this.hooks.beforeRequest.length = 0;
|
|
3246
|
-
this.hooks.afterResponse.length = 0;
|
|
3247
|
-
this.hooks.beforeError.length = 0;
|
|
3248
|
-
return this;
|
|
3249
|
-
}
|
|
3250
|
-
/**
|
|
3251
|
-
* Tears down this instance: clears all instance subscriptions and hooks.
|
|
3252
|
-
* The instance should not be used after calling this method.
|
|
3253
|
-
*/
|
|
3254
|
-
destroy() {
|
|
3255
|
-
this.clearHooks();
|
|
3256
|
-
this.subscribr.destroy();
|
|
3257
|
-
}
|
|
3258
|
-
/**
|
|
3259
|
-
* This function returns a promise that resolves to the result of a request to the specified path with
|
|
3260
|
-
* the specified options, where the method is GET.
|
|
3261
|
-
*
|
|
3262
|
-
* @async
|
|
3263
|
-
* @param path The path to the resource you want to get.
|
|
3264
|
-
* @param options The options for the request.
|
|
3265
|
-
* @returns A promise that resolves to the response of the request.
|
|
3266
|
-
*/
|
|
3267
|
-
async get(path, options) {
|
|
3268
|
-
return this._get(path, options);
|
|
3269
|
-
}
|
|
3270
|
-
/**
|
|
3271
|
-
* This function makes a POST request to the given path with the given body and options.
|
|
3272
|
-
*
|
|
3273
|
-
* @async
|
|
3274
|
-
* @template T The expected response type (defaults to ResponseBody)
|
|
3275
|
-
* @param path The path to the endpoint you want to call.
|
|
3276
|
-
* @param options The options for the request.
|
|
3277
|
-
* @returns A promise that resolves to the response body.
|
|
3278
|
-
*/
|
|
3279
|
-
async post(path, options) {
|
|
3280
|
-
if (typeof path !== "string") {
|
|
3281
|
-
[path, options] = [void 0, path];
|
|
3282
|
-
}
|
|
3283
|
-
return this.execute(path, options, { method: HttpRequestMethod.POST });
|
|
3284
|
-
}
|
|
3285
|
-
/**
|
|
3286
|
-
* This function returns a promise that resolves to the result of a request to the specified path with
|
|
3287
|
-
* the specified options, where the method is PUT.
|
|
3288
|
-
*
|
|
3289
|
-
* @async
|
|
3290
|
-
* @template T The expected response type (defaults to ResponseBody)
|
|
3291
|
-
* @param path The path to the endpoint you want to call.
|
|
3292
|
-
* @param options The options for the request.
|
|
3293
|
-
* @returns The return value of the #request method.
|
|
3294
|
-
*/
|
|
3295
|
-
async put(path, options) {
|
|
3296
|
-
return this.execute(path, options, { method: HttpRequestMethod.PUT });
|
|
3297
|
-
}
|
|
3298
|
-
/**
|
|
3299
|
-
* It takes a path and options, and returns a request with the method set to PATCH.
|
|
3300
|
-
*
|
|
3301
|
-
* @async
|
|
3302
|
-
* @template T The expected response type (defaults to ResponseBody)
|
|
3303
|
-
* @param path The path to the endpoint you want to hit.
|
|
3304
|
-
* @param options The options for the request.
|
|
3305
|
-
* @returns A promise that resolves to the response of the request.
|
|
3306
|
-
*/
|
|
3307
|
-
async patch(path, options) {
|
|
3308
|
-
return this.execute(path, options, { method: HttpRequestMethod.PATCH });
|
|
3309
|
-
}
|
|
3310
|
-
/**
|
|
3311
|
-
* It takes a path and options, and returns a request with the method set to DELETE.
|
|
3312
|
-
*
|
|
3313
|
-
* @async
|
|
3314
|
-
* @param path The path to the resource you want to access.
|
|
3315
|
-
* @param options The options for the request.
|
|
3316
|
-
* @returns The result of the request.
|
|
3317
|
-
*/
|
|
3318
|
-
async delete(path, options) {
|
|
3319
|
-
return this.execute(path, options, { method: HttpRequestMethod.DELETE });
|
|
3320
|
-
}
|
|
3321
|
-
/**
|
|
3322
|
-
* Returns the response headers of a request to the given path.
|
|
3323
|
-
*
|
|
3324
|
-
* @async
|
|
3325
|
-
* @param path The path to the resource you want to access.
|
|
3326
|
-
* @param options The options for the request.
|
|
3327
|
-
* @returns A promise that resolves to the response object.
|
|
3328
|
-
*/
|
|
3329
|
-
async head(path, options) {
|
|
3330
|
-
return this.execute(path, options, { method: HttpRequestMethod.HEAD });
|
|
3331
|
-
}
|
|
3332
|
-
/**
|
|
3333
|
-
* It returns a promise that resolves to the allowed request methods for the given resource path.
|
|
3334
|
-
*
|
|
3335
|
-
* @async
|
|
3336
|
-
* @param path The path to the resource.
|
|
3337
|
-
* @param options The options for the request.
|
|
3338
|
-
* @returns A promise that resolves to an array of allowed request methods for this resource.
|
|
3339
|
-
*/
|
|
3340
|
-
async options(path, options = {}) {
|
|
3341
|
-
if (isObject(path)) {
|
|
3342
|
-
[path, options] = [void 0, path];
|
|
3343
|
-
}
|
|
3344
|
-
const requestConfig = this.processRequestOptions(options, { method: HttpRequestMethod.OPTIONS });
|
|
3345
|
-
const { requestOptions } = requestConfig;
|
|
3346
|
-
const requestHooks = requestOptions.hooks;
|
|
3347
|
-
let url = _Transportr.createUrl(this._baseUrl, path, requestOptions.searchParams);
|
|
3348
|
-
const beforeRequestHookSets = [_Transportr.globalHooks.beforeRequest, this.hooks.beforeRequest, requestHooks?.beforeRequest];
|
|
3349
|
-
for (const hooks of beforeRequestHookSets) {
|
|
3350
|
-
if (!hooks) {
|
|
3351
|
-
continue;
|
|
3352
|
-
}
|
|
3353
|
-
for (const hook of hooks) {
|
|
3354
|
-
const result = await hook(requestOptions, url);
|
|
3355
|
-
if (result) {
|
|
3356
|
-
Object.assign(requestOptions, result);
|
|
3357
|
-
if (result.searchParams !== void 0) {
|
|
3358
|
-
url = _Transportr.createUrl(this._baseUrl, path, requestOptions.searchParams);
|
|
3359
|
-
}
|
|
3360
|
-
}
|
|
3361
|
-
}
|
|
3362
|
-
}
|
|
3363
|
-
let response = await this._request(path, requestConfig);
|
|
3364
|
-
const afterResponseHookSets = [_Transportr.globalHooks.afterResponse, this.hooks.afterResponse, requestHooks?.afterResponse];
|
|
3365
|
-
for (const hooks of afterResponseHookSets) {
|
|
3366
|
-
if (!hooks) {
|
|
3367
|
-
continue;
|
|
3368
|
-
}
|
|
3369
|
-
for (const hook of hooks) {
|
|
3370
|
-
const result = await hook(response, requestOptions);
|
|
3371
|
-
if (result) {
|
|
3372
|
-
response = result;
|
|
3373
|
-
}
|
|
3374
|
-
}
|
|
3375
|
-
}
|
|
3376
|
-
const allowedMethods = response.headers.get("allow")?.split(",").map((method) => method.trim());
|
|
3377
|
-
this.publish({ name: RequestEvent.SUCCESS, data: allowedMethods, global: options.global });
|
|
3378
|
-
return allowedMethods;
|
|
3379
|
-
}
|
|
3380
|
-
/**
|
|
3381
|
-
* It takes a path and options, and makes a request to the server
|
|
3382
|
-
* @async
|
|
3383
|
-
* @param path The path to the endpoint you want to hit.
|
|
3384
|
-
* @param options The options for the request.
|
|
3385
|
-
* @returns The return value of the function is the return value of the function that is passed to the `then` method of the promise returned by the `fetch` method.
|
|
3386
|
-
* @throws {HttpError} If an error occurs during the request.
|
|
3387
|
-
*/
|
|
3388
|
-
async request(path, options = {}) {
|
|
3389
|
-
if (isObject(path)) {
|
|
3390
|
-
[path, options] = [void 0, path];
|
|
3391
|
-
}
|
|
3392
|
-
const response = await this._request(path, this.processRequestOptions(options, {}));
|
|
3393
|
-
this.publish({ name: RequestEvent.SUCCESS, data: response, global: options.global });
|
|
3394
|
-
return response;
|
|
3395
|
-
}
|
|
3396
|
-
/**
|
|
3397
|
-
* It gets the JSON representation of the resource at the given path.
|
|
3398
|
-
*
|
|
3399
|
-
* @async
|
|
3400
|
-
* @template T The expected JSON response type (defaults to JsonObject)
|
|
3401
|
-
* @param path The path to the resource.
|
|
3402
|
-
* @param options The options object to pass to the request.
|
|
3403
|
-
* @returns A promise that resolves to the response body as a typed JSON value.
|
|
3404
|
-
*/
|
|
3405
|
-
async getJson(path, options) {
|
|
3406
|
-
return this._get(path, options, { headers: { [HttpRequestHeader.ACCEPT]: `${mediaTypes.JSON}` } }, handleJson);
|
|
3407
|
-
}
|
|
3408
|
-
/**
|
|
3409
|
-
* It gets the XML representation of the resource at the given path.
|
|
3410
|
-
*
|
|
3411
|
-
* @async
|
|
3412
|
-
* @param path The path to the resource you want to get.
|
|
3413
|
-
* @param options The options for the request.
|
|
3414
|
-
* @returns The result of the function call to #get.
|
|
3415
|
-
*/
|
|
3416
|
-
async getXml(path, options) {
|
|
3417
|
-
return this._get(path, options, { headers: { [HttpRequestHeader.ACCEPT]: `${mediaTypes.XML}` } }, handleXml);
|
|
3418
|
-
}
|
|
3419
|
-
/**
|
|
3420
|
-
* Get the HTML content of the specified path.
|
|
3421
|
-
* When a selector is provided, returns only the first matching element from the parsed document.
|
|
3422
|
-
*
|
|
3423
|
-
* @async
|
|
3424
|
-
* @param path The path to the resource.
|
|
3425
|
-
* @param options The options for the request.
|
|
3426
|
-
* @param selector An optional CSS selector to extract a specific element from the parsed HTML.
|
|
3427
|
-
* @returns A promise that resolves to a Document, an Element (if selector matched), or void.
|
|
3428
|
-
*/
|
|
3429
|
-
async getHtml(path, options, selector) {
|
|
3430
|
-
const doc = await this._get(path, options, { headers: { [HttpRequestHeader.ACCEPT]: `${mediaTypes.HTML}` } }, handleHtml);
|
|
3431
|
-
return selector && doc ? doc.querySelector(selector) : doc;
|
|
3432
|
-
}
|
|
3433
|
-
/**
|
|
3434
|
-
* It returns a promise that resolves to the HTML fragment at the given path.
|
|
3435
|
-
* When a selector is provided, returns only the first matching element from the parsed fragment.
|
|
3436
|
-
*
|
|
3437
|
-
* @async
|
|
3438
|
-
* @param path The path to the resource.
|
|
3439
|
-
* @param options The options for the request.
|
|
3440
|
-
* @param selector An optional CSS selector to extract a specific element from the parsed fragment.
|
|
3441
|
-
* @returns A promise that resolves to a DocumentFragment, an Element (if selector matched), or void.
|
|
3442
|
-
*/
|
|
3443
|
-
async getHtmlFragment(path, options, selector) {
|
|
3444
|
-
const fragment = await this._get(path, options, { headers: { [HttpRequestHeader.ACCEPT]: `${mediaTypes.HTML}` } }, handleHtmlFragment);
|
|
3445
|
-
return selector && fragment ? fragment.querySelector(selector) : fragment;
|
|
3446
|
-
}
|
|
3447
|
-
/**
|
|
3448
|
-
* It gets a script from the server, and appends the script to the Document HTMLHeadElement
|
|
3449
|
-
* @param path The path to the script.
|
|
3450
|
-
* @param options The options for the request.
|
|
3451
|
-
* @returns A promise that resolves to void.
|
|
3452
|
-
*/
|
|
3453
|
-
async getScript(path, options) {
|
|
3454
|
-
return this._get(path, options, { headers: { [HttpRequestHeader.ACCEPT]: `${mediaTypes.JAVA_SCRIPT}` } }, handleScript);
|
|
3455
|
-
}
|
|
3456
|
-
/**
|
|
3457
|
-
* Gets a stylesheet from the server, and adds it as a Blob URL.
|
|
3458
|
-
* @param path The path to the stylesheet.
|
|
3459
|
-
* @param options The options for the request.
|
|
3460
|
-
* @returns A promise that resolves to void.
|
|
3461
|
-
*/
|
|
3462
|
-
async getStylesheet(path, options) {
|
|
3463
|
-
return this._get(path, options, { headers: { [HttpRequestHeader.ACCEPT]: `${mediaTypes.CSS}` } }, handleCss);
|
|
3464
|
-
}
|
|
3465
|
-
/**
|
|
3466
|
-
* It returns a blob from the specified path.
|
|
3467
|
-
* @param path The path to the resource.
|
|
3468
|
-
* @param options The options for the request.
|
|
3469
|
-
* @returns A promise that resolves to a Blob or void.
|
|
3470
|
-
*/
|
|
3471
|
-
async getBlob(path, options) {
|
|
3472
|
-
return this._get(path, options, { headers: { [HttpRequestHeader.ACCEPT]: HttpMediaType.BIN } }, handleBlob);
|
|
3473
|
-
}
|
|
3474
|
-
/**
|
|
3475
|
-
* It returns a promise that resolves to an `HTMLImageElement`.
|
|
3476
|
-
* The object URL created to load the image is automatically revoked to prevent memory leaks.
|
|
3477
|
-
* Works in both browser and Node.js (via JSDOM) environments.
|
|
3478
|
-
* @param path The path to the image.
|
|
3479
|
-
* @param options The options for the request.
|
|
3480
|
-
* @returns A promise that resolves to an `HTMLImageElement` or `void`.
|
|
3481
|
-
*/
|
|
3482
|
-
async getImage(path, options) {
|
|
3483
|
-
return this._get(path, options, { headers: { [HttpRequestHeader.ACCEPT]: "image/*" } }, handleImage);
|
|
3484
|
-
}
|
|
3485
|
-
/**
|
|
3486
|
-
* It gets a buffer from the specified path
|
|
3487
|
-
* @param path The path to the resource.
|
|
3488
|
-
* @param options The options for the request.
|
|
3489
|
-
* @returns A promise that resolves to an ArrayBuffer or void.
|
|
3490
|
-
*/
|
|
3491
|
-
async getBuffer(path, options) {
|
|
3492
|
-
return this._get(path, options, { headers: { [HttpRequestHeader.ACCEPT]: HttpMediaType.BIN } }, handleBuffer);
|
|
3493
|
-
}
|
|
3494
|
-
/**
|
|
3495
|
-
* It returns a readable stream of the response body from the specified path.
|
|
3496
|
-
* @param path The path to the resource.
|
|
3497
|
-
* @param options The options for the request.
|
|
3498
|
-
* @returns A promise that resolves to a ReadableStream, null, or void.
|
|
3499
|
-
*/
|
|
3500
|
-
async getStream(path, options) {
|
|
3501
|
-
return this._get(path, options, { headers: { [HttpRequestHeader.ACCEPT]: HttpMediaType.BIN } }, handleReadableStream);
|
|
3502
|
-
}
|
|
3503
|
-
/**
|
|
3504
|
-
* Handles a GET request.
|
|
3505
|
-
* @async
|
|
3506
|
-
* @param path The path to the resource.
|
|
3507
|
-
* @param userOptions The user options for the request.
|
|
3508
|
-
* @param options The options for the request.
|
|
3509
|
-
* @param responseHandler The response handler for the request.
|
|
3510
|
-
* @returns A promise that resolves to the response body or void.
|
|
3511
|
-
*/
|
|
3512
|
-
async _get(path, userOptions, options = {}, responseHandler) {
|
|
3513
|
-
return this.execute(path, userOptions, { ...options, method: HttpRequestMethod.GET, body: void 0 }, responseHandler);
|
|
3514
|
-
}
|
|
3515
|
-
/**
|
|
3516
|
-
* It processes the request options and returns a new object with the processed options.
|
|
3517
|
-
* @param path The path to the resource.
|
|
3518
|
-
* @param processedRequestOptions The user options for the request.
|
|
3519
|
-
* @returns A new object with the processed options.
|
|
3520
|
-
*/
|
|
3521
|
-
async _request(path, { signalController, requestOptions, global }) {
|
|
3522
|
-
_Transportr.signalControllers.add(signalController);
|
|
3523
|
-
const retryConfig = _Transportr.normalizeRetryOptions(requestOptions.retry);
|
|
3524
|
-
const method = requestOptions.method ?? "GET";
|
|
3525
|
-
const canRetry = retryConfig.limit > 0 && retryConfig.methods.includes(method);
|
|
3526
|
-
const canDedupe = requestOptions.dedupe === true && (method === "GET" || method === "HEAD");
|
|
3527
|
-
let attempt = 0;
|
|
3528
|
-
const startTime = performance.now();
|
|
3529
|
-
const getTiming = () => {
|
|
3530
|
-
const end = performance.now();
|
|
3531
|
-
return { start: startTime, end, duration: end - startTime };
|
|
3532
|
-
};
|
|
3533
|
-
try {
|
|
3534
|
-
const url = _Transportr.createUrl(this._baseUrl, path, requestOptions.searchParams);
|
|
3535
|
-
const dedupeKey = canDedupe ? `${method}:${url.href}` : "";
|
|
3536
|
-
if (canDedupe) {
|
|
3537
|
-
const inflight = _Transportr.inflightRequests.get(dedupeKey);
|
|
3538
|
-
if (inflight) {
|
|
3539
|
-
return (await inflight).clone();
|
|
3540
|
-
}
|
|
3541
|
-
}
|
|
3542
|
-
const doFetch = async () => {
|
|
3543
|
-
while (true) {
|
|
3544
|
-
try {
|
|
3545
|
-
const response = await fetch(url, requestOptions);
|
|
3546
|
-
if (!response.ok) {
|
|
3547
|
-
if (canRetry && attempt < retryConfig.limit && retryConfig.statusCodes.includes(response.status)) {
|
|
3548
|
-
attempt++;
|
|
3549
|
-
this.publish({ name: RequestEvent.RETRY, data: { attempt, status: response.status, method, path, timing: getTiming() }, global });
|
|
3550
|
-
await _Transportr.retryDelay(retryConfig, attempt);
|
|
3551
|
-
continue;
|
|
3552
|
-
}
|
|
3553
|
-
let entity;
|
|
3554
|
-
try {
|
|
3555
|
-
entity = await response.text();
|
|
3556
|
-
} catch {
|
|
3557
|
-
}
|
|
3558
|
-
throw await this.handleError(path, response, { entity, url, method, timing: getTiming() }, requestOptions);
|
|
3559
|
-
}
|
|
3560
|
-
return response;
|
|
3561
|
-
} catch (cause) {
|
|
3562
|
-
if (cause instanceof HttpError) {
|
|
3563
|
-
throw cause;
|
|
3564
|
-
}
|
|
3565
|
-
if (canRetry && attempt < retryConfig.limit) {
|
|
3566
|
-
attempt++;
|
|
3567
|
-
this.publish({ name: RequestEvent.RETRY, data: { attempt, error: cause.message, method, path, timing: getTiming() }, global });
|
|
3568
|
-
await _Transportr.retryDelay(retryConfig, attempt);
|
|
3569
|
-
continue;
|
|
3570
|
-
}
|
|
3571
|
-
throw await this.handleError(path, void 0, { cause, url, method, timing: getTiming() }, requestOptions);
|
|
3572
|
-
}
|
|
3573
|
-
}
|
|
3574
|
-
};
|
|
3575
|
-
if (canDedupe) {
|
|
3576
|
-
const promise = doFetch();
|
|
3577
|
-
_Transportr.inflightRequests.set(dedupeKey, promise);
|
|
3578
|
-
try {
|
|
3579
|
-
const response = await promise;
|
|
3580
|
-
return response;
|
|
3581
|
-
} finally {
|
|
3582
|
-
_Transportr.inflightRequests.delete(dedupeKey);
|
|
3583
|
-
}
|
|
3584
|
-
}
|
|
3585
|
-
return await doFetch();
|
|
3586
|
-
} finally {
|
|
3587
|
-
_Transportr.signalControllers.delete(signalController.destroy());
|
|
3588
|
-
if (!requestOptions.signal?.aborted) {
|
|
3589
|
-
const timing = getTiming();
|
|
3590
|
-
this.publish({ name: RequestEvent.COMPLETE, data: { timing }, global });
|
|
3591
|
-
if (_Transportr.signalControllers.size === 0) {
|
|
3592
|
-
this.publish({ name: RequestEvent.ALL_COMPLETE, global });
|
|
3593
|
-
}
|
|
3594
|
-
}
|
|
3595
|
-
}
|
|
3596
|
-
}
|
|
3597
|
-
/**
|
|
3598
|
-
* Normalizes a retry option into a full RetryOptions object.
|
|
3599
|
-
* @param retry The retry option from request options.
|
|
3600
|
-
* @returns Normalized retry configuration.
|
|
3601
|
-
*/
|
|
3602
|
-
static normalizeRetryOptions(retry) {
|
|
3603
|
-
if (retry === void 0) {
|
|
3604
|
-
return { limit: 0, statusCodes: [], methods: [], delay: retryDelay, backoffFactor: retryBackoffFactor };
|
|
3605
|
-
}
|
|
3606
|
-
if (typeof retry === "number") {
|
|
3607
|
-
return { limit: retry, statusCodes: [...retryStatusCodes], methods: [...retryMethods], delay: retryDelay, backoffFactor: retryBackoffFactor };
|
|
3608
|
-
}
|
|
3609
|
-
return {
|
|
3610
|
-
limit: retry.limit ?? 0,
|
|
3611
|
-
statusCodes: retry.statusCodes ?? [...retryStatusCodes],
|
|
3612
|
-
methods: retry.methods ?? [...retryMethods],
|
|
3613
|
-
delay: retry.delay ?? retryDelay,
|
|
3614
|
-
backoffFactor: retry.backoffFactor ?? retryBackoffFactor
|
|
3615
|
-
};
|
|
3616
|
-
}
|
|
3617
|
-
/**
|
|
3618
|
-
* Waits for the appropriate delay before a retry attempt.
|
|
3619
|
-
* @param config The retry configuration.
|
|
3620
|
-
* @param attempt The current attempt number (1-based).
|
|
3621
|
-
* @returns A promise that resolves after the delay.
|
|
3622
|
-
*/
|
|
3623
|
-
static retryDelay(config, attempt) {
|
|
3624
|
-
const ms = typeof config.delay === "function" ? config.delay(attempt) : config.delay * config.backoffFactor ** (attempt - 1);
|
|
3625
|
-
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
3626
|
-
}
|
|
3627
|
-
/**
|
|
3628
|
-
* It returns a response handler based on the content type of the response.
|
|
3629
|
-
* @param path The path to the resource.
|
|
3630
|
-
* @param userOptions The user options for the request.
|
|
3631
|
-
* @param options The options for the request.
|
|
3632
|
-
* @param responseHandler The response handler for the request.
|
|
3633
|
-
* @returns A response handler function.
|
|
3634
|
-
*/
|
|
3635
|
-
async execute(path, userOptions = {}, options = {}, responseHandler) {
|
|
3636
|
-
if (isObject(path)) {
|
|
3637
|
-
[path, userOptions] = [void 0, path];
|
|
3638
|
-
}
|
|
3639
|
-
const requestConfig = this.processRequestOptions(userOptions, options);
|
|
3640
|
-
const { requestOptions } = requestConfig;
|
|
3641
|
-
const requestHooks = requestOptions.hooks;
|
|
3642
|
-
let url = _Transportr.createUrl(this._baseUrl, path, requestOptions.searchParams);
|
|
3643
|
-
const beforeRequestHookSets = [_Transportr.globalHooks.beforeRequest, this.hooks.beforeRequest, requestHooks?.beforeRequest];
|
|
3644
|
-
for (const hooks of beforeRequestHookSets) {
|
|
3645
|
-
if (!hooks) {
|
|
3646
|
-
continue;
|
|
3647
|
-
}
|
|
3648
|
-
for (const hook of hooks) {
|
|
3649
|
-
const result = await hook(requestOptions, url);
|
|
3650
|
-
if (result) {
|
|
3651
|
-
Object.assign(requestOptions, result);
|
|
3652
|
-
if (result.searchParams !== void 0) {
|
|
3653
|
-
url = _Transportr.createUrl(this._baseUrl, path, requestOptions.searchParams);
|
|
3654
|
-
}
|
|
3655
|
-
}
|
|
3656
|
-
}
|
|
3657
|
-
}
|
|
3658
|
-
let response = await this._request(path, requestConfig);
|
|
3659
|
-
const afterResponseHookSets = [_Transportr.globalHooks.afterResponse, this.hooks.afterResponse, requestHooks?.afterResponse];
|
|
3660
|
-
for (const hooks of afterResponseHookSets) {
|
|
3661
|
-
if (!hooks) {
|
|
3662
|
-
continue;
|
|
3663
|
-
}
|
|
3664
|
-
for (const hook of hooks) {
|
|
3665
|
-
const result = await hook(response, requestOptions);
|
|
3666
|
-
if (result) {
|
|
3667
|
-
response = result;
|
|
3668
|
-
}
|
|
3669
|
-
}
|
|
3670
|
-
}
|
|
3671
|
-
try {
|
|
3672
|
-
if (!responseHandler && response.status !== 204) {
|
|
3673
|
-
responseHandler = this.getResponseHandler(response.headers.get(HttpResponseHeader.CONTENT_TYPE));
|
|
3674
|
-
}
|
|
3675
|
-
const data = await responseHandler?.(response);
|
|
3676
|
-
this.publish({ name: RequestEvent.SUCCESS, data, global: requestConfig.global });
|
|
3677
|
-
return data;
|
|
3678
|
-
} catch (cause) {
|
|
3679
|
-
throw await this.handleError(path, response, { cause }, requestOptions);
|
|
3680
|
-
}
|
|
3681
|
-
}
|
|
3682
|
-
/**
|
|
3683
|
-
* Creates a new set of options for a request.
|
|
3684
|
-
* @param options The user options for the request.
|
|
3685
|
-
* @param userOptions The default options for the request.
|
|
3686
|
-
* @returns A new set of options for the request.
|
|
3687
|
-
*/
|
|
3688
|
-
static createOptions({ headers: userHeaders, searchParams: userSearchParams, ...userOptions }, { headers, searchParams, ...options }) {
|
|
3689
|
-
headers = _Transportr.mergeHeaders(new Headers(), userHeaders, headers);
|
|
3690
|
-
searchParams = _Transportr.mergeSearchParams(new URLSearchParams(), userSearchParams, searchParams);
|
|
3691
|
-
return { ...objectMerge(options, userOptions) ?? {}, headers, searchParams };
|
|
3692
|
-
}
|
|
3693
|
-
/**
|
|
3694
|
-
* Merges user and request headers into the target Headers object.
|
|
3695
|
-
* @param target The target Headers object.
|
|
3696
|
-
* @param headerSources Variable number of header sources to merge.
|
|
3697
|
-
* @returns The merged Headers object.
|
|
3698
|
-
*/
|
|
3699
|
-
static mergeHeaders(target, ...headerSources) {
|
|
3700
|
-
for (const headers of headerSources) {
|
|
3701
|
-
if (headers === void 0) {
|
|
3702
|
-
continue;
|
|
3703
|
-
}
|
|
3704
|
-
if (headers instanceof Headers) {
|
|
3705
|
-
headers.forEach((value, name) => target.set(name, value));
|
|
3706
|
-
} else if (Array.isArray(headers)) {
|
|
3707
|
-
for (const [name, value] of headers) {
|
|
3708
|
-
target.set(name, value);
|
|
3709
|
-
}
|
|
3710
|
-
} else {
|
|
3711
|
-
const record = headers;
|
|
3712
|
-
const keys = Object.keys(record);
|
|
3713
|
-
for (let i = 0; i < keys.length; i++) {
|
|
3714
|
-
const name = keys[i];
|
|
3715
|
-
const value = record[name];
|
|
3716
|
-
if (value !== void 0) {
|
|
3717
|
-
target.set(name, String(value));
|
|
3718
|
-
}
|
|
3719
|
-
}
|
|
3720
|
-
}
|
|
3721
|
-
}
|
|
3722
|
-
return target;
|
|
3723
|
-
}
|
|
3724
|
-
/**
|
|
3725
|
-
* Merges user and request search parameters into the target URLSearchParams object.
|
|
3726
|
-
* @param target The target URLSearchParams object.
|
|
3727
|
-
* @param sources The search parameters to merge.
|
|
3728
|
-
* @returns The merged URLSearchParams object.
|
|
3729
|
-
*/
|
|
3730
|
-
static mergeSearchParams(target, ...sources) {
|
|
3731
|
-
for (const searchParams of sources) {
|
|
3732
|
-
if (searchParams === void 0) {
|
|
3733
|
-
continue;
|
|
3734
|
-
}
|
|
3735
|
-
if (searchParams instanceof URLSearchParams) {
|
|
3736
|
-
searchParams.forEach((value, name) => target.set(name, value));
|
|
3737
|
-
} else if (isString(searchParams) || Array.isArray(searchParams)) {
|
|
3738
|
-
for (const [name, value] of new URLSearchParams(searchParams)) {
|
|
3739
|
-
target.set(name, value);
|
|
3740
|
-
}
|
|
3741
|
-
} else {
|
|
3742
|
-
const keys = Object.keys(searchParams);
|
|
3743
|
-
for (let i = 0; i < keys.length; i++) {
|
|
3744
|
-
const name = keys[i];
|
|
3745
|
-
const value = searchParams[name];
|
|
3746
|
-
if (value !== void 0) {
|
|
3747
|
-
target.set(name, String(value));
|
|
3748
|
-
}
|
|
3749
|
-
}
|
|
3750
|
-
}
|
|
3751
|
-
}
|
|
3752
|
-
return target;
|
|
3753
|
-
}
|
|
3754
|
-
/**
|
|
3755
|
-
* Processes request options by merging user, instance, and method-specific options.
|
|
3756
|
-
* This method optimizes performance by using cached instance options and performing
|
|
3757
|
-
* shallow merges where possible instead of deep object cloning.
|
|
3758
|
-
* @param userOptions The user-provided options for the request.
|
|
3759
|
-
* @param options Additional method-specific options.
|
|
3760
|
-
* @returns Processed request options with signal controller and global flag.
|
|
3761
|
-
*/
|
|
3762
|
-
processRequestOptions({ body: userBody, headers: userHeaders, searchParams: userSearchParams, ...userOptions }, { headers, searchParams, ...options }) {
|
|
3763
|
-
const requestOptions = {
|
|
3764
|
-
// Spread instance options (already merged with defaults)
|
|
3765
|
-
...this._options,
|
|
3766
|
-
// Spread user options (shallow merge, sufficient for flat properties)
|
|
3767
|
-
...userOptions,
|
|
3768
|
-
// Spread method-specific options (e.g., method: 'POST')
|
|
3769
|
-
...options,
|
|
3770
|
-
// Deep merge required for headers and searchParams
|
|
3771
|
-
headers: _Transportr.mergeHeaders(new Headers(), this._options.headers, userHeaders, headers),
|
|
3772
|
-
searchParams: _Transportr.mergeSearchParams(new URLSearchParams(), this._options.searchParams, userSearchParams, searchParams)
|
|
3773
|
-
};
|
|
3774
|
-
if (isRequestBodyMethod(requestOptions.method)) {
|
|
3775
|
-
if (isRawBody(userBody)) {
|
|
3776
|
-
requestOptions.body = userBody;
|
|
3777
|
-
requestOptions.headers.delete(HttpRequestHeader.CONTENT_TYPE);
|
|
3778
|
-
} else {
|
|
3779
|
-
const isJson = requestOptions.headers.get(HttpRequestHeader.CONTENT_TYPE)?.includes("json") ?? false;
|
|
3780
|
-
requestOptions.body = isJson && isObject(userBody) ? serialize(userBody) : userBody;
|
|
3781
|
-
}
|
|
3782
|
-
} else {
|
|
3783
|
-
requestOptions.headers.delete(HttpRequestHeader.CONTENT_TYPE);
|
|
3784
|
-
if (requestOptions.body instanceof URLSearchParams) {
|
|
3785
|
-
_Transportr.mergeSearchParams(requestOptions.searchParams, requestOptions.body);
|
|
3786
|
-
}
|
|
3787
|
-
requestOptions.body = void 0;
|
|
3788
|
-
}
|
|
3789
|
-
const { signal, timeout, global = false, xsrf } = requestOptions;
|
|
3790
|
-
if (xsrf) {
|
|
3791
|
-
const xsrfConfig = typeof xsrf === "object" ? xsrf : {};
|
|
3792
|
-
const token = getCookieValue(xsrfConfig.cookieName ?? XSRF_COOKIE_NAME);
|
|
3793
|
-
if (token) {
|
|
3794
|
-
requestOptions.headers.set(xsrfConfig.headerName ?? XSRF_HEADER_NAME, token);
|
|
3795
|
-
}
|
|
3796
|
-
}
|
|
3797
|
-
const signalController = new SignalController({ signal, timeout }).onAbort((event) => this.publish({ name: RequestEvent.ABORTED, event, global })).onTimeout((event) => this.publish({ name: RequestEvent.TIMEOUT, event, global }));
|
|
3798
|
-
requestOptions.signal = signalController.signal;
|
|
3799
|
-
this.publish({ name: RequestEvent.CONFIGURED, data: requestOptions, global });
|
|
3800
|
-
return { signalController, requestOptions, global };
|
|
3801
|
-
}
|
|
3802
|
-
/**
|
|
3803
|
-
* Gets the base URL from a URL or string.
|
|
3804
|
-
* @param url The URL or string to parse.
|
|
3805
|
-
* @returns The base URL.
|
|
3806
|
-
*/
|
|
3807
|
-
static getBaseUrl(url) {
|
|
3808
|
-
if (url instanceof URL) {
|
|
3809
|
-
return url;
|
|
3810
|
-
}
|
|
3811
|
-
if (!isString(url)) {
|
|
3812
|
-
throw new TypeError("Invalid URL");
|
|
3813
|
-
}
|
|
3814
|
-
return new URL(url, url.startsWith("/") ? globalThis.location.origin : void 0);
|
|
3815
|
-
}
|
|
3816
|
-
/**
|
|
3817
|
-
* Parses a content-type string into a MediaType instance with caching.
|
|
3818
|
-
* This method caches parsed MediaType instances to avoid re-parsing the same content-type strings,
|
|
3819
|
-
* which significantly improves performance for repeated requests with the same content types.
|
|
3820
|
-
* @param contentType The content-type string to parse.
|
|
3821
|
-
* @returns The parsed MediaType instance, or undefined if parsing fails.
|
|
3822
|
-
*/
|
|
3823
|
-
static getOrParseMediaType(contentType) {
|
|
3824
|
-
if (contentType === null) {
|
|
3825
|
-
return;
|
|
3826
|
-
}
|
|
3827
|
-
let mediaType = _Transportr.mediaTypeCache.get(contentType);
|
|
3828
|
-
if (mediaType !== void 0) {
|
|
3829
|
-
return mediaType;
|
|
3830
|
-
}
|
|
3831
|
-
mediaType = MediaType.parse(contentType) ?? void 0;
|
|
3832
|
-
if (mediaType !== void 0) {
|
|
3833
|
-
if (_Transportr.mediaTypeCache.size >= 100) {
|
|
3834
|
-
const firstKey = _Transportr.mediaTypeCache.keys().next().value;
|
|
3835
|
-
if (firstKey !== void 0) {
|
|
3836
|
-
_Transportr.mediaTypeCache.delete(firstKey);
|
|
3837
|
-
}
|
|
3838
|
-
}
|
|
3839
|
-
_Transportr.mediaTypeCache.set(contentType, mediaType);
|
|
3840
|
-
}
|
|
3841
|
-
return mediaType;
|
|
3842
|
-
}
|
|
3843
|
-
/**
|
|
3844
|
-
* Creates a new URL with the given path and search parameters.
|
|
3845
|
-
* @param url The base URL.
|
|
3846
|
-
* @param path The path to append to the base URL.
|
|
3847
|
-
* @param searchParams The search parameters to append to the URL.
|
|
3848
|
-
* @returns A new URL with the given path and search parameters.
|
|
3849
|
-
*/
|
|
3850
|
-
static createUrl(url, path, searchParams) {
|
|
3851
|
-
const requestUrl = path ? new URL(`${url.pathname.replace(endsWithSlashRegEx, "")}${path}`, url.origin) : new URL(url);
|
|
3852
|
-
if (searchParams) {
|
|
3853
|
-
_Transportr.mergeSearchParams(requestUrl.searchParams, searchParams);
|
|
3854
|
-
}
|
|
3855
|
-
return requestUrl;
|
|
3856
|
-
}
|
|
3857
|
-
/**
|
|
3858
|
-
* It generates a ResponseStatus object from an error name and a Response object.
|
|
3859
|
-
* @param errorName The name of the error.
|
|
3860
|
-
* @param response The Response object.
|
|
3861
|
-
* @returns A ResponseStatus object.
|
|
3862
|
-
*/
|
|
3863
|
-
static generateResponseStatusFromError(errorName, { status, statusText } = new Response()) {
|
|
3864
|
-
switch (errorName) {
|
|
3865
|
-
case SignalErrors.ABORT:
|
|
3866
|
-
return aborted;
|
|
3867
|
-
case SignalErrors.TIMEOUT:
|
|
3868
|
-
return timedOut;
|
|
3869
|
-
default:
|
|
3870
|
-
return status >= 400 ? new ResponseStatus(status, statusText) : internalServerError;
|
|
3871
|
-
}
|
|
3872
|
-
}
|
|
3873
|
-
/**
|
|
3874
|
-
* Handles an error that occurs during a request.
|
|
3875
|
-
* @param path The path of the request.
|
|
3876
|
-
* @param response The Response object.
|
|
3877
|
-
* @param options Additional error context including cause, entity, url, method, and timing.
|
|
3878
|
-
* @param requestOptions The original request options that led to the error, used for hooks context.
|
|
3879
|
-
* @returns An HttpError object.
|
|
3880
|
-
*/
|
|
3881
|
-
async handleError(path, response, { cause, entity, url, method, timing } = {}, requestOptions) {
|
|
3882
|
-
const message = method && url ? `${method} ${url.href} failed${response ? ` with status ${response.status}` : ""}` : `An error has occurred with your request to: '${path}'`;
|
|
3883
|
-
let error = new HttpError(_Transportr.generateResponseStatusFromError(cause?.name, response), { message, cause, entity, url, method, timing });
|
|
3884
|
-
const beforeErrorHookSets = [_Transportr.globalHooks.beforeError, this.hooks.beforeError, requestOptions?.hooks?.beforeError];
|
|
3885
|
-
for (const hooks of beforeErrorHookSets) {
|
|
3886
|
-
if (!hooks) {
|
|
3887
|
-
continue;
|
|
3888
|
-
}
|
|
3889
|
-
for (const hook of hooks) {
|
|
3890
|
-
const result = await hook(error);
|
|
3891
|
-
if (result instanceof HttpError) {
|
|
3892
|
-
error = result;
|
|
3893
|
-
}
|
|
3894
|
-
}
|
|
3895
|
-
}
|
|
3896
|
-
this.publish({ name: RequestEvent.ERROR, data: error });
|
|
3897
|
-
return error;
|
|
3898
|
-
}
|
|
3899
|
-
/**
|
|
3900
|
-
* Publishes an event to the global and instance event handlers.
|
|
3901
|
-
* @param eventObject The event object to publish.
|
|
3902
|
-
*/
|
|
3903
|
-
publish({ name, event = new CustomEvent(name), data, global = true }) {
|
|
3904
|
-
if (global) {
|
|
3905
|
-
_Transportr.globalSubscribr.publish(name, event, data);
|
|
3906
|
-
}
|
|
3907
|
-
this.subscribr.publish(name, event, data);
|
|
3908
|
-
}
|
|
3909
|
-
/**
|
|
3910
|
-
* It returns a response handler based on the content type of the response.
|
|
3911
|
-
* @param contentType The content type of the response.
|
|
3912
|
-
* @returns A response handler function.
|
|
3913
|
-
*/
|
|
3914
|
-
getResponseHandler(contentType) {
|
|
3915
|
-
if (!contentType) {
|
|
3916
|
-
return;
|
|
3917
|
-
}
|
|
3918
|
-
const mediaType = _Transportr.getOrParseMediaType(contentType);
|
|
3919
|
-
if (!mediaType) {
|
|
3920
|
-
return;
|
|
3921
|
-
}
|
|
3922
|
-
for (const [contentType2, responseHandler] of _Transportr.contentTypeHandlers) {
|
|
3923
|
-
if (mediaType.matches(contentType2)) {
|
|
3924
|
-
return responseHandler;
|
|
3925
|
-
}
|
|
3926
|
-
}
|
|
3927
|
-
return void 0;
|
|
3928
|
-
}
|
|
3929
|
-
/**
|
|
3930
|
-
* A string representation of the Transportr instance.
|
|
3931
|
-
* @returns The string 'Transportr'.
|
|
3932
|
-
*/
|
|
3933
|
-
get [Symbol.toStringTag]() {
|
|
3934
|
-
return "Transportr";
|
|
3935
|
-
}
|
|
3936
|
-
};
|
|
3937
|
-
export {
|
|
3938
|
-
Transportr
|
|
3939
|
-
};
|
|
3940
|
-
/*! Bundled license information:
|
|
3941
|
-
|
|
3942
|
-
dompurify/dist/purify.es.mjs:
|
|
3943
|
-
(*! @license DOMPurify 3.3.3 | (c) Cure53 and other contributors | Released under the Apache license 2.0 and Mozilla Public License 2.0 | github.com/cure53/DOMPurify/blob/3.3.3/LICENSE *)
|
|
3944
|
-
*/
|
|
1
|
+
var P=/^[-!#$%&'*+.^_`|~A-Za-z0-9]*$/u,me=/(["\\])/ug,ye=/^[\t\u0020-\u007E\u0080-\u00FF]*$/u,W=class K extends Map{constructor(e=[]){super(e)}static isValid(e,t){return P.test(e)&&ye.test(t)}get(e){return super.get(e.toLowerCase())}has(e){return super.has(e.toLowerCase())}set(e,t){if(!K.isValid(e,t))throw new Error(`Invalid media type parameter name/value: ${e}/${t}`);return super.set(e.toLowerCase(),t),this}delete(e){return super.delete(e.toLowerCase())}toString(){return Array.from(this).map(([e,t])=>`;${e}=${!t||!P.test(t)?`"${t.replace(me,"\\$1")}"`:t}`).join("")}get[Symbol.toStringTag](){return"MediaTypeParameters"}},be=new Set([" "," ",`
|
|
2
|
+
`,"\r"]),Ee=/[ \t\n\r]+$/u,Te=/^[ \t\n\r]+|[ \t\n\r]+$/ug,Oe=class E{static parse(e){e=e.replace(Te,"");let t=0,[r,n]=E.collect(e,t,["/"]);if(t=n,!r.length||t>=e.length||!P.test(r))throw new TypeError(E.generateErrorMessage("type",r));++t;let[o,i]=E.collect(e,t,[";"],!0,!0);if(t=i,!o.length||!P.test(o))throw new TypeError(E.generateErrorMessage("subtype",o));let u=new W;for(;t<e.length;){for(++t;be.has(e[t]);)++t;let a;if([a,t]=E.collect(e,t,[";","="],!1),t>=e.length||e[t]===";")continue;++t;let l;if(e[t]==='"')for([l,t]=E.collectHttpQuotedString(e,t);t<e.length&&e[t]!==";";)++t;else if([l,t]=E.collect(e,t,[";"],!1,!0),!l)continue;a&&W.isValid(a,l)&&!u.has(a)&&u.set(a,l)}return{type:r,subtype:o,parameters:u}}get[Symbol.toStringTag](){return"MediaTypeParser"}static collect(e,t,r,n=!0,o=!1){let i="";for(let{length:u}=e;t<u&&!r.includes(e[t]);t++)i+=e[t];return n&&(i=i.toLowerCase()),o&&(i=i.replace(Ee,"")),[i,t]}static collectHttpQuotedString(e,t){let r="";for(let n=e.length,o;++t<n&&(o=e[t])!=='"';)r+=o=="\\"&&++t<n?e[t]:o;return[r,t]}static generateErrorMessage(e,t){return`Invalid ${e} "${t}": only HTTP token code points are valid.`}},y=class Y{_type;_subtype;_parameters;constructor(e,t={}){if(t===null||typeof t!="object"||Array.isArray(t))throw new TypeError("The parameters argument must be an object");({type:this._type,subtype:this._subtype,parameters:this._parameters}=Oe.parse(e));for(let[r,n]of Object.entries(t))this._parameters.set(r,n)}static parse(e){try{return new Y(e)}catch{}return null}get type(){return this._type}get subtype(){return this._subtype}get essence(){return`${this._type}/${this._subtype}`}get parameters(){return this._parameters}matches(e){return typeof e=="string"?this.essence.includes(e):this._type===e._type&&this._subtype===e._subtype}toString(){return`${this.essence}${this._parameters.toString()}`}get[Symbol.toStringTag](){return"MediaType"}};var Se=class extends Map{set(s,e){return super.set(s,e instanceof Set?e:(super.get(s)??new Set).add(e)),this}find(s,e){let t=this.get(s);if(t!==void 0)return Array.from(t).find(e)}hasValue(s,e){let t=super.get(s);return t?t.has(e):!1}deleteValue(s,e){if(e===void 0)return this.delete(s);let t=super.get(s);if(t){let r=t.delete(e);return t.size===0&&super.delete(s),r}return!1}get[Symbol.toStringTag](){return"SetMultiMap"}},ve=class{context;eventHandler;constructor(s,e){this.context=s,this.eventHandler=e}handle(s,e){this.eventHandler.call(this.context,s,e)}get[Symbol.toStringTag](){return"ContextEventHandler"}},we=class{_eventName;_contextEventHandler;constructor(s,e){this._eventName=s,this._contextEventHandler=e}get eventName(){return this._eventName}get contextEventHandler(){return this._contextEventHandler}get[Symbol.toStringTag](){return"Subscription"}},C=class{subscribers=new Se;errorHandler;setErrorHandler(s){this.errorHandler=s}subscribe(s,e,t=e,r){if(this.validateEventName(s),r?.once){let i=e;e=(u,a)=>{i.call(t,u,a),this.unsubscribe(o)}}let n=new ve(t,e);this.subscribers.set(s,n);let o=new we(s,n);return o}unsubscribe({eventName:s,contextEventHandler:e}){let t=this.subscribers.get(s)??new Set,r=t.delete(e);return r&&t.size===0&&this.subscribers.delete(s),r}publish(s,e=new CustomEvent(s),t){this.validateEventName(s),this.subscribers.get(s)?.forEach(r=>{try{r.handle(e,t)}catch(n){this.errorHandler?this.errorHandler(n,s,e,t):console.error(`Error in event handler for '${s}':`,n)}})}isSubscribed({eventName:s,contextEventHandler:e}){return this.subscribers.get(s)?.has(e)??!1}validateEventName(s){if(!s||typeof s!="string")throw new TypeError("Event name must be a non-empty string");if(s.trim()!==s)throw new Error("Event name cannot have leading or trailing whitespace")}destroy(){this.subscribers.clear()}get[Symbol.toStringTag](){return"Subscribr"}};var v=class extends Error{_entity;responseStatus;_url;_method;_timing;constructor(e,{message:t,cause:r,entity:n,url:o,method:i,timing:u}={}){super(t,{cause:r}),this._entity=n,this.responseStatus=e,this._url=o,this._method=i,this._timing=u}get entity(){return this._entity}get statusCode(){return this.responseStatus.code}get statusText(){return this.responseStatus?.text}get url(){return this._url}get method(){return this._method}get timing(){return this._timing}get name(){return"HttpError"}get[Symbol.toStringTag](){return this.name}};var T=class{_code;_text;constructor(e,t){this._code=e,this._text=t}get code(){return this._code}get text(){return this._text}get[Symbol.toStringTag](){return"ResponseStatus"}toString(){return`${this._code} ${this._text}`}};var w={charset:"utf-8"},Q=/\/$/,Z="XSRF-TOKEN",ee="X-XSRF-TOKEN",R={PNG:new y("image/png"),TEXT:new y("text/plain",w),JSON:new y("application/json",w),HTML:new y("text/html",w),JAVA_SCRIPT:new y("text/javascript",w),CSS:new y("text/css",w),XML:new y("application/xml",w),BIN:new y("application/octet-stream")},x=R.JSON.toString(),te={DEFAULT:"default",FORCE_CACHE:"force-cache",NO_CACHE:"no-cache",NO_STORE:"no-store",ONLY_IF_CACHED:"only-if-cached",RELOAD:"reload"},m={CONFIGURED:"configured",SUCCESS:"success",ERROR:"error",ABORTED:"aborted",TIMEOUT:"timeout",RETRY:"retry",COMPLETE:"complete",ALL_COMPLETE:"all-complete"},O={ABORT:"abort",TIMEOUT:"timeout"},S={ABORT:"AbortError",TIMEOUT:"TimeoutError"},H={once:!0,passive:!0},L=()=>new CustomEvent(O.ABORT,{detail:{cause:S.ABORT}}),se=()=>new CustomEvent(O.TIMEOUT,{detail:{cause:S.TIMEOUT}}),re=["POST","PUT","PATCH","DELETE"],ne=new T(500,"Internal Server Error"),oe=new T(499,"Aborted"),ie=new T(504,"Request Timeout"),I=[408,413,429,500,502,503,504],B=["GET","PUT","HEAD","DELETE","OPTIONS"],k=300,A=2;var M=class{abortSignal;abortController=new AbortController;events=new Map;constructor({signal:e,timeout:t=1/0}={}){if(t<0)throw new RangeError("The timeout cannot be negative");let r=[this.abortController.signal];e!=null&&r.push(e),t!==1/0&&r.push(AbortSignal.timeout(t)),(this.abortSignal=AbortSignal.any(r)).addEventListener(O.ABORT,this,H)}handleEvent({target:{reason:e}}){this.abortController.signal.aborted||e instanceof DOMException&&e.name===S.TIMEOUT&&this.abortSignal.dispatchEvent(se())}get signal(){return this.abortSignal}onAbort(e){return this.addEventListener(O.ABORT,e)}onTimeout(e){return this.addEventListener(O.TIMEOUT,e)}abort(e=L()){this.abortController.abort(e.detail?.cause)}destroy(){this.abortSignal.removeEventListener(O.ABORT,this,H);for(let[e,t]of this.events)this.abortSignal.removeEventListener(t,e,H);return this.events.clear(),this}addEventListener(e,t){return this.abortSignal.addEventListener(e,t,H),this.events.set(t,e),this}get[Symbol.toStringTag](){return"SignalController"}};var ae,qe,N=()=>qe??=import("./OP3JQ447.js").then(({default:s})=>e=>s.sanitize(e)),q=async()=>typeof document<"u"&&typeof DOMParser<"u"&&typeof DocumentFragment<"u"?Promise.resolve():ae??=import("jsdom").then(({JSDOM:s})=>{let{window:e}=new s("<!DOCTYPE html><html><head></head><body></body></html>",{url:"http://localhost"});globalThis.window=e,Object.assign(globalThis,{document:e.document,DOMParser:e.DOMParser,DocumentFragment:e.DocumentFragment})}).catch(()=>{throw ae=void 0,new Error("jsdom is required for HTML/XML/DOM features in Node.js environments. Install it with: npm install jsdom")}),ce=async s=>await s.text(),_=async s=>{await q();let e=URL.createObjectURL(await s.blob());return new Promise((t,r)=>{let n=document.createElement("script");Object.assign(n,{src:e,type:"text/javascript",async:!0}),n.onload=()=>{URL.revokeObjectURL(e),document.head.removeChild(n),t()},n.onerror=()=>{URL.revokeObjectURL(e),document.head.removeChild(n),r(new Error("Script failed to load"))},document.head.appendChild(n)})},D=async s=>{await q();let e=URL.createObjectURL(await s.blob());return new Promise((t,r)=>{let n=document.createElement("link");Object.assign(n,{href:e,type:"text/css",rel:"stylesheet"}),n.onload=()=>t(URL.revokeObjectURL(e)),n.onerror=()=>{URL.revokeObjectURL(e),document.head.removeChild(n),r(new Error("Stylesheet load failed"))},document.head.appendChild(n)})},j=async s=>await s.json(),ue=async s=>await s.blob(),F=async s=>{await q();let e=URL.createObjectURL(await s.blob());return new Promise((t,r)=>{let n=new Image;n.onload=()=>{URL.revokeObjectURL(e),t(n)},n.onerror=()=>{URL.revokeObjectURL(e),r(new Error("Image failed to load"))},n.src=e})},le=async s=>await s.arrayBuffer(),$=async s=>Promise.resolve(s.body),G=async s=>{await q();let e=await N();return new DOMParser().parseFromString(e(await s.text()),"application/xml")},J=async s=>{await q();let e=await N();return new DOMParser().parseFromString(e(await s.text()),"text/html")},de=async s=>{await q();let e=await N();return document.createRange().createContextualFragment(e(await s.text()))};var pe=s=>s!==void 0&&re.includes(s),fe=s=>s instanceof FormData||s instanceof Blob||s instanceof ArrayBuffer||s instanceof ReadableStream||s instanceof URLSearchParams||ArrayBuffer.isView(s),he=s=>{if(typeof document>"u"||!document.cookie)return;let e=`${s}=`,t=document.cookie.split(";");for(let r=0,n=t.length;r<n;r++){let o=t[r].trim();if(o.startsWith(e))return decodeURIComponent(o.slice(e.length))}},ge=s=>JSON.stringify(s),z=s=>s!==null&&typeof s=="string",b=s=>s!==null&&typeof s=="object"&&!Array.isArray(s)&&Object.getPrototypeOf(s)===Object.prototype,V=(...s)=>{let e=s.length;if(e===0)return;if(e===1){let[r]=s;return b(r)?X(r):r}let t={};for(let r of s){if(!b(r))return;for(let[n,o]of Object.entries(r)){let i=t[n];Array.isArray(o)?t[n]=[...o,...Array.isArray(i)?i.filter(u=>!o.includes(u)):[]]:b(o)?t[n]=b(i)?V(i,o):X(o):t[n]=o}}return t};function X(s){if(b(s)){let e={},t=Object.keys(s);for(let r=0,n=t.length,o;r<n;r++)o=t[r],e[o]=X(s[o]);return e}return s}var Re=class s{_baseUrl;_options;subscribr;hooks={beforeRequest:[],afterResponse:[],beforeError:[]};static globalSubscribr=new C;static globalHooks={beforeRequest:[],afterResponse:[],beforeError:[]};static signalControllers=new Set;static inflightRequests=new Map;static mediaTypeCache=new Map(Object.values(R).map(e=>[e.toString(),e]));static contentTypeHandlers=[[R.TEXT.type,ce],[R.JSON.subtype,j],[R.BIN.subtype,$],[R.HTML.subtype,J],[R.XML.subtype,G],[R.PNG.type,F],[R.JAVA_SCRIPT.subtype,_],[R.CSS.subtype,D]];constructor(e=globalThis.location?.origin??"http://localhost",t={}){b(e)&&([e,t]=[globalThis.location?.origin??"http://localhost",e]),this._baseUrl=s.getBaseUrl(e),this._options=s.createOptions(t,s.defaultRequestOptions),this.subscribr=new C}static CredentialsPolicy={INCLUDE:"include",OMIT:"omit",SAME_ORIGIN:"same-origin"};static RequestModes={CORS:"cors",NAVIGATE:"navigate",NO_CORS:"no-cors",SAME_ORIGIN:"same-origin"};static RequestPriorities={HIGH:"high",LOW:"low",AUTO:"auto"};static RedirectPolicies={ERROR:"error",FOLLOW:"follow",MANUAL:"manual"};static ReferrerPolicy={NO_REFERRER:"no-referrer",NO_REFERRER_WHEN_DOWNGRADE:"no-referrer-when-downgrade",ORIGIN:"origin",ORIGIN_WHEN_CROSS_ORIGIN:"origin-when-cross-origin",SAME_ORIGIN:"same-origin",STRICT_ORIGIN:"strict-origin",STRICT_ORIGIN_WHEN_CROSS_ORIGIN:"strict-origin-when-cross-origin",UNSAFE_URL:"unsafe-url"};static RequestEvents=m;static defaultRequestOptions={body:void 0,cache:te.NO_STORE,credentials:s.CredentialsPolicy.SAME_ORIGIN,headers:new Headers({"content-type":x,accept:x}),searchParams:void 0,integrity:void 0,keepalive:void 0,method:"GET",mode:s.RequestModes.CORS,priority:s.RequestPriorities.AUTO,redirect:s.RedirectPolicies.FOLLOW,referrer:"about:client",referrerPolicy:s.ReferrerPolicy.STRICT_ORIGIN_WHEN_CROSS_ORIGIN,signal:void 0,timeout:3e4,global:!0};static register(e,t,r){return s.globalSubscribr.subscribe(e,t,r)}static unregister(e){return s.globalSubscribr.unsubscribe(e)}static abortAll(){for(let e of this.signalControllers)e.abort(L());this.signalControllers.clear()}static registerContentTypeHandler(e,t){s.contentTypeHandlers.unshift([e,t])}static unregisterContentTypeHandler(e){let t=s.contentTypeHandlers.findIndex(([r])=>r===e);return t===-1?!1:(s.contentTypeHandlers.splice(t,1),!0)}static addHooks(e){e.beforeRequest&&s.globalHooks.beforeRequest.push(...e.beforeRequest),e.afterResponse&&s.globalHooks.afterResponse.push(...e.afterResponse),e.beforeError&&s.globalHooks.beforeError.push(...e.beforeError)}static clearHooks(){s.globalHooks={beforeRequest:[],afterResponse:[],beforeError:[]}}static unregisterAll(){s.abortAll(),s.globalSubscribr=new C,s.clearHooks(),s.inflightRequests.clear()}get baseUrl(){return this._baseUrl}register(e,t,r){return this.subscribr.subscribe(e,t,r)}unregister(e){return this.subscribr.unsubscribe(e)}addHooks(e){return e.beforeRequest&&this.hooks.beforeRequest.push(...e.beforeRequest),e.afterResponse&&this.hooks.afterResponse.push(...e.afterResponse),e.beforeError&&this.hooks.beforeError.push(...e.beforeError),this}clearHooks(){return this.hooks.beforeRequest.length=0,this.hooks.afterResponse.length=0,this.hooks.beforeError.length=0,this}destroy(){this.clearHooks(),this.subscribr.destroy()}async get(e,t){return this._get(e,t)}async post(e,t){return typeof e!="string"&&([e,t]=[void 0,e]),this.execute(e,t,{method:"POST"})}async put(e,t){return this.execute(e,t,{method:"PUT"})}async patch(e,t){return this.execute(e,t,{method:"PATCH"})}async delete(e,t){return this.execute(e,t,{method:"DELETE"})}async head(e,t){return this.execute(e,t,{method:"HEAD"})}async options(e,t={}){b(e)&&([e,t]=[void 0,e]);let r=this.processRequestOptions(t,{method:"OPTIONS"}),{requestOptions:n}=r,o=n.hooks,i=s.createUrl(this._baseUrl,e,n.searchParams),u=[s.globalHooks.beforeRequest,this.hooks.beforeRequest,o?.beforeRequest];for(let d of u)if(d)for(let c of d){let g=await c(n,i);g&&(Object.assign(n,g),g.searchParams!==void 0&&(i=s.createUrl(this._baseUrl,e,n.searchParams)))}let a=await this._request(e,r),l=[s.globalHooks.afterResponse,this.hooks.afterResponse,o?.afterResponse];for(let d of l)if(d)for(let c of d){let g=await c(a,n);g&&(a=g)}let h=a.headers.get("allow")?.split(",").map(d=>d.trim());return this.publish({name:m.SUCCESS,data:h,global:t.global}),h}async request(e,t={}){b(e)&&([e,t]=[void 0,e]);let r=await this._request(e,this.processRequestOptions(t,{}));return this.publish({name:m.SUCCESS,data:r,global:t.global}),r}async getJson(e,t){return this._get(e,t,{headers:{accept:`${R.JSON}`}},j)}async getXml(e,t){return this._get(e,t,{headers:{accept:`${R.XML}`}},G)}async getHtml(e,t,r){let n=await this._get(e,t,{headers:{accept:`${R.HTML}`}},J);return r&&n?n.querySelector(r):n}async getHtmlFragment(e,t,r){let n=await this._get(e,t,{headers:{accept:`${R.HTML}`}},de);return r&&n?n.querySelector(r):n}async getScript(e,t){return this._get(e,t,{headers:{accept:`${R.JAVA_SCRIPT}`}},_)}async getStylesheet(e,t){return this._get(e,t,{headers:{accept:`${R.CSS}`}},D)}async getBlob(e,t){return this._get(e,t,{headers:{accept:"application/octet-stream"}},ue)}async getImage(e,t){return this._get(e,t,{headers:{accept:"image/*"}},F)}async getBuffer(e,t){return this._get(e,t,{headers:{accept:"application/octet-stream"}},le)}async getStream(e,t){return this._get(e,t,{headers:{accept:"application/octet-stream"}},$)}async _get(e,t,r={},n){return this.execute(e,t,{...r,method:"GET",body:void 0},n)}async _request(e,{signalController:t,requestOptions:r,global:n}){s.signalControllers.add(t);let o=s.normalizeRetryOptions(r.retry),i=r.method??"GET",u=o.limit>0&&o.methods.includes(i),a=r.dedupe===!0&&(i==="GET"||i==="HEAD"),l=0,h=performance.now(),d=()=>{let c=performance.now();return{start:h,end:c,duration:c-h}};try{let c=s.createUrl(this._baseUrl,e,r.searchParams),g=a?`${i}:${c.href}`:"";if(a){let f=s.inflightRequests.get(g);if(f)return(await f).clone()}let p=async()=>{for(;;)try{let f=await fetch(c,r);if(!f.ok){if(u&&l<o.limit&&o.statusCodes.includes(f.status)){l++,this.publish({name:m.RETRY,data:{attempt:l,status:f.status,method:i,path:e,timing:d()},global:n}),await s.retryDelay(o,l);continue}let U;try{U=await f.text()}catch{}throw await this.handleError(e,f,{entity:U,url:c,method:i,timing:d()},r)}return f}catch(f){if(f instanceof v)throw f;if(u&&l<o.limit){l++,this.publish({name:m.RETRY,data:{attempt:l,error:f.message,method:i,path:e,timing:d()},global:n}),await s.retryDelay(o,l);continue}throw await this.handleError(e,void 0,{cause:f,url:c,method:i,timing:d()},r)}};if(a){let f=p();s.inflightRequests.set(g,f);try{return await f}finally{s.inflightRequests.delete(g)}}return await p()}finally{if(s.signalControllers.delete(t.destroy()),!r.signal?.aborted){let c=d();this.publish({name:m.COMPLETE,data:{timing:c},global:n}),s.signalControllers.size===0&&this.publish({name:m.ALL_COMPLETE,global:n})}}}static normalizeRetryOptions(e){return e===void 0?{limit:0,statusCodes:[],methods:[],delay:k,backoffFactor:A}:typeof e=="number"?{limit:e,statusCodes:[...I],methods:[...B],delay:k,backoffFactor:A}:{limit:e.limit??0,statusCodes:e.statusCodes??[...I],methods:e.methods??[...B],delay:e.delay??k,backoffFactor:e.backoffFactor??A}}static retryDelay(e,t){let r=typeof e.delay=="function"?e.delay(t):e.delay*e.backoffFactor**(t-1);return new Promise(n=>setTimeout(n,r))}async execute(e,t={},r={},n){b(e)&&([e,t]=[void 0,e]);let o=this.processRequestOptions(t,r),{requestOptions:i}=o,u=i.hooks,a=s.createUrl(this._baseUrl,e,i.searchParams),l=[s.globalHooks.beforeRequest,this.hooks.beforeRequest,u?.beforeRequest];for(let c of l)if(c)for(let g of c){let p=await g(i,a);p&&(Object.assign(i,p),p.searchParams!==void 0&&(a=s.createUrl(this._baseUrl,e,i.searchParams)))}let h=await this._request(e,o),d=[s.globalHooks.afterResponse,this.hooks.afterResponse,u?.afterResponse];for(let c of d)if(c)for(let g of c){let p=await g(h,i);p&&(h=p)}try{!n&&h.status!==204&&(n=this.getResponseHandler(h.headers.get("content-type")));let c=await n?.(h);return this.publish({name:m.SUCCESS,data:c,global:o.global}),c}catch(c){throw await this.handleError(e,h,{cause:c},i)}}static createOptions({headers:e,searchParams:t,...r},{headers:n,searchParams:o,...i}){return n=s.mergeHeaders(new Headers,e,n),o=s.mergeSearchParams(new URLSearchParams,t,o),{...V(i,r)??{},headers:n,searchParams:o}}static mergeHeaders(e,...t){for(let r of t)if(r!==void 0)if(r instanceof Headers)r.forEach((n,o)=>e.set(o,n));else if(Array.isArray(r))for(let[n,o]of r)e.set(n,o);else{let n=r,o=Object.keys(n);for(let i=0;i<o.length;i++){let u=o[i],a=n[u];a!==void 0&&e.set(u,String(a))}}return e}static mergeSearchParams(e,...t){for(let r of t)if(r!==void 0)if(r instanceof URLSearchParams)r.forEach((n,o)=>e.set(o,n));else if(z(r)||Array.isArray(r))for(let[n,o]of new URLSearchParams(r))e.set(n,o);else{let n=Object.keys(r);for(let o=0;o<n.length;o++){let i=n[o],u=r[i];u!==void 0&&e.set(i,String(u))}}return e}processRequestOptions({body:e,headers:t,searchParams:r,...n},{headers:o,searchParams:i,...u}){let a={...this._options,...n,...u,headers:s.mergeHeaders(new Headers,this._options.headers,t,o),searchParams:s.mergeSearchParams(new URLSearchParams,this._options.searchParams,r,i)};if(pe(a.method))if(fe(e))a.body=e,a.headers.delete("content-type");else{let p=a.headers.get("content-type")?.includes("json")??!1;a.body=p&&b(e)?ge(e):e}else a.headers.delete("content-type"),a.body instanceof URLSearchParams&&s.mergeSearchParams(a.searchParams,a.body),a.body=void 0;let{signal:l,timeout:h,global:d=!1,xsrf:c}=a;if(c){let p=typeof c=="object"?c:{},f=he(p.cookieName??Z);f&&a.headers.set(p.headerName??ee,f)}let g=new M({signal:l,timeout:h}).onAbort(p=>this.publish({name:m.ABORTED,event:p,global:d})).onTimeout(p=>this.publish({name:m.TIMEOUT,event:p,global:d}));return a.signal=g.signal,this.publish({name:m.CONFIGURED,data:a,global:d}),{signalController:g,requestOptions:a,global:d}}static getBaseUrl(e){if(e instanceof URL)return e;if(!z(e))throw new TypeError("Invalid URL");return new URL(e,e.startsWith("/")?globalThis.location.origin:void 0)}static getOrParseMediaType(e){if(e===null)return;let t=s.mediaTypeCache.get(e);if(t!==void 0)return t;if(t=y.parse(e)??void 0,t!==void 0){if(s.mediaTypeCache.size>=100){let r=s.mediaTypeCache.keys().next().value;r!==void 0&&s.mediaTypeCache.delete(r)}s.mediaTypeCache.set(e,t)}return t}static createUrl(e,t,r){let n=t?new URL(`${e.pathname.replace(Q,"")}${t}`,e.origin):new URL(e);return r&&s.mergeSearchParams(n.searchParams,r),n}static generateResponseStatusFromError(e,{status:t,statusText:r}=new Response){switch(e){case S.ABORT:return oe;case S.TIMEOUT:return ie;default:return t>=400?new T(t,r):ne}}async handleError(e,t,{cause:r,entity:n,url:o,method:i,timing:u}={},a){let l=i&&o?`${i} ${o.href} failed${t?` with status ${t.status}`:""}`:`An error has occurred with your request to: '${e}'`,h=new v(s.generateResponseStatusFromError(r?.name,t),{message:l,cause:r,entity:n,url:o,method:i,timing:u}),d=[s.globalHooks.beforeError,this.hooks.beforeError,a?.hooks?.beforeError];for(let c of d)if(c)for(let g of c){let p=await g(h);p instanceof v&&(h=p)}return this.publish({name:m.ERROR,data:h}),h}publish({name:e,event:t=new CustomEvent(e),data:r,global:n=!0}){n&&s.globalSubscribr.publish(e,t,r),this.subscribr.publish(e,t,r)}getResponseHandler(e){if(!e)return;let t=s.getOrParseMediaType(e);if(t){for(let[r,n]of s.contentTypeHandlers)if(t.matches(r))return n}}get[Symbol.toStringTag](){return"Transportr"}};export{Re as Transportr};
|
|
3945
3
|
//# sourceMappingURL=transportr.js.map
|