@blinkdotnew/dev-sdk 2.1.3 → 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
  */
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
  */
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") {
@@ -1493,6 +1464,17 @@ var BlinkAuth = class {
1493
1464
  console.warn("Failed to parse redirect URL:", e);
1494
1465
  }
1495
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
+ }
1496
1478
  const authUrl = new URL("/auth", this.authUrl);
1497
1479
  authUrl.searchParams.set("redirect_url", redirectUrl || "");
1498
1480
  if (this.config.projectId) {
@@ -1500,6 +1482,34 @@ var BlinkAuth = class {
1500
1482
  }
1501
1483
  window.location.href = authUrl.toString();
1502
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
+ }
1503
1513
  /**
1504
1514
  * Logout and clear stored tokens
1505
1515
  */
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") {
@@ -1491,6 +1462,17 @@ var BlinkAuth = class {
1491
1462
  console.warn("Failed to parse redirect URL:", e);
1492
1463
  }
1493
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
+ }
1494
1476
  const authUrl = new URL("/auth", this.authUrl);
1495
1477
  authUrl.searchParams.set("redirect_url", redirectUrl || "");
1496
1478
  if (this.config.projectId) {
@@ -1498,6 +1480,34 @@ var BlinkAuth = class {
1498
1480
  }
1499
1481
  window.location.href = authUrl.toString();
1500
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
+ }
1501
1511
  /**
1502
1512
  * Logout and clear stored tokens
1503
1513
  */
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.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",