@bisondesk/documents-sdk 1.0.589 → 1.0.591

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.
@@ -1,290 +0,0 @@
1
- import { DEFAULT_EXACT_MATCH_BOOST } from '@bisondesk/commons/es';
2
- import { getTranslatedTitles } from '@bisondesk/commons/translations';
3
- import {
4
- EsAggregationsDefinition,
5
- EsDefinition,
6
- EsDefinitionField,
7
- EsFullTextSearchDefinition,
8
- SearchDefinition,
9
- SearchField,
10
- } from '@bisondesk/core-sdk/types/definitions';
11
- import { DateGranularity, FieldTypes } from '@bisondesk/core-sdk/types/fields';
12
- import { AggregationType } from '@bisondesk/core-sdk/types/search';
13
- import { UTCDate } from '@date-fns/utc';
14
- import { getTime, parseISO, setHours, setMinutes, setSeconds } from 'date-fns';
15
-
16
- const BASE_DOC_DRAFT_MAPPING_FIELDS: {
17
- [fieldId: string]: EsDefinitionField;
18
- } = {
19
- 'doc.id': {
20
- esMapping: { type: 'keyword', boost: DEFAULT_EXACT_MATCH_BOOST },
21
- },
22
- 'doc.status': {
23
- esMapping: { type: 'keyword' },
24
- },
25
- 'doc.documentType': {
26
- esMapping: { type: 'keyword' },
27
- },
28
- 'doc.category': {
29
- esMapping: { type: 'keyword' },
30
- },
31
- 'doc.branchId': {
32
- esMapping: { type: 'keyword' },
33
- },
34
- 'doc.attachment': {
35
- esMapping: { type: 'object', enabled: false },
36
- },
37
- 'doc.createdAt': {
38
- esMapping: { type: 'date' },
39
- },
40
- 'doc.createdBy': {
41
- esMapping: { type: 'keyword' },
42
- },
43
- 'custom.stage': {
44
- esMapping: { type: 'keyword' },
45
- },
46
- 'custom.rejected': {
47
- esMapping: { type: 'boolean' },
48
- },
49
- 'custom.validationRulesStatus': {
50
- esMapping: { type: 'keyword' },
51
- },
52
- 'custom.businessValidationAt': {
53
- esMapping: { type: 'date' },
54
- },
55
- };
56
-
57
- const FINANCE_DOC_DRAFT_MAPPING_FIELDS: {
58
- [fieldId: string]: EsDefinitionField;
59
- } = {
60
- 'doc.type': {
61
- esMapping: { type: 'keyword' },
62
- },
63
- 'doc.subtype': {
64
- esMapping: { type: 'keyword' },
65
- },
66
- 'doc.reference': {
67
- esMapping: { type: 'keyword', boost: DEFAULT_EXACT_MATCH_BOOST },
68
- },
69
- 'doc.issueDate': {
70
- esMapping: { type: 'date', ignore_malformed: true },
71
- },
72
- 'doc.dueDate': {
73
- esMapping: { type: 'date', ignore_malformed: true },
74
- },
75
-
76
- 'doc.organizationSummary.name': {
77
- esMapping: { type: 'text' },
78
- },
79
- 'doc.organizationSummary.id': {
80
- esMapping: { type: 'keyword' },
81
- },
82
- 'doc.organizationSummary.code': {
83
- esMapping: { type: 'keyword' },
84
- },
85
- 'doc.organizationSummary.vatNumber': {
86
- esMapping: { type: 'text' },
87
- },
88
-
89
- 'doc.lines.associations.businessEntityId': {
90
- esMapping: { type: 'keyword' },
91
- },
92
- 'doc.lines.associations.recordId': {
93
- esMapping: { type: 'keyword' },
94
- },
95
- 'doc.lines.associations.title': {
96
- esMapping: { type: 'text' },
97
- },
98
- 'doc.lines.associations.description': {
99
- esMapping: { type: 'text' },
100
- },
101
- 'doc.lines.associations.tags': {
102
- esMapping: { type: 'keyword' },
103
- },
104
- 'doc.invoiceId': {
105
- esMapping: { type: 'keyword' },
106
- },
107
- 'custom.validators': {
108
- esMapping: { type: 'keyword' },
109
- },
110
- 'custom.restrictedDraftUsers': {
111
- esMapping: { type: 'keyword' },
112
- },
113
- };
114
-
115
- const ADMIN_DOC_DRAFT_MAPPING_FIELDS: {
116
- [fieldId: string]: EsDefinitionField;
117
- } = {
118
- 'doc.tags': {
119
- esMapping: { type: 'text' },
120
- },
121
- 'doc.associations.businessEntityId': {
122
- esMapping: { type: 'keyword' },
123
- },
124
- 'doc.associations.recordId': {
125
- esMapping: { type: 'keyword' },
126
- },
127
- 'doc.associations.title': {
128
- esMapping: { type: 'text' },
129
- },
130
- 'doc.associations.description': {
131
- esMapping: { type: 'text' },
132
- },
133
- 'doc.associations.tags': {
134
- esMapping: { type: 'keyword' },
135
- },
136
- };
137
-
138
- export const DOC_DRAFT_MAPPING_FIELDS: {
139
- [fieldId: string]: EsDefinitionField;
140
- } = {
141
- ...BASE_DOC_DRAFT_MAPPING_FIELDS,
142
- ...FINANCE_DOC_DRAFT_MAPPING_FIELDS,
143
- ...ADMIN_DOC_DRAFT_MAPPING_FIELDS,
144
- };
145
-
146
- export const DOC_DRAFT_DEFINITION_FIELDS: {
147
- [fieldId: string]: SearchField;
148
- } = {
149
- 'doc.id': {
150
- id: 'doc.id',
151
- titles: getTranslatedTitles('id'),
152
- type: FieldTypes.text,
153
- },
154
- 'custom.stage': {
155
- id: 'custom.stage',
156
- titles: getTranslatedTitles('aggs.draft.stage'),
157
- type: FieldTypes.text,
158
- },
159
- 'doc.documentType': {
160
- id: 'doc.documentType',
161
- titles: getTranslatedTitles('aggs.draft.documentType'),
162
- type: FieldTypes.text,
163
- },
164
- 'doc.branchId': {
165
- id: 'doc.branchId',
166
- titles: getTranslatedTitles('branch'),
167
- type: FieldTypes.text,
168
- },
169
- 'doc.createdAt': {
170
- id: 'doc.createdAt',
171
- titles: getTranslatedTitles('aggs.creationDate'),
172
- type: FieldTypes.date,
173
- meta: {
174
- granularity: DateGranularity.yearMonthDayTime,
175
- },
176
- },
177
- 'custom.validationRulesStatus': {
178
- id: 'custom.validationRulesStatus',
179
- titles: getTranslatedTitles('aggs.draft.validationRules'),
180
- type: FieldTypes.text,
181
- },
182
- 'doc.createdBy': {
183
- id: 'doc.createdBy',
184
- titles: getTranslatedTitles('aggs.createdBy'),
185
- type: FieldTypes.collaborator,
186
- },
187
- // Finance fields
188
- 'doc.subtype': {
189
- id: 'doc.subtype',
190
- titles: getTranslatedTitles('type'),
191
- type: FieldTypes.text,
192
- },
193
- 'custom.rejected': {
194
- id: 'custom.rejected',
195
- titles: getTranslatedTitles('aggs.draft.rejected'),
196
- type: FieldTypes.checkbox,
197
- },
198
- 'custom.restrictedDraftUsers': {
199
- id: 'custom.restrictedDraftUsers',
200
- titles: getTranslatedTitles('agg.drafts.restrictedDraftUsers'),
201
- type: FieldTypes.text,
202
- },
203
- };
204
-
205
- export const getSearchDocumentDraftsAggs = (): EsAggregationsDefinition => [
206
- {
207
- titles: getTranslatedTitles('aggs.draft.stage'),
208
- fieldId: 'custom.stage',
209
- fieldType: FieldTypes.text,
210
- type: AggregationType.term,
211
- orderBy: 'count',
212
- },
213
- {
214
- titles: getTranslatedTitles('aggs.draft.documentType'),
215
- fieldId: 'doc.documentType',
216
- fieldType: FieldTypes.text,
217
- type: AggregationType.term,
218
- orderBy: 'count',
219
- },
220
- {
221
- titles: getTranslatedTitles('type'),
222
- fieldId: 'doc.subtype',
223
- fieldType: FieldTypes.text,
224
- type: AggregationType.term,
225
- orderBy: 'count',
226
- },
227
- {
228
- titles: getTranslatedTitles('aggs.draft.rejected'),
229
- fieldId: 'custom.rejected',
230
- fieldType: FieldTypes.checkbox,
231
- type: AggregationType.term,
232
- orderBy: 'count',
233
- },
234
- {
235
- titles: getTranslatedTitles('aggs.draft.validationRules'),
236
- fieldId: 'custom.validationRulesStatus',
237
- fieldType: FieldTypes.text,
238
- type: AggregationType.term,
239
- orderBy: 'count',
240
- },
241
- {
242
- titles: getTranslatedTitles('aggs.creationDate'),
243
- fieldId: 'doc.createdAt',
244
- step: 1,
245
- type: AggregationType.range,
246
- ranges: [
247
- {
248
- start: getTime(parseISO('2015-01-01')),
249
- end: getTime(setSeconds(setMinutes(setHours(new UTCDate(), 23), 59), 59)),
250
- },
251
- ],
252
- },
253
- {
254
- titles: getTranslatedTitles('aggs.draft.restrictedDraftUsers'),
255
- fieldId: 'custom.restrictedDraftUsers',
256
- fieldType: FieldTypes.text,
257
- type: AggregationType.term,
258
- orderBy: 'count',
259
- },
260
- ];
261
-
262
- export const SEARCH_DOC_DRAFT_FULL_TEXT_FIELDS: EsFullTextSearchDefinition = [
263
- // finance fields
264
- () => 'doc.id',
265
- () => 'doc.reference',
266
- () => 'doc.tags',
267
- () => 'doc.lines.associations.tags',
268
- // administrative fields
269
- () => 'doc.tags',
270
- () => 'doc.associations.tags',
271
- // OrgSummary fields
272
- () => 'doc.organizationSummary.name',
273
- () => 'doc.organizationSummary.id',
274
- () => 'doc.organizationSummary.code',
275
- () => 'doc.organizationSummary.vatNumber',
276
- ];
277
-
278
- export const SEARCH_DOC_DRAFTS_MAPPINGS: EsDefinition = {
279
- name: 'document_drafts',
280
- nestedEsPaths: [],
281
- fields: {
282
- ...DOC_DRAFT_MAPPING_FIELDS,
283
- },
284
- };
285
-
286
- export const SEARCH_DOC_DRAFTS_DEFINITION: SearchDefinition = {
287
- fields: {
288
- ...DOC_DRAFT_DEFINITION_FIELDS,
289
- },
290
- };
package/src/schemas.ts DELETED
@@ -1,144 +0,0 @@
1
- import { BusinessEntityIds } from '@bisondesk/commons-sdk/constants';
2
- import {
3
- attachmentValueSchema,
4
- getPhoneSchema,
5
- isoDateSchema,
6
- } from '@bisondesk/commons/joi-schemas';
7
- import { FinanceDocType } from '@bisondesk/documents-sdk/types/documents';
8
- import Joi from 'joi';
9
-
10
- const orgSummarySchema = Joi.object({
11
- id: Joi.string().required(),
12
- code: Joi.number().required(),
13
- name: Joi.string().empty('').required(),
14
- language: Joi.string().empty(''),
15
- vatNumber: Joi.string().empty(''),
16
- addressLine1: Joi.string().empty(''),
17
- addressLine2: Joi.string().empty(''),
18
- postcode: Joi.string().empty(''),
19
- city: Joi.string().empty(''),
20
- country: Joi.string().required(),
21
- emails: Joi.array().items(Joi.string().empty('').email()),
22
- phone: getPhoneSchema(),
23
- contact: Joi.object({
24
- name: Joi.string().empty('').required(),
25
- username: Joi.string().empty('').required(),
26
- }),
27
- });
28
-
29
- const associationsSchema = Joi.array().items(
30
- Joi.object({
31
- businessEntityId: Joi.string()
32
- .valid(...Object.values(BusinessEntityIds))
33
- .required(),
34
- recordId: Joi.string().required(),
35
- title: Joi.string().required(),
36
- description: Joi.string().required(),
37
- tags: Joi.array().items(Joi.string().empty('')),
38
- linkTo: Joi.object({
39
- businessEntityId: Joi.string().required(),
40
- recordId: Joi.string().required(),
41
- }),
42
- }),
43
- );
44
-
45
- export const lineSchema = Joi.object({
46
- category: Joi.string().required(),
47
- amount: Joi.number().cast('string').required(),
48
- amountExcl: Joi.number().cast('string').required(),
49
- description: Joi.string().required(),
50
- foreign: Joi.object({
51
- amount: Joi.number().cast('string').required(),
52
- amountExcl: Joi.number().cast('string').required(),
53
- unitPriceExcl: Joi.number().cast('string').required(),
54
- vatAmount: Joi.number().cast('string').required(),
55
- }),
56
- invoiceLineId: Joi.string().empty('').uuid(),
57
- quantity: Joi.number().min(0).cast('string').required(),
58
- associations: associationsSchema,
59
- unitPriceExcl: Joi.number().cast('string').required(),
60
- vatAmount: Joi.number().cast('string').required(),
61
- vatCode: Joi.string().required(),
62
- vatPercentage: Joi.number().min(0).cast('string').required(),
63
- vatReason: Joi.string().empty(''),
64
- costCenterId: Joi.string().empty(''),
65
- });
66
-
67
- export const newFinanceDocV2Schema = Joi.object({
68
- id: Joi.string().uuid(),
69
- version: Joi.number().valid(2.0).default(2.0),
70
- reference: Joi.string().required(),
71
- type: Joi.string()
72
- .valid(...Object.values(FinanceDocType))
73
- .required(),
74
- subtype: Joi.string().required(),
75
- attachment: attachmentValueSchema.required(),
76
- branchId: Joi.string().required(),
77
- category: Joi.string().required(),
78
- organizationSummary: orgSummarySchema.required(),
79
- transferDescription: Joi.string().empty(''),
80
- invoiceId: Joi.string().uuid().empty(''),
81
- notes: Joi.string().empty(''),
82
- salesperson: Joi.object({
83
- name: Joi.string().required(),
84
- username: Joi.string().required(),
85
- }),
86
- paidAt: Joi.string().empty(''),
87
- tags: Joi.array().items(Joi.string().empty('')),
88
- total: Joi.object({
89
- amountExcl: Joi.number().min(0).cast('string').required(),
90
- amount: Joi.number().min(0).cast('string').required(),
91
- currencyCode: Joi.string().required(),
92
- foreign: Joi.object({
93
- amount: Joi.number().min(0).cast('string').required(),
94
- amountExcl: Joi.number().min(0).cast('string').required(),
95
- vatAmount: Joi.number().min(0).cast('string').required(),
96
- currencyCode: Joi.string().required(),
97
- exchangeRate: Joi.number().min(0).cast('string').required(),
98
- }),
99
- vatAmount: Joi.number().min(0).cast('string').required(),
100
- }),
101
- issueDate: isoDateSchema.required(),
102
- dueDate: isoDateSchema.empty(''),
103
- lines: Joi.array().items(lineSchema).required().default([]),
104
- reportingYear: Joi.number().min(0).cast('string'),
105
- reportingPeriod: Joi.number().min(0).cast('string'),
106
- accountingDescription: Joi.string().empty(''),
107
- peppol: Joi.object({
108
- extraAttachments: Joi.array()
109
- .items(
110
- attachmentValueSchema.keys({
111
- contentType: Joi.string().valid('application/pdf').required(),
112
- }),
113
- )
114
- .max(9),
115
- additionalItemProperties: Joi.array().items(
116
- Joi.object({
117
- lineId: Joi.string().required(),
118
- properties: Joi.array().items(
119
- Joi.object({
120
- name: Joi.string().required(),
121
- value: Joi.string().required(),
122
- }),
123
- ),
124
- }),
125
- ),
126
- }),
127
- });
128
-
129
- export const newAdministrativedDocumentSchema = Joi.object({
130
- id: Joi.string(),
131
- displayName: Joi.string().empty(''),
132
- branchId: Joi.string().required(),
133
- attachment: attachmentValueSchema.required(),
134
- category: Joi.string().empty(''),
135
- tags: Joi.array().items(Joi.string().empty('')),
136
- associations: associationsSchema,
137
- organizationSummary: orgSummarySchema,
138
- });
139
-
140
- export const AdministrativeDocumentSchema = newAdministrativedDocumentSchema.keys({
141
- id: Joi.string().required(),
142
- createdAt: Joi.string().required(),
143
- createdBy: Joi.string().required(),
144
- });