@bisondesk/documents-sdk 1.0.315 → 1.0.317

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.
Files changed (73) hide show
  1. package/lib/apis/documents.d.ts +6 -0
  2. package/lib/apis/documents.d.ts.map +1 -0
  3. package/lib/apis/documents.js +71 -0
  4. package/lib/apis/documents.js.map +1 -0
  5. package/lib/types/booking.d.ts +26 -0
  6. package/lib/types/booking.d.ts.map +1 -0
  7. package/lib/types/booking.js +2 -0
  8. package/lib/types/booking.js.map +1 -0
  9. package/lib/types/{types/documents.d.ts → documents.d.ts} +33 -12
  10. package/lib/types/documents.d.ts.map +1 -0
  11. package/lib/{esm/types → types}/documents.js +15 -0
  12. package/lib/types/documents.js.map +1 -0
  13. package/lib/types/embeddings.d.ts +18 -0
  14. package/lib/types/embeddings.d.ts.map +1 -0
  15. package/lib/types/embeddings.js +6 -0
  16. package/lib/types/embeddings.js.map +1 -0
  17. package/lib/types/events.d.ts +19 -0
  18. package/lib/types/events.d.ts.map +1 -0
  19. package/lib/types/events.js +2 -0
  20. package/lib/types/events.js.map +1 -0
  21. package/lib/types/legacy.d.ts +60 -0
  22. package/lib/types/legacy.d.ts.map +1 -0
  23. package/lib/types/legacy.js +2 -0
  24. package/lib/types/legacy.js.map +1 -0
  25. package/lib/types/scans.d.ts +10 -0
  26. package/lib/types/scans.d.ts.map +1 -0
  27. package/lib/types/scans.js.map +1 -0
  28. package/lib/types/search.d.ts +36 -0
  29. package/lib/types/search.d.ts.map +1 -0
  30. package/lib/types/search.js +2 -0
  31. package/lib/types/search.js.map +1 -0
  32. package/lib/utils.d.ts +2 -0
  33. package/lib/utils.d.ts.map +1 -0
  34. package/lib/utils.js +2 -0
  35. package/lib/utils.js.map +1 -0
  36. package/package.json +13 -21
  37. package/src/apis/documents.ts +96 -0
  38. package/src/types/booking.ts +29 -0
  39. package/src/types/documents.ts +37 -14
  40. package/src/types/embeddings.ts +20 -0
  41. package/src/types/events.ts +19 -0
  42. package/src/types/legacy.ts +56 -0
  43. package/src/types/scans.ts +7 -1
  44. package/src/types/search.ts +42 -0
  45. package/src/utils.ts +1 -0
  46. package/tsconfig.json +0 -1
  47. package/tsconfig.tsbuildinfo +1 -0
  48. package/lib/cjs/types/document-categories.js +0 -9
  49. package/lib/cjs/types/document-categories.js.map +0 -1
  50. package/lib/cjs/types/documents.js +0 -54
  51. package/lib/cjs/types/documents.js.map +0 -1
  52. package/lib/cjs/types/scans.js +0 -3
  53. package/lib/cjs/types/scans.js.map +0 -1
  54. package/lib/cjs/types/vat.js +0 -15
  55. package/lib/cjs/types/vat.js.map +0 -1
  56. package/lib/esm/types/documents.js.map +0 -1
  57. package/lib/esm/types/scans.js.map +0 -1
  58. package/lib/tsconfig.cjs.tsbuildinfo +0 -1
  59. package/lib/tsconfig.esm.tsbuildinfo +0 -1
  60. package/lib/types/types/documents.d.ts.map +0 -1
  61. package/lib/types/types/scans.d.ts +0 -6
  62. package/lib/types/types/scans.d.ts.map +0 -1
  63. package/tsconfig.cjs.json +0 -8
  64. package/tsconfig.esm.json +0 -8
  65. /package/lib/types/{types/document-categories.d.ts → document-categories.d.ts} +0 -0
  66. /package/lib/types/{types/document-categories.d.ts.map → document-categories.d.ts.map} +0 -0
  67. /package/lib/{esm/types → types}/document-categories.js +0 -0
  68. /package/lib/{esm/types → types}/document-categories.js.map +0 -0
  69. /package/lib/{esm/types → types}/scans.js +0 -0
  70. /package/lib/types/{types/vat.d.ts → vat.d.ts} +0 -0
  71. /package/lib/types/{types/vat.d.ts.map → vat.d.ts.map} +0 -0
  72. /package/lib/{esm/types → types}/vat.js +0 -0
  73. /package/lib/{esm/types → types}/vat.js.map +0 -0
