@saasquatch/squatch-js 2.8.2-31 → 2.8.2-32

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.
@@ -1234,235 +1234,561 @@ class EmbedWidget extends Widget {
1234
1234
  return isVerified && (noContainer || isComponent);
1235
1235
  }
1236
1236
  }
1237
- const _log$6 = browserExports.debug("squatch-js:POPUPwidget");
1238
- let popupId = 0;
1239
- class PopupWidget extends Widget {
1240
- constructor(params, trigger = ".squatchpop") {
1241
- super(params);
1242
- __publicField(this, "trigger");
1243
- __publicField(this, "id");
1244
- __publicField(this, "show", this.open);
1245
- __publicField(this, "hide", this.close);
1246
- this.trigger = trigger;
1247
- if (this.container) {
1248
- this.id = "squatchModal";
1249
- } else {
1250
- this.id = popupId === 0 ? `squatchModal` : `squatchModal__${popupId}`;
1251
- popupId = popupId + 1;
1252
- }
1253
- document.head.insertAdjacentHTML(
1254
- "beforeend",
1255
- `<style>#${this.id}::-webkit-scrollbar { display: none; }</style>`
1256
- );
1257
- }
1258
- _initialiseCTA() {
1259
- if (!this.trigger) return;
1260
- let triggerElement;
1261
- try {
1262
- triggerElement = document.querySelector(this.trigger) || document.querySelector(".impactpop");
1263
- if (this.trigger && !triggerElement)
1264
- _log$6("No element found with trigger selector", this.trigger);
1265
- } catch {
1266
- _log$6("Not a valid selector", this.trigger);
1267
- }
1268
- if (triggerElement) {
1269
- triggerElement.onclick = () => {
1270
- this.open();
1271
- };
1272
- }
1273
- }
1274
- _createPopupDialog() {
1275
- var _a2, _b, _c;
1276
- const dialog = document.createElement("dialog");
1277
- const brandingConfig = (_b = (_a2 = this.context.widgetConfig) == null ? void 0 : _a2.values) == null ? void 0 : _b.brandingConfig;
1278
- const sizes = (_c = brandingConfig == null ? void 0 : brandingConfig.widgetSize) == null ? void 0 : _c.popupWidgets;
1279
- const minWidth = (sizes == null ? void 0 : sizes.minWidth) ? formatWidth(sizes.minWidth) : "auto";
1280
- const maxWidth = (sizes == null ? void 0 : sizes.maxWidth) ? formatWidth(sizes.maxWidth) : "500px";
1281
- dialog.id = this.id;
1282
- dialog.setAttribute(
1283
- "style",
1284
- `width: 100%; min-width: ${minWidth}; max-width: ${maxWidth}; border: none; padding: 0;`
1285
- );
1286
- const onClick = (e) => {
1287
- e.stopPropagation();
1288
- if (e.target === dialog) dialog.close();
1289
- };
1290
- dialog.addEventListener("click", onClick);
1291
- return dialog;
1292
- }
1293
- async load() {
1294
- var _a2;
1295
- const frame = this._createFrame();
1296
- this._initialiseCTA();
1297
- const element = this.container ? this._findElement() : document.body;
1298
- const dialogParent = element.shadowRoot || element;
1299
- const dialog = this._createPopupDialog();
1300
- dialog.appendChild(frame);
1301
- if (((_a2 = dialogParent.lastChild) == null ? void 0 : _a2.nodeName) === "DIALOG") {
1302
- dialogParent.replaceChild(dialog, dialogParent.lastChild);
1303
- } else {
1304
- dialogParent.appendChild(dialog);
1305
- }
1306
- const { contentWindow } = frame;
1307
- if (!contentWindow) {
1308
- throw new Error("Frame needs a content window");
1309
- }
1310
- const frameDoc = contentWindow.document;
1311
- frameDoc.open();
1312
- frameDoc.write(this.content);
1313
- frameDoc.write(
1314
- `<script src="${this.npmCdn}/resize-observer-polyfill@1.5.x"><\/script>`
1315
- );
1316
- frameDoc.close();
1317
- _log$6("Popup template loaded into iframe");
1318
- await this._setupResizeHandler(frame);
1319
- }
1320
- async _setupResizeHandler(frame) {
1321
- const { contentWindow } = frame;
1322
- if (!contentWindow) {
1323
- throw new Error("Frame needs a content window");
1324
- }
1325
- const frameDoc = contentWindow.document;
1326
- domready(frameDoc, async () => {
1327
- frameDoc.body.style.overflowY = "hidden";
1328
- frame.height = `${frameDoc.body.offsetHeight}px`;
1329
- const ro = new contentWindow["ResizeObserver"]((entries) => {
1330
- for (const entry of entries) {
1331
- const { top, bottom } = entry.contentRect;
1332
- const computedHeight = bottom + top;
1333
- frame.height = computedHeight + "";
1334
- entry.target.style = ``;
1237
+ const getSkeleton = ({
1238
+ type = "verified-access",
1239
+ height = "500px",
1240
+ skeletonBackgroundColor = "#e0e0e0",
1241
+ skeletonShimmerColor = "#f5f5f5"
1242
+ }) => {
1243
+ const referrerHTML = `
1244
+ <div class="hero-section">
1245
+ <div class="hero-content">
1246
+ <div class="skeleton sk-title-lg"></div>
1247
+ <div class="skeleton sk-text"></div>
1248
+ <div class="skeleton sk-text sk-text-short"></div>
1249
+ </div>
1250
+ <div class="skeleton hero-image"></div>
1251
+ </div>
1252
+
1253
+ <div class="share-section">
1254
+ <div class="skeleton sk-label"></div>
1255
+ <div class="skeleton sk-input"></div>
1256
+ <div class="social-buttons">
1257
+ <div class="skeleton sk-btn-social"></div>
1258
+ <div class="skeleton sk-btn-social"></div>
1259
+ <div class="skeleton sk-btn-social"></div>
1260
+ <div class="skeleton sk-btn-social"></div>
1261
+ </div>
1262
+ </div>
1263
+
1264
+ <div class="skeleton sk-title-md" style="margin-top: 0; width: 30%; margin-left: auto; margin-right: auto"></div>
1265
+ <div class="skeleton sk-text" style="width: 60%; margin-left: auto; margin-right: auto"></div>
1266
+
1267
+ <div class="stats-section">
1268
+ <div class="stat-card">
1269
+ <div class="skeleton sk-stat-num"></div>
1270
+ <div class="skeleton sk-stat-label"></div>
1271
+ </div>
1272
+ <div class="stat-card stat-divider">
1273
+ <div class="skeleton sk-stat-num"></div>
1274
+ <div class="skeleton sk-stat-label"></div>
1275
+ </div>
1276
+ </div>
1277
+
1278
+ <div class="skeleton sk-title-md"></div>
1279
+
1280
+ <div class="table-header">
1281
+ <div class="skeleton sk-th col-user"></div>
1282
+ <div class="skeleton sk-th col-status"></div>
1283
+ <div class="skeleton sk-th col-reward"></div>
1284
+ <div class="skeleton sk-th col-date"></div>
1285
+ </div>
1286
+
1287
+ <div class="table-row">
1288
+ <div class="col-user"><div class="skeleton sk-text" style="width: 70%; margin: 0"></div></div>
1289
+ <div class="col-status"><div class="skeleton sk-badge" style="margin: 0"></div></div>
1290
+ <div class="col-reward"><div class="skeleton sk-reward-block" style="margin: 0"></div></div>
1291
+ <div class="col-date"><div class="skeleton sk-text" style="width: 80%; margin: 0"></div></div>
1292
+ </div>
1293
+
1294
+ <div class="table-row">
1295
+ <div class="col-user"><div class="skeleton sk-text" style="width: 60%; margin: 0"></div></div>
1296
+ <div class="col-status"><div class="skeleton sk-badge" style="margin: 0"></div></div>
1297
+ <div class="col-reward"><div class="skeleton sk-reward-block" style="margin: 0"></div></div>
1298
+ <div class="col-date"><div class="skeleton sk-text" style="width: 80%; margin: 0"></div></div>
1299
+ </div>
1300
+
1301
+ <div class="table-row">
1302
+ <div class="col-user"><div class="skeleton sk-text" style="width: 75%; margin: 0"></div></div>
1303
+ <div class="col-status"><div class="skeleton sk-badge" style="margin: 0"></div></div>
1304
+ <div class="col-reward"><div class="skeleton sk-reward-block" style="margin: 0"></div></div>
1305
+ <div class="col-date"><div class="skeleton sk-text" style="width: 80%; margin: 0"></div></div>
1306
+ </div>
1307
+
1308
+ <div class="pagination">
1309
+ <div class="skeleton sk-btn-page"></div>
1310
+ <div class="skeleton sk-btn-page"></div>
1311
+ </div>
1312
+ `;
1313
+ const instantAccessHTML = `
1314
+ <div class="hero-section instant-access-layout">
1315
+ <div class="skeleton hero-image ia-image"></div>
1316
+
1317
+ <div class="hero-content ia-content">
1318
+ <div class="skeleton sk-title-lg ia-center"></div>
1319
+ <div class="skeleton sk-text ia-center"></div>
1320
+
1321
+ <div class="skeleton sk-btn-action"></div>
1322
+
1323
+ <div class="skeleton sk-label"></div>
1324
+ <div class="input-group">
1325
+ <div class="skeleton sk-input"></div>
1326
+ <div class="skeleton sk-btn-copy"></div>
1327
+ </div>
1328
+
1329
+ <div class="skeleton sk-text-short ia-center" style="margin-top: 20px; width: 30%"></div>
1330
+ <div class="skeleton sk-text-short ia-center" style="width: 20%"></div>
1331
+ </div>
1332
+ </div>
1333
+ `;
1334
+ return `
1335
+ <style>
1336
+ * {
1337
+ box-sizing: border-box;
1338
+ padding: 0;
1339
+ margin: 0;
1335
1340
  }
1336
- });
1337
- ro.observe(await this._findInnerContainer(frame));
1338
- });
1339
- }
1340
- open() {
1341
- const element = this.container ? this._findElement() : document.body;
1342
- const parent = element.shadowRoot || element;
1343
- const dialog = parent.querySelector(`#${this.id}`);
1344
- if (!dialog) throw new Error("Could not determine container div");
1345
- dialog.showModal();
1346
- const frame = this._findFrame();
1347
- if (!frame) throw new Error("Could not find iframe");
1348
- const { contentWindow } = frame;
1349
- if (!contentWindow) throw new Error("Squatch.js has an empty iframe");
1350
- const frameDoc = contentWindow.document;
1351
- domready(frameDoc, () => {
1352
- var _a2;
1353
- const _sqh = contentWindow.squatch || contentWindow.widgetIdent;
1354
- (_a2 = frame.contentDocument) == null ? void 0 : _a2.dispatchEvent(new CustomEvent("sq:refresh"));
1355
- if (this.context.user) {
1356
- this._loadEvent(_sqh);
1357
- _log$6("Popup opened");
1358
- } else {
1359
- this._attachLoadEventListener(frameDoc, _sqh);
1341
+
1342
+ .widget-container {
1343
+ background: white;
1344
+ width: 100%;
1345
+ padding: 40px;
1346
+ box-sizing: border-box;
1347
+ overflow: hidden;
1360
1348
  }
1361
- });
1362
- }
1363
- close() {
1364
- const frame = this._findFrame();
1365
- if (frame == null ? void 0 : frame.contentDocument)
1366
- this._detachLoadEventListener(frame.contentDocument);
1367
- const element = this.container ? this._findElement() : document.body;
1368
- const parent = element.shadowRoot || element;
1369
- const dialog = parent.querySelector(`#${this.id}`);
1370
- if (!dialog) throw new Error("Could not determine container div");
1371
- dialog.close();
1372
- _log$6("Popup closed");
1373
- }
1374
- _clickedOutside({ target }) {
1375
- }
1376
- _error(rs, mode = "modal", style = "") {
1377
- const _style = "body { margin: 0; } .modal { box-shadow: none; border: 0; }";
1378
- return super._error(rs, mode, style || _style);
1379
- }
1380
- }
1381
- const _log$5 = browserExports.debug("squatch-js:widgets");
1382
- class Widgets {
1383
- /**
1384
- * Initialize a new {@link Widgets} instance.
1385
- *
1386
- * @param {ConfigOptions} config Config details
1387
- *
1388
- * @example <caption>Browser example</caption>
1389
- * var widgets = new squatch.Widgets({tenantAlias:'test_12b5bo1b25125'});
1390
- *
1391
- * @example <caption>Browserify/Webpack example</caption>
1392
- * var Widgets = require('@saasquatch/squatch-js').Widgets;
1393
- * var widgets = new Widgets({tenantAlias:'test_12b5bo1b25125'});
1394
- *
1395
- * @example <caption>Babel+Browserify/Webpack example</caption>
1396
- * import {Widgets} from '@saasquatch/squatch-js';
1397
- * let widgets = new Widgets({tenantAlias:'test_12b5bo1b25125'});
1398
- */
1399
- constructor(configin) {
1400
- /**
1401
- * Instance of {@link WidgetApi}
1402
- */
1403
- __publicField(this, "api");
1404
- /**
1405
- * Tenant alias of SaaSquatch tenant
1406
- */
1407
- __publicField(this, "tenantAlias");
1408
- /**
1409
- * SaaSquatch domain for API requests
1410
- * @default "https://app.referralsaasquatch.com"
1411
- */
1412
- __publicField(this, "domain");
1413
- /**
1414
- * Hosted CDN for npm packages
1415
- * @default "https://fast.ssqt.io/npm"
1416
- */
1417
- __publicField(this, "npmCdn");
1418
- const config = validateConfig(configin);
1419
- this.tenantAlias = config.tenantAlias;
1420
- this.domain = config.domain;
1421
- this.npmCdn = config.npmCdn;
1422
- this.api = new WidgetApi(config);
1349
+
1350
+ @keyframes shimmer {
1351
+ 0% { background-position: -100% 0; }
1352
+ 100% { background-position: 100% 0; }
1353
+ }
1354
+
1355
+ .skeleton {
1356
+ background: ${skeletonBackgroundColor};
1357
+ background: linear-gradient(
1358
+ 90deg,
1359
+ ${skeletonBackgroundColor} 25%,
1360
+ ${skeletonShimmerColor} 50%,
1361
+ ${skeletonBackgroundColor} 75%
1362
+ );
1363
+ background-size: 200% 100%;
1364
+ animation: shimmer 1.5s infinite linear;
1365
+ border-radius: 6px;
1366
+ margin-bottom: 12px;
1367
+ }
1368
+
1369
+ /* Typography Skeletons */
1370
+ .sk-title-lg { height: 36px; width: 80%; margin-bottom: 16px; }
1371
+ .sk-title-md { height: 28px; width: 30%; margin-bottom: 20px; margin-top: 40px; }
1372
+ .sk-text { height: 16px; width: 90%; margin-bottom: 8px; }
1373
+ .sk-text-short { width: 40%; }
1374
+ .sk-label { height: 14px; width: 25%; margin-bottom: 10px; }
1375
+
1376
+ /* Layouts */
1377
+ .hero-section {
1378
+ display: flex;
1379
+ gap: 40px;
1380
+ margin-bottom: 40px;
1381
+ padding-bottom: 40px;
1382
+ flex-direction: row;
1383
+ height: 100%;
1384
+ /* Removed border-bottom */
1385
+ }
1386
+
1387
+ .hero-content {
1388
+ flex: 1;
1389
+ display: flex;
1390
+ flex-direction: column;
1391
+ justify-content: center;
1392
+ }
1393
+
1394
+ .hero-image {
1395
+ flex: 1;
1396
+ height: 300px;
1397
+ border-radius: 12px;
1398
+ }
1399
+
1400
+ /* -- Specific Instant Access Overrides -- */
1401
+ .instant-access-layout {
1402
+ margin-bottom: 0;
1403
+ padding-bottom: 0;
1404
+ align-items: center;
1405
+ }
1406
+ .ia-image {
1407
+ height: 400px;
1408
+ }
1409
+ .ia-center {
1410
+ margin-left: auto;
1411
+ margin-right: auto;
1412
+ }
1413
+ .ia-content {
1414
+ align-items: center;
1415
+ text-align: center;
1416
+ }
1417
+ .sk-btn-action {
1418
+ height: 45px;
1419
+ width: 140px;
1420
+ border-radius: 6px;
1421
+ margin: 24px auto;
1422
+ }
1423
+ .input-group {
1424
+ display: flex;
1425
+ gap: 10px;
1426
+ width: 100%;
1427
+ max-width: 400px;
1428
+ }
1429
+ .sk-btn-copy {
1430
+ height: 50px;
1431
+ width: 120px;
1432
+ border-radius: 8px;
1433
+ }
1434
+ /* ------------------------------------- */
1435
+
1436
+ .share-section { margin-bottom: 40px; }
1437
+ .sk-input { height: 50px; width: 100%; border-radius: 8px; margin-bottom: 16px; }
1438
+
1439
+ .social-buttons { display: flex; gap: 12px; }
1440
+ .sk-btn-social { flex: 1; height: 50px; border-radius: 8px; }
1441
+
1442
+ .stats-section {
1443
+ display: flex;
1444
+ gap: 24px;
1445
+ margin-bottom: 40px;
1446
+ padding: 30px 0;
1447
+ /* Removed border-top and border-bottom */
1448
+ }
1449
+ .stat-card { flex: 1; display: flex; flex-direction: column; align-items: center; }
1450
+ .stat-divider { padding-left: 24px; }
1451
+ .sk-stat-num { height: 48px; width: 120px; margin-bottom: 8px; }
1452
+ .sk-stat-label { height: 18px; width: 80px; }
1453
+
1454
+ /* Table Styles */
1455
+ .table-header { display: flex; gap: 16px; margin-bottom: 16px; }
1456
+ .sk-th { height: 16px; }
1457
+ .table-row {
1458
+ display: flex;
1459
+ align-items: center;
1460
+ gap: 16px;
1461
+ padding: 16px 0;
1462
+ /* Removed border-bottom */
1463
+ }
1464
+
1465
+ .col-user { flex: 2; }
1466
+ .col-status { flex: 1; }
1467
+ .col-reward { flex: 2; }
1468
+ .col-date { flex: 1; }
1469
+
1470
+ .sk-badge { height: 28px; width: 90px; border-radius: 14px; }
1471
+ .sk-reward-block { height: 36px; width: 100%; border-radius: 6px; }
1472
+
1473
+ .pagination { display: flex; justify-content: flex-end; gap: 8px; margin-top: 24px; }
1474
+ .sk-btn-page { height: 36px; width: 64px; border-radius: 6px; margin-bottom: 0; }
1475
+
1476
+ @media (max-width: 768px) {
1477
+ body { padding: 20px; }
1478
+ .widget-container { padding: 24px; }
1479
+
1480
+ .hero-section { flex-direction: column-reverse; gap: 24px; }
1481
+ .instant-access-layout { flex-direction: column; }
1482
+
1483
+ .hero-image { height: 220px; width: 100%; }
1484
+ .sk-title-lg { width: 100%; }
1485
+
1486
+ .col-date { display: none; }
1487
+ }
1488
+ </style>
1489
+
1490
+ <div class="widget-container">
1491
+ ${type === "verified-access" ? referrerHTML : instantAccessHTML}
1492
+ </div>
1493
+ `;
1494
+ };
1495
+ const _log$6 = browserExports.debug("squatch-js:POPUPwidget");
1496
+ let popupId = 0;
1497
+ class PopupWidget extends Widget {
1498
+ constructor(params, trigger = ".squatchpop") {
1499
+ super(params);
1500
+ __publicField(this, "trigger");
1501
+ __publicField(this, "id");
1502
+ __publicField(this, "show", this.open);
1503
+ __publicField(this, "hide", this.close);
1504
+ this.trigger = trigger;
1505
+ if (this.container) {
1506
+ this.id = "squatchModal";
1507
+ } else {
1508
+ this.id = popupId === 0 ? `squatchModal` : `squatchModal__${popupId}`;
1509
+ popupId = popupId + 1;
1510
+ }
1511
+ document.head.insertAdjacentHTML(
1512
+ "beforeend",
1513
+ `<style>#${this.id}::-webkit-scrollbar { display: none; }</style>`
1514
+ );
1423
1515
  }
1424
- /**
1425
- * This function calls the {@link WidgetApi.upsertUser} method, and it renders
1426
- * the widget if it is successful. Otherwise it shows the "error" widget.
1427
- *
1428
- * @param {Object} config Config details
1429
- * @param {Object} config.user The user details
1430
- * @param {string} config.user.id The user id
1431
- * @param {string} config.user.accountId The user account id
1432
- * @param {WidgetType} config.widgetType The content of the widget
1433
- * @param {EngagementMedium} config.engagementMedium How to display the widget
1434
- * @param {string} config.jwt the JSON Web Token (JWT) that is used to validate the data (can be disabled)
1435
- * @param {HTMLElement | string | undefined} config.container Element to load the widget into
1436
- * @param {string | undefined} config.trigger Trigger element for opening the popup widget
1437
- *
1438
- * @return {Promise<WidgetResult>} json object if true, with a Widget and user details
1439
- */
1440
- async upsertUser(config) {
1441
- const raw = config;
1442
- const clean = validateWidgetConfig(raw);
1516
+ _initialiseCTA() {
1517
+ if (!this.trigger) return;
1518
+ let triggerElement;
1443
1519
  try {
1444
- const response = await this.api.upsertUser(clean);
1445
- return {
1446
- widget: this._renderWidget(response, clean, {
1447
- type: "upsert",
1448
- user: clean.user,
1449
- engagementMedium: config.engagementMedium,
1450
- container: config.container,
1451
- trigger: config.trigger,
1452
- widgetConfig: {
1453
- values: {
1454
- brandingConfig: response == null ? void 0 : response.brandingConfig
1455
- }
1456
- }
1457
- }),
1458
- user: response.user
1520
+ triggerElement = document.querySelector(this.trigger) || document.querySelector(".impactpop");
1521
+ if (this.trigger && !triggerElement)
1522
+ _log$6("No element found with trigger selector", this.trigger);
1523
+ } catch {
1524
+ _log$6("Not a valid selector", this.trigger);
1525
+ }
1526
+ if (triggerElement) {
1527
+ triggerElement.onclick = () => {
1528
+ this.open();
1459
1529
  };
1460
- } catch (err) {
1461
- _log$5(err);
1462
- if (err.apiErrorCode) {
1463
- this._renderErrorWidget(err, config.engagementMedium);
1464
- }
1465
- throw new Error(err);
1530
+ }
1531
+ }
1532
+ _createPopupDialog() {
1533
+ var _a2, _b, _c;
1534
+ const dialog = document.createElement("dialog");
1535
+ const brandingConfig = (_b = (_a2 = this.context.widgetConfig) == null ? void 0 : _a2.values) == null ? void 0 : _b.brandingConfig;
1536
+ const sizes = (_c = brandingConfig == null ? void 0 : brandingConfig.widgetSize) == null ? void 0 : _c.popupWidgets;
1537
+ const minWidth = (sizes == null ? void 0 : sizes.minWidth) ? formatWidth(sizes.minWidth) : "auto";
1538
+ const maxWidth = (sizes == null ? void 0 : sizes.maxWidth) ? formatWidth(sizes.maxWidth) : "500px";
1539
+ dialog.id = this.id;
1540
+ dialog.setAttribute(
1541
+ "style",
1542
+ `width: 100%; min-width: ${minWidth}; max-width: ${maxWidth}; border: none; padding: 0;`
1543
+ );
1544
+ const onClick = (e) => {
1545
+ e.stopPropagation();
1546
+ if (e.target === dialog) dialog.close();
1547
+ };
1548
+ dialog.addEventListener("click", onClick);
1549
+ return dialog;
1550
+ }
1551
+ /*
1552
+ async load() {
1553
+ const frame = this._createFrame();
1554
+ this._initialiseCTA();
1555
+
1556
+ const element = this.container ? this._findElement() : document.body;
1557
+
1558
+ const dialogParent = element.shadowRoot || element;
1559
+ const dialog = this._createPopupDialog();
1560
+ dialog.appendChild(frame);
1561
+
1562
+ const skeletonHTML = getSkeleton({
1563
+ height: "100%",
1564
+ type: "verified-access",
1565
+ });
1566
+
1567
+ const skeletonContainer = document.createElement("div");
1568
+ skeletonContainer.id = "loading-skeleton";
1569
+ skeletonContainer.innerHTML = skeletonHTML;
1570
+
1571
+ if (dialogParent.lastChild?.nodeName === "DIALOG") {
1572
+ // Was reloaded
1573
+ dialogParent.replaceChild(dialog, dialogParent.lastChild);
1574
+ } else {
1575
+ // First time rendering
1576
+ dialogParent.appendChild(dialog);
1577
+ }
1578
+
1579
+ const { contentWindow } = frame;
1580
+ if (!contentWindow) {
1581
+ throw new Error("Frame needs a content window");
1582
+ }
1583
+
1584
+ const frameDoc = contentWindow.document;
1585
+ frameDoc.open();
1586
+ frameDoc.write(this.content);
1587
+ frameDoc.write(
1588
+ `<script src="${this.npmCdn}/resize-observer-polyfill@1.5.x"><\/script>`
1589
+ );
1590
+ frameDoc.close();
1591
+ _log("Popup template loaded into iframe");
1592
+ await this._setupResizeHandler(frame);
1593
+ }
1594
+ */
1595
+ async load() {
1596
+ var _a2;
1597
+ const frame = this._createFrame();
1598
+ this._initialiseCTA();
1599
+ const element = this.container ? this._findElement() : document.body;
1600
+ const dialogParent = element.shadowRoot || element;
1601
+ const dialog = this._createPopupDialog();
1602
+ const skeletonHTML = getSkeleton({
1603
+ height: "100%",
1604
+ type: "verified-access"
1605
+ });
1606
+ const skeletonContainer = document.createElement("div");
1607
+ skeletonContainer.id = "loading-skeleton";
1608
+ skeletonContainer.innerHTML = skeletonHTML;
1609
+ skeletonContainer.style.width = "100%";
1610
+ frame.style.display = "none";
1611
+ dialog.appendChild(skeletonContainer);
1612
+ dialog.appendChild(frame);
1613
+ if (((_a2 = dialogParent.lastChild) == null ? void 0 : _a2.nodeName) === "DIALOG") {
1614
+ dialogParent.replaceChild(dialog, dialogParent.lastChild);
1615
+ } else {
1616
+ dialogParent.appendChild(dialog);
1617
+ }
1618
+ const removeSkeleton = () => {
1619
+ const skel = dialog.querySelector("#loading-skeleton");
1620
+ if (skel) {
1621
+ skel.remove();
1622
+ }
1623
+ frame.style.display = "block";
1624
+ };
1625
+ frame.addEventListener("sq:load", removeSkeleton);
1626
+ frame.addEventListener("load", removeSkeleton);
1627
+ const safetyTimer = setTimeout(() => {
1628
+ removeSkeleton();
1629
+ }, 5e3);
1630
+ const { contentWindow } = frame;
1631
+ if (!contentWindow) {
1632
+ throw new Error("Frame needs a content window");
1633
+ }
1634
+ const frameDoc = contentWindow.document;
1635
+ frameDoc.open();
1636
+ frameDoc.write(this.content);
1637
+ frameDoc.write(
1638
+ `<script src="${this.npmCdn}/resize-observer-polyfill@1.5.x"><\/script>`
1639
+ );
1640
+ frameDoc.close();
1641
+ _log$6("Popup template loaded into iframe");
1642
+ await this._setupResizeHandler(frame);
1643
+ clearTimeout(safetyTimer);
1644
+ removeSkeleton();
1645
+ }
1646
+ async _setupResizeHandler(frame) {
1647
+ const { contentWindow } = frame;
1648
+ if (!contentWindow) {
1649
+ throw new Error("Frame needs a content window");
1650
+ }
1651
+ const frameDoc = contentWindow.document;
1652
+ domready(frameDoc, async () => {
1653
+ frameDoc.body.style.overflowY = "hidden";
1654
+ frame.height = `${frameDoc.body.offsetHeight}px`;
1655
+ const ro = new contentWindow["ResizeObserver"]((entries) => {
1656
+ for (const entry of entries) {
1657
+ const { top, bottom } = entry.contentRect;
1658
+ const computedHeight = bottom + top;
1659
+ frame.height = computedHeight + "";
1660
+ entry.target.style = ``;
1661
+ }
1662
+ });
1663
+ ro.observe(await this._findInnerContainer(frame));
1664
+ });
1665
+ }
1666
+ open() {
1667
+ const element = this.container ? this._findElement() : document.body;
1668
+ const parent = element.shadowRoot || element;
1669
+ const dialog = parent.querySelector(`#${this.id}`);
1670
+ if (!dialog) throw new Error("Could not determine container div");
1671
+ dialog.showModal();
1672
+ const frame = this._findFrame();
1673
+ if (!frame) throw new Error("Could not find iframe");
1674
+ const { contentWindow } = frame;
1675
+ if (!contentWindow) throw new Error("Squatch.js has an empty iframe");
1676
+ const frameDoc = contentWindow.document;
1677
+ domready(frameDoc, () => {
1678
+ var _a2;
1679
+ const _sqh = contentWindow.squatch || contentWindow.widgetIdent;
1680
+ (_a2 = frame.contentDocument) == null ? void 0 : _a2.dispatchEvent(new CustomEvent("sq:refresh"));
1681
+ if (this.context.user) {
1682
+ this._loadEvent(_sqh);
1683
+ _log$6("Popup opened");
1684
+ } else {
1685
+ this._attachLoadEventListener(frameDoc, _sqh);
1686
+ }
1687
+ });
1688
+ }
1689
+ close() {
1690
+ const frame = this._findFrame();
1691
+ if (frame == null ? void 0 : frame.contentDocument)
1692
+ this._detachLoadEventListener(frame.contentDocument);
1693
+ const element = this.container ? this._findElement() : document.body;
1694
+ const parent = element.shadowRoot || element;
1695
+ const dialog = parent.querySelector(`#${this.id}`);
1696
+ if (!dialog) throw new Error("Could not determine container div");
1697
+ dialog.close();
1698
+ _log$6("Popup closed");
1699
+ }
1700
+ _clickedOutside({ target }) {
1701
+ }
1702
+ _error(rs, mode = "modal", style = "") {
1703
+ const _style = "body { margin: 0; } .modal { box-shadow: none; border: 0; }";
1704
+ return super._error(rs, mode, style || _style);
1705
+ }
1706
+ }
1707
+ const _log$5 = browserExports.debug("squatch-js:widgets");
1708
+ class Widgets {
1709
+ /**
1710
+ * Initialize a new {@link Widgets} instance.
1711
+ *
1712
+ * @param {ConfigOptions} config Config details
1713
+ *
1714
+ * @example <caption>Browser example</caption>
1715
+ * var widgets = new squatch.Widgets({tenantAlias:'test_12b5bo1b25125'});
1716
+ *
1717
+ * @example <caption>Browserify/Webpack example</caption>
1718
+ * var Widgets = require('@saasquatch/squatch-js').Widgets;
1719
+ * var widgets = new Widgets({tenantAlias:'test_12b5bo1b25125'});
1720
+ *
1721
+ * @example <caption>Babel+Browserify/Webpack example</caption>
1722
+ * import {Widgets} from '@saasquatch/squatch-js';
1723
+ * let widgets = new Widgets({tenantAlias:'test_12b5bo1b25125'});
1724
+ */
1725
+ constructor(configin) {
1726
+ /**
1727
+ * Instance of {@link WidgetApi}
1728
+ */
1729
+ __publicField(this, "api");
1730
+ /**
1731
+ * Tenant alias of SaaSquatch tenant
1732
+ */
1733
+ __publicField(this, "tenantAlias");
1734
+ /**
1735
+ * SaaSquatch domain for API requests
1736
+ * @default "https://app.referralsaasquatch.com"
1737
+ */
1738
+ __publicField(this, "domain");
1739
+ /**
1740
+ * Hosted CDN for npm packages
1741
+ * @default "https://fast.ssqt.io/npm"
1742
+ */
1743
+ __publicField(this, "npmCdn");
1744
+ const config = validateConfig(configin);
1745
+ this.tenantAlias = config.tenantAlias;
1746
+ this.domain = config.domain;
1747
+ this.npmCdn = config.npmCdn;
1748
+ this.api = new WidgetApi(config);
1749
+ }
1750
+ /**
1751
+ * This function calls the {@link WidgetApi.upsertUser} method, and it renders
1752
+ * the widget if it is successful. Otherwise it shows the "error" widget.
1753
+ *
1754
+ * @param {Object} config Config details
1755
+ * @param {Object} config.user The user details
1756
+ * @param {string} config.user.id The user id
1757
+ * @param {string} config.user.accountId The user account id
1758
+ * @param {WidgetType} config.widgetType The content of the widget
1759
+ * @param {EngagementMedium} config.engagementMedium How to display the widget
1760
+ * @param {string} config.jwt the JSON Web Token (JWT) that is used to validate the data (can be disabled)
1761
+ * @param {HTMLElement | string | undefined} config.container Element to load the widget into
1762
+ * @param {string | undefined} config.trigger Trigger element for opening the popup widget
1763
+ *
1764
+ * @return {Promise<WidgetResult>} json object if true, with a Widget and user details
1765
+ */
1766
+ async upsertUser(config) {
1767
+ const raw = config;
1768
+ const clean = validateWidgetConfig(raw);
1769
+ try {
1770
+ const response = await this.api.upsertUser(clean);
1771
+ return {
1772
+ widget: this._renderWidget(response, clean, {
1773
+ type: "upsert",
1774
+ user: clean.user,
1775
+ engagementMedium: config.engagementMedium,
1776
+ container: config.container,
1777
+ trigger: config.trigger,
1778
+ widgetConfig: {
1779
+ values: {
1780
+ brandingConfig: response == null ? void 0 : response.brandingConfig
1781
+ }
1782
+ }
1783
+ }),
1784
+ user: response.user
1785
+ };
1786
+ } catch (err) {
1787
+ _log$5(err);
1788
+ if (err.apiErrorCode) {
1789
+ this._renderErrorWidget(err, config.engagementMedium);
1790
+ }
1791
+ throw new Error(err);
1466
1792
  }
1467
1793
  }
1468
1794
  /**
@@ -1857,264 +2183,6 @@ function _getAutoConfig() {
1857
2183
  }
1858
2184
  };
1859
2185
  }
1860
- const getSkeleton = ({
1861
- type = "verified-access",
1862
- height = "500px",
1863
- skeletonBackgroundColor = "#e0e0e0",
1864
- skeletonShimmerColor = "#f5f5f5"
1865
- }) => {
1866
- const referrerHTML = `
1867
- <div class="hero-section">
1868
- <div class="hero-content">
1869
- <div class="skeleton sk-title-lg"></div>
1870
- <div class="skeleton sk-text"></div>
1871
- <div class="skeleton sk-text sk-text-short"></div>
1872
- </div>
1873
- <div class="skeleton hero-image"></div>
1874
- </div>
1875
-
1876
- <div class="share-section">
1877
- <div class="skeleton sk-label"></div>
1878
- <div class="skeleton sk-input"></div>
1879
- <div class="social-buttons">
1880
- <div class="skeleton sk-btn-social"></div>
1881
- <div class="skeleton sk-btn-social"></div>
1882
- <div class="skeleton sk-btn-social"></div>
1883
- <div class="skeleton sk-btn-social"></div>
1884
- </div>
1885
- </div>
1886
-
1887
- <div class="skeleton sk-title-md" style="margin-top: 0; width: 30%; margin-left: auto; margin-right: auto"></div>
1888
- <div class="skeleton sk-text" style="width: 60%; margin-left: auto; margin-right: auto"></div>
1889
-
1890
- <div class="stats-section">
1891
- <div class="stat-card">
1892
- <div class="skeleton sk-stat-num"></div>
1893
- <div class="skeleton sk-stat-label"></div>
1894
- </div>
1895
- <div class="stat-card stat-divider">
1896
- <div class="skeleton sk-stat-num"></div>
1897
- <div class="skeleton sk-stat-label"></div>
1898
- </div>
1899
- </div>
1900
-
1901
- <div class="skeleton sk-title-md"></div>
1902
-
1903
- <div class="table-header">
1904
- <div class="skeleton sk-th col-user"></div>
1905
- <div class="skeleton sk-th col-status"></div>
1906
- <div class="skeleton sk-th col-reward"></div>
1907
- <div class="skeleton sk-th col-date"></div>
1908
- </div>
1909
-
1910
- <div class="table-row">
1911
- <div class="col-user"><div class="skeleton sk-text" style="width: 70%; margin: 0"></div></div>
1912
- <div class="col-status"><div class="skeleton sk-badge" style="margin: 0"></div></div>
1913
- <div class="col-reward"><div class="skeleton sk-reward-block" style="margin: 0"></div></div>
1914
- <div class="col-date"><div class="skeleton sk-text" style="width: 80%; margin: 0"></div></div>
1915
- </div>
1916
-
1917
- <div class="table-row">
1918
- <div class="col-user"><div class="skeleton sk-text" style="width: 60%; margin: 0"></div></div>
1919
- <div class="col-status"><div class="skeleton sk-badge" style="margin: 0"></div></div>
1920
- <div class="col-reward"><div class="skeleton sk-reward-block" style="margin: 0"></div></div>
1921
- <div class="col-date"><div class="skeleton sk-text" style="width: 80%; margin: 0"></div></div>
1922
- </div>
1923
-
1924
- <div class="table-row">
1925
- <div class="col-user"><div class="skeleton sk-text" style="width: 75%; margin: 0"></div></div>
1926
- <div class="col-status"><div class="skeleton sk-badge" style="margin: 0"></div></div>
1927
- <div class="col-reward"><div class="skeleton sk-reward-block" style="margin: 0"></div></div>
1928
- <div class="col-date"><div class="skeleton sk-text" style="width: 80%; margin: 0"></div></div>
1929
- </div>
1930
-
1931
- <div class="pagination">
1932
- <div class="skeleton sk-btn-page"></div>
1933
- <div class="skeleton sk-btn-page"></div>
1934
- </div>
1935
- `;
1936
- const instantAccessHTML = `
1937
- <div class="hero-section instant-access-layout">
1938
- <div class="skeleton hero-image ia-image"></div>
1939
-
1940
- <div class="hero-content ia-content">
1941
- <div class="skeleton sk-title-lg ia-center"></div>
1942
- <div class="skeleton sk-text ia-center"></div>
1943
-
1944
- <div class="skeleton sk-btn-action"></div>
1945
-
1946
- <div class="skeleton sk-label"></div>
1947
- <div class="input-group">
1948
- <div class="skeleton sk-input"></div>
1949
- <div class="skeleton sk-btn-copy"></div>
1950
- </div>
1951
-
1952
- <div class="skeleton sk-text-short ia-center" style="margin-top: 20px; width: 30%"></div>
1953
- <div class="skeleton sk-text-short ia-center" style="width: 20%"></div>
1954
- </div>
1955
- </div>
1956
- `;
1957
- return `
1958
- <style>
1959
- * {
1960
- box-sizing: border-box;
1961
- padding: 0;
1962
- margin: 0;
1963
- }
1964
-
1965
- .widget-container {
1966
- background: white;
1967
- width: 100%;
1968
- padding: 40px;
1969
- box-sizing: border-box;
1970
- overflow: hidden;
1971
- }
1972
-
1973
- @keyframes shimmer {
1974
- 0% { background-position: -100% 0; }
1975
- 100% { background-position: 100% 0; }
1976
- }
1977
-
1978
- .skeleton {
1979
- background: ${skeletonBackgroundColor};
1980
- background: linear-gradient(
1981
- 90deg,
1982
- ${skeletonBackgroundColor} 25%,
1983
- ${skeletonShimmerColor} 50%,
1984
- ${skeletonBackgroundColor} 75%
1985
- );
1986
- background-size: 200% 100%;
1987
- animation: shimmer 1.5s infinite linear;
1988
- border-radius: 6px;
1989
- margin-bottom: 12px;
1990
- }
1991
-
1992
- /* Typography Skeletons */
1993
- .sk-title-lg { height: 36px; width: 80%; margin-bottom: 16px; }
1994
- .sk-title-md { height: 28px; width: 30%; margin-bottom: 20px; margin-top: 40px; }
1995
- .sk-text { height: 16px; width: 90%; margin-bottom: 8px; }
1996
- .sk-text-short { width: 40%; }
1997
- .sk-label { height: 14px; width: 25%; margin-bottom: 10px; }
1998
-
1999
- /* Layouts */
2000
- .hero-section {
2001
- display: flex;
2002
- gap: 40px;
2003
- margin-bottom: 40px;
2004
- padding-bottom: 40px;
2005
- flex-direction: row;
2006
- height: 100%;
2007
- /* Removed border-bottom */
2008
- }
2009
-
2010
- .hero-content {
2011
- flex: 1;
2012
- display: flex;
2013
- flex-direction: column;
2014
- justify-content: center;
2015
- }
2016
-
2017
- .hero-image {
2018
- flex: 1;
2019
- height: 300px;
2020
- border-radius: 12px;
2021
- }
2022
-
2023
- /* -- Specific Instant Access Overrides -- */
2024
- .instant-access-layout {
2025
- margin-bottom: 0;
2026
- padding-bottom: 0;
2027
- align-items: center;
2028
- }
2029
- .ia-image {
2030
- height: 400px;
2031
- }
2032
- .ia-center {
2033
- margin-left: auto;
2034
- margin-right: auto;
2035
- }
2036
- .ia-content {
2037
- align-items: center;
2038
- text-align: center;
2039
- }
2040
- .sk-btn-action {
2041
- height: 45px;
2042
- width: 140px;
2043
- border-radius: 6px;
2044
- margin: 24px auto;
2045
- }
2046
- .input-group {
2047
- display: flex;
2048
- gap: 10px;
2049
- width: 100%;
2050
- max-width: 400px;
2051
- }
2052
- .sk-btn-copy {
2053
- height: 50px;
2054
- width: 120px;
2055
- border-radius: 8px;
2056
- }
2057
- /* ------------------------------------- */
2058
-
2059
- .share-section { margin-bottom: 40px; }
2060
- .sk-input { height: 50px; width: 100%; border-radius: 8px; margin-bottom: 16px; }
2061
-
2062
- .social-buttons { display: flex; gap: 12px; }
2063
- .sk-btn-social { flex: 1; height: 50px; border-radius: 8px; }
2064
-
2065
- .stats-section {
2066
- display: flex;
2067
- gap: 24px;
2068
- margin-bottom: 40px;
2069
- padding: 30px 0;
2070
- /* Removed border-top and border-bottom */
2071
- }
2072
- .stat-card { flex: 1; display: flex; flex-direction: column; align-items: center; }
2073
- .stat-divider { padding-left: 24px; }
2074
- .sk-stat-num { height: 48px; width: 120px; margin-bottom: 8px; }
2075
- .sk-stat-label { height: 18px; width: 80px; }
2076
-
2077
- /* Table Styles */
2078
- .table-header { display: flex; gap: 16px; margin-bottom: 16px; }
2079
- .sk-th { height: 16px; }
2080
- .table-row {
2081
- display: flex;
2082
- align-items: center;
2083
- gap: 16px;
2084
- padding: 16px 0;
2085
- /* Removed border-bottom */
2086
- }
2087
-
2088
- .col-user { flex: 2; }
2089
- .col-status { flex: 1; }
2090
- .col-reward { flex: 2; }
2091
- .col-date { flex: 1; }
2092
-
2093
- .sk-badge { height: 28px; width: 90px; border-radius: 14px; }
2094
- .sk-reward-block { height: 36px; width: 100%; border-radius: 6px; }
2095
-
2096
- .pagination { display: flex; justify-content: flex-end; gap: 8px; margin-top: 24px; }
2097
- .sk-btn-page { height: 36px; width: 64px; border-radius: 6px; margin-bottom: 0; }
2098
-
2099
- @media (max-width: 768px) {
2100
- body { padding: 20px; }
2101
- .widget-container { padding: 24px; }
2102
-
2103
- .hero-section { flex-direction: column-reverse; gap: 24px; }
2104
- .instant-access-layout { flex-direction: column; }
2105
-
2106
- .hero-image { height: 220px; width: 100%; }
2107
- .sk-title-lg { width: 100%; }
2108
-
2109
- .col-date { display: none; }
2110
- }
2111
- </style>
2112
-
2113
- <div class="widget-container">
2114
- ${type === "verified-access" ? referrerHTML : instantAccessHTML}
2115
- </div>
2116
- `;
2117
- };
2118
2186
  const _log$2 = browserExports.debug("squatch-js:decodeUserJwt");
2119
2187
  function decodeUserJwt(tokenStr) {
2120
2188
  var _a2;