@fonderie/auth 7.3.3 → 7.3.4
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/index.cjs +32 -48
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +35 -51
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -235,7 +235,7 @@ function cookieHeaders(cookies) {
|
|
|
235
235
|
|
|
236
236
|
// src/controllers/mfa.controller.ts
|
|
237
237
|
import QRCode from "qrcode";
|
|
238
|
-
import { setApiResponse as setApiResponse2, HTTP as HTTP2 } from "@fonderie/core";
|
|
238
|
+
import { setApiResponse as setApiResponse2, HTTP as HTTP2, background } from "@fonderie/core";
|
|
239
239
|
import { NOTIFICATION_EVENT } from "@fonderie/events";
|
|
240
240
|
|
|
241
241
|
// src/config.ts
|
|
@@ -970,13 +970,12 @@ function mfaController(store, config, issuer, bus) {
|
|
|
970
970
|
return setApiResponse2(HTTP2.UNAUTHORIZED, "INVALID_CODE", "Invalid MFA token");
|
|
971
971
|
}
|
|
972
972
|
await users.confirmMfaSecret(ctx.user.id);
|
|
973
|
-
bus?.emit(NOTIFICATION_EVENT, {
|
|
973
|
+
await background(bus?.emit(NOTIFICATION_EVENT, {
|
|
974
974
|
type: MESSAGE_KEYS.mfaEnabled,
|
|
975
975
|
locale: ctx.user.locale,
|
|
976
976
|
data: {},
|
|
977
977
|
recipient: { email: ctx.user.email, phone: null, deviceToken: null }
|
|
978
|
-
})
|
|
979
|
-
});
|
|
978
|
+
}));
|
|
980
979
|
return setApiResponse2(HTTP2.OK, "MFA_VERIFIED", "MFA verified successfully.", {
|
|
981
980
|
mfaEnabled: true
|
|
982
981
|
});
|
|
@@ -1076,13 +1075,12 @@ function mfaController(store, config, issuer, bus) {
|
|
|
1076
1075
|
const plainCodes = generateBackupCodes();
|
|
1077
1076
|
const codeHashes = await Promise.all(plainCodes.map((c) => hashPassword(c)));
|
|
1078
1077
|
await backupCodes.replace(ctx.user.id, codeHashes);
|
|
1079
|
-
bus?.emit(NOTIFICATION_EVENT, {
|
|
1078
|
+
await background(bus?.emit(NOTIFICATION_EVENT, {
|
|
1080
1079
|
type: MESSAGE_KEYS.mfaBackupCodesRegenerated,
|
|
1081
1080
|
locale: ctx.user.locale,
|
|
1082
1081
|
data: {},
|
|
1083
1082
|
recipient: { email: ctx.user.email, phone: null, deviceToken: null }
|
|
1084
|
-
})
|
|
1085
|
-
});
|
|
1083
|
+
}));
|
|
1086
1084
|
return setApiResponse2(HTTP2.OK, "BACKUP_CODES_REGENERATED", "Backup codes regenerated.", {
|
|
1087
1085
|
backupCodes: plainCodes
|
|
1088
1086
|
});
|
|
@@ -1104,13 +1102,12 @@ function mfaController(store, config, issuer, bus) {
|
|
|
1104
1102
|
return setApiResponse2(HTTP2.UNAUTHORIZED, "INVALID_CODE", "Invalid TOTP code");
|
|
1105
1103
|
}
|
|
1106
1104
|
await Promise.all([users.disableMfa(ctx.user.id), backupCodes.deleteByUser(ctx.user.id)]);
|
|
1107
|
-
bus?.emit(NOTIFICATION_EVENT, {
|
|
1105
|
+
await background(bus?.emit(NOTIFICATION_EVENT, {
|
|
1108
1106
|
type: MESSAGE_KEYS.mfaDisabled,
|
|
1109
1107
|
locale: user.locale,
|
|
1110
1108
|
data: {},
|
|
1111
1109
|
recipient: { email: user.email, phone: null, deviceToken: null }
|
|
1112
|
-
})
|
|
1113
|
-
});
|
|
1110
|
+
}));
|
|
1114
1111
|
return setApiResponse2(HTTP2.OK, "MFA_DISABLED", "MFA disabled successfully.");
|
|
1115
1112
|
}
|
|
1116
1113
|
};
|
|
@@ -1119,7 +1116,7 @@ function mfaController(store, config, issuer, bus) {
|
|
|
1119
1116
|
// src/controllers/auth.controller.ts
|
|
1120
1117
|
import { randomBytes as randomBytes3, randomInt } from "crypto";
|
|
1121
1118
|
import { NOTIFICATION_EVENT as NOTIFICATION_EVENT2 } from "@fonderie/events";
|
|
1122
|
-
import { setApiResponse as setApiResponse3, HTTP as HTTP3 } from "@fonderie/core";
|
|
1119
|
+
import { setApiResponse as setApiResponse3, HTTP as HTTP3, background as background2 } from "@fonderie/core";
|
|
1123
1120
|
|
|
1124
1121
|
// src/services/cooldown.ts
|
|
1125
1122
|
function checkCooldown(lastSentAt, cooldownMs) {
|
|
@@ -1366,7 +1363,7 @@ function authController(store, config, bus) {
|
|
|
1366
1363
|
}
|
|
1367
1364
|
const reqId = ctx.meta["requestId"];
|
|
1368
1365
|
const reqOpts = reqId !== void 0 ? { requestId: reqId } : void 0;
|
|
1369
|
-
bus?.emit(
|
|
1366
|
+
await background2(bus?.emit(
|
|
1370
1367
|
NOTIFICATION_EVENT2,
|
|
1371
1368
|
{
|
|
1372
1369
|
type: MESSAGE_KEYS.emailRegistration,
|
|
@@ -1375,9 +1372,8 @@ function authController(store, config, bus) {
|
|
|
1375
1372
|
recipient: { email: normalizedEmail, phone: null, deviceToken: null }
|
|
1376
1373
|
},
|
|
1377
1374
|
reqOpts
|
|
1378
|
-
)
|
|
1379
|
-
|
|
1380
|
-
bus?.emit(
|
|
1375
|
+
));
|
|
1376
|
+
await background2(bus?.emit(
|
|
1381
1377
|
EVENT_KEYS.userRegistered,
|
|
1382
1378
|
{
|
|
1383
1379
|
userId: user.id,
|
|
@@ -1387,8 +1383,7 @@ function authController(store, config, bus) {
|
|
|
1387
1383
|
loginMethod: "email"
|
|
1388
1384
|
},
|
|
1389
1385
|
reqOpts
|
|
1390
|
-
)
|
|
1391
|
-
});
|
|
1386
|
+
));
|
|
1392
1387
|
const { accessToken, refreshToken, sid } = issueTokenPair(user.id, config, {
|
|
1393
1388
|
loginMethod: "email"
|
|
1394
1389
|
});
|
|
@@ -1430,7 +1425,7 @@ function authController(store, config, bus) {
|
|
|
1430
1425
|
}
|
|
1431
1426
|
const reqId2 = ctx.meta["requestId"];
|
|
1432
1427
|
const reqOpts2 = reqId2 !== void 0 ? { requestId: reqId2 } : void 0;
|
|
1433
|
-
bus?.emit(
|
|
1428
|
+
await background2(bus?.emit(
|
|
1434
1429
|
NOTIFICATION_EVENT2,
|
|
1435
1430
|
{
|
|
1436
1431
|
type: MESSAGE_KEYS.phoneOtp,
|
|
@@ -1439,9 +1434,8 @@ function authController(store, config, bus) {
|
|
|
1439
1434
|
recipient: { email: null, phone: normalizePhone(phone2), deviceToken: null }
|
|
1440
1435
|
},
|
|
1441
1436
|
reqOpts2
|
|
1442
|
-
)
|
|
1443
|
-
|
|
1444
|
-
bus?.emit(
|
|
1437
|
+
));
|
|
1438
|
+
await background2(bus?.emit(
|
|
1445
1439
|
EVENT_KEYS.userRegistered,
|
|
1446
1440
|
{
|
|
1447
1441
|
userId: user.id,
|
|
@@ -1451,8 +1445,7 @@ function authController(store, config, bus) {
|
|
|
1451
1445
|
loginMethod: "phone"
|
|
1452
1446
|
},
|
|
1453
1447
|
reqOpts2
|
|
1454
|
-
)
|
|
1455
|
-
});
|
|
1448
|
+
));
|
|
1456
1449
|
const otpToken = issueMfaPendingToken(user.id, config, "phone");
|
|
1457
1450
|
return Response.json(
|
|
1458
1451
|
{
|
|
@@ -1570,13 +1563,12 @@ function authController(store, config, bus) {
|
|
|
1570
1563
|
const otp = randomInt(1e5, 1e6).toString();
|
|
1571
1564
|
const expiresAt = new Date(Date.now() + OTP_TTL_MS);
|
|
1572
1565
|
await phoneVerif.upsert(user.id, normalizePhone(phone2), otp, expiresAt);
|
|
1573
|
-
bus?.emit(NOTIFICATION_EVENT2, {
|
|
1566
|
+
await background2(bus?.emit(NOTIFICATION_EVENT2, {
|
|
1574
1567
|
type: MESSAGE_KEYS.phoneOtp,
|
|
1575
1568
|
locale: user.locale,
|
|
1576
1569
|
data: { otp },
|
|
1577
1570
|
recipient: { email: null, phone: normalizePhone(phone2), deviceToken: null }
|
|
1578
|
-
})
|
|
1579
|
-
});
|
|
1571
|
+
}));
|
|
1580
1572
|
const otpToken = issueMfaPendingToken(user.id, config, "phone");
|
|
1581
1573
|
return Response.json(
|
|
1582
1574
|
{
|
|
@@ -1683,13 +1675,12 @@ function authController(store, config, bus) {
|
|
|
1683
1675
|
await passwordReset.create(user.id, pin, token, expiresAt);
|
|
1684
1676
|
const base = resolved.passwordResetUrl;
|
|
1685
1677
|
const resetUrl = base ? `${base}${base.includes("?") ? "&" : "?"}token=${token}` : "";
|
|
1686
|
-
bus?.emit(NOTIFICATION_EVENT2, {
|
|
1678
|
+
await background2(bus?.emit(NOTIFICATION_EVENT2, {
|
|
1687
1679
|
type: MESSAGE_KEYS.passwordReset,
|
|
1688
1680
|
locale: user.locale,
|
|
1689
1681
|
recipient: { email: email2, phone: null, deviceToken: null },
|
|
1690
1682
|
data: { pin, token, resetUrl }
|
|
1691
|
-
})
|
|
1692
|
-
});
|
|
1683
|
+
}));
|
|
1693
1684
|
return setApiResponse3(
|
|
1694
1685
|
HTTP3.OK,
|
|
1695
1686
|
"PASSWORD_RESET_EMAIL_SENT",
|
|
@@ -1864,13 +1855,12 @@ function authController(store, config, bus) {
|
|
|
1864
1855
|
const otp = randomInt(1e5, 1e6).toString();
|
|
1865
1856
|
const expiresAt2 = new Date(Date.now() + OTP_TTL_MS);
|
|
1866
1857
|
await phoneVerif.upsert(ctx.user.id, phone2, otp, expiresAt2);
|
|
1867
|
-
bus?.emit(NOTIFICATION_EVENT2, {
|
|
1858
|
+
await background2(bus?.emit(NOTIFICATION_EVENT2, {
|
|
1868
1859
|
type: MESSAGE_KEYS.phoneOtp,
|
|
1869
1860
|
locale: ctx.user.locale,
|
|
1870
1861
|
data: { otp },
|
|
1871
1862
|
recipient: { email: null, phone: phone2, deviceToken: null }
|
|
1872
|
-
})
|
|
1873
|
-
});
|
|
1863
|
+
}));
|
|
1874
1864
|
return setApiResponse3(
|
|
1875
1865
|
HTTP3.OK,
|
|
1876
1866
|
"VERIFICATION_SENT",
|
|
@@ -1904,13 +1894,12 @@ function authController(store, config, bus) {
|
|
|
1904
1894
|
const pin = randomInt(1e5, 1e6).toString();
|
|
1905
1895
|
const expiresAt = new Date(Date.now() + 1e3 * 60 * 60 * 24);
|
|
1906
1896
|
await emailVerif.replace(ctx.user.id, pin, expiresAt);
|
|
1907
|
-
bus?.emit(NOTIFICATION_EVENT2, {
|
|
1897
|
+
await background2(bus?.emit(NOTIFICATION_EVENT2, {
|
|
1908
1898
|
type: MESSAGE_KEYS.emailVerification,
|
|
1909
1899
|
locale: ctx.user.locale,
|
|
1910
1900
|
recipient: { email: ctx.user.email, phone: null, deviceToken: null },
|
|
1911
1901
|
data: { pin }
|
|
1912
|
-
})
|
|
1913
|
-
});
|
|
1902
|
+
}));
|
|
1914
1903
|
return setApiResponse3(HTTP3.OK, "VERIFICATION_SENT", "Verification email sent.", {
|
|
1915
1904
|
email: ctx.user.email
|
|
1916
1905
|
});
|
|
@@ -1920,7 +1909,7 @@ function authController(store, config, bus) {
|
|
|
1920
1909
|
|
|
1921
1910
|
// src/controllers/user.controller.ts
|
|
1922
1911
|
import { randomInt as randomInt2 } from "crypto";
|
|
1923
|
-
import { setApiResponse as setApiResponse4, HTTP as HTTP4, dateOrEmpty as dateOrEmpty2 } from "@fonderie/core";
|
|
1912
|
+
import { setApiResponse as setApiResponse4, HTTP as HTTP4, dateOrEmpty as dateOrEmpty2, background as background3 } from "@fonderie/core";
|
|
1924
1913
|
import { NOTIFICATION_EVENT as NOTIFICATION_EVENT3 } from "@fonderie/events";
|
|
1925
1914
|
|
|
1926
1915
|
// src/dtos/login-activity.ts
|
|
@@ -2113,21 +2102,19 @@ function userController(store, config, bus) {
|
|
|
2113
2102
|
const expiresAt = new Date(Date.now() + 1e3 * 60 * 60 * 24);
|
|
2114
2103
|
await emailVerif.replace(ctx.user.id, pin, expiresAt);
|
|
2115
2104
|
await users.updateEmail(ctx.user.id, normalised);
|
|
2116
|
-
bus?.emit(NOTIFICATION_EVENT3, {
|
|
2105
|
+
await background3(bus?.emit(NOTIFICATION_EVENT3, {
|
|
2117
2106
|
type: MESSAGE_KEYS.emailVerification,
|
|
2118
2107
|
locale: ctx.user.locale,
|
|
2119
2108
|
data: { pin },
|
|
2120
2109
|
recipient: { email: normalised, phone: null, deviceToken: null }
|
|
2121
|
-
})
|
|
2122
|
-
});
|
|
2110
|
+
}));
|
|
2123
2111
|
if (oldEmail) {
|
|
2124
|
-
bus?.emit(NOTIFICATION_EVENT3, {
|
|
2112
|
+
await background3(bus?.emit(NOTIFICATION_EVENT3, {
|
|
2125
2113
|
type: MESSAGE_KEYS.emailChanged,
|
|
2126
2114
|
locale: ctx.user.locale,
|
|
2127
2115
|
data: { newEmail: normalised },
|
|
2128
2116
|
recipient: { email: oldEmail, phone: null, deviceToken: null }
|
|
2129
|
-
})
|
|
2130
|
-
});
|
|
2117
|
+
}));
|
|
2131
2118
|
}
|
|
2132
2119
|
return setApiResponse4(
|
|
2133
2120
|
HTTP4.OK,
|
|
@@ -2157,21 +2144,19 @@ function userController(store, config, bus) {
|
|
|
2157
2144
|
const expiresAt = new Date(Date.now() + 10 * 60 * 1e3);
|
|
2158
2145
|
await phoneVerif.upsert(ctx.user.id, normalised, otp, expiresAt);
|
|
2159
2146
|
await users.updatePhone(ctx.user.id, normalised);
|
|
2160
|
-
bus?.emit(NOTIFICATION_EVENT3, {
|
|
2147
|
+
await background3(bus?.emit(NOTIFICATION_EVENT3, {
|
|
2161
2148
|
type: MESSAGE_KEYS.phoneOtp,
|
|
2162
2149
|
locale: ctx.user.locale,
|
|
2163
2150
|
data: { otp },
|
|
2164
2151
|
recipient: { email: null, phone: normalised, deviceToken: null }
|
|
2165
|
-
})
|
|
2166
|
-
});
|
|
2152
|
+
}));
|
|
2167
2153
|
if (ctx.user.email) {
|
|
2168
|
-
bus?.emit(NOTIFICATION_EVENT3, {
|
|
2154
|
+
await background3(bus?.emit(NOTIFICATION_EVENT3, {
|
|
2169
2155
|
type: MESSAGE_KEYS.phoneChanged,
|
|
2170
2156
|
locale: ctx.user.locale,
|
|
2171
2157
|
data: {},
|
|
2172
2158
|
recipient: { email: ctx.user.email, phone: null, deviceToken: null }
|
|
2173
|
-
})
|
|
2174
|
-
});
|
|
2159
|
+
}));
|
|
2175
2160
|
}
|
|
2176
2161
|
return setApiResponse4(
|
|
2177
2162
|
HTTP4.OK,
|
|
@@ -2208,12 +2193,11 @@ function userController(store, config, bus) {
|
|
|
2208
2193
|
const userId = ctx.user.id;
|
|
2209
2194
|
await users.softDelete(userId);
|
|
2210
2195
|
const reqId = ctx.meta["requestId"];
|
|
2211
|
-
bus?.emit(
|
|
2196
|
+
await background3(bus?.emit(
|
|
2212
2197
|
EVENT_KEYS.userDeleted,
|
|
2213
2198
|
{ userId },
|
|
2214
2199
|
reqId !== void 0 ? { requestId: reqId } : void 0
|
|
2215
|
-
)
|
|
2216
|
-
});
|
|
2200
|
+
));
|
|
2217
2201
|
return Response.json(
|
|
2218
2202
|
{ reason: "ACCOUNT_DELETED", explanation: "Account successfully deleted." },
|
|
2219
2203
|
{
|