@justair/justair-library 5.3.0-alpha.0bb41e3 → 5.3.0-alpha.5884d16

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/index.d.ts CHANGED
@@ -68,7 +68,9 @@ import { Samples } from "./models/samples.js";
68
68
  import { samplesAuditSchema } from "./models/samples.js";
69
69
  import { SamplesAudit } from "./models/samples.js";
70
70
  import { sampleParameterReferenceConcentrations } from "./models/samples.js";
71
+ import { passwordResetTokenSchema } from "./models/passwordResetToken.js";
72
+ import { PasswordResetToken } from "./models/passwordResetToken.js";
71
73
  import { PARAMETERS } from "./constants/pollutants.js";
72
74
  import { HEAVY_METALS } from "./constants/pollutants.js";
73
- export { Database, adminSchema, Admin, configurationsSchema, Configurations, measurementsSchema, Measurements, monitorRequestsSchema, MonitorRequests, monitorsSchema, Monitors, organizationsSchema, Organizations, usersSchema, Users, eventsSchema, Events, lightMonitorSchema, LightMonitors, monitorSuppliersSchema, MonitorSuppliers, contextsSchema, Contexts, parametersSchema, Parameters, announcementSchema, Announcements, jobsSchema, Jobs, apiKeySchema, ApiKey, UsageMetrics, usageMetricsSchema, Audit, auditSchema, EventsAudit, eventsAuditSchema, MonitorAudit, monitorAuditSchema, parametersEnum, deploymentTypesEnum, AlertsAudit, Alerts, alertsSchema, alertsAuditSchema, Features, featuresSchema, dataCompletenessSchema, DataCompleteness, networkMetricsSchema, NetworkMetrics, rateOfChangeSchema, RateOfChange, sitesSchema, Sites, sampleSitesSchema, SampleSites, sampleSiteAuditSchema, SampleSiteAudit, sampleParametersEnum, samplesSchema, Samples, samplesAuditSchema, SamplesAudit, sampleParameterReferenceConcentrations, PARAMETERS, HEAVY_METALS };
75
+ export { Database, adminSchema, Admin, configurationsSchema, Configurations, measurementsSchema, Measurements, monitorRequestsSchema, MonitorRequests, monitorsSchema, Monitors, organizationsSchema, Organizations, usersSchema, Users, eventsSchema, Events, lightMonitorSchema, LightMonitors, monitorSuppliersSchema, MonitorSuppliers, contextsSchema, Contexts, parametersSchema, Parameters, announcementSchema, Announcements, jobsSchema, Jobs, apiKeySchema, ApiKey, UsageMetrics, usageMetricsSchema, Audit, auditSchema, EventsAudit, eventsAuditSchema, MonitorAudit, monitorAuditSchema, parametersEnum, deploymentTypesEnum, AlertsAudit, Alerts, alertsSchema, alertsAuditSchema, Features, featuresSchema, dataCompletenessSchema, DataCompleteness, networkMetricsSchema, NetworkMetrics, rateOfChangeSchema, RateOfChange, sitesSchema, Sites, sampleSitesSchema, SampleSites, sampleSiteAuditSchema, SampleSiteAudit, sampleParametersEnum, samplesSchema, Samples, samplesAuditSchema, SamplesAudit, sampleParameterReferenceConcentrations, passwordResetTokenSchema, PasswordResetToken, PARAMETERS, HEAVY_METALS };
74
76
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.js"],"names":[],"mappings":"AAgFA;;;iBAEC;yBA1BwB,oBAAoB;qBADxB,gBAAgB;4BAvDF,mBAAmB;sBAAnB,mBAAmB;qCAI/C,4BAA4B;+BAA5B,4BAA4B;mCAM5B,0BAA0B;6BAA1B,0BAA0B;sCAI1B,6BAA6B;gCAA7B,6BAA6B;+BAQ7B,sBAAsB;yBAAtB,sBAAsB;oCACsB,2BAA2B;8BAA3B,2BAA2B;4BAQ3C,mBAAmB;sBAAnB,mBAAmB;6BAM/C,oBAAoB;uBAApB,oBAAoB;mCAbuB,2BAA2B;8BAA3B,2BAA2B;uCAItE,8BAA8B;iCAA9B,8BAA8B;+BACI,sBAAsB;yBAAtB,sBAAsB;iCAClB,wBAAwB;2BAAxB,wBAAwB;mCAQnB,2BAA2B;8BAA3B,2BAA2B;2BAC5C,kBAAkB;qBAAlB,kBAAkB;6BACd,oBAAoB;uBAApB,oBAAoB;6BACR,0BAA0B;mCAA1B,0BAA0B;sBA/BpE,0BAA0B;4BAA1B,0BAA0B;4BA2B1B,oBAAoB;kCAApB,oBAAoB;6BAf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;+BAAtB,sBAAsB;oCAAtB,sBAAsB;4BAyBtB,oBAAoB;uBAApB,oBAAoB;6BAApB,oBAAoB;kCAApB,oBAAoB;yBACc,sBAAsB;+BAAtB,sBAAsB;uCAIxD,8BAA8B;iCAA9B,8BAA8B;qCACgB,4BAA4B;+BAA5B,4BAA4B;mCAChC,0BAA0B;6BAA1B,0BAA0B;4BAMxC,mBAAmB;sBAAnB,mBAAmB;kCAS/C,yBAAyB;4BAAzB,yBAAyB;sCAAzB,yBAAyB;gCAAzB,yBAAyB;qCAAzB,yBAAyB;8BASzB,qBAAqB;wBAArB,qBAAqB;mCAArB,qBAAqB;6BAArB,qBAAqB;uDAArB,qBAAqB;yCAMrB,gCAAgC;mCAAhC,gCAAgC;2BA3BE,2BAA2B;6BAA3B,2BAA2B"}
@@ -1 +1 @@
1
- {"version":3,"file":"admin.d.ts","sourceRoot":"","sources":["../../src/models/admin.js"],"names":[],"mappings":"AAEA,8BAcG;AAUH,wBAAmD"}
1
+ {"version":3,"file":"admin.d.ts","sourceRoot":"","sources":["../../src/models/admin.js"],"names":[],"mappings":"AAEA,8BAaG;AAUH,wBAAmD"}
@@ -0,0 +1,185 @@
1
+ /**
2
+ * PasswordResetToken — short-lived single-use tokens for admin password reset.
3
+ *
4
+ * Lifecycle (state machine):
5
+ *
6
+ * forgotPassword(email)
7
+ * |
8
+ * v
9
+ * [issued] tokenHash = sha256(raw), usedAt = null, expiresAt = now+30min
10
+ * |
11
+ * | reset succeeds expires (no click)
12
+ * v |
13
+ * [used] usedAt = <Date> ----+ v
14
+ * | [expired] expiresAt < now, usedAt still null
15
+ * | |
16
+ * +---------+
17
+ * |
18
+ * v
19
+ * TTL purge
20
+ * (24h after expiresAt)
21
+ *
22
+ * The 24h TTL grace window keeps used+expired docs around so the API can return
23
+ * 410 EXPIRED (vs 401 INVALID) for clicks just past the 30-min window. The user
24
+ * never sees the underlying state — just the right error message.
25
+ *
26
+ * The raw token string (sent in the email URL) is NEVER stored. Only sha256 hex.
27
+ */
28
+ export const passwordResetTokenSchema: mongoose.Schema<any, mongoose.Model<any, any, any, any, any, any>, {}, {}, {}, {}, {
29
+ timestamps: true;
30
+ }, {
31
+ createdAt: NativeDate;
32
+ updatedAt: NativeDate;
33
+ } & {
34
+ adminId: {
35
+ prototype?: mongoose.Types.ObjectId;
36
+ cacheHexString?: unknown;
37
+ generate?: {};
38
+ createFromTime?: {};
39
+ createFromHexString?: {};
40
+ createFromBase64?: {};
41
+ isValid?: {};
42
+ };
43
+ tokenHash: string;
44
+ expiresAt: Date;
45
+ usedAt: Date;
46
+ }, mongoose.Document<unknown, {}, mongoose.FlatRecord<{
47
+ createdAt: NativeDate;
48
+ updatedAt: NativeDate;
49
+ } & {
50
+ adminId: {
51
+ prototype?: mongoose.Types.ObjectId;
52
+ cacheHexString?: unknown;
53
+ generate?: {};
54
+ createFromTime?: {};
55
+ createFromHexString?: {};
56
+ createFromBase64?: {};
57
+ isValid?: {};
58
+ };
59
+ tokenHash: string;
60
+ expiresAt: Date;
61
+ usedAt: Date;
62
+ }>> & mongoose.FlatRecord<{
63
+ createdAt: NativeDate;
64
+ updatedAt: NativeDate;
65
+ } & {
66
+ adminId: {
67
+ prototype?: mongoose.Types.ObjectId;
68
+ cacheHexString?: unknown;
69
+ generate?: {};
70
+ createFromTime?: {};
71
+ createFromHexString?: {};
72
+ createFromBase64?: {};
73
+ isValid?: {};
74
+ };
75
+ tokenHash: string;
76
+ expiresAt: Date;
77
+ usedAt: Date;
78
+ }> & {
79
+ _id: mongoose.Types.ObjectId;
80
+ }>;
81
+ export const PasswordResetToken: mongoose.Model<{
82
+ createdAt: NativeDate;
83
+ updatedAt: NativeDate;
84
+ } & {
85
+ adminId: {
86
+ prototype?: mongoose.Types.ObjectId;
87
+ cacheHexString?: unknown;
88
+ generate?: {};
89
+ createFromTime?: {};
90
+ createFromHexString?: {};
91
+ createFromBase64?: {};
92
+ isValid?: {};
93
+ };
94
+ tokenHash: string;
95
+ expiresAt: Date;
96
+ usedAt: Date;
97
+ }, {}, {}, {}, mongoose.Document<unknown, {}, {
98
+ createdAt: NativeDate;
99
+ updatedAt: NativeDate;
100
+ } & {
101
+ adminId: {
102
+ prototype?: mongoose.Types.ObjectId;
103
+ cacheHexString?: unknown;
104
+ generate?: {};
105
+ createFromTime?: {};
106
+ createFromHexString?: {};
107
+ createFromBase64?: {};
108
+ isValid?: {};
109
+ };
110
+ tokenHash: string;
111
+ expiresAt: Date;
112
+ usedAt: Date;
113
+ }> & {
114
+ createdAt: NativeDate;
115
+ updatedAt: NativeDate;
116
+ } & {
117
+ adminId: {
118
+ prototype?: mongoose.Types.ObjectId;
119
+ cacheHexString?: unknown;
120
+ generate?: {};
121
+ createFromTime?: {};
122
+ createFromHexString?: {};
123
+ createFromBase64?: {};
124
+ isValid?: {};
125
+ };
126
+ tokenHash: string;
127
+ expiresAt: Date;
128
+ usedAt: Date;
129
+ } & {
130
+ _id: mongoose.Types.ObjectId;
131
+ }, mongoose.Schema<any, mongoose.Model<any, any, any, any, any, any>, {}, {}, {}, {}, {
132
+ timestamps: true;
133
+ }, {
134
+ createdAt: NativeDate;
135
+ updatedAt: NativeDate;
136
+ } & {
137
+ adminId: {
138
+ prototype?: mongoose.Types.ObjectId;
139
+ cacheHexString?: unknown;
140
+ generate?: {};
141
+ createFromTime?: {};
142
+ createFromHexString?: {};
143
+ createFromBase64?: {};
144
+ isValid?: {};
145
+ };
146
+ tokenHash: string;
147
+ expiresAt: Date;
148
+ usedAt: Date;
149
+ }, mongoose.Document<unknown, {}, mongoose.FlatRecord<{
150
+ createdAt: NativeDate;
151
+ updatedAt: NativeDate;
152
+ } & {
153
+ adminId: {
154
+ prototype?: mongoose.Types.ObjectId;
155
+ cacheHexString?: unknown;
156
+ generate?: {};
157
+ createFromTime?: {};
158
+ createFromHexString?: {};
159
+ createFromBase64?: {};
160
+ isValid?: {};
161
+ };
162
+ tokenHash: string;
163
+ expiresAt: Date;
164
+ usedAt: Date;
165
+ }>> & mongoose.FlatRecord<{
166
+ createdAt: NativeDate;
167
+ updatedAt: NativeDate;
168
+ } & {
169
+ adminId: {
170
+ prototype?: mongoose.Types.ObjectId;
171
+ cacheHexString?: unknown;
172
+ generate?: {};
173
+ createFromTime?: {};
174
+ createFromHexString?: {};
175
+ createFromBase64?: {};
176
+ isValid?: {};
177
+ };
178
+ tokenHash: string;
179
+ expiresAt: Date;
180
+ usedAt: Date;
181
+ }> & {
182
+ _id: mongoose.Types.ObjectId;
183
+ }>>;
184
+ import mongoose from "mongoose";
185
+ //# sourceMappingURL=passwordResetToken.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"passwordResetToken.d.ts","sourceRoot":"","sources":["../../src/models/passwordResetToken.js"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsBE;AAaF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAGE;qBAnEmB,UAAU"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=passwordResetToken.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"passwordResetToken.test.d.ts","sourceRoot":"","sources":["../../../src/models/tests/passwordResetToken.test.js"],"names":[],"mappings":""}
@@ -1 +1 @@
1
- {"version":3,"file":"users.d.ts","sourceRoot":"","sources":["../../src/models/users.js"],"names":[],"mappings":"AAEA,8BA+CE;AAIF,wBAAmD"}
1
+ {"version":3,"file":"users.d.ts","sourceRoot":"","sources":["../../src/models/users.js"],"names":[],"mappings":"AAEA,8BA8CE;AAIF,wBAAmD"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@justair/justair-library",
3
- "version": "5.3.0-alpha.0bb41e3",
3
+ "version": "5.3.0-alpha.5884d16",
4
4
  "description": "JustAir Internal Library",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
package/src/index.js CHANGED
@@ -78,6 +78,12 @@ import {
78
78
  sampleParameterReferenceConcentrations,
79
79
  } from "./models/samples.js";
80
80
 
81
+ // PasswordResetToken (admin password-reset flow)
82
+ import {
83
+ passwordResetTokenSchema,
84
+ PasswordResetToken,
85
+ } from "./models/passwordResetToken.js";
86
+
81
87
  export function createLoggerInstance({ DATADOG_API_KEY, APPLICATION_NAME }) {
82
88
  return new CustomLogger({ DATADOG_API_KEY, APPLICATION_NAME });
83
89
  }
@@ -151,6 +157,9 @@ export {
151
157
  samplesAuditSchema,
152
158
  SamplesAudit,
153
159
  sampleParameterReferenceConcentrations,
160
+ // PasswordResetToken
161
+ passwordResetTokenSchema,
162
+ PasswordResetToken,
154
163
  // Pollutant constants
155
164
  PARAMETERS,
156
165
  HEAVY_METALS,
@@ -1,8 +1,7 @@
1
1
  import mongoose from 'mongoose';
2
2
 
3
3
  const adminSchema = mongoose.Schema({
4
- firstName: String,
5
- lastName: String,
4
+ name: String,
6
5
  phone: String,
7
6
  email: String,
8
7
  password: String,
@@ -0,0 +1,70 @@
1
+ import mongoose from "mongoose";
2
+
3
+ /**
4
+ * PasswordResetToken — short-lived single-use tokens for admin password reset.
5
+ *
6
+ * Lifecycle (state machine):
7
+ *
8
+ * forgotPassword(email)
9
+ * |
10
+ * v
11
+ * [issued] tokenHash = sha256(raw), usedAt = null, expiresAt = now+30min
12
+ * |
13
+ * | reset succeeds expires (no click)
14
+ * v |
15
+ * [used] usedAt = <Date> ----+ v
16
+ * | [expired] expiresAt < now, usedAt still null
17
+ * | |
18
+ * +---------+
19
+ * |
20
+ * v
21
+ * TTL purge
22
+ * (24h after expiresAt)
23
+ *
24
+ * The 24h TTL grace window keeps used+expired docs around so the API can return
25
+ * 410 EXPIRED (vs 401 INVALID) for clicks just past the 30-min window. The user
26
+ * never sees the underlying state — just the right error message.
27
+ *
28
+ * The raw token string (sent in the email URL) is NEVER stored. Only sha256 hex.
29
+ */
30
+ const passwordResetTokenSchema = new mongoose.Schema(
31
+ {
32
+ adminId: {
33
+ type: mongoose.Types.ObjectId,
34
+ ref: "Admin",
35
+ required: true,
36
+ },
37
+ tokenHash: {
38
+ type: String,
39
+ required: true,
40
+ unique: true,
41
+ },
42
+ expiresAt: {
43
+ type: Date,
44
+ required: true,
45
+ },
46
+ usedAt: {
47
+ type: Date,
48
+ default: null,
49
+ },
50
+ },
51
+ { timestamps: true },
52
+ );
53
+
54
+ // TTL: docs are purged 24h after expiresAt. The buffer preserves the
55
+ // expired-vs-invalid distinction for the API window after the user-facing
56
+ // 30-min expiry.
57
+ passwordResetTokenSchema.index(
58
+ { expiresAt: 1 },
59
+ { expireAfterSeconds: 60 * 60 * 24 },
60
+ );
61
+
62
+ // Reissue path: invalidate prior unused tokens for the same admin.
63
+ passwordResetTokenSchema.index({ adminId: 1, usedAt: 1 });
64
+
65
+ const PasswordResetToken = mongoose.model(
66
+ "PasswordResetToken",
67
+ passwordResetTokenSchema,
68
+ );
69
+
70
+ export { passwordResetTokenSchema, PasswordResetToken };
@@ -2,8 +2,7 @@ import mongoose from "mongoose";
2
2
 
3
3
  const usersSchema = mongoose.Schema(
4
4
  {
5
- firstName: String,
6
- lastName: String,
5
+ name: String,
7
6
  phone: String,
8
7
  email: String,
9
8
  zipCode: String,