@descope/user-profile-widget 0.4.35 → 0.5.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/dist/esm/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
 
2
2
  /**
3
- * @descope/user-profile-widget v0.4.35
3
+ * @descope/user-profile-widget v0.5.0
4
4
  */
5
- import{__awaiter as t,__classPrivateFieldGet as e,__classPrivateFieldSet as i}from"tslib";import{createTemplate as s,kebabCase as o,createSingletonMixin as r,compose as a,withMemCache as h}from"@descope/sdk-helpers";import{projectIdMixin as n,observeAttributesMixin as d,loggerMixin as l,baseUrlMixin as c,cookieConfigMixin as u,createStateManagementMixin as f,initLifecycleMixin as v,modalMixin as g,themeMixin as p,staticResourcesMixin as m,createValidateAttributesMixin as w,descopeUiMixin as b,initElementMixin as U,debuggerMixin as y}from"@descope/sdk-mixins";import{FlowDriver as k,AvatarDriver as C,UserAttributeDriver as R,ButtonDriver as S,UserAuthMethodDriver as W}from"@descope/sdk-component-drivers";import{createAsyncThunk as M}from"@reduxjs/toolkit";import"@descope/core-js-sdk";import I from"@descope/web-js-sdk";import{createSelector as A}from"reselect";import"@descope/web-component";const j=(t={})=>{const e=s("<descope-wc></descope-wc>");return Object.entries(t).forEach((([t,i])=>{e.content.querySelector("descope-wc").setAttribute(o(t),i)})),e};function N(t){return new URLSearchParams(window.location.search).get(t)}const x=t=>(...e)=>i=>{i.addCase(t.pending,((t,i)=>{e.forEach((({onPending:e})=>{null==e||e(t,i)}))})),i.addCase(t.fulfilled,((t,i)=>{e.forEach((({onFulfilled:e})=>{null==e||e(t,i)}))})),i.addCase(t.rejected,((t,i)=>{e.forEach((({onRejected:e})=>{null==e||e(t,i)}))}))},T=M("users/me",((t,{extra:{api:e}})=>e.user.me())),F=x(T)({onFulfilled:(t,e)=>{t.me.data=e.payload}},(E=t=>t.me,{onFulfilled:t=>{E(t).loading=!1},onPending:t=>{E(t).loading=!0,E(t).error=null},onRejected:(t,e)=>{E(t).loading=!1,E(t).error=e.error}}));var E;const O={action:T,reducer:F},q=M("users/logout",((t,{extra:{api:e}})=>e.user.logout())),P={action:q,reducer:x(q)({})},L={me:{loading:!1,error:null,data:{}}},D={me:"/v1/auth/me"},$=()=>t(void 0,void 0,void 0,(function*(){return new Promise((t=>{t({loginIds:["user@company.com"],externalIds:["user@company.com"],userId:"user-1",name:"Test User",email:"user@company.com",roleNames:["Role"],phone:"+1-202-555-010",verifiedEmail:!0,verifiedPhone:!0,userTenants:[],status:"enabled",editable:!0,createdTime:(new Date).getTime(),customAttributes:{},familyName:"",givenName:"",middleName:"",picture:void 0,password:!0,SAML:!1,test:!1,TOTP:!1,webauthn:!0})}))})),B=({httpClient:e,mock:i})=>({me:()=>t(void 0,void 0,void 0,(function*(){if(i)return $();const s=yield e.get(D.me);return yield(e=>t(void 0,void 0,void 0,(function*(){const t=yield e.text(),i=JSON.parse(t);if(!e.ok){const t=`${i.errorDescription}${i.errorMessage?`: ${i.errorMessage}`:""}`;throw Error(t||`${e.status} ${e.statusText}`)}e.json=()=>Promise.resolve(i),e.text=()=>Promise.resolve(t)})))(s),s.json()}))}),H=r((s=>{var o,r,h,f;const v=a(n,d,l,c,u)(s);return f=class extends v{constructor(){super(...arguments),o.add(this),r.set(this,void 0)}get widgetId(){return this.getAttribute("widget-id")}get mock(){return this.getAttribute("mock")}get api(){return e(this,r,"f")||e(this,o,"m",h).call(this),e(this,r,"f")}init(){const i=Object.create(null,{init:{get:()=>super.init}});return t(this,void 0,void 0,(function*(){var t;yield null===(t=i.init)||void 0===t?void 0:t.call(this),this.observeAttributes(["project-id","base-url"],(()=>{e(this,r,"f")&&e(this,o,"m",h).call(this)}))}))}},r=new WeakMap,o=new WeakSet,h=function(){this.logger.debug("creating an sdk instance"),i(this,r,((e,i,s)=>{const o=I(Object.assign(Object.assign({},e),{persistTokens:!0,baseHeaders:{"x-descope-widget-type":"user-profile-widget","x-descope-widget-id":s,"x-descope-widget-version":"0.4.35"}}));return{user:Object.assign(Object.assign({},B({httpClient:o.httpClient,mock:i})),{logout:i?()=>t(void 0,void 0,void 0,(function*(){})):o.logout})}})({projectId:this.projectId,baseUrl:this.baseUrl,refreshCookieName:this.refreshCookieName},"true"===this.mock,this.widgetId),"f")},f})),V=r((t=>{const e=a(f({name:"widget",initialState:L,reducers:{},extraReducers:t=>{O.reducer(t),P.reducer(t)},asyncActions:{getMe:O.action,logout:P.action}}),v,l,H)(t);return class extends e{constructor(...t){super(...t),this.state=L,this.subscribe((t=>{this.logger.debug("State update:",t),this.state=t}))}}})),X="widget-flow",G=r((i=>{var s,o,r;return r=class extends(a(v,g,V,u,l,p)(i)){constructor(){super(...arguments),s.add(this)}init(){const i=Object.create(null,{init:{get:()=>super.init}});return t(this,void 0,void 0,(function*(){var t;yield null===(t=i.init)||void 0===t?void 0:t.call(this);const r=N(X);r&&(!function(t){if(window.history.replaceState&&N(t)){const e=new URL(window.location.href),i=new URLSearchParams(e.search);i.delete(t),e.search=i.toString(),window.history.replaceState({},"",e.toString())}}(X),e(this,s,"m",o).call(this,r))}))}},s=new WeakSet,o=function(t){const e=this.createModal({"data-id":"redirect-flow"});e.setContent(j({projectId:this.projectId,flowId:t,baseUrl:this.baseUrl,baseStaticUrl:this.baseStaticUrl,baseCdnUrl:this.baseCdnUrl,refreshCookieName:this.refreshCookieName,theme:this.theme}));new k((()=>{var t;return null===(t=e.ele)||void 0===t?void 0:t.querySelector("descope-wc")}),{logger:this.logger}).onSuccess((()=>{e.close(),this.actions.getMe()})),e.afterClose=()=>{e.remove()},e.open()},r})),J=t=>t.me.data,Y=A(J,(t=>t.picture)),_=A(J,(t=>t.email)),z=A(J,(t=>t.verifiedEmail)),K=A(J,(t=>t.name)),Q=A(J,(t=>t.phone)),Z=A(J,(t=>t.verifiedPhone)),tt=A(J,(t=>t.webauthn));A(J,(t=>t.password));const et=A(J,(t=>t.TOTP)),it=A(J,(t=>t.customAttributes)),st=r((e=>{const i=a(m,w({"widget-id":w.missingAttrValidator}))(e);return class extends i{get widgetId(){return this.getAttribute("widget-id")}fetchWidgetPage(e){return t(this,void 0,void 0,(function*(){return(yield this.fetchStaticResource(`user-profile-widget/${this.widgetId}/${e}`,"text")).body}))}}})),ot=r((i=>{var o,r,h;return h=class extends(a(l,v,b,U,st,V)(i)){constructor(){super(...arguments),o.add(this)}onWidgetRootReady(){return t(this,void 0,void 0,(function*(){}))}init(){const i=Object.create(null,{init:{get:()=>super.init}});return t(this,void 0,void 0,(function*(){var t;yield null===(t=i.init)||void 0===t?void 0:t.call(this),yield Promise.all([this.actions.getMe(),e(this,o,"m",r).call(this)]),this.onWidgetRootReady()}))}},o=new WeakSet,r=function(){return t(this,void 0,void 0,(function*(){const t=s(yield this.fetchWidgetPage("root.html"));yield this.loadDescopeUiComponents(t),this.contentRootElement.append(t.content.cloneNode(!0))}))},h})),rt=r((t=>class extends(a(p,d)(t)){syncFlowTheme(t){t.theme=this.theme,this.observeAttributes(["theme"],(()=>{t.theme=this.theme}))}})),at=r((s=>{var o,r,n,d,c,f,v,m,w;return w=class extends(a(rt,p,V,l,u,ot,g)(s)){constructor(){super(...arguments),o.add(this),r.set(this,void 0),n.set(this,void 0),v.set(this,h((t=>{this.avatar.image=t}))),m.set(this,h((t=>{this.avatar.displayName=t})))}onWidgetRootReady(){const i=Object.create(null,{onWidgetRootReady:{get:()=>super.onWidgetRootReady}});return t(this,void 0,void 0,(function*(){var t;yield null===(t=i.onWidgetRootReady)||void 0===t?void 0:t.call(this),e(this,o,"m",f).call(this),e(this,o,"m",d).call(this),e(this,v,"f").call(this,Y(this.state)),e(this,m,"f").call(this,K(this.state)),this.subscribe(e(this,v,"f").bind(this),Y),this.subscribe(e(this,m,"f").bind(this),K)}))}},r=new WeakMap,n=new WeakMap,v=new WeakMap,m=new WeakMap,o=new WeakSet,d=function(){this.avatar.flowId&&(i(this,r,this.createModal({"data-id":"update-pic"}),"f"),i(this,n,new k((()=>{var t;return null===(t=e(this,r,"f").ele)||void 0===t?void 0:t.querySelector("descope-wc")}),{logger:this.logger}),"f"),e(this,r,"f").afterClose=e(this,o,"m",c).bind(this),e(this,o,"m",c).call(this),this.syncFlowTheme(e(this,n,"f")))},c=function(){e(this,r,"f").setContent(j({projectId:this.projectId,flowId:this.avatar.flowId,baseUrl:this.baseUrl,baseStaticUrl:this.baseStaticUrl,baseCdnUrl:this.baseCdnUrl,refreshCookieName:this.refreshCookieName,theme:this.theme})),e(this,n,"f").onSuccess((()=>{e(this,r,"f").close(),this.actions.getMe()}))},f=function(){this.avatar=new C((()=>{var t;return null===(t=this.shadowRoot)||void 0===t?void 0:t.querySelector("descope-avatar")}),{logger:this.logger}),this.avatar.onClick((()=>{var t;null===(t=e(this,r,"f"))||void 0===t||t.open()}))},w})),ht=r((s=>{var o,r,n,d,c,f,v,p,m,w,b,U,y;return y=class extends(a(rt,V,l,ot,u,g)(s)){constructor(){super(...arguments),o.add(this),r.set(this,void 0),n.set(this,void 0),d.set(this,void 0),c.set(this,void 0),b.set(this,h((t=>{this.emailUserAttr.value=t}))),U.set(this,h((t=>{this.emailUserAttr.badgeLabel=t?"":"Unverified"})))}onWidgetRootReady(){const i=Object.create(null,{onWidgetRootReady:{get:()=>super.onWidgetRootReady}});return t(this,void 0,void 0,(function*(){var t;yield null===(t=i.onWidgetRootReady)||void 0===t?void 0:t.call(this),e(this,o,"m",w).call(this),e(this,o,"m",f).call(this),e(this,o,"m",p).call(this),e(this,b,"f").call(this,_(this.state)),e(this,U,"f").call(this,z(this.state)),this.subscribe(e(this,b,"f").bind(this),_),this.subscribe(e(this,U,"f").bind(this),z)}))}},r=new WeakMap,n=new WeakMap,d=new WeakMap,c=new WeakMap,b=new WeakMap,U=new WeakMap,o=new WeakSet,f=function(){this.emailUserAttr.editFlowId&&(i(this,r,this.createModal({"data-id":"edit-email"}),"f"),i(this,n,new k((()=>{var t;return null===(t=e(this,r,"f").ele)||void 0===t?void 0:t.querySelector("descope-wc")}),{logger:this.logger}),"f"),e(this,r,"f").afterClose=e(this,o,"m",v).bind(this),e(this,o,"m",v).call(this),this.syncFlowTheme(e(this,n,"f")))},v=function(){e(this,r,"f").setContent(j({projectId:this.projectId,flowId:this.emailUserAttr.editFlowId,baseUrl:this.baseUrl,baseStaticUrl:this.baseStaticUrl,baseCdnUrl:this.baseCdnUrl,refreshCookieName:this.refreshCookieName,theme:this.theme})),e(this,n,"f").onSuccess((()=>{e(this,r,"f").close(),this.actions.getMe()}))},p=function(){this.emailUserAttr.deleteFlowId&&(i(this,d,this.createModal({"data-id":"delete-email"}),"f"),i(this,c,new k((()=>{var t;return null===(t=e(this,d,"f").ele)||void 0===t?void 0:t.querySelector("descope-wc")}),{logger:this.logger}),"f"),e(this,d,"f").afterClose=e(this,o,"m",m).bind(this),e(this,o,"m",m).call(this),this.syncFlowTheme(e(this,c,"f")))},m=function(){e(this,d,"f").setContent(j({projectId:this.projectId,flowId:this.emailUserAttr.deleteFlowId,baseUrl:this.baseUrl,baseStaticUrl:this.baseStaticUrl,baseCdnUrl:this.baseCdnUrl,refreshCookieName:this.refreshCookieName,theme:this.theme})),e(this,c,"f").onSuccess((()=>{e(this,d,"f").close(),this.actions.getMe()}))},w=function(){this.emailUserAttr=new R((()=>{var t;return null===(t=this.shadowRoot)||void 0===t?void 0:t.querySelector('descope-user-attribute[data-id="email"]')}),{logger:this.logger}),this.emailUserAttr.onEditClick((()=>{var t;null===(t=e(this,r,"f"))||void 0===t||t.open()})),this.emailUserAttr.onDeleteClick((()=>{var t;null===(t=e(this,d,"f"))||void 0===t||t.open()}))},y})),nt=r((i=>{var s,o,r;return r=class extends(a(V,l,ot,g)(i)){constructor(){super(...arguments),s.add(this)}onWidgetRootReady(){const i=Object.create(null,{onWidgetRootReady:{get:()=>super.onWidgetRootReady}});return t(this,void 0,void 0,(function*(){var t;yield null===(t=i.onWidgetRootReady)||void 0===t?void 0:t.call(this),e(this,s,"m",o).call(this)}))}},s=new WeakSet,o=function(){this.logout=new S((()=>{var t;return null===(t=this.shadowRoot)||void 0===t?void 0:t.querySelector('descope-button[data-id="logout"]')}),{logger:this.logger}),this.logout.onClick((()=>t(this,void 0,void 0,(function*(){yield this.actions.logout(),this.dispatchEvent(new CustomEvent("logout"))}))))},r})),dt=r((s=>{var o,r,n,d,c,f,v,p,m,w,b,U;return U=class extends(a(rt,V,l,ot,u,g)(s)){constructor(){super(...arguments),o.add(this),r.set(this,void 0),n.set(this,void 0),d.set(this,void 0),c.set(this,void 0),b.set(this,h((t=>{this.nameUserAttr.value=t})))}onWidgetRootReady(){const i=Object.create(null,{onWidgetRootReady:{get:()=>super.onWidgetRootReady}});return t(this,void 0,void 0,(function*(){var t;yield null===(t=i.onWidgetRootReady)||void 0===t?void 0:t.call(this),e(this,o,"m",w).call(this),e(this,o,"m",f).call(this),e(this,o,"m",p).call(this),e(this,b,"f").call(this,K(this.state)),this.subscribe(e(this,b,"f").bind(this),K)}))}},r=new WeakMap,n=new WeakMap,d=new WeakMap,c=new WeakMap,b=new WeakMap,o=new WeakSet,f=function(){this.nameUserAttr.editFlowId&&(i(this,r,this.createModal({"data-id":"edit-name"}),"f"),i(this,n,new k((()=>{var t;return null===(t=e(this,r,"f").ele)||void 0===t?void 0:t.querySelector("descope-wc")}),{logger:this.logger}),"f"),e(this,r,"f").afterClose=e(this,o,"m",v).bind(this),e(this,o,"m",v).call(this),this.syncFlowTheme(e(this,n,"f")))},v=function(){e(this,r,"f").setContent(j({projectId:this.projectId,flowId:this.nameUserAttr.editFlowId,baseUrl:this.baseUrl,baseStaticUrl:this.baseStaticUrl,baseCdnUrl:this.baseCdnUrl,refreshCookieName:this.refreshCookieName,theme:this.theme})),e(this,n,"f").onSuccess((()=>{e(this,r,"f").close(),this.actions.getMe()}))},p=function(){this.nameUserAttr.deleteFlowId&&(i(this,d,this.createModal({"data-id":"delete-name"}),"f"),i(this,c,new k((()=>{var t;return null===(t=e(this,d,"f").ele)||void 0===t?void 0:t.querySelector("descope-wc")}),{logger:this.logger}),"f"),e(this,d,"f").afterClose=e(this,o,"m",m).bind(this),e(this,o,"m",m).call(this),this.syncFlowTheme(e(this,c,"f")))},m=function(){e(this,d,"f").setContent(j({projectId:this.projectId,flowId:this.nameUserAttr.deleteFlowId,baseUrl:this.baseUrl,baseStaticUrl:this.baseStaticUrl,baseCdnUrl:this.baseCdnUrl,refreshCookieName:this.refreshCookieName,theme:this.theme})),e(this,c,"f").onSuccess((()=>{e(this,d,"f").close(),this.actions.getMe()}))},w=function(){this.nameUserAttr=new R((()=>{var t;return null===(t=this.shadowRoot)||void 0===t?void 0:t.querySelector('descope-user-attribute[data-id="name"]')}),{logger:this.logger}),this.nameUserAttr.onEditClick((()=>{var t;null===(t=e(this,r,"f"))||void 0===t||t.open()})),this.nameUserAttr.onDeleteClick((()=>{var t;null===(t=e(this,d,"f"))||void 0===t||t.open()}))},U})),lt=r((s=>{var o,r,n,d,c,f,v,p;return p=class extends(a(rt,V,l,ot,u,g)(s)){constructor(){super(...arguments),o.add(this),r.set(this,void 0),n.set(this,void 0),v.set(this,h((t=>{this.passkeyUserAuthMethod.fulfilled=t})))}onWidgetRootReady(){const i=Object.create(null,{onWidgetRootReady:{get:()=>super.onWidgetRootReady}});return t(this,void 0,void 0,(function*(){var t;yield null===(t=i.onWidgetRootReady)||void 0===t?void 0:t.call(this),e(this,o,"m",f).call(this),e(this,o,"m",d).call(this),e(this,v,"f").call(this,tt(this.state)),this.subscribe(e(this,v,"f").bind(this),tt)}))}},r=new WeakMap,n=new WeakMap,v=new WeakMap,o=new WeakSet,d=function(){this.passkeyUserAuthMethod.flowId&&(i(this,r,this.createModal({"data-id":"passkey"}),"f"),i(this,n,new k((()=>{var t;return null===(t=e(this,r,"f").ele)||void 0===t?void 0:t.querySelector("descope-wc")}),{logger:this.logger}),"f"),e(this,r,"f").afterClose=e(this,o,"m",c).bind(this),e(this,o,"m",c).call(this),this.syncFlowTheme(e(this,n,"f")))},c=function(){e(this,r,"f").setContent(j({projectId:this.projectId,flowId:this.passkeyUserAuthMethod.flowId,baseUrl:this.baseUrl,baseStaticUrl:this.baseStaticUrl,baseCdnUrl:this.baseCdnUrl,refreshCookieName:this.refreshCookieName,theme:this.theme})),e(this,n,"f").onSuccess((()=>{e(this,r,"f").close(),this.actions.getMe()}))},f=function(){this.passkeyUserAuthMethod=new W((()=>{var t;return null===(t=this.shadowRoot)||void 0===t?void 0:t.querySelector('descope-user-auth-method[data-id="passkey"]')}),{logger:this.logger}),this.passkeyUserAuthMethod.onButtonClick((()=>{var t;null===(t=e(this,r,"f"))||void 0===t||t.open()}))},p})),ct=r((s=>{var o,r,h,n,d,c;return c=class extends(a(rt,V,l,ot,u,g)(s)){constructor(){super(...arguments),o.add(this),r.set(this,void 0),h.set(this,void 0)}initPasswordAuthMethod(){this.passwordUserAuthMethod=new W((()=>{var t;return null===(t=this.shadowRoot)||void 0===t?void 0:t.querySelector('descope-user-auth-method[data-id="password"]')}),{logger:this.logger}),this.passwordUserAuthMethod.onButtonClick((()=>{var t;null===(t=e(this,r,"f"))||void 0===t||t.open()}))}onWidgetRootReady(){const i=Object.create(null,{onWidgetRootReady:{get:()=>super.onWidgetRootReady}});return t(this,void 0,void 0,(function*(){var t;yield null===(t=i.onWidgetRootReady)||void 0===t?void 0:t.call(this),this.initPasswordAuthMethod(),e(this,o,"m",n).call(this)}))}},r=new WeakMap,h=new WeakMap,o=new WeakSet,n=function(){this.passwordUserAuthMethod.flowId&&(i(this,r,this.createModal({"data-id":"password"}),"f"),i(this,h,new k((()=>{var t;return null===(t=e(this,r,"f").ele)||void 0===t?void 0:t.querySelector("descope-wc")}),{logger:this.logger}),"f"),e(this,r,"f").afterClose=e(this,o,"m",d).bind(this),e(this,o,"m",d).call(this),this.syncFlowTheme(e(this,h,"f")))},d=function(){e(this,r,"f").setContent(j({projectId:this.projectId,flowId:this.passwordUserAuthMethod.flowId,baseUrl:this.baseUrl,baseStaticUrl:this.baseStaticUrl,baseCdnUrl:this.baseCdnUrl,refreshCookieName:this.refreshCookieName,theme:this.theme})),e(this,h,"f").onSuccess((()=>{e(this,r,"f").close()}))},c})),ut=r((s=>{var o,r,n,d,c,f,v,p,m,w,b,U,y;return y=class extends(a(rt,V,l,ot,u,g)(s)){constructor(){super(...arguments),o.add(this),r.set(this,void 0),n.set(this,void 0),d.set(this,void 0),c.set(this,void 0),b.set(this,h((t=>{this.phoneUserAttr.value=t}))),U.set(this,h((t=>{this.phoneUserAttr.badgeLabel=t?"":"Unverified"})))}onWidgetRootReady(){const i=Object.create(null,{onWidgetRootReady:{get:()=>super.onWidgetRootReady}});return t(this,void 0,void 0,(function*(){var t;yield null===(t=i.onWidgetRootReady)||void 0===t?void 0:t.call(this),e(this,o,"m",w).call(this),e(this,o,"m",f).call(this),e(this,o,"m",p).call(this),e(this,b,"f").call(this,Q(this.state)),e(this,U,"f").call(this,Z(this.state)),this.subscribe(e(this,b,"f").bind(this),Q),this.subscribe(e(this,U,"f").bind(this),Z)}))}},r=new WeakMap,n=new WeakMap,d=new WeakMap,c=new WeakMap,b=new WeakMap,U=new WeakMap,o=new WeakSet,f=function(){this.phoneUserAttr.editFlowId&&(i(this,r,this.createModal({"data-id":"edit-phone"}),"f"),i(this,n,new k((()=>{var t;return null===(t=e(this,r,"f").ele)||void 0===t?void 0:t.querySelector("descope-wc")}),{logger:this.logger}),"f"),e(this,r,"f").afterClose=e(this,o,"m",v).bind(this),e(this,o,"m",v).call(this),this.syncFlowTheme(e(this,n,"f")))},v=function(){e(this,r,"f").setContent(j({projectId:this.projectId,flowId:this.phoneUserAttr.editFlowId,baseUrl:this.baseUrl,baseStaticUrl:this.baseStaticUrl,baseCdnUrl:this.baseCdnUrl,refreshCookieName:this.refreshCookieName,theme:this.theme})),e(this,n,"f").onSuccess((()=>{e(this,r,"f").close(),this.actions.getMe()}))},p=function(){this.phoneUserAttr.deleteFlowId&&(i(this,d,this.createModal({"data-id":"delete-phone"}),"f"),i(this,c,new k((()=>{var t;return null===(t=e(this,d,"f").ele)||void 0===t?void 0:t.querySelector("descope-wc")}),{logger:this.logger}),"f"),e(this,d,"f").afterClose=e(this,o,"m",m).bind(this),e(this,o,"m",m).call(this),this.syncFlowTheme(e(this,c,"f")))},m=function(){e(this,d,"f").setContent(j({projectId:this.projectId,flowId:this.phoneUserAttr.deleteFlowId,baseUrl:this.baseUrl,baseStaticUrl:this.baseStaticUrl,baseCdnUrl:this.baseCdnUrl,refreshCookieName:this.refreshCookieName,theme:this.theme})),e(this,c,"f").onSuccess((()=>{e(this,d,"f").close(),this.actions.getMe()}))},w=function(){this.phoneUserAttr=new R((()=>{var t;return null===(t=this.shadowRoot)||void 0===t?void 0:t.querySelector('descope-user-attribute[data-id="phone"]')}),{logger:this.logger}),this.phoneUserAttr.onEditClick((()=>{var t;null===(t=e(this,r,"f"))||void 0===t||t.open()})),this.phoneUserAttr.onDeleteClick((()=>{var t;null===(t=e(this,d,"f"))||void 0===t||t.open()}))},y}));var ft;!function(t){t.TEXT="text",t.NUMBER="number",t.BOOLEAN="boolean",t.SINGLE_SELECT="singleSelect",t.ARRAY="array",t.DATE="date"}(ft||(ft={}));const vt=r((i=>{var s,o,r,n,d,c,f,v,p,m,w;return o=class extends(a(rt,V,l,ot,u,g)(i)){constructor(){super(...arguments),s.add(this),r.set(this,{}),n.set(this,{}),d.set(this,{}),c.set(this,{}),p.set(this,h((t=>{var i;const r=null===(i=this.shadowRoot)||void 0===i?void 0:i.querySelectorAll('descope-user-attribute[data-id^="customAttributes."]');Array.from(r).forEach((i=>{const r=i.getAttribute("data-id").replace("customAttributes.",""),a=i.getAttribute("data-type")||ft.TEXT,h=t[r],n=new R(i,{logger:this.logger});n.value=o.getFormattedValue(a,h),e(this,s,"m",m).call(this,i,r,n),e(this,s,"m",w).call(this,i,r,n)}))})))}static getFormattedValue(t,e){return t===ft.DATE&&e?new Date(e).toLocaleString():t===ft.BOOLEAN&&void 0!==e?e?"True":"False":(e||"").toString()}onWidgetRootReady(){const i=Object.create(null,{onWidgetRootReady:{get:()=>super.onWidgetRootReady}});return t(this,void 0,void 0,(function*(){var t;yield null===(t=i.onWidgetRootReady)||void 0===t?void 0:t.call(this),e(this,p,"f").call(this,it(this.state)),this.subscribe(e(this,p,"f").bind(this),it)}))}},r=new WeakMap,n=new WeakMap,d=new WeakMap,c=new WeakMap,p=new WeakMap,s=new WeakSet,f=function(t){var i,s;null===(i=e(this,r,"f")[t])||void 0===i||i.setContent(j({projectId:this.projectId,flowId:t,baseUrl:this.baseUrl,baseStaticUrl:this.baseStaticUrl,baseCdnUrl:this.baseCdnUrl,refreshCookieName:this.refreshCookieName,theme:this.theme})),null===(s=e(this,n,"f")[t])||void 0===s||s.onSuccess((()=>{var i;null===(i=e(this,r,"f")[t])||void 0===i||i.close(),this.actions.getMe()}))},v=function(t){var i,s;null===(i=e(this,d,"f")[t])||void 0===i||i.setContent(j({projectId:this.projectId,flowId:t,baseUrl:this.baseUrl,baseStaticUrl:this.baseStaticUrl,baseCdnUrl:this.baseCdnUrl,refreshCookieName:this.refreshCookieName,theme:this.theme})),null===(s=e(this,c,"f")[t])||void 0===s||s.onSuccess((()=>{var i;null===(i=e(this,d,"f")[t])||void 0===i||i.close(),this.actions.getMe()}))},m=function(t,i,o){const a=t.getAttribute("edit-flow-id");a&&(e(this,r,"f")[a]=this.createModal({"data-id":`edit-${i}`}),e(this,n,"f")[a]=new k((()=>{var t,i;return null===(i=null===(t=e(this,r,"f")[a])||void 0===t?void 0:t.ele)||void 0===i?void 0:i.querySelector("descope-wc")}),{logger:this.logger}),e(this,r,"f")[a].afterClose=e(this,s,"m",f).bind(this,a),o.onEditClick((()=>{var t,i;null===(i=null===(t=e(this,r,"f"))||void 0===t?void 0:t[a])||void 0===i||i.open()})),e(this,s,"m",f).call(this,a),this.syncFlowTheme(e(this,n,"f")[a]))},w=function(t,i,o){const r=t.getAttribute("delete-flow-id");r&&(e(this,d,"f")[r]=this.createModal({"data-id":`delete-${i}`}),e(this,c,"f")[r]=new k((()=>{var t,i;return null===(i=null===(t=e(this,d,"f")[r])||void 0===t?void 0:t.ele)||void 0===i?void 0:i.querySelector("descope-wc")}),{logger:this.logger}),e(this,d,"f")[r].afterClose=e(this,s,"m",v).bind(this,r),o.onDeleteClick((()=>{var t,i;null===(i=null===(t=e(this,d,"f"))||void 0===t?void 0:t[r])||void 0===i||i.open()})),e(this,s,"m",v).call(this,r),this.syncFlowTheme(e(this,c,"f")[r]))},o})),gt=r((s=>{var o,r,n,d,c,f,v,p;return p=class extends(a(rt,V,l,ot,u,g)(s)){constructor(){super(...arguments),o.add(this),r.set(this,void 0),n.set(this,void 0),v.set(this,h((t=>{this.totpUserAuthMethod.fulfilled=t})))}onWidgetRootReady(){const i=Object.create(null,{onWidgetRootReady:{get:()=>super.onWidgetRootReady}});return t(this,void 0,void 0,(function*(){var t;yield null===(t=i.onWidgetRootReady)||void 0===t?void 0:t.call(this),e(this,o,"m",f).call(this),e(this,o,"m",d).call(this),e(this,v,"f").call(this,et(this.state)),this.subscribe(e(this,v,"f").bind(this),et)}))}},r=new WeakMap,n=new WeakMap,v=new WeakMap,o=new WeakSet,d=function(){this.totpUserAuthMethod.flowId&&(i(this,r,this.createModal({"data-id":"totp"}),"f"),i(this,n,new k((()=>{var t;return null===(t=e(this,r,"f").ele)||void 0===t?void 0:t.querySelector("descope-wc")}),{logger:this.logger}),"f"),e(this,r,"f").afterClose=e(this,o,"m",c).bind(this),e(this,o,"m",c).call(this),this.syncFlowTheme(e(this,n,"f")))},c=function(){e(this,r,"f").setContent(j({projectId:this.projectId,flowId:this.totpUserAuthMethod.flowId,baseUrl:this.baseUrl,baseStaticUrl:this.baseStaticUrl,baseCdnUrl:this.baseCdnUrl,refreshCookieName:this.refreshCookieName,theme:this.theme})),e(this,n,"f").onSuccess((()=>{e(this,r,"f").close(),this.actions.getMe()}))},f=function(){this.totpUserAuthMethod=new W((()=>{var t;return null===(t=this.shadowRoot)||void 0===t?void 0:t.querySelector('descope-user-auth-method[data-id="totp"]')}),{logger:this.logger}),this.totpUserAuthMethod.onButtonClick((()=>{var t;null===(t=e(this,r,"f"))||void 0===t||t.open()}))},p})),pt=r((e=>class extends(a(y,p,G,vt,ht,at,dt,ut,lt,ct,ct,gt,nt)(e)){init(){const e=Object.create(null,{init:{get:()=>super.init}});return t(this,void 0,void 0,(function*(){var t;yield null===(t=e.init)||void 0===t?void 0:t.call(this)}))}})),mt=a((e=>class extends(pt(e)){init(){const e=Object.create(null,{init:{get:()=>super.init}});return t(this,void 0,void 0,(function*(){var t;yield null===(t=e.init)||void 0===t?void 0:t.call(this);(customElements.get("descope-wc")||(yield import("@descope/web-component").then((t=>t.default)))).sdkConfigOverrides={baseHeaders:{"x-descope-widget-type":"user-profile-widget","x-descope-widget-id":this.getAttribute("widget-id"),"x-descope-widget-version":"0.4.35"}}}))}}))(HTMLElement);customElements.define("descope-user-profile-widget",mt);export{mt as default};
5
+ import{__awaiter as t,__classPrivateFieldGet as e,__classPrivateFieldSet as i}from"tslib";import{createTemplate as s,kebabCase as o,createSingletonMixin as r,compose as a,withMemCache as h}from"@descope/sdk-helpers";import{projectIdMixin as n,observeAttributesMixin as l,loggerMixin as d,baseUrlMixin as c,cookieConfigMixin as u,createStateManagementMixin as f,initLifecycleMixin as v,modalMixin as g,themeMixin as m,staticResourcesMixin as p,createValidateAttributesMixin as w,descopeUiMixin as b,initElementMixin as U,debuggerMixin as y}from"@descope/sdk-mixins";import{FlowDriver as k,AvatarDriver as C,UserAttributeDriver as R,ButtonDriver as S,UserAuthMethodDriver as W}from"@descope/sdk-component-drivers";import{createAsyncThunk as M}from"@reduxjs/toolkit";import"@descope/core-js-sdk";import I from"@descope/web-js-sdk";import{createSelector as A}from"reselect";import"@descope/web-component";const j=(t={})=>{const e=s("<descope-wc></descope-wc>");return Object.entries(t).forEach((([t,i])=>{e.content.querySelector("descope-wc").setAttribute(o(t),i)})),e};function N(t){return new URLSearchParams(window.location.search).get(t)}const x=t=>(...e)=>i=>{i.addCase(t.pending,((t,i)=>{e.forEach((({onPending:e})=>{null==e||e(t,i)}))})),i.addCase(t.fulfilled,((t,i)=>{e.forEach((({onFulfilled:e})=>{null==e||e(t,i)}))})),i.addCase(t.rejected,((t,i)=>{e.forEach((({onRejected:e})=>{null==e||e(t,i)}))}))},T=M("users/me",((t,{extra:{api:e}})=>e.user.me())),F=x(T)({onFulfilled:(t,e)=>{t.me.data=e.payload}},(E=t=>t.me,{onFulfilled:t=>{E(t).loading=!1},onPending:t=>{E(t).loading=!0,E(t).error=null},onRejected:(t,e)=>{E(t).loading=!1,E(t).error=e.error}}));var E;const O={action:T,reducer:F},q=M("users/logout",((t,{extra:{api:e}})=>e.user.logout())),P={action:q,reducer:x(q)({})},L={me:{loading:!1,error:null,data:{}}},D={me:"/v1/auth/me"},$=()=>t(void 0,void 0,void 0,(function*(){return new Promise((t=>{t({loginIds:["user@company.com"],externalIds:["user@company.com"],userId:"user-1",name:"Test User",email:"user@company.com",roleNames:["Role"],phone:"+1-202-555-010",verifiedEmail:!0,verifiedPhone:!0,userTenants:[],status:"enabled",editable:!0,createdTime:(new Date).getTime(),customAttributes:{},familyName:"",givenName:"",middleName:"",picture:void 0,password:!0,SAML:!1,test:!1,TOTP:!1,webauthn:!0})}))})),B=({httpClient:e,mock:i})=>({me:()=>t(void 0,void 0,void 0,(function*(){if(i)return $();const s=yield e.get(D.me);return yield(e=>t(void 0,void 0,void 0,(function*(){const t=yield e.text(),i=JSON.parse(t);if(!e.ok){const t=`${i.errorDescription}${i.errorMessage?`: ${i.errorMessage}`:""}`;throw Error(t||`${e.status} ${e.statusText}`)}e.json=()=>Promise.resolve(i),e.text=()=>Promise.resolve(t)})))(s),s.json()}))}),H=r((s=>{var o,r,h,f;const v=a(n,l,d,c,u)(s);return f=class extends v{constructor(){super(...arguments),o.add(this),r.set(this,void 0)}get widgetId(){return this.getAttribute("widget-id")}get mock(){return this.getAttribute("mock")}get api(){return e(this,r,"f")||e(this,o,"m",h).call(this),e(this,r,"f")}init(){const i=Object.create(null,{init:{get:()=>super.init}});return t(this,void 0,void 0,(function*(){var t;yield null===(t=i.init)||void 0===t?void 0:t.call(this),this.observeAttributes(["project-id","base-url"],(()=>{e(this,r,"f")&&e(this,o,"m",h).call(this)}))}))}},r=new WeakMap,o=new WeakSet,h=function(){this.logger.debug("creating an sdk instance"),i(this,r,((e,i,s)=>{const o=I(Object.assign(Object.assign({},e),{persistTokens:!0,baseHeaders:{"x-descope-widget-type":"user-profile-widget","x-descope-widget-id":s,"x-descope-widget-version":"0.5.0"}}));return{user:Object.assign(Object.assign({},B({httpClient:o.httpClient,mock:i})),{logout:i?()=>t(void 0,void 0,void 0,(function*(){})):o.logout})}})({projectId:this.projectId,baseUrl:this.baseUrl,refreshCookieName:this.refreshCookieName},"true"===this.mock,this.widgetId),"f")},f})),V=r((t=>{const e=a(f({name:"widget",initialState:L,reducers:{},extraReducers:t=>{O.reducer(t),P.reducer(t)},asyncActions:{getMe:O.action,logout:P.action}}),v,d,H)(t);return class extends e{constructor(...t){super(...t),this.state=L,this.subscribe((t=>{this.logger.debug("State update:",t),this.state=t}))}}})),X="widget-flow",G=r((i=>{var s,o,r;return r=class extends(a(v,g,V,u,d,m)(i)){constructor(){super(...arguments),s.add(this)}init(){const i=Object.create(null,{init:{get:()=>super.init}});return t(this,void 0,void 0,(function*(){var t;yield null===(t=i.init)||void 0===t?void 0:t.call(this);const r=N(X);r&&(!function(t){if(window.history.replaceState&&N(t)){const e=new URL(window.location.href),i=new URLSearchParams(e.search);i.delete(t),e.search=i.toString(),window.history.replaceState({},"",e.toString())}}(X),e(this,s,"m",o).call(this,r))}))}},s=new WeakSet,o=function(t){const e=this.createModal({"data-id":"redirect-flow"});e.setContent(j({projectId:this.projectId,flowId:t,baseUrl:this.baseUrl,baseStaticUrl:this.baseStaticUrl,baseCdnUrl:this.baseCdnUrl,refreshCookieName:this.refreshCookieName,theme:this.theme}));new k((()=>{var t;return null===(t=e.ele)||void 0===t?void 0:t.querySelector("descope-wc")}),{logger:this.logger}).onSuccess((()=>{e.close(),this.actions.getMe()})),e.afterClose=()=>{e.remove()},e.open()},r})),J=t=>t.me.data,Y=A(J,(t=>t.picture)),_=A(J,(t=>t.email)),z=A(J,(t=>t.verifiedEmail)),K=A(J,(t=>t.name)),Q=A(J,(t=>t.phone)),Z=A(J,(t=>t.verifiedPhone)),tt=A(J,(t=>t.webauthn));A(J,(t=>t.password));const et=A(J,(t=>t.TOTP)),it=A(J,(t=>t.customAttributes)),st=A(J,(t=>({givenName:t.givenName,middleName:t.middleName,familyName:t.familyName}))),ot=r((e=>{const i=a(p,w({"widget-id":w.missingAttrValidator}))(e);return class extends i{get widgetId(){return this.getAttribute("widget-id")}fetchWidgetPage(e){return t(this,void 0,void 0,(function*(){return(yield this.fetchStaticResource(`user-profile-widget/${this.widgetId}/${e}`,"text")).body}))}}})),rt=r((i=>{var o,r,h;return h=class extends(a(d,v,b,U,ot,V)(i)){constructor(){super(...arguments),o.add(this)}onWidgetRootReady(){return t(this,void 0,void 0,(function*(){}))}init(){const i=Object.create(null,{init:{get:()=>super.init}});return t(this,void 0,void 0,(function*(){var t;yield null===(t=i.init)||void 0===t?void 0:t.call(this),yield Promise.all([this.actions.getMe(),e(this,o,"m",r).call(this)]),this.onWidgetRootReady()}))}},o=new WeakSet,r=function(){return t(this,void 0,void 0,(function*(){const t=s(yield this.fetchWidgetPage("root.html"));yield this.loadDescopeUiComponents(t),this.contentRootElement.append(t.content.cloneNode(!0))}))},h})),at=r((t=>class extends(a(m,l)(t)){syncFlowTheme(t){t.theme=this.theme,this.observeAttributes(["theme"],(()=>{t.theme=this.theme}))}})),ht=r((s=>{var o,r,n,l,c,f,v,p,w;return w=class extends(a(at,m,V,d,u,rt,g)(s)){constructor(){super(...arguments),o.add(this),r.set(this,void 0),n.set(this,void 0),v.set(this,h((t=>{this.avatar.image=t}))),p.set(this,h((t=>{this.avatar.displayName=t})))}onWidgetRootReady(){const i=Object.create(null,{onWidgetRootReady:{get:()=>super.onWidgetRootReady}});return t(this,void 0,void 0,(function*(){var t;yield null===(t=i.onWidgetRootReady)||void 0===t?void 0:t.call(this),e(this,o,"m",f).call(this),e(this,o,"m",l).call(this),e(this,v,"f").call(this,Y(this.state)),e(this,p,"f").call(this,K(this.state)),this.subscribe(e(this,v,"f").bind(this),Y),this.subscribe(e(this,p,"f").bind(this),K)}))}},r=new WeakMap,n=new WeakMap,v=new WeakMap,p=new WeakMap,o=new WeakSet,l=function(){this.avatar.flowId&&(i(this,r,this.createModal({"data-id":"update-pic"}),"f"),i(this,n,new k((()=>{var t;return null===(t=e(this,r,"f").ele)||void 0===t?void 0:t.querySelector("descope-wc")}),{logger:this.logger}),"f"),e(this,r,"f").afterClose=e(this,o,"m",c).bind(this),e(this,o,"m",c).call(this),this.syncFlowTheme(e(this,n,"f")))},c=function(){e(this,r,"f").setContent(j({projectId:this.projectId,flowId:this.avatar.flowId,baseUrl:this.baseUrl,baseStaticUrl:this.baseStaticUrl,baseCdnUrl:this.baseCdnUrl,refreshCookieName:this.refreshCookieName,theme:this.theme})),e(this,n,"f").onSuccess((()=>{e(this,r,"f").close(),this.actions.getMe()}))},f=function(){this.avatar=new C((()=>{var t;return null===(t=this.shadowRoot)||void 0===t?void 0:t.querySelector("descope-avatar")}),{logger:this.logger}),this.avatar.onClick((()=>{var t;null===(t=e(this,r,"f"))||void 0===t||t.open()}))},w})),nt=r((s=>{var o,r,n,l,c,f,v,m,p,w,b,U,y;return y=class extends(a(at,V,d,rt,u,g)(s)){constructor(){super(...arguments),o.add(this),r.set(this,void 0),n.set(this,void 0),l.set(this,void 0),c.set(this,void 0),b.set(this,h((t=>{this.emailUserAttr.value=t}))),U.set(this,h((t=>{this.emailUserAttr.badgeLabel=t?"":"Unverified"})))}onWidgetRootReady(){const i=Object.create(null,{onWidgetRootReady:{get:()=>super.onWidgetRootReady}});return t(this,void 0,void 0,(function*(){var t;yield null===(t=i.onWidgetRootReady)||void 0===t?void 0:t.call(this),e(this,o,"m",w).call(this),e(this,o,"m",f).call(this),e(this,o,"m",m).call(this),e(this,b,"f").call(this,_(this.state)),e(this,U,"f").call(this,z(this.state)),this.subscribe(e(this,b,"f").bind(this),_),this.subscribe(e(this,U,"f").bind(this),z)}))}},r=new WeakMap,n=new WeakMap,l=new WeakMap,c=new WeakMap,b=new WeakMap,U=new WeakMap,o=new WeakSet,f=function(){this.emailUserAttr.editFlowId&&(i(this,r,this.createModal({"data-id":"edit-email"}),"f"),i(this,n,new k((()=>{var t;return null===(t=e(this,r,"f").ele)||void 0===t?void 0:t.querySelector("descope-wc")}),{logger:this.logger}),"f"),e(this,r,"f").afterClose=e(this,o,"m",v).bind(this),e(this,o,"m",v).call(this),this.syncFlowTheme(e(this,n,"f")))},v=function(){e(this,r,"f").setContent(j({projectId:this.projectId,flowId:this.emailUserAttr.editFlowId,baseUrl:this.baseUrl,baseStaticUrl:this.baseStaticUrl,baseCdnUrl:this.baseCdnUrl,refreshCookieName:this.refreshCookieName,theme:this.theme})),e(this,n,"f").onSuccess((()=>{e(this,r,"f").close(),this.actions.getMe()}))},m=function(){this.emailUserAttr.deleteFlowId&&(i(this,l,this.createModal({"data-id":"delete-email"}),"f"),i(this,c,new k((()=>{var t;return null===(t=e(this,l,"f").ele)||void 0===t?void 0:t.querySelector("descope-wc")}),{logger:this.logger}),"f"),e(this,l,"f").afterClose=e(this,o,"m",p).bind(this),e(this,o,"m",p).call(this),this.syncFlowTheme(e(this,c,"f")))},p=function(){e(this,l,"f").setContent(j({projectId:this.projectId,flowId:this.emailUserAttr.deleteFlowId,baseUrl:this.baseUrl,baseStaticUrl:this.baseStaticUrl,baseCdnUrl:this.baseCdnUrl,refreshCookieName:this.refreshCookieName,theme:this.theme})),e(this,c,"f").onSuccess((()=>{e(this,l,"f").close(),this.actions.getMe()}))},w=function(){this.emailUserAttr=new R((()=>{var t;return null===(t=this.shadowRoot)||void 0===t?void 0:t.querySelector('descope-user-attribute[data-id="email"]')}),{logger:this.logger}),this.emailUserAttr.onEditClick((()=>{var t;null===(t=e(this,r,"f"))||void 0===t||t.open()})),this.emailUserAttr.onDeleteClick((()=>{var t;null===(t=e(this,l,"f"))||void 0===t||t.open()}))},y})),lt=r((i=>{var s,o,r;return r=class extends(a(V,d,rt,g)(i)){constructor(){super(...arguments),s.add(this)}onWidgetRootReady(){const i=Object.create(null,{onWidgetRootReady:{get:()=>super.onWidgetRootReady}});return t(this,void 0,void 0,(function*(){var t;yield null===(t=i.onWidgetRootReady)||void 0===t?void 0:t.call(this),e(this,s,"m",o).call(this)}))}},s=new WeakSet,o=function(){this.logout=new S((()=>{var t;return null===(t=this.shadowRoot)||void 0===t?void 0:t.querySelector('descope-button[data-id="logout"]')}),{logger:this.logger}),this.logout.onClick((()=>t(this,void 0,void 0,(function*(){yield this.actions.logout(),this.dispatchEvent(new CustomEvent("logout"))}))))},r})),dt=r((s=>{var o,r,n,l,c,f,v,m,p,w,b,U;return U=class extends(a(at,V,d,rt,u,g)(s)){constructor(){super(...arguments),o.add(this),r.set(this,void 0),n.set(this,void 0),l.set(this,void 0),c.set(this,void 0),b.set(this,h((t=>{this.nameUserAttr.value=t})))}onWidgetRootReady(){const i=Object.create(null,{onWidgetRootReady:{get:()=>super.onWidgetRootReady}});return t(this,void 0,void 0,(function*(){var t;yield null===(t=i.onWidgetRootReady)||void 0===t?void 0:t.call(this),e(this,o,"m",w).call(this),e(this,o,"m",f).call(this),e(this,o,"m",m).call(this),e(this,b,"f").call(this,K(this.state)),this.subscribe(e(this,b,"f").bind(this),K)}))}},r=new WeakMap,n=new WeakMap,l=new WeakMap,c=new WeakMap,b=new WeakMap,o=new WeakSet,f=function(){this.nameUserAttr.editFlowId&&(i(this,r,this.createModal({"data-id":"edit-name"}),"f"),i(this,n,new k((()=>{var t;return null===(t=e(this,r,"f").ele)||void 0===t?void 0:t.querySelector("descope-wc")}),{logger:this.logger}),"f"),e(this,r,"f").afterClose=e(this,o,"m",v).bind(this),e(this,o,"m",v).call(this),this.syncFlowTheme(e(this,n,"f")))},v=function(){e(this,r,"f").setContent(j({projectId:this.projectId,flowId:this.nameUserAttr.editFlowId,baseUrl:this.baseUrl,baseStaticUrl:this.baseStaticUrl,baseCdnUrl:this.baseCdnUrl,refreshCookieName:this.refreshCookieName,theme:this.theme})),e(this,n,"f").onSuccess((()=>{e(this,r,"f").close(),this.actions.getMe()}))},m=function(){this.nameUserAttr.deleteFlowId&&(i(this,l,this.createModal({"data-id":"delete-name"}),"f"),i(this,c,new k((()=>{var t;return null===(t=e(this,l,"f").ele)||void 0===t?void 0:t.querySelector("descope-wc")}),{logger:this.logger}),"f"),e(this,l,"f").afterClose=e(this,o,"m",p).bind(this),e(this,o,"m",p).call(this),this.syncFlowTheme(e(this,c,"f")))},p=function(){e(this,l,"f").setContent(j({projectId:this.projectId,flowId:this.nameUserAttr.deleteFlowId,baseUrl:this.baseUrl,baseStaticUrl:this.baseStaticUrl,baseCdnUrl:this.baseCdnUrl,refreshCookieName:this.refreshCookieName,theme:this.theme})),e(this,c,"f").onSuccess((()=>{e(this,l,"f").close(),this.actions.getMe()}))},w=function(){this.nameUserAttr=new R((()=>{var t;return null===(t=this.shadowRoot)||void 0===t?void 0:t.querySelector('descope-user-attribute[data-id="name"]')}),{logger:this.logger}),this.nameUserAttr.onEditClick((()=>{var t;null===(t=e(this,r,"f"))||void 0===t||t.open()})),this.nameUserAttr.onDeleteClick((()=>{var t;null===(t=e(this,l,"f"))||void 0===t||t.open()}))},U})),ct=r((s=>{var o,r,n,l,c,f,v,m;return m=class extends(a(at,V,d,rt,u,g)(s)){constructor(){super(...arguments),o.add(this),r.set(this,void 0),n.set(this,void 0),v.set(this,h((t=>{this.passkeyUserAuthMethod.fulfilled=t})))}onWidgetRootReady(){const i=Object.create(null,{onWidgetRootReady:{get:()=>super.onWidgetRootReady}});return t(this,void 0,void 0,(function*(){var t;yield null===(t=i.onWidgetRootReady)||void 0===t?void 0:t.call(this),e(this,o,"m",f).call(this),e(this,o,"m",l).call(this),e(this,v,"f").call(this,tt(this.state)),this.subscribe(e(this,v,"f").bind(this),tt)}))}},r=new WeakMap,n=new WeakMap,v=new WeakMap,o=new WeakSet,l=function(){this.passkeyUserAuthMethod.flowId&&(i(this,r,this.createModal({"data-id":"passkey"}),"f"),i(this,n,new k((()=>{var t;return null===(t=e(this,r,"f").ele)||void 0===t?void 0:t.querySelector("descope-wc")}),{logger:this.logger}),"f"),e(this,r,"f").afterClose=e(this,o,"m",c).bind(this),e(this,o,"m",c).call(this),this.syncFlowTheme(e(this,n,"f")))},c=function(){e(this,r,"f").setContent(j({projectId:this.projectId,flowId:this.passkeyUserAuthMethod.flowId,baseUrl:this.baseUrl,baseStaticUrl:this.baseStaticUrl,baseCdnUrl:this.baseCdnUrl,refreshCookieName:this.refreshCookieName,theme:this.theme})),e(this,n,"f").onSuccess((()=>{e(this,r,"f").close(),this.actions.getMe()}))},f=function(){this.passkeyUserAuthMethod=new W((()=>{var t;return null===(t=this.shadowRoot)||void 0===t?void 0:t.querySelector('descope-user-auth-method[data-id="passkey"]')}),{logger:this.logger}),this.passkeyUserAuthMethod.onButtonClick((()=>{var t;null===(t=e(this,r,"f"))||void 0===t||t.open()}))},m})),ut=r((s=>{var o,r,h,n,l,c;return c=class extends(a(at,V,d,rt,u,g)(s)){constructor(){super(...arguments),o.add(this),r.set(this,void 0),h.set(this,void 0)}initPasswordAuthMethod(){this.passwordUserAuthMethod=new W((()=>{var t;return null===(t=this.shadowRoot)||void 0===t?void 0:t.querySelector('descope-user-auth-method[data-id="password"]')}),{logger:this.logger}),this.passwordUserAuthMethod.onButtonClick((()=>{var t;null===(t=e(this,r,"f"))||void 0===t||t.open()}))}onWidgetRootReady(){const i=Object.create(null,{onWidgetRootReady:{get:()=>super.onWidgetRootReady}});return t(this,void 0,void 0,(function*(){var t;yield null===(t=i.onWidgetRootReady)||void 0===t?void 0:t.call(this),this.initPasswordAuthMethod(),e(this,o,"m",n).call(this)}))}},r=new WeakMap,h=new WeakMap,o=new WeakSet,n=function(){this.passwordUserAuthMethod.flowId&&(i(this,r,this.createModal({"data-id":"password"}),"f"),i(this,h,new k((()=>{var t;return null===(t=e(this,r,"f").ele)||void 0===t?void 0:t.querySelector("descope-wc")}),{logger:this.logger}),"f"),e(this,r,"f").afterClose=e(this,o,"m",l).bind(this),e(this,o,"m",l).call(this),this.syncFlowTheme(e(this,h,"f")))},l=function(){e(this,r,"f").setContent(j({projectId:this.projectId,flowId:this.passwordUserAuthMethod.flowId,baseUrl:this.baseUrl,baseStaticUrl:this.baseStaticUrl,baseCdnUrl:this.baseCdnUrl,refreshCookieName:this.refreshCookieName,theme:this.theme})),e(this,h,"f").onSuccess((()=>{e(this,r,"f").close()}))},c})),ft=r((s=>{var o,r,n,l,c,f,v,m,p,w,b,U,y;return y=class extends(a(at,V,d,rt,u,g)(s)){constructor(){super(...arguments),o.add(this),r.set(this,void 0),n.set(this,void 0),l.set(this,void 0),c.set(this,void 0),b.set(this,h((t=>{this.phoneUserAttr.value=t}))),U.set(this,h((t=>{this.phoneUserAttr.badgeLabel=t?"":"Unverified"})))}onWidgetRootReady(){const i=Object.create(null,{onWidgetRootReady:{get:()=>super.onWidgetRootReady}});return t(this,void 0,void 0,(function*(){var t;yield null===(t=i.onWidgetRootReady)||void 0===t?void 0:t.call(this),e(this,o,"m",w).call(this),e(this,o,"m",f).call(this),e(this,o,"m",m).call(this),e(this,b,"f").call(this,Q(this.state)),e(this,U,"f").call(this,Z(this.state)),this.subscribe(e(this,b,"f").bind(this),Q),this.subscribe(e(this,U,"f").bind(this),Z)}))}},r=new WeakMap,n=new WeakMap,l=new WeakMap,c=new WeakMap,b=new WeakMap,U=new WeakMap,o=new WeakSet,f=function(){this.phoneUserAttr.editFlowId&&(i(this,r,this.createModal({"data-id":"edit-phone"}),"f"),i(this,n,new k((()=>{var t;return null===(t=e(this,r,"f").ele)||void 0===t?void 0:t.querySelector("descope-wc")}),{logger:this.logger}),"f"),e(this,r,"f").afterClose=e(this,o,"m",v).bind(this),e(this,o,"m",v).call(this),this.syncFlowTheme(e(this,n,"f")))},v=function(){e(this,r,"f").setContent(j({projectId:this.projectId,flowId:this.phoneUserAttr.editFlowId,baseUrl:this.baseUrl,baseStaticUrl:this.baseStaticUrl,baseCdnUrl:this.baseCdnUrl,refreshCookieName:this.refreshCookieName,theme:this.theme})),e(this,n,"f").onSuccess((()=>{e(this,r,"f").close(),this.actions.getMe()}))},m=function(){this.phoneUserAttr.deleteFlowId&&(i(this,l,this.createModal({"data-id":"delete-phone"}),"f"),i(this,c,new k((()=>{var t;return null===(t=e(this,l,"f").ele)||void 0===t?void 0:t.querySelector("descope-wc")}),{logger:this.logger}),"f"),e(this,l,"f").afterClose=e(this,o,"m",p).bind(this),e(this,o,"m",p).call(this),this.syncFlowTheme(e(this,c,"f")))},p=function(){e(this,l,"f").setContent(j({projectId:this.projectId,flowId:this.phoneUserAttr.deleteFlowId,baseUrl:this.baseUrl,baseStaticUrl:this.baseStaticUrl,baseCdnUrl:this.baseCdnUrl,refreshCookieName:this.refreshCookieName,theme:this.theme})),e(this,c,"f").onSuccess((()=>{e(this,l,"f").close(),this.actions.getMe()}))},w=function(){this.phoneUserAttr=new R((()=>{var t;return null===(t=this.shadowRoot)||void 0===t?void 0:t.querySelector('descope-user-attribute[data-id="phone"]')}),{logger:this.logger}),this.phoneUserAttr.onEditClick((()=>{var t;null===(t=e(this,r,"f"))||void 0===t||t.open()})),this.phoneUserAttr.onDeleteClick((()=>{var t;null===(t=e(this,l,"f"))||void 0===t||t.open()}))},y})),vt=r((s=>{var o,r,n,l,c,f,v,m;return m=class extends(a(at,V,d,rt,u,g)(s)){constructor(){super(...arguments),o.add(this),r.set(this,void 0),n.set(this,void 0),v.set(this,h((t=>{this.totpUserAuthMethod.fulfilled=t})))}onWidgetRootReady(){const i=Object.create(null,{onWidgetRootReady:{get:()=>super.onWidgetRootReady}});return t(this,void 0,void 0,(function*(){var t;yield null===(t=i.onWidgetRootReady)||void 0===t?void 0:t.call(this),e(this,o,"m",f).call(this),e(this,o,"m",l).call(this),e(this,v,"f").call(this,et(this.state)),this.subscribe(e(this,v,"f").bind(this),et)}))}},r=new WeakMap,n=new WeakMap,v=new WeakMap,o=new WeakSet,l=function(){this.totpUserAuthMethod.flowId&&(i(this,r,this.createModal({"data-id":"totp"}),"f"),i(this,n,new k((()=>{var t;return null===(t=e(this,r,"f").ele)||void 0===t?void 0:t.querySelector("descope-wc")}),{logger:this.logger}),"f"),e(this,r,"f").afterClose=e(this,o,"m",c).bind(this),e(this,o,"m",c).call(this),this.syncFlowTheme(e(this,n,"f")))},c=function(){e(this,r,"f").setContent(j({projectId:this.projectId,flowId:this.totpUserAuthMethod.flowId,baseUrl:this.baseUrl,baseStaticUrl:this.baseStaticUrl,baseCdnUrl:this.baseCdnUrl,refreshCookieName:this.refreshCookieName,theme:this.theme})),e(this,n,"f").onSuccess((()=>{e(this,r,"f").close(),this.actions.getMe()}))},f=function(){this.totpUserAuthMethod=new W((()=>{var t;return null===(t=this.shadowRoot)||void 0===t?void 0:t.querySelector('descope-user-auth-method[data-id="totp"]')}),{logger:this.logger}),this.totpUserAuthMethod.onButtonClick((()=>{var t;null===(t=e(this,r,"f"))||void 0===t||t.open()}))},m})),gt=r((i=>{var s,o,r,n,l,c,f,v,m,p,w;return w=class extends(a(at,V,d,rt,u,g)(i)){constructor(){super(...arguments),s.add(this),o.set(this,{}),r.set(this,{}),n.set(this,{}),l.set(this,{}),v.set(this,h((t=>{var i;const o=null===(i=this.shadowRoot)||void 0===i?void 0:i.querySelectorAll('descope-user-attribute[data-id^="builtin."]');Array.from(o).forEach((i=>{const o=i.getAttribute("data-id").replace("builtin.",""),r=t[o],a=new R(i,{logger:this.logger});a.value=(r||"").toString(),e(this,s,"m",m).call(this,i,o,a),e(this,s,"m",p).call(this,i,o,a)}))})))}onWidgetRootReady(){const i=Object.create(null,{onWidgetRootReady:{get:()=>super.onWidgetRootReady}});return t(this,void 0,void 0,(function*(){var t;yield null===(t=i.onWidgetRootReady)||void 0===t?void 0:t.call(this),e(this,v,"f").call(this,st(this.state)),this.subscribe(e(this,v,"f").bind(this),st)}))}},o=new WeakMap,r=new WeakMap,n=new WeakMap,l=new WeakMap,v=new WeakMap,s=new WeakSet,c=function(t){var i,s;null===(i=e(this,o,"f")[t])||void 0===i||i.setContent(j({projectId:this.projectId,flowId:t,baseUrl:this.baseUrl,baseStaticUrl:this.baseStaticUrl,baseCdnUrl:this.baseCdnUrl,refreshCookieName:this.refreshCookieName,theme:this.theme})),null===(s=e(this,r,"f")[t])||void 0===s||s.onSuccess((()=>{var i;null===(i=e(this,o,"f")[t])||void 0===i||i.close(),this.actions.getMe()}))},f=function(t){var i,s;null===(i=e(this,n,"f")[t])||void 0===i||i.setContent(j({projectId:this.projectId,flowId:t,baseUrl:this.baseUrl,baseStaticUrl:this.baseStaticUrl,baseCdnUrl:this.baseCdnUrl,refreshCookieName:this.refreshCookieName,theme:this.theme})),null===(s=e(this,l,"f")[t])||void 0===s||s.onSuccess((()=>{var i;null===(i=e(this,n,"f")[t])||void 0===i||i.close(),this.actions.getMe()}))},m=function(t,i,a){const h=t.getAttribute("edit-flow-id");h&&(e(this,o,"f")[h]=this.createModal({"data-id":`edit-${i}`}),e(this,r,"f")[h]=new k((()=>{var t,i;return null===(i=null===(t=e(this,o,"f")[h])||void 0===t?void 0:t.ele)||void 0===i?void 0:i.querySelector("descope-wc")}),{logger:this.logger}),e(this,o,"f")[h].afterClose=e(this,s,"m",c).bind(this,h),a.onEditClick((()=>{var t,i;null===(i=null===(t=e(this,o,"f"))||void 0===t?void 0:t[h])||void 0===i||i.open()})),e(this,s,"m",c).call(this,h),this.syncFlowTheme(e(this,r,"f")[h]))},p=function(t,i,o){const r=t.getAttribute("delete-flow-id");r&&(e(this,n,"f")[r]=this.createModal({"data-id":`delete-${i}`}),e(this,l,"f")[r]=new k((()=>{var t,i;return null===(i=null===(t=e(this,n,"f")[r])||void 0===t?void 0:t.ele)||void 0===i?void 0:i.querySelector("descope-wc")}),{logger:this.logger}),e(this,n,"f")[r].afterClose=e(this,s,"m",f).bind(this,r),o.onDeleteClick((()=>{var t,i;null===(i=null===(t=e(this,n,"f"))||void 0===t?void 0:t[r])||void 0===i||i.open()})),e(this,s,"m",f).call(this,r),this.syncFlowTheme(e(this,l,"f")[r]))},w}));var mt;!function(t){t.TEXT="text",t.NUMBER="number",t.BOOLEAN="boolean",t.SINGLE_SELECT="singleSelect",t.ARRAY="array",t.DATE="date"}(mt||(mt={}));const pt=r((i=>{var s,o,r,n,l,c,f,v,m,p,w;return o=class extends(a(at,V,d,rt,u,g)(i)){constructor(){super(...arguments),s.add(this),r.set(this,{}),n.set(this,{}),l.set(this,{}),c.set(this,{}),m.set(this,h((t=>{var i;const r=null===(i=this.shadowRoot)||void 0===i?void 0:i.querySelectorAll('descope-user-attribute[data-id^="customAttributes."]');Array.from(r).forEach((i=>{const r=i.getAttribute("data-id").replace("customAttributes.",""),a=i.getAttribute("data-type")||mt.TEXT,h=t[r],n=new R(i,{logger:this.logger});n.value=o.getFormattedValue(a,h),e(this,s,"m",p).call(this,i,r,n),e(this,s,"m",w).call(this,i,r,n)}))})))}static getFormattedValue(t,e){return t===mt.DATE&&e?new Date(e).toLocaleString():t===mt.BOOLEAN&&void 0!==e?e?"True":"False":(e||"").toString()}onWidgetRootReady(){const i=Object.create(null,{onWidgetRootReady:{get:()=>super.onWidgetRootReady}});return t(this,void 0,void 0,(function*(){var t;yield null===(t=i.onWidgetRootReady)||void 0===t?void 0:t.call(this),e(this,m,"f").call(this,it(this.state)),this.subscribe(e(this,m,"f").bind(this),it)}))}},r=new WeakMap,n=new WeakMap,l=new WeakMap,c=new WeakMap,m=new WeakMap,s=new WeakSet,f=function(t){var i,s;null===(i=e(this,r,"f")[t])||void 0===i||i.setContent(j({projectId:this.projectId,flowId:t,baseUrl:this.baseUrl,baseStaticUrl:this.baseStaticUrl,baseCdnUrl:this.baseCdnUrl,refreshCookieName:this.refreshCookieName,theme:this.theme})),null===(s=e(this,n,"f")[t])||void 0===s||s.onSuccess((()=>{var i;null===(i=e(this,r,"f")[t])||void 0===i||i.close(),this.actions.getMe()}))},v=function(t){var i,s;null===(i=e(this,l,"f")[t])||void 0===i||i.setContent(j({projectId:this.projectId,flowId:t,baseUrl:this.baseUrl,baseStaticUrl:this.baseStaticUrl,baseCdnUrl:this.baseCdnUrl,refreshCookieName:this.refreshCookieName,theme:this.theme})),null===(s=e(this,c,"f")[t])||void 0===s||s.onSuccess((()=>{var i;null===(i=e(this,l,"f")[t])||void 0===i||i.close(),this.actions.getMe()}))},p=function(t,i,o){const a=t.getAttribute("edit-flow-id");a&&(e(this,r,"f")[a]=this.createModal({"data-id":`edit-${i}`}),e(this,n,"f")[a]=new k((()=>{var t,i;return null===(i=null===(t=e(this,r,"f")[a])||void 0===t?void 0:t.ele)||void 0===i?void 0:i.querySelector("descope-wc")}),{logger:this.logger}),e(this,r,"f")[a].afterClose=e(this,s,"m",f).bind(this,a),o.onEditClick((()=>{var t,i;null===(i=null===(t=e(this,r,"f"))||void 0===t?void 0:t[a])||void 0===i||i.open()})),e(this,s,"m",f).call(this,a),this.syncFlowTheme(e(this,n,"f")[a]))},w=function(t,i,o){const r=t.getAttribute("delete-flow-id");r&&(e(this,l,"f")[r]=this.createModal({"data-id":`delete-${i}`}),e(this,c,"f")[r]=new k((()=>{var t,i;return null===(i=null===(t=e(this,l,"f")[r])||void 0===t?void 0:t.ele)||void 0===i?void 0:i.querySelector("descope-wc")}),{logger:this.logger}),e(this,l,"f")[r].afterClose=e(this,s,"m",v).bind(this,r),o.onDeleteClick((()=>{var t,i;null===(i=null===(t=e(this,l,"f"))||void 0===t?void 0:t[r])||void 0===i||i.open()})),e(this,s,"m",v).call(this,r),this.syncFlowTheme(e(this,c,"f")[r]))},o})),wt=r((e=>class extends(a(y,m,G,pt,nt,ht,dt,ft,ct,ut,vt,gt,lt)(e)){init(){const e=Object.create(null,{init:{get:()=>super.init}});return t(this,void 0,void 0,(function*(){var t;yield null===(t=e.init)||void 0===t?void 0:t.call(this)}))}})),bt=a((e=>class extends(wt(e)){init(){const e=Object.create(null,{init:{get:()=>super.init}});return t(this,void 0,void 0,(function*(){var t;yield null===(t=e.init)||void 0===t?void 0:t.call(this);(customElements.get("descope-wc")||(yield import("@descope/web-component").then((t=>t.default)))).sdkConfigOverrides={baseHeaders:{"x-descope-widget-type":"user-profile-widget","x-descope-widget-id":this.getAttribute("widget-id"),"x-descope-widget-version":"0.5.0"}}}))}}))(HTMLElement);customElements.define("descope-user-profile-widget",bt);export{bt as default};
6
6
  //# sourceMappingURL=index.js.map