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