@driveflux/api-functions 0.0.7-next.2 → 0.0.7-next.21
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 +73 -327
- package/dist/auth/emails.js +43 -210
- package/dist/auth/formatter.js +11 -11
- package/dist/auth/otp.js +122 -392
- package/dist/auth/register.d.ts +1 -1
- package/dist/auth/register.js +102 -398
- package/dist/auth/register.js.map +1 -1
- package/dist/auth/tokens.js +115 -430
- package/dist/auth/verifications.js +177 -583
- package/dist/constants.js +5 -4
- package/dist/mailjet/calls/manage-contacts-in-list.d.ts +2 -2
- package/dist/mailjet/calls/manage-contacts-in-list.d.ts.map +1 -1
- package/dist/mailjet/calls/manage-contacts-in-list.js +24 -168
- package/dist/mailjet/calls/manage-contacts-in-list.js.map +1 -1
- package/dist/mailjet/calls/manage-subscription-status.d.ts +2 -2
- package/dist/mailjet/calls/manage-subscription-status.d.ts.map +1 -1
- package/dist/mailjet/calls/manage-subscription-status.js +14 -154
- package/dist/mailjet/calls/manage-subscription-status.js.map +1 -1
- package/dist/mailjet/calls/request-service.d.ts +1 -1
- package/dist/mailjet/calls/request-service.d.ts.map +1 -1
- package/dist/mailjet/calls/request-service.js +18 -183
- package/dist/mailjet/refresh-email-preferences.js +26 -225
- package/dist/mailjet/set-contact.d.ts +2 -2
- package/dist/mailjet/set-contact.d.ts.map +1 -1
- package/dist/mailjet/set-contact.js +26 -217
- package/dist/mailjet/set-contact.js.map +1 -1
- package/dist/mailjet/types.d.ts +2 -2
- package/dist/mailjet/types.d.ts.map +1 -1
- package/dist/mailjet/types.js +2 -1
- package/dist/mailjet/utils/convert-to-array.d.ts +1 -1
- package/dist/mailjet/utils/convert-to-array.d.ts.map +1 -1
- package/dist/mailjet/utils/convert-to-array.js +9 -58
- package/dist/mailjet/utils/extract-email-preferences.d.ts +1 -1
- package/dist/mailjet/utils/extract-email-preferences.d.ts.map +1 -1
- package/dist/mailjet/utils/extract-email-preferences.js +41 -217
- package/dist/mailjet/utils/lists.js +30 -249
- package/dist/mailjet/utils/update-email-references.d.ts +2 -2
- package/dist/mailjet/utils/update-email-references.d.ts.map +1 -1
- package/dist/mailjet/utils/update-email-references.js +27 -208
- package/dist/mailjet/utils/update-email-references.js.map +1 -1
- package/dist/notion/client.js +48 -197
- package/dist/notion/helpful.js +29 -170
- package/dist/notion/schemas/block.js +49 -43
- package/dist/notion/schemas/common.js +17 -14
- package/dist/notion/schemas/database.js +125 -159
- package/dist/notion/schemas/emoji.js +3 -2
- package/dist/notion/schemas/file.js +10 -10
- package/dist/notion/schemas/kb.js +9 -8
- package/dist/notion/schemas/page.js +126 -171
- package/dist/notion/schemas/parent.js +9 -8
- package/dist/notion/schemas/user.js +21 -20
- package/dist/reservation/agree.d.ts +1 -1
- package/dist/reservation/agree.d.ts.map +1 -1
- package/dist/reservation/agree.js +19 -158
- package/dist/reservation/checks.d.ts +1 -1
- package/dist/reservation/checks.d.ts.map +1 -1
- package/dist/reservation/checks.js +23 -178
- package/dist/reservation/display-vehicle.d.ts +17 -17
- package/dist/reservation/display-vehicle.js +142 -514
- package/dist/reservation/display-vehicle.js.map +1 -1
- package/dist/reservation/fetch-or-create.d.ts +2 -2
- package/dist/reservation/fetch-or-create.d.ts.map +1 -1
- package/dist/reservation/fetch-or-create.js +199 -482
- package/dist/reservation/fetch-or-create.js.map +1 -1
- package/dist/reservation/invoice.d.ts +3 -3
- package/dist/reservation/invoice.d.ts.map +1 -1
- package/dist/reservation/invoice.js +198 -496
- package/dist/reservation/invoice.js.map +1 -1
- package/dist/reservation/payer.d.ts +1 -1
- package/dist/reservation/payer.d.ts.map +1 -1
- package/dist/reservation/payer.js +28 -177
- package/dist/reservation/reserve.d.ts +1 -1
- package/dist/reservation/reserve.d.ts.map +1 -1
- package/dist/reservation/reserve.js +36 -196
- package/dist/reservation/reserve.js.map +1 -1
- package/dist/reservation/types.d.ts +1 -0
- package/dist/reservation/types.d.ts.map +1 -1
- package/dist/reservation/types.js +2 -1
- package/dist/reservation/vehicle.d.ts +1 -1
- package/dist/reservation/vehicle.d.ts.map +1 -1
- package/dist/reservation/vehicle.js +26 -188
- package/dist/reservation/vehicle.js.map +1 -1
- package/dist/slack.d.ts +2 -2
- package/dist/slack.d.ts.map +1 -1
- package/dist/slack.js +67 -273
- package/dist/validation.d.ts +4 -4
- package/dist/validation.d.ts.map +1 -1
- package/dist/validation.js +89 -139
- package/dist/validation.js.map +1 -1
- package/dist/vehicle/vehicle-pricing/constants.d.ts +1 -1
- package/dist/vehicle/vehicle-pricing/constants.d.ts.map +1 -1
- package/dist/vehicle/vehicle-pricing/constants.js +33 -36
- package/dist/vehicle/vehicle-pricing/index.d.ts +1 -1
- package/dist/vehicle/vehicle-pricing/index.d.ts.map +1 -1
- package/dist/vehicle/vehicle-pricing/index.js +101 -259
- package/dist/vehicle/vehicle-pricing/index.js.map +1 -1
- package/dist/vehicle/vehicle-pricing/types.js +2 -1
- package/package.json +21 -21
package/dist/auth/confirm.js
CHANGED
|
@@ -1,202 +1,3 @@
|
|
|
1
|
-
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
2
|
-
try {
|
|
3
|
-
var info = gen[key](arg);
|
|
4
|
-
var value = info.value;
|
|
5
|
-
} catch (error) {
|
|
6
|
-
reject(error);
|
|
7
|
-
return;
|
|
8
|
-
}
|
|
9
|
-
if (info.done) {
|
|
10
|
-
resolve(value);
|
|
11
|
-
} else {
|
|
12
|
-
Promise.resolve(value).then(_next, _throw);
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
function _async_to_generator(fn) {
|
|
16
|
-
return function() {
|
|
17
|
-
var self = this, args = arguments;
|
|
18
|
-
return new Promise(function(resolve, reject) {
|
|
19
|
-
var gen = fn.apply(self, args);
|
|
20
|
-
function _next(value) {
|
|
21
|
-
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
22
|
-
}
|
|
23
|
-
function _throw(err) {
|
|
24
|
-
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
25
|
-
}
|
|
26
|
-
_next(undefined);
|
|
27
|
-
});
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
function _define_property(obj, key, value) {
|
|
31
|
-
if (key in obj) {
|
|
32
|
-
Object.defineProperty(obj, key, {
|
|
33
|
-
value: value,
|
|
34
|
-
enumerable: true,
|
|
35
|
-
configurable: true,
|
|
36
|
-
writable: true
|
|
37
|
-
});
|
|
38
|
-
} else {
|
|
39
|
-
obj[key] = value;
|
|
40
|
-
}
|
|
41
|
-
return obj;
|
|
42
|
-
}
|
|
43
|
-
function _object_spread(target) {
|
|
44
|
-
for(var i = 1; i < arguments.length; i++){
|
|
45
|
-
var source = arguments[i] != null ? arguments[i] : {};
|
|
46
|
-
var ownKeys = Object.keys(source);
|
|
47
|
-
if (typeof Object.getOwnPropertySymbols === "function") {
|
|
48
|
-
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
|
|
49
|
-
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
|
50
|
-
}));
|
|
51
|
-
}
|
|
52
|
-
ownKeys.forEach(function(key) {
|
|
53
|
-
_define_property(target, key, source[key]);
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
return target;
|
|
57
|
-
}
|
|
58
|
-
function ownKeys(object, enumerableOnly) {
|
|
59
|
-
var keys = Object.keys(object);
|
|
60
|
-
if (Object.getOwnPropertySymbols) {
|
|
61
|
-
var symbols = Object.getOwnPropertySymbols(object);
|
|
62
|
-
if (enumerableOnly) {
|
|
63
|
-
symbols = symbols.filter(function(sym) {
|
|
64
|
-
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
keys.push.apply(keys, symbols);
|
|
68
|
-
}
|
|
69
|
-
return keys;
|
|
70
|
-
}
|
|
71
|
-
function _object_spread_props(target, source) {
|
|
72
|
-
source = source != null ? source : {};
|
|
73
|
-
if (Object.getOwnPropertyDescriptors) {
|
|
74
|
-
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
|
|
75
|
-
} else {
|
|
76
|
-
ownKeys(Object(source)).forEach(function(key) {
|
|
77
|
-
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
return target;
|
|
81
|
-
}
|
|
82
|
-
function _object_without_properties(source, excluded) {
|
|
83
|
-
if (source == null) return {};
|
|
84
|
-
var target = _object_without_properties_loose(source, excluded);
|
|
85
|
-
var key, i;
|
|
86
|
-
if (Object.getOwnPropertySymbols) {
|
|
87
|
-
var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
|
|
88
|
-
for(i = 0; i < sourceSymbolKeys.length; i++){
|
|
89
|
-
key = sourceSymbolKeys[i];
|
|
90
|
-
if (excluded.indexOf(key) >= 0) continue;
|
|
91
|
-
if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
|
|
92
|
-
target[key] = source[key];
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
return target;
|
|
96
|
-
}
|
|
97
|
-
function _object_without_properties_loose(source, excluded) {
|
|
98
|
-
if (source == null) return {};
|
|
99
|
-
var target = {};
|
|
100
|
-
var sourceKeys = Object.keys(source);
|
|
101
|
-
var key, i;
|
|
102
|
-
for(i = 0; i < sourceKeys.length; i++){
|
|
103
|
-
key = sourceKeys[i];
|
|
104
|
-
if (excluded.indexOf(key) >= 0) continue;
|
|
105
|
-
target[key] = source[key];
|
|
106
|
-
}
|
|
107
|
-
return target;
|
|
108
|
-
}
|
|
109
|
-
function _ts_generator(thisArg, body) {
|
|
110
|
-
var f, y, t, _ = {
|
|
111
|
-
label: 0,
|
|
112
|
-
sent: function() {
|
|
113
|
-
if (t[0] & 1) throw t[1];
|
|
114
|
-
return t[1];
|
|
115
|
-
},
|
|
116
|
-
trys: [],
|
|
117
|
-
ops: []
|
|
118
|
-
}, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
119
|
-
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() {
|
|
120
|
-
return this;
|
|
121
|
-
}), g;
|
|
122
|
-
function verb(n) {
|
|
123
|
-
return function(v) {
|
|
124
|
-
return step([
|
|
125
|
-
n,
|
|
126
|
-
v
|
|
127
|
-
]);
|
|
128
|
-
};
|
|
129
|
-
}
|
|
130
|
-
function step(op) {
|
|
131
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
132
|
-
while(g && (g = 0, op[0] && (_ = 0)), _)try {
|
|
133
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
134
|
-
if (y = 0, t) op = [
|
|
135
|
-
op[0] & 2,
|
|
136
|
-
t.value
|
|
137
|
-
];
|
|
138
|
-
switch(op[0]){
|
|
139
|
-
case 0:
|
|
140
|
-
case 1:
|
|
141
|
-
t = op;
|
|
142
|
-
break;
|
|
143
|
-
case 4:
|
|
144
|
-
_.label++;
|
|
145
|
-
return {
|
|
146
|
-
value: op[1],
|
|
147
|
-
done: false
|
|
148
|
-
};
|
|
149
|
-
case 5:
|
|
150
|
-
_.label++;
|
|
151
|
-
y = op[1];
|
|
152
|
-
op = [
|
|
153
|
-
0
|
|
154
|
-
];
|
|
155
|
-
continue;
|
|
156
|
-
case 7:
|
|
157
|
-
op = _.ops.pop();
|
|
158
|
-
_.trys.pop();
|
|
159
|
-
continue;
|
|
160
|
-
default:
|
|
161
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
162
|
-
_ = 0;
|
|
163
|
-
continue;
|
|
164
|
-
}
|
|
165
|
-
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
166
|
-
_.label = op[1];
|
|
167
|
-
break;
|
|
168
|
-
}
|
|
169
|
-
if (op[0] === 6 && _.label < t[1]) {
|
|
170
|
-
_.label = t[1];
|
|
171
|
-
t = op;
|
|
172
|
-
break;
|
|
173
|
-
}
|
|
174
|
-
if (t && _.label < t[2]) {
|
|
175
|
-
_.label = t[2];
|
|
176
|
-
_.ops.push(op);
|
|
177
|
-
break;
|
|
178
|
-
}
|
|
179
|
-
if (t[2]) _.ops.pop();
|
|
180
|
-
_.trys.pop();
|
|
181
|
-
continue;
|
|
182
|
-
}
|
|
183
|
-
op = body.call(thisArg, _);
|
|
184
|
-
} catch (e) {
|
|
185
|
-
op = [
|
|
186
|
-
6,
|
|
187
|
-
e
|
|
188
|
-
];
|
|
189
|
-
y = 0;
|
|
190
|
-
} finally{
|
|
191
|
-
f = t = 0;
|
|
192
|
-
}
|
|
193
|
-
if (op[0] & 5) throw op[1];
|
|
194
|
-
return {
|
|
195
|
-
value: op[0] ? op[1] : void 0,
|
|
196
|
-
done: true
|
|
197
|
-
};
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
1
|
import { refreshEmailPreferences } from '@driveflux/api-functions/mailjet/refresh-email-preferences';
|
|
201
2
|
import { prisma } from '@driveflux/db';
|
|
202
3
|
import { generateId } from '@driveflux/db/id';
|
|
@@ -207,136 +8,81 @@ import { addDays } from 'date-fns/addDays';
|
|
|
207
8
|
import { z } from 'zod';
|
|
208
9
|
import { clearToken, verifyToken } from './tokens.js';
|
|
209
10
|
import { sendVerificationEmail } from './verifications.js';
|
|
210
|
-
|
|
11
|
+
const Body = z.object({
|
|
211
12
|
firstName: z.string(),
|
|
212
13
|
lastName: z.string(),
|
|
213
|
-
phoneNumber: z.string().transform(
|
|
214
|
-
return s.replace(/[\s-]/g, '');
|
|
215
|
-
}),
|
|
14
|
+
phoneNumber: z.string().transform((s) => s.replace(/[\s-]/g, '')),
|
|
216
15
|
code: z.string().optional().nullable(),
|
|
217
|
-
email: z
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
16
|
+
email: z
|
|
17
|
+
.string()
|
|
18
|
+
.email()
|
|
19
|
+
.transform((s) => s.toLowerCase().trim()),
|
|
20
|
+
pageSource: z.string().optional().nullable(),
|
|
221
21
|
});
|
|
222
|
-
export
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
},
|
|
288
|
-
consents: {
|
|
289
|
-
create: {
|
|
290
|
-
id: generateId('UserConsent'),
|
|
291
|
-
ipAddress: Array.isArray(xForwardedFor) ? (xForwardedFor === null || xForwardedFor === void 0 ? void 0 : xForwardedFor[0]) || '0.0.0.0' : xForwardedFor || '0.0.0.0',
|
|
292
|
-
consentType: 'terms',
|
|
293
|
-
email: email
|
|
294
|
-
}
|
|
295
|
-
},
|
|
296
|
-
registrationComplete: true
|
|
297
|
-
})
|
|
298
|
-
})
|
|
299
|
-
];
|
|
300
|
-
case 5:
|
|
301
|
-
updatedUser = _state.sent();
|
|
302
|
-
return [
|
|
303
|
-
4,
|
|
304
|
-
prisma.token.create({
|
|
305
|
-
data: {
|
|
306
|
-
id: generateId('Token'),
|
|
307
|
-
user: {
|
|
308
|
-
connect: {
|
|
309
|
-
id: updatedUser.id
|
|
310
|
-
}
|
|
311
|
-
},
|
|
312
|
-
expiresAt: addDays(new Date(), 365),
|
|
313
|
-
scope: 'all'
|
|
314
|
-
}
|
|
315
|
-
})
|
|
316
|
-
];
|
|
317
|
-
case 6:
|
|
318
|
-
token = _state.sent();
|
|
319
|
-
// We don't want this to be a task. It should be instant
|
|
320
|
-
return [
|
|
321
|
-
4,
|
|
322
|
-
sendVerificationEmail(updatedUser.id)
|
|
323
|
-
];
|
|
324
|
-
case 7:
|
|
325
|
-
_state.sent();
|
|
326
|
-
return [
|
|
327
|
-
4,
|
|
328
|
-
refreshEmailPreferences(updatedUser.id)
|
|
329
|
-
];
|
|
330
|
-
case 8:
|
|
331
|
-
_state.sent();
|
|
332
|
-
return [
|
|
333
|
-
2,
|
|
334
|
-
new Ok({
|
|
335
|
-
token: token,
|
|
336
|
-
user: updatedUser
|
|
337
|
-
})
|
|
338
|
-
];
|
|
339
|
-
}
|
|
340
|
-
});
|
|
341
|
-
})();
|
|
22
|
+
export const handleConfirmUser = async (b, user, xForwardedFor) => {
|
|
23
|
+
const { phoneNumber, email, code, pageSource, ...body } = Body.parse(b);
|
|
24
|
+
let phoneNumberVerified = false;
|
|
25
|
+
if (code) {
|
|
26
|
+
const tokenResult = await verifyToken(code, { scope: 'verify-phone' });
|
|
27
|
+
if (tokenResult.err) {
|
|
28
|
+
return new Err(makeProblem(PROBLEM_CONFLICT, 'Invalid OTP token'));
|
|
29
|
+
}
|
|
30
|
+
await clearToken(tokenResult.val.id);
|
|
31
|
+
phoneNumberVerified = true;
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
phoneNumberVerified = user.phoneNumberVerified;
|
|
35
|
+
}
|
|
36
|
+
const method = isMetadata(user?.metadata)
|
|
37
|
+
? user?.metadata?.signupProvider
|
|
38
|
+
: undefined;
|
|
39
|
+
const updatedUser = await prisma.user.update({
|
|
40
|
+
where: {
|
|
41
|
+
id: user.id,
|
|
42
|
+
},
|
|
43
|
+
data: {
|
|
44
|
+
...body,
|
|
45
|
+
phoneNumber: phoneNumber?.replace(/[\s-]/g, ''),
|
|
46
|
+
preferredCurrency: 'MYR',
|
|
47
|
+
preferredLocale: 'en',
|
|
48
|
+
phoneNumberVerified,
|
|
49
|
+
consented: true,
|
|
50
|
+
groups: ['member'],
|
|
51
|
+
signupParams: {
|
|
52
|
+
method,
|
|
53
|
+
source: pageSource,
|
|
54
|
+
},
|
|
55
|
+
consents: {
|
|
56
|
+
create: {
|
|
57
|
+
id: generateId('UserConsent'),
|
|
58
|
+
ipAddress: Array.isArray(xForwardedFor)
|
|
59
|
+
? xForwardedFor?.[0] || '0.0.0.0'
|
|
60
|
+
: xForwardedFor || '0.0.0.0',
|
|
61
|
+
consentType: 'terms',
|
|
62
|
+
email: email,
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
registrationComplete: true,
|
|
66
|
+
},
|
|
67
|
+
});
|
|
68
|
+
const token = await prisma.token.create({
|
|
69
|
+
data: {
|
|
70
|
+
id: generateId('Token'),
|
|
71
|
+
user: {
|
|
72
|
+
connect: {
|
|
73
|
+
id: updatedUser.id,
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
expiresAt: addDays(new Date(), 365),
|
|
77
|
+
scope: 'all',
|
|
78
|
+
},
|
|
79
|
+
});
|
|
80
|
+
// We don't want this to be a task. It should be instant
|
|
81
|
+
await sendVerificationEmail(updatedUser.id);
|
|
82
|
+
await refreshEmailPreferences(updatedUser.id);
|
|
83
|
+
return new Ok({
|
|
84
|
+
token,
|
|
85
|
+
user: updatedUser,
|
|
86
|
+
});
|
|
342
87
|
};
|
|
88
|
+
//# sourceMappingURL=confirm.js.map
|
package/dist/auth/emails.js
CHANGED
|
@@ -1,218 +1,51 @@
|
|
|
1
|
-
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
2
|
-
try {
|
|
3
|
-
var info = gen[key](arg);
|
|
4
|
-
var value = info.value;
|
|
5
|
-
} catch (error) {
|
|
6
|
-
reject(error);
|
|
7
|
-
return;
|
|
8
|
-
}
|
|
9
|
-
if (info.done) {
|
|
10
|
-
resolve(value);
|
|
11
|
-
} else {
|
|
12
|
-
Promise.resolve(value).then(_next, _throw);
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
function _async_to_generator(fn) {
|
|
16
|
-
return function() {
|
|
17
|
-
var self = this, args = arguments;
|
|
18
|
-
return new Promise(function(resolve, reject) {
|
|
19
|
-
var gen = fn.apply(self, args);
|
|
20
|
-
function _next(value) {
|
|
21
|
-
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
22
|
-
}
|
|
23
|
-
function _throw(err) {
|
|
24
|
-
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
25
|
-
}
|
|
26
|
-
_next(undefined);
|
|
27
|
-
});
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
function _ts_generator(thisArg, body) {
|
|
31
|
-
var f, y, t, _ = {
|
|
32
|
-
label: 0,
|
|
33
|
-
sent: function() {
|
|
34
|
-
if (t[0] & 1) throw t[1];
|
|
35
|
-
return t[1];
|
|
36
|
-
},
|
|
37
|
-
trys: [],
|
|
38
|
-
ops: []
|
|
39
|
-
}, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
40
|
-
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() {
|
|
41
|
-
return this;
|
|
42
|
-
}), g;
|
|
43
|
-
function verb(n) {
|
|
44
|
-
return function(v) {
|
|
45
|
-
return step([
|
|
46
|
-
n,
|
|
47
|
-
v
|
|
48
|
-
]);
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
function step(op) {
|
|
52
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
53
|
-
while(g && (g = 0, op[0] && (_ = 0)), _)try {
|
|
54
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
55
|
-
if (y = 0, t) op = [
|
|
56
|
-
op[0] & 2,
|
|
57
|
-
t.value
|
|
58
|
-
];
|
|
59
|
-
switch(op[0]){
|
|
60
|
-
case 0:
|
|
61
|
-
case 1:
|
|
62
|
-
t = op;
|
|
63
|
-
break;
|
|
64
|
-
case 4:
|
|
65
|
-
_.label++;
|
|
66
|
-
return {
|
|
67
|
-
value: op[1],
|
|
68
|
-
done: false
|
|
69
|
-
};
|
|
70
|
-
case 5:
|
|
71
|
-
_.label++;
|
|
72
|
-
y = op[1];
|
|
73
|
-
op = [
|
|
74
|
-
0
|
|
75
|
-
];
|
|
76
|
-
continue;
|
|
77
|
-
case 7:
|
|
78
|
-
op = _.ops.pop();
|
|
79
|
-
_.trys.pop();
|
|
80
|
-
continue;
|
|
81
|
-
default:
|
|
82
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
83
|
-
_ = 0;
|
|
84
|
-
continue;
|
|
85
|
-
}
|
|
86
|
-
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
87
|
-
_.label = op[1];
|
|
88
|
-
break;
|
|
89
|
-
}
|
|
90
|
-
if (op[0] === 6 && _.label < t[1]) {
|
|
91
|
-
_.label = t[1];
|
|
92
|
-
t = op;
|
|
93
|
-
break;
|
|
94
|
-
}
|
|
95
|
-
if (t && _.label < t[2]) {
|
|
96
|
-
_.label = t[2];
|
|
97
|
-
_.ops.push(op);
|
|
98
|
-
break;
|
|
99
|
-
}
|
|
100
|
-
if (t[2]) _.ops.pop();
|
|
101
|
-
_.trys.pop();
|
|
102
|
-
continue;
|
|
103
|
-
}
|
|
104
|
-
op = body.call(thisArg, _);
|
|
105
|
-
} catch (e) {
|
|
106
|
-
op = [
|
|
107
|
-
6,
|
|
108
|
-
e
|
|
109
|
-
];
|
|
110
|
-
y = 0;
|
|
111
|
-
} finally{
|
|
112
|
-
f = t = 0;
|
|
113
|
-
}
|
|
114
|
-
if (op[0] & 5) throw op[1];
|
|
115
|
-
return {
|
|
116
|
-
value: op[0] ? op[1] : void 0,
|
|
117
|
-
done: true
|
|
118
|
-
};
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
1
|
import { prisma } from '@driveflux/db';
|
|
122
2
|
import { send } from '@driveflux/email';
|
|
123
3
|
import { emailChangedEmail } from '@driveflux/email-templates/flux/email-changed';
|
|
124
4
|
import { passwordChangedEmail } from '@driveflux/email-templates/flux/password-changed';
|
|
125
5
|
import { makeProblem, PROBLEM_NOT_FOUND } from '@driveflux/problem';
|
|
126
6
|
import { Err } from '@driveflux/result';
|
|
127
|
-
export
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
}
|
|
149
|
-
return [
|
|
150
|
-
4,
|
|
151
|
-
send({
|
|
152
|
-
subject: 'Email change confirmation',
|
|
153
|
-
to: {
|
|
154
|
-
name: user.firstName || '',
|
|
155
|
-
address: user.email
|
|
156
|
-
},
|
|
157
|
-
html: emailChangedEmail({
|
|
158
|
-
user: user.firstName || '',
|
|
159
|
-
title: 'Email change confirmation',
|
|
160
|
-
newEmail: user.email
|
|
161
|
-
})
|
|
162
|
-
})
|
|
163
|
-
];
|
|
164
|
-
case 2:
|
|
165
|
-
return [
|
|
166
|
-
2,
|
|
167
|
-
_state.sent()
|
|
168
|
-
];
|
|
169
|
-
}
|
|
170
|
-
});
|
|
171
|
-
})();
|
|
7
|
+
export const sendEmailChangedEmail = async (userId) => {
|
|
8
|
+
const user = await prisma.user.findUnique({
|
|
9
|
+
where: {
|
|
10
|
+
id: userId,
|
|
11
|
+
},
|
|
12
|
+
});
|
|
13
|
+
if (!user) {
|
|
14
|
+
return new Err(makeProblem(PROBLEM_NOT_FOUND, `The user ${userId} was not found`));
|
|
15
|
+
}
|
|
16
|
+
return await send({
|
|
17
|
+
subject: 'Email change confirmation',
|
|
18
|
+
to: {
|
|
19
|
+
name: user.firstName || '',
|
|
20
|
+
address: user.email,
|
|
21
|
+
},
|
|
22
|
+
html: emailChangedEmail({
|
|
23
|
+
user: user.firstName || '',
|
|
24
|
+
title: 'Email change confirmation',
|
|
25
|
+
newEmail: user.email,
|
|
26
|
+
}),
|
|
27
|
+
});
|
|
172
28
|
};
|
|
173
|
-
export
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
}
|
|
195
|
-
title = 'Password changed';
|
|
196
|
-
return [
|
|
197
|
-
4,
|
|
198
|
-
send({
|
|
199
|
-
subject: title,
|
|
200
|
-
to: {
|
|
201
|
-
name: user.firstName || '',
|
|
202
|
-
address: user.email
|
|
203
|
-
},
|
|
204
|
-
html: passwordChangedEmail({
|
|
205
|
-
user: user.firstName || '',
|
|
206
|
-
title: title
|
|
207
|
-
})
|
|
208
|
-
})
|
|
209
|
-
];
|
|
210
|
-
case 2:
|
|
211
|
-
return [
|
|
212
|
-
2,
|
|
213
|
-
_state.sent()
|
|
214
|
-
];
|
|
215
|
-
}
|
|
216
|
-
});
|
|
217
|
-
})();
|
|
29
|
+
export const sendPasswordChangedEmail = async (userId) => {
|
|
30
|
+
const user = await prisma.user.findUnique({
|
|
31
|
+
where: {
|
|
32
|
+
id: userId,
|
|
33
|
+
},
|
|
34
|
+
});
|
|
35
|
+
if (!user) {
|
|
36
|
+
return new Err(makeProblem(PROBLEM_NOT_FOUND, `The user ${userId} was not found`));
|
|
37
|
+
}
|
|
38
|
+
const title = 'Password changed';
|
|
39
|
+
return await send({
|
|
40
|
+
subject: title,
|
|
41
|
+
to: {
|
|
42
|
+
name: user.firstName || '',
|
|
43
|
+
address: user.email,
|
|
44
|
+
},
|
|
45
|
+
html: passwordChangedEmail({
|
|
46
|
+
user: user.firstName || '',
|
|
47
|
+
title: title,
|
|
48
|
+
}),
|
|
49
|
+
});
|
|
218
50
|
};
|
|
51
|
+
//# sourceMappingURL=emails.js.map
|