@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/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,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
- 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", "camera; microphone; payment");
401
- this.iframe.style.opacity = "0";
402
- this.container.appendChild(this.iframe);
403
- // Show iframe and hide skeleton once loaded
404
- this.iframe.addEventListener("load", () => {
405
- if (this.iframe && this.skeleton) {
406
- this.skeleton.classList.add("hidden");
407
- this.iframe.style.opacity = "1";
408
- this.iframe.style.transition = "opacity 0.3s ease-out";
409
- }
410
- }, { once: true });
411
- // Show overlay and container
412
- this.overlay.classList.add("open");
413
- this.container.classList.add("open");
414
- // Prevent body scroll when modal is open
415
- document.body.style.overflow = "hidden";
416
- }
417
- hideModal() {
418
- var _a, _b, _c, _d;
419
- // Remove open class first, then add closing class
420
- (_a = this.overlay) === null || _a === void 0 ? void 0 : _a.classList.remove("open");
421
- (_b = this.container) === null || _b === void 0 ? void 0 : _b.classList.remove("open");
422
- (_c = this.overlay) === null || _c === void 0 ? void 0 : _c.classList.add("closing");
423
- (_d = this.container) === null || _d === void 0 ? void 0 : _d.classList.add("closing");
424
- // Remove classes and iframe after animation completes
425
- setTimeout(() => {
426
- var _a, _b;
427
- (_a = this.overlay) === null || _a === void 0 ? void 0 : _a.classList.remove("closing");
428
- (_b = this.container) === null || _b === void 0 ? void 0 : _b.classList.remove("closing");
429
- // Restore body scroll
430
- document.body.style.overflow = "";
431
- // Remove iframe
432
- if (this.iframe) {
433
- this.iframe.remove();
434
- this.iframe = null;
435
- }
436
- }, 300);
437
- }
438
- open(url, onClose, onMessage) {
439
- // If already open, do nothing
440
- if (this.isOpen) {
441
- return;
442
- }
443
- this.isOpen = true;
444
- this.onCloseCallback = onClose || null;
445
- // Set up message listener if callback provided
446
- if (onMessage) {
447
- this.messageHandler = onMessage;
448
- window.addEventListener("message", this.messageHandler);
449
- }
450
- this.initializeElements();
451
- this.showModal(url);
452
- }
453
- close() {
454
- if (!this.isOpen) {
455
- return;
456
- }
457
- this.isOpen = false;
458
- this.hideModal();
459
- // Remove message listener if it exists
460
- if (this.messageHandler) {
461
- window.removeEventListener("message", this.messageHandler);
462
- this.messageHandler = null;
463
- }
464
- // Call onClose callback if provided
465
- if (this.onCloseCallback) {
466
- this.onCloseCallback();
467
- this.onCloseCallback = null;
468
- }
469
- }
470
- destroy() {
471
- this.close();
472
- // Wait for close animation to complete before removing elements
473
- setTimeout(() => {
474
- var _a, _b;
475
- (_a = this.overlay) === null || _a === void 0 ? void 0 : _a.remove();
476
- (_b = this.container) === null || _b === void 0 ? void 0 : _b.remove();
477
- this.overlay = null;
478
- this.container = null;
479
- this.closeButton = null;
480
- this.iframe = null;
481
- this.skeleton = null;
482
- this.initialized = false;
483
- Modal.instance = null;
484
- }, 350);
485
- }
486
- static destroyInstance() {
487
- if (Modal.instance) {
488
- Modal.instance.destroy();
489
- }
490
- }
491
- }
492
- Modal.instance = null;
493
-
494
- /**
495
- * Main Jupiter SDK class
496
- */
497
- class Jupiter {
498
- /**
499
- * Initialize the Jupiter SDK
500
- *
501
- * @param config - Configuration options
502
- *
503
- * @example
504
- * ```js
505
- * const jupiter = new Jupiter({
506
- * apiKey: 'jup_prod-xxxxx',
507
- * environment: 'production'
508
- * });
509
- * ```
510
- */
511
- constructor(config) {
512
- this.isInUse = false;
513
- // Validate API key
514
- if (!config.apiKey) {
515
- throw {
516
- code: "INVALID_CONFIG",
517
- message: "apiKey is required",
518
- };
519
- }
520
- // Set configuration
521
- this.environment = config.environment || "production";
522
- this.api = new JupiterAPI(config);
523
- }
524
- /**
525
- * Authorize a payment amount and open loan application flow
526
- *
527
- * @example
528
- * ```js
529
- * jupiter.authorize({
530
- * amount: 100000, // $1,000.00 in cents
531
- * referenceId: "order_12345",
532
- * onComplete: ({ loanId, status, referenceId }) => {
533
- * console.log('Loan', loanId, 'is', status);
534
- * },
535
- * onCancel: () => console.log('User cancelled'),
536
- * onError: (error) => console.error(error)
537
- * });
538
- * ```
539
- */
540
- authorize({ amount, referenceId, onComplete, onCancel, onError, modalTimeout, }) {
541
- // Prevent multiple concurrent authorizations
542
- if (this.isInUse) {
543
- return;
544
- }
545
- // Validate inputs (throw immediately, don't call onError)
546
- if (typeof amount !== "number" || amount <= 0) {
547
- throw {
548
- code: "INVALID_AMOUNT",
549
- message: "Amount must be a positive number in cents",
550
- };
551
- }
552
- if (referenceId && referenceId.length > 255) {
553
- throw {
554
- code: "INVALID_REFERENCE_ID",
555
- message: "Reference ID must be 255 characters or less",
556
- };
557
- }
558
- this.isInUse = true;
559
- // Handle API call asynchronously internally
560
- this.api
561
- .createPaymentLink(amount, referenceId)
562
- .then((paymentLink) => {
563
- const paymentUrl = `${APP_URLS[this.environment]}/pay/${paymentLink.slug}`;
564
- // Track if authorization was completed via message
565
- let wasCompleted = false;
566
- const modal = Modal.getInstance();
567
- modal.open(paymentUrl,
568
- // onClose
569
- () => {
570
- this.isInUse = false;
571
- // If modal closes without completion message, treat as cancel
572
- if (!wasCompleted) {
573
- onCancel();
574
- }
575
- },
576
- // onMessage
577
- (event) => {
578
- if (event.origin !== new URL(APP_URLS[this.environment]).origin) {
579
- return;
580
- }
581
- if (event.data.type === "jupiter_loan_status") {
582
- wasCompleted = true;
583
- setTimeout(() => {
584
- modal.close();
585
- }, modalTimeout !== null && modalTimeout !== void 0 ? modalTimeout : 5000);
586
- this.isInUse = false;
587
- onComplete({
588
- loanId: event.data.loanId,
589
- status: event.data.status,
590
- });
591
- }
592
- });
593
- })
594
- .catch((error) => {
595
- this.isInUse = false;
596
- onError(error);
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
- * Jupiter JavaScript SDK
603
- *
604
- * @packageDocumentation
605
- */
606
- // For UMD build - expose on window object
607
- if (typeof window !== "undefined") {
608
- window.Jupiter = Jupiter;
609
- window.JupiterModal = Modal;
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
- exports.Jupiter = Jupiter;
613
- exports.Modal = Modal;
526
+ exports.Jupiter = Jupiter;
527
+ exports.Modal = Modal;
614
528
 
615
529
  }));
616
530
  //# sourceMappingURL=index.umd.js.map