@liquidcommercedev/rmn-sdk 1.5.0-beta.12 → 1.5.0-beta.13
Sign up to get free protection for your applications and to get access to all the features.
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
|
6885
|
-
|
6886
|
-
'
|
6887
|
-
'
|
6888
|
-
'
|
6889
|
-
'
|
6890
|
-
'
|
6891
|
-
'
|
6892
|
-
'
|
6893
|
-
'
|
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
|
-
'
|
6896
|
-
'variant_id',
|
6906
|
+
'item_variant',
|
6897
6907
|
'item_number',
|
6898
|
-
'
|
6899
|
-
'
|
6908
|
+
'article_number',
|
6909
|
+
'reference',
|
6910
|
+
'groupingId',
|
6900
6911
|
];
|
6901
|
-
//
|
6902
|
-
const
|
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 &&
|
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;
|
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
|
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
|
6883
|
-
|
6884
|
-
'
|
6885
|
-
'
|
6886
|
-
'
|
6887
|
-
'
|
6888
|
-
'
|
6889
|
-
'
|
6890
|
-
'
|
6891
|
-
'
|
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
|
-
'
|
6894
|
-
'variant_id',
|
6904
|
+
'item_variant',
|
6895
6905
|
'item_number',
|
6896
|
-
'
|
6897
|
-
'
|
6906
|
+
'article_number',
|
6907
|
+
'reference',
|
6908
|
+
'groupingId',
|
6898
6909
|
];
|
6899
|
-
//
|
6900
|
-
const
|
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 &&
|
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;
|
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
|
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>;
|
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.
|
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",
|