tevrocsdk 0.1.39 → 0.1.40
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/package.json +1 -1
- package/tevroc-sdk.esm.js +109 -17
- package/tevroc-sdk.min.js +36 -36
- package/tevroc-sdk.umd.js +109 -17
package/package.json
CHANGED
package/tevroc-sdk.esm.js
CHANGED
|
@@ -26282,7 +26282,7 @@ function subscribeGoogleLogin(cb) {
|
|
|
26282
26282
|
if (i4 !== -1) googleListeners.splice(i4, 1);
|
|
26283
26283
|
};
|
|
26284
26284
|
}
|
|
26285
|
-
var googleInitialized, googleListeners, authWindowRef, authCleanupTimer, authMessageListener, closeAllTauriWebviews, cleanupAuthWindow, handleCallback, initializeGoogleLogin, createGoogleLogin;
|
|
26285
|
+
var googleInitialized, googleListeners, authWindowRef, authCleanupTimer, authMessageListener, authTauriUnlisten, authHandled, closeAllTauriWebviews, cleanupAuthWindow, handleCallback, initializeGoogleLogin, createGoogleLogin;
|
|
26286
26286
|
var init_useGoogleAuth = __esm({
|
|
26287
26287
|
"src/services/useGoogleAuth.js"() {
|
|
26288
26288
|
init_esm3();
|
|
@@ -26294,6 +26294,8 @@ var init_useGoogleAuth = __esm({
|
|
|
26294
26294
|
authWindowRef = null;
|
|
26295
26295
|
authCleanupTimer = null;
|
|
26296
26296
|
authMessageListener = null;
|
|
26297
|
+
authTauriUnlisten = null;
|
|
26298
|
+
authHandled = false;
|
|
26297
26299
|
closeAllTauriWebviews = async () => {
|
|
26298
26300
|
if (!isTauri) return;
|
|
26299
26301
|
try {
|
|
@@ -26330,6 +26332,14 @@ var init_useGoogleAuth = __esm({
|
|
|
26330
26332
|
window.removeEventListener("message", authMessageListener);
|
|
26331
26333
|
authMessageListener = null;
|
|
26332
26334
|
}
|
|
26335
|
+
if (authTauriUnlisten) {
|
|
26336
|
+
try {
|
|
26337
|
+
await authTauriUnlisten();
|
|
26338
|
+
} catch (e2) {
|
|
26339
|
+
console.warn("Error removing Tauri auth listener:", e2);
|
|
26340
|
+
}
|
|
26341
|
+
authTauriUnlisten = null;
|
|
26342
|
+
}
|
|
26333
26343
|
if (authWindowRef) {
|
|
26334
26344
|
const currentAuthWindow = authWindowRef;
|
|
26335
26345
|
authWindowRef = null;
|
|
@@ -26363,6 +26373,8 @@ var init_useGoogleAuth = __esm({
|
|
|
26363
26373
|
};
|
|
26364
26374
|
handleCallback = async (url) => {
|
|
26365
26375
|
try {
|
|
26376
|
+
if (authHandled) return;
|
|
26377
|
+
authHandled = true;
|
|
26366
26378
|
await cleanupAuthWindow();
|
|
26367
26379
|
if (!url?.includes("token=")) return;
|
|
26368
26380
|
const params = new URLSearchParams(url.split("?")[1]);
|
|
@@ -26444,6 +26456,17 @@ var init_useGoogleAuth = __esm({
|
|
|
26444
26456
|
win.once("tauri://error", (e2) => {
|
|
26445
26457
|
console.error("Auth window error:", e2);
|
|
26446
26458
|
});
|
|
26459
|
+
try {
|
|
26460
|
+
const { listen: listen2 } = await Promise.resolve().then(() => (init_event(), event_exports));
|
|
26461
|
+
authTauriUnlisten = await listen2("google-auth", async (event) => {
|
|
26462
|
+
const token = event?.payload?.token;
|
|
26463
|
+
if (!token) return;
|
|
26464
|
+
const callbackUrl = `${window.location.href}${window.location.href.includes("?") ? "&" : "?"}token=${encodeURIComponent(token)}`;
|
|
26465
|
+
await handleCallback(callbackUrl);
|
|
26466
|
+
});
|
|
26467
|
+
} catch (e2) {
|
|
26468
|
+
console.warn("Tauri google-auth listener install failed:", e2);
|
|
26469
|
+
}
|
|
26447
26470
|
return;
|
|
26448
26471
|
}
|
|
26449
26472
|
const isLocalhost = true;
|
|
@@ -26576,19 +26599,38 @@ var init_useYocoPayment = __esm({
|
|
|
26576
26599
|
externalCallback
|
|
26577
26600
|
);
|
|
26578
26601
|
});
|
|
26602
|
+
await listen2("payment-result", async (event) => {
|
|
26603
|
+
if (paymentWindowRef) {
|
|
26604
|
+
try {
|
|
26605
|
+
await paymentWindowRef.close();
|
|
26606
|
+
paymentWindowRef = null;
|
|
26607
|
+
} catch (e2) {
|
|
26608
|
+
console.warn("Error closing Tauri payment window:", e2);
|
|
26609
|
+
}
|
|
26610
|
+
}
|
|
26611
|
+
const payload = event?.payload || {};
|
|
26612
|
+
const params = new URLSearchParams();
|
|
26613
|
+
if (payload.status) params.set("status", payload.status);
|
|
26614
|
+
if (payload.mode) params.set("mode", payload.mode);
|
|
26615
|
+
if (payload.app) params.set("app", payload.app);
|
|
26616
|
+
if (payload.checkoutId) params.set("checkoutId", payload.checkoutId);
|
|
26617
|
+
const url = `?${params.toString()}`;
|
|
26618
|
+
handlePaymentCallback(url, externalCallback);
|
|
26619
|
+
});
|
|
26579
26620
|
}
|
|
26580
26621
|
};
|
|
26581
26622
|
createPayment = async (amountZAR, {
|
|
26582
26623
|
appId = "tevrocsoft",
|
|
26583
26624
|
serviceUrl = "https://tevrocsoftapi.netlify.app",
|
|
26584
26625
|
payAccount = "default",
|
|
26626
|
+
companyId,
|
|
26585
26627
|
externalCallback = () => {
|
|
26586
26628
|
}
|
|
26587
26629
|
} = {}) => {
|
|
26588
26630
|
await initializePayment(externalCallback);
|
|
26589
26631
|
const cents = Math.round(Number(amountZAR) * 100);
|
|
26590
26632
|
const basePaymentUrl = `${serviceUrl.replace(/\/$/, "")}/yoco-pay`;
|
|
26591
|
-
const paymentUrl = `${basePaymentUrl}?mode=mobile&amount=${cents}&app=${appId}&account=${payAccount}`;
|
|
26633
|
+
const paymentUrl = `${basePaymentUrl}?mode=mobile&amount=${cents}&app=${appId}&account=${payAccount}${companyId ? `&companyId=${encodeURIComponent(companyId)}` : ""}`;
|
|
26592
26634
|
console.log(basePaymentUrl, paymentUrl);
|
|
26593
26635
|
if (isCapacitor) {
|
|
26594
26636
|
await Browser2.open({
|
|
@@ -26597,7 +26639,7 @@ var init_useYocoPayment = __esm({
|
|
|
26597
26639
|
return;
|
|
26598
26640
|
}
|
|
26599
26641
|
if (isTauri) {
|
|
26600
|
-
const url = `${basePaymentUrl}?mode=desktop&amount=${cents}&app=${appId}&account=${payAccount}`;
|
|
26642
|
+
const url = `${basePaymentUrl}?mode=desktop&amount=${cents}&app=${appId}&account=${payAccount}${companyId ? `&companyId=${encodeURIComponent(companyId)}` : ""}`;
|
|
26601
26643
|
const win = new WebviewWindow("payment", {
|
|
26602
26644
|
url,
|
|
26603
26645
|
title: "Complete Payment",
|
|
@@ -26617,7 +26659,7 @@ var init_useYocoPayment = __esm({
|
|
|
26617
26659
|
}
|
|
26618
26660
|
const isLocalhost = window.location.hostname === "localhost" || window.location.hostname === "127.0.0.1";
|
|
26619
26661
|
const mode = isLocalhost ? "localhost" : "netlify";
|
|
26620
|
-
const finalUrl = `${basePaymentUrl}?mode=${mode}&amount=${cents}&app=${appId}`;
|
|
26662
|
+
const finalUrl = `${basePaymentUrl}?mode=${mode}&amount=${cents}&app=${appId}${companyId ? `&companyId=${encodeURIComponent(companyId)}` : ""}`;
|
|
26621
26663
|
try {
|
|
26622
26664
|
const popup = window.open(finalUrl, "yocoPayment", "width=500,height=650");
|
|
26623
26665
|
if (!popup) {
|
|
@@ -40959,6 +41001,29 @@ var normalizePdfBlob = async (input) => {
|
|
|
40959
41001
|
}
|
|
40960
41002
|
throw new Error("Unsupported PDF source. Pass a Blob or a jsPDF document instance.");
|
|
40961
41003
|
};
|
|
41004
|
+
var normalizeFileBlob = async (input) => {
|
|
41005
|
+
if (!input) {
|
|
41006
|
+
throw new Error("File source is required");
|
|
41007
|
+
}
|
|
41008
|
+
if (input instanceof Blob) {
|
|
41009
|
+
return input;
|
|
41010
|
+
}
|
|
41011
|
+
if (typeof input.output === "function") {
|
|
41012
|
+
const output = input.output("blob");
|
|
41013
|
+
return output instanceof Promise ? await output : output;
|
|
41014
|
+
}
|
|
41015
|
+
if (input instanceof ArrayBuffer) {
|
|
41016
|
+
return new Blob([input]);
|
|
41017
|
+
}
|
|
41018
|
+
if (input instanceof Uint8Array) {
|
|
41019
|
+
return new Blob([input]);
|
|
41020
|
+
}
|
|
41021
|
+
if (input && typeof input.arrayBuffer === "function") {
|
|
41022
|
+
const buffer = await input.arrayBuffer();
|
|
41023
|
+
return new Blob([buffer]);
|
|
41024
|
+
}
|
|
41025
|
+
throw new Error("Unsupported file source. Pass a Blob, ArrayBuffer, Uint8Array, or a jsPDF document instance.");
|
|
41026
|
+
};
|
|
40962
41027
|
var createObjectUrl = (blob) => {
|
|
40963
41028
|
return URL.createObjectURL(blob);
|
|
40964
41029
|
};
|
|
@@ -40973,10 +41038,25 @@ var downloadBlobWeb = async (blob, fileName) => {
|
|
|
40973
41038
|
document.body.removeChild(a3);
|
|
40974
41039
|
URL.revokeObjectURL(url);
|
|
40975
41040
|
};
|
|
40976
|
-
var
|
|
41041
|
+
var getFileExtension = (fileName) => {
|
|
41042
|
+
if (!fileName) return "";
|
|
41043
|
+
const parts = String(fileName).trim().split(".");
|
|
41044
|
+
return parts.length > 1 ? parts.pop().toLowerCase() : "";
|
|
41045
|
+
};
|
|
41046
|
+
var getFileFilters = (fileName) => {
|
|
41047
|
+
const ext = getFileExtension(fileName);
|
|
41048
|
+
if (!ext) return [];
|
|
41049
|
+
return [{ name: ext.toUpperCase(), extensions: [ext] }];
|
|
41050
|
+
};
|
|
41051
|
+
var getFinalFileName = (fileName, defaultExt = "pdf") => {
|
|
41052
|
+
if (!fileName) return `document.${defaultExt}`;
|
|
41053
|
+
if (String(fileName).includes(".")) return fileName;
|
|
41054
|
+
return `${fileName}.${defaultExt}`;
|
|
41055
|
+
};
|
|
41056
|
+
var saveBlobCapacitor = async (blob, fileName, defaultExt = "pdf") => {
|
|
40977
41057
|
const { Filesystem: Filesystem2, Directory: Directory2 } = await Promise.resolve().then(() => (init_esm4(), esm_exports4));
|
|
40978
41058
|
const { Toast: Toast2 } = await Promise.resolve().then(() => (init_esm5(), esm_exports5));
|
|
40979
|
-
const finalName =
|
|
41059
|
+
const finalName = getFinalFileName(fileName, defaultExt);
|
|
40980
41060
|
const base64 = await blobToBase64(blob);
|
|
40981
41061
|
await Filesystem2.writeFile({
|
|
40982
41062
|
path: finalName,
|
|
@@ -40997,12 +41077,14 @@ var saveBlobCapacitor = async (blob, fileName) => {
|
|
|
40997
41077
|
}
|
|
40998
41078
|
return uri?.uri ?? finalName;
|
|
40999
41079
|
};
|
|
41000
|
-
var saveBlobTauri = async (blob, fileName) => {
|
|
41080
|
+
var saveBlobTauri = async (blob, fileName, defaultExt = "pdf") => {
|
|
41001
41081
|
const { save: save2 } = await Promise.resolve().then(() => (init_dist_js2(), dist_js_exports2));
|
|
41002
41082
|
const { writeFile: writeFile2 } = await Promise.resolve().then(() => (init_dist_js3(), dist_js_exports3));
|
|
41083
|
+
const finalName = getFinalFileName(fileName, defaultExt);
|
|
41084
|
+
const filters = getFileFilters(finalName);
|
|
41003
41085
|
const filePath = await save2({
|
|
41004
|
-
defaultPath:
|
|
41005
|
-
filters
|
|
41086
|
+
defaultPath: finalName,
|
|
41087
|
+
filters
|
|
41006
41088
|
});
|
|
41007
41089
|
if (!filePath) return void 0;
|
|
41008
41090
|
const buffer = await blob.arrayBuffer();
|
|
@@ -41136,10 +41218,6 @@ var printBlob = async (blob) => {
|
|
|
41136
41218
|
document.body.appendChild(iframe);
|
|
41137
41219
|
});
|
|
41138
41220
|
};
|
|
41139
|
-
var getFinalFileName = (fileName) => {
|
|
41140
|
-
if (!fileName) return "document.pdf";
|
|
41141
|
-
return fileName.endsWith(".pdf") ? fileName : `${fileName}.pdf`;
|
|
41142
|
-
};
|
|
41143
41221
|
function createPdfApi() {
|
|
41144
41222
|
return {
|
|
41145
41223
|
async generatePdfFromElement(element, options = {}) {
|
|
@@ -41170,16 +41248,29 @@ function createPdfApi() {
|
|
|
41170
41248
|
},
|
|
41171
41249
|
async downloadPdf(source, fileName) {
|
|
41172
41250
|
const pdfBlob = await normalizePdfBlob(source);
|
|
41173
|
-
const finalName = getFinalFileName(fileName);
|
|
41251
|
+
const finalName = getFinalFileName(fileName, "pdf");
|
|
41174
41252
|
if (isCapacitor && platform !== "web") {
|
|
41175
|
-
return await saveBlobCapacitor(pdfBlob, finalName);
|
|
41253
|
+
return await saveBlobCapacitor(pdfBlob, finalName, "pdf");
|
|
41176
41254
|
}
|
|
41177
41255
|
if (isTauri) {
|
|
41178
|
-
return await saveBlobTauri(pdfBlob, finalName);
|
|
41256
|
+
return await saveBlobTauri(pdfBlob, finalName, "pdf");
|
|
41179
41257
|
}
|
|
41180
41258
|
await downloadBlobWeb(pdfBlob, finalName);
|
|
41181
41259
|
return finalName;
|
|
41182
41260
|
},
|
|
41261
|
+
async downloadFile(source, fileName) {
|
|
41262
|
+
const fileBlob = await normalizeFileBlob(source);
|
|
41263
|
+
const finalName = getFinalFileName(fileName, "bin");
|
|
41264
|
+
const defaultExt = getFileExtension(finalName) || "bin";
|
|
41265
|
+
if (isCapacitor && platform !== "web") {
|
|
41266
|
+
return await saveBlobCapacitor(fileBlob, finalName, defaultExt);
|
|
41267
|
+
}
|
|
41268
|
+
if (isTauri) {
|
|
41269
|
+
return await saveBlobTauri(fileBlob, finalName, defaultExt);
|
|
41270
|
+
}
|
|
41271
|
+
await downloadBlobWeb(fileBlob, finalName);
|
|
41272
|
+
return finalName;
|
|
41273
|
+
},
|
|
41183
41274
|
async previewPdf(source, fileName = "preview.pdf") {
|
|
41184
41275
|
const pdfBlob = await normalizePdfBlob(source);
|
|
41185
41276
|
return await openPreview(pdfBlob, fileName);
|
|
@@ -41398,12 +41489,13 @@ function createPlatformApi(client) {
|
|
|
41398
41489
|
}
|
|
41399
41490
|
function createPaymentApi(client) {
|
|
41400
41491
|
return {
|
|
41401
|
-
create: async ({ amountZAR, appId = "tevrocsoft", mode = "web", account = "default", externalCallback = void 0 } = {}) => {
|
|
41492
|
+
create: async ({ amountZAR, appId = "tevrocsoft", mode = "web", account = "default", companyId, externalCallback = void 0 } = {}) => {
|
|
41402
41493
|
return await createPayment(amountZAR, {
|
|
41403
41494
|
appId,
|
|
41404
41495
|
serviceUrl: client.serviceUrl,
|
|
41405
41496
|
mode,
|
|
41406
41497
|
payAccount: account,
|
|
41498
|
+
companyId,
|
|
41407
41499
|
externalCallback
|
|
41408
41500
|
});
|
|
41409
41501
|
},
|