More build fixes
This commit is contained in:
parent
8fabcbaba2
commit
67b9b3e20a
11 changed files with 34 additions and 53 deletions
|
|
@ -1,24 +1,13 @@
|
|||
import type * as Hapi from "@hapi/hapi";
|
||||
import NextAuthPlugin, { AdapterFactory } from "@digiresilience/hapi-nextauth";
|
||||
import NextAuthPlugin from "@digiresilience/hapi-nextauth";
|
||||
import { NextAuthAdapter } from "@digiresilience/metamigo-common";
|
||||
import type {
|
||||
SavedUser,
|
||||
UnsavedUser,
|
||||
SavedSession,
|
||||
} from "@digiresilience/metamigo-common";
|
||||
import { IAppConfig } from "@digiresilience/metamigo-config";
|
||||
|
||||
export const registerNextAuth = async (
|
||||
server: Hapi.Server,
|
||||
config: IAppConfig
|
||||
): Promise<void> => {
|
||||
// I'm not sure why I need to be so explicit with the generic types here
|
||||
// I thought ts could figure out the generics based on the concrete params, but apparently not
|
||||
const nextAuthAdapterFactory: AdapterFactory<
|
||||
SavedUser,
|
||||
UnsavedUser,
|
||||
SavedSession
|
||||
> = (request: Hapi.Request) => new NextAuthAdapter(request.db());
|
||||
const nextAuthAdapterFactory: any = (request: Hapi.Request) => new NextAuthAdapter(request.db());
|
||||
|
||||
await server.register({
|
||||
plugin: NextAuthPlugin,
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/* eslint-disable camelcase */
|
||||
import { FC, useState } from "react";
|
||||
import { useSelector } from "react-redux";
|
||||
// import { useSelector } from "react-redux";
|
||||
import SecurityIcon from "@mui/icons-material/Security";
|
||||
import VoiceIcon from "@mui/icons-material/PhoneInTalk";
|
||||
import { Box } from "@mui/material";
|
||||
|
|
|
|||
6
package-lock.json
generated
6
package-lock.json
generated
|
|
@ -2654,6 +2654,11 @@
|
|||
"react": ">=16.x"
|
||||
}
|
||||
},
|
||||
"node_modules/@graphile-contrib/pg-many-to-many": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmjs.org/@graphile-contrib/pg-many-to-many/-/pg-many-to-many-1.0.2.tgz",
|
||||
"integrity": "sha512-ChSaSU7/n99Crdlink62cCGqlEYmjUJKizz2Nx0tdGgqSMkf6KTk00D3ILGybScywMcJGjJE2cc6FXYIHVlxCg=="
|
||||
},
|
||||
"node_modules/@graphile-contrib/pg-simplify-inflector": {
|
||||
"version": "6.1.0",
|
||||
"resolved": "https://registry.npmjs.org/@graphile-contrib/pg-simplify-inflector/-/pg-simplify-inflector-6.1.0.tgz",
|
||||
|
|
@ -21496,6 +21501,7 @@
|
|||
"dependencies": {
|
||||
"@digiresilience/metamigo-common": "*",
|
||||
"@digiresilience/metamigo-config": "^0.2.0",
|
||||
"@graphile-contrib/pg-many-to-many": "^1.0.2",
|
||||
"graphile-migrate": "^1.4.1",
|
||||
"graphql": "16.6.0",
|
||||
"postgraphile": "4.13.0"
|
||||
|
|
|
|||
|
|
@ -58,16 +58,16 @@ const validateAuth = (sharedSecret) => (request, username, password) => {
|
|||
return { isValid, credentials };
|
||||
};
|
||||
|
||||
const register = async <TUser, TProfile, TSession>(
|
||||
const register = async (
|
||||
server: Hapi.Server,
|
||||
pluginOpts?: NextAuthPluginOptions<TUser, TProfile, TSession>
|
||||
pluginOpts?: any
|
||||
): Promise<void> => {
|
||||
const options: NextAuthPluginOptions<TUser, TProfile, TSession> =
|
||||
const options: any =
|
||||
Hoek.applyToDefaults(
|
||||
// a little type gymnastics here to workaround poor typing
|
||||
defaultOptions as unknown,
|
||||
defaultOptions as any,
|
||||
pluginOpts
|
||||
) as NextAuthPluginOptions<TUser, TProfile, TSession>;
|
||||
) as any;
|
||||
|
||||
if (!options.nextAuthAdapterFactory) {
|
||||
throw new Error(
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
/* eslint-disable unicorn/no-null */
|
||||
import * as Joi from "joi";
|
||||
import * as Hapi from "@hapi/hapi";
|
||||
import { NextAuthPluginOptions } from "./types";
|
||||
import { ResponseToolkit, ResponseObject } from "@hapi/hapi";
|
||||
|
||||
export interface LinkAccountPayload {
|
||||
|
|
@ -14,9 +13,9 @@ export interface LinkAccountPayload {
|
|||
accessTokenExpires?: null;
|
||||
}
|
||||
|
||||
export const register = async <TUser, TProfile, TSession>(
|
||||
export const register = async <TUser, TProfile>(
|
||||
server: Hapi.Server,
|
||||
opts: NextAuthPluginOptions<TUser, TProfile, TSession>,
|
||||
opts: any,
|
||||
auth?: string
|
||||
): Promise<void> => {
|
||||
const { tags, basePath, validators } = opts;
|
||||
|
|
|
|||
|
|
@ -1,14 +1,13 @@
|
|||
// @ts-nocheck
|
||||
import type { AdapterInstance } from "next-auth/adapters";
|
||||
import type { Adapter } from "next-auth/adapters";
|
||||
import type { NumberSchema, StringSchema, ObjectSchema } from "joi";
|
||||
import type { Request } from "@hapi/hapi";
|
||||
|
||||
export type AdapterFactory<TUser, TProfile, TSession> = (
|
||||
export type AdapterFactory = (
|
||||
request: Request
|
||||
) => AdapterInstance<TUser, TProfile, TSession>;
|
||||
) => Adapter;
|
||||
|
||||
export interface NextAuthPluginOptions<TUser, TProfile, TSession> {
|
||||
nextAuthAdapterFactory: AdapterFactory<TUser, TProfile, TSession>;
|
||||
export interface NextAuthPluginOptions {
|
||||
nextAuthAdapterFactory: Adapter;
|
||||
|
||||
validators?: {
|
||||
profile: ObjectSchema;
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
// @ts-nocheck
|
||||
import { writeFileSync } from "node:fs";
|
||||
import {
|
||||
getIntrospectionQuery,
|
||||
|
|
@ -27,7 +26,7 @@ export const exportGraphqlSchema = async (): Promise<void> => {
|
|||
getPostGraphileOptions()
|
||||
)) as unknown as GraphQLSchema;
|
||||
const sorted = lexicographicSortSchema(schema);
|
||||
const json = graphqlSync(schema, getIntrospectionQuery());
|
||||
const json = graphqlSync({ schema, source: getIntrospectionQuery() });
|
||||
writeFileSync(exportSchema, printSchema(sorted));
|
||||
writeFileSync(exportJson, JSON.stringify(json));
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,5 @@
|
|||
/* eslint-disable unicorn/no-null,max-params */
|
||||
// @ts-nocheck
|
||||
import { createHash, randomBytes } from "node:crypto";
|
||||
import type { AdapterInstance } from "next-auth/adapters";
|
||||
import omit from "lodash/omit";
|
||||
import type { IMetamigoRepositories } from "../records";
|
||||
import type { UnsavedAccount } from "../records/account";
|
||||
|
|
@ -20,9 +18,7 @@ const getCompoundId = (providerId: any, providerAccountId: any) =>
|
|||
|
||||
const randomToken = () => randomBytes(32).toString("hex");
|
||||
|
||||
export class NextAuthAdapter<TRepositories extends IMetamigoRepositories>
|
||||
implements AdapterInstance<SavedUser, UnsavedUser, SavedSession>
|
||||
{
|
||||
export class NextAuthAdapter<TRepositories extends IMetamigoRepositories> {
|
||||
constructor(
|
||||
private repos: TRepositories,
|
||||
private readonly sessionMaxAge = defaultSessionMaxAge,
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@
|
|||
"dependencies": {
|
||||
"@digiresilience/metamigo-common": "*",
|
||||
"@digiresilience/metamigo-config": "^0.2.0",
|
||||
"@graphile-contrib/pg-many-to-many": "^1.0.2",
|
||||
"graphile-migrate": "^1.4.1",
|
||||
"graphql": "16.6.0",
|
||||
"postgraphile": "4.13.0"
|
||||
|
|
|
|||
|
|
@ -1,10 +1,9 @@
|
|||
// @ts-nocheck
|
||||
import type { IAppConfig } from "@digiresilience/metamigo-config";
|
||||
import camelcaseKeys from "camelcase-keys";
|
||||
import PgSimplifyInflectorPlugin from "@graphile-contrib/pg-simplify-inflector";
|
||||
// import PgManyToManyPlugin from "@graphile-contrib/pg-many-to-many";
|
||||
import PgManyToManyPlugin from "@graphile-contrib/pg-many-to-many";
|
||||
import * as ConnectionFilterPlugin from "postgraphile-plugin-connection-filter";
|
||||
import type { PostGraphileCoreOptions } from "postgraphile-core";
|
||||
import type { PostGraphileOptions } from "postgraphile";
|
||||
|
||||
import {
|
||||
UserRecordRepository,
|
||||
|
|
@ -52,7 +51,6 @@ export const dbInitOptions = (
|
|||
|
||||
// Extending the database protocol with our custom repositories;
|
||||
// API: http://vitaly-t.github.io/pg-promise/global.html#event:extend
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
extend(obj: any, _dc) {
|
||||
// AppDatase was obj type
|
||||
// Database Context (_dc) is mainly needed for extending multiple databases with different access API.
|
||||
|
|
@ -74,14 +72,13 @@ export const dbInitOptions = (
|
|||
},
|
||||
});
|
||||
|
||||
export const getPostGraphileOptions = (): PostGraphileCoreOptions => ({
|
||||
export const getPostGraphileOptions = (): PostGraphileOptions => ({
|
||||
ignoreRBAC: false,
|
||||
dynamicJson: true,
|
||||
ignoreIndexes: false,
|
||||
appendPlugins: [
|
||||
PgSimplifyInflectorPlugin,
|
||||
// PgManyToManyPlugin,
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
PgManyToManyPlugin,
|
||||
ConnectionFilterPlugin as any,
|
||||
],
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,5 +1,3 @@
|
|||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-nocheck
|
||||
/* eslint-disable no-new,no-useless-call */
|
||||
// mutableProxyFactory from https://stackoverflow.com/a/54460544
|
||||
// (C) Alex Hall https://stackoverflow.com/users/2482744/alex-hall
|
||||
|
|
@ -11,7 +9,6 @@ export class PProxyHandler<T extends object> implements ProxyHandler<T> {
|
|||
return Reflect.getPrototypeOf(target);
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
setPrototypeOf?(target: T, v: any): boolean {
|
||||
return Reflect.setPrototypeOf(target, v);
|
||||
}
|
||||
|
|
@ -35,12 +32,10 @@ export class PProxyHandler<T extends object> implements ProxyHandler<T> {
|
|||
return Reflect.has(target, p);
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
get?(target: T, p: PropertyKey, receiver: any): any {
|
||||
return Reflect.get(target, p, receiver);
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
set?(target: T, p: PropertyKey, value: any, receiver: any): boolean {
|
||||
return Reflect.set(target, p, value, receiver);
|
||||
}
|
||||
|
|
@ -61,16 +56,15 @@ export class PProxyHandler<T extends object> implements ProxyHandler<T> {
|
|||
return Reflect.ownKeys(target);
|
||||
}
|
||||
|
||||
// @ts-expect-error
|
||||
ownKeys?(target: T): PropertyKey[] {
|
||||
return Reflect.ownKeys(target);
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
apply?(target: T, thisArg: any, argArray?: any): any {
|
||||
return Reflect.apply(target as Function, thisArg, argArray);
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
construct?(target: T, argArray: any, newTarget?: any): object {
|
||||
return Reflect.construct(target as Function, argArray, newTarget);
|
||||
}
|
||||
|
|
@ -88,27 +82,28 @@ export function mutableProxyFactory<T extends object>(
|
|||
mutableTarget: T,
|
||||
mutableHandler?: ProxyHandler<T>
|
||||
): MutableProxy<T> {
|
||||
if (!mutableHandler) mutableHandler = new PProxyHandler();
|
||||
if (!mutableHandler) mutableHandler = new PProxyHandler() as any;
|
||||
return {
|
||||
setTarget(target: T): void {
|
||||
new Proxy(target, {}); // test target validity
|
||||
mutableTarget = target;
|
||||
},
|
||||
setHandler(handler: PProxyHandler<T>): void {
|
||||
new Proxy({}, handler); // test handler validity
|
||||
new Proxy({}, handler as any); // test handler validity
|
||||
Object.keys(handler).forEach((key) => {
|
||||
const value = handler[key];
|
||||
if (Reflect[key] && typeof value !== "function") {
|
||||
throw new Error(`Trap "${key}: ${value}" is not a function`);
|
||||
}
|
||||
});
|
||||
mutableHandler = handler;
|
||||
mutableHandler = handler as any;
|
||||
},
|
||||
getTarget(): T {
|
||||
return mutableTarget;
|
||||
},
|
||||
// @ts-expect-error
|
||||
getHandler(): PProxyHandler<T> {
|
||||
return mutableHandler;
|
||||
return mutableHandler as any;
|
||||
},
|
||||
proxy: new Proxy(
|
||||
mutableTarget,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue