@jupiterdo/sdk 0.1.4 → 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/index.umd.js CHANGED
@@ -1,108 +1,10 @@
1
1
  (function (global, factory) {
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 = {}));
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
- const SKELETON_HTML = `
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,297 +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
- class Modal {
325
- constructor() {
326
- this.isOpen = false;
327
- this.overlay = null;
328
- this.container = null;
329
- this.closeButton = null;
330
- this.iframe = null;
331
- this.skeleton = null;
332
- this.initialized = false;
333
- this.onCloseCallback = null;
334
- this.messageHandler = null;
335
- }
336
- static getInstance() {
337
- if (!Modal.instance) {
338
- Modal.instance = new Modal();
339
- }
340
- return Modal.instance;
341
- }
342
- injectStyles() {
343
- if (document.getElementById("jupiter-modal-styles")) {
344
- return;
345
- }
346
- const style = document.createElement("style");
347
- style.id = "jupiter-modal-styles";
348
- style.textContent = MODAL_STYLES;
349
- document.head.appendChild(style);
350
- }
351
- initializeElements() {
352
- if (this.initialized) {
353
- return;
354
- }
355
- this.injectStyles();
356
- // Create overlay
357
- this.overlay = document.createElement("div");
358
- this.overlay.className = "jupiter-modal-overlay";
359
- this.overlay.addEventListener("click", (e) => {
360
- if (e.target === this.overlay) {
361
- this.close();
362
- }
363
- });
364
- document.body.appendChild(this.overlay);
365
- // Create container
366
- this.container = document.createElement("div");
367
- this.container.className = "jupiter-modal-container";
368
- // Create close button
369
- this.closeButton = document.createElement("button");
370
- this.closeButton.className = "jupiter-modal-close";
371
- this.closeButton.setAttribute("aria-label", "Close");
372
- this.closeButton.innerHTML = `
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
- this.closeButton.addEventListener("click", (e) => {
379
- e.preventDefault();
380
- e.stopPropagation();
381
- this.close();
382
- });
383
- this.container.appendChild(this.closeButton);
384
- // Create skeleton
385
- this.skeleton = document.createElement("div");
386
- this.skeleton.className = "jupiter-modal-skeleton hidden";
387
- this.skeleton.innerHTML = SKELETON_HTML;
388
- this.container.appendChild(this.skeleton);
389
- // Add container to body
390
- document.body.appendChild(this.container);
391
- this.initialized = true;
392
- }
393
- showModal(url) {
394
- // Show skeleton loader
395
- this.skeleton.classList.remove("hidden");
396
- // Create iframe (hidden initially)
397
- this.iframe = document.createElement("iframe");
398
- this.iframe.className = "jupiter-modal-iframe";
399
- this.iframe.src = url;
400
- this.iframe.setAttribute("allow", "payment");
401
- this.iframe.setAttribute("sandbox", "allow-scripts allow-same-origin allow-forms allow-popups allow-modals");
402
- this.iframe.style.opacity = "0";
403
- this.container.appendChild(this.iframe);
404
- // Show iframe and hide skeleton once loaded
405
- this.iframe.addEventListener("load", () => {
406
- if (this.iframe && this.skeleton) {
407
- this.skeleton.classList.add("hidden");
408
- this.iframe.style.opacity = "1";
409
- this.iframe.style.transition = "opacity 0.3s ease-out";
410
- }
411
- }, { once: true });
412
- // Show overlay and container
413
- this.overlay.classList.add("open");
414
- this.container.classList.add("open");
415
- // Prevent body scroll when modal is open
416
- document.body.style.overflow = "hidden";
417
- }
418
- hideModal() {
419
- var _a, _b, _c, _d;
420
- // Remove open class first, then add closing class
421
- (_a = this.overlay) === null || _a === void 0 ? void 0 : _a.classList.remove("open");
422
- (_b = this.container) === null || _b === void 0 ? void 0 : _b.classList.remove("open");
423
- (_c = this.overlay) === null || _c === void 0 ? void 0 : _c.classList.add("closing");
424
- (_d = this.container) === null || _d === void 0 ? void 0 : _d.classList.add("closing");
425
- // Remove classes and iframe after animation completes
426
- setTimeout(() => {
427
- var _a, _b;
428
- (_a = this.overlay) === null || _a === void 0 ? void 0 : _a.classList.remove("closing");
429
- (_b = this.container) === null || _b === void 0 ? void 0 : _b.classList.remove("closing");
430
- // Restore body scroll
431
- document.body.style.overflow = "";
432
- // Remove iframe
433
- if (this.iframe) {
434
- this.iframe.remove();
435
- this.iframe = null;
436
- }
437
- }, 300);
438
- }
439
- open(url, onClose, onMessage) {
440
- // If already open, do nothing
441
- if (this.isOpen) {
442
- return;
443
- }
444
- this.isOpen = true;
445
- this.onCloseCallback = onClose || null;
446
- // Set up message listener if callback provided
447
- if (onMessage) {
448
- this.messageHandler = onMessage;
449
- window.addEventListener("message", this.messageHandler);
450
- }
451
- this.initializeElements();
452
- this.showModal(url);
453
- }
454
- close() {
455
- if (!this.isOpen) {
456
- return;
457
- }
458
- this.isOpen = false;
459
- this.hideModal();
460
- // Remove message listener if it exists
461
- if (this.messageHandler) {
462
- window.removeEventListener("message", this.messageHandler);
463
- this.messageHandler = null;
464
- }
465
- // Call onClose callback if provided
466
- if (this.onCloseCallback) {
467
- this.onCloseCallback();
468
- this.onCloseCallback = null;
469
- }
470
- }
471
- destroy() {
472
- this.close();
473
- // Wait for close animation to complete before removing elements
474
- setTimeout(() => {
475
- var _a, _b;
476
- (_a = this.overlay) === null || _a === void 0 ? void 0 : _a.remove();
477
- (_b = this.container) === null || _b === void 0 ? void 0 : _b.remove();
478
- this.overlay = null;
479
- this.container = null;
480
- this.closeButton = null;
481
- this.iframe = null;
482
- this.skeleton = null;
483
- this.initialized = false;
484
- Modal.instance = null;
485
- }, 350);
486
- }
487
- static destroyInstance() {
488
- if (Modal.instance) {
489
- Modal.instance.destroy();
490
- }
491
- }
492
- }
493
- Modal.instance = null;
494
-
495
- /**
496
- * Main Jupiter SDK class
497
- */
498
- class Jupiter {
499
- /**
500
- * Initialize the Jupiter SDK
501
- *
502
- * @param config - Configuration options
503
- *
504
- * @example
505
- * ```js
506
- * const jupiter = new Jupiter({
507
- * apiKey: 'jup_prod-xxxxx',
508
- * environment: 'production'
509
- * });
510
- * ```
511
- */
512
- constructor(config) {
513
- this.isInUse = false;
514
- // Validate API key
515
- if (!config.apiKey) {
516
- throw {
517
- code: "INVALID_CONFIG",
518
- message: "apiKey is required",
519
- };
520
- }
521
- // Set configuration
522
- this.environment = config.environment || "production";
523
- this.api = new JupiterAPI(config);
524
- }
525
- /**
526
- * Authorize a payment amount and open loan application flow
527
- *
528
- * @example
529
- * ```js
530
- * jupiter.authorize({
531
- * amount: 100000, // $1,000.00 in cents
532
- * referenceId: "order_12345",
533
- * onComplete: ({ loanId, status, referenceId }) => {
534
- * console.log('Loan', loanId, 'is', status);
535
- * },
536
- * onCancel: () => console.log('User cancelled'),
537
- * onError: (error) => console.error(error)
538
- * });
539
- * ```
540
- */
541
- authorize({ amount, referenceId, onComplete, onCancel, onError, modalTimeout, }) {
542
- // Prevent multiple concurrent authorizations
543
- if (this.isInUse) {
544
- return;
545
- }
546
- // Validate inputs (throw immediately, don't call onError)
547
- if (typeof amount !== "number" || amount <= 0) {
548
- throw {
549
- code: "INVALID_AMOUNT",
550
- message: "Amount must be a positive number in cents",
551
- };
552
- }
553
- if (referenceId && referenceId.length > 255) {
554
- throw {
555
- code: "INVALID_REFERENCE_ID",
556
- message: "Reference ID must be 255 characters or less",
557
- };
558
- }
559
- this.isInUse = true;
560
- // Handle API call asynchronously internally
561
- this.api
562
- .createPaymentLink(amount, referenceId)
563
- .then((paymentLink) => {
564
- const paymentUrl = `${APP_URLS[this.environment]}/pay/${paymentLink.slug}`;
565
- // Track if authorization was completed via message
566
- let wasCompleted = false;
567
- const modal = Modal.getInstance();
568
- modal.open(paymentUrl,
569
- // onClose
570
- () => {
571
- this.isInUse = false;
572
- // If modal closes without completion message, treat as cancel
573
- if (!wasCompleted) {
574
- onCancel();
575
- }
576
- },
577
- // onMessage
578
- (event) => {
579
- if (event.origin !== new URL(APP_URLS[this.environment]).origin) {
580
- return;
581
- }
582
- if (event.data.type === "jupiter_loan_status") {
583
- wasCompleted = true;
584
- setTimeout(() => {
585
- modal.close();
586
- }, modalTimeout !== null && modalTimeout !== void 0 ? modalTimeout : 5000);
587
- this.isInUse = false;
588
- onComplete({
589
- loanId: event.data.loanId,
590
- status: event.data.status,
591
- });
592
- }
593
- });
594
- })
595
- .catch((error) => {
596
- this.isInUse = false;
597
- onError(error);
598
- });
599
- }
600
- }
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
+ }
601
514
 
602
- /**
603
- * Jupiter JavaScript SDK
604
- *
605
- * @packageDocumentation
606
- */
607
- // For UMD build - expose on window object
608
- if (typeof window !== "undefined") {
609
- window.Jupiter = Jupiter;
610
- window.JupiterModal = Modal;
611
- }
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
+ }
612
525
 
613
- exports.Jupiter = Jupiter;
614
- exports.Modal = Modal;
526
+ exports.Jupiter = Jupiter;
527
+ exports.Modal = Modal;
615
528
 
616
529
  }));
617
530
  //# sourceMappingURL=index.umd.js.map