@dime-technology/dime-js-sdk 1.0.0 → 1.3.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.3.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,465 @@ 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/cover-fee-quote.ts
781
+ var CoverFeeQuote = class _CoverFeeQuote {
782
+ constructor(basis, base, ccFee, ccTotal, achFee, achTotal) {
783
+ this.basis = basis;
784
+ this.base = base;
785
+ this.ccFee = ccFee;
786
+ this.ccTotal = ccTotal;
787
+ this.achFee = achFee;
788
+ this.achTotal = achTotal;
789
+ }
790
+ basis;
791
+ base;
792
+ ccFee;
793
+ ccTotal;
794
+ achFee;
795
+ achTotal;
796
+ static fromRaw(data) {
797
+ const cc = arrObjectFrom(data, ["cc"]);
798
+ const ach = arrObjectFrom(data, ["ach"]);
799
+ return new _CoverFeeQuote(
800
+ arrString(data, "basis"),
801
+ arrString(data, "base"),
802
+ arrString(cc, "fee"),
803
+ arrString(cc, "total"),
804
+ arrString(ach, "fee"),
805
+ arrString(ach, "total")
806
+ );
807
+ }
808
+ };
809
+
810
+ // src/data-objects/invoice-customer.ts
811
+ var InvoiceCustomer = class _InvoiceCustomer {
812
+ constructor(id, name, email) {
813
+ this.id = id;
814
+ this.name = name;
815
+ this.email = email;
816
+ }
817
+ id;
818
+ name;
819
+ email;
820
+ static fromRaw(data) {
821
+ return new _InvoiceCustomer(
822
+ arrInt(data, "id"),
823
+ arrString(data, "name"),
824
+ arrString(data, "email")
825
+ );
826
+ }
827
+ };
828
+
829
+ // src/data-objects/invoice-event.ts
830
+ var InvoiceEvent = class _InvoiceEvent {
831
+ constructor(type, label, description, createdAt) {
832
+ this.type = type;
833
+ this.label = label;
834
+ this.description = description;
835
+ this.createdAt = createdAt;
836
+ }
837
+ type;
838
+ label;
839
+ description;
840
+ createdAt;
841
+ static fromRaw(data) {
842
+ return new _InvoiceEvent(
843
+ arrString(data, "type"),
844
+ arrString(data, "label"),
845
+ arrString(data, "description"),
846
+ arrString(data, "created_at")
847
+ );
848
+ }
849
+ };
850
+
851
+ // src/data-objects/invoice-line-item.ts
852
+ var InvoiceLineItem = class _InvoiceLineItem {
853
+ constructor(id, itemId, name, description, quantity, unitPrice, amount) {
854
+ this.id = id;
855
+ this.itemId = itemId;
856
+ this.name = name;
857
+ this.description = description;
858
+ this.quantity = quantity;
859
+ this.unitPrice = unitPrice;
860
+ this.amount = amount;
861
+ }
862
+ id;
863
+ itemId;
864
+ name;
865
+ description;
866
+ quantity;
867
+ unitPrice;
868
+ amount;
869
+ static fromRaw(data) {
870
+ return new _InvoiceLineItem(
871
+ arrInt(data, "id"),
872
+ arrInt(data, "item_id"),
873
+ arrString(data, "name"),
874
+ arrString(data, "description"),
875
+ arrString(data, "quantity"),
876
+ arrString(data, "unit_price"),
877
+ arrString(data, "amount")
878
+ );
879
+ }
880
+ };
881
+
882
+ // src/data-objects/invoice-payment.ts
883
+ var InvoicePayment = class _InvoicePayment {
884
+ constructor(amount, paidAt, method, transactionId, coverFee) {
885
+ this.amount = amount;
886
+ this.paidAt = paidAt;
887
+ this.method = method;
888
+ this.transactionId = transactionId;
889
+ this.coverFee = coverFee;
890
+ }
891
+ amount;
892
+ paidAt;
893
+ method;
894
+ transactionId;
895
+ coverFee;
896
+ static fromRaw(data) {
897
+ return new _InvoicePayment(
898
+ arrString(data, "amount"),
899
+ arrString(data, "paid_at"),
900
+ arrString(data, "method"),
901
+ arrString(data, "transaction_id"),
902
+ arrString(data, "cover_fee")
903
+ );
904
+ }
905
+ };
906
+
907
+ // src/data-objects/invoice.ts
908
+ var Invoice = class _Invoice {
909
+ 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 = [], coverFeeRequired = false, coverFeeQuote) {
910
+ this.id = id;
911
+ this.invoiceNumber = invoiceNumber;
912
+ this.status = status;
913
+ this.token = token;
914
+ this.paymentTerms = paymentTerms;
915
+ this.issueDate = issueDate;
916
+ this.dueDate = dueDate;
917
+ this.isOverdue = isOverdue;
918
+ this.subtotal = subtotal;
919
+ this.total = total;
920
+ this.amountPaid = amountPaid;
921
+ this.balance = balance;
922
+ this.allowPartialPayment = allowPartialPayment;
923
+ this.thankYouNote = thankYouNote;
924
+ this.customerName = customerName;
925
+ this.customerEmail = customerEmail;
926
+ this.publicUrl = publicUrl;
927
+ this.customer = customer;
928
+ this.items = items;
929
+ this.payments = payments;
930
+ this.events = events;
931
+ this.coverFeeRequired = coverFeeRequired;
932
+ this.coverFeeQuote = coverFeeQuote;
933
+ }
934
+ id;
935
+ invoiceNumber;
936
+ status;
937
+ token;
938
+ paymentTerms;
939
+ issueDate;
940
+ dueDate;
941
+ isOverdue;
942
+ subtotal;
943
+ total;
944
+ amountPaid;
945
+ balance;
946
+ allowPartialPayment;
947
+ thankYouNote;
948
+ customerName;
949
+ customerEmail;
950
+ publicUrl;
951
+ customer;
952
+ items;
953
+ payments;
954
+ events;
955
+ coverFeeRequired;
956
+ coverFeeQuote;
957
+ static fromRaw(data) {
958
+ return new _Invoice(
959
+ arrInt(data, "id"),
960
+ arrString(data, "invoice_number"),
961
+ arrString(data, "status"),
962
+ arrString(data, "token"),
963
+ arrString(data, "payment_terms"),
964
+ arrString(data, "issue_date"),
965
+ arrString(data, "due_date"),
966
+ arrBool(data, "is_overdue"),
967
+ arrString(data, "subtotal"),
968
+ arrString(data, "total"),
969
+ arrString(data, "amount_paid"),
970
+ arrString(data, "balance"),
971
+ arrBool(data, "allow_partial_payment"),
972
+ arrString(data, "thank_you_note"),
973
+ arrString(data, "customer_name"),
974
+ arrString(data, "customer_email"),
975
+ arrString(data, "public_url"),
976
+ InvoiceCustomer.fromRaw(arrObjectFrom(data, ["customer"])),
977
+ arrArrayFrom(data, "items").map(InvoiceLineItem.fromRaw),
978
+ arrArrayFrom(data, "payments").map(InvoicePayment.fromRaw),
979
+ arrArrayFrom(data, "events").map(InvoiceEvent.fromRaw),
980
+ arrBool(data, "cover_fee_required"),
981
+ data["cover_fee_quote"] && typeof data["cover_fee_quote"] === "object" ? CoverFeeQuote.fromRaw(data["cover_fee_quote"]) : void 0
982
+ );
983
+ }
984
+ };
985
+
986
+ // src/data-objects/invoice-item.ts
987
+ var InvoiceItem = class _InvoiceItem {
988
+ constructor(id, name, description, price, taxDeductible = false) {
989
+ this.id = id;
990
+ this.name = name;
991
+ this.description = description;
992
+ this.price = price;
993
+ this.taxDeductible = taxDeductible;
994
+ }
995
+ id;
996
+ name;
997
+ description;
998
+ price;
999
+ taxDeductible;
1000
+ static fromRaw(data) {
1001
+ return new _InvoiceItem(
1002
+ arrInt(data, "id"),
1003
+ arrString(data, "name"),
1004
+ arrString(data, "description"),
1005
+ arrString(data, "price"),
1006
+ arrBool(data, "tax_deductible")
1007
+ );
1008
+ }
1009
+ };
1010
+
1011
+ // src/data-objects/invoice-link.ts
1012
+ var InvoiceLink = class _InvoiceLink {
1013
+ constructor(publicUrl, token) {
1014
+ this.publicUrl = publicUrl;
1015
+ this.token = token;
1016
+ }
1017
+ publicUrl;
1018
+ token;
1019
+ static fromRaw(data) {
1020
+ return new _InvoiceLink(arrString(data, "public_url"), arrString(data, "token"));
1021
+ }
1022
+ };
1023
+
1024
+ // src/resources/invoices.ts
1025
+ var Invoices = class extends AbstractResource {
1026
+ /**
1027
+ * List invoices for a merchant.
1028
+ *
1029
+ * @param filters `status` — draft | sent | paid | partial | void | overdue
1030
+ */
1031
+ async list(sid, filters = {}) {
1032
+ return this.paginate("GET", "invoices", this.envelope({ sid }, filters), Invoice.fromRaw);
1033
+ }
1034
+ async show(sid, invoiceId) {
1035
+ const raw = await this.transport.request(
1036
+ "GET",
1037
+ "invoice",
1038
+ this.envelope({ sid, invoice_id: invoiceId })
1039
+ );
1040
+ return Invoice.fromRaw(raw["data"] ?? {});
1041
+ }
1042
+ /**
1043
+ * Create a draft invoice with its line items. Every line must reference a
1044
+ * Merchant `item_id`; the line name and unit price are snapshotted.
1045
+ *
1046
+ * @param attributes
1047
+ * `customer_uuid` (or `customer_id`), `customer_name`, `customer_email`,
1048
+ * `payment_terms` (`due_on_receipt` | `net_15` | `net_30` | `net_60`) and
1049
+ * `lines` are required. `lines[]` takes `item_id`, `name`, `quantity`,
1050
+ * `unit_price` and optional `description`. Optional: `invoice_number`,
1051
+ * `issue_date` (Y-m-d, defaults to today — `due_date` is derived from
1052
+ * `payment_terms`), `thank_you_note`, `allow_partial_payment`,
1053
+ * `cover_fee_required`, `reminder_settings`.
1054
+ *
1055
+ * Set `cover_fee_required` to make the customer pay the processing fee. The
1056
+ * fee is added on top of the invoice at payment time rather than becoming a
1057
+ * line item, so `total` stays the amount owed to the merchant — read
1058
+ * `invoice.coverFeeQuote` for what the customer will actually be charged.
1059
+ * Omitting the field inherits the merchant's invoice setting.
1060
+ */
1061
+ async create(sid, attributes) {
1062
+ const raw = await this.transport.request(
1063
+ "POST",
1064
+ "invoice/create",
1065
+ this.envelope({ sid, ...attributes })
1066
+ );
1067
+ return Invoice.fromRaw(raw["data"] ?? {});
1068
+ }
1069
+ /**
1070
+ * Update a draft invoice. Only drafts can be edited, and passing `lines`
1071
+ * replaces the existing line items.
1072
+ *
1073
+ * @param attributes same shape as {@link Invoices.create}
1074
+ */
1075
+ async update(sid, invoiceId, attributes) {
1076
+ const raw = await this.transport.request(
1077
+ "PATCH",
1078
+ "invoice/update",
1079
+ this.envelope({ sid, invoice_id: invoiceId, ...attributes })
1080
+ );
1081
+ return Invoice.fromRaw(raw["data"] ?? {});
1082
+ }
1083
+ async delete(sid, invoiceId) {
1084
+ const raw = await this.transport.request(
1085
+ "POST",
1086
+ "invoice/delete",
1087
+ this.envelope({ sid, invoice_id: invoiceId })
1088
+ );
1089
+ return MessageResult.fromRaw(raw["data"] ?? raw);
1090
+ }
1091
+ /** Email the invoice to the customer and advance it to Sent. */
1092
+ async send(sid, invoiceId) {
1093
+ const raw = await this.transport.request(
1094
+ "POST",
1095
+ "invoice/send",
1096
+ this.envelope({ sid, invoice_id: invoiceId })
1097
+ );
1098
+ return Invoice.fromRaw(raw["data"] ?? {});
1099
+ }
1100
+ /** Activate a draft invoice for payment without emailing it. */
1101
+ async markSent(sid, invoiceId) {
1102
+ const raw = await this.transport.request(
1103
+ "POST",
1104
+ "invoice/mark-sent",
1105
+ this.envelope({ sid, invoice_id: invoiceId })
1106
+ );
1107
+ return Invoice.fromRaw(raw["data"] ?? {});
1108
+ }
1109
+ async void(sid, invoiceId) {
1110
+ const raw = await this.transport.request(
1111
+ "PATCH",
1112
+ "invoice/void",
1113
+ this.envelope({ sid, invoice_id: invoiceId })
1114
+ );
1115
+ return Invoice.fromRaw(raw["data"] ?? {});
1116
+ }
1117
+ /** Clone any invoice into a new draft with a freshly allocated number. */
1118
+ async duplicate(sid, invoiceId) {
1119
+ const raw = await this.transport.request(
1120
+ "POST",
1121
+ "invoice/duplicate",
1122
+ this.envelope({ sid, invoice_id: invoiceId })
1123
+ );
1124
+ return Invoice.fromRaw(raw["data"] ?? {});
1125
+ }
1126
+ /**
1127
+ * Record a merchant-initiated (MOTO) card or ACH payment against an open
1128
+ * invoice.
1129
+ *
1130
+ * @param attributes
1131
+ * `payment_type` is required and is `cc` or `ach`. For a card, pass a stored
1132
+ * `token` or raw `cardholder_name` / `card_number` / `expiration_date` (m/Y)
1133
+ * plus optional `cvv`; for ACH, pass `routing_number` / `account_number` /
1134
+ * `account_type` (Checking | Savings) / `account_name`. Omit `amount` to pay
1135
+ * the full balance — partial amounts require the invoice to allow them.
1136
+ * Optional: `memo`, `billing_address`.
1137
+ *
1138
+ * On a cover-fee invoice the processing fee for `payment_type` is charged on
1139
+ * top of `amount`, so the card or bank account is debited more than the
1140
+ * invoice is credited. The fee lands as `coverFee` on the matching entry in
1141
+ * `invoice.payments`. Card and ACH rates differ, so the same `amount` settles
1142
+ * differently per `payment_type`.
1143
+ */
1144
+ async pay(sid, invoiceId, attributes) {
1145
+ const raw = await this.transport.request(
1146
+ "POST",
1147
+ "invoice/pay",
1148
+ this.envelope({ sid, invoice_id: invoiceId, ...attributes })
1149
+ );
1150
+ return Invoice.fromRaw(raw["data"] ?? {});
1151
+ }
1152
+ /** Get the public pay link (and token) for an invoice. */
1153
+ async getLink(sid, invoiceId) {
1154
+ const raw = await this.transport.request(
1155
+ "GET",
1156
+ "invoice/link",
1157
+ this.envelope({ sid, invoice_id: invoiceId })
1158
+ );
1159
+ return InvoiceLink.fromRaw(raw["data"] ?? {});
1160
+ }
1161
+ /**
1162
+ * Append a single line item to a draft invoice.
1163
+ *
1164
+ * @param attributes `item_id`, `name`, `quantity` and `unit_price` are
1165
+ * required; `description` is optional.
1166
+ */
1167
+ async addLineItem(sid, invoiceId, attributes) {
1168
+ const raw = await this.transport.request(
1169
+ "POST",
1170
+ "invoice/line-item/add",
1171
+ this.envelope({ sid, invoice_id: invoiceId, ...attributes })
1172
+ );
1173
+ return Invoice.fromRaw(raw["data"] ?? {});
1174
+ }
1175
+ /**
1176
+ * Update a single line item on a draft invoice.
1177
+ *
1178
+ * @param attributes any of `item_id`, `name`, `description`, `quantity`,
1179
+ * `unit_price`
1180
+ */
1181
+ async updateLineItem(sid, invoiceId, lineItemId, attributes) {
1182
+ const raw = await this.transport.request(
1183
+ "PATCH",
1184
+ "invoice/line-item/update",
1185
+ this.envelope({ sid, invoice_id: invoiceId, line_item_id: lineItemId, ...attributes })
1186
+ );
1187
+ return Invoice.fromRaw(raw["data"] ?? {});
1188
+ }
1189
+ /** Remove a single line item from a draft invoice. */
1190
+ async deleteLineItem(sid, invoiceId, lineItemId) {
1191
+ const raw = await this.transport.request(
1192
+ "POST",
1193
+ "invoice/line-item/delete",
1194
+ this.envelope({ sid, invoice_id: invoiceId, line_item_id: lineItemId })
1195
+ );
1196
+ return Invoice.fromRaw(raw["data"] ?? {});
1197
+ }
1198
+ /** List the Merchant's items (funds/designations) available as invoice line items. */
1199
+ async listItems(sid) {
1200
+ const raw = await this.transport.request("GET", "invoice/items", this.envelope({ sid }));
1201
+ const items = Array.isArray(raw["data"]) ? raw["data"] : [];
1202
+ return items.map(InvoiceItem.fromRaw);
1203
+ }
1204
+ /**
1205
+ * Create an invoicing-only item (fund/designation) for the Merchant. The item
1206
+ * is hidden from public giving pages and can be referenced as a line's
1207
+ * `item_id`.
1208
+ *
1209
+ * @param attributes `name` is required; `description`, `price` and
1210
+ * `tax_deductible` are optional.
1211
+ */
1212
+ async createItem(sid, attributes) {
1213
+ const raw = await this.transport.request(
1214
+ "POST",
1215
+ "invoice/item/create",
1216
+ this.envelope({ sid, ...attributes })
1217
+ );
1218
+ return InvoiceItem.fromRaw(raw["data"] ?? {});
1219
+ }
1220
+ };
1221
+
714
1222
  // src/data-objects/form-link.ts
