@blinkdotnew/dev-sdk 0.0.1 → 0.0.2

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
@@ -731,54 +731,6 @@ interface BlinkNotifications {
731
731
  email(params: SendEmailRequest): Promise<SendEmailResponse>;
732
732
  }
733
733
 
734
- type ConnectorProvider = 'discord' | 'notion' | 'google_drive' | 'google_calendar' | 'ai';
735
- type ConnectorAuthMode = 'oauth' | 'api_key' | 'blink_managed' | 'hybrid';
736
- interface ConnectorStatusData {
737
- connected: boolean;
738
- provider: ConnectorProvider;
739
- auth_mode?: ConnectorAuthMode;
740
- account_id?: string;
741
- metadata?: Record<string, unknown>;
742
- expires_at?: any;
743
- scopes?: string[];
744
- }
745
- interface ConnectorStatusResponse {
746
- success: boolean;
747
- data: ConnectorStatusData;
748
- }
749
- interface ConnectorExecuteRequest<TParams = Record<string, unknown>> {
750
- method: string;
751
- params?: TParams;
752
- account_id?: string;
753
- http_method?: string;
754
- }
755
- interface ConnectorExecuteResponse<TData = any> {
756
- success: boolean;
757
- data: TData;
758
- }
759
- interface ConnectorApiKeyRequest<TMetadata = Record<string, unknown>> {
760
- api_key: string;
761
- account_id?: string;
762
- metadata?: TMetadata;
763
- }
764
- interface ConnectorApiKeyResponse {
765
- success: boolean;
766
- data: {
767
- id: string;
768
- account_id?: string;
769
- };
770
- }
771
- interface BlinkConnectors {
772
- status(provider: ConnectorProvider, options?: {
773
- account_id?: string;
774
- }): Promise<ConnectorStatusResponse>;
775
- execute<TParams = Record<string, unknown>, TData = any>(provider: ConnectorProvider, request: ConnectorExecuteRequest<TParams>): Promise<ConnectorExecuteResponse<TData>>;
776
- saveApiKey<TMetadata = Record<string, unknown>>(provider: ConnectorProvider, request: ConnectorApiKeyRequest<TMetadata>): Promise<ConnectorApiKeyResponse>;
777
- }
778
- declare class BlinkConnectorError extends BlinkError {
779
- constructor(message: string, status?: number, details?: any);
780
- }
781
-
782
734
  /**
783
735
  * HTTP client for Blink API requests
784
736
  * Handles authentication, error handling, and request/response processing
@@ -952,13 +904,6 @@ declare class HttpClient {
952
904
  dataScreenshot(projectId: string, request: ScreenshotRequest): Promise<BlinkResponse<ScreenshotResponse>>;
953
905
  dataFetch(projectId: string, request: FetchRequest): Promise<BlinkResponse<FetchResponse | AsyncFetchResponse>>;
954
906
  dataSearch(projectId: string, request: SearchRequest): Promise<BlinkResponse<SearchResponse>>;
955
- /**
956
- * Connector requests
957
- */
958
- private formatProviderForPath;
959
- connectorStatus(provider: ConnectorProvider): Promise<BlinkResponse<ConnectorStatusResponse>>;
960
- connectorExecute<TParams = Record<string, unknown>, TData = any>(provider: ConnectorProvider, request: ConnectorExecuteRequest<TParams>): Promise<BlinkResponse<ConnectorExecuteResponse<TData>>>;
961
- connectorSaveApiKey<TMetadata = Record<string, unknown>>(provider: ConnectorProvider, request: ConnectorApiKeyRequest<TMetadata>): Promise<BlinkResponse<ConnectorApiKeyResponse>>;
962
907
  /**
963
908
  * Realtime-specific requests
964
909
  */
@@ -1702,7 +1647,6 @@ interface BlinkClient {
1702
1647
  realtime: BlinkRealtime;
1703
1648
  notifications: BlinkNotifications;
1704
1649
  analytics: BlinkAnalytics;
1705
- connectors: BlinkConnectors;
1706
1650
  }
