@blinkdotnew/dev-sdk 2.1.4 → 2.1.5

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
@@ -1161,6 +1161,10 @@ declare class BlinkAuth {
1161
1161
  * Redirect to Blink auth page
1162
1162
  */
1163
1163
  login(nextUrl?: string): void;
1164
+ /**
1165
+ * Set up listener for tokens from parent window (for iframe OAuth delegation)
1166
+ */
1167
+ private setupParentTokenListener;
1164
1168
  /**
1165
1169
  * Logout and clear stored tokens
1166
1170
  */
@@ -1325,11 +1329,6 @@ declare class BlinkAuth {
1325
1329
  * Uses expo-web-browser to open auth URL and polls for completion
1326
1330
  */
1327
1331
  private signInWithProviderUniversal;
1328
- /**
1329
- * OAuth flow via parent window (for iframe context)
1330
- * Delegates OAuth to parent window since OAuth providers block flows inside iframes
1331
- */
1332
- private signInWithProviderViaParent;
1333
1332
  /**
1334
1333
  * Generic provider sign-in method (headless mode)
1335
1334
  *
package/dist/index.d.ts CHANGED
@@ -1161,6 +1161,10 @@ declare class BlinkAuth {
1161
1161
  * Redirect to Blink auth page
1162
1162
  */
1163
1163
  login(nextUrl?: string): void;
1164
+ /**
1165
+ * Set up listener for tokens from parent window (for iframe OAuth delegation)
1166
+ */
1167
+ private setupParentTokenListener;
1164
1168
  /**
1165
1169
  * Logout and clear stored tokens
1166
1170
  */
@@ -1325,11 +1329,6 @@ declare class BlinkAuth {
1325
1329
  * Uses expo-web-browser to open auth URL and polls for completion
1326
1330
  */
1327
1331
  private signInWithProviderUniversal;
1328
- /**
1329
- * OAuth flow via parent window (for iframe context)
1330
- * Delegates OAuth to parent window since OAuth providers block flows inside iframes
1331
- */
1332
- private signInWithProviderViaParent;
1333
1332
  /**
1334
1333
  * Generic provider sign-in method (headless mode)
1335
1334
  *
package/dist/index.js CHANGED
@@ -1464,6 +1464,17 @@ var BlinkAuth = class {
1464
1464
  console.warn("Failed to parse redirect URL:", e);
1465
1465
  }
1466
1466
  }
1467
+ if (isWeb && this.isIframe && hasWindow() && window.parent !== window) {
1468
+ console.log("\u{1F5BC}\uFE0F In iframe, delegating login to parent window");
1469
+ this.setupParentTokenListener();
1470
+ window.parent.postMessage({
1471
+ type: "BLINK_AUTH_LOGIN_REQUEST",
1472
+ projectId: this.config.projectId,
1473
+ redirectUrl: redirectUrl || "",
1474
+ authUrl: this.authUrl
1475
+ }, "*");
1476
+ return;
1477
+ }
1467
1478
  const authUrl = new URL("/auth", this.authUrl);
1468
1479
  authUrl.searchParams.set("redirect_url", redirectUrl || "");
1469
1480
  if (this.config.projectId) {
@@ -1471,6 +1482,34 @@ var BlinkAuth = class {
1471
1482
  }
1472
1483
  window.location.href = authUrl.toString();
1473
1484
  }
1485
+ /**
1486
+ * Set up listener for tokens from parent window (for iframe OAuth delegation)
1487
+ */
1488
+ setupParentTokenListener() {
1489
+ if (typeof window === "undefined") return;
1490
+ const messageListener = (event) => {
1491
+ const { type, access_token, refresh_token, expires_in, refresh_expires_in, issued_at, projectId, error } = event.data || {};
1492
+ if (type === "BLINK_AUTH_TOKENS") {
1493
+ if (projectId && projectId !== this.config.projectId) {
1494
+ return;
1495
+ }
1496
+ console.log("\u{1F4E5} Received auth tokens from parent window");
1497
+ window.removeEventListener("message", messageListener);
1498
+ this.setTokens({
1499
+ access_token,
1500
+ refresh_token,
1501
+ token_type: "Bearer",
1502
+ expires_in: expires_in || 3600,
1503
+ refresh_expires_in,
1504
+ issued_at: issued_at || Math.floor(Date.now() / 1e3)
1505
+ }, true);
1506
+ } else if (type === "BLINK_AUTH_ERROR") {
1507
+ window.removeEventListener("message", messageListener);
1508
+ console.error("Auth error from parent:", error);
1509
+ }
1510
+ };
1511
+ window.addEventListener("message", messageListener);
1512
+ }
1474
1513
  /**
1475
1514
  * Logout and clear stored tokens
1476
1515
  */
@@ -1966,67 +2005,6 @@ var BlinkAuth = class {
1966
2005
  throw pollError;
1967
2006
  }
1968
2007
  }
1969
- /**
1970
- * OAuth flow via parent window (for iframe context)
1971
- * Delegates OAuth to parent window since OAuth providers block flows inside iframes
1972
- */
1973
- signInWithProviderViaParent(provider, options) {
1974
- return new Promise((resolve, reject) => {
1975
- const state = this.generateState();
1976
- const redirectUrl = options?.redirectUrl || getLocationOrigin() || "";
1977
- let timeoutId;
1978
- let cleanedUp = false;
1979
- const cleanup = () => {
1980
- if (cleanedUp) return;
1981
- cleanedUp = true;
1982
- clearTimeout(timeoutId);
1983
- window.removeEventListener("message", messageListener);
1984
- };
1985
- const messageListener = (event) => {
1986
- const { type, access_token, refresh_token, expires_in, refresh_expires_in, issued_at, projectId, error } = event.data || {};
1987
- if (type === "BLINK_AUTH_TOKENS") {
1988
- if (projectId && projectId !== this.config.projectId) {
1989
- return;
1990
- }
1991
- console.log("\u{1F4E5} Received auth tokens from parent window");
1992
- this.setTokens({
1993
- access_token,
1994
- refresh_token,
1995
- token_type: "Bearer",
1996
- expires_in: expires_in || 3600,
1997
- refresh_expires_in,
1998
- issued_at: issued_at || Math.floor(Date.now() / 1e3)
1999
- }, true).then(() => {
2000
- cleanup();
2001
- resolve(this.authState.user);
2002
- }).catch((err) => {
2003
- cleanup();
2004
- reject(err);
2005
- });
2006
- } else if (type === "BLINK_AUTH_ERROR") {
2007
- cleanup();
2008
- reject(new BlinkAuthError(
2009
- "POPUP_CANCELED" /* POPUP_CANCELED */,
2010
- error || "Authentication failed"
2011
- ));
2012
- }
2013
- };
2014
- window.addEventListener("message", messageListener);
2015
- timeoutId = setTimeout(() => {
2016
- cleanup();
2017
- reject(new BlinkAuthError("AUTH_TIMEOUT" /* AUTH_TIMEOUT */, "Authentication timed out"));
2018
- }, 3e5);
2019
- console.log("\u{1F4E4} Sending OAuth request to parent window");
2020
- window.parent.postMessage({
2021
- type: "BLINK_AUTH_OAUTH_REQUEST",
2022
- provider,
2023
- projectId: this.config.projectId,
2024
- redirectUrl,
2025
- state,
2026
- authUrl: this.authUrl
2027
- }, "*");
2028
- });
2029
- }
2030
2008
  /**
2031
2009
  * Generic provider sign-in method (headless mode)
2032
2010
  *
@@ -2073,10 +2051,7 @@ var BlinkAuth = class {
2073
2051
  if (!hasWindow()) {
2074
2052
  throw new BlinkAuthError("NETWORK_ERROR" /* NETWORK_ERROR */, "signInWithProvider requires a browser environment");
2075
2053
  }
