@genz-its/sevdesk-sdk 0.0.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/dist/index.js ADDED
@@ -0,0 +1,2017 @@
1
+ //#region src/errors.ts
2
+ var SevDeskError = class extends Error {
3
+ status;
4
+ statusText;
5
+ body;
6
+ constructor(options) {
7
+ super(extractMessage(options));
8
+ this.name = "SevDeskError";
9
+ this.status = options.status;
10
+ this.statusText = options.statusText;
11
+ this.body = options.body;
12
+ }
13
+ };
14
+ function extractMessage(options) {
15
+ const fallback = `sevdesk API error: ${options.status} ${options.statusText}`;
16
+ const body = options.body;
17
+ if (typeof body === "string" && body.length > 0) return body;
18
+ if (typeof body === "object" && body !== null) {
19
+ const error = body.error;
20
+ if (typeof error === "object" && error !== null) {
21
+ const message = error.message;
22
+ if (typeof message === "string" && message.length > 0) return message;
23
+ }
24
+ const message = body.message;
25
+ if (typeof message === "string" && message.length > 0) return message;
26
+ }
27
+ return fallback;
28
+ }
29
+ //#endregion
30
+ //#region src/http-client.ts
31
+ const DEFAULT_BASE_URL = "https://my.sevdesk.de/api/v1";
32
+ const DEFAULT_TIMEOUT = 3e4;
33
+ const DEFAULT_USER_AGENT = "@genz-its/sevdesk-sdk";
34
+ const RETRY_MAX_ATTEMPTS = 3;
35
+ const RETRY_BASE_DELAY = 500;
36
+ const RETRY_MAX_DELAY = 1e4;
37
+ const RETRY_AFTER_MAX_DELAY = 6e4;
38
+ const RETRYABLE_METHODS = /* @__PURE__ */ new Set([
39
+ "GET",
40
+ "PUT",
41
+ "DELETE"
42
+ ]);
43
+ const RETRYABLE_STATUS_CODES = /* @__PURE__ */ new Set([
44
+ 429,
45
+ 500,
46
+ 502,
47
+ 503,
48
+ 504
49
+ ]);
50
+ var HttpClient = class {
51
+ token;
52
+ baseUrl;
53
+ timeout;
54
+ userAgent;
55
+ fetch;
56
+ constructor(options) {
57
+ this.token = options.token.trim();
58
+ this.baseUrl = options.baseUrl ?? "https://my.sevdesk.de/api/v1";
59
+ this.timeout = options.timeout ?? DEFAULT_TIMEOUT;
60
+ this.userAgent = options.userAgent ?? DEFAULT_USER_AGENT;
61
+ this.fetch = options.fetch ?? globalThis.fetch;
62
+ }
63
+ /**
64
+ * Performs a request and returns the payload of the `objects` response
65
+ * envelope. Responses without an envelope are returned as-is.
66
+ */
67
+ async request(options) {
68
+ const text = await (await this.fetchWithRetry(options)).text();
69
+ if (text.length === 0) return;
70
+ return unwrap(JSON.parse(text));
71
+ }
72
+ async fetchWithRetry(options) {
73
+ const url = this.buildUrl(options);
74
+ const retryable = RETRYABLE_METHODS.has(options.method);
75
+ for (let attempt = 0;; attempt++) {
76
+ const canRetry = retryable && attempt < RETRY_MAX_ATTEMPTS;
77
+ let response;
78
+ try {
79
+ response = await this.fetch(url, this.buildRequestInit(options));
80
+ } catch (error) {
81
+ if (canRetry) {
82
+ await delay(backoffDelay(attempt));
83
+ continue;
84
+ }
85
+ throw error;
86
+ }
87
+ if (response.ok) return response;
88
+ if (canRetry && RETRYABLE_STATUS_CODES.has(response.status)) {
89
+ await delay(retryAfterDelay(response.headers.get("Retry-After")) ?? backoffDelay(attempt));
90
+ continue;
91
+ }
92
+ throw new SevDeskError({
93
+ status: response.status,
94
+ statusText: response.statusText,
95
+ body: await parseErrorBody(response)
96
+ });
97
+ }
98
+ }
99
+ buildUrl(options) {
100
+ const url = new URL(this.baseUrl + options.path);
101
+ for (const [key, value] of Object.entries(options.query ?? {})) {
102
+ if (value === void 0) continue;
103
+ url.searchParams.append(key, Array.isArray(value) ? value.join(",") : String(value));
104
+ }
105
+ return url.toString();
106
+ }
107
+ buildRequestInit(options) {
108
+ const headers = {
109
+ Authorization: this.token,
110
+ Accept: "application/json",
111
+ "User-Agent": this.userAgent
112
+ };
113
+ let body;
114
+ if (options.formData) body = options.formData;
115
+ else if (options.body !== void 0) {
116
+ headers["Content-Type"] = "application/json";
117
+ body = JSON.stringify(options.body);
118
+ }
119
+ return {
120
+ method: options.method,
121
+ headers,
122
+ body,
123
+ signal: AbortSignal.timeout(this.timeout)
124
+ };
125
+ }
126
+ };
127
+ function unwrap(payload) {
128
+ if (typeof payload === "object" && payload !== null && "objects" in payload) return payload.objects;
129
+ return payload;
130
+ }
131
+ async function parseErrorBody(response) {
132
+ const text = await response.text();
133
+ try {
134
+ return JSON.parse(text);
135
+ } catch {
136
+ return text;
137
+ }
138
+ }
139
+ function backoffDelay(attempt) {
140
+ const ceiling = Math.min(RETRY_MAX_DELAY, RETRY_BASE_DELAY * 2 ** attempt);
141
+ return ceiling / 2 + Math.random() * (ceiling / 2);
142
+ }
143
+ function retryAfterDelay(header) {
144
+ if (!header) return;
145
+ const seconds = Number(header);
146
+ const milliseconds = Number.isFinite(seconds) ? seconds * 1e3 : new Date(header).getTime() - Date.now();
147
+ if (!Number.isFinite(milliseconds) || milliseconds < 0) return;
148
+ return Math.min(milliseconds, RETRY_AFTER_MAX_DELAY);
149
+ }
150
+ function delay(milliseconds) {
151
+ return new Promise((resolve) => setTimeout(resolve, milliseconds));
152
+ }
153
+ //#endregion
154
+ //#region src/resources/base.ts
155
+ var BaseResource = class {
156
+ http;
157
+ constructor(http) {
158
+ this.http = http;
159
+ }
160
+ };
161
+ //#endregion
162
+ //#region src/resources/basics.ts
163
+ var BasicsResource = class extends BaseResource {
164
+ /** Retrieves the bookkeeping system version via `GET /Tools/bookkeepingSystemVersion`. */
165
+ async getBookkeepingSystemVersion() {
166
+ return (await this.http.request({
167
+ method: "GET",
168
+ path: "/Tools/bookkeepingSystemVersion"
169
+ })).version;
170
+ }
171
+ };
172
+ //#endregion
173
+ //#region src/dates.ts
174
+ /**
175
+ * Serializes a date for voucher endpoints, which accept a Unix timestamp
176
+ * or a `dd.mm.yyyy` string.
177
+ */
178
+ function toVoucherDate(value) {
179
+ if (value instanceof Date) return Math.floor(value.getTime() / 1e3);
180
+ return value;
181
+ }
182
+ /** Serializes a date as ISO 8601, as expected by transaction endpoints. */
183
+ function toIsoDateTime(value) {
184
+ if (value instanceof Date) return value.toISOString();
185
+ if (typeof value === "number") return (/* @__PURE__ */ new Date(value * 1e3)).toISOString();
186
+ return value;
187
+ }
188
+ /** Serializes a date as `YYYY-MM-DD`. */
189
+ function toPlainDate(value) {
190
+ if (value instanceof Date) return value.toISOString().slice(0, 10);
191
+ if (typeof value === "number") return (/* @__PURE__ */ new Date(value * 1e3)).toISOString().slice(0, 10);
192
+ return value;
193
+ }
194
+ //#endregion
195
+ //#region src/resources/check-accounts.ts
196
+ var CheckAccountsResource = class extends BaseResource {
197
+ /** Retrieves all check accounts via `GET /CheckAccount`. */
198
+ async list(options = {}) {
199
+ return this.http.request({
200
+ method: "GET",
201
+ path: "/CheckAccount",
202
+ query: {
203
+ limit: options.limit,
204
+ offset: options.offset
205
+ }
206
+ });
207
+ }
208
+ /** Retrieves a single check account via `GET /CheckAccount/{checkAccountId}`. */
209
+ async get(options) {
210
+ const checkAccount = (await this.http.request({
211
+ method: "GET",
212
+ path: `/CheckAccount/${options.checkAccountId}`
213
+ }))[0];
214
+ if (!checkAccount) throw new SevDeskError({
215
+ status: 404,
216
+ statusText: "Not Found",
217
+ body: null
218
+ });
219
+ return checkAccount;
220
+ }
221
+ /** Creates a file import account via `POST /CheckAccount/Factory/fileImportAccount`. */
222
+ async createFileImportAccount(options) {
223
+ return this.http.request({
224
+ method: "POST",
225
+ path: "/CheckAccount/Factory/fileImportAccount",
226
+ body: options
227
+ });
228
+ }
229
+ /** Creates a clearing account via `POST /CheckAccount/Factory/clearingAccount`. */
230
+ async createClearingAccount(options) {
231
+ return this.http.request({
232
+ method: "POST",
233
+ path: "/CheckAccount/Factory/clearingAccount",
234
+ body: options
235
+ });
236
+ }
237
+ /** Updates a check account via `PUT /CheckAccount/{checkAccountId}`. */
238
+ async update(options) {
239
+ const { checkAccountId, ...body } = options;
240
+ return this.http.request({
241
+ method: "PUT",
242
+ path: `/CheckAccount/${checkAccountId}`,
243
+ body
244
+ });
245
+ }
246
+ /** Deletes a check account via `DELETE /CheckAccount/{checkAccountId}`. */
247
+ async delete(options) {
248
+ await this.http.request({
249
+ method: "DELETE",
250
+ path: `/CheckAccount/${options.checkAccountId}`
251
+ });
252
+ }
253
+ /**
254
+ * Retrieves the balance at a date via `GET /CheckAccount/{checkAccountId}/getBalanceAtDate`.
255
+ *
256
+ * The balance is the sum of all transactions sevdesk knows up to and
257
+ * including the given date. It does not have to match the actual bank
258
+ * account balance, e.g. if old transactions were never imported.
259
+ */
260
+ async getBalanceAtDate(options) {
261
+ return this.http.request({
262
+ method: "GET",
263
+ path: `/CheckAccount/${options.checkAccountId}/getBalanceAtDate`,
264
+ query: { date: toPlainDate(options.date) }
265
+ });
266
+ }
267
+ };
268
+ //#endregion
269
+ //#region src/resources/contacts.ts
270
+ var ContactsResource = class extends BaseResource {
271
+ /** Retrieves contacts via `GET /Contact`. */
272
+ list(options = {}) {
273
+ const { depth, customerNumber, name, categoryId, parentId, limit, offset, embed } = options;
274
+ return this.http.request({
275
+ method: "GET",
276
+ path: "/Contact",
277
+ query: {
278
+ depth,
279
+ customerNumber,
280
+ name,
281
+ "category[id]": categoryId,
282
+ "category[objectName]": categoryId === void 0 ? void 0 : "Category",
283
+ "parent[id]": parentId,
284
+ "parent[objectName]": parentId === void 0 ? void 0 : "Contact",
285
+ limit,
286
+ offset,
287
+ embed
288
+ }
289
+ });
290
+ }
291
+ /** Retrieves a single contact via `GET /Contact/{contactId}`. */
292
+ async get(options) {
293
+ const contact = (await this.http.request({
294
+ method: "GET",
295
+ path: `/Contact/${options.contactId}`
296
+ }))[0];
297
+ if (!contact) throw new SevDeskError({
298
+ status: 404,
299
+ statusText: "Not Found",
300
+ body: null
301
+ });
302
+ return contact;
303
+ }
304
+ /** Creates a contact via `POST /Contact`. */
305
+ create(options) {
306
+ return this.http.request({
307
+ method: "POST",
308
+ path: "/Contact",
309
+ body: toContactBody(options)
310
+ });
311
+ }
312
+ /** Updates a contact via `PUT /Contact/{contactId}`. */
313
+ update(options) {
314
+ const { contactId, ...fields } = options;
315
+ return this.http.request({
316
+ method: "PUT",
317
+ path: `/Contact/${contactId}`,
318
+ body: toContactBody(fields)
319
+ });
320
+ }
321
+ /** Deletes a contact via `DELETE /Contact/{contactId}`. */
322
+ async delete(options) {
323
+ await this.http.request({
324
+ method: "DELETE",
325
+ path: `/Contact/${options.contactId}`
326
+ });
327
+ }
328
+ /** Retrieves the next free customer number via `GET /Contact/Factory/getNextCustomerNumber`. */
329
+ getNextCustomerNumber() {
330
+ return this.http.request({
331
+ method: "GET",
332
+ path: "/Contact/Factory/getNextCustomerNumber"
333
+ });
334
+ }
335
+ /** Retrieves contacts by a custom field value via `GET /Contact/Factory/findContactsByCustomFieldValue`. */
336
+ findByCustomFieldValue(options) {
337
+ const { value, customFieldName, customFieldSettingId } = options;
338
+ return this.http.request({
339
+ method: "GET",
340
+ path: "/Contact/Factory/findContactsByCustomFieldValue",
341
+ query: {
342
+ value,
343
+ customFieldName,
344
+ "customFieldSetting[id]": customFieldSettingId,
345
+ "customFieldSetting[objectName]": customFieldSettingId === void 0 ? void 0 : "ContactCustomFieldSetting"
346
+ }
347
+ });
348
+ }
349
+ /** Checks if a customer number is still free via `GET /Contact/Mapper/checkCustomerNumberAvailability`. */
350
+ checkCustomerNumberAvailability(options) {
351
+ return this.http.request({
352
+ method: "GET",
353
+ path: "/Contact/Mapper/checkCustomerNumberAvailability",
354
+ query: { customerNumber: options.customerNumber }
355
+ });
356
+ }
357
+ /** Retrieves the document counts of a contact via `GET /Contact/{contactId}/getTabsItemCount`. */
358
+ getTabsItemCount(options) {
359
+ return this.http.request({
360
+ method: "GET",
361
+ path: `/Contact/${options.contactId}/getTabsItemCount`
362
+ });
363
+ }
364
+ };
365
+ function toContactBody(fields) {
366
+ return {
367
+ objectName: "Contact",
368
+ mapAll: true,
369
+ category: toRef$6(fields.categoryId, "Category"),
370
+ parent: toRef$6(fields.parentId, "Contact"),
371
+ name: fields.name,
372
+ surename: fields.surename,
373
+ familyname: fields.familyname,
374
+ name2: fields.name2,
375
+ titel: fields.titel,
376
+ academicTitle: fields.academicTitle,
377
+ gender: fields.gender,
378
+ customerNumber: fields.customerNumber,
379
+ status: fields.status,
380
+ description: fields.description,
381
+ vatNumber: fields.vatNumber,
382
+ taxNumber: fields.taxNumber,
383
+ exemptVat: fields.exemptVat,
384
+ bankAccount: fields.bankAccount,
385
+ bankNumber: fields.bankNumber,
386
+ defaultTimeToPay: fields.defaultTimeToPay,
387
+ buyerReference: fields.buyerReference,
388
+ governmentAgency: fields.governmentAgency
389
+ };
390
+ }
391
+ function toRef$6(id, objectName) {
392
+ return id === void 0 ? void 0 : {
393
+ id,
394
+ objectName
395
+ };
396
+ }
397
+ //#endregion
398
+ //#region src/resources/credit-notes.ts
399
+ var CreditNotesResource = class extends BaseResource {
400
+ /** Retrieves credit notes via `GET /CreditNote`. */
401
+ list(options = {}) {
402
+ const { status, creditNoteNumber, startDate, endDate, contactId, limit, offset, embed } = options;
403
+ return this.http.request({
404
+ method: "GET",
405
+ path: "/CreditNote",
406
+ query: {
407
+ status,
408
+ creditNoteNumber,
409
+ startDate: toOptionalDate$1(startDate),
410
+ endDate: toOptionalDate$1(endDate),
411
+ "contact[id]": contactId,
412
+ "contact[objectName]": contactId === void 0 ? void 0 : "Contact",
413
+ limit,
414
+ offset,
415
+ embed
416
+ }
417
+ });
418
+ }
419
+ /** Retrieves a single credit note via `GET /CreditNote/{creditNoteId}`. */
420
+ async get(options) {
421
+ const creditNote = (await this.http.request({
422
+ method: "GET",
423
+ path: `/CreditNote/${options.creditNoteId}`
424
+ }))[0];
425
+ if (!creditNote) throw new SevDeskError({
426
+ status: 404,
427
+ statusText: "Not Found",
428
+ body: null
429
+ });
430
+ return creditNote;
431
+ }
432
+ /** Creates or updates a credit note with its positions via `POST /CreditNote/Factory/saveCreditNote`. */
433
+ async save(options) {
434
+ const { creditNote, positions } = options;
435
+ const result = await this.http.request({
436
+ method: "POST",
437
+ path: "/CreditNote/Factory/saveCreditNote",
438
+ body: {
439
+ creditNote: toCreditNoteBody(creditNote),
440
+ creditNotePosSave: positions.map(toCreditNotePositionBody),
441
+ creditNotePosDelete: null,
442
+ discountSave: null,
443
+ discountDelete: null
444
+ }
445
+ });
446
+ return {
447
+ creditNote: result.creditNote,
448
+ positions: result.creditNotePos
449
+ };
450
+ }
451
+ /** Creates a credit note from an invoice via `POST /CreditNote/Factory/createFromInvoice`. */
452
+ async createFromInvoice(options) {
453
+ const result = await this.http.request({
454
+ method: "POST",
455
+ path: "/CreditNote/Factory/createFromInvoice",
456
+ body: { invoice: {
457
+ id: options.invoiceId,
458
+ objectName: "Invoice"
459
+ } }
460
+ });
461
+ return {
462
+ creditNote: result.creditNote,
463
+ positions: result.creditNotePos,
464
+ discounts: result.discount
465
+ };
466
+ }
467
+ /** Updates a credit note via `PUT /CreditNote/{creditNoteId}`. */
468
+ update(options) {
469
+ const { creditNoteId, creditNoteDate, deliveryDate, ...rest } = options;
470
+ return this.http.request({
471
+ method: "PUT",
472
+ path: `/CreditNote/${creditNoteId}`,
473
+ body: {
474
+ ...rest,
475
+ creditNoteDate: toOptionalDate$1(creditNoteDate),
476
+ deliveryDate: toOptionalDate$1(deliveryDate)
477
+ }
478
+ });
479
+ }
480
+ /** Deletes a credit note via `DELETE /CreditNote/{creditNoteId}`. */
481
+ async delete(options) {
482
+ await this.http.request({
483
+ method: "DELETE",
484
+ path: `/CreditNote/${options.creditNoteId}`
485
+ });
486
+ }
487
+ /** Sends a credit note via email using `POST /CreditNote/{creditNoteId}/sendViaEmail`. */
488
+ sendViaEmail(options) {
489
+ const { creditNoteId, ...body } = options;
490
+ return this.http.request({
491
+ method: "POST",
492
+ path: `/CreditNote/${creditNoteId}/sendViaEmail`,
493
+ body
494
+ });
495
+ }
496
+ /** Retrieves the pdf of a credit note via `GET /CreditNote/{creditNoteId}/getPdf`. */
497
+ getPdf(options) {
498
+ return this.http.request({
499
+ method: "GET",
500
+ path: `/CreditNote/${options.creditNoteId}/getPdf`,
501
+ query: { preventSendBy: options.preventSendBy }
502
+ });
503
+ }
504
+ /** Marks a credit note as sent via `PUT /CreditNote/{creditNoteId}/sendBy`. */
505
+ sendBy(options) {
506
+ const { creditNoteId, sendType, sendDraft } = options;
507
+ return this.http.request({
508
+ method: "PUT",
509
+ path: `/CreditNote/${creditNoteId}/sendBy`,
510
+ body: {
511
+ sendType,
512
+ sendDraft
513
+ }
514
+ });
515
+ }
516
+ /** Books an amount on a credit note via `PUT /CreditNote/{creditNoteId}/bookAmount`. */
517
+ book(options) {
518
+ const { creditNoteId, amount, date, type, checkAccountId, checkAccountTransactionId, createFeed } = options;
519
+ return this.http.request({
520
+ method: "PUT",
521
+ path: `/CreditNote/${creditNoteId}/bookAmount`,
522
+ body: {
523
+ amount,
524
+ date: toIsoDateTime(date),
525
+ type,
526
+ checkAccount: {
527
+ id: checkAccountId,
528
+ objectName: "CheckAccount"
529
+ },
530
+ checkAccountTransaction: toRef$5(checkAccountTransactionId, "CheckAccountTransaction"),
531
+ createFeed
532
+ }
533
+ });
534
+ }
535
+ /** Enshrines a credit note via `PUT /CreditNote/{creditNoteId}/enshrine`. This cannot be undone. */
536
+ async enshrine(options) {
537
+ await this.http.request({
538
+ method: "PUT",
539
+ path: `/CreditNote/${options.creditNoteId}/enshrine`
540
+ });
541
+ }
542
+ /** Resets the credit note status to open via `PUT /CreditNote/{creditNoteId}/resetToOpen`. */
543
+ resetToOpen(options) {
544
+ return this.http.request({
545
+ method: "PUT",
546
+ path: `/CreditNote/${options.creditNoteId}/resetToOpen`
547
+ });
548
+ }
549
+ /** Resets the credit note status to draft via `PUT /CreditNote/{creditNoteId}/resetToDraft`. */
550
+ resetToDraft(options) {
551
+ return this.http.request({
552
+ method: "PUT",
553
+ path: `/CreditNote/${options.creditNoteId}/resetToDraft`
554
+ });
555
+ }
556
+ /** Retrieves credit note positions via `GET /CreditNotePos`. */
557
+ listPositions(options = {}) {
558
+ const { creditNoteId, limit, offset, embed } = options;
559
+ return this.http.request({
560
+ method: "GET",
561
+ path: "/CreditNotePos",
562
+ query: {
563
+ "creditNote[id]": creditNoteId,
564
+ "creditNote[objectName]": creditNoteId === void 0 ? void 0 : "CreditNote",
565
+ limit,
566
+ offset,
567
+ embed
568
+ }
569
+ });
570
+ }
571
+ };
572
+ function toCreditNoteBody(creditNote) {
573
+ return {
574
+ objectName: "CreditNote",
575
+ mapAll: true,
576
+ creditNoteNumber: creditNote.creditNoteNumber,
577
+ creditNoteDate: toVoucherDate(creditNote.creditNoteDate),
578
+ contact: {
579
+ id: creditNote.contactId,
580
+ objectName: "Contact"
581
+ },
582
+ status: creditNote.status,
583
+ header: creditNote.header,
584
+ bookingCategory: creditNote.bookingCategory,
585
+ contactPerson: {
586
+ id: creditNote.contactPersonId,
587
+ objectName: "SevUser"
588
+ },
589
+ taxRule: {
590
+ id: creditNote.taxRuleId,
591
+ objectName: "TaxRule"
592
+ },
593
+ taxRate: creditNote.taxRate,
594
+ taxText: creditNote.taxText,
595
+ currency: creditNote.currency,
596
+ deliveryDate: toVoucherDate(creditNote.deliveryDate),
597
+ addressCountry: toRef$5(creditNote.addressCountryId, "StaticCountry"),
598
+ headText: creditNote.headText,
599
+ footText: creditNote.footText,
600
+ address: creditNote.address,
601
+ smallSettlement: creditNote.smallSettlement,
602
+ showNet: creditNote.showNet,
603
+ customerInternalNote: creditNote.customerInternalNote,
604
+ sendDate: toOptionalDate$1(creditNote.sendDate),
605
+ sendType: creditNote.sendType
606
+ };
607
+ }
608
+ function toCreditNotePositionBody(position) {
609
+ return {
610
+ objectName: "CreditNotePos",
611
+ mapAll: true,
612
+ unity: {
613
+ id: position.unityId,
614
+ objectName: "Unity"
615
+ },
616
+ quantity: position.quantity,
617
+ taxRate: position.taxRate,
618
+ name: position.name,
619
+ price: position.price,
620
+ text: position.text,
621
+ part: toRef$5(position.partId, "Part"),
622
+ positionNumber: position.positionNumber,
623
+ discount: position.discount,
624
+ optional: position.optional
625
+ };
626
+ }
627
+ function toRef$5(id, objectName) {
628
+ return id === void 0 ? void 0 : {
629
+ id,
630
+ objectName
631
+ };
632
+ }
633
+ function toOptionalDate$1(value) {
634
+ return value === void 0 ? void 0 : toVoucherDate(value);
635
+ }
636
+ //#endregion
637
+ //#region src/resources/exports.ts
638
+ var ExportsResource = class extends BaseResource {
639
+ /**
640
+ * Updates the export config via `PUT /SevClient/{sevClientId}/updateExportConfig`.
641
+ *
642
+ * The accounting year has to be set once before any DATEV export can be run.
643
+ */
644
+ async updateExportConfig(options) {
645
+ const { sevClientId, accountantNumber, accountantClientNumber, accountingYearBegin } = options;
646
+ await this.http.request({
647
+ method: "PUT",
648
+ path: `/SevClient/${sevClientId}/updateExportConfig`,
649
+ body: {
650
+ accountantNumber,
651
+ accountantClientNumber,
652
+ accountingYearBegin: toVoucherDate(accountingYearBegin)
653
+ }
654
+ });
655
+ }
656
+ /** Starts a DATEV CSV zip export via `GET /Export/createDatevCsvZipExportJob` and returns the job id. */
657
+ createDatevCsvZipExportJob(options) {
658
+ const { startDate, endDate, ...rest } = options;
659
+ return this.http.request({
660
+ method: "GET",
661
+ path: "/Export/createDatevCsvZipExportJob",
662
+ query: {
663
+ startDate: toVoucherDate(startDate),
664
+ endDate: toVoucherDate(endDate),
665
+ ...rest
666
+ }
667
+ });
668
+ }
669
+ /** Starts a DATEV XML zip export via `GET /Export/createDatevXmlZipExportJob` and returns the job id. */
670
+ createDatevXmlZipExportJob(options) {
671
+ const { startDate, endDate, ...rest } = options;
672
+ return this.http.request({
673
+ method: "GET",
674
+ path: "/Export/createDatevXmlZipExportJob",
675
+ query: {
676
+ startDate: toVoucherDate(startDate),
677
+ endDate: toVoucherDate(endDate),
678
+ ...rest
679
+ }
680
+ });
681
+ }
682
+ /** Generates the hash of an export job via `GET /Progress/generateDownloadHash`. */
683
+ generateDownloadHash(options) {
684
+ return this.http.request({
685
+ method: "GET",
686
+ path: "/Progress/generateDownloadHash",
687
+ query: { jobId: options.jobId }
688
+ });
689
+ }
690
+ /** Retrieves the progress of an export via `GET /Progress/getProgress`. */
691
+ getProgress(options) {
692
+ return this.http.request({
693
+ method: "GET",
694
+ path: "/Progress/getProgress",
695
+ query: { hash: options.hash }
696
+ });
697
+ }
698
+ /** Retrieves the download url of a finished export job via `GET /ExportJob/jobDownloadInfo`. */
699
+ getJobDownloadInfo(options) {
700
+ return this.http.request({
701
+ method: "GET",
702
+ path: "/ExportJob/jobDownloadInfo",
703
+ query: { jobId: options.jobId }
704
+ });
705
+ }
706
+ /** Exports invoices as CSV via `GET /Export/invoiceCsv`. */
707
+ exportInvoicesCsv(options = {}) {
708
+ return this.requestExport("/Export/invoiceCsv", options, {
709
+ modelName: "Invoice",
710
+ limit: options.limit,
711
+ filter: toExportInvoiceFilter(options.filter)
712
+ });
713
+ }
714
+ /** Exports invoices as zip via `GET /Export/invoiceZip`. */
715
+ exportInvoicesZip(options = {}) {
716
+ return this.requestExport("/Export/invoiceZip", options, {
717
+ modelName: "Invoice",
718
+ limit: options.limit,
719
+ filter: toExportInvoiceFilter(options.filter)
720
+ });
721
+ }
722
+ /** Exports credit notes as CSV via `GET /Export/creditNoteCsv`. */
723
+ exportCreditNotesCsv(options = {}) {
724
+ return this.requestExport("/Export/creditNoteCsv", options, {
725
+ modelName: "CreditNote",
726
+ limit: options.limit,
727
+ filter: toExportDocumentFilter(options.filter)
728
+ });
729
+ }
730
+ /** Exports vouchers as CSV via `GET /Export/voucherListCsv`. */
731
+ exportVouchersCsv(options = {}) {
732
+ return this.requestExport("/Export/voucherListCsv", options, {
733
+ modelName: "Voucher",
734
+ limit: options.limit,
735
+ filter: toExportVoucherFilter(options.filter)
736
+ });
737
+ }
738
+ /** Exports vouchers as zip via `GET /Export/voucherZip`. */
739
+ exportVouchersZip(options = {}) {
740
+ return this.requestExport("/Export/voucherZip", options, {
741
+ modelName: "Voucher",
742
+ limit: options.limit,
743
+ filter: toExportVoucherFilter(options.filter)
744
+ });
745
+ }
746
+ /** Exports transactions as CSV via `GET /Export/transactionsCsv`. */
747
+ exportTransactionsCsv(options = {}) {
748
+ return this.requestExport("/Export/transactionsCsv", options, {
749
+ modelName: "CheckAccountTransaction",
750
+ limit: options.limit,
751
+ filter: toExportTransactionFilter(options.filter)
752
+ });
753
+ }
754
+ /** Exports contacts as CSV via `GET /Export/contactListCsv`. */
755
+ exportContactsCsv(options = {}) {
756
+ return this.requestExport("/Export/contactListCsv", options, {
757
+ modelName: "Contact",
758
+ limit: options.limit,
759
+ filter: toExportContactFilter(options.filter)
760
+ });
761
+ }
762
+ requestExport(path, options, sevQuery) {
763
+ return this.http.request({
764
+ method: "GET",
765
+ path,
766
+ query: {
767
+ download: options.download,
768
+ ...toExportSevQueryParams(sevQuery)
769
+ }
770
+ });
771
+ }
772
+ };
773
+ /**
774
+ * Flattens a `sevQuery` object into the deep bracket query parameters expected
775
+ * by the export and report endpoints, e.g. `sevQuery[filter][startDate]`.
776
+ */
777
+ function toExportSevQueryParams(sevQuery) {
778
+ const query = {};
779
+ flattenSevQueryValue("sevQuery", {
780
+ objectName: "SevQuery",
781
+ ...sevQuery
782
+ }, query);
783
+ return query;
784
+ }
785
+ /** Maps a document export filter to its `sevQuery` representation. */
786
+ function toExportDocumentFilter(filter = {}) {
787
+ return {
788
+ startDate: toOptionalIsoDateTime$1(filter.startDate),
789
+ endDate: toOptionalIsoDateTime$1(filter.endDate),
790
+ contact: toRef$4(filter.contactId, "Contact"),
791
+ startAmount: filter.startAmount,
792
+ endAmount: filter.endAmount
793
+ };
794
+ }
795
+ /** Maps an invoice export filter to its `sevQuery` representation. */
796
+ function toExportInvoiceFilter(filter = {}) {
797
+ return {
798
+ ...toExportDocumentFilter(filter),
799
+ invoiceType: filter.invoiceType
800
+ };
801
+ }
802
+ /** Maps a voucher export filter to its `sevQuery` representation. */
803
+ function toExportVoucherFilter(filter = {}) {
804
+ return {
805
+ ...toExportDocumentFilter(filter),
806
+ startPayDate: toOptionalIsoDateTime$1(filter.startPayDate),
807
+ endPayDate: toOptionalIsoDateTime$1(filter.endPayDate)
808
+ };
809
+ }
810
+ /** Maps a contact export filter to its `sevQuery` representation. */
811
+ function toExportContactFilter(filter = {}) {
812
+ return {
813
+ zip: filter.zip,
814
+ city: filter.city,
815
+ country: toRef$4(filter.countryId, "StaticCountry"),
816
+ depth: filter.depth,
817
+ onlyPeople: filter.onlyPeople
818
+ };
819
+ }
820
+ function toExportTransactionFilter(filter = {}) {
821
+ return {
822
+ paymtPurpose: filter.paymtPurpose,
823
+ name: filter.name,
824
+ startDate: toOptionalIsoDateTime$1(filter.startDate),
825
+ endDate: toOptionalIsoDateTime$1(filter.endDate),
826
+ startAmount: filter.startAmount,
827
+ endAmount: filter.endAmount,
828
+ checkAccount: toRef$4(filter.checkAccountId, "CheckAccount")
829
+ };
830
+ }
831
+ function flattenSevQueryValue(key, value, query) {
832
+ if (Array.isArray(value)) {
833
+ value.forEach((item, index) => flattenSevQueryValue(`${key}[${index}]`, item, query));
834
+ return;
835
+ }
836
+ if (typeof value === "object") {
837
+ for (const [nestedKey, nestedValue] of Object.entries(value)) if (nestedValue !== void 0) flattenSevQueryValue(`${key}[${nestedKey}]`, nestedValue, query);
838
+ return;
839
+ }
840
+ query[key] = value;
841
+ }
842
+ function toRef$4(id, objectName) {
843
+ return id === void 0 ? void 0 : {
844
+ id,
845
+ objectName
846
+ };
847
+ }
848
+ function toOptionalIsoDateTime$1(value) {
849
+ return value === void 0 ? void 0 : toIsoDateTime(value);
850
+ }
851
+ //#endregion
852
+ //#region src/resources/invoices.ts
853
+ var InvoicesResource = class extends BaseResource {
854
+ /** Retrieves invoices via `GET /Invoice`. */
855
+ list(options = {}) {
856
+ const { status, invoiceNumber, startDate, endDate, contactId, limit, offset, embed } = options;
857
+ return this.http.request({
858
+ method: "GET",
859
+ path: "/Invoice",
860
+ query: {
861
+ status,
862
+ invoiceNumber,
863
+ startDate: toOptionalInvoiceDate(startDate),
864
+ endDate: toOptionalInvoiceDate(endDate),
865
+ "contact[id]": contactId,
866
+ "contact[objectName]": contactId === void 0 ? void 0 : "Contact",
867
+ limit,
868
+ offset,
869
+ embed
870
+ }
871
+ });
872
+ }
873
+ /** Retrieves a single invoice via `GET /Invoice/{invoiceId}`. */
874
+ async get(options) {
875
+ const invoice = (await this.http.request({
876
+ method: "GET",
877
+ path: `/Invoice/${options.invoiceId}`
878
+ }))[0];
879
+ if (!invoice) throw new SevDeskError({
880
+ status: 404,
881
+ statusText: "Not Found",
882
+ body: null
883
+ });
884
+ return invoice;
885
+ }
886
+ /**
887
+ * Creates or updates an invoice with its positions via
888
+ * `POST /Invoice/Factory/saveInvoice`.
889
+ *
890
+ * Invoices can only be created as drafts. Use `sendViaEmail`, `sendBy` and
891
+ * `book` to advance the status afterwards.
892
+ */
893
+ async save(options) {
894
+ const { invoice, positions, takeDefaultAddress } = options;
895
+ const result = await this.http.request({
896
+ method: "POST",
897
+ path: "/Invoice/Factory/saveInvoice",
898
+ body: {
899
+ invoice: toInvoiceBody(invoice),
900
+ invoicePosSave: positions.map(toInvoicePositionBody),
901
+ invoicePosDelete: null,
902
+ discountSave: null,
903
+ discountDelete: null,
904
+ ...takeDefaultAddress === void 0 ? {} : { takeDefaultAddress }
905
+ }
906
+ });
907
+ return {
908
+ invoice: result.invoice,
909
+ positions: result.invoicePos
910
+ };
911
+ }
912
+ /** Creates an invoice from an order via `POST /Invoice/Factory/createInvoiceFromOrder`. */
913
+ createFromOrder(options) {
914
+ const { orderId, type, amount, partialType } = options;
915
+ return this.http.request({
916
+ method: "POST",
917
+ path: "/Invoice/Factory/createInvoiceFromOrder",
918
+ body: {
919
+ order: {
920
+ id: orderId,
921
+ objectName: "Order"
922
+ },
923
+ type,
924
+ amount,
925
+ partialType
926
+ }
927
+ });
928
+ }
929
+ /** Creates a reminder for an invoice via `POST /Invoice/Factory/createInvoiceReminder`. */
930
+ createReminder(options) {
931
+ return this.http.request({
932
+ method: "POST",
933
+ path: "/Invoice/Factory/createInvoiceReminder",
934
+ body: { invoice: {
935
+ id: options.invoiceId,
936
+ objectName: "Invoice"
937
+ } }
938
+ });
939
+ }
940
+ /** Retrieves the positions of an invoice via `GET /Invoice/{invoiceId}/getPositions`. */
941
+ getPositions(options) {
942
+ const { invoiceId, limit, offset, embed } = options;
943
+ return this.http.request({
944
+ method: "GET",
945
+ path: `/Invoice/${invoiceId}/getPositions`,
946
+ query: {
947
+ limit,
948
+ offset,
949
+ embed
950
+ }
951
+ });
952
+ }
953
+ /**
954
+ * Checks if an invoice is partially paid via
955
+ * `GET /Invoice/{invoiceId}/getIsPartiallyPaid`.
956
+ *
957
+ * Fully paid invoices are regarded as not partially paid.
958
+ */
959
+ isPartiallyPaid(options) {
960
+ return this.http.request({
961
+ method: "GET",
962
+ path: `/Invoice/${options.invoiceId}/getIsPartiallyPaid`
963
+ });
964
+ }
965
+ /**
966
+ * Cancels an invoice via `POST /Invoice/{invoiceId}/cancelInvoice` and
967
+ * returns the created cancellation invoice.
968
+ */
969
+ cancel(options) {
970
+ return this.http.request({
971
+ method: "POST",
972
+ path: `/Invoice/${options.invoiceId}/cancelInvoice`
973
+ });
974
+ }
975
+ /** Renders the pdf document of an invoice via `POST /Invoice/{invoiceId}/render`. */
976
+ render(options) {
977
+ return this.http.request({
978
+ method: "POST",
979
+ path: `/Invoice/${options.invoiceId}/render`,
980
+ body: { forceReload: options.forceReload }
981
+ });
982
+ }
983
+ /**
984
+ * Sends an invoice to the end-customer via
985
+ * `POST /Invoice/{invoiceId}/sendViaEmail`. This marks the invoice as sent.
986
+ */
987
+ sendViaEmail(options) {
988
+ const { invoiceId, ...body } = options;
989
+ return this.http.request({
990
+ method: "POST",
991
+ path: `/Invoice/${invoiceId}/sendViaEmail`,
992
+ body
993
+ });
994
+ }
995
+ /** Retrieves the pdf document of an invoice via `GET /Invoice/{invoiceId}/getPdf`. */
996
+ getPdf(options) {
997
+ return this.http.request({
998
+ method: "GET",
999
+ path: `/Invoice/${options.invoiceId}/getPdf`,
1000
+ query: { preventSendBy: options.preventSendBy }
1001
+ });
1002
+ }
1003
+ /** Retrieves the xml of an e-invoice via `GET /Invoice/{invoiceId}/getXml`. */
1004
+ getXml(options) {
1005
+ return this.http.request({
1006
+ method: "GET",
1007
+ path: `/Invoice/${options.invoiceId}/getXml`
1008
+ });
1009
+ }
1010
+ /** Marks an invoice as sent via `PUT /Invoice/{invoiceId}/sendBy`. */
1011
+ sendBy(options) {
1012
+ const { invoiceId, sendType, sendDraft } = options;
1013
+ return this.http.request({
1014
+ method: "PUT",
1015
+ path: `/Invoice/${invoiceId}/sendBy`,
1016
+ body: {
1017
+ sendType,
1018
+ sendDraft
1019
+ }
1020
+ });
1021
+ }
1022
+ /** Books an amount on an invoice via `PUT /Invoice/{invoiceId}/bookAmount`. */
1023
+ book(options) {
1024
+ const { invoiceId, amount, date, type, checkAccountId, checkAccountTransactionId, createFeed } = options;
1025
+ return this.http.request({
1026
+ method: "PUT",
1027
+ path: `/Invoice/${invoiceId}/bookAmount`,
1028
+ body: {
1029
+ amount,
1030
+ date: toIsoDateTime(date),
1031
+ type,
1032
+ checkAccount: {
1033
+ id: checkAccountId,
1034
+ objectName: "CheckAccount"
1035
+ },
1036
+ checkAccountTransaction: toRef$3(checkAccountTransactionId, "CheckAccountTransaction"),
1037
+ createFeed
1038
+ }
1039
+ });
1040
+ }
1041
+ /**
1042
+ * Enshrines an invoice via `PUT /Invoice/{invoiceId}/enshrine`.
1043
+ *
1044
+ * Requires a status of at least `200` and cannot be undone.
1045
+ */
1046
+ async enshrine(options) {
1047
+ await this.http.request({
1048
+ method: "PUT",
1049
+ path: `/Invoice/${options.invoiceId}/enshrine`
1050
+ });
1051
+ }
1052
+ /**
1053
+ * Resets the invoice status to open via `PUT /Invoice/{invoiceId}/resetToOpen`.
1054
+ *
1055
+ * Linked transactions are unlinked. Not possible for enshrined invoices.
1056
+ */
1057
+ resetToOpen(options) {
1058
+ return this.http.request({
1059
+ method: "PUT",
1060
+ path: `/Invoice/${options.invoiceId}/resetToOpen`
1061
+ });
1062
+ }
1063
+ /**
1064
+ * Resets the invoice status to draft via `PUT /Invoice/{invoiceId}/resetToDraft`.
1065
+ *
1066
+ * Only possible for invoices with the status `200`.
1067
+ */
1068
+ resetToDraft(options) {
1069
+ return this.http.request({
1070
+ method: "PUT",
1071
+ path: `/Invoice/${options.invoiceId}/resetToDraft`
1072
+ });
1073
+ }
1074
+ };
1075
+ function toInvoiceBody(invoice) {
1076
+ return {
1077
+ objectName: "Invoice",
1078
+ mapAll: true,
1079
+ invoiceNumber: invoice.invoiceNumber,
1080
+ contact: {
1081
+ id: invoice.contactId,
1082
+ objectName: "Contact"
1083
+ },
1084
+ contactPerson: {
1085
+ id: invoice.contactPersonId,
1086
+ objectName: "SevUser"
1087
+ },
1088
+ invoiceDate: toVoucherDate(invoice.invoiceDate),
1089
+ header: invoice.header,
1090
+ headText: invoice.headText,
1091
+ footText: invoice.footText,
1092
+ timeToPay: invoice.timeToPay,
1093
+ discount: invoice.discount ?? 0,
1094
+ address: invoice.address,
1095
+ addressCountry: toRef$3(invoice.addressCountryId, "StaticCountry"),
1096
+ payDate: toOptionalInvoiceDate(invoice.payDate),
1097
+ deliveryDate: toOptionalInvoiceDate(invoice.deliveryDate),
1098
+ deliveryDateUntil: toOptionalInvoiceDate(invoice.deliveryDateUntil),
1099
+ status: invoice.status,
1100
+ smallSettlement: invoice.smallSettlement,
1101
+ taxRate: 0,
1102
+ taxRule: {
1103
+ id: invoice.taxRuleId,
1104
+ objectName: "TaxRule"
1105
+ },
1106
+ taxText: invoice.taxText,
1107
+ paymentMethod: toRef$3(invoice.paymentMethodId, "PaymentMethod"),
1108
+ invoiceType: invoice.invoiceType,
1109
+ currency: invoice.currency,
1110
+ showNet: invoice.showNet,
1111
+ customerInternalNote: invoice.customerInternalNote,
1112
+ propertyIsEInvoice: invoice.propertyIsEInvoice
1113
+ };
1114
+ }
1115
+ function toInvoicePositionBody(position) {
1116
+ return {
1117
+ objectName: "InvoicePos",
1118
+ mapAll: true,
1119
+ invoice: null,
1120
+ part: toRef$3(position.partId, "Part"),
1121
+ quantity: position.quantity,
1122
+ price: position.price,
1123
+ name: position.name,
1124
+ unity: {
1125
+ id: position.unityId,
1126
+ objectName: "Unity"
1127
+ },
1128
+ positionNumber: position.positionNumber,
1129
+ text: position.text,
1130
+ discount: position.discount,
1131
+ taxRate: position.taxRate
1132
+ };
1133
+ }
1134
+ function toRef$3(id, objectName) {
1135
+ return id === void 0 ? void 0 : {
1136
+ id,
1137
+ objectName
1138
+ };
1139
+ }
1140
+ function toOptionalInvoiceDate(value) {
1141
+ return value === void 0 ? void 0 : toVoucherDate(value);
1142
+ }
1143
+ //#endregion
1144
+ //#region src/resources/orders.ts
1145
+ var OrdersResource = class extends BaseResource {
1146
+ /** Retrieves orders via `GET /Order`. */
1147
+ list(options = {}) {
1148
+ const { status, orderNumber, startDate, endDate, contactId, limit, offset, embed } = options;
1149
+ return this.http.request({
1150
+ method: "GET",
1151
+ path: "/Order",
1152
+ query: {
1153
+ status,
1154
+ orderNumber,
1155
+ startDate: toOptionalDate(startDate),
1156
+ endDate: toOptionalDate(endDate),
1157
+ "contact[id]": contactId,
1158
+ "contact[objectName]": contactId === void 0 ? void 0 : "Contact",
1159
+ limit,
1160
+ offset,
1161
+ embed
1162
+ }
1163
+ });
1164
+ }
1165
+ /** Retrieves a single order via `GET /Order/{orderId}`. */
1166
+ async get(options) {
1167
+ const order = (await this.http.request({
1168
+ method: "GET",
1169
+ path: `/Order/${options.orderId}`
1170
+ }))[0];
1171
+ if (!order) throw new SevDeskError({
1172
+ status: 404,
1173
+ statusText: "Not Found",
1174
+ body: null
1175
+ });
1176
+ return order;
1177
+ }
1178
+ /** Creates or updates an order with its positions via `POST /Order/Factory/saveOrder`. */
1179
+ async save(options) {
1180
+ const { order, positions } = options;
1181
+ const result = await this.http.request({
1182
+ method: "POST",
1183
+ path: "/Order/Factory/saveOrder",
1184
+ body: {
1185
+ order: toOrderBody(order),
1186
+ orderPosSave: positions.map(toOrderPositionBody),
1187
+ orderPosDelete: null
1188
+ }
1189
+ });
1190
+ return {
1191
+ order: result.order,
1192
+ positions: result.orderPos
1193
+ };
1194
+ }
1195
+ /** Updates an order via `PUT /Order/{orderId}`. */
1196
+ update(options) {
1197
+ const { orderId, orderDate, ...rest } = options;
1198
+ return this.http.request({
1199
+ method: "PUT",
1200
+ path: `/Order/${orderId}`,
1201
+ body: {
1202
+ ...rest,
1203
+ orderDate: toOptionalDate(orderDate)
1204
+ }
1205
+ });
1206
+ }
1207
+ /** Deletes an order via `DELETE /Order/{orderId}`. */
1208
+ async delete(options) {
1209
+ await this.http.request({
1210
+ method: "DELETE",
1211
+ path: `/Order/${options.orderId}`
1212
+ });
1213
+ }
1214
+ /** Retrieves the positions of an order via `GET /Order/{orderId}/getPositions`. */
1215
+ getPositions(options) {
1216
+ const { orderId, limit, offset, embed } = options;
1217
+ return this.http.request({
1218
+ method: "GET",
1219
+ path: `/Order/${orderId}/getPositions`,
1220
+ query: {
1221
+ limit,
1222
+ offset,
1223
+ embed
1224
+ }
1225
+ });
1226
+ }
1227
+ /** Retrieves the discounts of an order via `GET /Order/{orderId}/getDiscounts`. */
1228
+ getDiscounts(options) {
1229
+ const { orderId, limit, offset, embed } = options;
1230
+ return this.http.request({
1231
+ method: "GET",
1232
+ path: `/Order/${orderId}/getDiscounts`,
1233
+ query: {
1234
+ limit,
1235
+ offset,
1236
+ embed
1237
+ }
1238
+ });
1239
+ }
1240
+ /** Retrieves the objects related to an order via `GET /Order/{orderId}/getRelatedObjects`. */
1241
+ getRelatedObjects(options) {
1242
+ const { orderId, includeItself, sortByType, embed } = options;
1243
+ return this.http.request({
1244
+ method: "GET",
1245
+ path: `/Order/${orderId}/getRelatedObjects`,
1246
+ query: {
1247
+ includeItself,
1248
+ sortByType,
1249
+ embed
1250
+ }
1251
+ });
1252
+ }
1253
+ /** Sends an order via email using `POST /Order/{orderId}/sendViaEmail`. */
1254
+ sendViaEmail(options) {
1255
+ const { orderId, ...body } = options;
1256
+ return this.http.request({
1257
+ method: "POST",
1258
+ path: `/Order/${orderId}/sendViaEmail`,
1259
+ body
1260
+ });
1261
+ }
1262
+ /** Creates a packing list from an order via `POST /Order/Factory/createPackingListFromOrder`. */
1263
+ createPackingList(options) {
1264
+ return this.http.request({
1265
+ method: "POST",
1266
+ path: "/Order/Factory/createPackingListFromOrder",
1267
+ query: {
1268
+ "order[id]": options.orderId,
1269
+ "order[objectName]": "Order"
1270
+ },
1271
+ body: {
1272
+ id: options.orderId,
1273
+ objectName: "Order"
1274
+ }
1275
+ });
1276
+ }
1277
+ /** Creates a contract note from an order via `POST /Order/Factory/createContractNoteFromOrder`. */
1278
+ createContractNote(options) {
1279
+ return this.http.request({
1280
+ method: "POST",
1281
+ path: "/Order/Factory/createContractNoteFromOrder",
1282
+ query: {
1283
+ "order[id]": options.orderId,
1284
+ "order[objectName]": "Order"
1285
+ },
1286
+ body: {
1287
+ id: options.orderId,
1288
+ objectName: "Order"
1289
+ }
1290
+ });
1291
+ }
1292
+ /** Retrieves the pdf of an order via `GET /Order/{orderId}/getPdf`. */
1293
+ getPdf(options) {
1294
+ return this.http.request({
1295
+ method: "GET",
1296
+ path: `/Order/${options.orderId}/getPdf`,
1297
+ query: { preventSendBy: options.preventSendBy }
1298
+ });
1299
+ }
1300
+ /** Marks an order as sent via `PUT /Order/{orderId}/sendBy`. */
1301
+ sendBy(options) {
1302
+ const { orderId, sendType, sendDraft } = options;
1303
+ return this.http.request({
1304
+ method: "PUT",
1305
+ path: `/Order/${orderId}/sendBy`,
1306
+ body: {
1307
+ sendType,
1308
+ sendDraft
1309
+ }
1310
+ });
1311
+ }
1312
+ /** Retrieves order positions via `GET /OrderPos`. */
1313
+ listPositions(options = {}) {
1314
+ const { orderId, limit, offset, embed } = options;
1315
+ return this.http.request({
1316
+ method: "GET",
1317
+ path: "/OrderPos",
1318
+ query: {
1319
+ "order[id]": orderId,
1320
+ "order[objectName]": orderId === void 0 ? void 0 : "Order",
1321
+ limit,
1322
+ offset,
1323
+ embed
1324
+ }
1325
+ });
1326
+ }
1327
+ /** Retrieves a single order position via `GET /OrderPos/{orderPosId}`. */
1328
+ async getPosition(options) {
1329
+ const position = (await this.http.request({
1330
+ method: "GET",
1331
+ path: `/OrderPos/${options.orderPosId}`
1332
+ }))[0];
1333
+ if (!position) throw new SevDeskError({
1334
+ status: 404,
1335
+ statusText: "Not Found",
1336
+ body: null
1337
+ });
1338
+ return position;
1339
+ }
1340
+ /** Updates an order position via `PUT /OrderPos/{orderPosId}`. */
1341
+ updatePosition(options) {
1342
+ const { orderPosId, unityId, partId, ...rest } = options;
1343
+ return this.http.request({
1344
+ method: "PUT",
1345
+ path: `/OrderPos/${orderPosId}`,
1346
+ body: {
1347
+ ...rest,
1348
+ unity: toRef$2(unityId, "Unity"),
1349
+ part: toRef$2(partId, "Part")
1350
+ }
1351
+ });
1352
+ }
1353
+ /** Deletes an order position via `DELETE /OrderPos/{orderPosId}`. */
1354
+ async deletePosition(options) {
1355
+ await this.http.request({
1356
+ method: "DELETE",
1357
+ path: `/OrderPos/${options.orderPosId}`
1358
+ });
1359
+ }
1360
+ };
1361
+ function toOrderBody(order) {
1362
+ return {
1363
+ objectName: "Order",
1364
+ mapAll: true,
1365
+ orderNumber: order.orderNumber,
1366
+ orderDate: toVoucherDate(order.orderDate),
1367
+ contact: {
1368
+ id: order.contactId,
1369
+ objectName: "Contact"
1370
+ },
1371
+ status: order.status,
1372
+ orderType: order.orderType,
1373
+ header: order.header,
1374
+ version: order.version,
1375
+ addressCountry: {
1376
+ id: order.addressCountryId,
1377
+ objectName: "StaticCountry"
1378
+ },
1379
+ contactPerson: {
1380
+ id: order.contactPersonId,
1381
+ objectName: "SevUser"
1382
+ },
1383
+ taxRule: {
1384
+ id: order.taxRuleId,
1385
+ objectName: "TaxRule"
1386
+ },
1387
+ taxRate: order.taxRate,
1388
+ taxText: order.taxText,
1389
+ currency: order.currency,
1390
+ headText: order.headText,
1391
+ footText: order.footText,
1392
+ deliveryTerms: order.deliveryTerms,
1393
+ paymentTerms: order.paymentTerms,
1394
+ smallSettlement: order.smallSettlement,
1395
+ showNet: order.showNet,
1396
+ address: order.address,
1397
+ customerInternalNote: order.customerInternalNote,
1398
+ sendDate: toOptionalDate(order.sendDate),
1399
+ sendType: order.sendType
1400
+ };
1401
+ }
1402
+ function toOrderPositionBody(position) {
1403
+ return {
1404
+ objectName: "OrderPos",
1405
+ mapAll: true,
1406
+ unity: {
1407
+ id: position.unityId,
1408
+ objectName: "Unity"
1409
+ },
1410
+ quantity: position.quantity,
1411
+ taxRate: position.taxRate,
1412
+ name: position.name,
1413
+ price: position.price,
1414
+ text: position.text,
1415
+ part: toRef$2(position.partId, "Part"),
1416
+ positionNumber: position.positionNumber,
1417
+ discount: position.discount,
1418
+ optional: position.optional
1419
+ };
1420
+ }
1421
+ function toRef$2(id, objectName) {
1422
+ return id === void 0 ? void 0 : {
1423
+ id,
1424
+ objectName
1425
+ };
1426
+ }
1427
+ function toOptionalDate(value) {
1428
+ return value === void 0 ? void 0 : toVoucherDate(value);
1429
+ }
1430
+ //#endregion
1431
+ //#region src/resources/parts.ts
1432
+ var PartsResource = class extends BaseResource {
1433
+ /** Retrieves parts via `GET /Part`. */
1434
+ list(options = {}) {
1435
+ const { partNumber, name, limit, offset, embed } = options;
1436
+ return this.http.request({
1437
+ method: "GET",
1438
+ path: "/Part",
1439
+ query: {
1440
+ partNumber,
1441
+ name,
1442
+ limit,
1443
+ offset,
1444
+ embed
1445
+ }
1446
+ });
1447
+ }
1448
+ /** Retrieves a single part via `GET /Part/{partId}`. */
1449
+ async get(options) {
1450
+ const part = (await this.http.request({
1451
+ method: "GET",
1452
+ path: `/Part/${options.partId}`
1453
+ }))[0];
1454
+ if (!part) throw new SevDeskError({
1455
+ status: 404,
1456
+ statusText: "Not Found",
1457
+ body: null
1458
+ });
1459
+ return part;
1460
+ }
1461
+ /** Creates a part via `POST /Part`. */
1462
+ create(options) {
1463
+ return this.http.request({
1464
+ method: "POST",
1465
+ path: "/Part",
1466
+ body: toPartBody(options)
1467
+ });
1468
+ }
1469
+ /** Updates a part via `PUT /Part/{partId}`. */
1470
+ update(options) {
1471
+ const { partId, ...fields } = options;
1472
+ return this.http.request({
1473
+ method: "PUT",
1474
+ path: `/Part/${partId}`,
1475
+ body: toPartBody(fields)
1476
+ });
1477
+ }
1478
+ /** Retrieves the current stock amount of a part via `GET /Part/{partId}/getStock`. */
1479
+ getStock(options) {
1480
+ return this.http.request({
1481
+ method: "GET",
1482
+ path: `/Part/${options.partId}/getStock`
1483
+ });
1484
+ }
1485
+ };
1486
+ function toPartBody(fields) {
1487
+ return {
1488
+ objectName: "Part",
1489
+ mapAll: true,
1490
+ name: fields.name,
1491
+ partNumber: fields.partNumber,
1492
+ unity: toRef$1(fields.unityId, "Unity"),
1493
+ taxRate: fields.taxRate,
1494
+ stock: fields.stock,
1495
+ text: fields.text,
1496
+ category: toRef$1(fields.categoryId, "Category"),
1497
+ stockEnabled: fields.stockEnabled,
1498
+ price: fields.price,
1499
+ priceNet: fields.priceNet,
1500
+ priceGross: fields.priceGross,
1501
+ pricePurchase: fields.pricePurchase,
1502
+ status: fields.status,
1503
+ internalComment: fields.internalComment
1504
+ };
1505
+ }
1506
+ function toRef$1(id, objectName) {
1507
+ return id === void 0 ? void 0 : {
1508
+ id,
1509
+ objectName
1510
+ };
1511
+ }
1512
+ //#endregion
1513
+ //#region src/resources/receipt-guidance.ts
1514
+ var ReceiptGuidanceResource = class extends BaseResource {
1515
+ /** Retrieves guidance for all accounts via `GET /ReceiptGuidance/forAllAccounts`. */
1516
+ forAllAccounts() {
1517
+ return this.http.request({
1518
+ method: "GET",
1519
+ path: "/ReceiptGuidance/forAllAccounts"
1520
+ });
1521
+ }
1522
+ /** Retrieves guidance for a datev account number via `GET /ReceiptGuidance/forAccountNumber`. */
1523
+ forAccountNumber(options) {
1524
+ return this.http.request({
1525
+ method: "GET",
1526
+ path: "/ReceiptGuidance/forAccountNumber",
1527
+ query: { accountNumber: options.accountNumber }
1528
+ });
1529
+ }
1530
+ /** Retrieves guidance for a tax rule via `GET /ReceiptGuidance/forTaxRule`. */
1531
+ forTaxRule(options) {
1532
+ return this.http.request({
1533
+ method: "GET",
1534
+ path: "/ReceiptGuidance/forTaxRule",
1535
+ query: { taxRule: options.taxRule }
1536
+ });
1537
+ }
1538
+ /** Retrieves guidance for revenue accounts via `GET /ReceiptGuidance/forRevenue`. */
1539
+ forRevenue() {
1540
+ return this.http.request({
1541
+ method: "GET",
1542
+ path: "/ReceiptGuidance/forRevenue"
1543
+ });
1544
+ }
1545
+ /** Retrieves guidance for expense accounts via `GET /ReceiptGuidance/forExpense`. */
1546
+ forExpense() {
1547
+ return this.http.request({
1548
+ method: "GET",
1549
+ path: "/ReceiptGuidance/forExpense"
1550
+ });
1551
+ }
1552
+ };
1553
+ //#endregion
1554
+ //#region src/resources/reports.ts
1555
+ var ReportsResource = class extends BaseResource {
1556
+ /** Creates an invoice list report as PDF via `GET /Report/invoicelist`. */
1557
+ invoiceList(options = {}) {
1558
+ return this.requestReport("/Report/invoicelist", {
1559
+ download: options.download,
1560
+ view: options.view ?? "all"
1561
+ }, {
1562
+ modelName: "Invoice",
1563
+ limit: options.limit,
1564
+ filter: toExportInvoiceFilter(options.filter)
1565
+ });
1566
+ }
1567
+ /** Creates an order list report as PDF via `GET /Report/orderlist`. */
1568
+ orderList(options = {}) {
1569
+ return this.requestReport("/Report/orderlist", {
1570
+ download: options.download,
1571
+ view: options.view ?? "all"
1572
+ }, {
1573
+ modelName: "Order",
1574
+ limit: options.limit,
1575
+ filter: {
1576
+ ...toExportDocumentFilter(options.filter),
1577
+ orderType: options.filter?.orderType
1578
+ }
1579
+ });
1580
+ }
1581
+ /** Creates a contact list report as PDF via `GET /Report/contactlist`. */
1582
+ contactList(options = {}) {
1583
+ return this.requestReport("/Report/contactlist", options, {
1584
+ modelName: "Contact",
1585
+ limit: options.limit,
1586
+ filter: toExportContactFilter(options.filter)
1587
+ });
1588
+ }
1589
+ /** Creates a voucher list report as PDF via `GET /Report/voucherlist`. */
1590
+ voucherList(options = {}) {
1591
+ return this.requestReport("/Report/voucherlist", options, {
1592
+ modelName: "Voucher",
1593
+ limit: options.limit,
1594
+ filter: toExportVoucherFilter(options.filter)
1595
+ });
1596
+ }
1597
+ requestReport(path, options, sevQuery) {
1598
+ return this.http.request({
1599
+ method: "GET",
1600
+ path,
1601
+ query: {
1602
+ download: options.download,
1603
+ view: options.view,
1604
+ ...toExportSevQueryParams(sevQuery)
1605
+ }
1606
+ });
1607
+ }
1608
+ };
1609
+ //#endregion
1610
+ //#region src/resources/tags.ts
1611
+ var TagsResource = class extends BaseResource {
1612
+ /** Retrieves tags via `GET /Tag`. */
1613
+ list(options = {}) {
1614
+ const { name, limit, offset } = options;
1615
+ return this.http.request({
1616
+ method: "GET",
1617
+ path: "/Tag",
1618
+ query: {
1619
+ name,
1620
+ limit,
1621
+ offset
1622
+ }
1623
+ });
1624
+ }
1625
+ /** Retrieves a single tag via `GET /Tag/{tagId}`. */
1626
+ async get(options) {
1627
+ const tag = (await this.http.request({
1628
+ method: "GET",
1629
+ path: `/Tag/${options.tagId}`
1630
+ }))[0];
1631
+ if (!tag) throw new SevDeskError({
1632
+ status: 404,
1633
+ statusText: "Not Found",
1634
+ body: null
1635
+ });
1636
+ return tag;
1637
+ }
1638
+ /**
1639
+ * Creates a tag and attaches it to a document via `POST /Tag/Factory/create`.
1640
+ * Returns the created tag relation.
1641
+ */
1642
+ create(options) {
1643
+ const { name, objectId, objectName } = options;
1644
+ return this.http.request({
1645
+ method: "POST",
1646
+ path: "/Tag/Factory/create",
1647
+ body: {
1648
+ name,
1649
+ object: {
1650
+ id: objectId,
1651
+ objectName
1652
+ }
1653
+ }
1654
+ });
1655
+ }
1656
+ /** Renames a tag via `PUT /Tag/{tagId}`. */
1657
+ update(options) {
1658
+ return this.http.request({
1659
+ method: "PUT",
1660
+ path: `/Tag/${options.tagId}`,
1661
+ body: { name: options.name }
1662
+ });
1663
+ }
1664
+ /** Deletes a tag via `DELETE /Tag/{tagId}`. */
1665
+ async delete(options) {
1666
+ await this.http.request({
1667
+ method: "DELETE",
1668
+ path: `/Tag/${options.tagId}`
1669
+ });
1670
+ }
1671
+ /** Retrieves tag relations via `GET /TagRelation`. */
1672
+ listRelations(options = {}) {
1673
+ return this.http.request({
1674
+ method: "GET",
1675
+ path: "/TagRelation",
1676
+ query: {
1677
+ limit: options.limit,
1678
+ offset: options.offset
1679
+ }
1680
+ });
1681
+ }
1682
+ };
1683
+ //#endregion
1684
+ //#region src/resources/transactions.ts
1685
+ var TransactionsResource = class extends BaseResource {
1686
+ /** Retrieves transactions via `GET /CheckAccountTransaction`. */
1687
+ async list(options = {}) {
1688
+ return this.http.request({
1689
+ method: "GET",
1690
+ path: "/CheckAccountTransaction",
1691
+ query: {
1692
+ "checkAccount[id]": options.checkAccountId,
1693
+ "checkAccount[objectName]": options.checkAccountId === void 0 ? void 0 : "CheckAccount",
1694
+ isBooked: options.isBooked,
1695
+ paymtPurpose: options.paymtPurpose,
1696
+ startDate: toOptionalIsoDateTime(options.startDate),
1697
+ endDate: toOptionalIsoDateTime(options.endDate),
1698
+ payeePayerName: options.payeePayerName,
1699
+ onlyCredit: options.onlyCredit,
1700
+ onlyDebit: options.onlyDebit,
1701
+ limit: options.limit,
1702
+ offset: options.offset
1703
+ }
1704
+ });
1705
+ }
1706
+ /** Retrieves a single transaction via `GET /CheckAccountTransaction/{transactionId}`. */
1707
+ async get(options) {
1708
+ const transaction = (await this.http.request({
1709
+ method: "GET",
1710
+ path: `/CheckAccountTransaction/${options.transactionId}`
1711
+ }))[0];
1712
+ if (!transaction) throw new SevDeskError({
1713
+ status: 404,
1714
+ statusText: "Not Found",
1715
+ body: null
1716
+ });
1717
+ return transaction;
1718
+ }
1719
+ /**
1720
+ * Creates a transaction via `POST /CheckAccountTransaction`.
1721
+ *
1722
+ * Should only be used on check accounts of type online, preferably on
1723
+ * accounts that import their transactions from CSV files.
1724
+ */
1725
+ async create(options) {
1726
+ return this.http.request({
1727
+ method: "POST",
1728
+ path: "/CheckAccountTransaction",
1729
+ body: {
1730
+ objectName: "CheckAccountTransaction",
1731
+ mapAll: true,
1732
+ valueDate: toIsoDateTime(options.valueDate),
1733
+ entryDate: toOptionalIsoDateTime(options.entryDate),
1734
+ amount: options.amount,
1735
+ payeePayerName: options.payeePayerName,
1736
+ paymtPurpose: options.paymtPurpose,
1737
+ payeePayerAcctNo: options.payeePayerAcctNo,
1738
+ payeePayerBankCode: options.payeePayerBankCode,
1739
+ checkAccount: {
1740
+ id: options.checkAccountId,
1741
+ objectName: "CheckAccount"
1742
+ },
1743
+ status: options.status ?? 100
1744
+ }
1745
+ });
1746
+ }
1747
+ /** Updates a transaction via `PUT /CheckAccountTransaction/{transactionId}`. */
1748
+ async update(options) {
1749
+ const { transactionId, valueDate, entryDate, ...rest } = options;
1750
+ return this.http.request({
1751
+ method: "PUT",
1752
+ path: `/CheckAccountTransaction/${transactionId}`,
1753
+ body: {
1754
+ ...rest,
1755
+ valueDate: toOptionalIsoDateTime(valueDate),
1756
+ entryDate: toOptionalIsoDateTime(entryDate)
1757
+ }
1758
+ });
1759
+ }
1760
+ /** Deletes a transaction via `DELETE /CheckAccountTransaction/{transactionId}`. */
1761
+ async delete(options) {
1762
+ await this.http.request({
1763
+ method: "DELETE",
1764
+ path: `/CheckAccountTransaction/${options.transactionId}`
1765
+ });
1766
+ }
1767
+ /**
1768
+ * Enshrines a transaction via `PUT /CheckAccountTransaction/{transactionId}/enshrine`.
1769
+ *
1770
+ * Requires a status of at least `200` and cannot be undone. Linked invoices,
1771
+ * credit notes and vouchers can no longer be changed afterwards.
1772
+ */
1773
+ async enshrine(options) {
1774
+ await this.http.request({
1775
+ method: "PUT",
1776
+ path: `/CheckAccountTransaction/${options.transactionId}/enshrine`
1777
+ });
1778
+ }
1779
+ };
1780
+ function toOptionalIsoDateTime(value) {
1781
+ return value === void 0 ? void 0 : toIsoDateTime(value);
1782
+ }
1783
+ //#endregion
1784
+ //#region src/resources/vouchers.ts
1785
+ var VouchersResource = class extends BaseResource {
1786
+ /** Retrieves vouchers via `GET /Voucher`. */
1787
+ list(options = {}) {
1788
+ const { status, creditDebit, descriptionLike, startDate, endDate, contactId, limit, offset, embed } = options;
1789
+ return this.http.request({
1790
+ method: "GET",
1791
+ path: "/Voucher",
1792
+ query: {
1793
+ status,
1794
+ creditDebit,
1795
+ descriptionLike,
1796
+ startDate: toOptionalVoucherDate(startDate),
1797
+ endDate: toOptionalVoucherDate(endDate),
1798
+ "contact[id]": contactId,
1799
+ "contact[objectName]": contactId === void 0 ? void 0 : "Contact",
1800
+ limit,
1801
+ offset,
1802
+ embed
1803
+ }
1804
+ });
1805
+ }
1806
+ /** Retrieves a single voucher via `GET /Voucher/{voucherId}`. */
1807
+ async get(options) {
1808
+ const voucher = (await this.http.request({
1809
+ method: "GET",
1810
+ path: `/Voucher/${options.voucherId}`
1811
+ }))[0];
1812
+ if (!voucher) throw new SevDeskError({
1813
+ status: 404,
1814
+ statusText: "Not Found",
1815
+ body: null
1816
+ });
1817
+ return voucher;
1818
+ }
1819
+ /** Uploads a voucher document via `POST /Voucher/Factory/uploadTempFile`. */
1820
+ uploadFile(options) {
1821
+ const { file, filename = "upload" } = options;
1822
+ const formData = new FormData();
1823
+ const blob = file instanceof Blob ? file : new Blob([file]);
1824
+ formData.append("file", blob, filename);
1825
+ return this.http.request({
1826
+ method: "POST",
1827
+ path: "/Voucher/Factory/uploadTempFile",
1828
+ formData
1829
+ });
1830
+ }
1831
+ /** Creates or updates a voucher with its positions via `POST /Voucher/Factory/saveVoucher`. */
1832
+ async save(options) {
1833
+ const { voucher, positions, filename } = options;
1834
+ const result = await this.http.request({
1835
+ method: "POST",
1836
+ path: "/Voucher/Factory/saveVoucher",
1837
+ body: {
1838
+ voucher: toVoucherBody(voucher),
1839
+ voucherPosSave: positions.map(toVoucherPositionBody),
1840
+ voucherPosDelete: null,
1841
+ ...filename === void 0 ? {} : { filename }
1842
+ }
1843
+ });
1844
+ return {
1845
+ voucher: result.voucher,
1846
+ positions: result.voucherPos,
1847
+ filename: result.filename
1848
+ };
1849
+ }
1850
+ /** Uploads a document and creates a voucher with it attached. */
1851
+ async createFromFile(options) {
1852
+ const { file, filename, voucher, positions } = options;
1853
+ const upload = await this.uploadFile({
1854
+ file,
1855
+ filename
1856
+ });
1857
+ return this.save({
1858
+ voucher,
1859
+ positions,
1860
+ filename: upload.filename
1861
+ });
1862
+ }
1863
+ /** Updates simple fields of a draft voucher via `PUT /Voucher/{voucherId}`. */
1864
+ update(options) {
1865
+ const { voucherId, voucherDate, description, payDate, supplierName } = options;
1866
+ return this.http.request({
1867
+ method: "PUT",
1868
+ path: `/Voucher/${voucherId}`,
1869
+ body: {
1870
+ voucherDate: toOptionalVoucherDate(voucherDate),
1871
+ description,
1872
+ payDate: toOptionalVoucherDate(payDate),
1873
+ supplierName
1874
+ }
1875
+ });
1876
+ }
1877
+ /** Books an amount on a voucher via `PUT /Voucher/{voucherId}/bookAmount`. */
1878
+ book(options) {
1879
+ const { voucherId, amount, date, type, checkAccountId, checkAccountTransactionId, createFeed } = options;
1880
+ return this.http.request({
1881
+ method: "PUT",
1882
+ path: `/Voucher/${voucherId}/bookAmount`,
1883
+ body: {
1884
+ amount,
1885
+ date: toIsoDateTime(date),
1886
+ type,
1887
+ checkAccount: {
1888
+ id: checkAccountId,
1889
+ objectName: "CheckAccount"
1890
+ },
1891
+ checkAccountTransaction: toRef(checkAccountTransactionId, "CheckAccountTransaction"),
1892
+ createFeed
1893
+ }
1894
+ });
1895
+ }
1896
+ /** Resets the voucher status to open via `PUT /Voucher/{voucherId}/resetToOpen`. */
1897
+ resetToOpen(options) {
1898
+ return this.http.request({
1899
+ method: "PUT",
1900
+ path: `/Voucher/${options.voucherId}/resetToOpen`
1901
+ });
1902
+ }
1903
+ /** Resets the voucher status to draft via `PUT /Voucher/{voucherId}/resetToDraft`. */
1904
+ resetToDraft(options) {
1905
+ return this.http.request({
1906
+ method: "PUT",
1907
+ path: `/Voucher/${options.voucherId}/resetToDraft`
1908
+ });
1909
+ }
1910
+ /** Enshrines a voucher via `PUT /Voucher/{voucherId}/enshrine`. This cannot be undone. */
1911
+ async enshrine(options) {
1912
+ await this.http.request({
1913
+ method: "PUT",
1914
+ path: `/Voucher/${options.voucherId}/enshrine`
1915
+ });
1916
+ }
1917
+ /** Retrieves the positions of a voucher via `GET /VoucherPos`. */
1918
+ listPositions(options) {
1919
+ const { voucherId, limit, offset } = options;
1920
+ return this.http.request({
1921
+ method: "GET",
1922
+ path: "/VoucherPos",
1923
+ query: {
1924
+ "voucher[id]": voucherId,
1925
+ "voucher[objectName]": "Voucher",
1926
+ limit,
1927
+ offset
1928
+ }
1929
+ });
1930
+ }
1931
+ };
1932
+ function toVoucherBody(voucher) {
1933
+ return {
1934
+ objectName: "Voucher",
1935
+ mapAll: true,
1936
+ status: voucher.status,
1937
+ creditDebit: voucher.creditDebit,
1938
+ taxRule: {
1939
+ id: voucher.taxRuleId,
1940
+ objectName: "TaxRule"
1941
+ },
1942
+ voucherType: voucher.voucherType ?? "VOU",
1943
+ voucherDate: toOptionalVoucherDate(voucher.voucherDate),
1944
+ payDate: toOptionalVoucherDate(voucher.payDate),
1945
+ deliveryDate: toOptionalVoucherDate(voucher.deliveryDate),
1946
+ deliveryDateUntil: toOptionalVoucherDate(voucher.deliveryDateUntil),
1947
+ supplier: toRef(voucher.supplierId, "Contact"),
1948
+ supplierName: voucher.supplierName,
1949
+ description: voucher.description,
1950
+ currency: voucher.currency,
1951
+ propertyExchangeRate: voucher.propertyExchangeRate,
1952
+ costCentre: toRef(voucher.costCentreId, "CostCentre")
1953
+ };
1954
+ }
1955
+ function toVoucherPositionBody(position) {
1956
+ return {
1957
+ objectName: "VoucherPos",
1958
+ mapAll: true,
1959
+ voucher: null,
1960
+ accountDatev: {
1961
+ id: position.accountDatevId,
1962
+ objectName: "AccountDatev"
1963
+ },
1964
+ taxRate: position.taxRate,
1965
+ net: position.net,
1966
+ sumNet: position.sumNet,
1967
+ sumGross: position.sumGross,
1968
+ isAsset: position.isAsset,
1969
+ comment: position.comment
1970
+ };
1971
+ }
1972
+ function toRef(id, objectName) {
1973
+ return id === void 0 ? void 0 : {
1974
+ id,
1975
+ objectName
1976
+ };
1977
+ }
1978
+ function toOptionalVoucherDate(value) {
1979
+ return value === void 0 ? void 0 : toVoucherDate(value);
1980
+ }
1981
+ //#endregion
1982
+ //#region src/client.ts
1983
+ var SevDesk = class {
1984
+ basics;
1985
+ checkAccounts;
1986
+ contacts;
1987
+ creditNotes;
1988
+ exports;
1989
+ invoices;
1990
+ orders;
1991
+ parts;
1992
+ receiptGuidance;
1993
+ reports;
1994
+ tags;
1995
+ transactions;
1996
+ vouchers;
1997
+ constructor(options) {
1998
+ const http = new HttpClient(options);
1999
+ this.basics = new BasicsResource(http);
2000
+ this.checkAccounts = new CheckAccountsResource(http);
2001
+ this.contacts = new ContactsResource(http);
2002
+ this.creditNotes = new CreditNotesResource(http);
2003
+ this.exports = new ExportsResource(http);
2004
+ this.invoices = new InvoicesResource(http);
2005
+ this.orders = new OrdersResource(http);
2006
+ this.parts = new PartsResource(http);
2007
+ this.receiptGuidance = new ReceiptGuidanceResource(http);
2008
+ this.reports = new ReportsResource(http);
2009
+ this.tags = new TagsResource(http);
2010
+ this.transactions = new TransactionsResource(http);
2011
+ this.vouchers = new VouchersResource(http);
2012
+ }
2013
+ };
2014
+ //#endregion
2015
+ export { BasicsResource, CheckAccountsResource, ContactsResource, CreditNotesResource, DEFAULT_BASE_URL, ExportsResource, InvoicesResource, OrdersResource, PartsResource, ReceiptGuidanceResource, ReportsResource, SevDesk, SevDeskError, TagsResource, TransactionsResource, VouchersResource, toExportContactFilter, toExportDocumentFilter, toExportInvoiceFilter, toExportSevQueryParams, toExportVoucherFilter };
2016
+
2017
+ //# sourceMappingURL=index.js.map