@muze-nl/metro-oidc 0.5.5 → 0.5.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser.js +259 -400
- package/dist/browser.js.map +4 -4
- package/dist/browser.min.js +1 -1
- package/dist/browser.min.js.map +4 -4
- package/package.json +2 -2
package/dist/browser.min.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
(()=>{var ze=Object.defineProperty;var Le=(e,o)=>{for(var t in o)ze(e,t,{get:o[t],enumerable:!0})};var J={};Le(J,{Client:()=>v,client:()=>L,deepClone:()=>z,formdata:()=>he,metroError:()=>g,request:()=>I,response:()=>F,trace:()=>Ce,url:()=>w});var H="https://metro.muze.nl/details/";Symbol.metroProxy||(Symbol.metroProxy=Symbol("isProxy"));Symbol.metroSource||(Symbol.metroSource=Symbol("source"));var v=class e{clientOptions={url:w(typeof window<"u"?window.location:"https://localhost"),verbs:["get","post","put","delete","patch","head","options","query"]};static tracers={};constructor(...o){for(let t of o)if(typeof t=="string"||t instanceof String)this.clientOptions.url=w(this.clientOptions.url.href,t);else if(t instanceof e)Object.assign(this.clientOptions,t.clientOptions);else if(t instanceof Function)this.#e([t]);else if(t&&typeof t=="object")for(let n in t)n=="middlewares"?this.#e(t[n]):n=="url"?this.clientOptions.url=w(this.clientOptions.url.href,t[n]):typeof t[n]=="function"?this.clientOptions[n]=t[n](this.clientOptions[n],this.clientOptions):this.clientOptions[n]=t[n];for(let t of this.clientOptions.verbs)this[t]=async function(...n){return this.fetch(I(this.clientOptions,...n,{method:t.toUpperCase()}))}}#e(o){typeof o=="function"&&(o=[o]);let t=o.findIndex(n=>typeof n!="function");if(t>=0)throw g("metro.client: middlewares must be a function or an array of functions "+H+"client/invalid-middlewares/",o[t]);Array.isArray(this.clientOptions.middlewares)||(this.clientOptions.middlewares=[]),this.clientOptions.middlewares=this.clientOptions.middlewares.concat(o)}fetch(o,t){if(o=I(o,t),!o.url)throw g("metro.client."+o.method.toLowerCase()+": Missing url parameter "+H+"client/fetch-missing-url/",o);if(t||(t={}),typeof t!="object"||t instanceof String)throw g("metro.client.fetch: Invalid options parameter "+H+"client/fetch-invalid-options/",t);let r=[async function(s){s[Symbol.metroProxy]&&(s=s[Symbol.metroSource]);let m=await fetch(s);return F(m)}].concat(this.clientOptions?.middlewares?.slice()||[]);t=Object.assign({},this.clientOptions,t);let i;for(let a of r)i=(function(s,m){return async function(_){let l,f=Object.values(e.tracers);for(let u of f)u.request&&u.request.call(u,_,m);l=await m(_,s);for(let u of f)u.response&&u.response.call(u,l,m);return l}})(i,a);return i(o)}with(...o){return new e(z(this.clientOptions),...o)}get location(){return this.clientOptions.url}};function L(...e){return new v(...z(e))}function Ue(e,o){let t=o||{};!t.url&&o.url&&(t.url=o.url);for(let n of["method","headers","body","mode","credentials","cache","redirect","referrer","referrerPolicy","integrity","keepalive","signal","priority","url"]){let r=e[n];if(!(typeof r>"u"||r==null))if(r?.[Symbol.metroProxy]&&(r=r[Symbol.metroSource]),typeof r=="function")t[n]=r(t[n],t);else if(n=="url")t.url=w(t.url,r);else if(n=="headers"){t.headers=new Headers(o.headers),r instanceof Headers||(r=new Headers(e.headers));for(let[i,a]of r.entries())t.headers.set(i,a)}else t[n]=r}return e instanceof Request&&e.data&&(t.body=e.data),t}function I(...e){let o={url:w(typeof window<"u"?window.location:"https://localhost/"),duplex:"half"};for(let r of e)typeof r=="string"||r instanceof URL||r instanceof URLSearchParams?o.url=w(o.url,r):r&&(r instanceof FormData||r instanceof ReadableStream||r instanceof Blob||r instanceof ArrayBuffer||r instanceof DataView)?o.body=r:r&&typeof r=="object"&&Object.assign(o,Ue(r,o));let t=new Request(o.url,o),n=o.body;return n&&typeof n=="object"&&!(n instanceof String)&&!(n instanceof ReadableStream)&&!(n instanceof Blob)&&!(n instanceof ArrayBuffer)&&!(n instanceof DataView)&&!(n instanceof FormData)&&!(n instanceof URLSearchParams)&&(typeof globalThis.TypedArray>"u"||!(n instanceof globalThis.TypedArray))&&typeof n.toString=="function"&&(o.body=n.toString({headers:t.headers}),t=new Request(o.url,o)),Object.freeze(t),new Proxy(t,{get(r,i){let a;switch(i){case Symbol.metroSource:a=r;break;case Symbol.metroProxy:a=!0;break;case"with":a=function(...s){return n&&s.unshift({body:n}),I(r,...s)};break;case"data":a=n;break;default:r[i]instanceof Function?a=r[i].bind(r):a=r[i];break}return a}})}function de(e,o){let t=o||{};!t.url&&o.url&&(t.url=o.url);for(let n of["status","statusText","headers","body","url","type","redirected"]){let r=e[n];typeof r>"u"||r==null||(r?.[Symbol.metroProxy]&&(r=r[Symbol.metroSource]),typeof r=="function"?t[n]=r(t[n],t):n=="url"?t.url=new URL(r,t.url||"https://localhost/"):t[n]=r)}return e instanceof Response&&e.data&&(t.body=e.data),t}function F(...e){let o={};for(let r of e)typeof r=="string"?o.body=r:r instanceof Response?Object.assign(o,de(r,o)):r&&typeof r=="object"&&(r instanceof FormData||r instanceof Blob||r instanceof ArrayBuffer||r instanceof DataView||r instanceof ReadableStream||r instanceof URLSearchParams||r instanceof String||typeof globalThis.TypedArray<"u"&&r instanceof globalThis.TypedArray?o.body=r:Object.assign(o,de(r,o)));let t;o.body&&(t=o.body),[101,204,205,304].includes(o.status)&&(o.body=null);let n=new Response(o.body,o);return Object.freeze(n),new Proxy(n,{get(r,i){let a;switch(i){case Symbol.metroProxy:a=!0;break;case Symbol.metroSource:a=r;break;case"with":a=function(...s){return F(r,...s)};break;case"data":a=t;break;case"ok":a=r.status>=200&&r.status<400;break;default:typeof r[i]=="function"?a=r[i].bind(r):a=r[i];break}return a}})}function pe(e,o){typeof o=="function"?o(e.searchParams,e):(o=new URLSearchParams(o),o.forEach((t,n)=>{e.searchParams.append(n,t)}))}function w(...e){let o=["hash","host","hostname","href","password","pathname","port","protocol","username","search","searchParams"],t=new URL("https://localhost/");for(let n of e)if(typeof n=="string"||n instanceof String)t=new URL(n,t);else if(n instanceof URL||typeof Location<"u"&&n instanceof Location)t=new URL(n);else if(n instanceof URLSearchParams)pe(t,n);else if(n&&typeof n=="object")for(let r in n)switch(r){case"search":typeof n.search=="function"?n.search(t.search,t):t.search=new URLSearchParams(n.search);break;case"searchParams":pe(t,n.searchParams);break;default:if(!o.includes(r))throw g("metro.url: unknown url parameter "+H+"url/unknown-param-name/",r);if(typeof n[r]=="function")n[r](t[r],t);else if(typeof n[r]=="string"||n[r]instanceof String||typeof n[r]=="number"||n[r]instanceof Number||typeof n[r]=="boolean"||n[r]instanceof Boolean)t[r]=""+n[r];else if(typeof n[r]=="object"&&n[r].toString)t[r]=n[r].toString();else throw g("metro.url: unsupported value for "+r+" "+H+"url/unsupported-param-value/",e[r]);break}else throw g("metro.url: unsupported option value "+H+"url/unsupported-option-value/",n);return Object.freeze(t),new Proxy(t,{get(n,r){let i;switch(r){case Symbol.metroProxy:i=!0;break;case Symbol.metroSource:i=n;break;case"with":i=function(...a){return w(n,...a)};break;case"filename":i=n.pathname.split("/").pop();break;case"folderpath":i=n.pathname.substring(0,n.pathname.lastIndexOf("\\")+1);break;case"authority":i=n.username??"",i+=n.password?":"+n.password:"",i+=i?"@":"",i+=n.hostname,i+=n.port?":"+n.port:"",i+="/",i=n.protocol+"//"+i;break;case"origin":i=n.protocol+"//"+n.hostname,i+=n.port?":"+n.port:"",i+="/";break;case"fragment":i=n.hash.substring(1);break;case"scheme":n.protocol?i=n.protocol.substring(0,n.protocol.length-1):i="";break;default:n[r]instanceof Function?i=n[r].bind(n):i=n[r];break}return i}})}function he(...e){var o=new FormData;for(let t of e)if(t instanceof HTMLFormElement&&(t=new FormData(t)),t instanceof FormData)for(let n of t.entries())o.append(n[0],n[1]);else if(t&&typeof t=="object")for(let n of Object.entries(t))if(Array.isArray(n[1]))for(let r of n[1])o.append(n[0],r);else o.append(n[0],n[1]);else throw new g("metro.formdata: unknown option type "+H+"formdata/unknown-option-value/",t);return Object.freeze(o),new Proxy(o,{get(t,n){let r;switch(n){case Symbol.metroProxy:r=!0;break;case Symbol.metroSource:r=t;break;case"with":r=function(...i){return he(t,...i)};break;default:t[n]instanceof Function?r=t[n].bind(t):r=t[n];break}return r}})}var Z={error:(e,...o)=>{console.error("\u24C2\uFE0F ",e,...o)},info:(e,...o)=>{console.info("\u24C2\uFE0F ",e,...o)},group:e=>{console.group("\u24C2\uFE0F "+e)},groupEnd:e=>{console.groupEnd("\u24C2\uFE0F "+e)}};function g(e,...o){return Z.error(e,...o),new Error(e,...o)}var Ce={add(e,o){v.tracers[e]=o},delete(e){delete v.tracers[e]},clear(){v.tracers={}},group(){let e=0;return{request:(o,t)=>{e++,Z.group(e),Z.info(o?.url,o,t)},response:(o,t)=>{Z.info(o?.body?o.body[Symbol.metroSource]:null,o,t),Z.groupEnd(e),e--}}}};function z(e){if(Array.isArray(e))return e.slice().map(z);if(e&&typeof e=="object")if(e.__proto__.constructor==Object||!e.__proto__){let o=Object.assign({},e);return Object.keys(o).forEach(t=>{o[t]=z(e[t])}),o}else return e;return e}function R(e){return e=Object.assign({contentType:"application/json",reviver:null,replacer:null,space:""},e),async function(t,n){if(t.headers.get("Accept")||(t=t.with({headers:{Accept:e.accept??e.contentType}})),t.method!=="GET"&&t.method!=="HEAD"&&t.data&&typeof t.data=="object"&&!(t.data instanceof ReadableStream)){let i=t.headers.get("Content-Type");(!i||Ke(i))&&(t=t.with({headers:{"Content-Type":e.contentType}})),me(t.headers.get("Content-Type"))&&(t=t.with({body:JSON.stringify(t.data,e.replacer,e.space)}))}let r=await n(t);if(r&&me(r.headers?.get("Content-Type"))){let a=await r.clone().text();try{let s=JSON.parse(a,e.reviver);return r.with({body:s})}catch{}}return r}}var De=/^application\/([a-zA-Z0-9\-_]+\+)?json\b/;function me(e){return De.exec(e)}function Ke(e){return/^text\/plain\b/.exec(e)}function P(e){return async function(t,n){let r=await n(t);if(!r.ok)if(e&&typeof e[r.status]=="function")r=e[r.status].apply(r,t);else throw new Error(r.status+": "+r.statusText,{cause:r});return r}}function W(){return async function(o,t){let n=await t(o);return n.ok&&n.data?n.data:n}}var Y=class extends v{constructor(o,t,n=null){o instanceof v?super(o.clientOptions,P(),W()):super(o,P(),W()),n||(n=this);for(let r in t)typeof t[r]=="function"?this[r]=t[r].bind(n):t[r]&&typeof t[r]=="object"?this[r]=new this.constructor(o,t[r],n):this[r]=t[r]}},oe=class extends Y{constructor(o,t,n=null){o instanceof v?super(o.with(R()),t,n):super(L(o,R()),t,n)}};function _e(...e){return new Y(...z(e))}function ye(...e){return new oe(...z(e))}var ge=Object.assign({},J,{mw:{json:R,thrower:P,getdata:W},api:_e,jsonApi:ye});globalThis.metro||(globalThis.metro=ge);var j=ge;globalThis.assertEnabled=!1;function M(e,o){if(globalThis.assertEnabled){let t=U(e,o);if(t)throw console.error("\u{1F170}\uFE0F Assertions failed because of:",t,"in this source:",e),new Error("Assertions failed",{cause:{problems:t,source:e}})}}function we(e){return function(t,n,r){if(typeof t<"u"&&t!=null&&typeof e<"u")return U(t,e,n,r)}}function T(e){return function(t,n,r){return t==null||typeof t>"u"?k("data is required",t,e||"any value",r):typeof e<"u"?U(t,e,n,r):!1}}function C(e,o,t){try{e instanceof URL&&(e=e.href);let n=new URL(e);if(n.href!=e&&!(n.href+"/"==e||n.href==e+"/"))return k("data is not a valid url",e,"validURL",t)}catch{return k("data is not a valid url",e,"validURL",t)}}function U(e,o,t,n=""){t||(t=e);let r=[];if(o===Boolean)typeof e!="boolean"&&!(e instanceof Boolean)&&r.push(k("data is not a boolean",e,o,n));else if(o===Number)typeof e!="number"&&!(e instanceof Number)&&r.push(k("data is not a number",e,o,n));else if(o===String)typeof e!="string"&&!(e instanceof String)&&r.push(k("data is not a string",e,o,n)),e==""&&r.push(k("data is an empty string, which is not allowed",e,o,n));else if(o instanceof RegExp)if(Array.isArray(e)){let i=e.findIndex((a,s)=>U(a,o,t,n+"["+s+"]"));i>-1&&r.push(k("data["+i+"] does not match pattern",e[i],o,n+"["+i+"]"))}else typeof e>"u"?r.push(k("data is undefined, should match pattern",e,o,n)):o.test(e)||r.push(k("data does not match pattern",e,o,n));else if(o instanceof Function){let i=o(e,t,n);i&&(Array.isArray(i)?r=r.concat(i):r.push(i))}else if(Array.isArray(o)){Array.isArray(e)||r.push(k("data is not an array",e,[],n));for(let i of o)for(let a of e.keys()){let s=U(e[a],i,t,n+"["+a+"]");Array.isArray(s)?r=r.concat(s):s&&r.push(s)}}else if(o&&typeof o=="object")if(Array.isArray(e)){let i=e.findIndex((a,s)=>U(a,o,t,n+"["+s+"]"));i>-1&&r.push(k("data["+i+"] does not match pattern",e[i],o,n+"["+i+"]"))}else if(!e||typeof e!="object")r.push(k("data is not an object, pattern is",e,o,n));else if(e instanceof URLSearchParams&&(e=Object.fromEntries(e)),o instanceof Function){let i=U(e,o,t,n);i&&(r=r.concat(i))}else for(let[i,a]of Object.entries(o)){let s=U(e[i],a,t,n+"."+i);s&&(r=r.concat(s))}else o!=e&&r.push(k("data and pattern are not equal",e,o,n));return r.length?r:!1}function k(e,o,t,n,r){let i={path:n,message:e,found:o,expected:t};return r&&(i.problems=r),i}function be(e){let o,t;if(typeof localStorage<"u")o={get:()=>localStorage.getItem("metro/state:"+e),set:n=>localStorage.setItem("metro/state:"+e,n),has:()=>localStorage.getItem("metro/state:"+e)!==null,delete:()=>localStorage.remoteItem("metro/state:"+e)},t={get:n=>JSON.parse(localStorage.getItem(e+":"+n)),set:(n,r)=>localStorage.setItem(e+":"+n,JSON.stringify(r)),has:n=>localStorage.getItem(e+":"+n)!==null,delete:n=>localStorage.removeItem(e+":"+n)};else{let n=new Map;o={get:()=>n.get("metro/state:"+e),set:r=>n.set("metro/state:"+e,r),has:()=>n.has("metro/state:"+e),delete:()=>n.delete("metro/state:"+e)},t=new Map}return{state:o,tokens:t}}function ie(e){let o={client:L(),force_authorization:!1,site:"default",oauth2_configuration:{authorization_endpoint:"/authorize",token_endpoint:"/token",redirect_uri:globalThis.document?.location.href,grant_type:"authorization_code",code_verifier:Ie(64)},authorize_callback:async l=>(window.location.href!=l.href&&window.location.replace(l.href),!1)};M(e,{});let t=Object.assign({},o.oauth2_configuration,e?.oauth2_configuration);e=Object.assign({},o,e),e.oauth2_configuration=t;let n=be(e.site);e.tokens||(e.tokens=n.tokens),e.state||(e.state=n.state),M(e,{oauth2_configuration:{client_id:T(/.+/),grant_type:"authorization_code",authorization_endpoint:T(C),token_endpoint:T(C),redirect_uri:T(C)}});for(let l in t)switch(l){case"access_token":case"authorization_code":case"refresh_token":e.tokens.set(l,t[l]);break}return async function(l,f){if(e.force_authorization)return r(l,f);let u;try{if(u=await f(l),u.ok)return u}catch(p){switch(u?.status){case 400:case 401:return r(l,f)}throw p}if(!u.ok)switch(u.status){case 400:case 401:return r(l,f)}return u};async function r(l,f){i();let u=e.tokens.get("access_token"),p=e.tokens.get("refresh_token"),S=He(u);if(!u||S&&!p){try{if(!await a())return F("false")}catch(O){throw O}return r(l,f)}else if(S&&p){try{if(!await s())return F("false")}catch(O){throw O}return r(l,f)}else return l=I(l,{headers:{Authorization:u.type+" "+u.value}}),f(l)}function i(){if(typeof window<"u"&&window?.location){let l=w(window.location),f,u,p;if(l.searchParams.has("code"))p=l.searchParams,l=l.with({search:""}),history.pushState({},"",l.href);else if(l.hash){let S=l.hash.substr(1);p=new URLSearchParams("?"+S),l=l.with({hash:""}),history.pushState({},"",l.href)}if(p){f=p.get("code"),u=p.get("state");let S=e.state.get("metro/state");if(!u||u!==S)return;f&&e.tokens.set("authorization_code",f)}}}async function a(){if(t.grant_type==="authorization_code"&&!e.tokens.has("authorization_code")){let p=await m();if(!e.authorize_callback||typeof e.authorize_callback!="function")throw g("oauth2mw: oauth2 with grant_type:authorization_code requires a callback function in client options.authorize_callback");let S=await e.authorize_callback(p);if(S)e.tokens.set("authorization_code",S);else return!1}let l=_(),f=await e.client.post(l);if(!f.ok){let p=await f.text();throw g("OAuth2mw: fetch access_token: "+f.status+": "+f.statusText,{cause:l})}let u=await f.json();if(e.tokens.set("access_token",{value:u.access_token,expires:ke(u.expires_in),type:u.token_type,scope:u.scope}),u.refresh_token){let p={value:u.refresh_token};e.tokens.set("refresh_token",p)}return e.tokens.delete("authorization_code"),u}async function s(){let l=_("refresh_token"),f=await e.client.post(l);if(!f.ok)throw g("OAuth2mw: refresh access_token: "+f.status+": "+f.statusText,{cause:l});let u=await f.json();if(e.tokens.set("access_token",{value:u.access_token,expires:ke(u.expires_in),type:u.token_type,scope:u.scope}),u.refresh_token){let p={value:u.refresh_token};e.tokens.set("refresh_token",p)}else return!1;return u}async function m(){if(!t.authorization_endpoint)throw g("oauth2mw: Missing options.oauth2_configuration.authorization_endpoint");let l=w(t.authorization_endpoint,{hash:""});M(t,{client_id:/.+/,redirect_uri:/.+/,scope:/.*/});let f={response_type:"code",client_id:t.client_id,redirect_uri:t.redirect_uri,state:t.state||Be(40)};return t.response_type&&(f.response_type=t.response_type),t.response_mode&&(f.response_mode=t.response_mode),e.state.set(f.state),t.client_secret&&(f.client_secret=t.client_secret),t.code_verifier&&(e.tokens.set("code_verifier",t.code_verifier),f.code_challenge=await Me(t.code_verifier),f.code_challenge_method="S256"),t.scope&&(f.scope=t.scope),t.prompt&&(f.prompt=t.prompt),w(l,{search:f})}function _(l=null){if(M(t,{client_id:/.+/,redirect_uri:/.+/}),!t.token_endpoint)throw g("oauth2mw: Missing options.endpoints.token url");let f=w(t.token_endpoint,{hash:""}),u={grant_type:l||t.grant_type,client_id:t.client_id};switch(t.client_secret&&(u.client_secret=t.client_secret),t.scope&&(u.scope=t.scope),u.grant_type){case"authorization_code":u.redirect_uri=t.redirect_uri,u.code=e.tokens.get("authorization_code");let p=e.tokens.get("code_verifier");p&&(u.code_verifier=p);break;case"client_credentials":break;case"refresh_token":let S=e.tokens.get("refresh_token");u.refresh_token=S.value;break;default:throw new Error("Unknown grant_type: ".oauth2.grant_type)}return I(f,{method:"POST",body:new URLSearchParams(u)})}}function He(e){if(!e)return!0;let o=new Date(e.expires);return new Date().getTime()>o.getTime()}function ke(e){if(e instanceof Date)return new Date(e.getTime());if(typeof e=="number"){let o=new Date;return o.setSeconds(o.getSeconds()+e),o}throw new TypeError("Unknown expires type "+e)}function Ie(e=64){let o=new Uint8Array(e);return globalThis.crypto.getRandomValues(o),Se(o)}async function Me(e){let t=new TextEncoder().encode(e),n=await globalThis.crypto.subtle.digest("SHA-256",t);return Se(n)}function Se(e){let o=Array.from(new Uint8Array(e),t=>String.fromCharCode(t)).join("");return btoa(o).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}function Be(e){let o="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",t="",n=0;for(;n<e;)t+=o.charAt(Math.floor(Math.random()*o.length)),n++;return t}function xe(){let e=new URL(document.location.href);if(!e.searchParams.has("code")){if(e.hash){let o=e.hash.substr(1);if(params=new URLSearchParams("?"+o),params.has("code"))return!0}return!1}return!0}function se(){return new Promise((e,o)=>{let t=globalThis.indexedDB.open("metro",1);t.onupgradeneeded=()=>t.result.createObjectStore("keyPairs",{keyPath:"domain"}),t.onerror=n=>{o(n)},t.onsuccess=n=>{let r=n.target.result;e({set:function(i,a){return new Promise((s,m)=>{let _=r.transaction("keyPairs","readwrite",{durability:"strict"}),l=_.objectStore("keyPairs");_.oncomplete=()=>{s()},_.onerror=m,l.put(i,a)})},get:function(i){return new Promise((a,s)=>{let m=r.transaction("keyPairs","readonly"),l=m.objectStore("keyPairs").get(i);l.onsuccess=()=>{a(l.result)},l.onerror=s,m.onerror=s})},clear:function(){return new Promise((i,a)=>{let s=r.transaction("keyPairs","readwrite"),_=s.objectStore("keyPairs").clear();_.onsuccess=()=>{i()},_.onerror=a,s.onerror=a})}})}})}var Fe=new TextEncoder,Je=new TextDecoder;function ee(e){return typeof e=="string"?Fe.encode(e):Je.decode(e)}function ve(e){if(typeof e.modulusLength!="number"||e.modulusLength<2048)throw new ae(`${e.name} modulusLength must be at least 2048 bits`)}function We(e){switch(e.algorithm.name){case"ECDSA":return{name:e.algorithm.name,hash:"SHA-256"};case"RSA-PSS":return ve(e.algorithm),{name:e.algorithm.name,saltLength:32};case"RSASSA-PKCS1-v1_5":return ve(e.algorithm),{name:e.algorithm.name};case"Ed25519":return{name:e.algorithm.name}}throw new D}async function $e(e,o,t){if(t.usages.includes("sign")===!1)throw new TypeError('private CryptoKey instances used for signing assertions must include "sign" in their "usages"');let n=`${G(ee(JSON.stringify(e)))}.${G(ee(JSON.stringify(o)))}`,r=G(await crypto.subtle.sign(We(t),t,ee(n)));return`${n}.${r}`}var Ae=32768;function Ve(e){e instanceof ArrayBuffer&&(e=new Uint8Array(e));let o=[];for(let t=0;t<e.byteLength;t+=Ae)o.push(String.fromCharCode.apply(null,e.subarray(t,t+Ae)));return btoa(o.join("")).replace(/=/g,"").replace(/\+/g,"-").replace(/\//g,"_")}function G(e){return Ve(e)}function Ze(){return G(crypto.getRandomValues(new Uint8Array(32)))}var D=class extends Error{constructor(o){super(o??"operation not supported"),this.name=this.constructor.name,Error.captureStackTrace?.(this,this.constructor)}},ae=class extends Error{constructor(o){super(o),this.name=this.constructor.name,Error.captureStackTrace?.(this,this.constructor)}};function Ge(e){if(e.algorithm.hash.name==="SHA-256")return"PS256";throw new D("unsupported RsaHashedKeyAlgorithm hash name")}function qe(e){if(e.algorithm.hash.name==="SHA-256")return"RS256";throw new D("unsupported RsaHashedKeyAlgorithm hash name")}function Qe(e){if(e.algorithm.namedCurve==="P-256")return"ES256";throw new D("unsupported EcKeyAlgorithm namedCurve")}function Xe(e){switch(e.algorithm.name){case"RSA-PSS":return Ge(e);case"RSASSA-PKCS1-v1_5":return qe(e);case"ECDSA":return Qe(e);case"Ed25519":return"EdDSA";default:throw new D("unsupported CryptoKey algorithm name")}}function Oe(e){return e instanceof CryptoKey}function Ye(e){return Oe(e)&&e.type==="private"}function et(e){return Oe(e)&&e.type==="public"}function tt(){return Math.floor(Date.now()/1e3)}async function te(e,o,t,n,r,i){let a=e?.privateKey,s=e?.publicKey;if(!Ye(a))throw new TypeError('"keypair.privateKey" must be a private CryptoKey');if(!et(s))throw new TypeError('"keypair.publicKey" must be a public CryptoKey');if(s.extractable!==!0)throw new TypeError('"keypair.publicKey.extractable" must be true');if(typeof o!="string")throw new TypeError('"htu" must be a string');if(typeof t!="string")throw new TypeError('"htm" must be a string');if(n!==void 0&&typeof n!="string")throw new TypeError('"nonce" must be a string or undefined');if(r!==void 0&&typeof r!="string")throw new TypeError('"accessToken" must be a string or undefined');if(i!==void 0&&(typeof i!="object"||i===null||Array.isArray(i)))throw new TypeError('"additional" must be an object');return $e({alg:Xe(a),typ:"dpop+jwt",jwk:await rt(s)},{...i,iat:tt(),jti:Ze(),htm:t,nonce:n,htu:o,ath:r?G(await crypto.subtle.digest("SHA-256",ee(r))):void 0},a)}async function rt(e){let{kty:o,e:t,n,x:r,y:i,crv:a}=await crypto.subtle.exportKey("jwk",e);return{kty:o,crv:a,e:t,n,x:r,y:i}}async function Re(e,o){let t;if(typeof e!="string"||e.length===0)throw new TypeError('"alg" must be a non-empty string');switch(e){case"PS256":t={name:"RSA-PSS",hash:"SHA-256",modulusLength:o?.modulusLength??2048,publicExponent:new Uint8Array([1,0,1])};break;case"RS256":t={name:"RSASSA-PKCS1-v1_5",hash:"SHA-256",modulusLength:o?.modulusLength??2048,publicExponent:new Uint8Array([1,0,1])};break;case"ES256":t={name:"ECDSA",namedCurve:"P-256"};break;case"EdDSA":t={name:"Ed25519"};break;default:throw new D}return crypto.subtle.generateKey(t,o?.extractable??!1,["sign","verify"])}function ce(e){return M(e,{site:T(C),authorization_endpoint:T(C),token_endpoint:T(C),dpop_signing_alg_values_supported:we([])}),async(o,t)=>{let n=await se(),r=await n.get(e.site);if(!r){let s=await Re("ES256");r={domain:e.site,keyPair:s},await n.set(r)}let i=j.url(o.url);if(o.url.startsWith(e.authorization_endpoint)){let s=o.body;s instanceof URLSearchParams||s instanceof FormData?s.set("dpop_jkt",r.keyPair.publicKey):s.dpop_jkt=r.keyPair.publicKey}else if(o.url.startsWith(e.token_endpoint)){let s=await te(r.keyPair,o.url,o.method);o=o.with({headers:{DPoP:s}})}else if(o.headers.has("Authorization")){let s=localStorage.getItem(i.host+":nonce")||void 0,m=o.headers.get("Authorization").split(" ")[1],_=await te(r.keyPair,o.url,o.method,s,m);o=o.with({headers:{Authorization:"DPoP "+m,DPoP:_}})}let a=await t(o);return a.headers.get("DPoP-Nonce")&&localStorage.setItem(i.host+":nonce",a.headers.get("DPoP-Nonce")),a}}globalThis.assertEnabled=!1;function nt(){globalThis.assertEnabled=!0}function ot(){globalThis.assertEnabled=!1}function E(e,o){if(globalThis.assertEnabled){let t=x(e,o);if(t)throw console.error("\u{1F170}\uFE0F Assertions failed because of:",t,"in this source:",e),new Error("Assertions failed",{cause:{problems:t,source:e}})}}function c(e){return function(t,n,r){if(typeof t<"u"&&t!=null&&typeof e<"u")return x(t,e,n,r)}}function y(e){return function(t,n,r){return t==null||typeof t>"u"?h("data is required",t,e||"any value",r):typeof e<"u"?x(t,e,n,r):!1}}function $(e){return function(t,n,r){return t==null||typeof t>"u"?(Pe("data does not contain recommended value",t,e,r),!1):x(t,e,n,r)}}function b(...e){return function(t,n,r){for(let i of e)if(!x(t,i,n,r))return!1;return h("data does not match oneOf patterns",t,e,r)}}function B(...e){return function(t,n,r){if(!Array.isArray(t))return h("data is not an array",t,"anyOf",r);for(let i of t)if(b(...e)(i))return h("data does not match anyOf patterns",i,e,r);return!1}}function le(...e){return function(t,n,r){let i=[];for(let a of e)i=i.concat(x(t,a,n,r));if(i=i.filter(Boolean),i.length)return h("data does not match all given patterns",t,e,r,i)}}function d(e,o,t){try{e instanceof URL&&(e=e.href);let n=new URL(e);if(n.href!=e&&!(n.href+"/"==e||n.href==e+"/"))return h("data is not a valid url",e,"validURL",t)}catch{return h("data is not a valid url",e,"validURL",t)}}function ue(e,o,t){if(!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(e))return h("data is not a valid email",e,"validEmail",t)}function N(e){return function(t,n,r){if(!(t instanceof e))return h("data is not an instanceof pattern",t,e,r)}}function V(e){return function(t,n,r){if(!x(t,e,n,r))return h("data matches pattern, when required not to",t,e,r)}}function x(e,o,t,n=""){t||(t=e);let r=[];if(o===Boolean)typeof e!="boolean"&&!(e instanceof Boolean)&&r.push(h("data is not a boolean",e,o,n));else if(o===Number)typeof e!="number"&&!(e instanceof Number)&&r.push(h("data is not a number",e,o,n));else if(o===String)typeof e!="string"&&!(e instanceof String)&&r.push(h("data is not a string",e,o,n)),e==""&&r.push(h("data is an empty string, which is not allowed",e,o,n));else if(o instanceof RegExp)if(Array.isArray(e)){let i=e.findIndex((a,s)=>x(a,o,t,n+"["+s+"]"));i>-1&&r.push(h("data["+i+"] does not match pattern",e[i],o,n+"["+i+"]"))}else typeof e>"u"?r.push(h("data is undefined, should match pattern",e,o,n)):o.test(e)||r.push(h("data does not match pattern",e,o,n));else if(o instanceof Function){let i=o(e,t,n);i&&(Array.isArray(i)?r=r.concat(i):r.push(i))}else if(Array.isArray(o)){Array.isArray(e)||r.push(h("data is not an array",e,[],n));for(let i of o)for(let a of e.keys()){let s=x(e[a],i,t,n+"["+a+"]");Array.isArray(s)?r=r.concat(s):s&&r.push(s)}}else if(o&&typeof o=="object")if(Array.isArray(e)){let i=e.findIndex((a,s)=>x(a,o,t,n+"["+s+"]"));i>-1&&r.push(h("data["+i+"] does not match pattern",e[i],o,n+"["+i+"]"))}else if(!e||typeof e!="object")r.push(h("data is not an object, pattern is",e,o,n));else if(e instanceof URLSearchParams&&(e=Object.fromEntries(e)),o instanceof Function){let i=x(e,o,t,n);i&&(r=r.concat(i))}else for(let[i,a]of Object.entries(o)){let s=x(e[i],a,t,n+"."+i);s&&(r=r.concat(s))}else o!=e&&r.push(h("data and pattern are not equal",e,o,n));return r.length?r:!1}function h(e,o,t,n,r){let i={path:n,message:e,found:o,expected:t};return r&&(i.problems=r),i}function Pe(e,o,t,n){console.warn("\u{1F170}\uFE0F Assert: "+n,e,t,o)}globalThis.assert={warn:Pe,error:h,assert:E,enable:nt,disable:ot,Required:y,Recommended:$,Optional:c,oneOf:b,anyOf:B,allOf:le,validURL:d,validEmail:ue,instanceOf:N,not:V,fails:x};var q=(...e)=>(o,t)=>e.filter(n=>t.hasOwnKey(n)).length>0?!1:h("root data must have all of",t,e),K=(...e)=>o=>Array.isArray(o)&&e.filter(t=>!o.includes(t)).length==0?!1:h("data must be an array which includes",o,e);var A=["HS256","HS384","HS512","RS256","RS384","RS512","ES256","ES384","ES512"],re=["client_secret_post","client_secret_basic","client_secret_jwt","private_key_jwt"];async function Q(e={}){E(e,{client:c(N(j.client().constructor)),issuer:y(d)});let o={client:j.client().with(P()).with(R()),requireDynamicRegistration:!1};e=Object.assign({},o,e);let t=!1;function n(m){return t}let r={issuer:y(le(e.issuer,n)),authorization_endpoint:y(d),token_endpoint:y(d),userinfo_endpoint:$(d),jwks_uri:y(d),registration_endpoint:e.requireDynamicRegistration?y(d):$(d),scopes_supported:$(K("openid")),response_types_supported:e.requireDynamicRegistration?y(K("code","id_token","id_token token")):y([]),response_modes_supported:c([]),grant_types_supported:e.requireDynamicRegistration?c(K("authorization_code")):c([]),acr_values_supported:c([]),subject_types_supported:y([]),id_token_signing_alg_values_supported:y(K("RS256")),id_token_encryption_alg_values_supported:c([]),id_token_encryption_enc_values_supported:c([]),userinfo_signing_alg_values_supported:c([]),userinfo_encryption_alg_values_supported:c([]),userinfo_encryption_enc_values_supported:c([]),request_object_signing_alg_values_supported:c(K("RS256")),request_object_encryption_alg_values_supported:c([]),request_object_encryption_enc_values_supported:c([]),token_endpoint_auth_methods_supported:c(B(...re)),token_endpoint_auth_signing_alg_values_supported:c(K("RS256"),V(K("none"))),display_values_supported:c(B("page","popup","touch","wap")),claim_types_supported:c(B("normal","aggregated","distributed")),claims_supported:$([]),service_documentation:c(d),claims_locales_supported:c([]),ui_locales_supported:c([]),claims_parameter_supported:c(Boolean),request_parameter_supported:c(Boolean),request_uri_parameter_supported:c(Boolean),op_policy_uri:c(d),op_tos_uri:c(d)},i=j.url(e.issuer,".well-known/openid-configuration"),s=(await e.client.get(i)).data;return E(s,r),E(s.issuer,e.issuer),s}async function X(e){let o={redirect_uris:y([d]),response_types:c([]),grant_types:c(B("authorization_code","refresh_token")),application_type:c(b("native","web")),contacts:c([ue]),client_name:c(String),logo_uri:c(d),client_uri:c(d),policy_uri:c(d),tos_uri:c(d),jwks_uri:c(d,V(q("jwks"))),jwks:c(d,V(q("jwks_uri"))),sector_identifier_uri:c(d),subject_type:c(String),id_token_signed_response_alg:c(b(...A)),id_token_encrypted_response_alg:c(b(...A)),id_token_encrypted_response_enc:c(b(...A),q("id_token_encrypted_response_alg")),userinfo_signed_response_alg:c(b(...A)),userinfo_encrypted_response_alg:c(b(...A)),userinfo_encrypted_response_enc:c(b(...A),q("userinfo_encrypted_response_alg")),request_object_signing_alg:c(b(...A)),request_object_encryption_alg:c(b(...A)),request_object_encryption_enc:c(b(...A)),token_endpoint_auth_method:c(b(...re)),token_endpoint_auth_signing_alg:c(b(...A)),default_max_age:c(Number),require_auth_time:c(Boolean),default_acr_values:c([String]),initiate_login_uri:c([d]),request_uris:c([d])};E(e,{client:c(N(j.client().constructor)),registration_endpoint:d,client_info:o});let t={client:j.client().with(P()).with(R()),client_info:{redirect_uris:[globalThis.document?.location.href]}};e=Object.assign({},t,e),e.client_info||(e.client_info={}),e.client_info.redirect_uris||(e.client_info.redirect_uris=[globalThis.document?.location.href]);let n=await e.client.post(e.registration_endpoint,{body:e.client_info}),r=n.data;if(!r.client_id||!r.client_secret)throw j.metroError("metro.oidc: Error: dynamic registration of client failed, no client_id or client_secret returned",n);return e.client_info=Object.assign(e.client_info,r),e.client_info}function ne(e){let o;if(typeof localStorage<"u")o={get:t=>JSON.parse(localStorage.getItem("metro/oidc:"+e+":"+t)),set:(t,n)=>localStorage.setItem("metro/oidc:"+e+":"+t,JSON.stringify(n)),has:t=>localStorage.getItem("metro/oidc:"+e+":"+t)!==null};else{let t=new Map;o={get:n=>JSON.parse(t.get("metro/oidc:"+e+":"+n)||null),set:(n,r)=>t.set("metro/oidc:"+e+":"+n,JSON.stringify(r)),has:n=>t.has("metro/oidc:"+e+":"+n)}}return o}function fe(e={}){let o={client:L(),force_authorization:!1,use_dpop:!0,authorize_callback:async t=>(window.location.href!=t.href&&window.location.replace(t.href),!1)};return e=Object.assign({},o,e),E(e,{client:y(N(L().constructor)),client_info:y(),issuer:y(d),oauth2:c({}),openid_configuration:c()}),e.store||(e.store=ne(e.issuer)),!e.openid_configuration&&e.store.has("openid_configuration")&&(e.openid_configuration=e.store.get("openid_configuration")),!e.client_info?.client_id&&e.store.has("client_info")&&(e.client_info=e.store.get("client_info")),async(t,n)=>{let r;if(!e.force_authorization){try{r=await n(t)}catch(_){if(r.status!=401&&r.status!=403)throw _}if(r.ok||r.status!=401&&r.status!=403)return r}if(e.openid_configuration||(e.openid_configuration=await Q({issuer:e.issuer}),e.store.set("openid_configuration",e.openid_configuration)),!e.client_info?.client_id){if(!e.openid_configuration.registration_endpoint)throw g("metro.oidcmw: Error: issuer "+e.issuer+" does not support dynamic client registration, but you haven't specified a client_id");e.client_info=await X({registration_endpoint:e.openid_configuration.registration_endpoint,client_info:e.client_info}),e.store.set("client_info",e.client_info)}let i=e.scope||"openid",a=Object.assign({site:e.issuer,client:e.client,force_authorization:!0,authorize_callback:e.authorize_callback,oauth2_configuration:{client_id:e.client_info?.client_id,client_secret:e.client_info?.client_secret,grant_type:"authorization_code",response_type:"code",response_mode:"query",authorization_endpoint:e.openid_configuration.authorization_endpoint,token_endpoint:e.openid_configuration.token_endpoint,scope:i,redirect_uri:e.client_info.redirect_uris[0]}}),s=async(_,l)=>{let f=await l(_);if(f.headers.get("content-type")?.startsWith("application/json")){let p=f.data?.id_token;if(!p){let S=f.clone();try{let O=await S.json();O&&O.id_token&&(p=O.id_token)}catch{}}p&&e.store.set("id_token",p)}return f},m=e.client.with(e.issuer).with(s);if(e.use_dpop){let _={site:e.issuer,authorization_endpoint:e.openid_configuration.authorization_endpoint,token_endpoint:e.openid_configuration.token_endpoint,dpop_signing_alg_values_supported:e.openid_configuration.dpop_signing_alg_values_supported};m=m.with(ce(_)),a.client=m}return m=m.with(ie(a)),r=await m.fetch(t),r}}function je(){return xe()}function Te(e){if(!e.store){if(!e.issuer)throw g("Must supply options.issuer or options.store to get the id_token");e.store=ne(e.issuer)}return e.store.get("id_token")}var Ee={oidcmw:fe,discover:Q,register:X,isRedirected:je,idToken:Te};globalThis.metro.oidc||(globalThis.metro.oidc=Ee);var sr=Ee;})();
|
|
1
|
+
(()=>{var Ae=Object.defineProperty;var Pe=(e,o)=>{for(var t in o)Ae(e,t,{get:o[t],enumerable:!0})};var I={};Pe(I,{Client:()=>v,client:()=>E,deepClone:()=>T,formdata:()=>ue,metroError:()=>g,request:()=>C,response:()=>H,trace:()=>je,url:()=>b});var L="https://metro.muze.nl/details/";Symbol.metroProxy||(Symbol.metroProxy=Symbol("isProxy"));Symbol.metroSource||(Symbol.metroSource=Symbol("source"));var v=class e{clientOptions={url:b(typeof window<"u"?window.location:"https://localhost"),verbs:["get","post","put","delete","patch","head","options","query"]};static tracers={};constructor(...o){for(let t of o)if(typeof t=="string"||t instanceof String)this.clientOptions.url=b(this.clientOptions.url.href,t);else if(t instanceof e)Object.assign(this.clientOptions,t.clientOptions);else if(t instanceof Function)this.#e([t]);else if(t&&typeof t=="object")for(let r in t)r=="middlewares"?this.#e(t[r]):r=="url"?this.clientOptions.url=b(this.clientOptions.url.href,t[r]):typeof t[r]=="function"?this.clientOptions[r]=t[r](this.clientOptions[r],this.clientOptions):this.clientOptions[r]=t[r];for(let t of this.clientOptions.verbs)this[t]=async function(...r){return this.fetch(C(this.clientOptions,...r,{method:t.toUpperCase()}))}}#e(o){typeof o=="function"&&(o=[o]);let t=o.findIndex(r=>typeof r!="function");if(t>=0)throw g("metro.client: middlewares must be a function or an array of functions "+L+"client/invalid-middlewares/",o[t]);Array.isArray(this.clientOptions.middlewares)||(this.clientOptions.middlewares=[]),this.clientOptions.middlewares=this.clientOptions.middlewares.concat(o)}fetch(o,t){if(o=C(o,t),!o.url)throw g("metro.client."+o.method.toLowerCase()+": Missing url parameter "+L+"client/fetch-missing-url/",o);if(t||(t={}),typeof t!="object"||t instanceof String)throw g("metro.client.fetch: Invalid options parameter "+L+"client/fetch-invalid-options/",t);let n=[async function(c){c[Symbol.metroProxy]&&(c=c[Symbol.metroSource]);let _=await fetch(c);return H(_)}].concat(this.clientOptions?.middlewares?.slice()||[]);t=Object.assign({},this.clientOptions,t);let i;for(let a of n)i=(function(c,_){return async function(y){let l,f=Object.values(e.tracers);for(let u of f)u.request&&u.request.call(u,y,_);l=await _(y,c);for(let u of f)u.response&&u.response.call(u,l,_);return l}})(i,a);return i(o)}with(...o){return new e(T(this.clientOptions),...o)}get location(){return this.clientOptions.url}};function E(...e){return new v(...T(e))}function Re(e,o){let t=o||{};!t.url&&o.url&&(t.url=o.url);for(let r of["method","headers","body","mode","credentials","cache","redirect","referrer","referrerPolicy","integrity","keepalive","signal","priority","url"]){let n=e[r];if(!(typeof n>"u"||n==null))if(n?.[Symbol.metroProxy]&&(n=n[Symbol.metroSource]),typeof n=="function")t[r]=n(t[r],t);else if(r=="url")t.url=b(t.url,n);else if(r=="headers"){t.headers=new Headers(o.headers),n instanceof Headers||(n=new Headers(e.headers));for(let[i,a]of n.entries())t.headers.set(i,a)}else t[r]=n}return e instanceof Request&&e.data&&(t.body=e.data),t}function C(...e){let o={url:b(typeof window<"u"?window.location:"https://localhost/"),duplex:"half"};for(let n of e)typeof n=="string"||n instanceof URL||n instanceof URLSearchParams?o.url=b(o.url,n):n&&(n instanceof FormData||n instanceof ReadableStream||n instanceof Blob||n instanceof ArrayBuffer||n instanceof DataView)?o.body=n:n&&typeof n=="object"&&Object.assign(o,Re(n,o));let t=new Request(o.url,o),r=o.body;return r&&typeof r=="object"&&!(r instanceof String)&&!(r instanceof ReadableStream)&&!(r instanceof Blob)&&!(r instanceof ArrayBuffer)&&!(r instanceof DataView)&&!(r instanceof FormData)&&!(r instanceof URLSearchParams)&&(typeof globalThis.TypedArray>"u"||!(r instanceof globalThis.TypedArray))&&typeof r.toString=="function"&&(o.body=r.toString({headers:t.headers}),t=new Request(o.url,o)),Object.freeze(t),new Proxy(t,{get(n,i){let a;switch(i){case Symbol.metroSource:a=n;break;case Symbol.metroProxy:a=!0;break;case"with":a=function(...c){return r&&c.unshift({body:r}),C(n,...c)};break;case"data":a=r;break;default:n[i]instanceof Function?a=n[i].bind(n):a=n[i];break}return a}})}function ce(e,o){let t=o||{};!t.url&&o.url&&(t.url=o.url);for(let r of["status","statusText","headers","body","url","type","redirected"]){let n=e[r];typeof n>"u"||n==null||(n?.[Symbol.metroProxy]&&(n=n[Symbol.metroSource]),typeof n=="function"?t[r]=n(t[r],t):r=="url"?t.url=new URL(n,t.url||"https://localhost/"):t[r]=n)}return e instanceof Response&&e.data&&(t.body=e.data),t}function H(...e){let o={};for(let n of e)typeof n=="string"?o.body=n:n instanceof Response?Object.assign(o,ce(n,o)):n&&typeof n=="object"&&(n instanceof FormData||n instanceof Blob||n instanceof ArrayBuffer||n instanceof DataView||n instanceof ReadableStream||n instanceof URLSearchParams||n instanceof String||typeof globalThis.TypedArray<"u"&&n instanceof globalThis.TypedArray?o.body=n:Object.assign(o,ce(n,o)));let t;o.body&&(t=o.body),[101,204,205,304].includes(o.status)&&(o.body=null);let r=new Response(o.body,o);return Object.freeze(r),new Proxy(r,{get(n,i){let a;switch(i){case Symbol.metroProxy:a=!0;break;case Symbol.metroSource:a=n;break;case"with":a=function(...c){return H(n,...c)};break;case"data":a=t;break;case"ok":a=n.status>=200&&n.status<400;break;default:typeof n[i]=="function"?a=n[i].bind(n):a=n[i];break}return a}})}function le(e,o){typeof o=="function"?o(e.searchParams,e):(o=new URLSearchParams(o),o.forEach((t,r)=>{e.searchParams.append(r,t)}))}function b(...e){let o=["hash","host","hostname","href","password","pathname","port","protocol","username","search","searchParams"],t=new URL("https://localhost/");for(let r of e)if(typeof r=="string"||r instanceof String)t=new URL(r,t);else if(r instanceof URL||typeof Location<"u"&&r instanceof Location)t=new URL(r);else if(r instanceof URLSearchParams)le(t,r);else if(r&&typeof r=="object")for(let n in r)switch(n){case"search":typeof r.search=="function"?r.search(t.search,t):t.search=new URLSearchParams(r.search);break;case"searchParams":le(t,r.searchParams);break;default:if(!o.includes(n))throw g("metro.url: unknown url parameter "+L+"url/unknown-param-name/",n);if(typeof r[n]=="function")r[n](t[n],t);else if(typeof r[n]=="string"||r[n]instanceof String||typeof r[n]=="number"||r[n]instanceof Number||typeof r[n]=="boolean"||r[n]instanceof Boolean)t[n]=""+r[n];else if(typeof r[n]=="object"&&r[n].toString)t[n]=r[n].toString();else throw g("metro.url: unsupported value for "+n+" "+L+"url/unsupported-param-value/",e[n]);break}else throw g("metro.url: unsupported option value "+L+"url/unsupported-option-value/",r);return Object.freeze(t),new Proxy(t,{get(r,n){let i;switch(n){case Symbol.metroProxy:i=!0;break;case Symbol.metroSource:i=r;break;case"with":i=function(...a){return b(r,...a)};break;case"filename":i=r.pathname.split("/").pop();break;case"folderpath":i=r.pathname.substring(0,r.pathname.lastIndexOf("\\")+1);break;case"authority":i=r.username??"",i+=r.password?":"+r.password:"",i+=i?"@":"",i+=r.hostname,i+=r.port?":"+r.port:"",i+="/",i=r.protocol+"//"+i;break;case"origin":i=r.protocol+"//"+r.hostname,i+=r.port?":"+r.port:"",i+="/";break;case"fragment":i=r.hash.substring(1);break;case"scheme":r.protocol?i=r.protocol.substring(0,r.protocol.length-1):i="";break;default:r[n]instanceof Function?i=r[n].bind(r):i=r[n];break}return i}})}function ue(...e){var o=new FormData;for(let t of e)if(t instanceof HTMLFormElement&&(t=new FormData(t)),t instanceof FormData)for(let r of t.entries())o.append(r[0],r[1]);else if(t&&typeof t=="object")for(let r of Object.entries(t))if(Array.isArray(r[1]))for(let n of r[1])o.append(r[0],n);else o.append(r[0],r[1]);else throw new g("metro.formdata: unknown option type "+L+"formdata/unknown-option-value/",t);return Object.freeze(o),new Proxy(o,{get(t,r){let n;switch(r){case Symbol.metroProxy:n=!0;break;case Symbol.metroSource:n=t;break;case"with":n=function(...i){return ue(t,...i)};break;default:t[r]instanceof Function?n=t[r].bind(t):n=t[r];break}return n}})}var J={error:(e,...o)=>{console.error("\u24C2\uFE0F ",e,...o)},info:(e,...o)=>{console.info("\u24C2\uFE0F ",e,...o)},group:e=>{console.group("\u24C2\uFE0F "+e)},groupEnd:e=>{console.groupEnd("\u24C2\uFE0F "+e)}};function g(e,...o){return J.error(e,...o),new Error(e,...o)}var je={add(e,o){v.tracers[e]=o},delete(e){delete v.tracers[e]},clear(){v.tracers={}},group(){let e=0;return{request:(o,t)=>{e++,J.group(e),J.info(o?.url,o,t)},response:(o,t)=>{J.info(o?.body?o.body[Symbol.metroSource]:null,o,t),J.groupEnd(e),e--}}}};function T(e){if(Array.isArray(e))return e.slice().map(T);if(e&&typeof e=="object")if(e.__proto__.constructor==Object||!e.__proto__){let o=Object.assign({},e);return Object.keys(o).forEach(t=>{o[t]=T(e[t])}),o}else return e;return e}function P(e){return e=Object.assign({contentType:"application/json",reviver:null,replacer:null,space:""},e),async function(t,r){if(t.headers.get("Accept")||(t=t.with({headers:{Accept:e.accept??e.contentType}})),t.method!=="GET"&&t.method!=="HEAD"&&t.data&&typeof t.data=="object"&&!(t.data instanceof ReadableStream)){let i=t.headers.get("Content-Type");(!i||Ee(i))&&(t=t.with({headers:{"Content-Type":e.contentType}})),fe(t.headers.get("Content-Type"))&&(t=t.with({body:JSON.stringify(t.data,e.replacer,e.space)}))}let n=await r(t);if(n&&fe(n.headers?.get("Content-Type"))){let a=await n.clone().text();try{let c=JSON.parse(a,e.reviver);return n.with({body:c})}catch{}}return n}}var Te=/^application\/([a-zA-Z0-9\-_]+\+)?json\b/;function fe(e){return Te.exec(e)}function Ee(e){return/^text\/plain\b/.exec(e)}function R(e){return async function(t,r){let n=await r(t);if(!n.ok)if(e&&typeof e[n.status]=="function")n=e[n.status].apply(n,t);else throw new Error(n.status+": "+n.statusText,{cause:n});return n}}function M(){return async function(o,t){let r=await t(o);return r.ok&&r.data?r.data:r}}var V=class extends v{constructor(o,t,r=null){o instanceof v?super(o.clientOptions,R(),M()):super(o,R(),M()),r||(r=this);for(let n in t)typeof t[n]=="function"?this[n]=t[n].bind(r):t[n]&&typeof t[n]=="object"?this[n]=new this.constructor(o,t[n],r):this[n]=t[n]}},Y=class extends V{constructor(o,t,r=null){o instanceof v?super(o.with(P()),t,r):super(E(o,P()),t,r)}};function de(...e){return new V(...T(e))}function pe(...e){return new Y(...T(e))}var he=Object.assign({},I,{mw:{json:P,thrower:R,getdata:M},api:de,jsonApi:pe});globalThis.metro||(globalThis.metro=he);var j=he;globalThis.assertEnabled=!1;function ze(){globalThis.assertEnabled=!0}function Ue(){globalThis.assertEnabled=!1}function w(e,o){if(globalThis.assertEnabled){let t=S(e,o);if(t)throw console.error("\u{1F170}\uFE0F Assertions failed because of:",t,"in this source:",e),new Error("Assertions failed",{cause:{problems:t,source:e}})}}function s(e){return function(t,r,n){if(typeof t<"u"&&t!=null&&typeof e<"u")return S(t,e,r,n)}}function p(e){return function(t,r,n){return t==null||typeof t>"u"?m("data is required",t,e||"any value",n):typeof e<"u"?S(t,e,r,n):!1}}function N(e){return function(t,r,n){return t==null||typeof t>"u"?(me("data does not contain recommended value",t,e,n),!1):S(t,e,r,n)}}function k(...e){return function(t,r,n){for(let i of e)if(!S(t,i,r,n))return!1;return m("data does not match oneOf patterns",t,e,n)}}function D(...e){return function(t,r,n){if(!Array.isArray(t))return m("data is not an array",t,"anyOf",n);for(let i of t)if(k(...e)(i))return m("data does not match anyOf patterns",i,e,n);return!1}}function q(...e){return function(t,r,n){let i=[];for(let a of e)i=i.concat(S(t,a,r,n));if(i=i.filter(Boolean),i.length)return m("data does not match all given patterns",t,e,n,i)}}function d(e,o,t){try{e instanceof URL&&(e=e.href);let r=new URL(e);if(r.href!=e&&!(r.href+"/"==e||r.href==e+"/"))return m("data is not a valid url",e,"validURL",t)}catch{return m("data is not a valid url",e,"validURL",t)}}function ee(e,o,t){if(!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(e))return m("data is not a valid email",e,"validEmail",t)}function K(e){return function(t,r,n){if(!(t instanceof e))return m("data is not an instanceof pattern",t,e,n)}}function B(e){return function(t,r,n){if(!S(t,e,r,n))return m("data matches pattern, when required not to",t,e,n)}}function S(e,o,t,r=""){t||(t=e);let n=[];if(o===Boolean)typeof e!="boolean"&&!(e instanceof Boolean)&&n.push(m("data is not a boolean",e,o,r));else if(o===Number)typeof e!="number"&&!(e instanceof Number)&&n.push(m("data is not a number",e,o,r));else if(o===String)typeof e!="string"&&!(e instanceof String)&&n.push(m("data is not a string",e,o,r)),e==""&&n.push(m("data is an empty string, which is not allowed",e,o,r));else if(o instanceof RegExp)if(Array.isArray(e)){let i=e.findIndex((a,c)=>S(a,o,t,r+"["+c+"]"));i>-1&&n.push(m("data["+i+"] does not match pattern",e[i],o,r+"["+i+"]"))}else typeof e>"u"?n.push(m("data is undefined, should match pattern",e,o,r)):o.test(e)||n.push(m("data does not match pattern",e,o,r));else if(o instanceof Function){let i=o(e,t,r);i&&(Array.isArray(i)?n=n.concat(i):n.push(i))}else if(Array.isArray(o)){Array.isArray(e)||n.push(m("data is not an array",e,[],r));for(let i of o)for(let a of e.keys()){let c=S(e[a],i,t,r+"["+a+"]");Array.isArray(c)?n=n.concat(c):c&&n.push(c)}}else if(o&&typeof o=="object")if(Array.isArray(e)){let i=e.findIndex((a,c)=>S(a,o,t,r+"["+c+"]"));i>-1&&n.push(m("data["+i+"] does not match pattern",e[i],o,r+"["+i+"]"))}else if(!e||typeof e!="object")n.push(m("data is not an object, pattern is",e,o,r));else if(e instanceof URLSearchParams&&(e=Object.fromEntries(e)),o instanceof Function){let i=S(e,o,t,r);i&&(n=n.concat(i))}else for(let[i,a]of Object.entries(o)){let c=S(e[i],a,t,r+"."+i);c&&(n=n.concat(c))}else o!=e&&n.push(m("data and pattern are not equal",e,o,r));return n.length?n:!1}function m(e,o,t,r,n){let i={path:r,message:e,found:o,expected:t};return n&&(i.problems=n),i}function me(e,o,t,r){console.warn("\u{1F170}\uFE0F Assert: "+r,e,t,o)}globalThis.assert={warn:me,error:m,assert:w,enable:ze,disable:Ue,Required:p,Recommended:N,Optional:s,oneOf:k,anyOf:D,allOf:q,validURL:d,validEmail:ee,instanceOf:K,not:B,fails:S};function _e(e){let o,t;if(typeof localStorage<"u")o={get:()=>localStorage.getItem("metro/state:"+e),set:r=>localStorage.setItem("metro/state:"+e,r),has:()=>localStorage.getItem("metro/state:"+e)!==null,delete:()=>localStorage.remoteItem("metro/state:"+e)},t={get:r=>JSON.parse(localStorage.getItem(e+":"+r)),set:(r,n)=>localStorage.setItem(e+":"+r,JSON.stringify(n)),has:r=>localStorage.getItem(e+":"+r)!==null,delete:r=>localStorage.removeItem(e+":"+r)};else{let r=new Map;o={get:()=>r.get("metro/state:"+e),set:n=>r.set("metro/state:"+e,n),has:()=>r.has("metro/state:"+e),delete:()=>r.delete("metro/state:"+e)},t=new Map}return{state:o,tokens:t}}function te(e){let o={client:E(),force_authorization:!1,site:"default",oauth2_configuration:{authorization_endpoint:"/authorize",token_endpoint:"/token",redirect_uri:globalThis.document?.location.href,grant_type:"authorization_code",code_verifier:Ce(64)},authorize_callback:async l=>(window.location.href!=l.href&&window.location.replace(l.href),!1)};w(e,{});let t=Object.assign({},o.oauth2_configuration,e?.oauth2_configuration);e=Object.assign({},o,e),e.oauth2_configuration=t;let r=_e(e.site);e.tokens||(e.tokens=r.tokens),e.state||(e.state=r.state),w(e,{oauth2_configuration:{client_id:p(/.+/),grant_type:"authorization_code",authorization_endpoint:p(d),token_endpoint:p(d),redirect_uri:p(d)}});for(let l in t)switch(l){case"access_token":case"authorization_code":case"refresh_token":e.tokens.set(l,t[l]);break}return async function(l,f){if(e.force_authorization)return n(l,f);let u;try{if(u=await f(l),u.ok)return u}catch(h){switch(u?.status){case 400:case 401:return n(l,f)}throw h}if(!u.ok)switch(u.status){case 400:case 401:return n(l,f)}return u};async function n(l,f){i();let u=e.tokens.get("access_token"),h=e.tokens.get("refresh_token"),x=Le(u);if(!u||x&&!h){try{if(!await a())return H("false")}catch(A){throw A}return n(l,f)}else if(x&&h){try{if(!await c())return H("false")}catch(A){throw A}return n(l,f)}else return l=C(l,{headers:{Authorization:u.type+" "+u.value}}),f(l)}function i(){if(typeof window<"u"&&window?.location){let l=b(window.location),f,u,h;if(l.searchParams.has("code"))h=l.searchParams,l=l.with({search:""}),history.pushState({},"",l.href);else if(l.hash){let x=l.hash.substr(1);h=new URLSearchParams("?"+x),l=l.with({hash:""}),history.pushState({},"",l.href)}if(h){f=h.get("code"),u=h.get("state");let x=e.state.get("metro/state");if(!u||u!==x)return;f&&e.tokens.set("authorization_code",f)}}}async function a(){if(t.grant_type==="authorization_code"&&!e.tokens.has("authorization_code")){let h=await _();if(!e.authorize_callback||typeof e.authorize_callback!="function")throw g("oauth2mw: oauth2 with grant_type:authorization_code requires a callback function in client options.authorize_callback");let x=await e.authorize_callback(h);if(x)e.tokens.set("authorization_code",x);else return!1}let l=y(),f=await e.client.post(l);if(!f.ok){let h=await f.text();throw g("OAuth2mw: fetch access_token: "+f.status+": "+f.statusText+" ("+h+")",{cause:l})}let u=await f.json();if(e.tokens.set("access_token",{value:u.access_token,expires:ye(u.expires_in),type:u.token_type,scope:u.scope}),u.refresh_token){let h={value:u.refresh_token};e.tokens.set("refresh_token",h)}return e.tokens.delete("authorization_code"),u}async function c(){let l=y("refresh_token"),f=await e.client.post(l);if(!f.ok)throw g("OAuth2mw: refresh access_token: "+f.status+": "+f.statusText,{cause:l});let u=await f.json();if(e.tokens.set("access_token",{value:u.access_token,expires:ye(u.expires_in),type:u.token_type,scope:u.scope}),u.refresh_token){let h={value:u.refresh_token};e.tokens.set("refresh_token",h)}else return!1;return u}async function _(){if(!t.authorization_endpoint)throw g("oauth2mw: Missing options.oauth2_configuration.authorization_endpoint");let l=b(t.authorization_endpoint,{hash:""});w(t,{client_id:/.+/,redirect_uri:/.+/,scope:/.*/});let f={response_type:"code",client_id:t.client_id,redirect_uri:t.redirect_uri,state:t.state||Ke(40)};return t.response_type&&(f.response_type=t.response_type),t.response_mode&&(f.response_mode=t.response_mode),e.state.set(f.state),t.client_secret&&(f.client_secret=t.client_secret),t.code_verifier&&(e.tokens.set("code_verifier",t.code_verifier),f.code_challenge=await De(t.code_verifier),f.code_challenge_method="S256"),t.scope&&(f.scope=t.scope),t.prompt&&(f.prompt=t.prompt),b(l,{search:f})}function y(l=null){if(w(t,{client_id:/.+/,redirect_uri:/.+/}),!t.token_endpoint)throw g("oauth2mw: Missing options.endpoints.token url");let f=b(t.token_endpoint,{hash:""}),u={grant_type:l||t.grant_type,client_id:t.client_id};switch(t.client_secret&&(u.client_secret=t.client_secret),t.scope&&(u.scope=t.scope),u.grant_type){case"authorization_code":u.redirect_uri=t.redirect_uri,u.code=e.tokens.get("authorization_code");let h=e.tokens.get("code_verifier");h&&(u.code_verifier=h);break;case"client_credentials":break;case"refresh_token":u.refresh_token=e.tokens.get("refresh_token");break;default:throw new Error("Unknown grant_type: ".oauth2.grant_type)}return C(f,{method:"POST",body:new URLSearchParams(u)})}}function Le(e){if(!e)return!0;let o=new Date(e.expires);return new Date().getTime()>o.getTime()}function ye(e){if(e instanceof Date)return new Date(e.getTime());if(typeof e=="number"){let o=new Date;return o.setSeconds(o.getSeconds()+e),o}throw new TypeError("Unknown expires type "+e)}function Ce(e=64){let o=new Uint8Array(e);return globalThis.crypto.getRandomValues(o),ge(o)}async function De(e){let t=new TextEncoder().encode(e),r=await globalThis.crypto.subtle.digest("SHA-256",t);return ge(r)}function ge(e){let o=Array.from(new Uint8Array(e),t=>String.fromCharCode(t)).join("");return btoa(o).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}function Ke(e){let o="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",t="",r=0;for(;r<e;)t+=o.charAt(Math.floor(Math.random()*o.length)),r++;return t}function we(){let e=new URL(document.location.href);if(!e.searchParams.has("code")){if(e.hash){let o=e.hash.substr(1);if(new URLSearchParams("?"+o).has("code"))return!0}return!1}return!0}function re(){return new Promise((e,o)=>{let t=globalThis.indexedDB.open("metro",1);t.onupgradeneeded=()=>t.result.createObjectStore("keyPairs",{keyPath:"domain"}),t.onerror=r=>{o(r)},t.onsuccess=r=>{let n=r.target.result;e({set:function(i,a){return new Promise((c,_)=>{let y=n.transaction("keyPairs","readwrite",{durability:"strict"}),l=y.objectStore("keyPairs");y.oncomplete=()=>{c()},y.onerror=_,l.put(i,a)})},get:function(i){return new Promise((a,c)=>{let _=n.transaction("keyPairs","readonly"),l=_.objectStore("keyPairs").get(i);l.onsuccess=()=>{a(l.result)},l.onerror=c,_.onerror=c})},clear:function(){return new Promise((i,a)=>{let c=n.transaction("keyPairs","readwrite"),y=c.objectStore("keyPairs").clear();y.onsuccess=()=>{i()},y.onerror=a,c.onerror=a})}})}})}var Ie=new TextEncoder,Me=new TextDecoder;function Z(e){return typeof e=="string"?Ie.encode(e):Me.decode(e)}function be(e){if(typeof e.modulusLength!="number"||e.modulusLength<2048)throw new oe(`${e.name} modulusLength must be at least 2048 bits`)}function Ne(e){switch(e.algorithm.name){case"ECDSA":return{name:e.algorithm.name,hash:"SHA-256"};case"RSA-PSS":return be(e.algorithm),{name:e.algorithm.name,saltLength:32};case"RSASSA-PKCS1-v1_5":return be(e.algorithm),{name:e.algorithm.name};case"Ed25519":return{name:e.algorithm.name}}throw new z}async function Be(e,o,t){if(t.usages.includes("sign")===!1)throw new TypeError('private CryptoKey instances used for signing assertions must include "sign" in their "usages"');let r=`${G(Z(JSON.stringify(e)))}.${G(Z(JSON.stringify(o)))}`,n=G(await crypto.subtle.sign(Ne(t),t,Z(r)));return`${r}.${n}`}var ne;Uint8Array.prototype.toBase64?ne=e=>(e instanceof ArrayBuffer&&(e=new Uint8Array(e)),e.toBase64({alphabet:"base64url",omitPadding:!0})):ne=o=>{o instanceof ArrayBuffer&&(o=new Uint8Array(o));let t=[];for(let r=0;r<o.byteLength;r+=32768)t.push(String.fromCharCode.apply(null,o.subarray(r,r+32768)));return btoa(t.join("")).replace(/=/g,"").replace(/\+/g,"-").replace(/\//g,"_")};function G(e){return ne(e)}var z=class extends Error{constructor(o){var t;super(o??"operation not supported"),this.name=this.constructor.name,(t=Error.captureStackTrace)===null||t===void 0||t.call(Error,this,this.constructor)}},oe=class extends Error{constructor(o){var t;super(o),this.name=this.constructor.name,(t=Error.captureStackTrace)===null||t===void 0||t.call(Error,this,this.constructor)}};function Je(e){if(e.algorithm.hash.name==="SHA-256")return"PS256";throw new z("unsupported RsaHashedKeyAlgorithm hash name")}function Fe(e){if(e.algorithm.hash.name==="SHA-256")return"RS256";throw new z("unsupported RsaHashedKeyAlgorithm hash name")}function We(e){if(e.algorithm.namedCurve==="P-256")return"ES256";throw new z("unsupported EcKeyAlgorithm namedCurve")}function $e(e){switch(e.algorithm.name){case"RSA-PSS":return Je(e);case"RSASSA-PKCS1-v1_5":return Fe(e);case"ECDSA":return We(e);case"Ed25519":return"Ed25519";default:throw new z("unsupported CryptoKey algorithm name")}}function ke(e){return e instanceof CryptoKey}function Ve(e){return ke(e)&&e.type==="private"}function Ze(e){return ke(e)&&e.type==="public"}function Ge(){return Math.floor(Date.now()/1e3)}async function ie(e,o,t,r,n,i){let a=e?.privateKey,c=e?.publicKey;if(!Ve(a))throw new TypeError('"keypair.privateKey" must be a private CryptoKey');if(!Ze(c))throw new TypeError('"keypair.publicKey" must be a public CryptoKey');if(c.extractable!==!0)throw new TypeError('"keypair.publicKey.extractable" must be true');if(typeof o!="string")throw new TypeError('"htu" must be a string');if(typeof t!="string")throw new TypeError('"htm" must be a string');if(r!==void 0&&typeof r!="string")throw new TypeError('"nonce" must be a string or undefined');if(n!==void 0&&typeof n!="string")throw new TypeError('"accessToken" must be a string or undefined');if(i!==void 0&&(typeof i!="object"||i===null||Array.isArray(i)))throw new TypeError('"additional" must be an object');return Be({alg:$e(a),typ:"dpop+jwt",jwk:await Qe(c)},Object.assign(Object.assign({},i),{iat:Ge(),jti:crypto.randomUUID(),htm:t,nonce:r,htu:o,ath:n?G(await crypto.subtle.digest("SHA-256",Z(n))):void 0}),a)}async function Qe(e){let{kty:o,e:t,n:r,x:n,y:i,crv:a}=await crypto.subtle.exportKey("jwk",e);return{kty:o,crv:a,e:t,n:r,x:n,y:i}}async function Se(e,o){var t;let r;if(typeof e!="string"||e.length===0)throw new TypeError('"alg" must be a non-empty string');switch(e){case"PS256":r={name:"RSA-PSS",hash:"SHA-256",modulusLength:2048,publicExponent:new Uint8Array([1,0,1])};break;case"RS256":r={name:"RSASSA-PKCS1-v1_5",hash:"SHA-256",modulusLength:2048,publicExponent:new Uint8Array([1,0,1])};break;case"ES256":r={name:"ECDSA",namedCurve:"P-256"};break;case"Ed25519":r={name:"Ed25519"};break;default:throw new z}return crypto.subtle.generateKey(r,(t=o?.extractable)!==null&&t!==void 0?t:!1,["sign","verify"])}function se(e){return w(e,{site:p(d),authorization_endpoint:p(d),token_endpoint:p(d),dpop_signing_alg_values_supported:s([])}),async(o,t)=>{let r=await re(),n=await r.get(e.site);if(!n){let c=await Se("ES256");n={domain:e.site,keyPair:c},await r.set(n)}let i=j.url(o.url);if(o.url.startsWith(e.authorization_endpoint)){let c=o.body;c instanceof URLSearchParams||c instanceof FormData?c.set("dpop_jkt",n.keyPair.publicKey):c.dpop_jkt=n.keyPair.publicKey}else if(o.url.startsWith(e.token_endpoint)){let c=await ie(n.keyPair,o.url,o.method);o=o.with({headers:{DPoP:c}})}else if(o.headers.has("Authorization")){let c=localStorage.getItem(i.host+":nonce")||void 0,_=o.headers.get("Authorization").split(" ")[1],y=await ie(n.keyPair,o.url,o.method,c,_);o=o.with({headers:{Authorization:"DPoP "+_,DPoP:y}})}let a=await t(o);return a.headers.get("DPoP-Nonce")&&localStorage.setItem(i.host+":nonce",a.headers.get("DPoP-Nonce")),a}}var F=(...e)=>(o,t)=>e.filter(r=>t.hasOwnKey(r)).length>0?!1:m("root data must have all of",t,e),U=(...e)=>o=>Array.isArray(o)&&e.filter(t=>!o.includes(t)).length==0?!1:m("data must be an array which includes",o,e);var O=["HS256","HS384","HS512","RS256","RS384","RS512","ES256","ES384","ES512"],Q=["client_secret_post","client_secret_basic","client_secret_jwt","private_key_jwt"];async function W(e={}){w(e,{client:s(K(j.client().constructor)),issuer:p(d)});let o={client:j.client().with(R()).with(P()),requireDynamicRegistration:!1};e=Object.assign({},o,e);let t=!1;function r(_){return t}let n={issuer:p(q(e.issuer,r)),authorization_endpoint:p(d),token_endpoint:p(d),userinfo_endpoint:N(d),jwks_uri:p(d),registration_endpoint:e.requireDynamicRegistration?p(d):N(d),scopes_supported:N(U("openid")),response_types_supported:e.requireDynamicRegistration?p(U("code","id_token","id_token token")):p([]),response_modes_supported:s([]),grant_types_supported:e.requireDynamicRegistration?s(U("authorization_code")):s([]),acr_values_supported:s([]),subject_types_supported:p([]),id_token_signing_alg_values_supported:p(U("RS256")),id_token_encryption_alg_values_supported:s([]),id_token_encryption_enc_values_supported:s([]),userinfo_signing_alg_values_supported:s([]),userinfo_encryption_alg_values_supported:s([]),userinfo_encryption_enc_values_supported:s([]),request_object_signing_alg_values_supported:s(U("RS256")),request_object_encryption_alg_values_supported:s([]),request_object_encryption_enc_values_supported:s([]),token_endpoint_auth_methods_supported:s(D(...Q)),token_endpoint_auth_signing_alg_values_supported:s(U("RS256"),B(U("none"))),display_values_supported:s(D("page","popup","touch","wap")),claim_types_supported:s(D("normal","aggregated","distributed")),claims_supported:N([]),service_documentation:s(d),claims_locales_supported:s([]),ui_locales_supported:s([]),claims_parameter_supported:s(Boolean),request_parameter_supported:s(Boolean),request_uri_parameter_supported:s(Boolean),op_policy_uri:s(d),op_tos_uri:s(d)},i=j.url(e.issuer,".well-known/openid-configuration"),c=(await e.client.get(i)).data;return w(c,n),w(c.issuer,e.issuer),c}async function $(e){let o={redirect_uris:p([d]),response_types:s([]),grant_types:s(D("authorization_code","refresh_token")),application_type:s(k("native","web")),contacts:s([ee]),client_name:s(String),logo_uri:s(d),client_uri:s(d),policy_uri:s(d),tos_uri:s(d),jwks_uri:s(d,B(F("jwks"))),jwks:s(d,B(F("jwks_uri"))),sector_identifier_uri:s(d),subject_type:s(String),id_token_signed_response_alg:s(k(...O)),id_token_encrypted_response_alg:s(k(...O)),id_token_encrypted_response_enc:s(k(...O),F("id_token_encrypted_response_alg")),userinfo_signed_response_alg:s(k(...O)),userinfo_encrypted_response_alg:s(k(...O)),userinfo_encrypted_response_enc:s(k(...O),F("userinfo_encrypted_response_alg")),request_object_signing_alg:s(k(...O)),request_object_encryption_alg:s(k(...O)),request_object_encryption_enc:s(k(...O)),token_endpoint_auth_method:s(k(...Q)),token_endpoint_auth_signing_alg:s(k(...O)),default_max_age:s(Number),require_auth_time:s(Boolean),default_acr_values:s([String]),initiate_login_uri:s([d]),request_uris:s([d])};w(e,{client:s(K(j.client().constructor)),registration_endpoint:d,client_info:o});let t={client:j.client().with(R()).with(P()),client_info:{redirect_uris:[globalThis.document?.location.href]}};e=Object.assign({},t,e),e.client_info||(e.client_info={}),e.client_info.redirect_uris||(e.client_info.redirect_uris=[globalThis.document?.location.href]);let r=await e.client.post(e.registration_endpoint,{body:e.client_info}),n=r.data;if(!n.client_id||!n.client_secret)throw j.metroError("metro.oidc: Error: dynamic registration of client failed, no client_id or client_secret returned",r);return e.client_info=Object.assign(e.client_info,n),e.client_info}function X(e){let o;if(typeof localStorage<"u")o={get:t=>JSON.parse(localStorage.getItem("metro/oidc:"+e+":"+t)),set:(t,r)=>localStorage.setItem("metro/oidc:"+e+":"+t,JSON.stringify(r)),has:t=>localStorage.getItem("metro/oidc:"+e+":"+t)!==null};else{let t=new Map;o={get:r=>JSON.parse(t.get("metro/oidc:"+e+":"+r)||null),set:(r,n)=>t.set("metro/oidc:"+e+":"+r,JSON.stringify(n)),has:r=>t.has("metro/oidc:"+e+":"+r)}}return o}function ae(e={}){let o={client:E(),force_authorization:!1,use_dpop:!0,authorize_callback:async t=>(window.location.href!=t.href&&window.location.replace(t.href),!1)};return e=Object.assign({},o,e),w(e,{client:p(K(E().constructor)),client_info:p(),issuer:p(d),oauth2:s({}),openid_configuration:s()}),e.store||(e.store=X(e.issuer)),!e.openid_configuration&&e.store.has("openid_configuration")&&(e.openid_configuration=e.store.get("openid_configuration")),!e.client_info?.client_id&&e.store.has("client_info")&&(e.client_info=e.store.get("client_info")),async(t,r)=>{let n;if(!e.force_authorization){try{n=await r(t)}catch(y){if(n.status!=401&&n.status!=403)throw y}if(n.ok||n.status!=401&&n.status!=403)return n}if(e.openid_configuration||(e.openid_configuration=await W({issuer:e.issuer}),e.store.set("openid_configuration",e.openid_configuration)),!e.client_info?.client_id){if(!e.openid_configuration.registration_endpoint)throw g("metro.oidcmw: Error: issuer "+e.issuer+" does not support dynamic client registration, but you haven't specified a client_id");e.client_info=await $({registration_endpoint:e.openid_configuration.registration_endpoint,client_info:e.client_info}),e.store.set("client_info",e.client_info)}let i=e.scope||"openid",a=Object.assign({site:e.issuer,client:e.client,force_authorization:!0,authorize_callback:e.authorize_callback,oauth2_configuration:{client_id:e.client_info?.client_id,client_secret:e.client_info?.client_secret,grant_type:"authorization_code",response_type:"code",response_mode:"query",authorization_endpoint:e.openid_configuration.authorization_endpoint,token_endpoint:e.openid_configuration.token_endpoint,scope:i,redirect_uri:e.client_info.redirect_uris[0]}}),c=async(y,l)=>{let f=await l(y);if(f.headers.get("content-type")?.startsWith("application/json")){let h=f.data?.id_token;if(!h){let x=f.clone();try{let A=await x.json();A&&A.id_token&&(h=A.id_token)}catch{}}h&&e.store.set("id_token",h)}return f},_=e.client.with(e.issuer).with(c);if(e.use_dpop){let y={site:e.issuer,authorization_endpoint:e.openid_configuration.authorization_endpoint,token_endpoint:e.openid_configuration.token_endpoint,dpop_signing_alg_values_supported:e.openid_configuration.dpop_signing_alg_values_supported};_=_.with(se(y)),a.client=_}return _=_.with(te(a)),n=await _.fetch(t),n}}function xe(){return we()}function ve(e){if(!e.store){if(!e.issuer)throw g("Must supply options.issuer or options.store to get the id_token");e.store=X(e.issuer)}return e.store.get("id_token")}var Oe={oidcmw:ae,discover:W,register:$,isRedirected:xe,idToken:ve};globalThis.metro.oidc||(globalThis.metro.oidc=Oe);var Qt=Oe;})();
|
|
2
2
|
//# sourceMappingURL=browser.min.js.map
|