@beel_es/sdk 1.3.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 +237 -29
- package/dist/index.d.mts +4875 -1235
- package/dist/index.d.ts +4875 -1235
- package/dist/index.js +1462 -184
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1460 -184
- 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 +11 -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 };
|
|
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;
|
|
204
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,24 +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
|
+
/**
|
|
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.
|
|
947
|
+
*/
|
|
591
948
|
async provision(body) {
|
|
592
949
|
const { data } = await this.client.POST("/v1/accounts", { body });
|
|
593
950
|
return data.data;
|
|
594
951
|
}
|
|
595
|
-
/**
|
|
952
|
+
/**
|
|
953
|
+
* Get a managed account.
|
|
954
|
+
*
|
|
955
|
+
* @param accountId - Account UUID.
|
|
956
|
+
* @returns The account summary.
|
|
957
|
+
*/
|
|
596
958
|
async get(accountId) {
|
|
597
959
|
const { data } = await this.client.GET("/v1/accounts/{account_id}", {
|
|
598
960
|
params: { path: { account_id: accountId } }
|
|
599
961
|
});
|
|
600
962
|
return data.data;
|
|
601
963
|
}
|
|
602
|
-
/**
|
|
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
|
+
*/
|
|
603
970
|
scope(accountId) {
|
|
604
971
|
return new AccountScope(this.client, accountId);
|
|
605
972
|
}
|
|
@@ -616,28 +983,49 @@ var AccountScope = class {
|
|
|
616
983
|
path() {
|
|
617
984
|
return { account_id: this.accountId };
|
|
618
985
|
}
|
|
619
|
-
/**
|
|
986
|
+
/**
|
|
987
|
+
* Get the account summary.
|
|
988
|
+
*
|
|
989
|
+
* @returns The account summary.
|
|
990
|
+
*/
|
|
620
991
|
async get() {
|
|
621
992
|
const { data } = await this.client.GET("/v1/accounts/{account_id}", { params: { path: this.path() } });
|
|
622
993
|
return data.data;
|
|
623
994
|
}
|
|
624
|
-
/**
|
|
995
|
+
/**
|
|
996
|
+
* Provisioning usage counters for billing: provisioned accounts and NIFs.
|
|
997
|
+
*
|
|
998
|
+
* @returns `provisioned_accounts` and `nifs`.
|
|
999
|
+
*/
|
|
625
1000
|
async usage() {
|
|
626
1001
|
const { data } = await this.client.GET("/v1/accounts/{account_id}/usage", { params: { path: this.path() } });
|
|
627
1002
|
return data.data;
|
|
628
1003
|
}
|
|
629
|
-
/**
|
|
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
|
+
*/
|
|
630
1010
|
async changeAccessLevel(body) {
|
|
631
1011
|
await this.client.PATCH("/v1/accounts/{account_id}/access-level", {
|
|
632
1012
|
params: { path: this.path() },
|
|
633
1013
|
body
|
|
634
1014
|
});
|
|
635
1015
|
}
|
|
636
|
-
/**
|
|
1016
|
+
/**
|
|
1017
|
+
* End your management of this account: you lose access, and the holder keeps the
|
|
1018
|
+
* account, its NIFs and its invoices.
|
|
1019
|
+
*/
|
|
637
1020
|
async endManagement() {
|
|
638
1021
|
await this.client.DELETE("/v1/accounts/{account_id}/management", { params: { path: this.path() } });
|
|
639
1022
|
}
|
|
640
|
-
/**
|
|
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
|
+
*/
|
|
641
1029
|
async createClaimToken(body) {
|
|
642
1030
|
const { data } = await this.client.POST("/v1/accounts/{account_id}/claim-tokens", {
|
|
643
1031
|
params: { path: this.path() },
|
|
@@ -645,7 +1033,11 @@ var AccountScope = class {
|
|
|
645
1033
|
});
|
|
646
1034
|
return data.data;
|
|
647
1035
|
}
|
|
648
|
-
/**
|
|
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
|
+
*/
|
|
649
1041
|
async setOwner(body) {
|
|
650
1042
|
await this.client.PUT("/v1/accounts/{account_id}/owner", {
|
|
651
1043
|
params: { path: this.path() },
|
|
@@ -658,19 +1050,36 @@ var AccountMembersResource = class {
|
|
|
658
1050
|
this.client = client;
|
|
659
1051
|
this.accountId = accountId;
|
|
660
1052
|
}
|
|
1053
|
+
/**
|
|
1054
|
+
* List the account's members.
|
|
1055
|
+
*
|
|
1056
|
+
* @returns The members (`data.members` of the response), as an array.
|
|
1057
|
+
*/
|
|
661
1058
|
async list() {
|
|
662
1059
|
const { data } = await this.client.GET("/v1/accounts/{account_id}/members", {
|
|
663
1060
|
params: { path: { account_id: this.accountId } }
|
|
664
1061
|
});
|
|
665
1062
|
return data.data.members;
|
|
666
1063
|
}
|
|
1064
|
+
/**
|
|
1065
|
+
* Get one member.
|
|
1066
|
+
*
|
|
1067
|
+
* @param memberId - Member UUID.
|
|
1068
|
+
* @returns The member.
|
|
1069
|
+
*/
|
|
667
1070
|
async get(memberId) {
|
|
668
1071
|
const { data } = await this.client.GET("/v1/accounts/{account_id}/members/{member_id}", {
|
|
669
1072
|
params: { path: { account_id: this.accountId, member_id: memberId } }
|
|
670
1073
|
});
|
|
671
1074
|
return data.data;
|
|
672
1075
|
}
|
|
673
|
-
/**
|
|
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
|
+
*/
|
|
674
1083
|
async update(memberId, body) {
|
|
675
1084
|
const { data } = await this.client.PATCH("/v1/accounts/{account_id}/members/{member_id}", {
|
|
676
1085
|
params: { path: { account_id: this.accountId, member_id: memberId } },
|
|
@@ -678,20 +1087,36 @@ var AccountMembersResource = class {
|
|
|
678
1087
|
});
|
|
679
1088
|
return data.data;
|
|
680
1089
|
}
|
|
681
|
-
/**
|
|
1090
|
+
/**
|
|
1091
|
+
* Remove a member from the account.
|
|
1092
|
+
*
|
|
1093
|
+
* @param memberId - Member UUID.
|
|
1094
|
+
*/
|
|
682
1095
|
async remove(memberId) {
|
|
683
1096
|
await this.client.DELETE("/v1/accounts/{account_id}/members/{member_id}", {
|
|
684
1097
|
params: { path: { account_id: this.accountId, member_id: memberId } }
|
|
685
1098
|
});
|
|
686
1099
|
}
|
|
687
|
-
/**
|
|
1100
|
+
/**
|
|
1101
|
+
* List a member's per-company grants.
|
|
1102
|
+
*
|
|
1103
|
+
* @param memberId - Member UUID.
|
|
1104
|
+
* @returns The `grants` and their `pagination`.
|
|
1105
|
+
*/
|
|
688
1106
|
async listGrants(memberId) {
|
|
689
1107
|
const { data } = await this.client.GET("/v1/accounts/{account_id}/members/{member_id}/grants", {
|
|
690
1108
|
params: { path: { account_id: this.accountId, member_id: memberId } }
|
|
691
1109
|
});
|
|
692
1110
|
return data.data;
|
|
693
1111
|
}
|
|
694
|
-
/**
|
|
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
|
+
*/
|
|
695
1120
|
async putGrant(memberId, companyId, body) {
|
|
696
1121
|
const { data } = await this.client.PUT("/v1/accounts/{account_id}/members/{member_id}/grants/{company_id}", {
|
|
697
1122
|
params: { path: { account_id: this.accountId, member_id: memberId, company_id: companyId } },
|
|
@@ -699,7 +1124,12 @@ var AccountMembersResource = class {
|
|
|
699
1124
|
});
|
|
700
1125
|
return data.data;
|
|
701
1126
|
}
|
|
702
|
-
/**
|
|
1127
|
+
/**
|
|
1128
|
+
* Revoke a member's access to one company.
|
|
1129
|
+
*
|
|
1130
|
+
* @param memberId - Member UUID.
|
|
1131
|
+
* @param companyId - Company UUID.
|
|
1132
|
+
*/
|
|
703
1133
|
async removeGrant(memberId, companyId) {
|
|
704
1134
|
await this.client.DELETE("/v1/accounts/{account_id}/members/{member_id}/grants/{company_id}", {
|
|
705
1135
|
params: { path: { account_id: this.accountId, member_id: memberId, company_id: companyId } }
|
|
@@ -711,12 +1141,23 @@ var AccountInvitationsResource = class {
|
|
|
711
1141
|
this.client = client;
|
|
712
1142
|
this.accountId = accountId;
|
|
713
1143
|
}
|
|
1144
|
+
/**
|
|
1145
|
+
* List the account's invitations.
|
|
1146
|
+
*
|
|
1147
|
+
* @returns The invitations.
|
|
1148
|
+
*/
|
|
714
1149
|
async list() {
|
|
715
1150
|
const { data } = await this.client.GET("/v1/accounts/{account_id}/invitations", {
|
|
716
1151
|
params: { path: { account_id: this.accountId } }
|
|
717
1152
|
});
|
|
718
1153
|
return data.data;
|
|
719
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
|
+
*/
|
|
720
1161
|
async create(body) {
|
|
721
1162
|
const { data } = await this.client.POST("/v1/accounts/{account_id}/invitations", {
|
|
722
1163
|
params: { path: { account_id: this.accountId } },
|
|
@@ -724,12 +1165,23 @@ var AccountInvitationsResource = class {
|
|
|
724
1165
|
});
|
|
725
1166
|
return data.data;
|
|
726
1167
|
}
|
|
1168
|
+
/**
|
|
1169
|
+
* Get one invitation.
|
|
1170
|
+
*
|
|
1171
|
+
* @param invitationId - Invitation UUID.
|
|
1172
|
+
* @returns The invitation.
|
|
1173
|
+
*/
|
|
727
1174
|
async get(invitationId) {
|
|
728
1175
|
const { data } = await this.client.GET("/v1/accounts/{account_id}/invitations/{invitation_id}", {
|
|
729
1176
|
params: { path: { account_id: this.accountId, invitation_id: invitationId } }
|
|
730
1177
|
});
|
|
731
1178
|
return data.data;
|
|
732
1179
|
}
|
|
1180
|
+
/**
|
|
1181
|
+
* Revoke a `PENDING` invitation, so its link stops working.
|
|
1182
|
+
*
|
|
1183
|
+
* @param invitationId - Invitation UUID.
|
|
1184
|
+
*/
|
|
733
1185
|
async revoke(invitationId) {
|
|
734
1186
|
await this.client.DELETE("/v1/accounts/{account_id}/invitations/{invitation_id}", {
|
|
735
1187
|
params: { path: { account_id: this.accountId, invitation_id: invitationId } }
|
|
@@ -741,12 +1193,24 @@ var AccountWebhooksResource = class {
|
|
|
741
1193
|
this.client = client;
|
|
742
1194
|
this.accountId = accountId;
|
|
743
1195
|
}
|
|
1196
|
+
/**
|
|
1197
|
+
* List the webhook subscriptions.
|
|
1198
|
+
*
|
|
1199
|
+
* @param params - Pagination.
|
|
1200
|
+
* @returns The `webhooks` and their `pagination`.
|
|
1201
|
+
*/
|
|
744
1202
|
async list(params) {
|
|
745
1203
|
const { data } = await this.client.GET("/v1/accounts/{account_id}/webhooks", {
|
|
746
1204
|
params: { path: { account_id: this.accountId }, query: params }
|
|
747
1205
|
});
|
|
748
1206
|
return data.data;
|
|
749
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
|
+
*/
|
|
750
1214
|
async create(body) {
|
|
751
1215
|
const { data } = await this.client.POST("/v1/accounts/{account_id}/webhooks", {
|
|
752
1216
|
params: { path: { account_id: this.accountId } },
|
|
@@ -754,12 +1218,25 @@ var AccountWebhooksResource = class {
|
|
|
754
1218
|
});
|
|
755
1219
|
return data.data;
|
|
756
1220
|
}
|
|
1221
|
+
/**
|
|
1222
|
+
* Get one webhook subscription.
|
|
1223
|
+
*
|
|
1224
|
+
* @param webhookId - Subscription UUID.
|
|
1225
|
+
* @returns The subscription.
|
|
1226
|
+
*/
|
|
757
1227
|
async get(webhookId) {
|
|
758
1228
|
const { data } = await this.client.GET("/v1/accounts/{account_id}/webhooks/{webhook_id}", {
|
|
759
1229
|
params: { path: { account_id: this.accountId, webhook_id: webhookId } }
|
|
760
1230
|
});
|
|
761
1231
|
return data.data;
|
|
762
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
|
+
*/
|
|
763
1240
|
async update(webhookId, body) {
|
|
764
1241
|
const { data } = await this.client.PATCH("/v1/accounts/{account_id}/webhooks/{webhook_id}", {
|
|
765
1242
|
params: { path: { account_id: this.accountId, webhook_id: webhookId } },
|
|
@@ -767,31 +1244,60 @@ var AccountWebhooksResource = class {
|
|
|
767
1244
|
});
|
|
768
1245
|
return data.data;
|
|
769
1246
|
}
|
|
1247
|
+
/**
|
|
1248
|
+
* Delete a webhook subscription.
|
|
1249
|
+
*
|
|
1250
|
+
* @param webhookId - Subscription UUID.
|
|
1251
|
+
*/
|
|
770
1252
|
async delete(webhookId) {
|
|
771
1253
|
await this.client.DELETE("/v1/accounts/{account_id}/webhooks/{webhook_id}", {
|
|
772
1254
|
params: { path: { account_id: this.accountId, webhook_id: webhookId } }
|
|
773
1255
|
});
|
|
774
1256
|
}
|
|
775
|
-
/**
|
|
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
|
+
*/
|
|
776
1263
|
async test(webhookId) {
|
|
777
1264
|
const { data } = await this.client.POST("/v1/accounts/{account_id}/webhooks/{webhook_id}/test", {
|
|
778
1265
|
params: { path: { account_id: this.accountId, webhook_id: webhookId } }
|
|
779
1266
|
});
|
|
780
1267
|
return data.data;
|
|
781
1268
|
}
|
|
782
|
-
/**
|
|
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
|
+
*/
|
|
783
1275
|
async rotateSecret(webhookId) {
|
|
784
1276
|
const { data } = await this.client.POST("/v1/accounts/{account_id}/webhooks/{webhook_id}/secret", {
|
|
785
1277
|
params: { path: { account_id: this.accountId, webhook_id: webhookId } }
|
|
786
1278
|
});
|
|
787
1279
|
return data.data;
|
|
788
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
|
+
*/
|
|
789
1288
|
async listDeliveries(webhookId, params) {
|
|
790
1289
|
const { data } = await this.client.GET("/v1/accounts/{account_id}/webhooks/{webhook_id}/deliveries", {
|
|
791
1290
|
params: { path: { account_id: this.accountId, webhook_id: webhookId }, query: params }
|
|
792
1291
|
});
|
|
793
1292
|
return data.data;
|
|
794
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
|
+
*/
|
|
795
1301
|
async retryDelivery(webhookId, deliveryId) {
|
|
796
1302
|
const { data } = await this.client.POST("/v1/accounts/{account_id}/webhooks/{webhook_id}/deliveries/{delivery_id}/retry", {
|
|
797
1303
|
params: { path: { account_id: this.accountId, webhook_id: webhookId, delivery_id: deliveryId } }
|
|
@@ -804,6 +1310,19 @@ var AccountCompaniesResource = class {
|
|
|
804
1310
|
this.client = client;
|
|
805
1311
|
this.accountId = accountId;
|
|
806
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
|
+
*/
|
|
807
1326
|
async list(params) {
|
|
808
1327
|
const { data } = await this.client.GET("/v1/accounts/{account_id}/companies", {
|
|
809
1328
|
params: { path: { account_id: this.accountId }, query: params }
|
|
@@ -813,7 +1332,12 @@ var AccountCompaniesResource = class {
|
|
|
813
1332
|
pagination: data.data?.pagination
|
|
814
1333
|
};
|
|
815
1334
|
}
|
|
816
|
-
/**
|
|
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
|
+
*/
|
|
817
1341
|
async create(body) {
|
|
818
1342
|
const { data } = await this.client.POST("/v1/accounts/{account_id}/companies", {
|
|
819
1343
|
params: { path: { account_id: this.accountId } },
|
|
@@ -821,7 +1345,11 @@ var AccountCompaniesResource = class {
|
|
|
821
1345
|
});
|
|
822
1346
|
return data.data;
|
|
823
1347
|
}
|
|
824
|
-
/**
|
|
1348
|
+
/**
|
|
1349
|
+
* Per-company invoice stats: how many fiscal documents each issued, and when last.
|
|
1350
|
+
*
|
|
1351
|
+
* @returns One entry per company.
|
|
1352
|
+
*/
|
|
825
1353
|
async stats() {
|
|
826
1354
|
const { data } = await this.client.GET("/v1/accounts/{account_id}/companies/stats", {
|
|
827
1355
|
params: { path: { account_id: this.accountId } }
|
|
@@ -830,6 +1358,38 @@ var AccountCompaniesResource = class {
|
|
|
830
1358
|
}
|
|
831
1359
|
};
|
|
832
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
|
+
|
|
833
1393
|
// src/resources/payment-connections.ts
|
|
834
1394
|
var CompanyPaymentConnectionsResource = class {
|
|
835
1395
|
constructor(client, companyId) {
|
|
@@ -839,7 +1399,11 @@ var CompanyPaymentConnectionsResource = class {
|
|
|
839
1399
|
path() {
|
|
840
1400
|
return { company_id: this.companyId };
|
|
841
1401
|
}
|
|
842
|
-
/**
|
|
1402
|
+
/**
|
|
1403
|
+
* Every payment connection of this company.
|
|
1404
|
+
*
|
|
1405
|
+
* @returns The `connections`.
|
|
1406
|
+
*/
|
|
843
1407
|
async list() {
|
|
844
1408
|
const { data } = await this.client.GET("/v1/companies/{company_id}/payment-connections", {
|
|
845
1409
|
params: { path: this.path() }
|
|
@@ -850,6 +1414,9 @@ var CompanyPaymentConnectionsResource = class {
|
|
|
850
1414
|
* Start an authorization and get the URL where the NIF's holder approves it.
|
|
851
1415
|
*
|
|
852
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.
|
|
853
1420
|
*/
|
|
854
1421
|
async authorize(body) {
|
|
855
1422
|
const { data } = await this.client.POST(
|
|
@@ -858,7 +1425,13 @@ var CompanyPaymentConnectionsResource = class {
|
|
|
858
1425
|
);
|
|
859
1426
|
return data.data;
|
|
860
1427
|
}
|
|
861
|
-
/**
|
|
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
|
+
*/
|
|
862
1435
|
async update(connectionId, body) {
|
|
863
1436
|
const { data } = await this.client.PATCH(
|
|
864
1437
|
"/v1/companies/{company_id}/payment-connections/{connection_id}",
|
|
@@ -869,13 +1442,20 @@ var CompanyPaymentConnectionsResource = class {
|
|
|
869
1442
|
/**
|
|
870
1443
|
* Disconnect one connection. Tokens are revoked and auto-invoicing stops;
|
|
871
1444
|
* already-issued invoices are untouched.
|
|
1445
|
+
*
|
|
1446
|
+
* @param connectionId - Connection UUID.
|
|
872
1447
|
*/
|
|
873
1448
|
async disconnect(connectionId) {
|
|
874
1449
|
await this.client.DELETE("/v1/companies/{company_id}/payment-connections/{connection_id}", {
|
|
875
1450
|
params: { path: { ...this.path(), connection_id: connectionId } }
|
|
876
1451
|
});
|
|
877
1452
|
}
|
|
878
|
-
/**
|
|
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
|
+
*/
|
|
879
1459
|
events(connectionId) {
|
|
880
1460
|
return new CompanyPaymentEventsResource(this.client, this.companyId, connectionId);
|
|
881
1461
|
}
|
|
@@ -893,6 +1473,9 @@ var CompanyPaymentEventsResource = class {
|
|
|
893
1473
|
* Events of the connection, most recent first. Nothing is hidden by default:
|
|
894
1474
|
* skipped events, duplicates and disputes are all returned — narrow with the
|
|
895
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`.
|
|
896
1479
|
*/
|
|
897
1480
|
async list(params) {
|
|
898
1481
|
const { data } = await this.client.GET(
|
|
@@ -901,7 +1484,12 @@ var CompanyPaymentEventsResource = class {
|
|
|
901
1484
|
);
|
|
902
1485
|
return data.data;
|
|
903
1486
|
}
|
|
904
|
-
/**
|
|
1487
|
+
/**
|
|
1488
|
+
* Get one event.
|
|
1489
|
+
*
|
|
1490
|
+
* @param eventId - Event UUID.
|
|
1491
|
+
* @returns The event.
|
|
1492
|
+
*/
|
|
905
1493
|
async get(eventId) {
|
|
906
1494
|
const { data } = await this.client.GET(
|
|
907
1495
|
"/v1/companies/{company_id}/payment-connections/{connection_id}/events/{event_id}",
|
|
@@ -913,6 +1501,9 @@ var CompanyPaymentEventsResource = class {
|
|
|
913
1501
|
* Reprocess an event whose automatic invoicing didn't complete, applying the NIF's
|
|
914
1502
|
* **current** configuration. Only retryable states qualify and the retry budget is
|
|
915
1503
|
* finite: otherwise `400`.
|
|
1504
|
+
*
|
|
1505
|
+
* @param eventId - Event UUID.
|
|
1506
|
+
* @returns The event after the retry.
|
|
916
1507
|
*/
|
|
917
1508
|
async retry(eventId) {
|
|
918
1509
|
const { data } = await this.client.POST(
|
|
@@ -923,7 +1514,10 @@ var CompanyPaymentEventsResource = class {
|
|
|
923
1514
|
}
|
|
924
1515
|
/**
|
|
925
1516
|
* Build a **draft** invoice from an event that couldn't be invoiced automatically,
|
|
926
|
-
* 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`.
|
|
927
1521
|
*/
|
|
928
1522
|
async draft(eventId) {
|
|
929
1523
|
const { data } = await this.client.POST(
|
|
@@ -932,7 +1526,12 @@ var CompanyPaymentEventsResource = class {
|
|
|
932
1526
|
);
|
|
933
1527
|
return data.data;
|
|
934
1528
|
}
|
|
935
|
-
/**
|
|
1529
|
+
/**
|
|
1530
|
+
* Mark an event as dealt with outside the automatic flow.
|
|
1531
|
+
*
|
|
1532
|
+
* @param eventId - Event UUID.
|
|
1533
|
+
* @returns The resolved event.
|
|
1534
|
+
*/
|
|
936
1535
|
async resolve(eventId) {
|
|
937
1536
|
const { data } = await this.client.POST(
|
|
938
1537
|
"/v1/companies/{company_id}/payment-connections/{connection_id}/events/{event_id}/resolve",
|
|
@@ -940,7 +1539,12 @@ var CompanyPaymentEventsResource = class {
|
|
|
940
1539
|
);
|
|
941
1540
|
return data.data;
|
|
942
1541
|
}
|
|
943
|
-
/**
|
|
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
|
+
*/
|
|
944
1548
|
async discard(eventId) {
|
|
945
1549
|
const { data } = await this.client.POST(
|
|
946
1550
|
"/v1/companies/{company_id}/payment-connections/{connection_id}/events/{event_id}/discard",
|
|
@@ -948,7 +1552,12 @@ var CompanyPaymentEventsResource = class {
|
|
|
948
1552
|
);
|
|
949
1553
|
return data.data;
|
|
950
1554
|
}
|
|
951
|
-
/**
|
|
1555
|
+
/**
|
|
1556
|
+
* Bring a discarded event back into the list.
|
|
1557
|
+
*
|
|
1558
|
+
* @param eventId - Event UUID.
|
|
1559
|
+
* @returns The restored event.
|
|
1560
|
+
*/
|
|
952
1561
|
async restore(eventId) {
|
|
953
1562
|
const { data } = await this.client.POST(
|
|
954
1563
|
"/v1/companies/{company_id}/payment-connections/{connection_id}/events/{event_id}/restore",
|
|
@@ -958,6 +1567,44 @@ var CompanyPaymentEventsResource = class {
|
|
|
958
1567
|
}
|
|
959
1568
|
};
|
|
960
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
|
+
}
|
|
1607
|
+
|
|
961
1608
|
// src/resources/company.ts
|
|
962
1609
|
var CompanyScope = class {
|
|
963
1610
|
constructor(client, companyId) {
|
|
@@ -975,14 +1622,24 @@ var CompanyScope = class {
|
|
|
975
1622
|
path() {
|
|
976
1623
|
return { company_id: this.companyId };
|
|
977
1624
|
}
|
|
978
|
-
/**
|
|
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
|
+
*/
|
|
979
1631
|
async get(params) {
|
|
980
1632
|
const { data } = await this.client.GET("/v1/companies/{company_id}", {
|
|
981
1633
|
params: { path: this.path(), query: params }
|
|
982
1634
|
});
|
|
983
1635
|
return data.data;
|
|
984
1636
|
}
|
|
985
|
-
/**
|
|
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
|
+
*/
|
|
986
1643
|
async update(body) {
|
|
987
1644
|
const { data } = await this.client.PATCH("/v1/companies/{company_id}", {
|
|
988
1645
|
params: { path: this.path() },
|
|
@@ -990,18 +1647,30 @@ var CompanyScope = class {
|
|
|
990
1647
|
});
|
|
991
1648
|
return data.data;
|
|
992
1649
|
}
|
|
993
|
-
/**
|
|
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
|
+
*/
|
|
994
1654
|
async delete() {
|
|
995
1655
|
await this.client.DELETE("/v1/companies/{company_id}", { params: { path: this.path() } });
|
|
996
1656
|
}
|
|
997
|
-
/**
|
|
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
|
+
*/
|
|
998
1663
|
async fiscalSummary(params) {
|
|
999
1664
|
const { data } = await this.client.GET("/v1/companies/{company_id}/fiscal-summary", {
|
|
1000
1665
|
params: { path: this.path(), query: params }
|
|
1001
1666
|
});
|
|
1002
1667
|
return data.data;
|
|
1003
1668
|
}
|
|
1004
|
-
/**
|
|
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
|
+
*/
|
|
1005
1674
|
async issuingReadiness() {
|
|
1006
1675
|
const { data } = await this.client.GET("/v1/companies/{company_id}/issuing-readiness", {
|
|
1007
1676
|
params: { path: this.path() }
|
|
@@ -1016,10 +1685,16 @@ var CompanyInvoicesResource = class {
|
|
|
1016
1685
|
this.schedule = new CompanyInvoiceScheduleResource(client, companyId);
|
|
1017
1686
|
}
|
|
1018
1687
|
/**
|
|
1019
|
-
* 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.
|
|
1020
1694
|
*/
|
|
1021
|
-
async derive(body) {
|
|
1695
|
+
async derive(body, options) {
|
|
1022
1696
|
const { data } = await this.client.POST("/v1/companies/{company_id}/invoices/derivations", {
|
|
1697
|
+
...toRequestInit(options),
|
|
1023
1698
|
params: { path: { company_id: this.companyId } },
|
|
1024
1699
|
body
|
|
1025
1700
|
});
|
|
@@ -1028,88 +1703,309 @@ var CompanyInvoicesResource = class {
|
|
|
1028
1703
|
path(rest) {
|
|
1029
1704
|
return { company_id: this.companyId, ...rest };
|
|
1030
1705
|
}
|
|
1031
|
-
|
|
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) {
|
|
1032
1720
|
const { data } = await this.client.GET("/v1/companies/{company_id}/invoices", {
|
|
1721
|
+
...toRequestInit(options),
|
|
1033
1722
|
params: { path: this.path(), query: params }
|
|
1034
1723
|
});
|
|
1035
1724
|
return data.data;
|
|
1036
1725
|
}
|
|
1037
|
-
|
|
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) {
|
|
1038
1754
|
const { data } = await this.client.POST("/v1/companies/{company_id}/invoices", {
|
|
1755
|
+
...toRequestInit(options),
|
|
1039
1756
|
params: { path: this.path(), query: params },
|
|
1040
1757
|
body
|
|
1041
1758
|
});
|
|
1042
1759
|
return data.data;
|
|
1043
1760
|
}
|
|
1044
|
-
|
|
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) {
|
|
1045
1814
|
const { data } = await this.client.GET("/v1/companies/{company_id}/invoices/{invoice_id}", {
|
|
1815
|
+
...toRequestInit(options),
|
|
1046
1816
|
params: { path: this.path({ invoice_id: invoiceId }) }
|
|
1047
1817
|
});
|
|
1048
1818
|
return data.data;
|
|
1049
1819
|
}
|
|
1050
|
-
/**
|
|
1051
|
-
|
|
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) {
|
|
1052
1830
|
const { data } = await this.client.PATCH("/v1/companies/{company_id}/invoices/{invoice_id}", {
|
|
1831
|
+
...toRequestInit(options),
|
|
1053
1832
|
params: { path: this.path({ invoice_id: invoiceId }) },
|
|
1054
1833
|
body
|
|
1055
1834
|
});
|
|
1056
1835
|
return data.data;
|
|
1057
1836
|
}
|
|
1058
|
-
/**
|
|
1059
|
-
|
|
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) {
|
|
1060
1844
|
await this.client.DELETE("/v1/companies/{company_id}/invoices/{invoice_id}", {
|
|
1845
|
+
...toRequestInit(options),
|
|
1061
1846
|
params: { path: this.path({ invoice_id: invoiceId }) }
|
|
1062
1847
|
});
|
|
1063
1848
|
}
|
|
1064
|
-
/**
|
|
1065
|
-
|
|
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) {
|
|
1066
1859
|
const { data } = await this.client.POST("/v1/companies/{company_id}/invoices/{invoice_id}/issue", {
|
|
1860
|
+
...toRequestInit(options),
|
|
1067
1861
|
params: { path: this.path({ invoice_id: invoiceId }), query: params }
|
|
1068
1862
|
});
|
|
1069
1863
|
return data.data;
|
|
1070
1864
|
}
|
|
1071
|
-
/**
|
|
1072
|
-
|
|
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) {
|
|
1073
1875
|
const { data } = await this.client.POST("/v1/companies/{company_id}/invoices/{invoice_id}/void", {
|
|
1876
|
+
...toRequestInit(options),
|
|
1074
1877
|
params: { path: this.path({ invoice_id: invoiceId }) },
|
|
1075
1878
|
body
|
|
1076
1879
|
});
|
|
1077
1880
|
return data.data;
|
|
1078
1881
|
}
|
|
1079
|
-
/**
|
|
1080
|
-
|
|
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) {
|
|
1081
1903
|
const { data } = await this.client.POST("/v1/companies/{company_id}/invoices/{invoice_id}/corrective", {
|
|
1904
|
+
...toRequestInit(options),
|
|
1082
1905
|
params: { path: this.path({ invoice_id: invoiceId }) },
|
|
1083
1906
|
body
|
|
1084
1907
|
});
|
|
1085
1908
|
return data.data;
|
|
1086
1909
|
}
|
|
1087
|
-
/**
|
|
1088
|
-
|
|
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) {
|
|
1089
1919
|
const { data } = await this.client.POST("/v1/companies/{company_id}/invoices/{invoice_id}/convert-to-invoice", {
|
|
1920
|
+
...toRequestInit(options),
|
|
1090
1921
|
params: { path: this.path({ invoice_id: invoiceId }) },
|
|
1091
1922
|
body
|
|
1092
1923
|
});
|
|
1093
1924
|
return data.data;
|
|
1094
1925
|
}
|
|
1095
|
-
/**
|
|
1096
|
-
|
|
1926
|
+
/**
|
|
1927
|
+
* Issue a full invoice in exchange for one or more issued simplified invoices, when the
|
|
1928
|
+
* customer asks for an invoice with their details. It is not a corrective: the simplified
|
|
1929
|
+
* invoices become `VOIDED` with `void_cause: 'EXCHANGED'`, and the new `STANDARD` invoice
|
|
1930
|
+
* lists them in `replaced_invoice_ids`.
|
|
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
|
+
*
|
|
1936
|
+
* @example
|
|
1937
|
+
* ```typescript
|
|
1938
|
+
* const invoice = await company.invoices.createSimplifiedExchange({
|
|
1939
|
+
* simplified_invoice_ids: ['simplified-uuid'],
|
|
1940
|
+
* recipient: { customer_id: 'customer-uuid' },
|
|
1941
|
+
* });
|
|
1942
|
+
* ```
|
|
1943
|
+
*/
|
|
1944
|
+
async createSimplifiedExchange(body, options) {
|
|
1945
|
+
const { data } = await this.client.POST("/v1/companies/{company_id}/invoices/simplified-exchanges", {
|
|
1946
|
+
...toRequestInit(options),
|
|
1947
|
+
params: { path: this.path() },
|
|
1948
|
+
body
|
|
1949
|
+
});
|
|
1950
|
+
return data.data;
|
|
1951
|
+
}
|
|
1952
|
+
/**
|
|
1953
|
+
* The VeriFactu records of an invoice, oldest first: its registration and, if it was
|
|
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`.
|
|
1959
|
+
*/
|
|
1960
|
+
async verifactuRecords(invoiceId, options) {
|
|
1961
|
+
const { data } = await this.client.GET("/v1/companies/{company_id}/invoices/{invoice_id}/verifactu-records", {
|
|
1962
|
+
...toRequestInit(options),
|
|
1963
|
+
params: { path: this.path({ invoice_id: invoiceId }) }
|
|
1964
|
+
});
|
|
1965
|
+
return data.data.records;
|
|
1966
|
+
}
|
|
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) {
|
|
1097
1977
|
const { data } = await this.client.PUT("/v1/companies/{company_id}/invoices/{invoice_id}/status", {
|
|
1978
|
+
...toRequestInit(options),
|
|
1098
1979
|
params: { path: this.path({ invoice_id: invoiceId }) },
|
|
1099
1980
|
body
|
|
1100
1981
|
});
|
|
1101
1982
|
return data.data;
|
|
1102
1983
|
}
|
|
1103
|
-
/**
|
|
1104
|
-
|
|
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) {
|
|
1105
1992
|
const { data } = await this.client.GET("/v1/companies/{company_id}/invoices/{invoice_id}/pdf", {
|
|
1993
|
+
...toRequestInit(options),
|
|
1106
1994
|
params: { path: this.path({ invoice_id: invoiceId }) }
|
|
1107
1995
|
});
|
|
1108
1996
|
return data.data;
|
|
1109
1997
|
}
|
|
1110
|
-
/**
|
|
1111
|
-
|
|
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) {
|
|
1112
2007
|
const { data } = await this.client.POST("/v1/companies/{company_id}/invoices/{invoice_id}/send", {
|
|
2008
|
+
...toRequestInit(options),
|
|
1113
2009
|
params: { path: this.path({ invoice_id: invoiceId }) },
|
|
1114
2010
|
body
|
|
1115
2011
|
});
|
|
@@ -1121,6 +2017,12 @@ var CompanyInvoiceScheduleResource = class {
|
|
|
1121
2017
|
this.client = client;
|
|
1122
2018
|
this.companyId = companyId;
|
|
1123
2019
|
}
|
|
2020
|
+
/**
|
|
2021
|
+
* Get the schedule of an invoice.
|
|
2022
|
+
*
|
|
2023
|
+
* @param invoiceId - Invoice UUID.
|
|
2024
|
+
* @returns `scheduled_for` and `generation_mode`.
|
|
2025
|
+
*/
|
|
1124
2026
|
async get(invoiceId) {
|
|
1125
2027
|
const { data } = await this.client.GET(
|
|
1126
2028
|
"/v1/companies/{company_id}/invoices/{invoice_id}/schedule",
|
|
@@ -1131,6 +2033,10 @@ var CompanyInvoiceScheduleResource = class {
|
|
|
1131
2033
|
/**
|
|
1132
2034
|
* Set or move the schedule. One `PUT` replaces the three legacy calls
|
|
1133
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.
|
|
1134
2040
|
*/
|
|
1135
2041
|
async set(invoiceId, body) {
|
|
1136
2042
|
const { data } = await this.client.PUT(
|
|
@@ -1139,7 +2045,12 @@ var CompanyInvoiceScheduleResource = class {
|
|
|
1139
2045
|
);
|
|
1140
2046
|
return data.data;
|
|
1141
2047
|
}
|
|
1142
|
-
/**
|
|
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
|
+
*/
|
|
1143
2054
|
async clear(invoiceId) {
|
|
1144
2055
|
await this.client.DELETE("/v1/companies/{company_id}/invoices/{invoice_id}/schedule", {
|
|
1145
2056
|
params: { path: { company_id: this.companyId, invoice_id: invoiceId } }
|
|
@@ -1151,12 +2062,24 @@ var CompanyCustomersResource = class {
|
|
|
1151
2062
|
this.client = client;
|
|
1152
2063
|
this.companyId = companyId;
|
|
1153
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
|
+
*/
|
|
1154
2071
|
async list(params) {
|
|
1155
2072
|
const { data } = await this.client.GET("/v1/companies/{company_id}/customers", {
|
|
1156
2073
|
params: { path: { company_id: this.companyId }, query: params }
|
|
1157
2074
|
});
|
|
1158
2075
|
return data.data;
|
|
1159
2076
|
}
|
|
2077
|
+
/**
|
|
2078
|
+
* Create a customer.
|
|
2079
|
+
*
|
|
2080
|
+
* @param body - Legal name, NIF (or alternative id) and address.
|
|
2081
|
+
* @returns The created customer.
|
|
2082
|
+
*/
|
|
1160
2083
|
async create(body) {
|
|
1161
2084
|
const { data } = await this.client.POST("/v1/companies/{company_id}/customers", {
|
|
1162
2085
|
params: { path: { company_id: this.companyId } },
|
|
@@ -1164,6 +2087,12 @@ var CompanyCustomersResource = class {
|
|
|
1164
2087
|
});
|
|
1165
2088
|
return data.data;
|
|
1166
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
|
+
*/
|
|
1167
2096
|
async createBulk(body) {
|
|
1168
2097
|
const { data } = await this.client.POST("/v1/companies/{company_id}/customers/bulk", {
|
|
1169
2098
|
params: { path: { company_id: this.companyId } },
|
|
@@ -1171,12 +2100,25 @@ var CompanyCustomersResource = class {
|
|
|
1171
2100
|
});
|
|
1172
2101
|
return data.data;
|
|
1173
2102
|
}
|
|
2103
|
+
/**
|
|
2104
|
+
* Get one customer.
|
|
2105
|
+
*
|
|
2106
|
+
* @param customerId - Customer UUID.
|
|
2107
|
+
* @returns The customer.
|
|
2108
|
+
*/
|
|
1174
2109
|
async get(customerId) {
|
|
1175
2110
|
const { data } = await this.client.GET("/v1/companies/{company_id}/customers/{customer_id}", {
|
|
1176
2111
|
params: { path: { company_id: this.companyId, customer_id: customerId } }
|
|
1177
2112
|
});
|
|
1178
2113
|
return data.data;
|
|
1179
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
|
+
*/
|
|
1180
2122
|
async update(customerId, body) {
|
|
1181
2123
|
const { data } = await this.client.PATCH("/v1/companies/{company_id}/customers/{customer_id}", {
|
|
1182
2124
|
params: { path: { company_id: this.companyId, customer_id: customerId } },
|
|
@@ -1184,6 +2126,12 @@ var CompanyCustomersResource = class {
|
|
|
1184
2126
|
});
|
|
1185
2127
|
return data.data;
|
|
1186
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
|
+
*/
|
|
1187
2135
|
async delete(customerId) {
|
|
1188
2136
|
await this.client.DELETE("/v1/companies/{company_id}/customers/{customer_id}", {
|
|
1189
2137
|
params: { path: { company_id: this.companyId, customer_id: customerId } }
|
|
@@ -1195,12 +2143,24 @@ var CompanyProductsResource = class {
|
|
|
1195
2143
|
this.client = client;
|
|
1196
2144
|
this.companyId = companyId;
|
|
1197
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
|
+
*/
|
|
1198
2152
|
async list(params) {
|
|
1199
2153
|
const { data } = await this.client.GET("/v1/companies/{company_id}/products", {
|
|
1200
2154
|
params: { path: { company_id: this.companyId }, query: params }
|
|
1201
2155
|
});
|
|
1202
2156
|
return data.data;
|
|
1203
2157
|
}
|
|
2158
|
+
/**
|
|
2159
|
+
* Create a product or service.
|
|
2160
|
+
*
|
|
2161
|
+
* @param body - Name, category, price and main tax.
|
|
2162
|
+
* @returns The created product.
|
|
2163
|
+
*/
|
|
1204
2164
|
async create(body) {
|
|
1205
2165
|
const { data } = await this.client.POST("/v1/companies/{company_id}/products", {
|
|
1206
2166
|
params: { path: { company_id: this.companyId } },
|
|
@@ -1208,12 +2168,25 @@ var CompanyProductsResource = class {
|
|
|
1208
2168
|
});
|
|
1209
2169
|
return data.data;
|
|
1210
2170
|
}
|
|
2171
|
+
/**
|
|
2172
|
+
* Get one product.
|
|
2173
|
+
*
|
|
2174
|
+
* @param productId - Product UUID.
|
|
2175
|
+
* @returns The product.
|
|
2176
|
+
*/
|
|
1211
2177
|
async get(productId) {
|
|
1212
2178
|
const { data } = await this.client.GET("/v1/companies/{company_id}/products/{product_id}", {
|
|
1213
2179
|
params: { path: { company_id: this.companyId, product_id: productId } }
|
|
1214
2180
|
});
|
|
1215
2181
|
return data.data;
|
|
1216
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
|
+
*/
|
|
1217
2190
|
async update(productId, body) {
|
|
1218
2191
|
const { data } = await this.client.PATCH("/v1/companies/{company_id}/products/{product_id}", {
|
|
1219
2192
|
params: { path: { company_id: this.companyId, product_id: productId } },
|
|
@@ -1221,6 +2194,11 @@ var CompanyProductsResource = class {
|
|
|
1221
2194
|
});
|
|
1222
2195
|
return data.data;
|
|
1223
2196
|
}
|
|
2197
|
+
/**
|
|
2198
|
+
* Delete a product from the catalog. Existing invoice lines are unaffected.
|
|
2199
|
+
*
|
|
2200
|
+
* @param productId - Product UUID.
|
|
2201
|
+
*/
|
|
1224
2202
|
async delete(productId) {
|
|
1225
2203
|
await this.client.DELETE("/v1/companies/{company_id}/products/{product_id}", {
|
|
1226
2204
|
params: { path: { company_id: this.companyId, product_id: productId } }
|
|
@@ -1232,12 +2210,24 @@ var CompanySeriesResource = class {
|
|
|
1232
2210
|
this.client = client;
|
|
1233
2211
|
this.companyId = companyId;
|
|
1234
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
|
+
*/
|
|
1235
2219
|
async list(params) {
|
|
1236
2220
|
const { data } = await this.client.GET("/v1/companies/{company_id}/series", {
|
|
1237
2221
|
params: { path: { company_id: this.companyId }, query: params }
|
|
1238
2222
|
});
|
|
1239
2223
|
return data.data;
|
|
1240
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
|
+
*/
|
|
1241
2231
|
async create(body) {
|
|
1242
2232
|
const { data } = await this.client.POST("/v1/companies/{company_id}/series", {
|
|
1243
2233
|
params: { path: { company_id: this.companyId } },
|
|
@@ -1245,6 +2235,13 @@ var CompanySeriesResource = class {
|
|
|
1245
2235
|
});
|
|
1246
2236
|
return data.data;
|
|
1247
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
|
+
*/
|
|
1248
2245
|
async update(seriesId, body) {
|
|
1249
2246
|
const { data } = await this.client.PATCH("/v1/companies/{company_id}/series/{series_id}", {
|
|
1250
2247
|
params: { path: { company_id: this.companyId, series_id: seriesId } },
|
|
@@ -1252,26 +2249,45 @@ var CompanySeriesResource = class {
|
|
|
1252
2249
|
});
|
|
1253
2250
|
return data.data;
|
|
1254
2251
|
}
|
|
2252
|
+
/**
|
|
2253
|
+
* Delete (soft-delete) a series. Its code stays taken, since issued invoices carry it.
|
|
2254
|
+
*
|
|
2255
|
+
* @param seriesId - Series UUID.
|
|
2256
|
+
*/
|
|
1255
2257
|
async delete(seriesId) {
|
|
1256
2258
|
await this.client.DELETE("/v1/companies/{company_id}/series/{series_id}", {
|
|
1257
2259
|
params: { path: { company_id: this.companyId, series_id: seriesId } }
|
|
1258
2260
|
});
|
|
1259
2261
|
}
|
|
1260
|
-
/**
|
|
2262
|
+
/**
|
|
2263
|
+
* The current default series per document type.
|
|
2264
|
+
*
|
|
2265
|
+
* @returns One entry per document type, saying whether a default exists.
|
|
2266
|
+
*/
|
|
1261
2267
|
async getDefaults() {
|
|
1262
2268
|
const { data } = await this.client.GET("/v1/companies/{company_id}/series/defaults", {
|
|
1263
2269
|
params: { path: { company_id: this.companyId } }
|
|
1264
2270
|
});
|
|
1265
2271
|
return data.data;
|
|
1266
2272
|
}
|
|
1267
|
-
/**
|
|
2273
|
+
/**
|
|
2274
|
+
* Ensure a default series exists per document type, creating the missing ones.
|
|
2275
|
+
* Idempotent.
|
|
2276
|
+
*
|
|
2277
|
+
* @returns The default series.
|
|
2278
|
+
*/
|
|
1268
2279
|
async ensureDefaults() {
|
|
1269
2280
|
const { data } = await this.client.PUT("/v1/companies/{company_id}/series/defaults", {
|
|
1270
2281
|
params: { path: { company_id: this.companyId } }
|
|
1271
2282
|
});
|
|
1272
2283
|
return data.data;
|
|
1273
2284
|
}
|
|
1274
|
-
/**
|
|
2285
|
+
/**
|
|
2286
|
+
* Mark a series as the default for its document type.
|
|
2287
|
+
*
|
|
2288
|
+
* @param seriesId - Series UUID.
|
|
2289
|
+
* @returns The series.
|
|
2290
|
+
*/
|
|
1275
2291
|
async setDefault(seriesId) {
|
|
1276
2292
|
const { data } = await this.client.PUT("/v1/companies/{company_id}/series/{series_id}/default", {
|
|
1277
2293
|
params: { path: { company_id: this.companyId, series_id: seriesId } }
|
|
@@ -1287,12 +2303,24 @@ var CompanyRecurringInvoicesResource = class {
|
|
|
1287
2303
|
path(rest) {
|
|
1288
2304
|
return { company_id: this.companyId, ...rest };
|
|
1289
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
|
+
*/
|
|
1290
2312
|
async list(params) {
|
|
1291
2313
|
const { data } = await this.client.GET("/v1/companies/{company_id}/recurring-invoices", {
|
|
1292
2314
|
params: { path: this.path(), query: params }
|
|
1293
2315
|
});
|
|
1294
2316
|
return data.data;
|
|
1295
2317
|
}
|
|
2318
|
+
/**
|
|
2319
|
+
* Create a recurring invoice template.
|
|
2320
|
+
*
|
|
2321
|
+
* @param body - Frequency, schedule, recipient and lines.
|
|
2322
|
+
* @returns The recurring invoice.
|
|
2323
|
+
*/
|
|
1296
2324
|
async create(body) {
|
|
1297
2325
|
const { data } = await this.client.POST("/v1/companies/{company_id}/recurring-invoices", {
|
|
1298
2326
|
params: { path: this.path() },
|
|
@@ -1300,12 +2328,25 @@ var CompanyRecurringInvoicesResource = class {
|
|
|
1300
2328
|
});
|
|
1301
2329
|
return data.data;
|
|
1302
2330
|
}
|
|
2331
|
+
/**
|
|
2332
|
+
* Get one recurring invoice.
|
|
2333
|
+
*
|
|
2334
|
+
* @param recurringInvoiceId - Recurring invoice UUID.
|
|
2335
|
+
* @returns The recurring invoice.
|
|
2336
|
+
*/
|
|
1303
2337
|
async get(recurringInvoiceId) {
|
|
1304
2338
|
const { data } = await this.client.GET("/v1/companies/{company_id}/recurring-invoices/{recurring_invoice_id}", {
|
|
1305
2339
|
params: { path: this.path({ recurring_invoice_id: recurringInvoiceId }) }
|
|
1306
2340
|
});
|
|
1307
2341
|
return data.data;
|
|
1308
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
|
+
*/
|
|
1309
2350
|
async update(recurringInvoiceId, body) {
|
|
1310
2351
|
const { data } = await this.client.PATCH("/v1/companies/{company_id}/recurring-invoices/{recurring_invoice_id}", {
|
|
1311
2352
|
params: { path: this.path({ recurring_invoice_id: recurringInvoiceId }) },
|
|
@@ -1313,12 +2354,24 @@ var CompanyRecurringInvoicesResource = class {
|
|
|
1313
2354
|
});
|
|
1314
2355
|
return data.data;
|
|
1315
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
|
+
*/
|
|
1316
2363
|
async delete(recurringInvoiceId) {
|
|
1317
2364
|
await this.client.DELETE("/v1/companies/{company_id}/recurring-invoices/{recurring_invoice_id}", {
|
|
1318
2365
|
params: { path: this.path({ recurring_invoice_id: recurringInvoiceId }) }
|
|
1319
2366
|
});
|
|
1320
2367
|
}
|
|
1321
|
-
/**
|
|
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
|
+
*/
|
|
1322
2375
|
async setStatus(recurringInvoiceId, body) {
|
|
1323
2376
|
const { data } = await this.client.PUT("/v1/companies/{company_id}/recurring-invoices/{recurring_invoice_id}/status", {
|
|
1324
2377
|
params: { path: this.path({ recurring_invoice_id: recurringInvoiceId }) },
|
|
@@ -1326,26 +2379,49 @@ var CompanyRecurringInvoicesResource = class {
|
|
|
1326
2379
|
});
|
|
1327
2380
|
return data.data;
|
|
1328
2381
|
}
|
|
1329
|
-
/**
|
|
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
|
+
*/
|
|
1330
2388
|
async skip(recurringInvoiceId) {
|
|
1331
2389
|
const { data } = await this.client.POST("/v1/companies/{company_id}/recurring-invoices/{recurring_invoice_id}/skip", {
|
|
1332
2390
|
params: { path: this.path({ recurring_invoice_id: recurringInvoiceId }) }
|
|
1333
2391
|
});
|
|
1334
2392
|
return data.data;
|
|
1335
2393
|
}
|
|
1336
|
-
/**
|
|
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
|
+
*/
|
|
1337
2400
|
async generateNow(recurringInvoiceId) {
|
|
1338
2401
|
const { data } = await this.client.POST("/v1/companies/{company_id}/recurring-invoices/{recurring_invoice_id}/generate", {
|
|
1339
2402
|
params: { path: this.path({ recurring_invoice_id: recurringInvoiceId }) }
|
|
1340
2403
|
});
|
|
1341
2404
|
return data.data;
|
|
1342
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
|
+
*/
|
|
1343
2412
|
async nextOccurrence(recurringInvoiceId) {
|
|
1344
2413
|
const { data } = await this.client.GET("/v1/companies/{company_id}/recurring-invoices/{recurring_invoice_id}/next-occurrence", {
|
|
1345
2414
|
params: { path: this.path({ recurring_invoice_id: recurringInvoiceId }) }
|
|
1346
2415
|
});
|
|
1347
2416
|
return data.data;
|
|
1348
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
|
+
*/
|
|
1349
2425
|
async history(recurringInvoiceId, params) {
|
|
1350
2426
|
const { data } = await this.client.GET("/v1/companies/{company_id}/recurring-invoices/{recurring_invoice_id}/history", {
|
|
1351
2427
|
params: { path: this.path({ recurring_invoice_id: recurringInvoiceId }), query: params }
|
|
@@ -1358,13 +2434,23 @@ var CompanyTaxConfigurationResource = class {
|
|
|
1358
2434
|
this.client = client;
|
|
1359
2435
|
this.companyId = companyId;
|
|
1360
2436
|
}
|
|
2437
|
+
/**
|
|
2438
|
+
* Get the tax configuration.
|
|
2439
|
+
*
|
|
2440
|
+
* @returns The company's tax defaults.
|
|
2441
|
+
*/
|
|
1361
2442
|
async get() {
|
|
1362
2443
|
const { data } = await this.client.GET("/v1/companies/{company_id}/tax-configuration", {
|
|
1363
2444
|
params: { path: { company_id: this.companyId } }
|
|
1364
2445
|
});
|
|
1365
2446
|
return data.data;
|
|
1366
2447
|
}
|
|
1367
|
-
/**
|
|
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
|
+
*/
|
|
1368
2454
|
async update(body) {
|
|
1369
2455
|
const { data } = await this.client.PUT("/v1/companies/{company_id}/tax-configuration", {
|
|
1370
2456
|
params: { path: { company_id: this.companyId } },
|
|
@@ -1378,13 +2464,23 @@ var CompanyVeriFactuConfigurationResource = class {
|
|
|
1378
2464
|
this.client = client;
|
|
1379
2465
|
this.companyId = companyId;
|
|
1380
2466
|
}
|
|
2467
|
+
/**
|
|
2468
|
+
* Get the VeriFactu configuration of this NIF.
|
|
2469
|
+
*
|
|
2470
|
+
* @returns `enabled` and the server-resolved state of the NIF.
|
|
2471
|
+
*/
|
|
1381
2472
|
async get() {
|
|
1382
2473
|
const { data } = await this.client.GET("/v1/companies/{company_id}/verifactu-configuration", {
|
|
1383
2474
|
params: { path: { company_id: this.companyId } }
|
|
1384
2475
|
});
|
|
1385
2476
|
return data.data;
|
|
1386
2477
|
}
|
|
1387
|
-
/**
|
|
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
|
+
*/
|
|
1388
2484
|
async update(body) {
|
|
1389
2485
|
const { data } = await this.client.PUT("/v1/companies/{company_id}/verifactu-configuration", {
|
|
1390
2486
|
params: { path: { company_id: this.companyId } },
|
|
@@ -1410,7 +2506,11 @@ var BeeL = class {
|
|
|
1410
2506
|
}
|
|
1411
2507
|
/**
|
|
1412
2508
|
* Returns a facade scoped to one company (NIF) — the explicit multi-NIF surface.
|
|
1413
|
-
* 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.
|
|
1414
2514
|
*
|
|
1415
2515
|
* @example
|
|
1416
2516
|
* ```typescript
|
|
@@ -1422,8 +2522,12 @@ var BeeL = class {
|
|
|
1422
2522
|
return new CompanyScope(this.raw, companyId);
|
|
1423
2523
|
}
|
|
1424
2524
|
/**
|
|
1425
|
-
* Returns a facade scoped to one
|
|
1426
|
-
*
|
|
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.
|
|
1427
2531
|
*
|
|
1428
2532
|
* @example
|
|
1429
2533
|
* ```typescript
|
|
@@ -1440,6 +2544,10 @@ var BeeL = class {
|
|
|
1440
2544
|
* @deprecated Relies on the deprecated session-focus PDF endpoint. Use
|
|
1441
2545
|
* `beel.company(companyId).invoices.getPdf(invoiceId)` and fetch `download_url` instead.
|
|
1442
2546
|
*
|
|
2547
|
+
* @param invoiceId - Invoice UUID.
|
|
2548
|
+
* @returns The PDF bytes and its file name.
|
|
2549
|
+
* @throws {Error} When downloading the file fails.
|
|
2550
|
+
*
|
|
1443
2551
|
* @example
|
|
1444
2552
|
* ```typescript
|
|
1445
2553
|
* const { buffer, fileName } = await beel.downloadPdf('invoice-uuid');
|
|
@@ -1484,6 +2592,7 @@ var WebhookVerifier = class {
|
|
|
1484
2592
|
* const verifier = new WebhookVerifier('your_secret');
|
|
1485
2593
|
* const event = verifier.verify(rawBody, signature);
|
|
1486
2594
|
*
|
|
2595
|
+
* if (event.test) return; // a "Send test" delivery carries a synthetic `data`
|
|
1487
2596
|
* if (event.type === 'verifactu.status.updated') {
|
|
1488
2597
|
* console.log('Invoice:', event.data.invoice_number);
|
|
1489
2598
|
* console.log('Status:', event.data.new_status);
|
|
@@ -1607,6 +2716,24 @@ var InvoiceIssuedEvent;
|
|
|
1607
2716
|
})(type = InvoiceIssuedEvent2.type || (InvoiceIssuedEvent2.type = {}));
|
|
1608
2717
|
})(InvoiceIssuedEvent || (InvoiceIssuedEvent = {}));
|
|
1609
2718
|
|
|
2719
|
+
// src/generated-webhooks/models/InvoicePdfGeneratedEvent.ts
|
|
2720
|
+
var InvoicePdfGeneratedEvent;
|
|
2721
|
+
((InvoicePdfGeneratedEvent2) => {
|
|
2722
|
+
let type;
|
|
2723
|
+
((type2) => {
|
|
2724
|
+
type2["INVOICE_PDF_GENERATED"] = "invoice.pdf.generated";
|
|
2725
|
+
})(type = InvoicePdfGeneratedEvent2.type || (InvoicePdfGeneratedEvent2.type = {}));
|
|
2726
|
+
})(InvoicePdfGeneratedEvent || (InvoicePdfGeneratedEvent = {}));
|
|
2727
|
+
|
|
2728
|
+
// src/generated-webhooks/models/InvoiceScheduleFailedEvent.ts
|
|
2729
|
+
var InvoiceScheduleFailedEvent;
|
|
2730
|
+
((InvoiceScheduleFailedEvent2) => {
|
|
2731
|
+
let type;
|
|
2732
|
+
((type2) => {
|
|
2733
|
+
type2["INVOICE_SCHEDULE_FAILED"] = "invoice.schedule_failed";
|
|
2734
|
+
})(type = InvoiceScheduleFailedEvent2.type || (InvoiceScheduleFailedEvent2.type = {}));
|
|
2735
|
+
})(InvoiceScheduleFailedEvent || (InvoiceScheduleFailedEvent = {}));
|
|
2736
|
+
|
|
1610
2737
|
// src/generated-webhooks/models/InvoiceVoidedEvent.ts
|
|
1611
2738
|
var InvoiceVoidedEvent;
|
|
1612
2739
|
((InvoiceVoidedEvent2) => {
|
|
@@ -1657,8 +2784,10 @@ var WebhookEventType = /* @__PURE__ */ ((WebhookEventType2) => {
|
|
|
1657
2784
|
WebhookEventType2["VERIFACTU_STATUS_UPDATED"] = "verifactu.status.updated";
|
|
1658
2785
|
WebhookEventType2["INVOICE_ISSUED"] = "invoice.issued";
|
|
1659
2786
|
WebhookEventType2["INVOICE_EMAIL_SENT"] = "invoice.email.sent";
|
|
2787
|
+
WebhookEventType2["INVOICE_PDF_GENERATED"] = "invoice.pdf.generated";
|
|
1660
2788
|
WebhookEventType2["INVOICE_VOIDED"] = "invoice.voided";
|
|
1661
2789
|
WebhookEventType2["RECURRING_INVOICE_PAUSED"] = "recurring_invoice.paused";
|
|
2790
|
+
WebhookEventType2["INVOICE_SCHEDULE_FAILED"] = "invoice.schedule_failed";
|
|
1662
2791
|
WebhookEventType2["ACCOUNT_CLAIMED"] = "account.claimed";
|
|
1663
2792
|
WebhookEventType2["COMPANY_CREATED"] = "company.created";
|
|
1664
2793
|
WebhookEventType2["REPRESENTATION_SIGNED"] = "representation.signed";
|
|
@@ -1669,33 +2798,86 @@ var WebhookEventType = /* @__PURE__ */ ((WebhookEventType2) => {
|
|
|
1669
2798
|
var CustomerBuilder = class _CustomerBuilder {
|
|
1670
2799
|
constructor() {
|
|
1671
2800
|
}
|
|
2801
|
+
/**
|
|
2802
|
+
* Start a new builder.
|
|
2803
|
+
*
|
|
2804
|
+
* @returns An empty customer builder.
|
|
2805
|
+
*/
|
|
1672
2806
|
static create() {
|
|
1673
2807
|
return new _CustomerBuilder();
|
|
1674
2808
|
}
|
|
2809
|
+
/**
|
|
2810
|
+
* Legal name of the customer. Required.
|
|
2811
|
+
*
|
|
2812
|
+
* @param name - Legal name.
|
|
2813
|
+
* @returns This builder.
|
|
2814
|
+
*/
|
|
1675
2815
|
name(name) {
|
|
1676
2816
|
this._name = name;
|
|
1677
2817
|
return this;
|
|
1678
2818
|
}
|
|
2819
|
+
/**
|
|
2820
|
+
* NIF/CIF of the customer. Required.
|
|
2821
|
+
*
|
|
2822
|
+
* @param nif - Spanish tax id.
|
|
2823
|
+
* @returns This builder.
|
|
2824
|
+
*/
|
|
1679
2825
|
nif(nif) {
|
|
1680
2826
|
this._nif = nif;
|
|
1681
2827
|
return this;
|
|
1682
2828
|
}
|
|
2829
|
+
/**
|
|
2830
|
+
* Contact email.
|
|
2831
|
+
*
|
|
2832
|
+
* @param email - Email address.
|
|
2833
|
+
* @returns This builder.
|
|
2834
|
+
*/
|
|
1683
2835
|
email(email) {
|
|
1684
2836
|
this._email = email;
|
|
1685
2837
|
return this;
|
|
1686
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
|
+
*/
|
|
1687
2845
|
phone(phone) {
|
|
1688
2846
|
this._phone = phone;
|
|
1689
2847
|
return this;
|
|
1690
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
|
+
*/
|
|
1691
2861
|
address(street, number, postalCode, city, province, country, countryCode = "ES") {
|
|
1692
2862
|
this._address = { street, number, postal_code: postalCode, city, province, country, country_code: countryCode };
|
|
1693
2863
|
return this;
|
|
1694
2864
|
}
|
|
2865
|
+
/**
|
|
2866
|
+
* Internal notes about the customer.
|
|
2867
|
+
*
|
|
2868
|
+
* @param notes - Free text.
|
|
2869
|
+
* @returns This builder.
|
|
2870
|
+
*/
|
|
1695
2871
|
notes(notes) {
|
|
1696
2872
|
this._notes = notes;
|
|
1697
2873
|
return this;
|
|
1698
2874
|
}
|
|
2875
|
+
/**
|
|
2876
|
+
* Build the request body.
|
|
2877
|
+
*
|
|
2878
|
+
* @returns The `CreateCustomerRequest`.
|
|
2879
|
+
* @throws {Error} When the name, NIF or address is missing.
|
|
2880
|
+
*/
|
|
1699
2881
|
build() {
|
|
1700
2882
|
if (!this._name || this._name.trim().length === 0) throw new Error("Legal name is required");
|
|
1701
2883
|
if (!this._nif || this._nif.trim().length === 0) throw new Error("NIF/CIF is required");
|
|
@@ -1712,50 +2894,144 @@ var CustomerBuilder = class _CustomerBuilder {
|
|
|
1712
2894
|
};
|
|
1713
2895
|
|
|
1714
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
|
+
}
|
|
1715
2902
|
var InvoiceBuilder = class _InvoiceBuilder {
|
|
1716
2903
|
constructor() {
|
|
1717
2904
|
this._type = "STANDARD";
|
|
1718
2905
|
this._lines = [];
|
|
1719
2906
|
}
|
|
2907
|
+
/**
|
|
2908
|
+
* Start a new builder.
|
|
2909
|
+
*
|
|
2910
|
+
* @returns An empty `STANDARD` invoice builder.
|
|
2911
|
+
*/
|
|
1720
2912
|
static create() {
|
|
1721
2913
|
return new _InvoiceBuilder();
|
|
1722
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
|
+
*/
|
|
1723
2921
|
type(type) {
|
|
1724
2922
|
this._type = type;
|
|
1725
2923
|
return this;
|
|
1726
2924
|
}
|
|
2925
|
+
/**
|
|
2926
|
+
* Invoice a registered customer.
|
|
2927
|
+
*
|
|
2928
|
+
* @param customerId - Customer UUID.
|
|
2929
|
+
* @returns This builder.
|
|
2930
|
+
*/
|
|
1727
2931
|
forCustomer(customerId) {
|
|
1728
2932
|
this._customerId = customerId;
|
|
1729
2933
|
return this;
|
|
1730
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
|
+
*/
|
|
1731
2941
|
operationDate(date) {
|
|
1732
|
-
this._operationDate = date
|
|
2942
|
+
this._operationDate = toIsoDate(date);
|
|
1733
2943
|
return this;
|
|
1734
2944
|
}
|
|
2945
|
+
/**
|
|
2946
|
+
* Payment due date.
|
|
2947
|
+
*
|
|
2948
|
+
* @param date - A `Date` or a `YYYY-MM-DD` string.
|
|
2949
|
+
* @returns This builder.
|
|
2950
|
+
*/
|
|
1735
2951
|
dueDate(date) {
|
|
1736
|
-
this._dueDate = date
|
|
2952
|
+
this._dueDate = toIsoDate(date);
|
|
1737
2953
|
return this;
|
|
1738
2954
|
}
|
|
1739
|
-
|
|
1740
|
-
|
|
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
|
+
});
|
|
1741
2987
|
return this;
|
|
1742
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
|
+
*/
|
|
1743
2995
|
addLineObject(line) {
|
|
1744
2996
|
this._lines.push(line);
|
|
1745
2997
|
return this;
|
|
1746
2998
|
}
|
|
2999
|
+
/**
|
|
3000
|
+
* Notes printed on the invoice.
|
|
3001
|
+
*
|
|
3002
|
+
* @param notes - Free text.
|
|
3003
|
+
* @returns This builder.
|
|
3004
|
+
*/
|
|
1747
3005
|
notes(notes) {
|
|
1748
3006
|
this._notes = notes;
|
|
1749
3007
|
return this;
|
|
1750
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
|
+
*/
|
|
1751
3015
|
series(id) {
|
|
1752
3016
|
this._seriesId = id;
|
|
1753
3017
|
return this;
|
|
1754
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
|
+
*/
|
|
1755
3025
|
metadata(data) {
|
|
1756
3026
|
this._metadata = data;
|
|
1757
3027
|
return this;
|
|
1758
3028
|
}
|
|
3029
|
+
/**
|
|
3030
|
+
* Build the request body.
|
|
3031
|
+
*
|
|
3032
|
+
* @returns The `CreateInvoiceRequest`.
|
|
3033
|
+
* @throws {Error} When there is no customer or no line.
|
|
3034
|
+
*/
|
|
1759
3035
|
build() {
|
|
1760
3036
|
if (!this._customerId) throw new Error("Customer ID is required");
|
|
1761
3037
|
if (this._lines.length === 0) throw new Error("At least one invoice line is required");
|
|
@@ -1784,6 +3060,7 @@ var InvoiceBuilder = class _InvoiceBuilder {
|
|
|
1784
3060
|
BeeLApiError,
|
|
1785
3061
|
BeeLAuthError,
|
|
1786
3062
|
BeeLConflictError,
|
|
3063
|
+
BeeLErrorCodes,
|
|
1787
3064
|
BeeLNotFoundError,
|
|
1788
3065
|
BeeLRateLimitError,
|
|
1789
3066
|
BeeLValidationError,
|
|
@@ -1800,6 +3077,7 @@ var InvoiceBuilder = class _InvoiceBuilder {
|
|
|
1800
3077
|
CompanyTaxConfigurationResource,
|
|
1801
3078
|
CompanyVeriFactuConfigurationResource,
|
|
1802
3079
|
CustomerBuilder,
|
|
3080
|
+
EXTERNAL_REF_UNIQUE_INVOICE_TYPES,
|
|
1803
3081
|
InvoiceBuilder,
|
|
1804
3082
|
VeriFactuSubmissionStatus,
|
|
1805
3083
|
WebhookEventType,
|