@connect-xyz/auth-js 1.3.0 → 1.19.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +52 -58
- package/dist/index.umd.cjs +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -64,7 +64,7 @@ const auth = new Auth({
|
|
|
64
64
|
console.log('Auth widget closed');
|
|
65
65
|
},
|
|
66
66
|
onDeposit: ({ data }) => {
|
|
67
|
-
console.log('Deposit
|
|
67
|
+
console.log('Deposit completed:', data);
|
|
68
68
|
},
|
|
69
69
|
onEvent: ({ type, data }) => {
|
|
70
70
|
console.log('Event received:', type, data);
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,17 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
const s = "production", d = "JWT token is required and must be a string.";
|
|
2
|
+
class c {
|
|
3
|
+
config;
|
|
4
|
+
state;
|
|
5
|
+
scriptLoadingPromise;
|
|
6
6
|
constructor(e) {
|
|
7
|
-
n(this, "config");
|
|
8
|
-
n(this, "state");
|
|
9
|
-
n(this, "scriptLoadingPromise");
|
|
10
7
|
if (!e.jwt || typeof e.jwt != "string")
|
|
11
|
-
throw new Error(
|
|
8
|
+
throw new Error(d);
|
|
12
9
|
this.config = {
|
|
13
10
|
...e,
|
|
14
|
-
env: e.env ||
|
|
11
|
+
env: e.env || s,
|
|
15
12
|
theme: e.theme
|
|
16
13
|
}, this.state = {
|
|
17
14
|
initialized: !1,
|
|
@@ -32,10 +29,10 @@ class p {
|
|
|
32
29
|
throw new Error(this.errorMessages.ALREADY_RENDERED);
|
|
33
30
|
try {
|
|
34
31
|
await this.ensureScriptLoaded();
|
|
35
|
-
const
|
|
36
|
-
e.innerHTML = "", e.appendChild(
|
|
37
|
-
} catch (
|
|
38
|
-
throw console.error("Failed to render widget:",
|
|
32
|
+
const r = this.createWebComponent();
|
|
33
|
+
e.innerHTML = "", e.appendChild(r), this.state.container = e, this.state.element = r, this.state.initialized = !0;
|
|
34
|
+
} catch (r) {
|
|
35
|
+
throw console.error("Failed to render widget:", r), r;
|
|
39
36
|
}
|
|
40
37
|
}
|
|
41
38
|
/**
|
|
@@ -46,9 +43,9 @@ class p {
|
|
|
46
43
|
updateConfig(e) {
|
|
47
44
|
if (!this.state.initialized || !this.state.element)
|
|
48
45
|
throw new Error(this.errorMessages.NOT_RENDERED);
|
|
49
|
-
const
|
|
50
|
-
Object.entries(e).forEach(([
|
|
51
|
-
|
|
46
|
+
const r = this.state.element;
|
|
47
|
+
Object.entries(e).forEach(([t, n]) => {
|
|
48
|
+
n && (this.config[t] = n, r[t] = n);
|
|
52
49
|
});
|
|
53
50
|
}
|
|
54
51
|
/**
|
|
@@ -72,7 +69,7 @@ class p {
|
|
|
72
69
|
return { ...this.config };
|
|
73
70
|
}
|
|
74
71
|
getEnvironment() {
|
|
75
|
-
return this.config.env ||
|
|
72
|
+
return this.config.env || s;
|
|
76
73
|
}
|
|
77
74
|
getScriptId() {
|
|
78
75
|
return `${this.webComponentTag}-script-${this.getEnvironment()}`;
|
|
@@ -90,15 +87,15 @@ class p {
|
|
|
90
87
|
if (!this.isScriptLoaded()) {
|
|
91
88
|
if (this.scriptLoadingPromise)
|
|
92
89
|
return this.scriptLoadingPromise;
|
|
93
|
-
this.scriptLoadingPromise = new Promise((e,
|
|
94
|
-
const
|
|
95
|
-
|
|
90
|
+
this.scriptLoadingPromise = new Promise((e, r) => {
|
|
91
|
+
const t = document.createElement("script");
|
|
92
|
+
t.id = this.getScriptId(), t.src = this.getScriptUrl(), t.type = "module", t.async = !0, t.onload = () => {
|
|
96
93
|
setTimeout(() => {
|
|
97
|
-
this.getWebComponent() ? e() :
|
|
94
|
+
this.getWebComponent() ? e() : r(new Error(this.errorMessages.WEB_COMPONENT_NOT_DEFINED));
|
|
98
95
|
}, 0);
|
|
99
|
-
},
|
|
100
|
-
this.scriptLoadingPromise = void 0,
|
|
101
|
-
}, document.head.appendChild(
|
|
96
|
+
}, t.onerror = () => {
|
|
97
|
+
this.scriptLoadingPromise = void 0, r(new Error(`${this.errorMessages.SCRIPT_LOAD_FAILED} (${this.getEnvironment()})`));
|
|
98
|
+
}, document.head.appendChild(t);
|
|
102
99
|
});
|
|
103
100
|
try {
|
|
104
101
|
await this.scriptLoadingPromise;
|
|
@@ -110,14 +107,14 @@ class p {
|
|
|
110
107
|
}
|
|
111
108
|
async waitForWebComponent(e = 5e3) {
|
|
112
109
|
if (!this.getWebComponent())
|
|
113
|
-
return new Promise((
|
|
114
|
-
const
|
|
115
|
-
|
|
110
|
+
return new Promise((r, t) => {
|
|
111
|
+
const n = setTimeout(() => {
|
|
112
|
+
t(new Error(`Timeout waiting for ${this.webComponentTag} to be defined`));
|
|
116
113
|
}, e);
|
|
117
114
|
customElements.whenDefined(this.webComponentTag).then(() => {
|
|
118
|
-
clearTimeout(
|
|
119
|
-
}).catch((
|
|
120
|
-
clearTimeout(
|
|
115
|
+
clearTimeout(n), r();
|
|
116
|
+
}).catch((a) => {
|
|
117
|
+
clearTimeout(n), t(a);
|
|
121
118
|
});
|
|
122
119
|
});
|
|
123
120
|
}
|
|
@@ -134,45 +131,42 @@ class p {
|
|
|
134
131
|
}
|
|
135
132
|
createWebComponent() {
|
|
136
133
|
const e = document.createElement(this.webComponentTag);
|
|
137
|
-
return Object.entries(this.config).forEach(([
|
|
138
|
-
|
|
134
|
+
return Object.entries(this.config).forEach(([r, t]) => {
|
|
135
|
+
t && (e[r] = t);
|
|
139
136
|
}), e;
|
|
140
137
|
}
|
|
141
138
|
}
|
|
142
|
-
var
|
|
139
|
+
var o;
|
|
143
140
|
(function(i) {
|
|
144
141
|
i.NETWORK_ERROR = "network_error", i.AUTH_ERROR = "auth_error", i.NOT_FOUND_ERROR = "not_found_error", i.VALIDATION_ERROR = "validation_error", i.SERVER_ERROR = "server_error", i.CLIENT_ERROR = "client_error", i.UNKNOWN_ERROR = "unknown_error";
|
|
145
|
-
})(
|
|
146
|
-
class
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
});
|
|
160
|
-
n(this, "webComponentTag", "connect-auth");
|
|
161
|
-
}
|
|
142
|
+
})(o || (o = {}));
|
|
143
|
+
class h extends c {
|
|
144
|
+
errorMessages = {
|
|
145
|
+
ALREADY_RENDERED: "Auth widget is already rendered. Call destroy() before rendering again.",
|
|
146
|
+
NOT_RENDERED: "Auth widget is not rendered. Call render() first.",
|
|
147
|
+
INVALID_CONTAINER: "Invalid container element provided.",
|
|
148
|
+
SCRIPT_LOAD_FAILED: "Failed to load the Connect Auth script.",
|
|
149
|
+
WEB_COMPONENT_NOT_DEFINED: "Web component is not defined. Script may not be loaded."
|
|
150
|
+
};
|
|
151
|
+
scriptUrls = {
|
|
152
|
+
sandbox: "https://sdk.sandbox.connect.xyz/auth-web/index.js",
|
|
153
|
+
production: "https://sdk.connect.xyz/auth-web/index.js"
|
|
154
|
+
};
|
|
155
|
+
webComponentTag = "connect-auth";
|
|
162
156
|
/**
|
|
163
157
|
* Render the Auth widget to a container element
|
|
164
158
|
* @param container - The container element to render the widget into
|
|
165
159
|
* @returns Promise that resolves when the widget is rendered
|
|
166
160
|
*/
|
|
167
|
-
render(
|
|
168
|
-
return super.render(
|
|
161
|
+
render(e) {
|
|
162
|
+
return super.render(e);
|
|
169
163
|
}
|
|
170
164
|
/**
|
|
171
165
|
* Update the configuration of the Auth widget
|
|
172
166
|
* @param config - Partial configuration to update
|
|
173
167
|
*/
|
|
174
|
-
updateConfig(
|
|
175
|
-
return super.updateConfig(
|
|
168
|
+
updateConfig(e) {
|
|
169
|
+
return super.updateConfig(e);
|
|
176
170
|
}
|
|
177
171
|
/**
|
|
178
172
|
* Get the current configuration
|
|
@@ -196,7 +190,7 @@ class u extends p {
|
|
|
196
190
|
}
|
|
197
191
|
}
|
|
198
192
|
export {
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
193
|
+
h as Auth,
|
|
194
|
+
o as ErrorCode,
|
|
195
|
+
h as default
|
|
202
196
|
};
|
package/dist/index.umd.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(r,s){typeof exports=="object"&&typeof module<"u"?s(exports):typeof define=="function"&&define.amd?define(["exports"],s):(r=typeof globalThis<"u"?globalThis:r||self,s(r.Auth={}))})(this,function(r){"use strict";const s="production",d="JWT token is required and must be a string.";class h{config;state;scriptLoadingPromise;constructor(e){if(!e.jwt||typeof e.jwt!="string")throw new Error(d);this.config={...e,env:e.env||s,theme:e.theme},this.state={initialized:!1,scriptLoaded:!1,container:null,element:null}}async render(e){if(!e||!(e instanceof HTMLElement))throw new Error(this.errorMessages.INVALID_CONTAINER);if(this.state.initialized)throw new Error(this.errorMessages.ALREADY_RENDERED);try{await this.ensureScriptLoaded();const i=this.createWebComponent();e.innerHTML="",e.appendChild(i),this.state.container=e,this.state.element=i,this.state.initialized=!0}catch(i){throw console.error("Failed to render widget:",i),i}}updateConfig(e){if(!this.state.initialized||!this.state.element)throw new Error(this.errorMessages.NOT_RENDERED);const i=this.state.element;Object.entries(e).forEach(([t,o])=>{o&&(this.config[t]=o,i[t]=o)})}destroy(){this.state.initialized&&(this.state.element&&this.state.element.parentNode&&this.state.element.parentNode.removeChild(this.state.element),this.state.container&&(this.state.container.innerHTML=""),this.state.container=null,this.state.element=null,this.state.initialized=!1)}isRendered(){return this.state.initialized}getConfig(){return{...this.config}}getEnvironment(){return this.config.env||s}getScriptId(){return`${this.webComponentTag}-script-${this.getEnvironment()}`}isScriptLoaded(){return!!document.getElementById(this.getScriptId())}getWebComponent(){return customElements.get(this.webComponentTag)}getScriptUrl(){return this.scriptUrls[this.getEnvironment()]}async loadScript(){if(!this.isScriptLoaded()){if(this.scriptLoadingPromise)return this.scriptLoadingPromise;this.scriptLoadingPromise=new Promise((e,i)=>{const t=document.createElement("script");t.id=this.getScriptId(),t.src=this.getScriptUrl(),t.type="module",t.async=!0,t.onload=()=>{setTimeout(()=>{this.getWebComponent()?e():i(new Error(this.errorMessages.WEB_COMPONENT_NOT_DEFINED))},0)},t.onerror=()=>{this.scriptLoadingPromise=void 0,i(new Error(`${this.errorMessages.SCRIPT_LOAD_FAILED} (${this.getEnvironment()})`))},document.head.appendChild(t)});try{await this.scriptLoadingPromise}catch(e){throw this.scriptLoadingPromise=void 0,e}return this.scriptLoadingPromise}}async waitForWebComponent(e=5e3){if(!this.getWebComponent())return new Promise((i,t)=>{const o=setTimeout(()=>{t(new Error(`Timeout waiting for ${this.webComponentTag} to be defined`))},e);customElements.whenDefined(this.webComponentTag).then(()=>{clearTimeout(o),i()}).catch(c=>{clearTimeout(o),t(c)})})}async ensureScriptLoaded(){if(!this.state.scriptLoaded)try{await this.loadScript(),await this.waitForWebComponent(),this.state.scriptLoaded=!0}catch(e){throw console.error("Failed to load Connect script:",e),e}}createWebComponent(){const e=document.createElement(this.webComponentTag);return Object.entries(this.config).forEach(([i,t])=>{t&&(e[i]=t)}),e}}r.ErrorCode=void 0,function(n){n.NETWORK_ERROR="network_error",n.AUTH_ERROR="auth_error",n.NOT_FOUND_ERROR="not_found_error",n.VALIDATION_ERROR="validation_error",n.SERVER_ERROR="server_error",n.CLIENT_ERROR="client_error",n.UNKNOWN_ERROR="unknown_error"}(r.ErrorCode||(r.ErrorCode={}));class a extends h{errorMessages={ALREADY_RENDERED:"Auth widget is already rendered. Call destroy() before rendering again.",NOT_RENDERED:"Auth widget is not rendered. Call render() first.",INVALID_CONTAINER:"Invalid container element provided.",SCRIPT_LOAD_FAILED:"Failed to load the Connect Auth script.",WEB_COMPONENT_NOT_DEFINED:"Web component is not defined. Script may not be loaded."};scriptUrls={sandbox:"https://sdk.sandbox.connect.xyz/auth-web/index.js",production:"https://sdk.connect.xyz/auth-web/index.js"};webComponentTag="connect-auth";render(e){return super.render(e)}updateConfig(e){return super.updateConfig(e)}getConfig(){return super.getConfig()}isRendered(){return super.isRendered()}destroy(){return super.destroy()}}r.Auth=a,r.default=a,Object.defineProperties(r,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|