@ztimson/momentum 0.52.4 → 0.53.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -19,6 +19,13 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
19
19
  }
20
20
  return obj;
21
21
  }
22
+ function deepCopy(value2) {
23
+ try {
24
+ return structuredClone(value2);
25
+ } catch {
26
+ return JSON.parse(JSONSanitize(value2));
27
+ }
28
+ }
22
29
  function isEqual(a2, b2) {
23
30
  const ta = typeof a2, tb = typeof b2;
24
31
  if (ta != "object" || a2 == null || (tb != "object" || b2 == null))
@@ -177,11 +184,11 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
177
184
  return new Proxy(this, {
178
185
  get: (target, prop2) => {
179
186
  if (prop2 in target) return target[prop2];
180
- return target.store[prop2];
187
+ return deepCopy(target.store[prop2]);
181
188
  },
182
189
  set: (target, prop2, value2) => {
183
190
  if (prop2 in target) target[prop2] = value2;
184
- else target.store[prop2] = value2;
191
+ else this.set(prop2, value2);
185
192
  return true;
186
193
  }
187
194
  });
@@ -196,7 +203,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
196
203
  * @return {T[]} Array of items
197
204
  */
198
205
  all() {
199
- return Object.values(this.store);
206
+ return deepCopy(Object.values(this.store));
200
207
  }
201
208
  /**
202
209
  * Add a new item to the cache. Like set, but finds key automatically
@@ -251,7 +258,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
251
258
  * @return {T} Cached item
252
259
  */
253
260
  get(key) {
254
- return this.store[key];
261
+ return deepCopy(this.store[key]);
255
262
  }
256
263
  /**
257
264
  * Get a list of cached keys
@@ -267,7 +274,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
267
274
  * @return {Record<K, T>}
268
275
  */
269
276
  map() {
270
- return structuredClone(this.store);
277
+ return deepCopy(this.store);
271
278
  }
272
279
  /**
273
280
  * Add an item to the cache manually specifying the key
@@ -337,6 +344,106 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
337
344
  return this.from(super.finally(res));
338
345
  }
339
346
  }
347
+ function formatDate(format = "YYYY-MM-DD H:mm", date = /* @__PURE__ */ new Date(), tz) {
348
+ const timezones = [
349
+ ["IDLW", -12],
350
+ ["SST", -11],
351
+ ["HST", -10],
352
+ ["AKST", -9],
353
+ ["PST", -8],
354
+ ["MST", -7],
355
+ ["CST", -6],
356
+ ["EST", -5],
357
+ ["AST", -4],
358
+ ["BRT", -3],
359
+ ["MAT", -2],
360
+ ["AZOT", -1],
361
+ ["UTC", 0],
362
+ ["CET", 1],
363
+ ["EET", 2],
364
+ ["MSK", 3],
365
+ ["AST", 4],
366
+ ["PKT", 5],
367
+ ["IST", 5.5],
368
+ ["BST", 6],
369
+ ["ICT", 7],
370
+ ["CST", 8],
371
+ ["JST", 9],
372
+ ["AEST", 10],
373
+ ["SBT", 11],
374
+ ["FJT", 12],
375
+ ["TOT", 13],
376
+ ["LINT", 14]
377
+ ];
378
+ function adjustTz(date2, gmt) {
379
+ const currentOffset = date2.getTimezoneOffset();
380
+ const adjustedOffset = gmt * 60;
381
+ return new Date(date2.getTime() + (adjustedOffset + currentOffset) * 6e4);
382
+ }
383
+ function day(num) {
384
+ return ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"][num] || "Unknown";
385
+ }
386
+ function doy(date2) {
387
+ const start = /* @__PURE__ */ new Date(`${date2.getFullYear()}-01-01 0:00:00`);
388
+ return Math.ceil((date2.getTime() - start.getTime()) / (1e3 * 60 * 60 * 24));
389
+ }
390
+ function month(num) {
391
+ return ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"][num] || "Unknown";
392
+ }
393
+ function suffix(num) {
394
+ if (num % 100 >= 11 && num % 100 <= 13) return `${num}th`;
395
+ switch (num % 10) {
396
+ case 1:
397
+ return `${num}st`;
398
+ case 2:
399
+ return `${num}nd`;
400
+ case 3:
401
+ return `${num}rd`;
402
+ default:
403
+ return `${num}th`;
404
+ }
405
+ }
406
+ function tzOffset(offset) {
407
+ const hours = ~~(offset / 60);
408
+ const minutes = offset % 60;
409
+ return (offset > 0 ? "-" : "") + `${hours}:${minutes.toString().padStart(2, "0")}`;
410
+ }
411
+ if (typeof date == "number" || typeof date == "string") date = new Date(date);
412
+ let t;
413
+ if (tz == null) tz = -(date.getTimezoneOffset() / 60);
414
+ t = timezones.find((t2) => isNaN(tz) ? t2[0] == tz : t2[1] == tz);
415
+ if (!t) throw new Error(`Unknown timezone: ${tz}`);
416
+ date = adjustTz(date, t[1]);
417
+ const tokens = {
418
+ "YYYY": date.getFullYear().toString(),
419
+ "YY": date.getFullYear().toString().slice(2),
420
+ "MMMM": month(date.getMonth()),
421
+ "MMM": month(date.getMonth()).slice(0, 3),
422
+ "MM": (date.getMonth() + 1).toString().padStart(2, "0"),
423
+ "M": (date.getMonth() + 1).toString(),
424
+ "DDD": doy(date).toString(),
425
+ "DD": date.getDate().toString().padStart(2, "0"),
426
+ "Do": suffix(date.getDate()),
427
+ "D": date.getDate().toString(),
428
+ "dddd": day(date.getDay()),
429
+ "ddd": day(date.getDay()).slice(0, 3),
430
+ "HH": date.getHours().toString().padStart(2, "0"),
431
+ "H": date.getHours().toString(),
432
+ "hh": (date.getHours() % 12 || 12).toString().padStart(2, "0"),
433
+ "h": (date.getHours() % 12 || 12).toString(),
434
+ "mm": date.getMinutes().toString().padStart(2, "0"),
435
+ "m": date.getMinutes().toString(),
436
+ "ss": date.getSeconds().toString().padStart(2, "0"),
437
+ "s": date.getSeconds().toString(),
438
+ "SSS": date.getMilliseconds().toString().padStart(3, "0"),
439
+ "A": date.getHours() >= 12 ? "PM" : "AM",
440
+ "a": date.getHours() >= 12 ? "pm" : "am",
441
+ "ZZ": tzOffset(t[1] * 60).replace(":", ""),
442
+ "Z": tzOffset(t[1] * 60),
443
+ "z": typeof tz == "string" ? tz : t[0]
444
+ };
445
+ return format.replace(/YYYY|YY|MMMM|MMM|MM|M|DDD|DD|Do|D|dddd|ddd|HH|H|hh|h|mm|m|ss|s|SSS|A|a|ZZ|Z|z/g, (token) => tokens[token]);
446
+ }
340
447
  function downloadFile(blob, name) {
341
448
  if (!(blob instanceof Blob)) blob = new Blob(makeArray(blob));
342
449
  const url = URL.createObjectURL(blob);
@@ -368,7 +475,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
368
475
  }
