@wral/studio.mods.auth 1.0.0 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,6 +1,7 @@
1
1
  # Vellum Auth Mod
2
2
 
3
- This mod provides an Authentication mechanism via JWTs.
3
+ This mod provides an Authentication mechanism via JWTs. This mod is compatible
4
+ with Vellum 1.0.
4
5
 
5
6
  ## Usage
6
7
 
@@ -8,7 +9,7 @@ In a vellum project, add the following mod:
8
9
 
9
10
  ```html
10
11
  <vellum-app>
11
- <vellum-mod name="auth" src="https://cdn.wral.studio/mods/auth/release/v1.0.0/auth.es.js"
12
+ <vellum-mod name="auth" src="https://cdn.wral.studio/mods/auth/release/v2.0.0/auth.es.js"
12
13
  api="https://api.wral.com/auth"
13
14
  force-login>
14
15
  </vellum-mod>
@@ -18,7 +19,6 @@ In a vellum project, add the following mod:
18
19
  ### Attributes
19
20
  * `api`: _required_ auth api endpoint (without version or trailing slash)
20
21
  * `force-login`: _optional_ force login on first page load
21
- * session-key: _optional_ session key to use. Defaults to `token`
22
22
 
23
23
  ### Requesting an auth token
24
24
 
@@ -19,14 +19,14 @@ definitions:
19
19
  FAIL_ONLY: 'true'
20
20
  - step: &test
21
21
  name: Run tests
22
- image: node:18
22
+ # image: node:18
23
23
  caches:
24
24
  - npm
25
25
  - node
26
26
  script:
27
27
  - npm ci
28
- - npx playwright install-deps
29
- - npx playwright install chromium
28
+ # - npx playwright install-deps
29
+ # - npx playwright install chromium
30
30
  - npm run test
31
31
  artifacts:
32
32
  - coverage/**
package/dist/auth.cjs.js CHANGED
@@ -1,25 +1,48 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const X=require("./lib.cjs.js");function k(r,...e){return(...t)=>r(...e,...t)}/**
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const fe=require("./lib.cjs.js");/**
2
2
  * @license
3
3
  * Copyright 2019 Google LLC
4
4
  * SPDX-License-Identifier: BSD-3-Clause
5
- */const L=globalThis,K=L.ShadowRoot&&(L.ShadyCSS===void 0||L.ShadyCSS.nativeShadow)&&"adoptedStyleSheets"in Document.prototype&&"replace"in CSSStyleSheet.prototype,Q=Symbol(),ee=new WeakMap;let he=class{constructor(e,t,s){if(this._$cssResult$=!0,s!==Q)throw Error("CSSResult is not constructable. Use `unsafeCSS` or `css` instead.");this.cssText=e,this.t=t}get styleSheet(){let e=this.o;const t=this.t;if(K&&e===void 0){const s=t!==void 0&&t.length===1;s&&(e=ee.get(t)),e===void 0&&((this.o=e=new CSSStyleSheet).replaceSync(this.cssText),s&&ee.set(t,e))}return e}toString(){return this.cssText}};const Ce=r=>new he(typeof r=="string"?r:r+"",void 0,Q),q=(r,...e)=>{const t=r.length===1?r[0]:e.reduce((s,o,i)=>s+(n=>{if(n._$cssResult$===!0)return n.cssText;if(typeof n=="number")return n;throw Error("Value passed to 'css' function must be a 'css' function result: "+n+". Use 'unsafeCSS' to pass non-literal values, but take care to ensure page security.")})(o)+r[i+1],r[0]);return new he(t,r,Q)},xe=(r,e)=>{if(K)r.adoptedStyleSheets=e.map(t=>t instanceof CSSStyleSheet?t:t.styleSheet);else for(const t of e){const s=document.createElement("style"),o=L.litNonce;o!==void 0&&s.setAttribute("nonce",o),s.textContent=t.cssText,r.appendChild(s)}},te=K?r=>r:r=>r instanceof CSSStyleSheet?(e=>{let t="";for(const s of e.cssRules)t+=s.cssText;return Ce(t)})(r):r;/**
5
+ */const q=globalThis,G=q.ShadowRoot&&(q.ShadyCSS===void 0||q.ShadyCSS.nativeShadow)&&"adoptedStyleSheets"in Document.prototype&&"replace"in CSSStyleSheet.prototype,V=Symbol(),K=new WeakMap;let ae=class{constructor(e,t,s){if(this._$cssResult$=!0,s!==V)throw Error("CSSResult is not constructable. Use `unsafeCSS` or `css` instead.");this.cssText=e,this.t=t}get styleSheet(){let e=this.o;const t=this.t;if(G&&e===void 0){const s=t!==void 0&&t.length===1;s&&(e=K.get(t)),e===void 0&&((this.o=e=new CSSStyleSheet).replaceSync(this.cssText),s&&K.set(t,e))}return e}toString(){return this.cssText}};const ge=r=>new ae(typeof r=="string"?r:r+"",void 0,V),J=(r,...e)=>{const t=r.length===1?r[0]:e.reduce((s,o,i)=>s+(n=>{if(n._$cssResult$===!0)return n.cssText;if(typeof n=="number")return n;throw Error("Value passed to 'css' function must be a 'css' function result: "+n+". Use 'unsafeCSS' to pass non-literal values, but take care to ensure page security.")})(o)+r[i+1],r[0]);return new ae(t,r,V)},$e=(r,e)=>{if(G)r.adoptedStyleSheets=e.map(t=>t instanceof CSSStyleSheet?t:t.styleSheet);else for(const t of e){const s=document.createElement("style"),o=q.litNonce;o!==void 0&&s.setAttribute("nonce",o),s.textContent=t.cssText,r.appendChild(s)}},Y=G?r=>r:r=>r instanceof CSSStyleSheet?(e=>{let t="";for(const s of e.cssRules)t+=s.cssText;return ge(t)})(r):r;/**
6
6
  * @license
7
7
  * Copyright 2017 Google LLC
8
8
  * SPDX-License-Identifier: BSD-3-Clause
9
- */const{is:ke,defineProperty:Te,getOwnPropertyDescriptor:Ue,getOwnPropertyNames:Re,getOwnPropertySymbols:Oe,getPrototypeOf:Ne}=Object,$=globalThis,re=$.trustedTypes,He=re?re.emptyScript:"",j=$.reactiveElementPolyfillSupport,U=(r,e)=>r,V={toAttribute(r,e){switch(e){case Boolean:r=r?He:null;break;case Object:case Array:r=r==null?r:JSON.stringify(r)}return r},fromAttribute(r,e){let t=r;switch(e){case Boolean:t=r!==null;break;case Number:t=r===null?null:Number(r);break;case Object:case Array:try{t=JSON.parse(r)}catch{t=null}}return t}},ue=(r,e)=>!ke(r,e),se={attribute:!0,type:String,converter:V,reflect:!1,hasChanged:ue};Symbol.metadata??(Symbol.metadata=Symbol("metadata")),$.litPropertyMetadata??($.litPropertyMetadata=new WeakMap);class E extends HTMLElement{static addInitializer(e){this._$Ei(),(this.l??(this.l=[])).push(e)}static get observedAttributes(){return this.finalize(),this._$Eh&&[...this._$Eh.keys()]}static createProperty(e,t=se){if(t.state&&(t.attribute=!1),this._$Ei(),this.elementProperties.set(e,t),!t.noAccessor){const s=Symbol(),o=this.getPropertyDescriptor(e,s,t);o!==void 0&&Te(this.prototype,e,o)}}static getPropertyDescriptor(e,t,s){const{get:o,set:i}=Ue(this.prototype,e)??{get(){return this[t]},set(n){this[t]=n}};return{get(){return o==null?void 0:o.call(this)},set(n){const l=o==null?void 0:o.call(this);i.call(this,n),this.requestUpdate(e,l,s)},configurable:!0,enumerable:!0}}static getPropertyOptions(e){return this.elementProperties.get(e)??se}static _$Ei(){if(this.hasOwnProperty(U("elementProperties")))return;const e=Ne(this);e.finalize(),e.l!==void 0&&(this.l=[...e.l]),this.elementProperties=new Map(e.elementProperties)}static finalize(){if(this.hasOwnProperty(U("finalized")))return;if(this.finalized=!0,this._$Ei(),this.hasOwnProperty(U("properties"))){const t=this.properties,s=[...Re(t),...Oe(t)];for(const o of s)this.createProperty(o,t[o])}const e=this[Symbol.metadata];if(e!==null){const t=litPropertyMetadata.get(e);if(t!==void 0)for(const[s,o]of t)this.elementProperties.set(s,o)}this._$Eh=new Map;for(const[t,s]of this.elementProperties){const o=this._$Eu(t,s);o!==void 0&&this._$Eh.set(o,t)}this.elementStyles=this.finalizeStyles(this.styles)}static finalizeStyles(e){const t=[];if(Array.isArray(e)){const s=new Set(e.flat(1/0).reverse());for(const o of s)t.unshift(te(o))}else e!==void 0&&t.push(te(e));return t}static _$Eu(e,t){const s=t.attribute;return s===!1?void 0:typeof s=="string"?s:typeof e=="string"?e.toLowerCase():void 0}constructor(){super(),this._$Ep=void 0,this.isUpdatePending=!1,this.hasUpdated=!1,this._$Em=null,this._$Ev()}_$Ev(){var e;this._$ES=new Promise(t=>this.enableUpdating=t),this._$AL=new Map,this._$E_(),this.requestUpdate(),(e=this.constructor.l)==null||e.forEach(t=>t(this))}addController(e){var t;(this._$EO??(this._$EO=new Set)).add(e),this.renderRoot!==void 0&&this.isConnected&&((t=e.hostConnected)==null||t.call(e))}removeController(e){var t;(t=this._$EO)==null||t.delete(e)}_$E_(){const e=new Map,t=this.constructor.elementProperties;for(const s of t.keys())this.hasOwnProperty(s)&&(e.set(s,this[s]),delete this[s]);e.size>0&&(this._$Ep=e)}createRenderRoot(){const e=this.shadowRoot??this.attachShadow(this.constructor.shadowRootOptions);return xe(e,this.constructor.elementStyles),e}connectedCallback(){var e;this.renderRoot??(this.renderRoot=this.createRenderRoot()),this.enableUpdating(!0),(e=this._$EO)==null||e.forEach(t=>{var s;return(s=t.hostConnected)==null?void 0:s.call(t)})}enableUpdating(e){}disconnectedCallback(){var e;(e=this._$EO)==null||e.forEach(t=>{var s;return(s=t.hostDisconnected)==null?void 0:s.call(t)})}attributeChangedCallback(e,t,s){this._$AK(e,s)}_$EC(e,t){var i;const s=this.constructor.elementProperties.get(e),o=this.constructor._$Eu(e,s);if(o!==void 0&&s.reflect===!0){const n=(((i=s.converter)==null?void 0:i.toAttribute)!==void 0?s.converter:V).toAttribute(t,s.type);this._$Em=e,n==null?this.removeAttribute(o):this.setAttribute(o,n),this._$Em=null}}_$AK(e,t){var i;const s=this.constructor,o=s._$Eh.get(e);if(o!==void 0&&this._$Em!==o){const n=s.getPropertyOptions(o),l=typeof n.converter=="function"?{fromAttribute:n.converter}:((i=n.converter)==null?void 0:i.fromAttribute)!==void 0?n.converter:V;this._$Em=o,this[o]=l.fromAttribute(t,n.type),this._$Em=null}}requestUpdate(e,t,s){if(e!==void 0){if(s??(s=this.constructor.getPropertyOptions(e)),!(s.hasChanged??ue)(this[e],t))return;this.P(e,t,s)}this.isUpdatePending===!1&&(this._$ES=this._$ET())}P(e,t,s){this._$AL.has(e)||this._$AL.set(e,t),s.reflect===!0&&this._$Em!==e&&(this._$Ej??(this._$Ej=new Set)).add(e)}async _$ET(){this.isUpdatePending=!0;try{await this._$ES}catch(t){Promise.reject(t)}const e=this.scheduleUpdate();return e!=null&&await e,!this.isUpdatePending}scheduleUpdate(){return this.performUpdate()}performUpdate(){var s;if(!this.isUpdatePending)return;if(!this.hasUpdated){if(this.renderRoot??(this.renderRoot=this.createRenderRoot()),this._$Ep){for(const[i,n]of this._$Ep)this[i]=n;this._$Ep=void 0}const o=this.constructor.elementProperties;if(o.size>0)for(const[i,n]of o)n.wrapped!==!0||this._$AL.has(i)||this[i]===void 0||this.P(i,this[i],n)}let e=!1;const t=this._$AL;try{e=this.shouldUpdate(t),e?(this.willUpdate(t),(s=this._$EO)==null||s.forEach(o=>{var i;return(i=o.hostUpdate)==null?void 0:i.call(o)}),this.update(t)):this._$EU()}catch(o){throw e=!1,this._$EU(),o}e&&this._$AE(t)}willUpdate(e){}_$AE(e){var t;(t=this._$EO)==null||t.forEach(s=>{var o;return(o=s.hostUpdated)==null?void 0:o.call(s)}),this.hasUpdated||(this.hasUpdated=!0,this.firstUpdated(e)),this.updated(e)}_$EU(){this._$AL=new Map,this.isUpdatePending=!1}get updateComplete(){return this.getUpdateComplete()}getUpdateComplete(){return this._$ES}shouldUpdate(e){return!0}update(e){this._$Ej&&(this._$Ej=this._$Ej.forEach(t=>this._$EC(t,this[t]))),this._$EU()}updated(e){}firstUpdated(e){}}E.elementStyles=[],E.shadowRootOptions={mode:"open"},E[U("elementProperties")]=new Map,E[U("finalized")]=new Map,j==null||j({ReactiveElement:E}),($.reactiveElementVersions??($.reactiveElementVersions=[])).push("2.0.4");/**
9
+ */const{is:ye,defineProperty:be,getOwnPropertyDescriptor:_e,getOwnPropertyNames:ve,getOwnPropertySymbols:we,getPrototypeOf:Ae}=Object,$=globalThis,Z=$.trustedTypes,Ee=Z?Z.emptyScript:"",I=$.reactiveElementPolyfillSupport,U=(r,e)=>r,W={toAttribute(r,e){switch(e){case Boolean:r=r?Ee:null;break;case Object:case Array:r=r==null?r:JSON.stringify(r)}return r},fromAttribute(r,e){let t=r;switch(e){case Boolean:t=r!==null;break;case Number:t=r===null?null:Number(r);break;case Object:case Array:try{t=JSON.parse(r)}catch{t=null}}return t}},le=(r,e)=>!ye(r,e),X={attribute:!0,type:String,converter:W,reflect:!1,hasChanged:le};Symbol.metadata??(Symbol.metadata=Symbol("metadata")),$.litPropertyMetadata??($.litPropertyMetadata=new WeakMap);class S extends HTMLElement{static addInitializer(e){this._$Ei(),(this.l??(this.l=[])).push(e)}static get observedAttributes(){return this.finalize(),this._$Eh&&[...this._$Eh.keys()]}static createProperty(e,t=X){if(t.state&&(t.attribute=!1),this._$Ei(),this.elementProperties.set(e,t),!t.noAccessor){const s=Symbol(),o=this.getPropertyDescriptor(e,s,t);o!==void 0&&be(this.prototype,e,o)}}static getPropertyDescriptor(e,t,s){const{get:o,set:i}=_e(this.prototype,e)??{get(){return this[t]},set(n){this[t]=n}};return{get(){return o==null?void 0:o.call(this)},set(n){const l=o==null?void 0:o.call(this);i.call(this,n),this.requestUpdate(e,l,s)},configurable:!0,enumerable:!0}}static getPropertyOptions(e){return this.elementProperties.get(e)??X}static _$Ei(){if(this.hasOwnProperty(U("elementProperties")))return;const e=Ae(this);e.finalize(),e.l!==void 0&&(this.l=[...e.l]),this.elementProperties=new Map(e.elementProperties)}static finalize(){if(this.hasOwnProperty(U("finalized")))return;if(this.finalized=!0,this._$Ei(),this.hasOwnProperty(U("properties"))){const t=this.properties,s=[...ve(t),...we(t)];for(const o of s)this.createProperty(o,t[o])}const e=this[Symbol.metadata];if(e!==null){const t=litPropertyMetadata.get(e);if(t!==void 0)for(const[s,o]of t)this.elementProperties.set(s,o)}this._$Eh=new Map;for(const[t,s]of this.elementProperties){const o=this._$Eu(t,s);o!==void 0&&this._$Eh.set(o,t)}this.elementStyles=this.finalizeStyles(this.styles)}static finalizeStyles(e){const t=[];if(Array.isArray(e)){const s=new Set(e.flat(1/0).reverse());for(const o of s)t.unshift(Y(o))}else e!==void 0&&t.push(Y(e));return t}static _$Eu(e,t){const s=t.attribute;return s===!1?void 0:typeof s=="string"?s:typeof e=="string"?e.toLowerCase():void 0}constructor(){super(),this._$Ep=void 0,this.isUpdatePending=!1,this.hasUpdated=!1,this._$Em=null,this._$Ev()}_$Ev(){var e;this._$ES=new Promise(t=>this.enableUpdating=t),this._$AL=new Map,this._$E_(),this.requestUpdate(),(e=this.constructor.l)==null||e.forEach(t=>t(this))}addController(e){var t;(this._$EO??(this._$EO=new Set)).add(e),this.renderRoot!==void 0&&this.isConnected&&((t=e.hostConnected)==null||t.call(e))}removeController(e){var t;(t=this._$EO)==null||t.delete(e)}_$E_(){const e=new Map,t=this.constructor.elementProperties;for(const s of t.keys())this.hasOwnProperty(s)&&(e.set(s,this[s]),delete this[s]);e.size>0&&(this._$Ep=e)}createRenderRoot(){const e=this.shadowRoot??this.attachShadow(this.constructor.shadowRootOptions);return $e(e,this.constructor.elementStyles),e}connectedCallback(){var e;this.renderRoot??(this.renderRoot=this.createRenderRoot()),this.enableUpdating(!0),(e=this._$EO)==null||e.forEach(t=>{var s;return(s=t.hostConnected)==null?void 0:s.call(t)})}enableUpdating(e){}disconnectedCallback(){var e;(e=this._$EO)==null||e.forEach(t=>{var s;return(s=t.hostDisconnected)==null?void 0:s.call(t)})}attributeChangedCallback(e,t,s){this._$AK(e,s)}_$EC(e,t){var i;const s=this.constructor.elementProperties.get(e),o=this.constructor._$Eu(e,s);if(o!==void 0&&s.reflect===!0){const n=(((i=s.converter)==null?void 0:i.toAttribute)!==void 0?s.converter:W).toAttribute(t,s.type);this._$Em=e,n==null?this.removeAttribute(o):this.setAttribute(o,n),this._$Em=null}}_$AK(e,t){var i;const s=this.constructor,o=s._$Eh.get(e);if(o!==void 0&&this._$Em!==o){const n=s.getPropertyOptions(o),l=typeof n.converter=="function"?{fromAttribute:n.converter}:((i=n.converter)==null?void 0:i.fromAttribute)!==void 0?n.converter:W;this._$Em=o,this[o]=l.fromAttribute(t,n.type),this._$Em=null}}requestUpdate(e,t,s){if(e!==void 0){if(s??(s=this.constructor.getPropertyOptions(e)),!(s.hasChanged??le)(this[e],t))return;this.P(e,t,s)}this.isUpdatePending===!1&&(this._$ES=this._$ET())}P(e,t,s){this._$AL.has(e)||this._$AL.set(e,t),s.reflect===!0&&this._$Em!==e&&(this._$Ej??(this._$Ej=new Set)).add(e)}async _$ET(){this.isUpdatePending=!0;try{await this._$ES}catch(t){Promise.reject(t)}const e=this.scheduleUpdate();return e!=null&&await e,!this.isUpdatePending}scheduleUpdate(){return this.performUpdate()}performUpdate(){var s;if(!this.isUpdatePending)return;if(!this.hasUpdated){if(this.renderRoot??(this.renderRoot=this.createRenderRoot()),this._$Ep){for(const[i,n]of this._$Ep)this[i]=n;this._$Ep=void 0}const o=this.constructor.elementProperties;if(o.size>0)for(const[i,n]of o)n.wrapped!==!0||this._$AL.has(i)||this[i]===void 0||this.P(i,this[i],n)}let e=!1;const t=this._$AL;try{e=this.shouldUpdate(t),e?(this.willUpdate(t),(s=this._$EO)==null||s.forEach(o=>{var i;return(i=o.hostUpdate)==null?void 0:i.call(o)}),this.update(t)):this._$EU()}catch(o){throw e=!1,this._$EU(),o}e&&this._$AE(t)}willUpdate(e){}_$AE(e){var t;(t=this._$EO)==null||t.forEach(s=>{var o;return(o=s.hostUpdated)==null?void 0:o.call(s)}),this.hasUpdated||(this.hasUpdated=!0,this.firstUpdated(e)),this.updated(e)}_$EU(){this._$AL=new Map,this.isUpdatePending=!1}get updateComplete(){return this.getUpdateComplete()}getUpdateComplete(){return this._$ES}shouldUpdate(e){return!0}update(e){this._$Ej&&(this._$Ej=this._$Ej.forEach(t=>this._$EC(t,this[t]))),this._$EU()}updated(e){}firstUpdated(e){}}S.elementStyles=[],S.shadowRootOptions={mode:"open"},S[U("elementProperties")]=new Map,S[U("finalized")]=new Map,I==null||I({ReactiveElement:S}),($.reactiveElementVersions??($.reactiveElementVersions=[])).push("2.0.4");/**
10
10
  * @license
11
11
  * Copyright 2017 Google LLC
12
12
  * SPDX-License-Identifier: BSD-3-Clause
13
- */const R=globalThis,M=R.trustedTypes,oe=M?M.createPolicy("lit-html",{createHTML:r=>r}):void 0,pe="$lit$",w=`lit$${Math.random().toFixed(9).slice(2)}$`,me="?"+w,qe=`<${me}>`,A=document,O=()=>A.createComment(""),N=r=>r===null||typeof r!="object"&&typeof r!="function",J=Array.isArray,De=r=>J(r)||typeof(r==null?void 0:r[Symbol.iterator])=="function",W=`[
14
- \f\r]`,T=/<(?:(!--|\/[^a-zA-Z])|(\/?[a-zA-Z][^>\s]*)|(\/?$))/g,ie=/-->/g,ne=/>/g,v=RegExp(`>|${W}(?:([^\\s"'>=/]+)(${W}*=${W}*(?:[^
15
- \f\r"'\`<>=]|("|')|))|$)`,"g"),ae=/'/g,le=/"/g,fe=/^(?:script|style|textarea|title)$/i,Fe=r=>(e,...t)=>({_$litType$:r,strings:e,values:t}),c=Fe(1),S=Symbol.for("lit-noChange"),p=Symbol.for("lit-nothing"),ce=new WeakMap,_=A.createTreeWalker(A,129);function ge(r,e){if(!J(r)||!r.hasOwnProperty("raw"))throw Error("invalid template strings array");return oe!==void 0?oe.createHTML(e):e}const Le=(r,e)=>{const t=r.length-1,s=[];let o,i=e===2?"<svg>":e===3?"<math>":"",n=T;for(let l=0;l<t;l++){const a=r[l];let u,d,h=-1,m=0;for(;m<a.length&&(n.lastIndex=m,d=n.exec(a),d!==null);)m=n.lastIndex,n===T?d[1]==="!--"?n=ie:d[1]!==void 0?n=ne:d[2]!==void 0?(fe.test(d[2])&&(o=RegExp("</"+d[2],"g")),n=v):d[3]!==void 0&&(n=v):n===v?d[0]===">"?(n=o??T,h=-1):d[1]===void 0?h=-2:(h=n.lastIndex-d[2].length,u=d[1],n=d[3]===void 0?v:d[3]==='"'?le:ae):n===le||n===ae?n=v:n===ie||n===ne?n=T:(n=v,o=void 0);const f=n===v&&r[l+1].startsWith("/>")?" ":"";i+=n===T?a+qe:h>=0?(s.push(u),a.slice(0,h)+pe+a.slice(h)+w+f):a+w+(h===-2?l:f)}return[ge(r,i+(r[t]||"<?>")+(e===2?"</svg>":e===3?"</math>":"")),s]};class H{constructor({strings:e,_$litType$:t},s){let o;this.parts=[];let i=0,n=0;const l=e.length-1,a=this.parts,[u,d]=Le(e,t);if(this.el=H.createElement(u,s),_.currentNode=this.el.content,t===2||t===3){const h=this.el.content.firstChild;h.replaceWith(...h.childNodes)}for(;(o=_.nextNode())!==null&&a.length<l;){if(o.nodeType===1){if(o.hasAttributes())for(const h of o.getAttributeNames())if(h.endsWith(pe)){const m=d[n++],f=o.getAttribute(h).split(w),F=/([.?@])?(.*)/.exec(m);a.push({type:1,index:i,name:F[2],strings:f,ctor:F[1]==="."?Ie:F[1]==="?"?ze:F[1]==="@"?je:I}),o.removeAttribute(h)}else h.startsWith(w)&&(a.push({type:6,index:i}),o.removeAttribute(h));if(fe.test(o.tagName)){const h=o.textContent.split(w),m=h.length-1;if(m>0){o.textContent=M?M.emptyScript:"";for(let f=0;f<m;f++)o.append(h[f],O()),_.nextNode(),a.push({type:2,index:++i});o.append(h[m],O())}}}else if(o.nodeType===8)if(o.data===me)a.push({type:2,index:i});else{let h=-1;for(;(h=o.data.indexOf(w,h+1))!==-1;)a.push({type:7,index:i}),h+=w.length-1}i++}}static createElement(e,t){const s=A.createElement("template");return s.innerHTML=e,s}}function C(r,e,t=r,s){var n,l;if(e===S)return e;let o=s!==void 0?(n=t._$Co)==null?void 0:n[s]:t._$Cl;const i=N(e)?void 0:e._$litDirective$;return(o==null?void 0:o.constructor)!==i&&((l=o==null?void 0:o._$AO)==null||l.call(o,!1),i===void 0?o=void 0:(o=new i(r),o._$AT(r,t,s)),s!==void 0?(t._$Co??(t._$Co=[]))[s]=o:t._$Cl=o),o!==void 0&&(e=C(r,o._$AS(r,e.values),o,s)),e}class Me{constructor(e,t){this._$AV=[],this._$AN=void 0,this._$AD=e,this._$AM=t}get parentNode(){return this._$AM.parentNode}get _$AU(){return this._$AM._$AU}u(e){const{el:{content:t},parts:s}=this._$AD,o=((e==null?void 0:e.creationScope)??A).importNode(t,!0);_.currentNode=o;let i=_.nextNode(),n=0,l=0,a=s[0];for(;a!==void 0;){if(n===a.index){let u;a.type===2?u=new D(i,i.nextSibling,this,e):a.type===1?u=new a.ctor(i,a.name,a.strings,this,e):a.type===6&&(u=new We(i,this,e)),this._$AV.push(u),a=s[++l]}n!==(a==null?void 0:a.index)&&(i=_.nextNode(),n++)}return _.currentNode=A,o}p(e){let t=0;for(const s of this._$AV)s!==void 0&&(s.strings!==void 0?(s._$AI(e,s,t),t+=s.strings.length-2):s._$AI(e[t])),t++}}class D{get _$AU(){var e;return((e=this._$AM)==null?void 0:e._$AU)??this._$Cv}constructor(e,t,s,o){this.type=2,this._$AH=p,this._$AN=void 0,this._$AA=e,this._$AB=t,this._$AM=s,this.options=o,this._$Cv=(o==null?void 0:o.isConnected)??!0}get parentNode(){let e=this._$AA.parentNode;const t=this._$AM;return t!==void 0&&(e==null?void 0:e.nodeType)===11&&(e=t.parentNode),e}get startNode(){return this._$AA}get endNode(){return this._$AB}_$AI(e,t=this){e=C(this,e,t),N(e)?e===p||e==null||e===""?(this._$AH!==p&&this._$AR(),this._$AH=p):e!==this._$AH&&e!==S&&this._(e):e._$litType$!==void 0?this.$(e):e.nodeType!==void 0?this.T(e):De(e)?this.k(e):this._(e)}O(e){return this._$AA.parentNode.insertBefore(e,this._$AB)}T(e){this._$AH!==e&&(this._$AR(),this._$AH=this.O(e))}_(e){this._$AH!==p&&N(this._$AH)?this._$AA.nextSibling.data=e:this.T(A.createTextNode(e)),this._$AH=e}$(e){var i;const{values:t,_$litType$:s}=e,o=typeof s=="number"?this._$AC(e):(s.el===void 0&&(s.el=H.createElement(ge(s.h,s.h[0]),this.options)),s);if(((i=this._$AH)==null?void 0:i._$AD)===o)this._$AH.p(t);else{const n=new Me(o,this),l=n.u(this.options);n.p(t),this.T(l),this._$AH=n}}_$AC(e){let t=ce.get(e.strings);return t===void 0&&ce.set(e.strings,t=new H(e)),t}k(e){J(this._$AH)||(this._$AH=[],this._$AR());const t=this._$AH;let s,o=0;for(const i of e)o===t.length?t.push(s=new D(this.O(O()),this.O(O()),this,this.options)):s=t[o],s._$AI(i),o++;o<t.length&&(this._$AR(s&&s._$AB.nextSibling,o),t.length=o)}_$AR(e=this._$AA.nextSibling,t){var s;for((s=this._$AP)==null?void 0:s.call(this,!1,!0,t);e&&e!==this._$AB;){const o=e.nextSibling;e.remove(),e=o}}setConnected(e){var t;this._$AM===void 0&&(this._$Cv=e,(t=this._$AP)==null||t.call(this,e))}}class I{get tagName(){return this.element.tagName}get _$AU(){return this._$AM._$AU}constructor(e,t,s,o,i){this.type=1,this._$AH=p,this._$AN=void 0,this.element=e,this.name=t,this._$AM=o,this.options=i,s.length>2||s[0]!==""||s[1]!==""?(this._$AH=Array(s.length-1).fill(new String),this.strings=s):this._$AH=p}_$AI(e,t=this,s,o){const i=this.strings;let n=!1;if(i===void 0)e=C(this,e,t,0),n=!N(e)||e!==this._$AH&&e!==S,n&&(this._$AH=e);else{const l=e;let a,u;for(e=i[0],a=0;a<i.length-1;a++)u=C(this,l[s+a],t,a),u===S&&(u=this._$AH[a]),n||(n=!N(u)||u!==this._$AH[a]),u===p?e=p:e!==p&&(e+=(u??"")+i[a+1]),this._$AH[a]=u}n&&!o&&this.j(e)}j(e){e===p?this.element.removeAttribute(this.name):this.element.setAttribute(this.name,e??"")}}class Ie extends I{constructor(){super(...arguments),this.type=3}j(e){this.element[this.name]=e===p?void 0:e}}class ze extends I{constructor(){super(...arguments),this.type=4}j(e){this.element.toggleAttribute(this.name,!!e&&e!==p)}}class je extends I{constructor(e,t,s,o,i){super(e,t,s,o,i),this.type=5}_$AI(e,t=this){if((e=C(this,e,t,0)??p)===S)return;const s=this._$AH,o=e===p&&s!==p||e.capture!==s.capture||e.once!==s.once||e.passive!==s.passive,i=e!==p&&(s===p||o);o&&this.element.removeEventListener(this.name,this,s),i&&this.element.addEventListener(this.name,this,e),this._$AH=e}handleEvent(e){var t;typeof this._$AH=="function"?this._$AH.call(((t=this.options)==null?void 0:t.host)??this.element,e):this._$AH.handleEvent(e)}}class We{constructor(e,t,s){this.element=e,this.type=6,this._$AN=void 0,this._$AM=t,this.options=s}get _$AU(){return this._$AM._$AU}_$AI(e){C(this,e)}}const B=R.litHtmlPolyfillSupport;B==null||B(H,D),(R.litHtmlVersions??(R.litHtmlVersions=[])).push("3.2.1");const Be=(r,e,t)=>{const s=(t==null?void 0:t.renderBefore)??e;let o=s._$litPart$;if(o===void 0){const i=(t==null?void 0:t.renderBefore)??null;s._$litPart$=o=new D(e.insertBefore(O(),i),i,void 0,t??{})}return o._$AI(r),o};/**
13
+ */const T=globalThis,M=T.trustedTypes,ee=M?M.createPolicy("lit-html",{createHTML:r=>r}):void 0,he="$lit$",g=`lit$${Math.random().toFixed(9).slice(2)}$`,ce="?"+g,Se=`<${ce}>`,A=document,k=()=>A.createComment(""),O=r=>r===null||typeof r!="object"&&typeof r!="function",Q=Array.isArray,Ce=r=>Q(r)||typeof(r==null?void 0:r[Symbol.iterator])=="function",z=`[
14
+ \f\r]`,x=/<(?:(!--|\/[^a-zA-Z])|(\/?[a-zA-Z][^>\s]*)|(\/?$))/g,te=/-->/g,se=/>/g,b=RegExp(`>|${z}(?:([^\\s"'>=/]+)(${z}*=${z}*(?:[^
15
+ \f\r"'\`<>=]|("|')|))|$)`,"g"),re=/'/g,oe=/"/g,de=/^(?:script|style|textarea|title)$/i,Pe=r=>(e,...t)=>({_$litType$:r,strings:e,values:t}),p=Pe(1),C=Symbol.for("lit-noChange"),u=Symbol.for("lit-nothing"),ie=new WeakMap,v=A.createTreeWalker(A,129);function ue(r,e){if(!Q(r)||!r.hasOwnProperty("raw"))throw Error("invalid template strings array");return ee!==void 0?ee.createHTML(e):e}const xe=(r,e)=>{const t=r.length-1,s=[];let o,i=e===2?"<svg>":e===3?"<math>":"",n=x;for(let l=0;l<t;l++){const a=r[l];let d,h,c=-1,m=0;for(;m<a.length&&(n.lastIndex=m,h=n.exec(a),h!==null);)m=n.lastIndex,n===x?h[1]==="!--"?n=te:h[1]!==void 0?n=se:h[2]!==void 0?(de.test(h[2])&&(o=RegExp("</"+h[2],"g")),n=b):h[3]!==void 0&&(n=b):n===b?h[0]===">"?(n=o??x,c=-1):h[1]===void 0?c=-2:(c=n.lastIndex-h[2].length,d=h[1],n=h[3]===void 0?b:h[3]==='"'?oe:re):n===oe||n===re?n=b:n===te||n===se?n=x:(n=b,o=void 0);const f=n===b&&r[l+1].startsWith("/>")?" ":"";i+=n===x?a+Se:c>=0?(s.push(d),a.slice(0,c)+he+a.slice(c)+g+f):a+g+(c===-2?l:f)}return[ue(r,i+(r[t]||"<?>")+(e===2?"</svg>":e===3?"</math>":"")),s]};class R{constructor({strings:e,_$litType$:t},s){let o;this.parts=[];let i=0,n=0;const l=e.length-1,a=this.parts,[d,h]=xe(e,t);if(this.el=R.createElement(d,s),v.currentNode=this.el.content,t===2||t===3){const c=this.el.content.firstChild;c.replaceWith(...c.childNodes)}for(;(o=v.nextNode())!==null&&a.length<l;){if(o.nodeType===1){if(o.hasAttributes())for(const c of o.getAttributeNames())if(c.endsWith(he)){const m=h[n++],f=o.getAttribute(c).split(g),y=/([.?@])?(.*)/.exec(m);a.push({type:1,index:i,name:y[2],strings:f,ctor:y[1]==="."?Te:y[1]==="?"?ke:y[1]==="@"?Oe:D}),o.removeAttribute(c)}else c.startsWith(g)&&(a.push({type:6,index:i}),o.removeAttribute(c));if(de.test(o.tagName)){const c=o.textContent.split(g),m=c.length-1;if(m>0){o.textContent=M?M.emptyScript:"";for(let f=0;f<m;f++)o.append(c[f],k()),v.nextNode(),a.push({type:2,index:++i});o.append(c[m],k())}}}else if(o.nodeType===8)if(o.data===ce)a.push({type:2,index:i});else{let c=-1;for(;(c=o.data.indexOf(g,c+1))!==-1;)a.push({type:7,index:i}),c+=g.length-1}i++}}static createElement(e,t){const s=A.createElement("template");return s.innerHTML=e,s}}function P(r,e,t=r,s){var n,l;if(e===C)return e;let o=s!==void 0?(n=t._$Co)==null?void 0:n[s]:t._$Cl;const i=O(e)?void 0:e._$litDirective$;return(o==null?void 0:o.constructor)!==i&&((l=o==null?void 0:o._$AO)==null||l.call(o,!1),i===void 0?o=void 0:(o=new i(r),o._$AT(r,t,s)),s!==void 0?(t._$Co??(t._$Co=[]))[s]=o:t._$Cl=o),o!==void 0&&(e=P(r,o._$AS(r,e.values),o,s)),e}class Ue{constructor(e,t){this._$AV=[],this._$AN=void 0,this._$AD=e,this._$AM=t}get parentNode(){return this._$AM.parentNode}get _$AU(){return this._$AM._$AU}u(e){const{el:{content:t},parts:s}=this._$AD,o=((e==null?void 0:e.creationScope)??A).importNode(t,!0);v.currentNode=o;let i=v.nextNode(),n=0,l=0,a=s[0];for(;a!==void 0;){if(n===a.index){let d;a.type===2?d=new H(i,i.nextSibling,this,e):a.type===1?d=new a.ctor(i,a.name,a.strings,this,e):a.type===6&&(d=new Re(i,this,e)),this._$AV.push(d),a=s[++l]}n!==(a==null?void 0:a.index)&&(i=v.nextNode(),n++)}return v.currentNode=A,o}p(e){let t=0;for(const s of this._$AV)s!==void 0&&(s.strings!==void 0?(s._$AI(e,s,t),t+=s.strings.length-2):s._$AI(e[t])),t++}}class H{get _$AU(){var e;return((e=this._$AM)==null?void 0:e._$AU)??this._$Cv}constructor(e,t,s,o){this.type=2,this._$AH=u,this._$AN=void 0,this._$AA=e,this._$AB=t,this._$AM=s,this.options=o,this._$Cv=(o==null?void 0:o.isConnected)??!0}get parentNode(){let e=this._$AA.parentNode;const t=this._$AM;return t!==void 0&&(e==null?void 0:e.nodeType)===11&&(e=t.parentNode),e}get startNode(){return this._$AA}get endNode(){return this._$AB}_$AI(e,t=this){e=P(this,e,t),O(e)?e===u||e==null||e===""?(this._$AH!==u&&this._$AR(),this._$AH=u):e!==this._$AH&&e!==C&&this._(e):e._$litType$!==void 0?this.$(e):e.nodeType!==void 0?this.T(e):Ce(e)?this.k(e):this._(e)}O(e){return this._$AA.parentNode.insertBefore(e,this._$AB)}T(e){this._$AH!==e&&(this._$AR(),this._$AH=this.O(e))}_(e){this._$AH!==u&&O(this._$AH)?this._$AA.nextSibling.data=e:this.T(A.createTextNode(e)),this._$AH=e}$(e){var i;const{values:t,_$litType$:s}=e,o=typeof s=="number"?this._$AC(e):(s.el===void 0&&(s.el=R.createElement(ue(s.h,s.h[0]),this.options)),s);if(((i=this._$AH)==null?void 0:i._$AD)===o)this._$AH.p(t);else{const n=new Ue(o,this),l=n.u(this.options);n.p(t),this.T(l),this._$AH=n}}_$AC(e){let t=ie.get(e.strings);return t===void 0&&ie.set(e.strings,t=new R(e)),t}k(e){Q(this._$AH)||(this._$AH=[],this._$AR());const t=this._$AH;let s,o=0;for(const i of e)o===t.length?t.push(s=new H(this.O(k()),this.O(k()),this,this.options)):s=t[o],s._$AI(i),o++;o<t.length&&(this._$AR(s&&s._$AB.nextSibling,o),t.length=o)}_$AR(e=this._$AA.nextSibling,t){var s;for((s=this._$AP)==null?void 0:s.call(this,!1,!0,t);e&&e!==this._$AB;){const o=e.nextSibling;e.remove(),e=o}}setConnected(e){var t;this._$AM===void 0&&(this._$Cv=e,(t=this._$AP)==null||t.call(this,e))}}class D{get tagName(){return this.element.tagName}get _$AU(){return this._$AM._$AU}constructor(e,t,s,o,i){this.type=1,this._$AH=u,this._$AN=void 0,this.element=e,this.name=t,this._$AM=o,this.options=i,s.length>2||s[0]!==""||s[1]!==""?(this._$AH=Array(s.length-1).fill(new String),this.strings=s):this._$AH=u}_$AI(e,t=this,s,o){const i=this.strings;let n=!1;if(i===void 0)e=P(this,e,t,0),n=!O(e)||e!==this._$AH&&e!==C,n&&(this._$AH=e);else{const l=e;let a,d;for(e=i[0],a=0;a<i.length-1;a++)d=P(this,l[s+a],t,a),d===C&&(d=this._$AH[a]),n||(n=!O(d)||d!==this._$AH[a]),d===u?e=u:e!==u&&(e+=(d??"")+i[a+1]),this._$AH[a]=d}n&&!o&&this.j(e)}j(e){e===u?this.element.removeAttribute(this.name):this.element.setAttribute(this.name,e??"")}}class Te extends D{constructor(){super(...arguments),this.type=3}j(e){this.element[this.name]=e===u?void 0:e}}class ke extends D{constructor(){super(...arguments),this.type=4}j(e){this.element.toggleAttribute(this.name,!!e&&e!==u)}}class Oe extends D{constructor(e,t,s,o,i){super(e,t,s,o,i),this.type=5}_$AI(e,t=this){if((e=P(this,e,t,0)??u)===C)return;const s=this._$AH,o=e===u&&s!==u||e.capture!==s.capture||e.once!==s.once||e.passive!==s.passive,i=e!==u&&(s===u||o);o&&this.element.removeEventListener(this.name,this,s),i&&this.element.addEventListener(this.name,this,e),this._$AH=e}handleEvent(e){var t;typeof this._$AH=="function"?this._$AH.call(((t=this.options)==null?void 0:t.host)??this.element,e):this._$AH.handleEvent(e)}}class Re{constructor(e,t,s){this.element=e,this.type=6,this._$AN=void 0,this._$AM=t,this.options=s}get _$AU(){return this._$AM._$AU}_$AI(e){P(this,e)}}const j=T.litHtmlPolyfillSupport;j==null||j(R,H),(T.litHtmlVersions??(T.litHtmlVersions=[])).push("3.2.1");const Ne=(r,e,t)=>{const s=(t==null?void 0:t.renderBefore)??e;let o=s._$litPart$;if(o===void 0){const i=(t==null?void 0:t.renderBefore)??null;s._$litPart$=o=new H(e.insertBefore(k(),i),i,void 0,t??{})}return o._$AI(r),o};/**
16
16
  * @license
17
17
  * Copyright 2017 Google LLC
18
18
  * SPDX-License-Identifier: BSD-3-Clause
19
- */class b extends E{constructor(){super(...arguments),this.renderOptions={host:this},this._$Do=void 0}createRenderRoot(){var t;const e=super.createRenderRoot();return(t=this.renderOptions).renderBefore??(t.renderBefore=e.firstChild),e}update(e){const t=this.render();this.hasUpdated||(this.renderOptions.isConnected=this.isConnected),super.update(e),this._$Do=Be(t,this.renderRoot,this.renderOptions)}connectedCallback(){var e;super.connectedCallback(),(e=this._$Do)==null||e.setConnected(!0)}disconnectedCallback(){var e;super.disconnectedCallback(),(e=this._$Do)==null||e.setConnected(!1)}render(){return S}}var de;b._$litElement$=!0,b.finalized=!0,(de=globalThis.litElementHydrateSupport)==null||de.call(globalThis,{LitElement:b});const G=globalThis.litElementPolyfillSupport;G==null||G({LitElement:b});(globalThis.litElementVersions??(globalThis.litElementVersions=[])).push("4.1.1");function x(r){return{api:(e,t)=>P(r,e,t),mintToken:({username:e,password:t})=>Ge({config:r,username:e,password:t}),refreshToken:({token:e})=>Ve({config:r,token:e}),pubkey:()=>Ke({config:r}),updatePassword:({token:e,currentPassword:t,newPassword:s})=>Qe({config:r,token:e,currentPassword:t,newPassword:s}),triggerResetPassword:({username:e})=>Je({config:r,username:e}),confirmResetPassword:({username:e,newPassword:t,confirmationCode:s})=>Ye({config:r,username:e,newPassword:t,confirmationCode:s})}}function Ge({config:r,username:e,password:t}){return P(r,"/v1/user/login",{method:"POST",body:{username:e,password:t}})}function Ve({config:r,token:e}){return P(r,"/v1/refresh",{method:"POST",body:{token:e}})}function Ke({config:r}){return P(r,"/v1/pubkey",{method:"GET"})}function Qe({config:r,token:e,currentPassword:t,newPassword:s}){return P(r,"/v1/user/password",{method:"PUT",body:{currentPassword:t,newPassword:s},headers:{Authorization:`Bearer ${e}`}})}function Je({config:r,username:e}){return P(r,"/v1/user/password/reset",{method:"POST",body:{username:e}})}function Ye({config:r,username:e,newPassword:t,confirmationCode:s}){return P(r,"/v1/user/password/reset/confirm",{method:"POST",body:{username:e,newPassword:t,confirmationCode:s}})}async function P(r,e,t){var u;const s=r.baseUrl.endsWith("/")?r.baseUrl:`${r.baseUrl}/`,o=e.startsWith("/")?e.substring(1):e,i=new URL(o,s),l=Object.assign({},t,{headers:Object.assign({},{"Content-Type":"application/json"},t==null?void 0:t.headers),body:t!=null&&t.body?JSON.stringify(t.body):void 0}),a=await fetch(i.toString(),l);if(!a.ok){const d=new Error("API request failed.");if(d.status=a.status,d.statusText=a.statusText,d.url=i.toString(),d.headers=a.headers,d.bodyUsed=a.bodyUsed,(u=a.headers.get("Content-Type"))!=null&&u.includes("application/json"))try{d.body=await a.json()}catch{d.body="Failed to parse response body."}throw d}if(a.status!==204)return await a.json()}function ye({api:r},e){const t=x({baseUrl:r});return console.log("sending credentials to API",r),t.mintToken(e)}const g=Object.freeze({REQUEST:"request",CONFIRM:"confirm",FINISHED:"finished"});class Ze extends b{static get properties(){return{api:{type:String,attribute:"api"},confirmation:{type:"String",attribute:"confirmation"}}}static get styles(){return q`
19
+ */class w extends S{constructor(){super(...arguments),this.renderOptions={host:this},this._$Do=void 0}createRenderRoot(){var t;const e=super.createRenderRoot();return(t=this.renderOptions).renderBefore??(t.renderBefore=e.firstChild),e}update(e){const t=this.render();this.hasUpdated||(this.renderOptions.isConnected=this.isConnected),super.update(e),this._$Do=Ne(t,this.renderRoot,this.renderOptions)}connectedCallback(){var e;super.connectedCallback(),(e=this._$Do)==null||e.setConnected(!0)}disconnectedCallback(){var e;super.disconnectedCallback(),(e=this._$Do)==null||e.setConnected(!1)}render(){return C}}var ne;w._$litElement$=!0,w.finalized=!0,(ne=globalThis.litElementHydrateSupport)==null||ne.call(globalThis,{LitElement:w});const B=globalThis.litElementPolyfillSupport;B==null||B({LitElement:w});(globalThis.litElementVersions??(globalThis.litElementVersions=[])).push("4.1.1");class He extends w{static get styles(){return J`
20
+ .login-layout {
21
+ display: flex;
22
+ flex-direction: column;
23
+ gap: 1rem;
24
+ justify-content: center;
25
+ align-items: center;
26
+ min-height: 100vh;
27
+ background-color: var(--color-gray-100);
28
+ }
29
+ .login-layout > * {
30
+ max-width: 400px;
31
+ }
32
+ `}render(){return p`
33
+ <div class="login-layout">
34
+ <slot name="main"></slot>
35
+ </div>
36
+ `}}customElements.get("mod-auth-layout")===void 0&&customElements.define("mod-auth-layout",He);function Le(){return p`<mod-auth-layout></mod-auth-layout>`}function N(r){return{api:(e,t)=>E(r,e,t),mintToken:({username:e,password:t})=>Fe({config:r,username:e,password:t}),refreshToken:({token:e})=>qe({config:r,token:e}),pubkey:()=>Me({config:r}),updatePassword:({token:e,currentPassword:t,newPassword:s})=>De({config:r,token:e,currentPassword:t,newPassword:s}),triggerResetPassword:({username:e})=>Ie({config:r,username:e}),confirmResetPassword:({username:e,newPassword:t,confirmationCode:s})=>ze({config:r,username:e,newPassword:t,confirmationCode:s})}}function Fe({config:r,username:e,password:t}){return E(r,"/v1/user/login",{method:"POST",body:{username:e,password:t}})}function qe({config:r,token:e}){return E(r,"/v1/refresh",{method:"POST",body:{token:e}})}function Me({config:r}){return E(r,"/v1/pubkey",{method:"GET"})}function De({config:r,token:e,currentPassword:t,newPassword:s}){return E(r,"/v1/user/password",{method:"PUT",body:{currentPassword:t,newPassword:s},headers:{Authorization:`Bearer ${e}`}})}function Ie({config:r,username:e}){return E(r,"/v1/user/password/reset",{method:"POST",body:{username:e}})}function ze({config:r,username:e,newPassword:t,confirmationCode:s}){return E(r,"/v1/user/password/reset/confirm",{method:"POST",body:{username:e,newPassword:t,confirmationCode:s}})}async function E(r,e,t){var d;const s=r.baseUrl.endsWith("/")?r.baseUrl:`${r.baseUrl}/`,o=e.startsWith("/")?e.substring(1):e,i=new URL(o,s),l=Object.assign({},t,{headers:Object.assign({},{"Content-Type":"application/json"},t==null?void 0:t.headers),body:t!=null&&t.body?JSON.stringify(t.body):void 0}),a=await fetch(i.toString(),l);if(!a.ok){const h=new Error("API request failed.");if(h.status=a.status,h.statusText=a.statusText,h.url=i.toString(),h.headers=a.headers,h.bodyUsed=a.bodyUsed,(d=a.headers.get("Content-Type"))!=null&&d.includes("application/json"))try{h.body=await a.json()}catch{h.body="Failed to parse response body."}throw h}if(a.status!==204)return await a.json()}const _=Object.freeze({REQUEST:"request",CONFIRM:"confirm",FINISHED:"finished"});class je extends w{static get properties(){return{api:{type:String}}}static get styles(){return J`
20
37
  :host {
21
- display: block;
22
- font-family: Arial, sans-serif;
38
+ display: flex;
39
+ flex-direction: column;
40
+ justify-content: center;
41
+ align-items: center;
42
+ }
43
+ form {
44
+ display: flex;
45
+ flex-direction: column;
23
46
  }
24
47
  form input[type="text"],
25
48
  form input[type="password"] {
@@ -27,14 +50,14 @@
27
50
  margin: 5px 0 15px 0;
28
51
  padding: var(--spacing-sm, 0.5rem) var(--spacing-md, 1rem);
29
52
  box-sizing: border-box;
30
- border: 1px solid var(--color-gray-300, #ccc);
31
- border-radius: var(--radius-sm, 5px);
32
- color: var(--color-gray-9, #333);
33
- background-color: var(--color-gray-0, transparent);
53
+ border: 1px solid var(--color-gray-300, #CCC);
54
+ border-radius: var(--radius-sm, 3px);
55
+ color: var(--color-gray-700, #333);
56
+ background-color: var(--color-gray-50, #FFF);
34
57
  }
35
58
  form input[type="submit"] {
36
- background-color:var(--color-primary, inherit);
37
- color: var(--color-gray-0, #fff);
59
+ background-color: var(--color-primary, inherit);
60
+ color: var(--color-gray-50, #fff);
38
61
  border: none;
39
62
  padding: var(--spacing-sm, 0.5rem) var(--spacing-md, 1rem);
40
63
  border-radius: var(--radius-dynamic, 5px);
@@ -45,16 +68,16 @@
45
68
  }
46
69
  form label {
47
70
  font-size: 14px;
48
- color: var(--color-gray-9, #333);
71
+ color: var(--color-gray-700, #333);
49
72
  font-weight: bold;
50
73
  margin-bottom: var(--spacing-sm, 0.5rem);
51
74
  }
52
75
  .error {
53
76
  color: var(--color-danger, red);
54
- font-size: 12px;
77
+ font-size: 14px;
55
78
  }
56
- `}constructor(){super(),this.errors={},this.stage=g.REQUEST}connectedCallback(){console.log("[auth]","[forgot-password]",{confirmation:this.confirmation}),super.connectedCallback(),this.confirmation&&this.stage!==g.FINISHED&&(this.stage=g.CONFIRM),this.requestUpdate()}handleSubmitRequest(e){e.preventDefault();const t=e.target.username.value;this.username=t,x({baseUrl:this.api}).triggerResetPassword({username:t}).then(()=>{console.log("[auth]","triggered reset password for ",t),this.stage=g.CONFIRM}).catch(o=>{console.error("[auth] error triggering reset password",o),this.errors.general=o.message||"Unable to send password reset request. Please try again later."}).finally(()=>{this.requestUpdate()})}handleSubmitConfirm(e){e.preventDefault();const t=e.target.password.value,s=e.target["confirm-password"].value;if(t!==s){this.errors["confirm-password"]="Passwords do not match.",this.requestUpdate();return}const o=this.confirmation||e.target.confirmation.value;if(!o){this.errors.general="Confirmation code is required.",this.requestUpdate();return}x({baseUrl:this.api}).confirmResetPassword({username:this.username,newPassword:t,confirmationCode:o}).then(()=>ye(this,{username:this.username,password:t}).then(({token:n})=>{this.dispatchEvent(new CustomEvent("login-success",{detail:{token:n},composed:!0,bubbles:!0}))})).catch(n=>{console.error("[auth][forgot-password-form]",n),this.errors.general="Unable to reset password. Please try again later."}).finally(()=>{this.requestUpdate()})}render(){switch(this.stage){case g.CONFIRM:return this.renderConfirmForm();case g.FINISHED:return c`<p>Your password has been reset.</p>`;case g.REQUEST_SENT:return c`<p>A email has been sent with instructions to finish
57
- resetting your password.</p>`;case g.REQUEST:default:return this.renderRequestForm()}}renderRequestForm(){return c`<form @submit=${this.handleSubmitRequest}>
79
+ `}constructor(){super(),this.errors={},this.stage=_.REQUEST}connectedCallback(){super.connectedCallback(),this.confirmToken&&this.stage!==_.FINISHED&&this.setStage(_.CONFIRM)}setStage(e){this.stage!==e&&(this.stage=e,this.requestUpdate())}handleSubmitRequest(e){e.preventDefault();const t=e.target.username.value;this.username=t,N({baseUrl:this.api}).triggerResetPassword({username:t}).then(()=>{this.setStage(_.CONFIRM)}).catch(o=>{this.errors.general=o.message||"Unable to send password reset request. Please try again later."}).finally(()=>{this.requestUpdate()})}handleSubmitConfirm(e){e.preventDefault();const t=e.target.password.value,s=e.target["confirm-password"].value;if(t!==s){this.errors["confirm-password"]="Passwords do not match",this.requestUpdate();return}const o=this.confirmToken||e.target.confirmation.value;if(!o){this.errors.general="Confirmation code is required",this.requestUpdate();return}const i=N({baseUrl:this.api});i.confirmResetPassword({username:this.username,newPassword:t,confirmationCode:o}).then(()=>{i.mintToken({username:this.username,password:t}).then(({token:n})=>{this.dispatchEvent(new CustomEvent("login-success",{detail:{token:n},bubbles:!0,composed:!0,cancelable:!0}))})}).catch(n=>{this.errors.general=n.message||"Unable to send password reset request. Please try again later."}).finally(()=>{this.requestUpdate()})}render(){switch(this.stage){case _.FINISHED:return p`<p>Your password has been reset.</p>`;case _.CONFIRM:return this.renderConfirmForm();case _.REQUEST:default:return this.renderRequestForm()}}renderRequestForm(){return p`<form @submit="${this.handleSubmitRequest}">
80
+ <p>Enter your username or email address to request a password reset.</p>
58
81
  <label for="username">Username/Email</label>
59
82
  <input
60
83
  type="text"
@@ -63,17 +86,17 @@
63
86
  required
64
87
  />
65
88
  <p class="error">${this.errors.general}</p>
66
- <input type="submit" value="Request password reset" />
67
- </form>`}renderConfirmForm(){return c`<form @submit=${this.handleSubmitConfirm}>
68
- <p>You should have received a confirmation code to reset your password</p>
89
+ <input type="submit" value="Request Password Reset" />
90
+ </form>`}renderConfirmForm(){return p`<form @submit="${this.handleSubmitConfirm}">
91
+ <p>You should have received a confirmation code to reset your password.</p>
69
92
 
70
- ${this.confirmation?"":c`<label for="confirmation">Confirmation Code</label>
71
- <input
72
- type="text"
73
- name="confirmation"
74
- placeholder="Confirmation Code"
75
- required
76
- />`}
93
+ ${this.confirmToken?"":p`<label for="confirmation">Confirmation Code</label>
94
+ <input
95
+ type="text"
96
+ name="confirmation"
97
+ placeholder="Confirmation Code"
98
+ required
99
+ />`}
77
100
 
78
101
  <label for="password">New Password</label>
79
102
  <input
@@ -82,8 +105,6 @@
82
105
  placeholder="Password"
83
106
  required
84
107
  />
85
- ${this.errors.password?c`<p class="error">${this.errors.password}</p>`:""}
86
-
87
108
  <label for="confirm-password">Confirm Password</label>
88
109
  <input
89
110
  type="password"
@@ -91,17 +112,17 @@
91
112
  placeholder="Confirm Password"
92
113
  required
93
114
  />
94
- ${this.errors["confirm-password"]?c`<p class="error">${this.errors["confirm-password"]}</p>`:""}
115
+ ${this.errors["confirm-password"]?p`<p class="error">${this.errors["confirm-password"]}</p>`:""}
116
+
117
+ ${this.errors.general?p`<p class="error">${this.errors.general}</p>`:""}
95
118
 
96
- ${this.errors.general?c`<p class="error">${this.errors.general}</p>`:""}
97
119
  <input type="submit" value="Reset Password" />
98
- </form>`}}class y extends b{static get properties(){return{api:{type:String,attribute:"api"}}}static get styles(){return q`
120
+ </form>`}}customElements.get("auth-forgot-password-form")||window.customElements.define("auth-forgot-password-form",je);class Be extends w{static get properties(){return{api:{type:String,attribute:"api"}}}static get styles(){return J`
99
121
  :host {
100
122
  display: block;
101
- font-family: Arial, sans-serif;
102
123
  }
103
124
  .login-form {
104
- background-color: var(--color-gray-0, #fff);
125
+ background-color: var(--color-gray-50);
105
126
  padding: var(--spacing-xl, 3rem);
106
127
  border-radius: var(--radius-md, 5px);
107
128
  box-shadow: var(--drop-shadow-md, none);
@@ -112,14 +133,14 @@
112
133
  margin: 5px 0 15px 0;
113
134
  padding: var(--spacing-sm, 0.5rem) var(--spacing-md, 1rem);
114
135
  box-sizing: border-box;
115
- border: 1px solid var(--color-gray-300, #ccc);
116
- border-radius: var(--radius-sm, 5px);
117
- color: var(--color-gray-9, #333);
118
- background-color: var(--color-gray-0, transparent);
136
+ border: 1px solid var(--color-gray-300, #CCC);
137
+ border-radius: var(--radius-sm, 3px);
138
+ color: var(--color-gray-700, #333);
139
+ background-color: var(--color-gray-100, #FFF);
119
140
  }
120
141
  form input[type="submit"] {
121
142
  background-color: var(--color-primary, inherit);
122
- color: var(--color-gray-0, #fff);
143
+ color: var(--color-gray-50, #fff);
123
144
  border: none;
124
145
  padding: var(--spacing-sm, 0.5rem) var(--spacing-md, 1rem);
125
146
  border-radius: var(--radius-dynamic, 5px);
@@ -130,15 +151,15 @@
130
151
  }
131
152
  form label {
132
153
  font-size: 14px;
133
- color: var(--color-gray-9, #333);
154
+ color: var(--color-gray-900, #333);
134
155
  font-weight: bold;
135
156
  margin-bottom: var(--spacing-sm, 0.5rem);
136
157
  }
137
158
  a.forgot {
138
159
  color: var(--color-primary, inherit);
139
160
  text-decoration: none;
140
- font-size: 12px;
141
161
  font-weight: bold;
162
+ font-size: 12px;
142
163
  }
143
164
  .error {
144
165
  color: var(--color-error, red);
@@ -153,7 +174,7 @@
153
174
  .header .intro {
154
175
  width: 200px;
155
176
  margin-bottom: 0;
156
- color: var(--color-gray-3);
177
+ color: var(--color-gray-300, #333);
157
178
  }
158
179
  .header .brand {
159
180
  font-size: 32px;
@@ -165,174 +186,67 @@
165
186
  font-weight: bold;
166
187
  font-style: normal;
167
188
  }
168
- `}static get states(){return{DEFAULT:"DEFAULT",FORGOT:"FORGOT",CHALLENGE_CHANGE_PW:"CHALLENGE_CHANGE_PW"}}constructor(){super(),this.formState=y.states.DEFAULT,this.username="",this.password="",this.token=void 0,this.errors=[]}onSubmit(e){e.preventDefault();const t=e.explicitOriginalTarget.parentElement;console.log(t);const s=new FormData(t).entries().reduce((o,[i,n])=>(o[i]=n,o),{});ye(this,s).then(({token:o,challenge:i})=>{if(i&&i.name==="NEW_PASSWORD_REQUIRED"){this.token=o,this.username=s.username,this.password=s.password,this.setState(y.states.CHALLENGE_CHANGE_PW);return}this.dispatchEvent(new CustomEvent("login-success",{detail:{token:o}}))}).catch(o=>{console.log(o),this.errors=[o.message],this.requestUpdate()})}onSubmitChangePasswordChallenge(e){e.preventDefault();const t=e.explicitOriginalTarget,s=new FormData(t).entries().reduce((l,[a,u])=>(l[a]=u,l),{}),o=s.password,i=s["confirm-password"];if(o!==i){this.errors=["Passwords do not match."],this.requestUpdate();return}x({baseUrl:this.api}).updatePassword({token:this.token,currentPassword:this.password,newPassword:o}).then(()=>{this.dispatchEvent(new CustomEvent("login-success",{detail:{token:this.token}}))}).catch(l=>{console.log(l),this.errors=[l.message],this.requestUpdate()})}setState(e){e!==this.formState&&(this.formState=e,this.errors=[],this.requestUpdate())}render(){return c`<div class="login-form">
189
+ `}static get states(){return{DEFAULT:"DEFAULT",FORGOT:"FORGOT",CHALLENGE_CHANGE_PW:"CHALLENGE_CHANGE_PW"}}constructor(){super(),this.formState=this.constructor.states.DEFAULT,this.errors=[],this.isBusy=!1}login({username:e,password:t}){return N({baseUrl:this.api}).mintToken({username:e,password:t})}emitLoginSuccess(e){this.dispatchEvent(new CustomEvent("login-success",{detail:{token:e},bubbles:!0,composed:!0,cancelable:!0}))}handleSubmitLogin(e){e.preventDefault();const t=e.explicitOriginalTarget.parentElement,s=new FormData(t).entries().reduce((o,[i,n])=>(o[i]=n,o),{});this.isBusy=!0,this.errors=[],this.requestUpdate(),this.login(s).then(({token:o,challenge:i})=>{if((i==null?void 0:i.name)==="NEW_PASSWORD_REQUIRED"){this.token=o,this.username=s.username,this.password=s.password,this.setState(this.constructor.states.CHALLENGE_CHANGE_PW);return}this.emitLoginSuccess(o)}).catch(o=>{console.error(o),this.errors=[o.message],this.requestUpdate()})}onSubmitChangePasswordChallenge(e){e.preventDefault();const t=e.explicitOriginalTarget.parentElement,s=new FormData(t).entries().reduce((l,[a,d])=>(l[a]=d,l),{}),o=s.password,i=s["confirm-password"];if(o!==i){this.errors=["Passwords do not match"],this.requestUpdate();return}N({baseUrl:this.api}).updatePassword({token:this.token,currentPassword:this.password,newPassword:o}).then(()=>{this.emitLoginSuccess(this.token)}).catch(l=>{console.error(l),this.errors=[l.message],this.requestUpdate()})}setState(e){this.formState=e,this.isBusy=!1,this.errors=[],this.requestUpdate()}render(){return p`<div class="login-form">
169
190
  ${this.renderHeader()}
170
- ${this.formState===y.states.FORGOT?this.renderForgotPasswordForm():""}
171
- ${this.formState===y.states.CHALLENGE_CHANGE_PW?this.renderChangePasswordForm():""}
172
- ${this.formState===y.states.DEFAULT?this.renderLoginForm():""}
173
- </div>`}renderHeader(){return c`<div class="header">
174
- <div class="intro">
175
- Welcome to
176
- </div>
177
- <div class="brand">
178
- <em>WRAL</em>.studio
179
- </div>
180
- </div>`}renderLoginForm(){return c`
181
- <form>
182
- <label for="username">User</label>
183
- <input
184
- type="text"
185
- name="username"
186
- placeholder="Email or Username"
187
- required
188
- />
189
-
190
- <label for="password">Password</label>
191
- <input
192
- type="password"
193
- name="password"
194
- placeholder="Password"
195
- required
196
- />
197
- <div>
198
- <a href="#" class="forgot"
199
- @click=${()=>{this.setState(y.states.FORGOT)}}
200
- >Forgot password</a>
201
- </div>
202
-
203
- ${this.errors?this.errors.map(e=>c`<p class="error">${e}</p>`):""}
204
- <input type="submit" value="Log in" @click=${this.onSubmit} />
205
-
206
- </form>`}renderForgotPasswordForm(){return c`
207
- <auth-forgot-password-form
208
- api=${this.api}>
209
- </auth-forgot-password-form>
210
- `}renderChangePasswordForm(){return c`
211
- <p>You have logged in successfully, but you must change your password.</p>
212
- <form @submit=${this.onSubmitChangePasswordChallenge}>
213
- <input type="hidden" name="username" value="${this.username}" />
214
- <label for="password">New Password</label>
191
+ ${this.formState===this.constructor.states.DEFAULT?this.renderLoginForm():""}
192
+ ${this.formState===this.constructor.states.CHALLENGE_CHANGE_PW?this.renderChangePasswordForm():""}
193
+ ${this.formState===this.constructor.states.FORGOT?this.renderForgotPasswordForm():""}
194
+ </div>`}renderHeader(){return p`<div class="header">
195
+ <div class="intro">Welcome to</div>
196
+ <div class="brand"><em>WRAL</em>.studio</div>
197
+ </div>`}renderLoginForm(){return p`
198
+ <form>
199
+ <label for="username">User</label>
215
200
  <input
216
- type="password"
217
- name="password"
218
- placeholder="Password"
201
+ type="text"
202
+ name="username"
203
+ placeholder="Email or Username"
219
204
  required
220
205
  />
221
- <label for="confirm-password">Confirm Password</label>
206
+
207
+ <label for="password">Password</label>
222
208
  <input
223
209
  type="password"
224
- name="confirm-password"
225
- placeholder="Confirm Password"
210
+ name="password"
211
+ placeholder="Password"
226
212
  required
227
213
  />
228
- ${this.errors?this.errors.map(e=>c`<p class="error">${e}</p>`):""}
229
- <input type="submit" value="Change Password" />
230
- </form>
231
- `}}customElements.define("auth-login-form",y);customElements.define("auth-forgot-password-form",Ze);function Xe(){return function(r){const e=q`
232
- .login-layout {
233
- display: flex;
234
- flex-direction: column;
235
- gap: 1rem;
236
- justify-content: center;
237
- align-items: center;
238
- min-height: 100vh;
239
- background-color: var(--color-gray-100, #f5f5f5);
240
- }
241
- .login-layout > * {
242
- max-width: 400px;
243
- }
244
- `;return c`
245
- <style>${e}</style>
246
- <div class="login-layout">
247
- ${r.main}
248
- </div>
249
- `}}function et(r){return JSON.parse(window.atob(r.split(".")[1].replace(/-/g,"+").replace(/_/g,"/")))}function tt(r,e=300,t=Date.now()){return et(r).exp*1e3-e<t}function we(r){return(r.startsWith("/")?r:`/${r}`).replace(/\/{2,}/g,"/").replace(new RegExp("(?<=.)\\/$"),"")}function $e(r,e,t){const s=st(r,t);e.pushState(t,t.title,s),r.requestRender(t)}function rt(r,e){const{mount:t}=r.config,{history:s}=r.config.toolkit.element.ownerDocument.defaultView;return e.startsWith(t)?{path:we(e.slice(t.length)),push:o=>$e(r,s,o)}:null}function st(r,e){const{mount:t}=r.config;return we(`${t}/${e.path}`)}function ot(r,e){const{history:t}=e.config.toolkit.element.ownerDocument.defaultView;return c`
250
- <h1>Auth Dashboard</h1>
251
- <ul>
252
- <li><a href="#" @click=${((o,i)=>()=>{$e(e,t,{path:o,title:i})})("/change-password")}>Change Password</a></li>
253
- <li><a href="#" @click=${e.handleDestroyAuth}>Logout</a></li>
254
- </ul>
255
- `}function it(r,e){return c`
256
- <auth-change-password-form .auth=${e}></auth-change-password-form>
257
- `}class nt extends b{static get styles(){return q`
258
- :host {
259
- color: var(--color-text);
260
- display: block;
261
- font-family: var(--font-body);
262
- }
263
- h1,h2,h3,h4,h5,h6,label { font-family: var(--font-heading) }
264
- label {
265
- display: block;
266
- font-size: var(--font-size-base);
267
- margin-top: var(--spacing-md, 0.5rem);
268
- }
269
- input[type="text"],
270
- input[type="password"] {
271
- width: 100%;
272
- margin: 5px 0 15px 0;
273
- padding: var(--spacing-sm, 0.5rem) var(--spacing-md, 1rem);
274
- box-sizing: border-box;
275
- border: 1px solid var(--color-gray-300, #ccc);
276
- border-radius: var(--radius-sm, 5px);
277
- color: var(--color-gray-9, #333);
278
- background-color: var(--color-gray-0, transparent);
279
- }
280
- input[type="submit"] {
281
- background-color: var(--color-primary, inherit);
282
- color: var(--color-gray-0, #fff);
283
- border: none;
284
- padding: var(--spacing-sm, 0.5rem) var(--spacing-md, 1rem);
285
- border-radius: var(--radius-dynamic, 5px);
286
- width: 200px;
287
- cursor: pointer;
288
- }
289
- .error {
290
- color: var(--color-error);
291
- }
292
- `}static get properties(){return{auth:{type:Object}}}constructor(){super(),this.errors={},this.success=null}connectedCallback(){super.connectedCallback(),X.getToken(this)}async onSubmit(e){if(e.preventDefault(),e.target.newPassword.value!==e.target.confirmPassword.value){this.errors.confirmPassword="Passwords do not match",this.requestUpdate();return}if(e.target.newPassword.value===e.target.currentPassword.value){this.errors.newPassword="The new password is the same as your current password.",this.requestUpdate();return}await X.getToken(this),await x({baseUrl:this.auth.config.api}).updatePassword({currentPassword:e.target.currentPassword.value,newPassword:e.target.newPassword.value}).then(()=>{this.errors={},this.success="Password changed.",this.requestUpdate()}).catch(s=>{this.errors.submit=s.message,this.requestUpdate()})}render(){return c`
293
- <h1>Change your password</h1>
294
- <p>Enter your current password and choose a new password.</p>
295
- <form @submit=${this.onSubmit}>
296
- <div class="field">
297
- <label for="currentPassword">Current Password</label>
298
- <input
299
- type="password"
300
- name="currentPassword"
301
- placeholder="Current Password"
302
- required
303
- />
304
- ${this.errors.currentPassword?c`<p class="error">${this.errors.currentPassword}</p>`:""}
305
- </div>
306
- <div class="field">
307
- <label for="newPassword">New Password</label>
308
- <input
309
- type="password"
310
- name="newPassword"
311
- placeholder="New Password"
312
- required
313
- />
314
- ${this.errors.newPassword?c`<p class="error">${this.errors.newPassword}</p>`:""}
214
+ <div>
215
+ <a href="#" class="forgot"
216
+ @click=${()=>{this.setState(this.constructor.states.FORGOT)}}>Forgot password</a>
315
217
  </div>
316
- <div class="field">
317
- <label for="confirmPassword">Confirm Password</label>
318
- <input
319
- type="password"
320
- name="confirmPassword"
321
- placeholder="Confirm Password"
322
- required
323
- />
324
- ${this.errors.confirmPassword?c`<p class="error">${this.errors.confirmPassword}</p>`:""}
325
- </div>
326
- <input type="submit" value="Change Password" />
327
- ${this.errors.submit?c`<p class="error">${this.errors.submit}</p>`:""}
328
- ${this.success?c`<p class="success">${this.success}</p>`:""}
329
- </form>
330
- `}}customElements.get("auth-change-password-form")||customElements.define("auth-change-password-form",nt);const at=[{path:"/",render:ot},{path:"/change-password",render:it}];function lt(r,e){const{path:t}=r,s=at.find(o=>o.path===t);if(s)return s.render(r,e)}const ct=q`
331
- :host {
218
+ ${this.errors?this.errors.map(e=>p`<p class="error">${e}</p>`):""}
332
219
 
333
- }
334
- `;class dt extends b{static get styles(){return[ct]}static get properties(){return{state:{type:Object},auth:{type:Object}}}render(){const{state:e,auth:t}=this;return lt(e,t)}}customElements.get("auth-app")||customElements.define("auth-app",dt);function ht(r){const e={config:r,log:(...t)=>console.log("[auth]",...t)};return e.mount=k(be,e),e.handleTokenRequest=_e(e),e.handleDestroyAuth=Ae(e),e.presentLoginForm=k(Pe,e),e.getToken=k(Z,e),e.saveToken=k(Ee,e),e.getFreshToken=k(Se,e),e.requestRender=t=>Y(e,t),e}function be(r){const e=r.config.toolkit.element.ownerDocument.defaultView;[{type:"action:register",detail:{actionType:"auth:requestToken",handler:r.handleTokenRequest,modName:"auth"}},{type:"action:register",detail:{actionType:"auth:destroy",handler:r.handleDestroyAuth,modName:"auth"}},{type:"layout:register",detail:{name:"auth:login",slots:["main"],templateFn:Xe()}}].forEach(t=>r.config.toolkit.dispatchAction(t)),e.addEventListener("popstate",ve(r))}function Y(r,e){const t=r.config.toolkit.element.ownerDocument.defaultView;let s=e;s||(s=rt(r,t.location.pathname)),s&&r.config.toolkit.dispatchAction({type:"layout:slot:replace",detail:{layout:"menu-main-task-layout",slot:"main",content:c`<auth-app .state=${s} .auth=${r}></auth-app>`}})}function ve(r){return e=>{r.log("onpopstate",e),Y(r)}}function _e(r){let e=[],t=!1;const s=o=>{e.forEach(i=>{i(o)}),e=[]};return async({callback:o})=>{let i;try{i=await r.getFreshToken(),o(i)}catch(n){e.push(o),t||(r.presentLoginForm({onLogin:s}),t=!0),r.log(n)}}}function Ae(r){return()=>{const e=z(r);window.localStorage.removeItem(e),r.config.toolkit.dispatchAction({type:"layout:pop"})}}function Pe(r,{onLogin:e}){const{toolkit:t}=r.config,o=new URLSearchParams(t.element.ownerDocument.defaultView.location.search).get("password_reset_confirmation"),i=n=>{r.log("login success",{event:n});const{token:l}=n.detail;r.log("Login form dismissed",{args:[l]}),t.dispatchAction({type:"layout:pop"}),r.saveToken({token:l}),e({token:l})};t.dispatchAction({type:"layout:push",detail:{layout:"auth:login"}}),t.dispatchAction({type:"layout:slot:push",detail:{layout:"auth:login",slot:"main",content:c`<auth-login-form
335
- api=${r.config.api}
336
- confirmation="${o}"
337
- @login-success=${i}>
338
- </auth-login-form>`}})}function Ee(r,{token:e}){r.log("saving token",{args:[e]});const t=z(r);window.localStorage.setItem(t,e)}function Z(r){const e=z(r);return window.localStorage.getItem(e)}async function Se(r){const e=Z(r);if(!e||e.length<1)throw new Error("No token found");return tt(e)?(r.log("refreshing token",{args:[e]}),await x({baseUrl:r.config.api}).refreshToken({token:e}).then(({token:s})=>s)):e}function z({storageKey:r="token"}){return r}exports.getFreshToken=Se;exports.getToken=Z;exports.getTokenStorageKey=z;exports.historyStateHandler=ve;exports.loginDestroyHandler=Ae;exports.makeAuth=ht;exports.mount=be;exports.presentLoginForm=Pe;exports.renderApp=Y;exports.saveToken=Ee;exports.tokenRequestHandler=_e;
220
+ <input type="submit" value="Log in" @click=${this.handleSubmitLogin}
221
+ ?disabled=${this.isBusy}
222
+ />
223
+ </form>
224
+ `}renderForgotPasswordForm(){return p`
225
+ <auth-forgot-password-form
226
+ api=${this.api}>
227
+ </auth-forgot-password-form>
228
+ `}renderChangePasswordForm(){return p`
229
+ <p>You have logged in successfully, but you must change your password.</p>
230
+ <form @submit="${this.onSubmitChangePasswordChallenge}">
231
+ <input type="hidden" name="username" value="${this.username}" />
232
+ <label for="password">New Password</label>
233
+ <input
234
+ type="password"
235
+ name="password"
236
+ placeholder="Password"
237
+ required
238
+ />
239
+ <label for="confirm-password">Confirm Password</label>
240
+ <input
241
+ type="password"
242
+ name="confirm-password"
243
+ placeholder="Confirm Password"
244
+ required
245
+ />
246
+ ${this.errors?this.errors.map(e=>p`<p class="error">${e}</p>`):""}
247
+ <input type="submit" value="Change Password" />
248
+ </form>
249
+ `}}customElements.get("auth-login-form")||customElements.define("auth-login-form",Be);function We(r,e){return p`<auth-login-form slot="main"
250
+ api=${r==null?void 0:r.apiBaseUrl}
251
+ @login-success=${e}>
252
+ </auth-login-form>`}function Ge({tokenKey:r}){return window.localStorage.getItem(r)}function Ve({tokenKey:r},e){window.localStorage.setItem(r,e)}function Je({tokenKey:r}){window.localStorage.removeItem(r)}async function Qe(r){const e=Ge(r);if(!e||e.length<1)throw new Error("No token found");return Ke(e)?await N({baseUrl:r.apiBaseUrl}).refreshToken({token:e}).then(({token:s})=>s):e}function Ke(r,e=300,t=Date.now()){return Ye(r).exp*1e3-e<t}function Ye(r){return JSON.parse(window.atob(r.split(".")[1].replace(/-/g,"+").replace(/_/g,"/")))}function Ze(r,e){var n,l,a,d,h,c,m,f,y;const t="mod-auth",s=((a=(l=(n=e==null?void 0:e.element)==null?void 0:n.attributes)==null?void 0:l.debug)==null?void 0:a.value)||!1,o=((c=(h=(d=e==null?void 0:e.element)==null?void 0:d.attributes)==null?void 0:h["force-login"])==null?void 0:c.value)||!1,i={modName:t,toolkit:r,apiBaseUrl:((y=(f=(m=e==null?void 0:e.element)==null?void 0:m.attributes)==null?void 0:f.api)==null?void 0:y.value)||"https://api.wral.com/auth",debug:s?(...L)=>console.log("[auth]",...L):()=>{},tokenKey:`${t}::token`,callbacks:[],isLoginPresent:!1};Object.entries({"auth:requestToken":Xe,"auth:destroy":et}).forEach(([L,pe])=>{const me=(...F)=>i.debug("[action]",L,...F);r.dispatchAction({type:"action:register",detail:{actionType:L,modName:t,handler:(...F)=>{me("handler",...F),pe(i,...F)}}})}),r.dispatchAction({type:"layout:register",detail:{name:`${t}::auth-layout`,templateFn:Le}}),o&&fe.getToken(e.element)}async function Xe(r,e){const{callback:t}=e;let s;try{s=await Qe(r),t(s)}catch(o){console.log("Presenting login form to get a fresh token",o),r.callbacks.push(t),r.isLoginPresent||tt(r)}}function et(r){Je(r)}function tt(r){r.isLoginPresent=!0,r.toolkit.dispatchAction({type:"layout:push",detail:{name:`${r.modName}::auth-layout`}}),r.toolkit.dispatchAction({type:"layout:content:append",detail:{content:We(r,st(r))}})}function st(r){return e=>{const{token:t}=e.detail;Ve(r,t),r.callbacks.forEach(s=>s(t)),r.callbacks=[],r.isLoginPresent=!1,r.toolkit.dispatchAction({type:"layout:pop"})}}exports.init=Ze;