@shipfox/api-auth 5.0.0 → 7.0.1
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/.turbo/turbo-build.log +1 -1
- package/CHANGELOG.md +69 -0
- package/README.md +71 -37
- package/dist/config.d.ts +0 -12
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +0 -62
- package/dist/config.js.map +1 -1
- package/dist/core/auth.d.ts +21 -2
- package/dist/core/auth.d.ts.map +1 -1
- package/dist/core/auth.js +109 -77
- package/dist/core/auth.js.map +1 -1
- package/dist/core/email-owner.d.ts +12 -0
- package/dist/core/email-owner.d.ts.map +1 -0
- package/dist/core/email-owner.js +20 -0
- package/dist/core/email-owner.js.map +1 -0
- package/dist/core/job-lease-token.d.ts.map +1 -1
- package/dist/core/job-lease-token.js +3 -2
- package/dist/core/job-lease-token.js.map +1 -1
- package/dist/core/jwt.d.ts +2 -2
- package/dist/core/jwt.d.ts.map +1 -1
- package/dist/core/jwt.js.map +1 -1
- package/dist/core/rate-limit.d.ts.map +1 -1
- package/dist/core/rate-limit.js +2 -7
- package/dist/core/rate-limit.js.map +1 -1
- package/dist/core/runner-session-token.d.ts.map +1 -1
- package/dist/core/runner-session-token.js +3 -2
- package/dist/core/runner-session-token.js.map +1 -1
- package/dist/db/db.d.ts +0 -218
- package/dist/db/db.d.ts.map +1 -1
- package/dist/db/db.js +0 -2
- package/dist/db/db.js.map +1 -1
- package/dist/db/users.d.ts +3 -0
- package/dist/db/users.d.ts.map +1 -1
- package/dist/db/users.js +28 -10
- package/dist/db/users.js.map +1 -1
- package/dist/index.d.ts +5 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +40 -34
- package/dist/index.js.map +1 -1
- package/dist/presentation/auth/jwt-auth.d.ts.map +1 -1
- package/dist/presentation/auth/jwt-auth.js +2 -2
- package/dist/presentation/auth/jwt-auth.js.map +1 -1
- package/dist/presentation/e2eRoutes/create-session.d.ts +2 -1
- package/dist/presentation/e2eRoutes/create-session.d.ts.map +1 -1
- package/dist/presentation/e2eRoutes/create-session.js +42 -39
- package/dist/presentation/e2eRoutes/create-session.js.map +1 -1
- package/dist/presentation/e2eRoutes/index.d.ts +2 -1
- package/dist/presentation/e2eRoutes/index.d.ts.map +1 -1
- package/dist/presentation/e2eRoutes/index.js +12 -10
- package/dist/presentation/e2eRoutes/index.js.map +1 -1
- package/dist/presentation/inter-module.d.ts +4 -0
- package/dist/presentation/inter-module.d.ts.map +1 -0
- package/dist/presentation/inter-module.js +16 -0
- package/dist/presentation/inter-module.js.map +1 -0
- package/dist/presentation/routes/email-verification/verify-email-confirm.d.ts +2 -1
- package/dist/presentation/routes/email-verification/verify-email-confirm.d.ts.map +1 -1
- package/dist/presentation/routes/email-verification/verify-email-confirm.js +36 -25
- package/dist/presentation/routes/email-verification/verify-email-confirm.js.map +1 -1
- package/dist/presentation/routes/email-verification/verify-email-resend.d.ts.map +1 -1
- package/dist/presentation/routes/email-verification/verify-email-resend.js +20 -4
- package/dist/presentation/routes/email-verification/verify-email-resend.js.map +1 -1
- package/dist/presentation/routes/index.d.ts +2 -2
- package/dist/presentation/routes/index.d.ts.map +1 -1
- package/dist/presentation/routes/index.js +11 -13
- package/dist/presentation/routes/index.js.map +1 -1
- package/dist/presentation/routes/password/password-reset-confirm.d.ts +2 -1
- package/dist/presentation/routes/password/password-reset-confirm.d.ts.map +1 -1
- package/dist/presentation/routes/password/password-reset-confirm.js +29 -26
- package/dist/presentation/routes/password/password-reset-confirm.js.map +1 -1
- package/dist/presentation/routes/registration/signup.d.ts +2 -1
- package/dist/presentation/routes/registration/signup.d.ts.map +1 -1
- package/dist/presentation/routes/registration/signup.js +86 -68
- package/dist/presentation/routes/registration/signup.js.map +1 -1
- package/dist/presentation/routes/session/login.d.ts +2 -1
- package/dist/presentation/routes/session/login.d.ts.map +1 -1
- package/dist/presentation/routes/session/login.js +40 -37
- package/dist/presentation/routes/session/login.js.map +1 -1
- package/dist/presentation/routes/session/refresh.d.ts +2 -1
- package/dist/presentation/routes/session/refresh.d.ts.map +1 -1
- package/dist/presentation/routes/session/refresh.js +42 -39
- package/dist/presentation/routes/session/refresh.js.map +1 -1
- package/dist/presentation/subscribers/index.d.ts +0 -1
- package/dist/presentation/subscribers/index.d.ts.map +1 -1
- package/dist/presentation/subscribers/index.js +0 -1
- package/dist/presentation/subscribers/index.js.map +1 -1
- package/dist/presentation/subscribers/on-password-reset-send-requested.js +1 -1
- package/dist/presentation/subscribers/on-password-reset-send-requested.js.map +1 -1
- package/dist/tsconfig.test.tsbuildinfo +1 -1
- package/drizzle/0000_initial.sql +1 -13
- package/drizzle/meta/0000_snapshot.json +0 -92
- package/package.json +18 -14
- package/src/config.ts +0 -56
- package/src/core/auth.test.ts +106 -187
- package/src/core/auth.ts +131 -87
- package/src/core/email-owner.test.ts +86 -0
- package/src/core/email-owner.ts +23 -0
- package/src/core/job-lease-token.test.ts +2 -1
- package/src/core/job-lease-token.ts +3 -2
- package/src/core/jwt.ts +2 -2
- package/src/core/rate-limit.test.ts +11 -28
- package/src/core/rate-limit.ts +3 -11
- package/src/core/runner-session-token.test.ts +2 -1
- package/src/core/runner-session-token.ts +3 -2
- package/src/db/db.ts +0 -2
- package/src/db/users.ts +32 -14
- package/src/index.test.ts +15 -11
- package/src/index.ts +23 -20
- package/src/presentation/auth/jwt-auth.test.ts +2 -1
- package/src/presentation/auth/jwt-auth.ts +2 -2
- package/src/presentation/e2eRoutes/create-session.ts +34 -30
- package/src/presentation/e2eRoutes/index.test.ts +9 -6
- package/src/presentation/e2eRoutes/index.ts +8 -5
- package/src/presentation/inter-module.ts +13 -0
- package/src/presentation/routes/email-verification/verify-email-confirm.ts +42 -24
- package/src/presentation/routes/email-verification/verify-email-resend.ts +18 -4
- package/src/presentation/routes/index.test.ts +10 -3
- package/src/presentation/routes/index.ts +22 -12
- package/src/presentation/routes/password/password-reset-confirm.ts +25 -22
- package/src/presentation/routes/password/password-reset-request.test.ts +1 -0
- package/src/presentation/routes/rate-limit.test.ts +2 -2
- package/src/presentation/routes/registration/signup.test.ts +39 -74
- package/src/presentation/routes/registration/signup.ts +89 -70
- package/src/presentation/routes/session/login.ts +38 -35
- package/src/presentation/routes/session/refresh.ts +43 -40
- package/src/presentation/subscribers/email-send-requested.test.ts +2 -30
- package/src/presentation/subscribers/index.ts +0 -1
- package/src/presentation/subscribers/on-password-reset-send-requested.ts +1 -1
- package/test/env.ts +1 -3
- package/test/globalSetup.ts +10 -1
- package/test/routes.ts +51 -84
- package/tsconfig.build.tsbuildinfo +1 -1
- package/dist/core/entities/email-verification.d.ts +0 -9
- package/dist/core/entities/email-verification.d.ts.map +0 -1
- package/dist/core/entities/email-verification.js +0 -3
- package/dist/core/entities/email-verification.js.map +0 -1
- package/dist/db/email-verifications.d.ts +0 -39
- package/dist/db/email-verifications.d.ts.map +0 -1
- package/dist/db/email-verifications.js +0 -95
- package/dist/db/email-verifications.js.map +0 -1
- package/dist/db/schema/email-verifications.d.ts +0 -114
- package/dist/db/schema/email-verifications.d.ts.map +0 -1
- package/dist/db/schema/email-verifications.js +0 -35
- package/dist/db/schema/email-verifications.js.map +0 -1
- package/dist/presentation/subscribers/on-email-verification-send-requested.d.ts +0 -3
- package/dist/presentation/subscribers/on-email-verification-send-requested.d.ts.map +0 -1
- package/dist/presentation/subscribers/on-email-verification-send-requested.js +0 -13
- package/dist/presentation/subscribers/on-email-verification-send-requested.js.map +0 -1
- package/src/core/entities/email-verification.ts +0 -8
- package/src/db/email-verifications.test.ts +0 -61
- package/src/db/email-verifications.ts +0 -160
- package/src/db/schema/email-verifications.ts +0 -37
- package/src/presentation/routes/email-verification/verify-email-confirm.test.ts +0 -66
- package/src/presentation/routes/email-verification/verify-email-resend.test.ts +0 -100
- package/src/presentation/subscribers/on-email-verification-send-requested.ts +0 -10
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/presentation/routes/index.ts"],"sourcesContent":["import type {
|
|
1
|
+
{"version":3,"sources":["../../../src/presentation/routes/index.ts"],"sourcesContent":["import type {WorkspacesInterModuleClient} from '@shipfox/api-workspaces-dto/inter-module';\nimport type {RouteGroup} from '@shipfox/node-fastify';\nimport {authCookiePlugin} from '#presentation/auth/refresh-cookie.js';\nimport {createVerifyEmailConfirmRoute} from './email-verification/verify-email-confirm.js';\nimport {verifyEmailResendRoute} from './email-verification/verify-email-resend.js';\nimport {changePasswordRoute} from './password/change-password.js';\nimport {createPasswordResetConfirmRoute} from './password/password-reset-confirm.js';\nimport {passwordResetRequestRoute} from './password/password-reset-request.js';\nimport {createSignupRoute} from './registration/signup.js';\nimport {createLoginRoute} from './session/login.js';\nimport {logoutRoute} from './session/logout.js';\nimport {meRoute} from './session/me.js';\nimport {createRefreshRoute} from './session/refresh.js';\n\nexport function buildAuthRoutes(\n passwordEnabled: boolean,\n workspaces: WorkspacesInterModuleClient,\n): RouteGroup {\n const passwordRoutes = passwordEnabled\n ? [\n createSignupRoute(workspaces),\n createVerifyEmailConfirmRoute(workspaces),\n verifyEmailResendRoute,\n createLoginRoute(workspaces),\n ]\n : [];\n\n return {\n prefix: '/auth',\n plugins: [authCookiePlugin],\n routes: [\n ...passwordRoutes,\n createRefreshRoute(workspaces),\n logoutRoute,\n meRoute,\n ...(passwordEnabled\n ? [\n changePasswordRoute,\n passwordResetRequestRoute,\n createPasswordResetConfirmRoute(workspaces),\n ]\n : []),\n ],\n };\n}\n"],"names":["authCookiePlugin","createVerifyEmailConfirmRoute","verifyEmailResendRoute","changePasswordRoute","createPasswordResetConfirmRoute","passwordResetRequestRoute","createSignupRoute","createLoginRoute","logoutRoute","meRoute","createRefreshRoute","buildAuthRoutes","passwordEnabled","workspaces","passwordRoutes","prefix","plugins","routes"],"mappings":"AAEA,SAAQA,gBAAgB,QAAO,uCAAuC;AACtE,SAAQC,6BAA6B,QAAO,+CAA+C;AAC3F,SAAQC,sBAAsB,QAAO,8CAA8C;AACnF,SAAQC,mBAAmB,QAAO,gCAAgC;AAClE,SAAQC,+BAA+B,QAAO,uCAAuC;AACrF,SAAQC,yBAAyB,QAAO,uCAAuC;AAC/E,SAAQC,iBAAiB,QAAO,2BAA2B;AAC3D,SAAQC,gBAAgB,QAAO,qBAAqB;AACpD,SAAQC,WAAW,QAAO,sBAAsB;AAChD,SAAQC,OAAO,QAAO,kBAAkB;AACxC,SAAQC,kBAAkB,QAAO,uBAAuB;AAExD,OAAO,SAASC,gBACdC,eAAwB,EACxBC,UAAuC;IAEvC,MAAMC,iBAAiBF,kBACnB;QACEN,kBAAkBO;QAClBZ,8BAA8BY;QAC9BX;QACAK,iBAAiBM;KAClB,GACD,EAAE;IAEN,OAAO;QACLE,QAAQ;QACRC,SAAS;YAAChB;SAAiB;QAC3BiB,QAAQ;eACHH;YACHJ,mBAAmBG;YACnBL;YACAC;eACIG,kBACA;gBACET;gBACAE;gBACAD,gCAAgCS;aACjC,GACD,EAAE;SACP;IACH;AACF"}
|
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
|
|
1
|
+
import type { WorkspacesInterModuleClient } from '@shipfox/api-workspaces-dto/inter-module';
|
|
2
|
+
export declare function createPasswordResetConfirmRoute(workspaces: WorkspacesInterModuleClient): import("@shipfox/node-fastify").RouteDefinition;
|
|
2
3
|
//# sourceMappingURL=password-reset-confirm.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"password-reset-confirm.d.ts","sourceRoot":"","sources":["../../../../src/presentation/routes/password/password-reset-confirm.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"password-reset-confirm.d.ts","sourceRoot":"","sources":["../../../../src/presentation/routes/password/password-reset-confirm.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,2BAA2B,EAAC,MAAM,0CAA0C,CAAC;AAO1F,wBAAgB,+BAA+B,CAAC,UAAU,EAAE,2BAA2B,mDA0BtF"}
|
|
@@ -4,33 +4,36 @@ import { confirmPasswordReset } from '#core/auth.js';
|
|
|
4
4
|
import { TokenInvalidError } from '#core/errors.js';
|
|
5
5
|
import { setRefreshTokenCookie } from '#presentation/auth/refresh-cookie.js';
|
|
6
6
|
import { toAuthSessionDto } from '#presentation/dto/user.js';
|
|
7
|
-
export
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
7
|
+
export function createPasswordResetConfirmRoute(workspaces) {
|
|
8
|
+
return defineRoute({
|
|
9
|
+
method: 'POST',
|
|
10
|
+
path: '/password-reset/confirm',
|
|
11
|
+
description: 'Set a new password using the link sent by email.',
|
|
12
|
+
schema: {
|
|
13
|
+
body: passwordResetConfirmBodySchema,
|
|
14
|
+
response: {
|
|
15
|
+
200: passwordResetConfirmResponseSchema
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
errorHandler: (error)=>{
|
|
19
|
+
if (error instanceof TokenInvalidError) {
|
|
20
|
+
throw new ClientError('Reset token is invalid or expired', 'token-invalid', {
|
|
21
|
+
status: 410
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
throw error;
|
|
25
|
+
},
|
|
26
|
+
handler: async (request, reply)=>{
|
|
27
|
+
const { token, new_password } = request.body;
|
|
28
|
+
const result = await confirmPasswordReset({
|
|
29
|
+
token,
|
|
30
|
+
newPassword: new_password,
|
|
31
|
+
workspaces
|
|
21
32
|
});
|
|
33
|
+
setRefreshTokenCookie(reply, result.refreshToken);
|
|
34
|
+
return toAuthSessionDto(result);
|
|
22
35
|
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
handler: async (request, reply)=>{
|
|
26
|
-
const { token, new_password } = request.body;
|
|
27
|
-
const result = await confirmPasswordReset({
|
|
28
|
-
token,
|
|
29
|
-
newPassword: new_password
|
|
30
|
-
});
|
|
31
|
-
setRefreshTokenCookie(reply, result.refreshToken);
|
|
32
|
-
return toAuthSessionDto(result);
|
|
33
|
-
}
|
|
34
|
-
});
|
|
36
|
+
});
|
|
37
|
+
}
|
|
35
38
|
|
|
36
39
|
//# sourceMappingURL=password-reset-confirm.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/presentation/routes/password/password-reset-confirm.ts"],"sourcesContent":["import {\n passwordResetConfirmBodySchema,\n passwordResetConfirmResponseSchema,\n} from '@shipfox/api-auth-dto';\nimport {ClientError, defineRoute} from '@shipfox/node-fastify';\nimport {confirmPasswordReset} from '#core/auth.js';\nimport {TokenInvalidError} from '#core/errors.js';\nimport {setRefreshTokenCookie} from '#presentation/auth/refresh-cookie.js';\nimport {toAuthSessionDto} from '#presentation/dto/user.js';\n\nexport
|
|
1
|
+
{"version":3,"sources":["../../../../src/presentation/routes/password/password-reset-confirm.ts"],"sourcesContent":["import {\n passwordResetConfirmBodySchema,\n passwordResetConfirmResponseSchema,\n} from '@shipfox/api-auth-dto';\nimport type {WorkspacesInterModuleClient} from '@shipfox/api-workspaces-dto/inter-module';\nimport {ClientError, defineRoute} from '@shipfox/node-fastify';\nimport {confirmPasswordReset} from '#core/auth.js';\nimport {TokenInvalidError} from '#core/errors.js';\nimport {setRefreshTokenCookie} from '#presentation/auth/refresh-cookie.js';\nimport {toAuthSessionDto} from '#presentation/dto/user.js';\n\nexport function createPasswordResetConfirmRoute(workspaces: WorkspacesInterModuleClient) {\n return defineRoute({\n method: 'POST',\n path: '/password-reset/confirm',\n description: 'Set a new password using the link sent by email.',\n schema: {\n body: passwordResetConfirmBodySchema,\n response: {\n 200: passwordResetConfirmResponseSchema,\n },\n },\n errorHandler: (error) => {\n if (error instanceof TokenInvalidError) {\n throw new ClientError('Reset token is invalid or expired', 'token-invalid', {status: 410});\n }\n throw error;\n },\n handler: async (request, reply) => {\n const {token, new_password} = request.body;\n\n const result = await confirmPasswordReset({token, newPassword: new_password, workspaces});\n setRefreshTokenCookie(reply, result.refreshToken);\n\n return toAuthSessionDto(result);\n },\n });\n}\n"],"names":["passwordResetConfirmBodySchema","passwordResetConfirmResponseSchema","ClientError","defineRoute","confirmPasswordReset","TokenInvalidError","setRefreshTokenCookie","toAuthSessionDto","createPasswordResetConfirmRoute","workspaces","method","path","description","schema","body","response","errorHandler","error","status","handler","request","reply","token","new_password","result","newPassword","refreshToken"],"mappings":"AAAA,SACEA,8BAA8B,EAC9BC,kCAAkC,QAC7B,wBAAwB;AAE/B,SAAQC,WAAW,EAAEC,WAAW,QAAO,wBAAwB;AAC/D,SAAQC,oBAAoB,QAAO,gBAAgB;AACnD,SAAQC,iBAAiB,QAAO,kBAAkB;AAClD,SAAQC,qBAAqB,QAAO,uCAAuC;AAC3E,SAAQC,gBAAgB,QAAO,4BAA4B;AAE3D,OAAO,SAASC,gCAAgCC,UAAuC;IACrF,OAAON,YAAY;QACjBO,QAAQ;QACRC,MAAM;QACNC,aAAa;QACbC,QAAQ;YACNC,MAAMd;YACNe,UAAU;gBACR,KAAKd;YACP;QACF;QACAe,cAAc,CAACC;YACb,IAAIA,iBAAiBZ,mBAAmB;gBACtC,MAAM,IAAIH,YAAY,qCAAqC,iBAAiB;oBAACgB,QAAQ;gBAAG;YAC1F;YACA,MAAMD;QACR;QACAE,SAAS,OAAOC,SAASC;YACvB,MAAM,EAACC,KAAK,EAAEC,YAAY,EAAC,GAAGH,QAAQN,IAAI;YAE1C,MAAMU,SAAS,MAAMpB,qBAAqB;gBAACkB;gBAAOG,aAAaF;gBAAcd;YAAU;YACvFH,sBAAsBe,OAAOG,OAAOE,YAAY;YAEhD,OAAOnB,iBAAiBiB;QAC1B;IACF;AACF"}
|
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
|
|
1
|
+
import type { WorkspacesInterModuleClient } from '@shipfox/api-workspaces-dto/inter-module';
|
|
2
|
+
export declare function createSignupRoute(workspaces: WorkspacesInterModuleClient): import("@shipfox/node-fastify").RouteDefinition;
|
|
2
3
|
//# sourceMappingURL=signup.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"signup.d.ts","sourceRoot":"","sources":["../../../../src/presentation/routes/registration/signup.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"signup.d.ts","sourceRoot":"","sources":["../../../../src/presentation/routes/registration/signup.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAC,2BAA2B,EAAC,MAAM,0CAA0C,CAAC;AAa1F,wBAAgB,iBAAiB,CAAC,UAAU,EAAE,2BAA2B,mDAoFxE"}
|
|
@@ -1,82 +1,100 @@
|
|
|
1
1
|
import { signupBodySchema, signupResponseSchema } from '@shipfox/api-auth-dto';
|
|
2
|
-
import {
|
|
2
|
+
import { EmailChallengeError } from '@shipfox/api-email-challenges';
|
|
3
3
|
import { ClientError, defineRoute } from '@shipfox/node-fastify';
|
|
4
4
|
import { signup, signupWithInvitation } from '#core/auth.js';
|
|
5
|
-
import { EmailTakenError } from '#core/errors.js';
|
|
5
|
+
import { EmailTakenError, InvitationEmailMismatchError, TokenAlreadyUsedError, TokenExpiredError, TokenInvalidError } from '#core/errors.js';
|
|
6
6
|
import { setRefreshTokenCookie } from '#presentation/auth/refresh-cookie.js';
|
|
7
7
|
import { toUserDto } from '#presentation/dto/user.js';
|
|
8
|
-
export
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
8
|
+
export function createSignupRoute(workspaces) {
|
|
9
|
+
return defineRoute({
|
|
10
|
+
method: 'POST',
|
|
11
|
+
path: '/signup',
|
|
12
|
+
description: 'Create a user account. Sends a verification email unless an invitation token is supplied.',
|
|
13
|
+
schema: {
|
|
14
|
+
body: signupBodySchema,
|
|
15
|
+
response: {
|
|
16
|
+
201: signupResponseSchema
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
errorHandler: (error)=>{
|
|
20
|
+
if (error instanceof EmailChallengeError) {
|
|
21
|
+
throw new ClientError(error.message, `email-challenge-${error.code}`, {
|
|
22
|
+
status: error.code === 'limited' ? 429 : 400,
|
|
23
|
+
...error.retryAt ? {
|
|
24
|
+
details: {
|
|
25
|
+
retry_at: error.retryAt.toISOString()
|
|
26
|
+
}
|
|
27
|
+
} : {}
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
if (error instanceof EmailTakenError) {
|
|
31
|
+
throw new ClientError('Email already registered', 'email-taken', {
|
|
32
|
+
status: 409
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
if (error instanceof TokenInvalidError) {
|
|
36
|
+
throw new ClientError('Invitation token is invalid', 'invitation-token-invalid', {
|
|
37
|
+
status: 410
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
if (error instanceof TokenAlreadyUsedError) {
|
|
41
|
+
throw new ClientError('Invitation has already been accepted', 'invitation-token-used', {
|
|
42
|
+
status: 410
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
if (error instanceof TokenExpiredError) {
|
|
46
|
+
throw new ClientError('Invitation has expired', 'invitation-token-expired', {
|
|
47
|
+
status: 410
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
if (error instanceof InvitationEmailMismatchError) {
|
|
51
|
+
throw new ClientError('Signup email does not match the invitation', 'invitation-email-mismatch', {
|
|
52
|
+
status: 403
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
throw error;
|
|
56
|
+
},
|
|
57
|
+
handler: async (request, reply)=>{
|
|
58
|
+
const { email, password, name, invitation_token } = request.body;
|
|
59
|
+
if (invitation_token === undefined) {
|
|
60
|
+
const result = await signup({
|
|
61
|
+
email,
|
|
62
|
+
password,
|
|
63
|
+
name,
|
|
64
|
+
sourceIp: request.ip
|
|
65
|
+
});
|
|
66
|
+
reply.code(201);
|
|
67
|
+
return {
|
|
68
|
+
user: toUserDto(result),
|
|
69
|
+
email_challenge: {
|
|
70
|
+
id: result.emailChallenge.id,
|
|
71
|
+
next_resend_available_at: result.emailChallenge.nextResendAvailableAt.toISOString()
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
const result = await signupWithInvitation({
|
|
50
76
|
email,
|
|
51
77
|
password,
|
|
52
|
-
name
|
|
78
|
+
name,
|
|
79
|
+
invitationToken: invitation_token,
|
|
80
|
+
workspaces
|
|
53
81
|
});
|
|
82
|
+
setRefreshTokenCookie(reply, result.refreshToken);
|
|
54
83
|
reply.code(201);
|
|
55
84
|
return {
|
|
56
|
-
user: toUserDto(user)
|
|
85
|
+
user: toUserDto(result.user),
|
|
86
|
+
token: result.token,
|
|
87
|
+
membership: result.membership ? {
|
|
88
|
+
id: result.membership.id,
|
|
89
|
+
user_id: result.membership.userId,
|
|
90
|
+
workspace_id: result.membership.workspaceId
|
|
91
|
+
} : null,
|
|
92
|
+
...result.acceptError ? {
|
|
93
|
+
accept_error: result.acceptError
|
|
94
|
+
} : {}
|
|
57
95
|
};
|
|
58
96
|
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
password,
|
|
62
|
-
name,
|
|
63
|
-
invitationToken: invitation_token
|
|
64
|
-
});
|
|
65
|
-
setRefreshTokenCookie(reply, result.refreshToken);
|
|
66
|
-
reply.code(201);
|
|
67
|
-
return {
|
|
68
|
-
user: toUserDto(result.user),
|
|
69
|
-
token: result.token,
|
|
70
|
-
membership: result.membership ? {
|
|
71
|
-
id: result.membership.id,
|
|
72
|
-
user_id: result.membership.userId,
|
|
73
|
-
workspace_id: result.membership.workspaceId
|
|
74
|
-
} : null,
|
|
75
|
-
...result.acceptError ? {
|
|
76
|
-
accept_error: result.acceptError
|
|
77
|
-
} : {}
|
|
78
|
-
};
|
|
79
|
-
}
|
|
80
|
-
});
|
|
97
|
+
});
|
|
98
|
+
}
|
|
81
99
|
|
|
82
100
|
//# sourceMappingURL=signup.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/presentation/routes/registration/signup.ts"],"sourcesContent":["import {signupBodySchema, signupResponseSchema} from '@shipfox/api-auth-dto';\nimport {
|
|
1
|
+
{"version":3,"sources":["../../../../src/presentation/routes/registration/signup.ts"],"sourcesContent":["import {signupBodySchema, signupResponseSchema} from '@shipfox/api-auth-dto';\nimport {EmailChallengeError} from '@shipfox/api-email-challenges';\nimport type {WorkspacesInterModuleClient} from '@shipfox/api-workspaces-dto/inter-module';\nimport {ClientError, defineRoute} from '@shipfox/node-fastify';\nimport {signup, signupWithInvitation} from '#core/auth.js';\nimport {\n EmailTakenError,\n InvitationEmailMismatchError,\n TokenAlreadyUsedError,\n TokenExpiredError,\n TokenInvalidError,\n} from '#core/errors.js';\nimport {setRefreshTokenCookie} from '#presentation/auth/refresh-cookie.js';\nimport {toUserDto} from '#presentation/dto/user.js';\n\nexport function createSignupRoute(workspaces: WorkspacesInterModuleClient) {\n return defineRoute({\n method: 'POST',\n path: '/signup',\n description:\n 'Create a user account. Sends a verification email unless an invitation token is supplied.',\n schema: {\n body: signupBodySchema,\n response: {\n 201: signupResponseSchema,\n },\n },\n errorHandler: (error) => {\n if (error instanceof EmailChallengeError) {\n throw new ClientError(error.message, `email-challenge-${error.code}`, {\n status: error.code === 'limited' ? 429 : 400,\n ...(error.retryAt ? {details: {retry_at: error.retryAt.toISOString()}} : {}),\n });\n }\n if (error instanceof EmailTakenError) {\n throw new ClientError('Email already registered', 'email-taken', {status: 409});\n }\n if (error instanceof TokenInvalidError) {\n throw new ClientError('Invitation token is invalid', 'invitation-token-invalid', {\n status: 410,\n });\n }\n if (error instanceof TokenAlreadyUsedError) {\n throw new ClientError('Invitation has already been accepted', 'invitation-token-used', {\n status: 410,\n });\n }\n if (error instanceof TokenExpiredError) {\n throw new ClientError('Invitation has expired', 'invitation-token-expired', {\n status: 410,\n });\n }\n if (error instanceof InvitationEmailMismatchError) {\n throw new ClientError(\n 'Signup email does not match the invitation',\n 'invitation-email-mismatch',\n {status: 403},\n );\n }\n throw error;\n },\n handler: async (request, reply) => {\n const {email, password, name, invitation_token} = request.body;\n\n if (invitation_token === undefined) {\n const result = await signup({email, password, name, sourceIp: request.ip});\n reply.code(201);\n return {\n user: toUserDto(result),\n email_challenge: {\n id: result.emailChallenge.id,\n next_resend_available_at: result.emailChallenge.nextResendAvailableAt.toISOString(),\n },\n };\n }\n\n const result = await signupWithInvitation({\n email,\n password,\n name,\n invitationToken: invitation_token,\n workspaces,\n });\n setRefreshTokenCookie(reply, result.refreshToken);\n reply.code(201);\n return {\n user: toUserDto(result.user),\n token: result.token,\n membership: result.membership\n ? {\n id: result.membership.id,\n user_id: result.membership.userId,\n workspace_id: result.membership.workspaceId,\n }\n : null,\n ...(result.acceptError ? {accept_error: result.acceptError} : {}),\n };\n },\n });\n}\n"],"names":["signupBodySchema","signupResponseSchema","EmailChallengeError","ClientError","defineRoute","signup","signupWithInvitation","EmailTakenError","InvitationEmailMismatchError","TokenAlreadyUsedError","TokenExpiredError","TokenInvalidError","setRefreshTokenCookie","toUserDto","createSignupRoute","workspaces","method","path","description","schema","body","response","errorHandler","error","message","code","status","retryAt","details","retry_at","toISOString","handler","request","reply","email","password","name","invitation_token","undefined","result","sourceIp","ip","user","email_challenge","id","emailChallenge","next_resend_available_at","nextResendAvailableAt","invitationToken","refreshToken","token","membership","user_id","userId","workspace_id","workspaceId","acceptError","accept_error"],"mappings":"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"}
|
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
|
|
1
|
+
import type { WorkspacesInterModuleClient } from '@shipfox/api-workspaces-dto/inter-module';
|
|
2
|
+
export declare function createLoginRoute(workspaces: WorkspacesInterModuleClient): import("@shipfox/node-fastify").RouteDefinition;
|
|
2
3
|
//# sourceMappingURL=login.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"login.d.ts","sourceRoot":"","sources":["../../../../src/presentation/routes/session/login.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"login.d.ts","sourceRoot":"","sources":["../../../../src/presentation/routes/session/login.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAC,2BAA2B,EAAC,MAAM,0CAA0C,CAAC;AAY1F,wBAAgB,gBAAgB,CAAC,UAAU,EAAE,2BAA2B,mDAuCvE"}
|
|
@@ -5,44 +5,47 @@ import { AuthDependencyUnavailableError, EmailNotVerifiedError, InvalidCredentia
|
|
|
5
5
|
import { setRefreshTokenCookie } from '#presentation/auth/refresh-cookie.js';
|
|
6
6
|
import { toAuthSessionDto } from '#presentation/dto/user.js';
|
|
7
7
|
import { createAuthRateLimitPreHandler } from '#presentation/routes/rate-limit.js';
|
|
8
|
-
export
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
8
|
+
export function createLoginRoute(workspaces) {
|
|
9
|
+
return defineRoute({
|
|
10
|
+
method: 'POST',
|
|
11
|
+
path: '/login',
|
|
12
|
+
description: 'Sign in with an email address and password.',
|
|
13
|
+
schema: {
|
|
14
|
+
body: loginBodySchema,
|
|
15
|
+
response: {
|
|
16
|
+
200: loginResponseSchema
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
preHandler: createAuthRateLimitPreHandler('login'),
|
|
20
|
+
errorHandler: (error)=>{
|
|
21
|
+
if (error instanceof InvalidCredentialsError) {
|
|
22
|
+
throw new ClientError('Invalid credentials', 'invalid-credentials', {
|
|
23
|
+
status: 401
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
if (error instanceof EmailNotVerifiedError) {
|
|
27
|
+
throw new ClientError('Email not verified', 'email-not-verified', {
|
|
28
|
+
status: 403
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
if (error instanceof AuthDependencyUnavailableError) {
|
|
32
|
+
throw new ClientError('Authentication dependency unavailable', 'auth-dependency-unavailable', {
|
|
33
|
+
status: 503
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
throw error;
|
|
37
|
+
},
|
|
38
|
+
handler: async (request, reply)=>{
|
|
39
|
+
const { email, password } = request.body;
|
|
40
|
+
const result = await login({
|
|
41
|
+
email,
|
|
42
|
+
password,
|
|
43
|
+
workspaces
|
|
33
44
|
});
|
|
45
|
+
setRefreshTokenCookie(reply, result.refreshToken);
|
|
46
|
+
return toAuthSessionDto(result);
|
|
34
47
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
handler: async (request, reply)=>{
|
|
38
|
-
const { email, password } = request.body;
|
|
39
|
-
const result = await login({
|
|
40
|
-
email,
|
|
41
|
-
password
|
|
42
|
-
});
|
|
43
|
-
setRefreshTokenCookie(reply, result.refreshToken);
|
|
44
|
-
return toAuthSessionDto(result);
|
|
45
|
-
}
|
|
46
|
-
});
|
|
48
|
+
});
|
|
49
|
+
}
|
|
47
50
|
|
|
48
51
|
//# sourceMappingURL=login.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/presentation/routes/session/login.ts"],"sourcesContent":["import {loginBodySchema, loginResponseSchema} from '@shipfox/api-auth-dto';\nimport {ClientError, defineRoute} from '@shipfox/node-fastify';\nimport {login} from '#core/auth.js';\nimport {\n AuthDependencyUnavailableError,\n EmailNotVerifiedError,\n InvalidCredentialsError,\n} from '#core/errors.js';\nimport {setRefreshTokenCookie} from '#presentation/auth/refresh-cookie.js';\nimport {toAuthSessionDto} from '#presentation/dto/user.js';\nimport {createAuthRateLimitPreHandler} from '#presentation/routes/rate-limit.js';\n\nexport
|
|
1
|
+
{"version":3,"sources":["../../../../src/presentation/routes/session/login.ts"],"sourcesContent":["import {loginBodySchema, loginResponseSchema} from '@shipfox/api-auth-dto';\nimport type {WorkspacesInterModuleClient} from '@shipfox/api-workspaces-dto/inter-module';\nimport {ClientError, defineRoute} from '@shipfox/node-fastify';\nimport {login} from '#core/auth.js';\nimport {\n AuthDependencyUnavailableError,\n EmailNotVerifiedError,\n InvalidCredentialsError,\n} from '#core/errors.js';\nimport {setRefreshTokenCookie} from '#presentation/auth/refresh-cookie.js';\nimport {toAuthSessionDto} from '#presentation/dto/user.js';\nimport {createAuthRateLimitPreHandler} from '#presentation/routes/rate-limit.js';\n\nexport function createLoginRoute(workspaces: WorkspacesInterModuleClient) {\n return defineRoute({\n method: 'POST',\n path: '/login',\n description: 'Sign in with an email address and password.',\n schema: {\n body: loginBodySchema,\n response: {\n 200: loginResponseSchema,\n },\n },\n preHandler: createAuthRateLimitPreHandler('login'),\n errorHandler: (error) => {\n if (error instanceof InvalidCredentialsError) {\n throw new ClientError('Invalid credentials', 'invalid-credentials', {status: 401});\n }\n if (error instanceof EmailNotVerifiedError) {\n throw new ClientError('Email not verified', 'email-not-verified', {status: 403});\n }\n if (error instanceof AuthDependencyUnavailableError) {\n throw new ClientError(\n 'Authentication dependency unavailable',\n 'auth-dependency-unavailable',\n {\n status: 503,\n },\n );\n }\n throw error;\n },\n handler: async (request, reply) => {\n const {email, password} = request.body;\n\n const result = await login({email, password, workspaces});\n setRefreshTokenCookie(reply, result.refreshToken);\n\n return toAuthSessionDto(result);\n },\n });\n}\n"],"names":["loginBodySchema","loginResponseSchema","ClientError","defineRoute","login","AuthDependencyUnavailableError","EmailNotVerifiedError","InvalidCredentialsError","setRefreshTokenCookie","toAuthSessionDto","createAuthRateLimitPreHandler","createLoginRoute","workspaces","method","path","description","schema","body","response","preHandler","errorHandler","error","status","handler","request","reply","email","password","result","refreshToken"],"mappings":"AAAA,SAAQA,eAAe,EAAEC,mBAAmB,QAAO,wBAAwB;AAE3E,SAAQC,WAAW,EAAEC,WAAW,QAAO,wBAAwB;AAC/D,SAAQC,KAAK,QAAO,gBAAgB;AACpC,SACEC,8BAA8B,EAC9BC,qBAAqB,EACrBC,uBAAuB,QAClB,kBAAkB;AACzB,SAAQC,qBAAqB,QAAO,uCAAuC;AAC3E,SAAQC,gBAAgB,QAAO,4BAA4B;AAC3D,SAAQC,6BAA6B,QAAO,qCAAqC;AAEjF,OAAO,SAASC,iBAAiBC,UAAuC;IACtE,OAAOT,YAAY;QACjBU,QAAQ;QACRC,MAAM;QACNC,aAAa;QACbC,QAAQ;YACNC,MAAMjB;YACNkB,UAAU;gBACR,KAAKjB;YACP;QACF;QACAkB,YAAYT,8BAA8B;QAC1CU,cAAc,CAACC;YACb,IAAIA,iBAAiBd,yBAAyB;gBAC5C,MAAM,IAAIL,YAAY,uBAAuB,uBAAuB;oBAACoB,QAAQ;gBAAG;YAClF;YACA,IAAID,iBAAiBf,uBAAuB;gBAC1C,MAAM,IAAIJ,YAAY,sBAAsB,sBAAsB;oBAACoB,QAAQ;gBAAG;YAChF;YACA,IAAID,iBAAiBhB,gCAAgC;gBACnD,MAAM,IAAIH,YACR,yCACA,+BACA;oBACEoB,QAAQ;gBACV;YAEJ;YACA,MAAMD;QACR;QACAE,SAAS,OAAOC,SAASC;YACvB,MAAM,EAACC,KAAK,EAAEC,QAAQ,EAAC,GAAGH,QAAQP,IAAI;YAEtC,MAAMW,SAAS,MAAMxB,MAAM;gBAACsB;gBAAOC;gBAAUf;YAAU;YACvDJ,sBAAsBiB,OAAOG,OAAOC,YAAY;YAEhD,OAAOpB,iBAAiBmB;QAC1B;IACF;AACF"}
|
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
|
|
1
|
+
import type { WorkspacesInterModuleClient } from '@shipfox/api-workspaces-dto/inter-module';
|
|
2
|
+
export declare function createRefreshRoute(workspaces: WorkspacesInterModuleClient): import("@shipfox/node-fastify").RouteDefinition;
|
|
2
3
|
//# sourceMappingURL=refresh.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"refresh.d.ts","sourceRoot":"","sources":["../../../../src/presentation/routes/session/refresh.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"refresh.d.ts","sourceRoot":"","sources":["../../../../src/presentation/routes/session/refresh.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAC,2BAA2B,EAAC,MAAM,0CAA0C,CAAC;AAW1F,wBAAgB,kBAAkB,CAAC,UAAU,EAAE,2BAA2B,mDA4CzE"}
|
|
@@ -4,46 +4,49 @@ import { refreshAccessToken } from '#core/auth.js';
|
|
|
4
4
|
import { AuthDependencyUnavailableError, TokenInvalidError } from '#core/errors.js';
|
|
5
5
|
import { clearRefreshTokenCookie, getRefreshTokenCookie, setRefreshTokenCookie } from '#presentation/auth/refresh-cookie.js';
|
|
6
6
|
import { toAuthSessionDto } from '#presentation/dto/user.js';
|
|
7
|
-
export
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
7
|
+
export function createRefreshRoute(workspaces) {
|
|
8
|
+
return defineRoute({
|
|
9
|
+
method: 'POST',
|
|
10
|
+
path: '/refresh',
|
|
11
|
+
description: 'Refresh the current browser session access token.',
|
|
12
|
+
schema: {
|
|
13
|
+
response: {
|
|
14
|
+
200: refreshResponseSchema
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
errorHandler: (error, _request, reply)=>{
|
|
18
|
+
if (error instanceof TokenInvalidError) {
|
|
19
|
+
clearRefreshTokenCookie(reply);
|
|
20
|
+
throw new ClientError('Refresh token is invalid or expired', 'unauthorized', {
|
|
21
|
+
status: 401
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
if (error instanceof AuthDependencyUnavailableError) {
|
|
25
|
+
throw new ClientError('Authentication dependency unavailable', 'auth-dependency-unavailable', {
|
|
26
|
+
status: 503
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
throw error;
|
|
30
|
+
},
|
|
31
|
+
handler: async (request, reply)=>{
|
|
32
|
+
const refreshToken = getRefreshTokenCookie(request);
|
|
33
|
+
if (!refreshToken) {
|
|
34
|
+
clearRefreshTokenCookie(reply);
|
|
35
|
+
throw new ClientError('Refresh token is invalid or expired', 'unauthorized', {
|
|
36
|
+
status: 401
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
const result = await refreshAccessToken({
|
|
40
|
+
refreshToken,
|
|
41
|
+
workspaces
|
|
26
42
|
});
|
|
43
|
+
// Absent on a grace-window hit: keep the existing cookie rather than overwrite it.
|
|
44
|
+
if (result.refreshToken) {
|
|
45
|
+
setRefreshTokenCookie(reply, result.refreshToken);
|
|
46
|
+
}
|
|
47
|
+
return toAuthSessionDto(result);
|
|
27
48
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
handler: async (request, reply)=>{
|
|
31
|
-
const refreshToken = getRefreshTokenCookie(request);
|
|
32
|
-
if (!refreshToken) {
|
|
33
|
-
clearRefreshTokenCookie(reply);
|
|
34
|
-
throw new ClientError('Refresh token is invalid or expired', 'unauthorized', {
|
|
35
|
-
status: 401
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
const result = await refreshAccessToken({
|
|
39
|
-
refreshToken
|
|
40
|
-
});
|
|
41
|
-
// Absent on a grace-window hit: keep the existing cookie rather than overwrite it.
|
|
42
|
-
if (result.refreshToken) {
|
|
43
|
-
setRefreshTokenCookie(reply, result.refreshToken);
|
|
44
|
-
}
|
|
45
|
-
return toAuthSessionDto(result);
|
|
46
|
-
}
|
|
47
|
-
});
|
|
49
|
+
});
|
|
50
|
+
}
|
|
48
51
|
|
|
49
52
|
//# sourceMappingURL=refresh.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/presentation/routes/session/refresh.ts"],"sourcesContent":["import {refreshResponseSchema} from '@shipfox/api-auth-dto';\nimport {ClientError, defineRoute} from '@shipfox/node-fastify';\nimport {refreshAccessToken} from '#core/auth.js';\nimport {AuthDependencyUnavailableError, TokenInvalidError} from '#core/errors.js';\nimport {\n clearRefreshTokenCookie,\n getRefreshTokenCookie,\n setRefreshTokenCookie,\n} from '#presentation/auth/refresh-cookie.js';\nimport {toAuthSessionDto} from '#presentation/dto/user.js';\n\nexport
|
|
1
|
+
{"version":3,"sources":["../../../../src/presentation/routes/session/refresh.ts"],"sourcesContent":["import {refreshResponseSchema} from '@shipfox/api-auth-dto';\nimport type {WorkspacesInterModuleClient} from '@shipfox/api-workspaces-dto/inter-module';\nimport {ClientError, defineRoute} from '@shipfox/node-fastify';\nimport {refreshAccessToken} from '#core/auth.js';\nimport {AuthDependencyUnavailableError, TokenInvalidError} from '#core/errors.js';\nimport {\n clearRefreshTokenCookie,\n getRefreshTokenCookie,\n setRefreshTokenCookie,\n} from '#presentation/auth/refresh-cookie.js';\nimport {toAuthSessionDto} from '#presentation/dto/user.js';\n\nexport function createRefreshRoute(workspaces: WorkspacesInterModuleClient) {\n return defineRoute({\n method: 'POST',\n path: '/refresh',\n description: 'Refresh the current browser session access token.',\n schema: {\n response: {\n 200: refreshResponseSchema,\n },\n },\n errorHandler: (error, _request, reply) => {\n if (error instanceof TokenInvalidError) {\n clearRefreshTokenCookie(reply);\n throw new ClientError('Refresh token is invalid or expired', 'unauthorized', {\n status: 401,\n });\n }\n if (error instanceof AuthDependencyUnavailableError) {\n throw new ClientError(\n 'Authentication dependency unavailable',\n 'auth-dependency-unavailable',\n {\n status: 503,\n },\n );\n }\n throw error;\n },\n handler: async (request, reply) => {\n const refreshToken = getRefreshTokenCookie(request);\n if (!refreshToken) {\n clearRefreshTokenCookie(reply);\n throw new ClientError('Refresh token is invalid or expired', 'unauthorized', {status: 401});\n }\n\n const result = await refreshAccessToken({refreshToken, workspaces});\n\n // Absent on a grace-window hit: keep the existing cookie rather than overwrite it.\n if (result.refreshToken) {\n setRefreshTokenCookie(reply, result.refreshToken);\n }\n return toAuthSessionDto(result);\n },\n });\n}\n"],"names":["refreshResponseSchema","ClientError","defineRoute","refreshAccessToken","AuthDependencyUnavailableError","TokenInvalidError","clearRefreshTokenCookie","getRefreshTokenCookie","setRefreshTokenCookie","toAuthSessionDto","createRefreshRoute","workspaces","method","path","description","schema","response","errorHandler","error","_request","reply","status","handler","request","refreshToken","result"],"mappings":"AAAA,SAAQA,qBAAqB,QAAO,wBAAwB;AAE5D,SAAQC,WAAW,EAAEC,WAAW,QAAO,wBAAwB;AAC/D,SAAQC,kBAAkB,QAAO,gBAAgB;AACjD,SAAQC,8BAA8B,EAAEC,iBAAiB,QAAO,kBAAkB;AAClF,SACEC,uBAAuB,EACvBC,qBAAqB,EACrBC,qBAAqB,QAChB,uCAAuC;AAC9C,SAAQC,gBAAgB,QAAO,4BAA4B;AAE3D,OAAO,SAASC,mBAAmBC,UAAuC;IACxE,OAAOT,YAAY;QACjBU,QAAQ;QACRC,MAAM;QACNC,aAAa;QACbC,QAAQ;YACNC,UAAU;gBACR,KAAKhB;YACP;QACF;QACAiB,cAAc,CAACC,OAAOC,UAAUC;YAC9B,IAAIF,iBAAiBb,mBAAmB;gBACtCC,wBAAwBc;gBACxB,MAAM,IAAInB,YAAY,uCAAuC,gBAAgB;oBAC3EoB,QAAQ;gBACV;YACF;YACA,IAAIH,iBAAiBd,gCAAgC;gBACnD,MAAM,IAAIH,YACR,yCACA,+BACA;oBACEoB,QAAQ;gBACV;YAEJ;YACA,MAAMH;QACR;QACAI,SAAS,OAAOC,SAASH;YACvB,MAAMI,eAAejB,sBAAsBgB;YAC3C,IAAI,CAACC,cAAc;gBACjBlB,wBAAwBc;gBACxB,MAAM,IAAInB,YAAY,uCAAuC,gBAAgB;oBAACoB,QAAQ;gBAAG;YAC3F;YAEA,MAAMI,SAAS,MAAMtB,mBAAmB;gBAACqB;gBAAcb;YAAU;YAEjE,mFAAmF;YACnF,IAAIc,OAAOD,YAAY,EAAE;gBACvBhB,sBAAsBY,OAAOK,OAAOD,YAAY;YAClD;YACA,OAAOf,iBAAiBgB;QAC1B;IACF;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/presentation/subscribers/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/presentation/subscribers/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,4BAA4B,EAAC,MAAM,uCAAuC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/presentation/subscribers/index.ts"],"sourcesContent":["export {
|
|
1
|
+
{"version":3,"sources":["../../../src/presentation/subscribers/index.ts"],"sourcesContent":["export {onPasswordResetSendRequested} from './on-password-reset-send-requested.js';\n"],"names":["onPasswordResetSendRequested"],"mappings":"AAAA,SAAQA,4BAA4B,QAAO,wCAAwC"}
|