@blinkdotnew/dev-sdk 2.1.3 → 2.1.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/dist/index.d.mts CHANGED
@@ -1325,6 +1325,11 @@ declare class BlinkAuth {
1325
1325
  * Uses expo-web-browser to open auth URL and polls for completion
1326
1326
  */
1327
1327
  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;
1328
1333
  /**
1329
1334
  * Generic provider sign-in method (headless mode)
1330
1335
  *
package/dist/index.d.ts CHANGED
@@ -1325,6 +1325,11 @@ declare class BlinkAuth {
1325
1325
  * Uses expo-web-browser to open auth URL and polls for completion
1326
1326
  */
1327
1327
  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;
1328
1333
  /**
1329
1334
  * Generic provider sign-in method (headless mode)
1330
1335
  *
package/dist/index.js CHANGED
@@ -1285,45 +1285,16 @@ var BlinkAuth = class {
1285
1285
  if (!config.projectId) {
1286
1286
  throw new Error("projectId is required for authentication");
1287
1287
  }
1288
- const detectAuthUrl = () => {
1289
- if (typeof window !== "undefined") {
1290
- const referrer = document.referrer;
1291
- if (referrer?.includes("dev.blink.new")) {
1292
- console.log("\u{1F527} Dev environment detected via referrer, using dev.blink.new for auth");
1293
- return "https://dev.blink.new";
1294
- }
1295
- try {
1296
- if (window.parent !== window) {
1297
- const parentOrigin = window.parent.location.origin;
1298
- if (parentOrigin?.includes("dev.blink.new")) {
1299
- console.log("\u{1F527} Dev environment detected via parent origin, using dev.blink.new for auth");
1300
- return "https://dev.blink.new";
1301
- }
1302
- }
1303
- } catch {
1304
- }
1305
- try {
1306
- const opener = window.opener?.location?.origin;
1307
- if (opener?.includes("dev.blink.new")) {
1308
- console.log("\u{1F527} Dev environment detected via opener, using dev.blink.new for auth");
1309
- return "https://dev.blink.new";
1310
- }
1311
- } catch {
1312
- }
1313
- }
1314
- return "https://blink.new";
1315
- };
1316
- const defaultAuthUrl = detectAuthUrl();
1317
1288
  this.authConfig = {
1318
1289
  mode: "managed",
1319
1290
  // Default mode
1320
- authUrl: defaultAuthUrl,
1291
+ authUrl: "https://blink.new",
1321
1292
  coreUrl: "https://core.blink.new",
1322
1293
  detectSessionInUrl: true,
1323
1294
  // Default to true for web compatibility
1324
1295
  ...config.auth
1325
1296
  };
1326
- this.authUrl = this.authConfig.authUrl || defaultAuthUrl;
1297
+ this.authUrl = this.authConfig.authUrl || "https://blink.new";
1327
1298
  this.coreUrl = this.authConfig.coreUrl || "https://core.blink.new";
1328
1299
  const hostname = getLocationHostname();
1329
1300
  if (hostname && this.authUrl === "https://blink.new" && (hostname === "localhost" || hostname === "127.0.0.1")) {
@@ -1378,7 +1349,7 @@ var BlinkAuth = class {
1378
1349
  setupParentWindowListener() {
1379
1350
  if (!isWeb || !this.isIframe || !hasWindow()) return;
1380
1351
  window.addEventListener("message", (event) => {
1381
- if (event.origin !== "https://blink.new" && event.origin !== "https://dev.blink.new" && event.origin !== "http://localhost:3000" && event.origin !== "http://localhost:3001") {
1352
+ if (event.origin !== "https://blink.new" && event.origin !== "http://localhost:3000" && event.origin !== "http://localhost:3001") {
1382
1353
  return;
1383
1354
  }
1384
1355
  if (event.data?.type === "BLINK_AUTH_TOKENS") {
@@ -1995,6 +1966,67 @@ var BlinkAuth = class {
1995
1966
  throw pollError;
1996
1967
  }
1997
1968
  }
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
+ }
1998
2030
  /**
1999
2031
  * Generic provider sign-in method (headless mode)
2000
2032
  *
@@ -2041,7 +2073,10 @@ var BlinkAuth = class {
2041
2073
  if (!hasWindow()) {
2042
2074
  throw new BlinkAuthError("NETWORK_ERROR" /* NETWORK_ERROR */, "signInWithProvider requires a browser environment");
2043
2075
  }
2044
- const shouldPreferRedirect = isWeb && this.isIframe || typeof window !== "undefined" && window.crossOriginIsolated === true;
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
+ }
2045
2080
  const state = this.generateState();
