@loomcore/api 0.0.2 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/__tests__/test-express-app.js +10 -2
- package/dist/config/base-api-config.d.ts +3 -0
- package/dist/config/base-api-config.js +18 -0
- package/dist/config/index.d.ts +1 -1
- package/dist/config/index.js +1 -1
- package/dist/middleware/error-handler.js +1 -1
- package/dist/models/base-api-config.interface.d.ts +20 -2
- package/dist/models/index.d.ts +0 -1
- package/dist/models/index.js +0 -1
- package/package.json +1 -1
- package/dist/config/api-common-config.d.ts +0 -3
- package/dist/config/api-common-config.js +0 -11
- package/dist/models/api-common-config.interface.d.ts +0 -22
- package/dist/models/api-common-config.interface.js +0 -1
|
@@ -6,7 +6,7 @@ import { MongoMemoryServer } from 'mongodb-memory-server';
|
|
|
6
6
|
import { MongoClient } from 'mongodb';
|
|
7
7
|
import { initializeTypeBox } from '@loomcore/common/validation';
|
|
8
8
|
import testUtils from './common-test.utils.js';
|
|
9
|
-
import {
|
|
9
|
+
import { setBaseApiConfig } from '../config/base-api-config.js';
|
|
10
10
|
import { errorHandler } from '../middleware/error-handler.js';
|
|
11
11
|
import { ensureUserContext } from '../middleware/ensure-user-context.js';
|
|
12
12
|
export class TestExpressApp {
|
|
@@ -15,11 +15,19 @@ export class TestExpressApp {
|
|
|
15
15
|
static client;
|
|
16
16
|
static db;
|
|
17
17
|
static async init() {
|
|
18
|
-
|
|
18
|
+
setBaseApiConfig({
|
|
19
19
|
env: 'test',
|
|
20
20
|
hostName: 'localhost',
|
|
21
21
|
appName: 'test-app',
|
|
22
22
|
clientSecret: 'test-secret',
|
|
23
|
+
mongoDbUrl: '',
|
|
24
|
+
databaseName: '',
|
|
25
|
+
externalPort: 4000,
|
|
26
|
+
internalPort: 8083,
|
|
27
|
+
corsAllowedOrigins: ['*'],
|
|
28
|
+
saltWorkFactor: 10,
|
|
29
|
+
jobTypes: '',
|
|
30
|
+
deployedBranch: '',
|
|
23
31
|
debug: {
|
|
24
32
|
showErrors: false
|
|
25
33
|
},
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export let config;
|
|
2
|
+
let isConfigSet = false;
|
|
3
|
+
function copyOnlyBaseApiConfigProperties(obj) {
|
|
4
|
+
const baseConfig = {};
|
|
5
|
+
Object.keys(obj).forEach((key) => {
|
|
6
|
+
baseConfig[key] = obj[key];
|
|
7
|
+
});
|
|
8
|
+
return baseConfig;
|
|
9
|
+
}
|
|
10
|
+
export function setBaseApiConfig(baseApiConfig) {
|
|
11
|
+
if (!isConfigSet) {
|
|
12
|
+
config = copyOnlyBaseApiConfigProperties(baseApiConfig);
|
|
13
|
+
isConfigSet = true;
|
|
14
|
+
}
|
|
15
|
+
else if (config.env !== 'test') {
|
|
16
|
+
console.warn('BaseApiConfig data has already been set. Ignoring subsequent calls to setBaseApiConfig.');
|
|
17
|
+
}
|
|
18
|
+
}
|
package/dist/config/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from './api-
|
|
1
|
+
export * from './base-api-config.js';
|
package/dist/config/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from './api-
|
|
1
|
+
export * from './base-api-config.js';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { CustomError } from '@loomcore/common/errors';
|
|
2
2
|
import { apiUtils } from '../utils/index.js';
|
|
3
|
-
import { config } from '../config/api-
|
|
3
|
+
import { config } from '../config/base-api-config.js';
|
|
4
4
|
export const errorHandler = (err, req, res, next) => {
|
|
5
5
|
if (config.debug?.showErrors || config.env !== 'test') {
|
|
6
6
|
console.error('API Error:', {
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
import { IApiCommonConfig } from './api-common-config.interface.js';
|
|
2
1
|
export interface IBaseApiConfig {
|
|
2
|
+
appName: string;
|
|
3
|
+
env: string;
|
|
4
|
+
hostName: string;
|
|
5
|
+
clientSecret: string;
|
|
3
6
|
mongoDbUrl?: string;
|
|
4
7
|
databaseName?: string;
|
|
5
8
|
externalPort?: number;
|
|
@@ -8,5 +11,20 @@ export interface IBaseApiConfig {
|
|
|
8
11
|
saltWorkFactor?: number;
|
|
9
12
|
jobTypes?: string;
|
|
10
13
|
deployedBranch?: string;
|
|
11
|
-
|
|
14
|
+
debug?: {
|
|
15
|
+
showErrors?: boolean;
|
|
16
|
+
};
|
|
17
|
+
app: {
|
|
18
|
+
multiTenant: boolean;
|
|
19
|
+
};
|
|
20
|
+
auth: {
|
|
21
|
+
jwtExpirationInSeconds: number;
|
|
22
|
+
refreshTokenExpirationInDays: number;
|
|
23
|
+
deviceIdCookieMaxAgeInDays: number;
|
|
24
|
+
passwordResetTokenExpirationInMinutes: number;
|
|
25
|
+
};
|
|
26
|
+
email: {
|
|
27
|
+
sendGridApiKey?: string;
|
|
28
|
+
fromAddress?: string;
|
|
29
|
+
};
|
|
12
30
|
}
|
package/dist/models/index.d.ts
CHANGED
package/dist/models/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
export let config;
|
|
2
|
-
let isConfigSet = false;
|
|
3
|
-
export function setApiCommonConfig(apiCommonConfig) {
|
|
4
|
-
if (!isConfigSet) {
|
|
5
|
-
config = apiCommonConfig;
|
|
6
|
-
isConfigSet = true;
|
|
7
|
-
}
|
|
8
|
-
else if (config.env !== 'test') {
|
|
9
|
-
console.warn('ApiCommonConfig data has already been set. Ignoring subsequent calls to setApiCommonConfig.');
|
|
10
|
-
}
|
|
11
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
export interface IApiCommonConfig {
|
|
2
|
-
env: string;
|
|
3
|
-
hostName: string;
|
|
4
|
-
appName: string;
|
|
5
|
-
clientSecret: string;
|
|
6
|
-
debug?: {
|
|
7
|
-
showErrors?: boolean;
|
|
8
|
-
};
|
|
9
|
-
app: {
|
|
10
|
-
multiTenant: boolean;
|
|
11
|
-
};
|
|
12
|
-
auth: {
|
|
13
|
-
jwtExpirationInSeconds: number;
|
|
14
|
-
refreshTokenExpirationInDays: number;
|
|
15
|
-
deviceIdCookieMaxAgeInDays: number;
|
|
16
|
-
passwordResetTokenExpirationInMinutes: number;
|
|
17
|
-
};
|
|
18
|
-
email: {
|
|
19
|
-
sendGridApiKey?: string;
|
|
20
|
-
fromAddress?: string;
|
|
21
|
-
};
|
|
22
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|