@liquidcommercedev/rmn-sdk 1.5.0-beta.12 → 1.5.0-beta.13

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/dist/index.cjs CHANGED
@@ -6866,40 +6866,60 @@ class ObjectHelper {
6866
6866
  /**
6867
6867
  * Recursively extracts ID values from a nested data structure.
6868
6868
  * Searches for specified property names and collects their primitive values (strings/numbers).
6869
+ * Captures properties ending with 'id' and any additional specified property names.
6869
6870
  *
6870
6871
  * @param data - The data structure to search through (can be nested objects/arrays)
6871
- * @param propertyNames - Array of property names to look for
6872
+ * @param propertyNames - Array of additional property names to look for (optional)
6872
6873
  * @returns Array of extracted ID values (strings/numbers only)
6873
6874
  *
6874
6875
  * @example
6875
6876
  * const data = {
6876
6877
  * id: [1, 2, 3],
6877
- * nested: { id: 'abc' },
6878
- * items: [{ id: 456 }]
6878
+ * nested: { id: 'abc', userId: 123 },
6879
+ * items: [{ id: 456, productId: '789', sku: 'ABC123' }]
6879
6880
  * };
6880
- * extractDeepIds(data); // Returns [1, 2, 3, 'abc', 456]
6881
+ * extractDeepIds(data); // Returns [1, 2, 3, 'abc', 123, 456, '789', 'ABC123']
6881
6882
  */
6882
6883
  function extractDeepIds(data, propertyNames) {
6883
6884
  const ids = [];
6884
- const defaulPropertyNames = [
6885
- 'id',
6886
- 'upc',
6887
- 'groupingId',
6888
- 'sku',
6889
- 'productId',
6890
- 'item_id',
6891
- 'isbn',
6892
- 'asin',
6893
- 'mpn',
6885
+ const defaultPropertyNames = [
6886
+ // Universal product identifiers
6887
+ 'gtin', // Global Trade Item Number
6888
+ 'gtin8', // 8-digit GTIN
6889
+ 'gtin12', // 12-digit GTIN (UPC)
6890
+ 'gtin13', // 13-digit GTIN (EAN)
6891
+ 'gtin14', // 14-digit GTIN
6892
+ 'mpn', // Manufacturer Part Number
6893
+ 'sku', // Stock Keeping Unit
6894
+ 'upc', // Universal Product Code
6895
+ 'ean', // European Article Number
6896
+ 'isbn', // International Standard Book Number
6897
+ 'isbn10', // 10-digit ISBN
6898
+ 'isbn13', // 13-digit ISBN
6899
+ 'asin', // Amazon Standard Identification Number
6900
+ // Product codes and references
6901
+ 'coupon',
6902
+ 'barcode',
6903
+ 'product_code',
6904
+ 'part_number',
6894
6905
  'model_number',
6895
- 'article_number',
6896
- 'variant_id',
6906
+ 'item_variant',
6897
6907
  'item_number',
6898
- 'catalog_id',
6899
- 'reference_id',
6908
+ 'article_number',
6909
+ 'reference',
6910
+ 'groupingId',
6900
6911
  ];
6901
- // Set for faster property name lookups
6902
- const propertySet = new Set(defaulPropertyNames);
6912
+ // Convert property names to lowercase for consistent comparison
6913
+ const additionalProperties = new Set((defaultPropertyNames).map((name) => name.toLowerCase()));
6914
+ /**
6915
+ * Checks if a property name is an ID field
6916
+ * @param key - The property name to check
6917
+ * @returns boolean indicating if the key is an ID field
6918
+ */
6919
+ const isIdField = (key) => {
6920
+ const lowercaseKey = key.toLowerCase();
6921
+ return lowercaseKey.endsWith('id') || additionalProperties.has(lowercaseKey);
6922
+ };
6903
6923
  /**
6904
6924
  * Processes a value and extracts IDs if it matches criteria
6905
6925
  * @param value - The value to process
@@ -6910,7 +6930,7 @@ function extractDeepIds(data, propertyNames) {
6910
6930
  if (value == null)
6911
6931
  return;
6912
6932
  // If current key matches our target properties
6913
- if (currentKey && propertySet.has(currentKey)) {
6933
+ if (currentKey && isIdField(currentKey)) {
6914
6934
  if (Array.isArray(value)) {
6915
6935
  // Filter and push valid array values in one pass
6916
6936
  ids.push(...value.filter((item) => typeof item === 'string' || typeof item === 'number'));
@@ -6932,7 +6952,7 @@ function extractDeepIds(data, propertyNames) {
6932
6952
  }
6933
6953
  };
6934
6954
  processValue(data);
6935
- return ids; // No need to filter nulls as we handle that during collection
6955
+ return ids;
6936
6956
  }
6937
6957
  // Fallback method using fetch if sendBeacon isn't available
6938
6958
  async function fallbackEventFire(url) {
@@ -18986,7 +19006,7 @@ class DataLayerMonitor {
18986
19006
  if (!eventName) {
18987
19007
  return null;
18988
19008
  }
18989
- const productIds = extractDeepIds(data.value);
19009
+ const productIds = extractDeepIds(data);
18990
19010
  return {
18991
19011
  event: eventName,
18992
19012
  productIds,
package/dist/index.esm.js CHANGED
@@ -6864,40 +6864,60 @@ class ObjectHelper {
6864
6864
  /**
6865
6865
  * Recursively extracts ID values from a nested data structure.
6866
6866
  * Searches for specified property names and collects their primitive values (strings/numbers).
6867
+ * Captures properties ending with 'id' and any additional specified property names.
6867
6868
  *
6868
6869
  * @param data - The data structure to search through (can be nested objects/arrays)
6869
- * @param propertyNames - Array of property names to look for
6870
+ * @param propertyNames - Array of additional property names to look for (optional)
6870
6871
  * @returns Array of extracted ID values (strings/numbers only)
6871
6872
  *
6872
6873
  * @example
6873
6874
  * const data = {
6874
6875
  * id: [1, 2, 3],
6875
- * nested: { id: 'abc' },
6876
- * items: [{ id: 456 }]
6876
+ * nested: { id: 'abc', userId: 123 },
6877
+ * items: [{ id: 456, productId: '789', sku: 'ABC123' }]
6877
6878
  * };
6878
- * extractDeepIds(data); // Returns [1, 2, 3, 'abc', 456]
6879
+ * extractDeepIds(data); // Returns [1, 2, 3, 'abc', 123, 456, '789', 'ABC123']
6879
6880
  */
6880
6881
  function extractDeepIds(data, propertyNames) {
6881
6882
  const ids = [];
6882
- const defaulPropertyNames = [
6883
- 'id',
6884
- 'upc',
6885
- 'groupingId',
6886
- 'sku',
6887
- 'productId',
6888
- 'item_id',
6889
- 'isbn',
6890
- 'asin',
6891
- 'mpn',
6883
+ const defaultPropertyNames = [
6884
+ // Universal product identifiers
6885
+ 'gtin', // Global Trade Item Number
6886
+ 'gtin8', // 8-digit GTIN
6887
+ 'gtin12', // 12-digit GTIN (UPC)
6888
+ 'gtin13', // 13-digit GTIN (EAN)
6889
+ 'gtin14', // 14-digit GTIN
6890
+ 'mpn', // Manufacturer Part Number
6891
+ 'sku', // Stock Keeping Unit
6892
+ 'upc', // Universal Product Code
6893
+ 'ean', // European Article Number
6894
+ 'isbn', // International Standard Book Number
6895
+ 'isbn10', // 10-digit ISBN
6896
+ 'isbn13', // 13-digit ISBN
6897
+ 'asin', // Amazon Standard Identification Number
6898
+ // Product codes and references
6899
+ 'coupon',
6900
+ 'barcode',
6901
+ 'product_code',
6902
+ 'part_number',
6892
6903
  'model_number',
6893
- 'article_number',
6894
- 'variant_id',
6904
+ 'item_variant',
6895
6905
  'item_number',
6896
- 'catalog_id',
6897
- 'reference_id',
6906
+ 'article_number',
6907
+ 'reference',
6908
+ 'groupingId',
6898
6909
  ];
6899
- // Set for faster property name lookups
6900
- const propertySet = new Set(defaulPropertyNames);
6910
+ // Convert property names to lowercase for consistent comparison
6911
+ const additionalProperties = new Set((defaultPropertyNames).map((name) => name.toLowerCase()));
6912
+ /**
6913
+ * Checks if a property name is an ID field
6914
+ * @param key - The property name to check
6915
+ * @returns boolean indicating if the key is an ID field
6916
+ */
6917
+ const isIdField = (key) => {
6918
+ const lowercaseKey = key.toLowerCase();
6919
+ return lowercaseKey.endsWith('id') || additionalProperties.has(lowercaseKey);
6920
+ };
6901
6921
  /**
6902
6922
  * Processes a value and extracts IDs if it matches criteria
6903
6923
  * @param value - The value to process
@@ -6908,7 +6928,7 @@ function extractDeepIds(data, propertyNames) {
6908
6928
  if (value == null)
6909
6929
  return;
6910
6930
  // If current key matches our target properties
6911
- if (currentKey && propertySet.has(currentKey)) {
6931
+ if (currentKey && isIdField(currentKey)) {
6912
6932
  if (Array.isArray(value)) {
6913
6933
  // Filter and push valid array values in one pass
6914
6934
  ids.push(...value.filter((item) => typeof item === 'string' || typeof item === 'number'));
@@ -6930,7 +6950,7 @@ function extractDeepIds(data, propertyNames) {
6930
6950
  }
6931
6951
  };
6932
6952
  processValue(data);
6933
- return ids; // No need to filter nulls as we handle that during collection
6953
+ return ids;
6934
6954
  }
6935
6955
  // Fallback method using fetch if sendBeacon isn't available
6936
6956
  async function fallbackEventFire(url) {
@@ -18984,7 +19004,7 @@ class DataLayerMonitor {
18984
19004
  if (!eventName) {
18985
19005
  return null;
18986
19006
  }
18987
- const productIds = extractDeepIds(data.value);
19007
+ const productIds = extractDeepIds(data);
18988
19008
  return {
18989
19009
  event: eventName,
18990
19010
  productIds,
@@ -2,18 +2,19 @@ import type { IFireEventParams } from 'modules/event';
2
2
  /**
3
3
  * Recursively extracts ID values from a nested data structure.
4
4
  * Searches for specified property names and collects their primitive values (strings/numbers).
5
+ * Captures properties ending with 'id' and any additional specified property names.
5
6
  *
6
7
  * @param data - The data structure to search through (can be nested objects/arrays)
7
- * @param propertyNames - Array of property names to look for
8
+ * @param propertyNames - Array of additional property names to look for (optional)
8
9
  * @returns Array of extracted ID values (strings/numbers only)
9
10
  *
10
11
  * @example
11
12
  * const data = {
12
13
  * id: [1, 2, 3],
13
- * nested: { id: 'abc' },
14
- * items: [{ id: 456 }]
14
+ * nested: { id: 'abc', userId: 123 },
15
+ * items: [{ id: 456, productId: '789', sku: 'ABC123' }]
15
16
  * };
16
- * extractDeepIds(data); // Returns [1, 2, 3, 'abc', 456]
17
+ * extractDeepIds(data); // Returns [1, 2, 3, 'abc', 123, 456, '789', 'ABC123']
17
18
  */
18
19
  export declare function extractDeepIds(data: any, propertyNames?: string[]): Array<string | number>;
19
20
  export declare function fallbackEventFire(url: string): Promise<boolean>;
@@ -1,4 +1,8 @@
1
1
  import type { RMN_SPOT_EVENT } from 'enums';
2
+ export interface IDataLayerEvent {
3
+ event: string;
4
+ [key: string]: any;
5
+ }
2
6
  export interface INormalizedEventData {
3
7
  event: RMN_SPOT_EVENT;
4
8
  productIds: Array<string | number>;
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.12",
5
+ "version": "1.5.0-beta.13",
6
6
  "homepage": "https://docs.liquidcommerce.co/rmn-sdk",
7
7
  "main": "./dist/index.cjs",
8
8
  "module": "./dist/index.esm.js",