@justair/justair-library 7.14.0 → 7.15.0-alpha.4db0518
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 +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/models/emailChangeToken.d.ts +130 -0
- package/dist/models/emailChangeToken.d.ts.map +1 -0
- package/dist/models/tests/emailChangeToken.test.d.ts +2 -0
- package/dist/models/tests/emailChangeToken.test.d.ts.map +1 -0
- package/dist/modules/audit/actions.d.ts +5 -2
- package/dist/modules/audit/actions.d.ts.map +1 -1
- package/dist/modules/audit/schema.d.ts +12 -12
- package/package.json +1 -1
- package/src/index.js +7 -0
- package/src/models/emailChangeToken.js +41 -0
- package/src/modules/audit/actions.js +4 -1
- package/src/modules/audit/tests/actions.test.js +3 -1
package/dist/index.d.ts
CHANGED
|
@@ -75,6 +75,8 @@ import { SamplesAudit } from "./models/samples.js";
|
|
|
75
75
|
import { sampleParameterReferenceConcentrations } from "./models/samples.js";
|
|
76
76
|
import { passwordResetTokenSchema } from "./models/passwordResetToken.js";
|
|
77
77
|
import { PasswordResetToken } from "./models/passwordResetToken.js";
|
|
78
|
+
import { emailChangeTokenSchema } from "./models/emailChangeToken.js";
|
|
79
|
+
import { EmailChangeToken } from "./models/emailChangeToken.js";
|
|
78
80
|
import { monitorEpisodesSchema } from "./models/monitorEpisodes.js";
|
|
79
81
|
import { MonitorEpisode } from "./models/monitorEpisodes.js";
|
|
80
82
|
import { userNotificationsSchema } from "./models/userNotifications.js";
|
|
@@ -126,5 +128,5 @@ import { validateQuietHours } from "./utils/quietHours.js";
|
|
|
126
128
|
import { getZoneMinutes } from "./utils/quietHours.js";
|
|
127
129
|
import { isInQuietWindow } from "./utils/quietHours.js";
|
|
128
130
|
import { resolveQuietHours } from "./utils/quietHours.js";
|
|
129
|
-
export { Database, adminSchema, Admin, configurationsSchema, Configurations, measurementsSchema, Measurements, monitorRequestsSchema, MonitorRequests, monitorsSchema, Monitors, organizationsSchema, Organizations, usersSchema, Users, COOKIE_CONSENT_CATEGORIES, COOKIE_CONSENT_VALUES, validateCookieConsent, 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, changeStreamCheckpointsSchema, ChangeStreamCheckpoints, sitesSchema, Sites, sampleSitesSchema, SampleSites, sampleSiteAuditSchema, SampleSiteAudit, sampleParametersEnum, samplesSchema, Samples, samplesAuditSchema, SamplesAudit, sampleParameterReferenceConcentrations, passwordResetTokenSchema, PasswordResetToken, monitorEpisodesSchema, MonitorEpisode, userNotificationsSchema, UserNotification, AqiAlertNotification, DeviceOfflineNotification, WeeklyDigestNotification, AccountNotification, NOTIFICATION_KINDS, NOTIFICATION_CHANNELS, DELIVERY_STATUSES, DATA_DOWNLOAD_TYPES, dataDownloadSchema, DataDownloads, AqiDataDownload, SampleDataDownload, DATA_DOWNLOAD_MAX_RANGE_DAYS, DATA_DOWNLOAD_ERRORS, validateDataDownloadDateOrder, validateDataDownloadMaxDateRange, validateDataDownloadEmail, normalizeDataDownloadEmail, validateDataDownloadTimezone, normalizeDataDownloadTimezone, PARAMETERS, HEAVY_METALS, ALERT_LEVEL_WEIGHTS, getAlertWeight, TERMS_VERSION_MAX_LENGTH, DEVICE_TYPES, DEVICE_TYPE_VALUES, isAqiCapableDeviceType, AQI_CAPABLE_DEVICE_TYPES, JOB_CATEGORIES, JOB_CATEGORY_VALUES, SUPPLIER_DISPLAY_NAMES, getSupplierDisplayName, projectSubscribedMonitors, resolveSubscribedMonitorIdsByUser, VISIBLE_SITE_MONITOR_FILTER, SUBSCRIBED_DEVICES_ERRORS, splitName, DEFAULT_QUIET_HOURS, DEFAULT_TIMEZONE, QUIET_HOURS_ERRORS, isValidTimeString, isValidIANATimezone, validateQuietHours, getZoneMinutes, isInQuietWindow, resolveQuietHours };
|
|
131
|
+
export { Database, adminSchema, Admin, configurationsSchema, Configurations, measurementsSchema, Measurements, monitorRequestsSchema, MonitorRequests, monitorsSchema, Monitors, organizationsSchema, Organizations, usersSchema, Users, COOKIE_CONSENT_CATEGORIES, COOKIE_CONSENT_VALUES, validateCookieConsent, 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, changeStreamCheckpointsSchema, ChangeStreamCheckpoints, sitesSchema, Sites, sampleSitesSchema, SampleSites, sampleSiteAuditSchema, SampleSiteAudit, sampleParametersEnum, samplesSchema, Samples, samplesAuditSchema, SamplesAudit, sampleParameterReferenceConcentrations, passwordResetTokenSchema, PasswordResetToken, emailChangeTokenSchema, EmailChangeToken, monitorEpisodesSchema, MonitorEpisode, userNotificationsSchema, UserNotification, AqiAlertNotification, DeviceOfflineNotification, WeeklyDigestNotification, AccountNotification, NOTIFICATION_KINDS, NOTIFICATION_CHANNELS, DELIVERY_STATUSES, DATA_DOWNLOAD_TYPES, dataDownloadSchema, DataDownloads, AqiDataDownload, SampleDataDownload, DATA_DOWNLOAD_MAX_RANGE_DAYS, DATA_DOWNLOAD_ERRORS, validateDataDownloadDateOrder, validateDataDownloadMaxDateRange, validateDataDownloadEmail, normalizeDataDownloadEmail, validateDataDownloadTimezone, normalizeDataDownloadTimezone, PARAMETERS, HEAVY_METALS, ALERT_LEVEL_WEIGHTS, getAlertWeight, TERMS_VERSION_MAX_LENGTH, DEVICE_TYPES, DEVICE_TYPE_VALUES, isAqiCapableDeviceType, AQI_CAPABLE_DEVICE_TYPES, JOB_CATEGORIES, JOB_CATEGORY_VALUES, SUPPLIER_DISPLAY_NAMES, getSupplierDisplayName, projectSubscribedMonitors, resolveSubscribedMonitorIdsByUser, VISIBLE_SITE_MONITOR_FILTER, SUBSCRIBED_DEVICES_ERRORS, splitName, DEFAULT_QUIET_HOURS, DEFAULT_TIMEZONE, QUIET_HOURS_ERRORS, isValidTimeString, isValidIANATimezone, validateQuietHours, getZoneMinutes, isInQuietWindow, resolveQuietHours };
|
|
130
132
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.js"],"names":[],"mappings":"AAmLA;;;iBAEC;yBAhHwB,oBAAoB;qBADxB,gBAAgB;4BApEF,mBAAmB;sBAAnB,mBAAmB;qCAI/C,4BAA4B;+BAA5B,4BAA4B;mCAM5B,0BAA0B;6BAA1B,0BAA0B;sCAI1B,6BAA6B;gCAA7B,6BAA6B;+BAQ7B,sBAAsB;yBAAtB,sBAAsB;oCACsB,2BAA2B;8BAA3B,2BAA2B;4BAcvE,mBAAmB;sBAAnB,mBAAmB;0CAAnB,mBAAmB;sCAAnB,mBAAmB;sCAAnB,mBAAmB;6BAMnB,oBAAoB;uBAApB,oBAAoB;mCAnBuB,2BAA2B;8BAA3B,2BAA2B;uCAItE,8BAA8B;iCAA9B,8BAA8B;+BACI,sBAAsB;yBAAtB,sBAAsB;iCAClB,wBAAwB;2BAAxB,wBAAwB;mCAcnB,2BAA2B;8BAA3B,2BAA2B;2BAC5C,kBAAkB;qBAAlB,kBAAkB;6BACd,oBAAoB;uBAApB,oBAAoB;6BACR,0BAA0B;mCAA1B,0BAA0B;sBArCpE,0BAA0B;4BAA1B,0BAA0B;4BAiC1B,oBAAoB;kCAApB,oBAAoB;6BArBpB,sBAAsB;mCAAtB,sBAAsB;+BAAtB,sBAAsB;oCAAtB,sBAAsB;4BA+BtB,oBAAoB;uBAApB,oBAAoB;6BAApB,oBAAoB;kCAApB,oBAAoB;yBACc,sBAAsB;+BAAtB,sBAAsB;uCAIxD,8BAA8B;iCAA9B,8BAA8B;qCAI9B,4BAA4B;+BAA5B,4BAA4B;mCACc,0BAA0B;6BAA1B,0BAA0B;8CAIpE,qCAAqC;wCAArC,qCAAqC;4BAwDT,mBAAmB;sBAAnB,mBAAmB;kCAS/C,yBAAyB;4BAAzB,yBAAyB;sCAAzB,yBAAyB;gCAAzB,yBAAyB;qCAAzB,yBAAyB;8BASzB,qBAAqB;wBAArB,qBAAqB;mCAArB,qBAAqB;6BAArB,qBAAqB;uDAArB,qBAAqB;yCAIrB,gCAAgC;mCAAhC,gCAAgC;uCAIhC,8BAA8B;iCAA9B,8BAA8B;sCAzD9B,6BAA6B;+BAA7B,6BAA6B;wCAW7B,+BAA+B;iCAA/B,+BAA+B;qCAA/B,+BAA+B;0CAA/B,+BAA+B;yCAA/B,+BAA+B;oCAA/B,+BAA+B;mCAA/B,+BAA+B;sCAA/B,+BAA+B;kCAA/B,+BAA+B;oCA3BF,8BAA8B;mCA+E3D,2BAA2B;8BAA3B,2BAA2B;gCAA3B,2BAA2B;mCAA3B,2BAA2B;+DAsB3B,mCAAmC;qCAAnC,mCAAmC;mEAAnC,mCAAmC;yEAAnC,mCAAmC;mEAAnC,mCAAmC;qEAAnC,mCAAmC;yEAAnC,mCAAmC;2EAAnC,mCAAmC;2BA3GD,2BAA2B;6BAA3B,2BAA2B;oCAI7D,4BAA4B;+BAA5B,4BAA4B;yCAGM,sBAAsB;6BAMxD,4BAA4B;mCAA5B,4BAA4B;uCAA5B,4BAA4B;yCAA5B,4BAA4B;+BACiB,8BAA8B;oCAA9B,8BAA8B;uCAI3E,0BAA0B;uCAA1B,0BAA0B;0CAgC1B,8BAA8B;kDAA9B,8BAA8B;4CAA9B,8BAA8B;0CAA9B,8BAA8B;0BAhBX,sBAAsB;oCASzC,uBAAuB;iCAtCG,0BAA0B;mCAsCpD,uBAAuB;kCAAvB,uBAAuB;oCACM,qBAAqB;mCADlD,uBAAuB;+BAAvB,uBAAuB;gCAAvB,uBAAuB;kCAAvB,uBAAuB"}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
export const emailChangeTokenSchema: mongoose.Schema<any, mongoose.Model<any, any, any, any, any, any, any>, {}, {}, {}, {}, {
|
|
2
|
+
timestamps: true;
|
|
3
|
+
}, {
|
|
4
|
+
adminId: mongoose.Types.ObjectId;
|
|
5
|
+
tokenHash: string;
|
|
6
|
+
used: boolean;
|
|
7
|
+
expiresAt: NativeDate;
|
|
8
|
+
newEmail: string;
|
|
9
|
+
} & mongoose.DefaultTimestampProps, mongoose.Document<unknown, {}, {
|
|
10
|
+
adminId: mongoose.Types.ObjectId;
|
|
11
|
+
tokenHash: string;
|
|
12
|
+
used: boolean;
|
|
13
|
+
expiresAt: NativeDate;
|
|
14
|
+
newEmail: string;
|
|
15
|
+
} & mongoose.DefaultTimestampProps, {
|
|
16
|
+
id: string;
|
|
17
|
+
}, Omit<mongoose.DefaultSchemaOptions, "timestamps"> & {
|
|
18
|
+
timestamps: true;
|
|
19
|
+
}> & Omit<{
|
|
20
|
+
adminId: mongoose.Types.ObjectId;
|
|
21
|
+
tokenHash: string;
|
|
22
|
+
used: boolean;
|
|
23
|
+
expiresAt: NativeDate;
|
|
24
|
+
newEmail: string;
|
|
25
|
+
} & mongoose.DefaultTimestampProps & {
|
|
26
|
+
_id: mongoose.Types.ObjectId;
|
|
27
|
+
} & {
|
|
28
|
+
__v: number;
|
|
29
|
+
}, "id"> & mongoose.HydratedDocumentOverrides<{
|
|
30
|
+
id: string;
|
|
31
|
+
}>, unknown, {
|
|
32
|
+
adminId: mongoose.Types.ObjectId;
|
|
33
|
+
tokenHash: string;
|
|
34
|
+
used: boolean;
|
|
35
|
+
expiresAt: NativeDate;
|
|
36
|
+
newEmail: string;
|
|
37
|
+
createdAt: NativeDate;
|
|
38
|
+
updatedAt: NativeDate;
|
|
39
|
+
} & {
|
|
40
|
+
_id: mongoose.Types.ObjectId;
|
|
41
|
+
} & {
|
|
42
|
+
__v: number;
|
|
43
|
+
}>;
|
|
44
|
+
export const EmailChangeToken: mongoose.Model<{
|
|
45
|
+
adminId: mongoose.Types.ObjectId;
|
|
46
|
+
tokenHash: string;
|
|
47
|
+
used: boolean;
|
|
48
|
+
expiresAt: NativeDate;
|
|
49
|
+
newEmail: string;
|
|
50
|
+
} & mongoose.DefaultTimestampProps, {}, {}, {
|
|
51
|
+
id: string;
|
|
52
|
+
}, mongoose.Document<unknown, {}, {
|
|
53
|
+
adminId: mongoose.Types.ObjectId;
|
|
54
|
+
tokenHash: string;
|
|
55
|
+
used: boolean;
|
|
56
|
+
expiresAt: NativeDate;
|
|
57
|
+
newEmail: string;
|
|
58
|
+
} & mongoose.DefaultTimestampProps, {
|
|
59
|
+
id: string;
|
|
60
|
+
}, {
|
|
61
|
+
timestamps: true;
|
|
62
|
+
}> & Omit<{
|
|
63
|
+
adminId: mongoose.Types.ObjectId;
|
|
64
|
+
tokenHash: string;
|
|
65
|
+
used: boolean;
|
|
66
|
+
expiresAt: NativeDate;
|
|
67
|
+
newEmail: string;
|
|
68
|
+
} & mongoose.DefaultTimestampProps & {
|
|
69
|
+
_id: mongoose.Types.ObjectId;
|
|
70
|
+
} & {
|
|
71
|
+
__v: number;
|
|
72
|
+
}, "id"> & mongoose.HydratedDocumentOverrides<{
|
|
73
|
+
id: string;
|
|
74
|
+
}>, mongoose.Schema<any, mongoose.Model<any, any, any, any, any, any, any>, {}, {}, {}, {}, {
|
|
75
|
+
timestamps: true;
|
|
76
|
+
}, {
|
|
77
|
+
adminId: mongoose.Types.ObjectId;
|
|
78
|
+
tokenHash: string;
|
|
79
|
+
used: boolean;
|
|
80
|
+
expiresAt: NativeDate;
|
|
81
|
+
newEmail: string;
|
|
82
|
+
} & mongoose.DefaultTimestampProps, mongoose.Document<unknown, {}, {
|
|
83
|
+
adminId: mongoose.Types.ObjectId;
|
|
84
|
+
tokenHash: string;
|
|
85
|
+
used: boolean;
|
|
86
|
+
expiresAt: NativeDate;
|
|
87
|
+
newEmail: string;
|
|
88
|
+
} & mongoose.DefaultTimestampProps, {
|
|
89
|
+
id: string;
|
|
90
|
+
}, Omit<mongoose.DefaultSchemaOptions, "timestamps"> & {
|
|
91
|
+
timestamps: true;
|
|
92
|
+
}> & Omit<{
|
|
93
|
+
adminId: mongoose.Types.ObjectId;
|
|
94
|
+
tokenHash: string;
|
|
95
|
+
used: boolean;
|
|
96
|
+
expiresAt: NativeDate;
|
|
97
|
+
newEmail: string;
|
|
98
|
+
} & mongoose.DefaultTimestampProps & {
|
|
99
|
+
_id: mongoose.Types.ObjectId;
|
|
100
|
+
} & {
|
|
101
|
+
__v: number;
|
|
102
|
+
}, "id"> & mongoose.HydratedDocumentOverrides<{
|
|
103
|
+
id: string;
|
|
104
|
+
}>, unknown, {
|
|
105
|
+
adminId: mongoose.Types.ObjectId;
|
|
106
|
+
tokenHash: string;
|
|
107
|
+
used: boolean;
|
|
108
|
+
expiresAt: NativeDate;
|
|
109
|
+
newEmail: string;
|
|
110
|
+
createdAt: NativeDate;
|
|
111
|
+
updatedAt: NativeDate;
|
|
112
|
+
} & {
|
|
113
|
+
_id: mongoose.Types.ObjectId;
|
|
114
|
+
} & {
|
|
115
|
+
__v: number;
|
|
116
|
+
}>, {
|
|
117
|
+
adminId: mongoose.Types.ObjectId;
|
|
118
|
+
tokenHash: string;
|
|
119
|
+
used: boolean;
|
|
120
|
+
expiresAt: NativeDate;
|
|
121
|
+
newEmail: string;
|
|
122
|
+
createdAt: NativeDate;
|
|
123
|
+
updatedAt: NativeDate;
|
|
124
|
+
} & {
|
|
125
|
+
_id: mongoose.Types.ObjectId;
|
|
126
|
+
} & {
|
|
127
|
+
__v: number;
|
|
128
|
+
}>;
|
|
129
|
+
import mongoose from 'mongoose';
|
|
130
|
+
//# sourceMappingURL=emailChangeToken.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"emailChangeToken.d.ts","sourceRoot":"","sources":["../../src/models/emailChangeToken.js"],"names":[],"mappings":"AAuBA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAUE;AAKF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAAoF;qBAtC/D,UAAU"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"emailChangeToken.test.d.ts","sourceRoot":"","sources":["../../../src/models/tests/emailChangeToken.test.js"],"names":[],"mappings":""}
|
|
@@ -7,7 +7,8 @@
|
|
|
7
7
|
* Emit sites (in the services): login (success/failure), logout, forgot-password
|
|
8
8
|
* (requested/completed), silent refresh, and the admin mutation sites
|
|
9
9
|
* (create/update/delete, role.change when permissionName changes,
|
|
10
|
-
* deactivate/reactivate when isActive toggles)
|
|
10
|
+
* deactivate/reactivate when isActive toggles), and the admin email-change flow
|
|
11
|
+
* (requested when a verify link is mailed, verified when it is clicked; JA-3744).
|
|
11
12
|
*/
|
|
12
13
|
export const AUDIT_ACTIONS: Readonly<{
|
|
13
14
|
LOGIN_SUCCESS: "auth.login.success";
|
|
@@ -22,7 +23,9 @@ export const AUDIT_ACTIONS: Readonly<{
|
|
|
22
23
|
ADMIN_ROLE_CHANGE: "admin.role.change";
|
|
23
24
|
ADMIN_DEACTIVATE: "admin.deactivate";
|
|
24
25
|
ADMIN_REACTIVATE: "admin.reactivate";
|
|
26
|
+
ADMIN_EMAIL_CHANGE_REQUESTED: "admin.email.change.requested";
|
|
27
|
+
ADMIN_EMAIL_CHANGE_VERIFIED: "admin.email.change.verified";
|
|
25
28
|
}>;
|
|
26
29
|
/** Frozen list of all valid action strings — used as the AuditLog schema enum. */
|
|
27
|
-
export const AUDIT_ACTION_VALUES: readonly ("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")[];
|
|
30
|
+
export const AUDIT_ACTION_VALUES: readonly ("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" | "admin.email.change.requested" | "admin.email.change.verified")[];
|
|
28
31
|
//# sourceMappingURL=actions.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"actions.d.ts","sourceRoot":"","sources":["../../../src/modules/audit/actions.js"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"actions.d.ts","sourceRoot":"","sources":["../../../src/modules/audit/actions.js"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH;;;;;;;;;;;;;;;GAeG;AAEH,kFAAkF;AAClF,0XAA+E"}
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
export const auditLogSchema: mongoose.Schema<any, mongoose.Model<any, any, any, any, any, any, any>, {}, {}, {}, {}, {
|
|
12
12
|
timestamps: true;
|
|
13
13
|
}, {
|
|
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";
|
|
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" | "admin.email.change.requested" | "admin.email.change.verified";
|
|
15
15
|
outcome: "success" | "failure";
|
|
16
16
|
metadata?: any;
|
|
17
17
|
actor?: {
|
|
@@ -26,7 +26,7 @@ export const auditLogSchema: mongoose.Schema<any, mongoose.Model<any, any, any,
|
|
|
26
26
|
reason?: string;
|
|
27
27
|
requestId?: string;
|
|
28
28
|
} & mongoose.DefaultTimestampProps, mongoose.Document<unknown, {}, {
|
|
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";
|
|
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" | "admin.email.change.requested" | "admin.email.change.verified";
|
|
30
30
|
outcome: "success" | "failure";
|
|
31
31
|
metadata?: any;
|
|
32
32
|
actor?: {
|
|
@@ -45,7 +45,7 @@ export const auditLogSchema: mongoose.Schema<any, mongoose.Model<any, any, any,
|
|
|
45
45
|
}, Omit<mongoose.DefaultSchemaOptions, "timestamps"> & {
|
|
46
46
|
timestamps: true;
|
|
47
47
|
}> & Omit<{
|
|
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";
|
|
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" | "admin.email.change.requested" | "admin.email.change.verified";
|
|
49
49
|
outcome: "success" | "failure";
|
|
50
50
|
metadata?: any;
|
|
51
51
|
actor?: {
|
|
@@ -66,7 +66,7 @@ export const auditLogSchema: mongoose.Schema<any, mongoose.Model<any, any, any,
|
|
|
66
66
|
}, "id"> & mongoose.HydratedDocumentOverrides<{
|
|
67
67
|
id: string;
|
|
68
68
|
}>, unknown, {
|
|
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";
|
|
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" | "admin.email.change.requested" | "admin.email.change.verified";
|
|
70
70
|
outcome: "success" | "failure";
|
|
71
71
|
metadata?: any;
|
|
72
72
|
actor?: {
|
|
@@ -88,7 +88,7 @@ export const auditLogSchema: mongoose.Schema<any, mongoose.Model<any, any, any,
|
|
|
88
88
|
__v: number;
|
|
89
89
|
}>;
|
|
90
90
|
export const AuditLog: mongoose.Model<{
|
|
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";
|
|
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" | "admin.email.change.requested" | "admin.email.change.verified";
|
|
92
92
|
outcome: "success" | "failure";
|
|
93
93
|
metadata?: any;
|
|
94
94
|
actor?: {
|
|
@@ -105,7 +105,7 @@ export const AuditLog: mongoose.Model<{
|
|
|
105
105
|
} & mongoose.DefaultTimestampProps, {}, {}, {
|
|
106
106
|
id: string;
|
|
107
107
|
}, mongoose.Document<unknown, {}, {
|
|
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";
|
|
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" | "admin.email.change.requested" | "admin.email.change.verified";
|
|
109
109
|
outcome: "success" | "failure";
|
|
110
110
|
metadata?: any;
|
|
111
111
|
actor?: {
|
|
@@ -124,7 +124,7 @@ export const AuditLog: mongoose.Model<{
|
|
|
124
124
|
}, {
|
|
125
125
|
timestamps: true;
|
|
126
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";
|
|
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" | "admin.email.change.requested" | "admin.email.change.verified";
|
|
128
128
|
outcome: "success" | "failure";
|
|
129
129
|
metadata?: any;
|
|
130
130
|
actor?: {
|
|
@@ -147,7 +147,7 @@ export const AuditLog: mongoose.Model<{
|
|
|
147
147
|
}>, mongoose.Schema<any, mongoose.Model<any, any, any, any, any, any, any>, {}, {}, {}, {}, {
|
|
148
148
|
timestamps: true;
|
|
149
149
|
}, {
|
|
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";
|
|
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" | "admin.email.change.requested" | "admin.email.change.verified";
|
|
151
151
|
outcome: "success" | "failure";
|
|
152
152
|
metadata?: any;
|
|
153
153
|
actor?: {
|
|
@@ -162,7 +162,7 @@ export const AuditLog: mongoose.Model<{
|
|
|
162
162
|
reason?: string;
|
|
163
163
|
requestId?: string;
|
|
164
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";
|
|
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" | "admin.email.change.requested" | "admin.email.change.verified";
|
|
166
166
|
outcome: "success" | "failure";
|
|
167
167
|
metadata?: any;
|
|
168
168
|
actor?: {
|
|
@@ -181,7 +181,7 @@ export const AuditLog: mongoose.Model<{
|
|
|
181
181
|
}, Omit<mongoose.DefaultSchemaOptions, "timestamps"> & {
|
|
182
182
|
timestamps: true;
|
|
183
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";
|
|
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" | "admin.email.change.requested" | "admin.email.change.verified";
|
|
185
185
|
outcome: "success" | "failure";
|
|
186
186
|
metadata?: any;
|
|
187
187
|
actor?: {
|
|
@@ -202,7 +202,7 @@ export const AuditLog: mongoose.Model<{
|
|
|
202
202
|
}, "id"> & mongoose.HydratedDocumentOverrides<{
|
|
203
203
|
id: string;
|
|
204
204
|
}>, unknown, {
|
|
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";
|
|
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" | "admin.email.change.requested" | "admin.email.change.verified";
|
|
206
206
|
outcome: "success" | "failure";
|
|
207
207
|
metadata?: any;
|
|
208
208
|
actor?: {
|
|
@@ -223,7 +223,7 @@ export const AuditLog: mongoose.Model<{
|
|
|
223
223
|
} & {
|
|
224
224
|
__v: number;
|
|
225
225
|
}>, {
|
|
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";
|
|
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" | "admin.email.change.requested" | "admin.email.change.verified";
|
|
227
227
|
outcome: "success" | "failure";
|
|
228
228
|
metadata?: any;
|
|
229
229
|
actor?: {
|
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -144,6 +144,10 @@ import {
|
|
|
144
144
|
passwordResetTokenSchema,
|
|
145
145
|
PasswordResetToken,
|
|
146
146
|
} from "./models/passwordResetToken.js";
|
|
147
|
+
import {
|
|
148
|
+
emailChangeTokenSchema,
|
|
149
|
+
EmailChangeToken,
|
|
150
|
+
} from "./models/emailChangeToken.js";
|
|
147
151
|
import {
|
|
148
152
|
dataDownloadSchema,
|
|
149
153
|
DataDownloads,
|
|
@@ -254,6 +258,9 @@ export {
|
|
|
254
258
|
// Password reset tokens (JA-2946)
|
|
255
259
|
passwordResetTokenSchema,
|
|
256
260
|
PasswordResetToken,
|
|
261
|
+
// Admin email-change verification tokens (JA-3744)
|
|
262
|
+
emailChangeTokenSchema,
|
|
263
|
+
EmailChangeToken,
|
|
257
264
|
// Notification episodes + send log (JA-2658 / JA-2691 stack)
|
|
258
265
|
monitorEpisodesSchema,
|
|
259
266
|
MonitorEpisode,
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import mongoose from 'mongoose';
|
|
2
|
+
|
|
3
|
+
// One-time, hashed admin email-change verification tokens (JA-3744 / JA-3806).
|
|
4
|
+
//
|
|
5
|
+
// An admin's new email address is NOT written to Admin.email when it is
|
|
6
|
+
// requested. It is parked here, with a one-time token mailed to the NEW address,
|
|
7
|
+
// and only moves onto the Admin document when that link is clicked
|
|
8
|
+
// (JustAirService POST /admin/verify-email-change). "Pending" for an admin means
|
|
9
|
+
// an unused, unexpired document exists here; there is no copy of that state on
|
|
10
|
+
// Admin (decision D2 on JA-3744), so this collection is the single owner of it.
|
|
11
|
+
//
|
|
12
|
+
// Same shape and guarantees as PasswordResetToken:
|
|
13
|
+
// - the raw token travels only in the emailed link; its SHA-256 hash is stored,
|
|
14
|
+
// so a DB read cannot reconstruct a usable link;
|
|
15
|
+
// - single-use is enforced with ONE atomic operation at verify time:
|
|
16
|
+
// findOneAndUpdate({ tokenHash, used:false, expiresAt:{$gt: now} }, {$set:{used:true}})
|
|
17
|
+
// so two clicks cannot both consume the same token;
|
|
18
|
+
// - the TTL index self-cleans the collection, but verify MUST still check
|
|
19
|
+
// `expiresAt` in the query above: MongoDB's TTL monitor sweeps about once a
|
|
20
|
+
// minute, so an expired doc can linger briefly and must not be honored.
|
|
21
|
+
//
|
|
22
|
+
// Requesting a second change for the same admin marks every earlier unused token
|
|
23
|
+
// used (updateMany) before minting the new one, so only the newest link works.
|
|
24
|
+
const emailChangeTokenSchema = new mongoose.Schema(
|
|
25
|
+
{
|
|
26
|
+
adminId: { type: mongoose.Types.ObjectId, ref: 'Admin', required: true, index: true },
|
|
27
|
+
// The address the admin asked to move to. Written to Admin.email at verify.
|
|
28
|
+
newEmail: { type: String, required: true },
|
|
29
|
+
tokenHash: { type: String, required: true, unique: true, index: true },
|
|
30
|
+
used: { type: Boolean, default: false },
|
|
31
|
+
expiresAt: { type: Date, required: true },
|
|
32
|
+
},
|
|
33
|
+
{ timestamps: true },
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
// TTL index — MongoDB removes the doc once expiresAt < now()
|
|
37
|
+
emailChangeTokenSchema.index({ expiresAt: 1 }, { expireAfterSeconds: 0 });
|
|
38
|
+
|
|
39
|
+
const EmailChangeToken = mongoose.model('EmailChangeToken', emailChangeTokenSchema);
|
|
40
|
+
|
|
41
|
+
export { emailChangeTokenSchema, EmailChangeToken };
|
|
@@ -7,7 +7,8 @@
|
|
|
7
7
|
* Emit sites (in the services): login (success/failure), logout, forgot-password
|
|
8
8
|
* (requested/completed), silent refresh, and the admin mutation sites
|
|
9
9
|
* (create/update/delete, role.change when permissionName changes,
|
|
10
|
-
* deactivate/reactivate when isActive toggles)
|
|
10
|
+
* deactivate/reactivate when isActive toggles), and the admin email-change flow
|
|
11
|
+
* (requested when a verify link is mailed, verified when it is clicked; JA-3744).
|
|
11
12
|
*/
|
|
12
13
|
export const AUDIT_ACTIONS = Object.freeze({
|
|
13
14
|
LOGIN_SUCCESS: 'auth.login.success',
|
|
@@ -22,6 +23,8 @@ export const AUDIT_ACTIONS = Object.freeze({
|
|
|
22
23
|
ADMIN_ROLE_CHANGE: 'admin.role.change',
|
|
23
24
|
ADMIN_DEACTIVATE: 'admin.deactivate',
|
|
24
25
|
ADMIN_REACTIVATE: 'admin.reactivate',
|
|
26
|
+
ADMIN_EMAIL_CHANGE_REQUESTED: 'admin.email.change.requested',
|
|
27
|
+
ADMIN_EMAIL_CHANGE_VERIFIED: 'admin.email.change.verified',
|
|
25
28
|
});
|
|
26
29
|
|
|
27
30
|
/** Frozen list of all valid action strings — used as the AuditLog schema enum. */
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { AUDIT_ACTIONS, AUDIT_ACTION_VALUES } from '../actions.js';
|
|
2
2
|
|
|
3
|
-
test('exposes the exact
|
|
3
|
+
test('exposes the exact 14 contract action strings, in order', () => {
|
|
4
4
|
expect(AUDIT_ACTION_VALUES).toEqual([
|
|
5
5
|
'auth.login.success',
|
|
6
6
|
'auth.login.failure',
|
|
@@ -14,6 +14,8 @@ test('exposes the exact 12 contract action strings, in order', () => {
|
|
|
14
14
|
'admin.role.change',
|
|
15
15
|
'admin.deactivate',
|
|
16
16
|
'admin.reactivate',
|
|
17
|
+
'admin.email.change.requested',
|
|
18
|
+
'admin.email.change.verified',
|
|
17
19
|
]);
|
|
18
20
|
});
|
|
19
21
|
|