@planningcenter/topbar 12.4.1-qa-983.0 → 12.5.0-qa-988.0

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/topbar.js CHANGED
@@ -4154,6 +4154,10 @@ async function mintToken(personId) {
4154
4154
  }
4155
4155
  return token;
4156
4156
  }
4157
+ function hasReadOnlyToken(personId) {
4158
+ var _a;
4159
+ return ((_a = cachedToken(personId)) === null || _a === void 0 ? void 0 : _a.readOnly) === true;
4160
+ }
4157
4161
  async function request(personId, key, init = {}, isRetry = false) {
4158
4162
  var _a;
4159
4163
  const token = isRetry ? await mintToken(personId) : (_a = cachedToken(personId)) !== null && _a !== void 0 ? _a : await mintToken(personId);
@@ -4189,8 +4193,8 @@ function ifMatch(version) {
4189
4193
  // retrying when another tab or device wrote in between. `change` returns null
4190
4194
  // when there's nothing to write. A read-only token (staff impersonating
4191
4195
  // someone) only reads, so nothing is written into the person's history.
4192
- // Resolves to the value now stored, or null when the service couldn't be
4193
- // reached.
4196
+ // Resolves to the value now stored, with whether the token was read-only, or
4197
+ // null when the service couldn't be reached.
4194
4198
  async function updateStoredValue(personId, key, change, attemptsLeft = MAX_ATTEMPTS) {
4195
4199
  const read = await request(personId, key);
4196
4200
  if (read === null || read === void 0 ? void 0 : read.response.ok) {
@@ -4198,9 +4202,15 @@ async function updateStoredValue(personId, key, change, attemptsLeft = MAX_ATTEM
4198
4202
  value,
4199
4203
  version
4200
4204
  } = await read.response.json();
4201
- const next = read.token.readOnly ? null : change(value);
4205
+ const {
4206
+ readOnly
4207
+ } = read.token;
4208
+ const next = readOnly ? null : change(value);
4202
4209
  if (next === null) {
4203
- return Array.isArray(value) ? value : [];
4210
+ return {
4211
+ readOnly,
4212
+ value: Array.isArray(value) ? value : []
4213
+ };
4204
4214
  } else {
4205
4215
  const write = await request(personId, key, {
4206
4216
  body: JSON.stringify({
@@ -4213,7 +4223,10 @@ async function updateStoredValue(personId, key, change, attemptsLeft = MAX_ATTEM
4213
4223
  method: "PUT"
4214
4224
  });
4215
4225
  if (write === null || write === void 0 ? void 0 : write.response.ok) {
4216
- return next;
4226
+ return {
4227
+ readOnly,
4228
+ value: next
4229
+ };
4217
4230
  } else if ((write === null || write === void 0 ? void 0 : write.response.status) === 409 && attemptsLeft > 1) {
4218
4231
  return updateStoredValue(personId, key, change, attemptsLeft - 1);
4219
4232
  } else {
@@ -4265,7 +4278,8 @@ async function syncOnce(scope) {
4265
4278
  return isSameList(mergeEntries(shared, local), shared) ? null : mergeStored(stored, local);
4266
4279
  });
4267
4280
  if (synced) {
4268
- writeRecentlyVisited(scope, mergeEntries(entriesFrom(synced), readRecentlyVisited(scope)));
4281
+ const shared = entriesFrom(synced.value);
4282
+ writeRecentlyVisited(scope, synced.readOnly ? shared : mergeEntries(shared, readRecentlyVisited(scope)));
4269
4283
  }
4270
4284
  } catch {
4271
4285
  // The service is best-effort; the local copy stands on its own.
@@ -4296,9 +4310,13 @@ function sync(scope, followUp) {
4296
4310
  function syncRecentlyVisited(scope) {
4297
4311
  return sync(scope, false);
4298
4312
  }
4313
+ // Staff impersonating someone get a read-only token, and their visits stay out
4314
+ // of that person's list. Until the token is minted the visit is kept, and the
4315
+ // sync that mints it replaces the local list with the synced one, so recording
4316
+ // never waits on the network.
4299
4317
  function recordVisit(visit, scope) {
4300
4318
  const entry = toEntry(visit, new Date());
4301
- if (isEntry(entry)) {
4319
+ if (isEntry(entry) && !hasReadOnlyToken(scope.personId)) {
4302
4320
  writeRecentlyVisited(scope, addVisit(readRecentlyVisited(scope), entry));
4303
4321
  sync(scope, true);
4304
4322
  }
@@ -36859,13 +36877,15 @@ const useNotifications = ({
36859
36877
  return notification.data;
36860
36878
  }
36861
36879
  };
36862
- const updateStateFromJoltMessage = React.useCallback(message => {
36880
+ const updateStateFromJoltMessage = React.useCallback(async message => {
36863
36881
  try {
36864
36882
  const joltMessageNotificationDataPayload = extractPayloadFromJoltMessage(message);
36865
- fetchNotification(joltMessageNotificationDataPayload.data.id).then(resp => {
36866
- const notification = buildNotificationFromApiResponse(resp.data, resp);
36867
- setNotifications(notifications => [...notifications.filter(candidate => candidate.id !== notification.id), notification]);
36868
- });
36883
+ const resp = await fetchNotification(joltMessageNotificationDataPayload.data.id);
36884
+ if (!(resp === null || resp === void 0 ? void 0 : resp.data)) {
36885
+ return;
36886
+ }
36887
+ const notification = buildNotificationFromApiResponse(resp.data, resp);
36888
+ setNotifications(notifications => [...notifications.filter(candidate => candidate.id !== notification.id), notification]);
36869
36889
  } catch (exception) {
36870
36890
  console.error("topbar encountered error when updating state from jolt message", exception);
36871
36891
  }