@auxilium/datalynk-client 1.0.8 → 1.0.11

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
@@ -184,12 +184,13 @@ This library comes with some logic to automatically handle the login flow & shou
184
184
  2. It will check the localStorage for a saved token
185
185
  3. It will prompt the user to login via UI
186
186
  4. Reload page if token changed
187
+
187
188
  ```js
188
189
  await api.auth.handleLogin('spoke', {
189
- background: 'url("...")', // CSS URL or hex color
190
- color: '#ff0000', // hex color
191
- title: '<img alt="logo" src="..." />', // text or HTML
192
- titleColor: '#ffffff' // Color of title text
190
+ background: 'url("...")', // CSS URL or hex color
191
+ color: '#ff0000', // hex color
192
+ title: '<img alt="logo" src="..." />', // text or HTML
193
+ textColor: '#ffffff' // Color of title text
193
194
  });
194
195
  ```
195
196
 
package/dist/api.d.ts CHANGED
@@ -40,6 +40,8 @@ export interface ApiRequestOptions {
40
40
  noOptimize?: boolean;
41
41
  /** Skip the token translating step */
42
42
  raw?: boolean;
43
+ /** Set request token */
44
+ token?: string;
43
45
  }
44
46
  /** API error response */
45
47
  export interface ApiError {
package/dist/api.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,eAAe,EAAuB,MAAM,MAAM,CAAC;AAC3D,OAAO,EAAC,IAAI,EAAC,MAAM,QAAQ,CAAC;AAC5B,OAAO,EAAC,KAAK,EAAC,MAAM,SAAS,CAAC;AAC9B,OAAO,EAAC,GAAG,EAAC,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAC,KAAK,EAAC,MAAM,SAAS,CAAC;AAC9B,OAAO,EAAC,MAAM,EAAC,MAAM,UAAU,CAAC;AAChC,OAAO,EAAC,SAAS,EAAC,MAAM,aAAa,CAAC;AAGtC,MAAM,MAAM,UAAU,GAAG;IACxB,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAA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B;;;;;;OAMG;IACH,OAAO,CAAC,MAAM,CAAC,eAAe;IAsB9B;;;;OAIG;IACI,KAAK,CAAC,GAAG,QAAQ,EAAE,CAAC,GAAG,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,EAAE;IAe9C;;;;OAIG;IACI,QAAQ,CAAC,OAAO,EAAE;QAAC,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;KAAC;IAiB7C;;;;;;OAMG;IACI,KAAK,CAAC,CAAC,GAAG,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,OAAO,GAAE,iBAAsB,GAAG,OAAO,CAAC,CAAC,CAAC;IAU7E;;;;;;;;;;;OAWG;IACI,OAAO,CAAC,CAAC,GAAG,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,OAAO,GAAE,iBAAsB,GAAG,OAAO,CAAC,CAAC,CAAC;IAqC/E;;;;;;;;;;;;OAYG;IACI,KAAK,CAAC,CAAC,GAAG,GAAG,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM;CAG5C"}
package/dist/auth.d.ts CHANGED
@@ -44,7 +44,7 @@ export declare class Auth {
44
44
  *
45
45
  * @return {Promise<User | null>}
46
46
  */
47
- current(): Promise<null | User>;
47
+ current(token?: string | null, set?: boolean): Promise<null | User>;
48
48
  /**
49
49
  * Automatically handle sessions by checking localStorage & URL parameters for a token & prompting
50
50
  * user with a login screen if required
@@ -91,7 +91,7 @@ export declare class Auth {
91
91
  * @param {string} password Password for account
92
92
  * @param {string} spoke Override login spoke
93
93
  * @param {twoFactor?: string, expire?: string} opts 2FA code & expire date (YYYY-MM-DD)
94
- * @returns {Promise<any>} Session information returned from login request
94
+ * @returns {Promise<User>} User account
95
95
  */
96
96
  login(spoke: string, login: string, password: string, opts?: {
97
97
  twoFactor?: string;
@@ -100,9 +100,9 @@ export declare class Auth {
100
100
  /**
101
101
  * Login as guest user
102
102
  *
103
- * @return {Promise<any>}
103
+ * @return {Promise<User>} Guest account
104
104
  */
105
- loginGuest(): Promise<any>;
105
+ loginGuest(): Promise<User>;
106
106
  /**
107
107
  * Create Login UI
108
108
  *
@@ -1 +1 @@
1
- {"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../src/auth.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,eAAe,EAAyB,MAAM,MAAM,CAAC;AAC7D,OAAO,EAAC,GAAG,EAAC,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAC,WAAW,EAAE,kBAAkB,EAAC,MAAM,gBAAgB,CAAC;AAE/D,mBAAmB;AACnB,MAAM,MAAM,IAAI,GAAG;IAClB,cAAc;IACd,EAAE,EAAE,MAAM,CAAC;IACX,4BAA4B;IAC5B,KAAK,EAAE,MAAM,CAAC;IACd,4CAA4C;IAC5C,KAAK,EAAE,OAAO,CAAC;IACf,kCAAkC;IAClC,QAAQ,EAAE,OAAO,CAAC;IAClB,gCAAgC;IAChC,UAAU,EAAE,MAAM,CAAC;IACnB,+BAA+B;IAC/B,SAAS,EAAE,MAAM,CAAC;IAClB,4BAA4B;IAC5B,KAAK,EAAE,MAAM,CAAC;IACd,8BAA8B;IAC9B,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,2BAA2B;IAC3B,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,4BAA4B;IAC5B,KAAK,EAAE,MAAM,CAAC;CACd,CAAA;AAED;;GAEG;AACH,qBAAa,IAAI;IAUJ,OAAO,CAAC,QAAQ,CAAC,GAAG;IAThC,oCAAoC;IACpC,KAAK,2CAA2D;IAChE,mBAAmB;IACnB,IAAI,IAAI,IAEO,IAAI,GAAG,IAAI,GAAG,SAAS,CAFM;IAC5C,4BAA4B;IAC5B,IAAI,IAAI,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,GAAG,SAAS,EAA4B;IAElE,IAAI,KAAK,kBAAiD;gBAE7B,GAAG,EAAE,GAAG;IAIrC;;;;OAIG;IACH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AC;IAW7E;;;;OAIG;IACH,eAAe;IAEf;;;;OAIG;IACH,OAAO;IAEP;;;;OAIG;IACG,UAAU,IAAI,OAAO,CAAC,OAAO,CAAC;IAOpC;;;;OAIG;IACG,YAAY,IAAI,OAAO,CAAC,OAAO,CAAC;IAOtC;;;;OAIG;IACG,WAAW,IAAI,OAAO,CAAC,OAAO,CAAC;IAOrC;;;;;;;;OAQG;IACH,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE;QAAC,SAAS,CAAC,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,IAAI,GAAG,MAAM,CAAA;KAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAqBzH;;;;OAIG;IACH,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAQ3B;;;;;;OAMG;IACH,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,kBAAkB,GAAG,WAAW;IAIrE;;;;OAIG;IACH,MAAM;gBAC6B,MAAM;aAAO,MAAM;;IAOtD;;;;;;;OAOG;IACH,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM;IAWvD;;;;;;OAMG;IACH,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,GAAG,KAAK,GAAG,OAAO;CAI3D"}
package/dist/index.cjs CHANGED
@@ -31,6 +31,13 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
31
31
  return value2;
32
32
  }, space);
33
33
  }
34
+ function blackOrWhite(background) {
35
+ const exploded = background == null ? void 0 : background.match(background.length >= 6 ? /\w\w/g : /\w/g);
36
+ if (!exploded) return "black";
37
+ const [r2, g, b2] = exploded.map((hex) => parseInt(hex, 16));
38
+ const luminance = (0.299 * r2 + 0.587 * g + 0.114 * b2) / 255;
39
+ return luminance > 0.5 ? "black" : "white";
40
+ }
34
41
  class PromiseProgress extends Promise {
35
42
  constructor(executor) {
36
43
  super((resolve, reject) => executor(
@@ -1308,38 +1315,6 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
1308
1315
  };
1309
1316
  return BehaviorSubject2;
1310
1317
  }(Subject);
1311
- var EmptyError = createErrorClass(function(_super) {
1312
- return function EmptyErrorImpl() {
1313
- _super(this);
1314
- this.name = "EmptyError";
1315
- this.message = "no elements in sequence";
1316
- };
1317
- });
1318
- function firstValueFrom(source, config2) {
1319
- return new Promise(function(resolve, reject) {
1320
- var subscriber = new SafeSubscriber({
1321
- next: function(value) {
1322
- resolve(value);
1323
- subscriber.unsubscribe();
1324
- },
1325
- error: reject,
1326
- complete: function() {
1327
- {
1328
- reject(new EmptyError());
1329
- }
1330
- }
1331
- });
1332
- source.subscribe(subscriber);
1333
- });
1334
- }
1335
- function filter(predicate, thisArg) {
1336
- return operate(function(source, subscriber) {
1337
- var index = 0;
1338
- source.subscribe(createOperatorSubscriber(subscriber, function(value) {
1339
- return predicate.call(thisArg, value, index++) && subscriber.next(value);
1340
- }));
1341
- });
1342
- }
1343
1318
  function distinctUntilChanged(comparator, keySelector) {
1344
1319
  if (keySelector === void 0) {
1345
1320
  keySelector = identity;
@@ -1369,6 +1344,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
1369
1344
  __publicField(this, "password");
1370
1345
  __publicField(this, "persist");
1371
1346
  __publicField(this, "username");
1347
+ __publicField(this, "options");
1372
1348
  __publicField(this, "_done");
1373
1349
  /** Promise which resolves once login is complete */
1374
1350
  __publicField(this, "done", new Promise((res) => {
@@ -1376,9 +1352,16 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
1376
1352
  }));
1377
1353
  this.api = api;
1378
1354
  this.spoke = spoke;
1379
- this.options = options;
1380
- document.head.innerHTML += _LoginPrompt.css(options.background, options.color, options.titleColor);
1381
- document.body.innerHTML += _LoginPrompt.template(options.title || this.spoke);
1355
+ this.options = {
1356
+ title: this.spoke,
1357
+ background: "#ffffff",
1358
+ color: "#c83232",
1359
+ textColor: "#000000",
1360
+ ...options
1361
+ };
1362
+ this.close();
1363
+ document.head.innerHTML += _LoginPrompt.css(this.options);
1364
+ document.body.innerHTML += _LoginPrompt.template(this.options);
1382
1365
  this.alert = document.querySelector("#datalynk-login-alert");
1383
1366
  this.button = document.querySelector("#datalynk-login-form button");
1384
1367
  this.form = document.querySelector("#datalynk-login-form");
@@ -1388,9 +1371,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
1388
1371
  this.form.onsubmit = (event) => this.login(event);
1389
1372
  if (options.persist === false) this.persist.parentElement.style.display = "none";
1390
1373
  }
1391
- /**
1392
- * Close the login prompt
1393
- */
1374
+ /** Close the login prompt */
1394
1375
  close() {
1395
1376
  var _a, _b;
1396
1377
  (_a = document.querySelector("#datalynk-login-css")) == null ? void 0 : _a.remove();
@@ -1430,14 +1411,16 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
1430
1411
  }
1431
1412
  };
1432
1413
  /** Dynamically create CSS style */
1433
- __publicField(_LoginPrompt, "css", (background = "#ffffff", color = "#000000cc", titleColor = "#000000") => `
1414
+ __publicField(_LoginPrompt, "css", (options) => `
1434
1415
  <style id="datalynk-login-styles">
1435
1416
  @import url('https://fonts.cdnfonts.com/css/ar-blanca');
1436
1417
 
1437
1418
  #datalynk-login {
1438
- --theme-background: ${background};
1439
- --theme-primary: ${color};
1440
- --theme-title: ${titleColor};
1419
+ --theme-background: ${options.background};
1420
+ --theme-container: #000000cc;
1421
+ --theme-glow: ${options.glow || options.color};
1422
+ --theme-primary: ${options.color};
1423
+ --theme-text: ${options.textColor};;
1441
1424
 
1442
1425
  position: fixed;
1443
1426
  left: 0;
@@ -1450,6 +1433,19 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
1450
1433
  font-family: sans-serif;
1451
1434
  z-index: 1000;
1452
1435
  }
1436
+
1437
+ #datalynk-login .added-links {
1438
+ color: var(--theme-text);
1439
+ position: fixed;
1440
+ bottom: 0;
1441
+ right: 0;
1442
+ padding: 0.25rem;
1443
+ }
1444
+
1445
+ #datalynk-login .added-links a, #datalynk-login .added-links a:hover, #datalynk-login .added-links a:visited {
1446
+ color: var(--theme-text);
1447
+ text-shadow: 0 0 10px black;
1448
+ }
1453
1449
 
1454
1450
  #datalynk-login-alert {
1455
1451
  padding: 0.75rem;
@@ -1457,6 +1453,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
1457
1453
  color: white;
1458
1454
  border-radius: 5px;
1459
1455
  margin-bottom: 1rem;
1456
+ border: grey 1px solid;
1460
1457
  }
