@logto/remix 1.1.1 → 2.0.0
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/lib/framework/get-cookie-header-from-request.cjs +5 -0
- package/lib/framework/get-cookie-header-from-request.d.ts +1 -0
- package/lib/framework/get-cookie-header-from-request.js +3 -0
- package/lib/framework/mocks.d.ts +22 -0
- package/lib/index.cjs +24 -0
- package/lib/index.d.ts +3 -7
- package/lib/index.js +17 -482
- package/lib/infrastructure/logto/create-client.cjs +17 -0
- package/lib/infrastructure/logto/create-client.d.ts +6 -0
- package/lib/infrastructure/logto/create-client.js +11 -0
- package/lib/infrastructure/logto/create-client.spec.d.ts +1 -0
- package/lib/infrastructure/logto/create-storage.cjs +30 -0
- package/lib/infrastructure/logto/create-storage.d.ts +14 -0
- package/lib/infrastructure/logto/create-storage.js +28 -0
- package/lib/infrastructure/logto/create-storage.spec.d.ts +1 -0
- package/lib/infrastructure/logto/get-context.cjs +12 -0
- package/lib/infrastructure/logto/get-context.d.ts +11 -0
- package/lib/infrastructure/logto/get-context.js +10 -0
- package/lib/infrastructure/logto/handle-sign-in-callback.cjs +12 -0
- package/lib/infrastructure/logto/handle-sign-in-callback.d.ts +14 -0
- package/lib/infrastructure/logto/handle-sign-in-callback.js +10 -0
- package/lib/infrastructure/logto/handle-sign-in.cjs +30 -0
- package/lib/infrastructure/logto/handle-sign-in.d.ts +15 -0
- package/lib/infrastructure/logto/handle-sign-in.js +28 -0
- package/lib/infrastructure/logto/handle-sign-out.cjs +26 -0
- package/lib/infrastructure/logto/handle-sign-out.d.ts +11 -0
- package/lib/infrastructure/logto/handle-sign-out.js +24 -0
- package/lib/infrastructure/logto/index.cjs +21 -0
- package/lib/infrastructure/logto/index.d.ts +26 -0
- package/lib/infrastructure/logto/index.js +19 -0
- package/lib/useCases/getContext/GetContextController.cjs +21 -0
- package/lib/useCases/getContext/GetContextController.d.ts +13 -0
- package/lib/useCases/getContext/GetContextController.js +19 -0
- package/lib/useCases/getContext/GetContextController.spec.d.ts +1 -0
- package/lib/useCases/getContext/GetContextUseCase.cjs +13 -0
- package/lib/useCases/getContext/GetContextUseCase.d.ts +15 -0
- package/lib/useCases/getContext/GetContextUseCase.js +11 -0
- package/lib/useCases/getContext/GetContextUseCase.spec.d.ts +1 -0
- package/lib/useCases/getContext/index.cjs +19 -0
- package/lib/useCases/getContext/index.d.ts +9 -0
- package/lib/useCases/getContext/index.js +17 -0
- package/lib/useCases/handleAuthRoutes/HandleAuthRoutesError.cjs +21 -0
- package/lib/useCases/handleAuthRoutes/HandleAuthRoutesError.d.ts +9 -0
- package/lib/useCases/handleAuthRoutes/HandleAuthRoutesError.js +19 -0
- package/lib/useCases/handleAuthRoutes/index.cjs +44 -0
- package/lib/useCases/handleAuthRoutes/index.d.ts +15 -0
- package/lib/useCases/handleAuthRoutes/index.js +42 -0
- package/lib/useCases/handleSignIn/HandleSignInController.cjs +31 -0
- package/lib/useCases/handleSignIn/HandleSignInController.d.ts +15 -0
- package/lib/useCases/handleSignIn/HandleSignInController.js +29 -0
- package/lib/useCases/handleSignIn/HandleSignInController.spec.d.ts +1 -0
- package/lib/useCases/handleSignIn/HandleSignInUseCase.cjs +17 -0
- package/lib/useCases/handleSignIn/HandleSignInUseCase.d.ts +16 -0
- package/lib/useCases/handleSignIn/HandleSignInUseCase.js +15 -0
- package/lib/useCases/handleSignIn/HandleSignInUseCase.spec.d.ts +1 -0
- package/lib/useCases/handleSignIn/index.cjs +19 -0
- package/lib/useCases/handleSignIn/index.d.ts +11 -0
- package/lib/useCases/handleSignIn/index.js +17 -0
- package/lib/useCases/handleSignInCallback/HandleSignInCallbackController.cjs +42 -0
- package/lib/useCases/handleSignInCallback/HandleSignInCallbackController.d.ts +15 -0
- package/lib/useCases/handleSignInCallback/HandleSignInCallbackController.js +40 -0
- package/lib/useCases/handleSignInCallback/HandleSignInCallbackController.spec.d.ts +1 -0
- package/lib/useCases/handleSignInCallback/HandleSignInCallbackError.cjs +17 -0
- package/lib/useCases/handleSignInCallback/HandleSignInCallbackError.d.ts +8 -0
- package/lib/useCases/handleSignInCallback/HandleSignInCallbackError.js +15 -0
- package/lib/useCases/handleSignInCallback/HandleSignInCallbackUseCase.cjs +16 -0
- package/lib/useCases/handleSignInCallback/HandleSignInCallbackUseCase.d.ts +15 -0
- package/lib/useCases/handleSignInCallback/HandleSignInCallbackUseCase.js +14 -0
- package/lib/useCases/handleSignInCallback/HandleSignInCallbackUseCase.spec.d.ts +1 -0
- package/lib/useCases/handleSignInCallback/index.cjs +19 -0
- package/lib/useCases/handleSignInCallback/index.d.ts +11 -0
- package/lib/useCases/handleSignInCallback/index.js +17 -0
- package/lib/useCases/handleSignOut/HandleSignOutController.cjs +34 -0
- package/lib/useCases/handleSignOut/HandleSignOutController.d.ts +15 -0
- package/lib/useCases/handleSignOut/HandleSignOutController.js +32 -0
- package/lib/useCases/handleSignOut/HandleSignOutController.spec.d.ts +1 -0
- package/lib/useCases/handleSignOut/HandleSignOutError.cjs +17 -0
- package/lib/useCases/handleSignOut/HandleSignOutError.d.ts +8 -0
- package/lib/useCases/handleSignOut/HandleSignOutError.js +15 -0
- package/lib/useCases/handleSignOut/HandleSignOutUseCase.cjs +17 -0
- package/lib/useCases/handleSignOut/HandleSignOutUseCase.d.ts +16 -0
- package/lib/useCases/handleSignOut/HandleSignOutUseCase.js +15 -0
- package/lib/useCases/handleSignOut/HandleSignOutUseCase.spec.d.ts +1 -0
- package/lib/useCases/handleSignOut/index.cjs +19 -0
- package/lib/useCases/handleSignOut/index.d.ts +11 -0
- package/lib/useCases/handleSignOut/index.js +17 -0
- package/package.json +29 -34
- package/lib/index.d.ts.map +0 -1
- package/lib/index.js.map +0 -1
- package/lib/module.d.mts +0 -29
- package/lib/module.mjs +0 -480
- 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,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,11 @@
|
|
|
1
|
+
import type { GetContextParameters, LogtoContext } from '@logto/node';
|
|
2
|
+
import type { CreateLogtoClient } from './create-client.js';
|
|
3
|
+
import type { LogtoStorage } from './create-storage.js';
|
|
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 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,14 @@
|
|
|
1
|
+
import type { Session } from '@remix-run/node';
|
|
2
|
+
import type { CreateLogtoClient } from './create-client.js';
|
|
3
|
+
import type { LogtoStorage } from './create-storage.js';
|
|
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,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,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,15 @@
|
|
|
1
|
+
import type { Session } from '@remix-run/node';
|
|
2
|
+
import type { CreateLogtoClient } from './create-client.js';
|
|
3
|
+
import type { LogtoStorage } from './create-storage.js';
|
|
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,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,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,11 @@
|
|
|
1
|
+
import type { CreateLogtoClient } from './create-client.js';
|
|
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,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,21 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var createClient = require('./create-client.cjs');
|
|
4
|
+
var createStorage = require('./create-storage.cjs');
|
|
5
|
+
var getContext = require('./get-context.cjs');
|
|
6
|
+
var handleSignInCallback = require('./handle-sign-in-callback.cjs');
|
|
7
|
+
var handleSignIn = require('./handle-sign-in.cjs');
|
|
8
|
+
var handleSignOut = require('./handle-sign-out.cjs');
|
|
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,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,19 @@
|
|
|
1
|
+
import { makeLogtoClient } from './create-client.js';
|
|
2
|
+
import { createStorage } from './create-storage.js';
|
|
3
|
+
import { makeGetContext } from './get-context.js';
|
|
4
|
+
import { makeHandleSignInCallback } from './handle-sign-in-callback.js';
|
|
5
|
+
import { makeHandleSignIn } from './handle-sign-in.js';
|
|
6
|
+
import { makeHandleSignOut } from './handle-sign-out.js';
|
|
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,21 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var getCookieHeaderFromRequest = require('../../framework/get-cookie-header-from-request.cjs');
|
|
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,13 @@
|
|
|
1
|
+
import type { GetContextParameters, LogtoContext } from '@logto/node';
|
|
2
|
+
import type { GetContextUseCase } from './GetContextUseCase.js';
|
|
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,19 @@
|
|
|
1
|
+
import { getCookieHeaderFromRequest } from '../../framework/get-cookie-header-from-request.js';
|
|
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 @@
|
|
|
1
|
+
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,15 @@
|
|
|
1
|
+
import type { GetContextParameters } from '@logto/node';
|
|
2
|
+
import type { SessionStorage } from '@remix-run/node';
|
|
3
|
+
import type { CreateLogtoAdapter, LogtoContext } from '../../infrastructure/logto/index.js';
|
|
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,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 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var GetContextController = require('./GetContextController.cjs');
|
|
4
|
+
var GetContextUseCase = require('./GetContextUseCase.cjs');
|
|
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,9 @@
|
|
|
1
|
+
import type { GetContextParameters } from '@logto/node';
|
|
2
|
+
import type { SessionStorage } from '@remix-run/node';
|
|
3
|
+
import type { CreateLogtoAdapter } from '../../infrastructure/logto/index.js';
|
|
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,17 @@
|
|
|
1
|
+
import { GetContextController } from './GetContextController.js';
|
|
2
|
+
import { makeGetContextUseCase } from './GetContextUseCase.js';
|
|
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,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,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,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,44 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var index$2 = require('../handleSignIn/index.cjs');
|
|
4
|
+
var index$1 = require('../handleSignInCallback/index.cjs');
|
|
5
|
+
var index = require('../handleSignOut/index.cjs');
|
|
6
|
+
var HandleAuthRoutesError = require('./HandleAuthRoutesError.cjs');
|
|
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,15 @@
|
|
|
1
|
+
import type { LoaderFunction, SessionStorage } from '@remix-run/node';
|
|
2
|
+
import type { CreateLogtoAdapter } from '../../infrastructure/logto/index.js';
|
|
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,42 @@
|
|
|
1
|
+
import { makeHandleSignIn } from '../handleSignIn/index.js';
|
|
2
|
+
import { makeHandleSignInCallback } from '../handleSignInCallback/index.js';
|
|
3
|
+
import { makeHandleSignOut } from '../handleSignOut/index.js';
|
|
4
|
+
import { HandleAuthRoutesError } from './HandleAuthRoutesError.js';
|
|
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 };
|