@blinkdotnew/dev-sdk 0.0.1 → 2.1.1

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
@@ -61,6 +61,39 @@ interface BlinkClientConfig {
61
61
  projectId: string;
62
62
  authRequired?: boolean;
63
63
  auth?: BlinkAuthConfig;
64
+ /**
65
+ * Publishable key (client-safe).
66
+ *
67
+ * Used for **public endpoints** when no user JWT is present (e.g. analytics ingest, storage upload,
68
+ * optional public DB reads). Never use for privileged operations.
69
+ */
70
+ publishableKey?: string;
71
+ /**
72
+ * Secret key (server-only, privileged). Permanent, never expires.
73
+ *
74
+ * Used in **server runtimes** (Edge Functions, Workers) for privileged operations that require
75
+ * service-role access (e.g. raw SQL, bypassing row-level security).
76
+ *
77
+ * Format: `blnk_sk_{projectId-last-8}_{random}` (similar to Stripe's `sk_live_...`)
78
+ *
79
+ * **Security**: Never expose this key in client-side code. It is injected by the platform
80
+ * into edge function environments as `BLINK_SECRET_KEY`.
81
+ *
82
+ * When present, this key takes precedence over user JWTs for all requests.
83
+ *
84
+ * @example
85
+ * // Edge function (Deno)
86
+ * const blink = createClient({
87
+ * projectId: Deno.env.get('BLINK_PROJECT_ID')!,
88
+ * secretKey: Deno.env.get('BLINK_SECRET_KEY'),
89
+ * })
90
+ */
91
+ secretKey?: string;
92
+ /**
93
+ * @deprecated Use `secretKey` instead. Service tokens are JWT-based and expire after 365 days.
94
+ * Secret keys are permanent and never expire.
95
+ */
96
+ serviceToken?: string;
64
97
  /**
65
98
  * Storage adapter for cross-platform token persistence
66
99
  *
@@ -281,6 +314,9 @@ declare class BlinkError extends Error {
281
314
  constructor(message: string, code?: string | undefined, status?: number | undefined, details?: any);
282
315
  }
283
316
  interface StorageUploadOptions {
317
+ /**
318
+ * @deprecated Blink storage uploads are add-only by default. This option is ignored.
319
+ */
284
320
  upsert?: boolean;
285
321
  onProgress?: (percent: number) => void;
286
322
  }