1707
1651
  /**
1708
1652
  * Create a new Blink client instance
@@ -2352,14 +2296,4 @@ declare class BlinkRealtimeImpl implements BlinkRealtime {
2352
2296
  onPresence(channelName: string, callback: (users: PresenceUser[]) => void): () => void;
2353
2297
  }
2354
2298
 
2355
- declare class BlinkConnectorsImpl implements BlinkConnectors {
2356
- private httpClient;
2357
- constructor(httpClient: HttpClient);
2358
- status(provider: ConnectorProvider, options?: {
2359
- account_id?: string;
2360
- }): Promise<ConnectorStatusResponse>;
2361
- execute<TParams = Record<string, unknown>, TData = any>(provider: ConnectorProvider, request: ConnectorExecuteRequest<TParams>): Promise<ConnectorExecuteResponse<TData>>;
2362
- saveApiKey<TMetadata = Record<string, unknown>>(provider: ConnectorProvider, request: ConnectorApiKeyRequest<TMetadata>): Promise<ConnectorApiKeyResponse>;
2363
- }
2364
-
2365
- export { type AnalyticsEvent, AsyncStorageAdapter, type AuthState, type AuthStateChangeCallback, type AuthTokens, type BlinkAI, BlinkAIImpl, type BlinkAnalytics, BlinkAnalyticsImpl, type BlinkClient, type BlinkClientConfig, BlinkConnectorError, type BlinkConnectors, BlinkConnectorsImpl, type BlinkData, BlinkDataImpl, BlinkDatabase, type BlinkRealtime, BlinkRealtimeChannel, BlinkRealtimeError, BlinkRealtimeImpl, type BlinkStorage, BlinkStorageImpl, BlinkTable, type BlinkUser, type ConnectorApiKeyRequest, type ConnectorApiKeyResponse, type ConnectorAuthMode, type ConnectorExecuteRequest, type ConnectorExecuteResponse, type ConnectorProvider, type ConnectorStatusResponse, type CreateOptions, type DataExtraction, type FileObject, type FilterCondition, type ImageGenerationRequest, type ImageGenerationResponse, type Message, NoOpStorageAdapter, type ObjectGenerationRequest, type ObjectGenerationResponse, type PresenceUser, type QueryOptions, type RealtimeChannel, type RealtimeGetMessagesOptions, type RealtimeMessage, type RealtimePublishOptions, type RealtimeSubscribeOptions, type SearchRequest, type SearchResponse, type SpeechGenerationRequest, type SpeechGenerationResponse, type StorageAdapter, type StorageUploadOptions, type StorageUploadResponse, type TableOperations, type TextGenerationRequest, type TextGenerationResponse, type TokenUsage, type TranscriptionRequest, type TranscriptionResponse, type UpdateOptions, type UpsertOptions, type WebBrowserModule, WebStorageAdapter, createClient, getDefaultStorageAdapter, isBrowser, isNode, isReactNative, isWeb, platform };
2299
+ export { type AnalyticsEvent, AsyncStorageAdapter, type AuthState, type AuthStateChangeCallback, type AuthTokens, type BlinkAI, BlinkAIImpl, type BlinkAnalytics, BlinkAnalyticsImpl, type BlinkClient, type BlinkClientConfig, type BlinkData, BlinkDataImpl, BlinkDatabase, type BlinkRealtime, BlinkRealtimeChannel, BlinkRealtimeError, BlinkRealtimeImpl, type BlinkStorage, BlinkStorageImpl, BlinkTable, type BlinkUser, type CreateOptions, type DataExtraction, type FileObject, type FilterCondition, type ImageGenerationRequest, type ImageGenerationResponse, type Message, NoOpStorageAdapter, type ObjectGenerationRequest, type ObjectGenerationResponse, type PresenceUser, type QueryOptions, type RealtimeChannel, type RealtimeGetMessagesOptions, type RealtimeMessage, type RealtimePublishOptions, type RealtimeSubscribeOptions, type SearchRequest, type SearchResponse, type SpeechGenerationRequest, type SpeechGenerationResponse, type StorageAdapter, type StorageUploadOptions, type StorageUploadResponse, type TableOperations, type TextGenerationRequest, type TextGenerationResponse, type TokenUsage, type TranscriptionRequest, type TranscriptionResponse, type UpdateOptions, type UpsertOptions, type WebBrowserModule, WebStorageAdapter, createClient, getDefaultStorageAdapter, isBrowser, isNode, isReactNative, isWeb, platform };
package/dist/index.d.ts CHANGED
@@ -731,54 +731,6 @@ interface BlinkNotifications {
731
731
  email(params: SendEmailRequest): Promise<SendEmailResponse>;
732
732
  }
733
733
 
734
- type ConnectorProvider = 'discord' | 'notion' | 'google_drive' | 'google_calendar' | 'ai';
735
- type ConnectorAuthMode = 'oauth' | 'api_key' | 'blink_managed' | 'hybrid';
736
- interface ConnectorStatusData {
737
- connected: boolean;
738
- provider: ConnectorProvider;
739
- auth_mode?: ConnectorAuthMode;
740
- account_id?: string;
741
- metadata?: Record<string, unknown>;
742
- expires_at?: any;
743
- scopes?: string[];
744
- }
745
- interface ConnectorStatusResponse {
746
- success: boolean;
747
- data: ConnectorStatusData;
748
- }
749
- interface ConnectorExecuteRequest<TParams = Record<string, unknown>> {
750
- method: string;
751
- params?: TParams;
752
- account_id?: string;
753
- http_method?: string;
754
- }
755
- interface ConnectorExecuteResponse<TData = any> {
756
- success: boolean;
757
- data: TData;
758
- }
759
- interface ConnectorApiKeyRequest<TMetadata = Record<string, unknown>> {
760
- api_key: string;
761
- account_id?: string;
762
- metadata?: TMetadata;
763
- }
764
- interface ConnectorApiKeyResponse {
765
- success: boolean;
766
- data: {
767
- id: string;
768
- account_id?: string;
769
- };
770
- }
771
- interface BlinkConnectors {
772
- status(provider: ConnectorProvider, options?: {
773
- account_id?: string;
774
- }): Promise<ConnectorStatusResponse>;
775
- execute<TParams = Record<string, unknown>, TData = any>(provider: ConnectorProvider, request: ConnectorExecuteRequest<TParams>): Promise<ConnectorExecuteResponse<TData>>;
776
- saveApiKey<TMetadata = Record<string, unknown>>(provider: ConnectorProvider, request: ConnectorApiKeyRequest<TMetadata>): Promise<ConnectorApiKeyResponse>;
777
- }
778
- declare class BlinkConnectorError extends BlinkError {
779
- constructor(message: string, status?: number, details?: any);
780
- }
781
-
782
734
  /**
783
735
  * HTTP client for Blink API requests
784
736
  * Handles authentication, error handling, and request/response processing
@@ -952,13 +904,6 @@ declare class HttpClient {
952
904
  dataScreenshot(projectId: string, request: ScreenshotRequest): Promise<BlinkResponse<ScreenshotResponse>>;
953
905
  dataFetch(projectId: string, request: FetchRequest): Promise<BlinkResponse<FetchResponse | AsyncFetchResponse>>;
954
906
  dataSearch(projectId: string, request: SearchRequest): Promise<BlinkResponse<SearchResponse>>;
955
- /**
956
- * Connector requests
957
- */
958
- private formatProviderForPath;
959
- connectorStatus(provider: ConnectorProvider): Promise<BlinkResponse<ConnectorStatusResponse>>;
960
- connectorExecute<TParams = Record<string, unknown>, TData = any>(provider: ConnectorProvider, request: ConnectorExecuteRequest<TParams>): Promise<BlinkResponse<ConnectorExecuteResponse<TData>>>;
961
- connectorSaveApiKey<TMetadata = Record<string, unknown>>(provider: ConnectorProvider, request: ConnectorApiKeyRequest<TMetadata>): Promise<BlinkResponse<ConnectorApiKeyResponse>>;
962
907
  /**
963
908
  * Realtime-specific requests
964
909
  */
