@authhero/saml 0.1.54 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,5 +1,167 @@
1
1
  # @authhero/saml
2
2
 
3
- A SAML authentication package without node dependencies.
3
+ SAML utilities for AuthHero, including SAML request/response parsing, metadata generation, and signing capabilities.
4
4
 
5
- It uses fast-xml-parser and zod for the XML parsing and validation.
5
+ ## Features
6
+
7
+ - Parse SAML requests
8
+ - Generate SAML metadata
9
+ - Create SAML responses
10
+ - Pluggable signing implementations:
11
+ - Local signing with xml-crypto (Node.js only)
12
+ - HTTP-based signing for edge/browser environments
13
+
14
+ ## Installation
15
+
16
+ ```bash
17
+ npm install @authhero/saml
18
+ ```
19
+
20
+ ## Usage
21
+
22
+ # @authhero/saml
23
+
24
+ SAML utilities for AuthHero, including SAML request/response parsing, metadata generation, and signing capabilities.
25
+
26
+ ## Features
27
+
28
+ - Parse SAML requests
29
+ - Generate SAML metadata
30
+ - Create SAML responses
31
+ - Pluggable signing implementations:
32
+ - Local signing with xml-crypto (Node.js only)
33
+ - HTTP-based signing for edge/browser environments
34
+
35
+ ## Installation
36
+
37
+ ```bash
38
+ npm install @authhero/saml
39
+ ```
40
+
41
+ For local signing (Node.js), also install xml-crypto:
42
+
43
+ ```bash
44
+ npm install xml-crypto
45
+ ```
46
+
47
+ ## Import Strategies
48
+
49
+ The package provides **three import paths** to optimize bundle size:
50
+
51
+ ### 1. Full Import (All Features)
52
+
53
+ Includes everything including `LocalSamlSigner`. Use this for Node.js environments where you want local signing.
54
+
55
+ ```typescript
56
+ import {
57
+ createSamlResponse,
58
+ LocalSamlSigner,
59
+ HttpSamlSigner,
60
+ } from "@authhero/saml";
61
+ ```
62
+
63
+ **Bundle impact:** Includes reference to xml-crypto (even with dynamic import)
64
+
65
+ ### 2. Core Import (Edge-Optimized, **Recommended for Edge/Cloudflare Workers**)
66
+
67
+ Excludes `LocalSamlSigner` to avoid any xml-crypto imports. Perfect for edge environments.
68
+
69
+ ```typescript
70
+ import { createSamlResponse, HttpSamlSigner } from "@authhero/saml/core";
71
+ ```
72
+
73
+ **Bundle impact:** ✅ No xml-crypto imports, smaller bundle
74
+
75
+ ### 3. Local Signer Only
76
+
77
+ Import only the local signer when needed.
78
+
79
+ ```typescript
80
+ import { LocalSamlSigner } from "@authhero/saml/local-signer";
81
+ ```
82
+
83
+ ## Usage Examples
84
+
85
+ ### Edge Environment (HTTP Signer) - **Recommended**
86
+
87
+ ```typescript
88
+ import { createSamlResponse, HttpSamlSigner } from "@authhero/saml/core";
89
+
90
+ const signer = new HttpSamlSigner("https://your-signing-service.com/sign");
91
+
92
+ const response = await createSamlResponse(
93
+ {
94
+ issuer: "https://example.com",
95
+ audience: "urn:example:audience",
96
+ destination: "https://sp.example.com/acs",
97
+ inResponseTo: "request-id",
98
+ userId: "user-123",
99
+ email: "user@example.com",
100
+ sessionIndex: "session-123",
101
+ signature: {
102
+ privateKeyPem: "-----BEGIN PRIVATE KEY-----...",
103
+ cert: "-----BEGIN CERTIFICATE-----...",
104
+ kid: "key-id",
105
+ },
106
+ },
107
+ signer,
108
+ );
109
+ ```
110
+
111
+ **Benefits:**
112
+
113
+ - ✅ Works in Cloudflare Workers, Deno Deploy, Vercel Edge
114
+ - ✅ No heavy xml-crypto dependency
115
+ - ✅ Smaller bundle size
116
+ - ✅ No Node.js native dependencies
117
+
118
+ ### Node.js Environment (Local Signer)
119
+
120
+ ```typescript
121
+ import { createSamlResponse, LocalSamlSigner } from "@authhero/saml";
122
+
123
+ const signer = new LocalSamlSigner();
124
+
125
+ const response = await createSamlResponse(
126
+ {
127
+ // ... same params as above
128
+ },
129
+ signer,
130
+ );
131
+ ```
132
+
133
+ ### HTTP Signer for Edge Environments
134
+
135
+ ```typescript
136
+ import { createSamlResponse, HttpSamlSigner } from "@authhero/saml";
137
+
138
+ const signer = new HttpSamlSigner("https://your-signing-service.com/sign");
139
+
140
+ const response = await createSamlResponse(
141
+ {
142
+ // ... same params as above
143
+ },
144
+ signer,
145
+ );
146
+ ```
147
+
148
+ ### Custom Signer Implementation
149
+
150
+ ```typescript
151
+ import { SamlSigner } from "@authhero/saml";
152
+
153
+ class CustomSamlSigner implements SamlSigner {
154
+ async signSAML(
155
+ xmlContent: string,
156
+ privateKey: string,
157
+ publicCert: string,
158
+ ): Promise<string> {
159
+ // Your custom signing logic
160
+ return signedXml;
161
+ }
162
+ }
163
+ ```
164
+
165
+ ## License
166
+
167
+ MIT
package/dist/core.cjs ADDED
@@ -0,0 +1,7 @@
1
+ "use strict";var D=Object.defineProperty;var ee=(e,t,n)=>t in e?D(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var z=(e,t,n)=>ee(e,typeof t!="symbol"?t+"":t,n);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("@hono/zod-openapi"),b=s.z.object({"#text":s.z.string()}),R=s.z.object({"#text":s.z.string(),"@_xmlns:saml":s.z.string().optional()}),B=s.z.object({"samlp:AuthnRequest":s.z.object({"saml:Issuer":R,"@_xmlns:samlp":s.z.string(),"@_xmlns:saml":s.z.string().optional(),"@_ForceAuthn":s.z.string().transform(e=>e.toLowerCase()==="true").optional(),"@_ID":s.z.string(),"@_IssueInstant":s.z.string().datetime(),"@_Destination":s.z.string().url(),"@_AssertionConsumerServiceURL":s.z.string().url().optional(),"@_ProtocolBinding":s.z.string().optional(),"@_Version":s.z.string()})}),te=s.z.array(s.z.object({":@":s.z.object({"@_xmlns":s.z.string(),"@_entityID":s.z.string()}),EntityDescriptor:s.z.array(s.z.object({":@":s.z.object({"@_protocolSupportEnumeration":s.z.string()}),IDPSSODescriptor:s.z.array(s.z.union([s.z.object({KeyDescriptor:s.z.array(s.z.object({KeyInfo:s.z.array(s.z.object({X509Data:s.z.array(s.z.object({X509Certificate:s.z.array(b)}))})),":@":s.z.object({"@_xmlns":s.z.string()})})),":@":s.z.object({"@_use":s.z.string()})}),s.z.object({SingleLogoutService:s.z.array(s.z.object({})),":@":s.z.object({"@_Binding":s.z.string(),"@_Location":s.z.string()})}),s.z.object({NameIDFormat:s.z.array(b)}),s.z.object({SingleSignOnService:s.z.array(s.z.object({})),":@":s.z.object({"@_Binding":s.z.string(),"@_Location":s.z.string()})}),s.z.object({Attribute:s.z.array(s.z.object({})),":@":s.z.object({"@_Name":s.z.string(),"@_NameFormat":s.z.string(),"@_FriendlyName":s.z.string(),"@_xmlns":s.z.string()})})]))}))})),ne=s.z.object({":@":s.z.object({"@_Name":s.z.string(),"@_NameFormat":s.z.string(),"@_FriendlyName":s.z.string().optional()}),"saml:AttributeValue":s.z.array(s.z.object({"#text":s.z.string(),":@":s.z.object({"@_xmlns:xs":s.z.string().optional(),"@_xmlns:xsi":s.z.string(),"@_xsi:type":s.z.string()}).optional()}))}),se=s.z.object({"ds:Transform":s.z.array(s.z.any()),":@":s.z.object({"@_Algorithm":s.z.string()})}),T=s.z.object({"ds:Signature":s.z.array(s.z.union([s.z.object({"ds:SignedInfo":s.z.array(s.z.union([s.z.object({"ds:CanonicalizationMethod":s.z.array(s.z.object({":@":s.z.object({"@_Algorithm":s.z.string()})}))}),s.z.object({"ds:SignatureMethod":s.z.array(s.z.object({":@":s.z.object({"@_Algorithm":s.z.string()})}))}),s.z.object({"ds:Reference":s.z.array(s.z.union([s.z.object({"ds:Transforms":s.z.array(se)}),s.z.object({"ds:DigestMethod":s.z.array(s.z.object({":@":s.z.object({"@_Algorithm":s.z.string()})}))}),s.z.object({"ds:DigestValue":s.z.array(b)})])),":@":s.z.object({"@_URI":s.z.string().optional()}).optional()})]))}),s.z.object({"ds:SignatureValue":s.z.array(b)}),s.z.object({"ds:KeyInfo":s.z.array(s.z.union([s.z.object({"ds:KeyValue":s.z.array(s.z.object({"ds:RSAKeyValue":s.z.array(s.z.union([s.z.object({"ds:Modulus":s.z.array(b)}),s.z.object({"ds:Exponent":s.z.array(b)})]))}))}),s.z.object({"ds:X509Data":s.z.array(s.z.object({"ds:X509Certificate":s.z.array(b)}))}),s.z.object({"ds:KeyValue":s.z.array(s.z.object({"ds:RSAKeyValue":s.z.array(s.z.union([s.z.object({"ds:Modulus":s.z.array(b)}),s.z.object({"ds:Exponent":s.z.array(b)})]))})),"ds:X509Data":s.z.array(s.z.object({"ds:X509Certificate":s.z.array(b)}))})]))})])),":@":s.z.object({"@_xmlns:ds":s.z.string().optional()}).optional()}),re=s.z.array(s.z.object({"samlp:Response":s.z.array(s.z.union([s.z.object({"saml:Issuer":s.z.array(b)}),T,s.z.object({"samlp:Status":s.z.array(s.z.object({"samlp:StatusCode":s.z.array(b),":@":s.z.object({"@_Value":s.z.string()})}))}),s.z.object({"saml:Assertion":s.z.array(s.z.union([s.z.object({"saml:Issuer":s.z.array(b)}),T,s.z.object({"saml:Subject":s.z.array(s.z.union([s.z.object({"saml:NameID":s.z.array(b),":@":s.z.object({"@_Format":s.z.string()})}),s.z.object({"saml:SubjectConfirmation":s.z.array(s.z.object({"saml:SubjectConfirmationData":s.z.array(s.z.any()),":@":s.z.object({"@_InResponseTo":s.z.string(),"@_NotOnOrAfter":s.z.string(),"@_Recipient":s.z.string()})})),":@":s.z.object({"@_Method":s.z.string()})})]))}),s.z.object({"saml:Conditions":s.z.array(s.z.object({"saml:AudienceRestriction":s.z.array(s.z.object({"saml:Audience":s.z.array(b)}))})),":@":s.z.object({"@_NotBefore":s.z.string(),"@_NotOnOrAfter":s.z.string()})}),s.z.object({"saml:AuthnStatement":s.z.array(s.z.object({"saml:AuthnContext":s.z.array(s.z.object({"saml:AuthnContextClassRef":s.z.array(b)}))})),":@":s.z.object({"@_AuthnInstant":s.z.string(),"@_SessionIndex":s.z.string(),"@_SessionNotOnOrAfter":s.z.string()})}),s.z.object({"saml:AttributeStatement":s.z.array(s.z.object({"saml:Attribute":s.z.array(ne)}))})])),":@":s.z.object({"@_xmlns":s.z.string(),"@_ID":s.z.string(),"@_IssueInstant":s.z.string(),"@_Version":s.z.string()})})])),":@":s.z.object({"@_xmlns:samlp":s.z.string(),"@_xmlns:saml":s.z.string(),"@_Destination":s.z.string(),"@_ID":s.z.string(),"@_InResponseTo":s.z.string(),"@_IssueInstant":s.z.string(),"@_Version":s.z.string()})}));var C={},E={};(function(e){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){const f=[];let c=a.exec(u);for(;c;){const d=[];d.startIndex=a.lastIndex-c[0].length;const g=c.length;for(let m=0;m<g;m++)d.push(c[m]);f.push(d),c=a.exec(u)}return f},l=function(u){const a=i.exec(u);return!(a===null||typeof a>"u")};e.isExist=function(u){return typeof u<"u"},e.isEmptyObject=function(u){return Object.keys(u).length===0},e.merge=function(u,a,f){if(a){const c=Object.keys(a),d=c.length;for(let g=0;g<d;g++)f==="strict"?u[c[g]]=[a[c[g]]]:u[c[g]]=a[c[g]]}},e.getValue=function(u){return e.isExist(u)?u:""},e.isName=l,e.getAllMatches=r,e.nameRegexp=o})(E);const L=E,ie={allowBooleanAttributes:!1,unpairedTags:[]};C.validate=function(e,t){t=Object.assign({},ie,t);const n=[];let o=!1,i=!1;e[0]==="\uFEFF"&&(e=e.substr(1));for(let r=0;r<e.length;r++)if(e[r]==="<"&&e[r+1]==="?"){if(r+=2,r=P(e,r),r.err)return r}else if(e[r]==="<"){let l=r;if(r++,e[r]==="!"){r=F(e,r);continue}else{let u=!1;e[r]==="/"&&(u=!0,r++);let a="";for(;r<e.length&&e[r]!==">"&&e[r]!==" "&&e[r]!==" "&&e[r]!==`
2
+ `&&e[r]!=="\r";r++)a+=e[r];if(a=a.trim(),a[a.length-1]==="/"&&(a=a.substring(0,a.length-1),r--),!ge(a)){let d;return a.trim().length===0?d="Invalid space after '<'.":d="Tag '"+a+"' is an invalid name.",h("InvalidTag",d,N(e,r))}const f=ue(e,r);if(f===!1)return h("InvalidAttr","Attributes for '"+a+"' have open quote.",N(e,r));let c=f.value;if(r=f.index,c[c.length-1]==="/"){const d=r-c.length;c=c.substring(0,c.length-1);const g=V(c,t);if(g===!0)o=!0;else return h(g.err.code,g.err.msg,N(e,d+g.err.line))}else if(u)if(f.tagClosed){if(c.trim().length>0)return h("InvalidTag","Closing tag '"+a+"' can't have attributes or invalid starting.",N(e,l));if(n.length===0)return h("InvalidTag","Closing tag '"+a+"' has not been opened.",N(e,l));{const d=n.pop();if(a!==d.tagName){let g=N(e,d.tagStartPos);return h("InvalidTag","Expected closing tag '"+d.tagName+"' (opened in line "+g.line+", col "+g.col+") instead of closing tag '"+a+"'.",N(e,l))}n.length==0&&(i=!0)}}else return h("InvalidTag","Closing tag '"+a+"' doesn't have proper closing.",N(e,r));else{const d=V(c,t);if(d!==!0)return h(d.err.code,d.err.msg,N(e,r-c.length+d.err.line));if(i===!0)return h("InvalidXml","Multiple possible root nodes found.",N(e,r));t.unpairedTags.indexOf(a)!==-1||n.push({tagName:a,tagStartPos:l}),o=!0}for(r++;r<e.length;r++)if(e[r]==="<")if(e[r+1]==="!"){r++,r=F(e,r);continue}else if(e[r+1]==="?"){if(r=P(e,++r),r.err)return r}else break;else if(e[r]==="&"){const d=fe(e,r);if(d==-1)return h("InvalidChar","char '&' is not expected.",N(e,r));r=d}else if(i===!0&&!v(e[r]))return h("InvalidXml","Extra text at the end",N(e,r));e[r]==="<"&&r--}}else{if(v(e[r]))continue;return h("InvalidChar","char '"+e[r]+"' is not expected.",N(e,r))}if(o){if(n.length==1)return h("InvalidTag","Unclosed tag '"+n[0].tagName+"'.",N(e,n[0].tagStartPos));if(n.length>0)return h("InvalidXml","Invalid '"+JSON.stringify(n.map(r=>r.tagName),null,4).replace(/\r?\n/g,"")+"' found.",{line:1,col:1})}else return h("InvalidXml","Start tag expected.",1);return!0};function v(e){return e===" "||e===" "||e===`
3
+ `||e==="\r"}function P(e,t){const n=t;for(;t<e.length;t++)if(e[t]=="?"||e[t]==" "){const o=e.substr(n,t-n);if(t>5&&o==="xml")return h("InvalidXml","XML declaration allowed only at the start of the document.",N(e,t));if(e[t]=="?"&&e[t+1]==">"){t++;break}else continue}return t}function F(e,t){if(e.length>t+5&&e[t+1]==="-"&&e[t+2]==="-"){for(t+=3;t<e.length;t++)if(e[t]==="-"&&e[t+1]==="-"&&e[t+2]===">"){t+=2;break}}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"){let n=1;for(t+=8;t<e.length;t++)if(e[t]==="<")n++;else if(e[t]===">"&&(n--,n===0))break}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]==="["){for(t+=8;t<e.length;t++)if(e[t]==="]"&&e[t+1]==="]"&&e[t+2]===">"){t+=2;break}}return t}const oe='"',ae="'";function ue(e,t){let n="",o="",i=!1;for(;t<e.length;t++){if(e[t]===oe||e[t]===ae)o===""?o=e[t]:o!==e[t]||(o="");else if(e[t]===">"&&o===""){i=!0;break}n+=e[t]}return o!==""?!1:{value:n,index:t,tagClosed:i}}const le=new RegExp(`(\\s*)([^\\s=]+)(\\s*=)?(\\s*(['"])(([\\s\\S])*?)\\5)?`,"g");function V(e,t){const n=L.getAllMatches(e,le),o={};for(let i=0;i<n.length;i++){if(n[i][1].length===0)return h("InvalidAttr","Attribute '"+n[i][2]+"' has no space in starting.",S(n[i]));if(n[i][3]!==void 0&&n[i][4]===void 0)return h("InvalidAttr","Attribute '"+n[i][2]+"' is without value.",S(n[i]));if(n[i][3]===void 0&&!t.allowBooleanAttributes)return h("InvalidAttr","boolean attribute '"+n[i][2]+"' is not allowed.",S(n[i]));const r=n[i][2];if(!de(r))return h("InvalidAttr","Attribute '"+r+"' is an invalid name.",S(n[i]));if(!o.hasOwnProperty(r))o[r]=1;else return h("InvalidAttr","Attribute '"+r+"' is repeated.",S(n[i]))}return!0}function ce(e,t){let n=/\d/;for(e[t]==="x"&&(t++,n=/[\da-fA-F]/);t<e.length;t++){if(e[t]===";")return t;if(!e[t].match(n))break}return-1}function fe(e,t){if(t++,e[t]===";")return-1;if(e[t]==="#")return t++,ce(e,t);let n=0;for(;t<e.length;t++,n++)if(!(e[t].match(/\w/)&&n<20)){if(e[t]===";")break;return-1}return t}function h(e,t,n){return{err:{code:e,msg:t,line:n.line||n,col:n.col}}}function de(e){return L.isName(e)}function ge(e){return L.isName(e)}function N(e,t){const n=e.substring(0,t).split(/\r?\n/);return{line:n.length,col:n[n.length-1].length+1}}function S(e){return e.startIndex+e[1].length}var M={};const k={preserveOrder:!1,attributeNamePrefix:"@_",attributesGroupName:!1,textNodeName:"#text",ignoreAttributes:!0,removeNSPrefix:!1,allowBooleanAttributes:!1,parseTagValue:!0,parseAttributeValue:!1,trimValues:!0,cdataPropName:!1,numberParseOptions:{hex:!0,leadingZeros:!0,eNotation:!0},tagValueProcessor:function(e,t){return t},attributeValueProcessor:function(e,t){return t},stopNodes:[],alwaysCreateTextNode:!1,isArray:()=>!1,commentPropName:!1,unpairedTags:[],processEntities:!0,htmlEntities:!1,ignoreDeclaration:!1,ignorePiTags:!1,transformTagName:!1,transformAttributeName:!1,updateTag:function(e,t,n){return e}},he=function(e){return Object.assign({},k,e)};M.buildOptions=he;M.defaultOptions=k;class pe{constructor(t){this.tagname=t,this.child=[],this[":@"]={}}add(t,n){t==="__proto__"&&(t="#__proto__"),this.child.push({[t]:n})}addChild(t){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})}}var me=pe;const be=E;function Ne(e,t){const n={};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"){t=t+9;let o=1,i=!1,r=!1,l="";for(;t<e.length;t++)if(e[t]==="<"&&!r){if(i&&ze(e,t)){t+=7;let u,a;[u,a,t]=ye(e,t+1),a.indexOf("&")===-1&&(n[xe(u)]={regx:RegExp(`&${u};`,"g"),val:a})}else if(i&&Ae(e,t))t+=8;else if(i&&_e(e,t))t+=8;else if(i&&Se(e,t))t+=9;else if(we)r=!0;else throw new Error("Invalid DOCTYPE");o++,l=""}else if(e[t]===">"){if(r?e[t-1]==="-"&&e[t-2]==="-"&&(r=!1,o--):o--,o===0)break}else e[t]==="["?i=!0:l+=e[t];if(o!==0)throw new Error("Unclosed DOCTYPE")}else throw new Error("Invalid Tag instead of DOCTYPE");return{entities:n,i:t}}function ye(e,t){let n="";for(;t<e.length&&e[t]!=="'"&&e[t]!=='"';t++)n+=e[t];if(n=n.trim(),n.indexOf(" ")!==-1)throw new Error("External entites are not supported");const o=e[t++];let i="";for(;t<e.length&&e[t]!==o;t++)i+=e[t];return[n,i,t]}function we(e,t){return e[t+1]==="!"&&e[t+2]==="-"&&e[t+3]==="-"}function ze(e,t){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"}function Ae(e,t){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"}function _e(e,t){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"}function Se(e,t){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"}function xe(e){if(be.isName(e))return e;throw new Error(`Invalid entity name ${e}`)}var Ee=Ne;const Te=/^[-+]?0x[a-fA-F0-9]+$/,Ie=/^([\-\+])?(0*)(\.[0-9]+([eE]\-?[0-9]+)?|[0-9]+(\.[0-9]+([eE]\-?[0-9]+)?)?)$/;!Number.parseInt&&window.parseInt&&(Number.parseInt=window.parseInt);!Number.parseFloat&&window.parseFloat&&(Number.parseFloat=window.parseFloat);const Oe={hex:!0,leadingZeros:!0,decimalPoint:".",eNotation:!0};function Ce(e,t={}){if(t=Object.assign({},Oe,t),!e||typeof e!="string")return e;let n=e.trim();if(t.skipLike!==void 0&&t.skipLike.test(n))return e;if(t.hex&&Te.test(n))return Number.parseInt(n,16);{const o=Ie.exec(n);if(o){const i=o[1],r=o[2];let l=Le(o[3]);const u=o[4]||o[6];if(!t.leadingZeros&&r.length>0&&i&&n[2]!==".")return e;if(!t.leadingZeros&&r.length>0&&!i&&n[1]!==".")return e;{const a=Number(n),f=""+a;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}}else return e}}function Le(e){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}var Me=Ce;function je(e){return typeof e=="function"?e:Array.isArray(e)?t=>{for(const n of e)if(typeof n=="string"&&t===n||n instanceof RegExp&&n.test(t))return!0}:()=>!1}var U=je;const G=E,x=me,ve=Ee,Pe=Me,Fe=U;let Ve=class{constructor(t){this.options=t,this.currentNode=null,this.tagsNodeStack=[],this.docTypeEntities={},this.lastEntities={apos:{regex:/&(apos|#39|#x27);/g,val:"'"},gt:{regex:/&(gt|#62|#x3E);/g,val:">"},lt:{regex:/&(lt|#60|#x3C);/g,val:"<"},quot:{regex:/&(quot|#34|#x22);/g,val:'"'}},this.ampEntity={regex:/&(amp|#38|#x26);/g,val:"&"},this.htmlEntities={space:{regex:/&(nbsp|#160);/g,val:" "},cent:{regex:/&(cent|#162);/g,val:"¢"},pound:{regex:/&(pound|#163);/g,val:"£"},yen:{regex:/&(yen|#165);/g,val:"¥"},euro:{regex:/&(euro|#8364);/g,val:"€"},copyright:{regex:/&(copy|#169);/g,val:"©"},reg:{regex:/&(reg|#174);/g,val:"®"},inr:{regex:/&(inr|#8377);/g,val:"₹"},num_dec:{regex:/&#([0-9]{1,7});/g,val:(n,o)=>String.fromCharCode(Number.parseInt(o,10))},num_hex:{regex:/&#x([0-9a-fA-F]{1,6});/g,val:(n,o)=>String.fromCharCode(Number.parseInt(o,16))}},this.addExternalEntities=$e,this.parseXml=Ue,this.parseTextData=Xe,this.resolveNameSpace=Re,this.buildAttributesMap=ke,this.isItStopNode=qe,this.replaceEntitiesValue=Ke,this.readStopNodeData=Ze,this.saveTextToParentTag=Je,this.addChild=Ge,this.ignoreAttributesFn=Fe(this.options.ignoreAttributes)}};function $e(e){const t=Object.keys(e);for(let n=0;n<t.length;n++){const o=t[n];this.lastEntities[o]={regex:new RegExp("&"+o+";","g"),val:e[o]}}}function Xe(e,t,n,o,i,r,l){if(e!==void 0&&(this.options.trimValues&&!o&&(e=e.trim()),e.length>0)){l||(e=this.replaceEntitiesValue(e));const u=this.options.tagValueProcessor(t,e,n,i,r);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}}function Re(e){if(this.options.removeNSPrefix){const t=e.split(":"),n=e.charAt(0)==="/"?"/":"";if(t[0]==="xmlns")return"";t.length===2&&(e=n+t[1])}return e}const Be=new RegExp(`([^\\s=]+)\\s*(=\\s*(['"])([\\s\\S]*?)\\3)?`,"gm");function ke(e,t,n){if(this.options.ignoreAttributes!==!0&&typeof e=="string"){const o=G.getAllMatches(e,Be),i=o.length,r={};for(let l=0;l<i;l++){const u=this.resolveNameSpace(o[l][1]);if(this.ignoreAttributesFn(u,t))continue;let a=o[l][4],f=this.options.attributeNamePrefix+u;if(u.length)if(this.options.transformAttributeName&&(f=this.options.transformAttributeName(f)),f==="__proto__"&&(f="#__proto__"),a!==void 0){this.options.trimValues&&(a=a.trim()),a=this.replaceEntitiesValue(a);const c=this.options.attributeValueProcessor(u,a,t);c==null?r[f]=a:typeof c!=typeof a||c!==a?r[f]=c:r[f]=O(a,this.options.parseAttributeValue,this.options.numberParseOptions)}else this.options.allowBooleanAttributes&&(r[f]=!0)}if(!Object.keys(r).length)return;if(this.options.attributesGroupName){const l={};return l[this.options.attributesGroupName]=r,l}return r}}const Ue=function(e){e=e.replace(/\r\n?/g,`
4
+ `);const t=new x("!xml");let n=t,o="",i="";for(let r=0;r<e.length;r++)if(e[r]==="<")if(e[r+1]==="/"){const u=A(e,">",r,"Closing Tag is not closed.");let a=e.substring(r+2,u).trim();if(this.options.removeNSPrefix){const d=a.indexOf(":");d!==-1&&(a=a.substr(d+1))}this.options.transformTagName&&(a=this.options.transformTagName(a)),n&&(o=this.saveTextToParentTag(o,n,i));const f=i.substring(i.lastIndexOf(".")+1);if(a&&this.options.unpairedTags.indexOf(a)!==-1)throw new Error(`Unpaired tag can not be used as closing tag: </${a}>`);let c=0;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}else if(e[r+1]==="?"){let u=I(e,r,!1,"?>");if(!u)throw new Error("Pi Tag is not closed.");if(o=this.saveTextToParentTag(o,n,i),!(this.options.ignoreDeclaration&&u.tagName==="?xml"||this.options.ignorePiTags)){const a=new x(u.tagName);a.add(this.options.textNodeName,""),u.tagName!==u.tagExp&&u.attrExpPresent&&(a[":@"]=this.buildAttributesMap(u.tagExp,i,u.tagName)),this.addChild(n,a,i)}r=u.closeIndex+1}else if(e.substr(r+1,3)==="!--"){const u=A(e,"-->",r+4,"Comment is not closed.");if(this.options.commentPropName){const a=e.substring(r+4,u-2);o=this.saveTextToParentTag(o,n,i),n.add(this.options.commentPropName,[{[this.options.textNodeName]:a}])}r=u}else if(e.substr(r+1,2)==="!D"){const u=ve(e,r);this.docTypeEntities=u.entities,r=u.i}else if(e.substr(r+1,2)==="!["){const u=A(e,"]]>",r,"CDATA is not closed.")-2,a=e.substring(r+9,u);o=this.saveTextToParentTag(o,n,i);let f=this.parseTextData(a,n.tagname,i,!0,!1,!0,!0);f==null&&(f=""),this.options.cdataPropName?n.add(this.options.cdataPropName,[{[this.options.textNodeName]:a}]):n.add(this.options.textNodeName,f),r=u+2}else{let u=I(e,r,this.options.removeNSPrefix),a=u.tagName;const f=u.rawTagName;let c=u.tagExp,d=u.attrExpPresent,g=u.closeIndex;this.options.transformTagName&&(a=this.options.transformTagName(a)),n&&o&&n.tagname!=="!xml"&&(o=this.saveTextToParentTag(o,n,i,!1));const m=n;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)){let p="";if(c.length>0&&c.lastIndexOf("/")===c.length-1)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;else if(this.options.unpairedTags.indexOf(a)!==-1)r=u.closeIndex;else{const y=this.readStopNodeData(e,f,g+1);if(!y)throw new Error(`Unexpected end of ${f}`);r=y.i,p=y.tagContent}const _=new x(a);a!==c&&d&&(_[":@"]=this.buildAttributesMap(c,i,a)),p&&(p=this.parseTextData(p,a,i,!0,d,!0,!0)),i=i.substr(0,i.lastIndexOf(".")),_.add(this.options.textNodeName,p),this.addChild(n,_,i)}else{if(c.length>0&&c.lastIndexOf("/")===c.length-1){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));const p=new x(a);a!==c&&d&&(p[":@"]=this.buildAttributesMap(c,i,a)),this.addChild(n,p,i),i=i.substr(0,i.lastIndexOf("."))}else{const p=new x(a);this.tagsNodeStack.push(n),a!==c&&d&&(p[":@"]=this.buildAttributesMap(c,i,a)),this.addChild(n,p,i),n=p}o="",r=g}}else o+=e[r];return t.child};function Ge(e,t,n){const o=this.options.updateTag(t.tagname,n,t[":@"]);o===!1||(typeof o=="string"&&(t.tagname=o),e.addChild(t))}const Ke=function(e){if(this.options.processEntities){for(let t in this.docTypeEntities){const n=this.docTypeEntities[t];e=e.replace(n.regx,n.val)}for(let t in this.lastEntities){const n=this.lastEntities[t];e=e.replace(n.regex,n.val)}if(this.options.htmlEntities)for(let t in this.htmlEntities){const n=this.htmlEntities[t];e=e.replace(n.regex,n.val)}e=e.replace(this.ampEntity.regex,this.ampEntity.val)}return e};function Je(e,t,n,o){return e&&(o===void 0&&(o=Object.keys(t.child).length===0),e=this.parseTextData(e,t.tagname,n,!1,t[":@"]?Object.keys(t[":@"]).length!==0:!1,o),e!==void 0&&e!==""&&t.add(this.options.textNodeName,e),e=""),e}function qe(e,t,n){const o="*."+n;for(const i in e){const r=e[i];if(o===r||t===r)return!0}return!1}function He(e,t,n=">"){let o,i="";for(let r=t;r<e.length;r++){let l=e[r];if(o)l===o&&(o="");else if(l==='"'||l==="'")o=l;else if(l===n[0])if(n[1]){if(e[r+1]===n[1])return{data:i,index:r}}else return{data:i,index:r};else l===" "&&(l=" ");i+=l}}function A(e,t,n,o){const i=e.indexOf(t,n);if(i===-1)throw new Error(o);return i+t.length-1}function I(e,t,n,o=">"){const i=He(e,t+1,o);if(!i)return;let r=i.data;const l=i.index,u=r.search(/\s/);let a=r,f=!0;u!==-1&&(a=r.substring(0,u),r=r.substring(u+1).trimStart());const c=a;if(n){const d=a.indexOf(":");d!==-1&&(a=a.substr(d+1),f=a!==i.data.substr(d+1))}return{tagName:a,tagExp:r,closeIndex:l,attrExpPresent:f,rawTagName:c}}function Ze(e,t,n){const o=n;let i=1;for(;n<e.length;n++)if(e[n]==="<")if(e[n+1]==="/"){const r=A(e,">",n,`${t} is not closed`);if(e.substring(n+2,r).trim()===t&&(i--,i===0))return{tagContent:e.substring(o,n),i:r};n=r}else if(e[n+1]==="?")n=A(e,"?>",n+1,"StopNode is not closed.");else if(e.substr(n+1,3)==="!--")n=A(e,"-->",n+3,"StopNode is not closed.");else if(e.substr(n+1,2)==="![")n=A(e,"]]>",n,"StopNode is not closed.")-2;else{const r=I(e,n,">");r&&((r&&r.tagName)===t&&r.tagExp[r.tagExp.length-1]!=="/"&&i++,n=r.closeIndex)}}function O(e,t,n){if(t&&typeof e=="string"){const o=e.trim();return o==="true"?!0:o==="false"?!1:Pe(e,n)}else return G.isExist(e)?e:""}var Ye=Ve,K={};function Qe(e,t){return J(e,t)}function J(e,t,n){let o;const i={};for(let r=0;r<e.length;r++){const l=e[r],u=We(l);let a="";if(n===void 0?a=u:a=n+"."+u,u===t.textNodeName)o===void 0?o=l[u]:o+=""+l[u];else{if(u===void 0)continue;if(l[u]){let f=J(l[u],t,a);const c=et(f,t);l[":@"]?De(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}}}return typeof o=="string"?o.length>0&&(i[t.textNodeName]=o):o!==void 0&&(i[t.textNodeName]=o),i}function We(e){const t=Object.keys(e);for(let n=0;n<t.length;n++){const o=t[n];if(o!==":@")return o}}function De(e,t,n,o){if(t){const i=Object.keys(t),r=i.length;for(let l=0;l<r;l++){const u=i[l];o.isArray(u,n+"."+u,!0,!0)?e[u]=[t[u]]:e[u]=t[u]}}}function et(e,t){const{textNodeName:n}=t,o=Object.keys(e).length;return!!(o===0||o===1&&(e[n]||typeof e[n]=="boolean"||e[n]===0))}K.prettify=Qe;const{buildOptions:tt}=M,nt=Ye,{prettify:st}=K,rt=C;let it=class{constructor(t){this.externalEntities={},this.options=tt(t)}parse(t,n){if(typeof t!="string")if(t.toString)t=t.toString();else throw new Error("XML data is accepted in String or Bytes[] form.");if(n){n===!0&&(n={});const r=rt.validate(t,n);if(r!==!0)throw Error(`${r.err.msg}:${r.err.line}:${r.err.col}`)}const o=new nt(this.options);o.addExternalEntities(this.externalEntities);const i=o.parseXml(t);return this.options.preserveOrder||i===void 0?i:st(i,this.options)}addEntity(t,n){if(n.indexOf("&")!==-1)throw new Error("Entity value can't have '&'");if(t.indexOf("&")!==-1||t.indexOf(";")!==-1)throw new Error("An entity must be set without '&' and ';'. Eg. use '#xD' for '&#xD;'");if(n==="&")throw new Error("An entity with value '&' is not permitted");this.externalEntities[t]=n}};var ot=it;const at=`
5
+ `;function ut(e,t){let n="";return t.format&&t.indentBy.length>0&&(n=at),q(e,t,"",n)}function q(e,t,n,o){let i="",r=!1;for(let l=0;l<e.length;l++){const u=e[l],a=lt(u);if(a===void 0)continue;let f="";if(n.length===0?f=a:f=`${n}.${a}`,a===t.textNodeName){let p=u[a];ct(f,t)||(p=t.tagValueProcessor(a,p),p=H(p,t)),r&&(i+=o),i+=p,r=!1;continue}else if(a===t.cdataPropName){r&&(i+=o),i+=`<![CDATA[${u[a][0][t.textNodeName]}]]>`,r=!1;continue}else if(a===t.commentPropName){i+=o+`<!--${u[a][0][t.textNodeName]}-->`,r=!0;continue}else if(a[0]==="?"){const p=$(u[":@"],t),_=a==="?xml"?"":o;let y=u[a][0][t.textNodeName];y=y.length!==0?" "+y:"",i+=_+`<${a}${y}${p}?>`,r=!0;continue}let c=o;c!==""&&(c+=t.indentBy);const d=$(u[":@"],t),g=o+`<${a}${d}`,m=q(u[a],t,f,c);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}return i}function lt(e){const t=Object.keys(e);for(let n=0;n<t.length;n++){const o=t[n];if(e.hasOwnProperty(o)&&o!==":@")return o}}function $(e,t){let n="";if(e&&!t.ignoreAttributes)for(let o in e){if(!e.hasOwnProperty(o))continue;let i=t.attributeValueProcessor(o,e[o]);i=H(i,t),i===!0&&t.suppressBooleanAttributes?n+=` ${o.substr(t.attributeNamePrefix.length)}`:n+=` ${o.substr(t.attributeNamePrefix.length)}="${i}"`}return n}function ct(e,t){e=e.substr(0,e.length-t.textNodeName.length-1);let n=e.substr(e.lastIndexOf(".")+1);for(let o in t.stopNodes)if(t.stopNodes[o]===e||t.stopNodes[o]==="*."+n)return!0;return!1}function H(e,t){if(e&&e.length>0&&t.processEntities)for(let n=0;n<t.entities.length;n++){const o=t.entities[n];e=e.replace(o.regex,o.val)}return e}var ft=ut;const dt=ft,gt=U,ht={attributeNamePrefix:"@_",attributesGroupName:!1,textNodeName:"#text",ignoreAttributes:!0,cdataPropName:!1,format:!1,indentBy:" ",suppressEmptyNode:!1,suppressUnpairedNode:!0,suppressBooleanAttributes:!0,tagValueProcessor:function(e,t){return t},attributeValueProcessor:function(e,t){return t},preserveOrder:!1,commentPropName:!1,unpairedTags:[],entities:[{regex:new RegExp("&","g"),val:"&amp;"},{regex:new RegExp(">","g"),val:"&gt;"},{regex:new RegExp("<","g"),val:"&lt;"},{regex:new RegExp("'","g"),val:"&apos;"},{regex:new RegExp('"',"g"),val:"&quot;"}],processEntities:!0,stopNodes:[],oneListGroup:!1};function w(e){this.options=Object.assign({},ht,e),this.options.ignoreAttributes===!0||this.options.attributesGroupName?this.isAttribute=function(){return!1}:(this.ignoreAttributesFn=gt(this.options.ignoreAttributes),this.attrPrefixLen=this.options.attributeNamePrefix.length,this.isAttribute=bt),this.processTextOrObjNode=pt,this.options.format?(this.indentate=mt,this.tagEndChar=`>
6
+ `,this.newLine=`
7
+ `):(this.indentate=function(){return""},this.tagEndChar=">",this.newLine="")}w.prototype.build=function(e){return this.options.preserveOrder?dt(e,this.options):(Array.isArray(e)&&this.options.arrayNodeName&&this.options.arrayNodeName.length>1&&(e={[this.options.arrayNodeName]:e}),this.j2x(e,0,[]).val)};w.prototype.j2x=function(e,t,n){let o="",i="";const r=n.join(".");for(let l in e)if(Object.prototype.hasOwnProperty.call(e,l))if(typeof e[l]>"u")this.isAttribute(l)&&(i+="");else if(e[l]===null)this.isAttribute(l)?i+="":l[0]==="?"?i+=this.indentate(t)+"<"+l+"?"+this.tagEndChar:i+=this.indentate(t)+"<"+l+"/"+this.tagEndChar;else if(e[l]instanceof Date)i+=this.buildTextValNode(e[l],l,"",t);else if(typeof e[l]!="object"){const u=this.isAttribute(l);if(u&&!this.ignoreAttributesFn(u,r))o+=this.buildAttrPairStr(u,""+e[l]);else if(!u)if(l===this.options.textNodeName){let a=this.options.tagValueProcessor(l,""+e[l]);i+=this.replaceEntitiesValue(a)}else i+=this.buildTextValNode(e[l],l,"",t)}else if(Array.isArray(e[l])){const u=e[l].length;let a="",f="";for(let c=0;c<u;c++){const d=e[l][c];if(!(typeof d>"u"))if(d===null)l[0]==="?"?i+=this.indentate(t)+"<"+l+"?"+this.tagEndChar:i+=this.indentate(t)+"<"+l+"/"+this.tagEndChar;else if(typeof d=="object")if(this.options.oneListGroup){const g=this.j2x(d,t+1,n.concat(l));a+=g.val,this.options.attributesGroupName&&d.hasOwnProperty(this.options.attributesGroupName)&&(f+=g.attrStr)}else a+=this.processTextOrObjNode(d,l,t,n);else if(this.options.oneListGroup){let g=this.options.tagValueProcessor(l,d);g=this.replaceEntitiesValue(g),a+=g}else a+=this.buildTextValNode(d,l,"",t)}this.options.oneListGroup&&(a=this.buildObjectNode(a,l,f,t)),i+=a}else if(this.options.attributesGroupName&&l===this.options.attributesGroupName){const u=Object.keys(e[l]),a=u.length;for(let f=0;f<a;f++)o+=this.buildAttrPairStr(u[f],""+e[l][u[f]])}else i+=this.processTextOrObjNode(e[l],l,t,n);return{attrStr:o,val:i}};w.prototype.buildAttrPairStr=function(e,t){return t=this.options.attributeValueProcessor(e,""+t),t=this.replaceEntitiesValue(t),this.options.suppressBooleanAttributes&&t==="true"?" "+e:" "+e+'="'+t+'"'};function pt(e,t,n,o){const i=this.j2x(e,n+1,o.concat(t));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)}w.prototype.buildObjectNode=function(e,t,n,o){if(e==="")return t[0]==="?"?this.indentate(o)+"<"+t+n+"?"+this.tagEndChar:this.indentate(o)+"<"+t+n+this.closeTag(t)+this.tagEndChar;{let i="</"+t+this.tagEndChar,r="";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}};w.prototype.closeTag=function(e){let t="";return this.options.unpairedTags.indexOf(e)!==-1?this.options.suppressUnpairedNode||(t="/"):this.options.suppressEmptyNode?t="/":t=`></${e}`,t};w.prototype.buildTextValNode=function(e,t,n,o){if(this.options.cdataPropName!==!1&&t===this.options.cdataPropName)return this.indentate(o)+`<![CDATA[${e}]]>`+this.newLine;if(this.options.commentPropName!==!1&&t===this.options.commentPropName)return this.indentate(o)+`<!--${e}-->`+this.newLine;if(t[0]==="?")return this.indentate(o)+"<"+t+n+"?"+this.tagEndChar;{let i=this.options.tagValueProcessor(t,e);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}};w.prototype.replaceEntitiesValue=function(e){if(e&&e.length>0&&this.options.processEntities)for(let t=0;t<this.options.entities.length;t++){const n=this.options.entities[t];e=e.replace(n.regex,n.val)}return e};function mt(e){return this.options.indentBy.repeat(e)}function bt(e){return e.startsWith(this.options.attributeNamePrefix)&&e!==this.options.textNodeName?e.substr(this.attrPrefixLen):!1}var Nt=w;const yt=C,wt=ot,zt=Nt;var j={XMLParser:wt,XMLValidator:yt,XMLBuilder:zt};class Z{constructor(t,n){z(this,"alphabet");z(this,"padding");z(this,"decodeMap",new Map);if(t.length!==32)throw new Error("Invalid alphabet");if(this.alphabet=t,this.padding=(n==null?void 0:n.padding)??"=",this.alphabet.includes(this.padding)||this.padding.length!==1)throw new Error("Invalid padding");for(let o=0;o<t.length;o++)this.decodeMap.set(t[o],o)}encode(t,n){let o="",i=0,r=0;for(let u=0;u<t.length;u++)for(i=i<<8|t[u],r+=8;r>=5;)r-=5,o+=this.alphabet[i>>r&31];if(r>0&&(o+=this.alphabet[i<<5-r&31]),(n==null?void 0:n.includePadding)??!0){const u=(8-o.length%8)%8;for(let a=0;a<u;a++)o+="="}return o}decode(t,n){const o=(n==null?void 0:n.strict)??!0,i=Math.ceil(t.length/8),r=[];for(let l=0;l<i;l++){let u=0;const a=[];for(let c=0;c<8;c++){const d=t[l*8+c];if(d==="="){if(l+1!==i)throw new Error(`Invalid character: ${d}`);u+=1;continue}if(d===void 0){if(o)throw new Error("Invalid data");u+=1;continue}const g=this.decodeMap.get(d)??null;if(g===null)throw new Error(`Invalid character: ${d}`);a.push(g)}if(u===8||u===7||u===5||u===2)throw new Error("Invalid padding");const f=(a[0]<<3)+(a[1]>>2);if(r.push(f),u<6){const c=((a[1]&3)<<6)+(a[2]<<1)+(a[3]>>4);r.push(c)}if(u<4){const c=((a[3]&255)<<4)+(a[4]>>1);r.push(c)}if(u<3){const c=((a[4]&1)<<7)+(a[5]<<2)+(a[6]>>3);r.push(c)}if(u<1){const c=((a[6]&7)<<5)+a[7];r.push(c)}}return Uint8Array.from(r)}}new Z("ABCDEFGHIJKLMNOPQRSTUVWXYZ234567");new Z("0123456789ABCDEFGHIJKLMNOPQRSTUV");class Y{constructor(t,n){z(this,"alphabet");z(this,"padding");z(this,"decodeMap",new Map);if(t.length!==64)throw new Error("Invalid alphabet");if(this.alphabet=t,this.padding=(n==null?void 0:n.padding)??"=",this.alphabet.includes(this.padding)||this.padding.length!==1)throw new Error("Invalid padding");for(let o=0;o<t.length;o++)this.decodeMap.set(t[o],o)}encode(t,n){let o="",i=0,r=0;for(let u=0;u<t.length;u++)for(i=i<<8|t[u],r+=8;r>=6;)r+=-6,o+=this.alphabet[i>>r&63];if(r>0&&(o+=this.alphabet[i<<6-r&63]),(n==null?void 0:n.includePadding)??!0){const u=(4-o.length%4)%4;for(let a=0;a<u;a++)o+="="}return o}decode(t,n){const o=(n==null?void 0:n.strict)??!0,i=Math.ceil(t.length/4),r=[];for(let l=0;l<i;l++){let u=0,a=0;for(let f=0;f<4;f++){const c=t[l*4+f];if(c==="="){if(l+1!==i)throw new Error(`Invalid character: ${c}`);u+=1;continue}if(c===void 0){if(o)throw new Error("Invalid data");u+=1;continue}const d=this.decodeMap.get(c)??null;if(d===null)throw new Error(`Invalid character: ${c}`);a+=d<<6*(3-f)}r.push(a>>16&255),u<2&&r.push(a>>8&255),u<1&&r.push(a&255)}return Uint8Array.from(r)}}const At=new Y("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/");new Y("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_");const _t="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";let X=(e=21)=>{let t="",n=crypto.getRandomValues(new Uint8Array(e));for(;e--;)t+=_t[n[e]&63];return t};async function Q(e){const t=new DecompressionStream("deflate-raw"),n=new Uint8Array(e),o=new Blob([n]).stream().pipeThrough(t);return new Uint8Array(await new Response(o).arrayBuffer())}async function W(e){const t=await At.decode(e.replace(/ /g,"+"));try{const n=await Q(t);return new TextDecoder().decode(n)}catch(n){return console.warn("Decompression failed, assuming data is not compressed:",n),new TextDecoder().decode(t)}}async function St(e){const t=await W(e),o=new j.XMLParser({attributeNamePrefix:"@_",alwaysCreateTextNode:!0,ignoreAttributes:!1}).parse(t);return B.parse(o)}function xt(e){const t=e.certificates.map(i=>({"@_use":"signing",KeyInfo:{"@_xmlns":"http://www.w3.org/2000/09/xmldsig#",X509Data:{X509Certificate:i}}})),n={EntityDescriptor:{"@_entityID":e.entityId,"@_xmlns":"urn:oasis:names:tc:SAML:2.0:metadata",IDPSSODescriptor:{"@_protocolSupportEnumeration":"urn:oasis:names:tc:SAML:2.0:protocol",KeyDescriptor:t,SingleLogoutService:[{"@_Binding":"urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect","@_Location":e.singleLogoutServiceUrl},{"@_Binding":"urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST","@_Location":e.singleLogoutServiceUrl}],NameIDFormat:["urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress","urn:oasis:names:tc:SAML:2.0:nameid-format:persistent","urn:oasis:names:tc:SAML:2.0:nameid-format:transient"],SingleSignOnService:[{"@_Binding":"urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect","@_Location":e.assertionConsumerServiceUrl},{"@_Binding":"urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST","@_Location":e.assertionConsumerServiceUrl}],Attribute:[{"@_Name":"http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress","@_NameFormat":"urn:oasis:names:tc:SAML:2.0:attrname-format:uri","@_FriendlyName":"E-Mail Address","@_xmlns":"urn:oasis:names:tc:SAML:2.0:assertion"},{"@_Name":"http://schemas.xmlsoap.org/ws/2005/05/identity/claims/givenname","@_NameFormat":"urn:oasis:names:tc:SAML:2.0:attrname-format:uri","@_FriendlyName":"Given Name","@_xmlns":"urn:oasis:names:tc:SAML:2.0:assertion"},{"@_Name":"http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name","@_NameFormat":"urn:oasis:names:tc:SAML:2.0:attrname-format:uri","@_FriendlyName":"Name","@_xmlns":"urn:oasis:names:tc:SAML:2.0:assertion"},{"@_Name":"http://schemas.xmlsoap.org/ws/2005/05/identity/claims/surname","@_NameFormat":"urn:oasis:names:tc:SAML:2.0:attrname-format:uri","@_FriendlyName":"Surname","@_xmlns":"urn:oasis:names:tc:SAML:2.0:assertion"},{"@_Name":"http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier","@_NameFormat":"urn:oasis:names:tc:SAML:2.0:attrname-format:uri","@_FriendlyName":"Name ID","@_xmlns":"urn:oasis:names:tc:SAML:2.0:assertion"}]}}};return new j.XMLBuilder({ignoreAttributes:!1,suppressEmptyNode:!0,preserveOrder:!1,format:!0,attributeNamePrefix:"@_"}).build(n)}async function Et(e,t){const n=e.notBefore||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||`_${X()}`,u=e.assertionId||`_${X()}`,a=[{"samlp:Response":[{"saml:Issuer":[{"#text":e.issuer}]},{"samlp:Status":[{"samlp:StatusCode":[],":@":{"@_Value":"urn:oasis:names:tc:SAML:2.0:status:Success"}}]},{"saml:Assertion":[{"saml:Issuer":[{"#text":e.issuer}]},{"saml:Subject":[{"saml:NameID":[{"#text":e.email}],":@":{"@_Format":"urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress"}},{"saml:SubjectConfirmation":[{"saml:SubjectConfirmationData":[],":@":{"@_InResponseTo":e.inResponseTo,"@_NotOnOrAfter":o,"@_Recipient":e.destination}}],":@":{"@_Method":"urn:oasis:names:tc:SAML:2.0:cm:bearer"}}]},{"saml:Conditions":[{"saml:AudienceRestriction":[{"saml:Audience":[{"#text":e.audience}]}]}],":@":{"@_NotBefore":n,"@_NotOnOrAfter":o}},{"saml:AuthnStatement":[{"saml:AuthnContext":[{"saml:AuthnContextClassRef":[{"#text":"urn:oasis:names:tc:SAML:2.0:ac:classes:unspecified"}]}]}],":@":{"@_AuthnInstant":i,"@_SessionIndex":e.sessionIndex,"@_SessionNotOnOrAfter":r}},{"saml:AttributeStatement":[{"saml:Attribute":[{":@":{"@_FriendlyName":"persistent","@_Name":"id","@_NameFormat":"urn:oasis:names:tc:SAML:2.0:attrname-format:unspecified"},"saml:AttributeValue":[{"#text":e.userId,":@":{"@_xmlns:xs":"http://www.w3.org/2001/XMLSchema","@_xmlns:xsi":"http://www.w3.org/2001/XMLSchema-instance","@_xsi:type":"xs:string"}}]}]},{"saml:Attribute":[{":@":{"@_Name":"email","@_NameFormat":"urn:oasis:names:tc:SAML:2.0:attrname-format:basic"},"saml:AttributeValue":[{"#text":e.email,":@":{"@_xmlns:xs":"http://www.w3.org/2001/XMLSchema","@_xmlns:xsi":"http://www.w3.org/2001/XMLSchema-instance","@_xsi:type":"xs:string"}}]}]},{"saml:Attribute":[{":@":{"@_Name":"Role","@_NameFormat":"urn:oasis:names:tc:SAML:2.0:attrname-format:basic"},"saml:AttributeValue":[{"#text":"manage-account",":@":{"@_xmlns:xs":"http://www.w3.org/2001/XMLSchema","@_xmlns:xsi":"http://www.w3.org/2001/XMLSchema-instance","@_xsi:type":"xs:string"}}]}]},{"saml:Attribute":[{":@":{"@_Name":"Role","@_NameFormat":"urn:oasis:names:tc:SAML:2.0:attrname-format:basic"},"saml:AttributeValue":[{"#text":"default-roles-master",":@":{"@_xmlns:xs":"http://www.w3.org/2001/XMLSchema","@_xmlns:xsi":"http://www.w3.org/2001/XMLSchema-instance","@_xsi:type":"xs:string"}}]}]},{"saml:Attribute":[{":@":{"@_Name":"Role","@_NameFormat":"urn:oasis:names:tc:SAML:2.0:attrname-format:basic"},"saml:AttributeValue":[{"#text":"offline_access",":@":{"@_xmlns:xs":"http://www.w3.org/2001/XMLSchema","@_xmlns:xsi":"http://www.w3.org/2001/XMLSchema-instance","@_xsi:type":"xs:string"}}]}]},{"saml:Attribute":[{":@":{"@_Name":"Role","@_NameFormat":"urn:oasis:names:tc:SAML:2.0:attrname-format:basic"},"saml:AttributeValue":[{"#text":"view-profile",":@":{"@_xmlns:xs":"http://www.w3.org/2001/XMLSchema","@_xmlns:xsi":"http://www.w3.org/2001/XMLSchema-instance","@_xsi:type":"xs:string"}}]}]},{"saml:Attribute":[{":@":{"@_Name":"Role","@_NameFormat":"urn:oasis:names:tc:SAML:2.0:attrname-format:basic"},"saml:AttributeValue":[{"#text":"uma_authorization",":@":{"@_xmlns:xs":"http://www.w3.org/2001/XMLSchema","@_xmlns:xsi":"http://www.w3.org/2001/XMLSchema-instance","@_xsi:type":"xs:string"}}]}]},{"saml:Attribute":[{":@":{"@_Name":"Role","@_NameFormat":"urn:oasis:names:tc:SAML:2.0:attrname-format:basic"},"saml:AttributeValue":[{"#text":"manage-account-links",":@":{"@_xmlns:xs":"http://www.w3.org/2001/XMLSchema","@_xmlns:xsi":"http://www.w3.org/2001/XMLSchema-instance","@_xsi:type":"xs:string"}}]}]}]}],":@":{"@_xmlns":"urn:oasis:names:tc:SAML:2.0:assertion","@_ID":u,"@_IssueInstant":i,"@_Version":"2.0"}}],":@":{"@_xmlns:samlp":"urn:oasis:names:tc:SAML:2.0:protocol","@_xmlns:saml":"urn:oasis:names:tc:SAML:2.0:assertion","@_Destination":e.destination,"@_ID":l,"@_InResponseTo":e.inResponseTo,"@_IssueInstant":i,"@_Version":"2.0"}}];let c=new j.XMLBuilder({ignoreAttributes:!1,suppressEmptyNode:!0,preserveOrder:!0}).build(a);return e.signature&&t&&(c=await t.signSAML(c,e.signature.privateKeyPem,e.signature.cert)),e.encode===!1?c:btoa(c)}class Tt{constructor(t){this.signUrl=t}async signSAML(t,n,o){const i=await fetch(this.signUrl,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({xmlContent:t,privateKey:n,publicCert:o})});if(!i.ok)throw new Error(`Failed to sign SAML via HTTP: ${i.status} ${i.statusText}`);return await i.text()}}exports.HttpSamlSigner=Tt;exports.createSamlMetadata=xt;exports.createSamlResponse=Et;exports.dsSignatureSchema=T;exports.inflateDecompress=W;exports.inflateRaw=Q;exports.parseSamlRequestQuery=St;exports.samlIssuerSchema=R;exports.samlMetadataResponseSchema=te;exports.samlRequestSchema=B;exports.samlResponseJsonSchema=re;