web-push-notifications 3.91.1 → 3.95.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/CHANGELOG.md +85 -0
- package/core/Pushwoosh.d.ts +13 -0
- package/core/__tests__/loadWebPopupsWidget.test.d.ts +1 -0
- package/core/__tests__/reportPushPermissionChange.test.d.ts +1 -0
- package/core/__tests__/settlesWithin.test.d.ts +1 -0
- package/core/constants.d.ts +3 -0
- package/core/events.types.d.ts +3 -0
- package/core/functions.d.ts +2 -0
- package/core/resolveInitParams.d.ts +9 -1
- package/modules/Api/Api.d.ts +10 -1
- package/modules/ApiClient/ApiClient.types.d.ts +8 -2
- package/modules/Data/Data.d.ts +5 -0
- package/modules/FeatureFlags/FeatureFlag.d.ts +12 -0
- package/modules/FeatureFlags/FeatureFlags.d.ts +57 -0
- package/modules/FeatureFlags/FeatureFlags.types.d.ts +19 -0
- package/modules/FeatureFlags/__tests__/FeatureFlags.test.d.ts +1 -0
- package/modules/FeatureFlags/featureFlagsUrl.d.ts +1 -0
- package/modules/InboxMessagesPublic.d.ts +3 -1
- package/npm.js +1 -1
- package/npm.js.map +1 -1
- package/package.json +1 -1
- package/service-worker.js +1 -1
- package/service-worker.js.map +1 -1
- package/services/PushService/__tests__/pushPermissionStatus.test.d.ts +1 -0
- package/services/PushService/pushPermissionStatus.d.ts +3 -0
- package/widget-inbox.js +1 -1
- package/widget-inbox.js.map +1 -1
- package/widget-subscription-button.js.map +1 -1
- package/widget-web-popups.js +1 -1
- package/widget-web-popups.js.map +1 -1
- package/widgets/WebPopups/WebPopupsWidget.d.ts +6 -2
- package/widgets/WebPopups/__tests__/WebPopupsWidget.test.d.ts +1 -0
- package/widgets/WebPopups/types.d.ts +2 -0
package/CHANGELOG.md
CHANGED
|
@@ -9,6 +9,91 @@ the same mapping is in the
|
|
|
9
9
|
Entries for 3.71.0 through 3.78.0 are grouped under version headings, which is how this file was
|
|
10
10
|
kept before the version moved to the tag; earlier versions live only in the git history.
|
|
11
11
|
|
|
12
|
+
## fix(push): report permission changes with registerDevice
|
|
13
|
+
|
|
14
|
+
- A refusal in the permission dialog, or a permission change reported by `navigator.permissions`, now goes
|
|
15
|
+
to the server as a registerDevice without a push token instead of an extra `applicationOpen`, which the
|
|
16
|
+
server counted as one more app open. It is sent only for a device without a push token, after a
|
|
17
|
+
subscription in flight has been answered, and once per status: the last status the server got is kept
|
|
18
|
+
in `localStorage` (`reportedPushPermissionStatus`), so a page load does not repeat it.
|
|
19
|
+
- A permission revoked or reset in the site settings while the page is open drops the subscription right
|
|
20
|
+
away (as the next init would) and reports the new status; after init the status is reported too, so a
|
|
21
|
+
revoke noticed on reload, or a grant without a subscription, no longer waits for the hourly
|
|
22
|
+
`applicationOpen`.
|
|
23
|
+
- A permission granted in the dialog is reported only by the subscription's own registerDevice: the
|
|
24
|
+
`change` event that fires first waits for the subscription instead of sending a tokenless report that
|
|
25
|
+
could land after it and clear the token. It waits at most 10 s, and so does the re-subscribe after a
|
|
26
|
+
grant in the site settings and the unsubscribe after a revoke. A subscription, unsubscribe or
|
|
27
|
+
registerDevice that hangs is waited for once: the next permission change on the page is reported
|
|
28
|
+
right away (a revoke as a tokenless registerDevice, the dead token may be cleared), and a report that
|
|
29
|
+
would overtake a hanging registerDevice is dropped rather than risk clearing its token. A grant in the site settings re-subscribes a device the SDK
|
|
30
|
+
dropped on a revoke (not one the user unsubscribed manually), as the next init would.
|
|
31
|
+
- A reload after a permission change sends one `unregisterDevice` instead of two: init no longer asks the
|
|
32
|
+
server whether the device it has just unregistered still has a token.
|
|
33
|
+
|
|
34
|
+
## feat(push): report push permission status
|
|
35
|
+
|
|
36
|
+
- `applicationOpen` and `registerDevice` carry `push_permission_status`: `not_determined`, `granted_explicit`,
|
|
37
|
+
`denied`, or `unsupported` when the browser has no Push API (iOS Safari outside a home screen app).
|
|
38
|
+
The legacy Safari driver reports its own permission the same way.
|
|
39
|
+
- An `applicationOpen` goes right after the permission dialog closes, past the hourly throttle, and on a
|
|
40
|
+
change of the notifications permission where `navigator.permissions` reports one (Chromium, Firefox).
|
|
41
|
+
|
|
42
|
+
## fix(feature-flags): serve the cached flags from onReady
|
|
43
|
+
|
|
44
|
+
- The flags cache is read from IndexedDB before `ready` fires, so `get()`/`isEnabled()` called in
|
|
45
|
+
`onReady` return the cached flags instead of `null`.
|
|
46
|
+
- A flag read before the cache finished loading is followed by an update-listener call once the cache
|
|
47
|
+
is there, also when the page-load refresh is skipped (cache younger than 15 minutes) or answers
|
|
48
|
+
`not_modified`.
|
|
49
|
+
|
|
50
|
+
## feat(feature-flags): add the feature flags client
|
|
51
|
+
|
|
52
|
+
- `Pushwoosh.featureFlags` reads the application's feature flags that the server evaluates for the
|
|
53
|
+
device: `get(key)` with typed getters and defaults, `isEnabled`, `refresh()`, update listeners and
|
|
54
|
+
`logImpression(key)` (`PW_FeatureFlagImpression`).
|
|
55
|
+
- Nothing goes to the network until the site first calls the flags API on a page; sites that do not
|
|
56
|
+
use feature flags send no requests.
|
|
57
|
+
- Flags come from `/api/v2/device-api/getFeatureFlags` on the current API host, are cached in
|
|
58
|
+
IndexedDB per User ID for up to 24 hours with an etag, and refresh on the first use of a page when
|
|
59
|
+
the cache is older than 15 minutes, hourly while the page is open, after the first device
|
|
60
|
+
registration and right after the User ID changes.
|
|
61
|
+
|
|
62
|
+
## fix(web-sdk): take legacy panel modules from web_sdk_modules
|
|
63
|
+
|
|
64
|
+
- A legacy (snippet) application now gets its panel `inboxWidget`/`webPopups` from the
|
|
65
|
+
`web_sdk_modules` feature, and only those two keys are taken from it. `web_sdk` keeps meaning
|
|
66
|
+
"panel-managed", so the Control Panel Subscription Prompt stays on for a legacy site that switched
|
|
67
|
+
a module in the panel.
|
|
68
|
+
|
|
69
|
+
## fix(inbox): open the web popup content an inbox message points to
|
|
70
|
+
|
|
71
|
+
- Tapping an App Inbox message that opens a web popup now shows it when the message carries a popup
|
|
72
|
+
content code (the inbox wizard and the journey Send Inbox point pick a content, not a campaign).
|
|
73
|
+
Campaign codes work as before; a content shown this way records no popup campaign stats, the tap is
|
|
74
|
+
counted as the inbox open.
|
|
75
|
+
- The web popups bundle is fetched on such a tap when the site did not load it (no active popup
|
|
76
|
+
campaigns); `webPopups.enable: false` still keeps it off. If the popup cannot be shown, the message
|
|
77
|
+
link is followed as before.
|
|
78
|
+
- `moduleRegistry.webPopups.show(code)` accepts a popup content code as well.
|
|
79
|
+
|
|
80
|
+
## feat(web-popups): take the web popups switch from the panel
|
|
81
|
+
|
|
82
|
+
- An application in the panel-managed mode gets `webPopups.enable` from the Control Panel, so support
|
|
83
|
+
can switch web popups off for a site without a snippet change; `colorScheme` and `autoShow` stay as
|
|
84
|
+
the snippet set them.
|
|
85
|
+
- `webPopups.enable: false` and `inboxWidget.enable: false` now also stop a widget an npm site
|
|
86
|
+
constructs itself, not only the CDN loader.
|
|
87
|
+
- A missing inbox trigger element is reported by its id, with where to change it.
|
|
88
|
+
|
|
89
|
+
## feat(inbox): take the inbox widget from the panel in managed mode
|
|
90
|
+
|
|
91
|
+
- An application in the panel-managed mode gets `inboxWidget` from the Control Panel: its keys
|
|
92
|
+
override the snippet ones, and keys the panel does not carry (usually `triggerId`, `appendTo`) stay
|
|
93
|
+
as written in the snippet. Legacy mode is unchanged.
|
|
94
|
+
- An inbox switched on only in the panel now registers the device before the first inbox sync, as one
|
|
95
|
+
enabled in the snippet always did.
|
|
96
|
+
|
|
12
97
|
## perf(npm): take preact from the consumer instead of bundling it per widget
|
|
13
98
|
|
|
14
99
|
- The npm `widget-inbox`, `widget-subscription` and `widget-web-popups` builds import `preact`,
|
package/core/Pushwoosh.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { type EventHandlerMap, type EventName } from './events.types';
|
|
|
2
2
|
import { type IInitParams, type IModuleRegistry, type PWInput } from './Pushwoosh.types';
|
|
3
3
|
import { Api } from '../modules/Api/Api';
|
|
4
4
|
import { Data } from '../modules/Data/Data';
|
|
5
|
+
import { FeatureFlags } from '../modules/FeatureFlags/FeatureFlags';
|
|
5
6
|
import InboxMessagesPublic from '../modules/InboxMessagesPublic';
|
|
6
7
|
import { PlatformChecker } from '../modules/PlatformChecker';
|
|
7
8
|
import { type IPushService } from '../services/PushService/PushService.types';
|
|
@@ -19,10 +20,16 @@ export declare class Pushwoosh {
|
|
|
19
20
|
platformChecker: PlatformChecker;
|
|
20
21
|
private isPushDisabled;
|
|
21
22
|
private isInitAborted;
|
|
23
|
+
private isPushPermissionWatched;
|
|
24
|
+
private subscriptionInFlight;
|
|
25
|
+
private readonly waitForPermissionWork;
|
|
22
26
|
pwinbox: InboxMessagesPublic;
|
|
23
27
|
private inboxModel;
|
|
24
28
|
moduleRegistry: IModuleRegistry;
|
|
29
|
+
readonly featureFlags: FeatureFlags;
|
|
30
|
+
widgetLoader?: (widgetName: string) => Promise<boolean>;
|
|
25
31
|
constructor();
|
|
32
|
+
private loadWebPopupsWidget;
|
|
26
33
|
/**
|
|
27
34
|
* Add Web SDK Event Handler.
|
|
28
35
|
* Alias to addEventHandler method of EventBus module.
|
|
@@ -104,6 +111,7 @@ export declare class Pushwoosh {
|
|
|
104
111
|
* @returns {Promise<void>}
|
|
105
112
|
*/
|
|
106
113
|
subscribe(isForceSubscribe?: boolean): Promise<void>;
|
|
114
|
+
private runSubscribe;
|
|
107
115
|
/**
|
|
108
116
|
* Unsubscribe device.
|
|
109
117
|
* @returns {Promise<void>}
|
|
@@ -201,6 +209,11 @@ export declare class Pushwoosh {
|
|
|
201
209
|
* @returns {Promise<void>}
|
|
202
210
|
*/
|
|
203
211
|
private open;
|
|
212
|
+
private getPushPermissionStatus;
|
|
213
|
+
private reportPushPermissionChange;
|
|
214
|
+
private dropRevokedSubscription;
|
|
215
|
+
private reportPushPermissionChangeInBackground;
|
|
216
|
+
private watchPushPermission;
|
|
204
217
|
private sendData;
|
|
205
218
|
private loadConfig;
|
|
206
219
|
private applyServerInitParams;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/core/constants.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ export declare const DEFAULT_NOTIFICATION_IMAGE = "https://cp.pushwoosh.com/img/
|
|
|
7
7
|
export declare const KEY_SHOW_SUBSCRIBE_WIDGET = "WIDGET_SHOWED";
|
|
8
8
|
export declare const KEY_CLICK_SUBSCRIBE_WIDGET = "WIDGET_CLICKED";
|
|
9
9
|
export declare const KEY_DEVICE_REGISTRATION_STATUS: string;
|
|
10
|
+
export declare const KEY_REPORTED_PUSH_PERMISSION_STATUS: string;
|
|
10
11
|
export declare const KEY_SAFARI_PREVIOUS_PERMISSION = "safariPreviousPermission";
|
|
11
12
|
export declare const MANUAL_SET_LOGGER_LEVEL = "PW_SET_LOGGER_LEVEL";
|
|
12
13
|
export declare const DEVICE_REGISTRATION_STATUS_REGISTERED: string;
|
|
@@ -42,3 +43,5 @@ export declare const HWID_UNAVAILABLE_MESSAGE: string;
|
|
|
42
43
|
export declare const IDENTITY_UNAVAILABLE_MESSAGE: string;
|
|
43
44
|
export declare const API_STATUS_CODE_INVALID_APPLICATION = 210;
|
|
44
45
|
export declare const FATAL_API_STATUS_CODES: number[];
|
|
46
|
+
export declare const WIDGET_LOAD_TIMEOUT_MS = 10000;
|
|
47
|
+
export declare const SUBSCRIPTION_WAIT_TIMEOUT_MS: number;
|
package/core/events.types.d.ts
CHANGED
|
@@ -8,6 +8,9 @@ export interface EventHandlerMap {
|
|
|
8
8
|
}>>;
|
|
9
9
|
'communication-disabled': EventHandler<EventPayload<Record<string, never>>>;
|
|
10
10
|
register: EventHandler<EventPayload<Record<string, never>>>;
|
|
11
|
+
'change-user-id': EventHandler<EventPayload<{
|
|
12
|
+
userId: string;
|
|
13
|
+
}>>;
|
|
11
14
|
unregister: EventHandler<EventPayload<Record<string, never>>>;
|
|
12
15
|
'show-subscription-widget': EventHandler<EventPayload<Record<string, never>>>;
|
|
13
16
|
'hide-subscription-widget': EventHandler<EventPayload<Record<string, never>>>;
|
package/core/functions.d.ts
CHANGED
|
@@ -3,3 +3,5 @@ export declare function getVersion(): string;
|
|
|
3
3
|
export declare function parseSerializedNotificationParams(param: any, defaultValue?: any): any;
|
|
4
4
|
export declare function v4(): `${string}-${string}-${string}-${string}-${string}`;
|
|
5
5
|
export declare const isFunction: (value: any) => value is ((...args: any[]) => any);
|
|
6
|
+
export declare function settlesWithin(promise: Promise<unknown>, timeoutMs: number): Promise<boolean>;
|
|
7
|
+
export declare function createStuckAwareWait(timeoutMs: number): (promise: Promise<unknown>) => Promise<boolean>;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import type { IInitParams, ISubscribeWidget } from './Pushwoosh.types';
|
|
1
|
+
import type { IInboxWidget, IInitParams, ISubscribeWidget } from './Pushwoosh.types';
|
|
2
2
|
import type { ISubscriptionWidgetParams } from '../widgets/SubscriptionWidget/types';
|
|
3
|
+
import type { IWebPopupsConfig } from '../widgets/WebPopups/types';
|
|
3
4
|
export interface IServerInitParams {
|
|
4
5
|
autoSubscribe?: boolean;
|
|
5
6
|
defaultNotificationTitle?: string;
|
|
@@ -8,5 +9,12 @@ export interface IServerInitParams {
|
|
|
8
9
|
unifiedPlatform?: boolean;
|
|
9
10
|
subscribeWidget?: Partial<ISubscribeWidget>;
|
|
10
11
|
subscriptionWidget?: ISubscriptionWidgetParams;
|
|
12
|
+
inboxWidget?: Partial<IInboxWidget>;
|
|
13
|
+
webPopups?: Pick<IWebPopupsConfig, 'enable'>;
|
|
11
14
|
}
|
|
15
|
+
export type IServerModules = Pick<IServerInitParams, 'inboxWidget' | 'webPopups'>;
|
|
16
|
+
export declare function serverInitParams(features?: {
|
|
17
|
+
web_sdk?: IServerInitParams;
|
|
18
|
+
web_sdk_modules?: IServerModules;
|
|
19
|
+
}): IServerInitParams | undefined;
|
|
12
20
|
export declare function resolveInitParams(rawParams: IInitParams, serverParams?: IServerInitParams): Partial<IInitParams>;
|
package/modules/Api/Api.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type MultiRegisterDeviceRequest } from './Api.types';
|
|
2
2
|
import { type EventBus } from '../../core/modules/EventBus';
|
|
3
|
+
import { type TPushPermissionStatus } from '../../services/PushService/pushPermissionStatus';
|
|
3
4
|
import { type WebPopup } from '../../widgets/WebPopups/types';
|
|
4
5
|
import { ApiClient } from '../ApiClient/ApiClient';
|
|
5
6
|
import { type IMapResponse } from '../ApiClient/ApiClient.types';
|
|
@@ -10,17 +11,25 @@ export declare class Api {
|
|
|
10
11
|
private readonly eventBus;
|
|
11
12
|
private readonly getIsCommunicationDisabled;
|
|
12
13
|
private readonly getInitUserId;
|
|
14
|
+
private readonly getPushPermissionStatus;
|
|
13
15
|
private ensureDeviceRegisteredPromise;
|
|
14
16
|
private checkDevicePromise;
|
|
15
|
-
|
|
17
|
+
private registerDevicePromise;
|
|
18
|
+
private reportingPushPermissionStatus?;
|
|
19
|
+
private readonly waitForRegisterDevice;
|
|
20
|
+
constructor(eventBus: EventBus, data?: Data, apiClient?: ApiClient, getIsCommunicationDisabled?: () => boolean | undefined, getInitUserId?: () => string | undefined, getPushPermissionStatus?: () => TPushPermissionStatus | undefined);
|
|
16
21
|
checkDevice(): Promise<IMapResponse['checkDevice']>;
|
|
17
22
|
private requestCheckDevice;
|
|
18
23
|
checkDeviceSubscribeForPushNotifications(useCache?: boolean): Promise<boolean>;
|
|
19
24
|
ensureDeviceRegistered(): Promise<boolean>;
|
|
20
25
|
private registerDeviceIfNotExist;
|
|
26
|
+
reportPushPermissionStatus(isTokenDead?: boolean): Promise<void>;
|
|
27
|
+
isPushPermissionStatusReported(): boolean;
|
|
28
|
+
private rememberReportedPushPermissionStatus;
|
|
21
29
|
getConfig(features: string[]): Promise<IMapResponse['getConfig']>;
|
|
22
30
|
applicationOpen(): Promise<IMapResponse['applicationOpen']>;
|
|
23
31
|
registerDevice(): Promise<IMapResponse['registerDevice']>;
|
|
32
|
+
private requestRegisterDevice;
|
|
24
33
|
unregisterDevice(): Promise<IMapResponse['unregisterDevice']>;
|
|
25
34
|
deleteDevice(): Promise<IMapResponse['deleteDevice']>;
|
|
26
35
|
messageDeliveryEvent(hash: string, isTrackingLogOnFailure?: boolean, metaData?: {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { type IServerInitParams } from '../../core/resolveInitParams';
|
|
1
|
+
import { type IServerInitParams, type IServerModules } from '../../core/resolveInitParams';
|
|
2
2
|
import { type IInboxMessage } from '../../models/InboxMessages.types';
|
|
3
|
+
import { type TPushPermissionStatus } from '../../services/PushService/pushPermissionStatus';
|
|
3
4
|
import { type WebPopup } from '../../widgets/WebPopups/types';
|
|
4
5
|
import { type MultiRegisterDeviceRequest } from '../Api/Api.types';
|
|
5
6
|
type TMethodCheckDevice = 'checkDevice';
|
|
@@ -54,7 +55,11 @@ interface IRequestRecordPopupFormEvent extends IRequest {
|
|
|
54
55
|
code: string;
|
|
55
56
|
event: 1 | 2;
|
|
56
57
|
}
|
|
58
|
+
interface IRequestApplicationOpen extends IRequest {
|
|
59
|
+
push_permission_status?: TPushPermissionStatus;
|
|
60
|
+
}
|
|
57
61
|
interface IRequestRegisterDevice extends IRequest {
|
|
62
|
+
push_permission_status?: TPushPermissionStatus;
|
|
58
63
|
push_token?: string;
|
|
59
64
|
public_key?: string;
|
|
60
65
|
auth_token?: string;
|
|
@@ -134,6 +139,7 @@ interface IResponseGetConfig {
|
|
|
134
139
|
use_case: 'not-set' | 'default' | 'not-used';
|
|
135
140
|
};
|
|
136
141
|
web_sdk?: IServerInitParams;
|
|
142
|
+
web_sdk_modules?: IServerModules;
|
|
137
143
|
};
|
|
138
144
|
}
|
|
139
145
|
interface IResponseGetPopupForms {
|
|
@@ -162,7 +168,7 @@ export type TMethod = TMethodCheckDevice | TMethodGetConfig | TMethodApplication
|
|
|
162
168
|
export interface IMapRequest {
|
|
163
169
|
checkDevice: IRequest;
|
|
164
170
|
getConfig: IRequestGetConfig;
|
|
165
|
-
applicationOpen:
|
|
171
|
+
applicationOpen: IRequestApplicationOpen;
|
|
166
172
|
registerDevice: IRequestRegisterDevice;
|
|
167
173
|
unregisterDevice: IRequest;
|
|
168
174
|
deleteDevice: IRequest;
|
package/modules/Data/Data.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { type SubscriptionWidgetHistory } from '@pushwoosh/websdk-common/subscription-widget';
|
|
2
2
|
import { keyValue } from '../../core/storage';
|
|
3
3
|
import { type TLoggerOutputLevels } from '../../helpers/pwlogger';
|
|
4
|
+
import { type IFeatureFlagsCache, type TFeatureFlagImpressions } from '../FeatureFlags/FeatureFlags.types';
|
|
4
5
|
export declare class Data {
|
|
5
6
|
private readonly store;
|
|
6
7
|
constructor(store?: typeof keyValue);
|
|
@@ -37,6 +38,10 @@ export declare class Data {
|
|
|
37
38
|
getDefaultNotificationTitle(): Promise<string>;
|
|
38
39
|
setUserId(userId?: string | number | undefined): Promise<void>;
|
|
39
40
|
getUserId(): Promise<string | undefined>;
|
|
41
|
+
getFeatureFlags(): Promise<IFeatureFlagsCache | undefined>;
|
|
42
|
+
setFeatureFlags(cache: IFeatureFlagsCache | undefined): Promise<void>;
|
|
43
|
+
getFeatureFlagImpressions(): Promise<TFeatureFlagImpressions>;
|
|
44
|
+
setFeatureFlagImpressions(impressions: TFeatureFlagImpressions): Promise<void>;
|
|
40
45
|
setStatusUserIdWasChanged(status: boolean): Promise<void>;
|
|
41
46
|
getStatusUserIdWasChanged(): Promise<boolean>;
|
|
42
47
|
setEmail(email?: string): Promise<void>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare class FeatureFlag {
|
|
2
|
+
readonly key: string;
|
|
3
|
+
readonly enabled: boolean;
|
|
4
|
+
readonly ruleId: string;
|
|
5
|
+
private readonly properties;
|
|
6
|
+
constructor(key: string, enabled: boolean, ruleId: string, properties: Record<string, unknown>);
|
|
7
|
+
getString(property: string, defaultValue: string): string;
|
|
8
|
+
getNumber(property: string, defaultValue: number): number;
|
|
9
|
+
getBool(property: string, defaultValue: boolean): boolean;
|
|
10
|
+
getJson<T = unknown>(property: string, defaultValue: T): T;
|
|
11
|
+
getProperties(): Record<string, unknown>;
|
|
12
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { FeatureFlag } from './FeatureFlag';
|
|
2
|
+
import { type TFeatureFlagsUpdateListener } from './FeatureFlags.types';
|
|
3
|
+
import { type EventBus } from '../../core/modules/EventBus';
|
|
4
|
+
import { type Data } from '../Data/Data';
|
|
5
|
+
export declare const FEATURE_FLAG_IMPRESSION_EVENT = "PW_FeatureFlagImpression";
|
|
6
|
+
export interface IFeatureFlagsDeps {
|
|
7
|
+
eventBus: EventBus;
|
|
8
|
+
data: Data;
|
|
9
|
+
postEvent: (event: string, attributes: Record<string, unknown>) => Promise<unknown>;
|
|
10
|
+
isCommunicationDisabled: () => boolean;
|
|
11
|
+
isDeviceRegistered: () => boolean;
|
|
12
|
+
fetch?: typeof fetch;
|
|
13
|
+
now?: () => number;
|
|
14
|
+
}
|
|
15
|
+
export declare class FeatureFlags {
|
|
16
|
+
private readonly deps;
|
|
17
|
+
private readonly listeners;
|
|
18
|
+
private readonly pageImpressions;
|
|
19
|
+
private cache?;
|
|
20
|
+
private isMemoryOnly;
|
|
21
|
+
private applicationCode;
|
|
22
|
+
private userId;
|
|
23
|
+
private lastRequestAt;
|
|
24
|
+
private lastSentUnregistered;
|
|
25
|
+
private generation;
|
|
26
|
+
private inFlight?;
|
|
27
|
+
private timer?;
|
|
28
|
+
private isStarted;
|
|
29
|
+
private isLoaded;
|
|
30
|
+
private isActivated;
|
|
31
|
+
private userChangedWhileLoading;
|
|
32
|
+
constructor(deps: IFeatureFlagsDeps);
|
|
33
|
+
start(): Promise<void>;
|
|
34
|
+
get(key: string): FeatureFlag | null;
|
|
35
|
+
isEnabled(key: string, defaultValue: boolean): boolean;
|
|
36
|
+
refresh(): Promise<void>;
|
|
37
|
+
reset(): void;
|
|
38
|
+
addUpdateListener(listener: TFeatureFlagsUpdateListener): void;
|
|
39
|
+
removeUpdateListener(listener: TFeatureFlagsUpdateListener): void;
|
|
40
|
+
logImpression(key: string): Promise<void>;
|
|
41
|
+
private sendImpression;
|
|
42
|
+
private onUserChanged;
|
|
43
|
+
private onRegistered;
|
|
44
|
+
private activate;
|
|
45
|
+
private refreshOnPageLoad;
|
|
46
|
+
private sendAfterInFlight;
|
|
47
|
+
private sendInBackground;
|
|
48
|
+
private send;
|
|
49
|
+
private request;
|
|
50
|
+
private apply;
|
|
51
|
+
private newCache;
|
|
52
|
+
private notify;
|
|
53
|
+
private schedulePeriodicRefresh;
|
|
54
|
+
private hasValidCache;
|
|
55
|
+
private isCacheOfCurrentUser;
|
|
56
|
+
private visibleSnapshot;
|
|
57
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export interface IFeatureFlagValue {
|
|
2
|
+
enabled: boolean;
|
|
3
|
+
rule_id: string;
|
|
4
|
+
properties: Record<string, unknown>;
|
|
5
|
+
}
|
|
6
|
+
export interface IFeatureFlagsCache {
|
|
7
|
+
applicationCode: string;
|
|
8
|
+
userId: string;
|
|
9
|
+
flags: Record<string, IFeatureFlagValue>;
|
|
10
|
+
etag: string;
|
|
11
|
+
fetchedAt: number;
|
|
12
|
+
sentUnregistered?: boolean;
|
|
13
|
+
}
|
|
14
|
+
export type TFeatureFlagImpressions = Record<string, number>;
|
|
15
|
+
export type TFeatureFlagsUpdateListener = () => void;
|
|
16
|
+
export declare class FeatureFlagsError extends Error {
|
|
17
|
+
readonly httpStatus: number;
|
|
18
|
+
constructor(message: string, httpStatus: number);
|
|
19
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function featureFlagsUrl(entrypoint: string | undefined): string;
|
|
@@ -4,13 +4,15 @@ import DateModule from './DateModule';
|
|
|
4
4
|
import { type IModuleRegistry } from '../core/Pushwoosh.types';
|
|
5
5
|
import { type default as InboxMessagesModel } from '../models/InboxMessages';
|
|
6
6
|
import { type IInboxMessage, type IInboxMessagePublic, type IInboxMessages } from '../models/InboxMessages.types';
|
|
7
|
+
import { type IWebPopupsPublicApi } from '../widgets/WebPopups/types';
|
|
7
8
|
export default class InboxMessages implements IInboxMessages {
|
|
8
9
|
private readonly data;
|
|
9
10
|
private readonly api;
|
|
10
11
|
private readonly inboxModel;
|
|
11
12
|
private readonly moduleRegistry;
|
|
13
|
+
private readonly loadWebPopups;
|
|
12
14
|
private dateModule;
|
|
13
|
-
constructor(data: Data, api: Api, inboxModel: InboxMessagesModel, moduleRegistry?: IModuleRegistry, dateModule?: DateModule);
|
|
15
|
+
constructor(data: Data, api: Api, inboxModel: InboxMessagesModel, moduleRegistry?: IModuleRegistry, loadWebPopups?: () => Promise<IWebPopupsPublicApi | undefined>, dateModule?: DateModule);
|
|
14
16
|
private parseActionParams;
|
|
15
17
|
/**
|
|
16
18
|
* Get message type by IInboxMessageActionParams
|