@blinkdotnew/sdk 0.14.1 → 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
@@ -741,7 +741,13 @@ declare class BlinkAuth {
741
741
  private authState;
742
742
  private listeners;
743
743
  private readonly authUrl;
744
+ private parentWindowTokens;
745
+ private isIframe;
744
746
  constructor(config: BlinkClientConfig);
747
+ /**
748
+ * Setup listener for tokens from parent window
749
+ */
750
+ private setupParentWindowListener;
745
751
  /**
746
752
  * Initialize authentication from stored tokens or URL fragments
747
753
  */
package/dist/index.d.ts CHANGED
@@ -741,7 +741,13 @@ declare class BlinkAuth {
741
741
  private authState;
742
742
  private listeners;
743
743
  private readonly authUrl;
744
+ private parentWindowTokens;
745
+ private isIframe;
744
746
  constructor(config: BlinkClientConfig);
747
+ /**
748
+ * Setup listener for tokens from parent window
749
+ */
750
+ private setupParentWindowListener;
745
751
  /**
746
752
  * Initialize authentication from stored tokens or URL fragments
747
753
  */
package/dist/index.js CHANGED
@@ -867,6 +867,8 @@ var BlinkAuth = class {
867
867
  authState;
868
868
  listeners = /* @__PURE__ */ new Set();
869
869
  authUrl = "https://blink.new";
870
+ parentWindowTokens = null;
871
+ isIframe = false;
870
872
  constructor(config) {
871
873
  this.config = config;
872
874
  this.authState = {
@@ -876,9 +878,45 @@ var BlinkAuth = class {
876
878
  isLoading: false
877
879
  };
878
880
  if (typeof window !== "undefined") {
881
+ this.isIframe = window.self !== window.top;
882
+ this.setupParentWindowListener();
879
883
  this.initialize();
880
884
  }
881
885
  }
886
+ /**
887
+ * Setup listener for tokens from parent window
888
+ */
889
+ setupParentWindowListener() {
890
+ if (!this.isIframe) return;
891
+ window.addEventListener("message", (event) => {
892
+ if (event.origin !== "https://blink.new" && event.origin !== "http://localhost:3000" && event.origin !== "http://localhost:3001") {
893
+ return;
894
+ }
895
+ if (event.data?.type === "BLINK_AUTH_TOKENS") {
896
+ console.log("\u{1F4E5} Received auth tokens from parent window");
897
+ const { tokens } = event.data;
898
+ if (tokens) {
899
+ this.parentWindowTokens = tokens;
900
+ this.setTokens(tokens, false).then(() => {
901
+ console.log("\u2705 Tokens from parent window applied");
902
+ }).catch((error) => {
903
+ console.error("Failed to apply parent window tokens:", error);
904
+ });
905
+ }
906
+ }
907
+ if (event.data?.type === "BLINK_AUTH_LOGOUT") {
908
+ console.log("\u{1F4E4} Received logout command from parent window");
909
+ this.clearTokens();
910
+ }
911
+ });
912
+ if (window.parent !== window) {
913
+ console.log("\u{1F504} Requesting auth tokens from parent window");
914
+ window.parent.postMessage({
915
+ type: "BLINK_REQUEST_AUTH_TOKENS",
916
+ projectId: this.config.projectId
917
+ }, "*");
918
+ }
919
+ }
882
920
  /**
883
921
  * Initialize authentication from stored tokens or URL fragments
884
922
  */
@@ -886,6 +924,15 @@ var BlinkAuth = class {
886
924
  console.log("\u{1F680} Initializing Blink Auth...");
887
925
  this.setLoading(true);
888
926
  try {
927
+ if (this.isIframe) {
928
+ console.log("\u{1F50D} Detected iframe environment, waiting for parent tokens...");
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;
934
+ }
935
+ }
889
936
  const tokensFromUrl = this.extractTokensFromUrl();
890
937
  if (tokensFromUrl) {
891
938
  console.log("\u{1F4E5} Found tokens in URL, setting them...");
@@ -1333,6 +1380,9 @@ var BlinkAuth = class {
1333
1380
  }
1334
1381
  getStoredTokens() {
1335
1382
  if (typeof window === "undefined") return null;
1383
+ if (this.isIframe && this.parentWindowTokens) {
1384
+ return this.parentWindowTokens;
1385
+ }
1336
1386
  try {
1337
1387
  const stored = localStorage.getItem("blink_tokens");
1338
1388
  console.log("\u{1F50D} Checking localStorage for tokens:", {
package/dist/index.mjs CHANGED
@@ -865,6 +865,8 @@ var BlinkAuth = class {
865
865
  authState;
866
866
  listeners = /* @__PURE__ */ new Set();
867
867
  authUrl = "https://blink.new";
868
+ parentWindowTokens = null;
869
+ isIframe = false;
868
870
  constructor(config) {
869
871
  this.config = config;
870
872
  this.authState = {
@@ -874,9 +876,45 @@ var BlinkAuth = class {
874
876
  isLoading: false
875
877
  };
876
878
  if (typeof window !== "undefined") {
879
+ this.isIframe = window.self !== window.top;
880
+ this.setupParentWindowListener();
877
881
  this.initialize();
878
882
  }
879
883
  }
884
+ /**
885
+ * Setup listener for tokens from parent window
886
+ */
887
+ setupParentWindowListener() {
888
+ if (!this.isIframe) return;
889
+ window.addEventListener("message", (event) => {
890
+ if (event.origin !== "https://blink.new" && event.origin !== "http://localhost:3000" && event.origin !== "http://localhost:3001") {
891
+ return;
892
+ }
893
+ if (event.data?.type === "BLINK_AUTH_TOKENS") {
894
+ console.log("\u{1F4E5} Received auth tokens from parent window");
895
+ const { tokens } = event.data;
896
+ if (tokens) {
897
+ this.parentWindowTokens = tokens;
898
+ this.setTokens(tokens, false).then(() => {
899
+ console.log("\u2705 Tokens from parent window applied");
900
+ }).catch((error) => {
901
+ console.error("Failed to apply parent window tokens:", error);
902
+ });
903
+ }
904
+ }
905
+ if (event.data?.type === "BLINK_AUTH_LOGOUT") {
906
+ console.log("\u{1F4E4} Received logout command from parent window");
907
+ this.clearTokens();
908
+ }
909
+ });
910
+ if (window.parent !== window) {
911
+ console.log("\u{1F504} Requesting auth tokens from parent window");
912
+ window.parent.postMessage({
913
+ type: "BLINK_REQUEST_AUTH_TOKENS",
914
+ projectId: this.config.projectId
915
+ }, "*");
916
+ }
917
+ }
880
918
  /**
881
919
  * Initialize authentication from stored tokens or URL fragments
882
920
  */
@@ -884,6 +922,15 @@ var BlinkAuth = class {
884
922
  console.log("\u{1F680} Initializing Blink Auth...");
885
923
  this.setLoading(true);
886
924
  try {
925
+ if (this.isIframe) {
926
+ console.log("\u{1F50D} Detected iframe environment, waiting for parent tokens...");
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;
932
+ }
933
+ }
887
934
  const tokensFromUrl = this.extractTokensFromUrl();
888
935
  if (tokensFromUrl) {
889
936
  console.log("\u{1F4E5} Found tokens in URL, setting them...");
@@ -1331,6 +1378,9 @@ var BlinkAuth = class {
1331
1378
  }
1332
1379
  getStoredTokens() {
1333
1380
  if (typeof window === "undefined") return null;
1381
+ if (this.isIframe && this.parentWindowTokens) {
1382
+ return this.parentWindowTokens;
1383
+ }
1334
1384
  try {
1335
1385
  const stored = localStorage.getItem("blink_tokens");
1336
1386
  console.log("\u{1F50D} Checking localStorage for tokens:", {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blinkdotnew/sdk",
3
- "version": "0.14.1",
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",