@bisondesk/core-sdk 1.0.66 → 1.0.68

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 +1 -0
  2. package/lib/apis/crm.d.ts.map +1 -1
  3. package/lib/apis/crm.js +17 -2
  4. package/lib/apis/crm.js.map +1 -1
  5. package/lib/apis/leasing.d.ts +6 -0
  6. package/lib/apis/leasing.d.ts.map +1 -0
  7. package/lib/apis/leasing.js +77 -0
  8. package/lib/apis/leasing.js.map +1 -0
  9. package/lib/apis/settings.js +1 -1
  10. package/lib/apis/settings.js.map +1 -1
  11. package/lib/apis/utils.js +1 -1
  12. package/lib/apis/utils.js.map +1 -1
  13. package/lib/apis/vehicles.d.ts +4 -0
  14. package/lib/apis/vehicles.d.ts.map +1 -0
  15. package/lib/apis/vehicles.js +41 -0
  16. package/lib/apis/vehicles.js.map +1 -0
  17. package/lib/constants.d.ts +0 -1
  18. package/lib/constants.d.ts.map +1 -1
  19. package/lib/constants.js +1 -5
  20. package/lib/constants.js.map +1 -1
  21. package/lib/types/definitions.d.ts +1 -0
  22. package/lib/types/definitions.d.ts.map +1 -1
  23. package/lib/types/leads.d.ts +2 -2
  24. package/lib/types/leads.d.ts.map +1 -1
  25. package/lib/types/leasing.d.ts +136 -0
  26. package/lib/types/leasing.d.ts.map +1 -0
  27. package/lib/types/leasing.js +3 -0
  28. package/lib/types/leasing.js.map +1 -0
  29. package/lib/types/settings.d.ts +5 -0
  30. package/lib/types/settings.d.ts.map +1 -1
  31. package/lib/types/users.d.ts +3 -0
  32. package/lib/types/users.d.ts.map +1 -1
  33. package/lib/types/vehicles.d.ts +5 -9
  34. package/lib/types/vehicles.d.ts.map +1 -1
  35. package/package.json +2 -2
  36. package/src/apis/crm.ts +24 -1
  37. package/src/apis/leasing.ts +97 -0
  38. package/src/apis/settings.ts +1 -1
  39. package/src/apis/utils.ts +1 -1
  40. package/src/apis/vehicles.ts +51 -0
  41. package/src/constants.ts +0 -5
  42. package/src/types/definitions.ts +1 -0
  43. package/src/types/leads.ts +2 -3
  44. package/src/types/leasing.ts +153 -0
  45. package/src/types/settings.ts +5 -0
  46. package/src/types/users.ts +4 -0
  47. package/src/types/vehicles.ts +5 -9
  48. package/tsconfig.tsbuildinfo +80 -34
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bisondesk/core-sdk",
3
- "version": "1.0.66",
3
+ "version": "1.0.68",
4
4
  "description": "",
5
5
  "scripts": {
6
6
  "clean": "rm -rf build dist lib *.tsbuildinfo",
@@ -11,7 +11,7 @@
11
11
  },
12
12
  "author": "Ivo Anastácio",
13
13
  "dependencies": {
14
- "@bisondesk/commons-sdk": "1.0.66",
14
+ "@bisondesk/commons-sdk": "1.0.68",
15
15
  "joi": "17.4.0",
16
16
  "lru-cache": "6.0.0"
17
17
  },
package/src/apis/crm.ts CHANGED
@@ -1,6 +1,6 @@
1
+ import { TENANT_ID_ADMIN_HEADER } from '@bisondesk/commons-sdk/lib/constants';
1
2
  import { XError } from '@bisondesk/commons/lib/errors';
2
3
  import fetch, { Response } from 'node-fetch';
3
- import { TENANT_ID_ADMIN_HEADER } from '../constants';
4
4
  import { Contact, Organization } from '../types/crm';
5
5
  import { getAdminAuth } from './utils';
6
6
 
@@ -27,6 +27,29 @@ export const getCrmOrganization = async (
27
27
  throw new XError(response.statusText, { body });
28
28
  };
29
29
 
