@beel_es/sdk 1.2.0 → 2.0.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
@@ -43,12 +43,18 @@ __export(index_exports, {
43
43
  BeeLNotFoundError: () => BeeLNotFoundError,
44
44
  BeeLRateLimitError: () => BeeLRateLimitError,
45
45
  BeeLValidationError: () => BeeLValidationError,
46
+ CatalogsResource: () => CatalogsResource,
46
47
  CompanyCustomersResource: () => CompanyCustomersResource,
48
+ CompanyInvoiceScheduleResource: () => CompanyInvoiceScheduleResource,
47
49
  CompanyInvoicesResource: () => CompanyInvoicesResource,
50
+ CompanyPaymentConnectionsResource: () => CompanyPaymentConnectionsResource,
51
+ CompanyPaymentEventsResource: () => CompanyPaymentEventsResource,
48
52
  CompanyProductsResource: () => CompanyProductsResource,
49
53
  CompanyRecurringInvoicesResource: () => CompanyRecurringInvoicesResource,
50
54
  CompanyScope: () => CompanyScope,
51
55
  CompanySeriesResource: () => CompanySeriesResource,
56
+ CompanyTaxConfigurationResource: () => CompanyTaxConfigurationResource,
57
+ CompanyVeriFactuConfigurationResource: () => CompanyVeriFactuConfigurationResource,
52
58
  CustomerBuilder: () => CustomerBuilder,
53
59
  InvoiceBuilder: () => InvoiceBuilder,
54
60
  VeriFactuSubmissionStatus: () => VeriFactuSubmissionStatus,
@@ -483,6 +489,29 @@ var ConfigurationResource = class {
483
489
  return data.data;
484
490
  }
485
491
  };
492
+ var CatalogsResource = class {
493
+ constructor(client) {
494
+ this.client = client;
495
+ }
496
+ /** Tax types the API accepts. Canonical form of `configuration/tax-types`. */
497
+ async taxTypes() {
498
+ const { data } = await this.client.GET("/v1/tax-types");
499
+ return data.data;
500
+ }
501
+ /** Invoice customization options. Canonical form of the `configuration` read. */
502
+ async invoiceCustomizationOptions() {
503
+ const { data } = await this.client.GET("/v1/invoice-customization-options");
504
+ return data.data;
505
+ }
506
+ /**
507
+ * The signed-in person's preferences. Canonical form of
508
+ * `PUT /v1/configuration/language`: the language belongs to the person, not to a company.
509
+ */
510
+ async updateMe(body) {
511
+ const { data } = await this.client.PATCH("/v1/me", { body });
512
+ return data.data;
513
+ }
514
+ };
486
515
 
487
516
  // src/resources/series.ts
488
517
  var SeriesResource = class {
@@ -558,7 +587,10 @@ var AccountsResource = class {
558
587
  const { data } = await this.client.GET("/v1/accounts", { params: { query: params } });
559
588
  return data.data;
560
589
  }
561
- /** Provision a new managed account. */
590
+ /**
591
+ * Provision a new managed account. Answers with the provisioning result — the account
592
+ * id, its status and, when one is issued, the claim link — not with the account summary.
593
+ */
562
594
  async provision(body) {
563
595
  const { data } = await this.client.POST("/v1/accounts", { body });
564
596
  return data.data;
@@ -779,7 +811,10 @@ var AccountCompaniesResource = class {
779
811
  const { data } = await this.client.GET("/v1/accounts/{account_id}/companies", {
780
812
  params: { path: { account_id: this.accountId }, query: params }
781
813
  });
782
- return { companies: data.data ?? [], pagination: data.pagination };
814
+ return {
815
+ companies: data.data?.companies ?? [],
816
+ pagination: data.data?.pagination
817
+ };
783
818
  }
784
819
  /** Register a new company (NIF) under the account. */
785
820
  async create(body) {
@@ -798,6 +833,134 @@ var AccountCompaniesResource = class {
798
833
  }
799
834
  };
800
835
 
836
+ // src/resources/payment-connections.ts
837
+ var CompanyPaymentConnectionsResource = class {
838
+ constructor(client, companyId) {
839
+ this.client = client;
840
+ this.companyId = companyId;
841
+ }
842
+ path() {
843
+ return { company_id: this.companyId };
844
+ }
845
+ /** Every payment connection of this company. */
846
+ async list() {
847
+ const { data } = await this.client.GET("/v1/companies/{company_id}/payment-connections", {
848
+ params: { path: this.path() }
849
+ });
850
+ return data.data;
851
+ }
852
+ /**
853
+ * Start an authorization and get the URL where the NIF's holder approves it.
854
+ *
855
+ * This is the one place the provider slug is used — currently only `stripe`.
856
+ */
857
+ async authorize(body) {
858
+ const { data } = await this.client.POST(
859
+ "/v1/companies/{company_id}/payment-connections/authorizations",
860
+ { params: { path: this.path() }, body }
861
+ );
862
+ return data.data;
863
+ }
864
+ /** Update one connection, addressed by its UUID. */
865
+ async update(connectionId, body) {
866
+ const { data } = await this.client.PATCH(
867
+ "/v1/companies/{company_id}/payment-connections/{connection_id}",
868
+ { params: { path: { ...this.path(), connection_id: connectionId } }, body }
869
+ );
870
+ return data.data;
871
+ }
872
+ /**
873
+ * Disconnect one connection. Tokens are revoked and auto-invoicing stops;
874
+ * already-issued invoices are untouched.
875
+ */
876
+ async disconnect(connectionId) {
877
+ await this.client.DELETE("/v1/companies/{company_id}/payment-connections/{connection_id}", {
878
+ params: { path: { ...this.path(), connection_id: connectionId } }
879
+ });
880
+ }
881
+ /** The payment events of one connection — where you audit what did and didn't invoice. */
882
+ events(connectionId) {
883
+ return new CompanyPaymentEventsResource(this.client, this.companyId, connectionId);
884
+ }
885
+ };
886
+ var CompanyPaymentEventsResource = class {
887
+ constructor(client, companyId, connectionId) {
888
+ this.client = client;
889
+ this.companyId = companyId;
890
+ this.connectionId = connectionId;
891
+ }
892
+ path() {
893
+ return { company_id: this.companyId, connection_id: this.connectionId };
894
+ }
895
+ /**
896
+ * Events of the connection, most recent first. Nothing is hidden by default:
897
+ * skipped events, duplicates and disputes are all returned — narrow with the
898
+ * filters. `charges_only` returns one row per money movement instead.
899
+ */
900
+ async list(params) {
901
+ const { data } = await this.client.GET(
902
+ "/v1/companies/{company_id}/payment-connections/{connection_id}/events",
903
+ { params: { path: this.path(), query: params } }
904
+ );
905
+ return data.data;
906
+ }
907
+ /** One event. */
908
+ async get(eventId) {
909
+ const { data } = await this.client.GET(
910
+ "/v1/companies/{company_id}/payment-connections/{connection_id}/events/{event_id}",
911
+ { params: { path: { ...this.path(), event_id: eventId } } }
912
+ );
913
+ return data.data;
914
+ }
915
+ /**
916
+ * Reprocess an event whose automatic invoicing didn't complete, applying the NIF's
917
+ * **current** configuration. Only retryable states qualify and the retry budget is
918
+ * finite: otherwise `400`.
919
+ */
920
+ async retry(eventId) {
921
+ const { data } = await this.client.POST(
922
+ "/v1/companies/{company_id}/payment-connections/{connection_id}/events/{event_id}/retry",
923
+ { params: { path: { ...this.path(), event_id: eventId } } }
924
+ );
925
+ return data.data;
926
+ }
927
+ /**
928
+ * Build a **draft** invoice from an event that couldn't be invoiced automatically,
929
+ * so you can review it before issuing. Returns the draft's id.
930
+ */
931
+ async draft(eventId) {
932
+ const { data } = await this.client.POST(
933
+ "/v1/companies/{company_id}/payment-connections/{connection_id}/events/{event_id}/draft",
934
+ { params: { path: { ...this.path(), event_id: eventId } } }
935
+ );
936
+ return data.data;
937
+ }
938
+ /** Mark an event as dealt with outside the automatic flow. */
939
+ async resolve(eventId) {
940
+ const { data } = await this.client.POST(
941
+ "/v1/companies/{company_id}/payment-connections/{connection_id}/events/{event_id}/resolve",
942
+ { params: { path: { ...this.path(), event_id: eventId } } }
943
+ );
944
+ return data.data;
945
+ }
946
+ /** Discard an event so it stops asking for attention. Reversible with {@link restore}. */
947
+ async discard(eventId) {
948
+ const { data } = await this.client.POST(
949
+ "/v1/companies/{company_id}/payment-connections/{connection_id}/events/{event_id}/discard",
950
+ { params: { path: { ...this.path(), event_id: eventId } } }
951
+ );
952
+ return data.data;
953
+ }
954
+ /** Bring a discarded event back into the list. */
955
+ async restore(eventId) {
956
+ const { data } = await this.client.POST(
957
+ "/v1/companies/{company_id}/payment-connections/{connection_id}/events/{event_id}/restore",
958
+ { params: { path: { ...this.path(), event_id: eventId } } }
959
+ );
960
+ return data.data;
961
+ }
962
+ };
963
+
801
964
  // src/resources/company.ts
802
965
  var CompanyScope = class {
803
966
  constructor(client, companyId) {
@@ -808,6 +971,9 @@ var CompanyScope = class {
808
971
  this.products = new CompanyProductsResource(client, companyId);
809
972
  this.series = new CompanySeriesResource(client, companyId);
810
973
  this.recurringInvoices = new CompanyRecurringInvoicesResource(client, companyId);
974
+ this.paymentConnections = new CompanyPaymentConnectionsResource(client, companyId);
975
+ this.taxConfiguration = new CompanyTaxConfigurationResource(client, companyId);
976
+ this.verifactuConfiguration = new CompanyVeriFactuConfigurationResource(client, companyId);
811
977
  }
812
978
  path() {
813
979
  return { company_id: this.companyId };
@@ -850,6 +1016,17 @@ var CompanyInvoicesResource = class {
850
1016
  constructor(client, companyId) {
851
1017
  this.client = client;
852
1018
  this.companyId = companyId;
1019
+ this.schedule = new CompanyInvoiceScheduleResource(client, companyId);
1020
+ }
1021
+ /**
1022
+ * Derive a new invoice from an existing one — the canonical form of `duplicate`.
1023
+ */
1024
+ async derive(body) {
1025
+ const { data } = await this.client.POST("/v1/companies/{company_id}/invoices/derivations", {
1026
+ params: { path: { company_id: this.companyId } },
1027
+ body
1028
+ });
1029
+ return data.data;
853
1030
  }
854
1031
  path(rest) {
855
1032
  return { company_id: this.companyId, ...rest };
@@ -918,6 +1095,37 @@ var CompanyInvoicesResource = class {
918
1095
  });
919
1096
  return data.data;
920
1097
  }
1098
+ /**
1099
+ * Issue a full invoice in exchange for one or more issued simplified invoices, when the
1100
+ * customer asks for an invoice with their details. It is not a corrective: the simplified
1101
+ * invoices become `VOIDED` with `void_cause: 'EXCHANGED'`, and the new `STANDARD` invoice
1102
+ * lists them in `replaced_invoice_ids`.
1103
+ *
1104
+ * @example
1105
+ * ```typescript
1106
+ * const invoice = await company.invoices.createSimplifiedExchange({
1107
+ * simplified_invoice_ids: ['simplified-uuid'],
1108
+ * recipient: { customer_id: 'customer-uuid' },
1109
+ * });
1110
+ * ```
1111
+ */
1112
+ async createSimplifiedExchange(body) {
1113
+ const { data } = await this.client.POST("/v1/companies/{company_id}/invoices/simplified-exchanges", {
1114
+ params: { path: this.path() },
1115
+ body
1116
+ });
1117
+ return data.data;
1118
+ }
1119
+ /**
1120
+ * The VeriFactu records of an invoice, oldest first: its registration and, if it was
1121
+ * voided, its cancellation. An invoice never submitted answers with an empty list.
1122
+ */
1123
+ async verifactuRecords(invoiceId) {
1124
+ const { data } = await this.client.GET("/v1/companies/{company_id}/invoices/{invoice_id}/verifactu-records", {
1125
+ params: { path: this.path({ invoice_id: invoiceId }) }
1126
+ });
1127
+ return data.data.records;
1128
+ }
921
1129
  /** Update payment status (e.g. mark as paid). */
922
1130
  async setStatus(invoiceId, body) {
923
1131
  const { data } = await this.client.PUT("/v1/companies/{company_id}/invoices/{invoice_id}/status", {
@@ -942,6 +1150,36 @@ var CompanyInvoicesResource = class {
942
1150
  return data.data;
943
1151
  }
944
1152
  };
1153
+ var CompanyInvoiceScheduleResource = class {
1154
+ constructor(client, companyId) {
1155
+ this.client = client;
1156
+ this.companyId = companyId;
1157
+ }
1158
+ async get(invoiceId) {
1159
+ const { data } = await this.client.GET(
1160
+ "/v1/companies/{company_id}/invoices/{invoice_id}/schedule",
1161
+ { params: { path: { company_id: this.companyId, invoice_id: invoiceId } } }
1162
+ );
1163
+ return data.data;
1164
+ }
1165
+ /**
1166
+ * Set or move the schedule. One `PUT` replaces the three legacy calls
1167
+ * (`schedule`, `reschedule`, `unschedule`): setting it again moves it.
1168
+ */
1169
+ async set(invoiceId, body) {
1170
+ const { data } = await this.client.PUT(
1171
+ "/v1/companies/{company_id}/invoices/{invoice_id}/schedule",
1172
+ { params: { path: { company_id: this.companyId, invoice_id: invoiceId } }, body }
1173
+ );
1174
+ return data.data;
1175
+ }
1176
+ /** Clear the schedule — the canonical form of `unschedule`. */
1177
+ async clear(invoiceId) {
1178
+ await this.client.DELETE("/v1/companies/{company_id}/invoices/{invoice_id}/schedule", {
1179
+ params: { path: { company_id: this.companyId, invoice_id: invoiceId } }
1180
+ });
1181
+ }
1182
+ };
945
1183
  var CompanyCustomersResource = class {
946
1184
  constructor(client, companyId) {
947
1185
  this.client = client;
@@ -1149,16 +1387,57 @@ var CompanyRecurringInvoicesResource = class {
1149
1387
  return data.data;
1150
1388
  }
1151
1389
  };
1390
+ var CompanyTaxConfigurationResource = class {
1391
+ constructor(client, companyId) {
1392
+ this.client = client;
1393
+ this.companyId = companyId;
1394
+ }
1395
+ async get() {
1396
+ const { data } = await this.client.GET("/v1/companies/{company_id}/tax-configuration", {
1397
+ params: { path: { company_id: this.companyId } }
1398
+ });
1399
+ return data.data;
1400
+ }
1401
+ /** Replaces the whole state — this is a `PUT`, not a merge. */
1402
+ async update(body) {
1403
+ const { data } = await this.client.PUT("/v1/companies/{company_id}/tax-configuration", {
1404
+ params: { path: { company_id: this.companyId } },
1405
+ body
1406
+ });
1407
+ return data.data;
1408
+ }
1409
+ };
1410
+ var CompanyVeriFactuConfigurationResource = class {
1411
+ constructor(client, companyId) {
1412
+ this.client = client;
1413
+ this.companyId = companyId;
1414
+ }
1415
+ async get() {
1416
+ const { data } = await this.client.GET("/v1/companies/{company_id}/verifactu-configuration", {
1417
+ params: { path: { company_id: this.companyId } }
1418
+ });
1419
+ return data.data;
1420
+ }
1421
+ /** Flip VeriFactu for this NIF. `enabled` is the only field you can write. */
1422
+ async update(body) {
1423
+ const { data } = await this.client.PUT("/v1/companies/{company_id}/verifactu-configuration", {
1424
+ params: { path: { company_id: this.companyId } },
1425
+ body
1426
+ });
1427
+ return data.data;
1428
+ }
1429
+ };
1152
1430
 
1153
1431
  // src/client.ts
1154
1432
  var BeeL = class {
1155
1433
  constructor(config) {
1156
1434
  const client = createBeeLClient(config);
1157
- this._client = client;
1435
+ this.raw = client;
1158
1436
  this.invoices = new InvoicesResource(client);
1159
1437
  this.customers = new CustomersResource(client);
1160
1438
  this.products = new ProductsResource(client);
1161
1439
  this.configuration = new ConfigurationResource(client);
1440
+ this.catalogs = new CatalogsResource(client);
1162
1441
  this.series = new SeriesResource(client);
1163
1442
  this.nif = new NifResource(client);
1164
1443
  this.accounts = new AccountsResource(client);
@@ -1174,7 +1453,7 @@ var BeeL = class {
1174
1453
  * ```
1175
1454
  */
1176
1455
  company(companyId) {
1177
- return new CompanyScope(this._client, companyId);
1456
+ return new CompanyScope(this.raw, companyId);
1178
1457
  }
1179
1458
  /**
1180
1459
  * Returns a facade scoped to one managed account — members, invitations,
@@ -1187,7 +1466,7 @@ var BeeL = class {
1187
1466
  * ```
1188
1467
  */
1189
1468
  account(accountId) {
1190
- return new AccountScope(this._client, accountId);
1469
+ return new AccountScope(this.raw, accountId);
1191
1470
  }
1192
1471
  /**
1193
1472
  * Download an invoice PDF as a Buffer.
@@ -1239,6 +1518,7 @@ var WebhookVerifier = class {
1239
1518
  * const verifier = new WebhookVerifier('your_secret');
1240
1519
  * const event = verifier.verify(rawBody, signature);
1241
1520
  *
1521
+ * if (event.test) return; // a "Send test" delivery carries a synthetic `data`
1242
1522
  * if (event.type === 'verifactu.status.updated') {
1243
1523
  * console.log('Invoice:', event.data.invoice_number);
1244
1524
  * console.log('Status:', event.data.new_status);
@@ -1362,6 +1642,24 @@ var InvoiceIssuedEvent;
1362
1642
  })(type = InvoiceIssuedEvent2.type || (InvoiceIssuedEvent2.type = {}));
1363
1643
  })(InvoiceIssuedEvent || (InvoiceIssuedEvent = {}));
1364
1644
 
1645
+ // src/generated-webhooks/models/InvoicePdfGeneratedEvent.ts
1646
+ var InvoicePdfGeneratedEvent;
1647
+ ((InvoicePdfGeneratedEvent2) => {
1648
+ let type;
1649
+ ((type2) => {
1650
+ type2["INVOICE_PDF_GENERATED"] = "invoice.pdf.generated";
1651
+ })(type = InvoicePdfGeneratedEvent2.type || (InvoicePdfGeneratedEvent2.type = {}));
1652
+ })(InvoicePdfGeneratedEvent || (InvoicePdfGeneratedEvent = {}));
1653
+
1654
+ // src/generated-webhooks/models/InvoiceScheduleFailedEvent.ts
1655
+ var InvoiceScheduleFailedEvent;
1656
+ ((InvoiceScheduleFailedEvent2) => {
1657
+ let type;
1658
+ ((type2) => {
1659
+ type2["INVOICE_SCHEDULE_FAILED"] = "invoice.schedule_failed";
1660
+ })(type = InvoiceScheduleFailedEvent2.type || (InvoiceScheduleFailedEvent2.type = {}));
1661
+ })(InvoiceScheduleFailedEvent || (InvoiceScheduleFailedEvent = {}));
1662
+
1365
1663
  // src/generated-webhooks/models/InvoiceVoidedEvent.ts
1366
1664
  var InvoiceVoidedEvent;
1367
1665
  ((InvoiceVoidedEvent2) => {
@@ -1412,8 +1710,10 @@ var WebhookEventType = /* @__PURE__ */ ((WebhookEventType2) => {
1412
1710
  WebhookEventType2["VERIFACTU_STATUS_UPDATED"] = "verifactu.status.updated";
1413
1711
  WebhookEventType2["INVOICE_ISSUED"] = "invoice.issued";
1414
1712
  WebhookEventType2["INVOICE_EMAIL_SENT"] = "invoice.email.sent";
1713
+ WebhookEventType2["INVOICE_PDF_GENERATED"] = "invoice.pdf.generated";
1415
1714
  WebhookEventType2["INVOICE_VOIDED"] = "invoice.voided";
1416
1715
  WebhookEventType2["RECURRING_INVOICE_PAUSED"] = "recurring_invoice.paused";
1716
+ WebhookEventType2["INVOICE_SCHEDULE_FAILED"] = "invoice.schedule_failed";
1417
1717
  WebhookEventType2["ACCOUNT_CLAIMED"] = "account.claimed";
1418
1718
  WebhookEventType2["COMPANY_CREATED"] = "company.created";
1419
1719
  WebhookEventType2["REPRESENTATION_SIGNED"] = "representation.signed";
@@ -1542,12 +1842,18 @@ var InvoiceBuilder = class _InvoiceBuilder {
1542
1842
  BeeLNotFoundError,
1543
1843
  BeeLRateLimitError,
1544
1844
  BeeLValidationError,
1845
+ CatalogsResource,
1545
1846
  CompanyCustomersResource,
1847
+ CompanyInvoiceScheduleResource,
1546
1848
  CompanyInvoicesResource,
1849
+ CompanyPaymentConnectionsResource,
1850
+ CompanyPaymentEventsResource,
1547
1851
  CompanyProductsResource,
1548
1852
  CompanyRecurringInvoicesResource,
1549
1853
  CompanyScope,
1550
1854
  CompanySeriesResource,
1855
+ CompanyTaxConfigurationResource,
1856
+ CompanyVeriFactuConfigurationResource,
1551
1857
  CustomerBuilder,
1552
1858
  InvoiceBuilder,
1553
1859
  VeriFactuSubmissionStatus,