@driveflux/api-functions 1.0.135 → 1.0.137
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/dist/auth/confirm.js +24 -24
- package/dist/auth/consent.js +22 -27
- package/dist/auth/emails.js +12 -13
- package/dist/auth/formatter.js +5 -5
- package/dist/auth/otp.js +66 -50
- package/dist/auth/register.js +48 -35
- package/dist/auth/tokens.js +58 -55
- package/dist/auth/verifications.js +53 -52
- package/dist/constants.js +0 -1
- package/dist/create-logger.js +1 -2
- package/dist/mailjet/calls/manage-contacts-in-list.js +5 -6
- package/dist/mailjet/calls/manage-subscription-status.js +4 -5
- package/dist/mailjet/calls/request-service.js +7 -6
- package/dist/mailjet/refresh-email-preferences.js +11 -12
- package/dist/mailjet/set-contact.js +11 -12
- package/dist/mailjet/types.js +1 -2
- package/dist/mailjet/utils/convert-to-array.js +8 -6
- package/dist/mailjet/utils/extract-email-preferences.js +14 -15
- package/dist/mailjet/utils/lists.js +7 -8
- package/dist/mailjet/utils/update-email-references.js +16 -15
- package/dist/notion/client.js +22 -19
- package/dist/notion/helpful.js +6 -9
- package/dist/notion/schemas/block.js +42 -48
- package/dist/notion/schemas/common.js +9 -14
- package/dist/notion/schemas/database.js +62 -60
- package/dist/notion/schemas/emoji.js +1 -2
- package/dist/notion/schemas/file.js +9 -9
- package/dist/notion/schemas/kb.js +5 -6
- package/dist/notion/schemas/page.js +72 -61
- package/dist/notion/schemas/parent.js +4 -5
- package/dist/notion/schemas/user.js +18 -19
- package/dist/reservation/agree.js +2 -3
- package/dist/reservation/checks.js +3 -4
- package/dist/reservation/display-vehicle.js +73 -83
- package/dist/reservation/ensure-user-billing-address.js +9 -11
- package/dist/reservation/fetch-or-create.js +49 -56
- package/dist/reservation/invoice.js +77 -88
- package/dist/reservation/payer.js +5 -6
- package/dist/reservation/payment-intent-sync.js +4 -6
- package/dist/reservation/reserve.js +3 -4
- package/dist/reservation/types.js +1 -2
- package/dist/reservation/vehicle.js +13 -16
- package/dist/slack.js +24 -29
- package/dist/validation.js +77 -79
- package/dist/vehicle/vehicle-pricing/constants.js +22 -19
- package/dist/vehicle/vehicle-pricing/index.js +28 -42
- package/dist/vehicle/vehicle-pricing/types.js +1 -2
- package/package.json +4 -4
package/dist/validation.js
CHANGED
|
@@ -1,34 +1,32 @@
|
|
|
1
1
|
import { makeProblem } from '@driveflux/problem';
|
|
2
2
|
import { Err } from '@driveflux/result';
|
|
3
|
-
import { z
|
|
4
|
-
export const makeValidationErrorResult = (zodError)
|
|
5
|
-
const validation = zodError.flatten((i)
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
export const makeValidationErrorResult = (zodError)=>{
|
|
5
|
+
const validation = zodError.flatten((i)=>({
|
|
6
|
+
message: i.message,
|
|
7
|
+
code: i.code,
|
|
8
|
+
path: i.path
|
|
9
|
+
}));
|
|
10
10
|
return new Err(makeProblem({
|
|
11
11
|
object: 'validation-issues',
|
|
12
|
-
...validation
|
|
12
|
+
...validation
|
|
13
13
|
}));
|
|
14
14
|
};
|
|
15
|
-
export const getIdOrObjectValidation = (object, extendObjectValidation)
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
.catchall(z.any())
|
|
21
|
-
], {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
});
|
|
15
|
+
export const getIdOrObjectValidation = (object, extendObjectValidation)=>z.union([
|
|
16
|
+
z.string(),
|
|
17
|
+
z.object({
|
|
18
|
+
object: z.literal(object),
|
|
19
|
+
...extendObjectValidation
|
|
20
|
+
}).passthrough().catchall(z.any())
|
|
21
|
+
], {
|
|
22
|
+
error: ()=>{
|
|
23
|
+
return {
|
|
24
|
+
message: `Invalid details. Please provide an id as a string or an object of type ${object}`
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
28
|
export const nonEmptyStringValidator = z.string().min(1);
|
|
29
|
-
export const metadataValidation = z
|
|
30
|
-
.object({})
|
|
31
|
-
.catchall(z.union([
|
|
29
|
+
export const metadataValidation = z.object({}).catchall(z.union([
|
|
32
30
|
z.string(),
|
|
33
31
|
z.number(),
|
|
34
32
|
z.boolean(),
|
|
@@ -36,36 +34,33 @@ export const metadataValidation = z
|
|
|
36
34
|
z.array(z.number()),
|
|
37
35
|
z.array(z.boolean()),
|
|
38
36
|
z.null(),
|
|
39
|
-
z.undefined()
|
|
37
|
+
z.undefined()
|
|
40
38
|
]));
|
|
41
39
|
export const addressValidation = z.object({
|
|
42
40
|
name: z.string().optional().nullable(),
|
|
43
|
-
coordinates: z
|
|
44
|
-
.object({
|
|
41
|
+
coordinates: z.object({
|
|
45
42
|
lat: z.number().min(-90).max(90),
|
|
46
|
-
lng: z.number().min(-180).max(180)
|
|
47
|
-
})
|
|
48
|
-
.nullable()
|
|
49
|
-
.optional(),
|
|
43
|
+
lng: z.number().min(-180).max(180)
|
|
44
|
+
}).nullable().optional(),
|
|
50
45
|
street1: nonEmptyStringValidator,
|
|
51
46
|
street2: z.string().nullable().optional(),
|
|
52
47
|
city: nonEmptyStringValidator,
|
|
53
48
|
state: nonEmptyStringValidator,
|
|
54
49
|
postalCode: z.string().min(3).max(11),
|
|
55
|
-
country: nonEmptyStringValidator
|
|
56
|
-
});
|
|
57
|
-
export const getIsoDatetimeToDate = (dateValidation) => z
|
|
58
|
-
.codec(z.string(), dateValidation ?? z.date(), {
|
|
59
|
-
decode: (isoString) => new Date(isoString),
|
|
60
|
-
encode: (date) => date.toISOString(),
|
|
61
|
-
})
|
|
62
|
-
.refine((d) => {
|
|
63
|
-
const date = new Date(d);
|
|
64
|
-
return !Number.isNaN(date.getTime());
|
|
65
|
-
}, {
|
|
66
|
-
message: 'Invalid date',
|
|
67
|
-
path: ['date'],
|
|
50
|
+
country: nonEmptyStringValidator
|
|
68
51
|
});
|
|
52
|
+
export const getIsoDatetimeToDate = (dateValidation)=>z.codec(z.string(), dateValidation ?? z.date(), {
|
|
53
|
+
decode: (isoString)=>new Date(isoString),
|
|
54
|
+
encode: (date)=>date.toISOString()
|
|
55
|
+
}).refine((d)=>{
|
|
56
|
+
const date = new Date(d);
|
|
57
|
+
return !Number.isNaN(date.getTime());
|
|
58
|
+
}, {
|
|
59
|
+
message: 'Invalid date',
|
|
60
|
+
path: [
|
|
61
|
+
'date'
|
|
62
|
+
]
|
|
63
|
+
});
|
|
69
64
|
export const dateValidation = getIsoDatetimeToDate();
|
|
70
65
|
export const enhancedImageValidation = z.object({
|
|
71
66
|
default: z.string(),
|
|
@@ -74,64 +69,67 @@ export const enhancedImageValidation = z.object({
|
|
|
74
69
|
small: z.string().optional(),
|
|
75
70
|
medium: z.string().optional(),
|
|
76
71
|
large: z.string().optional(),
|
|
77
|
-
description: z.string().optional()
|
|
72
|
+
description: z.string().optional()
|
|
78
73
|
});
|
|
79
|
-
export const getObjectValidation = (o)
|
|
74
|
+
export const getObjectValidation = (o)=>z.enum([
|
|
75
|
+
o
|
|
76
|
+
]).optional();
|
|
80
77
|
export const contactValidation = z.object({
|
|
81
78
|
id: z.string().optional(),
|
|
82
79
|
firstName: z.string(),
|
|
83
80
|
lastName: z.string(),
|
|
84
81
|
jobTitle: z.string().optional(),
|
|
85
|
-
email: z
|
|
86
|
-
.string()
|
|
87
|
-
.email()
|
|
88
|
-
.optional()
|
|
89
|
-
.transform((email) => email?.toLowerCase().trim()),
|
|
82
|
+
email: z.string().email().optional().transform((email)=>email?.toLowerCase().trim()),
|
|
90
83
|
phoneNumber: z.string().optional(),
|
|
91
|
-
remarks: z.string().default('')
|
|
84
|
+
remarks: z.string().default('')
|
|
92
85
|
});
|
|
93
86
|
export const documentFileValidation = z.object({
|
|
94
87
|
id: z.string().optional(),
|
|
95
88
|
name: z.string(),
|
|
96
89
|
description: z.string().nullable().optional(),
|
|
97
90
|
url: z.string(),
|
|
98
|
-
fileType: z.preprocess((f)
|
|
91
|
+
fileType: z.preprocess((f)=>typeof f === 'string' ? f.toLowerCase() : f, z.enum([
|
|
92
|
+
'jpg',
|
|
93
|
+
'jpeg',
|
|
94
|
+
'png',
|
|
95
|
+
'pdf',
|
|
96
|
+
'image'
|
|
97
|
+
]).optional()),
|
|
99
98
|
mimeType: z.string().optional(),
|
|
100
99
|
uploaded: z.boolean().default(true),
|
|
101
100
|
createdAt: dateValidation.nullable().optional(),
|
|
102
101
|
updatedAt: dateValidation.nullable().optional(),
|
|
103
|
-
metadata: metadataValidation.nullable().optional()
|
|
102
|
+
metadata: metadataValidation.nullable().optional()
|
|
104
103
|
});
|
|
105
104
|
export const queryBooleanValidator = z.stringbool({
|
|
106
|
-
truthy: [
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
105
|
+
truthy: [
|
|
106
|
+
'1',
|
|
107
|
+
'true',
|
|
108
|
+
'yes'
|
|
109
|
+
],
|
|
110
|
+
falsy: [
|
|
111
|
+
'0',
|
|
112
|
+
'false',
|
|
113
|
+
'no'
|
|
114
|
+
]
|
|
112
115
|
});
|
|
116
|
+
export const getStringToNumberValidator = (numberValidation)=>z.codec(z.string().regex(z.regexes.number), numberValidation ?? z.number(), {
|
|
117
|
+
decode: (str)=>Number.parseFloat(str),
|
|
118
|
+
encode: (num)=>num.toString()
|
|
119
|
+
});
|
|
113
120
|
export const queryNumberValidator = getStringToNumberValidator();
|
|
114
121
|
export function queryEnumArrayValidator(enumOrValidation) {
|
|
115
122
|
// Handle ZodEnum case
|
|
116
|
-
if (enumOrValidation &&
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
encode: (value) => value.join(','),
|
|
122
|
-
decode: (value) => value.split(','),
|
|
123
|
-
})
|
|
124
|
-
.or(z.array(enumOrValidation));
|
|
123
|
+
if (enumOrValidation && typeof enumOrValidation === 'object' && '_zod' in enumOrValidation) {
|
|
124
|
+
return z.codec(z.string(), z.array(enumOrValidation), {
|
|
125
|
+
encode: (value)=>value.join(','),
|
|
126
|
+
decode: (value)=>value.split(',')
|
|
127
|
+
}).or(z.array(enumOrValidation));
|
|
125
128
|
}
|
|
126
129
|
// Handle array or enum-like object case
|
|
127
|
-
const enumSchema = Array.isArray(enumOrValidation)
|
|
128
|
-
|
|
129
|
-
:
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
encode: (value) => value.join(','),
|
|
133
|
-
decode: (value) => value.split(','),
|
|
134
|
-
})
|
|
135
|
-
.or(z.array(enumSchema));
|
|
130
|
+
const enumSchema = Array.isArray(enumOrValidation) ? z.enum(enumOrValidation) : z.enum(Object.values(enumOrValidation));
|
|
131
|
+
return z.codec(z.string(), z.array(enumSchema), {
|
|
132
|
+
encode: (value)=>value.join(','),
|
|
133
|
+
decode: (value)=>value.split(',')
|
|
134
|
+
}).or(z.array(enumSchema));
|
|
136
135
|
}
|
|
137
|
-
//# sourceMappingURL=validation.js.map
|
|
@@ -1,18 +1,23 @@
|
|
|
1
|
-
const DEFAUALT_MILEAGE_MATRIX = {
|
|
1
|
+
const DEFAUALT_MILEAGE_MATRIX = {
|
|
2
|
+
lite: 0,
|
|
3
|
+
standard: 0,
|
|
4
|
+
plus: 0,
|
|
5
|
+
unlimited: 0
|
|
6
|
+
};
|
|
2
7
|
export const DEFAULT_MATRIX = {
|
|
3
8
|
plan1: DEFAUALT_MILEAGE_MATRIX,
|
|
4
9
|
plan12: DEFAUALT_MILEAGE_MATRIX,
|
|
5
10
|
plan24: DEFAUALT_MILEAGE_MATRIX,
|
|
6
11
|
plan36: DEFAUALT_MILEAGE_MATRIX,
|
|
7
12
|
plan60: DEFAUALT_MILEAGE_MATRIX,
|
|
8
|
-
planWeekly: DEFAUALT_MILEAGE_MATRIX
|
|
13
|
+
planWeekly: DEFAUALT_MILEAGE_MATRIX
|
|
9
14
|
};
|
|
10
15
|
export const FLUX_MIN_TAKE = 200;
|
|
11
16
|
const EMPTY_MILEAGE_PACKAGES = {
|
|
12
17
|
lite: 0,
|
|
13
18
|
standard: 0,
|
|
14
19
|
plus: 0,
|
|
15
|
-
unlimited: 0
|
|
20
|
+
unlimited: 0
|
|
16
21
|
};
|
|
17
22
|
export const EMPTY_FLUX_PRICING_MATRIX_CONTROLLER = {
|
|
18
23
|
plan60: 0,
|
|
@@ -22,7 +27,7 @@ export const EMPTY_FLUX_PRICING_MATRIX_CONTROLLER = {
|
|
|
22
27
|
plan1: 0,
|
|
23
28
|
planWeekly: 0,
|
|
24
29
|
add: EMPTY_MILEAGE_PACKAGES,
|
|
25
|
-
excessMileage: 0
|
|
30
|
+
excessMileage: 0
|
|
26
31
|
};
|
|
27
32
|
export const EMPTY_FLUX_START_FEE_MATRIX_CONTROLLER = {
|
|
28
33
|
plan60: EMPTY_MILEAGE_PACKAGES,
|
|
@@ -30,7 +35,7 @@ export const EMPTY_FLUX_START_FEE_MATRIX_CONTROLLER = {
|
|
|
30
35
|
plan24: EMPTY_MILEAGE_PACKAGES,
|
|
31
36
|
plan12: EMPTY_MILEAGE_PACKAGES,
|
|
32
37
|
plan1: EMPTY_MILEAGE_PACKAGES,
|
|
33
|
-
planWeekly: EMPTY_MILEAGE_PACKAGES
|
|
38
|
+
planWeekly: EMPTY_MILEAGE_PACKAGES
|
|
34
39
|
};
|
|
35
40
|
export const EMPTY_ULTRA_TIERS = {
|
|
36
41
|
tier1: 0,
|
|
@@ -47,7 +52,7 @@ export const EMPTY_ULTRA_TIERS = {
|
|
|
47
52
|
tier12: 0,
|
|
48
53
|
tier13: 0,
|
|
49
54
|
tier14: 0,
|
|
50
|
-
tier15: 0
|
|
55
|
+
tier15: 0
|
|
51
56
|
};
|
|
52
57
|
export const EMPTY_MATRIX = {
|
|
53
58
|
plan60: EMPTY_MILEAGE_PACKAGES,
|
|
@@ -55,50 +60,49 @@ export const EMPTY_MATRIX = {
|
|
|
55
60
|
plan24: EMPTY_MILEAGE_PACKAGES,
|
|
56
61
|
plan12: EMPTY_MILEAGE_PACKAGES,
|
|
57
62
|
plan1: EMPTY_MILEAGE_PACKAGES,
|
|
58
|
-
planWeekly: EMPTY_MILEAGE_PACKAGES
|
|
63
|
+
planWeekly: EMPTY_MILEAGE_PACKAGES
|
|
59
64
|
};
|
|
60
65
|
/**
|
|
61
66
|
* Matrix representing the dealership's take in percentages
|
|
62
67
|
*
|
|
63
68
|
* @see https://docs.google.com/spreadsheets/d/1lYYMdQgnzG53lCGf_dKJY9pEue5suJuo3O3-zegIOT0/edit#gid=819271234
|
|
64
|
-
*/
|
|
65
|
-
export const HOST_MATRIX_COEFFICIENTS = {
|
|
69
|
+
*/ export const HOST_MATRIX_COEFFICIENTS = {
|
|
66
70
|
plan60: {
|
|
67
71
|
lite: 0.8,
|
|
68
72
|
standard: 0.9,
|
|
69
73
|
plus: 1,
|
|
70
|
-
unlimited: 1.25
|
|
74
|
+
unlimited: 1.25
|
|
71
75
|
},
|
|
72
76
|
plan36: {
|
|
73
77
|
lite: 1,
|
|
74
78
|
standard: 1.1,
|
|
75
79
|
plus: 1.2,
|
|
76
|
-
unlimited: 1.45
|
|
80
|
+
unlimited: 1.45
|
|
77
81
|
},
|
|
78
82
|
plan24: {
|
|
79
83
|
lite: 1.1,
|
|
80
84
|
standard: 1.2,
|
|
81
85
|
plus: 1.3,
|
|
82
|
-
unlimited: 1.55
|
|
86
|
+
unlimited: 1.55
|
|
83
87
|
},
|
|
84
88
|
plan12: {
|
|
85
89
|
lite: 1.2,
|
|
86
90
|
standard: 1.3,
|
|
87
91
|
plus: 1.4,
|
|
88
|
-
unlimited: 1.65
|
|
92
|
+
unlimited: 1.65
|
|
89
93
|
},
|
|
90
94
|
plan1: {
|
|
91
95
|
lite: 0,
|
|
92
96
|
standard: 0,
|
|
93
97
|
plus: 0,
|
|
94
|
-
unlimited: 0
|
|
98
|
+
unlimited: 0
|
|
95
99
|
},
|
|
96
100
|
planWeekly: {
|
|
97
101
|
lite: 0,
|
|
98
102
|
standard: 0,
|
|
99
103
|
plus: 0,
|
|
100
|
-
unlimited: 0
|
|
101
|
-
}
|
|
104
|
+
unlimited: 0
|
|
105
|
+
}
|
|
102
106
|
};
|
|
103
107
|
export const ULTRA_HOST_TIERS_PRICING = {
|
|
104
108
|
tier1: 800,
|
|
@@ -115,7 +119,7 @@ export const ULTRA_HOST_TIERS_PRICING = {
|
|
|
115
119
|
tier12: 8500,
|
|
116
120
|
tier13: 10500,
|
|
117
121
|
tier14: 12800,
|
|
118
|
-
tier15: 15000
|
|
122
|
+
tier15: 15000
|
|
119
123
|
};
|
|
120
124
|
export const ULTRA_FLUX_TIERS_PRICING = {
|
|
121
125
|
tier1: 999,
|
|
@@ -132,11 +136,10 @@ export const ULTRA_FLUX_TIERS_PRICING = {
|
|
|
132
136
|
tier12: 9999,
|
|
133
137
|
tier13: 12599,
|
|
134
138
|
tier14: 14999,
|
|
135
|
-
tier15: 17999
|
|
139
|
+
tier15: 17999
|
|
136
140
|
};
|
|
137
141
|
export const HOST_EXCESS_MILEAGE_COEFFICIENT = 0.00048;
|
|
138
142
|
export const MAX_HOST_EXCESS_MILEAGE = 4;
|
|
139
143
|
export const MIN_HOST_EXCESS_MILEAGE = 0.52;
|
|
140
144
|
export const MAX_FLUX_EXCESS_MILEAGE = 5;
|
|
141
145
|
export const MIN_FLUX_EXCESS_MILEAGE = 0.65;
|
|
142
|
-
//# sourceMappingURL=constants.js.map
|
|
@@ -5,18 +5,17 @@ import cloneDeep from 'lodash/cloneDeep.js';
|
|
|
5
5
|
import { EMPTY_MATRIX } from './constants.js';
|
|
6
6
|
/**
|
|
7
7
|
* This is a last moment feature the CEO asked for and was not properly designed
|
|
8
|
-
*/
|
|
9
|
-
export const getRecommendedMotorcycleDeposit = (baseline) => {
|
|
8
|
+
*/ export const getRecommendedMotorcycleDeposit = (baseline)=>{
|
|
10
9
|
return Math.max(Math.min(baseline * 5, 1500), 1000);
|
|
11
10
|
};
|
|
12
|
-
export const getHostsMatrix = (pricingData, baseline, tier, flatPricing)
|
|
11
|
+
export const getHostsMatrix = (pricingData, baseline, tier, flatPricing)=>{
|
|
13
12
|
// Let's not mutate percentages
|
|
14
13
|
const newMatrix = cloneDeep(pricingData.hostEarnings.matrixCoefficients);
|
|
15
14
|
const baseCoefficients = cloneDeep(newMatrix.plan36);
|
|
16
15
|
const plans = Object.keys(newMatrix);
|
|
17
|
-
for (const plan of plans)
|
|
16
|
+
for (const plan of plans){
|
|
18
17
|
const mileagePackages = Object.keys(newMatrix[plan]);
|
|
19
|
-
for (const mileagePackage of mileagePackages)
|
|
18
|
+
for (const mileagePackage of mileagePackages){
|
|
20
19
|
if (plan === 'plan1') {
|
|
21
20
|
if (tier === 'tierCustom') {
|
|
22
21
|
newMatrix[plan][mileagePackage] = 0;
|
|
@@ -25,26 +24,23 @@ export const getHostsMatrix = (pricingData, baseline, tier, flatPricing) => {
|
|
|
25
24
|
newMatrix[plan][mileagePackage] = Number(pricingData.hostEarnings.ultraTiers[tier]);
|
|
26
25
|
continue;
|
|
27
26
|
}
|
|
28
|
-
newMatrix[plan][mileagePackage] = round(baseline *
|
|
29
|
-
(flatPricing
|
|
30
|
-
? baseCoefficients[mileagePackage]
|
|
31
|
-
: newMatrix[plan][mileagePackage]));
|
|
27
|
+
newMatrix[plan][mileagePackage] = round(baseline * (flatPricing ? baseCoefficients[mileagePackage] : newMatrix[plan][mileagePackage]));
|
|
32
28
|
}
|
|
33
29
|
}
|
|
34
30
|
return sortMatrix(newMatrix);
|
|
35
31
|
};
|
|
36
|
-
export const getHostExcessMileage = (pricingData, baseline)
|
|
32
|
+
export const getHostExcessMileage = (pricingData, baseline)=>{
|
|
37
33
|
return decimals(Math.max(Math.min(baseline * pricingData.hostEarnings.excessMileage.coefficient, pricingData.hostEarnings.excessMileage.upperBound), pricingData.hostEarnings.excessMileage.lowerBound));
|
|
38
34
|
};
|
|
39
|
-
export const getEmptyMatrix = ()
|
|
35
|
+
export const getEmptyMatrix = ()=>{
|
|
40
36
|
return cloneDeep(EMPTY_MATRIX);
|
|
41
37
|
};
|
|
42
|
-
export const sortMatrix = (unorderedMatrix)
|
|
38
|
+
export const sortMatrix = (unorderedMatrix)=>{
|
|
43
39
|
const ordered = {};
|
|
44
40
|
const plans = getVehicleDataVariant(PLANS, 'car');
|
|
45
41
|
const mileagePackages = getVehicleDataVariant(MILEAGE_PACKAGES, 'car');
|
|
46
|
-
for (const plan of plans)
|
|
47
|
-
for (const mileagePackage of mileagePackages)
|
|
42
|
+
for (const plan of plans){
|
|
43
|
+
for (const mileagePackage of mileagePackages){
|
|
48
44
|
if (!ordered[plan]) {
|
|
49
45
|
ordered[plan] = {};
|
|
50
46
|
}
|
|
@@ -53,7 +49,7 @@ export const sortMatrix = (unorderedMatrix) => {
|
|
|
53
49
|
}
|
|
54
50
|
return ordered;
|
|
55
51
|
};
|
|
56
|
-
const round = (number)
|
|
52
|
+
const round = (number)=>{
|
|
57
53
|
return Math.round(number * 100) / 100;
|
|
58
54
|
};
|
|
59
55
|
/**
|
|
@@ -66,8 +62,7 @@ const round = (number) => {
|
|
|
66
62
|
* @param customLitePicing
|
|
67
63
|
*
|
|
68
64
|
* @see https://docs.google.com/spreadsheets/d/1lYYMdQgnzG53lCGf_dKJY9pEue5suJuo3O3-zegIOT0/edit#gid=819271234
|
|
69
|
-
*/
|
|
70
|
-
export const getFluxPiceMatrix = (pricingData, vehicleType, baseline, dealershipPriceMatrix, tier, flatPricing, customMileagePackage, customLitePicing) => {
|
|
65
|
+
*/ export const getFluxPiceMatrix = (pricingData, vehicleType, baseline, dealershipPriceMatrix, tier, flatPricing, customMileagePackage, customLitePicing)=>{
|
|
71
66
|
// Let's not mutate percentages
|
|
72
67
|
const newMatrix = cloneDeep(pricingData.hostEarnings.matrixCoefficients);
|
|
73
68
|
const plans = Object.keys(newMatrix);
|
|
@@ -75,7 +70,7 @@ export const getFluxPiceMatrix = (pricingData, vehicleType, baseline, dealership
|
|
|
75
70
|
// if flat pricing, we order the plans by 36 months first, then the rest,
|
|
76
71
|
// that's because we perform the operations on the same matrix, so 36 is the base
|
|
77
72
|
// and should influence th rest of the plans
|
|
78
|
-
plans.sort((a, _b)
|
|
73
|
+
plans.sort((a, _b)=>{
|
|
79
74
|
if (a === 'plan36') {
|
|
80
75
|
return -1;
|
|
81
76
|
}
|
|
@@ -85,16 +80,16 @@ export const getFluxPiceMatrix = (pricingData, vehicleType, baseline, dealership
|
|
|
85
80
|
// This code is highly vulnerable to order. The order **MUST** be sorted,
|
|
86
81
|
// this is because it edits "lite" plan, then the other plans depend on the outcome of this one.
|
|
87
82
|
// TODO: Fix this code so that it sorts lite package first.
|
|
88
|
-
for (const plan of plans)
|
|
83
|
+
for (const plan of plans){
|
|
89
84
|
const mileagePackages = Object.keys(newMatrix[plan]);
|
|
90
|
-
mileagePackages.sort((a)
|
|
85
|
+
mileagePackages.sort((a)=>{
|
|
91
86
|
if (a === 'lite') {
|
|
92
87
|
return -1;
|
|
93
88
|
}
|
|
94
89
|
return 0;
|
|
95
90
|
});
|
|
96
91
|
const baseMileagePackage = vehicleType === 'motorcycle' ? 'standard' : 'lite';
|
|
97
|
-
for (const mileagePackage of mileagePackages)
|
|
92
|
+
for (const mileagePackage of mileagePackages){
|
|
98
93
|
const targetPlan = flatPricing ? 'plan36' : plan;
|
|
99
94
|
if (plan === 'plan1') {
|
|
100
95
|
if (tier === 'tierCustom') {
|
|
@@ -105,42 +100,38 @@ export const getFluxPiceMatrix = (pricingData, vehicleType, baseline, dealership
|
|
|
105
100
|
continue;
|
|
106
101
|
}
|
|
107
102
|
if (mileagePackage === baseMileagePackage) {
|
|
108
|
-
const baseMileagePackagePrice = Math.max(baseline * pricingData.fluxPricing.matrixCoefficients[targetPlan], Number(dealershipPriceMatrix[targetPlan][baseMileagePackage]) +
|
|
109
|
-
pricingData.fluxPricing.minFluxTake);
|
|
103
|
+
const baseMileagePackagePrice = Math.max(baseline * pricingData.fluxPricing.matrixCoefficients[targetPlan], Number(dealershipPriceMatrix[targetPlan][baseMileagePackage]) + pricingData.fluxPricing.minFluxTake);
|
|
110
104
|
const custom = customLitePicing?.[plan];
|
|
111
105
|
newMatrix[plan][baseMileagePackage] = decimals(typeof custom === 'undefined' ? baseMileagePackagePrice : custom);
|
|
112
106
|
continue;
|
|
113
107
|
}
|
|
114
|
-
const mileagePackageAdd = baseline *
|
|
115
|
-
pricingData.fluxPricing.matrixCoefficients.add[mileagePackage];
|
|
108
|
+
const mileagePackageAdd = baseline * pricingData.fluxPricing.matrixCoefficients.add[mileagePackage];
|
|
116
109
|
const cutomMileagePackageAdd = customMileagePackage?.[mileagePackage];
|
|
117
110
|
const basePlanMileagePackagePricing = newMatrix[targetPlan][baseMileagePackage];
|
|
118
|
-
newMatrix[plan][mileagePackage] = decimals(round(basePlanMileagePackagePricing +
|
|
119
|
-
(cutomMileagePackageAdd || mileagePackageAdd)));
|
|
111
|
+
newMatrix[plan][mileagePackage] = decimals(round(basePlanMileagePackagePricing + (cutomMileagePackageAdd || mileagePackageAdd)));
|
|
120
112
|
}
|
|
121
113
|
}
|
|
122
114
|
return sortMatrix(newMatrix);
|
|
123
115
|
};
|
|
124
|
-
export const updateMatrixWithCustomPackages = (matrix, add)
|
|
116
|
+
export const updateMatrixWithCustomPackages = (matrix, add)=>{
|
|
125
117
|
const newMatrix = cloneDeep(matrix);
|
|
126
118
|
const plans = getVehicleDataVariant(PLANS, 'car');
|
|
127
119
|
const mileagePackages = getVehicleDataVariant(MILEAGE_PACKAGES, 'car');
|
|
128
120
|
const baseMileagePackage = mileagePackages[0];
|
|
129
|
-
for (const plan of plans)
|
|
130
|
-
for (const mileagePackage of mileagePackages)
|
|
121
|
+
for (const plan of plans){
|
|
122
|
+
for (const mileagePackage of mileagePackages){
|
|
131
123
|
if (mileagePackage === baseMileagePackage) {
|
|
132
124
|
continue;
|
|
133
125
|
}
|
|
134
126
|
const toAdd = add[mileagePackage];
|
|
135
127
|
if (toAdd) {
|
|
136
|
-
newMatrix[plan][mileagePackage] =
|
|
137
|
-
(newMatrix[plan]?.[baseMileagePackage] || 0) + toAdd;
|
|
128
|
+
newMatrix[plan][mileagePackage] = (newMatrix[plan]?.[baseMileagePackage] || 0) + toAdd;
|
|
138
129
|
}
|
|
139
130
|
}
|
|
140
131
|
}
|
|
141
132
|
return newMatrix;
|
|
142
133
|
};
|
|
143
|
-
export const getFluxExcessMileage = (pricingData, baseline)
|
|
134
|
+
export const getFluxExcessMileage = (pricingData, baseline)=>{
|
|
144
135
|
return decimals(Math.max(Math.min(baseline * pricingData.fluxPricing.matrixCoefficients.excessMileage, pricingData.fluxPricing.excessMileage.upperBound), pricingData.fluxPricing.excessMileage.lowerBound));
|
|
145
136
|
};
|
|
146
137
|
/**
|
|
@@ -149,21 +140,16 @@ export const getFluxExcessMileage = (pricingData, baseline) => {
|
|
|
149
140
|
* @param coefficient
|
|
150
141
|
*
|
|
151
142
|
* @see https://docs.google.com/spreadsheets/d/1lYYMdQgnzG53lCGf_dKJY9pEue5suJuo3O3-zegIOT0/edit#gid=819271234
|
|
152
|
-
*/
|
|
153
|
-
export const getStartFeeMatrix = (pricingData, baseline, flatPricing) => {
|
|
143
|
+
*/ export const getStartFeeMatrix = (pricingData, baseline, flatPricing)=>{
|
|
154
144
|
// Let's not mutate percentages
|
|
155
145
|
const newMatrix = cloneDeep(pricingData.startFee.matrixCoefficients);
|
|
156
146
|
const baseCoefficients = cloneDeep(newMatrix.plan36);
|
|
157
147
|
const plans = Object.keys(newMatrix);
|
|
158
|
-
for (const plan of plans)
|
|
148
|
+
for (const plan of plans){
|
|
159
149
|
const mileagePackages = Object.keys(newMatrix[plan]);
|
|
160
|
-
for (const mileagePackage of mileagePackages)
|
|
161
|
-
newMatrix[plan][mileagePackage] = round(baseline *
|
|
162
|
-
(flatPricing
|
|
163
|
-
? baseCoefficients[mileagePackage]
|
|
164
|
-
: newMatrix[plan][mileagePackage]));
|
|
150
|
+
for (const mileagePackage of mileagePackages){
|
|
151
|
+
newMatrix[plan][mileagePackage] = round(baseline * (flatPricing ? baseCoefficients[mileagePackage] : newMatrix[plan][mileagePackage]));
|
|
165
152
|
}
|
|
166
153
|
}
|
|
167
154
|
return sortMatrix(newMatrix);
|
|
168
155
|
};
|
|
169
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
export {};
|
|
2
|
-
//# sourceMappingURL=types.js.map
|
|
1
|
+
export { };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@driveflux/api-functions",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.137",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
"./notion": {
|
|
@@ -73,14 +73,14 @@
|
|
|
73
73
|
],
|
|
74
74
|
"dependencies": {
|
|
75
75
|
"@casl/ability": "^6.7.3",
|
|
76
|
-
"@driveflux/auth": "4.0.
|
|
76
|
+
"@driveflux/auth": "4.0.78",
|
|
77
77
|
"@driveflux/billing": "8.1.4",
|
|
78
78
|
"@driveflux/config": "3.0.9",
|
|
79
79
|
"@driveflux/coupon": "9.1.9",
|
|
80
80
|
"@driveflux/db": "4.1.8",
|
|
81
81
|
"@driveflux/email": "7.1.8",
|
|
82
82
|
"@driveflux/email-templates": "1.2.9",
|
|
83
|
-
"@driveflux/engine": "1.1.
|
|
83
|
+
"@driveflux/engine": "1.1.22",
|
|
84
84
|
"@driveflux/fetch": "8.0.1",
|
|
85
85
|
"@driveflux/format-money": "7.0.0",
|
|
86
86
|
"@driveflux/logger": "1.1.3",
|
|
@@ -89,7 +89,7 @@
|
|
|
89
89
|
"@driveflux/result": "6.0.1",
|
|
90
90
|
"@driveflux/scheduler": "8.1.9",
|
|
91
91
|
"@driveflux/singleton": "3.0.0",
|
|
92
|
-
"@driveflux/subscription": "9.1.
|
|
92
|
+
"@driveflux/subscription": "9.1.6",
|
|
93
93
|
"@driveflux/time": "6.0.2",
|
|
94
94
|
"@driveflux/utils": "6.0.0",
|
|
95
95
|
"@notionhq/client": "^5.3.0",
|