@driveflux/api-functions 1.0.43 → 1.0.44
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 +29 -24
- package/dist/auth/emails.js +13 -12
- package/dist/auth/formatter.js +5 -5
- package/dist/auth/otp.js +50 -66
- package/dist/auth/register.js +34 -42
- package/dist/auth/tokens.js +55 -58
- package/dist/auth/verifications.js +52 -53
- package/dist/constants.js +1 -0
- package/dist/create-logger.js +2 -1
- package/dist/mailjet/calls/manage-contacts-in-list.js +6 -5
- package/dist/mailjet/calls/manage-subscription-status.js +5 -4
- package/dist/mailjet/calls/request-service.js +6 -7
- package/dist/mailjet/refresh-email-preferences.js +12 -11
- package/dist/mailjet/set-contact.js +12 -11
- package/dist/mailjet/types.js +2 -1
- package/dist/mailjet/utils/convert-to-array.js +6 -8
- package/dist/mailjet/utils/extract-email-preferences.js +15 -14
- package/dist/mailjet/utils/lists.js +8 -7
- package/dist/mailjet/utils/update-email-references.js +15 -16
- package/dist/notion/client.js +19 -22
- package/dist/notion/helpful.js +9 -6
- package/dist/notion/schemas/block.js +48 -42
- package/dist/notion/schemas/common.js +14 -9
- package/dist/notion/schemas/database.js +60 -62
- package/dist/notion/schemas/emoji.js +2 -1
- package/dist/notion/schemas/file.js +9 -9
- package/dist/notion/schemas/kb.js +6 -5
- package/dist/notion/schemas/page.js +61 -72
- package/dist/notion/schemas/parent.js +5 -4
- package/dist/notion/schemas/user.js +19 -18
- package/dist/reservation/agree.js +7 -6
- package/dist/reservation/checks.js +4 -3
- package/dist/reservation/display-vehicle.js +71 -65
- package/dist/reservation/ensure-user-billing-address.js +11 -9
- package/dist/reservation/fetch-or-create.js +54 -48
- package/dist/reservation/invoice.js +78 -70
- package/dist/reservation/payer.js +6 -5
- package/dist/reservation/payment-intent-sync.js +6 -4
- package/dist/reservation/reserve.js +4 -3
- package/dist/reservation/types.js +2 -1
- package/dist/reservation/vehicle.js +16 -13
- package/dist/slack.js +29 -24
- package/dist/validation.js +79 -77
- package/dist/vehicle/vehicle-pricing/constants.js +19 -22
- package/dist/vehicle/vehicle-pricing/index.js +42 -28
- package/dist/vehicle/vehicle-pricing/types.js +2 -1
- package/package.json +2 -2
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { config } from '@driveflux/config/backend';
|
|
2
2
|
import { loadCoupon, PROBLEM_APPLICABLE_NOT_FOUND } from '@driveflux/coupon';
|
|
3
|
-
import { prisma } from '@driveflux/db';
|
|
3
|
+
import { prisma, } from '@driveflux/db';
|
|
4
4
|
import { generateId } from '@driveflux/db/id';
|
|
5
5
|
import { EMPTY_BILLING_ADDRESS } from '@driveflux/db/models/other';
|
|
6
6
|
import { PURPOSE_RESERVATION } from '@driveflux/db/models/subscription';
|
|
@@ -14,15 +14,16 @@ import { isAfter } from 'date-fns/isAfter';
|
|
|
14
14
|
import { subMinutes } from 'date-fns/subMinutes';
|
|
15
15
|
import { createScopedLogger } from '../create-logger.js';
|
|
16
16
|
const log = createScopedLogger('reservation:invoice');
|
|
17
|
-
export const updateReservationInvoiceIfNeeded = async (oldReservationInvoice, newParams)=>{
|
|
17
|
+
export const updateReservationInvoiceIfNeeded = async (oldReservationInvoice, newParams) => {
|
|
18
18
|
const couponIsDifferent = oldReservationInvoice.couponCode !== newParams.couponCode;
|
|
19
|
-
if (!couponIsDifferent &&
|
|
19
|
+
if (!couponIsDifferent &&
|
|
20
|
+
oldReservationInvoice.stripePaymentIntentId === newParams.paymentIntentId) {
|
|
20
21
|
return new Ok(oldReservationInvoice);
|
|
21
22
|
}
|
|
22
23
|
// If the coupon or payment intent are differnt we should update the invoice
|
|
23
24
|
let update = {
|
|
24
25
|
stripePaymentIntentId: newParams.paymentIntentId,
|
|
25
|
-
couponCode: newParams.couponCode
|
|
26
|
+
couponCode: newParams.couponCode,
|
|
26
27
|
};
|
|
27
28
|
// If the coupon is different, we need to apply the coupon to the invoice
|
|
28
29
|
if (couponIsDifferent) {
|
|
@@ -30,56 +31,63 @@ export const updateReservationInvoiceIfNeeded = async (oldReservationInvoice, ne
|
|
|
30
31
|
const result = await coupons.applyCouponToUnsavedInvoice(newParams.couponCode, oldReservationInvoice);
|
|
31
32
|
if (result.ok) {
|
|
32
33
|
const { discounts, ...rest } = result.val;
|
|
33
|
-
const toDisconnect = discounts
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
34
|
+
const toDisconnect = discounts
|
|
35
|
+
? oldReservationInvoice.discountIds?.filter((id) => !discounts.connect?.some((d) => d.id === id))
|
|
36
|
+
: undefined;
|
|
37
|
+
const disconnectClauses = toDisconnect?.length
|
|
38
|
+
? {
|
|
39
|
+
disconnect: toDisconnect.map((id) => ({ id })),
|
|
40
|
+
}
|
|
41
|
+
: undefined;
|
|
39
42
|
update = {
|
|
40
43
|
...update,
|
|
41
44
|
...rest,
|
|
42
|
-
...discounts || disconnectClauses
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
45
|
+
...(discounts || disconnectClauses
|
|
46
|
+
? {
|
|
47
|
+
discounts: {
|
|
48
|
+
...(discounts || {}),
|
|
49
|
+
...(disconnectClauses || {}),
|
|
50
|
+
},
|
|
46
51
|
}
|
|
47
|
-
|
|
52
|
+
: {}),
|
|
48
53
|
metadata: {
|
|
49
54
|
...update.metadata,
|
|
50
|
-
couponCode: newParams.couponCode
|
|
55
|
+
couponCode: newParams.couponCode,
|
|
51
56
|
},
|
|
52
57
|
providerMetadata: {
|
|
53
58
|
...update.providerMetadata,
|
|
54
|
-
couponCode: newParams.couponCode
|
|
55
|
-
}
|
|
59
|
+
couponCode: newParams.couponCode,
|
|
60
|
+
},
|
|
56
61
|
};
|
|
57
62
|
}
|
|
58
63
|
if (result.err && result.val.code !== PROBLEM_APPLICABLE_NOT_FOUND) {
|
|
59
64
|
return result;
|
|
60
65
|
}
|
|
61
|
-
}
|
|
66
|
+
}
|
|
67
|
+
else if (oldReservationInvoice.discountIds.length) {
|
|
62
68
|
// No discounts, so we disconnect all of them
|
|
63
69
|
update = {
|
|
64
70
|
discounts: {
|
|
65
|
-
disconnect: oldReservationInvoice.discountIds.map((id)=>({
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
}
|
|
71
|
+
disconnect: oldReservationInvoice.discountIds.map((id) => ({
|
|
72
|
+
id,
|
|
73
|
+
})),
|
|
74
|
+
},
|
|
69
75
|
};
|
|
70
76
|
}
|
|
71
77
|
}
|
|
72
78
|
let updated = await wrapInResult(biller.updateInvoice(oldReservationInvoice.id, update));
|
|
73
79
|
// If the invoice was locked due to pending status and we're more than 1 minute old, we unlock it
|
|
74
80
|
if (updated.err && updated.val.code === 'invoice_pending') {
|
|
75
|
-
if (oldReservationInvoice.lockedAt &&
|
|
81
|
+
if ((oldReservationInvoice.lockedAt &&
|
|
82
|
+
isAfter(oldReservationInvoice.lockedAt, subMinutes(new Date(), 1))) ||
|
|
83
|
+
!oldReservationInvoice.lockedAt) {
|
|
76
84
|
updated = await wrapInResult(biller.updateInvoice(oldReservationInvoice.id, {
|
|
77
85
|
...update,
|
|
78
86
|
locked: false,
|
|
79
87
|
lockedAt: null,
|
|
80
88
|
lockReason: null,
|
|
81
89
|
unlockAt: null,
|
|
82
|
-
status: 'draft'
|
|
90
|
+
status: 'draft',
|
|
83
91
|
}));
|
|
84
92
|
}
|
|
85
93
|
}
|
|
@@ -88,7 +96,7 @@ export const updateReservationInvoiceIfNeeded = async (oldReservationInvoice, ne
|
|
|
88
96
|
}
|
|
89
97
|
return new Ok(updated.val);
|
|
90
98
|
};
|
|
91
|
-
export const createReservationInvoice = async ({ invoiceId, couponCode, plan, mileagePackage, referralCode, reservationId, paymentIntentId, freeReservation, freeReservationReason, analytics, vehicle, payer, subscribingUser })=>{
|
|
99
|
+
export const createReservationInvoice = async ({ invoiceId, couponCode, plan, mileagePackage, referralCode, reservationId, paymentIntentId, freeReservation, freeReservationReason, analytics, vehicle, payer, subscribingUser, }) => {
|
|
92
100
|
if (freeReservation) {
|
|
93
101
|
// It's a free reservation, so we don't need to add a coupon code
|
|
94
102
|
return await wrapInResult(biller.createInvoice(getInvoiceCreateDetails({
|
|
@@ -101,17 +109,21 @@ export const createReservationInvoice = async ({ invoiceId, couponCode, plan, mi
|
|
|
101
109
|
freeReservation,
|
|
102
110
|
freeReservationReason,
|
|
103
111
|
analytics,
|
|
104
|
-
reservationId
|
|
112
|
+
reservationId,
|
|
105
113
|
})));
|
|
106
114
|
}
|
|
107
115
|
let finalCouponCode = couponCode;
|
|
108
116
|
// If we don't have a reservation coupon ID, we apply the referral discount if any
|
|
109
|
-
const referral = referralCode &&
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
117
|
+
const referral = referralCode &&
|
|
118
|
+
(await prisma.referral.findUnique({
|
|
119
|
+
where: {
|
|
120
|
+
id: referralCode,
|
|
121
|
+
},
|
|
122
|
+
}));
|
|
123
|
+
if (!finalCouponCode &&
|
|
124
|
+
referral &&
|
|
125
|
+
referral.discountToReceiverCouponId &&
|
|
126
|
+
referral.discountToReceiverCouponApplicationName === 'reservationFee') {
|
|
115
127
|
const referralCoupon = await loadCoupon(referral.discountToReceiverCouponId);
|
|
116
128
|
if (referralCoupon) {
|
|
117
129
|
finalCouponCode = referralCoupon.code;
|
|
@@ -130,20 +142,18 @@ export const createReservationInvoice = async ({ invoiceId, couponCode, plan, mi
|
|
|
130
142
|
freeReservation,
|
|
131
143
|
freeReservationReason,
|
|
132
144
|
analytics,
|
|
133
|
-
reservationId
|
|
145
|
+
reservationId,
|
|
134
146
|
}),
|
|
135
147
|
lines: [
|
|
136
148
|
{
|
|
137
149
|
amount: reservationAmount,
|
|
138
150
|
description: `Reservation fee for ${vehicleName(vehicle)}`,
|
|
139
|
-
chargingFor: 'reservationFee'
|
|
140
|
-
}
|
|
141
|
-
]
|
|
151
|
+
chargingFor: 'reservationFee',
|
|
152
|
+
},
|
|
153
|
+
],
|
|
142
154
|
};
|
|
143
155
|
if (finalCouponCode) {
|
|
144
|
-
log.debug({
|
|
145
|
-
finalCouponCode
|
|
146
|
-
}, 'Applying coupon code to invoice');
|
|
156
|
+
log.debug({ finalCouponCode }, 'Applying coupon code to invoice');
|
|
147
157
|
const withCoupon = await coupons.applyCouponToUnsavedInvoice(finalCouponCode, invoiceCreateDetails, 'reservationFee', {
|
|
148
158
|
subscriptionPlans: plan,
|
|
149
159
|
subscriptionMileagePackages: mileagePackage,
|
|
@@ -151,25 +161,24 @@ export const createReservationInvoice = async ({ invoiceId, couponCode, plan, mi
|
|
|
151
161
|
vehicleMake: vehicle.make,
|
|
152
162
|
userId: subscribingUser.id,
|
|
153
163
|
businessId: payer.object === 'business' ? payer.id : undefined,
|
|
154
|
-
vehicleType: vehicle.type
|
|
164
|
+
vehicleType: vehicle.type,
|
|
155
165
|
});
|
|
156
|
-
if (withCoupon.err &&
|
|
166
|
+
if (withCoupon.err &&
|
|
167
|
+
withCoupon.val.code !== PROBLEM_APPLICABLE_NOT_FOUND) {
|
|
157
168
|
return withCoupon;
|
|
158
169
|
}
|
|
159
|
-
log.debug({
|
|
160
|
-
couponUpdates: withCoupon.val
|
|
161
|
-
}, 'Coupon applied to invoice');
|
|
170
|
+
log.debug({ couponUpdates: withCoupon.val }, 'Coupon applied to invoice');
|
|
162
171
|
if (withCoupon.ok) {
|
|
163
172
|
invoiceCreateDetails = {
|
|
164
173
|
...withCoupon.val,
|
|
165
174
|
metadata: {
|
|
166
175
|
...withCoupon.val.metadata,
|
|
167
|
-
couponCode: finalCouponCode
|
|
176
|
+
couponCode: finalCouponCode,
|
|
168
177
|
},
|
|
169
178
|
providerMetadata: {
|
|
170
179
|
...withCoupon.val.providerMetadata,
|
|
171
|
-
couponCode: finalCouponCode
|
|
172
|
-
}
|
|
180
|
+
couponCode: finalCouponCode,
|
|
181
|
+
},
|
|
173
182
|
};
|
|
174
183
|
}
|
|
175
184
|
}
|
|
@@ -177,15 +186,15 @@ export const createReservationInvoice = async ({ invoiceId, couponCode, plan, mi
|
|
|
177
186
|
...invoiceCreateDetails,
|
|
178
187
|
providerMetadata: {
|
|
179
188
|
...invoiceCreateDetails.providerMetadata,
|
|
180
|
-
invoiceId: invoiceCreateDetails.id
|
|
181
|
-
}
|
|
189
|
+
invoiceId: invoiceCreateDetails.id,
|
|
190
|
+
},
|
|
182
191
|
}));
|
|
183
192
|
if (result.err) {
|
|
184
193
|
return result;
|
|
185
194
|
}
|
|
186
195
|
return new Ok(result.val);
|
|
187
196
|
};
|
|
188
|
-
const getInvoiceCreateDetails = ({ invoiceId, payer, date, reservationDiscountId, vehicle, plan, mileagePackage, couponCode, paymentIntentId, freeReservation, freeReservationReason, analytics, reservationId })=>{
|
|
197
|
+
const getInvoiceCreateDetails = ({ invoiceId, payer, date, reservationDiscountId, vehicle, plan, mileagePackage, couponCode, paymentIntentId, freeReservation, freeReservationReason, analytics, reservationId, }) => {
|
|
189
198
|
return {
|
|
190
199
|
id: invoiceId || generateId('Invoice'),
|
|
191
200
|
taxPercentage: 0,
|
|
@@ -201,13 +210,15 @@ const getInvoiceCreateDetails = ({ invoiceId, payer, date, reservationDiscountId
|
|
|
201
210
|
description: 'Reservation fee for a FLUX subscription',
|
|
202
211
|
footer: `Invoice for a FLUX subscription reservation. Due by ${format(date ?? new Date())}`,
|
|
203
212
|
invoiceUrl: `${config.appUrl}/invoice-preview/${invoiceId}`,
|
|
204
|
-
...reservationDiscountId
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
213
|
+
...(reservationDiscountId
|
|
214
|
+
? {
|
|
215
|
+
discounts: {
|
|
216
|
+
connect: {
|
|
217
|
+
id: reservationDiscountId,
|
|
218
|
+
},
|
|
219
|
+
},
|
|
209
220
|
}
|
|
210
|
-
|
|
221
|
+
: {}),
|
|
211
222
|
lines: [],
|
|
212
223
|
subscriptionDetails: {
|
|
213
224
|
vehicleId: vehicle.id,
|
|
@@ -216,7 +227,7 @@ const getInvoiceCreateDetails = ({ invoiceId, payer, date, reservationDiscountId
|
|
|
216
227
|
variant: vehicle.variant,
|
|
217
228
|
year: vehicle.year,
|
|
218
229
|
plan: plan,
|
|
219
|
-
mileagePackage: mileagePackage
|
|
230
|
+
mileagePackage: mileagePackage,
|
|
220
231
|
},
|
|
221
232
|
// Legacy field:
|
|
222
233
|
stripePaymentIntentId: paymentIntentId,
|
|
@@ -226,18 +237,14 @@ const getInvoiceCreateDetails = ({ invoiceId, payer, date, reservationDiscountId
|
|
|
226
237
|
mileagePackage,
|
|
227
238
|
vehicleId: vehicle.id,
|
|
228
239
|
vehicleName: vehicleName(vehicle),
|
|
229
|
-
...reservationId ? {
|
|
230
|
-
|
|
231
|
-
} : {},
|
|
232
|
-
...couponCode ? {
|
|
233
|
-
couponCode
|
|
234
|
-
} : {}
|
|
240
|
+
...(reservationId ? { reservationId } : {}),
|
|
241
|
+
...(couponCode ? { couponCode } : {}),
|
|
235
242
|
},
|
|
236
243
|
autoRetry: {
|
|
237
244
|
enabled: false,
|
|
238
245
|
interval: 0,
|
|
239
246
|
maxAttempts: 0,
|
|
240
|
-
attempts: 0
|
|
247
|
+
attempts: 0,
|
|
241
248
|
},
|
|
242
249
|
metadata: {
|
|
243
250
|
purpose: PURPOSE_RESERVATION,
|
|
@@ -246,10 +253,11 @@ const getInvoiceCreateDetails = ({ invoiceId, payer, date, reservationDiscountId
|
|
|
246
253
|
plan,
|
|
247
254
|
mileagePackage,
|
|
248
255
|
couponCode,
|
|
249
|
-
...freeReservation && freeReservationReason
|
|
250
|
-
freeReservationReason
|
|
251
|
-
|
|
252
|
-
analytics
|
|
253
|
-
}
|
|
256
|
+
...(freeReservation && freeReservationReason
|
|
257
|
+
? { freeReservationReason }
|
|
258
|
+
: {}),
|
|
259
|
+
analytics,
|
|
260
|
+
},
|
|
254
261
|
};
|
|
255
262
|
};
|
|
263
|
+
//# sourceMappingURL=invoice.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { prisma } from '@driveflux/db';
|
|
2
|
-
import { makeProblem, PROBLEM_CONDITION_FAILED, PROBLEM_NOT_FOUND } from '@driveflux/problem';
|
|
2
|
+
import { makeProblem, PROBLEM_CONDITION_FAILED, PROBLEM_NOT_FOUND, } from '@driveflux/problem';
|
|
3
3
|
import { Err, Ok } from '@driveflux/result';
|
|
4
|
-
export const getPayer = async ({ subscribingUser, asBusiness })=>{
|
|
4
|
+
export const getPayer = async ({ subscribingUser, asBusiness, }) => {
|
|
5
5
|
let business = null;
|
|
6
6
|
let payer = subscribingUser;
|
|
7
7
|
if (asBusiness) {
|
|
@@ -11,8 +11,8 @@ export const getPayer = async ({ subscribingUser, asBusiness })=>{
|
|
|
11
11
|
// load business
|
|
12
12
|
business = await prisma.business.findUnique({
|
|
13
13
|
where: {
|
|
14
|
-
id: subscribingUser.businessId
|
|
15
|
-
}
|
|
14
|
+
id: subscribingUser.businessId,
|
|
15
|
+
},
|
|
16
16
|
});
|
|
17
17
|
if (!business) {
|
|
18
18
|
return new Err(makeProblem(PROBLEM_NOT_FOUND, `The business ${subscribingUser.businessId} was not found.`));
|
|
@@ -26,7 +26,7 @@ export const getPayer = async ({ subscribingUser, asBusiness })=>{
|
|
|
26
26
|
}
|
|
27
27
|
return new Ok(payer);
|
|
28
28
|
};
|
|
29
|
-
const checkPayerObjectSanity = (subscriber)=>{
|
|
29
|
+
const checkPayerObjectSanity = (subscriber) => {
|
|
30
30
|
if (!subscriber.email) {
|
|
31
31
|
return new Err(makeProblem(PROBLEM_CONDITION_FAILED, `Subscriber ${subscriber.id} has no email. Please add a verified email first.`));
|
|
32
32
|
}
|
|
@@ -35,3 +35,4 @@ const checkPayerObjectSanity = (subscriber)=>{
|
|
|
35
35
|
}
|
|
36
36
|
return new Ok(true);
|
|
37
37
|
};
|
|
38
|
+
//# sourceMappingURL=payer.js.map
|
|
@@ -3,18 +3,20 @@ import { makeProblem, PROBLEM_EXTERNAL } from '@driveflux/problem';
|
|
|
3
3
|
import { Err, Ok } from '@driveflux/result';
|
|
4
4
|
import { createScopedLogger } from '../create-logger.js';
|
|
5
5
|
const log = createScopedLogger('reservation:payment-intent-sync');
|
|
6
|
-
export const ensurePaymentIntentIdIsSynced = async (invoice, paymentIntentId)=>{
|
|
6
|
+
export const ensurePaymentIntentIdIsSynced = async (invoice, paymentIntentId) => {
|
|
7
7
|
const stripe = biller.getPaymentProvider('stripe').getStripe();
|
|
8
8
|
try {
|
|
9
9
|
await stripe.paymentIntents.update(paymentIntentId, {
|
|
10
10
|
metadata: {
|
|
11
11
|
...invoice.providerMetadata,
|
|
12
|
-
invoiceId: invoice.id
|
|
13
|
-
}
|
|
12
|
+
invoiceId: invoice.id,
|
|
13
|
+
},
|
|
14
14
|
});
|
|
15
15
|
return new Ok(true);
|
|
16
|
-
}
|
|
16
|
+
}
|
|
17
|
+
catch (error) {
|
|
17
18
|
log.error(error, 'Error updating payment intent metadata');
|
|
18
19
|
return new Err(makeProblem(PROBLEM_EXTERNAL, 'Error updating payment intent metadata'));
|
|
19
20
|
}
|
|
20
21
|
};
|
|
22
|
+
//# sourceMappingURL=payment-intent-sync.js.map
|
|
@@ -6,14 +6,14 @@ import { fetchOrCreateReservation } from './fetch-or-create.js';
|
|
|
6
6
|
import { getPayer } from './payer.js';
|
|
7
7
|
import { ensurePaymentIntentIdIsSynced } from './payment-intent-sync.js';
|
|
8
8
|
import { getVehicle } from './vehicle.js';
|
|
9
|
-
const processBody = (body)=>{
|
|
9
|
+
const processBody = (body) => {
|
|
10
10
|
// Switch mileage package
|
|
11
11
|
if (body.plan === 'plan1' || body.plan === 'planWeekly') {
|
|
12
12
|
body.mileagePackage = 'unlimited';
|
|
13
13
|
}
|
|
14
14
|
return body;
|
|
15
15
|
};
|
|
16
|
-
export const reserveVehicle = async (vehicleId, unprocessed)=>{
|
|
16
|
+
export const reserveVehicle = async (vehicleId, unprocessed) => {
|
|
17
17
|
const body = processBody(unprocessed);
|
|
18
18
|
// Agree to terms if not done yet
|
|
19
19
|
await handleAgreeToTerms(body);
|
|
@@ -41,7 +41,7 @@ export const reserveVehicle = async (vehicleId, unprocessed)=>{
|
|
|
41
41
|
const reservationResult = await fetchOrCreateReservation({
|
|
42
42
|
vehicle,
|
|
43
43
|
payer,
|
|
44
|
-
body
|
|
44
|
+
body,
|
|
45
45
|
});
|
|
46
46
|
if (reservationResult.err) {
|
|
47
47
|
return reservationResult;
|
|
@@ -57,3 +57,4 @@ export const reserveVehicle = async (vehicleId, unprocessed)=>{
|
|
|
57
57
|
}
|
|
58
58
|
return new Ok(reservation);
|
|
59
59
|
};
|
|
60
|
+
//# sourceMappingURL=reserve.js.map
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export {};
|
|
2
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -4,19 +4,21 @@ import { makeProblem, PROBLEM_NOT_FOUND } from '@driveflux/problem';
|
|
|
4
4
|
import { Err, Ok } from '@driveflux/result';
|
|
5
5
|
import { checkIfVehicleIsAvailableForReservation } from './checks.js';
|
|
6
6
|
import { createVehicleFromDisplayVehicle } from './display-vehicle.js';
|
|
7
|
-
export const getVehicle = async (id, { selectedColor, plan, requestUser }, requesterAbility)=>{
|
|
8
|
-
const vehicle = id.startsWith('DV_')
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
7
|
+
export const getVehicle = async (id, { selectedColor, plan, requestUser, }, requesterAbility) => {
|
|
8
|
+
const vehicle = id.startsWith('DV_')
|
|
9
|
+
? await createVehicleFromDisplayVehicle(id, selectedColor || undefined)
|
|
10
|
+
: await prisma.vehicle.findUnique({
|
|
11
|
+
where: {
|
|
12
|
+
id,
|
|
13
|
+
},
|
|
14
|
+
include: {
|
|
15
|
+
host: {
|
|
16
|
+
select: {
|
|
17
|
+
id: true,
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
});
|
|
20
22
|
if (!vehicle) {
|
|
21
23
|
return new Err(makeProblem(PROBLEM_NOT_FOUND, 'Vehicle not found'));
|
|
22
24
|
}
|
|
@@ -27,3 +29,4 @@ export const getVehicle = async (id, { selectedColor, plan, requestUser }, reque
|
|
|
27
29
|
}
|
|
28
30
|
return new Ok(vehicle);
|
|
29
31
|
};
|
|
32
|
+
//# sourceMappingURL=vehicle.js.map
|
package/dist/slack.js
CHANGED
|
@@ -10,11 +10,12 @@ const slackBlocks = global.__slackBlocks;
|
|
|
10
10
|
/**
|
|
11
11
|
*
|
|
12
12
|
* @deprecated Use slackLater instead and commitSlack to commit
|
|
13
|
-
*/
|
|
13
|
+
*/
|
|
14
|
+
export const slack = async (message, channel = config.slack.defaultChannelId) => {
|
|
14
15
|
return await enhancedFetch('https://slack.com/api/chat.postMessage', {
|
|
15
16
|
method: 'POST',
|
|
16
17
|
headers: {
|
|
17
|
-
Authorization: `Bearer ${config.slack.token}
|
|
18
|
+
Authorization: `Bearer ${config.slack.token}`,
|
|
18
19
|
},
|
|
19
20
|
body: JSON.stringify({
|
|
20
21
|
channel,
|
|
@@ -23,20 +24,23 @@ const slackBlocks = global.__slackBlocks;
|
|
|
23
24
|
type: 'section',
|
|
24
25
|
text: {
|
|
25
26
|
type: 'mrkdwn',
|
|
26
|
-
text: message
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
]
|
|
30
|
-
})
|
|
27
|
+
text: message,
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
],
|
|
31
|
+
}),
|
|
31
32
|
});
|
|
32
33
|
};
|
|
33
|
-
export const getSlackBlocks = (channel)=>channel ? slackBlocks.get(channel) : slackBlocks;
|
|
34
|
+
export const getSlackBlocks = (channel) => channel ? slackBlocks.get(channel) : slackBlocks;
|
|
34
35
|
/**
|
|
35
36
|
* Naive implementation, however, for now (uncrowded serverless env), this works
|
|
36
37
|
* @param blocks
|
|
37
38
|
* @param channel
|
|
38
|
-
*/
|
|
39
|
-
|
|
39
|
+
*/
|
|
40
|
+
export function slackLater(blocks, channel) {
|
|
41
|
+
const targetChannel = (config.appEnv === 'production'
|
|
42
|
+
? channel
|
|
43
|
+
: config.slack.defaultChannelId) || config.slack.defaultChannelId;
|
|
40
44
|
if (!targetChannel || !blocks) {
|
|
41
45
|
return;
|
|
42
46
|
}
|
|
@@ -46,13 +50,15 @@ export const getSlackBlocks = (channel)=>channel ? slackBlocks.get(channel) : sl
|
|
|
46
50
|
type: 'section',
|
|
47
51
|
text: {
|
|
48
52
|
type: 'mrkdwn',
|
|
49
|
-
text: blocks
|
|
50
|
-
}
|
|
53
|
+
text: blocks,
|
|
54
|
+
},
|
|
51
55
|
});
|
|
52
|
-
}
|
|
56
|
+
}
|
|
57
|
+
else if (!Array.isArray(blocks)) {
|
|
53
58
|
messages.add(blocks);
|
|
54
|
-
}
|
|
55
|
-
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
for (const b of blocks) {
|
|
56
62
|
messages.add(b);
|
|
57
63
|
}
|
|
58
64
|
}
|
|
@@ -63,22 +69,22 @@ export async function sendSlackMessages(channel, blocks) {
|
|
|
63
69
|
return await enhancedFetch('https://slack.com/api/chat.postMessage', {
|
|
64
70
|
method: 'POST',
|
|
65
71
|
headers: {
|
|
66
|
-
Authorization: `Bearer ${config.slack.token}
|
|
72
|
+
Authorization: `Bearer ${config.slack.token}`,
|
|
67
73
|
},
|
|
68
74
|
body: JSON.stringify({
|
|
69
75
|
channel: targetChannel,
|
|
70
|
-
blocks: Array.from(blocks)
|
|
71
|
-
})
|
|
76
|
+
blocks: Array.from(blocks),
|
|
77
|
+
}),
|
|
72
78
|
});
|
|
73
79
|
}
|
|
74
|
-
export const commitSlack = ()=>{
|
|
80
|
+
export const commitSlack = () => {
|
|
75
81
|
if (!slackBlocks.size) {
|
|
76
82
|
return;
|
|
77
83
|
}
|
|
78
84
|
const channels = slackBlocks.keys();
|
|
79
85
|
let i = 1;
|
|
80
86
|
const baseUrl = config.appEnv === 'development' ? config.tunnelUrl : config.appUrl;
|
|
81
|
-
for (const channel of channels){
|
|
87
|
+
for (const channel of channels) {
|
|
82
88
|
const blocks = slackBlocks.get(channel);
|
|
83
89
|
if (!blocks?.size) {
|
|
84
90
|
continue;
|
|
@@ -88,13 +94,12 @@ export const commitSlack = ()=>{
|
|
|
88
94
|
name: TASK_COMMIT_SLACK_CHANNEL,
|
|
89
95
|
metadata: {
|
|
90
96
|
channel,
|
|
91
|
-
blocks: [
|
|
92
|
-
...blocks
|
|
93
|
-
]
|
|
97
|
+
blocks: [...blocks],
|
|
94
98
|
},
|
|
95
99
|
taskHandlerUrl: `${baseUrl || config.appUrl}/api/hooks/slack-pipeline`,
|
|
96
|
-
scheduledAt: addSeconds(new Date(), i++)
|
|
100
|
+
scheduledAt: addSeconds(new Date(), i++),
|
|
97
101
|
});
|
|
98
102
|
}
|
|
99
103
|
slackBlocks.clear();
|
|
100
104
|
};
|
|
105
|
+
//# sourceMappingURL=slack.js.map
|