@justair/justair-library 7.6.0-alpha.f80fd11 → 7.7.0-alpha.3af709a
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/SECURITY.md +21 -0
- package/dist/constants/index.d.ts +1 -0
- package/dist/constants/terms.d.ts +2 -0
- package/dist/constants/terms.d.ts.map +1 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/models/users.d.ts.map +1 -1
- package/dist/utils/subscribedDevices.d.ts +1 -3
- package/dist/utils/subscribedDevices.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/constants/index.js +1 -0
- package/src/constants/terms.js +14 -0
- package/src/constants/tests/constantsBarrel.test.js +6 -0
- package/src/index.js +8 -4
- package/src/models/users.js +26 -0
- package/src/utils/subscribedDevices.js +24 -15
- package/src/utils/tests/subscribedDevices.test.js +11 -9
package/SECURITY.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# Security Policy
|
|
2
|
+
|
|
3
|
+
## Supported versions
|
|
4
|
+
|
|
5
|
+
Security fixes are prioritized for the current default branch and actively supported releases of `JustAir-Solutions/justair-library`. Older or retired versions may not receive fixes.
|
|
6
|
+
|
|
7
|
+
## Reporting a vulnerability
|
|
8
|
+
|
|
9
|
+
Do not open a public GitHub issue for a suspected vulnerability.
|
|
10
|
+
|
|
11
|
+
Send the initial report to `info@justair.co` with the subject `Security vulnerability: justair-library`. Include the affected repository or component, the potential impact, minimal reproduction steps, and a way to contact you.
|
|
12
|
+
|
|
13
|
+
Do not include passwords, tokens, private keys, personal data, regulated data, or other sensitive payloads in the initial message. Ask for an approved secure transfer method when sensitive evidence is necessary.
|
|
14
|
+
|
|
15
|
+
## Testing boundaries
|
|
16
|
+
|
|
17
|
+
This policy does not grant authorization to access data that is not yours, disrupt service, perform denial-of-service testing, use social engineering, destroy data, or establish persistence. Stop testing and report the issue if sensitive data or credentials are encountered.
|
|
18
|
+
|
|
19
|
+
## Coordinated disclosure
|
|
20
|
+
|
|
21
|
+
Please allow JustAir reasonable time to investigate and remediate before public disclosure. Receipt of a report does not create a promise of a specific response or remediation timeline.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"terms.d.ts","sourceRoot":"","sources":["../../src/constants/terms.js"],"names":[],"mappings":"AAaA,0CAA2C"}
|
package/dist/index.d.ts
CHANGED
|
@@ -103,6 +103,7 @@ import { PARAMETERS } from "./constants/pollutants.js";
|
|
|
103
103
|
import { HEAVY_METALS } from "./constants/pollutants.js";
|
|
104
104
|
import { ALERT_LEVEL_WEIGHTS } from "./constants/alertLevels.js";
|
|
105
105
|
import { getAlertWeight } from "./constants/alertLevels.js";
|
|
106
|
+
import { TERMS_VERSION_MAX_LENGTH } from "./constants/terms.js";
|
|
106
107
|
import { DEVICE_TYPES } from "./constants/deviceTypes.js";
|
|
107
108
|
import { DEVICE_TYPE_VALUES } from "./constants/deviceTypes.js";
|
|
108
109
|
import { isAqiCapableDeviceType } from "./constants/deviceTypes.js";
|
|
@@ -121,5 +122,5 @@ import { validateQuietHours } from "./utils/quietHours.js";
|
|
|
121
122
|
import { getZoneMinutes } from "./utils/quietHours.js";
|
|
122
123
|
import { isInQuietWindow } from "./utils/quietHours.js";
|
|
123
124
|
import { resolveQuietHours } from "./utils/quietHours.js";
|
|
124
|
-
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, DEVICE_TYPES, DEVICE_TYPE_VALUES, isAqiCapableDeviceType, AQI_CAPABLE_DEVICE_TYPES, projectSubscribedMonitors, resolveSubscribedMonitorIdsByUser, VISIBLE_SITE_MONITOR_FILTER, SUBSCRIBED_DEVICES_ERRORS, splitName, DEFAULT_QUIET_HOURS, DEFAULT_TIMEZONE, QUIET_HOURS_ERRORS, isValidTimeString, isValidIANATimezone, validateQuietHours, getZoneMinutes, isInQuietWindow, resolveQuietHours };
|
|
125
|
+
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, projectSubscribedMonitors, resolveSubscribedMonitorIdsByUser, VISIBLE_SITE_MONITOR_FILTER, SUBSCRIBED_DEVICES_ERRORS, splitName, DEFAULT_QUIET_HOURS, DEFAULT_TIMEZONE, QUIET_HOURS_ERRORS, isValidTimeString, isValidIANATimezone, validateQuietHours, getZoneMinutes, isInQuietWindow, resolveQuietHours };
|
|
125
126
|
//# 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":"AA0KA;;;iBAEC;yBAvGwB,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;4BAmDT,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;sCArDhC,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;oCAtBF,8BAA8B;mCAsE3D,2BAA2B;8BAA3B,2BAA2B;gCAA3B,2BAA2B;mCAA3B,2BAA2B;+DAsB3B,mCAAmC;qCAAnC,mCAAmC;mEAAnC,mCAAmC;yEAAnC,mCAAmC;mEAAnC,mCAAmC;qEAAnC,mCAAmC;yEAAnC,mCAAmC;2EAAnC,mCAAmC;2BAlGD,2BAA2B;6BAA3B,2BAA2B;oCAI7D,4BAA4B;+BAA5B,4BAA4B;yCAGM,sBAAsB;6BAMxD,4BAA4B;mCAA5B,4BAA4B;uCAA5B,4BAA4B;yCAA5B,4BAA4B;0CAgC5B,8BAA8B;kDAA9B,8BAA8B;4CAA9B,8BAA8B;0CAA9B,8BAA8B;0BAhBX,sBAAsB;oCASzC,uBAAuB;iCAjCG,0BAA0B;mCAiCpD,uBAAuB;kCAAvB,uBAAuB;oCACM,qBAAqB;mCADlD,uBAAuB;+BAAvB,uBAAuB;gCAAvB,uBAAuB;kCAAvB,uBAAuB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"users.d.ts","sourceRoot":"","sources":["../../src/models/users.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"users.d.ts","sourceRoot":"","sources":["../../src/models/users.js"],"names":[],"mappings":"AA8FA,8BAmIE;AAiCF,wBAAmD;AAxPnD,iDAA4D;AAC5D,6CAAmD;AAUnD,4DA0BC"}
|
|
@@ -11,9 +11,7 @@ export const VISIBLE_SITE_MONITOR_FILTER: Readonly<{
|
|
|
11
11
|
isPrivate: Readonly<{
|
|
12
12
|
$ne: true;
|
|
13
13
|
}>;
|
|
14
|
-
isActive:
|
|
15
|
-
$ne: false;
|
|
16
|
-
}>;
|
|
14
|
+
isActive: true;
|
|
17
15
|
}>;
|
|
18
16
|
export function projectSubscribedMonitors(subscribedDevices?: Array<{
|
|
19
17
|
deviceId: import("mongoose").Types.ObjectId;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"subscribedDevices.d.ts","sourceRoot":"","sources":["../../src/utils/subscribedDevices.js"],"names":[],"mappings":"AA0FA;;;;;;;;GASG;
|
|
1
|
+
{"version":3,"file":"subscribedDevices.d.ts","sourceRoot":"","sources":["../../src/utils/subscribedDevices.js"],"names":[],"mappings":"AA0FA;;;;;;;;GASG;AA+CH;;;;;GAGG;AA6LI,8DANI,KAAK,CAAC;IAAE,QAAQ,EAAE,OAAO,UAAU,EAAE,KAAK,CAAC,QAAQ,CAAC;IAC1D,UAAU,EAAE,OAAO,6BAA6B,EAAE,UAAU,CAAA;CAAE,CAAC,8BACzD;IAAE,qBAAqB,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,UAAU,EAAE,KAAK,CAAC,QAAQ,EAAE,KAC7E,OAAO,CAAC,KAAK,CAAC,OAAO,UAAU,EAAE,KAAK,CAAC,QAAQ,GAAG,IAAI,GAAG,SAAS,CAAC,CAAC,CAAA;CAAE,GAC9D,OAAO,CAAC,OAAO,UAAU,EAAE,KAAK,CAAC,QAAQ,EAAE,CAAC,CA0BxD;AA0EM,0DAPI,KAAK,CAAC;IAAE,GAAG,EAAE,GAAG,CAAC;IAAC,iBAAiB,CAAC,EAAE,KAAK,CAAC;QAClD,QAAQ,EAAE,OAAO,UAAU,EAAE,KAAK,CAAC,QAAQ,CAAC;QAC5C,UAAU,EAAE,OAAO,6BAA6B,EAAE,UAAU,CAAA;KAAE,CAAC,CAAA;CAAE,CAAC,mCAC5D;IAAE,0BAA0B,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,UAAU,EAAE,KAAK,CAAC,QAAQ,EAAE,KAClF,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,OAAO,UAAU,EAAE,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAA;CAAE,GACnD,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,OAAO,UAAU,EAAE,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAC,CAmErE"}
|
package/package.json
CHANGED
package/src/constants/index.js
CHANGED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// Terms-of-service agreement vocabulary.
|
|
2
|
+
//
|
|
3
|
+
// Users.termsVersion stores the policy-document version a public user agreed
|
|
4
|
+
// to at registration (e.g. "2026.1" — the published doc's tab name). The
|
|
5
|
+
// VALUE is owned by the frontend signup flow; nothing in the
|
|
6
|
+
// backend hardcodes a current version, so there is deliberately no
|
|
7
|
+
// TERMS_CURRENT_VERSION constant here.
|
|
8
|
+
//
|
|
9
|
+
// The cap below is the one number shared by the two enforcement points in
|
|
10
|
+
// different repos: the Users schema (`maxlength`) and JustAirUserService's
|
|
11
|
+
// registration route validator. Import it from either barrel rather than
|
|
12
|
+
// inlining the literal — if the two drift, the route accepts what the schema
|
|
13
|
+
// rejects and a signup 500s instead of 400ing.
|
|
14
|
+
export const TERMS_VERSION_MAX_LENGTH = 32;
|
|
@@ -8,6 +8,7 @@ import { PARAMETERS, HEAVY_METALS } from '../pollutants.js';
|
|
|
8
8
|
import { ALERT_LEVEL_WEIGHTS, getAlertWeight } from '../alertLevels.js';
|
|
9
9
|
import { DEFAULT_TIMEZONE } from '../timezones.js';
|
|
10
10
|
import { DATA_DOWNLOAD_TYPES } from '../dataDownloads.js';
|
|
11
|
+
import { TERMS_VERSION_MAX_LENGTH } from '../terms.js';
|
|
11
12
|
|
|
12
13
|
test('barrel re-exports the pollutants constants unchanged (identity, not copies)', () => {
|
|
13
14
|
expect(barrel.PARAMETERS).toBe(PARAMETERS);
|
|
@@ -56,6 +57,11 @@ test('barrel exports DATA_DOWNLOAD_TYPES (browser-safe, no Mongoose)', () => {
|
|
|
56
57
|
expect(barrel.DATA_DOWNLOAD_TYPES).toBe(DATA_DOWNLOAD_TYPES);
|
|
57
58
|
});
|
|
58
59
|
|
|
60
|
+
test('barrel exports TERMS_VERSION_MAX_LENGTH (browser-safe, no Mongoose)', () => {
|
|
61
|
+
expect(barrel.TERMS_VERSION_MAX_LENGTH).toBe(TERMS_VERSION_MAX_LENGTH);
|
|
62
|
+
expect(TERMS_VERSION_MAX_LENGTH).toBe(32);
|
|
63
|
+
});
|
|
64
|
+
|
|
59
65
|
// models/dataDownloads.js destructures this list positionally to build the two
|
|
60
66
|
// discriminators, so a reorder would silently swap the persisted dataType
|
|
61
67
|
// values on every future download. Pin contents AND order.
|
package/src/index.js
CHANGED
|
@@ -75,6 +75,7 @@ import {
|
|
|
75
75
|
} from "./constants/alertLevels.js";
|
|
76
76
|
import { DEFAULT_TIMEZONE } from "./constants/timezones.js";
|
|
77
77
|
import { DATA_DOWNLOAD_TYPES } from "./constants/dataDownloads.js";
|
|
78
|
+
import { TERMS_VERSION_MAX_LENGTH } from "./constants/terms.js";
|
|
78
79
|
import {
|
|
79
80
|
DEVICE_TYPES,
|
|
80
81
|
DEVICE_TYPE_VALUES,
|
|
@@ -280,6 +281,9 @@ export {
|
|
|
280
281
|
// AQI alert-level hierarchy (single source of truth)
|
|
281
282
|
ALERT_LEVEL_WEIGHTS,
|
|
282
283
|
getAlertWeight,
|
|
284
|
+
// Terms agreement (JA-3396) — cap shared by the Users schema and
|
|
285
|
+
// JustAirUserService's registration route validator
|
|
286
|
+
TERMS_VERSION_MAX_LENGTH,
|
|
283
287
|
// V2 device-type vocabulary (single source of truth) — JA-3110 / JA-3335
|
|
284
288
|
DEVICE_TYPES,
|
|
285
289
|
DEVICE_TYPE_VALUES,
|
|
@@ -293,16 +297,16 @@ export {
|
|
|
293
297
|
// being retired rather than kept in step with it. Nothing should store this
|
|
294
298
|
// result — see the module header for the five bugs a stored copy caused.
|
|
295
299
|
//
|
|
300
|
+
// Both resolvers are only correct for users whose subscribedDevices has been
|
|
301
|
+
// backfilled from subscribedMonitors — read the PRECONDITION block in the
|
|
302
|
+
// module header before pointing a service at either of them.
|
|
303
|
+
//
|
|
296
304
|
// resolveSubscribedMonitorIdsByUser — the batch form. One Sites lookup for
|
|
297
305
|
// a whole cohort. What alert runs, org pages and
|
|
298
306
|
// session responses should call.
|
|
299
307
|
// projectSubscribedMonitors — the single-user rule the batch form is built
|
|
300
308
|
// on. Named after the field being retired; it
|
|
301
309
|
// gets renamed when that field is dropped.
|
|
302
|
-
//
|
|
303
|
-
// Only correct for users whose subscribedDevices has been backfilled from
|
|
304
|
-
// subscribedMonitors — see the PRECONDITION block in the module header
|
|
305
|
-
// before pointing a service at these.
|
|
306
310
|
// VISIBLE_SITE_MONITOR_FILTER — the privacy predicate every consumer must
|
|
307
311
|
// apply when turning a Site into monitor ids.
|
|
308
312
|
// Sites.monitorIds is unfiltered; reading it
|
package/src/models/users.js
CHANGED
|
@@ -6,6 +6,7 @@ import {
|
|
|
6
6
|
QUIET_HOURS_ERRORS,
|
|
7
7
|
} from "../utils/quietHours.js";
|
|
8
8
|
import { DEVICE_TYPE_VALUES } from "../constants/deviceTypes.js";
|
|
9
|
+
import { TERMS_VERSION_MAX_LENGTH } from "../constants/terms.js";
|
|
9
10
|
|
|
10
11
|
const COOKIE_CONSENT_CATEGORIES = ["analytics_performance"];
|
|
11
12
|
const COOKIE_CONSENT_VALUES = ["accept", "reject"];
|
|
@@ -193,6 +194,31 @@ const usersSchema = mongoose.Schema(
|
|
|
193
194
|
message: "timezone must be a valid IANA timezone identifier",
|
|
194
195
|
},
|
|
195
196
|
},
|
|
197
|
+
// Terms agreement: the policy-document version the user agreed to at
|
|
198
|
+
// registration (e.g. "2026.1"). The client supplies the value (the signup
|
|
199
|
+
// FE owns it); the backend never hardcodes a
|
|
200
|
+
// current version. Written once at account creation — `immutable` means
|
|
201
|
+
// save() mutations are ignored and strict-mode query updates are
|
|
202
|
+
// stripped, silently by design; treat any need to change it as a product
|
|
203
|
+
// decision, not a bug. Absent = registered before terms tracking existed
|
|
204
|
+
// (or a legacy client that sent only { phone }); absence is legal
|
|
205
|
+
// forever. Deliberately NO acceptance boolean (an account cannot be
|
|
206
|
+
// created without pressing "I Agree", so it would be true on every
|
|
207
|
+
// record) and NO separate acceptance timestamp — createdAt IS the
|
|
208
|
+
// agreement date (grooming decision, 2026-09-03).
|
|
209
|
+
//
|
|
210
|
+
// Blank guard: immutability makes a stored value permanent, so a blank or
|
|
211
|
+
// padded string ("" / " 2026.1") would be an uncorrectable third state —
|
|
212
|
+
// looks present, records nothing. trim + minlength reject it here as the
|
|
213
|
+
// backstop; the registration route validator (JA-3397) is the primary
|
|
214
|
+
// 400 path, both sharing TERMS_VERSION_MAX_LENGTH.
|
|
215
|
+
termsVersion: {
|
|
216
|
+
type: String,
|
|
217
|
+
trim: true,
|
|
218
|
+
minlength: 1,
|
|
219
|
+
immutable: true,
|
|
220
|
+
maxlength: TERMS_VERSION_MAX_LENGTH,
|
|
221
|
+
},
|
|
196
222
|
},
|
|
197
223
|
{
|
|
198
224
|
timestamps: true,
|
|
@@ -116,15 +116,20 @@ export const SUBSCRIBED_DEVICES_ERRORS = Object.freeze({
|
|
|
116
116
|
// "_id",
|
|
117
117
|
// ).lean();
|
|
118
118
|
//
|
|
119
|
-
// `isActive:
|
|
120
|
-
//
|
|
121
|
-
//
|
|
122
|
-
// `
|
|
123
|
-
//
|
|
124
|
-
//
|
|
125
|
-
//
|
|
126
|
-
//
|
|
127
|
-
//
|
|
119
|
+
// `isActive: true` is an EXACT match, and that asymmetry with the `$ne` above
|
|
120
|
+
// is DELIBERATE — do not "fix" it to `{ $ne: false }`. The two clauses answer
|
|
121
|
+
// different questions. `isPrivate` is a privacy gate: a monitor with no
|
|
122
|
+
// `isPrivate` key was never marked private, so excluding it would hide a
|
|
123
|
+
// monitor its followers are entitled to see. `isActive` is an eligibility
|
|
124
|
+
// gate: a monitor only earns a place in an alert audience by positively
|
|
125
|
+
// asserting it is active. A document with no `isActive` key has made no such
|
|
126
|
+
// assertion, and the safe reading of "we don't know" is to leave it out rather
|
|
127
|
+
// than alert on it.
|
|
128
|
+
//
|
|
129
|
+
// So the failure modes are not symmetric and should not be made symmetric.
|
|
130
|
+
// Over-including here means alerting people about a monitor nobody confirmed
|
|
131
|
+
// is live; under-including means one unconfirmed monitor is missing from an
|
|
132
|
+
// audience until someone sets the flag. This predicate takes the second.
|
|
128
133
|
//
|
|
129
134
|
// `monitorState: "Deployed"` is deliberately NOT here. That is an
|
|
130
135
|
// alerting-eligibility rule, not a visibility rule, and it belongs to the
|
|
@@ -137,10 +142,11 @@ export const SUBSCRIBED_DEVICES_ERRORS = Object.freeze({
|
|
|
137
142
|
// top-level-only freeze still lets a consumer write
|
|
138
143
|
// `VISIBLE_SITE_MONITOR_FILTER.isPrivate.$ne = false` — and because every
|
|
139
144
|
// consumer spreads THIS instance, that one write flips the privacy predicate
|
|
140
|
-
// for the whole process.
|
|
145
|
+
// for the whole process. `isPrivate` is the only nested object here; freeze it
|
|
146
|
+
// too, and freeze any operator object a future clause introduces.
|
|
141
147
|
export const VISIBLE_SITE_MONITOR_FILTER = Object.freeze({
|
|
142
148
|
isPrivate: Object.freeze({ $ne: true }),
|
|
143
|
-
isActive:
|
|
149
|
+
isActive: true,
|
|
144
150
|
});
|
|
145
151
|
|
|
146
152
|
// Dedupe by string form, keep the caller's ObjectId instances. Two equal
|
|
@@ -398,10 +404,13 @@ export const projectSubscribedMonitors = async (
|
|
|
398
404
|
// to nothing, so their alerts stop) is the subscription-identity question
|
|
399
405
|
// tracked in TODOS, and is deliberately not papered over here.
|
|
400
406
|
//
|
|
401
|
-
// Users are keyed by `String(user._id)`, so callers look up with the same.
|
|
402
|
-
//
|
|
403
|
-
//
|
|
404
|
-
//
|
|
407
|
+
// Users are keyed by `String(user._id)`, so callers look up with the same.
|
|
408
|
+
// Anything in the cohort that is not a user object carrying an `_id` — a
|
|
409
|
+
// missing `_id`, a `null` slot, a bare id string — throws COHORT_USER_MISSING_ID
|
|
410
|
+
// rather than being skipped. Skipping would silently remove a real person from
|
|
411
|
+
// an alert audience, which is the failure mode this whole module exists to
|
|
412
|
+
// avoid, and a caller cannot tell a dropped entry apart from one that resolved
|
|
413
|
+
// to nothing.
|
|
405
414
|
//
|
|
406
415
|
// Consumers can shrink the cohort by pushing the AQI-capability predicate into
|
|
407
416
|
// the Users query, so rows that can never alert are not loaded at all.
|
|
@@ -665,15 +665,17 @@ describe('resolveSubscribedMonitorIdsByUser — rejects what would otherwise fai
|
|
|
665
665
|
});
|
|
666
666
|
|
|
667
667
|
describe('VISIBLE_SITE_MONITOR_FILTER', () => {
|
|
668
|
-
test('
|
|
669
|
-
//
|
|
670
|
-
//
|
|
671
|
-
//
|
|
672
|
-
//
|
|
673
|
-
//
|
|
668
|
+
test('privacy uses $ne, eligibility uses an exact match — deliberately', () => {
|
|
669
|
+
// The asymmetry is the point, and this test exists to stop it being
|
|
670
|
+
// "fixed". isPrivate is a privacy gate: $ne keeps a monitor that was never
|
|
671
|
+
// marked private, which its followers are entitled to see. isActive is an
|
|
672
|
+
// eligibility gate: a monitor earns a place in an alert audience only by
|
|
673
|
+
// positively asserting it is active, so a document that has made no such
|
|
674
|
+
// assertion stays out. Confirmed product decision — flipping either half
|
|
675
|
+
// is a behaviour change, not a cleanup.
|
|
674
676
|
expect(VISIBLE_SITE_MONITOR_FILTER).toEqual({
|
|
675
677
|
isPrivate: { $ne: true },
|
|
676
|
-
isActive:
|
|
678
|
+
isActive: true,
|
|
677
679
|
});
|
|
678
680
|
});
|
|
679
681
|
|
|
@@ -683,12 +685,12 @@ describe('VISIBLE_SITE_MONITOR_FILTER', () => {
|
|
|
683
685
|
// predicate for every consumer that spreads this instance.
|
|
684
686
|
expect(Object.isFrozen(VISIBLE_SITE_MONITOR_FILTER)).toBe(true);
|
|
685
687
|
expect(Object.isFrozen(VISIBLE_SITE_MONITOR_FILTER.isPrivate)).toBe(true);
|
|
686
|
-
expect(Object.isFrozen(VISIBLE_SITE_MONITOR_FILTER.isActive)).toBe(true);
|
|
687
688
|
});
|
|
688
689
|
|
|
689
690
|
test('a nested write is rejected rather than shared with every consumer', () => {
|
|
691
|
+
// ES modules are strict, so a write to a frozen property throws rather
|
|
692
|
+
// than failing silently.
|
|
690
693
|
expect(() => {
|
|
691
|
-
'use strict';
|
|
692
694
|
VISIBLE_SITE_MONITOR_FILTER.isPrivate.$ne = false;
|
|
693
695
|
}).toThrow(TypeError);
|
|
694
696
|
|