@blinkdotnew/sdk 2.3.6 → 2.3.7
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.js +38 -30
- package/dist/index.mjs +38 -30
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -627,7 +627,7 @@ var HttpClient = class {
|
|
|
627
627
|
const blobWithType = options.contentType ? new Blob([file], { type: options.contentType }) : file;
|
|
628
628
|
formData.append("file", blobWithType);
|
|
629
629
|
} else if (typeof Buffer !== "undefined" && file instanceof Buffer) {
|
|
630
|
-
const blob = new Blob([file], { type: options.contentType || "application/octet-stream" });
|
|
630
|
+
const blob = new Blob([new Uint8Array(file)], { type: options.contentType || "application/octet-stream" });
|
|
631
631
|
formData.append("file", blob);
|
|
632
632
|
} else {
|
|
633
633
|
throw new BlinkValidationError("Unsupported file type");
|
|
@@ -1753,7 +1753,7 @@ var BlinkAuth = class {
|
|
|
1753
1753
|
token_type: result.token_type,
|
|
1754
1754
|
expires_in: result.expires_in,
|
|
1755
1755
|
refresh_expires_in: result.refresh_expires_in
|
|
1756
|
-
}, true);
|
|
1756
|
+
}, true, result.user);
|
|
1757
1757
|
return result.user;
|
|
1758
1758
|
} catch (error) {
|
|
1759
1759
|
if (error instanceof BlinkAuthError) {
|
|
@@ -1793,7 +1793,7 @@ var BlinkAuth = class {
|
|
|
1793
1793
|
token_type: result.token_type,
|
|
1794
1794
|
expires_in: result.expires_in,
|
|
1795
1795
|
refresh_expires_in: result.refresh_expires_in
|
|
1796
|
-
}, true);
|
|
1796
|
+
}, true, result.user);
|
|
1797
1797
|
return result.user;
|
|
1798
1798
|
} catch (error) {
|
|
1799
1799
|
if (error instanceof BlinkAuthError) {
|
|
@@ -2526,7 +2526,7 @@ var BlinkAuth = class {
|
|
|
2526
2526
|
token_type: result.token_type,
|
|
2527
2527
|
expires_in: result.expires_in,
|
|
2528
2528
|
refresh_expires_in: result.refresh_expires_in
|
|
2529
|
-
}, true);
|
|
2529
|
+
}, true, result.user);
|
|
2530
2530
|
return result.user;
|
|
2531
2531
|
} catch (error) {
|
|
2532
2532
|
if (error instanceof BlinkAuthError) {
|
|
@@ -2923,7 +2923,7 @@ var BlinkAuth = class {
|
|
|
2923
2923
|
return false;
|
|
2924
2924
|
}
|
|
2925
2925
|
}
|
|
2926
|
-
async setTokens(tokens, persist) {
|
|
2926
|
+
async setTokens(tokens, persist, knownUser) {
|
|
2927
2927
|
const tokensWithTimestamp = {
|
|
2928
2928
|
...tokens,
|
|
2929
2929
|
issued_at: tokens.issued_at || Math.floor(Date.now() / 1e3)
|
|
@@ -2933,7 +2933,8 @@ var BlinkAuth = class {
|
|
|
2933
2933
|
hasAccessToken: !!tokensWithTimestamp.access_token,
|
|
2934
2934
|
hasRefreshToken: !!tokensWithTimestamp.refresh_token,
|
|
2935
2935
|
expiresIn: tokensWithTimestamp.expires_in,
|
|
2936
|
-
issuedAt: tokensWithTimestamp.issued_at
|
|
2936
|
+
issuedAt: tokensWithTimestamp.issued_at,
|
|
2937
|
+
hasKnownUser: !!knownUser
|
|
2937
2938
|
});
|
|
2938
2939
|
if (persist) {
|
|
2939
2940
|
try {
|
|
@@ -2949,32 +2950,39 @@ var BlinkAuth = class {
|
|
|
2949
2950
|
console.log("\u{1F4A5} Error persisting tokens:", error);
|
|
2950
2951
|
}
|
|
2951
2952
|
}
|
|
2952
|
-
let user = null;
|
|
2953
|
-
|
|
2954
|
-
|
|
2955
|
-
|
|
2956
|
-
|
|
2957
|
-
|
|
2958
|
-
|
|
2959
|
-
|
|
2960
|
-
console.log("\u{1F4E1} User fetch response:", {
|
|
2961
|
-
status: response.status,
|
|
2962
|
-
statusText: response.statusText,
|
|
2963
|
-
ok: response.ok
|
|
2964
|
-
});
|
|
2965
|
-
if (response.ok) {
|
|
2966
|
-
const data = await response.json();
|
|
2967
|
-
user = data.user;
|
|
2968
|
-
console.log("\u2705 User data fetched successfully:", {
|
|
2969
|
-
id: user?.id,
|
|
2970
|
-
email: user?.email,
|
|
2971
|
-
displayName: user?.displayName
|
|
2953
|
+
let user = knownUser || null;
|
|
2954
|
+
if (!user) {
|
|
2955
|
+
try {
|
|
2956
|
+
console.log("\u{1F464} Fetching user data...");
|
|
2957
|
+
const response = await fetch(`${this.authUrl}/api/auth/me`, {
|
|
2958
|
+
headers: {
|
|
2959
|
+
"Authorization": `Bearer ${tokensWithTimestamp.access_token}`
|
|
2960
|
+
}
|
|
2972
2961
|
});
|
|
2973
|
-
|
|
2974
|
-
|
|
2962
|
+
console.log("\u{1F4E1} User fetch response:", {
|
|
2963
|
+
status: response.status,
|
|
2964
|
+
statusText: response.statusText,
|
|
2965
|
+
ok: response.ok
|
|
2966
|
+
});
|
|
2967
|
+
if (response.ok) {
|
|
2968
|
+
const data = await response.json();
|
|
2969
|
+
user = data.user;
|
|
2970
|
+
console.log("\u2705 User data fetched successfully:", {
|
|
2971
|
+
id: user?.id,
|
|
2972
|
+
email: user?.email,
|
|
2973
|
+
displayName: user?.displayName
|
|
2974
|
+
});
|
|
2975
|
+
} else {
|
|
2976
|
+
console.log("\u274C Failed to fetch user data:", await response.text());
|
|
2977
|
+
}
|
|
2978
|
+
} catch (error) {
|
|
2979
|
+
console.log("\u{1F4A5} Error fetching user data:", error);
|
|
2975
2980
|
}
|
|
2976
|
-
}
|
|
2977
|
-
console.log("\
|
|
2981
|
+
} else {
|
|
2982
|
+
console.log("\u2705 Using known user data (skipping /api/auth/me):", {
|
|
2983
|
+
id: user?.id,
|
|
2984
|
+
email: user?.email
|
|
2985
|
+
});
|
|
2978
2986
|
}
|
|
2979
2987
|
this.updateAuthState({
|
|
2980
2988
|
user,
|
package/dist/index.mjs
CHANGED
|
@@ -625,7 +625,7 @@ var HttpClient = class {
|
|
|
625
625
|
const blobWithType = options.contentType ? new Blob([file], { type: options.contentType }) : file;
|
|
626
626
|
formData.append("file", blobWithType);
|
|
627
627
|
} else if (typeof Buffer !== "undefined" && file instanceof Buffer) {
|
|
628
|
-
const blob = new Blob([file], { type: options.contentType || "application/octet-stream" });
|
|
628
|
+
const blob = new Blob([new Uint8Array(file)], { type: options.contentType || "application/octet-stream" });
|
|
629
629
|
formData.append("file", blob);
|
|
630
630
|
} else {
|
|
631
631
|
throw new BlinkValidationError("Unsupported file type");
|
|
@@ -1751,7 +1751,7 @@ var BlinkAuth = class {
|
|
|
1751
1751
|
token_type: result.token_type,
|
|
1752
1752
|
expires_in: result.expires_in,
|
|
1753
1753
|
refresh_expires_in: result.refresh_expires_in
|
|
1754
|
-
}, true);
|
|
1754
|
+
}, true, result.user);
|
|
1755
1755
|
return result.user;
|
|
1756
1756
|
} catch (error) {
|
|
1757
1757
|
if (error instanceof BlinkAuthError) {
|
|
@@ -1791,7 +1791,7 @@ var BlinkAuth = class {
|
|
|
1791
1791
|
token_type: result.token_type,
|
|
1792
1792
|
expires_in: result.expires_in,
|
|
1793
1793
|
refresh_expires_in: result.refresh_expires_in
|
|
1794
|
-
}, true);
|
|
1794
|
+
}, true, result.user);
|
|
1795
1795
|
return result.user;
|
|
1796
1796
|
} catch (error) {
|
|
1797
1797
|
if (error instanceof BlinkAuthError) {
|
|
@@ -2524,7 +2524,7 @@ var BlinkAuth = class {
|
|
|
2524
2524
|
token_type: result.token_type,
|
|
2525
2525
|
expires_in: result.expires_in,
|
|
2526
2526
|
refresh_expires_in: result.refresh_expires_in
|
|
2527
|
-
}, true);
|
|
2527
|
+
}, true, result.user);
|
|
2528
2528
|
return result.user;
|
|
2529
2529
|
} catch (error) {
|
|
2530
2530
|
if (error instanceof BlinkAuthError) {
|
|
@@ -2921,7 +2921,7 @@ var BlinkAuth = class {
|
|
|
2921
2921
|
return false;
|
|
2922
2922
|
}
|
|
2923
2923
|
}
|
|
2924
|
-
async setTokens(tokens, persist) {
|
|
2924
|
+
async setTokens(tokens, persist, knownUser) {
|
|
2925
2925
|
const tokensWithTimestamp = {
|
|
2926
2926
|
...tokens,
|
|
2927
2927
|
issued_at: tokens.issued_at || Math.floor(Date.now() / 1e3)
|
|
@@ -2931,7 +2931,8 @@ var BlinkAuth = class {
|
|
|
2931
2931
|
hasAccessToken: !!tokensWithTimestamp.access_token,
|
|
2932
2932
|
hasRefreshToken: !!tokensWithTimestamp.refresh_token,
|
|
2933
2933
|
expiresIn: tokensWithTimestamp.expires_in,
|
|
2934
|
-
issuedAt: tokensWithTimestamp.issued_at
|
|
2934
|
+
issuedAt: tokensWithTimestamp.issued_at,
|
|
2935
|
+
hasKnownUser: !!knownUser
|
|
2935
2936
|
});
|
|
2936
2937
|
if (persist) {
|
|
2937
2938
|
try {
|
|
@@ -2947,32 +2948,39 @@ var BlinkAuth = class {
|
|
|
2947
2948
|
console.log("\u{1F4A5} Error persisting tokens:", error);
|
|
2948
2949
|
}
|
|
2949
2950
|
}
|
|
2950
|
-
let user = null;
|
|
2951
|
-
|
|
2952
|
-
|
|
2953
|
-
|
|
2954
|
-
|
|
2955
|
-
|
|
2956
|
-
|
|
2957
|
-
|
|
2958
|
-
console.log("\u{1F4E1} User fetch response:", {
|
|
2959
|
-
status: response.status,
|
|
2960
|
-
statusText: response.statusText,
|
|
2961
|
-
ok: response.ok
|
|
2962
|
-
});
|
|
2963
|
-
if (response.ok) {
|
|
2964
|
-
const data = await response.json();
|
|
2965
|
-
user = data.user;
|
|
2966
|
-
console.log("\u2705 User data fetched successfully:", {
|
|
2967
|
-
id: user?.id,
|
|
2968
|
-
email: user?.email,
|
|
2969
|
-
displayName: user?.displayName
|
|
2951
|
+
let user = knownUser || null;
|
|
2952
|
+
if (!user) {
|
|
2953
|
+
try {
|
|
2954
|
+
console.log("\u{1F464} Fetching user data...");
|
|
2955
|
+
const response = await fetch(`${this.authUrl}/api/auth/me`, {
|
|
2956
|
+
headers: {
|
|
2957
|
+
"Authorization": `Bearer ${tokensWithTimestamp.access_token}`
|
|
2958
|
+
}
|
|
2970
2959
|
});
|
|
2971
|
-
|
|
2972
|
-
|
|
2960
|
+
console.log("\u{1F4E1} User fetch response:", {
|
|
2961
|
+
status: response.status,
|
|
2962
|
+
statusText: response.statusText,
|
|
2963
|
+
ok: response.ok
|
|
2964
|
+
});
|
|
2965
|
+
if (response.ok) {
|
|
2966
|
+
const data = await response.json();
|
|
2967
|
+
user = data.user;
|
|
2968
|
+
console.log("\u2705 User data fetched successfully:", {
|
|
2969
|
+
id: user?.id,
|
|
2970
|
+
email: user?.email,
|
|
2971
|
+
displayName: user?.displayName
|
|
2972
|
+
});
|
|
2973
|
+
} else {
|
|
2974
|
+
console.log("\u274C Failed to fetch user data:", await response.text());
|
|
2975
|
+
}
|
|
2976
|
+
} catch (error) {
|
|
2977
|
+
console.log("\u{1F4A5} Error fetching user data:", error);
|
|
2973
2978
|
}
|
|
2974
|
-
}
|
|
2975
|
-
console.log("\
|
|
2979
|
+
} else {
|
|
2980
|
+
console.log("\u2705 Using known user data (skipping /api/auth/me):", {
|
|
2981
|
+
id: user?.id,
|
|
2982
|
+
email: user?.email
|
|
2983
|
+
});
|
|
2976
2984
|
}
|
|
2977
2985
|
this.updateAuthState({
|
|
2978
2986
|
user,
|
package/package.json
CHANGED