@memberjunction/server 2.112.0 → 2.113.1
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/dist/agents/skip-agent.d.ts +4 -4
- package/dist/agents/skip-agent.d.ts.map +1 -1
- package/dist/agents/skip-agent.js +951 -808
- package/dist/agents/skip-agent.js.map +1 -1
- package/dist/agents/skip-sdk.d.ts +1 -1
- package/dist/agents/skip-sdk.d.ts.map +1 -1
- package/dist/agents/skip-sdk.js +43 -53
- package/dist/agents/skip-sdk.js.map +1 -1
- package/dist/apolloServer/index.js +1 -1
- package/dist/auth/AuthProviderFactory.d.ts +1 -1
- package/dist/auth/AuthProviderFactory.d.ts.map +1 -1
- package/dist/auth/AuthProviderFactory.js +3 -1
- package/dist/auth/AuthProviderFactory.js.map +1 -1
- package/dist/auth/BaseAuthProvider.d.ts +1 -1
- package/dist/auth/BaseAuthProvider.d.ts.map +1 -1
- package/dist/auth/BaseAuthProvider.js +2 -3
- package/dist/auth/BaseAuthProvider.js.map +1 -1
- package/dist/auth/IAuthProvider.d.ts +1 -1
- package/dist/auth/IAuthProvider.d.ts.map +1 -1
- package/dist/auth/exampleNewUserSubClass.d.ts.map +1 -1
- package/dist/auth/exampleNewUserSubClass.js +1 -1
- package/dist/auth/exampleNewUserSubClass.js.map +1 -1
- package/dist/auth/index.d.ts +1 -1
- package/dist/auth/index.d.ts.map +1 -1
- package/dist/auth/index.js +6 -6
- package/dist/auth/index.js.map +1 -1
- package/dist/auth/initializeProviders.js +1 -1
- package/dist/auth/initializeProviders.js.map +1 -1
- package/dist/auth/newUsers.d.ts +1 -1
- package/dist/auth/newUsers.d.ts.map +1 -1
- package/dist/auth/newUsers.js +7 -7
- package/dist/auth/newUsers.js.map +1 -1
- package/dist/auth/providers/Auth0Provider.d.ts +1 -1
- package/dist/auth/providers/Auth0Provider.d.ts.map +1 -1
- package/dist/auth/providers/Auth0Provider.js +1 -1
- package/dist/auth/providers/Auth0Provider.js.map +1 -1
- package/dist/auth/providers/CognitoProvider.d.ts +1 -1
- package/dist/auth/providers/CognitoProvider.d.ts.map +1 -1
- package/dist/auth/providers/CognitoProvider.js +6 -3
- package/dist/auth/providers/CognitoProvider.js.map +1 -1
- package/dist/auth/providers/GoogleProvider.d.ts +1 -1
- package/dist/auth/providers/GoogleProvider.d.ts.map +1 -1
- package/dist/auth/providers/GoogleProvider.js +1 -1
- package/dist/auth/providers/GoogleProvider.js.map +1 -1
- package/dist/auth/providers/MSALProvider.d.ts +1 -1
- package/dist/auth/providers/MSALProvider.d.ts.map +1 -1
- package/dist/auth/providers/MSALProvider.js +1 -1
- package/dist/auth/providers/MSALProvider.js.map +1 -1
- package/dist/auth/providers/OktaProvider.d.ts +1 -1
- package/dist/auth/providers/OktaProvider.d.ts.map +1 -1
- package/dist/auth/providers/OktaProvider.js +1 -1
- package/dist/auth/providers/OktaProvider.js.map +1 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +10 -22
- package/dist/config.js.map +1 -1
- package/dist/context.d.ts +1 -1
- package/dist/context.d.ts.map +1 -1
- package/dist/context.js +7 -9
- package/dist/context.js.map +1 -1
- package/dist/entitySubclasses/entityPermissions.server.d.ts +1 -1
- package/dist/entitySubclasses/entityPermissions.server.d.ts.map +1 -1
- package/dist/entitySubclasses/entityPermissions.server.js +1 -1
- package/dist/entitySubclasses/entityPermissions.server.js.map +1 -1
- package/dist/generated/generated.d.ts +788 -658
- package/dist/generated/generated.d.ts.map +1 -1
- package/dist/generated/generated.js +2050 -3054
- package/dist/generated/generated.js.map +1 -1
- package/dist/generic/KeyInputOutputTypes.d.ts +1 -1
- package/dist/generic/KeyInputOutputTypes.d.ts.map +1 -1
- package/dist/generic/KeyInputOutputTypes.js +1 -1
- package/dist/generic/KeyInputOutputTypes.js.map +1 -1
- package/dist/generic/ResolverBase.d.ts +1 -1
- package/dist/generic/ResolverBase.d.ts.map +1 -1
- package/dist/generic/ResolverBase.js +10 -15
- package/dist/generic/ResolverBase.js.map +1 -1
- package/dist/generic/RunViewResolver.d.ts +1 -1
- package/dist/generic/RunViewResolver.d.ts.map +1 -1
- package/dist/generic/RunViewResolver.js +15 -15
- package/dist/generic/RunViewResolver.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +13 -18
- package/dist/index.js.map +1 -1
- package/dist/resolvers/ActionResolver.d.ts +2 -2
- package/dist/resolvers/ActionResolver.d.ts.map +1 -1
- package/dist/resolvers/ActionResolver.js +30 -28
- package/dist/resolvers/ActionResolver.js.map +1 -1
- package/dist/resolvers/AskSkipResolver.d.ts +2 -2
- package/dist/resolvers/AskSkipResolver.d.ts.map +1 -1
- package/dist/resolvers/AskSkipResolver.js +50 -60
- package/dist/resolvers/AskSkipResolver.js.map +1 -1
- package/dist/resolvers/ComponentRegistryResolver.d.ts.map +1 -1
- package/dist/resolvers/ComponentRegistryResolver.js +38 -36
- package/dist/resolvers/ComponentRegistryResolver.js.map +1 -1
- package/dist/resolvers/CreateQueryResolver.d.ts +1 -1
- package/dist/resolvers/CreateQueryResolver.d.ts.map +1 -1
- package/dist/resolvers/CreateQueryResolver.js +40 -43
- package/dist/resolvers/CreateQueryResolver.js.map +1 -1
- package/dist/resolvers/DatasetResolver.d.ts.map +1 -1
- package/dist/resolvers/DatasetResolver.js +1 -1
- package/dist/resolvers/DatasetResolver.js.map +1 -1
- package/dist/resolvers/EntityRecordNameResolver.d.ts +1 -1
- package/dist/resolvers/EntityRecordNameResolver.d.ts.map +1 -1
- package/dist/resolvers/EntityRecordNameResolver.js +1 -1
- package/dist/resolvers/EntityRecordNameResolver.js.map +1 -1
- package/dist/resolvers/EntityResolver.d.ts.map +1 -1
- package/dist/resolvers/EntityResolver.js +1 -1
- package/dist/resolvers/EntityResolver.js.map +1 -1
- package/dist/resolvers/FileCategoryResolver.js +1 -1
- package/dist/resolvers/FileCategoryResolver.js.map +1 -1
- package/dist/resolvers/FileResolver.js +1 -1
- package/dist/resolvers/FileResolver.js.map +1 -1
- package/dist/resolvers/GetDataContextDataResolver.d.ts +1 -1
- package/dist/resolvers/GetDataContextDataResolver.d.ts.map +1 -1
- package/dist/resolvers/GetDataContextDataResolver.js +5 -5
- package/dist/resolvers/GetDataContextDataResolver.js.map +1 -1
- package/dist/resolvers/GetDataResolver.d.ts.map +1 -1
- package/dist/resolvers/GetDataResolver.js +6 -8
- package/dist/resolvers/GetDataResolver.js.map +1 -1
- package/dist/resolvers/MergeRecordsResolver.d.ts +3 -3
- package/dist/resolvers/MergeRecordsResolver.d.ts.map +1 -1
- package/dist/resolvers/MergeRecordsResolver.js +3 -3
- package/dist/resolvers/MergeRecordsResolver.js.map +1 -1
- package/dist/resolvers/PotentialDuplicateRecordResolver.d.ts +1 -1
- package/dist/resolvers/PotentialDuplicateRecordResolver.d.ts.map +1 -1
- package/dist/resolvers/PotentialDuplicateRecordResolver.js +1 -1
- package/dist/resolvers/PotentialDuplicateRecordResolver.js.map +1 -1
- package/dist/resolvers/QueryResolver.d.ts.map +1 -1
- package/dist/resolvers/QueryResolver.js +11 -11
- package/dist/resolvers/QueryResolver.js.map +1 -1
- package/dist/resolvers/ReportResolver.js +1 -1
- package/dist/resolvers/ReportResolver.js.map +1 -1
- package/dist/resolvers/RunAIAgentResolver.d.ts.map +1 -1
- package/dist/resolvers/RunAIAgentResolver.js +28 -27
- package/dist/resolvers/RunAIAgentResolver.js.map +1 -1
- package/dist/resolvers/RunAIPromptResolver.d.ts.map +1 -1
- package/dist/resolvers/RunAIPromptResolver.js +31 -31
- package/dist/resolvers/RunAIPromptResolver.js.map +1 -1
- package/dist/resolvers/RunTemplateResolver.d.ts.map +1 -1
- package/dist/resolvers/RunTemplateResolver.js +9 -9
- package/dist/resolvers/RunTemplateResolver.js.map +1 -1
- package/dist/resolvers/SqlLoggingConfigResolver.d.ts.map +1 -1
- package/dist/resolvers/SqlLoggingConfigResolver.js +10 -10
- package/dist/resolvers/SqlLoggingConfigResolver.js.map +1 -1
- package/dist/resolvers/SyncDataResolver.d.ts +1 -1
- package/dist/resolvers/SyncDataResolver.d.ts.map +1 -1
- package/dist/resolvers/SyncDataResolver.js +14 -15
- package/dist/resolvers/SyncDataResolver.js.map +1 -1
- package/dist/resolvers/SyncRolesUsersResolver.d.ts +1 -1
- package/dist/resolvers/SyncRolesUsersResolver.d.ts.map +1 -1
- package/dist/resolvers/SyncRolesUsersResolver.js +44 -48
- package/dist/resolvers/SyncRolesUsersResolver.js.map +1 -1
- package/dist/resolvers/TaskResolver.d.ts.map +1 -1
- package/dist/resolvers/TaskResolver.js +7 -7
- package/dist/resolvers/TaskResolver.js.map +1 -1
- package/dist/resolvers/TransactionGroupResolver.d.ts +1 -1
- package/dist/resolvers/TransactionGroupResolver.d.ts.map +1 -1
- package/dist/resolvers/TransactionGroupResolver.js +12 -12
- package/dist/resolvers/TransactionGroupResolver.js.map +1 -1
- package/dist/resolvers/UserFavoriteResolver.d.ts +1 -1
- package/dist/resolvers/UserFavoriteResolver.d.ts.map +1 -1
- package/dist/resolvers/UserFavoriteResolver.js +1 -1
- package/dist/resolvers/UserFavoriteResolver.js.map +1 -1
- package/dist/resolvers/UserViewResolver.d.ts.map +1 -1
- package/dist/resolvers/UserViewResolver.js.map +1 -1
- package/dist/rest/EntityCRUDHandler.d.ts +1 -1
- package/dist/rest/EntityCRUDHandler.d.ts.map +1 -1
- package/dist/rest/EntityCRUDHandler.js +16 -14
- package/dist/rest/EntityCRUDHandler.js.map +1 -1
- package/dist/rest/RESTEndpointHandler.d.ts.map +1 -1
- package/dist/rest/RESTEndpointHandler.js +25 -23
- package/dist/rest/RESTEndpointHandler.js.map +1 -1
- package/dist/rest/ViewOperationsHandler.d.ts +1 -1
- package/dist/rest/ViewOperationsHandler.d.ts.map +1 -1
- package/dist/rest/ViewOperationsHandler.js +21 -17
- package/dist/rest/ViewOperationsHandler.js.map +1 -1
- package/dist/scheduler/LearningCycleScheduler.d.ts.map +1 -1
- package/dist/scheduler/LearningCycleScheduler.js.map +1 -1
- package/dist/services/ScheduledJobsService.d.ts.map +1 -1
- package/dist/services/ScheduledJobsService.js +6 -4
- package/dist/services/ScheduledJobsService.js.map +1 -1
- package/dist/services/TaskOrchestrator.d.ts +1 -1
- package/dist/services/TaskOrchestrator.d.ts.map +1 -1
- package/dist/services/TaskOrchestrator.js +30 -30
- package/dist/services/TaskOrchestrator.js.map +1 -1
- package/dist/types.d.ts +3 -3
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +1 -0
- package/dist/types.js.map +1 -1
- package/dist/util.d.ts +1 -1
- package/dist/util.d.ts.map +1 -1
- package/dist/util.js +2 -2
- package/dist/util.js.map +1 -1
- package/package.json +39 -36
- package/src/agents/skip-agent.ts +1200 -1067
- package/src/agents/skip-sdk.ts +851 -877
- package/src/apolloServer/index.ts +2 -2
- package/src/auth/AuthProviderFactory.ts +14 -8
- package/src/auth/BaseAuthProvider.ts +4 -5
- package/src/auth/IAuthProvider.ts +2 -2
- package/src/auth/exampleNewUserSubClass.ts +2 -9
- package/src/auth/index.ts +26 -31
- package/src/auth/initializeProviders.ts +3 -3
- package/src/auth/newUsers.ts +134 -166
- package/src/auth/providers/Auth0Provider.ts +5 -5
- package/src/auth/providers/CognitoProvider.ts +10 -7
- package/src/auth/providers/GoogleProvider.ts +5 -4
- package/src/auth/providers/MSALProvider.ts +5 -5
- package/src/auth/providers/OktaProvider.ts +7 -6
- package/src/config.ts +54 -63
- package/src/context.ts +30 -42
- package/src/entitySubclasses/entityPermissions.server.ts +3 -3
- package/src/generated/generated.ts +40442 -48106
- package/src/generic/KeyInputOutputTypes.ts +6 -3
- package/src/generic/ResolverBase.ts +78 -119
- package/src/generic/RunViewResolver.ts +23 -27
- package/src/index.ts +48 -66
- package/src/resolvers/ActionResolver.ts +57 -46
- package/src/resolvers/AskSkipResolver.ts +533 -607
- package/src/resolvers/ComponentRegistryResolver.ts +562 -547
- package/src/resolvers/CreateQueryResolver.ts +655 -683
- package/src/resolvers/DatasetResolver.ts +6 -5
- package/src/resolvers/EntityCommunicationsResolver.ts +1 -1
- package/src/resolvers/EntityRecordNameResolver.ts +5 -9
- package/src/resolvers/EntityResolver.ts +7 -9
- package/src/resolvers/FileCategoryResolver.ts +2 -2
- package/src/resolvers/FileResolver.ts +4 -4
- package/src/resolvers/GetDataContextDataResolver.ts +118 -106
- package/src/resolvers/GetDataResolver.ts +205 -194
- package/src/resolvers/MergeRecordsResolver.ts +5 -5
- package/src/resolvers/PotentialDuplicateRecordResolver.ts +1 -1
- package/src/resolvers/QueryResolver.ts +78 -95
- package/src/resolvers/ReportResolver.ts +2 -2
- package/src/resolvers/RunAIAgentResolver.ts +828 -818
- package/src/resolvers/RunAIPromptResolver.ts +709 -693
- package/src/resolvers/RunTemplateResolver.ts +103 -105
- package/src/resolvers/SqlLoggingConfigResolver.ts +72 -69
- package/src/resolvers/SyncDataResolver.ts +352 -386
- package/src/resolvers/SyncRolesUsersResolver.ts +350 -387
- package/src/resolvers/TaskResolver.ts +115 -110
- package/src/resolvers/TransactionGroupResolver.ts +138 -143
- package/src/resolvers/UserFavoriteResolver.ts +8 -17
- package/src/resolvers/UserViewResolver.ts +12 -17
- package/src/rest/EntityCRUDHandler.ts +268 -291
- package/src/rest/RESTEndpointHandler.ts +776 -782
- package/src/rest/ViewOperationsHandler.ts +195 -191
- package/src/scheduler/LearningCycleScheduler.ts +52 -8
- package/src/services/ScheduledJobsService.ts +132 -129
- package/src/services/TaskOrchestrator.ts +776 -792
- package/src/types.ts +9 -15
- package/src/util.ts +109 -112
package/src/index.ts
CHANGED
|
@@ -4,7 +4,7 @@ dotenv.config();
|
|
|
4
4
|
|
|
5
5
|
import { expressMiddleware } from '@apollo/server/express4';
|
|
6
6
|
import { mergeSchemas } from '@graphql-tools/schema';
|
|
7
|
-
import { Metadata } from '@memberjunction/
|
|
7
|
+
import { Metadata } from '@memberjunction/core';
|
|
8
8
|
import { setupSQLServerClient, SQLServerProviderConfigData, UserCache } from '@memberjunction/sqlserver-dataprovider';
|
|
9
9
|
import { extendConnectionPoolWithQuery } from './util.js';
|
|
10
10
|
import { default as BodyParser } from 'body-parser';
|
|
@@ -22,18 +22,7 @@ import { BuildSchemaOptions, buildSchemaSync, GraphQLTimestamp } from 'type-grap
|
|
|
22
22
|
import sql from 'mssql';
|
|
23
23
|
import { WebSocketServer } from 'ws';
|
|
24
24
|
import buildApolloServer from './apolloServer/index.js';
|
|
25
|
-
import {
|
|
26
|
-
configInfo,
|
|
27
|
-
dbDatabase,
|
|
28
|
-
dbHost,
|
|
29
|
-
dbPort,
|
|
30
|
-
dbUsername,
|
|
31
|
-
graphqlPort,
|
|
32
|
-
graphqlRootPath,
|
|
33
|
-
mj_core_schema,
|
|
34
|
-
websiteRunFromPackage,
|
|
35
|
-
RESTApiOptions,
|
|
36
|
-
} from './config.js';
|
|
25
|
+
import { configInfo, dbDatabase, dbHost, dbPort, dbUsername, graphqlPort, graphqlRootPath, mj_core_schema, websiteRunFromPackage, RESTApiOptions } from './config.js';
|
|
37
26
|
import { contextFunction, getUserPayload } from './context.js';
|
|
38
27
|
import { requireSystemUserDirective, publicDirective } from './directives/index.js';
|
|
39
28
|
import createMSSQLConfig from './orm.js';
|
|
@@ -41,7 +30,7 @@ import { setupRESTEndpoints } from './rest/setupRESTEndpoints.js';
|
|
|
41
30
|
|
|
42
31
|
import { LoadAllCoreActions } from '@memberjunction/core-actions';
|
|
43
32
|
LoadAllCoreActions(); // prevent tree shaking for this dynamic module
|
|
44
|
-
import { LoadApolloAccountsEnrichmentAction, LoadApolloContactsEnrichmentAction } from '@memberjunction/actions-apollo'
|
|
33
|
+
import { LoadApolloAccountsEnrichmentAction, LoadApolloContactsEnrichmentAction } from '@memberjunction/actions-apollo'
|
|
45
34
|
LoadApolloAccountsEnrichmentAction();
|
|
46
35
|
LoadApolloContactsEnrichmentAction();
|
|
47
36
|
|
|
@@ -61,6 +50,7 @@ LoadSchedulingEngine(); // This also loads drivers
|
|
|
61
50
|
import { LoadAllSchedulingActions } from '@memberjunction/scheduling-actions';
|
|
62
51
|
LoadAllSchedulingActions(); // prevent tree shaking for scheduling actions
|
|
63
52
|
|
|
53
|
+
|
|
64
54
|
import { resolve } from 'node:path';
|
|
65
55
|
import { DataSourceInfo, raiseEvent } from './types.js';
|
|
66
56
|
import { LoadAIEngine } from '@memberjunction/aiengine';
|
|
@@ -69,6 +59,12 @@ import { LoadAIProviders } from '@memberjunction/ai-provider-bundle';
|
|
|
69
59
|
LoadAIEngine();
|
|
70
60
|
LoadAIProviders();
|
|
71
61
|
|
|
62
|
+
// Load Communication Providers
|
|
63
|
+
import { LoadMSGraphProvider } from '@memberjunction/communication-ms-graph';
|
|
64
|
+
import { LoadProvider as LoadSendGridProvider } from '@memberjunction/communication-sendgrid';
|
|
65
|
+
LoadMSGraphProvider();
|
|
66
|
+
LoadSendGridProvider();
|
|
67
|
+
|
|
72
68
|
import { ExternalChangeDetectorEngine } from '@memberjunction/external-change-detection';
|
|
73
69
|
import { ScheduledJobsService } from './services/ScheduledJobsService.js';
|
|
74
70
|
|
|
@@ -116,6 +112,7 @@ export { GetReadOnlyDataSource, GetReadWriteDataSource, GetReadWriteProvider, Ge
|
|
|
116
112
|
|
|
117
113
|
export * from './generated/generated.js';
|
|
118
114
|
|
|
115
|
+
|
|
119
116
|
export type MJServerOptions = {
|
|
120
117
|
onBeforeServe?: () => void | Promise<void>;
|
|
121
118
|
restApiOptions?: Partial<RESTApiOptions>; // Options for REST API configuration
|
|
@@ -153,10 +150,8 @@ export const serve = async (resolverPaths: Array<string>, app = createApp(), opt
|
|
|
153
150
|
const md = new Metadata();
|
|
154
151
|
console.log(`Data Source has been initialized. ${md?.Entities ? md.Entities.length : 0} entities loaded.`);
|
|
155
152
|
|
|
156
|
-
const dataSources = [
|
|
157
|
-
|
|
158
|
-
];
|
|
159
|
-
|
|
153
|
+
const dataSources = [new DataSourceInfo({dataSource: pool, type: 'Read-Write', host: dbHost, port: dbPort, database: dbDatabase, userName: dbUsername})];
|
|
154
|
+
|
|
160
155
|
// Establish a second read-only connection to the database if dbReadOnlyUsername and dbReadOnlyPassword exist
|
|
161
156
|
let readOnlyPool: sql.ConnectionPool | null = null;
|
|
162
157
|
if (configInfo.dbReadOnlyUsername && configInfo.dbReadOnlyPassword) {
|
|
@@ -169,21 +164,12 @@ export const serve = async (resolverPaths: Array<string>, app = createApp(), opt
|
|
|
169
164
|
await readOnlyPool.connect();
|
|
170
165
|
|
|
171
166
|
// since we created a read-only pool, add it to the list of data sources
|
|
172
|
-
dataSources.push(
|
|
173
|
-
new DataSourceInfo({
|
|
174
|
-
dataSource: readOnlyPool,
|
|
175
|
-
type: 'Read-Only',
|
|
176
|
-
host: dbHost,
|
|
177
|
-
port: dbPort,
|
|
178
|
-
database: dbDatabase,
|
|
179
|
-
userName: configInfo.dbReadOnlyUsername,
|
|
180
|
-
})
|
|
181
|
-
);
|
|
167
|
+
dataSources.push(new DataSourceInfo({dataSource: readOnlyPool, type: 'Read-Only', host: dbHost, port: dbPort, database: dbDatabase, userName: configInfo.dbReadOnlyUsername}));
|
|
182
168
|
console.log('Read-only Connection Pool has been initialized.');
|
|
183
169
|
}
|
|
184
170
|
|
|
185
171
|
setupComplete$.next(true);
|
|
186
|
-
raiseEvent('setupComplete', dataSources, null,
|
|
172
|
+
raiseEvent('setupComplete', dataSources, null, this);
|
|
187
173
|
|
|
188
174
|
/******TEST HARNESS FOR CHANGE DETECTION */
|
|
189
175
|
/******TEST HARNESS FOR CHANGE DETECTION */
|
|
@@ -245,45 +231,41 @@ export const serve = async (resolverPaths: Array<string>, app = createApp(), opt
|
|
|
245
231
|
|
|
246
232
|
const apolloServer = buildApolloServer({ schema }, { httpServer, serverCleanup });
|
|
247
233
|
await apolloServer.start();
|
|
248
|
-
|
|
234
|
+
|
|
249
235
|
// Fix #8: Add compression for better throughput performance
|
|
250
|
-
app.use(
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
if (
|
|
259
|
-
contentType.includes('image/') ||
|
|
236
|
+
app.use(compression({
|
|
237
|
+
// Don't compress responses smaller than 1KB
|
|
238
|
+
threshold: 1024,
|
|
239
|
+
// Skip compression for images, videos, and other binary files
|
|
240
|
+
filter: (req, res) => {
|
|
241
|
+
if (req.headers['content-type']) {
|
|
242
|
+
const contentType = req.headers['content-type'];
|
|
243
|
+
if (contentType.includes('image/') ||
|
|
260
244
|
contentType.includes('video/') ||
|
|
261
245
|
contentType.includes('audio/') ||
|
|
262
|
-
contentType.includes('application/octet-stream')
|
|
263
|
-
|
|
264
|
-
return false;
|
|
265
|
-
}
|
|
246
|
+
contentType.includes('application/octet-stream')) {
|
|
247
|
+
return false;
|
|
266
248
|
}
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
);
|
|
249
|
+
}
|
|
250
|
+
return compression.filter(req, res);
|
|
251
|
+
},
|
|
252
|
+
// High compression level (good balance between CPU and compression ratio)
|
|
253
|
+
level: 6
|
|
254
|
+
}));
|
|
273
255
|
|
|
274
256
|
app.use(
|
|
275
257
|
graphqlRootPath,
|
|
276
258
|
cors<cors.CorsRequest>(),
|
|
277
259
|
BodyParser.json({ limit: '50mb' }),
|
|
278
260
|
expressMiddleware(apolloServer, {
|
|
279
|
-
context: contextFunction({
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
261
|
+
context: contextFunction({
|
|
262
|
+
setupComplete$,
|
|
263
|
+
dataSource: extendConnectionPoolWithQuery(pool), // default read-write data source
|
|
264
|
+
dataSources // all data source
|
|
265
|
+
}),
|
|
284
266
|
})
|
|
285
267
|
);
|
|
286
|
-
|
|
268
|
+
|
|
287
269
|
// Setup REST API endpoints
|
|
288
270
|
const authMiddleware = async (req, res, next) => {
|
|
289
271
|
try {
|
|
@@ -297,7 +279,7 @@ export const serve = async (resolverPaths: Array<string>, app = createApp(), opt
|
|
|
297
279
|
if (!userPayload) {
|
|
298
280
|
return res.status(401).json({ error: 'Invalid token' });
|
|
299
281
|
}
|
|
300
|
-
|
|
282
|
+
|
|
301
283
|
req.user = userPayload;
|
|
302
284
|
next();
|
|
303
285
|
} catch (error) {
|
|
@@ -305,19 +287,19 @@ export const serve = async (resolverPaths: Array<string>, app = createApp(), opt
|
|
|
305
287
|
return res.status(401).json({ error: 'Authentication failed' });
|
|
306
288
|
}
|
|
307
289
|
};
|
|
308
|
-
|
|
290
|
+
|
|
309
291
|
// Get REST API configuration from the config file
|
|
310
292
|
const restApiConfig: RESTApiOptions = {
|
|
311
293
|
enabled: configInfo.restApiOptions?.enabled ?? true,
|
|
312
294
|
includeEntities: configInfo.restApiOptions?.includeEntities,
|
|
313
|
-
excludeEntities: configInfo.restApiOptions?.excludeEntities
|
|
295
|
+
excludeEntities: configInfo.restApiOptions?.excludeEntities
|
|
314
296
|
};
|
|
315
|
-
|
|
297
|
+
|
|
316
298
|
// Apply options from server options if provided (these override the config file)
|
|
317
299
|
if (options?.restApiOptions) {
|
|
318
300
|
Object.assign(restApiConfig, options.restApiOptions);
|
|
319
301
|
}
|
|
320
|
-
|
|
302
|
+
|
|
321
303
|
// Get REST API configuration from environment variables if present (env vars override everything)
|
|
322
304
|
if (process.env.MJ_REST_API_ENABLED !== undefined) {
|
|
323
305
|
restApiConfig.enabled = process.env.MJ_REST_API_ENABLED === 'true';
|
|
@@ -325,15 +307,15 @@ export const serve = async (resolverPaths: Array<string>, app = createApp(), opt
|
|
|
325
307
|
console.log('REST API is enabled via environment variable');
|
|
326
308
|
}
|
|
327
309
|
}
|
|
328
|
-
|
|
310
|
+
|
|
329
311
|
if (process.env.MJ_REST_API_INCLUDE_ENTITIES) {
|
|
330
|
-
restApiConfig.includeEntities = process.env.MJ_REST_API_INCLUDE_ENTITIES.split(',').map(
|
|
312
|
+
restApiConfig.includeEntities = process.env.MJ_REST_API_INCLUDE_ENTITIES.split(',').map(e => e.trim());
|
|
331
313
|
}
|
|
332
|
-
|
|
314
|
+
|
|
333
315
|
if (process.env.MJ_REST_API_EXCLUDE_ENTITIES) {
|
|
334
|
-
restApiConfig.excludeEntities = process.env.MJ_REST_API_EXCLUDE_ENTITIES.split(',').map(
|
|
316
|
+
restApiConfig.excludeEntities = process.env.MJ_REST_API_EXCLUDE_ENTITIES.split(',').map(e => e.trim());
|
|
335
317
|
}
|
|
336
|
-
|
|
318
|
+
|
|
337
319
|
// Set up REST endpoints with the configured options and auth middleware
|
|
338
320
|
setupRESTEndpoints(app, restApiConfig, authMiddleware);
|
|
339
321
|
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { Resolver, Mutation, Arg, Ctx } from
|
|
2
|
-
import { ActionEngineServer } from
|
|
3
|
-
import { EntityActionEngineServer } from
|
|
4
|
-
import { Metadata, UserInfo, BaseEntity, CompositeKey, KeyValuePair, LogError } from
|
|
5
|
-
import { ActionParam, ActionResult } from
|
|
6
|
-
import { Field, InputType, ObjectType } from
|
|
7
|
-
import { KeyValuePairInput } from
|
|
8
|
-
import { AppContext, ProviderInfo } from
|
|
9
|
-
import { CopyScalarsAndArrays } from
|
|
10
|
-
import { GetReadOnlyProvider } from
|
|
1
|
+
import { Resolver, Mutation, Arg, Ctx } from "type-graphql";
|
|
2
|
+
import { ActionEngineServer } from "@memberjunction/actions";
|
|
3
|
+
import { EntityActionEngineServer } from "@memberjunction/actions";
|
|
4
|
+
import { Metadata, UserInfo, BaseEntity, CompositeKey, KeyValuePair, LogError } from "@memberjunction/core";
|
|
5
|
+
import { ActionParam, ActionResult } from "@memberjunction/actions-base";
|
|
6
|
+
import { Field, InputType, ObjectType } from "type-graphql";
|
|
7
|
+
import { KeyValuePairInput } from "../generic/KeyValuePairInput.js";
|
|
8
|
+
import { AppContext, ProviderInfo } from "../types.js";
|
|
9
|
+
import { CopyScalarsAndArrays } from "@memberjunction/global";
|
|
10
|
+
import { GetReadOnlyProvider } from "../util.js";
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
13
|
* Input type for action parameters
|
|
@@ -60,7 +60,7 @@ export class RunActionInput {
|
|
|
60
60
|
@Field(() => Boolean, { nullable: true })
|
|
61
61
|
SkipActionLog?: boolean;
|
|
62
62
|
}
|
|
63
|
-
|
|
63
|
+
|
|
64
64
|
/**
|
|
65
65
|
* Represents a collection of key-value pairs that make up a composite key
|
|
66
66
|
* Used for both primary keys and foreign keys
|
|
@@ -97,7 +97,7 @@ export class EntityActionInput {
|
|
|
97
97
|
*/
|
|
98
98
|
@Field(() => String, { nullable: true })
|
|
99
99
|
EntityName?: string;
|
|
100
|
-
|
|
100
|
+
|
|
101
101
|
/**
|
|
102
102
|
* The ID of the entity
|
|
103
103
|
* Use EntityName instead when possible for better code readability
|
|
@@ -179,12 +179,15 @@ export class ActionResolver {
|
|
|
179
179
|
* @returns The result of running the action
|
|
180
180
|
*/
|
|
181
181
|
@Mutation(() => ActionResultOutput)
|
|
182
|
-
async RunAction(
|
|
182
|
+
async RunAction(
|
|
183
|
+
@Arg("input") input: RunActionInput,
|
|
184
|
+
@Ctx() ctx: AppContext
|
|
185
|
+
): Promise<ActionResultOutput> {
|
|
183
186
|
try {
|
|
184
187
|
// Get the user from context
|
|
185
188
|
const user = ctx.userPayload.userRecord;
|
|
186
189
|
if (!user) {
|
|
187
|
-
throw new Error(
|
|
190
|
+
throw new Error("User is not authenticated");
|
|
188
191
|
}
|
|
189
192
|
|
|
190
193
|
// Initialize the action engine
|
|
@@ -214,7 +217,7 @@ export class ActionResolver {
|
|
|
214
217
|
* @private
|
|
215
218
|
*/
|
|
216
219
|
private findActionById(actionID: string): any {
|
|
217
|
-
const action = ActionEngineServer.Instance.Actions.find(
|
|
220
|
+
const action = ActionEngineServer.Instance.Actions.find(a => a.ID === actionID);
|
|
218
221
|
if (!action) {
|
|
219
222
|
throw new Error(`Action with ID ${actionID} not found`);
|
|
220
223
|
}
|
|
@@ -232,9 +235,9 @@ export class ActionResolver {
|
|
|
232
235
|
return [];
|
|
233
236
|
}
|
|
234
237
|
|
|
235
|
-
return inputParams.map(
|
|
238
|
+
return inputParams.map(p => {
|
|
236
239
|
let value: any = p.Value;
|
|
237
|
-
|
|
240
|
+
|
|
238
241
|
// Try to parse JSON for complex values
|
|
239
242
|
try {
|
|
240
243
|
if (p.Value && (p.Type === 'object' || p.Type === 'array')) {
|
|
@@ -245,11 +248,11 @@ export class ActionResolver {
|
|
|
245
248
|
const error = e as Error;
|
|
246
249
|
LogError(`Failed to parse parameter value as JSON: ${error.message}`);
|
|
247
250
|
}
|
|
248
|
-
|
|
251
|
+
|
|
249
252
|
return {
|
|
250
253
|
Name: p.Name,
|
|
251
254
|
Value: value,
|
|
252
|
-
Type: 'Input'
|
|
255
|
+
Type: 'Input' // Default to Input type since we're sending parameters
|
|
253
256
|
};
|
|
254
257
|
});
|
|
255
258
|
}
|
|
@@ -263,13 +266,18 @@ export class ActionResolver {
|
|
|
263
266
|
* @returns The action result
|
|
264
267
|
* @private
|
|
265
268
|
*/
|
|
266
|
-
private async executeAction(
|
|
269
|
+
private async executeAction(
|
|
270
|
+
action: any,
|
|
271
|
+
user: UserInfo,
|
|
272
|
+
params: ActionParam[],
|
|
273
|
+
skipActionLog?: boolean
|
|
274
|
+
): Promise<ActionResult> {
|
|
267
275
|
return await ActionEngineServer.Instance.RunAction({
|
|
268
276
|
Action: action,
|
|
269
277
|
ContextUser: user,
|
|
270
278
|
Params: params,
|
|
271
279
|
SkipActionLog: skipActionLog,
|
|
272
|
-
Filters: []
|
|
280
|
+
Filters: []
|
|
273
281
|
});
|
|
274
282
|
}
|
|
275
283
|
|
|
@@ -280,14 +288,14 @@ export class ActionResolver {
|
|
|
280
288
|
* @private
|
|
281
289
|
*/
|
|
282
290
|
private createActionResult(result: ActionResult): ActionResultOutput {
|
|
283
|
-
const x =
|
|
284
|
-
|
|
285
|
-
|
|
291
|
+
const x =(result.Params || result.RunParams.Params || [])
|
|
292
|
+
.filter(p => p.Type.trim().toLowerCase() === 'output' ||
|
|
293
|
+
p.Type.trim().toLowerCase() === 'both') ;
|
|
286
294
|
return {
|
|
287
295
|
Success: result.Success,
|
|
288
296
|
Message: result.Message,
|
|
289
297
|
ResultCode: result.Result?.ResultCode,
|
|
290
|
-
ResultData: x && x.length > 0 ? JSON.stringify(CopyScalarsAndArrays(x)) : undefined
|
|
298
|
+
ResultData: x && x.length > 0 ? JSON.stringify(CopyScalarsAndArrays(x)) : undefined
|
|
291
299
|
};
|
|
292
300
|
}
|
|
293
301
|
|
|
@@ -302,7 +310,7 @@ export class ActionResolver {
|
|
|
302
310
|
LogError(`Error in RunAction resolver: ${error}`);
|
|
303
311
|
return {
|
|
304
312
|
Success: false,
|
|
305
|
-
Message: `Error executing action: ${error.message}
|
|
313
|
+
Message: `Error executing action: ${error.message}`
|
|
306
314
|
};
|
|
307
315
|
}
|
|
308
316
|
|
|
@@ -313,11 +321,14 @@ export class ActionResolver {
|
|
|
313
321
|
* @returns The result of running the entity action
|
|
314
322
|
*/
|
|
315
323
|
@Mutation(() => ActionResultOutput)
|
|
316
|
-
async RunEntityAction(
|
|
324
|
+
async RunEntityAction(
|
|
325
|
+
@Arg("input") input: EntityActionInput,
|
|
326
|
+
@Ctx() ctx: AppContext
|
|
327
|
+
): Promise<ActionResultOutput> {
|
|
317
328
|
try {
|
|
318
329
|
const user = ctx.userPayload.userRecord;
|
|
319
330
|
if (!user) {
|
|
320
|
-
throw new Error(
|
|
331
|
+
throw new Error("User is not authenticated");
|
|
321
332
|
}
|
|
322
333
|
|
|
323
334
|
// Initialize the entity action engine
|
|
@@ -344,13 +355,13 @@ export class ActionResolver {
|
|
|
344
355
|
return {
|
|
345
356
|
Success: result.Success,
|
|
346
357
|
Message: result.Message,
|
|
347
|
-
ResultData: JSON.stringify(result)
|
|
358
|
+
ResultData: JSON.stringify(result)
|
|
348
359
|
};
|
|
349
360
|
} catch (e) {
|
|
350
361
|
return this.handleError(e);
|
|
351
362
|
}
|
|
352
363
|
}
|
|
353
|
-
|
|
364
|
+
|
|
354
365
|
/**
|
|
355
366
|
* Gets an entity action by ID
|
|
356
367
|
* @param actionID The ID of the entity action
|
|
@@ -359,7 +370,7 @@ export class ActionResolver {
|
|
|
359
370
|
* @private
|
|
360
371
|
*/
|
|
361
372
|
private getEntityAction(actionID: string): any {
|
|
362
|
-
const entityAction = EntityActionEngineServer.Instance.EntityActions.find(
|
|
373
|
+
const entityAction = EntityActionEngineServer.Instance.EntityActions.find(ea => ea.ID === actionID);
|
|
363
374
|
if (!entityAction) {
|
|
364
375
|
throw new Error(`EntityAction with ID ${actionID} not found`);
|
|
365
376
|
}
|
|
@@ -392,23 +403,23 @@ export class ActionResolver {
|
|
|
392
403
|
*/
|
|
393
404
|
private async addEntityObject(providers: Array<ProviderInfo>, params: any, input: EntityActionInput, user: UserInfo): Promise<void> {
|
|
394
405
|
const md = GetReadOnlyProvider(providers);
|
|
395
|
-
|
|
406
|
+
|
|
396
407
|
// Find the entity by ID or name
|
|
397
408
|
let entity;
|
|
398
409
|
if (input.EntityName) {
|
|
399
|
-
entity = md.Entities.find(
|
|
410
|
+
entity = md.Entities.find(e => e.Name === input.EntityName);
|
|
400
411
|
if (!entity) {
|
|
401
412
|
throw new Error(`Entity with name ${input.EntityName} not found`);
|
|
402
413
|
}
|
|
403
414
|
} else if (input.EntityID) {
|
|
404
|
-
entity = md.Entities.find(
|
|
415
|
+
entity = md.Entities.find(e => e.ID === input.EntityID);
|
|
405
416
|
if (!entity) {
|
|
406
417
|
throw new Error(`Entity with ID ${input.EntityID} not found`);
|
|
407
418
|
}
|
|
408
419
|
}
|
|
409
420
|
|
|
410
421
|
if (!entity) {
|
|
411
|
-
throw new Error(
|
|
422
|
+
throw new Error("Entity information is required");
|
|
412
423
|
}
|
|
413
424
|
|
|
414
425
|
// Create a composite key and load the entity object
|
|
@@ -427,24 +438,24 @@ export class ActionResolver {
|
|
|
427
438
|
*/
|
|
428
439
|
private createCompositeKey(entity: any, primaryKey: CompositeKeyInput): CompositeKey {
|
|
429
440
|
const compositeKey = new CompositeKey();
|
|
430
|
-
|
|
441
|
+
|
|
431
442
|
for (const kvp of primaryKey.KeyValuePairs) {
|
|
432
443
|
// Convert value based on the field type if necessary
|
|
433
|
-
const field = entity.Fields.find(
|
|
444
|
+
const field = entity.Fields.find(f => f.Name === kvp.Key);
|
|
434
445
|
let value: any = kvp.Value;
|
|
435
|
-
|
|
446
|
+
|
|
436
447
|
// If the field is found, try to convert to proper type
|
|
437
448
|
if (field) {
|
|
438
449
|
value = this.convertValueToProperType(value, field);
|
|
439
450
|
}
|
|
440
|
-
|
|
451
|
+
|
|
441
452
|
// Add to composite key
|
|
442
453
|
const kvPair = new KeyValuePair();
|
|
443
454
|
kvPair.FieldName = kvp.Key;
|
|
444
455
|
kvPair.Value = value;
|
|
445
456
|
compositeKey.KeyValuePairs.push(kvPair);
|
|
446
457
|
}
|
|
447
|
-
|
|
458
|
+
|
|
448
459
|
return compositeKey;
|
|
449
460
|
}
|
|
450
461
|
|
|
@@ -484,7 +495,7 @@ export class ActionResolver {
|
|
|
484
495
|
|
|
485
496
|
// Add additional parameters if provided
|
|
486
497
|
if (input.Params && input.Params.length > 0) {
|
|
487
|
-
params.Params = input.Params.map(
|
|
498
|
+
params.Params = input.Params.map(p => this.convertParameterValue(p));
|
|
488
499
|
}
|
|
489
500
|
}
|
|
490
501
|
|
|
@@ -496,7 +507,7 @@ export class ActionResolver {
|
|
|
496
507
|
*/
|
|
497
508
|
private convertParameterValue(p: ActionParamInput): any {
|
|
498
509
|
let value: any = p.Value;
|
|
499
|
-
|
|
510
|
+
|
|
500
511
|
// Try to parse JSON for complex values
|
|
501
512
|
try {
|
|
502
513
|
if (p.Value && (p.Type === 'object' || p.Type === 'array')) {
|
|
@@ -507,11 +518,11 @@ export class ActionResolver {
|
|
|
507
518
|
const error = e as Error;
|
|
508
519
|
LogError(`Failed to parse parameter value as JSON: ${error.message}`);
|
|
509
520
|
}
|
|
510
|
-
|
|
521
|
+
|
|
511
522
|
return {
|
|
512
523
|
Name: p.Name,
|
|
513
524
|
Value: value,
|
|
514
|
-
Type: 'Input'
|
|
525
|
+
Type: 'Input' // Default to Input type since we're sending parameters
|
|
515
526
|
};
|
|
516
527
|
}
|
|
517
528
|
|
|
@@ -526,7 +537,7 @@ export class ActionResolver {
|
|
|
526
537
|
LogError(`Error in RunEntityAction resolver: ${error}`);
|
|
527
538
|
return {
|
|
528
539
|
Success: false,
|
|
529
|
-
Message: `Error executing entity action: ${error.message}
|
|
540
|
+
Message: `Error executing entity action: ${error.message}`
|
|
530
541
|
};
|
|
531
542
|
}
|
|
532
|
-
}
|
|
543
|
+
}
|