2046
2081
  try {
2047
2082
  const sessionStorage = getSessionStorage();
@@ -2061,6 +2096,7 @@ var BlinkAuth = class {
2061
2096
  url.searchParams.set("opener_origin", getLocationOrigin() || "");
2062
2097
  return url;
2063
2098
  };
2099
+ const shouldPreferRedirect = typeof window !== "undefined" && window.crossOriginIsolated === true;
2064
2100
  if (shouldPreferRedirect) {
2065
2101
  window.location.href = buildAuthUrl("redirect").toString();
2066
2102
  return new Promise(() => {
package/dist/index.mjs CHANGED
@@ -1283,45 +1283,16 @@ var BlinkAuth = class {
1283
1283
  if (!config.projectId) {
1284
1284
  throw new Error("projectId is required for authentication");
1285
1285
  }
1286
- const detectAuthUrl = () => {
1287
- if (typeof window !== "undefined") {
1288
- const referrer = document.referrer;
1289
- if (referrer?.includes("dev.blink.new")) {
1290
- console.log("\u{1F527} Dev environment detected via referrer, using dev.blink.new for auth");
1291
- return "https://dev.blink.new";
1292
- }
1293
- try {
1294
- if (window.parent !== window) {
1295
- const parentOrigin = window.parent.location.origin;
1296
- if (parentOrigin?.includes("dev.blink.new")) {
1297
- console.log("\u{1F527} Dev environment detected via parent origin, using dev.blink.new for auth");
1298
- return "https://dev.blink.new";
1299
- }
1300
- }
1301
- } catch {
1302
- }
1303
- try {
1304
- const opener = window.opener?.location?.origin;
1305
- if (opener?.includes("dev.blink.new")) {
1306
- console.log("\u{1F527} Dev environment detected via opener, using dev.blink.new for auth");
1307
- return "https://dev.blink.new";
1308
- }
1309
- } catch {
1310
- }
1311
- }
1312
- return "https://blink.new";
1313
- };
1314
- const defaultAuthUrl = detectAuthUrl();
1315
1286
  this.authConfig = {
1316
1287
  mode: "managed",
1317
1288
  // Default mode
1318
- authUrl: defaultAuthUrl,
1289
+ authUrl: "https://blink.new",
1319
1290
  coreUrl: "https://core.blink.new",
1320
1291
  detectSessionInUrl: true,
1321
1292
  // Default to true for web compatibility
1322
1293
  ...config.auth
1323
1294
  };
1324
- this.authUrl = this.authConfig.authUrl || defaultAuthUrl;
1295
+ this.authUrl = this.authConfig.authUrl || "https://blink.new";
1325
1296
  this.coreUrl = this.authConfig.coreUrl || "https://core.blink.new";
1326
1297
  const hostname = getLocationHostname();
1327
1298
  if (hostname && this.authUrl === "https://blink.new" && (hostname === "localhost" || hostname === "127.0.0.1")) {
@@ -1376,7 +1347,7 @@ var BlinkAuth = class {
1376
1347
  setupParentWindowListener() {
1377
1348
  if (!isWeb || !this.isIframe || !hasWindow()) return;
1378
1349
  window.addEventListener("message", (event) => {
1379
- if (event.origin !== "https://blink.new" && event.origin !== "https://dev.blink.new" && event.origin !== "http://localhost:3000" && event.origin !== "http://localhost:3001") {
1350
+ if (event.origin !== "https://blink.new" && event.origin !== "http://localhost:3000" && event.origin !== "http://localhost:3001") {
1380
1351
  return;
1381
1352
  }
1382
1353
  if (event.data?.type === "BLINK_AUTH_TOKENS") {
@@ -1993,6 +1964,67 @@ var BlinkAuth = class {
1993
1964
  throw pollError;
1994
1965
  }
1995
1966
  }
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
+ }
1996
2028
  /**
1997
2029
  * Generic provider sign-in method (headless mode)
1998
2030
  *
@@ -2039,7 +2071,10 @@ var BlinkAuth = class {
2039
2071
  if (!hasWindow()) {
2040
2072
  throw new BlinkAuthError("NETWORK_ERROR" /* NETWORK_ERROR */, "signInWithProvider requires a browser environment");
2041
2073
  }
2042
- const shouldPreferRedirect = isWeb && this.isIframe || typeof window !== "undefined" && window.crossOriginIsolated === true;
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
+ }
2043
2078
  const state = this.generateState();
2044
2079
  try {
2045
2080
  const sessionStorage = getSessionStorage();
@@ -2059,6 +2094,7 @@ var BlinkAuth = class {
2059
2094
  url.searchParams.set("opener_origin", getLocationOrigin() || "");
2060
2095
  return url;
2061
2096
  };
2097
+ const shouldPreferRedirect = typeof window !== "undefined" && window.crossOriginIsolated === true;
2062
2098
  if (shouldPreferRedirect) {
2063
2099
  window.location.href = buildAuthUrl("redirect").toString();
2064
2100
  return new Promise(() => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blinkdotnew/dev-sdk",
3
- "version": "2.1.3",
3
+ "version": "2.1.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",