@loomcore/api 0.0.1 → 0.0.3
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 +11 -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/dist/utils/db.utils.js +18 -0
- package/package.json +2 -3
- 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,11 @@
|
|
|
1
|
+
export let config;
|
|
2
|
+
let isConfigSet = false;
|
|
3
|
+
export function setBaseApiConfig(baseApiConfig) {
|
|
4
|
+
if (!isConfigSet) {
|
|
5
|
+
config = baseApiConfig;
|
|
6
|
+
isConfigSet = true;
|
|
7
|
+
}
|
|
8
|
+
else if (config.env !== 'test') {
|
|
9
|
+
console.warn('BaseApiConfig data has already been set. Ignoring subsequent calls to setBaseApiConfig.');
|
|
10
|
+
}
|
|
11
|
+
}
|
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/dist/utils/db.utils.js
CHANGED
|
@@ -160,6 +160,19 @@ function buildMongoMatchFromQueryOptions(queryOptions) {
|
|
|
160
160
|
match[key] = value.eq;
|
|
161
161
|
}
|
|
162
162
|
}
|
|
163
|
+
else if (value.in !== undefined && Array.isArray(value.in)) {
|
|
164
|
+
if (key.endsWith('Id') && !PROPERTIES_THAT_ARE_NOT_OBJECT_IDS.includes(key)) {
|
|
165
|
+
const objectIds = value.in
|
|
166
|
+
.filter(val => typeof val === 'string' && entityUtils.isValidObjectId(val))
|
|
167
|
+
.map(val => new ObjectId(val));
|
|
168
|
+
if (objectIds.length > 0) {
|
|
169
|
+
match[key] = { $in: objectIds };
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
else {
|
|
173
|
+
match[key] = { $in: value.in };
|
|
174
|
+
}
|
|
175
|
+
}
|
|
163
176
|
else if (value.gte !== undefined) {
|
|
164
177
|
match[key] = { $gte: value.gte };
|
|
165
178
|
}
|
|
@@ -199,6 +212,11 @@ function addKeyValueToWhereClause(whereClause, key, value, tableAlias = '') {
|
|
|
199
212
|
formattedValue = formatValue(value.eq);
|
|
200
213
|
operator = '=';
|
|
201
214
|
}
|
|
215
|
+
else if (value.in !== undefined && Array.isArray(value.in)) {
|
|
216
|
+
const formattedValues = value.in.map(val => formatValue(val)).join(', ');
|
|
217
|
+
formattedValue = `(${formattedValues})`;
|
|
218
|
+
operator = 'IN';
|
|
219
|
+
}
|
|
202
220
|
else if (value.gte !== undefined) {
|
|
203
221
|
formattedValue = formatValue(value.gte);
|
|
204
222
|
operator = '>=';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@loomcore/api",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Loom Core Api - An opinionated Node.js api using Typescript, Express, and MongoDb",
|
|
6
6
|
"scripts": {
|
|
@@ -16,7 +16,6 @@
|
|
|
16
16
|
"update-lib-versions": "npx --yes npm-check-updates -u -f @loomcore/models",
|
|
17
17
|
"install-updated-libs": "npm i @loomcore/models",
|
|
18
18
|
"update-libs": "npm-run-all -s update-lib-versions install-updated-libs",
|
|
19
|
-
|
|
20
19
|
"typecheck": "tsc",
|
|
21
20
|
"test": "cross-env NODE_ENV=test vitest run",
|
|
22
21
|
"test:ci": "cross-env NODE_ENV=test vitest run --reporter=json --outputFile=test-results.json",
|
|
@@ -45,7 +44,7 @@
|
|
|
45
44
|
"jsonwebtoken": "^9.0.2"
|
|
46
45
|
},
|
|
47
46
|
"peerDependencies": {
|
|
48
|
-
"@loomcore/common": "^0.0.
|
|
47
|
+
"@loomcore/common": "^0.0.7",
|
|
49
48
|
"@sinclair/typebox": "^0.34.31",
|
|
50
49
|
"cookie-parser": "^1.4.6",
|
|
51
50
|
"express": "^5.1.0",
|
|
@@ -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 {};
|