web-push-notifications 3.95.0 → 3.99.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. package/CHANGELOG.md +51 -0
  2. package/core/Pushwoosh.d.ts +6 -0
  3. package/core/Pushwoosh.types.d.ts +2 -0
  4. package/core/recommendationsLoader.d.ts +5 -0
  5. package/modules/Api/Api.d.ts +4 -2
  6. package/modules/ApiClient/ApiClient.d.ts +5 -1
  7. package/modules/ApiClient/ApiClient.types.d.ts +13 -1
  8. package/modules/Recommendations/Recommendations.d.ts +30 -0
  9. package/modules/Recommendations/Recommendations.types.d.ts +55 -0
  10. package/modules/Recommendations/__tests__/Recommendations.test.d.ts +1 -0
  11. package/npm.js +1 -1
  12. package/npm.js.map +1 -1
  13. package/package.json +2 -2
  14. package/pushwoosh-widget-recommendations.d.ts +1 -0
  15. package/service-worker.js +1 -1
  16. package/service-worker.js.map +1 -1
  17. package/widget-recommendations.d.ts +1 -0
  18. package/widget-recommendations.js +2 -0
  19. package/widget-recommendations.js.map +1 -0
  20. package/widget-subscription.js.map +1 -1
  21. package/widget-web-popups.js +1 -1
  22. package/widget-web-popups.js.map +1 -1
  23. package/widgets/Recommendations/RecommendationsWidget.d.ts +20 -0
  24. package/widgets/Recommendations/__tests__/RecommendationsWidget.test.d.ts +1 -0
  25. package/widgets/Recommendations/styles.d.ts +1 -0
  26. package/widgets/WebPopups/EmbeddedWebPopups.d.ts +37 -0
  27. package/widgets/WebPopups/WebPopupsWidget.d.ts +10 -0
  28. package/widgets/WebPopups/__tests__/deviceSubmitApi.test.d.ts +1 -0
  29. package/widgets/WebPopups/__tests__/embedded.test.d.ts +1 -0
  30. package/widgets/WebPopups/__tests__/embeddedRenderer.test.d.ts +1 -0
  31. package/widgets/WebPopups/__tests__/formValuesRender.test.d.ts +1 -0
  32. package/widgets/WebPopups/constants.d.ts +1 -0
  33. package/widgets/WebPopups/deviceSubmitApi.d.ts +2 -1
  34. package/widgets/WebPopups/embeddedRenderer.d.ts +4 -0
  35. package/widgets/WebPopups/renderer.d.ts +5 -2
  36. package/widgets/WebPopups/types.d.ts +6 -1
