@beel_es/sdk 1.3.0 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +227 -0
- package/README.md +237 -29
- package/dist/index.d.mts +4875 -1235
- package/dist/index.d.ts +4875 -1235
- package/dist/index.js +1462 -184
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1460 -184
- package/dist/index.mjs.map +1 -1
- package/docs/reference/README.md +233 -0
- package/docs/reference/account-companies.md +55 -0
- package/docs/reference/account-invitations.md +57 -0
- package/docs/reference/account-members.md +97 -0
- package/docs/reference/account-webhooks.md +123 -0
- package/docs/reference/account.md +94 -0
- package/docs/reference/accounts.md +72 -0
- package/docs/reference/catalogs.md +68 -0
- package/docs/reference/client.md +113 -0
- package/docs/reference/company-customers.md +85 -0
- package/docs/reference/company-invoices-schedule.md +52 -0
- package/docs/reference/company-invoices.md +316 -0
- package/docs/reference/company-payment-connections-events.md +103 -0
- package/docs/reference/company-payment-connections.md +87 -0
- package/docs/reference/company-products.md +72 -0
- package/docs/reference/company-recurring-invoices.md +136 -0
- package/docs/reference/company-series.md +94 -0
- package/docs/reference/company-tax-configuration.md +36 -0
- package/docs/reference/company-verifactu-configuration.md +41 -0
- package/docs/reference/company.md +94 -0
- package/docs/reference/configuration.md +90 -0
- package/docs/reference/customer-builder.md +107 -0
- package/docs/reference/customers.md +91 -0
- package/docs/reference/errors.md +72 -0
- package/docs/reference/invoice-builder.md +149 -0
- package/docs/reference/invoices.md +250 -0
- package/docs/reference/nif.md +31 -0
- package/docs/reference/products.md +111 -0
- package/docs/reference/series.md +81 -0
- package/docs/reference/types.md +222 -0
- package/docs/reference/webhook-verifier.md +95 -0
- package/llms.txt +52 -0
- package/package.json +11 -4
package/dist/index.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 };
|
|
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;
|
|
138
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,24 +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
|
+
/**
|
|
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.
|
|
879
|
+
*/
|
|
525
880
|
async provision(body) {
|
|
526
881
|
const { data } = await this.client.POST("/v1/accounts", { body });
|
|
527
882
|
return data.data;
|
|
528
883
|
}
|
|
529
|
-
/**
|
|
884
|
+
/**
|
|
885
|
+
* Get a managed account.
|
|
886
|
+
*
|
|
887
|
+
* @param accountId - Account UUID.
|
|
888
|
+
* @returns The account summary.
|
|
889
|
+
*/
|
|
530
890
|
async get(accountId) {
|
|
531
891
|
const { data } = await this.client.GET("/v1/accounts/{account_id}", {
|
|
532
892
|
params: { path: { account_id: accountId } }
|
|
533
893
|
});
|
|
534
894
|
return data.data;
|
|
535
895
|
}
|
|
536
|
-
/**
|
|
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
|
+
*/
|
|
537
902
|
scope(accountId) {
|
|
538
903
|
return new AccountScope(this.client, accountId);
|
|
539
904
|
}
|
|
@@ -550,28 +915,49 @@ var AccountScope = class {
|
|
|
550
915
|
path() {
|
|
551
916
|
return { account_id: this.accountId };
|
|
552
917
|
}
|
|
553
|
-
/**
|
|
918
|
+
/**
|
|
919
|
+
* Get the account summary.
|
|
920
|
+
*
|
|
921
|
+
* @returns The account summary.
|
|
922
|
+
*/
|
|
554
923
|
async get() {
|
|
555
924
|
const { data } = await this.client.GET("/v1/accounts/{account_id}", { params: { path: this.path() } });
|
|
556
925
|
return data.data;
|
|
557
926
|
}
|
|
558
|
-
/**
|
|
927
|
+
/**
|
|
928
|
+
* Provisioning usage counters for billing: provisioned accounts and NIFs.
|
|
929
|
+
*
|
|
930
|
+
* @returns `provisioned_accounts` and `nifs`.
|
|
931
|
+
*/
|
|
559
932
|
async usage() {
|
|
560
933
|
const { data } = await this.client.GET("/v1/accounts/{account_id}/usage", { params: { path: this.path() } });
|
|
561
934
|
return data.data;
|
|
562
935
|
}
|
|
563
|
-
/**
|
|
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
|
+
*/
|
|
564
942
|
async changeAccessLevel(body) {
|
|
565
943
|
await this.client.PATCH("/v1/accounts/{account_id}/access-level", {
|
|
566
944
|
params: { path: this.path() },
|
|
567
945
|
body
|
|
568
946
|
});
|
|
569
947
|
}
|
|
570
|
-
/**
|
|
948
|
+
/**
|
|
949
|
+
* End your management of this account: you lose access, and the holder keeps the
|
|
950
|
+
* account, its NIFs and its invoices.
|
|
951
|
+
*/
|
|
571
952
|
async endManagement() {
|
|
572
953
|
await this.client.DELETE("/v1/accounts/{account_id}/management", { params: { path: this.path() } });
|
|
573
954
|
}
|
|
574
|
-
/**
|
|
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
|
+
*/
|
|
575
961
|
async createClaimToken(body) {
|
|
576
962
|
const { data } = await this.client.POST("/v1/accounts/{account_id}/claim-tokens", {
|
|
577
963
|
params: { path: this.path() },
|
|
@@ -579,7 +965,11 @@ var AccountScope = class {
|
|
|
579
965
|
});
|
|
580
966
|
return data.data;
|
|
581
967
|
}
|
|
582
|
-
/**
|
|
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
|
+
*/
|
|
583
973
|
async setOwner(body) {
|
|
584
974
|
await this.client.PUT("/v1/accounts/{account_id}/owner", {
|
|
585
975
|
params: { path: this.path() },
|
|
@@ -592,19 +982,36 @@ var AccountMembersResource = class {
|
|
|
592
982
|
this.client = client;
|
|
593
983
|
this.accountId = accountId;
|
|
594
984
|
}
|
|
985
|
+
/**
|
|
986
|
+
* List the account's members.
|
|
987
|
+
*
|
|
988
|
+
* @returns The members (`data.members` of the response), as an array.
|
|
989
|
+
*/
|
|
595
990
|
async list() {
|
|
596
991
|
const { data } = await this.client.GET("/v1/accounts/{account_id}/members", {
|
|
597
992
|
params: { path: { account_id: this.accountId } }
|
|
598
993
|
});
|
|
599
994
|
return data.data.members;
|
|
600
995
|
}
|
|
996
|
+
/**
|
|
997
|
+
* Get one member.
|
|
998
|
+
*
|
|
999
|
+
* @param memberId - Member UUID.
|
|
1000
|
+
* @returns The member.
|
|
1001
|
+
*/
|
|
601
1002
|
async get(memberId) {
|
|
602
1003
|
const { data } = await this.client.GET("/v1/accounts/{account_id}/members/{member_id}", {
|
|
603
1004
|
params: { path: { account_id: this.accountId, member_id: memberId } }
|
|
604
1005
|
});
|
|
605
1006
|
return data.data;
|
|
606
1007
|
}
|
|
607
|
-
/**
|
|
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
|
+
*/
|
|
608
1015
|
async update(memberId, body) {
|
|
609
1016
|
const { data } = await this.client.PATCH("/v1/accounts/{account_id}/members/{member_id}", {
|
|
610
1017
|
params: { path: { account_id: this.accountId, member_id: memberId } },
|
|
@@ -612,20 +1019,36 @@ var AccountMembersResource = class {
|
|
|
612
1019
|
});
|
|
613
1020
|
return data.data;
|
|
614
1021
|
}
|
|
615
|
-
/**
|
|
1022
|
+
/**
|
|
1023
|
+
* Remove a member from the account.
|
|
1024
|
+
*
|
|
1025
|
+
* @param memberId - Member UUID.
|
|
1026
|
+
*/
|
|
616
1027
|
async remove(memberId) {
|
|
617
1028
|
await this.client.DELETE("/v1/accounts/{account_id}/members/{member_id}", {
|
|
618
1029
|
params: { path: { account_id: this.accountId, member_id: memberId } }
|
|
619
1030
|
});
|
|
620
1031
|
}
|
|
621
|
-
/**
|
|
1032
|
+
/**
|
|
1033
|
+
* List a member's per-company grants.
|
|
1034
|
+
*
|
|
1035
|
+
* @param memberId - Member UUID.
|
|
1036
|
+
* @returns The `grants` and their `pagination`.
|
|
1037
|
+
*/
|
|
622
1038
|
async listGrants(memberId) {
|
|
623
1039
|
const { data } = await this.client.GET("/v1/accounts/{account_id}/members/{member_id}/grants", {
|
|
624
1040
|
params: { path: { account_id: this.accountId, member_id: memberId } }
|
|
625
1041
|
});
|
|
626
1042
|
return data.data;
|
|
627
1043
|
}
|
|
628
|
-
/**
|
|
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
|
+
*/
|
|
629
1052
|
async putGrant(memberId, companyId, body) {
|
|
630
1053
|
const { data } = await this.client.PUT("/v1/accounts/{account_id}/members/{member_id}/grants/{company_id}", {
|
|
631
1054
|
params: { path: { account_id: this.accountId, member_id: memberId, company_id: companyId } },
|
|
@@ -633,7 +1056,12 @@ var AccountMembersResource = class {
|
|
|
633
1056
|
});
|
|
634
1057
|
return data.data;
|
|
635
1058
|
}
|
|
636
|
-
/**
|
|
1059
|
+
/**
|
|
1060
|
+
* Revoke a member's access to one company.
|
|
1061
|
+
*
|
|
1062
|
+
* @param memberId - Member UUID.
|
|
1063
|
+
* @param companyId - Company UUID.
|
|
1064
|
+
*/
|
|
637
1065
|
async removeGrant(memberId, companyId) {
|
|
638
1066
|
await this.client.DELETE("/v1/accounts/{account_id}/members/{member_id}/grants/{company_id}", {
|
|
639
1067
|
params: { path: { account_id: this.accountId, member_id: memberId, company_id: companyId } }
|
|
@@ -645,12 +1073,23 @@ var AccountInvitationsResource = class {
|
|
|
645
1073
|
this.client = client;
|
|
646
1074
|
this.accountId = accountId;
|
|
647
1075
|
}
|
|
1076
|
+
/**
|
|
1077
|
+
* List the account's invitations.
|
|
1078
|
+
*
|
|
1079
|
+
* @returns The invitations.
|
|
1080
|
+
*/
|
|
648
1081
|
async list() {
|
|
649
1082
|
const { data } = await this.client.GET("/v1/accounts/{account_id}/invitations", {
|
|
650
1083
|
params: { path: { account_id: this.accountId } }
|
|
651
1084
|
});
|
|
652
1085
|
return data.data;
|
|
653
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
|
+
*/
|
|
654
1093
|
async create(body) {
|
|
655
1094
|
const { data } = await this.client.POST("/v1/accounts/{account_id}/invitations", {
|
|
656
1095
|
params: { path: { account_id: this.accountId } },
|
|
@@ -658,12 +1097,23 @@ var AccountInvitationsResource = class {
|
|
|
658
1097
|
});
|
|
659
1098
|
return data.data;
|
|
660
1099
|
}
|
|
1100
|
+
/**
|
|
1101
|
+
* Get one invitation.
|
|
1102
|
+
*
|
|
1103
|
+
* @param invitationId - Invitation UUID.
|
|
1104
|
+
* @returns The invitation.
|
|
1105
|
+
*/
|
|
661
1106
|
async get(invitationId) {
|
|
662
1107
|
const { data } = await this.client.GET("/v1/accounts/{account_id}/invitations/{invitation_id}", {
|
|
663
1108
|
params: { path: { account_id: this.accountId, invitation_id: invitationId } }
|
|
664
1109
|
});
|
|
665
1110
|
return data.data;
|
|
666
1111
|
}
|
|
1112
|
+
/**
|
|
1113
|
+
* Revoke a `PENDING` invitation, so its link stops working.
|
|
1114
|
+
*
|
|
1115
|
+
* @param invitationId - Invitation UUID.
|
|
1116
|
+
*/
|
|
667
1117
|
async revoke(invitationId) {
|
|
668
1118
|
await this.client.DELETE("/v1/accounts/{account_id}/invitations/{invitation_id}", {
|
|
669
1119
|
params: { path: { account_id: this.accountId, invitation_id: invitationId } }
|
|
@@ -675,12 +1125,24 @@ var AccountWebhooksResource = class {
|
|
|
675
1125
|
this.client = client;
|
|
676
1126
|
this.accountId = accountId;
|
|
677
1127
|
}
|
|
1128
|
+
/**
|
|
1129
|
+
* List the webhook subscriptions.
|
|
1130
|
+
*
|
|
1131
|
+
* @param params - Pagination.
|
|
1132
|
+
* @returns The `webhooks` and their `pagination`.
|
|
1133
|
+
*/
|
|
678
1134
|
async list(params) {
|
|
679
1135
|
const { data } = await this.client.GET("/v1/accounts/{account_id}/webhooks", {
|
|
680
1136
|
params: { path: { account_id: this.accountId }, query: params }
|
|
681
1137
|
});
|
|
682
1138
|
return data.data;
|
|
683
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
|
+
*/
|
|
684
1146
|
async create(body) {
|
|
685
1147
|
const { data } = await this.client.POST("/v1/accounts/{account_id}/webhooks", {
|
|
686
1148
|
params: { path: { account_id: this.accountId } },
|
|
@@ -688,12 +1150,25 @@ var AccountWebhooksResource = class {
|
|
|
688
1150
|
});
|
|
689
1151
|
return data.data;
|
|
690
1152
|
}
|
|
1153
|
+
/**
|
|
1154
|
+
* Get one webhook subscription.
|
|
1155
|
+
*
|
|
1156
|
+
* @param webhookId - Subscription UUID.
|
|
1157
|
+
* @returns The subscription.
|
|
1158
|
+
*/
|
|
691
1159
|
async get(webhookId) {
|
|
692
1160
|
const { data } = await this.client.GET("/v1/accounts/{account_id}/webhooks/{webhook_id}", {
|
|
693
1161
|
params: { path: { account_id: this.accountId, webhook_id: webhookId } }
|
|
694
1162
|
});
|
|
695
1163
|
return data.data;
|
|
696
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
|
+
*/
|
|
697
1172
|
async update(webhookId, body) {
|
|
698
1173
|
const { data } = await this.client.PATCH("/v1/accounts/{account_id}/webhooks/{webhook_id}", {
|
|
699
1174
|
params: { path: { account_id: this.accountId, webhook_id: webhookId } },
|
|
@@ -701,31 +1176,60 @@ var AccountWebhooksResource = class {
|
|
|
701
1176
|
});
|
|
702
1177
|
return data.data;
|
|
703
1178
|
}
|
|
1179
|
+
/**
|
|
1180
|
+
* Delete a webhook subscription.
|
|
1181
|
+
*
|
|
1182
|
+
* @param webhookId - Subscription UUID.
|
|
1183
|
+
*/
|
|
704
1184
|
async delete(webhookId) {
|
|
705
1185
|
await this.client.DELETE("/v1/accounts/{account_id}/webhooks/{webhook_id}", {
|
|
706
1186
|
params: { path: { account_id: this.accountId, webhook_id: webhookId } }
|
|
707
1187
|
});
|
|
708
1188
|
}
|
|
709
|
-
/**
|
|
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
|
+
*/
|
|
710
1195
|
async test(webhookId) {
|
|
711
1196
|
const { data } = await this.client.POST("/v1/accounts/{account_id}/webhooks/{webhook_id}/test", {
|
|
712
1197
|
params: { path: { account_id: this.accountId, webhook_id: webhookId } }
|
|
713
1198
|
});
|
|
714
1199
|
return data.data;
|
|
715
1200
|
}
|
|
716
|
-
/**
|
|
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
|
+
*/
|
|
717
1207
|
async rotateSecret(webhookId) {
|
|
718
1208
|
const { data } = await this.client.POST("/v1/accounts/{account_id}/webhooks/{webhook_id}/secret", {
|
|
719
1209
|
params: { path: { account_id: this.accountId, webhook_id: webhookId } }
|
|
720
1210
|
});
|
|
721
1211
|
return data.data;
|
|
722
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
|
+
*/
|
|
723
1220
|
async listDeliveries(webhookId, params) {
|
|
724
1221
|
const { data } = await this.client.GET("/v1/accounts/{account_id}/webhooks/{webhook_id}/deliveries", {
|
|
725
1222
|
params: { path: { account_id: this.accountId, webhook_id: webhookId }, query: params }
|
|
726
1223
|
});
|
|
727
1224
|
return data.data;
|
|
728
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
|
+
*/
|
|
729
1233
|
async retryDelivery(webhookId, deliveryId) {
|
|
730
1234
|
const { data } = await this.client.POST("/v1/accounts/{account_id}/webhooks/{webhook_id}/deliveries/{delivery_id}/retry", {
|
|
731
1235
|
params: { path: { account_id: this.accountId, webhook_id: webhookId, delivery_id: deliveryId } }
|
|
@@ -738,6 +1242,19 @@ var AccountCompaniesResource = class {
|
|
|
738
1242
|
this.client = client;
|
|
739
1243
|
this.accountId = accountId;
|
|
740
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
|
+
*/
|
|
741
1258
|
async list(params) {
|
|
742
1259
|
const { data } = await this.client.GET("/v1/accounts/{account_id}/companies", {
|
|
743
1260
|
params: { path: { account_id: this.accountId }, query: params }
|
|
@@ -747,7 +1264,12 @@ var AccountCompaniesResource = class {
|
|
|
747
1264
|
pagination: data.data?.pagination
|
|
748
1265
|
};
|
|
749
1266
|
}
|
|
750
|
-
/**
|
|
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
|
+
*/
|
|
751
1273
|
async create(body) {
|
|
752
1274
|
const { data } = await this.client.POST("/v1/accounts/{account_id}/companies", {
|
|
753
1275
|
params: { path: { account_id: this.accountId } },
|
|
@@ -755,7 +1277,11 @@ var AccountCompaniesResource = class {
|
|
|
755
1277
|
});
|
|
756
1278
|
return data.data;
|
|
757
1279
|
}
|
|
758
|
-
/**
|
|
1280
|
+
/**
|
|
1281
|
+
* Per-company invoice stats: how many fiscal documents each issued, and when last.
|
|
1282
|
+
*
|
|
1283
|
+
* @returns One entry per company.
|
|
1284
|
+
*/
|
|
759
1285
|
async stats() {
|
|
760
1286
|
const { data } = await this.client.GET("/v1/accounts/{account_id}/companies/stats", {
|
|
761
1287
|
params: { path: { account_id: this.accountId } }
|
|
@@ -764,6 +1290,38 @@ var AccountCompaniesResource = class {
|
|
|
764
1290
|
}
|
|
765
1291
|
};
|
|
766
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
|
+
|
|
767
1325
|
// src/resources/payment-connections.ts
|
|
768
1326
|
var CompanyPaymentConnectionsResource = class {
|
|
769
1327
|
constructor(client, companyId) {
|
|
@@ -773,7 +1331,11 @@ var CompanyPaymentConnectionsResource = class {
|
|
|
773
1331
|
path() {
|
|
774
1332
|
return { company_id: this.companyId };
|
|
775
1333
|
}
|
|
776
|
-
/**
|
|
1334
|
+
/**
|
|
1335
|
+
* Every payment connection of this company.
|
|
1336
|
+
*
|
|
1337
|
+
* @returns The `connections`.
|
|
1338
|
+
*/
|
|
777
1339
|
async list() {
|
|
778
1340
|
const { data } = await this.client.GET("/v1/companies/{company_id}/payment-connections", {
|
|
779
1341
|
params: { path: this.path() }
|
|
@@ -784,6 +1346,9 @@ var CompanyPaymentConnectionsResource = class {
|
|
|
784
1346
|
* Start an authorization and get the URL where the NIF's holder approves it.
|
|
785
1347
|
*
|
|
786
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.
|
|
787
1352
|
*/
|
|
788
1353
|
async authorize(body) {
|
|
789
1354
|
const { data } = await this.client.POST(
|
|
@@ -792,7 +1357,13 @@ var CompanyPaymentConnectionsResource = class {
|
|
|
792
1357
|
);
|
|
793
1358
|
return data.data;
|
|
794
1359
|
}
|
|
795
|
-
/**
|
|
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
|
+
*/
|
|
796
1367
|
async update(connectionId, body) {
|
|
797
1368
|
const { data } = await this.client.PATCH(
|
|
798
1369
|
"/v1/companies/{company_id}/payment-connections/{connection_id}",
|
|
@@ -803,13 +1374,20 @@ var CompanyPaymentConnectionsResource = class {
|
|
|
803
1374
|
/**
|
|
804
1375
|
* Disconnect one connection. Tokens are revoked and auto-invoicing stops;
|
|
805
1376
|
* already-issued invoices are untouched.
|
|
1377
|
+
*
|
|
1378
|
+
* @param connectionId - Connection UUID.
|
|
806
1379
|
*/
|
|
807
1380
|
async disconnect(connectionId) {
|
|
808
1381
|
await this.client.DELETE("/v1/companies/{company_id}/payment-connections/{connection_id}", {
|
|
809
1382
|
params: { path: { ...this.path(), connection_id: connectionId } }
|
|
810
1383
|
});
|
|
811
1384
|
}
|
|
812
|
-
/**
|
|
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
|
+
*/
|
|
813
1391
|
events(connectionId) {
|
|
814
1392
|
return new CompanyPaymentEventsResource(this.client, this.companyId, connectionId);
|
|
815
1393
|
}
|
|
@@ -827,6 +1405,9 @@ var CompanyPaymentEventsResource = class {
|
|
|
827
1405
|
* Events of the connection, most recent first. Nothing is hidden by default:
|
|
828
1406
|
* skipped events, duplicates and disputes are all returned — narrow with the
|
|
829
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`.
|
|
830
1411
|
*/
|
|
831
1412
|
async list(params) {
|
|
832
1413
|
const { data } = await this.client.GET(
|
|
@@ -835,7 +1416,12 @@ var CompanyPaymentEventsResource = class {
|
|
|
835
1416
|
);
|
|
836
1417
|
return data.data;
|
|
837
1418
|
}
|
|
838
|
-
/**
|
|
1419
|
+
/**
|
|
1420
|
+
* Get one event.
|
|
1421
|
+
*
|
|
1422
|
+
* @param eventId - Event UUID.
|
|
1423
|
+
* @returns The event.
|
|
1424
|
+
*/
|
|
839
1425
|
async get(eventId) {
|
|
840
1426
|
const { data } = await this.client.GET(
|
|
841
1427
|
"/v1/companies/{company_id}/payment-connections/{connection_id}/events/{event_id}",
|
|
@@ -847,6 +1433,9 @@ var CompanyPaymentEventsResource = class {
|
|
|
847
1433
|
* Reprocess an event whose automatic invoicing didn't complete, applying the NIF's
|
|
848
1434
|
* **current** configuration. Only retryable states qualify and the retry budget is
|
|
849
1435
|
* finite: otherwise `400`.
|
|
1436
|
+
*
|
|
1437
|
+
* @param eventId - Event UUID.
|
|
1438
|
+
* @returns The event after the retry.
|
|
850
1439
|
*/
|
|
851
1440
|
async retry(eventId) {
|
|
852
1441
|
const { data } = await this.client.POST(
|
|
@@ -857,7 +1446,10 @@ var CompanyPaymentEventsResource = class {
|
|
|
857
1446
|
}
|
|
858
1447
|
/**
|
|
859
1448
|
* Build a **draft** invoice from an event that couldn't be invoiced automatically,
|
|
860
|
-
* 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`.
|
|
861
1453
|
*/
|
|
862
1454
|
async draft(eventId) {
|
|
863
1455
|
const { data } = await this.client.POST(
|
|
@@ -866,7 +1458,12 @@ var CompanyPaymentEventsResource = class {
|
|
|
866
1458
|
);
|
|
867
1459
|
return data.data;
|
|
868
1460
|
}
|
|
869
|
-
/**
|
|
1461
|
+
/**
|
|
1462
|
+
* Mark an event as dealt with outside the automatic flow.
|
|
1463
|
+
*
|
|
1464
|
+
* @param eventId - Event UUID.
|
|
1465
|
+
* @returns The resolved event.
|
|
1466
|
+
*/
|
|
870
1467
|
async resolve(eventId) {
|
|
871
1468
|
const { data } = await this.client.POST(
|
|
872
1469
|
"/v1/companies/{company_id}/payment-connections/{connection_id}/events/{event_id}/resolve",
|
|
@@ -874,7 +1471,12 @@ var CompanyPaymentEventsResource = class {
|
|
|
874
1471
|
);
|
|
875
1472
|
return data.data;
|
|
876
1473
|
}
|
|
877
|
-
/**
|
|
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
|
+
*/
|
|
878
1480
|
async discard(eventId) {
|
|
879
1481
|
const { data } = await this.client.POST(
|
|
880
1482
|
"/v1/companies/{company_id}/payment-connections/{connection_id}/events/{event_id}/discard",
|
|
@@ -882,7 +1484,12 @@ var CompanyPaymentEventsResource = class {
|
|
|
882
1484
|
);
|
|
883
1485
|
return data.data;
|
|
884
1486
|
}
|
|
885
|
-
/**
|
|
1487
|
+
/**
|
|
1488
|
+
* Bring a discarded event back into the list.
|
|
1489
|
+
*
|
|
1490
|
+
* @param eventId - Event UUID.
|
|
1491
|
+
* @returns The restored event.
|
|
1492
|
+
*/
|
|
886
1493
|
async restore(eventId) {
|
|
887
1494
|
const { data } = await this.client.POST(
|
|
888
1495
|
"/v1/companies/{company_id}/payment-connections/{connection_id}/events/{event_id}/restore",
|
|
@@ -892,6 +1499,44 @@ var CompanyPaymentEventsResource = class {
|
|
|
892
1499
|
}
|
|
893
1500
|
};
|
|
894
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
|
+
}
|
|
1539
|
+
|
|
895
1540
|
// src/resources/company.ts
|
|
896
1541
|
var CompanyScope = class {
|
|
897
1542
|
constructor(client, companyId) {
|
|
@@ -909,14 +1554,24 @@ var CompanyScope = class {
|
|
|
909
1554
|
path() {
|
|
910
1555
|
return { company_id: this.companyId };
|
|
911
1556
|
}
|
|
912
|
-
/**
|
|
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
|
+
*/
|
|
913
1563
|
async get(params) {
|
|
914
1564
|
const { data } = await this.client.GET("/v1/companies/{company_id}", {
|
|
915
1565
|
params: { path: this.path(), query: params }
|
|
916
1566
|
});
|
|
917
1567
|
return data.data;
|
|
918
1568
|
}
|
|
919
|
-
/**
|
|
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
|
+
*/
|
|
920
1575
|
async update(body) {
|
|
921
1576
|
const { data } = await this.client.PATCH("/v1/companies/{company_id}", {
|
|
922
1577
|
params: { path: this.path() },
|
|
@@ -924,18 +1579,30 @@ var CompanyScope = class {
|
|
|
924
1579
|
});
|
|
925
1580
|
return data.data;
|
|
926
1581
|
}
|
|
927
|
-
/**
|
|
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
|
+
*/
|
|
928
1586
|
async delete() {
|
|
929
1587
|
await this.client.DELETE("/v1/companies/{company_id}", { params: { path: this.path() } });
|
|
930
1588
|
}
|
|
931
|
-
/**
|
|
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
|
+
*/
|
|
932
1595
|
async fiscalSummary(params) {
|
|
933
1596
|
const { data } = await this.client.GET("/v1/companies/{company_id}/fiscal-summary", {
|
|
934
1597
|
params: { path: this.path(), query: params }
|
|
935
1598
|
});
|
|
936
1599
|
return data.data;
|
|
937
1600
|
}
|
|
938
|
-
/**
|
|
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
|
+
*/
|
|
939
1606
|
async issuingReadiness() {
|
|
940
1607
|
const { data } = await this.client.GET("/v1/companies/{company_id}/issuing-readiness", {
|
|
941
1608
|
params: { path: this.path() }
|
|
@@ -950,10 +1617,16 @@ var CompanyInvoicesResource = class {
|
|
|
950
1617
|
this.schedule = new CompanyInvoiceScheduleResource(client, companyId);
|
|
951
1618
|
}
|
|
952
1619
|
/**
|
|
953
|
-
* 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.
|
|
954
1626
|
*/
|
|
955
|
-
async derive(body) {
|
|
1627
|
+
async derive(body, options) {
|
|
956
1628
|
const { data } = await this.client.POST("/v1/companies/{company_id}/invoices/derivations", {
|
|
1629
|
+
...toRequestInit(options),
|
|
957
1630
|
params: { path: { company_id: this.companyId } },
|
|
958
1631
|
body
|
|
959
1632
|
});
|
|
@@ -962,88 +1635,309 @@ var CompanyInvoicesResource = class {
|
|
|
962
1635
|
path(rest) {
|
|
963
1636
|
return { company_id: this.companyId, ...rest };
|
|
964
1637
|
}
|
|
965
|
-
|
|
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) {
|
|
966
1652
|
const { data } = await this.client.GET("/v1/companies/{company_id}/invoices", {
|
|
1653
|
+
...toRequestInit(options),
|
|
967
1654
|
params: { path: this.path(), query: params }
|
|
968
1655
|
});
|
|
969
1656
|
return data.data;
|
|
970
1657
|
}
|
|
971
|
-
|
|
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) {
|
|
972
1686
|
const { data } = await this.client.POST("/v1/companies/{company_id}/invoices", {
|
|
1687
|
+
...toRequestInit(options),
|
|
973
1688
|
params: { path: this.path(), query: params },
|
|
974
1689
|
body
|
|
975
1690
|
});
|
|
976
1691
|
return data.data;
|
|
977
1692
|
}
|
|
978
|
-
|
|
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) {
|
|
979
1746
|
const { data } = await this.client.GET("/v1/companies/{company_id}/invoices/{invoice_id}", {
|
|
1747
|
+
...toRequestInit(options),
|
|
980
1748
|
params: { path: this.path({ invoice_id: invoiceId }) }
|
|
981
1749
|
});
|
|
982
1750
|
return data.data;
|
|
983
1751
|
}
|
|
984
|
-
/**
|
|
985
|
-
|
|
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) {
|
|
986
1762
|
const { data } = await this.client.PATCH("/v1/companies/{company_id}/invoices/{invoice_id}", {
|
|
1763
|
+
...toRequestInit(options),
|
|
987
1764
|
params: { path: this.path({ invoice_id: invoiceId }) },
|
|
988
1765
|
body
|
|
989
1766
|
});
|
|
990
1767
|
return data.data;
|
|
991
1768
|
}
|
|
992
|
-
/**
|
|
993
|
-
|
|
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) {
|
|
994
1776
|
await this.client.DELETE("/v1/companies/{company_id}/invoices/{invoice_id}", {
|
|
1777
|
+
...toRequestInit(options),
|
|
995
1778
|
params: { path: this.path({ invoice_id: invoiceId }) }
|
|
996
1779
|
});
|
|
997
1780
|
}
|
|
998
|
-
/**
|
|
999
|
-
|
|
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) {
|
|
1000
1791
|
const { data } = await this.client.POST("/v1/companies/{company_id}/invoices/{invoice_id}/issue", {
|
|
1792
|
+
...toRequestInit(options),
|
|
1001
1793
|
params: { path: this.path({ invoice_id: invoiceId }), query: params }
|
|
1002
1794
|
});
|
|
1003
1795
|
return data.data;
|
|
1004
1796
|
}
|
|
1005
|
-
/**
|
|
1006
|
-
|
|
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) {
|
|
1007
1807
|
const { data } = await this.client.POST("/v1/companies/{company_id}/invoices/{invoice_id}/void", {
|
|
1808
|
+
...toRequestInit(options),
|
|
1008
1809
|
params: { path: this.path({ invoice_id: invoiceId }) },
|
|
1009
1810
|
body
|
|
1010
1811
|
});
|
|
1011
1812
|
return data.data;
|
|
1012
1813
|
}
|
|
1013
|
-
/**
|
|
1014
|
-
|
|
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) {
|
|
1015
1835
|
const { data } = await this.client.POST("/v1/companies/{company_id}/invoices/{invoice_id}/corrective", {
|
|
1836
|
+
...toRequestInit(options),
|
|
1016
1837
|
params: { path: this.path({ invoice_id: invoiceId }) },
|
|
1017
1838
|
body
|
|
1018
1839
|
});
|
|
1019
1840
|
return data.data;
|
|
1020
1841
|
}
|
|
1021
|
-
/**
|
|
1022
|
-
|
|
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) {
|
|
1023
1851
|
const { data } = await this.client.POST("/v1/companies/{company_id}/invoices/{invoice_id}/convert-to-invoice", {
|
|
1852
|
+
...toRequestInit(options),
|
|
1024
1853
|
params: { path: this.path({ invoice_id: invoiceId }) },
|
|
1025
1854
|
body
|
|
1026
1855
|
});
|
|
1027
1856
|
return data.data;
|
|
1028
1857
|
}
|
|
1029
|
-
/**
|
|
1030
|
-
|
|
1858
|
+
/**
|
|
1859
|
+
* Issue a full invoice in exchange for one or more issued simplified invoices, when the
|
|
1860
|
+
* customer asks for an invoice with their details. It is not a corrective: the simplified
|
|
1861
|
+
* invoices become `VOIDED` with `void_cause: 'EXCHANGED'`, and the new `STANDARD` invoice
|
|
1862
|
+
* lists them in `replaced_invoice_ids`.
|
|
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
|
+
*
|
|
1868
|
+
* @example
|
|
1869
|
+
* ```typescript
|
|
1870
|
+
* const invoice = await company.invoices.createSimplifiedExchange({
|
|
1871
|
+
* simplified_invoice_ids: ['simplified-uuid'],
|
|
1872
|
+
* recipient: { customer_id: 'customer-uuid' },
|
|
1873
|
+
* });
|
|
1874
|
+
* ```
|
|
1875
|
+
*/
|
|
1876
|
+
async createSimplifiedExchange(body, options) {
|
|
1877
|
+
const { data } = await this.client.POST("/v1/companies/{company_id}/invoices/simplified-exchanges", {
|
|
1878
|
+
...toRequestInit(options),
|
|
1879
|
+
params: { path: this.path() },
|
|
1880
|
+
body
|
|
1881
|
+
});
|
|
1882
|
+
return data.data;
|
|
1883
|
+
}
|
|
1884
|
+
/**
|
|
1885
|
+
* The VeriFactu records of an invoice, oldest first: its registration and, if it was
|
|
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`.
|
|
1891
|
+
*/
|
|
1892
|
+
async verifactuRecords(invoiceId, options) {
|
|
1893
|
+
const { data } = await this.client.GET("/v1/companies/{company_id}/invoices/{invoice_id}/verifactu-records", {
|
|
1894
|
+
...toRequestInit(options),
|
|
1895
|
+
params: { path: this.path({ invoice_id: invoiceId }) }
|
|
1896
|
+
});
|
|
1897
|
+
return data.data.records;
|
|
1898
|
+
}
|
|
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) {
|
|
1031
1909
|
const { data } = await this.client.PUT("/v1/companies/{company_id}/invoices/{invoice_id}/status", {
|
|
1910
|
+
...toRequestInit(options),
|
|
1032
1911
|
params: { path: this.path({ invoice_id: invoiceId }) },
|
|
1033
1912
|
body
|
|
1034
1913
|
});
|
|
1035
1914
|
return data.data;
|
|
1036
1915
|
}
|
|
1037
|
-
/**
|
|
1038
|
-
|
|
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) {
|
|
1039
1924
|
const { data } = await this.client.GET("/v1/companies/{company_id}/invoices/{invoice_id}/pdf", {
|
|
1925
|
+
...toRequestInit(options),
|
|
1040
1926
|
params: { path: this.path({ invoice_id: invoiceId }) }
|
|
1041
1927
|
});
|
|
1042
1928
|
return data.data;
|
|
1043
1929
|
}
|
|
1044
|
-
/**
|
|
1045
|
-
|
|
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) {
|
|
1046
1939
|
const { data } = await this.client.POST("/v1/companies/{company_id}/invoices/{invoice_id}/send", {
|
|
1940
|
+
...toRequestInit(options),
|
|
1047
1941
|
params: { path: this.path({ invoice_id: invoiceId }) },
|
|
1048
1942
|
body
|
|
1049
1943
|
});
|
|
@@ -1055,6 +1949,12 @@ var CompanyInvoiceScheduleResource = class {
|
|
|
1055
1949
|
this.client = client;
|
|
1056
1950
|
this.companyId = companyId;
|
|
1057
1951
|
}
|
|
1952
|
+
/**
|
|
1953
|
+
* Get the schedule of an invoice.
|
|
1954
|
+
*
|
|
1955
|
+
* @param invoiceId - Invoice UUID.
|
|
1956
|
+
* @returns `scheduled_for` and `generation_mode`.
|
|
1957
|
+
*/
|
|
1058
1958
|
async get(invoiceId) {
|
|
1059
1959
|
const { data } = await this.client.GET(
|
|
1060
1960
|
"/v1/companies/{company_id}/invoices/{invoice_id}/schedule",
|
|
@@ -1065,6 +1965,10 @@ var CompanyInvoiceScheduleResource = class {
|
|
|
1065
1965
|
/**
|
|
1066
1966
|
* Set or move the schedule. One `PUT` replaces the three legacy calls
|
|
1067
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.
|
|
1068
1972
|
*/
|
|
1069
1973
|
async set(invoiceId, body) {
|
|
1070
1974
|
const { data } = await this.client.PUT(
|
|
@@ -1073,7 +1977,12 @@ var CompanyInvoiceScheduleResource = class {
|
|
|
1073
1977
|
);
|
|
1074
1978
|
return data.data;
|
|
1075
1979
|
}
|
|
1076
|
-
/**
|
|
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
|
+
*/
|
|
1077
1986
|
async clear(invoiceId) {
|
|
1078
1987
|
await this.client.DELETE("/v1/companies/{company_id}/invoices/{invoice_id}/schedule", {
|
|
1079
1988
|
params: { path: { company_id: this.companyId, invoice_id: invoiceId } }
|
|
@@ -1085,12 +1994,24 @@ var CompanyCustomersResource = class {
|
|
|
1085
1994
|
this.client = client;
|
|
1086
1995
|
this.companyId = companyId;
|
|
1087
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
|
+
*/
|
|
1088
2003
|
async list(params) {
|
|
1089
2004
|
const { data } = await this.client.GET("/v1/companies/{company_id}/customers", {
|
|
1090
2005
|
params: { path: { company_id: this.companyId }, query: params }
|
|
1091
2006
|
});
|
|
1092
2007
|
return data.data;
|
|
1093
2008
|
}
|
|
2009
|
+
/**
|
|
2010
|
+
* Create a customer.
|
|
2011
|
+
*
|
|
2012
|
+
* @param body - Legal name, NIF (or alternative id) and address.
|
|
2013
|
+
* @returns The created customer.
|
|
2014
|
+
*/
|
|
1094
2015
|
async create(body) {
|
|
1095
2016
|
const { data } = await this.client.POST("/v1/companies/{company_id}/customers", {
|
|
1096
2017
|
params: { path: { company_id: this.companyId } },
|
|
@@ -1098,6 +2019,12 @@ var CompanyCustomersResource = class {
|
|
|
1098
2019
|
});
|
|
1099
2020
|
return data.data;
|
|
1100
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
|
+
*/
|
|
1101
2028
|
async createBulk(body) {
|
|
1102
2029
|
const { data } = await this.client.POST("/v1/companies/{company_id}/customers/bulk", {
|
|
1103
2030
|
params: { path: { company_id: this.companyId } },
|
|
@@ -1105,12 +2032,25 @@ var CompanyCustomersResource = class {
|
|
|
1105
2032
|
});
|
|
1106
2033
|
return data.data;
|
|
1107
2034
|
}
|
|
2035
|
+
/**
|
|
2036
|
+
* Get one customer.
|
|
2037
|
+
*
|
|
2038
|
+
* @param customerId - Customer UUID.
|
|
2039
|
+
* @returns The customer.
|
|
2040
|
+
*/
|
|
1108
2041
|
async get(customerId) {
|
|
1109
2042
|
const { data } = await this.client.GET("/v1/companies/{company_id}/customers/{customer_id}", {
|
|
1110
2043
|
params: { path: { company_id: this.companyId, customer_id: customerId } }
|
|
1111
2044
|
});
|
|
1112
2045
|
return data.data;
|
|
1113
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
|
+
*/
|
|
1114
2054
|
async update(customerId, body) {
|
|
1115
2055
|
const { data } = await this.client.PATCH("/v1/companies/{company_id}/customers/{customer_id}", {
|
|
1116
2056
|
params: { path: { company_id: this.companyId, customer_id: customerId } },
|
|
@@ -1118,6 +2058,12 @@ var CompanyCustomersResource = class {
|
|
|
1118
2058
|
});
|
|
1119
2059
|
return data.data;
|
|
1120
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
|
+
*/
|
|
1121
2067
|
async delete(customerId) {
|
|
1122
2068
|
await this.client.DELETE("/v1/companies/{company_id}/customers/{customer_id}", {
|
|
1123
2069
|
params: { path: { company_id: this.companyId, customer_id: customerId } }
|
|
@@ -1129,12 +2075,24 @@ var CompanyProductsResource = class {
|
|
|
1129
2075
|
this.client = client;
|
|
1130
2076
|
this.companyId = companyId;
|
|
1131
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
|
+
*/
|
|
1132
2084
|
async list(params) {
|
|
1133
2085
|
const { data } = await this.client.GET("/v1/companies/{company_id}/products", {
|
|
1134
2086
|
params: { path: { company_id: this.companyId }, query: params }
|
|
1135
2087
|
});
|
|
1136
2088
|
return data.data;
|
|
1137
2089
|
}
|
|
2090
|
+
/**
|
|
2091
|
+
* Create a product or service.
|
|
2092
|
+
*
|
|
2093
|
+
* @param body - Name, category, price and main tax.
|
|
2094
|
+
* @returns The created product.
|
|
2095
|
+
*/
|
|
1138
2096
|
async create(body) {
|
|
1139
2097
|
const { data } = await this.client.POST("/v1/companies/{company_id}/products", {
|
|
1140
2098
|
params: { path: { company_id: this.companyId } },
|
|
@@ -1142,12 +2100,25 @@ var CompanyProductsResource = class {
|
|
|
1142
2100
|
});
|
|
1143
2101
|
return data.data;
|
|
1144
2102
|
}
|
|
2103
|
+
/**
|
|
2104
|
+
* Get one product.
|
|
2105
|
+
*
|
|
2106
|
+
* @param productId - Product UUID.
|
|
2107
|
+
* @returns The product.
|
|
2108
|
+
*/
|
|
1145
2109
|
async get(productId) {
|
|
1146
2110
|
const { data } = await this.client.GET("/v1/companies/{company_id}/products/{product_id}", {
|
|
1147
2111
|
params: { path: { company_id: this.companyId, product_id: productId } }
|
|
1148
2112
|
});
|
|
1149
2113
|
return data.data;
|
|
1150
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
|
+
*/
|
|
1151
2122
|
async update(productId, body) {
|
|
1152
2123
|
const { data } = await this.client.PATCH("/v1/companies/{company_id}/products/{product_id}", {
|
|
1153
2124
|
params: { path: { company_id: this.companyId, product_id: productId } },
|
|
@@ -1155,6 +2126,11 @@ var CompanyProductsResource = class {
|
|
|
1155
2126
|
});
|
|
1156
2127
|
return data.data;
|
|
1157
2128
|
}
|
|
2129
|
+
/**
|
|
2130
|
+
* Delete a product from the catalog. Existing invoice lines are unaffected.
|
|
2131
|
+
*
|
|
2132
|
+
* @param productId - Product UUID.
|
|
2133
|
+
*/
|
|
1158
2134
|
async delete(productId) {
|
|
1159
2135
|
await this.client.DELETE("/v1/companies/{company_id}/products/{product_id}", {
|
|
1160
2136
|
params: { path: { company_id: this.companyId, product_id: productId } }
|
|
@@ -1166,12 +2142,24 @@ var CompanySeriesResource = class {
|
|
|
1166
2142
|
this.client = client;
|
|
1167
2143
|
this.companyId = companyId;
|
|
1168
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
|
+
*/
|
|
1169
2151
|
async list(params) {
|
|
1170
2152
|
const { data } = await this.client.GET("/v1/companies/{company_id}/series", {
|
|
1171
2153
|
params: { path: { company_id: this.companyId }, query: params }
|
|
1172
2154
|
});
|
|
1173
2155
|
return data.data;
|
|
1174
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
|
+
*/
|
|
1175
2163
|
async create(body) {
|
|
1176
2164
|
const { data } = await this.client.POST("/v1/companies/{company_id}/series", {
|
|
1177
2165
|
params: { path: { company_id: this.companyId } },
|
|
@@ -1179,6 +2167,13 @@ var CompanySeriesResource = class {
|
|
|
1179
2167
|
});
|
|
1180
2168
|
return data.data;
|
|
1181
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
|
+
*/
|
|
1182
2177
|
async update(seriesId, body) {
|
|
1183
2178
|
const { data } = await this.client.PATCH("/v1/companies/{company_id}/series/{series_id}", {
|
|
1184
2179
|
params: { path: { company_id: this.companyId, series_id: seriesId } },
|
|
@@ -1186,26 +2181,45 @@ var CompanySeriesResource = class {
|
|
|
1186
2181
|
});
|
|
1187
2182
|
return data.data;
|
|
1188
2183
|
}
|
|
2184
|
+
/**
|
|
2185
|
+
* Delete (soft-delete) a series. Its code stays taken, since issued invoices carry it.
|
|
2186
|
+
*
|
|
2187
|
+
* @param seriesId - Series UUID.
|
|
2188
|
+
*/
|
|
1189
2189
|
async delete(seriesId) {
|
|
1190
2190
|
await this.client.DELETE("/v1/companies/{company_id}/series/{series_id}", {
|
|
1191
2191
|
params: { path: { company_id: this.companyId, series_id: seriesId } }
|
|
1192
2192
|
});
|
|
1193
2193
|
}
|
|
1194
|
-
/**
|
|
2194
|
+
/**
|
|
2195
|
+
* The current default series per document type.
|
|
2196
|
+
*
|
|
2197
|
+
* @returns One entry per document type, saying whether a default exists.
|
|
2198
|
+
*/
|
|
1195
2199
|
async getDefaults() {
|
|
1196
2200
|
const { data } = await this.client.GET("/v1/companies/{company_id}/series/defaults", {
|
|
1197
2201
|
params: { path: { company_id: this.companyId } }
|
|
1198
2202
|
});
|
|
1199
2203
|
return data.data;
|
|
1200
2204
|
}
|
|
1201
|
-
/**
|
|
2205
|
+
/**
|
|
2206
|
+
* Ensure a default series exists per document type, creating the missing ones.
|
|
2207
|
+
* Idempotent.
|
|
2208
|
+
*
|
|
2209
|
+
* @returns The default series.
|
|
2210
|
+
*/
|
|
1202
2211
|
async ensureDefaults() {
|
|
1203
2212
|
const { data } = await this.client.PUT("/v1/companies/{company_id}/series/defaults", {
|
|
1204
2213
|
params: { path: { company_id: this.companyId } }
|
|
1205
2214
|
});
|
|
1206
2215
|
return data.data;
|
|
1207
2216
|
}
|
|
1208
|
-
/**
|
|
2217
|
+
/**
|
|
2218
|
+
* Mark a series as the default for its document type.
|
|
2219
|
+
*
|
|
2220
|
+
* @param seriesId - Series UUID.
|
|
2221
|
+
* @returns The series.
|
|
2222
|
+
*/
|
|
1209
2223
|
async setDefault(seriesId) {
|
|
1210
2224
|
const { data } = await this.client.PUT("/v1/companies/{company_id}/series/{series_id}/default", {
|
|
1211
2225
|
params: { path: { company_id: this.companyId, series_id: seriesId } }
|
|
@@ -1221,12 +2235,24 @@ var CompanyRecurringInvoicesResource = class {
|
|
|
1221
2235
|
path(rest) {
|
|
1222
2236
|
return { company_id: this.companyId, ...rest };
|
|
1223
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
|
+
*/
|
|
1224
2244
|
async list(params) {
|
|
1225
2245
|
const { data } = await this.client.GET("/v1/companies/{company_id}/recurring-invoices", {
|
|
1226
2246
|
params: { path: this.path(), query: params }
|
|
1227
2247
|
});
|
|
1228
2248
|
return data.data;
|
|
1229
2249
|
}
|
|
2250
|
+
/**
|
|
2251
|
+
* Create a recurring invoice template.
|
|
2252
|
+
*
|
|
2253
|
+
* @param body - Frequency, schedule, recipient and lines.
|
|
2254
|
+
* @returns The recurring invoice.
|
|
2255
|
+
*/
|
|
1230
2256
|
async create(body) {
|
|
1231
2257
|
const { data } = await this.client.POST("/v1/companies/{company_id}/recurring-invoices", {
|
|
1232
2258
|
params: { path: this.path() },
|
|
@@ -1234,12 +2260,25 @@ var CompanyRecurringInvoicesResource = class {
|
|
|
1234
2260
|
});
|
|
1235
2261
|
return data.data;
|
|
1236
2262
|
}
|
|
2263
|
+
/**
|
|
2264
|
+
* Get one recurring invoice.
|
|
2265
|
+
*
|
|
2266
|
+
* @param recurringInvoiceId - Recurring invoice UUID.
|
|
2267
|
+
* @returns The recurring invoice.
|
|
2268
|
+
*/
|
|
1237
2269
|
async get(recurringInvoiceId) {
|
|
1238
2270
|
const { data } = await this.client.GET("/v1/companies/{company_id}/recurring-invoices/{recurring_invoice_id}", {
|
|
1239
2271
|
params: { path: this.path({ recurring_invoice_id: recurringInvoiceId }) }
|
|
1240
2272
|
});
|
|
1241
2273
|
return data.data;
|
|
1242
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
|
+
*/
|
|
1243
2282
|
async update(recurringInvoiceId, body) {
|
|
1244
2283
|
const { data } = await this.client.PATCH("/v1/companies/{company_id}/recurring-invoices/{recurring_invoice_id}", {
|
|
1245
2284
|
params: { path: this.path({ recurring_invoice_id: recurringInvoiceId }) },
|
|
@@ -1247,12 +2286,24 @@ var CompanyRecurringInvoicesResource = class {
|
|
|
1247
2286
|
});
|
|
1248
2287
|
return data.data;
|
|
1249
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
|
+
*/
|
|
1250
2295
|
async delete(recurringInvoiceId) {
|
|
1251
2296
|
await this.client.DELETE("/v1/companies/{company_id}/recurring-invoices/{recurring_invoice_id}", {
|
|
1252
2297
|
params: { path: this.path({ recurring_invoice_id: recurringInvoiceId }) }
|
|
1253
2298
|
});
|
|
1254
2299
|
}
|
|
1255
|
-
/**
|
|
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
|
+
*/
|
|
1256
2307
|
async setStatus(recurringInvoiceId, body) {
|
|
1257
2308
|
const { data } = await this.client.PUT("/v1/companies/{company_id}/recurring-invoices/{recurring_invoice_id}/status", {
|
|
1258
2309
|
params: { path: this.path({ recurring_invoice_id: recurringInvoiceId }) },
|
|
@@ -1260,26 +2311,49 @@ var CompanyRecurringInvoicesResource = class {
|
|
|
1260
2311
|
});
|
|
1261
2312
|
return data.data;
|
|
1262
2313
|
}
|
|
1263
|
-
/**
|
|
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
|
+
*/
|
|
1264
2320
|
async skip(recurringInvoiceId) {
|
|
1265
2321
|
const { data } = await this.client.POST("/v1/companies/{company_id}/recurring-invoices/{recurring_invoice_id}/skip", {
|
|
1266
2322
|
params: { path: this.path({ recurring_invoice_id: recurringInvoiceId }) }
|
|
1267
2323
|
});
|
|
1268
2324
|
return data.data;
|
|
1269
2325
|
}
|
|
1270
|
-
/**
|
|
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
|
+
*/
|
|
1271
2332
|
async generateNow(recurringInvoiceId) {
|
|
1272
2333
|
const { data } = await this.client.POST("/v1/companies/{company_id}/recurring-invoices/{recurring_invoice_id}/generate", {
|
|
1273
2334
|
params: { path: this.path({ recurring_invoice_id: recurringInvoiceId }) }
|
|
1274
2335
|
});
|
|
1275
2336
|
return data.data;
|
|
1276
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
|
+
*/
|
|
1277
2344
|
async nextOccurrence(recurringInvoiceId) {
|
|
1278
2345
|
const { data } = await this.client.GET("/v1/companies/{company_id}/recurring-invoices/{recurring_invoice_id}/next-occurrence", {
|
|
1279
2346
|
params: { path: this.path({ recurring_invoice_id: recurringInvoiceId }) }
|
|
1280
2347
|
});
|
|
1281
2348
|
return data.data;
|
|
1282
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
|
+
*/
|
|
1283
2357
|
async history(recurringInvoiceId, params) {
|
|
1284
2358
|
const { data } = await this.client.GET("/v1/companies/{company_id}/recurring-invoices/{recurring_invoice_id}/history", {
|
|
1285
2359
|
params: { path: this.path({ recurring_invoice_id: recurringInvoiceId }), query: params }
|
|
@@ -1292,13 +2366,23 @@ var CompanyTaxConfigurationResource = class {
|
|
|
1292
2366
|
this.client = client;
|
|
1293
2367
|
this.companyId = companyId;
|
|
1294
2368
|
}
|
|
2369
|
+
/**
|
|
2370
|
+
* Get the tax configuration.
|
|
2371
|
+
*
|
|
2372
|
+
* @returns The company's tax defaults.
|
|
2373
|
+
*/
|
|
1295
2374
|
async get() {
|
|
1296
2375
|
const { data } = await this.client.GET("/v1/companies/{company_id}/tax-configuration", {
|
|
1297
2376
|
params: { path: { company_id: this.companyId } }
|
|
1298
2377
|
});
|
|
1299
2378
|
return data.data;
|
|
1300
2379
|
}
|
|
1301
|
-
/**
|
|
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
|
+
*/
|
|
1302
2386
|
async update(body) {
|
|
1303
2387
|
const { data } = await this.client.PUT("/v1/companies/{company_id}/tax-configuration", {
|
|
1304
2388
|
params: { path: { company_id: this.companyId } },
|
|
@@ -1312,13 +2396,23 @@ var CompanyVeriFactuConfigurationResource = class {
|
|
|
1312
2396
|
this.client = client;
|
|
1313
2397
|
this.companyId = companyId;
|
|
1314
2398
|
}
|
|
2399
|
+
/**
|
|
2400
|
+
* Get the VeriFactu configuration of this NIF.
|
|
2401
|
+
*
|
|
2402
|
+
* @returns `enabled` and the server-resolved state of the NIF.
|
|
2403
|
+
*/
|
|
1315
2404
|
async get() {
|
|
1316
2405
|
const { data } = await this.client.GET("/v1/companies/{company_id}/verifactu-configuration", {
|
|
1317
2406
|
params: { path: { company_id: this.companyId } }
|
|
1318
2407
|
});
|
|
1319
2408
|
return data.data;
|
|
1320
2409
|
}
|
|
1321
|
-
/**
|
|
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
|
+
*/
|
|
1322
2416
|
async update(body) {
|
|
1323
2417
|
const { data } = await this.client.PUT("/v1/companies/{company_id}/verifactu-configuration", {
|
|
1324
2418
|
params: { path: { company_id: this.companyId } },
|
|
@@ -1344,7 +2438,11 @@ var BeeL = class {
|
|
|
1344
2438
|
}
|
|
1345
2439
|
/**
|
|
1346
2440
|
* Returns a facade scoped to one company (NIF) — the explicit multi-NIF surface.
|
|
1347
|
-
* 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.
|
|
1348
2446
|
*
|
|
1349
2447
|
* @example
|
|
1350
2448
|
* ```typescript
|
|
@@ -1356,8 +2454,12 @@ var BeeL = class {
|
|
|
1356
2454
|
return new CompanyScope(this.raw, companyId);
|
|
1357
2455
|
}
|
|
1358
2456
|
/**
|
|
1359
|
-
* Returns a facade scoped to one
|
|
1360
|
-
*
|
|
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.
|
|
1361
2463
|
*
|
|
1362
2464
|
* @example
|
|
1363
2465
|
* ```typescript
|
|
@@ -1374,6 +2476,10 @@ var BeeL = class {
|
|
|
1374
2476
|
* @deprecated Relies on the deprecated session-focus PDF endpoint. Use
|
|
1375
2477
|
* `beel.company(companyId).invoices.getPdf(invoiceId)` and fetch `download_url` instead.
|
|
1376
2478
|
*
|
|
2479
|
+
* @param invoiceId - Invoice UUID.
|
|
2480
|
+
* @returns The PDF bytes and its file name.
|
|
2481
|
+
* @throws {Error} When downloading the file fails.
|
|
2482
|
+
*
|
|
1377
2483
|
* @example
|
|
1378
2484
|
* ```typescript
|
|
1379
2485
|
* const { buffer, fileName } = await beel.downloadPdf('invoice-uuid');
|
|
@@ -1418,6 +2524,7 @@ var WebhookVerifier = class {
|
|
|
1418
2524
|
* const verifier = new WebhookVerifier('your_secret');
|
|
1419
2525
|
* const event = verifier.verify(rawBody, signature);
|
|
1420
2526
|
*
|
|
2527
|
+
* if (event.test) return; // a "Send test" delivery carries a synthetic `data`
|
|
1421
2528
|
* if (event.type === 'verifactu.status.updated') {
|
|
1422
2529
|
* console.log('Invoice:', event.data.invoice_number);
|
|
1423
2530
|
* console.log('Status:', event.data.new_status);
|
|
@@ -1541,6 +2648,24 @@ var InvoiceIssuedEvent;
|
|
|
1541
2648
|
})(type = InvoiceIssuedEvent2.type || (InvoiceIssuedEvent2.type = {}));
|
|
1542
2649
|
})(InvoiceIssuedEvent || (InvoiceIssuedEvent = {}));
|
|
1543
2650
|
|
|
2651
|
+
// src/generated-webhooks/models/InvoicePdfGeneratedEvent.ts
|
|
2652
|
+
var InvoicePdfGeneratedEvent;
|
|
2653
|
+
((InvoicePdfGeneratedEvent2) => {
|
|
2654
|
+
let type;
|
|
2655
|
+
((type2) => {
|
|
2656
|
+
type2["INVOICE_PDF_GENERATED"] = "invoice.pdf.generated";
|
|
2657
|
+
})(type = InvoicePdfGeneratedEvent2.type || (InvoicePdfGeneratedEvent2.type = {}));
|
|
2658
|
+
})(InvoicePdfGeneratedEvent || (InvoicePdfGeneratedEvent = {}));
|
|
2659
|
+
|
|
2660
|
+
// src/generated-webhooks/models/InvoiceScheduleFailedEvent.ts
|
|
2661
|
+
var InvoiceScheduleFailedEvent;
|
|
2662
|
+
((InvoiceScheduleFailedEvent2) => {
|
|
2663
|
+
let type;
|
|
2664
|
+
((type2) => {
|
|
2665
|
+
type2["INVOICE_SCHEDULE_FAILED"] = "invoice.schedule_failed";
|
|
2666
|
+
})(type = InvoiceScheduleFailedEvent2.type || (InvoiceScheduleFailedEvent2.type = {}));
|
|
2667
|
+
})(InvoiceScheduleFailedEvent || (InvoiceScheduleFailedEvent = {}));
|
|
2668
|
+
|
|
1544
2669
|
// src/generated-webhooks/models/InvoiceVoidedEvent.ts
|
|
1545
2670
|
var InvoiceVoidedEvent;
|
|
1546
2671
|
((InvoiceVoidedEvent2) => {
|
|
@@ -1591,8 +2716,10 @@ var WebhookEventType = /* @__PURE__ */ ((WebhookEventType2) => {
|
|
|
1591
2716
|
WebhookEventType2["VERIFACTU_STATUS_UPDATED"] = "verifactu.status.updated";
|
|
1592
2717
|
WebhookEventType2["INVOICE_ISSUED"] = "invoice.issued";
|
|
1593
2718
|
WebhookEventType2["INVOICE_EMAIL_SENT"] = "invoice.email.sent";
|
|
2719
|
+
WebhookEventType2["INVOICE_PDF_GENERATED"] = "invoice.pdf.generated";
|
|
1594
2720
|
WebhookEventType2["INVOICE_VOIDED"] = "invoice.voided";
|
|
1595
2721
|
WebhookEventType2["RECURRING_INVOICE_PAUSED"] = "recurring_invoice.paused";
|
|
2722
|
+
WebhookEventType2["INVOICE_SCHEDULE_FAILED"] = "invoice.schedule_failed";
|
|
1596
2723
|
WebhookEventType2["ACCOUNT_CLAIMED"] = "account.claimed";
|
|
1597
2724
|
WebhookEventType2["COMPANY_CREATED"] = "company.created";
|
|
1598
2725
|
WebhookEventType2["REPRESENTATION_SIGNED"] = "representation.signed";
|
|
@@ -1603,33 +2730,86 @@ var WebhookEventType = /* @__PURE__ */ ((WebhookEventType2) => {
|
|
|
1603
2730
|
var CustomerBuilder = class _CustomerBuilder {
|
|
1604
2731
|
constructor() {
|
|
1605
2732
|
}
|
|
2733
|
+
/**
|
|
2734
|
+
* Start a new builder.
|
|
2735
|
+
*
|
|
2736
|
+
* @returns An empty customer builder.
|
|
2737
|
+
*/
|
|
1606
2738
|
static create() {
|
|
1607
2739
|
return new _CustomerBuilder();
|
|
1608
2740
|
}
|
|
2741
|
+
/**
|
|
2742
|
+
* Legal name of the customer. Required.
|
|
2743
|
+
*
|
|
2744
|
+
* @param name - Legal name.
|
|
2745
|
+
* @returns This builder.
|
|
2746
|
+
*/
|
|
1609
2747
|
name(name) {
|
|
1610
2748
|
this._name = name;
|
|
1611
2749
|
return this;
|
|
1612
2750
|
}
|
|
2751
|
+
/**
|
|
2752
|
+
* NIF/CIF of the customer. Required.
|
|
2753
|
+
*
|
|
2754
|
+
* @param nif - Spanish tax id.
|
|
2755
|
+
* @returns This builder.
|
|
2756
|
+
*/
|
|
1613
2757
|
nif(nif) {
|
|
1614
2758
|
this._nif = nif;
|
|
1615
2759
|
return this;
|
|
1616
2760
|
}
|
|
2761
|
+
/**
|
|
2762
|
+
* Contact email.
|
|
2763
|
+
*
|
|
2764
|
+
* @param email - Email address.
|
|
2765
|
+
* @returns This builder.
|
|
2766
|
+
*/
|
|
1617
2767
|
email(email) {
|
|
1618
2768
|
this._email = email;
|
|
1619
2769
|
return this;
|
|
1620
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
|
+
*/
|
|
1621
2777
|
phone(phone) {
|
|
1622
2778
|
this._phone = phone;
|
|
1623
2779
|
return this;
|
|
1624
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
|
+
*/
|
|
1625
2793
|
address(street, number, postalCode, city, province, country, countryCode = "ES") {
|
|
1626
2794
|
this._address = { street, number, postal_code: postalCode, city, province, country, country_code: countryCode };
|
|
1627
2795
|
return this;
|
|
1628
2796
|
}
|
|
2797
|
+
/**
|
|
2798
|
+
* Internal notes about the customer.
|
|
2799
|
+
*
|
|
2800
|
+
* @param notes - Free text.
|
|
2801
|
+
* @returns This builder.
|
|
2802
|
+
*/
|
|
1629
2803
|
notes(notes) {
|
|
1630
2804
|
this._notes = notes;
|
|
1631
2805
|
return this;
|
|
1632
2806
|
}
|
|
2807
|
+
/**
|
|
2808
|
+
* Build the request body.
|
|
2809
|
+
*
|
|
2810
|
+
* @returns The `CreateCustomerRequest`.
|
|
2811
|
+
* @throws {Error} When the name, NIF or address is missing.
|
|
2812
|
+
*/
|
|
1633
2813
|
build() {
|
|
1634
2814
|
if (!this._name || this._name.trim().length === 0) throw new Error("Legal name is required");
|
|
1635
2815
|
if (!this._nif || this._nif.trim().length === 0) throw new Error("NIF/CIF is required");
|
|
@@ -1646,50 +2826,144 @@ var CustomerBuilder = class _CustomerBuilder {
|
|
|
1646
2826
|
};
|
|
1647
2827
|
|
|
1648
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
|
+
}
|
|
1649
2834
|
var InvoiceBuilder = class _InvoiceBuilder {
|
|
1650
2835
|
constructor() {
|
|
1651
2836
|
this._type = "STANDARD";
|
|
1652
2837
|
this._lines = [];
|
|
1653
2838
|
}
|
|
2839
|
+
/**
|
|
2840
|
+
* Start a new builder.
|
|
2841
|
+
*
|
|
2842
|
+
* @returns An empty `STANDARD` invoice builder.
|
|
2843
|
+
*/
|
|
1654
2844
|
static create() {
|
|
1655
2845
|
return new _InvoiceBuilder();
|
|
1656
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
|
+
*/
|
|
1657
2853
|
type(type) {
|
|
1658
2854
|
this._type = type;
|
|
1659
2855
|
return this;
|
|
1660
2856
|
}
|
|
2857
|
+
/**
|
|
2858
|
+
* Invoice a registered customer.
|
|
2859
|
+
*
|
|
2860
|
+
* @param customerId - Customer UUID.
|
|
2861
|
+
* @returns This builder.
|
|
2862
|
+
*/
|
|
1661
2863
|
forCustomer(customerId) {
|
|
1662
2864
|
this._customerId = customerId;
|
|
1663
2865
|
return this;
|
|
1664
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
|
+
*/
|
|
1665
2873
|
operationDate(date) {
|
|
1666
|
-
this._operationDate = date
|
|
2874
|
+
this._operationDate = toIsoDate(date);
|
|
1667
2875
|
return this;
|
|
1668
2876
|
}
|
|
2877
|
+
/**
|
|
2878
|
+
* Payment due date.
|
|
2879
|
+
*
|
|
2880
|
+
* @param date - A `Date` or a `YYYY-MM-DD` string.
|
|
2881
|
+
* @returns This builder.
|
|
2882
|
+
*/
|
|
1669
2883
|
dueDate(date) {
|
|
1670
|
-
this._dueDate = date
|
|
2884
|
+
this._dueDate = toIsoDate(date);
|
|
1671
2885
|
return this;
|
|
1672
2886
|
}
|
|
1673
|
-
|
|
1674
|
-
|
|
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
|
+
});
|
|
1675
2919
|
return this;
|
|
1676
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
|
+
*/
|
|
1677
2927
|
addLineObject(line) {
|
|
1678
2928
|
this._lines.push(line);
|
|
1679
2929
|
return this;
|
|
1680
2930
|
}
|
|
2931
|
+
/**
|
|
2932
|
+
* Notes printed on the invoice.
|
|
2933
|
+
*
|
|
2934
|
+
* @param notes - Free text.
|
|
2935
|
+
* @returns This builder.
|
|
2936
|
+
*/
|
|
1681
2937
|
notes(notes) {
|
|
1682
2938
|
this._notes = notes;
|
|
1683
2939
|
return this;
|
|
1684
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
|
+
*/
|
|
1685
2947
|
series(id) {
|
|
1686
2948
|
this._seriesId = id;
|
|
1687
2949
|
return this;
|
|
1688
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
|
+
*/
|
|
1689
2957
|
metadata(data) {
|
|
1690
2958
|
this._metadata = data;
|
|
1691
2959
|
return this;
|
|
1692
2960
|
}
|
|
2961
|
+
/**
|
|
2962
|
+
* Build the request body.
|
|
2963
|
+
*
|
|
2964
|
+
* @returns The `CreateInvoiceRequest`.
|
|
2965
|
+
* @throws {Error} When there is no customer or no line.
|
|
2966
|
+
*/
|
|
1693
2967
|
build() {
|
|
1694
2968
|
if (!this._customerId) throw new Error("Customer ID is required");
|
|
1695
2969
|
if (this._lines.length === 0) throw new Error("At least one invoice line is required");
|
|
@@ -1717,6 +2991,7 @@ export {
|
|
|
1717
2991
|
BeeLApiError,
|
|
1718
2992
|
BeeLAuthError,
|
|
1719
2993
|
BeeLConflictError,
|
|
2994
|
+
BeeLErrorCodes,
|
|
1720
2995
|
BeeLNotFoundError,
|
|
1721
2996
|
BeeLRateLimitError,
|
|
1722
2997
|
BeeLValidationError,
|
|
@@ -1733,6 +3008,7 @@ export {
|
|
|
1733
3008
|
CompanyTaxConfigurationResource,
|
|
1734
3009
|
CompanyVeriFactuConfigurationResource,
|
|
1735
3010
|
CustomerBuilder,
|
|
3011
|
+
EXTERNAL_REF_UNIQUE_INVOICE_TYPES,
|
|
1736
3012
|
InvoiceBuilder,
|
|
1737
3013
|
VeriFactuSubmissionStatus,
|
|
1738
3014
|
WebhookEventType,
|