@memberjunction/server 0.9.73 → 0.9.74
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/README.md +141 -141
- package/dist/apolloServer/TransactionPlugin.js +45 -45
- package/dist/apolloServer/index.js +26 -26
- package/dist/auth/exampleNewUserSubClass.js +67 -67
- package/dist/auth/index.js +104 -104
- package/dist/auth/newUsers.js +66 -66
- package/dist/cache.js +10 -10
- package/dist/config.js +61 -61
- package/dist/context.js +101 -101
- package/dist/directives/Public.js +33 -33
- package/dist/directives/index.js +17 -17
- package/dist/entitySubclasses/userViewEntity.server.js +144 -144
- package/dist/index.js +120 -120
- package/dist/orm.js +33 -33
- package/dist/types.js +2 -2
- package/package.json +75 -75
- package/src/apolloServer/TransactionPlugin.ts +54 -54
- package/src/apolloServer/index.ts +33 -33
- package/src/auth/exampleNewUserSubClass.ts +70 -70
- package/src/auth/index.ts +136 -136
- package/src/auth/newUsers.ts +55 -55
- package/src/cache.ts +10 -10
- package/src/config.ts +76 -76
- package/src/context.ts +106 -106
- package/src/directives/Public.ts +42 -42
- package/src/directives/index.ts +1 -1
- package/src/entitySubclasses/userViewEntity.server.ts +156 -156
- package/src/index.ts +111 -111
- package/src/orm.ts +36 -36
- package/src/types.ts +19 -19
package/.eslintignore
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
node_modules
|
|
2
|
-
dist
|
|
3
|
-
package-lock.json
|
|
4
|
-
src/generated/**
|
|
1
|
+
node_modules
|
|
2
|
+
dist
|
|
3
|
+
package-lock.json
|
|
4
|
+
src/generated/**
|
|
5
5
|
src/generic/**
|
package/.eslintrc
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
{
|
|
2
|
-
"env": {
|
|
3
|
-
"node": true
|
|
4
|
-
},
|
|
5
|
-
"extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended", "prettier"],
|
|
6
|
-
"parser": "@typescript-eslint/parser",
|
|
7
|
-
"plugins": ["prettier", "@typescript-eslint"],
|
|
8
|
-
"rules": {
|
|
9
|
-
"@typescript-eslint/no-explicit-any": "error",
|
|
10
|
-
"@typescript-eslint/no-shadow": "error",
|
|
11
|
-
"@typescript-eslint/no-unused-vars": ["error", { "argsIgnorePattern": "^_" }],
|
|
12
|
-
"class-methods-use-this": "off",
|
|
13
|
-
"no-shadow": "off",
|
|
14
|
-
"no-unused-vars": "off",
|
|
15
|
-
"object-shorthand": "error",
|
|
16
|
-
"prettier/prettier": "error",
|
|
17
|
-
"spaced-comment": "off"
|
|
18
|
-
},
|
|
19
|
-
"settings": {
|
|
20
|
-
"import/resolver": {
|
|
21
|
-
"typescript": {}
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"env": {
|
|
3
|
+
"node": true
|
|
4
|
+
},
|
|
5
|
+
"extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended", "prettier"],
|
|
6
|
+
"parser": "@typescript-eslint/parser",
|
|
7
|
+
"plugins": ["prettier", "@typescript-eslint"],
|
|
8
|
+
"rules": {
|
|
9
|
+
"@typescript-eslint/no-explicit-any": "error",
|
|
10
|
+
"@typescript-eslint/no-shadow": "error",
|
|
11
|
+
"@typescript-eslint/no-unused-vars": ["error", { "argsIgnorePattern": "^_" }],
|
|
12
|
+
"class-methods-use-this": "off",
|
|
13
|
+
"no-shadow": "off",
|
|
14
|
+
"no-unused-vars": "off",
|
|
15
|
+
"object-shorthand": "error",
|
|
16
|
+
"prettier/prettier": "error",
|
|
17
|
+
"spaced-comment": "off"
|
|
18
|
+
},
|
|
19
|
+
"settings": {
|
|
20
|
+
"import/resolver": {
|
|
21
|
+
"typescript": {}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
package/README.md
CHANGED
|
@@ -1,141 +1,141 @@
|
|
|
1
|
-
# @memberjunction/server
|
|
2
|
-
|
|
3
|
-
The `@memberjunction/server` library provides a simple way to run the MemberJunction API server. It includes all the functions required to start up the GraphQL server, manage authentication, and connect to the common data store.
|
|
4
|
-
|
|
5
|
-
comprehensive interface for accessing and managing metadata within MemberJunction, along with facilities for working with entities, applications, and various other aspects central to the MemberJunction ecosystem. This library primarily exports a `Metadata` class which acts as the gateway to many functionalities.
|
|
6
|
-
|
|
7
|
-
## Installation
|
|
8
|
-
|
|
9
|
-
```shell
|
|
10
|
-
npm install @memberjunction/server
|
|
11
|
-
```
|
|
12
|
-
|
|
13
|
-
## Configuration
|
|
14
|
-
|
|
15
|
-
The server uses configuration from its environment
|
|
16
|
-
|
|
17
|
-
| Env variable | Description |
|
|
18
|
-
| ------------------------ | ------------------------------------------------------------ |
|
|
19
|
-
| DB_HOST | The hostname for the common data store database |
|
|
20
|
-
| DB_PORT | The port for the common data store database (default 1433) |
|
|
21
|
-
| DB_USERNAME | The username used to authenticate with the common data store |
|
|
22
|
-
| DB_PASSWORD | The password used to authenticate with the common data store |
|
|
23
|
-
| DB_DATABASE | The common data store database name |
|
|
24
|
-
| PORT | The port used by the server (default 4000) |
|
|
25
|
-
| ROOT_PATH | The GraphQL root path (default /) |
|
|
26
|
-
| WEB_CLIENT_ID | The client ID used for MSAL authentication |
|
|
27
|
-
| TENANT_ID | The tenant ID used for MSAL authentication |
|
|
28
|
-
| ENABLE_INTROSPECTION | A flag to allow GraphQL introspection (default false) |
|
|
29
|
-
| WEBSITE_RUN_FROM_PACKAGE | An Azure flag to indicate a read-only file system |
|
|
30
|
-
| AUTH0_DOMAIN | The Auth0 domain |
|
|
31
|
-
| AUTH0_CLIENT_ID | The Auth0 Client ID |
|
|
32
|
-
| AUTH0_CLIENT_SECRET | The Auth0 Client secret |
|
|
33
|
-
| MJ_CORE_SCHEMA | The core schema to use for the data provider |
|
|
34
|
-
| CONFIG_FILE | An absolute path to the config file json |
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
## Usage
|
|
38
|
-
|
|
39
|
-
Import the `serve` function from the package and run it as part of the server's main function. The function accepts an array of absolute paths to the resolver code.
|
|
40
|
-
|
|
41
|
-
```ts
|
|
42
|
-
import { serve } from '@memberjunction/server';
|
|
43
|
-
import { resolve } from 'node:path';
|
|
44
|
-
|
|
45
|
-
const localPath = (p: string) => resolve(__dirname, p);
|
|
46
|
-
|
|
47
|
-
const resolverPaths = [
|
|
48
|
-
'resolvers/**/*Resolver.{js,ts}',
|
|
49
|
-
'generic/*Resolver.{js,ts}',
|
|
50
|
-
'generated/generated.ts',
|
|
51
|
-
]
|
|
52
|
-
|
|
53
|
-
serve(resolverPaths.map(localPath));
|
|
54
|
-
```
|
|
55
|
-
|
|
56
|
-
### Custom New User Behavior
|
|
57
|
-
|
|
58
|
-
The behavior to handle new users can be customized by subclassing the `NewUserBase` class. The subclass can pre-process, post-process or entirely override the base class behavior as needed. Import the class before calling `serve` to ensure the class is registered.
|
|
59
|
-
|
|
60
|
-
`index.ts`
|
|
61
|
-
|
|
62
|
-
```ts
|
|
63
|
-
import { serve } from '@memberjunction/server';
|
|
64
|
-
import { resolve } from 'node:path';
|
|
65
|
-
|
|
66
|
-
import './auth/exampleNewUserSubClass'; // make sure this new class gets registered
|
|
67
|
-
|
|
68
|
-
// ...
|
|
69
|
-
```
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
`auth/exampleNewUserSubClass.ts`
|
|
73
|
-
|
|
74
|
-
```ts
|
|
75
|
-
import { LogError, Metadata, RunView } from "@memberjunction/core";
|
|
76
|
-
import { RegisterClass } from "@memberjunction/global";
|
|
77
|
-
import { NewUserBase, configInfo } from '@memberjunction/server';
|
|
78
|
-
import { UserCache } from "@memberjunction/sqlserver-dataprovider";
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
* This example class subclasses the @NewUserBase class and overrides the createNewUser method to create a new person record and then call the base class to create the user record. In this example there is an entity
|
|
82
|
-
* called "Persons" that is mapped to the User table in the core MemberJunction schema. You can sub-class the NewUserBase to do whatever behavior you want and pre-process, post-process or entirely override the base
|
|
83
|
-
* class behavior.
|
|
84
|
-
*/
|
|
85
|
-
@RegisterClass(NewUserBase, undefined, 1) /*by putting 1 into the priority setting, MJGlobal ClassFactory will use this instead of the base class as that registration had no priority*/
|
|
86
|
-
export class ExampleNewUserSubClass extends NewUserBase {
|
|
87
|
-
public override async createNewUser(firstName: string, lastName: string, email: string) {
|
|
88
|
-
try {
|
|
89
|
-
const md = new Metadata();
|
|
90
|
-
const contextUser = UserCache.Instance.Users.find(u => u.Email.trim().toLowerCase() === configInfo?.userHandling?.contextUserForNewUserCreation?.trim().toLowerCase())
|
|
91
|
-
if(!contextUser) {
|
|
92
|
-
LogError(`Failed to load context user ${configInfo?.userHandling?.contextUserForNewUserCreation}, if you've not specified this on your config.json you must do so. This is the user that is contextually used for creating a new user record dynamically.`);
|
|
93
|
-
return undefined;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
const pEntity = md.Entities.find(e => e.Name === 'Persons'); // look up the entity info for the Persons entity
|
|
97
|
-
if (!pEntity) {
|
|
98
|
-
LogError('Failed to find Persons entity');
|
|
99
|
-
return undefined;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
let personId;
|
|
103
|
-
// this block of code only executes if we have an entity called Persons
|
|
104
|
-
const rv = new RunView();
|
|
105
|
-
const viewResults = await rv.RunView({
|
|
106
|
-
EntityName: 'Persons',
|
|
107
|
-
ExtraFilter: `Email = '${email}'`
|
|
108
|
-
}, contextUser)
|
|
109
|
-
|
|
110
|
-
if (viewResults && viewResults.Success && Array.isArray(viewResults.Results) && viewResults.Results.length > 0) {
|
|
111
|
-
// we have a match so use it
|
|
112
|
-
const row = (viewResults.Results as { ID: number }[])[0]; // we know the rows will have an ID number
|
|
113
|
-
personId = row['ID'];
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
if (!personId) {
|
|
117
|
-
// we don't have a match so create a new person record
|
|
118
|
-
const p = await md.GetEntityObject('Persons', contextUser);
|
|
119
|
-
p.NewRecord(); // assumes we have an entity called Persons that has FirstName/LastName/Email fields
|
|
120
|
-
p.FirstName = firstName;
|
|
121
|
-
p.LastName = lastName;
|
|
122
|
-
p.Email = email;
|
|
123
|
-
p.Status = 'active';
|
|
124
|
-
if (await p.Save()) {
|
|
125
|
-
personId = p.ID;
|
|
126
|
-
}
|
|
127
|
-
else {
|
|
128
|
-
LogError(`Failed to create new person ${firstName} ${lastName} ${email}`)
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
// now call the base class to create the user, and pass in our LinkedRecordType and ID
|
|
133
|
-
return super.createNewUser(firstName, lastName, email, 'Other', pEntity?.ID, personId);
|
|
134
|
-
}
|
|
135
|
-
catch (e) {
|
|
136
|
-
LogError(`Error creating new user ${email} ${e}`);
|
|
137
|
-
return undefined;
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
```
|
|
1
|
+
# @memberjunction/server
|
|
2
|
+
|
|
3
|
+
The `@memberjunction/server` library provides a simple way to run the MemberJunction API server. It includes all the functions required to start up the GraphQL server, manage authentication, and connect to the common data store.
|
|
4
|
+
|
|
5
|
+
comprehensive interface for accessing and managing metadata within MemberJunction, along with facilities for working with entities, applications, and various other aspects central to the MemberJunction ecosystem. This library primarily exports a `Metadata` class which acts as the gateway to many functionalities.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```shell
|
|
10
|
+
npm install @memberjunction/server
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Configuration
|
|
14
|
+
|
|
15
|
+
The server uses configuration from its environment
|
|
16
|
+
|
|
17
|
+
| Env variable | Description |
|
|
18
|
+
| ------------------------ | ------------------------------------------------------------ |
|
|
19
|
+
| DB_HOST | The hostname for the common data store database |
|
|
20
|
+
| DB_PORT | The port for the common data store database (default 1433) |
|
|
21
|
+
| DB_USERNAME | The username used to authenticate with the common data store |
|
|
22
|
+
| DB_PASSWORD | The password used to authenticate with the common data store |
|
|
23
|
+
| DB_DATABASE | The common data store database name |
|
|
24
|
+
| PORT | The port used by the server (default 4000) |
|
|
25
|
+
| ROOT_PATH | The GraphQL root path (default /) |
|
|
26
|
+
| WEB_CLIENT_ID | The client ID used for MSAL authentication |
|
|
27
|
+
| TENANT_ID | The tenant ID used for MSAL authentication |
|
|
28
|
+
| ENABLE_INTROSPECTION | A flag to allow GraphQL introspection (default false) |
|
|
29
|
+
| WEBSITE_RUN_FROM_PACKAGE | An Azure flag to indicate a read-only file system |
|
|
30
|
+
| AUTH0_DOMAIN | The Auth0 domain |
|
|
31
|
+
| AUTH0_CLIENT_ID | The Auth0 Client ID |
|
|
32
|
+
| AUTH0_CLIENT_SECRET | The Auth0 Client secret |
|
|
33
|
+
| MJ_CORE_SCHEMA | The core schema to use for the data provider |
|
|
34
|
+
| CONFIG_FILE | An absolute path to the config file json |
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
## Usage
|
|
38
|
+
|
|
39
|
+
Import the `serve` function from the package and run it as part of the server's main function. The function accepts an array of absolute paths to the resolver code.
|
|
40
|
+
|
|
41
|
+
```ts
|
|
42
|
+
import { serve } from '@memberjunction/server';
|
|
43
|
+
import { resolve } from 'node:path';
|
|
44
|
+
|
|
45
|
+
const localPath = (p: string) => resolve(__dirname, p);
|
|
46
|
+
|
|
47
|
+
const resolverPaths = [
|
|
48
|
+
'resolvers/**/*Resolver.{js,ts}',
|
|
49
|
+
'generic/*Resolver.{js,ts}',
|
|
50
|
+
'generated/generated.ts',
|
|
51
|
+
]
|
|
52
|
+
|
|
53
|
+
serve(resolverPaths.map(localPath));
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
### Custom New User Behavior
|
|
57
|
+
|
|
58
|
+
The behavior to handle new users can be customized by subclassing the `NewUserBase` class. The subclass can pre-process, post-process or entirely override the base class behavior as needed. Import the class before calling `serve` to ensure the class is registered.
|
|
59
|
+
|
|
60
|
+
`index.ts`
|
|
61
|
+
|
|
62
|
+
```ts
|
|
63
|
+
import { serve } from '@memberjunction/server';
|
|
64
|
+
import { resolve } from 'node:path';
|
|
65
|
+
|
|
66
|
+
import './auth/exampleNewUserSubClass'; // make sure this new class gets registered
|
|
67
|
+
|
|
68
|
+
// ...
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
`auth/exampleNewUserSubClass.ts`
|
|
73
|
+
|
|
74
|
+
```ts
|
|
75
|
+
import { LogError, Metadata, RunView } from "@memberjunction/core";
|
|
76
|
+
import { RegisterClass } from "@memberjunction/global";
|
|
77
|
+
import { NewUserBase, configInfo } from '@memberjunction/server';
|
|
78
|
+
import { UserCache } from "@memberjunction/sqlserver-dataprovider";
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* This example class subclasses the @NewUserBase class and overrides the createNewUser method to create a new person record and then call the base class to create the user record. In this example there is an entity
|
|
82
|
+
* called "Persons" that is mapped to the User table in the core MemberJunction schema. You can sub-class the NewUserBase to do whatever behavior you want and pre-process, post-process or entirely override the base
|
|
83
|
+
* class behavior.
|
|
84
|
+
*/
|
|
85
|
+
@RegisterClass(NewUserBase, undefined, 1) /*by putting 1 into the priority setting, MJGlobal ClassFactory will use this instead of the base class as that registration had no priority*/
|
|
86
|
+
export class ExampleNewUserSubClass extends NewUserBase {
|
|
87
|
+
public override async createNewUser(firstName: string, lastName: string, email: string) {
|
|
88
|
+
try {
|
|
89
|
+
const md = new Metadata();
|
|
90
|
+
const contextUser = UserCache.Instance.Users.find(u => u.Email.trim().toLowerCase() === configInfo?.userHandling?.contextUserForNewUserCreation?.trim().toLowerCase())
|
|
91
|
+
if(!contextUser) {
|
|
92
|
+
LogError(`Failed to load context user ${configInfo?.userHandling?.contextUserForNewUserCreation}, if you've not specified this on your config.json you must do so. This is the user that is contextually used for creating a new user record dynamically.`);
|
|
93
|
+
return undefined;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const pEntity = md.Entities.find(e => e.Name === 'Persons'); // look up the entity info for the Persons entity
|
|
97
|
+
if (!pEntity) {
|
|
98
|
+
LogError('Failed to find Persons entity');
|
|
99
|
+
return undefined;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
let personId;
|
|
103
|
+
// this block of code only executes if we have an entity called Persons
|
|
104
|
+
const rv = new RunView();
|
|
105
|
+
const viewResults = await rv.RunView({
|
|
106
|
+
EntityName: 'Persons',
|
|
107
|
+
ExtraFilter: `Email = '${email}'`
|
|
108
|
+
}, contextUser)
|
|
109
|
+
|
|
110
|
+
if (viewResults && viewResults.Success && Array.isArray(viewResults.Results) && viewResults.Results.length > 0) {
|
|
111
|
+
// we have a match so use it
|
|
112
|
+
const row = (viewResults.Results as { ID: number }[])[0]; // we know the rows will have an ID number
|
|
113
|
+
personId = row['ID'];
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
if (!personId) {
|
|
117
|
+
// we don't have a match so create a new person record
|
|
118
|
+
const p = await md.GetEntityObject('Persons', contextUser);
|
|
119
|
+
p.NewRecord(); // assumes we have an entity called Persons that has FirstName/LastName/Email fields
|
|
120
|
+
p.FirstName = firstName;
|
|
121
|
+
p.LastName = lastName;
|
|
122
|
+
p.Email = email;
|
|
123
|
+
p.Status = 'active';
|
|
124
|
+
if (await p.Save()) {
|
|
125
|
+
personId = p.ID;
|
|
126
|
+
}
|
|
127
|
+
else {
|
|
128
|
+
LogError(`Failed to create new person ${firstName} ${lastName} ${email}`)
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// now call the base class to create the user, and pass in our LinkedRecordType and ID
|
|
133
|
+
return super.createNewUser(firstName, lastName, email, 'Other', pEntity?.ID, personId);
|
|
134
|
+
}
|
|
135
|
+
catch (e) {
|
|
136
|
+
LogError(`Error creating new user ${email} ${e}`);
|
|
137
|
+
return undefined;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
```
|
|
@@ -1,46 +1,46 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.TransactionPlugin = void 0;
|
|
4
|
-
exports.TransactionPlugin = {
|
|
5
|
-
async requestDidStart(requestContext) {
|
|
6
|
-
const start = Date.now();
|
|
7
|
-
const query = requestContext.request.query || '';
|
|
8
|
-
const isMutation = /^\s*mutation\b/i.test(query);
|
|
9
|
-
if (!isMutation) {
|
|
10
|
-
return;
|
|
11
|
-
}
|
|
12
|
-
const dataSource = requestContext.contextValue.dataSource;
|
|
13
|
-
const queryRunner = dataSource.createQueryRunner();
|
|
14
|
-
requestContext.contextValue.queryRunner = queryRunner;
|
|
15
|
-
console.log('Starting transaction wrapper, time spent: ', Date.now() - start, 'ms ');
|
|
16
|
-
await queryRunner.startTransaction();
|
|
17
|
-
return {
|
|
18
|
-
executionDidStart: async () => {
|
|
19
|
-
return {
|
|
20
|
-
executionDidEnd: async (err) => {
|
|
21
|
-
try {
|
|
22
|
-
if (err) {
|
|
23
|
-
console.log('Error in transaction, rolling back, time spent: ', Date.now() - start, 'ms ');
|
|
24
|
-
console.error('Rolling back transaction', err);
|
|
25
|
-
await queryRunner.rollbackTransaction();
|
|
26
|
-
}
|
|
27
|
-
else {
|
|
28
|
-
console.log('Committing transaction, time spent: ', Date.now() - start, 'ms ');
|
|
29
|
-
await queryRunner.commitTransaction();
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
catch (execErr) {
|
|
33
|
-
console.log('Execution Error, time spent: ', Date.now() - start, 'ms ');
|
|
34
|
-
console.error(execErr);
|
|
35
|
-
}
|
|
36
|
-
finally {
|
|
37
|
-
await queryRunner.release();
|
|
38
|
-
console.log('Transaction complete, time spent: ', Date.now() - start, 'ms ');
|
|
39
|
-
}
|
|
40
|
-
},
|
|
41
|
-
};
|
|
42
|
-
},
|
|
43
|
-
};
|
|
44
|
-
},
|
|
45
|
-
};
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TransactionPlugin = void 0;
|
|
4
|
+
exports.TransactionPlugin = {
|
|
5
|
+
async requestDidStart(requestContext) {
|
|
6
|
+
const start = Date.now();
|
|
7
|
+
const query = requestContext.request.query || '';
|
|
8
|
+
const isMutation = /^\s*mutation\b/i.test(query);
|
|
9
|
+
if (!isMutation) {
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
const dataSource = requestContext.contextValue.dataSource;
|
|
13
|
+
const queryRunner = dataSource.createQueryRunner();
|
|
14
|
+
requestContext.contextValue.queryRunner = queryRunner;
|
|
15
|
+
console.log('Starting transaction wrapper, time spent: ', Date.now() - start, 'ms ');
|
|
16
|
+
await queryRunner.startTransaction();
|
|
17
|
+
return {
|
|
18
|
+
executionDidStart: async () => {
|
|
19
|
+
return {
|
|
20
|
+
executionDidEnd: async (err) => {
|
|
21
|
+
try {
|
|
22
|
+
if (err) {
|
|
23
|
+
console.log('Error in transaction, rolling back, time spent: ', Date.now() - start, 'ms ');
|
|
24
|
+
console.error('Rolling back transaction', err);
|
|
25
|
+
await queryRunner.rollbackTransaction();
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
console.log('Committing transaction, time spent: ', Date.now() - start, 'ms ');
|
|
29
|
+
await queryRunner.commitTransaction();
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
catch (execErr) {
|
|
33
|
+
console.log('Execution Error, time spent: ', Date.now() - start, 'ms ');
|
|
34
|
+
console.error(execErr);
|
|
35
|
+
}
|
|
36
|
+
finally {
|
|
37
|
+
await queryRunner.release();
|
|
38
|
+
console.log('Transaction complete, time spent: ', Date.now() - start, 'ms ');
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
46
|
//# sourceMappingURL=TransactionPlugin.js.map
|
|
@@ -1,27 +1,27 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const server_1 = require("@apollo/server");
|
|
4
|
-
const drainHttpServer_1 = require("@apollo/server/plugin/drainHttpServer");
|
|
5
|
-
const config_1 = require("../config");
|
|
6
|
-
const TransactionPlugin_1 = require("./TransactionPlugin");
|
|
7
|
-
const buildApolloServer = (configOverride, { httpServer, serverCleanup }) => new server_1.ApolloServer({
|
|
8
|
-
csrfPrevention: true,
|
|
9
|
-
cache: 'bounded',
|
|
10
|
-
plugins: [
|
|
11
|
-
(0, drainHttpServer_1.ApolloServerPluginDrainHttpServer)({ httpServer }),
|
|
12
|
-
TransactionPlugin_1.TransactionPlugin,
|
|
13
|
-
{
|
|
14
|
-
async serverWillStart() {
|
|
15
|
-
return {
|
|
16
|
-
async drainServer() {
|
|
17
|
-
await serverCleanup.dispose();
|
|
18
|
-
},
|
|
19
|
-
};
|
|
20
|
-
},
|
|
21
|
-
},
|
|
22
|
-
],
|
|
23
|
-
introspection: config_1.enableIntrospection,
|
|
24
|
-
...configOverride,
|
|
25
|
-
});
|
|
26
|
-
exports.default = buildApolloServer;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const server_1 = require("@apollo/server");
|
|
4
|
+
const drainHttpServer_1 = require("@apollo/server/plugin/drainHttpServer");
|
|
5
|
+
const config_1 = require("../config");
|
|
6
|
+
const TransactionPlugin_1 = require("./TransactionPlugin");
|
|
7
|
+
const buildApolloServer = (configOverride, { httpServer, serverCleanup }) => new server_1.ApolloServer({
|
|
8
|
+
csrfPrevention: true,
|
|
9
|
+
cache: 'bounded',
|
|
10
|
+
plugins: [
|
|
11
|
+
(0, drainHttpServer_1.ApolloServerPluginDrainHttpServer)({ httpServer }),
|
|
12
|
+
TransactionPlugin_1.TransactionPlugin,
|
|
13
|
+
{
|
|
14
|
+
async serverWillStart() {
|
|
15
|
+
return {
|
|
16
|
+
async drainServer() {
|
|
17
|
+
await serverCleanup.dispose();
|
|
18
|
+
},
|
|
19
|
+
};
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
],
|
|
23
|
+
introspection: config_1.enableIntrospection,
|
|
24
|
+
...configOverride,
|
|
25
|
+
});
|
|
26
|
+
exports.default = buildApolloServer;
|
|
27
27
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,68 +1,68 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
-
};
|
|
8
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.LoadExampleNewUserSubClass = exports.ExampleNewUserSubClass = void 0;
|
|
10
|
-
const global_1 = require("@memberjunction/global");
|
|
11
|
-
const core_1 = require("@memberjunction/core");
|
|
12
|
-
const newUsers_1 = require("./newUsers");
|
|
13
|
-
const sqlserver_dataprovider_1 = require("@memberjunction/sqlserver-dataprovider");
|
|
14
|
-
const config_1 = require("../config");
|
|
15
|
-
let ExampleNewUserSubClass = class ExampleNewUserSubClass extends newUsers_1.NewUserBase {
|
|
16
|
-
async createNewUser(firstName, lastName, email) {
|
|
17
|
-
try {
|
|
18
|
-
const md = new core_1.Metadata();
|
|
19
|
-
const contextUser = sqlserver_dataprovider_1.UserCache.Instance.Users.find(u => u.Email.trim().toLowerCase() === config_1.configInfo?.userHandling?.contextUserForNewUserCreation?.trim().toLowerCase());
|
|
20
|
-
if (!contextUser) {
|
|
21
|
-
(0, core_1.LogError)(`Failed to load context user ${config_1.configInfo?.userHandling?.contextUserForNewUserCreation}, if you've not specified this on your config.json you must do so. This is the user that is contextually used for creating a new user record dynamically.`);
|
|
22
|
-
return undefined;
|
|
23
|
-
}
|
|
24
|
-
const pEntity = md.Entities.find(e => e.Name === 'Persons');
|
|
25
|
-
if (!pEntity) {
|
|
26
|
-
(0, core_1.LogError)('Failed to find Persons entity');
|
|
27
|
-
return undefined;
|
|
28
|
-
}
|
|
29
|
-
let personId;
|
|
30
|
-
const rv = new core_1.RunView();
|
|
31
|
-
const viewResults = await rv.RunView({
|
|
32
|
-
EntityName: 'Persons',
|
|
33
|
-
ExtraFilter: `Email = '${email}'`
|
|
34
|
-
}, contextUser);
|
|
35
|
-
if (viewResults && viewResults.Success && Array.isArray(viewResults.Results) && viewResults.Results.length > 0) {
|
|
36
|
-
const row = viewResults.Results[0];
|
|
37
|
-
personId = row['ID'];
|
|
38
|
-
}
|
|
39
|
-
if (!personId) {
|
|
40
|
-
const p = await md.GetEntityObject('Persons', contextUser);
|
|
41
|
-
p.NewRecord();
|
|
42
|
-
p.FirstName = firstName;
|
|
43
|
-
p.LastName = lastName;
|
|
44
|
-
p.Email = email;
|
|
45
|
-
p.Status = 'active';
|
|
46
|
-
if (await p.Save()) {
|
|
47
|
-
personId = p.ID;
|
|
48
|
-
}
|
|
49
|
-
else {
|
|
50
|
-
(0, core_1.LogError)(`Failed to create new person ${firstName} ${lastName} ${email}`);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
return super.createNewUser(firstName, lastName, email, 'Other', pEntity?.ID, personId);
|
|
54
|
-
}
|
|
55
|
-
catch (e) {
|
|
56
|
-
(0, core_1.LogError)(`Error creating new user ${email} ${e}`);
|
|
57
|
-
return undefined;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
};
|
|
61
|
-
ExampleNewUserSubClass = __decorate([
|
|
62
|
-
(0, global_1.RegisterClass)(newUsers_1.NewUserBase, undefined, 1)
|
|
63
|
-
], ExampleNewUserSubClass);
|
|
64
|
-
exports.ExampleNewUserSubClass = ExampleNewUserSubClass;
|
|
65
|
-
function LoadExampleNewUserSubClass() {
|
|
66
|
-
}
|
|
67
|
-
exports.LoadExampleNewUserSubClass = LoadExampleNewUserSubClass;
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.LoadExampleNewUserSubClass = exports.ExampleNewUserSubClass = void 0;
|
|
10
|
+
const global_1 = require("@memberjunction/global");
|
|
11
|
+
const core_1 = require("@memberjunction/core");
|
|
12
|
+
const newUsers_1 = require("./newUsers");
|
|
13
|
+
const sqlserver_dataprovider_1 = require("@memberjunction/sqlserver-dataprovider");
|
|
14
|
+
const config_1 = require("../config");
|
|
15
|
+
let ExampleNewUserSubClass = class ExampleNewUserSubClass extends newUsers_1.NewUserBase {
|
|
16
|
+
async createNewUser(firstName, lastName, email) {
|
|
17
|
+
try {
|
|
18
|
+
const md = new core_1.Metadata();
|
|
19
|
+
const contextUser = sqlserver_dataprovider_1.UserCache.Instance.Users.find(u => u.Email.trim().toLowerCase() === config_1.configInfo?.userHandling?.contextUserForNewUserCreation?.trim().toLowerCase());
|
|
20
|
+
if (!contextUser) {
|
|
21
|
+
(0, core_1.LogError)(`Failed to load context user ${config_1.configInfo?.userHandling?.contextUserForNewUserCreation}, if you've not specified this on your config.json you must do so. This is the user that is contextually used for creating a new user record dynamically.`);
|
|
22
|
+
return undefined;
|
|
23
|
+
}
|
|
24
|
+
const pEntity = md.Entities.find(e => e.Name === 'Persons');
|
|
25
|
+
if (!pEntity) {
|
|
26
|
+
(0, core_1.LogError)('Failed to find Persons entity');
|
|
27
|
+
return undefined;
|
|
28
|
+
}
|
|
29
|
+
let personId;
|
|
30
|
+
const rv = new core_1.RunView();
|
|
31
|
+
const viewResults = await rv.RunView({
|
|
32
|
+
EntityName: 'Persons',
|
|
33
|
+
ExtraFilter: `Email = '${email}'`
|
|
34
|
+
}, contextUser);
|
|
35
|
+
if (viewResults && viewResults.Success && Array.isArray(viewResults.Results) && viewResults.Results.length > 0) {
|
|
36
|
+
const row = viewResults.Results[0];
|
|
37
|
+
personId = row['ID'];
|
|
38
|
+
}
|
|
39
|
+
if (!personId) {
|
|
40
|
+
const p = await md.GetEntityObject('Persons', contextUser);
|
|
41
|
+
p.NewRecord();
|
|
42
|
+
p.FirstName = firstName;
|
|
43
|
+
p.LastName = lastName;
|
|
44
|
+
p.Email = email;
|
|
45
|
+
p.Status = 'active';
|
|
46
|
+
if (await p.Save()) {
|
|
47
|
+
personId = p.ID;
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
(0, core_1.LogError)(`Failed to create new person ${firstName} ${lastName} ${email}`);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return super.createNewUser(firstName, lastName, email, 'Other', pEntity?.ID, personId);
|
|
54
|
+
}
|
|
55
|
+
catch (e) {
|
|
56
|
+
(0, core_1.LogError)(`Error creating new user ${email} ${e}`);
|
|
57
|
+
return undefined;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
ExampleNewUserSubClass = __decorate([
|
|
62
|
+
(0, global_1.RegisterClass)(newUsers_1.NewUserBase, undefined, 1)
|
|
63
|
+
], ExampleNewUserSubClass);
|
|
64
|
+
exports.ExampleNewUserSubClass = ExampleNewUserSubClass;
|
|
65
|
+
function LoadExampleNewUserSubClass() {
|
|
66
|
+
}
|
|
67
|
+
exports.LoadExampleNewUserSubClass = LoadExampleNewUserSubClass;
|
|
68
68
|
//# sourceMappingURL=exampleNewUserSubClass.js.map
|