@logto/remix 1.1.0 → 1.1.2

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 (92) hide show
  1. package/lib/framework/get-cookie-header-from-request.d.ts +1 -0
  2. package/lib/framework/get-cookie-header-from-request.js +5 -0
  3. package/lib/framework/get-cookie-header-from-request.mjs +3 -0
  4. package/lib/framework/mocks.d.ts +22 -0
  5. package/lib/index.d.ts +3 -7
  6. package/lib/index.js +17 -480
  7. package/lib/index.mjs +22 -0
  8. package/lib/infrastructure/logto/create-client.d.ts +6 -0
  9. package/lib/infrastructure/logto/create-client.js +17 -0
  10. package/lib/infrastructure/logto/create-client.mjs +11 -0
  11. package/lib/infrastructure/logto/create-client.spec.d.ts +1 -0
  12. package/lib/infrastructure/logto/create-storage.d.ts +14 -0
  13. package/lib/infrastructure/logto/create-storage.js +30 -0
  14. package/lib/infrastructure/logto/create-storage.mjs +28 -0
  15. package/lib/infrastructure/logto/create-storage.spec.d.ts +1 -0
  16. package/lib/infrastructure/logto/get-context.d.ts +11 -0
  17. package/lib/infrastructure/logto/get-context.js +12 -0
  18. package/lib/infrastructure/logto/get-context.mjs +10 -0
  19. package/lib/infrastructure/logto/handle-sign-in-callback.d.ts +14 -0
  20. package/lib/infrastructure/logto/handle-sign-in-callback.js +12 -0
  21. package/lib/infrastructure/logto/handle-sign-in-callback.mjs +10 -0
  22. package/lib/infrastructure/logto/handle-sign-in.d.ts +15 -0
  23. package/lib/infrastructure/logto/handle-sign-in.js +30 -0
  24. package/lib/infrastructure/logto/handle-sign-in.mjs +28 -0
  25. package/lib/infrastructure/logto/handle-sign-out.d.ts +11 -0
  26. package/lib/infrastructure/logto/handle-sign-out.js +26 -0
  27. package/lib/infrastructure/logto/handle-sign-out.mjs +24 -0
  28. package/lib/infrastructure/logto/index.d.ts +26 -0
  29. package/lib/infrastructure/logto/index.js +21 -0
  30. package/lib/infrastructure/logto/index.mjs +19 -0
  31. package/lib/useCases/getContext/GetContextController.d.ts +13 -0
  32. package/lib/useCases/getContext/GetContextController.js +21 -0
  33. package/lib/useCases/getContext/GetContextController.mjs +19 -0
  34. package/lib/useCases/getContext/GetContextController.spec.d.ts +1 -0
  35. package/lib/useCases/getContext/GetContextUseCase.d.ts +15 -0
  36. package/lib/useCases/getContext/GetContextUseCase.js +13 -0
  37. package/lib/useCases/getContext/GetContextUseCase.mjs +11 -0
  38. package/lib/useCases/getContext/GetContextUseCase.spec.d.ts +1 -0
  39. package/lib/useCases/getContext/index.d.ts +9 -0
  40. package/lib/useCases/getContext/index.js +19 -0
  41. package/lib/useCases/getContext/index.mjs +17 -0
  42. package/lib/useCases/handleAuthRoutes/HandleAuthRoutesError.d.ts +9 -0
  43. package/lib/useCases/handleAuthRoutes/HandleAuthRoutesError.js +21 -0
  44. package/lib/useCases/handleAuthRoutes/HandleAuthRoutesError.mjs +19 -0
  45. package/lib/useCases/handleAuthRoutes/index.d.ts +15 -0
  46. package/lib/useCases/handleAuthRoutes/index.js +44 -0
  47. package/lib/useCases/handleAuthRoutes/index.mjs +42 -0
  48. package/lib/useCases/handleSignIn/HandleSignInController.d.ts +15 -0
  49. package/lib/useCases/handleSignIn/HandleSignInController.js +31 -0
  50. package/lib/useCases/handleSignIn/HandleSignInController.mjs +29 -0
  51. package/lib/useCases/handleSignIn/HandleSignInController.spec.d.ts +1 -0
  52. package/lib/useCases/handleSignIn/HandleSignInUseCase.d.ts +16 -0
  53. package/lib/useCases/handleSignIn/HandleSignInUseCase.js +17 -0
  54. package/lib/useCases/handleSignIn/HandleSignInUseCase.mjs +15 -0
  55. package/lib/useCases/handleSignIn/HandleSignInUseCase.spec.d.ts +1 -0
  56. package/lib/useCases/handleSignIn/index.d.ts +11 -0
  57. package/lib/useCases/handleSignIn/index.js +19 -0
  58. package/lib/useCases/handleSignIn/index.mjs +17 -0
  59. package/lib/useCases/handleSignInCallback/HandleSignInCallbackController.d.ts +15 -0
  60. package/lib/useCases/handleSignInCallback/HandleSignInCallbackController.js +42 -0
  61. package/lib/useCases/handleSignInCallback/HandleSignInCallbackController.mjs +40 -0
  62. package/lib/useCases/handleSignInCallback/HandleSignInCallbackController.spec.d.ts +1 -0
  63. package/lib/useCases/handleSignInCallback/HandleSignInCallbackError.d.ts +8 -0
  64. package/lib/useCases/handleSignInCallback/HandleSignInCallbackError.js +17 -0
  65. package/lib/useCases/handleSignInCallback/HandleSignInCallbackError.mjs +15 -0
  66. package/lib/useCases/handleSignInCallback/HandleSignInCallbackUseCase.d.ts +15 -0
  67. package/lib/useCases/handleSignInCallback/HandleSignInCallbackUseCase.js +16 -0
  68. package/lib/useCases/handleSignInCallback/HandleSignInCallbackUseCase.mjs +14 -0
  69. package/lib/useCases/handleSignInCallback/HandleSignInCallbackUseCase.spec.d.ts +1 -0
  70. package/lib/useCases/handleSignInCallback/index.d.ts +11 -0
  71. package/lib/useCases/handleSignInCallback/index.js +19 -0
  72. package/lib/useCases/handleSignInCallback/index.mjs +17 -0
  73. package/lib/useCases/handleSignOut/HandleSignOutController.d.ts +15 -0
  74. package/lib/useCases/handleSignOut/HandleSignOutController.js +34 -0
  75. package/lib/useCases/handleSignOut/HandleSignOutController.mjs +32 -0
  76. package/lib/useCases/handleSignOut/HandleSignOutController.spec.d.ts +1 -0
  77. package/lib/useCases/handleSignOut/HandleSignOutError.d.ts +8 -0
  78. package/lib/useCases/handleSignOut/HandleSignOutError.js +17 -0
  79. package/lib/useCases/handleSignOut/HandleSignOutError.mjs +15 -0
  80. package/lib/useCases/handleSignOut/HandleSignOutUseCase.d.ts +16 -0
  81. package/lib/useCases/handleSignOut/HandleSignOutUseCase.js +17 -0
  82. package/lib/useCases/handleSignOut/HandleSignOutUseCase.mjs +15 -0
  83. package/lib/useCases/handleSignOut/HandleSignOutUseCase.spec.d.ts +1 -0
  84. package/lib/useCases/handleSignOut/index.d.ts +11 -0
  85. package/lib/useCases/handleSignOut/index.js +19 -0
  86. package/lib/useCases/handleSignOut/index.mjs +17 -0
  87. package/package.json +13 -17
  88. package/lib/index.d.ts.map +0 -1
  89. package/lib/index.js.map +0 -1
  90. package/lib/module.d.mts +0 -29
  91. package/lib/module.mjs +0 -480
  92. package/lib/module.mjs.map +0 -1
@@ -0,0 +1,28 @@
1
+ class LogtoStorage {
2
+ static { this.fromSession = (session) => {
3
+ return new LogtoStorage({ session });
4
+ }; }
5
+ constructor(properties) {
6
+ this.properties = properties;
7
+ this.session = this.properties.session;
8
+ this.setItem = async (key, value) => {
9
+ this.session.set(key, value);
10
+ };
11
+ this.getItem = async (key) => {
12
+ const itemExists = this.session.has(key);
13
+ if (!itemExists) {
14
+ return null;
15
+ }
16
+ return String(this.session.get(key));
17
+ };
18
+ this.removeItem = async (key) => {
19
+ this.session.unset(key);
20
+ };
21
+ this.save = async () => {
22
+ // Not required as the persistence happens in the integration layer
23
+ };
24
+ }
25
+ }
26
+ const createStorage = (session) => LogtoStorage.fromSession(session);
27
+
28
+ export { createStorage };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,11 @@
1
+ import type { GetContextParameters, LogtoContext } from '@logto/node';
2
+ import type { CreateLogtoClient } from './create-client';
3
+ import type { LogtoStorage } from './create-storage';
4
+ type GetContextResponse = {
5
+ readonly context: LogtoContext;
6
+ };
7
+ export declare const makeGetContext: (deps: {
8
+ storage: LogtoStorage;
9
+ createClient: CreateLogtoClient;
10
+ }) => (request: GetContextParameters) => Promise<GetContextResponse>;
11
+ export {};
@@ -0,0 +1,12 @@
1
+ 'use strict';
2
+
3
+ const makeGetContext = (deps) => async (request) => {
4
+ const { storage, createClient } = deps;
5
+ const client = createClient();
6
+ const context = await client.getContext(request);
7
+ return {
8
+ context,
9
+ };
10
+ };
11
+
12
+ exports.makeGetContext = makeGetContext;
@@ -0,0 +1,10 @@
1
+ const makeGetContext = (deps) => async (request) => {
2
+ const { storage, createClient } = deps;
3
+ const client = createClient();
4
+ const context = await client.getContext(request);
5
+ return {
6
+ context,
7
+ };
8
+ };
9
+
10
+ export { makeGetContext };
@@ -0,0 +1,14 @@
1
+ import type { Session } from '@remix-run/node';
2
+ import type { CreateLogtoClient } from './create-client';
3
+ import type { LogtoStorage } from './create-storage';
4
+ type HandleSignInCallbackRequest = {
5
+ callbackUri: string;
6
+ };
7
+ type HandleSignInCallbackResponse = {
8
+ readonly session: Session;
9
+ };
10
+ export declare const makeHandleSignInCallback: (deps: {
11
+ storage: LogtoStorage;
12
+ createClient: CreateLogtoClient;
13
+ }) => (request: HandleSignInCallbackRequest) => Promise<HandleSignInCallbackResponse>;
14
+ export {};
@@ -0,0 +1,12 @@
1
+ 'use strict';
2
+
3
+ const makeHandleSignInCallback = (deps) => async (request) => {
4
+ const { storage, createClient } = deps;
5
+ const client = createClient();
6
+ await client.handleSignInCallback(request.callbackUri);
7
+ return {
8
+ session: storage.session,
9
+ };
10
+ };
11
+
12
+ exports.makeHandleSignInCallback = makeHandleSignInCallback;
@@ -0,0 +1,10 @@
1
+ const makeHandleSignInCallback = (deps) => async (request) => {
2
+ const { storage, createClient } = deps;
3
+ const client = createClient();
4
+ await client.handleSignInCallback(request.callbackUri);
5
+ return {
6
+ session: storage.session,
7
+ };
8
+ };
9
+
10
+ export { makeHandleSignInCallback };
@@ -0,0 +1,15 @@
1
+ import type { Session } from '@remix-run/node';
2
+ import type { CreateLogtoClient } from './create-client';
3
+ import type { LogtoStorage } from './create-storage';
4
+ type HandleSignInRequest = {
5
+ readonly redirectUri: string;
6
+ };
7
+ type HandleSignInResponse = {
8
+ readonly session: Session;
9
+ readonly navigateToUrl: string;
10
+ };
11
+ export declare const makeHandleSignIn: (deps: {
12
+ storage: LogtoStorage;
13
+ createClient: CreateLogtoClient;
14
+ }) => (request: HandleSignInRequest) => Promise<HandleSignInResponse>;
15
+ export {};
@@ -0,0 +1,30 @@
1
+ 'use strict';
2
+
3
+ class HandleSignInCommand {
4
+ static { this.fromDependencies = (dependencies) => new HandleSignInCommand({ createClient: dependencies.createClient }); }
5
+ constructor(properties) {
6
+ this.properties = properties;
7
+ this.navigateToUrl = '/api/sign-in';
8
+ }
9
+ async execute(request) {
10
+ const { createClient } = this.properties;
11
+ const client = createClient((url) => {
12
+ this.navigateToUrl = url;
13
+ });
14
+ await client.signIn(request.redirectUri);
15
+ return {
16
+ navigateToUrl: this.navigateToUrl,
17
+ };
18
+ }
19
+ }
20
+ const makeHandleSignIn = (deps) => async (request) => {
21
+ const { storage, createClient } = deps;
22
+ const command = HandleSignInCommand.fromDependencies({ createClient });
23
+ const { navigateToUrl } = await command.execute(request);
24
+ return {
25
+ session: storage.session,
26
+ navigateToUrl,
27
+ };
28
+ };
29
+
30
+ exports.makeHandleSignIn = makeHandleSignIn;
@@ -0,0 +1,28 @@
1
+ class HandleSignInCommand {
2
+ static { this.fromDependencies = (dependencies) => new HandleSignInCommand({ createClient: dependencies.createClient }); }
3
+ constructor(properties) {
4
+ this.properties = properties;
5
+ this.navigateToUrl = '/api/sign-in';
6
+ }
7
+ async execute(request) {
8
+ const { createClient } = this.properties;
9
+ const client = createClient((url) => {
10
+ this.navigateToUrl = url;
11
+ });
12
+ await client.signIn(request.redirectUri);
13
+ return {
14
+ navigateToUrl: this.navigateToUrl,
15
+ };
16
+ }
17
+ }
18
+ const makeHandleSignIn = (deps) => async (request) => {
19
+ const { storage, createClient } = deps;
20
+ const command = HandleSignInCommand.fromDependencies({ createClient });
21
+ const { navigateToUrl } = await command.execute(request);
22
+ return {
23
+ session: storage.session,
24
+ navigateToUrl,
25
+ };
26
+ };
27
+
28
+ export { makeHandleSignIn };
@@ -0,0 +1,11 @@
1
+ import type { CreateLogtoClient } from './create-client';
2
+ type HandleSignOutRequest = {
3
+ readonly redirectUri: string;
4
+ };
5
+ type HandleSignOutResponse = {
6
+ readonly navigateToUrl: string;
7
+ };
8
+ export declare const makeHandleSignOut: (deps: {
9
+ createClient: CreateLogtoClient;
10
+ }) => (request: HandleSignOutRequest) => Promise<HandleSignOutResponse>;
11
+ export {};
@@ -0,0 +1,26 @@
1
+ 'use strict';
2
+
3
+ class HandleSignOutCommand {
4
+ static { this.fromDependencies = (dependencies) => new HandleSignOutCommand({ createClient: dependencies.createClient }); }
5
+ constructor(properties) {
6
+ this.properties = properties;
7
+ this.navigateToUrl = '/api/sign-in';
8
+ }
9
+ async execute(request) {
10
+ const { createClient } = this.properties;
11
+ const client = createClient((url) => {
12
+ this.navigateToUrl = url;
13
+ });
14
+ await client.signOut(request.redirectUri);
15
+ return {
16
+ navigateToUrl: this.navigateToUrl,
17
+ };
18
+ }
19
+ }
20
+ const makeHandleSignOut = (deps) => async (request) => {
21
+ const { createClient } = deps;
22
+ const command = HandleSignOutCommand.fromDependencies({ createClient });
23
+ return command.execute(request);
24
+ };
25
+
26
+ exports.makeHandleSignOut = makeHandleSignOut;
@@ -0,0 +1,24 @@
1
+ class HandleSignOutCommand {
2
+ static { this.fromDependencies = (dependencies) => new HandleSignOutCommand({ createClient: dependencies.createClient }); }
3
+ constructor(properties) {
4
+ this.properties = properties;
5
+ this.navigateToUrl = '/api/sign-in';
6
+ }
7
+ async execute(request) {
8
+ const { createClient } = this.properties;
9
+ const client = createClient((url) => {
10
+ this.navigateToUrl = url;
11
+ });
12
+ await client.signOut(request.redirectUri);
13
+ return {
14
+ navigateToUrl: this.navigateToUrl,
15
+ };
16
+ }
17
+ }
18
+ const makeHandleSignOut = (deps) => async (request) => {
19
+ const { createClient } = deps;
20
+ const command = HandleSignOutCommand.fromDependencies({ createClient });
21
+ return command.execute(request);
22
+ };
23
+
24
+ export { makeHandleSignOut };
@@ -0,0 +1,26 @@
1
+ import type { LogtoConfig } from '@logto/node';
2
+ import type { Session } from '@remix-run/node';
3
+ type MakeLogtoAdapterConfiguration = LogtoConfig;
4
+ export declare const makeLogtoAdapter: (config: MakeLogtoAdapterConfiguration) => (session: Session) => {
5
+ handleSignIn: (request: {
6
+ readonly redirectUri: string;
7
+ }) => Promise<{
8
+ readonly session: Session;
9
+ readonly navigateToUrl: string;
10
+ }>;
11
+ handleSignInCallback: (request: {
12
+ callbackUri: string;
13
+ }) => Promise<{
14
+ readonly session: Session;
15
+ }>;
16
+ handleSignOut: (request: {
17
+ readonly redirectUri: string;
18
+ }) => Promise<{
19
+ readonly navigateToUrl: string;
20
+ }>;
21
+ getContext: (request: import("@logto/node").GetContextParameters) => Promise<{
22
+ readonly context: import("@logto/node").LogtoContext;
23
+ }>;
24
+ };
25
+ export type CreateLogtoAdapter = ReturnType<typeof makeLogtoAdapter>;
26
+ export { type LogtoContext } from '@logto/node';
@@ -0,0 +1,21 @@
1
+ 'use strict';
2
+
3
+ var createClient = require('./create-client.js');
4
+ var createStorage = require('./create-storage.js');
5
+ var getContext = require('./get-context.js');
6
+ var handleSignIn = require('./handle-sign-in.js');
7
+ var handleSignInCallback = require('./handle-sign-in-callback.js');
8
+ var handleSignOut = require('./handle-sign-out.js');
9
+
10
+ const makeLogtoAdapter = (config) => (session) => {
11
+ const storage = createStorage.createStorage(session);
12
+ const createClient$1 = createClient.makeLogtoClient(config, storage);
13
+ return {
14
+ handleSignIn: handleSignIn.makeHandleSignIn({ storage, createClient: createClient$1 }),
15
+ handleSignInCallback: handleSignInCallback.makeHandleSignInCallback({ storage, createClient: createClient$1 }),
16
+ handleSignOut: handleSignOut.makeHandleSignOut({ createClient: createClient$1 }),
17
+ getContext: getContext.makeGetContext({ storage, createClient: createClient$1 }),
18
+ };
19
+ };
20
+
21
+ exports.makeLogtoAdapter = makeLogtoAdapter;
@@ -0,0 +1,19 @@
1
+ import { makeLogtoClient } from './create-client.mjs';
2
+ import { createStorage } from './create-storage.mjs';
3
+ import { makeGetContext } from './get-context.mjs';
4
+ import { makeHandleSignIn } from './handle-sign-in.mjs';
5
+ import { makeHandleSignInCallback } from './handle-sign-in-callback.mjs';
6
+ import { makeHandleSignOut } from './handle-sign-out.mjs';
7
+
8
+ const makeLogtoAdapter = (config) => (session) => {
9
+ const storage = createStorage(session);
10
+ const createClient = makeLogtoClient(config, storage);
11
+ return {
12
+ handleSignIn: makeHandleSignIn({ storage, createClient }),
13
+ handleSignInCallback: makeHandleSignInCallback({ storage, createClient }),
14
+ handleSignOut: makeHandleSignOut({ createClient }),
15
+ getContext: makeGetContext({ storage, createClient }),
16
+ };
17
+ };
18
+
19
+ export { makeLogtoAdapter };
@@ -0,0 +1,13 @@
1
+ import type { GetContextParameters, LogtoContext } from '@logto/node';
2
+ import type { GetContextUseCase } from './GetContextUseCase';
3
+ type GetContextControllerDto = GetContextParameters & {
4
+ readonly useCase: GetContextUseCase;
5
+ };
6
+ export declare class GetContextController {
7
+ private readonly properties;
8
+ static readonly fromDto: (dto: GetContextControllerDto) => GetContextController;
9
+ private readonly useCase;
10
+ private constructor();
11
+ readonly execute: (request: Request) => Promise<LogtoContext>;
12
+ }
13
+ export {};
@@ -0,0 +1,21 @@
1
+ 'use strict';
2
+
3
+ var getCookieHeaderFromRequest = require('../../framework/get-cookie-header-from-request.js');
4
+
5
+ class GetContextController {
6
+ static { this.fromDto = (dto) => new GetContextController(dto); }
7
+ constructor(properties) {
8
+ this.properties = properties;
9
+ this.useCase = this.properties.useCase;
10
+ this.execute = async (request) => {
11
+ const cookieHeader = getCookieHeaderFromRequest.getCookieHeaderFromRequest(request);
12
+ const result = await this.useCase({
13
+ cookieHeader: cookieHeader ?? undefined,
14
+ ...this.properties,
15
+ });
16
+ return result.context;
17
+ };
18
+ }
19
+ }
20
+
21
+ exports.GetContextController = GetContextController;
@@ -0,0 +1,19 @@
1
+ import { getCookieHeaderFromRequest } from '../../framework/get-cookie-header-from-request.mjs';
2
+
3
+ class GetContextController {
4
+ static { this.fromDto = (dto) => new GetContextController(dto); }
5
+ constructor(properties) {
6
+ this.properties = properties;
7
+ this.useCase = this.properties.useCase;
8
+ this.execute = async (request) => {
9
+ const cookieHeader = getCookieHeaderFromRequest(request);
10
+ const result = await this.useCase({
11
+ cookieHeader: cookieHeader ?? undefined,
12
+ ...this.properties,
13
+ });
14
+ return result.context;
15
+ };
16
+ }
17
+ }
18
+
19
+ export { GetContextController };
@@ -0,0 +1,15 @@
1
+ import type { GetContextParameters } from '@logto/node';
2
+ import type { SessionStorage } from '@remix-run/node';
3
+ import type { CreateLogtoAdapter, LogtoContext } from '../../infrastructure/logto';
4
+ type GetContextRequest = GetContextParameters & {
5
+ readonly cookieHeader: string | undefined;
6
+ };
7
+ type GetContextResponse = {
8
+ context: Readonly<LogtoContext>;
9
+ };
10
+ export declare const makeGetContextUseCase: (deps: {
11
+ createLogtoAdapter: CreateLogtoAdapter;
12
+ sessionStorage: SessionStorage;
13
+ }) => (request: GetContextRequest) => Promise<GetContextResponse>;
14
+ export type GetContextUseCase = ReturnType<typeof makeGetContextUseCase>;
15
+ export {};
@@ -0,0 +1,13 @@
1
+ 'use strict';
2
+
3
+ const makeGetContextUseCase = (deps) => async (request) => {
4
+ const { sessionStorage, createLogtoAdapter } = deps;
5
+ const session = await sessionStorage.getSession(request.cookieHeader);
6
+ const logto = createLogtoAdapter(session);
7
+ const response = await logto.getContext(request);
8
+ return {
9
+ context: response.context,
10
+ };
11
+ };
12
+
13
+ exports.makeGetContextUseCase = makeGetContextUseCase;
@@ -0,0 +1,11 @@
1
+ const makeGetContextUseCase = (deps) => async (request) => {
2
+ const { sessionStorage, createLogtoAdapter } = deps;
3
+ const session = await sessionStorage.getSession(request.cookieHeader);
4
+ const logto = createLogtoAdapter(session);
5
+ const response = await logto.getContext(request);
6
+ return {
7
+ context: response.context,
8
+ };
9
+ };
10
+
11
+ export { makeGetContextUseCase };
@@ -0,0 +1,9 @@
1
+ import type { GetContextParameters } from '@logto/node';
2
+ import type { SessionStorage } from '@remix-run/node';
3
+ import type { CreateLogtoAdapter } from '../../infrastructure/logto';
4
+ type HandleGetContextDeps = {
5
+ readonly createLogtoAdapter: CreateLogtoAdapter;
6
+ readonly sessionStorage: SessionStorage;
7
+ };
8
+ export declare const makeGetContext: (dto: GetContextParameters, deps: HandleGetContextDeps) => (request: Request) => Promise<import("@logto/node").LogtoContext>;
9
+ export {};
@@ -0,0 +1,19 @@
1
+ 'use strict';
2
+
3
+ var GetContextController = require('./GetContextController.js');
4
+ var GetContextUseCase = require('./GetContextUseCase.js');
5
+
6
+ const makeGetContext = (dto, deps) => async (request) => {
7
+ const { createLogtoAdapter, sessionStorage } = deps;
8
+ const useCase = GetContextUseCase.makeGetContextUseCase({
9
+ createLogtoAdapter,
10
+ sessionStorage,
11
+ });
12
+ const controller = GetContextController.GetContextController.fromDto({
13
+ useCase,
14
+ ...dto,
15
+ });
16
+ return controller.execute(request);
17
+ };
18
+
19
+ exports.makeGetContext = makeGetContext;
@@ -0,0 +1,17 @@
1
+ import { GetContextController } from './GetContextController.mjs';
2
+ import { makeGetContextUseCase } from './GetContextUseCase.mjs';
3
+
4
+ const makeGetContext = (dto, deps) => async (request) => {
5
+ const { createLogtoAdapter, sessionStorage } = deps;
6
+ const useCase = makeGetContextUseCase({
7
+ createLogtoAdapter,
8
+ sessionStorage,
9
+ });
10
+ const controller = GetContextController.fromDto({
11
+ useCase,
12
+ ...dto,
13
+ });
14
+ return controller.execute(request);
15
+ };
16
+
17
+ export { makeGetContext };
@@ -0,0 +1,9 @@
1
+ export declare class HandleAuthRoutesError extends Error {
2
+ private readonly properties;
3
+ static readonly becauseNoConfigForPath: (anticipatedPath: string) => HandleAuthRoutesError;
4
+ static readonly becauseOfUnknownRoute: (anticipatedConfigKey: string) => HandleAuthRoutesError;
5
+ readonly code: number;
6
+ readonly cause: Error | undefined;
7
+ readonly plainMessage: string;
8
+ private constructor();
9
+ }
@@ -0,0 +1,21 @@
1
+ 'use strict';
2
+
3
+ class HandleAuthRoutesError extends Error {
4
+ static { this.becauseNoConfigForPath = (anticipatedPath) => new HandleAuthRoutesError({
5
+ code: 1_665_388_277,
6
+ message: `No configuration available for path "${anticipatedPath}".`,
7
+ }); }
8
+ static { this.becauseOfUnknownRoute = (anticipatedConfigKey) => new HandleAuthRoutesError({
9
+ code: 1_665_388_278,
10
+ message: `The config key "${anticipatedConfigKey}" is invalid.`,
11
+ }); }
12
+ constructor(properties) {
13
+ super(`#[${properties.code}] ${properties.message}`);
14
+ this.properties = properties;
15
+ this.code = this.properties.code;
16
+ this.cause = this.properties.cause;
17
+ this.plainMessage = this.properties.message;
18
+ }
19
+ }
20
+
21
+ exports.HandleAuthRoutesError = HandleAuthRoutesError;
@@ -0,0 +1,19 @@
1
+ class HandleAuthRoutesError extends Error {
2
+ static { this.becauseNoConfigForPath = (anticipatedPath) => new HandleAuthRoutesError({
3
+ code: 1_665_388_277,
4
+ message: `No configuration available for path "${anticipatedPath}".`,
5
+ }); }
6
+ static { this.becauseOfUnknownRoute = (anticipatedConfigKey) => new HandleAuthRoutesError({
7
+ code: 1_665_388_278,
8
+ message: `The config key "${anticipatedConfigKey}" is invalid.`,
9
+ }); }
10
+ constructor(properties) {
11
+ super(`#[${properties.code}] ${properties.message}`);
12
+ this.properties = properties;
13
+ this.code = this.properties.code;
14
+ this.cause = this.properties.cause;
15
+ this.plainMessage = this.properties.message;
16
+ }
17
+ }
18
+
19
+ export { HandleAuthRoutesError };
@@ -0,0 +1,15 @@
1
+ import type { LoaderFunction, SessionStorage } from '@remix-run/node';
2
+ import type { CreateLogtoAdapter } from '../../infrastructure/logto';
3
+ type AuthRouteConfig = {
4
+ readonly path: string;
5
+ readonly redirectBackTo: string;
6
+ };
7
+ type PossibleRouteTypes = 'sign-in' | 'sign-in-callback' | 'sign-out';
8
+ type HandleAuthRoutesDto = Record<PossibleRouteTypes, AuthRouteConfig>;
9
+ type MakeHandleAuthRoutesDto = {
10
+ readonly baseUrl: string;
11
+ readonly createLogtoAdapter: CreateLogtoAdapter;
12
+ readonly sessionStorage: SessionStorage;
13
+ };
14
+ export declare const makeHandleAuthRoutes: (deps: MakeHandleAuthRoutesDto) => (dto: HandleAuthRoutesDto) => LoaderFunction;
15
+ export {};
@@ -0,0 +1,44 @@
1
+ 'use strict';
2
+
3
+ var index$2 = require('../handleSignIn/index.js');
4
+ var index$1 = require('../handleSignInCallback/index.js');
5
+ var index = require('../handleSignOut/index.js');
6
+ var HandleAuthRoutesError = require('./HandleAuthRoutesError.js');
7
+
8
+ const makeHandleAuthRoutes = (deps) => (dto) => async ({ request }) => {
9
+ const anticipatedPath = new URL(request.url).pathname;
10
+ /* eslint-disable no-restricted-syntax */
11
+ const configKey = Object.keys(dto).find((type) => dto[type].path === anticipatedPath);
12
+ const configExists = Boolean(configKey);
13
+ /* eslint-enable no-restricted-syntax */
14
+ if (!configExists) {
15
+ throw HandleAuthRoutesError.HandleAuthRoutesError.becauseNoConfigForPath(anticipatedPath);
16
+ }
17
+ const { sessionStorage, createLogtoAdapter, baseUrl } = deps;
18
+ const config = dto[configKey];
19
+ switch (configKey) {
20
+ case 'sign-in': {
21
+ const handler = index$2.makeHandleSignIn({
22
+ redirectBackTo: `${baseUrl}${config.redirectBackTo}`,
23
+ }, { sessionStorage, createLogtoAdapter });
24
+ return handler(request);
25
+ }
26
+ case 'sign-in-callback': {
27
+ const handler = index$1.makeHandleSignInCallback({
28
+ redirectBackTo: `${baseUrl}${config.redirectBackTo}`,
29
+ }, { sessionStorage, createLogtoAdapter });
30
+ return handler(request);
31
+ }
32
+ case 'sign-out': {
33
+ const handler = index.makeHandleSignOut({
34
+ redirectBackTo: `${baseUrl}${config.redirectBackTo}`,
35
+ }, { sessionStorage, createLogtoAdapter });
36
+ return handler(request);
37
+ }
38
+ default: {
39
+ throw HandleAuthRoutesError.HandleAuthRoutesError.becauseOfUnknownRoute(configKey);
40
+ }
41
+ }
42
+ };
43
+
44
+ exports.makeHandleAuthRoutes = makeHandleAuthRoutes;
@@ -0,0 +1,42 @@
1
+ import { makeHandleSignIn } from '../handleSignIn/index.mjs';
2
+ import { makeHandleSignInCallback } from '../handleSignInCallback/index.mjs';
3
+ import { makeHandleSignOut } from '../handleSignOut/index.mjs';
4
+ import { HandleAuthRoutesError } from './HandleAuthRoutesError.mjs';
5
+
6
+ const makeHandleAuthRoutes = (deps) => (dto) => async ({ request }) => {
7
+ const anticipatedPath = new URL(request.url).pathname;
8
+ /* eslint-disable no-restricted-syntax */
9
+ const configKey = Object.keys(dto).find((type) => dto[type].path === anticipatedPath);
10
+ const configExists = Boolean(configKey);
11
+ /* eslint-enable no-restricted-syntax */
12
+ if (!configExists) {
13
+ throw HandleAuthRoutesError.becauseNoConfigForPath(anticipatedPath);
14
+ }
15
+ const { sessionStorage, createLogtoAdapter, baseUrl } = deps;
16
+ const config = dto[configKey];
17
+ switch (configKey) {
18
+ case 'sign-in': {
19
+ const handler = makeHandleSignIn({
20
+ redirectBackTo: `${baseUrl}${config.redirectBackTo}`,
21
+ }, { sessionStorage, createLogtoAdapter });
22
+ return handler(request);
23
+ }
24
+ case 'sign-in-callback': {
25
+ const handler = makeHandleSignInCallback({
26
+ redirectBackTo: `${baseUrl}${config.redirectBackTo}`,
27
+ }, { sessionStorage, createLogtoAdapter });
28
+ return handler(request);
29
+ }
30
+ case 'sign-out': {
31
+ const handler = makeHandleSignOut({
32
+ redirectBackTo: `${baseUrl}${config.redirectBackTo}`,
33
+ }, { sessionStorage, createLogtoAdapter });
34
+ return handler(request);
35
+ }
36
+ default: {
37
+ throw HandleAuthRoutesError.becauseOfUnknownRoute(configKey);
38
+ }
39
+ }
40
+ };
41
+
42
+ export { makeHandleAuthRoutes };
@@ -0,0 +1,15 @@
1
+ import type { TypedResponse } from '@remix-run/node';
2
+ import type { HandleSignInUseCase } from './HandleSignInUseCase';
3
+ type HandleSignInControllerDto = {
4
+ readonly redirectUri: string;
5
+ readonly useCase: HandleSignInUseCase;
6
+ };
7
+ export declare class HandleSignInController {
8
+ private readonly properties;
9
+ static readonly fromDto: (dto: HandleSignInControllerDto) => HandleSignInController;
10
+ private readonly useCase;
11
+ private readonly redirectUri;
12
+ private constructor();
13
+ readonly execute: (request: Request) => Promise<TypedResponse<never>>;
14
+ }
15
+ export {};