@@ -1702,7 +1647,6 @@ interface BlinkClient {
1702
1647
  realtime: BlinkRealtime;
1703
1648
  notifications: BlinkNotifications;
1704
1649
  analytics: BlinkAnalytics;
1705
- connectors: BlinkConnectors;
1706
1650
  }
1707
1651
  /**
1708
1652
  * Create a new Blink client instance
@@ -2352,14 +2296,4 @@ declare class BlinkRealtimeImpl implements BlinkRealtime {
2352
2296
  onPresence(channelName: string, callback: (users: PresenceUser[]) => void): () => void;
2353
2297
  }
2354
2298
 
2355
- declare class BlinkConnectorsImpl implements BlinkConnectors {
2356
- private httpClient;
2357
- constructor(httpClient: HttpClient);
2358
- status(provider: ConnectorProvider, options?: {
2359
- account_id?: string;
2360
- }): Promise<ConnectorStatusResponse>;
2361
- execute<TParams = Record<string, unknown>, TData = any>(provider: ConnectorProvider, request: ConnectorExecuteRequest<TParams>): Promise<ConnectorExecuteResponse<TData>>;
2362
- saveApiKey<TMetadata = Record<string, unknown>>(provider: ConnectorProvider, request: ConnectorApiKeyRequest<TMetadata>): Promise<ConnectorApiKeyResponse>;
2363
- }
2364
-
2365
- export { type AnalyticsEvent, AsyncStorageAdapter, type AuthState, type AuthStateChangeCallback, type AuthTokens, type BlinkAI, BlinkAIImpl, type BlinkAnalytics, BlinkAnalyticsImpl, type BlinkClient, type BlinkClientConfig, BlinkConnectorError, type BlinkConnectors, BlinkConnectorsImpl, type BlinkData, BlinkDataImpl, BlinkDatabase, type BlinkRealtime, BlinkRealtimeChannel, BlinkRealtimeError, BlinkRealtimeImpl, type BlinkStorage, BlinkStorageImpl, BlinkTable, type BlinkUser, type ConnectorApiKeyRequest, type ConnectorApiKeyResponse, type ConnectorAuthMode, type ConnectorExecuteRequest, type ConnectorExecuteResponse, type ConnectorProvider, type ConnectorStatusResponse, type CreateOptions, type DataExtraction, type FileObject, type FilterCondition, type ImageGenerationRequest, type ImageGenerationResponse, type Message, NoOpStorageAdapter, type ObjectGenerationRequest, type ObjectGenerationResponse, type PresenceUser, type QueryOptions, type RealtimeChannel, type RealtimeGetMessagesOptions, type RealtimeMessage, type RealtimePublishOptions, type RealtimeSubscribeOptions, type SearchRequest, type SearchResponse, type SpeechGenerationRequest, type SpeechGenerationResponse, type StorageAdapter, type StorageUploadOptions, type StorageUploadResponse, type TableOperations, type TextGenerationRequest, type TextGenerationResponse, type TokenUsage, type TranscriptionRequest, type TranscriptionResponse, type UpdateOptions, type UpsertOptions, type WebBrowserModule, WebStorageAdapter, createClient, getDefaultStorageAdapter, isBrowser, isNode, isReactNative, isWeb, platform };
2299
+ export { type AnalyticsEvent, AsyncStorageAdapter, type AuthState, type AuthStateChangeCallback, type AuthTokens, type BlinkAI, BlinkAIImpl, type BlinkAnalytics, BlinkAnalyticsImpl, type BlinkClient, type BlinkClientConfig, type BlinkData, BlinkDataImpl, BlinkDatabase, type BlinkRealtime, BlinkRealtimeChannel, BlinkRealtimeError, BlinkRealtimeImpl, type BlinkStorage, BlinkStorageImpl, BlinkTable, type BlinkUser, type CreateOptions, type DataExtraction, type FileObject, type FilterCondition, type ImageGenerationRequest, type ImageGenerationResponse, type Message, NoOpStorageAdapter, type ObjectGenerationRequest, type ObjectGenerationResponse, type PresenceUser, type QueryOptions, type RealtimeChannel, type RealtimeGetMessagesOptions, type RealtimeMessage, type RealtimePublishOptions, type RealtimeSubscribeOptions, type SearchRequest, type SearchResponse, type SpeechGenerationRequest, type SpeechGenerationResponse, type StorageAdapter, type StorageUploadOptions, type StorageUploadResponse, type TableOperations, type TextGenerationRequest, type TextGenerationResponse, type TokenUsage, type TranscriptionRequest, type TranscriptionResponse, type UpdateOptions, type UpsertOptions, type WebBrowserModule, WebStorageAdapter, createClient, getDefaultStorageAdapter, isBrowser, isNode, isReactNative, isWeb, platform };
package/dist/index.js CHANGED
@@ -388,8 +388,8 @@ function convertKeysToCamelCase(obj) {
388
388
  return converted;
389
389
  }
390
390
  var HttpClient = class {
391
- authUrl = "https://blink.new";
392
- coreUrl = "https://core.blink.new";
391
+ authUrl;
392
+ coreUrl;
393
393
  projectId;
394
394
  getToken;
395
395
  getValidToken;
@@ -397,6 +397,8 @@ var HttpClient = class {
397
397
  this.projectId = config.projectId;
398
398
  this.getToken = getToken;
399
399
  this.getValidToken = getValidToken;
400
+ this.authUrl = config.auth?.authUrl ?? "https://blink.new";
401
+ this.coreUrl = config.auth?.coreUrl ?? "https://core.blink.new";
400
402
  }
401
403
  /**
402
404
  * Make an authenticated request to the Blink API
@@ -859,38 +861,6 @@ var HttpClient = class {
859
861
  async dataSearch(projectId, request) {
860
862
  return this.post(`/api/data/${projectId}/search`, request);
861
863
  }
862
- /**
863
- * Connector requests
864
- */
865
- formatProviderForPath(provider) {
866
- return provider.replace("_", "-");
867
- }
868
- async connectorStatus(provider) {
869
- return this.request(`/api/connectors/${this.formatProviderForPath(provider)}/${this.projectId}/status`, {
870
- method: "GET"
871
- });
872
- }
873
- async connectorExecute(provider, request) {
874
- const path = request.method.startsWith("/") ? request.method : `/${request.method}`;
875
- const url = `/api/connectors/${this.formatProviderForPath(provider)}/${this.projectId}${path}`;
876
- const method = (request.http_method || "GET").toUpperCase();
877
- if (method === "GET") {
878
- return this.request(url, {
879
- method: "GET",
880
- searchParams: request.params
881
- });
882
- }
883
- return this.request(url, {
884
- method,
885
- body: request.params || {}
886
- });
887
- }
888
- async connectorSaveApiKey(provider, request) {
889
- return this.request(`/api/connectors/${this.formatProviderForPath(provider)}/${this.projectId}/api-key`, {
890
- method: "POST",
891
- body: request
892
- });
893
- }
894
864
  /**
895
865
  * Realtime-specific requests
896
866
  */