1461
1458
 
1462
1459
  #datalynk-login label {
@@ -1474,30 +1471,6 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
1474
1471
  color: black;
1475
1472
  }
1476
1473
 
1477
- #datalynk-login input:disabled {
1478
- color: #333;
1479
- background-color: #ccc;
1480
- }
1481
-
1482
- #datalynk-login button {
1483
- background-color: #e03a3e;
1484
- background-image: none;
1485
- border: 0;
1486
- color: #fff;
1487
- padding: 8px 24px;
1488
- border-radius: 5px;
1489
- }
1490
-
1491
- #datalynk-login button:disabled {
1492
- cursor: pointer;
1493
- filter: brightness(90%);
1494
- }
1495
-
1496
- #datalynk-login button:hover:not(:disabled) {
1497
- cursor: pointer;
1498
- filter: brightness(110%);
1499
- }
1500
-
1501
1474
  #datalynk-login .login-container {
1502
1475
  position: fixed;
1503
1476
  top: 50%;
@@ -1507,7 +1480,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
1507
1480
  }
1508
1481
 
1509
1482
  #datalynk-login .login-header {
1510
- color: var(--theme-title);
1483
+ color: var(--theme-text);
1511
1484
  text-align: center;
1512
1485
  font-size: 32px;
1513
1486
  margin-bottom: 2rem;