369
476
  function timestampFilename(name, date = /* @__PURE__ */ new Date()) {
370
477
  if (typeof date == "number" || typeof date == "string") date = new Date(date);
371
- const timestamp = `${date.getFullYear()}-${(date.getMonth() + 1).toString().padStart(2, "0")}-${date.getDate().toString().padStart(2, "0")}_${date.getHours().toString().padStart(2, "0")}-${date.getMinutes().toString().padStart(2, "0")}-${date.getSeconds().toString().padStart(2, "0")}`;
478
+ const timestamp = formatDate("YYYY-MM-DD_HH:mm:ss", date);
372
479
  return timestamp;
373
480
  }
374
481
  function uploadWithProgress(options) {
@@ -986,6 +1093,10 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
986
1093
  if (token) this.token = token;
987
1094
  }
988
1095
  }
1096
+ get sameOrigin() {
1097
+ if (typeof window == "undefined" || !(window == null ? void 0 : window.location)) return false;
1098
+ return window.location.host == this.host;
1099
+ }
989
1100
  /** Current API token */
990
1101
  get token() {
991
1102
  return this._token;
@@ -1019,7 +1130,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
1019
1130
  const key = JSONSanitize(options);
1020
1131
  const method = options.method == "GET" ? "r" : options.method == "POST" ? "c" : options.method == "DELETE" ? "d" : "u";
1021
1132
  if (this.pending[key] != null) return this.pending[key];
1022
- this.pending[key] = super.request(options).then((response) => {
1133
+ this.pending[key] = super.request({ ...options, credentials: "include" }).then((response) => {
1023
1134
  this.emit(PES`api/response:${method}`, { request: options, response });
1024
1135
  return options.decode === false ? response : response.data;
1025
1136
  }).catch((err) => {
@@ -1061,6 +1172,15 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
1061
1172
  return resp;
1062
1173
  });
1063
1174
  }
1175
+ /**
1176
+ * Manually trigger an actions execution
1177
+ * @param {string} id Action ID
1178
+ * @param {HttpRequestOptions} opts Additional arguments
1179
+ * @return {Promise<ActionResult>} All action output including console logs & return
1180
+ */
1181
+ debug(id, opts = {}) {
1182
+ return this.api.request({ url: "/api/" + PES`actions/debug/${id}`, method: "POST", ...opts });
1183
+ }
1064
1184
  /**
1065
1185
  * Delete an existing action
1066
1186
  * @param {string} id Action ID
@@ -1090,13 +1210,13 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
1090
1210
  });
1091
1211
  }
1092
1212
  /**
1093
- * Manually trigger an actions execution
1094
- * @param {string} id Action ID
1095
- * @param {HttpRequestOptions} opts Additional arguments
1096
- * @return {Promise<ActionResult>} Result of action
1213
+ * Run an HTTP action
1214
+ * @param {string} path HTTP path excluding `/api/actions/run`
1215
+ * @param {HttpRequestOptions} opts HTTP options
1216
+ * @return {Promise<T>} HTTP response
1097
1217
  */
1098
- runById(id, opts = {}) {
1099
- return this.api.request({ url: "/api/" + PES`actions/run-by-id/${id}`, method: "POST", ...opts });
1218
+ run(path, opts = {}) {
1219
+ return this.api.request({ ...opts, url: "/api/" + PES`actions/run/${path}` });
1100
1220
  }
1101
1221
  /**
1102
1222
  * Update an action
@@ -1154,6 +1274,13 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
1154
1274
  return resp;
1155
1275
  });
1156
1276
  }
1277
+ /**
1278
+ * Get model info
1279
+ * @return {Promise<{host: string, model: string}>} Model Info
1280
+ */
1281
+ info() {
1282
+ return this.api.request({ url: "/api/ai/info" });
1283
+ }
1157
1284
  }
1158
1285
  class Analytics extends PathEventEmitter {
1159
1286
  constructor(api) {
@@ -1272,7 +1399,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
1272
1399
  this.totp = new Totp(this.api);
1273
1400
  this.relayEvents(this.token);
1274
1401
  this.opts = {
1275
- loginUrl: this.api.url + "/ui/#/login",
1402
+ loginUrl: this.api.url + "/ui/login",
1276
1403
  ...this.opts
1277
1404
  };
1278
1405
  this.api.addInterceptor((resp, next) => {
@@ -1354,12 +1481,11 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
1354
1481
  loginRedirect(host = location.origin) {
1355
1482
  return new Promise((res, rej) => {
1356
1483
  var _a;
1357
- let origin = new URL(this.opts.loginUrl).origin, done = false, listener, win;
1484
+ let origin = new URL(this.opts.loginUrl).origin, listener, win;
1358
1485
  window.addEventListener("message", listener = (event) => {
1359
1486
  const data = (event == null ? void 0 : event.data) || {};
1360
1487
  if (event.origin != origin || data.sender != origin) return;
1361
1488
  if (!data.token) return rej("Unknown response from login");
1362
- done = true;
1363
1489
  this.api.token = data.token;
1364
1490
  window.removeEventListener("message", listener);
1365
1491
  win.close();
@@ -1370,9 +1496,6 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
1370
1496
  window.removeEventListener("message", listener);
1371
1497
  return rej("Unable to open login");
1372
1498
  }
1373
- win.addEventListener("close", () => {
1374
- if (!done) rej("Window closed before logging in");
1375
- });
1376
1499
  });
1377
1500
  }
1378
1501
  /**
@@ -1381,6 +1504,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
1381
1504
  logout() {
1382
1505
  this.emit(PES`auth/logout:d`, this.user);
1383
1506
  this.api.token = null;
1507
+ this.api.request({ url: "/api/auth/logout", method: "DELETE" });
1384
1508
  this.user = null;
1385
1509
  }
1386
1510
  /**
@@ -1392,8 +1516,10 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
1392
1516
  var _a;
1393
1517
  if (!user.username || !user.password) throw new Error("Cannot register user, missing username or password");
1394
1518
  const u = await this.api.request({ url: "/api/auth/register", body: { ...user } });
1395
- if ((_a = u == null ? void 0 : u.image) == null ? void 0 : _a.startsWith("/")) u.image = `${this.api.url}${u.image}?token=${this.api.token}`;
1396
- this.emit(PES`auth/register:c`, u);
1519
+ if ((_a = u == null ? void 0 : u.image) == null ? void 0 : _a.startsWith("/")) u.image = `${this.api.url}${u.image}${!this.api.sameOrigin && this.api.token ? `?token=${this.api.token}` : ""}`;
1520
+ this.user = u;
1521
+ this.permissions = [];
1522
+ this.emit(PES`auth/register:u`, u);
1397
1523
  return u;
1398
1524
  }
1399
1525
  reset(emailOrPass, token) {
@@ -1424,7 +1550,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
1424
1550
  this.emit(PES`auth/session:r`, session);
1425
1551
  if (set) {
1426
1552
  this.api.token = token;
1427
- if (session == null ? void 0 : session.user) session.user.image = `${this.api.url}${session.user.image}?token=${this.api.token}`;
1553
+ if (session == null ? void 0 : session.user) session.user.image = `${this.api.url}${session.user.image}${!this.api.sameOrigin && this.api.token ? `?token=${this.api.token}` : ""}`;
1428
1554
  this.user = (session == null ? void 0 : session.user) || null;
1429
1555
  this.permissions = (session == null ? void 0 : session.permissions) || [];
1430
1556
  if (session) this.emit(PES`auth/login:c`, session.user);
@@ -1509,7 +1635,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
1509
1635
  * @return {Promise<void>} Resolves on completion
1510
1636
  */
1511
1637
  async init(opts = {}) {
1512
- var _a, _b, _c, _d, _e, _f, _g;
1638
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i;
1513
1639
  opts = {
1514
1640
  reload: void 0,
1515
1641
  pwa: true,
@@ -1526,7 +1652,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
1526
1652
  if (!this.settings.cache.keys().length) opts.reload = true;
1527
1653
  let settings = await (opts.reload ? this.settings.all(false, true) : this.settings.cache);
1528
1654
  if (opts.reload == null) this.settings.all(false, true).then(() => this.init({ reload: false }));
1529
- if (settings["title"]) document.querySelectorAll(".momentum-title").forEach((el) => el.innerText = settings["title"]);
1655
+ if (settings["title"]) document.querySelectorAll(".momentum-title").forEach((el) => el.innerText = el.innerText.includes("|") ? `${el.innerText.split("|")[0].trim()} | ${settings["title"]}` : settings["title"]);
1530
1656
  if (settings["description"]) document.querySelectorAll(".momentum-description").forEach((el) => el.innerText = settings["description"]);
1531
1657
  if (settings["version"]) document.querySelectorAll(".momentum-version").forEach((el) => el.innerText = settings["version"]);
1532
1658
  if (settings["logo"]) document.querySelectorAll(".momentum-logo").forEach((el) => el.src = settings["logo"]);
@@ -1571,6 +1697,8 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
1571
1697
  --theme-primary: ${(_e = settings["theme"]) == null ? void 0 : _e.primary} !important;
1572
1698
  --theme-accent: ${(_f = settings["theme"]) == null ? void 0 : _f.accent} !important;
1573
1699
  --theme-contrast: ${blackOrWhite((_g = settings["theme"]) == null ? void 0 : _g.background)} !important;
1700
+ --theme-primary-contrast: ${blackOrWhite((_h = settings["theme"]) == null ? void 0 : _h.primary)} !important;
1701
+ --theme-accent-contrast: ${blackOrWhite((_i = settings["theme"]) == null ? void 0 : _i.accent)} !important;
1574
1702
  }
1575
1703
  `;
1576
1704
  if (!style.parentElement) document.head.append(style);
@@ -1807,6 +1935,59 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
1807
1935
  });
1808
1936
  }
1809
1937
  }
1938
+ class Discounts extends PathEventEmitter {
1939
+ constructor(api) {
1940
+ super();
1941
+ this.api = api;
1942
+ }
1943
+ all() {
1944
+ return this.api.request({
1945
+ url: `/api/payments/discounts`,
1946
+ method: "GET"
1947
+ }).then((resp) => {
1948
+ this.emit(`discounts:r`, resp);
1949
+ return resp;
1950
+ });
1951
+ }
1952
+ create(discount) {
1953
+ return this.api.request({
1954
+ url: "/api/payments/discounts",
1955
+ method: "POST",
1956
+ body: discount
1957
+ }).then((resp) => {
1958
+ this.emit(`discounts/${resp.code}:c`, resp);
1959
+ return resp;
1960
+ });
1961
+ }
1962
+ delete(discount) {
1963
+ const code = typeof discount == "string" ? discount : discount.code;
1964
+ return this.api.request({
1965
+ url: `/api/payments/discounts/${code}`,
1966
+ method: "DELETE"
1967
+ }).then(() => {
1968
+ this.emit(`discounts/${code}:d`, code);
1969
+ });
1970
+ }
1971
+ read(code) {
1972
+ return this.api.request({
1973
+ url: `/api/payments/discounts/${code}`,
1974
+ method: "GET"
1975
+ }).then((resp) => {
1976
+ this.emit(`discounts/${code}:r`, resp);
1977
+ return resp;
1978
+ });
1979
+ }
1980
+ update(discount) {
1981
+ return this.api.request({
1982
+ url: "/api/payments/discounts",
1983
+ method: "PATCH",
1984
+ body: discount
1985
+ }).then((resp) => {
1986
+ this.emit(`discounts/${resp.code}:u`, resp);
1987
+ return resp;
1988
+ });
1989
+ }
1990
+ }
1810
1991
  class Email extends PathEventEmitter {
1811
1992
  constructor(api) {
1812
1993
  super();
@@ -1942,7 +2123,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
1942
2123
  if (LOG_LEVEL[logLevel] >= 0) {
1943
2124
  console.error = (...args) => {
1944
2125
  this.console.error(...args);
1945
- this.error(...args);
2126
+ this.error(args);
1946
2127
  };
1947
2128
  window.addEventListener("unhandledrejection", async (event) => {
1948
2129
  var _a, _b, _c, _d;
@@ -1957,25 +2138,25 @@ ${log}`;
1957
2138
  if (LOG_LEVEL[logLevel] >= 1) {
1958
2139
  console.warn = (...args) => {
1959
2140
  this.console.warn(...args);
1960
- this.warn(...args);
2141
+ this.warn(args);
1961
2142
  };
1962
2143
  }
1963
2144
  if (LOG_LEVEL[logLevel] >= 2) {
1964
2145
  console.info = (...args) => {
1965
2146
  this.console.info(...args);
1966
- this.info(...args);
2147
+ this.info(args);
1967
2148
  };
1968
2149
  }
1969
2150
  if (LOG_LEVEL[logLevel] >= 3) {
1970
2151
  console.log = (...args) => {
1971
2152
  this.console.log(...args);
1972
- this.log(...args);
2153
+ this.log(args);
1973
2154
  };
1974
2155
  }
1975
2156
  if (LOG_LEVEL[logLevel] >= 4) {
1976
2157
  console.debug = (...args) => {
1977
2158
  this.console.debug(...args);
1978
- this.debug(...args);
2159
+ this.debug(args);
1979
2160
  };
1980
2161
  }
1981
2162
  }
@@ -2031,6 +2212,7 @@ ${log}`;
2031
2212
  constructor(api, opts = {}) {
2032
2213
  super();
2033
2214
  __publicField(this, "api");
2215
+ __publicField(this, "discounts");
2034
2216
  /** Stripe object */
2035
2217
  __publicField(this, "stripe");
2036
2218
  /** Public stripe token */
@@ -2038,9 +2220,11 @@ ${log}`;
2038
2220
  this.opts = opts;
2039
2221
  this.api = typeof api == "string" ? new Api(api) : api;
2040
2222
  this.opts = {
2041
- paymentUrl: this.api.url + "/ui/#/payment",
2223
+ paymentUrl: this.api.url + "/ui/payments/checkout",
2042
2224
  ...this.opts
2043
2225
  };
2226
+ this.discounts = new Discounts(this.api);
2227
+ this.relayEvents(this.discounts);
2044
2228
  }
2045
2229
  /**
2046
2230
  * Initialize stripe API
@@ -2155,12 +2339,11 @@ ${log}`;
2155
2339
  paymentRedirect(id, host = location.origin) {
2156
2340
  return new Promise(async (res, rej) => {
2157
2341
  var _a;
2158
- let origin = new URL(this.opts.paymentUrl).origin, done = false, listener, win;
2342
+ let origin = new URL(this.opts.paymentUrl).origin, listener, win;
2159
2343
  window.addEventListener("message", listener = (event) => {
2160
2344
  const data = (event == null ? void 0 : event.data) || {};
2161
2345
  if (event.origin != origin || data.sender != origin) return;
2162
2346
  if (!data.response) return rej("Unknown response from payment page");
2163
- done = true;
2164
2347
  window.removeEventListener("message", listener);
2165
2348
  win.close();
2166
2349
  res(data.response);
@@ -2170,9 +2353,17 @@ ${log}`;
2170
2353
  window.removeEventListener("message", listener);
2171
2354
  return rej("Unable to open payment page");
2172
2355
  }
2173
- win.addEventListener("close", () => {
2174
- if (!done) rej("Window closed before payment was complete");
2175
- });
2356
+ });
2357
+ }
2358
+ /**
2359
+ * Refund a transaction
2360
+ * @param {string} id Transaction number to refund
2361
+ * @return {PromiseProgress<any>}
2362
+ */
2363
+ refund(id) {
2364
+ return this.api.request({ url: `/api/payments/transactions/${id || ""}`, method: "DELETE" }).then((resp) => {
2365
+ this.emit(PES`products/${id ?? ""}:d`, resp);
2366
+ return resp;
2176
2367
  });
2177
2368
  }
2178
2369
  }
@@ -2308,7 +2499,7 @@ ${log}`;
2308
2499
  }
2309
2500
  open(path, target = "_blank") {
2310
2501
  if (!path) throw new Error("Cannot download file, missing path");
2311
- const link = `${this.api.url}/api/` + PES`${this.path}/${path}` + (this.api.token ? `?token=${this.api.token}` : "");
2502
+ const link = `${this.api.url}/api/` + PES`${this.path}/${path}${!this.api.sameOrigin && this.api.token ? `?token=${this.api.token}` : ""}`;
2312
2503
  if (!target) return link;
2313
2504
  this.emit(PES`${this.path}/${path}:r`, path);
2314
2505
  return window.open(link, target);
@@ -2357,7 +2548,7 @@ ${log}`;
2357
2548
  if (!reload && this.cache.complete) return this.cache.all();
2358
2549
  return this.api.request({ url: "/api/" + PES`users` }).then((resp) => {
2359
2550
  resp == null ? void 0 : resp.forEach((r) => {
2360
- r.image = this.api.url + r.image + `?token=${this.api.token}`;
2551
+ r.image = `${this.api.url}${r.image}${!this.api.sameOrigin && this.api.token ? `?token=${this.api.token}` : ""}`;
2361
2552
  return r;
2362
2553
  });
2363
2554
  this.cache.addAll(resp);
@@ -2380,7 +2571,7 @@ ${log}`;
2380
2571
  if (!reload && this.cache.get(username)) return this.cache.get(username);
2381
2572
  return this.api.request({ url: "/api/" + PES`users/${username}` }).then((resp) => {
2382
2573
  if (resp) {
2383
- resp.image = this.api.url + resp.image + `?token=${this.api.token}`;
2574
+ resp.image = `${this.api.url}${resp.image}${!this.api.sameOrigin && this.api.token ? `?token=${this.api.token}` : ""}`;
2384
2575
  this.cache.add(resp);
2385
2576
  }
2386
2577
  this.emit(PES`users/${username}:r`, resp);
@@ -2540,6 +2731,7 @@ ${log}`;
2540
2731
  exports2.Auth = Auth;
2541
2732
  exports2.Client = Client;
2542
2733
  exports2.Data = Data;
2734
+ exports2.Discounts = Discounts;
2543
2735
  exports2.Email = Email;
2544
2736
  exports2.Forms = Forms;
2545
2737
  exports2.Groups = Groups;
package/dist/index.d.ts CHANGED
@@ -7,6 +7,7 @@ export * from './auth';
7
7
  export * from './client';
8
8
  export * from './core';
9
9
  export * from './data';
10
+ export * from './discounts';
10
11
  export * from './email';
11
12
  export * from './forms';
12
13
  export * from './groups';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,KAAK,iBAAiB,EACtB,EAAE,EAAE,GAAG,EAAE,SAAS,EAClB,KAAK,YAAY,EACjB,KAAK,eAAe,EACpB,gBAAgB,EAChB,MAAM,gBAAgB,CAAC;AAExB,cAAc,WAAW,CAAC;AAC1B,cAAc,MAAM,CAAC;AACrB,cAAc,aAAa,CAAC;AAC5B,cAAc,OAAO,CAAC;AACtB,cAAc,QAAQ,CAAC;AACvB,cAAc,UAAU,CAAC;AACzB,cAAc,QAAQ,CAAC;AACvB,cAAc,QAAQ,CAAC;AACvB,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,cAAc,SAAS,CAAC;AACxB,cAAc,OAAO,CAAC;AACtB,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,KAAK,iBAAiB,EACtB,EAAE,EAAE,GAAG,EAAE,SAAS,EAClB,KAAK,YAAY,EACjB,KAAK,eAAe,EACpB,gBAAgB,EAChB,MAAM,gBAAgB,CAAC;AAExB,cAAc,WAAW,CAAC;AAC1B,cAAc,MAAM,CAAC;AACrB,cAAc,aAAa,CAAC;AAC5B,cAAc,OAAO,CAAC;AACtB,cAAc,QAAQ,CAAC;AACvB,cAAc,UAAU,CAAC;AACzB,cAAc,QAAQ,CAAC;AACvB,cAAc,QAAQ,CAAC;AACvB,cAAc,aAAa,CAAC;AAC5B,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,cAAc,SAAS,CAAC;AACxB,cAAc,OAAO,CAAC;AACtB,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC"}