@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.mjs CHANGED
@@ -423,6 +423,29 @@ var ConfigurationResource = class {
423
423
  return data.data;
424
424
  }
425
425
  };
426
+ var CatalogsResource = class {
427
+ constructor(client) {
428
+ this.client = client;
429
+ }
430
+ /** Tax types the API accepts. Canonical form of `configuration/tax-types`. */
431
+ async taxTypes() {
432
+ const { data } = await this.client.GET("/v1/tax-types");
433
+ return data.data;
434
+ }
435
+ /** Invoice customization options. Canonical form of the `configuration` read. */
436
+ async invoiceCustomizationOptions() {
437
+ const { data } = await this.client.GET("/v1/invoice-customization-options");
438
+ return data.data;
439
+ }
440
+ /**
441
+ * The signed-in person's preferences. Canonical form of
442
+ * `PUT /v1/configuration/language`: the language belongs to the person, not to a company.
443
+ */
444
+ async updateMe(body) {
445
+ const { data } = await this.client.PATCH("/v1/me", { body });
446
+ return data.data;
447
+ }
448
+ };
426
449
 
427
450
  // src/resources/series.ts
428
451
  var SeriesResource = class {
@@ -498,7 +521,10 @@ var AccountsResource = class {
498
521
  const { data } = await this.client.GET("/v1/accounts", { params: { query: params } });
499
522
  return data.data;
500
523
  }
501
- /** Provision a new managed account. */
524
+ /**
525
+ * Provision a new managed account. Answers with the provisioning result — the account
526
+ * id, its status and, when one is issued, the claim link — not with the account summary.
527
+ */
502
528
  async provision(body) {
503
529
  const { data } = await this.client.POST("/v1/accounts", { body });
504
530
  return data.data;
@@ -719,7 +745,10 @@ var AccountCompaniesResource = class {
719
745
  const { data } = await this.client.GET("/v1/accounts/{account_id}/companies", {
720
746
  params: { path: { account_id: this.accountId }, query: params }
721
747
  });
722
- return { companies: data.data ?? [], pagination: data.pagination };
748
+ return {
749
+ companies: data.data?.companies ?? [],
750
+ pagination: data.data?.pagination
751
+ };
723
752
  }
724
753
  /** Register a new company (NIF) under the account. */
725
754
  async create(body) {
@@ -738,6 +767,134 @@ var AccountCompaniesResource = class {
738
767
  }
739
768
  };
740
769
 
770
+ // src/resources/payment-connections.ts
771
+ var CompanyPaymentConnectionsResource = class {
772
+ constructor(client, companyId) {
773
+ this.client = client;
774
+ this.companyId = companyId;
775
+ }
776
+ path() {
777
+ return { company_id: this.companyId };
778
+ }
779
+ /** Every payment connection of this company. */
780
+ async list() {
781
+ const { data } = await this.client.GET("/v1/companies/{company_id}/payment-connections", {
782
+ params: { path: this.path() }
783
+ });
784
+ return data.data;
785
+ }
786
+ /**
787
+ * Start an authorization and get the URL where the NIF's holder approves it.
788
+ *
789
+ * This is the one place the provider slug is used — currently only `stripe`.
790
+ */
791
+ async authorize(body) {
792
+ const { data } = await this.client.POST(
793
+ "/v1/companies/{company_id}/payment-connections/authorizations",
794
+ { params: { path: this.path() }, body }
795
+ );
796
+ return data.data;
797
+ }
798
+ /** Update one connection, addressed by its UUID. */
799
+ async update(connectionId, body) {
800
+ const { data } = await this.client.PATCH(
801
+ "/v1/companies/{company_id}/payment-connections/{connection_id}",
802
+ { params: { path: { ...this.path(), connection_id: connectionId } }, body }
803
+ );
804
+ return data.data;
805
+ }
806
+ /**
807
+ * Disconnect one connection. Tokens are revoked and auto-invoicing stops;
808
+ * already-issued invoices are untouched.
809
+ */
810
+ async disconnect(connectionId) {
811
+ await this.client.DELETE("/v1/companies/{company_id}/payment-connections/{connection_id}", {
812
+ params: { path: { ...this.path(), connection_id: connectionId } }
813
+ });
814
+ }
815
+ /** The payment events of one connection — where you audit what did and didn't invoice. */
816
+ events(connectionId) {
817
+ return new CompanyPaymentEventsResource(this.client, this.companyId, connectionId);
818
+ }
819
+ };
820
+ var CompanyPaymentEventsResource = class {
821
+ constructor(client, companyId, connectionId) {
822
+ this.client = client;
823
+ this.companyId = companyId;
824
+ this.connectionId = connectionId;
825
+ }
826
+ path() {
827
+ return { company_id: this.companyId, connection_id: this.connectionId };
828
+ }
829
+ /**
830
+ * Events of the connection, most recent first. Nothing is hidden by default:
831
+ * skipped events, duplicates and disputes are all returned — narrow with the
832
+ * filters. `charges_only` returns one row per money movement instead.
833
+ */
834
+ async list(params) {
835
+ const { data } = await this.client.GET(
836
+ "/v1/companies/{company_id}/payment-connections/{connection_id}/events",
837
+ { params: { path: this.path(), query: params } }
838
+ );
839
+ return data.data;
840
+ }
841
+ /** One event. */
842
+ async get(eventId) {
843
+ const { data } = await this.client.GET(
844
+ "/v1/companies/{company_id}/payment-connections/{connection_id}/events/{event_id}",
845
+ { params: { path: { ...this.path(), event_id: eventId } } }
846
+ );
847
+ return data.data;
848
+ }
849
+ /**
850
+ * Reprocess an event whose automatic invoicing didn't complete, applying the NIF's
851
+ * **current** configuration. Only retryable states qualify and the retry budget is
852
+ * finite: otherwise `400`.
853
+ */
854
+ async retry(eventId) {
855
+ const { data } = await this.client.POST(
856
+ "/v1/companies/{company_id}/payment-connections/{connection_id}/events/{event_id}/retry",
857
+ { params: { path: { ...this.path(), event_id: eventId } } }
858
+ );
859
+ return data.data;
860
+ }
861
+ /**
862
+ * Build a **draft** invoice from an event that couldn't be invoiced automatically,
863
+ * so you can review it before issuing. Returns the draft's id.
864
+ */
865
+ async draft(eventId) {
866
+ const { data } = await this.client.POST(
867
+ "/v1/companies/{company_id}/payment-connections/{connection_id}/events/{event_id}/draft",
868
+ { params: { path: { ...this.path(), event_id: eventId } } }
869
+ );
870
+ return data.data;
871
+ }
872
+ /** Mark an event as dealt with outside the automatic flow. */
873
+ async resolve(eventId) {
874
+ const { data } = await this.client.POST(
875
+ "/v1/companies/{company_id}/payment-connections/{connection_id}/events/{event_id}/resolve",
876
+ { params: { path: { ...this.path(), event_id: eventId } } }
877
+ );
878
+ return data.data;
879
+ }
880
+ /** Discard an event so it stops asking for attention. Reversible with {@link restore}. */
881
+ async discard(eventId) {
882
+ const { data } = await this.client.POST(
883
+ "/v1/companies/{company_id}/payment-connections/{connection_id}/events/{event_id}/discard",
884
+ { params: { path: { ...this.path(), event_id: eventId } } }
885
+ );
886
+ return data.data;
887
+ }
888
+ /** Bring a discarded event back into the list. */
889
+ async restore(eventId) {
890
+ const { data } = await this.client.POST(
891
+ "/v1/companies/{company_id}/payment-connections/{connection_id}/events/{event_id}/restore",
892
+ { params: { path: { ...this.path(), event_id: eventId } } }
893
+ );
894
+ return data.data;
895
+ }
896
+ };
897
+
741
898
  // src/resources/company.ts
742
899
  var CompanyScope = class {
743
900
  constructor(client, companyId) {
@@ -748,6 +905,9 @@ var CompanyScope = class {
748
905
  this.products = new CompanyProductsResource(client, companyId);
749
906
  this.series = new CompanySeriesResource(client, companyId);
750
907
  this.recurringInvoices = new CompanyRecurringInvoicesResource(client, companyId);
908
+ this.paymentConnections = new CompanyPaymentConnectionsResource(client, companyId);
909
+ this.taxConfiguration = new CompanyTaxConfigurationResource(client, companyId);
910
+ this.verifactuConfiguration = new CompanyVeriFactuConfigurationResource(client, companyId);
751
911
  }
752
912
  path() {
753
913
  return { company_id: this.companyId };
@@ -790,6 +950,17 @@ var CompanyInvoicesResource = class {
790
950
  constructor(client, companyId) {
791
951
  this.client = client;
792
952
  this.companyId = companyId;
953
+ this.schedule = new CompanyInvoiceScheduleResource(client, companyId);
954
+ }
955
+ /**
956
+ * Derive a new invoice from an existing one — the canonical form of `duplicate`.
957
+ */
958
+ async derive(body) {
959
+ const { data } = await this.client.POST("/v1/companies/{company_id}/invoices/derivations", {
960
+ params: { path: { company_id: this.companyId } },
961
+ body
962
+ });
963
+ return data.data;
793
964
  }
794
965
  path(rest) {
795
966
  return { company_id: this.companyId, ...rest };
@@ -858,6 +1029,37 @@ var CompanyInvoicesResource = class {
858
1029
  });
859
1030
  return data.data;
860
1031
  }
1032
+ /**
1033
+ * Issue a full invoice in exchange for one or more issued simplified invoices, when the
1034
+ * customer asks for an invoice with their details. It is not a corrective: the simplified
1035
+ * invoices become `VOIDED` with `void_cause: 'EXCHANGED'`, and the new `STANDARD` invoice
1036
+ * lists them in `replaced_invoice_ids`.
1037
+ *
1038
+ * @example
1039
+ * ```typescript
1040
+ * const invoice = await company.invoices.createSimplifiedExchange({
1041
+ * simplified_invoice_ids: ['simplified-uuid'],
1042
+ * recipient: { customer_id: 'customer-uuid' },
1043
+ * });
1044
+ * ```
1045
+ */
1046
+ async createSimplifiedExchange(body) {
1047
+ const { data } = await this.client.POST("/v1/companies/{company_id}/invoices/simplified-exchanges", {
1048
+ params: { path: this.path() },
1049
+ body
1050
+ });
1051
+ return data.data;
1052
+ }
1053
+ /**
1054
+ * The VeriFactu records of an invoice, oldest first: its registration and, if it was
1055
+ * voided, its cancellation. An invoice never submitted answers with an empty list.
1056
+ */
1057
+ async verifactuRecords(invoiceId) {
1058
+ const { data } = await this.client.GET("/v1/companies/{company_id}/invoices/{invoice_id}/verifactu-records", {
1059
+ params: { path: this.path({ invoice_id: invoiceId }) }
1060
+ });
1061
+ return data.data.records;
1062
+ }
861
1063
  /** Update payment status (e.g. mark as paid). */
862
1064
  async setStatus(invoiceId, body) {
863
1065
  const { data } = await this.client.PUT("/v1/companies/{company_id}/invoices/{invoice_id}/status", {
@@ -882,6 +1084,36 @@ var CompanyInvoicesResource = class {
882
1084
  return data.data;
883
1085
  }
884
1086
  };
1087
+ var CompanyInvoiceScheduleResource = class {
1088
+ constructor(client, companyId) {
1089
+ this.client = client;
1090
+ this.companyId = companyId;
1091
+ }
1092
+ async get(invoiceId) {
1093
+ const { data } = await this.client.GET(
1094
+ "/v1/companies/{company_id}/invoices/{invoice_id}/schedule",
1095
+ { params: { path: { company_id: this.companyId, invoice_id: invoiceId } } }
1096
+ );
1097
+ return data.data;
1098
+ }
1099
+ /**
1100
+ * Set or move the schedule. One `PUT` replaces the three legacy calls
1101
+ * (`schedule`, `reschedule`, `unschedule`): setting it again moves it.
1102
+ */
1103
+ async set(invoiceId, body) {
1104
+ const { data } = await this.client.PUT(
1105
+ "/v1/companies/{company_id}/invoices/{invoice_id}/schedule",
1106
+ { params: { path: { company_id: this.companyId, invoice_id: invoiceId } }, body }
1107
+ );
1108
+ return data.data;
1109
+ }
1110
+ /** Clear the schedule — the canonical form of `unschedule`. */
1111
+ async clear(invoiceId) {
1112
+ await this.client.DELETE("/v1/companies/{company_id}/invoices/{invoice_id}/schedule", {
1113
+ params: { path: { company_id: this.companyId, invoice_id: invoiceId } }
1114
+ });
1115
+ }
1116
+ };
885
1117
  var CompanyCustomersResource = class {
886
1118
  constructor(client, companyId) {
887
1119
  this.client = client;
@@ -1089,16 +1321,57 @@ var CompanyRecurringInvoicesResource = class {
1089
1321
  return data.data;
1090
1322
  }
1091
1323
  };
1324
+ var CompanyTaxConfigurationResource = class {
1325
+ constructor(client, companyId) {
1326
+ this.client = client;
1327
+ this.companyId = companyId;
1328
+ }
1329
+ async get() {
1330
+ const { data } = await this.client.GET("/v1/companies/{company_id}/tax-configuration", {
1331
+ params: { path: { company_id: this.companyId } }
1332
+ });
1333
+ return data.data;
1334
+ }
1335
+ /** Replaces the whole state — this is a `PUT`, not a merge. */
1336
+ async update(body) {
1337
+ const { data } = await this.client.PUT("/v1/companies/{company_id}/tax-configuration", {
1338
+ params: { path: { company_id: this.companyId } },
1339
+ body
1340
+ });
1341
+ return data.data;
1342
+ }
1343
+ };
1344
+ var CompanyVeriFactuConfigurationResource = class {
1345
+ constructor(client, companyId) {
1346
+ this.client = client;
1347
+ this.companyId = companyId;
1348
+ }
1349
+ async get() {
1350
+ const { data } = await this.client.GET("/v1/companies/{company_id}/verifactu-configuration", {
1351
+ params: { path: { company_id: this.companyId } }
1352
+ });
1353
+ return data.data;
1354
+ }
1355
+ /** Flip VeriFactu for this NIF. `enabled` is the only field you can write. */
1356
+ async update(body) {
1357
+ const { data } = await this.client.PUT("/v1/companies/{company_id}/verifactu-configuration", {
1358
+ params: { path: { company_id: this.companyId } },
1359
+ body
1360
+ });
1361
+ return data.data;
1362
+ }
1363
+ };
1092
1364
 
1093
1365
  // src/client.ts
1094
1366
  var BeeL = class {
1095
1367
  constructor(config) {
1096
1368
  const client = createBeeLClient(config);
1097
- this._client = client;
1369
+ this.raw = client;
1098
1370
  this.invoices = new InvoicesResource(client);
1099
1371
  this.customers = new CustomersResource(client);
1100
1372
  this.products = new ProductsResource(client);
1101
1373
  this.configuration = new ConfigurationResource(client);
1374
+ this.catalogs = new CatalogsResource(client);
1102
1375
  this.series = new SeriesResource(client);
1103
1376
  this.nif = new NifResource(client);
1104
1377
  this.accounts = new AccountsResource(client);
@@ -1114,7 +1387,7 @@ var BeeL = class {
1114
1387
  * ```
1115
1388
  */
1116
1389
  company(companyId) {
1117
- return new CompanyScope(this._client, companyId);
1390
+ return new CompanyScope(this.raw, companyId);
1118
1391
  }
1119
1392
  /**
1120
1393
  * Returns a facade scoped to one managed account — members, invitations,
@@ -1127,7 +1400,7 @@ var BeeL = class {
1127
1400
  * ```
1128
1401
  */
1129
1402
  account(accountId) {
1130
- return new AccountScope(this._client, accountId);
1403
+ return new AccountScope(this.raw, accountId);
1131
1404
  }
1132
1405
  /**
1133
1406
  * Download an invoice PDF as a Buffer.
@@ -1179,6 +1452,7 @@ var WebhookVerifier = class {
1179
1452
  * const verifier = new WebhookVerifier('your_secret');
1180
1453
  * const event = verifier.verify(rawBody, signature);
1181
1454
  *
1455
+ * if (event.test) return; // a "Send test" delivery carries a synthetic `data`
1182
1456
  * if (event.type === 'verifactu.status.updated') {
1183
1457
  * console.log('Invoice:', event.data.invoice_number);
1184
1458
  * console.log('Status:', event.data.new_status);
@@ -1302,6 +1576,24 @@ var InvoiceIssuedEvent;
1302
1576
  })(type = InvoiceIssuedEvent2.type || (InvoiceIssuedEvent2.type = {}));
1303
1577
  })(InvoiceIssuedEvent || (InvoiceIssuedEvent = {}));
1304
1578
 
1579
+ // src/generated-webhooks/models/InvoicePdfGeneratedEvent.ts
1580
+ var InvoicePdfGeneratedEvent;
1581
+ ((InvoicePdfGeneratedEvent2) => {
1582
+ let type;
1583
+ ((type2) => {
1584
+ type2["INVOICE_PDF_GENERATED"] = "invoice.pdf.generated";
1585
+ })(type = InvoicePdfGeneratedEvent2.type || (InvoicePdfGeneratedEvent2.type = {}));
1586
+ })(InvoicePdfGeneratedEvent || (InvoicePdfGeneratedEvent = {}));
1587
+
1588
+ // src/generated-webhooks/models/InvoiceScheduleFailedEvent.ts
1589
+ var InvoiceScheduleFailedEvent;
1590
+ ((InvoiceScheduleFailedEvent2) => {
1591
+ let type;
1592
+ ((type2) => {
1593
+ type2["INVOICE_SCHEDULE_FAILED"] = "invoice.schedule_failed";
1594
+ })(type = InvoiceScheduleFailedEvent2.type || (InvoiceScheduleFailedEvent2.type = {}));
1595
+ })(InvoiceScheduleFailedEvent || (InvoiceScheduleFailedEvent = {}));
1596
+
1305
1597
  // src/generated-webhooks/models/InvoiceVoidedEvent.ts
1306
1598
  var InvoiceVoidedEvent;
1307
1599
  ((InvoiceVoidedEvent2) => {
@@ -1352,8 +1644,10 @@ var WebhookEventType = /* @__PURE__ */ ((WebhookEventType2) => {
1352
1644
  WebhookEventType2["VERIFACTU_STATUS_UPDATED"] = "verifactu.status.updated";
1353
1645
  WebhookEventType2["INVOICE_ISSUED"] = "invoice.issued";
1354
1646
  WebhookEventType2["INVOICE_EMAIL_SENT"] = "invoice.email.sent";
1647
+ WebhookEventType2["INVOICE_PDF_GENERATED"] = "invoice.pdf.generated";
1355
1648
  WebhookEventType2["INVOICE_VOIDED"] = "invoice.voided";
1356
1649
  WebhookEventType2["RECURRING_INVOICE_PAUSED"] = "recurring_invoice.paused";
1650
+ WebhookEventType2["INVOICE_SCHEDULE_FAILED"] = "invoice.schedule_failed";
1357
1651
  WebhookEventType2["ACCOUNT_CLAIMED"] = "account.claimed";
1358
1652
  WebhookEventType2["COMPANY_CREATED"] = "company.created";
1359
1653
  WebhookEventType2["REPRESENTATION_SIGNED"] = "representation.signed";
@@ -1481,12 +1775,18 @@ export {
1481
1775
  BeeLNotFoundError,
1482
1776
  BeeLRateLimitError,
1483
1777
  BeeLValidationError,
1778
+ CatalogsResource,
1484
1779
  CompanyCustomersResource,
1780
+ CompanyInvoiceScheduleResource,
1485
1781
  CompanyInvoicesResource,
1782
+ CompanyPaymentConnectionsResource,
1783
+ CompanyPaymentEventsResource,
1486
1784
  CompanyProductsResource,
1487
1785
  CompanyRecurringInvoicesResource,
1488
1786
  CompanyScope,
1489
1787
  CompanySeriesResource,
1788
+ CompanyTaxConfigurationResource,
1789
+ CompanyVeriFactuConfigurationResource,
1490
1790
  CustomerBuilder,
1491
1791
  InvoiceBuilder,
1492
1792
  VeriFactuSubmissionStatus,