tevrocsdk 0.1.81 → 0.1.82
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 +12 -0
- package/package.json +1 -1
- package/tevroc-sdk.cjs.js +1110 -324
- package/tevroc-sdk.cjs.js.map +4 -4
- package/tevroc-sdk.esm.js +225 -105
- package/tevroc-sdk.esm.js.map +4 -4
package/tevroc-sdk.cjs.js
CHANGED
|
@@ -3639,6 +3639,7 @@ __export(useGoogleAuth_exports, {
|
|
|
3639
3639
|
subscribeGoogleLogin: () => subscribeGoogleLogin
|
|
3640
3640
|
});
|
|
3641
3641
|
function emitGoogleLogin(user, err = null) {
|
|
3642
|
+
debugAuth("Emitting login result", { success: Boolean(user), error: err?.message || null });
|
|
3642
3643
|
googleListeners.forEach((cb) => {
|
|
3643
3644
|
try {
|
|
3644
3645
|
cb(user, err);
|
|
@@ -3648,13 +3649,15 @@ function emitGoogleLogin(user, err = null) {
|
|
|
3648
3649
|
});
|
|
3649
3650
|
}
|
|
3650
3651
|
function subscribeGoogleLogin(cb) {
|
|
3652
|
+
debugAuth("Listener subscribed", { count: googleListeners.length + 1 });
|
|
3651
3653
|
googleListeners.push(cb);
|
|
3652
3654
|
return () => {
|
|
3653
3655
|
const i = googleListeners.indexOf(cb);
|
|
3654
3656
|
if (i !== -1) googleListeners.splice(i, 1);
|
|
3657
|
+
debugAuth("Listener unsubscribed", { count: googleListeners.length });
|
|
3655
3658
|
};
|
|
3656
3659
|
}
|
|
3657
|
-
var capacitorPluginsPromise, tauriWebviewWindowPromise, getCapacitorPlugins, getTauriWebviewWindow, googleInitialized, googleListeners, authWindowRef, authCleanupTimer, authMessageListener, closeAllTauriWebviews, cleanupAuthWindow, handleCallback, initializeGoogleLogin, createGoogleLogin;
|
|
3660
|
+
var capacitorPluginsPromise, tauriWebviewWindowPromise, getCapacitorPlugins, debugAuth, debugAuthWarn, debugAuthError, getTauriWebviewWindow, googleInitialized, googleListeners, authWindowRef, authCleanupTimer, authMessageListener, closeAllTauriWebviews, cleanupAuthWindow, handleCallback, initializeGoogleLogin, createGoogleLogin;
|
|
3658
3661
|
var init_useGoogleAuth = __esm({
|
|
3659
3662
|
"src/services/useGoogleAuth.js"() {
|
|
3660
3663
|
init_usePlatform();
|
|
@@ -3663,6 +3666,9 @@ var init_useGoogleAuth = __esm({
|
|
|
3663
3666
|
capacitorPluginsPromise ??= Promise.all([Promise.resolve().then(() => __toESM(require_plugin_cjs(), 1)), Promise.resolve().then(() => __toESM(require_plugin_cjs2(), 1))]).then(([appModule, browserModule]) => ({ App: appModule.App, Browser: browserModule.Browser }));
|
|
3664
3667
|
return capacitorPluginsPromise;
|
|
3665
3668
|
};
|
|
3669
|
+
debugAuth = (...args) => debugLog("[tevrocsdk][google-auth]", ...args);
|
|
3670
|
+
debugAuthWarn = (...args) => debugWarn("[tevrocsdk][google-auth]", ...args);
|
|
3671
|
+
debugAuthError = (...args) => debugError("[tevrocsdk][google-auth]", ...args);
|
|
3666
3672
|
getTauriWebviewWindow = async () => {
|
|
3667
3673
|
tauriWebviewWindowPromise ??= Promise.resolve().then(() => (init_webviewWindow(), webviewWindow_exports)).then((module2) => module2.WebviewWindow);
|
|
3668
3674
|
return tauriWebviewWindowPromise;
|
|
@@ -3701,6 +3707,7 @@ var init_useGoogleAuth = __esm({
|
|
|
3701
3707
|
}
|
|
3702
3708
|
};
|
|
3703
3709
|
cleanupAuthWindow = async () => {
|
|
3710
|
+
debugAuth("Cleaning up auth window", { hasWindow: Boolean(authWindowRef), isTauri, isCapacitor });
|
|
3704
3711
|
if (authCleanupTimer) {
|
|
3705
3712
|
clearInterval(authCleanupTimer);
|
|
3706
3713
|
authCleanupTimer = null;
|
|
@@ -3744,11 +3751,15 @@ var init_useGoogleAuth = __esm({
|
|
|
3744
3751
|
};
|
|
3745
3752
|
handleCallback = async (url) => {
|
|
3746
3753
|
try {
|
|
3754
|
+
debugAuth("Callback received", { hasUrl: Boolean(url), hasToken: Boolean(url?.includes("token=")) });
|
|
3747
3755
|
await cleanupAuthWindow();
|
|
3748
|
-
if (!url?.includes("token="))
|
|
3756
|
+
if (!url?.includes("token=")) {
|
|
3757
|
+
debugAuthWarn("Callback did not include a token");
|
|
3758
|
+
return;
|
|
3759
|
+
}
|
|
3749
3760
|
const params = new URLSearchParams(url.split("?")[1]);
|
|
3750
3761
|
const token = params.get("token");
|
|
3751
|
-
|
|
3762
|
+
debugAuth("Verifying provider token", { tokenPresent: Boolean(token) });
|
|
3752
3763
|
const res = await fetch(
|
|
3753
3764
|
"https://www.googleapis.com/oauth2/v3/userinfo",
|
|
3754
3765
|
{
|
|
@@ -3758,6 +3769,7 @@ var init_useGoogleAuth = __esm({
|
|
|
3758
3769
|
}
|
|
3759
3770
|
);
|
|
3760
3771
|
const googleUser = await res.json();
|
|
3772
|
+
debugAuth("Provider profile received", { idPresent: Boolean(googleUser.sub), emailPresent: Boolean(googleUser.email) });
|
|
3761
3773
|
const profile = {
|
|
3762
3774
|
id: googleUser.sub,
|
|
3763
3775
|
firstName: googleUser.given_name,
|
|
@@ -3771,19 +3783,26 @@ var init_useGoogleAuth = __esm({
|
|
|
3771
3783
|
localStorage.setItem("idToken", token);
|
|
3772
3784
|
emitGoogleLogin(profile, null);
|
|
3773
3785
|
} catch (err) {
|
|
3786
|
+
debugAuthError("Callback failed", err);
|
|
3774
3787
|
emitGoogleLogin(null, err);
|
|
3775
3788
|
}
|
|
3776
3789
|
};
|
|
3777
3790
|
initializeGoogleLogin = async () => {
|
|
3778
|
-
if (googleInitialized)
|
|
3791
|
+
if (googleInitialized) {
|
|
3792
|
+
debugAuth("Already initialized");
|
|
3793
|
+
return;
|
|
3794
|
+
}
|
|
3779
3795
|
googleInitialized = true;
|
|
3796
|
+
debugAuth("Initializing listeners", { isCapacitor, isTauri });
|
|
3780
3797
|
if (isCapacitor) {
|
|
3798
|
+
debugAuth("Registering Capacitor appUrlOpen listener");
|
|
3781
3799
|
const { App } = await getCapacitorPlugins();
|
|
3782
3800
|
App.addListener("appUrlOpen", (event) => {
|
|
3783
3801
|
handleCallback(event.url);
|
|
3784
3802
|
});
|
|
3785
3803
|
}
|
|
3786
3804
|
if (isTauri) {
|
|
3805
|
+
debugAuth("Registering Tauri deep-link listener");
|
|
3787
3806
|
const { listen: listen2 } = await Promise.resolve().then(() => (init_event(), event_exports));
|
|
3788
3807
|
await listen2("deep-link://open-url", async (event) => {
|
|
3789
3808
|
let url = event.payload;
|
|
@@ -3800,16 +3819,17 @@ var init_useGoogleAuth = __esm({
|
|
|
3800
3819
|
appName = "Tevroc",
|
|
3801
3820
|
serviceUrl = "https://tevrocsoftapi.netlify.app"
|
|
3802
3821
|
} = {}) => {
|
|
3803
|
-
|
|
3804
|
-
debugLog(isCapacitor, isTauri);
|
|
3822
|
+
debugAuth("Creating login", { appId, appName, serviceUrl, isCapacitor, isTauri });
|
|
3805
3823
|
await initializeGoogleLogin();
|
|
3806
3824
|
let authUrl = `${serviceUrl}/auth/google/login?mode=mobile&app=${encodeURIComponent(appId)}&name=${encodeURIComponent(appName)}`;
|
|
3807
3825
|
if (isCapacitor) {
|
|
3826
|
+
debugAuth("Opening mobile auth browser");
|
|
3808
3827
|
const { Browser } = await getCapacitorPlugins();
|
|
3809
3828
|
await Browser.open({ url: authUrl });
|
|
3810
3829
|
return;
|
|
3811
3830
|
}
|
|
3812
3831
|
if (isTauri) {
|
|
3832
|
+
debugAuth("Opening desktop auth window");
|
|
3813
3833
|
const WebviewWindow2 = await getTauriWebviewWindow();
|
|
3814
3834
|
await closeAllTauriWebviews();
|
|
3815
3835
|
const url = `${serviceUrl}/auth/google/login?mode=desktop&app=${encodeURIComponent(appId)}&name=${encodeURIComponent(appName)}`;
|
|
@@ -3823,10 +3843,10 @@ var init_useGoogleAuth = __esm({
|
|
|
3823
3843
|
});
|
|
3824
3844
|
authWindowRef = win;
|
|
3825
3845
|
win.once("tauri://created", () => {
|
|
3826
|
-
|
|
3846
|
+
debugAuth("Auth window opened");
|
|
3827
3847
|
});
|
|
3828
3848
|
win.once("tauri://error", (e) => {
|
|
3829
|
-
|
|
3849
|
+
debugAuthError("Auth window error", e);
|
|
3830
3850
|
});
|
|
3831
3851
|
return;
|
|
3832
3852
|
}
|
|
@@ -3837,19 +3857,21 @@ var init_useGoogleAuth = __esm({
|
|
|
3837
3857
|
detectedAppId
|
|
3838
3858
|
)}&name=${encodeURIComponent(appName)}`;
|
|
3839
3859
|
if (isLocalhost) {
|
|
3860
|
+
debugAuth("Opening web auth popup", { mode, appId: detectedAppId });
|
|
3840
3861
|
const popup = window.open(
|
|
3841
3862
|
finalUrl,
|
|
3842
3863
|
"googleLogin",
|
|
3843
3864
|
"width=500,height=650"
|
|
3844
3865
|
);
|
|
3845
3866
|
if (!popup) {
|
|
3846
|
-
|
|
3867
|
+
debugAuthError("Popup blocked");
|
|
3847
3868
|
}
|
|
3848
3869
|
authWindowRef = popup;
|
|
3849
3870
|
authMessageListener = async (event) => {
|
|
3850
3871
|
const serviceOrigin = new URL(serviceUrl).origin;
|
|
3851
3872
|
if (event.origin !== serviceOrigin) return;
|
|
3852
3873
|
if (event.data?.type === "google-auth") {
|
|
3874
|
+
debugAuth("Received popup auth message", { origin: event.origin });
|
|
3853
3875
|
const token = event.data?.token || null;
|
|
3854
3876
|
const url = token ? `${window.location.href}${window.location.href.includes("?") ? "&" : "?"}token=${token}` : window.location.href;
|
|
3855
3877
|
await handleCallback(url);
|
|
@@ -3868,6 +3890,521 @@ var init_useGoogleAuth = __esm({
|
|
|
3868
3890
|
}
|
|
3869
3891
|
});
|
|
3870
3892
|
|
|
3893
|
+
// src/services/useFacebookAuth.js
|
|
3894
|
+
var useFacebookAuth_exports = {};
|
|
3895
|
+
__export(useFacebookAuth_exports, {
|
|
3896
|
+
createFacebookLogin: () => createFacebookLogin,
|
|
3897
|
+
initializeFacebookLogin: () => initializeFacebookLogin,
|
|
3898
|
+
subscribeFacebookLogin: () => subscribeFacebookLogin
|
|
3899
|
+
});
|
|
3900
|
+
function emitFacebookLogin(user, err = null) {
|
|
3901
|
+
debugAuth2("Emitting login result", { success: Boolean(user), error: err?.message || null });
|
|
3902
|
+
facebookListeners.forEach((cb) => {
|
|
3903
|
+
try {
|
|
3904
|
+
cb(user, err);
|
|
3905
|
+
} catch (e) {
|
|
3906
|
+
debugError("Facebook listener error:", e);
|
|
3907
|
+
}
|
|
3908
|
+
});
|
|
3909
|
+
}
|
|
3910
|
+
function subscribeFacebookLogin(cb) {
|
|
3911
|
+
debugAuth2("Listener subscribed", { count: facebookListeners.length + 1 });
|
|
3912
|
+
facebookListeners.push(cb);
|
|
3913
|
+
return () => {
|
|
3914
|
+
const i = facebookListeners.indexOf(cb);
|
|
3915
|
+
if (i !== -1) facebookListeners.splice(i, 1);
|
|
3916
|
+
debugAuth2("Listener unsubscribed", { count: facebookListeners.length });
|
|
3917
|
+
};
|
|
3918
|
+
}
|
|
3919
|
+
var capacitorPluginsPromise2, tauriWebviewWindowPromise2, getCapacitorPlugins2, debugAuth2, debugAuthWarn2, debugAuthError2, getTauriWebviewWindow2, facebookInitialized, facebookListeners, authWindowRef2, authCleanupTimer2, authMessageListener2, closeAllTauriWebviews2, cleanupAuthWindow2, handleCallback2, initializeFacebookLogin, createFacebookLogin;
|
|
3920
|
+
var init_useFacebookAuth = __esm({
|
|
3921
|
+
"src/services/useFacebookAuth.js"() {
|
|
3922
|
+
init_usePlatform();
|
|
3923
|
+
init_debug();
|
|
3924
|
+
getCapacitorPlugins2 = () => {
|
|
3925
|
+
capacitorPluginsPromise2 ??= Promise.all([Promise.resolve().then(() => __toESM(require_plugin_cjs(), 1)), Promise.resolve().then(() => __toESM(require_plugin_cjs2(), 1))]).then(([appModule, browserModule]) => ({ App: appModule.App, Browser: browserModule.Browser }));
|
|
3926
|
+
return capacitorPluginsPromise2;
|
|
3927
|
+
};
|
|
3928
|
+
debugAuth2 = (...args) => debugLog("[tevrocsdk][facebook-auth]", ...args);
|
|
3929
|
+
debugAuthWarn2 = (...args) => debugWarn("[tevrocsdk][facebook-auth]", ...args);
|
|
3930
|
+
debugAuthError2 = (...args) => debugError("[tevrocsdk][facebook-auth]", ...args);
|
|
3931
|
+
getTauriWebviewWindow2 = async () => {
|
|
3932
|
+
tauriWebviewWindowPromise2 ??= Promise.resolve().then(() => (init_webviewWindow(), webviewWindow_exports)).then((module2) => module2.WebviewWindow);
|
|
3933
|
+
return tauriWebviewWindowPromise2;
|
|
3934
|
+
};
|
|
3935
|
+
facebookInitialized = false;
|
|
3936
|
+
facebookListeners = [];
|
|
3937
|
+
authWindowRef2 = null;
|
|
3938
|
+
authCleanupTimer2 = null;
|
|
3939
|
+
authMessageListener2 = null;
|
|
3940
|
+
closeAllTauriWebviews2 = async () => {
|
|
3941
|
+
if (!isTauri) return;
|
|
3942
|
+
const WebviewWindow2 = await getTauriWebviewWindow2();
|
|
3943
|
+
try {
|
|
3944
|
+
if (typeof WebviewWindow2.getAll === "function") {
|
|
3945
|
+
const windows = await WebviewWindow2.getAll();
|
|
3946
|
+
for (const webview of windows || []) {
|
|
3947
|
+
try {
|
|
3948
|
+
if (webview?.label && webview.label !== "main") {
|
|
3949
|
+
await webview.close();
|
|
3950
|
+
}
|
|
3951
|
+
} catch (e) {
|
|
3952
|
+
debugWarn("Error closing Tauri webview:", e);
|
|
3953
|
+
}
|
|
3954
|
+
}
|
|
3955
|
+
}
|
|
3956
|
+
} catch (e) {
|
|
3957
|
+
debugWarn("Error listing Tauri webviews:", e);
|
|
3958
|
+
}
|
|
3959
|
+
try {
|
|
3960
|
+
const tauriAuthWindow = await WebviewWindow2.getByLabel("auth");
|
|
3961
|
+
if (tauriAuthWindow) {
|
|
3962
|
+
await tauriAuthWindow.close();
|
|
3963
|
+
}
|
|
3964
|
+
} catch (e) {
|
|
3965
|
+
debugWarn("Error closing Tauri auth window by label:", e);
|
|
3966
|
+
}
|
|
3967
|
+
};
|
|
3968
|
+
cleanupAuthWindow2 = async () => {
|
|
3969
|
+
debugAuth2("Cleaning up auth window", { hasWindow: Boolean(authWindowRef2), isTauri, isCapacitor });
|
|
3970
|
+
if (authCleanupTimer2) {
|
|
3971
|
+
clearInterval(authCleanupTimer2);
|
|
3972
|
+
authCleanupTimer2 = null;
|
|
3973
|
+
}
|
|
3974
|
+
if (authMessageListener2 && typeof window !== "undefined") {
|
|
3975
|
+
window.removeEventListener("message", authMessageListener2);
|
|
3976
|
+
authMessageListener2 = null;
|
|
3977
|
+
}
|
|
3978
|
+
if (authWindowRef2) {
|
|
3979
|
+
const currentAuthWindow = authWindowRef2;
|
|
3980
|
+
authWindowRef2 = null;
|
|
3981
|
+
try {
|
|
3982
|
+
if (typeof currentAuthWindow?.close === "function") {
|
|
3983
|
+
await currentAuthWindow.close();
|
|
3984
|
+
}
|
|
3985
|
+
} catch (e) {
|
|
3986
|
+
debugWarn("Error closing auth window:", e);
|
|
3987
|
+
}
|
|
3988
|
+
}
|
|
3989
|
+
if (isTauri) {
|
|
3990
|
+
const WebviewWindow2 = await getTauriWebviewWindow2();
|
|
3991
|
+
await closeAllTauriWebviews2();
|
|
3992
|
+
}
|
|
3993
|
+
if (isCapacitor) {
|
|
3994
|
+
try {
|
|
3995
|
+
const { Browser } = await getCapacitorPlugins2();
|
|
3996
|
+
await Browser.close();
|
|
3997
|
+
} catch (e) {
|
|
3998
|
+
debugWarn("Error closing Capacitor browser:", e);
|
|
3999
|
+
}
|
|
4000
|
+
}
|
|
4001
|
+
if (typeof window !== "undefined" && window !== window.parent) {
|
|
4002
|
+
try {
|
|
4003
|
+
if (authWindowRef2 && typeof authWindowRef2.close === "function") {
|
|
4004
|
+
await authWindowRef2.close();
|
|
4005
|
+
}
|
|
4006
|
+
} catch (e) {
|
|
4007
|
+
debugWarn("Error closing popup fallback:", e);
|
|
4008
|
+
}
|
|
4009
|
+
}
|
|
4010
|
+
};
|
|
4011
|
+
handleCallback2 = async (url) => {
|
|
4012
|
+
try {
|
|
4013
|
+
debugAuth2("Callback received", { hasUrl: Boolean(url), hasToken: Boolean(url?.includes("token=")) });
|
|
4014
|
+
await cleanupAuthWindow2();
|
|
4015
|
+
if (!url?.includes("token=")) {
|
|
4016
|
+
debugAuthWarn2("Callback did not include a token");
|
|
4017
|
+
return;
|
|
4018
|
+
}
|
|
4019
|
+
const params = new URLSearchParams(url.split("?")[1]);
|
|
4020
|
+
const token = params.get("token");
|
|
4021
|
+
debugAuth2("Verifying provider token", { tokenPresent: Boolean(token) });
|
|
4022
|
+
const res = await fetch(
|
|
4023
|
+
`https://graph.facebook.com/me?fields=id,first_name,last_name,email,picture&access_token=${encodeURIComponent(token)}`
|
|
4024
|
+
);
|
|
4025
|
+
if (!res.ok) {
|
|
4026
|
+
throw new Error(`Facebook profile request failed: ${res.status}`);
|
|
4027
|
+
}
|
|
4028
|
+
const facebookUser = await res.json();
|
|
4029
|
+
debugAuth2("Provider profile received", { idPresent: Boolean(facebookUser.id), emailPresent: Boolean(facebookUser.email) });
|
|
4030
|
+
const profile = {
|
|
4031
|
+
id: facebookUser.id,
|
|
4032
|
+
firstName: facebookUser.first_name,
|
|
4033
|
+
lastName: facebookUser.last_name,
|
|
4034
|
+
email: facebookUser.email,
|
|
4035
|
+
photo: facebookUser.picture?.data?.url,
|
|
4036
|
+
accessToken: token
|
|
4037
|
+
};
|
|
4038
|
+
debugLog("Facebook user profile:", profile);
|
|
4039
|
+
localStorage.setItem("user", JSON.stringify(profile));
|
|
4040
|
+
localStorage.setItem("idToken", token);
|
|
4041
|
+
emitFacebookLogin(profile, null);
|
|
4042
|
+
} catch (err) {
|
|
4043
|
+
debugAuthError2("Callback failed", err);
|
|
4044
|
+
emitFacebookLogin(null, err);
|
|
4045
|
+
}
|
|
4046
|
+
};
|
|
4047
|
+
initializeFacebookLogin = async () => {
|
|
4048
|
+
if (facebookInitialized) {
|
|
4049
|
+
debugAuth2("Already initialized");
|
|
4050
|
+
return;
|
|
4051
|
+
}
|
|
4052
|
+
facebookInitialized = true;
|
|
4053
|
+
debugAuth2("Initializing listeners", { isCapacitor, isTauri });
|
|
4054
|
+
if (isCapacitor) {
|
|
4055
|
+
debugAuth2("Registering Capacitor appUrlOpen listener");
|
|
4056
|
+
const { App } = await getCapacitorPlugins2();
|
|
4057
|
+
App.addListener("appUrlOpen", (event) => {
|
|
4058
|
+
handleCallback2(event.url);
|
|
4059
|
+
});
|
|
4060
|
+
}
|
|
4061
|
+
if (isTauri) {
|
|
4062
|
+
debugAuth2("Registering Tauri deep-link listener");
|
|
4063
|
+
const { listen: listen2 } = await Promise.resolve().then(() => (init_event(), event_exports));
|
|
4064
|
+
await listen2("deep-link://open-url", async (event) => {
|
|
4065
|
+
let url = event.payload;
|
|
4066
|
+
if (typeof url === "object") {
|
|
4067
|
+
url = url?.url || url?.payload || null;
|
|
4068
|
+
}
|
|
4069
|
+
if (!url) return;
|
|
4070
|
+
await handleCallback2(url);
|
|
4071
|
+
});
|
|
4072
|
+
}
|
|
4073
|
+
};
|
|
4074
|
+
createFacebookLogin = async ({
|
|
4075
|
+
appId = "tevrocsoft",
|
|
4076
|
+
appName = "Tevroc",
|
|
4077
|
+
serviceUrl = "https://tevrocsoftapi.netlify.app"
|
|
4078
|
+
} = {}) => {
|
|
4079
|
+
debugAuth2("Creating login", { appId, appName, serviceUrl, isCapacitor, isTauri });
|
|
4080
|
+
await initializeFacebookLogin();
|
|
4081
|
+
let authUrl = `${serviceUrl}/auth/facebook/login?mode=mobile&app=${encodeURIComponent(appId)}&name=${encodeURIComponent(appName)}`;
|
|
4082
|
+
if (isCapacitor) {
|
|
4083
|
+
debugAuth2("Opening mobile auth browser");
|
|
4084
|
+
const { Browser } = await getCapacitorPlugins2();
|
|
4085
|
+
await Browser.open({ url: authUrl });
|
|
4086
|
+
return;
|
|
4087
|
+
}
|
|
4088
|
+
if (isTauri) {
|
|
4089
|
+
debugAuth2("Opening desktop auth window");
|
|
4090
|
+
const WebviewWindow2 = await getTauriWebviewWindow2();
|
|
4091
|
+
await closeAllTauriWebviews2();
|
|
4092
|
+
const url = `${serviceUrl}/auth/facebook/login?mode=desktop&app=${encodeURIComponent(appId)}&name=${encodeURIComponent(appName)}`;
|
|
4093
|
+
const win = new WebviewWindow2("auth", {
|
|
4094
|
+
url,
|
|
4095
|
+
title: `${appName} Login`,
|
|
4096
|
+
width: 550,
|
|
4097
|
+
height: 500,
|
|
4098
|
+
resizable: true,
|
|
4099
|
+
center: true
|
|
4100
|
+
});
|
|
4101
|
+
authWindowRef2 = win;
|
|
4102
|
+
win.once("tauri://created", () => {
|
|
4103
|
+
debugAuth2("Auth window opened");
|
|
4104
|
+
});
|
|
4105
|
+
win.once("tauri://error", (e) => {
|
|
4106
|
+
debugAuthError2("Auth window error", e);
|
|
4107
|
+
});
|
|
4108
|
+
return;
|
|
4109
|
+
}
|
|
4110
|
+
const isLocalhost = true;
|
|
4111
|
+
const detectedAppId = typeof window !== "undefined" ? window.location.host : appId;
|
|
4112
|
+
const mode = isLocalhost ? "localhost" : "netlify";
|
|
4113
|
+
const finalUrl = `${serviceUrl}/auth/facebook/login?mode=${mode}&app=${encodeURIComponent(
|
|
4114
|
+
detectedAppId
|
|
4115
|
+
)}&name=${encodeURIComponent(appName)}`;
|
|
4116
|
+
if (isLocalhost) {
|
|
4117
|
+
debugAuth2("Opening web auth popup", { mode, appId: detectedAppId });
|
|
4118
|
+
const popup = window.open(
|
|
4119
|
+
finalUrl,
|
|
4120
|
+
"facebookLogin",
|
|
4121
|
+
"width=500,height=650"
|
|
4122
|
+
);
|
|
4123
|
+
if (!popup) {
|
|
4124
|
+
debugAuthError2("Popup blocked");
|
|
4125
|
+
throw new Error("Facebook sign-in popup was blocked. Allow popups and try again.");
|
|
4126
|
+
}
|
|
4127
|
+
authWindowRef2 = popup;
|
|
4128
|
+
authMessageListener2 = async (event) => {
|
|
4129
|
+
const serviceOrigin = new URL(serviceUrl).origin;
|
|
4130
|
+
if (event.origin !== serviceOrigin) return;
|
|
4131
|
+
if (event.data?.type === "facebook-auth") {
|
|
4132
|
+
debugAuth2("Received popup auth message", { origin: event.origin });
|
|
4133
|
+
const token = event.data?.token || null;
|
|
4134
|
+
const url = token ? `${window.location.href}${window.location.href.includes("?") ? "&" : "?"}token=${token}` : window.location.href;
|
|
4135
|
+
await handleCallback2(url);
|
|
4136
|
+
}
|
|
4137
|
+
};
|
|
4138
|
+
window.addEventListener("message", authMessageListener2);
|
|
4139
|
+
authCleanupTimer2 = setInterval(() => {
|
|
4140
|
+
if (popup.closed) {
|
|
4141
|
+
cleanupAuthWindow2().catch(() => {
|
|
4142
|
+
});
|
|
4143
|
+
}
|
|
4144
|
+
}, 500);
|
|
4145
|
+
return;
|
|
4146
|
+
}
|
|
4147
|
+
};
|
|
4148
|
+
}
|
|
4149
|
+
});
|
|
4150
|
+
|
|
4151
|
+
// src/services/useMetaAuth.js
|
|
4152
|
+
var useMetaAuth_exports = {};
|
|
4153
|
+
__export(useMetaAuth_exports, {
|
|
4154
|
+
createMetaLogin: () => createMetaLogin,
|
|
4155
|
+
initializeMetaLogin: () => initializeMetaLogin,
|
|
4156
|
+
subscribeMetaLogin: () => subscribeMetaLogin
|
|
4157
|
+
});
|
|
4158
|
+
function emitMetaLogin(user, err = null) {
|
|
4159
|
+
debugAuth3("Emitting login result", { success: Boolean(user), error: err?.message || null });
|
|
4160
|
+
metaListeners.forEach((cb) => {
|
|
4161
|
+
try {
|
|
4162
|
+
cb(user, err);
|
|
4163
|
+
} catch (e) {
|
|
4164
|
+
debugError("Meta listener error:", e);
|
|
4165
|
+
}
|
|
4166
|
+
});
|
|
4167
|
+
}
|
|
4168
|
+
function subscribeMetaLogin(cb) {
|
|
4169
|
+
debugAuth3("Listener subscribed", { count: metaListeners.length + 1 });
|
|
4170
|
+
metaListeners.push(cb);
|
|
4171
|
+
return () => {
|
|
4172
|
+
const i = metaListeners.indexOf(cb);
|
|
4173
|
+
if (i !== -1) metaListeners.splice(i, 1);
|
|
4174
|
+
debugAuth3("Listener unsubscribed", { count: metaListeners.length });
|
|
4175
|
+
};
|
|
4176
|
+
}
|
|
4177
|
+
var capacitorPluginsPromise3, tauriWebviewWindowPromise3, getCapacitorPlugins3, debugAuth3, debugAuthWarn3, debugAuthError3, getTauriWebviewWindow3, metaInitialized, metaListeners, authWindowRef3, authCleanupTimer3, authMessageListener3, closeAllTauriWebviews3, cleanupAuthWindow3, handleCallback3, initializeMetaLogin, createMetaLogin;
|
|
4178
|
+
var init_useMetaAuth = __esm({
|
|
4179
|
+
"src/services/useMetaAuth.js"() {
|
|
4180
|
+
init_usePlatform();
|
|
4181
|
+
init_debug();
|
|
4182
|
+
getCapacitorPlugins3 = () => {
|
|
4183
|
+
capacitorPluginsPromise3 ??= Promise.all([Promise.resolve().then(() => __toESM(require_plugin_cjs(), 1)), Promise.resolve().then(() => __toESM(require_plugin_cjs2(), 1))]).then(([appModule, browserModule]) => ({ App: appModule.App, Browser: browserModule.Browser }));
|
|
4184
|
+
return capacitorPluginsPromise3;
|
|
4185
|
+
};
|
|
4186
|
+
debugAuth3 = (...args) => debugLog("[tevrocsdk][meta-auth]", ...args);
|
|
4187
|
+
debugAuthWarn3 = (...args) => debugWarn("[tevrocsdk][meta-auth]", ...args);
|
|
4188
|
+
debugAuthError3 = (...args) => debugError("[tevrocsdk][meta-auth]", ...args);
|
|
4189
|
+
getTauriWebviewWindow3 = async () => {
|
|
4190
|
+
tauriWebviewWindowPromise3 ??= Promise.resolve().then(() => (init_webviewWindow(), webviewWindow_exports)).then((module2) => module2.WebviewWindow);
|
|
4191
|
+
return tauriWebviewWindowPromise3;
|
|
4192
|
+
};
|
|
4193
|
+
metaInitialized = false;
|
|
4194
|
+
metaListeners = [];
|
|
4195
|
+
authWindowRef3 = null;
|
|
4196
|
+
authCleanupTimer3 = null;
|
|
4197
|
+
authMessageListener3 = null;
|
|
4198
|
+
closeAllTauriWebviews3 = async () => {
|
|
4199
|
+
if (!isTauri) return;
|
|
4200
|
+
const WebviewWindow2 = await getTauriWebviewWindow3();
|
|
4201
|
+
try {
|
|
4202
|
+
if (typeof WebviewWindow2.getAll === "function") {
|
|
4203
|
+
const windows = await WebviewWindow2.getAll();
|
|
4204
|
+
for (const webview of windows || []) {
|
|
4205
|
+
try {
|
|
4206
|
+
if (webview?.label && webview.label !== "main") {
|
|
4207
|
+
await webview.close();
|
|
4208
|
+
}
|
|
4209
|
+
} catch (e) {
|
|
4210
|
+
debugWarn("Error closing Tauri webview:", e);
|
|
4211
|
+
}
|
|
4212
|
+
}
|
|
4213
|
+
}
|
|
4214
|
+
} catch (e) {
|
|
4215
|
+
debugWarn("Error listing Tauri webviews:", e);
|
|
4216
|
+
}
|
|
4217
|
+
try {
|
|
4218
|
+
const tauriAuthWindow = await WebviewWindow2.getByLabel("auth");
|
|
4219
|
+
if (tauriAuthWindow) {
|
|
4220
|
+
await tauriAuthWindow.close();
|
|
4221
|
+
}
|
|
4222
|
+
} catch (e) {
|
|
4223
|
+
debugWarn("Error closing Tauri auth window by label:", e);
|
|
4224
|
+
}
|
|
4225
|
+
};
|
|
4226
|
+
cleanupAuthWindow3 = async () => {
|
|
4227
|
+
debugAuth3("Cleaning up auth window", { hasWindow: Boolean(authWindowRef3), isTauri, isCapacitor });
|
|
4228
|
+
if (authCleanupTimer3) {
|
|
4229
|
+
clearInterval(authCleanupTimer3);
|
|
4230
|
+
authCleanupTimer3 = null;
|
|
4231
|
+
}
|
|
4232
|
+
if (authMessageListener3 && typeof window !== "undefined") {
|
|
4233
|
+
window.removeEventListener("message", authMessageListener3);
|
|
4234
|
+
authMessageListener3 = null;
|
|
4235
|
+
}
|
|
4236
|
+
if (authWindowRef3) {
|
|
4237
|
+
const currentAuthWindow = authWindowRef3;
|
|
4238
|
+
authWindowRef3 = null;
|
|
4239
|
+
try {
|
|
4240
|
+
if (typeof currentAuthWindow?.close === "function") {
|
|
4241
|
+
await currentAuthWindow.close();
|
|
4242
|
+
}
|
|
4243
|
+
} catch (e) {
|
|
4244
|
+
debugWarn("Error closing auth window:", e);
|
|
4245
|
+
}
|
|
4246
|
+
}
|
|
4247
|
+
if (isTauri) {
|
|
4248
|
+
const WebviewWindow2 = await getTauriWebviewWindow3();
|
|
4249
|
+
await closeAllTauriWebviews3();
|
|
4250
|
+
}
|
|
4251
|
+
if (isCapacitor) {
|
|
4252
|
+
try {
|
|
4253
|
+
const { Browser } = await getCapacitorPlugins3();
|
|
4254
|
+
await Browser.close();
|
|
4255
|
+
} catch (e) {
|
|
4256
|
+
debugWarn("Error closing Capacitor browser:", e);
|
|
4257
|
+
}
|
|
4258
|
+
}
|
|
4259
|
+
if (typeof window !== "undefined" && window !== window.parent) {
|
|
4260
|
+
try {
|
|
4261
|
+
if (authWindowRef3 && typeof authWindowRef3.close === "function") {
|
|
4262
|
+
await authWindowRef3.close();
|
|
4263
|
+
}
|
|
4264
|
+
} catch (e) {
|
|
4265
|
+
debugWarn("Error closing popup fallback:", e);
|
|
4266
|
+
}
|
|
4267
|
+
}
|
|
4268
|
+
};
|
|
4269
|
+
handleCallback3 = async (url) => {
|
|
4270
|
+
try {
|
|
4271
|
+
debugAuth3("Callback received", { hasUrl: Boolean(url), hasToken: Boolean(url?.includes("token=")) });
|
|
4272
|
+
await cleanupAuthWindow3();
|
|
4273
|
+
if (!url?.includes("token=")) {
|
|
4274
|
+
debugAuthWarn3("Callback did not include a token");
|
|
4275
|
+
return;
|
|
4276
|
+
}
|
|
4277
|
+
const params = new URLSearchParams(url.split("?")[1]);
|
|
4278
|
+
const token = params.get("token");
|
|
4279
|
+
debugAuth3("Verifying provider token", { tokenPresent: Boolean(token) });
|
|
4280
|
+
const res = await fetch(
|
|
4281
|
+
`https://graph.facebook.com/me?fields=id,name,first_name,last_name,email,picture&access_token=${encodeURIComponent(token)}`
|
|
4282
|
+
);
|
|
4283
|
+
if (!res.ok) throw new Error(`Meta profile request failed: ${res.status}`);
|
|
4284
|
+
const metaUser = await res.json();
|
|
4285
|
+
debugAuth3("Provider profile received", { idPresent: Boolean(metaUser.id), emailPresent: Boolean(metaUser.email) });
|
|
4286
|
+
const profile = {
|
|
4287
|
+
id: metaUser.id,
|
|
4288
|
+
name: metaUser.name,
|
|
4289
|
+
firstName: metaUser.first_name,
|
|
4290
|
+
lastName: metaUser.last_name,
|
|
4291
|
+
email: metaUser.email,
|
|
4292
|
+
photo: metaUser.picture?.data?.url,
|
|
4293
|
+
accessToken: token
|
|
4294
|
+
};
|
|
4295
|
+
debugLog("Meta user profile:", profile);
|
|
4296
|
+
localStorage.setItem("user", JSON.stringify(profile));
|
|
4297
|
+
localStorage.setItem("idToken", token);
|
|
4298
|
+
emitMetaLogin(profile, null);
|
|
4299
|
+
} catch (err) {
|
|
4300
|
+
debugAuthError3("Callback failed", err);
|
|
4301
|
+
emitMetaLogin(null, err);
|
|
4302
|
+
}
|
|
4303
|
+
};
|
|
4304
|
+
initializeMetaLogin = async () => {
|
|
4305
|
+
if (metaInitialized) {
|
|
4306
|
+
debugAuth3("Already initialized");
|
|
4307
|
+
return;
|
|
4308
|
+
}
|
|
4309
|
+
metaInitialized = true;
|
|
4310
|
+
debugAuth3("Initializing listeners", { isCapacitor, isTauri });
|
|
4311
|
+
if (isCapacitor) {
|
|
4312
|
+
debugAuth3("Registering Capacitor appUrlOpen listener");
|
|
4313
|
+
const { App } = await getCapacitorPlugins3();
|
|
4314
|
+
App.addListener("appUrlOpen", (event) => {
|
|
4315
|
+
handleCallback3(event.url);
|
|
4316
|
+
});
|
|
4317
|
+
}
|
|
4318
|
+
if (isTauri) {
|
|
4319
|
+
debugAuth3("Registering Tauri deep-link listener");
|
|
4320
|
+
const { listen: listen2 } = await Promise.resolve().then(() => (init_event(), event_exports));
|
|
4321
|
+
await listen2("deep-link://open-url", async (event) => {
|
|
4322
|
+
let url = event.payload;
|
|
4323
|
+
if (typeof url === "object") {
|
|
4324
|
+
url = url?.url || url?.payload || null;
|
|
4325
|
+
}
|
|
4326
|
+
if (!url) return;
|
|
4327
|
+
await handleCallback3(url);
|
|
4328
|
+
});
|
|
4329
|
+
}
|
|
4330
|
+
};
|
|
4331
|
+
createMetaLogin = async ({
|
|
4332
|
+
appId = "tevrocsoft",
|
|
4333
|
+
appName = "Tevroc",
|
|
4334
|
+
serviceUrl = "https://tevrocsoftapi.netlify.app"
|
|
4335
|
+
} = {}) => {
|
|
4336
|
+
debugAuth3("Creating login", { appId, appName, serviceUrl, isCapacitor, isTauri });
|
|
4337
|
+
await initializeMetaLogin();
|
|
4338
|
+
const authUrl = `${serviceUrl}/auth/meta/login?mode=mobile&app=${encodeURIComponent(appId)}&name=${encodeURIComponent(appName)}`;
|
|
4339
|
+
if (isCapacitor) {
|
|
4340
|
+
debugAuth3("Opening mobile auth browser");
|
|
4341
|
+
const { Browser } = await getCapacitorPlugins3();
|
|
4342
|
+
await Browser.open({ url: authUrl });
|
|
4343
|
+
return;
|
|
4344
|
+
}
|
|
4345
|
+
if (isTauri) {
|
|
4346
|
+
debugAuth3("Opening desktop auth window");
|
|
4347
|
+
const WebviewWindow2 = await getTauriWebviewWindow3();
|
|
4348
|
+
await closeAllTauriWebviews3();
|
|
4349
|
+
const url = `${serviceUrl}/auth/meta/login?mode=desktop&app=${encodeURIComponent(appId)}&name=${encodeURIComponent(appName)}`;
|
|
4350
|
+
const win = new WebviewWindow2("auth", {
|
|
4351
|
+
url,
|
|
4352
|
+
title: `${appName} Login`,
|
|
4353
|
+
width: 550,
|
|
4354
|
+
height: 500,
|
|
4355
|
+
resizable: true,
|
|
4356
|
+
center: true
|
|
4357
|
+
});
|
|
4358
|
+
authWindowRef3 = win;
|
|
4359
|
+
win.once("tauri://created", () => {
|
|
4360
|
+
debugAuth3("Auth window opened");
|
|
4361
|
+
});
|
|
4362
|
+
win.once("tauri://error", (e) => {
|
|
4363
|
+
debugAuthError3("Auth window error", e);
|
|
4364
|
+
});
|
|
4365
|
+
return;
|
|
4366
|
+
}
|
|
4367
|
+
const isLocalhost = true;
|
|
4368
|
+
const detectedAppId = typeof window !== "undefined" ? window.location.host : appId;
|
|
4369
|
+
const mode = isLocalhost ? "localhost" : "netlify";
|
|
4370
|
+
const finalUrl = `${serviceUrl}/auth/meta/login?mode=${mode}&app=${encodeURIComponent(
|
|
4371
|
+
detectedAppId
|
|
4372
|
+
)}&name=${encodeURIComponent(appName)}`;
|
|
4373
|
+
if (isLocalhost) {
|
|
4374
|
+
debugAuth3("Opening web auth popup", { mode, appId: detectedAppId });
|
|
4375
|
+
const popup = window.open(
|
|
4376
|
+
finalUrl,
|
|
4377
|
+
"metaLogin",
|
|
4378
|
+
"width=500,height=650"
|
|
4379
|
+
);
|
|
4380
|
+
if (!popup) {
|
|
4381
|
+
debugAuthError3("Popup blocked");
|
|
4382
|
+
throw new Error("Meta sign-in popup was blocked. Allow popups and try again.");
|
|
4383
|
+
}
|
|
4384
|
+
authWindowRef3 = popup;
|
|
4385
|
+
authMessageListener3 = async (event) => {
|
|
4386
|
+
const serviceOrigin = new URL(serviceUrl).origin;
|
|
4387
|
+
if (event.origin !== serviceOrigin) return;
|
|
4388
|
+
if (event.data?.type === "meta-auth") {
|
|
4389
|
+
debugAuth3("Received popup auth message", { origin: event.origin });
|
|
4390
|
+
const token = event.data?.token || null;
|
|
4391
|
+
const url = token ? `${window.location.href}${window.location.href.includes("?") ? "&" : "?"}token=${token}` : window.location.href;
|
|
4392
|
+
await handleCallback3(url);
|
|
4393
|
+
}
|
|
4394
|
+
};
|
|
4395
|
+
window.addEventListener("message", authMessageListener3);
|
|
4396
|
+
authCleanupTimer3 = setInterval(() => {
|
|
4397
|
+
if (popup.closed) {
|
|
4398
|
+
cleanupAuthWindow3().catch(() => {
|
|
4399
|
+
});
|
|
4400
|
+
}
|
|
4401
|
+
}, 500);
|
|
4402
|
+
return;
|
|
4403
|
+
}
|
|
4404
|
+
};
|
|
4405
|
+
}
|
|
4406
|
+
});
|
|
4407
|
+
|
|
3871
4408
|
// src/services/useYocoPayment.js
|
|
3872
4409
|
function emitPaymentStatus(status, err = null) {
|
|
3873
4410
|
paymentStatusListeners.forEach((cb) => {
|
|
@@ -3885,18 +4422,18 @@ function subscribePaymentStatus(cb) {
|
|
|
3885
4422
|
if (i !== -1) paymentStatusListeners.splice(i, 1);
|
|
3886
4423
|
};
|
|
3887
4424
|
}
|
|
3888
|
-
var
|
|
4425
|
+
var capacitorPluginsPromise4, tauriWebviewWindowPromise4, getCapacitorPlugins4, getTauriWebviewWindow4, paymentInitialized, paymentStatusListeners, paymentWindowRef, logs, addLog, handlePaymentCallback, initializePayment, createPayment;
|
|
3889
4426
|
var init_useYocoPayment = __esm({
|
|
3890
4427
|
"src/services/useYocoPayment.js"() {
|
|
3891
4428
|
init_usePlatform();
|
|
3892
4429
|
init_debug();
|
|
3893
|
-
|
|
3894
|
-
|
|
3895
|
-
return
|
|
4430
|
+
getCapacitorPlugins4 = () => {
|
|
4431
|
+
capacitorPluginsPromise4 ??= Promise.all([Promise.resolve().then(() => __toESM(require_plugin_cjs(), 1)), Promise.resolve().then(() => __toESM(require_plugin_cjs2(), 1))]).then(([appModule, browserModule]) => ({ App: appModule.App, Browser: browserModule.Browser }));
|
|
4432
|
+
return capacitorPluginsPromise4;
|
|
3896
4433
|
};
|
|
3897
|
-
|
|
3898
|
-
|
|
3899
|
-
return
|
|
4434
|
+
getTauriWebviewWindow4 = async () => {
|
|
4435
|
+
tauriWebviewWindowPromise4 ??= Promise.resolve().then(() => (init_webviewWindow(), webviewWindow_exports)).then((module2) => module2.WebviewWindow);
|
|
4436
|
+
return tauriWebviewWindowPromise4;
|
|
3900
4437
|
};
|
|
3901
4438
|
paymentInitialized = false;
|
|
3902
4439
|
paymentStatusListeners = [];
|
|
@@ -3938,7 +4475,7 @@ var init_useYocoPayment = __esm({
|
|
|
3938
4475
|
if (paymentInitialized) return;
|
|
3939
4476
|
paymentInitialized = true;
|
|
3940
4477
|
if (isCapacitor) {
|
|
3941
|
-
const { App } = await
|
|
4478
|
+
const { App } = await getCapacitorPlugins4();
|
|
3942
4479
|
App.addListener("appUrlOpen", (event) => {
|
|
3943
4480
|
handlePaymentCallback(
|
|
3944
4481
|
event.url,
|
|
@@ -3981,14 +4518,14 @@ var init_useYocoPayment = __esm({
|
|
|
3981
4518
|
const paymentUrl = `${basePaymentUrl}?mode=mobile&amount=${cents}&app=${appId}&account=${payAccount}`;
|
|
3982
4519
|
debugLog(basePaymentUrl, paymentUrl);
|
|
3983
4520
|
if (isCapacitor) {
|
|
3984
|
-
const { Browser } = await
|
|
4521
|
+
const { Browser } = await getCapacitorPlugins4();
|
|
3985
4522
|
await Browser.open({
|
|
3986
4523
|
url: paymentUrl
|
|
3987
4524
|
});
|
|
3988
4525
|
return;
|
|
3989
4526
|
}
|
|
3990
4527
|
if (isTauri) {
|
|
3991
|
-
const WebviewWindow2 = await
|
|
4528
|
+
const WebviewWindow2 = await getTauriWebviewWindow4();
|
|
3992
4529
|
const url = `${basePaymentUrl}?mode=desktop&amount=${cents}&app=${appId}&account=${payAccount}`;
|
|
3993
4530
|
const win = new WebviewWindow2("payment", {
|
|
3994
4531
|
url,
|
|
@@ -8156,13 +8693,13 @@ var require_html2canvas = __commonJS({
|
|
|
8156
8693
|
var textList = toCodePoints$1(node.data).map(function(i2) {
|
|
8157
8694
|
return fromCodePoint$1(i2);
|
|
8158
8695
|
});
|
|
8159
|
-
var
|
|
8696
|
+
var offset2 = 0;
|
|
8160
8697
|
var prev = {};
|
|
8161
8698
|
var supports = textList.every(function(text, i2) {
|
|
8162
|
-
range.setStart(node,
|
|
8163
|
-
range.setEnd(node,
|
|
8699
|
+
range.setStart(node, offset2);
|
|
8700
|
+
range.setEnd(node, offset2 + text.length);
|
|
8164
8701
|
var rect = range.getBoundingClientRect();
|
|
8165
|
-
|
|
8702
|
+
offset2 += text.length;
|
|
8166
8703
|
var boundAhead = rect.x > prev.x || rect.y > prev.y;
|
|
8167
8704
|
prev = rect;
|
|
8168
8705
|
if (i2 === 0) {
|
|
@@ -8311,16 +8848,16 @@ var require_html2canvas = __commonJS({
|
|
|
8311
8848
|
var parseTextBounds = function(context, value, styles, node) {
|
|
8312
8849
|
var textList = breakText(value, styles);
|
|
8313
8850
|
var textBounds = [];
|
|
8314
|
-
var
|
|
8851
|
+
var offset2 = 0;
|
|
8315
8852
|
textList.forEach(function(text) {
|
|
8316
8853
|
if (styles.textDecorationLine.length || text.trim().length > 0) {
|
|
8317
8854
|
if (FEATURES.SUPPORT_RANGE_BOUNDS) {
|
|
8318
|
-
var clientRects = createRange(node,
|
|
8855
|
+
var clientRects = createRange(node, offset2, text.length).getClientRects();
|
|
8319
8856
|
if (clientRects.length > 1) {
|
|
8320
8857
|
var subSegments = segmentGraphemes(text);
|
|
8321
8858
|
var subOffset_1 = 0;
|
|
8322
8859
|
subSegments.forEach(function(subSegment) {
|
|
8323
|
-
textBounds.push(new TextBounds(subSegment, Bounds.fromDOMRectList(context, createRange(node, subOffset_1 +
|
|
8860
|
+
textBounds.push(new TextBounds(subSegment, Bounds.fromDOMRectList(context, createRange(node, subOffset_1 + offset2, subSegment.length).getClientRects())));
|
|
8324
8861
|
subOffset_1 += subSegment.length;
|
|
8325
8862
|
});
|
|
8326
8863
|
} else {
|
|
@@ -8334,7 +8871,7 @@ var require_html2canvas = __commonJS({
|
|
|
8334
8871
|
} else if (!FEATURES.SUPPORT_RANGE_BOUNDS) {
|
|
8335
8872
|
node = node.splitText(text.length);
|
|
8336
8873
|
}
|
|
8337
|
-
|
|
8874
|
+
offset2 += text.length;
|
|
8338
8875
|
});
|
|
8339
8876
|
return textBounds;
|
|
8340
8877
|
};
|
|
@@ -8355,14 +8892,14 @@ var require_html2canvas = __commonJS({
|
|
|
8355
8892
|
}
|
|
8356
8893
|
return Bounds.EMPTY;
|
|
8357
8894
|
};
|
|
8358
|
-
var createRange = function(node,
|
|
8895
|
+
var createRange = function(node, offset2, length) {
|
|
8359
8896
|
var ownerDocument = node.ownerDocument;
|
|
8360
8897
|
if (!ownerDocument) {
|
|
8361
8898
|
throw new Error("Node has no owner document");
|
|
8362
8899
|
}
|
|
8363
8900
|
var range = ownerDocument.createRange();
|
|
8364
|
-
range.setStart(node,
|
|
8365
|
-
range.setEnd(node,
|
|
8901
|
+
range.setStart(node, offset2);
|
|
8902
|
+
range.setEnd(node, offset2 + length);
|
|
8366
8903
|
return range;
|
|
8367
8904
|
};
|
|
8368
8905
|
var segmentGraphemes = function(value) {
|
|
@@ -13125,12 +13662,12 @@ var require_node = __commonJS({
|
|
|
13125
13662
|
}
|
|
13126
13663
|
], this, StrmOpt.call(this, opts, cb), function(ev) {
|
|
13127
13664
|
var strm = new Gunzip(ev.data);
|
|
13128
|
-
strm.onmember = function(
|
|
13129
|
-
return postMessage(
|
|
13665
|
+
strm.onmember = function(offset2) {
|
|
13666
|
+
return postMessage(offset2);
|
|
13130
13667
|
};
|
|
13131
13668
|
onmessage = astrm(strm);
|
|
13132
|
-
}, 9, 0, function(
|
|
13133
|
-
return _this.onmember && _this.onmember(
|
|
13669
|
+
}, 9, 0, function(offset2) {
|
|
13670
|
+
return _this.onmember && _this.onmember(offset2);
|
|
13134
13671
|
});
|
|
13135
13672
|
}
|
|
13136
13673
|
return AsyncGunzip2;
|
|
@@ -14302,12 +14839,12 @@ var require_IOBuffer = __commonJS({
|
|
|
14302
14839
|
dataIsGiven = true;
|
|
14303
14840
|
this.lastWrittenByte = data.byteLength;
|
|
14304
14841
|
}
|
|
14305
|
-
const
|
|
14306
|
-
const byteLength = data.byteLength -
|
|
14307
|
-
let dvOffset =
|
|
14842
|
+
const offset2 = options.offset ? options.offset >>> 0 : 0;
|
|
14843
|
+
const byteLength = data.byteLength - offset2;
|
|
14844
|
+
let dvOffset = offset2;
|
|
14308
14845
|
if (ArrayBuffer.isView(data) || data instanceof _IOBuffer) {
|
|
14309
14846
|
if (data.byteLength !== data.buffer.byteLength) {
|
|
14310
|
-
dvOffset = data.byteOffset +
|
|
14847
|
+
dvOffset = data.byteOffset + offset2;
|
|
14311
14848
|
}
|
|
14312
14849
|
data = data.buffer;
|
|
14313
14850
|
}
|
|
@@ -14389,8 +14926,8 @@ var require_IOBuffer = __commonJS({
|
|
|
14389
14926
|
* @param offset - The offset to move to.
|
|
14390
14927
|
* @returns This.
|
|
14391
14928
|
*/
|
|
14392
|
-
seek(
|
|
14393
|
-
this.offset =
|
|
14929
|
+
seek(offset2) {
|
|
14930
|
+
this.offset = offset2;
|
|
14394
14931
|
return this;
|
|
14395
14932
|
}
|
|
14396
14933
|
/**
|
|
@@ -14427,11 +14964,11 @@ var require_IOBuffer = __commonJS({
|
|
|
14427
14964
|
* @returns This.
|
|
14428
14965
|
*/
|
|
14429
14966
|
popMark() {
|
|
14430
|
-
const
|
|
14431
|
-
if (
|
|
14967
|
+
const offset2 = this._marks.pop();
|
|
14968
|
+
if (offset2 === void 0) {
|
|
14432
14969
|
throw new Error("Mark stack empty");
|
|
14433
14970
|
}
|
|
14434
|
-
this.seek(
|
|
14971
|
+
this.seek(offset2);
|
|
14435
14972
|
return this;
|
|
14436
14973
|
}
|
|
14437
14974
|
/**
|
|
@@ -14509,10 +15046,10 @@ var require_IOBuffer = __commonJS({
|
|
|
14509
15046
|
*/
|
|
14510
15047
|
readArray(size2, type) {
|
|
14511
15048
|
const bytes = typedArrays[type].BYTES_PER_ELEMENT * size2;
|
|
14512
|
-
const
|
|
14513
|
-
const slice = this.buffer.slice(
|
|
15049
|
+
const offset2 = this.byteOffset + this.offset;
|
|
15050
|
+
const slice = this.buffer.slice(offset2, offset2 + bytes);
|
|
14514
15051
|
if (this.littleEndian === hostBigEndian && type !== "uint8" && type !== "int8") {
|
|
14515
|
-
const slice2 = new Uint8Array(this.buffer.slice(
|
|
15052
|
+
const slice2 = new Uint8Array(this.buffer.slice(offset2, offset2 + bytes));
|
|
14516
15053
|
slice2.reverse();
|
|
14517
15054
|
const returnArray2 = new typedArrays[type](slice2.buffer);
|
|
14518
15055
|
this.offset += bytes;
|
|
@@ -19341,7 +19878,7 @@ var require_decodeInterlaceAdam7 = __commonJS({
|
|
|
19341
19878
|
];
|
|
19342
19879
|
const bytesPerPixel = Math.ceil(depth / 8) * channels;
|
|
19343
19880
|
const resultData = new Uint8Array(height * width * bytesPerPixel);
|
|
19344
|
-
let
|
|
19881
|
+
let offset2 = 0;
|
|
19345
19882
|
for (let passIndex = 0; passIndex < 7; passIndex++) {
|
|
19346
19883
|
const pass = passes[passIndex];
|
|
19347
19884
|
const passWidth = Math.ceil((width - pass.x) / pass.xStep);
|
|
@@ -19351,9 +19888,9 @@ var require_decodeInterlaceAdam7 = __commonJS({
|
|
|
19351
19888
|
const passLineBytes = passWidth * bytesPerPixel;
|
|
19352
19889
|
const prevLine = new Uint8Array(passLineBytes);
|
|
19353
19890
|
for (let y = 0; y < passHeight; y++) {
|
|
19354
|
-
const filterType = data[
|
|
19355
|
-
const currentLine = data.subarray(
|
|
19356
|
-
|
|
19891
|
+
const filterType = data[offset2++];
|
|
19892
|
+
const currentLine = data.subarray(offset2, offset2 + passLineBytes);
|
|
19893
|
+
offset2 += passLineBytes;
|
|
19357
19894
|
const newLine = new Uint8Array(passLineBytes);
|
|
19358
19895
|
(0, applyUnfilter_1.applyUnfilter)(filterType, currentLine, newLine, prevLine, passLineBytes, bytesPerPixel);
|
|
19359
19896
|
prevLine.set(newLine);
|
|
@@ -19403,13 +19940,13 @@ var require_decodeInterlaceNull = __commonJS({
|
|
|
19403
19940
|
const bytesPerLine = Math.ceil(depth / 8 * channels * width);
|
|
19404
19941
|
const newData = new Uint8Array(height * bytesPerLine);
|
|
19405
19942
|
let prevLine = empty;
|
|
19406
|
-
let
|
|
19943
|
+
let offset2 = 0;
|
|
19407
19944
|
let currentLine;
|
|
19408
19945
|
let newLine;
|
|
19409
19946
|
for (let i = 0; i < height; i++) {
|
|
19410
|
-
currentLine = data.subarray(
|
|
19947
|
+
currentLine = data.subarray(offset2 + 1, offset2 + 1 + bytesPerLine);
|
|
19411
19948
|
newLine = newData.subarray(i * bytesPerLine, (i + 1) * bytesPerLine);
|
|
19412
|
-
switch (data[
|
|
19949
|
+
switch (data[offset2]) {
|
|
19413
19950
|
case 0:
|
|
19414
19951
|
(0, unfilter_1.unfilterNone)(currentLine, newLine, bytesPerLine);
|
|
19415
19952
|
break;
|
|
@@ -19426,10 +19963,10 @@ var require_decodeInterlaceNull = __commonJS({
|
|
|
19426
19963
|
(0, unfilter_1.unfilterPaeth)(currentLine, newLine, prevLine, bytesPerLine, bytesPerPixel);
|
|
19427
19964
|
break;
|
|
19428
19965
|
default:
|
|
19429
|
-
throw new Error(`Unsupported filter: ${data[
|
|
19966
|
+
throw new Error(`Unsupported filter: ${data[offset2]}`);
|
|
19430
19967
|
}
|
|
19431
19968
|
prevLine = newLine;
|
|
19432
|
-
|
|
19969
|
+
offset2 += bytesPerLine + 1;
|
|
19433
19970
|
}
|
|
19434
19971
|
if (depth === 16) {
|
|
19435
19972
|
const uint16Data = new Uint16Array(newData.buffer);
|
|
@@ -19670,7 +20207,7 @@ var require_PngDecoder = __commonJS({
|
|
|
19670
20207
|
}
|
|
19671
20208
|
// https://www.w3.org/TR/PNG/#5Chunk-layout
|
|
19672
20209
|
decodeChunk(length, type) {
|
|
19673
|
-
const
|
|
20210
|
+
const offset2 = this.offset;
|
|
19674
20211
|
switch (type) {
|
|
19675
20212
|
// 11.2 Critical chunks
|
|
19676
20213
|
case "IHDR":
|
|
@@ -19702,7 +20239,7 @@ var require_PngDecoder = __commonJS({
|
|
|
19702
20239
|
this.skip(length);
|
|
19703
20240
|
break;
|
|
19704
20241
|
}
|
|
19705
|
-
if (this.offset -
|
|
20242
|
+
if (this.offset - offset2 !== length) {
|
|
19706
20243
|
throw new Error(`Length mismatch while decoding chunk ${type}`);
|
|
19707
20244
|
}
|
|
19708
20245
|
if (this._checkCrc) {
|
|
@@ -19712,7 +20249,7 @@ var require_PngDecoder = __commonJS({
|
|
|
19712
20249
|
}
|
|
19713
20250
|
}
|
|
19714
20251
|
decodeApngChunk(length, type) {
|
|
19715
|
-
const
|
|
20252
|
+
const offset2 = this.offset;
|
|
19716
20253
|
if (type !== "fdAT" && type !== "IDAT" && this._writingDataChunks) {
|
|
19717
20254
|
this.pushDataToFrame();
|
|
19718
20255
|
}
|
|
@@ -19728,10 +20265,10 @@ var require_PngDecoder = __commonJS({
|
|
|
19728
20265
|
break;
|
|
19729
20266
|
default:
|
|
19730
20267
|
this.decodeChunk(length, type);
|
|
19731
|
-
this.offset =
|
|
20268
|
+
this.offset = offset2 + length;
|
|
19732
20269
|
break;
|
|
19733
20270
|
}
|
|
19734
|
-
if (this.offset -
|
|
20271
|
+
if (this.offset - offset2 !== length) {
|
|
19735
20272
|
throw new Error(`Length mismatch while decoding chunk ${type}`);
|
|
19736
20273
|
}
|
|
19737
20274
|
if (this._checkCrc) {
|
|
@@ -20161,18 +20698,18 @@ var require_PngEncoder = __commonJS({
|
|
|
20161
20698
|
const { width, height, channels, depth, data } = this._png;
|
|
20162
20699
|
const slotsPerLine = depth <= 8 ? Math.ceil(width * depth / 8) * channels : Math.ceil(width * depth / 8 * channels / 2);
|
|
20163
20700
|
const newData = new iobuffer_1.IOBuffer().setBigEndian();
|
|
20164
|
-
let
|
|
20701
|
+
let offset2 = 0;
|
|
20165
20702
|
if (this._interlaceMethod === internalTypes_1.InterlaceMethod.NO_INTERLACE) {
|
|
20166
20703
|
for (let i = 0; i < height; i++) {
|
|
20167
20704
|
newData.writeByte(0);
|
|
20168
20705
|
if (depth === 16) {
|
|
20169
|
-
|
|
20706
|
+
offset2 = writeDataUint16(data, newData, slotsPerLine, offset2);
|
|
20170
20707
|
} else {
|
|
20171
|
-
|
|
20708
|
+
offset2 = writeDataBytes(data, newData, slotsPerLine, offset2);
|
|
20172
20709
|
}
|
|
20173
20710
|
}
|
|
20174
20711
|
} else if (this._interlaceMethod === internalTypes_1.InterlaceMethod.ADAM7) {
|
|
20175
|
-
|
|
20712
|
+
offset2 = writeDataInterlaced(this._png, data, newData, offset2);
|
|
20176
20713
|
}
|
|
20177
20714
|
const buffer = newData.toArray();
|
|
20178
20715
|
const compressed = (0, pako_1.deflate)(buffer, this._zlibOptions);
|
|
@@ -20236,13 +20773,13 @@ var require_PngEncoder = __commonJS({
|
|
|
20236
20773
|
}
|
|
20237
20774
|
return returnValue;
|
|
20238
20775
|
}
|
|
20239
|
-
function writeDataBytes(data, newData, slotsPerLine,
|
|
20776
|
+
function writeDataBytes(data, newData, slotsPerLine, offset2) {
|
|
20240
20777
|
for (let j = 0; j < slotsPerLine; j++) {
|
|
20241
|
-
newData.writeByte(data[
|
|
20778
|
+
newData.writeByte(data[offset2++]);
|
|
20242
20779
|
}
|
|
20243
|
-
return
|
|
20780
|
+
return offset2;
|
|
20244
20781
|
}
|
|
20245
|
-
function writeDataInterlaced(imageData, data, newData,
|
|
20782
|
+
function writeDataInterlaced(imageData, data, newData, offset2) {
|
|
20246
20783
|
const passes = [
|
|
20247
20784
|
{ x: 0, y: 0, xStep: 8, yStep: 8 },
|
|
20248
20785
|
{ x: 4, y: 0, xStep: 8, yStep: 8 },
|
|
@@ -20290,13 +20827,13 @@ var require_PngEncoder = __commonJS({
|
|
|
20290
20827
|
}
|
|
20291
20828
|
}
|
|
20292
20829
|
}
|
|
20293
|
-
return
|
|
20830
|
+
return offset2;
|
|
20294
20831
|
}
|
|
20295
|
-
function writeDataUint16(data, newData, slotsPerLine,
|
|
20832
|
+
function writeDataUint16(data, newData, slotsPerLine, offset2) {
|
|
20296
20833
|
for (let j = 0; j < slotsPerLine; j++) {
|
|
20297
|
-
newData.writeUint16(data[
|
|
20834
|
+
newData.writeUint16(data[offset2++]);
|
|
20298
20835
|
}
|
|
20299
|
-
return
|
|
20836
|
+
return offset2;
|
|
20300
20837
|
}
|
|
20301
20838
|
}
|
|
20302
20839
|
});
|
|
@@ -20332,7 +20869,7 @@ var require_convertIndexedToRgb = __commonJS({
|
|
|
20332
20869
|
const resSize = indexSize * palette[0].length;
|
|
20333
20870
|
const res = new Uint8Array(resSize);
|
|
20334
20871
|
let indexPos = 0;
|
|
20335
|
-
let
|
|
20872
|
+
let offset2 = 0;
|
|
20336
20873
|
const indexes = new Uint8Array(indexSize);
|
|
20337
20874
|
let bit = 255;
|
|
20338
20875
|
switch (depth) {
|
|
@@ -20369,8 +20906,8 @@ var require_convertIndexedToRgb = __commonJS({
|
|
|
20369
20906
|
if (!color) {
|
|
20370
20907
|
throw new Error("Incorrect index of palette color");
|
|
20371
20908
|
}
|
|
20372
|
-
res.set(color,
|
|
20373
|
-
|
|
20909
|
+
res.set(color, offset2);
|
|
20910
|
+
offset2 += color.length;
|
|
20374
20911
|
}
|
|
20375
20912
|
}
|
|
20376
20913
|
return res;
|
|
@@ -31507,13 +32044,13 @@ var require_lib2 = __commonJS({
|
|
|
31507
32044
|
} else if (typeof ctx.mozDash !== "undefined" && !(gaps.length === 1 && gaps[0] === 0)) {
|
|
31508
32045
|
ctx.mozDash = gaps;
|
|
31509
32046
|
}
|
|
31510
|
-
var
|
|
32047
|
+
var offset2 = strokeDashoffsetProp.getPixels();
|
|
31511
32048
|
if (typeof ctx.lineDashOffset !== "undefined") {
|
|
31512
|
-
ctx.lineDashOffset =
|
|
32049
|
+
ctx.lineDashOffset = offset2;
|
|
31513
32050
|
} else if (typeof ctx.webkitLineDashOffset !== "undefined") {
|
|
31514
|
-
ctx.webkitLineDashOffset =
|
|
32051
|
+
ctx.webkitLineDashOffset = offset2;
|
|
31515
32052
|
} else if (typeof ctx.mozDashOffset !== "undefined") {
|
|
31516
|
-
ctx.mozDashOffset =
|
|
32053
|
+
ctx.mozDashOffset = offset2;
|
|
31517
32054
|
}
|
|
31518
32055
|
}
|
|
31519
32056
|
}
|
|
@@ -33578,7 +34115,7 @@ var require_lib2 = __commonJS({
|
|
|
33578
34115
|
_classCallCheck__default["default"](this, StopElement2);
|
|
33579
34116
|
_this = _super.call(this, document2, node2, captureTextNodes);
|
|
33580
34117
|
_this.type = "stop";
|
|
33581
|
-
var
|
|
34118
|
+
var offset2 = Math.max(0, Math.min(1, _this.getAttribute("offset").getNumber()));
|
|
33582
34119
|
var stopOpacity = _this.getStyle("stop-opacity");
|
|
33583
34120
|
var stopColor = _this.getStyle("stop-color", true);
|
|
33584
34121
|
if (stopColor.getString() === "") {
|
|
@@ -33587,7 +34124,7 @@ var require_lib2 = __commonJS({
|
|
|
33587
34124
|
if (stopOpacity.hasValue()) {
|
|
33588
34125
|
stopColor = stopColor.addOpacity(stopOpacity);
|
|
33589
34126
|
}
|
|
33590
|
-
_this.offset =
|
|
34127
|
+
_this.offset = offset2;
|
|
33591
34128
|
_this.color = stopColor.getColor();
|
|
33592
34129
|
return _this;
|
|
33593
34130
|
}
|
|
@@ -34402,17 +34939,17 @@ var require_lib2 = __commonJS({
|
|
|
34402
34939
|
}, {
|
|
34403
34940
|
key: "findSegmentToFitChar",
|
|
34404
34941
|
value: function findSegmentToFitChar(ctx, anchor, textFullWidth, fullPathWidth, spacesNumber, inputOffset, dy, c2, charI) {
|
|
34405
|
-
var
|
|
34942
|
+
var offset2 = inputOffset;
|
|
34406
34943
|
var glyphWidth = this.measureText(ctx, c2);
|
|
34407
34944
|
if (c2 === " " && anchor === "justify" && textFullWidth < fullPathWidth) {
|
|
34408
34945
|
glyphWidth += (fullPathWidth - textFullWidth) / spacesNumber;
|
|
34409
34946
|
}
|
|
34410
34947
|
if (charI > -1) {
|
|
34411
|
-
|
|
34948
|
+
offset2 += this.getLetterSpacingAt(charI);
|
|
34412
34949
|
}
|
|
34413
34950
|
var splineStep = this.textHeight / 20;
|
|
34414
|
-
var p0 = this.getEquidistantPointOnPath(
|
|
34415
|
-
var p1 = this.getEquidistantPointOnPath(
|
|
34951
|
+
var p0 = this.getEquidistantPointOnPath(offset2, splineStep, 0);
|
|
34952
|
+
var p1 = this.getEquidistantPointOnPath(offset2 + glyphWidth, splineStep, 0);
|
|
34416
34953
|
var segment = {
|
|
34417
34954
|
p0,
|
|
34418
34955
|
p1
|
|
@@ -34430,9 +34967,9 @@ var require_lib2 = __commonJS({
|
|
|
34430
34967
|
y: p1.y + dyY
|
|
34431
34968
|
});
|
|
34432
34969
|
}
|
|
34433
|
-
|
|
34970
|
+
offset2 += glyphWidth;
|
|
34434
34971
|
return {
|
|
34435
|
-
offset,
|
|
34972
|
+
offset: offset2,
|
|
34436
34973
|
segment,
|
|
34437
34974
|
rotation
|
|
34438
34975
|
};
|
|
@@ -34493,17 +35030,17 @@ var require_lib2 = __commonJS({
|
|
|
34493
35030
|
this.glyphInfo = [];
|
|
34494
35031
|
var fullPathWidth = this.getPathLength();
|
|
34495
35032
|
var startOffset = this.getStyle("startOffset").getNumber(0) * fullPathWidth;
|
|
34496
|
-
var
|
|
35033
|
+
var offset2 = 0;
|
|
34497
35034
|
if (anchor === "middle" || anchor === "center") {
|
|
34498
|
-
|
|
35035
|
+
offset2 = -textFullWidth / 2;
|
|
34499
35036
|
}
|
|
34500
35037
|
if (anchor === "end" || anchor === "right") {
|
|
34501
|
-
|
|
35038
|
+
offset2 = -textFullWidth;
|
|
34502
35039
|
}
|
|
34503
|
-
|
|
35040
|
+
offset2 += startOffset;
|
|
34504
35041
|
chars.forEach(function(char, i2) {
|
|
34505
|
-
var _this2$findSegmentToF = _this2.findSegmentToFitChar(ctx, anchor, textFullWidth, fullPathWidth, spacesNumber,
|
|
34506
|
-
|
|
35042
|
+
var _this2$findSegmentToF = _this2.findSegmentToFitChar(ctx, anchor, textFullWidth, fullPathWidth, spacesNumber, offset2, dy, char, i2), nextOffset = _this2$findSegmentToF.offset, segment = _this2$findSegmentToF.segment, rotation = _this2$findSegmentToF.rotation;
|
|
35043
|
+
offset2 = nextOffset;
|
|
34507
35044
|
if (!segment.p0 || !segment.p1) {
|
|
34508
35045
|
return;
|
|
34509
35046
|
}
|
|
@@ -45262,10 +45799,10 @@ var init_dist_js2 = __esm({
|
|
|
45262
45799
|
*
|
|
45263
45800
|
* @since 2.0.0
|
|
45264
45801
|
*/
|
|
45265
|
-
async seek(
|
|
45802
|
+
async seek(offset2, whence) {
|
|
45266
45803
|
return await invoke("plugin:fs|seek", {
|
|
45267
45804
|
rid: this.rid,
|
|
45268
|
-
offset,
|
|
45805
|
+
offset: offset2,
|
|
45269
45806
|
whence
|
|
45270
45807
|
});
|
|
45271
45808
|
}
|
|
@@ -46907,6 +47444,8 @@ __export(index_exports, {
|
|
|
46907
47444
|
});
|
|
46908
47445
|
module.exports = __toCommonJS(index_exports);
|
|
46909
47446
|
init_useGoogleAuth();
|
|
47447
|
+
init_useFacebookAuth();
|
|
47448
|
+
init_useMetaAuth();
|
|
46910
47449
|
init_useYocoPayment();
|
|
46911
47450
|
init_debug();
|
|
46912
47451
|
|
|
@@ -47243,6 +47782,181 @@ function createPdfApi() {
|
|
|
47243
47782
|
};
|
|
47244
47783
|
}
|
|
47245
47784
|
|
|
47785
|
+
// src/services/agentNotifications.js
|
|
47786
|
+
var toList = (result) => Array.isArray(result) ? result : result?.data || [];
|
|
47787
|
+
var latestByTime = (records) => [...records].sort((a, b) => {
|
|
47788
|
+
const left = Number(a.createdAt || a.updatedAt || 0) || Date.parse(a.createdAt || a.updatedAt || 0) || 0;
|
|
47789
|
+
const right = Number(b.createdAt || b.updatedAt || 0) || Date.parse(b.createdAt || b.updatedAt || 0) || 0;
|
|
47790
|
+
return right - left;
|
|
47791
|
+
})[0] || null;
|
|
47792
|
+
function createAgentNotificationService(client) {
|
|
47793
|
+
let timer = null;
|
|
47794
|
+
let stopped = true;
|
|
47795
|
+
const seen = /* @__PURE__ */ new Map();
|
|
47796
|
+
const listeners2 = /* @__PURE__ */ new Set();
|
|
47797
|
+
const notify = (event) => listeners2.forEach((listener) => listener(event));
|
|
47798
|
+
const getSessionId = (session) => session.sessionId || session.session_id || session.id;
|
|
47799
|
+
const getMessages = async (sessionId, appId) => {
|
|
47800
|
+
const [bySessionId, byLegacySessionId] = await Promise.all([
|
|
47801
|
+
client.entities.ChatMessage.query({ filter: { appId, sessionId }, limit: 100 }),
|
|
47802
|
+
client.entities.ChatMessage.query({ filter: { appId, session_id: sessionId }, limit: 100 })
|
|
47803
|
+
]);
|
|
47804
|
+
const seenMessages = /* @__PURE__ */ new Set();
|
|
47805
|
+
return [...toList(bySessionId), ...toList(byLegacySessionId)].filter((message2) => {
|
|
47806
|
+
const key = message2?.id || `${message2?.createdAt || ""}:${message2?.content || ""}`;
|
|
47807
|
+
if (seenMessages.has(key)) return false;
|
|
47808
|
+
seenMessages.add(key);
|
|
47809
|
+
return true;
|
|
47810
|
+
});
|
|
47811
|
+
};
|
|
47812
|
+
const publish = (sessionId, payload) => {
|
|
47813
|
+
const connection = client.realtime.room(sessionId, {}, { maxReconnects: 2 });
|
|
47814
|
+
connection.publish({ type: "chat_message", sessionId, session_id: sessionId, message: payload, payload });
|
|
47815
|
+
setTimeout(() => connection.close(), 1e3);
|
|
47816
|
+
};
|
|
47817
|
+
const publishStatus = (sessionId, status, session) => publish(sessionId, {
|
|
47818
|
+
id: `status_${status}_${Date.now()}`,
|
|
47819
|
+
type: "chat_status",
|
|
47820
|
+
status,
|
|
47821
|
+
sessionId,
|
|
47822
|
+
session_id: sessionId,
|
|
47823
|
+
visitor_name: session?.visitor_name || "",
|
|
47824
|
+
createdAt: Date.now()
|
|
47825
|
+
});
|
|
47826
|
+
const accept = async (session) => {
|
|
47827
|
+
const sessionId = getSessionId(session);
|
|
47828
|
+
await client.entities.ChatSession.update(session.id, {
|
|
47829
|
+
status: "agent_active",
|
|
47830
|
+
agent_email: client.agentIdentity || "agent",
|
|
47831
|
+
updatedAt: Date.now()
|
|
47832
|
+
});
|
|
47833
|
+
publishStatus(sessionId, "agent_active", session);
|
|
47834
|
+
notify({ type: "accepted", sessionId, session });
|
|
47835
|
+
};
|
|
47836
|
+
const reject = async (session) => {
|
|
47837
|
+
const sessionId = getSessionId(session);
|
|
47838
|
+
await client.entities.ChatSession.update(session.id, { status: "agent_rejected", updatedAt: Date.now() });
|
|
47839
|
+
publishStatus(sessionId, "agent_rejected", session);
|
|
47840
|
+
notify({ type: "rejected", sessionId, session });
|
|
47841
|
+
};
|
|
47842
|
+
const reply = async (session, content) => {
|
|
47843
|
+
const sessionId = getSessionId(session);
|
|
47844
|
+
if (!content?.trim()) throw new TypeError("A reply message is required.");
|
|
47845
|
+
const message2 = {
|
|
47846
|
+
id: `msg_${Date.now()}_${Math.random().toString(36).slice(2)}`,
|
|
47847
|
+
appId: session.appId || client.appId,
|
|
47848
|
+
userId: client.agentIdentity || "agent",
|
|
47849
|
+
sessionId,
|
|
47850
|
+
session_id: sessionId,
|
|
47851
|
+
role: "agent",
|
|
47852
|
+
content: content.trim(),
|
|
47853
|
+
createdAt: Date.now()
|
|
47854
|
+
};
|
|
47855
|
+
await client.entities.ChatMessage.create(message2);
|
|
47856
|
+
publish(sessionId, message2);
|
|
47857
|
+
notify({ type: "replied", sessionId, session, message: message2 });
|
|
47858
|
+
return message2;
|
|
47859
|
+
};
|
|
47860
|
+
const dispatchAction = async ({ action, sessionId, reply: text }) => {
|
|
47861
|
+
const appId = client.appId;
|
|
47862
|
+
const [bySessionId, byLegacySessionId] = await Promise.all([
|
|
47863
|
+
client.entities.ChatSession.query({ filter: { appId, sessionId }, limit: 1 }),
|
|
47864
|
+
client.entities.ChatSession.query({ filter: { appId, session_id: sessionId }, limit: 1 })
|
|
47865
|
+
]);
|
|
47866
|
+
const session = toList(bySessionId)[0] || toList(byLegacySessionId)[0];
|
|
47867
|
+
if (!session) return;
|
|
47868
|
+
if (action === "open") return notify({ type: "open", sessionId, session });
|
|
47869
|
+
if (action === "accept") return accept(session);
|
|
47870
|
+
if (action === "reject") return reject(session);
|
|
47871
|
+
if (action === "reply") return reply(session, text);
|
|
47872
|
+
};
|
|
47873
|
+
const showNative = (request) => client.notifications.show({
|
|
47874
|
+
id: `agent-request-${request.sessionId}`,
|
|
47875
|
+
title: request.title,
|
|
47876
|
+
body: request.body,
|
|
47877
|
+
data: { sessionId: request.sessionId, kind: request.kind || "agent_request" },
|
|
47878
|
+
channel: "agent_requests",
|
|
47879
|
+
style: request.style,
|
|
47880
|
+
actions: [
|
|
47881
|
+
...request.kind === "agent_message" ? [] : [
|
|
47882
|
+
{ id: "accept", title: "Accept" },
|
|
47883
|
+
{ id: "reject", title: "Reject" }
|
|
47884
|
+
],
|
|
47885
|
+
{ id: "open", title: "Open" },
|
|
47886
|
+
{ id: "reply", title: "Reply", input: true }
|
|
47887
|
+
]
|
|
47888
|
+
});
|
|
47889
|
+
const check = async ({ appId = client.appId, notificationStyle } = {}) => {
|
|
47890
|
+
const sessions = toList(await client.entities.ChatSession.query({ filter: { appId, status: "escalated" }, limit: 100 }));
|
|
47891
|
+
for (const session of sessions) {
|
|
47892
|
+
const sessionId = getSessionId(session);
|
|
47893
|
+
if (!sessionId) continue;
|
|
47894
|
+
const latest = latestByTime(await getMessages(sessionId, appId));
|
|
47895
|
+
const fingerprint = `${session.updatedAt || session.lastMessageAt || session.createdAt}:${latest?.id || latest?.content || ""}`;
|
|
47896
|
+
if (seen.get(sessionId) === fingerprint) continue;
|
|
47897
|
+
seen.set(sessionId, fingerprint);
|
|
47898
|
+
const request = {
|
|
47899
|
+
sessionId,
|
|
47900
|
+
kind: "agent_request",
|
|
47901
|
+
title: `Support request from ${session.visitor_name || "a visitor"}`,
|
|
47902
|
+
body: latest?.content || "A visitor is requesting a human agent.",
|
|
47903
|
+
latestMessage: latest,
|
|
47904
|
+
session,
|
|
47905
|
+
style: notificationStyle
|
|
47906
|
+
};
|
|
47907
|
+
await showNative(request);
|
|
47908
|
+
notify({ type: "request", ...request });
|
|
47909
|
+
}
|
|
47910
|
+
if (client.agentIdentity) {
|
|
47911
|
+
const active = toList(await client.entities.ChatSession.query({ filter: { appId, status: "agent_active", agent_email: client.agentIdentity }, limit: 100 }));
|
|
47912
|
+
for (const session of active) {
|
|
47913
|
+
const sessionId = getSessionId(session);
|
|
47914
|
+
if (!sessionId) continue;
|
|
47915
|
+
const messages = await getMessages(sessionId, appId);
|
|
47916
|
+
const latestVisitor = latestByTime(messages.filter((message2) => message2?.role === "visitor" || message2?.role === "user"));
|
|
47917
|
+
if (!latestVisitor) continue;
|
|
47918
|
+
const fingerprint = `message:${latestVisitor.id || latestVisitor.createdAt || latestVisitor.content}`;
|
|
47919
|
+
if (seen.get(`message:${sessionId}`) === fingerprint) continue;
|
|
47920
|
+
seen.set(`message:${sessionId}`, fingerprint);
|
|
47921
|
+
const request = {
|
|
47922
|
+
sessionId,
|
|
47923
|
+
kind: "agent_message",
|
|
47924
|
+
title: `New message from ${session.visitor_name || "visitor"}`,
|
|
47925
|
+
body: latestVisitor.content || "The visitor sent an attachment.",
|
|
47926
|
+
latestMessage: latestVisitor,
|
|
47927
|
+
session,
|
|
47928
|
+
style: notificationStyle
|
|
47929
|
+
};
|
|
47930
|
+
await showNative(request);
|
|
47931
|
+
notify({ type: "message", ...request });
|
|
47932
|
+
}
|
|
47933
|
+
}
|
|
47934
|
+
};
|
|
47935
|
+
const start = async ({ pollMs = 8e3, agentIdentity, ...options } = {}) => {
|
|
47936
|
+
if (agentIdentity) client.agentIdentity = agentIdentity;
|
|
47937
|
+
if (options.appId) client.appId = options.appId;
|
|
47938
|
+
stopped = false;
|
|
47939
|
+
await check(options);
|
|
47940
|
+
clearInterval(timer);
|
|
47941
|
+
timer = setInterval(() => !stopped && check(options).catch((error) => notify({ type: "error", error })), pollMs);
|
|
47942
|
+
};
|
|
47943
|
+
const stop = () => {
|
|
47944
|
+
stopped = true;
|
|
47945
|
+
clearInterval(timer);
|
|
47946
|
+
timer = null;
|
|
47947
|
+
};
|
|
47948
|
+
const onEvent = (listener) => {
|
|
47949
|
+
listeners2.add(listener);
|
|
47950
|
+
return () => listeners2.delete(listener);
|
|
47951
|
+
};
|
|
47952
|
+
client.notifications.onAction(({ action, data, reply: text }) => {
|
|
47953
|
+
if (data?.sessionId && String(data.kind || "").startsWith("agent_")) {
|
|
47954
|
+
dispatchAction({ action, sessionId: data.sessionId, reply: text }).catch((error) => notify({ type: "error", error }));
|
|
47955
|
+
}
|
|
47956
|
+
});
|
|
47957
|
+
return { start, stop, check, onEvent, accept, reject, reply, dispatchAction };
|
|
47958
|
+
}
|
|
47959
|
+
|
|
47246
47960
|
// src/services/notifications.js
|
|
47247
47961
|
var isBrowser = () => typeof window !== "undefined" && typeof Notification !== "undefined";
|
|
47248
47962
|
function createNotificationService() {
|
|
@@ -47368,190 +48082,13 @@ function createNotificationService() {
|
|
|
47368
48082
|
return { permission, requestPermission, show, schedule, cancel, cancelAll, onAction };
|
|
47369
48083
|
}
|
|
47370
48084
|
|
|
47371
|
-
// src/services/agentNotifications.js
|
|
47372
|
-
var toList = (result) => Array.isArray(result) ? result : result?.data || [];
|
|
47373
|
-
var latestByTime = (records) => [...records].sort((a, b) => {
|
|
47374
|
-
const left = Number(a.createdAt || a.updatedAt || 0) || Date.parse(a.createdAt || a.updatedAt || 0) || 0;
|
|
47375
|
-
const right = Number(b.createdAt || b.updatedAt || 0) || Date.parse(b.createdAt || b.updatedAt || 0) || 0;
|
|
47376
|
-
return right - left;
|
|
47377
|
-
})[0] || null;
|
|
47378
|
-
function createAgentNotificationService(client) {
|
|
47379
|
-
const notifications = client.notifications || createNotificationService();
|
|
47380
|
-
let timer = null;
|
|
47381
|
-
let stopped = true;
|
|
47382
|
-
const seen = /* @__PURE__ */ new Map();
|
|
47383
|
-
const listeners2 = /* @__PURE__ */ new Set();
|
|
47384
|
-
const notify = (event) => listeners2.forEach((listener) => listener(event));
|
|
47385
|
-
const getSessionId = (session) => session.sessionId || session.session_id || session.id;
|
|
47386
|
-
const getMessages = async (sessionId, appId) => {
|
|
47387
|
-
const [bySessionId, byLegacySessionId] = await Promise.all([
|
|
47388
|
-
client.entities.ChatMessage.query({ filter: { appId, sessionId }, limit: 100 }),
|
|
47389
|
-
client.entities.ChatMessage.query({ filter: { appId, session_id: sessionId }, limit: 100 })
|
|
47390
|
-
]);
|
|
47391
|
-
const seenMessages = /* @__PURE__ */ new Set();
|
|
47392
|
-
return [...toList(bySessionId), ...toList(byLegacySessionId)].filter((message2) => {
|
|
47393
|
-
const key = message2?.id || `${message2?.createdAt || ""}:${message2?.content || ""}`;
|
|
47394
|
-
if (seenMessages.has(key)) return false;
|
|
47395
|
-
seenMessages.add(key);
|
|
47396
|
-
return true;
|
|
47397
|
-
});
|
|
47398
|
-
};
|
|
47399
|
-
const publish = (sessionId, payload) => {
|
|
47400
|
-
const connection = client.realtime.room(sessionId, {}, { maxReconnects: 2 });
|
|
47401
|
-
connection.publish({ type: "chat_message", sessionId, session_id: sessionId, message: payload, payload });
|
|
47402
|
-
setTimeout(() => connection.close(), 1e3);
|
|
47403
|
-
};
|
|
47404
|
-
const publishStatus = (sessionId, status, session) => publish(sessionId, {
|
|
47405
|
-
id: `status_${status}_${Date.now()}`,
|
|
47406
|
-
type: "chat_status",
|
|
47407
|
-
status,
|
|
47408
|
-
sessionId,
|
|
47409
|
-
session_id: sessionId,
|
|
47410
|
-
visitor_name: session?.visitor_name || "",
|
|
47411
|
-
createdAt: Date.now()
|
|
47412
|
-
});
|
|
47413
|
-
const accept = async (session) => {
|
|
47414
|
-
const sessionId = getSessionId(session);
|
|
47415
|
-
await client.entities.ChatSession.update(session.id, {
|
|
47416
|
-
status: "agent_active",
|
|
47417
|
-
agent_email: client.agentIdentity || "agent",
|
|
47418
|
-
updatedAt: Date.now()
|
|
47419
|
-
});
|
|
47420
|
-
publishStatus(sessionId, "agent_active", session);
|
|
47421
|
-
notify({ type: "accepted", sessionId, session });
|
|
47422
|
-
};
|
|
47423
|
-
const reject = async (session) => {
|
|
47424
|
-
const sessionId = getSessionId(session);
|
|
47425
|
-
await client.entities.ChatSession.update(session.id, { status: "agent_rejected", updatedAt: Date.now() });
|
|
47426
|
-
publishStatus(sessionId, "agent_rejected", session);
|
|
47427
|
-
notify({ type: "rejected", sessionId, session });
|
|
47428
|
-
};
|
|
47429
|
-
const reply = async (session, content) => {
|
|
47430
|
-
const sessionId = getSessionId(session);
|
|
47431
|
-
if (!content?.trim()) throw new TypeError("A reply message is required.");
|
|
47432
|
-
const message2 = {
|
|
47433
|
-
id: `msg_${Date.now()}_${Math.random().toString(36).slice(2)}`,
|
|
47434
|
-
appId: session.appId || client.appId,
|
|
47435
|
-
userId: client.agentIdentity || "agent",
|
|
47436
|
-
sessionId,
|
|
47437
|
-
session_id: sessionId,
|
|
47438
|
-
role: "agent",
|
|
47439
|
-
content: content.trim(),
|
|
47440
|
-
createdAt: Date.now()
|
|
47441
|
-
};
|
|
47442
|
-
await client.entities.ChatMessage.create(message2);
|
|
47443
|
-
publish(sessionId, message2);
|
|
47444
|
-
notify({ type: "replied", sessionId, session, message: message2 });
|
|
47445
|
-
return message2;
|
|
47446
|
-
};
|
|
47447
|
-
const dispatchAction = async ({ action, sessionId, reply: text }) => {
|
|
47448
|
-
const appId = client.appId;
|
|
47449
|
-
const [bySessionId, byLegacySessionId] = await Promise.all([
|
|
47450
|
-
client.entities.ChatSession.query({ filter: { appId, sessionId }, limit: 1 }),
|
|
47451
|
-
client.entities.ChatSession.query({ filter: { appId, session_id: sessionId }, limit: 1 })
|
|
47452
|
-
]);
|
|
47453
|
-
const session = toList(bySessionId)[0] || toList(byLegacySessionId)[0];
|
|
47454
|
-
if (!session) return;
|
|
47455
|
-
if (action === "open") return notify({ type: "open", sessionId, session });
|
|
47456
|
-
if (action === "accept") return accept(session);
|
|
47457
|
-
if (action === "reject") return reject(session);
|
|
47458
|
-
if (action === "reply") return reply(session, text);
|
|
47459
|
-
};
|
|
47460
|
-
const showNative = (request) => notifications.show({
|
|
47461
|
-
id: `agent-request-${request.sessionId}`,
|
|
47462
|
-
title: request.title,
|
|
47463
|
-
body: request.body,
|
|
47464
|
-
data: { sessionId: request.sessionId, kind: request.kind || "agent_request" },
|
|
47465
|
-
channel: "agent_requests",
|
|
47466
|
-
style: request.style,
|
|
47467
|
-
actions: [
|
|
47468
|
-
...request.kind === "agent_message" ? [] : [
|
|
47469
|
-
{ id: "accept", title: "Accept" },
|
|
47470
|
-
{ id: "reject", title: "Reject" }
|
|
47471
|
-
],
|
|
47472
|
-
{ id: "open", title: "Open" },
|
|
47473
|
-
{ id: "reply", title: "Reply", input: true }
|
|
47474
|
-
]
|
|
47475
|
-
});
|
|
47476
|
-
const check = async ({ appId = client.appId, notificationStyle } = {}) => {
|
|
47477
|
-
const sessions = toList(await client.entities.ChatSession.query({ filter: { appId, status: "escalated" }, limit: 100 }));
|
|
47478
|
-
for (const session of sessions) {
|
|
47479
|
-
const sessionId = getSessionId(session);
|
|
47480
|
-
if (!sessionId) continue;
|
|
47481
|
-
const latest = latestByTime(await getMessages(sessionId, appId));
|
|
47482
|
-
const fingerprint = `${session.updatedAt || session.lastMessageAt || session.createdAt}:${latest?.id || latest?.content || ""}`;
|
|
47483
|
-
if (seen.get(sessionId) === fingerprint) continue;
|
|
47484
|
-
seen.set(sessionId, fingerprint);
|
|
47485
|
-
const request = {
|
|
47486
|
-
sessionId,
|
|
47487
|
-
kind: "agent_request",
|
|
47488
|
-
title: `Support request from ${session.visitor_name || "a visitor"}`,
|
|
47489
|
-
body: latest?.content || "A visitor is requesting a human agent.",
|
|
47490
|
-
latestMessage: latest,
|
|
47491
|
-
session,
|
|
47492
|
-
style: notificationStyle
|
|
47493
|
-
};
|
|
47494
|
-
await showNative(request);
|
|
47495
|
-
notify({ type: "request", ...request });
|
|
47496
|
-
}
|
|
47497
|
-
if (client.agentIdentity) {
|
|
47498
|
-
const active = toList(await client.entities.ChatSession.query({ filter: { appId, status: "agent_active", agent_email: client.agentIdentity }, limit: 100 }));
|
|
47499
|
-
for (const session of active) {
|
|
47500
|
-
const sessionId = getSessionId(session);
|
|
47501
|
-
if (!sessionId) continue;
|
|
47502
|
-
const messages = await getMessages(sessionId, appId);
|
|
47503
|
-
const latestVisitor = latestByTime(messages.filter((message2) => message2?.role === "visitor" || message2?.role === "user"));
|
|
47504
|
-
if (!latestVisitor) continue;
|
|
47505
|
-
const fingerprint = `message:${latestVisitor.id || latestVisitor.createdAt || latestVisitor.content}`;
|
|
47506
|
-
if (seen.get(`message:${sessionId}`) === fingerprint) continue;
|
|
47507
|
-
seen.set(`message:${sessionId}`, fingerprint);
|
|
47508
|
-
const request = {
|
|
47509
|
-
sessionId,
|
|
47510
|
-
kind: "agent_message",
|
|
47511
|
-
title: `New message from ${session.visitor_name || "visitor"}`,
|
|
47512
|
-
body: latestVisitor.content || "The visitor sent an attachment.",
|
|
47513
|
-
latestMessage: latestVisitor,
|
|
47514
|
-
session,
|
|
47515
|
-
style: notificationStyle
|
|
47516
|
-
};
|
|
47517
|
-
await showNative(request);
|
|
47518
|
-
notify({ type: "message", ...request });
|
|
47519
|
-
}
|
|
47520
|
-
}
|
|
47521
|
-
};
|
|
47522
|
-
const start = async ({ pollMs = 8e3, agentIdentity, ...options } = {}) => {
|
|
47523
|
-
if (agentIdentity) client.agentIdentity = agentIdentity;
|
|
47524
|
-
if (options.appId) client.appId = options.appId;
|
|
47525
|
-
stopped = false;
|
|
47526
|
-
await check(options);
|
|
47527
|
-
clearInterval(timer);
|
|
47528
|
-
timer = setInterval(() => !stopped && check(options).catch((error) => notify({ type: "error", error })), pollMs);
|
|
47529
|
-
};
|
|
47530
|
-
const stop = () => {
|
|
47531
|
-
stopped = true;
|
|
47532
|
-
clearInterval(timer);
|
|
47533
|
-
timer = null;
|
|
47534
|
-
};
|
|
47535
|
-
const onEvent = (listener) => {
|
|
47536
|
-
listeners2.add(listener);
|
|
47537
|
-
return () => listeners2.delete(listener);
|
|
47538
|
-
};
|
|
47539
|
-
notifications.onAction(({ action, data, reply: text }) => {
|
|
47540
|
-
if (data?.sessionId && String(data.kind || "").startsWith("agent_")) {
|
|
47541
|
-
dispatchAction({ action, sessionId: data.sessionId, reply: text }).catch((error) => notify({ type: "error", error }));
|
|
47542
|
-
}
|
|
47543
|
-
});
|
|
47544
|
-
return { start, stop, check, onEvent, accept, reject, reply, dispatchAction };
|
|
47545
|
-
}
|
|
47546
|
-
|
|
47547
48085
|
// src/services/chatNotifications.js
|
|
47548
48086
|
function createChatNotificationService(client) {
|
|
47549
|
-
const notifications = client.notifications || createNotificationService();
|
|
47550
48087
|
const listeners2 = /* @__PURE__ */ new Set();
|
|
47551
48088
|
const emit2 = (event) => listeners2.forEach((listener) => listener(event));
|
|
47552
48089
|
const showMessage = async ({ sessionId, title = "New chat message", body = "", data = {}, style } = {}) => {
|
|
47553
48090
|
if (!sessionId) return null;
|
|
47554
|
-
return notifications.show({
|
|
48091
|
+
return client.notifications.show({
|
|
47555
48092
|
id: `chat-message-${sessionId}-${Date.now()}`,
|
|
47556
48093
|
title,
|
|
47557
48094
|
body,
|
|
@@ -47566,7 +48103,7 @@ function createChatNotificationService(client) {
|
|
|
47566
48103
|
};
|
|
47567
48104
|
const showStatus = async ({ sessionId, title = "Chat update", body = "", data = {}, style } = {}) => {
|
|
47568
48105
|
if (!sessionId) return null;
|
|
47569
|
-
return notifications.show({
|
|
48106
|
+
return client.notifications.show({
|
|
47570
48107
|
id: `chat-status-${sessionId}-${Date.now()}`,
|
|
47571
48108
|
title,
|
|
47572
48109
|
body,
|
|
@@ -47580,7 +48117,7 @@ function createChatNotificationService(client) {
|
|
|
47580
48117
|
listeners2.add(listener);
|
|
47581
48118
|
return () => listeners2.delete(listener);
|
|
47582
48119
|
};
|
|
47583
|
-
notifications.onAction(({ action, data, reply }) => {
|
|
48120
|
+
client.notifications.onAction(({ action, data, reply }) => {
|
|
47584
48121
|
if (data?.sessionId && ["chat_message", "chat_status"].includes(data.kind)) {
|
|
47585
48122
|
emit2({ type: action === "reply" ? "reply" : action, action, sessionId: data.sessionId, reply: reply || "", data });
|
|
47586
48123
|
}
|
|
@@ -48591,6 +49128,20 @@ async function getGoogleModule() {
|
|
|
48591
49128
|
}
|
|
48592
49129
|
return googleModule;
|
|
48593
49130
|
}
|
|
49131
|
+
var facebookModule = null;
|
|
49132
|
+
async function getFacebookModule() {
|
|
49133
|
+
if (!facebookModule) {
|
|
49134
|
+
facebookModule = await Promise.resolve().then(() => (init_useFacebookAuth(), useFacebookAuth_exports));
|
|
49135
|
+
}
|
|
49136
|
+
return facebookModule;
|
|
49137
|
+
}
|
|
49138
|
+
var metaModule = null;
|
|
49139
|
+
async function getMetaModule() {
|
|
49140
|
+
if (!metaModule) {
|
|
49141
|
+
metaModule = await Promise.resolve().then(() => (init_useMetaAuth(), useMetaAuth_exports));
|
|
49142
|
+
}
|
|
49143
|
+
return metaModule;
|
|
49144
|
+
}
|
|
48594
49145
|
var TevrocError = class extends Error {
|
|
48595
49146
|
constructor(message2, options = {}) {
|
|
48596
49147
|
super(message2);
|
|
@@ -48653,10 +49204,12 @@ function createChatbotClient(options = {}) {
|
|
|
48653
49204
|
var TevrocClient = class {
|
|
48654
49205
|
constructor(options = {}) {
|
|
48655
49206
|
const baseUrl = options.baseUrl ?? options.url;
|
|
48656
|
-
const serviceUrl = options.serviceUrl ?? options.url;
|
|
49207
|
+
const serviceUrl = options.serviceUrl ?? options.url ?? baseUrl;
|
|
49208
|
+
const vpsUrl = options.vpsUrl ?? serviceUrl;
|
|
48657
49209
|
if (!baseUrl) throw new TypeError("createClient requires a baseUrl");
|
|
48658
49210
|
this.baseUrl = normalizeBaseUrl(baseUrl);
|
|
48659
49211
|
this.serviceUrl = normalizeBaseUrl(serviceUrl);
|
|
49212
|
+
this.vpsUrl = normalizeBaseUrl(vpsUrl);
|
|
48660
49213
|
this.appId = options.appId;
|
|
48661
49214
|
this.appName = options.appName;
|
|
48662
49215
|
this.payAccount = options.payAccount ?? "default";
|
|
@@ -49003,6 +49556,7 @@ function createAuthApi(client) {
|
|
|
49003
49556
|
// base44
|
|
49004
49557
|
loginWithProvider: async (provider, redirectTo, setToken = async () => {
|
|
49005
49558
|
}) => {
|
|
49559
|
+
console.log(client, "loginWithProvider called", { provider, redirectTo });
|
|
49006
49560
|
if (provider === "google") {
|
|
49007
49561
|
const { createGoogleLogin: createGoogleLogin2, subscribeGoogleLogin: subscribeGoogleLogin2 } = await getGoogleModule();
|
|
49008
49562
|
debugLog2(client, {
|
|
@@ -49010,7 +49564,7 @@ function createAuthApi(client) {
|
|
|
49010
49564
|
appId: client.appId,
|
|
49011
49565
|
appName: client.appName
|
|
49012
49566
|
});
|
|
49013
|
-
createGoogleLogin2({
|
|
49567
|
+
await createGoogleLogin2({
|
|
49014
49568
|
serviceUrl: client.serviceUrl,
|
|
49015
49569
|
appId: client.appId,
|
|
49016
49570
|
appName: client.appName
|
|
@@ -49032,12 +49586,100 @@ function createAuthApi(client) {
|
|
|
49032
49586
|
});
|
|
49033
49587
|
}
|
|
49034
49588
|
}
|
|
49589
|
+
if (provider === "facebook") {
|
|
49590
|
+
const { createFacebookLogin: createFacebookLogin2, subscribeFacebookLogin: subscribeFacebookLogin2 } = await getFacebookModule();
|
|
49591
|
+
debugLog2(client, {
|
|
49592
|
+
serviceUrl: client.serviceUrl,
|
|
49593
|
+
appId: client.appId,
|
|
49594
|
+
appName: client.appName
|
|
49595
|
+
});
|
|
49596
|
+
if (redirectTo) {
|
|
49597
|
+
const unsub = subscribeFacebookLogin2(async (user, err) => {
|
|
49598
|
+
debugLog2(client, "Facebook callback:", user, err);
|
|
49599
|
+
unsub();
|
|
49600
|
+
if (!user) return;
|
|
49601
|
+
const result = await client.request("/auth/facebook", {
|
|
49602
|
+
method: "POST",
|
|
49603
|
+
body: buildAuthPayload({ accessToken: user.accessToken }, client),
|
|
49604
|
+
auth: false
|
|
49605
|
+
});
|
|
49606
|
+
debugLog2(client, result);
|
|
49607
|
+
await setToken(result.token, result.user);
|
|
49608
|
+
debugLog2(client, "Redirecting to:", redirectTo);
|
|
49609
|
+
window.location.href = redirectTo;
|
|
49610
|
+
});
|
|
49611
|
+
try {
|
|
49612
|
+
await createFacebookLogin2({
|
|
49613
|
+
serviceUrl: client.serviceUrl,
|
|
49614
|
+
appId: client.appId,
|
|
49615
|
+
appName: client.appName
|
|
49616
|
+
});
|
|
49617
|
+
} catch (error) {
|
|
49618
|
+
unsub();
|
|
49619
|
+
throw error;
|
|
49620
|
+
}
|
|
49621
|
+
} else {
|
|
49622
|
+
await createFacebookLogin2({
|
|
49623
|
+
serviceUrl: client.serviceUrl,
|
|
49624
|
+
appId: client.appId,
|
|
49625
|
+
appName: client.appName
|
|
49626
|
+
});
|
|
49627
|
+
}
|
|
49628
|
+
}
|
|
49629
|
+
if (provider === "meta") {
|
|
49630
|
+
const { createMetaLogin: createMetaLogin2, subscribeMetaLogin: subscribeMetaLogin2 } = await getMetaModule();
|
|
49631
|
+
debugLog2(client, {
|
|
49632
|
+
serviceUrl: client.serviceUrl,
|
|
49633
|
+
appId: client.appId,
|
|
49634
|
+
appName: client.appName
|
|
49635
|
+
});
|
|
49636
|
+
if (redirectTo) {
|
|
49637
|
+
const unsub = subscribeMetaLogin2(async (user, err) => {
|
|
49638
|
+
debugLog2(client, "Meta callback:", user, err);
|
|
49639
|
+
unsub();
|
|
49640
|
+
if (!user) return;
|
|
49641
|
+
const result = await client.request("/auth/meta", {
|
|
49642
|
+
method: "POST",
|
|
49643
|
+
body: buildAuthPayload({ accessToken: user.accessToken }, client),
|
|
49644
|
+
auth: false
|
|
49645
|
+
});
|
|
49646
|
+
debugLog2(client, result);
|
|
49647
|
+
await setToken(result.token, result.user);
|
|
49648
|
+
debugLog2(client, "Redirecting to:", redirectTo);
|
|
49649
|
+
window.location.href = redirectTo;
|
|
49650
|
+
});
|
|
49651
|
+
try {
|
|
49652
|
+
await createMetaLogin2({
|
|
49653
|
+
serviceUrl: client.serviceUrl,
|
|
49654
|
+
appId: client.appId,
|
|
49655
|
+
appName: client.appName
|
|
49656
|
+
});
|
|
49657
|
+
} catch (error) {
|
|
49658
|
+
unsub();
|
|
49659
|
+
throw error;
|
|
49660
|
+
}
|
|
49661
|
+
} else {
|
|
49662
|
+
await createMetaLogin2({
|
|
49663
|
+
serviceUrl: client.serviceUrl,
|
|
49664
|
+
appId: client.appId,
|
|
49665
|
+
appName: client.appName
|
|
49666
|
+
});
|
|
49667
|
+
}
|
|
49668
|
+
}
|
|
49035
49669
|
},
|
|
49036
49670
|
// extra
|
|
49037
49671
|
googleLogin: (params) => createGoogleLogin(params),
|
|
49038
49672
|
onGoogleLogin: (callback) => {
|
|
49039
49673
|
return subscribeGoogleLogin(callback);
|
|
49040
49674
|
},
|
|
49675
|
+
facebookLogin: (params) => createFacebookLogin(params),
|
|
49676
|
+
onFacebookLogin: (callback) => {
|
|
49677
|
+
return subscribeFacebookLogin(callback);
|
|
49678
|
+
},
|
|
49679
|
+
metaLogin: (params) => createMetaLogin(params),
|
|
49680
|
+
onMetaLogin: (callback) => {
|
|
49681
|
+
return subscribeMetaLogin(callback);
|
|
49682
|
+
},
|
|
49041
49683
|
//
|
|
49042
49684
|
async login(input) {
|
|
49043
49685
|
const body = buildAuthPayload(input, client);
|
|
@@ -49045,6 +49687,33 @@ function createAuthApi(client) {
|
|
|
49045
49687
|
if (result.token) client.setToken(result.token);
|
|
49046
49688
|
return result;
|
|
49047
49689
|
},
|
|
49690
|
+
async loginWithGoogle(input) {
|
|
49691
|
+
const result = await client.request("/auth/google", {
|
|
49692
|
+
method: "POST",
|
|
49693
|
+
body: buildAuthPayload(input, client),
|
|
49694
|
+
auth: false
|
|
49695
|
+
});
|
|
49696
|
+
if (result.token) client.setToken(result.token);
|
|
49697
|
+
return result;
|
|
49698
|
+
},
|
|
49699
|
+
async loginWithFacebook(input) {
|
|
49700
|
+
const result = await client.request("/auth/facebook", {
|
|
49701
|
+
method: "POST",
|
|
49702
|
+
body: buildAuthPayload(input, client),
|
|
49703
|
+
auth: false
|
|
49704
|
+
});
|
|
49705
|
+
if (result.token) client.setToken(result.token);
|
|
49706
|
+
return result;
|
|
49707
|
+
},
|
|
49708
|
+
async loginWithMeta(input) {
|
|
49709
|
+
const result = await client.request("/auth/meta", {
|
|
49710
|
+
method: "POST",
|
|
49711
|
+
body: buildAuthPayload(input, client),
|
|
49712
|
+
auth: false
|
|
49713
|
+
});
|
|
49714
|
+
if (result.token) client.setToken(result.token);
|
|
49715
|
+
return result;
|
|
49716
|
+
},
|
|
49048
49717
|
async logout() {
|
|
49049
49718
|
const result = await client.request("/auth/logout", { method: "POST", body: buildAuthPayload({}, client) });
|
|
49050
49719
|
client.clearToken();
|
|
@@ -49636,29 +50305,6 @@ function base64ToBlob(base64, contentType = "application/octet-stream") {
|
|
|
49636
50305
|
}
|
|
49637
50306
|
return new Blob([bytes], { type: contentType });
|
|
49638
50307
|
}
|
|
49639
|
-
function arrayBufferToBase64(buffer) {
|
|
49640
|
-
let binary = "";
|
|
49641
|
-
const bytes = new Uint8Array(buffer);
|
|
49642
|
-
const chunkSize = 32768;
|
|
49643
|
-
for (let i = 0; i < bytes.length; i += chunkSize) {
|
|
49644
|
-
const chunk = bytes.subarray(i, i + chunkSize);
|
|
49645
|
-
binary += String.fromCharCode.apply(null, chunk);
|
|
49646
|
-
}
|
|
49647
|
-
return btoa(binary);
|
|
49648
|
-
}
|
|
49649
|
-
async function normalizeUploadBody(file) {
|
|
49650
|
-
if (typeof Blob !== "undefined" && file instanceof Blob) {
|
|
49651
|
-
return { data: await blobToBase643(file), contentType: file.type || "application/octet-stream", bodyIsBase64: true };
|
|
49652
|
-
}
|
|
49653
|
-
if (file && typeof file.arrayBuffer === "function") {
|
|
49654
|
-
const buffer = await file.arrayBuffer();
|
|
49655
|
-
return { data: arrayBufferToBase64(buffer), contentType: "application/octet-stream", bodyIsBase64: true };
|
|
49656
|
-
}
|
|
49657
|
-
if (typeof file === "string") {
|
|
49658
|
-
return { data: file, contentType: "text/plain", bodyIsBase64: false };
|
|
49659
|
-
}
|
|
49660
|
-
return { data: JSON.stringify(file), contentType: "application/json", bodyIsBase64: false };
|
|
49661
|
-
}
|
|
49662
50308
|
function createFileApi(client) {
|
|
49663
50309
|
return {
|
|
49664
50310
|
url: async (key) => {
|
|
@@ -49794,34 +50440,174 @@ function createFileApi(client) {
|
|
|
49794
50440
|
};
|
|
49795
50441
|
}
|
|
49796
50442
|
async function upload(client, path, file, options = {}) {
|
|
49797
|
-
const
|
|
49798
|
-
if (
|
|
49799
|
-
|
|
49800
|
-
|
|
49801
|
-
|
|
49802
|
-
|
|
49803
|
-
|
|
49804
|
-
|
|
49805
|
-
|
|
49806
|
-
|
|
50443
|
+
const isElectron = await detectElectronEnvironment(client);
|
|
50444
|
+
if (isElectron) {
|
|
50445
|
+
return uploadViaElectronBridge(client, file, options);
|
|
50446
|
+
}
|
|
50447
|
+
return uploadViaGoogleStorage(client, file, { ...options, path });
|
|
50448
|
+
}
|
|
50449
|
+
async function detectElectronEnvironment(client) {
|
|
50450
|
+
try {
|
|
50451
|
+
const serviceUrl = String(client?.serviceUrl || "").replace(/\/$/, "");
|
|
50452
|
+
const response = await client.fetch(`${serviceUrl}/api/environment`, {
|
|
50453
|
+
method: "GET",
|
|
50454
|
+
headers: { Accept: "application/json" },
|
|
50455
|
+
cache: "no-store"
|
|
50456
|
+
});
|
|
50457
|
+
if (response && response.ok) {
|
|
50458
|
+
const data = await response.json();
|
|
50459
|
+
if (data && typeof data === "object" && "isElectron" in data) {
|
|
50460
|
+
return Boolean(data.isElectron);
|
|
50461
|
+
}
|
|
50462
|
+
}
|
|
50463
|
+
} catch (error) {
|
|
50464
|
+
console.debug("[tevrocsdk][env] /api/environment fallback", error);
|
|
50465
|
+
}
|
|
50466
|
+
if (typeof navigator !== "undefined") {
|
|
50467
|
+
const userAgent = navigator.userAgent || "";
|
|
50468
|
+
if (/electron/i.test(userAgent)) return true;
|
|
50469
|
+
}
|
|
50470
|
+
if (typeof window !== "undefined") {
|
|
50471
|
+
const bridge = window?.bridge || window?.electronBridge || window?.nativeBridge;
|
|
50472
|
+
if (bridge) return true;
|
|
50473
|
+
if (window.process && window.process.versions && window.process.versions.electron) return true;
|
|
50474
|
+
}
|
|
50475
|
+
return false;
|
|
50476
|
+
}
|
|
50477
|
+
async function uploadViaElectronBridge(client, file, options = {}) {
|
|
50478
|
+
const fileName = options.filename || "upload";
|
|
50479
|
+
const contentType = options.contentType || "application/octet-stream";
|
|
50480
|
+
const resolvedFile = file instanceof Blob ? file : new Blob([String(file ?? "")], { type: contentType });
|
|
50481
|
+
const dataUrl = resolvedFile instanceof Blob ? `data:${contentType};base64,${await blobToBase643(resolvedFile)}` : String(file);
|
|
50482
|
+
const packetSize = options.packetSize || 1024 * 1024;
|
|
50483
|
+
const packets = [];
|
|
50484
|
+
for (let offset2 = 0; offset2 < dataUrl.length; offset2 += packetSize) {
|
|
50485
|
+
const packetData2 = dataUrl.slice(offset2, offset2 + packetSize);
|
|
50486
|
+
packets.push({
|
|
50487
|
+
packetId: packets.length,
|
|
50488
|
+
packetData: encodeURIComponent(packetData2),
|
|
50489
|
+
isLastPacket: offset2 + packetSize >= dataUrl.length,
|
|
50490
|
+
filePanaroma: options.filePanaroma || "NO"
|
|
50491
|
+
});
|
|
50492
|
+
}
|
|
50493
|
+
if (!packets.length) throw new TevrocError("Cannot upload an empty file", { code: "empty_file" });
|
|
50494
|
+
let clientId = "";
|
|
50495
|
+
const endpoint = `${client.serviceUrl.replace(/\/$/, "")}/receivePacket`;
|
|
50496
|
+
for (const packet of packets) {
|
|
50497
|
+
const payload = {
|
|
50498
|
+
...packet,
|
|
50499
|
+
clientId,
|
|
50500
|
+
tableName: options.tableName || "",
|
|
50501
|
+
tableIdx: options.tableIdx ?? "",
|
|
50502
|
+
tableGallery: options.gallery === true || options.gallery === "YES",
|
|
50503
|
+
fileName,
|
|
50504
|
+
fileSize: resolvedFile.size,
|
|
50505
|
+
fileMime: contentType,
|
|
50506
|
+
server: options.server || "test",
|
|
50507
|
+
session: options.session || client.token || ""
|
|
50508
|
+
};
|
|
50509
|
+
let result;
|
|
50510
|
+
const bridge = typeof window !== "undefined" ? window : null;
|
|
50511
|
+
if (bridge && typeof bridge.syncRequest === "function") {
|
|
50512
|
+
const rawResult = bridge.syncRequest(endpoint, "POST", payload);
|
|
50513
|
+
if (!rawResult) throw new TevrocError("Electron upload failed", { code: "electron_upload_failed" });
|
|
50514
|
+
try {
|
|
50515
|
+
result = JSON.parse(rawResult);
|
|
50516
|
+
} catch (error) {
|
|
50517
|
+
throw new TevrocError("Electron upload returned invalid JSON", { code: "electron_upload_failed" });
|
|
50518
|
+
}
|
|
50519
|
+
} else {
|
|
50520
|
+
const response = await client.fetch(endpoint, {
|
|
49807
50521
|
method: "POST",
|
|
49808
|
-
headers,
|
|
49809
|
-
body:
|
|
49810
|
-
|
|
49811
|
-
|
|
49812
|
-
|
|
49813
|
-
|
|
49814
|
-
}
|
|
49815
|
-
|
|
49816
|
-
debugLog2(client, "[tevrocsdk][files] upload queued offline", { path, id, queued });
|
|
49817
|
-
return queued;
|
|
50522
|
+
headers: { "Content-Type": "application/json", Accept: "application/json" },
|
|
50523
|
+
body: JSON.stringify(payload)
|
|
50524
|
+
});
|
|
50525
|
+
if (!response.ok) {
|
|
50526
|
+
const text = await response.text();
|
|
50527
|
+
throw new TevrocError(text || "Electron upload failed", { status: response.status, code: "electron_upload_failed" });
|
|
50528
|
+
}
|
|
50529
|
+
result = await response.json();
|
|
49818
50530
|
}
|
|
50531
|
+
clientId = result.clientId || clientId;
|
|
50532
|
+
if (typeof options.onProgress === "function") {
|
|
50533
|
+
options.onProgress({ uploaded: Math.min(offset + packetData.length, dataUrl.length), total: dataUrl.length, progress: Math.round((offset + packetData.length) / dataUrl.length * 100) });
|
|
50534
|
+
}
|
|
50535
|
+
}
|
|
50536
|
+
return { success: true, clientId, fileName, fileSize: resolvedFile.size, runtime: "electron" };
|
|
50537
|
+
}
|
|
50538
|
+
async function uploadViaGoogleStorage(client, file, options = {}) {
|
|
50539
|
+
const contentType = options.contentType || "application/octet-stream";
|
|
50540
|
+
const fileName = options.filename || "upload";
|
|
50541
|
+
const body = file instanceof Blob ? file : new Blob([String(file ?? "")], { type: contentType });
|
|
50542
|
+
const serviceUrl = client.serviceUrl.replace(/\/$/, "");
|
|
50543
|
+
const initResponse = await client.fetch(`${serviceUrl}/api/uploads/create`, {
|
|
50544
|
+
method: "POST",
|
|
50545
|
+
headers: {
|
|
50546
|
+
"Content-Type": "application/json",
|
|
50547
|
+
Accept: "application/json"
|
|
50548
|
+
},
|
|
50549
|
+
body: JSON.stringify({
|
|
50550
|
+
filename: fileName,
|
|
50551
|
+
contentType,
|
|
50552
|
+
size: body.size,
|
|
50553
|
+
userId: options.userId || "anon"
|
|
50554
|
+
})
|
|
50555
|
+
});
|
|
50556
|
+
if (!initResponse.ok) {
|
|
50557
|
+
const text = await initResponse.text();
|
|
50558
|
+
throw new TevrocError(text || "Create upload session failed", { status: initResponse.status, code: "gcs_create_failed" });
|
|
50559
|
+
}
|
|
50560
|
+
const init = await initResponse.json();
|
|
50561
|
+
const uploadUrl = init && init.uploadUrl ? init.uploadUrl : null;
|
|
50562
|
+
const uploadId = init && init.uploadId ? init.uploadId : null;
|
|
50563
|
+
if (!uploadUrl || !uploadId) {
|
|
50564
|
+
throw new TevrocError("Google storage upload session is missing uploadUrl or uploadId", { code: "gcs_invalid_session" });
|
|
50565
|
+
}
|
|
50566
|
+
const chunkSize = options.chunkSize || 10 * 1024 * 1024;
|
|
50567
|
+
for (let offset2 = 0; offset2 < body.size; offset2 += chunkSize) {
|
|
50568
|
+
const end = Math.min(offset2 + chunkSize, body.size) - 1;
|
|
50569
|
+
let uploadResponse;
|
|
50570
|
+
for (let attempt = 1; attempt <= (options.retries || 5); attempt += 1) {
|
|
50571
|
+
try {
|
|
50572
|
+
uploadResponse = await client.fetch(uploadUrl, {
|
|
50573
|
+
method: "PUT",
|
|
50574
|
+
body: body.slice(offset2, end + 1),
|
|
50575
|
+
headers: {
|
|
50576
|
+
"Content-Length": String(end - offset2 + 1),
|
|
50577
|
+
"Content-Range": `bytes ${offset2}-${end}/${body.size}`,
|
|
50578
|
+
"Content-Type": contentType
|
|
50579
|
+
}
|
|
50580
|
+
});
|
|
50581
|
+
if (uploadResponse.ok || uploadResponse.status === 308) break;
|
|
50582
|
+
throw new Error(`HTTP ${uploadResponse.status}`);
|
|
50583
|
+
} catch (error) {
|
|
50584
|
+
if (attempt === (options.retries || 5)) throw new TevrocError(error.message, { code: "gcs_upload_failed" });
|
|
50585
|
+
await new Promise((resolve2) => setTimeout(resolve2, 1e3 * attempt));
|
|
50586
|
+
}
|
|
50587
|
+
}
|
|
50588
|
+
if (!uploadResponse || !uploadResponse.ok && uploadResponse.status !== 308) {
|
|
50589
|
+
throw new TevrocError("Google storage upload failed", { code: "gcs_upload_failed" });
|
|
50590
|
+
}
|
|
50591
|
+
if (typeof options.onProgress === "function") options.onProgress({ uploaded: end + 1, total: body.size, progress: Math.round((end + 1) / body.size * 100) });
|
|
49819
50592
|
}
|
|
49820
|
-
|
|
49821
|
-
|
|
50593
|
+
const finalizeResponse = await client.fetch(`${serviceUrl}/api/uploads/${encodeURIComponent(uploadId)}/complete`, {
|
|
50594
|
+
method: "POST",
|
|
50595
|
+
headers: { "Content-Type": "application/json", Accept: "application/json" },
|
|
50596
|
+
body: JSON.stringify({ storageKey: init.storageKey, userId: options.userId || "anon" })
|
|
50597
|
+
});
|
|
50598
|
+
if (!finalizeResponse.ok) {
|
|
50599
|
+
const text = await finalizeResponse.text();
|
|
50600
|
+
throw new TevrocError(text || "Finalize upload failed", { status: finalizeResponse.status, code: "gcs_finalize_failed" });
|
|
50601
|
+
}
|
|
50602
|
+
const result = await finalizeResponse.json();
|
|
50603
|
+
if (options.tableName && options.tableIdx !== void 0) {
|
|
50604
|
+
await client.fetch(`${serviceUrl}/api/files/gcs-store`, {
|
|
50605
|
+
method: "POST",
|
|
50606
|
+
headers: { "Content-Type": "application/json", Accept: "application/json" },
|
|
50607
|
+
body: JSON.stringify({ storageKey: result.storageKey || init.storageKey, tableName: options.tableName, tableIdx: options.tableIdx, fileName, fileSize: body.size, fileMime: contentType, gallery: options.gallery ? "YES" : "NO", filePanaroma: options.filePanaroma || "NO" })
|
|
50608
|
+
});
|
|
49822
50609
|
}
|
|
49823
|
-
|
|
49824
|
-
return result;
|
|
50610
|
+
return { ...result, runtime: "gcs" };
|
|
49825
50611
|
}
|
|
49826
50612
|
async function parseResponse(response, parseAs) {
|
|
49827
50613
|
if (parseAs === "response") return response;
|