@blinkdotnew/sdk 2.0.2 → 2.1.0
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 +92 -6
- package/dist/index.d.ts +92 -6
- package/dist/index.js +5632 -0
- package/dist/index.mjs +5613 -0
- package/package.json +3 -2
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
|
}
|
|
@@ -737,7 +773,7 @@ interface BlinkNotifications {
|
|
|
737
773
|
*/
|
|
738
774
|
|
|
739
775
|
interface RequestOptions {
|
|
740
|
-
method?: 'GET' | 'POST' | 'PATCH' | 'DELETE';
|
|
776
|
+
method?: 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
|
|
741
777
|
headers?: Record<string, string>;
|
|
742
778
|
body?: any;
|
|
743
779
|
searchParams?: Record<string, string>;
|
|
@@ -752,9 +788,14 @@ declare class HttpClient {
|
|
|
752
788
|
private readonly authUrl;
|
|
753
789
|
private readonly coreUrl;
|
|
754
790
|
readonly projectId: string;
|
|
791
|
+
private readonly publishableKey?;
|
|
792
|
+
private readonly secretKey?;
|
|
755
793
|
private getToken;
|
|
756
794
|
private getValidToken?;
|
|
757
795
|
constructor(config: BlinkClientConfig, getToken: () => string | null, getValidToken?: () => Promise<string | null>);
|
|
796
|
+
private shouldAttachPublishableKey;
|
|
797
|
+
private shouldSkipSecretKey;
|
|
798
|
+
private getAuthorizationHeader;
|
|
758
799
|
/**
|
|
759
800
|
* Make an authenticated request to the Blink API
|
|
760
801
|
*/
|
|
@@ -836,7 +877,7 @@ declare class HttpClient {
|
|
|
836
877
|
signal?: AbortSignal;
|
|
837
878
|
}): Promise<BlinkResponse<any>>;
|
|
838
879
|
/**
|
|
839
|
-
* Stream AI text generation
|
|
880
|
+
* Stream AI text generation - uses Vercel AI SDK's pipeUIMessageStreamToResponse (Data Stream Protocol)
|
|
840
881
|
*/
|
|
841
882
|
streamAiText(prompt: string, options: {
|
|
842
883
|
model?: string | undefined;
|
|
@@ -860,7 +901,7 @@ declare class HttpClient {
|
|
|
860
901
|
signal?: AbortSignal;
|
|
861
902
|
}): Promise<BlinkResponse<any>>;
|
|
862
903
|
/**
|
|
863
|
-
* Stream AI object generation
|
|
904
|
+
* Stream AI object generation - uses Vercel AI SDK's pipeTextStreamToResponse
|
|
864
905
|
*/
|
|
865
906
|
streamAiObject(prompt: string, options: {
|
|
866
907
|
model?: string | undefined;
|
|
@@ -941,10 +982,10 @@ declare class HttpClient {
|
|
|
941
982
|
private parseResponse;
|
|
942
983
|
private handleErrorResponse;
|
|
943
984
|
/**
|
|
944
|
-
* Parse Vercel AI SDK
|
|
945
|
-
*
|
|
985
|
+
* Parse Vercel AI SDK v5 Data Stream Protocol (Server-Sent Events)
|
|
986
|
+
* Supports all event types from the UI Message Stream protocol
|
|
946
987
|
*/
|
|
947
|
-
private
|
|
988
|
+
private parseDataStreamProtocol;
|
|
948
989
|
}
|
|
949
990
|
|
|
950
991
|
/**
|
|
@@ -1633,6 +1674,50 @@ declare class BlinkAnalyticsImpl implements BlinkAnalytics {
|
|
|
1633
1674
|
private detectChannel;
|
|
1634
1675
|
}
|
|
1635
1676
|
|
|
1677
|
+
/**
|
|
1678
|
+
* Blink Functions - Edge function invocation helper
|
|
1679
|
+
* Provides a simple interface for calling Blink Edge Functions with automatic JWT attachment
|
|
1680
|
+
*/
|
|
1681
|
+
|
|
1682
|
+
interface FunctionsInvokeOptions {
|
|
1683
|
+
method?: 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
|
|
1684
|
+
body?: any;
|
|
1685
|
+
headers?: Record<string, string>;
|
|
1686
|
+
searchParams?: Record<string, string>;
|
|
1687
|
+
}
|
|
1688
|
+
interface FunctionsInvokeResponse<T = any> {
|
|
1689
|
+
data: T;
|
|
1690
|
+
status: number;
|
|
1691
|
+
headers: Headers;
|
|
1692
|
+
}
|
|
1693
|
+
interface BlinkFunctions {
|
|
1694
|
+
/**
|
|
1695
|
+
* Invoke a Blink Edge Function.
|
|
1696
|
+
*
|
|
1697
|
+
* Automatically attaches the user's JWT for authenticated requests.
|
|
1698
|
+
* The function URL is constructed as: https://{projectSuffix}--{functionSlug}.functions.blink.new
|
|
1699
|
+
*
|
|
1700
|
+
* @param functionSlug - The slug of the edge function to invoke
|
|
1701
|
+
* @param options - Request options (method, body, headers, etc.)
|
|
1702
|
+
* @returns The function response
|
|
1703
|
+
*
|
|
1704
|
+
* @example
|
|
1705
|
+
* // Simple POST request
|
|
1706
|
+
* const { data } = await blink.functions.invoke('my-function', {
|
|
1707
|
+
* method: 'POST',
|
|
1708
|
+
* body: { message: 'Hello' }
|
|
1709
|
+
* })
|
|
1710
|
+
*
|
|
1711
|
+
* @example
|
|
1712
|
+
* // GET request with query params
|
|
1713
|
+
* const { data } = await blink.functions.invoke('my-function', {
|
|
1714
|
+
* method: 'GET',
|
|
1715
|
+
* searchParams: { limit: '10' }
|
|
1716
|
+
* })
|
|
1717
|
+
*/
|
|
1718
|
+
invoke<T = any>(functionSlug: string, options?: FunctionsInvokeOptions): Promise<FunctionsInvokeResponse<T>>;
|
|
1719
|
+
}
|
|
1720
|
+
|
|
1636
1721
|
/**
|
|
1637
1722
|
* Blink Client - Main SDK entry point
|
|
1638
1723
|
* Factory function and client class for the Blink SDK
|
|
@@ -1647,6 +1732,7 @@ interface BlinkClient {
|
|
|
1647
1732
|
realtime: BlinkRealtime;
|
|
1648
1733
|
notifications: BlinkNotifications;
|
|
1649
1734
|
analytics: BlinkAnalytics;
|
|
1735
|
+
functions: BlinkFunctions;
|
|
1650
1736
|
}
|
|
1651
1737
|
/**
|
|
1652
1738
|
* Create a new Blink client instance
|
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
|
}
|
|
@@ -737,7 +773,7 @@ interface BlinkNotifications {
|
|
|
737
773
|
*/
|
|
738
774
|
|
|
739
775
|
interface RequestOptions {
|
|
740
|
-
method?: 'GET' | 'POST' | 'PATCH' | 'DELETE';
|
|
776
|
+
method?: 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
|
|
741
777
|
headers?: Record<string, string>;
|
|
742
778
|
body?: any;
|
|
743
779
|
searchParams?: Record<string, string>;
|
|
@@ -752,9 +788,14 @@ declare class HttpClient {
|
|
|
752
788
|
private readonly authUrl;
|
|
753
789
|
private readonly coreUrl;
|
|
754
790
|
readonly projectId: string;
|
|
791
|
+
private readonly publishableKey?;
|
|
792
|
+
private readonly secretKey?;
|
|
755
793
|
private getToken;
|
|
756
794
|
private getValidToken?;
|
|
757
795
|
constructor(config: BlinkClientConfig, getToken: () => string | null, getValidToken?: () => Promise<string | null>);
|
|
796
|
+
private shouldAttachPublishableKey;
|
|
797
|
+
private shouldSkipSecretKey;
|
|
798
|
+
private getAuthorizationHeader;
|
|
758
799
|
/**
|
|
759
800
|
* Make an authenticated request to the Blink API
|
|
760
801
|
*/
|
|
@@ -836,7 +877,7 @@ declare class HttpClient {
|
|
|
836
877
|
signal?: AbortSignal;
|
|
837
878
|
}): Promise<BlinkResponse<any>>;
|
|
838
879
|
/**
|
|
839
|
-
* Stream AI text generation
|
|
880
|
+
* Stream AI text generation - uses Vercel AI SDK's pipeUIMessageStreamToResponse (Data Stream Protocol)
|
|
840
881
|
*/
|
|
841
882
|
streamAiText(prompt: string, options: {
|
|
842
883
|
model?: string | undefined;
|
|
@@ -860,7 +901,7 @@ declare class HttpClient {
|
|
|
860
901
|
signal?: AbortSignal;
|
|
861
902
|
}): Promise<BlinkResponse<any>>;
|
|
862
903
|
/**
|
|
863
|
-
* Stream AI object generation
|
|
904
|
+
* Stream AI object generation - uses Vercel AI SDK's pipeTextStreamToResponse
|
|
864
905
|
*/
|
|
865
906
|
streamAiObject(prompt: string, options: {
|
|
866
907
|
model?: string | undefined;
|
|
@@ -941,10 +982,10 @@ declare class HttpClient {
|
|
|
941
982
|
private parseResponse;
|
|
942
983
|
private handleErrorResponse;
|
|
943
984
|
/**
|
|
944
|
-
* Parse Vercel AI SDK
|
|
945
|
-
*
|
|
985
|
+
* Parse Vercel AI SDK v5 Data Stream Protocol (Server-Sent Events)
|
|
986
|
+
* Supports all event types from the UI Message Stream protocol
|
|
946
987
|
*/
|
|
947
|
-
private
|
|
988
|
+
private parseDataStreamProtocol;
|
|
948
989
|
}
|
|
949
990
|
|
|
950
991
|
/**
|
|
@@ -1633,6 +1674,50 @@ declare class BlinkAnalyticsImpl implements BlinkAnalytics {
|
|
|
1633
1674
|
private detectChannel;
|
|
1634
1675
|
}
|
|
1635
1676
|
|
|
1677
|
+
/**
|
|
1678
|
+
* Blink Functions - Edge function invocation helper
|
|
1679
|
+
* Provides a simple interface for calling Blink Edge Functions with automatic JWT attachment
|
|
1680
|
+
*/
|
|
1681
|
+
|
|
1682
|
+
interface FunctionsInvokeOptions {
|
|
1683
|
+
method?: 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
|
|
1684
|
+
body?: any;
|
|
1685
|
+
headers?: Record<string, string>;
|
|
1686
|
+
searchParams?: Record<string, string>;
|
|
1687
|
+
}
|
|
1688
|
+
interface FunctionsInvokeResponse<T = any> {
|
|
1689
|
+
data: T;
|
|
1690
|
+
status: number;
|
|
1691
|
+
headers: Headers;
|
|
1692
|
+
}
|
|
1693
|
+
interface BlinkFunctions {
|
|
1694
|
+
/**
|
|
1695
|
+
* Invoke a Blink Edge Function.
|
|
1696
|
+
*
|
|
1697
|
+
* Automatically attaches the user's JWT for authenticated requests.
|
|
1698
|
+
* The function URL is constructed as: https://{projectSuffix}--{functionSlug}.functions.blink.new
|
|
1699
|
+
*
|
|
1700
|
+
* @param functionSlug - The slug of the edge function to invoke
|
|
1701
|
+
* @param options - Request options (method, body, headers, etc.)
|
|
1702
|
+
* @returns The function response
|
|
1703
|
+
*
|
|
1704
|
+
* @example
|
|
1705
|
+
* // Simple POST request
|
|
1706
|
+
* const { data } = await blink.functions.invoke('my-function', {
|
|
1707
|
+
* method: 'POST',
|
|
1708
|
+
* body: { message: 'Hello' }
|
|
1709
|
+
* })
|
|
1710
|
+
*
|
|
1711
|
+
* @example
|
|
1712
|
+
* // GET request with query params
|
|
1713
|
+
* const { data } = await blink.functions.invoke('my-function', {
|
|
1714
|
+
* method: 'GET',
|
|
1715
|
+
* searchParams: { limit: '10' }
|
|
1716
|
+
* })
|
|
1717
|
+
*/
|
|
1718
|
+
invoke<T = any>(functionSlug: string, options?: FunctionsInvokeOptions): Promise<FunctionsInvokeResponse<T>>;
|
|
1719
|
+
}
|
|
1720
|
+
|
|
1636
1721
|
/**
|
|
1637
1722
|
* Blink Client - Main SDK entry point
|
|
1638
1723
|
* Factory function and client class for the Blink SDK
|
|
@@ -1647,6 +1732,7 @@ interface BlinkClient {
|
|
|
1647
1732
|
realtime: BlinkRealtime;
|
|
1648
1733
|
notifications: BlinkNotifications;
|
|
1649
1734
|
analytics: BlinkAnalytics;
|
|
1735
|
+
functions: BlinkFunctions;
|
|
1650
1736
|
}
|
|
1651
1737
|
/**
|
|
1652
1738
|
* Create a new Blink client instance
|