@descope/user-profile-widget 0.0.0-next-0e292820-20250415

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 Descope <help@descope.com>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,100 @@
1
+ # @descope/user-profile-widget
2
+
3
+ ## Setup
4
+
5
+ ### Create an `.env` file
6
+
7
+ In the widget package create an `.env` file which includes;
8
+
9
+ ```
10
+ DESCOPE_BASE_URL= # env base url
11
+ DESCOPE_PROJECT_ID= # project ID
12
+ DESCOPE_WIDGET_ID= # default: user-profile-widget
13
+ DEBUG_MODE= # "true" / "false", default: "false"
14
+ DESCOPE_THEME= # "light" / "dark" / "os", default: "light"
15
+ ```
16
+
17
+ ### Example
18
+
19
+ ```
20
+ // replace x.x.x with the latest release of the widget: https://www.npmjs.com/package/@descope/user-profile-widget
21
+ <script src="https://descopecdn.com/npm/@descope/user-profile-widget@x.x.x/dist/index.js"></script>
22
+ <descope-user-profile-widget
23
+ base-url="<DESCOPE_BASE_URL>"
24
+ project-id="<DESCOPE_PROJECT_ID>"
25
+ tenant="<DESCOPE_TENANT>"
26
+ debug="<DEBUG_MODE>"
27
+ theme="<DESCOPE_THEME>"
28
+ widget-id="<DESCOPE_WIDGET_ID>"
29
+ ></descope-user-profile-widget>
30
+
31
+ <script>
32
+ function onLogout(error) {
33
+ window.location.reload();
34
+ }
35
+ const descopeWidgetEle = document.getElementsByTagName('descope-user-profile-widget')[0];
36
+ descopeWidgetEle.logout = onLogout;
37
+ </script>
38
+ ```
39
+
40
+ ### Authenticate
41
+
42
+ In order to work with the widget, you must be logged in
43
+ In case you are not authenticated, a login flow will run first, and after logging in, the widget will be rendered
44
+
45
+ ### Start the widget
46
+
47
+ run `npm start` to start the widget.
48
+
49
+ ## Architecture
50
+
51
+ ## Project Structure
52
+
53
+ - `/app` - contains `index.html`
54
+ - `/lib` - widget's source code
55
+ - `lib/widget` - widget related implementations
56
+ - `lib/widget/api` - Logic related to API calls
57
+ - `lib/widget/mixins` - Widget specific logic
58
+ - `lib/widget/state` - State management logic
59
+
60
+ ### API
61
+
62
+ ---
63
+
64
+ ### Mixins
65
+
66
+ The widget is composed of mixins, each mixin contains specific logic parts, and sometime exposes an API that can be used in other mixins.
67
+
68
+ Mixins can be composed on top of each other, so we can create new mixins by composing several mixins together.
69
+
70
+ #### Mixins Creators
71
+
72
+ Functions that create mixins, can get a configuration, and returns the mixin functions.
73
+
74
+ #### Singleton Mixin
75
+
76
+ Since mixins are composable, in some cases we want to make sure a mixin is loaded only once. For example: When there is no need for its logic to run multiple times when composed in different mixins.
77
+
78
+ For this case we have a wrapper function (`createSingletonMixin`) to ensure that a mixin is loaded only once, regardless how many times it will be composed.
79
+
80
+ Mixins should be wrapped with the `createSingletonMixin` wrapper function, unless there is a reason for running the mixin's logic multiple times.
81
+
82
+ ### State
83
+
84
+ We're using several tools to handle the widget's state:
85
+
86
+ - [Redux Toolkit](https://redux-toolkit.js.org/) for the widget's state management.
87
+ - [Redux Thunk](https://github.com/reduxjs/redux-thunk) for API calls and async operations we're using
88
+ - [Reselect](https://github.com/reduxjs/reselect) to compute derived data without hitting performance or triggering state recalculation when state is not mutated.
89
+
90
+ ### Drivers
91
+
92
+ An abstraction layer that provides an API for components, and enables handling interactions with components within the widget.
93
+
94
+ The motivation to use drivers is to decouple the widget's code from the component's implementation, and therefore it's important to interact with components only using drivers (and not relying on component's implementation details).
95
+
96
+ ## Dev
97
+
98
+ ### Use mock screens
99
+
100
+ Since screen are fetched dynamically, when developing a new screen for the widget you will probably want to use mock templates. To do so, simply replace the call to `fetchWidgetPage` with a string which includes your HTML.
@@ -0,0 +1,6 @@
1
+
2
+ /**
3
+ * @descope/user-profile-widget v0.4.16
4
+ */
5
+ "use strict";var e=require("tslib"),t=require("@descope/sdk-helpers"),i=require("@descope/sdk-mixins"),s=require("@descope/sdk-component-drivers"),a=require("@reduxjs/toolkit");require("@descope/core-js-sdk");var r=require("@descope/web-js-sdk"),l=require("reselect");require("@descope/web-component");const o=(e={})=>{const i=t.createTemplate("<descope-wc></descope-wc>");return Object.entries(e).forEach((([e,s])=>{i.content.querySelector("descope-wc").setAttribute(t.kebabCase(e),s)})),i};function d(e){return new URLSearchParams(window.location.search).get(e)}const n=e=>(...t)=>i=>{i.addCase(e.pending,((e,i)=>{t.forEach((({onPending:t})=>{null==t||t(e,i)}))})),i.addCase(e.fulfilled,((e,i)=>{t.forEach((({onFulfilled:t})=>{null==t||t(e,i)}))})),i.addCase(e.rejected,((e,i)=>{t.forEach((({onRejected:t})=>{null==t||t(e,i)}))}))},c=a.createAsyncThunk("users/me",((e,{extra:{api:t}})=>t.user.me())),h=n(c)({onFulfilled:(e,t)=>{e.me.data=t.payload}},(v=e=>e.me,{onFulfilled:e=>{v(e).loading=!1},onPending:e=>{v(e).loading=!0,v(e).error=null},onRejected:(e,t)=>{v(e).loading=!1,v(e).error=t.error}}));var v;const u={action:c,reducer:h},_=a.createAsyncThunk("users/logout",((e,{extra:{api:t}})=>t.user.logout())),f={action:_,reducer:n(_)({})},g={me:{loading:!1,error:null,data:{}}},m={me:"/v1/auth/me"},p=()=>e.__awaiter(void 0,void 0,void 0,(function*(){return new Promise((e=>{e({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})}))})),w=({httpClient:t,mock:i})=>({me:()=>e.__awaiter(void 0,void 0,void 0,(function*(){if(i)return p();const s=yield t.get(m.me);return yield(t=>e.__awaiter(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)})))(s),s.json()}))}),F=t.createSingletonMixin((s=>{var a,l,o,d;const n=t.compose(i.projectIdMixin,i.observeAttributesMixin,i.loggerMixin,i.baseUrlMixin,i.cookieConfigMixin)(s);return d=class extends n{constructor(){super(...arguments),a.add(this),l.set(this,void 0)}get widgetId(){return this.getAttribute("widget-id")}get mock(){return this.getAttribute("mock")}get api(){return e.__classPrivateFieldGet(this,l,"f")||e.__classPrivateFieldGet(this,a,"m",o).call(this),e.__classPrivateFieldGet(this,l,"f")}init(){const t=Object.create(null,{init:{get:()=>super.init}});return e.__awaiter(this,void 0,void 0,(function*(){var i;yield null===(i=t.init)||void 0===i?void 0:i.call(this),this.observeAttributes(["project-id","base-url"],(()=>{e.__classPrivateFieldGet(this,l,"f")&&e.__classPrivateFieldGet(this,a,"m",o).call(this)}))}))}},l=new WeakMap,a=new WeakSet,o=function(){this.logger.debug("creating an sdk instance"),e.__classPrivateFieldSet(this,l,((t,i,s)=>{const a=r(Object.assign(Object.assign({},t),{persistTokens:!0,baseHeaders:{"x-descope-widget-type":"user-profile-widget","x-descope-widget-id":s,"x-descope-widget-version":"0.4.16"}}));return{user:Object.assign(Object.assign({},w({httpClient:a.httpClient,mock:i})),{logout:i?()=>e.__awaiter(void 0,void 0,void 0,(function*(){})):a.logout})}})({projectId:this.projectId,baseUrl:this.baseUrl,refreshCookieName:this.refreshCookieName},"true"===this.mock,this.widgetId),"f")},d})),b=t.createSingletonMixin((e=>{const s=t.compose(i.createStateManagementMixin({name:"widget",initialState:g,reducers:{},extraReducers:e=>{u.reducer(e),f.reducer(e)},asyncActions:{getMe:u.action,logout:f.action}}),i.initLifecycleMixin,i.loggerMixin,F)(e);return class extends s{constructor(...e){super(...e),this.state=g,this.subscribe((e=>{this.logger.debug("State update:",e),this.state=e}))}}})),P="widget-flow",M=t.createSingletonMixin((a=>{var r,l,n;return n=class extends(t.compose(i.initLifecycleMixin,i.modalMixin,b,i.cookieConfigMixin,i.loggerMixin,i.themeMixin)(a)){constructor(){super(...arguments),r.add(this)}init(){const t=Object.create(null,{init:{get:()=>super.init}});return e.__awaiter(this,void 0,void 0,(function*(){var i;yield null===(i=t.init)||void 0===i?void 0:i.call(this);const s=d(P);s&&(!function(e){if(window.history.replaceState&&d(e)){const t=new URL(window.location.href),i=new URLSearchParams(t.search);i.delete(e),t.search=i.toString(),window.history.replaceState({},"",t.toString())}}(P),e.__classPrivateFieldGet(this,r,"m",l).call(this,s))}))}},r=new WeakSet,l=function(e){const t=this.createModal({"data-id":"redirect-flow"});t.setContent(o({projectId:this.projectId,flowId:e,baseUrl:this.baseUrl,baseStaticUrl:this.baseStaticUrl,baseCdnUrl:this.baseCdnUrl,refreshCookieName:this.refreshCookieName,theme:this.theme}));new s.FlowDriver((()=>{var e;return null===(e=t.ele)||void 0===e?void 0:e.querySelector("descope-wc")}),{logger:this.logger}).onSuccess((()=>{t.close(),this.actions.getMe()})),t.afterClose=()=>{t.remove()},t.open()},n})),G=e=>e.me.data,S=l.createSelector(G,(e=>e.picture)),U=l.createSelector(G,(e=>e.email)),y=l.createSelector(G,(e=>e.verifiedEmail)),C=l.createSelector(G,(e=>e.name)),k=l.createSelector(G,(e=>e.phone)),x=l.createSelector(G,(e=>e.verifiedPhone)),R=l.createSelector(G,(e=>e.webauthn));l.createSelector(G,(e=>e.password));const W=l.createSelector(G,(e=>e.TOTP)),A=l.createSelector(G,(e=>e.customAttributes)),I=t.createSingletonMixin((s=>{const a=t.compose(i.staticResourcesMixin,i.createValidateAttributesMixin({"widget-id":i.createValidateAttributesMixin.missingAttrValidator}))(s);return class extends a{get widgetId(){return this.getAttribute("widget-id")}fetchWidgetPage(t){return e.__awaiter(this,void 0,void 0,(function*(){return(yield this.fetchStaticResource(`user-profile-widget/${this.widgetId}/${t}`,"text")).body}))}}})),j=t.createSingletonMixin((s=>{var a,r,l;return l=class extends(t.compose(i.loggerMixin,i.initLifecycleMixin,i.descopeUiMixin,i.initElementMixin,I,b)(s)){constructor(){super(...arguments),a.add(this)}onWidgetRootReady(){return e.__awaiter(this,void 0,void 0,(function*(){}))}init(){const t=Object.create(null,{init:{get:()=>super.init}});return e.__awaiter(this,void 0,void 0,(function*(){var i;yield null===(i=t.init)||void 0===i?void 0:i.call(this),yield Promise.all([this.actions.getMe(),e.__classPrivateFieldGet(this,a,"m",r).call(this)]),this.onWidgetRootReady()}))}},a=new WeakSet,r=function(){return e.__awaiter(this,void 0,void 0,(function*(){const e=t.createTemplate(yield this.fetchWidgetPage("root.html"));yield this.loadDescopeUiComponents(e),this.contentRootElement.append(e.content.cloneNode(!0))}))},l})),N=t.createSingletonMixin((e=>class extends(t.compose(i.themeMixin,i.observeAttributesMixin)(e)){syncFlowTheme(e){e.theme=this.theme,this.observeAttributes(["theme"],(()=>{e.theme=this.theme}))}})),T=t.createSingletonMixin((a=>{var r,l,d,n,c,h,v,u,_;return _=class extends(t.compose(N,i.themeMixin,b,i.loggerMixin,i.cookieConfigMixin,j,i.modalMixin)(a)){constructor(){super(...arguments),r.add(this),l.set(this,void 0),d.set(this,void 0),v.set(this,t.withMemCache((e=>{this.avatar.image=e}))),u.set(this,t.withMemCache((e=>{this.avatar.displayName=e})))}onWidgetRootReady(){const t=Object.create(null,{onWidgetRootReady:{get:()=>super.onWidgetRootReady}});return e.__awaiter(this,void 0,void 0,(function*(){var i;yield null===(i=t.onWidgetRootReady)||void 0===i?void 0:i.call(this),e.__classPrivateFieldGet(this,r,"m",h).call(this),e.__classPrivateFieldGet(this,r,"m",n).call(this),e.__classPrivateFieldGet(this,v,"f").call(this,S(this.state)),e.__classPrivateFieldGet(this,u,"f").call(this,C(this.state)),this.subscribe(e.__classPrivateFieldGet(this,v,"f").bind(this),S),this.subscribe(e.__classPrivateFieldGet(this,u,"f").bind(this),C)}))}},l=new WeakMap,d=new WeakMap,v=new WeakMap,u=new WeakMap,r=new WeakSet,n=function(){this.avatar.flowId&&(e.__classPrivateFieldSet(this,l,this.createModal({"data-id":"update-pic"}),"f"),e.__classPrivateFieldSet(this,d,new s.FlowDriver((()=>{var t;return null===(t=e.__classPrivateFieldGet(this,l,"f").ele)||void 0===t?void 0:t.querySelector("descope-wc")}),{logger:this.logger}),"f"),e.__classPrivateFieldGet(this,l,"f").afterClose=e.__classPrivateFieldGet(this,r,"m",c).bind(this),e.__classPrivateFieldGet(this,r,"m",c).call(this),this.syncFlowTheme(e.__classPrivateFieldGet(this,d,"f")))},c=function(){e.__classPrivateFieldGet(this,l,"f").setContent(o({projectId:this.projectId,flowId:this.avatar.flowId,baseUrl:this.baseUrl,baseStaticUrl:this.baseStaticUrl,baseCdnUrl:this.baseCdnUrl,refreshCookieName:this.refreshCookieName,theme:this.theme})),e.__classPrivateFieldGet(this,d,"f").onSuccess((()=>{e.__classPrivateFieldGet(this,l,"f").close(),this.actions.getMe()}))},h=function(){this.avatar=new s.AvatarDriver((()=>{var e;return null===(e=this.shadowRoot)||void 0===e?void 0:e.querySelector("descope-avatar")}),{logger:this.logger}),this.avatar.onClick((()=>{var t;null===(t=e.__classPrivateFieldGet(this,l,"f"))||void 0===t||t.open()}))},_})),q=t.createSingletonMixin((a=>{var r,l,d,n,c,h,v,u,_,f,g,m,p;return p=class extends(t.compose(N,b,i.loggerMixin,j,i.cookieConfigMixin,i.modalMixin)(a)){constructor(){super(...arguments),r.add(this),l.set(this,void 0),d.set(this,void 0),n.set(this,void 0),c.set(this,void 0),g.set(this,t.withMemCache((e=>{this.emailUserAttr.value=e}))),m.set(this,t.withMemCache((e=>{this.emailUserAttr.badgeLabel=e?"":"Unverified"})))}onWidgetRootReady(){const t=Object.create(null,{onWidgetRootReady:{get:()=>super.onWidgetRootReady}});return e.__awaiter(this,void 0,void 0,(function*(){var i;yield null===(i=t.onWidgetRootReady)||void 0===i?void 0:i.call(this),e.__classPrivateFieldGet(this,r,"m",f).call(this),e.__classPrivateFieldGet(this,r,"m",h).call(this),e.__classPrivateFieldGet(this,r,"m",u).call(this),e.__classPrivateFieldGet(this,g,"f").call(this,U(this.state)),e.__classPrivateFieldGet(this,m,"f").call(this,y(this.state)),this.subscribe(e.__classPrivateFieldGet(this,g,"f").bind(this),U),this.subscribe(e.__classPrivateFieldGet(this,m,"f").bind(this),y)}))}},l=new WeakMap,d=new WeakMap,n=new WeakMap,c=new WeakMap,g=new WeakMap,m=new WeakMap,r=new WeakSet,h=function(){this.emailUserAttr.editFlowId&&(e.__classPrivateFieldSet(this,l,this.createModal({"data-id":"edit-email"}),"f"),e.__classPrivateFieldSet(this,d,new s.FlowDriver((()=>{var t;return null===(t=e.__classPrivateFieldGet(this,l,"f").ele)||void 0===t?void 0:t.querySelector("descope-wc")}),{logger:this.logger}),"f"),e.__classPrivateFieldGet(this,l,"f").afterClose=e.__classPrivateFieldGet(this,r,"m",v).bind(this),e.__classPrivateFieldGet(this,r,"m",v).call(this),this.syncFlowTheme(e.__classPrivateFieldGet(this,d,"f")))},v=function(){e.__classPrivateFieldGet(this,l,"f").setContent(o({projectId:this.projectId,flowId:this.emailUserAttr.editFlowId,baseUrl:this.baseUrl,baseStaticUrl:this.baseStaticUrl,baseCdnUrl:this.baseCdnUrl,refreshCookieName:this.refreshCookieName,theme:this.theme})),e.__classPrivateFieldGet(this,d,"f").onSuccess((()=>{e.__classPrivateFieldGet(this,l,"f").close(),this.actions.getMe()}))},u=function(){this.emailUserAttr.deleteFlowId&&(e.__classPrivateFieldSet(this,n,this.createModal({"data-id":"delete-email"}),"f"),e.__classPrivateFieldSet(this,c,new s.FlowDriver((()=>{var t;return null===(t=e.__classPrivateFieldGet(this,n,"f").ele)||void 0===t?void 0:t.querySelector("descope-wc")}),{logger:this.logger}),"f"),e.__classPrivateFieldGet(this,n,"f").afterClose=e.__classPrivateFieldGet(this,r,"m",_).bind(this),e.__classPrivateFieldGet(this,r,"m",_).call(this),this.syncFlowTheme(e.__classPrivateFieldGet(this,c,"f")))},_=function(){e.__classPrivateFieldGet(this,n,"f").setContent(o({projectId:this.projectId,flowId:this.emailUserAttr.deleteFlowId,baseUrl:this.baseUrl,baseStaticUrl:this.baseStaticUrl,baseCdnUrl:this.baseCdnUrl,refreshCookieName:this.refreshCookieName,theme:this.theme})),e.__classPrivateFieldGet(this,c,"f").onSuccess((()=>{e.__classPrivateFieldGet(this,n,"f").close(),this.actions.getMe()}))},f=function(){this.emailUserAttr=new s.UserAttributeDriver((()=>{var e;return null===(e=this.shadowRoot)||void 0===e?void 0:e.querySelector('descope-user-attribute[data-id="email"]')}),{logger:this.logger}),this.emailUserAttr.onEditClick((()=>{var t;null===(t=e.__classPrivateFieldGet(this,l,"f"))||void 0===t||t.open()})),this.emailUserAttr.onDeleteClick((()=>{var t;null===(t=e.__classPrivateFieldGet(this,n,"f"))||void 0===t||t.open()}))},p})),D=t.createSingletonMixin((a=>{var r,l,o;return o=class extends(t.compose(b,i.loggerMixin,j,i.modalMixin)(a)){constructor(){super(...arguments),r.add(this)}onWidgetRootReady(){const t=Object.create(null,{onWidgetRootReady:{get:()=>super.onWidgetRootReady}});return e.__awaiter(this,void 0,void 0,(function*(){var i;yield null===(i=t.onWidgetRootReady)||void 0===i?void 0:i.call(this),e.__classPrivateFieldGet(this,r,"m",l).call(this)}))}},r=new WeakSet,l=function(){this.logout=new s.ButtonDriver((()=>{var e;return null===(e=this.shadowRoot)||void 0===e?void 0:e.querySelector('descope-button[data-id="logout"]')}),{logger:this.logger}),this.logout.onClick((()=>e.__awaiter(this,void 0,void 0,(function*(){yield this.actions.logout(),this.dispatchEvent(new CustomEvent("logout"))}))))},o})),E=t.createSingletonMixin((a=>{var r,l,d,n,c,h,v,u,_,f,g,m;return m=class extends(t.compose(N,b,i.loggerMixin,j,i.cookieConfigMixin,i.modalMixin)(a)){constructor(){super(...arguments),r.add(this),l.set(this,void 0),d.set(this,void 0),n.set(this,void 0),c.set(this,void 0),g.set(this,t.withMemCache((e=>{this.nameUserAttr.value=e})))}onWidgetRootReady(){const t=Object.create(null,{onWidgetRootReady:{get:()=>super.onWidgetRootReady}});return e.__awaiter(this,void 0,void 0,(function*(){var i;yield null===(i=t.onWidgetRootReady)||void 0===i?void 0:i.call(this),e.__classPrivateFieldGet(this,r,"m",f).call(this),e.__classPrivateFieldGet(this,r,"m",h).call(this),e.__classPrivateFieldGet(this,r,"m",u).call(this),e.__classPrivateFieldGet(this,g,"f").call(this,C(this.state)),this.subscribe(e.__classPrivateFieldGet(this,g,"f").bind(this),C)}))}},l=new WeakMap,d=new WeakMap,n=new WeakMap,c=new WeakMap,g=new WeakMap,r=new WeakSet,h=function(){this.nameUserAttr.editFlowId&&(e.__classPrivateFieldSet(this,l,this.createModal({"data-id":"edit-name"}),"f"),e.__classPrivateFieldSet(this,d,new s.FlowDriver((()=>{var t;return null===(t=e.__classPrivateFieldGet(this,l,"f").ele)||void 0===t?void 0:t.querySelector("descope-wc")}),{logger:this.logger}),"f"),e.__classPrivateFieldGet(this,l,"f").afterClose=e.__classPrivateFieldGet(this,r,"m",v).bind(this),e.__classPrivateFieldGet(this,r,"m",v).call(this),this.syncFlowTheme(e.__classPrivateFieldGet(this,d,"f")))},v=function(){e.__classPrivateFieldGet(this,l,"f").setContent(o({projectId:this.projectId,flowId:this.nameUserAttr.editFlowId,baseUrl:this.baseUrl,baseStaticUrl:this.baseStaticUrl,baseCdnUrl:this.baseCdnUrl,refreshCookieName:this.refreshCookieName,theme:this.theme})),e.__classPrivateFieldGet(this,d,"f").onSuccess((()=>{e.__classPrivateFieldGet(this,l,"f").close(),this.actions.getMe()}))},u=function(){this.nameUserAttr.deleteFlowId&&(e.__classPrivateFieldSet(this,n,this.createModal({"data-id":"delete-name"}),"f"),e.__classPrivateFieldSet(this,c,new s.FlowDriver((()=>{var t;return null===(t=e.__classPrivateFieldGet(this,n,"f").ele)||void 0===t?void 0:t.querySelector("descope-wc")}),{logger:this.logger}),"f"),e.__classPrivateFieldGet(this,n,"f").afterClose=e.__classPrivateFieldGet(this,r,"m",_).bind(this),e.__classPrivateFieldGet(this,r,"m",_).call(this),this.syncFlowTheme(e.__classPrivateFieldGet(this,c,"f")))},_=function(){e.__classPrivateFieldGet(this,n,"f").setContent(o({projectId:this.projectId,flowId:this.nameUserAttr.deleteFlowId,baseUrl:this.baseUrl,baseStaticUrl:this.baseStaticUrl,baseCdnUrl:this.baseCdnUrl,refreshCookieName:this.refreshCookieName,theme:this.theme})),e.__classPrivateFieldGet(this,c,"f").onSuccess((()=>{e.__classPrivateFieldGet(this,n,"f").close(),this.actions.getMe()}))},f=function(){this.nameUserAttr=new s.UserAttributeDriver((()=>{var e;return null===(e=this.shadowRoot)||void 0===e?void 0:e.querySelector('descope-user-attribute[data-id="name"]')}),{logger:this.logger}),this.nameUserAttr.onEditClick((()=>{var t;null===(t=e.__classPrivateFieldGet(this,l,"f"))||void 0===t||t.open()})),this.nameUserAttr.onDeleteClick((()=>{var t;null===(t=e.__classPrivateFieldGet(this,n,"f"))||void 0===t||t.open()}))},m})),O=t.createSingletonMixin((a=>{var r,l,d,n,c,h,v,u;return u=class extends(t.compose(N,b,i.loggerMixin,j,i.cookieConfigMixin,i.modalMixin)(a)){constructor(){super(...arguments),r.add(this),l.set(this,void 0),d.set(this,void 0),v.set(this,t.withMemCache((e=>{this.passkeyUserAuthMethod.fulfilled=e})))}onWidgetRootReady(){const t=Object.create(null,{onWidgetRootReady:{get:()=>super.onWidgetRootReady}});return e.__awaiter(this,void 0,void 0,(function*(){var i;yield null===(i=t.onWidgetRootReady)||void 0===i?void 0:i.call(this),e.__classPrivateFieldGet(this,r,"m",h).call(this),e.__classPrivateFieldGet(this,r,"m",n).call(this),e.__classPrivateFieldGet(this,v,"f").call(this,R(this.state)),this.subscribe(e.__classPrivateFieldGet(this,v,"f").bind(this),R)}))}},l=new WeakMap,d=new WeakMap,v=new WeakMap,r=new WeakSet,n=function(){this.passkeyUserAuthMethod.flowId&&(e.__classPrivateFieldSet(this,l,this.createModal({"data-id":"passkey"}),"f"),e.__classPrivateFieldSet(this,d,new s.FlowDriver((()=>{var t;return null===(t=e.__classPrivateFieldGet(this,l,"f").ele)||void 0===t?void 0:t.querySelector("descope-wc")}),{logger:this.logger}),"f"),e.__classPrivateFieldGet(this,l,"f").afterClose=e.__classPrivateFieldGet(this,r,"m",c).bind(this),e.__classPrivateFieldGet(this,r,"m",c).call(this),this.syncFlowTheme(e.__classPrivateFieldGet(this,d,"f")))},c=function(){e.__classPrivateFieldGet(this,l,"f").setContent(o({projectId:this.projectId,flowId:this.passkeyUserAuthMethod.flowId,baseUrl:this.baseUrl,baseStaticUrl:this.baseStaticUrl,baseCdnUrl:this.baseCdnUrl,refreshCookieName:this.refreshCookieName,theme:this.theme})),e.__classPrivateFieldGet(this,d,"f").onSuccess((()=>{e.__classPrivateFieldGet(this,l,"f").close(),this.actions.getMe()}))},h=function(){this.passkeyUserAuthMethod=new s.UserAuthMethodDriver((()=>{var e;return null===(e=this.shadowRoot)||void 0===e?void 0:e.querySelector('descope-user-auth-method[data-id="passkey"]')}),{logger:this.logger}),this.passkeyUserAuthMethod.onButtonClick((()=>{var t;null===(t=e.__classPrivateFieldGet(this,l,"f"))||void 0===t||t.open()}))},u})),L=t.createSingletonMixin((a=>{var r,l,d,n,c,h;return h=class extends(t.compose(N,b,i.loggerMixin,j,i.cookieConfigMixin,i.modalMixin)(a)){constructor(){super(...arguments),r.add(this),l.set(this,void 0),d.set(this,void 0)}initPasswordAuthMethod(){this.passwordUserAuthMethod=new s.UserAuthMethodDriver((()=>{var e;return null===(e=this.shadowRoot)||void 0===e?void 0:e.querySelector('descope-user-auth-method[data-id="password"]')}),{logger:this.logger}),this.passwordUserAuthMethod.onButtonClick((()=>{var t;null===(t=e.__classPrivateFieldGet(this,l,"f"))||void 0===t||t.open()}))}onWidgetRootReady(){const t=Object.create(null,{onWidgetRootReady:{get:()=>super.onWidgetRootReady}});return e.__awaiter(this,void 0,void 0,(function*(){var i;yield null===(i=t.onWidgetRootReady)||void 0===i?void 0:i.call(this),this.initPasswordAuthMethod(),e.__classPrivateFieldGet(this,r,"m",n).call(this)}))}},l=new WeakMap,d=new WeakMap,r=new WeakSet,n=function(){this.passwordUserAuthMethod.flowId&&(e.__classPrivateFieldSet(this,l,this.createModal({"data-id":"password"}),"f"),e.__classPrivateFieldSet(this,d,new s.FlowDriver((()=>{var t;return null===(t=e.__classPrivateFieldGet(this,l,"f").ele)||void 0===t?void 0:t.querySelector("descope-wc")}),{logger:this.logger}),"f"),e.__classPrivateFieldGet(this,l,"f").afterClose=e.__classPrivateFieldGet(this,r,"m",c).bind(this),e.__classPrivateFieldGet(this,r,"m",c).call(this),this.syncFlowTheme(e.__classPrivateFieldGet(this,d,"f")))},c=function(){e.__classPrivateFieldGet(this,l,"f").setContent(o({projectId:this.projectId,flowId:this.passwordUserAuthMethod.flowId,baseUrl:this.baseUrl,baseStaticUrl:this.baseStaticUrl,baseCdnUrl:this.baseCdnUrl,refreshCookieName:this.refreshCookieName,theme:this.theme})),e.__classPrivateFieldGet(this,d,"f").onSuccess((()=>{e.__classPrivateFieldGet(this,l,"f").close()}))},h})),$=t.createSingletonMixin((a=>{var r,l,d,n,c,h,v,u,_,f,g,m,p;return p=class extends(t.compose(N,b,i.loggerMixin,j,i.cookieConfigMixin,i.modalMixin)(a)){constructor(){super(...arguments),r.add(this),l.set(this,void 0),d.set(this,void 0),n.set(this,void 0),c.set(this,void 0),g.set(this,t.withMemCache((e=>{this.phoneUserAttr.value=e}))),m.set(this,t.withMemCache((e=>{this.phoneUserAttr.badgeLabel=e?"":"Unverified"})))}onWidgetRootReady(){const t=Object.create(null,{onWidgetRootReady:{get:()=>super.onWidgetRootReady}});return e.__awaiter(this,void 0,void 0,(function*(){var i;yield null===(i=t.onWidgetRootReady)||void 0===i?void 0:i.call(this),e.__classPrivateFieldGet(this,r,"m",f).call(this),e.__classPrivateFieldGet(this,r,"m",h).call(this),e.__classPrivateFieldGet(this,r,"m",u).call(this),e.__classPrivateFieldGet(this,g,"f").call(this,k(this.state)),e.__classPrivateFieldGet(this,m,"f").call(this,x(this.state)),this.subscribe(e.__classPrivateFieldGet(this,g,"f").bind(this),k),this.subscribe(e.__classPrivateFieldGet(this,m,"f").bind(this),x)}))}},l=new WeakMap,d=new WeakMap,n=new WeakMap,c=new WeakMap,g=new WeakMap,m=new WeakMap,r=new WeakSet,h=function(){this.phoneUserAttr.editFlowId&&(e.__classPrivateFieldSet(this,l,this.createModal({"data-id":"edit-phone"}),"f"),e.__classPrivateFieldSet(this,d,new s.FlowDriver((()=>{var t;return null===(t=e.__classPrivateFieldGet(this,l,"f").ele)||void 0===t?void 0:t.querySelector("descope-wc")}),{logger:this.logger}),"f"),e.__classPrivateFieldGet(this,l,"f").afterClose=e.__classPrivateFieldGet(this,r,"m",v).bind(this),e.__classPrivateFieldGet(this,r,"m",v).call(this),this.syncFlowTheme(e.__classPrivateFieldGet(this,d,"f")))},v=function(){e.__classPrivateFieldGet(this,l,"f").setContent(o({projectId:this.projectId,flowId:this.phoneUserAttr.editFlowId,baseUrl:this.baseUrl,baseStaticUrl:this.baseStaticUrl,baseCdnUrl:this.baseCdnUrl,refreshCookieName:this.refreshCookieName,theme:this.theme})),e.__classPrivateFieldGet(this,d,"f").onSuccess((()=>{e.__classPrivateFieldGet(this,l,"f").close(),this.actions.getMe()}))},u=function(){this.phoneUserAttr.deleteFlowId&&(e.__classPrivateFieldSet(this,n,this.createModal({"data-id":"delete-phone"}),"f"),e.__classPrivateFieldSet(this,c,new s.FlowDriver((()=>{var t;return null===(t=e.__classPrivateFieldGet(this,n,"f").ele)||void 0===t?void 0:t.querySelector("descope-wc")}),{logger:this.logger}),"f"),e.__classPrivateFieldGet(this,n,"f").afterClose=e.__classPrivateFieldGet(this,r,"m",_).bind(this),e.__classPrivateFieldGet(this,r,"m",_).call(this),this.syncFlowTheme(e.__classPrivateFieldGet(this,c,"f")))},_=function(){e.__classPrivateFieldGet(this,n,"f").setContent(o({projectId:this.projectId,flowId:this.phoneUserAttr.deleteFlowId,baseUrl:this.baseUrl,baseStaticUrl:this.baseStaticUrl,baseCdnUrl:this.baseCdnUrl,refreshCookieName:this.refreshCookieName,theme:this.theme})),e.__classPrivateFieldGet(this,c,"f").onSuccess((()=>{e.__classPrivateFieldGet(this,n,"f").close(),this.actions.getMe()}))},f=function(){this.phoneUserAttr=new s.UserAttributeDriver((()=>{var e;return null===(e=this.shadowRoot)||void 0===e?void 0:e.querySelector('descope-user-attribute[data-id="phone"]')}),{logger:this.logger}),this.phoneUserAttr.onEditClick((()=>{var t;null===(t=e.__classPrivateFieldGet(this,l,"f"))||void 0===t||t.open()})),this.phoneUserAttr.onDeleteClick((()=>{var t;null===(t=e.__classPrivateFieldGet(this,n,"f"))||void 0===t||t.open()}))},p}));var B;!function(e){e.TEXT="text",e.NUMBER="number",e.BOOLEAN="boolean",e.SINGLE_SELECT="singleSelect",e.ARRAY="array",e.DATE="date"}(B||(B={}));const V=t.createSingletonMixin((a=>{var r,l,d,n,c,h,v,u,_,f,g;return l=class extends(t.compose(N,b,i.loggerMixin,j,i.cookieConfigMixin,i.modalMixin)(a)){constructor(){super(...arguments),r.add(this),d.set(this,{}),n.set(this,{}),c.set(this,{}),h.set(this,{}),_.set(this,t.withMemCache((t=>{var i;const a=null===(i=this.shadowRoot)||void 0===i?void 0:i.querySelectorAll('descope-user-attribute[data-id^="customAttributes."]');Array.from(a).forEach((i=>{const a=i.getAttribute("data-id").replace("customAttributes.",""),o=i.getAttribute("data-type")||B.TEXT,d=t[a],n=new s.UserAttributeDriver(i,{logger:this.logger});n.value=l.getFormattedValue(o,d),e.__classPrivateFieldGet(this,r,"m",f).call(this,i,a,n),e.__classPrivateFieldGet(this,r,"m",g).call(this,i,a,n)}))})))}static getFormattedValue(e,t){return e===B.DATE&&t?new Date(t).toLocaleString():e===B.BOOLEAN&&void 0!==t?t?"True":"False":(t||"").toString()}onWidgetRootReady(){const t=Object.create(null,{onWidgetRootReady:{get:()=>super.onWidgetRootReady}});return e.__awaiter(this,void 0,void 0,(function*(){var i;yield null===(i=t.onWidgetRootReady)||void 0===i?void 0:i.call(this),e.__classPrivateFieldGet(this,_,"f").call(this,A(this.state)),this.subscribe(e.__classPrivateFieldGet(this,_,"f").bind(this),A)}))}},d=new WeakMap,n=new WeakMap,c=new WeakMap,h=new WeakMap,_=new WeakMap,r=new WeakSet,v=function(t){var i,s;null===(i=e.__classPrivateFieldGet(this,d,"f")[t])||void 0===i||i.setContent(o({projectId:this.projectId,flowId:t,baseUrl:this.baseUrl,baseStaticUrl:this.baseStaticUrl,baseCdnUrl:this.baseCdnUrl,refreshCookieName:this.refreshCookieName,theme:this.theme})),null===(s=e.__classPrivateFieldGet(this,n,"f")[t])||void 0===s||s.onSuccess((()=>{var i;null===(i=e.__classPrivateFieldGet(this,d,"f")[t])||void 0===i||i.close(),this.actions.getMe()}))},u=function(t){var i,s;null===(i=e.__classPrivateFieldGet(this,c,"f")[t])||void 0===i||i.setContent(o({projectId:this.projectId,flowId:t,baseUrl:this.baseUrl,baseStaticUrl:this.baseStaticUrl,baseCdnUrl:this.baseCdnUrl,refreshCookieName:this.refreshCookieName,theme:this.theme})),null===(s=e.__classPrivateFieldGet(this,h,"f")[t])||void 0===s||s.onSuccess((()=>{var i;null===(i=e.__classPrivateFieldGet(this,c,"f")[t])||void 0===i||i.close(),this.actions.getMe()}))},f=function(t,i,a){const l=t.getAttribute("edit-flow-id");l&&(e.__classPrivateFieldGet(this,d,"f")[l]=this.createModal({"data-id":`edit-${i}`}),e.__classPrivateFieldGet(this,n,"f")[l]=new s.FlowDriver((()=>{var t,i;return null===(i=null===(t=e.__classPrivateFieldGet(this,d,"f")[l])||void 0===t?void 0:t.ele)||void 0===i?void 0:i.querySelector("descope-wc")}),{logger:this.logger}),e.__classPrivateFieldGet(this,d,"f")[l].afterClose=e.__classPrivateFieldGet(this,r,"m",v).bind(this,l),a.onEditClick((()=>{var t,i;null===(i=null===(t=e.__classPrivateFieldGet(this,d,"f"))||void 0===t?void 0:t[l])||void 0===i||i.open()})),e.__classPrivateFieldGet(this,r,"m",v).call(this,l),this.syncFlowTheme(e.__classPrivateFieldGet(this,n,"f")[l]))},g=function(t,i,a){const l=t.getAttribute("delete-flow-id");l&&(e.__classPrivateFieldGet(this,c,"f")[l]=this.createModal({"data-id":`delete-${i}`}),e.__classPrivateFieldGet(this,h,"f")[l]=new s.FlowDriver((()=>{var t,i;return null===(i=null===(t=e.__classPrivateFieldGet(this,c,"f")[l])||void 0===t?void 0:t.ele)||void 0===i?void 0:i.querySelector("descope-wc")}),{logger:this.logger}),e.__classPrivateFieldGet(this,c,"f")[l].afterClose=e.__classPrivateFieldGet(this,r,"m",u).bind(this,l),a.onDeleteClick((()=>{var t,i;null===(i=null===(t=e.__classPrivateFieldGet(this,c,"f"))||void 0===t?void 0:t[l])||void 0===i||i.open()})),e.__classPrivateFieldGet(this,r,"m",u).call(this,l),this.syncFlowTheme(e.__classPrivateFieldGet(this,h,"f")[l]))},l})),H=t.createSingletonMixin((a=>{var r,l,d,n,c,h,v,u;return u=class extends(t.compose(N,b,i.loggerMixin,j,i.cookieConfigMixin,i.modalMixin)(a)){constructor(){super(...arguments),r.add(this),l.set(this,void 0),d.set(this,void 0),v.set(this,t.withMemCache((e=>{this.totpUserAuthMethod.fulfilled=e})))}onWidgetRootReady(){const t=Object.create(null,{onWidgetRootReady:{get:()=>super.onWidgetRootReady}});return e.__awaiter(this,void 0,void 0,(function*(){var i;yield null===(i=t.onWidgetRootReady)||void 0===i?void 0:i.call(this),e.__classPrivateFieldGet(this,r,"m",h).call(this),e.__classPrivateFieldGet(this,r,"m",n).call(this),e.__classPrivateFieldGet(this,v,"f").call(this,W(this.state)),this.subscribe(e.__classPrivateFieldGet(this,v,"f").bind(this),W)}))}},l=new WeakMap,d=new WeakMap,v=new WeakMap,r=new WeakSet,n=function(){this.totpUserAuthMethod.flowId&&(e.__classPrivateFieldSet(this,l,this.createModal({"data-id":"totp"}),"f"),e.__classPrivateFieldSet(this,d,new s.FlowDriver((()=>{var t;return null===(t=e.__classPrivateFieldGet(this,l,"f").ele)||void 0===t?void 0:t.querySelector("descope-wc")}),{logger:this.logger}),"f"),e.__classPrivateFieldGet(this,l,"f").afterClose=e.__classPrivateFieldGet(this,r,"m",c).bind(this),e.__classPrivateFieldGet(this,r,"m",c).call(this),this.syncFlowTheme(e.__classPrivateFieldGet(this,d,"f")))},c=function(){e.__classPrivateFieldGet(this,l,"f").setContent(o({projectId:this.projectId,flowId:this.totpUserAuthMethod.flowId,baseUrl:this.baseUrl,baseStaticUrl:this.baseStaticUrl,baseCdnUrl:this.baseCdnUrl,refreshCookieName:this.refreshCookieName,theme:this.theme})),e.__classPrivateFieldGet(this,d,"f").onSuccess((()=>{e.__classPrivateFieldGet(this,l,"f").close(),this.actions.getMe()}))},h=function(){this.totpUserAuthMethod=new s.UserAuthMethodDriver((()=>{var e;return null===(e=this.shadowRoot)||void 0===e?void 0:e.querySelector('descope-user-auth-method[data-id="totp"]')}),{logger:this.logger}),this.totpUserAuthMethod.onButtonClick((()=>{var t;null===(t=e.__classPrivateFieldGet(this,l,"f"))||void 0===t||t.open()}))},u})),X=t.createSingletonMixin((s=>class extends(t.compose(i.debuggerMixin,i.themeMixin,M,V,q,T,E,$,O,L,L,H,D)(s)){init(){const t=Object.create(null,{init:{get:()=>super.init}});return e.__awaiter(this,void 0,void 0,(function*(){var e;yield null===(e=t.init)||void 0===e?void 0:e.call(this)}))}})),J=t.compose((t=>class extends(X(t)){init(){const t=Object.create(null,{init:{get:()=>super.init}});return e.__awaiter(this,void 0,void 0,(function*(){var e;yield null===(e=t.init)||void 0===e?void 0:e.call(this);(customElements.get("descope-wc")||(yield import("@descope/web-component").then((e=>e.default)))).sdkConfigOverrides={baseHeaders:{"x-descope-widget-type":"user-profile-widget","x-descope-widget-id":this.getAttribute("widget-id"),"x-descope-widget-version":"0.4.16"}}}))}}))(HTMLElement);customElements.define("descope-user-profile-widget",J),module.exports=J;
6
+ //# sourceMappingURL=index.js.map