@@ -0,0 +1,96 @@
1
+ import { TENANT_ID_ADMIN_HEADER } from '@bisondesk/commons-sdk/constants';
2
+ import { XError } from '@bisondesk/commons-sdk/errors';
3
+ import { getAdminAuth } from '@bisondesk/commons-sdk/fetch';
4
+ import fetch, { Response } from 'node-fetch';
5
+ import { FinanceBooking } from '../types/booking.js';
6
+ import { AdministrativeDocument, FinanceDocument } from '../types/documents.js';
7
+
8
+ export const upsertFinanceDoc = async (
9
+ tenantId: string,
10
+ doc: FinanceDocument
11
+ ): Promise<FinanceDocument> => {
12
+ const auth = await getAdminAuth();
13
+ const response: Response = await fetch(`${process.env.CORE_API_ORIGIN}/api/documents/finance`, {
14
+ method: 'POST',
15
+ headers: {
16
+ 'Content-Type': 'application/json',
17
+ Authorization: auth,
18
+ [TENANT_ID_ADMIN_HEADER]: tenantId,
19
+ },
20
+ body: JSON.stringify(doc),
21
+ });
22
+
23
+ if (response.status === 200) {
24
+ return response.json() as any;
25
+ }
26
+
27
+ const body = await response.text();
28
+ throw new XError('core-sdk.documents.upsert-finance-doc-fail', {
29
+ tenantId,
30
+ doc,
31
+ response: body,
32
+ status: response.status,
33
+ });
34
+ };
35
+
36
+ export const upsertAdminDoc = async (
37
+ tenantId: string,
38
+ doc: AdministrativeDocument
39
+ ): Promise<AdministrativeDocument> => {
40
+ const auth = await getAdminAuth();
41
+ const response: Response = await fetch(
42
+ `${process.env.CORE_API_ORIGIN}/api/documents/administrative`,
43
+ {
44
+ method: 'POST',
45
+ headers: {
46
+ 'Content-Type': 'application/json',
47
+ Authorization: auth,
48
+ [TENANT_ID_ADMIN_HEADER]: tenantId,
49
+ },
50
+ body: JSON.stringify(doc),
51
+ }
52
+ );
53
+
54
+ if (response.status === 200) {
55
+ return response.json() as any;
56
+ }
57
+
58
+ const body = await response.text();
59
+ throw new XError('core-sdk.documents.upsert-admin-doc-fail', {
60
+ tenantId,
61
+ doc,
62
+ response: body,
63
+ status: response.status,
64
+ });
65
+ };
66
+
67
+ export const upsertFinanceBooking = async (
68
+ tenantId: string,
69
+ booking: FinanceBooking
70
+ ): Promise<FinanceBooking> => {
71
+ const auth = await getAdminAuth();
72
+ const response: Response = await fetch(
73
+ `${process.env.CORE_API_ORIGIN}/api/documents/finance/booking`,
74
+ {
75
+ method: 'POST',
76
+ headers: {
77
+ 'Content-Type': 'application/json',
78
+ Authorization: auth,
79
+ [TENANT_ID_ADMIN_HEADER]: tenantId,
80
+ },
81
+ body: JSON.stringify(booking),
82
+ }
83
+ );
84
+
85
+ if (response.status === 200) {
86
+ return response.json() as any;
87
+ }
88
+
89
+ const body = await response.text();
90
+ throw new XError('core-sdk.documents.upsert-finance-booking-fail', {
91
+ tenantId,
92
+ booking,
93
+ response: body,
94
+ status: response.status,
95
+ });
96
+ };
@@ -0,0 +1,29 @@
1
+ import { FinanceDocument } from './documents.js';
2
+
3
+ export type FinanceBookingEvent = {
4
+ id: string;
5
+ branchId: string;
6
+ actionAt: string;
7
+ userId: string;
8
+ tenantId: string;
9
+ type: 'Sale Finance' | 'Purchase Finance';
10
+ version: FinanceDocument['version'];
11
+ };
12
+
13
+ export type FinanceBooking = {
14
+ branchId: string; // same tenantId can have different companies
15
+ bookingNumber: string; // same booking number can and will exist across different "branches", unique => BranchId / Journal / Booking Number
16
+ documentId: string;
17
+
18
+ booked: true;
19
+ journal?: string;
20
+ amount?: string;
21
+ reportingPeriod?: number;
22
+ reportingYear?: number;
23
+ paid: boolean;
24
+
25
+ createdAt: string;
26
+ createdBy: string;
27
+ modifiedAt: string;
28
+ modifiedBy: string;
29
+ };
@@ -1,6 +1,7 @@
1
+ import type { Block } from '@aws-sdk/client-textract';
1
2
  import { BusinessEntityIds } from '@bisondesk/commons-sdk/constants';