@@ -1933,22 +1903,33 @@ var BlinkAuth = class {
1933
1903
  if (!hasWindow()) {
1934
1904
  throw new BlinkAuthError("NETWORK_ERROR" /* NETWORK_ERROR */, "signInWithProvider requires a browser environment");
1935
1905
  }
1906
+ const shouldPreferRedirect = isWeb && this.isIframe || typeof window !== "undefined" && window.crossOriginIsolated === true;
1907
+ const state = this.generateState();
1908
+ try {
1909
+ const sessionStorage = getSessionStorage();
1910
+ if (sessionStorage) {
1911
+ sessionStorage.setItem("blink_oauth_state", state);
1912
+ }
1913
+ } catch {
1914
+ }
1915
+ const redirectUrl = options?.redirectUrl || getLocationOrigin() || "";
1916
+ const buildAuthUrl = (mode) => {
1917
+ const url = new URL("/auth", this.authUrl);
1918
+ url.searchParams.set("provider", provider);
1919
+ url.searchParams.set("project_id", this.config.projectId);
1920
+ url.searchParams.set("state", state);
1921
+ url.searchParams.set("mode", mode);
1922
+ url.searchParams.set("redirect_url", redirectUrl);
1923
+ url.searchParams.set("opener_origin", getLocationOrigin() || "");
1924
+ return url;
1925
+ };
1926
+ if (shouldPreferRedirect) {
1927
+ window.location.href = buildAuthUrl("redirect").toString();
1928
+ return new Promise(() => {
1929
+ });
1930
+ }
1936
1931
  return new Promise((resolve, reject) => {
1937
- const state = this.generateState();
1938
- try {
1939
- const sessionStorage = getSessionStorage();
1940
- if (sessionStorage) {
1941
- sessionStorage.setItem("blink_oauth_state", state);
1942
- }
1943
- } catch {
1944
- }
1945
- const redirectUrl = options?.redirectUrl || getLocationOrigin() || "";
1946
- const popupUrl = new URL("/auth", this.authUrl);
1947
- popupUrl.searchParams.set("provider", provider);
1948
- popupUrl.searchParams.set("project_id", this.config.projectId);
1949
- popupUrl.searchParams.set("state", state);
1950
- popupUrl.searchParams.set("mode", "popup");
1951
- popupUrl.searchParams.set("redirect_url", redirectUrl);
1932
+ const popupUrl = buildAuthUrl("popup");
1952
1933
  const popup = window.open(
1953
1934
  popupUrl.toString(),
1954
1935
  "blink-auth",
@@ -1959,6 +1940,15 @@ var BlinkAuth = class {
1959
1940
  return;
1960
1941
  }
1961
1942
  let timeoutId;
1943
+ let closedIntervalId;
1944
+ let cleanedUp = false;
1945
+ const cleanup = () => {
1946
+ if (cleanedUp) return;
1947
+ cleanedUp = true;
1948
+ clearTimeout(timeoutId);
1949
+ if (closedIntervalId) clearInterval(closedIntervalId);
1950
+ window.removeEventListener("message", messageListener);
1951
+ };
1962
1952
  const messageListener = (event) => {
1963
1953
  let allowed = false;
1964
1954
  try {
@@ -1995,29 +1985,34 @@ var BlinkAuth = class {
1995
1985
  }, true).then(() => {
1996
1986
  resolve(this.authState.user);
1997
1987
  }).catch(reject);
1998
- clearTimeout(timeoutId);
1999
- window.removeEventListener("message", messageListener);
1988
+ cleanup();
2000
1989
  popup.close();
2001
1990
  } else if (event.data?.type === "BLINK_AUTH_ERROR") {
2002
1991
  const errorCode = this.mapErrorCodeFromResponse(event.data.code);
2003
1992
  reject(new BlinkAuthError(errorCode, event.data.message || "Authentication failed"));
2004
- clearTimeout(timeoutId);
2005
- window.removeEventListener("message", messageListener);
1993
+ cleanup();
2006
1994
  popup.close();
2007
1995
  }
2008
1996
  };
1997
+ if (popup.opener === null) {
1998
+ try {
1999
+ popup.close();
2000
+ } catch {
2001
+ }
2002
+ cleanup();
2003
+ window.location.href = buildAuthUrl("redirect").toString();
2004
+ return;
2005
+ }
2009
2006
  timeoutId = setTimeout(() => {
2010
- window.removeEventListener("message", messageListener);
2007
+ cleanup();
2011
2008
  if (!popup.closed) {
2012
2009
  popup.close();
2013
2010
  }
2014
2011
  reject(new BlinkAuthError("AUTH_TIMEOUT" /* AUTH_TIMEOUT */, "Authentication timed out"));
2015
2012
  }, 3e5);
2016
- const checkClosed = setInterval(() => {
2013
+ closedIntervalId = setInterval(() => {
2017
2014
  if (popup.closed) {
2018
- clearInterval(checkClosed);
2019
- clearTimeout(timeoutId);
2020
- window.removeEventListener("message", messageListener);
2015
+ cleanup();
2021
2016
  reject(new BlinkAuthError("POPUP_CANCELED" /* POPUP_CANCELED */, "Authentication was canceled"));
2022
2017
  }
2023
2018
  }, 1e3);
@@ -5469,25 +5464,6 @@ var BlinkAnalyticsImpl = class {
5469
5464
  }
5470
5465
  };
5471
5466
 
5472
- // src/connectors.ts
5473
- var BlinkConnectorsImpl = class {
5474
- constructor(httpClient) {
5475
- this.httpClient = httpClient;
5476
- }
5477
- async status(provider, options) {
5478
- const response = await this.httpClient.connectorStatus(provider);
5479
- return response.data;
5480
- }
5481
- async execute(provider, request) {
5482
- const response = await this.httpClient.connectorExecute(provider, request);
5483
- return response.data;
5484
- }
5485
- async saveApiKey(provider, request) {
5486
- const response = await this.httpClient.connectorSaveApiKey(provider, request);
5487
- return response.data;
5488
- }
5489
- };
5490
-
5491
5467
  // src/client.ts
5492
5468
  var BlinkClientImpl = class {
5493
5469
  auth;
@@ -5498,7 +5474,6 @@ var BlinkClientImpl = class {
5498
5474
  realtime;
5499
5475
  notifications;
5500
5476
  analytics;
5501
- connectors;
5502
5477
  httpClient;
5503
5478
  constructor(config) {
5504
5479
  this.auth = new BlinkAuth(config);
@@ -5514,7 +5489,6 @@ var BlinkClientImpl = class {
5514
5489
  this.realtime = new BlinkRealtimeImpl(this.httpClient, config.projectId);
5515
5490
  this.notifications = new BlinkNotificationsImpl(this.httpClient);
5516
5491
  this.analytics = new BlinkAnalyticsImpl(this.httpClient, config.projectId);
5517
- this.connectors = new BlinkConnectorsImpl(this.httpClient);
5518
5492
  this.auth.onAuthStateChanged((state) => {
5519
5493
  if (state.isAuthenticated && state.user) {
5520
5494
  this.analytics.setUserId(state.user.id);
@@ -5536,7 +5510,6 @@ function createClient(config) {
5536
5510
  exports.AsyncStorageAdapter = AsyncStorageAdapter;
5537
5511
  exports.BlinkAIImpl = BlinkAIImpl;
5538
5512
  exports.BlinkAnalyticsImpl = BlinkAnalyticsImpl;
5539
- exports.BlinkConnectorsImpl = BlinkConnectorsImpl;
5540
5513
  exports.BlinkDataImpl = BlinkDataImpl;
5541
5514
  exports.BlinkDatabase = BlinkDatabase;
5542
5515
  exports.BlinkRealtimeChannel = BlinkRealtimeChannel;
package/dist/index.mjs CHANGED
@@ -386,8 +386,8 @@ function convertKeysToCamelCase(obj) {
386
386
  return converted;
387
387
  }
388
388
  var HttpClient = class {
389
- authUrl = "https://blink.new";
390
- coreUrl = "https://core.blink.new";
389
+ authUrl;
390
+ coreUrl;
391
391
  projectId;
392
392
  getToken;
393
393
  getValidToken;
@@ -395,6 +395,8 @@ var HttpClient = class {
395
395
  this.projectId = config.projectId;
396
396
  this.getToken = getToken;
397
397
  this.getValidToken = getValidToken;
398
+ this.authUrl = config.auth?.authUrl ?? "https://blink.new";
399
+ this.coreUrl = config.auth?.coreUrl ?? "https://core.blink.new";
398
400
  }
399
401
  /**
400
402
  * Make an authenticated request to the Blink API
@@ -857,38 +859,6 @@ var HttpClient = class {
857
859
  async dataSearch(projectId, request) {
858
860
  return this.post(`/api/data/${projectId}/search`, request);
859
861
  }
860
- /**
861
- * Connector requests
862
- */
863
- formatProviderForPath(provider) {
864
- return provider.replace("_", "-");
865
- }
866
- async connectorStatus(provider) {
867
- return this.request(`/api/connectors/${this.formatProviderForPath(provider)}/${this.projectId}/status`, {
868
- method: "GET"
869
- });
870
- }
871
- async connectorExecute(provider, request) {
872
- const path = request.method.startsWith("/") ? request.method : `/${request.method}`;
873
- const url = `/api/connectors/${this.formatProviderForPath(provider)}/${this.projectId}${path}`;
874
- const method = (request.http_method || "GET").toUpperCase();
875
- if (method === "GET") {
876
- return this.request(url, {
877
- method: "GET",
878
- searchParams: request.params
879
- });
880
- }
881
- return this.request(url, {
882
- method,
883
- body: request.params || {}
884
- });
885
- }
886
- async connectorSaveApiKey(provider, request) {
887
- return this.request(`/api/connectors/${this.formatProviderForPath(provider)}/${this.projectId}/api-key`, {
888
- method: "POST",
889
- body: request
890
- });
891
- }
892
862
  /**
893
863
  * Realtime-specific requests
894
864
  */
@@ -1931,22 +1901,33 @@ var BlinkAuth = class {
1931
1901
  if (!hasWindow()) {
1932
1902
  throw new BlinkAuthError("NETWORK_ERROR" /* NETWORK_ERROR */, "signInWithProvider requires a browser environment");
1933
1903
  }
1904
+ const shouldPreferRedirect = isWeb && this.isIframe || typeof window !== "undefined" && window.crossOriginIsolated === true;
1905
+ const state = this.generateState();
1906
+ try {
1907
+ const sessionStorage = getSessionStorage();
1908
+ if (sessionStorage) {
1909
+ sessionStorage.setItem("blink_oauth_state", state);
1910
+ }
1911
+ } catch {
1912
+ }
1913
+ const redirectUrl = options?.redirectUrl || getLocationOrigin() || "";
1914
+ const buildAuthUrl = (mode) => {
1915
+ const url = new URL("/auth", this.authUrl);
1916
+ url.searchParams.set("provider", provider);
1917
+ url.searchParams.set("project_id", this.config.projectId);
1918
+ url.searchParams.set("state", state);
1919
+ url.searchParams.set("mode", mode);
1920
+ url.searchParams.set("redirect_url", redirectUrl);
1921
+ url.searchParams.set("opener_origin", getLocationOrigin() || "");
1922
+ return url;
1923
+ };
1924
+ if (shouldPreferRedirect) {
1925
+ window.location.href = buildAuthUrl("redirect").toString();
1926
+ return new Promise(() => {
1927
+ });
1928
+ }
1934
1929
  return new Promise((resolve, reject) => {
1935
- const state = this.generateState();
1936
- try {
1937
- const sessionStorage = getSessionStorage();
1938
- if (sessionStorage) {
1939
- sessionStorage.setItem("blink_oauth_state", state);
1940
- }
1941
- } catch {
1942
- }
1943
- const redirectUrl = options?.redirectUrl || getLocationOrigin() || "";
1944
- const popupUrl = new URL("/auth", this.authUrl);
1945
- popupUrl.searchParams.set("provider", provider);
1946
- popupUrl.searchParams.set("project_id", this.config.projectId);
1947
- popupUrl.searchParams.set("state", state);
1948
- popupUrl.searchParams.set("mode", "popup");
1949
- popupUrl.searchParams.set("redirect_url", redirectUrl);
1930
+ const popupUrl = buildAuthUrl("popup");
1950
1931
  const popup = window.open(
1951
1932
  popupUrl.toString(),
1952
1933
  "blink-auth",
@@ -1957,6 +1938,15 @@ var BlinkAuth = class {
1957
1938
  return;
1958
1939
  }
1959
1940
  let timeoutId;
1941
+ let closedIntervalId;
1942
+ let cleanedUp = false;
1943
+ const cleanup = () => {
1944
+ if (cleanedUp) return;
1945
+ cleanedUp = true;
1946
+ clearTimeout(timeoutId);
1947
+ if (closedIntervalId) clearInterval(closedIntervalId);
1948
+ window.removeEventListener("message", messageListener);
1949
+ };
1960
1950
  const messageListener = (event) => {
1961
1951
  let allowed = false;
1962
1952
  try {
@@ -1993,29 +1983,34 @@ var BlinkAuth = class {
1993
1983
  }, true).then(() => {
1994
1984
  resolve(this.authState.user);
1995
1985
  }).catch(reject);
1996
- clearTimeout(timeoutId);
1997
- window.removeEventListener("message", messageListener);
1986
+ cleanup();
1998
1987
  popup.close();
1999
1988
  } else if (event.data?.type === "BLINK_AUTH_ERROR") {
2000
1989
  const errorCode = this.mapErrorCodeFromResponse(event.data.code);
2001
1990
  reject(new BlinkAuthError(errorCode, event.data.message || "Authentication failed"));
2002
- clearTimeout(timeoutId);
2003
- window.removeEventListener("message", messageListener);
1991
+ cleanup();
2004
1992
  popup.close();
2005
1993
  }
2006
1994
  };
1995
+ if (popup.opener === null) {
1996
+ try {
1997
+ popup.close();
1998
+ } catch {
1999
+ }
2000
+ cleanup();
2001
+ window.location.href = buildAuthUrl("redirect").toString();
2002
+ return;
2003
+ }
2007
2004
  timeoutId = setTimeout(() => {
2008
- window.removeEventListener("message", messageListener);
2005
+ cleanup();
2009
2006
  if (!popup.closed) {
2010
2007
  popup.close();
2011
2008
  }
2012
2009
  reject(new BlinkAuthError("AUTH_TIMEOUT" /* AUTH_TIMEOUT */, "Authentication timed out"));
2013
2010
  }, 3e5);
2014
- const checkClosed = setInterval(() => {
2011
+ closedIntervalId = setInterval(() => {
2015
2012
  if (popup.closed) {
2016
- clearInterval(checkClosed);
2017
- clearTimeout(timeoutId);
2018
- window.removeEventListener("message", messageListener);
2013
+ cleanup();
2019
2014
  reject(new BlinkAuthError("POPUP_CANCELED" /* POPUP_CANCELED */, "Authentication was canceled"));
2020
2015
  }
2021
2016
  }, 1e3);
@@ -5467,25 +5462,6 @@ var BlinkAnalyticsImpl = class {
5467
5462
  }
5468
5463
  };
5469
5464
 
5470
- // src/connectors.ts
5471
- var BlinkConnectorsImpl = class {
5472
- constructor(httpClient) {
5473
- this.httpClient = httpClient;
5474
- }
5475
- async status(provider, options) {
5476
- const response = await this.httpClient.connectorStatus(provider);
5477
- return response.data;
5478
- }
5479
- async execute(provider, request) {
5480
- const response = await this.httpClient.connectorExecute(provider, request);
5481
- return response.data;
5482
- }
5483
- async saveApiKey(provider, request) {
5484
- const response = await this.httpClient.connectorSaveApiKey(provider, request);
5485
- return response.data;
5486
- }
5487
- };
5488
-
5489
5465
  // src/client.ts
5490
5466
  var BlinkClientImpl = class {
5491
5467
  auth;
@@ -5496,7 +5472,6 @@ var BlinkClientImpl = class {
5496
5472
  realtime;
5497
5473
  notifications;
5498
5474
  analytics;
5499
- connectors;
5500
5475
  httpClient;
5501
5476
  constructor(config) {
5502
5477
  this.auth = new BlinkAuth(config);
@@ -5512,7 +5487,6 @@ var BlinkClientImpl = class {
5512
5487
  this.realtime = new BlinkRealtimeImpl(this.httpClient, config.projectId);
5513
5488
  this.notifications = new BlinkNotificationsImpl(this.httpClient);
5514
5489
  this.analytics = new BlinkAnalyticsImpl(this.httpClient, config.projectId);
5515
- this.connectors = new BlinkConnectorsImpl(this.httpClient);
5516
5490
  this.auth.onAuthStateChanged((state) => {
5517
5491
  if (state.isAuthenticated && state.user) {
5518
5492
  this.analytics.setUserId(state.user.id);
@@ -5531,6 +5505,6 @@ function createClient(config) {
5531
5505
  return new BlinkClientImpl(config);
5532
5506
  }
5533
5507
 
5534
- export { AsyncStorageAdapter, BlinkAIImpl, BlinkAnalyticsImpl, BlinkConnectorsImpl, BlinkDataImpl, BlinkDatabase, BlinkRealtimeChannel, BlinkRealtimeImpl, BlinkStorageImpl, BlinkTable, NoOpStorageAdapter, WebStorageAdapter, createClient, getDefaultStorageAdapter, isBrowser, isNode, isReactNative, isWeb, platform };
5508
+ export { AsyncStorageAdapter, BlinkAIImpl, BlinkAnalyticsImpl, BlinkDataImpl, BlinkDatabase, BlinkRealtimeChannel, BlinkRealtimeImpl, BlinkStorageImpl, BlinkTable, NoOpStorageAdapter, WebStorageAdapter, createClient, getDefaultStorageAdapter, isBrowser, isNode, isReactNative, isWeb, platform };
5535
5509
  //# sourceMappingURL=index.mjs.map
5536
5510
  //# sourceMappingURL=index.mjs.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blinkdotnew/dev-sdk",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
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",