web-push-notifications 3.92.0 → 3.98.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 +116 -0
- package/core/Pushwoosh.d.ts +19 -0
- package/core/Pushwoosh.types.d.ts +2 -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/recommendationsLoader.d.ts +5 -0
- package/core/resolveInitParams.d.ts +7 -0
- package/modules/Api/Api.d.ts +12 -3
- package/modules/ApiClient/ApiClient.d.ts +4 -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/modules/Recommendations/Recommendations.d.ts +30 -0
- package/modules/Recommendations/Recommendations.types.d.ts +55 -0
- package/modules/Recommendations/__tests__/Recommendations.test.d.ts +1 -0
- package/npm.js +1 -1
- package/npm.js.map +1 -1
- package/package.json +2 -2
- package/pushwoosh-widget-recommendations.d.ts +1 -0
- 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-recommendations.d.ts +1 -0
- package/widget-recommendations.js +2 -0
- package/widget-recommendations.js.map +1 -0
- package/widget-subscription-button.js.map +1 -1
- package/widget-subscription.js.map +1 -1
- package/widget-web-popups.js +1 -1
- package/widget-web-popups.js.map +1 -1
- package/widgets/Recommendations/RecommendationsWidget.d.ts +20 -0
- package/widgets/Recommendations/__tests__/RecommendationsWidget.test.d.ts +1 -0
- package/widgets/Recommendations/styles.d.ts +1 -0
- package/widgets/WebPopups/EmbeddedWebPopups.d.ts +37 -0
- package/widgets/WebPopups/WebPopupsWidget.d.ts +15 -2
- package/widgets/WebPopups/__tests__/WebPopupsWidget.test.d.ts +1 -0
- package/widgets/WebPopups/__tests__/embedded.test.d.ts +1 -0
- package/widgets/WebPopups/__tests__/embeddedRenderer.test.d.ts +1 -0
- package/widgets/WebPopups/constants.d.ts +1 -0
- package/widgets/WebPopups/embeddedRenderer.d.ts +4 -0
- package/widgets/WebPopups/types.d.ts +8 -1
package/CHANGELOG.md
CHANGED
|
@@ -9,6 +9,122 @@ 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
|
+
## feat(widgets): load widgets from the bundle's own host, version widget URLs
|
|
13
|
+
|
|
14
|
+
- The CDN bundle loads widgets from the folder it was itself loaded from, or from `cdn.pushwoosh.com/webpush/v3/` when that folder is unknown.
|
|
15
|
+
- Widget URLs carry the SDK version (`?v=`), so a cached bundle never pairs with widgets of another release.
|
|
16
|
+
|
|
17
|
+
## feat(web-popups): render EMBEDDED web campaigns inside a page element
|
|
18
|
+
|
|
19
|
+
- A web campaign with `kind: 'EMBEDDED'` renders as a block inside the first element its `css_selector`
|
|
20
|
+
matches, instead of over the page, stretched to the element's full width (the page width is ignored).
|
|
21
|
+
Images are capped at 360px high and cropped to cover; text and buttons are never clipped.
|
|
22
|
+
No close icon; close-action buttons are not drawn and a `hide-popup` countdown does not remove the block.
|
|
23
|
+
- EMBEDDED follows device type, visitor type, page rules and the trigger setting, but has no delay
|
|
24
|
+
and no frequency. `webPopups.autoShow: false` and API-triggered campaigns leave it to `show(code)`.
|
|
25
|
+
- Several campaigns with the same selector stack in server order. A missing element or an invalid
|
|
26
|
+
selector skips the campaign silently.
|
|
27
|
+
- On SPA navigation the blocks follow the page rules: removed when the rules stop matching, rendered
|
|
28
|
+
again when they match. A block shown by `show(code)` stays across navigation and is removed only when
|
|
29
|
+
its element leaves the page. An element added later is not watched: the SDK looks for it on load and
|
|
30
|
+
on each navigation, otherwise call `show(code)` once it is on the page. VISIT is reported once per
|
|
31
|
+
page load, at the first render; IMPRESSION and subscription form views once per page load, when the
|
|
32
|
+
block first enters the viewport.
|
|
33
|
+
- The `auto` color scheme follows OS theme changes while the block is on the page.
|
|
34
|
+
- A missing or unknown `kind` keeps the popup behavior.
|
|
35
|
+
|
|
36
|
+
## feat(recommendations): onsite product recommendations widget and API
|
|
37
|
+
|
|
38
|
+
- `Pushwoosh.trackProductView({id, name, price, currency, category, url, imageUrl})` sends `PW_ProductView`
|
|
39
|
+
(one event per product in 30 s), the input of the "viewed" recommendations and of the product pairs.
|
|
40
|
+
- `Pushwoosh.recommendations.fetch({strategy, fallback, limit, productId, exclude, block})` reads the public onsite
|
|
41
|
+
feed (`/feed/v1/onsite/products.json`, the application opts in on the server); the hwid goes in the
|
|
42
|
+
`X-PW-HWID` header, and without communication consent the request is anonymous.
|
|
43
|
+
- `Pushwoosh.recommendations.trackClick({block, strategy, productId, position})` sends `PW_RecommendationClick`
|
|
44
|
+
with `keepalive`, the product under `recoProductId` so a click does not feed the recommendations themselves.
|
|
45
|
+
- New widget bundle `pushwoosh-widget-recommendations.js`: loaded only once a `[data-pw-recommendations]` block is
|
|
46
|
+
on the page (checked once when the SDK is ready; with `recommendations.spa: true` also when an SPA adds one later), renders into shadow DOM, themed by `--pw-reco-font`,
|
|
47
|
+
`--pw-reco-accent`, `--pw-reco-radius`, `--pw-reco-columns`, reports `data-pw-state`
|
|
48
|
+
(`loading`/`ready`/`empty`/`error`) and re-renders on a data attribute change. `recommendations.widget: false`
|
|
49
|
+
in the init params keeps it off; `recommendations.endpoint` points it at another feed.
|
|
50
|
+
|
|
51
|
+
## fix(push): report permission changes with registerDevice
|
|
52
|
+
|
|
53
|
+
- A refusal in the permission dialog, or a permission change reported by `navigator.permissions`, now goes
|
|
54
|
+
to the server as a registerDevice without a push token instead of an extra `applicationOpen`, which the
|
|
55
|
+
server counted as one more app open. It is sent only for a device without a push token, after a
|
|
56
|
+
subscription in flight has been answered, and once per status: the last status the server got is kept
|
|
57
|
+
in `localStorage` (`reportedPushPermissionStatus`), so a page load does not repeat it.
|
|
58
|
+
- A permission revoked or reset in the site settings while the page is open drops the subscription right
|
|
59
|
+
away (as the next init would) and reports the new status; after init the status is reported too, so a
|
|
60
|
+
revoke noticed on reload, or a grant without a subscription, no longer waits for the hourly
|
|
61
|
+
`applicationOpen`.
|
|
62
|
+
- A permission granted in the dialog is reported only by the subscription's own registerDevice: the
|
|
63
|
+
`change` event that fires first waits for the subscription instead of sending a tokenless report that
|
|
64
|
+
could land after it and clear the token. It waits at most 10 s, and so does the re-subscribe after a
|
|
65
|
+
grant in the site settings and the unsubscribe after a revoke. A subscription, unsubscribe or
|
|
66
|
+
registerDevice that hangs is waited for once: the next permission change on the page is reported
|
|
67
|
+
right away (a revoke as a tokenless registerDevice, the dead token may be cleared), and a report that
|
|
68
|
+
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
|
|
69
|
+
dropped on a revoke (not one the user unsubscribed manually), as the next init would.
|
|
70
|
+
- A reload after a permission change sends one `unregisterDevice` instead of two: init no longer asks the
|
|
71
|
+
server whether the device it has just unregistered still has a token.
|
|
72
|
+
|
|
73
|
+
## feat(push): report push permission status
|
|
74
|
+
|
|
75
|
+
- `applicationOpen` and `registerDevice` carry `push_permission_status`: `not_determined`, `granted_explicit`,
|
|
76
|
+
`denied`, or `unsupported` when the browser has no Push API (iOS Safari outside a home screen app).
|
|
77
|
+
The legacy Safari driver reports its own permission the same way.
|
|
78
|
+
- An `applicationOpen` goes right after the permission dialog closes, past the hourly throttle, and on a
|
|
79
|
+
change of the notifications permission where `navigator.permissions` reports one (Chromium, Firefox).
|
|
80
|
+
|
|
81
|
+
## fix(feature-flags): serve the cached flags from onReady
|
|
82
|
+
|
|
83
|
+
- The flags cache is read from IndexedDB before `ready` fires, so `get()`/`isEnabled()` called in
|
|
84
|
+
`onReady` return the cached flags instead of `null`.
|
|
85
|
+
- A flag read before the cache finished loading is followed by an update-listener call once the cache
|
|
86
|
+
is there, also when the page-load refresh is skipped (cache younger than 15 minutes) or answers
|
|
87
|
+
`not_modified`.
|
|
88
|
+
|
|
89
|
+
## feat(feature-flags): add the feature flags client
|
|
90
|
+
|
|
91
|
+
- `Pushwoosh.featureFlags` reads the application's feature flags that the server evaluates for the
|
|
92
|
+
device: `get(key)` with typed getters and defaults, `isEnabled`, `refresh()`, update listeners and
|
|
93
|
+
`logImpression(key)` (`PW_FeatureFlagImpression`).
|
|
94
|
+
- Nothing goes to the network until the site first calls the flags API on a page; sites that do not
|
|
95
|
+
use feature flags send no requests.
|
|
96
|
+
- Flags come from `/api/v2/device-api/getFeatureFlags` on the current API host, are cached in
|
|
97
|
+
IndexedDB per User ID for up to 24 hours with an etag, and refresh on the first use of a page when
|
|
98
|
+
the cache is older than 15 minutes, hourly while the page is open, after the first device
|
|
99
|
+
registration and right after the User ID changes.
|
|
100
|
+
|
|
101
|
+
## fix(web-sdk): take legacy panel modules from web_sdk_modules
|
|
102
|
+
|
|
103
|
+
- A legacy (snippet) application now gets its panel `inboxWidget`/`webPopups` from the
|
|
104
|
+
`web_sdk_modules` feature, and only those two keys are taken from it. `web_sdk` keeps meaning
|
|
105
|
+
"panel-managed", so the Control Panel Subscription Prompt stays on for a legacy site that switched
|
|
106
|
+
a module in the panel.
|
|
107
|
+
|
|
108
|
+
## fix(inbox): open the web popup content an inbox message points to
|
|
109
|
+
|
|
110
|
+
- Tapping an App Inbox message that opens a web popup now shows it when the message carries a popup
|
|
111
|
+
content code (the inbox wizard and the journey Send Inbox point pick a content, not a campaign).
|
|
112
|
+
Campaign codes work as before; a content shown this way records no popup campaign stats, the tap is
|
|
113
|
+
counted as the inbox open.
|
|
114
|
+
- The web popups bundle is fetched on such a tap when the site did not load it (no active popup
|
|
115
|
+
campaigns); `webPopups.enable: false` still keeps it off. If the popup cannot be shown, the message
|
|
116
|
+
link is followed as before.
|
|
117
|
+
- `moduleRegistry.webPopups.show(code)` accepts a popup content code as well.
|
|
118
|
+
|
|
119
|
+
## feat(web-popups): take the web popups switch from the panel
|
|
120
|
+
|
|
121
|
+
- An application in the panel-managed mode gets `webPopups.enable` from the Control Panel, so support
|
|
122
|
+
can switch web popups off for a site without a snippet change; `colorScheme` and `autoShow` stay as
|
|
123
|
+
the snippet set them.
|
|
124
|
+
- `webPopups.enable: false` and `inboxWidget.enable: false` now also stop a widget an npm site
|
|
125
|
+
constructs itself, not only the CDN loader.
|
|
126
|
+
- A missing inbox trigger element is reported by its id, with where to change it.
|
|
127
|
+
|
|
12
128
|
## feat(inbox): take the inbox widget from the panel in managed mode
|
|
13
129
|
|
|
14
130
|
- An application in the panel-managed mode gets `inboxWidget` from the Control Panel: its keys
|
package/core/Pushwoosh.d.ts
CHANGED
|
@@ -2,8 +2,11 @@ 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';
|
|
8
|
+
import { Recommendations } from '../modules/Recommendations/Recommendations';
|
|
9
|
+
import { type IProductView } from '../modules/Recommendations/Recommendations.types';
|
|
7
10
|
import { type IPushService } from '../services/PushService/PushService.types';
|
|
8
11
|
export declare class Pushwoosh {
|
|
9
12
|
ready: boolean;
|
|
@@ -19,10 +22,18 @@ export declare class Pushwoosh {
|
|
|
19
22
|
platformChecker: PlatformChecker;
|
|
20
23
|
private isPushDisabled;
|
|
21
24
|
private isInitAborted;
|
|
25
|
+
private isPushPermissionWatched;
|
|
26
|
+
private subscriptionInFlight;
|
|
27
|
+
private readonly waitForPermissionWork;
|
|
22
28
|
pwinbox: InboxMessagesPublic;
|
|
23
29
|
private inboxModel;
|
|
24
30
|
moduleRegistry: IModuleRegistry;
|
|
31
|
+
readonly featureFlags: FeatureFlags;
|
|
32
|
+
/** Onsite product recommendations: headless `fetch` and `trackClick`, the widget renders through them. */
|
|
33
|
+
readonly recommendations: Recommendations;
|
|
34
|
+
widgetLoader?: (widgetName: string) => Promise<boolean>;
|
|
25
35
|
constructor();
|
|
36
|
+
private loadWebPopupsWidget;
|
|
26
37
|
/**
|
|
27
38
|
* Add Web SDK Event Handler.
|
|
28
39
|
* Alias to addEventHandler method of EventBus module.
|
|
@@ -104,6 +115,7 @@ export declare class Pushwoosh {
|
|
|
104
115
|
* @returns {Promise<void>}
|
|
105
116
|
*/
|
|
106
117
|
subscribe(isForceSubscribe?: boolean): Promise<void>;
|
|
118
|
+
private runSubscribe;
|
|
107
119
|
/**
|
|
108
120
|
* Unsubscribe device.
|
|
109
121
|
* @returns {Promise<void>}
|
|
@@ -142,6 +154,8 @@ export declare class Pushwoosh {
|
|
|
142
154
|
* @returns {Promise<void>}
|
|
143
155
|
*/
|
|
144
156
|
removeAllDeviceData(): Promise<void>;
|
|
157
|
+
/** Reports a product page view (`PW_ProductView`), the input of "You viewed" and of the product pairs. */
|
|
158
|
+
trackProductView(product: IProductView): Promise<void>;
|
|
145
159
|
/**
|
|
146
160
|
* Method returns hardware id.
|
|
147
161
|
* @returns {Promise<string>}
|
|
@@ -201,6 +215,11 @@ export declare class Pushwoosh {
|
|
|
201
215
|
* @returns {Promise<void>}
|
|
202
216
|
*/
|
|
203
217
|
private open;
|
|
218
|
+
private getPushPermissionStatus;
|
|
219
|
+
private reportPushPermissionChange;
|
|
220
|
+
private dropRevokedSubscription;
|
|
221
|
+
private reportPushPermissionChangeInBackground;
|
|
222
|
+
private watchPushPermission;
|
|
204
223
|
private sendData;
|
|
205
224
|
private loadConfig;
|
|
206
225
|
private applyServerInitParams;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type INotificationButton } from '../models/NotificationPayload.types';
|
|
2
|
+
import { type IRecommendationsConfig } from '../modules/Recommendations/Recommendations.types';
|
|
2
3
|
import { type ISubscribePopupConfig } from '../widgets/SubscribePopup/types/subscribe-popup';
|
|
3
4
|
import { type ISubscriptionWidgetParams, type ISubscriptionWidgetPublicApi } from '../widgets/SubscriptionWidget/types';
|
|
4
5
|
import { type IWebPopupsConfig, type IWebPopupsPublicApi } from '../widgets/WebPopups/types';
|
|
@@ -148,6 +149,7 @@ export interface IInitParams {
|
|
|
148
149
|
/** The unified subscription widget; while its prompt or bell is on — or whenever the panel saved it — `subscribeWidget`, `subscribePopup` and the Subscription Prompt stay off. */
|
|
149
150
|
subscriptionWidget?: ISubscriptionWidgetParams;
|
|
150
151
|
webPopups?: IWebPopupsConfig;
|
|
152
|
+
recommendations?: IRecommendationsConfig;
|
|
151
153
|
webSDKPath?: string;
|
|
152
154
|
unifiedPlatform?: boolean;
|
|
153
155
|
}
|
|
@@ -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>;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Calls `load` once a recommendations block is on the page: a site without one never fetches the bundle.
|
|
3
|
+
* Only `spa` keeps watching for blocks added later, so other sites carry no document-wide observer.
|
|
4
|
+
*/
|
|
5
|
+
export declare function loadWhenRecommendationsAppear(root: Document, load: () => void, spa?: boolean): void;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
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;
|
|
@@ -9,5 +10,11 @@ export interface IServerInitParams {
|
|
|
9
10
|
subscribeWidget?: Partial<ISubscribeWidget>;
|
|
10
11
|
subscriptionWidget?: ISubscriptionWidgetParams;
|
|
11
12
|
inboxWidget?: Partial<IInboxWidget>;
|
|
13
|
+
webPopups?: Pick<IWebPopupsConfig, 'enable'>;
|
|
12
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;
|
|
13
20
|
export declare function resolveInitParams(rawParams: IInitParams, serverParams?: IServerInitParams): Partial<IInitParams>;
|
package/modules/Api/Api.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
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
|
-
import { ApiClient } from '../ApiClient/ApiClient';
|
|
5
|
+
import { ApiClient, type IRequestInit } from '../ApiClient/ApiClient';
|
|
5
6
|
import { type IMapResponse } from '../ApiClient/ApiClient.types';
|
|
6
7
|
import { Data } from '../Data/Data';
|
|
7
8
|
export declare class Api {
|
|
@@ -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?: {
|
|
@@ -43,7 +52,7 @@ export declare class Api {
|
|
|
43
52
|
recordPopupFormEvent(code: string, event: 1 | 2): Promise<IMapResponse['recordPopupFormEvent']>;
|
|
44
53
|
postEvent(event: string, attributes: {
|
|
45
54
|
[key: string]: any;
|
|
46
|
-
}): Promise<IMapResponse['postEvent']>;
|
|
55
|
+
}, init?: IRequestInit): Promise<IMapResponse['postEvent']>;
|
|
47
56
|
getInboxMessages(count?: number): Promise<IMapResponse['getInboxMessages']>;
|
|
48
57
|
inboxStatus(order: string, status: number): Promise<IMapResponse['inboxStatus']>;
|
|
49
58
|
multiRegisterDevice(request: Partial<MultiRegisterDeviceRequest>): Promise<IMapResponse['multiRegisterDevice']>;
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { type IMapRequest, type IMapResponse } from './ApiClient.types';
|
|
2
2
|
import { Logger } from '../../core/logger';
|
|
3
3
|
import { Data } from '../Data/Data';
|
|
4
|
+
export type IRequestInit = {
|
|
5
|
+
keepalive?: boolean;
|
|
6
|
+
};
|
|
4
7
|
export declare class ApiClient {
|
|
5
8
|
private readonly data;
|
|
6
9
|
private readonly logger;
|
|
@@ -22,7 +25,7 @@ export declare class ApiClient {
|
|
|
22
25
|
registerEmail(options: IMapRequest['registerEmail']): Promise<IMapResponse['registerEmail']>;
|
|
23
26
|
registerEmailUser(options: IMapRequest['registerEmailUser']): Promise<IMapResponse['registerEmailUser']>;
|
|
24
27
|
setEmailTags(options: IMapRequest['setEmailTags']): Promise<IMapResponse['setEmailTags']>;
|
|
25
|
-
postEvent(options: IMapRequest['postEvent']): Promise<IMapResponse['postEvent']>;
|
|
28
|
+
postEvent(options: IMapRequest['postEvent'], init?: IRequestInit): Promise<IMapResponse['postEvent']>;
|
|
26
29
|
getInboxMessages(options: IMapRequest['getInboxMessages']): Promise<IMapResponse['getInboxMessages']>;
|
|
27
30
|
inboxStatus(options: IMapRequest['inboxStatus']): Promise<IMapResponse['inboxStatus']>;
|
|
28
31
|
multiRegisterDevice(options: IMapRequest['multiRegisterDevice']): Promise<IMapResponse['multiRegisterDevice']>;
|
|
@@ -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
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { type IProductView, type IRecommendationClick, type IRecommendationsRequest, type IRecommendationsResponse } from './Recommendations.types';
|
|
2
|
+
export declare const PRODUCT_VIEW_EVENT = "PW_ProductView";
|
|
3
|
+
export declare const RECOMMENDATION_CLICK_EVENT = "PW_RecommendationClick";
|
|
4
|
+
export declare const DEFAULT_RECOMMENDATIONS_ENDPOINT = "https://recommender-onsite.svc-nue.pushwoosh.com";
|
|
5
|
+
export interface IRecommendationsDeps {
|
|
6
|
+
postEvent: (event: string, attributes: Record<string, unknown>, init?: {
|
|
7
|
+
keepalive?: boolean;
|
|
8
|
+
}) => Promise<unknown>;
|
|
9
|
+
isCommunicationDisabled: () => boolean;
|
|
10
|
+
getApplicationCode: () => Promise<string>;
|
|
11
|
+
getHwid: () => Promise<string>;
|
|
12
|
+
getEndpoint: () => string | undefined;
|
|
13
|
+
fetch?: typeof fetch;
|
|
14
|
+
now?: () => number;
|
|
15
|
+
storage?: Pick<Storage, 'getItem' | 'setItem'>;
|
|
16
|
+
}
|
|
17
|
+
export declare class Recommendations {
|
|
18
|
+
private readonly deps;
|
|
19
|
+
constructor(deps: IRecommendationsDeps);
|
|
20
|
+
/** Feeds "You viewed" and the co-occurrence pairs; one event per product in 30 s, so a reload is not a second view. */
|
|
21
|
+
trackProductView(product: IProductView): Promise<void>;
|
|
22
|
+
/** Without communication consent the request goes anonymous: no hwid, so `viewed` falls back on the server. */
|
|
23
|
+
fetch(request: IRecommendationsRequest): Promise<IRecommendationsResponse>;
|
|
24
|
+
/**
|
|
25
|
+
* The product goes under `recoProductId`, not `productId`: a scalar product id feeds the viewed tail
|
|
26
|
+
* and the pairs on the server, and recommendations would then reinforce themselves.
|
|
27
|
+
*/
|
|
28
|
+
trackClick(click: IRecommendationClick): Promise<void>;
|
|
29
|
+
private seenRecently;
|
|
30
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
export type TRecommendationStrategy = 'viewed' | 'bestsellers_30d' | 'also_bought';
|
|
2
|
+
export interface IRecommendationsConfig {
|
|
3
|
+
/** Base URL of the onsite feed; the NUE deployment by default. */
|
|
4
|
+
endpoint?: string;
|
|
5
|
+
/** `false` keeps the widget bundle off even with `[data-pw-recommendations]` on the page. */
|
|
6
|
+
widget?: boolean;
|
|
7
|
+
/** Single-page apps: keep watching for blocks rendered after load. Off by default, so other sites carry no observer. */
|
|
8
|
+
spa?: boolean;
|
|
9
|
+
}
|
|
10
|
+
export interface IProductView {
|
|
11
|
+
id: string;
|
|
12
|
+
name?: string;
|
|
13
|
+
price?: number;
|
|
14
|
+
currency?: string;
|
|
15
|
+
category?: string;
|
|
16
|
+
url?: string;
|
|
17
|
+
imageUrl?: string;
|
|
18
|
+
}
|
|
19
|
+
export interface IRecommendationsRequest {
|
|
20
|
+
strategy: TRecommendationStrategy;
|
|
21
|
+
/** Served when the strategy has nothing; `bestsellers_30d` by default, `none` for an empty answer. */
|
|
22
|
+
fallback?: TRecommendationStrategy | 'none';
|
|
23
|
+
limit?: number;
|
|
24
|
+
/** The anchor of `also_bought`: the product on screen. */
|
|
25
|
+
productId?: string;
|
|
26
|
+
/** Products not to show: the cart, the product on screen. */
|
|
27
|
+
exclude?: string[];
|
|
28
|
+
/** Marks the links and the click event, so a click is traced back to the block. */
|
|
29
|
+
block?: string;
|
|
30
|
+
}
|
|
31
|
+
export interface IRecommendedProduct {
|
|
32
|
+
id: string;
|
|
33
|
+
title: string;
|
|
34
|
+
description: string;
|
|
35
|
+
image_url: string;
|
|
36
|
+
url: string;
|
|
37
|
+
price: number;
|
|
38
|
+
price_formatted: string;
|
|
39
|
+
old_price_formatted?: string;
|
|
40
|
+
currency: string;
|
|
41
|
+
category: string;
|
|
42
|
+
sku: string;
|
|
43
|
+
}
|
|
44
|
+
export interface IRecommendationsResponse {
|
|
45
|
+
items: IRecommendedProduct[];
|
|
46
|
+
/** The strategy actually served: the fallback one, or `none` for an empty answer. */
|
|
47
|
+
strategy: TRecommendationStrategy | 'none';
|
|
48
|
+
}
|
|
49
|
+
export interface IRecommendationClick {
|
|
50
|
+
block?: string;
|
|
51
|
+
strategy?: string;
|
|
52
|
+
productId: string;
|
|
53
|
+
/** 1-based place of the product in the block. */
|
|
54
|
+
position?: number;
|
|
55
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|