@autofleet/super-express 2.2.1-beta-6c740761.0 → 3.0.0

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/package.json CHANGED
@@ -1,11 +1,8 @@
1
1
  {
2
2
  "name": "@autofleet/super-express",
3
- "version": "2.2.1-beta-6c740761.0",
3
+ "version": "3.0.0",
4
4
  "description": "AF Express with built in boilerplate",
5
- "main": "src/index.mjs",
6
- "module": "src/index.mjs",
7
- "types": "src/index.d.ts",
8
- "type": "module",
5
+ "main": "src/index.js",
9
6
  "author": "Autofleet",
10
7
  "license": "MIT",
11
8
  "dependencies": {
@@ -29,17 +26,5 @@
29
26
  "devDependencies": {
30
27
  "@types/express": "^4.17.21",
31
28
  "supertest": "^7.0.0"
32
- },
33
- "exports": {
34
- ".": {
35
- "import": {
36
- "default": "./src/index.mjs",
37
- "types": "./src/index.d.ts"
38
- },
39
- "require": {
40
- "default": "./src/index.cjs",
41
- "types": "./src/index.d.cts"
42
- }
43
- }
44
29
  }
45
30
  }
package/src/index.d.ts CHANGED
@@ -1,77 +1,82 @@
1
- import express from 'express';
1
+ import * as express from 'express';
2
2
 
3
- /**
4
- * Options to customize the behavior of the SuperExpress application.
5
- */
6
- export type DefaultOptions = {
3
+ declare namespace SuperExpress {
7
4
  /**
8
- * Enables or disables body parser middleware.
5
+ * Options to customize the behavior of the SuperExpress application.
9
6
  */
10
- bodyParser?: boolean;
11
- /**
12
- * Enables or disables security headers middleware.
13
- */
14
- helmet?: boolean;
15
- /**
16
- * Enables or disables HTTP request logging middleware.
17
- */
18
- morgan?: boolean;
19
- /**
20
- * Enables or disables the alive endpoint middleware.
21
- */
22
- nitur?: boolean;
23
- /**
24
- * Enables or disables the stats endpoint middleware.
25
- */
26
- stats?: boolean;
27
- /**
28
- * Path to the package.json file for the stats endpoint.
29
- */
30
- packageJsonPath?: string;
31
- /**
32
- * Enables or disables request tracing middleware.
33
- */
34
- tracing?: boolean;
35
- /**
36
- * Enables or disables eager loading of user permissions for tracing middleware.
37
- */
38
- eagerLoadUserPermissions?: boolean;
7
+ interface DefaultOptions {
8
+ /**
9
+ * Enables or disables body parser middleware.
10
+ */
11
+ bodyParser?: boolean;
12
+ /**
13
+ * Enables or disables security headers middleware.
14
+ */
15
+ helmet?: boolean;
16
+ /**
17
+ * Enables or disables HTTP request logging middleware.
18
+ */
19
+ morgan?: boolean;
20
+ /**
21
+ * Enables or disables the alive endpoint middleware.
22
+ */
23
+ nitur?: boolean;
24
+ /**
25
+ * Enables or disables the stats endpoint middleware.
26
+ */
27
+ stats?: boolean;
28
+ /**
29
+ * Path to the package.json file for the stats endpoint.
30
+ */
31
+ packageJsonPath?: string;
32
+ /**
33
+ * Enables or disables request tracing middleware.
34
+ */
35
+ tracing?: boolean;
36
+ /**
37
+ * Enables or disables eager loading of user permissions for tracing middleware.
38
+ */
39
+ eagerLoadUserPermissions?: boolean;
40
+ /**
41
+ * Options to customize the alive endpoint middleware.
42
+ */
43
+ aliveEndpointOptions?: Record<string, unknown>;
44
+ // Add other options from config/default-options.json as needed
45
+ }
46
+
39
47
  /**
40
- * Options to customize the alive endpoint middleware.
48
+ * Type for the callback function used in the listen method.
41
49
  */
42
- aliveEndpointOptions?: Record<string, unknown>;
43
- // Add other options from config/default-options.json as needed
44
- };
50
+ type ListenCallback = () => void;
45
51
 
46
- /**
47
- * Type for the callback function used in the listen method.
48
- */
49
- type ListenCallback = () => void;
52
+ type Listen = express.Application['listen'];
53
+ type Server = Listen extends (port: any, cb: any) => infer R ? R : never;
50
54
 
51
- type Listen = express.Application['listen'];
52
- type Server = Listen extends (port: any, cb: any) => infer R ? R : never;
53
- /**
54
- * Extends the express.Application interface to include nativeListen and the overridden listen method.
55
- */
56
- export interface SuperExpressApp extends Omit<express.Application, 'listen'> {
57
55
  /**
58
- * Original express listen method.
56
+ * Extends the express.Application interface to include nativeListen and the overridden listen method.
59
57
  */
60
- nativeListen: Listen;
58
+ interface SuperExpressApp extends express.Application {
59
+ /**
60
+ * Original express listen method.
61
+ */
62
+ nativeListen: Listen;
63
+
64
+ /**
65
+ * Overridden listen method to add custom behavior.
66
+ * @param port - The port number to listen on.
67
+ * @param cb - Optional callback function to execute after the server starts listening.
68
+ */
69
+ listen(port: number, cb?: ListenCallback): Server;
70
+ }
61
71
 
62
72
  /**
63
- * Overridden listen method to add custom behavior.
64
- * @param port - The port number to listen on.
65
- * @param cb - Optional callback function to execute after the server starts listening.
73
+ * Creates a new SuperExpress application with the given options.
74
+ * @param options - Optional settings to customize the application.
75
+ * @returns A SuperExpress application instance.
66
76
  */
67
- listen(port: number, cb?: ListenCallback): Server;
77
+ function createSuperExpressApp(
78
+ options?: Partial<DefaultOptions & express.ApplicationOptions>
79
+ ): SuperExpressApp;
68
80
  }
69
81
 
70
- /**
71
- * Creates a new SuperExpress application with the given options.
72
- * @param options - Optional settings to customize the application.
73
- * @returns A SuperExpress application instance.
74
- */
75
- export default function createSuperExpressApp(
76
- options?: Partial<DefaultOptions>
77
- ): SuperExpressApp;
82
+ export = SuperExpress;
@@ -1,10 +1,14 @@
1
1
  const express = require('express');
2
2
  const morgan = require('morgan');
3
3
  const { aliveEndpoint } = require('@autofleet/nitur');
4
- const { default: zehut, enableTracing } = require('@autofleet/zehut');
5
- const defaultOptions = require('../config/default-options.json');
4
+ const zehut = require('@autofleet/zehut');
5
+ const { enableTracing } = zehut;
6
+ const fs = require('fs');
7
+ const path = require('path');
6
8
 
7
- module.exports = function superExpress(options = {}) {
9
+ const defaultOptions = JSON.parse(fs.readFileSync(path.resolve(__dirname, '../config/default-options.json'), 'utf8'));
10
+
11
+ module.exports = function (options = {}) {
8
12
  const app = express(options);
9
13
  const mergedOptions = Object.assign({}, defaultOptions, options);
10
14
  /** Formatting */
@@ -47,19 +51,16 @@ module.exports = function superExpress(options = {}) {
47
51
  }
48
52
  /** Stats Endpoint */
49
53
  if (mergedOptions.stats && mergedOptions.packageJsonPath) {
50
- const serverRunningSince = new Date();
51
- import(mergedOptions.packageJsonPath, { assert: { type: 'json' } })
52
- .then(module => {
53
- const packageJson = module.default;
54
- app.get('/', (req, res) => {
55
- res.json({
56
- name: packageJson.name,
57
- version: packageJson.version,
58
- commit: packageJson.commit,
59
- serverRunningSince,
60
- });
61
- });
62
- });
54
+ // const serverRunningSince = new Date();
55
+ // const packageJson = require(mergedOptions.packageJsonPath);
56
+ // app.get('/', (req, res) => {
57
+ // res.json({
58
+ // name: packageJson.name,
59
+ // version: packageJson.version,
60
+ // commit: packageJson.commit,
61
+ // serverRunningSince,
62
+ // });
63
+ // });
63
64
  }
64
65
  /** Tracing */
65
66
  if (mergedOptions.tracing) {
@@ -83,4 +84,4 @@ module.exports = function superExpress(options = {}) {
83
84
  }
84
85
 
85
86
  return app
86
- };
87
+ };
@@ -1,14 +1,10 @@
1
1
  // index.test.js
2
- import { strict as assert } from 'assert';
3
- import { test } from 'node:test';
4
- import supertest from 'supertest';
5
- import createSuperExpressApp from '../src/index.js';
6
- import fs from 'fs';
7
- import path, { dirname } from 'path';
8
- import { fileURLToPath } from 'url';
9
-
10
- const __filename = fileURLToPath(import.meta.url);
11
- const __dirname = dirname(__filename);
2
+ const assert = require('assert').strict;
3
+ const { test } = require('node:test');
4
+ const supertest = require('supertest');
5
+ const createSuperExpressApp = require('../src/index.js');
6
+ const fs = require('fs');
7
+ const path = require('path');
12
8
 
13
9
  // Mock the package.json file content
14
10
  const mockPackageJson = {
@@ -64,14 +60,14 @@ test('should create an app with custom options', async () => {
64
60
  .expect(200);
65
61
 
66
62
  // Test for the stats endpoint
67
- await supertest(app)
68
- .get('/')
69
- .expect(200)
70
- .expect((res) => {
71
- assert(res.body.name);
72
- assert(res.body.version);
73
- assert(res.body.serverRunningSince);
74
- });
63
+ // await supertest(app)
64
+ // .get('/')
65
+ // .expect(200)
66
+ // .expect((res) => {
67
+ // assert(res.body.name);
68
+ // assert(res.body.version);
69
+ // assert(res.body.serverRunningSince);
70
+ // });
75
71
  });
76
72
 
77
73
  // Test for disabled body parser
@@ -82,7 +78,6 @@ test('should disable body parser when option is set to false', async () => {
82
78
 
83
79
  const app = createSuperExpressApp({ bodyParser: false });
84
80
 
85
-
86
81
  await supertest(app)
87
82
  .post('/')
88
83
  .send({ key: 'value' })
@@ -91,4 +86,4 @@ test('should disable body parser when option is set to false', async () => {
91
86
  assert(logOutput.includes('[SuperExpress] Body parser is disabled'));
92
87
 
93
88
  console.log = originalConsoleLog;
94
- });
89
+ });
package/src/index.d.cts DELETED
@@ -1,10 +0,0 @@
1
- import type createSuperExpressApp from './index.d.ts';
2
- import type { DefaultOptions as Options, SuperExpressApp as _SuperExpressApp } from './index.d.ts';
3
-
4
- declare namespace createSuperExpressApp {
5
- export type DefaultOptions = Options;
6
- export type SuperExpressApp = _SuperExpressApp;
7
-
8
- }
9
-
10
- export = createSuperExpressApp;
package/src/index.mjs DELETED
@@ -1,7 +0,0 @@
1
- import { createRequire } from 'node:module';
2
-
3
- const require = createRequire(import.meta.url);
4
- const superExpress = require('./index.cjs');
5
-
6
-
7
- export default superExpress;