@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 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 initiated:', data);
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
@@ -213,7 +213,7 @@ declare type DepositCompletedPayload = {
213
213
  /** Network identifier (e.g., 'bitcoin', 'ethereum') */
214
214
  networkId: string;
215
215
  /** Amount being deposited */
216
- amount: string;
216
+ amount?: string;
217
217
  };
218
218
  };
219
219
 
package/dist/index.js CHANGED
@@ -1,17 +1,14 @@
1
- var c = Object.defineProperty;
2
- var h = (i, e, t) => e in i ? c(i, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : i[e] = t;
3
- var n = (i, e, t) => h(i, typeof e != "symbol" ? e + "" : e, t);
4
- const o = "production", l = "JWT token is required and must be a string.";
5
- class p {
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(l);
8
+ throw new Error(d);
12
9
  this.config = {
13
10
  ...e,
14
- env: e.env || o,
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 t = this.createWebComponent();
36
- e.innerHTML = "", e.appendChild(t), this.state.container = e, this.state.element = t, this.state.initialized = !0;
37
- } catch (t) {
38
- throw console.error("Failed to render widget:", t), t;
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 t = this.state.element;
50
- Object.entries(e).forEach(([r, s]) => {
51
- s && (this.config[r] = s, t[r] = s);
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 || o;
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, t) => {
94
- const r = document.createElement("script");
95
- r.id = this.getScriptId(), r.src = this.getScriptUrl(), r.type = "module", r.async = !0, r.onload = () => {
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() : t(new Error(this.errorMessages.WEB_COMPONENT_NOT_DEFINED));
94
+ this.getWebComponent() ? e() : r(new Error(this.errorMessages.WEB_COMPONENT_NOT_DEFINED));
98
95
  }, 0);
99
- }, r.onerror = () => {
100
- this.scriptLoadingPromise = void 0, t(new Error(`${this.errorMessages.SCRIPT_LOAD_FAILED} (${this.getEnvironment()})`));
101
- }, document.head.appendChild(r);
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((t, r) => {
114
- const s = setTimeout(() => {
115
- r(new Error(`Timeout waiting for ${this.webComponentTag} to be defined`));
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(s), t();
119
- }).catch((d) => {
120
- clearTimeout(s), r(d);
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(([t, r]) => {
138
- r && (e[t] = r);
134
+ return Object.entries(this.config).forEach(([r, t]) => {
135
+ t && (e[r] = t);
139
136
  }), e;
140
137
  }
141
138
  }
142
- var a;
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
- })(a || (a = {}));
146
- class u extends p {
147
- constructor() {
148
- super(...arguments);
149
- n(this, "errorMessages", {
150
- ALREADY_RENDERED: "Auth widget is already rendered. Call destroy() before rendering again.",
151
- NOT_RENDERED: "Auth widget is not rendered. Call render() first.",
152
- INVALID_CONTAINER: "Invalid container element provided.",
153
- SCRIPT_LOAD_FAILED: "Failed to load the Connect Auth script.",
154
- WEB_COMPONENT_NOT_DEFINED: "Web component is not defined. Script may not be loaded."
155
- });
156
- n(this, "scriptUrls", {
157
- sandbox: "https://sdk.sandbox.connect.xyz/auth-web/index.js",
158
- production: "https://sdk.connect.xyz/auth-web/index.js"
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(t) {
168
- return super.render(t);
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(t) {
175
- return super.updateConfig(t);
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
- u as Auth,
200
- a as ErrorCode,
201
- u as default
193
+ h as Auth,
194
+ o as ErrorCode,
195
+ h as default
202
196
  };
@@ -1 +1 @@
1
- (function(i,n){typeof exports=="object"&&typeof module<"u"?n(exports):typeof define=="function"&&define.amd?define(["exports"],n):(i=typeof globalThis<"u"?globalThis:i||self,n(i.Auth={}))})(this,function(i){"use strict";var l=Object.defineProperty;var m=(i,n,a)=>n in i?l(i,n,{enumerable:!0,configurable:!0,writable:!0,value:a}):i[n]=a;var o=(i,n,a)=>m(i,typeof n!="symbol"?n+"":n,a);const n="production",a="JWT token is required and must be a string.";class c{constructor(e){o(this,"config");o(this,"state");o(this,"scriptLoadingPromise");if(!e.jwt||typeof e.jwt!="string")throw new Error(a);this.config={...e,env:e.env||n,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 t=this.createWebComponent();e.innerHTML="",e.appendChild(t),this.state.container=e,this.state.element=t,this.state.initialized=!0}catch(t){throw console.error("Failed to render widget:",t),t}}updateConfig(e){if(!this.state.initialized||!this.state.element)throw new Error(this.errorMessages.NOT_RENDERED);const t=this.state.element;Object.entries(e).forEach(([r,d])=>{d&&(this.config[r]=d,t[r]=d)})}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||n}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,t)=>{const r=document.createElement("script");r.id=this.getScriptId(),r.src=this.getScriptUrl(),r.type="module",r.async=!0,r.onload=()=>{setTimeout(()=>{this.getWebComponent()?e():t(new Error(this.errorMessages.WEB_COMPONENT_NOT_DEFINED))},0)},r.onerror=()=>{this.scriptLoadingPromise=void 0,t(new Error(`${this.errorMessages.SCRIPT_LOAD_FAILED} (${this.getEnvironment()})`))},document.head.appendChild(r)});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((t,r)=>{const d=setTimeout(()=>{r(new Error(`Timeout waiting for ${this.webComponentTag} to be defined`))},e);customElements.whenDefined(this.webComponentTag).then(()=>{clearTimeout(d),t()}).catch(u=>{clearTimeout(d),r(u)})})}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(([t,r])=>{r&&(e[t]=r)}),e}}i.ErrorCode=void 0,function(s){s.NETWORK_ERROR="network_error",s.AUTH_ERROR="auth_error",s.NOT_FOUND_ERROR="not_found_error",s.VALIDATION_ERROR="validation_error",s.SERVER_ERROR="server_error",s.CLIENT_ERROR="client_error",s.UNKNOWN_ERROR="unknown_error"}(i.ErrorCode||(i.ErrorCode={}));class h extends c{constructor(){super(...arguments);o(this,"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."});o(this,"scriptUrls",{sandbox:"https://sdk.sandbox.connect.xyz/auth-web/index.js",production:"https://sdk.connect.xyz/auth-web/index.js"});o(this,"webComponentTag","connect-auth")}render(t){return super.render(t)}updateConfig(t){return super.updateConfig(t)}getConfig(){return super.getConfig()}isRendered(){return super.isRendered()}destroy(){return super.destroy()}}i.Auth=h,i.default=h,Object.defineProperties(i,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
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"}})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@connect-xyz/auth-js",
3
- "version": "1.3.0",
3
+ "version": "1.19.0",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",