@auxilium/datalynk-client 1.0.8 → 1.0.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api.d.ts +2 -0
- package/dist/api.d.ts.map +1 -1
- package/dist/auth.d.ts +4 -4
- package/dist/auth.d.ts.map +1 -1
- package/dist/index.cjs +23 -54
- package/dist/index.mjs +23 -54
- package/package.json +1 -1
package/dist/api.d.ts
CHANGED
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,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,EAAE,GAAG,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,GAAG,EAAE,MAAM,CAAC;CACZ,CAAA;AAED;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG;IACxB,+DAA+D;IAC/D,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,kCAAkC;IAClC,WAAW,CAAC,EAAE,OAAO,CAAC;I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AC,KAAK,QAAmB;IACjC,UAAU;IACV,QAAQ,CAAC,GAAG,MAAiB;IAC7B,aAAa;IACb,QAAQ,CAAC,MAAM,EAAG,MAAM,CAAC;IACzB,gBAAgB;IAChB,QAAQ,CAAC,SAAS,YAAuB;IAEzC;;;;;;;;;;OAUG;gBACS,GAAG,EAAE,MAAM,EAAkB,OAAO,GAAE,UAAe;IA0BjE,OAAO,CAAC,QAAQ;IAqBhB;;;;;;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<
|
|
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<
|
|
103
|
+
* @return {Promise<User>} Guest account
|
|
104
104
|
*/
|
|
105
|
-
loginGuest(): Promise<
|
|
105
|
+
loginGuest(): Promise<User>;
|
|
106
106
|
/**
|
|
107
107
|
* Create Login UI
|
|
108
108
|
*
|
package/dist/auth.d.ts.map
CHANGED
|
@@ -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,MAA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,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
|
@@ -1308,38 +1308,6 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
1308
1308
|
};
|
|
1309
1309
|
return BehaviorSubject2;
|
|
1310
1310
|
}(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
1311
|
function distinctUntilChanged(comparator, keySelector) {
|
|
1344
1312
|
if (keySelector === void 0) {
|
|
1345
1313
|
keySelector = identity;
|
|
@@ -1610,7 +1578,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
1610
1578
|
/** Current user as an observable */
|
|
1611
1579
|
__publicField(this, "user$", new BehaviorSubject(void 0));
|
|
1612
1580
|
this.api = api;
|
|
1613
|
-
this.api.token$.subscribe(() => this.current());
|
|
1581
|
+
this.api.token$.subscribe((token) => this.current(token, true));
|
|
1614
1582
|
}
|
|
1615
1583
|
/** Current user */
|
|
1616
1584
|
get user() {
|
|
@@ -1629,14 +1597,21 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
1629
1597
|
*
|
|
1630
1598
|
* @return {Promise<User | null>}
|
|
1631
1599
|
*/
|
|
1632
|
-
current() {
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1600
|
+
async current(token = this.api.token, set) {
|
|
1601
|
+
var _a;
|
|
1602
|
+
if (!token) {
|
|
1603
|
+
if (set && this.user != null) this.user = null;
|
|
1604
|
+
return null;
|
|
1605
|
+
} else if (token == ((_a = this.user) == null ? void 0 : _a.token)) {
|
|
1606
|
+
return this.user;
|
|
1636
1607
|
}
|
|
1637
|
-
return this.api.request({ "$/auth/current": {} }).then((resp) => {
|
|
1638
|
-
|
|
1639
|
-
|
|
1608
|
+
return this.api.request({ "$/auth/current": {} }, { token }).then((resp) => {
|
|
1609
|
+
const u = (resp == null ? void 0 : resp.login) ? resp : null;
|
|
1610
|
+
if (set) {
|
|
1611
|
+
this.api.token = token;
|
|
1612
|
+
this.user = u;
|
|
1613
|
+
}
|
|
1614
|
+
return u;
|
|
1640
1615
|
});
|
|
1641
1616
|
}
|
|
1642
1617
|
/**
|
|
@@ -1652,12 +1627,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
1652
1627
|
if (urlToken) {
|
|
1653
1628
|
this.api.token = urlToken;
|
|
1654
1629
|
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 {
|
|
1630
|
+
} else if (!this.api.token) {
|
|
1661
1631
|
await this.loginPrompt(spoke, options).done;
|
|
1662
1632
|
location.reload();
|
|
1663
1633
|
}
|
|
@@ -1710,7 +1680,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
1710
1680
|
* @param {string} password Password for account
|
|
1711
1681
|
* @param {string} spoke Override login spoke
|
|
1712
1682
|
* @param {twoFactor?: string, expire?: string} opts 2FA code & expire date (YYYY-MM-DD)
|
|
1713
|
-
* @returns {Promise<
|
|
1683
|
+
* @returns {Promise<User>} User account
|
|
1714
1684
|
*/
|
|
1715
1685
|
login(spoke, login, password, opts) {
|
|
1716
1686
|
const date = /* @__PURE__ */ new Date();
|
|
@@ -1729,21 +1699,19 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
1729
1699
|
}).then(async (resp) => {
|
|
1730
1700
|
const data = await resp.json().catch(() => ({}));
|
|
1731
1701
|
if (!resp.ok || data["error"]) throw Object.assign(errorFromCode(resp.status, data.error) || {}, data);
|
|
1732
|
-
this.
|
|
1733
|
-
return await firstValueFrom(this.user$.pipe(filter((u) => (u == null ? void 0 : u.token) == data["token"])));
|
|
1702
|
+
return await this.current(data["token"], true);
|
|
1734
1703
|
});
|
|
1735
1704
|
}
|
|
1736
1705
|
/**
|
|
1737
1706
|
* Login as guest user
|
|
1738
1707
|
*
|
|
1739
|
-
* @return {Promise<
|
|
1708
|
+
* @return {Promise<User>} Guest account
|
|
1740
1709
|
*/
|
|
1741
1710
|
loginGuest() {
|
|
1742
1711
|
return fetch(`${this.api.url}guest`).then(async (resp) => {
|
|
1743
1712
|
const data = await resp.json().catch(() => ({}));
|
|
1744
1713
|
if (!resp.ok || data["error"]) throw Object.assign(errorFromCode(resp.status, data.error) || {}, data);
|
|
1745
|
-
this.
|
|
1746
|
-
return data;
|
|
1714
|
+
return await this.current(data["token"], true);
|
|
1747
1715
|
});
|
|
1748
1716
|
}
|
|
1749
1717
|
/**
|
|
@@ -2490,7 +2458,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
2490
2458
|
} });
|
|
2491
2459
|
}
|
|
2492
2460
|
}
|
|
2493
|
-
const version = "1.0.
|
|
2461
|
+
const version = "1.0.10";
|
|
2494
2462
|
class Api {
|
|
2495
2463
|
/**
|
|
2496
2464
|
* Connect to Datalynk & send requests
|
|
@@ -2561,10 +2529,11 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
2561
2529
|
return jwtDecode(this.token);
|
|
2562
2530
|
}
|
|
2563
2531
|
_request(req, options = {}) {
|
|
2532
|
+
const token = options.token || this.token;
|
|
2564
2533
|
return fetch(this.url, {
|
|
2565
2534
|
method: "POST",
|
|
2566
2535
|
headers: clean({
|
|
2567
|
-
Authorization:
|
|
2536
|
+
Authorization: token ? `Bearer ${token}` : void 0,
|
|
2568
2537
|
"Content-Type": "application/json",
|
|
2569
2538
|
"X-Date-Return-Format": this.options.legacyDates ? void 0 : "ISO8601"
|
|
2570
2539
|
}),
|
package/dist/index.mjs
CHANGED
|
@@ -1304,38 +1304,6 @@ var BehaviorSubject = function(_super) {
|
|
|
1304
1304
|
};
|
|
1305
1305
|
return BehaviorSubject2;
|
|
1306
1306
|
}(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
1307
|
function distinctUntilChanged(comparator, keySelector) {
|
|
1340
1308
|
if (keySelector === void 0) {
|
|
1341
1309
|
keySelector = identity;
|
|
@@ -1606,7 +1574,7 @@ class Auth {
|
|
|
1606
1574
|
/** Current user as an observable */
|
|
1607
1575
|
__publicField(this, "user$", new BehaviorSubject(void 0));
|
|
1608
1576
|
this.api = api;
|
|
1609
|
-
this.api.token$.subscribe(() => this.current());
|
|
1577
|
+
this.api.token$.subscribe((token) => this.current(token, true));
|
|
1610
1578
|
}
|
|
1611
1579
|
/** Current user */
|
|
1612
1580
|
get user() {
|
|
@@ -1625,14 +1593,21 @@ class Auth {
|
|
|
1625
1593
|
*
|
|
1626
1594
|
* @return {Promise<User | null>}
|
|
1627
1595
|
*/
|
|
1628
|
-
current() {
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1596
|
+
async current(token = this.api.token, set) {
|
|
1597
|
+
var _a;
|
|
1598
|
+
if (!token) {
|
|
1599
|
+
if (set && this.user != null) this.user = null;
|
|
1600
|
+
return null;
|
|
1601
|
+
} else if (token == ((_a = this.user) == null ? void 0 : _a.token)) {
|
|
1602
|
+
return this.user;
|
|
1632
1603
|
}
|
|
1633
|
-
return this.api.request({ "$/auth/current": {} }).then((resp) => {
|
|
1634
|
-
|
|
1635
|
-
|
|
1604
|
+
return this.api.request({ "$/auth/current": {} }, { token }).then((resp) => {
|
|
1605
|
+
const u = (resp == null ? void 0 : resp.login) ? resp : null;
|
|
1606
|
+
if (set) {
|
|
1607
|
+
this.api.token = token;
|
|
1608
|
+
this.user = u;
|
|
1609
|
+
}
|
|
1610
|
+
return u;
|
|
1636
1611
|
});
|
|
1637
1612
|
}
|
|
1638
1613
|
/**
|
|
@@ -1648,12 +1623,7 @@ class Auth {
|
|
|
1648
1623
|
if (urlToken) {
|
|
1649
1624
|
this.api.token = urlToken;
|
|
1650
1625
|
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 {
|
|
1626
|
+
} else if (!this.api.token) {
|
|
1657
1627
|
await this.loginPrompt(spoke, options).done;
|
|
1658
1628
|
location.reload();
|
|
1659
1629
|
}
|
|
@@ -1706,7 +1676,7 @@ class Auth {
|
|
|
1706
1676
|
* @param {string} password Password for account
|
|
1707
1677
|
* @param {string} spoke Override login spoke
|
|
1708
1678
|
* @param {twoFactor?: string, expire?: string} opts 2FA code & expire date (YYYY-MM-DD)
|
|
1709
|
-
* @returns {Promise<
|
|
1679
|
+
* @returns {Promise<User>} User account
|
|
1710
1680
|
*/
|
|
1711
1681
|
login(spoke, login, password, opts) {
|
|
1712
1682
|
const date = /* @__PURE__ */ new Date();
|
|
@@ -1725,21 +1695,19 @@ class Auth {
|
|
|
1725
1695
|
}).then(async (resp) => {
|
|
1726
1696
|
const data = await resp.json().catch(() => ({}));
|
|
1727
1697
|
if (!resp.ok || data["error"]) throw Object.assign(errorFromCode(resp.status, data.error) || {}, data);
|
|
1728
|
-
this.
|
|
1729
|
-
return await firstValueFrom(this.user$.pipe(filter((u) => (u == null ? void 0 : u.token) == data["token"])));
|
|
1698
|
+
return await this.current(data["token"], true);
|
|
1730
1699
|
});
|
|
1731
1700
|
}
|
|
1732
1701
|
/**
|
|
1733
1702
|
* Login as guest user
|
|
1734
1703
|
*
|
|
1735
|
-
* @return {Promise<
|
|
1704
|
+
* @return {Promise<User>} Guest account
|
|
1736
1705
|
*/
|
|
1737
1706
|
loginGuest() {
|
|
1738
1707
|
return fetch(`${this.api.url}guest`).then(async (resp) => {
|
|
1739
1708
|
const data = await resp.json().catch(() => ({}));
|
|
1740
1709
|
if (!resp.ok || data["error"]) throw Object.assign(errorFromCode(resp.status, data.error) || {}, data);
|
|
1741
|
-
this.
|
|
1742
|
-
return data;
|
|
1710
|
+
return await this.current(data["token"], true);
|
|
1743
1711
|
});
|
|
1744
1712
|
}
|
|
1745
1713
|
/**
|
|
@@ -2486,7 +2454,7 @@ class Superuser {
|
|
|
2486
2454
|
} });
|
|
2487
2455
|
}
|
|
2488
2456
|
}
|
|
2489
|
-
const version = "1.0.
|
|
2457
|
+
const version = "1.0.10";
|
|
2490
2458
|
class Api {
|
|
2491
2459
|
/**
|
|
2492
2460
|
* Connect to Datalynk & send requests
|
|
@@ -2557,10 +2525,11 @@ class Api {
|
|
|
2557
2525
|
return jwtDecode(this.token);
|
|
2558
2526
|
}
|
|
2559
2527
|
_request(req, options = {}) {
|
|
2528
|
+
const token = options.token || this.token;
|
|
2560
2529
|
return fetch(this.url, {
|
|
2561
2530
|
method: "POST",
|
|
2562
2531
|
headers: clean({
|
|
2563
|
-
Authorization:
|
|
2532
|
+
Authorization: token ? `Bearer ${token}` : void 0,
|
|
2564
2533
|
"Content-Type": "application/json",
|
|
2565
2534
|
"X-Date-Return-Format": this.options.legacyDates ? void 0 : "ISO8601"
|
|
2566
2535
|
}),
|
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.
|
|
5
|
+
"version": "1.0.10",
|
|
6
6
|
"author": "Zak Timson <zaktimson@gmail.com>",
|
|
7
7
|
"private": false,
|
|
8
8
|
"main": "./dist/index.cjs",
|