@txstate-mws/graphql-server
Version:
A simple graphql server designed to work with typegraphql.
73 lines (72 loc) • 3.58 kB
TypeScript
import { type KeyObject } from 'node:crypto';
import type { Multipart } from '@fastify/multipart';
import { DataLoaderFactory } from 'dataloader-factory';
import { type FastifyRequest } from 'fastify';
import type { FastifyTxStateAuthInfo } from 'fastify-txstate';
import { type JWTPayload, type JWTVerifyGetKey } from 'jose';
import { Cache } from 'txstate-utils';
import type { BaseService } from './service';
import type { UploadFiles } from './models';
export type Type<T> = new (...args: any[]) => T;
export declare function cleanPem(secretOrPem: string | undefined): string | undefined;
export declare class MockContext<AuthType = any> {
auth?: AuthType;
protected serviceInstances: Map<any, any>;
loaders: DataLoaderFactory<this>;
private static executeQuery;
protected parts: AsyncIterableIterator<Multipart> | undefined;
constructor(auth: any);
waitForAuth(): Promise<void>;
static init(): void;
svc<T extends BaseService>(ServiceType: Type<T>): T;
private lasttime?;
timing(...messages: string[]): void;
authForLog(): Partial<AuthType> | undefined;
requireAuth(): void;
query<T>(query: string, variables?: any): Promise<T>;
setParts(parts: AsyncIterableIterator<Multipart> | undefined): void;
files(): UploadFiles;
}
export declare class Context<AuthType = any> extends MockContext<AuthType> {
private authPromise;
protected static jwtVerifyKey: KeyObject | undefined;
protected static issuerKeys: Map<string, KeyObject | JWTVerifyGetKey>;
protected static issuerConfig: Map<string, any>;
protected static tokenCache: Cache<string, any, {
req?: FastifyRequest;
ctx: Context;
}>;
constructor(req?: FastifyRequest);
waitForAuth(): Promise<void>;
static init(): void;
/**
* If implemented, this method will be called on startup, once per configured issuer. It receives
* the issuer configuration from the JWT_TRUSTED_ISSUERS environment variable and allows you to manipulate
* the configuration before storing it.
*
* Once stored, whatever you create may be used in your custom validateToken method. For example,
* you might want to create an in-memory URL object with an issuer's URL so that it can be manipulated
* easily to send validation checks to the issuer.
*/
static processIssuerConfig: undefined | ((config: any) => any);
/**
* If implemented, this method is called after a token's signature is checked and passes. You would
* typically implement this method to check whether the user has manually signed out, or the token has
* been otherwise deauthorized before its expiration date.
*
* If the token is not valid, this method should throw an error with an appropriate message.
*/
static validateToken: undefined | ((token: string, issuerConfig: any, claims: JWTPayload) => void | Promise<void>);
tokenFromReq(req?: FastifyRequest): string | undefined;
authFromReq(req?: FastifyRequest): Promise<AuthType | undefined>;
authFromPayload(payload: JWTPayload): Promise<AuthType>;
}
export declare class TxStateUAuthContext extends Context {
static processIssuerConfig(config: any): any;
static validateToken(token: string, issuerConfig: any, claims: any): Promise<void>;
}
export declare class FastifyTxStateContext extends Context<FastifyTxStateAuthInfo> {
init(): void;
authFromReq(req?: FastifyRequest): Promise<FastifyTxStateAuthInfo | undefined>;
authForLog(): Omit<FastifyTxStateAuthInfo, "token" | "issuerConfig"> | undefined;
}