@justair/justair-library 4.8.1 → 4.8.3-alpha

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/README CHANGED
@@ -1,146 +1,146 @@
1
- # justair-library
2
-
3
- ## Overview
4
-
5
- The `justair-library` is an NPM package that is installed on all backend and AWS Lambda services within the JustAir ecosystem. It provides essential utilities and shared functionality used across various JustAir services.
6
-
7
- ## Prerequisites
8
-
9
- To access and install the `justair-library`, you must be a part of the JustAir organization on npmjs.org. Ensure you have the following:
10
-
11
- 1. **NPM** - Node Package Manager
12
- 2. **Access Token** - Obtain your access token from the JustAir organization on npmjs.org
13
-
14
- ## Installation
15
-
16
- To install the `justair-library`, use the following command:
17
-
18
- ```bash
19
- npm install @justair/justair-library
20
- ```
21
-
22
- Ensure you have authenticated with npmjs.org using your access token:
23
-
24
- ```bash
25
- npm login
26
- # Follow the prompts to authenticate
27
- ```
28
-
29
- Alternatively, you can set your token directly in your NPM configuration:
30
-
31
- ```bash
32
- npm set //registry.npmjs.org/:_authToken=YOUR_ACCESS_TOKEN
33
- ```
34
-
35
- ## Usage
36
-
37
- After installation, you can import and use the library in your project:
38
-
39
- ```javascript
40
- const justair = require("@justair/justair-library");
41
-
42
- // Example usage
43
- justair.someUtilityFunction();
44
- ```
45
-
46
- ## Upgrading Versions
47
-
48
- To upgrade to a newer version of the justair-library, run:
49
-
50
- ```bash
51
- npm update @justair/justair-library
52
- ```
53
-
54
- Ensure you review the release notes and any potential breaking changes before upgrading.
55
-
56
- ## Publishing a New Version
57
-
58
- ### Testing Locally Before Publishing
59
-
60
- Before publishing to npm, it's recommended to test your package locally:
61
-
62
- 1. **Build and pack the library locally:**
63
-
64
- ```bash
65
- npm run build # If you have a build step
66
- npm pack
67
- ```
68
-
69
- This creates a `.tgz` file (e.g., `justair-justair-library-1.0.0.tgz`)
70
-
71
- 2. **Install in a test project:**
72
-
73
- In your test project directory:
74
-
75
- ```bash
76
- npm install /path/to/justair-library/justair-justair-library-1.0.0.tgz
77
- ```
78
-
79
- Or using npm link for development:
80
-
81
- ```bash
82
- # In the justair-library directory
83
- npm link
84
-
85
- # In your test project directory
86
- npm link @justair/justair-library
87
- ```
88
-
89
- 3. **Test your changes:**
90
-
91
- Import and test the library in your test project to ensure everything works as expected.
92
-
93
- 4. **Unlink when done (if using npm link):**
94
-
95
- ```bash
96
- # In your test project directory
97
- npm unlink @justair/justair-library
98
-
99
- # In the justair-library directory
100
- npm unlink
101
- ```
102
-
103
- ### Publishing to npm
104
-
105
- Once you've tested locally and are ready to publish:
106
-
107
- 1. **Update the version number:**
108
-
109
- Modify the version field in `package.json` according to semantic versioning guidelines.
110
-
111
- 2. **Build the package (if applicable):**
112
-
113
- Ensure any build steps are completed:
114
-
115
- ```bash
116
- npm run build
117
- ```
118
-
119
- 3. **Login to npm:**
120
-
121
- Ensure you are authenticated with the JustAir organization on npmjs.org:
122
-
123
- ```bash
124
- npm login
125
- # Follow the prompts to authenticate
126
- ```
127
-
128
- 4. **Publish the package:**
129
-
130
- Run the following command to publish the updated package:
131
-
132
- ```bash
133
- npm publish --access public
134
- ```
135
-
136
- ## Contributing
137
-
138
- If you would like to contribute to this project, please fork the repository and submit a pull request. For major changes, please open an issue first to discuss what you would like to change.
139
-
140
- ## License
141
-
142
- This project is licensed under the MIT License - see the LICENSE file for details.
143
-
144
- ## Contact
145
-
146
- For any inquiries or support, please contact the development team.
1
+ # justair-library
2
+
3
+ ## Overview
4
+
5
+ The `justair-library` is an NPM package that is installed on all backend and AWS Lambda services within the JustAir ecosystem. It provides essential utilities and shared functionality used across various JustAir services.
6
+
7
+ ## Prerequisites
8
+
9
+ To access and install the `justair-library`, you must be a part of the JustAir organization on npmjs.org. Ensure you have the following:
10
+
11
+ 1. **NPM** - Node Package Manager
12
+ 2. **Access Token** - Obtain your access token from the JustAir organization on npmjs.org
13
+
14
+ ## Installation
15
+
16
+ To install the `justair-library`, use the following command:
17
+
18
+ ```bash
19
+ npm install @justair/justair-library
20
+ ```
21
+
22
+ Ensure you have authenticated with npmjs.org using your access token:
23
+
24
+ ```bash
25
+ npm login
26
+ # Follow the prompts to authenticate
27
+ ```
28
+
29
+ Alternatively, you can set your token directly in your NPM configuration:
30
+
31
+ ```bash
32
+ npm set //registry.npmjs.org/:_authToken=YOUR_ACCESS_TOKEN
33
+ ```
34
+
35
+ ## Usage
36
+
37
+ After installation, you can import and use the library in your project:
38
+
39
+ ```javascript
40
+ const justair = require("@justair/justair-library");
41
+
42
+ // Example usage
43
+ justair.someUtilityFunction();
44
+ ```
45
+
46
+ ## Upgrading Versions
47
+
48
+ To upgrade to a newer version of the justair-library, run:
49
+
50
+ ```bash
51
+ npm update @justair/justair-library
52
+ ```
53
+
54
+ Ensure you review the release notes and any potential breaking changes before upgrading.
55
+
56
+ ## Publishing a New Version
57
+
58
+ ### Testing Locally Before Publishing
59
+
60
+ Before publishing to npm, it's recommended to test your package locally:
61
+
62
+ 1. **Build and pack the library locally:**
63
+
64
+ ```bash
65
+ npm run build # If you have a build step
66
+ npm pack
67
+ ```
68
+
69
+ This creates a `.tgz` file (e.g., `justair-justair-library-1.0.0.tgz`)
70
+
71
+ 2. **Install in a test project:**
72
+
73
+ In your test project directory:
74
+
75
+ ```bash
76
+ npm install /path/to/justair-library/justair-justair-library-1.0.0.tgz
77
+ ```
78
+
79
+ Or using npm link for development:
80
+
81
+ ```bash
82
+ # In the justair-library directory
83
+ npm link
84
+
85
+ # In your test project directory
86
+ npm link @justair/justair-library
87
+ ```
88
+
89
+ 3. **Test your changes:**
90
+
91
+ Import and test the library in your test project to ensure everything works as expected.
92
+
93
+ 4. **Unlink when done (if using npm link):**
94
+
95
+ ```bash
96
+ # In your test project directory
97
+ npm unlink @justair/justair-library
98
+
99
+ # In the justair-library directory
100
+ npm unlink
101
+ ```
102
+
103
+ ### Publishing to npm
104
+
105
+ Once you've tested locally and are ready to publish:
106
+
107
+ 1. **Update the version number:**
108
+
109
+ Modify the version field in `package.json` according to semantic versioning guidelines.
110
+
111
+ 2. **Build the package (if applicable):**
112
+
113
+ Ensure any build steps are completed:
114
+
115
+ ```bash
116
+ npm run build
117
+ ```
118
+
119
+ 3. **Login to npm:**
120
+
121
+ Ensure you are authenticated with the JustAir organization on npmjs.org:
122
+
123
+ ```bash
124
+ npm login
125
+ # Follow the prompts to authenticate
126
+ ```
127
+
128
+ 4. **Publish the package:**
129
+
130
+ Run the following command to publish the updated package:
131
+
132
+ ```bash
133
+ npm publish --access public
134
+ ```
135
+
136
+ ## Contributing
137
+
138
+ If you would like to contribute to this project, please fork the repository and submit a pull request. For major changes, please open an issue first to discuss what you would like to change.
139
+
140
+ ## License
141
+
142
+ This project is licensed under the MIT License - see the LICENSE file for details.
143
+
144
+ ## Contact
145
+
146
+ For any inquiries or support, please contact the development team.
package/package.json CHANGED
@@ -1,27 +1,27 @@
1
- {
2
- "name": "@justair/justair-library",
3
- "version": "4.8.1",
4
- "description": "JustAir Internal Library",
5
- "main": "src/index.js",
6
- "type": "module",
7
- "types": "dist/index.d.ts",
8
- "scripts": {
9
- "test": "echo \"Error: no test specified\" && exit 1",
10
- "build": "tsc",
11
- "prepublish": "npm run build"
12
- },
13
- "keywords": [
14
- "JustAir"
15
- ],
16
- "author": "Britney Epps",
17
- "license": "ISC",
18
- "dependencies": {
19
- "mongoose": "^7.8.3",
20
- "winston": "^3.10.0"
21
- },
22
- "devDependencies": {
23
- "typescript": "^5.3.2",
24
- "@types/node": "^16.0.0",
25
- "ts-node": "^10.0.0"
26
- }
27
- }
1
+ {
2
+ "name": "@justair/justair-library",
3
+ "version": "4.8.3-alpha",
4
+ "description": "JustAir Internal Library",
5
+ "main": "src/index.js",
6
+ "type": "module",
7
+ "types": "dist/index.d.ts",
8
+ "scripts": {
9
+ "test": "echo \"Error: no test specified\" && exit 1",
10
+ "build": "tsc",
11
+ "prepublish": "npm run build"
12
+ },
13
+ "keywords": [
14
+ "JustAir"
15
+ ],
16
+ "author": "Britney Epps",
17
+ "license": "ISC",
18
+ "dependencies": {
19
+ "mongoose": "^7.8.3",
20
+ "winston": "^3.10.0"
21
+ },
22
+ "devDependencies": {
23
+ "typescript": "^5.3.2",
24
+ "@types/node": "^16.0.0",
25
+ "ts-node": "^10.0.0"
26
+ }
27
+ }
package/src/config/db.js CHANGED
@@ -1,116 +1,116 @@
1
- import mongoose from "mongoose";
2
-
3
- class Database {
4
- static instances = new Map(); // Store multiple instances by connection key
5
-
6
- constructor({ CONNECTION_URL, database }) {
7
- this.CONNECTION_URL = CONNECTION_URL;
8
- this.database = database;
9
- this.connectionKey = `${CONNECTION_URL}:${database}`;
10
- this.isConnected = false;
11
- }
12
-
13
- async connect() {
14
- // Check if we're already connected to this specific database
15
- if (this.isConnected && mongoose.connection.readyState === 1) {
16
- // Verify we're connected to the right database
17
- if (mongoose.connection.db.databaseName === this.database) {
18
- console.log(`Already connected to database: ${this.database}`);
19
- return;
20
- }
21
- }
22
-
23
- try {
24
- // Only disconnect if we're connected to a different database
25
- if (mongoose.connection.readyState === 1) {
26
- const currentDb = mongoose.connection.db.databaseName;
27
- if (currentDb !== this.database) {
28
- console.log(
29
- `Switching from database: ${currentDb} to: ${this.database}`
30
- );
31
- await mongoose.disconnect();
32
- } else {
33
- // Already connected to the correct database
34
- this.isConnected = true;
35
- return;
36
- }
37
- }
38
-
39
- await mongoose.connect(this.CONNECTION_URL, {
40
- authSource: "admin",
41
- ssl: true,
42
- dbName: this.database,
43
- });
44
-
45
- this.isConnected = true;
46
- console.log(`Database connection successful: ${this.database}`);
47
- } catch (err) {
48
- this.isConnected = false;
49
- console.error(`Database connection error for ${this.database}: ${err}`);
50
- throw err;
51
- }
52
- }
53
-
54
- async disconnect() {
55
- try {
56
- if (mongoose.connection.readyState === 1) {
57
- await mongoose.disconnect();
58
- this.isConnected = false;
59
- console.log(`Disconnected from database: ${this.database}`);
60
- }
61
- } catch (err) {
62
- console.error(`Error disconnecting from database: ${err}`);
63
- throw err;
64
- }
65
- }
66
-
67
- static async getInstance(config) {
68
- const connectionKey = `${config.CONNECTION_URL}:${config.database}`;
69
-
70
- // Check if we have an instance for this connection
71
- if (Database.instances.has(connectionKey)) {
72
- const instance = Database.instances.get(connectionKey);
73
-
74
- // Ensure the connection is still valid
75
- if (!instance.isConnected || mongoose.connection.readyState !== 1) {
76
- await instance.connect();
77
- }
78
-
79
- return instance;
80
- }
81
-
82
- // Create new instance
83
- const instance = new Database(config);
84
- await instance.connect();
85
- Database.instances.set(connectionKey, instance);
86
-
87
- return instance;
88
- }
89
-
90
- static getCurrentDatabase() {
91
- if (mongoose.connection.readyState === 1) {
92
- return mongoose.connection.db.databaseName;
93
- }
94
- return null;
95
- }
96
-
97
- static async closeAllConnections() {
98
- try {
99
- if (mongoose.connection.readyState === 1) {
100
- await mongoose.disconnect();
101
- }
102
-
103
- // Mark all instances as disconnected
104
- for (const instance of Database.instances.values()) {
105
- instance.isConnected = false;
106
- }
107
-
108
- console.log("All database connections closed");
109
- } catch (err) {
110
- console.error("Error closing database connections:", err);
111
- throw err;
112
- }
113
- }
114
- }
115
-
116
- export default Database;
1
+ import mongoose from "mongoose";
2
+
3
+ class Database {
4
+ static instances = new Map(); // Store multiple instances by connection key
5
+
6
+ constructor({ CONNECTION_URL, database }) {
7
+ this.CONNECTION_URL = CONNECTION_URL;
8
+ this.database = database;
9
+ this.connectionKey = `${CONNECTION_URL}:${database}`;
10
+ this.isConnected = false;
11
+ }
12
+
13
+ async connect() {
14
+ // Check if we're already connected to this specific database
15
+ if (this.isConnected && mongoose.connection.readyState === 1) {
16
+ // Verify we're connected to the right database
17
+ if (mongoose.connection.db.databaseName === this.database) {
18
+ console.log(`Already connected to database: ${this.database}`);
19
+ return;
20
+ }
21
+ }
22
+
23
+ try {
24
+ // Only disconnect if we're connected to a different database
25
+ if (mongoose.connection.readyState === 1) {
26
+ const currentDb = mongoose.connection.db.databaseName;
27
+ if (currentDb !== this.database) {
28
+ console.log(
29
+ `Switching from database: ${currentDb} to: ${this.database}`
30
+ );
31
+ await mongoose.disconnect();
32
+ } else {
33
+ // Already connected to the correct database
34
+ this.isConnected = true;
35
+ return;
36
+ }
37
+ }
38
+
39
+ await mongoose.connect(this.CONNECTION_URL, {
40
+ authSource: "admin",
41
+ ssl: true,
42
+ dbName: this.database,
43
+ });
44
+
45
+ this.isConnected = true;
46
+ console.log(`Database connection successful: ${this.database}`);
47
+ } catch (err) {
48
+ this.isConnected = false;
49
+ console.error(`Database connection error for ${this.database}: ${err}`);
50
+ throw err;
51
+ }
52
+ }
53
+
54
+ async disconnect() {
55
+ try {
56
+ if (mongoose.connection.readyState === 1) {
57
+ await mongoose.disconnect();
58
+ this.isConnected = false;
59
+ console.log(`Disconnected from database: ${this.database}`);
60
+ }
61
+ } catch (err) {
62
+ console.error(`Error disconnecting from database: ${err}`);
63
+ throw err;
64
+ }
65
+ }
66
+
67
+ static async getInstance(config) {
68
+ const connectionKey = `${config.CONNECTION_URL}:${config.database}`;
69
+
70
+ // Check if we have an instance for this connection
71
+ if (Database.instances.has(connectionKey)) {
72
+ const instance = Database.instances.get(connectionKey);
73
+
74
+ // Ensure the connection is still valid
75
+ if (!instance.isConnected || mongoose.connection.readyState !== 1) {
76
+ await instance.connect();
77
+ }
78
+
79
+ return instance;
80
+ }
81
+
82
+ // Create new instance
83
+ const instance = new Database(config);
84
+ await instance.connect();
85
+ Database.instances.set(connectionKey, instance);
86
+
87
+ return instance;
88
+ }
89
+
90
+ static getCurrentDatabase() {
91
+ if (mongoose.connection.readyState === 1) {
92
+ return mongoose.connection.db.databaseName;
93
+ }
94
+ return null;
95
+ }
96
+
97
+ static async closeAllConnections() {
98
+ try {
99
+ if (mongoose.connection.readyState === 1) {
100
+ await mongoose.disconnect();
101
+ }
102
+
103
+ // Mark all instances as disconnected
104
+ for (const instance of Database.instances.values()) {
105
+ instance.isConnected = false;
106
+ }
107
+
108
+ console.log("All database connections closed");
109
+ } catch (err) {
110
+ console.error("Error closing database connections:", err);
111
+ throw err;
112
+ }
113
+ }
114
+ }
115
+
116
+ export default Database;