@driveflux/api-functions 1.0.148 → 1.0.149

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/dist/auth/confirm.js +24 -24
  2. package/dist/auth/consent.js +22 -27
  3. package/dist/auth/emails.js +12 -13
  4. package/dist/auth/formatter.js +5 -5
  5. package/dist/auth/otp.js +66 -50
  6. package/dist/auth/register.js +48 -35
  7. package/dist/auth/tokens.js +58 -55
  8. package/dist/auth/verifications.js +53 -52
  9. package/dist/constants.js +0 -1
  10. package/dist/create-logger.js +1 -2
  11. package/dist/mailjet/calls/manage-contacts-in-list.js +5 -6
  12. package/dist/mailjet/calls/manage-subscription-status.js +4 -5
  13. package/dist/mailjet/calls/request-service.js +7 -6
  14. package/dist/mailjet/refresh-email-preferences.js +11 -12
  15. package/dist/mailjet/set-contact.js +11 -12
  16. package/dist/mailjet/types.js +1 -2
  17. package/dist/mailjet/utils/convert-to-array.js +8 -6
  18. package/dist/mailjet/utils/extract-email-preferences.js +14 -15
  19. package/dist/mailjet/utils/lists.js +7 -8
  20. package/dist/mailjet/utils/update-email-references.js +16 -15
  21. package/dist/notion/client.js +22 -19
  22. package/dist/notion/helpful.js +6 -9
  23. package/dist/notion/schemas/block.js +42 -48
  24. package/dist/notion/schemas/common.js +9 -14
  25. package/dist/notion/schemas/database.js +62 -60
  26. package/dist/notion/schemas/emoji.js +1 -2
  27. package/dist/notion/schemas/file.js +9 -9
  28. package/dist/notion/schemas/kb.js +5 -6
  29. package/dist/notion/schemas/page.js +72 -61
  30. package/dist/notion/schemas/parent.js +4 -5
  31. package/dist/notion/schemas/user.js +18 -19
  32. package/dist/reservation/agree.js +2 -3
  33. package/dist/reservation/checks.js +3 -4
  34. package/dist/reservation/display-vehicle.js +73 -83
  35. package/dist/reservation/ensure-user-billing-address.js +9 -11
  36. package/dist/reservation/fetch-or-create.js +49 -56
  37. package/dist/reservation/invoice.js +77 -88
  38. package/dist/reservation/payer.js +5 -6
  39. package/dist/reservation/payment-intent-sync.js +4 -6
  40. package/dist/reservation/reserve.js +3 -4
  41. package/dist/reservation/types.js +1 -2
  42. package/dist/reservation/vehicle.js +13 -16
  43. package/dist/slack.js +24 -29
  44. package/dist/validation.js +81 -85
  45. package/dist/vehicle/vehicle-pricing/constants.js +22 -19
  46. package/dist/vehicle/vehicle-pricing/index.js +28 -42
  47. package/dist/vehicle/vehicle-pricing/types.js +1 -2
  48. package/package.json +8 -8
@@ -1,34 +1,32 @@
1
1
  import { makeProblem } from '@driveflux/problem';