@@ -1517,23 +1490,58 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
1517
1490
  display: flex;
1518
1491
  flex-direction: column;
1519
1492
  align-items: center;
1520
- background: var(--theme-primary);
1493
+ background: var(--theme-container);
1494
+ border-top: var(--theme-glow) 1px solid;
1495
+ box-shadow: 0 -10px 20px -10px var(--theme-glow);
1521
1496
  }
1522
1497
 
1523
1498
  #datalynk-login .login-body {
1524
- padding: 3.5rem 0 0 0;
1499
+ padding: ${options.hideApps ? "3.5rem 0" : "3.5rem 0 1.5rem 0"};
1500
+ width: 100%;
1501
+ max-width: 400px;;
1525
1502
  color: white;
1526
1503
  }
1504
+
1505
+ #datalynk-login input:disabled {
1506
+ color: #333;
1507
+ background-color: #ccc;
1508
+ }
1509
+
1510
+ #datalynk-login input[type="checkbox"] {
1511
+ height: 15px;
1512
+ margin: 0;
1513
+ padding: 0;
1514
+ accent-color: var(--theme-primary);
1515
+ }
1516
+
1517
+ #datalynk-login button {
1518
+ background-color: var(--theme-primary);
1519
+ background-image: none;
1520
+ border: 0;
1521
+ color: ${blackOrWhite(options.color)};
1522
+ padding: 8px 24px;
1523
+ border-radius: 5px;
1524
+ }
1527
1525
 
1528
- #datalynk-login .login-footer{
1529
- padding: 1.5rem 0;
1526
+ #datalynk-login button:disabled {
1527
+ cursor: pointer;
1528
+ filter: brightness(90%);
1530
1529
  }
1531
1530
 
1532
- #datalynk-login .login-footer a {
1531
+ #datalynk-login button:hover:not(:disabled) {
1532
+ cursor: pointer;
1533
+ filter: ${blackOrWhite(options.color) == "black" ? "brightness(105%)" : "brightness(80%)"};
1534
+ }
1535
+
1536
+ #datalynk-login .login-links{
1537
+ padding: 0 0 1.5rem 0;
1538
+ }
1539
+
1540
+ #datalynk-login .login-links a {
1533
1541
  text-decoration: none;
1534
1542
  }
1535
1543
 
1536
- #datalynk-login .login-footer img {
1544
+ #datalynk-login .login-links img {
1537
1545
  width: 150px;
1538
1546
  height: auto;
1539
1547
  }
@@ -1542,26 +1550,27 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
1542
1550
  display: none;
1543
1551
  }
1544
1552
 
1553
+ #datalynk-login .login-footer {
1554
+ transform: translateY(-18px);
1555
+ }
1556
+
1545
1557
  #datalynk-login .sloped-div {
1546
- margin-left:auto;
1547
- margin-right: auto;
1548
- display: inline-flex;
1549
- padding: 0 3rem 0.5rem 3rem;
1550
- justify-content: center;
1551
- align-items: center;
1552
- background: var(--theme-primary);
1553
- clip-path: polygon(0 0, 100% 0, 80% 100%, 20% 100%);
1554
1558
  position: absolute;
1555
- left: 50%;
1556
- transform: translate(-50%, -1px);
1559
+ height: 45px;
1560
+ width: 200px;
1561
+ background: var(--theme-container);
1562
+ clip-path: polygon(0 20px, 100% 20px, 85% 60px, 15% 60px);
1557
1563
  }
