@oila/0account 3.5.0 → 3.5.2

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.
@@ -17,7 +17,7 @@ const patchBrowser = () => {
17
17
  };
18
18
 
19
19
  patchBrowser().then(options => {
20
- return index.bootstrapLazy([["qr-code_2.cjs",[[1,"zero-account",{"appId":[1,"app-id"],"updateInterval":[2,"update-interval"],"callbackURL":[1,"callback-url"],"modal":[4],"level":[1],"primaryColor":[1,"primary-color"],"secondaryColor":[1,"secondary-color"],"environment":[1],"enableWithCredentials":[4,"enable-with-credentials"],"themePreset":[1,"theme-preset"],"autoStartApp":[4,"auto-start-app"],"modalOpen":[32],"isAnimating":[32],"url":[32]},[[4,"0account-toggle-modal","toggleModal"],[4,"0account-close-modal","_closeModal"],[4,"0account-authenticated","_closeModal"],[4,"0account-open-app","openApp"]]],[0,"qr-code",{"url":[1],"level":[1],"class":[1],"color":[1]}]]]], options);
20
+ return index.bootstrapLazy([["qr-code_2.cjs",[[1,"zero-account",{"appId":[1,"app-id"],"updateInterval":[2,"update-interval"],"callbackURL":[1,"callback-url"],"modal":[4],"level":[1],"primaryColor":[1,"primary-color"],"secondaryColor":[1,"secondary-color"],"environment":[1],"enableWithCredentials":[4,"enable-with-credentials"],"themePreset":[1,"theme-preset"],"autoStartApp":[4,"auto-start-app"],"modalOpen":[32],"isAnimating":[32],"url":[32]},[[4,"0account-toggle-modal","toggleModal"],[4,"0account-close-modal","_closeModal"],[4,"0account-authenticated","_closeModal"],[4,"0account-logout","logout"],[4,"0account-open-app","openApp"]]],[0,"qr-code",{"url":[1],"level":[1],"class":[1],"color":[1]}]]]], options);
21
21
  });
22
22
 
23
23
  exports.setNonce = index.setNonce;
@@ -101,6 +101,9 @@ export class WS {
101
101
  this.uuid = uuid;
102
102
  this.send(fromWidgetUUIDUpdated, this.deviceInfo());
103
103
  }
