@wral/studio.mods.auth 1.0.0 → 1.0.1
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/bitbucket-pipelines.yml +3 -3
- package/dist/auth.cjs.js +20 -20
- package/dist/auth.es.js +263 -252
- package/package.json +1 -1
- package/vite.config.mjs +1 -1
package/bitbucket-pipelines.yml
CHANGED
|
@@ -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,22 +1,22 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const G=require("./lib.cjs.js");function be(s,e){var o,i;const r=e.element.attributes;return console.log(r),{api:r.api.value||ve("auth:api is required"),forceLogin:r["force-login"]!==void 0,storageKey:(o=r["storage-key"])==null?void 0:o.value,mount:((i=r.path)==null?void 0:i.value)||"/auth",toolkit:s}}function ve(s){throw new Error(s)}function k(s,...e){return(...t)=>s(...e,...t)}/**
|
|
2
2
|
* @license
|
|
3
3
|
* Copyright 2019 Google LLC
|
|
4
4
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
5
|
-
*/const
|
|
5
|
+
*/const F=globalThis,K=F.ShadowRoot&&(F.ShadyCSS===void 0||F.ShadyCSS.nativeShadow)&&"adoptedStyleSheets"in Document.prototype&&"replace"in CSSStyleSheet.prototype,Q=Symbol(),Z=new WeakMap;let ce=class{constructor(e,t,r){if(this._$cssResult$=!0,r!==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 r=t!==void 0&&t.length===1;r&&(e=Z.get(t)),e===void 0&&((this.o=e=new CSSStyleSheet).replaceSync(this.cssText),r&&Z.set(t,e))}return e}toString(){return this.cssText}};const _e=s=>new ce(typeof s=="string"?s:s+"",void 0,Q),q=(s,...e)=>{const t=s.length===1?s[0]:e.reduce((r,o,i)=>r+(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)+s[i+1],s[0]);return new ce(t,s,Q)},Ae=(s,e)=>{if(K)s.adoptedStyleSheets=e.map(t=>t instanceof CSSStyleSheet?t:t.styleSheet);else for(const t of e){const r=document.createElement("style"),o=F.litNonce;o!==void 0&&r.setAttribute("nonce",o),r.textContent=t.cssText,s.appendChild(r)}},X=K?s=>s:s=>s instanceof CSSStyleSheet?(e=>{let t="";for(const r of e.cssRules)t+=r.cssText;return _e(t)})(s):s;/**
|
|
6
6
|
* @license
|
|
7
7
|
* Copyright 2017 Google LLC
|
|
8
8
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
9
|
-
*/const{is:
|
|
9
|
+
*/const{is:Ee,defineProperty:Pe,getOwnPropertyDescriptor:Se,getOwnPropertyNames:Ce,getOwnPropertySymbols:xe,getPrototypeOf:ke}=Object,$=globalThis,ee=$.trustedTypes,Te=ee?ee.emptyScript:"",z=$.reactiveElementPolyfillSupport,U=(s,e)=>s,V={toAttribute(s,e){switch(e){case Boolean:s=s?Te:null;break;case Object:case Array:s=s==null?s:JSON.stringify(s)}return s},fromAttribute(s,e){let t=s;switch(e){case Boolean:t=s!==null;break;case Number:t=s===null?null:Number(s);break;case Object:case Array:try{t=JSON.parse(s)}catch{t=null}}return t}},de=(s,e)=>!Ee(s,e),te={attribute:!0,type:String,converter:V,reflect:!1,hasChanged:de};Symbol.metadata??(Symbol.metadata=Symbol("metadata")),$.litPropertyMetadata??($.litPropertyMetadata=new WeakMap);class P 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=te){if(t.state&&(t.attribute=!1),this._$Ei(),this.elementProperties.set(e,t),!t.noAccessor){const r=Symbol(),o=this.getPropertyDescriptor(e,r,t);o!==void 0&&Pe(this.prototype,e,o)}}static getPropertyDescriptor(e,t,r){const{get:o,set:i}=Se(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,r)},configurable:!0,enumerable:!0}}static getPropertyOptions(e){return this.elementProperties.get(e)??te}static _$Ei(){if(this.hasOwnProperty(U("elementProperties")))return;const e=ke(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,r=[...Ce(t),...xe(t)];for(const o of r)this.createProperty(o,t[o])}const e=this[Symbol.metadata];if(e!==null){const t=litPropertyMetadata.get(e);if(t!==void 0)for(const[r,o]of t)this.elementProperties.set(r,o)}this._$Eh=new Map;for(const[t,r]of this.elementProperties){const o=this._$Eu(t,r);o!==void 0&&this._$Eh.set(o,t)}this.elementStyles=this.finalizeStyles(this.styles)}static finalizeStyles(e){const t=[];if(Array.isArray(e)){const r=new Set(e.flat(1/0).reverse());for(const o of r)t.unshift(X(o))}else e!==void 0&&t.push(X(e));return t}static _$Eu(e,t){const r=t.attribute;return r===!1?void 0:typeof r=="string"?r: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 r of t.keys())this.hasOwnProperty(r)&&(e.set(r,this[r]),delete this[r]);e.size>0&&(this._$Ep=e)}createRenderRoot(){const e=this.shadowRoot??this.attachShadow(this.constructor.shadowRootOptions);return Ae(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 r;return(r=t.hostConnected)==null?void 0:r.call(t)})}enableUpdating(e){}disconnectedCallback(){var e;(e=this._$EO)==null||e.forEach(t=>{var r;return(r=t.hostDisconnected)==null?void 0:r.call(t)})}attributeChangedCallback(e,t,r){this._$AK(e,r)}_$EC(e,t){var i;const r=this.constructor.elementProperties.get(e),o=this.constructor._$Eu(e,r);if(o!==void 0&&r.reflect===!0){const n=(((i=r.converter)==null?void 0:i.toAttribute)!==void 0?r.converter:V).toAttribute(t,r.type);this._$Em=e,n==null?this.removeAttribute(o):this.setAttribute(o,n),this._$Em=null}}_$AK(e,t){var i;const r=this.constructor,o=r._$Eh.get(e);if(o!==void 0&&this._$Em!==o){const n=r.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,r){if(e!==void 0){if(r??(r=this.constructor.getPropertyOptions(e)),!(r.hasChanged??de)(this[e],t))return;this.P(e,t,r)}this.isUpdatePending===!1&&(this._$ES=this._$ET())}P(e,t,r){this._$AL.has(e)||this._$AL.set(e,t),r.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 r;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),(r=this._$EO)==null||r.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(r=>{var o;return(o=r.hostUpdated)==null?void 0:o.call(r)}),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){}}P.elementStyles=[],P.shadowRootOptions={mode:"open"},P[U("elementProperties")]=new Map,P[U("finalized")]=new Map,z==null||z({ReactiveElement:P}),($.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,
|
|
14
|
-
\f\r]`,T=/<(?:(!--|\/[^a-zA-Z])|(\/?[a-zA-Z][^>\s]*)|(\/?$))/g,
|
|
15
|
-
\f\r"'\`<>=]|("|')|))|$)`,"g"),
|
|
13
|
+
*/const R=globalThis,M=R.trustedTypes,re=M?M.createPolicy("lit-html",{createHTML:s=>s}):void 0,he="$lit$",w=`lit$${Math.random().toFixed(9).slice(2)}$`,ue="?"+w,Ue=`<${ue}>`,A=document,O=()=>A.createComment(""),N=s=>s===null||typeof s!="object"&&typeof s!="function",J=Array.isArray,Re=s=>J(s)||typeof(s==null?void 0:s[Symbol.iterator])=="function",j=`[
|
|
14
|
+
\f\r]`,T=/<(?:(!--|\/[^a-zA-Z])|(\/?[a-zA-Z][^>\s]*)|(\/?$))/g,se=/-->/g,oe=/>/g,v=RegExp(`>|${j}(?:([^\\s"'>=/]+)(${j}*=${j}*(?:[^
|
|
15
|
+
\f\r"'\`<>=]|("|')|))|$)`,"g"),ie=/'/g,ne=/"/g,pe=/^(?:script|style|textarea|title)$/i,Oe=s=>(e,...t)=>({_$litType$:s,strings:e,values:t}),c=Oe(1),S=Symbol.for("lit-noChange"),p=Symbol.for("lit-nothing"),ae=new WeakMap,_=A.createTreeWalker(A,129);function me(s,e){if(!J(s)||!s.hasOwnProperty("raw"))throw Error("invalid template strings array");return re!==void 0?re.createHTML(e):e}const Ne=(s,e)=>{const t=s.length-1,r=[];let o,i=e===2?"<svg>":e===3?"<math>":"",n=T;for(let l=0;l<t;l++){const a=s[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=se:d[1]!==void 0?n=oe:d[2]!==void 0?(pe.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]==='"'?ne:ie):n===ne||n===ie?n=v:n===se||n===oe?n=T:(n=v,o=void 0);const f=n===v&&s[l+1].startsWith("/>")?" ":"";i+=n===T?a+Ue:h>=0?(r.push(u),a.slice(0,h)+he+a.slice(h)+w+f):a+w+(h===-2?l:f)}return[me(s,i+(s[t]||"<?>")+(e===2?"</svg>":e===3?"</math>":"")),r]};class H{constructor({strings:e,_$litType$:t},r){let o;this.parts=[];let i=0,n=0;const l=e.length-1,a=this.parts,[u,d]=Ne(e,t);if(this.el=H.createElement(u,r),_.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(he)){const m=d[n++],f=o.getAttribute(h).split(w),L=/([.?@])?(.*)/.exec(m);a.push({type:1,index:i,name:L[2],strings:f,ctor:L[1]==="."?qe:L[1]==="?"?De:L[1]==="@"?Le:I}),o.removeAttribute(h)}else h.startsWith(w)&&(a.push({type:6,index:i}),o.removeAttribute(h));if(pe.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===ue)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 r=A.createElement("template");return r.innerHTML=e,r}}function C(s,e,t=s,r){var n,l;if(e===S)return e;let o=r!==void 0?(n=t._$Co)==null?void 0:n[r]: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(s),o._$AT(s,t,r)),r!==void 0?(t._$Co??(t._$Co=[]))[r]=o:t._$Cl=o),o!==void 0&&(e=C(s,o._$AS(s,e.values),o,r)),e}class He{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:r}=this._$AD,o=((e==null?void 0:e.creationScope)??A).importNode(t,!0);_.currentNode=o;let i=_.nextNode(),n=0,l=0,a=r[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 Fe(i,this,e)),this._$AV.push(u),a=r[++l]}n!==(a==null?void 0:a.index)&&(i=_.nextNode(),n++)}return _.currentNode=A,o}p(e){let t=0;for(const r of this._$AV)r!==void 0&&(r.strings!==void 0?(r._$AI(e,r,t),t+=r.strings.length-2):r._$AI(e[t])),t++}}class D{get _$AU(){var e;return((e=this._$AM)==null?void 0:e._$AU)??this._$Cv}constructor(e,t,r,o){this.type=2,this._$AH=p,this._$AN=void 0,this._$AA=e,this._$AB=t,this._$AM=r,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):Re(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$:r}=e,o=typeof r=="number"?this._$AC(e):(r.el===void 0&&(r.el=H.createElement(me(r.h,r.h[0]),this.options)),r);if(((i=this._$AH)==null?void 0:i._$AD)===o)this._$AH.p(t);else{const n=new He(o,this),l=n.u(this.options);n.p(t),this.T(l),this._$AH=n}}_$AC(e){let t=ae.get(e.strings);return t===void 0&&ae.set(e.strings,t=new H(e)),t}k(e){J(this._$AH)||(this._$AH=[],this._$AR());const t=this._$AH;let r,o=0;for(const i of e)o===t.length?t.push(r=new D(this.O(O()),this.O(O()),this,this.options)):r=t[o],r._$AI(i),o++;o<t.length&&(this._$AR(r&&r._$AB.nextSibling,o),t.length=o)}_$AR(e=this._$AA.nextSibling,t){var r;for((r=this._$AP)==null?void 0:r.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,r,o,i){this.type=1,this._$AH=p,this._$AN=void 0,this.element=e,this.name=t,this._$AM=o,this.options=i,r.length>2||r[0]!==""||r[1]!==""?(this._$AH=Array(r.length-1).fill(new String),this.strings=r):this._$AH=p}_$AI(e,t=this,r,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[r+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 qe extends I{constructor(){super(...arguments),this.type=3}j(e){this.element[this.name]=e===p?void 0:e}}class De extends I{constructor(){super(...arguments),this.type=4}j(e){this.element.toggleAttribute(this.name,!!e&&e!==p)}}class Le extends I{constructor(e,t,r,o,i){super(e,t,r,o,i),this.type=5}_$AI(e,t=this){if((e=C(this,e,t,0)??p)===S)return;const r=this._$AH,o=e===p&&r!==p||e.capture!==r.capture||e.once!==r.once||e.passive!==r.passive,i=e!==p&&(r===p||o);o&&this.element.removeEventListener(this.name,this,r),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 Fe{constructor(e,t,r){this.element=e,this.type=6,this._$AN=void 0,this._$AM=t,this.options=r}get _$AU(){return this._$AM._$AU}_$AI(e){C(this,e)}}const W=R.litHtmlPolyfillSupport;W==null||W(H,D),(R.litHtmlVersions??(R.litHtmlVersions=[])).push("3.2.1");const Me=(s,e,t)=>{const r=(t==null?void 0:t.renderBefore)??e;let o=r._$litPart$;if(o===void 0){const i=(t==null?void 0:t.renderBefore)??null;r._$litPart$=o=new D(e.insertBefore(O(),i),i,void 0,t??{})}return o._$AI(s),o};/**
|
|
16
16
|
* @license
|
|
17
17
|
* Copyright 2017 Google LLC
|
|
18
18
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
19
|
-
*/class b extends
|
|
19
|
+
*/class b extends P{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=Me(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 le;b._$litElement$=!0,b.finalized=!0,(le=globalThis.litElementHydrateSupport)==null||le.call(globalThis,{LitElement:b});const B=globalThis.litElementPolyfillSupport;B==null||B({LitElement:b});(globalThis.litElementVersions??(globalThis.litElementVersions=[])).push("4.1.1");function x(s){return{api:(e,t)=>E(s,e,t),mintToken:({username:e,password:t})=>Ie({config:s,username:e,password:t}),refreshToken:({token:e})=>ze({config:s,token:e}),pubkey:()=>je({config:s}),updatePassword:({token:e,currentPassword:t,newPassword:r})=>We({config:s,token:e,currentPassword:t,newPassword:r}),triggerResetPassword:({username:e})=>Be({config:s,username:e}),confirmResetPassword:({username:e,newPassword:t,confirmationCode:r})=>Ge({config:s,username:e,newPassword:t,confirmationCode:r})}}function Ie({config:s,username:e,password:t}){return E(s,"/v1/user/login",{method:"POST",body:{username:e,password:t}})}function ze({config:s,token:e}){return E(s,"/v1/refresh",{method:"POST",body:{token:e}})}function je({config:s}){return E(s,"/v1/pubkey",{method:"GET"})}function We({config:s,token:e,currentPassword:t,newPassword:r}){return E(s,"/v1/user/password",{method:"PUT",body:{currentPassword:t,newPassword:r},headers:{Authorization:`Bearer ${e}`}})}function Be({config:s,username:e}){return E(s,"/v1/user/password/reset",{method:"POST",body:{username:e}})}function Ge({config:s,username:e,newPassword:t,confirmationCode:r}){return E(s,"/v1/user/password/reset/confirm",{method:"POST",body:{username:e,newPassword:t,confirmationCode:r}})}async function E(s,e,t){var u;const r=s.baseUrl.endsWith("/")?s.baseUrl:`${s.baseUrl}/`,o=e.startsWith("/")?e.substring(1):e,i=new URL(o,r),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 fe({api:s},e){const t=x({baseUrl:s});return console.log("sending credentials to API",s),t.mintToken(e)}const g=Object.freeze({REQUEST:"request",CONFIRM:"confirm",FINISHED:"finished"});class Ve extends b{static get properties(){return{api:{type:String,attribute:"api"},confirmation:{type:"String",attribute:"confirmation"}}}static get styles(){return q`
|
|
20
20
|
:host {
|
|
21
21
|
display: block;
|
|
22
22
|
font-family: Arial, sans-serif;
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
color: var(--color-danger, red);
|
|
54
54
|
font-size: 12px;
|
|
55
55
|
}
|
|
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,
|
|
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,r=e.target["confirm-password"].value;if(t!==r){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(()=>fe(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
57
|
resetting your password.</p>`;case g.REQUEST:default:return this.renderRequestForm()}}renderRequestForm(){return c`<form @submit=${this.handleSubmitRequest}>
|
|
58
58
|
<label for="username">Username/Email</label>
|
|
59
59
|
<input
|
|
@@ -165,7 +165,7 @@
|
|
|
165
165
|
font-weight: bold;
|
|
166
166
|
font-style: normal;
|
|
167
167
|
}
|
|
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
|
|
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 r=new FormData(t).entries().reduce((o,[i,n])=>(o[i]=n,o),{});fe(this,r).then(({token:o,challenge:i})=>{if(i&&i.name==="NEW_PASSWORD_REQUIRED"){this.token=o,this.username=r.username,this.password=r.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,r=new FormData(t).entries().reduce((l,[a,u])=>(l[a]=u,l),{}),o=r.password,i=r["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">
|
|
169
169
|
${this.renderHeader()}
|
|
170
170
|
${this.formState===y.states.FORGOT?this.renderForgotPasswordForm():""}
|
|
171
171
|
${this.formState===y.states.CHALLENGE_CHANGE_PW?this.renderChangePasswordForm():""}
|
|
@@ -228,7 +228,7 @@
|
|
|
228
228
|
${this.errors?this.errors.map(e=>c`<p class="error">${e}</p>`):""}
|
|
229
229
|
<input type="submit" value="Change Password" />
|
|
230
230
|
</form>
|
|
231
|
-
`}}customElements.define("auth-login-form",y);customElements.define("auth-forgot-password-form",
|
|
231
|
+
`}}customElements.define("auth-login-form",y);customElements.define("auth-forgot-password-form",Ve);function Ke(){return function(s){const e=q`
|
|
232
232
|
.login-layout {
|
|
233
233
|
display: flex;
|
|
234
234
|
flex-direction: column;
|
|
@@ -244,17 +244,17 @@
|
|
|
244
244
|
`;return c`
|
|
245
245
|
<style>${e}</style>
|
|
246
246
|
<div class="login-layout">
|
|
247
|
-
${
|
|
247
|
+
${s.main}
|
|
248
248
|
</div>
|
|
249
|
-
`}}function
|
|
249
|
+
`}}function Qe(s){return JSON.parse(window.atob(s.split(".")[1].replace(/-/g,"+").replace(/_/g,"/")))}function Je(s,e=300,t=Date.now()){return Qe(s).exp*1e3-e<t}function ge(s){return(s.startsWith("/")?s:`/${s}`).replace(/\/{2,}/g,"/").replace(new RegExp("(?<=.)\\/$"),"")}function ye(s,e,t){const r=Ze(s,t);e.pushState(t,t.title,r),s.requestRender(t)}function Ye(s,e){const{mount:t}=s.config,{history:r}=s.config.toolkit.element.ownerDocument.defaultView;return e.startsWith(t)?{path:ge(e.slice(t.length)),push:o=>ye(s,r,o)}:null}function Ze(s,e){const{mount:t}=s.config;return ge(`${t}/${e.path}`)}function Xe(s,e){const{history:t}=e.config.toolkit.element.ownerDocument.defaultView;return c`
|
|
250
250
|
<h1>Auth Dashboard</h1>
|
|
251
251
|
<ul>
|
|
252
|
-
<li><a href="#" @click=${((o,i)=>()=>{
|
|
252
|
+
<li><a href="#" @click=${((o,i)=>()=>{ye(e,t,{path:o,title:i})})("/change-password")}>Change Password</a></li>
|
|
253
253
|
<li><a href="#" @click=${e.handleDestroyAuth}>Logout</a></li>
|
|
254
254
|
</ul>
|
|
255
|
-
`}function
|
|
255
|
+
`}function et(s,e){return c`
|
|
256
256
|
<auth-change-password-form .auth=${e}></auth-change-password-form>
|
|
257
|
-
`}class
|
|
257
|
+
`}class tt extends b{static get styles(){return q`
|
|
258
258
|
:host {
|
|
259
259
|
color: var(--color-text);
|
|
260
260
|
display: block;
|
|
@@ -289,7 +289,7 @@
|
|
|
289
289
|
.error {
|
|
290
290
|
color: var(--color-error);
|
|
291
291
|
}
|
|
292
|
-
`}static get properties(){return{auth:{type:Object}}}constructor(){super(),this.errors={},this.success=null}connectedCallback(){super.connectedCallback(),
|
|
292
|
+
`}static get properties(){return{auth:{type:Object}}}constructor(){super(),this.errors={},this.success=null}connectedCallback(){super.connectedCallback(),G.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 G.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(r=>{this.errors.submit=r.message,this.requestUpdate()})}render(){return c`
|
|
293
293
|
<h1>Change your password</h1>
|
|
294
294
|
<p>Enter your current password and choose a new password.</p>
|
|
295
295
|
<form @submit=${this.onSubmit}>
|
|
@@ -327,12 +327,12 @@
|
|
|
327
327
|
${this.errors.submit?c`<p class="error">${this.errors.submit}</p>`:""}
|
|
328
328
|
${this.success?c`<p class="success">${this.success}</p>`:""}
|
|
329
329
|
</form>
|
|
330
|
-
`}}customElements.get("auth-change-password-form")||customElements.define("auth-change-password-form",
|
|
330
|
+
`}}customElements.get("auth-change-password-form")||customElements.define("auth-change-password-form",tt);const rt=[{path:"/",render:Xe},{path:"/change-password",render:et}];function st(s,e){const{path:t}=s,r=rt.find(o=>o.path===t);if(r)return r.render(s,e)}const ot=q`
|
|
331
331
|
:host {
|
|
332
332
|
|
|
333
333
|
}
|
|
334
|
-
`;class
|
|
335
|
-
api=${
|
|
334
|
+
`;class it extends b{static get styles(){return[ot]}static get properties(){return{state:{type:Object},auth:{type:Object}}}render(){const{state:e,auth:t}=this;return st(e,t)}}customElements.get("auth-app")||customElements.define("auth-app",it);function nt(s){const e={config:s,log:(...t)=>console.log("[auth]",...t)};return e.mount=k(at,e),e.handleTokenRequest=ct(e),e.handleDestroyAuth=dt(e),e.presentLoginForm=k(ht,e),e.getToken=k($e,e),e.saveToken=k(ut,e),e.getFreshToken=k(pt,e),e.requestRender=t=>we(e,t),e}function at(s){const e=s.config.toolkit.element.ownerDocument.defaultView;[{type:"action:register",detail:{actionType:"auth:requestToken",handler:s.handleTokenRequest,modName:"auth"}},{type:"action:register",detail:{actionType:"auth:destroy",handler:s.handleDestroyAuth,modName:"auth"}},{type:"layout:register",detail:{name:"auth:login",slots:["main"],templateFn:Ke()}}].forEach(t=>s.config.toolkit.dispatchAction(t)),e.addEventListener("popstate",lt(s))}function we(s,e){const t=s.config.toolkit.element.ownerDocument.defaultView;let r=e;r||(r=Ye(s,t.location.pathname)),r&&s.config.toolkit.dispatchAction({type:"layout:slot:replace",detail:{layout:"menu-main-task-layout",slot:"main",content:c`<auth-app .state=${r} .auth=${s}></auth-app>`}})}function lt(s){return e=>{s.log("onpopstate",e),we(s)}}function ct(s){let e=[],t=!1;const r=o=>{e.forEach(i=>{i(o)}),e=[]};return async({callback:o})=>{let i;try{i=await s.getFreshToken(),o(i)}catch(n){e.push(o),t||(s.presentLoginForm({onLogin:r}),t=!0),s.log(n)}}}function dt(s){return()=>{const e=Y(s);window.localStorage.removeItem(e),s.config.toolkit.dispatchAction({type:"layout:pop"})}}function ht(s,{onLogin:e}){const{toolkit:t}=s.config,o=new URLSearchParams(t.element.ownerDocument.defaultView.location.search).get("password_reset_confirmation"),i=n=>{s.log("login success",{event:n});const{token:l}=n.detail;s.log("Login form dismissed",{args:[l]}),t.dispatchAction({type:"layout:pop"}),s.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=${s.config.api}
|
|
336
336
|
confirmation="${o}"
|
|
337
337
|
@login-success=${i}>
|
|
338
|
-
</auth-login-form>`}})}function
|
|
338
|
+
</auth-login-form>`}})}function ut(s,{token:e}){s.log("saving token",{args:[e]});const t=Y(s);window.localStorage.setItem(t,e)}function $e(s){const e=Y(s);return window.localStorage.getItem(e)}async function pt(s){const e=$e(s);if(!e||e.length<1)throw new Error("No token found");return Je(e)?(s.log("refreshing token",{args:[e]}),await x({baseUrl:s.config.api}).refreshToken({token:e}).then(({token:r})=>r)):e}function Y({storageKey:s="token"}){return s}function mt(s,e){const t=be(s,e),r=nt(t);r.mount(),r.requestRender(),t.forceLogin&&G.getToken(s.element).then(o=>{r.log("You have logged in successfully!",o)})}exports.init=mt;
|