@@ -785,7 +821,7 @@ declare class BlinkConnectorError extends BlinkError {
785
821
  */
786
822
 
787
823
  interface RequestOptions {
788
- method?: 'GET' | 'POST' | 'PATCH' | 'DELETE';
824
+ method?: 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
789
825
  headers?: Record<string, string>;
790
826
  body?: any;
791
827
  searchParams?: Record<string, string>;
@@ -800,9 +836,14 @@ declare class HttpClient {
800
836
  private readonly authUrl;
801
837
  private readonly coreUrl;
802
838
  readonly projectId: string;
839
+ private readonly publishableKey?;
840
+ private readonly secretKey?;
803
841
  private getToken;
804
842
  private getValidToken?;
805
843
  constructor(config: BlinkClientConfig, getToken: () => string | null, getValidToken?: () => Promise<string | null>);
844
+ private shouldAttachPublishableKey;
845
+ private shouldSkipSecretKey;
846
+ private getAuthorizationHeader;
806
847
  /**
807
848
  * Make an authenticated request to the Blink API
808
849
  */
@@ -884,7 +925,7 @@ declare class HttpClient {
884
925
  signal?: AbortSignal;
885
926
  }): Promise<BlinkResponse<any>>;
886
927
  /**
887
- * Stream AI text generation with Vercel AI SDK data stream format
928
+ * Stream AI text generation - uses Vercel AI SDK's pipeUIMessageStreamToResponse (Data Stream Protocol)
888
929
  */
889
930
  streamAiText(prompt: string, options: {
890
931
  model?: string | undefined;
@@ -908,7 +949,7 @@ declare class HttpClient {
908
949
  signal?: AbortSignal;
909
950
  }): Promise<BlinkResponse<any>>;
910
951
  /**
911
- * Stream AI object generation with Vercel AI SDK data stream format
952
+ * Stream AI object generation - uses Vercel AI SDK's pipeTextStreamToResponse
912
953
  */
913
954
  streamAiObject(prompt: string, options: {
914
955
  model?: string | undefined;
@@ -996,17 +1037,17 @@ declare class HttpClient {
996
1037
  private parseResponse;
997
1038
  private handleErrorResponse;
998
1039
  /**
999
- * Parse Vercel AI SDK data stream format
1000
- * Handles text chunks (0:"text"), partial objects (2:[...]), and metadata (d:, e:)
1040
+ * Parse Vercel AI SDK v5 Data Stream Protocol (Server-Sent Events)
1041
+ * Supports all event types from the UI Message Stream protocol
1001
1042
  */
1002
- private parseDataStream;
1043
+ private parseDataStreamProtocol;
1003
1044
  }
1004
1045
 
1005
1046
  /**
1006
1047
  * Platform detection for cross-platform compatibility
1007
- * Detects whether code is running on web, React Native, or Node.js
1048
+ * Detects whether code is running on web, React Native, Node.js, or Deno
1008
1049
  */
1009
- type Platform = 'web' | 'react-native' | 'node';
1050
+ type Platform = 'web' | 'react-native' | 'node' | 'deno';
1010
1051
  /**
1011
1052
  * Current platform
1012
1053
  */
@@ -1017,7 +1058,9 @@ declare const platform: Platform;
1017
1058
  declare const isWeb: boolean;
1018
1059
  declare const isReactNative: boolean;
1019
1060
  declare const isNode: boolean;
1061
+ declare const isDeno: boolean;
1020
1062
  declare const isBrowser: boolean;
1063
+ declare const isServer: boolean;
1021
1064
 
1022
1065
  /**
1023
1066
  * Blink Auth Module - Client-side authentication management
@@ -1688,6 +1731,50 @@ declare class BlinkAnalyticsImpl implements BlinkAnalytics {
1688
1731
  private detectChannel;
1689
1732
  }
1690
1733
 
1734
+ /**
1735
+ * Blink Functions - Edge function invocation helper
1736
+ * Provides a simple interface for calling Blink Edge Functions with automatic JWT attachment
1737
+ */
1738
+
1739
+ interface FunctionsInvokeOptions {
1740
+ method?: 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
1741
+ body?: any;
1742
+ headers?: Record<string, string>;
1743
+ searchParams?: Record<string, string>;
1744
+ }
1745
+ interface FunctionsInvokeResponse<T = any> {
1746
+ data: T;
1747
+ status: number;
1748
+ headers: Headers;
1749
+ }
1750
+ interface BlinkFunctions {
1751
+ /**
1752
+ * Invoke a Blink Edge Function.
1753
+ *
1754
+ * Automatically attaches the user's JWT for authenticated requests.
1755
+ * The function URL is constructed as: https://{projectSuffix}--{functionSlug}.functions.blink.new
1756
+ *
1757
+ * @param functionSlug - The slug of the edge function to invoke
1758
+ * @param options - Request options (method, body, headers, etc.)
1759
+ * @returns The function response
1760
+ *
1761
+ * @example
1762
+ * // Simple POST request
1763
+ * const { data } = await blink.functions.invoke('my-function', {
1764
+ * method: 'POST',
1765
+ * body: { message: 'Hello' }
1766
+ * })
1767
+ *
1768
+ * @example
1769
+ * // GET request with query params
1770
+ * const { data } = await blink.functions.invoke('my-function', {
1771
+ * method: 'GET',
1772
+ * searchParams: { limit: '10' }
1773
+ * })
1774
+ */
1775
+ invoke<T = any>(functionSlug: string, options?: FunctionsInvokeOptions): Promise<FunctionsInvokeResponse<T>>;
1776
+ }
1777
+
1691
1778
  /**
1692
1779
  * Blink Client - Main SDK entry point
1693
1780
  * Factory function and client class for the Blink SDK
@@ -1703,6 +1790,7 @@ interface BlinkClient {
1703
1790
  notifications: BlinkNotifications;
1704
1791
  analytics: BlinkAnalytics;
1705
1792
  connectors: BlinkConnectors;
1793
+ functions: BlinkFunctions;
1706
1794
  }
1707
1795
  /**
1708
1796
  * Create a new Blink client instance
@@ -2362,4 +2450,4 @@ declare class BlinkConnectorsImpl implements BlinkConnectors {
2362
2450
  saveApiKey<TMetadata = Record<string, unknown>>(provider: ConnectorProvider, request: ConnectorApiKeyRequest<TMetadata>): Promise<ConnectorApiKeyResponse>;
2363
2451
  }
2364
2452
 
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 };
2453
+ 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, isDeno, isNode, isReactNative, isServer, isWeb, platform };
package/dist/index.d.ts CHANGED
@@ -61,6 +61,39 @@ interface BlinkClientConfig {
61
61
  projectId: string;
62
62
  authRequired?: boolean;
63
63
  auth?: BlinkAuthConfig;
64
+ /**
65
+ * Publishable key (client-safe).
66
+ *
67
+ * Used for **public endpoints** when no user JWT is present (e.g. analytics ingest, storage upload,
68
+ * optional public DB reads). Never use for privileged operations.
69
+ */
70
+ publishableKey?: string;
71
+ /**
72
+ * Secret key (server-only, privileged). Permanent, never expires.
73
+ *
74
+ * Used in **server runtimes** (Edge Functions, Workers) for privileged operations that require
75
+ * service-role access (e.g. raw SQL, bypassing row-level security).
76
+ *
77
+ * Format: `blnk_sk_{projectId-last-8}_{random}` (similar to Stripe's `sk_live_...`)
78
+ *
79
+ * **Security**: Never expose this key in client-side code. It is injected by the platform
80
+ * into edge function environments as `BLINK_SECRET_KEY`.
81
+ *
82
+ * When present, this key takes precedence over user JWTs for all requests.
83
+ *
84
+ * @example
85
+ * // Edge function (Deno)
86
+ * const blink = createClient({
87
+ * projectId: Deno.env.get('BLINK_PROJECT_ID')!,
88
+ * secretKey: Deno.env.get('BLINK_SECRET_KEY'),
89
+ * })
90
+ */
91
+ secretKey?: string;
92
+ /**
93
+ * @deprecated Use `secretKey` instead. Service tokens are JWT-based and expire after 365 days.
94
+ * Secret keys are permanent and never expire.
95
+ */
96
+ serviceToken?: string;
64
97
  /**
65
98
  * Storage adapter for cross-platform token persistence
66
99
  *
@@ -281,6 +314,9 @@ declare class BlinkError extends Error {
281
314
  constructor(message: string, code?: string | undefined, status?: number | undefined, details?: any);
282
315
  }
283
316
  interface StorageUploadOptions {
317
+ /**
318
+ * @deprecated Blink storage uploads are add-only by default. This option is ignored.
319
+ */
284
320
  upsert?: boolean;
285
321
  onProgress?: (percent: number) => void;
286
322
  }
@@ -785,7 +821,7 @@ declare class BlinkConnectorError extends BlinkError {
785
821
  */
786
822
 
787
823
  interface RequestOptions {
788
- method?: 'GET' | 'POST' | 'PATCH' | 'DELETE';
824
+ method?: 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
789
825
  headers?: Record<string, string>;
790
826
  body?: any;
791
827
  searchParams?: Record<string, string>;
@@ -800,9 +836,14 @@ declare class HttpClient {
800
836
  private readonly authUrl;
801
837
  private readonly coreUrl;
802
838
  readonly projectId: string;
839
+ private readonly publishableKey?;
840
+ private readonly secretKey?;
803
841
  private getToken;
804
842
  private getValidToken?;
805
843
  constructor(config: BlinkClientConfig, getToken: () => string | null, getValidToken?: () => Promise<string | null>);
844
+ private shouldAttachPublishableKey;
845
+ private shouldSkipSecretKey;
846
+ private getAuthorizationHeader;
806
847
  /**
807
848
  * Make an authenticated request to the Blink API
808
849
  */
@@ -884,7 +925,7 @@ declare class HttpClient {
884
925
  signal?: AbortSignal;
885
926
  }): Promise<BlinkResponse<any>>;
886
927
  /**
887
- * Stream AI text generation with Vercel AI SDK data stream format
928
+ * Stream AI text generation - uses Vercel AI SDK's pipeUIMessageStreamToResponse (Data Stream Protocol)
888
929
  */
889
930
  streamAiText(prompt: string, options: {
890
931
  model?: string | undefined;
@@ -908,7 +949,7 @@ declare class HttpClient {
908
949
  signal?: AbortSignal;
909
950
  }): Promise<BlinkResponse<any>>;
910
951
  /**
911
- * Stream AI object generation with Vercel AI SDK data stream format
952
+ * Stream AI object generation - uses Vercel AI SDK's pipeTextStreamToResponse
912
953
  */
913
954
  streamAiObject(prompt: string, options: {
914
955
  model?: string | undefined;
@@ -996,17 +1037,17 @@ declare class HttpClient {
996
1037
  private parseResponse;
997
1038
  private handleErrorResponse;
998
1039
  /**
999
- * Parse Vercel AI SDK data stream format
1000
- * Handles text chunks (0:"text"), partial objects (2:[...]), and metadata (d:, e:)
1040
+ * Parse Vercel AI SDK v5 Data Stream Protocol (Server-Sent Events)
1041
+ * Supports all event types from the UI Message Stream protocol
1001
1042
  */
1002
- private parseDataStream;
1043
+ private parseDataStreamProtocol;
1003
1044
  }
1004
1045
 
1005
1046
  /**
1006
1047
  * Platform detection for cross-platform compatibility
1007
- * Detects whether code is running on web, React Native, or Node.js
1048
+ * Detects whether code is running on web, React Native, Node.js, or Deno
1008
1049
  */
1009
- type Platform = 'web' | 'react-native' | 'node';
1050
+ type Platform = 'web' | 'react-native' | 'node' | 'deno';
1010
1051
  /**
1011
1052
  * Current platform
1012
1053
  */
@@ -1017,7 +1058,9 @@ declare const platform: Platform;
1017
1058
  declare const isWeb: boolean;
1018
1059
  declare const isReactNative: boolean;
1019
1060
  declare const isNode: boolean;
1061
+ declare const isDeno: boolean;
1020
1062
  declare const isBrowser: boolean;
1063
+ declare const isServer: boolean;
1021
1064
 
1022
1065
  /**
1023
1066
  * Blink Auth Module - Client-side authentication management
@@ -1688,6 +1731,50 @@ declare class BlinkAnalyticsImpl implements BlinkAnalytics {
1688
1731
  private detectChannel;
1689
1732
  }
1690
1733
 
1734
+ /**
1735
+ * Blink Functions - Edge function invocation helper
1736
+ * Provides a simple interface for calling Blink Edge Functions with automatic JWT attachment
1737
+ */
1738
+
1739
+ interface FunctionsInvokeOptions {
1740
+ method?: 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
1741
+ body?: any;
1742
+ headers?: Record<string, string>;
1743
+ searchParams?: Record<string, string>;
1744
+ }
1745
+ interface FunctionsInvokeResponse<T = any> {
1746
+ data: T;
1747
+ status: number;
1748
+ headers: Headers;
1749
+ }
1750
+ interface BlinkFunctions {
1751
+ /**
1752
+ * Invoke a Blink Edge Function.
1753
+ *
1754
+ * Automatically attaches the user's JWT for authenticated requests.
1755
+ * The function URL is constructed as: https://{projectSuffix}--{functionSlug}.functions.blink.new
1756
+ *
1757
+ * @param functionSlug - The slug of the edge function to invoke
1758
+ * @param options - Request options (method, body, headers, etc.)
1759
+ * @returns The function response
1760
+ *
1761
+ * @example
1762
+ * // Simple POST request
1763
+ * const { data } = await blink.functions.invoke('my-function', {
1764
+ * method: 'POST',
1765
+ * body: { message: 'Hello' }
1766
+ * })
1767
+ *
1768
+ * @example
1769
+ * // GET request with query params
1770
+ * const { data } = await blink.functions.invoke('my-function', {
1771
+ * method: 'GET',
1772
+ * searchParams: { limit: '10' }
1773
+ * })
1774
+ */
1775
+ invoke<T = any>(functionSlug: string, options?: FunctionsInvokeOptions): Promise<FunctionsInvokeResponse<T>>;
1776
+ }
1777
+
1691
1778
  /**
1692
1779
  * Blink Client - Main SDK entry point
1693
1780
  * Factory function and client class for the Blink SDK
@@ -1703,6 +1790,7 @@ interface BlinkClient {
1703
1790
  notifications: BlinkNotifications;
1704
1791
  analytics: BlinkAnalytics;
1705
1792
  connectors: BlinkConnectors;
1793
+ functions: BlinkFunctions;
1706
1794
  }
1707
1795
  /**
1708
1796
  * Create a new Blink client instance
@@ -2362,4 +2450,4 @@ declare class BlinkConnectorsImpl implements BlinkConnectors {
2362
2450
  saveApiKey<TMetadata = Record<string, unknown>>(provider: ConnectorProvider, request: ConnectorApiKeyRequest<TMetadata>): Promise<ConnectorApiKeyResponse>;
2363
2451
  }
2364
2452
 
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 };
2453
+ 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, isDeno, isNode, isReactNative, isServer, isWeb, platform };