@authhero/saml 0.1.55 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/core.mjs ADDED
@@ -0,0 +1,1903 @@
1
+ var Y = Object.defineProperty;
2
+ var Q = (e, t, n) => t in e ? Y(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
3
+ var A = (e, t, n) => Q(e, typeof t != "symbol" ? t + "" : t, n);
4
+ import { z as s } from "@hono/zod-openapi";
5
+ const b = s.object({ "#text": s.string() }), W = s.object({
6
+ "#text": s.string(),
7
+ "@_xmlns:saml": s.string().optional()
8
+ }), z = s.object({
9
+ "samlp:AuthnRequest": s.object({
10
+ "saml:Issuer": W,
11
+ "@_xmlns:samlp": s.string(),
12
+ "@_xmlns:saml": s.string().optional(),
13
+ "@_ForceAuthn": s.string().transform((e) => e.toLowerCase() === "true").optional(),
14
+ "@_ID": s.string(),
15
+ "@_IssueInstant": s.string().datetime(),
16
+ "@_Destination": s.string().url(),
17
+ "@_AssertionConsumerServiceURL": s.string().url().optional(),
18
+ "@_ProtocolBinding": s.string().optional(),
19
+ "@_Version": s.string()
20
+ })
21
+ }), St = s.array(
22
+ s.object({
23
+ ":@": s.object({
24
+ "@_xmlns": s.string(),
25
+ "@_entityID": s.string()
26
+ }),
27
+ EntityDescriptor: s.array(
28
+ s.object({
29
+ ":@": s.object({
30
+ "@_protocolSupportEnumeration": s.string()
31
+ }),
32
+ IDPSSODescriptor: s.array(
33
+ s.union([
34
+ s.object({
35
+ KeyDescriptor: s.array(
36
+ s.object({
37
+ KeyInfo: s.array(
38
+ s.object({
39
+ X509Data: s.array(
40
+ s.object({
41
+ X509Certificate: s.array(b)
42
+ })
43
+ )
44
+ })
45
+ ),
46
+ ":@": s.object({
47
+ "@_xmlns": s.string()
48
+ })
49
+ })
50
+ ),
51
+ ":@": s.object({
52
+ "@_use": s.string()
53
+ })
54
+ }),
55
+ s.object({
56
+ SingleLogoutService: s.array(s.object({})),
57
+ ":@": s.object({
58
+ "@_Binding": s.string(),
59
+ "@_Location": s.string()
60
+ })
61
+ }),
62
+ s.object({
63
+ NameIDFormat: s.array(b)
64
+ }),
65
+ s.object({
66
+ SingleSignOnService: s.array(s.object({})),
67
+ ":@": s.object({
68
+ "@_Binding": s.string(),
69
+ "@_Location": s.string()
70
+ })
71
+ }),
72
+ s.object({
73
+ Attribute: s.array(s.object({})),
74
+ ":@": s.object({
75
+ "@_Name": s.string(),
76
+ "@_NameFormat": s.string(),
77
+ "@_FriendlyName": s.string(),
78
+ "@_xmlns": s.string()
79
+ })
80
+ })
81
+ ])
82
+ )
83
+ })
84
+ )
85
+ })
86
+ ), D = s.object({
87
+ "saml:Attribute": s.array(
88
+ s.object({
89
+ "saml:AttributeValue": s.array(
90
+ s.object({
91
+ "#text": s.string()
92
+ })
93
+ ),
94
+ ":@": s.object({
95
+ "@_xmlns:xs": s.string().optional(),
96
+ "@_xmlns:xsi": s.string(),
97
+ "@_xsi:type": s.string()
98
+ }).optional()
99
+ })
100
+ ),
101
+ ":@": s.object({
102
+ "@_Name": s.string(),
103
+ "@_NameFormat": s.string(),
104
+ "@_FriendlyName": s.string().optional()
105
+ })
106
+ }), ee = s.object({
107
+ "ds:Transform": s.array(s.any()),
108
+ ":@": s.object({
109
+ "@_Algorithm": s.string()
110
+ })
111
+ }), v = s.object({
112
+ "ds:Signature": s.array(
113
+ s.union([
114
+ s.object({
115
+ "ds:SignedInfo": s.array(
116
+ s.union([
117
+ s.object({
118
+ "ds:CanonicalizationMethod": s.array(
119
+ s.object({
120
+ ":@": s.object({
121
+ "@_Algorithm": s.string()
122
+ })
123
+ })
124
+ )
125
+ }),
126
+ s.object({
127
+ "ds:SignatureMethod": s.array(
128
+ s.object({
129
+ ":@": s.object({
130
+ "@_Algorithm": s.string()
131
+ })
132
+ })
133
+ )
134
+ }),
135
+ s.object({
136
+ "ds:Reference": s.array(
137
+ s.union([
138
+ s.object({
139
+ "ds:Transforms": s.array(ee)
140
+ }),
141
+ s.object({
142
+ "ds:DigestMethod": s.array(
143
+ s.object({
144
+ ":@": s.object({
145
+ "@_Algorithm": s.string()
146
+ })
147
+ })
148
+ )
149
+ }),
150
+ s.object({ "ds:DigestValue": s.array(b) })
151
+ ])
152
+ ),
153
+ ":@": s.object({
154
+ "@_URI": s.string().optional()
155
+ }).optional()
156
+ })
157
+ ])
158
+ )
159
+ }),
160
+ s.object({
161
+ "ds:SignatureValue": s.array(b)
162
+ }),
163
+ s.object({
164
+ "ds:KeyInfo": s.array(
165
+ s.union([
166
+ s.object({
167
+ "ds:KeyValue": s.array(
168
+ s.object({
169
+ "ds:RSAKeyValue": s.array(
170
+ s.union([
171
+ s.object({
172
+ "ds:Modulus": s.array(b)
173
+ }),
174
+ s.object({
175
+ "ds:Exponent": s.array(b)
176
+ })
177
+ ])
178
+ )
179
+ })
180
+ )
181
+ }),
182
+ s.object({
183
+ "ds:X509Data": s.array(
184
+ s.object({
185
+ "ds:X509Certificate": s.array(b)
186
+ })
187
+ )
188
+ }),
189
+ // Support KeyInfo with both KeyValue and X509Data
190
+ s.object({
191
+ "ds:KeyValue": s.array(
192
+ s.object({
193
+ "ds:RSAKeyValue": s.array(
194
+ s.union([
195
+ s.object({
196
+ "ds:Modulus": s.array(b)
197
+ }),
198
+ s.object({
199
+ "ds:Exponent": s.array(b)
200
+ })
201
+ ])
202
+ )
203
+ })
204
+ ),
205
+ "ds:X509Data": s.array(
206
+ s.object({
207
+ "ds:X509Certificate": s.array(b)
208
+ })
209
+ )
210
+ })
211
+ ])
212
+ )
213
+ })
214
+ ])
215
+ ),
216
+ ":@": s.object({
217
+ "@_xmlns:ds": s.string().optional()
218
+ }).optional()
219
+ }), Et = s.array(
220
+ s.object({
221
+ "samlp:Response": s.array(
222
+ s.union([
223
+ s.object({
224
+ "saml:Issuer": s.array(b)
225
+ }),
226
+ v,
227
+ s.object({
228
+ "samlp:Status": s.array(
229
+ s.object({
230
+ "samlp:StatusCode": s.array(b),
231
+ ":@": s.object({
232
+ "@_Value": s.string()
233
+ })
234
+ })
235
+ )
236
+ }),
237
+ s.object({
238
+ "saml:Assertion": s.array(
239
+ s.union([
240
+ s.object({
241
+ "saml:Issuer": s.array(b)
242
+ }),
243
+ v,
244
+ s.object({
245
+ "saml:Subject": s.array(
246
+ s.union([
247
+ s.object({
248
+ "saml:NameID": s.array(b),
249
+ ":@": s.object({
250
+ "@_Format": s.string()
251
+ })
252
+ }),
253
+ s.object({
254
+ "saml:SubjectConfirmation": s.array(
255
+ s.object({
256
+ "saml:SubjectConfirmationData": s.array(s.any()),
257
+ ":@": s.object({
258
+ "@_InResponseTo": s.string(),
259
+ "@_NotOnOrAfter": s.string(),
260
+ "@_Recipient": s.string()
261
+ })
262
+ })
263
+ ),
264
+ ":@": s.object({
265
+ "@_Method": s.string()
266
+ })
267
+ })
268
+ ])
269
+ )
270
+ }),
271
+ s.object({
272
+ "saml:Conditions": s.array(
273
+ s.object({
274
+ "saml:AudienceRestriction": s.array(
275
+ s.object({
276
+ "saml:Audience": s.array(b)
277
+ })
278
+ )
279
+ })
280
+ ),
281
+ ":@": s.object({
282
+ "@_NotBefore": s.string(),
283
+ "@_NotOnOrAfter": s.string()
284
+ })
285
+ }),
286
+ s.object({
287
+ "saml:AuthnStatement": s.array(
288
+ s.object({
289
+ "saml:AuthnContext": s.array(
290
+ s.object({
291
+ "saml:AuthnContextClassRef": s.array(b)
292
+ })
293
+ )
294
+ })
295
+ ),
296
+ ":@": s.object({
297
+ "@_AuthnInstant": s.string(),
298
+ "@_SessionIndex": s.string(),
299
+ "@_SessionNotOnOrAfter": s.string()
300
+ })
301
+ }),
302
+ s.object({
303
+ "saml:AttributeStatement": s.array(D)
304
+ })
305
+ ])
306
+ ),
307
+ ":@": s.object({
308
+ "@_xmlns": s.string(),
309
+ "@_ID": s.string(),
310
+ "@_IssueInstant": s.string(),
311
+ "@_Version": s.string()
312
+ })
313
+ })
314
+ ])
315
+ ),
316
+ ":@": s.object({
317
+ "@_xmlns:samlp": s.string(),
318
+ "@_xmlns:saml": s.string(),
319
+ "@_Destination": s.string(),
320
+ "@_ID": s.string(),
321
+ "@_InResponseTo": s.string(),
322
+ "@_IssueInstant": s.string(),
323
+ "@_Version": s.string()
324
+ })
325
+ })
326
+ );
327
+ var C = {}, T = {};
328
+ (function(e) {
329
+ const t = ":A-Za-z_\\u00C0-\\u00D6\\u00D8-\\u00F6\\u00F8-\\u02FF\\u0370-\\u037D\\u037F-\\u1FFF\\u200C-\\u200D\\u2070-\\u218F\\u2C00-\\u2FEF\\u3001-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFFD", n = t + "\\-.\\d\\u00B7\\u0300-\\u036F\\u203F-\\u2040", o = "[" + t + "][" + n + "]*", i = new RegExp("^" + o + "$"), r = function(u, a) {
330
+ const f = [];
331
+ let c = a.exec(u);
332
+ for (; c; ) {
333
+ const d = [];
334
+ d.startIndex = a.lastIndex - c[0].length;
335
+ const g = c.length;
336
+ for (let m = 0; m < g; m++)
337
+ d.push(c[m]);
338
+ f.push(d), c = a.exec(u);
339
+ }
340
+ return f;
341
+ }, l = function(u) {
342
+ const a = i.exec(u);
343
+ return !(a === null || typeof a > "u");
344
+ };
345
+ e.isExist = function(u) {
346
+ return typeof u < "u";
347
+ }, e.isEmptyObject = function(u) {
348
+ return Object.keys(u).length === 0;
349
+ }, e.merge = function(u, a, f) {
350
+ if (a) {
351
+ const c = Object.keys(a), d = c.length;
352
+ for (let g = 0; g < d; g++)
353
+ f === "strict" ? u[c[g]] = [a[c[g]]] : u[c[g]] = a[c[g]];
354
+ }
355
+ }, e.getValue = function(u) {
356
+ return e.isExist(u) ? u : "";
357
+ }, e.isName = l, e.getAllMatches = r, e.nameRegexp = o;
358
+ })(T);
359
+ const L = T, te = {
360
+ allowBooleanAttributes: !1,
361
+ //A tag can have attributes without any value
362
+ unpairedTags: []
363
+ };
364
+ C.validate = function(e, t) {
365
+ t = Object.assign({}, te, t);
366
+ const n = [];
367
+ let o = !1, i = !1;
368
+ e[0] === "\uFEFF" && (e = e.substr(1));
369
+ for (let r = 0; r < e.length; r++)
370
+ if (e[r] === "<" && e[r + 1] === "?") {
371
+ if (r += 2, r = F(e, r), r.err) return r;
372
+ } else if (e[r] === "<") {
373
+ let l = r;
374
+ if (r++, e[r] === "!") {
375
+ r = V(e, r);
376
+ continue;
377
+ } else {
378
+ let u = !1;
379
+ e[r] === "/" && (u = !0, r++);
380
+ let a = "";
381
+ for (; r < e.length && e[r] !== ">" && e[r] !== " " && e[r] !== " " && e[r] !== `
382
+ ` && e[r] !== "\r"; r++)
383
+ a += e[r];
384
+ if (a = a.trim(), a[a.length - 1] === "/" && (a = a.substring(0, a.length - 1), r--), !le(a)) {
385
+ let d;
386
+ return a.trim().length === 0 ? d = "Invalid space after '<'." : d = "Tag '" + a + "' is an invalid name.", h("InvalidTag", d, N(e, r));
387
+ }
388
+ const f = re(e, r);
389
+ if (f === !1)
390
+ return h("InvalidAttr", "Attributes for '" + a + "' have open quote.", N(e, r));
391
+ let c = f.value;
392
+ if (r = f.index, c[c.length - 1] === "/") {
393
+ const d = r - c.length;
394
+ c = c.substring(0, c.length - 1);
395
+ const g = $(c, t);
396
+ if (g === !0)
397
+ o = !0;
398
+ else
399
+ return h(g.err.code, g.err.msg, N(e, d + g.err.line));
400
+ } else if (u)
401
+ if (f.tagClosed) {
402
+ if (c.trim().length > 0)
403
+ return h("InvalidTag", "Closing tag '" + a + "' can't have attributes or invalid starting.", N(e, l));
404
+ if (n.length === 0)
405
+ return h("InvalidTag", "Closing tag '" + a + "' has not been opened.", N(e, l));
406
+ {
407
+ const d = n.pop();
408
+ if (a !== d.tagName) {
409
+ let g = N(e, d.tagStartPos);
410
+ return h(
411
+ "InvalidTag",
412
+ "Expected closing tag '" + d.tagName + "' (opened in line " + g.line + ", col " + g.col + ") instead of closing tag '" + a + "'.",
413
+ N(e, l)
414
+ );
415
+ }
416
+ n.length == 0 && (i = !0);
417
+ }
418
+ } else return h("InvalidTag", "Closing tag '" + a + "' doesn't have proper closing.", N(e, r));
419
+ else {
420
+ const d = $(c, t);
421
+ if (d !== !0)
422
+ return h(d.err.code, d.err.msg, N(e, r - c.length + d.err.line));
423
+ if (i === !0)
424
+ return h("InvalidXml", "Multiple possible root nodes found.", N(e, r));
425
+ t.unpairedTags.indexOf(a) !== -1 || n.push({ tagName: a, tagStartPos: l }), o = !0;
426
+ }
427
+ for (r++; r < e.length; r++)
428
+ if (e[r] === "<")
429
+ if (e[r + 1] === "!") {
430
+ r++, r = V(e, r);
431
+ continue;
432
+ } else if (e[r + 1] === "?") {
433
+ if (r = F(e, ++r), r.err) return r;
434
+ } else
435
+ break;
436
+ else if (e[r] === "&") {
437
+ const d = ae(e, r);
438
+ if (d == -1)
439
+ return h("InvalidChar", "char '&' is not expected.", N(e, r));
440
+ r = d;
441
+ } else if (i === !0 && !P(e[r]))
442
+ return h("InvalidXml", "Extra text at the end", N(e, r));
443
+ e[r] === "<" && r--;
444
+ }
445
+ } else {
446
+ if (P(e[r]))
447
+ continue;
448
+ return h("InvalidChar", "char '" + e[r] + "' is not expected.", N(e, r));
449
+ }
450
+ if (o) {
451
+ if (n.length == 1)
452
+ return h("InvalidTag", "Unclosed tag '" + n[0].tagName + "'.", N(e, n[0].tagStartPos));
453
+ if (n.length > 0)
454
+ return h("InvalidXml", "Invalid '" + JSON.stringify(n.map((r) => r.tagName), null, 4).replace(/\r?\n/g, "") + "' found.", { line: 1, col: 1 });
455
+ } else return h("InvalidXml", "Start tag expected.", 1);
456
+ return !0;
457
+ };
458
+ function P(e) {
459
+ return e === " " || e === " " || e === `
460
+ ` || e === "\r";
461
+ }
462
+ function F(e, t) {
463
+ const n = t;
464
+ for (; t < e.length; t++)
465
+ if (e[t] == "?" || e[t] == " ") {
466
+ const o = e.substr(n, t - n);
467
+ if (t > 5 && o === "xml")
468
+ return h("InvalidXml", "XML declaration allowed only at the start of the document.", N(e, t));
469
+ if (e[t] == "?" && e[t + 1] == ">") {
470
+ t++;
471
+ break;
472
+ } else
473
+ continue;
474
+ }
475
+ return t;
476
+ }
477
+ function V(e, t) {
478
+ if (e.length > t + 5 && e[t + 1] === "-" && e[t + 2] === "-") {
479
+ for (t += 3; t < e.length; t++)
480
+ if (e[t] === "-" && e[t + 1] === "-" && e[t + 2] === ">") {
481
+ t += 2;
482
+ break;
483
+ }
484
+ } else if (e.length > t + 8 && e[t + 1] === "D" && e[t + 2] === "O" && e[t + 3] === "C" && e[t + 4] === "T" && e[t + 5] === "Y" && e[t + 6] === "P" && e[t + 7] === "E") {
485
+ let n = 1;
486
+ for (t += 8; t < e.length; t++)
487
+ if (e[t] === "<")
488
+ n++;
489
+ else if (e[t] === ">" && (n--, n === 0))
490
+ break;
491
+ } else if (e.length > t + 9 && e[t + 1] === "[" && e[t + 2] === "C" && e[t + 3] === "D" && e[t + 4] === "A" && e[t + 5] === "T" && e[t + 6] === "A" && e[t + 7] === "[") {
492
+ for (t += 8; t < e.length; t++)
493
+ if (e[t] === "]" && e[t + 1] === "]" && e[t + 2] === ">") {
494
+ t += 2;
495
+ break;
496
+ }
497
+ }
498
+ return t;
499
+ }
500
+ const ne = '"', se = "'";
501
+ function re(e, t) {
502
+ let n = "", o = "", i = !1;
503
+ for (; t < e.length; t++) {
504
+ if (e[t] === ne || e[t] === se)
505
+ o === "" ? o = e[t] : o !== e[t] || (o = "");
506
+ else if (e[t] === ">" && o === "") {
507
+ i = !0;
508
+ break;
509
+ }
510
+ n += e[t];
511
+ }
512
+ return o !== "" ? !1 : {
513
+ value: n,
514
+ index: t,
515
+ tagClosed: i
516
+ };
517
+ }
518
+ const ie = new RegExp(`(\\s*)([^\\s=]+)(\\s*=)?(\\s*(['"])(([\\s\\S])*?)\\5)?`, "g");
519
+ function $(e, t) {
520
+ const n = L.getAllMatches(e, ie), o = {};
521
+ for (let i = 0; i < n.length; i++) {
522
+ if (n[i][1].length === 0)
523
+ return h("InvalidAttr", "Attribute '" + n[i][2] + "' has no space in starting.", S(n[i]));
524
+ if (n[i][3] !== void 0 && n[i][4] === void 0)
525
+ return h("InvalidAttr", "Attribute '" + n[i][2] + "' is without value.", S(n[i]));
526
+ if (n[i][3] === void 0 && !t.allowBooleanAttributes)
527
+ return h("InvalidAttr", "boolean attribute '" + n[i][2] + "' is not allowed.", S(n[i]));
528
+ const r = n[i][2];
529
+ if (!ue(r))
530
+ return h("InvalidAttr", "Attribute '" + r + "' is an invalid name.", S(n[i]));
531
+ if (!o.hasOwnProperty(r))
532
+ o[r] = 1;
533
+ else
534
+ return h("InvalidAttr", "Attribute '" + r + "' is repeated.", S(n[i]));
535
+ }
536
+ return !0;
537
+ }
538
+ function oe(e, t) {
539
+ let n = /\d/;
540
+ for (e[t] === "x" && (t++, n = /[\da-fA-F]/); t < e.length; t++) {
541
+ if (e[t] === ";")
542
+ return t;
543
+ if (!e[t].match(n))
544
+ break;
545
+ }
546
+ return -1;
547
+ }
548
+ function ae(e, t) {
549
+ if (t++, e[t] === ";")
550
+ return -1;
551
+ if (e[t] === "#")
552
+ return t++, oe(e, t);
553
+ let n = 0;
554
+ for (; t < e.length; t++, n++)
555
+ if (!(e[t].match(/\w/) && n < 20)) {
556
+ if (e[t] === ";")
557
+ break;
558
+ return -1;
559
+ }
560
+ return t;
561
+ }
562
+ function h(e, t, n) {
563
+ return {
564
+ err: {
565
+ code: e,
566
+ msg: t,
567
+ line: n.line || n,
568
+ col: n.col
569
+ }
570
+ };
571
+ }
572
+ function ue(e) {
573
+ return L.isName(e);
574
+ }
575
+ function le(e) {
576
+ return L.isName(e);
577
+ }
578
+ function N(e, t) {
579
+ const n = e.substring(0, t).split(/\r?\n/);
580
+ return {
581
+ line: n.length,
582
+ // column number is last line's length + 1, because column numbering starts at 1:
583
+ col: n[n.length - 1].length + 1
584
+ };
585
+ }
586
+ function S(e) {
587
+ return e.startIndex + e[1].length;
588
+ }
589
+ var M = {};
590
+ const R = {
591
+ preserveOrder: !1,
592
+ attributeNamePrefix: "@_",
593
+ attributesGroupName: !1,
594
+ textNodeName: "#text",
595
+ ignoreAttributes: !0,
596
+ removeNSPrefix: !1,
597
+ // remove NS from tag name or attribute name if true
598
+ allowBooleanAttributes: !1,
599
+ //a tag can have attributes without any value
600
+ //ignoreRootElement : false,
601
+ parseTagValue: !0,
602
+ parseAttributeValue: !1,
603
+ trimValues: !0,
604
+ //Trim string values of tag and attributes
605
+ cdataPropName: !1,
606
+ numberParseOptions: {
607
+ hex: !0,
608
+ leadingZeros: !0,
609
+ eNotation: !0
610
+ },
611
+ tagValueProcessor: function(e, t) {
612
+ return t;
613
+ },
614
+ attributeValueProcessor: function(e, t) {
615
+ return t;
616
+ },
617
+ stopNodes: [],
618
+ //nested tags will not be parsed even for errors
619
+ alwaysCreateTextNode: !1,
620
+ isArray: () => !1,
621
+ commentPropName: !1,
622
+ unpairedTags: [],
623
+ processEntities: !0,
624
+ htmlEntities: !1,
625
+ ignoreDeclaration: !1,
626
+ ignorePiTags: !1,
627
+ transformTagName: !1,
628
+ transformAttributeName: !1,
629
+ updateTag: function(e, t, n) {
630
+ return e;
631
+ }
632
+ // skipEmptyListItem: false
633
+ }, ce = function(e) {
634
+ return Object.assign({}, R, e);
635
+ };
636
+ M.buildOptions = ce;
637
+ M.defaultOptions = R;
638
+ class fe {
639
+ constructor(t) {
640
+ this.tagname = t, this.child = [], this[":@"] = {};
641
+ }
642
+ add(t, n) {
643
+ t === "__proto__" && (t = "#__proto__"), this.child.push({ [t]: n });
644
+ }
645
+ addChild(t) {
646
+ t.tagname === "__proto__" && (t.tagname = "#__proto__"), t[":@"] && Object.keys(t[":@"]).length > 0 ? this.child.push({ [t.tagname]: t.child, ":@": t[":@"] }) : this.child.push({ [t.tagname]: t.child });
647
+ }
648
+ }
649
+ var de = fe;
650
+ const ge = T;
651
+ function he(e, t) {
652
+ const n = {};
653
+ if (e[t + 3] === "O" && e[t + 4] === "C" && e[t + 5] === "T" && e[t + 6] === "Y" && e[t + 7] === "P" && e[t + 8] === "E") {
654
+ t = t + 9;
655
+ let o = 1, i = !1, r = !1, l = "";
656
+ for (; t < e.length; t++)
657
+ if (e[t] === "<" && !r) {
658
+ if (i && be(e, t)) {
659
+ t += 7;
660
+ let u, a;
661
+ [u, a, t] = pe(e, t + 1), a.indexOf("&") === -1 && (n[Ae(u)] = {
662
+ regx: RegExp(`&${u};`, "g"),
663
+ val: a
664
+ });
665
+ } else if (i && Ne(e, t)) t += 8;
666
+ else if (i && ye(e, t)) t += 8;
667
+ else if (i && we(e, t)) t += 9;
668
+ else if (me) r = !0;
669
+ else throw new Error("Invalid DOCTYPE");
670
+ o++, l = "";
671
+ } else if (e[t] === ">") {
672
+ if (r ? e[t - 1] === "-" && e[t - 2] === "-" && (r = !1, o--) : o--, o === 0)
673
+ break;
674
+ } else e[t] === "[" ? i = !0 : l += e[t];
675
+ if (o !== 0)
676
+ throw new Error("Unclosed DOCTYPE");
677
+ } else
678
+ throw new Error("Invalid Tag instead of DOCTYPE");
679
+ return { entities: n, i: t };
680
+ }
681
+ function pe(e, t) {
682
+ let n = "";
683
+ for (; t < e.length && e[t] !== "'" && e[t] !== '"'; t++)
684
+ n += e[t];
685
+ if (n = n.trim(), n.indexOf(" ") !== -1) throw new Error("External entites are not supported");
686
+ const o = e[t++];
687
+ let i = "";
688
+ for (; t < e.length && e[t] !== o; t++)
689
+ i += e[t];
690
+ return [n, i, t];
691
+ }
692
+ function me(e, t) {
693
+ return e[t + 1] === "!" && e[t + 2] === "-" && e[t + 3] === "-";
694
+ }
695
+ function be(e, t) {
696
+ return e[t + 1] === "!" && e[t + 2] === "E" && e[t + 3] === "N" && e[t + 4] === "T" && e[t + 5] === "I" && e[t + 6] === "T" && e[t + 7] === "Y";
697
+ }
698
+ function Ne(e, t) {
699
+ return e[t + 1] === "!" && e[t + 2] === "E" && e[t + 3] === "L" && e[t + 4] === "E" && e[t + 5] === "M" && e[t + 6] === "E" && e[t + 7] === "N" && e[t + 8] === "T";
700
+ }
701
+ function ye(e, t) {
702
+ return e[t + 1] === "!" && e[t + 2] === "A" && e[t + 3] === "T" && e[t + 4] === "T" && e[t + 5] === "L" && e[t + 6] === "I" && e[t + 7] === "S" && e[t + 8] === "T";
703
+ }
704
+ function we(e, t) {
705
+ return e[t + 1] === "!" && e[t + 2] === "N" && e[t + 3] === "O" && e[t + 4] === "T" && e[t + 5] === "A" && e[t + 6] === "T" && e[t + 7] === "I" && e[t + 8] === "O" && e[t + 9] === "N";
706
+ }
707
+ function Ae(e) {
708
+ if (ge.isName(e))
709
+ return e;
710
+ throw new Error(`Invalid entity name ${e}`);
711
+ }
712
+ var _e = he;
713
+ const xe = /^[-+]?0x[a-fA-F0-9]+$/, Se = /^([\-\+])?(0*)(\.[0-9]+([eE]\-?[0-9]+)?|[0-9]+(\.[0-9]+([eE]\-?[0-9]+)?)?)$/;
714
+ !Number.parseInt && window.parseInt && (Number.parseInt = window.parseInt);
715
+ !Number.parseFloat && window.parseFloat && (Number.parseFloat = window.parseFloat);
716
+ const Ee = {
717
+ hex: !0,
718
+ leadingZeros: !0,
719
+ decimalPoint: ".",
720
+ eNotation: !0
721
+ //skipLike: /regex/
722
+ };
723
+ function Te(e, t = {}) {
724
+ if (t = Object.assign({}, Ee, t), !e || typeof e != "string") return e;
725
+ let n = e.trim();
726
+ if (t.skipLike !== void 0 && t.skipLike.test(n)) return e;
727
+ if (t.hex && xe.test(n))
728
+ return Number.parseInt(n, 16);
729
+ {
730
+ const o = Se.exec(n);
731
+ if (o) {
732
+ const i = o[1], r = o[2];
733
+ let l = Ie(o[3]);
734
+ const u = o[4] || o[6];
735
+ if (!t.leadingZeros && r.length > 0 && i && n[2] !== ".") return e;
736
+ if (!t.leadingZeros && r.length > 0 && !i && n[1] !== ".") return e;
737
+ {
738
+ const a = Number(n), f = "" + a;
739
+ return f.search(/[eE]/) !== -1 || u ? t.eNotation ? a : e : n.indexOf(".") !== -1 ? f === "0" && l === "" || f === l || i && f === "-" + l ? a : e : r ? l === f || i + l === f ? a : e : n === f || n === i + f ? a : e;
740
+ }
741
+ } else
742
+ return e;
743
+ }
744
+ }
745
+ function Ie(e) {
746
+ return e && e.indexOf(".") !== -1 && (e = e.replace(/0+$/, ""), e === "." ? e = "0" : e[0] === "." ? e = "0" + e : e[e.length - 1] === "." && (e = e.substr(0, e.length - 1))), e;
747
+ }
748
+ var Oe = Te;
749
+ function Ce(e) {
750
+ return typeof e == "function" ? e : Array.isArray(e) ? (t) => {
751
+ for (const n of e)
752
+ if (typeof n == "string" && t === n || n instanceof RegExp && n.test(t))
753
+ return !0;
754
+ } : () => !1;
755
+ }
756
+ var k = Ce;
757
+ const U = T, E = de, Le = _e, Me = Oe, je = k;
758
+ let ve = class {
759
+ constructor(t) {
760
+ this.options = t, this.currentNode = null, this.tagsNodeStack = [], this.docTypeEntities = {}, this.lastEntities = {
761
+ apos: { regex: /&(apos|#39|#x27);/g, val: "'" },
762
+ gt: { regex: /&(gt|#62|#x3E);/g, val: ">" },
763
+ lt: { regex: /&(lt|#60|#x3C);/g, val: "<" },
764
+ quot: { regex: /&(quot|#34|#x22);/g, val: '"' }
765
+ }, this.ampEntity = { regex: /&(amp|#38|#x26);/g, val: "&" }, this.htmlEntities = {
766
+ space: { regex: /&(nbsp|#160);/g, val: " " },
767
+ // "lt" : { regex: /&(lt|#60);/g, val: "<" },
768
+ // "gt" : { regex: /&(gt|#62);/g, val: ">" },
769
+ // "amp" : { regex: /&(amp|#38);/g, val: "&" },
770
+ // "quot" : { regex: /&(quot|#34);/g, val: "\"" },
771
+ // "apos" : { regex: /&(apos|#39);/g, val: "'" },
772
+ cent: { regex: /&(cent|#162);/g, val: "¢" },
773
+ pound: { regex: /&(pound|#163);/g, val: "£" },
774
+ yen: { regex: /&(yen|#165);/g, val: "¥" },
775
+ euro: { regex: /&(euro|#8364);/g, val: "€" },
776
+ copyright: { regex: /&(copy|#169);/g, val: "©" },
777
+ reg: { regex: /&(reg|#174);/g, val: "®" },
778
+ inr: { regex: /&(inr|#8377);/g, val: "₹" },
779
+ num_dec: { regex: /&#([0-9]{1,7});/g, val: (n, o) => String.fromCharCode(Number.parseInt(o, 10)) },
780
+ num_hex: { regex: /&#x([0-9a-fA-F]{1,6});/g, val: (n, o) => String.fromCharCode(Number.parseInt(o, 16)) }
781
+ }, this.addExternalEntities = Pe, this.parseXml = Be, this.parseTextData = Fe, this.resolveNameSpace = Ve, this.buildAttributesMap = Xe, this.isItStopNode = Ge, this.replaceEntitiesValue = ke, this.readStopNodeData = Je, this.saveTextToParentTag = Ue, this.addChild = Re, this.ignoreAttributesFn = je(this.options.ignoreAttributes);
782
+ }
783
+ };
784
+ function Pe(e) {
785
+ const t = Object.keys(e);
786
+ for (let n = 0; n < t.length; n++) {
787
+ const o = t[n];
788
+ this.lastEntities[o] = {
789
+ regex: new RegExp("&" + o + ";", "g"),
790
+ val: e[o]
791
+ };
792
+ }
793
+ }
794
+ function Fe(e, t, n, o, i, r, l) {
795
+ if (e !== void 0 && (this.options.trimValues && !o && (e = e.trim()), e.length > 0)) {
796
+ l || (e = this.replaceEntitiesValue(e));
797
+ const u = this.options.tagValueProcessor(t, e, n, i, r);
798
+ return u == null ? e : typeof u != typeof e || u !== e ? u : this.options.trimValues ? O(e, this.options.parseTagValue, this.options.numberParseOptions) : e.trim() === e ? O(e, this.options.parseTagValue, this.options.numberParseOptions) : e;
799
+ }
800
+ }
801
+ function Ve(e) {
802
+ if (this.options.removeNSPrefix) {
803
+ const t = e.split(":"), n = e.charAt(0) === "/" ? "/" : "";
804
+ if (t[0] === "xmlns")
805
+ return "";
806
+ t.length === 2 && (e = n + t[1]);
807
+ }
808
+ return e;
809
+ }
810
+ const $e = new RegExp(`([^\\s=]+)\\s*(=\\s*(['"])([\\s\\S]*?)\\3)?`, "gm");
811
+ function Xe(e, t, n) {
812
+ if (this.options.ignoreAttributes !== !0 && typeof e == "string") {
813
+ const o = U.getAllMatches(e, $e), i = o.length, r = {};
814
+ for (let l = 0; l < i; l++) {
815
+ const u = this.resolveNameSpace(o[l][1]);
816
+ if (this.ignoreAttributesFn(u, t))
817
+ continue;
818
+ let a = o[l][4], f = this.options.attributeNamePrefix + u;
819
+ if (u.length)
820
+ if (this.options.transformAttributeName && (f = this.options.transformAttributeName(f)), f === "__proto__" && (f = "#__proto__"), a !== void 0) {
821
+ this.options.trimValues && (a = a.trim()), a = this.replaceEntitiesValue(a);
822
+ const c = this.options.attributeValueProcessor(u, a, t);
823
+ c == null ? r[f] = a : typeof c != typeof a || c !== a ? r[f] = c : r[f] = O(
824
+ a,
825
+ this.options.parseAttributeValue,
826
+ this.options.numberParseOptions
827
+ );
828
+ } else this.options.allowBooleanAttributes && (r[f] = !0);
829
+ }
830
+ if (!Object.keys(r).length)
831
+ return;
832
+ if (this.options.attributesGroupName) {
833
+ const l = {};
834
+ return l[this.options.attributesGroupName] = r, l;
835
+ }
836
+ return r;
837
+ }
838
+ }
839
+ const Be = function(e) {
840
+ e = e.replace(/\r\n?/g, `
841
+ `);
842
+ const t = new E("!xml");
843
+ let n = t, o = "", i = "";
844
+ for (let r = 0; r < e.length; r++)
845
+ if (e[r] === "<")
846
+ if (e[r + 1] === "/") {
847
+ const u = _(e, ">", r, "Closing Tag is not closed.");
848
+ let a = e.substring(r + 2, u).trim();
849
+ if (this.options.removeNSPrefix) {
850
+ const d = a.indexOf(":");
851
+ d !== -1 && (a = a.substr(d + 1));
852
+ }
853
+ this.options.transformTagName && (a = this.options.transformTagName(a)), n && (o = this.saveTextToParentTag(o, n, i));
854
+ const f = i.substring(i.lastIndexOf(".") + 1);
855
+ if (a && this.options.unpairedTags.indexOf(a) !== -1)
856
+ throw new Error(`Unpaired tag can not be used as closing tag: </${a}>`);
857
+ let c = 0;
858
+ f && this.options.unpairedTags.indexOf(f) !== -1 ? (c = i.lastIndexOf(".", i.lastIndexOf(".") - 1), this.tagsNodeStack.pop()) : c = i.lastIndexOf("."), i = i.substring(0, c), n = this.tagsNodeStack.pop(), o = "", r = u;
859
+ } else if (e[r + 1] === "?") {
860
+ let u = I(e, r, !1, "?>");
861
+ if (!u) throw new Error("Pi Tag is not closed.");
862
+ if (o = this.saveTextToParentTag(o, n, i), !(this.options.ignoreDeclaration && u.tagName === "?xml" || this.options.ignorePiTags)) {
863
+ const a = new E(u.tagName);
864
+ a.add(this.options.textNodeName, ""), u.tagName !== u.tagExp && u.attrExpPresent && (a[":@"] = this.buildAttributesMap(u.tagExp, i, u.tagName)), this.addChild(n, a, i);
865
+ }
866
+ r = u.closeIndex + 1;
867
+ } else if (e.substr(r + 1, 3) === "!--") {
868
+ const u = _(e, "-->", r + 4, "Comment is not closed.");
869
+ if (this.options.commentPropName) {
870
+ const a = e.substring(r + 4, u - 2);
871
+ o = this.saveTextToParentTag(o, n, i), n.add(this.options.commentPropName, [{ [this.options.textNodeName]: a }]);
872
+ }
873
+ r = u;
874
+ } else if (e.substr(r + 1, 2) === "!D") {
875
+ const u = Le(e, r);
876
+ this.docTypeEntities = u.entities, r = u.i;
877
+ } else if (e.substr(r + 1, 2) === "![") {
878
+ const u = _(e, "]]>", r, "CDATA is not closed.") - 2, a = e.substring(r + 9, u);
879
+ o = this.saveTextToParentTag(o, n, i);
880
+ let f = this.parseTextData(a, n.tagname, i, !0, !1, !0, !0);
881
+ f == null && (f = ""), this.options.cdataPropName ? n.add(this.options.cdataPropName, [{ [this.options.textNodeName]: a }]) : n.add(this.options.textNodeName, f), r = u + 2;
882
+ } else {
883
+ let u = I(e, r, this.options.removeNSPrefix), a = u.tagName;
884
+ const f = u.rawTagName;
885
+ let c = u.tagExp, d = u.attrExpPresent, g = u.closeIndex;
886
+ this.options.transformTagName && (a = this.options.transformTagName(a)), n && o && n.tagname !== "!xml" && (o = this.saveTextToParentTag(o, n, i, !1));
887
+ const m = n;
888
+ if (m && this.options.unpairedTags.indexOf(m.tagname) !== -1 && (n = this.tagsNodeStack.pop(), i = i.substring(0, i.lastIndexOf("."))), a !== t.tagname && (i += i ? "." + a : a), this.isItStopNode(this.options.stopNodes, i, a)) {
889
+ let p = "";
890
+ if (c.length > 0 && c.lastIndexOf("/") === c.length - 1)
891
+ a[a.length - 1] === "/" ? (a = a.substr(0, a.length - 1), i = i.substr(0, i.length - 1), c = a) : c = c.substr(0, c.length - 1), r = u.closeIndex;
892
+ else if (this.options.unpairedTags.indexOf(a) !== -1)
893
+ r = u.closeIndex;
894
+ else {
895
+ const y = this.readStopNodeData(e, f, g + 1);
896
+ if (!y) throw new Error(`Unexpected end of ${f}`);
897
+ r = y.i, p = y.tagContent;
898
+ }
899
+ const x = new E(a);
900
+ a !== c && d && (x[":@"] = this.buildAttributesMap(c, i, a)), p && (p = this.parseTextData(p, a, i, !0, d, !0, !0)), i = i.substr(0, i.lastIndexOf(".")), x.add(this.options.textNodeName, p), this.addChild(n, x, i);
901
+ } else {
902
+ if (c.length > 0 && c.lastIndexOf("/") === c.length - 1) {
903
+ a[a.length - 1] === "/" ? (a = a.substr(0, a.length - 1), i = i.substr(0, i.length - 1), c = a) : c = c.substr(0, c.length - 1), this.options.transformTagName && (a = this.options.transformTagName(a));
904
+ const p = new E(a);
905
+ a !== c && d && (p[":@"] = this.buildAttributesMap(c, i, a)), this.addChild(n, p, i), i = i.substr(0, i.lastIndexOf("."));
906
+ } else {
907
+ const p = new E(a);
908
+ this.tagsNodeStack.push(n), a !== c && d && (p[":@"] = this.buildAttributesMap(c, i, a)), this.addChild(n, p, i), n = p;
909
+ }
910
+ o = "", r = g;
911
+ }
912
+ }
913
+ else
914
+ o += e[r];
915
+ return t.child;
916
+ };
917
+ function Re(e, t, n) {
918
+ const o = this.options.updateTag(t.tagname, n, t[":@"]);
919
+ o === !1 || (typeof o == "string" && (t.tagname = o), e.addChild(t));
920
+ }
921
+ const ke = function(e) {
922
+ if (this.options.processEntities) {
923
+ for (let t in this.docTypeEntities) {
924
+ const n = this.docTypeEntities[t];
925
+ e = e.replace(n.regx, n.val);
926
+ }
927
+ for (let t in this.lastEntities) {
928
+ const n = this.lastEntities[t];
929
+ e = e.replace(n.regex, n.val);
930
+ }
931
+ if (this.options.htmlEntities)
932
+ for (let t in this.htmlEntities) {
933
+ const n = this.htmlEntities[t];
934
+ e = e.replace(n.regex, n.val);
935
+ }
936
+ e = e.replace(this.ampEntity.regex, this.ampEntity.val);
937
+ }
938
+ return e;
939
+ };
940
+ function Ue(e, t, n, o) {
941
+ return e && (o === void 0 && (o = Object.keys(t.child).length === 0), e = this.parseTextData(
942
+ e,
943
+ t.tagname,
944
+ n,
945
+ !1,
946
+ t[":@"] ? Object.keys(t[":@"]).length !== 0 : !1,
947
+ o
948
+ ), e !== void 0 && e !== "" && t.add(this.options.textNodeName, e), e = ""), e;
949
+ }
950
+ function Ge(e, t, n) {
951
+ const o = "*." + n;
952
+ for (const i in e) {
953
+ const r = e[i];
954
+ if (o === r || t === r) return !0;
955
+ }
956
+ return !1;
957
+ }
958
+ function Ke(e, t, n = ">") {
959
+ let o, i = "";
960
+ for (let r = t; r < e.length; r++) {
961
+ let l = e[r];
962
+ if (o)
963
+ l === o && (o = "");
964
+ else if (l === '"' || l === "'")
965
+ o = l;
966
+ else if (l === n[0])
967
+ if (n[1]) {
968
+ if (e[r + 1] === n[1])
969
+ return {
970
+ data: i,
971
+ index: r
972
+ };
973
+ } else
974
+ return {
975
+ data: i,
976
+ index: r
977
+ };
978
+ else l === " " && (l = " ");
979
+ i += l;
980
+ }
981
+ }
982
+ function _(e, t, n, o) {
983
+ const i = e.indexOf(t, n);
984
+ if (i === -1)
985
+ throw new Error(o);
986
+ return i + t.length - 1;
987
+ }
988
+ function I(e, t, n, o = ">") {
989
+ const i = Ke(e, t + 1, o);
990
+ if (!i) return;
991
+ let r = i.data;
992
+ const l = i.index, u = r.search(/\s/);
993
+ let a = r, f = !0;
994
+ u !== -1 && (a = r.substring(0, u), r = r.substring(u + 1).trimStart());
995
+ const c = a;
996
+ if (n) {
997
+ const d = a.indexOf(":");
998
+ d !== -1 && (a = a.substr(d + 1), f = a !== i.data.substr(d + 1));
999
+ }
1000
+ return {
1001
+ tagName: a,
1002
+ tagExp: r,
1003
+ closeIndex: l,
1004
+ attrExpPresent: f,
1005
+ rawTagName: c
1006
+ };
1007
+ }
1008
+ function Je(e, t, n) {
1009
+ const o = n;
1010
+ let i = 1;
1011
+ for (; n < e.length; n++)
1012
+ if (e[n] === "<")
1013
+ if (e[n + 1] === "/") {
1014
+ const r = _(e, ">", n, `${t} is not closed`);
1015
+ if (e.substring(n + 2, r).trim() === t && (i--, i === 0))
1016
+ return {
1017
+ tagContent: e.substring(o, n),
1018
+ i: r
1019
+ };
1020
+ n = r;
1021
+ } else if (e[n + 1] === "?")
1022
+ n = _(e, "?>", n + 1, "StopNode is not closed.");
1023
+ else if (e.substr(n + 1, 3) === "!--")
1024
+ n = _(e, "-->", n + 3, "StopNode is not closed.");
1025
+ else if (e.substr(n + 1, 2) === "![")
1026
+ n = _(e, "]]>", n, "StopNode is not closed.") - 2;
1027
+ else {
1028
+ const r = I(e, n, ">");
1029
+ r && ((r && r.tagName) === t && r.tagExp[r.tagExp.length - 1] !== "/" && i++, n = r.closeIndex);
1030
+ }
1031
+ }
1032
+ function O(e, t, n) {
1033
+ if (t && typeof e == "string") {
1034
+ const o = e.trim();
1035
+ return o === "true" ? !0 : o === "false" ? !1 : Me(e, n);
1036
+ } else
1037
+ return U.isExist(e) ? e : "";
1038
+ }
1039
+ var qe = ve, G = {};
1040
+ function Ze(e, t) {
1041
+ return K(e, t);
1042
+ }
1043
+ function K(e, t, n) {
1044
+ let o;
1045
+ const i = {};
1046
+ for (let r = 0; r < e.length; r++) {
1047
+ const l = e[r], u = He(l);
1048
+ let a = "";
1049
+ if (n === void 0 ? a = u : a = n + "." + u, u === t.textNodeName)
1050
+ o === void 0 ? o = l[u] : o += "" + l[u];
1051
+ else {
1052
+ if (u === void 0)
1053
+ continue;
1054
+ if (l[u]) {
1055
+ let f = K(l[u], t, a);
1056
+ const c = Qe(f, t);
1057
+ l[":@"] ? Ye(f, l[":@"], a, t) : Object.keys(f).length === 1 && f[t.textNodeName] !== void 0 && !t.alwaysCreateTextNode ? f = f[t.textNodeName] : Object.keys(f).length === 0 && (t.alwaysCreateTextNode ? f[t.textNodeName] = "" : f = ""), i[u] !== void 0 && i.hasOwnProperty(u) ? (Array.isArray(i[u]) || (i[u] = [i[u]]), i[u].push(f)) : t.isArray(u, a, c) ? i[u] = [f] : i[u] = f;
1058
+ }
1059
+ }
1060
+ }
1061
+ return typeof o == "string" ? o.length > 0 && (i[t.textNodeName] = o) : o !== void 0 && (i[t.textNodeName] = o), i;
1062
+ }
1063
+ function He(e) {
1064
+ const t = Object.keys(e);
1065
+ for (let n = 0; n < t.length; n++) {
1066
+ const o = t[n];
1067
+ if (o !== ":@") return o;
1068
+ }
1069
+ }
1070
+ function Ye(e, t, n, o) {
1071
+ if (t) {
1072
+ const i = Object.keys(t), r = i.length;
1073
+ for (let l = 0; l < r; l++) {
1074
+ const u = i[l];
1075
+ o.isArray(u, n + "." + u, !0, !0) ? e[u] = [t[u]] : e[u] = t[u];
1076
+ }
1077
+ }
1078
+ }
1079
+ function Qe(e, t) {
1080
+ const { textNodeName: n } = t, o = Object.keys(e).length;
1081
+ return !!(o === 0 || o === 1 && (e[n] || typeof e[n] == "boolean" || e[n] === 0));
1082
+ }
1083
+ G.prettify = Ze;
1084
+ const { buildOptions: We } = M, ze = qe, { prettify: De } = G, et = C;
1085
+ let tt = class {
1086
+ constructor(t) {
1087
+ this.externalEntities = {}, this.options = We(t);
1088
+ }
1089
+ /**
1090
+ * Parse XML dats to JS object
1091
+ * @param {string|Buffer} xmlData
1092
+ * @param {boolean|Object} validationOption
1093
+ */
1094
+ parse(t, n) {
1095
+ if (typeof t != "string") if (t.toString)
1096
+ t = t.toString();
1097
+ else
1098
+ throw new Error("XML data is accepted in String or Bytes[] form.");
1099
+ if (n) {
1100
+ n === !0 && (n = {});
1101
+ const r = et.validate(t, n);
1102
+ if (r !== !0)
1103
+ throw Error(`${r.err.msg}:${r.err.line}:${r.err.col}`);
1104
+ }
1105
+ const o = new ze(this.options);
1106
+ o.addExternalEntities(this.externalEntities);
1107
+ const i = o.parseXml(t);
1108
+ return this.options.preserveOrder || i === void 0 ? i : De(i, this.options);
1109
+ }
1110
+ /**
1111
+ * Add Entity which is not by default supported by this library
1112
+ * @param {string} key
1113
+ * @param {string} value
1114
+ */
1115
+ addEntity(t, n) {
1116
+ if (n.indexOf("&") !== -1)
1117
+ throw new Error("Entity value can't have '&'");
1118
+ if (t.indexOf("&") !== -1 || t.indexOf(";") !== -1)
1119
+ throw new Error("An entity must be set without '&' and ';'. Eg. use '#xD' for '&#xD;'");
1120
+ if (n === "&")
1121
+ throw new Error("An entity with value '&' is not permitted");
1122
+ this.externalEntities[t] = n;
1123
+ }
1124
+ };
1125
+ var nt = tt;
1126
+ const st = `
1127
+ `;
1128
+ function rt(e, t) {
1129
+ let n = "";
1130
+ return t.format && t.indentBy.length > 0 && (n = st), J(e, t, "", n);
1131
+ }
1132
+ function J(e, t, n, o) {
1133
+ let i = "", r = !1;
1134
+ for (let l = 0; l < e.length; l++) {
1135
+ const u = e[l], a = it(u);
1136
+ if (a === void 0) continue;
1137
+ let f = "";
1138
+ if (n.length === 0 ? f = a : f = `${n}.${a}`, a === t.textNodeName) {
1139
+ let p = u[a];
1140
+ ot(f, t) || (p = t.tagValueProcessor(a, p), p = q(p, t)), r && (i += o), i += p, r = !1;
1141
+ continue;
1142
+ } else if (a === t.cdataPropName) {
1143
+ r && (i += o), i += `<![CDATA[${u[a][0][t.textNodeName]}]]>`, r = !1;
1144
+ continue;
1145
+ } else if (a === t.commentPropName) {
1146
+ i += o + `<!--${u[a][0][t.textNodeName]}-->`, r = !0;
1147
+ continue;
1148
+ } else if (a[0] === "?") {
1149
+ const p = X(u[":@"], t), x = a === "?xml" ? "" : o;
1150
+ let y = u[a][0][t.textNodeName];
1151
+ y = y.length !== 0 ? " " + y : "", i += x + `<${a}${y}${p}?>`, r = !0;
1152
+ continue;
1153
+ }
1154
+ let c = o;
1155
+ c !== "" && (c += t.indentBy);
1156
+ const d = X(u[":@"], t), g = o + `<${a}${d}`, m = J(u[a], t, f, c);
1157
+ t.unpairedTags.indexOf(a) !== -1 ? t.suppressUnpairedNode ? i += g + ">" : i += g + "/>" : (!m || m.length === 0) && t.suppressEmptyNode ? i += g + "/>" : m && m.endsWith(">") ? i += g + `>${m}${o}</${a}>` : (i += g + ">", m && o !== "" && (m.includes("/>") || m.includes("</")) ? i += o + t.indentBy + m + o : i += m, i += `</${a}>`), r = !0;
1158
+ }
1159
+ return i;
1160
+ }
1161
+ function it(e) {
1162
+ const t = Object.keys(e);
1163
+ for (let n = 0; n < t.length; n++) {
1164
+ const o = t[n];
1165
+ if (e.hasOwnProperty(o) && o !== ":@")
1166
+ return o;
1167
+ }
1168
+ }
1169
+ function X(e, t) {
1170
+ let n = "";
1171
+ if (e && !t.ignoreAttributes)
1172
+ for (let o in e) {
1173
+ if (!e.hasOwnProperty(o)) continue;
1174
+ let i = t.attributeValueProcessor(o, e[o]);
1175
+ i = q(i, t), i === !0 && t.suppressBooleanAttributes ? n += ` ${o.substr(t.attributeNamePrefix.length)}` : n += ` ${o.substr(t.attributeNamePrefix.length)}="${i}"`;
1176
+ }
1177
+ return n;
1178
+ }
1179
+ function ot(e, t) {
1180
+ e = e.substr(0, e.length - t.textNodeName.length - 1);
1181
+ let n = e.substr(e.lastIndexOf(".") + 1);
1182
+ for (let o in t.stopNodes)
1183
+ if (t.stopNodes[o] === e || t.stopNodes[o] === "*." + n) return !0;
1184
+ return !1;
1185
+ }
1186
+ function q(e, t) {
1187
+ if (e && e.length > 0 && t.processEntities)
1188
+ for (let n = 0; n < t.entities.length; n++) {
1189
+ const o = t.entities[n];
1190
+ e = e.replace(o.regex, o.val);
1191
+ }
1192
+ return e;
1193
+ }
1194
+ var at = rt;
1195
+ const ut = at, lt = k, ct = {
1196
+ attributeNamePrefix: "@_",
1197
+ attributesGroupName: !1,
1198
+ textNodeName: "#text",
1199
+ ignoreAttributes: !0,
1200
+ cdataPropName: !1,
1201
+ format: !1,
1202
+ indentBy: " ",
1203
+ suppressEmptyNode: !1,
1204
+ suppressUnpairedNode: !0,
1205
+ suppressBooleanAttributes: !0,
1206
+ tagValueProcessor: function(e, t) {
1207
+ return t;
1208
+ },
1209
+ attributeValueProcessor: function(e, t) {
1210
+ return t;
1211
+ },
1212
+ preserveOrder: !1,
1213
+ commentPropName: !1,
1214
+ unpairedTags: [],
1215
+ entities: [
1216
+ { regex: new RegExp("&", "g"), val: "&amp;" },
1217
+ //it must be on top
1218
+ { regex: new RegExp(">", "g"), val: "&gt;" },
1219
+ { regex: new RegExp("<", "g"), val: "&lt;" },
1220
+ { regex: new RegExp("'", "g"), val: "&apos;" },
1221
+ { regex: new RegExp('"', "g"), val: "&quot;" }
1222
+ ],
1223
+ processEntities: !0,
1224
+ stopNodes: [],
1225
+ // transformTagName: false,
1226
+ // transformAttributeName: false,
1227
+ oneListGroup: !1
1228
+ };
1229
+ function w(e) {
1230
+ this.options = Object.assign({}, ct, e), this.options.ignoreAttributes === !0 || this.options.attributesGroupName ? this.isAttribute = function() {
1231
+ return !1;
1232
+ } : (this.ignoreAttributesFn = lt(this.options.ignoreAttributes), this.attrPrefixLen = this.options.attributeNamePrefix.length, this.isAttribute = gt), this.processTextOrObjNode = ft, this.options.format ? (this.indentate = dt, this.tagEndChar = `>
1233
+ `, this.newLine = `
1234
+ `) : (this.indentate = function() {
1235
+ return "";
1236
+ }, this.tagEndChar = ">", this.newLine = "");
1237
+ }
1238
+ w.prototype.build = function(e) {
1239
+ return this.options.preserveOrder ? ut(e, this.options) : (Array.isArray(e) && this.options.arrayNodeName && this.options.arrayNodeName.length > 1 && (e = {
1240
+ [this.options.arrayNodeName]: e
1241
+ }), this.j2x(e, 0, []).val);
1242
+ };
1243
+ w.prototype.j2x = function(e, t, n) {
1244
+ let o = "", i = "";
1245
+ const r = n.join(".");
1246
+ for (let l in e)
1247
+ if (Object.prototype.hasOwnProperty.call(e, l))
1248
+ if (typeof e[l] > "u")
1249
+ this.isAttribute(l) && (i += "");
1250
+ else if (e[l] === null)
1251
+ this.isAttribute(l) ? i += "" : l[0] === "?" ? i += this.indentate(t) + "<" + l + "?" + this.tagEndChar : i += this.indentate(t) + "<" + l + "/" + this.tagEndChar;
1252
+ else if (e[l] instanceof Date)
1253
+ i += this.buildTextValNode(e[l], l, "", t);
1254
+ else if (typeof e[l] != "object") {
1255
+ const u = this.isAttribute(l);
1256
+ if (u && !this.ignoreAttributesFn(u, r))
1257
+ o += this.buildAttrPairStr(u, "" + e[l]);
1258
+ else if (!u)
1259
+ if (l === this.options.textNodeName) {
1260
+ let a = this.options.tagValueProcessor(l, "" + e[l]);
1261
+ i += this.replaceEntitiesValue(a);
1262
+ } else
1263
+ i += this.buildTextValNode(e[l], l, "", t);
1264
+ } else if (Array.isArray(e[l])) {
1265
+ const u = e[l].length;
1266
+ let a = "", f = "";
1267
+ for (let c = 0; c < u; c++) {
1268
+ const d = e[l][c];
1269
+ if (!(typeof d > "u")) if (d === null)
1270
+ l[0] === "?" ? i += this.indentate(t) + "<" + l + "?" + this.tagEndChar : i += this.indentate(t) + "<" + l + "/" + this.tagEndChar;
1271
+ else if (typeof d == "object")
1272
+ if (this.options.oneListGroup) {
1273
+ const g = this.j2x(d, t + 1, n.concat(l));
1274
+ a += g.val, this.options.attributesGroupName && d.hasOwnProperty(this.options.attributesGroupName) && (f += g.attrStr);
1275
+ } else
1276
+ a += this.processTextOrObjNode(d, l, t, n);
1277
+ else if (this.options.oneListGroup) {
1278
+ let g = this.options.tagValueProcessor(l, d);
1279
+ g = this.replaceEntitiesValue(g), a += g;
1280
+ } else
1281
+ a += this.buildTextValNode(d, l, "", t);
1282
+ }
1283
+ this.options.oneListGroup && (a = this.buildObjectNode(a, l, f, t)), i += a;
1284
+ } else if (this.options.attributesGroupName && l === this.options.attributesGroupName) {
1285
+ const u = Object.keys(e[l]), a = u.length;
1286
+ for (let f = 0; f < a; f++)
1287
+ o += this.buildAttrPairStr(u[f], "" + e[l][u[f]]);
1288
+ } else
1289
+ i += this.processTextOrObjNode(e[l], l, t, n);
1290
+ return { attrStr: o, val: i };
1291
+ };
1292
+ w.prototype.buildAttrPairStr = function(e, t) {
1293
+ return t = this.options.attributeValueProcessor(e, "" + t), t = this.replaceEntitiesValue(t), this.options.suppressBooleanAttributes && t === "true" ? " " + e : " " + e + '="' + t + '"';
1294
+ };
1295
+ function ft(e, t, n, o) {
1296
+ const i = this.j2x(e, n + 1, o.concat(t));
1297
+ return e[this.options.textNodeName] !== void 0 && Object.keys(e).length === 1 ? this.buildTextValNode(e[this.options.textNodeName], t, i.attrStr, n) : this.buildObjectNode(i.val, t, i.attrStr, n);
1298
+ }
1299
+ w.prototype.buildObjectNode = function(e, t, n, o) {
1300
+ if (e === "")
1301
+ return t[0] === "?" ? this.indentate(o) + "<" + t + n + "?" + this.tagEndChar : this.indentate(o) + "<" + t + n + this.closeTag(t) + this.tagEndChar;
1302
+ {
1303
+ let i = "</" + t + this.tagEndChar, r = "";
1304
+ return t[0] === "?" && (r = "?", i = ""), (n || n === "") && e.indexOf("<") === -1 ? this.indentate(o) + "<" + t + n + r + ">" + e + i : this.options.commentPropName !== !1 && t === this.options.commentPropName && r.length === 0 ? this.indentate(o) + `<!--${e}-->` + this.newLine : this.indentate(o) + "<" + t + n + r + this.tagEndChar + e + this.indentate(o) + i;
1305
+ }
1306
+ };
1307
+ w.prototype.closeTag = function(e) {
1308
+ let t = "";
1309
+ return this.options.unpairedTags.indexOf(e) !== -1 ? this.options.suppressUnpairedNode || (t = "/") : this.options.suppressEmptyNode ? t = "/" : t = `></${e}`, t;
1310
+ };
1311
+ w.prototype.buildTextValNode = function(e, t, n, o) {
1312
+ if (this.options.cdataPropName !== !1 && t === this.options.cdataPropName)
1313
+ return this.indentate(o) + `<![CDATA[${e}]]>` + this.newLine;
1314
+ if (this.options.commentPropName !== !1 && t === this.options.commentPropName)
1315
+ return this.indentate(o) + `<!--${e}-->` + this.newLine;
1316
+ if (t[0] === "?")
1317
+ return this.indentate(o) + "<" + t + n + "?" + this.tagEndChar;
1318
+ {
1319
+ let i = this.options.tagValueProcessor(t, e);
1320
+ return i = this.replaceEntitiesValue(i), i === "" ? this.indentate(o) + "<" + t + n + this.closeTag(t) + this.tagEndChar : this.indentate(o) + "<" + t + n + ">" + i + "</" + t + this.tagEndChar;
1321
+ }
1322
+ };
1323
+ w.prototype.replaceEntitiesValue = function(e) {
1324
+ if (e && e.length > 0 && this.options.processEntities)
1325
+ for (let t = 0; t < this.options.entities.length; t++) {
1326
+ const n = this.options.entities[t];
1327
+ e = e.replace(n.regex, n.val);
1328
+ }
1329
+ return e;
1330
+ };
1331
+ function dt(e) {
1332
+ return this.options.indentBy.repeat(e);
1333
+ }
1334
+ function gt(e) {
1335
+ return e.startsWith(this.options.attributeNamePrefix) && e !== this.options.textNodeName ? e.substr(this.attrPrefixLen) : !1;
1336
+ }
1337
+ var ht = w;
1338
+ const pt = C, mt = nt, bt = ht;
1339
+ var j = {
1340
+ XMLParser: mt,
1341
+ XMLValidator: pt,
1342
+ XMLBuilder: bt
1343
+ };
1344
+ class Z {
1345
+ constructor(t, n) {
1346
+ A(this, "alphabet");
1347
+ A(this, "padding");
1348
+ A(this, "decodeMap", /* @__PURE__ */ new Map());
1349
+ if (t.length !== 32)
1350
+ throw new Error("Invalid alphabet");
1351
+ if (this.alphabet = t, this.padding = (n == null ? void 0 : n.padding) ?? "=", this.alphabet.includes(this.padding) || this.padding.length !== 1)
1352
+ throw new Error("Invalid padding");
1353
+ for (let o = 0; o < t.length; o++)
1354
+ this.decodeMap.set(t[o], o);
1355
+ }
1356
+ encode(t, n) {
1357
+ let o = "", i = 0, r = 0;
1358
+ for (let u = 0; u < t.length; u++)
1359
+ for (i = i << 8 | t[u], r += 8; r >= 5; )
1360
+ r -= 5, o += this.alphabet[i >> r & 31];
1361
+ if (r > 0 && (o += this.alphabet[i << 5 - r & 31]), (n == null ? void 0 : n.includePadding) ?? !0) {
1362
+ const u = (8 - o.length % 8) % 8;
1363
+ for (let a = 0; a < u; a++)
1364
+ o += "=";
1365
+ }
1366
+ return o;
1367
+ }
1368
+ decode(t, n) {
1369
+ const o = (n == null ? void 0 : n.strict) ?? !0, i = Math.ceil(t.length / 8), r = [];
1370
+ for (let l = 0; l < i; l++) {
1371
+ let u = 0;
1372
+ const a = [];
1373
+ for (let c = 0; c < 8; c++) {
1374
+ const d = t[l * 8 + c];
1375
+ if (d === "=") {
1376
+ if (l + 1 !== i)
1377
+ throw new Error(`Invalid character: ${d}`);
1378
+ u += 1;
1379
+ continue;
1380
+ }
1381
+ if (d === void 0) {
1382
+ if (o)
1383
+ throw new Error("Invalid data");
1384
+ u += 1;
1385
+ continue;
1386
+ }
1387
+ const g = this.decodeMap.get(d) ?? null;
1388
+ if (g === null)
1389
+ throw new Error(`Invalid character: ${d}`);
1390
+ a.push(g);
1391
+ }
1392
+ if (u === 8 || u === 7 || u === 5 || u === 2)
1393
+ throw new Error("Invalid padding");
1394
+ const f = (a[0] << 3) + (a[1] >> 2);
1395
+ if (r.push(f), u < 6) {
1396
+ const c = ((a[1] & 3) << 6) + (a[2] << 1) + (a[3] >> 4);
1397
+ r.push(c);
1398
+ }
1399
+ if (u < 4) {
1400
+ const c = ((a[3] & 255) << 4) + (a[4] >> 1);
1401
+ r.push(c);
1402
+ }
1403
+ if (u < 3) {
1404
+ const c = ((a[4] & 1) << 7) + (a[5] << 2) + (a[6] >> 3);
1405
+ r.push(c);
1406
+ }
1407
+ if (u < 1) {
1408
+ const c = ((a[6] & 7) << 5) + a[7];
1409
+ r.push(c);
1410
+ }
1411
+ }
1412
+ return Uint8Array.from(r);
1413
+ }
1414
+ }
1415
+ new Z("ABCDEFGHIJKLMNOPQRSTUVWXYZ234567");
1416
+ new Z("0123456789ABCDEFGHIJKLMNOPQRSTUV");
1417
+ class H {
1418
+ constructor(t, n) {
1419
+ A(this, "alphabet");
1420
+ A(this, "padding");
1421
+ A(this, "decodeMap", /* @__PURE__ */ new Map());
1422
+ if (t.length !== 64)
1423
+ throw new Error("Invalid alphabet");
1424
+ if (this.alphabet = t, this.padding = (n == null ? void 0 : n.padding) ?? "=", this.alphabet.includes(this.padding) || this.padding.length !== 1)
1425
+ throw new Error("Invalid padding");
1426
+ for (let o = 0; o < t.length; o++)
1427
+ this.decodeMap.set(t[o], o);
1428
+ }
1429
+ encode(t, n) {
1430
+ let o = "", i = 0, r = 0;
1431
+ for (let u = 0; u < t.length; u++)
1432
+ for (i = i << 8 | t[u], r += 8; r >= 6; )
1433
+ r += -6, o += this.alphabet[i >> r & 63];
1434
+ if (r > 0 && (o += this.alphabet[i << 6 - r & 63]), (n == null ? void 0 : n.includePadding) ?? !0) {
1435
+ const u = (4 - o.length % 4) % 4;
1436
+ for (let a = 0; a < u; a++)
1437
+ o += "=";
1438
+ }
1439
+ return o;
1440
+ }
1441
+ decode(t, n) {
1442
+ const o = (n == null ? void 0 : n.strict) ?? !0, i = Math.ceil(t.length / 4), r = [];
1443
+ for (let l = 0; l < i; l++) {
1444
+ let u = 0, a = 0;
1445
+ for (let f = 0; f < 4; f++) {
1446
+ const c = t[l * 4 + f];
1447
+ if (c === "=") {
1448
+ if (l + 1 !== i)
1449
+ throw new Error(`Invalid character: ${c}`);
1450
+ u += 1;
1451
+ continue;
1452
+ }
1453
+ if (c === void 0) {
1454
+ if (o)
1455
+ throw new Error("Invalid data");
1456
+ u += 1;
1457
+ continue;
1458
+ }
1459
+ const d = this.decodeMap.get(c) ?? null;
1460
+ if (d === null)
1461
+ throw new Error(`Invalid character: ${c}`);
1462
+ a += d << 6 * (3 - f);
1463
+ }
1464
+ r.push(a >> 16 & 255), u < 2 && r.push(a >> 8 & 255), u < 1 && r.push(a & 255);
1465
+ }
1466
+ return Uint8Array.from(r);
1467
+ }
1468
+ }
1469
+ const Nt = new H("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/");
1470
+ new H("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_");
1471
+ const yt = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";
1472
+ let B = (e = 21) => {
1473
+ let t = "", n = crypto.getRandomValues(new Uint8Array(e));
1474
+ for (; e--; )
1475
+ t += yt[n[e] & 63];
1476
+ return t;
1477
+ };
1478
+ async function wt(e) {
1479
+ const t = new DecompressionStream("deflate-raw"), n = new Uint8Array(e), o = new Blob([n]).stream().pipeThrough(t);
1480
+ return new Uint8Array(await new Response(o).arrayBuffer());
1481
+ }
1482
+ async function At(e) {
1483
+ const t = await Nt.decode(e.replace(/ /g, "+"));
1484
+ try {
1485
+ const n = await wt(t);
1486
+ return new TextDecoder().decode(n);
1487
+ } catch (n) {
1488
+ return console.warn(
1489
+ "Decompression failed, assuming data is not compressed:",
1490
+ n
1491
+ ), new TextDecoder().decode(t);
1492
+ }
1493
+ }
1494
+ async function Ot(e) {
1495
+ const t = await At(e), o = new j.XMLParser({
1496
+ attributeNamePrefix: "@_",
1497
+ alwaysCreateTextNode: !0,
1498
+ ignoreAttributes: !1
1499
+ }).parse(t);
1500
+ return z.parse(o);
1501
+ }
1502
+ function Ct(e) {
1503
+ const t = e.certificates.map((i) => ({
1504
+ "@_use": "signing",
1505
+ KeyInfo: {
1506
+ "@_xmlns": "http://www.w3.org/2000/09/xmldsig#",
1507
+ X509Data: {
1508
+ X509Certificate: i
1509
+ }
1510
+ }
1511
+ })), n = {
1512
+ EntityDescriptor: {
1513
+ "@_entityID": e.entityId,
1514
+ "@_xmlns": "urn:oasis:names:tc:SAML:2.0:metadata",
1515
+ IDPSSODescriptor: {
1516
+ "@_protocolSupportEnumeration": "urn:oasis:names:tc:SAML:2.0:protocol",
1517
+ KeyDescriptor: t,
1518
+ SingleLogoutService: [
1519
+ {
1520
+ "@_Binding": "urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect",
1521
+ "@_Location": e.singleLogoutServiceUrl
1522
+ },
1523
+ {
1524
+ "@_Binding": "urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST",
1525
+ "@_Location": e.singleLogoutServiceUrl
1526
+ }
1527
+ ],
1528
+ NameIDFormat: [
1529
+ "urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress",
1530
+ "urn:oasis:names:tc:SAML:2.0:nameid-format:persistent",
1531
+ "urn:oasis:names:tc:SAML:2.0:nameid-format:transient"
1532
+ ],
1533
+ SingleSignOnService: [
1534
+ {
1535
+ "@_Binding": "urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect",
1536
+ "@_Location": e.assertionConsumerServiceUrl
1537
+ },
1538
+ {
1539
+ "@_Binding": "urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST",
1540
+ "@_Location": e.assertionConsumerServiceUrl
1541
+ }
1542
+ ],
1543
+ Attribute: [
1544
+ {
1545
+ "@_Name": "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress",
1546
+ "@_NameFormat": "urn:oasis:names:tc:SAML:2.0:attrname-format:uri",
1547
+ "@_FriendlyName": "E-Mail Address",
1548
+ "@_xmlns": "urn:oasis:names:tc:SAML:2.0:assertion"
1549
+ },
1550
+ {
1551
+ "@_Name": "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/givenname",
1552
+ "@_NameFormat": "urn:oasis:names:tc:SAML:2.0:attrname-format:uri",
1553
+ "@_FriendlyName": "Given Name",
1554
+ "@_xmlns": "urn:oasis:names:tc:SAML:2.0:assertion"
1555
+ },
1556
+ {
1557
+ "@_Name": "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name",
1558
+ "@_NameFormat": "urn:oasis:names:tc:SAML:2.0:attrname-format:uri",
1559
+ "@_FriendlyName": "Name",
1560
+ "@_xmlns": "urn:oasis:names:tc:SAML:2.0:assertion"
1561
+ },
1562
+ {
1563
+ "@_Name": "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/surname",
1564
+ "@_NameFormat": "urn:oasis:names:tc:SAML:2.0:attrname-format:uri",
1565
+ "@_FriendlyName": "Surname",
1566
+ "@_xmlns": "urn:oasis:names:tc:SAML:2.0:assertion"
1567
+ },
1568
+ {
1569
+ "@_Name": "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier",
1570
+ "@_NameFormat": "urn:oasis:names:tc:SAML:2.0:attrname-format:uri",
1571
+ "@_FriendlyName": "Name ID",
1572
+ "@_xmlns": "urn:oasis:names:tc:SAML:2.0:assertion"
1573
+ }
1574
+ ]
1575
+ }
1576
+ }
1577
+ };
1578
+ return new j.XMLBuilder({
1579
+ ignoreAttributes: !1,
1580
+ suppressEmptyNode: !0,
1581
+ preserveOrder: !1,
1582
+ format: !0,
1583
+ attributeNamePrefix: "@_"
1584
+ }).build(n);
1585
+ }
1586
+ async function Lt(e, t) {
1587
+ const n = e.notBefore || (/* @__PURE__ */ new Date()).toISOString(), o = e.notAfter || new Date(new Date(n).getTime() + 10 * 60 * 1e3).toISOString(), i = e.issueInstant || n, r = e.sessionNotOnOrAfter || o, l = e.responseId || `_${B()}`, u = e.assertionId || `_${B()}`, a = [
1588
+ {
1589
+ "samlp:Response": [
1590
+ {
1591
+ "saml:Issuer": [{ "#text": e.issuer }]
1592
+ },
1593
+ {
1594
+ "samlp:Status": [
1595
+ {
1596
+ "samlp:StatusCode": [],
1597
+ ":@": { "@_Value": "urn:oasis:names:tc:SAML:2.0:status:Success" }
1598
+ }
1599
+ ]
1600
+ },
1601
+ {
1602
+ "saml:Assertion": [
1603
+ {
1604
+ "saml:Issuer": [
1605
+ {
1606
+ "#text": e.issuer
1607
+ }
1608
+ ]
1609
+ },
1610
+ {
1611
+ "saml:Subject": [
1612
+ {
1613
+ "saml:NameID": [{ "#text": e.email }],
1614
+ ":@": {
1615
+ "@_Format": "urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress"
1616
+ }
1617
+ },
1618
+ {
1619
+ "saml:SubjectConfirmation": [
1620
+ {
1621
+ "saml:SubjectConfirmationData": [],
1622
+ ":@": {
1623
+ "@_InResponseTo": e.inResponseTo,
1624
+ "@_NotOnOrAfter": o,
1625
+ "@_Recipient": e.destination
1626
+ }
1627
+ }
1628
+ ],
1629
+ ":@": { "@_Method": "urn:oasis:names:tc:SAML:2.0:cm:bearer" }
1630
+ }
1631
+ ]
1632
+ },
1633
+ {
1634
+ "saml:Conditions": [
1635
+ {
1636
+ "saml:AudienceRestriction": [
1637
+ {
1638
+ "saml:Audience": [
1639
+ {
1640
+ "#text": e.audience
1641
+ }
1642
+ ]
1643
+ }
1644
+ ]
1645
+ }
1646
+ ],
1647
+ ":@": {
1648
+ "@_NotBefore": n,
1649
+ "@_NotOnOrAfter": o
1650
+ }
1651
+ },
1652
+ {
1653
+ "saml:AuthnStatement": [
1654
+ {
1655
+ "saml:AuthnContext": [
1656
+ {
1657
+ "saml:AuthnContextClassRef": [
1658
+ {
1659
+ "#text": "urn:oasis:names:tc:SAML:2.0:ac:classes:unspecified"
1660
+ }
1661
+ ]
1662
+ }
1663
+ ]
1664
+ }
1665
+ ],
1666
+ ":@": {
1667
+ "@_AuthnInstant": i,
1668
+ "@_SessionIndex": e.sessionIndex,
1669
+ "@_SessionNotOnOrAfter": r
1670
+ }
1671
+ },
1672
+ {
1673
+ "saml:AttributeStatement": [
1674
+ {
1675
+ "saml:Attribute": [
1676
+ {
1677
+ "saml:AttributeValue": [
1678
+ {
1679
+ "#text": e.userId
1680
+ }
1681
+ ],
1682
+ ":@": {
1683
+ "@_xmlns:xs": "http://www.w3.org/2001/XMLSchema",
1684
+ "@_xmlns:xsi": "http://www.w3.org/2001/XMLSchema-instance",
1685
+ "@_xsi:type": "xs:string"
1686
+ }
1687
+ }
1688
+ ],
1689
+ ":@": {
1690
+ "@_FriendlyName": "persistent",
1691
+ "@_Name": "id",
1692
+ "@_NameFormat": "urn:oasis:names:tc:SAML:2.0:attrname-format:unspecified"
1693
+ }
1694
+ },
1695
+ {
1696
+ "saml:Attribute": [
1697
+ {
1698
+ "saml:AttributeValue": [
1699
+ {
1700
+ "#text": e.email
1701
+ }
1702
+ ],
1703
+ ":@": {
1704
+ "@_xmlns:xs": "http://www.w3.org/2001/XMLSchema",
1705
+ "@_xmlns:xsi": "http://www.w3.org/2001/XMLSchema-instance",
1706
+ "@_xsi:type": "xs:string"
1707
+ }
1708
+ }
1709
+ ],
1710
+ ":@": {
1711
+ "@_Name": "email",
1712
+ "@_NameFormat": "urn:oasis:names:tc:SAML:2.0:attrname-format:basic"
1713
+ }
1714
+ },
1715
+ {
1716
+ "saml:Attribute": [
1717
+ {
1718
+ "saml:AttributeValue": [
1719
+ {
1720
+ "#text": "manage-account"
1721
+ }
1722
+ ],
1723
+ ":@": {
1724
+ "@_xmlns:xs": "http://www.w3.org/2001/XMLSchema",
1725
+ "@_xmlns:xsi": "http://www.w3.org/2001/XMLSchema-instance",
1726
+ "@_xsi:type": "xs:string"
1727
+ }
1728
+ }
1729
+ ],
1730
+ ":@": {
1731
+ "@_Name": "Role",
1732
+ "@_NameFormat": "urn:oasis:names:tc:SAML:2.0:attrname-format:basic"
1733
+ }
1734
+ },
1735
+ {
1736
+ "saml:Attribute": [
1737
+ {
1738
+ "saml:AttributeValue": [
1739
+ {
1740
+ "#text": "default-roles-master"
1741
+ }
1742
+ ],
1743
+ ":@": {
1744
+ "@_xmlns:xs": "http://www.w3.org/2001/XMLSchema",
1745
+ "@_xmlns:xsi": "http://www.w3.org/2001/XMLSchema-instance",
1746
+ "@_xsi:type": "xs:string"
1747
+ }
1748
+ }
1749
+ ],
1750
+ ":@": {
1751
+ "@_Name": "Role",
1752
+ "@_NameFormat": "urn:oasis:names:tc:SAML:2.0:attrname-format:basic"
1753
+ }
1754
+ },
1755
+ {
1756
+ "saml:Attribute": [
1757
+ {
1758
+ "saml:AttributeValue": [
1759
+ {
1760
+ "#text": "offline_access"
1761
+ }
1762
+ ],
1763
+ ":@": {
1764
+ "@_xmlns:xs": "http://www.w3.org/2001/XMLSchema",
1765
+ "@_xmlns:xsi": "http://www.w3.org/2001/XMLSchema-instance",
1766
+ "@_xsi:type": "xs:string"
1767
+ }
1768
+ }
1769
+ ],
1770
+ ":@": {
1771
+ "@_Name": "Role",
1772
+ "@_NameFormat": "urn:oasis:names:tc:SAML:2.0:attrname-format:basic"
1773
+ }
1774
+ },
1775
+ {
1776
+ "saml:Attribute": [
1777
+ {
1778
+ "saml:AttributeValue": [
1779
+ {
1780
+ "#text": "view-profile"
1781
+ }
1782
+ ],
1783
+ ":@": {
1784
+ "@_xmlns:xs": "http://www.w3.org/2001/XMLSchema",
1785
+ "@_xmlns:xsi": "http://www.w3.org/2001/XMLSchema-instance",
1786
+ "@_xsi:type": "xs:string"
1787
+ }
1788
+ }
1789
+ ],
1790
+ ":@": {
1791
+ "@_Name": "Role",
1792
+ "@_NameFormat": "urn:oasis:names:tc:SAML:2.0:attrname-format:basic"
1793
+ }
1794
+ },
1795
+ {
1796
+ "saml:Attribute": [
1797
+ {
1798
+ "saml:AttributeValue": [
1799
+ {
1800
+ "#text": "uma_authorization"
1801
+ }
1802
+ ],
1803
+ ":@": {
1804
+ "@_xmlns:xs": "http://www.w3.org/2001/XMLSchema",
1805
+ "@_xmlns:xsi": "http://www.w3.org/2001/XMLSchema-instance",
1806
+ "@_xsi:type": "xs:string"
1807
+ }
1808
+ }
1809
+ ],
1810
+ ":@": {
1811
+ "@_Name": "Role",
1812
+ "@_NameFormat": "urn:oasis:names:tc:SAML:2.0:attrname-format:basic"
1813
+ }
1814
+ },
1815
+ {
1816
+ "saml:Attribute": [
1817
+ {
1818
+ "saml:AttributeValue": [
1819
+ {
1820
+ "#text": "manage-account-links"
1821
+ }
1822
+ ],
1823
+ ":@": {
1824
+ "@_xmlns:xs": "http://www.w3.org/2001/XMLSchema",
1825
+ "@_xmlns:xsi": "http://www.w3.org/2001/XMLSchema-instance",
1826
+ "@_xsi:type": "xs:string"
1827
+ }
1828
+ }
1829
+ ],
1830
+ ":@": {
1831
+ "@_Name": "Role",
1832
+ "@_NameFormat": "urn:oasis:names:tc:SAML:2.0:attrname-format:basic"
1833
+ }
1834
+ }
1835
+ ]
1836
+ }
1837
+ ],
1838
+ ":@": {
1839
+ "@_xmlns": "urn:oasis:names:tc:SAML:2.0:assertion",
1840
+ "@_ID": u,
1841
+ "@_IssueInstant": i,
1842
+ "@_Version": "2.0"
1843
+ }
1844
+ }
1845
+ ],
1846
+ ":@": {
1847
+ "@_xmlns:samlp": "urn:oasis:names:tc:SAML:2.0:protocol",
1848
+ "@_xmlns:saml": "urn:oasis:names:tc:SAML:2.0:assertion",
1849
+ "@_Destination": e.destination,
1850
+ "@_ID": l,
1851
+ "@_InResponseTo": e.inResponseTo,
1852
+ "@_IssueInstant": i,
1853
+ "@_Version": "2.0"
1854
+ }
1855
+ }
1856
+ ];
1857
+ let c = new j.XMLBuilder({
1858
+ ignoreAttributes: !1,
1859
+ suppressEmptyNode: !0,
1860
+ preserveOrder: !0
1861
+ }).build(a);
1862
+ return e.signature && t && (c = await t.signSAML(
1863
+ c,
1864
+ e.signature.privateKeyPem,
1865
+ e.signature.cert
1866
+ )), e.encode === !1 ? c : btoa(c);
1867
+ }
1868
+ class Mt {
1869
+ constructor(t) {
1870
+ this.signUrl = t;
1871
+ }
1872
+ async signSAML(t, n, o) {
1873
+ const i = await fetch(this.signUrl, {
1874
+ method: "POST",
1875
+ headers: {
1876
+ "Content-Type": "application/json"
1877
+ },
1878
+ body: JSON.stringify({
1879
+ xmlContent: t,
1880
+ privateKey: n,
1881
+ publicCert: o
1882
+ })
1883
+ });
1884
+ if (!i.ok)
1885
+ throw new Error(
1886
+ `Failed to sign SAML via HTTP: ${i.status} ${i.statusText}`
1887
+ );
1888
+ return await i.text();
1889
+ }
1890
+ }
1891
+ export {
1892
+ Mt as HttpSamlSigner,
1893
+ Ct as createSamlMetadata,
1894
+ Lt as createSamlResponse,
1895
+ v as dsSignatureSchema,
1896
+ At as inflateDecompress,
1897
+ wt as inflateRaw,
1898
+ Ot as parseSamlRequestQuery,
1899
+ W as samlIssuerSchema,
1900
+ St as samlMetadataResponseSchema,
1901
+ z as samlRequestSchema,
1902
+ Et as samlResponseJsonSchema
1903
+ };