@justair/justair-library 7.3.0-alpha.80c577a → 7.3.0-alpha.cc30881
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/constants/dataDownloads.d.ts.map +1 -1
- package/dist/index.d.ts +1 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/models/dataDownloads.d.ts.map +1 -1
- package/dist/utils/dataDownloadValidation.d.ts +0 -4
- package/dist/utils/dataDownloadValidation.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/constants/dataDownloads.js +1 -6
- package/src/index.js +0 -6
- package/src/models/dataDownloads.js +3 -9
- package/src/utils/dataDownloadValidation.js +2 -24
- package/src/utils/tests/dataDownloadValidation.test.js +0 -29
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dataDownloads.d.ts","sourceRoot":"","sources":["../../src/constants/dataDownloads.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"dataDownloads.d.ts","sourceRoot":"","sources":["../../src/constants/dataDownloads.js"],"names":[],"mappings":"AAUA,2CAAqD"}
|
package/dist/index.d.ts
CHANGED
|
@@ -97,7 +97,6 @@ import { validateDateOrder as validateDataDownloadDateOrder } from "./utils/data
|
|
|
97
97
|
import { validateMaxDateRange as validateDataDownloadMaxDateRange } from "./utils/dataDownloadValidation.js";
|
|
98
98
|
import { validateDownloadEmail as validateDataDownloadEmail } from "./utils/dataDownloadValidation.js";
|
|
99
99
|
import { normalizeDownloadEmail as normalizeDataDownloadEmail } from "./utils/dataDownloadValidation.js";
|
|
100
|
-
import { validateDownloadTimezone as validateDataDownloadTimezone } from "./utils/dataDownloadValidation.js";
|
|
101
100
|
import { PARAMETERS } from "./constants/pollutants.js";
|
|
102
101
|
import { HEAVY_METALS } from "./constants/pollutants.js";
|
|
103
102
|
import { ALERT_LEVEL_WEIGHTS } from "./constants/alertLevels.js";
|
|
@@ -112,5 +111,5 @@ import { validateQuietHours } from "./utils/quietHours.js";
|
|
|
112
111
|
import { getZoneMinutes } from "./utils/quietHours.js";
|
|
113
112
|
import { isInQuietWindow } from "./utils/quietHours.js";
|
|
114
113
|
import { resolveQuietHours } from "./utils/quietHours.js";
|
|
115
|
-
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,
|
|
114
|
+
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, PARAMETERS, HEAVY_METALS, ALERT_LEVEL_WEIGHTS, getAlertWeight, splitName, DEFAULT_QUIET_HOURS, DEFAULT_TIMEZONE, QUIET_HOURS_ERRORS, isValidTimeString, isValidIANATimezone, validateQuietHours, getZoneMinutes, isInQuietWindow, resolveQuietHours };
|
|
116
115
|
//# 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":"AA8IA;;;iBAEC;yBA9EwB,oBAAoB;qBADxB,gBAAgB;4BAjEF,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;qCACgB,4BAA4B;+BAA5B,4BAA4B;mCAChC,0BAA0B;6BAA1B,0BAA0B;8CAIpE,qCAAqC;wCAArC,qCAAqC;4BAmCT,mBAAmB;sBAAnB,mBAAmB;kCAS/C,yBAAyB;4BAAzB,yBAAyB;sCAAzB,yBAAyB;gCAAzB,yBAAyB;qCAAzB,yBAAyB;8BASzB,qBAAqB;wBAArB,qBAAqB;mCAArB,qBAAqB;6BAArB,qBAAqB;uDAArB,qBAAqB;yCACiC,gCAAgC;mCAAhC,gCAAgC;sCA5CtF,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;oCAfF,8BAA8B;mCAsD3D,2BAA2B;8BAA3B,2BAA2B;gCAA3B,2BAA2B;mCAA3B,2BAA2B;+DAgB3B,mCAAmC;qCAAnC,mCAAmC;mEAAnC,mCAAmC;yEAAnC,mCAAmC;mEAAnC,mCAAmC;qEAAnC,mCAAmC;2BAzED,2BAA2B;6BAA3B,2BAA2B;oCAChB,4BAA4B;+BAA5B,4BAA4B;0BAkBtD,sBAAsB;oCASzC,uBAAuB;iCA1BG,0BAA0B;mCA0BpD,uBAAuB;kCAAvB,uBAAuB;oCACM,qBAAqB;mCADlD,uBAAuB;+BAAvB,uBAAuB;gCAAvB,uBAAuB;kCAAvB,uBAAuB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dataDownloads.d.ts","sourceRoot":"","sources":["../../src/models/dataDownloads.js"],"names":[],"mappings":"AAuBA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+DE;
|
|
1
|
+
{"version":3,"file":"dataDownloads.d.ts","sourceRoot":"","sources":["../../src/models/dataDownloads.js"],"names":[],"mappings":"AAuBA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+DE;AAqDF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAA0E;AAY1E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAEG;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAIE;qBA/JmB,UAAU"}
|
|
@@ -18,8 +18,4 @@ export function validateDownloadEmail({ email }?: {}): {
|
|
|
18
18
|
code: "invalid_email";
|
|
19
19
|
message: string;
|
|
20
20
|
}[];
|
|
21
|
-
export function validateDownloadTimezone({ timezone }?: {}): {
|
|
22
|
-
code: "invalid_timezone";
|
|
23
|
-
message: string;
|
|
24
|
-
}[];
|
|
25
21
|
//# sourceMappingURL=dataDownloadValidation.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dataDownloadValidation.d.ts","sourceRoot":"","sources":["../../src/utils/dataDownloadValidation.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"dataDownloadValidation.d.ts","sourceRoot":"","sources":["../../src/utils/dataDownloadValidation.js"],"names":[],"mappings":"AAUA,gCAAiC;AAUjC;;;;;GAKG;AAmBI;;;IAcN;AAIM;;;IAcN;AAgBM,wDAMN;AAIM;;;IAqBN"}
|
package/package.json
CHANGED
|
@@ -1,14 +1,9 @@
|
|
|
1
1
|
// DataDownloads vocabulary — source of truth for the `dataType` discriminator
|
|
2
2
|
// values (JA-3080/JA-3245). Kept here (Mongoose-free) so JustAirService and
|
|
3
3
|
// JustAir-Client can import the list without pulling in the models: the client
|
|
4
|
-
//
|
|
4
|
+
// renders these as the download modal's data-type picker, and the service
|
|
5
5
|
// branches on them when building the export.
|
|
6
6
|
//
|
|
7
|
-
// These are persisted values, NOT display labels. Figma labels the second
|
|
8
|
-
// option "Sample Data" while the stored value is "Sample", so a consumer that
|
|
9
|
-
// renders the array directly shows the wrong copy. Labels belong to the
|
|
10
|
-
// consumer; this library has no i18n and no view layer to own them.
|
|
11
|
-
//
|
|
12
7
|
// Order is the order the picker shows. JA-3080 notes concentration is coming
|
|
13
8
|
// as a third type — add it here and register its discriminator in
|
|
14
9
|
// models/dataDownloads.js, so no consumer has to hardcode the string.
|
package/src/index.js
CHANGED
|
@@ -134,15 +134,10 @@ import {
|
|
|
134
134
|
// as `DATA_DOWNLOAD_MAX_RANGE_DAYS * 86400000` builds a stricter limit than
|
|
135
135
|
// the model and rejects a 745-hour range the schema saves. Same reason
|
|
136
136
|
// validateQuietHours is exported rather than just DEFAULT_QUIET_HOURS.
|
|
137
|
-
//
|
|
138
|
-
// DateOrder applies to every download kind; MaxDateRange applies to AQI
|
|
139
|
-
// only, since Sample downloads have no length cap. Running both against a
|
|
140
|
-
// Sample request rejects year-long ranges the model saves without complaint.
|
|
141
137
|
validateDateOrder as validateDataDownloadDateOrder,
|
|
142
138
|
validateMaxDateRange as validateDataDownloadMaxDateRange,
|
|
143
139
|
validateDownloadEmail as validateDataDownloadEmail,
|
|
144
140
|
normalizeDownloadEmail as normalizeDataDownloadEmail,
|
|
145
|
-
validateDownloadTimezone as validateDataDownloadTimezone,
|
|
146
141
|
} from "./utils/dataDownloadValidation.js";
|
|
147
142
|
|
|
148
143
|
export function createLoggerInstance({ DATADOG_API_KEY, APPLICATION_NAME }) {
|
|
@@ -250,7 +245,6 @@ export {
|
|
|
250
245
|
validateDataDownloadMaxDateRange,
|
|
251
246
|
validateDataDownloadEmail,
|
|
252
247
|
normalizeDataDownloadEmail,
|
|
253
|
-
validateDataDownloadTimezone,
|
|
254
248
|
// Pollutant constants
|
|
255
249
|
PARAMETERS,
|
|
256
250
|
HEAVY_METALS,
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import mongoose from "mongoose";
|
|
2
2
|
import { DATA_DOWNLOAD_TYPES } from "../constants/dataDownloads.js";
|
|
3
3
|
import { DEFAULT_TIMEZONE } from "../constants/timezones.js";
|
|
4
|
+
import { isValidIANATimezone } from "../utils/timezone.js";
|
|
4
5
|
import {
|
|
5
6
|
DATA_DOWNLOAD_ERRORS,
|
|
6
7
|
validateDateOrder,
|
|
7
8
|
validateMaxDateRange,
|
|
8
9
|
validateDownloadEmail,
|
|
9
10
|
normalizeDownloadEmail,
|
|
10
|
-
validateDownloadTimezone,
|
|
11
11
|
} from "../utils/dataDownloadValidation.js";
|
|
12
12
|
|
|
13
13
|
// DataDownloads — one doc per data download request (JA-3080). Written by
|
|
@@ -44,12 +44,12 @@ const dataDownloadSchema = new mongoose.Schema(
|
|
|
44
44
|
default: DEFAULT_TIMEZONE,
|
|
45
45
|
set: (value) => (value === null ? DEFAULT_TIMEZONE : value),
|
|
46
46
|
validate: {
|
|
47
|
-
validator:
|
|
47
|
+
validator: isValidIANATimezone,
|
|
48
48
|
message: "timezone must be a valid IANA timezone identifier",
|
|
49
49
|
type: DATA_DOWNLOAD_ERRORS.INVALID_TIMEZONE,
|
|
50
50
|
},
|
|
51
51
|
},
|
|
52
|
-
downloadedAt: { type: Date, required:
|
|
52
|
+
downloadedAt: { type: Date, required: true, default: Date.now },
|
|
53
53
|
// Figma's download modal requires checking "I have reviewed and agree to
|
|
54
54
|
// the Data Sharing Agreement" before the download proceeds (JA-3245).
|
|
55
55
|
// Stored as the acceptance timestamp rather than a boolean so the
|
|
@@ -93,12 +93,6 @@ const dataDownloadSchema = new mongoose.Schema(
|
|
|
93
93
|
//
|
|
94
94
|
// Passes the error code as invalidate()'s `kind` so a caught ValidationError
|
|
95
95
|
// can be classified via err.errors.<path>.kind, not by message wording.
|
|
96
|
-
//
|
|
97
|
-
// Same caveat the `timezone` field carries: pre('validate') never runs on a
|
|
98
|
-
// query update, so a `$set` of dateRangeStart/dateRangeEnd can persist a
|
|
99
|
-
// reversed or over-length range even with { runValidators: true }. Deliberate
|
|
100
|
-
// — the rules are cross-field, and query updates have no full document to
|
|
101
|
-
// check. Writers should go through create()/save(); readers must still defend.
|
|
102
96
|
dataDownloadSchema.pre("validate", function () {
|
|
103
97
|
const rangeErrors = validateDateOrder({ start: this.dateRangeStart, end: this.dateRangeEnd });
|
|
104
98
|
for (const error of rangeErrors) {
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
// Data download validation (JA-3080/JA-3245): the shared field and cross-field
|
|
2
2
|
// rules for a DataDownloads document — date range order, the AQI-only length
|
|
3
|
-
// cap, the optional email
|
|
4
|
-
//
|
|
3
|
+
// cap, and the optional email. Pure functions, no DB, no clock reads. Same
|
|
4
|
+
// shape as quietHours.js's cross-field validator.
|
|
5
5
|
//
|
|
6
6
|
// Two separate rules, deliberately not one function: end-must-not-precede-
|
|
7
7
|
// start applies to every download kind, but the 31-day cap is AQI-only.
|
|
8
|
-
import { isValidIANATimezone } from "./timezone.js";
|
|
9
8
|
|
|
10
9
|
// Messaging only ("range cannot exceed 31 days"). validateMaxDateRange is the
|
|
11
10
|
// sole authority on the enforced bound; don't rebuild the cap from this.
|
|
@@ -123,24 +122,3 @@ export const validateDownloadEmail = ({ email } = {}) => {
|
|
|
123
122
|
},
|
|
124
123
|
];
|
|
125
124
|
};
|
|
126
|
-
|
|
127
|
-
// Returns { code, message }[]; empty = valid. null/undefined is valid: the
|
|
128
|
-
// schema's setter resolves either to DEFAULT_TIMEZONE, so a consumer
|
|
129
|
-
// pre-validating a request body must accept the same "didn't pick one" shape
|
|
130
|
-
// the model stores. isValidIANATimezone alone rejects null, which would fail
|
|
131
|
-
// a request the model saves happily — the write-path/read-path split the
|
|
132
|
-
// email rules exist to avoid.
|
|
133
|
-
export const validateDownloadTimezone = ({ timezone } = {}) => {
|
|
134
|
-
if (timezone === null || timezone === undefined) {
|
|
135
|
-
return [];
|
|
136
|
-
}
|
|
137
|
-
if (isValidIANATimezone(timezone)) {
|
|
138
|
-
return [];
|
|
139
|
-
}
|
|
140
|
-
return [
|
|
141
|
-
{
|
|
142
|
-
code: DATA_DOWNLOAD_ERRORS.INVALID_TIMEZONE,
|
|
143
|
-
message: "timezone must be a valid IANA timezone identifier",
|
|
144
|
-
},
|
|
145
|
-
];
|
|
146
|
-
};
|
|
@@ -4,7 +4,6 @@ import {
|
|
|
4
4
|
validateDateOrder,
|
|
5
5
|
validateMaxDateRange,
|
|
6
6
|
validateDownloadEmail,
|
|
7
|
-
validateDownloadTimezone,
|
|
8
7
|
normalizeDownloadEmail,
|
|
9
8
|
} from "../dataDownloadValidation.js";
|
|
10
9
|
|
|
@@ -156,31 +155,3 @@ describe("validateDownloadEmail (email is optional — JA-3080)", () => {
|
|
|
156
155
|
]);
|
|
157
156
|
});
|
|
158
157
|
});
|
|
159
|
-
|
|
160
|
-
describe("validateDownloadTimezone", () => {
|
|
161
|
-
test.each(["America/New_York", "America/Detroit", "UTC", "Asia/Tokyo"])(
|
|
162
|
-
"accepts %s",
|
|
163
|
-
(timezone) => {
|
|
164
|
-
expect(validateDownloadTimezone({ timezone })).toEqual([]);
|
|
165
|
-
}
|
|
166
|
-
);
|
|
167
|
-
|
|
168
|
-
// The schema setter resolves both to DEFAULT_TIMEZONE, so a consumer
|
|
169
|
-
// pre-validating a request body must accept what the model stores.
|
|
170
|
-
test.each([null, undefined])("treats %p as valid (the setter fills the default)", (timezone) => {
|
|
171
|
-
expect(validateDownloadTimezone({ timezone })).toEqual([]);
|
|
172
|
-
});
|
|
173
|
-
|
|
174
|
-
test("accepts a call with no argument at all", () => {
|
|
175
|
-
expect(validateDownloadTimezone()).toEqual([]);
|
|
176
|
-
});
|
|
177
|
-
|
|
178
|
-
test.each(["America/Fake_City", "Not/A_Zone", " ", 5, {}])(
|
|
179
|
-
"flags %p with INVALID_TIMEZONE",
|
|
180
|
-
(timezone) => {
|
|
181
|
-
expect(validateDownloadTimezone({ timezone })).toEqual([
|
|
182
|
-
expect.objectContaining({ code: DATA_DOWNLOAD_ERRORS.INVALID_TIMEZONE }),
|
|
183
|
-
]);
|
|
184
|
-
}
|
|
185
|
-
);
|
|
186
|
-
});
|