@justair/justair-library 6.14.0 → 7.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.
@@ -1 +1 @@
1
- {"version":3,"file":"userNotifications.d.ts","sourceRoot":"","sources":["../../src/models/userNotifications.js"],"names":[],"mappings":"AA6BA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuBE;AAQF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAAwE;AAgBxE,6EAGE;AAOF,kFAGE;AAQF,iFAGE;AAGF,4EAGE;qBA1GmB,UAAU"}
1
+ {"version":3,"file":"userNotifications.d.ts","sourceRoot":"","sources":["../../src/models/userNotifications.js"],"names":[],"mappings":"AA6BA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuBE;AAQF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAAwE;AAgBxE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAGE;AAOF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAGE;AAQF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAGE;AAGF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;oCAGE;qBA1GmB,UAAU"}
@@ -1 +1 @@
1
- {"version":3,"file":"users.d.ts","sourceRoot":"","sources":["../../src/models/users.js"],"names":[],"mappings":"AA2CA,8BAiFE;AA+BF,wBAAmD;AAnJnD,iDAA4D;AAC5D,6CAAmD;AAUnD,4DAsBC"}
1
+ {"version":3,"file":"users.d.ts","sourceRoot":"","sources":["../../src/models/users.js"],"names":[],"mappings":"AA2CA,8BAiFE;AA8BF,wBAAmD;AAlJnD,iDAA4D;AAC5D,6CAAmD;AAUnD,4DAsBC"}
@@ -8,314 +8,241 @@
8
8
  * action (what) ├─► AuditLog doc ──► compliance queries (by actor / action / target)
9
9
  * resource (tgt) ┘
10
10
  */
