@memberjunction/server 0.9.75 → 0.9.77

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.
@@ -1,105 +1,105 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.verifyUserRecord = exports.getSigningKeys = exports.UserPayload = exports.validationOptions = void 0;
7
- const jwks_rsa_1 = __importDefault(require("jwks-rsa"));
8
- const config_1 = require("../config");
9
- const sqlserver_dataprovider_1 = require("@memberjunction/sqlserver-dataprovider");
10
- const core_1 = require("@memberjunction/core");
11
- const newUsers_1 = require("./newUsers");
12
- const global_1 = require("@memberjunction/global");
13
- const missingAzureConfig = !config_1.tenantID || !config_1.webClientID;
14
- const missingAuth0Config = !config_1.auth0Domain || !config_1.auth0WebClientID;
15
- class MissingAuthError extends Error {
16
- constructor() {
17
- super('Could not find authentication configuration for either MSAL or Auth0 in the server environment variables.');
18
- this.name = 'MissingAuthError';
19
- }
20
- }
21
- const issuers = {
22
- azure: `https://login.microsoftonline.com/${config_1.tenantID}/v2.0`,
23
- auth0: `https://${config_1.auth0Domain}/`,
24
- };
25
- exports.validationOptions = {
26
- [issuers.auth0]: {
27
- audience: config_1.auth0WebClientID,
28
- jwksUri: `https://${config_1.auth0Domain}/.well-known/jwks.json`,
29
- },
30
- [issuers.azure]: {
31
- audience: config_1.webClientID,
32
- jwksUri: `https://login.microsoftonline.com/${config_1.tenantID}/discovery/v2.0/keys`,
33
- },
34
- };
35
- class UserPayload {
36
- }
37
- exports.UserPayload = UserPayload;
38
- const getSigningKeys = (issuer) => (header, cb) => {
39
- const jwksUri = exports.validationOptions[issuer].jwksUri;
40
- if (missingAuth0Config && missingAzureConfig) {
41
- throw new MissingAuthError();
42
- }
43
- if (missingAuth0Config) {
44
- console.warn('Auth0 configuration not found in environment variables');
45
- }
46
- if (missingAzureConfig) {
47
- console.warn('MSAL configuration not found in environment variables');
48
- }
49
- (0, jwks_rsa_1.default)({ jwksUri })
50
- .getSigningKey(header.kid)
51
- .then((key) => {
52
- cb(null, 'publicKey' in key ? key.publicKey : key.rsaPublicKey);
53
- })
54
- .catch((err) => console.error(err));
55
- };
56
- exports.getSigningKeys = getSigningKeys;
57
- const verifyUserRecord = async (email, firstName, lastName, requestDomain, dataSource, attemptCacheUpdateIfNeeded = true) => {
58
- if (!email)
59
- return undefined;
60
- let user = sqlserver_dataprovider_1.UserCache.Instance.Users.find((u) => {
61
- if (!u.Email || u.Email.trim() === '') {
62
- console.error(`SYSTEM METADATA ISSUE: User ${u.ID} has no email address`);
63
- return false;
64
- }
65
- else
66
- return u.Email.toLowerCase().trim() === email.toLowerCase().trim();
67
- });
68
- if (!user) {
69
- if (config_1.configInfo.userHandling.autoCreateNewUsers && firstName && lastName && requestDomain) {
70
- const domainMatch = config_1.configInfo.userHandling.newUserAuthorizedDomains.some((domain) => domain.toLowerCase().trim() === requestDomain.toLowerCase().trim());
71
- if (domainMatch) {
72
- console.warn(`User ${email} not found in cache. Attempting to create a new user...`);
73
- const newUserCreator = global_1.MJGlobal.Instance.ClassFactory.CreateInstance(newUsers_1.NewUserBase);
74
- const newUser = await newUserCreator.createNewUser(firstName, lastName, email);
75
- if (newUser) {
76
- const initData = newUser.GetAll();
77
- initData.UserRoles = config_1.configInfo.userHandling.newUserRoles.map((role) => { return { UserID: initData.ID, RoleName: role }; });
78
- user = new core_1.UserInfo(core_1.Metadata.Provider, initData);
79
- sqlserver_dataprovider_1.UserCache.Instance.Users.push(user);
80
- console.warn(` >>> New user ${email} created successfully!`);
81
- }
82
- }
83
- else {
84
- console.warn(`User ${email} not found in cache. Request domain '${requestDomain}' does not match any of the domains in the newUserAuthorizedDomains setting. NOT creating a new user.`);
85
- }
86
- }
87
- if (!user && config_1.configInfo.userHandling.updateCacheWhenNotFound && dataSource && attemptCacheUpdateIfNeeded) {
88
- console.warn(`User ${email} not found in cache. Updating cache in attempt to find the user...`);
89
- const startTime = Date.now();
90
- await sqlserver_dataprovider_1.UserCache.Instance.Refresh(dataSource);
91
- const endTime = Date.now();
92
- const elapsed = endTime - startTime;
93
- const delay = config_1.configInfo.userHandling.updateCacheWhenNotFoundDelay ? (config_1.configInfo.userHandling.updateCacheWhenNotFoundDelay < 30000 ? config_1.configInfo.userHandling.updateCacheWhenNotFoundDelay : 30000) : 0;
94
- if (elapsed < delay)
95
- await new Promise(resolve => setTimeout(resolve, delay - elapsed));
96
- const finalTime = Date.now();
97
- const finalElapsed = finalTime - startTime;
98
- console.log(` UserCache updated in ${elapsed}ms, total elapsed time of ${finalElapsed}ms including delay of ${delay}ms (if needed). Attempting to find the user again via recursive call to verifyUserRecord()`);
99
- return (0, exports.verifyUserRecord)(email, firstName, lastName, requestDomain, dataSource, false);
100
- }
101
- }
102
- return user;
103
- };
104
- exports.verifyUserRecord = verifyUserRecord;
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.verifyUserRecord = exports.getSigningKeys = exports.UserPayload = exports.validationOptions = void 0;
7
+ const jwks_rsa_1 = __importDefault(require("jwks-rsa"));
8
+ const config_1 = require("../config");
9
+ const sqlserver_dataprovider_1 = require("@memberjunction/sqlserver-dataprovider");
10
+ const core_1 = require("@memberjunction/core");
11
+ const newUsers_1 = require("./newUsers");
12
+ const global_1 = require("@memberjunction/global");
13
+ const missingAzureConfig = !config_1.tenantID || !config_1.webClientID;
14
+ const missingAuth0Config = !config_1.auth0Domain || !config_1.auth0WebClientID;
15
+ class MissingAuthError extends Error {
16
+ constructor() {
17
+ super('Could not find authentication configuration for either MSAL or Auth0 in the server environment variables.');
18
+ this.name = 'MissingAuthError';
19
+ }
20
+ }
21
+ const issuers = {
22
+ azure: `https://login.microsoftonline.com/${config_1.tenantID}/v2.0`,
23
+ auth0: `https://${config_1.auth0Domain}/`,
24
+ };
25
+ exports.validationOptions = {
26
+ [issuers.auth0]: {
27
+ audience: config_1.auth0WebClientID,
28
+ jwksUri: `https://${config_1.auth0Domain}/.well-known/jwks.json`,
29
+ },
30
+ [issuers.azure]: {
31
+ audience: config_1.webClientID,
32
+ jwksUri: `https://login.microsoftonline.com/${config_1.tenantID}/discovery/v2.0/keys`,
33
+ },
34
+ };
35
+ class UserPayload {
36
+ }
37
+ exports.UserPayload = UserPayload;
38
+ const getSigningKeys = (issuer) => (header, cb) => {
39
+ const jwksUri = exports.validationOptions[issuer].jwksUri;
40
+ if (missingAuth0Config && missingAzureConfig) {
41
+ throw new MissingAuthError();
42
+ }
43
+ if (missingAuth0Config) {
44
+ console.warn('Auth0 configuration not found in environment variables');
45
+ }
46
+ if (missingAzureConfig) {
47
+ console.warn('MSAL configuration not found in environment variables');
48
+ }
49
+ (0, jwks_rsa_1.default)({ jwksUri })
50
+ .getSigningKey(header.kid)
51
+ .then((key) => {
52
+ cb(null, 'publicKey' in key ? key.publicKey : key.rsaPublicKey);
53
+ })
54
+ .catch((err) => console.error(err));
55
+ };
56
+ exports.getSigningKeys = getSigningKeys;
57
+ const verifyUserRecord = async (email, firstName, lastName, requestDomain, dataSource, attemptCacheUpdateIfNeeded = true) => {
58
+ if (!email)
59
+ return undefined;
60
+ let user = sqlserver_dataprovider_1.UserCache.Instance.Users.find((u) => {
61
+ if (!u.Email || u.Email.trim() === '') {
62
+ console.error(`SYSTEM METADATA ISSUE: User ${u.ID} has no email address`);
63
+ return false;
64
+ }
65
+ else
66
+ return u.Email.toLowerCase().trim() === email.toLowerCase().trim();
67
+ });
68
+ if (!user) {
69
+ if (config_1.configInfo.userHandling.autoCreateNewUsers && firstName && lastName && requestDomain) {
70
+ const domainMatch = config_1.configInfo.userHandling.newUserAuthorizedDomains.some((domain) => domain.toLowerCase().trim() === requestDomain.toLowerCase().trim());
71
+ if (domainMatch) {
72
+ console.warn(`User ${email} not found in cache. Attempting to create a new user...`);
73
+ const newUserCreator = global_1.MJGlobal.Instance.ClassFactory.CreateInstance(newUsers_1.NewUserBase);
74
+ const newUser = await newUserCreator.createNewUser(firstName, lastName, email);
75
+ if (newUser) {
76
+ const initData = newUser.GetAll();
77
+ initData.UserRoles = config_1.configInfo.userHandling.newUserRoles.map((role) => { return { UserID: initData.ID, RoleName: role }; });
78
+ user = new core_1.UserInfo(core_1.Metadata.Provider, initData);
79
+ sqlserver_dataprovider_1.UserCache.Instance.Users.push(user);
80
+ console.warn(` >>> New user ${email} created successfully!`);
81
+ }
82
+ }
83
+ else {
84
+ console.warn(`User ${email} not found in cache. Request domain '${requestDomain}' does not match any of the domains in the newUserAuthorizedDomains setting. NOT creating a new user.`);
85
+ }
86
+ }
87
+ if (!user && config_1.configInfo.userHandling.updateCacheWhenNotFound && dataSource && attemptCacheUpdateIfNeeded) {
88
+ console.warn(`User ${email} not found in cache. Updating cache in attempt to find the user...`);
89
+ const startTime = Date.now();
90
+ await sqlserver_dataprovider_1.UserCache.Instance.Refresh(dataSource);
91
+ const endTime = Date.now();
92
+ const elapsed = endTime - startTime;
93
+ const delay = config_1.configInfo.userHandling.updateCacheWhenNotFoundDelay ? (config_1.configInfo.userHandling.updateCacheWhenNotFoundDelay < 30000 ? config_1.configInfo.userHandling.updateCacheWhenNotFoundDelay : 30000) : 0;
94
+ if (elapsed < delay)
95
+ await new Promise(resolve => setTimeout(resolve, delay - elapsed));
96
+ const finalTime = Date.now();
97
+ const finalElapsed = finalTime - startTime;
98
+ console.log(` UserCache updated in ${elapsed}ms, total elapsed time of ${finalElapsed}ms including delay of ${delay}ms (if needed). Attempting to find the user again via recursive call to verifyUserRecord()`);
99
+ return (0, exports.verifyUserRecord)(email, firstName, lastName, requestDomain, dataSource, false);
100
+ }
101
+ }
102
+ return user;
103
+ };
104
+ exports.verifyUserRecord = verifyUserRecord;
105
105
  //# sourceMappingURL=index.js.map
