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