Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove createSessionContext export from @keystone-6/core/session #7912

Merged
merged 1 commit into from
Sep 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/nine-pugs-draw.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@keystone-6/core': major
---

Removes `createSessionContext` export from `@keystone-6/core/session`
15 changes: 15 additions & 0 deletions packages/core/src/lib/context/session.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { IncomingMessage, ServerResponse } from 'http';
import { SessionStrategy, CreateContext, SessionContext } from '../../types';

export async function createSessionContext<T>(
sessionStrategy: SessionStrategy<T>,
req: IncomingMessage,
res: ServerResponse,
createContext: CreateContext
): Promise<SessionContext<T>> {
return {
session: await sessionStrategy.get({ req, createContext }),
startSession: (data: T) => sessionStrategy.start({ res, data, createContext }),
endSession: () => sessionStrategy.end({ req, res, createContext }),
};
}
2 changes: 1 addition & 1 deletion packages/core/src/lib/server/createAdminUIMiddleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import url from 'url';
import path from 'path';
import express from 'express';
import type { KeystoneConfig, CreateContext } from '../../types';
import { createSessionContext } from '../../session';
import { createSessionContext } from '../context/session';

const adminErrorHTMLFilepath = path.join(
path.dirname(require.resolve('@keystone-6/core/package.json')),
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/lib/server/createApolloServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
Config,
} from 'apollo-server-core';
import type { CreateContext, GraphQLConfig, SessionStrategy } from '../../types';
import { createSessionContext } from '../../session';
import { createSessionContext } from '../context/session';

export const createApolloServerMicro = ({
graphQLSchema,
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/lib/server/createExpressServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { GraphQLSchema } from 'graphql';
import graphqlUploadExpress from 'graphql-upload/graphqlUploadExpress.js';
import { ApolloServer } from 'apollo-server-express';
import type { KeystoneConfig, CreateContext, SessionStrategy, GraphQLConfig } from '../../types';
import { createSessionContext } from '../../session';
import { createSessionContext } from '../context/session';
import { createApolloServerExpress } from './createApolloServer';
import { addHealthCheck } from './addHealthCheck';

Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/scripts/run/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ import {
requirePrismaClient,
} from '../../artifacts';
import { ExitError, getAdminPath, getBuiltConfigPath } from '../utils';
import { createSessionContext } from '../../session';
import { AdminMetaRootVal, CreateContext, KeystoneConfig } from '../../types';
import { initialiseLists } from '../../lib/core/types-for-lists';
import { printPrismaSchema } from '../../lib/core/prisma-schema';
import { createSessionContext } from '../../lib/context/session';

const devLoadingHTMLFilepath = path.join(
path.dirname(require.resolve('@keystone-6/core/package.json')),
Expand Down
25 changes: 1 addition & 24 deletions packages/core/src/session/index.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
import { IncomingMessage, ServerResponse } from 'http';
import * as cookie from 'cookie';
import Iron from '@hapi/iron';
// uid-safe is what express-session uses so let's just use it
import { sync as uid } from 'uid-safe';
import {
SessionStrategy,
JSONValue,
SessionStoreFunction,
SessionContext,
CreateContext,
} from '../types';
import { SessionStrategy, JSONValue, SessionStoreFunction } from '../types';

function generateSessionId() {
return uid(24);
Expand Down Expand Up @@ -177,19 +170,3 @@ export function storedSessions({
},
};
}

/**
* This is the function createSystem uses to implement the session strategy provided
*/
export async function createSessionContext<T>(
sessionStrategy: SessionStrategy<T>,
req: IncomingMessage,
res: ServerResponse,
createContext: CreateContext
): Promise<SessionContext<T>> {
return {
session: await sessionStrategy.get({ req, createContext }),
startSession: (data: T) => sessionStrategy.start({ res, data, createContext }),
endSession: () => sessionStrategy.end({ req, res, createContext }),
};
}