@blinkdotnew/sdk 0.17.3 → 0.18.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/README.md +665 -85
- package/dist/index.d.mts +209 -47
- package/dist/index.d.ts +209 -47
- package/dist/index.js +902 -125
- package/dist/index.mjs +902 -125
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -4,6 +4,53 @@
|
|
|
4
4
|
interface BlinkClientConfig {
|
|
5
5
|
projectId: string;
|
|
6
6
|
authRequired?: boolean;
|
|
7
|
+
auth?: BlinkAuthConfig;
|
|
8
|
+
}
|
|
9
|
+
interface BlinkAuthConfig {
|
|
10
|
+
mode?: 'managed' | 'headless';
|
|
11
|
+
email?: {
|
|
12
|
+
requireVerification?: boolean;
|
|
13
|
+
allowSignUp?: boolean;
|
|
14
|
+
passwordRules?: {
|
|
15
|
+
minLength?: number;
|
|
16
|
+
requireUppercase?: boolean;
|
|
17
|
+
requireLowercase?: boolean;
|
|
18
|
+
requireNumbers?: boolean;
|
|
19
|
+
requireSpecialChars?: boolean;
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
roles?: {
|
|
23
|
+
[role: string]: {
|
|
24
|
+
permissions: string[];
|
|
25
|
+
inherit?: string[];
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
defaultRole?: string;
|
|
29
|
+
session?: {
|
|
30
|
+
duration?: number;
|
|
31
|
+
refreshThreshold?: number;
|
|
32
|
+
multiDevice?: boolean;
|
|
33
|
+
};
|
|
34
|
+
redirectUrl?: string;
|
|
35
|
+
authUrl?: string;
|
|
36
|
+
coreUrl?: string;
|
|
37
|
+
}
|
|
38
|
+
type AuthProvider = 'email' | 'google' | 'github' | 'apple' | 'microsoft' | 'twitter' | 'linkedin' | 'discord';
|
|
39
|
+
interface AuthOptions {
|
|
40
|
+
redirectUrl?: string;
|
|
41
|
+
metadata?: Record<string, any>;
|
|
42
|
+
}
|
|
43
|
+
interface SignUpData {
|
|
44
|
+
email: string;
|
|
45
|
+
password: string;
|
|
46
|
+
metadata?: {
|
|
47
|
+
displayName?: string;
|
|
48
|
+
avatar?: string;
|
|
49
|
+
[key: string]: any;
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
interface MagicLinkOptions {
|
|
53
|
+
redirectUrl?: string;
|
|
7
54
|
}
|
|
8
55
|
interface BlinkUser {
|
|
9
56
|
id: string;
|
|
@@ -13,6 +60,7 @@ interface BlinkUser {
|
|
|
13
60
|
emailVerified?: boolean;
|
|
14
61
|
createdAt?: string;
|
|
15
62
|
lastSignInAt?: string;
|
|
63
|
+
role?: string;
|
|
16
64
|
}
|
|
17
65
|
interface AuthTokens {
|
|
18
66
|
access_token: string;
|
|
@@ -768,9 +816,11 @@ declare class HttpClient {
|
|
|
768
816
|
type AuthStateChangeCallback = (state: AuthState) => void;
|
|
769
817
|
declare class BlinkAuth {
|
|
770
818
|
private config;
|
|
819
|
+
private authConfig;
|
|
771
820
|
private authState;
|
|
772
821
|
private listeners;
|
|
773
822
|
private readonly authUrl;
|
|
823
|
+
private readonly coreUrl;
|
|
774
824
|
private parentWindowTokens;
|
|
775
825
|
private isIframe;
|
|
776
826
|
private initializationPromise;
|
|
@@ -825,6 +875,111 @@ declare class BlinkAuth {
|
|
|
825
875
|
* Gracefully waits for auth initialization to complete before throwing errors
|
|
826
876
|
*/
|
|
827
877
|
me(): Promise<BlinkUser>;
|
|
878
|
+
/**
|
|
879
|
+
* Sign up with email and password (headless mode)
|
|
880
|
+
*/
|
|
881
|
+
signUp(data: SignUpData): Promise<BlinkUser>;
|
|
882
|
+
/**
|
|
883
|
+
* Sign in with email and password (headless mode)
|
|
884
|
+
*/
|
|
885
|
+
signInWithEmail(email: string, password: string): Promise<BlinkUser>;
|
|
886
|
+
/**
|
|
887
|
+
* Sign in with Google (headless mode)
|
|
888
|
+
*/
|
|
889
|
+
signInWithGoogle(options?: AuthOptions): Promise<BlinkUser>;
|
|
890
|
+
/**
|
|
891
|
+
* Sign in with GitHub (headless mode)
|
|
892
|
+
*/
|
|
893
|
+
signInWithGitHub(options?: AuthOptions): Promise<BlinkUser>;
|
|
894
|
+
/**
|
|
895
|
+
* Sign in with Apple (headless mode)
|
|
896
|
+
*/
|
|
897
|
+
signInWithApple(options?: AuthOptions): Promise<BlinkUser>;
|
|
898
|
+
/**
|
|
899
|
+
* Sign in with Microsoft (headless mode)
|
|
900
|
+
*/
|
|
901
|
+
signInWithMicrosoft(options?: AuthOptions): Promise<BlinkUser>;
|
|
902
|
+
/**
|
|
903
|
+
* Generic provider sign-in method (headless mode)
|
|
904
|
+
*/
|
|
905
|
+
signInWithProvider(provider: AuthProvider, options?: AuthOptions): Promise<BlinkUser>;
|
|
906
|
+
/**
|
|
907
|
+
* Generate password reset token (for custom email delivery)
|
|
908
|
+
*/
|
|
909
|
+
generatePasswordResetToken(email: string): Promise<{
|
|
910
|
+
token: string;
|
|
911
|
+
expiresAt: string;
|
|
912
|
+
resetUrl: string;
|
|
913
|
+
}>;
|
|
914
|
+
/**
|
|
915
|
+
* Send password reset email (using Blink default email service)
|
|
916
|
+
*/
|
|
917
|
+
sendPasswordResetEmail(email: string): Promise<void>;
|
|
918
|
+
/**
|
|
919
|
+
* Confirm password reset with token
|
|
920
|
+
*/
|
|
921
|
+
confirmPasswordReset(token: string, newPassword: string): Promise<void>;
|
|
922
|
+
/**
|
|
923
|
+
* Change password (requires current authentication)
|
|
924
|
+
*/
|
|
925
|
+
changePassword(oldPassword: string, newPassword: string): Promise<void>;
|
|
926
|
+
/**
|
|
927
|
+
* Generate email verification token (for custom email delivery)
|
|
928
|
+
*/
|
|
929
|
+
generateEmailVerificationToken(): Promise<{
|
|
930
|
+
token: string;
|
|
931
|
+
expiresAt: string;
|
|
932
|
+
verifyUrl: string;
|
|
933
|
+
}>;
|
|
934
|
+
/**
|
|
935
|
+
* Send email verification (using Blink default email service)
|
|
936
|
+
*/
|
|
937
|
+
sendEmailVerification(): Promise<void>;
|
|
938
|
+
/**
|
|
939
|
+
* Verify email with token
|
|
940
|
+
*/
|
|
941
|
+
verifyEmail(token: string): Promise<void>;
|
|
942
|
+
/**
|
|
943
|
+
* Generate magic link token (for custom email delivery)
|
|
944
|
+
*/
|
|
945
|
+
generateMagicLinkToken(email: string, options?: MagicLinkOptions): Promise<{
|
|
946
|
+
token: string;
|
|
947
|
+
expiresAt: string;
|
|
948
|
+
magicUrl: string;
|
|
949
|
+
}>;
|
|
950
|
+
/**
|
|
951
|
+
* Send magic link (using Blink default email service)
|
|
952
|
+
*/
|
|
953
|
+
sendMagicLink(email: string, options?: MagicLinkOptions): Promise<void>;
|
|
954
|
+
/**
|
|
955
|
+
* Verify magic link (automatic on redirect)
|
|
956
|
+
*/
|
|
957
|
+
verifyMagicLink(token?: string): Promise<BlinkUser>;
|
|
958
|
+
/**
|
|
959
|
+
* Get available providers for the current project
|
|
960
|
+
*/
|
|
961
|
+
getAvailableProviders(): Promise<AuthProvider[]>;
|
|
962
|
+
/**
|
|
963
|
+
* Check if user has a specific role
|
|
964
|
+
*/
|
|
965
|
+
hasRole(role: string | string[]): boolean;
|
|
966
|
+
/**
|
|
967
|
+
* Check if user can perform a specific action
|
|
968
|
+
*/
|
|
969
|
+
can(permission: string, resource?: string): boolean;
|
|
970
|
+
/**
|
|
971
|
+
* Sign out (clear local tokens)
|
|
972
|
+
* Note: With stateless tokens, this only clears local storage
|
|
973
|
+
*/
|
|
974
|
+
signOut(): Promise<void>;
|
|
975
|
+
/**
|
|
976
|
+
* @deprecated Use signOut() instead. Kept for backward compatibility.
|
|
977
|
+
*/
|
|
978
|
+
revokeAllSessions(): Promise<void>;
|
|
979
|
+
/**
|
|
980
|
+
* Recover auth state (clear corrupted tokens and re-initialize)
|
|
981
|
+
*/
|
|
982
|
+
recoverAuthState(): Promise<void>;
|
|
828
983
|
/**
|
|
829
984
|
* Update user profile
|
|
830
985
|
*/
|
|
@@ -853,6 +1008,22 @@ declare class BlinkAuth {
|
|
|
853
1008
|
private redirectToAuth;
|
|
854
1009
|
private setLoading;
|
|
855
1010
|
private updateAuthState;
|
|
1011
|
+
/**
|
|
1012
|
+
* Generate secure random state for OAuth flows
|
|
1013
|
+
*/
|
|
1014
|
+
private generateState;
|
|
1015
|
+
/**
|
|
1016
|
+
* Extract magic link token from URL
|
|
1017
|
+
*/
|
|
1018
|
+
private extractMagicTokenFromUrl;
|
|
1019
|
+
/**
|
|
1020
|
+
* Map server error codes to BlinkAuthErrorCode
|
|
1021
|
+
*/
|
|
1022
|
+
private mapErrorCodeFromResponse;
|
|
1023
|
+
/**
|
|
1024
|
+
* Setup cross-tab authentication synchronization
|
|
1025
|
+
*/
|
|
1026
|
+
private setupCrossTabSync;
|
|
856
1027
|
}
|
|
857
1028
|
|
|
858
1029
|
/**
|
|
@@ -1447,14 +1618,11 @@ declare class BlinkAIImpl implements BlinkAI {
|
|
|
1447
1618
|
*/
|
|
1448
1619
|
streamObject(options: ObjectGenerationRequest, onPartial: (partial: any) => void): Promise<ObjectGenerationResponse>;
|
|
1449
1620
|
/**
|
|
1450
|
-
* Generates images from text descriptions using
|
|
1621
|
+
* Generates images from text descriptions using Gemini 2.5 Flash Image.
|
|
1451
1622
|
*
|
|
1452
1623
|
* @param options - Object containing:
|
|
1453
|
-
* - `prompt`: Text description of the desired image (required)
|
|
1454
|
-
* - `size`: Image dimensions (default: "1024x1024")
|
|
1455
|
-
* - `quality`: Image quality ("auto", "low", "medium", or "high", default: "auto")
|
|
1624
|
+
* - `prompt`: Text description of the desired image (required, up to 100k characters)
|
|
1456
1625
|
* - `n`: Number of images to generate (default: 1)
|
|
1457
|
-
* - `background`: Background handling ("auto", "transparent", "opaque", default: "auto")
|
|
1458
1626
|
* - Plus optional signal parameter
|
|
1459
1627
|
*
|
|
1460
1628
|
* @example
|
|
@@ -1465,47 +1633,36 @@ declare class BlinkAIImpl implements BlinkAI {
|
|
|
1465
1633
|
* });
|
|
1466
1634
|
* console.log("Image URL:", data[0].url);
|
|
1467
1635
|
*
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
* background: "transparent"
|
|
1474
|
-
* });
|
|
1475
|
-
*
|
|
1476
|
-
* // Multiple images
|
|
1477
|
-
* const { data } = await blink.ai.generateImage({
|
|
1478
|
-
* prompt: "A cute robot mascot for a tech company",
|
|
1479
|
-
* n: 3,
|
|
1480
|
-
* size: "1024x1024",
|
|
1481
|
-
* quality: "high"
|
|
1482
|
-
* });
|
|
1636
|
+
* // Multiple images
|
|
1637
|
+
* const { data } = await blink.ai.generateImage({
|
|
1638
|
+
* prompt: "A futuristic city skyline with flying cars",
|
|
1639
|
+
* n: 3
|
|
1640
|
+
* });
|
|
1483
1641
|
* data.forEach((img, i) => console.log(`Image ${i+1}:`, img.url));
|
|
1642
|
+
*
|
|
1643
|
+
* // Detailed prompt for better results
|
|
1644
|
+
* const { data } = await blink.ai.generateImage({
|
|
1645
|
+
* prompt: "A cute robot mascot for a tech company, digital art style, vibrant colors, modern design, friendly expression"
|
|
1646
|
+
* });
|
|
1484
1647
|
* ```
|
|
1485
1648
|
*
|
|
1486
1649
|
* @returns Promise<ImageGenerationResponse> - Object containing:
|
|
1487
1650
|
* - `data`: Array of generated images with URLs
|
|
1488
1651
|
* - `created`: Timestamp of generation
|
|
1489
|
-
* - `
|
|
1652
|
+
* - `model`: Always "gemini-2.5-flash-image-preview"
|
|
1490
1653
|
*/
|
|
1491
1654
|
generateImage(options: {
|
|
1492
1655
|
prompt: string;
|
|
1493
|
-
size?: string;
|
|
1494
|
-
quality?: "auto" | "low" | "medium" | "high";
|
|
1495
1656
|
n?: number;
|
|
1496
|
-
background?: "auto" | "transparent" | "opaque";
|
|
1497
1657
|
signal?: AbortSignal;
|
|
1498
1658
|
}): Promise<ImageGenerationResponse>;
|
|
1499
1659
|
/**
|
|
1500
|
-
* Modifies existing images using
|
|
1660
|
+
* Modifies existing images using Gemini 2.5 Flash Image with text prompts for image-to-image editing.
|
|
1501
1661
|
*
|
|
1502
1662
|
* @param options - Object containing:
|
|
1503
|
-
* - `images`: Array of public image URLs to modify (required, up to
|
|
1504
|
-
* - `prompt`: Text description of desired modifications (required)
|
|
1505
|
-
* - `size`: Output image dimensions (default: "auto")
|
|
1506
|
-
* - `quality`: Image quality ("auto", "low", "medium", or "high", default: "auto")
|
|
1663
|
+
* - `images`: Array of public image URLs to modify (required, up to 50 images)
|
|
1664
|
+
* - `prompt`: Text description of desired modifications (required, up to 100k characters)
|
|
1507
1665
|
* - `n`: Number of output images to generate (default: 1)
|
|
1508
|
-
* - `background`: Background handling ("auto", "transparent", "opaque", default: "auto")
|
|
1509
1666
|
* - Plus optional signal parameter
|
|
1510
1667
|
*
|
|
1511
1668
|
* @example
|
|
@@ -1516,25 +1673,21 @@ declare class BlinkAIImpl implements BlinkAI {
|
|
|
1516
1673
|
* "https://storage.example.com/user-photo-1.jpg",
|
|
1517
1674
|
* "https://storage.example.com/user-photo-2.jpg"
|
|
1518
1675
|
* ],
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
* n: 4
|
|
1676
|
+
* prompt: "Transform into professional business headshots with studio lighting",
|
|
1677
|
+
* n: 4
|
|
1522
1678
|
* });
|
|
1523
1679
|
* data.forEach((img, i) => console.log(`Headshot ${i+1}:`, img.url));
|
|
1524
1680
|
*
|
|
1525
1681
|
* // Artistic style transformation
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
* size: "1024x1024"
|
|
1531
|
-
* });
|
|
1682
|
+
* const { data } = await blink.ai.modifyImage({
|
|
1683
|
+
* images: ["https://storage.example.com/portrait.jpg"],
|
|
1684
|
+
* prompt: "Transform into oil painting style with dramatic lighting"
|
|
1685
|
+
* });
|
|
1532
1686
|
*
|
|
1533
1687
|
* // Background replacement
|
|
1534
1688
|
* const { data } = await blink.ai.modifyImage({
|
|
1535
1689
|
* images: ["https://storage.example.com/product.jpg"],
|
|
1536
1690
|
* prompt: "Remove background and place on clean white studio background",
|
|
1537
|
-
* background: "transparent",
|
|
1538
1691
|
* n: 2
|
|
1539
1692
|
* });
|
|
1540
1693
|
*
|
|
@@ -1545,24 +1698,33 @@ declare class BlinkAIImpl implements BlinkAI {
|
|
|
1545
1698
|
* "https://storage.example.com/photo3.jpg"
|
|
1546
1699
|
* ];
|
|
1547
1700
|
* const { data } = await blink.ai.modifyImage({
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1701
|
+
* images: userPhotos,
|
|
1702
|
+
* prompt: "Convert to black and white vintage style photographs"
|
|
1703
|
+
* });
|
|
1704
|
+
*
|
|
1705
|
+
* // 🎨 Style Transfer - IMPORTANT: Provide all images in array
|
|
1706
|
+
* // ❌ WRONG - Don't reference other images in prompt
|
|
1707
|
+
* const wrong = await blink.ai.modifyImage({
|
|
1708
|
+
* images: [userPhotoUrl],
|
|
1709
|
+
* prompt: `Apply hairstyle from ${referenceUrl}`
|
|
1710
|
+
* });
|
|
1711
|
+
*
|
|
1712
|
+
* // ✅ CORRECT - Provide all images in array
|
|
1713
|
+
* const { data } = await blink.ai.modifyImage({
|
|
1714
|
+
* images: [userPhotoUrl, hairstyleReferenceUrl],
|
|
1715
|
+
* prompt: "Apply the hairstyle from the second image to the person in the first image"
|
|
1551
1716
|
* });
|
|
1552
1717
|
* ```
|
|
1553
1718
|
*
|
|
1554
1719
|
* @returns Promise<ImageGenerationResponse> - Object containing:
|
|
1555
1720
|
* - `data`: Array of modified images with URLs
|
|
1556
1721
|
* - `created`: Timestamp of generation
|
|
1557
|
-
* - `
|
|
1722
|
+
* - `model`: Always "gemini-2.5-flash-image-preview"
|
|
1558
1723
|
*/
|
|
1559
1724
|
modifyImage(options: {
|
|
1560
1725
|
images: string[];
|
|
1561
1726
|
prompt: string;
|
|
1562
|
-
size?: string;
|
|
1563
|
-
quality?: "auto" | "low" | "medium" | "high";
|
|
1564
1727
|
n?: number;
|
|
1565
|
-
background?: "auto" | "transparent" | "opaque";
|
|
1566
1728
|
signal?: AbortSignal;
|
|
1567
1729
|
}): Promise<ImageGenerationResponse>;
|
|
1568
1730
|
/**
|