1558
1564
  </style>`);
1559
1565
  /** Dynamically create HTML */
1560
- __publicField(_LoginPrompt, "template", (title = "Datalynk") => `
1566
+ __publicField(_LoginPrompt, "template", (options) => `
1561
1567
  <div id="datalynk-login">
1568
+ <div class="added-links">
1569
+ ${(options.addLinks || []).map((link) => `<a href="${link.url}" target="_blank">${link.text}</a>`).join(" | ")}
1570
+ </div>
1562
1571
  <div class="login-container">
1563
1572
  <div class="login-header">
1564
- ${title}
1573
+ ${options.title}
1565
1574
  </div>
1566
1575
  <div class="login-content">
1567
1576
  <div class="login-body" style="max-width: 300px">
@@ -1584,7 +1593,8 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
1584
1593
  <button>Login</button>
1585
1594
  </form>
1586
1595
  </div>
1587
- <div class="login-footer" style="text-align: center">
1596
+ ${options.hideApps ? "" : `
1597
+ <div class="login-links" style="text-align: center">
1588
1598
  <a href="https://itunes.apple.com/ca/app/auxilium-mobile/id1166379280?mt=8" target="_blank">
1589
1599
  <img alt="App Store" src="https://datalynk.auxiliumgroup.com/api/js/auxilium/dijits/templates/login/_common/mobile_apple_transparent.png">
1590
1600
  </a>
@@ -1592,14 +1602,14 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
1592
1602
  <img alt="Playstore" src="https://datalynk.auxiliumgroup.com/api/js/auxilium/dijits/templates/login/_common/mobile_google_transparent.png">
1593
1603
  </a>
1594
1604
  </div>
1605
+ `}
1595
1606
  </div>
1596
- <div class="sloped-div">
1597
- <div style="height: 36px">
1598
- <a href="https://auxiliumgroup.com" target="_blank" style="height: 40px; display: flex; align-items: center; text-decoration: none; font-family: 'AR BLANCA', serif; font-size: 26px; color: white; position: relative">
1599
- Au<span style="font-size: 52px; color: #c83232; margin-bottom: 5px">x</span>ilium
1600
- <span style="position: absolute; font-size: 10px; color: #c83232; top: 2px; right: 2px">Group</span>
1601
- </a>
1602
- </div>
1607
+ <div class="login-footer" style="position: relative; display: flex; align-items: center; justify-content: center;">
1608
+ <div class="sloped-div"></div>
1609
+ <a href="https://auxiliumgroup.com" target="_blank" style="position: relative; height: 40px; display: flex; align-items: center; text-decoration: none; font-family: 'AR BLANCA', serif; font-size: 26px; color: white;">
1610
+ Au<span style="font-size: 52px; color: #c83232; margin-bottom: 5px">x</span>ilium
1611
+ <span style="position: absolute; font-size: 10px; color: #c83232; top: 2px; right: 2px">Group</span>
1612
+ </a>
1603
1613
  </div>
1604
1614
  </div>
1605
1615
  </div>
@@ -1610,7 +1620,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
1610
1620
  /** Current user as an observable */
1611
1621
  __publicField(this, "user$", new BehaviorSubject(void 0));
1612
1622
  this.api = api;
1613
- this.api.token$.subscribe(() => this.current());
1623
+ this.api.token$.subscribe((token) => this.current(token, true));
1614
1624
  }
1615
1625
  /** Current user */
1616
1626
  get user() {
@@ -1629,14 +1639,21 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
1629
1639
  *
1630
1640
  * @return {Promise<User | null>}
1631
1641
  */
1632
- current() {
1633
- if (!this.api.token) {
1634
- this.user = null;
1635
- return Promise.resolve(null);
1642
+ async current(token = this.api.token, set) {
1643
+ var _a;
1644
+ if (!token) {
1645
+ if (set && this.user != null) this.user = null;
1646
+ return null;
1647
+ } else if (token == ((_a = this.user) == null ? void 0 : _a.token)) {
1648
+ return this.user;
1636
1649
  }
1637
- return this.api.request({ "$/auth/current": {} }).then((resp) => {
1638
- this.user = (resp == null ? void 0 : resp.login) ? resp : null;
1639
- return resp;
1650
+ return this.api.request({ "$/auth/current": {} }, { token }).then((resp) => {
1651
+ const u = (resp == null ? void 0 : resp.login) ? resp : null;
1652
+ if (set) {
1653
+ this.api.token = token;
1654
+ this.user = u;
1655
+ }
1656
+ return u;
1640
1657
  });
1641
1658
  }
1642
1659
  /**
@@ -1652,12 +1669,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
1652
1669
  if (urlToken) {
1653
1670
  this.api.token = urlToken;
1654
1671
  location.href = location.href.replace(/datalynkToken.*?(&|$)/gm, "");
1655
- } else if (this.api.token) {
1656
- await this.current().catch(() => {
1657
- this.api.token = null;
1658
- location.reload();
1659
- });
1660
- } else {
1672
+ } else if (!this.api.token) {
1661
1673
  await this.loginPrompt(spoke, options).done;
1662
1674
  location.reload();
1663
1675
  }
@@ -1710,7 +1722,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
1710
1722
  * @param {string} password Password for account
1711
1723
  * @param {string} spoke Override login spoke
1712
1724
  * @param {twoFactor?: string, expire?: string} opts 2FA code & expire date (YYYY-MM-DD)
1713
- * @returns {Promise<any>} Session information returned from login request
1725
+ * @returns {Promise<User>} User account
1714
1726
  */
1715
1727
  login(spoke, login, password, opts) {
1716
1728
  const date = /* @__PURE__ */ new Date();
@@ -1729,21 +1741,19 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
1729
1741
  }).then(async (resp) => {
1730
1742
  const data = await resp.json().catch(() => ({}));
1731
1743
  if (!resp.ok || data["error"]) throw Object.assign(errorFromCode(resp.status, data.error) || {}, data);
1732
- this.api.token = data["token"];
1733
- return await firstValueFrom(this.user$.pipe(filter((u) => (u == null ? void 0 : u.token) == data["token"])));
1744
+ return await this.current(data["token"], true);
1734
1745
  });
1735
1746
  }
1736
1747
  /**
1737
1748
  * Login as guest user
1738
1749
  *
1739
- * @return {Promise<any>}
1750
+ * @return {Promise<User>} Guest account
1740
1751
  */
1741
1752
  loginGuest() {
1742
1753
  return fetch(`${this.api.url}guest`).then(async (resp) => {
1743
1754
  const data = await resp.json().catch(() => ({}));
1744
1755
  if (!resp.ok || data["error"]) throw Object.assign(errorFromCode(resp.status, data.error) || {}, data);
1745
- this.api.token = data["token"];
1746
- return data;
1756
+ return await this.current(data["token"], true);
1747
1757
  });
1748
1758
  }
1749
1759
  /**
@@ -2490,7 +2500,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
2490
2500
  } });
2491
2501
  }
2492
2502
  }
2493
- const version = "1.0.8";
2503
+ const version = "1.0.11";
2494
2504
  class Api {
2495
2505
  /**
2496
2506
  * Connect to Datalynk & send requests
@@ -2561,10 +2571,11 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
2561
2571
  return jwtDecode(this.token);
2562
2572
  }
2563
2573
  _request(req, options = {}) {
2574
+ const token = options.token || this.token;
2564
2575
  return fetch(this.url, {
2565
2576
  method: "POST",
2566
2577
  headers: clean({
2567
- Authorization: this.token ? `Bearer ${this.token}` : void 0,
2578
+ Authorization: token ? `Bearer ${token}` : void 0,
2568
2579
  "Content-Type": "application/json",
2569
2580
  "X-Date-Return-Format": this.options.legacyDates ? void 0 : "ISO8601"
2570
2581
  }),
package/dist/index.mjs CHANGED
@@ -27,6 +27,13 @@ function JSONSanitize(obj, space) {
27
27
  return value2;
28
28
  }, space);
29
29
  }
30
+ function blackOrWhite(background) {
31
+ const exploded = background == null ? void 0 : background.match(background.length >= 6 ? /\w\w/g : /\w/g);
32
+ if (!exploded) return "black";
33
+ const [r2, g, b2] = exploded.map((hex) => parseInt(hex, 16));
34
+ const luminance = (0.299 * r2 + 0.587 * g + 0.114 * b2) / 255;
35
+ return luminance > 0.5 ? "black" : "white";
36
+ }
30
37
  class PromiseProgress extends Promise {
31
38
  constructor(executor) {
32
39
  super((resolve, reject) => executor(
@@ -1304,38 +1311,6 @@ var BehaviorSubject = function(_super) {
1304
1311
  };
1305
1312
  return BehaviorSubject2;
1306
1313
  }(Subject);
1307
- var EmptyError = createErrorClass(function(_super) {
1308
- return function EmptyErrorImpl() {
1309
- _super(this);
1310
- this.name = "EmptyError";
1311
- this.message = "no elements in sequence";
1312
- };
1313
- });
1314
- function firstValueFrom(source, config2) {
1315
- return new Promise(function(resolve, reject) {
1316
- var subscriber = new SafeSubscriber({
1317
- next: function(value) {
1318
- resolve(value);
1319
- subscriber.unsubscribe();
1320
- },
1321
- error: reject,
1322
- complete: function() {
1323
- {
1324
- reject(new EmptyError());
1325
- }
1326
- }
1327
- });
1328
- source.subscribe(subscriber);
1329
- });
1330
- }
1331
- function filter(predicate, thisArg) {
1332
- return operate(function(source, subscriber) {
1333
- var index = 0;
1334
- source.subscribe(createOperatorSubscriber(subscriber, function(value) {
1335
- return predicate.call(thisArg, value, index++) && subscriber.next(value);
1336
- }));
1337
- });
1338
- }
1339
1314
  function distinctUntilChanged(comparator, keySelector) {
1340
1315
  if (keySelector === void 0) {
1341
1316
  keySelector = identity;
@@ -1365,6 +1340,7 @@ const _LoginPrompt = class _LoginPrompt {
1365
1340
  __publicField(this, "password");
1366
1341
  __publicField(this, "persist");
1367
1342
  __publicField(this, "username");
1343
+ __publicField(this, "options");
1368
1344
  __publicField(this, "_done");
1369
1345
  /** Promise which resolves once login is complete */
1370
1346
  __publicField(this, "done", new Promise((res) => {
@@ -1372,9 +1348,16 @@ const _LoginPrompt = class _LoginPrompt {
1372
1348
  }));
1373
1349
  this.api = api;
1374
1350
  this.spoke = spoke;
1375
- this.options = options;
1376
- document.head.innerHTML += _LoginPrompt.css(options.background, options.color, options.titleColor);
1377
- document.body.innerHTML += _LoginPrompt.template(options.title || this.spoke);
1351
+ this.options = {
1352
+ title: this.spoke,
1353
+ background: "#ffffff",
1354
+ color: "#c83232",
1355
+ textColor: "#000000",
1356
+ ...options
1357
+ };
1358
+ this.close();
1359
+ document.head.innerHTML += _LoginPrompt.css(this.options);
1360
+ document.body.innerHTML += _LoginPrompt.template(this.options);
1378
1361
  this.alert = document.querySelector("#datalynk-login-alert");
1379
1362
  this.button = document.querySelector("#datalynk-login-form button");
1380
1363
  this.form = document.querySelector("#datalynk-login-form");
@@ -1384,9 +1367,7 @@ const _LoginPrompt = class _LoginPrompt {
1384
1367
  this.form.onsubmit = (event) => this.login(event);
1385
1368
  if (options.persist === false) this.persist.parentElement.style.display = "none";
1386
1369
  }
1387
- /**
1388
- * Close the login prompt
1389
- */
1370
+ /** Close the login prompt */
1390
1371
  close() {
1391
1372
  var _a, _b;
1392
1373
  (_a = document.querySelector("#datalynk-login-css")) == null ? void 0 : _a.remove();
@@ -1426,14 +1407,16 @@ const _LoginPrompt = class _LoginPrompt {
1426
1407
  }
1427
1408
  };
1428
1409
  /** Dynamically create CSS style */
1429
- __publicField(_LoginPrompt, "css", (background = "#ffffff", color = "#000000cc", titleColor = "#000000") => `
1410
+ __publicField(_LoginPrompt, "css", (options) => `
1430
1411
  <style id="datalynk-login-styles">
1431
1412
  @import url('https://fonts.cdnfonts.com/css/ar-blanca');
1432
1413
 
1433
1414
  #datalynk-login {
1434
- --theme-background: ${background};
1435
- --theme-primary: ${color};
1436
- --theme-title: ${titleColor};
1415
+ --theme-background: ${options.background};
1416
+ --theme-container: #000000cc;
1417
+ --theme-glow: ${options.glow || options.color};
1418
+ --theme-primary: ${options.color};
1419
+ --theme-text: ${options.textColor};;
1437
1420
 
1438
1421
  position: fixed;
1439
1422
  left: 0;
@@ -1446,6 +1429,19 @@ __publicField(_LoginPrompt, "css", (background = "#ffffff", color = "#000000cc",
1446
1429
  font-family: sans-serif;
1447
1430
  z-index: 1000;
1448
1431
  }
1432
+
1433
+ #datalynk-login .added-links {
1434
+ color: var(--theme-text);
1435
+ position: fixed;
1436
+ bottom: 0;
1437
+ right: 0;
1438
+ padding: 0.25rem;
1439
+ }
1440
+
1441
+ #datalynk-login .added-links a, #datalynk-login .added-links a:hover, #datalynk-login .added-links a:visited {
1442
+ color: var(--theme-text);
1443
+ text-shadow: 0 0 10px black;
1444
+ }
1449
1445
 
1450
1446
  #datalynk-login-alert {
1451
1447
  padding: 0.75rem;
@@ -1453,6 +1449,7 @@ __publicField(_LoginPrompt, "css", (background = "#ffffff", color = "#000000cc",
1453
1449
  color: white;
1454
1450
  border-radius: 5px;
1455
1451
  margin-bottom: 1rem;
1452
+ border: grey 1px solid;
1456
1453
  }
1457
1454
 
1458
1455
  #datalynk-login label {
@@ -1470,30 +1467,6 @@ __publicField(_LoginPrompt, "css", (background = "#ffffff", color = "#000000cc",
1470
1467
  color: black;
1471
1468
  }
1472
1469
 
1473
- #datalynk-login input:disabled {
1474
- color: #333;
1475
- background-color: #ccc;
1476
- }
1477
-
1478
- #datalynk-login button {
1479
- background-color: #e03a3e;
1480
- background-image: none;
1481
- border: 0;
1482
- color: #fff;
1483
- padding: 8px 24px;
1484
- border-radius: 5px;
1485
- }
1486
-
1487
- #datalynk-login button:disabled {
1488
- cursor: pointer;
1489
- filter: brightness(90%);
1490
- }
1491
-
1492
- #datalynk-login button:hover:not(:disabled) {
1493
- cursor: pointer;
1494
- filter: brightness(110%);
1495
- }
1496
-
1497
1470
  #datalynk-login .login-container {
1498
1471
  position: fixed;
1499
1472
  top: 50%;
@@ -1503,7 +1476,7 @@ __publicField(_LoginPrompt, "css", (background = "#ffffff", color = "#000000cc",
1503
1476
  }
1504
1477
 
1505
1478
  #datalynk-login .login-header {
1506
- color: var(--theme-title);
1479
+ color: var(--theme-text);
1507
1480
  text-align: center;
1508
1481
  font-size: 32px;
1509
1482
  margin-bottom: 2rem;
@@ -1513,23 +1486,58 @@ __publicField(_LoginPrompt, "css", (background = "#ffffff", color = "#000000cc",
1513
1486
  display: flex;
1514
1487
  flex-direction: column;
1515
1488
  align-items: center;
1516
- background: var(--theme-primary);
1489
+ background: var(--theme-container);
1490
+ border-top: var(--theme-glow) 1px solid;
1491
+ box-shadow: 0 -10px 20px -10px var(--theme-glow);
1517
1492
  }
1518
1493
 
1519
1494
  #datalynk-login .login-body {
1520
- padding: 3.5rem 0 0 0;
1495
+ padding: ${options.hideApps ? "3.5rem 0" : "3.5rem 0 1.5rem 0"};
1496
+ width: 100%;
1497
+ max-width: 400px;;
1521
1498
  color: white;
1522
1499
  }
1500
+
1501
+ #datalynk-login input:disabled {
1502
+ color: #333;
1503
+ background-color: #ccc;
1504
+ }
1505
+
1506
+ #datalynk-login input[type="checkbox"] {
1507
+ height: 15px;
1508
+ margin: 0;
1509
+ padding: 0;
1510
+ accent-color: var(--theme-primary);
1511
+ }
1512
+
1513
+ #datalynk-login button {
1514
+ background-color: var(--theme-primary);
1515
+ background-image: none;
1516
+ border: 0;
1517
+ color: ${blackOrWhite(options.color)};
1518
+ padding: 8px 24px;
1519
+ border-radius: 5px;
1520
+ }
1523
1521
 
1524
- #datalynk-login .login-footer{
1525
- padding: 1.5rem 0;
1522
+ #datalynk-login button:disabled {
1523
+ cursor: pointer;
1524
+ filter: brightness(90%);
1526
1525
  }
1527
1526
 
1528
- #datalynk-login .login-footer a {
1527
+ #datalynk-login button:hover:not(:disabled) {
1528
+ cursor: pointer;
1529
+ filter: ${blackOrWhite(options.color) == "black" ? "brightness(105%)" : "brightness(80%)"};
1530
+ }
1531
+
1532
+ #datalynk-login .login-links{
1533
+ padding: 0 0 1.5rem 0;
1534
+ }
1535
+
1536
+ #datalynk-login .login-links a {
1529
1537
  text-decoration: none;
1530
1538
  }
1531
1539
 
1532
- #datalynk-login .login-footer img {
1540
+ #datalynk-login .login-links img {
1533
1541
  width: 150px;
1534
1542
  height: auto;
1535
1543
  }
@@ -1538,26 +1546,27 @@ __publicField(_LoginPrompt, "css", (background = "#ffffff", color = "#000000cc",
1538
1546
  display: none;
1539
1547
  }
1540
1548
 
1549
+ #datalynk-login .login-footer {
1550
+ transform: translateY(-18px);
1551
+ }
1552
+
1541
1553
  #datalynk-login .sloped-div {
1542
- margin-left:auto;
1543
- margin-right: auto;
1544
- display: inline-flex;
1545
- padding: 0 3rem 0.5rem 3rem;
1546
- justify-content: center;
1547
- align-items: center;
1548
- background: var(--theme-primary);
1549
- clip-path: polygon(0 0, 100% 0, 80% 100%, 20% 100%);
1550
1554
  position: absolute;
1551
- left: 50%;
1552
- transform: translate(-50%, -1px);
1555
+ height: 45px;
1556
+ width: 200px;
1557
+ background: var(--theme-container);
1558
+ clip-path: polygon(0 20px, 100% 20px, 85% 60px, 15% 60px);
1553
1559
  }
1554
1560
  </style>`);
1555
1561
  /** Dynamically create HTML */
1556
- __publicField(_LoginPrompt, "template", (title = "Datalynk") => `
1562
+ __publicField(_LoginPrompt, "template", (options) => `
1557
1563
  <div id="datalynk-login">
1564
+ <div class="added-links">
1565
+ ${(options.addLinks || []).map((link) => `<a href="${link.url}" target="_blank">${link.text}</a>`).join(" | ")}
1566
+ </div>
1558
1567
  <div class="login-container">
1559
1568
  <div class="login-header">
1560
- ${title}
1569
+ ${options.title}
1561
1570
  </div>
1562
1571
  <div class="login-content">
1563
1572
  <div class="login-body" style="max-width: 300px">
@@ -1580,7 +1589,8 @@ __publicField(_LoginPrompt, "template", (title = "Datalynk") => `
1580
1589
  <button>Login</button>
1581
1590
  </form>
1582
1591
  </div>
1583
- <div class="login-footer" style="text-align: center">
1592
+ ${options.hideApps ? "" : `
1593
+ <div class="login-links" style="text-align: center">
1584
1594
  <a href="https://itunes.apple.com/ca/app/auxilium-mobile/id1166379280?mt=8" target="_blank">
1585
1595
  <img alt="App Store" src="https://datalynk.auxiliumgroup.com/api/js/auxilium/dijits/templates/login/_common/mobile_apple_transparent.png">
1586
1596
  </a>
@@ -1588,14 +1598,14 @@ __publicField(_LoginPrompt, "template", (title = "Datalynk") => `
1588
1598
  <img alt="Playstore" src="https://datalynk.auxiliumgroup.com/api/js/auxilium/dijits/templates/login/_common/mobile_google_transparent.png">
1589
1599
  </a>
1590
1600
  </div>
1601
+ `}
1591
1602
  </div>
1592
- <div class="sloped-div">
1593
- <div style="height: 36px">
1594
- <a href="https://auxiliumgroup.com" target="_blank" style="height: 40px; display: flex; align-items: center; text-decoration: none; font-family: 'AR BLANCA', serif; font-size: 26px; color: white; position: relative">
1595
- Au<span style="font-size: 52px; color: #c83232; margin-bottom: 5px">x</span>ilium
1596
- <span style="position: absolute; font-size: 10px; color: #c83232; top: 2px; right: 2px">Group</span>
1597
- </a>
1598
- </div>
1603
+ <div class="login-footer" style="position: relative; display: flex; align-items: center; justify-content: center;">
1604
+ <div class="sloped-div"></div>
1605
+ <a href="https://auxiliumgroup.com" target="_blank" style="position: relative; height: 40px; display: flex; align-items: center; text-decoration: none; font-family: 'AR BLANCA', serif; font-size: 26px; color: white;">
1606
+ Au<span style="font-size: 52px; color: #c83232; margin-bottom: 5px">x</span>ilium
1607
+ <span style="position: absolute; font-size: 10px; color: #c83232; top: 2px; right: 2px">Group</span>
1608
+ </a>
1599
1609
  </div>
1600
1610
  </div>
1601
1611
  </div>
@@ -1606,7 +1616,7 @@ class Auth {
1606
1616
  /** Current user as an observable */
1607
1617
  __publicField(this, "user$", new BehaviorSubject(void 0));
1608
1618
  this.api = api;
1609
- this.api.token$.subscribe(() => this.current());
1619
+ this.api.token$.subscribe((token) => this.current(token, true));
1610
1620
  }
1611
1621
  /** Current user */
1612
1622
  get user() {
@@ -1625,14 +1635,21 @@ class Auth {
1625
1635
  *
1626
1636
  * @return {Promise<User | null>}
1627
1637
  */
1628
- current() {
1629
- if (!this.api.token) {
1630
- this.user = null;
1631
- return Promise.resolve(null);
1638
+ async current(token = this.api.token, set) {
1639
+ var _a;
1640
+ if (!token) {
1641
+ if (set && this.user != null) this.user = null;
1642
+ return null;
1643
+ } else if (token == ((_a = this.user) == null ? void 0 : _a.token)) {
1644
+ return this.user;
1632
1645
  }
1633
- return this.api.request({ "$/auth/current": {} }).then((resp) => {
1634
- this.user = (resp == null ? void 0 : resp.login) ? resp : null;
1635
- return resp;
1646
+ return this.api.request({ "$/auth/current": {} }, { token }).then((resp) => {
1647
+ const u = (resp == null ? void 0 : resp.login) ? resp : null;
1648
+ if (set) {
1649
+ this.api.token = token;
1650
+ this.user = u;
1651
+ }
1652
+ return u;
1636
1653
  });
1637
1654
  }
1638
1655
  /**
@@ -1648,12 +1665,7 @@ class Auth {
1648
1665
  if (urlToken) {
1649
1666
  this.api.token = urlToken;
1650
1667
  location.href = location.href.replace(/datalynkToken.*?(&|$)/gm, "");
1651
- } else if (this.api.token) {
1652
- await this.current().catch(() => {
1653
- this.api.token = null;
1654
- location.reload();
1655
- });
1656
- } else {
1668
+ } else if (!this.api.token) {
1657
1669
  await this.loginPrompt(spoke, options).done;
1658
1670
  location.reload();
1659
1671
  }
@@ -1706,7 +1718,7 @@ class Auth {
1706
1718
  * @param {string} password Password for account
1707
1719
  * @param {string} spoke Override login spoke
1708
1720
  * @param {twoFactor?: string, expire?: string} opts 2FA code & expire date (YYYY-MM-DD)
1709
- * @returns {Promise<any>} Session information returned from login request
1721
+ * @returns {Promise<User>} User account
1710
1722
  */
1711
1723
  login(spoke, login, password, opts) {
1712
1724
  const date = /* @__PURE__ */ new Date();
@@ -1725,21 +1737,19 @@ class Auth {
1725
1737
  }).then(async (resp) => {
1726
1738
  const data = await resp.json().catch(() => ({}));
1727
1739
  if (!resp.ok || data["error"]) throw Object.assign(errorFromCode(resp.status, data.error) || {}, data);
1728
- this.api.token = data["token"];
1729
- return await firstValueFrom(this.user$.pipe(filter((u) => (u == null ? void 0 : u.token) == data["token"])));
1740
+ return await this.current(data["token"], true);
1730
1741
  });
1731
1742
  }
1732
1743
  /**
1733
1744
  * Login as guest user
1734
1745
  *
1735
- * @return {Promise<any>}
1746
+ * @return {Promise<User>} Guest account
1736
1747
  */
1737
1748
  loginGuest() {
1738
1749
  return fetch(`${this.api.url}guest`).then(async (resp) => {
1739
1750
  const data = await resp.json().catch(() => ({}));
1740
1751
  if (!resp.ok || data["error"]) throw Object.assign(errorFromCode(resp.status, data.error) || {}, data);
1741
- this.api.token = data["token"];
1742
- return data;
1752
+ return await this.current(data["token"], true);
1743
1753
  });
1744
1754
  }
1745
1755
  /**
@@ -2486,7 +2496,7 @@ class Superuser {
2486
2496
  } });
2487
2497
  }
2488
2498
  }
2489
- const version = "1.0.8";
2499
+ const version = "1.0.11";
2490
2500
  class Api {
2491
2501
  /**
2492
2502
  * Connect to Datalynk & send requests
@@ -2557,10 +2567,11 @@ class Api {
2557
2567
  return jwtDecode(this.token);
2558
2568
  }
2559
2569
  _request(req, options = {}) {
2570
+ const token = options.token || this.token;
2560
2571
  return fetch(this.url, {
2561
2572
  method: "POST",
2562
2573
  headers: clean({
2563
- Authorization: this.token ? `Bearer ${this.token}` : void 0,
2574
+ Authorization: token ? `Bearer ${token}` : void 0,
2564
2575
  "Content-Type": "application/json",
2565
2576
  "X-Date-Return-Format": this.options.legacyDates ? void 0 : "ISO8601"
2566
2577
  }),
@@ -1,22 +1,30 @@
1
1
  import { Api } from './api';
2
2
  /** Styling options for login prompt */
3
3
  export type LoginPromptOptions = {
4
- /** Background CSS property, could be a hex: `#fffff` or a url: `url("...")` */
4
+ /** Add links to top of page */
5
+ addLinks?: {
6
+ text: string;
7
+ url: string;
8
+ }[];
9
+ /** Background CSS property: url("...") #fff */
5
10
  background?: string;
6
- /** Foreground color hex: `#000000` */
11
+ /** Primary color as hex: `#000000` */
7
12
  color?: string;
13
+ /** Change glow color, defaults to color or set to falsy to disable */
14
+ glow?: string;
15
+ /** Hide app links */
16
+ hideApps?: boolean;
8
17
  /** Allow users to stay logged in */
9
18
  persist?: boolean;
10
- /** Header, could be a simple string: 'Datalynk' or HTML: `<img src="...">`*/
19
+ /** Header string or HTML: <img alt="logo" src="...">*/
11
20
  title?: string;
12
- /** Text color of header, only valid when passing a string to title */
13
- titleColor?: string;
21
+ /** Color of headers & links */
22
+ textColor?: string;
14
23
  };
15
24
  /** Create a login prompt */
16
25
  export declare class LoginPrompt {
17
26
  private readonly api;
18
27
  readonly spoke: string;
19
- options: LoginPromptOptions;
20
28
  /** Dynamically create CSS style */
21
29
  private static css;
22
30
  /** Dynamically create HTML */
@@ -27,13 +35,12 @@ export declare class LoginPrompt {
27
35
  private readonly password;
28
36
  private readonly persist;
29
37
  private readonly username;
38
+ readonly options: LoginPromptOptions;
30
39
  private _done;
31
40
  /** Promise which resolves once login is complete */
32
41
  done: Promise<void>;
33
42
  constructor(api: Api, spoke: string, options?: LoginPromptOptions);
34
- /**
35
- * Close the login prompt
36
- */
43
+ /** Close the login prompt */
37
44
  close(): void;
38
45
  /** Check if login prompt is still open */
39
46
  isOpen(): boolean;
@@ -1 +1 @@
1
- {"version":3,"file":"login-prompt.d.ts","sourceRoot":"","sources":["../src/login-prompt.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,GAAG,EAAC,MAAM,OAAO,CAAC;AAE1B,uCAAuC;AACvC,MAAM,MAAM,kBAAkB,GAAG;IAChC,+EAA+E;IAC/E,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,sCAAsC;IACtC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,oCAAoC;IACpC,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,6EAA6E;IAC7E,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,sEAAsE;IACtE,UAAU,CAAC,EAAE,MAAM,CAAC;CACpB,CAAA;AAED,4BAA4B;AAC5B,qBAAa,WAAW;IA6LX,OAAO,CAAC,QAAQ,CAAC,GAAG;aAAuB,KAAK,EAAE,MAAM;IAAS,OAAO,EAAE,kBAAkB;IA5LxG,mCAAmC;IACnC,OAAO,CAAC,MAAM,CAAC,GAAG,CA6HR;IAEV,8BAA8B;IAC9B,OAAO,CAAC,MAAM,CAAC,QAAQ,CA8CrB;IAEF,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAO;IAC7B,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAO;IAC9B,OAAO,CAAC,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;IAEV,8BAA8B;IAC9B,OAAO,CAAC,MAAM,CAAC,QAAQ,CAkDrB;IAEF,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAO;IAC7B,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAO;IAC9B,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAO;IAC5B,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAO;IAChC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAO;IAC/B,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAO;IAEhC,SAAgB,OAAO,EAAG,kBAAkB,CAAC;IAE7C,OAAO,CAAC,KAAK,CAAY;IACzB,oDAAoD;IACpD,IAAI,gBAAmD;gBAE1B,GAAG,EAAE,GAAG,EAAkB,KAAK,EAAE,MAAM,EAAE,OAAO,GAAE,kBAAuB;IAyBtG,6BAA6B;IAC7B,KAAK;IAKL,0CAA0C;IAC1C,MAAM;IAIN,8BAA8B;IAC9B,KAAK,CAAC,KAAK,EAAE,GAAG;CA4BhB"}
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@auxilium/datalynk-client",
3
3
  "description": "Datalynk client library",
4
4
  "repository": "https://gitlab.auxiliumgroup.com/auxilium/datalynk/datalynk-client",
5
- "version": "1.0.8",
5
+ "version": "1.0.11",
6
6
  "author": "Zak Timson <zaktimson@gmail.com>",
7
7
  "private": false,
8
8
  "main": "./dist/index.cjs",