104
+ logout() {
105
+ this.send(fromWidgetLoggedOut, this.deviceInfo());
106
+ }
104
107
  send(action, data) {
105
108
  if (!this.socket || !this.socket.readyState || this.socket.readyState !== WebSocket.OPEN) {
106
109
  const retry = debounce(this.send.bind(this), 1000);
@@ -113,7 +116,7 @@ export class WS {
113
116
  appId: `${this.appId}`,
114
117
  message: {},
115
118
  };
116
- if (action === fromWidgetEnsureSession) {
119
+ if (action === fromWidgetEnsureSession || action === fromWidgetLoggedOut) {
117
120
  const sessionId = localStorage.getItem(`${PREFIX}_${SESSION_ID}`);
118
121
  const sessionToken = localStorage.getItem(`${PREFIX}_${SESSION_TOKEN}`);
119
122
  if (!sessionId || !sessionToken)
@@ -1 +1 @@
1
- {"version":3,"file":"websocket.js","sourceRoot":"","sources":["../../../src/components/zero-account/websocket.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AACtC,OAAO,IAAI,MAAM,qBAAqB,CAAC;AAEvC,MAAM,oBAAoB,GAAG,MAAM,CAAC,QAAQ,CAAC,MAAM,GAAG,YAAY,CAAC;AACnE,MAAM,OAAO,GAAG,0BAA0B,CAAC;AAC3C,MAAM,eAAe,GAAG,kCAAkC,CAAC;AAE3D,MAAM,MAAM,GAAG,UAAU,CAAC;AAC1B,MAAM,UAAU,GAAG,YAAY,CAAC;AAChC,MAAM,aAAa,GAAG,eAAe,CAAC;AAEtC,MAAM,qBAAqB,GAAG,0BAA0B,CAAC;AACzD,MAAM,mBAAmB,GAAG,wBAAwB,CAAC;AACrD,gFAAgF;AAChF,MAAM,uBAAuB,GAAG,4BAA4B,CAAC;AAE7D,MAAM,cAAc,GAAG,kBAAkB,CAAC;AAC1C,MAAM,gBAAgB,GAAG,oBAAoB,CAAC;AAC9C,MAAM,UAAU,GAAG,cAAc,CAAC;AAClC,eAAe;AACf,MAAM,UAAU,GAAG,iBAAiB,CAAC;AACrC,MAAM,iBAAiB,GAAG,wBAAwB,CAAC;AACnD,qEAAqE;AAErE,SAAS,QAAQ,CAAC,IAAI,EAAE,OAAO,GAAG,GAAG;IACn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;QACvC,IAAI,CAAC,aAAa,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;QAC/B,IAAI,CAAC,IAAI,CAAC,cAAc,GAAG,IAAI,EAAE,IAAI,CAAC,CAAC;IACzC,CAAC;IAEO,aAAa,CAAC,IAAY,EAAE,IAAU;QAC5C,IAAI,KAAK,GAAG,IAAI,WAAW,CAAC,IAAI,CAAC,CAAC;QAClC,IAAI,IAAI;YAAE,KAAK,GAAG,IAAI,WAAW,CAAC,IAAI,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC;QAC1D,QAAQ,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;IAChC,CAAC;CAEF","sourcesContent":["import { UAParser } from 'ua-parser-js';\nimport { Environment } from './enums';\nimport http from '../../utils/request';\n\nconst DEFAULT_CALLBACK_URL = window.location.origin + '/zero/auth';\nconst API_URL = 'wss://ws.0account.com/ws';\nconst API_URL_STAGING = 'wss://staging.ws.0account.com/ws';\n\nconst PREFIX = '0account';\nconst SESSION_ID = 'session-id';\nconst SESSION_TOKEN = 'session-token';\n\nconst fromWidgetUUIDUpdated = 'from-widget-uuid-updated';\nconst fromWidgetLoggedOut = 'from-widget-logged-out';\n// const fromWidgetAuthenticationStarted = 'from-widget-authentication-started';\nconst fromWidgetEnsureSession = 'from-widget-ensure-session';\n\nconst toWidgetLogout = 'to-widget-logout';\nconst toWidgetApproved = 'to-widget-approved';\nconst toAnyError = 'to-any-error';\n// CustomEvents\nconst zeroLogout = '0account-logout';\nconst zeroAuthenticated = '0account-authenticated';\n// const zeroAuthenticationFailed = '0account-authentication-failed';\n\nfunction debounce(func, timeout = 300) {\n let timer;\n return (...args) => {\n clearTimeout(timer);\n timer = setTimeout(() => {\n func.apply(this, args);\n }, timeout);\n };\n}\n\ntype Options = {\n callbackURL: string,\n updateInterval: number,\n enableWithCredentials: boolean,\n uaParser: UAParser,\n log: (...args) => void\n env?: Environment,\n}\n\n\nexport class WS {\n private readonly appId: string;\n private socket: WebSocket;\n private uaParser: UAParser;\n private readonly log: (...args) => void;\n private uuid: string;\n private wsURL = API_URL;\n private callbackURL = DEFAULT_CALLBACK_URL;\n private request: XMLHttpRequest;\n private readonly updateInterval: number;\n private enableWithCredentials: boolean;\n\n constructor(appId: string, opts: Options) {\n if (!opts.env) opts.env = Environment.production\n\n this.appId = appId;\n this.uaParser = opts.uaParser;\n this.callbackURL = opts.callbackURL;\n this.updateInterval = opts.updateInterval;\n this.enableWithCredentials = opts.enableWithCredentials;\n this.log = opts.log;\n if (opts.env !== Environment.production) this.wsURL = API_URL_STAGING;\n this.init();\n }\n\n private deviceInfo() {\n return {\n appId: this.appId,\n browser: this.uaParser.getBrowser().withFeatureCheck().name,\n os: this.uaParser.getOS().withFeatureCheck().name,\n // TODO: handle these on backend:\n // device: `${this.uaParser.getDevice().vendor} ${this.uaParser.getDevice().model}`,\n // all: this.uaParser.getResult()\n };\n }\n\n private reinit() {\n const retry = debounce(this.init.bind(this), 1000)\n retry()\n }\n\n private init() {\n const onopen = (_) => {\n this.send(fromWidgetEnsureSession, this.deviceInfo());\n };\n const onmessage = (event) => {\n try {\n const data = JSON.parse(event.data);\n this.handleMessage(data);\n } catch (e) {\n this.log(e);\n }\n };\n const onerror = (_) => {\n if (this.socket && (this.socket.readyState !== WebSocket.CLOSED\n && this.socket.readyState !== WebSocket.CLOSING)) {\n this.socket.close();\n }\n };\n const onclose = (_) => {\n if (this.socket) {\n this.socket.removeEventListener('open', onopen);\n this.socket.removeEventListener('message', onmessage);\n this.socket.removeEventListener('error', onerror);\n this.socket.removeEventListener('close', onclose);\n delete this.socket;\n }\n this.reinit();\n };\n\n if (this.socket) {\n this.socket.removeEventListener('open', onopen);\n this.socket.removeEventListener('message', onmessage);\n this.socket.removeEventListener('error', onerror);\n this.socket.removeEventListener('close', onclose);\n }\n this.socket = new WebSocket(this.wsURL);\n this.socket.addEventListener('open', onopen);\n this.socket.addEventListener('message', onmessage);\n this.socket.addEventListener('error', onerror);\n this.socket.addEventListener('close', onclose);\n }\n\n updateUUID(uuid: string) {\n this.uuid = uuid;\n this.send(fromWidgetUUIDUpdated, this.deviceInfo());\n }\n\n send(action, data) {\n if (!this.socket || !this.socket.readyState || this.socket.readyState !== WebSocket.OPEN) {\n const retry = debounce(this.send.bind(this), 1000)\n return retry();\n }\n\n const msg: any = {\n action: action,\n timeout: `${this.updateInterval}ms`,\n uuid: this.uuid,\n appId: `${this.appId}`,\n message: {},\n };\n if (action === fromWidgetEnsureSession) {\n const sessionId = localStorage.getItem(`${PREFIX}_${SESSION_ID}`);\n const sessionToken = localStorage.getItem(`${PREFIX}_${SESSION_TOKEN}`);\n if (!sessionId || !sessionToken) return;\n msg.sessionId = sessionId;\n msg.sessionToken = sessionToken;\n }\n\n if (data) msg.message = data;\n this.socket.send(JSON.stringify(msg));\n }\n\n onZeroAuth() {\n if (this.request) this.request.abort();\n this.request = http.send(this.callbackURL,\n {\n enableWithCredentials: this.enableWithCredentials,\n headers: {\n 'x-0account-uuid': this.uuid,\n 'x-0account-auth': 'true',\n },\n },\n (responseText) => {\n try {\n const data = JSON.parse(responseText);\n this.dispatchEventAndWsSend(zeroAuthenticated, data);\n } catch (err) {\n this.log(err);\n }\n },\n );\n }\n\n private handleMessage(msg: any) {\n switch (msg.action) {\n case toWidgetApproved:\n this.onZeroAuth();\n localStorage.setItem(`${PREFIX}_${SESSION_ID}`, msg.sessionId);\n localStorage.setItem(`${PREFIX}_${SESSION_TOKEN}`, msg.message);\n break;\n case toWidgetLogout:\n localStorage.removeItem(`${PREFIX}_${SESSION_ID}`);\n localStorage.removeItem(`${PREFIX}_${SESSION_TOKEN}`);\n this.dispatchEvent(zeroLogout);\n this.send(fromWidgetLoggedOut, this.deviceInfo());\n break;\n case toAnyError:\n this.log('ws error', msg);\n break;\n default:\n this.log('incorrect action', msg.action, msg);\n }\n }\n\n private dispatchEventAndWsSend(name, data) {\n this.dispatchEvent(name, data);\n this.send('from-widget-' + name, data);\n }\n\n private dispatchEvent(name: string, data?: any) {\n let event = new CustomEvent(name);\n if (data) event = new CustomEvent(name, { detail: data });\n document.dispatchEvent(event);\n }\n\n}\n"]}
1
+ {"version":3,"file":"websocket.js","sourceRoot":"","sources":["../../../src/components/zero-account/websocket.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AACtC,OAAO,IAAI,MAAM,qBAAqB,CAAC;AAEvC,MAAM,oBAAoB,GAAG,MAAM,CAAC,QAAQ,CAAC,MAAM,GAAG,YAAY,CAAC;AACnE,MAAM,OAAO,GAAG,0BAA0B,CAAC;AAC3C,MAAM,eAAe,GAAG,kCAAkC,CAAC;AAE3D,MAAM,MAAM,GAAG,UAAU,CAAC;AAC1B,MAAM,UAAU,GAAG,YAAY,CAAC;AAChC,MAAM,aAAa,GAAG,eAAe,CAAC;AAEtC,MAAM,qBAAqB,GAAG,0BAA0B,CAAC;AACzD,MAAM,mBAAmB,GAAG,wBAAwB,CAAC;AACrD,gFAAgF;AAChF,MAAM,uBAAuB,GAAG,4BAA4B,CAAC;AAE7D,MAAM,cAAc,GAAG,kBAAkB,CAAC;AAC1C,MAAM,gBAAgB,GAAG,oBAAoB,CAAC;AAC9C,MAAM,UAAU,GAAG,cAAc,CAAC;AAClC,eAAe;AACf,MAAM,UAAU,GAAG,iBAAiB,CAAC;AACrC,MAAM,iBAAiB,GAAG,wBAAwB,CAAC;AACnD,qEAAqE;AAErE,SAAS,QAAQ,CAAC,IAAI,EAAE,OAAO,GAAG,GAAG;IACnC,IAAI,KAAK,CAAC;IACV,OAAO,CAAC,GAAG,IAAI,EAAE,EAAE;QACjB,YAAY,CAAC,KAAK,CAAC,CAAC;QACpB,KAAK,GAAG,UAAU,CAAC,GAAG,EAAE;YACtB,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;QACzB,CAAC,EAAE,OAAO,CAAC,CAAC;IACd,CAAC,CAAC;AACJ,CAAC;AAYD,MAAM,OAAO,EAAE;IAYb,YA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AY,EAAE,IAAU;QAC5C,IAAI,KAAK,GAAG,IAAI,WAAW,CAAC,IAAI,CAAC,CAAC;QAClC,IAAI,IAAI;YAAE,KAAK,GAAG,IAAI,WAAW,CAAC,IAAI,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC;QAC1D,QAAQ,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;IAChC,CAAC;CAEF","sourcesContent":["import { UAParser } from 'ua-parser-js';\nimport { Environment } from './enums';\nimport http from '../../utils/request';\n\nconst DEFAULT_CALLBACK_URL = window.location.origin + '/zero/auth';\nconst API_URL = 'wss://ws.0account.com/ws';\nconst API_URL_STAGING = 'wss://staging.ws.0account.com/ws';\n\nconst PREFIX = '0account';\nconst SESSION_ID = 'session-id';\nconst SESSION_TOKEN = 'session-token';\n\nconst fromWidgetUUIDUpdated = 'from-widget-uuid-updated';\nconst fromWidgetLoggedOut = 'from-widget-logged-out';\n// const fromWidgetAuthenticationStarted = 'from-widget-authentication-started';\nconst fromWidgetEnsureSession = 'from-widget-ensure-session';\n\nconst toWidgetLogout = 'to-widget-logout';\nconst toWidgetApproved = 'to-widget-approved';\nconst toAnyError = 'to-any-error';\n// CustomEvents\nconst zeroLogout = '0account-logout';\nconst zeroAuthenticated = '0account-authenticated';\n// const zeroAuthenticationFailed = '0account-authentication-failed';\n\nfunction debounce(func, timeout = 300) {\n let timer;\n return (...args) => {\n clearTimeout(timer);\n timer = setTimeout(() => {\n func.apply(this, args);\n }, timeout);\n };\n}\n\ntype Options = {\n callbackURL: string,\n updateInterval: number,\n enableWithCredentials: boolean,\n uaParser: UAParser,\n log: (...args) => void\n env?: Environment,\n}\n\n\nexport class WS {\n private readonly appId: string;\n private socket: WebSocket;\n private uaParser: UAParser;\n private readonly log: (...args) => void;\n private uuid: string;\n private wsURL = API_URL;\n private callbackURL = DEFAULT_CALLBACK_URL;\n private request: XMLHttpRequest;\n private readonly updateInterval: number;\n private enableWithCredentials: boolean;\n\n constructor(appId: string, opts: Options) {\n if (!opts.env) opts.env = Environment.production\n\n this.appId = appId;\n this.uaParser = opts.uaParser;\n this.callbackURL = opts.callbackURL;\n this.updateInterval = opts.updateInterval;\n this.enableWithCredentials = opts.enableWithCredentials;\n this.log = opts.log;\n if (opts.env !== Environment.production) this.wsURL = API_URL_STAGING;\n this.init();\n }\n\n private deviceInfo() {\n return {\n appId: this.appId,\n browser: this.uaParser.getBrowser().withFeatureCheck().name,\n os: this.uaParser.getOS().withFeatureCheck().name,\n // TODO: handle these on backend:\n // device: `${this.uaParser.getDevice().vendor} ${this.uaParser.getDevice().model}`,\n // all: this.uaParser.getResult()\n };\n }\n\n private reinit() {\n const retry = debounce(this.init.bind(this), 1000)\n retry()\n }\n\n private init() {\n const onopen = (_) => {\n this.send(fromWidgetEnsureSession, this.deviceInfo());\n };\n const onmessage = (event) => {\n try {\n const data = JSON.parse(event.data);\n this.handleMessage(data);\n } catch (e) {\n this.log(e);\n }\n };\n const onerror = (_) => {\n if (this.socket && (this.socket.readyState !== WebSocket.CLOSED\n && this.socket.readyState !== WebSocket.CLOSING)) {\n this.socket.close();\n }\n };\n const onclose = (_) => {\n if (this.socket) {\n this.socket.removeEventListener('open', onopen);\n this.socket.removeEventListener('message', onmessage);\n this.socket.removeEventListener('error', onerror);\n this.socket.removeEventListener('close', onclose);\n delete this.socket;\n }\n this.reinit();\n };\n\n if (this.socket) {\n this.socket.removeEventListener('open', onopen);\n this.socket.removeEventListener('message', onmessage);\n this.socket.removeEventListener('error', onerror);\n this.socket.removeEventListener('close', onclose);\n }\n this.socket = new WebSocket(this.wsURL);\n this.socket.addEventListener('open', onopen);\n this.socket.addEventListener('message', onmessage);\n this.socket.addEventListener('error', onerror);\n this.socket.addEventListener('close', onclose);\n }\n\n updateUUID(uuid: string) {\n this.uuid = uuid;\n this.send(fromWidgetUUIDUpdated, this.deviceInfo());\n }\n\n logout() {\n this.send(fromWidgetLoggedOut, this.deviceInfo());\n }\n\n send(action, data) {\n if (!this.socket || !this.socket.readyState || this.socket.readyState !== WebSocket.OPEN) {\n const retry = debounce(this.send.bind(this), 1000)\n return retry();\n }\n\n const msg: any = {\n action: action,\n timeout: `${this.updateInterval}ms`,\n uuid: this.uuid,\n appId: `${this.appId}`,\n message: {},\n };\n if (action === fromWidgetEnsureSession || action === fromWidgetLoggedOut) {\n const sessionId = localStorage.getItem(`${PREFIX}_${SESSION_ID}`);\n const sessionToken = localStorage.getItem(`${PREFIX}_${SESSION_TOKEN}`);\n if (!sessionId || !sessionToken) return;\n msg.sessionId = sessionId;\n msg.sessionToken = sessionToken;\n }\n\n if (data) msg.message = data;\n this.socket.send(JSON.stringify(msg));\n }\n\n onZeroAuth() {\n if (this.request) this.request.abort();\n this.request = http.send(this.callbackURL,\n {\n enableWithCredentials: this.enableWithCredentials,\n headers: {\n 'x-0account-uuid': this.uuid,\n 'x-0account-auth': 'true',\n },\n },\n (responseText) => {\n try {\n const data = JSON.parse(responseText);\n this.dispatchEventAndWsSend(zeroAuthenticated, data);\n } catch (err) {\n this.log(err);\n }\n },\n );\n }\n\n private handleMessage(msg: any) {\n switch (msg.action) {\n case toWidgetApproved:\n this.onZeroAuth();\n localStorage.setItem(`${PREFIX}_${SESSION_ID}`, msg.sessionId);\n localStorage.setItem(`${PREFIX}_${SESSION_TOKEN}`, msg.message);\n break;\n case toWidgetLogout:\n localStorage.removeItem(`${PREFIX}_${SESSION_ID}`);\n localStorage.removeItem(`${PREFIX}_${SESSION_TOKEN}`);\n this.dispatchEvent(zeroLogout);\n this.send(fromWidgetLoggedOut, this.deviceInfo());\n break;\n case toAnyError:\n this.log('ws error', msg);\n break;\n default:\n this.log('incorrect action', msg.action, msg);\n }\n }\n\n private dispatchEventAndWsSend(name, data) {\n this.dispatchEvent(name, data);\n this.send('from-widget-' + name, data);\n }\n\n private dispatchEvent(name: string, data?: any) {\n let event = new CustomEvent(name);\n if (data) event = new CustomEvent(name, { detail: data });\n document.dispatchEvent(event);\n }\n\n}\n"]}
@@ -15,6 +15,8 @@
15
15
  --modal-logo-border-color: var(--primary-color);
16
16
  --modal-animation-duration: 350ms;
17
17
  --easing: cubic-bezier(0.16, 1, 0.3, 1);
18
+ --disabled-background-color: rgba(0, 0, 0, 0.12);
19
+ --disabled-color: rgba(0, 0, 0, 0.3);
18
20
  /*--easing: ease;*/
19
21
 
20
22
  font-family: sans-serif;
@@ -26,6 +28,8 @@
26
28
  --button-border-color: #FFFFF9;
27
29
  --text-color: #FFFFF9;
28
30
  --modal-logo-border-color: #CCC;
31
+ --disabled-background-color: rgba(255, 255, 255, 0.12);
32
+ --disabled-color: rgba(255, 255, 255, 0.3);
29
33
  --theme-based-radius: 4px;
30
34
  --theme-based-padding: 8px;
31
35
  }
@@ -194,6 +198,13 @@
194
198
  ) var(--primary-color);
195
199
  }
196
200
 
201
+ .modal__button:disabled {
202
+ background-color: var(--disabled-background-color);
203
+ color: var(--disabled-color);
204
+ cursor: not-allowed;
205
+ pointer-events: none;
206
+ }
207
+
197
208
  .modal__link {
198
209
  transform: scale(0) translate3d(0, 150px, 0);
199
210
  transition: calc(var(--modal-animation-duration) + 150ms) var(--easing);
@@ -13,6 +13,7 @@ const ANIMATION_DURATION = 3000;
13
13
  export class ZeroAccount {
14
14
  constructor() {
15
15
  this.refreshQR = (ignoreAnimate = false) => {
16
+ this.initServices();
16
17
  const update = () => {
17
18
  this.restartTimer();
18
19
  this.updateURL();
@@ -61,6 +62,9 @@ export class ZeroAccount {
61
62
  this.modalOpen = false;
62
63
  this.stopTimer();
63
64
  }
65
+ logout() {
66
+ this.ws.logout();
67
+ }
64
68
  closeModal(e) {
65
69
  if (e.target !== this.modalEl && e.target !== this.closeButtonEl) {
66
70
  return e.stopPropagation();
@@ -69,17 +73,19 @@ export class ZeroAccount {
69
73
  }
70
74
  openApp() {
71
75
  if (this.modalOpen) {
76
+ this.refreshQR(true);
72
77
  window.location.href = this.url;
73
78
  }
74
79
  }
75
80
  render() {
76
81
  const logoColor = this.themePreset === ThemePreset.light ? '#7263FA' : '#FFFFF9';
77
82
  const qrColor = '#000';
78
- return (h(Host, { key: '1dc3610232166249e09861006f22ad43a58d208d' }, h("slot", { key: '5c510d06b9423a2540e494c57eebda16ac2f3fe6' }), this.host.childNodes.length === 0 &&
79
- h("button", { class: `button ${this.themePreset}`, onClick: () => this.toggleModal() }, h(Logo, { className: 'button__logo', color: logoColor }), "use 0account"), h("div", { key: '1ccab237f88fe77eb22f0c0b82b9612b536a6eb2', ref: el => this.modalEl = el, onClick: (e) => this.closeModal(e), class: `modal ${this.themePreset} ${this.isAnimating ? 'modal-animated' : ''} ${this.modalOpen ? '' : 'modal--hidden'}` }, h("div", { key: 'cca5693c98f2dbf7aa5584e62862e90783c24bdb', class: 'modal__content' }, h("div", { key: 'fa239e9bb2f618a7d0067c74d6c599f1482aa0ce', ref: el => this.closeButtonEl = el, class: 'modal__close-button' }), h("div", { key: '3d8e206fbbb7a45f0b634fc1ac5cda0a3434d6d9', class: 'modal__qrcode__container' }, h("qr-code", { key: 'a2f7f00f7926c7994c79098b4f386e4e60f16bc4', url: this.url, class: `modal__qrcode`, level: this.level, color: qrColor }), h("div", { key: '5819116a32e44341a408b79d5ed48a31c0be17d9', class: 'circle__overlay' }, h("div", { key: '67220c1757145e3263fdf8b265730a9b50628034', class: 'circle' }), h("div", { key: '2d43067a7a3e0fad60670a92f026925b7b2141f0', class: 'circle circle--medium' }), h("div", { key: 'c6cc6df2fcfd06b895e185f5b818150ea031c15e', class: 'circle circle--large' })), h(Logo, { key: '1e5b5f9687d0629cacd3c2524bb271824c03f102', className: 'modal__logo', color: logoColor })), h("div", { key: '13e998689e3b8942c39f94c8d67b1d6908ea63de', class: 'modal__buttons' }, h("button", { key: '879631b5e37bd0b9f440023edbef542d3628142c', onClick: () => this.openApp(), class: 'modal__button' }, "Open the desktop app"), h("a", { key: '3be4413c520f42982546535badf4aa133a25ee78', href: 'https://0account.com/downloads', class: 'modal__link' }, "Download the app"))))));
83
+ return (h(Host, { key: '16e012816a541ac508e2c7e4bfb2c86ec5e12139' }, h("slot", { key: 'f843c7ca9d61291c0e789ea57f7f205ff426fbb5' }), this.host.childNodes.length === 0 &&
84
+ h("button", { class: `button ${this.themePreset}`, onClick: () => this.toggleModal() }, h(Logo, { className: 'button__logo', color: logoColor }), "use 0account"), h("div", { key: '3a97849bd767edbd569ebd9e18d0dcd1adc0d5d2', ref: el => this.modalEl = el, onClick: (e) => this.closeModal(e), class: `modal ${this.themePreset} ${this.isAnimating ? 'modal-animated' : ''} ${this.modalOpen ? '' : 'modal--hidden'}` }, h("div", { key: 'b26ba193432193a6157c52be76fa3b15129760e2', class: 'modal__content' }, h("div", { key: '5586291e6cc5717aac240bfb9bef3b7e38240ff5', ref: el => this.closeButtonEl = el, class: 'modal__close-button' }), h("div", { key: '77edd32e4e29b902b20c4dbd60e348efe8c0f521', class: 'modal__qrcode__container' }, h("qr-code", { key: 'f0fa7b6c4ef4db32c579bf20da52bd9fef5b30cb', url: this.url, class: `modal__qrcode`, level: this.level, color: qrColor }), h("div", { key: '4ed77c6bfe8b90fe3907c869e54b3dfaf06f221f', class: 'circle__overlay' }, h("div", { key: '2d866ad14e0d42bb00f24ad572823c55413c5ffd', class: 'circle' }), h("div", { key: '8f29661b6d0626054dfa1d9a918666e939e0980c', class: 'circle circle--medium' }), h("div", { key: 'a6d5be1ba18df35063a49a4af0c64a1ca9bbe22d', class: 'circle circle--large' })), h(Logo, { key: '7f252c9b4df9660ad7bb21141ca2de02687056e8', className: 'modal__logo', color: logoColor })), h("div", { key: '69230e62468944142e4bd99ead185ee20af20b6f', class: 'modal__buttons' }, h("button", { key: '4d03821841d9262f3774011abee30b8a85e460eb', disabled: this.isAnimating, onClick: () => this.openApp(), class: 'modal__button' }, "Open 0account"), h("a", { key: 'd6e6313b40eefd3dce8a9097a298f9464eb0a86e', href: 'https://0account.com/downloads', class: 'modal__link' }, "Download"))))));
80
85
  }
81
- // called only once
82
- componentWillLoad() {
86
+ initServices() {
87
+ if (this.logger && this.uaParser && this.ws)
88
+ return;
83
89
  this.logger = new Logger(this.environment);
84
90
  this.uaParser = new UAParser();
85
91
  this.ws = new WS(this.appId, {
@@ -90,6 +96,10 @@ export class ZeroAccount {
90
96
  env: this.environment,
91
97
  log: this.log,
92
98
  });
99
+ }
100
+ // called only once
101
+ componentWillLoad() {
102
+ this.initServices();
93
103
  // make sure we initQR
94
104
  this.refreshQR(true);
95
105
  document.addEventListener('keydown', this.hideOnEsc);
@@ -390,6 +400,12 @@ export class ZeroAccount {
390
400
  "target": "document",
391
401
  "capture": false,
392
402
  "passive": false
403
+ }, {
404
+ "name": "0account-logout",
405
+ "method": "logout",
406
+ "target": "document",
407
+ "capture": false,
408
+ "passive": false
393
409
  }, {
394
410
  "name": "0account-open-app",
395
411
  "method": "openApp",
@@ -1 +1 @@
1
- {"version":3,"file":"zero-account.js","sourceRoot":"","sources":["../../../src/components/zero-account/zero-account.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACjF,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AACxC,OAAO,EAAE,EAAE,IAAI,MAAM,EAAE,MAAM,MAAM,CAAC;AAEpC,OAAO,EAAE,WAAW,EAAE,oBAAoB,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AACzE,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC3C,OAAO,KAAK,QAAQ,MAAM,iBAAiB,CAAC;AAC5C,OAAO,IAAI,MAAM,QAAQ,CAAC;AAC1B,OAAO,EAAE,EAAE,EAAE,MAAM,aAAa,CAAC;AAEjC,MAAM,WAAW,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;AACnC,MAAM,WAAW,GAAG,EAAE,GAAG,IAAI,CAAC;AAE9B,MAAM,oBAAoB,GAAG,MAAM,CAAC,QAAQ,CAAC,MAAM,GAAG,YA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QACN,MAAM,MAAM,GAAG,IAAI,CAAC,QAAQ,CAAC,SAAS,EAAE,CAAA;QACxC,OAAO,MAAM,CAAC,IAAI,KAAK,QAAQ,IAAI,MAAM,CAAC,IAAI,KAAK,QAAQ,CAAA;IAC7D,CAAC;IAED,iBAAiB;QACf,IAAI,CAAC,UAAU,EAAE,CAAA;IACnB,CAAC;IAED,oBAAoB;QAClB,IAAI,CAAC,SAAS,EAAE,CAAA;QAChB,QAAQ,CAAC,mBAAmB,CAAC,SAAS,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC;IAC1D,CAAC;IAEO,YAAY;QAClB,IAAI,CAAC,SAAS,EAAE,CAAA;QAChB,IAAI,CAAC,UAAU,EAAE,CAAA;IACnB,CAAC;IAEO,UAAU;QAChB,IAAI,CAAC,KAAK,GAAG,MAAM,CAAC,WAAW,CAAC,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,iBAAiB,EAAE,CAAC,CAAC;IAC5E,CAAC;IAEO,SAAS;QACf,MAAM,CAAC,aAAa,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACjC,MAAM,CAAC,YAAY,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;QACzC,IAAI,CAAC,WAAW,GAAG,KAAK,CAAA;IAC1B,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAGF","sourcesContent":["import { Element, Component, h, Host, Prop, Listen, State } from '@stencil/core';\nimport { UAParser } from 'ua-parser-js';\nimport { v4 as uuidv4 } from 'uuid';\n\nimport { Environment, ErrorCorrectionLevel, ThemePreset } from './enums';\nimport { Logger } from '../../utils/utils';\nimport * as utilsURL from '../../utils/url';\nimport Logo from './logo';\nimport { WS } from './websocket';\n\nconst maxInterval = 59 * 60 * 1000;\nconst minInterval = 10 * 1000;\n\nconst DEFAULT_CALLBACK_URL = window.location.origin + '/zero/auth';\nconst ANIMATION_DURATION = 3000\n\n@Component({\n tag: 'zero-account',\n styleUrl: 'zero-account.css',\n shadow: true,\n})\nexport class ZeroAccount {\n @Prop() appId!: string;\n @Prop() updateInterval?: number = 3 * 60 * 1000;\n @Prop({attribute: 'callback-url'}) callbackURL: string = DEFAULT_CALLBACK_URL;\n @Prop() modal?: boolean = true;\n @Prop() level?: ErrorCorrectionLevel = ErrorCorrectionLevel.M;\n @Prop() primaryColor: string = '#3C444F';\n @Prop() secondaryColor: string;\n @Prop() environment?: Environment = Environment.production;\n @Prop() enableWithCredentials?: boolean = false;\n @Prop() themePreset?: ThemePreset = ThemePreset.light;\n @Prop() autoStartApp? = true;\n\n private logger: Logger;\n private uaParser: UAParser;\n private ws: WS;\n\n private timer: number;\n private animationTimer: number;\n\n @Element() host: HTMLElement;\n private modalEl: HTMLDivElement;\n private closeButtonEl: HTMLDivElement;\n\n @State() modalOpen = false;\n @State() isAnimating = false;\n @State() url = '';\n\n private getUpdateInterval() {\n // make sure the provided value is within bounds\n return Math.min(Math.max(this.updateInterval, minInterval), maxInterval);\n }\n private refreshQR = (ignoreAnimate = false)=> {\n const update = () => {\n this.restartTimer();\n this.updateURL()\n }\n if (ignoreAnimate) return update();\n\n this.isAnimating = true\n this.animationTimer = window.setTimeout(()=>{\n update()\n this.isAnimating = false\n }, ANIMATION_DURATION)\n }\n\n @Listen('0account-toggle-modal', { target: 'document' })\n toggleModal() {\n this.modalOpen = !this.modalOpen;\n if (this.modalOpen) this.refreshQR(true)\n if ((this.modalOpen && this.autoStartApp) || this.isMobile()) this.openApp()\n }\n\n @Listen('0account-close-modal', { target: 'document' })\n @Listen('0account-authenticated', { target: 'document' })\n private _closeModal() {\n this.modalOpen = false;\n this.stopTimer()\n }\n\n private closeModal(e: MouseEvent) {\n if (e.target !== this.modalEl && e.target !== this.closeButtonEl) {\n return e.stopPropagation();\n }\n this._closeModal()\n }\n\n @Listen('0account-open-app', { target: 'document' })\n openApp() {\n if (this.modalOpen) {\n window.location.href = this.url\n }\n }\n\n render() {\n const logoColor = this.themePreset === ThemePreset.light ? '#7263FA': '#FFFFF9'\n const qrColor = '#000'\n return (\n <Host>\n <slot />\n {this.host.childNodes.length === 0 &&\n <button class={`button ${this.themePreset}`} onClick={()=>this.toggleModal()}>\n <Logo className='button__logo' color={logoColor} />\n use 0account\n </button>\n }\n <div\n ref={el => this.modalEl = el}\n onClick={(e) => this.closeModal(e)}\n class={`modal ${this.themePreset} ${this.isAnimating ? 'modal-animated': ''} ${this.modalOpen ? '' : 'modal--hidden'}`}>\n <div class='modal__content'>\n <div ref={el => this.closeButtonEl = el} class='modal__close-button'></div>\n <div class='modal__qrcode__container'>\n <qr-code url={this.url} class={`modal__qrcode`} level={this.level} color={qrColor}/>\n <div class='circle__overlay'>\n <div class='circle'></div>\n <div class='circle circle--medium'></div>\n <div class='circle circle--large'></div>\n </div>\n <Logo className='modal__logo' color={logoColor} />\n </div>\n <div class='modal__buttons'>\n <button onClick={()=>this.openApp()} class='modal__button'>Open the desktop app</button>\n <a href='https://0account.com/downloads' class='modal__link'>Download the app</a>\n </div>\n </div>\n </div>\n </Host>\n );\n }\n\n private hideOnEsc = (e) => {\n if ((e.key === 'Escape' || e.key === 'Esc')) {\n this.modalOpen = false;\n }\n };\n\n // called only once\n componentWillLoad() {\n this.logger = new Logger(this.environment);\n this.uaParser = new UAParser()\n this.ws = new WS(this.appId, {\n updateInterval: this.getUpdateInterval(),\n enableWithCredentials: this.enableWithCredentials,\n callbackURL: this.callbackURL,\n uaParser: this.uaParser,\n env: this.environment,\n log: this.log,\n })\n\n // make sure we initQR\n this.refreshQR(true)\n document.addEventListener('keydown', this.hideOnEsc);\n }\n\n private updateURL() {\n const expires = new Date().getTime() + this.getUpdateInterval();\n const uuid = uuidv4();\n this.ws.updateUUID(uuid);\n const params = utilsURL.appendToParams('', {\n appId: this.appId,\n uuid: uuid,\n expires: expires,\n })\n\n if (this.isMobile()) {\n this.url = 'https://launch.0account.com/auth?' + params;\n } else {\n this.url = 'zero-account://auth?' + params;\n }\n }\n\n isMobile() {\n const device = this.uaParser.getDevice()\n return device.type === 'tablet' || device.type === 'mobile'\n }\n\n connectedCallback() {\n this.startTimer()\n }\n\n disconnectedCallback() {\n this.stopTimer()\n document.removeEventListener('keydown', this.hideOnEsc);\n }\n\n private restartTimer() {\n this.stopTimer()\n this.startTimer()\n }\n\n private startTimer() {\n this.timer = window.setInterval(this.refreshQR, this.getUpdateInterval());\n }\n\n private stopTimer() {\n window.clearInterval(this.timer);\n window.clearTimeout(this.animationTimer);\n this.isAnimating = false\n }\n\n private log = (...args) => this.logger.log(...args);\n}\n"]}
1
+ {"version":3,"file":"zero-account.js","sourceRoot":"","sources":["../../../src/components/zero-account/zero-account.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACjF,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AACxC,OAAO,EAAE,EAAE,IAAI,MAAM,EAAE,MAAM,MAAM,CAAC;AAEpC,OAAO,EAAE,WAAW,EAAE,oBAAoB,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AACzE,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC3C,OAAO,KAAK,QAAQ,MAAM,iBAAiB,CAAC;AAC5C,OAAO,IAAI,MAAM,QAAQ,CAAC;AAC1B,OAAO,EAAE,EAAE,EAAE,MAAM,aAAa,CAAC;AAEjC,MAAM,WAAW,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;AACnC,MAAM,WAA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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAGF","sourcesContent":["import { Element, Component, h, Host, Prop, Listen, State } from '@stencil/core';\nimport { UAParser } from 'ua-parser-js';\nimport { v4 as uuidv4 } from 'uuid';\n\nimport { Environment, ErrorCorrectionLevel, ThemePreset } from './enums';\nimport { Logger } from '../../utils/utils';\nimport * as utilsURL from '../../utils/url';\nimport Logo from './logo';\nimport { WS } from './websocket';\n\nconst maxInterval = 59 * 60 * 1000;\nconst minInterval = 10 * 1000;\n\nconst DEFAULT_CALLBACK_URL = window.location.origin + '/zero/auth';\nconst ANIMATION_DURATION = 3000\n\n@Component({\n tag: 'zero-account',\n styleUrl: 'zero-account.css',\n shadow: true,\n})\nexport class ZeroAccount {\n @Prop() appId!: string;\n @Prop() updateInterval?: number = 3 * 60 * 1000;\n @Prop({attribute: 'callback-url'}) callbackURL: string = DEFAULT_CALLBACK_URL;\n @Prop() modal?: boolean = true;\n @Prop() level?: ErrorCorrectionLevel = ErrorCorrectionLevel.M;\n @Prop() primaryColor: string = '#3C444F';\n @Prop() secondaryColor: string;\n @Prop() environment?: Environment = Environment.production;\n @Prop() enableWithCredentials?: boolean = false;\n @Prop() themePreset?: ThemePreset = ThemePreset.light;\n @Prop() autoStartApp? = true;\n\n private logger: Logger;\n private uaParser: UAParser;\n private ws: WS;\n\n private timer: number;\n private animationTimer: number;\n\n @Element() host: HTMLElement;\n private modalEl: HTMLDivElement;\n private closeButtonEl: HTMLDivElement;\n\n @State() modalOpen = false;\n @State() isAnimating = false;\n @State() url = '';\n\n private getUpdateInterval() {\n // make sure the provided value is within bounds\n return Math.min(Math.max(this.updateInterval, minInterval), maxInterval);\n }\n private refreshQR = (ignoreAnimate = false)=> {\n this.initServices();\n const update = () => {\n this.restartTimer();\n this.updateURL()\n }\n if (ignoreAnimate) return update();\n\n this.isAnimating = true\n this.animationTimer = window.setTimeout(()=>{\n update()\n this.isAnimating = false\n }, ANIMATION_DURATION)\n }\n\n @Listen('0account-toggle-modal', { target: 'document' })\n toggleModal() {\n this.modalOpen = !this.modalOpen;\n if (this.modalOpen) this.refreshQR(true)\n if ((this.modalOpen && this.autoStartApp) || this.isMobile()) this.openApp()\n }\n\n @Listen('0account-close-modal', { target: 'document' })\n @Listen('0account-authenticated', { target: 'document' })\n private _closeModal() {\n this.modalOpen = false;\n this.stopTimer()\n }\n\n @Listen('0account-logout', { target: 'document' })\n logout() {\n this.ws.logout()\n }\n\n private closeModal(e: MouseEvent) {\n if (e.target !== this.modalEl && e.target !== this.closeButtonEl) {\n return e.stopPropagation();\n }\n this._closeModal()\n }\n\n @Listen('0account-open-app', { target: 'document' })\n openApp() {\n if (this.modalOpen) {\n this.refreshQR(true)\n window.location.href = this.url\n }\n }\n\n render() {\n const logoColor = this.themePreset === ThemePreset.light ? '#7263FA': '#FFFFF9'\n const qrColor = '#000'\n return (\n <Host>\n <slot />\n {this.host.childNodes.length === 0 &&\n <button class={`button ${this.themePreset}`} onClick={()=>this.toggleModal()}>\n <Logo className='button__logo' color={logoColor} />\n use 0account\n </button>\n }\n <div\n ref={el => this.modalEl = el}\n onClick={(e) => this.closeModal(e)}\n class={`modal ${this.themePreset} ${this.isAnimating ? 'modal-animated': ''} ${this.modalOpen ? '' : 'modal--hidden'}`}>\n <div class='modal__content'>\n <div ref={el => this.closeButtonEl = el} class='modal__close-button'></div>\n <div class='modal__qrcode__container'>\n <qr-code url={this.url} class={`modal__qrcode`} level={this.level} color={qrColor}/>\n <div class='circle__overlay'>\n <div class='circle'></div>\n <div class='circle circle--medium'></div>\n <div class='circle circle--large'></div>\n </div>\n <Logo className='modal__logo' color={logoColor} />\n </div>\n <div class='modal__buttons'>\n <button disabled={this.isAnimating} onClick={()=>this.openApp()} class='modal__button'>Open 0account</button>\n <a href='https://0account.com/downloads' class='modal__link'>Download</a>\n </div>\n </div>\n </div>\n </Host>\n );\n }\n\n private hideOnEsc = (e) => {\n if ((e.key === 'Escape' || e.key === 'Esc')) {\n this.modalOpen = false;\n }\n };\n\n initServices() {\n if (this.logger && this.uaParser && this.ws) return;\n this.logger = new Logger(this.environment);\n this.uaParser = new UAParser()\n this.ws = new WS(this.appId, {\n updateInterval: this.getUpdateInterval(),\n enableWithCredentials: this.enableWithCredentials,\n callbackURL: this.callbackURL,\n uaParser: this.uaParser,\n env: this.environment,\n log: this.log,\n })\n }\n // called only once\n componentWillLoad() {\n this.initServices()\n\n // make sure we initQR\n this.refreshQR(true)\n document.addEventListener('keydown', this.hideOnEsc);\n }\n\n private updateURL() {\n const expires = new Date().getTime() + this.getUpdateInterval();\n const uuid = uuidv4();\n this.ws.updateUUID(uuid);\n const params = utilsURL.appendToParams('', {\n appId: this.appId,\n uuid: uuid,\n expires: expires,\n })\n\n if (this.isMobile()) {\n this.url = 'https://launch.0account.com/auth?' + params;\n } else {\n this.url = 'zero-account://auth?' + params;\n }\n }\n\n isMobile() {\n const device = this.uaParser.getDevice()\n return device.type === 'tablet' || device.type === 'mobile'\n }\n\n connectedCallback() {\n this.startTimer()\n }\n\n disconnectedCallback() {\n this.stopTimer()\n document.removeEventListener('keydown', this.hideOnEsc);\n }\n\n private restartTimer() {\n this.stopTimer()\n this.startTimer()\n }\n\n private startTimer() {\n this.timer = window.setInterval(this.refreshQR, this.getUpdateInterval());\n }\n\n private stopTimer() {\n window.clearInterval(this.timer);\n window.clearTimeout(this.animationTimer);\n this.isAnimating = false\n }\n\n private log = (...args) => this.logger.log(...args);\n}\n"]}
@@ -284,6 +284,9 @@ class WS {
284
284
  this.uuid = uuid;
285
285
  this.send(fromWidgetUUIDUpdated, this.deviceInfo());
286
286
  }
287
+ logout() {
288
+ this.send(fromWidgetLoggedOut, this.deviceInfo());
289
+ }
287
290
  send(action, data) {
288
291
  if (!this.socket || !this.socket.readyState || this.socket.readyState !== WebSocket.OPEN) {
289
292
  const retry = debounce(this.send.bind(this), 1000);
@@ -296,7 +299,7 @@ class WS {
296
299
  appId: `${this.appId}`,
297
300
  message: {},
298
301
  };
299
- if (action === fromWidgetEnsureSession) {
302
+ if (action === fromWidgetEnsureSession || action === fromWidgetLoggedOut) {
300
303
  const sessionId = localStorage.getItem(`${PREFIX}_${SESSION_ID}`);
301
304
  const sessionToken = localStorage.getItem(`${PREFIX}_${SESSION_TOKEN}`);
302
305
  if (!sessionId || !sessionToken)
@@ -359,7 +362,7 @@ class WS {
359
362
  }
360
363
  }
361
364
 
362
- const zeroAccountCss = ":host{--primary-color:#7263FA;--primary-background-color:#FFF;--theme-based-radius:0px;--theme-based-padding:0px;--button-animation-duration:200ms;--text-color:#000;--button-border-color:#B2D4FF;--button-border-radius:9999px;--button-background-color:var(--primary-background-color);--modal-logo-border-color:var(--primary-color);--modal-animation-duration:350ms;--easing:cubic-bezier(0.16, 1, 0.3, 1);font-family:sans-serif}.dark{--button-background-color:rgb(30, 41, 59);--primary-background-color:rgb(30, 41, 59);--button-border-color:#FFFFF9;--text-color:#FFFFF9;--modal-logo-border-color:#CCC;--theme-based-radius:4px;--theme-based-padding:8px}.button{font-size:16px;color:var(--text-color);cursor:pointer;padding:8px 12px 8px 10px;display:flex;flex-direction:row;align-items:center;gap:6px;border:1px solid var(--button-border-color);background-color:var(--button-background-color);border-radius:var(--button-border-radius)}.button:hover{transition:box-shadow var(--button-animation-duration);box-shadow:0 0 3px rgba(0, 0, 0, 0.3);background:linear-gradient(\n to top,\n rgba(200, 200, 200, 0.1),\n rgba(200, 200, 200, 0.1)\n ) var(--button-background-color)}.button:active{transition:box-shadow var(--button-animation-duration);box-shadow:0 0 0 rgba(0, 0, 0, 0)}.button__logo{width:1.3rem}.modal{display:flex;z-index:9999;justify-content:center;align-items:center;position:fixed;top:0;left:0;width:100%;height:100%;opacity:1;background-color:rgba(0, 0, 0, 0.3);transition:opacity var(--modal-animation-duration) var(--easing)}.modal--hidden{opacity:0;pointer-events:none}.modal__content{max-width:240px;border-radius:4px;position:relative;display:flex;flex-direction:column;align-items:center;padding:16px;background-color:var(--primary-background-color);transform:scale(1);transition:transform var(--modal-animation-duration) var(--easing)}.modal--hidden .modal__content{transform:scale(0.5)}.modal__qrcode__container{position:relative;background-color:white;border-radius:var(--theme-based-radius);padding:var(--theme-based-padding)}.modal__qrcode{border-radius:4px;width:100%;height:auto}.modal__logo{padding:8px;border:2px var(--modal-logo-border-color) solid;border-radius:var(--button-border-radius);background-color:var(--primary-background-color);position:absolute;width:16%;top:50%;left:50%;transform:translate3d(-50%, -50%, 0)}.modal-animated .circle__overlay{width:100%;height:100%}.modal-animated .modal__qrcode{filter:blur(2px)}.modal-animated .modal__logo{border:none;animation:spin 2.5s var(--easing) infinite}@keyframes spin{0%{transform:translate3d(-50%, -50%, 0) rotate(0deg)}50%{transform:translate3d(-50%, -50%, 0) rotate(180deg)}100%{transform:translate3d(-50%, -50%, 0) rotate(360deg)}}.modal__buttons{width:100%;flex-direction:column;align-items:center;margin-top:14px;display:flex;text-align:center}.modal:not(.modal--hidden) .modal__button{transform:scale(1) translate3d(0, 0, 0)}.modal:not(.modal--hidden) .modal__link{transform:scale(1) translate3d(0, 0, 0)}.modal__button{transform:scale(0) translate3d(0, 150px, 0);transition:calc(var(--modal-animation-duration) + 50ms) var(--easing);transition-property:scale, transform, background-color;cursor:pointer;padding:12px;font-size:14px;background-color:var(--primary-color);color:white;border:none;border-radius:6px;width:100%}.modal__button:hover{background:linear-gradient(\n to top,\n rgba(0, 0, 0, 0.1),\n rgba(0, 0, 0, 0.1)\n ) var(--primary-color)}.modal__link{transform:scale(0) translate3d(0, 150px, 0);transition:calc(var(--modal-animation-duration) + 150ms) var(--easing);transition-property:scale, transform;font-size:0.8rem;padding:10px 20px 0;color:var(--primary-color);width:100%;text-decoration:underline rgba(0, 0, 0, 0)}.modal__link:hover{text-decoration-color:var(--primary-color)}.modal__close-button{position:absolute;top:-26px;right:-26px;width:24px;height:24px;background-color:rgba(0, 0, 0, 0.1);border-radius:10px;cursor:pointer;transition:background-color var(--modal-animation-duration) var(--easing)}.modal__close-button:hover{background-color:rgba(0, 0, 0, 0.3)}.modal__close-button:before,.modal__close-button:after{content:\"\";position:absolute;top:50%;left:50%;width:50%;height:1px;background-color:rgba(255, 255, 255, 0.8);transform:translate(-50%, -50%) rotate(45deg)}.modal__close-button:after{transform:translate(-50%, -50%) rotate(-45deg)}.circle__overlay{overflow:hidden;top:50%;left:50%;transform:translate(-50%, -50%);position:absolute;background-color:var(--primary-background-color);border-radius:var(--button-border-radius);width:10%;height:10%;border:2px var(--modal-logo-border-color) solid;transition:calc(var(--modal-animation-duration) + 200ms) var(--easing);transition-property:width, height, opacity}.circle{position:absolute;top:50%;left:50%;transform:translate(-50%, -50%);width:100px;height:100px;border-radius:50%;background-color:#E0E0E0;animation:circle__ripple 2s linear infinite}.circle--medium{width:150px;height:150px;animation-duration:2.5s}.circle--large{width:200px;height:200px;animation-duration:3s}@keyframes circle__ripple{0%{transform:translate(-50%, -50%) scale(0);opacity:1}100%{transform:translate(-50%, -50%) scale(1.5);opacity:0}}";
365
+ const zeroAccountCss = ":host{--primary-color:#7263FA;--primary-background-color:#FFF;--theme-based-radius:0px;--theme-based-padding:0px;--button-animation-duration:200ms;--text-color:#000;--button-border-color:#B2D4FF;--button-border-radius:9999px;--button-background-color:var(--primary-background-color);--modal-logo-border-color:var(--primary-color);--modal-animation-duration:350ms;--easing:cubic-bezier(0.16, 1, 0.3, 1);--disabled-background-color:rgba(0, 0, 0, 0.12);--disabled-color:rgba(0, 0, 0, 0.3);font-family:sans-serif}.dark{--button-background-color:rgb(30, 41, 59);--primary-background-color:rgb(30, 41, 59);--button-border-color:#FFFFF9;--text-color:#FFFFF9;--modal-logo-border-color:#CCC;--disabled-background-color:rgba(255, 255, 255, 0.12);--disabled-color:rgba(255, 255, 255, 0.3);--theme-based-radius:4px;--theme-based-padding:8px}.button{font-size:16px;color:var(--text-color);cursor:pointer;padding:8px 12px 8px 10px;display:flex;flex-direction:row;align-items:center;gap:6px;border:1px solid var(--button-border-color);background-color:var(--button-background-color);border-radius:var(--button-border-radius)}.button:hover{transition:box-shadow var(--button-animation-duration);box-shadow:0 0 3px rgba(0, 0, 0, 0.3);background:linear-gradient(\n to top,\n rgba(200, 200, 200, 0.1),\n rgba(200, 200, 200, 0.1)\n ) var(--button-background-color)}.button:active{transition:box-shadow var(--button-animation-duration);box-shadow:0 0 0 rgba(0, 0, 0, 0)}.button__logo{width:1.3rem}.modal{display:flex;z-index:9999;justify-content:center;align-items:center;position:fixed;top:0;left:0;width:100%;height:100%;opacity:1;background-color:rgba(0, 0, 0, 0.3);transition:opacity var(--modal-animation-duration) var(--easing)}.modal--hidden{opacity:0;pointer-events:none}.modal__content{max-width:240px;border-radius:4px;position:relative;display:flex;flex-direction:column;align-items:center;padding:16px;background-color:var(--primary-background-color);transform:scale(1);transition:transform var(--modal-animation-duration) var(--easing)}.modal--hidden .modal__content{transform:scale(0.5)}.modal__qrcode__container{position:relative;background-color:white;border-radius:var(--theme-based-radius);padding:var(--theme-based-padding)}.modal__qrcode{border-radius:4px;width:100%;height:auto}.modal__logo{padding:8px;border:2px var(--modal-logo-border-color) solid;border-radius:var(--button-border-radius);background-color:var(--primary-background-color);position:absolute;width:16%;top:50%;left:50%;transform:translate3d(-50%, -50%, 0)}.modal-animated .circle__overlay{width:100%;height:100%}.modal-animated .modal__qrcode{filter:blur(2px)}.modal-animated .modal__logo{border:none;animation:spin 2.5s var(--easing) infinite}@keyframes spin{0%{transform:translate3d(-50%, -50%, 0) rotate(0deg)}50%{transform:translate3d(-50%, -50%, 0) rotate(180deg)}100%{transform:translate3d(-50%, -50%, 0) rotate(360deg)}}.modal__buttons{width:100%;flex-direction:column;align-items:center;margin-top:14px;display:flex;text-align:center}.modal:not(.modal--hidden) .modal__button{transform:scale(1) translate3d(0, 0, 0)}.modal:not(.modal--hidden) .modal__link{transform:scale(1) translate3d(0, 0, 0)}.modal__button{transform:scale(0) translate3d(0, 150px, 0);transition:calc(var(--modal-animation-duration) + 50ms) var(--easing);transition-property:scale, transform, background-color;cursor:pointer;padding:12px;font-size:14px;background-color:var(--primary-color);color:white;border:none;border-radius:6px;width:100%}.modal__button:hover{background:linear-gradient(\n to top,\n rgba(0, 0, 0, 0.1),\n rgba(0, 0, 0, 0.1)\n ) var(--primary-color)}.modal__button:disabled{background-color:var(--disabled-background-color);color:var(--disabled-color);cursor:not-allowed;pointer-events:none}.modal__link{transform:scale(0) translate3d(0, 150px, 0);transition:calc(var(--modal-animation-duration) + 150ms) var(--easing);transition-property:scale, transform;font-size:0.8rem;padding:10px 20px 0;color:var(--primary-color);width:100%;text-decoration:underline rgba(0, 0, 0, 0)}.modal__link:hover{text-decoration-color:var(--primary-color)}.modal__close-button{position:absolute;top:-26px;right:-26px;width:24px;height:24px;background-color:rgba(0, 0, 0, 0.1);border-radius:10px;cursor:pointer;transition:background-color var(--modal-animation-duration) var(--easing)}.modal__close-button:hover{background-color:rgba(0, 0, 0, 0.3)}.modal__close-button:before,.modal__close-button:after{content:\"\";position:absolute;top:50%;left:50%;width:50%;height:1px;background-color:rgba(255, 255, 255, 0.8);transform:translate(-50%, -50%) rotate(45deg)}.modal__close-button:after{transform:translate(-50%, -50%) rotate(-45deg)}.circle__overlay{overflow:hidden;top:50%;left:50%;transform:translate(-50%, -50%);position:absolute;background-color:var(--primary-background-color);border-radius:var(--button-border-radius);width:10%;height:10%;border:2px var(--modal-logo-border-color) solid;transition:calc(var(--modal-animation-duration) + 200ms) var(--easing);transition-property:width, height, opacity}.circle{position:absolute;top:50%;left:50%;transform:translate(-50%, -50%);width:100px;height:100px;border-radius:50%;background-color:#E0E0E0;animation:circle__ripple 2s linear infinite}.circle--medium{width:150px;height:150px;animation-duration:2.5s}.circle--large{width:200px;height:200px;animation-duration:3s}@keyframes circle__ripple{0%{transform:translate(-50%, -50%) scale(0);opacity:1}100%{transform:translate(-50%, -50%) scale(1.5);opacity:0}}";
363
366
  const ZeroAccountStyle0 = zeroAccountCss;
364
367
 
365
368
  const maxInterval = 59 * 60 * 1000;
@@ -372,6 +375,7 @@ const ZeroAccount$1 = /*@__PURE__*/ proxyCustomElement(class ZeroAccount extends
372
375
  this.__registerHost();
373
376
  this.__attachShadow();
374
377
  this.refreshQR = (ignoreAnimate = false) => {
378
+ this.initServices();
375
379
  const update = () => {
376
380
  this.restartTimer();
377
381
  this.updateURL();
@@ -420,6 +424,9 @@ const ZeroAccount$1 = /*@__PURE__*/ proxyCustomElement(class ZeroAccount extends
420
424
  this.modalOpen = false;
421
425
  this.stopTimer();
422
426
  }
427
+ logout() {
428
+ this.ws.logout();
429
+ }
423
430
  closeModal(e) {
424
431
  if (e.target !== this.modalEl && e.target !== this.closeButtonEl) {
425
432
  return e.stopPropagation();
@@ -428,17 +435,19 @@ const ZeroAccount$1 = /*@__PURE__*/ proxyCustomElement(class ZeroAccount extends
428
435
  }
429
436
  openApp() {
430
437
  if (this.modalOpen) {
438
+ this.refreshQR(true);
431
439
  window.location.href = this.url;
432
440
  }
433
441
  }
434
442
  render() {
435
443
  const logoColor = this.themePreset === ThemePreset.light ? '#7263FA' : '#FFFFF9';
436
444
  const qrColor = '#000';
437
- return (h(Host, { key: '1dc3610232166249e09861006f22ad43a58d208d' }, h("slot", { key: '5c510d06b9423a2540e494c57eebda16ac2f3fe6' }), this.host.childNodes.length === 0 &&
438
- h("button", { class: `button ${this.themePreset}`, onClick: () => this.toggleModal() }, h(Logo, { className: 'button__logo', color: logoColor }), "use 0account"), h("div", { key: '1ccab237f88fe77eb22f0c0b82b9612b536a6eb2', ref: el => this.modalEl = el, onClick: (e) => this.closeModal(e), class: `modal ${this.themePreset} ${this.isAnimating ? 'modal-animated' : ''} ${this.modalOpen ? '' : 'modal--hidden'}` }, h("div", { key: 'cca5693c98f2dbf7aa5584e62862e90783c24bdb', class: 'modal__content' }, h("div", { key: 'fa239e9bb2f618a7d0067c74d6c599f1482aa0ce', ref: el => this.closeButtonEl = el, class: 'modal__close-button' }), h("div", { key: '3d8e206fbbb7a45f0b634fc1ac5cda0a3434d6d9', class: 'modal__qrcode__container' }, h("qr-code", { key: 'a2f7f00f7926c7994c79098b4f386e4e60f16bc4', url: this.url, class: `modal__qrcode`, level: this.level, color: qrColor }), h("div", { key: '5819116a32e44341a408b79d5ed48a31c0be17d9', class: 'circle__overlay' }, h("div", { key: '67220c1757145e3263fdf8b265730a9b50628034', class: 'circle' }), h("div", { key: '2d43067a7a3e0fad60670a92f026925b7b2141f0', class: 'circle circle--medium' }), h("div", { key: 'c6cc6df2fcfd06b895e185f5b818150ea031c15e', class: 'circle circle--large' })), h(Logo, { key: '1e5b5f9687d0629cacd3c2524bb271824c03f102', className: 'modal__logo', color: logoColor })), h("div", { key: '13e998689e3b8942c39f94c8d67b1d6908ea63de', class: 'modal__buttons' }, h("button", { key: '879631b5e37bd0b9f440023edbef542d3628142c', onClick: () => this.openApp(), class: 'modal__button' }, "Open the desktop app"), h("a", { key: '3be4413c520f42982546535badf4aa133a25ee78', href: 'https://0account.com/downloads', class: 'modal__link' }, "Download the app"))))));
445
+ return (h(Host, { key: '16e012816a541ac508e2c7e4bfb2c86ec5e12139' }, h("slot", { key: 'f843c7ca9d61291c0e789ea57f7f205ff426fbb5' }), this.host.childNodes.length === 0 &&
446
+ h("button", { class: `button ${this.themePreset}`, onClick: () => this.toggleModal() }, h(Logo, { className: 'button__logo', color: logoColor }), "use 0account"), h("div", { key: '3a97849bd767edbd569ebd9e18d0dcd1adc0d5d2', ref: el => this.modalEl = el, onClick: (e) => this.closeModal(e), class: `modal ${this.themePreset} ${this.isAnimating ? 'modal-animated' : ''} ${this.modalOpen ? '' : 'modal--hidden'}` }, h("div", { key: 'b26ba193432193a6157c52be76fa3b15129760e2', class: 'modal__content' }, h("div", { key: '5586291e6cc5717aac240bfb9bef3b7e38240ff5', ref: el => this.closeButtonEl = el, class: 'modal__close-button' }), h("div", { key: '77edd32e4e29b902b20c4dbd60e348efe8c0f521', class: 'modal__qrcode__container' }, h("qr-code", { key: 'f0fa7b6c4ef4db32c579bf20da52bd9fef5b30cb', url: this.url, class: `modal__qrcode`, level: this.level, color: qrColor }), h("div", { key: '4ed77c6bfe8b90fe3907c869e54b3dfaf06f221f', class: 'circle__overlay' }, h("div", { key: '2d866ad14e0d42bb00f24ad572823c55413c5ffd', class: 'circle' }), h("div", { key: '8f29661b6d0626054dfa1d9a918666e939e0980c', class: 'circle circle--medium' }), h("div", { key: 'a6d5be1ba18df35063a49a4af0c64a1ca9bbe22d', class: 'circle circle--large' })), h(Logo, { key: '7f252c9b4df9660ad7bb21141ca2de02687056e8', className: 'modal__logo', color: logoColor })), h("div", { key: '69230e62468944142e4bd99ead185ee20af20b6f', class: 'modal__buttons' }, h("button", { key: '4d03821841d9262f3774011abee30b8a85e460eb', disabled: this.isAnimating, onClick: () => this.openApp(), class: 'modal__button' }, "Open 0account"), h("a", { key: 'd6e6313b40eefd3dce8a9097a298f9464eb0a86e', href: 'https://0account.com/downloads', class: 'modal__link' }, "Download"))))));
439
447
  }
440
- // called only once
441
- componentWillLoad() {
448
+ initServices() {
449
+ if (this.logger && this.uaParser && this.ws)
450
+ return;
442
451
  this.logger = new Logger(this.environment);
443
452
  this.uaParser = new uaParser_pack.exports.UAParser();
444
453
  this.ws = new WS(this.appId, {
@@ -449,6 +458,10 @@ const ZeroAccount$1 = /*@__PURE__*/ proxyCustomElement(class ZeroAccount extends
449
458
  env: this.environment,
450
459
  log: this.log,
451
460
  });
461
+ }
462
+ // called only once
463
+ componentWillLoad() {
464
+ this.initServices();
452
465
  // make sure we initQR
453
466
  this.refreshQR(true);
454
467
  document.addEventListener('keydown', this.hideOnEsc);
@@ -509,7 +522,7 @@ const ZeroAccount$1 = /*@__PURE__*/ proxyCustomElement(class ZeroAccount extends
509
522
  "modalOpen": [32],
510
523
  "isAnimating": [32],
511
524
  "url": [32]
512
- }, [[4, "0account-toggle-modal", "toggleModal"], [4, "0account-close-modal", "_closeModal"], [4, "0account-authenticated", "_closeModal"], [4, "0account-open-app", "openApp"]]]);
525
+ }, [[4, "0account-toggle-modal", "toggleModal"], [4, "0account-close-modal", "_closeModal"], [4, "0account-authenticated", "_closeModal"], [4, "0account-logout", "logout"], [4, "0account-open-app", "openApp"]]]);
513
526
  function defineCustomElement$1() {
514
527
  if (typeof customElements === "undefined") {
515
528
  return;