11
- export const auditLogSchema: mongoose.Schema<any, mongoose.Model<any, any, any, any, any, any>, {}, {}, {}, {}, {
11
+ export const auditLogSchema: mongoose.Schema<any, mongoose.Model<any, any, any, any, any, any, any>, {}, {}, {}, {}, {
12
12
  timestamps: true;
13
13
  }, {
14
- createdAt: NativeDate;
15
- updatedAt: NativeDate;
16
- } & {
17
14
  action: "auth.login.success" | "auth.login.failure" | "auth.logout" | "auth.password.reset.requested" | "auth.password.reset.completed" | "auth.token.refresh" | "admin.create" | "admin.update" | "admin.delete" | "admin.role.change" | "admin.deactivate" | "admin.reactivate";
18
15
  outcome: "success" | "failure";
19
16
  metadata?: any;
20
17
  actor?: {
21
- adminId?: {
22
- prototype?: mongoose.Types.ObjectId;
23
- cacheHexString?: unknown;
24
- generate?: {};
25
- createFromTime?: {};
26
- createFromHexString?: {};
27
- createFromBase64?: {};
28
- isValid?: {};
29
- };
18
+ adminId?: mongoose.Types.ObjectId;
30
19
  email?: string;
31
- orgId?: {
32
- prototype?: mongoose.Types.ObjectId;
33
- cacheHexString?: unknown;
34
- generate?: {};
35
- createFromTime?: {};
36
- createFromHexString?: {};
37
- createFromBase64?: {};
38
- isValid?: {};
39
- };
20
+ orgId?: mongoose.Types.ObjectId;
40
21
  };
41
22
  resource?: {
23
+ id?: any;
42
24
  type?: string;
43
25
  };
44
26
  reason?: string;
45
27
  requestId?: string;
46
- }, mongoose.Document<unknown, {}, mongoose.FlatRecord<{
47
- createdAt: NativeDate;
48
- updatedAt: NativeDate;
49
- } & {
28
+ } & mongoose.DefaultTimestampProps, mongoose.Document<unknown, {}, {
50
29
  action: "auth.login.success" | "auth.login.failure" | "auth.logout" | "auth.password.reset.requested" | "auth.password.reset.completed" | "auth.token.refresh" | "admin.create" | "admin.update" | "admin.delete" | "admin.role.change" | "admin.deactivate" | "admin.reactivate";
51
30
  outcome: "success" | "failure";
52
31
  metadata?: any;
53
32
  actor?: {
54
- adminId?: {
55
- prototype?: mongoose.Types.ObjectId;
56
- cacheHexString?: unknown;
57
- generate?: {};
58
- createFromTime?: {};
59
- createFromHexString?: {};
60
- createFromBase64?: {};
61
- isValid?: {};
62
- };
33
+ adminId?: mongoose.Types.ObjectId;
63
34
  email?: string;
64
- orgId?: {
65
- prototype?: mongoose.Types.ObjectId;
66
- cacheHexString?: unknown;
67
- generate?: {};
68
- createFromTime?: {};
69
- createFromHexString?: {};
70
- createFromBase64?: {};
71
- isValid?: {};
72
- };
35
+ orgId?: mongoose.Types.ObjectId;
73
36
  };
74
37
  resource?: {
38
+ id?: any;
75
39
  type?: string;
76
40
  };
77
41
  reason?: string;
78
42
  requestId?: string;
79
- }>> & mongoose.FlatRecord<{
80
- createdAt: NativeDate;
81
- updatedAt: NativeDate;
82
- } & {
43
+ } & mongoose.DefaultTimestampProps, {
44
+ id: string;
45
+ }, Omit<mongoose.DefaultSchemaOptions, "timestamps"> & {
46
+ timestamps: true;
47
+ }> & Omit<{
83
48
  action: "auth.login.success" | "auth.login.failure" | "auth.logout" | "auth.password.reset.requested" | "auth.password.reset.completed" | "auth.token.refresh" | "admin.create" | "admin.update" | "admin.delete" | "admin.role.change" | "admin.deactivate" | "admin.reactivate";
84
49
  outcome: "success" | "failure";
85
50
  metadata?: any;
86
51
  actor?: {
87
- adminId?: {
88
- prototype?: mongoose.Types.ObjectId;
89
- cacheHexString?: unknown;
90
- generate?: {};
91
- createFromTime?: {};
92
- createFromHexString?: {};
93
- createFromBase64?: {};
94
- isValid?: {};
95
- };
52
+ adminId?: mongoose.Types.ObjectId;
96
53
  email?: string;
97
- orgId?: {
98
- prototype?: mongoose.Types.ObjectId;
99
- cacheHexString?: unknown;
100
- generate?: {};
101
- createFromTime?: {};
102
- createFromHexString?: {};
103
- createFromBase64?: {};
104
- isValid?: {};
105
- };
54
+ orgId?: mongoose.Types.ObjectId;
106
55
  };
107
56
  resource?: {
57
+ id?: any;
108
58
  type?: string;
109
59
  };
110
60
  reason?: string;
111
61
  requestId?: string;
112
- }> & {
62
+ } & mongoose.DefaultTimestampProps & {
113
63
  _id: mongoose.Types.ObjectId;
114
- }>;
115
- export const AuditLog: mongoose.Model<{
116
- createdAt: NativeDate;
117
- updatedAt: NativeDate;
118
64
  } & {
65
+ __v: number;
66
+ }, "id"> & mongoose.HydratedDocumentOverrides<{
67
+ id: string;
68
+ }>, unknown, {
119
69
  action: "auth.login.success" | "auth.login.failure" | "auth.logout" | "auth.password.reset.requested" | "auth.password.reset.completed" | "auth.token.refresh" | "admin.create" | "admin.update" | "admin.delete" | "admin.role.change" | "admin.deactivate" | "admin.reactivate";
120
70
  outcome: "success" | "failure";
121
71
  metadata?: any;
122
72
  actor?: {
123
- adminId?: {
124
- prototype?: mongoose.Types.ObjectId;
125
- cacheHexString?: unknown;
126
- generate?: {};
127
- createFromTime?: {};
128
- createFromHexString?: {};
129
- createFromBase64?: {};
130
- isValid?: {};
131
- };
73
+ adminId?: mongoose.Types.ObjectId;
132
74
  email?: string;
133
- orgId?: {
134
- prototype?: mongoose.Types.ObjectId;
135
- cacheHexString?: unknown;
136
- generate?: {};
137
- createFromTime?: {};
138
- createFromHexString?: {};
139
- createFromBase64?: {};
140
- isValid?: {};
141
- };
75
+ orgId?: mongoose.Types.ObjectId;
142
76
  };
143
77
  resource?: {
78
+ id?: any;
144
79
  type?: string;
145
80
  };
146
81
  reason?: string;
147
82
  requestId?: string;
148
- }, {}, {}, {}, mongoose.Document<unknown, {}, {
149
83
  createdAt: NativeDate;
150
84
  updatedAt: NativeDate;
151
85
  } & {
86
+ _id: mongoose.Types.ObjectId;
87
+ } & {
88
+ __v: number;
89
+ }>;
90
+ export const AuditLog: mongoose.Model<{
152
91
  action: "auth.login.success" | "auth.login.failure" | "auth.logout" | "auth.password.reset.requested" | "auth.password.reset.completed" | "auth.token.refresh" | "admin.create" | "admin.update" | "admin.delete" | "admin.role.change" | "admin.deactivate" | "admin.reactivate";
153
92
  outcome: "success" | "failure";
154
93
  metadata?: any;
155
94
  actor?: {
156
- adminId?: {
157
- prototype?: mongoose.Types.ObjectId;
158
- cacheHexString?: unknown;
159
- generate?: {};
160
- createFromTime?: {};
161
- createFromHexString?: {};
162
- createFromBase64?: {};
163
- isValid?: {};
164
- };
95
+ adminId?: mongoose.Types.ObjectId;
165
96
  email?: string;
166
- orgId?: {
167
- prototype?: mongoose.Types.ObjectId;
168
- cacheHexString?: unknown;
169
- generate?: {};
170
- createFromTime?: {};
171
- createFromHexString?: {};
172
- createFromBase64?: {};
173
- isValid?: {};
174
- };
97
+ orgId?: mongoose.Types.ObjectId;
175
98
  };
176
99
  resource?: {
100
+ id?: any;
177
101
  type?: string;
178
102
  };
179
103
  reason?: string;
180
104
  requestId?: string;
181
- }> & {
182
- createdAt: NativeDate;
183
- updatedAt: NativeDate;
184
- } & {
105
+ } & mongoose.DefaultTimestampProps, {}, {}, {
106
+ id: string;
107
+ }, mongoose.Document<unknown, {}, {
185
108
  action: "auth.login.success" | "auth.login.failure" | "auth.logout" | "auth.password.reset.requested" | "auth.password.reset.completed" | "auth.token.refresh" | "admin.create" | "admin.update" | "admin.delete" | "admin.role.change" | "admin.deactivate" | "admin.reactivate";
186
109
  outcome: "success" | "failure";
187
110
  metadata?: any;
188
111
  actor?: {
189
- adminId?: {
190
- prototype?: mongoose.Types.ObjectId;
191
- cacheHexString?: unknown;
192
- generate?: {};
193
- createFromTime?: {};
194
- createFromHexString?: {};
195
- createFromBase64?: {};
196
- isValid?: {};
197
- };
112
+ adminId?: mongoose.Types.ObjectId;
198
113
  email?: string;
199
- orgId?: {
200
- prototype?: mongoose.Types.ObjectId;
201
- cacheHexString?: unknown;
202
- generate?: {};
203
- createFromTime?: {};
204
- createFromHexString?: {};
205
- createFromBase64?: {};
206
- isValid?: {};
207
- };
114
+ orgId?: mongoose.Types.ObjectId;
208
115
  };
209
116
  resource?: {
117
+ id?: any;
210
118
  type?: string;
211
119
  };
212
120
  reason?: string;
213
121
  requestId?: string;
214
- } & {
122
+ } & mongoose.DefaultTimestampProps, {
123
+ id: string;
124
+ }, {
125
+ timestamps: true;
126
+ }> & Omit<{
127
+ action: "auth.login.success" | "auth.login.failure" | "auth.logout" | "auth.password.reset.requested" | "auth.password.reset.completed" | "auth.token.refresh" | "admin.create" | "admin.update" | "admin.delete" | "admin.role.change" | "admin.deactivate" | "admin.reactivate";
128
+ outcome: "success" | "failure";
129
+ metadata?: any;
130
+ actor?: {
131
+ adminId?: mongoose.Types.ObjectId;
132
+ email?: string;
133
+ orgId?: mongoose.Types.ObjectId;
134
+ };
135
+ resource?: {
136
+ id?: any;
137
+ type?: string;
138
+ };
139
+ reason?: string;
140
+ requestId?: string;
141
+ } & mongoose.DefaultTimestampProps & {
215
142
  _id: mongoose.Types.ObjectId;
216
- }, mongoose.Schema<any, mongoose.Model<any, any, any, any, any, any>, {}, {}, {}, {}, {
143
+ } & {
144
+ __v: number;
145
+ }, "id"> & mongoose.HydratedDocumentOverrides<{
146
+ id: string;
147
+ }>, mongoose.Schema<any, mongoose.Model<any, any, any, any, any, any, any>, {}, {}, {}, {}, {
217
148
  timestamps: true;
218
149
  }, {
219
- createdAt: NativeDate;
220
- updatedAt: NativeDate;
221
- } & {
222
150
  action: "auth.login.success" | "auth.login.failure" | "auth.logout" | "auth.password.reset.requested" | "auth.password.reset.completed" | "auth.token.refresh" | "admin.create" | "admin.update" | "admin.delete" | "admin.role.change" | "admin.deactivate" | "admin.reactivate";
223
151
  outcome: "success" | "failure";
224
152
  metadata?: any;
225
153
  actor?: {
226
- adminId?: {
227
- prototype?: mongoose.Types.ObjectId;
228
- cacheHexString?: unknown;
229
- generate?: {};
230
- createFromTime?: {};
231
- createFromHexString?: {};
232
- createFromBase64?: {};
233
- isValid?: {};
234
- };
154
+ adminId?: mongoose.Types.ObjectId;
235
155
  email?: string;
236
- orgId?: {
237
- prototype?: mongoose.Types.ObjectId;
238
- cacheHexString?: unknown;
239
- generate?: {};
240
- createFromTime?: {};
241
- createFromHexString?: {};
242
- createFromBase64?: {};
243
- isValid?: {};
244
- };
156
+ orgId?: mongoose.Types.ObjectId;
245
157
  };
246
158
  resource?: {
159
+ id?: any;
247
160
  type?: string;
248
161
  };
249
162
  reason?: string;
250
163
  requestId?: string;
251
- }, mongoose.Document<unknown, {}, mongoose.FlatRecord<{
252
- createdAt: NativeDate;
253
- updatedAt: NativeDate;
164
+ } & mongoose.DefaultTimestampProps, mongoose.Document<unknown, {}, {
165
+ action: "auth.login.success" | "auth.login.failure" | "auth.logout" | "auth.password.reset.requested" | "auth.password.reset.completed" | "auth.token.refresh" | "admin.create" | "admin.update" | "admin.delete" | "admin.role.change" | "admin.deactivate" | "admin.reactivate";
166
+ outcome: "success" | "failure";
167
+ metadata?: any;
168
+ actor?: {
169
+ adminId?: mongoose.Types.ObjectId;
170
+ email?: string;
171
+ orgId?: mongoose.Types.ObjectId;
172
+ };
173
+ resource?: {
174
+ id?: any;
175
+ type?: string;
176
+ };
177
+ reason?: string;
178
+ requestId?: string;
179
+ } & mongoose.DefaultTimestampProps, {
180
+ id: string;
181
+ }, Omit<mongoose.DefaultSchemaOptions, "timestamps"> & {
182
+ timestamps: true;
183
+ }> & Omit<{
184
+ action: "auth.login.success" | "auth.login.failure" | "auth.logout" | "auth.password.reset.requested" | "auth.password.reset.completed" | "auth.token.refresh" | "admin.create" | "admin.update" | "admin.delete" | "admin.role.change" | "admin.deactivate" | "admin.reactivate";
185
+ outcome: "success" | "failure";
186
+ metadata?: any;
187
+ actor?: {
188
+ adminId?: mongoose.Types.ObjectId;
189
+ email?: string;
190
+ orgId?: mongoose.Types.ObjectId;
191
+ };
192
+ resource?: {
193
+ id?: any;
194
+ type?: string;
195
+ };
196
+ reason?: string;
197
+ requestId?: string;
198
+ } & mongoose.DefaultTimestampProps & {
199
+ _id: mongoose.Types.ObjectId;
254
200
  } & {
201
+ __v: number;
202
+ }, "id"> & mongoose.HydratedDocumentOverrides<{
203
+ id: string;
204
+ }>, unknown, {
255
205
  action: "auth.login.success" | "auth.login.failure" | "auth.logout" | "auth.password.reset.requested" | "auth.password.reset.completed" | "auth.token.refresh" | "admin.create" | "admin.update" | "admin.delete" | "admin.role.change" | "admin.deactivate" | "admin.reactivate";
256
206
  outcome: "success" | "failure";
257
207
  metadata?: any;
258
208
  actor?: {
259
- adminId?: {
260
- prototype?: mongoose.Types.ObjectId;
261
- cacheHexString?: unknown;
262
- generate?: {};
263
- createFromTime?: {};
264
- createFromHexString?: {};
265
- createFromBase64?: {};
266
- isValid?: {};
267
- };
209
+ adminId?: mongoose.Types.ObjectId;
268
210
  email?: string;
269
- orgId?: {
270
- prototype?: mongoose.Types.ObjectId;
271
- cacheHexString?: unknown;
272
- generate?: {};
273
- createFromTime?: {};
274
- createFromHexString?: {};
275
- createFromBase64?: {};
276
- isValid?: {};
277
- };
211
+ orgId?: mongoose.Types.ObjectId;
278
212
  };
279
213
  resource?: {
214
+ id?: any;
280
215
  type?: string;
281
216
  };
282
217
  reason?: string;
283
218
  requestId?: string;
284
- }>> & mongoose.FlatRecord<{
285
219
  createdAt: NativeDate;
286
220
  updatedAt: NativeDate;
287
221
  } & {
222
+ _id: mongoose.Types.ObjectId;
223
+ } & {
224
+ __v: number;
225
+ }>, {
288
226
  action: "auth.login.success" | "auth.login.failure" | "auth.logout" | "auth.password.reset.requested" | "auth.password.reset.completed" | "auth.token.refresh" | "admin.create" | "admin.update" | "admin.delete" | "admin.role.change" | "admin.deactivate" | "admin.reactivate";
289
227
  outcome: "success" | "failure";
290
228
  metadata?: any;
291
229
  actor?: {
292
- adminId?: {
293
- prototype?: mongoose.Types.ObjectId;
294
- cacheHexString?: unknown;
295
- generate?: {};
296
- createFromTime?: {};
297
- createFromHexString?: {};
298
- createFromBase64?: {};
299
- isValid?: {};
300
- };
230
+ adminId?: mongoose.Types.ObjectId;
301
231
  email?: string;
302
- orgId?: {
303
- prototype?: mongoose.Types.ObjectId;
304
- cacheHexString?: unknown;
305
- generate?: {};
306
- createFromTime?: {};
307
- createFromHexString?: {};
308
- createFromBase64?: {};
309
- isValid?: {};
310
- };
232
+ orgId?: mongoose.Types.ObjectId;
311
233
  };
312
234
  resource?: {
235
+ id?: any;
313
236
  type?: string;
314
237
  };
315
238
  reason?: string;
316
239
  requestId?: string;
317
- }> & {
240
+ createdAt: NativeDate;
241
+ updatedAt: NativeDate;
242
+ } & {
318
243
  _id: mongoose.Types.ObjectId;
319
- }>>;
244
+ } & {
245
+ __v: number;
246
+ }>;
320
247
  import mongoose from 'mongoose';
