@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.
Files changed (154) hide show
  1. package/.turbo/turbo-build.log +1 -1
  2. package/CHANGELOG.md +69 -0
  3. package/README.md +71 -37
  4. package/dist/config.d.ts +0 -12
  5. package/dist/config.d.ts.map +1 -1
  6. package/dist/config.js +0 -62
  7. package/dist/config.js.map +1 -1
  8. package/dist/core/auth.d.ts +21 -2
  9. package/dist/core/auth.d.ts.map +1 -1
  10. package/dist/core/auth.js +109 -77
  11. package/dist/core/auth.js.map +1 -1
  12. package/dist/core/email-owner.d.ts +12 -0
  13. package/dist/core/email-owner.d.ts.map +1 -0
  14. package/dist/core/email-owner.js +20 -0
  15. package/dist/core/email-owner.js.map +1 -0
  16. package/dist/core/job-lease-token.d.ts.map +1 -1
  17. package/dist/core/job-lease-token.js +3 -2
  18. package/dist/core/job-lease-token.js.map +1 -1
  19. package/dist/core/jwt.d.ts +2 -2
  20. package/dist/core/jwt.d.ts.map +1 -1
  21. package/dist/core/jwt.js.map +1 -1
  22. package/dist/core/rate-limit.d.ts.map +1 -1
  23. package/dist/core/rate-limit.js +2 -7
  24. package/dist/core/rate-limit.js.map +1 -1
  25. package/dist/core/runner-session-token.d.ts.map +1 -1
  26. package/dist/core/runner-session-token.js +3 -2
  27. package/dist/core/runner-session-token.js.map +1 -1
  28. package/dist/db/db.d.ts +0 -218
  29. package/dist/db/db.d.ts.map +1 -1
  30. package/dist/db/db.js +0 -2
  31. package/dist/db/db.js.map +1 -1
  32. package/dist/db/users.d.ts +3 -0
  33. package/dist/db/users.d.ts.map +1 -1
  34. package/dist/db/users.js +28 -10
  35. package/dist/db/users.js.map +1 -1
  36. package/dist/index.d.ts +5 -1
  37. package/dist/index.d.ts.map +1 -1
  38. package/dist/index.js +40 -34
  39. package/dist/index.js.map +1 -1
  40. package/dist/presentation/auth/jwt-auth.d.ts.map +1 -1
  41. package/dist/presentation/auth/jwt-auth.js +2 -2
  42. package/dist/presentation/auth/jwt-auth.js.map +1 -1
  43. package/dist/presentation/e2eRoutes/create-session.d.ts +2 -1
  44. package/dist/presentation/e2eRoutes/create-session.d.ts.map +1 -1
  45. package/dist/presentation/e2eRoutes/create-session.js +42 -39
  46. package/dist/presentation/e2eRoutes/create-session.js.map +1 -1
  47. package/dist/presentation/e2eRoutes/index.d.ts +2 -1
  48. package/dist/presentation/e2eRoutes/index.d.ts.map +1 -1
  49. package/dist/presentation/e2eRoutes/index.js +12 -10
  50. package/dist/presentation/e2eRoutes/index.js.map +1 -1
  51. package/dist/presentation/inter-module.d.ts +4 -0
  52. package/dist/presentation/inter-module.d.ts.map +1 -0
  53. package/dist/presentation/inter-module.js +16 -0
  54. package/dist/presentation/inter-module.js.map +1 -0
  55. package/dist/presentation/routes/email-verification/verify-email-confirm.d.ts +2 -1
  56. package/dist/presentation/routes/email-verification/verify-email-confirm.d.ts.map +1 -1
  57. package/dist/presentation/routes/email-verification/verify-email-confirm.js +36 -25
  58. package/dist/presentation/routes/email-verification/verify-email-confirm.js.map +1 -1
  59. package/dist/presentation/routes/email-verification/verify-email-resend.d.ts.map +1 -1
  60. package/dist/presentation/routes/email-verification/verify-email-resend.js +20 -4
  61. package/dist/presentation/routes/email-verification/verify-email-resend.js.map +1 -1
  62. package/dist/presentation/routes/index.d.ts +2 -2
  63. package/dist/presentation/routes/index.d.ts.map +1 -1
  64. package/dist/presentation/routes/index.js +11 -13
  65. package/dist/presentation/routes/index.js.map +1 -1
  66. package/dist/presentation/routes/password/password-reset-confirm.d.ts +2 -1
  67. package/dist/presentation/routes/password/password-reset-confirm.d.ts.map +1 -1
  68. package/dist/presentation/routes/password/password-reset-confirm.js +29 -26
  69. package/dist/presentation/routes/password/password-reset-confirm.js.map +1 -1
  70. package/dist/presentation/routes/registration/signup.d.ts +2 -1
  71. package/dist/presentation/routes/registration/signup.d.ts.map +1 -1
  72. package/dist/presentation/routes/registration/signup.js +86 -68
  73. package/dist/presentation/routes/registration/signup.js.map +1 -1
  74. package/dist/presentation/routes/session/login.d.ts +2 -1
  75. package/dist/presentation/routes/session/login.d.ts.map +1 -1
  76. package/dist/presentation/routes/session/login.js +40 -37
  77. package/dist/presentation/routes/session/login.js.map +1 -1
  78. package/dist/presentation/routes/session/refresh.d.ts +2 -1
  79. package/dist/presentation/routes/session/refresh.d.ts.map +1 -1
  80. package/dist/presentation/routes/session/refresh.js +42 -39
  81. package/dist/presentation/routes/session/refresh.js.map +1 -1
  82. package/dist/presentation/subscribers/index.d.ts +0 -1
  83. package/dist/presentation/subscribers/index.d.ts.map +1 -1
  84. package/dist/presentation/subscribers/index.js +0 -1
  85. package/dist/presentation/subscribers/index.js.map +1 -1
  86. package/dist/presentation/subscribers/on-password-reset-send-requested.js +1 -1
  87. package/dist/presentation/subscribers/on-password-reset-send-requested.js.map +1 -1
  88. package/dist/tsconfig.test.tsbuildinfo +1 -1
  89. package/drizzle/0000_initial.sql +1 -13
  90. package/drizzle/meta/0000_snapshot.json +0 -92
  91. package/package.json +18 -14
  92. package/src/config.ts +0 -56
  93. package/src/core/auth.test.ts +106 -187
  94. package/src/core/auth.ts +131 -87
  95. package/src/core/email-owner.test.ts +86 -0
  96. package/src/core/email-owner.ts +23 -0
  97. package/src/core/job-lease-token.test.ts +2 -1
  98. package/src/core/job-lease-token.ts +3 -2
  99. package/src/core/jwt.ts +2 -2
  100. package/src/core/rate-limit.test.ts +11 -28
  101. package/src/core/rate-limit.ts +3 -11
  102. package/src/core/runner-session-token.test.ts +2 -1
  103. package/src/core/runner-session-token.ts +3 -2
  104. package/src/db/db.ts +0 -2
  105. package/src/db/users.ts +32 -14
  106. package/src/index.test.ts +15 -11
  107. package/src/index.ts +23 -20
  108. package/src/presentation/auth/jwt-auth.test.ts +2 -1
  109. package/src/presentation/auth/jwt-auth.ts +2 -2
  110. package/src/presentation/e2eRoutes/create-session.ts +34 -30
  111. package/src/presentation/e2eRoutes/index.test.ts +9 -6
  112. package/src/presentation/e2eRoutes/index.ts +8 -5
  113. package/src/presentation/inter-module.ts +13 -0
  114. package/src/presentation/routes/email-verification/verify-email-confirm.ts +42 -24
  115. package/src/presentation/routes/email-verification/verify-email-resend.ts +18 -4
  116. package/src/presentation/routes/index.test.ts +10 -3
  117. package/src/presentation/routes/index.ts +22 -12
  118. package/src/presentation/routes/password/password-reset-confirm.ts +25 -22
  119. package/src/presentation/routes/password/password-reset-request.test.ts +1 -0
  120. package/src/presentation/routes/rate-limit.test.ts +2 -2
  121. package/src/presentation/routes/registration/signup.test.ts +39 -74
  122. package/src/presentation/routes/registration/signup.ts +89 -70
  123. package/src/presentation/routes/session/login.ts +38 -35
  124. package/src/presentation/routes/session/refresh.ts +43 -40
  125. package/src/presentation/subscribers/email-send-requested.test.ts +2 -30
  126. package/src/presentation/subscribers/index.ts +0 -1
  127. package/src/presentation/subscribers/on-password-reset-send-requested.ts +1 -1
  128. package/test/env.ts +1 -3
  129. package/test/globalSetup.ts +10 -1
  130. package/test/routes.ts +51 -84
  131. package/tsconfig.build.tsbuildinfo +1 -1
  132. package/dist/core/entities/email-verification.d.ts +0 -9
  133. package/dist/core/entities/email-verification.d.ts.map +0 -1
  134. package/dist/core/entities/email-verification.js +0 -3
  135. package/dist/core/entities/email-verification.js.map +0 -1
  136. package/dist/db/email-verifications.d.ts +0 -39
  137. package/dist/db/email-verifications.d.ts.map +0 -1
  138. package/dist/db/email-verifications.js +0 -95
  139. package/dist/db/email-verifications.js.map +0 -1
  140. package/dist/db/schema/email-verifications.d.ts +0 -114
  141. package/dist/db/schema/email-verifications.d.ts.map +0 -1
  142. package/dist/db/schema/email-verifications.js +0 -35
  143. package/dist/db/schema/email-verifications.js.map +0 -1
  144. package/dist/presentation/subscribers/on-email-verification-send-requested.d.ts +0 -3
  145. package/dist/presentation/subscribers/on-email-verification-send-requested.d.ts.map +0 -1
  146. package/dist/presentation/subscribers/on-email-verification-send-requested.js +0 -13
  147. package/dist/presentation/subscribers/on-email-verification-send-requested.js.map +0 -1
  148. package/src/core/entities/email-verification.ts +0 -8
  149. package/src/db/email-verifications.test.ts +0 -61
  150. package/src/db/email-verifications.ts +0 -160
  151. package/src/db/schema/email-verifications.ts +0 -37
  152. package/src/presentation/routes/email-verification/verify-email-confirm.test.ts +0 -66
  153. package/src/presentation/routes/email-verification/verify-email-resend.test.ts +0 -100
  154. 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 {RouteGroup} from '@shipfox/node-fastify';\nimport {config} from '#config.js';\nimport {authCookiePlugin} from '#presentation/auth/refresh-cookie.js';\nimport {verifyEmailConfirmRoute} from './email-verification/verify-email-confirm.js';\nimport {verifyEmailResendRoute} from './email-verification/verify-email-resend.js';\nimport {changePasswordRoute} from './password/change-password.js';\nimport {passwordResetConfirmRoute} from './password/password-reset-confirm.js';\nimport {passwordResetRequestRoute} from './password/password-reset-request.js';\nimport {signupRoute} from './registration/signup.js';\nimport {loginRoute} from './session/login.js';\nimport {logoutRoute} from './session/logout.js';\nimport {meRoute} from './session/me.js';\nimport {refreshRoute} from './session/refresh.js';\n\nexport function buildAuthRoutes(passwordEnabled: boolean): RouteGroup {\n const passwordRoutes = passwordEnabled\n ? [signupRoute, verifyEmailConfirmRoute, verifyEmailResendRoute, loginRoute]\n : [];\n\n return {\n prefix: '/auth',\n plugins: [authCookiePlugin],\n routes: [\n ...passwordRoutes,\n refreshRoute,\n logoutRoute,\n meRoute,\n ...(passwordEnabled\n ? [changePasswordRoute, passwordResetRequestRoute, passwordResetConfirmRoute]\n : []),\n ],\n };\n}\n\nexport const authRoutes = buildAuthRoutes(config.AUTH_PASSWORD_ENABLED);\n"],"names":["config","authCookiePlugin","verifyEmailConfirmRoute","verifyEmailResendRoute","changePasswordRoute","passwordResetConfirmRoute","passwordResetRequestRoute","signupRoute","loginRoute","logoutRoute","meRoute","refreshRoute","buildAuthRoutes","passwordEnabled","passwordRoutes","prefix","plugins","routes","authRoutes","AUTH_PASSWORD_ENABLED"],"mappings":"AACA,SAAQA,MAAM,QAAO,aAAa;AAClC,SAAQC,gBAAgB,QAAO,uCAAuC;AACtE,SAAQC,uBAAuB,QAAO,+CAA+C;AACrF,SAAQC,sBAAsB,QAAO,8CAA8C;AACnF,SAAQC,mBAAmB,QAAO,gCAAgC;AAClE,SAAQC,yBAAyB,QAAO,uCAAuC;AAC/E,SAAQC,yBAAyB,QAAO,uCAAuC;AAC/E,SAAQC,WAAW,QAAO,2BAA2B;AACrD,SAAQC,UAAU,QAAO,qBAAqB;AAC9C,SAAQC,WAAW,QAAO,sBAAsB;AAChD,SAAQC,OAAO,QAAO,kBAAkB;AACxC,SAAQC,YAAY,QAAO,uBAAuB;AAElD,OAAO,SAASC,gBAAgBC,eAAwB;IACtD,MAAMC,iBAAiBD,kBACnB;QAACN;QAAaL;QAAyBC;QAAwBK;KAAW,GAC1E,EAAE;IAEN,OAAO;QACLO,QAAQ;QACRC,SAAS;YAACf;SAAiB;QAC3BgB,QAAQ;eACHH;YACHH;YACAF;YACAC;eACIG,kBACA;gBAACT;gBAAqBE;gBAA2BD;aAA0B,GAC3E,EAAE;SACP;IACH;AACF;AAEA,OAAO,MAAMa,aAAaN,gBAAgBZ,OAAOmB,qBAAqB,EAAE"}
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
- export declare const passwordResetConfirmRoute: import("@shipfox/node-fastify").RouteDefinition;
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":"AAUA,eAAO,MAAM,yBAAyB,iDAwBpC,CAAC"}
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 const passwordResetConfirmRoute = defineRoute({
8
- method: 'POST',
9
- path: '/password-reset/confirm',
10
- description: 'Set a new password using the link sent by email.',
11
- schema: {
12
- body: passwordResetConfirmBodySchema,
13
- response: {
14
- 200: passwordResetConfirmResponseSchema
15
- }
16
- },
17
- errorHandler: (error)=>{
18
- if (error instanceof TokenInvalidError) {
19
- throw new ClientError('Reset token is invalid or expired', 'token-invalid', {
20
- status: 410
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
- throw error;
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 const passwordResetConfirmRoute = 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});\n setRefreshTokenCookie(reply, result.refreshToken);\n\n return toAuthSessionDto(result);\n },\n});\n"],"names":["passwordResetConfirmBodySchema","passwordResetConfirmResponseSchema","ClientError","defineRoute","confirmPasswordReset","TokenInvalidError","setRefreshTokenCookie","toAuthSessionDto","passwordResetConfirmRoute","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;AAC/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,MAAMC,4BAA4BL,YAAY;IACnDM,QAAQ;IACRC,MAAM;IACNC,aAAa;IACbC,QAAQ;QACNC,MAAMb;QACNc,UAAU;YACR,KAAKb;QACP;IACF;IACAc,cAAc,CAACC;QACb,IAAIA,iBAAiBX,mBAAmB;YACtC,MAAM,IAAIH,YAAY,qCAAqC,iBAAiB;gBAACe,QAAQ;YAAG;QAC1F;QACA,MAAMD;IACR;IACAE,SAAS,OAAOC,SAASC;QACvB,MAAM,EAACC,KAAK,EAAEC,YAAY,EAAC,GAAGH,QAAQN,IAAI;QAE1C,MAAMU,SAAS,MAAMnB,qBAAqB;YAACiB;YAAOG,aAAaF;QAAY;QAC3EhB,sBAAsBc,OAAOG,OAAOE,YAAY;QAEhD,OAAOlB,iBAAiBgB;IAC1B;AACF,GAAG"}
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
- export declare const signupRoute: import("@shipfox/node-fastify").RouteDefinition;
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":"AAaA,eAAO,MAAM,WAAW,iDAmEtB,CAAC"}
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 { InvitationEmailMismatchError, TokenAlreadyUsedError, TokenExpiredError, TokenInvalidError as WorkspacesTokenInvalidError } from '@shipfox/api-workspaces';
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 const signupRoute = defineRoute({
9
- method: 'POST',
10
- path: '/signup',
11
- description: 'Create a user account. Sends a verification email unless an invitation token is supplied.',
12
- schema: {
13
- body: signupBodySchema,
14
- response: {
15
- 201: signupResponseSchema
16
- }
17
- },
18
- errorHandler: (error)=>{
19
- if (error instanceof EmailTakenError) {
20
- throw new ClientError('Email already registered', 'email-taken', {
21
- status: 409
22
- });
23
- }
24
- if (error instanceof WorkspacesTokenInvalidError) {
25
- throw new ClientError('Invitation token is invalid', 'invitation-token-invalid', {
26
- status: 410
27
- });
28
- }
29
- if (error instanceof TokenAlreadyUsedError) {
30
- throw new ClientError('Invitation has already been accepted', 'invitation-token-used', {
31
- status: 410
32
- });
33
- }
34
- if (error instanceof TokenExpiredError) {
35
- throw new ClientError('Invitation has expired', 'invitation-token-expired', {
36
- status: 410
37
- });
38
- }
39
- if (error instanceof InvitationEmailMismatchError) {
40
- throw new ClientError('Signup email does not match the invitation', 'invitation-email-mismatch', {
41
- status: 403
42
- });
43
- }
44
- throw error;
45
- },
46
- handler: async (request, reply)=>{
47
- const { email, password, name, invitation_token } = request.body;
48
- if (invitation_token === undefined) {
49
- const user = await signup({
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
- const result = await signupWithInvitation({
60
- email,
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 {\n InvitationEmailMismatchError,\n TokenAlreadyUsedError,\n TokenExpiredError,\n TokenInvalidError as WorkspacesTokenInvalidError,\n} from '@shipfox/api-workspaces';\nimport {ClientError, defineRoute} from '@shipfox/node-fastify';\nimport {signup, signupWithInvitation} from '#core/auth.js';\nimport {EmailTakenError} from '#core/errors.js';\nimport {setRefreshTokenCookie} from '#presentation/auth/refresh-cookie.js';\nimport {toUserDto} from '#presentation/dto/user.js';\n\nexport const signupRoute = 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 EmailTakenError) {\n throw new ClientError('Email already registered', 'email-taken', {status: 409});\n }\n if (error instanceof WorkspacesTokenInvalidError) {\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', {status: 410});\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 user = await signup({email, password, name});\n reply.code(201);\n return {user: toUserDto(user)};\n }\n\n const result = await signupWithInvitation({\n email,\n password,\n name,\n invitationToken: invitation_token,\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"],"names":["signupBodySchema","signupResponseSchema","InvitationEmailMismatchError","TokenAlreadyUsedError","TokenExpiredError","TokenInvalidError","WorkspacesTokenInvalidError","ClientError","defineRoute","signup","signupWithInvitation","EmailTakenError","setRefreshTokenCookie","toUserDto","signupRoute","method","path","description","schema","body","response","errorHandler","error","status","handler","request","reply","email","password","name","invitation_token","undefined","user","code","result","invitationToken","refreshToken","token","membership","id","user_id","userId","workspace_id","workspaceId","acceptError","accept_error"],"mappings":"AAAA,SAAQA,gBAAgB,EAAEC,oBAAoB,QAAO,wBAAwB;AAC7E,SACEC,4BAA4B,EAC5BC,qBAAqB,EACrBC,iBAAiB,EACjBC,qBAAqBC,2BAA2B,QAC3C,0BAA0B;AACjC,SAAQC,WAAW,EAAEC,WAAW,QAAO,wBAAwB;AAC/D,SAAQC,MAAM,EAAEC,oBAAoB,QAAO,gBAAgB;AAC3D,SAAQC,eAAe,QAAO,kBAAkB;AAChD,SAAQC,qBAAqB,QAAO,uCAAuC;AAC3E,SAAQC,SAAS,QAAO,4BAA4B;AAEpD,OAAO,MAAMC,cAAcN,YAAY;IACrCO,QAAQ;IACRC,MAAM;IACNC,aACE;IACFC,QAAQ;QACNC,MAAMnB;QACNoB,UAAU;YACR,KAAKnB;QACP;IACF;IACAoB,cAAc,CAACC;QACb,IAAIA,iBAAiBX,iBAAiB;YACpC,MAAM,IAAIJ,YAAY,4BAA4B,eAAe;gBAACgB,QAAQ;YAAG;QAC/E;QACA,IAAID,iBAAiBhB,6BAA6B;YAChD,MAAM,IAAIC,YAAY,+BAA+B,4BAA4B;gBAC/EgB,QAAQ;YACV;QACF;QACA,IAAID,iBAAiBnB,uBAAuB;YAC1C,MAAM,IAAII,YAAY,wCAAwC,yBAAyB;gBACrFgB,QAAQ;YACV;QACF;QACA,IAAID,iBAAiBlB,mBAAmB;YACtC,MAAM,IAAIG,YAAY,0BAA0B,4BAA4B;gBAACgB,QAAQ;YAAG;QAC1F;QACA,IAAID,iBAAiBpB,8BAA8B;YACjD,MAAM,IAAIK,YACR,8CACA,6BACA;gBAACgB,QAAQ;YAAG;QAEhB;QACA,MAAMD;IACR;IACAE,SAAS,OAAOC,SAASC;QACvB,MAAM,EAACC,KAAK,EAAEC,QAAQ,EAAEC,IAAI,EAAEC,gBAAgB,EAAC,GAAGL,QAAQN,IAAI;QAE9D,IAAIW,qBAAqBC,WAAW;YAClC,MAAMC,OAAO,MAAMvB,OAAO;gBAACkB;gBAAOC;gBAAUC;YAAI;YAChDH,MAAMO,IAAI,CAAC;YACX,OAAO;gBAACD,MAAMnB,UAAUmB;YAAK;QAC/B;QAEA,MAAME,SAAS,MAAMxB,qBAAqB;YACxCiB;YACAC;YACAC;YACAM,iBAAiBL;QACnB;QACAlB,sBAAsBc,OAAOQ,OAAOE,YAAY;QAChDV,MAAMO,IAAI,CAAC;QACX,OAAO;YACLD,MAAMnB,UAAUqB,OAAOF,IAAI;YAC3BK,OAAOH,OAAOG,KAAK;YACnBC,YAAYJ,OAAOI,UAAU,GACzB;gBACEC,IAAIL,OAAOI,UAAU,CAACC,EAAE;gBACxBC,SAASN,OAAOI,UAAU,CAACG,MAAM;gBACjCC,cAAcR,OAAOI,UAAU,CAACK,WAAW;YAC7C,IACA;YACJ,GAAIT,OAAOU,WAAW,GAAG;gBAACC,cAAcX,OAAOU,WAAW;YAAA,IAAI,CAAC,CAAC;QAClE;IACF;AACF,GAAG"}
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":"AAAA,SAAQA,gBAAgB,EAAEC,oBAAoB,QAAO,wBAAwB;AAC7E,SAAQC,mBAAmB,QAAO,gCAAgC;AAElE,SAAQC,WAAW,EAAEC,WAAW,QAAO,wBAAwB;AAC/D,SAAQC,MAAM,EAAEC,oBAAoB,QAAO,gBAAgB;AAC3D,SACEC,eAAe,EACfC,4BAA4B,EAC5BC,qBAAqB,EACrBC,iBAAiB,EACjBC,iBAAiB,QACZ,kBAAkB;AACzB,SAAQC,qBAAqB,QAAO,uCAAuC;AAC3E,SAAQC,SAAS,QAAO,4BAA4B;AAEpD,OAAO,SAASC,kBAAkBC,UAAuC;IACvE,OAAOX,YAAY;QACjBY,QAAQ;QACRC,MAAM;QACNC,aACE;QACFC,QAAQ;YACNC,MAAMpB;YACNqB,UAAU;gBACR,KAAKpB;YACP;QACF;QACAqB,cAAc,CAACC;YACb,IAAIA,iBAAiBrB,qBAAqB;gBACxC,MAAM,IAAIC,YAAYoB,MAAMC,OAAO,EAAE,CAAC,gBAAgB,EAAED,MAAME,IAAI,EAAE,EAAE;oBACpEC,QAAQH,MAAME,IAAI,KAAK,YAAY,MAAM;oBACzC,GAAIF,MAAMI,OAAO,GAAG;wBAACC,SAAS;4BAACC,UAAUN,MAAMI,OAAO,CAACG,WAAW;wBAAE;oBAAC,IAAI,CAAC,CAAC;gBAC7E;YACF;YACA,IAAIP,iBAAiBhB,iBAAiB;gBACpC,MAAM,IAAIJ,YAAY,4BAA4B,eAAe;oBAACuB,QAAQ;gBAAG;YAC/E;YACA,IAAIH,iBAAiBZ,mBAAmB;gBACtC,MAAM,IAAIR,YAAY,+BAA+B,4BAA4B;oBAC/EuB,QAAQ;gBACV;YACF;YACA,IAAIH,iBAAiBd,uBAAuB;gBAC1C,MAAM,IAAIN,YAAY,wCAAwC,yBAAyB;oBACrFuB,QAAQ;gBACV;YACF;YACA,IAAIH,iBAAiBb,mBAAmB;gBACtC,MAAM,IAAIP,YAAY,0BAA0B,4BAA4B;oBAC1EuB,QAAQ;gBACV;YACF;YACA,IAAIH,iBAAiBf,8BAA8B;gBACjD,MAAM,IAAIL,YACR,8CACA,6BACA;oBAACuB,QAAQ;gBAAG;YAEhB;YACA,MAAMH;QACR;QACAQ,SAAS,OAAOC,SAASC;YACvB,MAAM,EAACC,KAAK,EAAEC,QAAQ,EAAEC,IAAI,EAAEC,gBAAgB,EAAC,GAAGL,QAAQZ,IAAI;YAE9D,IAAIiB,qBAAqBC,WAAW;gBAClC,MAAMC,SAAS,MAAMlC,OAAO;oBAAC6B;oBAAOC;oBAAUC;oBAAMI,UAAUR,QAAQS,EAAE;gBAAA;gBACxER,MAAMR,IAAI,CAAC;gBACX,OAAO;oBACLiB,MAAM7B,UAAU0B;oBAChBI,iBAAiB;wBACfC,IAAIL,OAAOM,cAAc,CAACD,EAAE;wBAC5BE,0BAA0BP,OAAOM,cAAc,CAACE,qBAAqB,CAACjB,WAAW;oBACnF;gBACF;YACF;YAEA,MAAMS,SAAS,MAAMjC,qBAAqB;gBACxC4B;gBACAC;gBACAC;gBACAY,iBAAiBX;gBACjBtB;YACF;YACAH,sBAAsBqB,OAAOM,OAAOU,YAAY;YAChDhB,MAAMR,IAAI,CAAC;YACX,OAAO;gBACLiB,MAAM7B,UAAU0B,OAAOG,IAAI;gBAC3BQ,OAAOX,OAAOW,KAAK;gBACnBC,YAAYZ,OAAOY,UAAU,GACzB;oBACEP,IAAIL,OAAOY,UAAU,CAACP,EAAE;oBACxBQ,SAASb,OAAOY,UAAU,CAACE,MAAM;oBACjCC,cAAcf,OAAOY,UAAU,CAACI,WAAW;gBAC7C,IACA;gBACJ,GAAIhB,OAAOiB,WAAW,GAAG;oBAACC,cAAclB,OAAOiB,WAAW;gBAAA,IAAI,CAAC,CAAC;YAClE;QACF;IACF;AACF"}
@@ -1,2 +1,3 @@
1
- export declare const loginRoute: import("@shipfox/node-fastify").RouteDefinition;
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":"AAYA,eAAO,MAAM,UAAU,iDAqCrB,CAAC"}
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 const loginRoute = defineRoute({
9
- method: 'POST',
10
- path: '/login',
11
- description: 'Sign in with an email address and password.',
12
- schema: {
13
- body: loginBodySchema,
14
- response: {
15
- 200: loginResponseSchema
16
- }
17
- },
18
- preHandler: createAuthRateLimitPreHandler('login'),
19
- errorHandler: (error)=>{
20
- if (error instanceof InvalidCredentialsError) {
21
- throw new ClientError('Invalid credentials', 'invalid-credentials', {
22
- status: 401
23
- });
24
- }
25
- if (error instanceof EmailNotVerifiedError) {
26
- throw new ClientError('Email not verified', 'email-not-verified', {
27
- status: 403
28
- });
29
- }
30
- if (error instanceof AuthDependencyUnavailableError) {
31
- throw new ClientError('Authentication dependency unavailable', 'auth-dependency-unavailable', {
32
- status: 503
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
- throw error;
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 const loginRoute = 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});\n setRefreshTokenCookie(reply, result.refreshToken);\n\n return toAuthSessionDto(result);\n },\n});\n"],"names":["loginBodySchema","loginResponseSchema","ClientError","defineRoute","login","AuthDependencyUnavailableError","EmailNotVerifiedError","InvalidCredentialsError","setRefreshTokenCookie","toAuthSessionDto","createAuthRateLimitPreHandler","loginRoute","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;AAC3E,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,MAAMC,aAAaR,YAAY;IACpCS,QAAQ;IACRC,MAAM;IACNC,aAAa;IACbC,QAAQ;QACNC,MAAMhB;QACNiB,UAAU;YACR,KAAKhB;QACP;IACF;IACAiB,YAAYR,8BAA8B;IAC1CS,cAAc,CAACC;QACb,IAAIA,iBAAiBb,yBAAyB;YAC5C,MAAM,IAAIL,YAAY,uBAAuB,uBAAuB;gBAACmB,QAAQ;YAAG;QAClF;QACA,IAAID,iBAAiBd,uBAAuB;YAC1C,MAAM,IAAIJ,YAAY,sBAAsB,sBAAsB;gBAACmB,QAAQ;YAAG;QAChF;QACA,IAAID,iBAAiBf,gCAAgC;YACnD,MAAM,IAAIH,YACR,yCACA,+BACA;gBACEmB,QAAQ;YACV;QAEJ;QACA,MAAMD;IACR;IACAE,SAAS,OAAOC,SAASC;QACvB,MAAM,EAACC,KAAK,EAAEC,QAAQ,EAAC,GAAGH,QAAQP,IAAI;QAEtC,MAAMW,SAAS,MAAMvB,MAAM;YAACqB;YAAOC;QAAQ;QAC3ClB,sBAAsBgB,OAAOG,OAAOC,YAAY;QAEhD,OAAOnB,iBAAiBkB;IAC1B;AACF,GAAG"}
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
- export declare const refreshRoute: import("@shipfox/node-fastify").RouteDefinition;
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":"AAWA,eAAO,MAAM,YAAY,iDA0CvB,CAAC"}
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 const refreshRoute = defineRoute({
8
- method: 'POST',
9
- path: '/refresh',
10
- description: 'Refresh the current browser session access token.',
11
- schema: {
12
- response: {
13
- 200: refreshResponseSchema
14
- }
15
- },
16
- errorHandler: (error, _request, reply)=>{
17
- if (error instanceof TokenInvalidError) {
18
- clearRefreshTokenCookie(reply);
19
- throw new ClientError('Refresh token is invalid or expired', 'unauthorized', {
20
- status: 401
21
- });
22
- }
23
- if (error instanceof AuthDependencyUnavailableError) {
24
- throw new ClientError('Authentication dependency unavailable', 'auth-dependency-unavailable', {
25
- status: 503
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
- throw error;
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 const refreshRoute = 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});\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"],"names":["refreshResponseSchema","ClientError","defineRoute","refreshAccessToken","AuthDependencyUnavailableError","TokenInvalidError","clearRefreshTokenCookie","getRefreshTokenCookie","setRefreshTokenCookie","toAuthSessionDto","refreshRoute","method","path","description","schema","response","errorHandler","error","_request","reply","status","handler","request","refreshToken","result"],"mappings":"AAAA,SAAQA,qBAAqB,QAAO,wBAAwB;AAC5D,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,MAAMC,eAAeR,YAAY;IACtCS,QAAQ;IACRC,MAAM;IACNC,aAAa;IACbC,QAAQ;QACNC,UAAU;YACR,KAAKf;QACP;IACF;IACAgB,cAAc,CAACC,OAAOC,UAAUC;QAC9B,IAAIF,iBAAiBZ,mBAAmB;YACtCC,wBAAwBa;YACxB,MAAM,IAAIlB,YAAY,uCAAuC,gBAAgB;gBAC3EmB,QAAQ;YACV;QACF;QACA,IAAIH,iBAAiBb,gCAAgC;YACnD,MAAM,IAAIH,YACR,yCACA,+BACA;gBACEmB,QAAQ;YACV;QAEJ;QACA,MAAMH;IACR;IACAI,SAAS,OAAOC,SAASH;QACvB,MAAMI,eAAehB,sBAAsBe;QAC3C,IAAI,CAACC,cAAc;YACjBjB,wBAAwBa;YACxB,MAAM,IAAIlB,YAAY,uCAAuC,gBAAgB;gBAACmB,QAAQ;YAAG;QAC3F;QAEA,MAAMI,SAAS,MAAMrB,mBAAmB;YAACoB;QAAY;QAErD,mFAAmF;QACnF,IAAIC,OAAOD,YAAY,EAAE;YACvBf,sBAAsBW,OAAOK,OAAOD,YAAY;QAClD;QACA,OAAOd,iBAAiBe;IAC1B;AACF,GAAG"}
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,3 +1,2 @@
1
- export { onEmailVerificationSendRequested } from './on-email-verification-send-requested.js';
2
1
  export { onPasswordResetSendRequested } from './on-password-reset-send-requested.js';
3
2
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/presentation/subscribers/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,gCAAgC,EAAC,MAAM,2CAA2C,CAAC;AAC3F,OAAO,EAAC,4BAA4B,EAAC,MAAM,uCAAuC,CAAC"}
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,4 +1,3 @@
1
- export { onEmailVerificationSendRequested } from './on-email-verification-send-requested.js';
2
1
  export { onPasswordResetSendRequested } from './on-password-reset-send-requested.js';
3
2
 
4
3
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/presentation/subscribers/index.ts"],"sourcesContent":["export {onEmailVerificationSendRequested} from './on-email-verification-send-requested.js';\nexport {onPasswordResetSendRequested} from './on-password-reset-send-requested.js';\n"],"names":["onEmailVerificationSendRequested","onPasswordResetSendRequested"],"mappings":"AAAA,SAAQA,gCAAgC,QAAO,4CAA4C;AAC3F,SAAQC,4BAA4B,QAAO,wCAAwC"}
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"}