@justair/justair-library 7.15.0 → 7.16.0-alpha.904c753

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":"users.d.ts","sourceRoot":"","sources":["../../src/models/users.js"],"names":[],"mappings":"AA8FA,8BA2IE;AAiCF,wBAAmD;AAhQnD,iDAA4D;AAC5D,6CAAmD;AAUnD,4DA0BC"}
1
+ {"version":3,"file":"users.d.ts","sourceRoot":"","sources":["../../src/models/users.js"],"names":[],"mappings":"AAuHA,8BA2IE;AAiCF,wBAAmD;AAzRnD,iDAA4D;AAC5D,6CAAmD;AAUnD,4DA0BC"}
@@ -16,6 +16,7 @@ export const VISIBLE_SITE_MONITOR_FILTER: Readonly<{
16
16
  export function projectSubscribedMonitors(subscribedDevices?: Array<{
17
17
  deviceId: import("mongoose").Types.ObjectId;
18
18
  deviceType: import("../constants/deviceTypes.js").DeviceType;
19
+ subscribedAt?: Date;
19
20
  }>, { resolveSiteMonitorIds }?: {
20
21
  resolveSiteMonitorIds?: (siteIds: import("mongoose").Types.ObjectId[]) => Promise<Array<import("mongoose").Types.ObjectId | null | undefined>>;
21
22
  }): Promise<import("mongoose").Types.ObjectId[]>;
@@ -24,6 +25,7 @@ export function resolveSubscribedMonitorIdsByUser(users?: Array<{
24
25
  subscribedDevices?: Array<{
25
26
  deviceId: import("mongoose").Types.ObjectId;
26
27
  deviceType: import("../constants/deviceTypes.js").DeviceType;
28
+ subscribedAt?: Date;
27
29
  }>;
28
30
  }>, { resolveVisibleSiteMonitors }?: {
29
31
  resolveVisibleSiteMonitors?: (siteIds: import("mongoose").Types.ObjectId[]) => Promise<Map<string, import("mongoose").Types.ObjectId[]>>;
@@ -1 +1 @@
1
- {"version":3,"file":"subscribedDevices.d.ts","sourceRoot":"","sources":["../../src/utils/subscribedDevices.js"],"names":[],"mappings":"AA0FA;;;;;;;;GASG;AA+CH;;;;;GAGG;AA6LI,8DANI,KA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,CAAC;IAC7D,YAAY,CAAC,EAAE,IAAI,CAAA;CAAE,CAAC,8BAChB;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;AA2EM,0DARI,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,CAAC;QAC7D,YAAY,CAAC,EAAE,IAAI,CAAA;KAAE,CAAC,CAAA;CAAE,CAAC,mCACnB;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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@justair/justair-library",
3
- "version": "7.15.0",
3
+ "version": "7.16.0-alpha.904c753",
4
4
  "description": "JustAir Internal Library",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
@@ -63,16 +63,40 @@ const validateCookieConsent = (consent) => {
63
63
  // projectSubscribedMonitors would read the `monitor` row as a monitor id and
64
64
  // write a Site id into subscribedMonitors, which is precisely the polymorphic
65
65
  // id the subscribedMonitors/subscribedDevices split exists to keep out, and it
66
- // fails silently (the notification service just filters it away). Consumers on
67
- // the subscribe path should `$pull { deviceId }` before `$addToSet` so a
68
- // re-subscribe with a corrected type replaces the row instead of adding one.
66
+ // fails silently (the notification service just filters it away). Since
67
+ // JA-3765 the subscribe path guards on deviceId alone (below), so a second
68
+ // type for the same id is refused rather than added; rows written earlier
69
+ // under `$addToSet` can still hold both and are removed by an exact `$pull`.
69
70
  //
70
- // That is two sequential updates, not one. MongoDB rejects `$pull` and
71
- // `$addToSet` on the same path in a single update document ("would create a
72
- // conflict at 'subscribedDevices'"), so the pull must be awaited before the
73
- // add. Between the two writes the user reads as unsubscribed from that device;
74
- // the window is only worth closing with a transaction if a concurrent read
75
- // acting on it would be harmful.
71
+ // `subscribedAt` (JA-3765) is when the user followed the device, read per org
72
+ // by the admin Community > Communication page. It lives INSIDE the element,
73
+ // which ends the `$addToSet` dedupe described above: a fresh timestamp makes
74
+ // every pushed element distinct, so `$addToSet` would add a row per click.
75
+ // Writers that stamp it must guard in the filter instead and `$push`:
76
+ //
77
+ // updateOne(
78
+ // { _id, "subscribedDevices.deviceId": { $ne: deviceId } },
79
+ // { $push: { subscribedDevices: { deviceId, deviceType, subscribedAt: now } } },
80
+ // )
81
+ //
82
+ // A repeat subscribe then matches nothing, writes nothing and keeps the first
83
+ // date; the filter and the push are one atomic single-document update, so two
84
+ // concurrent clicks still leave one row. Guarding on deviceId alone (not the
85
+ // pair) also enforces "a deviceId never carries two types".
86
+ //
87
+ // `matchedCount: 0` from that update is ambiguous: it means "already follows
88
+ // this device" OR "no user with this _id". A caller that must tell the two
89
+ // apart (404 vs idempotent 200) has to check the user exists separately.
90
+ //
91
+ // Once any row can carry a date, `$addToSet` on this array is unsafe in BOTH
92
+ // directions: a dated push never matches an existing row, and an undated
93
+ // `$addToSet` (e.g. an instance still on the old code mid-deploy) never
94
+ // matches a row that already has a date. Either way the device is listed
95
+ // twice. Every writer must use the guard above.
96
+ //
97
+ // Optional with NO default, on purpose: every element written before JA-3765
98
+ // has no date, and a default would be invented at hydrate time and read as
99
+ // real. Readers treat absent as "unknown".
76
100
  const subscribedDeviceSchema = mongoose.Schema(
77
101
  {
78
102
  deviceId: { type: mongoose.Types.ObjectId, required: true },
@@ -88,6 +112,7 @@ const subscribedDeviceSchema = mongoose.Schema(
88
112
  // path MUST check the request body against DEVICE_TYPE_VALUES before
89
113
  // writing (and/or pass `{ runValidators: true }` to the update).
90
114
  deviceType: { type: String, enum: DEVICE_TYPE_VALUES, required: true },
115
+ subscribedAt: { type: Date },
91
116
  },
92
117
  { _id: false },
93
118
  );
@@ -331,7 +331,8 @@ const validateResolvedSiteMonitorMap = (resolved) => {
331
331
  // user.
332
332
  /**
333
333
  * @param {Array<{ deviceId: import("mongoose").Types.ObjectId,
334
- * deviceType: import("../constants/deviceTypes.js").DeviceType }>} [subscribedDevices]
334
+ * deviceType: import("../constants/deviceTypes.js").DeviceType,
335
+ * subscribedAt?: Date }>} [subscribedDevices]
335
336
  * @param {{ resolveSiteMonitorIds?: (siteIds: import("mongoose").Types.ObjectId[]) =>
336
337
  * Promise<Array<import("mongoose").Types.ObjectId | null | undefined>> }} [options]
337
338
  * @returns {Promise<import("mongoose").Types.ObjectId[]>}
@@ -429,7 +430,8 @@ export const projectSubscribedMonitors = async (
429
430
  /**
430
431
  * @param {Array<{ _id: any, subscribedDevices?: Array<{
431
432
  * deviceId: import("mongoose").Types.ObjectId,
432
- * deviceType: import("../constants/deviceTypes.js").DeviceType }> }>} [users]
433
+ * deviceType: import("../constants/deviceTypes.js").DeviceType,
434
+ * subscribedAt?: Date }> }>} [users]
433
435
  * @param {{ resolveVisibleSiteMonitors?: (siteIds: import("mongoose").Types.ObjectId[]) =>
434
436
  * Promise<Map<string, import("mongoose").Types.ObjectId[]>> }} [options]
435
437
  * @returns {Promise<Map<string, import("mongoose").Types.ObjectId[]>>}