-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Manage database dependencies so the integrating form service apps may…
… import and run the server's express handler. This includes: - Create helper in @atj/common to create service objects from a collection of service functions - Remove module-global imports of @atj/database from the @atj/server, replacing with async imports where appropriate TODO: The app integration tests for Kansas and DOJ are now passing, but the build bundle fails.
- Loading branch information
1 parent
3f6ee77
commit 947b2db
Showing
34 changed files
with
263 additions
and
148 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,28 @@ | ||
import { createServer } from '@atj/server/dist/handler.js'; | ||
import path, { dirname } from 'path'; | ||
import { fileURLToPath } from 'url'; | ||
|
||
const getDirname = () => dirname(fileURLToPath(import.meta.url)); | ||
|
||
export const createCustomServer = async (): Promise<any> => { | ||
const { createDevDatabaseContext, createDatabaseService } = await import( | ||
'@atj/database' | ||
); | ||
const { createServer } = await import('@atj/server'); | ||
|
||
const dbCtx = await createDevDatabaseContext( | ||
path.join(getDirname(), '../doj.db') | ||
); | ||
const database = createDatabaseService(dbCtx); | ||
|
||
export const createCustomServer = () => { | ||
return createServer({ | ||
title: 'DOJ Form Service', | ||
database, | ||
loginGovOptions: { | ||
loginGovUrl: 'https://idp.int.identitysandbox.gov', | ||
clientId: | ||
'urn:gov:gsa:openidconnect.profiles:sp:sso:gsa:tts-10x-atj-dev-server-doj', | ||
clientSecret: '', | ||
redirectURI: 'http://localhost:4322/signin/callback', | ||
}, | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,28 @@ | ||
import { createServer } from '@atj/server/dist/handler.js'; | ||
import path, { dirname } from 'path'; | ||
import { fileURLToPath } from 'url'; | ||
|
||
const getDirname = () => dirname(fileURLToPath(import.meta.url)); | ||
|
||
export const createCustomServer = async (): Promise<any> => { | ||
const { createDevDatabaseContext, createDatabaseService } = await import( | ||
'@atj/database' | ||
); | ||
const { createServer } = await import('@atj/server'); | ||
|
||
const dbCtx = await createDevDatabaseContext( | ||
path.join(getDirname(), '../doj.db') | ||
); | ||
const database = createDatabaseService(dbCtx); | ||
|
||
export const createCustomServer = () => { | ||
return createServer({ | ||
title: 'KS Courts Form Service', | ||
database, | ||
loginGovOptions: { | ||
loginGovUrl: 'https://idp.int.identitysandbox.gov', | ||
clientId: | ||
'urn:gov:gsa:openidconnect.profiles:sp:sso:gsa:tts-10x-atj-dev-server-doj', | ||
clientSecret: '', | ||
redirectURI: 'http://localhost:4322/signin/callback', | ||
}, | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,6 @@ import { beforeEach, describe, expect, it, vi } from 'vitest'; | |
|
||
import { processProviderCallback } from './process-provider-callback'; | ||
import { createTestAuthContext } from '../context/test'; | ||
import { createUser } from '@atj/database'; | ||
import { AuthContext } from '..'; | ||
|
||
describe('processProviderCallback', () => { | ||
|
@@ -14,7 +13,7 @@ describe('processProviderCallback', () => { | |
|
||
// Create test auth context with a test user in the db | ||
ctx = await createTestAuthContext(); | ||
const user = await createUser(ctx.database, '[email protected]'); | ||
const user = await ctx.database.createUser('[email protected]'); | ||
if (!user) { | ||
expect.fail('error creating test user'); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,6 @@ | ||
import { randomUUID } from 'crypto'; | ||
import { beforeEach, describe, expect, it, vi } from 'vitest'; | ||
|
||
import { createSession, createUser } from '@atj/database'; | ||
|
||
import { createTestAuthContext } from '../context/test'; | ||
import { processSessionCookie } from './process-session-cookie'; | ||
|
||
|
@@ -121,11 +119,11 @@ const setUpTest = async (sessionExpirationDate: Date) => { | |
setUserSession: vi.fn(), | ||
}; | ||
const ctx = await createTestAuthContext(mocks); | ||
const user = await createUser(ctx.database, '[email protected]'); | ||
const user = await ctx.database.createUser('[email protected]'); | ||
if (!user) { | ||
expect.fail('error creating test user'); | ||
} | ||
const sessionId = await createSession(ctx.database, { | ||
const sessionId = await ctx.database.createSession({ | ||
id: randomUUID(), | ||
expiresAt: addOneDay(sessionExpirationDate), | ||
sessionToken: 'my-token', | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
{ | ||
"extends": "../../tsconfig.base.json", | ||
"compilerOptions": { | ||
"emitDeclarationOnly": false, | ||
"outDir": "./dist", | ||
"emitDeclarationOnly": true | ||
"rootDir": "./src" | ||
}, | ||
"include": ["./src", "global.d.ts"], | ||
"include": ["src", "global.d.ts"], | ||
"exclude": ["./dist"], | ||
"references": [] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
type ServiceFunction<Args extends any[], Return, Context> = ( | ||
context: Context, | ||
...args: Args | ||
) => Return; | ||
|
||
type ServiceFunctions<Context> = { | ||
[key: string]: ServiceFunction<any[], any, Context>; | ||
}; | ||
|
||
type WithoutFirstArg<F> = F extends (context: any, ...args: infer P) => infer R | ||
? (...args: P) => R | ||
: never; | ||
|
||
type Service< | ||
Context extends any, | ||
Functions extends ServiceFunctions<Context>, | ||
> = { | ||
[K in keyof Functions]: WithoutFirstArg<Functions[K]>; | ||
} & { getContext: () => Context }; | ||
|
||
export const createService = < | ||
Context extends any, | ||
Functions extends ServiceFunctions<Context>, | ||
>( | ||
ctx: Context, | ||
serviceFunctions: Functions | ||
): Service<Context, Functions> => { | ||
const handler: ProxyHandler<Functions> = { | ||
get(target: Functions, prop: string | symbol) { | ||
if (prop === 'getContext') { | ||
return () => ctx; | ||
} | ||
const propKey = prop as keyof Functions; | ||
const originalFn = target[propKey]; | ||
return (...args: any[]) => | ||
(originalFn as Function).call(null, ctx, ...args); | ||
}, | ||
}; | ||
|
||
return new Proxy(serviceFunctions, handler) as unknown as Service< | ||
Context, | ||
Functions | ||
>; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.