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