@beel_es/sdk 2.0.0 → 2.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.
Files changed (41) hide show
  1. package/CHANGELOG.md +244 -0
  2. package/README.md +216 -25
  3. package/dist/index.d.mts +1480 -185
  4. package/dist/index.d.ts +1480 -185
  5. package/dist/index.js +1419 -187
  6. package/dist/index.js.map +1 -1
  7. package/dist/index.mjs +1416 -187
  8. package/dist/index.mjs.map +1 -1
  9. package/docs/reference/README.md +233 -0
  10. package/docs/reference/account-companies.md +55 -0
  11. package/docs/reference/account-invitations.md +57 -0
  12. package/docs/reference/account-members.md +97 -0
  13. package/docs/reference/account-webhooks.md +123 -0
  14. package/docs/reference/account.md +94 -0
  15. package/docs/reference/accounts.md +72 -0
  16. package/docs/reference/catalogs.md +68 -0
  17. package/docs/reference/client.md +113 -0
  18. package/docs/reference/company-customers.md +85 -0
  19. package/docs/reference/company-invoices-schedule.md +52 -0
  20. package/docs/reference/company-invoices.md +316 -0
  21. package/docs/reference/company-payment-connections-events.md +103 -0
  22. package/docs/reference/company-payment-connections.md +87 -0
  23. package/docs/reference/company-products.md +72 -0
  24. package/docs/reference/company-recurring-invoices.md +136 -0
  25. package/docs/reference/company-series.md +94 -0
  26. package/docs/reference/company-tax-configuration.md +36 -0
  27. package/docs/reference/company-verifactu-configuration.md +41 -0
  28. package/docs/reference/company.md +94 -0
  29. package/docs/reference/configuration.md +90 -0
  30. package/docs/reference/customer-builder.md +107 -0
  31. package/docs/reference/customers.md +91 -0
  32. package/docs/reference/errors.md +72 -0
  33. package/docs/reference/invoice-builder.md +149 -0
  34. package/docs/reference/invoices.md +250 -0
  35. package/docs/reference/nif.md +31 -0
  36. package/docs/reference/products.md +111 -0
  37. package/docs/reference/series.md +81 -0
  38. package/docs/reference/types.md +222 -0
  39. package/docs/reference/webhook-verifier.md +95 -0
  40. package/llms.txt +52 -0
  41. package/package.json +10 -4
