@bisondesk/documents-sdk 1.0.588 → 1.0.590

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 (55) hide show
  1. package/lib/apis/document-drafts.js.map +1 -1
  2. package/lib/apis/documents-search.js.map +1 -1
  3. package/lib/apis/documents.js.map +1 -1
  4. package/lib/constants/search.d.ts +473 -9
  5. package/lib/constants/search.d.ts.map +1 -1
  6. package/lib/constants/search.js +0 -18
  7. package/lib/constants/search.js.map +1 -1
  8. package/lib/types/ai.js.map +1 -1
  9. package/lib/types/documents.js.map +1 -1
  10. package/lib/utils/associations.js.map +1 -1
  11. package/lib/utils/finance-legacy.d.ts.map +1 -1
  12. package/lib/utils/finance-legacy.js.map +1 -1
  13. package/lib/utils/finance.js.map +1 -1
  14. package/lib/utils/vat.js.map +1 -1
  15. package/lib/utils/visibility.js.map +1 -1
  16. package/package.json +14 -10
  17. package/src/apis/document-drafts.ts +20 -20
  18. package/src/apis/documents-search.ts +2 -2
  19. package/src/apis/documents.ts +14 -14
  20. package/src/constants/index.js +45 -0
  21. package/src/constants/index.js.map +1 -0
  22. package/src/constants/search.js +240 -0
  23. package/src/constants/search.js.map +1 -0
  24. package/src/types/ai.ts +1 -1
  25. package/src/types/bank-accounts.js +2 -0
  26. package/src/types/bank-accounts.js.map +1 -0
  27. package/src/types/booking.js +2 -0
  28. package/src/types/booking.js.map +1 -0
  29. package/src/types/document-categories.js +11 -0
  30. package/src/types/document-categories.js.map +1 -0
  31. package/src/types/documents.js +68 -0
  32. package/src/types/documents.js.map +1 -0
  33. package/src/types/documents.ts +5 -5
  34. package/src/types/legacy.js +2 -0
  35. package/src/types/legacy.js.map +1 -0
  36. package/src/types/rules.js +15 -0
  37. package/src/types/rules.js.map +1 -0
  38. package/src/types/search.js +13 -0
  39. package/src/types/search.js.map +1 -0
  40. package/src/types/vat.js +2 -0
  41. package/src/types/vat.js.map +1 -0
  42. package/src/utils/associations.ts +3 -3
  43. package/src/utils/finance-legacy.ts +7 -7
  44. package/src/utils/finance.ts +20 -20
  45. package/src/utils/previews.js +2 -0
  46. package/src/utils/previews.js.map +1 -0
  47. package/src/utils/vat.ts +5 -5
  48. package/src/utils/visibility.ts +1 -1
  49. package/tsconfig.tsbuildinfo +1 -1
  50. package/lib/schemas.d.ts +0 -6
  51. package/lib/schemas.d.ts.map +0 -1
  52. package/lib/schemas.js +0 -127
  53. package/lib/schemas.js.map +0 -1
  54. package/src/constants/search.ts +0 -290
  55. package/src/schemas.ts +0 -144
@@ -5,8 +5,8 @@ import {
5
5
  FinanceDocumentSubtype,
6
6
  NewFinanceDocumentLine,
7
7
  } from '../types/documents.js';
8
- import { FinanceLineV1 } from '../types/legacy.js';
9
8
  import { LeasingFinanceLineCode } from '../types/leasing.js';
9
+ import { FinanceLineV1 } from '../types/legacy.js';
10
10
  import { VatCode } from '../types/vat.js';
11
11
  import { getAssociationForBusinessEntity, SupportedAssociationEntity } from './associations.js';
12
12
  import { getLineAmounts } from './finance.js';
