@jupiterdo/sdk 0.1.5 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/constants.d.ts +0 -9
- package/dist/index.esm.js +76 -162
- package/dist/index.esm.js.map +1 -1
- package/dist/index.umd.js +300 -386
- package/dist/index.umd.js.map +1 -1
- package/dist/index.umd.min.js +1 -1
- package/dist/index.umd.min.js.map +1 -1
- package/dist/jupiter.d.ts +5 -8
- package/dist/types.d.ts +17 -13
- package/package.json +1 -1
- package/dist/api.d.ts +0 -13
package/dist/index.umd.js
CHANGED
|
@@ -1,108 +1,10 @@
|
|
|
1
1
|
(function (global, factory) {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
|
|
3
|
+
typeof define === 'function' && define.amd ? define(['exports'], factory) :
|
|
4
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.Jupiter = {}));
|
|
5
5
|
})(this, (function (exports) { 'use strict';
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
Copyright (c) Microsoft Corporation.
|
|
9
|
-
|
|
10
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
|
11
|
-
purpose with or without fee is hereby granted.
|
|
12
|
-
|
|
13
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
14
|
-
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
15
|
-
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
16
|
-
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
17
|
-
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
18
|
-
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
19
|
-
PERFORMANCE OF THIS SOFTWARE.
|
|
20
|
-
***************************************************************************** */
|
|
21
|
-
/* global Reflect, Promise, SuppressedError, Symbol, Iterator */
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
function __awaiter(thisArg, _arguments, P, generator) {
|
|
25
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
26
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
27
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
28
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
29
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
30
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
35
|
-
var e = new Error(message);
|
|
36
|
-
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* API base URLs for different environments
|
|
41
|
-
*/
|
|
42
|
-
const API_URLS = {
|
|
43
|
-
production: "https://api.jupiter.do",
|
|
44
|
-
sandbox: "https://api-sandbox.jupiter.do",
|
|
45
|
-
staging: "https://api-staging.jupiter.do",
|
|
46
|
-
localhost: "http://localhost:8000",
|
|
47
|
-
};
|
|
48
|
-
/**
|
|
49
|
-
* App URLs for different environments
|
|
50
|
-
*/
|
|
51
|
-
const APP_URLS = {
|
|
52
|
-
production: "https://jupiter.do",
|
|
53
|
-
sandbox: "https://sandbox.jupiter.do",
|
|
54
|
-
staging: "https://staging.jupiter.do",
|
|
55
|
-
localhost: "http://localhost:3000",
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* API client for communicating with Jupiter backend
|
|
60
|
-
*/
|
|
61
|
-
class JupiterAPI {
|
|
62
|
-
constructor(config) {
|
|
63
|
-
this.apiKey = config.apiKey;
|
|
64
|
-
this.baseUrl = API_URLS[config.environment || "production"];
|
|
65
|
-
}
|
|
66
|
-
createPaymentLink(amount, referenceId) {
|
|
67
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
68
|
-
var _a;
|
|
69
|
-
let response;
|
|
70
|
-
try {
|
|
71
|
-
response = yield fetch(`${this.baseUrl}/sdk/link/`, {
|
|
72
|
-
method: "POST",
|
|
73
|
-
headers: {
|
|
74
|
-
"Content-Type": "application/json",
|
|
75
|
-
Authorization: `Bearer ${this.apiKey}`,
|
|
76
|
-
},
|
|
77
|
-
body: JSON.stringify({
|
|
78
|
-
amount,
|
|
79
|
-
reference_id: referenceId,
|
|
80
|
-
}),
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
catch (error) {
|
|
84
|
-
// Handle network errors
|
|
85
|
-
throw {
|
|
86
|
-
code: "NETWORK_ERROR",
|
|
87
|
-
message: error instanceof Error ? error.message : "Unknown error",
|
|
88
|
-
};
|
|
89
|
-
}
|
|
90
|
-
if (!response.ok) {
|
|
91
|
-
const error = yield response.json().catch(() => ({}));
|
|
92
|
-
throw {
|
|
93
|
-
code: error.code || `HTTP_${response.status}`,
|
|
94
|
-
message: error.detail ||
|
|
95
|
-
((_a = error.amount) === null || _a === void 0 ? void 0 : _a[0]) ||
|
|
96
|
-
`API error: ${response.status} ${response.statusText}`,
|
|
97
|
-
details: error,
|
|
98
|
-
};
|
|
99
|
-
}
|
|
100
|
-
return response.json();
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
const MODAL_STYLES = `
|
|
7
|
+
const MODAL_STYLES = `
|
|
106
8
|
/* Animations */
|
|
107
9
|
@keyframes jupiter-fadeIn {
|
|
108
10
|
from { opacity: 0; }
|
|
@@ -301,7 +203,7 @@
|
|
|
301
203
|
}
|
|
302
204
|
}
|
|
303
205
|
`;
|
|
304
|
-
|
|
206
|
+
const SKELETON_HTML = `
|
|
305
207
|
<div style="display: flex; gap: 12px;">
|
|
306
208
|
<div class="jupiter-skeleton-item" style="width: 48px; height: 48px; border-radius: 50%;"></div>
|
|
307
209
|
<div >
|
|
@@ -321,296 +223,308 @@
|
|
|
321
223
|
<div class="jupiter-skeleton-item" style="width: 375px; height: 64px; border-radius: calc(infinity * 1px)"></div>
|
|
322
224
|
</div>
|
|
323
225
|
`;
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
226
|
+
class Modal {
|
|
227
|
+
constructor() {
|
|
228
|
+
this.isOpen = false;
|
|
229
|
+
this.overlay = null;
|
|
230
|
+
this.container = null;
|
|
231
|
+
this.closeButton = null;
|
|
232
|
+
this.iframe = null;
|
|
233
|
+
this.skeleton = null;
|
|
234
|
+
this.initialized = false;
|
|
235
|
+
this.onCloseCallback = null;
|
|
236
|
+
this.messageHandler = null;
|
|
237
|
+
}
|
|
238
|
+
static getInstance() {
|
|
239
|
+
if (!Modal.instance) {
|
|
240
|
+
Modal.instance = new Modal();
|
|
241
|
+
}
|
|
242
|
+
return Modal.instance;
|
|
243
|
+
}
|
|
244
|
+
injectStyles() {
|
|
245
|
+
if (document.getElementById("jupiter-modal-styles")) {
|
|
246
|
+
return;
|
|
247
|
+
}
|
|
248
|
+
const style = document.createElement("style");
|
|
249
|
+
style.id = "jupiter-modal-styles";
|
|
250
|
+
style.textContent = MODAL_STYLES;
|
|
251
|
+
document.head.appendChild(style);
|
|
252
|
+
}
|
|
253
|
+
initializeElements() {
|
|
254
|
+
if (this.initialized) {
|
|
255
|
+
return;
|
|
256
|
+
}
|
|
257
|
+
this.injectStyles();
|
|
258
|
+
// Create overlay
|
|
259
|
+
this.overlay = document.createElement("div");
|
|
260
|
+
this.overlay.className = "jupiter-modal-overlay";
|
|
261
|
+
this.overlay.addEventListener("click", (e) => {
|
|
262
|
+
if (e.target === this.overlay) {
|
|
263
|
+
this.close();
|
|
264
|
+
}
|
|
265
|
+
});
|
|
266
|
+
document.body.appendChild(this.overlay);
|
|
267
|
+
// Create container
|
|
268
|
+
this.container = document.createElement("div");
|
|
269
|
+
this.container.className = "jupiter-modal-container";
|
|
270
|
+
// Create close button
|
|
271
|
+
this.closeButton = document.createElement("button");
|
|
272
|
+
this.closeButton.className = "jupiter-modal-close";
|
|
273
|
+
this.closeButton.setAttribute("aria-label", "Close");
|
|
274
|
+
this.closeButton.innerHTML = `
|
|
373
275
|
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
|
374
276
|
<path d="M18 6 6 18"></path>
|
|
375
277
|
<path d="m6 6 12 12"></path>
|
|
376
278
|
</svg>
|
|
377
279
|
`;
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
280
|
+
this.closeButton.addEventListener("click", (e) => {
|
|
281
|
+
e.preventDefault();
|
|
282
|
+
e.stopPropagation();
|
|
283
|
+
this.close();
|
|
284
|
+
});
|
|
285
|
+
this.container.appendChild(this.closeButton);
|
|
286
|
+
// Create skeleton
|
|
287
|
+
this.skeleton = document.createElement("div");
|
|
288
|
+
this.skeleton.className = "jupiter-modal-skeleton hidden";
|
|
289
|
+
this.skeleton.innerHTML = SKELETON_HTML;
|
|
290
|
+
this.container.appendChild(this.skeleton);
|
|
291
|
+
// Add container to body
|
|
292
|
+
document.body.appendChild(this.container);
|
|
293
|
+
this.initialized = true;
|
|
294
|
+
}
|
|
295
|
+
showModal(url) {
|
|
296
|
+
// Show skeleton loader
|
|
297
|
+
this.skeleton.classList.remove("hidden");
|
|
298
|
+
// Create iframe (hidden initially)
|
|
299
|
+
this.iframe = document.createElement("iframe");
|
|
300
|
+
this.iframe.className = "jupiter-modal-iframe";
|
|
301
|
+
this.iframe.src = url;
|
|
302
|
+
this.iframe.setAttribute("allow", "camera; microphone; payment");
|
|
303
|
+
this.iframe.style.opacity = "0";
|
|
304
|
+
this.container.appendChild(this.iframe);
|
|
305
|
+
// Show iframe and hide skeleton once loaded
|
|
306
|
+
this.iframe.addEventListener("load", () => {
|
|
307
|
+
if (this.iframe && this.skeleton) {
|
|
308
|
+
this.skeleton.classList.add("hidden");
|
|
309
|
+
this.iframe.style.opacity = "1";
|
|
310
|
+
this.iframe.style.transition = "opacity 0.3s ease-out";
|
|
311
|
+
}
|
|
312
|
+
}, { once: true });
|
|
313
|
+
// Show overlay and container
|
|
314
|
+
this.overlay.classList.add("open");
|
|
315
|
+
this.container.classList.add("open");
|
|
316
|
+
// Prevent body scroll when modal is open
|
|
317
|
+
document.body.style.overflow = "hidden";
|
|
318
|
+
}
|
|
319
|
+
hideModal() {
|
|
320
|
+
var _a, _b, _c, _d;
|
|
321
|
+
// Remove open class first, then add closing class
|
|
322
|
+
(_a = this.overlay) === null || _a === void 0 ? void 0 : _a.classList.remove("open");
|
|
323
|
+
(_b = this.container) === null || _b === void 0 ? void 0 : _b.classList.remove("open");
|
|
324
|
+
(_c = this.overlay) === null || _c === void 0 ? void 0 : _c.classList.add("closing");
|
|
325
|
+
(_d = this.container) === null || _d === void 0 ? void 0 : _d.classList.add("closing");
|
|
326
|
+
// Remove classes and iframe after animation completes
|
|
327
|
+
setTimeout(() => {
|
|
328
|
+
var _a, _b;
|
|
329
|
+
(_a = this.overlay) === null || _a === void 0 ? void 0 : _a.classList.remove("closing");
|
|
330
|
+
(_b = this.container) === null || _b === void 0 ? void 0 : _b.classList.remove("closing");
|
|
331
|
+
// Restore body scroll
|
|
332
|
+
document.body.style.overflow = "";
|
|
333
|
+
// Remove iframe
|
|
334
|
+
if (this.iframe) {
|
|
335
|
+
this.iframe.remove();
|
|
336
|
+
this.iframe = null;
|
|
337
|
+
}
|
|
338
|
+
}, 300);
|
|
339
|
+
}
|
|
340
|
+
open(url, onClose, onMessage) {
|
|
341
|
+
// If already open, do nothing
|
|
342
|
+
if (this.isOpen) {
|
|
343
|
+
return;
|
|
344
|
+
}
|
|
345
|
+
this.isOpen = true;
|
|
346
|
+
this.onCloseCallback = onClose || null;
|
|
347
|
+
// Set up message listener if callback provided
|
|
348
|
+
if (onMessage) {
|
|
349
|
+
this.messageHandler = onMessage;
|
|
350
|
+
window.addEventListener("message", this.messageHandler);
|
|
351
|
+
}
|
|
352
|
+
this.initializeElements();
|
|
353
|
+
this.showModal(url);
|
|
354
|
+
}
|
|
355
|
+
close() {
|
|
356
|
+
if (!this.isOpen) {
|
|
357
|
+
return;
|
|
358
|
+
}
|
|
359
|
+
this.isOpen = false;
|
|
360
|
+
this.hideModal();
|
|
361
|
+
// Remove message listener if it exists
|
|
362
|
+
if (this.messageHandler) {
|
|
363
|
+
window.removeEventListener("message", this.messageHandler);
|
|
364
|
+
this.messageHandler = null;
|
|
365
|
+
}
|
|
366
|
+
// Call onClose callback if provided
|
|
367
|
+
if (this.onCloseCallback) {
|
|
368
|
+
this.onCloseCallback();
|
|
369
|
+
this.onCloseCallback = null;
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
destroy() {
|
|
373
|
+
this.close();
|
|
374
|
+
// Wait for close animation to complete before removing elements
|
|
375
|
+
setTimeout(() => {
|
|
376
|
+
var _a, _b;
|
|
377
|
+
(_a = this.overlay) === null || _a === void 0 ? void 0 : _a.remove();
|
|
378
|
+
(_b = this.container) === null || _b === void 0 ? void 0 : _b.remove();
|
|
379
|
+
this.overlay = null;
|
|
380
|
+
this.container = null;
|
|
381
|
+
this.closeButton = null;
|
|
382
|
+
this.iframe = null;
|
|
383
|
+
this.skeleton = null;
|
|
384
|
+
this.initialized = false;
|
|
385
|
+
Modal.instance = null;
|
|
386
|
+
}, 350);
|
|
387
|
+
}
|
|
388
|
+
static destroyInstance() {
|
|
389
|
+
if (Modal.instance) {
|
|
390
|
+
Modal.instance.destroy();
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
Modal.instance = null;
|
|
395
|
+
|
|
396
|
+
/**
|
|
397
|
+
* App URLs for different environments
|
|
398
|
+
*/
|
|
399
|
+
const APP_URLS = {
|
|
400
|
+
production: "https://jupiter.do",
|
|
401
|
+
sandbox: "https://sandbox.jupiter.do",
|
|
402
|
+
staging: "https://staging.jupiter.do",
|
|
403
|
+
localhost: "http://localhost:3000",
|
|
404
|
+
};
|
|
405
|
+
|
|
406
|
+
/**
|
|
407
|
+
* Decode the payload from a JWT session token.
|
|
408
|
+
* Returns null if the token is malformed or missing required fields.
|
|
409
|
+
*/
|
|
410
|
+
function decodeSessionPayload(token) {
|
|
411
|
+
try {
|
|
412
|
+
const parts = token.split(".");
|
|
413
|
+
if (parts.length !== 3) {
|
|
414
|
+
return null;
|
|
415
|
+
}
|
|
416
|
+
const payload = JSON.parse(atob(parts[1]));
|
|
417
|
+
if (!payload.slug || !payload.exp || payload.type !== "sdk_session") {
|
|
418
|
+
return null;
|
|
419
|
+
}
|
|
420
|
+
return payload;
|
|
421
|
+
}
|
|
422
|
+
catch (_a) {
|
|
423
|
+
return null;
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
/**
|
|
427
|
+
* Main Jupiter SDK class
|
|
428
|
+
*/
|
|
429
|
+
class Jupiter {
|
|
430
|
+
/**
|
|
431
|
+
* Initialize the Jupiter SDK
|
|
432
|
+
*
|
|
433
|
+
* @param config - Configuration options
|
|
434
|
+
*
|
|
435
|
+
* @example
|
|
436
|
+
* ```js
|
|
437
|
+
* const jupiter = new Jupiter({
|
|
438
|
+
* environment: 'production'
|
|
439
|
+
* });
|
|
440
|
+
* ```
|
|
441
|
+
*/
|
|
442
|
+
constructor(config = {}) {
|
|
443
|
+
this.isInUse = false;
|
|
444
|
+
this.environment = config.environment || "production";
|
|
445
|
+
}
|
|
446
|
+
/**
|
|
447
|
+
* Authorize a payment using a session token and open the loan application flow
|
|
448
|
+
*
|
|
449
|
+
* @example
|
|
450
|
+
* ```js
|
|
451
|
+
* jupiter.authorize({
|
|
452
|
+
* session: sessionTokenFromBackend,
|
|
453
|
+
* onComplete: ({ loanId, status }) => {
|
|
454
|
+
* console.log('Loan', loanId, 'is', status);
|
|
455
|
+
* },
|
|
456
|
+
* onCancel: () => console.log('User cancelled'),
|
|
457
|
+
* onError: (error) => console.error(error)
|
|
458
|
+
* });
|
|
459
|
+
* ```
|
|
460
|
+
*/
|
|
461
|
+
authorize({ session, onComplete, onCancel, onError, modalTimeout, }) {
|
|
462
|
+
// Prevent multiple concurrent authorizations
|
|
463
|
+
if (this.isInUse) {
|
|
464
|
+
return;
|
|
465
|
+
}
|
|
466
|
+
// Validate and decode session token
|
|
467
|
+
const payload = decodeSessionPayload(session);
|
|
468
|
+
if (!payload) {
|
|
469
|
+
onError({
|
|
470
|
+
code: "INVALID_SESSION",
|
|
471
|
+
message: "Invalid or malformed session token.",
|
|
472
|
+
});
|
|
473
|
+
return;
|
|
474
|
+
}
|
|
475
|
+
// Client-side expiry check for better UX
|
|
476
|
+
if (payload.exp < Date.now() / 1000) {
|
|
477
|
+
onError({
|
|
478
|
+
code: "SESSION_EXPIRED",
|
|
479
|
+
message: "Session has expired. Request a new session from your server.",
|
|
480
|
+
});
|
|
481
|
+
return;
|
|
482
|
+
}
|
|
483
|
+
this.isInUse = true;
|
|
484
|
+
const paymentUrl = `${APP_URLS[this.environment]}/pay/${payload.slug}`;
|
|
485
|
+
let wasCompleted = false;
|
|
486
|
+
const modal = Modal.getInstance();
|
|
487
|
+
modal.open(paymentUrl,
|
|
488
|
+
// onClose
|
|
489
|
+
() => {
|
|
490
|
+
this.isInUse = false;
|
|
491
|
+
if (!wasCompleted) {
|
|
492
|
+
onCancel();
|
|
493
|
+
}
|
|
494
|
+
},
|
|
495
|
+
// onMessage
|
|
496
|
+
(event) => {
|
|
497
|
+
if (event.origin !== new URL(APP_URLS[this.environment]).origin) {
|
|
498
|
+
return;
|
|
499
|
+
}
|
|
500
|
+
if (event.data.type === "jupiter_loan_status") {
|
|
501
|
+
wasCompleted = true;
|
|
502
|
+
setTimeout(() => {
|
|
503
|
+
modal.close();
|
|
504
|
+
}, modalTimeout !== null && modalTimeout !== void 0 ? modalTimeout : 5000);
|
|
505
|
+
this.isInUse = false;
|
|
506
|
+
onComplete({
|
|
507
|
+
loanId: event.data.loanId,
|
|
508
|
+
status: event.data.status,
|
|
509
|
+
});
|
|
510
|
+
}
|
|
511
|
+
});
|
|
512
|
+
}
|
|
513
|
+
}
|
|
600
514
|
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
515
|
+
/**
|
|
516
|
+
* Jupiter JavaScript SDK
|
|
517
|
+
*
|
|
518
|
+
* @packageDocumentation
|
|
519
|
+
*/
|
|
520
|
+
// For UMD build - expose on window object
|
|
521
|
+
if (typeof window !== "undefined") {
|
|
522
|
+
window.Jupiter = Jupiter;
|
|
523
|
+
window.JupiterModal = Modal;
|
|
524
|
+
}
|
|
611
525
|
|
|
612
|
-
|
|
613
|
-
|
|
526
|
+
exports.Jupiter = Jupiter;
|
|
527
|
+
exports.Modal = Modal;
|
|
614
528
|
|
|
615
529
|
}));
|
|
616
530
|
//# sourceMappingURL=index.umd.js.map
|