@bisondesk/documents-sdk 1.0.316 → 1.0.318

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 (94) 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/{types/booking.d.ts → booking.d.ts} +2 -0
  6. package/lib/types/booking.d.ts.map +1 -0
  7. package/lib/types/booking.js.map +1 -0
  8. package/lib/types/document-categories.d.ts +42 -0
  9. package/lib/types/document-categories.d.ts.map +1 -0
  10. package/lib/types/document-categories.js +11 -0
  11. package/lib/types/document-categories.js.map +1 -0
  12. package/lib/types/{types/documents.d.ts → documents.d.ts} +46 -40
  13. package/lib/types/documents.d.ts.map +1 -0
  14. package/lib/{esm/types → types}/documents.js +14 -16
  15. package/lib/types/documents.js.map +1 -0
  16. package/lib/types/embeddings.d.ts +19 -0
  17. package/lib/types/embeddings.d.ts.map +1 -0
  18. package/lib/types/embeddings.js +7 -0
  19. package/lib/types/embeddings.js.map +1 -0
  20. package/lib/types/{types/events.d.ts → events.d.ts} +0 -2
  21. package/lib/types/{types/events.d.ts.map → events.d.ts.map} +1 -1
  22. package/lib/{cjs/types → types}/events.js.map +1 -1
  23. package/lib/types/{types/legacy.d.ts → legacy.d.ts} +1 -0
  24. package/lib/types/legacy.d.ts.map +1 -0
  25. package/lib/types/legacy.js.map +1 -0
  26. package/lib/types/ocr.d.ts +45 -0
  27. package/lib/types/ocr.d.ts.map +1 -0
  28. package/lib/types/ocr.js +28 -0
  29. package/lib/types/ocr.js.map +1 -0
  30. package/lib/types/scans.d.ts +10 -0
  31. package/lib/types/scans.d.ts.map +1 -0
  32. package/lib/types/scans.js.map +1 -0
  33. package/lib/types/search.d.ts +36 -0
  34. package/lib/types/search.d.ts.map +1 -0
  35. package/lib/types/search.js +2 -0
  36. package/lib/types/search.js.map +1 -0
  37. package/lib/utils.d.ts +2 -0
  38. package/lib/utils.d.ts.map +1 -0
  39. package/lib/utils.js +2 -0
  40. package/lib/utils.js.map +1 -0
  41. package/package.json +13 -20
  42. package/src/apis/documents.ts +96 -0
  43. package/src/types/booking.ts +3 -0
  44. package/src/types/document-categories.ts +22 -4
  45. package/src/types/documents.ts +54 -53
  46. package/src/types/embeddings.ts +23 -0
  47. package/src/types/events.ts +0 -2
  48. package/src/types/legacy.ts +1 -0
  49. package/src/types/ocr.ts +47 -0
  50. package/src/types/scans.ts +7 -1
  51. package/src/types/search.ts +42 -0
  52. package/src/utils.ts +1 -0
  53. package/tsconfig.deploy.json +5 -0
  54. package/tsconfig.deploy.tsbuildinfo +1 -0
  55. package/tsconfig.json +1 -2
  56. package/lib/cjs/types/booking.js +0 -3
  57. package/lib/cjs/types/booking.js.map +0 -1
  58. package/lib/cjs/types/document-categories.js +0 -9
  59. package/lib/cjs/types/document-categories.js.map +0 -1
  60. package/lib/cjs/types/documents.js +0 -61
  61. package/lib/cjs/types/documents.js.map +0 -1
  62. package/lib/cjs/types/events.js +0 -3
  63. package/lib/cjs/types/legacy.js +0 -3
  64. package/lib/cjs/types/legacy.js.map +0 -1
  65. package/lib/cjs/types/scans.js +0 -3
  66. package/lib/cjs/types/scans.js.map +0 -1
  67. package/lib/cjs/types/vat.js +0 -15
  68. package/lib/cjs/types/vat.js.map +0 -1
  69. package/lib/esm/types/booking.js.map +0 -1
  70. package/lib/esm/types/document-categories.js +0 -6
  71. package/lib/esm/types/document-categories.js.map +0 -1
  72. package/lib/esm/types/documents.js.map +0 -1
  73. package/lib/esm/types/events.js.map +0 -1
  74. package/lib/esm/types/legacy.js.map +0 -1
  75. package/lib/esm/types/scans.js.map +0 -1
  76. package/lib/tsconfig.cjs.tsbuildinfo +0 -1
  77. package/lib/tsconfig.esm.tsbuildinfo +0 -1
  78. package/lib/types/types/booking.d.ts.map +0 -1
  79. package/lib/types/types/document-categories.d.ts +0 -29
  80. package/lib/types/types/document-categories.d.ts.map +0 -1
  81. package/lib/types/types/documents.d.ts.map +0 -1
  82. package/lib/types/types/legacy.d.ts.map +0 -1
  83. package/lib/types/types/scans.d.ts +0 -6
  84. package/lib/types/types/scans.d.ts.map +0 -1
  85. package/tsconfig.cjs.json +0 -8
  86. package/tsconfig.esm.json +0 -8
  87. /package/lib/{esm/types → types}/booking.js +0 -0
  88. /package/lib/{esm/types → types}/events.js +0 -0
  89. /package/lib/{esm/types → types}/legacy.js +0 -0
  90. /package/lib/{esm/types → types}/scans.js +0 -0
  91. /package/lib/types/{types/vat.d.ts → vat.d.ts} +0 -0
  92. /package/lib/types/{types/vat.d.ts.map → vat.d.ts.map} +0 -0
  93. /package/lib/{esm/types → types}/vat.js +0 -0
  94. /package/lib/{esm/types → types}/vat.js.map +0 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scans.d.ts","sourceRoot":"/","sources":["types/scans.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C,MAAM,MAAM,oBAAoB,GAAG;IACjC,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAEhB,YAAY,CAAC,EAAE,YAAY,CAAC;IAC5B,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB,CAAC"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scans.js","sourceRoot":"/","sources":["types/scans.ts"],"names":[],"mappings":"","sourcesContent":["import { DocumentType } from './documents.js';\n\nexport type NewDocumentScanEvent = {\n tenantId: string;\n source: string;\n fileUrl: string;\n\n documentType?: DocumentType;\n existingDraftId?: string;\n skipSplit?: boolean;\n};\n"]}
