@servicetitan/notifications 41.2.0 → 42.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.
- package/dist/demo/container.js +1 -3
- package/dist/demo/container.js.map +1 -1
- package/dist/demo/mock-notifications-api.js +1 -3
- package/dist/demo/mock-notifications-api.js.map +1 -1
- package/dist/notifications-service.js +14 -7
- package/dist/notifications-service.js.map +1 -1
- package/dist/stores/notifications.store.js +18 -16
- package/dist/stores/notifications.store.js.map +1 -1
- package/package.json +6 -6
package/dist/demo/container.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/demo/container.tsx"],"sourcesContent":["import type { FC } from 'react';\nimport { useEffect, useMemo } from 'react';\n\nimport { Provider, useDependencies } from '@servicetitan/react-ioc';\n\nimport type { Notification } from '../api/notifications.api';\nimport type { NotificationsProps } from '..';\nimport { NOTIFICATIONS_CHANNEL_TOKEN, Notifications, NotificationsService } from '..';\n\ntype EventCallback = (notification: Notification) => void;\n\nclass Publisher {\n // eslint-disable-next-line @typescript-eslint/naming-convention\n global_emitter = {\n bind: () => {},\n unbind: () => {},\n };\n\n private subscription?: EventCallback;\n\n bind = (_0: string, callback: EventCallback) => {\n this.subscription = callback;\n };\n\n unbind = () => {};\n\n fire = (notification: Notification) => {\n if (this.subscription) {\n this.subscription(notification);\n }\n };\n}\n\nconst NotificationsInitializer: FC = () => {\n const [notifications] = useDependencies(NotificationsService);\n\n useEffect(() => {\n notifications.initialize();\n }, [notifications]);\n\n return null;\n};\n\ninterface ContainerProps {\n apiService?: NotificationsProps['apiService'];\n children(publisher: Publisher): JSX.Element;\n}\n\nexport const Container: FC<ContainerProps> = ({ apiService, children }) => {\n const publisherInstance = useMemo(() => new Publisher(), []);\n\n return (\n <Provider\n singletons={[\n {\n provide: NOTIFICATIONS_CHANNEL_TOKEN,\n useValue: () => publisherInstance,\n },\n ]}\n >\n <Notifications apiService={apiService}>\n <NotificationsInitializer />\n {children(publisherInstance)}\n </Notifications>\n </Provider>\n );\n};\n"],"names":["useEffect","useMemo","Provider","useDependencies","NOTIFICATIONS_CHANNEL_TOKEN","Notifications","NotificationsService","Publisher","global_emitter","bind","unbind","subscription","_0","callback","fire","notification","NotificationsInitializer","notifications","initialize","Container","apiService","children","publisherInstance","singletons","provide","useValue"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../src/demo/container.tsx"],"sourcesContent":["import type { FC } from 'react';\nimport { useEffect, useMemo } from 'react';\n\nimport { Provider, useDependencies } from '@servicetitan/react-ioc';\n\nimport type { Notification } from '../api/notifications.api';\nimport type { NotificationsProps } from '..';\nimport { NOTIFICATIONS_CHANNEL_TOKEN, Notifications, NotificationsService } from '..';\n\ntype EventCallback = (notification: Notification) => void;\n\nclass Publisher {\n // eslint-disable-next-line @typescript-eslint/naming-convention\n global_emitter = {\n bind: () => {},\n unbind: () => {},\n };\n\n private subscription?: EventCallback;\n\n bind = (_0: string, callback: EventCallback) => {\n this.subscription = callback;\n };\n\n unbind = () => {};\n\n fire = (notification: Notification) => {\n if (this.subscription) {\n this.subscription(notification);\n }\n };\n}\n\nconst NotificationsInitializer: FC = () => {\n const [notifications] = useDependencies(NotificationsService);\n\n useEffect(() => {\n notifications.initialize();\n }, [notifications]);\n\n return null;\n};\n\ninterface ContainerProps {\n apiService?: NotificationsProps['apiService'];\n children(publisher: Publisher): JSX.Element;\n}\n\nexport const Container: FC<ContainerProps> = ({ apiService, children }) => {\n const publisherInstance = useMemo(() => new Publisher(), []);\n\n return (\n <Provider\n singletons={[\n {\n provide: NOTIFICATIONS_CHANNEL_TOKEN,\n useValue: () => publisherInstance,\n },\n ]}\n >\n <Notifications apiService={apiService}>\n <NotificationsInitializer />\n {children(publisherInstance)}\n </Notifications>\n </Provider>\n );\n};\n"],"names":["useEffect","useMemo","Provider","useDependencies","NOTIFICATIONS_CHANNEL_TOKEN","Notifications","NotificationsService","Publisher","global_emitter","bind","unbind","subscription","_0","callback","fire","notification","NotificationsInitializer","notifications","initialize","Container","apiService","children","publisherInstance","singletons","provide","useValue"],"mappings":";;;;;;;;;;;;AACA,SAASA,SAAS,EAAEC,OAAO,QAAQ,QAAQ;AAE3C,SAASC,QAAQ,EAAEC,eAAe,QAAQ,0BAA0B;AAIpE,SAASC,2BAA2B,EAAEC,aAAa,EAAEC,oBAAoB,QAAQ,KAAK;AAItF,MAAMC;;QACF,gEAAgE;QAChEC,uBAAAA,kBAAiB;YACbC,MAAM,KAAO;YACbC,QAAQ,KAAO;QACnB;QAEA,uBAAQC,gBAAR,KAAA;QAEAF,uBAAAA,QAAO,CAACG,IAAYC;YAChB,IAAI,CAACF,YAAY,GAAGE;QACxB;QAEAH,uBAAAA,UAAS,KAAO;QAEhBI,uBAAAA,QAAO,CAACC;YACJ,IAAI,IAAI,CAACJ,YAAY,EAAE;gBACnB,IAAI,CAACA,YAAY,CAACI;YACtB;QACJ;;AACJ;AAEA,MAAMC,2BAA+B;IACjC,MAAM,CAACC,cAAc,GAAGd,gBAAgBG;IAExCN,UAAU;QACNiB,cAAcC,UAAU;IAC5B,GAAG;QAACD;KAAc;IAElB,OAAO;AACX;AAOA,OAAO,MAAME,YAAgC,CAAC,EAAEC,UAAU,EAAEC,QAAQ,EAAE;IAClE,MAAMC,oBAAoBrB,QAAQ,IAAM,IAAIM,aAAa,EAAE;IAE3D,qBACI,KAACL;QACGqB,YAAY;YACR;gBACIC,SAASpB;gBACTqB,UAAU,IAAMH;YACpB;SACH;kBAED,cAAA,MAACjB;YAAce,YAAYA;;8BACvB,KAACJ;gBACAK,SAASC;;;;AAI1B,EAAE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/demo/mock-notifications-api.ts"],"sourcesContent":["import type { AxiosPromise, CancelToken } from 'axios';\nimport type { Notification } from '../api/notifications.api';\nimport { NotificationsApi } from '../api/notifications.api';\n\nexport class MockNotificationsApi extends NotificationsApi {\n private readonly localStorageKey = 'MockNotificationsApi.notifications';\n\n add(notification: Notification) {\n this.notifications = [...this.notifications, notification];\n }\n\n getNotification(id: number, _cancelToken?: CancelToken): AxiosPromise<Notification> {\n return Promise.resolve({ data: this.notifications.find(el => el.id === id) } as any);\n }\n\n getNotifications(_read: boolean, _cancelToken?: CancelToken): AxiosPromise<Notification[]> {\n return Promise.resolve({ data: this.notifications } as any);\n }\n\n changeIsReadProperty(\n id: number,\n read: boolean,\n _version: number,\n _cancelToken?: CancelToken\n ): AxiosPromise<void> {\n if (read) {\n this.notifications = this.notifications.filter(el => el.id !== id);\n }\n return Promise.resolve({} as any);\n }\n\n private get notifications() {\n const value = localStorage.getItem(this.localStorageKey);\n const result: Notification[] = value ? JSON.parse(value) : [];\n return result;\n }\n\n private set notifications(notifications: Notification[]) {\n if (notifications.length) {\n localStorage.setItem(this.localStorageKey, JSON.stringify(notifications));\n } else {\n localStorage.removeItem(this.localStorageKey);\n }\n }\n}\n"],"names":["NotificationsApi","MockNotificationsApi","add","notification","notifications","getNotification","id","_cancelToken","Promise","resolve","data","find","el","getNotifications","_read","changeIsReadProperty","read","_version","filter","value","localStorage","getItem","localStorageKey","result","JSON","parse","length","setItem","stringify","removeItem"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../src/demo/mock-notifications-api.ts"],"sourcesContent":["import type { AxiosPromise, CancelToken } from 'axios';\nimport type { Notification } from '../api/notifications.api';\nimport { NotificationsApi } from '../api/notifications.api';\n\nexport class MockNotificationsApi extends NotificationsApi {\n private readonly localStorageKey = 'MockNotificationsApi.notifications';\n\n add(notification: Notification) {\n this.notifications = [...this.notifications, notification];\n }\n\n getNotification(id: number, _cancelToken?: CancelToken): AxiosPromise<Notification> {\n return Promise.resolve({ data: this.notifications.find(el => el.id === id) } as any);\n }\n\n getNotifications(_read: boolean, _cancelToken?: CancelToken): AxiosPromise<Notification[]> {\n return Promise.resolve({ data: this.notifications } as any);\n }\n\n changeIsReadProperty(\n id: number,\n read: boolean,\n _version: number,\n _cancelToken?: CancelToken\n ): AxiosPromise<void> {\n if (read) {\n this.notifications = this.notifications.filter(el => el.id !== id);\n }\n return Promise.resolve({} as any);\n }\n\n private get notifications() {\n const value = localStorage.getItem(this.localStorageKey);\n const result: Notification[] = value ? JSON.parse(value) : [];\n return result;\n }\n\n private set notifications(notifications: Notification[]) {\n if (notifications.length) {\n localStorage.setItem(this.localStorageKey, JSON.stringify(notifications));\n } else {\n localStorage.removeItem(this.localStorageKey);\n }\n }\n}\n"],"names":["NotificationsApi","MockNotificationsApi","add","notification","notifications","getNotification","id","_cancelToken","Promise","resolve","data","find","el","getNotifications","_read","changeIsReadProperty","read","_version","filter","value","localStorage","getItem","localStorageKey","result","JSON","parse","length","setItem","stringify","removeItem"],"mappings":";;;;;;;;;;;AAEA,SAASA,gBAAgB,QAAQ,2BAA2B;AAE5D,OAAO,MAAMC,6BAA6BD;IAGtCE,IAAIC,YAA0B,EAAE;QAC5B,IAAI,CAACC,aAAa,GAAG;eAAI,IAAI,CAACA,aAAa;YAAED;SAAa;IAC9D;IAEAE,gBAAgBC,EAAU,EAAEC,YAA0B,EAA8B;QAChF,OAAOC,QAAQC,OAAO,CAAC;YAAEC,MAAM,IAAI,CAACN,aAAa,CAACO,IAAI,CAACC,CAAAA,KAAMA,GAAGN,EAAE,KAAKA;QAAI;IAC/E;IAEAO,iBAAiBC,KAAc,EAAEP,YAA0B,EAAgC;QACvF,OAAOC,QAAQC,OAAO,CAAC;YAAEC,MAAM,IAAI,CAACN,aAAa;QAAC;IACtD;IAEAW,qBACIT,EAAU,EACVU,IAAa,EACbC,QAAgB,EAChBV,YAA0B,EACR;QAClB,IAAIS,MAAM;YACN,IAAI,CAACZ,aAAa,GAAG,IAAI,CAACA,aAAa,CAACc,MAAM,CAACN,CAAAA,KAAMA,GAAGN,EAAE,KAAKA;QACnE;QACA,OAAOE,QAAQC,OAAO,CAAC,CAAC;IAC5B;IAEA,IAAYL,gBAAgB;QACxB,MAAMe,QAAQC,aAAaC,OAAO,CAAC,IAAI,CAACC,eAAe;QACvD,MAAMC,SAAyBJ,QAAQK,KAAKC,KAAK,CAACN,SAAS,EAAE;QAC7D,OAAOI;IACX;IAEA,IAAYnB,cAAcA,aAA6B,EAAE;QACrD,IAAIA,cAAcsB,MAAM,EAAE;YACtBN,aAAaO,OAAO,CAAC,IAAI,CAACL,eAAe,EAAEE,KAAKI,SAAS,CAACxB;QAC9D,OAAO;YACHgB,aAAaS,UAAU,CAAC,IAAI,CAACP,eAAe;QAChD;IACJ;;QAvCG,gBACH,uBAAiBA,mBAAkB;;AAuCvC"}
|
|
@@ -6,19 +6,26 @@ function _define_property(obj, key, value) {
|
|
|
6
6
|
configurable: true,
|
|
7
7
|
writable: true
|
|
8
8
|
});
|
|
9
|
-
} else
|
|
10
|
-
obj[key] = value;
|
|
11
|
-
}
|
|
9
|
+
} else obj[key] = value;
|
|
12
10
|
return obj;
|
|
13
11
|
}
|
|
14
12
|
function _ts_decorate(decorators, target, key, desc) {
|
|
15
13
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
16
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
17
|
-
|
|
14
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
|
|
15
|
+
r = Reflect.decorate(decorators, target, key, desc);
|
|
16
|
+
} else {
|
|
17
|
+
for(var i = decorators.length - 1; i >= 0; i--){
|
|
18
|
+
if (d = decorators[i]) {
|
|
19
|
+
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
18
23
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
19
24
|
}
|
|
20
|
-
function _ts_metadata(
|
|
21
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
|
|
25
|
+
function _ts_metadata(metadataKey, metadataValue) {
|
|
26
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
|
|
27
|
+
return Reflect.metadata(metadataKey, metadataValue);
|
|
28
|
+
}
|
|
22
29
|
}
|
|
23
30
|
function _ts_param(paramIndex, decorator) {
|
|
24
31
|
return function(target, key) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/notifications-service.ts"],"sourcesContent":["import { injectable, inject } from '@servicetitan/react-ioc';\n\nimport type { DefaultNotificationOptions } from './common';\nimport { Status } from './common';\n\nimport { NotificationsStore } from './stores/notifications.store';\n\ntype OptionsWithoutStatus = Omit<DefaultNotificationOptions, 'status'>;\n\nexport interface INotificationsService {\n initialize(userId?: number): Promise<void>;\n show(options: DefaultNotificationOptions, preventDuplicates?: boolean): void;\n info(options: OptionsWithoutStatus, preventDuplicates?: boolean): void;\n success(options: OptionsWithoutStatus, preventDuplicates?: boolean): void;\n warning(options: OptionsWithoutStatus, preventDuplicates?: boolean): void;\n error(options: OptionsWithoutStatus, preventDuplicates?: boolean): void;\n}\n\n@injectable()\nexport class NotificationsService implements INotificationsService {\n constructor(@inject(NotificationsStore) private readonly store: NotificationsStore) {}\n\n initialize = async (userId = 0) => {\n await this.store.initialize(userId);\n };\n\n show = (options: DefaultNotificationOptions, preventDuplicates?: boolean) => {\n this.store.add(options, preventDuplicates);\n };\n\n info = (options: OptionsWithoutStatus, preventDuplicates?: boolean) => {\n this.store.add({ ...options, status: Status.Info }, preventDuplicates);\n };\n\n success = (options: OptionsWithoutStatus, preventDuplicates?: boolean) => {\n this.store.add({ ...options, status: Status.Success }, preventDuplicates);\n };\n\n warning = (options: OptionsWithoutStatus, preventDuplicates?: boolean) => {\n this.store.add({ ...options, status: Status.Warning }, preventDuplicates);\n };\n\n error = (options: OptionsWithoutStatus, preventDuplicates?: boolean) => {\n this.store.add({ ...options, status: Status.Error }, preventDuplicates);\n };\n}\n"],"names":["injectable","inject","Status","NotificationsStore","NotificationsService","store","initialize","show","info","success","warning","error","userId","options","preventDuplicates","add","status","Info","Success","Warning","Error"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../src/notifications-service.ts"],"sourcesContent":["import { injectable, inject } from '@servicetitan/react-ioc';\n\nimport type { DefaultNotificationOptions } from './common';\nimport { Status } from './common';\n\nimport { NotificationsStore } from './stores/notifications.store';\n\ntype OptionsWithoutStatus = Omit<DefaultNotificationOptions, 'status'>;\n\nexport interface INotificationsService {\n initialize(userId?: number): Promise<void>;\n show(options: DefaultNotificationOptions, preventDuplicates?: boolean): void;\n info(options: OptionsWithoutStatus, preventDuplicates?: boolean): void;\n success(options: OptionsWithoutStatus, preventDuplicates?: boolean): void;\n warning(options: OptionsWithoutStatus, preventDuplicates?: boolean): void;\n error(options: OptionsWithoutStatus, preventDuplicates?: boolean): void;\n}\n\n@injectable()\nexport class NotificationsService implements INotificationsService {\n constructor(@inject(NotificationsStore) private readonly store: NotificationsStore) {}\n\n initialize = async (userId = 0) => {\n await this.store.initialize(userId);\n };\n\n show = (options: DefaultNotificationOptions, preventDuplicates?: boolean) => {\n this.store.add(options, preventDuplicates);\n };\n\n info = (options: OptionsWithoutStatus, preventDuplicates?: boolean) => {\n this.store.add({ ...options, status: Status.Info }, preventDuplicates);\n };\n\n success = (options: OptionsWithoutStatus, preventDuplicates?: boolean) => {\n this.store.add({ ...options, status: Status.Success }, preventDuplicates);\n };\n\n warning = (options: OptionsWithoutStatus, preventDuplicates?: boolean) => {\n this.store.add({ ...options, status: Status.Warning }, preventDuplicates);\n };\n\n error = (options: OptionsWithoutStatus, preventDuplicates?: boolean) => {\n this.store.add({ ...options, status: Status.Error }, preventDuplicates);\n };\n}\n"],"names":["injectable","inject","Status","NotificationsStore","NotificationsService","store","initialize","show","info","success","warning","error","userId","options","preventDuplicates","add","status","Info","Success","Warning","Error"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,SAASA,UAAU,EAAEC,MAAM,QAAQ,0BAA0B;AAG7D,SAASC,MAAM,QAAQ,WAAW;AAElC,SAASC,kBAAkB,QAAQ,+BAA+B;AAclE,OAAO,MAAMC;IACT,YAAY,AAA6CC,KAAyB,CAAE;;QAEpFC,uBAAAA,cAAAA,KAAAA;QAIAC,uBAAAA,QAAAA,KAAAA;QAIAC,uBAAAA,QAAAA,KAAAA;QAIAC,uBAAAA,WAAAA,KAAAA;QAIAC,uBAAAA,WAAAA,KAAAA;QAIAC,uBAAAA,SAAAA,KAAAA;aAtByDN,QAAAA;aAEzDC,aAAa,OAAOM,SAAS,CAAC;YAC1B,MAAM,IAAI,CAACP,KAAK,CAACC,UAAU,CAACM;QAChC;aAEAL,OAAO,CAACM,SAAqCC;YACzC,IAAI,CAACT,KAAK,CAACU,GAAG,CAACF,SAASC;QAC5B;aAEAN,OAAO,CAACK,SAA+BC;YACnC,IAAI,CAACT,KAAK,CAACU,GAAG,CAAC;gBAAE,GAAGF,OAAO;gBAAEG,QAAQd,OAAOe,IAAI;YAAC,GAAGH;QACxD;aAEAL,UAAU,CAACI,SAA+BC;YACtC,IAAI,CAACT,KAAK,CAACU,GAAG,CAAC;gBAAE,GAAGF,OAAO;gBAAEG,QAAQd,OAAOgB,OAAO;YAAC,GAAGJ;QAC3D;aAEAJ,UAAU,CAACG,SAA+BC;YACtC,IAAI,CAACT,KAAK,CAACU,GAAG,CAAC;gBAAE,GAAGF,OAAO;gBAAEG,QAAQd,OAAOiB,OAAO;YAAC,GAAGL;QAC3D;aAEAH,QAAQ,CAACE,SAA+BC;YACpC,IAAI,CAACT,KAAK,CAACU,GAAG,CAAC;gBAAE,GAAGF,OAAO;gBAAEG,QAAQd,OAAOkB,KAAK;YAAC,GAAGN;QACzD;IAxBqF;AAyBzF"}
|
|
@@ -4,15 +4,12 @@ function _check_private_redeclaration(obj, privateCollection) {
|
|
|
4
4
|
}
|
|
5
5
|
}
|
|
6
6
|
function _class_apply_descriptor_get(receiver, descriptor) {
|
|
7
|
-
if (descriptor.get)
|
|
8
|
-
return descriptor.get.call(receiver);
|
|
9
|
-
}
|
|
7
|
+
if (descriptor.get) return descriptor.get.call(receiver);
|
|
10
8
|
return descriptor.value;
|
|
11
9
|
}
|
|
12
10
|
function _class_apply_descriptor_set(receiver, descriptor, value) {
|
|
13
|
-
if (descriptor.set)
|
|
14
|
-
|
|
15
|
-
} else {
|
|
11
|
+
if (descriptor.set) descriptor.set.call(receiver, value);
|
|
12
|
+
else {
|
|
16
13
|
if (!descriptor.writable) {
|
|
17
14
|
throw new TypeError("attempted to set read only private field");
|
|
18
15
|
}
|
|
@@ -20,9 +17,7 @@ function _class_apply_descriptor_set(receiver, descriptor, value) {
|
|
|
20
17
|
}
|
|
21
18
|
}
|
|
22
19
|
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
|
-
}
|
|
20
|
+
if (!privateMap.has(receiver)) throw new TypeError("attempted to " + action + " private field on non-instance");
|
|
26
21
|
return privateMap.get(receiver);
|
|
27
22
|
}
|
|
28
23
|
function _class_private_field_get(receiver, privateMap) {
|
|
@@ -46,19 +41,26 @@ function _define_property(obj, key, value) {
|
|
|
46
41
|
configurable: true,
|
|
47
42
|
writable: true
|
|
48
43
|
});
|
|
49
|
-
} else
|
|
50
|
-
obj[key] = value;
|
|
51
|
-
}
|
|
44
|
+
} else obj[key] = value;
|
|
52
45
|
return obj;
|
|
53
46
|
}
|
|
54
47
|
function _ts_decorate(decorators, target, key, desc) {
|
|
55
48
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
56
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
57
|
-
|
|
49
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
|
|
50
|
+
r = Reflect.decorate(decorators, target, key, desc);
|
|
51
|
+
} else {
|
|
52
|
+
for(var i = decorators.length - 1; i >= 0; i--){
|
|
53
|
+
if (d = decorators[i]) {
|
|
54
|
+
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
58
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
59
59
|
}
|
|
60
|
-
function _ts_metadata(
|
|
61
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
|
|
60
|
+
function _ts_metadata(metadataKey, metadataValue) {
|
|
61
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
|
|
62
|
+
return Reflect.metadata(metadataKey, metadataValue);
|
|
63
|
+
}
|
|
62
64
|
}
|
|
63
65
|
function _ts_param(paramIndex, decorator) {
|
|
64
66
|
return function(target, key) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/stores/notifications.store.ts"],"sourcesContent":["import type { toastProps } from '@servicetitan/anvil2';\nimport { toast, Toaster } from '@servicetitan/anvil2';\nimport { injectable, inject, optional } from '@servicetitan/react-ioc';\nimport { action, runInAction, comparer, makeObservable } from 'mobx';\nimport type { ComponentProps } from 'react';\n\nimport type {\n DefaultServerNotificationPayload,\n Notification as ServerNotification,\n} from '../api/notifications.api';\nimport {\n NotificationsApi,\n NotificationProcessStatus as ServerNotificationStatus,\n} from '../api/notifications.api';\nimport type { DefaultNotificationOptions, Notification } from '../common';\nimport { Status, isLinkAction, isNewer } from '../common';\nimport type { NotificationInterceptor } from '../intercept';\nimport type { NotificationsChannel } from '../notifications-channel';\nimport { 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 toastActive?: boolean;\n}\n\ntype NavigateCallback = (path: string) => void;\n\ntype ToastMethod = 'info' | 'success' | 'warning' | 'danger';\n\ntype ToastEvent = Parameters<NonNullable<ComponentProps<typeof Toaster>['onToastEvent']>>[0];\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 private readonly timers: Map<number, 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 this.timers = new Map();\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 Object.values(this.timers).forEach(timer => window.clearTimeout(timer));\n this.timers.clear();\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 const id = notification.id;\n if (!this.notifications.get(id)) {\n return;\n }\n\n if (id > 0) {\n this.clearTimer(notification);\n\n if (notification.status === ServerNotificationStatus.InProgress) {\n this.closedNotifications.set(id, {\n status: notification.status,\n timestamp: Date.now(),\n });\n }\n\n if (this.notificationsApi) {\n this.notificationsApi.changeIsReadProperty(id, true, notification.version);\n }\n }\n\n this.notifications.delete(id);\n };\n\n onToastEvent = (toastEvent: ToastEvent) => {\n if (toastEvent.eventType === 'add') {\n for (const [id, { toastId }] of Array.from(this.notifications)) {\n if (toastId === toastEvent.id) {\n this.notifications.get(id)!.toastActive = true;\n }\n }\n }\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 this.setTimer(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 this.setTimer(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 onDismiss: () => this.handleDismiss(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 handleDismiss(notification: Notification) {\n if (process.env.NODE_ENV !== 'production') {\n /*\n * StrictMode's double-rendering trigger's multiple onDismiss callbacks.\n * Ignore any that arrive before the toast is displayed.\n */\n if (!this.notifications.get(notification.id)?.toastActive) {\n return;\n }\n }\n\n this.handleClose(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 private setTimer(notification: ClientNotification) {\n this.clearTimer(notification);\n\n const { duration = 0 } = notification.payload;\n if (duration <= 0) {\n return;\n }\n\n this.timers.set(\n notification.id,\n window.setTimeout(() => this.read(notification), duration)\n );\n }\n\n private clearTimer({ id }: Notification) {\n const timer = this.timers.get(id);\n if (!timer) {\n return;\n }\n\n this.timers.delete(id);\n window.clearTimeout(timer);\n }\n}\n"],"names":["toast","injectable","inject","optional","action","runInAction","comparer","makeObservable","NotificationsApi","NotificationProcessStatus","ServerNotificationStatus","Status","isLinkAction","isNewer","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","setTimer","dismiss","method","getToastMethod","payload","Success","Error","Warning","duration","message","progress","title","actions","getToastActions","onClose","handleClose","onDismiss","handleDismiss","primary","label","onClick","handleClick","external","window","open","link","read","process","env","NODE_ENV","toastActive","serverNotification","result","JSON","parse","toClientStatus","interceptor","Failure","Info","clearTimer","timers","setTimeout","timer","clearTimeout","notificationsApi","index","userId","intervalId","initialize","dispose","add","onToastEvent","onPublisherEvent","Map","bind","setInterval","getNotifications","data","global_emitter","unbind","clearInterval","Object","values","forEach","clear","options","preventDuplicates","isRead","createdOn","modifiedOn","version","some","structural","changeIsReadProperty","toastEvent","eventType"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,SAASA,KAAK,QAAiB,uBAAuB;AACtD,SAASC,UAAU,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,0BAA0B;AACvE,SAASC,MAAM,EAAEC,WAAW,EAAEC,QAAQ,EAAEC,cAAc,QAAQ,OAAO;AAOrE,SACIC,gBAAgB,EAChBC,6BAA6BC,wBAAwB,QAClD,2BAA2B;AAElC,SAASC,MAAM,EAAEC,YAAY,EAAEC,OAAO,QAAQ,YAAY;AAG1D,SAASC,2BAA2B,QAAQ,2BAA2B;AACvE,SAASC,cAAc,QAAQ,4BAA4B;AAE3D,MAAMC,aAAa;AACnB,MAAMC,2BAA2B;AACjC,MAAMC,8BAA8B;AACpC,MAAMC,eAAe,KAAK,KAAK,KAAK;IA8BhC;AAXJ,OAAO,MAAMC;IAuBT,OAAOC,UAAUC,IAAY,EAAEC,EAA4B,EAAE;QACzD,IAAIA,IAAI;YACJH,mBAAmBI,YAAY,CAACC,GAAG,CAACH,MAAMC;QAC9C,OAAO;YACHH,mBAAmBI,YAAY,CAACE,MAAM,CAACJ;QAC3C;IACJ;IAEA,IAAYK,YAAY;YACb,4BAAA;QAAP,QAAO,6BAAA,CAAA,QAAA,IAAI,EAACC,oBAAoB,cAAzB,iDAAA,gCAAA;IACX;IAEA,IAAIC,WAAyC;QACzC,gCAAO,IAAI,EAAC;IAChB;IAEA,IAAIA,SAASN,EAAoB,EAAE;uCAC1B,WAAYA;IACrB;IAgHQO,6BAA6B;QACjC,KAAK,MAAM,CAACC,IAAI,EAAEC,SAAS,EAAE,CAAC,IAAIC,MAAMC,IAAI,CAAC,IAAI,CAACC,mBAAmB,EAAG;YACpE,IAAIC,KAAKC,GAAG,KAA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a;IACtB;AAyTJ;AA7UI,iBADSpF,oBACOI,gBAAe,IAAIgF"}
|
|
1
|
+
{"version":3,"sources":["../../src/stores/notifications.store.ts"],"sourcesContent":["import type { toastProps } from '@servicetitan/anvil2';\nimport { toast, Toaster } from '@servicetitan/anvil2';\nimport { injectable, inject, optional } from '@servicetitan/react-ioc';\nimport { action, runInAction, comparer, makeObservable } from 'mobx';\nimport type { ComponentProps } from 'react';\n\nimport type {\n DefaultServerNotificationPayload,\n Notification as ServerNotification,\n} from '../api/notifications.api';\nimport {\n NotificationsApi,\n NotificationProcessStatus as ServerNotificationStatus,\n} from '../api/notifications.api';\nimport type { DefaultNotificationOptions, Notification } from '../common';\nimport { Status, isLinkAction, isNewer } from '../common';\nimport type { NotificationInterceptor } from '../intercept';\nimport type { NotificationsChannel } from '../notifications-channel';\nimport { 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 toastActive?: boolean;\n}\n\ntype NavigateCallback = (path: string) => void;\n\ntype ToastMethod = 'info' | 'success' | 'warning' | 'danger';\n\ntype ToastEvent = Parameters<NonNullable<ComponentProps<typeof Toaster>['onToastEvent']>>[0];\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 private readonly timers: Map<number, 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 this.timers = new Map();\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 Object.values(this.timers).forEach(timer => window.clearTimeout(timer));\n this.timers.clear();\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 const id = notification.id;\n if (!this.notifications.get(id)) {\n return;\n }\n\n if (id > 0) {\n this.clearTimer(notification);\n\n if (notification.status === ServerNotificationStatus.InProgress) {\n this.closedNotifications.set(id, {\n status: notification.status,\n timestamp: Date.now(),\n });\n }\n\n if (this.notificationsApi) {\n this.notificationsApi.changeIsReadProperty(id, true, notification.version);\n }\n }\n\n this.notifications.delete(id);\n };\n\n onToastEvent = (toastEvent: ToastEvent) => {\n if (toastEvent.eventType === 'add') {\n for (const [id, { toastId }] of Array.from(this.notifications)) {\n if (toastId === toastEvent.id) {\n this.notifications.get(id)!.toastActive = true;\n }\n }\n }\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 this.setTimer(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 this.setTimer(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 onDismiss: () => this.handleDismiss(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 handleDismiss(notification: Notification) {\n if (process.env.NODE_ENV !== 'production') {\n /*\n * StrictMode's double-rendering trigger's multiple onDismiss callbacks.\n * Ignore any that arrive before the toast is displayed.\n */\n if (!this.notifications.get(notification.id)?.toastActive) {\n return;\n }\n }\n\n this.handleClose(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 private setTimer(notification: ClientNotification) {\n this.clearTimer(notification);\n\n const { duration = 0 } = notification.payload;\n if (duration <= 0) {\n return;\n }\n\n this.timers.set(\n notification.id,\n window.setTimeout(() => this.read(notification), duration)\n );\n }\n\n private clearTimer({ id }: Notification) {\n const timer = this.timers.get(id);\n if (!timer) {\n return;\n }\n\n this.timers.delete(id);\n window.clearTimeout(timer);\n }\n}\n"],"names":["toast","injectable","inject","optional","action","runInAction","comparer","makeObservable","NotificationsApi","NotificationProcessStatus","ServerNotificationStatus","Status","isLinkAction","isNewer","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","setTimer","dismiss","method","getToastMethod","payload","Success","Error","Warning","duration","message","progress","title","actions","getToastActions","onClose","handleClose","onDismiss","handleDismiss","primary","label","onClick","handleClick","external","window","open","link","read","process","env","NODE_ENV","toastActive","serverNotification","result","JSON","parse","toClientStatus","interceptor","Failure","Info","clearTimer","timers","setTimeout","timer","clearTimeout","notificationsApi","index","userId","intervalId","initialize","dispose","add","onToastEvent","onPublisherEvent","Map","bind","setInterval","getNotifications","data","global_emitter","unbind","clearInterval","Object","values","forEach","clear","options","preventDuplicates","isRead","createdOn","modifiedOn","version","some","structural","changeIsReadProperty","toastEvent","eventType"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,SAASA,KAAK,QAAiB,uBAAuB;AACtD,SAASC,UAAU,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,0BAA0B;AACvE,SAASC,MAAM,EAAEC,WAAW,EAAEC,QAAQ,EAAEC,cAAc,QAAQ,OAAO;AAOrE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wBAC7BW,QAAQH,aAAaG,MAAM;wBAC3BV,WAAWI,KAAKC,GAAG;oBACvB;gBACJ;gBAEA,IAAI,IAAI,CAAC0D,gBAAgB,EAAE;oBACvB,IAAI,CAACA,gBAAgB,CAAC6B,oBAAoB,CAAC7F,IAAI,MAAMQ,aAAakF,OAAO;gBAC7E;YACJ;YAEA,IAAI,CAAC3E,aAAa,CAACpB,MAAM,CAACK;QAC9B;aAEAuE,eAAe,CAACuB;YACZ,IAAIA,WAAWC,SAAS,KAAK,OAAO;gBAChC,KAAK,MAAM,CAAC/F,IAAI,EAAEkB,OAAO,EAAE,CAAC,IAAIhB,MAAMC,IAAI,CAAC,IAAI,CAACY,aAAa,EAAG;oBAC5D,IAAIG,YAAY4E,WAAW9F,EAAE,EAAE;wBAC3B,IAAI,CAACe,aAAa,CAACL,GAAG,CAACV,IAAKkD,WAAW,GAAG;oBAC9C;gBACJ;YACJ;QACJ;aAGiBsB,mBAAmB,CAAChE;YACjC,IAAIA,aAAa0D,MAAM,KAAK,IAAI,CAACA,MAAM,EAAE;gBACrC;YACJ;YAEA,IAAI,CAAC3D,aAAa,CAAC;gBACf,GAAGC,YAAY;gBACfgF,WAAWxG,eAAewB,aAAagF,SAAS;gBAChDC,YAAYzG,eAAewB,aAAaiF,UAAU;YACtD;QACJ;QApIIjH,eAAe,IAAI;QACnB,IAAI,CAACoF,MAAM,GAAG,IAAIa;IACtB;AAyTJ;AA7UI,iBADSpF,oBACOI,gBAAe,IAAIgF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@servicetitan/notifications",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "42.0.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"homepage": "https://docs.st.dev/docs/frontend/notifications-center",
|
|
6
6
|
"repository": {
|
|
@@ -19,10 +19,10 @@
|
|
|
19
19
|
"react-shadow-dom-retarget-events": "~1.1.0"
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|
|
22
|
-
"@servicetitan/anvil2": "^3.
|
|
23
|
-
"@servicetitan/design-system": "~14.5.
|
|
24
|
-
"@servicetitan/react-ioc": "^38.
|
|
25
|
-
"@servicetitan/testing-library": "^
|
|
22
|
+
"@servicetitan/anvil2": "^3.9.0",
|
|
23
|
+
"@servicetitan/design-system": "~14.5.3",
|
|
24
|
+
"@servicetitan/react-ioc": "^38.1.0",
|
|
25
|
+
"@servicetitan/testing-library": "^7.0.0",
|
|
26
26
|
"@testing-library/jest-dom": "^6.4.2",
|
|
27
27
|
"@testing-library/react": "^14.2.1",
|
|
28
28
|
"@types/react": "~18.2.55",
|
|
@@ -52,5 +52,5 @@
|
|
|
52
52
|
"cli": {
|
|
53
53
|
"webpack": false
|
|
54
54
|
},
|
|
55
|
-
"gitHead": "
|
|
55
|
+
"gitHead": "af4dee1e6d65f7b611a03a15771adf5a6fa6f45d"
|
|
56
56
|
}
|