@justair/justair-library 7.15.0 → 7.16.0-alpha.c51e44a

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":"AA8GA,8BA2IE;AAiCF,wBAAmD;AAhRnD,iDAA4D;AAC5D,6CAAmD;AAUnD,4DA0BC"}
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.c51e44a",
4
4
  "description": "JustAir Internal Library",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
@@ -63,16 +63,31 @@ 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
+ // Optional with NO default, on purpose: every element written before JA-3765
88
+ // has no date, and a default would be invented at hydrate time and read as
89
+ // real. Readers treat absent as "unknown"; the JA-3985 backfill dates the old
90
+ // rows from MonitorEpisode history.
76
91
  const subscribedDeviceSchema = mongoose.Schema(
77
92
  {
78
93
  deviceId: { type: mongoose.Types.ObjectId, required: true },
@@ -88,6 +103,7 @@ const subscribedDeviceSchema = mongoose.Schema(
88
103
  // path MUST check the request body against DEVICE_TYPE_VALUES before
89
104
  // writing (and/or pass `{ runValidators: true }` to the update).
90
105
  deviceType: { type: String, enum: DEVICE_TYPE_VALUES, required: true },
106
+ subscribedAt: { type: Date },
91
107
  },
92
108
  { _id: false },
93
109
  );