@@ -0,0 +1,36 @@
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
+ export type SearchDocumentVehicleRef = {
7
+ id: string;
8
+ stockNumber: string;
9
+ administrativeNumber?: string;
10
+ };
11
+ export type InputSearchFinanceDocument = SearchFinanceDocument & {
12
+ permissions: SearchPermissions;
13
+ };
14
+ export type InputSearchAdministrativeDocument = SearchAdministrativeDocument & {
15
+ permissions: SearchPermissions;
16
+ };
17
+ export type DocsSearchDefinitions = {
18
+ searchFinanceDoc: PublicSearchDefinition;
19
+ };
20
+ export type AdministrativeDocsSearchDefinitions = {
21
+ searchAdministrativeDoc: PublicSearchDefinition;
22
+ };
23
+ export type SearchFinanceDocument = {
24
+ permissions: SearchPermissions;
25
+ org?: Organization;
26
+ doc: FinanceDocument;
27
+ booking?: FinanceBooking;
28
+ vehicle?: SearchDocumentVehicleRef[];
29
+ };
30
+ export type SearchAdministrativeDocument = {
31
+ doc: AdministrativeDocument;
32
+ permissions: SearchPermissions;
33
+ org?: Organization;
34
+ vehicle?: SearchDocumentVehicleRef[];
35
+ };
36
+ //# sourceMappingURL=search.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"search.d.ts","sourceRoot":"/","sources":["types/search.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AACjE,OAAO,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAC7D,OAAO,EAAE,sBAAsB,EAAE,MAAM,uCAAuC,CAAC;AAC/E,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,EAAE,sBAAsB,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAEzE,MAAM,MAAM,wBAAwB,GAAG;IACrC,EAAE,EAAE,MAAM,CAAC;IACX,WAAW,EAAE,MAAM,CAAC;IACpB,oBAAoB,CAAC,EAAE,MAAM,CAAC;CAC/B,CAAC;AAEF,MAAM,MAAM,0BAA0B,GAAG,qBAAqB,GAAG;IAC/D,WAAW,EAAE,iBAAiB,CAAC;CAChC,CAAC;AAEF,MAAM,MAAM,iCAAiC,GAAG,4BAA4B,GAAG;IAC7E,WAAW,EAAE,iBAAiB,CAAC;CAChC,CAAC;AAEF,MAAM,MAAM,qBAAqB,GAAG;IAClC,gBAAgB,EAAE,sBAAsB,CAAC;CAC1C,CAAC;AAEF,MAAM,MAAM,mCAAmC,GAAG;IAChD,uBAAuB,EAAE,sBAAsB,CAAC;CACjD,CAAC;AAEF,MAAM,MAAM,qBAAqB,GAAG;IAClC,WAAW,EAAE,iBAAiB,CAAC;IAC/B,GAAG,CAAC,EAAE,YAAY,CAAC;IACnB,GAAG,EAAE,eAAe,CAAC;IACrB,OAAO,CAAC,EAAE,cAAc,CAAC;IACzB,OAAO,CAAC,EAAE,wBAAwB,EAAE,CAAC;CACtC,CAAC;AAEF,MAAM,MAAM,4BAA4B,GAAG;IACzC,GAAG,EAAE,sBAAsB,CAAC;IAC5B,WAAW,EAAE,iBAAiB,CAAC;IAC/B,GAAG,CAAC,EAAE,YAAY,CAAC;IACnB,OAAO,CAAC,EAAE,wBAAwB,EAAE,CAAC;CACtC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=search.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"search.js","sourceRoot":"/","sources":["types/search.ts"],"names":[],"mappings":"","sourcesContent":["import { SearchPermissions } from '@bisondesk/commons-sdk/types';\nimport { Organization } from '@bisondesk/core-sdk/types/crm';\nimport { PublicSearchDefinition } from '@bisondesk/core-sdk/types/definitions';\nimport { FinanceBooking } from './booking.js';\nimport { AdministrativeDocument, FinanceDocument } from './documents.js';\n\nexport type SearchDocumentVehicleRef = {\n id: string;\n stockNumber: string;\n administrativeNumber?: string;\n};\n\nexport type InputSearchFinanceDocument = SearchFinanceDocument & {\n permissions: SearchPermissions;\n};\n\nexport type InputSearchAdministrativeDocument = SearchAdministrativeDocument & {\n permissions: SearchPermissions;\n};\n\nexport type DocsSearchDefinitions = {\n searchFinanceDoc: PublicSearchDefinition;\n};\n\nexport type AdministrativeDocsSearchDefinitions = {\n searchAdministrativeDoc: PublicSearchDefinition;\n};\n\nexport type SearchFinanceDocument = {\n permissions: SearchPermissions;\n org?: Organization;\n doc: FinanceDocument;\n booking?: FinanceBooking;\n vehicle?: SearchDocumentVehicleRef[];\n};\n\nexport type SearchAdministrativeDocument = {\n doc: AdministrativeDocument;\n permissions: SearchPermissions;\n org?: Organization;\n vehicle?: SearchDocumentVehicleRef[];\n};\n"]}
package/lib/utils.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export declare const getPdfPreviewSrc: (fileUrl: string) => string;
2
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"/","sources":["utils.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,gBAAgB,YAAa,MAAM,WAAsC,CAAC"}
package/lib/utils.js ADDED
@@ -0,0 +1,2 @@
1
+ export const getPdfPreviewSrc = (fileUrl) => fileUrl.replace('.pdf', '/1.jpg');
2
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sourceRoot":"/","sources":["utils.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,OAAe,EAAE,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC","sourcesContent":["export const getPdfPreviewSrc = (fileUrl: string) => fileUrl.replace('.pdf', '/1.jpg');\n"]}
package/package.json CHANGED
@@ -1,9 +1,10 @@
1
1
  {
2
2
  "name": "@bisondesk/documents-sdk",
3
- "version": "1.0.316",
3
+ "version": "1.0.318",
4
4
  "description": "",
5
+ "type": "module",
5
6
  "scripts": {
6
- "build": "npx tsc --build tsconfig.cjs.json & npx tsc --build tsconfig.esm.json",
7
+ "build": "npx tsc --build tsconfig.deploy.json",
7
8
  "clean": "rm -rf lib *.tsbuildinfo",
8
9
  "unittest": "echo \"No test specified\"",
9
10
  "integrationtest": "echo \"No test specified\"",
@@ -13,31 +14,23 @@
13
14
  "dependencies": {
14
15
  "@bisondesk/commons-sdk": "*",
15
16
  "@bisondesk/core-sdk": "*",
16
- "decimal.js": "10.3.1",
17
- "joi": "17.4.0"
17
+ "decimal.js": "10.4.3",
18
+ "joi": "17.4.0",
19
+ "node-fetch": "3.3.2"
18
20
  },
19
21
  "devDependencies": {
20
- "typescript": "4.7.4"
21
- },
22
- "main": "./lib/cjs/*",
23
- "module": "./lib/esm/*",
24
- "exports": {
25
- "./*": {
26
- "import": [
27
- "./lib/esm/*.js",
28
- "./lib/esm/*/*.js"
29
- ],
30
- "require": [
31
- "./lib/cjs/*.js",
32
- "./lib/cjs/*/*.js"
33
- ]
34
- }
22
+ "@aws-sdk/client-textract": "3.465.0",
23
+ "@types/node": "18.11.9",
24
+ "typescript": "5.3.3"
35
25
  },
36
26
  "typesVersions": {
37
27
  "*": {
38
28
  "*": [
39
- "lib/types/*"
29
+ "lib/*.d.ts"
40
30
  ]
41
31
  }
32
+ },
33
+ "exports": {
34
+ "./*": "./lib/*.js"
42
35
  }
43
36
  }
@@ -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
+ };
@@ -1,3 +1,5 @@
1
+ import { FinanceDocument } from './documents.js';
2
+
1
3
  export type FinanceBookingEvent = {
2
4
  id: string;
3
5
  branchId: string;
@@ -5,6 +7,7 @@ export type FinanceBookingEvent = {
5
7
  userId: string;
6
8
  tenantId: string;
7
9
  type: 'Sale Finance' | 'Purchase Finance';
10
+ version: FinanceDocument['version'];
8
11
  };
9
12
 
10
13
  export type FinanceBooking = {
@@ -5,21 +5,39 @@ export enum DocumentCategoryVisibility {
5
5
  Private = 'private',
6
6
  }
7
7
 
8
- export type DocumentCategory = {
8
+ export enum DocumentCategoryType {
9
+ Administrative = 'administrative',
10
+ Finance = 'finance',
11
+ }
12
+
13
+ type BaseDocumentCategory = {
9
14
  createdAt: string;
10
15
  branchId: string;
11
16
  id: string;
12
17
  code: string;
18
+ type: DocumentCategoryType;
13
19
  title: string;
20
+ };
21
+
22
+ export type AdministrativeDocumentCategory = BaseDocumentCategory & {
23
+ type: DocumentCategoryType.Administrative;
24
+ };
25
+
26
+ export type FinanceDocumentCategory = BaseDocumentCategory & {
27
+ type: DocumentCategoryType.Finance;
14
28
  journal: string;
15
29
  visibility: DocumentCategoryVisibility;
16
30
  transactionTypes: [TransactionType, ...TransactionType[]];
17
31
  validators?: string[];
18
32
  };
19
33
 
20
- export type NewDocumentCategory = Omit<DocumentCategory, 'id' | 'createdAt'>;
34
+ export type DocumentCategory = AdministrativeDocumentCategory | FinanceDocumentCategory;
35
+
36
+ export type NewDocumentCategory =
37
+ | Omit<FinanceDocumentCategory, 'id' | 'createdAt'>
38
+ | Omit<AdministrativeDocumentCategory, 'id' | 'createdAt'>;
21
39
 
22
- export type DocumentLineCategory = {
40
+ export type FinanceDocumentLineCategory = {
23
41
  createdAt: string;
24
42
  branchId: string;
25
43
  categoryId: string;
@@ -30,4 +48,4 @@ export type DocumentLineCategory = {
30
48
  glAccount: string;
31
49
  };
32
50
 
33
- export type NewDocumentLineCategory = Omit<DocumentLineCategory, 'id' | 'createdAt'>;
51
+ export type NewFinanceDocumentLineCategory = Omit<FinanceDocumentLineCategory, 'id' | 'createdAt'>;
@@ -1,14 +1,6 @@
1
1
  import { BusinessEntityIds } from '@bisondesk/commons-sdk/constants';
2
- import { AttachmentValue, PhoneNumberValue, SearchPermissions } from '@bisondesk/commons-sdk/types';
3
- import { FinanceBooking } from './booking';
4
- import { FinanceDocumentV1 } from './legacy';
5
-
6
- export enum AdministrativeDocType {
7
- General = 'General Administrative',
8
- Logistics = 'Logistics Administrative',
9
- Purchase = 'Purchase Administrative',
10
- Sale = 'Sale Administrative',
11
- }
2
+ import { AttachmentValue, PhoneNumberValue } from '@bisondesk/commons-sdk/types';
3
+ import { FinanceDocumentV1 } from './legacy.js';
12
4
 
13
5
  export type FinanceDocument = FinanceDocumentV1 | FinanceDocumentV2;
14
6
 
@@ -70,16 +62,10 @@ export enum FinanceDocType {
70
62
  Purchase = 'Purchase Finance',
71
63
  }
72
64
 
73
- export enum FinanceDocumentGenerateSubtype {
74
- Invoice = 'Invoice',
75
- CreditNote = 'Credit Note',
76
- }
77
-
78
65
  type BaseDocument = {
79
66
  id: string;
80
67
  branchId: string;
81
68
  attachment: AttachmentValue;
82
- subtype: string;
83
69
  createdAt: string;
84
70
  createdBy: string;
85
71
  };
@@ -87,11 +73,9 @@ type BaseDocument = {
87
73
  export type FinanceDocumentV2 = BaseDocument & {
88
74
  version: 2.0;
89
75
  reference: string;
90
-
76
+ subtype: FinanceDocumentSubtype;
91
77
  type: FinanceDocType;
92
-
93
- category: string; // abstraction used to map invoices to Journals (e.g., leasing, used trucks)
94
-
78
+ category: string;
95
79
  organizationSummary: OrgSummary;
96
80
 
97
81
  dueDate?: string;
@@ -99,6 +83,7 @@ export type FinanceDocumentV2 = BaseDocument & {
99
83
  invoiceId?: string; // mandatory in credit notes but forbidden in invoices
100
84
  issueDate: string;
101
85
  lines: FinanceDocumentLine[];
86
+ paymentNotes?: string;
102
87
  notes?: string;
103
88
  salesperson: {
104
89
  name: string;
@@ -130,8 +115,8 @@ export type NewFinanceDocumentV2 = Omit<
130
115
  };
131
116
 
132
117
  export type AdministrativeDocument = BaseDocument & {
133
- type: AdministrativeDocType;
134
118
  tags?: string[];
119
+ category: string;
135
120
  associations?: Association[];
136
121
  organizationSummary?: OrgSummary;
137
122
  };
@@ -142,21 +127,21 @@ export type NewAdministrativeDocument = Omit<
142
127
  >;
143
128
 
144
129
  export enum DraftProcessStatus {
145
- // Prefill = 'Prefill',
146
- // Ready = 'Ready',
147
- Error = 'Error',
130
+ Prefill = 'Prefill',
148
131
  Unprocessed = 'Unprocessed',
149
- Unvalidated = 'Unvalidated',
132
+ Processed = 'Processed',
133
+ BusinessValid = 'BusinessValid',
134
+ AccountingValid = 'AccountingValid',
135
+ Completed = 'Completed',
136
+ Rejected = 'Rejected',
150
137
  }
151
138
 
152
139
  type DraftProcessing = {
153
140
  status: DraftProcessStatus;
154
- businessValid: boolean;
155
- accountingValid: boolean;
156
- rejectedAt?: string;
157
- rejectedBy?: string;
158
- rejectionReason?: string;
159
141
  failedValidationRules?: string[];
142
+ documentType?: DocumentType;
143
+ vatTotalCheck?: string;
144
+ totalCheck?: string;
160
145
  };
161
146
 
162
147
  export enum DocumentType {
@@ -164,17 +149,37 @@ export enum DocumentType {
164
149
  Administrative = 'Administrative Document',
165
150
  }
166
151
 
167
- type BaseDocumentDraft = BaseDocument &
168
- DraftProcessing & {
169
- documentType?: DocumentType;
152
+ type DraftStatusLogEntry = {
153
+ at: string;
154
+ by: string;
155
+ };
156
+
157
+ type DraftStatusLog = { [key in DraftProcessStatus]?: DraftStatusLogEntry };
158
+
159
+ type BaseDocumentDraft = (BaseDocument & DraftProcessing) &
160
+ (
161
+ | {
162
+ status: Exclude<DraftProcessStatus, DraftProcessStatus.Rejected>;
163
+ }
164
+ | {
165
+ status: DraftProcessStatus.Rejected;
166
+ rejectedAt?: string;
167
+ rejectedBy?: string;
168
+ rejectionReason?: string;
169
+ }
170
+ ) & {
171
+ log?: DraftStatusLog;
170
172
  };
171
173
 
172
174
  export type DocumentDraft<T = FinanceDocumentV2 | AdministrativeDocument> = Partial<T> &
173
175
  BaseDocumentDraft;
174
176
 
177
+ export type DocumentDraftListMeta = { status: DraftProcessStatus; count: number }[];
178
+
175
179
  export enum DraftActions {
176
180
  Delete = 'delete',
177
181
  Validate = 'validate',
182
+ Reject = 'reject',
178
183
  Submit = 'submit',
179
184
  ValidateBusinessRules = 'validate_business_rules',
180
185
  ValidateAccountingRules = 'validate_accounting_rules',
@@ -185,40 +190,31 @@ export type RejectDraftRequest = {
185
190
  };
186
191
 
187
192
  export type NewDocumentDraft<T = NewFinanceDocumentV2 | NewAdministrativeDocument> = Partial<T> &
188
- Omit<BaseDocument, 'id' | 'createdAt' | 'createdBy' | 'subtype'> & {
193
+ Omit<BaseDocumentDraft, 'id' | 'createdAt' | 'createdBy' | 'subtype'> & {
189
194
  subtype?: string;
190
195
  documentType?: DocumentType;
191
196
  };
192
197
 
193
- export type SearchFinanceDocument = {
194
- doc: FinanceDocumentV2;
195
- permissions: SearchPermissions;
196
- booking?: FinanceBooking;
197
- };
198
-
199
- export type SearchAdministrativeDocument = {
200
- doc: AdministrativeDocument;
201
- permissions: SearchPermissions;
202
- };
203
-
204
198
  export const isFinanceDocumentV2 = (
205
199
  arg: FinanceDocumentV2 | FinanceDocumentV1
206
200
  ): arg is FinanceDocumentV2 => {
207
201
  return (arg as FinanceDocumentV2).version === 2;
208
202
  };
209
203
 
210
- export const isAdministrativeDocument = (arg: any): arg is AdministrativeDocument => {
211
- return Object.values(AdministrativeDocType).includes(arg.type);
204
+ export const isFinanceDocumentV1 = (
205
+ arg: FinanceDocumentV2 | FinanceDocumentV1
206
+ ): arg is FinanceDocumentV1 => {
207
+ return (arg as FinanceDocumentV2).version == null;
212
208
  };
213
209
 
214
210
  export const isAdministrativeDocumentDraft = (
215
- draft: DocumentDraft
216
- ): draft is DocumentDraft<AdministrativeDocument> =>
211
+ draft: DocumentDraft | NewDocumentDraft
212
+ ): draft is DocumentDraft<AdministrativeDocument> | NewDocumentDraft<AdministrativeDocument> =>
217
213
  draft.documentType === DocumentType.Administrative;
218
214
 
219
215
  export const isFinanceDocumentDraft = (
220
216
  arg: DocumentDraft | NewDocumentDraft
221
- ): arg is DocumentDraft<FinanceDocumentV2> => {
217
+ ): arg is DocumentDraft<FinanceDocumentV2> | NewDocumentDraft<FinanceDocumentV2> => {
222
218
  return arg.documentType === DocumentType.Finance;
223
219
  };
224
220
 
@@ -226,7 +222,7 @@ export type FinanceDocumentGenerateRequest = Omit<
226
222
  FinanceDocumentV2,
227
223
  'id' | 'attachment' | 'createdAt' | 'createdBy' | 'version' | 'reference' | 'lines' | 'subtype'
228
224
  > & {
229
- subtype: FinanceDocumentGenerateSubtype;
225
+ subtype: FinanceDocumentSubtype;
230
226
  lines: Omit<FinanceDocumentLine, 'id'>[];
231
227
  };
232
228
 
@@ -243,11 +239,11 @@ export type FinanceDocumentSettings<M = {}> = {
243
239
  };
244
240
 
245
241
  export type FinanceDocumentBisondeskSettings = {
246
- [FinanceDocumentGenerateSubtype.Invoice]: {
242
+ [FinanceDocumentSubtype.Invoice]: {
247
243
  prefix: string;
248
244
  templateId: string;
249
245
  };
250
- [FinanceDocumentGenerateSubtype.CreditNote]: {
246
+ [FinanceDocumentSubtype.CreditNote]: {
251
247
  prefix: string;
252
248
  templateId: string;
253
249
  };
@@ -264,3 +260,8 @@ export enum FinanceDocumentSubtype {
264
260
  Proforma = 'Proforma',
265
261
  PurchaseOrder = 'Purchase Order',
266
262
  }
263
+
264
+ export enum FinanceDocumentActions {
265
+ PAY_FINANCE_DOCUMENT = 'pay_finance_document',
266
+ DELETE_FINANCE_DOCUMENT = 'delete_finance_document',
267
+ }
@@ -0,0 +1,23 @@
1
+ export enum EmbeddingType {
2
+ FinancialDocument = 'financialDocument',
3
+ AdminDocument = 'adminDocument',
4
+ Line = 'line',
5
+ }
6
+
7
+ export type DocumentEmbedding = {
8
+ id: string;
9
+ documentId: string;
10
+ embedding: number[];
11
+ type: EmbeddingType;
12
+ active: boolean;
13
+
14
+ category?: string;
15
+ subcategory?: string;
16
+ };
17
+
18
+ export type DocumentEmbeddingDB = {
19
+ // since the column needs to be indexed its stored separately
20
+ // so in the DB this type is slightly different
21
+ data: Omit<DocumentEmbedding, 'embedding'>;
22
+ embedding: string;
23
+ };
@@ -14,6 +14,4 @@ export type AdminDocumentEvent = {
14
14
  action: 'upsert' | 'delete';
15
15
  userId: string;
16
16
  tenantId: string;
17
- type: string;
18
- subtype: string;
19
17
  };
@@ -18,6 +18,7 @@ export type FinanceLineV1 = {
18
18
  export type FinanceDocumentV1 = {
19
19
  id: string;
20
20
  branchId: string;
21
+ version?: 1.0;
21
22
 
22
23
  type: 'Sale Finance' | 'Purchase Finance';
23
24
  subtype: 'Invoice' | 'Credit Note' | 'Proforma' | 'Purchase Order';
@@ -0,0 +1,47 @@
1
+ export enum OCRBlockType {
2
+ CELL = 'CELL',
3
+ KEY_VALUE_SET = 'KEY_VALUE_SET',
4
+ LAYOUT_FIGURE = 'LAYOUT_FIGURE',
5
+ LAYOUT_FOOTER = 'LAYOUT_FOOTER',
6
+ LAYOUT_HEADER = 'LAYOUT_HEADER',
7
+ LAYOUT_KEY_VALUE = 'LAYOUT_KEY_VALUE',
8
+ LAYOUT_LIST = 'LAYOUT_LIST',
9
+ LAYOUT_PAGE_NUMBER = 'LAYOUT_PAGE_NUMBER',
10
+ LAYOUT_SECTION_HEADER = 'LAYOUT_SECTION_HEADER',
11
+ LAYOUT_TABLE = 'LAYOUT_TABLE',
12
+ LAYOUT_TEXT = 'LAYOUT_TEXT',
13
+ LAYOUT_TITLE = 'LAYOUT_TITLE',
14
+ LINE = 'LINE',
15
+ MERGED_CELL = 'MERGED_CELL',
16
+ PAGE = 'PAGE',
17
+ QUERY = 'QUERY',
18
+ QUERY_RESULT = 'QUERY_RESULT',
19
+ SELECTION_ELEMENT = 'SELECTION_ELEMENT',
20
+ SIGNATURE = 'SIGNATURE',
21
+ TABLE = 'TABLE',
22
+ TABLE_FOOTER = 'TABLE_FOOTER',
23
+ TABLE_TITLE = 'TABLE_TITLE',
24
+ TITLE = 'TITLE',
25
+ WORD = 'WORD',
26
+ }
27
+
28
+ export interface OCRPoint {
29
+ X?: number;
30
+ Y?: number;
31
+ }
32
+
33
+ export type OCRBlock = {
34
+ Id?: string;
35
+ BlockType?: OCRBlockType;
36
+ Text?: string;
37
+ Confidence?: number;
38
+ Geometry?: {
39
+ Polygon?: OCRPoint[];
40
+ };
41
+ };
42
+
43
+ export type OCRDocument = {
44
+ Blocks?: OCRBlock[];
45
+ orientation: number;
46
+ hasCurrency: boolean;
47
+ };
@@ -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');
@@ -0,0 +1,5 @@
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "exclude": ["/**/*.spec.ts", "/**/*.test.ts"],
4
+ "references": [{ "path": "../commons-sdk" }, { "path": "../core-sdk" }]
5
+ }