715
1223
  var FormLink = class _FormLink {
716
1224
  constructor(link) {
@@ -809,11 +1317,19 @@ var Merchants = class extends AbstractResource {
809
1317
  return Merchant.fromRaw(raw["data"] ?? {});
810
1318
  }
811
1319
  async update(sid, attributes) {
812
- const raw = await this.transport.request("PATCH", "merchant/update", this.envelope({ sid, ...attributes }));
1320
+ const raw = await this.transport.request(
1321
+ "PATCH",
1322
+ "merchant/update",
1323
+ this.envelope({ sid, ...attributes })
1324
+ );
813
1325
  return Merchant.fromRaw(raw["data"] ?? {});
814
1326
  }
815
1327
  async getFormLink(sid) {
816
- const raw = await this.transport.request("GET", "merchant/get-form-link", this.envelope({ sid }));
1328
+ const raw = await this.transport.request(
1329
+ "GET",
1330
+ "merchant/get-form-link",
1331
+ this.envelope({ sid })
1332
+ );
817
1333
  return FormLink.fromRaw(raw["data"] ?? {});
818
1334
  }
819
1335
  };
@@ -906,26 +1422,159 @@ var PaymentMethod = class _PaymentMethod {
906
1422
  // src/resources/payment-methods.ts
907
1423
  var PaymentMethods = class extends AbstractResource {
908
1424
  async list(sid, filters) {
909
- return this.paginate("GET", "payment-method/list", this.envelope({ sid }, filters), PaymentMethod.fromRaw);
1425
+ return this.paginate(
1426
+ "GET",
1427
+ "payment-method/list",
1428
+ this.envelope({ sid }, filters),
1429
+ PaymentMethod.fromRaw
1430
+ );
910
1431
  }
911
1432
  async show(sid, paymentMethodId, filters) {
912
- const raw = await this.transport.request("GET", "payment-method/show", this.envelope({ sid, payment_method_id: paymentMethodId }, filters));
1433
+ const raw = await this.transport.request(
1434
+ "GET",
1435
+ "payment-method/show",
1436
+ this.envelope({ sid, payment_method_id: paymentMethodId }, filters)
1437
+ );
913
1438
  return PaymentMethod.fromRaw(raw["data"] ?? {});
914
1439
  }
915
1440
  async create(sid, attributes) {
916
- const raw = await this.transport.request("POST", "payment-method/create", this.envelope({ sid, ...attributes }));
1441
+ const raw = await this.transport.request(
1442
+ "POST",
1443
+ "payment-method/create",
1444
+ this.envelope({ sid, ...attributes })
1445
+ );
917
1446
  return PaymentMethod.fromRaw(raw["data"] ?? {});
918
1447
  }
919
1448
  async update(sid, attributes) {
920
- const raw = await this.transport.request("PATCH", "payment-method/update", this.envelope({ sid, ...attributes }));
1449
+ const raw = await this.transport.request(
1450
+ "PATCH",
1451
+ "payment-method/update",
1452
+ this.envelope({ sid, ...attributes })
1453
+ );
921
1454
  return PaymentMethod.fromRaw(raw["data"] ?? {});
922
1455
  }
923
1456
  async delete(sid, paymentMethodId, uuid) {
924
- const raw = await this.transport.request("POST", "payment-method/delete", this.envelope({ sid, payment_method_id: paymentMethodId, uuid }));
1457
+ const raw = await this.transport.request(
1458
+ "POST",
1459
+ "payment-method/delete",
1460
+ this.envelope({ sid, payment_method_id: paymentMethodId, uuid })
1461
+ );
925
1462
  return MessageResult.fromRaw(raw["data"] ?? raw);
926
1463
  }
927
1464
  };
928
1465
 
1466
+ // src/data-objects/recurring-invoice.ts
1467
+ var RecurringInvoice = class _RecurringInvoice {
1468
+ constructor(id, status, recurrenceSchedule, paymentTerms, startDate, endDate, nextRunDate, lastRunDate, customerName, thankYouNote, customer = new InvoiceCustomer(), items = [], upcomingRunDates = [], invoices = [], coverFeeRequired = false) {
1469
+ this.id = id;
1470
+ this.status = status;
1471
+ this.recurrenceSchedule = recurrenceSchedule;
1472
+ this.paymentTerms = paymentTerms;
1473
+ this.startDate = startDate;
1474
+ this.endDate = endDate;
1475
+ this.nextRunDate = nextRunDate;
1476
+ this.lastRunDate = lastRunDate;
1477
+ this.customerName = customerName;
1478
+ this.thankYouNote = thankYouNote;
1479
+ this.customer = customer;
1480
+ this.items = items;
1481
+ this.upcomingRunDates = upcomingRunDates;
1482
+ this.invoices = invoices;
1483
+ this.coverFeeRequired = coverFeeRequired;
1484
+ }
1485
+ id;
1486
+ status;
1487
+ recurrenceSchedule;
1488
+ paymentTerms;
1489
+ startDate;
1490
+ endDate;
1491
+ nextRunDate;
1492
+ lastRunDate;
1493
+ customerName;
1494
+ thankYouNote;
1495
+ customer;
1496
+ items;
1497
+ upcomingRunDates;
1498
+ invoices;
1499
+ coverFeeRequired;
1500
+ static fromRaw(data) {
1501
+ const runDates = data["upcoming_run_dates"];
1502
+ return new _RecurringInvoice(
1503
+ arrInt(data, "id"),
1504
+ arrString(data, "status"),
1505
+ arrString(data, "recurrence_schedule"),
1506
+ arrString(data, "payment_terms"),
1507
+ arrString(data, "start_date"),
1508
+ arrString(data, "end_date"),
1509
+ arrString(data, "next_run_date"),
1510
+ arrString(data, "last_run_date"),
1511
+ arrString(data, "customer_name"),
1512
+ arrString(data, "thank_you_note"),
1513
+ InvoiceCustomer.fromRaw(arrObjectFrom(data, ["customer"])),
1514
+ arrArrayFrom(data, "items").map(InvoiceLineItem.fromRaw),
1515
+ Array.isArray(runDates) ? runDates.map((d) => String(d)) : [],
1516
+ arrArrayFrom(data, "invoices").map(Invoice.fromRaw),
1517
+ arrBool(data, "cover_fee_required")
1518
+ );
1519
+ }
1520
+ };
1521
+
1522
+ // src/resources/recurring-invoices.ts
1523
+ var RecurringInvoices = class extends AbstractResource {
1524
+ /**
1525
+ * List recurring-invoice templates.
1526
+ *
1527
+ * @param filters `status` — Active | Paused | Cancelled | Completed
1528
+ */
1529
+ async list(sid, filters = {}) {
1530
+ return this.paginate(
1531
+ "GET",
1532
+ "recurring-invoices",
1533
+ this.envelope({ sid }, filters),
1534
+ RecurringInvoice.fromRaw
1535
+ );
1536
+ }
1537
+ async show(sid, recurringInvoiceId) {
1538
+ const raw = await this.transport.request(
1539
+ "GET",
1540
+ "recurring-invoice",
1541
+ this.envelope({ sid, recurring_invoice_id: recurringInvoiceId })
1542
+ );
1543
+ return RecurringInvoice.fromRaw(raw["data"] ?? {});
1544
+ }
1545
+ /**
1546
+ * Create a recurring-invoice template. When `recurring_start_date` is today the
1547
+ * first invoice is generated and sent immediately.
1548
+ *
1549
+ * @param attributes
1550
+ * `customer_uuid` (or `customer_id`), `payment_terms` (`due_on_receipt` |
1551
+ * `net_15` | `net_30` | `net_60`), `recurring_frequency` (`Weekly` |
1552
+ * `Biweekly` | `FirstFifteenth` | `Monthly` | `Yearly`),
1553
+ * `recurring_start_date` (Y-m-d) and `lines` are required. Optional:
1554
+ * `recurring_end_date` (Y-m-d, on or after the start date),
1555
+ * `thank_you_note`.
1556
+ *
1557
+ * `cover_fee_required` makes the customer cover the processing fee on every
1558
+ * invoice this template generates.
1559
+ */
1560
+ async create(sid, attributes) {
1561
+ const raw = await this.transport.request(
1562
+ "POST",
1563
+ "recurring-invoice/create",
1564
+ this.envelope({ sid, ...attributes })
1565
+ );
1566
+ return RecurringInvoice.fromRaw(raw["data"] ?? {});
1567
+ }
1568
+ async cancel(sid, recurringInvoiceId) {
1569
+ const raw = await this.transport.request(
1570
+ "POST",
1571
+ "recurring-invoice/cancel",
1572
+ this.envelope({ sid, recurring_invoice_id: recurringInvoiceId })
1573
+ );
1574
+ return RecurringInvoice.fromRaw(raw["data"] ?? {});
1575
+ }
1576
+ };
1577
+
929
1578
  // src/data-objects/recurring-payment-method.ts
930
1579
  var RecurringPaymentMethod = class _RecurringPaymentMethod {
931
1580
  constructor(id, type, lastFour, expiration, zip, nameOnCard, bankAccountName, routingNumber, accountNumber, ownershipType, accountType, bankName) {
@@ -1036,34 +1685,71 @@ var RecurringPayment = class _RecurringPayment {
1036
1685
  // src/resources/recurring-payments.ts
1037
1686
  var RecurringPayments = class extends AbstractResource {
1038
1687
  async list(sid, filters = {}) {
1039
- return this.paginate("GET", "recurring-payment/list", this.envelope({ sid }, filters), RecurringPayment.fromRaw);
1688
+ return this.paginate(
1689
+ "GET",
1690
+ "recurring-payment/list",
1691
+ this.envelope({ sid }, filters),
1692
+ RecurringPayment.fromRaw
1693
+ );
1040
1694
  }
1041
1695
  async show(sid, recurringPaymentId) {
1042
- const raw = await this.transport.request("GET", "recurring-payment/show", this.envelope({ sid, recurring_payment_id: recurringPaymentId }));
1696
+ const raw = await this.transport.request(
1697
+ "GET",
1698
+ "recurring-payment/show",
1699
+ this.envelope({ sid, recurring_payment_id: recurringPaymentId })
1700
+ );
1043
1701
  return RecurringPayment.fromRaw(raw["data"] ?? {});
1044
1702
  }
1045
1703
  async create(sid, attributes) {
1046
- const raw = await this.transport.request("POST", "recurring-payment/create", this.envelope({ sid, ...attributes }));
1704
+ const raw = await this.transport.request(
1705
+ "POST",
1706
+ "recurring-payment/create",
1707
+ this.envelope({ sid, ...attributes })
1708
+ );
1047
1709
  return RecurringPayment.fromRaw(raw["data"] ?? {});
1048
1710
  }
1049
1711
  async edit(sid, recurringPaymentId, attributes) {
1050
- const raw = await this.transport.request("PATCH", "recurring-payment/edit", this.envelope({ sid, recurring_payment_id: recurringPaymentId, ...attributes }));
1712
+ const raw = await this.transport.request(
1713
+ "PATCH",
1714
+ "recurring-payment/edit",
1715
+ this.envelope({ sid, recurring_payment_id: recurringPaymentId, ...attributes })
1716
+ );
1051
1717
  return RecurringPayment.fromRaw(raw["data"] ?? {});
1052
1718
  }
1053
1719
  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 }));
1720
+ const raw = await this.transport.request(
1721
+ "PATCH",
1722
+ "recurring-payment/pause",
1723
+ this.envelope({
1724
+ sid,
1725
+ recurring_payment_id: recurringPaymentId,
1726
+ pause_until_date: pauseUntilDate
1727
+ })
1728
+ );
1055
1729
  return RecurringPayment.fromRaw(raw["data"] ?? {});
1056
1730
  }
1057
1731
  async cancel(sid, recurringPaymentId) {
1058
- const raw = await this.transport.request("PATCH", "recurring-payment/cancel", this.envelope({ sid, recurring_payment_id: recurringPaymentId }));
1732
+ const raw = await this.transport.request(
1733
+ "PATCH",
1734
+ "recurring-payment/cancel",
1735
+ this.envelope({ sid, recurring_payment_id: recurringPaymentId })
1736
+ );
1059
1737
  return RecurringPayment.fromRaw(raw["data"] ?? {});
1060
1738
  }
1061
1739
  async activate(sid, recurringPaymentId) {
1062
- const raw = await this.transport.request("PATCH", "recurring-payment/activate", this.envelope({ sid, recurring_payment_id: recurringPaymentId }));
1740
+ const raw = await this.transport.request(
1741
+ "PATCH",
1742
+ "recurring-payment/activate",
1743
+ this.envelope({ sid, recurring_payment_id: recurringPaymentId })
1744
+ );
1063
1745
  return RecurringPayment.fromRaw(raw["data"] ?? {});
1064
1746
  }
1065
1747
  async delete(sid, recurringPaymentId) {
1066
- const raw = await this.transport.request("POST", "recurring-payment/delete", this.envelope({ sid, recurring_payment_id: recurringPaymentId }));
1748
+ const raw = await this.transport.request(
1749
+ "POST",
1750
+ "recurring-payment/delete",
1751
+ this.envelope({ sid, recurring_payment_id: recurringPaymentId })
1752
+ );
1067
1753
  return MessageResult.fromRaw(raw["data"] ?? raw);
1068
1754
  }
1069
1755
  };
@@ -1082,35 +1768,68 @@ var TokenizeResult = class _TokenizeResult {
1082
1768
  // src/resources/transactions.ts
1083
1769
  var Transactions = class extends AbstractResource {
1084
1770
  async list(sid, filters = {}) {
1085
- return this.paginate("GET", "transactions", this.envelope({ sid }, filters), Transaction.fromRaw);
1771
+ return this.paginate(
1772
+ "GET",
1773
+ "transactions",
1774
+ this.envelope({ sid }, filters),
1775
+ Transaction.fromRaw
1776
+ );
1086
1777
  }
1087
1778
  async show(sid, identifier) {
1088
- const raw = await this.transport.request("GET", "transaction", this.envelope({ sid, ...identifier }));
1779
+ const raw = await this.transport.request(
1780
+ "GET",
1781
+ "transaction",
1782
+ this.envelope({ sid, ...identifier })
1783
+ );
1089
1784
  return Transaction.fromRaw(raw["data"] ?? {});
1090
1785
  }
1091
1786
  async chargeCard(sid, attributes) {
1092
- const raw = await this.transport.request("POST", "transaction/charge-card", this.envelope({ sid, ...attributes }));
1787
+ const raw = await this.transport.request(
1788
+ "POST",
1789
+ "transaction/charge-card",
1790
+ this.envelope({ sid, ...attributes })
1791
+ );
1093
1792
  return Transaction.fromRaw(raw["data"] ?? {});
1094
1793
  }
1095
1794
  /** @deprecated The API marks this deprecated; prefer chargeCard() with a token. */
1096
1795
  async chargeCardToken(sid, attributes) {
1097
- const raw = await this.transport.request("POST", "transaction/charge-card-token", this.envelope({ sid, ...attributes }));
1796
+ const raw = await this.transport.request(
1797
+ "POST",
1798
+ "transaction/charge-card-token",
1799
+ this.envelope({ sid, ...attributes })
1800
+ );
1098
1801
  return Transaction.fromRaw(raw["data"] ?? {});
1099
1802
  }
1100
1803
  async chargeAch(sid, attributes) {
1101
- const raw = await this.transport.request("POST", "transaction/charge-ach", this.envelope({ sid, ...attributes }));
1804
+ const raw = await this.transport.request(
1805
+ "POST",
1806
+ "transaction/charge-ach",
1807
+ this.envelope({ sid, ...attributes })
1808
+ );
1102
1809
  return Transaction.fromRaw(raw["data"] ?? {});
1103
1810
  }
1104
1811
  async tokenizeCard(sid, attributes) {
1105
- const raw = await this.transport.request("POST", "transaction/tokenize-card", this.envelope({ sid, ...attributes }));
1812
+ const raw = await this.transport.request(
1813
+ "POST",
1814
+ "transaction/tokenize-card",
1815
+ this.envelope({ sid, ...attributes })
1816
+ );
1106
1817
  return TokenizeResult.fromRaw(raw["data"] ?? {});
1107
1818
  }
1108
1819
  async refund(sid, attributes) {
1109
- const raw = await this.transport.request("POST", "transaction/refund", this.envelope({ sid, ...attributes }));
1820
+ const raw = await this.transport.request(
1821
+ "POST",
1822
+ "transaction/refund",
1823
+ this.envelope({ sid, ...attributes })
1824
+ );
1110
1825
  return MessageResult.fromRaw(raw["data"] ?? raw);
1111
1826
  }
1112
1827
  async void(sid, transactionType, transactionId) {
1113
- const raw = await this.transport.request("PATCH", "transaction/void", this.envelope({ sid, transaction_type: transactionType, transaction_id: transactionId }));
1828
+ const raw = await this.transport.request(
1829
+ "PATCH",
1830
+ "transaction/void",
1831
+ this.envelope({ sid, transaction_type: transactionType, transaction_id: transactionId })
1832
+ );
1114
1833
  return MessageResult.fromRaw(raw["data"] ?? raw);
1115
1834
  }
1116
1835
  };
@@ -1124,6 +1843,8 @@ var Client = class {
1124
1843
  addresses;
1125
1844
  deposits;
1126
1845
  recurringPayments;
1846
+ invoices;
1847
+ recurringInvoices;
1127
1848
  _config;
1128
1849
  constructor(token, baseUrl = DEFAULT_BASE_URL) {
1129
1850
  this._config = token instanceof Config ? token : new Config(token, baseUrl);
@@ -1135,6 +1856,8 @@ var Client = class {
1135
1856
  this.addresses = new Addresses(transport);
1136
1857
  this.deposits = new Deposits(transport);
1137
1858
  this.recurringPayments = new RecurringPayments(transport);
1859
+ this.invoices = new Invoices(transport);
1860
+ this.recurringInvoices = new RecurringInvoices(transport);
1138
1861
  }
1139
1862
  config() {
1140
1863
  return this._config;
@@ -1147,6 +1870,7 @@ export {
1147
1870
  Client,
1148
1871
  Config,
1149
1872
  ConnectionException,
1873
+ CoverFeeQuote,
1150
1874
  CursorPage,
1151
1875
  Customer,
1152
1876
  DEFAULT_BASE_URL,
@@ -1155,12 +1879,20 @@ export {
1155
1879
  DepositWithTransactions,
1156
1880
  DimeException,
1157
1881
  FormLink,
1882
+ Invoice,
1883
+ InvoiceCustomer,
1884
+ InvoiceEvent,
1885
+ InvoiceItem,
1886
+ InvoiceLineItem,
1887
+ InvoiceLink,
1888
+ InvoicePayment,
1158
1889
  Merchant,
1159
1890
  MessageResult,
1160
1891
  NotFoundException,
1161
1892
  PaymentMethod,
1162
1893
  PermissionDeniedException,
1163
1894
  RateLimitException,
1895
+ RecurringInvoice,
1164
1896
  RecurringPayment,
1165
1897
  RecurringPaymentMethod,
1166
1898
  ServerException,