@liquidcommercedev/rmn-sdk 1.5.0-beta.1 → 1.5.0-beta.3

Sign up to get free protection for your applications and to get access to all the features.
package/dist/index.cjs CHANGED
@@ -3,6 +3,7 @@
3
3
  exports.RMN_SPOT_TYPE = void 0;
4
4
  (function (RMN_SPOT_TYPE) {
5
5
  // Reserve Bar Spot Types
6
+ RMN_SPOT_TYPE["RB_HOMEPAGE_HERO"] = "rbHomepageHero";
6
7
  RMN_SPOT_TYPE["RB_HOMEPAGE_HERO_THREE_TILE"] = "rbHomepageHeroThreeTile";
7
8
  RMN_SPOT_TYPE["RB_HOMEPAGE_HERO_TWO_TILE"] = "rbHomepageHeroTwoTile";
8
9
  RMN_SPOT_TYPE["RB_HOMEPAGE_HERO_FULL_IMAGE"] = "rbHomepageHeroFullImage";
@@ -18196,7 +18197,8 @@ class EventService {
18196
18197
  })();
18197
18198
  }
18198
18199
  /**
18199
- * Fires an event using the navigator.sendBeacon method and redirects the user if the event is a click event.
18200
+ * Fires an event using the navigator.sendBeacon method or a fallback method if sendBeacon is not available.
18201
+ * If the event is a click event and a redirect URL is found, it redirects the user to that URL.
18200
18202
  *
18201
18203
  * @param {IFireEventParams} params - The parameters for firing the event.
18202
18204
  * @param {RMN_SPOT_EVENT} params.event - The event type.
@@ -18204,26 +18206,65 @@ class EventService {
18204
18206
  * @returns {Promise<void>} - A promise that resolves when the event is fired.
18205
18207
  */
