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