@bisondesk/core-sdk 1.0.319 → 1.0.321

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 (48) hide show
  1. package/lib/apis/crm.d.ts +5 -0
  2. package/lib/apis/crm.d.ts.map +1 -1
  3. package/lib/apis/crm.js +20 -0
  4. package/lib/apis/crm.js.map +1 -1
  5. package/lib/apis/opportunities.d.ts +1 -0
  6. package/lib/apis/opportunities.d.ts.map +1 -1
  7. package/lib/apis/opportunities.js +9 -0
  8. package/lib/apis/opportunities.js.map +1 -1
  9. package/lib/apis/picklists.d.ts +2 -1
  10. package/lib/apis/picklists.d.ts.map +1 -1
  11. package/lib/apis/picklists.js +16 -0
  12. package/lib/apis/picklists.js.map +1 -1
  13. package/lib/constants.d.ts +2 -0
  14. package/lib/constants.d.ts.map +1 -1
  15. package/lib/constants.js +2 -0
  16. package/lib/constants.js.map +1 -1
  17. package/lib/types/crm.d.ts +3 -2
  18. package/lib/types/crm.d.ts.map +1 -1
  19. package/lib/types/crm.js.map +1 -1
  20. package/lib/types/internet-opportunities.d.ts +2 -1
  21. package/lib/types/internet-opportunities.d.ts.map +1 -1
  22. package/lib/types/internet-opportunities.js.map +1 -1
  23. package/lib/types/leasing-administration.d.ts +1 -0
  24. package/lib/types/leasing-administration.d.ts.map +1 -1
  25. package/lib/types/leasing-administration.js.map +1 -1
  26. package/lib/types/picklists.d.ts +6 -0
  27. package/lib/types/picklists.d.ts.map +1 -1
  28. package/lib/types/picklists.js.map +1 -1
  29. package/lib/types/search.d.ts +16 -3
  30. package/lib/types/search.d.ts.map +1 -1
  31. package/lib/types/search.js.map +1 -1
  32. package/lib/utils/search.d.ts +33 -0
  33. package/lib/utils/search.d.ts.map +1 -0
  34. package/lib/utils/search.js +64 -0
  35. package/lib/utils/search.js.map +1 -0
  36. package/package.json +1 -1
  37. package/src/apis/crm.ts +30 -0
  38. package/src/apis/opportunities.ts +13 -0
  39. package/src/apis/picklists.ts +23 -0
  40. package/src/constants.ts +2 -0
  41. package/src/types/crm.ts +5 -2
  42. package/src/types/internet-opportunities.ts +2 -1
  43. package/src/types/leasing-administration.ts +2 -1
  44. package/src/types/picklists.ts +7 -0
  45. package/src/types/search.ts +17 -3
  46. package/src/utils/search.ts +130 -0
  47. package/tsconfig.deploy.tsbuildinfo +1 -1
  48. package/tsconfig.tsbuildinfo +1 -1
@@ -0,0 +1,130 @@
1
+ import { joinWithSeparator } from '@bisondesk/commons-sdk/formatting';
2
+ import { BusinessEntityIds } from '../constants.js';
3
+ import { Contact, Organization, SearchOrganization } from '../types/crm.js';
4
+ import { SearchLeasingContract } from '../types/leasing-search.js';
5
+ import { LeasingContract } from '../types/leasing.js';
6
+ import { Opportunity, SearchOpportunity } from '../types/opportunities.js';
7
+ import { SearchVehicle, Vehicle } from '../types/vehicles.js';
8
+
9
+ export type GlobalBusinessEntity = Opportunity | Vehicle | Organization | LeasingContract;
10
+ export type GlobalSearchEntity =
11
+ | SearchOpportunity
12
+ | SearchVehicle
13
+ | SearchOrganization
14
+ | SearchLeasingContract;
15
+
16
+ export const getCustomerInformation = (org?: Organization, contact?: Contact) => {
17
+ if (org != null) {
18
+ return {
19
+ countryCode: org.countryCode,
20
+ title: org.name,
21
+ code: org.externalId,
22
+ };
23
+ }
24
+
25
+ if (contact != null) {
26
+ return {
27
+ countryCode: contact.countryCode,
28
+ title: [contact?.firstName, contact?.lastName].filter(Boolean).join(' '),
29
+ };
30
+ }
31
+ };
32
+
33
+ export const mappings: {
34
+ [key in BusinessEntityIds]?: {
35
+ getMainEntity: (entity: any) => GlobalBusinessEntity;
36
+ getTitle: (entity: any) => string;
37
+ getTags: (entity: any) => (string | undefined)[];
38
+ getDescription?: (entity: any) => string;
39
+ };
40
+ } = {
41
+ [BusinessEntityIds.Opportunities]: {
42
+ getMainEntity: (entity: SearchOpportunity) => entity.opportunity,
43
+ getTitle: (opp: Opportunity) => opp.id,
44
+ getDescription: (opp: SearchOpportunity) =>
45
+ joinWithSeparator(
46
+ [
47
+ getCustomerInformation(opp.org, opp.contact)?.code,
48
+ opp.vehicle?.external.identification.stockNumber,
49
+ ].filter(Boolean)
50
+ ),
51
+ getTags: (opp: Opportunity) => [opp.id],
52
+ },
53
+ [BusinessEntityIds.Vehicles]: {
54
+ getMainEntity: (entity: SearchVehicle) => entity.vehicle,
55
+ getTitle: (vehicle: Vehicle) => vehicle.internal.description.title,
56
+ getTags: (vehicle: Vehicle) => [
57
+ vehicle.external.identification?.stockNumber,
58
+ vehicle.internal.identification?.administrativeNumber,
59
+ ],
60
+ },
61
+ [BusinessEntityIds.Organizations]: {
62
+ getMainEntity: (entity: SearchOrganization) => entity.org,
63
+ getTitle: (org: Organization) => org.name,
64
+ getTags: (org: Organization) => [`${org.externalId}`, org.vatNumber],
65
+ },
66
+ [BusinessEntityIds.LeasingContracts]: {
67
+ getMainEntity: (entity: SearchLeasingContract) => entity.contract,
68
+ getTitle: (contract: LeasingContract) => contract.contractNumber ?? contract.id,
69
+ getTags: (contract: LeasingContract) => [contract.contractNumber, contract.slbPartner],
70
+ },
71
+ };
72
+
73
+ const getMapping = (businessEntityId: BusinessEntityIds) => {
74
+ const mapping = mappings[businessEntityId];
75
+ if (!mapping) {
76
+ throw new Error(`Invalid business entity id ${businessEntityId}`);
77
+ }
78
+ return mapping;
79
+ };
80
+
81
+ export const getTagsForBusinessEntity = (
82
+ businessEntityId: BusinessEntityIds,
83
+ entity: GlobalBusinessEntity
84
+ ): string[] => getMapping(businessEntityId).getTags(entity).filter(Boolean) as string[];
85
+
86
+ export const getTagsForSearchBusinessEntity = (
87
+ businessEntityId: BusinessEntityIds,
88
+ entity: GlobalSearchEntity
89
+ ) =>
90
+ getTagsForBusinessEntity(
91
+ businessEntityId,
92
+ getMainEntityFromSearchEntity(businessEntityId, entity)
93
+ );
94
+
95
+ export const getDescriptionForBusinessEntity = (
96
+ businessEntityId: BusinessEntityIds,
97
+ entity: GlobalBusinessEntity
98
+ ) => joinWithSeparator(getTagsForBusinessEntity(businessEntityId, entity));
99
+
100
+ export const getDescriptionForSearchBusinessEntity = (
101
+ businessEntityId: BusinessEntityIds,
102
+ entity: GlobalSearchEntity
103
+ ) => {
104
+ return (
105
+ getMapping(businessEntityId).getDescription?.(entity) ??
106
+ getDescriptionForBusinessEntity(
107
+ businessEntityId,
108
+ getMainEntityFromSearchEntity(businessEntityId, entity)
109
+ )
110
+ );
111
+ };
112
+
113
+ export const getMainEntityFromSearchEntity = (
114
+ businessEntityId: BusinessEntityIds,
115
+ entity: GlobalSearchEntity
116
+ ) => getMapping(businessEntityId).getMainEntity(entity);
117
+
118
+ export const getTitleForBusinessEntity = (
119
+ businessEntityId: BusinessEntityIds,
120
+ entity: GlobalBusinessEntity
121
+ ) => getMapping(businessEntityId).getTitle(entity);
122
+
123
+ export const getTitleForSearchBusinessEntity = (
124
+ businessEntityId: BusinessEntityIds,
125
+ searchEntity: GlobalSearchEntity
126
+ ) =>
127
+ getTitleForBusinessEntity(
128
+ businessEntityId,
129
+ getMainEntityFromSearchEntity(businessEntityId, searchEntity)
130
+ );