@tiquo/dom-package 1.3.0 → 1.3.2

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/README.md CHANGED
@@ -174,7 +174,7 @@ const completedOrders = await auth.getOrders({ status: 'completed' });
174
174
  **Options:**
175
175
  - `limit` - Number of orders to return (max 100, default 50)
176
176
  - `cursor` - Order ID to start after (for pagination)
177
- - `status` - Filter by status: `draft`, `pending`, `confirmed`, `processing`, `completed`, `cancelled`, `refunded`, `open_tab`
177
+ - `status` - Filter by status: `draft`, `pending`, `processing`, `completed`, `cancelled`, `refunded`, `open_tab`
178
178
 
179
179
  **Returns:**
180
180
  - `orders` - Array of order objects with items, totals, and status
package/dist/index.d.mts CHANGED
@@ -325,7 +325,7 @@ interface TiquoOrderItem {
325
325
  interface TiquoOrder {
326
326
  id: string;
327
327
  orderNumber: string;
328
- status: 'draft' | 'pending' | 'confirmed' | 'processing' | 'completed' | 'cancelled' | 'refunded' | 'open_tab';
328
+ status: 'draft' | 'pending' | 'processing' | 'completed' | 'cancelled' | 'refunded' | 'open_tab';
329
329
  paymentStatus: 'pending' | 'paid' | 'partial' | 'refunded' | 'partially_refunded' | 'failed' | 'cancelled';
330
330
  total: number;
331
331
  subtotal: number;
@@ -417,6 +417,7 @@ declare class TiquoAuth {
417
417
  private listeners;
418
418
  private refreshTimer;
419
419
  private isRefreshing;
420
+ private visibilityHandler;
420
421
  private broadcastChannel;
421
422
  private tabId;
422
423
  private isProcessingTabSync;
@@ -434,7 +435,9 @@ declare class TiquoAuth {
434
435
  */
435
436
  getUser(): Promise<TiquoSession | null>;
436
437
  /**
437
- * Check if user is currently authenticated
438
+ * Check if user is currently authenticated.
439
+ * Returns true if the access token is valid OR a refresh token exists
440
+ * (meaning the session can be restored via token refresh).
438
441
  */
439
442
  isAuthenticated(): boolean;
440
443
  /**
@@ -522,6 +525,7 @@ declare class TiquoAuth {
522
525
  private clearTokens;
523
526
  private notifyListeners;
524
527
  private scheduleRefresh;
528
+ private initVisibilityHandler;
525
529
  private log;
526
530
  private generateTabId;
527
531
  private initTabSync;
package/dist/index.d.ts CHANGED
@@ -325,7 +325,7 @@ interface TiquoOrderItem {
325
325
  interface TiquoOrder {
326
326
  id: string;
327
327
  orderNumber: string;
328
- status: 'draft' | 'pending' | 'confirmed' | 'processing' | 'completed' | 'cancelled' | 'refunded' | 'open_tab';
328
+ status: 'draft' | 'pending' | 'processing' | 'completed' | 'cancelled' | 'refunded' | 'open_tab';
329
329
  paymentStatus: 'pending' | 'paid' | 'partial' | 'refunded' | 'partially_refunded' | 'failed' | 'cancelled';
330
330
  total: number;
331
331
  subtotal: number;
@@ -417,6 +417,7 @@ declare class TiquoAuth {
417
417
  private listeners;
418
418
  private refreshTimer;
419
419
  private isRefreshing;
420
+ private visibilityHandler;
420
421
  private broadcastChannel;
421
422
  private tabId;
422
423
  private isProcessingTabSync;
@@ -434,7 +435,9 @@ declare class TiquoAuth {
434
435
  */
435
436
  getUser(): Promise<TiquoSession | null>;
436
437
  /**
437
- * Check if user is currently authenticated
438
+ * Check if user is currently authenticated.
439
+ * Returns true if the access token is valid OR a refresh token exists
440
+ * (meaning the session can be restored via token refresh).
438
441
  */
439
442
  isAuthenticated(): boolean;
440
443
  /**
@@ -522,6 +525,7 @@ declare class TiquoAuth {
522
525
  private clearTokens;
523
526
  private notifyListeners;
524
527
  private scheduleRefresh;
528
+ private initVisibilityHandler;
525
529
  private log;
526
530
  private generateTabId;
527
531
  private initTabSync;
package/dist/index.js CHANGED
@@ -650,6 +650,33 @@ function buildPhone(countryCode, nationalNumber) {
650
650
  }
651
651
 
652
652
  // src/index.ts
653
+ var _brandingPrinted = false;
654
+ function printTiquoBranding() {
655
+ if (_brandingPrinted) return;
656
+ if (typeof window === "undefined" || typeof console === "undefined") return;
657
+ _brandingPrinted = true;
658
+ try {
659
+ const art = [
660
+ " _ _ ",
661
+ "| |_(_) __ _ _ _ ___ ",
662
+ "| __| |/ _` | | | |/ _ \\ ",
663
+ "| |_| | (_| | |_| | (_) |",
664
+ " \\__|_|\\__, |\\__,_|\\___/ ",
665
+ " |_| "
666
+ ].join("\n");
667
+ console.log(
668
+ `%c${art}`,
669
+ "color:#6d28d9;font-weight:bold;font-size:12px;font-family:monospace"
670
+ );
671
+ console.log(
672
+ "%cLearn more at %chttps://tiquo.co",
673
+ "color:#6d28d9;font-size:11px",
674
+ "color:#6d28d9;font-size:11px;text-decoration:underline"
675
+ );
676
+ } catch {
677
+ }
678
+ }
679
+ printTiquoBranding();
653
680
  var TiquoAuthError = class extends Error {
654
681
  constructor(message, code, statusCode) {
655
682
  super(message);
@@ -684,9 +711,11 @@ var TiquoAuth = class {
684
711
  this.listeners = /* @__PURE__ */ new Set();
685
712
  this.refreshTimer = null;
686
713
  this.isRefreshing = false;
714
+ this.visibilityHandler = null;
687
715
  // Multi-tab sync
688
716
  this.broadcastChannel = null;
689
717
  this.isProcessingTabSync = false;
718
+ printTiquoBranding();
690
719
  if (!config.publicKey) {
691
720
  throw new TiquoAuthError("publicKey is required", "MISSING_PUBLIC_KEY");
692
721
  }
@@ -712,6 +741,7 @@ var TiquoAuth = class {
712
741
  }
713
742
  this.checkForInjectedTokens();
714
743
  this.restoreTokens();
744
+ this.initVisibilityHandler();
715
745
  }
716
746
  // ============================================
717
747
  // PUBLIC METHODS
@@ -788,10 +818,15 @@ var TiquoAuth = class {
788
818
  return this.refreshSession();
789
819
  }
790
820
  /**
791
- * Check if user is currently authenticated
821
+ * Check if user is currently authenticated.
822
+ * Returns true if the access token is valid OR a refresh token exists
823
+ * (meaning the session can be restored via token refresh).
792
824
  */
793
825
  isAuthenticated() {
794
- return !!this.accessToken && !isTokenExpired(this.accessToken, 0);
826
+ if (this.accessToken && !isTokenExpired(this.accessToken, 0)) {
827
+ return true;
828
+ }
829
+ return !!this.refreshToken;
795
830
  }
796
831
  /**
797
832
  * Update the authenticated customer's profile
@@ -1176,6 +1211,13 @@ var TiquoAuth = class {
1176
1211
  this.refreshToken = result.data.refresh_token;
1177
1212
  this.saveTokens();
1178
1213
  this.scheduleRefresh();
1214
+ if (this.session && this.accessToken) {
1215
+ const payload = decodeJWT(this.accessToken);
1216
+ if (payload?.exp) {
1217
+ this.session = { ...this.session, expiresAt: payload.exp * 1e3 };
1218
+ }
1219
+ this.notifyListeners();
1220
+ }
1179
1221
  this.broadcastTabSync("TOKEN_REFRESH");
1180
1222
  this.log("Token refreshed successfully");
1181
1223
  return true;
@@ -1301,8 +1343,22 @@ var TiquoAuth = class {
1301
1343
  this.refreshTimer = setTimeout(() => {
1302
1344
  this.performTokenRefresh();
1303
1345
  }, refreshIn);
1346
+ } else if (this.refreshToken) {
1347
+ this.performTokenRefresh();
1304
1348
  }
1305
1349
  }
1350
+ initVisibilityHandler() {
1351
+ if (typeof document === "undefined") return;
1352
+ this.visibilityHandler = () => {
1353
+ if (document.visibilityState === "visible" && this.accessToken && this.refreshToken) {
1354
+ if (isTokenExpired(this.accessToken, 300)) {
1355
+ this.log("Tab became visible with expiring token, refreshing");
1356
+ this.performTokenRefresh();
1357
+ }
1358
+ }
1359
+ };
1360
+ document.addEventListener("visibilitychange", this.visibilityHandler);
1361
+ }
1306
1362
  log(...args) {
1307
1363
  if (this.config.debug) {
1308
1364
  console.log("[TiquoAuth]", ...args);
@@ -1405,6 +1461,10 @@ var TiquoAuth = class {
1405
1461
  clearTimeout(this.refreshTimer);
1406
1462
  this.refreshTimer = null;
1407
1463
  }
1464
+ if (this.visibilityHandler) {
1465
+ document.removeEventListener("visibilitychange", this.visibilityHandler);
1466
+ this.visibilityHandler = null;
1467
+ }
1408
1468
  if (this.broadcastChannel) {
1409
1469
  this.broadcastChannel.close();
1410
1470
  this.broadcastChannel = null;
package/dist/index.mjs CHANGED
@@ -614,6 +614,33 @@ function buildPhone(countryCode, nationalNumber) {
614
614
  }
615
615
 
616
616
  // src/index.ts
617
+ var _brandingPrinted = false;
618
+ function printTiquoBranding() {
619
+ if (_brandingPrinted) return;
620
+ if (typeof window === "undefined" || typeof console === "undefined") return;
621
+ _brandingPrinted = true;
622
+ try {
623
+ const art = [
624
+ " _ _ ",
625
+ "| |_(_) __ _ _ _ ___ ",
626
+ "| __| |/ _` | | | |/ _ \\ ",
627
+ "| |_| | (_| | |_| | (_) |",
628
+ " \\__|_|\\__, |\\__,_|\\___/ ",
629
+ " |_| "
630
+ ].join("\n");
631
+ console.log(
632
+ `%c${art}`,
633
+ "color:#6d28d9;font-weight:bold;font-size:12px;font-family:monospace"
634
+ );
635
+ console.log(
636
+ "%cLearn more at %chttps://tiquo.co",
637
+ "color:#6d28d9;font-size:11px",
638
+ "color:#6d28d9;font-size:11px;text-decoration:underline"
639
+ );
640
+ } catch {
641
+ }
642
+ }
643
+ printTiquoBranding();
617
644
  var TiquoAuthError = class extends Error {
618
645
  constructor(message, code, statusCode) {
619
646
  super(message);
@@ -648,9 +675,11 @@ var TiquoAuth = class {
648
675
  this.listeners = /* @__PURE__ */ new Set();
649
676
  this.refreshTimer = null;
650
677
  this.isRefreshing = false;
678
+ this.visibilityHandler = null;
651
679
  // Multi-tab sync
652
680
  this.broadcastChannel = null;
653
681
  this.isProcessingTabSync = false;
682
+ printTiquoBranding();
654
683
  if (!config.publicKey) {
655
684
  throw new TiquoAuthError("publicKey is required", "MISSING_PUBLIC_KEY");
656
685
  }
@@ -676,6 +705,7 @@ var TiquoAuth = class {
676
705
  }
677
706
  this.checkForInjectedTokens();
678
707
  this.restoreTokens();
708
+ this.initVisibilityHandler();
679
709
  }
680
710
  // ============================================
681
711
  // PUBLIC METHODS
@@ -752,10 +782,15 @@ var TiquoAuth = class {
752
782
  return this.refreshSession();
753
783
  }
754
784
  /**
755
- * Check if user is currently authenticated
785
+ * Check if user is currently authenticated.
786
+ * Returns true if the access token is valid OR a refresh token exists
787
+ * (meaning the session can be restored via token refresh).
756
788
  */
757
789
  isAuthenticated() {
758
- return !!this.accessToken && !isTokenExpired(this.accessToken, 0);
790
+ if (this.accessToken && !isTokenExpired(this.accessToken, 0)) {
791
+ return true;
792
+ }
793
+ return !!this.refreshToken;
759
794
  }
760
795
  /**
761
796
  * Update the authenticated customer's profile
@@ -1140,6 +1175,13 @@ var TiquoAuth = class {
1140
1175
  this.refreshToken = result.data.refresh_token;
1141
1176
  this.saveTokens();
1142
1177
  this.scheduleRefresh();
1178
+ if (this.session && this.accessToken) {
1179
+ const payload = decodeJWT(this.accessToken);
1180
+ if (payload?.exp) {
1181
+ this.session = { ...this.session, expiresAt: payload.exp * 1e3 };
1182
+ }
1183
+ this.notifyListeners();
1184
+ }
1143
1185
  this.broadcastTabSync("TOKEN_REFRESH");
1144
1186
  this.log("Token refreshed successfully");
1145
1187
  return true;
@@ -1265,8 +1307,22 @@ var TiquoAuth = class {
1265
1307
  this.refreshTimer = setTimeout(() => {
1266
1308
  this.performTokenRefresh();
1267
1309
  }, refreshIn);
1310
+ } else if (this.refreshToken) {
1311
+ this.performTokenRefresh();
1268
1312
  }
1269
1313
  }
1314
+ initVisibilityHandler() {
1315
+ if (typeof document === "undefined") return;
1316
+ this.visibilityHandler = () => {
1317
+ if (document.visibilityState === "visible" && this.accessToken && this.refreshToken) {
1318
+ if (isTokenExpired(this.accessToken, 300)) {
1319
+ this.log("Tab became visible with expiring token, refreshing");
1320
+ this.performTokenRefresh();
1321
+ }
1322
+ }
1323
+ };
1324
+ document.addEventListener("visibilitychange", this.visibilityHandler);
1325
+ }
1270
1326
  log(...args) {
1271
1327
  if (this.config.debug) {
1272
1328
  console.log("[TiquoAuth]", ...args);
@@ -1369,6 +1425,10 @@ var TiquoAuth = class {
1369
1425
  clearTimeout(this.refreshTimer);
1370
1426
  this.refreshTimer = null;
1371
1427
  }
1428
+ if (this.visibilityHandler) {
1429
+ document.removeEventListener("visibilitychange", this.visibilityHandler);
1430
+ this.visibilityHandler = null;
1431
+ }
1372
1432
  if (this.broadcastChannel) {
1373
1433
  this.broadcastChannel.close();
1374
1434
  this.broadcastChannel = null;
package/package.json CHANGED
@@ -1,7 +1,8 @@
1
1
  {
2
2
  "name": "@tiquo/dom-package",
3
- "version": "1.3.0",
3
+ "version": "1.3.2",
4
4
  "description": "Tiquo SDK for third-party websites - authentication, customer profiles, orders, bookings, and enquiries",
5
+ "sideEffects": true,
5
6
  "publishConfig": {
6
7
  "access": "restricted"
7
8
  },