@bisondesk/documents-sdk 1.0.317 → 1.0.319
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/lib/apis/document-drafts.d.ts +4 -0
- package/lib/apis/document-drafts.d.ts.map +1 -0
- package/lib/apis/document-drafts.js +45 -0
- package/lib/apis/document-drafts.js.map +1 -0
- package/lib/apis/documents.d.ts +3 -0
- package/lib/apis/documents.d.ts.map +1 -1
- package/lib/apis/documents.js +41 -3
- package/lib/apis/documents.js.map +1 -1
- package/lib/schemas.d.ts +6 -0
- package/lib/schemas.d.ts.map +1 -0
- package/lib/schemas.js +105 -0
- package/lib/schemas.js.map +1 -0
- package/lib/types/booking.d.ts +9 -3
- package/lib/types/booking.d.ts.map +1 -1
- package/lib/types/booking.js.map +1 -1
- package/lib/types/document-categories.d.ts +39 -8
- package/lib/types/document-categories.d.ts.map +1 -1
- package/lib/types/document-categories.js +5 -0
- package/lib/types/document-categories.js.map +1 -1
- package/lib/types/documents.d.ts +61 -37
- package/lib/types/documents.d.ts.map +1 -1
- package/lib/types/documents.js +13 -16
- package/lib/types/documents.js.map +1 -1
- package/lib/types/embeddings.d.ts +3 -2
- package/lib/types/embeddings.d.ts.map +1 -1
- package/lib/types/embeddings.js +2 -1
- package/lib/types/embeddings.js.map +1 -1
- package/lib/types/events.d.ts +2 -4
- package/lib/types/events.d.ts.map +1 -1
- package/lib/types/events.js.map +1 -1
- package/lib/types/legacy.d.ts +1 -0
- package/lib/types/legacy.d.ts.map +1 -1
- package/lib/types/legacy.js.map +1 -1
- package/lib/types/ocr.d.ts +45 -0
- package/lib/types/ocr.d.ts.map +1 -0
- package/lib/types/ocr.js +28 -0
- package/lib/types/ocr.js.map +1 -0
- package/lib/types/search.d.ts +9 -8
- package/lib/types/search.d.ts.map +1 -1
- package/lib/types/search.js.map +1 -1
- package/lib/types/vat.d.ts +1 -1
- package/lib/types/vat.d.ts.map +1 -1
- package/lib/types/vat.js.map +1 -1
- package/lib/utils/associations.d.ts +6 -0
- package/lib/utils/associations.d.ts.map +1 -0
- package/lib/utils/associations.js +9 -0
- package/lib/utils/associations.js.map +1 -0
- package/lib/{utils.d.ts → utils/previews.d.ts} +1 -1
- package/lib/utils/previews.d.ts.map +1 -0
- package/lib/{utils.js → utils/previews.js} +1 -1
- package/lib/utils/previews.js.map +1 -0
- package/package.json +2 -2
- package/src/apis/document-drafts.ts +68 -0
- package/src/apis/documents.ts +60 -3
- package/src/schemas.ts +112 -0
- package/src/types/booking.ts +4 -3
- package/src/types/document-categories.ts +48 -8
- package/src/types/documents.ts +73 -50
- package/src/types/embeddings.ts +5 -2
- package/src/types/events.ts +2 -4
- package/src/types/legacy.ts +1 -0
- package/src/types/ocr.ts +47 -0
- package/src/types/search.ts +10 -8
- package/src/types/vat.ts +1 -1
- package/src/utils/associations.ts +21 -0
- package/tsconfig.deploy.json +5 -0
- package/tsconfig.deploy.tsbuildinfo +1 -0
- package/tsconfig.json +1 -1
- package/lib/utils.d.ts.map +0 -1
- package/lib/utils.js.map +0 -1
- package/tsconfig.tsbuildinfo +0 -1
- /package/src/{utils.ts → utils/previews.ts} +0 -0
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { BusinessEntityIds } from '@bisondesk/commons-sdk/constants';
|
|
2
|
+
import { GlobalBusinessEntity } from '@bisondesk/core-sdk/utils/search';
|
|
3
|
+
import { Association } from '../types/documents.js';
|
|
4
|
+
export type SupportedAssociationEntity = GlobalBusinessEntity;
|
|
5
|
+
export declare const getAssociationForBusinessEntity: (businessEntityId: BusinessEntityIds, record: SupportedAssociationEntity) => Association;
|
|
6
|
+
//# sourceMappingURL=associations.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"associations.d.ts","sourceRoot":"/","sources":["utils/associations.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,kCAAkC,CAAC;AACrE,OAAO,EACL,oBAAoB,EAIrB,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAEpD,MAAM,MAAM,0BAA0B,GAAG,oBAAoB,CAAC;AAE9D,eAAO,MAAM,+BAA+B,qBACxB,iBAAiB,UAC3B,0BAA0B,KACjC,WAMD,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { getDescriptionForBusinessEntity, getTagsForBusinessEntity, getTitleForBusinessEntity, } from '@bisondesk/core-sdk/utils/search';
|
|
2
|
+
export const getAssociationForBusinessEntity = (businessEntityId, record) => ({
|
|
3
|
+
businessEntityId,
|
|
4
|
+
recordId: record.id,
|
|
5
|
+
title: getTitleForBusinessEntity(businessEntityId, record),
|
|
6
|
+
description: getDescriptionForBusinessEntity(businessEntityId, record),
|
|
7
|
+
tags: getTagsForBusinessEntity(businessEntityId, record),
|
|
8
|
+
});
|
|
9
|
+
//# sourceMappingURL=associations.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"associations.js","sourceRoot":"/","sources":["utils/associations.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,+BAA+B,EAC/B,wBAAwB,EACxB,yBAAyB,GAC1B,MAAM,kCAAkC,CAAC;AAK1C,MAAM,CAAC,MAAM,+BAA+B,GAAG,CAC7C,gBAAmC,EACnC,MAAkC,EACrB,EAAE,CAAC,CAAC;IACjB,gBAAgB;IAChB,QAAQ,EAAE,MAAM,CAAC,EAAE;IACnB,KAAK,EAAE,yBAAyB,CAAC,gBAAgB,EAAE,MAAM,CAAC;IAC1D,WAAW,EAAE,+BAA+B,CAAC,gBAAgB,EAAE,MAAM,CAAC;IACtE,IAAI,EAAE,wBAAwB,CAAC,gBAAgB,EAAE,MAAM,CAAC;CACzD,CAAC,CAAC","sourcesContent":["import { BusinessEntityIds } from '@bisondesk/commons-sdk/constants';\nimport {\n GlobalBusinessEntity,\n getDescriptionForBusinessEntity,\n getTagsForBusinessEntity,\n getTitleForBusinessEntity,\n} from '@bisondesk/core-sdk/utils/search';\nimport { Association } from '../types/documents.js';\n\nexport type SupportedAssociationEntity = GlobalBusinessEntity;\n\nexport const getAssociationForBusinessEntity = (\n businessEntityId: BusinessEntityIds,\n record: SupportedAssociationEntity\n): Association => ({\n businessEntityId,\n recordId: record.id,\n title: getTitleForBusinessEntity(businessEntityId, record),\n description: getDescriptionForBusinessEntity(businessEntityId, record),\n tags: getTagsForBusinessEntity(businessEntityId, record),\n});\n"]}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export declare const getPdfPreviewSrc: (fileUrl: string) => string;
|
|
2
|
-
//# sourceMappingURL=
|
|
2
|
+
//# sourceMappingURL=previews.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"previews.d.ts","sourceRoot":"/","sources":["utils/previews.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,gBAAgB,YAAa,MAAM,WAAsC,CAAC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export const getPdfPreviewSrc = (fileUrl) => fileUrl.replace('.pdf', '/1.jpg');
|
|
2
|
-
//# sourceMappingURL=
|
|
2
|
+
//# sourceMappingURL=previews.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"previews.js","sourceRoot":"/","sources":["utils/previews.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,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bisondesk/documents-sdk",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.319",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"scripts": {
|
|
7
|
-
"build": "npx tsc --build",
|
|
7
|
+
"build": "npx tsc --build tsconfig.deploy.json",
|
|
8
8
|
"clean": "rm -rf lib *.tsbuildinfo",
|
|
9
9
|
"unittest": "echo \"No test specified\"",
|
|
10
10
|
"integrationtest": "echo \"No test specified\"",
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import {
|
|
2
|
+
FinanceDocumentCategory,
|
|
3
|
+
FinanceDocumentLineCategory,
|
|
4
|
+
} from '../types/document-categories.js';
|
|
5
|
+
import { getAdminAuth } from '@bisondesk/commons-sdk/fetch';
|
|
6
|
+
import fetch, { Response } from 'node-fetch';
|
|
7
|
+
import { TENANT_ID_ADMIN_HEADER } from '@bisondesk/commons-sdk/constants';
|
|
8
|
+
import { XError } from '@bisondesk/commons-sdk/errors';
|
|
9
|
+
|
|
10
|
+
export const getFinanceDocumentCategory = async (
|
|
11
|
+
tenantId: string,
|
|
12
|
+
branchId: string,
|
|
13
|
+
docCategoryId: string
|
|
14
|
+
): Promise<FinanceDocumentCategory | undefined> => {
|
|
15
|
+
const auth = await getAdminAuth();
|
|
16
|
+
const response: Response = await fetch(
|
|
17
|
+
`${process.env.DOCUMENT_DRAFTS_API_ORIGIN}/api/documents/settings/${branchId}/document-categories/${docCategoryId}`,
|
|
18
|
+
{
|
|
19
|
+
headers: {
|
|
20
|
+
Authorization: auth,
|
|
21
|
+
[TENANT_ID_ADMIN_HEADER]: tenantId,
|
|
22
|
+
},
|
|
23
|
+
}
|
|
24
|
+
);
|
|
25
|
+
|
|
26
|
+
if (response.status === 200) {
|
|
27
|
+
return response.json() as any;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const body = await response.text();
|
|
31
|
+
throw new XError('documents-sdk.drafts.get-doc-category-fail', {
|
|
32
|
+
tenantId,
|
|
33
|
+
branchId,
|
|
34
|
+
docCategoryId,
|
|
35
|
+
response: body,
|
|
36
|
+
status: response.status,
|
|
37
|
+
});
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export const listFinanceLineCategories = async (
|
|
41
|
+
tenantId: string,
|
|
42
|
+
branchId: string,
|
|
43
|
+
docCategoryId: string
|
|
44
|
+
): Promise<FinanceDocumentLineCategory[]> => {
|
|
45
|
+
const auth = await getAdminAuth();
|
|
46
|
+
const response: Response = await fetch(
|
|
47
|
+
`${process.env.DOCUMENT_DRAFTS_API_ORIGIN}/api/documents/settings/${branchId}/document-categories/${docCategoryId}/line-categories`,
|
|
48
|
+
{
|
|
49
|
+
headers: {
|
|
50
|
+
Authorization: auth,
|
|
51
|
+
[TENANT_ID_ADMIN_HEADER]: tenantId,
|
|
52
|
+
},
|
|
53
|
+
}
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
if (response.status === 200) {
|
|
57
|
+
return response.json() as any;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const body = await response.text();
|
|
61
|
+
throw new XError('documents-sdk.drafts.get-doc-lines-categories-fail', {
|
|
62
|
+
tenantId,
|
|
63
|
+
branchId,
|
|
64
|
+
docCategoryId,
|
|
65
|
+
response: body,
|
|
66
|
+
status: response.status,
|
|
67
|
+
});
|
|
68
|
+
};
|
package/src/apis/documents.ts
CHANGED
|
@@ -1,10 +1,67 @@
|
|
|
1
1
|
import { TENANT_ID_ADMIN_HEADER } from '@bisondesk/commons-sdk/constants';
|
|
2
2
|
import { XError } from '@bisondesk/commons-sdk/errors';
|
|
3
3
|
import { getAdminAuth } from '@bisondesk/commons-sdk/fetch';
|
|
4
|
+
import { DataRecord, ReferenceData } from '@bisondesk/core-sdk/types/utils';
|
|
4
5
|
import fetch, { Response } from 'node-fetch';
|
|
5
6
|
import { FinanceBooking } from '../types/booking.js';
|
|
6
7
|
import { AdministrativeDocument, FinanceDocument } from '../types/documents.js';
|
|
7
8
|
|
|
9
|
+
export const getFinanceDocument = async (
|
|
10
|
+
tenantId: string,
|
|
11
|
+
documentId: string
|
|
12
|
+
): Promise<DataRecord<FinanceDocument, ReferenceData> | undefined> => {
|
|
13
|
+
const auth = await getAdminAuth();
|
|
14
|
+
const response: Response = await fetch(
|
|
15
|
+
`${process.env.CORE_API_ORIGIN}/api/documents/finance/${documentId}`,
|
|
16
|
+
{
|
|
17
|
+
headers: {
|
|
18
|
+
Authorization: auth,
|
|
19
|
+
[TENANT_ID_ADMIN_HEADER]: tenantId,
|
|
20
|
+
},
|
|
21
|
+
}
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
if (response.status === 200) {
|
|
25
|
+
return response.json() as any;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const body = await response.text();
|
|
29
|
+
throw new XError('documents-sdk.get-finance-doc-fail', {
|
|
30
|
+
tenantId,
|
|
31
|
+
documentId,
|
|
32
|
+
response: body,
|
|
33
|
+
status: response.status,
|
|
34
|
+
});
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export const getFinanceBookingByDocId = async (
|
|
38
|
+
tenantId: string,
|
|
39
|
+
documentId: string
|
|
40
|
+
): Promise<FinanceBooking | undefined> => {
|
|
41
|
+
const auth = await getAdminAuth();
|
|
42
|
+
const response: Response = await fetch(
|
|
43
|
+
`${process.env.CORE_API_ORIGIN}/api/documents/finance/${documentId}/booking`,
|
|
44
|
+
{
|
|
45
|
+
headers: {
|
|
46
|
+
Authorization: auth,
|
|
47
|
+
[TENANT_ID_ADMIN_HEADER]: tenantId,
|
|
48
|
+
},
|
|
49
|
+
}
|
|
50
|
+
);
|
|
51
|
+
|
|
52
|
+
if (response.status === 200) {
|
|
53
|
+
return response.json() as any;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const body = await response.text();
|
|
57
|
+
throw new XError('documents-sdk.get-finance-booking-fail', {
|
|
58
|
+
tenantId,
|
|
59
|
+
documentId,
|
|
60
|
+
response: body,
|
|
61
|
+
status: response.status,
|
|
62
|
+
});
|
|
63
|
+
};
|
|
64
|
+
|
|
8
65
|
export const upsertFinanceDoc = async (
|
|
9
66
|
tenantId: string,
|
|
10
67
|
doc: FinanceDocument
|
|
@@ -25,7 +82,7 @@ export const upsertFinanceDoc = async (
|
|
|
25
82
|
}
|
|
26
83
|
|
|
27
84
|
const body = await response.text();
|
|
28
|
-
throw new XError('
|
|
85
|
+
throw new XError('documents-sdk.upsert-finance-doc-fail', {
|
|
29
86
|
tenantId,
|
|
30
87
|
doc,
|
|
31
88
|
response: body,
|
|
@@ -56,7 +113,7 @@ export const upsertAdminDoc = async (
|
|
|
56
113
|
}
|
|
57
114
|
|
|
58
115
|
const body = await response.text();
|
|
59
|
-
throw new XError('
|
|
116
|
+
throw new XError('documents-sdk.upsert-admin-doc-fail', {
|
|
60
117
|
tenantId,
|
|
61
118
|
doc,
|
|
62
119
|
response: body,
|
|
@@ -87,7 +144,7 @@ export const upsertFinanceBooking = async (
|
|
|
87
144
|
}
|
|
88
145
|
|
|
89
146
|
const body = await response.text();
|
|
90
|
-
throw new XError('
|
|
147
|
+
throw new XError('documents-sdk.upsert-finance-booking-fail', {
|
|
91
148
|
tenantId,
|
|
92
149
|
booking,
|
|
93
150
|
response: body,
|
package/src/schemas.ts
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { BusinessEntityIds } from '@bisondesk/commons-sdk/constants';
|
|
2
|
+
import { attachmentValueSchema, getPhoneSchema } from '@bisondesk/commons/joi-schemas';
|
|
3
|
+
import { FinanceDocType } from '@bisondesk/documents-sdk/types/documents';
|
|
4
|
+
import Joi from 'joi';
|
|
5
|
+
|
|
6
|
+
const orgSummarySchema = Joi.object({
|
|
7
|
+
id: Joi.string().required(),
|
|
8
|
+
code: Joi.number().required(),
|
|
9
|
+
name: Joi.string().required(),
|
|
10
|
+
language: Joi.string().required(),
|
|
11
|
+
vatNumber: Joi.string(),
|
|
12
|
+
addressLine1: Joi.string(),
|
|
13
|
+
addressLine2: Joi.string(),
|
|
14
|
+
postcode: Joi.string(),
|
|
15
|
+
city: Joi.string(),
|
|
16
|
+
country: Joi.string().required(),
|
|
17
|
+
emails: Joi.array().items(Joi.string().email()),
|
|
18
|
+
phone: getPhoneSchema(),
|
|
19
|
+
contact: Joi.object({
|
|
20
|
+
name: Joi.string().required(),
|
|
21
|
+
username: Joi.string().required(),
|
|
22
|
+
}),
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
const associationsSchema = Joi.array().items(
|
|
26
|
+
Joi.object({
|
|
27
|
+
businessEntityId: Joi.string()
|
|
28
|
+
.valid(...Object.values(BusinessEntityIds))
|
|
29
|
+
.required(),
|
|
30
|
+
recordId: Joi.string().required(),
|
|
31
|
+
title: Joi.string().required(),
|
|
32
|
+
description: Joi.string().required(),
|
|
33
|
+
tags: Joi.array().items(Joi.string()),
|
|
34
|
+
})
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
export const lineSchema = Joi.object({
|
|
38
|
+
category: Joi.string().required(),
|
|
39
|
+
amount: Joi.string().required(),
|
|
40
|
+
amountExcl: Joi.string().required(),
|
|
41
|
+
description: Joi.string().required(),
|
|
42
|
+
foreign: Joi.object({
|
|
43
|
+
amount: Joi.string().required(),
|
|
44
|
+
amountExcl: Joi.string().required(),
|
|
45
|
+
unitPriceExcl: Joi.string().required(),
|
|
46
|
+
vatAmount: Joi.string().required(),
|
|
47
|
+
}),
|
|
48
|
+
invoiceLineId: Joi.string(),
|
|
49
|
+
quantity: Joi.string().required(),
|
|
50
|
+
associations: associationsSchema,
|
|
51
|
+
unitPriceExcl: Joi.string().required(),
|
|
52
|
+
vatAmount: Joi.string().required(),
|
|
53
|
+
vatCode: Joi.string().required(),
|
|
54
|
+
vatPercentage: Joi.string().required(),
|
|
55
|
+
vatReason: Joi.string(),
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
export const newFinanceDocV2Schema = Joi.object({
|
|
59
|
+
id: Joi.string(),
|
|
60
|
+
version: Joi.number().valid(2.0).required(),
|
|
61
|
+
reference: Joi.string().required(),
|
|
62
|
+
type: Joi.string()
|
|
63
|
+
.valid(...Object.values(FinanceDocType))
|
|
64
|
+
.required(),
|
|
65
|
+
subtype: Joi.string().required(),
|
|
66
|
+
attachment: attachmentValueSchema.required(),
|
|
67
|
+
branchId: Joi.string().required(),
|
|
68
|
+
category: Joi.string().required(),
|
|
69
|
+
organizationSummary: orgSummarySchema.required(),
|
|
70
|
+
dueDate: Joi.string(),
|
|
71
|
+
transferDescription: Joi.string(),
|
|
72
|
+
invoiceId: Joi.string(),
|
|
73
|
+
notes: Joi.string(),
|
|
74
|
+
salesperson: Joi.object({
|
|
75
|
+
name: Joi.string().required(),
|
|
76
|
+
username: Joi.string().required(),
|
|
77
|
+
}),
|
|
78
|
+
paidAt: Joi.string(),
|
|
79
|
+
tags: Joi.array().items(Joi.string()),
|
|
80
|
+
total: Joi.object({
|
|
81
|
+
amountExcl: Joi.string().required(),
|
|
82
|
+
amount: Joi.string().required(),
|
|
83
|
+
currencyCode: Joi.string().required(),
|
|
84
|
+
foreign: Joi.object({
|
|
85
|
+
amount: Joi.string().required(),
|
|
86
|
+
amountExcl: Joi.string().required(),
|
|
87
|
+
vatAmount: Joi.string().required(),
|
|
88
|
+
currencyCode: Joi.string().required(),
|
|
89
|
+
exchangeRate: Joi.string().required(),
|
|
90
|
+
}),
|
|
91
|
+
vatAmount: Joi.string().required(),
|
|
92
|
+
}),
|
|
93
|
+
issueDate: Joi.string().isoDate().required(),
|
|
94
|
+
lines: Joi.array().items(lineSchema).required(),
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
export const newAdministativedDocumentSchema = Joi.object({
|
|
98
|
+
id: Joi.string(),
|
|
99
|
+
displayName: Joi.string(),
|
|
100
|
+
branchId: Joi.string().required(),
|
|
101
|
+
attachment: attachmentValueSchema.required(),
|
|
102
|
+
category: Joi.string().empty(''),
|
|
103
|
+
tags: Joi.array().items(Joi.string()),
|
|
104
|
+
associations: associationsSchema,
|
|
105
|
+
organizationSummary: orgSummarySchema,
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
export const administativeDocumentSchema = newAdministativedDocumentSchema.keys({
|
|
109
|
+
id: Joi.string().required(),
|
|
110
|
+
createdAt: Joi.string().required(),
|
|
111
|
+
createdBy: Joi.string().required(),
|
|
112
|
+
});
|
package/src/types/booking.ts
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import { FinanceDocument } from './documents.js';
|
|
2
2
|
|
|
3
3
|
export type FinanceBookingEvent = {
|
|
4
|
-
id: string;
|
|
5
|
-
branchId: string;
|
|
6
4
|
actionAt: string;
|
|
7
5
|
userId: string;
|
|
8
6
|
tenantId: string;
|
|
9
7
|
type: 'Sale Finance' | 'Purchase Finance';
|
|
10
8
|
version: FinanceDocument['version'];
|
|
11
|
-
}
|
|
9
|
+
} & (
|
|
10
|
+
| { action: 'create'; booking: FinanceBooking; previousBooking?: undefined }
|
|
11
|
+
| { action: 'update'; booking: FinanceBooking; previousBooking: FinanceBooking }
|
|
12
|
+
);
|
|
12
13
|
|
|
13
14
|
export type FinanceBooking = {
|
|
14
15
|
branchId: string; // same tenantId can have different companies
|
|
@@ -5,29 +5,69 @@ export enum DocumentCategoryVisibility {
|
|
|
5
5
|
Private = 'private',
|
|
6
6
|
}
|
|
7
7
|
|
|
8
|
-
export
|
|
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
|
+
type: DocumentCategoryType;
|
|
13
18
|
title: string;
|
|
14
|
-
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export type AdministrativeDocumentCategory = BaseDocumentCategory & {
|
|
22
|
+
type: DocumentCategoryType.Administrative;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export type FinanceDocumentCategory = BaseDocumentCategory & {
|
|
26
|
+
type: DocumentCategoryType.Finance;
|
|
27
|
+
journal?: string;
|
|
28
|
+
costCenter: string;
|
|
15
29
|
visibility: DocumentCategoryVisibility;
|
|
16
|
-
|
|
30
|
+
transactionType: TransactionType;
|
|
17
31
|
validators?: string[];
|
|
18
32
|
};
|
|
19
33
|
|
|
20
|
-
export type
|
|
34
|
+
export type DocumentCategory = AdministrativeDocumentCategory | FinanceDocumentCategory;
|
|
35
|
+
|
|
36
|
+
export type NewDocumentCategory = (
|
|
37
|
+
| Omit<FinanceDocumentCategory, 'id' | 'createdAt'>
|
|
38
|
+
| Omit<AdministrativeDocumentCategory, 'id' | 'createdAt'>
|
|
39
|
+
) & {
|
|
40
|
+
createdAt?: undefined;
|
|
41
|
+
id?: undefined;
|
|
42
|
+
};
|
|
21
43
|
|
|
22
|
-
export type
|
|
44
|
+
export type FinanceDocumentLineCategory = {
|
|
23
45
|
createdAt: string;
|
|
24
46
|
branchId: string;
|
|
25
47
|
categoryId: string;
|
|
26
48
|
id: string;
|
|
27
|
-
code: string;
|
|
28
49
|
title: string;
|
|
29
50
|
description: string;
|
|
51
|
+
associationMandatory: boolean;
|
|
30
52
|
glAccount: string;
|
|
31
53
|
};
|
|
32
54
|
|
|
33
|
-
export type
|
|
55
|
+
export type NewFinanceDocumentLineCategory = Omit<FinanceDocumentLineCategory, 'id' | 'createdAt'>;
|
|
56
|
+
|
|
57
|
+
type BaseCostCenter = {
|
|
58
|
+
branchId: string;
|
|
59
|
+
name: string;
|
|
60
|
+
externalId?: string;
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
export type CostCenter = BaseCostCenter & {
|
|
64
|
+
createdAt: string;
|
|
65
|
+
createdBy: string;
|
|
66
|
+
id: string;
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
export type NewCostCenter = BaseCostCenter & {
|
|
70
|
+
createdAt?: undefined;
|
|
71
|
+
createdBy?: string;
|
|
72
|
+
id?: undefined;
|
|
73
|
+
};
|
package/src/types/documents.ts
CHANGED
|
@@ -1,20 +1,13 @@
|
|
|
1
|
-
import type { Block } from '@aws-sdk/client-textract';
|
|
2
1
|
import { BusinessEntityIds } from '@bisondesk/commons-sdk/constants';
|
|
3
2
|
import { AttachmentValue, PhoneNumberValue } from '@bisondesk/commons-sdk/types';
|
|
4
3
|
import { FinanceDocumentV1 } from './legacy.js';
|
|
5
4
|
|
|
6
|
-
export enum AdministrativeDocType {
|
|
7
|
-
General = 'General Administrative',
|
|
8
|
-
Logistics = 'Logistics Administrative',
|
|
9
|
-
Purchase = 'Purchase Administrative',
|
|
10
|
-
Sale = 'Sale Administrative',
|
|
11
|
-
}
|
|
12
|
-
|
|
13
5
|
export type FinanceDocument = FinanceDocumentV1 | FinanceDocumentV2;
|
|
14
6
|
|
|
15
7
|
export type Association = {
|
|
16
8
|
businessEntityId: BusinessEntityIds;
|
|
17
|
-
|
|
9
|
+
recordId: string;
|
|
10
|
+
title: string;
|
|
18
11
|
description: string;
|
|
19
12
|
tags?: string[];
|
|
20
13
|
};
|
|
@@ -70,16 +63,10 @@ export enum FinanceDocType {
|
|
|
70
63
|
Purchase = 'Purchase Finance',
|
|
71
64
|
}
|
|
72
65
|
|
|
73
|
-
export enum FinanceDocumentGenerateSubtype {
|
|
74
|
-
Invoice = 'Invoice',
|
|
75
|
-
CreditNote = 'Credit Note',
|
|
76
|
-
}
|
|
77
|
-
|
|
78
66
|
type BaseDocument = {
|
|
79
67
|
id: string;
|
|
80
68
|
branchId: string;
|
|
81
69
|
attachment: AttachmentValue;
|
|
82
|
-
subtype: string;
|
|
83
70
|
createdAt: string;
|
|
84
71
|
createdBy: string;
|
|
85
72
|
};
|
|
@@ -87,19 +74,18 @@ type BaseDocument = {
|
|
|
87
74
|
export type FinanceDocumentV2 = BaseDocument & {
|
|
88
75
|
version: 2.0;
|
|
89
76
|
reference: string;
|
|
90
|
-
|
|
77
|
+
subtype: FinanceDocumentSubtype;
|
|
91
78
|
type: FinanceDocType;
|
|
92
|
-
|
|
93
|
-
category: string; // abstraction used to map invoices to Journals (e.g., leasing, used trucks)
|
|
94
|
-
|
|
79
|
+
category: string;
|
|
95
80
|
organizationSummary: OrgSummary;
|
|
96
81
|
|
|
97
82
|
dueDate?: string;
|
|
98
83
|
transferDescription?: string; // we ask clients to put this as description of the transfer
|
|
99
84
|
invoiceId?: string; // mandatory in credit notes but forbidden in invoices
|
|
100
85
|
issueDate: string;
|
|
101
|
-
lines: FinanceDocumentLine[];
|
|
102
86
|
paymentNotes?: string;
|
|
87
|
+
lines: FinanceDocumentLine[];
|
|
88
|
+
accountingLines?: FinanceDocumentLine[];
|
|
103
89
|
notes?: string;
|
|
104
90
|
salesperson: {
|
|
105
91
|
name: string;
|
|
@@ -131,10 +117,10 @@ export type NewFinanceDocumentV2 = Omit<
|
|
|
131
117
|
};
|
|
132
118
|
|
|
133
119
|
export type AdministrativeDocument = BaseDocument & {
|
|
134
|
-
type: AdministrativeDocType;
|
|
135
120
|
tags?: string[];
|
|
121
|
+
category: string;
|
|
136
122
|
associations?: Association[];
|
|
137
|
-
|
|
123
|
+
displayName?: string;
|
|
138
124
|
};
|
|
139
125
|
|
|
140
126
|
export type NewAdministrativeDocument = Omit<
|
|
@@ -143,22 +129,21 @@ export type NewAdministrativeDocument = Omit<
|
|
|
143
129
|
>;
|
|
144
130
|
|
|
145
131
|
export enum DraftProcessStatus {
|
|
146
|
-
|
|
147
|
-
// Ready = 'Ready',
|
|
148
|
-
Error = 'Error',
|
|
149
|
-
Validated = 'Validated',
|
|
132
|
+
Prefill = 'Prefill',
|
|
150
133
|
Unprocessed = 'Unprocessed',
|
|
151
|
-
|
|
134
|
+
Processed = 'Processed',
|
|
135
|
+
BusinessValid = 'BusinessValid',
|
|
136
|
+
AccountingValid = 'AccountingValid',
|
|
137
|
+
Completed = 'Completed',
|
|
138
|
+
Rejected = 'Rejected',
|
|
152
139
|
}
|
|
153
140
|
|
|
154
141
|
type DraftProcessing = {
|
|
155
142
|
status: DraftProcessStatus;
|
|
156
|
-
businessValid: boolean;
|
|
157
|
-
accountingValid: boolean;
|
|
158
|
-
rejectedAt?: string;
|
|
159
|
-
rejectedBy?: string;
|
|
160
|
-
rejectionReason?: string;
|
|
161
143
|
failedValidationRules?: string[];
|
|
144
|
+
documentType?: DocumentType;
|
|
145
|
+
vatTotalCheck?: string;
|
|
146
|
+
totalCheck?: string;
|
|
162
147
|
};
|
|
163
148
|
|
|
164
149
|
export enum DocumentType {
|
|
@@ -166,17 +151,37 @@ export enum DocumentType {
|
|
|
166
151
|
Administrative = 'Administrative Document',
|
|
167
152
|
}
|
|
168
153
|
|
|
169
|
-
type
|
|
170
|
-
|
|
171
|
-
|
|
154
|
+
type DraftStatusLogEntry = {
|
|
155
|
+
at: string;
|
|
156
|
+
by: string;
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
type DraftStatusLog = { [key in DraftProcessStatus]?: DraftStatusLogEntry };
|
|
160
|
+
|
|
161
|
+
type BaseDocumentDraft = (BaseDocument & DraftProcessing) &
|
|
162
|
+
(
|
|
163
|
+
| {
|
|
164
|
+
status: Exclude<DraftProcessStatus, DraftProcessStatus.Rejected>;
|
|
165
|
+
}
|
|
166
|
+
| {
|
|
167
|
+
status: DraftProcessStatus.Rejected;
|
|
168
|
+
rejectedAt?: string;
|
|
169
|
+
rejectedBy?: string;
|
|
170
|
+
rejectionReason?: string;
|
|
171
|
+
}
|
|
172
|
+
) & {
|
|
173
|
+
log?: DraftStatusLog;
|
|
172
174
|
};
|
|
173
175
|
|
|
174
176
|
export type DocumentDraft<T = FinanceDocumentV2 | AdministrativeDocument> = Partial<T> &
|
|
175
177
|
BaseDocumentDraft;
|
|
176
178
|
|
|
179
|
+
export type DocumentDraftListMeta = { status: DraftProcessStatus; count: number }[];
|
|
180
|
+
|
|
177
181
|
export enum DraftActions {
|
|
178
182
|
Delete = 'delete',
|
|
179
183
|
Validate = 'validate',
|
|
184
|
+
Reject = 'reject',
|
|
180
185
|
Submit = 'submit',
|
|
181
186
|
ValidateBusinessRules = 'validate_business_rules',
|
|
182
187
|
ValidateAccountingRules = 'validate_accounting_rules',
|
|
@@ -187,7 +192,7 @@ export type RejectDraftRequest = {
|
|
|
187
192
|
};
|
|
188
193
|
|
|
189
194
|
export type NewDocumentDraft<T = NewFinanceDocumentV2 | NewAdministrativeDocument> = Partial<T> &
|
|
190
|
-
Omit<
|
|
195
|
+
Omit<BaseDocumentDraft, 'id' | 'createdAt' | 'createdBy' | 'subtype'> & {
|
|
191
196
|
subtype?: string;
|
|
192
197
|
documentType?: DocumentType;
|
|
193
198
|
};
|
|
@@ -204,18 +209,20 @@ export const isFinanceDocumentV1 = (
|
|
|
204
209
|
return (arg as FinanceDocumentV2).version == null;
|
|
205
210
|
};
|
|
206
211
|
|
|
207
|
-
export const
|
|
208
|
-
|
|
212
|
+
export const isFinanceDocument = (
|
|
213
|
+
arg: FinanceDocument | AdministrativeDocument | NewAdministrativeDocument | NewFinanceDocumentV2
|
|
214
|
+
): arg is FinanceDocument => {
|
|
215
|
+
return (arg as FinanceDocument).reference != null;
|
|
209
216
|
};
|
|
210
217
|
|
|
211
218
|
export const isAdministrativeDocumentDraft = (
|
|
212
|
-
draft: DocumentDraft
|
|
213
|
-
): draft is DocumentDraft<AdministrativeDocument> =>
|
|
219
|
+
draft: DocumentDraft | NewDocumentDraft
|
|
220
|
+
): draft is DocumentDraft<AdministrativeDocument> | NewDocumentDraft<AdministrativeDocument> =>
|
|
214
221
|
draft.documentType === DocumentType.Administrative;
|
|
215
222
|
|
|
216
223
|
export const isFinanceDocumentDraft = (
|
|
217
224
|
arg: DocumentDraft | NewDocumentDraft
|
|
218
|
-
): arg is DocumentDraft<FinanceDocumentV2> => {
|
|
225
|
+
): arg is DocumentDraft<FinanceDocumentV2> | NewDocumentDraft<FinanceDocumentV2> => {
|
|
219
226
|
return arg.documentType === DocumentType.Finance;
|
|
220
227
|
};
|
|
221
228
|
|
|
@@ -223,7 +230,7 @@ export type FinanceDocumentGenerateRequest = Omit<
|
|
|
223
230
|
FinanceDocumentV2,
|
|
224
231
|
'id' | 'attachment' | 'createdAt' | 'createdBy' | 'version' | 'reference' | 'lines' | 'subtype'
|
|
225
232
|
> & {
|
|
226
|
-
subtype:
|
|
233
|
+
subtype: FinanceDocumentSubtype;
|
|
227
234
|
lines: Omit<FinanceDocumentLine, 'id'>[];
|
|
228
235
|
};
|
|
229
236
|
|
|
@@ -240,11 +247,11 @@ export type FinanceDocumentSettings<M = {}> = {
|
|
|
240
247
|
};
|
|
241
248
|
|
|
242
249
|
export type FinanceDocumentBisondeskSettings = {
|
|
243
|
-
[
|
|
250
|
+
[FinanceDocumentSubtype.Invoice]: {
|
|
244
251
|
prefix: string;
|
|
245
252
|
templateId: string;
|
|
246
253
|
};
|
|
247
|
-
[
|
|
254
|
+
[FinanceDocumentSubtype.CreditNote]: {
|
|
248
255
|
prefix: string;
|
|
249
256
|
templateId: string;
|
|
250
257
|
};
|
|
@@ -262,13 +269,29 @@ export enum FinanceDocumentSubtype {
|
|
|
262
269
|
PurchaseOrder = 'Purchase Order',
|
|
263
270
|
}
|
|
264
271
|
|
|
265
|
-
export type OCRDocument = {
|
|
266
|
-
Blocks?: Block[];
|
|
267
|
-
orientation: number;
|
|
268
|
-
hasCurrency: boolean;
|
|
269
|
-
};
|
|
270
|
-
|
|
271
272
|
export enum FinanceDocumentActions {
|
|
272
273
|
PAY_FINANCE_DOCUMENT = 'pay_finance_document',
|
|
273
274
|
DELETE_FINANCE_DOCUMENT = 'delete_finance_document',
|
|
274
275
|
}
|
|
276
|
+
|
|
277
|
+
export enum AdministrativeDocumentActions {
|
|
278
|
+
DELETE_ADMINISTRATIVE_DOCUMENT = 'delete_finance_document',
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
export type AdministrativeUpdateOperation =
|
|
282
|
+
| {
|
|
283
|
+
doc: AdministrativeDocument;
|
|
284
|
+
op: 'replace';
|
|
285
|
+
}
|
|
286
|
+
| {
|
|
287
|
+
doc: NewAdministrativeDocument;
|
|
288
|
+
op: 'add';
|
|
289
|
+
}
|
|
290
|
+
| {
|
|
291
|
+
association: {
|
|
292
|
+
businessEntityId: BusinessEntityIds;
|
|
293
|
+
recordId: string;
|
|
294
|
+
documentId: string;
|
|
295
|
+
};
|
|
296
|
+
op: 'remove-association';
|
|
297
|
+
};
|