@descope/user-profile-widget 0.0.6 → 0.0.7

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.0.6
3
+ * @descope/user-profile-widget v0.0.7
4
4
  */
5
5
  import{createSingletonMixin as t,compose as e,createTemplate as i,kebabCase as s,withMemCache as o}from"@descope/sdk-helpers";import{__awaiter as n,__classPrivateFieldGet as r,__classPrivateFieldSet as a}from"tslib";import{projectIdMixin as d,observeAttributesMixin as l,loggerMixin as h,createValidateAttributesMixin as c,createStateManagementMixin as u,initLifecycleMixin as f,staticResourcesMixin as g,descopeUiMixin as p,initElementMixin as v,modalMixin as m,debuggerMixin as w,themeMixin as b}from"@descope/sdk-mixins";import{FlowDriver as y,AvatarDriver as R,UserAttributeDriver as W,UserAuthMethodDriver as k,ButtonDriver as M}from"@descope/sdk-component-drivers";import{createSelector as U}from"reselect";import{createAsyncThunk as j}from"@reduxjs/toolkit";import I from"@descope/web-js-sdk";import"@descope/core-js-sdk";import"@descope/web-component";const S=t=>t.me.data,A=U(S,(t=>t.picture)),C=U(S,(t=>t.email)),x=U(S,(t=>t.verifiedEmail)),q=U(S,(t=>t.name)),O=U(S,(t=>t.phone)),E=U(S,(t=>t.verifiedPhone)),P=U(S,(t=>t.webauthn));U(S,(t=>t.password));const D=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)}))}))},F=j("users/me",((t,{extra:{api:e}})=>e.user.me())),T=D(F)({onFulfilled:(t,e)=>{t.me.data=e.payload}},(N=t=>t.me,{onFulfilled:t=>{N(t).loading=!1},onPending:t=>{N(t).loading=!0,N(t).error=null},onRejected:(t,e)=>{N(t).loading=!1,N(t).error=e.error}}));var N;const $={action:F,reducer:T},L=j("users/logout",((t,{extra:{api:e}})=>e.user.logout())),H={action:L,reducer:D(L)({})},B={me:{loading:!1,error:null,data:{}}},K={me:"/v1/auth/me"},J=()=>n(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:"https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSzmudcbKkbOue75DaM9HDDrt0W39SJLBH-3HPK3s-K1w&s",password:!0,SAML:!1,test:!1,TOTP:!1,webauthn:!0})}))})),V=({httpClient:t,mock:e})=>({me:()=>n(void 0,void 0,void 0,(function*(){if(e)return J();const i=yield t.get(K.me);return yield(t=>n(void 0,void 0,void 0,(function*(){const e=yield t.text(),i=JSON.parse(e);if(!t.ok){const e=`${i.errorDescription}${i.errorMessage?`: ${i.errorMessage}`:""}`;throw Error(e||`${t.status} ${t.statusText}`)}t.json=()=>Promise.resolve(i),t.text=()=>Promise.resolve(e)})))(i),i.json()}))}),z=t((t=>{var i,s,o,u;const f=e(d,l,h,c({tenant:c.missingAttrValidator}))(t);return u=class extends f{constructor(){super(...arguments),i.add(this),s.set(this,void 0)}get baseUrl(){return this.getAttribute("base-url")}get tenant(){return this.getAttribute("tenant")}get mock(){return this.getAttribute("mock")}get api(){return r(this,s,"f")||r(this,i,"m",o).call(this),r(this,s,"f")}init(){const t=Object.create(null,{init:{get:()=>super.init}});var e;return n(this,void 0,void 0,(function*(){yield null===(e=t.init)||void 0===e?void 0:e.call(this),this.observeAttributes(["project-id","base-url","tenant"],(()=>{r(this,s,"f")&&r(this,i,"m",o).call(this)}))}))}},s=new WeakMap,i=new WeakSet,o=function(){this.logger.debug("creating an sdk instance"),a(this,s,((t,e,i)=>{const s=I(Object.assign(Object.assign({},t),{persistTokens:!0}));return{user:Object.assign(Object.assign({},V({httpClient:s.httpClient,tenant:e,mock:i})),{logout:i?()=>n(void 0,void 0,void 0,(function*(){})):s.logout})}})({projectId:this.projectId,baseUrl:this.baseUrl},this.tenant,"true"===this.mock),"f")},u})),G=t((t=>{const i=e(u({name:"widget",initialState:B,reducers:{},extraReducers:t=>{$.reducer(t),H.reducer(t)},asyncActions:{getMe:$.action,logout:H.action}}),f,h,z)(t);return class extends i{constructor(...t){super(...t),this.state=B,this.subscribe((t=>{this.logger.debug("State update:",t),this.state=t}))}}})),Q=t((t=>{const i=e(g,c({"widget-id":c.missingAttrValidator}))(t);return class extends i{get widgetId(){return this.getAttribute("widget-id")}fetchWidgetPage(t){return n(this,void 0,void 0,(function*(){return(yield this.fetchStaticResource(`user-profile-widget/${this.widgetId}/${t}`,"text")).body}))}}})),X=t((t=>{var s,o,a;return a=class extends(e(h,f,p,v,Q,G)(t)){constructor(){super(...arguments),s.add(this)}onWidgetRootReady(){return n(this,void 0,void 0,(function*(){}))}init(){const t=Object.create(null,{init:{get:()=>super.init}});var e;return n(this,void 0,void 0,(function*(){yield null===(e=t.init)||void 0===e?void 0:e.call(this),yield Promise.all([this.actions.getMe(),r(this,s,"m",o).call(this)]),this.onWidgetRootReady()}))}},s=new WeakSet,o=function(){return n(this,void 0,void 0,(function*(){const t=i(yield this.fetchWidgetPage("root.html"));yield this.loadDescopeUiComponents(t),this.contentRootElement.append(t.content.cloneNode(!0))}))},a})),Y=(t={})=>{const e=i("<descope-wc></descope-wc>");return Object.entries(t).forEach((([t,i])=>{e.content.querySelector("descope-wc").setAttribute(s(t),i)})),e},Z=t((t=>{var i,s,d,l,c,u,f,g,p;return p=class extends(e(G,h,X,m)(t)){constructor(){super(...arguments),i.add(this),s.set(this,void 0),d.set(this,void 0),f.set(this,o((t=>{this.avatar.image=t}))),g.set(this,o((t=>{this.avatar.displayName=t})))}onWidgetRootReady(){const t=Object.create(null,{onWidgetRootReady:{get:()=>super.onWidgetRootReady}});var e;return n(this,void 0,void 0,(function*(){yield null===(e=t.onWidgetRootReady)||void 0===e?void 0:e.call(this),r(this,i,"m",u).call(this),r(this,i,"m",l).call(this),r(this,f,"f").call(this,A(this.state)),r(this,g,"f").call(this,q(this.state)),this.subscribe(r(this,f,"f").bind(this),A),this.subscribe(r(this,g,"f").bind(this),q)}))}},s=new WeakMap,d=new WeakMap,f=new WeakMap,g=new WeakMap,i=new WeakSet,l=function(){a(this,s,this.createModal({"data-id":"update-pic"}),"f"),a(this,d,new y((()=>{var t;return null===(t=r(this,s,"f").ele)||void 0===t?void 0:t.querySelector("descope-wc")}),{logger:this.logger}),"f"),r(this,s,"f").afterClose=r(this,i,"m",c).bind(this),r(this,i,"m",c).call(this)},c=function(){r(this,s,"f").setContent(Y({projectId:this.projectId,flowId:this.avatar.flowId,baseUrl:this.baseUrl})),r(this,d,"f").onSuccess((()=>{r(this,s,"f").close(),this.actions.getMe()}))},u=function(){this.avatar=new R((()=>{var t;return null===(t=this.shadowRoot)||void 0===t?void 0:t.querySelector("descope-avatar")}),{logger:this.logger}),this.avatar.onClick((()=>{r(this,s,"f").open()}))},p})),_=t((t=>{var i,s,d,l,c,u,f,g,p,v,w,b,R;return R=class extends(e(G,h,X,m)(t)){constructor(){super(...arguments),i.add(this),s.set(this,void 0),d.set(this,void 0),l.set(this,void 0),c.set(this,void 0),w.set(this,o((t=>{this.emailUserAttr.value=t}))),b.set(this,o((t=>{this.emailUserAttr.badgeLabel=t?"":"Unverified"})))}onWidgetRootReady(){const t=Object.create(null,{onWidgetRootReady:{get:()=>super.onWidgetRootReady}});var e;return n(this,void 0,void 0,(function*(){yield null===(e=t.onWidgetRootReady)||void 0===e?void 0:e.call(this),r(this,i,"m",v).call(this),r(this,i,"m",u).call(this),r(this,i,"m",g).call(this),r(this,w,"f").call(this,C(this.state)),r(this,b,"f").call(this,x(this.state)),this.subscribe(r(this,w,"f").bind(this),C),this.subscribe(r(this,b,"f").bind(this),x)}))}},s=new WeakMap,d=new WeakMap,l=new WeakMap,c=new WeakMap,w=new WeakMap,b=new WeakMap,i=new WeakSet,u=function(){a(this,s,this.createModal({"data-id":"edit-email"}),"f"),a(this,d,new y((()=>{var t;return null===(t=r(this,s,"f").ele)||void 0===t?void 0:t.querySelector("descope-wc")}),{logger:this.logger}),"f"),r(this,s,"f").afterClose=r(this,i,"m",f).bind(this),r(this,i,"m",f).call(this)},f=function(){r(this,s,"f").setContent(Y({projectId:this.projectId,flowId:this.emailUserAttr.editFlowId,baseUrl:this.baseUrl})),r(this,d,"f").onSuccess((()=>{r(this,s,"f").close(),this.actions.getMe()}))},g=function(){a(this,l,this.createModal({"data-id":"delete-email"}),"f"),a(this,c,new y((()=>{var t;return null===(t=r(this,l,"f").ele)||void 0===t?void 0:t.querySelector("descope-wc")}),{logger:this.logger}),"f"),r(this,l,"f").afterClose=r(this,i,"m",p).bind(this),r(this,i,"m",p).call(this)},p=function(){r(this,l,"f").setContent(Y({projectId:this.projectId,flowId:this.emailUserAttr.deleteFlowId,baseUrl:this.baseUrl})),r(this,c,"f").onSuccess((()=>{r(this,l,"f").close(),this.actions.getMe()}))},v=function(){this.emailUserAttr=new W((()=>{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((()=>{r(this,s,"f").open()})),this.emailUserAttr.onDeleteClick((()=>{r(this,l,"f").open()}))},R})),tt=t((t=>{var i,s,d,l,c,u,f,g,p,v,w,b;return b=class extends(e(G,h,X,m)(t)){constructor(){super(...arguments),i.add(this),s.set(this,void 0),d.set(this,void 0),l.set(this,void 0),c.set(this,void 0),w.set(this,o((t=>{this.nameUserAttr.value=t})))}onWidgetRootReady(){const t=Object.create(null,{onWidgetRootReady:{get:()=>super.onWidgetRootReady}});var e;return n(this,void 0,void 0,(function*(){yield null===(e=t.onWidgetRootReady)||void 0===e?void 0:e.call(this),r(this,i,"m",v).call(this),r(this,i,"m",u).call(this),r(this,i,"m",g).call(this),r(this,w,"f").call(this,q(this.state)),this.subscribe(r(this,w,"f").bind(this),q)}))}},s=new WeakMap,d=new WeakMap,l=new WeakMap,c=new WeakMap,w=new WeakMap,i=new WeakSet,u=function(){a(this,s,this.createModal({"data-id":"edit-name"}),"f"),a(this,d,new y((()=>{var t;return null===(t=r(this,s,"f").ele)||void 0===t?void 0:t.querySelector("descope-wc")}),{logger:this.logger}),"f"),r(this,s,"f").afterClose=r(this,i,"m",f).bind(this),r(this,i,"m",f).call(this)},f=function(){r(this,s,"f").setContent(Y({projectId:this.projectId,flowId:this.nameUserAttr.editFlowId,baseUrl:this.baseUrl})),r(this,d,"f").onSuccess((()=>{r(this,s,"f").close(),this.actions.getMe()}))},g=function(){a(this,l,this.createModal({"data-id":"delete-name"}),"f"),a(this,c,new y((()=>{var t;return null===(t=r(this,l,"f").ele)||void 0===t?void 0:t.querySelector("descope-wc")}),{logger:this.logger}),"f"),r(this,l,"f").afterClose=r(this,i,"m",p).bind(this),r(this,i,"m",p).call(this)},p=function(){r(this,l,"f").setContent(Y({projectId:this.projectId,flowId:this.nameUserAttr.deleteFlowId,baseUrl:this.baseUrl})),r(this,c,"f").onSuccess((()=>{r(this,l,"f").close(),this.actions.getMe()}))},v=function(){this.nameUserAttr=new W((()=>{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((()=>{r(this,s,"f").open()})),this.nameUserAttr.onDeleteClick((()=>{r(this,l,"f").open()}))},b})),et=t((t=>{var i,s,d,l,c,u,f,g,p,v,w,b,R;return R=class extends(e(G,h,X,m)(t)){constructor(){super(...arguments),i.add(this),s.set(this,void 0),d.set(this,void 0),l.set(this,void 0),c.set(this,void 0),w.set(this,o((t=>{this.phoneUserAttr.value=t}))),b.set(this,o((t=>{this.phoneUserAttr.badgeLabel=t?"":"Unverified"})))}onWidgetRootReady(){const t=Object.create(null,{onWidgetRootReady:{get:()=>super.onWidgetRootReady}});var e;return n(this,void 0,void 0,(function*(){yield null===(e=t.onWidgetRootReady)||void 0===e?void 0:e.call(this),r(this,i,"m",v).call(this),r(this,i,"m",u).call(this),r(this,i,"m",g).call(this),r(this,w,"f").call(this,O(this.state)),r(this,b,"f").call(this,E(this.state)),this.subscribe(r(this,w,"f").bind(this),O),this.subscribe(r(this,b,"f").bind(this),E)}))}},s=new WeakMap,d=new WeakMap,l=new WeakMap,c=new WeakMap,w=new WeakMap,b=new WeakMap,i=new WeakSet,u=function(){a(this,s,this.createModal({"data-id":"edit-phone"}),"f"),a(this,d,new y((()=>{var t;return null===(t=r(this,s,"f").ele)||void 0===t?void 0:t.querySelector("descope-wc")}),{logger:this.logger}),"f"),r(this,s,"f").afterClose=r(this,i,"m",f).bind(this),r(this,i,"m",f).call(this)},f=function(){r(this,s,"f").setContent(Y({projectId:this.projectId,flowId:this.phoneUserAttr.editFlowId,baseUrl:this.baseUrl})),r(this,d,"f").onSuccess((()=>{r(this,s,"f").close(),this.actions.getMe()}))},g=function(){a(this,l,this.createModal({"data-id":"delete-phone"}),"f"),a(this,c,new y((()=>{var t;return null===(t=r(this,l,"f").ele)||void 0===t?void 0:t.querySelector("descope-wc")}),{logger:this.logger}),"f"),r(this,l,"f").afterClose=r(this,i,"m",p).bind(this),r(this,i,"m",p).call(this)},p=function(){r(this,l,"f").setContent(Y({projectId:this.projectId,flowId:this.phoneUserAttr.deleteFlowId,baseUrl:this.baseUrl})),r(this,c,"f").onSuccess((()=>{r(this,l,"f").close(),this.actions.getMe()}))},v=function(){this.phoneUserAttr=new W((()=>{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((()=>{r(this,s,"f").open()})),this.phoneUserAttr.onDeleteClick((()=>{r(this,l,"f").open()}))},R})),it=t((t=>{var i,s,d,l,c,u,f,g;return g=class extends(e(G,h,X,m)(t)){constructor(){super(...arguments),i.add(this),s.set(this,void 0),d.set(this,void 0),f.set(this,o((t=>{this.passkeyUserAuthMethod.fulfilled=t})))}onWidgetRootReady(){const t=Object.create(null,{onWidgetRootReady:{get:()=>super.onWidgetRootReady}});var e;return n(this,void 0,void 0,(function*(){yield null===(e=t.onWidgetRootReady)||void 0===e?void 0:e.call(this),r(this,i,"m",u).call(this),r(this,i,"m",l).call(this),r(this,f,"f").call(this,P(this.state)),this.subscribe(r(this,f,"f").bind(this),P)}))}},s=new WeakMap,d=new WeakMap,f=new WeakMap,i=new WeakSet,l=function(){a(this,s,this.createModal({"data-id":"passkey"}),"f"),a(this,d,new y((()=>{var t;return null===(t=r(this,s,"f").ele)||void 0===t?void 0:t.querySelector("descope-wc")}),{logger:this.logger}),"f"),r(this,s,"f").afterClose=r(this,i,"m",c).bind(this),r(this,i,"m",c).call(this)},c=function(){r(this,s,"f").setContent(Y({projectId:this.projectId,flowId:this.passkeyUserAuthMethod.flowId,baseUrl:this.baseUrl})),r(this,d,"f").onSuccess((()=>{r(this,s,"f").close(),this.actions.getMe()}))},u=function(){this.passkeyUserAuthMethod=new k((()=>{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((()=>{r(this,s,"f").open()}))},g})),st=t((t=>{var i,s,o,d,l,c,u;return u=class extends(e(G,h,X,m)(t)){constructor(){super(...arguments),i.add(this),s.set(this,void 0),o.set(this,void 0)}onWidgetRootReady(){const t=Object.create(null,{onWidgetRootReady:{get:()=>super.onWidgetRootReady}});var e;return n(this,void 0,void 0,(function*(){yield null===(e=t.onWidgetRootReady)||void 0===e?void 0:e.call(this),r(this,i,"m",c).call(this),r(this,i,"m",d).call(this)}))}},s=new WeakMap,o=new WeakMap,i=new WeakSet,d=function(){a(this,s,this.createModal({"data-id":"password"}),"f"),a(this,o,new y((()=>{var t;return null===(t=r(this,s,"f").ele)||void 0===t?void 0:t.querySelector("descope-wc")}),{logger:this.logger}),"f"),r(this,s,"f").afterClose=r(this,i,"m",l).bind(this),r(this,i,"m",l).call(this)},l=function(){r(this,s,"f").setContent(Y({projectId:this.projectId,flowId:this.passwordUserAuthMethod.flowId,baseUrl:this.baseUrl})),r(this,o,"f").onSuccess((()=>{r(this,s,"f").close()}))},c=function(){this.passwordUserAuthMethod=new k((()=>{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((()=>{r(this,s,"f").open()}))},u})),ot=t((t=>{var i,s,o;return o=class extends(e(G,h,X,m)(t)){constructor(){super(...arguments),i.add(this)}onWidgetRootReady(){const t=Object.create(null,{onWidgetRootReady:{get:()=>super.onWidgetRootReady}});var e;return n(this,void 0,void 0,(function*(){yield null===(e=t.onWidgetRootReady)||void 0===e?void 0:e.call(this),r(this,i,"m",s).call(this)}))}},i=new WeakSet,s=function(){this.logout=new M((()=>{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((()=>n(this,void 0,void 0,(function*(){yield this.actions.logout(),this.dispatchEvent(new CustomEvent("logout"))}))))},o})),nt=t((t=>class extends(e(w,b,Z,_,tt,et,it,st,ot)(t)){init(){const t=Object.create(null,{init:{get:()=>super.init}});var e;return n(this,void 0,void 0,(function*(){yield null===(e=t.init)||void 0===e?void 0:e.call(this)}))}})),rt=e((t=>class extends(nt(t)){}))(HTMLElement);customElements.define("descope-user-profile-widget",rt);export{rt as default};
6
6
  //# sourceMappingURL=index.js.map