web-push-notifications 3.44.7 → 3.44.8
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/core/Pushwoosh.d.ts +199 -0
- package/core/Pushwoosh.types.d.ts +213 -0
- package/core/Safari.types.d.ts +17 -0
- package/core/constants.d.ts +41 -0
- package/core/events.types.d.ts +55 -0
- package/core/functions.d.ts +5 -0
- package/core/legacyEventsMap.d.ts +5 -0
- package/core/logger.d.ts +14 -0
- package/core/modules/EventBus/EventBus.d.ts +10 -0
- package/core/storage.d.ts +27 -0
- package/helpers/logger.d.ts +11 -0
- package/helpers/pwlogger/Logger.constants.d.ts +21 -0
- package/helpers/pwlogger/Logger.d.ts +37 -0
- package/helpers/pwlogger/Logger.types.d.ts +44 -0
- package/helpers/pwlogger/handlers/handler-console/handler-console.d.ts +2 -0
- package/{src/helpers/unescape.ts → helpers/unescape.d.ts} +1 -18
- package/models/InboxMessages.d.ts +82 -0
- package/models/InboxMessages.types.d.ts +83 -0
- package/models/NotificationPayload.d.ts +39 -0
- package/models/NotificationPayload.types.d.ts +63 -0
- package/modules/Api/Api.d.ts +45 -0
- package/modules/Api/Api.types.d.ts +7 -0
- package/modules/ApiClient/ApiClient.d.ts +29 -0
- package/modules/ApiClient/ApiClient.types.d.ts +188 -0
- package/modules/Data/Data.d.ts +76 -0
- package/modules/DateModule.d.ts +27 -0
- package/modules/InboxMessagesPublic.d.ts +64 -0
- package/modules/PlatformChecker/PlatformChecker.d.ts +45 -0
- package/modules/PlatformChecker/PlatformChecker.types.d.ts +5 -0
- package/modules/storage/Storage.d.ts +63 -0
- package/{src/modules/storage/Storage.types.ts → modules/storage/Storage.types.d.ts} +7 -25
- package/modules/storage/Store.d.ts +22 -0
- package/modules/storage/migrations/26-11-2018.d.ts +2 -0
- package/modules/storage/migrations/MigrationExecutor.d.ts +9 -0
- package/modules/storage/migrations/Migrations.d.ts +15 -0
- package/modules/storage/migrations/constants.d.ts +6 -0
- package/modules/storage/migrations/helpers.d.ts +7 -0
- package/modules/storage/migrations/initial.d.ts +2 -0
- package/modules/storage/version.d.ts +2 -0
- package/npm.js +2 -0
- package/npm.js.map +1 -0
- package/package.json +1 -1
- package/service-worker.d.ts +1 -0
- package/service-worker.js +2 -0
- package/service-worker.js.map +1 -0
- package/services/PushService/PushService.types.d.ts +64 -0
- package/services/PushService/drivers/PushServiceDefault/PushServiceDefault.d.ts +29 -0
- package/{src/services/PushService/drivers/PushServiceDefault/PushServiceDefault.types.ts → services/PushService/drivers/PushServiceDefault/PushServiceDefault.types.d.ts} +1 -1
- package/services/PushService/drivers/PushServiceSafari/PushServiceSafari.d.ts +21 -0
- package/services/PushService/drivers/PushServiceSafari/PushServiceSafari.types.d.ts +4 -0
- package/widget-inbox.js +2 -0
- package/widget-inbox.js.map +1 -0
- package/widget-subscribe-popup.js +2 -0
- package/widget-subscribe-popup.js.map +1 -0
- package/widget-subscription-button.js +2 -0
- package/widget-subscription-button.js.map +1 -0
- package/widget-subscription-prompt.d.ts +2 -0
- package/widget-subscription-prompt.js +2 -0
- package/widget-subscription-prompt.js.map +1 -0
- package/widgets/Inbox/InboxWidget.d.ts +49 -0
- package/widgets/Inbox/constants.d.ts +7 -0
- package/widgets/Inbox/helpers.d.ts +4 -0
- package/widgets/Inbox/inbox_widget.types.d.ts +34 -0
- package/widgets/Inbox/widgetTemplates.d.ts +4 -0
- package/widgets/SubscribePopup/SubscribePopup.d.ts +20 -0
- package/widgets/SubscribePopup/constants.d.ts +6 -0
- package/widgets/SubscribePopup/helpers.d.ts +1 -0
- package/widgets/SubscribePopup/popupTemplates.d.ts +9 -0
- package/widgets/SubscribePopup/types/subscribe-popup.d.ts +43 -0
- package/widgets/SubscriptionButton/bell.d.ts +2 -0
- package/widgets/SubscriptionButton/constants.d.ts +7 -0
- package/widgets/SubscriptionButton/index.d.ts +90 -0
- package/widgets/SubscriptionButton/positioning.d.ts +11 -0
- package/widgets/SubscriptionButton/subscribe_widget.types.d.ts +35 -0
- package/widgets/SubscriptionPrompt/SubscriptionPromptWidget.constants.d.ts +1 -0
- package/widgets/SubscriptionPrompt/SubscriptionPromptWidget.d.ts +14 -0
- package/widgets/SubscriptionPrompt/SubscriptionPromptWidget.helpers.d.ts +3 -0
- package/widgets/SubscriptionPrompt/SubscriptionPromptWidget.types.d.ts +19 -0
- package/widgets/SubscriptionPrompt/constants.d.ts +21 -0
- package/widgets/SubscriptionPrompt/helpers.d.ts +5 -0
- package/worker/global.d.ts +16 -0
- package/worker/notification.d.ts +9 -0
- package/worker/worker.types.d.ts +4 -0
- package/.editorconfig +0 -11
- package/.gitlab-ci.yml +0 -193
- package/babel.config.js +0 -7
- package/ci/cdn/Dockerfile +0 -12
- package/ci/dev/Dockerfile +0 -30
- package/ci/dev/rootfs/entrypoint.sh +0 -18
- package/ci/dev/rootfs/entrypoint.sh.d/nginx.sh +0 -6
- package/ci/dev/rootfs/entrypoint.sh.d/supervisor.sh +0 -5
- package/ci/dev/rootfs/etc/nginx/_real_ip.conf +0 -2
- package/ci/dev/rootfs/etc/nginx/conf.d/default.conf +0 -20
- package/ci/dev/rootfs/etc/supervisor.d/nginx.ini +0 -11
- package/ci/github/Dockerfile +0 -59
- package/ci/github/release-zip.js +0 -61
- package/ci/npm/Dockerfile +0 -22
- package/config/config.js +0 -24
- package/config/configBuilder.js +0 -126
- package/config/helpers.js +0 -9
- package/config/index.js +0 -1
- package/develop/README.md +0 -42
- package/develop/favicon.png +0 -0
- package/develop/index.html +0 -511
- package/eslint.config.mjs +0 -114
- package/public/index.d.ts +0 -337
- package/scripts/zip.js +0 -26
- package/src/core/Pushwoosh.ts +0 -768
- package/src/core/Pushwoosh.types.ts +0 -254
- package/src/core/Safari.types.ts +0 -26
- package/src/core/constants.ts +0 -58
- package/src/core/events.types.ts +0 -46
- package/src/core/functions.ts +0 -33
- package/src/core/legacyEventsMap.ts +0 -64
- package/src/core/logger.ts +0 -64
- package/src/core/modules/EventBus/EventBus.ts +0 -66
- package/src/core/storage.ts +0 -254
- package/src/helpers/logger.ts +0 -81
- package/src/helpers/pwlogger/Logger.constants.ts +0 -31
- package/src/helpers/pwlogger/Logger.ts +0 -218
- package/src/helpers/pwlogger/Logger.types.ts +0 -66
- package/src/helpers/pwlogger/handlers/handler-console/handler-console.ts +0 -40
- package/src/models/InboxMessages.ts +0 -202
- package/src/models/InboxMessages.types.ts +0 -111
- package/src/models/NotificationPayload.ts +0 -216
- package/src/models/NotificationPayload.types.ts +0 -65
- package/src/modules/Api/Api.ts +0 -386
- package/src/modules/Api/Api.types.ts +0 -7
- package/src/modules/ApiClient/ApiClient.ts +0 -153
- package/src/modules/ApiClient/ApiClient.types.ts +0 -222
- package/src/modules/Data/Data.ts +0 -345
- package/src/modules/DateModule.ts +0 -53
- package/src/modules/InboxMessagesPublic.ts +0 -222
- package/src/modules/PlatformChecker/PlatformChecker.ts +0 -170
- package/src/modules/PlatformChecker/PlatformChecker.types.ts +0 -5
- package/src/modules/storage/Storage.ts +0 -164
- package/src/modules/storage/Store.ts +0 -104
- package/src/modules/storage/migrations/26-11-2018.ts +0 -25
- package/src/modules/storage/migrations/MigrationExecutor.ts +0 -31
- package/src/modules/storage/migrations/Migrations.ts +0 -41
- package/src/modules/storage/migrations/constants.ts +0 -8
- package/src/modules/storage/migrations/helpers.ts +0 -16
- package/src/modules/storage/migrations/initial.ts +0 -47
- package/src/modules/storage/version.ts +0 -2
- package/src/pushwoosh-web-notifications.ts +0 -47
- package/src/pushwoosh-widget-inbox.ts +0 -8
- package/src/pushwoosh-widget-subscribe-popup.ts +0 -9
- package/src/pushwoosh-widget-subscription-button.ts +0 -8
- package/src/pushwoosh-widget-subscription-prompt.ts +0 -6
- package/src/service-worker.ts +0 -455
- package/src/services/PushService/PushService.types.ts +0 -74
- package/src/services/PushService/drivers/PushServiceDefault/PushServiceDefault.ts +0 -235
- package/src/services/PushService/drivers/PushServiceSafari/PushServiceSafari.ts +0 -125
- package/src/services/PushService/drivers/PushServiceSafari/PushServiceSafari.types.ts +0 -4
- package/src/widget-subscription-prompt.ts +0 -33
- package/src/widgets/Inbox/InboxWidget.ts +0 -564
- package/src/widgets/Inbox/constants.ts +0 -49
- package/src/widgets/Inbox/css/inboxWidgetStyle.css +0 -274
- package/src/widgets/Inbox/helpers.ts +0 -63
- package/src/widgets/Inbox/inbox.d.ts +0 -9
- package/src/widgets/Inbox/inbox_widget.types.ts +0 -41
- package/src/widgets/Inbox/widgetTemplates.ts +0 -55
- package/src/widgets/SubscribePopup/SubscribePopup.ts +0 -241
- package/src/widgets/SubscribePopup/constants.ts +0 -66
- package/src/widgets/SubscribePopup/helpers.ts +0 -11
- package/src/widgets/SubscribePopup/popupTemplates.ts +0 -24
- package/src/widgets/SubscribePopup/styles/popup.css +0 -226
- package/src/widgets/SubscribePopup/types/subscribe-popup.ts +0 -68
- package/src/widgets/SubscriptionButton/assets/css/main.css +0 -205
- package/src/widgets/SubscriptionButton/bell.ts +0 -67
- package/src/widgets/SubscriptionButton/constants.ts +0 -28
- package/src/widgets/SubscriptionButton/index.ts +0 -377
- package/src/widgets/SubscriptionButton/positioning.ts +0 -165
- package/src/widgets/SubscriptionButton/subscribe_widget.types.ts +0 -53
- package/src/widgets/SubscriptionPrompt/SubscriptionPromptWidget.constants.ts +0 -1
- package/src/widgets/SubscriptionPrompt/SubscriptionPromptWidget.helpers.ts +0 -110
- package/src/widgets/SubscriptionPrompt/SubscriptionPromptWidget.ts +0 -102
- package/src/widgets/SubscriptionPrompt/SubscriptionPromptWidget.types.ts +0 -23
- package/src/widgets/SubscriptionPrompt/constants.ts +0 -22
- package/src/widgets/SubscriptionPrompt/helpers.ts +0 -42
- package/src/widgets/widgets.d.ts +0 -4
- package/src/worker/global.ts +0 -36
- package/src/worker/notification.ts +0 -34
- package/src/worker/worker.types.ts +0 -4
- package/test/__helpers__/apiHelpers.ts +0 -22
- package/test/__helpers__/keyValueHelpers.ts +0 -15
- package/test/__helpers__/platformHelpers.ts +0 -54
- package/test/__helpers__/sinonHelpers.ts +0 -7
- package/test/__helpers__/storageHelpers.ts +0 -56
- package/test/__mocks__/apiRequests.ts +0 -26
- package/test/__mocks__/idbMock.ts +0 -12
- package/test/__mocks__/idbObjectStoreMock.ts +0 -38
- package/test/__mocks__/inboxMessages.ts +0 -292
- package/test/__mocks__/models/inboxModel.ts +0 -71
- package/test/__mocks__/modules/apiClientModule.ts +0 -18
- package/test/__mocks__/modules/dateModule.ts +0 -34
- package/test/__mocks__/modules/inboxParamsModule.ts +0 -21
- package/test/__mocks__/modules/paramsBuilder.ts +0 -12
- package/test/__mocks__/modules/paramsModule.ts +0 -35
- package/test/__mocks__/modules/payloadBuilderModule.ts +0 -15
- package/test/__mocks__/modules/storageModule.ts +0 -58
- package/test/__mocks__/navigator.ts +0 -38
- package/test/__mocks__/notification.ts +0 -84
- package/test/__mocks__/pushwoosh.ts +0 -12
- package/test/__mocks__/userAgents +0 -8
- package/test/functions.test.ts +0 -22
- package/test/ignore-html.js +0 -6
- package/test/mocha.opts +0 -6
- package/test/modules/DateModule/unit.test.ts +0 -80
- package/test/modules/storage/Storage/unit.test.ts +0 -180
- package/test/modules/storage/Store/unit.test.ts +0 -192
- package/testRegister.js +0 -24
- package/tsconfig.json +0 -31
- package/webpack.config.js +0 -163
- /package/{src/core/modules/EventBus/index.ts → core/modules/EventBus/index.d.ts} +0 -0
- /package/{src/helpers/pwlogger/index.ts → helpers/pwlogger/index.d.ts} +0 -0
- /package/{src/modules/PlatformChecker/index.ts → modules/PlatformChecker/index.d.ts} +0 -0
- /package/{src/npm.ts → npm.d.ts} +0 -0
- /package/{src/services/PushService/PushService.ts → services/PushService/PushService.d.ts} +0 -0
- /package/{src/widget-inbox.ts → widget-inbox.d.ts} +0 -0
- /package/{src/widget-subscribe-popup.ts → widget-subscribe-popup.d.ts} +0 -0
- /package/{src/widget-subscription-button.ts → widget-subscription-button.d.ts} +0 -0
- /package/{src/widgets/Inbox/index.ts → widgets/Inbox/index.d.ts} +0 -0
- /package/{src/widgets/SubscribePopup/index.ts → widgets/SubscribePopup/index.d.ts} +0 -0
|
@@ -1,202 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
type IGetInboxMessagesResponse, type IInboxMessage, type TInboxMessagesIDBStatusIndex,
|
|
3
|
-
type TInboxMessageStatusDelivered, type TInboxMessageStatusOpen,
|
|
4
|
-
type TInboxMessageStatusRead, type TReadInboxMessagesStatusRange,
|
|
5
|
-
} from './InboxMessages.types';
|
|
6
|
-
import { type EventBus } from '../core/modules/EventBus';
|
|
7
|
-
import { type Api } from '../modules/Api/Api';
|
|
8
|
-
import { type Data } from '../modules/Data/Data';
|
|
9
|
-
import DateModule from '../modules/DateModule';
|
|
10
|
-
import InboxMessagesPublic from '../modules/InboxMessagesPublic';
|
|
11
|
-
import Storage from '../modules/storage/Storage';
|
|
12
|
-
import { type TInboxMessagesStoreName } from '../modules/storage/Storage.types';
|
|
13
|
-
|
|
14
|
-
export default class InboxMessages {
|
|
15
|
-
eventBus: EventBus;
|
|
16
|
-
data: Data;
|
|
17
|
-
api: Api;
|
|
18
|
-
storage: Storage;
|
|
19
|
-
storeName: TInboxMessagesStoreName;
|
|
20
|
-
dateModule: DateModule;
|
|
21
|
-
|
|
22
|
-
constructor(
|
|
23
|
-
eventBus: EventBus,
|
|
24
|
-
data: Data,
|
|
25
|
-
api: Api,
|
|
26
|
-
storage: Storage = new Storage(),
|
|
27
|
-
dateModule: DateModule = new DateModule(),
|
|
28
|
-
) {
|
|
29
|
-
this.eventBus = eventBus;
|
|
30
|
-
this.data = data;
|
|
31
|
-
this.api = api;
|
|
32
|
-
|
|
33
|
-
this.storage = storage;
|
|
34
|
-
this.storeName = 'inboxMessages';
|
|
35
|
-
this.dateModule = dateModule;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Get inbox messages by api
|
|
40
|
-
*/
|
|
41
|
-
private async getInboxMessages(): Promise<IGetInboxMessagesResponse> {
|
|
42
|
-
// get inbox messages
|
|
43
|
-
const response: IGetInboxMessagesResponse = await this.api.getInboxMessages();
|
|
44
|
-
await this.storeGetInboxMessagesRequestParams(response.next, response.new_inbox);
|
|
45
|
-
|
|
46
|
-
return response;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* Store parameters for next getInboxMessages request
|
|
51
|
-
* @param next
|
|
52
|
-
* @param newMessagesCount
|
|
53
|
-
*/
|
|
54
|
-
private async storeGetInboxMessagesRequestParams(next: string, newMessagesCount: number): Promise<void> {
|
|
55
|
-
this.dateModule.date = new Date();
|
|
56
|
-
await this.data.setInboxLastRequestTime(this.dateModule.getUtcTimestamp());
|
|
57
|
-
|
|
58
|
-
await this.data.setInboxLastRequestCode(next);
|
|
59
|
-
await this.data.setInboxNewMessagesCount(newMessagesCount);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* Put loaded messages. Add delete status to loaded messages if this status set locally.
|
|
64
|
-
* @param messages
|
|
65
|
-
*/
|
|
66
|
-
private async putServerMessages(messages: Array<IInboxMessage>): Promise<Array<string>> {
|
|
67
|
-
const putTransactions = messages.map(async (message: IInboxMessage) => {
|
|
68
|
-
const localMessage = await this.storage.get<IInboxMessage, object>(this.storeName, message.inbox_id, {});
|
|
69
|
-
if ('status' in localMessage) {
|
|
70
|
-
message.status = localMessage.status;
|
|
71
|
-
}
|
|
72
|
-
return this.putMessage(message);
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
return Promise.all(putTransactions);
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* Create or update inbox message
|
|
80
|
-
*/
|
|
81
|
-
putMessage(message: IInboxMessage): Promise<string> {
|
|
82
|
-
return <Promise<string>> this.storage.put(this.storeName, message);
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* Create or update messages pack
|
|
87
|
-
* @param messages
|
|
88
|
-
*/
|
|
89
|
-
putBulkMessages(messages: Array<IInboxMessage>): Promise<Array<string>> {
|
|
90
|
-
const putTransactions = messages.map((message) => this.putMessage(message));
|
|
91
|
-
return Promise.all(putTransactions);
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* Delete messages by codes
|
|
96
|
-
* @param codes
|
|
97
|
-
*/
|
|
98
|
-
deleteMessages(codes: Array<string>): Promise<Array<void>> {
|
|
99
|
-
const deleteTransactions = codes.map((code) => this.storage.delete(this.storeName, code));
|
|
100
|
-
return Promise.all(deleteTransactions);
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
/**
|
|
104
|
-
* Delete expired by removal time messages
|
|
105
|
-
*/
|
|
106
|
-
async deleteExpiredMessages(): Promise<Array<void>> {
|
|
107
|
-
this.dateModule.date = new Date();
|
|
108
|
-
const upperBound = this.dateModule.getTimestamp().toString();
|
|
109
|
-
const allMessages = await this.storage
|
|
110
|
-
.getAll<IInboxMessage>(this.storeName);
|
|
111
|
-
const codesToDelete = allMessages
|
|
112
|
-
.filter((msg: IInboxMessage) => msg.rt < upperBound)
|
|
113
|
-
.map((msg) => msg.inbox_id);
|
|
114
|
-
return this.deleteMessages(codesToDelete);
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
/**
|
|
118
|
-
* Get message by code
|
|
119
|
-
* @param code - inbox_id
|
|
120
|
-
*/
|
|
121
|
-
getMessage(code: string): Promise<IInboxMessage> {
|
|
122
|
-
return this.storage.get<IInboxMessage, IInboxMessage>(this.storeName, code);
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
/**
|
|
126
|
-
* Get all read messages
|
|
127
|
-
*/
|
|
128
|
-
async getReadOpenMessages(): Promise<Array<IInboxMessage>> {
|
|
129
|
-
const allMessages = await this.storage
|
|
130
|
-
.getAll<IInboxMessage>(this.storeName);
|
|
131
|
-
return allMessages
|
|
132
|
-
.filter((msg: IInboxMessage) => <TInboxMessageStatusRead>msg.status === 2 || <TInboxMessageStatusOpen>msg.status === 3);
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
/**
|
|
136
|
-
* Get all unread messages
|
|
137
|
-
*/
|
|
138
|
-
async getDeliveredMessages(): Promise<Array<IInboxMessage>> {
|
|
139
|
-
const allMessages = await this.storage
|
|
140
|
-
.getAll<IInboxMessage>(this.storeName);
|
|
141
|
-
return allMessages
|
|
142
|
-
.filter((msg: IInboxMessage) => <TInboxMessageStatusDelivered>msg.status === 1);
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
/**
|
|
146
|
-
* All messages count
|
|
147
|
-
*/
|
|
148
|
-
async messagesCount(): Promise<number> {
|
|
149
|
-
return this.storage.count(this.storeName);
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
/**
|
|
153
|
-
* Get count of messages with status "Delivered"
|
|
154
|
-
*/
|
|
155
|
-
async getDeliveredMessagesCount(): Promise<number> {
|
|
156
|
-
const deliveredStatus: TInboxMessageStatusDelivered = 1;
|
|
157
|
-
const statusIndexName: TInboxMessagesIDBStatusIndex = 'status';
|
|
158
|
-
return this.storage
|
|
159
|
-
.countByIndex(this.storeName, statusIndexName, deliveredStatus);
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
/**
|
|
163
|
-
* Get count of messages with status "Read"
|
|
164
|
-
*/
|
|
165
|
-
async getReadMessagesCount(): Promise<number> {
|
|
166
|
-
const readStatus: TInboxMessageStatusRead = 2;
|
|
167
|
-
const statusIndexName: TInboxMessagesIDBStatusIndex = 'status';
|
|
168
|
-
return this.storage
|
|
169
|
-
.countByIndex(this.storeName, statusIndexName, readStatus);
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
/**
|
|
173
|
-
* Get count of messages with status "Delivered" and "Read"
|
|
174
|
-
*/
|
|
175
|
-
async getDeliveredReadMessagesCount(): Promise<number> {
|
|
176
|
-
const [readStatus, openStatus]: TReadInboxMessagesStatusRange = [2, 3];
|
|
177
|
-
const keyRange = IDBKeyRange.bound(readStatus, openStatus);
|
|
178
|
-
const statusIndexName: TInboxMessagesIDBStatusIndex = 'status';
|
|
179
|
-
|
|
180
|
-
return this.storage.countByIndex(this.storeName, statusIndexName, keyRange);
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
/**
|
|
184
|
-
* Load messages and sync with locally
|
|
185
|
-
*/
|
|
186
|
-
async updateMessages(): Promise<void> {
|
|
187
|
-
const response = await this.getInboxMessages();
|
|
188
|
-
await this.deleteExpiredMessages();
|
|
189
|
-
if (response.deleted) {
|
|
190
|
-
await this.deleteMessages(response.deleted); // deleted from cp
|
|
191
|
-
}
|
|
192
|
-
await this.putServerMessages(response.messages);
|
|
193
|
-
|
|
194
|
-
this.eventBus.dispatchEvent('update-inbox-messages', {
|
|
195
|
-
messages: new InboxMessagesPublic(
|
|
196
|
-
this.data,
|
|
197
|
-
this.api,
|
|
198
|
-
this,
|
|
199
|
-
),
|
|
200
|
-
});
|
|
201
|
-
}
|
|
202
|
-
}
|
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
// Action types
|
|
2
|
-
export type TInboxActionLink = 1;
|
|
3
|
-
export type TInboxActionRichMedia = 2;
|
|
4
|
-
export type TInboxActionType = TInboxActionLink | TInboxActionRichMedia; // https://docs.pushwoosh.com/platform-docs/api-reference/message-inbox#getinboxmessages
|
|
5
|
-
|
|
6
|
-
// Statuses
|
|
7
|
-
export type TInboxMessageStatusDelivered = 1;
|
|
8
|
-
export type TInboxMessageStatusRead = 2; // set on message in viewport
|
|
9
|
-
export type TInboxMessageStatusOpen = 3; // set on message click
|
|
10
|
-
export type TInboxMessageStatusDeleted = 4; // set on message delete or expiry removal time
|
|
11
|
-
export type TInboxMessageStatus =
|
|
12
|
-
| TInboxMessageStatusDelivered
|
|
13
|
-
| TInboxMessageStatusRead
|
|
14
|
-
| TInboxMessageStatusOpen
|
|
15
|
-
| TInboxMessageStatusDeleted;
|
|
16
|
-
export type TReadInboxMessagesStatusRange = [TInboxMessageStatusRead, TInboxMessageStatusOpen]; // all inbox read messages
|
|
17
|
-
|
|
18
|
-
// Message
|
|
19
|
-
export interface IInboxMessageActionParams {
|
|
20
|
-
l?: string | null;
|
|
21
|
-
rm?: string;
|
|
22
|
-
h?: string;
|
|
23
|
-
r?: string;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export interface IInboxMessage {
|
|
27
|
-
inbox_id: string; // inbox message id
|
|
28
|
-
order: string; // id for ordering in inbox
|
|
29
|
-
rt: string; // timestamp. Remove date. UTC
|
|
30
|
-
send_date: string; // timestamp. UTC
|
|
31
|
-
title: string;
|
|
32
|
-
image: string;
|
|
33
|
-
text: string;
|
|
34
|
-
action_type: TInboxActionType;
|
|
35
|
-
action_params: string; // json string with IInboxMessageActionParams
|
|
36
|
-
status: TInboxMessageStatus;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
// Inbox API types
|
|
40
|
-
export interface IGetInboxMessagesRequest {
|
|
41
|
-
application: string; // application code
|
|
42
|
-
userId: string; // use hwid or other custom string if no userId
|
|
43
|
-
hwid: string;
|
|
44
|
-
last_code: string; // For pagination purpose. "next" parameter from response. For first request send empty string
|
|
45
|
-
count?: number; // optional, default messages count on page
|
|
46
|
-
last_request_time: number; // for update new messages counter. UTC
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
export interface IGetInboxMessagesResponse {
|
|
50
|
-
messages: Array<IInboxMessage>;
|
|
51
|
-
next: string; // pagination code
|
|
52
|
-
deleted: Array<string>; // array of notifications codes deleted from cp
|
|
53
|
-
new_inbox: number; // inbox messages created since last request time
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
export interface IInboxStatusRequest {
|
|
57
|
-
userId: string; // use hwid or other custom string if no userId
|
|
58
|
-
hwid: string; // hwid
|
|
59
|
-
application: string; // app code
|
|
60
|
-
inbox_code: string; // order. Ugly logic for fast development.
|
|
61
|
-
time: number; // timestamp utc
|
|
62
|
-
status: TInboxMessageStatus;
|
|
63
|
-
hash?: string; // ??
|
|
64
|
-
device_type: number; // platform type from Pushwoosh system
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
export type TGetInboxMessagesMethod = 'getInboxMessages';
|
|
68
|
-
export type TInboxStatusMethod = 'inboxStatus';
|
|
69
|
-
|
|
70
|
-
// IndexedDB keys/indexes
|
|
71
|
-
export type TInboxMessagesIDBKeyPath = 'inbox_id';
|
|
72
|
-
export type TInboxMessagesIDBStatusIndex = 'status';
|
|
73
|
-
export type TInboxMessagesIDBRemovalTimeIndex = 'rt';
|
|
74
|
-
|
|
75
|
-
// Public Interface
|
|
76
|
-
|
|
77
|
-
export type TInboxMessageTypePlain = 0;
|
|
78
|
-
export type TInboxMessageTypeRichmedia = 1;
|
|
79
|
-
export type TInboxMessageTypeURL = 2;
|
|
80
|
-
export type TInboxMessageTypeDeeplink = 3;
|
|
81
|
-
export type TInboxMessageType = // depend from action_params
|
|
82
|
-
| TInboxMessageTypePlain
|
|
83
|
-
| TInboxMessageTypeRichmedia
|
|
84
|
-
| TInboxMessageTypeURL
|
|
85
|
-
| TInboxMessageTypeDeeplink;
|
|
86
|
-
|
|
87
|
-
export type TInboxDefaultLink = '/';
|
|
88
|
-
|
|
89
|
-
export interface IInboxMessagePublic {
|
|
90
|
-
code: string; // inbox_id
|
|
91
|
-
title: string; // title
|
|
92
|
-
message: string; // body
|
|
93
|
-
imageUrl: string; // image
|
|
94
|
-
sendDate: string; // send_date
|
|
95
|
-
type: TInboxMessageType; // depend from action_params
|
|
96
|
-
link: string | TInboxDefaultLink; // url or deeplink.
|
|
97
|
-
isRead: boolean; // true if status read or open
|
|
98
|
-
isActionPerformed: boolean; // true if status open
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
export interface IInboxMessages {
|
|
102
|
-
messagesWithNoActionPerformedCount(): Promise<number>; // opened messages count
|
|
103
|
-
unreadMessagesCount(): Promise<number>; // read messages count
|
|
104
|
-
messagesCount(): Promise<number>; // all messages count
|
|
105
|
-
loadMessages(): Promise<Array<IInboxMessagePublic>>; // all messages
|
|
106
|
-
readMessagesWithCodes(codes: Array<string>): Promise<void>; // set read status to messages by code
|
|
107
|
-
performActionForMessageWithCode(code: string): Promise<void>; // call message action. Set open status to messages
|
|
108
|
-
deleteMessagesWithCodes(codes: Array<string>): Promise<void>; // Set delete status to messages by code
|
|
109
|
-
|
|
110
|
-
publicMessageBuilder(message: IInboxMessage): Promise<IInboxMessagePublic>; // build public inbox message from base inbox message
|
|
111
|
-
}
|
|
@@ -1,216 +0,0 @@
|
|
|
1
|
-
import { type IInboxMessage, type TInboxActionLink, type TInboxMessageStatusDelivered } from './InboxMessages.types';
|
|
2
|
-
import {
|
|
3
|
-
type IChromeNotificationPayload,
|
|
4
|
-
type INotificationButton,
|
|
5
|
-
type INotificationOptionsPayload,
|
|
6
|
-
type INotificationPayload,
|
|
7
|
-
type INotificationPayloadInboxParams,
|
|
8
|
-
type IShowNotificationOptions,
|
|
9
|
-
} from './NotificationPayload.types';
|
|
10
|
-
import { parseSerializedNotificationParams } from '../core/functions';
|
|
11
|
-
import { unescape } from '../helpers/unescape';
|
|
12
|
-
import { Data } from '../modules/Data/Data';
|
|
13
|
-
import DateModule from '../modules/DateModule';
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Build notification payload for different usage (show notification, use in sdk, inbox messages)
|
|
17
|
-
*/
|
|
18
|
-
export default class NotificationPayload {
|
|
19
|
-
payload: INotificationPayload;
|
|
20
|
-
data: Data;
|
|
21
|
-
code: string;
|
|
22
|
-
dateModule: DateModule;
|
|
23
|
-
|
|
24
|
-
constructor(
|
|
25
|
-
payload: INotificationPayload | IChromeNotificationPayload,
|
|
26
|
-
data: Data = new Data(),
|
|
27
|
-
dateModule: DateModule = new DateModule(),
|
|
28
|
-
) {
|
|
29
|
-
// Set payload
|
|
30
|
-
if ('data' in payload) {
|
|
31
|
-
const chromePayload = <IChromeNotificationPayload>payload;
|
|
32
|
-
this.payload = chromePayload.data;
|
|
33
|
-
} else {
|
|
34
|
-
this.payload = <INotificationPayload>payload;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
this.data = data;
|
|
38
|
-
this.code = `notificationCode-${Date.now()}-${Math.random().toString(16).slice(2, 10)}`;
|
|
39
|
-
this.dateModule = dateModule;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
async getIcon(): Promise<string> {
|
|
43
|
-
return this.payload.i || await this.data.getDefaultNotificationImage();
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
async getTitle(): Promise<string> {
|
|
47
|
-
return this.payload.header || await this.data.getDefaultNotificationTitle();
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
get silent(): boolean {
|
|
51
|
-
return Boolean(this.payload.silent);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
get body(): string {
|
|
55
|
-
return this.payload.body;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
get messageHash(): string {
|
|
59
|
-
return this.payload.p || '';
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
get metaData(): { [key: string]: any } {
|
|
63
|
-
return this.payload.md
|
|
64
|
-
? parseSerializedNotificationParams(this.payload.md)
|
|
65
|
-
: {};
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
get image(): string {
|
|
69
|
-
return this.payload.image || '';
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
get buttons(): Array<INotificationButton> {
|
|
73
|
-
return this.payload.buttons
|
|
74
|
-
? parseSerializedNotificationParams(this.payload.buttons)
|
|
75
|
-
: [];
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
get customData(): { [key: string]: any } {
|
|
79
|
-
return this.payload.u
|
|
80
|
-
? parseSerializedNotificationParams(this.payload.u)
|
|
81
|
-
: {};
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
get campaignCode(): string {
|
|
85
|
-
return this.payload.pwcid || '';
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
get link(): string {
|
|
89
|
-
return this.payload.l ? unescape(this.payload.l) : '/';
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
get inboxId(): string {
|
|
93
|
-
return this.payload.pw_inbox || '';
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
get inboxParams(): INotificationPayloadInboxParams {
|
|
97
|
-
// Parse inbox params
|
|
98
|
-
if (this.payload.inbox_params) {
|
|
99
|
-
return parseSerializedNotificationParams(this.payload.inbox_params);
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
return {};
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
get inboxRemovalTime(): string {
|
|
106
|
-
if (this.inboxParams && this.inboxParams.rt) {
|
|
107
|
-
return this.inboxParams.rt;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
this.dateModule.date = new Date();
|
|
111
|
-
this.dateModule.addDays(1); // one day removal time
|
|
112
|
-
return this.dateModule.getUtcTimestamp().toString();
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
async getInboxImage(): Promise<string> {
|
|
116
|
-
if (this.inboxParams && this.inboxParams.image) {
|
|
117
|
-
return this.inboxParams.image;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
return '';
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
get rootParams(): { [key: string]: any } {
|
|
124
|
-
const {
|
|
125
|
-
body: _body,
|
|
126
|
-
p: _p,
|
|
127
|
-
header: _header,
|
|
128
|
-
i: _i,
|
|
129
|
-
u: _u,
|
|
130
|
-
l: _l,
|
|
131
|
-
pwcid: _pwcid,
|
|
132
|
-
image: _image,
|
|
133
|
-
buttons: _buttons,
|
|
134
|
-
pw_inbox: _pw_inbox,
|
|
135
|
-
inbox_params: _inbox_params,
|
|
136
|
-
...rootParams
|
|
137
|
-
} = this.payload;
|
|
138
|
-
return rootParams;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
async getNotificationOptionsPayload(): Promise<INotificationOptionsPayload> {
|
|
142
|
-
const title = await this.getTitle();
|
|
143
|
-
const icon = await this.getIcon();
|
|
144
|
-
|
|
145
|
-
return {
|
|
146
|
-
...this.rootParams,
|
|
147
|
-
body: this.body,
|
|
148
|
-
title,
|
|
149
|
-
icon,
|
|
150
|
-
image: this.image,
|
|
151
|
-
buttons: this.buttons,
|
|
152
|
-
customData: this.customData,
|
|
153
|
-
metaData: this.metaData,
|
|
154
|
-
campaignCode: this.campaignCode,
|
|
155
|
-
openUrl: this.link,
|
|
156
|
-
messageHash: this.messageHash,
|
|
157
|
-
};
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
async getShowNotificationOptions(): Promise<IShowNotificationOptions> {
|
|
161
|
-
const icon = await this.getIcon();
|
|
162
|
-
|
|
163
|
-
const buttons = this.buttons.map((button: INotificationButton, key: number) => {
|
|
164
|
-
button.action = `action-${key}`;
|
|
165
|
-
return button;
|
|
166
|
-
});
|
|
167
|
-
|
|
168
|
-
return {
|
|
169
|
-
renotify: true,
|
|
170
|
-
...this.rootParams,
|
|
171
|
-
body: this.body,
|
|
172
|
-
icon,
|
|
173
|
-
tag: JSON.stringify({
|
|
174
|
-
url: this.link,
|
|
175
|
-
messageHash: this.messageHash,
|
|
176
|
-
customData: this.customData,
|
|
177
|
-
metaData: this.metaData,
|
|
178
|
-
}),
|
|
179
|
-
data: {
|
|
180
|
-
code: this.code,
|
|
181
|
-
buttons,
|
|
182
|
-
image: this.image,
|
|
183
|
-
campaignCode: this.campaignCode,
|
|
184
|
-
inboxId: this.inboxId,
|
|
185
|
-
},
|
|
186
|
-
silent: this.silent,
|
|
187
|
-
actions: buttons,
|
|
188
|
-
image: this.image,
|
|
189
|
-
buttons, // old notification api artifact
|
|
190
|
-
};
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
async getInboxMessage(): Promise<IInboxMessage> {
|
|
194
|
-
this.dateModule.date = new Date();
|
|
195
|
-
const sendDate = this.dateModule.getTimestamp().toString();
|
|
196
|
-
const title = this.payload.header || '';
|
|
197
|
-
const image = await this.getInboxImage();
|
|
198
|
-
const actionType: TInboxActionLink = 1;
|
|
199
|
-
const status: TInboxMessageStatusDelivered = 1;
|
|
200
|
-
|
|
201
|
-
return {
|
|
202
|
-
title,
|
|
203
|
-
image,
|
|
204
|
-
status,
|
|
205
|
-
order: this.dateModule.getInboxFakeOrder(),
|
|
206
|
-
inbox_id: this.inboxId,
|
|
207
|
-
send_date: sendDate,
|
|
208
|
-
rt: this.inboxRemovalTime,
|
|
209
|
-
text: this.body,
|
|
210
|
-
action_type: actionType,
|
|
211
|
-
action_params: JSON.stringify({
|
|
212
|
-
l: this.link,
|
|
213
|
-
}),
|
|
214
|
-
};
|
|
215
|
-
}
|
|
216
|
-
}
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
export interface INotificationPayloadInboxParams {
|
|
2
|
-
image?: string; // custom icon for inbox message
|
|
3
|
-
rt?: string; // removal time. YYYY-MM-DD HH:mm
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
export interface INotificationPayload {
|
|
7
|
-
body: string; // message text
|
|
8
|
-
p?: string; // message hash. Not required for send message on concrete device.
|
|
9
|
-
silent?: string; // is it silent push notifications (no need to show it to user PUSH-19207)
|
|
10
|
-
header?: string; // message title
|
|
11
|
-
i?: string; // icon
|
|
12
|
-
u?: string; // custom data json string
|
|
13
|
-
md?: string; // meta data json string
|
|
14
|
-
l?: string; // deep link or URL
|
|
15
|
-
pwcid?: string; // campaign id
|
|
16
|
-
image?: string; // chrome big image
|
|
17
|
-
buttons?: string; // button json string. XMPP Chrome Sender payload contains buttons as string
|
|
18
|
-
pw_inbox?: string; // inbox code
|
|
19
|
-
inbox_params?: string; // inbox params json INotificationPayloadInboxParams
|
|
20
|
-
[key: string]: any; // root params
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export interface IChromeNotificationPayload {
|
|
24
|
-
data: INotificationPayload;
|
|
25
|
-
from: string; // ??
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export interface INotificationButton {
|
|
29
|
-
title: string;
|
|
30
|
-
action?: string;
|
|
31
|
-
url?: string;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export interface INotificationOptionsPayload {
|
|
35
|
-
body: string;
|
|
36
|
-
title: string;
|
|
37
|
-
icon: string;
|
|
38
|
-
image: string;
|
|
39
|
-
buttons: Array<INotificationButton>;
|
|
40
|
-
customData: { [key: string]: any };
|
|
41
|
-
metaData: { [key: string]: any };
|
|
42
|
-
campaignCode: string;
|
|
43
|
-
openUrl: string;
|
|
44
|
-
[key: string]: any;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
export interface IShowNotificationOptionsData {
|
|
48
|
-
code: string; // message code
|
|
49
|
-
buttons: Array<INotificationButton>;
|
|
50
|
-
image: string;
|
|
51
|
-
campaignCode: string;
|
|
52
|
-
inboxId: string;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
export interface IShowNotificationOptions {
|
|
56
|
-
body: string;
|
|
57
|
-
icon: string;
|
|
58
|
-
tag: string;
|
|
59
|
-
data: IShowNotificationOptionsData;
|
|
60
|
-
actions: Array<INotificationButton>;
|
|
61
|
-
image: string;
|
|
62
|
-
badge?: string; // android chrome badge icon,
|
|
63
|
-
silent?: boolean; // is it silent push notifications (no need to show it to user PUSH-19207)
|
|
64
|
-
[key: string]: any;
|
|
65
|
-
}
|