2076
- if (isWeb && this.isIframe && hasWindow() && window.parent !== window) {
2077
- console.log("\u{1F5BC}\uFE0F In iframe, delegating OAuth to parent window");
2078
- return this.signInWithProviderViaParent(provider, options);
2079
- }
2054
+ const shouldPreferRedirect = isWeb && this.isIframe || typeof window !== "undefined" && window.crossOriginIsolated === true;
2080
2055
  const state = this.generateState();
2081
2056
  try {
2082
2057
  const sessionStorage = getSessionStorage();
@@ -2096,7 +2071,6 @@ var BlinkAuth = class {
2096
2071
  url.searchParams.set("opener_origin", getLocationOrigin() || "");
2097
2072
  return url;
2098
2073
  };
2099
- const shouldPreferRedirect = typeof window !== "undefined" && window.crossOriginIsolated === true;
2100
2074
  if (shouldPreferRedirect) {
2101
2075
  window.location.href = buildAuthUrl("redirect").toString();
2102
2076
  return new Promise(() => {
package/dist/index.mjs CHANGED
@@ -1462,6 +1462,17 @@ var BlinkAuth = class {
1462
1462
  console.warn("Failed to parse redirect URL:", e);
1463
1463
  }
1464
1464
  }
1465
+ if (isWeb && this.isIframe && hasWindow() && window.parent !== window) {
1466
+ console.log("\u{1F5BC}\uFE0F In iframe, delegating login to parent window");
1467
+ this.setupParentTokenListener();
1468
+ window.parent.postMessage({
1469
+ type: "BLINK_AUTH_LOGIN_REQUEST",
1470
+ projectId: this.config.projectId,
1471
+ redirectUrl: redirectUrl || "",
1472
+ authUrl: this.authUrl
1473
+ }, "*");
1474
+ return;
1475
+ }
1465
1476
  const authUrl = new URL("/auth", this.authUrl);
1466
1477
  authUrl.searchParams.set("redirect_url", redirectUrl || "");
1467
1478
  if (this.config.projectId) {
@@ -1469,6 +1480,34 @@ var BlinkAuth = class {
1469
1480
  }
1470
1481
  window.location.href = authUrl.toString();
1471
1482
  }
1483
+ /**
1484
+ * Set up listener for tokens from parent window (for iframe OAuth delegation)
1485
+ */
1486
+ setupParentTokenListener() {
1487
+ if (typeof window === "undefined") return;
1488
+ const messageListener = (event) => {
1489
+ const { type, access_token, refresh_token, expires_in, refresh_expires_in, issued_at, projectId, error } = event.data || {};
1490
+ if (type === "BLINK_AUTH_TOKENS") {
1491
+ if (projectId && projectId !== this.config.projectId) {
1492
+ return;
1493
+ }
1494
+ console.log("\u{1F4E5} Received auth tokens from parent window");
1495
+ window.removeEventListener("message", messageListener);
1496
+ this.setTokens({
1497
+ access_token,
1498
+ refresh_token,
1499
+ token_type: "Bearer",
1500
+ expires_in: expires_in || 3600,
1501
+ refresh_expires_in,
1502
+ issued_at: issued_at || Math.floor(Date.now() / 1e3)
1503
+ }, true);
1504
+ } else if (type === "BLINK_AUTH_ERROR") {
1505
+ window.removeEventListener("message", messageListener);
1506
+ console.error("Auth error from parent:", error);
1507
+ }
1508
+ };
1509
+ window.addEventListener("message", messageListener);
1510
+ }
1472
1511
  /**
1473
1512
  * Logout and clear stored tokens
1474
1513
  */
@@ -1964,67 +2003,6 @@ var BlinkAuth = class {
1964
2003
  throw pollError;
1965
2004
  }
1966
2005
  }
1967
- /**
1968
- * OAuth flow via parent window (for iframe context)
1969
- * Delegates OAuth to parent window since OAuth providers block flows inside iframes
1970
- */
1971
- signInWithProviderViaParent(provider, options) {
1972
- return new Promise((resolve, reject) => {
1973
- const state = this.generateState();
1974
- const redirectUrl = options?.redirectUrl || getLocationOrigin() || "";
1975
- let timeoutId;
1976
- let cleanedUp = false;
1977
- const cleanup = () => {
1978
- if (cleanedUp) return;
1979
- cleanedUp = true;
1980
- clearTimeout(timeoutId);
1981
- window.removeEventListener("message", messageListener);
1982
- };
1983
- const messageListener = (event) => {
1984
- const { type, access_token, refresh_token, expires_in, refresh_expires_in, issued_at, projectId, error } = event.data || {};
1985
- if (type === "BLINK_AUTH_TOKENS") {
1986
- if (projectId && projectId !== this.config.projectId) {
1987
- return;
1988
- }
1989
- console.log("\u{1F4E5} Received auth tokens from parent window");
1990
- this.setTokens({
1991
- access_token,
1992
- refresh_token,
1993
- token_type: "Bearer",
1994
- expires_in: expires_in || 3600,
1995
- refresh_expires_in,
1996
- issued_at: issued_at || Math.floor(Date.now() / 1e3)
1997
- }, true).then(() => {
1998
- cleanup();
1999
- resolve(this.authState.user);
2000
- }).catch((err) => {
2001
- cleanup();
2002
- reject(err);
2003
- });
2004
- } else if (type === "BLINK_AUTH_ERROR") {
2005
- cleanup();
2006
- reject(new BlinkAuthError(
2007
- "POPUP_CANCELED" /* POPUP_CANCELED */,
2008
- error || "Authentication failed"
2009
- ));
2010
- }
2011
- };
2012
- window.addEventListener("message", messageListener);
2013
- timeoutId = setTimeout(() => {
2014
- cleanup();
2015
- reject(new BlinkAuthError("AUTH_TIMEOUT" /* AUTH_TIMEOUT */, "Authentication timed out"));
2016
- }, 3e5);
2017
- console.log("\u{1F4E4} Sending OAuth request to parent window");
2018
- window.parent.postMessage({
2019
- type: "BLINK_AUTH_OAUTH_REQUEST",
2020
- provider,
2021
- projectId: this.config.projectId,
2022
- redirectUrl,
2023
- state,
2024
- authUrl: this.authUrl
2025
- }, "*");
2026
- });
2027
- }
2028
2006
  /**
2029
2007
  * Generic provider sign-in method (headless mode)
2030
2008
  *
@@ -2071,10 +2049,7 @@ var BlinkAuth = class {
2071
2049
  if (!hasWindow()) {
2072
2050
  throw new BlinkAuthError("NETWORK_ERROR" /* NETWORK_ERROR */, "signInWithProvider requires a browser environment");
2073
2051
  }
2074
- if (isWeb && this.isIframe && hasWindow() && window.parent !== window) {
2075
- console.log("\u{1F5BC}\uFE0F In iframe, delegating OAuth to parent window");
2076
- return this.signInWithProviderViaParent(provider, options);
2077
- }
2052
+ const shouldPreferRedirect = isWeb && this.isIframe || typeof window !== "undefined" && window.crossOriginIsolated === true;
2078
2053
  const state = this.generateState();
2079
2054
  try {
2080
2055
  const sessionStorage = getSessionStorage();
@@ -2094,7 +2069,6 @@ var BlinkAuth = class {
2094
2069
  url.searchParams.set("opener_origin", getLocationOrigin() || "");
2095
2070
  return url;
2096
2071
  };
2097
- const shouldPreferRedirect = typeof window !== "undefined" && window.crossOriginIsolated === true;
2098
2072
  if (shouldPreferRedirect) {
2099
2073
  window.location.href = buildAuthUrl("redirect").toString();
2100
2074
  return new Promise(() => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blinkdotnew/dev-sdk",
3
- "version": "2.1.4",
3
+ "version": "2.1.5",
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",