@constructor-io/constructorio-client-javascript 2.36.4 → 2.37.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/lib/types/types.d.ts +126 -0
- package/lib/utils/helpers.js +42 -0
- package/lib/utils/request-queue.js +7 -0
- package/package.json +1 -1
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import EventDispatcher from './event-dispatcher';
|
|
2
|
+
|
|
3
|
+
export interface ConstructorClientOptions {
|
|
4
|
+
apiKey: string;
|
|
5
|
+
version?: string;
|
|
6
|
+
serviceUrl?: string;
|
|
7
|
+
// session id is of type string in jsdocs but of type number in code usage
|
|
8
|
+
sessionId?: string;
|
|
9
|
+
clientId?: string;
|
|
10
|
+
userId?: string;
|
|
11
|
+
segments?: string[];
|
|
12
|
+
testCells?: Record<string, string>;
|
|
13
|
+
fetch?: any;
|
|
14
|
+
trackingSendDelay?: number;
|
|
15
|
+
sendTrackingEvents?: boolean;
|
|
16
|
+
sendReferrerWithTrackingEvents?: boolean;
|
|
17
|
+
eventDispatcher?: EventDispatcher;
|
|
18
|
+
beaconMode?: boolean;
|
|
19
|
+
networkParameters?: {
|
|
20
|
+
timeout: number;
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface RequestFeature extends Record<string, any> {
|
|
25
|
+
query_items: boolean;
|
|
26
|
+
auto_generated_refined_query_rules: boolean;
|
|
27
|
+
manual_searchandizing: boolean;
|
|
28
|
+
personalization: boolean;
|
|
29
|
+
filter_items: boolean;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export interface RequestFeatureVariant extends Record<string, any> {
|
|
33
|
+
query_items: string;
|
|
34
|
+
auto_generated_refined_query_rules: string;
|
|
35
|
+
manual_searchandizing: string | null;
|
|
36
|
+
personalization: string;
|
|
37
|
+
filter_items: string;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export type ErrorData = {
|
|
41
|
+
message: string;
|
|
42
|
+
[key: string]: any;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
export interface ResultSources extends Record<string, any> {
|
|
46
|
+
token_match: { count: number; [key: string]: any };
|
|
47
|
+
embeddings_match: { count: number; [key: string]: any };
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export interface SortOption extends Record<string, any> {
|
|
51
|
+
sort_by: string;
|
|
52
|
+
display_name: string;
|
|
53
|
+
sort_order: string;
|
|
54
|
+
status: string;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export interface Feature extends Record<string, any> {
|
|
58
|
+
feature_name: string;
|
|
59
|
+
display_name: string;
|
|
60
|
+
enabled: boolean;
|
|
61
|
+
variant: {
|
|
62
|
+
name: string;
|
|
63
|
+
display_name: string;
|
|
64
|
+
[key: string]: any;
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export interface FmtOption extends Record<string, any> {
|
|
69
|
+
groups_start: string;
|
|
70
|
+
groups_max_depth: number;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
type Facet = RangeFacet | OptionFacet;
|
|
74
|
+
|
|
75
|
+
export interface BaseFacet extends Record<string, any> {
|
|
76
|
+
data: Record<string, any>;
|
|
77
|
+
status: Record<string, any>;
|
|
78
|
+
display_name: string;
|
|
79
|
+
name: string;
|
|
80
|
+
hidden: boolean;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export interface RangeFacet extends BaseFacet, Record<string, any> {
|
|
84
|
+
max: number;
|
|
85
|
+
min: number;
|
|
86
|
+
type: "range";
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export interface OptionFacet extends BaseFacet, Record<string, any> {
|
|
90
|
+
options: FacetOption[];
|
|
91
|
+
type: "multiple" | "single" | "hierarchical";
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export interface FacetOption extends Record<string, any> {
|
|
95
|
+
count: number;
|
|
96
|
+
display_name: string;
|
|
97
|
+
value: string;
|
|
98
|
+
options?: FacetOption[];
|
|
99
|
+
range?: ["-inf" | number, "inf" | number];
|
|
100
|
+
status: string;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export interface Group extends BaseGroup, Record<string, any> {
|
|
104
|
+
count: number;
|
|
105
|
+
data: Record<string, any>;
|
|
106
|
+
parents: BaseGroup[];
|
|
107
|
+
children: Group[];
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export interface Collection extends Record<string, any> {
|
|
111
|
+
collection_id: string,
|
|
112
|
+
display_name: string,
|
|
113
|
+
data: Record<string, any>
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export interface BaseGroup extends Record<string, any> {
|
|
117
|
+
display_name: string;
|
|
118
|
+
group_id: string;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export interface FmtOptions extends Record<string, any> {
|
|
122
|
+
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
export type Nullable<T> = T | null;
|
|
126
|
+
|
package/lib/utils/helpers.js
CHANGED
|
@@ -10,6 +10,13 @@ var CRC32 = require('crc-32');
|
|
|
10
10
|
var store = require('./store');
|
|
11
11
|
|
|
12
12
|
var purchaseEventStorageKey = '_constructorio_purchase_order_ids';
|
|
13
|
+
var PII_REGEX = {
|
|
14
|
+
email: /^[\w\-+\\.]+@([\w-]+\.)+[\w-]{2,4}$/,
|
|
15
|
+
phoneNumber: /^(?:\+\d{11,12}|\+\d{1,3}\s\d{3}\s\d{3}\s\d{3,4}|\(\d{3}\)\d{7}|\(\d{3}\)\s\d{3}\s\d{4}|\(\d{3}\)\d{3}-\d{4}|\(\d{3}\)\s\d{3}-\d{4})$/,
|
|
16
|
+
creditCard: /^(?:4[0-9]{12}(?:[0-9]{3})?|(?:5[1-5][0-9]{2}|222[1-9]|22[3-9][0-9]|2[3-6][0-9]{2}|27[01][0-9]|2720)[0-9]{12}|3[47][0-9]{13}|3(?:0[0-5]|[68][0-9])[0-9]{11}|6(?:011|5[0-9]{2})[0-9]{12}|(?:2131|1800|35\d{3})\d{11})$/ // Visa, Mastercard, Amex, Discover, JCB and Diners Club, regex source: https://www.regular-expressions.info/creditcard.html
|
|
17
|
+
// Add more PII REGEX
|
|
18
|
+
|
|
19
|
+
};
|
|
13
20
|
var utils = {
|
|
14
21
|
trimNonBreakingSpaces: function trimNonBreakingSpaces(string) {
|
|
15
22
|
return string.replace(/\s/g, ' ').trim();
|
|
@@ -197,6 +204,41 @@ var utils = {
|
|
|
197
204
|
snakeCasedObj[newKey] = toRecurse && (0, _typeof2["default"])(camelCasedObj[key]) === 'object' && !Array.isArray(camelCasedObj[key]) ? utils.toSnakeCaseKeys(camelCasedObj[key], toRecurse) : camelCasedObj[key];
|
|
198
205
|
});
|
|
199
206
|
return snakeCasedObj;
|
|
207
|
+
},
|
|
208
|
+
containsPii: function containsPii(query) {
|
|
209
|
+
var piiRegex = Object.values(PII_REGEX);
|
|
210
|
+
var normalizedTerm = query.toLowerCase();
|
|
211
|
+
return piiRegex.some(function (regex) {
|
|
212
|
+
return regex.test(normalizedTerm);
|
|
213
|
+
});
|
|
214
|
+
},
|
|
215
|
+
requestContainsPii: function requestContainsPii(urlString) {
|
|
216
|
+
try {
|
|
217
|
+
var _decodeURI, _decodeURIComponent;
|
|
218
|
+
|
|
219
|
+
var url = new URL(urlString);
|
|
220
|
+
var paths = (_decodeURI = decodeURI(url === null || url === void 0 ? void 0 : url.pathname)) === null || _decodeURI === void 0 ? void 0 : _decodeURI.split('/');
|
|
221
|
+
var paramValues = (_decodeURIComponent = decodeURIComponent(url === null || url === void 0 ? void 0 : url.search)) === null || _decodeURIComponent === void 0 ? void 0 : _decodeURIComponent.split('&').map(function (param) {
|
|
222
|
+
var _param$split;
|
|
223
|
+
|
|
224
|
+
return param === null || param === void 0 ? void 0 : (_param$split = param.split('=')) === null || _param$split === void 0 ? void 0 : _param$split[1];
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
if (paths.some(function (path) {
|
|
228
|
+
return utils.containsPii(path);
|
|
229
|
+
})) {
|
|
230
|
+
return true;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
if (paramValues.some(function (value) {
|
|
234
|
+
return utils.containsPii(value);
|
|
235
|
+
})) {
|
|
236
|
+
return true;
|
|
237
|
+
}
|
|
238
|
+
} catch (e) {// do nothing
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
return false;
|
|
200
242
|
}
|
|
201
243
|
};
|
|
202
244
|
module.exports = utils;
|
|
@@ -13,6 +13,9 @@ var HumanityCheck = require('./humanity-check');
|
|
|
13
13
|
|
|
14
14
|
var helpers = require('./helpers');
|
|
15
15
|
|
|
16
|
+
var _require = require('./helpers'),
|
|
17
|
+
requestContainsPii = _require.requestContainsPii;
|
|
18
|
+
|
|
16
19
|
var storageKey = '_constructorio_requests';
|
|
17
20
|
var requestTTL = 180000; // 3 minutes in milliseconds
|
|
18
21
|
|
|
@@ -47,6 +50,10 @@ var RequestQueue = /*#__PURE__*/function () {
|
|
|
47
50
|
var networkParameters = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
|
48
51
|
|
|
49
52
|
if (this.sendTrackingEvents && !this.humanity.isBot()) {
|
|
53
|
+
if (requestContainsPii(url, body)) {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
|
|
50
57
|
var queue = RequestQueue.get();
|
|
51
58
|
queue.push({
|
|
52
59
|
url: url,
|