@authhero/saml 0.1.55 → 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 +164 -2
- package/dist/core.cjs +7 -0
- package/dist/core.d.ts +4312 -0
- package/dist/core.mjs +1903 -0
- package/dist/local-signer.cjs +1 -0
- package/dist/local-signer.d.ts +25 -0
- package/dist/local-signer.mjs +39 -0
- package/dist/saml.cjs +7 -0
- package/dist/saml.d.ts +4319 -0
- package/dist/saml.mjs +1940 -0
- package/package.json +35 -10
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var m=Object.create;var s=Object.defineProperty;var w=Object.getOwnPropertyDescriptor;var d=Object.getOwnPropertyNames;var h=Object.getPrototypeOf,p=Object.prototype.hasOwnProperty;var u=(e,t,r,a)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of d(t))!p.call(e,o)&&o!==r&&s(e,o,{get:()=>t[o],enumerable:!(a=w(t,o))||a.enumerable});return e};var S=(e,t,r)=>(r=e!=null?m(h(e)):{},u(t||!e||!e.__esModule?s(r,"default",{value:e,enumerable:!0}):r,e));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const f="http://www.w3.org/2001/04/xmldsig-more#rsa-sha256",y="http://www.w3.org/2001/04/xmlenc#sha256",c="http://www.w3.org/2001/10/xml-exc-c14n#";class A{async signSAML(t,r,a){var o;try{const l=await import("xml-crypto"),i=l.SignedXml||((o=l.default)==null?void 0:o.SignedXml);if(!i)throw new Error("SignedXml not found in xml-crypto module");const n=new i({privateKey:r,publicCert:a});n.canonicalizationAlgorithm=c,n.addReference({xpath:"(/*[local-name()='Response']/*[local-name()='Assertion'])[1]",digestAlgorithm:y,transforms:["http://www.w3.org/2000/09/xmldsig#enveloped-signature",c]}),n.signatureAlgorithm=f;const g=a.replace(/-----BEGIN CERTIFICATE-----|-----END CERTIFICATE-----/g,"").replace(/\s/g,"");return n.keyInfoProvider={getKeyInfo:()=>`<X509Data><X509Certificate>${g}</X509Certificate></X509Data>`},n.computeSignature(t,{location:{reference:"/*[local-name()='Response']/*[local-name()='Assertion']/*[local-name()='Issuer']",action:"after"}}),n.getSignedXml()}catch(l){throw new Error(`Failed to sign SAML locally. Make sure xml-crypto is installed. Error: ${l}`)}}}exports.LocalSamlSigner=A;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// Generated by dts-bundle-generator v9.5.1
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Interface for SAML signing implementations.
|
|
5
|
+
* This allows for different signing strategies (local, HTTP, etc.)
|
|
6
|
+
*/
|
|
7
|
+
export interface SamlSigner {
|
|
8
|
+
/**
|
|
9
|
+
* Signs SAML XML content with the provided private key and certificate
|
|
10
|
+
* @param xmlContent - The XML content to sign
|
|
11
|
+
* @param privateKey - The private key in PEM format
|
|
12
|
+
* @param publicCert - The public certificate
|
|
13
|
+
* @returns The signed XML content
|
|
14
|
+
*/
|
|
15
|
+
signSAML(xmlContent: string, privateKey: string, publicCert: string): Promise<string>;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Local SAML signer that uses xml-crypto library.
|
|
19
|
+
* This implementation requires Node.js and cannot be used in edge/browser environments.
|
|
20
|
+
*/
|
|
21
|
+
export declare class LocalSamlSigner implements SamlSigner {
|
|
22
|
+
signSAML(xmlContent: string, privateKey: string, publicCert: string): Promise<string>;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export {};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
const c = "http://www.w3.org/2001/04/xmldsig-more#rsa-sha256", g = "http://www.w3.org/2001/04/xmlenc#sha256", a = "http://www.w3.org/2001/10/xml-exc-c14n#";
|
|
2
|
+
class w {
|
|
3
|
+
async signSAML(l, i, o) {
|
|
4
|
+
var r;
|
|
5
|
+
try {
|
|
6
|
+
const t = await import("xml-crypto"), n = t.SignedXml || ((r = t.default) == null ? void 0 : r.SignedXml);
|
|
7
|
+
if (!n)
|
|
8
|
+
throw new Error("SignedXml not found in xml-crypto module");
|
|
9
|
+
const e = new n({ privateKey: i, publicCert: o });
|
|
10
|
+
e.canonicalizationAlgorithm = a, e.addReference({
|
|
11
|
+
xpath: "(/*[local-name()='Response']/*[local-name()='Assertion'])[1]",
|
|
12
|
+
digestAlgorithm: g,
|
|
13
|
+
transforms: [
|
|
14
|
+
"http://www.w3.org/2000/09/xmldsig#enveloped-signature",
|
|
15
|
+
a
|
|
16
|
+
]
|
|
17
|
+
}), e.signatureAlgorithm = c;
|
|
18
|
+
const s = o.replace(/-----BEGIN CERTIFICATE-----|-----END CERTIFICATE-----/g, "").replace(/\s/g, "");
|
|
19
|
+
return e.keyInfoProvider = {
|
|
20
|
+
getKeyInfo: () => `<X509Data><X509Certificate>${s}</X509Certificate></X509Data>`
|
|
21
|
+
}, e.computeSignature(l, {
|
|
22
|
+
// according to:
|
|
23
|
+
// https://docs.oasis-open.org/security/saml/v2.0/saml-schema-assertion-2.0.xsd
|
|
24
|
+
// Assertion's ds:Signature must be after Assertion/Issuer
|
|
25
|
+
location: {
|
|
26
|
+
reference: "/*[local-name()='Response']/*[local-name()='Assertion']/*[local-name()='Issuer']",
|
|
27
|
+
action: "after"
|
|
28
|
+
}
|
|
29
|
+
}), e.getSignedXml();
|
|
30
|
+
} catch (t) {
|
|
31
|
+
throw new Error(
|
|
32
|
+
`Failed to sign SAML locally. Make sure xml-crypto is installed. Error: ${t}`
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
export {
|
|
38
|
+
w as LocalSamlSigner
|
|
39
|
+
};
|
package/dist/saml.cjs
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";var te=Object.create;var I=Object.defineProperty;var ne=Object.getOwnPropertyDescriptor;var se=Object.getOwnPropertyNames;var re=Object.getPrototypeOf,ie=Object.prototype.hasOwnProperty;var oe=(e,t,n)=>t in e?I(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var ae=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of se(t))!ie.call(e,i)&&i!==n&&I(e,i,{get:()=>t[i],enumerable:!(o=ne(t,i))||o.enumerable});return e};var ue=(e,t,n)=>(n=e!=null?te(re(e)):{},ae(t||!e||!e.__esModule?I(n,"default",{value:e,enumerable:!0}):n,e));var z=(e,t,n)=>oe(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()}),k=s.z.object({"#text":s.z.string(),"@_xmlns:saml":s.z.string().optional()}),U=s.z.object({"samlp:AuthnRequest":s.z.object({"saml:Issuer":k,"@_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()})}),le=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()})})]))}))})),ce=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()}))}),fe=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(fe)}),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()}),de=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(ce)}))})])),":@":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 L={},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 M=E,ge={allowBooleanAttributes:!1,unpairedTags:[]};L.validate=function(e,t){t=Object.assign({},ge,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=F(e,r),r.err)return r}else if(e[r]==="<"){let l=r;if(r++,e[r]==="!"){r=V(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--),!ze(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=me(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=X(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=X(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=V(e,r);continue}else if(e[r+1]==="?"){if(r=F(e,++r),r.err)return r}else break;else if(e[r]==="&"){const d=we(e,r);if(d==-1)return h("InvalidChar","char '&' is not expected.",N(e,r));r=d}else if(i===!0&&!P(e[r]))return h("InvalidXml","Extra text at the end",N(e,r));e[r]==="<"&&r--}}else{if(P(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 P(e){return e===" "||e===" "||e===`
|
|
3
|
+
`||e==="\r"}function F(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 V(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 he='"',pe="'";function me(e,t){let n="",o="",i=!1;for(;t<e.length;t++){if(e[t]===he||e[t]===pe)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 be=new RegExp(`(\\s*)([^\\s=]+)(\\s*=)?(\\s*(['"])(([\\s\\S])*?)\\5)?`,"g");function X(e,t){const n=M.getAllMatches(e,be),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(!ye(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 Ne(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 we(e,t){if(t++,e[t]===";")return-1;if(e[t]==="#")return t++,Ne(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 ye(e){return M.isName(e)}function ze(e){return M.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 j={};const G={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}},Ae=function(e){return Object.assign({},G,e)};j.buildOptions=Ae;j.defaultOptions=G;class _e{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 Se=_e;const xe=E;function Ee(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&&Oe(e,t)){t+=7;let u,a;[u,a,t]=Ie(e,t+1),a.indexOf("&")===-1&&(n[je(u)]={regx:RegExp(`&${u};`,"g"),val:a})}else if(i&&Ce(e,t))t+=8;else if(i&&Le(e,t))t+=8;else if(i&&Me(e,t))t+=9;else if(Te)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 Ie(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 Te(e,t){return e[t+1]==="!"&&e[t+2]==="-"&&e[t+3]==="-"}function Oe(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 Ce(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 Le(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 Me(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 je(e){if(xe.isName(e))return e;throw new Error(`Invalid entity name ${e}`)}var ve=Ee;const Pe=/^[-+]?0x[a-fA-F0-9]+$/,Fe=/^([\-\+])?(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 Ve={hex:!0,leadingZeros:!0,decimalPoint:".",eNotation:!0};function Xe(e,t={}){if(t=Object.assign({},Ve,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&&Pe.test(n))return Number.parseInt(n,16);{const o=Fe.exec(n);if(o){const i=o[1],r=o[2];let l=$e(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 $e(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 Re=Xe;function Be(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 K=Be;const J=E,x=Se,ke=ve,Ue=Re,Ge=K;let Ke=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=Je,this.parseXml=Qe,this.parseTextData=qe,this.resolveNameSpace=He,this.buildAttributesMap=Ye,this.isItStopNode=tt,this.replaceEntitiesValue=De,this.readStopNodeData=st,this.saveTextToParentTag=et,this.addChild=We,this.ignoreAttributesFn=Ge(this.options.ignoreAttributes)}};function Je(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 qe(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?C(e,this.options.parseTagValue,this.options.numberParseOptions):e.trim()===e?C(e,this.options.parseTagValue,this.options.numberParseOptions):e}}function He(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 Ze=new RegExp(`([^\\s=]+)\\s*(=\\s*(['"])([\\s\\S]*?)\\3)?`,"gm");function Ye(e,t,n){if(this.options.ignoreAttributes!==!0&&typeof e=="string"){const o=J.getAllMatches(e,Ze),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]=C(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 Qe=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=O(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=ke(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=O(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 w=this.readStopNodeData(e,f,g+1);if(!w)throw new Error(`Unexpected end of ${f}`);r=w.i,p=w.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 We(e,t,n){const o=this.options.updateTag(t.tagname,n,t[":@"]);o===!1||(typeof o=="string"&&(t.tagname=o),e.addChild(t))}const De=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 et(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 tt(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 nt(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 O(e,t,n,o=">"){const i=nt(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 st(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=O(e,n,">");r&&((r&&r.tagName)===t&&r.tagExp[r.tagExp.length-1]!=="/"&&i++,n=r.closeIndex)}}function C(e,t,n){if(t&&typeof e=="string"){const o=e.trim();return o==="true"?!0:o==="false"?!1:Ue(e,n)}else return J.isExist(e)?e:""}var rt=Ke,q={};function it(e,t){return H(e,t)}function H(e,t,n){let o;const i={};for(let r=0;r<e.length;r++){const l=e[r],u=ot(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=H(l[u],t,a);const c=ut(f,t);l[":@"]?at(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 ot(e){const t=Object.keys(e);for(let n=0;n<t.length;n++){const o=t[n];if(o!==":@")return o}}function at(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 ut(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))}q.prettify=it;const{buildOptions:lt}=j,ct=rt,{prettify:ft}=q,dt=L;let gt=class{constructor(t){this.externalEntities={},this.options=lt(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=dt.validate(t,n);if(r!==!0)throw Error(`${r.err.msg}:${r.err.line}:${r.err.col}`)}const o=new ct(this.options);o.addExternalEntities(this.externalEntities);const i=o.parseXml(t);return this.options.preserveOrder||i===void 0?i:ft(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 '
'");if(n==="&")throw new Error("An entity with value '&' is not permitted");this.externalEntities[t]=n}};var ht=gt;const pt=`
|
|
5
|
+
`;function mt(e,t){let n="";return t.format&&t.indentBy.length>0&&(n=pt),Z(e,t,"",n)}function Z(e,t,n,o){let i="",r=!1;for(let l=0;l<e.length;l++){const u=e[l],a=bt(u);if(a===void 0)continue;let f="";if(n.length===0?f=a:f=`${n}.${a}`,a===t.textNodeName){let p=u[a];Nt(f,t)||(p=t.tagValueProcessor(a,p),p=Y(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 w=u[a][0][t.textNodeName];w=w.length!==0?" "+w:"",i+=_+`<${a}${w}${p}?>`,r=!0;continue}let c=o;c!==""&&(c+=t.indentBy);const d=$(u[":@"],t),g=o+`<${a}${d}`,m=Z(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 bt(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=Y(i,t),i===!0&&t.suppressBooleanAttributes?n+=` ${o.substr(t.attributeNamePrefix.length)}`:n+=` ${o.substr(t.attributeNamePrefix.length)}="${i}"`}return n}function Nt(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 Y(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 wt=mt;const yt=wt,zt=K,At={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:"&"},{regex:new RegExp(">","g"),val:">"},{regex:new RegExp("<","g"),val:"<"},{regex:new RegExp("'","g"),val:"'"},{regex:new RegExp('"',"g"),val:"""}],processEntities:!0,stopNodes:[],oneListGroup:!1};function y(e){this.options=Object.assign({},At,e),this.options.ignoreAttributes===!0||this.options.attributesGroupName?this.isAttribute=function(){return!1}:(this.ignoreAttributesFn=zt(this.options.ignoreAttributes),this.attrPrefixLen=this.options.attributeNamePrefix.length,this.isAttribute=xt),this.processTextOrObjNode=_t,this.options.format?(this.indentate=St,this.tagEndChar=`>
|
|
6
|
+
`,this.newLine=`
|
|
7
|
+
`):(this.indentate=function(){return""},this.tagEndChar=">",this.newLine="")}y.prototype.build=function(e){return this.options.preserveOrder?yt(e,this.options):(Array.isArray(e)&&this.options.arrayNodeName&&this.options.arrayNodeName.length>1&&(e={[this.options.arrayNodeName]:e}),this.j2x(e,0,[]).val)};y.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}};y.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 _t(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)}y.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}};y.prototype.closeTag=function(e){let t="";return this.options.unpairedTags.indexOf(e)!==-1?this.options.suppressUnpairedNode||(t="/"):this.options.suppressEmptyNode?t="/":t=`></${e}`,t};y.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}};y.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 St(e){return this.options.indentBy.repeat(e)}function xt(e){return e.startsWith(this.options.attributeNamePrefix)&&e!==this.options.textNodeName?e.substr(this.attrPrefixLen):!1}var Et=y;const It=L,Tt=ht,Ot=Et;var v={XMLParser:Tt,XMLValidator:It,XMLBuilder:Ot};class Q{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 Q("ABCDEFGHIJKLMNOPQRSTUVWXYZ234567");new Q("0123456789ABCDEFGHIJKLMNOPQRSTUV");class W{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 Ct=new W("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/");new W("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_");const Lt="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";let R=(e=21)=>{let t="",n=crypto.getRandomValues(new Uint8Array(e));for(;e--;)t+=Lt[n[e]&63];return t};async function D(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 ee(e){const t=await Ct.decode(e.replace(/ /g,"+"));try{const n=await D(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 Mt(e){const t=await ee(e),o=new v.XMLParser({attributeNamePrefix:"@_",alwaysCreateTextNode:!0,ignoreAttributes:!1}).parse(t);return U.parse(o)}function jt(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 v.XMLBuilder({ignoreAttributes:!1,suppressEmptyNode:!0,preserveOrder:!1,format:!0,attributeNamePrefix:"@_"}).build(n)}async function vt(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||`_${R()}`,u=e.assertionId||`_${R()}`,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 v.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)}const Pt="http://www.w3.org/2001/04/xmldsig-more#rsa-sha256",Ft="http://www.w3.org/2001/04/xmlenc#sha256",B="http://www.w3.org/2001/10/xml-exc-c14n#";class Vt{async signSAML(t,n,o){var i;try{const r=await import("xml-crypto"),l=r.SignedXml||((i=r.default)==null?void 0:i.SignedXml);if(!l)throw new Error("SignedXml not found in xml-crypto module");const u=new l({privateKey:n,publicCert:o});u.canonicalizationAlgorithm=B,u.addReference({xpath:"(/*[local-name()='Response']/*[local-name()='Assertion'])[1]",digestAlgorithm:Ft,transforms:["http://www.w3.org/2000/09/xmldsig#enveloped-signature",B]}),u.signatureAlgorithm=Pt;const a=o.replace(/-----BEGIN CERTIFICATE-----|-----END CERTIFICATE-----/g,"").replace(/\s/g,"");return u.keyInfoProvider={getKeyInfo:()=>`<X509Data><X509Certificate>${a}</X509Certificate></X509Data>`},u.computeSignature(t,{location:{reference:"/*[local-name()='Response']/*[local-name()='Assertion']/*[local-name()='Issuer']",action:"after"}}),u.getSignedXml()}catch(r){throw new Error(`Failed to sign SAML locally. Make sure xml-crypto is installed. Error: ${r}`)}}}class Xt{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=Xt;exports.LocalSamlSigner=Vt;exports.createSamlMetadata=jt;exports.createSamlResponse=vt;exports.dsSignatureSchema=T;exports.inflateDecompress=ee;exports.inflateRaw=D;exports.parseSamlRequestQuery=Mt;exports.samlIssuerSchema=k;exports.samlMetadataResponseSchema=le;exports.samlRequestSchema=U;exports.samlResponseJsonSchema=de;
|