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/tevroc-sdk.umd.js
CHANGED
|
@@ -26284,7 +26284,7 @@ var Tevroc = (() => {
|
|
|
26284
26284
|
if (i4 !== -1) googleListeners.splice(i4, 1);
|
|
26285
26285
|
};
|
|
26286
26286
|
}
|
|
26287
|
-
var googleInitialized, googleListeners, authWindowRef, authCleanupTimer, authMessageListener, closeAllTauriWebviews, cleanupAuthWindow, handleCallback, initializeGoogleLogin, createGoogleLogin;
|
|
26287
|
+
var googleInitialized, googleListeners, authWindowRef, authCleanupTimer, authMessageListener, authTauriUnlisten, authHandled, closeAllTauriWebviews, cleanupAuthWindow, handleCallback, initializeGoogleLogin, createGoogleLogin;
|
|
26288
26288
|
var init_useGoogleAuth = __esm({
|
|
26289
26289
|
"src/services/useGoogleAuth.js"() {
|
|
26290
26290
|
init_esm3();
|
|
@@ -26296,6 +26296,8 @@ var Tevroc = (() => {
|
|
|
26296
26296
|
authWindowRef = null;
|
|
26297
26297
|
authCleanupTimer = null;
|
|
26298
26298
|
authMessageListener = null;
|
|
26299
|
+
authTauriUnlisten = null;
|
|
26300
|
+
authHandled = false;
|
|
26299
26301
|
closeAllTauriWebviews = async () => {
|
|
26300
26302
|
if (!isTauri) return;
|
|
26301
26303
|
try {
|
|
@@ -26332,6 +26334,14 @@ var Tevroc = (() => {
|
|
|
26332
26334
|
window.removeEventListener("message", authMessageListener);
|
|
26333
26335
|
authMessageListener = null;
|
|
26334
26336
|
}
|
|
26337
|
+
if (authTauriUnlisten) {
|
|
26338
|
+
try {
|
|
26339
|
+
await authTauriUnlisten();
|
|
26340
|
+
} catch (e2) {
|
|
26341
|
+
console.warn("Error removing Tauri auth listener:", e2);
|
|
26342
|
+
}
|
|
26343
|
+
authTauriUnlisten = null;
|
|
26344
|
+
}
|
|
26335
26345
|
if (authWindowRef) {
|
|
26336
26346
|
const currentAuthWindow = authWindowRef;
|
|
26337
26347
|
authWindowRef = null;
|
|
@@ -26365,6 +26375,8 @@ var Tevroc = (() => {
|
|
|
26365
26375
|
};
|
|
26366
26376
|
handleCallback = async (url) => {
|
|
26367
26377
|
try {
|
|
26378
|
+
if (authHandled) return;
|
|
26379
|
+
authHandled = true;
|
|
26368
26380
|
await cleanupAuthWindow();
|
|
26369
26381
|
if (!url?.includes("token=")) return;
|
|
26370
26382
|
const params = new URLSearchParams(url.split("?")[1]);
|
|
@@ -26446,6 +26458,17 @@ var Tevroc = (() => {
|
|
|
26446
26458
|
win.once("tauri://error", (e2) => {
|
|
26447
26459
|
console.error("Auth window error:", e2);
|
|
26448
26460
|
});
|
|
26461
|
+
try {
|
|
26462
|
+
const { listen: listen2 } = await Promise.resolve().then(() => (init_event(), event_exports));
|
|
26463
|
+
authTauriUnlisten = await listen2("google-auth", async (event) => {
|
|
26464
|
+
const token = event?.payload?.token;
|
|
26465
|
+
if (!token) return;
|
|
26466
|
+
const callbackUrl = `${window.location.href}${window.location.href.includes("?") ? "&" : "?"}token=${encodeURIComponent(token)}`;
|
|
26467
|
+
await handleCallback(callbackUrl);
|
|
26468
|
+
});
|
|
26469
|
+
} catch (e2) {
|
|
26470
|
+
console.warn("Tauri google-auth listener install failed:", e2);
|
|
26471
|
+
}
|
|
26449
26472
|
return;
|
|
26450
26473
|
}
|
|
26451
26474
|
const isLocalhost = true;
|
|
@@ -26578,19 +26601,38 @@ var Tevroc = (() => {
|
|
|
26578
26601
|
externalCallback
|
|
26579
26602
|
);
|
|
26580
26603
|
});
|
|
26604
|
+
await listen2("payment-result", async (event) => {
|
|
26605
|
+
if (paymentWindowRef) {
|
|
26606
|
+
try {
|
|
26607
|
+
await paymentWindowRef.close();
|
|
26608
|
+
paymentWindowRef = null;
|
|
26609
|
+
} catch (e2) {
|
|
26610
|
+
console.warn("Error closing Tauri payment window:", e2);
|
|
26611
|
+
}
|
|
26612
|
+
}
|
|
26613
|
+
const payload = event?.payload || {};
|
|
26614
|
+
const params = new URLSearchParams();
|
|
26615
|
+
if (payload.status) params.set("status", payload.status);
|
|
26616
|
+
if (payload.mode) params.set("mode", payload.mode);
|
|
26617
|
+
if (payload.app) params.set("app", payload.app);
|
|
26618
|
+
if (payload.checkoutId) params.set("checkoutId", payload.checkoutId);
|
|
26619
|
+
const url = `?${params.toString()}`;
|
|
26620
|
+
handlePaymentCallback(url, externalCallback);
|
|
26621
|
+
});
|
|
26581
26622
|
}
|
|
26582
26623
|
};
|
|
26583
26624
|
createPayment = async (amountZAR, {
|
|
26584
26625
|
appId = "tevrocsoft",
|
|
26585
26626
|
serviceUrl = "https://tevrocsoftapi.netlify.app",
|
|
26586
26627
|
payAccount = "default",
|
|
26628
|
+
companyId,
|
|
26587
26629
|
externalCallback = () => {
|
|
26588
26630
|
}
|
|
26589
26631
|
} = {}) => {
|
|
26590
26632
|
await initializePayment(externalCallback);
|
|
26591
26633
|
const cents = Math.round(Number(amountZAR) * 100);
|
|
26592
26634
|
const basePaymentUrl = `${serviceUrl.replace(/\/$/, "")}/yoco-pay`;
|
|
26593
|
-
const paymentUrl = `${basePaymentUrl}?mode=mobile&amount=${cents}&app=${appId}&account=${payAccount}`;
|
|
26635
|
+
const paymentUrl = `${basePaymentUrl}?mode=mobile&amount=${cents}&app=${appId}&account=${payAccount}${companyId ? `&companyId=${encodeURIComponent(companyId)}` : ""}`;
|
|
26594
26636
|
console.log(basePaymentUrl, paymentUrl);
|
|
26595
26637
|
if (isCapacitor) {
|
|
26596
26638
|
await Browser2.open({
|
|
@@ -26599,7 +26641,7 @@ var Tevroc = (() => {
|
|
|
26599
26641
|
return;
|
|
26600
26642
|
}
|
|
26601
26643
|
if (isTauri) {
|
|
26602
|
-
const url = `${basePaymentUrl}?mode=desktop&amount=${cents}&app=${appId}&account=${payAccount}`;
|
|
26644
|
+
const url = `${basePaymentUrl}?mode=desktop&amount=${cents}&app=${appId}&account=${payAccount}${companyId ? `&companyId=${encodeURIComponent(companyId)}` : ""}`;
|
|
26603
26645
|
const win = new WebviewWindow("payment", {
|
|
26604
26646
|
url,
|
|
26605
26647
|
title: "Complete Payment",
|
|
@@ -26619,7 +26661,7 @@ var Tevroc = (() => {
|
|
|
26619
26661
|
}
|
|
26620
26662
|
const isLocalhost = window.location.hostname === "localhost" || window.location.hostname === "127.0.0.1";
|
|
26621
26663
|
const mode = isLocalhost ? "localhost" : "netlify";
|
|
26622
|
-
const finalUrl = `${basePaymentUrl}?mode=${mode}&amount=${cents}&app=${appId}`;
|
|
26664
|
+
const finalUrl = `${basePaymentUrl}?mode=${mode}&amount=${cents}&app=${appId}${companyId ? `&companyId=${encodeURIComponent(companyId)}` : ""}`;
|
|
26623
26665
|
try {
|
|
26624
26666
|
const popup = window.open(finalUrl, "yocoPayment", "width=500,height=650");
|
|
26625
26667
|
if (!popup) {
|
|
@@ -40969,6 +41011,29 @@ var Tevroc = (() => {
|
|
|
40969
41011
|
}
|
|
40970
41012
|
throw new Error("Unsupported PDF source. Pass a Blob or a jsPDF document instance.");
|
|
40971
41013
|
};
|
|
41014
|
+
var normalizeFileBlob = async (input) => {
|
|
41015
|
+
if (!input) {
|
|
41016
|
+
throw new Error("File source is required");
|
|
41017
|
+
}
|
|
41018
|
+
if (input instanceof Blob) {
|
|
41019
|
+
return input;
|
|
41020
|
+
}
|
|
41021
|
+
if (typeof input.output === "function") {
|
|
41022
|
+
const output = input.output("blob");
|
|
41023
|
+
return output instanceof Promise ? await output : output;
|
|
41024
|
+
}
|
|
41025
|
+
if (input instanceof ArrayBuffer) {
|
|
41026
|
+
return new Blob([input]);
|
|
41027
|
+
}
|
|
41028
|
+
if (input instanceof Uint8Array) {
|
|
41029
|
+
return new Blob([input]);
|
|
41030
|
+
}
|
|
41031
|
+
if (input && typeof input.arrayBuffer === "function") {
|
|
41032
|
+
const buffer = await input.arrayBuffer();
|
|
41033
|
+
return new Blob([buffer]);
|
|
41034
|
+
}
|
|
41035
|
+
throw new Error("Unsupported file source. Pass a Blob, ArrayBuffer, Uint8Array, or a jsPDF document instance.");
|
|
41036
|
+
};
|
|
40972
41037
|
var createObjectUrl = (blob) => {
|
|
40973
41038
|
return URL.createObjectURL(blob);
|
|
40974
41039
|
};
|
|
@@ -40983,10 +41048,25 @@ var Tevroc = (() => {
|
|
|
40983
41048
|
document.body.removeChild(a3);
|
|
40984
41049
|
URL.revokeObjectURL(url);
|
|
40985
41050
|
};
|
|
40986
|
-
var
|
|
41051
|
+
var getFileExtension = (fileName) => {
|
|
41052
|
+
if (!fileName) return "";
|
|
41053
|
+
const parts = String(fileName).trim().split(".");
|
|
41054
|
+
return parts.length > 1 ? parts.pop().toLowerCase() : "";
|
|
41055
|
+
};
|
|
41056
|
+
var getFileFilters = (fileName) => {
|
|
41057
|
+
const ext = getFileExtension(fileName);
|
|
41058
|
+
if (!ext) return [];
|
|
41059
|
+
return [{ name: ext.toUpperCase(), extensions: [ext] }];
|
|
41060
|
+
};
|
|
41061
|
+
var getFinalFileName = (fileName, defaultExt = "pdf") => {
|
|
41062
|
+
if (!fileName) return `document.${defaultExt}`;
|
|
41063
|
+
if (String(fileName).includes(".")) return fileName;
|
|
41064
|
+
return `${fileName}.${defaultExt}`;
|
|
41065
|
+
};
|
|
41066
|
+
var saveBlobCapacitor = async (blob, fileName, defaultExt = "pdf") => {
|
|
40987
41067
|
const { Filesystem: Filesystem2, Directory: Directory2 } = await Promise.resolve().then(() => (init_esm4(), esm_exports4));
|
|
40988
41068
|
const { Toast: Toast2 } = await Promise.resolve().then(() => (init_esm5(), esm_exports5));
|
|
40989
|
-
const finalName =
|
|
41069
|
+
const finalName = getFinalFileName(fileName, defaultExt);
|
|
40990
41070
|
const base64 = await blobToBase64(blob);
|
|
40991
41071
|
await Filesystem2.writeFile({
|
|
40992
41072
|
path: finalName,
|
|
@@ -41007,12 +41087,14 @@ var Tevroc = (() => {
|
|
|
41007
41087
|
}
|
|
41008
41088
|
return uri?.uri ?? finalName;
|
|
41009
41089
|
};
|
|
41010
|
-
var saveBlobTauri = async (blob, fileName) => {
|
|
41090
|
+
var saveBlobTauri = async (blob, fileName, defaultExt = "pdf") => {
|
|
41011
41091
|
const { save: save2 } = await Promise.resolve().then(() => (init_dist_js2(), dist_js_exports2));
|
|
41012
41092
|
const { writeFile: writeFile2 } = await Promise.resolve().then(() => (init_dist_js3(), dist_js_exports3));
|
|
41093
|
+
const finalName = getFinalFileName(fileName, defaultExt);
|
|
41094
|
+
const filters = getFileFilters(finalName);
|
|
41013
41095
|
const filePath = await save2({
|
|
41014
|
-
defaultPath:
|
|
41015
|
-
filters
|
|
41096
|
+
defaultPath: finalName,
|
|
41097
|
+
filters
|
|
41016
41098
|
});
|
|
41017
41099
|
if (!filePath) return void 0;
|
|
41018
41100
|
const buffer = await blob.arrayBuffer();
|
|
@@ -41146,10 +41228,6 @@ var Tevroc = (() => {
|
|
|
41146
41228
|
document.body.appendChild(iframe);
|
|
41147
41229
|
});
|
|
41148
41230
|
};
|
|
41149
|
-
var getFinalFileName = (fileName) => {
|
|
41150
|
-
if (!fileName) return "document.pdf";
|
|
41151
|
-
return fileName.endsWith(".pdf") ? fileName : `${fileName}.pdf`;
|
|
41152
|
-
};
|
|
41153
41231
|
function createPdfApi() {
|
|
41154
41232
|
return {
|
|
41155
41233
|
async generatePdfFromElement(element, options = {}) {
|
|
@@ -41180,16 +41258,29 @@ var Tevroc = (() => {
|
|
|
41180
41258
|
},
|
|
41181
41259
|
async downloadPdf(source, fileName) {
|
|
41182
41260
|
const pdfBlob = await normalizePdfBlob(source);
|
|
41183
|
-
const finalName = getFinalFileName(fileName);
|
|
41261
|
+
const finalName = getFinalFileName(fileName, "pdf");
|
|
41184
41262
|
if (isCapacitor && platform !== "web") {
|
|
41185
|
-
return await saveBlobCapacitor(pdfBlob, finalName);
|
|
41263
|
+
return await saveBlobCapacitor(pdfBlob, finalName, "pdf");
|
|
41186
41264
|
}
|
|
41187
41265
|
if (isTauri) {
|
|
41188
|
-
return await saveBlobTauri(pdfBlob, finalName);
|
|
41266
|
+
return await saveBlobTauri(pdfBlob, finalName, "pdf");
|
|
41189
41267
|
}
|
|
41190
41268
|
await downloadBlobWeb(pdfBlob, finalName);
|
|
41191
41269
|
return finalName;
|
|
41192
41270
|
},
|
|
41271
|
+
async downloadFile(source, fileName) {
|
|
41272
|
+
const fileBlob = await normalizeFileBlob(source);
|
|
41273
|
+
const finalName = getFinalFileName(fileName, "bin");
|
|
41274
|
+
const defaultExt = getFileExtension(finalName) || "bin";
|
|
41275
|
+
if (isCapacitor && platform !== "web") {
|
|
41276
|
+
return await saveBlobCapacitor(fileBlob, finalName, defaultExt);
|
|
41277
|
+
}
|
|
41278
|
+
if (isTauri) {
|
|
41279
|
+
return await saveBlobTauri(fileBlob, finalName, defaultExt);
|
|
41280
|
+
}
|
|
41281
|
+
await downloadBlobWeb(fileBlob, finalName);
|
|
41282
|
+
return finalName;
|
|
41283
|
+
},
|
|
41193
41284
|
async previewPdf(source, fileName = "preview.pdf") {
|
|
41194
41285
|
const pdfBlob = await normalizePdfBlob(source);
|
|
41195
41286
|
return await openPreview(pdfBlob, fileName);
|
|
@@ -41408,12 +41499,13 @@ var Tevroc = (() => {
|
|
|
41408
41499
|
}
|
|
41409
41500
|
function createPaymentApi(client) {
|
|
41410
41501
|
return {
|
|
41411
|
-
create: async ({ amountZAR, appId = "tevrocsoft", mode = "web", account = "default", externalCallback = void 0 } = {}) => {
|
|
41502
|
+
create: async ({ amountZAR, appId = "tevrocsoft", mode = "web", account = "default", companyId, externalCallback = void 0 } = {}) => {
|
|
41412
41503
|
return await createPayment(amountZAR, {
|
|
41413
41504
|
appId,
|
|
41414
41505
|
serviceUrl: client.serviceUrl,
|
|
41415
41506
|
mode,
|
|
41416
41507
|
payAccount: account,
|
|
41508
|
+
companyId,
|
|
41417
41509
|
externalCallback
|
|
41418
41510
|
});
|
|
41419
41511
|
},
|