@descope/web-component 0.0.25
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/README.md +39 -0
- package/dist/descope-wc.d.ts +13 -0
- package/dist/descope-wc.js +1 -0
- package/package.json +67 -0
package/README.md
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# @descope/web-component
|
|
2
|
+
|
|
3
|
+
Create your login pages on our console-app, once done, you can use this library to inject those pages to your app</br>
|
|
4
|
+
it registers- a [web component](https://developer.mozilla.org/en-US/docs/Web/Web_Components) and update the web-component content based on the relevant page,
|
|
5
|
+
See usage example below
|
|
6
|
+
## Usage
|
|
7
|
+
### Install the package
|
|
8
|
+
```bash
|
|
9
|
+
npm install @descope/web-component
|
|
10
|
+
```
|
|
11
|
+
### As a library
|
|
12
|
+
```js
|
|
13
|
+
import '@descope/web-component'
|
|
14
|
+
import { DescopeWc } // in case you need types definition or you want to use the class directly
|
|
15
|
+
|
|
16
|
+
//render a custom element, for example:
|
|
17
|
+
render(){
|
|
18
|
+
return (
|
|
19
|
+
<descope-wc project="myProjectId"/>
|
|
20
|
+
)
|
|
21
|
+
}
|
|
22
|
+
```
|
|
23
|
+
### In HTML file
|
|
24
|
+
|
|
25
|
+
- Copy the file `@descope/web-js/sdk/dist/descope-wc.js` and place it where your HTML file is located
|
|
26
|
+
|
|
27
|
+
- Add the following script tag to your HTML file
|
|
28
|
+
```html
|
|
29
|
+
<head>
|
|
30
|
+
<script src="./my-lib.umd.production.min.js"></script>
|
|
31
|
+
</head>
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
- Now you can add the custom element to your HTML
|
|
35
|
+
```html
|
|
36
|
+
<descope-wc project="myProjectId"></descope-wc>
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
*TODO: we shoud host this file so it can be included without installing the package, once we will publish it to a public registry, we can also use unpkg.com/ to serve it*
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
declare class DescopeWc extends HTMLElement {
|
|
2
|
+
#private;
|
|
3
|
+
static get observedAttributes(): string[];
|
|
4
|
+
constructor();
|
|
5
|
+
get 'project-id'(): string;
|
|
6
|
+
get 'flow-id'(): string;
|
|
7
|
+
get 'base-url'(): string;
|
|
8
|
+
connectedCallback(): void;
|
|
9
|
+
disconnectedCallback(): void;
|
|
10
|
+
attributeChangedCallback(attrName: string, oldValue: string, newValue: string): void;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export { DescopeWc as default };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
!function(){"use strict";function t(t,e,n,r){return new(n||(n=Promise))((function(o,i){function s(t){try{c(r.next(t))}catch(t){i(t)}}function a(t){try{c(r.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(s,a)}c((r=r.apply(t,e||[])).next())}))}function e(t,e,n,r){if("a"===n&&!r)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof e?t!==e||!r:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===n?r:"a"===n?r.call(t):r?r.value:e.get(t)}function n(t,e,n,r,o){if("m"===r)throw new TypeError("Private method is not writable");if("a"===r&&!o)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof e?t!==e||!o:!e.has(t))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===r?o.call(t,n):o?o.value=n:e.set(t,n),n}function r(t){this.message=t}r.prototype=new Error,r.prototype.name="InvalidCharacterError";var o="undefined"!=typeof window&&window.atob&&window.atob.bind(window)||function(t){var e=String(t).replace(/=+$/,"");if(e.length%4==1)throw new r("'atob' failed: The string to be decoded is not correctly encoded.");for(var n,o,i=0,s=0,a="";o=e.charAt(s++);~o&&(n=i%4?64*n+o:o,i++%4)?a+=String.fromCharCode(255&n>>(-2*i&6)):0)o="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(o);return a};function i(t){this.message=t}function s(t,e){if("string"!=typeof t)throw new i("Invalid token specified");var n=!0===(e=e||{}).header?0:1;try{return JSON.parse(function(t){var e=t.replace(/-/g,"+").replace(/_/g,"/");switch(e.length%4){case 0:break;case 2:e+="==";break;case 3:e+="=";break;default:throw"Illegal base64url string!"}try{return function(t){return decodeURIComponent(o(t).replace(/(.)/g,(function(t,e){var n=e.charCodeAt(0).toString(16).toUpperCase();return n.length<2&&(n="0"+n),"%"+n})))}(e)}catch(t){return o(e)}}(t.split(".")[n]))}catch(t){throw new i("Invalid token specified: "+t.message)}}i.prototype=new Error,i.prototype.name="InvalidTokenError";var a="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},c="__lodash_hash_undefined__",d="[object Function]",u="[object GeneratorFunction]",l=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,h=/^\w*$/,p=/^\./,f=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,v=/\\(\\)?/g,g=/^\[object .+?Constructor\]$/,b="object"==typeof a&&a&&a.Object===Object&&a,m="object"==typeof self&&self&&self.Object===Object&&self,y=b||m||Function("return this")();var w,I=Array.prototype,j=Function.prototype,k=Object.prototype,O=y["__core-js_shared__"],x=(w=/[^.]+$/.exec(O&&O.keys&&O.keys.IE_PROTO||""))?"Symbol(src)_1."+w:"",_=j.toString,E=k.hasOwnProperty,U=k.toString,S=RegExp("^"+_.call(E).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),P=y.Symbol,T=I.splice,R=H(y,"Map"),M=H(Object,"create"),A=P?P.prototype:void 0,$=A?A.toString:void 0;function C(t){var e=-1,n=t?t.length:0;for(this.clear();++e<n;){var r=t[e];this.set(r[0],r[1])}}function L(t){var e=-1,n=t?t.length:0;for(this.clear();++e<n;){var r=t[e];this.set(r[0],r[1])}}function q(t){var e=-1,n=t?t.length:0;for(this.clear();++e<n;){var r=t[e];this.set(r[0],r[1])}}function N(t,e){for(var n,r,o=t.length;o--;)if((n=t[o][0])===(r=e)||n!=n&&r!=r)return o;return-1}function W(t,e){var n;e=function(t,e){if(Z(t))return!1;var n=typeof t;if("number"==n||"symbol"==n||"boolean"==n||null==t||K(t))return!0;return h.test(t)||!l.test(t)||null!=e&&t in Object(e)}(e,t)?[e]:Z(n=e)?n:F(n);for(var r=0,o=e.length;null!=t&&r<o;)t=t[B(e[r++])];return r&&r==o?t:void 0}function D(t){if(!G(t)||(e=t,x&&x in e))return!1;var e,n=function(t){var e=G(t)?U.call(t):"";return e==d||e==u}(t)||function(t){var e=!1;if(null!=t&&"function"!=typeof t.toString)try{e=!!(t+"")}catch(t){}return e}(t)?S:g;return n.test(function(t){if(null!=t){try{return _.call(t)}catch(t){}try{return t+""}catch(t){}}return""}(t))}function z(t,e){var n,r,o=t.__data__;return("string"==(r=typeof(n=e))||"number"==r||"symbol"==r||"boolean"==r?"__proto__"!==n:null===n)?o["string"==typeof e?"string":"hash"]:o.map}function H(t,e){var n=function(t,e){return null==t?void 0:t[e]}(t,e);return D(n)?n:void 0}C.prototype.clear=function(){this.__data__=M?M(null):{}},C.prototype.delete=function(t){return this.has(t)&&delete this.__data__[t]},C.prototype.get=function(t){var e=this.__data__;if(M){var n=e[t];return n===c?void 0:n}return E.call(e,t)?e[t]:void 0},C.prototype.has=function(t){var e=this.__data__;return M?void 0!==e[t]:E.call(e,t)},C.prototype.set=function(t,e){return this.__data__[t]=M&&void 0===e?c:e,this},L.prototype.clear=function(){this.__data__=[]},L.prototype.delete=function(t){var e=this.__data__,n=N(e,t);return!(n<0)&&(n==e.length-1?e.pop():T.call(e,n,1),!0)},L.prototype.get=function(t){var e=this.__data__,n=N(e,t);return n<0?void 0:e[n][1]},L.prototype.has=function(t){return N(this.__data__,t)>-1},L.prototype.set=function(t,e){var n=this.__data__,r=N(n,t);return r<0?n.push([t,e]):n[r][1]=e,this},q.prototype.clear=function(){this.__data__={hash:new C,map:new(R||L),string:new C}},q.prototype.delete=function(t){return z(this,t).delete(t)},q.prototype.get=function(t){return z(this,t).get(t)},q.prototype.has=function(t){return z(this,t).has(t)},q.prototype.set=function(t,e){return z(this,t).set(t,e),this};var F=J((function(t){var e;t=null==(e=t)?"":function(t){if("string"==typeof t)return t;if(K(t))return $?$.call(t):"";var e=t+"";return"0"==e&&1/t==-1/0?"-0":e}(e);var n=[];return p.test(t)&&n.push(""),t.replace(f,(function(t,e,r,o){n.push(r?o.replace(v,"$1"):e||t)})),n}));function B(t){if("string"==typeof t||K(t))return t;var e=t+"";return"0"==e&&1/t==-1/0?"-0":e}function J(t,e){if("function"!=typeof t||e&&"function"!=typeof e)throw new TypeError("Expected a function");var n=function(){var r=arguments,o=e?e.apply(this,r):r[0],i=n.cache;if(i.has(o))return i.get(o);var s=t.apply(this,r);return n.cache=i.set(o,s),s};return n.cache=new(J.Cache||q),n}J.Cache=q;var Z=Array.isArray;function G(t){var e=typeof t;return!!t&&("object"==e||"function"==e)}function K(t){return"symbol"==typeof t||function(t){return!!t&&"object"==typeof t}(t)&&"[object Symbol]"==U.call(t)}var Q=function(t,e,n){var r=null==t?void 0:W(t,e);return void 0===r?n:r},V="/v1/auth/code/verify",X="/v1/auth/signin/otp",Y="/v1/auth/signup/otp",tt={email:"/v1/user/update/email/otp",phone:"/v1/user/update/phone/otp"},et="/v1/auth/sign-up-or-in/otp",nt="/v1/auth/magiclink/verify",rt="/v1/auth/signin/magiclink",ot="/v1/auth/signup/magiclink",it="/v1/auth/magiclink/session",st={email:"/v1/user/update/email/magiclink",phone:"/v1/user/update/phone/magiclink"},at="/v1/auth/sign-up-or-in/magiclink",ct="/v1/oauth/authorize",dt="/v1/auth/saml/authorize",ut="/v1/auth/verify/totp",lt="/v1/auth/signup/totp",ht="/v1/user/update/totp",pt={start:"/v1/webauthn/signup/start",finish:"/v1/webauthn/signup/finish"},ft={start:"/v1/webauthn/signin/start",finish:"/v1/webauthn/signin/finish"},vt={start:"/v1/webauthn/device/add/start",finish:"/v1/webauthn/device/add/finish"},gt="/v1/flow/start",bt="/v1/flow/next";const mt=()=>{const t={};return{headers(e){const n="function"==typeof e.entries?Object.fromEntries(e.entries()):e;return t.Headers=JSON.stringify(n),this},body(e){return t.Body=e,this},url(e){return t.Url=e.toString(),this},method(e){return t.Method=e,this},title(e){return t.Title=e,this},status(e){return t.Status=e,this},build:()=>Object.keys(t).flatMap((e=>t[e]?[`${"Title"!==e?`${e}: `:""}${t[e]}`]:[])).join("\n")}},yt=(...t)=>new Headers(t.reduce(((t,e)=>{const n=(t=>Array.isArray(t)?t:t instanceof Headers?Array.from(t.entries()):t?Object.entries(t):[])(e);return n.reduce(((e,[n,r])=>(t[n]=r,t)),t),t}),{})),wt=t=>void 0===t?void 0:JSON.stringify(t);var It;!function(t){t.get="GET",t.delete="DELETE",t.post="POST",t.put="PUT"}(It||(It={}));const jt=(t,e="")=>{let n=t;return""!==e&&(n=n+":"+e),{Authorization:`Bearer ${n}`}},kt=({baseUrl:e,projectId:n,baseConfig:r,logger:o})=>{const i=((e,n)=>{const r=n||fetch;if(!r)throw new Error("fetch is not defined");return e?(...n)=>t(void 0,void 0,void 0,(function*(){e.log((t=>mt().title("Request").url(t[0]).method(t[1].method).headers(t[1].headers).body(t[1].body).build())(n));const o=yield r(...n);return e[o.ok?"log":"error"](yield(e=>t(void 0,void 0,void 0,(function*(){const t=yield e.text();return e.text=()=>Promise.resolve(t),e.json=()=>Promise.resolve(JSON.parse(t)),mt().title("Response").url(e.url.toString()).status(`${e.status} ${e.statusText}`).headers(e.headers).body(t).build()})))(o)),o})):r})(o),s=({path:t,body:o,headers:s,queryParams:a,method:c,token:d})=>i((({path:t,baseUrl:e,queryParams:n})=>{const r=new URL(t,e);return n&&(r.search=new URLSearchParams(n).toString()),r})({path:t,baseUrl:e,queryParams:a}),{headers:yt(jt(n,d),(null==r?void 0:r.baseHeaders)||{},s),method:c,body:wt(o)});return{get:(t,{headers:e,queryParams:n,token:r}={})=>s({path:t,headers:e,queryParams:n,body:void 0,method:It.get,token:r}),post:(t,e,{headers:n,queryParams:r,token:o}={})=>s({path:t,headers:n,queryParams:r,body:e,method:It.post,token:o}),put:(t,e,{headers:n,queryParams:r,token:o}={})=>s({path:t,headers:n,queryParams:r,body:e,method:It.put,token:o}),delete:(t,e,{headers:n,queryParams:r,token:o}={})=>s({path:t,headers:n,queryParams:r,body:e,method:It.delete,token:o})}},Ot=t=>{if("string"!=typeof t||!t)throw new Error("Invalid token provided");const{exp:e}=s(t);return(new Date).getTime()/1e3>e},xt=(...t)=>t.join("/").replace(/\/{2,}/g,"/"),_t=e=>t(void 0,void 0,void 0,(function*(){const t=yield e,n={code:t.status,ok:t.ok,response:t},r=yield t.json();return t.ok?n.data=r:n.error=r,n}));var Et,Ut,St;!function(t){t.sms="sms",t.whatsapp="whatsapp"}(Et||(Et={})),function(t){t.email="email",t.sms="sms",t.whatsapp="whatsapp"}(Ut||(Ut={})),function(t){t.signUp="signup",t.signIn="signin",t.verify="verify"}(St||(St={}));const Pt=(t,e)=>(n=e)=>e=>!t(e)&&n.replace("{val}",e),Tt=(...t)=>({validate:e=>(t.forEach((t=>{const n=t(e);if(n)throw new Error(n)})),!0)}),Rt=t=>e=>t.test(e),Mt=Rt(/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/),At=Rt(/^\+[1-9]{1}[0-9]{3,14}$/),$t=Pt(Mt,'"{val}" is not a valid email'),Ct=Pt(At,'"{val}" is not a valid phone number'),Lt=Pt((1,t=>t.length>=1),"Minimum length is 1");const qt=Pt((t=>"string"==typeof t),"Input is not a string"),Nt=(...t)=>e=>(...n)=>(t.forEach(((t,e)=>Tt(...t).validate(n[e]))),e(...n)),Wt=t=>[qt(`"${t}" must be a string`),Lt(`"${t}" must not be empty`)],Dt=t=>[qt(`"${t}" must be a string`),$t()],zt=t=>[qt(`"${t}" must be a string`),Ct()];var Ht;!function(t){t.signUp="signup",t.signIn="signin",t.verify="verify",t.updatePhone="updatePhone"}(Ht||(Ht={}));const Ft=Wt("identifier"),Bt=Nt(Ft,Wt("code")),Jt=Nt(Ft),Zt=Nt(Ft,zt("phone")),Gt=Nt(Ft,Dt("email")),Kt=t=>({verify:Object.keys(Ut).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:Bt(((e,r)=>_t(t.post(xt(V,n),{code:r,externalId:e}))))})),{}),signIn:Object.keys(Ut).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:Jt((e=>_t(t.post(xt(X,n),{externalId:e}))))})),{}),signUp:Object.keys(Ut).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:Jt(((e,r)=>_t(t.post(xt(Y,n),{externalId:e,user:r}))))})),{}),signUpOrIn:Object.keys(Ut).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:Jt((e=>_t(t.post(xt(et,n),{externalId:e}))))})),{}),update:{email:Gt(((e,n,r)=>_t(t.post(tt.email,{externalId:e,email:n},{token:r})))),phone:Object.keys(Et).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:Zt(((e,r,o)=>_t(t.post(xt(tt.phone,n),{externalId:e,phone:r},{token:o}))))})),{})}}),Qt=Wt("identifier"),Vt=Wt("uri"),Xt=Nt(Wt("token")),Yt=Nt(Qt,Vt),te=Nt(Wt("pendingRef")),ee=Nt(Qt,zt("phone"),Vt),ne=Nt(Qt,Dt("email"),Vt),re=e=>({verify:Xt((t=>_t(e.post(nt,{token:t})))),signIn:Object.keys(Ut).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:Yt(((t,r)=>_t(e.post(xt(rt,n),{externalId:t,URI:r,crossDevice:!0}))))})),{}),signUpOrIn:Object.keys(Ut).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:Yt(((t,r)=>_t(e.post(xt(at,n),{externalId:t,URI:r,crossDevice:!0}))))})),{}),signUp:Object.keys(Ut).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:Yt(((t,r,o)=>_t(e.post(xt(ot,n),{externalId:t,URI:r,user:o,crossDevice:!0}))))})),{}),waitForSession:te(((n,r)=>new Promise((o=>{const{pollingIntervalMs:i,timeoutMs:s}=(({pollingIntervalMs:t=1e3,timeoutMs:e=6e5}={})=>({pollingIntervalMs:Math.max(t||1e3,1e3),timeoutMs:Math.min(e||6e5,6e5)}))(r);let a;const c=setInterval((()=>t(void 0,void 0,void 0,(function*(){const t=yield e.post(it,{pendingRef:n});t.ok&&(clearInterval(c),a&&clearTimeout(a),o(_t(Promise.resolve(t))))}))),i);a=setTimeout((()=>{o({error:{message:`Session polling timeout exceeded: ${s}ms`,code:"0"},ok:!1}),clearInterval(c)}),s)})))),update:{email:ne(((t,n,r,o)=>_t(e.post(st.email,{externalId:t,email:n,URI:r,crossDevice:!0},{token:o})))),phone:Object.keys(Et).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:ee(((t,r,o,i)=>_t(e.post(xt(st.phone,n),{externalId:t,phone:r,URI:o,crossDevice:!0},{token:i}))))})),{})}}),oe=t=>({verify:Xt((e=>_t(t.post(nt,{token:e})))),signIn:Object.keys(Ut).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:Yt(((e,r)=>_t(t.post(xt(rt,n),{externalId:e,URI:r}))))})),{}),signUp:Object.keys(Ut).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:Yt(((e,r,o)=>_t(t.post(xt(ot,n),{externalId:e,URI:r,user:o}))))})),{}),signUpOrIn:Object.keys(Ut).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:Yt(((e,r)=>_t(t.post(xt(at,n),{externalId:e,URI:r}))))})),{}),update:{email:ne(((e,n,r,o)=>_t(t.post(st.email,{externalId:e,email:n,URI:r},{token:o})))),phone:Object.keys(Et).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:ee(((e,r,o,i)=>_t(t.post(xt(st.phone,n),{externalId:e,phone:r,URI:o},{token:i}))))})),{})},crossDevice:re(t)}),ie=Nt(Wt("code")),se=t=>({exchange:ie((e=>_t(t.get("/v1/auth/exchange",{queryParams:{code:e}}))))});var ae;!function(t){t.facebook="facebook",t.github="github",t.google="google",t.microsoft="microsoft",t.gitlab="gitlab",t.apple="apple"}(ae||(ae={}));const ce=e=>Object.assign({start:Object.keys(ae).reduce(((n,r)=>Object.assign(Object.assign({},n),{[r]:(n,{redirect:o=!1}={})=>t(void 0,void 0,void 0,(function*(){const t=yield e.get(ct,{queryParams:Object.assign({provider:r},n&&{redirectURL:n})});if(!o||!t.ok)return _t(Promise.resolve(t));const{url:i}=yield t.json();window.location.href=i}))})),{})},se(e)),de=Nt(Wt("flowId")),ue=Nt(Wt("executionId"),Wt("stepId"),Wt("actionId")),le=t=>({start:de((e=>_t(t.post(gt,{flowId:e})))),next:ue(((e,n,r,o)=>_t(t.post(bt,{executionId:e,stepId:n,actionId:r,input:o}))))}),he=Nt(Wt("tenant")),pe=e=>Object.assign({start:he(((n,r,{redirect:o=!1}={})=>t(void 0,void 0,void 0,(function*(){const t=yield e.get(dt,{queryParams:{tenant:n,redirectURL:r}});if(!o||!t.ok)return _t(Promise.resolve(t));const{url:i}=yield t.json();window.location.href=i}))))},se(e)),fe=Wt("identifier"),ve=Nt(fe,Wt("code")),ge=Nt(fe),be=Nt(fe),me=t=>({signUp:ge(((e,n)=>_t(t.post(lt,{externalId:e,user:n})))),verify:ve(((e,n)=>_t(t.post(ut,{externalId:e,code:n})))),update:be(((e,n)=>_t(t.post(ht,{externalId:e},{token:n}))))}),ye=Wt("identifier"),we=Wt("origin"),Ie=Nt(ye,we,Wt("name")),je=Nt(ye,we),ke=Nt(ye,we,Wt("token")),Oe=Nt(Wt("transactionId"),Wt("response")),xe=t=>({signUp:{start:Ie(((e,n,r)=>_t(t.post(pt.start,{user:{externalId:e,name:r},origin:n})))),finish:Oe(((e,n)=>_t(t.post(pt.finish,{transactionId:e,response:n}))))},signIn:{start:je(((e,n)=>_t(t.post(ft.start,{externalId:e,origin:n})))),finish:Oe(((e,n)=>_t(t.post(ft.finish,{transactionId:e,response:n}))))},add:{start:ke(((e,n,r)=>_t(t.post(vt.start,{externalId:e,origin:n},{token:r})))),finish:Oe(((e,n)=>_t(t.post(vt.finish,{transactionId:e,response:n}))))}}),_e=Nt(Wt("token"));var Ee;const Ue=Nt([("projectId",Ee=Wt("projectId"),Pt(((t,e)=>t=>Tt(...e).validate(Q(t,"projectId")))(0,Ee))())])((({projectId:t,logger:e,baseUrl:n})=>{return r=kt({baseUrl:n||"https://api.descope.com",projectId:t,logger:e}),{otp:Kt(r),magicLink:oe(r),oauth:ce(r),saml:pe(r),totp:me(r),webauthn:xe(r),flow:le(r),refresh:t=>_t(r.get("/v1/auth/refresh",{token:t})),logout:t=>_t(r.get("/v1/auth/logoutall",{token:t})),isJwtExpired:_e(Ot),httpClient:r};var r}));Ue.DeliveryMethods=Ut;const Se="descope-login-flow",Pe="code",Te="redirect",Re="poll";function Me(t){return new URLSearchParams(window.location.search).get(t)}function Ae(){return Me(Se)}function $e(t){if(window.history.replaceState&&Me(t)){const e=new URL(window.location.href),n=new URLSearchParams(e.search);n.delete(t),e.search=n.toString(),window.history.replaceState({},"",e.toString())}}var Ce;function Le(t){const e=`/${t}.html`,n=new URL("https://s3.eu-central-1.amazonaws.com/static.sandbox.descope.com/pages");return n.pathname+=e,n.toString()}function qe(t,e){if(!Number.isNaN(t)&&!Number.isNaN(e))return t>e?Ce.forward:t<e?Ce.backward:void 0}!function(t){t.backward="backward",t.forward="forward"}(Ce||(Ce={}));const Ne=()=>{const[t="",e=""]=(Ae()||"").split("_");return{executionId:t,stepId:e}},We=(t,e)=>{!function(t){if(window.history.pushState&&t!==Ae()){const e=new URL(window.location.href),n=new URLSearchParams(e.search);n.set(Se,t),e.search=n.toString(),window.history.pushState({},"",e.toString())}}([t,e].join("_"))};const De=(t,e,n="")=>{const r=t.getElementById(e);r&&(r.innerText=n,r.classList[n?"remove":"add"]("hide"))};var ze,He,Fe,Be,Je,Ze,Ge,Ke,Qe,Ve,Xe,Ye,tn,en,nn,rn,on,sn,an,cn,dn,un,ln,hn;class pn{constructor(t={}){ze.set(this,void 0),He.set(this,{}),Fe.set(this,0),n(this,ze,t,"f")}get current(){return Object.assign({},e(this,ze,"f"))}update(t){const r="function"==typeof t?t(e(this,ze,"f")):t,o=Object.assign(Object.assign({},e(this,ze,"f")),r);if(!function(t,e){const n=Object.getOwnPropertyNames(t),r=Object.getOwnPropertyNames(e);if(n.length!==r.length)return!1;for(let r=0;r<n.length;r+=1){const o=n[r];if(t[o]!==e[o])return!1}return!0}(e(this,ze,"f"),o)){const t=e(this,ze,"f");n(this,ze,o,"f"),Object.freeze(e(this,ze,"f")),setTimeout((()=>{Object.values(e(this,He,"f")).forEach((e=>e(o,t,((t,e)=>n=>t[n]!==e[n])(o,t))))}),0)}}subscribe(t){return n(this,Fe,e(this,Fe,"f")+1,"f"),e(this,He,"f")[e(this,Fe,"f")]=t,e(this,Fe,"f").toString()}unsubscribe(t){const n=!!e(this,He,"f")[t];return n&&delete e(this,He,"f")[t],n}unsubscribeAll(){return n(this,He,{},"f"),!0}}ze=new WeakMap,He=new WeakMap,Fe=new WeakMap,function(t){t.waiting="waiting",t.completed="completed",t.failed="failed",t.running="running"}(Be||(Be={}));const fn=document.createElement("template");fn.innerHTML="\n\t<style>\n\t\t:host {\n\t\t\tdisplay: inline-block;\n\t\t\twidth: 100%;\n\t\t\theight: 100%;\n\t\t}\n\t\t\n\t\tform {\n\t\t\theight: 100%;\n\t\t\ttransition: opacity 300ms ease-in-out;\n\t\t}\n\n\t\t.fade-out {\n\t\t\topacity: 0.1;\n\t\t}\n\n\t</style>\n\t<form></form>\n\t";class vn extends HTMLElement{constructor(){super(),Je.add(this),Ze.set(this,!1),Ge.set(this,new pn),Ke.set(this,new pn),Qe.set(this,void 0),Ve.set(this,void 0),Xe.set(this,void 0),Ye.set(this,{popstate:e(this,Je,"m",rn).bind(this)}),tn.set(this,void 0),cn.set(this,(t=>{var n,r;if(e(this,Je,"m",sn).call(this,t))return;const{executionId:o,stepId:i,status:s,action:a,screen:c,redirect:d,authInfo:u,error:l}=t.data;e(this,Je,"m",on).call(this,s,l,u)||e(this,Ge,"f").update({stepId:i,executionId:o,action:a,redirectUrl:null==d?void 0:d.url,screenId:null==c?void 0:c.id,screenErrorText:null===(n=null==c?void 0:c.state)||void 0===n?void 0:n.errorText,screenMessageText:null===(r=null==c?void 0:c.state)||void 0===r?void 0:r.messageText})})),e(this,Je,"m",en).call(this),e(this,Ge,"f").subscribe(e(this,Je,"m",an).bind(this)),e(this,Ke,"f").subscribe(e(this,Je,"m",un).bind(this))}static get observedAttributes(){return["project-id","flow-id","base-url"]}get"project-id"(){return this.getAttribute("project-id")}get"flow-id"(){return this.getAttribute("flow-id")}get"base-url"(){return this.getAttribute("base-url")||void 0}connectedCallback(){if(this.shadowRoot.isConnected){n(this,Ze,!0,"f"),e(this,Je,"m",nn).call(this);const{executionId:t,stepId:r}=Ne(),o=Me("t")||void 0;o&&$e("t");const i=Me(Pe)||void 0;i&&$e(Pe),e(this,Ge,"f").update({projectId:this["project-id"],flowId:this["flow-id"],baseUrl:this["base-url"],stepId:r,executionId:t,token:o,code:i}),window.addEventListener("popstate",e(this,Ye,"f").popstate)}}disconnectedCallback(){e(this,Ge,"f").unsubscribeAll(),e(this,Ke,"f").unsubscribeAll(),window.removeEventListener("popstate",e(this,Ye,"f").popstate)}attributeChangedCallback(t,n,r){if(this.shadowRoot.isConnected&&e(this,Ze,"f")&&n!==r&&vn.observedAttributes.includes(t)){e(this,Je,"m",nn).call(this);const o=null===n;e(this,Ge,"f").update((({stepId:e,executionId:n})=>{let i=e,s=n;return o||(s=null,i=null,$e(Se)),{[(a=t,a.replace(/-./g,(t=>t[1].toUpperCase())))]:r,stepId:i,executionId:s};var a}))}}}Ze=new WeakMap,Ge=new WeakMap,Ke=new WeakMap,Qe=new WeakMap,Ve=new WeakMap,Xe=new WeakMap,Ye=new WeakMap,tn=new WeakMap,cn=new WeakMap,Je=new WeakSet,en=function(){this.attachShadow({mode:"open"}),this.shadowRoot.appendChild(fn.content.cloneNode(!0)),n(this,Qe,this.shadowRoot.querySelector("form"),"f"),n(this,Ve,this.shadowRoot.querySelector("style"),"f")},nn=function(){const t=["base-url"];vn.observedAttributes.forEach((e=>{if(!t.includes(e)&&!this[e])throw Error(`${e} cannot be empty`)}))},rn=function(){const{stepId:t,executionId:n}=Ne();e(this,Ge,"f").update({stepId:t,executionId:n})},on=function(t,n,r){switch(t){case Be.failed:return e(this,Je,"m",hn).call(this,"error",n),!0;case Be.completed:return e(this,Je,"m",hn).call(this,"success",r),!0;default:return!1}},sn=function({ok:t,error:n}){return t||e(this,Je,"m",hn).call(this,"error",n),!t},an=function(r,o,i){return t(this,void 0,void 0,(function*(){const{projectId:s,flowId:a,baseUrl:c,stepId:d,executionId:u,action:l,screenId:h,screenErrorText:p,screenMessageText:f,redirectUrl:v,token:g,code:b}=r,m=i("projectId")||i("baseUrl");if(e(this,Xe,"f")&&(clearInterval(e(this,Xe,"f")),n(this,Xe,null,"f")),m){if(!s)return;n(this,tn,Ue({projectId:s,baseUrl:c}),"f")}if(!u){if(!a)return;const t=yield e(this,tn,"f").flow.start(a);return void e(this,cn,"f").call(this,t)}if(i("token")&&g||i("code")&&b){const t=yield e(this,tn,"f").flow.next(u,d,"submit",{token:g,code:b});return e(this,cn,"f").call(this,t),We(t.data.executionId,t.data.stepId),void e(this,Ge,"f").update({token:void 0,code:void 0})}if(l===Te)return v?void window.location.assign(v):void console.error("Did not get redirect url");if(l===Re&&n(this,Xe,setInterval((()=>t(this,void 0,void 0,(function*(){const t=yield e(this,tn,"f").flow.next(u,d,"submit",{});e(this,cn,"f").call(this,t)}))),2e3),"f"),!h)return void console.error("Refreshing the page during a flow is not supported yet");const y={direction:qe(+d,+o.stepId),screenErrorText:p,screenMessageText:f,htmlUrl:Le(h)};(m||i("executionId")||i("stepId"))&&(y.next=(...t)=>e(this,tn,"f").flow.next(u,d,...t)),e(this,Ke,"f").update(y)}))},dn=function(n){this.shadowRoot.querySelectorAll('button[type="button"]').forEach((r=>{const o=(t=>Array.from(t.attributes).reduce(((t,e)=>{var n;const r=null===(n=new RegExp("^data-descope-(\\S+)$").exec(e.name))||void 0===n?void 0:n[1];return r?Object.assign(t,{[r]:e.value}):t}),{}))(r),{action:i}=o,s=function(t,e){var n={};for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&e.indexOf(r)<0&&(n[r]=t[r]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(r=Object.getOwnPropertySymbols(t);o<r.length;o++)e.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(t,r[o])&&(n[r[o]]=t[r[o]])}return n}(o,["action"]);r.onclick=()=>t(this,void 0,void 0,(function*(){const t=yield n(i,s);e(this,cn,"f").call(this,t),We(t.data.executionId,t.data.stepId)}))})),e(this,Qe,"f").onsubmit=r=>t(this,void 0,void 0,(function*(){r.preventDefault();const t=Object.fromEntries(new FormData(r.target).entries()),o=yield n("submit",t);e(this,cn,"f").call(this,o),We(o.data.executionId,o.data.stepId)}))},un=function(n,r,o){return t(this,void 0,void 0,(function*(){const r="error",i="info",{htmlUrl:s,validations:a={},direction:c,next:d,screenErrorText:u,screenMessageText:l}=n;if(!o("htmlUrl"))return o("next")&&e(this,Je,"m",dn).call(this,d),o("screenErrorText")&&De(this.shadowRoot,r,u),void(o("screenMessageText")&&De(this.shadowRoot,i,l));const h=document.createElement("template");h.innerHTML=yield function(e){return t(this,void 0,void 0,(function*(){const t=yield fetch(e,{cache:"default"});if(!t.ok)throw new Error(e);return t.text()}))}(s);const p=h.content.cloneNode(!0),f=(t=>{var e;const n=Array.from(t.querySelectorAll("script[data-id]")).map((e=>{var n;const r=e.getAttribute("data-id"),o=null===(n=t.getElementById(r))||void 0===n?void 0:n.innerHTML,i=Function(o).bind(e.previousSibling);return e.remove(),i}));return null===(e=t.querySelector("scripts"))||void 0===e||e.remove(),n})(p),v=()=>{!function(t,e){Object.entries(e).forEach((([e,n])=>{const r=t.getElementById(e);if(!r)throw new Error(`Cannot find element with id: ${e}`);Object.entries(n).forEach((([t,e])=>{r.setAttribute(t,e.toString()),r.addEventListener("blur",(()=>r.classList.add("touched")),{once:!0})}))}))}(p,a),De(p,r,u),De(p,i,l);try{f.forEach((t=>t()))}catch(t){console.error(t)}e(this,Qe,"f").replaceChildren(p),e(this,Je,"m",dn).call(this,d),e(this,Je,"m",hn).call(this,"page-updated",{})};c?e(this,Je,"m",ln).call(this,v,c):v()}))},ln=function(t,n){e(this,Qe,"f").addEventListener("transitionend",(()=>{e(this,Qe,"f").classList.remove("fade-out"),t()}),{once:!0});const r=n===Ce.forward?"slide-forward":"slide-backward";Array.from(e(this,Qe,"f").getElementsByClassName("input-container")).forEach(((t,e)=>{t.style["transition-delay"]=40*e+"ms",t.classList.add(r)})),e(this,Qe,"f").classList.add("fade-out")},hn=function(t,e){this.dispatchEvent(new CustomEvent(t,{detail:e}))},customElements.define("descope-wc",vn)}();
|
package/package.json
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@descope/web-component",
|
|
3
|
+
"version": "0.0.25",
|
|
4
|
+
"main": "dist/descope-wc",
|
|
5
|
+
"types": "dist/descope-wc.d.ts",
|
|
6
|
+
"description": "Descope WC",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"start": "rollup -c rollup.config.app.js -w",
|
|
9
|
+
"build": "rollup -c",
|
|
10
|
+
"test": "jest",
|
|
11
|
+
"lint": "eslint ./src --fix",
|
|
12
|
+
"format": "prettier ./src --write",
|
|
13
|
+
"prepublishOnly": "npm run build"
|
|
14
|
+
},
|
|
15
|
+
"license": "ISC",
|
|
16
|
+
"repository": {
|
|
17
|
+
"type": "git",
|
|
18
|
+
"url": "https://github.com/descope/web-component.git"
|
|
19
|
+
},
|
|
20
|
+
"files": [
|
|
21
|
+
"dist"
|
|
22
|
+
],
|
|
23
|
+
"devDependencies": {
|
|
24
|
+
"@open-wc/rollup-plugin-html": "1.2.5",
|
|
25
|
+
"@rollup/plugin-commonjs": "^22.0.0",
|
|
26
|
+
"@rollup/plugin-node-resolve": "^13.3.0",
|
|
27
|
+
"@rollup/plugin-replace": "^4.0.0",
|
|
28
|
+
"@rollup/plugin-typescript": "^8.3.0",
|
|
29
|
+
"@types/jest": "^28.0.0",
|
|
30
|
+
"@types/lodash.get": "^4.4.7",
|
|
31
|
+
"@types/lodash.set": "^4.3.7",
|
|
32
|
+
"eslint": "8.22.0",
|
|
33
|
+
"eslint-config-airbnb": "19.0.4",
|
|
34
|
+
"eslint-config-airbnb-typescript": "17.0.0",
|
|
35
|
+
"eslint-config-prettier": "8.5.0",
|
|
36
|
+
"eslint-config-standard": "17.0.0",
|
|
37
|
+
"eslint-import-resolver-typescript": "3.4.0",
|
|
38
|
+
"eslint-plugin-import": "2.26.0",
|
|
39
|
+
"eslint-plugin-jest": "26.8.2",
|
|
40
|
+
"eslint-plugin-jest-dom": "4.0.2",
|
|
41
|
+
"eslint-plugin-jest-formatting": "3.1.0",
|
|
42
|
+
"eslint-plugin-n": "15.2.4",
|
|
43
|
+
"eslint-plugin-no-only-tests": "3.0.0",
|
|
44
|
+
"eslint-plugin-prefer-arrow": "1.2.3",
|
|
45
|
+
"eslint-plugin-prettier": "4.2.1",
|
|
46
|
+
"eslint-plugin-promise": "6.0.0",
|
|
47
|
+
"husky": "^8.0.1",
|
|
48
|
+
"jest": "^28.0.0",
|
|
49
|
+
"jest-environment-jsdom": "^28.1.1",
|
|
50
|
+
"prettier": "^2.6.2",
|
|
51
|
+
"rollup": "^2.62.0",
|
|
52
|
+
"rollup-plugin-browsersync": "^1.3.3",
|
|
53
|
+
"rollup-plugin-delete": "^2.0.0",
|
|
54
|
+
"rollup-plugin-dts": "^4.2.2",
|
|
55
|
+
"rollup-plugin-livereload": "^2.0.5",
|
|
56
|
+
"rollup-plugin-terser": "7.0.2",
|
|
57
|
+
"ts-jest": "^28.0.0",
|
|
58
|
+
"ts-node": "10.9.1",
|
|
59
|
+
"typescript": "^4.5.3"
|
|
60
|
+
},
|
|
61
|
+
"dependencies": {
|
|
62
|
+
"@descope/core-js-sdk": "^0.0.41-alpha.9"
|
|
63
|
+
},
|
|
64
|
+
"overrides": {
|
|
65
|
+
"terser": "5.14.2"
|
|
66
|
+
}
|
|
67
|
+
}
|