@dime-technology/dime-js-sdk 1.0.0 → 1.2.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.js CHANGED
@@ -1,6 +1,6 @@
1
1
  // src/config.ts
2
2
  var DEFAULT_BASE_URL = "https://app.dimepayments.com";
3
- var VERSION = "1.0.0";
3
+ var VERSION = "1.2.0";
4
4
  var Config = class {
5
5
  token;
6
6
  baseUrl;
@@ -169,25 +169,31 @@ var Transport = class {
169
169
  /**
170
170
  * Execute a request and return the decoded JSON body.
171
171
  *
172
- * The Dime API expects request parameters in the JSON body even for GET
173
- * requests; this transport always sends the payload as a JSON body regardless
174
- * of HTTP method, matching the server's expectation.
172
+ * The Dime API reads the same `{ data, filters }` envelope whether it arrives
173
+ * as a JSON body or as nested query parameters. The Fetch standard forbids a
174
+ * body on GET/HEAD (undici throws), so for those methods the envelope is
175
+ * serialised into the query string (`data[sid]=…&filters[status]=…`) and no
176
+ * body is sent; every other method sends the envelope as a JSON body.
175
177
  */
176
178
  async request(method, path, body = {}, query = {}) {
177
179
  let url = `${this.config.baseUri()}${path.replace(/^\//, "")}`;
178
- if (Object.keys(query).length > 0) {
179
- url += "?" + new URLSearchParams(query).toString();
180
+ const bodyless = method.toUpperCase() === "GET" || method.toUpperCase() === "HEAD";
181
+ const params = { ...query };
182
+ if (bodyless) Object.assign(params, flattenParams(body));
183
+ if (Object.keys(params).length > 0) {
184
+ url += "?" + new URLSearchParams(params).toString();
180
185
  }
181
- const hasBody = Object.keys(body).length > 0;
186
+ const sendBody = !bodyless && Object.keys(body).length > 0;
187
+ const headers = {
188
+ Authorization: `Bearer ${this.config.token}`,
189
+ Accept: "application/json",
190
+ "X-Dime-Sdk": `dime-js-sdk/${VERSION}`
191
+ };
192
+ if (sendBody) headers["Content-Type"] = "application/json";
182
193
  const init = {
183
194
  method,
184
- headers: {
185
- Authorization: `Bearer ${this.config.token}`,
186
- Accept: "application/json",
187
- "Content-Type": "application/json",
188
- "X-Dime-Sdk": `dime-js-sdk/${VERSION}`
189
- },
190
- ...hasBody ? { body: JSON.stringify(body) } : {}
195
+ headers,
196
+ ...sendBody ? { body: JSON.stringify(body) } : {}
191
197
  };
192
198
  return this.attempt(url, init, 0);
193
199
  }
@@ -227,6 +233,23 @@ var Transport = class {
227
233
  await this.sleepFn(ms);
228
234
  }
229
235
  };
236
+ function flattenParams(obj, prefix = "") {
237
+ const out = {};
238
+ for (const [key, value] of Object.entries(obj)) {
239
+ if (value === null || value === void 0) continue;
240
+ const name = prefix ? `${prefix}[${key}]` : key;
241
+ if (Array.isArray(value)) {
242
+ value.forEach((item, i) => {
243
+ Object.assign(out, flattenParams({ [i]: item }, name));
244
+ });
245
+ } else if (typeof value === "object") {
246
+ Object.assign(out, flattenParams(value, name));
247
+ } else {
248
+ out[name] = typeof value === "boolean" ? value ? "1" : "0" : String(value);
249
+ }
250
+ }
251
+ return out;
252
+ }
230
253
  function parseRetryAfter(response) {
231
254
  const header = response.headers.get("Retry-After");
232
255
  if (header !== null && /^\d+$/.test(header)) return parseInt(header, 10);
@@ -272,6 +295,11 @@ function arrObjectFrom(data, keys) {
272
295
  }
273
296
  return {};
274
297
  }
298
+ function arrArrayFrom(data, key) {
299
+ const value = data[key];
300
+ if (Array.isArray(value)) return value;
301
+ return [];
302
+ }
275
303
 
276
304
  // src/data-objects/address.ts
277
305
  var Address = class _Address {
@@ -401,9 +429,7 @@ function extractCursor(meta, key) {
401
429
  return typeof v === "string" && v !== "" ? v : void 0;
402
430
  }
403
431
  function pruneNulls(obj) {
404
- return Object.fromEntries(
405
- Object.entries(obj).filter(([, v]) => v !== null && v !== void 0)
406
- );
432
+ return Object.fromEntries(Object.entries(obj).filter(([, v]) => v !== null && v !== void 0));
407
433
  }
408
434
 
409
435
  // src/resources/addresses.ts
@@ -412,19 +438,35 @@ var Addresses = class extends AbstractResource {
412
438
  return this.paginate("GET", "address/list", this.envelope({ sid, uuid }), Address.fromRaw);
413
439
  }
414
440
  async show(sid, uuid, addressId) {
415
- const raw = await this.transport.request("GET", "address/show", this.envelope({ sid, uuid, address_id: addressId }));
441
+ const raw = await this.transport.request(
442
+ "GET",
443
+ "address/show",
444
+ this.envelope({ sid, uuid, address_id: addressId })
445
+ );
416
446
  return Address.fromRaw(raw["data"] ?? {});
417
447
  }
418
448
  async create(sid, uuid, attributes) {
419
- const raw = await this.transport.request("POST", "address/create", this.envelope({ sid, uuid, ...attributes }));
449
+ const raw = await this.transport.request(
450
+ "POST",
451
+ "address/create",
452
+ this.envelope({ sid, uuid, ...attributes })
453
+ );
420
454
  return Address.fromRaw(raw["data"] ?? {});
421
455
  }
422
456
  async update(sid, uuid, addressId, attributes) {
423
- const raw = await this.transport.request("PATCH", "address/update", this.envelope({ sid, uuid, address_id: addressId, ...attributes }));
457
+ const raw = await this.transport.request(
458
+ "PATCH",
459
+ "address/update",
460
+ this.envelope({ sid, uuid, address_id: addressId, ...attributes })
461
+ );
424
462
  return Address.fromRaw(raw["data"] ?? {});
425
463
  }
426
464
  async delete(sid, uuid, addressId) {
427
- const raw = await this.transport.request("POST", "address/delete", this.envelope({ sid, uuid, address_id: addressId }));
465
+ const raw = await this.transport.request(
466
+ "POST",
467
+ "address/delete",
468
+ this.envelope({ sid, uuid, address_id: addressId })
469
+ );
428
470
  return MessageResult.fromRaw(raw["data"] ?? raw);
429
471
  }
430
472
  };
@@ -481,19 +523,35 @@ var Customers = class extends AbstractResource {
481
523
  return this.paginate("GET", "customer/list", this.envelope({ sid }, filters), Customer.fromRaw);
482
524
  }
483
525
  async show(sid, filters) {
484
- const raw = await this.transport.request("GET", "customer/show", this.envelope({ sid }, filters));
526
+ const raw = await this.transport.request(
527
+ "GET",
528
+ "customer/show",
529
+ this.envelope({ sid }, filters)
530
+ );
485
531
  return Customer.fromRaw(raw["data"] ?? {});
486
532
  }
487
533
  async create(sid, attributes) {
488
- const raw = await this.transport.request("POST", "customer/create", this.envelope({ sid, ...attributes }));
534
+ const raw = await this.transport.request(
535
+ "POST",
536
+ "customer/create",
537
+ this.envelope({ sid, ...attributes })
538
+ );
489
539
  return Customer.fromRaw(raw["data"] ?? {});
490
540
  }
491
541
  async update(sid, filters, attributes) {
492
- const raw = await this.transport.request("PATCH", "customer/update", this.envelope({ sid, ...attributes }, filters));
542
+ const raw = await this.transport.request(
543
+ "PATCH",
544
+ "customer/update",
545
+ this.envelope({ sid, ...attributes }, filters)
546
+ );
493
547
  return Customer.fromRaw(raw["data"] ?? {});
494
548
  }
495
549
  async delete(sid, filters) {
496
- const raw = await this.transport.request("POST", "customer/delete", this.envelope({ sid }, filters));
550
+ const raw = await this.transport.request(
551
+ "POST",
552
+ "customer/delete",
553
+ this.envelope({ sid }, filters)
554
+ );
497
555
  return MessageResult.fromRaw(raw["data"] ?? raw);
498
556
  }
499
557
  };
@@ -702,15 +760,414 @@ var Deposits = class extends AbstractResource {
702
760
  return this.paginate("GET", "deposit/list", this.envelope({ sid }, filters), Deposit.fromRaw);
703
761
  }
704
762
  async listWithTransactions(sid, filters) {
705
- const raw = await this.transport.request("GET", "deposit/list-with-trans", this.envelope({ sid }, filters));
763
+ const raw = await this.transport.request(
764
+ "GET",
765
+ "deposit/list-with-trans",
766
+ this.envelope({ sid }, filters)
767
+ );
706
768
  return DepositGroup.fromRaw(raw["data"] ?? {});
707
769
  }
708
770
  async show(sid, identifier) {
709
- const raw = await this.transport.request("GET", "deposit/show", this.envelope({ sid, ...identifier }));
771
+ const raw = await this.transport.request(
772
+ "GET",
773
+ "deposit/show",
774
+ this.envelope({ sid, ...identifier })
775
+ );
710
776
  return DepositWithTransactions.fromRaw(raw["data"] ?? {});
711
777
  }
712
778
  };
