@blinkdotnew/sdk 0.14.3 → 0.14.4

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
@@ -1265,7 +1265,7 @@ All `{{secret_name}}` placeholders are replaced with encrypted values from your
1265
1265
 
1266
1266
  ### React
1267
1267
 
1268
- ```typitten
1268
+ ```typescript
1269
1269
  import { createClient } from '@blinkdotnew/sdk'
1270
1270
  import { useState, useEffect } from 'react'
1271
1271
 
package/dist/index.d.mts CHANGED
@@ -743,7 +743,13 @@ declare class BlinkAuth {
743
743
  private readonly authUrl;
744
744
  private parentWindowTokens;
745
745
  private isIframe;
746
+ private initializationPromise;
747
+ private isInitialized;
746
748
  constructor(config: BlinkClientConfig);
749
+ /**
750
+ * Wait for authentication initialization to complete
751
+ */
752
+ private waitForInitialization;
747
753
  /**
748
754
  * Setup listener for tokens from parent window
749
755
  */
@@ -786,6 +792,7 @@ declare class BlinkAuth {
786
792
  getValidToken(): Promise<string | null>;
787
793
  /**
788
794
  * Fetch current user profile from API
795
+ * Gracefully waits for auth initialization to complete before throwing errors
789
796
  */
790
797
  me(): Promise<BlinkUser>;
791
798
  /**
package/dist/index.d.ts CHANGED
@@ -743,7 +743,13 @@ declare class BlinkAuth {
743
743
  private readonly authUrl;
744
744
  private parentWindowTokens;
745
745
  private isIframe;
746
+ private initializationPromise;
747
+ private isInitialized;
746
748
  constructor(config: BlinkClientConfig);
749
+ /**
750
+ * Wait for authentication initialization to complete
751
+ */
752
+ private waitForInitialization;
747
753
  /**
748
754
  * Setup listener for tokens from parent window
749
755
  */
@@ -786,6 +792,7 @@ declare class BlinkAuth {
786
792
  getValidToken(): Promise<string | null>;
787
793
  /**
788
794
  * Fetch current user profile from API
795
+ * Gracefully waits for auth initialization to complete before throwing errors
789
796
  */
790
797
  me(): Promise<BlinkUser>;
791
798
  /**
package/dist/index.js CHANGED
@@ -869,6 +869,8 @@ var BlinkAuth = class {
869
869
  authUrl = "https://blink.new";
870
870
  parentWindowTokens = null;
871
871
  isIframe = false;
872
+ initializationPromise = null;
873
+ isInitialized = false;
872
874
  constructor(config) {
873
875
  this.config = config;
874
876
  this.authState = {
@@ -880,7 +882,18 @@ var BlinkAuth = class {
880
882
  if (typeof window !== "undefined") {
881
883
  this.isIframe = window.self !== window.top;
882
884
  this.setupParentWindowListener();
883
- this.initialize();
885
+ this.initializationPromise = this.initialize();
886
+ } else {
887
+ this.isInitialized = true;
888
+ }
889
+ }
890
+ /**
891
+ * Wait for authentication initialization to complete
892
+ */
893
+ async waitForInitialization() {
894
+ if (this.isInitialized) return;
895
+ if (this.initializationPromise) {
896
+ await this.initializationPromise;
884
897
  }
885
898
  }
886
899
  /**
@@ -971,6 +984,7 @@ var BlinkAuth = class {
971
984
  }
972
985
  } finally {
973
986
  this.setLoading(false);
987
+ this.isInitialized = true;
974
988
  }
975
989
  }
976
990
  /**
@@ -1085,8 +1099,36 @@ var BlinkAuth = class {
1085
1099
  }
1086
1100
  /**
1087
1101
  * Fetch current user profile from API
1102
+ * Gracefully waits for auth initialization to complete before throwing errors
1088
1103
  */
1089
1104
  async me() {
1105
+ await this.waitForInitialization();
1106
+ if (this.authState.isAuthenticated && this.authState.user) {
1107
+ return this.authState.user;
1108
+ }
1109
+ if (!this.authState.isAuthenticated) {
1110
+ return new Promise((resolve, reject) => {
1111
+ if (this.authState.user) {
1112
+ resolve(this.authState.user);
1113
+ return;
1114
+ }
1115
+ const timeout = setTimeout(() => {
1116
+ unsubscribe();
1117
+ reject(new BlinkAuthError("Authentication timeout - no user available"));
1118
+ }, 5e3);
1119
+ const unsubscribe = this.onAuthStateChanged((state) => {
1120
+ if (state.user) {
1121
+ clearTimeout(timeout);
1122
+ unsubscribe();
1123
+ resolve(state.user);
1124
+ } else if (!state.isLoading && !state.isAuthenticated) {
1125
+ clearTimeout(timeout);
1126
+ unsubscribe();
1127
+ reject(new BlinkAuthError("Not authenticated"));
1128
+ }
1129
+ });
1130
+ });
1131
+ }
1090
1132
  let token = this.getToken();
1091
1133
  if (!token) {
1092
1134
  throw new BlinkAuthError("No access token available");
package/dist/index.mjs CHANGED
@@ -867,6 +867,8 @@ var BlinkAuth = class {
867
867
  authUrl = "https://blink.new";
868
868
  parentWindowTokens = null;
869
869
  isIframe = false;
870
+ initializationPromise = null;
871
+ isInitialized = false;
870
872
  constructor(config) {
871
873
  this.config = config;
872
874
  this.authState = {
@@ -878,7 +880,18 @@ var BlinkAuth = class {
878
880
  if (typeof window !== "undefined") {
879
881
  this.isIframe = window.self !== window.top;
880
882
  this.setupParentWindowListener();
881
- this.initialize();
883
+ this.initializationPromise = this.initialize();
884
+ } else {
885
+ this.isInitialized = true;
886
+ }
887
+ }
888
+ /**
889
+ * Wait for authentication initialization to complete
890
+ */
891
+ async waitForInitialization() {
892
+ if (this.isInitialized) return;
893
+ if (this.initializationPromise) {
894
+ await this.initializationPromise;
882
895
  }
883
896
  }
884
897
  /**
@@ -969,6 +982,7 @@ var BlinkAuth = class {
969
982
  }
970
983
  } finally {
971
984
  this.setLoading(false);
985
+ this.isInitialized = true;
972
986
  }
973
987
  }
974
988
  /**
@@ -1083,8 +1097,36 @@ var BlinkAuth = class {
1083
1097
  }
1084
1098
  /**
1085
1099
  * Fetch current user profile from API
1100
+ * Gracefully waits for auth initialization to complete before throwing errors
1086
1101
  */
1087
1102
  async me() {
1103
+ await this.waitForInitialization();
1104
+ if (this.authState.isAuthenticated && this.authState.user) {
1105
+ return this.authState.user;
1106
+ }
1107
+ if (!this.authState.isAuthenticated) {
1108
+ return new Promise((resolve, reject) => {
1109
+ if (this.authState.user) {
1110
+ resolve(this.authState.user);
1111
+ return;
1112
+ }
1113
+ const timeout = setTimeout(() => {
1114
+ unsubscribe();
1115
+ reject(new BlinkAuthError("Authentication timeout - no user available"));
1116
+ }, 5e3);
1117
+ const unsubscribe = this.onAuthStateChanged((state) => {
1118
+ if (state.user) {
1119
+ clearTimeout(timeout);
1120
+ unsubscribe();
1121
+ resolve(state.user);
1122
+ } else if (!state.isLoading && !state.isAuthenticated) {
1123
+ clearTimeout(timeout);
1124
+ unsubscribe();
1125
+ reject(new BlinkAuthError("Not authenticated"));
1126
+ }
1127
+ });
1128
+ });
1129
+ }
1088
1130
  let token = this.getToken();
1089
1131
  if (!token) {
1090
1132
  throw new BlinkAuthError("No access token available");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blinkdotnew/sdk",
3
- "version": "0.14.3",
3
+ "version": "0.14.4",
4
4
  "description": "Blink TypeScript SDK for client-side applications - Zero-boilerplate CRUD + auth + AI + analytics + notifications for modern SaaS/AI apps",
5
5
  "keywords": [
6
6
  "blink",