@@ -1,67 +1,67 @@
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
- var NewUserBase_1;
9
- Object.defineProperty(exports, "__esModule", { value: true });
10
- exports.NewUserBase = void 0;
11
- const core_1 = require("@memberjunction/core");
12
- const global_1 = require("@memberjunction/global");
13
- const sqlserver_dataprovider_1 = require("@memberjunction/sqlserver-dataprovider");
14
- const config_1 = require("../config");
15
- let NewUserBase = NewUserBase_1 = class NewUserBase {
16
- async createNewUser(firstName, lastName, email, linkedRecordType = 'None', linkedEntityId, linkedEntityRecordId) {
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 u = await md.GetEntityObject('Users', contextUser);
25
- u.NewRecord();
26
- u.Name = email;
27
- u.IsActive = true;
28
- u.FirstName = firstName;
29
- u.LastName = lastName;
30
- u.Email = email;
31
- u.Type = 'User';
32
- u.LinkedRecordType = linkedRecordType;
33
- if (linkedEntityId)
34
- u.LinkedEntityID = linkedEntityId;
35
- if (linkedEntityRecordId)
36
- u.LinkedEntityRecordID = linkedEntityRecordId;
37
- if (await u.Save()) {
38
- const ur = await md.GetEntityObject('User Roles', contextUser);
39
- let bSuccess = true;
40
- for (const role of config_1.configInfo.userHandling.newUserRoles) {
41
- ur.NewRecord();
42
- ur.UserID = u.ID;
43
- ur.RoleName = role;
44
- bSuccess = bSuccess && await ur.Save();
45
- }
46
- if (!bSuccess) {
47
- (0, core_1.LogError)(`Failed to create roles for newly created user ${firstName} ${lastName} ${email}`);
48
- return undefined;
49
- }
50
- }
51
- else {
52
- (0, core_1.LogError)(`Failed to create new user ${firstName} ${lastName} ${email}`);
53
- return undefined;
54
- }
55
- return u;
56
- }
57
- catch (e) {
58
- (0, core_1.LogError)(e);
59
- return undefined;
60
- }
61
- }
62
- };
63
- NewUserBase = NewUserBase_1 = __decorate([
64
- (0, global_1.RegisterClass)(NewUserBase_1)
65
- ], NewUserBase);
66
- exports.NewUserBase = NewUserBase;
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
+ var NewUserBase_1;
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.NewUserBase = void 0;
11
+ const core_1 = require("@memberjunction/core");
12
+ const global_1 = require("@memberjunction/global");
13
+ const sqlserver_dataprovider_1 = require("@memberjunction/sqlserver-dataprovider");
14
+ const config_1 = require("../config");
15
+ let NewUserBase = NewUserBase_1 = class NewUserBase {
16
+ async createNewUser(firstName, lastName, email, linkedRecordType = 'None', linkedEntityId, linkedEntityRecordId) {
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 u = await md.GetEntityObject('Users', contextUser);
25
+ u.NewRecord();
26
+ u.Name = email;
27
+ u.IsActive = true;
28
+ u.FirstName = firstName;
29
+ u.LastName = lastName;
30
+ u.Email = email;
31
+ u.Type = 'User';
32
+ u.LinkedRecordType = linkedRecordType;
33
+ if (linkedEntityId)
34
+ u.LinkedEntityID = linkedEntityId;
35
+ if (linkedEntityRecordId)
36
+ u.LinkedEntityRecordID = linkedEntityRecordId;
37
+ if (await u.Save()) {
38
+ const ur = await md.GetEntityObject('User Roles', contextUser);
39
+ let bSuccess = true;
40
+ for (const role of config_1.configInfo.userHandling.newUserRoles) {
41
+ ur.NewRecord();
42
+ ur.UserID = u.ID;
43
+ ur.RoleName = role;
44
+ bSuccess = bSuccess && await ur.Save();
45
+ }
46
+ if (!bSuccess) {
47
+ (0, core_1.LogError)(`Failed to create roles for newly created user ${firstName} ${lastName} ${email}`);
48
+ return undefined;
49
+ }
50
+ }
51
+ else {
52
+ (0, core_1.LogError)(`Failed to create new user ${firstName} ${lastName} ${email}`);
53
+ return undefined;
54
+ }
55
+ return u;
56
+ }
57
+ catch (e) {
58
+ (0, core_1.LogError)(e);
59
+ return undefined;
60
+ }
61
+ }
62
+ };
63
+ NewUserBase = NewUserBase_1 = __decorate([
64
+ (0, global_1.RegisterClass)(NewUserBase_1)
65
+ ], NewUserBase);
66
+ exports.NewUserBase = NewUserBase;
67
67
  //# sourceMappingURL=newUsers.js.map