18206
18208
  async fireEvent({ event, eventUrl }) {
18207
- const didFireEvent = navigator.sendBeacon(eventUrl);
18208
- if (didFireEvent && event === exports.RMN_SPOT_EVENT.CLICK) {
18209
- window.location.href = this.getRedirectUrlFromPayload(eventUrl);
18209
+ var _a;
18210
+ try {
18211
+ const didFireEvent = ((_a = navigator === null || navigator === void 0 ? void 0 : navigator.sendBeacon) === null || _a === void 0 ? void 0 : _a.call(navigator, eventUrl)) || (await this.fallbackEventFire(eventUrl));
18212
+ if (!didFireEvent) {
18213
+ return;
18214
+ }
18215
+ if (event === exports.RMN_SPOT_EVENT.CLICK) {
18216
+ const redirectUrl = this.getRedirectUrlFromPayload(eventUrl);
18217
+ if (redirectUrl) {
18218
+ window.location.href = redirectUrl;
18219
+ }
18220
+ }
18221
+ }
18222
+ catch (_b) {
18223
+ // Handle errors silently
18224
+ }
18225
+ }
18226
+ // Fallback method using fetch if sendBeacon isn't available
18227
+ async fallbackEventFire(url) {
18228
+ try {
18229
+ const racePromise = Promise.race([
18230
+ // Promise #1: The fetch request
18231
+ fetch(url, {
18232
+ method: 'POST',
18233
+ keepalive: true,
18234
+ }),
18235
+ // Promise #2: The timeout
18236
+ new Promise((_, reject) => setTimeout(() => reject(new Error('Request timeout')), 2000)),
18237
+ ]);
18238
+ /**
18239
+ * Prevent requests from hanging indefinitely
18240
+ * Improve user experience by failing fast
18241
+ * Handle slow network conditions gracefully
18242
+ * Ensure resources are freed up in a timely manner
18243
+ */
18244
+ const response = await racePromise;
18245
+ return response.ok;
18246
+ }
18247
+ catch (_a) {
18248
+ return false;
18210
18249
  }
18211
18250
  }
18212
18251
  /**
18213
18252
  * Extracts and decodes a URL from a base64-encoded query parameter.
18214
18253
  *
18215
18254
  * @param {string} url - The URL containing the base64-encoded query parameter.
18216
- * @returns {string} - The decoded URL or an empty string if decoding fails.
18255
+ * @returns {string | null} - The decoded URL or null if not found or invalid.
18217
18256
  */
18218
18257
  getRedirectUrlFromPayload(url) {
18219
- var _a, _b;
18220
- const base64String = (_a = new URL(url).searchParams.get('e')) !== null && _a !== void 0 ? _a : '';
18221
18258
  try {
18259
+ const base64String = new URL(url).searchParams.get('e');
18260
+ if (!base64String) {
18261
+ return null;
18262
+ }
18222
18263
  const data = JSON.parse(atob(base64String));
18223
- return (_b = data.ur) !== null && _b !== void 0 ? _b : '';
18264
+ return data.ur || null;
18224
18265
  }
18225
- catch (_c) {
18226
- return '';
18266
+ catch (_a) {
18267
+ return null;
18227
18268
  }
18228
18269
  }
18229
18270
  }
package/dist/index.esm.js CHANGED
@@ -1,6 +1,7 @@
1
1
  var RMN_SPOT_TYPE;
2
2
  (function (RMN_SPOT_TYPE) {
3
3
  // Reserve Bar Spot Types
4
+ RMN_SPOT_TYPE["RB_HOMEPAGE_HERO"] = "rbHomepageHero";
4
5
  RMN_SPOT_TYPE["RB_HOMEPAGE_HERO_THREE_TILE"] = "rbHomepageHeroThreeTile";
5
6
  RMN_SPOT_TYPE["RB_HOMEPAGE_HERO_TWO_TILE"] = "rbHomepageHeroTwoTile";
6
7
  RMN_SPOT_TYPE["RB_HOMEPAGE_HERO_FULL_IMAGE"] = "rbHomepageHeroFullImage";
@@ -18194,7 +18195,8 @@ class EventService {
18194
18195
  })();
18195
18196
  }
18196
18197
  /**
18197
- * Fires an event using the navigator.sendBeacon method and redirects the user if the event is a click event.
18198
+ * Fires an event using the navigator.sendBeacon method or a fallback method if sendBeacon is not available.
18199
+ * If the event is a click event and a redirect URL is found, it redirects the user to that URL.
18198
18200
  *
18199
18201
  * @param {IFireEventParams} params - The parameters for firing the event.
18200
18202
  * @param {RMN_SPOT_EVENT} params.event - The event type.
@@ -18202,26 +18204,65 @@ class EventService {
18202
18204
  * @returns {Promise<void>} - A promise that resolves when the event is fired.
18203
18205
  */
18204
18206
  async fireEvent({ event, eventUrl }) {
18205
- const didFireEvent = navigator.sendBeacon(eventUrl);
18206
- if (didFireEvent && event === RMN_SPOT_EVENT.CLICK) {
18207
- window.location.href = this.getRedirectUrlFromPayload(eventUrl);
18207
+ var _a;
18208
+ try {
18209
+ const didFireEvent = ((_a = navigator === null || navigator === void 0 ? void 0 : navigator.sendBeacon) === null || _a === void 0 ? void 0 : _a.call(navigator, eventUrl)) || (await this.fallbackEventFire(eventUrl));
18210
+ if (!didFireEvent) {
18211
+ return;
18212
+ }
18213
+ if (event === RMN_SPOT_EVENT.CLICK) {
18214
+ const redirectUrl = this.getRedirectUrlFromPayload(eventUrl);
18215
+ if (redirectUrl) {
18216
+ window.location.href = redirectUrl;
18217
+ }
18218
+ }
18219
+ }
18220
+ catch (_b) {
18221
+ // Handle errors silently
18222
+ }
18223
+ }
18224
+ // Fallback method using fetch if sendBeacon isn't available
18225
+ async fallbackEventFire(url) {
18226
+ try {
18227
+ const racePromise = Promise.race([
18228
+ // Promise #1: The fetch request
18229
+ fetch(url, {
18230
+ method: 'POST',
18231
+ keepalive: true,
18232
+ }),
18233
+ // Promise #2: The timeout
18234
+ new Promise((_, reject) => setTimeout(() => reject(new Error('Request timeout')), 2000)),
18235
+ ]);
18236
+ /**
18237
+ * Prevent requests from hanging indefinitely
18238
+ * Improve user experience by failing fast
18239
+ * Handle slow network conditions gracefully
18240
+ * Ensure resources are freed up in a timely manner
18241
+ */
18242
+ const response = await racePromise;
18243
+ return response.ok;
18244
+ }
18245
+ catch (_a) {
18246
+ return false;
18208
18247
  }
18209
18248
  }
18210
18249
  /**
18211
18250
  * Extracts and decodes a URL from a base64-encoded query parameter.
18212
18251
  *
18213
18252
  * @param {string} url - The URL containing the base64-encoded query parameter.
18214
- * @returns {string} - The decoded URL or an empty string if decoding fails.
18253
+ * @returns {string | null} - The decoded URL or null if not found or invalid.
18215
18254
  */
18216
18255
  getRedirectUrlFromPayload(url) {
18217
- var _a, _b;
18218
- const base64String = (_a = new URL(url).searchParams.get('e')) !== null && _a !== void 0 ? _a : '';
18219
18256
  try {
18257
+ const base64String = new URL(url).searchParams.get('e');
18258
+ if (!base64String) {
18259
+ return null;
18260
+ }
18220
18261
  const data = JSON.parse(atob(base64String));
18221
- return (_b = data.ur) !== null && _b !== void 0 ? _b : '';
18262
+ return data.ur || null;
18222
18263
  }
18223
- catch (_c) {
18224
- return '';
18264
+ catch (_a) {
18265
+ return null;
18225
18266
  }
18226
18267
  }
18227
18268
  }
@@ -1,4 +1,5 @@
1
1
  export declare enum RMN_SPOT_TYPE {
2
+ RB_HOMEPAGE_HERO = "rbHomepageHero",
2
3
  RB_HOMEPAGE_HERO_THREE_TILE = "rbHomepageHeroThreeTile",
3
4
  RB_HOMEPAGE_HERO_TWO_TILE = "rbHomepageHeroTwoTile",
4
5
  RB_HOMEPAGE_HERO_FULL_IMAGE = "rbHomepageHeroFullImage",
@@ -1,4 +1,4 @@
1
- import type { RMN_SPOT_TYPE } from 'enums';
1
+ import type { RMN_FILTER_PROPERTIES, RMN_SPOT_TYPE } from 'enums';
2
2
  import type { ICarouselOptions, ICreateCarouselElementParams } from 'modules/element/component/carousel';
3
3
  import type { ICreateSpotElementParams } from 'modules/element/component/spot';
4
4
  import type { RmnFilterType } from 'modules/selection';
@@ -21,12 +21,15 @@ export interface IInjectSpotElementConfig {
21
21
  overlay?: ISpotOverlay;
22
22
  carousel?: ICarouselOptions;
23
23
  }
24
+ export type IInjectSpotElementFilterType = Partial<Omit<RmnFilterType, RMN_FILTER_PROPERTIES.KEYWORDS> & {
25
+ exactMatch?: string;
26
+ }>;
24
27
  export interface IInjectSpotElement {
25
28
  placementId: string;
26
29
  spotType: RMN_SPOT_TYPE | string;
27
30
  count?: number;
28
31
  config?: Omit<IInjectSpotElementConfig, 'url'>;
29
- filter?: Partial<RmnFilterType>;
32
+ filter?: IInjectSpotElementFilterType;
30
33
  }
31
34
  export interface ICreateElementConfig {
32
35
  spot?: RMN_SPOT_TYPE;
@@ -27,7 +27,8 @@ export declare class EventService {
27
27
  private handleIntersectionObserver;
28
28
  private fireImpressionEvent;
29
29
  /**
30
- * Fires an event using the navigator.sendBeacon method and redirects the user if the event is a click event.
30
+ * Fires an event using the navigator.sendBeacon method or a fallback method if sendBeacon is not available.
31
+ * If the event is a click event and a redirect URL is found, it redirects the user to that URL.
31
32
  *
32
33
  * @param {IFireEventParams} params - The parameters for firing the event.
33
34
  * @param {RMN_SPOT_EVENT} params.event - The event type.
@@ -35,11 +36,12 @@ export declare class EventService {
35
36
  * @returns {Promise<void>} - A promise that resolves when the event is fired.
36
37
  */
37
38
  private fireEvent;
39
+ private fallbackEventFire;
38
40
  /**
39
41
  * Extracts and decodes a URL from a base64-encoded query parameter.
40
42
  *
41
43
  * @param {string} url - The URL containing the base64-encoded query parameter.
42
- * @returns {string} - The decoded URL or an empty string if decoding fails.
44
+ * @returns {string | null} - The decoded URL or null if not found or invalid.
43
45
  */
44
46
  private getRedirectUrlFromPayload;
45
47
  }
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@liquidcommercedev/rmn-sdk",
3
3
  "description": "LiquidCommerce RMN SDK",
4
4
  "author": "LiquidCommerce Tech",
5
- "version": "1.5.0-beta.1",
5
+ "version": "1.5.0-beta.3",
6
6
  "homepage": "https://docs.liquidcommerce.co/rmn-sdk",
7
7
  "main": "./dist/index.cjs",
8
8
  "module": "./dist/index.esm.js",