2
2
  import { Err } from '@driveflux/result';
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
- }));
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) => z.union([
16
- z.string(),
17
- z
18
- .object({ object: z.literal(object), ...extendObjectValidation })
19
- .passthrough()
20
- .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
- });
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,70 +69,71 @@ 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) => z.enum([o]).optional();
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) => (typeof f === 'string' ? f.toLowerCase() : f), z.enum(['jpg', 'jpeg', 'png', 'pdf', 'image']).optional()),
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: ['1', 'true', 'yes'],
107
- falsy: ['0', 'false', 'no'],
108
- });
109
- export const getStringToNumberValidator = (numberValidation) => z.codec(z.string().regex(z.regexes.number), numberValidation ?? z.number(), {
110
- decode: (str) => Number.parseFloat(str),
111
- encode: (num) => num.toString(),
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
- export const queryStringArrayValidator = z
115
- .codec(z.string(), z.array(z.string()), {
116
- encode: (value) => value.join(','),
117
- decode: (value) => value.split(','),
118
- })
119
- .or(z.array(z.string()));
121
+ export const queryStringArrayValidator = z.codec(z.string(), z.array(z.string()), {
122
+ encode: (value)=>value.join(','),
123
+ decode: (value)=>value.split(',')
124
+ }).or(z.array(z.string()));
120
125
  export function queryEnumArrayValidator(enumOrValidation) {
121
126
  // Handle ZodEnum case
122
- if (enumOrValidation &&
123
- typeof enumOrValidation === 'object' &&
124
- '_zod' in enumOrValidation) {
125
- return z
126
- .codec(z.string(), z.array(enumOrValidation), {
127
- encode: (value) => value.join(','),
128
- decode: (value) => value.split(','),
129
- })
130
- .or(z.array(enumOrValidation));
127
+ if (enumOrValidation && typeof enumOrValidation === 'object' && '_zod' in enumOrValidation) {
128
+ return z.codec(z.string(), z.array(enumOrValidation), {
129
+ encode: (value)=>value.join(','),
130
+ decode: (value)=>value.split(',')
131
+ }).or(z.array(enumOrValidation));
131
132
  }
132
133
  // Handle array or enum-like object case
133
- const enumSchema = Array.isArray(enumOrValidation)
134
- ? z.enum(enumOrValidation)
135
- : z.enum(Object.values(enumOrValidation));
136
- return z
137
- .codec(z.string(), z.array(enumSchema), {
138
- encode: (value) => value.join(','),
139
- decode: (value) => value.split(','),
140
- })
141
- .or(z.array(enumSchema));
134
+ const enumSchema = Array.isArray(enumOrValidation) ? z.enum(enumOrValidation) : z.enum(Object.values(enumOrValidation));
135
+ return z.codec(z.string(), z.array(enumSchema), {
136
+ encode: (value)=>value.join(','),
137
+ decode: (value)=>value.split(',')
138
+ }).or(z.array(enumSchema));
142
139
  }
143
- //# sourceMappingURL=validation.js.map
@@ -1,18 +1,23 @@
1
- const DEFAUALT_MILEAGE_MATRIX = { lite: 0, standard: 0, plus: 0, unlimited: 0 };
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.148",
3
+ "version": "1.0.149",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  "./notion": {
@@ -73,21 +73,21 @@
73
73
  ],
74
74
  "dependencies": {
75
75
  "@casl/ability": "^6.7.3",
76
- "@driveflux/auth": "4.0.86",
76
+ "@driveflux/auth": "4.0.87",
77
77
  "@driveflux/billing": "8.1.6",
78
78
  "@driveflux/config": "3.0.10",
79
- "@driveflux/coupon": "9.1.19",
80
- "@driveflux/db": "4.1.18",
81
- "@driveflux/email": "7.1.19",
82
- "@driveflux/email-templates": "1.2.19",
83
- "@driveflux/engine": "1.1.38",
79
+ "@driveflux/coupon": "9.1.20",
80
+ "@driveflux/db": "4.1.19",
81
+ "@driveflux/email": "7.1.20",
82
+ "@driveflux/email-templates": "1.2.20",
83
+ "@driveflux/engine": "1.1.40",
84
84
  "@driveflux/fetch": "8.0.1",
85
85
  "@driveflux/format-money": "7.0.0",
86
86
  "@driveflux/logger": "1.1.3",
87
87
  "@driveflux/problem": "6.0.1",
88
88
  "@driveflux/reporter": "7.0.2",
89
89
  "@driveflux/result": "6.0.1",
90
- "@driveflux/scheduler": "8.1.19",
90
+ "@driveflux/scheduler": "8.1.20",
91
91
  "@driveflux/singleton": "3.0.0",
92
92
  "@driveflux/subscription": "9.1.9",
93
93
  "@driveflux/time": "6.0.2",