package/dist/index.js CHANGED
@@ -40,6 +40,7 @@ __export(index_exports, {
40
40
  BeeLApiError: () => BeeLApiError,
41
41
  BeeLAuthError: () => BeeLAuthError,
42
42
  BeeLConflictError: () => BeeLConflictError,
43
+ BeeLErrorCodes: () => BeeLErrorCodes,
43
44
  BeeLNotFoundError: () => BeeLNotFoundError,
44
45
  BeeLRateLimitError: () => BeeLRateLimitError,
45
46
  BeeLValidationError: () => BeeLValidationError,
@@ -56,7 +57,9 @@ __export(index_exports, {
56
57
  CompanyTaxConfigurationResource: () => CompanyTaxConfigurationResource,
57
58
  CompanyVeriFactuConfigurationResource: () => CompanyVeriFactuConfigurationResource,
58
59
  CustomerBuilder: () => CustomerBuilder,
60
+ EXTERNAL_REF_UNIQUE_INVOICE_TYPES: () => EXTERNAL_REF_UNIQUE_INVOICE_TYPES,
59
61
  InvoiceBuilder: () => InvoiceBuilder,
62
+ VeriFactuRecordOperation: () => VeriFactuRecordOperation,
60
63
  VeriFactuSubmissionStatus: () => VeriFactuSubmissionStatus,
61
64
  WebhookEventType: () => WebhookEventType,
62
65
  WebhookVerificationError: () => WebhookVerificationError,
@@ -67,54 +70,88 @@ module.exports = __toCommonJS(index_exports);
67
70
  // src/http/client.ts
68
71
  var import_openapi_fetch = __toESM(require("openapi-fetch"));
69
72
 
73
+ // src/core/defaults.ts
74
+ var DEFAULT_BASE_URL = "https://app.beel.es/api";
75
+ var DEFAULT_MAX_RETRIES = 3;
76
+ var DEFAULT_RETRY_DELAY_MS = 500;
77
+ var DEFAULT_MAX_RETRY_DELAY_MS = 3e4;
78
+ var DEFAULT_AUTO_IDEMPOTENCY_KEY = true;
79
+
80
+ // src/http/headers.ts
81
+ var IDEMPOTENCY_KEY_HEADER = "Idempotency-Key";
82
+ var IDEMPOTENCY_REPLAY_HEADER = "Idempotency-Replay";
83
+ var RETRY_AFTER_HEADER = "Retry-After";
84
+ var AUTHORIZATION_HEADER = "Authorization";
85
+ var CONTENT_TYPE_HEADER = "Content-Type";
86
+ var JSON_CONTENT_TYPE = "application/json";
87
+ var EMPTY_JSON_BODY = "{}";
88
+
70
89
  // src/http/middleware.ts
71
90
  var import_crypto = require("crypto");
72
91
 
92
+ // src/core/http-status.ts
93
+ var HttpStatus = {
94
+ UNAUTHORIZED: 401,
95
+ FORBIDDEN: 403,
96
+ NOT_FOUND: 404,
97
+ CONFLICT: 409,
98
+ UNPROCESSABLE_ENTITY: 422,
99
+ TOO_MANY_REQUESTS: 429,
100
+ /** First status of the 5xx range: the server failed, not the request. */
101
+ SERVER_ERROR_MIN: 500
102
+ };
103
+ function isServerErrorStatus(status) {
104
+ return status >= HttpStatus.SERVER_ERROR_MIN;
105
+ }
106
+
73
107
  // src/core/errors.ts
108
+ var DEFAULT_RATE_LIMIT_RETRY_AFTER_SECONDS = 60;
74
109
  var BeeLApiError = class extends Error {
75
- constructor(message, statusCode, code, details, requestId) {
110
+ constructor(message, statusCode, code, details, requestId, apiCode) {
76
111
  super(message);
77
112
  this.name = "BeeLApiError";
78
113
  this.statusCode = statusCode;
79
114
  this.code = code;
115
+ this.apiCode = apiCode ?? code;
80
116
  this.details = details;
81
117
  this.requestId = requestId;
82
118
  }
83
119
  };
84
120
  var BeeLRateLimitError = class extends BeeLApiError {
85
- constructor(message, retryAfterSeconds, requestId) {
86
- super(message, 429, "RATE_LIMIT_EXCEEDED", void 0, requestId);
121
+ constructor(message, retryAfterSeconds, requestId, apiCode) {
122
+ super(message, HttpStatus.TOO_MANY_REQUESTS, "RATE_LIMIT_EXCEEDED", void 0, requestId, apiCode);
87
123
  this.name = "BeeLRateLimitError";
88
124
  this.retryAfterSeconds = retryAfterSeconds;
89
125
  }
90
126
  };
91
127
  var BeeLValidationError = class extends BeeLApiError {
92
- constructor(message, details, requestId) {
93
- super(message, 422, "UNPROCESSABLE_ENTITY", details, requestId);
128
+ constructor(message, details, requestId, apiCode) {
129
+ super(message, HttpStatus.UNPROCESSABLE_ENTITY, "UNPROCESSABLE_ENTITY", details, requestId, apiCode);
94
130
  this.name = "BeeLValidationError";
95
131
  }
96
132
  };
97
133
  var BeeLAuthError = class extends BeeLApiError {
98
- constructor(message, statusCode, requestId) {
134
+ constructor(message, statusCode, requestId, apiCode) {
99
135
  super(
100
136
  message,
101
137
  statusCode,
102
- statusCode === 401 ? "UNAUTHORIZED" : "FORBIDDEN",
138
+ statusCode === HttpStatus.UNAUTHORIZED ? "UNAUTHORIZED" : "FORBIDDEN",
103
139
  void 0,
104
- requestId
140
+ requestId,
141
+ apiCode
105
142
  );
106
143
  this.name = "BeeLAuthError";
107
144
  }
108
145
  };
109
146
  var BeeLNotFoundError = class extends BeeLApiError {
110
- constructor(message, requestId) {
111
- super(message, 404, "NOT_FOUND", void 0, requestId);
147
+ constructor(message, requestId, apiCode) {
148
+ super(message, HttpStatus.NOT_FOUND, "NOT_FOUND", void 0, requestId, apiCode);
112
149
  this.name = "BeeLNotFoundError";
113
150
  }
114
151
  };
115
152
  var BeeLConflictError = class extends BeeLApiError {
116
- constructor(message, requestId) {
117
- super(message, 409, "CONFLICT", void 0, requestId);
153
+ constructor(message, requestId, apiCode, details) {
154
+ super(message, HttpStatus.CONFLICT, "CONFLICT", details, requestId, apiCode);
118
155
  this.name = "BeeLConflictError";
119
156
  }
120
157
  };
@@ -122,52 +159,60 @@ function throwApiError(status, body) {
122
159
  const parsed = body;
123
160
  const errorData = parsed?.error ?? parsed;
124
161
  const message = errorData?.message ?? `API error ${status}`;
125
- const code = errorData?.code ?? "UNKNOWN";
162
+ const apiCode = errorData?.code;
126
163
  const details = errorData?.details;
127
164
  const requestId = parsed?.meta?.request_id;
128
165
  switch (status) {
129
- case 401:
130
- case 403:
131
- throw new BeeLAuthError(message, status, requestId);
132
- case 404:
133
- throw new BeeLNotFoundError(message, requestId);
134
- case 409:
135
- throw new BeeLConflictError(message, requestId);
136
- case 422:
137
- throw new BeeLValidationError(message, details, requestId);
138
- case 429: {
139
- const retryAfter = errorData?.retry_after ?? 60;
140
- throw new BeeLRateLimitError(message, retryAfter, requestId);
166
+ case HttpStatus.UNAUTHORIZED:
167
+ case HttpStatus.FORBIDDEN:
168
+ throw new BeeLAuthError(message, status, requestId, apiCode);
169
+ case HttpStatus.NOT_FOUND:
170
+ throw new BeeLNotFoundError(message, requestId, apiCode);
171
+ case HttpStatus.CONFLICT:
172
+ throw new BeeLConflictError(message, requestId, apiCode, details);
173
+ case HttpStatus.UNPROCESSABLE_ENTITY:
174
+ throw new BeeLValidationError(message, details, requestId, apiCode);
175
+ case HttpStatus.TOO_MANY_REQUESTS: {
176
+ const retryAfter = errorData?.retry_after ?? DEFAULT_RATE_LIMIT_RETRY_AFTER_SECONDS;
177
+ throw new BeeLRateLimitError(message, retryAfter, requestId, apiCode);
141
178
  }
142
179
  default:
143
- throw new BeeLApiError(message, status, code, details, requestId);
180
+ throw new BeeLApiError(message, status, apiCode ?? "UNKNOWN", details, requestId);
144
181
  }
145
182
  }
146
183
 
147
184
  // src/http/middleware.ts
148
- var requestMiddleware = {
149
- async onRequest({ request }) {
150
- const method = request.method;
151
- if (["POST", "PUT", "PATCH"].includes(method)) {
152
- const hasBody = request.headers.get("content-type")?.includes("application/json");
153
- if (!hasBody) {
154
- const clone = new Request(request, {
155
- body: request.body ?? "{}",
156
- headers: new Headers(request.headers)
157
- });
158
- clone.headers.set("Content-Type", "application/json");
159
- if (method === "POST" && !clone.headers.has("Idempotency-Key")) {
160
- clone.headers.set("Idempotency-Key", (0, import_crypto.randomUUID)());
185
+ var METHODS_WITH_JSON_BODY = /* @__PURE__ */ new Set(["POST", "PUT", "PATCH"]);
186
+ var METHODS_WITH_AUTO_IDEMPOTENCY_KEY = /* @__PURE__ */ new Set(["POST"]);
187
+ function newIdempotencyKey() {
188
+ return (0, import_crypto.randomUUID)();
189
+ }
190
+ function createRequestMiddleware(options) {
191
+ const addKeyIfMissing = (request) => {
192
+ if (options.autoIdempotencyKey && METHODS_WITH_AUTO_IDEMPOTENCY_KEY.has(request.method) && !request.headers.has(IDEMPOTENCY_KEY_HEADER)) {
193
+ request.headers.set(IDEMPOTENCY_KEY_HEADER, newIdempotencyKey());
194
+ }
195
+ };
196
+ return {
197
+ async onRequest({ request }) {
198
+ if (METHODS_WITH_JSON_BODY.has(request.method)) {
199
+ const hasBody = request.headers.get(CONTENT_TYPE_HEADER)?.includes(JSON_CONTENT_TYPE);
200
+ if (!hasBody) {
201
+ const clone = new Request(request, {
202
+ body: request.body ?? EMPTY_JSON_BODY,
203
+ headers: new Headers(request.headers)
204
+ });
205
+ clone.headers.set(CONTENT_TYPE_HEADER, JSON_CONTENT_TYPE);
206
+ addKeyIfMissing(clone);
207
+ return clone;
161
208
  }
162
- return clone;
163
209
  }
210
+ addKeyIfMissing(request);
211
+ return request;
164
212
  }
165
- if (method === "POST" && !request.headers.has("Idempotency-Key")) {
166
- request.headers.set("Idempotency-Key", (0, import_crypto.randomUUID)());
167
- }
168
- return request;
169
- }
170
- };
213
+ };
214
+ }
215
+ var requestMiddleware = createRequestMiddleware({ autoIdempotencyKey: true });
171
216
  var errorMiddleware = {
172
217
  async onResponse({ response }) {
173
218
  if (!response.ok) {
@@ -177,31 +222,119 @@ var errorMiddleware = {
177
222
  return response;
178
223
  }
179
224
  };
180
- function createRetryMiddleware(options) {
181
- return {
182
- async onError({ error, request }) {
183
- if (!(error instanceof BeeLApiError)) return;
184
- if (!(error instanceof BeeLRateLimitError) && error.statusCode < 500) return;
185
- for (let attempt = 0; attempt < options.maxRetries; attempt++) {
186
- const delay = error instanceof BeeLRateLimitError ? error.retryAfterSeconds * 1e3 : Math.min(
187
- options.initialDelayMs * Math.pow(2, attempt) + Math.random() * options.initialDelayMs,
188
- options.maxDelayMs
189
- );
190
- await new Promise((r) => setTimeout(r, delay));
191
- try {
192
- if (request.method === "POST") {
193
- request.headers.set("Idempotency-Key", (0, import_crypto.randomUUID)());
194
- }
195
- const response = await fetch(request.clone());
196
- if (response.ok) return response;
197
- const body = await response.json().catch(() => null);
198
- throwApiError(response.status, body);
199
- } catch (retryError) {
200
- if (!(retryError instanceof BeeLApiError)) throw retryError;
201
- if (!(retryError instanceof BeeLRateLimitError) && retryError.statusCode < 500) throw retryError;
202
- if (attempt === options.maxRetries - 1) throw retryError;
203
- }
225
+
226
+ // src/core/retry.ts
227
+ function sleep(ms, signal) {
228
+ return new Promise((resolve, reject) => {
229
+ if (signal?.aborted) {
230
+ reject(signal.reason);
231
+ return;
232
+ }
233
+ const onAbort = () => {
234
+ clearTimeout(timer);
235
+ reject(signal.reason);
236
+ };
237
+ const timer = setTimeout(() => {
238
+ signal?.removeEventListener("abort", onAbort);
239
+ resolve();
240
+ }, ms);
241
+ signal?.addEventListener("abort", onAbort, { once: true });
242
+ });
243
+ }
244
+ function computeBackoffDelayMs(attempt, options, random = Math.random) {
245
+ const exponentialDelay = options.initialDelayMs * Math.pow(2, attempt);
246
+ const jitter = random() * options.initialDelayMs;
247
+ return Math.min(exponentialDelay + jitter, options.maxDelayMs);
248
+ }
249
+
250
+ // src/core/error-codes.ts
251
+ var BeeLErrorCodes = {
252
+ /**
253
+ * `409`: a live standard or simplified invoice with the same `external_ref` already exists
254
+ * in this environment. Look it up with `invoices.list({ external_ref })`.
255
+ */
256
+ INVOICE_DUPLICATE_EXTERNAL_REFERENCE: "INVOICE_DUPLICATE_EXTERNAL_REFERENCE",
257
+ /**
258
+ * `409`: the first request with this `Idempotency-Key` is still being processed. Retry with
259
+ * the same key after `Retry-After`; the client does so automatically.
260
+ */
261
+ IDEMPOTENCY_KEY_PROCESSING: "IDEMPOTENCY_KEY_PROCESSING",
262
+ /** `409`: the `Idempotency-Key` was already used with a different body. Use a new key. */
263
+ IDEMPOTENCY_KEY_MISMATCH: "IDEMPOTENCY_KEY_MISMATCH"
264
+ };
265
+
266
+ // src/http/retry-policy.ts
267
+ var MS_PER_SECOND = 1e3;
268
+ var READ_ONLY_METHODS = /* @__PURE__ */ new Set(["GET", "HEAD", "OPTIONS"]);
269
+ var IDEMPOTENCY_PROCESSING_DEFAULT_WAIT_MS = 2 * MS_PER_SECOND;
270
+ var NO_RETRY = { retry: false };
271
+ function isReplaySafe(request) {
272
+ return READ_ONLY_METHODS.has(request.method) || request.headers.has(IDEMPOTENCY_KEY_HEADER);
273
+ }
274
+ function parseRetryAfterMs(value, now = Date.now()) {
275
+ if (value === null || value.trim() === "") return void 0;
276
+ const seconds = Number(value);
277
+ if (Number.isFinite(seconds)) return Math.max(0, seconds * MS_PER_SECOND);
278
+ const date = Date.parse(value);
279
+ return Number.isNaN(date) ? void 0 : Math.max(0, date - now);
280
+ }
281
+ function isAbort(error) {
282
+ return error instanceof Error && error.name === "AbortError";
283
+ }
284
+ async function errorCodeOf(response) {
285
+ const body = await response.clone().json().catch(() => null);
286
+ return body?.error?.code;
287
+ }
288
+ async function decideRetry(request, outcome, attempt, options) {
289
+ const backoff = () => computeBackoffDelayMs(attempt, options);
290
+ const capped = (delayMs) => ({
291
+ retry: true,
292
+ delayMs: Math.min(delayMs, options.maxDelayMs)
293
+ });
294
+ if (request.signal?.aborted) return NO_RETRY;
295
+ if ("error" in outcome) {
296
+ if (isAbort(outcome.error) || !isReplaySafe(request)) return NO_RETRY;
297
+ return capped(backoff());
298
+ }
299
+ const { response } = outcome;
300
+ const retryAfterMs = parseRetryAfterMs(response.headers.get(RETRY_AFTER_HEADER));
301
+ if (response.status === HttpStatus.TOO_MANY_REQUESTS) {
302
+ return capped(retryAfterMs ?? backoff());
303
+ }
304
+ if (response.status === HttpStatus.CONFLICT && request.headers.has(IDEMPOTENCY_KEY_HEADER) && await errorCodeOf(response) === BeeLErrorCodes.IDEMPOTENCY_KEY_PROCESSING) {
305
+ return capped(retryAfterMs ?? IDEMPOTENCY_PROCESSING_DEFAULT_WAIT_MS);
306
+ }
307
+ if (isServerErrorStatus(response.status)) {
308
+ const isStoredReplay = response.headers.get(IDEMPOTENCY_REPLAY_HEADER) === "true";
309
+ if (isStoredReplay || !isReplaySafe(request)) return NO_RETRY;
310
+ return capped(retryAfterMs ?? backoff());
311
+ }
312
+ return NO_RETRY;
313
+ }
314
+
315
+ // src/http/retrying-fetch.ts
316
+ var globalFetch = (request, init) => globalThis.fetch(request, init);
317
+ async function discard(response) {
318
+ await response.body?.cancel().catch(() => void 0);
319
+ }
320
+ function createRetryingFetch(options, dependencies = {}) {
321
+ const attemptFetch = dependencies.fetch ?? globalFetch;
322
+ const wait = dependencies.sleep ?? sleep;
323
+ return async (request, init) => {
324
+ for (let attempt = 0; ; attempt++) {
325
+ let outcome;
326
+ try {
327
+ outcome = { response: await attemptFetch(request.clone(), init) };
328
+ } catch (error) {
329
+ outcome = { error };
204
330
  }
331
+ const decision = attempt < options.maxRetries ? await decideRetry(request, outcome, attempt, options) : { retry: false };
332
+ if (!decision.retry) {
333
+ if ("error" in outcome) throw outcome.error;
334
+ return outcome.response;
335
+ }
336
+ if ("response" in outcome) await discard(outcome.response);
337
+ await wait(decision.delayMs, request.signal ?? void 0);
205
338
  }
206
339
  };
207
340
  }
@@ -209,20 +342,22 @@ function createRetryMiddleware(options) {
209
342
  // src/http/client.ts
210
343
  function createBeeLClient(config) {
211
344
  const client = (0, import_openapi_fetch.default)({
212
- baseUrl: config.baseUrl ?? "https://app.beel.es/api",
345
+ baseUrl: config.baseUrl ?? DEFAULT_BASE_URL,
213
346
  headers: {
214
- Authorization: `Bearer ${config.apiKey}`
215
- }
347
+ [AUTHORIZATION_HEADER]: `Bearer ${config.apiKey}`
348
+ },
349
+ fetch: createRetryingFetch({
350
+ maxRetries: config.maxRetries ?? DEFAULT_MAX_RETRIES,
351
+ initialDelayMs: config.retryDelayMs ?? DEFAULT_RETRY_DELAY_MS,
352
+ maxDelayMs: config.maxRetryDelayMs ?? DEFAULT_MAX_RETRY_DELAY_MS
353
+ })
216
354
  });
217
- client.use(requestMiddleware);
218
- client.use(errorMiddleware);
219
355
  client.use(
220
- createRetryMiddleware({
221
- maxRetries: config.maxRetries ?? 3,
222
- initialDelayMs: config.retryDelayMs ?? 500,
223
- maxDelayMs: config.maxRetryDelayMs ?? 3e4
356
+ createRequestMiddleware({
357
+ autoIdempotencyKey: config.autoIdempotencyKey ?? DEFAULT_AUTO_IDEMPOTENCY_KEY
224
358
  })
225
359
  );
360
+ client.use(errorMiddleware);
226
361
  return client;
227
362
  }
228
363
 
@@ -234,6 +369,9 @@ var InvoicesResource = class {
234
369
  /**
235
370
  * List invoices with optional filters and pagination.
236
371
  *
372
+ * @param params - Filters and pagination.
373
+ * @returns The page of `invoices` and its `pagination`.
374
+ *
237
375
  * @example
238
376
  * const { invoices, pagination } = await beel.invoices.list({ status: 'ISSUED', limit: 20 });
239
377
  */
@@ -244,6 +382,9 @@ var InvoicesResource = class {
244
382
  /**
245
383
  * Create a new invoice. An idempotency key is automatically added.
246
384
  *
385
+ * @param body - Type, recipient and lines.
386
+ * @returns The created invoice.
387
+ *
247
388
  * @example
248
389
  * const invoice = await beel.invoices.create({
249
390
  * type: 'STANDARD',
@@ -255,28 +396,52 @@ var InvoicesResource = class {
255
396
  const { data } = await this.client.POST("/v1/invoices", { body });
256
397
  return data.data;
257
398
  }
258
- /** Get an invoice by ID. */
399
+ /**
400
+ * Get an invoice by ID.
401
+ *
402
+ * @param id - Invoice UUID.
403
+ * @returns The invoice.
404
+ */
259
405
  async get(id) {
260
406
  const { data } = await this.client.GET("/v1/invoices/{invoice_id}", { params: { path: { invoice_id: id } } });
261
407
  return data.data;
262
408
  }
263
- /** Update a draft invoice. Only draft invoices can be updated. */
409
+ /**
410
+ * Update a draft invoice. Only draft invoices can be updated.
411
+ *
412
+ * @param id - Invoice UUID.
413
+ * @param body - The draft's new content.
414
+ * @returns The updated invoice.
415
+ */
264
416
  async update(id, body) {
265
417
  const { data } = await this.client.PUT("/v1/invoices/{invoice_id}", { params: { path: { invoice_id: id } }, body });
266
418
  return data.data;
267
419
  }
268
- /** Delete a draft invoice. Only draft invoices can be deleted. */
420
+ /**
421
+ * Delete a draft invoice. Only draft invoices can be deleted.
422
+ *
423
+ * @param id - Invoice UUID.
424
+ */
269
425
  async delete(id) {
270
426
  await this.client.DELETE("/v1/invoices/{invoice_id}", { params: { path: { invoice_id: id } } });
271
427
  }
272
- /** Duplicate an invoice, optionally into a different series. */
428
+ /**
429
+ * Duplicate an invoice, optionally into a different series.
430
+ *
431
+ * @param id - Invoice UUID.
432
+ * @param options - `series_id` and `notes` of the copy.
433
+ * @returns The new draft.
434
+ */
273
435
  async duplicate(id, options) {
274
436
  const { data } = await this.client.POST("/v1/invoices/{invoice_id}/duplicate", { params: { path: { invoice_id: id } }, body: options });
275
437
  return data.data;
276
438
  }
277
439
  /**
278
440
  * Issue a draft invoice. Assigns an invoice number and triggers VeriFactu submission.
279
- * @param options.wait_for_pdf - If true, waits for PDF generation before returning.
441
+ *
442
+ * @param id - Invoice UUID.
443
+ * @param options - `wait_for_pdf: true` to wait for the PDF.
444
+ * @returns The issued invoice.
280
445
  */
281
446
  async issue(id, options) {
282
447
  const { data } = await this.client.POST("/v1/invoices/{invoice_id}/issue", { params: { path: { invoice_id: id }, query: options } });
@@ -284,19 +449,32 @@ var InvoicesResource = class {
284
449
  }
285
450
  /**
286
451
  * Mark an invoice as paid.
287
- * @param options.payment_date - Payment date (defaults to today).
288
- * @param options.payment_method - Payment method details.
452
+ *
453
+ * @param id - Invoice UUID.
454
+ * @param options - `payment_date` (default: today) and `payment_method`.
455
+ * @returns The paid invoice.
289
456
  */
290
457
  async markPaid(id, options) {
291
458
  const { data } = await this.client.POST("/v1/invoices/{invoice_id}/mark-paid", { params: { path: { invoice_id: id } }, body: options });
292
459
  return data.data;
293
460
  }
294
- /** Mark an invoice as sent (e.g. delivered by other means). */
461
+ /**
462
+ * Mark an invoice as sent (e.g. delivered by other means).
463
+ *
464
+ * @param id - Invoice UUID.
465
+ * @param options - `sent_at`.
466
+ * @returns The sent invoice.
467
+ */
295
468
  async markSent(id, options) {
296
469
  const { data } = await this.client.POST("/v1/invoices/{invoice_id}/mark-sent", { params: { path: { invoice_id: id } }, body: options });
297
470
  return data.data;
298
471
  }
299
- /** Revert a paid/sent invoice back to issued status. */
472
+ /**
473
+ * Revert a paid/sent invoice back to issued status.
474
+ *
475
+ * @param id - Invoice UUID.
476
+ * @returns The invoice, back in `ISSUED`.
477
+ */
300
478
  async revertToIssued(id) {
301
479
  const { data } = await this.client.POST("/v1/invoices/{invoice_id}/revert-to-issued", { params: { path: { invoice_id: id } } });
302
480
  return data.data;
@@ -304,6 +482,10 @@ var InvoicesResource = class {
304
482
  /**
305
483
  * Void an issued invoice. Requires a reason (min 10 chars).
306
484
  *
485
+ * @param id - Invoice UUID.
486
+ * @param params - `reason` (min 10 characters) and optional `void_date`.
487
+ * @returns The voided invoice.
488
+ *
307
489
  * @example
308
490
  * await beel.invoices.void('id', { reason: 'Duplicate invoice sent in error' });
309
491
  */
@@ -311,22 +493,45 @@ var InvoicesResource = class {
311
493
  const { data } = await this.client.POST("/v1/invoices/{invoice_id}/void", { params: { path: { invoice_id: id } }, body: params });
312
494
  return data.data;
313
495
  }
314
- /** Create a corrective invoice that references the original. */
496
+ /**
497
+ * Create a corrective invoice that references the original.
498
+ *
499
+ * @param id - UUID of the issued invoice to correct.
500
+ * @param body - Rectification type, code, reason and lines.
501
+ * @returns The corrective invoice.
502
+ */
315
503
  async createCorrective(id, body) {
316
504
  const { data } = await this.client.POST("/v1/invoices/{invoice_id}/corrective", { params: { path: { invoice_id: id } }, body });
317
505
  return data.data;
318
506
  }
319
- /** Schedule a draft invoice to be issued on a future date. */
507
+ /**
508
+ * Schedule a draft invoice to be issued on a future date.
509
+ *
510
+ * @param id - UUID of the draft.
511
+ * @param params - `scheduled_for` and optional `action`.
512
+ * @returns The scheduled invoice.
513
+ */
320
514
  async schedule(id, params) {
321
515
  const { data } = await this.client.POST("/v1/invoices/{invoice_id}/schedule", { params: { path: { invoice_id: id } }, body: params });
322
516
  return data.data;
323
517
  }
324
- /** Cancel a scheduled invoice, returning it to draft. */
518
+ /**
519
+ * Cancel a scheduled invoice, returning it to draft.
520
+ *
521
+ * @param id - Invoice UUID.
522
+ * @returns The invoice, back in draft.
523
+ */
325
524
  async unschedule(id) {
326
525
  const { data } = await this.client.POST("/v1/invoices/{invoice_id}/unschedule", { params: { path: { invoice_id: id } } });
327
526
  return data.data;
328
527
  }
329
- /** Change the scheduled date of a scheduled invoice. */
528
+ /**
529
+ * Change the scheduled date of a scheduled invoice.
530
+ *
531
+ * @param id - Invoice UUID.
532
+ * @param params - New `scheduled_for`.
533
+ * @returns The rescheduled invoice.
534
+ */
330
535
  async reschedule(id, params) {
331
536
  const { data } = await this.client.PATCH("/v1/invoices/{invoice_id}/reschedule", { params: { path: { invoice_id: id } }, body: params });
332
537
  return data.data;
@@ -334,12 +539,21 @@ var InvoicesResource = class {
334
539
  /**
335
540
  * Get a pre-signed URL to download the invoice PDF.
336
541
  * The URL expires in 5 minutes. Use `beel.downloadPdf(id)` for a simpler Buffer download.
542
+ *
543
+ * @param id - Invoice UUID.
544
+ * @returns `download_url`, `expires_in_seconds` and `file_name`.
337
545
  */
338
546
  async getPdf(id) {
339
547
  const { data } = await this.client.GET("/v1/invoices/{invoice_id}/pdf", { params: { path: { invoice_id: id } } });
340
548
  return data.data;
341
549
  }
342
- /** Send an invoice by email. Uses the customer's email by default. */
550
+ /**
551
+ * Send an invoice by email. Uses the customer's email by default.
552
+ *
553
+ * @param id - Invoice UUID.
554
+ * @param options - Recipients, subject and message.
555
+ * @returns The delivery record.
556
+ */
343
557
  async sendEmail(id, options) {
344
558
  const { data } = await this.client.POST("/v1/invoices/{invoice_id}/send", { params: { path: { invoice_id: id } }, body: options });
345
559
  return data.data;
@@ -354,6 +568,9 @@ var CustomersResource = class {
354
568
  /**
355
569
  * List customers with optional filters and pagination.
356
570
  *
571
+ * @param params - Filters and pagination.
572
+ * @returns The page of `customers` and its `pagination`.
573
+ *
357
574
  * @example
358
575
  * const { customers, pagination } = await beel.customers.list({ search: 'Acme', limit: 10 });
359
576
  */
@@ -364,6 +581,9 @@ var CustomersResource = class {
364
581
  /**
365
582
  * Create a new customer.
366
583
  *
584
+ * @param body - Legal name, NIF and address.
585
+ * @returns The created customer.
586
+ *
367
587
  * @example
368
588
  * const customer = await beel.customers.create({
369
589
  * legal_name: 'Acme SL',
@@ -375,17 +595,32 @@ var CustomersResource = class {
375
595
  const { data } = await this.client.POST("/v1/customers", { body });
376
596
  return data.data;
377
597
  }
378
- /** Get a customer by ID. */
598
+ /**
599
+ * Get a customer by ID.
600
+ *
601
+ * @param id - Customer UUID.
602
+ * @returns The customer.
603
+ */
379
604
  async get(id) {
380
605
  const { data } = await this.client.GET("/v1/customers/{customer_id}", { params: { path: { customer_id: id } } });
381
606
  return data.data;
382
607
  }
383
- /** Update a customer. Only provided fields are changed. */
608
+ /**
609
+ * Update a customer. Only provided fields are changed.
610
+ *
611
+ * @param id - Customer UUID.
612
+ * @param body - Fields to change.
613
+ * @returns The updated customer.
614
+ */
384
615
  async update(id, body) {
385
616
  const { data } = await this.client.PUT("/v1/customers/{customer_id}", { params: { path: { customer_id: id } }, body });
386
617
  return data.data;
387
618
  }
388
- /** Deactivate (soft-delete) a customer. */
619
+ /**
620
+ * Deactivate (soft-delete) a customer.
621
+ *
622
+ * @param id - Customer UUID.
623
+ */
389
624
  async deactivate(id) {
390
625
  await this.client.DELETE("/v1/customers/{customer_id}", { params: { path: { customer_id: id } } });
391
626
  }
@@ -399,6 +634,9 @@ var ProductsResource = class {
399
634
  /**
400
635
  * List products with optional filters and pagination.
401
636
  *
637
+ * @param params - Filters and pagination.
638
+ * @returns The page of `products` and its `pagination`.
639
+ *
402
640
  * @example
403
641
  * const { products, pagination } = await beel.products.list({ category: 'SERVICE' });
404
642
  */
@@ -409,6 +647,9 @@ var ProductsResource = class {
409
647
  /**
410
648
  * Create a new product or service.
411
649
  *
650
+ * @param body - Name, category, price and main tax.
651
+ * @returns The created product.
652
+ *
412
653
  * @example
413
654
  * const product = await beel.products.create({
414
655
  * name: 'Consulting',
@@ -422,23 +663,42 @@ var ProductsResource = class {
422
663
  const { data } = await this.client.POST("/v1/products", { body });
423
664
  return data.data;
424
665
  }
425
- /** Get a product by ID. */
666
+ /**
667
+ * Get a product by ID.
668
+ *
669
+ * @param id - Product UUID.
670
+ * @returns The product.
671
+ */
426
672
  async get(id) {
427
673
  const { data } = await this.client.GET("/v1/products/{product_id}", { params: { path: { product_id: id } } });
428
674
  return data.data;
429
675
  }
430
- /** Update a product. Only provided fields are changed. */
676
+ /**
677
+ * Update a product. Only provided fields are changed.
678
+ *
679
+ * @param id - Product UUID.
680
+ * @param body - Fields to change.
681
+ * @returns The updated product.
682
+ */
431
683
  async update(id, body) {
432
684
  const { data } = await this.client.PUT("/v1/products/{product_id}", { params: { path: { product_id: id } }, body });
433
685
  return data.data;
434
686
  }
435
- /** Delete a product permanently. */
687
+ /**
688
+ * Delete a product permanently.
689
+ *
690
+ * @param id - Product UUID.
691
+ */
436
692
  async delete(id) {
437
693
  await this.client.DELETE("/v1/products/{product_id}", { params: { path: { product_id: id } } });
438
694
  }
439
695
  /**
440
696
  * Search products by name or code. Returns up to `limit` results.
441
697
  *
698
+ * @param q - Text to search in name or code.
699
+ * @param limit - Maximum results.
700
+ * @returns The matching products, as a bare array.
701
+ *
442
702
  * @example
443
703
  * const results = await beel.products.search('consulting', 5);
444
704
  */
@@ -453,37 +713,68 @@ var ConfigurationResource = class {
453
713
  constructor(client) {
454
714
  this.client = client;
455
715
  }
456
- /** Get the current tax configuration (default VAT, IRPF, etc.). */
716
+ /**
717
+ * Get the tax configuration (default VAT, IRPF…) of the focused company.
718
+ *
719
+ * @returns The tax configuration.
720
+ */
457
721
  async getTaxConfig() {
458
722
  const { data } = await this.client.GET("/v1/configuration/taxes");
459
723
  return data.data;
460
724
  }
461
- /** Update tax configuration. */
725
+ /**
726
+ * Replace the tax configuration of the focused company.
727
+ *
728
+ * @param body - The complete tax configuration.
729
+ * @returns The stored configuration.
730
+ */
462
731
  async updateTaxConfig(body) {
463
732
  const { data } = await this.client.PUT("/v1/configuration/taxes", { body });
464
733
  return data.data;
465
734
  }
466
- /** Get available tax types (IVA/IGIC rates, IRPF types, equivalence surcharges). */
735
+ /**
736
+ * Tax types the API accepts (IVA/IGIC rates, IRPF types, equivalence surcharges).
737
+ *
738
+ * @returns The tax types catalog.
739
+ */
467
740
  async getTaxTypes() {
468
741
  const { data } = await this.client.GET("/v1/configuration/tax-types");
469
742
  return data.data;
470
743
  }
471
- /** Get invoice customization options (logo, colors, footer text, etc.). */
744
+ /**
745
+ * Invoice customization options (templates, colors…).
746
+ *
747
+ * @returns The customization options.
748
+ */
472
749
  async getInvoiceCustomizationOptions() {
473
750
  const { data } = await this.client.GET("/v1/configuration/invoice-customization-options");
474
751
  return data.data;
475
752
  }
476
- /** Update the user's preferred language (es, en, ca). */
753
+ /**
754
+ * Update the preferred language of the signed-in person.
755
+ *
756
+ * @param language - `es`, `en` or `ca`.
757
+ * @returns The updated preferences.
758
+ */
477
759
  async updateLanguage(language) {
478
760
  const { data } = await this.client.PUT("/v1/configuration/language", { body: { language } });
479
761
  return data.data;
480
762
  }
481
- /** Get VeriFactu configuration (enabled, certificate status, etc.). */
763
+ /**
764
+ * Get the VeriFactu configuration of the focused company.
765
+ *
766
+ * @returns The VeriFactu configuration.
767
+ */
482
768
  async getVerifactu() {
483
769
  const { data } = await this.client.GET("/v1/configuration/verifactu");
484
770
  return data.data;
485
771
  }
486
- /** Update VeriFactu configuration. */
772
+ /**
773
+ * Update the VeriFactu configuration of the focused company.
774
+ *
775
+ * @param body - `{ enabled }`.
776
+ * @returns The updated configuration.
777
+ */
487
778
  async updateVerifactu(body) {
488
779
  const { data } = await this.client.PUT("/v1/configuration/verifactu", { body });
489
780
  return data.data;
@@ -493,19 +784,47 @@ var CatalogsResource = class {
493
784
  constructor(client) {
494
785
  this.client = client;
495
786
  }
496
- /** Tax types the API accepts. Canonical form of `configuration/tax-types`. */
787
+ /**
788
+ * Who the API key belongs to: its `account_id` — the starting point to list the
789
+ * account's companies — plus the person's email, name and language, and the credential.
790
+ * Needs no scope, so it also confirms that a key works.
791
+ *
792
+ * @returns The identity of the credential.
793
+ *
794
+ * @example
795
+ * ```typescript
796
+ * const { account_id } = await beel.catalogs.identity();
797
+ * const { companies } = await beel.account(account_id).companies.list();
798
+ * ```
799
+ */
800
+ async identity() {
801
+ const { data } = await this.client.GET("/v1/me/identity");
802
+ return data.data;
803
+ }
804
+ /**
805
+ * Tax types the API accepts. Canonical form of `configuration/tax-types`.
806
+ *
807
+ * @returns The tax types catalog.
808
+ */
497
809
  async taxTypes() {
498
810
  const { data } = await this.client.GET("/v1/tax-types");
499
811
  return data.data;
500
812
  }
501
- /** Invoice customization options. Canonical form of the `configuration` read. */
813
+ /**
814
+ * Invoice PDF templates and customization options. Canonical form of the `configuration` read.
815
+ *
816
+ * @returns The customization options.
817
+ */
502
818
  async invoiceCustomizationOptions() {
503
819
  const { data } = await this.client.GET("/v1/invoice-customization-options");
504
820
  return data.data;
505
821
  }
506
822
  /**
507
- * The signed-in person's preferences. Canonical form of
823
+ * Update the signed-in person's preferences. Canonical form of
508
824
  * `PUT /v1/configuration/language`: the language belongs to the person, not to a company.
825
+ *
826
+ * @param body - Preferences to change, e.g. `{ language: 'es' }`.
827
+ * @returns The updated preferences.
509
828
  */
510
829
  async updateMe(body) {
511
830
  const { data } = await this.client.PATCH("/v1/me", { body });
@@ -521,6 +840,9 @@ var SeriesResource = class {
521
840
  /**
522
841
  * List all invoice series. Optionally filter by active status.
523
842
  *
843
+ * @param active - Only active (`true`) or inactive (`false`) series; all when omitted.
844
+ * @returns The series.
845
+ *
524
846
  * @example
525
847
  * const series = await beel.series.list();
526
848
  * const activeSeries = await beel.series.list(true);
@@ -531,12 +853,23 @@ var SeriesResource = class {
531
853
  });
532
854
  return data.data;
533
855
  }
534
- /** Create a new invoice series (e.g. "A-2026", "RECT"). */
856
+ /**
857
+ * Create a new invoice series (e.g. "A-2026", "RECT").
858
+ *
859
+ * @param body - Code, name and format.
860
+ * @returns The created series.
861
+ */
535
862
  async create(body) {
536
863
  const { data } = await this.client.POST("/v1/configuration/series", { body });
537
864
  return data.data;
538
865
  }
539
- /** Update a series (name, description, etc.). */
866
+ /**
867
+ * Update a series (name, description, etc.).
868
+ *
869
+ * @param id - Series UUID.
870
+ * @param body - Fields to change.
871
+ * @returns The updated series.
872
+ */
540
873
  async update(id, body) {
541
874
  const { data } = await this.client.PUT("/v1/configuration/series/{series_id}", {
542
875
  params: { path: { series_id: id } },
@@ -544,13 +877,22 @@ var SeriesResource = class {
544
877
  });
545
878
  return data.data;
546
879
  }
547
- /** Delete an invoice series. Only empty series can be deleted. */
880
+ /**
881
+ * Delete an invoice series. Only empty series can be deleted.
882
+ *
883
+ * @param id - Series UUID.
884
+ */
548
885
  async delete(id) {
549
886
  await this.client.DELETE("/v1/configuration/series/{series_id}", {
550
887
  params: { path: { series_id: id } }
551
888
  });
552
889
  }
553
- /** Set a series as the default for new invoices. */
890
+ /**
891
+ * Set a series as the default for new invoices.
892
+ *
893
+ * @param id - Series UUID.
894
+ * @returns The series.
895
+ */
554
896
  async setDefault(id) {
555
897
  const { data } = await this.client.POST("/v1/configuration/series/{series_id}/default", {
556
898
  params: { path: { series_id: id } }
@@ -567,6 +909,9 @@ var NifResource = class {
567
909
  /**
568
910
  * Validate a Spanish NIF/CIF against the AEAT tax registry.
569
911
  *
912
+ * @param nif - The NIF/CIF to validate.
913
+ * @returns Whether it is valid and, when the register knows it, its holder's name.
914
+ *
570
915
  * @example
571
916
  * const result = await beel.nif.validate('B12345678');
572
917
  * console.log(result.valid, result.name);
@@ -582,27 +927,47 @@ var AccountsResource = class {
582
927
  constructor(client) {
583
928
  this.client = client;
584
929
  }
585
- /** List accounts reachable with this API key (cursor-paginated). */
930
+ /**
931
+ * List the accounts you provisioned, newest first. Cursor-paginated: pass the
932
+ * `next_cursor` of one page as `cursor` of the next until it is `null`.
933
+ *
934
+ * @param params - `status`, `external_ref` (exact), `limit`, `cursor`.
935
+ * @returns The `accounts` of the page and `next_cursor`.
936
+ */
586
937
  async list(params) {
587
938
  const { data } = await this.client.GET("/v1/accounts", { params: { query: params } });
588
939
  return data.data;
589
940
  }
590
941
  /**
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.
942
+ * Provision a new managed account. Idempotent by `external_ref`: sending the same one
943
+ * again returns the same account. Answers with the provisioning result — the account id,
944
+ * its status and, when one is issued, the claim link — not with the account summary.
945
+ *
946
+ * @param body - `external_ref` and the holder's details.
947
+ * @returns `account_id`, `status` and the claim link state.
593
948
  */
594
949
  async provision(body) {
595
950
  const { data } = await this.client.POST("/v1/accounts", { body });
596
951
  return data.data;
597
952
  }
598
- /** Get a managed account by ID. */
953
+ /**
954
+ * Get a managed account.
955
+ *
956
+ * @param accountId - Account UUID.
957
+ * @returns The account summary.
958
+ */
599
959
  async get(accountId) {
600
960
  const { data } = await this.client.GET("/v1/accounts/{account_id}", {
601
961
  params: { path: { account_id: accountId } }
602
962
  });
603
963
  return data.data;
604
964
  }
605
- /** Alias of `beel.account(accountId)` — returns an account-scoped facade. */
965
+ /**
966
+ * Alias of `beel.account(accountId)`: the operations scoped to one account.
967
+ *
968
+ * @param accountId - Account UUID.
969
+ * @returns The account scope. No request is made.
970
+ */
606
971
  scope(accountId) {
607
972
  return new AccountScope(this.client, accountId);
608
973
  }
@@ -619,28 +984,49 @@ var AccountScope = class {
619
984
  path() {
620
985
  return { account_id: this.accountId };
621
986
  }
622
- /** Get the account summary. */
987
+ /**
988
+ * Get the account summary.
989
+ *
990
+ * @returns The account summary.
991
+ */
623
992
  async get() {
624
993
  const { data } = await this.client.GET("/v1/accounts/{account_id}", { params: { path: this.path() } });
625
994
  return data.data;
626
995
  }
627
- /** Provisioning usage counters (accounts, NIFs) for billing purposes. */
996
+ /**
997
+ * Provisioning usage counters for billing: provisioned accounts and NIFs.
998
+ *
999
+ * @returns `provisioned_accounts` and `nifs`.
1000
+ */
628
1001
  async usage() {
629
1002
  const { data } = await this.client.GET("/v1/accounts/{account_id}/usage", { params: { path: this.path() } });
630
1003
  return data.data;
631
1004
  }
632
- /** Change the manager's access level over this account. */
1005
+ /**
1006
+ * Change the access level you keep over this account. Raising it is only possible while
1007
+ * the account is unclaimed.
1008
+ *
1009
+ * @param body - The new `access_level`.
1010
+ */
633
1011
  async changeAccessLevel(body) {
634
1012
  await this.client.PATCH("/v1/accounts/{account_id}/access-level", {
635
1013
  params: { path: this.path() },
636
1014
  body
637
1015
  });
638
1016
  }
639
- /** End the management relationship with this account. */
1017
+ /**
1018
+ * End your management of this account: you lose access, and the holder keeps the
1019
+ * account, its NIFs and its invoices.
1020
+ */
640
1021
  async endManagement() {
641
1022
  await this.client.DELETE("/v1/accounts/{account_id}/management", { params: { path: this.path() } });
642
1023
  }
643
- /** Create a claim token so the end user can take ownership of the account. */
1024
+ /**
1025
+ * Issue a single-use claim token so the account's holder can take ownership.
1026
+ *
1027
+ * @param body - `email` when the account has no holder yet; omit to re-issue.
1028
+ * @returns `claim_token`, `claim_url` and `expires_at`.
1029
+ */
644
1030
  async createClaimToken(body) {
645
1031
  const { data } = await this.client.POST("/v1/accounts/{account_id}/claim-tokens", {
646
1032
  params: { path: this.path() },
@@ -648,7 +1034,11 @@ var AccountScope = class {
648
1034
  });
649
1035
  return data.data;
650
1036
  }
651
- /** Transfer account ownership to an existing member. */
1037
+ /**
1038
+ * Make an existing member the account's owner. Repeatable: it states the desired owner.
1039
+ *
1040
+ * @param body - The member that becomes owner.
1041
+ */
652
1042
  async setOwner(body) {
653
1043
  await this.client.PUT("/v1/accounts/{account_id}/owner", {
654
1044
  params: { path: this.path() },
@@ -661,19 +1051,36 @@ var AccountMembersResource = class {
661
1051
  this.client = client;
662
1052
  this.accountId = accountId;
663
1053
  }
1054
+ /**
1055
+ * List the account's members.
1056
+ *
1057
+ * @returns The members (`data.members` of the response), as an array.
1058
+ */
664
1059
  async list() {
665
1060
  const { data } = await this.client.GET("/v1/accounts/{account_id}/members", {
666
1061
  params: { path: { account_id: this.accountId } }
667
1062
  });
668
1063
  return data.data.members;
669
1064
  }
1065
+ /**
1066
+ * Get one member.
1067
+ *
1068
+ * @param memberId - Member UUID.
1069
+ * @returns The member.
1070
+ */
670
1071
  async get(memberId) {
671
1072
  const { data } = await this.client.GET("/v1/accounts/{account_id}/members/{member_id}", {
672
1073
  params: { path: { account_id: this.accountId, member_id: memberId } }
673
1074
  });
674
1075
  return data.data;
675
1076
  }
676
- /** Update a member's account role. */
1077
+ /**
1078
+ * Change a member's account role.
1079
+ *
1080
+ * @param memberId - Member UUID.
1081
+ * @param body - The new `account_role`.
1082
+ * @returns The updated member.
1083
+ */
677
1084
  async update(memberId, body) {
678
1085
  const { data } = await this.client.PATCH("/v1/accounts/{account_id}/members/{member_id}", {
679
1086
  params: { path: { account_id: this.accountId, member_id: memberId } },
@@ -681,20 +1088,36 @@ var AccountMembersResource = class {
681
1088
  });
682
1089
  return data.data;
683
1090
  }
684
- /** Remove a member from the account. */
1091
+ /**
1092
+ * Remove a member from the account.
1093
+ *
1094
+ * @param memberId - Member UUID.
1095
+ */
685
1096
  async remove(memberId) {
686
1097
  await this.client.DELETE("/v1/accounts/{account_id}/members/{member_id}", {
687
1098
  params: { path: { account_id: this.accountId, member_id: memberId } }
688
1099
  });
689
1100
  }
690
- /** List a member's per-company grants. */
1101
+ /**
1102
+ * List a member's per-company grants.
1103
+ *
1104
+ * @param memberId - Member UUID.
1105
+ * @returns The `grants` and their `pagination`.
1106
+ */
691
1107
  async listGrants(memberId) {
692
1108
  const { data } = await this.client.GET("/v1/accounts/{account_id}/members/{member_id}/grants", {
693
1109
  params: { path: { account_id: this.accountId, member_id: memberId } }
694
1110
  });
695
1111
  return data.data;
696
1112
  }
697
- /** Grant (or replace) a member's permissions over one company. */
1113
+ /**
1114
+ * Grant a member access to one company, or replace the grant it has.
1115
+ *
1116
+ * @param memberId - Member UUID.
1117
+ * @param companyId - Company UUID.
1118
+ * @param body - The `access_level` to grant.
1119
+ * @returns The grant.
1120
+ */
698
1121
  async putGrant(memberId, companyId, body) {
699
1122
  const { data } = await this.client.PUT("/v1/accounts/{account_id}/members/{member_id}/grants/{company_id}", {
700
1123
  params: { path: { account_id: this.accountId, member_id: memberId, company_id: companyId } },
@@ -702,7 +1125,12 @@ var AccountMembersResource = class {
702
1125
  });
703
1126
  return data.data;
704
1127
  }
705
- /** Revoke a member's grant over one company. */
1128
+ /**
1129
+ * Revoke a member's access to one company.
1130
+ *
1131
+ * @param memberId - Member UUID.
1132
+ * @param companyId - Company UUID.
1133
+ */
706
1134
  async removeGrant(memberId, companyId) {
707
1135
  await this.client.DELETE("/v1/accounts/{account_id}/members/{member_id}/grants/{company_id}", {
708
1136
  params: { path: { account_id: this.accountId, member_id: memberId, company_id: companyId } }
@@ -714,12 +1142,23 @@ var AccountInvitationsResource = class {
714
1142
  this.client = client;
715
1143
  this.accountId = accountId;
716
1144
  }
1145
+ /**
1146
+ * List the account's invitations.
1147
+ *
1148
+ * @returns The invitations.
1149
+ */
717
1150
  async list() {
718
1151
  const { data } = await this.client.GET("/v1/accounts/{account_id}/invitations", {
719
1152
  params: { path: { account_id: this.accountId } }
720
1153
  });
721
1154
  return data.data;
722
1155
  }
1156
+ /**
1157
+ * Invite someone to join the account.
1158
+ *
1159
+ * @param body - `invited_email` and the `account_role` to grant.
1160
+ * @returns The invitation.
1161
+ */
723
1162
  async create(body) {
724
1163
  const { data } = await this.client.POST("/v1/accounts/{account_id}/invitations", {
725
1164
  params: { path: { account_id: this.accountId } },
@@ -727,12 +1166,23 @@ var AccountInvitationsResource = class {
727
1166
  });
728
1167
  return data.data;
729
1168
  }
1169
+ /**
1170
+ * Get one invitation.
1171
+ *
1172
+ * @param invitationId - Invitation UUID.
1173
+ * @returns The invitation.
1174
+ */
730
1175
  async get(invitationId) {
731
1176
  const { data } = await this.client.GET("/v1/accounts/{account_id}/invitations/{invitation_id}", {
732
1177
  params: { path: { account_id: this.accountId, invitation_id: invitationId } }
733
1178
  });
734
1179
  return data.data;
735
1180
  }
1181
+ /**
1182
+ * Revoke a `PENDING` invitation, so its link stops working.
1183
+ *
1184
+ * @param invitationId - Invitation UUID.
1185
+ */
736
1186
  async revoke(invitationId) {
737
1187
  await this.client.DELETE("/v1/accounts/{account_id}/invitations/{invitation_id}", {
738
1188
  params: { path: { account_id: this.accountId, invitation_id: invitationId } }
@@ -744,12 +1194,24 @@ var AccountWebhooksResource = class {
744
1194
  this.client = client;
745
1195
  this.accountId = accountId;
746
1196
  }
1197
+ /**
1198
+ * List the webhook subscriptions.
1199
+ *
1200
+ * @param params - Pagination.
1201
+ * @returns The `webhooks` and their `pagination`.
1202
+ */
747
1203
  async list(params) {
748
1204
  const { data } = await this.client.GET("/v1/accounts/{account_id}/webhooks", {
749
1205
  params: { path: { account_id: this.accountId }, query: params }
750
1206
  });
751
1207
  return data.data;
752
1208
  }
1209
+ /**
1210
+ * Subscribe an HTTPS endpoint to events.
1211
+ *
1212
+ * @param body - `url` and the `events` to receive.
1213
+ * @returns The subscription, with its signing secret.
1214
+ */
753
1215
  async create(body) {
754
1216
  const { data } = await this.client.POST("/v1/accounts/{account_id}/webhooks", {
755
1217
  params: { path: { account_id: this.accountId } },
@@ -757,12 +1219,25 @@ var AccountWebhooksResource = class {
757
1219
  });
758
1220
  return data.data;
759
1221
  }
1222
+ /**
1223
+ * Get one webhook subscription.
1224
+ *
1225
+ * @param webhookId - Subscription UUID.
1226
+ * @returns The subscription.
1227
+ */
760
1228
  async get(webhookId) {
761
1229
  const { data } = await this.client.GET("/v1/accounts/{account_id}/webhooks/{webhook_id}", {
762
1230
  params: { path: { account_id: this.accountId, webhook_id: webhookId } }
763
1231
  });
764
1232
  return data.data;
765
1233
  }
1234
+ /**
1235
+ * Update a webhook subscription. Only the fields present in `body` change.
1236
+ *
1237
+ * @param webhookId - Subscription UUID.
1238
+ * @param body - Fields to change.
1239
+ * @returns The updated subscription.
1240
+ */
766
1241
  async update(webhookId, body) {
767
1242
  const { data } = await this.client.PATCH("/v1/accounts/{account_id}/webhooks/{webhook_id}", {
768
1243
  params: { path: { account_id: this.accountId, webhook_id: webhookId } },
@@ -770,31 +1245,60 @@ var AccountWebhooksResource = class {
770
1245
  });
771
1246
  return data.data;
772
1247
  }
1248
+ /**
1249
+ * Delete a webhook subscription.
1250
+ *
1251
+ * @param webhookId - Subscription UUID.
1252
+ */
773
1253
  async delete(webhookId) {
774
1254
  await this.client.DELETE("/v1/accounts/{account_id}/webhooks/{webhook_id}", {
775
1255
  params: { path: { account_id: this.accountId, webhook_id: webhookId } }
776
1256
  });
777
1257
  }
778
- /** Send a test event to the webhook endpoint. */
1258
+ /**
1259
+ * Send a test event to the endpoint. Test deliveries carry `test: true`.
1260
+ *
1261
+ * @param webhookId - Subscription UUID.
1262
+ * @returns The outcome of the delivery.
1263
+ */
779
1264
  async test(webhookId) {
780
1265
  const { data } = await this.client.POST("/v1/accounts/{account_id}/webhooks/{webhook_id}/test", {
781
1266
  params: { path: { account_id: this.accountId, webhook_id: webhookId } }
782
1267
  });
783
1268
  return data.data;
784
1269
  }
785
- /** Rotate the webhook signing secret. */
1270
+ /**
1271
+ * Rotate the signing secret. The old secret stops working immediately.
1272
+ *
1273
+ * @param webhookId - Subscription UUID.
1274
+ * @returns The subscription with its new secret.
1275
+ */
786
1276
  async rotateSecret(webhookId) {
787
1277
  const { data } = await this.client.POST("/v1/accounts/{account_id}/webhooks/{webhook_id}/secret", {
788
1278
  params: { path: { account_id: this.accountId, webhook_id: webhookId } }
789
1279
  });
790
1280
  return data.data;
791
1281
  }
1282
+ /**
1283
+ * List the delivery attempts of a subscription.
1284
+ *
1285
+ * @param webhookId - Subscription UUID.
1286
+ * @param params - Filters and pagination.
1287
+ * @returns The deliveries.
1288
+ */
792
1289
  async listDeliveries(webhookId, params) {
793
1290
  const { data } = await this.client.GET("/v1/accounts/{account_id}/webhooks/{webhook_id}/deliveries", {
794
1291
  params: { path: { account_id: this.accountId, webhook_id: webhookId }, query: params }
795
1292
  });
796
1293
  return data.data;
797
1294
  }
1295
+ /**
1296
+ * Retry a failed delivery.
1297
+ *
1298
+ * @param webhookId - Subscription UUID.
1299
+ * @param deliveryId - Delivery UUID.
1300
+ * @returns The new delivery attempt.
1301
+ */
798
1302
  async retryDelivery(webhookId, deliveryId) {
799
1303
  const { data } = await this.client.POST("/v1/accounts/{account_id}/webhooks/{webhook_id}/deliveries/{delivery_id}/retry", {
800
1304
  params: { path: { account_id: this.accountId, webhook_id: webhookId, delivery_id: deliveryId } }
@@ -807,6 +1311,19 @@ var AccountCompaniesResource = class {
807
1311
  this.client = client;
808
1312
  this.accountId = accountId;
809
1313
  }
1314
+ /**
1315
+ * List the account's companies, primary first. Always paginated (20 by default).
1316
+ *
1317
+ * @param params - `search`, `include`, `page`, `limit`.
1318
+ * @returns The `companies` of the page and its `pagination`.
1319
+ *
1320
+ * @example
1321
+ * ```typescript
1322
+ * const { account_id } = await beel.catalogs.identity();
1323
+ * const { companies } = await beel.account(account_id).companies.list({ search: 'B12345678' });
1324
+ * const company = beel.company(companies[0].id!);
1325
+ * ```
1326
+ */
810
1327
  async list(params) {
811
1328
  const { data } = await this.client.GET("/v1/accounts/{account_id}/companies", {
812
1329
  params: { path: { account_id: this.accountId }, query: params }
@@ -816,7 +1333,12 @@ var AccountCompaniesResource = class {
816
1333
  pagination: data.data?.pagination
817
1334
  };
818
1335
  }
819
- /** Register a new company (NIF) under the account. */
1336
+ /**
1337
+ * Register a new company (NIF) under the account.
1338
+ *
1339
+ * @param body - NIF, legal name, entity type and address.
1340
+ * @returns The created company.
1341
+ */
820
1342
  async create(body) {
821
1343
  const { data } = await this.client.POST("/v1/accounts/{account_id}/companies", {
822
1344
  params: { path: { account_id: this.accountId } },
@@ -824,7 +1346,11 @@ var AccountCompaniesResource = class {
824
1346
  });
825
1347
  return data.data;
826
1348
  }
827
- /** Aggregated per-company stats for the account. */
1349
+ /**
1350
+ * Per-company invoice stats: how many fiscal documents each issued, and when last.
1351
+ *
1352
+ * @returns One entry per company.
1353
+ */
828
1354
  async stats() {
829
1355
  const { data } = await this.client.GET("/v1/accounts/{account_id}/companies/stats", {
830
1356
  params: { path: { account_id: this.accountId } }
@@ -833,6 +1359,38 @@ var AccountCompaniesResource = class {
833
1359
  }
834
1360
  };
835
1361
 
1362
+ // src/http/request-options.ts
1363
+ function anySignal(signals) {
1364
+ const native = AbortSignal.any;
1365
+ if (native) return native(signals);
1366
+ const controller = new AbortController();
1367
+ for (const signal of signals) {
1368
+ if (signal.aborted) {
1369
+ controller.abort(signal.reason);
1370
+ break;
1371
+ }
1372
+ signal.addEventListener("abort", () => controller.abort(signal.reason), { once: true });
1373
+ }
1374
+ return controller.signal;
1375
+ }
1376
+ function signalOf(options) {
1377
+ const signals = [];
1378
+ if (options.signal) signals.push(options.signal);
1379
+ if (options.timeoutMs !== void 0) signals.push(AbortSignal.timeout(options.timeoutMs));
1380
+ if (signals.length <= 1) return signals[0];
1381
+ return anySignal(signals);
1382
+ }
1383
+ function toRequestInit(options) {
1384
+ if (!options) return {};
1385
+ const init = {};
1386
+ if (options.idempotencyKey !== void 0) {
1387
+ init.headers = { [IDEMPOTENCY_KEY_HEADER]: options.idempotencyKey };
1388
+ }
1389
+ const signal = signalOf(options);
1390
+ if (signal) init.signal = signal;
1391
+ return init;
1392
+ }
1393
+
836
1394
  // src/resources/payment-connections.ts
837
1395
  var CompanyPaymentConnectionsResource = class {
838
1396
  constructor(client, companyId) {
@@ -842,7 +1400,11 @@ var CompanyPaymentConnectionsResource = class {
842
1400
  path() {
843
1401
  return { company_id: this.companyId };
844
1402
  }
845
- /** Every payment connection of this company. */
1403
+ /**
1404
+ * Every payment connection of this company.
1405
+ *
1406
+ * @returns The `connections`.
1407
+ */
846
1408
  async list() {
847
1409
  const { data } = await this.client.GET("/v1/companies/{company_id}/payment-connections", {
848
1410
  params: { path: this.path() }
@@ -853,6 +1415,9 @@ var CompanyPaymentConnectionsResource = class {
853
1415
  * Start an authorization and get the URL where the NIF's holder approves it.
854
1416
  *
855
1417
  * This is the one place the provider slug is used — currently only `stripe`.
1418
+ *
1419
+ * @param body - `{ provider: 'stripe' }`, plus the return URL when needed.
1420
+ * @returns The `authorization_url` to send the NIF's holder to.
856
1421
  */
857
1422
  async authorize(body) {
858
1423
  const { data } = await this.client.POST(
@@ -861,7 +1426,13 @@ var CompanyPaymentConnectionsResource = class {
861
1426
  );
862
1427
  return data.data;
863
1428
  }
864
- /** Update one connection, addressed by its UUID. */
1429
+ /**
1430
+ * Update the settings of one connection, addressed by its UUID.
1431
+ *
1432
+ * @param connectionId - Connection UUID, from {@link list}.
1433
+ * @param body - Settings to change.
1434
+ * @returns The updated connection.
1435
+ */
865
1436
  async update(connectionId, body) {
866
1437
  const { data } = await this.client.PATCH(
867
1438
  "/v1/companies/{company_id}/payment-connections/{connection_id}",
@@ -872,13 +1443,20 @@ var CompanyPaymentConnectionsResource = class {
872
1443
  /**
873
1444
  * Disconnect one connection. Tokens are revoked and auto-invoicing stops;
874
1445
  * already-issued invoices are untouched.
1446
+ *
1447
+ * @param connectionId - Connection UUID.
875
1448
  */
876
1449
  async disconnect(connectionId) {
877
1450
  await this.client.DELETE("/v1/companies/{company_id}/payment-connections/{connection_id}", {
878
1451
  params: { path: { ...this.path(), connection_id: connectionId } }
879
1452
  });
880
1453
  }
881
- /** The payment events of one connection — where you audit what did and didn't invoice. */
1454
+ /**
1455
+ * The payment events of one connection — where you audit what did and didn't invoice.
1456
+ *
1457
+ * @param connectionId - Connection UUID.
1458
+ * @returns The events resource of that connection. No request is made.
1459
+ */
882
1460
  events(connectionId) {
883
1461
  return new CompanyPaymentEventsResource(this.client, this.companyId, connectionId);
884
1462
  }
@@ -896,6 +1474,9 @@ var CompanyPaymentEventsResource = class {
896
1474
  * Events of the connection, most recent first. Nothing is hidden by default:
897
1475
  * skipped events, duplicates and disputes are all returned — narrow with the
898
1476
  * filters. `charges_only` returns one row per money movement instead.
1477
+ *
1478
+ * @param params - Filters (`needs_action`, `charges_only`…) and pagination.
1479
+ * @returns The `events`, their `pagination` and `counts`.
899
1480
  */
900
1481
  async list(params) {
901
1482
  const { data } = await this.client.GET(
@@ -904,7 +1485,12 @@ var CompanyPaymentEventsResource = class {
904
1485
  );
905
1486
  return data.data;
906
1487
  }
907
- /** One event. */
1488
+ /**
1489
+ * Get one event.
1490
+ *
1491
+ * @param eventId - Event UUID.
1492
+ * @returns The event.
1493
+ */
908
1494
  async get(eventId) {
909
1495
  const { data } = await this.client.GET(
910
1496
  "/v1/companies/{company_id}/payment-connections/{connection_id}/events/{event_id}",
@@ -916,6 +1502,9 @@ var CompanyPaymentEventsResource = class {
916
1502
  * Reprocess an event whose automatic invoicing didn't complete, applying the NIF's
917
1503
  * **current** configuration. Only retryable states qualify and the retry budget is
918
1504
  * finite: otherwise `400`.
1505
+ *
1506
+ * @param eventId - Event UUID.
1507
+ * @returns The event after the retry.
919
1508
  */
920
1509
  async retry(eventId) {
921
1510
  const { data } = await this.client.POST(
@@ -926,7 +1515,10 @@ var CompanyPaymentEventsResource = class {
926
1515
  }
927
1516
  /**
928
1517
  * 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.
1518
+ * so you can review it before issuing.
1519
+ *
1520
+ * @param eventId - Event UUID.
1521
+ * @returns The draft's `invoice_id`.
930
1522
  */
931
1523
  async draft(eventId) {
932
1524
  const { data } = await this.client.POST(
@@ -935,7 +1527,12 @@ var CompanyPaymentEventsResource = class {
935
1527
  );
936
1528
  return data.data;
937
1529
  }
938
- /** Mark an event as dealt with outside the automatic flow. */
1530
+ /**
1531
+ * Mark an event as dealt with outside the automatic flow.
1532
+ *
1533
+ * @param eventId - Event UUID.
1534
+ * @returns The resolved event.
1535
+ */
939
1536
  async resolve(eventId) {
940
1537
  const { data } = await this.client.POST(
941
1538
  "/v1/companies/{company_id}/payment-connections/{connection_id}/events/{event_id}/resolve",
@@ -943,7 +1540,12 @@ var CompanyPaymentEventsResource = class {
943
1540
  );
944
1541
  return data.data;
945
1542
  }
946
- /** Discard an event so it stops asking for attention. Reversible with {@link restore}. */
1543
+ /**
1544
+ * Discard an event so it stops asking for attention. Reversible with {@link restore}.
1545
+ *
1546
+ * @param eventId - Event UUID.
1547
+ * @returns The discarded event.
1548
+ */
947
1549
  async discard(eventId) {
948
1550
  const { data } = await this.client.POST(
949
1551
  "/v1/companies/{company_id}/payment-connections/{connection_id}/events/{event_id}/discard",
@@ -951,7 +1553,12 @@ var CompanyPaymentEventsResource = class {
951
1553
  );
952
1554
  return data.data;
953
1555
  }
954
- /** Bring a discarded event back into the list. */
1556
+ /**
1557
+ * Bring a discarded event back into the list.
1558
+ *
1559
+ * @param eventId - Event UUID.
1560
+ * @returns The restored event.
1561
+ */
955
1562
  async restore(eventId) {
956
1563
  const { data } = await this.client.POST(
957
1564
  "/v1/companies/{company_id}/payment-connections/{connection_id}/events/{event_id}/restore",
@@ -961,6 +1568,44 @@ var CompanyPaymentEventsResource = class {
961
1568
  }
962
1569
  };
963
1570
 
1571
+ // src/resources/invoice-create-once.ts
1572
+ var EXTERNAL_REF_UNIQUE_INVOICE_TYPES = ["STANDARD", "SIMPLIFIED"];
1573
+ var MISSING_EXTERNAL_REF_MESSAGE = "invoices.createOnce requires a non-empty `external_ref`: it is the key that makes the call safe to repeat.";
1574
+ var UNSUPPORTED_TYPE_MESSAGE = "invoices.createOnce only creates STANDARD or SIMPLIFIED invoices: the API keeps `external_ref` unique for those types only.";
1575
+ function holdsTheReference(invoice) {
1576
+ return EXTERNAL_REF_UNIQUE_INVOICE_TYPES.includes(invoice.type);
1577
+ }
1578
+ async function findHolder(operations, externalRef) {
1579
+ const invoices = await operations.listByExternalRef(externalRef);
1580
+ return invoices.find(holdsTheReference);
1581
+ }
1582
+ function isDuplicateReference(error) {
1583
+ return error instanceof BeeLConflictError && error.apiCode === BeeLErrorCodes.INVOICE_DUPLICATE_EXTERNAL_REFERENCE;
1584
+ }
1585
+ function isUnknownOutcome(error) {
1586
+ if (!(error instanceof BeeLApiError)) return true;
1587
+ if (isServerErrorStatus(error.statusCode)) return true;
1588
+ return error instanceof BeeLConflictError && error.apiCode === BeeLErrorCodes.IDEMPOTENCY_KEY_PROCESSING;
1589
+ }
1590
+ async function createInvoiceOnce(operations, body, params) {
1591
+ if (typeof body.external_ref !== "string" || body.external_ref.trim() === "") {
1592
+ throw new TypeError(MISSING_EXTERNAL_REF_MESSAGE);
1593
+ }
1594
+ if (!EXTERNAL_REF_UNIQUE_INVOICE_TYPES.includes(body.type)) {
1595
+ throw new TypeError(UNSUPPORTED_TYPE_MESSAGE);
1596
+ }
1597
+ const existing = await findHolder(operations, body.external_ref);
1598
+ if (existing) return existing;
1599
+ try {
1600
+ return await operations.create(body, params);
1601
+ } catch (error) {
1602
+ if (!isDuplicateReference(error) && !isUnknownOutcome(error)) throw error;
1603
+ const holder = await findHolder(operations, body.external_ref).catch(() => void 0);
1604
+ if (holder) return holder;
1605
+ throw error;
1606
+ }
1607
+ }
1608
+
964
1609
  // src/resources/company.ts
965
1610
  var CompanyScope = class {
966
1611
  constructor(client, companyId) {
@@ -978,14 +1623,24 @@ var CompanyScope = class {
978
1623
  path() {
979
1624
  return { company_id: this.companyId };
980
1625
  }
981
- /** Get the company. */
1626
+ /**
1627
+ * Get the company: its fiscal identity, address and settings.
1628
+ *
1629
+ * @param params - Optional query of `getCompanyById` (e.g. `include`).
1630
+ * @returns The company.
1631
+ */
982
1632
  async get(params) {
983
1633
  const { data } = await this.client.GET("/v1/companies/{company_id}", {
984
1634
  params: { path: this.path(), query: params }
985
1635
  });
986
1636
  return data.data;
987
1637
  }
988
- /** Update company data. */
1638
+ /**
1639
+ * Update the company's data. Only the fields present in `body` change.
1640
+ *
1641
+ * @param body - Fields to change.
1642
+ * @returns The updated company.
1643
+ */
989
1644
  async update(body) {
990
1645
  const { data } = await this.client.PATCH("/v1/companies/{company_id}", {
991
1646
  params: { path: this.path() },
@@ -993,18 +1648,30 @@ var CompanyScope = class {
993
1648
  });
994
1649
  return data.data;
995
1650
  }
996
- /** Delete the company. */
1651
+ /**
1652
+ * Remove the company from its account. Blocked for the primary NIF, a NIF active in Live,
1653
+ * or one holding Live invoices.
1654
+ */
997
1655
  async delete() {
998
1656
  await this.client.DELETE("/v1/companies/{company_id}", { params: { path: this.path() } });
999
1657
  }
1000
- /** Fiscal summary (VAT/IRPF aggregates) for the company. */
1658
+ /**
1659
+ * Fiscal summary of the company for a period: taxable base, VAT and IRPF aggregates.
1660
+ *
1661
+ * @param params - `start_date` and `end_date` (both or neither; default: the current month).
1662
+ * @returns The aggregates of the period.
1663
+ */
1001
1664
  async fiscalSummary(params) {
1002
1665
  const { data } = await this.client.GET("/v1/companies/{company_id}/fiscal-summary", {
1003
1666
  params: { path: this.path(), query: params }
1004
1667
  });
1005
1668
  return data.data;
1006
1669
  }
1007
- /** Whether the company can already issue invoices, and what is missing if not. */
1670
+ /**
1671
+ * Whether the company can issue invoices now, and what blocks it if not.
1672
+ *
1673
+ * @returns `ready` plus the list of `blockers`.
1674
+ */
1008
1675
  async issuingReadiness() {
1009
1676
  const { data } = await this.client.GET("/v1/companies/{company_id}/issuing-readiness", {
1010
1677
  params: { path: this.path() }
@@ -1019,10 +1686,16 @@ var CompanyInvoicesResource = class {
1019
1686
  this.schedule = new CompanyInvoiceScheduleResource(client, companyId);
1020
1687
  }
1021
1688
  /**
1022
- * Derive a new invoice from an existing one — the canonical form of `duplicate`.
1689
+ * Derive a new draft invoice from an existing one — the canonical form of `duplicate`.
1690
+ * The source invoice is not modified.
1691
+ *
1692
+ * @param body - `from_invoice_id`, and optionally the `series_id` of the copy.
1693
+ * @param options - Per-call `idempotencyKey`, `signal` and `timeoutMs`.
1694
+ * @returns The new draft invoice.
1023
1695
  */
1024
- async derive(body) {
1696
+ async derive(body, options) {
1025
1697
  const { data } = await this.client.POST("/v1/companies/{company_id}/invoices/derivations", {
1698
+ ...toRequestInit(options),
1026
1699
  params: { path: { company_id: this.companyId } },
1027
1700
  body
1028
1701
  });
@@ -1031,65 +1704,221 @@ var CompanyInvoicesResource = class {
1031
1704
  path(rest) {
1032
1705
  return { company_id: this.companyId, ...rest };
1033
1706
  }
1034
- async list(params) {
1707
+ /**
1708
+ * List the company's invoices, paginated, with filters: status, type, customer, dates,
1709
+ * `external_ref` (exact match), VeriFactu status and more.
1710
+ *
1711
+ * @param params - Filters and pagination (`page`, `limit`).
1712
+ * @param options - Per-call `idempotencyKey`, `signal` and `timeoutMs`.
1713
+ * @returns The page of `invoices` and its `pagination`.
1714
+ *
1715
+ * @example
1716
+ * ```typescript
1717
+ * const { invoices } = await company.invoices.list({ external_ref: 'ORD-2026-0042' });
1718
+ * ```
1719
+ */
1720
+ async list(params, options) {
1035
1721
  const { data } = await this.client.GET("/v1/companies/{company_id}/invoices", {
1722
+ ...toRequestInit(options),
1036
1723
  params: { path: this.path(), query: params }
1037
1724
  });
1038
1725
  return data.data;
1039
1726
  }
1040
- async create(body, params) {
1727
+ /**
1728
+ * Create an invoice: a `DRAFT` by default, or numbered and issued in the same call with
1729
+ * `options.issue_directly: true`. `CORRECTIVE` is not accepted here: use
1730
+ * {@link createCorrective}.
1731
+ *
1732
+ * One call sends one `Idempotency-Key`, reused by the client's automatic retries, so
1733
+ * those never duplicate the invoice. A second call is a new operation: to repeat a create
1734
+ * whose outcome you do not know, use {@link createOnce}.
1735
+ *
1736
+ * @param body - Type, recipient and lines; `external_ref` to tie it to your order.
1737
+ * @param params - `wait_for_pdf`, when issuing directly.
1738
+ * @param options - Per-call `idempotencyKey`, `signal` and `timeoutMs`.
1739
+ * @returns The created invoice. With VeriFactu, `verifactu.submission_status` starts `PENDING`.
1740
+ *
1741
+ * @example
1742
+ * ```typescript
1743
+ * const invoice = await company.invoices.create({
1744
+ * type: 'STANDARD',
1745
+ * recipient: { customer_id: 'customer-uuid' },
1746
+ * lines: [{
1747
+ * description: 'Consulting', quantity: 1, unit_price: 100,
1748
+ * main_tax: { type: 'IVA', percentage: 21, regime_key: '01' },
1749
+ * }],
1750
+ * external_ref: 'ORD-2026-0042',
1751
+ * });
1752
+ * ```
1753
+ */
1754
+ async create(body, params, options) {
1041
1755
  const { data } = await this.client.POST("/v1/companies/{company_id}/invoices", {
1756
+ ...toRequestInit(options),
1042
1757
  params: { path: this.path(), query: params },
1043
1758
  body
1044
1759
  });
1045
1760
  return data.data;
1046
1761
  }
1047
- async get(invoiceId) {
1762
+ /**
1763
+ * Create a standard or simplified invoice once per `external_ref`, safe to call again
1764
+ * after any failure. It looks the reference up first and returns the invoice that already
1765
+ * holds it; otherwise it creates one. If the create answers
1766
+ * `409 INVOICE_DUPLICATE_EXTERNAL_REFERENCE`, or its outcome is unknown (network error,
1767
+ * `5xx`), it looks the reference up again and returns the invoice it finds.
1768
+ *
1769
+ * The returned invoice may be one created earlier, in any status (`VOIDED` included):
1770
+ * compare its fields if that matters to you.
1771
+ *
1772
+ * @param body - A `CreateInvoiceRequest` with `type` `STANDARD` or `SIMPLIFIED` and a
1773
+ * non-empty `external_ref`.
1774
+ * @param params - `wait_for_pdf`, when issuing directly.
1775
+ * @param options - `idempotencyKey` for the create; `signal` and `timeoutMs` for the whole
1776
+ * sequence of calls.
1777
+ * @returns The one invoice that holds `body.external_ref`.
1778
+ * @throws {TypeError} Before any request, when `external_ref` is empty or `type` is not
1779
+ * `STANDARD`/`SIMPLIFIED`.
1780
+ * @throws {BeeLApiError} The create's error when no invoice holds the reference
1781
+ * afterwards — nothing was created, so calling again is safe.
1782
+ *
1783
+ * @example
1784
+ * ```typescript
1785
+ * const invoice = await company.invoices.createOnce({
1786
+ * type: 'STANDARD',
1787
+ * external_ref: order.id,
1788
+ * recipient: { customer_id: order.customerId },
1789
+ * lines: [{ description: 'Order', quantity: 1, unit_price: 100,
1790
+ * main_tax: { type: 'IVA', percentage: 21, regime_key: '01' } }],
1791
+ * options: { issue_directly: true },
1792
+ * });
1793
+ * ```
1794
+ */
1795
+ async createOnce(body, params, options) {
1796
+ const { signal } = toRequestInit({ signal: options?.signal, timeoutMs: options?.timeoutMs });
1797
+ return createInvoiceOnce(
1798
+ {
1799
+ listByExternalRef: async (externalRef) => (await this.list({ external_ref: externalRef }, { signal })).invoices,
1800
+ create: (request, query) => this.create(request, query, { signal, idempotencyKey: options?.idempotencyKey })
1801
+ },
1802
+ body,
1803
+ params
1804
+ );
1805
+ }
1806
+ /**
1807
+ * Get one invoice, including its `status` and its `verifactu` block
1808
+ * (`submission_status`, `qr_url`, `error_code`…).
1809
+ *
1810
+ * @param invoiceId - Invoice UUID.
1811
+ * @param options - Per-call `idempotencyKey`, `signal` and `timeoutMs`.
1812
+ * @returns The invoice.
1813
+ */
1814
+ async get(invoiceId, options) {
1048
1815
  const { data } = await this.client.GET("/v1/companies/{company_id}/invoices/{invoice_id}", {
1816
+ ...toRequestInit(options),
1049
1817
  params: { path: this.path({ invoice_id: invoiceId }) }
1050
1818
  });
1051
1819
  return data.data;
1052
1820
  }
1053
- /** Update a draft invoice. */
1054
- async update(invoiceId, body) {
1821
+ /**
1822
+ * Update a `DRAFT` or `SCHEDULED` invoice (or an `ACTIVE` proforma). Only the fields
1823
+ * present in `body` change; an issued invoice is amended with a corrective instead.
1824
+ *
1825
+ * @param invoiceId - Invoice UUID.
1826
+ * @param body - Fields to change.
1827
+ * @param options - Per-call `idempotencyKey`, `signal` and `timeoutMs`.
1828
+ * @returns The updated invoice.
1829
+ */
1830
+ async update(invoiceId, body, options) {
1055
1831
  const { data } = await this.client.PATCH("/v1/companies/{company_id}/invoices/{invoice_id}", {
1832
+ ...toRequestInit(options),
1056
1833
  params: { path: this.path({ invoice_id: invoiceId }) },
1057
1834
  body
1058
1835
  });
1059
1836
  return data.data;
1060
1837
  }
1061
- /** Delete a draft invoice. */
1062
- async delete(invoiceId) {
1838
+ /**
1839
+ * Delete a draft invoice. Deleting frees its `external_ref` for a new invoice.
1840
+ *
1841
+ * @param invoiceId - Invoice UUID.
1842
+ * @param options - Per-call `idempotencyKey`, `signal` and `timeoutMs`.
1843
+ */
1844
+ async delete(invoiceId, options) {
1063
1845
  await this.client.DELETE("/v1/companies/{company_id}/invoices/{invoice_id}", {
1846
+ ...toRequestInit(options),
1064
1847
  params: { path: this.path({ invoice_id: invoiceId }) }
1065
1848
  });
1066
1849
  }
1067
- /** Issue a draft invoice (assigns number, submits to VeriFactu when configured). */
1068
- async issue(invoiceId, params) {
1850
+ /**
1851
+ * Issue a draft: assigns its definitive number and makes it immutable. PDF generation and
1852
+ * the VeriFactu submission happen after the response.
1853
+ *
1854
+ * @param invoiceId - UUID of the draft.
1855
+ * @param params - `wait_for_pdf: true` to wait for the PDF before answering.
1856
+ * @param options - Per-call `idempotencyKey`, `signal` and `timeoutMs`.
1857
+ * @returns The issued invoice.
1858
+ */
1859
+ async issue(invoiceId, params, options) {
1069
1860
  const { data } = await this.client.POST("/v1/companies/{company_id}/invoices/{invoice_id}/issue", {
1861
+ ...toRequestInit(options),
1070
1862
  params: { path: this.path({ invoice_id: invoiceId }), query: params }
1071
1863
  });
1072
1864
  return data.data;
1073
1865
  }
1074
- /** Void an issued invoice. */
1075
- async void(invoiceId, body) {
1866
+ /**
1867
+ * Void an invoice issued by mistake. The document is kept and its number never reused. If
1868
+ * the operation did happen but the invoice is wrong, use {@link createCorrective}.
1869
+ *
1870
+ * @param invoiceId - Invoice UUID.
1871
+ * @param body - `reason`; `issued_in_error: true` is required once it was sent or paid.
1872
+ * @param options - Per-call `idempotencyKey`, `signal` and `timeoutMs`.
1873
+ * @returns The voided invoice.
1874
+ */
1875
+ async void(invoiceId, body, options) {
1076
1876
  const { data } = await this.client.POST("/v1/companies/{company_id}/invoices/{invoice_id}/void", {
1877
+ ...toRequestInit(options),
1077
1878
  params: { path: this.path({ invoice_id: invoiceId }) },
1078
1879
  body
1079
1880
  });
1080
1881
  return data.data;
1081
1882
  }
1082
- /** Create a corrective (rectificativa) for an issued invoice. */
1083
- async createCorrective(invoiceId, body) {
1883
+ /**
1884
+ * Create a corrective invoice (rectificativa) for an issued invoice.
1885
+ *
1886
+ * @param invoiceId - UUID of the issued invoice to correct.
1887
+ * @param body - `rectification_type` (`TOTAL`/`PARTIAL`), `rectification_code` (`R1`–`R5`),
1888
+ * `reason` and, for `PARTIAL`, the correcting `lines`.
1889
+ * @param options - Per-call `idempotencyKey`, `signal` and `timeoutMs`.
1890
+ * @returns The corrective invoice.
1891
+ *
1892
+ * @example
1893
+ * ```typescript
1894
+ * const corrective = await company.invoices.createCorrective('invoice-uuid', {
1895
+ * rectification_type: 'PARTIAL',
1896
+ * rectification_code: 'R1',
1897
+ * reason: 'Discount agreed with the customer after the sale',
1898
+ * lines: [{ description: 'Discount', quantity: -1, unit_price: 10,
1899
+ * main_tax: { type: 'IVA', percentage: 21, regime_key: '01' } }],
1900
+ * });
1901
+ * ```
1902
+ */
1903
+ async createCorrective(invoiceId, body, options) {
1084
1904
  const { data } = await this.client.POST("/v1/companies/{company_id}/invoices/{invoice_id}/corrective", {
1905
+ ...toRequestInit(options),
1085
1906
  params: { path: this.path({ invoice_id: invoiceId }) },
1086
1907
  body
1087
1908
  });
1088
1909
  return data.data;
1089
1910
  }
1090
- /** Convert a proforma into an invoice. */
1091
- async convertToInvoice(invoiceId, body) {
1911
+ /**
1912
+ * Convert a proforma into an invoice.
1913
+ *
1914
+ * @param invoiceId - UUID of the proforma.
1915
+ * @param body - Optional overrides for the new invoice.
1916
+ * @param options - Per-call `idempotencyKey`, `signal` and `timeoutMs`.
1917
+ * @returns The new invoice.
1918
+ */
1919
+ async convertToInvoice(invoiceId, body, options) {
1092
1920
  const { data } = await this.client.POST("/v1/companies/{company_id}/invoices/{invoice_id}/convert-to-invoice", {
1921
+ ...toRequestInit(options),
1093
1922
  params: { path: this.path({ invoice_id: invoiceId }) },
1094
1923
  body
1095
1924
  });
@@ -1101,6 +1930,10 @@ var CompanyInvoicesResource = class {
1101
1930
  * invoices become `VOIDED` with `void_cause: 'EXCHANGED'`, and the new `STANDARD` invoice
1102
1931
  * lists them in `replaced_invoice_ids`.
1103
1932
  *
1933
+ * @param body - `simplified_invoice_ids` and the identified `recipient`.
1934
+ * @param options - Per-call `idempotencyKey`, `signal` and `timeoutMs`.
1935
+ * @returns The new standard invoice.
1936
+ *
1104
1937
  * @example
1105
1938
  * ```typescript
1106
1939
  * const invoice = await company.invoices.createSimplifiedExchange({
@@ -1109,8 +1942,9 @@ var CompanyInvoicesResource = class {
1109
1942
  * });
1110
1943
  * ```
1111
1944
  */
1112
- async createSimplifiedExchange(body) {
1945
+ async createSimplifiedExchange(body, options) {
1113
1946
  const { data } = await this.client.POST("/v1/companies/{company_id}/invoices/simplified-exchanges", {
1947
+ ...toRequestInit(options),
1114
1948
  params: { path: this.path() },
1115
1949
  body
1116
1950
  });
@@ -1119,31 +1953,60 @@ var CompanyInvoicesResource = class {
1119
1953
  /**
1120
1954
  * The VeriFactu records of an invoice, oldest first: its registration and, if it was
1121
1955
  * voided, its cancellation. An invoice never submitted answers with an empty list.
1956
+ *
1957
+ * @param invoiceId - Invoice UUID.
1958
+ * @param options - Per-call `idempotencyKey`, `signal` and `timeoutMs`.
1959
+ * @returns The records (`data.records` of the response), each with its own `submission_status`.
1122
1960
  */
1123
- async verifactuRecords(invoiceId) {
1961
+ async verifactuRecords(invoiceId, options) {
1124
1962
  const { data } = await this.client.GET("/v1/companies/{company_id}/invoices/{invoice_id}/verifactu-records", {
1963
+ ...toRequestInit(options),
1125
1964
  params: { path: this.path({ invoice_id: invoiceId }) }
1126
1965
  });
1127
1966
  return data.data.records;
1128
1967
  }
1129
- /** Update payment status (e.g. mark as paid). */
1130
- async setStatus(invoiceId, body) {
1968
+ /**
1969
+ * Set the commercial status: `PAID` (from `ISSUED`, `SENT`, `OVERDUE`), `SENT` (from
1970
+ * `ISSUED`) or back to `ISSUED` (from `SENT`). Issuing and voiding have their own methods.
1971
+ *
1972
+ * @param invoiceId - Invoice UUID.
1973
+ * @param body - Target `status` and, for `PAID`, the payment details.
1974
+ * @param options - Per-call `idempotencyKey`, `signal` and `timeoutMs`.
1975
+ * @returns The updated invoice.
1976
+ */
1977
+ async setStatus(invoiceId, body, options) {
1131
1978
  const { data } = await this.client.PUT("/v1/companies/{company_id}/invoices/{invoice_id}/status", {
1979
+ ...toRequestInit(options),
1132
1980
  params: { path: this.path({ invoice_id: invoiceId }) },
1133
1981
  body
1134
1982
  });
1135
1983
  return data.data;
1136
1984
  }
1137
- /** Get PDF metadata and download URL. */
1138
- async getPdf(invoiceId) {
1985
+ /**
1986
+ * Get a short-lived download URL for the invoice PDF.
1987
+ *
1988
+ * @param invoiceId - Invoice UUID.
1989
+ * @param options - Per-call `idempotencyKey`, `signal` and `timeoutMs`.
1990
+ * @returns `download_url`, `expires_in_seconds` and `file_name`.
1991
+ */
1992
+ async getPdf(invoiceId, options) {
1139
1993
  const { data } = await this.client.GET("/v1/companies/{company_id}/invoices/{invoice_id}/pdf", {
1994
+ ...toRequestInit(options),
1140
1995
  params: { path: this.path({ invoice_id: invoiceId }) }
1141
1996
  });
1142
1997
  return data.data;
1143
1998
  }
1144
- /** Send the invoice by email to the customer. */
1145
- async send(invoiceId, body) {
1999
+ /**
2000
+ * Send the invoice by email with its PDF. Without recipients, the customer's addresses are used.
2001
+ *
2002
+ * @param invoiceId - Invoice UUID.
2003
+ * @param body - Optional recipients, subject and message.
2004
+ * @param options - Per-call `idempotencyKey`, `signal` and `timeoutMs`.
2005
+ * @returns The delivery record.
2006
+ */
2007
+ async send(invoiceId, body, options) {
1146
2008
  const { data } = await this.client.POST("/v1/companies/{company_id}/invoices/{invoice_id}/send", {
2009
+ ...toRequestInit(options),
1147
2010
  params: { path: this.path({ invoice_id: invoiceId }) },
1148
2011
  body
1149
2012
  });
@@ -1155,6 +2018,12 @@ var CompanyInvoiceScheduleResource = class {
1155
2018
  this.client = client;
1156
2019
  this.companyId = companyId;
1157
2020
  }
2021
+ /**
2022
+ * Get the schedule of an invoice.
2023
+ *
2024
+ * @param invoiceId - Invoice UUID.
2025
+ * @returns `scheduled_for` and `generation_mode`.
2026
+ */
1158
2027
  async get(invoiceId) {
1159
2028
  const { data } = await this.client.GET(
1160
2029
  "/v1/companies/{company_id}/invoices/{invoice_id}/schedule",
@@ -1165,6 +2034,10 @@ var CompanyInvoiceScheduleResource = class {
1165
2034
  /**
1166
2035
  * Set or move the schedule. One `PUT` replaces the three legacy calls
1167
2036
  * (`schedule`, `reschedule`, `unschedule`): setting it again moves it.
2037
+ *
2038
+ * @param invoiceId - UUID of a draft invoice.
2039
+ * @param body - `scheduled_for` date and what to do then.
2040
+ * @returns The scheduled invoice.
1168
2041
  */
1169
2042
  async set(invoiceId, body) {
1170
2043
  const { data } = await this.client.PUT(
@@ -1173,7 +2046,12 @@ var CompanyInvoiceScheduleResource = class {
1173
2046
  );
1174
2047
  return data.data;
1175
2048
  }
1176
- /** Clear the schedule — the canonical form of `unschedule`. */
2049
+ /**
2050
+ * Clear the schedule, returning the invoice to a plain draft — the canonical form of
2051
+ * `unschedule`. Idempotent.
2052
+ *
2053
+ * @param invoiceId - Invoice UUID.
2054
+ */
1177
2055
  async clear(invoiceId) {
1178
2056
  await this.client.DELETE("/v1/companies/{company_id}/invoices/{invoice_id}/schedule", {
1179
2057
  params: { path: { company_id: this.companyId, invoice_id: invoiceId } }
@@ -1185,12 +2063,24 @@ var CompanyCustomersResource = class {
1185
2063
  this.client = client;
1186
2064
  this.companyId = companyId;
1187
2065
  }
2066
+ /**
2067
+ * List the company's customers, paginated and searchable.
2068
+ *
2069
+ * @param params - Filters and pagination.
2070
+ * @returns The page of `customers` and its `pagination`.
2071
+ */
1188
2072
  async list(params) {
1189
2073
  const { data } = await this.client.GET("/v1/companies/{company_id}/customers", {
1190
2074
  params: { path: { company_id: this.companyId }, query: params }
1191
2075
  });
1192
2076
  return data.data;
1193
2077
  }
2078
+ /**
2079
+ * Create a customer.
2080
+ *
2081
+ * @param body - Legal name, NIF (or alternative id) and address.
2082
+ * @returns The created customer.
2083
+ */
1194
2084
  async create(body) {
1195
2085
  const { data } = await this.client.POST("/v1/companies/{company_id}/customers", {
1196
2086
  params: { path: { company_id: this.companyId } },
@@ -1198,6 +2088,12 @@ var CompanyCustomersResource = class {
1198
2088
  });
1199
2089
  return data.data;
1200
2090
  }
2091
+ /**
2092
+ * Create several customers in one call.
2093
+ *
2094
+ * @param body - The customers, and whether it is a dry run.
2095
+ * @returns Per-customer results and totals.
2096
+ */
1201
2097
  async createBulk(body) {
1202
2098
  const { data } = await this.client.POST("/v1/companies/{company_id}/customers/bulk", {
1203
2099
  params: { path: { company_id: this.companyId } },
@@ -1205,12 +2101,25 @@ var CompanyCustomersResource = class {
1205
2101
  });
1206
2102
  return data.data;
1207
2103
  }
2104
+ /**
2105
+ * Get one customer.
2106
+ *
2107
+ * @param customerId - Customer UUID.
2108
+ * @returns The customer.
2109
+ */
1208
2110
  async get(customerId) {
1209
2111
  const { data } = await this.client.GET("/v1/companies/{company_id}/customers/{customer_id}", {
1210
2112
  params: { path: { company_id: this.companyId, customer_id: customerId } }
1211
2113
  });
1212
2114
  return data.data;
1213
2115
  }
2116
+ /**
2117
+ * Update a customer. Only the fields present in `body` change.
2118
+ *
2119
+ * @param customerId - Customer UUID.
2120
+ * @param body - Fields to change.
2121
+ * @returns The updated customer.
2122
+ */
1214
2123
  async update(customerId, body) {
1215
2124
  const { data } = await this.client.PATCH("/v1/companies/{company_id}/customers/{customer_id}", {
1216
2125
  params: { path: { company_id: this.companyId, customer_id: customerId } },
@@ -1218,6 +2127,12 @@ var CompanyCustomersResource = class {
1218
2127
  });
1219
2128
  return data.data;
1220
2129
  }
2130
+ /**
2131
+ * Delete a customer that has no invoices. Its NIF (or alternative id) is released for a
2132
+ * new customer.
2133
+ *
2134
+ * @param customerId - Customer UUID.
2135
+ */
1221
2136
  async delete(customerId) {
1222
2137
  await this.client.DELETE("/v1/companies/{company_id}/customers/{customer_id}", {
1223
2138
  params: { path: { company_id: this.companyId, customer_id: customerId } }
@@ -1229,12 +2144,24 @@ var CompanyProductsResource = class {
1229
2144
  this.client = client;
1230
2145
  this.companyId = companyId;
1231
2146
  }
2147
+ /**
2148
+ * List the company's products, paginated and searchable.
2149
+ *
2150
+ * @param params - Filters and pagination.
2151
+ * @returns The page of `products` and its `pagination`.
2152
+ */
1232
2153
  async list(params) {
1233
2154
  const { data } = await this.client.GET("/v1/companies/{company_id}/products", {
1234
2155
  params: { path: { company_id: this.companyId }, query: params }
1235
2156
  });
1236
2157
  return data.data;
1237
2158
  }
2159
+ /**
2160
+ * Create a product or service.
2161
+ *
2162
+ * @param body - Name, category, price and main tax.
2163
+ * @returns The created product.
2164
+ */
1238
2165
  async create(body) {
1239
2166
  const { data } = await this.client.POST("/v1/companies/{company_id}/products", {
1240
2167
  params: { path: { company_id: this.companyId } },
@@ -1242,12 +2169,25 @@ var CompanyProductsResource = class {
1242
2169
  });
1243
2170
  return data.data;
1244
2171
  }
2172
+ /**
2173
+ * Get one product.
2174
+ *
2175
+ * @param productId - Product UUID.
2176
+ * @returns The product.
2177
+ */
1245
2178
  async get(productId) {
1246
2179
  const { data } = await this.client.GET("/v1/companies/{company_id}/products/{product_id}", {
1247
2180
  params: { path: { company_id: this.companyId, product_id: productId } }
1248
2181
  });
1249
2182
  return data.data;
1250
2183
  }
2184
+ /**
2185
+ * Update a product. Only the fields present in `body` change.
2186
+ *
2187
+ * @param productId - Product UUID.
2188
+ * @param body - Fields to change.
2189
+ * @returns The updated product.
2190
+ */
1251
2191
  async update(productId, body) {
1252
2192
  const { data } = await this.client.PATCH("/v1/companies/{company_id}/products/{product_id}", {
1253
2193
  params: { path: { company_id: this.companyId, product_id: productId } },
@@ -1255,6 +2195,11 @@ var CompanyProductsResource = class {
1255
2195
  });
1256
2196
  return data.data;
1257
2197
  }
2198
+ /**
2199
+ * Delete a product from the catalog. Existing invoice lines are unaffected.
2200
+ *
2201
+ * @param productId - Product UUID.
2202
+ */
1258
2203
  async delete(productId) {
1259
2204
  await this.client.DELETE("/v1/companies/{company_id}/products/{product_id}", {
1260
2205
  params: { path: { company_id: this.companyId, product_id: productId } }
@@ -1266,12 +2211,24 @@ var CompanySeriesResource = class {
1266
2211
  this.client = client;
1267
2212
  this.companyId = companyId;
1268
2213
  }
2214
+ /**
2215
+ * List the company's series.
2216
+ *
2217
+ * @param params - Filters; `page`/`limit` to paginate.
2218
+ * @returns The `series`, and `pagination` when you paginated.
2219
+ */
1269
2220
  async list(params) {
1270
2221
  const { data } = await this.client.GET("/v1/companies/{company_id}/series", {
1271
2222
  params: { path: { company_id: this.companyId }, query: params }
1272
2223
  });
1273
2224
  return data.data;
1274
2225
  }
2226
+ /**
2227
+ * Create a series.
2228
+ *
2229
+ * @param body - Code, name, format and the `document_type` it numbers.
2230
+ * @returns The created series.
2231
+ */
1275
2232
  async create(body) {
1276
2233
  const { data } = await this.client.POST("/v1/companies/{company_id}/series", {
1277
2234
  params: { path: { company_id: this.companyId } },
@@ -1279,6 +2236,13 @@ var CompanySeriesResource = class {
1279
2236
  });
1280
2237
  return data.data;
1281
2238
  }
2239
+ /**
2240
+ * Update a series. Only the fields present in `body` change.
2241
+ *
2242
+ * @param seriesId - Series UUID.
2243
+ * @param body - Fields to change.
2244
+ * @returns The updated series.
2245
+ */
1282
2246
  async update(seriesId, body) {
1283
2247
  const { data } = await this.client.PATCH("/v1/companies/{company_id}/series/{series_id}", {
1284
2248
  params: { path: { company_id: this.companyId, series_id: seriesId } },
@@ -1286,26 +2250,45 @@ var CompanySeriesResource = class {
1286
2250
  });
1287
2251
  return data.data;
1288
2252
  }
2253
+ /**
2254
+ * Delete (soft-delete) a series. Its code stays taken, since issued invoices carry it.
2255
+ *
2256
+ * @param seriesId - Series UUID.
2257
+ */
1289
2258
  async delete(seriesId) {
1290
2259
  await this.client.DELETE("/v1/companies/{company_id}/series/{series_id}", {
1291
2260
  params: { path: { company_id: this.companyId, series_id: seriesId } }
1292
2261
  });
1293
2262
  }
1294
- /** Current default series per invoice type. */
2263
+ /**
2264
+ * The current default series per document type.
2265
+ *
2266
+ * @returns One entry per document type, saying whether a default exists.
2267
+ */
1295
2268
  async getDefaults() {
1296
2269
  const { data } = await this.client.GET("/v1/companies/{company_id}/series/defaults", {
1297
2270
  params: { path: { company_id: this.companyId } }
1298
2271
  });
1299
2272
  return data.data;
1300
2273
  }
1301
- /** Ensure the three typed default series exist (idempotent seeding). */
2274
+ /**
2275
+ * Ensure a default series exists per document type, creating the missing ones.
2276
+ * Idempotent.
2277
+ *
2278
+ * @returns The default series.
2279
+ */
1302
2280
  async ensureDefaults() {
1303
2281
  const { data } = await this.client.PUT("/v1/companies/{company_id}/series/defaults", {
1304
2282
  params: { path: { company_id: this.companyId } }
1305
2283
  });
1306
2284
  return data.data;
1307
2285
  }
1308
- /** Mark a series as the default for its invoice type. */
2286
+ /**
2287
+ * Mark a series as the default for its document type.
2288
+ *
2289
+ * @param seriesId - Series UUID.
2290
+ * @returns The series.
2291
+ */
1309
2292
  async setDefault(seriesId) {
1310
2293
  const { data } = await this.client.PUT("/v1/companies/{company_id}/series/{series_id}/default", {
1311
2294
  params: { path: { company_id: this.companyId, series_id: seriesId } }
@@ -1321,12 +2304,24 @@ var CompanyRecurringInvoicesResource = class {
1321
2304
  path(rest) {
1322
2305
  return { company_id: this.companyId, ...rest };
1323
2306
  }
2307
+ /**
2308
+ * List the recurring invoices.
2309
+ *
2310
+ * @param params - Filters and pagination.
2311
+ * @returns The page of `recurring_invoices` and its `pagination`.
2312
+ */
1324
2313
  async list(params) {
1325
2314
  const { data } = await this.client.GET("/v1/companies/{company_id}/recurring-invoices", {
1326
2315
  params: { path: this.path(), query: params }
1327
2316
  });
1328
2317
  return data.data;
1329
2318
  }
2319
+ /**
2320
+ * Create a recurring invoice template.
2321
+ *
2322
+ * @param body - Frequency, schedule, recipient and lines.
2323
+ * @returns The recurring invoice.
2324
+ */
1330
2325
  async create(body) {
1331
2326
  const { data } = await this.client.POST("/v1/companies/{company_id}/recurring-invoices", {
1332
2327
  params: { path: this.path() },
@@ -1334,12 +2329,25 @@ var CompanyRecurringInvoicesResource = class {
1334
2329
  });
1335
2330
  return data.data;
1336
2331
  }
2332
+ /**
2333
+ * Get one recurring invoice.
2334
+ *
2335
+ * @param recurringInvoiceId - Recurring invoice UUID.
2336
+ * @returns The recurring invoice.
2337
+ */
1337
2338
  async get(recurringInvoiceId) {
1338
2339
  const { data } = await this.client.GET("/v1/companies/{company_id}/recurring-invoices/{recurring_invoice_id}", {
1339
2340
  params: { path: this.path({ recurring_invoice_id: recurringInvoiceId }) }
1340
2341
  });
1341
2342
  return data.data;
1342
2343
  }
2344
+ /**
2345
+ * Update a recurring invoice. Only the fields present in `body` change.
2346
+ *
2347
+ * @param recurringInvoiceId - Recurring invoice UUID.
2348
+ * @param body - Fields to change.
2349
+ * @returns The updated recurring invoice.
2350
+ */
1343
2351
  async update(recurringInvoiceId, body) {
1344
2352
  const { data } = await this.client.PATCH("/v1/companies/{company_id}/recurring-invoices/{recurring_invoice_id}", {
1345
2353
  params: { path: this.path({ recurring_invoice_id: recurringInvoiceId }) },
@@ -1347,12 +2355,24 @@ var CompanyRecurringInvoicesResource = class {
1347
2355
  });
1348
2356
  return data.data;
1349
2357
  }
2358
+ /**
2359
+ * Delete a recurring invoice and cancel its pending generations. Invoices it already
2360
+ * generated are kept.
2361
+ *
2362
+ * @param recurringInvoiceId - Recurring invoice UUID.
2363
+ */
1350
2364
  async delete(recurringInvoiceId) {
1351
2365
  await this.client.DELETE("/v1/companies/{company_id}/recurring-invoices/{recurring_invoice_id}", {
1352
2366
  params: { path: this.path({ recurring_invoice_id: recurringInvoiceId }) }
1353
2367
  });
1354
2368
  }
1355
- /** Pause or resume the schedule. */
2369
+ /**
2370
+ * Pause, resume or end the template.
2371
+ *
2372
+ * @param recurringInvoiceId - Recurring invoice UUID.
2373
+ * @param body - Target `status` (e.g. `PAUSED`, `ACTIVE`).
2374
+ * @returns The updated recurring invoice.
2375
+ */
1356
2376
  async setStatus(recurringInvoiceId, body) {
1357
2377
  const { data } = await this.client.PUT("/v1/companies/{company_id}/recurring-invoices/{recurring_invoice_id}/status", {
1358
2378
  params: { path: this.path({ recurring_invoice_id: recurringInvoiceId }) },
@@ -1360,26 +2380,49 @@ var CompanyRecurringInvoicesResource = class {
1360
2380
  });
1361
2381
  return data.data;
1362
2382
  }
1363
- /** Skip the next scheduled occurrence. */
2383
+ /**
2384
+ * Skip the next scheduled occurrence.
2385
+ *
2386
+ * @param recurringInvoiceId - Recurring invoice UUID.
2387
+ * @returns The recurring invoice with its next date moved.
2388
+ */
1364
2389
  async skip(recurringInvoiceId) {
1365
2390
  const { data } = await this.client.POST("/v1/companies/{company_id}/recurring-invoices/{recurring_invoice_id}/skip", {
1366
2391
  params: { path: this.path({ recurring_invoice_id: recurringInvoiceId }) }
1367
2392
  });
1368
2393
  return data.data;
1369
2394
  }
1370
- /** Generate the next invoice now instead of waiting for the schedule. */
2395
+ /**
2396
+ * Generate the next invoice now instead of waiting for the schedule.
2397
+ *
2398
+ * @param recurringInvoiceId - Recurring invoice UUID.
2399
+ * @returns The generated `invoice_id` and the `next_generation` date.
2400
+ */
1371
2401
  async generateNow(recurringInvoiceId) {
1372
2402
  const { data } = await this.client.POST("/v1/companies/{company_id}/recurring-invoices/{recurring_invoice_id}/generate", {
1373
2403
  params: { path: this.path({ recurring_invoice_id: recurringInvoiceId }) }
1374
2404
  });
1375
2405
  return data.data;
1376
2406
  }
2407
+ /**
2408
+ * Preview the next invoice the template will generate.
2409
+ *
2410
+ * @param recurringInvoiceId - Recurring invoice UUID.
2411
+ * @returns The invoice as it would be generated.
2412
+ */
1377
2413
  async nextOccurrence(recurringInvoiceId) {
1378
2414
  const { data } = await this.client.GET("/v1/companies/{company_id}/recurring-invoices/{recurring_invoice_id}/next-occurrence", {
1379
2415
  params: { path: this.path({ recurring_invoice_id: recurringInvoiceId }) }
1380
2416
  });
1381
2417
  return data.data;
1382
2418
  }
2419
+ /**
2420
+ * The generation history of the template: generated, skipped and failed occurrences.
2421
+ *
2422
+ * @param recurringInvoiceId - Recurring invoice UUID.
2423
+ * @param params - Pagination.
2424
+ * @returns The `history` entries.
2425
+ */
1383
2426
  async history(recurringInvoiceId, params) {
1384
2427
  const { data } = await this.client.GET("/v1/companies/{company_id}/recurring-invoices/{recurring_invoice_id}/history", {
1385
2428
  params: { path: this.path({ recurring_invoice_id: recurringInvoiceId }), query: params }
@@ -1392,13 +2435,23 @@ var CompanyTaxConfigurationResource = class {
1392
2435
  this.client = client;
1393
2436
  this.companyId = companyId;
1394
2437
  }
2438
+ /**
2439
+ * Get the tax configuration.
2440
+ *
2441
+ * @returns The company's tax defaults.
2442
+ */
1395
2443
  async get() {
1396
2444
  const { data } = await this.client.GET("/v1/companies/{company_id}/tax-configuration", {
1397
2445
  params: { path: { company_id: this.companyId } }
1398
2446
  });
1399
2447
  return data.data;
1400
2448
  }
1401
- /** Replaces the whole state — this is a `PUT`, not a merge. */
2449
+ /**
2450
+ * Replace the tax configuration — this is a `PUT`, not a merge: send the whole state.
2451
+ *
2452
+ * @param body - The complete tax configuration.
2453
+ * @returns The stored configuration.
2454
+ */
1402
2455
  async update(body) {
1403
2456
  const { data } = await this.client.PUT("/v1/companies/{company_id}/tax-configuration", {
1404
2457
  params: { path: { company_id: this.companyId } },
@@ -1412,13 +2465,23 @@ var CompanyVeriFactuConfigurationResource = class {
1412
2465
  this.client = client;
1413
2466
  this.companyId = companyId;
1414
2467
  }
2468
+ /**
2469
+ * Get the VeriFactu configuration of this NIF.
2470
+ *
2471
+ * @returns `enabled` and the server-resolved state of the NIF.
2472
+ */
1415
2473
  async get() {
1416
2474
  const { data } = await this.client.GET("/v1/companies/{company_id}/verifactu-configuration", {
1417
2475
  params: { path: { company_id: this.companyId } }
1418
2476
  });
1419
2477
  return data.data;
1420
2478
  }
1421
- /** Flip VeriFactu for this NIF. `enabled` is the only field you can write. */
2479
+ /**
2480
+ * Turn VeriFactu on or off for this NIF. `enabled` is the only field you can write.
2481
+ *
2482
+ * @param body - `{ enabled }`.
2483
+ * @returns The updated configuration.
2484
+ */
1422
2485
  async update(body) {
1423
2486
  const { data } = await this.client.PUT("/v1/companies/{company_id}/verifactu-configuration", {
1424
2487
  params: { path: { company_id: this.companyId } },
@@ -1444,7 +2507,11 @@ var BeeL = class {
1444
2507
  }
1445
2508
  /**
1446
2509
  * Returns a facade scoped to one company (NIF) — the explicit multi-NIF surface.
1447
- * All operations address the company in the path, no session focus needed.
2510
+ * All operations address the company in the path, no session focus needed. No request
2511
+ * is made; get the ids from `beel.account(accountId).companies.list()`.
2512
+ *
2513
+ * @param companyId - Company UUID (not its NIF).
2514
+ * @returns The company scope.
1448
2515
  *
1449
2516
  * @example
1450
2517
  * ```typescript
@@ -1456,8 +2523,12 @@ var BeeL = class {
1456
2523
  return new CompanyScope(this.raw, companyId);
1457
2524
  }
1458
2525
  /**
1459
- * Returns a facade scoped to one managed account — members, invitations,
1460
- * account webhooks, companies, usage. Symmetric with {@link company}.
2526
+ * Returns a facade scoped to one account — companies, members, invitations, account
2527
+ * webhooks, usage. Symmetric with {@link company}. No request is made; your own account
2528
+ * id is `(await beel.catalogs.identity()).account_id`.
2529
+ *
2530
+ * @param accountId - Account UUID.
2531
+ * @returns The account scope.
1461
2532
  *
1462
2533
  * @example
1463
2534
  * ```typescript
@@ -1474,6 +2545,10 @@ var BeeL = class {
1474
2545
  * @deprecated Relies on the deprecated session-focus PDF endpoint. Use
1475
2546
  * `beel.company(companyId).invoices.getPdf(invoiceId)` and fetch `download_url` instead.
1476
2547
  *
2548
+ * @param invoiceId - Invoice UUID.
2549
+ * @returns The PDF bytes and its file name.
2550
+ * @throws {Error} When downloading the file fails.
2551
+ *
1477
2552
  * @example
1478
2553
  * ```typescript
1479
2554
  * const { buffer, fileName } = await beel.downloadPdf('invoice-uuid');
@@ -1687,6 +2762,13 @@ var RepresentationSignedEvent;
1687
2762
  })(type = RepresentationSignedEvent2.type || (RepresentationSignedEvent2.type = {}));
1688
2763
  })(RepresentationSignedEvent || (RepresentationSignedEvent = {}));
1689
2764
 
2765
+ // src/generated-webhooks/models/VeriFactuRecordOperation.ts
2766
+ var VeriFactuRecordOperation = /* @__PURE__ */ ((VeriFactuRecordOperation2) => {
2767
+ VeriFactuRecordOperation2["REGISTRATION"] = "REGISTRATION";
2768
+ VeriFactuRecordOperation2["VOID"] = "VOID";
2769
+ return VeriFactuRecordOperation2;
2770
+ })(VeriFactuRecordOperation || {});
2771
+
1690
2772
  // src/generated-webhooks/models/VeriFactuStatusUpdatedEvent.ts
1691
2773
  var VeriFactuStatusUpdatedEvent;
1692
2774
  ((VeriFactuStatusUpdatedEvent2) => {
@@ -1724,33 +2806,86 @@ var WebhookEventType = /* @__PURE__ */ ((WebhookEventType2) => {
1724
2806
  var CustomerBuilder = class _CustomerBuilder {
1725
2807
  constructor() {
1726
2808
  }
2809
+ /**
2810
+ * Start a new builder.
2811
+ *
2812
+ * @returns An empty customer builder.
2813
+ */
1727
2814
  static create() {
1728
2815
  return new _CustomerBuilder();
1729
2816
  }
2817
+ /**
2818
+ * Legal name of the customer. Required.
2819
+ *
2820
+ * @param name - Legal name.
2821
+ * @returns This builder.
2822
+ */
1730
2823
  name(name) {
1731
2824
  this._name = name;
1732
2825
  return this;
1733
2826
  }
2827
+ /**
2828
+ * NIF/CIF of the customer. Required.
2829
+ *
2830
+ * @param nif - Spanish tax id.
2831
+ * @returns This builder.
2832
+ */
1734
2833
  nif(nif) {
1735
2834
  this._nif = nif;
1736
2835
  return this;
1737
2836
  }
2837
+ /**
2838
+ * Contact email.
2839
+ *
2840
+ * @param email - Email address.
2841
+ * @returns This builder.
2842
+ */
1738
2843
  email(email) {
1739
2844
  this._email = email;
1740
2845
  return this;
1741
2846
  }
2847
+ /**
2848
+ * Contact phone: 9 to 20 characters of digits, spaces, dashes, parentheses and a leading `+`.
2849
+ *
2850
+ * @param phone - Phone number.
2851
+ * @returns This builder.
2852
+ */
1742
2853
  phone(phone) {
1743
2854
  this._phone = phone;
1744
2855
  return this;
1745
2856
  }
2857
+ /**
2858
+ * Fiscal address. Required.
2859
+ *
2860
+ * @param street - Street name.
2861
+ * @param number - Street number.
2862
+ * @param postalCode - Postal code.
2863
+ * @param city - City.
2864
+ * @param province - Province.
2865
+ * @param country - Country name.
2866
+ * @param countryCode - ISO 3166-1 alpha-2 code. Default: `ES`.
2867
+ * @returns This builder.
2868
+ */
1746
2869
  address(street, number, postalCode, city, province, country, countryCode = "ES") {
1747
2870
  this._address = { street, number, postal_code: postalCode, city, province, country, country_code: countryCode };
1748
2871
  return this;
1749
2872
  }
2873
+ /**
2874
+ * Internal notes about the customer.
2875
+ *
2876
+ * @param notes - Free text.
2877
+ * @returns This builder.
2878
+ */
1750
2879
  notes(notes) {
1751
2880
  this._notes = notes;
1752
2881
  return this;
1753
2882
  }
2883
+ /**
2884
+ * Build the request body.
2885
+ *
2886
+ * @returns The `CreateCustomerRequest`.
2887
+ * @throws {Error} When the name, NIF or address is missing.
2888
+ */
1754
2889
  build() {
1755
2890
  if (!this._name || this._name.trim().length === 0) throw new Error("Legal name is required");
1756
2891
  if (!this._nif || this._nif.trim().length === 0) throw new Error("NIF/CIF is required");
@@ -1767,50 +2902,144 @@ var CustomerBuilder = class _CustomerBuilder {
1767
2902
  };
1768
2903
 
1769
2904
  // src/builders/invoice-builder.ts
2905
+ var NORMAL_LINE_TYPE = "NORMAL";
2906
+ var NO_DISCOUNT = 0;
2907
+ function toIsoDate(date) {
2908
+ return date instanceof Date ? date.toISOString().split("T")[0] : date;
2909
+ }
1770
2910
  var InvoiceBuilder = class _InvoiceBuilder {
1771
2911
  constructor() {
1772
2912
  this._type = "STANDARD";
1773
2913
  this._lines = [];
1774
2914
  }
2915
+ /**
2916
+ * Start a new builder.
2917
+ *
2918
+ * @returns An empty `STANDARD` invoice builder.
2919
+ */
1775
2920
  static create() {
1776
2921
  return new _InvoiceBuilder();
1777
2922
  }
2923
+ /**
2924
+ * Set the invoice type. Default: `STANDARD`.
2925
+ *
2926
+ * @param type - `STANDARD`, `SIMPLIFIED` or `PROFORMA` (correctives use `createCorrective`).
2927
+ * @returns This builder.
2928
+ */
1778
2929
  type(type) {
1779
2930
  this._type = type;
1780
2931
  return this;
1781
2932
  }
2933
+ /**
2934
+ * Invoice a registered customer.
2935
+ *
2936
+ * @param customerId - Customer UUID.
2937
+ * @returns This builder.
2938
+ */
1782
2939
  forCustomer(customerId) {
1783
2940
  this._customerId = customerId;
1784
2941
  return this;
1785
2942
  }
2943
+ /**
2944
+ * Date the operation took place, when it differs from the issue date.
2945
+ *
2946
+ * @param date - A `Date` or a `YYYY-MM-DD` string.
2947
+ * @returns This builder.
2948
+ */
1786
2949
  operationDate(date) {
1787
- this._operationDate = date instanceof Date ? date.toISOString().split("T")[0] : date;
2950
+ this._operationDate = toIsoDate(date);
1788
2951
  return this;
1789
2952
  }
2953
+ /**
2954
+ * Payment due date.
2955
+ *
2956
+ * @param date - A `Date` or a `YYYY-MM-DD` string.
2957
+ * @returns This builder.
2958
+ */
1790
2959
  dueDate(date) {
1791
- this._dueDate = date instanceof Date ? date.toISOString().split("T")[0] : date;
2960
+ this._dueDate = toIsoDate(date);
1792
2961
  return this;
1793
2962
  }
1794
- addLine(description, quantity, unitPrice, discountPercentage = 0) {
1795
- this._lines.push({ line_type: "NORMAL", description, quantity, unit_price: unitPrice, discount_percentage: discountPercentage });
2963
+ /**
2964
+ * Main tax applied to every line added with {@link addLine} after this call, unless the
2965
+ * line passes its own.
2966
+ *
2967
+ * @param tax - For example `{ type: 'IVA', percentage: 21, regime_key: '01' }`.
2968
+ * @returns This builder.
2969
+ */
2970
+ mainTax(tax) {
2971
+ this._mainTax = tax;
2972
+ return this;
2973
+ }
2974
+ /**
2975
+ * Add a `NORMAL` line.
2976
+ *
2977
+ * @param description - What is invoiced.
2978
+ * @param quantity - Units.
2979
+ * @param unitPrice - Price per unit before taxes.
2980
+ * @param discountPercentage - Discount, 0–100. Default: `0`.
2981
+ * @param mainTax - Tax of this line; defaults to the one set with {@link mainTax}. The API
2982
+ * rejects a `NORMAL` line without one.
2983
+ * @returns This builder.
2984
+ */
2985
+ addLine(description, quantity, unitPrice, discountPercentage = NO_DISCOUNT, mainTax) {
2986
+ const tax = mainTax ?? this._mainTax;
2987
+ this._lines.push({
2988
+ line_type: NORMAL_LINE_TYPE,
2989
+ description,
2990
+ quantity,
2991
+ unit_price: unitPrice,
2992
+ discount_percentage: discountPercentage,
2993
+ ...tax ? { main_tax: tax } : {}
2994
+ });
1796
2995
  return this;
1797
2996
  }
2997
+ /**
2998
+ * Add a line exactly as given — any line type or pricing mode.
2999
+ *
3000
+ * @param line - A line of `CreateInvoiceRequest`.
3001
+ * @returns This builder.
3002
+ */
1798
3003
  addLineObject(line) {
1799
3004
  this._lines.push(line);
1800
3005
  return this;
1801
3006
  }
3007
+ /**
3008
+ * Notes printed on the invoice.
3009
+ *
3010
+ * @param notes - Free text.
3011
+ * @returns This builder.
3012
+ */
1802
3013
  notes(notes) {
1803
3014
  this._notes = notes;
1804
3015
  return this;
1805
3016
  }
3017
+ /**
3018
+ * Number the invoice in this series instead of the default one.
3019
+ *
3020
+ * @param id - Series UUID.
3021
+ * @returns This builder.
3022
+ */
1806
3023
  series(id) {
1807
3024
  this._seriesId = id;
1808
3025
  return this;
1809
3026
  }
3027
+ /**
3028
+ * Your own key/value pairs, filterable when listing.
3029
+ *
3030
+ * @param data - Metadata to store with the invoice.
3031
+ * @returns This builder.
3032
+ */
1810
3033
  metadata(data) {
1811
3034
  this._metadata = data;
1812
3035
  return this;
1813
3036
  }
3037
+ /**
3038
+ * Build the request body.
3039
+ *
3040
+ * @returns The `CreateInvoiceRequest`.
3041
+ * @throws {Error} When there is no customer or no line.
3042
+ */
1814
3043
  build() {
1815
3044
  if (!this._customerId) throw new Error("Customer ID is required");
1816
3045
  if (this._lines.length === 0) throw new Error("At least one invoice line is required");
@@ -1839,6 +3068,7 @@ var InvoiceBuilder = class _InvoiceBuilder {
1839
3068
  BeeLApiError,
1840
3069
  BeeLAuthError,
1841
3070
  BeeLConflictError,
3071
+ BeeLErrorCodes,
1842
3072
  BeeLNotFoundError,
1843
3073
  BeeLRateLimitError,
1844
3074
  BeeLValidationError,
@@ -1855,7 +3085,9 @@ var InvoiceBuilder = class _InvoiceBuilder {
1855
3085
  CompanyTaxConfigurationResource,
1856
3086
  CompanyVeriFactuConfigurationResource,
1857
3087
  CustomerBuilder,
3088
+ EXTERNAL_REF_UNIQUE_INVOICE_TYPES,
1858
3089
  InvoiceBuilder,
3090
+ VeriFactuRecordOperation,
1859
3091
  VeriFactuSubmissionStatus,
1860
3092
  WebhookEventType,
1861
3093
  WebhookVerificationError,