30
+ export const getCrmOrganizationByExternalId = async (
31
+ tenantId: string,
32
+ externalId: string
33
+ ): Promise<Organization | undefined> => {
34
+ const auth = await getAdminAuth();
35
+ const response: Response = await fetch(
36
+ `${process.env.CORE_API_ORIGIN}/api/crm/organizations/external-id/${externalId}`,
37
+ {
38
+ headers: {
39
+ Authorization: auth,
40
+ [TENANT_ID_ADMIN_HEADER]: tenantId,
41
+ },
42
+ }
43
+ );
44
+
45
+ if (response.ok) {
46
+ return response.status === 200 ? response.json() : undefined;
47
+ }
48
+
49
+ const body = await response.text();
50
+ throw new XError(response.statusText, { body });
51
+ };
52
+
30
53
  export const listCrmContacts = async (
31
54
  tenantId: string,
32
55
  organizationId: string
@@ -0,0 +1,97 @@
1
+ import { TENANT_ID_ADMIN_HEADER } from '@bisondesk/commons-sdk/lib/constants';
2
+ import { XError } from '@bisondesk/commons/lib/errors';
3
+ import fetch, { Response } from 'node-fetch';
4
+ import { LeasingConditions, LeasingContract, NewLeasingConditions } from '../types/leasing';
5
+ import { getAdminAuth } from './utils';
6
+
7
+ export const getLeasingConditions = async (
8
+ tenantId: string,
9
+ conditionsId: string
10
+ ): Promise<LeasingConditions | undefined> => {
11
+ const auth = await getAdminAuth();
12
+ const response: Response = await fetch(
13
+ `${process.env.CORE_API_ORIGIN}/api/leasing/conditions/${conditionsId}`,
14
+ {
15
+ headers: {
16
+ Authorization: auth,
17
+ [TENANT_ID_ADMIN_HEADER]: tenantId,
18
+ },
19
+ }
20
+ );
21
+
22
+ if (response.ok) {
23
+ return response.status === 200 ? response.json() : undefined;
24
+ }
25
+
26
+ const body = await response.text();
27
+ throw new XError(response.statusText, { body });
28
+ };
29
+
30
+ export const createLeasingConditions = async (
31
+ tenantId: string,
32
+ conditions: NewLeasingConditions
33
+ ): Promise<LeasingConditions> => {
34
+ const auth = await getAdminAuth();
35
+ const response: Response = await fetch(`${process.env.CORE_API_ORIGIN}/api/leasing/conditions`, {
36
+ method: 'POST',
37
+ headers: {
38
+ 'Content-Type': 'application/json',
39
+ Authorization: auth,
40
+ [TENANT_ID_ADMIN_HEADER]: tenantId,
41
+ },
42
+ body: JSON.stringify(conditions),
43
+ });
44
+
45
+ if (response.status === 200) {
46
+ return response.json();
47
+ }
48
+
49
+ const body = await response.text();
50
+ throw new XError(response.statusText, { body });
51
+ };
52
+
53
+ export const getLeasingContract = async (
54
+ tenantId: string,
55
+ contractId: string
56
+ ): Promise<LeasingContract | undefined> => {
57
+ const auth = await getAdminAuth();
58
+ const response: Response = await fetch(
59
+ `${process.env.CORE_API_ORIGIN}/api/leasing/contracts/${contractId}`,
60
+ {
61
+ headers: {
62
+ Authorization: auth,
63
+ [TENANT_ID_ADMIN_HEADER]: tenantId,
64
+ },
65
+ }
66
+ );
67
+
68
+ if (response.ok) {
69
+ return response.status === 200 ? response.json() : undefined;
70
+ }
71
+
72
+ const body = await response.text();
73
+ throw new XError(response.statusText, { body });
74
+ };
75
+
76
+ export const upsertLeasingContract = async (
77
+ tenantId: string,
78
+ contract: LeasingContract
79
+ ): Promise<LeasingContract> => {
80
+ const auth = await getAdminAuth();
81
+ const response: Response = await fetch(`${process.env.CORE_API_ORIGIN}/api/leasing/contracts`, {
82
+ method: 'POST',
83
+ headers: {
84
+ 'Content-Type': 'application/json',
85
+ Authorization: auth,
86
+ [TENANT_ID_ADMIN_HEADER]: tenantId,
87
+ },
88
+ body: JSON.stringify(contract),
89
+ });
90
+
91
+ if (response.status === 200) {
92
+ return response.json();
93
+ }
94
+
95
+ const body = await response.text();
96
+ throw new XError(response.statusText, { body });
97
+ };
@@ -1,6 +1,6 @@
1
+ import { TENANT_ID_ADMIN_HEADER } from '@bisondesk/commons-sdk/lib/constants';
1
2
  import { XError } from '@bisondesk/commons/lib/errors';
2
3
  import fetch, { Response } from 'node-fetch';
3
- import { TENANT_ID_ADMIN_HEADER } from '../constants';
4
4
  import { getAdminAuth } from './utils';
5
5
 
6
6
  export const getSettings = async <T>(
package/src/apis/utils.ts CHANGED
@@ -1,7 +1,7 @@
1
+ import { TENANT_ID_ADMIN_HEADER } from '@bisondesk/commons-sdk/lib/constants';
1
2
  import { InvalidArgumentsError } from '@bisondesk/commons/lib/errors';
2
3
  import { getStringSecret } from '@bisondesk/commons/lib/secrets';
3
4
  import LRU from 'lru-cache';
4
- import { TENANT_ID_ADMIN_HEADER } from '../constants';
5
5
 
6
6
  const authCache = new LRU<string, string>({
7
7
  maxAge: 1000 * 60 * 5,
@@ -0,0 +1,51 @@
1
+ import { TENANT_ID_ADMIN_HEADER } from '@bisondesk/commons-sdk/lib/constants';
2
+ import { XError } from '@bisondesk/commons/lib/errors';
3
+ import fetch, { Response } from 'node-fetch';
4
+ import { Vehicle } from '../types/vehicles';
5
+ import { getAdminAuth } from './utils';
6
+
7
+ export const getVehicle = async (
8
+ tenantId: string,
9
+ vehicleId: string
10
+ ): Promise<Vehicle | undefined> => {
11
+ const auth = await getAdminAuth();
12
+ const response: Response = await fetch(
13
+ `${process.env.CORE_API_ORIGIN}/api/vehicles/${vehicleId}`,
14
+ {
15
+ headers: {
16
+ Authorization: auth,
17
+ [TENANT_ID_ADMIN_HEADER]: tenantId,
18
+ },
19
+ }
20
+ );
21
+
22
+ if (response.ok) {
23
+ return response.status === 200 ? response.json() : undefined;
24
+ }
25
+
26
+ const body = await response.text();
27
+ throw new XError(response.statusText, { body });
28
+ };
29
+
30
+ export const getVehicleByStockNumber = async (
31
+ tenantId: string,
32
+ stockNumber: string
33
+ ): Promise<Vehicle | undefined> => {
34
+ const auth = await getAdminAuth();
35
+ const response: Response = await fetch(
36
+ `${process.env.CORE_API_ORIGIN}/api/vehicles/stock-number/${stockNumber}`,
37
+ {
38
+ headers: {
39
+ Authorization: auth,
40
+ [TENANT_ID_ADMIN_HEADER]: tenantId,
41
+ },
42
+ }
43
+ );
44
+
45
+ if (response.ok) {
46
+ return response.status === 200 ? response.json() : undefined;
47
+ }
48
+
49
+ const body = await response.text();
50
+ throw new XError(response.statusText, { body });
51
+ };
package/src/constants.ts CHANGED
@@ -61,8 +61,3 @@ export const MAX_KM = 1_000_000;
61
61
  export const MAX_PRICE = 100_000;
62
62
  export const PRICE_ROUNDING = 1000;
63
63
  export const KM_ROUNDING = 100_000;
64
-
65
- //
66
- // Headers
67
- //
68
- export const TENANT_ID_ADMIN_HEADER = 'tenant-id';
@@ -27,6 +27,7 @@ export type EsDefinition = {
27
27
  fields: {
28
28
  [fieldId: string]: {
29
29
  esMapping: unknown;
30
+ sortKey?: string;
30
31
  };
31
32
  };
32
33
  };
@@ -27,7 +27,7 @@ export type LeadEvent = {
27
27
  };
28
28
 
29
29
  export type LeadContact = {
30
- accountManager: string;
30
+ accountManager?: string;
31
31
  companyName?: string;
32
32
  country: string;
33
33
  email?: string;
@@ -65,7 +65,7 @@ export type VehicleLeadsResponse = VehicleLeads & {
65
65
  };
66
66
 
67
67
  export type LeadVehiclesResponse = LeadVehicles & {
68
- vehiclesById: { [leadId: string]: SearchVehicle };
68
+ vehiclesById: { [vehicleId: string]: SearchVehicle };
69
69
  };
70
70
 
71
71
  export type LeadStats = {
@@ -83,7 +83,6 @@ export type LeadVehicle = {
83
83
  export type Lead = {
84
84
  id: string;
85
85
  createdAt: string;
86
-
87
86
  contact: LeadContact;
88
87
  interests: Interest[];
89
88
  vehicles: LeadVehicle[];
@@ -0,0 +1,153 @@
1
+ import { Organization } from './crm';
2
+ import { PublicSearchDefinition } from './definitions';
3
+
4
+ export type LeasingPublicSearchDefinitions = {
5
+ searchLeasingContract: PublicSearchDefinition;
6
+ };
7
+
8
+ export type LeasingContractEvent = {
9
+ id: string;
10
+ action: 'upsert' | 'delete';
11
+ actionAt: string;
12
+ userId: string;
13
+ tenantId: string;
14
+ };
15
+
16
+ export type LeasingContractImportEvent = {
17
+ tenantId: string;
18
+ };
19
+
20
+ export type LeasingConditionEvent = {
21
+ id: string;
22
+ action: 'create';
23
+ actionAt: string;
24
+ userId: string;
25
+ tenantId: string;
26
+ };
27
+
28
+ export type SearchLeasingContract = {
29
+ contract: LeasingContract;
30
+ conditions: Omit<LeasingConditions, 'cashIn' | 'cashOut'>;
31
+ org: Organization;
32
+ };
33
+
34
+ export type LeasingContract = {
35
+ id: string;
36
+ createdAt: string;
37
+ updatedAt: string;
38
+
39
+ contractNumber: string;
40
+ startDate: string;
41
+
42
+ accountManager?: string;
43
+ branch?: string; // 'MrLease', 'MrLease NL', ...
44
+
45
+ client: {
46
+ organizationId: string;
47
+ contactIds: string[];
48
+ };
49
+
50
+ vehicle: {
51
+ id: string;
52
+ stockNumber: string;
53
+ administrativeNumber?: string;
54
+ };
55
+
56
+ conditions: ConditionsRef[];
57
+ };
58
+
59
+ export type ConditionsRef = {
60
+ id: string;
61
+ validSince: string;
62
+ };
63
+
64
+ export type NewLeasingConditions = {
65
+ parameters: {
66
+ yearlyRoadTax: string;
67
+ civilLiability: string;
68
+ oneTimeRoadTax: string;
69
+ specialInsurance: string;
70
+ allRisksPercentage: string;
71
+ allRisksTaxPercentage: string;
72
+ };
73
+
74
+ inputs: {
75
+ deposit: string;
76
+ salesPrice: string;
77
+ bankDeposit: string;
78
+ purchasePrice: string;
79
+ residualValue: string;
80
+ insuranceAmount: string;
81
+ durationInMonths: string;
82
+ includesAllRisks: boolean;
83
+ marginPercentage: string;
84
+ bankResidualValue: string;
85
+ bankDurationInMonths: string;
86
+ startupFeePercentage: string;
87
+ includesYearlyRoadTax: boolean;
88
+ includesCivilLiability: boolean;
89
+ includesOneTimeRoadTax: boolean;
90
+ interestRatePercentage: string;
91
+ includesSpecialInsurance: boolean;
92
+ monthlyAdministrationFee: string;
93
+ bankInterestRatePercentage: string;
94
+ };
95
+
96
+ outputs: {
97
+ ROI: string;
98
+ ROITarget: string;
99
+ ROIPerYear: string;
100
+ cashDeficit: string;
101
+ totalProfit: string;
102
+ ROIDifference: string;
103
+ leasingAmount: string;
104
+ leasingProfit: string;
105
+ vehicleProfit: string;
106
+ yearlyTaxCost: string;
107
+ monthlyTaxCost: string;
108
+ oneTimeTaxCost: string;
109
+ financingAmount: string;
110
+ bankContractValue: string;
111
+ bankLeasingAmount: string;
112
+ totalMonthlyPayment: string;
113
+ yearlyInsuranceCost: string;
114
+ leasingContractValue: string;
115
+ monthlyInsuranceCost: string;
116
+ yearlyTaxRetailPrice: string;
117
+ monthlyTaxRetailPrice: string;
118
+ allRisksInsuranceAmount: string;
119
+ yearlyInsuranceRetailPrice: string;
120
+ monthlyInsuranceRetailPrice: string;
121
+ monthlyInsuranceAndTaxesRetailPrice: string;
122
+ };
123
+
124
+ cashIn: Array<{
125
+ time: string;
126
+ cashIn: string;
127
+ deposit: string;
128
+ startupFee: string;
129
+ taxPayment: string;
130
+ residualValue: string;
131
+ cumulativeCash: string;
132
+ insurancePayment: string;
133
+ monthlyAdministrationFee: string;
134
+ leasingAmountWithoutAdminFee: string;
135
+ }>;
136
+
137
+ cashOut: Array<{
138
+ time: string;
139
+ cashOut: string;
140
+ deposit: string;
141
+ taxPayment: string;
142
+ leasingAmount: string;
143
+ residualValue: string;
144
+ cumulativeCash: string;
145
+ insurancePayment: string;
146
+ }>;
147
+ };
148
+
149
+ export type LeasingConditions = NewLeasingConditions & {
150
+ id: string;
151
+ createdAt: string;
152
+ createdBy: string;
153
+ };
@@ -17,7 +17,12 @@ export type WebsiteSettings = {
17
17
  };
18
18
 
19
19
  export type HyperportalSettings = {
20
+ hcTenantId: string;
20
21
  crm: {
21
22
  active: boolean;
22
23
  };
24
+ vehicles: {
25
+ active: boolean;
26
+ ignoreBeforeDate?: string; // do not modify vehicles created before this date;
27
+ };
23
28
  };
@@ -11,6 +11,10 @@ export type NewUserRequest = {
11
11
  roles: AppRoles[];
12
12
  };
13
13
 
14
+ export type UpdateUserRequest = Omit<User, 'phone'> & {
15
+ phone: PhoneNumberRawValue | PhoneNumberValue;
16
+ };
17
+
14
18
  export type User = {
15
19
  active: boolean;
16
20
  createdAt: string;
@@ -24,8 +24,8 @@ export type VehicleInternalInfo = {
24
24
  createdAt: string;
25
25
  description: {
26
26
  title: string;
27
- remarks?: MultiLangValue;
28
- technicalRemarks?: MultiLangValue;
27
+ remarks?: string;
28
+ technicalRemarks?: string;
29
29
  };
30
30
  marketingPlatforms: string[];
31
31
  identification: {
@@ -97,12 +97,8 @@ export type VehicleExtarnalInfo = {
97
97
  used?: boolean;
98
98
  };
99
99
  description: {
100
- remarks?: {
101
- [lang: string]: string;
102
- };
103
- titles: {
104
- [lang: string]: string;
105
- };
100
+ remarks?: MultiLangValue;
101
+ titles: MultiLangValue;
106
102
  };
107
103
  general: {
108
104
  bodystyle?: string;
@@ -120,7 +116,7 @@ export type VehicleExtarnalInfo = {
120
116
  };
121
117
  firstRegistration?: string;
122
118
  };
123
- identification?: {
119
+ identification: {
124
120
  licensePlate?: string;
125
121
  stockNumber: string;
126
122
  vin?: string;