713
779
 
780
+ // src/data-objects/invoice-customer.ts
781
+ var InvoiceCustomer = class _InvoiceCustomer {
782
+ constructor(id, name, email) {
783
+ this.id = id;
784
+ this.name = name;
785
+ this.email = email;
786
+ }
787
+ id;
788
+ name;
789
+ email;
790
+ static fromRaw(data) {
791
+ return new _InvoiceCustomer(
792
+ arrInt(data, "id"),
793
+ arrString(data, "name"),
794
+ arrString(data, "email")
795
+ );
796
+ }
797
+ };
798
+
799
+ // src/data-objects/invoice-event.ts
800
+ var InvoiceEvent = class _InvoiceEvent {
801
+ constructor(type, label, description, createdAt) {
802
+ this.type = type;
803
+ this.label = label;
804
+ this.description = description;
805
+ this.createdAt = createdAt;
806
+ }
807
+ type;
808
+ label;
809
+ description;
810
+ createdAt;
811
+ static fromRaw(data) {
812
+ return new _InvoiceEvent(
813
+ arrString(data, "type"),
814
+ arrString(data, "label"),
815
+ arrString(data, "description"),
816
+ arrString(data, "created_at")
817
+ );
818
+ }
819
+ };
820
+
821
+ // src/data-objects/invoice-line-item.ts
822
+ var InvoiceLineItem = class _InvoiceLineItem {
823
+ constructor(id, itemId, name, description, quantity, unitPrice, amount) {
824
+ this.id = id;
825
+ this.itemId = itemId;
826
+ this.name = name;
827
+ this.description = description;
828
+ this.quantity = quantity;
829
+ this.unitPrice = unitPrice;
830
+ this.amount = amount;
831
+ }
832
+ id;
833
+ itemId;
834
+ name;
835
+ description;
836
+ quantity;
837
+ unitPrice;
838
+ amount;
839
+ static fromRaw(data) {
840
+ return new _InvoiceLineItem(
841
+ arrInt(data, "id"),
842
+ arrInt(data, "item_id"),
843
+ arrString(data, "name"),
844
+ arrString(data, "description"),
845
+ arrString(data, "quantity"),
846
+ arrString(data, "unit_price"),
847
+ arrString(data, "amount")
848
+ );
849
+ }
850
+ };
851
+
852
+ // src/data-objects/invoice-payment.ts
853
+ var InvoicePayment = class _InvoicePayment {
854
+ constructor(amount, paidAt, method, transactionId) {
855
+ this.amount = amount;
856
+ this.paidAt = paidAt;
857
+ this.method = method;
858
+ this.transactionId = transactionId;
859
+ }
860
+ amount;
861
+ paidAt;
862
+ method;
863
+ transactionId;
864
+ static fromRaw(data) {
865
+ return new _InvoicePayment(
866
+ arrString(data, "amount"),
867
+ arrString(data, "paid_at"),
868
+ arrString(data, "method"),
869
+ arrString(data, "transaction_id")
870
+ );
871
+ }
872
+ };
873
+
874
+ // src/data-objects/invoice.ts
875
+ var Invoice = class _Invoice {
876
+ constructor(id, invoiceNumber, status, token, paymentTerms, issueDate, dueDate, isOverdue = false, subtotal, total, amountPaid, balance, allowPartialPayment = false, thankYouNote, customerName, customerEmail, publicUrl, customer = new InvoiceCustomer(), items = [], payments = [], events = []) {
877
+ this.id = id;
878
+ this.invoiceNumber = invoiceNumber;
879
+ this.status = status;
880
+ this.token = token;
881
+ this.paymentTerms = paymentTerms;
882
+ this.issueDate = issueDate;
883
+ this.dueDate = dueDate;
884
+ this.isOverdue = isOverdue;
885
+ this.subtotal = subtotal;
886
+ this.total = total;
887
+ this.amountPaid = amountPaid;
888
+ this.balance = balance;
889
+ this.allowPartialPayment = allowPartialPayment;
890
+ this.thankYouNote = thankYouNote;
891
+ this.customerName = customerName;
892
+ this.customerEmail = customerEmail;
893
+ this.publicUrl = publicUrl;
894
+ this.customer = customer;
895
+ this.items = items;
896
+ this.payments = payments;
897
+ this.events = events;
898
+ }
899
+ id;
900
+ invoiceNumber;
901
+ status;
902
+ token;
903
+ paymentTerms;
904
+ issueDate;
905
+ dueDate;
906
+ isOverdue;
907
+ subtotal;
908
+ total;
909
+ amountPaid;
910
+ balance;
911
+ allowPartialPayment;
912
+ thankYouNote;
913
+ customerName;
914
+ customerEmail;
915
+ publicUrl;
916
+ customer;
917
+ items;
918
+ payments;
919
+ events;
920
+ static fromRaw(data) {
921
+ return new _Invoice(
922
+ arrInt(data, "id"),
923
+ arrString(data, "invoice_number"),
924
+ arrString(data, "status"),
925
+ arrString(data, "token"),
926
+ arrString(data, "payment_terms"),
927
+ arrString(data, "issue_date"),
928
+ arrString(data, "due_date"),
929
+ arrBool(data, "is_overdue"),
930
+ arrString(data, "subtotal"),
931
+ arrString(data, "total"),
932
+ arrString(data, "amount_paid"),
933
+ arrString(data, "balance"),
934
+ arrBool(data, "allow_partial_payment"),
935
+ arrString(data, "thank_you_note"),
936
+ arrString(data, "customer_name"),
937
+ arrString(data, "customer_email"),
938
+ arrString(data, "public_url"),
939
+ InvoiceCustomer.fromRaw(arrObjectFrom(data, ["customer"])),
940
+ arrArrayFrom(data, "items").map(InvoiceLineItem.fromRaw),
941
+ arrArrayFrom(data, "payments").map(InvoicePayment.fromRaw),
942
+ arrArrayFrom(data, "events").map(InvoiceEvent.fromRaw)
943
+ );
944
+ }
945
+ };
946
+
947
+ // src/data-objects/invoice-item.ts
948
+ var InvoiceItem = class _InvoiceItem {
949
+ constructor(id, name, description, price, taxDeductible = false) {
950
+ this.id = id;
951
+ this.name = name;
952
+ this.description = description;
953
+ this.price = price;
954
+ this.taxDeductible = taxDeductible;
955
+ }
956
+ id;
957
+ name;
958
+ description;
959
+ price;
960
+ taxDeductible;
961
+ static fromRaw(data) {
962
+ return new _InvoiceItem(
963
+ arrInt(data, "id"),
964
+ arrString(data, "name"),
965
+ arrString(data, "description"),
966
+ arrString(data, "price"),
967
+ arrBool(data, "tax_deductible")
968
+ );
969
+ }
970
+ };
971
+
972
+ // src/data-objects/invoice-link.ts
973
+ var InvoiceLink = class _InvoiceLink {
974
+ constructor(publicUrl, token) {
975
+ this.publicUrl = publicUrl;
976
+ this.token = token;
977
+ }
978
+ publicUrl;
979
+ token;
980
+ static fromRaw(data) {
981
+ return new _InvoiceLink(arrString(data, "public_url"), arrString(data, "token"));
982
+ }
983
+ };
984
+
985
+ // src/resources/invoices.ts
986
+ var Invoices = class extends AbstractResource {
987
+ /**
988
+ * List invoices for a merchant.
989
+ *
990
+ * @param filters `status` — draft | sent | paid | partial | void | overdue
991
+ */
992
+ async list(sid, filters = {}) {
993
+ return this.paginate("GET", "invoices", this.envelope({ sid }, filters), Invoice.fromRaw);
994
+ }
995
+ async show(sid, invoiceId) {
996
+ const raw = await this.transport.request(
997
+ "GET",
998
+ "invoice",
999
+ this.envelope({ sid, invoice_id: invoiceId })
1000
+ );
1001
+ return Invoice.fromRaw(raw["data"] ?? {});
1002
+ }
1003
+ /**
1004
+ * Create a draft invoice with its line items. Every line must reference a
1005
+ * Merchant `item_id`; the line name and unit price are snapshotted.
1006
+ *
1007
+ * @param attributes
1008
+ * `customer_uuid` (or `customer_id`), `customer_name`, `customer_email`,
1009
+ * `payment_terms` (`due_on_receipt` | `net_15` | `net_30` | `net_60`) and
1010
+ * `lines` are required. `lines[]` takes `item_id`, `name`, `quantity`,
1011
+ * `unit_price` and optional `description`. Optional: `invoice_number`,
1012
+ * `issue_date` (Y-m-d, defaults to today — `due_date` is derived from
1013
+ * `payment_terms`), `thank_you_note`, `allow_partial_payment`,
1014
+ * `reminder_settings`.
1015
+ */
1016
+ async create(sid, attributes) {
1017
+ const raw = await this.transport.request(
1018
+ "POST",
1019
+ "invoice/create",
1020
+ this.envelope({ sid, ...attributes })
1021
+ );
1022
+ return Invoice.fromRaw(raw["data"] ?? {});
1023
+ }
1024
+ /**
1025
+ * Update a draft invoice. Only drafts can be edited, and passing `lines`
1026
+ * replaces the existing line items.
1027
+ *
1028
+ * @param attributes same shape as {@link Invoices.create}
1029
+ */
1030
+ async update(sid, invoiceId, attributes) {
1031
+ const raw = await this.transport.request(
1032
+ "PATCH",
1033
+ "invoice/update",
1034
+ this.envelope({ sid, invoice_id: invoiceId, ...attributes })
1035
+ );
1036
+ return Invoice.fromRaw(raw["data"] ?? {});
1037
+ }
1038
+ async delete(sid, invoiceId) {
1039
+ const raw = await this.transport.request(
1040
+ "POST",
1041
+ "invoice/delete",
1042
+ this.envelope({ sid, invoice_id: invoiceId })
1043
+ );
1044
+ return MessageResult.fromRaw(raw["data"] ?? raw);
1045
+ }
1046
+ /** Email the invoice to the customer and advance it to Sent. */
1047
+ async send(sid, invoiceId) {
1048
+ const raw = await this.transport.request(
1049
+ "POST",
1050
+ "invoice/send",
1051
+ this.envelope({ sid, invoice_id: invoiceId })
1052
+ );
1053
+ return Invoice.fromRaw(raw["data"] ?? {});
1054
+ }
1055
+ /** Activate a draft invoice for payment without emailing it. */
1056
+ async markSent(sid, invoiceId) {
1057
+ const raw = await this.transport.request(
1058
+ "POST",
1059
+ "invoice/mark-sent",
1060
+ this.envelope({ sid, invoice_id: invoiceId })
1061
+ );
1062
+ return Invoice.fromRaw(raw["data"] ?? {});
1063
+ }
1064
+ async void(sid, invoiceId) {
1065
+ const raw = await this.transport.request(
1066
+ "PATCH",
1067
+ "invoice/void",
1068
+ this.envelope({ sid, invoice_id: invoiceId })
1069
+ );
1070
+ return Invoice.fromRaw(raw["data"] ?? {});
1071
+ }
1072
+ /** Clone any invoice into a new draft with a freshly allocated number. */
1073
+ async duplicate(sid, invoiceId) {
1074
+ const raw = await this.transport.request(
1075
+ "POST",
1076
+ "invoice/duplicate",
1077
+ this.envelope({ sid, invoice_id: invoiceId })
1078
+ );
1079
+ return Invoice.fromRaw(raw["data"] ?? {});
1080
+ }
1081
+ /**
1082
+ * Record a merchant-initiated (MOTO) card or ACH payment against an open
1083
+ * invoice.
1084
+ *
1085
+ * @param attributes
1086
+ * `payment_type` is required and is `cc` or `ach`. For a card, pass a stored
1087
+ * `token` or raw `cardholder_name` / `card_number` / `expiration_date` (m/Y)
1088
+ * plus optional `cvv`; for ACH, pass `routing_number` / `account_number` /
1089
+ * `account_type` (Checking | Savings) / `account_name`. Omit `amount` to pay
1090
+ * the full balance — partial amounts require the invoice to allow them.
1091
+ * Optional: `memo`, `billing_address`.
1092
+ */
1093
+ async pay(sid, invoiceId, attributes) {
1094
+ const raw = await this.transport.request(
1095
+ "POST",
1096
+ "invoice/pay",
1097
+ this.envelope({ sid, invoice_id: invoiceId, ...attributes })
1098
+ );
1099
+ return Invoice.fromRaw(raw["data"] ?? {});
1100
+ }
1101
+ /** Get the public pay link (and token) for an invoice. */
1102
+ async getLink(sid, invoiceId) {
1103
+ const raw = await this.transport.request(
1104
+ "GET",
1105
+ "invoice/link",
1106
+ this.envelope({ sid, invoice_id: invoiceId })
1107
+ );
1108
+ return InvoiceLink.fromRaw(raw["data"] ?? {});
1109
+ }
1110
+ /**
1111
+ * Append a single line item to a draft invoice.
1112
+ *
1113
+ * @param attributes `item_id`, `name`, `quantity` and `unit_price` are
1114
+ * required; `description` is optional.
1115
+ */
1116
+ async addLineItem(sid, invoiceId, attributes) {
1117
+ const raw = await this.transport.request(
1118
+ "POST",
1119
+ "invoice/line-item/add",
1120
+ this.envelope({ sid, invoice_id: invoiceId, ...attributes })
1121
+ );
1122
+ return Invoice.fromRaw(raw["data"] ?? {});
1123
+ }
1124
+ /**
1125
+ * Update a single line item on a draft invoice.
1126
+ *
1127
+ * @param attributes any of `item_id`, `name`, `description`, `quantity`,
1128
+ * `unit_price`
1129
+ */
1130
+ async updateLineItem(sid, invoiceId, lineItemId, attributes) {
1131
+ const raw = await this.transport.request(
1132
+ "PATCH",
1133
+ "invoice/line-item/update",
1134
+ this.envelope({ sid, invoice_id: invoiceId, line_item_id: lineItemId, ...attributes })
1135
+ );
1136
+ return Invoice.fromRaw(raw["data"] ?? {});
1137
+ }
1138
+ /** Remove a single line item from a draft invoice. */
1139
+ async deleteLineItem(sid, invoiceId, lineItemId) {
1140
+ const raw = await this.transport.request(
1141
+ "POST",
1142
+ "invoice/line-item/delete",
1143
+ this.envelope({ sid, invoice_id: invoiceId, line_item_id: lineItemId })
1144
+ );
1145
+ return Invoice.fromRaw(raw["data"] ?? {});
1146
+ }
1147
+ /** List the Merchant's items (funds/designations) available as invoice line items. */
1148
+ async listItems(sid) {
1149
+ const raw = await this.transport.request("GET", "invoice/items", this.envelope({ sid }));
1150
+ const items = Array.isArray(raw["data"]) ? raw["data"] : [];
1151
+ return items.map(InvoiceItem.fromRaw);
1152
+ }
1153
+ /**
1154
+ * Create an invoicing-only item (fund/designation) for the Merchant. The item
1155
+ * is hidden from public giving pages and can be referenced as a line's
1156
+ * `item_id`.
1157
+ *
1158
+ * @param attributes `name` is required; `description`, `price` and
1159
+ * `tax_deductible` are optional.
1160
+ */
1161
+ async createItem(sid, attributes) {
1162
+ const raw = await this.transport.request(
1163
+ "POST",
1164
+ "invoice/item/create",
1165
+ this.envelope({ sid, ...attributes })
1166
+ );
1167
+ return InvoiceItem.fromRaw(raw["data"] ?? {});
1168
+ }
1169
+ };
1170
+
714
1171
  // src/data-objects/form-link.ts
