@servicetitan/notifications 31.2.0 → 32.0.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.
Files changed (75) hide show
  1. package/dist/api/notifications.api.js +4 -3
  2. package/dist/api/notifications.api.js.map +1 -1
  3. package/dist/common.js +4 -3
  4. package/dist/common.js.map +1 -1
  5. package/dist/components/notifications.js +42 -22
  6. package/dist/components/notifications.js.map +1 -1
  7. package/dist/demo/action-button-preview.js +41 -23
  8. package/dist/demo/action-button-preview.js.map +1 -1
  9. package/dist/demo/action-button.js +4 -1
  10. package/dist/demo/action-button.js.map +1 -1
  11. package/dist/demo/basic-preview.js +9 -5
  12. package/dist/demo/basic-preview.js.map +1 -1
  13. package/dist/demo/basic.js +4 -1
  14. package/dist/demo/basic.js.map +1 -1
  15. package/dist/demo/container.js +44 -45
  16. package/dist/demo/container.js.map +1 -1
  17. package/dist/demo/duration-preview.js +23 -9
  18. package/dist/demo/duration-preview.js.map +1 -1
  19. package/dist/demo/duration.js +4 -1
  20. package/dist/demo/duration.js.map +1 -1
  21. package/dist/demo/index.js +1 -0
  22. package/dist/demo/index.js.map +1 -1
  23. package/dist/demo/multiline-message-preview.js +9 -5
  24. package/dist/demo/multiline-message-preview.js.map +1 -1
  25. package/dist/demo/multiline-message.js +4 -1
  26. package/dist/demo/multiline-message.js.map +1 -1
  27. package/dist/demo/prevent-duplicates-preview.js +9 -5
  28. package/dist/demo/prevent-duplicates-preview.js.map +1 -1
  29. package/dist/demo/prevent-duplicates.js +4 -1
  30. package/dist/demo/prevent-duplicates.js.map +1 -1
  31. package/dist/demo/progress-preview.js +9 -5
  32. package/dist/demo/progress-preview.js.map +1 -1
  33. package/dist/demo/progress.js +4 -1
  34. package/dist/demo/progress.js.map +1 -1
  35. package/dist/demo/server-custom-preview.js +5 -4
  36. package/dist/demo/server-custom-preview.js.map +1 -1
  37. package/dist/demo/server-custom.js +13 -7
  38. package/dist/demo/server-custom.js.map +1 -1
  39. package/dist/demo/server-default.js +66 -61
  40. package/dist/demo/server-default.js.map +1 -1
  41. package/dist/demo/status-variations-preview.js +35 -13
  42. package/dist/demo/status-variations-preview.js.map +1 -1
  43. package/dist/demo/status-variations.js +4 -1
  44. package/dist/demo/status-variations.js.map +1 -1
  45. package/dist/index.js +7 -6
  46. package/dist/index.js.map +1 -1
  47. package/dist/intercept.js +1 -0
  48. package/dist/intercept.js.map +1 -1
  49. package/dist/notifications-channel.js +1 -0
  50. package/dist/notifications-channel.js.map +1 -1
  51. package/dist/notifications-service.js +71 -69
  52. package/dist/notifications-service.js.map +1 -1
  53. package/dist/stores/notifications.store.js +210 -218
  54. package/dist/stores/notifications.store.js.map +1 -1
  55. package/dist/utils/date-from-string.js +2 -1
  56. package/dist/utils/date-from-string.js.map +1 -1
  57. package/dist/utils/use-compatible-navigate.js +4 -3
  58. package/dist/utils/use-compatible-navigate.js.map +1 -1
  59. package/package.json +8 -8
  60. package/dist/__tests__/intercept.test.js +0 -13
  61. package/dist/__tests__/intercept.test.js.map +0 -1
  62. package/dist/__tests__/notifications-service.test.js +0 -42
  63. package/dist/__tests__/notifications-service.test.js.map +0 -1
  64. package/dist/components/__tests__/notifications.test.js +0 -93
  65. package/dist/components/__tests__/notifications.test.js.map +0 -1
  66. package/dist/notifications.stories.js +0 -20
  67. package/dist/notifications.stories.js.map +0 -1
  68. package/dist/stores/__mocks__/mock-notifications-channel.js +0 -36
  69. package/dist/stores/__mocks__/mock-notifications-channel.js.map +0 -1
  70. package/dist/stores/__tests__/notifications.store.test.js +0 -367
  71. package/dist/stores/__tests__/notifications.store.test.js.map +0 -1
  72. package/dist/utils/__tests__/date-from-string.test.js +0 -45
  73. package/dist/utils/__tests__/date-from-string.test.js.map +0 -1
  74. package/dist/utils/__tests__/use-compatible-navigate.test.js +0 -27
  75. package/dist/utils/__tests__/use-compatible-navigate.test.js.map +0 -1