package/CHANGELOG.md CHANGED
@@ -9,6 +9,57 @@ 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(web-popups): submit web content forms to submitPopupForm
13
+
14
+ - A FORM web content (email input, tag inputs, consent, submit) sends its values in one request to
15
+ `/json/1.3/submitPopupForm`, under the code of the campaign that shows it and with the visitor's hwid.
16
+ The same content in a popup and in an inline block submits under each campaign's own code.
17
+ - `OK` opens the Success page, `INVALID_EMAIL` shows the email input's invalid message. Any other answer
18
+ or a network error shows the Submit error, and the visitor can submit again.
19
+ - Nothing is sent while communication is disabled.
20
+ - A content with form fields opened without a campaign (inbox `wp`, `show(<content code>)`) is not shown:
21
+ `show()` logs and resolves `false`, and the inbox follows the message link as before.
22
+ - `@pushwoosh/websdk-common` 6.22.1.
23
+
24
+ ## feat(widgets): load widgets from the bundle's own host, version widget URLs
25
+
26
+ - 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.
27
+ - Widget URLs carry the SDK version (`?v=`), so a cached bundle never pairs with widgets of another release.
28
+
29
+ ## feat(web-popups): render EMBEDDED web campaigns inside a page element
30
+
31
+ - A web campaign with `kind: 'EMBEDDED'` renders as a block inside the first element its `css_selector`
32
+ matches, instead of over the page, stretched to the element's full width (the page width is ignored).
33
+ Images are capped at 360px high and cropped to cover; text and buttons are never clipped.
34
+ No close icon; close-action buttons are not drawn and a `hide-popup` countdown does not remove the block.
35
+ - EMBEDDED follows device type, visitor type, page rules and the trigger setting, but has no delay
36
+ and no frequency. `webPopups.autoShow: false` and API-triggered campaigns leave it to `show(code)`.
37
+ - Several campaigns with the same selector stack in server order. A missing element or an invalid
38
+ selector skips the campaign silently.
39
+ - On SPA navigation the blocks follow the page rules: removed when the rules stop matching, rendered
40
+ again when they match. A block shown by `show(code)` stays across navigation and is removed only when
41
+ its element leaves the page. An element added later is not watched: the SDK looks for it on load and
42
+ on each navigation, otherwise call `show(code)` once it is on the page. VISIT is reported once per
43
+ page load, at the first render; IMPRESSION and subscription form views once per page load, when the
44
+ block first enters the viewport.
45
+ - The `auto` color scheme follows OS theme changes while the block is on the page.
46
+ - A missing or unknown `kind` keeps the popup behavior.
47
+
48
+ ## feat(recommendations): onsite product recommendations widget and API
49
+
50
+ - `Pushwoosh.trackProductView({id, name, price, currency, category, url, imageUrl})` sends `PW_ProductView`
51
+ (one event per product in 30 s), the input of the "viewed" recommendations and of the product pairs.
52
+ - `Pushwoosh.recommendations.fetch({strategy, fallback, limit, productId, exclude, block})` reads the public onsite
53
+ feed (`/feed/v1/onsite/products.json`, the application opts in on the server); the hwid goes in the
54
+ `X-PW-HWID` header, and without communication consent the request is anonymous.
55
+ - `Pushwoosh.recommendations.trackClick({block, strategy, productId, position})` sends `PW_RecommendationClick`
56
+ with `keepalive`, the product under `recoProductId` so a click does not feed the recommendations themselves.
57
+ - New widget bundle `pushwoosh-widget-recommendations.js`: loaded only once a `[data-pw-recommendations]` block is
58
+ 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`,
59
+ `--pw-reco-accent`, `--pw-reco-radius`, `--pw-reco-columns`, reports `data-pw-state`
60
+ (`loading`/`ready`/`empty`/`error`) and re-renders on a data attribute change. `recommendations.widget: false`
61
+ in the init params keeps it off; `recommendations.endpoint` points it at another feed.
62
+
12
63
  ## fix(push): report permission changes with registerDevice
13
64
 
14
65
  - A refusal in the permission dialog, or a permission change reported by `navigator.permissions`, now goes
@@ -5,6 +5,8 @@ import { Data } from '../modules/Data/Data';
5
5
  import { FeatureFlags } from '../modules/FeatureFlags/FeatureFlags';
6
6
  import InboxMessagesPublic from '../modules/InboxMessagesPublic';
7
7
  import { PlatformChecker } from '../modules/PlatformChecker';
8
+ import { Recommendations } from '../modules/Recommendations/Recommendations';
9
+ import { type IProductView } from '../modules/Recommendations/Recommendations.types';
8
10
  import { type IPushService } from '../services/PushService/PushService.types';
9
11
  export declare class Pushwoosh {
10
12
  ready: boolean;
@@ -27,6 +29,8 @@ export declare class Pushwoosh {
27
29
  private inboxModel;
28
30
  moduleRegistry: IModuleRegistry;
29
31
  readonly featureFlags: FeatureFlags;
32
+ /** Onsite product recommendations: headless `fetch` and `trackClick`, the widget renders through them. */
33
+ readonly recommendations: Recommendations;
30
34
  widgetLoader?: (widgetName: string) => Promise<boolean>;
31
35
  constructor();
32
36
  private loadWebPopupsWidget;
@@ -150,6 +154,8 @@ export declare class Pushwoosh {
150
154
  * @returns {Promise<void>}
151
155
  */
152
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>;
153
159
  /**
154
160
  * Method returns hardware id.
155
161
  * @returns {Promise<string>}
@@ -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,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,8 +1,9 @@
1
+ import { type WebPopupFormValues } from '@pushwoosh/websdk-common/web-popups';
1
2
  import { type MultiRegisterDeviceRequest } from './Api.types';
2
3
  import { type EventBus } from '../../core/modules/EventBus';
3
4
  import { type TPushPermissionStatus } from '../../services/PushService/pushPermissionStatus';
4
5
  import { type WebPopup } from '../../widgets/WebPopups/types';
5
- import { ApiClient } from '../ApiClient/ApiClient';
6
+ import { ApiClient, type IRequestInit } from '../ApiClient/ApiClient';
6
7
  import { type IMapResponse } from '../ApiClient/ApiClient.types';
7
8
  import { Data } from '../Data/Data';
8
9
  export declare class Api {
@@ -50,9 +51,10 @@ export declare class Api {
50
51
  getPopupForms(): Promise<Array<WebPopup>>;
51
52
  getPopupFormContent(code: string): Promise<IMapResponse['getPopupFormContent']>;
52
53
  recordPopupFormEvent(code: string, event: 1 | 2): Promise<IMapResponse['recordPopupFormEvent']>;
54
+ submitPopupForm(code: string, values: WebPopupFormValues): Promise<IMapResponse['submitPopupForm']>;
53
55
  postEvent(event: string, attributes: {
54
56
  [key: string]: any;
55
- }): Promise<IMapResponse['postEvent']>;
57
+ }, init?: IRequestInit): Promise<IMapResponse['postEvent']>;
56
58
  getInboxMessages(count?: number): Promise<IMapResponse['getInboxMessages']>;
57
59
  inboxStatus(order: string, status: number): Promise<IMapResponse['inboxStatus']>;
58
60
  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;
@@ -10,6 +13,7 @@ export declare class ApiClient {
10
13
  getPopupForms(options: IMapRequest['getPopupForms']): Promise<IMapResponse['getPopupForms']>;
11
14
  getPopupFormContent(options: IMapRequest['getPopupFormContent']): Promise<IMapResponse['getPopupFormContent']>;
12
15
  recordPopupFormEvent(options: IMapRequest['recordPopupFormEvent']): Promise<IMapResponse['recordPopupFormEvent']>;
16
+ submitPopupForm(options: IMapRequest['submitPopupForm']): Promise<IMapResponse['submitPopupForm']>;
13
17
  applicationOpen(options: IMapRequest['applicationOpen']): Promise<IMapResponse['applicationOpen']>;
14
18
  registerDevice(options: IMapRequest['registerDevice']): Promise<IMapResponse['registerDevice']>;
15
19
  unregisterDevice(options: IMapRequest['unregisterDevice']): Promise<IMapResponse['unregisterDevice']>;
@@ -22,7 +26,7 @@ export declare class ApiClient {
22
26
  registerEmail(options: IMapRequest['registerEmail']): Promise<IMapResponse['registerEmail']>;
23
27
  registerEmailUser(options: IMapRequest['registerEmailUser']): Promise<IMapResponse['registerEmailUser']>;
24
28
  setEmailTags(options: IMapRequest['setEmailTags']): Promise<IMapResponse['setEmailTags']>;
25
- postEvent(options: IMapRequest['postEvent']): Promise<IMapResponse['postEvent']>;
29
+ postEvent(options: IMapRequest['postEvent'], init?: IRequestInit): Promise<IMapResponse['postEvent']>;
26
30
  getInboxMessages(options: IMapRequest['getInboxMessages']): Promise<IMapResponse['getInboxMessages']>;
27
31
  inboxStatus(options: IMapRequest['inboxStatus']): Promise<IMapResponse['inboxStatus']>;
28
32
  multiRegisterDevice(options: IMapRequest['multiRegisterDevice']): Promise<IMapResponse['multiRegisterDevice']>;
@@ -21,6 +21,7 @@ type TMethodRegisterWhatsappNumber = 'registerWhatsappNumber';
21
21
  type TMethodGetPopupForms = 'getPopupForms';
22
22
  type TMethodGetPopupFormContent = 'getPopupFormContent';
23
23
  type TMethodRecordPopupFormEvent = 'recordPopupFormEvent';
24
+ type TMethodSubmitPopupForm = 'submitPopupForm';
24
25
  type TMethodSetEmailTags = 'setEmailTags';
25
26
  type TMethodPostEvent = 'postEvent';
26
27
  type TMethodGetInboxMessages = 'getInboxMessages';
@@ -55,6 +56,12 @@ interface IRequestRecordPopupFormEvent extends IRequest {
55
56
  code: string;
56
57
  event: 1 | 2;
57
58
  }
59
+ interface IRequestSubmitPopupForm extends IRequest {
60
+ code: string;
61
+ email?: string;
62
+ tags: Record<string, unknown>;
63
+ policy_accepted: boolean;
64
+ }
58
65
  interface IRequestApplicationOpen extends IRequest {
59
66
  push_permission_status?: TPushPermissionStatus;
60
67
  }
@@ -150,6 +157,9 @@ interface IResponseGetPopupFormContent {
150
157
  json: string;
151
158
  html: string | null;
152
159
  }
160
+ interface IResponseSubmitPopupForm {
161
+ result: 'OK' | 'INVALID_EMAIL';
162
+ }
153
163
  interface IResponseGetTags {
154
164
  result: {
155
165
  [key: string]: any;
@@ -164,7 +174,7 @@ interface IResponseGetInboxMessages {
164
174
  deleted: Array<string>;
165
175
  new_inbox: number;
166
176
  }
167
- export type TMethod = TMethodCheckDevice | TMethodGetConfig | TMethodApplicationOpen | TMethodRegisterDevice | TMethodUnregisterDevice | TMethodDeleteDevice | TMethodMessageDeliveryEvent | TMethodPushStat | TMethodSetTags | TMethodGetTags | TMethodRegisterUser | TMethodRegisterEmail | TMethodRegisterEmailUser | TMethodRegisterSmsNumber | TMethodRegisterWhatsappNumber | TMethodGetPopupForms | TMethodGetPopupFormContent | TMethodRecordPopupFormEvent | TMethodSetEmailTags | TMethodPostEvent | TMethodGetInboxMessages | TMethodInboxStatus | TMethodMultiRegisterDevice;
177
+ export type TMethod = TMethodCheckDevice | TMethodGetConfig | TMethodApplicationOpen | TMethodRegisterDevice | TMethodUnregisterDevice | TMethodDeleteDevice | TMethodMessageDeliveryEvent | TMethodPushStat | TMethodSetTags | TMethodGetTags | TMethodRegisterUser | TMethodRegisterEmail | TMethodRegisterEmailUser | TMethodRegisterSmsNumber | TMethodRegisterWhatsappNumber | TMethodGetPopupForms | TMethodGetPopupFormContent | TMethodRecordPopupFormEvent | TMethodSubmitPopupForm | TMethodSetEmailTags | TMethodPostEvent | TMethodGetInboxMessages | TMethodInboxStatus | TMethodMultiRegisterDevice;
168
178
  export interface IMapRequest {
169
179
  checkDevice: IRequest;
170
180
  getConfig: IRequestGetConfig;
@@ -184,6 +194,7 @@ export interface IMapRequest {
184
194
  getPopupForms: IRequest;
185
195
  getPopupFormContent: IRequestGetPopupFormContent;
186
196
  recordPopupFormEvent: IRequestRecordPopupFormEvent;
197
+ submitPopupForm: IRequestSubmitPopupForm;
187
198
  setEmailTags: IRequestSetEmailTags;
188
199
  postEvent: IRequestPostEvent;
189
200
  getInboxMessages: IRequestGetInboxMessages;
@@ -209,6 +220,7 @@ export interface IMapResponse {
209
220
  getPopupForms: IResponseGetPopupForms;
210
221
  getPopupFormContent: IResponseGetPopupFormContent;
211
222
  recordPopupFormEvent: IResponse;
223
+ submitPopupForm: IResponseSubmitPopupForm;
212
224
  setEmailTags: IResponse;
213
225
  postEvent: IResponsePostEvent;
214
226
  getInboxMessages: IResponseGetInboxMessages;
@@ -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
+ }