tevrocsdk 0.1.81 → 0.1.83
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 +6 -2
- package/tevroc-sdk.cjs.js +1221 -322
- package/tevroc-sdk.cjs.js.map +4 -4
- package/tevroc-sdk.esm.js +387 -154
- 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,131 +47782,6 @@ function createPdfApi() {
|
|
|
47243
47782
|
};
|
|
47244
47783
|
}
|
|
47245
47784
|
|
|
47246
|
-
// src/services/notifications.js
|
|
47247
|
-
var isBrowser = () => typeof window !== "undefined" && typeof Notification !== "undefined";
|
|
47248
|
-
function createNotificationService() {
|
|
47249
|
-
const listeners2 = /* @__PURE__ */ new Set();
|
|
47250
|
-
const scheduled = /* @__PURE__ */ new Map();
|
|
47251
|
-
let nativeListenerInstalled = false;
|
|
47252
|
-
const emit2 = (event) => listeners2.forEach((listener) => listener(event));
|
|
47253
|
-
const appPlugin = () => globalThis?.Capacitor?.Plugins?.AppNotifications;
|
|
47254
|
-
const installNativeListener = () => {
|
|
47255
|
-
if (nativeListenerInstalled) return;
|
|
47256
|
-
const plugin = appPlugin();
|
|
47257
|
-
if (!plugin?.addListener) return;
|
|
47258
|
-
nativeListenerInstalled = true;
|
|
47259
|
-
plugin.addListener("notificationAction", (event) => {
|
|
47260
|
-
let data = event?.data || {};
|
|
47261
|
-
if (typeof data === "string") {
|
|
47262
|
-
try {
|
|
47263
|
-
data = JSON.parse(data);
|
|
47264
|
-
} catch {
|
|
47265
|
-
data = {};
|
|
47266
|
-
}
|
|
47267
|
-
}
|
|
47268
|
-
emit2({
|
|
47269
|
-
id: event?.id,
|
|
47270
|
-
action: event?.action || "open",
|
|
47271
|
-
reply: event?.reply || "",
|
|
47272
|
-
data,
|
|
47273
|
-
platform: "capacitor"
|
|
47274
|
-
});
|
|
47275
|
-
});
|
|
47276
|
-
plugin.consumePendingAction?.().catch?.(() => {
|
|
47277
|
-
});
|
|
47278
|
-
};
|
|
47279
|
-
const permission = async () => {
|
|
47280
|
-
const plugin = appPlugin();
|
|
47281
|
-
if (plugin?.checkPermissions) return plugin.checkPermissions();
|
|
47282
|
-
if (globalThis?.__TAURI_INTERNALS__) {
|
|
47283
|
-
try {
|
|
47284
|
-
const tauri = await new Function("name", "return import(name)")("@tauri-apps/plugin-notification");
|
|
47285
|
-
return { display: await tauri.isPermissionGranted() ? "granted" : "prompt" };
|
|
47286
|
-
} catch {
|
|
47287
|
-
return { display: "denied" };
|
|
47288
|
-
}
|
|
47289
|
-
}
|
|
47290
|
-
return { display: isBrowser() ? Notification.permission : "denied" };
|
|
47291
|
-
};
|
|
47292
|
-
const requestPermission = async () => {
|
|
47293
|
-
const plugin = appPlugin();
|
|
47294
|
-
if (plugin?.requestPermissions) return plugin.requestPermissions();
|
|
47295
|
-
if (globalThis?.__TAURI_INTERNALS__) {
|
|
47296
|
-
try {
|
|
47297
|
-
const tauri = await new Function("name", "return import(name)")("@tauri-apps/plugin-notification");
|
|
47298
|
-
return { display: await tauri.requestPermission() };
|
|
47299
|
-
} catch {
|
|
47300
|
-
return { display: "denied" };
|
|
47301
|
-
}
|
|
47302
|
-
}
|
|
47303
|
-
return { display: isBrowser() ? await Notification.requestPermission() : "denied" };
|
|
47304
|
-
};
|
|
47305
|
-
const show = async (options = {}) => {
|
|
47306
|
-
const id = String(options.id || `notification_${Date.now()}_${Math.random().toString(36).slice(2)}`);
|
|
47307
|
-
const request = {
|
|
47308
|
-
id,
|
|
47309
|
-
title: options.title || "Notification",
|
|
47310
|
-
body: options.body || "",
|
|
47311
|
-
data: options.data || {},
|
|
47312
|
-
actions: options.actions || [],
|
|
47313
|
-
silent: Boolean(options.silent),
|
|
47314
|
-
channel: options.channel || "general",
|
|
47315
|
-
style: options.style || {}
|
|
47316
|
-
};
|
|
47317
|
-
const plugin = appPlugin();
|
|
47318
|
-
if (plugin?.show) {
|
|
47319
|
-
installNativeListener();
|
|
47320
|
-
await plugin.show(request);
|
|
47321
|
-
return { id, platform: "capacitor" };
|
|
47322
|
-
}
|
|
47323
|
-
if (globalThis?.__TAURI_INTERNALS__) {
|
|
47324
|
-
try {
|
|
47325
|
-
const tauri = await new Function("name", "return import(name)")("@tauri-apps/plugin-notification");
|
|
47326
|
-
const current = await tauri.isPermissionGranted() ? "granted" : await tauri.requestPermission();
|
|
47327
|
-
if (current === "granted") {
|
|
47328
|
-
tauri.sendNotification({ title: request.title, body: request.body, extra: request.data });
|
|
47329
|
-
return { id, platform: "tauri" };
|
|
47330
|
-
}
|
|
47331
|
-
} catch {
|
|
47332
|
-
}
|
|
47333
|
-
}
|
|
47334
|
-
if (!isBrowser()) throw new Error("Notifications are not supported on this platform.");
|
|
47335
|
-
const state = Notification.permission === "default" ? await Notification.requestPermission() : Notification.permission;
|
|
47336
|
-
if (state !== "granted") throw new Error("Notification permission was not granted.");
|
|
47337
|
-
const notification = new Notification(request.title, { body: request.body, tag: id, data: request.data, silent: request.silent });
|
|
47338
|
-
notification.onclick = () => emit2({ id, action: "open", data: request.data, platform: "web" });
|
|
47339
|
-
return { id, platform: "web", notification };
|
|
47340
|
-
};
|
|
47341
|
-
const schedule = async (options = {}) => {
|
|
47342
|
-
const at = new Date(options.at || Date.now()).getTime();
|
|
47343
|
-
const delay = Math.max(0, at - Date.now());
|
|
47344
|
-
const id = String(options.id || `notification_${at}_${Math.random().toString(36).slice(2)}`);
|
|
47345
|
-
const timeout = setTimeout(() => {
|
|
47346
|
-
scheduled.delete(id);
|
|
47347
|
-
show({ ...options, id }).catch((error) => emit2({ type: "error", error }));
|
|
47348
|
-
}, delay);
|
|
47349
|
-
scheduled.set(id, timeout);
|
|
47350
|
-
return { id, at };
|
|
47351
|
-
};
|
|
47352
|
-
const cancel = async (id) => {
|
|
47353
|
-
const timeout = scheduled.get(String(id));
|
|
47354
|
-
if (timeout) clearTimeout(timeout);
|
|
47355
|
-
scheduled.delete(String(id));
|
|
47356
|
-
await appPlugin()?.cancel?.({ id: String(id) });
|
|
47357
|
-
};
|
|
47358
|
-
const cancelAll = async () => {
|
|
47359
|
-
for (const timeout of scheduled.values()) clearTimeout(timeout);
|
|
47360
|
-
scheduled.clear();
|
|
47361
|
-
await appPlugin()?.cancelAll?.();
|
|
47362
|
-
};
|
|
47363
|
-
const onAction = (listener) => {
|
|
47364
|
-
installNativeListener();
|
|
47365
|
-
listeners2.add(listener);
|
|
47366
|
-
return () => listeners2.delete(listener);
|
|
47367
|
-
};
|
|
47368
|
-
return { permission, requestPermission, show, schedule, cancel, cancelAll, onAction };
|
|
47369
|
-
}
|
|
47370
|
-
|
|
47371
47785
|
// src/services/agentNotifications.js
|
|
47372
47786
|
var toList = (result) => Array.isArray(result) ? result : result?.data || [];
|
|
47373
47787
|
var latestByTime = (records) => [...records].sort((a, b) => {
|
|
@@ -47376,7 +47790,6 @@ var latestByTime = (records) => [...records].sort((a, b) => {
|
|
|
47376
47790
|
return right - left;
|
|
47377
47791
|
})[0] || null;
|
|
47378
47792
|
function createAgentNotificationService(client) {
|
|
47379
|
-
const notifications = client.notifications || createNotificationService();
|
|
47380
47793
|
let timer = null;
|
|
47381
47794
|
let stopped = true;
|
|
47382
47795
|
const seen = /* @__PURE__ */ new Map();
|
|
@@ -47457,7 +47870,7 @@ function createAgentNotificationService(client) {
|
|
|
47457
47870
|
if (action === "reject") return reject(session);
|
|
47458
47871
|
if (action === "reply") return reply(session, text);
|
|
47459
47872
|
};
|
|
47460
|
-
const showNative = (request) => notifications.show({
|
|
47873
|
+
const showNative = (request) => client.notifications.show({
|
|
47461
47874
|
id: `agent-request-${request.sessionId}`,
|
|
47462
47875
|
title: request.title,
|
|
47463
47876
|
body: request.body,
|
|
@@ -47536,7 +47949,7 @@ function createAgentNotificationService(client) {
|
|
|
47536
47949
|
listeners2.add(listener);
|
|
47537
47950
|
return () => listeners2.delete(listener);
|
|
47538
47951
|
};
|
|
47539
|
-
notifications.onAction(({ action, data, reply: text }) => {
|
|
47952
|
+
client.notifications.onAction(({ action, data, reply: text }) => {
|
|
47540
47953
|
if (data?.sessionId && String(data.kind || "").startsWith("agent_")) {
|
|
47541
47954
|
dispatchAction({ action, sessionId: data.sessionId, reply: text }).catch((error) => notify({ type: "error", error }));
|
|
47542
47955
|
}
|
|
@@ -47544,14 +47957,138 @@ function createAgentNotificationService(client) {
|
|
|
47544
47957
|
return { start, stop, check, onEvent, accept, reject, reply, dispatchAction };
|
|
47545
47958
|
}
|
|
47546
47959
|
|
|
47960
|
+
// src/services/notifications.js
|
|
47961
|
+
var isBrowser = () => typeof window !== "undefined" && typeof Notification !== "undefined";
|
|
47962
|
+
function createNotificationService() {
|
|
47963
|
+
const listeners2 = /* @__PURE__ */ new Set();
|
|
47964
|
+
const scheduled = /* @__PURE__ */ new Map();
|
|
47965
|
+
let nativeListenerInstalled = false;
|
|
47966
|
+
const emit2 = (event) => listeners2.forEach((listener) => listener(event));
|
|
47967
|
+
const appPlugin = () => globalThis?.Capacitor?.Plugins?.AppNotifications;
|
|
47968
|
+
const installNativeListener = () => {
|
|
47969
|
+
if (nativeListenerInstalled) return;
|
|
47970
|
+
const plugin = appPlugin();
|
|
47971
|
+
if (!plugin?.addListener) return;
|
|
47972
|
+
nativeListenerInstalled = true;
|
|
47973
|
+
plugin.addListener("notificationAction", (event) => {
|
|
47974
|
+
let data = event?.data || {};
|
|
47975
|
+
if (typeof data === "string") {
|
|
47976
|
+
try {
|
|
47977
|
+
data = JSON.parse(data);
|
|
47978
|
+
} catch {
|
|
47979
|
+
data = {};
|
|
47980
|
+
}
|
|
47981
|
+
}
|
|
47982
|
+
emit2({
|
|
47983
|
+
id: event?.id,
|
|
47984
|
+
action: event?.action || "open",
|
|
47985
|
+
reply: event?.reply || "",
|
|
47986
|
+
data,
|
|
47987
|
+
platform: "capacitor"
|
|
47988
|
+
});
|
|
47989
|
+
});
|
|
47990
|
+
plugin.consumePendingAction?.().catch?.(() => {
|
|
47991
|
+
});
|
|
47992
|
+
};
|
|
47993
|
+
const permission = async () => {
|
|
47994
|
+
const plugin = appPlugin();
|
|
47995
|
+
if (plugin?.checkPermissions) return plugin.checkPermissions();
|
|
47996
|
+
if (globalThis?.__TAURI_INTERNALS__) {
|
|
47997
|
+
try {
|
|
47998
|
+
const tauri = await new Function("name", "return import(name)")("@tauri-apps/plugin-notification");
|
|
47999
|
+
return { display: await tauri.isPermissionGranted() ? "granted" : "prompt" };
|
|
48000
|
+
} catch {
|
|
48001
|
+
return { display: "denied" };
|
|
48002
|
+
}
|
|
48003
|
+
}
|
|
48004
|
+
return { display: isBrowser() ? Notification.permission : "denied" };
|
|
48005
|
+
};
|
|
48006
|
+
const requestPermission = async () => {
|
|
48007
|
+
const plugin = appPlugin();
|
|
48008
|
+
if (plugin?.requestPermissions) return plugin.requestPermissions();
|
|
48009
|
+
if (globalThis?.__TAURI_INTERNALS__) {
|
|
48010
|
+
try {
|
|
48011
|
+
const tauri = await new Function("name", "return import(name)")("@tauri-apps/plugin-notification");
|
|
48012
|
+
return { display: await tauri.requestPermission() };
|
|
48013
|
+
} catch {
|
|
48014
|
+
return { display: "denied" };
|
|
48015
|
+
}
|
|
48016
|
+
}
|
|
48017
|
+
return { display: isBrowser() ? await Notification.requestPermission() : "denied" };
|
|
48018
|
+
};
|
|
48019
|
+
const show = async (options = {}) => {
|
|
48020
|
+
const id = String(options.id || `notification_${Date.now()}_${Math.random().toString(36).slice(2)}`);
|
|
48021
|
+
const request = {
|
|
48022
|
+
id,
|
|
48023
|
+
title: options.title || "Notification",
|
|
48024
|
+
body: options.body || "",
|
|
48025
|
+
data: options.data || {},
|
|
48026
|
+
actions: options.actions || [],
|
|
48027
|
+
silent: Boolean(options.silent),
|
|
48028
|
+
channel: options.channel || "general",
|
|
48029
|
+
style: options.style || {}
|
|
48030
|
+
};
|
|
48031
|
+
const plugin = appPlugin();
|
|
48032
|
+
if (plugin?.show) {
|
|
48033
|
+
installNativeListener();
|
|
48034
|
+
await plugin.show(request);
|
|
48035
|
+
return { id, platform: "capacitor" };
|
|
48036
|
+
}
|
|
48037
|
+
if (globalThis?.__TAURI_INTERNALS__) {
|
|
48038
|
+
try {
|
|
48039
|
+
const tauri = await new Function("name", "return import(name)")("@tauri-apps/plugin-notification");
|
|
48040
|
+
const current = await tauri.isPermissionGranted() ? "granted" : await tauri.requestPermission();
|
|
48041
|
+
if (current === "granted") {
|
|
48042
|
+
tauri.sendNotification({ title: request.title, body: request.body, extra: request.data });
|
|
48043
|
+
return { id, platform: "tauri" };
|
|
48044
|
+
}
|
|
48045
|
+
} catch {
|
|
48046
|
+
}
|
|
48047
|
+
}
|
|
48048
|
+
if (!isBrowser()) throw new Error("Notifications are not supported on this platform.");
|
|
48049
|
+
const state = Notification.permission === "default" ? await Notification.requestPermission() : Notification.permission;
|
|
48050
|
+
if (state !== "granted") throw new Error("Notification permission was not granted.");
|
|
48051
|
+
const notification = new Notification(request.title, { body: request.body, tag: id, data: request.data, silent: request.silent });
|
|
48052
|
+
notification.onclick = () => emit2({ id, action: "open", data: request.data, platform: "web" });
|
|
48053
|
+
return { id, platform: "web", notification };
|
|
48054
|
+
};
|
|
48055
|
+
const schedule = async (options = {}) => {
|
|
48056
|
+
const at = new Date(options.at || Date.now()).getTime();
|
|
48057
|
+
const delay = Math.max(0, at - Date.now());
|
|
48058
|
+
const id = String(options.id || `notification_${at}_${Math.random().toString(36).slice(2)}`);
|
|
48059
|
+
const timeout = setTimeout(() => {
|
|
48060
|
+
scheduled.delete(id);
|
|
48061
|
+
show({ ...options, id }).catch((error) => emit2({ type: "error", error }));
|
|
48062
|
+
}, delay);
|
|
48063
|
+
scheduled.set(id, timeout);
|
|
48064
|
+
return { id, at };
|
|
48065
|
+
};
|
|
48066
|
+
const cancel = async (id) => {
|
|
48067
|
+
const timeout = scheduled.get(String(id));
|
|
48068
|
+
if (timeout) clearTimeout(timeout);
|
|
48069
|
+
scheduled.delete(String(id));
|
|
48070
|
+
await appPlugin()?.cancel?.({ id: String(id) });
|
|
48071
|
+
};
|
|
48072
|
+
const cancelAll = async () => {
|
|
48073
|
+
for (const timeout of scheduled.values()) clearTimeout(timeout);
|
|
48074
|
+
scheduled.clear();
|
|
48075
|
+
await appPlugin()?.cancelAll?.();
|
|
48076
|
+
};
|
|
48077
|
+
const onAction = (listener) => {
|
|
48078
|
+
installNativeListener();
|
|
48079
|
+
listeners2.add(listener);
|
|
48080
|
+
return () => listeners2.delete(listener);
|
|
48081
|
+
};
|
|
48082
|
+
return { permission, requestPermission, show, schedule, cancel, cancelAll, onAction };
|
|
48083
|
+
}
|
|
48084
|
+
|
|
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
|
}
|
|
@@ -48091,15 +48628,15 @@ async function downloadUrlToBase64(url) {
|
|
|
48091
48628
|
if (!url) return null;
|
|
48092
48629
|
if (!isNative) return null;
|
|
48093
48630
|
try {
|
|
48094
|
-
|
|
48631
|
+
debugLog(`[tevrocsdk][fileoffline] downloadUrlToBase64 fetching`, url);
|
|
48095
48632
|
const res = await fetch(url, { cache: "no-store" });
|
|
48096
48633
|
if (!res.ok) return null;
|
|
48097
48634
|
const b = await res.blob();
|
|
48098
48635
|
const base64 = await blobToBase642(b).catch(() => null);
|
|
48099
|
-
|
|
48636
|
+
debugLog(`[tevrocsdk][fileoffline] downloadUrlToBase64 fetched -> base64 length`, base64 ? base64.length : 0);
|
|
48100
48637
|
return base64;
|
|
48101
48638
|
} catch (e) {
|
|
48102
|
-
|
|
48639
|
+
debugWarn(`[tevrocsdk][fileoffline] downloadUrlToBase64 failed`, e);
|
|
48103
48640
|
return null;
|
|
48104
48641
|
}
|
|
48105
48642
|
}
|
|
@@ -48117,34 +48654,34 @@ function deriveKeyFromUrl(url) {
|
|
|
48117
48654
|
async function persistFileToNative(client, key, base64, contentType) {
|
|
48118
48655
|
try {
|
|
48119
48656
|
if (!isNative) return false;
|
|
48120
|
-
|
|
48657
|
+
debugLog("[tevrocsdk][fileoffline] persistFileToNative", { key, contentType, hasBase64: !!base64 });
|
|
48121
48658
|
if (!client?.native?.store || !base64) {
|
|
48122
|
-
|
|
48659
|
+
debugWarn("[tevrocsdk][fileoffline] persistFileToNative skipped - missing native.store or base64");
|
|
48123
48660
|
return false;
|
|
48124
48661
|
}
|
|
48125
48662
|
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
48126
48663
|
await client.native.store.set(`downloaded_files/${key}`, { data: base64, contentType: contentType || "application/octet-stream", key, updatedAt: now });
|
|
48127
|
-
|
|
48664
|
+
debugLog("[tevrocsdk][fileoffline] persistFileToNative stored", { key, updatedAt: now });
|
|
48128
48665
|
return true;
|
|
48129
48666
|
} catch (e) {
|
|
48130
|
-
|
|
48667
|
+
debugWarn("[tevrocsdk][fileoffline] persistFileToNative error", e);
|
|
48131
48668
|
return false;
|
|
48132
48669
|
}
|
|
48133
48670
|
}
|
|
48134
48671
|
async function walkAndPersistFiles(client, obj) {
|
|
48135
48672
|
if (!obj || typeof obj !== "object") return;
|
|
48136
48673
|
if (!isNative || !client?.native?.store) return;
|
|
48137
|
-
|
|
48674
|
+
debugLog("[tevrocsdk][fileoffline] walkAndPersistFiles start");
|
|
48138
48675
|
for (const k of Object.keys(obj)) {
|
|
48139
48676
|
const v = obj[k];
|
|
48140
48677
|
if (typeof v === "string") {
|
|
48141
48678
|
if (isDataUrl(v)) {
|
|
48142
|
-
|
|
48679
|
+
debugLog("[tevrocsdk][fileoffline] walkAndPersistFiles found data URL at key", k);
|
|
48143
48680
|
const base64 = extractBase64FromDataUrl(v);
|
|
48144
48681
|
const key = deriveKeyFromUrl(k) || `inline_${Date.now()}`;
|
|
48145
48682
|
await persistFileToNative(client, key, base64, (v.match(/^data:([^;]+);/) || [])[1] || "application/octet-stream");
|
|
48146
48683
|
} else if (/^https?:\/\//.test(v) || v.startsWith("filebase://")) {
|
|
48147
|
-
|
|
48684
|
+
debugLog("[tevrocsdk][fileoffline] walkAndPersistFiles found URL at key", k, v);
|
|
48148
48685
|
const url = v.startsWith("filebase://") ? v.replace(/^filebase:\/\//, "") : v;
|
|
48149
48686
|
const base64 = await downloadUrlToBase64(v).catch(() => null);
|
|
48150
48687
|
if (base64) {
|
|
@@ -48152,16 +48689,16 @@ async function walkAndPersistFiles(client, obj) {
|
|
|
48152
48689
|
await persistFileToNative(client, key, base64, "application/octet-stream");
|
|
48153
48690
|
}
|
|
48154
48691
|
} else if (isLikelyBase64(v)) {
|
|
48155
|
-
|
|
48692
|
+
debugLog("[tevrocsdk][fileoffline] walkAndPersistFiles found inline base64 at key", k);
|
|
48156
48693
|
const key = deriveKeyFromUrl(k) || `inline_${Date.now()}`;
|
|
48157
48694
|
await persistFileToNative(client, key, v, "application/octet-stream");
|
|
48158
48695
|
}
|
|
48159
48696
|
} else if (v && typeof v === "object") {
|
|
48160
|
-
|
|
48697
|
+
debugLog("[tevrocsdk][fileoffline] walkAndPersistFiles recursing into", k);
|
|
48161
48698
|
await walkAndPersistFiles(client, v);
|
|
48162
48699
|
}
|
|
48163
48700
|
}
|
|
48164
|
-
|
|
48701
|
+
debugLog("[tevrocsdk][fileoffline] walkAndPersistFiles end");
|
|
48165
48702
|
}
|
|
48166
48703
|
function createOfflineManager(client) {
|
|
48167
48704
|
const store = createNativeStore(client.appId);
|
|
@@ -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,13 @@ 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);
|
|
49213
|
+
this.vpsConfig = { ...options.vpsConfig || options.config || {} };
|
|
48660
49214
|
this.appId = options.appId;
|
|
48661
49215
|
this.appName = options.appName;
|
|
48662
49216
|
this.payAccount = options.payAccount ?? "default";
|
|
@@ -48665,11 +49219,14 @@ var TevrocClient = class {
|
|
|
48665
49219
|
throw new TypeError("No fetch implementation available");
|
|
48666
49220
|
}
|
|
48667
49221
|
this.timeoutMs = options.timeoutMs ?? DEFAULT_TIMEOUT_MS;
|
|
49222
|
+
this.axios = options.axios;
|
|
48668
49223
|
this.defaultHeaders = normalizeHeaders(options.headers);
|
|
48669
49224
|
this.token = options.token ?? null;
|
|
48670
49225
|
this.debug = options.debug ?? false;
|
|
48671
49226
|
setSdkDebug(this.debug);
|
|
48672
49227
|
this.auth = createAuthApi(this);
|
|
49228
|
+
this.vps = createVpsApi(this);
|
|
49229
|
+
this.database = this.vps.database;
|
|
48673
49230
|
this.entities = createEntityRegistry(this);
|
|
48674
49231
|
this.functions = createFunctionRegistry(this);
|
|
48675
49232
|
this.integrations = createIntegrationApi(this);
|
|
@@ -48726,7 +49283,15 @@ var TevrocClient = class {
|
|
|
48726
49283
|
}
|
|
48727
49284
|
clearToken() {
|
|
48728
49285
|
this.token = null;
|
|
48729
|
-
safeLocalStorage()
|
|
49286
|
+
const storage = safeLocalStorage();
|
|
49287
|
+
[
|
|
49288
|
+
"tevroc_access_token",
|
|
49289
|
+
"base44_access_token",
|
|
49290
|
+
"native_access_token",
|
|
49291
|
+
"token",
|
|
49292
|
+
"idToken",
|
|
49293
|
+
"user"
|
|
49294
|
+
].forEach((key) => storage?.removeItem(key));
|
|
48730
49295
|
return this;
|
|
48731
49296
|
}
|
|
48732
49297
|
setDebug(enabled) {
|
|
@@ -48738,7 +49303,8 @@ var TevrocClient = class {
|
|
|
48738
49303
|
const method = (options.method ?? "GET").toUpperCase();
|
|
48739
49304
|
const headers = new Headers(this.defaultHeaders);
|
|
48740
49305
|
const query = options.query ? toSearchParams(options.query) : "";
|
|
48741
|
-
const
|
|
49306
|
+
const requestBaseUrl = options.baseUrl ?? this.baseUrl;
|
|
49307
|
+
const url = `${requestBaseUrl}${path.startsWith("/") ? path : `/${path}`}${query}`;
|
|
48742
49308
|
const controller = new AbortController();
|
|
48743
49309
|
const timeoutMsActual = options.timeoutMs || this.timeoutMs || 2500;
|
|
48744
49310
|
let timeout = null;
|
|
@@ -48779,13 +49345,23 @@ var TevrocClient = class {
|
|
|
48779
49345
|
debugWarn2(this, "[tevrocsdk] pending sync failed", err);
|
|
48780
49346
|
}
|
|
48781
49347
|
}
|
|
48782
|
-
let
|
|
48783
|
-
|
|
48784
|
-
|
|
48785
|
-
|
|
48786
|
-
|
|
48787
|
-
|
|
48788
|
-
|
|
49348
|
+
let requestPromise;
|
|
49349
|
+
if (this.axios?.request) {
|
|
49350
|
+
requestPromise = this.axios.request({
|
|
49351
|
+
url,
|
|
49352
|
+
method,
|
|
49353
|
+
headers: Object.fromEntries(headers.entries()),
|
|
49354
|
+
data: body,
|
|
49355
|
+
signal: options.signal ?? controller.signal
|
|
49356
|
+
}).then((response) => parseAxiosResponse(response, options.parseAs));
|
|
49357
|
+
} else {
|
|
49358
|
+
requestPromise = this.fetch(url, {
|
|
49359
|
+
method,
|
|
49360
|
+
headers,
|
|
49361
|
+
body,
|
|
49362
|
+
signal: options.signal ?? controller.signal
|
|
49363
|
+
}).then((response) => parseResponse(response, options.parseAs));
|
|
49364
|
+
}
|
|
48789
49365
|
const timeoutPromise = new Promise((_, reject) => {
|
|
48790
49366
|
timeout = setTimeout(() => {
|
|
48791
49367
|
try {
|
|
@@ -48795,8 +49371,7 @@ var TevrocClient = class {
|
|
|
48795
49371
|
reject(new TevrocError("Request timed out", { code: "timeout" }));
|
|
48796
49372
|
}, timeoutMsActual);
|
|
48797
49373
|
});
|
|
48798
|
-
|
|
48799
|
-
let ret = await parseResponse(response, options.parseAs);
|
|
49374
|
+
let ret = await Promise.race([requestPromise, timeoutPromise]);
|
|
48800
49375
|
debugLog2(this, "Response from request:", ret);
|
|
48801
49376
|
return ret;
|
|
48802
49377
|
} catch (error) {
|
|
@@ -48809,6 +49384,67 @@ var TevrocClient = class {
|
|
|
48809
49384
|
}
|
|
48810
49385
|
}
|
|
48811
49386
|
};
|
|
49387
|
+
function createVpsApi(client) {
|
|
49388
|
+
const request = (path, options = {}) => client.request(path, { ...options, baseUrl: client.vpsUrl });
|
|
49389
|
+
const withSession = (session, query = {}) => ({
|
|
49390
|
+
...query,
|
|
49391
|
+
session: session ?? client.vpsConfig.session
|
|
49392
|
+
});
|
|
49393
|
+
const encodeSql = (sql) => {
|
|
49394
|
+
if (typeof sql !== "string" || !sql.trim()) throw new TypeError("sql must be a non-empty string");
|
|
49395
|
+
if (typeof btoa === "function") return btoa(unescape(encodeURIComponent(sql)));
|
|
49396
|
+
return Buffer.from(sql, "utf8").toString("base64");
|
|
49397
|
+
};
|
|
49398
|
+
const database = {
|
|
49399
|
+
dialect: () => request("/database/sql", { auth: false }),
|
|
49400
|
+
tables: (options = {}) => request("/database/tables", { query: withSession(options.session, options), auth: false }),
|
|
49401
|
+
table: (table, options = {}) => request("/database/table", {
|
|
49402
|
+
query: withSession(options.session, { ...options, table }),
|
|
49403
|
+
auth: false
|
|
49404
|
+
}),
|
|
49405
|
+
exec: (sql, options = {}) => request("/database/query/exec", {
|
|
49406
|
+
query: withSession(options.session, { ...options, query: encodeSql(sql) }),
|
|
49407
|
+
auth: false
|
|
49408
|
+
}),
|
|
49409
|
+
query: (sql, options = {}) => database.exec(sql, options)
|
|
49410
|
+
};
|
|
49411
|
+
const auth = {
|
|
49412
|
+
login: async (email, password, options = {}) => {
|
|
49413
|
+
const result = await request("/login", { query: { ...options, email, password }, auth: false });
|
|
49414
|
+
if (result?.session) client.setToken(result.session);
|
|
49415
|
+
return result;
|
|
49416
|
+
},
|
|
49417
|
+
verifyOtp: async (email, otp, options = {}) => {
|
|
49418
|
+
const result = await request("/auth-otp", { query: { ...options, email, otp }, auth: false });
|
|
49419
|
+
if (result?.session) client.setToken(result.session);
|
|
49420
|
+
return result;
|
|
49421
|
+
},
|
|
49422
|
+
register: (input, options = {}) => request(options.path || "/auth/register", { method: "POST", body: input, auth: false }),
|
|
49423
|
+
resetPassword: (input, options = {}) => request(options.path || "/auth/reset-password", { method: "POST", body: input, auth: false }),
|
|
49424
|
+
changePassword: (input, options = {}) => request(options.path || "/auth/change-password", { method: "POST", body: input }),
|
|
49425
|
+
session: (session = client.token, options = {}) => request("/session", { query: withSession(session, options), auth: false }),
|
|
49426
|
+
userType: (session = client.token, options = {}) => request("/get-usertype", { query: withSession(session, options), auth: false }),
|
|
49427
|
+
user: (session = client.token, options = {}) => request("/get-user", { query: withSession(session, options), auth: false }),
|
|
49428
|
+
hasOnboarded: (session = client.token, options = {}) => request("/has-onboarded", { query: withSession(session, options), auth: false }),
|
|
49429
|
+
hasVerified: (session = client.token, options = {}) => request("/has-verified", { query: withSession(session, options), auth: false }),
|
|
49430
|
+
updateProfile: (session, data, options = {}) => request("/update-profile", { query: withSession(session, { ...options, jsonObject: JSON.stringify(data) }), auth: false }),
|
|
49431
|
+
updateOnboarding: (session, data, options = {}) => request("/update-onboarding", { query: withSession(session, { ...options, jsonObject: JSON.stringify(data) }), auth: false }),
|
|
49432
|
+
logout: () => {
|
|
49433
|
+
client.clearToken();
|
|
49434
|
+
return Promise.resolve({ ok: true });
|
|
49435
|
+
}
|
|
49436
|
+
};
|
|
49437
|
+
return {
|
|
49438
|
+
request,
|
|
49439
|
+
auth,
|
|
49440
|
+
database,
|
|
49441
|
+
environment: () => request("/api/environment", { auth: false }),
|
|
49442
|
+
platform: () => request("/platform", { auth: false }),
|
|
49443
|
+
notifications: (options = {}) => request("/api/notifications", { query: options, auth: false }),
|
|
49444
|
+
accountContext: (session = client.token, options = {}) => request("/api/mobile/account-context", { query: withSession(session, options), auth: false }),
|
|
49445
|
+
avatarUrl: (options = {}) => `${client.vpsUrl}/api/avatar${toSearchParams(options)}`
|
|
49446
|
+
};
|
|
49447
|
+
}
|
|
48812
49448
|
function createShiplogicApi(client) {
|
|
48813
49449
|
return {
|
|
48814
49450
|
getRates: (payload = {}) => client.request("/shiplogic/rates", { method: "POST", body: payload }),
|
|
@@ -49003,6 +49639,7 @@ function createAuthApi(client) {
|
|
|
49003
49639
|
// base44
|
|
49004
49640
|
loginWithProvider: async (provider, redirectTo, setToken = async () => {
|
|
49005
49641
|
}) => {
|
|
49642
|
+
debugLog2(client, "loginWithProvider called", { provider, redirectTo });
|
|
49006
49643
|
if (provider === "google") {
|
|
49007
49644
|
const { createGoogleLogin: createGoogleLogin2, subscribeGoogleLogin: subscribeGoogleLogin2 } = await getGoogleModule();
|
|
49008
49645
|
debugLog2(client, {
|
|
@@ -49010,17 +49647,92 @@ function createAuthApi(client) {
|
|
|
49010
49647
|
appId: client.appId,
|
|
49011
49648
|
appName: client.appName
|
|
49012
49649
|
});
|
|
49013
|
-
|
|
49650
|
+
if (redirectTo) {
|
|
49651
|
+
const unsub = subscribeGoogleLogin2(async (user, err) => {
|
|
49652
|
+
debugLog2(client, "Google callback:", user, err);
|
|
49653
|
+
unsub();
|
|
49654
|
+
if (!user) return;
|
|
49655
|
+
const result = await client.request("/auth/google", {
|
|
49656
|
+
method: "POST",
|
|
49657
|
+
body: buildAuthPayload({ accessToken: user.accessToken }, client),
|
|
49658
|
+
auth: false
|
|
49659
|
+
});
|
|
49660
|
+
debugLog2(client, result);
|
|
49661
|
+
await setToken(result.token, result.user);
|
|
49662
|
+
debugLog2(client, "Redirecting to:", redirectTo);
|
|
49663
|
+
window.location.href = redirectTo;
|
|
49664
|
+
});
|
|
49665
|
+
try {
|
|
49666
|
+
await createGoogleLogin2({
|
|
49667
|
+
serviceUrl: client.serviceUrl,
|
|
49668
|
+
appId: client.appId,
|
|
49669
|
+
appName: client.appName
|
|
49670
|
+
});
|
|
49671
|
+
} catch (error) {
|
|
49672
|
+
unsub();
|
|
49673
|
+
throw error;
|
|
49674
|
+
}
|
|
49675
|
+
} else {
|
|
49676
|
+
await createGoogleLogin2({
|
|
49677
|
+
serviceUrl: client.serviceUrl,
|
|
49678
|
+
appId: client.appId,
|
|
49679
|
+
appName: client.appName
|
|
49680
|
+
});
|
|
49681
|
+
}
|
|
49682
|
+
}
|
|
49683
|
+
if (provider === "facebook") {
|
|
49684
|
+
const { createFacebookLogin: createFacebookLogin2, subscribeFacebookLogin: subscribeFacebookLogin2 } = await getFacebookModule();
|
|
49685
|
+
debugLog2(client, {
|
|
49014
49686
|
serviceUrl: client.serviceUrl,
|
|
49015
49687
|
appId: client.appId,
|
|
49016
49688
|
appName: client.appName
|
|
49017
49689
|
});
|
|
49018
49690
|
if (redirectTo) {
|
|
49019
|
-
const unsub =
|
|
49020
|
-
debugLog2(client, "
|
|
49691
|
+
const unsub = subscribeFacebookLogin2(async (user, err) => {
|
|
49692
|
+
debugLog2(client, "Facebook callback:", user, err);
|
|
49021
49693
|
unsub();
|
|
49022
49694
|
if (!user) return;
|
|
49023
|
-
const result = await client.request("/auth/
|
|
49695
|
+
const result = await client.request("/auth/facebook", {
|
|
49696
|
+
method: "POST",
|
|
49697
|
+
body: buildAuthPayload({ accessToken: user.accessToken }, client),
|
|
49698
|
+
auth: false
|
|
49699
|
+
});
|
|
49700
|
+
debugLog2(client, result);
|
|
49701
|
+
await setToken(result.token, result.user);
|
|
49702
|
+
debugLog2(client, "Redirecting to:", redirectTo);
|
|
49703
|
+
window.location.href = redirectTo;
|
|
49704
|
+
});
|
|
49705
|
+
try {
|
|
49706
|
+
await createFacebookLogin2({
|
|
49707
|
+
serviceUrl: client.serviceUrl,
|
|
49708
|
+
appId: client.appId,
|
|
49709
|
+
appName: client.appName
|
|
49710
|
+
});
|
|
49711
|
+
} catch (error) {
|
|
49712
|
+
unsub();
|
|
49713
|
+
throw error;
|
|
49714
|
+
}
|
|
49715
|
+
} else {
|
|
49716
|
+
await createFacebookLogin2({
|
|
49717
|
+
serviceUrl: client.serviceUrl,
|
|
49718
|
+
appId: client.appId,
|
|
49719
|
+
appName: client.appName
|
|
49720
|
+
});
|
|
49721
|
+
}
|
|
49722
|
+
}
|
|
49723
|
+
if (provider === "meta") {
|
|
49724
|
+
const { createMetaLogin: createMetaLogin2, subscribeMetaLogin: subscribeMetaLogin2 } = await getMetaModule();
|
|
49725
|
+
debugLog2(client, {
|
|
49726
|
+
serviceUrl: client.serviceUrl,
|
|
49727
|
+
appId: client.appId,
|
|
49728
|
+
appName: client.appName
|
|
49729
|
+
});
|
|
49730
|
+
if (redirectTo) {
|
|
49731
|
+
const unsub = subscribeMetaLogin2(async (user, err) => {
|
|
49732
|
+
debugLog2(client, "Meta callback:", user, err);
|
|
49733
|
+
unsub();
|
|
49734
|
+
if (!user) return;
|
|
49735
|
+
const result = await client.request("/auth/meta", {
|
|
49024
49736
|
method: "POST",
|
|
49025
49737
|
body: buildAuthPayload({ accessToken: user.accessToken }, client),
|
|
49026
49738
|
auth: false
|
|
@@ -49030,6 +49742,22 @@ function createAuthApi(client) {
|
|
|
49030
49742
|
debugLog2(client, "Redirecting to:", redirectTo);
|
|
49031
49743
|
window.location.href = redirectTo;
|
|
49032
49744
|
});
|
|
49745
|
+
try {
|
|
49746
|
+
await createMetaLogin2({
|
|
49747
|
+
serviceUrl: client.serviceUrl,
|
|
49748
|
+
appId: client.appId,
|
|
49749
|
+
appName: client.appName
|
|
49750
|
+
});
|
|
49751
|
+
} catch (error) {
|
|
49752
|
+
unsub();
|
|
49753
|
+
throw error;
|
|
49754
|
+
}
|
|
49755
|
+
} else {
|
|
49756
|
+
await createMetaLogin2({
|
|
49757
|
+
serviceUrl: client.serviceUrl,
|
|
49758
|
+
appId: client.appId,
|
|
49759
|
+
appName: client.appName
|
|
49760
|
+
});
|
|
49033
49761
|
}
|
|
49034
49762
|
}
|
|
49035
49763
|
},
|
|
@@ -49038,6 +49766,14 @@ function createAuthApi(client) {
|
|
|
49038
49766
|
onGoogleLogin: (callback) => {
|
|
49039
49767
|
return subscribeGoogleLogin(callback);
|
|
49040
49768
|
},
|
|
49769
|
+
facebookLogin: (params) => createFacebookLogin(params),
|
|
49770
|
+
onFacebookLogin: (callback) => {
|
|
49771
|
+
return subscribeFacebookLogin(callback);
|
|
49772
|
+
},
|
|
49773
|
+
metaLogin: (params) => createMetaLogin(params),
|
|
49774
|
+
onMetaLogin: (callback) => {
|
|
49775
|
+
return subscribeMetaLogin(callback);
|
|
49776
|
+
},
|
|
49041
49777
|
//
|
|
49042
49778
|
async login(input) {
|
|
49043
49779
|
const body = buildAuthPayload(input, client);
|
|
@@ -49045,11 +49781,40 @@ function createAuthApi(client) {
|
|
|
49045
49781
|
if (result.token) client.setToken(result.token);
|
|
49046
49782
|
return result;
|
|
49047
49783
|
},
|
|
49048
|
-
async
|
|
49049
|
-
const result = await client.request("/auth/
|
|
49050
|
-
|
|
49784
|
+
async loginWithGoogle(input) {
|
|
49785
|
+
const result = await client.request("/auth/google", {
|
|
49786
|
+
method: "POST",
|
|
49787
|
+
body: buildAuthPayload(input, client),
|
|
49788
|
+
auth: false
|
|
49789
|
+
});
|
|
49790
|
+
if (result.token) client.setToken(result.token);
|
|
49791
|
+
return result;
|
|
49792
|
+
},
|
|
49793
|
+
async loginWithFacebook(input) {
|
|
49794
|
+
const result = await client.request("/auth/facebook", {
|
|
49795
|
+
method: "POST",
|
|
49796
|
+
body: buildAuthPayload(input, client),
|
|
49797
|
+
auth: false
|
|
49798
|
+
});
|
|
49799
|
+
if (result.token) client.setToken(result.token);
|
|
49051
49800
|
return result;
|
|
49052
49801
|
},
|
|
49802
|
+
async loginWithMeta(input) {
|
|
49803
|
+
const result = await client.request("/auth/meta", {
|
|
49804
|
+
method: "POST",
|
|
49805
|
+
body: buildAuthPayload(input, client),
|
|
49806
|
+
auth: false
|
|
49807
|
+
});
|
|
49808
|
+
if (result.token) client.setToken(result.token);
|
|
49809
|
+
return result;
|
|
49810
|
+
},
|
|
49811
|
+
async logout() {
|
|
49812
|
+
try {
|
|
49813
|
+
return await client.request("/auth/logout", { method: "POST", body: buildAuthPayload({}, client) });
|
|
49814
|
+
} finally {
|
|
49815
|
+
client.clearToken();
|
|
49816
|
+
}
|
|
49817
|
+
},
|
|
49053
49818
|
inviteUser: (input) => client.request("/users/invite", { method: "POST", body: buildAuthPayload(input, client) }),
|
|
49054
49819
|
acceptInvite: (input) => client.request("/auth/accept-invite", { method: "POST", body: buildAuthPayload(input, client), auth: false }),
|
|
49055
49820
|
me: async () => {
|
|
@@ -49584,10 +50349,10 @@ async function blobToBase643(blob) {
|
|
|
49584
50349
|
async function readCachedFileResponse(client, key) {
|
|
49585
50350
|
if (!client.native?.store || !isNative) return null;
|
|
49586
50351
|
const cached = (await client.native.store.get(`downloaded_files/${key}`)).val();
|
|
49587
|
-
|
|
50352
|
+
debugLog2(client, "[tevrocsdk][files] readCachedFileResponse", { key, hasCached: !!cached?.data });
|
|
49588
50353
|
if (!cached?.data) return null;
|
|
49589
50354
|
const blob = base64ToBlob(cached.data, cached.contentType || "application/octet-stream");
|
|
49590
|
-
|
|
50355
|
+
debugLog2(client, "[tevrocsdk][files] readCachedFileResponse built blob", { key, size: blob && blob.size });
|
|
49591
50356
|
return new Response(blob, {
|
|
49592
50357
|
headers: { "content-type": cached.contentType || "application/octet-stream" }
|
|
49593
50358
|
});
|
|
@@ -49595,14 +50360,14 @@ async function readCachedFileResponse(client, key) {
|
|
|
49595
50360
|
async function storeCachedFileResponse(client, key, response, fallbackContentType = "application/octet-stream") {
|
|
49596
50361
|
if (!client.native?.store || !isNative || !key) return;
|
|
49597
50362
|
try {
|
|
49598
|
-
|
|
50363
|
+
debugLog2(client, "[tevrocsdk][files] storeCachedFileResponse", { key });
|
|
49599
50364
|
const clone = response instanceof Response ? response.clone() : null;
|
|
49600
50365
|
const blob = clone ? await clone.blob() : null;
|
|
49601
50366
|
const contentType = clone && clone.headers.get("content-type") || fallbackContentType;
|
|
49602
50367
|
const data = blob ? await blobToBase643(blob) : "";
|
|
49603
|
-
|
|
50368
|
+
debugLog2(client, "[tevrocsdk][files] storeCachedFileResponse data length", { key, length: data ? data.length : 0, contentType });
|
|
49604
50369
|
if (!data) {
|
|
49605
|
-
|
|
50370
|
+
debugWarn2(client, "[tevrocsdk][files] storeCachedFileResponse no data to store", { key });
|
|
49606
50371
|
return;
|
|
49607
50372
|
}
|
|
49608
50373
|
await client.native.store.set(`downloaded_files/${key}`, {
|
|
@@ -49611,18 +50376,18 @@ async function storeCachedFileResponse(client, key, response, fallbackContentTyp
|
|
|
49611
50376
|
key,
|
|
49612
50377
|
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
49613
50378
|
});
|
|
49614
|
-
|
|
50379
|
+
debugLog2(client, "[tevrocsdk][files] storeCachedFileResponse stored", { key });
|
|
49615
50380
|
} catch (error) {
|
|
49616
50381
|
debugWarn2(client, "Failed to cache downloaded file", error);
|
|
49617
|
-
|
|
50382
|
+
debugWarn2(client, "[tevrocsdk][files] storeCachedFileResponse error", error);
|
|
49618
50383
|
}
|
|
49619
50384
|
}
|
|
49620
50385
|
async function readCachedFileDataUrl(client, key) {
|
|
49621
50386
|
if (!client.native?.store || !isNative || !key) return null;
|
|
49622
50387
|
const cached = (await client.native.store.get(`downloaded_files/${key}`)).val();
|
|
49623
|
-
|
|
50388
|
+
debugLog2(client, "[tevrocsdk][files] readCachedFileDataUrl", { key, hasCached: !!cached?.data });
|
|
49624
50389
|
if (!cached?.data) return null;
|
|
49625
|
-
|
|
50390
|
+
debugLog2(client, "[tevrocsdk][files] readCachedFileDataUrl returning data url", { key, length: cached.data.length });
|
|
49626
50391
|
return `data:${cached.contentType || "application/octet-stream"};base64,${cached.data}`;
|
|
49627
50392
|
}
|
|
49628
50393
|
function base64ToBlob(base64, contentType = "application/octet-stream") {
|
|
@@ -49636,29 +50401,6 @@ function base64ToBlob(base64, contentType = "application/octet-stream") {
|
|
|
49636
50401
|
}
|
|
49637
50402
|
return new Blob([bytes], { type: contentType });
|
|
49638
50403
|
}
|
|
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
50404
|
function createFileApi(client) {
|
|
49663
50405
|
return {
|
|
49664
50406
|
url: async (key) => {
|
|
@@ -49677,7 +50419,7 @@ function createFileApi(client) {
|
|
|
49677
50419
|
}
|
|
49678
50420
|
rounds += 1;
|
|
49679
50421
|
} while (rawKey !== prev && rawKey.includes("%25") && rounds < 5);
|
|
49680
|
-
if (rounds > 0)
|
|
50422
|
+
if (rounds > 0) debugLog2(client, "[tevrocsdk][files] iterative decode performed", { original: key, rawKey, rounds });
|
|
49681
50423
|
} catch (e) {
|
|
49682
50424
|
}
|
|
49683
50425
|
debugLog2(client, "[tevrocsdk][files:url]", { key, rawKey, online, offline, isNative });
|
|
@@ -49707,7 +50449,7 @@ function createFileApi(client) {
|
|
|
49707
50449
|
}
|
|
49708
50450
|
rounds += 1;
|
|
49709
50451
|
} while (rawKey !== prev && rawKey.includes("%25") && rounds < 5);
|
|
49710
|
-
if (rounds > 0)
|
|
50452
|
+
if (rounds > 0) debugLog2(client, "[tevrocsdk][files] iterative decode performed (privateUrl)", { original: key, rawKey, rounds });
|
|
49711
50453
|
} catch (e) {
|
|
49712
50454
|
}
|
|
49713
50455
|
debugLog2(client, "[tevrocsdk][files:privateUrl]", { key, rawKey, online, offline, isNative });
|
|
@@ -49747,7 +50489,7 @@ function createFileApi(client) {
|
|
|
49747
50489
|
}
|
|
49748
50490
|
rounds += 1;
|
|
49749
50491
|
} while (rawKey !== prev && rawKey.includes("%25") && rounds < 5);
|
|
49750
|
-
if (rounds > 0)
|
|
50492
|
+
if (rounds > 0) debugLog2(client, "[tevrocsdk][files] iterative decode performed (get)", { original: key, rawKey, rounds });
|
|
49751
50493
|
} catch (e) {
|
|
49752
50494
|
}
|
|
49753
50495
|
debugLog2(client, "[tevrocsdk][files] get", { key, rawKey, isNative, online, offline });
|
|
@@ -49777,7 +50519,7 @@ function createFileApi(client) {
|
|
|
49777
50519
|
}
|
|
49778
50520
|
rounds += 1;
|
|
49779
50521
|
} while (rawKey !== prev && rawKey.includes("%25") && rounds < 5);
|
|
49780
|
-
if (rounds > 0)
|
|
50522
|
+
if (rounds > 0) debugLog2(client, "[tevrocsdk][files] iterative decode performed (getPrivate)", { original: key, rawKey, rounds });
|
|
49781
50523
|
} catch (e) {
|
|
49782
50524
|
}
|
|
49783
50525
|
debugLog2(client, "[tevrocsdk][files] getPrivate", { key, rawKey, isNative, online, offline });
|
|
@@ -49794,34 +50536,191 @@ function createFileApi(client) {
|
|
|
49794
50536
|
};
|
|
49795
50537
|
}
|
|
49796
50538
|
async function upload(client, path, file, options = {}) {
|
|
49797
|
-
const
|
|
49798
|
-
if (
|
|
49799
|
-
|
|
49800
|
-
|
|
49801
|
-
|
|
49802
|
-
|
|
49803
|
-
|
|
49804
|
-
|
|
49805
|
-
|
|
49806
|
-
|
|
50539
|
+
const isElectron = await detectElectronEnvironment(client);
|
|
50540
|
+
if (isElectron) {
|
|
50541
|
+
return uploadViaElectronBridge(client, file, options);
|
|
50542
|
+
}
|
|
50543
|
+
return uploadViaGoogleStorage(client, file, { ...options, path });
|
|
50544
|
+
}
|
|
50545
|
+
async function detectElectronEnvironment(client) {
|
|
50546
|
+
try {
|
|
50547
|
+
const serviceUrl = String(client?.serviceUrl || "").replace(/\/$/, "");
|
|
50548
|
+
const response = await client.fetch(`${serviceUrl}/api/environment`, {
|
|
50549
|
+
method: "GET",
|
|
50550
|
+
headers: { Accept: "application/json" },
|
|
50551
|
+
cache: "no-store"
|
|
50552
|
+
});
|
|
50553
|
+
if (response && response.ok) {
|
|
50554
|
+
const data = await response.json();
|
|
50555
|
+
if (data && typeof data === "object" && "isElectron" in data) {
|
|
50556
|
+
return Boolean(data.isElectron);
|
|
50557
|
+
}
|
|
50558
|
+
}
|
|
50559
|
+
} catch (error) {
|
|
50560
|
+
debugLog2(client, "[tevrocsdk][env] /api/environment fallback", error);
|
|
50561
|
+
}
|
|
50562
|
+
if (typeof navigator !== "undefined") {
|
|
50563
|
+
const userAgent = navigator.userAgent || "";
|
|
50564
|
+
if (/electron/i.test(userAgent)) return true;
|
|
50565
|
+
}
|
|
50566
|
+
if (typeof window !== "undefined") {
|
|
50567
|
+
const bridge = window?.bridge || window?.electronBridge || window?.nativeBridge;
|
|
50568
|
+
if (bridge) return true;
|
|
50569
|
+
if (window.process && window.process.versions && window.process.versions.electron) return true;
|
|
50570
|
+
}
|
|
50571
|
+
return false;
|
|
50572
|
+
}
|
|
50573
|
+
async function uploadViaElectronBridge(client, file, options = {}) {
|
|
50574
|
+
const fileName = options.filename || "upload";
|
|
50575
|
+
const contentType = options.contentType || "application/octet-stream";
|
|
50576
|
+
const resolvedFile = file instanceof Blob ? file : new Blob([String(file ?? "")], { type: contentType });
|
|
50577
|
+
const dataUrl = resolvedFile instanceof Blob ? `data:${contentType};base64,${await blobToBase643(resolvedFile)}` : String(file);
|
|
50578
|
+
const packetSize = options.packetSize || 1024 * 1024;
|
|
50579
|
+
const packets = [];
|
|
50580
|
+
for (let offset2 = 0; offset2 < dataUrl.length; offset2 += packetSize) {
|
|
50581
|
+
const packetData2 = dataUrl.slice(offset2, offset2 + packetSize);
|
|
50582
|
+
packets.push({
|
|
50583
|
+
packetId: packets.length,
|
|
50584
|
+
packetData: encodeURIComponent(packetData2),
|
|
50585
|
+
isLastPacket: offset2 + packetSize >= dataUrl.length,
|
|
50586
|
+
filePanaroma: options.filePanaroma || "NO"
|
|
50587
|
+
});
|
|
50588
|
+
}
|
|
50589
|
+
if (!packets.length) throw new TevrocError("Cannot upload an empty file", { code: "empty_file" });
|
|
50590
|
+
let clientId = "";
|
|
50591
|
+
const endpoint = `${client.serviceUrl.replace(/\/$/, "")}/receivePacket`;
|
|
50592
|
+
for (const packet of packets) {
|
|
50593
|
+
const payload = {
|
|
50594
|
+
...packet,
|
|
50595
|
+
clientId,
|
|
50596
|
+
tableName: options.tableName || "",
|
|
50597
|
+
tableIdx: options.tableIdx ?? "",
|
|
50598
|
+
tableGallery: options.gallery === true || options.gallery === "YES",
|
|
50599
|
+
fileName,
|
|
50600
|
+
fileSize: resolvedFile.size,
|
|
50601
|
+
fileMime: contentType,
|
|
50602
|
+
server: options.server || "test",
|
|
50603
|
+
session: options.session || client.token || ""
|
|
50604
|
+
};
|
|
50605
|
+
let result;
|
|
50606
|
+
const bridge = typeof window !== "undefined" ? window : null;
|
|
50607
|
+
if (bridge && typeof bridge.syncRequest === "function") {
|
|
50608
|
+
const rawResult = bridge.syncRequest(endpoint, "POST", payload);
|
|
50609
|
+
if (!rawResult) throw new TevrocError("Electron upload failed", { code: "electron_upload_failed" });
|
|
50610
|
+
try {
|
|
50611
|
+
result = JSON.parse(rawResult);
|
|
50612
|
+
} catch (error) {
|
|
50613
|
+
throw new TevrocError("Electron upload returned invalid JSON", { code: "electron_upload_failed" });
|
|
50614
|
+
}
|
|
50615
|
+
} else {
|
|
50616
|
+
const response = await client.fetch(endpoint, {
|
|
49807
50617
|
method: "POST",
|
|
49808
|
-
headers,
|
|
49809
|
-
body:
|
|
49810
|
-
|
|
49811
|
-
|
|
49812
|
-
|
|
49813
|
-
|
|
49814
|
-
}
|
|
49815
|
-
|
|
49816
|
-
|
|
49817
|
-
|
|
50618
|
+
headers: { "Content-Type": "application/json", Accept: "application/json" },
|
|
50619
|
+
body: JSON.stringify(payload)
|
|
50620
|
+
});
|
|
50621
|
+
if (!response.ok) {
|
|
50622
|
+
const text = await response.text();
|
|
50623
|
+
throw new TevrocError(text || "Electron upload failed", { status: response.status, code: "electron_upload_failed" });
|
|
50624
|
+
}
|
|
50625
|
+
result = await response.json();
|
|
50626
|
+
}
|
|
50627
|
+
clientId = result.clientId || clientId;
|
|
50628
|
+
if (typeof options.onProgress === "function") {
|
|
50629
|
+
options.onProgress({ uploaded: Math.min(offset + packetData.length, dataUrl.length), total: dataUrl.length, progress: Math.round((offset + packetData.length) / dataUrl.length * 100) });
|
|
50630
|
+
}
|
|
50631
|
+
}
|
|
50632
|
+
return { success: true, clientId, fileName, fileSize: resolvedFile.size, runtime: "electron" };
|
|
50633
|
+
}
|
|
50634
|
+
async function uploadViaGoogleStorage(client, file, options = {}) {
|
|
50635
|
+
const contentType = options.contentType || "application/octet-stream";
|
|
50636
|
+
const fileName = options.filename || "upload";
|
|
50637
|
+
const body = file instanceof Blob ? file : new Blob([String(file ?? "")], { type: contentType });
|
|
50638
|
+
const serviceUrl = client.serviceUrl.replace(/\/$/, "");
|
|
50639
|
+
const initResponse = await client.fetch(`${serviceUrl}/api/uploads/create`, {
|
|
50640
|
+
method: "POST",
|
|
50641
|
+
headers: {
|
|
50642
|
+
"Content-Type": "application/json",
|
|
50643
|
+
Accept: "application/json"
|
|
50644
|
+
},
|
|
50645
|
+
body: JSON.stringify({
|
|
50646
|
+
filename: fileName,
|
|
50647
|
+
contentType,
|
|
50648
|
+
size: body.size,
|
|
50649
|
+
userId: options.userId || "anon"
|
|
50650
|
+
})
|
|
50651
|
+
});
|
|
50652
|
+
if (!initResponse.ok) {
|
|
50653
|
+
const text = await initResponse.text();
|
|
50654
|
+
throw new TevrocError(text || "Create upload session failed", { status: initResponse.status, code: "gcs_create_failed" });
|
|
50655
|
+
}
|
|
50656
|
+
const init = await initResponse.json();
|
|
50657
|
+
const uploadUrl = init && init.uploadUrl ? init.uploadUrl : null;
|
|
50658
|
+
const uploadId = init && init.uploadId ? init.uploadId : null;
|
|
50659
|
+
if (!uploadUrl || !uploadId) {
|
|
50660
|
+
throw new TevrocError("Google storage upload session is missing uploadUrl or uploadId", { code: "gcs_invalid_session" });
|
|
50661
|
+
}
|
|
50662
|
+
const chunkSize = options.chunkSize || 10 * 1024 * 1024;
|
|
50663
|
+
for (let offset2 = 0; offset2 < body.size; offset2 += chunkSize) {
|
|
50664
|
+
const end = Math.min(offset2 + chunkSize, body.size) - 1;
|
|
50665
|
+
let uploadResponse;
|
|
50666
|
+
for (let attempt = 1; attempt <= (options.retries || 5); attempt += 1) {
|
|
50667
|
+
try {
|
|
50668
|
+
uploadResponse = await client.fetch(uploadUrl, {
|
|
50669
|
+
method: "PUT",
|
|
50670
|
+
body: body.slice(offset2, end + 1),
|
|
50671
|
+
headers: {
|
|
50672
|
+
"Content-Length": String(end - offset2 + 1),
|
|
50673
|
+
"Content-Range": `bytes ${offset2}-${end}/${body.size}`,
|
|
50674
|
+
"Content-Type": contentType
|
|
50675
|
+
}
|
|
50676
|
+
});
|
|
50677
|
+
if (uploadResponse.ok || uploadResponse.status === 308) break;
|
|
50678
|
+
throw new Error(`HTTP ${uploadResponse.status}`);
|
|
50679
|
+
} catch (error) {
|
|
50680
|
+
if (attempt === (options.retries || 5)) throw new TevrocError(error.message, { code: "gcs_upload_failed" });
|
|
50681
|
+
await new Promise((resolve2) => setTimeout(resolve2, 1e3 * attempt));
|
|
50682
|
+
}
|
|
49818
50683
|
}
|
|
50684
|
+
if (!uploadResponse || !uploadResponse.ok && uploadResponse.status !== 308) {
|
|
50685
|
+
throw new TevrocError("Google storage upload failed", { code: "gcs_upload_failed" });
|
|
50686
|
+
}
|
|
50687
|
+
if (typeof options.onProgress === "function") options.onProgress({ uploaded: end + 1, total: body.size, progress: Math.round((end + 1) / body.size * 100) });
|
|
49819
50688
|
}
|
|
49820
|
-
|
|
49821
|
-
|
|
50689
|
+
const finalizeResponse = await client.fetch(`${serviceUrl}/api/uploads/${encodeURIComponent(uploadId)}/complete`, {
|
|
50690
|
+
method: "POST",
|
|
50691
|
+
headers: { "Content-Type": "application/json", Accept: "application/json" },
|
|
50692
|
+
body: JSON.stringify({ storageKey: init.storageKey, userId: options.userId || "anon" })
|
|
50693
|
+
});
|
|
50694
|
+
if (!finalizeResponse.ok) {
|
|
50695
|
+
const text = await finalizeResponse.text();
|
|
50696
|
+
throw new TevrocError(text || "Finalize upload failed", { status: finalizeResponse.status, code: "gcs_finalize_failed" });
|
|
50697
|
+
}
|
|
50698
|
+
const result = await finalizeResponse.json();
|
|
50699
|
+
if (options.tableName && options.tableIdx !== void 0) {
|
|
50700
|
+
await client.fetch(`${serviceUrl}/api/files/gcs-store`, {
|
|
50701
|
+
method: "POST",
|
|
50702
|
+
headers: { "Content-Type": "application/json", Accept: "application/json" },
|
|
50703
|
+
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" })
|
|
50704
|
+
});
|
|
49822
50705
|
}
|
|
49823
|
-
|
|
49824
|
-
|
|
50706
|
+
return { ...result, runtime: "gcs" };
|
|
50707
|
+
}
|
|
50708
|
+
async function parseAxiosResponse(response, parseAs) {
|
|
50709
|
+
if (parseAs === "response") return response;
|
|
50710
|
+
const headers = response.headers ?? {};
|
|
50711
|
+
const contentType = typeof headers.get === "function" ? headers.get("content-type") ?? "" : String(headers["content-type"] ?? headers["Content-Type"] ?? "");
|
|
50712
|
+
const isJson = contentType.includes("application/json");
|
|
50713
|
+
const data = response.data;
|
|
50714
|
+
if (response.status < 200 || response.status >= 300) {
|
|
50715
|
+
const error = isJson && data?.error ? data.error : {};
|
|
50716
|
+
throw new TevrocError(error.message ?? response.statusText ?? "Request failed", {
|
|
50717
|
+
status: response.status,
|
|
50718
|
+
code: error.code ?? "api_error",
|
|
50719
|
+
details: error.details ?? data,
|
|
50720
|
+
response
|
|
50721
|
+
});
|
|
50722
|
+
}
|
|
50723
|
+
return data;
|
|
49825
50724
|
}
|
|
49826
50725
|
async function parseResponse(response, parseAs) {
|
|
49827
50726
|
if (parseAs === "response") return response;
|
|
@@ -49859,13 +50758,13 @@ function normalizeHeaders(headers = {}) {
|
|
|
49859
50758
|
return Object.fromEntries(new Headers(headers).entries());
|
|
49860
50759
|
}
|
|
49861
50760
|
function debugLog2(client, ...args) {
|
|
49862
|
-
|
|
50761
|
+
debugLog(...args);
|
|
49863
50762
|
}
|
|
49864
50763
|
function debugWarn2(client, ...args) {
|
|
49865
|
-
|
|
50764
|
+
debugWarn(...args);
|
|
49866
50765
|
}
|
|
49867
50766
|
function debugError2(client, ...args) {
|
|
49868
|
-
|
|
50767
|
+
debugError(...args);
|
|
49869
50768
|
}
|
|
49870
50769
|
function safeLocalStorage() {
|
|
49871
50770
|
return typeof globalThis !== "undefined" ? globalThis.localStorage : void 0;
|