@memberjunction/server 1.0.4 → 1.0.7-next.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintignore +4 -4
- package/.eslintrc +24 -24
- package/CHANGELOG.json +92 -0
- package/CHANGELOG.md +25 -0
- package/README.md +141 -141
- package/dist/config.d.ts +3 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +4 -1
- package/dist/config.js.map +1 -1
- package/dist/entitySubclasses/entityPermissions.server.d.ts +23 -0
- package/dist/entitySubclasses/entityPermissions.server.d.ts.map +1 -0
- package/dist/entitySubclasses/entityPermissions.server.js +99 -0
- package/dist/entitySubclasses/entityPermissions.server.js.map +1 -0
- package/dist/entitySubclasses/userViewEntity.server.js +17 -17
- package/dist/generated/generated.d.ts.map +1 -1
- package/dist/generated/generated.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/resolvers/AskSkipResolver.js +10 -10
- package/dist/resolvers/FileCategoryResolver.js +2 -2
- package/dist/resolvers/ReportResolver.js +4 -4
- package/package.json +80 -80
- package/src/apolloServer/TransactionPlugin.ts +57 -57
- package/src/apolloServer/index.ts +33 -33
- package/src/auth/exampleNewUserSubClass.ts +73 -73
- package/src/auth/index.ts +151 -151
- package/src/auth/newUsers.ts +56 -56
- package/src/auth/tokenExpiredError.ts +12 -12
- package/src/cache.ts +10 -10
- package/src/config.ts +89 -84
- package/src/context.ts +119 -119
- package/src/directives/Public.ts +42 -42
- package/src/directives/index.ts +1 -1
- package/src/entitySubclasses/entityPermissions.server.ts +111 -0
- package/src/entitySubclasses/userViewEntity.server.ts +187 -187
- package/src/generated/generated.ts +2573 -2573
- package/src/generic/PushStatusResolver.ts +40 -40
- package/src/generic/ResolverBase.ts +331 -331
- package/src/generic/RunViewResolver.ts +350 -350
- package/src/index.ts +133 -137
- package/src/orm.ts +36 -36
- package/src/resolvers/AskSkipResolver.ts +782 -782
- package/src/resolvers/ColorResolver.ts +72 -72
- package/src/resolvers/DatasetResolver.ts +115 -115
- package/src/resolvers/EntityRecordNameResolver.ts +77 -77
- package/src/resolvers/EntityResolver.ts +37 -37
- package/src/resolvers/FileCategoryResolver.ts +38 -38
- package/src/resolvers/FileResolver.ts +110 -110
- package/src/resolvers/MergeRecordsResolver.ts +198 -198
- package/src/resolvers/PotentialDuplicateRecordResolver.ts +59 -59
- package/src/resolvers/QueryResolver.ts +42 -42
- package/src/resolvers/ReportResolver.ts +131 -131
- package/src/resolvers/UserFavoriteResolver.ts +102 -102
- package/src/resolvers/UserResolver.ts +29 -29
- package/src/resolvers/UserViewResolver.ts +64 -64
- package/src/types.ts +19 -19
- package/src/util.ts +106 -106
- package/tsconfig.json +31 -31
- package/typedoc.json +4 -4
- package/build.log.json +0 -44
package/src/index.ts
CHANGED
|
@@ -1,137 +1,133 @@
|
|
|
1
|
-
import dotenv from 'dotenv';
|
|
2
|
-
|
|
3
|
-
dotenv.config();
|
|
4
|
-
|
|
5
|
-
import { expressMiddleware } from '@apollo/server/express4';
|
|
6
|
-
import { mergeSchemas } from '@graphql-tools/schema';
|
|
7
|
-
import { Metadata } from '@memberjunction/core';
|
|
8
|
-
import { setupSQLServerClient, SQLServerProviderConfigData } from '@memberjunction/sqlserver-dataprovider';
|
|
9
|
-
import { json } from 'body-parser';
|
|
10
|
-
import cors from 'cors';
|
|
11
|
-
import express from 'express';
|
|
12
|
-
import { globSync } from 'fast-glob';
|
|
13
|
-
import { useServer } from 'graphql-ws/lib/use/ws';
|
|
14
|
-
import { createServer } from 'node:http';
|
|
15
|
-
import { sep } from 'node:path';
|
|
16
|
-
import 'reflect-metadata';
|
|
17
|
-
import { ReplaySubject } from 'rxjs';
|
|
18
|
-
import { BuildSchemaOptions, buildSchemaSync, GraphQLTimestamp } from 'type-graphql';
|
|
19
|
-
import { DataSource } from 'typeorm';
|
|
20
|
-
import { WebSocketServer } from 'ws';
|
|
21
|
-
import buildApolloServer from './apolloServer';
|
|
22
|
-
import { configInfo, graphqlPort, graphqlRootPath, mj_core_schema, websiteRunFromPackage } from './config';
|
|
23
|
-
import { contextFunction, getUserPayload } from './context';
|
|
24
|
-
import { publicDirective } from './directives';
|
|
25
|
-
import orm from './orm';
|
|
26
|
-
|
|
27
|
-
const cacheRefreshInterval = configInfo.databaseSettings.metadataCacheRefreshInterval;
|
|
28
|
-
|
|
29
|
-
export { MaxLength } from 'class-validator';
|
|
30
|
-
export * from 'type-graphql';
|
|
31
|
-
export { NewUserBase } from './auth/newUsers';
|
|
32
|
-
export { configInfo } from './config';
|
|
33
|
-
export * from './directives';
|
|
34
|
-
export * from './entitySubclasses/userViewEntity.server';
|
|
35
|
-
export * from './
|
|
36
|
-
export
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
export * from './generic/
|
|
40
|
-
export * from './generic/
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
export * from './resolvers/
|
|
44
|
-
export * from './resolvers/
|
|
45
|
-
export * from './resolvers/
|
|
46
|
-
|
|
47
|
-
export * from './resolvers/MergeRecordsResolver';
|
|
48
|
-
export * from './resolvers/ReportResolver';
|
|
49
|
-
|
|
50
|
-
export * from './generated/generated'
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
const
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
const
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
const
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
console.log(`🚀 Server ready at http://localhost:${graphqlPort}/`);
|
|
135
|
-
};
|
|
136
|
-
|
|
137
|
-
export default serve;
|
|
1
|
+
import dotenv from 'dotenv';
|
|
2
|
+
|
|
3
|
+
dotenv.config();
|
|
4
|
+
|
|
5
|
+
import { expressMiddleware } from '@apollo/server/express4';
|
|
6
|
+
import { mergeSchemas } from '@graphql-tools/schema';
|
|
7
|
+
import { Metadata } from '@memberjunction/core';
|
|
8
|
+
import { setupSQLServerClient, SQLServerProviderConfigData } from '@memberjunction/sqlserver-dataprovider';
|
|
9
|
+
import { json } from 'body-parser';
|
|
10
|
+
import cors from 'cors';
|
|
11
|
+
import express from 'express';
|
|
12
|
+
import { globSync } from 'fast-glob';
|
|
13
|
+
import { useServer } from 'graphql-ws/lib/use/ws';
|
|
14
|
+
import { createServer } from 'node:http';
|
|
15
|
+
import { sep } from 'node:path';
|
|
16
|
+
import 'reflect-metadata';
|
|
17
|
+
import { ReplaySubject } from 'rxjs';
|
|
18
|
+
import { BuildSchemaOptions, buildSchemaSync, GraphQLTimestamp } from 'type-graphql';
|
|
19
|
+
import { DataSource } from 'typeorm';
|
|
20
|
+
import { WebSocketServer } from 'ws';
|
|
21
|
+
import buildApolloServer from './apolloServer';
|
|
22
|
+
import { configInfo, graphqlPort, graphqlRootPath, mj_core_schema, websiteRunFromPackage } from './config';
|
|
23
|
+
import { contextFunction, getUserPayload } from './context';
|
|
24
|
+
import { publicDirective } from './directives';
|
|
25
|
+
import orm from './orm';
|
|
26
|
+
|
|
27
|
+
const cacheRefreshInterval = configInfo.databaseSettings.metadataCacheRefreshInterval;
|
|
28
|
+
|
|
29
|
+
export { MaxLength } from 'class-validator';
|
|
30
|
+
export * from 'type-graphql';
|
|
31
|
+
export { NewUserBase } from './auth/newUsers';
|
|
32
|
+
export { configInfo } from './config';
|
|
33
|
+
export * from './directives';
|
|
34
|
+
export * from './entitySubclasses/userViewEntity.server';
|
|
35
|
+
export * from './entitySubclasses/entityPermissions.server';
|
|
36
|
+
export * from './types';
|
|
37
|
+
export { TokenExpiredError } from './auth';
|
|
38
|
+
|
|
39
|
+
export * from './generic/PushStatusResolver';
|
|
40
|
+
export * from './generic/ResolverBase';
|
|
41
|
+
export * from './generic/RunViewResolver';
|
|
42
|
+
|
|
43
|
+
export * from './resolvers/AskSkipResolver';
|
|
44
|
+
export * from './resolvers/ColorResolver';
|
|
45
|
+
export * from './resolvers/DatasetResolver';
|
|
46
|
+
export * from './resolvers/EntityRecordNameResolver';
|
|
47
|
+
export * from './resolvers/MergeRecordsResolver';
|
|
48
|
+
export * from './resolvers/ReportResolver';
|
|
49
|
+
|
|
50
|
+
export * from './generated/generated'
|
|
51
|
+
|
|
52
|
+
import { resolve } from 'node:path';
|
|
53
|
+
|
|
54
|
+
const localPath = (p: string) => resolve(__dirname, p);
|
|
55
|
+
|
|
56
|
+
export const serve = async (resolverPaths: Array<string>) => {
|
|
57
|
+
const localResolverPaths = [
|
|
58
|
+
'resolvers/**/*Resolver.{js,ts}',
|
|
59
|
+
'generic/*Resolver.{js,ts}',
|
|
60
|
+
'generated/generated.{js,ts}'
|
|
61
|
+
].map(localPath);
|
|
62
|
+
|
|
63
|
+
const combinedResolverPaths = [...resolverPaths, ...localResolverPaths];
|
|
64
|
+
|
|
65
|
+
const replaceBackslashes = sep === '\\';
|
|
66
|
+
const paths = combinedResolverPaths.flatMap((path) => globSync(replaceBackslashes ? path.replace(/\\/g, '/') : path));
|
|
67
|
+
if (paths.length === 0) {
|
|
68
|
+
console.warn(`No resolvers found in ${combinedResolverPaths.join(', ')}`);
|
|
69
|
+
console.log({ combinedResolverPaths, paths, cwd: process.cwd() });
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const dataSource = new DataSource(orm(paths));
|
|
73
|
+
const setupComplete$ = new ReplaySubject(1);
|
|
74
|
+
await dataSource.initialize();
|
|
75
|
+
|
|
76
|
+
const config = new SQLServerProviderConfigData(dataSource, '', mj_core_schema, cacheRefreshInterval);
|
|
77
|
+
await setupSQLServerClient(config); // datasource is already initialized, so we can setup the client right away
|
|
78
|
+
const md = new Metadata();
|
|
79
|
+
console.log(`Data Source has been initialized. ${md?.Entities ? md.Entities.length : 0} entities loaded.`);
|
|
80
|
+
|
|
81
|
+
setupComplete$.next(true);
|
|
82
|
+
|
|
83
|
+
const dynamicModules = await Promise.all(paths.map((modulePath) => import(modulePath.replace(/\.[jt]s$/, ''))));
|
|
84
|
+
const resolvers = dynamicModules.flatMap((module) =>
|
|
85
|
+
Object.values(module).filter((value) => typeof value === 'function')
|
|
86
|
+
) as BuildSchemaOptions['resolvers'];
|
|
87
|
+
|
|
88
|
+
const schema = publicDirective.transformer(
|
|
89
|
+
mergeSchemas({
|
|
90
|
+
schemas: [
|
|
91
|
+
buildSchemaSync({
|
|
92
|
+
resolvers,
|
|
93
|
+
validate: false,
|
|
94
|
+
scalarsMap: [{ type: Date, scalar: GraphQLTimestamp }],
|
|
95
|
+
emitSchemaFile: websiteRunFromPackage !== 1,
|
|
96
|
+
}),
|
|
97
|
+
],
|
|
98
|
+
typeDefs: [publicDirective.typeDefs],
|
|
99
|
+
})
|
|
100
|
+
);
|
|
101
|
+
|
|
102
|
+
const app = express();
|
|
103
|
+
const httpServer = createServer(app);
|
|
104
|
+
|
|
105
|
+
const webSocketServer = new WebSocketServer({ server: httpServer, path: graphqlRootPath });
|
|
106
|
+
const serverCleanup = useServer(
|
|
107
|
+
{
|
|
108
|
+
schema,
|
|
109
|
+
context: async ({ connectionParams }) => {
|
|
110
|
+
const userPayload = await getUserPayload(String(connectionParams?.Authorization), undefined, dataSource);
|
|
111
|
+
return { userPayload };
|
|
112
|
+
},
|
|
113
|
+
},
|
|
114
|
+
webSocketServer
|
|
115
|
+
);
|
|
116
|
+
|
|
117
|
+
const apolloServer = buildApolloServer({ schema }, { httpServer, serverCleanup });
|
|
118
|
+
await apolloServer.start();
|
|
119
|
+
|
|
120
|
+
app.use(
|
|
121
|
+
graphqlRootPath,
|
|
122
|
+
cors<cors.CorsRequest>(),
|
|
123
|
+
json({limit: '50mb'}),
|
|
124
|
+
expressMiddleware(apolloServer, {
|
|
125
|
+
context: contextFunction({ setupComplete$, dataSource }),
|
|
126
|
+
})
|
|
127
|
+
);
|
|
128
|
+
|
|
129
|
+
await new Promise<void>((resolve) => httpServer.listen({ port: graphqlPort }, resolve));
|
|
130
|
+
console.log(`🚀 Server ready at http://localhost:${graphqlPort}/`);
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
export default serve;
|
package/src/orm.ts
CHANGED
|
@@ -1,36 +1,36 @@
|
|
|
1
|
-
import { DataSourceOptions } from 'typeorm';
|
|
2
|
-
import { configInfo, dbDatabase, dbHost, dbPassword, dbPort, dbUsername, dbInstanceName, dbTrustServerCertificate } from './config';
|
|
3
|
-
|
|
4
|
-
const orm = (entities: Array<string>): DataSourceOptions => {
|
|
5
|
-
const ormConfig = {
|
|
6
|
-
type: 'mssql' as const,
|
|
7
|
-
entities,
|
|
8
|
-
logging: false,
|
|
9
|
-
host: dbHost,
|
|
10
|
-
port: dbPort,
|
|
11
|
-
username: dbUsername,
|
|
12
|
-
password: dbPassword,
|
|
13
|
-
database: dbDatabase,
|
|
14
|
-
synchronize: false,
|
|
15
|
-
requestTimeout: configInfo.databaseSettings.requestTimeout,
|
|
16
|
-
connectionTimeout: configInfo.databaseSettings.connectionTimeout,
|
|
17
|
-
options: {}
|
|
18
|
-
};
|
|
19
|
-
if (dbInstanceName !== null && dbInstanceName !== undefined && dbInstanceName.trim().length > 0) {
|
|
20
|
-
ormConfig.options = {
|
|
21
|
-
...ormConfig.options,
|
|
22
|
-
instanceName: dbInstanceName
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
if (dbTrustServerCertificate !== null && dbTrustServerCertificate !== undefined) {
|
|
26
|
-
ormConfig.options = {
|
|
27
|
-
...ormConfig.options,
|
|
28
|
-
trustServerCertificate: dbTrustServerCertificate
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
//console.log({ ormConfig: { ...ormConfig, password: '***' } });
|
|
33
|
-
return ormConfig;
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
export default orm;
|
|
1
|
+
import { DataSourceOptions } from 'typeorm';
|
|
2
|
+
import { configInfo, dbDatabase, dbHost, dbPassword, dbPort, dbUsername, dbInstanceName, dbTrustServerCertificate } from './config';
|
|
3
|
+
|
|
4
|
+
const orm = (entities: Array<string>): DataSourceOptions => {
|
|
5
|
+
const ormConfig = {
|
|
6
|
+
type: 'mssql' as const,
|
|
7
|
+
entities,
|
|
8
|
+
logging: false,
|
|
9
|
+
host: dbHost,
|
|
10
|
+
port: dbPort,
|
|
11
|
+
username: dbUsername,
|
|
12
|
+
password: dbPassword,
|
|
13
|
+
database: dbDatabase,
|
|
14
|
+
synchronize: false,
|
|
15
|
+
requestTimeout: configInfo.databaseSettings.requestTimeout,
|
|
16
|
+
connectionTimeout: configInfo.databaseSettings.connectionTimeout,
|
|
17
|
+
options: {}
|
|
18
|
+
};
|
|
19
|
+
if (dbInstanceName !== null && dbInstanceName !== undefined && dbInstanceName.trim().length > 0) {
|
|
20
|
+
ormConfig.options = {
|
|
21
|
+
...ormConfig.options,
|
|
22
|
+
instanceName: dbInstanceName
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
if (dbTrustServerCertificate !== null && dbTrustServerCertificate !== undefined) {
|
|
26
|
+
ormConfig.options = {
|
|
27
|
+
...ormConfig.options,
|
|
28
|
+
trustServerCertificate: dbTrustServerCertificate
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
//console.log({ ormConfig: { ...ormConfig, password: '***' } });
|
|
33
|
+
return ormConfig;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export default orm;
|