mirror of
https://github.com/logto-io/logto.git
synced 2024-12-16 20:26:19 -05:00
feat(core): add etag for settings api (#1011)
This commit is contained in:
parent
fdd12de1cf
commit
d4f38bce2b
3 changed files with 46 additions and 20 deletions
|
@ -44,6 +44,7 @@
|
|||
"decamelize": "^5.0.0",
|
||||
"deepmerge": "^4.2.2",
|
||||
"dotenv": "^16.0.0",
|
||||
"etag": "^1.8.1",
|
||||
"got": "^11.8.2",
|
||||
"i18next": "^21.0.0",
|
||||
"iconv-lite": "0.6.3",
|
||||
|
@ -76,6 +77,7 @@
|
|||
"@silverhand/jest-config": "^0.14.0",
|
||||
"@silverhand/ts-config": "^0.14.0",
|
||||
"@types/debug": "^4.1.7",
|
||||
"@types/etag": "^1.8.1",
|
||||
"@types/inquirer": "^8.2.1",
|
||||
"@types/jest": "^27.4.1",
|
||||
"@types/koa": "^2.13.3",
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import { ConnectorMetadata } from '@logto/connector-types';
|
||||
import etag from 'etag';
|
||||
|
||||
import { getConnectorInstances } from '@/connectors';
|
||||
import { findDefaultSignInExperience } from '@/queries/sign-in-experience';
|
||||
|
@ -6,25 +7,39 @@ import { findDefaultSignInExperience } from '@/queries/sign-in-experience';
|
|||
import { AnonymousRouter } from './types';
|
||||
|
||||
export default function signInSettingsRoutes<T extends AnonymousRouter>(router: T) {
|
||||
router.get('/sign-in-settings', async (ctx, next) => {
|
||||
const [signInExperience, connectorInstances] = await Promise.all([
|
||||
findDefaultSignInExperience(),
|
||||
getConnectorInstances(),
|
||||
]);
|
||||
const socialConnectors = signInExperience.socialSignInConnectorTargets.reduce<
|
||||
Array<ConnectorMetadata & { id: string }>
|
||||
>((previous, connectorTarget) => {
|
||||
const connectors = connectorInstances.filter(
|
||||
({ metadata: { target }, connector: { enabled } }) => target === connectorTarget && enabled
|
||||
);
|
||||
router.get(
|
||||
'/sign-in-settings',
|
||||
async (ctx, next) => {
|
||||
const [signInExperience, connectorInstances] = await Promise.all([
|
||||
findDefaultSignInExperience(),
|
||||
getConnectorInstances(),
|
||||
]);
|
||||
const socialConnectors = signInExperience.socialSignInConnectorTargets.reduce<
|
||||
Array<ConnectorMetadata & { id: string }>
|
||||
>((previous, connectorTarget) => {
|
||||
const connectors = connectorInstances.filter(
|
||||
({ metadata: { target }, connector: { enabled } }) =>
|
||||
target === connectorTarget && enabled
|
||||
);
|
||||
|
||||
return [
|
||||
...previous,
|
||||
...connectors.map(({ metadata, connector: { id } }) => ({ ...metadata, id })),
|
||||
];
|
||||
}, []);
|
||||
ctx.body = { ...signInExperience, socialConnectors };
|
||||
return [
|
||||
...previous,
|
||||
...connectors.map(({ metadata, connector: { id } }) => ({ ...metadata, id })),
|
||||
];
|
||||
}, []);
|
||||
ctx.body = { ...signInExperience, socialConnectors };
|
||||
|
||||
return next();
|
||||
});
|
||||
return next();
|
||||
},
|
||||
async (ctx, next) => {
|
||||
await next();
|
||||
|
||||
ctx.response.etag = etag(JSON.stringify(ctx.body));
|
||||
|
||||
if (ctx.fresh) {
|
||||
ctx.status = 304;
|
||||
ctx.body = null;
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
|
|
@ -767,6 +767,7 @@ importers:
|
|||
'@silverhand/jest-config': ^0.14.0
|
||||
'@silverhand/ts-config': ^0.14.0
|
||||
'@types/debug': ^4.1.7
|
||||
'@types/etag': ^1.8.1
|
||||
'@types/inquirer': ^8.2.1
|
||||
'@types/jest': ^27.4.1
|
||||
'@types/koa': ^2.13.3
|
||||
|
@ -786,6 +787,7 @@ importers:
|
|||
deepmerge: ^4.2.2
|
||||
dotenv: ^16.0.0
|
||||
eslint: ^8.10.0
|
||||
etag: ^1.8.1
|
||||
got: ^11.8.2
|
||||
i18next: ^21.0.0
|
||||
iconv-lite: 0.6.3
|
||||
|
@ -847,6 +849,7 @@ importers:
|
|||
decamelize: 5.0.1
|
||||
deepmerge: 4.2.2
|
||||
dotenv: 16.0.0
|
||||
etag: 1.8.1
|
||||
got: 11.8.3
|
||||
i18next: 21.6.12
|
||||
iconv-lite: 0.6.3
|
||||
|
@ -878,6 +881,7 @@ importers:
|
|||
'@silverhand/jest-config': 0.14.0_makj2rl6gt73u7koqro542qsmm
|
||||
'@silverhand/ts-config': 0.14.0_typescript@4.6.2
|
||||
'@types/debug': 4.1.7
|
||||
'@types/etag': 1.8.1
|
||||
'@types/inquirer': 8.2.1
|
||||
'@types/jest': 27.4.1
|
||||
'@types/koa': 2.13.4
|
||||
|
@ -7390,6 +7394,12 @@ packages:
|
|||
resolution: {integrity: sha512-CuPgU6f3eT/XgKKPqKd/gLZV1Xmvf1a2R5POBOGQa6uv82xpls89HU5zKeVoyR8XzHd1RGNOlQlvUe3CFkjWNQ==}
|
||||
dev: true
|
||||
|
||||
/@types/etag/1.8.1:
|
||||
resolution: {integrity: sha512-bsKkeSqN7HYyYntFRAmzcwx/dKW4Wa+KVMTInANlI72PWLQmOpZu96j0OqHZGArW4VQwCmJPteQlXaUDeOB0WQ==}
|
||||
dependencies:
|
||||
'@types/node': 17.0.23
|
||||
dev: true
|
||||
|
||||
/@types/express-serve-static-core/4.17.26:
|
||||
resolution: {integrity: sha512-zeu3tpouA043RHxW0gzRxwCHchMgftE8GArRsvYT0ByDMbn19olQHx5jLue0LxWY6iYtXb7rXmuVtSkhy9YZvQ==}
|
||||
dependencies:
|
||||
|
@ -11511,7 +11521,6 @@ packages:
|
|||
/etag/1.8.1:
|
||||
resolution: {integrity: sha512-aIL5Fx7mawVa300al2BnEE4iNvo1qETxLrPI/o05L7z6go7fCw1J6EQmbK4FmJ2AS7kgVF/KEZWufBfdClMcPg==}
|
||||
engines: {node: '>= 0.6'}
|
||||
dev: true
|
||||
|
||||
/eval/0.1.8:
|
||||
resolution: {integrity: sha512-EzV94NYKoO09GLXGjXj9JIlXijVck4ONSr5wiCWDvhsvj5jxSrzTmRU/9C1DyB6uToszLs8aifA6NQ7lEQdvFw==}
|
||||
|
|
Loading…
Reference in a new issue