@sprucelabs/spruce-calendar-components 29.0.3 → 29.0.5

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.
Files changed (43) hide show
  1. package/build/.spruce/errors/errors.types.d.ts +12 -12
  2. package/build/.spruce/errors/options.types.d.ts +2 -2
  3. package/build/.spruce/schemas/schemas.types.d.ts +2651 -3201
  4. package/build/.spruce/schemas/schemas.types.js +3 -0
  5. package/build/__tests__/support/CalendarToolBeltStateMachineTestFactory.js +11 -13
  6. package/build/__tests__/support/SpyEventManager.js +1 -1
  7. package/build/__tests__/support/SpyPeopleManager.js +4 -4
  8. package/build/__tests__/support/SpyRemoteEventStore.js +4 -4
  9. package/build/__tests__/support/utilities/calendarAssert.js +2 -1
  10. package/build/__tests__/support/utilities/calendarSkillAssert.js +5 -4
  11. package/build/calendar/Calendar.vc.js +17 -18
  12. package/build/calendar/CalendarEventManager.js +42 -49
  13. package/build/calendar/CalendarPeopleManager.js +12 -15
  14. package/build/calendar/CalendarPersister.js +9 -12
  15. package/build/constants.js +2 -1
  16. package/build/errors/SpruceError.js +1 -1
  17. package/build/esm/.spruce/errors/errors.types.d.ts +12 -12
  18. package/build/esm/.spruce/errors/options.types.d.ts +2 -2
  19. package/build/esm/.spruce/schemas/schemas.types.d.ts +2651 -3201
  20. package/build/esm/.spruce/schemas/schemas.types.js +3 -0
  21. package/build/root/Root.svc.js +36 -49
  22. package/build/stores/RemoteEventStore.js +13 -18
  23. package/build/stores/RemotePreferencesStore.js +4 -10
  24. package/build/toolBelt/CalendarToolRegistrar.js +12 -8
  25. package/build/toolBelt/CalendarToolTestFactory.js +1 -1
  26. package/build/toolBelt/states/AbstractCalendarEventToolBeltState.js +20 -20
  27. package/build/toolBelt/states/PrerequisitesToolBeltState.js +21 -24
  28. package/build/toolBelt/states/RootToolBeltState.js +19 -22
  29. package/build/toolBelt/states/UniversalEventToolBeltState.js +4 -1
  30. package/build/toolBelt/states/makeEventTyped.js +2 -1
  31. package/build/tools/CalendarSelectTool.vc.js +4 -7
  32. package/build/tools/EventDateTimeTool.vc.js +6 -10
  33. package/build/tools/EventDurationTool.vc.js +4 -7
  34. package/build/tools/EventRepeatingTool.vc.js +3 -7
  35. package/build/tools/EventTitleTool.vc.js +5 -8
  36. package/build/tools/PersonSelectTool.vc.js +8 -11
  37. package/build/utilities/draftGenerator.js +1 -1
  38. package/build/viewControllers/DateSelectCard.vc.js +2 -5
  39. package/build/viewControllers/EventControlsCard.vc.js +5 -9
  40. package/build/viewControllers/RepeatingControlsList.vc.js +54 -44
  41. package/build/viewControllers/SelectUpdateRepeatingStrategyCard.vc.js +4 -7
  42. package/build/viewControllers/UniversalCalendarEvent.vc.js +1 -1
  43. package/package.json +1 -1
@@ -1,4 +1,7 @@
1
1
  "use strict";
2
+ /* eslint-disable @typescript-eslint/no-namespace */
3
+ /* eslint-disable no-redeclare */
4
+ /* eslint-disable @typescript-eslint/no-unused-vars */
2
5
  /* eslint-disable import/order */
3
6
  Object.defineProperty(exports, "__esModule", { value: true });
4
7
  require("@sprucelabs/spruce-event-utils");
@@ -15,20 +15,19 @@ const SpyPeopleManager_1 = __importDefault(require("./SpyPeopleManager"));
15
15
  const mixinViewControllersForTests_1 = __importDefault(require("./utilities/mixinViewControllersForTests"));
