@vitia.ai/secure-api-client-vue 0.1.1 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -6,10 +6,12 @@ export declare type LoginOptions = {
6
6
  username: string;
7
7
  password: string;
8
8
  scope: string;
9
+ oauthSession?: object;
9
10
  } | {
10
11
  email: string;
11
12
  socialLoginId: string;
12
13
  scope: string;
14
+ oauthSession?: object;
13
15
  } | {
14
16
  jwt: string;
15
17
  } | {
package/dist/index.mjs CHANGED
@@ -2742,22 +2742,22 @@ class Ms {
2742
2742
  if (!(this.ws && (this.ws.readyState === WebSocket.OPEN || this.ws.readyState === WebSocket.CONNECTING))) {
2743
2743
  if (this._connectPromise) return this._connectPromise;
2744
2744
  this._connectPromise = (async () => {
2745
- const { url: t } = await this.client.get("/url/notifications");
2746
- this.ws = new WebSocket(t), this.ws.onopen = () => {
2745
+ const { ans: t } = await this.client.get("/url/notifications"), { url: r } = t.data[0];
2746
+ this.ws = new WebSocket(r), this.ws.onopen = () => {
2747
2747
  this._reconnectAttempt = 0, console.log("Notifications connected");
2748
- }, this.ws.onmessage = async (r) => {
2748
+ }, this.ws.onmessage = async (s) => {
2749
2749
  try {
2750
- const s = JSON.parse(r.data), i = await this.client.decryptAndVerify(s), o = this.subscriptions.request[i == null ? void 0 : i.correlation_id];
2751
- o && Object.values(o).length > 0 && Object.values(o).forEach((u) => u(i));
2752
- const c = this.subscriptions.status[i == null ? void 0 : i.status];
2753
- c && Object.values(c).length > 0 && Object.values(c).forEach((u) => u(i));
2754
- const a = this.subscriptions.topic[i == null ? void 0 : i.topic];
2755
- a && Object.values(a).length > 0 && Object.values(a).forEach((u) => u(i)), Object.values(this.listeners).forEach((u) => u(i));
2756
- } catch (s) {
2757
- console.warn("Failed to process notification:", s);
2750
+ const i = JSON.parse(s.data), o = await this.client.decryptAndVerify(i), c = this.subscriptions.request[o == null ? void 0 : o.correlation_id];
2751
+ c && Object.values(c).length > 0 && Object.values(c).forEach((f) => f(o));
2752
+ const a = this.subscriptions.status[o == null ? void 0 : o.status];
2753
+ a && Object.values(a).length > 0 && Object.values(a).forEach((f) => f(o));
2754
+ const u = this.subscriptions.topic[o == null ? void 0 : o.topic];
2755
+ u && Object.values(u).length > 0 && Object.values(u).forEach((f) => f(o)), Object.values(this.listeners).forEach((f) => f(o));
2756
+ } catch (i) {
2757
+ console.warn("Failed to process notification:", i);
2758
2758
  }
2759
- }, this.ws.onerror = (r) => {
2760
- console.error("Notifications error", r);
2759
+ }, this.ws.onerror = (s) => {
2760
+ console.error("Notifications error", s);
2761
2761
  }, this.ws.onclose = () => {
2762
2762
  this.scheduleReconnect(), console.log("Notifications closed");
2763
2763
  };
@@ -2962,7 +2962,7 @@ ${c}`, l = await Hs(i, new TextEncoder().encode(h)), g = ne(l), w = new Headers(
2962
2962
  var t, r, s;
2963
2963
  (!this.session || !this.session.sessionId || !this.session.sessionExpiresAt || !this.session.encKey || !this.session.macKey) && await this.handshake();
2964
2964
  const e = new Date(Date.now() + 5 * 60 * 1e3);
2965
- (t = this.session) != null && t.sessionExpiresAt && new Date((r = this.session) == null ? void 0 : r.sessionExpiresAt) < e && await this.extendHandshake(), (s = this.session) != null && s.userId && this.isTokenExpired() && await this.refresh();
2965
+ (t = this.session) != null && t.sessionExpiresAt && new Date((r = this.session) == null ? void 0 : r.sessionExpiresAt) < e && await this.extendHandshake(), (s = this.session) != null && s.accessToken && this.isTokenExpired() && await this.refresh();
2966
2966
  }
2967
2967
  async extendHandshake() {
2968
2968
  await this.post("/handshake/extend", {}).then(async (e) => {
@@ -2999,9 +2999,14 @@ ${c}`, l = await Hs(i, new TextEncoder().encode(h)), g = ne(l), w = new Headers(
2999
2999
  return r === 0;
3000
3000
  }
3001
3001
  async login(e) {
3002
- await this.ensureSession();
3002
+ (!this.session || !this.session.sessionId || !this.session.sessionExpiresAt || !this.session.encKey || !this.session.macKey) && await this.handshake(), this.updateSession({
3003
+ accessToken: void 0,
3004
+ tokenType: void 0,
3005
+ expiresAt: void 0,
3006
+ refreshToken: void 0
3007
+ });
3003
3008
  const t = {};
3004
- "username" in e && "password" in e && (t.username = e.username, t.password = e.password, t.scope = e.scope), "email" in e && "socialLoginId" in e && (t.email = e.email, t.social_login_id = e.socialLoginId, t.scope = e.scope), "jwt" in e && this.updateSession({
3009
+ "username" in e && "password" in e && (t.username = e.username, t.password = e.password, t.scope = e.scope, t.oauth_session = e.oauthSession), "email" in e && "socialLoginId" in e && (t.email = e.email, t.social_login_id = e.socialLoginId, t.scope = e.scope, t.oauth_session = e.oauthSession), "jwt" in e && this.updateSession({
3005
3010
  accessToken: e.jwt,
3006
3011
  tokenType: "Bearer"
3007
3012
  }), "refreshToken" in e && (t.refresh_token = e.refreshToken);
@@ -3010,7 +3015,7 @@ ${c}`, l = await Hs(i, new TextEncoder().encode(h)), g = ne(l), w = new Headers(
3010
3015
  token_type: i,
3011
3016
  expires_at: o,
3012
3017
  refresh_token: c
3013
- } = r;
3018
+ } = r.data[0];
3014
3019
  return s && this.updateSession({ accessToken: s }), i && this.updateSession({ tokenType: i }), o && this.updateSession({ expiresAt: o }), c && this.updateSession({ refreshToken: c }), {
3015
3020
  accessToken: s,
3016
3021
  tokenType: i,