@ztimson/momentum 0.52.3 → 0.53.0

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.mjs CHANGED
@@ -571,6 +571,20 @@ class GatewayTimeoutError extends CustomError {
571
571
  }
572
572
  }
573
573
  __publicField2(GatewayTimeoutError, "code", 504);
574
+ class HttpResponse extends Response {
575
+ constructor(resp, stream) {
576
+ super(stream, { headers: resp.headers, status: resp.status, statusText: resp.statusText });
577
+ __publicField2(this, "data");
578
+ __publicField2(this, "ok");
579
+ __publicField2(this, "redirected");
580
+ __publicField2(this, "type");
581
+ __publicField2(this, "url");
582
+ this.ok = resp.ok;
583
+ this.redirected = resp.redirected;
584
+ this.type = resp.type;
585
+ this.url = resp.url;
586
+ }
587
+ }
574
588
  const _Http = class _Http2 {
575
589
  constructor(defaults = {}) {
576
590
  __publicField2(this, "interceptors", {});
@@ -642,13 +656,13 @@ const _Http = class _Http2 {
642
656
  push();
643
657
  }
644
658
  });
645
- resp.data = new Response(stream);
646
- if (opts.decode == null || opts.decode) {
659
+ resp = new HttpResponse(resp, stream);
660
+ if (opts.decode !== false) {
647
661
  const content = (_b = resp.headers.get("Content-Type")) == null ? void 0 : _b.toLowerCase();
648
- if (content == null ? void 0 : content.includes("form")) resp.data = await resp.data.formData();
649
- else if (content == null ? void 0 : content.includes("json")) resp.data = await resp.data.json();
650
- else if (content == null ? void 0 : content.includes("text")) resp.data = await resp.data.text();
651
- else if (content == null ? void 0 : content.includes("application")) resp.data = await resp.data.blob();
662
+ if (content == null ? void 0 : content.includes("form")) resp.data = await resp.formData();
663
+ else if (content == null ? void 0 : content.includes("json")) resp.data = await resp.json();
664
+ else if (content == null ? void 0 : content.includes("text")) resp.data = await resp.text();
665
+ else if (content == null ? void 0 : content.includes("application")) resp.data = await resp.blob();
652
666
  }
653
667
  if (resp.ok) res(resp);
654
668
  else rej(resp);
@@ -1003,7 +1017,7 @@ class Api extends Http {
1003
1017
  if (this.pending[key] != null) return this.pending[key];
1004
1018
  this.pending[key] = super.request(options).then((response) => {
1005
1019
  this.emit(PES`api/response:${method}`, { request: options, response });
1006
- return response.data;
1020
+ return options.decode === false ? response : response.data;
1007
1021
  }).catch((err) => {
1008
1022
  const e = (err == null ? void 0 : err.data) || err;
1009
1023
  this.emit(PES`api/error:${method}`, { request: options, error: e });
@@ -1043,6 +1057,15 @@ class Actions extends PathEventEmitter {
1043
1057
  return resp;
1044
1058
  });
1045
1059
  }
1060
+ /**
1061
+ * Manually trigger an actions execution
1062
+ * @param {string} id Action ID
1063
+ * @param {HttpRequestOptions} opts Additional arguments
1064
+ * @return {Promise<ActionResult>} All action output including console logs & return
1065
+ */
1066
+ debug(id, opts = {}) {
1067
+ return this.api.request({ url: "/api/" + PES`actions/debug/${id}`, method: "POST", ...opts });
1068
+ }
1046
1069
  /**
1047
1070
  * Delete an existing action
1048
1071
  * @param {string} id Action ID
@@ -1072,13 +1095,13 @@ class Actions extends PathEventEmitter {
1072
1095
  });
1073
1096
  }
1074
1097
  /**
1075
- * Manually trigger an actions execution
1076
- * @param {string} id Action ID
1077
- * @param {HttpRequestOptions} opts Additional arguments
1078
- * @return {Promise<ActionResult>} Result of action
1098
+ * Run an HTTP action
1099
+ * @param {string} path HTTP path excluding `/api/actions/run`
1100
+ * @param {HttpRequestOptions} opts HTTP options
1101
+ * @return {Promise<T>} HTTP response
1079
1102
  */
1080
- runById(id, opts = {}) {
1081
- return this.api.request({ url: "/api/" + PES`actions/run-by-id/${id}`, method: "POST", ...opts });
1103
+ run(path, opts = {}) {
1104
+ return this.api.request({ ...opts, url: "/api/" + PES`actions/run/${path}` });
1082
1105
  }
1083
1106
  /**
1084
1107
  * Update an action
@@ -1254,7 +1277,7 @@ class Auth extends PathEventEmitter {
1254
1277
  this.totp = new Totp(this.api);
1255
1278
  this.relayEvents(this.token);
1256
1279
  this.opts = {
1257
- loginUrl: this.api.url + "/ui/#/login",
1280
+ loginUrl: this.api.url + "/ui/login",
1258
1281
  ...this.opts
1259
1282
  };
1260
1283
  this.api.addInterceptor((resp, next) => {
@@ -1336,12 +1359,11 @@ class Auth extends PathEventEmitter {
1336
1359
  loginRedirect(host = location.origin) {
1337
1360
  return new Promise((res, rej) => {
1338
1361
  var _a;
1339
- let origin = new URL(this.opts.loginUrl).origin, done = false, listener, win;
1362
+ let origin = new URL(this.opts.loginUrl).origin, listener, win;
1340
1363
  window.addEventListener("message", listener = (event) => {
1341
1364
  const data = (event == null ? void 0 : event.data) || {};
1342
1365
  if (event.origin != origin || data.sender != origin) return;
1343
1366
  if (!data.token) return rej("Unknown response from login");
1344
- done = true;
1345
1367
  this.api.token = data.token;
1346
1368
  window.removeEventListener("message", listener);
1347
1369
  win.close();
@@ -1352,9 +1374,6 @@ class Auth extends PathEventEmitter {
1352
1374
  window.removeEventListener("message", listener);
1353
1375
  return rej("Unable to open login");
1354
1376
  }
1355
- win.addEventListener("close", () => {
1356
- if (!done) rej("Window closed before logging in");
1357
- });
1358
1377
  });
1359
1378
  }
1360
1379
  /**
@@ -1491,7 +1510,7 @@ class Client extends PathEventEmitter {
1491
1510
  * @return {Promise<void>} Resolves on completion
1492
1511
  */
1493
1512
  async init(opts = {}) {
1494
- var _a, _b, _c, _d, _e, _f, _g;
1513
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i;
1495
1514
  opts = {
1496
1515
  reload: void 0,
1497
1516
  pwa: true,
@@ -1553,6 +1572,8 @@ class Client extends PathEventEmitter {
1553
1572
  --theme-primary: ${(_e = settings["theme"]) == null ? void 0 : _e.primary} !important;
1554
1573
  --theme-accent: ${(_f = settings["theme"]) == null ? void 0 : _f.accent} !important;
1555
1574
  --theme-contrast: ${blackOrWhite((_g = settings["theme"]) == null ? void 0 : _g.background)} !important;
1575
+ --theme-primary-contrast: ${blackOrWhite((_h = settings["theme"]) == null ? void 0 : _h.primary)} !important;
1576
+ --theme-accent-contrast: ${blackOrWhite((_i = settings["theme"]) == null ? void 0 : _i.accent)} !important;
1556
1577
  }
1557
1578
  `;
1558
1579
  if (!style.parentElement) document.head.append(style);
@@ -1789,6 +1810,59 @@ class Data extends PathEventEmitter {
1789
1810
  });
1790
1811
  }
1791
1812
  }
1813
+ class Discounts extends PathEventEmitter {
1814
+ constructor(api) {
1815
+ super();
1816
+ this.api = api;
1817
+ }
1818
+ all() {
1819
+ return this.api.request({
1820
+ url: `/api/payments/discounts`,
1821
+ method: "GET"
1822
+ }).then((resp) => {
1823
+ this.emit(`discounts:r`, resp);
1824
+ return resp;
1825
+ });
1826
+ }
1827
+ create(discount) {
1828
+ return this.api.request({
1829
+ url: "/api/payments/discounts",
1830
+ method: "POST",
1831
+ body: discount
1832
+ }).then((resp) => {
1833
+ this.emit(`discounts/${resp.code}:c`, resp);
1834
+ return resp;
1835
+ });
1836
+ }
1837
+ delete(discount) {
1838
+ const code = typeof discount == "string" ? discount : discount.code;
1839
+ return this.api.request({
1840
+ url: `/api/payments/discounts/${code}`,
1841
+ method: "DELETE"
1842
+ }).then(() => {
1843
+ this.emit(`discounts/${code}:d`, code);
1844
+ });
1845
+ }
1846
+ read(code) {
1847
+ return this.api.request({
1848
+ url: `/api/payments/discounts/${code}`,
1849
+ method: "GET"
1850
+ }).then((resp) => {
1851
+ this.emit(`discounts/${code}:r`, resp);
1852
+ return resp;
1853
+ });
1854
+ }
1855
+ update(discount) {
1856
+ return this.api.request({
1857
+ url: "/api/payments/discounts",
1858
+ method: "PATCH",
1859
+ body: discount
1860
+ }).then((resp) => {
1861
+ this.emit(`discounts/${resp.code}:u`, resp);
1862
+ return resp;
1863
+ });
1864
+ }
1865
+ }
1792
1866
  class Email extends PathEventEmitter {
1793
1867
  constructor(api) {
1794
1868
  super();
@@ -2013,53 +2087,100 @@ class Payments extends PathEventEmitter {
2013
2087
  constructor(api, opts = {}) {
2014
2088
  super();
2015
2089
  __publicField(this, "api");
2016
- __publicField(this, "loaded", false);
2090
+ __publicField(this, "discounts");
2091
+ /** Stripe object */
2017
2092
  __publicField(this, "stripe");
2093
+ /** Public stripe token */
2018
2094
  __publicField(this, "token");
2019
2095
  this.opts = opts;
2020
2096
  this.api = typeof api == "string" ? new Api(api) : api;
2021
2097
  this.opts = {
2022
- paymentUrl: this.api.url + "/ui/#/payment",
2098
+ paymentUrl: this.api.url + "/ui/payments/checkout",
2023
2099
  ...this.opts
2024
2100
  };
2101
+ this.discounts = new Discounts(this.api);
2102
+ this.relayEvents(this.discounts);
2025
2103
  }
2026
- async checkout(cart, opts = {}) {
2027
- if (!(cart == null ? void 0 : cart.length)) throw new Error("Please add items to cart`");
2028
- const request = await this.api.request({ url: "/api/payments", body: {
2029
- cart,
2030
- recipient: opts == null ? void 0 : opts.recipient,
2031
- invoice: opts == null ? void 0 : opts.invoice,
2032
- extra: opts == null ? void 0 : opts.extra
2033
- } });
2034
- this.emit(PES`payments:c`, request.token);
2035
- return request.token;
2036
- }
2104
+ /**
2105
+ * Initialize stripe API
2106
+ * @return {Promise<any>} Returns stripe API
2107
+ * @private
2108
+ */
2037
2109
  async init() {
2038
- if (!this.stripe) this.stripe = await new Promise((res) => {
2039
- if (this.loaded || this.stripe) return res(window["Stripe"]);
2040
- const script = document.createElement("script");
2041
- script.src = "https://js.stripe.com/v3/";
2042
- script.setAttribute("crossorigin", "anonymous");
2043
- script.onload = () => res(window["Stripe"]);
2044
- document.head.appendChild(script);
2045
- });
2110
+ await new Promise((res) => {
2111
+ if (this.stripe) return res(window["Stripe"]);
2112
+ const stripeScript = document.createElement("script");
2113
+ stripeScript.src = "https://js.stripe.com/v3/";
2114
+ stripeScript.setAttribute("crossorigin", "anonymous");
2115
+ stripeScript.onload = () => res();
2116
+ document.head.appendChild(stripeScript);
2117
+ }).then(() => this.stripe = window["Stripe"]);
2046
2118
  return this.stripe(this.token);
2047
2119
  }
2120
+ /**
2121
+ * Create a stripe client secret to complete transaction
2122
+ * @param {string} id Transaction ID
2123
+ * @return {Promise<string>} Client secret
2124
+ * @private
2125
+ */
2126
+ createSecret(id) {
2127
+ return this.api.request({ url: `/api/payments/init/${id || ""}`, method: "POST" }).then((resp) => resp.token);
2128
+ }
2129
+ /**
2130
+ * Create/Update a transaction
2131
+ * @param {Optional<Transaction, "subtotal" | "total">} transaction Transaction information
2132
+ * @return {Promise<string>} Completed translation information
2133
+ */
2134
+ checkout(transaction) {
2135
+ return this.api.request({
2136
+ url: `/api/payments/transactions/${transaction._id || ""}`,
2137
+ method: transaction._id ? "PATCH" : "POST",
2138
+ body: transaction
2139
+ }).then((resp) => {
2140
+ this.emit(PES`payments:c`, resp);
2141
+ return resp;
2142
+ });
2143
+ }
2144
+ /**
2145
+ * Get translation history
2146
+ * @param {string} username Limit history to user
2147
+ * @return {Promise<Transaction[]>} List of translations
2148
+ */
2048
2149
  async history(username) {
2049
- const history = await this.api.request({ url: `/api/payments/${username || ""}` });
2050
- this.emit(PES`payments/${username}:r`, history);
2051
- return history;
2150
+ return this.api.request({ url: `/api/payments/transactions/${username || ""}` }).then((resp) => {
2151
+ this.emit(PES`payments/${username}:r`, resp);
2152
+ return resp;
2153
+ });
2154
+ }
2155
+ /**
2156
+ * Send recipient transaction receipt or invoice
2157
+ * @param {string} id Translation ID
2158
+ * @return {Promise<void>} Returns once complete
2159
+ */
2160
+ notify(id) {
2161
+ return this.api.request({ url: `/api/payments/notify/${id || ""}`, method: "POST" });
2052
2162
  }
2053
- async products(id) {
2163
+ /**
2164
+ * Retrieve a list of available products
2165
+ * @param {string | number} id Limit to specific product
2166
+ * @return {Promise<any>} List of products or single product if ID is used
2167
+ */
2168
+ products(id) {
2054
2169
  return this.api.request({ url: `/api/payments/products/${id || ""}` }).then((resp) => {
2055
- this.emit(PES`products/${id}:r`, resp);
2170
+ this.emit(PES`products/${id ?? ""}:r`, resp);
2056
2171
  return resp;
2057
2172
  });
2058
2173
  }
2059
- async payment(card, token) {
2060
- const client = await this.init();
2174
+ /**
2175
+ * Process payment programmatically
2176
+ * @param {string} id Transaction ID
2177
+ * @param {Card} card Credit card information
2178
+ * @return {Promise<any>} Stripe confirmation
2179
+ */
2180
+ async payment(id, card) {
2181
+ const [client, secret] = await Promise.all([this.init(), this.createSecret(id)]);
2061
2182
  return client.confirmPayment({
2062
- clientSecret: token,
2183
+ clientSecret: secret,
2063
2184
  confirmParams: {
2064
2185
  payment_method: {
2065
2186
  card: { ...card, details: void 0 },
@@ -2068,9 +2189,15 @@ class Payments extends PathEventEmitter {
2068
2189
  }
2069
2190
  });
2070
2191
  }
2071
- async paymentForm(element, token) {
2072
- const client = await this.init();
2073
- const form = client.elements({ clientSecret: token });
2192
+ /**
2193
+ * Process payment using Stripe form
2194
+ * @param {string} id Transaction ID
2195
+ * @param {string} element DOM element to inject form into
2196
+ * @return {Promise<() => Promise<any>>} Callback to submit form
2197
+ */
2198
+ async paymentForm(id, element) {
2199
+ const [client, secret] = await Promise.all([this.init(), this.createSecret(id)]);
2200
+ const form = client.elements({ clientSecret: secret });
2074
2201
  form.create("payment").mount(element);
2075
2202
  return (redirect = location.href) => client.confirmPayment({
2076
2203
  elements: form,
@@ -2080,31 +2207,38 @@ class Payments extends PathEventEmitter {
2080
2207
  }
2081
2208
  /**
2082
2209
  * Complete payment via Momentum's payment page
2083
- * @param {string} token Stripe payment intent secret
2210
+ * @param {string} id Transaction ID
2084
2211
  * @param {string} host Host origin attempting to login
2085
- * @return {Promise<string>} Token on success
2212
+ * @return {Promise<string>} Translation ID on success
2086
2213
  */
2087
- paymentRedirect(token, host = location.origin) {
2214
+ paymentRedirect(id, host = location.origin) {
2088
2215
  return new Promise(async (res, rej) => {
2089
2216
  var _a;
2090
- let origin = new URL(this.opts.paymentUrl).origin, done = false, listener, win;
2217
+ let origin = new URL(this.opts.paymentUrl).origin, listener, win;
2091
2218
  window.addEventListener("message", listener = (event) => {
2092
2219
  const data = (event == null ? void 0 : event.data) || {};
2093
2220
  if (event.origin != origin || data.sender != origin) return;
2094
2221
  if (!data.response) return rej("Unknown response from payment page");
2095
- done = true;
2096
2222
  window.removeEventListener("message", listener);
2097
2223
  win.close();
2098
2224
  res(data.response);
2099
2225
  });
2100
- win = window.open(encodeURI(`${(_a = this.opts) == null ? void 0 : _a.paymentUrl}?token=${token}&host=${host}`), "_blank");
2226
+ win = window.open(encodeURI(`${(_a = this.opts) == null ? void 0 : _a.paymentUrl}?token=${id}&host=${host}`), "_blank");
2101
2227
  if (!win) {
2102
2228
  window.removeEventListener("message", listener);
2103
2229
  return rej("Unable to open payment page");
2104
2230
  }
2105
- win.addEventListener("close", () => {
2106
- if (!done) rej("Window closed before payment was complete");
2107
- });
2231
+ });
2232
+ }
2233
+ /**
2234
+ * Refund a transaction
2235
+ * @param {string} id Transaction number to refund
2236
+ * @return {PromiseProgress<any>}
2237
+ */
2238
+ refund(id) {
2239
+ return this.api.request({ url: `/api/payments/transactions/${id || ""}`, method: "DELETE" }).then((resp) => {
2240
+ this.emit(PES`products/${id ?? ""}:d`, resp);
2241
+ return resp;
2108
2242
  });
2109
2243
  }
2110
2244
  }
@@ -2115,17 +2249,14 @@ class Pdf extends PathEventEmitter {
2115
2249
  this.api = typeof api == "string" ? new Api(api) : api;
2116
2250
  }
2117
2251
  createPdf(body, options) {
2118
- return this.api.request({ url: `/api/` + PES`pdf`, body: { ...body, options }, decode: false }).then(async (resp) => {
2119
- const blob = await resp.blob();
2252
+ return this.api.request({ url: `/api/` + PES`pdf`, body: { ...body, options } }).then(async (resp) => {
2120
2253
  if (options == null ? void 0 : options.download) {
2121
2254
  let filename = (options == null ? void 0 : options.filename) || timestampFilename();
2122
2255
  if (!filename.endsWith(".pdf")) filename += ".pdf";
2123
- const url = URL.createObjectURL(blob);
2124
- downloadUrl(url, filename);
2125
- URL.revokeObjectURL(url);
2256
+ downloadFile(resp, filename);
2126
2257
  }
2127
- this.emit(PES`pdf:c`, blob);
2128
- return blob;
2258
+ this.emit(PES`pdf:c`, resp);
2259
+ return resp;
2129
2260
  });
2130
2261
  }
2131
2262
  fromHtml(html, options = {}) {
@@ -2476,6 +2607,7 @@ export {
2476
2607
  Auth,
2477
2608
  Client,
2478
2609
  Data,
2610
+ Discounts,
2479
2611
  Email,
2480
2612
  Forms,
2481
2613
  Groups,
@@ -1,72 +1,184 @@
1
1
  import { PathEventEmitter } from '@ztimson/utils';
2
2
  import { Api } from './api';
3
3
  import { Meta } from './core';
4
+ import { Discounts } from './discounts';
5
+ /** Credit-card information for payments */
4
6
  export type Card = {
7
+ /** Credit-card number */
5
8
  number: number | string;
9
+ /** Year card expires */
6
10
  expYear: number | string;
11
+ /** Month card expires */
7
12
  expMonth: number | string;
13
+ /** 3 digit security code */
8
14
  csv: number | string;
15
+ /** Additional details for anti-fraud */
9
16
  details?: {
17
+ /** Cardholder name */
10
18
  name?: string;
19
+ /** Billing address */
11
20
  address?: {
12
21
  postal_code?: string;
13
22
  };
14
23
  };
15
24
  };
16
- export type PaymentAccount = {
25
+ /** User financial status */
26
+ export type Finances = {
27
+ /** Username */
17
28
  _id?: string;
18
- username: string;
29
+ /** Account balance */
19
30
  balance: number;
31
+ /** Account subscriptions */
20
32
  subscriptions: {
33
+ /** Product ID */
21
34
  _id: string;
35
+ /** Date subscription started */
22
36
  created: Date;
37
+ /** Number of days the subscription lasts */
23
38
  interval: number;
39
+ /** Date of next renewal, null if cancelled */
40
+ renewal?: Date | null;
24
41
  }[];
25
42
  };
43
+ /** Payment API options */
26
44
  export type PaymentOptions = {
27
45
  /** Path to payment page */
28
46
  paymentUrl?: string;
29
47
  };
30
- export type PaymentTransaction = Meta & {
31
- /** Deliver to user/email */
32
- recipient: string;
48
+ /** Returned products */
49
+ export type Product<T = any> = T & {
50
+ _id: number;
51
+ name: string;
52
+ cost: number;
53
+ subscription?: number;
54
+ socked: boolean;
55
+ };
56
+ /** Purchase options */
57
+ export type Transaction = Meta & {
33
58
  /** Purchased items */
34
- receipt: {
35
- _id: number | string;
59
+ cart: {
60
+ /** Product ID number, 'balance' for credit or null if custom */
61
+ _id?: number | 'balance';
62
+ /** Product name or description */
36
63
  name: string;
64
+ /** Number of units to purchase */
37
65
  quantity: number;
38
- price: number;
66
+ /** Individual unit cost */
67
+ cost: number;
39
68
  }[];
69
+ /** How was the transaction completed */
70
+ complete?: string;
71
+ /** Apply credit (Infinity to use all credit) */
72
+ credit: number;
73
+ /** Apply discount */
74
+ discount?: {
75
+ code?: string;
76
+ type: 'fixed' | 'percent';
77
+ value: number;
78
+ };
79
+ /** Receipt/Invoice number */
80
+ invoiceNum?: string;
81
+ /** Transaction notes */
82
+ notes?: string | null;
83
+ /** Recipient username or information */
84
+ recipient?: {
85
+ /** Billing address */
86
+ address?: string;
87
+ /** Delivery email */
88
+ email?: string;
89
+ /** Receipt name */
90
+ name?: string;
91
+ /** Account name */
92
+ username?: string;
93
+ };
94
+ /** Whether the transaction/invoice has been refunded / canceled respectively */
95
+ refunded?: boolean;
96
+ /** Current status of transaction - null for self-checkout */
97
+ status?: 'Invoice' | 'Cancelled' | 'Receipt' | 'Refunded';
40
98
  /** Transaction total */
99
+ subtotal: number;
100
+ /** Tax percentage as float */
101
+ tax: number;
102
+ /** Transaction total (subtotal - discount - credit + tax) */
41
103
  total: number;
42
- /** Completion method (card, cash, etc) */
43
- method?: string;
44
104
  /** Stripe transaction */
45
105
  tx?: any;
46
106
  };
47
- export type Purchase = {
48
- target: 'balance' | string | number;
49
- amount?: number;
50
- };
51
107
  export declare class Payments extends PathEventEmitter {
52
108
  readonly opts: PaymentOptions;
53
109
  private readonly api;
54
- private loaded;
110
+ discounts: Discounts;
111
+ /** Stripe object */
55
112
  stripe?: any;
113
+ /** Public stripe token */
56
114
  token?: string;
57
115
  constructor(api: Api | string, opts?: PaymentOptions);
58
- private checkout;
116
+ /**
117
+ * Initialize stripe API
118
+ * @return {Promise<any>} Returns stripe API
119
+ * @private
120
+ */
59
121
  private init;
60
- history(username?: string): Promise<any[]>;
61
- products(id?: string | number): Promise<any[]>;
62
- payment(card: Card, token: string): Promise<any>;
63
- paymentForm(element: string, token: string): Promise<() => Promise<any>>;
122
+ /**
123
+ * Create a stripe client secret to complete transaction
124
+ * @param {string} id Transaction ID
125
+ * @return {Promise<string>} Client secret
126
+ * @private
127
+ */
128
+ private createSecret;
129
+ /**
130
+ * Create/Update a transaction
131
+ * @param {Optional<Transaction, "subtotal" | "total">} transaction Transaction information
132
+ * @return {Promise<string>} Completed translation information
133
+ */
134
+ checkout(transaction: Partial<Transaction> & {
135
+ recipient: string;
136
+ discount: string;
137
+ }): Promise<Transaction>;
138
+ /**
139
+ * Get translation history
140
+ * @param {string} username Limit history to user
141
+ * @return {Promise<Transaction[]>} List of translations
142
+ */
143
+ history(username?: string): Promise<Transaction[]>;
144
+ /**
145
+ * Send recipient transaction receipt or invoice
146
+ * @param {string} id Translation ID
147
+ * @return {Promise<void>} Returns once complete
148
+ */
149
+ notify(id: string): Promise<void>;
150
+ /**
151
+ * Retrieve a list of available products
152
+ * @param {string | number} id Limit to specific product
153
+ * @return {Promise<any>} List of products or single product if ID is used
154
+ */
155
+ products<T = any>(id?: string): Promise<T[]>;
156
+ /**
157
+ * Process payment programmatically
158
+ * @param {string} id Transaction ID
159
+ * @param {Card} card Credit card information
160
+ * @return {Promise<any>} Stripe confirmation
161
+ */
162
+ payment(id: string, card: Card): Promise<any>;
163
+ /**
164
+ * Process payment using Stripe form
165
+ * @param {string} id Transaction ID
166
+ * @param {string} element DOM element to inject form into
167
+ * @return {Promise<() => Promise<any>>} Callback to submit form
168
+ */
169
+ paymentForm(id: string, element: string): Promise<() => Promise<any>>;
64
170
  /**
65
171
  * Complete payment via Momentum's payment page
66
- * @param {string} token Stripe payment intent secret
172
+ * @param {string} id Transaction ID
67
173
  * @param {string} host Host origin attempting to login
68
- * @return {Promise<string>} Token on success
174
+ * @return {Promise<string>} Translation ID on success
175
+ */
176
+ paymentRedirect(id: string, host?: string): Promise<string>;
177
+ /**
178
+ * Refund a transaction
179
+ * @param {string} id Transaction number to refund
180
+ * @return {PromiseProgress<any>}
69
181
  */
70
- paymentRedirect(token: string, host?: string): Promise<string>;
182
+ refund(id: string): import('@ztimson/utils').PromiseProgress<any>;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MAAM,CAAC;QACb,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,MAAM,CAAC,EAAE,MAAM,CAAC;KAChB,CAAA;IACD,gCAAgC;IAChC,SAAS,CAAC,EAAE,QAAQ,GAAG,OAAO,CAAC;IAC/B,+BAA+B;IAC/B,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,mCAAmC;IACnC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,6DAA6D;IAC7D,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,kDAAkD;IAClD,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,oDAAoD;IACpD,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;CACrB,CAAA;AAED,qBAAa,GAAI,SAAQ,gBAAgB;IACxC,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAO;gBAEf,GAAG,EAAE,GAAG,GAAG,MAAM;IAK7B,OAAO,CAAC,SAAS;IAYjB,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,GAAE,UAAe;IAK/C,YAAY,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,GAAE,UAAe;IAKrE,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,GAAE,UAAe;CAI7C"}
package/dist/users.d.ts CHANGED
@@ -6,6 +6,7 @@ export type User = Meta & {
6
6
  name: string;
7
7
  email?: string;
8
8
  phone?: string;
9
+ address?: string;
9
10
  image: string;
10
11
  disabled?: boolean;
11
12
  groups: string[];
@@ -13,7 +14,9 @@ export type User = Meta & {
13
14
  permissions: string[];
14
15
  notes?: string;
15
16
  custom: any;
17
+ balance?: number;
16
18
  lastLogin?: number | null;
19
+ subscriptions?: any[];
17
20
  totp?: false | 'app' | 'email' | 'phone';
18
21
  };
19
22
  export declare class Users extends PathEventEmitter {