715
1172
  var FormLink = class _FormLink {
716
1173
  constructor(link) {
@@ -809,11 +1266,19 @@ var Merchants = class extends AbstractResource {
809
1266
  return Merchant.fromRaw(raw["data"] ?? {});
810
1267
  }
811
1268
  async update(sid, attributes) {
812
- const raw = await this.transport.request("PATCH", "merchant/update", this.envelope({ sid, ...attributes }));
1269
+ const raw = await this.transport.request(
1270
+ "PATCH",
1271
+ "merchant/update",
1272
+ this.envelope({ sid, ...attributes })
1273
+ );
813
1274
  return Merchant.fromRaw(raw["data"] ?? {});
814
1275
  }
815
1276
  async getFormLink(sid) {
816
- const raw = await this.transport.request("GET", "merchant/get-form-link", this.envelope({ sid }));
1277
+ const raw = await this.transport.request(
1278
+ "GET",
1279
+ "merchant/get-form-link",
1280
+ this.envelope({ sid })
1281
+ );
817
1282
  return FormLink.fromRaw(raw["data"] ?? {});
818
1283
  }
819
1284
  };
@@ -906,26 +1371,153 @@ var PaymentMethod = class _PaymentMethod {
906
1371
  // src/resources/payment-methods.ts
907
1372
  var PaymentMethods = class extends AbstractResource {
908
1373
  async list(sid, filters) {
909
- return this.paginate("GET", "payment-method/list", this.envelope({ sid }, filters), PaymentMethod.fromRaw);
1374
+ return this.paginate(
1375
+ "GET",
1376
+ "payment-method/list",
1377
+ this.envelope({ sid }, filters),
1378
+ PaymentMethod.fromRaw
1379
+ );
910
1380
  }
911
1381
  async show(sid, paymentMethodId, filters) {
912
- const raw = await this.transport.request("GET", "payment-method/show", this.envelope({ sid, payment_method_id: paymentMethodId }, filters));
1382
+ const raw = await this.transport.request(
1383
+ "GET",
1384
+ "payment-method/show",
1385
+ this.envelope({ sid, payment_method_id: paymentMethodId }, filters)
1386
+ );
913
1387
  return PaymentMethod.fromRaw(raw["data"] ?? {});
914
1388
  }
915
1389
  async create(sid, attributes) {
916
- const raw = await this.transport.request("POST", "payment-method/create", this.envelope({ sid, ...attributes }));
1390
+ const raw = await this.transport.request(
1391
+ "POST",
1392
+ "payment-method/create",
1393
+ this.envelope({ sid, ...attributes })
1394
+ );
917
1395
  return PaymentMethod.fromRaw(raw["data"] ?? {});
918
1396
  }
919
1397
  async update(sid, attributes) {
920
- const raw = await this.transport.request("PATCH", "payment-method/update", this.envelope({ sid, ...attributes }));
1398
+ const raw = await this.transport.request(
1399
+ "PATCH",
1400
+ "payment-method/update",
1401
+ this.envelope({ sid, ...attributes })
1402
+ );
921
1403
  return PaymentMethod.fromRaw(raw["data"] ?? {});
922
1404
  }
923
1405
  async delete(sid, paymentMethodId, uuid) {
924
- const raw = await this.transport.request("POST", "payment-method/delete", this.envelope({ sid, payment_method_id: paymentMethodId, uuid }));
1406
+ const raw = await this.transport.request(
1407
+ "POST",
1408
+ "payment-method/delete",
1409
+ this.envelope({ sid, payment_method_id: paymentMethodId, uuid })
1410
+ );
925
1411
  return MessageResult.fromRaw(raw["data"] ?? raw);
926
1412
  }
927
1413
  };
928
1414
 
1415
+ // src/data-objects/recurring-invoice.ts
1416
+ var RecurringInvoice = class _RecurringInvoice {
1417
+ constructor(id, status, recurrenceSchedule, paymentTerms, startDate, endDate, nextRunDate, lastRunDate, customerName, thankYouNote, customer = new InvoiceCustomer(), items = [], upcomingRunDates = [], invoices = []) {
1418
+ this.id = id;
1419
+ this.status = status;
1420
+ this.recurrenceSchedule = recurrenceSchedule;
1421
+ this.paymentTerms = paymentTerms;
1422
+ this.startDate = startDate;
1423
+ this.endDate = endDate;
1424
+ this.nextRunDate = nextRunDate;
1425
+ this.lastRunDate = lastRunDate;
1426
+ this.customerName = customerName;
1427
+ this.thankYouNote = thankYouNote;
1428
+ this.customer = customer;
1429
+ this.items = items;
1430
+ this.upcomingRunDates = upcomingRunDates;
1431
+ this.invoices = invoices;
1432
+ }
1433
+ id;
1434
+ status;
1435
+ recurrenceSchedule;
1436
+ paymentTerms;
1437
+ startDate;
1438
+ endDate;
1439
+ nextRunDate;
1440
+ lastRunDate;
1441
+ customerName;
1442
+ thankYouNote;
1443
+ customer;
1444
+ items;
1445
+ upcomingRunDates;
1446
+ invoices;
1447
+ static fromRaw(data) {
1448
+ const runDates = data["upcoming_run_dates"];
1449
+ return new _RecurringInvoice(
1450
+ arrInt(data, "id"),
1451
+ arrString(data, "status"),
1452
+ arrString(data, "recurrence_schedule"),
1453
+ arrString(data, "payment_terms"),
1454
+ arrString(data, "start_date"),
1455
+ arrString(data, "end_date"),
1456
+ arrString(data, "next_run_date"),
1457
+ arrString(data, "last_run_date"),
1458
+ arrString(data, "customer_name"),
1459
+ arrString(data, "thank_you_note"),
1460
+ InvoiceCustomer.fromRaw(arrObjectFrom(data, ["customer"])),
1461
+ arrArrayFrom(data, "items").map(InvoiceLineItem.fromRaw),
1462
+ Array.isArray(runDates) ? runDates.map((d) => String(d)) : [],
1463
+ arrArrayFrom(data, "invoices").map(Invoice.fromRaw)
1464
+ );
1465
+ }
1466
+ };
1467
+
1468
+ // src/resources/recurring-invoices.ts
1469
+ var RecurringInvoices = class extends AbstractResource {
1470
+ /**
1471
+ * List recurring-invoice templates.
1472
+ *
1473
+ * @param filters `status` — Active | Paused | Cancelled | Completed
1474
+ */
1475
+ async list(sid, filters = {}) {
1476
+ return this.paginate(
1477
+ "GET",
1478
+ "recurring-invoices",
1479
+ this.envelope({ sid }, filters),
1480
+ RecurringInvoice.fromRaw
1481
+ );
1482
+ }
1483
+ async show(sid, recurringInvoiceId) {
1484
+ const raw = await this.transport.request(
1485
+ "GET",
1486
+ "recurring-invoice",
1487
+ this.envelope({ sid, recurring_invoice_id: recurringInvoiceId })
1488
+ );
1489
+ return RecurringInvoice.fromRaw(raw["data"] ?? {});
1490
+ }
1491
+ /**
1492
+ * Create a recurring-invoice template. When `recurring_start_date` is today the
1493
+ * first invoice is generated and sent immediately.
1494
+ *
1495
+ * @param attributes
1496
+ * `customer_uuid` (or `customer_id`), `payment_terms` (`due_on_receipt` |
1497
+ * `net_15` | `net_30` | `net_60`), `recurring_frequency` (`Weekly` |
1498
+ * `Biweekly` | `FirstFifteenth` | `Monthly` | `Yearly`),
1499
+ * `recurring_start_date` (Y-m-d) and `lines` are required. Optional:
1500
+ * `recurring_end_date` (Y-m-d, on or after the start date),
1501
+ * `thank_you_note`.
1502
+ */
1503
+ async create(sid, attributes) {
1504
+ const raw = await this.transport.request(
1505
+ "POST",
1506
+ "recurring-invoice/create",
1507
+ this.envelope({ sid, ...attributes })
1508
+ );
1509
+ return RecurringInvoice.fromRaw(raw["data"] ?? {});
1510
+ }
1511
+ async cancel(sid, recurringInvoiceId) {
1512
+ const raw = await this.transport.request(
1513
+ "POST",
1514
+ "recurring-invoice/cancel",
1515
+ this.envelope({ sid, recurring_invoice_id: recurringInvoiceId })
1516
+ );
1517
+ return RecurringInvoice.fromRaw(raw["data"] ?? {});
1518
+ }
1519
+ };
1520
+
929
1521
  // src/data-objects/recurring-payment-method.ts
930
1522
  var RecurringPaymentMethod = class _RecurringPaymentMethod {
931
1523
  constructor(id, type, lastFour, expiration, zip, nameOnCard, bankAccountName, routingNumber, accountNumber, ownershipType, accountType, bankName) {
@@ -1036,34 +1628,71 @@ var RecurringPayment = class _RecurringPayment {
1036
1628
  // src/resources/recurring-payments.ts
1037
1629
  var RecurringPayments = class extends AbstractResource {
1038
1630
  async list(sid, filters = {}) {
1039
- return this.paginate("GET", "recurring-payment/list", this.envelope({ sid }, filters), RecurringPayment.fromRaw);
1631
+ return this.paginate(
1632
+ "GET",
1633
+ "recurring-payment/list",
1634
+ this.envelope({ sid }, filters),
1635
+ RecurringPayment.fromRaw
1636
+ );
1040
1637
  }
1041
1638
  async show(sid, recurringPaymentId) {
1042
- const raw = await this.transport.request("GET", "recurring-payment/show", this.envelope({ sid, recurring_payment_id: recurringPaymentId }));
1639
+ const raw = await this.transport.request(
1640
+ "GET",
1641
+ "recurring-payment/show",
1642
+ this.envelope({ sid, recurring_payment_id: recurringPaymentId })
1643
+ );
1043
1644
  return RecurringPayment.fromRaw(raw["data"] ?? {});
1044
1645
  }
1045
1646
  async create(sid, attributes) {
1046
- const raw = await this.transport.request("POST", "recurring-payment/create", this.envelope({ sid, ...attributes }));
1647
+ const raw = await this.transport.request(
1648
+ "POST",
1649
+ "recurring-payment/create",
1650
+ this.envelope({ sid, ...attributes })
1651
+ );
1047
1652
  return RecurringPayment.fromRaw(raw["data"] ?? {});
1048
1653
  }
1049
1654
  async edit(sid, recurringPaymentId, attributes) {
1050
- const raw = await this.transport.request("PATCH", "recurring-payment/edit", this.envelope({ sid, recurring_payment_id: recurringPaymentId, ...attributes }));
1655
+ const raw = await this.transport.request(
1656
+ "PATCH",
1657
+ "recurring-payment/edit",
1658
+ this.envelope({ sid, recurring_payment_id: recurringPaymentId, ...attributes })
1659
+ );
1051
1660
  return RecurringPayment.fromRaw(raw["data"] ?? {});
1052
1661
  }
1053
1662
  async pause(sid, recurringPaymentId, pauseUntilDate) {
1054
- const raw = await this.transport.request("PATCH", "recurring-payment/pause", this.envelope({ sid, recurring_payment_id: recurringPaymentId, pause_until_date: pauseUntilDate }));
1663
+ const raw = await this.transport.request(
1664
+ "PATCH",
1665
+ "recurring-payment/pause",
1666
+ this.envelope({
1667
+ sid,
1668
+ recurring_payment_id: recurringPaymentId,
1669
+ pause_until_date: pauseUntilDate
1670
+ })
1671
+ );
1055
1672
  return RecurringPayment.fromRaw(raw["data"] ?? {});
1056
1673
  }
1057
1674
  async cancel(sid, recurringPaymentId) {
1058
- const raw = await this.transport.request("PATCH", "recurring-payment/cancel", this.envelope({ sid, recurring_payment_id: recurringPaymentId }));
1675
+ const raw = await this.transport.request(
1676
+ "PATCH",
1677
+ "recurring-payment/cancel",
1678
+ this.envelope({ sid, recurring_payment_id: recurringPaymentId })
1679
+ );
1059
1680
  return RecurringPayment.fromRaw(raw["data"] ?? {});
1060
1681
  }
1061
1682
  async activate(sid, recurringPaymentId) {
1062
- const raw = await this.transport.request("PATCH", "recurring-payment/activate", this.envelope({ sid, recurring_payment_id: recurringPaymentId }));
1683
+ const raw = await this.transport.request(
1684
+ "PATCH",
1685
+ "recurring-payment/activate",
1686
+ this.envelope({ sid, recurring_payment_id: recurringPaymentId })
1687
+ );
1063
1688
  return RecurringPayment.fromRaw(raw["data"] ?? {});
1064
1689
  }
1065
1690
  async delete(sid, recurringPaymentId) {
1066
- const raw = await this.transport.request("POST", "recurring-payment/delete", this.envelope({ sid, recurring_payment_id: recurringPaymentId }));
1691
+ const raw = await this.transport.request(
1692
+ "POST",
1693
+ "recurring-payment/delete",
1694
+ this.envelope({ sid, recurring_payment_id: recurringPaymentId })
1695
+ );
1067
1696
  return MessageResult.fromRaw(raw["data"] ?? raw);
1068
1697
  }
1069
1698
  };
@@ -1082,35 +1711,68 @@ var TokenizeResult = class _TokenizeResult {
1082
1711
  // src/resources/transactions.ts
1083
1712
  var Transactions = class extends AbstractResource {
1084
1713
  async list(sid, filters = {}) {
1085
- return this.paginate("GET", "transactions", this.envelope({ sid }, filters), Transaction.fromRaw);
1714
+ return this.paginate(
1715
+ "GET",
1716
+ "transactions",
1717
+ this.envelope({ sid }, filters),
1718
+ Transaction.fromRaw
1719
+ );
1086
1720
  }
1087
1721
  async show(sid, identifier) {
1088
- const raw = await this.transport.request("GET", "transaction", this.envelope({ sid, ...identifier }));
1722
+ const raw = await this.transport.request(
1723
+ "GET",
1724
+ "transaction",
1725
+ this.envelope({ sid, ...identifier })
1726
+ );
1089
1727
  return Transaction.fromRaw(raw["data"] ?? {});
1090
1728
  }
1091
1729
  async chargeCard(sid, attributes) {
1092
- const raw = await this.transport.request("POST", "transaction/charge-card", this.envelope({ sid, ...attributes }));
1730
+ const raw = await this.transport.request(
1731
+ "POST",
1732
+ "transaction/charge-card",
1733
+ this.envelope({ sid, ...attributes })
1734
+ );
1093
1735
  return Transaction.fromRaw(raw["data"] ?? {});
1094
1736
  }
1095
1737
  /** @deprecated The API marks this deprecated; prefer chargeCard() with a token. */
1096
1738
  async chargeCardToken(sid, attributes) {
1097
- const raw = await this.transport.request("POST", "transaction/charge-card-token", this.envelope({ sid, ...attributes }));
1739
+ const raw = await this.transport.request(
1740
+ "POST",
1741
+ "transaction/charge-card-token",
1742
+ this.envelope({ sid, ...attributes })
1743
+ );
1098
1744
  return Transaction.fromRaw(raw["data"] ?? {});
1099
1745
  }
1100
1746
  async chargeAch(sid, attributes) {
1101
- const raw = await this.transport.request("POST", "transaction/charge-ach", this.envelope({ sid, ...attributes }));
1747
+ const raw = await this.transport.request(
1748
+ "POST",
1749
+ "transaction/charge-ach",
1750
+ this.envelope({ sid, ...attributes })
1751
+ );
1102
1752
  return Transaction.fromRaw(raw["data"] ?? {});
1103
1753
  }
1104
1754
  async tokenizeCard(sid, attributes) {
1105
- const raw = await this.transport.request("POST", "transaction/tokenize-card", this.envelope({ sid, ...attributes }));
1755
+ const raw = await this.transport.request(
1756
+ "POST",
1757
+ "transaction/tokenize-card",
1758
+ this.envelope({ sid, ...attributes })
1759
+ );
1106
1760
  return TokenizeResult.fromRaw(raw["data"] ?? {});
1107
1761
  }
1108
1762
  async refund(sid, attributes) {
1109
- const raw = await this.transport.request("POST", "transaction/refund", this.envelope({ sid, ...attributes }));
1763
+ const raw = await this.transport.request(
1764
+ "POST",
1765
+ "transaction/refund",
1766
+ this.envelope({ sid, ...attributes })
1767
+ );
1110
1768
  return MessageResult.fromRaw(raw["data"] ?? raw);
1111
1769
  }
1112
1770
  async void(sid, transactionType, transactionId) {
1113
- const raw = await this.transport.request("PATCH", "transaction/void", this.envelope({ sid, transaction_type: transactionType, transaction_id: transactionId }));
1771
+ const raw = await this.transport.request(
1772
+ "PATCH",
1773
+ "transaction/void",
1774
+ this.envelope({ sid, transaction_type: transactionType, transaction_id: transactionId })
1775
+ );
1114
1776
  return MessageResult.fromRaw(raw["data"] ?? raw);
1115
1777
  }
1116
1778
  };
@@ -1124,6 +1786,8 @@ var Client = class {
1124
1786
  addresses;
1125
1787
  deposits;
1126
1788
  recurringPayments;
1789
+ invoices;
1790
+ recurringInvoices;
1127
1791
  _config;
1128
1792
  constructor(token, baseUrl = DEFAULT_BASE_URL) {
1129
1793
  this._config = token instanceof Config ? token : new Config(token, baseUrl);
@@ -1135,6 +1799,8 @@ var Client = class {
1135
1799
  this.addresses = new Addresses(transport);
1136
1800
  this.deposits = new Deposits(transport);
1137
1801
  this.recurringPayments = new RecurringPayments(transport);
1802
+ this.invoices = new Invoices(transport);
1803
+ this.recurringInvoices = new RecurringInvoices(transport);
1138
1804
  }
1139
1805
  config() {
1140
1806
  return this._config;
@@ -1155,12 +1821,20 @@ export {
1155
1821
  DepositWithTransactions,
1156
1822
  DimeException,
1157
1823
  FormLink,
1824
+ Invoice,
1825
+ InvoiceCustomer,
1826
+ InvoiceEvent,
1827
+ InvoiceItem,
1828
+ InvoiceLineItem,
1829
+ InvoiceLink,
1830
+ InvoicePayment,
1158
1831
  Merchant,
1159
1832
  MessageResult,
1160
1833
  NotFoundException,
1161
1834
  PaymentMethod,
1162
1835
  PermissionDeniedException,
1163
1836
  RateLimitException,
1837
+ RecurringInvoice,
1164
1838
  RecurringPayment,
1165
1839
  RecurringPaymentMethod,
1166
1840
  ServerException,