@@ -1,199 +1,102 @@
1
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
1
+ function _check_private_redeclaration(obj, privateCollection) {
2
+ if (privateCollection.has(obj)) {
3
+ throw new TypeError("Cannot initialize the same private elements twice on an object");
4
+ }
5
+ }
6
+ function _class_apply_descriptor_get(receiver, descriptor) {
7
+ if (descriptor.get) {
8
+ return descriptor.get.call(receiver);
9
+ }
10
+ return descriptor.value;
11
+ }
12
+ function _class_apply_descriptor_set(receiver, descriptor, value) {
13
+ if (descriptor.set) {
14
+ descriptor.set.call(receiver, value);
15
+ } else {
16
+ if (!descriptor.writable) {
17
+ throw new TypeError("attempted to set read only private field");
18
+ }
19
+ descriptor.value = value;
20
+ }
21
+ }
22
+ function _class_extract_field_descriptor(receiver, privateMap, action) {
23
+ if (!privateMap.has(receiver)) {
24
+ throw new TypeError("attempted to " + action + " private field on non-instance");
25
+ }
26
+ return privateMap.get(receiver);
27
+ }
28
+ function _class_private_field_get(receiver, privateMap) {
29
+ var descriptor = _class_extract_field_descriptor(receiver, privateMap, "get");
30
+ return _class_apply_descriptor_get(receiver, descriptor);
31
+ }
32
+ function _class_private_field_init(obj, privateMap, value) {
33
+ _check_private_redeclaration(obj, privateMap);
34
+ privateMap.set(obj, value);
35
+ }
36
+ function _class_private_field_set(receiver, privateMap, value) {
37
+ var descriptor = _class_extract_field_descriptor(receiver, privateMap, "set");
38
+ _class_apply_descriptor_set(receiver, descriptor, value);
39
+ return value;
40
+ }
41
+ function _define_property(obj, key, value) {
42
+ if (key in obj) {
43
+ Object.defineProperty(obj, key, {
44
+ value: value,
45
+ enumerable: true,
46
+ configurable: true,
47
+ writable: true
48
+ });
49
+ } else {
50
+ obj[key] = value;
51
+ }
52
+ return obj;
53
+ }
54
+ function _ts_decorate(decorators, target, key, desc) {
2
55
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
56
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
57
+ else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
58
  return c > 3 && r && Object.defineProperty(target, key, r), r;
6
- };
7
- var __metadata = (this && this.__metadata) || function (k, v) {
59
+ }
60
+ function _ts_metadata(k, v) {
8
61
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
- };
10
- var __param = (this && this.__param) || function (paramIndex, decorator) {
11
- return function (target, key) { decorator(target, key, paramIndex); }
12
- };
13
- var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
14
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
15
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
16
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
17
- };
18
- var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
19
- if (kind === "m") throw new TypeError("Private method is not writable");
20
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
21
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
22
- return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
23
- };
24
- var _NotificationsStore_navigate;
25
- var NotificationsStore_1;
62
+ }
63
+ function _ts_param(paramIndex, decorator) {
64
+ return function(target, key) {
65
+ decorator(target, key, paramIndex);
66
+ };
67
+ }
26
68
  import { toast } from '@servicetitan/anvil2';
27
69
  import { injectable, inject, optional } from '@servicetitan/react-ioc';
28
70
  import { action, runInAction, comparer, makeObservable } from 'mobx';
29
- import { NotificationsApi, NotificationProcessStatus as ServerNotificationStatus, } from '../api/notifications.api';
71
+ import { NotificationsApi, NotificationProcessStatus as ServerNotificationStatus } from '../api/notifications.api';
30
72
  import { Status, isLinkAction, isNewer } from '../common';
31
- import { NOTIFICATIONS_CHANNEL_TOKEN } from '../notifications-channel';
73
+ import { NotificationsChannel, NOTIFICATIONS_CHANNEL_TOKEN } from '../notifications-channel';
32
74
  import { dateFromString } from '../utils/date-from-string';
33
75
  const EVENT_NAME = 'NotificationEvent';
34
76
  const CLIENT_NOTIFICATION_TYPE = 'ClientNotification';
35
77
  const CLIENT_NOTIFICATION_VERSION = 1;
36
78
  const DAY_INTERVAL = 24 * 60 * 60 * 1000;