package/dist/cache.js CHANGED
@@ -1,11 +1,11 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.authCache = void 0;
4
- const lru_cache_1 = require("lru-cache");
5
- const oneHourMs = 60 * 60 * 1000;
6
- exports.authCache = new lru_cache_1.LRUCache({
7
- max: 50000,
8
- ttl: oneHourMs,
9
- ttlAutopurge: false,
10
- });
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.authCache = void 0;
4
+ const lru_cache_1 = require("lru-cache");
5
+ const oneHourMs = 60 * 60 * 1000;
6
+ exports.authCache = new lru_cache_1.LRUCache({
7
+ max: 50000,
8
+ ttl: oneHourMs,
9
+ ttlAutopurge: false,
10
+ });
11
11
  //# sourceMappingURL=cache.js.map
package/dist/config.js CHANGED
@@ -1,62 +1,62 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.loadConfig = exports.configInfo = exports.configFile = exports.mj_core_schema = exports.auth0ClientSecret = exports.auth0WebClientID = exports.auth0Domain = exports.userEmailMap = exports.websiteRunFromPackage = exports.enableIntrospection = exports.tenantID = exports.webClientID = exports.graphqlRootPath = exports.graphqlPort = exports.dbTrustServerCertificate = exports.dbInstanceName = exports.dbDatabase = exports.dbPassword = exports.dbUsername = exports.dbPort = exports.dbHost = exports.nodeEnv = void 0;
7
- const env_var_1 = __importDefault(require("env-var"));
8
- const fs_1 = __importDefault(require("fs"));
9
- const path_1 = __importDefault(require("path"));
10
- const zod_1 = require("zod");
11
- exports.nodeEnv = env_var_1.default.get('NODE_ENV').asString();
12
- exports.dbHost = env_var_1.default.get('DB_HOST').required().asString();
13
- exports.dbPort = env_var_1.default.get('DB_PORT').default('1433').asPortNumber();
14
- exports.dbUsername = env_var_1.default.get('DB_USERNAME').required().asString();
15
- exports.dbPassword = env_var_1.default.get('DB_PASSWORD').required().asString();
16
- exports.dbDatabase = env_var_1.default.get('DB_DATABASE').required().asString();
17
- exports.dbInstanceName = env_var_1.default.get('DB_INSTANCE_NAME').asString();
18
- exports.dbTrustServerCertificate = env_var_1.default.get('DB_TRUST_SERVER_CERTIFICATE').asBool();
19
- exports.graphqlPort = env_var_1.default.get('PORT').default('4000').asPortNumber();
20
- exports.graphqlRootPath = env_var_1.default.get('ROOT_PATH').default('/').asString();
21
- exports.webClientID = env_var_1.default.get('WEB_CLIENT_ID').asString();
22
- exports.tenantID = env_var_1.default.get('TENANT_ID').asString();
23
- exports.enableIntrospection = env_var_1.default.get('ENABLE_INTROSPECTION').default('false').asBool();
24
- exports.websiteRunFromPackage = env_var_1.default.get('WEBSITE_RUN_FROM_PACKAGE').asIntPositive();
25
- exports.userEmailMap = env_var_1.default.get('USER_EMAIL_MAP').default('{}').asJsonObject();
26
- exports.auth0Domain = env_var_1.default.get('AUTH0_DOMAIN').asString();
27
- exports.auth0WebClientID = env_var_1.default.get('AUTH0_CLIENT_ID').asString();
28
- exports.auth0ClientSecret = env_var_1.default.get('AUTH0_CLIENT_SECRET').asString();
29
- exports.mj_core_schema = env_var_1.default.get('MJ_CORE_SCHEMA').asString();
30
- exports.configFile = env_var_1.default.get('CONFIG_FILE').asString();
31
- const userHandlingInfoSchema = zod_1.z.object({
32
- autoCreateNewUsers: zod_1.z.boolean().optional().default(false),
33
- newUserAuthorizedDomains: zod_1.z.array(zod_1.z.string()).optional().default([]),
34
- newUserRoles: zod_1.z.array(zod_1.z.string()).optional().default([]),
35
- updateCacheWhenNotFound: zod_1.z.boolean().optional().default(false),
36
- updateCacheWhenNotFoundDelay: zod_1.z.number().optional().default(30000),
37
- contextUserForNewUserCreation: zod_1.z.string().optional().default(''),
38
- });
39
- const databaseSettingsInfoSchema = zod_1.z.object({
40
- connectionTimeout: zod_1.z.number(),
41
- requestTimeout: zod_1.z.number(),
42
- metadataCacheRefreshInterval: zod_1.z.number(),
43
- });
44
- const viewingSystemInfoSchema = zod_1.z.object({
45
- enableSmartFilters: zod_1.z.boolean().optional(),
46
- });
47
- const configInfoSchema = zod_1.z.object({
48
- userHandling: userHandlingInfoSchema,
49
- databaseSettings: databaseSettingsInfoSchema,
50
- viewingSystem: viewingSystemInfoSchema.optional(),
51
- });
52
- exports.configInfo = loadConfig();
53
- function loadConfig() {
54
- const configPath = exports.configFile ?? path_1.default.resolve('config.json');
55
- if (!fs_1.default.existsSync(configPath)) {
56
- throw new Error(`Config file ${configPath} does not exist.`);
57
- }
58
- const configData = fs_1.default.readFileSync(configPath, 'utf-8');
59
- return configInfoSchema.parse(JSON.parse(configData));
60
- }
61
- exports.loadConfig = loadConfig;
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.loadConfig = exports.configInfo = exports.configFile = exports.mj_core_schema = exports.auth0ClientSecret = exports.auth0WebClientID = exports.auth0Domain = exports.userEmailMap = exports.websiteRunFromPackage = exports.enableIntrospection = exports.tenantID = exports.webClientID = exports.graphqlRootPath = exports.graphqlPort = exports.dbTrustServerCertificate = exports.dbInstanceName = exports.dbDatabase = exports.dbPassword = exports.dbUsername = exports.dbPort = exports.dbHost = exports.nodeEnv = void 0;
7
+ const env_var_1 = __importDefault(require("env-var"));
8
+ const fs_1 = __importDefault(require("fs"));
9
+ const path_1 = __importDefault(require("path"));
10
+ const zod_1 = require("zod");
11
+ exports.nodeEnv = env_var_1.default.get('NODE_ENV').asString();
12
+ exports.dbHost = env_var_1.default.get('DB_HOST').required().asString();
13
+ exports.dbPort = env_var_1.default.get('DB_PORT').default('1433').asPortNumber();
14
+ exports.dbUsername = env_var_1.default.get('DB_USERNAME').required().asString();
15
+ exports.dbPassword = env_var_1.default.get('DB_PASSWORD').required().asString();
16
+ exports.dbDatabase = env_var_1.default.get('DB_DATABASE').required().asString();
17
+ exports.dbInstanceName = env_var_1.default.get('DB_INSTANCE_NAME').asString();
18
+ exports.dbTrustServerCertificate = env_var_1.default.get('DB_TRUST_SERVER_CERTIFICATE').asBool();
19
+ exports.graphqlPort = env_var_1.default.get('PORT').default('4000').asPortNumber();
20
+ exports.graphqlRootPath = env_var_1.default.get('ROOT_PATH').default('/').asString();
21
+ exports.webClientID = env_var_1.default.get('WEB_CLIENT_ID').asString();
22
+ exports.tenantID = env_var_1.default.get('TENANT_ID').asString();
23
+ exports.enableIntrospection = env_var_1.default.get('ENABLE_INTROSPECTION').default('false').asBool();
24
+ exports.websiteRunFromPackage = env_var_1.default.get('WEBSITE_RUN_FROM_PACKAGE').asIntPositive();
25
+ exports.userEmailMap = env_var_1.default.get('USER_EMAIL_MAP').default('{}').asJsonObject();
26
+ exports.auth0Domain = env_var_1.default.get('AUTH0_DOMAIN').asString();
27
+ exports.auth0WebClientID = env_var_1.default.get('AUTH0_CLIENT_ID').asString();
28
+ exports.auth0ClientSecret = env_var_1.default.get('AUTH0_CLIENT_SECRET').asString();
29
+ exports.mj_core_schema = env_var_1.default.get('MJ_CORE_SCHEMA').asString();
30
+ exports.configFile = env_var_1.default.get('CONFIG_FILE').asString();
31
+ const userHandlingInfoSchema = zod_1.z.object({
32
+ autoCreateNewUsers: zod_1.z.boolean().optional().default(false),
33
+ newUserAuthorizedDomains: zod_1.z.array(zod_1.z.string()).optional().default([]),
34
+ newUserRoles: zod_1.z.array(zod_1.z.string()).optional().default([]),
35
+ updateCacheWhenNotFound: zod_1.z.boolean().optional().default(false),
36
+ updateCacheWhenNotFoundDelay: zod_1.z.number().optional().default(30000),
37
+ contextUserForNewUserCreation: zod_1.z.string().optional().default(''),
38
+ });
39
+ const databaseSettingsInfoSchema = zod_1.z.object({
40
+ connectionTimeout: zod_1.z.number(),
41
+ requestTimeout: zod_1.z.number(),
42
+ metadataCacheRefreshInterval: zod_1.z.number(),
43
+ });
44
+ const viewingSystemInfoSchema = zod_1.z.object({
45
+ enableSmartFilters: zod_1.z.boolean().optional(),
46
+ });
47
+ const configInfoSchema = zod_1.z.object({
48
+ userHandling: userHandlingInfoSchema,
49
+ databaseSettings: databaseSettingsInfoSchema,
50
+ viewingSystem: viewingSystemInfoSchema.optional(),
51
+ });
52
+ exports.configInfo = loadConfig();
53
+ function loadConfig() {
54
+ const configPath = exports.configFile ?? path_1.default.resolve('config.json');
55
+ if (!fs_1.default.existsSync(configPath)) {
56
+ throw new Error(`Config file ${configPath} does not exist.`);
57
+ }
58
+ const configData = fs_1.default.readFileSync(configPath, 'utf-8');
59
+ return configInfoSchema.parse(JSON.parse(configData));
60
+ }
61
+ exports.loadConfig = loadConfig;
62
62
  //# sourceMappingURL=config.js.map