@blinkdotnew/sdk 0.14.2 → 0.14.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.mts CHANGED
@@ -733,7 +733,6 @@ declare class HttpClient {
733
733
  /**
734
734
  * Blink Auth Module - Client-side authentication management
735
735
  * Handles token storage, user state, and authentication flows
736
- * Includes iframe token relay support for seamless preview authentication
737
736
  */
738
737
 
739
738
  type AuthStateChangeCallback = (state: AuthState) => void;
@@ -744,16 +743,11 @@ declare class BlinkAuth {
744
743
  private readonly authUrl;
745
744
  private parentWindowTokens;
746
745
  private isIframe;
747
- private tokenRequestSent;
748
746
  constructor(config: BlinkClientConfig);
749
747
  /**
750
- * Setup listener for tokens from parent window (iframe only)
748
+ * Setup listener for tokens from parent window
751
749
  */
752
750
  private setupParentWindowListener;
753
- /**
754
- * Request tokens from parent window
755
- */
756
- private requestTokensFromParent;
757
751
  /**
758
752
  * Initialize authentication from stored tokens or URL fragments
759
753
  */
package/dist/index.d.ts CHANGED
@@ -733,7 +733,6 @@ declare class HttpClient {
733
733
  /**
734
734
  * Blink Auth Module - Client-side authentication management
735
735
  * Handles token storage, user state, and authentication flows
736
- * Includes iframe token relay support for seamless preview authentication
737
736
  */
738
737
 
739
738
  type AuthStateChangeCallback = (state: AuthState) => void;
@@ -744,16 +743,11 @@ declare class BlinkAuth {
744
743
  private readonly authUrl;
745
744
  private parentWindowTokens;
746
745
  private isIframe;
747
- private tokenRequestSent;
748
746
  constructor(config: BlinkClientConfig);
749
747
  /**
750
- * Setup listener for tokens from parent window (iframe only)
748
+ * Setup listener for tokens from parent window
751
749
  */
752
750
  private setupParentWindowListener;
753
- /**
754
- * Request tokens from parent window
755
- */
756
- private requestTokensFromParent;
757
751
  /**
758
752
  * Initialize authentication from stored tokens or URL fragments
759
753
  */
package/dist/index.js CHANGED
@@ -869,7 +869,6 @@ var BlinkAuth = class {
869
869
  authUrl = "https://blink.new";
870
870
  parentWindowTokens = null;
871
871
  isIframe = false;
872
- tokenRequestSent = false;
873
872
  constructor(config) {
874
873
  this.config = config;
875
874
  this.authState = {
@@ -880,45 +879,28 @@ var BlinkAuth = class {
880
879
  };
881
880
  if (typeof window !== "undefined") {
882
881
  this.isIframe = window.self !== window.top;
883
- if (this.isIframe) {
884
- console.log("\u{1F5BC}\uFE0F Detected iframe environment, setting up parent window communication");
885
- this.setupParentWindowListener();
886
- }
882
+ this.setupParentWindowListener();
887
883
  this.initialize();
888
884
  }
889
885
  }
890
886
  /**
891
- * Setup listener for tokens from parent window (iframe only)
887
+ * Setup listener for tokens from parent window
892
888
  */
893
889
  setupParentWindowListener() {
894
890
  if (!this.isIframe) return;
895
891
  window.addEventListener("message", (event) => {
896
- const trustedOrigins = [
897
- "https://blink.new",
898
- "http://localhost:3000",
899
- "http://localhost:3001",
900
- "https://localhost:3000",
901
- "https://localhost:3001"
902
- ];
903
- if (!trustedOrigins.includes(event.origin)) {
892
+ if (event.origin !== "https://blink.new" && event.origin !== "http://localhost:3000" && event.origin !== "http://localhost:3001") {
904
893
  return;
905
894
  }
906
895
  if (event.data?.type === "BLINK_AUTH_TOKENS") {
907
- console.log("\u{1F4E5} Received auth tokens from parent window", {
908
- hasTokens: !!event.data.tokens,
909
- projectId: event.data.projectId
910
- });
911
- const { tokens, projectId } = event.data;
912
- if (projectId && projectId !== this.config.projectId) {
913
- console.log("\u26A0\uFE0F Ignoring tokens for different project:", projectId);
914
- return;
915
- }
896
+ console.log("\u{1F4E5} Received auth tokens from parent window");
897
+ const { tokens } = event.data;
916
898
  if (tokens) {
917
899
  this.parentWindowTokens = tokens;
918
900
  this.setTokens(tokens, false).then(() => {
919
- console.log("\u2705 Tokens from parent window applied successfully");
901
+ console.log("\u2705 Tokens from parent window applied");
920
902
  }).catch((error) => {
921
- console.error("\u274C Failed to apply parent window tokens:", error);
903
+ console.error("Failed to apply parent window tokens:", error);
922
904
  });
923
905
  }
924
906
  }
@@ -926,31 +908,13 @@ var BlinkAuth = class {
926
908
  console.log("\u{1F4E4} Received logout command from parent window");
927
909
  this.clearTokens();
928
910
  }
929
- if (event.data?.type === "BLINK_AUTH_REFRESH") {
930
- console.log("\u{1F504} Received token refresh from parent window");
931
- const { tokens } = event.data;
932
- if (tokens) {
933
- this.parentWindowTokens = tokens;
934
- this.setTokens(tokens, false).catch((error) => {
935
- console.error("\u274C Failed to apply refreshed tokens:", error);
936
- });
937
- }
938
- }
939
911
  });
940
- this.requestTokensFromParent();
941
- }
942
- /**
943
- * Request tokens from parent window
944
- */
945
- requestTokensFromParent() {
946
- if (!this.isIframe || this.tokenRequestSent) return;
947
912
  if (window.parent !== window) {
948
913
  console.log("\u{1F504} Requesting auth tokens from parent window");
949
914
  window.parent.postMessage({
950
915
  type: "BLINK_REQUEST_AUTH_TOKENS",
951
916
  projectId: this.config.projectId
952
917
  }, "*");
953
- this.tokenRequestSent = true;
954
918
  }
955
919
  }
956
920
  /**
@@ -962,15 +926,12 @@ var BlinkAuth = class {
962
926
  try {
963
927
  if (this.isIframe) {
964
928
  console.log("\u{1F50D} Detected iframe environment, waiting for parent tokens...");
965
- for (let i = 0; i < 10; i++) {
966
- if (this.parentWindowTokens) {
967
- console.log("\u2705 Using tokens from parent window");
968
- await this.setTokens(this.parentWindowTokens, false);
969
- return;
970
- }
971
- await new Promise((resolve) => setTimeout(resolve, 100));
929
+ await new Promise((resolve) => setTimeout(resolve, 100));
930
+ if (this.parentWindowTokens) {
931
+ console.log("\u2705 Using tokens from parent window");
932
+ await this.setTokens(this.parentWindowTokens, false);
933
+ return;
972
934
  }
973
- console.log("\u23F0 Timeout waiting for parent tokens, continuing with normal flow...");
974
935
  }
975
936
  const tokensFromUrl = this.extractTokensFromUrl();
976
937
  if (tokensFromUrl) {
@@ -1003,14 +964,6 @@ var BlinkAuth = class {
1003
964
  }
1004
965
  console.log("\u274C No tokens found");
1005
966
  if (this.config.authRequired) {
1006
- if (this.isIframe && !this.tokenRequestSent) {
1007
- this.requestTokensFromParent();
1008
- await new Promise((resolve) => setTimeout(resolve, 500));
1009
- if (this.parentWindowTokens) {
1010
- await this.setTokens(this.parentWindowTokens, false);
1011
- return;
1012
- }
1013
- }
1014
967
  console.log("\u{1F504} Auth required, redirecting to auth page...");
1015
968
  this.redirectToAuth();
1016
969
  } else {
@@ -1049,12 +1002,6 @@ var BlinkAuth = class {
1049
1002
  */
1050
1003
  logout(redirectUrl) {
1051
1004
  this.clearTokens();
1052
- if (this.isIframe && window.parent !== window) {
1053
- window.parent.postMessage({
1054
- type: "BLINK_AUTH_LOGOUT_IFRAME",
1055
- projectId: this.config.projectId
1056
- }, "*");
1057
- }
1058
1005
  if (redirectUrl && typeof window !== "undefined") {
1059
1006
  window.location.href = redirectUrl;
1060
1007
  }
@@ -1273,7 +1220,7 @@ var BlinkAuth = class {
1273
1220
  token_type: data.token_type,
1274
1221
  expires_in: data.expires_in,
1275
1222
  refresh_expires_in: data.refresh_expires_in
1276
- }, !this.isIframe);
1223
+ }, true);
1277
1224
  return true;
1278
1225
  } catch (error) {
1279
1226
  console.error("Token refresh failed:", error);
@@ -1350,7 +1297,7 @@ var BlinkAuth = class {
1350
1297
  return false;
1351
1298
  }
1352
1299
  } catch (error) {
1353
- console.log("\uFFFD\uFFFD Error validating tokens:", error);
1300
+ console.log("\u{1F4A5} Error validating tokens:", error);
1354
1301
  return false;
1355
1302
  }
1356
1303
  }
@@ -1364,10 +1311,9 @@ var BlinkAuth = class {
1364
1311
  hasAccessToken: !!tokensWithTimestamp.access_token,
1365
1312
  hasRefreshToken: !!tokensWithTimestamp.refresh_token,
1366
1313
  expiresIn: tokensWithTimestamp.expires_in,
1367
- issuedAt: tokensWithTimestamp.issued_at,
1368
- isIframe: this.isIframe
1314
+ issuedAt: tokensWithTimestamp.issued_at
1369
1315
  });
1370
- if (persist && !this.isIframe && typeof window !== "undefined") {
1316
+ if (persist && typeof window !== "undefined") {
1371
1317
  try {
1372
1318
  localStorage.setItem("blink_tokens", JSON.stringify(tokensWithTimestamp));
1373
1319
  console.log("\u{1F4BE} Tokens persisted to localStorage");
@@ -1418,7 +1364,6 @@ var BlinkAuth = class {
1418
1364
  });
1419
1365
  }
1420
1366
  clearTokens() {
1421
- this.parentWindowTokens = null;
1422
1367
  if (typeof window !== "undefined") {
1423
1368
  try {
1424
1369
  localStorage.removeItem("blink_tokens");
@@ -1436,7 +1381,6 @@ var BlinkAuth = class {
1436
1381
  getStoredTokens() {
1437
1382
  if (typeof window === "undefined") return null;
1438
1383
  if (this.isIframe && this.parentWindowTokens) {
1439
- console.log("\u{1F4E6} Using parent window tokens");
1440
1384
  return this.parentWindowTokens;
1441
1385
  }
1442
1386
  try {
@@ -1445,7 +1389,7 @@ var BlinkAuth = class {
1445
1389
  hasStoredData: !!stored,
1446
1390
  storedLength: stored?.length || 0,
1447
1391
  origin: window.location.origin,
1448
- isIframe: this.isIframe
1392
+ isIframe: window.self !== window.top
1449
1393
  });
1450
1394
  if (stored) {
1451
1395
  const tokens = JSON.parse(stored);
package/dist/index.mjs CHANGED
@@ -867,7 +867,6 @@ var BlinkAuth = class {
867
867
  authUrl = "https://blink.new";
868
868
  parentWindowTokens = null;
869
869
  isIframe = false;
870
- tokenRequestSent = false;
871
870
  constructor(config) {
872
871
  this.config = config;
873
872
  this.authState = {
@@ -878,45 +877,28 @@ var BlinkAuth = class {
878
877
  };
879
878
  if (typeof window !== "undefined") {
880
879
  this.isIframe = window.self !== window.top;
881
- if (this.isIframe) {
882
- console.log("\u{1F5BC}\uFE0F Detected iframe environment, setting up parent window communication");
883
- this.setupParentWindowListener();
884
- }
880
+ this.setupParentWindowListener();
885
881
  this.initialize();
886
882
  }
887
883
  }
888
884
  /**
889
- * Setup listener for tokens from parent window (iframe only)
885
+ * Setup listener for tokens from parent window
890
886
  */
891
887
  setupParentWindowListener() {
892
888
  if (!this.isIframe) return;
893
889
  window.addEventListener("message", (event) => {
894
- const trustedOrigins = [
895
- "https://blink.new",
896
- "http://localhost:3000",
897
- "http://localhost:3001",
898
- "https://localhost:3000",
899
- "https://localhost:3001"
900
- ];
901
- if (!trustedOrigins.includes(event.origin)) {
890
+ if (event.origin !== "https://blink.new" && event.origin !== "http://localhost:3000" && event.origin !== "http://localhost:3001") {
902
891
  return;
903
892
  }
904
893
  if (event.data?.type === "BLINK_AUTH_TOKENS") {
905
- console.log("\u{1F4E5} Received auth tokens from parent window", {
906
- hasTokens: !!event.data.tokens,
907
- projectId: event.data.projectId
908
- });
909
- const { tokens, projectId } = event.data;
910
- if (projectId && projectId !== this.config.projectId) {
911
- console.log("\u26A0\uFE0F Ignoring tokens for different project:", projectId);
912
- return;
913
- }
894
+ console.log("\u{1F4E5} Received auth tokens from parent window");
895
+ const { tokens } = event.data;
914
896
  if (tokens) {
915
897
  this.parentWindowTokens = tokens;
916
898
  this.setTokens(tokens, false).then(() => {
917
- console.log("\u2705 Tokens from parent window applied successfully");
899
+ console.log("\u2705 Tokens from parent window applied");
918
900
  }).catch((error) => {
919
- console.error("\u274C Failed to apply parent window tokens:", error);
901
+ console.error("Failed to apply parent window tokens:", error);
920
902
  });
921
903
  }
922
904
  }
@@ -924,31 +906,13 @@ var BlinkAuth = class {
924
906
  console.log("\u{1F4E4} Received logout command from parent window");
925
907
  this.clearTokens();
926
908
  }
927
- if (event.data?.type === "BLINK_AUTH_REFRESH") {
928
- console.log("\u{1F504} Received token refresh from parent window");
929
- const { tokens } = event.data;
930
- if (tokens) {
931
- this.parentWindowTokens = tokens;
932
- this.setTokens(tokens, false).catch((error) => {
933
- console.error("\u274C Failed to apply refreshed tokens:", error);
934
- });
935
- }
936
- }
937
909
  });
938
- this.requestTokensFromParent();
939
- }
940
- /**
941
- * Request tokens from parent window
942
- */
943
- requestTokensFromParent() {
944
- if (!this.isIframe || this.tokenRequestSent) return;
945
910
  if (window.parent !== window) {
946
911
  console.log("\u{1F504} Requesting auth tokens from parent window");
947
912
  window.parent.postMessage({
948
913
  type: "BLINK_REQUEST_AUTH_TOKENS",
949
914
  projectId: this.config.projectId
950
915
  }, "*");
951
- this.tokenRequestSent = true;
952
916
  }
953
917
  }
954
918
  /**
@@ -960,15 +924,12 @@ var BlinkAuth = class {
960
924
  try {
961
925
  if (this.isIframe) {
962
926
  console.log("\u{1F50D} Detected iframe environment, waiting for parent tokens...");
963
- for (let i = 0; i < 10; i++) {
964
- if (this.parentWindowTokens) {
965
- console.log("\u2705 Using tokens from parent window");
966
- await this.setTokens(this.parentWindowTokens, false);
967
- return;
968
- }
969
- await new Promise((resolve) => setTimeout(resolve, 100));
927
+ await new Promise((resolve) => setTimeout(resolve, 100));
928
+ if (this.parentWindowTokens) {
929
+ console.log("\u2705 Using tokens from parent window");
930
+ await this.setTokens(this.parentWindowTokens, false);
931
+ return;
970
932
  }
971
- console.log("\u23F0 Timeout waiting for parent tokens, continuing with normal flow...");
972
933
  }
973
934
  const tokensFromUrl = this.extractTokensFromUrl();
974
935
  if (tokensFromUrl) {
@@ -1001,14 +962,6 @@ var BlinkAuth = class {
1001
962
  }
1002
963
  console.log("\u274C No tokens found");
1003
964
  if (this.config.authRequired) {
1004
- if (this.isIframe && !this.tokenRequestSent) {
1005
- this.requestTokensFromParent();
1006
- await new Promise((resolve) => setTimeout(resolve, 500));
1007
- if (this.parentWindowTokens) {
1008
- await this.setTokens(this.parentWindowTokens, false);
1009
- return;
1010
- }
1011
- }
1012
965
  console.log("\u{1F504} Auth required, redirecting to auth page...");
1013
966
  this.redirectToAuth();
1014
967
  } else {
@@ -1047,12 +1000,6 @@ var BlinkAuth = class {
1047
1000
  */
1048
1001
  logout(redirectUrl) {
1049
1002
  this.clearTokens();
1050
- if (this.isIframe && window.parent !== window) {
1051
- window.parent.postMessage({
1052
- type: "BLINK_AUTH_LOGOUT_IFRAME",
1053
- projectId: this.config.projectId
1054
- }, "*");
1055
- }
1056
1003
  if (redirectUrl && typeof window !== "undefined") {
1057
1004
  window.location.href = redirectUrl;
1058
1005
  }
@@ -1271,7 +1218,7 @@ var BlinkAuth = class {
1271
1218
  token_type: data.token_type,
1272
1219
  expires_in: data.expires_in,
1273
1220
  refresh_expires_in: data.refresh_expires_in
1274
- }, !this.isIframe);
1221
+ }, true);
1275
1222
  return true;
1276
1223
  } catch (error) {
1277
1224
  console.error("Token refresh failed:", error);
@@ -1348,7 +1295,7 @@ var BlinkAuth = class {
1348
1295
  return false;
1349
1296
  }
1350
1297
  } catch (error) {
1351
- console.log("\uFFFD\uFFFD Error validating tokens:", error);
1298
+ console.log("\u{1F4A5} Error validating tokens:", error);
1352
1299
  return false;
1353
1300
  }
1354
1301
  }
@@ -1362,10 +1309,9 @@ var BlinkAuth = class {
1362
1309
  hasAccessToken: !!tokensWithTimestamp.access_token,
1363
1310
  hasRefreshToken: !!tokensWithTimestamp.refresh_token,
1364
1311
  expiresIn: tokensWithTimestamp.expires_in,
1365
- issuedAt: tokensWithTimestamp.issued_at,
1366
- isIframe: this.isIframe
1312
+ issuedAt: tokensWithTimestamp.issued_at
1367
1313
  });
1368
- if (persist && !this.isIframe && typeof window !== "undefined") {
1314
+ if (persist && typeof window !== "undefined") {
1369
1315
  try {
1370
1316
  localStorage.setItem("blink_tokens", JSON.stringify(tokensWithTimestamp));
1371
1317
  console.log("\u{1F4BE} Tokens persisted to localStorage");
@@ -1416,7 +1362,6 @@ var BlinkAuth = class {
1416
1362
  });
1417
1363
  }
1418
1364
  clearTokens() {
1419
- this.parentWindowTokens = null;
1420
1365
  if (typeof window !== "undefined") {
1421
1366
  try {
1422
1367
  localStorage.removeItem("blink_tokens");
@@ -1434,7 +1379,6 @@ var BlinkAuth = class {
1434
1379
  getStoredTokens() {
1435
1380
  if (typeof window === "undefined") return null;
1436
1381
  if (this.isIframe && this.parentWindowTokens) {
1437
- console.log("\u{1F4E6} Using parent window tokens");
1438
1382
  return this.parentWindowTokens;
1439
1383
  }
1440
1384
  try {
@@ -1443,7 +1387,7 @@ var BlinkAuth = class {
1443
1387
  hasStoredData: !!stored,
1444
1388
  storedLength: stored?.length || 0,
1445
1389
  origin: window.location.origin,
1446
- isIframe: this.isIframe
1390
+ isIframe: window.self !== window.top
1447
1391
  });
1448
1392
  if (stored) {
1449
1393
  const tokens = JSON.parse(stored);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blinkdotnew/sdk",
3
- "version": "0.14.2",
3
+ "version": "0.14.3",
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",