321
248
  //# sourceMappingURL=schema.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../../src/modules/audit/schema.js"],"names":[],"mappings":"AAGA;;;;;;;;;GASG;AACH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqBE;AAOF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAA4D;qBAzCvC,UAAU"}
1
+ {"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../../src/modules/audit/schema.js"],"names":[],"mappings":"AAGA;;;;;;;;;GASG;AACH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqBE;AAOF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAA4D;qBAzCvC,UAAU"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@justair/justair-library",
3
- "version": "6.14.0",
3
+ "version": "7.0.0",
4
4
  "description": "JustAir Internal Library",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
@@ -33,12 +33,17 @@
33
33
  ],
34
34
  "author": "Britney Epps",
35
35
  "license": "ISC",
36
+ "engines": {
37
+ "node": ">=20.19.0"
38
+ },
36
39
  "dependencies": {
37
40
  "jose": "^5.10.0",
38
- "mongoose": "^7.8.3",
39
41
  "nanoid": "^5.1.6",
40
42
  "winston": "^3.10.0"
41
43
  },
44
+ "peerDependencies": {
45
+ "mongoose": "^9.0.0"
46
+ },
42
47
  "jest": {
43
48
  "testEnvironment": "node",
44
49
  "transform": {},
@@ -49,6 +54,7 @@
49
54
  "@types/node": "^16.0.0",
50
55
  "jest": "^29",
51
56
  "mongodb-memory-server": "^11.2.0",
57
+ "mongoose": "^9.0.0",
52
58
  "jest-environment-node": "^29",
53
59
  "ts-node": "^10.0.0",
54
60
  "typescript": "^5.3.2"
package/src/config/db.js CHANGED
@@ -3,11 +3,15 @@ import mongoose from "mongoose";
3
3
  class Database {
4
4
  static instances = new Map(); // Store multiple instances by connection key
5
5
 
6
- constructor({ CONNECTION_URL, database }) {
6
+ constructor({ CONNECTION_URL, database, options = {} }) {
7
7
  this.CONNECTION_URL = CONNECTION_URL;
8
8
  this.database = database;
9
9
  this.connectionKey = `${CONNECTION_URL}:${database}`;
10
10
  this.isConnected = false;
11
+ // Per-instance mongoose connect options, merged over the defaults in
12
+ // connect(). Lets local/test targets disable TLS and JA-1781 pass
13
+ // Queryable Encryption options without another interface change.
14
+ this.options = options;
11
15
  }
12
16
 
13
17
  async connect() {
@@ -40,6 +44,7 @@ class Database {
40
44
  authSource: "admin",
41
45
  ssl: true,
42
46
  dbName: this.database,
47
+ ...this.options,
43
48
  });
44
49
 
45
50
  this.isConnected = true;
@@ -0,0 +1,46 @@
1
+ import mongoose from 'mongoose';
2
+ import { MongoMemoryServer } from 'mongodb-memory-server';
3
+ import Database from '../db.js';
4
+
5
+ let mongoServer;
6
+
7
+ beforeAll(async () => {
8
+ mongoServer = await MongoMemoryServer.create();
9
+ });
10
+
11
+ afterAll(async () => {
12
+ if (mongoose.connection.readyState === 1) {
13
+ await mongoose.disconnect();
14
+ }
15
+ await mongoServer.stop();
16
+ });
17
+
18
+ // JA-878: Database is the platform-wide connection choke point. These smoke
19
+ // tests pin connect/disconnect behavior under the mongoose 9 / driver 7 pair.
20
+ test('connects and disconnects cleanly', async () => {
21
+ const db = new Database({
22
+ CONNECTION_URL: mongoServer.getUri(),
23
+ database: 'ja878-smoke',
24
+ options: { ssl: false, authSource: undefined },
25
+ });
26
+
27
+ await db.connect();
28
+ expect(db.isConnected).toBe(true);
29
+ expect(mongoose.connection.readyState).toBe(1);
30
+ expect(Database.getCurrentDatabase()).toBe('ja878-smoke');
31
+
32
+ await db.disconnect();
33
+ expect(db.isConnected).toBe(false);
34
+ expect(mongoose.connection.readyState).toBe(0);
35
+ });
36
+
37
+ test('bad URI rejects with a clear error instead of hanging', async () => {
38
+ const db = new Database({
39
+ CONNECTION_URL: 'mongodb://127.0.0.1:1/unreachable',
40
+ database: 'nope',
41
+ options: { ssl: false, authSource: undefined, serverSelectionTimeoutMS: 2000, connectTimeoutMS: 2000 },
42
+ });
43
+
44
+ await expect(db.connect()).rejects.toThrow();
45
+ expect(db.isConnected).toBe(false);
46
+ });
@@ -162,12 +162,10 @@ organizationsSchema.methods.setRateLimitProperties = function () {
162
162
  });
163
163
  };
164
164
 
165
- organizationsSchema.pre("save", function (next) {
165
+ organizationsSchema.pre("save", function () {
166
166
  if (this.isModified("orgAPIKey")) {
167
167
  this.setRateLimitProperties();
168
168
  }
169
-
170
- next();
171
169
  });
172
170
 
173
171
  // Name-based sorting index