@loomcore/api 0.0.2 → 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.
@@ -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 { setApiCommonConfig } from '../config/api-common-config.js';
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
- setApiCommonConfig({
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,3 @@
1
+ import { IBaseApiConfig } from '../models/index.js';
2
+ export declare let config: IBaseApiConfig;
3
+ export declare function setBaseApiConfig(baseApiConfig: IBaseApiConfig): void;
@@ -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
+ }
@@ -1 +1 @@
1
- export * from './api-common-config.js';
1
+ export * from './base-api-config.js';
@@ -1 +1 @@
1
- export * from './api-common-config.js';
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-common-config.js';
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
- api: IApiCommonConfig;
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
  }
@@ -1,3 +1,2 @@
1
- export * from './api-common-config.interface.js';
2
1
  export * from './base-api-config.interface.js';
3
2
  export * from './types/index.js';
@@ -1,3 +1,2 @@
1
- export * from './api-common-config.interface.js';
2
1
  export * from './base-api-config.interface.js';
3
2
  export * from './types/index.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@loomcore/api",
3
- "version": "0.0.2",
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": {
@@ -1,3 +0,0 @@
1
- import { IApiCommonConfig } from '../models/index.js';
2
- export declare let config: IApiCommonConfig;
3
- export declare function setApiCommonConfig(apiCommonConfig: IApiCommonConfig): void;
@@ -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 {};