2
- import { AttachmentValue, PhoneNumberValue, SearchPermissions } from '@bisondesk/commons-sdk/types';
3
- import { FinanceBooking, FinanceDocument } from '@bisondesk/core-sdk/types/documents';
3
+ import { AttachmentValue, PhoneNumberValue } from '@bisondesk/commons-sdk/types';
4
+ import { FinanceDocumentV1 } from './legacy.js';
4
5
 
5
6
  export enum AdministrativeDocType {
6
7
  General = 'General Administrative',
@@ -9,6 +10,8 @@ export enum AdministrativeDocType {
9
10
  Sale = 'Sale Administrative',
10
11
  }
11
12
 
13
+ export type FinanceDocument = FinanceDocumentV1 | FinanceDocumentV2;
14
+
12
15
  export type Association = {
13
16
  businessEntityId: BusinessEntityIds;
14
17
  id: string;
@@ -96,6 +99,7 @@ export type FinanceDocumentV2 = BaseDocument & {
96
99
  invoiceId?: string; // mandatory in credit notes but forbidden in invoices
97
100
  issueDate: string;
98
101
  lines: FinanceDocumentLine[];
102
+ paymentNotes?: string;
99
103
  notes?: string;
100
104
  salesperson: {
101
105
  name: string;
@@ -142,6 +146,7 @@ export enum DraftProcessStatus {
142
146
  // Prefill = 'Prefill',
143
147
  // Ready = 'Ready',
144
148
  Error = 'Error',
149
+ Validated = 'Validated',
145
150
  Unprocessed = 'Unprocessed',
146
151
  Unvalidated = 'Unvalidated',
147
152
  }
@@ -187,23 +192,18 @@ export type NewDocumentDraft<T = NewFinanceDocumentV2 | NewAdministrativeDocumen
187
192
  documentType?: DocumentType;
188
193
  };
189
194
 
190
- export type SearchFinanceDocument = {
191
- doc: FinanceDocumentV2;
192
- permissions: SearchPermissions;
193
- booking?: FinanceBooking;
194
- };
195
-
196
- export type SearchAdministrativeDocument = {
197
- doc: AdministrativeDocument;
198
- permissions: SearchPermissions;
199
- };
200
-
201
195
  export const isFinanceDocumentV2 = (
202
- arg: FinanceDocumentV2 | FinanceDocument
196
+ arg: FinanceDocumentV2 | FinanceDocumentV1
203
197
  ): arg is FinanceDocumentV2 => {
204
198
  return (arg as FinanceDocumentV2).version === 2;
205
199
  };
206
200
 
201
+ export const isFinanceDocumentV1 = (
202
+ arg: FinanceDocumentV2 | FinanceDocumentV1
203
+ ): arg is FinanceDocumentV1 => {
204
+ return (arg as FinanceDocumentV2).version == null;
205
+ };
206
+
207
207
  export const isAdministrativeDocument = (arg: any): arg is AdministrativeDocument => {
208
208
  return Object.values(AdministrativeDocType).includes(arg.type);
209
209
  };
@@ -249,3 +249,26 @@ export type FinanceDocumentBisondeskSettings = {
249
249
  templateId: string;
250
250
  };
251
251
  };
252
+
253
+ export type FinanceDocumentPayment = { documentId: string } & (
254
+ | { paid: true; paidAt: string; comment?: string }
255
+ | { paid: false; paidAt?: undefined; comment?: undefined }
256
+ );
257
+
258
+ export enum FinanceDocumentSubtype {
259
+ Invoice = 'Invoice',
260
+ CreditNote = 'Credit Note',
261
+ Proforma = 'Proforma',
262
+ PurchaseOrder = 'Purchase Order',
263
+ }
264
+
265
+ export type OCRDocument = {
266
+ Blocks?: Block[];
267
+ orientation: number;
268
+ hasCurrency: boolean;
269
+ };
270
+
271
+ export enum FinanceDocumentActions {
272
+ PAY_FINANCE_DOCUMENT = 'pay_finance_document',
273
+ DELETE_FINANCE_DOCUMENT = 'delete_finance_document',
274
+ }
@@ -0,0 +1,20 @@
1
+ export enum EmbeddingType {
2
+ Document = 'document',
3
+ Line = 'line',
4
+ }
5
+
6
+ export type DocumentEmbedding = {
7
+ id: string;
8
+ documentId: string;
9
+ embedding: number[];
10
+ type: EmbeddingType;
11
+ active: boolean;
12
+
13
+ category?: string;
14
+ lineCategory?: string;
15
+ };
16
+
17
+ export type DocumentEmbeddingDB = {
18
+ data: Omit<DocumentEmbedding, 'embedding'>;
19
+ embedding: string;
20
+ };
@@ -0,0 +1,19 @@
1
+ export type FinanceDocumentEvent = {
2
+ id: string;
3
+ actionAt: string;
4
+ action: 'upsert' | 'delete';
5
+ userId: string;
6
+ tenantId: string;
7
+ type: 'Sale Finance' | 'Purchase Finance';
8
+ subtype: string; // Invoice, Credit Note, etc.
9
+ };
10
+
11
+ export type AdminDocumentEvent = {
12
+ id: string;
13
+ actionAt: string;
14
+ action: 'upsert' | 'delete';
15
+ userId: string;
16
+ tenantId: string;
17
+ type: string;
18
+ subtype: string;
19
+ };
@@ -0,0 +1,56 @@
1
+ import { AttachmentValue } from '@bisondesk/commons-sdk/types';
2
+
3
+ export type FinanceLineV1 = {
4
+ associations: {
5
+ others: { vehicleId: string; label: string }[];
6
+ sales: { id: string; vehicleId: string; label: string }[];
7
+ purchases: { id: string; vehicleId: string; label: string }[];
8
+ };
9
+ description: string;
10
+ id: string;
11
+ lineCode: string;
12
+ quantity: string;
13
+ unitPriceExclusive: string;
14
+ vatCode: string;
15
+ vatCoefficient: string;
16
+ };
17
+
18
+ export type FinanceDocumentV1 = {
19
+ id: string;
20
+ branchId: string;
21
+ version?: 1.0;
22
+
23
+ type: 'Sale Finance' | 'Purchase Finance';
24
+ subtype: 'Invoice' | 'Credit Note' | 'Proforma' | 'Purchase Order';
25
+ reference: string;
26
+
27
+ attachment: AttachmentValue;
28
+ lines: FinanceLineV1[];
29
+ notes?: string;
30
+
31
+ createdAt: string;
32
+ createdBy: string;
33
+ issueDate: string;
34
+ paidAt?: string;
35
+ paymentNotes?: string;
36
+ amount?: string;
37
+ dueDate?: string;
38
+
39
+ organizationSummary?: {
40
+ id: string;
41
+ code: string;
42
+ name: string;
43
+ country: string;
44
+ vatNumber?: string;
45
+
46
+ addressLine1?: string;
47
+ addressLine2?: string;
48
+ addressLine3?: string;
49
+ postcode?: string;
50
+ city?: string;
51
+
52
+ email?: string;
53
+ phone?: string;
54
+ fax?: string;
55
+ };
56
+ };
@@ -1,5 +1,11 @@
1
+ import { DocumentType } from './documents.js';
2
+
1
3
  export type NewDocumentScanEvent = {
2
4
  tenantId: string;
3
5
  source: string;
4
- files: string[];
6
+ fileUrl: string;
7
+
8
+ documentType?: DocumentType;
9
+ existingDraftId?: string;
10
+ skipSplit?: boolean;
5
11
  };
@@ -0,0 +1,42 @@
1
+ import { SearchPermissions } from '@bisondesk/commons-sdk/types';
2
+ import { Organization } from '@bisondesk/core-sdk/types/crm';
3
+ import { PublicSearchDefinition } from '@bisondesk/core-sdk/types/definitions';
4
+ import { FinanceBooking } from './booking.js';
5
+ import { AdministrativeDocument, FinanceDocument } from './documents.js';
6
+
7
+ export type SearchDocumentVehicleRef = {
8
+ id: string;
9
+ stockNumber: string;
10
+ administrativeNumber?: string;
11
+ };
12
+
13
+ export type InputSearchFinanceDocument = SearchFinanceDocument & {
14
+ permissions: SearchPermissions;
15
+ };
16
+
17
+ export type InputSearchAdministrativeDocument = SearchAdministrativeDocument & {
18
+ permissions: SearchPermissions;
19
+ };
20
+
21
+ export type DocsSearchDefinitions = {
22
+ searchFinanceDoc: PublicSearchDefinition;
23
+ };
24
+
25
+ export type AdministrativeDocsSearchDefinitions = {
26
+ searchAdministrativeDoc: PublicSearchDefinition;
27
+ };
28
+
29
+ export type SearchFinanceDocument = {
30
+ permissions: SearchPermissions;
31
+ org?: Organization;
32
+ doc: FinanceDocument;
33
+ booking?: FinanceBooking;
34
+ vehicle?: SearchDocumentVehicleRef[];
35
+ };
36
+
37
+ export type SearchAdministrativeDocument = {
38
+ doc: AdministrativeDocument;
39
+ permissions: SearchPermissions;
40
+ org?: Organization;
41
+ vehicle?: SearchDocumentVehicleRef[];
42
+ };
package/src/utils.ts ADDED
@@ -0,0 +1 @@
1
+ export const getPdfPreviewSrc = (fileUrl: string) => fileUrl.replace('.pdf', '/1.jpg');
package/tsconfig.json CHANGED
@@ -9,7 +9,6 @@
9
9
  "composite": true,
10
10
  "rootDir": "src",
11
11
  "outDir": "lib",
12
- "declarationDir": "lib/types"
13
12
  },
14
13
  "include": ["src"],
15
14
  "references": [{ "path": "../commons-sdk" }, { "path": "../core-sdk" }]