@@ -26,7 +26,7 @@ const hasValidLeasingLineCode = (code: string) =>
26
26
  const mapFinanceDocumentLineToMappedLine = (
27
27
  subtype: FinanceDocumentSubtype,
28
28
  line: FinanceDocumentLine,
29
- vatCodes: VatCode[] = []
29
+ vatCodes: VatCode[] = [],
30
30
  ): MappedFinanceLine => {
31
31
  const vatCode = vatCodes.find((c) => c.code === line.vatCode);
32
32
  const vatData = getVatCodeLineData(subtype, vatCode);
@@ -42,7 +42,7 @@ const mapFinanceDocumentLineToMappedLine = (
42
42
  const mapFinanceLineV1ToMappedLine = (
43
43
  subtype: FinanceDocumentSubtype,
44
44
  line: FinanceLineV1,
45
- vatCodes: VatCode[]
45
+ vatCodes: VatCode[],
46
46
  ): MappedFinanceLine => {
47
47
  const v2Code = getAccountingCodeForV1VatCode(line.vatCode);
48
48
  const vatCode = vatCodes.find((c) => c.code === v2Code);
@@ -70,7 +70,7 @@ const mapFinanceLineV1ToMappedLine = (
70
70
  export const mapFinanceLine = (
71
71
  subtype: FinanceDocumentSubtype,
72
72
  line: FinanceLine,
73
- vatCodes: VatCode[] = []
73
+ vatCodes: VatCode[] = [],
74
74
  ): MappedFinanceLine => {
75
75
  return isV1Line(line)
76
76
  ? mapFinanceLineV1ToMappedLine(subtype, line, vatCodes)
@@ -88,7 +88,7 @@ export const getExternalSaleVehicleIds = (lines: MappedFinanceLine[]): string[]
88
88
  ...(line.associations
89
89
  ?.filter(
90
90
  ({ businessEntityId, tags }) =>
91
- BusinessEntityIds.ExternalVehicleSale === businessEntityId && tags == null
91
+ BusinessEntityIds.ExternalVehicleSale === businessEntityId && tags == null,
92
92
  )
93
93
  .map(({ recordId, linkTo }) => linkTo?.recordId ?? recordId) ?? []),
94
94
  ];
@@ -100,7 +100,7 @@ export const getExternalSaleVehicleIds = (lines: MappedFinanceLine[]): string[]
100
100
  */
101
101
  export const enrichLinesWithVehicleTags = <T extends MappedFinanceLine>(
102
102
  lines: T[],
103
- vehicleMap: Map<string, SupportedAssociationEntity>
103
+ vehicleMap: Map<string, SupportedAssociationEntity>,
104
104
  ): T[] =>
105
105
  lines.map((line) => ({
106
106
  ...line,
@@ -118,7 +118,7 @@ export const enrichLinesWithVehicleTags = <T extends MappedFinanceLine>(
118
118
  }
119
119
  const vehicleAssociation = getAssociationForBusinessEntity(
120
120
  BusinessEntityIds.Vehicles,
121
- vehicle
121
+ vehicle,
122
122
  );
123
123
  return {
124
124
  ...association,
@@ -23,12 +23,12 @@ export const documentGoesToAccounting = (
23
23
  | FinanceDocumentV2
24
24
  | DocumentDraft<FinanceDocumentV2>
25
25
  | FinanceDocumentGenerateRequest
26
- | FinanceDocumentV1
26
+ | FinanceDocumentV1,
27
27
  ): boolean => {
28
28
  return (
29
29
  !!doc.subtype &&
30
30
  [FinanceDocumentSubtype.Invoice, FinanceDocumentSubtype.CreditNote].includes(
31
- doc.subtype as FinanceDocumentSubtype
31
+ doc.subtype as FinanceDocumentSubtype,
32
32
  )
33
33
  );
34
34
  };
@@ -38,7 +38,7 @@ export const documentGoesToStorecove = (
38
38
  | FinanceDocumentV2
39
39
  | DocumentDraft<FinanceDocumentV2>
40
40
  | FinanceDocumentGenerateRequest
41
- | FinanceDocumentV1
41
+ | FinanceDocumentV1,
42
42
  ): boolean => {
43
43
  if (!doc.organizationSummary) {
44
44
  return false;
@@ -65,7 +65,7 @@ export const getAccountingDescription = (doc: FinanceDocumentV2): string => {
65
65
 
66
66
  const uniqueAssociations = uniqBy(
67
67
  associations,
68
- (a) => `${equivalentEntityIds[a.businessEntityId] ?? a.businessEntityId}_${a.recordId}`
68
+ (a) => `${equivalentEntityIds[a.businessEntityId] ?? a.businessEntityId}_${a.recordId}`,
69
69
  );
70
70
 
71
71
  if (uniqueAssociations.length !== 1) {
@@ -89,7 +89,7 @@ export const getAccountingDescription = (doc: FinanceDocumentV2): string => {
89
89
 
90
90
  export const getTotalExcl = <T extends FinanceDocument['lines']>(
91
91
  lines: T,
92
- unitPrice: (line: T[0], index: number) => any
92
+ unitPrice: (line: T[0], index: number) => any,
93
93
  ) => {
94
94
  return lines.length === 0
95
95
  ? new Decimal(0)
@@ -100,7 +100,7 @@ export const getTotalVat = <T extends FinanceDocument['lines'], L = T[0]>(
100
100
  currency: string,
101
101
  lines: T,
102
102
  unitPrice: (doc: L, index: number) => any,
103
- vatCoefficient: (doc: L, index: number) => any
103
+ vatCoefficient: (doc: L, index: number) => any,
104
104
  ) => {
105
105
  return lines.length === 0
106
106
  ? new Decimal(0)
@@ -108,9 +108,9 @@ export const getTotalVat = <T extends FinanceDocument['lines'], L = T[0]>(
108
108
  currency,
109
109
  Decimal.sum(
110
110
  ...lines.map((line, i) =>
111
- Decimal.mul(line.quantity, unitPrice(line, i)).mul(vatCoefficient(line, i))
112
- )
113
- )
111
+ Decimal.mul(line.quantity, unitPrice(line, i)).mul(vatCoefficient(line, i)),
112
+ ),
113
+ ),
114
114
  );
115
115
  };
116
116
 
@@ -119,7 +119,7 @@ export const getDocumentTotals = (
119
119
  | FinanceDocument
120
120
  | DocumentDraft<FinanceDocumentV2>
121
121
  | NewDocumentDraft<FinanceDocumentV2>
122
- | FinanceDocumentGenerateRequest
122
+ | FinanceDocumentGenerateRequest,
123
123
  ) => {
124
124
  let totalVat: Decimal;
125
125
  let totalExcl: Decimal;
@@ -138,7 +138,7 @@ export const getDocumentTotals = (
138
138
  const getUnitPriceExcl = (line: FinanceDocumentLine) => line.unitPriceExcl;
139
139
 
140
140
  totalVat = getTotalVat(currency, lines, getUnitPriceExcl, (line) =>
141
- new Decimal(line.vatPercentage).div(100)
141
+ new Decimal(line.vatPercentage).div(100),
142
142
  );
143
143
  totalExcl = getTotalExcl(lines, getUnitPriceExcl);
144
144
  }
@@ -155,7 +155,7 @@ export const getRoundedDocumentTotal = (
155
155
  | FinanceDocument
156
156
  | DocumentDraft<FinanceDocumentV2>
157
157
  | NewDocumentDraft<FinanceDocumentV2>
158
- | FinanceDocumentGenerateRequest
158
+ | FinanceDocumentGenerateRequest,
159
159
  ) => {
160
160
  let total: FinanceDocumentV2['total'] | undefined;
161
161
 
@@ -192,7 +192,7 @@ export const getRoundedDocumentTotal = (
192
192
  export const getRoundedLinesTotals = (
193
193
  currency: string,
194
194
  lines: { quantity: string; unitPriceExcl: string; vatPercentage: string }[],
195
- rate = '1'
195
+ rate = '1',
196
196
  ) => {
197
197
  let totalWithoutVat = new Decimal('0');
198
198
  let vatTotal = new Decimal('0');
@@ -237,14 +237,14 @@ export const isGeneratingAttachment = (doc: FinanceDocument) =>
237
237
  // - the unit price is divided by the number of associations
238
238
  export const filterDocumentLinesForRecord = (
239
239
  doc: FinanceDocument,
240
- recordId: string // vehicleId, opportunityId, or externalVehicleSaleId
240
+ recordId: string, // vehicleId, opportunityId, or externalVehicleSaleId
241
241
  ): FinanceDocument => {
242
242
  const filteredLines = isFinanceDocumentV2(doc)
243
243
  ? doc.lines
244
244
  .filter((line) =>
245
245
  line.associations?.some(
246
- (assoc) => assoc.recordId === recordId || assoc.linkTo?.recordId === recordId
247
- )
246
+ (assoc) => assoc.recordId === recordId || assoc.linkTo?.recordId === recordId,
247
+ ),
248
248
  )
249
249
  .map((line) => ({
250
250
  ...line,
@@ -252,7 +252,7 @@ export const filterDocumentLinesForRecord = (
252
252
  amountExcl: calculateDistributedPrice(line.amountExcl, line.associations?.length || 1),
253
253
  unitPriceExcl: calculateDistributedPrice(
254
254
  line.unitPriceExcl,
255
- line.associations?.length || 1
255
+ line.associations?.length || 1,
256
256
  ),
257
257
  }))
258
258
  : doc.lines
@@ -264,13 +264,13 @@ export const filterDocumentLinesForRecord = (
264
264
  v1Ass.opportunityId === recordId ||
265
265
  v1Ass.id === recordId
266
266
  );
267
- })
267
+ }),
268
268
  )
269
269
  .map((line) => ({
270
270
  ...line,
271
271
  unitPriceExclusive: calculateDistributedPrice(
272
272
  line.unitPriceExclusive,
273
- getAllV1Associations(line.associations).length || 1
273
+ getAllV1Associations(line.associations).length || 1,
274
274
  ),
275
275
  }));
276
276
 
@@ -287,7 +287,7 @@ const calculateDistributedPrice = (price: string, count: number): string => {
287
287
  const getAllV1Associations = (ass: FinanceLineV1['associations']) => {
288
288
  const allAss = uniqBy(
289
289
  [...(ass?.sales ?? []), ...(ass?.purchases ?? []), ...(ass.others ?? [])],
290
- (ass) => ass.vehicleId
290
+ (ass) => ass.vehicleId,
291
291
  );
292
292
  return allAss;
293
293
  };
@@ -0,0 +1,2 @@
1
+ export const getPdfPreviewSrc = (fileUrl) => fileUrl.replace('.pdf', '/1.jpg');
2
+ //# sourceMappingURL=previews.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"previews.js","sourceRoot":"","sources":["previews.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,OAAe,EAAE,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC"}
package/src/utils/vat.ts CHANGED
@@ -9,7 +9,7 @@ import { VatCode } from '../types/vat.js';
9
9
 
10
10
  export const getVatCodeLineData = (
11
11
  subtype: FinanceDocumentSubtype,
12
- vatCode: VatCode | undefined
12
+ vatCode: VatCode | undefined,
13
13
  ) => {
14
14
  const reason =
15
15
  subtype === FinanceDocumentSubtype.CreditNote
@@ -39,7 +39,7 @@ export const getAccountingCodeForV1VatCode = (vatCode: string): string | undefin
39
39
  export const getSaleVatCodeForCustomer = (
40
40
  branchCountry: string,
41
41
  customerCountry: string,
42
- vatCodes: VatCode[]
42
+ vatCodes: VatCode[],
43
43
  ) => {
44
44
  const isSameCountry = branchCountry.toUpperCase() === customerCountry.toUpperCase();
45
45
  const isSaleInEU = isEUCountry(customerCountry);
@@ -47,8 +47,8 @@ export const getSaleVatCodeForCustomer = (
47
47
  isSameCountry || !branchCountry
48
48
  ? STANDARD_VAT_CODE_ID
49
49
  : isSaleInEU
50
- ? SALE_EU_INTRA_COMMUNITY_VAT_CODE_ID
51
- : SALE_EU_EXTRA_COMMUNITY_VAT_CODE_ID;
50
+ ? SALE_EU_INTRA_COMMUNITY_VAT_CODE_ID
51
+ : SALE_EU_EXTRA_COMMUNITY_VAT_CODE_ID;
52
52
 
53
53
  const vatCode = vatCodes?.find((code) => code.id === vatCodeId);
54
54
  return vatCode;
@@ -58,7 +58,7 @@ export const getSaleVatCodeDataForCustomer = (
58
58
  subtype: FinanceDocumentSubtype,
59
59
  branchCountry: string,
60
60
  customerCountry: string,
61
- vatCodes: VatCode[]
61
+ vatCodes: VatCode[],
62
62
  ) => {
63
63
  const vatCode = getSaleVatCodeForCustomer(branchCountry, customerCountry, vatCodes);
64
64
  return getVatCodeLineData(subtype, vatCode);
@@ -7,5 +7,5 @@ export const isPrivateVisibility = (
7
7
  | DocumentCategory
8
8
  | FinanceDocumentV1
9
9
  | FinanceDocumentV2
10
- | DocumentDraft<FinanceDocumentV2>
10
+ | DocumentDraft<FinanceDocumentV2>,
11
11
  ) => 'visibility' in catOrDoc && catOrDoc.visibility === DocumentCategoryVisibility.Private;