@descope/web-component 4.4.2 → 4.4.4
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/cjs/debugger-wc.js +1 -1
- package/dist/cjs/debugger-wc.js.map +1 -1
- package/dist/cjs/descope-wc/BaseDescopeWc.js +1 -1
- package/dist/cjs/descope-wc/DescopeWc.js +1 -1
- package/dist/cjs/descope-wc/DescopeWc.js.map +1 -1
- package/dist/esm/debugger-wc.js +1 -1
- package/dist/esm/debugger-wc.js.map +1 -1
- package/dist/esm/descope-wc/BaseDescopeWc.js +1 -1
- package/dist/esm/descope-wc/DescopeWc.js +1 -1
- package/dist/esm/descope-wc/DescopeWc.js.map +1 -1
- package/dist/index.d.ts +87 -87
- package/dist/index.js +2 -2
- package/package.json +4 -4
package/dist/cjs/debugger-wc.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var e=require("tslib"),t=require("@descope/sdk-helpers"),s=require("@descope/sdk-mixins/inject-style-mixin");require("./constants/content.js"),require("./constants/uiComponents.js"),require("./types.js");var i=require("./helpers/state.js");require("@descope/escape-markdown"),require("./helpers/webauthn.js");var n,l,a,r,o,d,c,p,h,g,v,m=require("./helpers/positionHelpers.js");const _=document.createElement("template");_.innerHTML='\n<div class="debugger">\n <div class="header">\n <span>Debugger messages</span>\n </div>\n <div class="content">\n <div class="empty-state">\n No errors detected 👀\n </div>\n </div>\n</div>\n';const u=t.compose(s.injectStyleMixin)(HTMLElement);class f extends u{constructor(){super(),n.add(this),l.set(this,new i({messages:[]})),a.set(this,void 0),r.set(this,void 0),o.set(this,void 0),d.set(this,{resize:e.__classPrivateFieldGet(this,n,"m",v).bind(this)}),this.attachShadow({mode:"open"}),this.shadowRoot.appendChild(_.content.cloneNode(!0)),e.__classPrivateFieldSet(this,a,this.shadowRoot.querySelector(".debugger"),"f"),e.__classPrivateFieldSet(this,r,e.__classPrivateFieldGet(this,a,"f").querySelector(".content"),"f"),e.__classPrivateFieldSet(this,o,e.__classPrivateFieldGet(this,a,"f").querySelector(".header"),"f"),e.__classPrivateFieldGet(this,n,"m",c).call(this)}updateData(t){e.__classPrivateFieldGet(this,l,"f").update((e=>({messages:e.messages.concat(t)})))}init(){const t=Object.create(null,{init:{get:()=>super.init}});return e.__awaiter(this,void 0,void 0,(function*(){var s;null===(s=t.init)||void 0===s||s.call(this),m.dragElement(e.__classPrivateFieldGet(this,a,"f"),e.__classPrivateFieldGet(this,o,"f"),{top:"all",bottom:100,left:100,right:100}),window.addEventListener("resize",e.__classPrivateFieldGet(this,d,"f").resize),m.addOnResize(e.__classPrivateFieldGet(this,a,"f")),e.__classPrivateFieldGet(this,a,"f").onresize=e.__classPrivateFieldGet(this,n,"m",g).bind(this),e.__classPrivateFieldGet(this,l,"f").subscribe(e.__classPrivateFieldGet(this,n,"m",p).bind(this))}))}disconnectedCallback(){e.__classPrivateFieldGet(this,l,"f").unsubscribeAll(),window.removeEventListener("resize",e.__classPrivateFieldGet(this,d,"f").resize)}}l=new WeakMap,a=new WeakMap,r=new WeakMap,o=new WeakMap,d=new WeakMap,n=new WeakSet,c=function(){this.injectStyle('\n .debugger {\n all: initial;\n width: 300px;\n height: 200px;\n background-color: #FAFAFA;\n position: fixed;\n font-family: "Helvetica Neue", sans-serif;\n box-shadow: rgba(0, 0, 0, 0.1) 0px 5px 10px;\n border-radius: 8px;\n overflow: hidden;\n border: 1px solid lightgrey;\n pointer-events: initial;\n display: flex;\n flex-direction: column;\n min-width: 200px;\n max-width: 600px;\n max-height: calc(100% - 64px);\n min-height: 200px;\n resize: both;\n }\n\n .header {\n padding: 8px 16px;\n display: flex;\n align-items: center;\n background-color: #EEEEEE;\n cursor: move;\n border-bottom: 1px solid #e0e0e0;\n }\n\n .content {\n font-size: 14px;\n flex-grow: 1;\n overflow: auto;\n }\n\n .msg {\n border-bottom: 1px solid lightgrey;\n padding: 8px 16px;\n display: flex;\n gap: 5px;\n background-color: #FAFAFA;\n }\n\n .msg.collapsible {\n cursor: pointer;\n }\n\n .empty-state {\n padding: 8px 16px;\n background-color: #FAFAFA;\n }\n\n\n .msg.collapsible:not(.collapsed) {\n background-color: #F5F5F5;\n }\n\n .msg_title {\n padding-bottom: 5px;\n display: flex;\n gap: 8px;\n font-weight: 500;\n }\n\n .msg svg {\n padding: 1px;\n flex-shrink: 0;\n margin-top: -2px;\n }\n\n .msg_content {\n overflow: hidden;\n flex-grow: 1;\n margin-right:5px;\n }\n\n .msg_desc {\n color: #646464;\n cursor: initial;\n word-wrap: break-word;\n }\n\n .msg.collapsed .msg_desc {\n overflow: hidden;\n text-overflow: ellipsis;\n white-space: nowrap;\n }\n\n .msg.collapsible.collapsed .chevron {\n transform: rotate(-45deg) translateX(-2px);\n }\n\n .msg.collapsible .chevron {\n content: "";\n width:6px;\n height:6px;\n border-bottom: 2px solid grey;\n border-right: 2px solid grey;\n transform: rotate(45deg) translateX(-1px);\n margin: 5px;\n flex-shrink:0;\n }\n'),e.__classPrivateFieldGet(this,a,"f").style.top="32px",e.__classPrivateFieldGet(this,a,"f").style.left=window.innerWidth-300-32+"px"},p=function(t){e.__classPrivateFieldGet(this,n,"m",h).call(this,t),e.__classPrivateFieldGet(this,n,"m",g).call(this)},h=function(
|
|
1
|
+
"use strict";var e=require("tslib"),t=require("@descope/sdk-helpers"),s=require("@descope/sdk-mixins/inject-style-mixin");require("./constants/content.js"),require("./constants/uiComponents.js"),require("./types.js");var i=require("./helpers/state.js");require("@descope/escape-markdown"),require("./helpers/webauthn.js");var n,l,a,r,o,d,c,p,h,g,v,m=require("./helpers/positionHelpers.js");const _=document.createElement("template");_.innerHTML='\n<div class="debugger">\n <div class="header">\n <span>Debugger messages</span>\n </div>\n <div class="content">\n <div class="empty-state">\n No errors detected 👀\n </div>\n </div>\n</div>\n';const u=t.compose(s.injectStyleMixin)(HTMLElement);class f extends u{constructor(){super(),n.add(this),l.set(this,new i({messages:[]})),a.set(this,void 0),r.set(this,void 0),o.set(this,void 0),d.set(this,{resize:e.__classPrivateFieldGet(this,n,"m",v).bind(this)}),this.attachShadow({mode:"open"}),this.shadowRoot.appendChild(_.content.cloneNode(!0)),e.__classPrivateFieldSet(this,a,this.shadowRoot.querySelector(".debugger"),"f"),e.__classPrivateFieldSet(this,r,e.__classPrivateFieldGet(this,a,"f").querySelector(".content"),"f"),e.__classPrivateFieldSet(this,o,e.__classPrivateFieldGet(this,a,"f").querySelector(".header"),"f"),e.__classPrivateFieldGet(this,n,"m",c).call(this)}updateData(t){e.__classPrivateFieldGet(this,l,"f").update((e=>({messages:e.messages.concat(t)})))}init(){const t=Object.create(null,{init:{get:()=>super.init}});return e.__awaiter(this,void 0,void 0,(function*(){var s;null===(s=t.init)||void 0===s||s.call(this),m.dragElement(e.__classPrivateFieldGet(this,a,"f"),e.__classPrivateFieldGet(this,o,"f"),{top:"all",bottom:100,left:100,right:100}),window.addEventListener("resize",e.__classPrivateFieldGet(this,d,"f").resize),m.addOnResize(e.__classPrivateFieldGet(this,a,"f")),e.__classPrivateFieldGet(this,a,"f").onresize=e.__classPrivateFieldGet(this,n,"m",g).bind(this),e.__classPrivateFieldGet(this,l,"f").subscribe(e.__classPrivateFieldGet(this,n,"m",p).bind(this))}))}disconnectedCallback(){e.__classPrivateFieldGet(this,l,"f").unsubscribeAll(),window.removeEventListener("resize",e.__classPrivateFieldGet(this,d,"f").resize)}}l=new WeakMap,a=new WeakMap,r=new WeakMap,o=new WeakMap,d=new WeakMap,n=new WeakSet,c=function(){this.injectStyle('\n .debugger {\n all: initial;\n width: 300px;\n height: 200px;\n background-color: #FAFAFA;\n position: fixed;\n font-family: "Helvetica Neue", sans-serif;\n box-shadow: rgba(0, 0, 0, 0.1) 0px 5px 10px;\n border-radius: 8px;\n overflow: hidden;\n border: 1px solid lightgrey;\n pointer-events: initial;\n display: flex;\n flex-direction: column;\n min-width: 200px;\n max-width: 600px;\n max-height: calc(100% - 64px);\n min-height: 200px;\n resize: both;\n }\n\n .header {\n padding: 8px 16px;\n display: flex;\n align-items: center;\n background-color: #EEEEEE;\n cursor: move;\n border-bottom: 1px solid #e0e0e0;\n }\n\n .content {\n font-size: 14px;\n flex-grow: 1;\n overflow: auto;\n }\n\n .msg {\n border-bottom: 1px solid lightgrey;\n padding: 8px 16px;\n display: flex;\n gap: 5px;\n background-color: #FAFAFA;\n }\n\n .msg.collapsible {\n cursor: pointer;\n }\n\n .empty-state {\n padding: 8px 16px;\n background-color: #FAFAFA;\n }\n\n\n .msg.collapsible:not(.collapsed) {\n background-color: #F5F5F5;\n }\n\n .msg_title {\n padding-bottom: 5px;\n display: flex;\n gap: 8px;\n font-weight: 500;\n }\n\n .msg svg {\n padding: 1px;\n flex-shrink: 0;\n margin-top: -2px;\n }\n\n .msg_content {\n overflow: hidden;\n flex-grow: 1;\n margin-right:5px;\n }\n\n .msg_desc {\n color: #646464;\n cursor: initial;\n word-wrap: break-word;\n }\n\n .msg.collapsed .msg_desc {\n overflow: hidden;\n text-overflow: ellipsis;\n white-space: nowrap;\n }\n\n .msg.collapsible.collapsed .chevron {\n transform: rotate(-45deg) translateX(-2px);\n }\n\n .msg.collapsible .chevron {\n content: "";\n width:6px;\n height:6px;\n border-bottom: 2px solid grey;\n border-right: 2px solid grey;\n transform: rotate(45deg) translateX(-1px);\n margin: 5px;\n flex-shrink:0;\n }\n'),e.__classPrivateFieldGet(this,a,"f").style.top="32px",e.__classPrivateFieldGet(this,a,"f").style.left=window.innerWidth-300-32+"px"},p=function(t){e.__classPrivateFieldGet(this,n,"m",h).call(this,t),e.__classPrivateFieldGet(this,n,"m",g).call(this)},h=function(s){e.__classPrivateFieldGet(this,r,"f").innerHTML=s.messages.map((e=>`\n <div class="msg">\n <svg width="18" height="18" viewBox="0 0 18 18" fill="none" xmlns="http://www.w3.org/2000/svg">\n<path d="M5.99984 13.167L8.99984 10.167L11.9998 13.167L13.1665 12.0003L10.1665 9.00033L13.1665 6.00033L11.9998 4.83366L8.99984 7.83366L5.99984 4.83366L4.83317 6.00033L7.83317 9.00033L4.83317 12.0003L5.99984 13.167ZM8.99984 17.3337C7.84706 17.3337 6.76373 17.1148 5.74984 16.677C4.73595 16.2398 3.854 15.6462 3.104 14.8962C2.354 14.1462 1.76039 13.2642 1.32317 12.2503C0.885393 11.2364 0.666504 10.1531 0.666504 9.00033C0.666504 7.84755 0.885393 6.76421 1.32317 5.75033C1.76039 4.73644 2.354 3.85449 3.104 3.10449C3.854 2.35449 4.73595 1.7606 5.74984 1.32283C6.76373 0.885603 7.84706 0.666992 8.99984 0.666992C10.1526 0.666992 11.2359 0.885603 12.2498 1.32283C13.2637 1.7606 14.1457 2.35449 14.8957 3.10449C15.6457 3.85449 16.2393 4.73644 16.6765 5.75033C17.1143 6.76421 17.3332 7.84755 17.3332 9.00033C17.3332 10.1531 17.1143 11.2364 16.6765 12.2503C16.2393 13.2642 15.6457 14.1462 14.8957 14.8962C14.1457 15.6462 13.2637 16.2398 12.2498 16.677C11.2359 17.1148 10.1526 17.3337 8.99984 17.3337ZM8.99984 15.667C10.8609 15.667 12.4373 15.0212 13.729 13.7295C15.0207 12.4378 15.6665 10.8614 15.6665 9.00033C15.6665 7.13921 15.0207 5.56283 13.729 4.27116C12.4373 2.97949 10.8609 2.33366 8.99984 2.33366C7.13873 2.33366 5.56234 2.97949 4.27067 4.27116C2.979 5.56283 2.33317 7.13921 2.33317 9.00033C2.33317 10.8614 2.979 12.4378 4.27067 13.7295C5.56234 15.0212 7.13873 15.667 8.99984 15.667Z" fill="#ED404A"/>\n</svg>\n\n <div class="msg_content">\n <div class="msg_title">\n ${t.escapeHtml(e.title)}\n </div>\n <div class="msg_desc">\n ${t.escapeHtml(e.description)}\n </div>\n </div>\n <div class="chevron"></div>\n </div>\n `)).join("")},g=function(){e.__classPrivateFieldGet(this,r,"f").querySelectorAll(".msg").forEach((e=>{const t=e.querySelector(".msg_desc"),s=t.scrollWidth>t.clientWidth,i=t.clientHeight>20;s||i?(e.classList.add("collapsible"),e.onclick=t=>{t.target.classList.contains("msg_desc")||e.classList.toggle("collapsed")}):(e.classList.remove("collapsible"),e.onclick=null)}))},v=function(){const[t,s]=m.limitCoordinateToScreenBoundaries(e.__classPrivateFieldGet(this,a,"f"),Number.parseInt(e.__classPrivateFieldGet(this,a,"f").style.left,10),Number.parseInt(e.__classPrivateFieldGet(this,a,"f").style.top,10),{top:"all",bottom:100,left:100,right:100});e.__classPrivateFieldGet(this,a,"f").style.top=`${s}px`,e.__classPrivateFieldGet(this,a,"f").style.left=`${t}px`},customElements.get("descope-debugger")||customElements.define("descope-debugger",f),module.exports=f;
|
|
2
2
|
//# sourceMappingURL=debugger-wc.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"debugger-wc.js","sources":["../../src/lib/debugger-wc.ts"],"sourcesContent":["/* eslint-disable no-param-reassign */\nimport { compose } from '@descope/sdk-helpers';\nimport { injectStyleMixin } from '@descope/sdk-mixins/inject-style-mixin';\nimport {\n addOnResize,\n dragElement,\n limitCoordinateToScreenBoundaries,\n State,\n} from './helpers';\nimport { DebuggerMessage } from './types';\n\nconst INITIAL_POS_THRESHOLD = 32;\nconst INITIAL_WIDTH = 300;\nconst INITIAL_HEIGHT = 200;\nconst MIN_SIZE = 200;\n\nconst template = document.createElement('template');\ntemplate.innerHTML = `\n<div class=\"debugger\">\n <div class=\"header\">\n <span>Debugger messages</span>\n </div>\n <div class=\"content\">\n <div class=\"empty-state\">\n No errors detected 👀\n </div>\n </div>\n</div>\n`;\n\nconst icon = `<svg width=\"18\" height=\"18\" viewBox=\"0 0 18 18\" fill=\"none\" xmlns=\"http://www.w3.org/2000/svg\">\n<path d=\"M5.99984 13.167L8.99984 10.167L11.9998 13.167L13.1665 12.0003L10.1665 9.00033L13.1665 6.00033L11.9998 4.83366L8.99984 7.83366L5.99984 4.83366L4.83317 6.00033L7.83317 9.00033L4.83317 12.0003L5.99984 13.167ZM8.99984 17.3337C7.84706 17.3337 6.76373 17.1148 5.74984 16.677C4.73595 16.2398 3.854 15.6462 3.104 14.8962C2.354 14.1462 1.76039 13.2642 1.32317 12.2503C0.885393 11.2364 0.666504 10.1531 0.666504 9.00033C0.666504 7.84755 0.885393 6.76421 1.32317 5.75033C1.76039 4.73644 2.354 3.85449 3.104 3.10449C3.854 2.35449 4.73595 1.7606 5.74984 1.32283C6.76373 0.885603 7.84706 0.666992 8.99984 0.666992C10.1526 0.666992 11.2359 0.885603 12.2498 1.32283C13.2637 1.7606 14.1457 2.35449 14.8957 3.10449C15.6457 3.85449 16.2393 4.73644 16.6765 5.75033C17.1143 6.76421 17.3332 7.84755 17.3332 9.00033C17.3332 10.1531 17.1143 11.2364 16.6765 12.2503C16.2393 13.2642 15.6457 14.1462 14.8957 14.8962C14.1457 15.6462 13.2637 16.2398 12.2498 16.677C11.2359 17.1148 10.1526 17.3337 8.99984 17.3337ZM8.99984 15.667C10.8609 15.667 12.4373 15.0212 13.729 13.7295C15.0207 12.4378 15.6665 10.8614 15.6665 9.00033C15.6665 7.13921 15.0207 5.56283 13.729 4.27116C12.4373 2.97949 10.8609 2.33366 8.99984 2.33366C7.13873 2.33366 5.56234 2.97949 4.27067 4.27116C2.979 5.56283 2.33317 7.13921 2.33317 9.00033C2.33317 10.8614 2.979 12.4378 4.27067 13.7295C5.56234 15.0212 7.13873 15.667 8.99984 15.667Z\" fill=\"#ED404A\"/>\n</svg>\n`;\n\nconst style = `\n .debugger {\n all: initial;\n width: ${INITIAL_WIDTH}px;\n height: ${INITIAL_HEIGHT}px;\n background-color: #FAFAFA;\n position: fixed;\n font-family: \"Helvetica Neue\", sans-serif;\n box-shadow: rgba(0, 0, 0, 0.1) 0px 5px 10px;\n border-radius: 8px;\n overflow: hidden;\n border: 1px solid lightgrey;\n pointer-events: initial;\n display: flex;\n flex-direction: column;\n min-width: ${MIN_SIZE}px;\n max-width: 600px;\n max-height: calc(100% - ${INITIAL_POS_THRESHOLD * 2}px);\n min-height: ${MIN_SIZE}px;\n resize: both;\n }\n\n .header {\n padding: 8px 16px;\n display: flex;\n align-items: center;\n background-color: #EEEEEE;\n cursor: move;\n border-bottom: 1px solid #e0e0e0;\n }\n\n .content {\n font-size: 14px;\n flex-grow: 1;\n overflow: auto;\n }\n\n .msg {\n border-bottom: 1px solid lightgrey;\n padding: 8px 16px;\n display: flex;\n gap: 5px;\n background-color: #FAFAFA;\n }\n\n .msg.collapsible {\n cursor: pointer;\n }\n\n .empty-state {\n padding: 8px 16px;\n background-color: #FAFAFA;\n }\n\n\n .msg.collapsible:not(.collapsed) {\n background-color: #F5F5F5;\n }\n\n .msg_title {\n padding-bottom: 5px;\n display: flex;\n gap: 8px;\n font-weight: 500;\n }\n\n .msg svg {\n padding: 1px;\n flex-shrink: 0;\n margin-top: -2px;\n }\n\n .msg_content {\n overflow: hidden;\n flex-grow: 1;\n margin-right:5px;\n }\n\n .msg_desc {\n color: #646464;\n cursor: initial;\n word-wrap: break-word;\n }\n\n .msg.collapsed .msg_desc {\n overflow: hidden;\n text-overflow: ellipsis;\n white-space: nowrap;\n }\n\n .msg.collapsible.collapsed .chevron {\n transform: rotate(-45deg) translateX(-2px);\n }\n\n .msg.collapsible .chevron {\n content: \"\";\n width:6px;\n height:6px;\n border-bottom: 2px solid grey;\n border-right: 2px solid grey;\n transform: rotate(45deg) translateX(-1px);\n margin: 5px;\n flex-shrink:0;\n }\n`;\n\ntype MessagesState = { messages: DebuggerMessage[] };\n\nconst BaseClass = compose(injectStyleMixin)(HTMLElement);\n\nclass Debugger extends BaseClass {\n #messagesState = new State<MessagesState>({ messages: [] });\n\n #rootEle: HTMLDivElement;\n\n #contentEle: HTMLDivElement;\n\n #headerEle: HTMLDivElement;\n\n #eventsCbRefs = {\n resize: this.#onWindowResize.bind(this),\n };\n\n constructor() {\n super();\n\n this.attachShadow({ mode: 'open' });\n this.shadowRoot.appendChild(template.content.cloneNode(true));\n\n this.#rootEle = this.shadowRoot.querySelector<HTMLDivElement>('.debugger');\n this.#contentEle = this.#rootEle.querySelector<HTMLDivElement>('.content');\n this.#headerEle = this.#rootEle.querySelector<HTMLDivElement>('.header');\n\n this.#initStyle();\n }\n\n #initStyle() {\n this.injectStyle(style);\n\n this.#rootEle.style.top = `${INITIAL_POS_THRESHOLD}px`;\n this.#rootEle.style.left = `${\n window.innerWidth - INITIAL_WIDTH - INITIAL_POS_THRESHOLD\n }px`;\n }\n\n updateData(data: DebuggerMessage | DebuggerMessage[]) {\n this.#messagesState.update((state) => ({\n messages: state.messages.concat(data),\n }));\n }\n\n #onNewMessages(data: MessagesState) {\n this.#renderMessages(data);\n this.#setCollapsibleMessages();\n }\n\n #renderMessages(data: MessagesState) {\n this.#contentEle.innerHTML = data.messages\n .map(\n (message) => `\n <div class=\"msg\">\n ${icon}\n <div class=\"msg_content\">\n <div class=\"msg_title\">\n ${message.title}\n </div>\n <div class=\"msg_desc\">\n ${message.description}\n </div>\n </div>\n <div class=\"chevron\"></div>\n </div>\n `,\n )\n .join('');\n }\n\n #setCollapsibleMessages() {\n this.#contentEle.querySelectorAll('.msg').forEach((ele: HTMLElement) => {\n const descEle = ele.querySelector('.msg_desc');\n const lineHeight = 20;\n const isScroll = descEle.scrollWidth > descEle.clientWidth;\n const isMultiLine = descEle.clientHeight > lineHeight;\n const isCollapsible = isScroll || isMultiLine;\n\n if (isCollapsible) {\n ele.classList.add('collapsible');\n ele.onclick = (e: MouseEvent) => {\n // message description should not toggle collapse\n if (!(e.target as HTMLElement).classList.contains('msg_desc')) {\n ele.classList.toggle('collapsed');\n }\n };\n } else {\n ele.classList.remove('collapsible');\n ele.onclick = null;\n }\n });\n }\n\n #onWindowResize() {\n // when window is resizing we want to make sure debugger is still visible\n const [left, top] = limitCoordinateToScreenBoundaries(\n this.#rootEle,\n Number.parseInt(this.#rootEle.style.left, 10),\n Number.parseInt(this.#rootEle.style.top, 10),\n { top: 'all', bottom: 100, left: 100, right: 100 },\n );\n this.#rootEle.style.top = `${top}px`;\n this.#rootEle.style.left = `${left}px`;\n }\n\n async init() {\n super.init?.();\n dragElement(this.#rootEle, this.#headerEle, {\n top: 'all',\n bottom: 100,\n left: 100,\n right: 100,\n });\n\n window.addEventListener('resize', this.#eventsCbRefs.resize);\n\n addOnResize(this.#rootEle);\n this.#rootEle.onresize = this.#setCollapsibleMessages.bind(this);\n\n this.#messagesState.subscribe(this.#onNewMessages.bind(this));\n }\n\n disconnectedCallback() {\n this.#messagesState.unsubscribeAll();\n window.removeEventListener('resize', this.#eventsCbRefs.resize);\n }\n}\n\nif (!customElements.get('descope-debugger')) {\n customElements.define('descope-debugger', Debugger);\n}\nexport default Debugger;\n"],"names":["template","document","createElement","innerHTML","BaseClass","compose","injectStyleMixin","HTMLElement","Debugger","constructor","super","_Debugger_messagesState","set","this","State","messages","_Debugger_rootEle","_Debugger_contentEle","_Debugger_headerEle","_Debugger_eventsCbRefs","resize","__classPrivateFieldGet","_Debugger_instances","_Debugger_onWindowResize","bind","attachShadow","mode","shadowRoot","appendChild","content","cloneNode","__classPrivateFieldSet","querySelector","_Debugger_initStyle","call","updateData","data","update","state","concat","init","_a","_super","dragElement","top","bottom","left","right","window","addEventListener","addOnResize","onresize","_Debugger_setCollapsibleMessages","subscribe","_Debugger_onNewMessages","disconnectedCallback","unsubscribeAll","removeEventListener","injectStyle","style","innerWidth","_Debugger_renderMessages","map","message","title","description","join","querySelectorAll","forEach","ele","descEle","isScroll","scrollWidth","clientWidth","isMultiLine","clientHeight","classList","add","onclick","e","target","contains","toggle","remove","limitCoordinateToScreenBoundaries","Number","parseInt","customElements","get","define"],"mappings":"sYAWA,MAKMA,EAAWC,SAASC,cAAc,YACxCF,EAASG,UAAY,sNAarB,MAiHMC,EAAYC,EAAOA,QAACC,mBAARD,CAA0BE,aAE5C,MAAMC,UAAiBJ,EAarB,WAAAK,GACEC,oBAbFC,EAAiBC,IAAAC,KAAA,IAAIC,EAAqB,CAAEC,SAAU,MAEtDC,EAAyBJ,IAAAC,UAAA,GAEzBI,EAA4BL,IAAAC,UAAA,GAE5BK,EAA2BN,IAAAC,UAAA,GAE3BM,EAAgBP,IAAAC,KAAA,CACdO,OAAQC,EAAAA,uBAAAR,KAAIS,EAAA,IAAAC,GAAiBC,KAAKX,QAMlCA,KAAKY,aAAa,CAAEC,KAAM,SAC1Bb,KAAKc,WAAWC,YAAY5B,EAAS6B,QAAQC,WAAU,IAEvDC,yBAAAlB,KAAgBG,EAAAH,KAAKc,WAAWK,cAA8B,aAAY,KAC1ED,EAAAA,uBAAAlB,KAAmBI,EAAAI,EAAAA,uBAAAR,KAAIG,EAAA,KAAUgB,cAA8B,YAAW,KAC1ED,EAAAA,uBAAAlB,KAAkBK,EAAAG,EAAAA,uBAAAR,KAAIG,EAAA,KAAUgB,cAA8B,WAAU,KAExEX,EAAAA,uBAAAR,KAAIS,EAAA,IAAAW,GAAJC,KAAArB,KACD,CAWD,UAAAsB,CAAWC,GACTf,EAAAA,uBAAAR,KAAmBF,EAAA,KAAC0B,QAAQC,IAAW,CACrCvB,SAAUuB,EAAMvB,SAASwB,OAAOH,MAEnC,CA+DK,IAAAI,oHACM,QAAVC,EAAAC,EAAMF,YAAI,IAAAC,GAAAA,EAAAP,KAAArB,MACV8B,cAAYtB,EAAAA,uBAAAR,KAAIG,EAAA,KAAWK,EAAAA,uBAAAR,YAAiB,CAC1C+B,IAAK,MACLC,OAAQ,IACRC,KAAM,IACNC,MAAO,MAGTC,OAAOC,iBAAiB,SAAU5B,EAAAA,uBAAAR,KAAkBM,EAAA,KAACC,QAErD8B,EAAAA,YAAY7B,EAAAA,uBAAAR,KAAIG,EAAA,MAChBK,EAAAA,uBAAAR,KAAIG,EAAA,KAAUmC,SAAW9B,EAAAA,uBAAAR,KAAIS,EAAA,IAAA8B,GAAyB5B,KAAKX,MAE3DQ,EAAAA,uBAAAR,KAAIF,EAAA,KAAgB0C,UAAUhC,EAAAA,uBAAAR,KAAmBS,EAAA,IAAAgC,GAAC9B,KAAKX,SACxD,CAED,oBAAA0C,GACElC,EAAAA,uBAAAR,KAAIF,EAAA,KAAgB6C,iBACpBR,OAAOS,oBAAoB,SAAUpC,EAAAA,uBAAAR,KAAkBM,EAAA,KAACC,OACzD,mGA/FCP,KAAK6C,YAzIK,07DA2IVrC,yBAAAR,KAAaG,EAAA,KAAC2C,MAAMf,IAAM,OAC1BvB,EAAAA,uBAAAR,KAAaG,EAAA,KAAC2C,MAAMb,KAClBE,OAAOY,WApKS,IADQ,GAoKC,IAG7B,aAQexB,GACbf,yBAAAR,KAAoBS,EAAA,IAAAuC,GAAA3B,KAApBrB,KAAqBuB,GACrBf,EAAAA,uBAAAR,KAAIS,EAAA,IAAA8B,GAAJlB,KAAArB,KACF,aAEgBuB,GACdf,EAAAA,uBAAAR,KAAgBI,EAAA,KAACd,UAAYiC,EAAKrB,SAC/B+C,KACEC,GAAY,qlDAKTA,EAAQC,oEAGRD,EAAQE,iGAObC,KAAK,GACV,EAACd,EAAA,WAGC/B,yBAAAR,KAAII,EAAA,KAAakD,iBAAiB,QAAQC,SAASC,IACjD,MAAMC,EAAUD,EAAIrC,cAAc,aAE5BuC,EAAWD,EAAQE,YAAcF,EAAQG,YACzCC,EAAcJ,EAAQK,aAFT,GAGGJ,GAAYG,GAGhCL,EAAIO,UAAUC,IAAI,eAClBR,EAAIS,QAAWC,IAEPA,EAAEC,OAAuBJ,UAAUK,SAAS,aAChDZ,EAAIO,UAAUM,OAAO,YACtB,IAGHb,EAAIO,UAAUO,OAAO,eACrBd,EAAIS,QAAU,KACf,GAEL,EAACvD,EAAA,WAIC,MAAOuB,EAAMF,GAAOwC,EAAAA,kCAClB/D,EAAAA,uBAAAR,KAAaG,EAAA,KACbqE,OAAOC,SAASjE,EAAAA,uBAAAR,KAAaG,EAAA,KAAC2C,MAAMb,KAAM,IAC1CuC,OAAOC,SAASjE,EAAAA,uBAAAR,KAAIG,EAAA,KAAU2C,MAAMf,IAAK,IACzC,CAAEA,IAAK,MAAOC,OAAQ,IAAKC,KAAM,IAAKC,MAAO,MAE/C1B,yBAAAR,KAAaG,EAAA,KAAC2C,MAAMf,IAAM,GAAGA,MAC7BvB,yBAAAR,KAAaG,EAAA,KAAC2C,MAAMb,KAAO,GAAGA,KAChC,EAyBGyC,eAAeC,IAAI,qBACtBD,eAAeE,OAAO,mBAAoBjF"}
|
|
1
|
+
{"version":3,"file":"debugger-wc.js","sources":["../../src/lib/debugger-wc.ts"],"sourcesContent":["/* eslint-disable no-param-reassign */\nimport { compose, escapeHtml } from '@descope/sdk-helpers';\nimport { injectStyleMixin } from '@descope/sdk-mixins/inject-style-mixin';\nimport {\n addOnResize,\n dragElement,\n limitCoordinateToScreenBoundaries,\n State,\n} from './helpers';\nimport { DebuggerMessage } from './types';\n\nconst INITIAL_POS_THRESHOLD = 32;\nconst INITIAL_WIDTH = 300;\nconst INITIAL_HEIGHT = 200;\nconst MIN_SIZE = 200;\n\nconst template = document.createElement('template');\ntemplate.innerHTML = `\n<div class=\"debugger\">\n <div class=\"header\">\n <span>Debugger messages</span>\n </div>\n <div class=\"content\">\n <div class=\"empty-state\">\n No errors detected 👀\n </div>\n </div>\n</div>\n`;\n\nconst icon = `<svg width=\"18\" height=\"18\" viewBox=\"0 0 18 18\" fill=\"none\" xmlns=\"http://www.w3.org/2000/svg\">\n<path d=\"M5.99984 13.167L8.99984 10.167L11.9998 13.167L13.1665 12.0003L10.1665 9.00033L13.1665 6.00033L11.9998 4.83366L8.99984 7.83366L5.99984 4.83366L4.83317 6.00033L7.83317 9.00033L4.83317 12.0003L5.99984 13.167ZM8.99984 17.3337C7.84706 17.3337 6.76373 17.1148 5.74984 16.677C4.73595 16.2398 3.854 15.6462 3.104 14.8962C2.354 14.1462 1.76039 13.2642 1.32317 12.2503C0.885393 11.2364 0.666504 10.1531 0.666504 9.00033C0.666504 7.84755 0.885393 6.76421 1.32317 5.75033C1.76039 4.73644 2.354 3.85449 3.104 3.10449C3.854 2.35449 4.73595 1.7606 5.74984 1.32283C6.76373 0.885603 7.84706 0.666992 8.99984 0.666992C10.1526 0.666992 11.2359 0.885603 12.2498 1.32283C13.2637 1.7606 14.1457 2.35449 14.8957 3.10449C15.6457 3.85449 16.2393 4.73644 16.6765 5.75033C17.1143 6.76421 17.3332 7.84755 17.3332 9.00033C17.3332 10.1531 17.1143 11.2364 16.6765 12.2503C16.2393 13.2642 15.6457 14.1462 14.8957 14.8962C14.1457 15.6462 13.2637 16.2398 12.2498 16.677C11.2359 17.1148 10.1526 17.3337 8.99984 17.3337ZM8.99984 15.667C10.8609 15.667 12.4373 15.0212 13.729 13.7295C15.0207 12.4378 15.6665 10.8614 15.6665 9.00033C15.6665 7.13921 15.0207 5.56283 13.729 4.27116C12.4373 2.97949 10.8609 2.33366 8.99984 2.33366C7.13873 2.33366 5.56234 2.97949 4.27067 4.27116C2.979 5.56283 2.33317 7.13921 2.33317 9.00033C2.33317 10.8614 2.979 12.4378 4.27067 13.7295C5.56234 15.0212 7.13873 15.667 8.99984 15.667Z\" fill=\"#ED404A\"/>\n</svg>\n`;\n\nconst style = `\n .debugger {\n all: initial;\n width: ${INITIAL_WIDTH}px;\n height: ${INITIAL_HEIGHT}px;\n background-color: #FAFAFA;\n position: fixed;\n font-family: \"Helvetica Neue\", sans-serif;\n box-shadow: rgba(0, 0, 0, 0.1) 0px 5px 10px;\n border-radius: 8px;\n overflow: hidden;\n border: 1px solid lightgrey;\n pointer-events: initial;\n display: flex;\n flex-direction: column;\n min-width: ${MIN_SIZE}px;\n max-width: 600px;\n max-height: calc(100% - ${INITIAL_POS_THRESHOLD * 2}px);\n min-height: ${MIN_SIZE}px;\n resize: both;\n }\n\n .header {\n padding: 8px 16px;\n display: flex;\n align-items: center;\n background-color: #EEEEEE;\n cursor: move;\n border-bottom: 1px solid #e0e0e0;\n }\n\n .content {\n font-size: 14px;\n flex-grow: 1;\n overflow: auto;\n }\n\n .msg {\n border-bottom: 1px solid lightgrey;\n padding: 8px 16px;\n display: flex;\n gap: 5px;\n background-color: #FAFAFA;\n }\n\n .msg.collapsible {\n cursor: pointer;\n }\n\n .empty-state {\n padding: 8px 16px;\n background-color: #FAFAFA;\n }\n\n\n .msg.collapsible:not(.collapsed) {\n background-color: #F5F5F5;\n }\n\n .msg_title {\n padding-bottom: 5px;\n display: flex;\n gap: 8px;\n font-weight: 500;\n }\n\n .msg svg {\n padding: 1px;\n flex-shrink: 0;\n margin-top: -2px;\n }\n\n .msg_content {\n overflow: hidden;\n flex-grow: 1;\n margin-right:5px;\n }\n\n .msg_desc {\n color: #646464;\n cursor: initial;\n word-wrap: break-word;\n }\n\n .msg.collapsed .msg_desc {\n overflow: hidden;\n text-overflow: ellipsis;\n white-space: nowrap;\n }\n\n .msg.collapsible.collapsed .chevron {\n transform: rotate(-45deg) translateX(-2px);\n }\n\n .msg.collapsible .chevron {\n content: \"\";\n width:6px;\n height:6px;\n border-bottom: 2px solid grey;\n border-right: 2px solid grey;\n transform: rotate(45deg) translateX(-1px);\n margin: 5px;\n flex-shrink:0;\n }\n`;\n\ntype MessagesState = { messages: DebuggerMessage[] };\n\nconst BaseClass = compose(injectStyleMixin)(HTMLElement);\n\nclass Debugger extends BaseClass {\n #messagesState = new State<MessagesState>({ messages: [] });\n\n #rootEle: HTMLDivElement;\n\n #contentEle: HTMLDivElement;\n\n #headerEle: HTMLDivElement;\n\n #eventsCbRefs = {\n resize: this.#onWindowResize.bind(this),\n };\n\n constructor() {\n super();\n\n this.attachShadow({ mode: 'open' });\n this.shadowRoot.appendChild(template.content.cloneNode(true));\n\n this.#rootEle = this.shadowRoot.querySelector<HTMLDivElement>('.debugger');\n this.#contentEle = this.#rootEle.querySelector<HTMLDivElement>('.content');\n this.#headerEle = this.#rootEle.querySelector<HTMLDivElement>('.header');\n\n this.#initStyle();\n }\n\n #initStyle() {\n this.injectStyle(style);\n\n this.#rootEle.style.top = `${INITIAL_POS_THRESHOLD}px`;\n this.#rootEle.style.left = `${\n window.innerWidth - INITIAL_WIDTH - INITIAL_POS_THRESHOLD\n }px`;\n }\n\n updateData(data: DebuggerMessage | DebuggerMessage[]) {\n this.#messagesState.update((state) => ({\n messages: state.messages.concat(data),\n }));\n }\n\n #onNewMessages(data: MessagesState) {\n this.#renderMessages(data);\n this.#setCollapsibleMessages();\n }\n\n #renderMessages(data: MessagesState) {\n this.#contentEle.innerHTML = data.messages\n .map(\n (message) => `\n <div class=\"msg\">\n ${icon}\n <div class=\"msg_content\">\n <div class=\"msg_title\">\n ${escapeHtml(message.title)}\n </div>\n <div class=\"msg_desc\">\n ${escapeHtml(message.description)}\n </div>\n </div>\n <div class=\"chevron\"></div>\n </div>\n `,\n )\n .join('');\n }\n\n #setCollapsibleMessages() {\n this.#contentEle.querySelectorAll('.msg').forEach((ele: HTMLElement) => {\n const descEle = ele.querySelector('.msg_desc');\n const lineHeight = 20;\n const isScroll = descEle.scrollWidth > descEle.clientWidth;\n const isMultiLine = descEle.clientHeight > lineHeight;\n const isCollapsible = isScroll || isMultiLine;\n\n if (isCollapsible) {\n ele.classList.add('collapsible');\n ele.onclick = (e: MouseEvent) => {\n // message description should not toggle collapse\n if (!(e.target as HTMLElement).classList.contains('msg_desc')) {\n ele.classList.toggle('collapsed');\n }\n };\n } else {\n ele.classList.remove('collapsible');\n ele.onclick = null;\n }\n });\n }\n\n #onWindowResize() {\n // when window is resizing we want to make sure debugger is still visible\n const [left, top] = limitCoordinateToScreenBoundaries(\n this.#rootEle,\n Number.parseInt(this.#rootEle.style.left, 10),\n Number.parseInt(this.#rootEle.style.top, 10),\n { top: 'all', bottom: 100, left: 100, right: 100 },\n );\n this.#rootEle.style.top = `${top}px`;\n this.#rootEle.style.left = `${left}px`;\n }\n\n async init() {\n super.init?.();\n dragElement(this.#rootEle, this.#headerEle, {\n top: 'all',\n bottom: 100,\n left: 100,\n right: 100,\n });\n\n window.addEventListener('resize', this.#eventsCbRefs.resize);\n\n addOnResize(this.#rootEle);\n this.#rootEle.onresize = this.#setCollapsibleMessages.bind(this);\n\n this.#messagesState.subscribe(this.#onNewMessages.bind(this));\n }\n\n disconnectedCallback() {\n this.#messagesState.unsubscribeAll();\n window.removeEventListener('resize', this.#eventsCbRefs.resize);\n }\n}\n\nif (!customElements.get('descope-debugger')) {\n customElements.define('descope-debugger', Debugger);\n}\nexport default Debugger;\n"],"names":["template","document","createElement","innerHTML","BaseClass","compose","injectStyleMixin","HTMLElement","Debugger","constructor","super","_Debugger_messagesState","set","this","State","messages","_Debugger_rootEle","_Debugger_contentEle","_Debugger_headerEle","_Debugger_eventsCbRefs","resize","__classPrivateFieldGet","_Debugger_instances","_Debugger_onWindowResize","bind","attachShadow","mode","shadowRoot","appendChild","content","cloneNode","__classPrivateFieldSet","querySelector","_Debugger_initStyle","call","updateData","data","update","state","concat","init","_a","_super","dragElement","top","bottom","left","right","window","addEventListener","addOnResize","onresize","_Debugger_setCollapsibleMessages","subscribe","_Debugger_onNewMessages","disconnectedCallback","unsubscribeAll","removeEventListener","injectStyle","style","innerWidth","_Debugger_renderMessages","map","message","escapeHtml","title","description","join","querySelectorAll","forEach","ele","descEle","isScroll","scrollWidth","clientWidth","isMultiLine","clientHeight","classList","add","onclick","e","target","contains","toggle","remove","limitCoordinateToScreenBoundaries","Number","parseInt","customElements","get","define"],"mappings":"sYAWA,MAKMA,EAAWC,SAASC,cAAc,YACxCF,EAASG,UAAY,sNAarB,MAiHMC,EAAYC,EAAOA,QAACC,mBAARD,CAA0BE,aAE5C,MAAMC,UAAiBJ,EAarB,WAAAK,GACEC,oBAbFC,EAAiBC,IAAAC,KAAA,IAAIC,EAAqB,CAAEC,SAAU,MAEtDC,EAAyBJ,IAAAC,UAAA,GAEzBI,EAA4BL,IAAAC,UAAA,GAE5BK,EAA2BN,IAAAC,UAAA,GAE3BM,EAAgBP,IAAAC,KAAA,CACdO,OAAQC,EAAAA,uBAAAR,KAAIS,EAAA,IAAAC,GAAiBC,KAAKX,QAMlCA,KAAKY,aAAa,CAAEC,KAAM,SAC1Bb,KAAKc,WAAWC,YAAY5B,EAAS6B,QAAQC,WAAU,IAEvDC,yBAAAlB,KAAgBG,EAAAH,KAAKc,WAAWK,cAA8B,aAAY,KAC1ED,EAAAA,uBAAAlB,KAAmBI,EAAAI,EAAAA,uBAAAR,KAAIG,EAAA,KAAUgB,cAA8B,YAAW,KAC1ED,EAAAA,uBAAAlB,KAAkBK,EAAAG,EAAAA,uBAAAR,KAAIG,EAAA,KAAUgB,cAA8B,WAAU,KAExEX,EAAAA,uBAAAR,KAAIS,EAAA,IAAAW,GAAJC,KAAArB,KACD,CAWD,UAAAsB,CAAWC,GACTf,EAAAA,uBAAAR,KAAmBF,EAAA,KAAC0B,QAAQC,IAAW,CACrCvB,SAAUuB,EAAMvB,SAASwB,OAAOH,MAEnC,CA+DK,IAAAI,oHACM,QAAVC,EAAAC,EAAMF,YAAI,IAAAC,GAAAA,EAAAP,KAAArB,MACV8B,cAAYtB,EAAAA,uBAAAR,KAAIG,EAAA,KAAWK,EAAAA,uBAAAR,YAAiB,CAC1C+B,IAAK,MACLC,OAAQ,IACRC,KAAM,IACNC,MAAO,MAGTC,OAAOC,iBAAiB,SAAU5B,EAAAA,uBAAAR,KAAkBM,EAAA,KAACC,QAErD8B,EAAAA,YAAY7B,EAAAA,uBAAAR,KAAIG,EAAA,MAChBK,EAAAA,uBAAAR,KAAIG,EAAA,KAAUmC,SAAW9B,EAAAA,uBAAAR,KAAIS,EAAA,IAAA8B,GAAyB5B,KAAKX,MAE3DQ,EAAAA,uBAAAR,KAAIF,EAAA,KAAgB0C,UAAUhC,EAAAA,uBAAAR,KAAmBS,EAAA,IAAAgC,GAAC9B,KAAKX,SACxD,CAED,oBAAA0C,GACElC,EAAAA,uBAAAR,KAAIF,EAAA,KAAgB6C,iBACpBR,OAAOS,oBAAoB,SAAUpC,EAAAA,uBAAAR,KAAkBM,EAAA,KAACC,OACzD,mGA/FCP,KAAK6C,YAzIK,07DA2IVrC,yBAAAR,KAAaG,EAAA,KAAC2C,MAAMf,IAAM,OAC1BvB,EAAAA,uBAAAR,KAAaG,EAAA,KAAC2C,MAAMb,KAClBE,OAAOY,WApKS,IADQ,GAoKC,IAG7B,aAQexB,GACbf,yBAAAR,KAAoBS,EAAA,IAAAuC,GAAA3B,KAApBrB,KAAqBuB,GACrBf,EAAAA,uBAAAR,KAAIS,EAAA,IAAA8B,GAAJlB,KAAArB,KACF,aAEgBuB,GACdf,EAAAA,uBAAAR,KAAgBI,EAAA,KAACd,UAAYiC,EAAKrB,SAC/B+C,KACEC,GAAY,qlDAKTC,EAAUA,WAACD,EAAQE,qEAGnBD,EAAUA,WAACD,EAAQG,kGAOxBC,KAAK,GACV,EAACf,EAAA,WAGC/B,yBAAAR,KAAII,EAAA,KAAamD,iBAAiB,QAAQC,SAASC,IACjD,MAAMC,EAAUD,EAAItC,cAAc,aAE5BwC,EAAWD,EAAQE,YAAcF,EAAQG,YACzCC,EAAcJ,EAAQK,aAFT,GAGGJ,GAAYG,GAGhCL,EAAIO,UAAUC,IAAI,eAClBR,EAAIS,QAAWC,IAEPA,EAAEC,OAAuBJ,UAAUK,SAAS,aAChDZ,EAAIO,UAAUM,OAAO,YACtB,IAGHb,EAAIO,UAAUO,OAAO,eACrBd,EAAIS,QAAU,KACf,GAEL,EAACxD,EAAA,WAIC,MAAOuB,EAAMF,GAAOyC,EAAAA,kCAClBhE,EAAAA,uBAAAR,KAAaG,EAAA,KACbsE,OAAOC,SAASlE,EAAAA,uBAAAR,KAAaG,EAAA,KAAC2C,MAAMb,KAAM,IAC1CwC,OAAOC,SAASlE,EAAAA,uBAAAR,KAAIG,EAAA,KAAU2C,MAAMf,IAAK,IACzC,CAAEA,IAAK,MAAOC,OAAQ,IAAKC,KAAM,IAAKC,MAAO,MAE/C1B,yBAAAR,KAAaG,EAAA,KAAC2C,MAAMf,IAAM,GAAGA,MAC7BvB,yBAAAR,KAAaG,EAAA,KAAC2C,MAAMb,KAAO,GAAGA,KAChC,EAyBG0C,eAAeC,IAAI,qBACtBD,eAAeE,OAAO,mBAAoBlF"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var t=require("tslib"),e=require("@descope/sdk-helpers"),i=require("@descope/sdk-mixins/static-resources-mixin"),s=require("@descope/sdk-mixins/theme-mixin"),r=require("@descope/sdk-mixins/inject-style-mixin"),n=require("@descope/sdk-mixins/telemetry-mixin"),o=require("@descope/web-js-sdk"),a=require("../constants/index.js"),l=require("../helpers/helpers.js"),d=require("../helpers/state.js");require("@descope/escape-markdown"),require("../helpers/webauthn.js");var u,c,h,g,f,p,v,_,m,b,w,k,C,P,x,F,y,A,E,S,G,I,j,M,O,q,U=require("../helpers/storage.js"),L=require("../helpers/flowInputs.js"),R=require("../mixins/formMountMixin.js"),T=require("../mixins/componentConditionsMixin.js"),W=require("../mixins/duplicateFlowWarningMixin.js"),N=require("../mixins/passwordManagerMixin.js"),D=require("../mixins/validationTrackingMixin.js"),K=require("../constants/content.js"),V=require("../constants/general.js");function z(t){return Object.freeze({__proto__:null,default:t})}const H=e.compose(s.themeMixin,i.staticResourcesMixin,R.formMountMixin,T.componentConditionsMixin,W.duplicateFlowWarningMixin,N.passwordManagerMixin,r.injectStyleMixin,n.telemetryMixin,D.validationTrackingMixin)(HTMLElement);class J extends H{static get observedAttributes(){return["project-id","flow-id","base-url","tenant","locale","debug","storage-prefix","preview","redirect-url","auto-focus","store-last-authenticated-user","refresh-cookie-name","keep-last-authenticated-user-after-logout","validate-on-blur","send-session-token","style-id"]}constructor(e){super(),u.add(this),this.sdkVersion="4.4.2",h.set(this,!1),g.set(this,void 0),this.flowStatus="initial",this.loggerWrapper={error:(e,i="")=>{this.logger.error(e,i,new Error),t.__classPrivateFieldGet(this,u,"m",q).call(this,e,i)},warn:(t,e="")=>{this.logger.warn(t,e)},info:(t,e="",i={})=>{this.logger.info(t,e,i)},debug:(t,e="")=>{this.logger.debug(t,e)}},f.set(this,new d),p.set(this,new d),v.set(this,{}),this.getComponentsContext=()=>t.__classPrivateFieldGet(this,v,"f"),this.nextRequestStatus=new d({isLoading:!1}),_.set(this,void 0),m.set(this,{popstate:t.__classPrivateFieldGet(this,u,"m",P).bind(this),componentsContext:t.__classPrivateFieldGet(this,u,"m",S).bind(this)}),b.set(this,void 0),this.getConfig=()=>t.__awaiter(this,void 0,void 0,(function*(){return(yield this.config)||{isMissingConfig:!0}})),G.set(this,void 0),I.set(this,void 0),t.__classPrivateFieldSet(this,b,e,"f"),t.__classPrivateFieldGet(this,u,"m",k).call(this)}get client(){try{return JSON.parse(this.getAttribute("client"))||{}}catch(t){return{}}}get redirectUrl(){return this.getAttribute("redirect-url")||void 0}get debug(){return"true"===this.getAttribute("debug")}get locale(){return this.getAttribute("locale")||void 0}get autoFocus(){var t;const e=null!==(t=this.getAttribute("auto-focus"))&&void 0!==t?t:"true";return"skipFirstScreen"===e?e:"true"===e}get validateOnBlur(){return"true"===this.getAttribute("validate-on-blur")}get storeLastAuthenticatedUser(){var t;return"true"===(null!==(t=this.getAttribute("store-last-authenticated-user"))&&void 0!==t?t:"true")}get refreshCookieName(){return this.getAttribute("refresh-cookie-name")||""}get keepLastAuthenticatedUserAfterLogout(){return"true"===this.getAttribute("keep-last-authenticated-user-after-logout")}get storagePrefix(){return this.getAttribute("storage-prefix")||""}get sendSessionToken(){return"true"===this.getAttribute("send-session-token")}get preview(){return!!this.getAttribute("preview")}get formConfig(){return L.transformFlowInputFormData(this.form)}get form(){return this.getAttribute("form")}get formConfigValues(){return L.extractNestedAttribute(this.formConfig,"value")}get outboundAppId(){return this.getAttribute("outbound-app-id")}get outboundAppScopes(){try{const t=JSON.parse(this.getAttribute("outbound-app-scopes"));return t||null}catch(t){return null}}get popupOrigin(){return this.getAttribute("popup-origin")}get customStorage(){return t.__classPrivateFieldGet(this,g,"f")}set customStorage(e){if(e&&"function"!=typeof e.getItem)throw new Error("Custom storage must have a getItem method");if(e&&"function"!=typeof e.setItem)throw new Error("Custom storage must have a setItem method");if(e&&"function"!=typeof e.removeItem)throw new Error("Custom storage must have a removeItem method");t.__classPrivateFieldSet(this,g,e,"f"),U.setCustomStorage(e)}get lazyStart(){return"true"===this.getAttribute("lazy-start")}start(){var e;null===(e=t.__classPrivateFieldGet(this,I,"f"))||void 0===e||e.call(this),t.__classPrivateFieldSet(this,G,Promise.resolve(),"f")}get isRestartOnError(){return"true"===this.getAttribute("restart-on-error")}getExecutionContext(){return t.__awaiter(this,void 0,void 0,(function*(){const t=yield this.getConfig();return"executionContext"in t?t.executionContext:void 0}))}getProjectConfig(){return t.__awaiter(this,void 0,void 0,(function*(){const t=yield this.getConfig();return"projectConfig"in t?t.projectConfig:void 0}))}getFlowConfig(){return t.__awaiter(this,void 0,void 0,(function*(){var t,e;const i=yield this.getProjectConfig(),s=(null===(t=null==i?void 0:i.flows)||void 0===t?void 0:t[this.flowId])||{};return null!==(e=s.version)&&void 0!==e||(s.version=0),s}))}getTargetLocales(){return t.__awaiter(this,void 0,void 0,(function*(){const t=yield this.getFlowConfig();return((null==t?void 0:t.targetLocales)||[]).map((t=>t.toLowerCase()))}))}handleKeyPress(){this.logger.debug("Enable key press handler"),this.rootElement.onkeydown=t=>{var e,i,s;const r=!!(null===(e=this.shadowRoot.activeElement)||void 0===e?void 0:e.getAttribute("href")),n=a.ELEMENTS_TO_IGNORE_ENTER_KEY_ON.includes(null!==(s=null===(i=this.shadowRoot.activeElement)||void 0===i?void 0:i.localName)&&void 0!==s?s:"");if("Enter"!==t.key||r||n)return;t.preventDefault();const o=this.rootElement.querySelectorAll("descope-button");if(1===o.length&&"false"!==o[0].getAttribute("auto-submit"))return void o[0].click();const l=Array.from(o).filter((t=>"true"===t.getAttribute("auto-submit")));if(1===l.length)return void l[0].click();const d=Array.from(o).filter((t=>"button"===t.getAttribute("data-type")));if(1===d.length)"false"!==d[0].getAttribute("auto-submit")&&d[0].click();else if(0===d.length){const t=Array.from(o).filter((t=>"sso"===t.getAttribute("data-type")));1===t.length&&"false"!==t[0].getAttribute("auto-submit")&&t[0].click()}}}disableKeyPressHandler(){this.logger.debug("Disable key press handler"),this.rootElement.onkeydown=null}getComponentsVersion(){return t.__awaiter(this,void 0,void 0,(function*(){var t;const e=yield this.getConfig(),i="projectConfig"in e?null===(t=e.projectConfig)||void 0===t?void 0:t.componentsVersion:{};return i||(this.logger.error("Did not get components version, using latest version"),"latest")}))}init(){const e=Object.create(null,{init:{get:()=>super.init}});return t.__awaiter(this,void 0,void 0,(function*(){var i;if(this.flowStatus="loading",["ready","error","success"].forEach((t=>this.addEventListener(t,(()=>{this.flowStatus=t})))),yield null===(i=e.init)||void 0===i?void 0:i.call(this),t.__classPrivateFieldGet(this,p,"f").subscribe(t.__classPrivateFieldGet(this,u,"m",O).bind(this)),t.__classPrivateFieldGet(this,p,"f").update({isDebug:this.debug}),t.__classPrivateFieldGet(this,u,"m",C).call(this),yield t.__classPrivateFieldGet(this,u,"m",A).call(this))return void this.loggerWrapper.error("This SDK version does not support your flows version","Make sure to upgrade your flows to the latest version or use an older SDK version");const s=yield this.getConfig();if("isMissingConfig"in s&&s.isMissingConfig)return void this.loggerWrapper.error("Cannot get config file","Make sure that your projectId & flowId are correct");const{executionId:r,stepId:n,token:o,code:a,isPopup:d,exchangeError:c,redirectAuthCallbackUrl:g,redirectAuthBackupCallbackUri:v,redirectAuthCodeChallenge:_,redirectAuthInitiator:b,ssoQueryParams:w}=l.handleUrlParams(this.flowId,this.loggerWrapper);window.addEventListener("popstate",t.__classPrivateFieldGet(this,m,"f").popstate),window.addEventListener("components-context",t.__classPrivateFieldGet(this,m,"f").componentsContext),t.__classPrivateFieldGet(this,f,"f").subscribe(t.__classPrivateFieldGet(this,u,"m",y).bind(this)),t.__classPrivateFieldGet(this,f,"f").update(Object.assign({projectId:this.projectId,flowId:this.flowId,baseUrl:this.baseUrl,tenant:this.tenantId,redirectUrl:this.redirectUrl,locale:this.locale,stepId:n,executionId:r,token:o,code:a,isPopup:d,exchangeError:c,redirectAuthCallbackUrl:g,redirectAuthBackupCallbackUri:v,redirectAuthCodeChallenge:_,redirectAuthInitiator:b},w)),t.__classPrivateFieldSet(this,h,!0,"f")}))}disconnectedCallback(){var e;t.__classPrivateFieldGet(this,f,"f").unsubscribeAll(),t.__classPrivateFieldGet(this,p,"f").unsubscribeAll(),t.__classPrivateFieldGet(this,u,"m",M).call(this),window.removeEventListener("popstate",t.__classPrivateFieldGet(this,m,"f").popstate),window.removeEventListener("components-context",t.__classPrivateFieldGet(this,m,"f").componentsContext),null===(e=super.disconnectedCallback)||void 0===e||e.call(this)}attributeChangedCallback(e,i,s){var r;if(null===(r=super.attributeChangedCallback)||void 0===r||r.call(this,e,i,s),this.shadowRoot.isConnected&&t.__classPrivateFieldGet(this,h,"f")&&i!==s&&c.observedAttributes.includes(e)){t.__classPrivateFieldGet(this,u,"m",C).call(this);const r=null===i;t.__classPrivateFieldGet(this,f,"f").update((({stepId:t,executionId:i})=>{let n=t,o=i;return r||(o=null,n=null,l.clearRunIdsFromUrl()),{[l.camelCase(e)]:s,stepId:n,executionId:o}})),t.__classPrivateFieldGet(this,p,"f").update({isDebug:this.debug})}}}c=J,h=new WeakMap,g=new WeakMap,f=new WeakMap,p=new WeakMap,v=new WeakMap,_=new WeakMap,m=new WeakMap,b=new WeakMap,G=new WeakMap,I=new WeakMap,u=new WeakSet,w=function(){this.injectStyle("\n :host {\n\t\t\twidth: 100%;\n display: block;\n\t\t}\n\n\t\t#root {\n\t\t\theight: 100%;\n display: flex;\n flex-direction: column;\n\t\t}\n\n #content-root {\n all: initial;\n transition: opacity 200ms ease-in-out;\n }\n\n\t\t#root[data-theme] {\n\t\t\tbackground-color: transparent;\n\t\t}\n\n\t\t.fade-out {\n\t\t\topacity: 0.1!important;\n\t\t}\n\n .hidden {\n display: none;\n }\n ")},k=function(){t.__classPrivateFieldGet(this,u,"m",w).call(this),this.slotElement=document.createElement("slot"),this.slotElement.classList.add("hidden"),this.rootElement.appendChild(this.slotElement)},C=function(){const t=["base-url","tenant","locale","debug","redirect-url","auto-focus","store-last-authenticated-user","refresh-cookie-name","keep-last-authenticated-user-after-logout","preview","storage-prefix","form","client","validate-on-blur","send-session-token","style-id","outbound-app-id","outbound-app-scopes","theme-override"];c.observedAttributes.forEach((e=>{if(!t.includes(e)&&!this[l.camelCase(e)])throw Error(`${e} cannot be empty`)}))},P=function(){const{stepId:e,executionId:i}=l.getRunIdsFromUrl(this.flowId);t.__classPrivateFieldGet(this,f,"f").update({stepId:e,executionId:i})},x=function(e,i){o.createSdk&&"function"==typeof o.createSdk||this.logger.error("SDK was not loaded properly",o.createSdk,JSON.stringify(o.createSdk));const s=Object.assign(Object.assign({persistTokens:!0,preview:this.preview,storagePrefix:this.storagePrefix,storeLastAuthenticatedUser:this.storeLastAuthenticatedUser,keepLastAuthenticatedUserAfterLogout:this.keepLastAuthenticatedUserAfterLogout,refreshCookieName:this.refreshCookieName},c.sdkConfigOverrides),{projectId:e,baseUrl:i});t.__classPrivateFieldGet(this,g,"f")&&(s.customStorage=t.__classPrivateFieldGet(this,g,"f")),this.sdk=o.createSdk(s);const r={start:1,next:7};["start","next"].forEach((e=>{const i=this.sdk.flow[e],s=l.withRetry(i,1e3,3);this.sdk.flow[e]=(...i)=>t.__awaiter(this,void 0,void 0,(function*(){const n=[...i],o=r[e],a=t.__classPrivateFieldGet(this,u,"m",F).call(this,n[o]);void 0!==a&&(n[o]=a);try{return yield s(...n)}catch(t){return this.logger.error(`Error in sdk flow ${e} function`,t),{error:{errorCode:V.FETCH_EXCEPTION_ERROR_CODE,errorDescription:t.toString()}}}}))}));const n=this.sdk.flow.start;this.sdk.flow.start=(...e)=>t.__awaiter(this,void 0,void 0,(function*(){return yield t.__classPrivateFieldGet(this,u,"m",j).call(this),n.apply(this.sdk.flow,e)}))},F=function(t){if(!this.sendSessionToken)return t;const e=null===o.getSessionToken||void 0===o.getSessionToken?void 0:o.getSessionToken(this.storagePrefix);return e?Object.assign(Object.assign({},null!=t?t:{}),{sessionJwt:e}):t},y=function(e,i,s){return t.__awaiter(this,void 0,void 0,(function*(){const{projectId:i,baseUrl:r}=e;if(s("projectId")||s("baseUrl")){if(!i)return;t.__classPrivateFieldGet(this,u,"m",x).call(this,i,r)}t.__classPrivateFieldGet(this,b,"f").call(this,e)}))},A=function(){return t.__awaiter(this,void 0,void 0,(function*(){const e=yield this.getConfig();return"isMissingConfig"in e&&e.isMissingConfig&&(yield t.__classPrivateFieldGet(this,u,"m",E).call(this))}))},E=function(){return t.__awaiter(this,void 0,void 0,(function*(){const t=l.getContentUrl({projectId:this.projectId,filename:K.CONFIG_FILENAME,assetsFolder:K.PREV_VER_ASSETS_FOLDER,baseUrl:this.baseStaticUrl});try{return yield l.fetchContent(t,"json"),!0}catch(t){return!1}}))},S=function(e){t.__classPrivateFieldSet(this,v,Object.assign(Object.assign({},t.__classPrivateFieldGet(this,v,"f")),e.detail),"f")},j=function(){return this.lazyStart?(t.__classPrivateFieldGet(this,G,"f")||t.__classPrivateFieldSet(this,G,new Promise((e=>{t.__classPrivateFieldSet(this,I,e,"f")})),"f"),t.__classPrivateFieldGet(this,G,"f")):Promise.resolve()},M=function(){var e;null===(e=t.__classPrivateFieldGet(this,_,"f"))||void 0===e||e.remove(),t.__classPrivateFieldSet(this,_,null,"f")},O=function(e){return t.__awaiter(this,arguments,void 0,(function*({isDebug:e}){e?(t.__classPrivateFieldSet(this,_,document.createElement("descope-debugger"),"f"),Object.assign(t.__classPrivateFieldGet(this,_,"f").style,{position:"fixed",top:"0",right:"0",height:"100vh",width:"100vw",pointerEvents:"none",zIndex:99999}),yield Promise.resolve().then((function(){return z(require("../debugger-wc.js"))})),document.body.appendChild(t.__classPrivateFieldGet(this,_,"f"))):t.__classPrivateFieldGet(this,u,"m",M).call(this)}))},q=function(e,i){var s;e&&this.debug&&(null===(s=t.__classPrivateFieldGet(this,_,"f"))||void 0===s||s.updateData({title:e,description:i}))},J.sdkConfigOverrides={baseHeaders:{"x-descope-sdk-name":"web-component","x-descope-sdk-version":"4.4.2"}},module.exports=J;
|
|
1
|
+
"use strict";var t=require("tslib"),e=require("@descope/sdk-helpers"),i=require("@descope/sdk-mixins/static-resources-mixin"),s=require("@descope/sdk-mixins/theme-mixin"),r=require("@descope/sdk-mixins/inject-style-mixin"),n=require("@descope/sdk-mixins/telemetry-mixin"),o=require("@descope/web-js-sdk"),a=require("../constants/index.js"),l=require("../helpers/helpers.js"),d=require("../helpers/state.js");require("@descope/escape-markdown"),require("../helpers/webauthn.js");var u,c,h,g,f,p,v,_,m,b,w,k,C,P,x,F,y,A,E,S,G,I,j,M,O,q,U=require("../helpers/storage.js"),L=require("../helpers/flowInputs.js"),R=require("../mixins/formMountMixin.js"),T=require("../mixins/componentConditionsMixin.js"),W=require("../mixins/duplicateFlowWarningMixin.js"),N=require("../mixins/passwordManagerMixin.js"),D=require("../mixins/validationTrackingMixin.js"),K=require("../constants/content.js"),V=require("../constants/general.js");function z(t){return Object.freeze({__proto__:null,default:t})}const H=e.compose(s.themeMixin,i.staticResourcesMixin,R.formMountMixin,T.componentConditionsMixin,W.duplicateFlowWarningMixin,N.passwordManagerMixin,r.injectStyleMixin,n.telemetryMixin,D.validationTrackingMixin)(HTMLElement);class J extends H{static get observedAttributes(){return["project-id","flow-id","base-url","tenant","locale","debug","storage-prefix","preview","redirect-url","auto-focus","store-last-authenticated-user","refresh-cookie-name","keep-last-authenticated-user-after-logout","validate-on-blur","send-session-token","style-id"]}constructor(e){super(),u.add(this),this.sdkVersion="4.4.4",h.set(this,!1),g.set(this,void 0),this.flowStatus="initial",this.loggerWrapper={error:(e,i="")=>{this.logger.error(e,i,new Error),t.__classPrivateFieldGet(this,u,"m",q).call(this,e,i)},warn:(t,e="")=>{this.logger.warn(t,e)},info:(t,e="",i={})=>{this.logger.info(t,e,i)},debug:(t,e="")=>{this.logger.debug(t,e)}},f.set(this,new d),p.set(this,new d),v.set(this,{}),this.getComponentsContext=()=>t.__classPrivateFieldGet(this,v,"f"),this.nextRequestStatus=new d({isLoading:!1}),_.set(this,void 0),m.set(this,{popstate:t.__classPrivateFieldGet(this,u,"m",P).bind(this),componentsContext:t.__classPrivateFieldGet(this,u,"m",S).bind(this)}),b.set(this,void 0),this.getConfig=()=>t.__awaiter(this,void 0,void 0,(function*(){return(yield this.config)||{isMissingConfig:!0}})),G.set(this,void 0),I.set(this,void 0),t.__classPrivateFieldSet(this,b,e,"f"),t.__classPrivateFieldGet(this,u,"m",k).call(this)}get client(){try{return JSON.parse(this.getAttribute("client"))||{}}catch(t){return{}}}get redirectUrl(){return this.getAttribute("redirect-url")||void 0}get debug(){return"true"===this.getAttribute("debug")}get locale(){return this.getAttribute("locale")||void 0}get autoFocus(){var t;const e=null!==(t=this.getAttribute("auto-focus"))&&void 0!==t?t:"true";return"skipFirstScreen"===e?e:"true"===e}get validateOnBlur(){return"true"===this.getAttribute("validate-on-blur")}get storeLastAuthenticatedUser(){var t;return"true"===(null!==(t=this.getAttribute("store-last-authenticated-user"))&&void 0!==t?t:"true")}get refreshCookieName(){return this.getAttribute("refresh-cookie-name")||""}get keepLastAuthenticatedUserAfterLogout(){return"true"===this.getAttribute("keep-last-authenticated-user-after-logout")}get storagePrefix(){return this.getAttribute("storage-prefix")||""}get sendSessionToken(){return"true"===this.getAttribute("send-session-token")}get preview(){return!!this.getAttribute("preview")}get formConfig(){return L.transformFlowInputFormData(this.form)}get form(){return this.getAttribute("form")}get formConfigValues(){return L.extractNestedAttribute(this.formConfig,"value")}get outboundAppId(){return this.getAttribute("outbound-app-id")}get outboundAppScopes(){try{const t=JSON.parse(this.getAttribute("outbound-app-scopes"));return t||null}catch(t){return null}}get popupOrigin(){return this.getAttribute("popup-origin")}get customStorage(){return t.__classPrivateFieldGet(this,g,"f")}set customStorage(e){if(e&&"function"!=typeof e.getItem)throw new Error("Custom storage must have a getItem method");if(e&&"function"!=typeof e.setItem)throw new Error("Custom storage must have a setItem method");if(e&&"function"!=typeof e.removeItem)throw new Error("Custom storage must have a removeItem method");t.__classPrivateFieldSet(this,g,e,"f"),U.setCustomStorage(e)}get lazyStart(){return"true"===this.getAttribute("lazy-start")}start(){var e;null===(e=t.__classPrivateFieldGet(this,I,"f"))||void 0===e||e.call(this),t.__classPrivateFieldSet(this,G,Promise.resolve(),"f")}get isRestartOnError(){return"true"===this.getAttribute("restart-on-error")}getExecutionContext(){return t.__awaiter(this,void 0,void 0,(function*(){const t=yield this.getConfig();return"executionContext"in t?t.executionContext:void 0}))}getProjectConfig(){return t.__awaiter(this,void 0,void 0,(function*(){const t=yield this.getConfig();return"projectConfig"in t?t.projectConfig:void 0}))}getFlowConfig(){return t.__awaiter(this,void 0,void 0,(function*(){var t,e;const i=yield this.getProjectConfig(),s=(null===(t=null==i?void 0:i.flows)||void 0===t?void 0:t[this.flowId])||{};return null!==(e=s.version)&&void 0!==e||(s.version=0),s}))}getTargetLocales(){return t.__awaiter(this,void 0,void 0,(function*(){const t=yield this.getFlowConfig();return((null==t?void 0:t.targetLocales)||[]).map((t=>t.toLowerCase()))}))}handleKeyPress(){this.logger.debug("Enable key press handler"),this.rootElement.onkeydown=t=>{var e,i,s;const r=!!(null===(e=this.shadowRoot.activeElement)||void 0===e?void 0:e.getAttribute("href")),n=a.ELEMENTS_TO_IGNORE_ENTER_KEY_ON.includes(null!==(s=null===(i=this.shadowRoot.activeElement)||void 0===i?void 0:i.localName)&&void 0!==s?s:"");if("Enter"!==t.key||r||n)return;t.preventDefault();const o=this.rootElement.querySelectorAll("descope-button");if(1===o.length&&"false"!==o[0].getAttribute("auto-submit"))return void o[0].click();const l=Array.from(o).filter((t=>"true"===t.getAttribute("auto-submit")));if(1===l.length)return void l[0].click();const d=Array.from(o).filter((t=>"button"===t.getAttribute("data-type")));if(1===d.length)"false"!==d[0].getAttribute("auto-submit")&&d[0].click();else if(0===d.length){const t=Array.from(o).filter((t=>"sso"===t.getAttribute("data-type")));1===t.length&&"false"!==t[0].getAttribute("auto-submit")&&t[0].click()}}}disableKeyPressHandler(){this.logger.debug("Disable key press handler"),this.rootElement.onkeydown=null}getComponentsVersion(){return t.__awaiter(this,void 0,void 0,(function*(){var t;const e=yield this.getConfig(),i="projectConfig"in e?null===(t=e.projectConfig)||void 0===t?void 0:t.componentsVersion:{};return i||(this.logger.error("Did not get components version, using latest version"),"latest")}))}init(){const e=Object.create(null,{init:{get:()=>super.init}});return t.__awaiter(this,void 0,void 0,(function*(){var i;if(this.flowStatus="loading",["ready","error","success"].forEach((t=>this.addEventListener(t,(()=>{this.flowStatus=t})))),yield null===(i=e.init)||void 0===i?void 0:i.call(this),t.__classPrivateFieldGet(this,p,"f").subscribe(t.__classPrivateFieldGet(this,u,"m",O).bind(this)),t.__classPrivateFieldGet(this,p,"f").update({isDebug:this.debug}),t.__classPrivateFieldGet(this,u,"m",C).call(this),yield t.__classPrivateFieldGet(this,u,"m",A).call(this))return void this.loggerWrapper.error("This SDK version does not support your flows version","Make sure to upgrade your flows to the latest version or use an older SDK version");const s=yield this.getConfig();if("isMissingConfig"in s&&s.isMissingConfig)return void this.loggerWrapper.error("Cannot get config file","Make sure that your projectId & flowId are correct");const{executionId:r,stepId:n,token:o,code:a,isPopup:d,exchangeError:c,redirectAuthCallbackUrl:g,redirectAuthBackupCallbackUri:v,redirectAuthCodeChallenge:_,redirectAuthInitiator:b,ssoQueryParams:w}=l.handleUrlParams(this.flowId,this.loggerWrapper);window.addEventListener("popstate",t.__classPrivateFieldGet(this,m,"f").popstate),window.addEventListener("components-context",t.__classPrivateFieldGet(this,m,"f").componentsContext),t.__classPrivateFieldGet(this,f,"f").subscribe(t.__classPrivateFieldGet(this,u,"m",y).bind(this)),t.__classPrivateFieldGet(this,f,"f").update(Object.assign({projectId:this.projectId,flowId:this.flowId,baseUrl:this.baseUrl,tenant:this.tenantId,redirectUrl:this.redirectUrl,locale:this.locale,stepId:n,executionId:r,token:o,code:a,isPopup:d,exchangeError:c,redirectAuthCallbackUrl:g,redirectAuthBackupCallbackUri:v,redirectAuthCodeChallenge:_,redirectAuthInitiator:b},w)),t.__classPrivateFieldSet(this,h,!0,"f")}))}disconnectedCallback(){var e;t.__classPrivateFieldGet(this,f,"f").unsubscribeAll(),t.__classPrivateFieldGet(this,p,"f").unsubscribeAll(),t.__classPrivateFieldGet(this,u,"m",M).call(this),window.removeEventListener("popstate",t.__classPrivateFieldGet(this,m,"f").popstate),window.removeEventListener("components-context",t.__classPrivateFieldGet(this,m,"f").componentsContext),null===(e=super.disconnectedCallback)||void 0===e||e.call(this)}attributeChangedCallback(e,i,s){var r;if(null===(r=super.attributeChangedCallback)||void 0===r||r.call(this,e,i,s),this.shadowRoot.isConnected&&t.__classPrivateFieldGet(this,h,"f")&&i!==s&&c.observedAttributes.includes(e)){t.__classPrivateFieldGet(this,u,"m",C).call(this);const r=null===i;t.__classPrivateFieldGet(this,f,"f").update((({stepId:t,executionId:i})=>{let n=t,o=i;return r||(o=null,n=null,l.clearRunIdsFromUrl()),{[l.camelCase(e)]:s,stepId:n,executionId:o}})),t.__classPrivateFieldGet(this,p,"f").update({isDebug:this.debug})}}}c=J,h=new WeakMap,g=new WeakMap,f=new WeakMap,p=new WeakMap,v=new WeakMap,_=new WeakMap,m=new WeakMap,b=new WeakMap,G=new WeakMap,I=new WeakMap,u=new WeakSet,w=function(){this.injectStyle("\n :host {\n\t\t\twidth: 100%;\n display: block;\n\t\t}\n\n\t\t#root {\n\t\t\theight: 100%;\n display: flex;\n flex-direction: column;\n\t\t}\n\n #content-root {\n all: initial;\n transition: opacity 200ms ease-in-out;\n }\n\n\t\t#root[data-theme] {\n\t\t\tbackground-color: transparent;\n\t\t}\n\n\t\t.fade-out {\n\t\t\topacity: 0.1!important;\n\t\t}\n\n .hidden {\n display: none;\n }\n ")},k=function(){t.__classPrivateFieldGet(this,u,"m",w).call(this),this.slotElement=document.createElement("slot"),this.slotElement.classList.add("hidden"),this.rootElement.appendChild(this.slotElement)},C=function(){const t=["base-url","tenant","locale","debug","redirect-url","auto-focus","store-last-authenticated-user","refresh-cookie-name","keep-last-authenticated-user-after-logout","preview","storage-prefix","form","client","validate-on-blur","send-session-token","style-id","outbound-app-id","outbound-app-scopes","theme-override"];c.observedAttributes.forEach((e=>{if(!t.includes(e)&&!this[l.camelCase(e)])throw Error(`${e} cannot be empty`)}))},P=function(){const{stepId:e,executionId:i}=l.getRunIdsFromUrl(this.flowId);t.__classPrivateFieldGet(this,f,"f").update({stepId:e,executionId:i})},x=function(e,i){o.createSdk&&"function"==typeof o.createSdk||this.logger.error("SDK was not loaded properly",o.createSdk,JSON.stringify(o.createSdk));const s=Object.assign(Object.assign({persistTokens:!0,preview:this.preview,storagePrefix:this.storagePrefix,storeLastAuthenticatedUser:this.storeLastAuthenticatedUser,keepLastAuthenticatedUserAfterLogout:this.keepLastAuthenticatedUserAfterLogout,refreshCookieName:this.refreshCookieName},c.sdkConfigOverrides),{projectId:e,baseUrl:i});t.__classPrivateFieldGet(this,g,"f")&&(s.customStorage=t.__classPrivateFieldGet(this,g,"f")),this.sdk=o.createSdk(s);const r={start:1,next:7};["start","next"].forEach((e=>{const i=this.sdk.flow[e],s=l.withRetry(i,1e3,3);this.sdk.flow[e]=(...i)=>t.__awaiter(this,void 0,void 0,(function*(){const n=[...i],o=r[e],a=t.__classPrivateFieldGet(this,u,"m",F).call(this,n[o]);void 0!==a&&(n[o]=a);try{return yield s(...n)}catch(t){return this.logger.error(`Error in sdk flow ${e} function`,t),{error:{errorCode:V.FETCH_EXCEPTION_ERROR_CODE,errorDescription:t.toString()}}}}))}));const n=this.sdk.flow.start;this.sdk.flow.start=(...e)=>t.__awaiter(this,void 0,void 0,(function*(){return yield t.__classPrivateFieldGet(this,u,"m",j).call(this),n.apply(this.sdk.flow,e)}))},F=function(t){if(!this.sendSessionToken)return t;const e=null===o.getSessionToken||void 0===o.getSessionToken?void 0:o.getSessionToken(this.storagePrefix);return e?Object.assign(Object.assign({},null!=t?t:{}),{sessionJwt:e}):t},y=function(e,i,s){return t.__awaiter(this,void 0,void 0,(function*(){const{projectId:i,baseUrl:r}=e;if(s("projectId")||s("baseUrl")){if(!i)return;t.__classPrivateFieldGet(this,u,"m",x).call(this,i,r)}t.__classPrivateFieldGet(this,b,"f").call(this,e)}))},A=function(){return t.__awaiter(this,void 0,void 0,(function*(){const e=yield this.getConfig();return"isMissingConfig"in e&&e.isMissingConfig&&(yield t.__classPrivateFieldGet(this,u,"m",E).call(this))}))},E=function(){return t.__awaiter(this,void 0,void 0,(function*(){const t=l.getContentUrl({projectId:this.projectId,filename:K.CONFIG_FILENAME,assetsFolder:K.PREV_VER_ASSETS_FOLDER,baseUrl:this.baseStaticUrl});try{return yield l.fetchContent(t,"json"),!0}catch(t){return!1}}))},S=function(e){t.__classPrivateFieldSet(this,v,Object.assign(Object.assign({},t.__classPrivateFieldGet(this,v,"f")),e.detail),"f")},j=function(){return this.lazyStart?(t.__classPrivateFieldGet(this,G,"f")||t.__classPrivateFieldSet(this,G,new Promise((e=>{t.__classPrivateFieldSet(this,I,e,"f")})),"f"),t.__classPrivateFieldGet(this,G,"f")):Promise.resolve()},M=function(){var e;null===(e=t.__classPrivateFieldGet(this,_,"f"))||void 0===e||e.remove(),t.__classPrivateFieldSet(this,_,null,"f")},O=function(e){return t.__awaiter(this,arguments,void 0,(function*({isDebug:e}){e?(t.__classPrivateFieldSet(this,_,document.createElement("descope-debugger"),"f"),Object.assign(t.__classPrivateFieldGet(this,_,"f").style,{position:"fixed",top:"0",right:"0",height:"100vh",width:"100vw",pointerEvents:"none",zIndex:99999}),yield Promise.resolve().then((function(){return z(require("../debugger-wc.js"))})),document.body.appendChild(t.__classPrivateFieldGet(this,_,"f"))):t.__classPrivateFieldGet(this,u,"m",M).call(this)}))},q=function(e,i){var s;e&&this.debug&&(null===(s=t.__classPrivateFieldGet(this,_,"f"))||void 0===s||s.updateData({title:e,description:i}))},J.sdkConfigOverrides={baseHeaders:{"x-descope-sdk-name":"web-component","x-descope-sdk-version":"4.4.4"}},module.exports=J;
|
|
2
2
|
//# sourceMappingURL=BaseDescopeWc.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var e,t,i,s,r,o,n,a,l,d,c,u,p,h,g,v,m,_,f,b,S,w,E,I,P,R,O,C,F,T,y,A,k,W,x,N,U,L,G,j,D,M,q,V,$,B=require("tslib"),K=require("@descope/sdk-helpers"),H=require("@descope/web-js-sdk"),X=require("../constants/index.js"),J=require("../helpers/helpers.js"),z=require("../helpers/state.js"),Q=require("../helpers/templates.js"),Y=require("../helpers/webauthn.js"),Z=require("../helpers/abTestingKey.js"),ee=require("../helpers/conditions.js"),te=require("../helpers/lastAuth.js"),ie=require("./BaseDescopeWc.js"),se=require("../constants/general.js");const re="__descope_webauthn_timed_out__";class oe extends ie{static set sdkConfigOverrides(e){ie.sdkConfigOverrides=e}static get sdkConfigOverrides(){return ie.sdkConfigOverrides}constructor(){const a=new z({deferredRedirect:!1,deferredPolling:!1});super(a.update.bind(a)),e.add(this),this.stepState=new z({}),t.set(this,void 0),i.set(this,null),s.set(this,null),r.set(this,{visibilitychange:B.__classPrivateFieldGet(this,e,"m",o).bind(this)}),this.bridgeVersion=oe.bridgeVersion,n.set(this,void 0),this.nativeCallbacks={},g.set(this,!1),this.handleRedirect=e=>{window.location.assign(e)},_.set(this,(t=>{const i=()=>{this.contentRootElement.classList.toggle("hidden",t),this.slotElement.classList.toggle("hidden",!t),t&&(this.contentRootElement.innerHTML="")};t&&this.contentRootElement.hasChildNodes()?B.__classPrivateFieldGet(this,e,"m",f).call(this,i):i()})),b.set(this,((e,i,s,r,o=!1)=>{const n=[se.FLOW_TIMED_OUT_ERROR_CODE,se.POLLING_STATUS_NOT_FOUND_ERROR_CODE,se.NONCE_VALIDATION_ERROR_CODE];if(this.flowState.current.action===X.RESPONSE_ACTIONS.poll){if(B.__classPrivateFieldGet(this,w,"f").call(this)&&document.hidden)return this.logger.debug("polling - Deferring polling until in foreground"),void this.flowState.update({deferredPolling:!0});this.logger.debug("polling - Scheduling polling request");const a=Date.now(),l=o?500:2e3;B.__classPrivateFieldSet(this,t,setTimeout((()=>B.__awaiter(this,void 0,void 0,(function*(){var t,d;this.logger.debug("polling - Calling next");const c=this.sdk.flow.next(e,i,X.CUSTOM_INTERACTIONS.polling,s,r,{}),u=document.hidden&&!o&&Date.now()-a>l+500;let p;u&&this.logger.debug("polling - The polling seems to be throttled");try{const e=u?1e3:6e3;p=yield J.timeoutPromise(e,c)}catch(t){return this.logger.warn(`polling - The ${u?"throttled fetch":"fetch"} call timed out or was aborted`),void B.__classPrivateFieldGet(this,b,"f").call(this,e,i,s,r,u)}if((null===(t=null==p?void 0:p.error)||void 0===t?void 0:t.errorCode)===se.FETCH_EXCEPTION_ERROR_CODE)return this.logger.debug("polling - Got a generic error due to exception in fetch call"),void B.__classPrivateFieldGet(this,b,"f").call(this,e,i,s,r);this.logger.debug("polling - Got a response"),(null==p?void 0:p.error)&&this.logger.debug("polling - Response has an error",JSON.stringify(p.error,null,4)),(null===(d=null==p?void 0:p.error)||void 0===d?void 0:d.errorCode)&&n.includes(p.error.errorCode)?this.logger.debug("polling - Stopping polling due to error"):B.__classPrivateFieldGet(this,b,"f").call(this,e,i,s,r),B.__classPrivateFieldGet(this,E,"f").call(this,p)}))),l),"f")}})),S.set(this,(()=>{clearTimeout(B.__classPrivateFieldGet(this,t,"f")),B.__classPrivateFieldSet(this,t,null,"f")})),w.set(this,(()=>!!window.descopeBridge||/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent))),E.set(this,(t=>{var i,r,o,n,a,l,d,c,u,p,g,v,m;if(!(null==t?void 0:t.ok)){const s=null===(i=null==t?void 0:t.response)||void 0===i?void 0:i.url,d=`${null===(r=null==t?void 0:t.response)||void 0===r?void 0:r.status} - ${null===(o=null==t?void 0:t.response)||void 0===o?void 0:o.statusText}`;B.__classPrivateFieldGet(this,e,"m",V).call(this,"error",(null==t?void 0:t.error)||{errorCode:se.FETCH_ERROR_RESPONSE_ERROR_CODE,errorDescription:d,errorMessage:s}),this.loggerWrapper.error((null===(n=null==t?void 0:t.error)||void 0===n?void 0:n.errorDescription)||s,(null===(a=null==t?void 0:t.error)||void 0===a?void 0:a.errorMessage)||d);const c=null===(l=null==t?void 0:t.error)||void 0===l?void 0:l.errorCode;return void(c!==se.FLOW_REQUESTED_IS_IN_OLD_VERSION_ERROR_CODE&&c!==se.FLOW_TIMED_OUT_ERROR_CODE&&c!==se.NONCE_VALIDATION_ERROR_CODE||!this.isRestartOnError||B.__classPrivateFieldGet(this,e,"m",h).call(this))}null===(c=null===(d=t.data)||void 0===d?void 0:d.runnerLogs)||void 0===c||c.forEach((e=>{const{level:t,title:i,log:s}=e;t&&this.loggerWrapper[t]?this.loggerWrapper[t](i,s):this.loggerWrapper.info(i,s)}));const _=null===(g=null===(p=null===(u=t.data)||void 0===u?void 0:u.screen)||void 0===p?void 0:p.state)||void 0===g?void 0:g.errorText;(null===(v=t.data)||void 0===v?void 0:v.error)?this.loggerWrapper.error(`[${t.data.error.code}]: ${t.data.error.description}`,`${_?`${_} - `:""}${t.data.error.message}`):_&&this.loggerWrapper.error(_);const{status:f,authInfo:b,lastAuth:w,action:E,openInNewTabUrl:I}=t.data;if(E!==X.RESPONSE_ACTIONS.poll&&B.__classPrivateFieldGet(this,S,"f").call(this),"completed"===f){this.storeLastAuthenticatedUser&&te.setLastAuth(Object.assign(Object.assign({},w),{lastUsedPerScreen:te.getInFlightLastUsedPerScreen()})),te.clearInFlightLastAuth(this.loggerWrapper);const i=Object.assign({},b);return t.data.output&&Object.keys(t.data.output).length>0&&(i.flowOutput=t.data.output),this.setValidationTrackingExecution(t.data.executionId),void B.__classPrivateFieldGet(this,e,"m",V).call(this,"success",i)}this.storeLastAuthenticatedUser&&te.setLastAuth(w,!0),I&&window.open(I,"_blank");const{executionId:P,stepId:R,stepName:O,screen:C,redirect:F,webauthn:T,error:y,samlIdpResponse:A,wsFedIdpResponse:k,nativeResponse:W}=t.data,x=Date.now();E!==X.RESPONSE_ACTIONS.poll?(this.loggerWrapper.info(`Step "${O||`#${R}`}" is ${f}`,"",{screen:C,status:f,stepId:R,stepName:O,action:E,error:y}),(null===(m=C.state)||void 0===m?void 0:m.clientScripts)&&B.__classPrivateFieldSet(this,s,this.loadSdkScripts(C.state.clientScripts),"f"),this.flowState.update({stepId:R,stepName:O,executionId:P,action:E,redirectTo:null==F?void 0:F.url,redirectIsPopup:null==F?void 0:F.isPopup,screenId:null==C?void 0:C.id,screenState:null==C?void 0:C.state,webauthnTransactionId:null==T?void 0:T.transactionId,webauthnOptions:null==T?void 0:T.options,samlIdpResponseUrl:null==A?void 0:A.url,samlIdpResponseSamlResponse:null==A?void 0:A.samlResponse,samlIdpResponseRelayState:null==A?void 0:A.relayState,wsFedIdpResponseUrl:null==k?void 0:k.url,wsFedIdpResponseWresult:null==k?void 0:k.wresult,wsFedIdpResponseWctx:null==k?void 0:k.wctx,nativeResponseType:null==W?void 0:W.type,nativePayload:null==W?void 0:W.payload,reqTimestamp:x})):this.flowState.update({action:E,reqTimestamp:x})})),I.set(this,J.withMemCache((()=>B.__awaiter(this,void 0,void 0,(function*(){var e;try{const t=yield this.sdk.webauthn.signIn.start("",window.location.origin);return t.ok||this.loggerWrapper.warn("Webauthn start failed",null===(e=null==t?void 0:t.error)||void 0===e?void 0:e.errorMessage),t.data}catch(e){this.loggerWrapper.warn("Webauthn start failed",e.message)}}))))),C.set(this,void 0),F.set(this,void 0),W.set(this,null),L.set(this,J.leadingDebounce(((t,i,s)=>B.__awaiter(this,void 0,void 0,(function*(){var r,o;if("true"===t.getAttribute("formnovalidate")||B.__classPrivateFieldGet(this,e,"m",A).call(this)){const n=null==t?void 0:t.getAttribute("id");B.__classPrivateFieldGet(this,e,"m",D).call(this,t,n,s),B.__classPrivateFieldGet(this,e,"m",x).call(this,t);const a=yield B.__classPrivateFieldGet(this,e,"m",k).call(this),l=J.getElementDescopeAttributes(t);this.nextRequestStatus.update({isLoading:!0});const d=Object.assign(Object.assign(Object.assign({},l),a),{origin:(null===(r=this.nativeOptions)||void 0===r?void 0:r.origin)||window.location.origin}),c=yield i(n,d);this.nextRequestStatus.update({isLoading:!1}),this.captureLastSubmittedLoginId(a,null===(o=null==c?void 0:c.data)||void 0===o?void 0:o.executionId),this.storeCredentials(a)}}))))),this.flowState=a,this.setValidationTrackingSender(((e,t)=>B.__awaiter(this,[e,t],void 0,(function*({executionId:e,events:t},{keepalive:i}){const s=yield this.sdk.flow.event(e,t,i);return{ok:s.ok,retryable:s.code>=500||429===s.code}}))))}nativeResume(e,t){var i,s,r,o,n,a;const l=JSON.parse(t);if("oauthWeb"===e||"sso"===e){let e,{exchangeCode:t}=l;if(!t){const r=new URL(l.url);t=null===(i=r.searchParams)||void 0===i?void 0:i.get(X.URL_CODE_PARAM_NAME),e=(null===(s=r.searchParams)||void 0===s?void 0:s.get(X.URL_ERR_PARAM_NAME))||void 0}null===(o=(r=this.nativeCallbacks).complete)||void 0===o||o.call(r,{exchangeCode:t,exchangeError:e,idpInitiated:!0})}else if("magicLink"===e){const e=new URL(l.url),t=e.searchParams.get(X.URL_TOKEN_PARAM_NAME),i=e.searchParams.get(X.URL_RUN_IDS_PARAM_NAME).split("_").pop();B.__classPrivateFieldGet(this,S,"f").call(this),this.flowState.update({token:t,stepId:i,action:void 0})}else if("beforeScreen"===e){const{screenResolve:e}=this.nativeCallbacks;this.nativeCallbacks.screenResolve=null;const{override:t}=l;t||(this.nativeCallbacks.screenNext=null),null==e||e(t)}else if("resumeScreen"===e){const{interactionId:e,form:t}=l,{screenNext:i}=this.nativeCallbacks;this.nativeCallbacks.screenNext=null,null==i||i(e,t)}else null===(a=(n=this.nativeCallbacks).complete)||void 0===a||a.call(n,l)}loadSdkScriptsModules(){const e=this.shadowRoot.querySelectorAll("div[data-script-id]");return Array.from(e).map((e=>e.moduleRes)).filter((e=>!!e))}loadSdkScripts(e){if(!(null==e?void 0:e.length))return null;const t=(e,t)=>i=>{this.dispatchEvent(new CustomEvent("components-context",{detail:{[J.getScriptResultPath(e.id,e.resultKey)]:i},bubbles:!0,composed:!0})),t(e.id)};this.loggerWrapper.debug(`Preparing to load scripts: ${e.map((e=>e.id)).join(", ")}`);const i=Promise.all(null==e?void 0:e.map((e=>B.__awaiter(this,void 0,void 0,(function*(){var i,s,r;const o=this.shadowRoot.querySelector(`[data-script-id="${e.id}"]`);if(o){this.loggerWrapper.debug("Script already loaded",e.id);const{moduleRes:t}=o;return null===(i=null==t?void 0:t.start)||void 0===i||i.call(t),t}(null===(s=globalThis.descope)||void 0===s?void 0:s[e.id])||(yield this.injectNpmLib("@descope/flow-scripts","1.0.19",`dist/${e.id}.js`));const n=null===(r=globalThis.descope)||void 0===r?void 0:r[e.id];return new Promise(((i,s)=>{try{const s=n(e.initArgs,{baseUrl:this.baseUrl,ref:this},t(e,i),this.loggerWrapper);if(s){const t=document.createElement("div");t.setAttribute("data-script-id",e.id),t.moduleRes=s,this.shadowRoot.appendChild(t);const r=this.nextRequestStatus.subscribe((()=>{var i;this.loggerWrapper.debug("Stopping script",e.id),(null===(i=s.stop)||void 0===i?void 0:i.call(s))&&(this.nextRequestStatus.unsubscribe(r),this.loggerWrapper.debug("Removing script",e.id),this.shadowRoot.removeChild(t))}));"function"==typeof s.present&&i(e.id)}}catch(e){s(e)}}))}))))),s=new Promise((e=>{setTimeout((()=>{this.loggerWrapper.warn("SDK scripts loading timeout"),e(!0)}),X.SDK_SCRIPTS_LOAD_TIMEOUT)}));return Promise.race([i,s])}get isDismissScreenErrorOnInput(){return"true"===this.getAttribute("dismiss-screen-error-on-input")}init(){var e,t;if(!window.descopeBridge)return this._init();this.lazyInit=this._init,B.__classPrivateFieldSet(this,n,null===(t=null===(e=null===window||void 0===window?void 0:window.descopeBridge)||void 0===e?void 0:e.registerFlow)||void 0===t?void 0:t.call(e,this),"f")}_init(){const t=Object.create(null,{init:{get:()=>super.init}});return B.__awaiter(this,void 0,void 0,(function*(){var i,s;this.shadowRoot.isConnected&&(null===(i=this.flowState)||void 0===i||i.subscribe(this.onFlowChange.bind(this)),B.__classPrivateFieldGet(this,e,"m",u).call(this),window.addEventListener("visibilitychange",B.__classPrivateFieldGet(this,r,"f").visibilitychange)),yield null===(s=t.init)||void 0===s?void 0:s.call(this)}))}disconnectedCallback(){var e,t,s;super.disconnectedCallback(),this.teardownValidationTracking(),B.__classPrivateFieldGet(this,n,"f")&&(null===(t=null===(e=window.descopeBridge)||void 0===e?void 0:e.unregisterFlow)||void 0===t||t.call(e,B.__classPrivateFieldGet(this,n,"f")),B.__classPrivateFieldSet(this,n,void 0,"f")),this.flowState.unsubscribeAll(),this.stepState.unsubscribeAll(),B.__classPrivateFieldGet(this,S,"f").call(this),null===(s=B.__classPrivateFieldGet(this,i,"f"))||void 0===s||s.abort(),B.__classPrivateFieldSet(this,i,null,"f"),window.removeEventListener("visibilitychange",B.__classPrivateFieldGet(this,r,"f").visibilitychange)}getHtmlFilenameWithLocale(e,t){return B.__awaiter(this,void 0,void 0,(function*(){let i;const s=K.getUserLocale(e),r=yield this.getTargetLocales();return r.includes(s.locale)?i=`${t}-${s.locale}.html`:r.includes(s.fallback)&&(i=`${t}-${s.fallback}.html`),i}))}getPageContent(e,t){return B.__awaiter(this,void 0,void 0,(function*(){if(t)try{const{body:e}=yield this.fetchStaticResource(t,"text");return e}catch(i){this.loggerWrapper.error(`Failed to fetch flow page from ${t}. Fallback to url ${e}`,i)}try{const{body:t}=yield this.fetchStaticResource(e,"text");return t}catch(e){this.loggerWrapper.error("Failed to fetch flow page",e.message)}return null}))}onFlowChange(t,r,o){return B.__awaiter(this,void 0,void 0,(function*(){var n,a;const{projectId:l,flowId:c,tenant:u,stepId:p,executionId:h,action:g,screenId:_,screenState:f,redirectTo:S,redirectIsPopup:w,redirectUrl:I,token:P,code:R,isPopup:O,exchangeError:y,webauthnTransactionId:A,webauthnOptions:k,redirectAuthCodeChallenge:W,redirectAuthCallbackUrl:x,redirectAuthBackupCallbackUri:N,redirectAuthInitiator:U,locale:L,samlIdpResponseUrl:j,samlIdpResponseSamlResponse:D,samlIdpResponseRelayState:M,wsFedIdpResponseUrl:q,wsFedIdpResponseWresult:z,wsFedIdpResponseWctx:Q,nativeResponseType:Y,nativePayload:ie,reqTimestamp:se}=t,re=B.__rest(t,["projectId","flowId","tenant","stepId","executionId","action","screenId","screenState","redirectTo","redirectIsPopup","redirectUrl","token","code","isPopup","exchangeError","webauthnTransactionId","webauthnOptions","redirectAuthCodeChallenge","redirectAuthCallbackUrl","redirectAuthBackupCallbackUri","redirectAuthInitiator","locale","samlIdpResponseUrl","samlIdpResponseSamlResponse","samlIdpResponseRelayState","wsFedIdpResponseUrl","wsFedIdpResponseWresult","wsFedIdpResponseWctx","nativeResponseType","nativePayload","reqTimestamp"]);let oe,ne,ae;const le=Z.getABTestingKey(),{outboundAppId:de,outboundAppScopes:ce}=this,ue=this.sdk.getLastUserLoginId();o("flowId")&&this.setValidationTrackingEnabled(!1);const pe=yield this.getFlowConfig();B.__classPrivateFieldGet(this,e,"m",T).call(this,pe,h,o);const he=yield this.getProjectConfig(),ge=Object.entries(he.flows||{}).reduce(((e,[t,i])=>(e[t]=i.version,e)),{}),ve=x&&W?{callbackUrl:x,codeChallenge:W,backupCallbackUri:N}:void 0,me=this.nativeOptions?{platform:this.nativeOptions.platform,bridgeVersion:this.nativeOptions.bridgeVersion,oauthProvider:this.nativeOptions.oauthProvider,oauthRedirect:this.nativeOptions.oauthRedirect,magicLinkRedirect:this.nativeOptions.magicLinkRedirect,ssoRedirect:this.nativeOptions.ssoRedirect,externalAuthRedirect:this.nativeOptions.externalAuthRedirect}:void 0;let _e={};if(!h){te.clearInFlightLastAuth(this.loggerWrapper);const e=[...pe.clientScripts||[],...pe.sdkScripts||[]];if(pe.conditions){let t=[];({startScreenId:oe,conditionInteractionId:ae,startScreenName:ne,clientScripts:t,componentsConfig:_e}=ee.calculateConditions({loginId:ue,code:R,token:P,abTestingKey:le,lastAuth:te.getLastAuth(ue,this.loggerWrapper)},pe.conditions)),e.push(...t||[])}else pe.condition?({startScreenId:oe,startScreenName:ne,conditionInteractionId:ae}=ee.calculateCondition(pe.condition,{loginId:ue,code:R,token:P,abTestingKey:le,lastAuth:te.getLastAuth(ue,this.loggerWrapper)})):(ne=pe.startScreenName,oe=pe.startScreenId);if(B.__classPrivateFieldSet(this,C,oe,"f"),B.__classPrivateFieldSet(this,F,ne,"f"),B.__classPrivateFieldSet(this,s,this.loadSdkScripts(e),"f"),pe.fingerprintEnabled&&pe.fingerprintKey?yield H.ensureFingerprintIds(pe.fingerprintKey,this.baseUrl):H.clearFingerprintData(),!J.showFirstScreenOnExecutionInit(oe,re)){const e=yield this.sdk.flow.start(c,Object.assign(Object.assign(Object.assign(Object.assign({tenant:u,redirectAuth:ve},re),{client:this.client}),I&&{redirectUrl:I}),{lastAuth:te.getLastAuth(ue,this.loggerWrapper),abTestingKey:le,locale:K.getUserLocale(L).locale,nativeOptions:me,outboundAppId:de,outboundAppScopes:ce}),ae,"",he.componentsVersion,ge,Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({},this.formConfigValues),R?{exchangeCode:R,idpInitiated:!0}:{}),re.descopeIdpInitiated&&{idpInitiated:!0}),P?{token:P}:{}),re.oidcLoginHint?{externalId:re.oidcLoginHint}:{}));return B.__classPrivateFieldGet(this,E,"f").call(this,e),void("completed"!==(null===(n=null==e?void 0:e.data)||void 0===n?void 0:n.status)&&this.flowState.update({code:void 0,token:void 0}))}}if(this.loggerWrapper.debug("Before popup postmessage send",JSON.stringify({isPopup:O,code:R,exchangeError:y,isCodeChanged:o("code"),isExchangeErrorChanged:o("exchangeError")})),O&&(o("code")&&R||o("exchangeError")&&y))return void B.__classPrivateFieldGet(this,e,"m",$).call(this,h,R,y);if(h&&(o("token")&&P||o("code")&&R||o("exchangeError")&&y)){const e=yield this.sdk.flow.next(h,p,X.CUSTOM_INTERACTIONS.submit,pe.version,he.componentsVersion,{token:P,exchangeCode:R,exchangeError:y});return B.__classPrivateFieldGet(this,E,"f").call(this,e),void this.flowState.update({token:void 0,code:void 0,exchangeError:void 0})}if(g===X.RESPONSE_ACTIONS.loadForm&&j&&["samlIdpResponseUrl","samlIdpResponseSamlResponse","samlIdpResponseRelayState"].some((e=>o(e)))){if(!D)return void this.loggerWrapper.error("Did not get saml idp params data to load");J.injectSamlIdpForm(j,D,M||"",J.submitForm)}if(g===X.RESPONSE_ACTIONS.loadForm&&q&&["wsFedIdpResponseUrl","wsFedIdpResponseWresult","wsFedIdpResponseWctx"].some((e=>o(e)))){if(!z)return void this.loggerWrapper.error("Did not get wsfed idp params data to load");J.injectWsFedIdpForm(q,z,Q||"",J.submitForm)}if(g===X.RESPONSE_ACTIONS.redirect&&(o("redirectTo")||o("deferredRedirect"))){if(!S)return void this.loggerWrapper.error("Did not get redirect url");if("no-op"===S)return;if("android"===U&&document.hidden)return void this.flowState.update({deferredRedirect:!0});if(this.loggerWrapper.debug(`Redirect is popup ${w}`),w){this.loggerWrapper.debug("Opening redirect in popup");const t=J.openCenteredPopup(S,"?",598,700),i=this.shouldUsePopupPostMessage();i&&(t.name=`descope-wc|${window.location.origin}`),this.loggerWrapper.debug("Popup communication method: "+(i?"postMessage":"BroadcastChannel"));let s=!1;const r=e=>{this.loggerWrapper.debug("Received popup message",JSON.stringify(e.data));const t=i?this.popupOrigin:window.location.origin;if(e.origin!==t)return void this.loggerWrapper.debug(`Ignoring message from unexpected origin. received: "${e.origin}", expected: "${t}"`);const{action:r,data:o}=e.data||{};"code"===r&&(s=!0,this.flowState.update({code:o.code,exchangeError:o.exchangeError}))};let o;this.loggerWrapper.debug("Starting popup closed detection");const n=setInterval((()=>{t.closed&&(this.loggerWrapper.debug("Popup closed, dispatching popupclosed event"),clearInterval(n),B.__classPrivateFieldGet(this,e,"m",V).call(this,"popupclosed",{abandoned:!s}),this.loggerWrapper.debug("Cleaning up popup listeners"),null==o||o())}),1e3);if(i)window.addEventListener("message",r),o=()=>{this.loggerWrapper.debug("Cleaning up popup postMessage listener"),window.removeEventListener("message",r)};else{this.loggerWrapper.debug("Creating broadcast channel");const e=new BroadcastChannel(h);e.onmessage=r,o=()=>{this.loggerWrapper.debug("Closing channel"),e.close()}}}else this.handleRedirect(S),this.flowState.update({redirectTo:"no-op"}),B.__classPrivateFieldGet(this,e,"m",V).call(this,"popupclosed",{});return}if(g===X.RESPONSE_ACTIONS.webauthnCreate||g===X.RESPONSE_ACTIONS.webauthnGet){if(!A||!k)return void this.loggerWrapper.error("Did not get webauthn transaction id or options");null===(a=B.__classPrivateFieldGet(this,i,"f"))||void 0===a||a.abort(),B.__classPrivateFieldSet(this,i,null,"f");const t=yield B.__classPrivateFieldGet(this,e,"m",m).call(this,g,k),s=yield this.sdk.flow.next(h,p,X.CUSTOM_INTERACTIONS.submit,pe.version,he.componentsVersion,Object.assign({transactionId:A},t));B.__classPrivateFieldGet(this,E,"f").call(this,s)}if(g===X.RESPONSE_ACTIONS.nativeBridge)return this.nativeCallbacks.complete=e=>B.__awaiter(this,void 0,void 0,(function*(){const t=yield this.sdk.flow.next(h,p,X.CUSTOM_INTERACTIONS.submit,pe.version,he.componentsVersion,e);B.__classPrivateFieldGet(this,E,"f").call(this,t)})),B.__classPrivateFieldGet(this,e,"m",d).call(this,Y,ie),void setTimeout((()=>{this.dispatchEvent(new Event("popupclosed"))}),500);if((o("action")||o("deferredPolling"))&&B.__classPrivateFieldGet(this,b,"f").call(this,h,p,pe.version,he.componentsVersion),!_&&!oe)return void this.loggerWrapper.warn("No screen was found to show");const fe=oe||_,be=yield this.getHtmlFilenameWithLocale(L,fe),{oidcLoginHint:Se,oidcPrompt:we,oidcErrorRedirectUri:Ee,oidcResource:Ie,samlIdpUsername:Pe}=re,Re={direction:J.getAnimationDirection(p,r.stepId),screenState:Object.assign(Object.assign({},f),{form:Object.assign(Object.assign({},this.formConfigValues),null==f?void 0:f.form),lastAuth:{loginId:ue,name:this.sdk.getLastUserDisplayName()||ue},componentsConfig:Object.assign(Object.assign(Object.assign({},pe.componentsConfig),_e),null==f?void 0:f.componentsConfig)}),htmlFilename:`${fe}.html`,htmlLocaleFilename:be,screenId:fe,stepName:t.stepName||ne,samlIdpUsername:Pe,oidcLoginHint:Se,oidcPrompt:we,oidcErrorRedirectUri:Ee,oidcResource:Ie,action:g,locale:K.getUserLocale(L).locale},Oe=te.getLastAuth(ue,this.loggerWrapper);J.showFirstScreenOnExecutionInit(oe,re)?Re.next=(t,i)=>B.__awaiter(this,void 0,void 0,(function*(){const s=(null==pe?void 0:pe.clientScripts)||[];yield B.__classPrivateFieldGet(this,e,"m",G).call(this,s);const r=yield this.sdk.flow.start(c,Object.assign(Object.assign(Object.assign(Object.assign({tenant:u,redirectAuth:ve},re),{lastAuth:Oe,preview:this.preview,abTestingKey:le,client:this.client}),I&&{redirectUrl:I}),{locale:K.getUserLocale(L).locale,nativeOptions:me,outboundAppId:de,outboundAppScopes:ce}),ae,t,he.componentsVersion,ge,Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({},this.formConfigValues),this.getComponentsContext()),J.transformScreenInputs(i)),R&&{exchangeCode:R,idpInitiated:!0}),re.descopeIdpInitiated&&{idpInitiated:!0}),P&&{token:P}),Re.next.isCustomScreen);return B.__classPrivateFieldGet(this,E,"f").call(this,r),r})):(o("projectId")||o("baseUrl")||o("executionId")||o("stepId"))&&(Re.next=(t,i)=>B.__awaiter(this,void 0,void 0,(function*(){const s=(null==f?void 0:f.clientScripts)||[];yield B.__classPrivateFieldGet(this,e,"m",G).call(this,s);const r=yield this.sdk.flow.next(h,p,t,pe.version,he.componentsVersion,Object.assign(Object.assign({},this.getComponentsContext()),J.transformScreenInputs(i)),Re.next.isCustomScreen);return B.__classPrivateFieldGet(this,E,"f").call(this,r),r}))),this.loggerWrapper.debug("Got a screen with id",Re.screenId),yield B.__classPrivateFieldGet(this,e,"m",v).call(this,Re),this.stepState.update(Re)}))}onStepChange(t,i){return B.__awaiter(this,void 0,void 0,(function*(){var s,r,o;const{htmlFilename:n,htmlLocaleFilename:a,direction:l,next:d,screenState:c,screenId:u}=t;this.loggerWrapper.debug("Rendering a flow screen"),this.updateScreenUser(null==c?void 0:c.user);const p=document.createElement("template");p.innerHTML=yield this.getPageContent(n,a);const h=p.content.cloneNode(!0),g=this.loadDescopeUiComponents(p);this.sdk.webauthn.helpers.isSupported()?yield B.__classPrivateFieldGet(this,e,"m",R).call(this,h,d):Q.disableWebauthnButtons(h),!t.samlIdpUsername||(null===(s=c.form)||void 0===s?void 0:s.loginId)||(null===(r=c.form)||void 0===r?void 0:r.email)||(c.form||(c.form={}),c.form.loginId=t.samlIdpUsername,c.form.email=t.samlIdpUsername),Q.updateTemplateFromScreenState(h,c,this.formConfig,this.loggerWrapper),this.applyComponentsState(h,null==c?void 0:c.componentsState);const{geo:v}=null!==(o=yield this.getExecutionContext())&&void 0!==o?o:{};Q.setComponentsAutoDetectByGeo(h,v),Q.setComponentsAutoDetectByLocale(h,t.locale);const m=()=>B.__awaiter(this,void 0,void 0,(function*(){var s,r;yield g;const o=this.contentRootElement;Q.setTOTPVariable(o,null===(s=null==c?void 0:c.totp)||void 0===s?void 0:s.image),Q.setNOTPVariable(o,null===(r=null==c?void 0:c.notp)||void 0===r?void 0:r.image),Q.setCssVars(o,h,c.cssVars,this.loggerWrapper),o.replaceChildren(h);const n=!i.htmlFilename;setTimeout((()=>{B.__classPrivateFieldGet(this,e,"m",N).call(this),this.updateUsernameAnchor(),this.validateOnBlur&&J.handleReportValidityOnBlur(o,(t=>this.trackValidationErrors([t],B.__classPrivateFieldGet(this,e,"a",y)))),Q.updateScreenFromScreenState(o,c),this.initRealtimeConditions(o,c),B.__classPrivateFieldGet(this,e,"m",O).call(this,{isFirstScreen:n,isCustomScreen:!1,stepName:t.stepName}),J.handleAutoFocus(o,this.autoFocus,n),B.__classPrivateFieldGet(this,e,"m",M).call(this,u)})),B.__classPrivateFieldGet(this,e,"m",q).call(this,d,u);o.querySelector(`[${X.ELEMENT_TYPE_ATTRIBUTE}="polling"]`)&&d(X.CUSTOM_INTERACTIONS.polling,{})}));l?B.__classPrivateFieldGet(this,e,"m",f).call(this,m):m()}))}getInputs(){return Array.from(this.shadowRoot.querySelectorAll(`*:not(slot)[name]:not([${X.DESCOPE_ATTRIBUTE_EXCLUDE_FIELD}])`))}shouldUsePopupPostMessage(){if(!this.popupOrigin)return!1;try{new URL(this.popupOrigin)}catch(e){return!1}return!0}}t=new WeakMap,i=new WeakMap,s=new WeakMap,r=new WeakMap,n=new WeakMap,g=new WeakMap,_=new WeakMap,b=new WeakMap,S=new WeakMap,w=new WeakMap,E=new WeakMap,I=new WeakMap,C=new WeakMap,F=new WeakMap,W=new WeakMap,L=new WeakMap,e=new WeakSet,o=function(){document.hidden||setTimeout((()=>{this.flowState.update({deferredRedirect:!1,deferredPolling:!1})}),300)},a=function(t,i,s){return B.__awaiter(this,void 0,void 0,(function*(){var r;return(null===(r=this.nativeOptions)||void 0===r?void 0:r.bridgeVersion)>=2&&new Promise((r=>{this.nativeCallbacks.screenNext=s,this.nativeCallbacks.screenResolve=r,B.__classPrivateFieldGet(this,e,"m",d).call(this,"beforeScreen",{screen:t,context:i})}))}))},l=function(t){var i;(null===(i=this.nativeOptions)||void 0===i?void 0:i.bridgeVersion)>=2&&B.__classPrivateFieldGet(this,e,"m",d).call(this,"afterScreen",{screen:t})},d=function(t,i){B.__classPrivateFieldGet(this,e,"m",V).call(this,"bridge",{type:t,payload:i})},c=function({errorText:e,errorType:t}){const i=()=>{var i;let s=e;try{s=(null===(i=this.errorTransformer)||void 0===i?void 0:i.call(this,{text:e,type:t}))||e}catch(e){this.loggerWrapper.error("Error transforming error message",e.message)}Q.replaceElementMessage(this.contentRootElement,"error-message",s)};this.addEventListener("screen-updated",i,{once:!0}),i()},u=function(){var t,i,s,r;null===(t=this.stepState)||void 0===t||t.subscribe(this.onStepChange.bind(this),(e=>{var t=e.screenState,i=void 0===t?{}:t,s=B.__rest(i,["errorText","errorType"]),r=B.__rest(e,["screenState"]);return Object.assign(Object.assign({},r),{screenState:s})})),null===(i=this.stepState)||void 0===i||i.subscribe(B.__classPrivateFieldGet(this,e,"m",c).bind(this),(e=>{var t,i;return{errorText:null===(t=null==e?void 0:e.screenState)||void 0===t?void 0:t.errorText,errorType:null===(i=null==e?void 0:e.screenState)||void 0===i?void 0:i.errorType}}),{forceUpdate:!0}),null===(s=this.stepState)||void 0===s||s.subscribe(B.__classPrivateFieldGet(this,e,"m",p).bind(this),(e=>{var t,i;return{errorText:null===(t=null==e?void 0:e.screenState)||void 0===t?void 0:t.errorText,errorType:null===(i=null==e?void 0:e.screenState)||void 0===i?void 0:i.errorType}}),{forceUpdate:!0}),null===(r=this.flowState)||void 0===r||r.subscribe((({screenId:e,executionId:t})=>{var i;try{this.updateTelemetryContext({screenId:e,executionId:t})}catch(e){null===(i=this.logger)||void 0===i||i.error("Error updating telemetry screenId:",e)}}),(e=>({screenId:e.screenId,executionId:e.executionId})))},p=function({errorText:e,errorType:t}){(t||e)&&(this.contentRootElement.querySelectorAll('descope-passcode[data-auto-submit="true"]').forEach((e=>{e.shadowRoot.querySelectorAll("descope-text-field[data-id]").forEach((e=>{e.value=""}))})),J.handleAutoFocus(this.contentRootElement,this.autoFocus,!1))},h=function(){return B.__awaiter(this,void 0,void 0,(function*(){this.loggerWrapper.debug("Trying to restart the flow");const e=yield this.getComponentsVersion();this.reset();e===(yield this.getComponentsVersion())?(this.loggerWrapper.debug("Components version was not changed, restarting flow"),this.flowState.update({stepId:null,executionId:null})):this.loggerWrapper.error("Components version mismatch, please reload the page")}))},v=function(t){return B.__awaiter(this,void 0,void 0,(function*(){var i;const s=Object.assign(Object.assign({},this.stepState.current),t),{next:r,stepName:o}=s,n=B.__rest(s,["next","stepName"]),l=J.transformStepStateForCustomScreen(n);let d=yield B.__classPrivateFieldGet(this,e,"m",a).call(this,o,l,r);d||(d=Boolean(yield null===(i=this.onScreenUpdate)||void 0===i?void 0:i.call(this,o,l,r,this)));const c=!this.stepState.current.htmlFilename;if(B.__classPrivateFieldGet(this,_,"f").call(this,d),r&&(r.isCustomScreen=d),B.__classPrivateFieldGet(this,g,"f")!==d){const[t,i]=["flow","custom"].sort((()=>d?-1:1));this.loggerWrapper.debug(`Switching from ${i} screen to ${t} screen`),B.__classPrivateFieldSet(this,g,d,"f"),d?this.stepState.unsubscribeAll():B.__classPrivateFieldGet(this,e,"m",u).call(this)}d?(this.loggerWrapper.debug("Showing a custom screen"),B.__classPrivateFieldGet(this,e,"m",O).call(this,{isFirstScreen:c,isCustomScreen:d,stepName:t.stepName}),this.disableKeyPressHandler()):this.handleKeyPress(),this.stepState.forceUpdate=d}))},m=function(e,t){return B.__awaiter(this,void 0,void 0,(function*(){const i=new AbortController;try{const s=e===X.RESPONSE_ACTIONS.webauthnCreate?this.sdk.webauthn.helpers.create(t,i):this.sdk.webauthn.helpers.get(t,i),r=yield J.timeoutPromise(X.WEBAUTHN_TIMEOUT,s,re);return r!==re?{response:r}:(i.abort(),this.loggerWrapper.warn(`WebAuthn operation timed out after ${X.WEBAUTHN_TIMEOUT}ms`),{failure:"AbortError",failureReason:"aborted",failureMessage:"Passkey operation timed out"})}catch(e){return"InvalidStateError"===e.name?this.loggerWrapper.warn("WebAuthn operation failed",e.message):"NotAllowedError"!==e.name&&this.loggerWrapper.error(e.message),{failure:e.name,failureReason:e.reason,failureMessage:e.message}}}))},f=function(e){this.contentRootElement.addEventListener("transitionend",(()=>{this.loggerWrapper.debug("page switch transition end"),this.contentRootElement.classList.remove("fade-out"),e()}),{once:!0}),this.loggerWrapper.debug("page switch transition start"),this.contentRootElement.classList.add("fade-out")},P=function(e){const t=e.getAttribute("name");if(!["email"].includes(t)){const i=`user-${t}`;e.setAttribute("name",i),e.addEventListener("input",(()=>{e.setAttribute("name",e.value?t:i)}))}},R=function(t,s){return B.__awaiter(this,void 0,void 0,(function*(){var r;null===(r=B.__classPrivateFieldGet(this,i,"f"))||void 0===r||r.abort();const o=t.querySelector('*[autocomplete="webauthn"]');if(o&&(yield Y.isConditionalLoginSupported())){const{options:t,transactionId:r}=(yield B.__classPrivateFieldGet(this,I,"f").call(this))||{};t&&r&&(B.__classPrivateFieldGet(this,e,"m",P).call(this,o),B.__classPrivateFieldSet(this,i,new AbortController,"f"),this.sdk.webauthn.helpers.conditional(t,B.__classPrivateFieldGet(this,i,"f")).then((e=>B.__awaiter(this,void 0,void 0,(function*(){s(o.id,{transactionId:r,response:e})})))).catch((e=>{"AbortError"!==e.name&&this.loggerWrapper.error("Conditional login failed",e.message)})))}}))},O=function({isFirstScreen:t,isCustomScreen:i,stepName:s}){t&&B.__classPrivateFieldGet(this,e,"m",V).call(this,"ready",{}),i||B.__classPrivateFieldGet(this,e,"m",l).call(this,s),B.__classPrivateFieldGet(this,e,"m",V).call(this,"page-updated",{screenName:s}),B.__classPrivateFieldGet(this,e,"m",V).call(this,"screen-updated",{screenName:s})},T=function(e,t,i){this.setValidationTrackingEnabled(!!e.clientValidationTrackingEnabled),t&&i("executionId")&&this.setValidationTrackingExecution(t)},y=function(){var e,t,i,s,r,o,n;const a=null===(e=this.flowState)||void 0===e?void 0:e.current;return(null==a?void 0:a.executionId)?{executionId:a.executionId,screenId:a.screenId,screenName:(null===(n=null===(o=this.stepState)||void 0===o?void 0:o.current)||void 0===n?void 0:n.stepName)||a.stepName}:{executionId:void 0,screenId:null!==(t=B.__classPrivateFieldGet(this,C,"f"))&&void 0!==t?t:null==a?void 0:a.screenId,screenName:null!==(i=B.__classPrivateFieldGet(this,F,"f"))&&void 0!==i?i:(null===(r=null===(s=this.stepState)||void 0===s?void 0:s.current)||void 0===r?void 0:r.stepName)||(null==a?void 0:a.stepName)}},A=function(){let t=!0;const i=[];return Array.from(this.shadowRoot.querySelectorAll("*[name]")).reverse().forEach((e=>{var s,r;"slot"===e.localName||e.classList.contains("hidden")||(null===(s=e.reportValidity)||void 0===s||s.call(e),e.validity&&!e.validity.valid&&i.push(e),t&&(t=null===(r=e.checkValidity)||void 0===r?void 0:r.call(e)))})),i.length&&this.trackValidationErrors(i,B.__classPrivateFieldGet(this,e,"a",y)),t},k=function(){return B.__awaiter(this,void 0,void 0,(function*(){const e=this.getInputs();return(yield Promise.all(e.map((e=>B.__awaiter(this,void 0,void 0,(function*(){return{name:e.getAttribute("name"),value:e.value}})))))).reduce(((e,t)=>Object.assign(Object.assign({},e),{[t.name]:t.value})),{})}))},x=function(e){var t,i;const r=Array.from(this.contentRootElement.querySelectorAll(':not([disabled]), [disabled="false"]')).filter((t=>t!==e)),o=(null===(i=null===(t=this.flowState.current)||void 0===t?void 0:t.screenState)||void 0===i?void 0:i.clientScripts)||[],n=()=>{e.removeAttribute("loading"),r.forEach((e=>{e.removeAttribute("disabled")}))},a=e=>B.__awaiter(this,void 0,void 0,(function*(){var t;this.loggerWrapper.debug("Restoring components state"),this.removeEventListener("popupclosed",a);if(!0===(null===(t=null==e?void 0:e.detail)||void 0===t?void 0:t.abandoned)&&o.length)return B.__classPrivateFieldSet(this,s,(()=>B.__awaiter(this,void 0,void 0,(function*(){try{yield this.loadSdkScripts(o)}catch(e){this.loggerWrapper.warn("Failed to refresh client scripts on popup close",null==e?void 0:e.message)}})))(),"f"),void n();n();const i=yield this.getFlowConfig(),r=[...i.clientScripts||[],...i.sdkScripts||[]];this.loadSdkScripts(r)})),l=()=>{var e;window.removeEventListener("pageshow",B.__classPrivateFieldGet(this,W,"f")),B.__classPrivateFieldSet(this,W,(e=>{e.persisted&&(this.logger.debug("Page was loaded from cache, restoring components state"),a())}),"f"),window.addEventListener("pageshow",B.__classPrivateFieldGet(this,W,"f"),{once:!0});const t=null===(e=this.stepState)||void 0===e?void 0:e.subscribe(((e,i)=>{e===i&&a(),this.removeEventListener("popupclosed",a),this.stepState.unsubscribe(t)}),(e=>e.screenId),{forceUpdate:!0})},d=this.nextRequestStatus.subscribe((({isLoading:t})=>{t?(this.addEventListener("popupclosed",a,{once:!0}),e.setAttribute("loading","true"),r.forEach((e=>e.setAttribute("disabled","true")))):(this.nextRequestStatus.unsubscribe(d),"success"===this.flowStatus?(this.removeEventListener("popupclosed",a),n()):l())}))},N=function(){J.clearPreviousExternalInputs();this.contentRootElement.querySelectorAll('[external-input="true"]').forEach((t=>B.__classPrivateFieldGet(this,e,"m",U).call(this,t)))},U=function(e){if(!e)return;e.querySelectorAll("input").forEach((t=>{const i=t.getAttribute("slot"),s=`input-${e.id}-${i}`,r=document.createElement("slot");r.setAttribute("name",s),r.setAttribute("slot",i),e.appendChild(r),t.setAttribute("slot",s),this.appendChild(t)}))},G=function(e){return B.__awaiter(this,void 0,void 0,(function*(){if(B.__classPrivateFieldGet(this,s,"f")){this.loggerWrapper.debug("Waiting for sdk scripts to load");const e=Date.now();yield B.__classPrivateFieldGet(this,s,"f"),this.loggerWrapper.debug("Sdk scripts loaded for",(Date.now()-e).toString())}const t=this.loadSdkScriptsModules(),i=e.map((e=>e.id));for(const e of t)if(i.includes(e.id))try{if("function"==typeof e.present){(yield e.present())||this.loggerWrapper.debug(`Sdk script ${e.id} was cancelled`)}}catch(t){this.loggerWrapper.error(`Failed to present ${e.id} script module`,t.message)}const r=[];for(const e of t)"function"==typeof e.refresh&&r.push(e.refresh());if(r.length>0)try{yield J.timeoutPromise(X.SDK_SCRIPTS_LOAD_TIMEOUT,Promise.all(r),null)}catch(e){this.loggerWrapper.error("Failed to refresh script module",e.message)}}))},j=function(e,t){this.contentRootElement.querySelectorAll('descope-passcode[data-auto-submit="true"]').forEach((i=>{i.addEventListener("input",(()=>{var s;(null===(s=i.checkValidity)||void 0===s?void 0:s.call(i))&&B.__classPrivateFieldGet(this,L,"f").call(this,i,e,t)}))}))},D=function(e,t,i){t&&i&&"true"===e.getAttribute(X.DESCOPE_ATTRIBUTE_OPT_IN_LAST_USED)&&te.updateLastUsedPerScreen(i,t,this.loggerWrapper)},M=function(e){var t;const i=this.sdk.getLastUserLoginId(),s=null===(t=te.getLastAuth(i,this.loggerWrapper).lastUsedPerScreen)||void 0===t?void 0:t[e];if(!s)return;const r=this.contentRootElement.querySelector(X.DESCOPE_LAST_AUTH_BADGE_COMPONENT),o=this.contentRootElement.querySelector(`#${CSS.escape(s)}`);r&&o&&(o.replaceWith(r),r.appendChild(o))},q=function(t,i){this.contentRootElement.querySelectorAll(`descope-button:not([${X.DESCOPE_ATTRIBUTE_EXCLUDE_NEXT_BUTTON}]), [data-type="button"]:not([${X.DESCOPE_ATTRIBUTE_EXCLUDE_NEXT_BUTTON}]`).forEach((e=>{e.onclick=()=>{B.__classPrivateFieldGet(this,L,"f").call(this,e,t,i)}})),B.__classPrivateFieldGet(this,e,"m",j).call(this,t,i),this.isDismissScreenErrorOnInput&&this.contentRootElement.querySelectorAll(`*[name]:not([${X.DESCOPE_ATTRIBUTE_EXCLUDE_FIELD}])`).forEach((e=>{e.addEventListener("input",(()=>{this.stepState.update((e=>Object.assign(Object.assign({},e),{screenState:Object.assign(Object.assign({},e.screenState),{errorText:"",errorType:""})})))}))}))},V=function(e,t){this.dispatchEvent(new CustomEvent(e,{detail:t}))},$=function(e,t,i){var s;const[r,o]=(null===(s=window.name)||void 0===s?void 0:s.split("|"))||[],n={data:{code:t,exchangeError:i},action:"code"};if("descope-wc"===r&&o){this.loggerWrapper.debug("Using postMessage fallback to notify opener in origin",o);try{window.opener.postMessage(n,o)}catch(e){this.loggerWrapper.error("Failed to send postMessage fallback (likely COOP isolation)",null==e?void 0:e.message)}}else{this.loggerWrapper.debug("Creating popup channel",e);const t=new BroadcastChannel(e);t.postMessage(n),t.close()}try{window.close()}catch(e){}},oe.bridgeVersion=3,module.exports=oe;
|
|
1
|
+
"use strict";var e,t,i,s,r,o,n,a,l,d,c,u,p,h,g,v,m,_,f,b,S,w,E,I,P,R,O,C,F,T,y,A,k,W,x,N,U,L,G,j,D,M,q,V,$,B=require("tslib"),K=require("@descope/sdk-helpers"),H=require("@descope/web-js-sdk"),X=require("../constants/index.js"),J=require("../helpers/helpers.js"),z=require("../helpers/state.js"),Q=require("../helpers/templates.js"),Y=require("../helpers/webauthn.js"),Z=require("../helpers/abTestingKey.js"),ee=require("../helpers/conditions.js"),te=require("../helpers/lastAuth.js"),ie=require("./BaseDescopeWc.js"),se=require("../constants/general.js");const re="__descope_webauthn_timed_out__";class oe extends ie{static set sdkConfigOverrides(e){ie.sdkConfigOverrides=e}static get sdkConfigOverrides(){return ie.sdkConfigOverrides}constructor(){const a=new z({deferredRedirect:!1,deferredPolling:!1});super(a.update.bind(a)),e.add(this),this.stepState=new z({}),t.set(this,void 0),i.set(this,null),s.set(this,null),r.set(this,{visibilitychange:B.__classPrivateFieldGet(this,e,"m",o).bind(this)}),this.bridgeVersion=oe.bridgeVersion,n.set(this,void 0),this.nativeCallbacks={},g.set(this,!1),this.handleRedirect=e=>{window.location.assign(e)},_.set(this,(t=>{const i=()=>{this.contentRootElement.classList.toggle("hidden",t),this.slotElement.classList.toggle("hidden",!t),t&&(this.contentRootElement.innerHTML="")};t&&this.contentRootElement.hasChildNodes()?B.__classPrivateFieldGet(this,e,"m",f).call(this,i):i()})),b.set(this,((e,i,s,r,o=!1)=>{const n=[se.FLOW_TIMED_OUT_ERROR_CODE,se.POLLING_STATUS_NOT_FOUND_ERROR_CODE,se.NONCE_VALIDATION_ERROR_CODE];if(this.flowState.current.action===X.RESPONSE_ACTIONS.poll){if(B.__classPrivateFieldGet(this,w,"f").call(this)&&document.hidden)return this.logger.debug("polling - Deferring polling until in foreground"),void this.flowState.update({deferredPolling:!0});this.logger.debug("polling - Scheduling polling request");const a=Date.now(),l=o?500:2e3;B.__classPrivateFieldSet(this,t,setTimeout((()=>B.__awaiter(this,void 0,void 0,(function*(){var t,d;this.logger.debug("polling - Calling next");const c=this.sdk.flow.next(e,i,X.CUSTOM_INTERACTIONS.polling,s,r,{}),u=document.hidden&&!o&&Date.now()-a>l+500;let p;u&&this.logger.debug("polling - The polling seems to be throttled");try{const e=u?1e3:6e3;p=yield J.timeoutPromise(e,c)}catch(t){return this.logger.warn(`polling - The ${u?"throttled fetch":"fetch"} call timed out or was aborted`),void B.__classPrivateFieldGet(this,b,"f").call(this,e,i,s,r,u)}if((null===(t=null==p?void 0:p.error)||void 0===t?void 0:t.errorCode)===se.FETCH_EXCEPTION_ERROR_CODE)return this.logger.debug("polling - Got a generic error due to exception in fetch call"),void B.__classPrivateFieldGet(this,b,"f").call(this,e,i,s,r);this.logger.debug("polling - Got a response"),(null==p?void 0:p.error)&&this.logger.debug("polling - Response has an error",JSON.stringify(p.error,null,4)),(null===(d=null==p?void 0:p.error)||void 0===d?void 0:d.errorCode)&&n.includes(p.error.errorCode)?this.logger.debug("polling - Stopping polling due to error"):B.__classPrivateFieldGet(this,b,"f").call(this,e,i,s,r),B.__classPrivateFieldGet(this,E,"f").call(this,p)}))),l),"f")}})),S.set(this,(()=>{clearTimeout(B.__classPrivateFieldGet(this,t,"f")),B.__classPrivateFieldSet(this,t,null,"f")})),w.set(this,(()=>!!window.descopeBridge||/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent))),E.set(this,(t=>{var i,r,o,n,a,l,d,c,u,p,g,v,m;if(!(null==t?void 0:t.ok)){const s=null===(i=null==t?void 0:t.response)||void 0===i?void 0:i.url,d=`${null===(r=null==t?void 0:t.response)||void 0===r?void 0:r.status} - ${null===(o=null==t?void 0:t.response)||void 0===o?void 0:o.statusText}`;B.__classPrivateFieldGet(this,e,"m",V).call(this,"error",(null==t?void 0:t.error)||{errorCode:se.FETCH_ERROR_RESPONSE_ERROR_CODE,errorDescription:d,errorMessage:s}),this.loggerWrapper.error((null===(n=null==t?void 0:t.error)||void 0===n?void 0:n.errorDescription)||s,(null===(a=null==t?void 0:t.error)||void 0===a?void 0:a.errorMessage)||d);const c=null===(l=null==t?void 0:t.error)||void 0===l?void 0:l.errorCode;return void(c!==se.FLOW_REQUESTED_IS_IN_OLD_VERSION_ERROR_CODE&&c!==se.FLOW_TIMED_OUT_ERROR_CODE&&c!==se.NONCE_VALIDATION_ERROR_CODE||!this.isRestartOnError||B.__classPrivateFieldGet(this,e,"m",h).call(this))}null===(c=null===(d=t.data)||void 0===d?void 0:d.runnerLogs)||void 0===c||c.forEach((e=>{const{level:t,title:i,log:s}=e;t&&this.loggerWrapper[t]?this.loggerWrapper[t](i,s):this.loggerWrapper.info(i,s)}));const _=null===(g=null===(p=null===(u=t.data)||void 0===u?void 0:u.screen)||void 0===p?void 0:p.state)||void 0===g?void 0:g.errorText;(null===(v=t.data)||void 0===v?void 0:v.error)?this.loggerWrapper.error(`[${t.data.error.code}]: ${t.data.error.description}`,`${_?`${_} - `:""}${t.data.error.message}`):_&&this.loggerWrapper.error(_);const{status:f,authInfo:b,lastAuth:w,action:E,openInNewTabUrl:I}=t.data;if(E!==X.RESPONSE_ACTIONS.poll&&B.__classPrivateFieldGet(this,S,"f").call(this),"completed"===f){this.storeLastAuthenticatedUser&&te.setLastAuth(Object.assign(Object.assign({},w),{lastUsedPerScreen:te.getInFlightLastUsedPerScreen()})),te.clearInFlightLastAuth(this.loggerWrapper);const i=Object.assign({},b);return t.data.output&&Object.keys(t.data.output).length>0&&(i.flowOutput=t.data.output),this.setValidationTrackingExecution(t.data.executionId),void B.__classPrivateFieldGet(this,e,"m",V).call(this,"success",i)}this.storeLastAuthenticatedUser&&te.setLastAuth(w,!0),I&&window.open(I,"_blank");const{executionId:P,stepId:R,stepName:O,screen:C,redirect:F,webauthn:T,error:y,samlIdpResponse:A,wsFedIdpResponse:k,nativeResponse:W}=t.data,x=Date.now();E!==X.RESPONSE_ACTIONS.poll?(this.loggerWrapper.info(`Step "${O||`#${R}`}" is ${f}`,"",{screen:C,status:f,stepId:R,stepName:O,action:E,error:y}),(null===(m=C.state)||void 0===m?void 0:m.clientScripts)&&B.__classPrivateFieldSet(this,s,this.loadSdkScripts(C.state.clientScripts),"f"),this.flowState.update({stepId:R,stepName:O,executionId:P,action:E,redirectTo:null==F?void 0:F.url,redirectIsPopup:null==F?void 0:F.isPopup,screenId:null==C?void 0:C.id,screenState:null==C?void 0:C.state,webauthnTransactionId:null==T?void 0:T.transactionId,webauthnOptions:null==T?void 0:T.options,samlIdpResponseUrl:null==A?void 0:A.url,samlIdpResponseSamlResponse:null==A?void 0:A.samlResponse,samlIdpResponseRelayState:null==A?void 0:A.relayState,wsFedIdpResponseUrl:null==k?void 0:k.url,wsFedIdpResponseWresult:null==k?void 0:k.wresult,wsFedIdpResponseWctx:null==k?void 0:k.wctx,nativeResponseType:null==W?void 0:W.type,nativePayload:null==W?void 0:W.payload,reqTimestamp:x})):this.flowState.update({action:E,reqTimestamp:x})})),I.set(this,J.withMemCache((()=>B.__awaiter(this,void 0,void 0,(function*(){var e;try{const t=yield this.sdk.webauthn.signIn.start("",window.location.origin);return t.ok||this.loggerWrapper.warn("Webauthn start failed",null===(e=null==t?void 0:t.error)||void 0===e?void 0:e.errorMessage),t.data}catch(e){this.loggerWrapper.warn("Webauthn start failed",e.message)}}))))),C.set(this,void 0),F.set(this,void 0),W.set(this,null),L.set(this,J.leadingDebounce(((t,i,s)=>B.__awaiter(this,void 0,void 0,(function*(){var r,o;if("true"!==t.getAttribute("loading")&&"true"!==t.getAttribute("disabled")){if("true"===t.getAttribute("formnovalidate")||B.__classPrivateFieldGet(this,e,"m",A).call(this)){const n=null==t?void 0:t.getAttribute("id");B.__classPrivateFieldGet(this,e,"m",D).call(this,t,n,s);const a=B.__classPrivateFieldGet(this,e,"m",x).call(this,t);try{const s=yield B.__classPrivateFieldGet(this,e,"m",k).call(this),a=J.getElementDescopeAttributes(t);this.nextRequestStatus.update({isLoading:!0});const l=Object.assign(Object.assign(Object.assign({},a),s),{origin:(null===(r=this.nativeOptions)||void 0===r?void 0:r.origin)||window.location.origin}),d=yield i(n,l);this.nextRequestStatus.update({isLoading:!1}),this.captureLastSubmittedLoginId(s,null===(o=null==d?void 0:d.data)||void 0===o?void 0:o.executionId),this.storeCredentials(s)}catch(e){throw a(),e}}}else this.loggerWrapper.debug("Submit already in flight, ignoring")}))))),this.flowState=a,this.setValidationTrackingSender(((e,t)=>B.__awaiter(this,[e,t],void 0,(function*({executionId:e,events:t},{keepalive:i}){const s=yield this.sdk.flow.event(e,t,i);return{ok:s.ok,retryable:s.code>=500||429===s.code}}))))}nativeResume(e,t){var i,s,r,o,n,a;const l=JSON.parse(t);if("oauthWeb"===e||"sso"===e){let e,{exchangeCode:t}=l;if(!t){const r=new URL(l.url);t=null===(i=r.searchParams)||void 0===i?void 0:i.get(X.URL_CODE_PARAM_NAME),e=(null===(s=r.searchParams)||void 0===s?void 0:s.get(X.URL_ERR_PARAM_NAME))||void 0}null===(o=(r=this.nativeCallbacks).complete)||void 0===o||o.call(r,{exchangeCode:t,exchangeError:e,idpInitiated:!0})}else if("magicLink"===e){const e=new URL(l.url),t=e.searchParams.get(X.URL_TOKEN_PARAM_NAME),i=e.searchParams.get(X.URL_RUN_IDS_PARAM_NAME).split("_").pop();B.__classPrivateFieldGet(this,S,"f").call(this),this.flowState.update({token:t,stepId:i,action:void 0})}else if("beforeScreen"===e){const{screenResolve:e}=this.nativeCallbacks;this.nativeCallbacks.screenResolve=null;const{override:t}=l;t||(this.nativeCallbacks.screenNext=null),null==e||e(t)}else if("resumeScreen"===e){const{interactionId:e,form:t}=l,{screenNext:i}=this.nativeCallbacks;this.nativeCallbacks.screenNext=null,null==i||i(e,t)}else null===(a=(n=this.nativeCallbacks).complete)||void 0===a||a.call(n,l)}loadSdkScriptsModules(){const e=this.shadowRoot.querySelectorAll("div[data-script-id]");return Array.from(e).map((e=>e.moduleRes)).filter((e=>!!e))}loadSdkScripts(e){if(!(null==e?void 0:e.length))return null;const t=(e,t)=>i=>{this.dispatchEvent(new CustomEvent("components-context",{detail:{[J.getScriptResultPath(e.id,e.resultKey)]:i},bubbles:!0,composed:!0})),t(e.id)};this.loggerWrapper.debug(`Preparing to load scripts: ${e.map((e=>e.id)).join(", ")}`);const i=Promise.all(null==e?void 0:e.map((e=>B.__awaiter(this,void 0,void 0,(function*(){var i,s,r;const o=this.shadowRoot.querySelector(`[data-script-id="${e.id}"]`);if(o){this.loggerWrapper.debug("Script already loaded",e.id);const{moduleRes:t}=o;return null===(i=null==t?void 0:t.start)||void 0===i||i.call(t),t}(null===(s=globalThis.descope)||void 0===s?void 0:s[e.id])||(yield this.injectNpmLib("@descope/flow-scripts","1.0.19",`dist/${e.id}.js`));const n=null===(r=globalThis.descope)||void 0===r?void 0:r[e.id];return new Promise(((i,s)=>{try{const s=n(e.initArgs,{baseUrl:this.baseUrl,ref:this},t(e,i),this.loggerWrapper);if(s){const t=document.createElement("div");t.setAttribute("data-script-id",e.id),t.moduleRes=s,this.shadowRoot.appendChild(t);const r=this.nextRequestStatus.subscribe((()=>{var i;this.loggerWrapper.debug("Stopping script",e.id),(null===(i=s.stop)||void 0===i?void 0:i.call(s))&&(this.nextRequestStatus.unsubscribe(r),this.loggerWrapper.debug("Removing script",e.id),this.shadowRoot.removeChild(t))}));"function"==typeof s.present&&i(e.id)}}catch(e){s(e)}}))}))))),s=new Promise((e=>{setTimeout((()=>{this.loggerWrapper.warn("SDK scripts loading timeout"),e(!0)}),X.SDK_SCRIPTS_LOAD_TIMEOUT)}));return Promise.race([i,s])}get isDismissScreenErrorOnInput(){return"true"===this.getAttribute("dismiss-screen-error-on-input")}init(){var e,t;if(!window.descopeBridge)return this._init();this.lazyInit=this._init,B.__classPrivateFieldSet(this,n,null===(t=null===(e=null===window||void 0===window?void 0:window.descopeBridge)||void 0===e?void 0:e.registerFlow)||void 0===t?void 0:t.call(e,this),"f")}_init(){const t=Object.create(null,{init:{get:()=>super.init}});return B.__awaiter(this,void 0,void 0,(function*(){var i,s;this.shadowRoot.isConnected&&(null===(i=this.flowState)||void 0===i||i.subscribe(this.onFlowChange.bind(this)),B.__classPrivateFieldGet(this,e,"m",u).call(this),window.addEventListener("visibilitychange",B.__classPrivateFieldGet(this,r,"f").visibilitychange)),yield null===(s=t.init)||void 0===s?void 0:s.call(this)}))}disconnectedCallback(){var e,t,s;super.disconnectedCallback(),this.teardownValidationTracking(),B.__classPrivateFieldGet(this,n,"f")&&(null===(t=null===(e=window.descopeBridge)||void 0===e?void 0:e.unregisterFlow)||void 0===t||t.call(e,B.__classPrivateFieldGet(this,n,"f")),B.__classPrivateFieldSet(this,n,void 0,"f")),this.flowState.unsubscribeAll(),this.stepState.unsubscribeAll(),B.__classPrivateFieldGet(this,S,"f").call(this),null===(s=B.__classPrivateFieldGet(this,i,"f"))||void 0===s||s.abort(),B.__classPrivateFieldSet(this,i,null,"f"),window.removeEventListener("visibilitychange",B.__classPrivateFieldGet(this,r,"f").visibilitychange)}getHtmlFilenameWithLocale(e,t){return B.__awaiter(this,void 0,void 0,(function*(){let i;const s=K.getUserLocale(e),r=yield this.getTargetLocales();return r.includes(s.locale)?i=`${t}-${s.locale}.html`:r.includes(s.fallback)&&(i=`${t}-${s.fallback}.html`),i}))}getPageContent(e,t){return B.__awaiter(this,void 0,void 0,(function*(){if(t)try{const{body:e}=yield this.fetchStaticResource(t,"text");return e}catch(i){this.loggerWrapper.error(`Failed to fetch flow page from ${t}. Fallback to url ${e}`,i)}try{const{body:t}=yield this.fetchStaticResource(e,"text");return t}catch(e){this.loggerWrapper.error("Failed to fetch flow page",e.message)}return null}))}onFlowChange(t,r,o){return B.__awaiter(this,void 0,void 0,(function*(){var n,a;const{projectId:l,flowId:c,tenant:u,stepId:p,executionId:h,action:g,screenId:_,screenState:f,redirectTo:S,redirectIsPopup:w,redirectUrl:I,token:P,code:R,isPopup:O,exchangeError:y,webauthnTransactionId:A,webauthnOptions:k,redirectAuthCodeChallenge:W,redirectAuthCallbackUrl:x,redirectAuthBackupCallbackUri:N,redirectAuthInitiator:U,locale:L,samlIdpResponseUrl:j,samlIdpResponseSamlResponse:D,samlIdpResponseRelayState:M,wsFedIdpResponseUrl:q,wsFedIdpResponseWresult:z,wsFedIdpResponseWctx:Q,nativeResponseType:Y,nativePayload:ie,reqTimestamp:se}=t,re=B.__rest(t,["projectId","flowId","tenant","stepId","executionId","action","screenId","screenState","redirectTo","redirectIsPopup","redirectUrl","token","code","isPopup","exchangeError","webauthnTransactionId","webauthnOptions","redirectAuthCodeChallenge","redirectAuthCallbackUrl","redirectAuthBackupCallbackUri","redirectAuthInitiator","locale","samlIdpResponseUrl","samlIdpResponseSamlResponse","samlIdpResponseRelayState","wsFedIdpResponseUrl","wsFedIdpResponseWresult","wsFedIdpResponseWctx","nativeResponseType","nativePayload","reqTimestamp"]);let oe,ne,ae;const le=Z.getABTestingKey(),{outboundAppId:de,outboundAppScopes:ce}=this,ue=this.sdk.getLastUserLoginId();o("flowId")&&this.setValidationTrackingEnabled(!1);const pe=yield this.getFlowConfig();B.__classPrivateFieldGet(this,e,"m",T).call(this,pe,h,o);const he=yield this.getProjectConfig(),ge=Object.entries(he.flows||{}).reduce(((e,[t,i])=>(e[t]=i.version,e)),{}),ve=x&&W?{callbackUrl:x,codeChallenge:W,backupCallbackUri:N}:void 0,me=this.nativeOptions?{platform:this.nativeOptions.platform,bridgeVersion:this.nativeOptions.bridgeVersion,oauthProvider:this.nativeOptions.oauthProvider,oauthRedirect:this.nativeOptions.oauthRedirect,magicLinkRedirect:this.nativeOptions.magicLinkRedirect,ssoRedirect:this.nativeOptions.ssoRedirect,externalAuthRedirect:this.nativeOptions.externalAuthRedirect}:void 0;let _e={};if(!h){te.clearInFlightLastAuth(this.loggerWrapper);const e=[...pe.clientScripts||[],...pe.sdkScripts||[]];if(pe.conditions){let t=[];({startScreenId:oe,conditionInteractionId:ae,startScreenName:ne,clientScripts:t,componentsConfig:_e}=ee.calculateConditions({loginId:ue,code:R,token:P,abTestingKey:le,lastAuth:te.getLastAuth(ue,this.loggerWrapper)},pe.conditions)),e.push(...t||[])}else pe.condition?({startScreenId:oe,startScreenName:ne,conditionInteractionId:ae}=ee.calculateCondition(pe.condition,{loginId:ue,code:R,token:P,abTestingKey:le,lastAuth:te.getLastAuth(ue,this.loggerWrapper)})):(ne=pe.startScreenName,oe=pe.startScreenId);if(B.__classPrivateFieldSet(this,C,oe,"f"),B.__classPrivateFieldSet(this,F,ne,"f"),B.__classPrivateFieldSet(this,s,this.loadSdkScripts(e),"f"),pe.fingerprintEnabled&&pe.fingerprintKey?yield H.ensureFingerprintIds(pe.fingerprintKey,this.baseUrl):H.clearFingerprintData(),!J.showFirstScreenOnExecutionInit(oe,re)){const e=yield this.sdk.flow.start(c,Object.assign(Object.assign(Object.assign(Object.assign({tenant:u,redirectAuth:ve},re),{client:this.client}),I&&{redirectUrl:I}),{lastAuth:te.getLastAuth(ue,this.loggerWrapper),abTestingKey:le,locale:K.getUserLocale(L).locale,nativeOptions:me,outboundAppId:de,outboundAppScopes:ce}),ae,"",he.componentsVersion,ge,Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({},this.formConfigValues),R?{exchangeCode:R,idpInitiated:!0}:{}),re.descopeIdpInitiated&&{idpInitiated:!0}),P?{token:P}:{}),re.oidcLoginHint?{externalId:re.oidcLoginHint}:{}));return B.__classPrivateFieldGet(this,E,"f").call(this,e),void("completed"!==(null===(n=null==e?void 0:e.data)||void 0===n?void 0:n.status)&&this.flowState.update({code:void 0,token:void 0}))}}if(this.loggerWrapper.debug("Before popup postmessage send",JSON.stringify({isPopup:O,code:R,exchangeError:y,isCodeChanged:o("code"),isExchangeErrorChanged:o("exchangeError")})),O&&(o("code")&&R||o("exchangeError")&&y))return void B.__classPrivateFieldGet(this,e,"m",$).call(this,h,R,y);if(h&&(o("token")&&P||o("code")&&R||o("exchangeError")&&y)){const e=yield this.sdk.flow.next(h,p,X.CUSTOM_INTERACTIONS.submit,pe.version,he.componentsVersion,{token:P,exchangeCode:R,exchangeError:y});return B.__classPrivateFieldGet(this,E,"f").call(this,e),void this.flowState.update({token:void 0,code:void 0,exchangeError:void 0})}if(g===X.RESPONSE_ACTIONS.loadForm&&j&&["samlIdpResponseUrl","samlIdpResponseSamlResponse","samlIdpResponseRelayState"].some((e=>o(e)))){if(!D)return void this.loggerWrapper.error("Did not get saml idp params data to load");J.injectSamlIdpForm(j,D,M||"",J.submitForm)}if(g===X.RESPONSE_ACTIONS.loadForm&&q&&["wsFedIdpResponseUrl","wsFedIdpResponseWresult","wsFedIdpResponseWctx"].some((e=>o(e)))){if(!z)return void this.loggerWrapper.error("Did not get wsfed idp params data to load");J.injectWsFedIdpForm(q,z,Q||"",J.submitForm)}if(g===X.RESPONSE_ACTIONS.redirect&&(o("redirectTo")||o("deferredRedirect"))){if(!S)return void this.loggerWrapper.error("Did not get redirect url");if("no-op"===S)return;if("android"===U&&document.hidden)return void this.flowState.update({deferredRedirect:!0});if(this.loggerWrapper.debug(`Redirect is popup ${w}`),w){this.loggerWrapper.debug("Opening redirect in popup");const t=J.openCenteredPopup(S,"?",598,700),i=this.shouldUsePopupPostMessage();i&&(t.name=`descope-wc|${window.location.origin}`),this.loggerWrapper.debug("Popup communication method: "+(i?"postMessage":"BroadcastChannel"));let s=!1;const r=e=>{this.loggerWrapper.debug("Received popup message",JSON.stringify(e.data));const t=i?this.popupOrigin:window.location.origin;if(e.origin!==t)return void this.loggerWrapper.debug(`Ignoring message from unexpected origin. received: "${e.origin}", expected: "${t}"`);const{action:r,data:o}=e.data||{};"code"===r&&(s=!0,this.flowState.update({code:o.code,exchangeError:o.exchangeError}))};let o;this.loggerWrapper.debug("Starting popup closed detection");const n=setInterval((()=>{t.closed&&(this.loggerWrapper.debug("Popup closed, dispatching popupclosed event"),clearInterval(n),B.__classPrivateFieldGet(this,e,"m",V).call(this,"popupclosed",{abandoned:!s}),this.loggerWrapper.debug("Cleaning up popup listeners"),null==o||o())}),1e3);if(i)window.addEventListener("message",r),o=()=>{this.loggerWrapper.debug("Cleaning up popup postMessage listener"),window.removeEventListener("message",r)};else{this.loggerWrapper.debug("Creating broadcast channel");const e=new BroadcastChannel(h);e.onmessage=r,o=()=>{this.loggerWrapper.debug("Closing channel"),e.close()}}}else this.handleRedirect(S),this.flowState.update({redirectTo:"no-op"}),B.__classPrivateFieldGet(this,e,"m",V).call(this,"popupclosed",{});return}if(g===X.RESPONSE_ACTIONS.webauthnCreate||g===X.RESPONSE_ACTIONS.webauthnGet){if(!A||!k)return void this.loggerWrapper.error("Did not get webauthn transaction id or options");null===(a=B.__classPrivateFieldGet(this,i,"f"))||void 0===a||a.abort(),B.__classPrivateFieldSet(this,i,null,"f");const t=yield B.__classPrivateFieldGet(this,e,"m",m).call(this,g,k),s=yield this.sdk.flow.next(h,p,X.CUSTOM_INTERACTIONS.submit,pe.version,he.componentsVersion,Object.assign({transactionId:A},t));B.__classPrivateFieldGet(this,E,"f").call(this,s)}if(g===X.RESPONSE_ACTIONS.nativeBridge)return this.nativeCallbacks.complete=e=>B.__awaiter(this,void 0,void 0,(function*(){const t=yield this.sdk.flow.next(h,p,X.CUSTOM_INTERACTIONS.submit,pe.version,he.componentsVersion,e);B.__classPrivateFieldGet(this,E,"f").call(this,t)})),B.__classPrivateFieldGet(this,e,"m",d).call(this,Y,ie),void setTimeout((()=>{this.dispatchEvent(new Event("popupclosed"))}),500);if((o("action")||o("deferredPolling"))&&B.__classPrivateFieldGet(this,b,"f").call(this,h,p,pe.version,he.componentsVersion),!_&&!oe)return void this.loggerWrapper.warn("No screen was found to show");const fe=oe||_,be=yield this.getHtmlFilenameWithLocale(L,fe),{oidcLoginHint:Se,oidcPrompt:we,oidcErrorRedirectUri:Ee,oidcResource:Ie,samlIdpUsername:Pe}=re,Re={direction:J.getAnimationDirection(p,r.stepId),screenState:Object.assign(Object.assign({},f),{form:Object.assign(Object.assign({},this.formConfigValues),null==f?void 0:f.form),lastAuth:{loginId:ue,name:this.sdk.getLastUserDisplayName()||ue},componentsConfig:Object.assign(Object.assign(Object.assign({},pe.componentsConfig),_e),null==f?void 0:f.componentsConfig)}),htmlFilename:`${fe}.html`,htmlLocaleFilename:be,screenId:fe,stepName:t.stepName||ne,samlIdpUsername:Pe,oidcLoginHint:Se,oidcPrompt:we,oidcErrorRedirectUri:Ee,oidcResource:Ie,action:g,locale:K.getUserLocale(L).locale},Oe=te.getLastAuth(ue,this.loggerWrapper);J.showFirstScreenOnExecutionInit(oe,re)?Re.next=(t,i)=>B.__awaiter(this,void 0,void 0,(function*(){const s=(null==pe?void 0:pe.clientScripts)||[];yield B.__classPrivateFieldGet(this,e,"m",G).call(this,s);const r=yield this.sdk.flow.start(c,Object.assign(Object.assign(Object.assign(Object.assign({tenant:u,redirectAuth:ve},re),{lastAuth:Oe,preview:this.preview,abTestingKey:le,client:this.client}),I&&{redirectUrl:I}),{locale:K.getUserLocale(L).locale,nativeOptions:me,outboundAppId:de,outboundAppScopes:ce}),ae,t,he.componentsVersion,ge,Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({},this.formConfigValues),this.getComponentsContext()),J.transformScreenInputs(i)),R&&{exchangeCode:R,idpInitiated:!0}),re.descopeIdpInitiated&&{idpInitiated:!0}),P&&{token:P}),Re.next.isCustomScreen);return B.__classPrivateFieldGet(this,E,"f").call(this,r),r})):(o("projectId")||o("baseUrl")||o("executionId")||o("stepId"))&&(Re.next=(t,i)=>B.__awaiter(this,void 0,void 0,(function*(){const s=(null==f?void 0:f.clientScripts)||[];yield B.__classPrivateFieldGet(this,e,"m",G).call(this,s);const r=yield this.sdk.flow.next(h,p,t,pe.version,he.componentsVersion,Object.assign(Object.assign({},this.getComponentsContext()),J.transformScreenInputs(i)),Re.next.isCustomScreen);return B.__classPrivateFieldGet(this,E,"f").call(this,r),r}))),this.loggerWrapper.debug("Got a screen with id",Re.screenId),yield B.__classPrivateFieldGet(this,e,"m",v).call(this,Re),this.stepState.update(Re)}))}onStepChange(t,i){return B.__awaiter(this,void 0,void 0,(function*(){var s,r,o;const{htmlFilename:n,htmlLocaleFilename:a,direction:l,next:d,screenState:c,screenId:u}=t;this.loggerWrapper.debug("Rendering a flow screen"),this.updateScreenUser(null==c?void 0:c.user);const p=document.createElement("template");p.innerHTML=yield this.getPageContent(n,a);const h=p.content.cloneNode(!0),g=this.loadDescopeUiComponents(p);this.sdk.webauthn.helpers.isSupported()?yield B.__classPrivateFieldGet(this,e,"m",R).call(this,h,d):Q.disableWebauthnButtons(h),!t.samlIdpUsername||(null===(s=c.form)||void 0===s?void 0:s.loginId)||(null===(r=c.form)||void 0===r?void 0:r.email)||(c.form||(c.form={}),c.form.loginId=t.samlIdpUsername,c.form.email=t.samlIdpUsername),Q.updateTemplateFromScreenState(h,c,this.formConfig,this.loggerWrapper),this.applyComponentsState(h,null==c?void 0:c.componentsState);const{geo:v}=null!==(o=yield this.getExecutionContext())&&void 0!==o?o:{};Q.setComponentsAutoDetectByGeo(h,v),Q.setComponentsAutoDetectByLocale(h,t.locale);const m=()=>B.__awaiter(this,void 0,void 0,(function*(){var s,r;yield g;const o=this.contentRootElement;Q.setTOTPVariable(o,null===(s=null==c?void 0:c.totp)||void 0===s?void 0:s.image),Q.setNOTPVariable(o,null===(r=null==c?void 0:c.notp)||void 0===r?void 0:r.image),Q.setCssVars(o,h,c.cssVars,this.loggerWrapper),o.replaceChildren(h);const n=!i.htmlFilename;setTimeout((()=>{B.__classPrivateFieldGet(this,e,"m",N).call(this),this.updateUsernameAnchor(),this.validateOnBlur&&J.handleReportValidityOnBlur(o,(t=>this.trackValidationErrors([t],B.__classPrivateFieldGet(this,e,"a",y)))),Q.updateScreenFromScreenState(o,c),this.initRealtimeConditions(o,c),B.__classPrivateFieldGet(this,e,"m",O).call(this,{isFirstScreen:n,isCustomScreen:!1,stepName:t.stepName}),J.handleAutoFocus(o,this.autoFocus,n),B.__classPrivateFieldGet(this,e,"m",M).call(this,u)})),B.__classPrivateFieldGet(this,e,"m",q).call(this,d,u);o.querySelector(`[${X.ELEMENT_TYPE_ATTRIBUTE}="polling"]`)&&d(X.CUSTOM_INTERACTIONS.polling,{})}));l?B.__classPrivateFieldGet(this,e,"m",f).call(this,m):m()}))}getInputs(){return Array.from(this.shadowRoot.querySelectorAll(`*:not(slot)[name]:not([${X.DESCOPE_ATTRIBUTE_EXCLUDE_FIELD}])`))}shouldUsePopupPostMessage(){if(!this.popupOrigin)return!1;try{new URL(this.popupOrigin)}catch(e){return!1}return!0}}t=new WeakMap,i=new WeakMap,s=new WeakMap,r=new WeakMap,n=new WeakMap,g=new WeakMap,_=new WeakMap,b=new WeakMap,S=new WeakMap,w=new WeakMap,E=new WeakMap,I=new WeakMap,C=new WeakMap,F=new WeakMap,W=new WeakMap,L=new WeakMap,e=new WeakSet,o=function(){document.hidden||setTimeout((()=>{this.flowState.update({deferredRedirect:!1,deferredPolling:!1})}),300)},a=function(t,i,s){return B.__awaiter(this,void 0,void 0,(function*(){var r;return(null===(r=this.nativeOptions)||void 0===r?void 0:r.bridgeVersion)>=2&&new Promise((r=>{this.nativeCallbacks.screenNext=s,this.nativeCallbacks.screenResolve=r,B.__classPrivateFieldGet(this,e,"m",d).call(this,"beforeScreen",{screen:t,context:i})}))}))},l=function(t){var i;(null===(i=this.nativeOptions)||void 0===i?void 0:i.bridgeVersion)>=2&&B.__classPrivateFieldGet(this,e,"m",d).call(this,"afterScreen",{screen:t})},d=function(t,i){B.__classPrivateFieldGet(this,e,"m",V).call(this,"bridge",{type:t,payload:i})},c=function({errorText:e,errorType:t}){const i=()=>{var i;let s=e;try{s=(null===(i=this.errorTransformer)||void 0===i?void 0:i.call(this,{text:e,type:t}))||e}catch(e){this.loggerWrapper.error("Error transforming error message",e.message)}Q.replaceElementMessage(this.contentRootElement,"error-message",s)};this.addEventListener("screen-updated",i,{once:!0}),i()},u=function(){var t,i,s,r;null===(t=this.stepState)||void 0===t||t.subscribe(this.onStepChange.bind(this),(e=>{var t=e.screenState,i=void 0===t?{}:t,s=B.__rest(i,["errorText","errorType"]),r=B.__rest(e,["screenState"]);return Object.assign(Object.assign({},r),{screenState:s})})),null===(i=this.stepState)||void 0===i||i.subscribe(B.__classPrivateFieldGet(this,e,"m",c).bind(this),(e=>{var t,i;return{errorText:null===(t=null==e?void 0:e.screenState)||void 0===t?void 0:t.errorText,errorType:null===(i=null==e?void 0:e.screenState)||void 0===i?void 0:i.errorType}}),{forceUpdate:!0}),null===(s=this.stepState)||void 0===s||s.subscribe(B.__classPrivateFieldGet(this,e,"m",p).bind(this),(e=>{var t,i;return{errorText:null===(t=null==e?void 0:e.screenState)||void 0===t?void 0:t.errorText,errorType:null===(i=null==e?void 0:e.screenState)||void 0===i?void 0:i.errorType}}),{forceUpdate:!0}),null===(r=this.flowState)||void 0===r||r.subscribe((({screenId:e,executionId:t})=>{var i;try{this.updateTelemetryContext({screenId:e,executionId:t})}catch(e){null===(i=this.logger)||void 0===i||i.error("Error updating telemetry screenId:",e)}}),(e=>({screenId:e.screenId,executionId:e.executionId})))},p=function({errorText:e,errorType:t}){(t||e)&&(this.contentRootElement.querySelectorAll('descope-passcode[data-auto-submit="true"]').forEach((e=>{e.shadowRoot.querySelectorAll("descope-text-field[data-id]").forEach((e=>{e.value=""}))})),J.handleAutoFocus(this.contentRootElement,this.autoFocus,!1))},h=function(){return B.__awaiter(this,void 0,void 0,(function*(){this.loggerWrapper.debug("Trying to restart the flow");const e=yield this.getComponentsVersion();this.reset();e===(yield this.getComponentsVersion())?(this.loggerWrapper.debug("Components version was not changed, restarting flow"),this.flowState.update({stepId:null,executionId:null})):this.loggerWrapper.error("Components version mismatch, please reload the page")}))},v=function(t){return B.__awaiter(this,void 0,void 0,(function*(){var i;const s=Object.assign(Object.assign({},this.stepState.current),t),{next:r,stepName:o}=s,n=B.__rest(s,["next","stepName"]),l=J.transformStepStateForCustomScreen(n);let d=yield B.__classPrivateFieldGet(this,e,"m",a).call(this,o,l,r);d||(d=Boolean(yield null===(i=this.onScreenUpdate)||void 0===i?void 0:i.call(this,o,l,r,this)));const c=!this.stepState.current.htmlFilename;if(B.__classPrivateFieldGet(this,_,"f").call(this,d),r&&(r.isCustomScreen=d),B.__classPrivateFieldGet(this,g,"f")!==d){const[t,i]=["flow","custom"].sort((()=>d?-1:1));this.loggerWrapper.debug(`Switching from ${i} screen to ${t} screen`),B.__classPrivateFieldSet(this,g,d,"f"),d?this.stepState.unsubscribeAll():B.__classPrivateFieldGet(this,e,"m",u).call(this)}d?(this.loggerWrapper.debug("Showing a custom screen"),B.__classPrivateFieldGet(this,e,"m",O).call(this,{isFirstScreen:c,isCustomScreen:d,stepName:t.stepName}),this.disableKeyPressHandler()):this.handleKeyPress(),this.stepState.forceUpdate=d}))},m=function(e,t){return B.__awaiter(this,void 0,void 0,(function*(){const i=new AbortController;try{const s=e===X.RESPONSE_ACTIONS.webauthnCreate?this.sdk.webauthn.helpers.create(t,i):this.sdk.webauthn.helpers.get(t,i),r=yield J.timeoutPromise(X.WEBAUTHN_TIMEOUT,s,re);return r!==re?{response:r}:(i.abort(),this.loggerWrapper.warn(`WebAuthn operation timed out after ${X.WEBAUTHN_TIMEOUT}ms`),{failure:"AbortError",failureReason:"aborted",failureMessage:"Passkey operation timed out"})}catch(e){return"InvalidStateError"===e.name?this.loggerWrapper.warn("WebAuthn operation failed",e.message):"NotAllowedError"!==e.name&&this.loggerWrapper.error(e.message),{failure:e.name,failureReason:e.reason,failureMessage:e.message}}}))},f=function(e){this.contentRootElement.addEventListener("transitionend",(()=>{this.loggerWrapper.debug("page switch transition end"),this.contentRootElement.classList.remove("fade-out"),e()}),{once:!0}),this.loggerWrapper.debug("page switch transition start"),this.contentRootElement.classList.add("fade-out")},P=function(e){const t=e.getAttribute("name");if(!["email"].includes(t)){const i=`user-${t}`;e.setAttribute("name",i),e.addEventListener("input",(()=>{e.setAttribute("name",e.value?t:i)}))}},R=function(t,s){return B.__awaiter(this,void 0,void 0,(function*(){var r;null===(r=B.__classPrivateFieldGet(this,i,"f"))||void 0===r||r.abort();const o=t.querySelector('*[autocomplete="webauthn"]');if(o&&(yield Y.isConditionalLoginSupported())){const{options:t,transactionId:r}=(yield B.__classPrivateFieldGet(this,I,"f").call(this))||{};t&&r&&(B.__classPrivateFieldGet(this,e,"m",P).call(this,o),B.__classPrivateFieldSet(this,i,new AbortController,"f"),this.sdk.webauthn.helpers.conditional(t,B.__classPrivateFieldGet(this,i,"f")).then((e=>B.__awaiter(this,void 0,void 0,(function*(){s(o.id,{transactionId:r,response:e})})))).catch((e=>{"AbortError"!==e.name&&this.loggerWrapper.error("Conditional login failed",e.message)})))}}))},O=function({isFirstScreen:t,isCustomScreen:i,stepName:s}){t&&B.__classPrivateFieldGet(this,e,"m",V).call(this,"ready",{}),i||B.__classPrivateFieldGet(this,e,"m",l).call(this,s),B.__classPrivateFieldGet(this,e,"m",V).call(this,"page-updated",{screenName:s}),B.__classPrivateFieldGet(this,e,"m",V).call(this,"screen-updated",{screenName:s})},T=function(e,t,i){this.setValidationTrackingEnabled(!!e.clientValidationTrackingEnabled),t&&i("executionId")&&this.setValidationTrackingExecution(t)},y=function(){var e,t,i,s,r,o,n;const a=null===(e=this.flowState)||void 0===e?void 0:e.current;return(null==a?void 0:a.executionId)?{executionId:a.executionId,screenId:a.screenId,screenName:(null===(n=null===(o=this.stepState)||void 0===o?void 0:o.current)||void 0===n?void 0:n.stepName)||a.stepName}:{executionId:void 0,screenId:null!==(t=B.__classPrivateFieldGet(this,C,"f"))&&void 0!==t?t:null==a?void 0:a.screenId,screenName:null!==(i=B.__classPrivateFieldGet(this,F,"f"))&&void 0!==i?i:(null===(r=null===(s=this.stepState)||void 0===s?void 0:s.current)||void 0===r?void 0:r.stepName)||(null==a?void 0:a.stepName)}},A=function(){let t=!0;const i=[];return Array.from(this.shadowRoot.querySelectorAll("*[name]")).reverse().forEach((e=>{var s,r;"slot"===e.localName||e.classList.contains("hidden")||(null===(s=e.reportValidity)||void 0===s||s.call(e),e.validity&&!e.validity.valid&&i.push(e),t&&(t=null===(r=e.checkValidity)||void 0===r?void 0:r.call(e)))})),i.length&&this.trackValidationErrors(i,B.__classPrivateFieldGet(this,e,"a",y)),t},k=function(){return B.__awaiter(this,void 0,void 0,(function*(){const e=this.getInputs();return(yield Promise.all(e.map((e=>B.__awaiter(this,void 0,void 0,(function*(){return{name:e.getAttribute("name"),value:e.value}})))))).reduce(((e,t)=>Object.assign(Object.assign({},e),{[t.name]:t.value})),{})}))},x=function(e){var t,i;const r=Array.from(this.contentRootElement.querySelectorAll(':not([disabled]), [disabled="false"]')).filter((t=>t!==e)),o=(null===(i=null===(t=this.flowState.current)||void 0===t?void 0:t.screenState)||void 0===i?void 0:i.clientScripts)||[];e.setAttribute("loading","true"),r.forEach((e=>e.setAttribute("disabled","true")));const n=()=>{e.removeAttribute("loading"),r.forEach((e=>{e.removeAttribute("disabled")}))},a=e=>B.__awaiter(this,void 0,void 0,(function*(){var t;this.loggerWrapper.debug("Restoring components state"),this.removeEventListener("popupclosed",a);if(!0===(null===(t=null==e?void 0:e.detail)||void 0===t?void 0:t.abandoned)&&o.length)return B.__classPrivateFieldSet(this,s,(()=>B.__awaiter(this,void 0,void 0,(function*(){try{yield this.loadSdkScripts(o)}catch(e){this.loggerWrapper.warn("Failed to refresh client scripts on popup close",null==e?void 0:e.message)}})))(),"f"),void n();n();const i=yield this.getFlowConfig(),r=[...i.clientScripts||[],...i.sdkScripts||[]];this.loadSdkScripts(r)})),l=()=>{var e;window.removeEventListener("pageshow",B.__classPrivateFieldGet(this,W,"f")),B.__classPrivateFieldSet(this,W,(e=>{e.persisted&&(this.logger.debug("Page was loaded from cache, restoring components state"),a())}),"f"),window.addEventListener("pageshow",B.__classPrivateFieldGet(this,W,"f"),{once:!0});const t=null===(e=this.stepState)||void 0===e?void 0:e.subscribe(((e,i)=>{e===i&&a(),this.removeEventListener("popupclosed",a),this.stepState.unsubscribe(t)}),(e=>e.screenId),{forceUpdate:!0})},d=this.nextRequestStatus.subscribe((({isLoading:e})=>{e?this.addEventListener("popupclosed",a,{once:!0}):(this.nextRequestStatus.unsubscribe(d),"success"===this.flowStatus?(this.removeEventListener("popupclosed",a),n()):l())}));return n},N=function(){J.clearPreviousExternalInputs();this.contentRootElement.querySelectorAll('[external-input="true"]').forEach((t=>B.__classPrivateFieldGet(this,e,"m",U).call(this,t)))},U=function(e){if(!e)return;e.querySelectorAll("input").forEach((t=>{const i=t.getAttribute("slot"),s=`input-${e.id}-${i}`,r=document.createElement("slot");r.setAttribute("name",s),r.setAttribute("slot",i),e.appendChild(r),t.setAttribute("slot",s),this.appendChild(t)}))},G=function(e){return B.__awaiter(this,void 0,void 0,(function*(){if(B.__classPrivateFieldGet(this,s,"f")){this.loggerWrapper.debug("Waiting for sdk scripts to load");const e=Date.now();yield B.__classPrivateFieldGet(this,s,"f"),this.loggerWrapper.debug("Sdk scripts loaded for",(Date.now()-e).toString())}const t=this.loadSdkScriptsModules(),i=e.map((e=>e.id));for(const e of t)if(i.includes(e.id))try{if("function"==typeof e.present){(yield e.present())||this.loggerWrapper.debug(`Sdk script ${e.id} was cancelled`)}}catch(t){this.loggerWrapper.error(`Failed to present ${e.id} script module`,t.message)}const r=[];for(const e of t)"function"==typeof e.refresh&&r.push(e.refresh());if(r.length>0)try{yield J.timeoutPromise(X.SDK_SCRIPTS_LOAD_TIMEOUT,Promise.all(r),null)}catch(e){this.loggerWrapper.error("Failed to refresh script module",e.message)}}))},j=function(e,t){this.contentRootElement.querySelectorAll('descope-passcode[data-auto-submit="true"]').forEach((i=>{i.addEventListener("input",(()=>{var s;(null===(s=i.checkValidity)||void 0===s?void 0:s.call(i))&&B.__classPrivateFieldGet(this,L,"f").call(this,i,e,t)}))}))},D=function(e,t,i){t&&i&&"true"===e.getAttribute(X.DESCOPE_ATTRIBUTE_OPT_IN_LAST_USED)&&te.updateLastUsedPerScreen(i,t,this.loggerWrapper)},M=function(e){var t;const i=this.sdk.getLastUserLoginId(),s=null===(t=te.getLastAuth(i,this.loggerWrapper).lastUsedPerScreen)||void 0===t?void 0:t[e];if(!s)return;const r=this.contentRootElement.querySelector(X.DESCOPE_LAST_AUTH_BADGE_COMPONENT),o=this.contentRootElement.querySelector(`#${CSS.escape(s)}`);r&&o&&(o.replaceWith(r),r.appendChild(o))},q=function(t,i){this.contentRootElement.querySelectorAll(`descope-button:not([${X.DESCOPE_ATTRIBUTE_EXCLUDE_NEXT_BUTTON}]), [data-type="button"]:not([${X.DESCOPE_ATTRIBUTE_EXCLUDE_NEXT_BUTTON}]`).forEach((e=>{e.onclick=()=>{B.__classPrivateFieldGet(this,L,"f").call(this,e,t,i)}})),B.__classPrivateFieldGet(this,e,"m",j).call(this,t,i),this.isDismissScreenErrorOnInput&&this.contentRootElement.querySelectorAll(`*[name]:not([${X.DESCOPE_ATTRIBUTE_EXCLUDE_FIELD}])`).forEach((e=>{e.addEventListener("input",(()=>{this.stepState.update((e=>Object.assign(Object.assign({},e),{screenState:Object.assign(Object.assign({},e.screenState),{errorText:"",errorType:""})})))}))}))},V=function(e,t){this.dispatchEvent(new CustomEvent(e,{detail:t}))},$=function(e,t,i){var s;const[r,o]=(null===(s=window.name)||void 0===s?void 0:s.split("|"))||[],n={data:{code:t,exchangeError:i},action:"code"};if("descope-wc"===r&&o){this.loggerWrapper.debug("Using postMessage fallback to notify opener in origin",o);try{window.opener.postMessage(n,o)}catch(e){this.loggerWrapper.error("Failed to send postMessage fallback (likely COOP isolation)",null==e?void 0:e.message)}}else{this.loggerWrapper.debug("Creating popup channel",e);const t=new BroadcastChannel(e);t.postMessage(n),t.close()}try{window.close()}catch(e){}},oe.bridgeVersion=3,module.exports=oe;
|
|
2
2
|
//# sourceMappingURL=DescopeWc.js.map
|