37
- let NotificationsStore = NotificationsStore_1 = class NotificationsStore {
38
- constructor(notificationsApi, notificationsChannel) {
39
- Object.defineProperty(this, "notificationsApi", {
40
- enumerable: true,
41
- configurable: true,
42
- writable: true,
43
- value: notificationsApi
44
- });
45
- Object.defineProperty(this, "notificationsChannel", {
46
- enumerable: true,
47
- configurable: true,
48
- writable: true,
49
- value: notificationsChannel
50
- });
51
- Object.defineProperty(this, "index", {
52
- enumerable: true,
53
- configurable: true,
54
- writable: true,
55
- value: -1
56
- });
57
- Object.defineProperty(this, "userId", {
58
- enumerable: true,
59
- configurable: true,
60
- writable: true,
61
- value: 0
62
- });
63
- Object.defineProperty(this, "intervalId", {
64
- enumerable: true,
65
- configurable: true,
66
- writable: true,
67
- value: void 0
68
- });
69
- Object.defineProperty(this, "notifications", {
70
- enumerable: true,
71
- configurable: true,
72
- writable: true,
73
- value: new Map()
74
- });
75
- Object.defineProperty(this, "closedNotifications", {
76
- enumerable: true,
77
- configurable: true,
78
- writable: true,
79
- value: new Map()
80
- });
81
- _NotificationsStore_navigate.set(this, void 0);
82
- Object.defineProperty(this, "initialize", {
83
- enumerable: true,
84
- configurable: true,
85
- writable: true,
86
- value: async (userId) => {
87
- this.userId = userId;
88
- if (this.publisher) {
89
- this.publisher.bind(EVENT_NAME, this.onPublisherEvent);
90
- }
91
- this.intervalId = window.setInterval(() => this.cleanupClosedNotifications(), DAY_INTERVAL);
92
- if (!this.notificationsApi) {
93
- return;
94
- }
95
- const notifications = (await this.notificationsApi.getNotifications(false)).data;
96
- runInAction(() => {
97
- for (const notification of notifications) {
98
- this.updateIfNewer(notification);
99
- }
100
- });
101
- }
102
- });
103
- Object.defineProperty(this, "dispose", {
104
- enumerable: true,
105
- configurable: true,
106
- writable: true,
107
- value: () => {
108
- if (this.publisher) {
109
- this.publisher.global_emitter.unbind(EVENT_NAME, this.onPublisherEvent);
110
- }
111
- window.clearInterval(this.intervalId);
112
- }
113
- });
114
- Object.defineProperty(this, "add", {
115
- enumerable: true,
116
- configurable: true,
117
- writable: true,
118
- value: (options, preventDuplicates) => {
119
- const notification = {
120
- id: this.index,
121
- userId: this.userId,
122
- type: CLIENT_NOTIFICATION_TYPE,
123
- status: ServerNotificationStatus.Info,
124
- isRead: false,
125
- createdOn: new Date(),
126
- modifiedOn: new Date(),
127
- version: CLIENT_NOTIFICATION_VERSION,
128
- payload: { ...options },
129
- };
130
- if (preventDuplicates) {
131
- if ([...this.notifications.values()].some(({ payload }) => comparer.structural(payload, notification.payload))) {
132
- return;
133
- }
134
- this.notifications.set(notification.id, notification);
135
- }
136
- const method = this.getToastMethod(notification);
137
- notification.toastId = toast[method](this.getToastProps(notification));
138
- this.index -= 1;
139
- }
140
- });
141
- Object.defineProperty(this, "read", {
142
- enumerable: true,
143
- configurable: true,
144
- writable: true,
145
- value: (notification) => {
146
- if (notification.id > 0) {
147
- if (notification.status === ServerNotificationStatus.InProgress) {
148
- this.closedNotifications.set(notification.id, {
149
- status: notification.status,
150
- timestamp: Date.now(),
151
- });
152
- }
153
- if (this.notificationsApi) {
154
- this.notificationsApi.changeIsReadProperty(notification.id, true, notification.version);
155
- }
156
- }
157
- this.notifications.delete(notification.id);
158
- }
159
- });
160
- Object.defineProperty(this, "onPublisherEvent", {
161
- enumerable: true,
162
- configurable: true,
163
- writable: true,
164
- value: (notification) => {
165
- if (notification.userId !== this.userId) {
166
- return;
167
- }
168
- this.updateIfNewer({
169
- ...notification,
170
- createdOn: dateFromString(notification.createdOn),
171
- modifiedOn: dateFromString(notification.modifiedOn),
172
- });
173
- }
174
- });
175
- makeObservable(this);
176
- }
79
+ var _navigate = /*#__PURE__*/ new WeakMap();
80
+ export class NotificationsStore {
177
81
  static intercept(type, fn) {
178
82
  if (fn) {
179
- NotificationsStore_1.interceptors.set(type, fn);
180
- }
181
- else {
182
- NotificationsStore_1.interceptors.delete(type);
83
+ NotificationsStore.interceptors.set(type, fn);
84
+ } else {
85
+ NotificationsStore.interceptors.delete(type);
183
86
  }
184
87
  }
185
88
  get publisher() {
186
- var _a;
187
- return (_a = this.notificationsChannel) === null || _a === void 0 ? void 0 : _a.call(this);
89
+ var _this_notificationsChannel, _this;
90
+ return (_this_notificationsChannel = (_this = this).notificationsChannel) === null || _this_notificationsChannel === void 0 ? void 0 : _this_notificationsChannel.call(_this);
188
91
  }
189
92
  get navigate() {
190
- return __classPrivateFieldGet(this, _NotificationsStore_navigate, "f");
93
+ return _class_private_field_get(this, _navigate);
191
94
  }
192
95
  set navigate(fn) {
193
- __classPrivateFieldSet(this, _NotificationsStore_navigate, fn, "f");
96
+ _class_private_field_set(this, _navigate, fn);
194
97
  }
195
98
  cleanupClosedNotifications() {
196
- for (const [id, { timestamp }] of Array.from(this.closedNotifications)) {
99
+ for (const [id, { timestamp }] of Array.from(this.closedNotifications)){
197
100
  if (Date.now() - timestamp > DAY_INTERVAL) {
198
101
  this.closedNotifications.delete(id);
199
102
  }
@@ -216,8 +119,7 @@ let NotificationsStore = NotificationsStore_1 = class NotificationsStore {
216
119
  if (!isNewer(existing, notification)) {
217
120
  return;
218
121
  }
219
- if (notification.status === existing.status ||
220
- notification.status === ServerNotificationStatus.InProgress) {
122
+ if (notification.status === existing.status || notification.status === ServerNotificationStatus.InProgress) {
221
123
  toast.update(existing.toastId, this.getToastProps(clientNotification));
222
124
  clientNotification.toastId = existing.toastId;
223
125
  this.notifications.set(notification.id, clientNotification);
@@ -230,7 +132,7 @@ let NotificationsStore = NotificationsStore_1 = class NotificationsStore {
230
132
  this.notifications.set(notification.id, clientNotification);
231
133
  }
232
134
  getToastMethod({ payload: { status } }) {
233
- switch (status) {
135
+ switch(status){
234
136
  case Status.Success:
235
137
  return 'success';
236
138
  case Status.Error:
@@ -247,9 +149,9 @@ let NotificationsStore = NotificationsStore_1 = class NotificationsStore {
247
149
  actions: this.getToastActions(notification),
248
150
  duration: action ? false : duration,
249
151
  message,
250
- onClose: () => this.handleClose(notification),
152
+ onClose: ()=>this.handleClose(notification),
251
153
  progress,
252
- title,
154
+ title
253
155
  };
254
156
  }
255
157
  getToastActions(notification) {
@@ -260,22 +162,20 @@ let NotificationsStore = NotificationsStore_1 = class NotificationsStore {
260
162
  return {
261
163
  primary: {
262
164
  label: action.label,
263
- onClick: () => this.handleClick(notification),
264
- },
165
+ onClick: ()=>this.handleClick(notification)
166
+ }
265
167
  };
266
168
  }
267
169
  handleClick({ payload: { action }, toastId }) {
268
- var _a;
269
170
  if (action) {
270
171
  if (isLinkAction(action)) {
271
172
  if (action.external) {
272
173
  window.open(action.link);
174
+ } else {
175
+ var _this_navigate, _this;
176
+ (_this_navigate = (_this = this).navigate) === null || _this_navigate === void 0 ? void 0 : _this_navigate.call(_this, action.link);
273
177
  }
274
- else {
275
- (_a = this.navigate) === null || _a === void 0 ? void 0 : _a.call(this, action.link);
276
- }
277
- }
278
- else {
178
+ } else {
279
179
  action.onClick();
280
180
  }
281
181
  }
@@ -285,21 +185,21 @@ let NotificationsStore = NotificationsStore_1 = class NotificationsStore {
285
185
  this.read(notification);
286
186
  }
287
187
  toClientNotification(serverNotification) {
288
- var _a;
188
+ var _serverNotification_payload;
289
189
  const result = {
290
190
  ...serverNotification,
291
191
  payload: {
292
- ...JSON.parse((_a = serverNotification.payload) !== null && _a !== void 0 ? _a : '{}'),
293
- status: this.toClientStatus(serverNotification.status),
294
- },
192
+ ...JSON.parse((_serverNotification_payload = serverNotification.payload) !== null && _serverNotification_payload !== void 0 ? _serverNotification_payload : '{}'),
193
+ status: this.toClientStatus(serverNotification.status)
194
+ }
295
195
  };
296
- const interceptor = NotificationsStore_1.interceptors.get(serverNotification.type);
196
+ const interceptor = NotificationsStore.interceptors.get(serverNotification.type);
297
197
  if (!interceptor) {
298
198
  return result;
299
199
  }
300
- const dismiss = () => {
301
- var _a;
302
- const toastId = (_a = this.notifications.get(result.id)) === null || _a === void 0 ? void 0 : _a.toastId;
200
+ const dismiss = ()=>{
201
+ var _this_notifications_get;
202
+ const toastId = (_this_notifications_get = this.notifications.get(result.id)) === null || _this_notifications_get === void 0 ? void 0 : _this_notifications_get.toastId;
303
203
  if (toastId) {
304
204
  toast.dismiss(toastId);
305
205
  }
@@ -307,7 +207,7 @@ let NotificationsStore = NotificationsStore_1 = class NotificationsStore {
307
207
  return interceptor(result, dismiss);
308
208
  }
309
209
  toClientStatus(status) {
310
- switch (status) {
210
+ switch(status){
311
211
  case ServerNotificationStatus.Success:
312
212
  return Status.Success;
313
213
  case ServerNotificationStatus.Failure:
@@ -316,33 +216,125 @@ let NotificationsStore = NotificationsStore_1 = class NotificationsStore {
316
216
  return Status.Info;
317
217
  }
318
218
  }
319
- };
320
- _NotificationsStore_navigate = new WeakMap();
321
- Object.defineProperty(NotificationsStore, "interceptors", {
322
- enumerable: true,
323
- configurable: true,
324
- writable: true,
325
- value: new Map()
326
- });
327
- __decorate([
328
- action,
329
- __metadata("design:type", Object)
219
+ constructor(notificationsApi, notificationsChannel){
220
+ _define_property(this, "notificationsApi", void 0);
221
+ _define_property(this, "notificationsChannel", void 0);
222
+ _define_property(this, "index", void 0);
223
+ _define_property(this, "userId", void 0);
224
+ _define_property(this, "intervalId", void 0);
225
+ _define_property(this, "notifications", void 0);
226
+ _define_property(this, "closedNotifications", void 0);
227
+ _class_private_field_init(this, _navigate, {
228
+ writable: true,
229
+ value: void 0
230
+ });
231
+ _define_property(this, "initialize", void 0);
232
+ _define_property(this, "dispose", void 0);
233
+ _define_property(this, "add", void 0);
234
+ _define_property(this, "read", void 0);
235
+ _define_property(this, "onPublisherEvent", void 0);
236
+ this.notificationsApi = notificationsApi;
237
+ this.notificationsChannel = notificationsChannel;
238
+ this.index = -1;
239
+ this.userId = 0;
240
+ this.notifications = new Map();
241
+ this.closedNotifications = new Map();
242
+ this.initialize = async (userId)=>{
243
+ this.userId = userId;
244
+ if (this.publisher) {
245
+ this.publisher.bind(EVENT_NAME, this.onPublisherEvent);
246
+ }
247
+ this.intervalId = window.setInterval(()=>this.cleanupClosedNotifications(), DAY_INTERVAL);
248
+ if (!this.notificationsApi) {
249
+ return;
250
+ }
251
+ const notifications = (await this.notificationsApi.getNotifications(false)).data;
252
+ runInAction(()=>{
253
+ for (const notification of notifications){
254
+ this.updateIfNewer(notification);
255
+ }
256
+ });
257
+ };
258
+ this.dispose = ()=>{
259
+ if (this.publisher) {
260
+ this.publisher.global_emitter.unbind(EVENT_NAME, this.onPublisherEvent);
261
+ }
262
+ window.clearInterval(this.intervalId);
263
+ };
264
+ this.add = (options, preventDuplicates)=>{
265
+ const notification = {
266
+ id: this.index,
267
+ userId: this.userId,
268
+ type: CLIENT_NOTIFICATION_TYPE,
269
+ status: ServerNotificationStatus.Info,
270
+ isRead: false,
271
+ createdOn: new Date(),
272
+ modifiedOn: new Date(),
273
+ version: CLIENT_NOTIFICATION_VERSION,
274
+ payload: {
275
+ ...options
276
+ }
277
+ };
278
+ if (preventDuplicates) {
279
+ if ([
280
+ ...this.notifications.values()
281
+ ].some(({ payload })=>comparer.structural(payload, notification.payload))) {
282
+ return;
283
+ }
284
+ this.notifications.set(notification.id, notification);
285
+ }
286
+ const method = this.getToastMethod(notification);
287
+ notification.toastId = toast[method](this.getToastProps(notification));
288
+ this.index -= 1;
289
+ };
290
+ this.read = (notification)=>{
291
+ if (notification.id > 0) {
292
+ if (notification.status === ServerNotificationStatus.InProgress) {
293
+ this.closedNotifications.set(notification.id, {
294
+ status: notification.status,
295
+ timestamp: Date.now()
296
+ });
297
+ }
298
+ if (this.notificationsApi) {
299
+ this.notificationsApi.changeIsReadProperty(notification.id, true, notification.version);
300
+ }
301
+ }
302
+ this.notifications.delete(notification.id);
303
+ };
304
+ this.onPublisherEvent = (notification)=>{
305
+ if (notification.userId !== this.userId) {
306
+ return;
307
+ }
308
+ this.updateIfNewer({
309
+ ...notification,
310
+ createdOn: dateFromString(notification.createdOn),
311
+ modifiedOn: dateFromString(notification.modifiedOn)
312
+ });
313
+ };
314
+ makeObservable(this);
315
+ }
316
+ }
317
+ _define_property(NotificationsStore, "interceptors", new Map());
318
+ _ts_decorate([
319
+ action
330
320
  ], NotificationsStore.prototype, "add", void 0);
331
- __decorate([
332
- action,
333
- __metadata("design:type", Object)
321
+ _ts_decorate([
322
+ action
334
323
  ], NotificationsStore.prototype, "read", void 0);
335
- __decorate([
336
- action,
337
- __metadata("design:type", Object)
324
+ _ts_decorate([
325
+ action
338
326
  ], NotificationsStore.prototype, "onPublisherEvent", void 0);
339
- NotificationsStore = NotificationsStore_1 = __decorate([
327
+ NotificationsStore = _ts_decorate([
340
328
  injectable(),
341
- __param(0, inject(NotificationsApi)),
342
- __param(0, optional()),
343
- __param(1, inject(NOTIFICATIONS_CHANNEL_TOKEN)),
344
- __param(1, optional()),
345
- __metadata("design:paramtypes", [NotificationsApi, Function])
329
+ _ts_param(0, inject(NotificationsApi)),
330
+ _ts_param(0, optional()),
331
+ _ts_param(1, inject(NOTIFICATIONS_CHANNEL_TOKEN)),
332
+ _ts_param(1, optional()),
333
+ _ts_metadata("design:type", Function),
334
+ _ts_metadata("design:paramtypes", [
335
+ typeof NotificationsApi === "undefined" ? Object : NotificationsApi,
336
+ typeof NotificationsChannel === "undefined" ? Object : NotificationsChannel
337
+ ])
346
338
  ], NotificationsStore);
347
- export { NotificationsStore };
339
+
348
340
  //# sourceMappingURL=notifications.store.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"notifications.store.js","sourceRoot":"","sources":["../../src/stores/notifications.store.ts"],"names":[],"mappings":";;;;;;;;;;;;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MAAM,EAAE,OAAO,CAAC,CAAC;IACxC,CAAC;IAEO,cAAc,CAAC,MAAgC;QACnD,QAAQ,MAAM,EAAE,CAAC;YACb,KAAK,wBAAwB,CAAC,OAAO;gBACjC,OAAO,MAAM,CAAC,OAAO,CAAC;YAC1B,KAAK,wBAAwB,CAAC,OAAO;gBACjC,OAAO,MAAM,CAAC,KAAK,CAAC;YACxB;gBACI,OAAO,MAAM,CAAC,IAAI,CAAC;QAC3B,CAAC;IACL,CAAC;;;AAlRe;;;;WAAe,IAAI,GAAG,EAAmC;EAA7C,CAA8C;AAuE1E;IADC,MAAM;;+CA4BL;AAGF;IADC,MAAM;;gDAoBL;AAGe;IADhB,MAAM;;4DAWL;AAtIO,kBAAkB;IAD9B,UAAU,EAAE;IAcJ,WAAA,MAAM,CAAC,gBAAgB,CAAC,CAAA;IAAE,WAAA,QAAQ,EAAE,CAAA;IACpC,WAAA,MAAM,CAAC,2BAA2B,CAAC,CAAA;IACnC,WAAA,QAAQ,EAAE,CAAA;qCAF+D,gBAAgB;GAbrF,kBAAkB,CAoR9B"}
1
+ {"version":3,"sources":["../../src/stores/notifications.store.ts"],"sourcesContent":["import { toast, toastProps } from '@servicetitan/anvil2';\nimport { injectable, inject, optional } from '@servicetitan/react-ioc';\nimport { action, runInAction, comparer, makeObservable } from 'mobx';\n\nimport {\n DefaultServerNotificationPayload,\n NotificationsApi,\n Notification as ServerNotification,\n NotificationProcessStatus as ServerNotificationStatus,\n} from '../api/notifications.api';\nimport { DefaultNotificationOptions, Notification, Status, isLinkAction, isNewer } from '../common';\nimport { NotificationInterceptor } from '../intercept';\nimport { NotificationsChannel, NOTIFICATIONS_CHANNEL_TOKEN } from '../notifications-channel';\nimport { dateFromString } from '../utils/date-from-string';\n\nconst EVENT_NAME = 'NotificationEvent';\nconst CLIENT_NOTIFICATION_TYPE = 'ClientNotification';\nconst CLIENT_NOTIFICATION_VERSION = 1;\nconst DAY_INTERVAL = 24 * 60 * 60 * 1000;\n\ninterface ClosedNotification {\n status: ServerNotificationStatus;\n timestamp: number;\n}\n\ninterface ClientNotification extends Notification<DefaultNotificationOptions> {\n toastId?: string;\n}\n\ntype NavigateCallback = (path: string) => void;\n\ntype ToastMethod = 'info' | 'success' | 'warning' | 'danger';\n\n@injectable()\nexport class NotificationsStore {\n static readonly interceptors = new Map<string, NotificationInterceptor>();\n\n private index = -1;\n private userId = 0;\n private intervalId?: number;\n\n private readonly notifications = new Map<number, ClientNotification>();\n private readonly closedNotifications = new Map<number, ClosedNotification>();\n\n #navigate?: NavigateCallback;\n\n constructor(\n @inject(NotificationsApi) @optional() private readonly notificationsApi?: NotificationsApi,\n @inject(NOTIFICATIONS_CHANNEL_TOKEN)\n @optional()\n private readonly notificationsChannel?: NotificationsChannel\n ) {\n makeObservable(this);\n }\n\n static intercept(type: string, fn?: NotificationInterceptor) {\n if (fn) {\n NotificationsStore.interceptors.set(type, fn);\n } else {\n NotificationsStore.interceptors.delete(type);\n }\n }\n\n private get publisher() {\n return this.notificationsChannel?.();\n }\n\n get navigate(): NavigateCallback | undefined {\n return this.#navigate;\n }\n\n set navigate(fn: NavigateCallback) {\n this.#navigate = fn;\n }\n\n initialize = async (userId: number) => {\n this.userId = userId;\n\n if (this.publisher) {\n this.publisher.bind(EVENT_NAME, this.onPublisherEvent);\n }\n\n this.intervalId = window.setInterval(() => this.cleanupClosedNotifications(), DAY_INTERVAL);\n\n if (!this.notificationsApi) {\n return;\n }\n\n const notifications = (await this.notificationsApi.getNotifications(false)).data;\n\n runInAction(() => {\n for (const notification of notifications) {\n this.updateIfNewer(notification);\n }\n });\n };\n\n dispose = () => {\n if (this.publisher) {\n this.publisher.global_emitter.unbind(EVENT_NAME, this.onPublisherEvent);\n }\n\n window.clearInterval(this.intervalId);\n };\n\n @action\n add = (options: DefaultNotificationOptions, preventDuplicates?: boolean) => {\n const notification: ClientNotification = {\n id: this.index,\n userId: this.userId,\n type: CLIENT_NOTIFICATION_TYPE,\n status: ServerNotificationStatus.Info,\n isRead: false,\n createdOn: new Date(),\n modifiedOn: new Date(),\n version: CLIENT_NOTIFICATION_VERSION,\n payload: { ...options },\n };\n\n if (preventDuplicates) {\n if (\n [...this.notifications.values()].some(({ payload }) =>\n comparer.structural(payload, notification.payload)\n )\n ) {\n return;\n }\n this.notifications.set(notification.id, notification);\n }\n\n const method = this.getToastMethod(notification);\n notification.toastId = toast[method](this.getToastProps(notification));\n this.index -= 1;\n };\n\n @action\n read = (notification: Notification) => {\n if (notification.id > 0) {\n if (notification.status === ServerNotificationStatus.InProgress) {\n this.closedNotifications.set(notification.id, {\n status: notification.status,\n timestamp: Date.now(),\n });\n }\n\n if (this.notificationsApi) {\n this.notificationsApi.changeIsReadProperty(\n notification.id,\n true,\n notification.version\n );\n }\n }\n\n this.notifications.delete(notification.id);\n };\n\n @action\n private readonly onPublisherEvent = (notification: ServerNotification) => {\n if (notification.userId !== this.userId) {\n return;\n }\n\n this.updateIfNewer({\n ...notification,\n createdOn: dateFromString(notification.createdOn),\n modifiedOn: dateFromString(notification.modifiedOn),\n });\n };\n\n private cleanupClosedNotifications() {\n for (const [id, { timestamp }] of Array.from(this.closedNotifications)) {\n if (Date.now() - timestamp > DAY_INTERVAL) {\n this.closedNotifications.delete(id);\n }\n }\n }\n\n private updateIfNewer(notification: ServerNotification) {\n const closed = this.closedNotifications.get(notification.id);\n if (closed) {\n if (closed.status === notification.status) {\n return;\n }\n\n this.closedNotifications.delete(notification.id);\n }\n\n const clientNotification = this.toClientNotification(notification);\n if (!clientNotification) {\n return;\n }\n\n const existing = this.notifications.get(notification.id);\n if (existing) {\n if (!isNewer(existing, notification)) {\n return;\n }\n if (\n notification.status === existing.status ||\n notification.status === ServerNotificationStatus.InProgress\n ) {\n toast.update(existing.toastId!, this.getToastProps(clientNotification));\n clientNotification.toastId = existing.toastId;\n this.notifications.set(notification.id, clientNotification);\n return;\n }\n toast.dismiss(existing.toastId);\n }\n\n const method = this.getToastMethod(clientNotification);\n clientNotification.toastId = toast[method](this.getToastProps(clientNotification));\n this.notifications.set(notification.id, clientNotification);\n }\n\n private getToastMethod({ payload: { status } }: ClientNotification): ToastMethod {\n switch (status) {\n case Status.Success:\n return 'success';\n case Status.Error:\n return 'danger';\n case Status.Warning:\n return 'warning';\n default:\n return 'info';\n }\n }\n\n private getToastProps(notification: ClientNotification): toastProps {\n const { action, duration = 8000, message = '', progress, title } = notification.payload;\n return {\n actions: this.getToastActions(notification),\n duration: action ? false : duration,\n message,\n onClose: () => this.handleClose(notification),\n progress,\n title,\n };\n }\n\n private getToastActions(notification: ClientNotification): toastProps['actions'] | undefined {\n const { action } = notification.payload;\n if (!action) {\n return;\n }\n\n return {\n primary: {\n label: action.label,\n onClick: () => this.handleClick(notification),\n },\n };\n }\n\n private handleClick({ payload: { action }, toastId }: ClientNotification) {\n if (action) {\n if (isLinkAction(action)) {\n if (action.external) {\n window.open(action.link);\n } else {\n this.navigate?.(action.link);\n }\n } else {\n action.onClick();\n }\n }\n\n toast.dismiss(toastId);\n }\n\n private handleClose(notification: Notification) {\n this.read(notification);\n }\n\n private toClientNotification(\n serverNotification: ServerNotification\n ): ClientNotification | undefined {\n const result: Notification<DefaultServerNotificationPayload> = {\n ...serverNotification,\n payload: {\n ...JSON.parse(serverNotification.payload ?? '{}'),\n status: this.toClientStatus(serverNotification.status),\n },\n };\n\n const interceptor = NotificationsStore.interceptors.get(serverNotification.type);\n if (!interceptor) {\n return result;\n }\n\n const dismiss = () => {\n const toastId = this.notifications.get(result.id)?.toastId;\n if (toastId) {\n toast.dismiss(toastId);\n }\n };\n\n return interceptor(result, dismiss);\n }\n\n private toClientStatus(status: ServerNotificationStatus) {\n switch (status) {\n case ServerNotificationStatus.Success:\n return Status.Success;\n case ServerNotificationStatus.Failure:\n return Status.Error;\n default:\n return Status.Info;\n }\n }\n}\n"],"names":["toast","injectable","inject","optional","action","runInAction","comparer","makeObservable","NotificationsApi","NotificationProcessStatus","ServerNotificationStatus","Status","isLinkAction","isNewer","NotificationsChannel","NOTIFICATIONS_CHANNEL_TOKEN","dateFromString","EVENT_NAME","CLIENT_NOTIFICATION_TYPE","CLIENT_NOTIFICATION_VERSION","DAY_INTERVAL","NotificationsStore","intercept","type","fn","interceptors","set","delete","publisher","notificationsChannel","navigate","cleanupClosedNotifications","id","timestamp","Array","from","closedNotifications","Date","now","updateIfNewer","notification","closed","get","status","clientNotification","toClientNotification","existing","notifications","InProgress","update","toastId","getToastProps","dismiss","method","getToastMethod","payload","Success","Error","Warning","duration","message","progress","title","actions","getToastActions","onClose","handleClose","primary","label","onClick","handleClick","external","window","open","link","read","serverNotification","result","JSON","parse","toClientStatus","interceptor","Failure","Info","constructor","notificationsApi","index","userId","intervalId","initialize","dispose","add","onPublisherEvent","Map","bind","setInterval","getNotifications","data","global_emitter","unbind","clearInterval","options","preventDuplicates","isRead","createdOn","modifiedOn","version","values","some","structural","changeIsReadProperty"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,SAASA,KAAK,QAAoB,uBAAuB;AACzD,SAASC,UAAU,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,0BAA0B;AACvE,SAASC,MAAM,EAAEC,WAAW,EAAEC,QAAQ,EAAEC,cAAc,QAAQ,OAAO;AAErE,SAEIC,gBAAgB,EAEhBC,6BAA6BC,wBAAwB,QAClD,2BAA2B;AAClC,SAAmDC,MAAM,EAAEC,YAAY,EAAEC,OAAO,QAAQ,YAAY;AAEpG,SAASC,oBAAoB,EAAEC,2BAA2B,QAAQ,2BAA2B;AAC7F,SAASC,cAAc,QAAQ,4BAA4B;AAE3D,MAAMC,aAAa;AACnB,MAAMC,2BAA2B;AACjC,MAAMC,8BAA8B;AACpC,MAAMC,eAAe,KAAK,KAAK,KAAK;IA0BhC;AAVJ,OAAO,MAAMC;IAqBT,OAAOC,UAAUC,IAAY,EAAEC,EAA4B,EAAE;QACzD,IAAIA,IAAI;YACJH,mBAAmBI,YAAY,CAACC,G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,IAAI,CAAChD,aAAa,CAAC;gBACf,GAAGC,YAAY;gBACfgE,WAAWxF,eAAewB,aAAagE,SAAS;gBAChDC,YAAYzF,eAAewB,aAAaiE,UAAU;YACtD;QACJ;QApHIlG,eAAe,IAAI;IACvB;AAiQJ;AAnRI,iBADSc,oBACOI,gBAAe,IAAIoE"}
@@ -6,7 +6,7 @@ export function dateFromString(date) {
6
6
  }
7
7
  if (dateISO.test(date)) {
8
8
  // Truncate milliseconds because Date.UTC returns invalid results when milliseconds is >999
9
- const d = date.split(/\D+/).map((s, index) => (index === 6 ? +s.substring(0, 3) : +s));
9
+ const d = date.split(/\D+/).map((s, index)=>index === 6 ? +s.substring(0, 3) : +s);
10
10
  return new Date(Date.UTC(d[0], --d[1], d[2], d[3], d[4], d[5], d[6]));
11
11
  }
12
12
  if (dateNet.test(date)) {
@@ -17,4 +17,5 @@ export function dateFromString(date) {
17
17
  }
18
18
  throw new Error('Incorrect date format');
19
19
  }
20
+
20
21
  //# sourceMappingURL=date-from-string.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"date-from-string.js","sourceRoot":"","sources":["../../src/utils/date-from-string.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,GAAG,sDAAsD,CAAC;AACvE,MAAM,OAAO,GAAG,kCAAkC,CAAC;AAEnD,MAAM,UAAU,cAAc,CAAC,IAAmB;IAC9C,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE,CAAC;QAC3B,OAAO,IAAI,CAAC;IAChB,CAAC;IAED,IAAI,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;QACrB,2FAA2F;QAC3F,MAAM,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE,CAAC,CAAC,KAAK,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QACvF,OAAO,IAAI,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAC1E,CAAC;IAED,IAAI,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;QACrB,MAAM,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACtC,IAAI,UAAU,KAAK,IAAI,EAAE,CAAC;YACtB,OAAO,IAAI,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC;QACjD,CAAC;IACL,CAAC;IAED,MAAM,IAAI,KAAK,CAAC,uBAAuB,CAAC,CAAC;AAC7C,CAAC"}
1
+ {"version":3,"sources":["../../src/utils/date-from-string.ts"],"sourcesContent":["const dateISO = /^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(?:[.,]\\d+)?Z?$/i;\nconst dateNet = /\\/Date\\((-?\\d+)(?:[+-]\\d+)?\\)\\//i;\n\nexport function dateFromString(date: string | Date) {\n if (typeof date === 'object') {\n return date;\n }\n\n if (dateISO.test(date)) {\n // Truncate milliseconds because Date.UTC returns invalid results when milliseconds is >999\n const d = date.split(/\\D+/).map((s, index) => (index === 6 ? +s.substring(0, 3) : +s));\n return new Date(Date.UTC(d[0], --d[1], d[2], d[3], d[4], d[5], d[6]));\n }\n\n if (dateNet.test(date)) {\n const parsedDate = dateNet.exec(date);\n if (parsedDate !== null) {\n return new Date(parseInt(parsedDate[1], 10));\n }\n }\n\n throw new Error('Incorrect date format');\n}\n"],"names":["dateISO","dateNet","dateFromString","date","test","d","split","map","s","index","substring","Date","UTC","parsedDate","exec","parseInt","Error"],"mappings":"AAAA,MAAMA,UAAU;AAChB,MAAMC,UAAU;AAEhB,OAAO,SAASC,eAAeC,IAAmB;IAC9C,IAAI,OAAOA,SAAS,UAAU;QAC1B,OAAOA;IACX;IAEA,IAAIH,QAAQI,IAAI,CAACD,OAAO;QACpB,2FAA2F;QAC3F,MAAME,IAAIF,KAAKG,KAAK,CAAC,OAAOC,GAAG,CAAC,CAACC,GAAGC,QAAWA,UAAU,IAAI,CAACD,EAAEE,SAAS,CAAC,GAAG,KAAK,CAACF;QACnF,OAAO,IAAIG,KAAKA,KAAKC,GAAG,CAACP,CAAC,CAAC,EAAE,EAAE,EAAEA,CAAC,CAAC,EAAE,EAAEA,CAAC,CAAC,EAAE,EAAEA,CAAC,CAAC,EAAE,EAAEA,CAAC,CAAC,EAAE,EAAEA,CAAC,CAAC,EAAE,EAAEA,CAAC,CAAC,EAAE;IACvE;IAEA,IAAIJ,QAAQG,IAAI,CAACD,OAAO;QACpB,MAAMU,aAAaZ,QAAQa,IAAI,CAACX;QAChC,IAAIU,eAAe,MAAM;YACrB,OAAO,IAAIF,KAAKI,SAASF,UAAU,CAAC,EAAE,EAAE;QAC5C;IACJ;IAEA,MAAM,IAAIG,MAAM;AACpB"}
@@ -1,10 +1,11 @@
1
1
  import * as ReactRouterProperties from 'react-router-dom';
2
2
  // adds support to navigate with react-router-dom v6
3
- export const useCompatibleNavigate = () => {
4
- var _a;
3
+ export const useCompatibleNavigate = ()=>{
5
4
  const { useHistory, useNavigate } = ReactRouterProperties;
6
5
  const history = useHistory === null || useHistory === void 0 ? void 0 : useHistory();
7
6
  const navigate = useNavigate === null || useNavigate === void 0 ? void 0 : useNavigate();
8
- return (_a = history === null || history === void 0 ? void 0 : history.push) !== null && _a !== void 0 ? _a : navigate;
7
+ var _history_push;
8
+ return (_history_push = history === null || history === void 0 ? void 0 : history.push) !== null && _history_push !== void 0 ? _history_push : navigate;
9
9
  };
10
+
10
11
  //# sourceMappingURL=use-compatible-navigate.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"use-compatible-navigate.js","sourceRoot":"","sources":["../../src/utils/use-compatible-navigate.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,qBAAqB,MAAM,kBAAkB,CAAC;AAE1D,oDAAoD;AACpD,MAAM,CAAC,MAAM,qBAAqB,GAAG,GAAG,EAAE;;IACtC,MAAM,EAAE,UAAU,EAAE,WAAW,EAAE,GAAG,qBAEnC,CAAC;IAEF,MAAM,OAAO,GAAG,UAAU,aAAV,UAAU,uBAAV,UAAU,EAAI,CAAC;IAC/B,MAAM,QAAQ,GAAG,WAAW,aAAX,WAAW,uBAAX,WAAW,EAAI,CAAC;IAEjC,OAAO,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,IAAI,mCAAI,QAAQ,CAAC;AACrC,CAAC,CAAC"}
1
+ {"version":3,"sources":["../../src/utils/use-compatible-navigate.ts"],"sourcesContent":["import * as ReactRouterProperties from 'react-router-dom';\n\n// adds support to navigate with react-router-dom v6\nexport const useCompatibleNavigate = () => {\n const { useHistory, useNavigate } = ReactRouterProperties as typeof ReactRouterProperties & {\n useNavigate: Function;\n };\n\n const history = useHistory?.();\n const navigate = useNavigate?.();\n\n return history?.push ?? navigate;\n};\n"],"names":["ReactRouterProperties","useCompatibleNavigate","useHistory","useNavigate","history","navigate","push"],"mappings":"AAAA,YAAYA,2BAA2B,mBAAmB;AAE1D,oDAAoD;AACpD,OAAO,MAAMC,wBAAwB;IACjC,MAAM,EAAEC,UAAU,EAAEC,WAAW,EAAE,GAAGH;IAIpC,MAAMI,UAAUF,uBAAAA,iCAAAA;IAChB,MAAMG,WAAWF,wBAAAA,kCAAAA;QAEVC;IAAP,OAAOA,CAAAA,gBAAAA,oBAAAA,8BAAAA,QAASE,IAAI,cAAbF,2BAAAA,gBAAiBC;AAC5B,EAAE"}