16
16
  class CalendarToolBeltStateMachineTestFactory {
17
17
  static async StateMachine(views, options) {
18
- const { EventManagerClass, calendarVc: passedCalendarVc } = options ?? {};
18
+ const { EventManagerClass, calendarVc: passedCalendarVc } = options !== null && options !== void 0 ? options : {};
19
19
  const factory = views.getFactory();
20
20
  (0, mixinViewControllersForTests_1.default)(factory);
21
21
  const toolBeltVc = views.Controller('toolBelt', {});
22
22
  const event = heartwood_view_controllers_1.calendarSeeder.generateEventValues();
23
- const calendarVc = passedCalendarVc ??
24
- views.Controller('calendar.calendar', {
25
- onAddDraftEvent: async (event) => {
26
- await events.addDraftEvent(event);
27
- },
28
- onEventSwapped(draft, saved) {
29
- return events.silentlySwapEvent(draft.id, saved);
30
- },
31
- });
23
+ const calendarVc = passedCalendarVc !== null && passedCalendarVc !== void 0 ? passedCalendarVc : views.Controller('calendar.calendar', {
24
+ onAddDraftEvent: async (event) => {
25
+ await events.addDraftEvent(event);
26
+ },
27
+ onEventSwapped(draft, saved) {
28
+ return events.silentlySwapEvent(draft.id, saved);
29
+ },
30
+ });
32
31
  calendarVc.addEvent(event);
33
32
  const sm = new heartwood_view_controllers_1.ToolBeltStateMachine({
34
33
  vcFactory: views.getFactory(),
@@ -44,7 +43,7 @@ class CalendarToolBeltStateMachineTestFactory {
44
43
  const connectToApi = async () => spruce_test_fixtures_1.fake.getClient();
45
44
  const preferences = new FakeRemotePreferences({ connectToApi });
46
45
  const remoteEventsStore = new FakeRemoteEventStore();
47
- const events = new (EventManagerClass ?? SpyEventManager_1.default)({
46
+ const events = new (EventManagerClass !== null && EventManagerClass !== void 0 ? EventManagerClass : SpyEventManager_1.default)({
48
47
  calendarVc,
49
48
  sm,
50
49
  dates: calendar_utils_1.dateUtil,
@@ -81,8 +80,6 @@ class FakeRemotePreferences extends RemotePreferencesStore_1.default {
81
80
  async save() { }
82
81
  }
83
82
  class FakeRemoteEventStore {
84
- static calendars = [];
85
- lastPersistedEvent;
86
83
  async load(_options) { }
87
84
  async persist(event) {
88
85
  const e = {
@@ -118,3 +115,4 @@ class FakeRemoteEventStore {
118
115
  setStreamHandler(_cb) { }
119
116
  }
120
117
  exports.FakeRemoteEventStore = FakeRemoteEventStore;
118
+ FakeRemoteEventStore.calendars = [];
@@ -5,12 +5,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const CalendarEventManager_1 = __importDefault(require("../../calendar/CalendarEventManager"));
7
7
  class SpyEventManager extends CalendarEventManager_1.default {
8
- wereShiftsRefreshed = false;
9
8
  getShouldIgnoreNextContextUpdate() {
10
9
  return this.shouldIgnoreNextContextUpdate;
11
10
  }
12
11
  constructor(options) {
13
12
  super(options);
13
+ this.wereShiftsRefreshed = false;
14
14
  }
15
15
  refreshShifts() {
16
16
  this.wereShiftsRefreshed = true;
@@ -5,16 +5,16 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const CalendarPeopleManager_1 = __importDefault(require("../../calendar/CalendarPeopleManager"));
7
7
  class SpyPeopleManager extends CalendarPeopleManager_1.default {
8
- visiblePeopleIds;
9
- peopleVisibilityMode;
10
8
  constructor(options) {
11
9
  super(options);
12
10
  }
13
11
  getVisiblePeopleIds() {
14
- return this.visiblePeopleIds ?? super.getVisiblePeopleIds();
12
+ var _a;
13
+ return (_a = this.visiblePeopleIds) !== null && _a !== void 0 ? _a : super.getVisiblePeopleIds();
15
14
  }
16
15
  getVisibilityMode() {
17
- return this.peopleVisibilityMode ?? super.getVisibilityMode();
16
+ var _a;
17
+ return (_a = this.peopleVisibilityMode) !== null && _a !== void 0 ? _a : super.getVisibilityMode();
18
18
  }
19
19
  async setVisiblePeopleIds(ids, options) {
20
20
  return super.setVisiblePeopleIds(ids, options);
@@ -6,21 +6,21 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const test_utils_1 = require("@sprucelabs/test-utils");
7
7
  const RemoteEventStore_1 = __importDefault(require("../../stores/RemoteEventStore"));
8
8
  class SpyRemoteEventStore extends RemoteEventStore_1.default {
9
- lastPersistedEvent;
10
9
  constructor(options) {
11
10
  const { calendars, client, locationId, organizationId } = options;
12
11
  super({ connectToApi: async () => client });
13
12
  this.client = client;
14
13
  this.calendars = calendars;
15
- this.locationId = locationId ?? (0, test_utils_1.generateId)();
16
- this.organizationId = organizationId ?? (0, test_utils_1.generateId)();
14
+ this.locationId = locationId !== null && locationId !== void 0 ? locationId : (0, test_utils_1.generateId)();
15
+ this.organizationId = organizationId !== null && organizationId !== void 0 ? organizationId : (0, test_utils_1.generateId)();
17
16
  }
18
17
  setOrganizationId(id) {
19
18
  this.organizationId = id;
20
19
  }
21
20
  async cancelEvent(_id, _options) { }
22
21
  async getCalendars() {
23
- return this.calendars ?? super.getCalendars();
22
+ var _a;
23
+ return (_a = this.calendars) !== null && _a !== void 0 ? _a : super.getCalendars();
24
24
  }
25
25
  async persist(event) {
26
26
  const results = await super.persist(event);
@@ -58,10 +58,11 @@ const calendarAssert = {
58
58
  }
59
59
  },
60
60
  eventEquals(actual, expected) {
61
+ var _a, _b, _c, _d;
61
62
  test_utils_1.assert.isTruthy(actual, 'Event is missing');
62
63
  test_utils_1.assert.isTruthy(expected, 'Event is missing');
63
64
  test_utils_1.assert.isEqual(actual.startDateTimeMs, expected.startDateTimeMs, 'startDateTimeMs does not match');
64
- test_utils_1.assert.isEqual(actual.isBusy ?? false, expected.isBusy ?? false, `isBusy does not match, needs to be '${expected.isBusy ?? false}' but got '${actual.isBusy ?? false}'`);
65
+ test_utils_1.assert.isEqual((_a = actual.isBusy) !== null && _a !== void 0 ? _a : false, (_b = expected.isBusy) !== null && _b !== void 0 ? _b : false, `isBusy does not match, needs to be '${(_c = expected.isBusy) !== null && _c !== void 0 ? _c : false}' but got '${(_d = actual.isBusy) !== null && _d !== void 0 ? _d : false}'`);
65
66
  const cleanedActual = (0, just_clone_1.default)(actual);
66
67
  const cleanedExpected = (0, just_clone_1.default)(expected);
67
68
  cleanEvent(cleanedActual);
@@ -45,6 +45,7 @@ const calendarSkillAssert = {
45
45
  await fakeCalendarEvents(this.createdCalendars);
46
46
  },
47
47
  async createsCalendarOnInstall(calendarSlug, client, typeSlugs) {
48
+ var _a, _b, _c, _d;
48
49
  assertRanBeforeEach(this);
49
50
  (0, schema_1.assertOptions)({
50
51
  calendarSlug,
@@ -66,7 +67,7 @@ const calendarSkillAssert = {
66
67
  },
67
68
  });
68
69
  if (responses.totalErrors > 0) {
69
- throw responses.responses[0].errors?.[0] ?? `did-instal error`;
70
+ throw (_b = (_a = responses.responses[0].errors) === null || _a === void 0 ? void 0 : _a[0]) !== null && _b !== void 0 ? _b : `did-instal error`;
70
71
  }
71
72
  if (responses.totalResponses === 0) {
72
73
  test_utils_1.assert.fail(`did-install listener missing! To get this test passing your skill will need to be listening to did-install, try 'spruce create.listener' and look under Mercury. You may also need to boot your skill with 'await this.bootSkill()'`);
@@ -98,7 +99,7 @@ await client.emitAndFlattenResponses(
98
99
  slug: '${calendarSlug}',
99
100
  },
100
101
  }
101
- )\n\nOh, and here's the original error: ${err.stack ?? err.message ?? err}`);
102
+ )\n\nOh, and here's the original error: ${(_d = (_c = err.stack) !== null && _c !== void 0 ? _c : err.message) !== null && _d !== void 0 ? _d : err}`);
102
103
  }
103
104
  if (typeSlugs) {
104
105
  test_utils_1.assert.isEqualDeep(cal.eventTypes, typeSlugs, `Your calendar does not have types set to: [${typeSlugs.join(', ')}]`);
@@ -138,7 +139,7 @@ try {
138
139
  },
139
140
  async createsEventTypesOnBoot(types, client, boot) {
140
141
  assertRanBeforeEach(this);
141
- await boot?.();
142
+ await (boot === null || boot === void 0 ? void 0 : boot());
142
143
  test_utils_1.assert.isTruthy(
143
144
  //@ts-ignore
144
145
  client.auth.skill, `You gotta be logged in as a skill! Try 'const { client } = await this.skills.loginAsCurrentSkill()'`);
@@ -286,7 +287,7 @@ await tools.fetchAndAddCards()
286
287
  exports.default = calendarSkillAssert;
287
288
  async function fakeEventTypeEvents(eventTypes) {
288
289
  await spruce_test_fixtures_1.eventFaker.on('calendar.list-calendar-event-types::v2021_05_19', ({ source }) => {
289
- const matches = eventTypes.filter((t) => t.source.skillId === source?.skillId);
290
+ const matches = eventTypes.filter((t) => t.source.skillId === (source === null || source === void 0 ? void 0 : source.skillId));
290
291
  return {
291
292
  calendarEventTypes: matches,
292
293
  count: matches.length,
@@ -9,14 +9,6 @@ const schema_1 = require("@sprucelabs/schema");
9
9
  const draftGenerator_1 = __importDefault(require("../utilities/draftGenerator"));
10
10
  const CalendarPersister_1 = __importDefault(require("./CalendarPersister"));
11
11
  class CalendarViewController extends heartwood_view_controllers_1.CalendarViewController {
12
- static id = 'calendar';
13
- draftAddedHandler;
14
- sorter;
15
- dropEventHandler;
16
- isSwapping;
17
- persister;
18
- draftRemovedHandler;
19
- eventSwappedHandler;
20
12
  constructor(options) {
21
13
  const { remoteEventStore, onDropEvent, ...rest } = options;
22
14
  super({
@@ -67,6 +59,7 @@ class CalendarViewController extends heartwood_view_controllers_1.CalendarViewCo
67
59
  await this.addDraftEventFromClick(options);
68
60
  }
69
61
  async handleDropEvent(options) {
62
+ var _a;
70
63
  const { event, blockUpdates, newPersonId, newStartDateTimeMs } = options;
71
64
  const updates = {};
72
65
  if (newStartDateTimeMs) {
@@ -85,7 +78,7 @@ class CalendarViewController extends heartwood_view_controllers_1.CalendarViewCo
85
78
  update.durationSec / 60;
86
79
  }
87
80
  }
88
- const results = await this.dropEventHandler?.(event.id, { ...updates });
81
+ const results = await ((_a = this.dropEventHandler) === null || _a === void 0 ? void 0 : _a.call(this, event.id, { ...updates }));
89
82
  return results !== false;
90
83
  }
91
84
  getCalendarVc() {
@@ -99,7 +92,8 @@ class CalendarViewController extends heartwood_view_controllers_1.CalendarViewCo
99
92
  });
100
93
  }
101
94
  getRemoteStore() {
102
- return this.persister?.getRemoteStore();
95
+ var _a;
96
+ return (_a = this.persister) === null || _a === void 0 ? void 0 : _a.getRemoteStore();
103
97
  }
104
98
  async handleClickView(options) {
105
99
  const selected = this.getSelectedEvent();
@@ -127,19 +121,20 @@ class CalendarViewController extends heartwood_view_controllers_1.CalendarViewCo
127
121
  return draft;
128
122
  }
129
123
  async removeDraftEvent(id) {
124
+ var _a, _b, _c;
130
125
  await this.removeEvent(id);
131
- await this.draftRemovedHandler?.();
126
+ await ((_a = this.draftRemovedHandler) === null || _a === void 0 ? void 0 : _a.call(this));
132
127
  try {
133
- await this.persister?.cancelEvent(id);
128
+ await ((_b = this.persister) === null || _b === void 0 ? void 0 : _b.cancelEvent(id));
134
129
  }
135
130
  catch (err) {
136
- console.error(err.stack ?? err.message);
131
+ console.error((_c = err.stack) !== null && _c !== void 0 ? _c : err.message);
137
132
  }
138
133
  }
139
134
  async addDraftEventFromClick(options) {
140
135
  const { personId, dateTimeMs } = options;
141
136
  const event = {
142
- ...draftGenerator_1.default.generate(dateTimeMs ?? 0, personId ?? '**missing**'),
137
+ ...draftGenerator_1.default.generate(dateTimeMs !== null && dateTimeMs !== void 0 ? dateTimeMs : 0, personId !== null && personId !== void 0 ? personId : '**missing**'),
143
138
  };
144
139
  //@ts-ignore
145
140
  delete event.id;
@@ -164,7 +159,7 @@ class CalendarViewController extends heartwood_view_controllers_1.CalendarViewCo
164
159
  const draftAddedPromise = this.draftAddedHandler(event);
165
160
  const saved = await this.persist(event);
166
161
  await draftAddedPromise;
167
- return saved ?? event;
162
+ return saved !== null && saved !== void 0 ? saved : event;
168
163
  }
169
164
  getIsSwappingEvent() {
170
165
  return this.isSwapping;
@@ -208,19 +203,23 @@ class CalendarViewController extends heartwood_view_controllers_1.CalendarViewCo
208
203
  return { ...updates };
209
204
  }
210
205
  async persist(event) {
211
- return this.persister?.persist(event);
206
+ var _a;
207
+ return (_a = this.persister) === null || _a === void 0 ? void 0 : _a.persist(event);
212
208
  }
213
209
  async waitForPendingSaves() {
214
- await this.persister?.waitForPendingSaves();
210
+ var _a;
211
+ await ((_a = this.persister) === null || _a === void 0 ? void 0 : _a.waitForPendingSaves());
215
212
  }
216
213
  render() {
214
+ var _a, _b;
217
215
  const model = super.render();
218
216
  return {
219
217
  ...model,
220
218
  onLongPressEvent: () => this.getDevice().vibrate(),
221
219
  onLongPressView: () => this.getDevice().vibrate(),
222
- shouldEnableSwipeNav: (model.people?.length ?? 0) === 1,
220
+ shouldEnableSwipeNav: ((_b = (_a = model.people) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0) === 1,
223
221
  };
224
222
  }
225
223
  }
224
+ CalendarViewController.id = 'calendar';
226
225
  exports.default = CalendarViewController;
@@ -11,32 +11,16 @@ const draftGenerator_1 = __importDefault(require("../utilities/draftGenerator"))
11
11
  const calculateCalendarEventDifferences_1 = __importDefault(require("./calculateCalendarEventDifferences"));
12
12
  const CalendarPersister_1 = __importDefault(require("./CalendarPersister"));
13
13
  class CalendarEventManager {
14
- static shouldBatchEvents = false;
15
- calendarVc;
16
- allEvents = [];
17
- inclusiveCalendarIds = [];
18
- events;
19
- eventTypes;
20
- remoteVc;
21
- hasVcForEventTypeBeenLoaded = {};
22
- sm;
23
- shouldIgnoreNextContextUpdate = false;
24
- askForUpdateStrategy;
25
- dateToUpdate;
26
- shouldUpdateAllEventsGoingForward;
27
- prefs;
28
- calendars = [];
29
- isLoaded = false;
30
- updateContext;
31
- updateOperations = [];
32
- isRunningUpdateQueue = false;
33
- updateQueuePromise;
34
- persister;
35
- hasPendingContextChanges = false;
36
- //@ts-ignore
37
- loadEventsStartTimeMs;
38
- activeChunk;
39
14
  constructor(options) {
15
+ this.allEvents = [];
16
+ this.inclusiveCalendarIds = [];
17
+ this.hasVcForEventTypeBeenLoaded = {};
18
+ this.shouldIgnoreNextContextUpdate = false;
19
+ this.calendars = [];
20
+ this.isLoaded = false;
21
+ this.updateOperations = [];
22
+ this.isRunningUpdateQueue = false;
23
+ this.hasPendingContextChanges = false;
40
24
  const { calendarVc, events, remoteVc, sm, askForUpdateStrategy, preferences, } = (0, schema_1.assertOptions)(options, [
41
25
  'calendarVc',
42
26
  'events',
@@ -63,12 +47,13 @@ class CalendarEventManager {
63
47
  return this.calendars.map((c) => c.id);
64
48
  }
65
49
  get visibleCalendarIds() {
66
- return (this.prefs.getVisibleCalendarIds() ??
67
- this.calendars.map((c) => c.id));
50
+ var _a;
51
+ return ((_a = this.prefs.getVisibleCalendarIds()) !== null && _a !== void 0 ? _a : this.calendars.map((c) => c.id));
68
52
  }
69
53
  async handleStreamEvents(options) {
54
+ var _a;
70
55
  const { events, chunkingId } = options;
71
- const { id, startDate, endDate } = this.activeChunk ?? {};
56
+ const { id, startDate, endDate } = (_a = this.activeChunk) !== null && _a !== void 0 ? _a : {};
72
57
  if (id !== chunkingId || !startDate || !endDate) {
73
58
  return;
74
59
  }
@@ -90,7 +75,8 @@ class CalendarEventManager {
90
75
  this.calendarVc.setShifts([...shifts]);
91
76
  }
92
77
  doShiftsMatchWhatIsInCalendar(shifts) {
93
- const currentShifts = this.generateShiftKeys(this.calendarVc.getShifts() ?? []);
78
+ var _a;
79
+ const currentShifts = this.generateShiftKeys((_a = this.calendarVc.getShifts()) !== null && _a !== void 0 ? _a : []);
94
80
  const newShifts = this.generateShiftKeys(shifts);
95
81
  const areShiftsTheSame = newShifts === currentShifts;
96
82
  return areShiftsTheSame;
@@ -144,9 +130,10 @@ class CalendarEventManager {
144
130
  this.calendarVc.mixinEvents(events);
145
131
  }
146
132
  async silentlySwapEvent(oldId, event) {
133
+ var _a;
147
134
  const events = this.getEvents().filter((e) => e.id !== oldId);
148
135
  this.allEvents = [...events, event];
149
- if (this.sm.getContext().event?.id === oldId) {
136
+ if (((_a = this.sm.getContext().event) === null || _a === void 0 ? void 0 : _a.id) === oldId) {
150
137
  await this.updateEventInContext(event);
151
138
  }
152
139
  }
@@ -172,8 +159,9 @@ class CalendarEventManager {
172
159
  }
173
160
  }
174
161
  async reset() {
162
+ var _a;
175
163
  await this.setEventInContext(undefined);
176
- this.events?.clearCalendarId();
164
+ (_a = this.events) === null || _a === void 0 ? void 0 : _a.clearCalendarId();
177
165
  }
178
166
  async restoreEventToDraftOnStateLoadError() {
179
167
  const updated = await this.updateEventInContext({
@@ -187,7 +175,8 @@ class CalendarEventManager {
187
175
  return this.visibleCalendarIds;
188
176
  }
189
177
  async cancelEvent(id, options) {
190
- const { shouldPersist = true } = options ?? {};
178
+ var _a;
179
+ const { shouldPersist = true } = options !== null && options !== void 0 ? options : {};
191
180
  const event = this.calendarVc.getEvent(id);
192
181
  if (shouldPersist) {
193
182
  const { pass } = await this.optionallyAskForUpdateRepeatingStrategy(event, 'cancel');
@@ -208,7 +197,7 @@ class CalendarEventManager {
208
197
  this.refreshShifts();
209
198
  }
210
199
  catch (err) {
211
- console.error(err.stack ?? err.message);
200
+ console.error((_a = err.stack) !== null && _a !== void 0 ? _a : err.message);
212
201
  this.calendarVc.addEvent({ ...event, error: err });
213
202
  }
214
203
  this.clearRepeatingStrategyOptions();
@@ -242,6 +231,7 @@ class CalendarEventManager {
242
231
  await this.updateQueuePromise;
243
232
  }
244
233
  async runUpdateQueue() {
234
+ var _a;
245
235
  this.isRunningUpdateQueue = true;
246
236
  let next;
247
237
  const savedEvents = [];
@@ -249,15 +239,16 @@ class CalendarEventManager {
249
239
  const e = await next.execute();
250
240
  savedEvents.push(e);
251
241
  }
252
- const currentId = this.sm.getContext().event?.id;
242
+ const currentId = (_a = this.sm.getContext().event) === null || _a === void 0 ? void 0 : _a.id;
253
243
  savedEvents.reverse();
254
244
  const eventMatching = savedEvents.find((e) => e.id === currentId);
255
- if (!this.hasPendingContextChanges && currentId === eventMatching?.id) {
245
+ if (!this.hasPendingContextChanges && currentId === (eventMatching === null || eventMatching === void 0 ? void 0 : eventMatching.id)) {
256
246
  await this.updateEventInContext(eventMatching);
257
247
  }
258
248
  this.isRunningUpdateQueue = false;
259
249
  }
260
250
  async _updateEvent(id, updates) {
251
+ var _a;
261
252
  let { shouldPersist = true, dateToUpdate, shouldUpdateAllEventsGoingForward, ...rest } = updates;
262
253
  const { isTheSame, isTheSameWithoutBusy, match: originalEvent, } = this.calculateDifferences(id, updates);
263
254
  if (isTheSame) {
@@ -297,7 +288,7 @@ class CalendarEventManager {
297
288
  }
298
289
  }
299
290
  catch (err) {
300
- console.error(err.stack ?? err.message);
291
+ console.error((_a = err.stack) !== null && _a !== void 0 ? _a : err.message);
301
292
  return originalEvent;
302
293
  }
303
294
  this.allEvents[idx] = updatedEvent;
@@ -347,8 +338,9 @@ class CalendarEventManager {
347
338
  this.eventTypes = await this.events.getEventTypes();
348
339
  }
349
340
  await Promise.all(events.map(async (e) => {
350
- const type = this.eventTypes?.find((t) => t.slug === e.eventTypeSlug);
351
- if (type?.viewControllerId) {
341
+ var _a;
342
+ const type = (_a = this.eventTypes) === null || _a === void 0 ? void 0 : _a.find((t) => t.slug === e.eventTypeSlug);
343
+ if (type === null || type === void 0 ? void 0 : type.viewControllerId) {
352
344
  await this.setupVcForEventType(type.viewControllerId, type.slug);
353
345
  }
354
346
  }));
@@ -397,9 +389,10 @@ class CalendarEventManager {
397
389
  return updated;
398
390
  }
399
391
  async setEventInContext(newEvent, options) {
392
+ var _a;
400
393
  this.shouldIgnoreNextContextUpdate =
401
- options?.shouldHandleDidUpdateContext !== false;
402
- const didTrigger = await (this.updateContext ?? this.sm.updateContext.bind(this.sm))({
394
+ (options === null || options === void 0 ? void 0 : options.shouldHandleDidUpdateContext) !== false;
395
+ const didTrigger = await ((_a = this.updateContext) !== null && _a !== void 0 ? _a : this.sm.updateContext.bind(this.sm))({
403
396
  event: newEvent,
404
397
  });
405
398
  if (!didTrigger) {
@@ -416,7 +409,7 @@ class CalendarEventManager {
416
409
  const lastSelected = this.getSelectedEvent();
417
410
  const event = this.calendarVc.getEvent(eventId);
418
411
  await this.calendarVc.selectEvent(event.id);
419
- if (lastSelected?.id !== event.id) {
412
+ if ((lastSelected === null || lastSelected === void 0 ? void 0 : lastSelected.id) !== event.id) {
420
413
  await this.setEventInContext(event);
421
414
  }
422
415
  }
@@ -449,8 +442,8 @@ class CalendarEventManager {
449
442
  const { event: originalEvent } = options.current;
450
443
  const { event } = options.updates;
451
444
  let pass = true;
452
- if (event?.id &&
453
- originalEvent?.id === event?.id &&
445
+ if ((event === null || event === void 0 ? void 0 : event.id) &&
446
+ (originalEvent === null || originalEvent === void 0 ? void 0 : originalEvent.id) === (event === null || event === void 0 ? void 0 : event.id) &&
454
447
  !this.shouldIgnoreNextContextUpdate) {
455
448
  const strat = await this.optionallyAskForUpdateRepeatingStrategy(event);
456
449
  pass = strat.pass;
@@ -477,7 +470,7 @@ class CalendarEventManager {
477
470
  return;
478
471
  }
479
472
  const { event } = this.sm.getContext();
480
- if (event?.id) {
473
+ if (event === null || event === void 0 ? void 0 : event.id) {
481
474
  this.hasPendingContextChanges = false;
482
475
  await this.saveEvent(event);
483
476
  }
@@ -509,15 +502,17 @@ class CalendarEventManager {
509
502
  return !!this.allEvents.find((e) => e.id === id);
510
503
  }
511
504
  getLastChunkingId() {
512
- return this.activeChunk?.id;
505
+ var _a;
506
+ return (_a = this.activeChunk) === null || _a === void 0 ? void 0 : _a.id;
513
507
  }
514
508
  async optionallyAskForUpdateRepeatingStrategy(event, action = 'update') {
509
+ var _a;
515
510
  if (!event.id) {
516
511
  return { pass: true };
517
512
  }
518
513
  let dateToUpdate = undefined;
519
514
  let shouldUpdateAllEventsGoingForward = undefined;
520
- if ((event.totalInRepeating ?? 0) > 1) {
515
+ if (((_a = event.totalInRepeating) !== null && _a !== void 0 ? _a : 0) > 1) {
521
516
  const cleaned = (0, schema_1.normalizeSchemaValues)(heartwood_view_controllers_1.calendarEventSchema, event, {
522
517
  shouldIncludeNullAndUndefinedFields: false,
523
518
  });
@@ -544,11 +539,9 @@ class CalendarEventManager {
544
539
  return { pass: true, dateToUpdate, shouldUpdateAllEventsGoingForward };
545
540
  }
546
541
  }
542
+ CalendarEventManager.shouldBatchEvents = false;
547
543
  exports.default = CalendarEventManager;
548
544
  class UpdateOperation {
549
- id;
550
- updates;
551
- onComplete;
552
545
  constructor(options) {
553
546
  const { id, updates, onComplete } = options;
554
547
  this.id = id;
@@ -9,25 +9,18 @@ const schema_1 = require("@sprucelabs/schema");
9
9
  const spruce_core_schemas_1 = require("@sprucelabs/spruce-core-schemas");
10
10
  const SpruceError_1 = __importDefault(require("../errors/SpruceError"));
11
11
  class CalendarPeopleManager extends mercury_event_emitter_1.AbstractEventEmitter {
12
- connectToApi;
13
- prefs;
14
- client;
15
- loggedInPerson;
16
- locationId;
17
- organizationId;
18
- team = [];
19
- getVisibleEvents;
20
12
  constructor(options) {
21
13
  super(peopleContract);
14
+ this.team = [];
22
15
  const { connectToApi, preferences, getVisibleEvents } = (0, schema_1.assertOptions)(options, ['connectToApi', 'preferences', 'calendarVc', 'getVisibleEvents']);
23
16
  this.connectToApi = connectToApi;
24
17
  this.prefs = preferences;
25
18
  this.getVisibleEvents = getVisibleEvents;
26
19
  }
27
20
  async load(options) {
28
- const { loggedInPerson, organizationId, locationId } = options ?? {};
21
+ const { loggedInPerson, organizationId, locationId } = options !== null && options !== void 0 ? options : {};
29
22
  this.client = await this.connectToApi();
30
- this.loggedInPerson = loggedInPerson ?? undefined;
23
+ this.loggedInPerson = loggedInPerson !== null && loggedInPerson !== void 0 ? loggedInPerson : undefined;
31
24
  this.organizationId = organizationId;
32
25
  this.locationId = locationId;
33
26
  await this.loadTeam();
@@ -60,7 +53,8 @@ class CalendarPeopleManager extends mercury_event_emitter_1.AbstractEventEmitter
60
53
  return people;
61
54
  }
62
55
  teammateById(id) {
63
- const teammate = this.team?.find((t) => t.id === id);
56
+ var _a;
57
+ const teammate = (_a = this.team) === null || _a === void 0 ? void 0 : _a.find((t) => t.id === id);
64
58
  if (!teammate) {
65
59
  throw new SpruceError_1.default({
66
60
  code: 'PERSON_NOT_FOUND',
@@ -76,16 +70,18 @@ class CalendarPeopleManager extends mercury_event_emitter_1.AbstractEventEmitter
76
70
  return this.loggedInPerson;
77
71
  }
78
72
  getVisiblePeopleIds() {
73
+ var _a;
79
74
  if (this.getVisibilityMode() === 'working') {
80
75
  return this.getWorkingPeopleIds();
81
76
  }
82
- return this.getSavedVisiblePeopleIds() ?? [];
77
+ return (_a = this.getSavedVisiblePeopleIds()) !== null && _a !== void 0 ? _a : [];
83
78
  }
84
79
  getSavedVisiblePeopleIds() {
85
80
  return this.prefs.getVisiblePeopleIds();
86
81
  }
87
82
  getVisibilityMode() {
88
- return this.prefs.getVisiblePeopleMode() ?? 'me';
83
+ var _a;
84
+ return (_a = this.prefs.getVisiblePeopleMode()) !== null && _a !== void 0 ? _a : 'me';
89
85
  }
90
86
  async setVisibilityMode(mode) {
91
87
  if (this.getVisibilityMode() === mode) {
@@ -128,9 +124,10 @@ class CalendarPeopleManager extends mercury_event_emitter_1.AbstractEventEmitter
128
124
  .filter((p) => !!p);
129
125
  }
130
126
  async setVisiblePeopleIds(visible, options) {
131
- const { shouldForceEmitDidChange } = options ?? {};
127
+ var _a;
128
+ const { shouldForceEmitDidChange } = options !== null && options !== void 0 ? options : {};
132
129
  const newVisibile = visible.filter((id, idx) => visible.indexOf(id) === idx);
133
- const oldVisible = this.getSavedVisiblePeopleIds() ?? [];
130
+ const oldVisible = (_a = this.getSavedVisiblePeopleIds()) !== null && _a !== void 0 ? _a : [];
134
131
  const newKey = newVisibile.join('');
135
132
  const oldKey = oldVisible.join('');
136
133
  const didChange = newKey !== oldKey;
@@ -1,21 +1,16 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  class CalendarPersister {
4
- static Class;
5
- activelyPersisting = {};
6
- persistPromise;
7
- events;
8
- lastSwappedId;
9
- calendarVc;
10
- eventSwappedHandler;
11
4
  constructor(options) {
5
+ this.activelyPersisting = {};
12
6
  const { events, calendarVc, onEventSwapped } = options;
13
7
  this.events = events;
14
8
  this.calendarVc = calendarVc;
15
9
  this.eventSwappedHandler = onEventSwapped;
16
10
  }
17
11
  static Persister(options) {
18
- return new (this.Class ?? CalendarPersister)(options);
12
+ var _a;
13
+ return new ((_a = this.Class) !== null && _a !== void 0 ? _a : CalendarPersister)(options);
19
14
  }
20
15
  async persist(event) {
21
16
  this.persistPromise = this._persist(event);
@@ -31,6 +26,7 @@ class CalendarPersister {
31
26
  return this.events;
32
27
  }
33
28
  async _persist(event) {
29
+ var _a, _b;
34
30
  let updated = event;
35
31
  const id = updated.id;
36
32
  try {
@@ -44,9 +40,9 @@ class CalendarPersister {
44
40
  isBusy: true,
45
41
  shouldPersist: false,
46
42
  });
47
- const saved = await this.events?.persist({
43
+ const saved = await ((_a = this.events) === null || _a === void 0 ? void 0 : _a.persist({
48
44
  ...event,
49
- });
45
+ }));
50
46
  this.activelyPersisting[id]--;
51
47
  if (!saved) {
52
48
  return undefined;
@@ -60,7 +56,7 @@ class CalendarPersister {
60
56
  await this.calendarVc.swapEvent(event, saved);
61
57
  }
62
58
  if (this.activelyPersisting[id] === 0) {
63
- await this.eventSwappedHandler?.(event, saved);
59
+ await ((_b = this.eventSwappedHandler) === null || _b === void 0 ? void 0 : _b.call(this, event, saved));
64
60
  }
65
61
  }
66
62
  else {
@@ -84,7 +80,8 @@ class CalendarPersister {
84
80
  return event;
85
81
  }
86
82
  async cancelEvent(id, options) {
87
- await this.events?.cancelEvent(id, options);
83
+ var _a;
84
+ await ((_a = this.events) === null || _a === void 0 ? void 0 : _a.cancelEvent(id, options));
88
85
  }
89
86
  }
90
87
  exports.default = CalendarPersister;
@@ -1,8 +1,9 @@
1
1
  "use strict";
2
+ var _a;
2
3
  Object.defineProperty(exports, "__esModule", { value: true });
3
4
  exports.UPDATE_STRATEGY_ALL = exports.UPDATE_STRATEGY_THIS_AND_ALL_GOING_FORWARD = exports.UPDATE_STRATEGY_SPECIFIC_DATES = exports.MAX_GET_SCHEDULE_DAYS = void 0;
4
5
  require('dotenv').config();
5
- exports.MAX_GET_SCHEDULE_DAYS = parseInt(process.env.MAX_GETSCHEDULE_DAYS ?? '365');
6
+ exports.MAX_GET_SCHEDULE_DAYS = parseInt((_a = process.env.MAX_GETSCHEDULE_DAYS) !== null && _a !== void 0 ? _a : '365');
6
7
  exports.UPDATE_STRATEGY_SPECIFIC_DATES = 'only-this-one';
7
8
  exports.UPDATE_STRATEGY_THIS_AND_ALL_GOING_FORWARD = 'all-going-forward';
8
9
  exports.UPDATE_STRATEGY_ALL = 'all';