@convertcom/js-sdk-rules 1.0.1 → 2.0.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/index.d.ts +14 -8
- package/lib/index.js +45 -31
- package/lib/index.js.map +1 -1
- package/lib/index.min.js +1 -1
- package/lib/index.min.mjs +1 -1
- package/lib/index.mjs +46 -32
- package/lib/index.mjs.map +1 -1
- package/lib/legacy/index.js +56 -42
- package/lib/legacy/index.js.map +1 -1
- package/lib/legacy/index.min.js +1 -1
- package/lib/package.json +7 -1
- package/package.json +1 -1
package/lib/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { RuleObject, RuleElement, Config } from '@convertcom/js-sdk-types';
|
|
2
2
|
import { RuleError } from '@convertcom/js-sdk-enums';
|
|
3
3
|
import { LogManagerInterface } from '@convertcom/js-sdk-logger';
|
|
4
4
|
|
|
@@ -12,8 +12,8 @@ import { LogManagerInterface } from '@convertcom/js-sdk-logger';
|
|
|
12
12
|
interface RuleManagerInterface {
|
|
13
13
|
comparisonProcessor: Record<string, any>;
|
|
14
14
|
getComparisonProcessorMethods(): Array<string>;
|
|
15
|
-
isRuleMatched(data: Record<string, any>, ruleSet:
|
|
16
|
-
isValidRule(rule:
|
|
15
|
+
isRuleMatched(data: Record<string, any>, ruleSet: RuleObject, logEntry?: string): boolean | RuleError;
|
|
16
|
+
isValidRule(rule: RuleElement): boolean;
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
/**
|
|
@@ -53,16 +53,16 @@ declare class RuleManager implements RuleManagerInterface {
|
|
|
53
53
|
/**
|
|
54
54
|
* Check input data matching to rule set
|
|
55
55
|
* @param {Record<string, any>} data Single value or key-value data set to compare
|
|
56
|
-
* @param {
|
|
56
|
+
* @param {RuleObject} ruleSet
|
|
57
57
|
* @return {boolean | RuleError}
|
|
58
58
|
*/
|
|
59
|
-
isRuleMatched(data: Record<string, any>, ruleSet:
|
|
59
|
+
isRuleMatched(data: Record<string, any>, ruleSet: RuleObject, logEntry?: string): boolean | RuleError;
|
|
60
60
|
/**
|
|
61
61
|
* Check is rule object valid
|
|
62
|
-
* @param {
|
|
62
|
+
* @param {RuleElement} rule
|
|
63
63
|
* @return {boolean}
|
|
64
64
|
*/
|
|
65
|
-
isValidRule(rule:
|
|
65
|
+
isValidRule(rule: RuleElement): boolean;
|
|
66
66
|
/**
|
|
67
67
|
* Process AND block of rule set. Return first false if found
|
|
68
68
|
* @param {Record<string, any>} data Single value or key-value data set to compare
|
|
@@ -82,11 +82,17 @@ declare class RuleManager implements RuleManagerInterface {
|
|
|
82
82
|
/**
|
|
83
83
|
* Process single rule item
|
|
84
84
|
* @param {Record<string, any>} data Single value or key-value data set to compare
|
|
85
|
-
* @param {
|
|
85
|
+
* @param {RuleElement} rule A single rule to compare
|
|
86
86
|
* @return {boolean | RuleError} Comparison result
|
|
87
87
|
* @private
|
|
88
88
|
*/
|
|
89
89
|
private _processRuleItem;
|
|
90
|
+
/**
|
|
91
|
+
* Check is rule data object is a custom interface instead of a literal object
|
|
92
|
+
* @param {Record<string, any>} data Single value or key-value data set to compare
|
|
93
|
+
* @return {boolean}
|
|
94
|
+
*/
|
|
95
|
+
private isUsingCustomInterface;
|
|
90
96
|
}
|
|
91
97
|
|
|
92
98
|
export { RuleManager, type RuleManagerInterface };
|
package/lib/index.js
CHANGED
|
@@ -24,16 +24,18 @@ class RuleManager {
|
|
|
24
24
|
* @param {LogManagerInterface=} dependencies.loggerManager
|
|
25
25
|
*/
|
|
26
26
|
constructor(config, { loggerManager } = {}) {
|
|
27
|
-
var _a, _b;
|
|
27
|
+
var _a, _b, _c, _d, _e;
|
|
28
28
|
this._comparisonProcessor = jsSdkUtils.Comparisons;
|
|
29
29
|
this._negation = DEFAULT_NEGATION;
|
|
30
30
|
this._keys_case_sensitive = DEFAULT_KEYS_CASE_SENSITIVE;
|
|
31
31
|
this._loggerManager = loggerManager;
|
|
32
|
-
this._comparisonProcessor =
|
|
33
|
-
|
|
34
|
-
this.
|
|
32
|
+
this._comparisonProcessor =
|
|
33
|
+
((_a = config === null || config === void 0 ? void 0 : config.rules) === null || _a === void 0 ? void 0 : _a.comparisonProcessor) || jsSdkUtils.Comparisons;
|
|
34
|
+
this._negation = String(((_b = config === null || config === void 0 ? void 0 : config.rules) === null || _b === void 0 ? void 0 : _b.negation) || DEFAULT_NEGATION);
|
|
35
|
+
this._keys_case_sensitive =
|
|
36
|
+
((_c = config === null || config === void 0 ? void 0 : config.rules) === null || _c === void 0 ? void 0 : _c.keys_case_sensitive) || DEFAULT_KEYS_CASE_SENSITIVE;
|
|
35
37
|
this._mapper = (config === null || config === void 0 ? void 0 : config.mapper) || ((value) => value);
|
|
36
|
-
(
|
|
38
|
+
(_e = (_d = this._loggerManager) === null || _d === void 0 ? void 0 : _d.trace) === null || _e === void 0 ? void 0 : _e.call(_d, 'RuleManager()', jsSdkEnums.MESSAGES.RULE_CONSTRUCTOR, this);
|
|
37
39
|
}
|
|
38
40
|
/**
|
|
39
41
|
* Setter for comparison processor
|
|
@@ -58,7 +60,7 @@ class RuleManager {
|
|
|
58
60
|
/**
|
|
59
61
|
* Check input data matching to rule set
|
|
60
62
|
* @param {Record<string, any>} data Single value or key-value data set to compare
|
|
61
|
-
* @param {
|
|
63
|
+
* @param {RuleObject} ruleSet
|
|
62
64
|
* @return {boolean | RuleError}
|
|
63
65
|
*/
|
|
64
66
|
isRuleMatched(data, ruleSet, logEntry) {
|
|
@@ -96,7 +98,7 @@ class RuleManager {
|
|
|
96
98
|
}
|
|
97
99
|
/**
|
|
98
100
|
* Check is rule object valid
|
|
99
|
-
* @param {
|
|
101
|
+
* @param {RuleElement} rule
|
|
100
102
|
* @return {boolean}
|
|
101
103
|
*/
|
|
102
104
|
isValidRule(rule) {
|
|
@@ -169,7 +171,7 @@ class RuleManager {
|
|
|
169
171
|
/**
|
|
170
172
|
* Process single rule item
|
|
171
173
|
* @param {Record<string, any>} data Single value or key-value data set to compare
|
|
172
|
-
* @param {
|
|
174
|
+
* @param {RuleElement} rule A single rule to compare
|
|
173
175
|
* @return {boolean | RuleError} Comparison result
|
|
174
176
|
* @private
|
|
175
177
|
*/
|
|
@@ -180,38 +182,40 @@ class RuleManager {
|
|
|
180
182
|
const negation = rule.matching.negated || false;
|
|
181
183
|
const matching = rule.matching.match_type;
|
|
182
184
|
if (this.getComparisonProcessorMethods().indexOf(matching) !== -1) {
|
|
183
|
-
if (data && typeof data === 'object'
|
|
185
|
+
if (data && typeof data === 'object') {
|
|
184
186
|
// Validate data key-value set.
|
|
185
|
-
if (data
|
|
186
|
-
//
|
|
187
|
+
if (this.isUsingCustomInterface(data)) {
|
|
188
|
+
// RuleElement object has to have `rule_type` field
|
|
189
|
+
if (rule === null || rule === void 0 ? void 0 : rule.rule_type) {
|
|
190
|
+
(_b = (_a = this._loggerManager) === null || _a === void 0 ? void 0 : _a.info) === null || _b === void 0 ? void 0 : _b.call(_a, 'RuleManager._processRuleItem()', jsSdkEnums.MESSAGES.RULE_MATCH_START.replace('#', rule.rule_type));
|
|
191
|
+
for (const method of Object.getOwnPropertyNames(data.constructor.prototype)) {
|
|
192
|
+
if (method === 'constructor')
|
|
193
|
+
continue;
|
|
194
|
+
const rule_method = jsSdkUtils.camelCase(`get ${rule.rule_type.replace(/_/g, ' ')}`);
|
|
195
|
+
if (method === rule_method ||
|
|
196
|
+
((_c = data === null || data === void 0 ? void 0 : data.mapper) === null || _c === void 0 ? void 0 : _c.call(data, method)) === rule_method) {
|
|
197
|
+
const dataValue = data[method](rule);
|
|
198
|
+
if (Object.values(jsSdkEnums.RuleError).includes(dataValue))
|
|
199
|
+
return dataValue;
|
|
200
|
+
if (rule.rule_type === 'js_condition')
|
|
201
|
+
return dataValue;
|
|
202
|
+
return this._comparisonProcessor[matching](dataValue, rule.value, negation);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
else if (jsSdkUtils.objectNotEmpty(data)) {
|
|
208
|
+
// only handle RuleElement with a `key` field
|
|
187
209
|
for (const key of Object.keys(data)) {
|
|
188
210
|
const k = this._keys_case_sensitive ? key : key.toLowerCase();
|
|
189
211
|
const rule_k = this._keys_case_sensitive
|
|
190
|
-
? rule
|
|
191
|
-
: rule
|
|
212
|
+
? rule['key']
|
|
213
|
+
: String(rule['key']).toLowerCase();
|
|
192
214
|
if (k === rule_k) {
|
|
193
215
|
return this._comparisonProcessor[matching](data[key], rule.value, negation);
|
|
194
216
|
}
|
|
195
217
|
}
|
|
196
218
|
}
|
|
197
|
-
else if (rule === null || rule === void 0 ? void 0 : rule.rule_type) {
|
|
198
|
-
// Rule object has to have `rule_type` field
|
|
199
|
-
(_b = (_a = this._loggerManager) === null || _a === void 0 ? void 0 : _a.info) === null || _b === void 0 ? void 0 : _b.call(_a, 'RuleManager._processRuleItem()', jsSdkEnums.MESSAGES.RULE_MATCH_START.replace('#', rule.rule_type));
|
|
200
|
-
for (const method of Object.getOwnPropertyNames(data.constructor.prototype)) {
|
|
201
|
-
if (method === 'constructor')
|
|
202
|
-
continue;
|
|
203
|
-
const rule_method = jsSdkUtils.camelCase(`get ${rule.rule_type.replace(/_/g, ' ')}`);
|
|
204
|
-
if (method === rule_method ||
|
|
205
|
-
((_c = data === null || data === void 0 ? void 0 : data.mapper) === null || _c === void 0 ? void 0 : _c.call(data, method)) === rule_method) {
|
|
206
|
-
const dataValue = data[method](rule);
|
|
207
|
-
if (Object.values(jsSdkEnums.RuleError).includes(dataValue))
|
|
208
|
-
return dataValue;
|
|
209
|
-
if (rule.rule_type === 'js_condition')
|
|
210
|
-
return dataValue;
|
|
211
|
-
return this._comparisonProcessor[matching](dataValue, rule.value, negation);
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
219
|
else {
|
|
216
220
|
(_e = (_d = this._loggerManager) === null || _d === void 0 ? void 0 : _d.trace) === null || _e === void 0 ? void 0 : _e.call(_d, 'RuleManager._processRuleItem()', {
|
|
217
221
|
warn: jsSdkEnums.ERROR_MESSAGES.RULE_DATA_NOT_VALID,
|
|
@@ -242,6 +246,16 @@ class RuleManager {
|
|
|
242
246
|
}
|
|
243
247
|
return false;
|
|
244
248
|
}
|
|
249
|
+
/**
|
|
250
|
+
* Check is rule data object is a custom interface instead of a literal object
|
|
251
|
+
* @param {Record<string, any>} data Single value or key-value data set to compare
|
|
252
|
+
* @return {boolean}
|
|
253
|
+
*/
|
|
254
|
+
isUsingCustomInterface(data) {
|
|
255
|
+
return (jsSdkUtils.objectNotEmpty(data) &&
|
|
256
|
+
Object.prototype.hasOwnProperty.call(data, 'name') &&
|
|
257
|
+
data.name === 'RuleData');
|
|
258
|
+
}
|
|
245
259
|
}
|
|
246
260
|
|
|
247
261
|
exports.RuleManager = RuleManager;
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/lib/index.min.js
CHANGED
|
@@ -4,5 +4,5 @@
|
|
|
4
4
|
* Copyright(c) 2020-2022 Convert Insights, Inc
|
|
5
5
|
* License Apache-2.0
|
|
6
6
|
*/
|
|
7
|
-
"use strict";var e=require("@convertcom/js-sdk-utils"),r=require("@convertcom/js-sdk-enums");exports.RuleManager=class{constructor(o,{loggerManager:l}={}){var t,a;this._comparisonProcessor=e.Comparisons,this._negation="!",this._keys_case_sensitive=true,this._loggerManager=l,this._comparisonProcessor=
|
|
7
|
+
"use strict";var e=require("@convertcom/js-sdk-utils"),r=require("@convertcom/js-sdk-enums");exports.RuleManager=class{constructor(o,{loggerManager:l}={}){var t,a,s,i,n;this._comparisonProcessor=e.Comparisons,this._negation="!",this._keys_case_sensitive=true,this._loggerManager=l,this._comparisonProcessor=(null===(t=null==o?void 0:o.rules)||void 0===t?void 0:t.comparisonProcessor)||e.Comparisons,this._negation=String((null===(a=null==o?void 0:o.rules)||void 0===a?void 0:a.negation)||"!"),this._keys_case_sensitive=(null===(s=null==o?void 0:o.rules)||void 0===s?void 0:s.keys_case_sensitive)||true,this._mapper=(null==o?void 0:o.mapper)||(e=>e),null===(n=null===(i=this._loggerManager)||void 0===i?void 0:i.trace)||void 0===n||n.call(i,"RuleManager()",r.MESSAGES.RULE_CONSTRUCTOR,this)}set comparisonProcessor(e){this._comparisonProcessor=e}get comparisonProcessor(){return this._comparisonProcessor}getComparisonProcessorMethods(){return Object.getOwnPropertyNames(this._comparisonProcessor).filter((e=>"function"==typeof this._comparisonProcessor[e]))}isRuleMatched(o,l,t){var a,s,i,n,c,u,_,g,R,p;let d;if(null===(s=null===(a=this._loggerManager)||void 0===a?void 0:a.trace)||void 0===s||s.call(a,"RuleManager.isRuleMatched()",this._mapper({data:o,ruleSet:l})),t&&(null===(n=null===(i=this._loggerManager)||void 0===i?void 0:i.info)||void 0===n||n.call(i,"RuleManager.isRuleMatched()",r.MESSAGES.PROCESSING_ENTITY.replace("#",t))),Object.prototype.hasOwnProperty.call(l,"OR")&&e.arrayNotEmpty(null==l?void 0:l.OR)){for(let e=0,a=l.OR.length;e<a;e++)if(d=this._processAND(o,l.OR[e]),Object.values(r.RuleError).includes(d)?null===(u=null===(c=this._loggerManager)||void 0===c?void 0:c.info)||void 0===u||u.call(c,"RuleManager.isRuleMatched()",t||"",r.ERROR_MESSAGES.RULE_ERROR):null===(g=null===(_=this._loggerManager)||void 0===_?void 0:_.info)||void 0===g||g.call(_,"RuleManager.isRuleMatched()",t||"",!1===d?r.MESSAGES.RULE_NOT_MATCH:r.MESSAGES.RULE_MATCH.replace("#",String(e))),!1!==d)return d}else null===(p=null===(R=this._loggerManager)||void 0===R?void 0:R.warn)||void 0===p||p.call(R,"RuleManager.isRuleMatched()",t||"",r.ERROR_MESSAGES.RULE_NOT_VALID);return!1}isValidRule(e){var r,o;return null===(o=null===(r=this._loggerManager)||void 0===r?void 0:r.trace)||void 0===o||o.call(r,"RuleManager.isValidRule()",this._mapper({rule:e})),Object.prototype.hasOwnProperty.call(e,"matching")&&"object"==typeof e.matching&&Object.prototype.hasOwnProperty.call(e.matching,"match_type")&&"string"==typeof e.matching.match_type&&Object.prototype.hasOwnProperty.call(e.matching,"negated")&&"boolean"==typeof e.matching.negated&&Object.prototype.hasOwnProperty.call(e,"value")}_processAND(o,l){var t,a,s,i;let n;if(Object.prototype.hasOwnProperty.call(l,"AND")&&e.arrayNotEmpty(null==l?void 0:l.AND)){for(let e=0,r=l.AND.length;e<r;e++)if(n=this._processORWHEN(o,l.AND[e]),!1===n)return!1;return!1!==n&&(null===(a=null===(t=this._loggerManager)||void 0===t?void 0:t.info)||void 0===a||a.call(t,"RuleManager._processAND()",r.MESSAGES.RULE_MATCH_AND)),n}return null===(i=null===(s=this._loggerManager)||void 0===s?void 0:s.warn)||void 0===i||i.call(s,"RuleManager._processAND()",r.ERROR_MESSAGES.RULE_NOT_VALID),!1}_processORWHEN(o,l){var t,a;let s;if(Object.prototype.hasOwnProperty.call(l,"OR_WHEN")&&e.arrayNotEmpty(null==l?void 0:l.OR_WHEN)){for(let e=0,r=l.OR_WHEN.length;e<r;e++)if(s=this._processRuleItem(o,l.OR_WHEN[e]),!1!==s)return s}else null===(a=null===(t=this._loggerManager)||void 0===t?void 0:t.warn)||void 0===a||a.call(t,"RuleManager._processORWHEN()",r.ERROR_MESSAGES.RULE_NOT_VALID);return!1}_processRuleItem(o,l){var t,a,s,i,n,c,u,_,g,R,p,d,v;if(this.isValidRule(l))try{const R=l.matching.negated||!1,p=l.matching.match_type;if(-1!==this.getComparisonProcessorMethods().indexOf(p))if(o&&"object"==typeof o)if(this.isUsingCustomInterface(o)){if(null==l?void 0:l.rule_type){null===(a=null===(t=this._loggerManager)||void 0===t?void 0:t.info)||void 0===a||a.call(t,"RuleManager._processRuleItem()",r.MESSAGES.RULE_MATCH_START.replace("#",l.rule_type));for(const t of Object.getOwnPropertyNames(o.constructor.prototype)){if("constructor"===t)continue;const a=e.camelCase(`get ${l.rule_type.replace(/_/g," ")}`);if(t===a||(null===(s=null==o?void 0:o.mapper)||void 0===s?void 0:s.call(o,t))===a){const e=o[t](l);return Object.values(r.RuleError).includes(e)||"js_condition"===l.rule_type?e:this._comparisonProcessor[p](e,l.value,R)}}}}else if(e.objectNotEmpty(o))for(const e of Object.keys(o)){const r=this._keys_case_sensitive?e:e.toLowerCase();if(r===(this._keys_case_sensitive?l.key:String(l.key).toLowerCase()))return this._comparisonProcessor[p](o[e],l.value,R)}else null===(n=null===(i=this._loggerManager)||void 0===i?void 0:i.trace)||void 0===n||n.call(i,"RuleManager._processRuleItem()",{warn:r.ERROR_MESSAGES.RULE_DATA_NOT_VALID,data:o});else null===(u=null===(c=this._loggerManager)||void 0===c?void 0:c.trace)||void 0===u||u.call(c,"RuleManager._processRuleItem()",{warn:r.ERROR_MESSAGES.RULE_NOT_VALID,data:o,rule:l});else null===(g=null===(_=this._loggerManager)||void 0===_?void 0:_.warn)||void 0===g||g.call(_,"RuleManager._processRuleItem()",r.ERROR_MESSAGES.RULE_MATCH_TYPE_NOT_SUPPORTED.replace("#",p))}catch(e){null===(p=null===(R=this._loggerManager)||void 0===R?void 0:R.error)||void 0===p||p.call(R,"RuleManager._processRuleItem()",{error:e.message})}else null===(v=null===(d=this._loggerManager)||void 0===d?void 0:d.warn)||void 0===v||v.call(d,"RuleManager._processRuleItem()",r.ERROR_MESSAGES.RULE_NOT_VALID);return!1}isUsingCustomInterface(r){return e.objectNotEmpty(r)&&Object.prototype.hasOwnProperty.call(r,"name")&&"RuleData"===r.name}};
|
|
8
8
|
//# sourceMappingURL=index.min.js.map
|
package/lib/index.min.mjs
CHANGED
|
@@ -4,5 +4,5 @@
|
|
|
4
4
|
* Copyright(c) 2020-2022 Convert Insights, Inc
|
|
5
5
|
* License Apache-2.0
|
|
6
6
|
*/
|
|
7
|
-
import{Comparisons as e,
|
|
7
|
+
import{Comparisons as e,arrayNotEmpty as l,camelCase as o,objectNotEmpty as r}from"@convertcom/js-sdk-utils";import{MESSAGES as t,RuleError as a,ERROR_MESSAGES as s}from"@convertcom/js-sdk-enums";class i{constructor(l,{loggerManager:o}={}){var r,a,s,i,n;this._comparisonProcessor=e,this._negation="!",this._keys_case_sensitive=true,this._loggerManager=o,this._comparisonProcessor=(null===(r=null==l?void 0:l.rules)||void 0===r?void 0:r.comparisonProcessor)||e,this._negation=String((null===(a=null==l?void 0:l.rules)||void 0===a?void 0:a.negation)||"!"),this._keys_case_sensitive=(null===(s=null==l?void 0:l.rules)||void 0===s?void 0:s.keys_case_sensitive)||true,this._mapper=(null==l?void 0:l.mapper)||(e=>e),null===(n=null===(i=this._loggerManager)||void 0===i?void 0:i.trace)||void 0===n||n.call(i,"RuleManager()",t.RULE_CONSTRUCTOR,this)}set comparisonProcessor(e){this._comparisonProcessor=e}get comparisonProcessor(){return this._comparisonProcessor}getComparisonProcessorMethods(){return Object.getOwnPropertyNames(this._comparisonProcessor).filter((e=>"function"==typeof this._comparisonProcessor[e]))}isRuleMatched(e,o,r){var i,n,c,u,g,_,d,p,v,h;let R;if(null===(n=null===(i=this._loggerManager)||void 0===i?void 0:i.trace)||void 0===n||n.call(i,"RuleManager.isRuleMatched()",this._mapper({data:e,ruleSet:o})),r&&(null===(u=null===(c=this._loggerManager)||void 0===c?void 0:c.info)||void 0===u||u.call(c,"RuleManager.isRuleMatched()",t.PROCESSING_ENTITY.replace("#",r))),Object.prototype.hasOwnProperty.call(o,"OR")&&l(null==o?void 0:o.OR)){for(let l=0,i=o.OR.length;l<i;l++)if(R=this._processAND(e,o.OR[l]),Object.values(a).includes(R)?null===(_=null===(g=this._loggerManager)||void 0===g?void 0:g.info)||void 0===_||_.call(g,"RuleManager.isRuleMatched()",r||"",s.RULE_ERROR):null===(p=null===(d=this._loggerManager)||void 0===d?void 0:d.info)||void 0===p||p.call(d,"RuleManager.isRuleMatched()",r||"",!1===R?t.RULE_NOT_MATCH:t.RULE_MATCH.replace("#",String(l))),!1!==R)return R}else null===(h=null===(v=this._loggerManager)||void 0===v?void 0:v.warn)||void 0===h||h.call(v,"RuleManager.isRuleMatched()",r||"",s.RULE_NOT_VALID);return!1}isValidRule(e){var l,o;return null===(o=null===(l=this._loggerManager)||void 0===l?void 0:l.trace)||void 0===o||o.call(l,"RuleManager.isValidRule()",this._mapper({rule:e})),Object.prototype.hasOwnProperty.call(e,"matching")&&"object"==typeof e.matching&&Object.prototype.hasOwnProperty.call(e.matching,"match_type")&&"string"==typeof e.matching.match_type&&Object.prototype.hasOwnProperty.call(e.matching,"negated")&&"boolean"==typeof e.matching.negated&&Object.prototype.hasOwnProperty.call(e,"value")}_processAND(e,o){var r,a,i,n;let c;if(Object.prototype.hasOwnProperty.call(o,"AND")&&l(null==o?void 0:o.AND)){for(let l=0,r=o.AND.length;l<r;l++)if(c=this._processORWHEN(e,o.AND[l]),!1===c)return!1;return!1!==c&&(null===(a=null===(r=this._loggerManager)||void 0===r?void 0:r.info)||void 0===a||a.call(r,"RuleManager._processAND()",t.RULE_MATCH_AND)),c}return null===(n=null===(i=this._loggerManager)||void 0===i?void 0:i.warn)||void 0===n||n.call(i,"RuleManager._processAND()",s.RULE_NOT_VALID),!1}_processORWHEN(e,o){var r,t;let a;if(Object.prototype.hasOwnProperty.call(o,"OR_WHEN")&&l(null==o?void 0:o.OR_WHEN)){for(let l=0,r=o.OR_WHEN.length;l<r;l++)if(a=this._processRuleItem(e,o.OR_WHEN[l]),!1!==a)return a}else null===(t=null===(r=this._loggerManager)||void 0===r?void 0:r.warn)||void 0===t||t.call(r,"RuleManager._processORWHEN()",s.RULE_NOT_VALID);return!1}_processRuleItem(e,l){var i,n,c,u,g,_,d,p,v,h,R,m,O;if(this.isValidRule(l))try{const h=l.matching.negated||!1,R=l.matching.match_type;if(-1!==this.getComparisonProcessorMethods().indexOf(R))if(e&&"object"==typeof e)if(this.isUsingCustomInterface(e)){if(null==l?void 0:l.rule_type){null===(n=null===(i=this._loggerManager)||void 0===i?void 0:i.info)||void 0===n||n.call(i,"RuleManager._processRuleItem()",t.RULE_MATCH_START.replace("#",l.rule_type));for(const r of Object.getOwnPropertyNames(e.constructor.prototype)){if("constructor"===r)continue;const t=o(`get ${l.rule_type.replace(/_/g," ")}`);if(r===t||(null===(c=null==e?void 0:e.mapper)||void 0===c?void 0:c.call(e,r))===t){const o=e[r](l);return Object.values(a).includes(o)||"js_condition"===l.rule_type?o:this._comparisonProcessor[R](o,l.value,h)}}}}else if(r(e))for(const o of Object.keys(e)){const r=this._keys_case_sensitive?o:o.toLowerCase();if(r===(this._keys_case_sensitive?l.key:String(l.key).toLowerCase()))return this._comparisonProcessor[R](e[o],l.value,h)}else null===(g=null===(u=this._loggerManager)||void 0===u?void 0:u.trace)||void 0===g||g.call(u,"RuleManager._processRuleItem()",{warn:s.RULE_DATA_NOT_VALID,data:e});else null===(d=null===(_=this._loggerManager)||void 0===_?void 0:_.trace)||void 0===d||d.call(_,"RuleManager._processRuleItem()",{warn:s.RULE_NOT_VALID,data:e,rule:l});else null===(v=null===(p=this._loggerManager)||void 0===p?void 0:p.warn)||void 0===v||v.call(p,"RuleManager._processRuleItem()",s.RULE_MATCH_TYPE_NOT_SUPPORTED.replace("#",R))}catch(e){null===(R=null===(h=this._loggerManager)||void 0===h?void 0:h.error)||void 0===R||R.call(h,"RuleManager._processRuleItem()",{error:e.message})}else null===(O=null===(m=this._loggerManager)||void 0===m?void 0:m.warn)||void 0===O||O.call(m,"RuleManager._processRuleItem()",s.RULE_NOT_VALID);return!1}isUsingCustomInterface(e){return r(e)&&Object.prototype.hasOwnProperty.call(e,"name")&&"RuleData"===e.name}}export{i as RuleManager};
|
|
8
8
|
//# sourceMappingURL=index.min.mjs.map
|
package/lib/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Comparisons,
|
|
1
|
+
import { Comparisons, arrayNotEmpty, camelCase, objectNotEmpty } from '@convertcom/js-sdk-utils';
|
|
2
2
|
import { MESSAGES, RuleError, ERROR_MESSAGES } from '@convertcom/js-sdk-enums';
|
|
3
3
|
|
|
4
4
|
/*!
|
|
@@ -22,16 +22,18 @@ class RuleManager {
|
|
|
22
22
|
* @param {LogManagerInterface=} dependencies.loggerManager
|
|
23
23
|
*/
|
|
24
24
|
constructor(config, { loggerManager } = {}) {
|
|
25
|
-
var _a, _b;
|
|
25
|
+
var _a, _b, _c, _d, _e;
|
|
26
26
|
this._comparisonProcessor = Comparisons;
|
|
27
27
|
this._negation = DEFAULT_NEGATION;
|
|
28
28
|
this._keys_case_sensitive = DEFAULT_KEYS_CASE_SENSITIVE;
|
|
29
29
|
this._loggerManager = loggerManager;
|
|
30
|
-
this._comparisonProcessor =
|
|
31
|
-
|
|
32
|
-
this.
|
|
30
|
+
this._comparisonProcessor =
|
|
31
|
+
((_a = config === null || config === void 0 ? void 0 : config.rules) === null || _a === void 0 ? void 0 : _a.comparisonProcessor) || Comparisons;
|
|
32
|
+
this._negation = String(((_b = config === null || config === void 0 ? void 0 : config.rules) === null || _b === void 0 ? void 0 : _b.negation) || DEFAULT_NEGATION);
|
|
33
|
+
this._keys_case_sensitive =
|
|
34
|
+
((_c = config === null || config === void 0 ? void 0 : config.rules) === null || _c === void 0 ? void 0 : _c.keys_case_sensitive) || DEFAULT_KEYS_CASE_SENSITIVE;
|
|
33
35
|
this._mapper = (config === null || config === void 0 ? void 0 : config.mapper) || ((value) => value);
|
|
34
|
-
(
|
|
36
|
+
(_e = (_d = this._loggerManager) === null || _d === void 0 ? void 0 : _d.trace) === null || _e === void 0 ? void 0 : _e.call(_d, 'RuleManager()', MESSAGES.RULE_CONSTRUCTOR, this);
|
|
35
37
|
}
|
|
36
38
|
/**
|
|
37
39
|
* Setter for comparison processor
|
|
@@ -56,7 +58,7 @@ class RuleManager {
|
|
|
56
58
|
/**
|
|
57
59
|
* Check input data matching to rule set
|
|
58
60
|
* @param {Record<string, any>} data Single value or key-value data set to compare
|
|
59
|
-
* @param {
|
|
61
|
+
* @param {RuleObject} ruleSet
|
|
60
62
|
* @return {boolean | RuleError}
|
|
61
63
|
*/
|
|
62
64
|
isRuleMatched(data, ruleSet, logEntry) {
|
|
@@ -94,7 +96,7 @@ class RuleManager {
|
|
|
94
96
|
}
|
|
95
97
|
/**
|
|
96
98
|
* Check is rule object valid
|
|
97
|
-
* @param {
|
|
99
|
+
* @param {RuleElement} rule
|
|
98
100
|
* @return {boolean}
|
|
99
101
|
*/
|
|
100
102
|
isValidRule(rule) {
|
|
@@ -167,7 +169,7 @@ class RuleManager {
|
|
|
167
169
|
/**
|
|
168
170
|
* Process single rule item
|
|
169
171
|
* @param {Record<string, any>} data Single value or key-value data set to compare
|
|
170
|
-
* @param {
|
|
172
|
+
* @param {RuleElement} rule A single rule to compare
|
|
171
173
|
* @return {boolean | RuleError} Comparison result
|
|
172
174
|
* @private
|
|
173
175
|
*/
|
|
@@ -178,38 +180,40 @@ class RuleManager {
|
|
|
178
180
|
const negation = rule.matching.negated || false;
|
|
179
181
|
const matching = rule.matching.match_type;
|
|
180
182
|
if (this.getComparisonProcessorMethods().indexOf(matching) !== -1) {
|
|
181
|
-
if (data && typeof data === 'object'
|
|
183
|
+
if (data && typeof data === 'object') {
|
|
182
184
|
// Validate data key-value set.
|
|
183
|
-
if (data
|
|
184
|
-
//
|
|
185
|
+
if (this.isUsingCustomInterface(data)) {
|
|
186
|
+
// RuleElement object has to have `rule_type` field
|
|
187
|
+
if (rule === null || rule === void 0 ? void 0 : rule.rule_type) {
|
|
188
|
+
(_b = (_a = this._loggerManager) === null || _a === void 0 ? void 0 : _a.info) === null || _b === void 0 ? void 0 : _b.call(_a, 'RuleManager._processRuleItem()', MESSAGES.RULE_MATCH_START.replace('#', rule.rule_type));
|
|
189
|
+
for (const method of Object.getOwnPropertyNames(data.constructor.prototype)) {
|
|
190
|
+
if (method === 'constructor')
|
|
191
|
+
continue;
|
|
192
|
+
const rule_method = camelCase(`get ${rule.rule_type.replace(/_/g, ' ')}`);
|
|
193
|
+
if (method === rule_method ||
|
|
194
|
+
((_c = data === null || data === void 0 ? void 0 : data.mapper) === null || _c === void 0 ? void 0 : _c.call(data, method)) === rule_method) {
|
|
195
|
+
const dataValue = data[method](rule);
|
|
196
|
+
if (Object.values(RuleError).includes(dataValue))
|
|
197
|
+
return dataValue;
|
|
198
|
+
if (rule.rule_type === 'js_condition')
|
|
199
|
+
return dataValue;
|
|
200
|
+
return this._comparisonProcessor[matching](dataValue, rule.value, negation);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
else if (objectNotEmpty(data)) {
|
|
206
|
+
// only handle RuleElement with a `key` field
|
|
185
207
|
for (const key of Object.keys(data)) {
|
|
186
208
|
const k = this._keys_case_sensitive ? key : key.toLowerCase();
|
|
187
209
|
const rule_k = this._keys_case_sensitive
|
|
188
|
-
? rule
|
|
189
|
-
: rule
|
|
210
|
+
? rule['key']
|
|
211
|
+
: String(rule['key']).toLowerCase();
|
|
190
212
|
if (k === rule_k) {
|
|
191
213
|
return this._comparisonProcessor[matching](data[key], rule.value, negation);
|
|
192
214
|
}
|
|
193
215
|
}
|
|
194
216
|
}
|
|
195
|
-
else if (rule === null || rule === void 0 ? void 0 : rule.rule_type) {
|
|
196
|
-
// Rule object has to have `rule_type` field
|
|
197
|
-
(_b = (_a = this._loggerManager) === null || _a === void 0 ? void 0 : _a.info) === null || _b === void 0 ? void 0 : _b.call(_a, 'RuleManager._processRuleItem()', MESSAGES.RULE_MATCH_START.replace('#', rule.rule_type));
|
|
198
|
-
for (const method of Object.getOwnPropertyNames(data.constructor.prototype)) {
|
|
199
|
-
if (method === 'constructor')
|
|
200
|
-
continue;
|
|
201
|
-
const rule_method = camelCase(`get ${rule.rule_type.replace(/_/g, ' ')}`);
|
|
202
|
-
if (method === rule_method ||
|
|
203
|
-
((_c = data === null || data === void 0 ? void 0 : data.mapper) === null || _c === void 0 ? void 0 : _c.call(data, method)) === rule_method) {
|
|
204
|
-
const dataValue = data[method](rule);
|
|
205
|
-
if (Object.values(RuleError).includes(dataValue))
|
|
206
|
-
return dataValue;
|
|
207
|
-
if (rule.rule_type === 'js_condition')
|
|
208
|
-
return dataValue;
|
|
209
|
-
return this._comparisonProcessor[matching](dataValue, rule.value, negation);
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
217
|
else {
|
|
214
218
|
(_e = (_d = this._loggerManager) === null || _d === void 0 ? void 0 : _d.trace) === null || _e === void 0 ? void 0 : _e.call(_d, 'RuleManager._processRuleItem()', {
|
|
215
219
|
warn: ERROR_MESSAGES.RULE_DATA_NOT_VALID,
|
|
@@ -240,6 +244,16 @@ class RuleManager {
|
|
|
240
244
|
}
|
|
241
245
|
return false;
|
|
242
246
|
}
|
|
247
|
+
/**
|
|
248
|
+
* Check is rule data object is a custom interface instead of a literal object
|
|
249
|
+
* @param {Record<string, any>} data Single value or key-value data set to compare
|
|
250
|
+
* @return {boolean}
|
|
251
|
+
*/
|
|
252
|
+
isUsingCustomInterface(data) {
|
|
253
|
+
return (objectNotEmpty(data) &&
|
|
254
|
+
Object.prototype.hasOwnProperty.call(data, 'name') &&
|
|
255
|
+
data.name === 'RuleData');
|
|
256
|
+
}
|
|
243
257
|
}
|
|
244
258
|
|
|
245
259
|
export { RuleManager };
|
package/lib/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/lib/legacy/index.js
CHANGED
|
@@ -53,16 +53,18 @@ var RuleManager = /** @class */ (function () {
|
|
|
53
53
|
*/
|
|
54
54
|
function RuleManager(config, _a) {
|
|
55
55
|
var _b = _a === void 0 ? {} : _a, loggerManager = _b.loggerManager;
|
|
56
|
-
var _c, _d;
|
|
56
|
+
var _c, _d, _e, _f, _g;
|
|
57
57
|
this._comparisonProcessor = jsSdkUtils.Comparisons;
|
|
58
58
|
this._negation = DEFAULT_NEGATION;
|
|
59
59
|
this._keys_case_sensitive = DEFAULT_KEYS_CASE_SENSITIVE;
|
|
60
60
|
this._loggerManager = loggerManager;
|
|
61
|
-
this._comparisonProcessor =
|
|
62
|
-
|
|
63
|
-
this.
|
|
61
|
+
this._comparisonProcessor =
|
|
62
|
+
((_c = config === null || config === void 0 ? void 0 : config.rules) === null || _c === void 0 ? void 0 : _c.comparisonProcessor) || jsSdkUtils.Comparisons;
|
|
63
|
+
this._negation = String(((_d = config === null || config === void 0 ? void 0 : config.rules) === null || _d === void 0 ? void 0 : _d.negation) || DEFAULT_NEGATION);
|
|
64
|
+
this._keys_case_sensitive =
|
|
65
|
+
((_e = config === null || config === void 0 ? void 0 : config.rules) === null || _e === void 0 ? void 0 : _e.keys_case_sensitive) || DEFAULT_KEYS_CASE_SENSITIVE;
|
|
64
66
|
this._mapper = (config === null || config === void 0 ? void 0 : config.mapper) || (function (value) { return value; });
|
|
65
|
-
(
|
|
67
|
+
(_g = (_f = this._loggerManager) === null || _f === void 0 ? void 0 : _f.trace) === null || _g === void 0 ? void 0 : _g.call(_f, 'RuleManager()', jsSdkEnums.MESSAGES.RULE_CONSTRUCTOR, this);
|
|
66
68
|
}
|
|
67
69
|
Object.defineProperty(RuleManager.prototype, "comparisonProcessor", {
|
|
68
70
|
/**
|
|
@@ -92,7 +94,7 @@ var RuleManager = /** @class */ (function () {
|
|
|
92
94
|
/**
|
|
93
95
|
* Check input data matching to rule set
|
|
94
96
|
* @param {Record<string, any>} data Single value or key-value data set to compare
|
|
95
|
-
* @param {
|
|
97
|
+
* @param {RuleObject} ruleSet
|
|
96
98
|
* @return {boolean | RuleError}
|
|
97
99
|
*/
|
|
98
100
|
RuleManager.prototype.isRuleMatched = function (data, ruleSet, logEntry) {
|
|
@@ -130,7 +132,7 @@ var RuleManager = /** @class */ (function () {
|
|
|
130
132
|
};
|
|
131
133
|
/**
|
|
132
134
|
* Check is rule object valid
|
|
133
|
-
* @param {
|
|
135
|
+
* @param {RuleElement} rule
|
|
134
136
|
* @return {boolean}
|
|
135
137
|
*/
|
|
136
138
|
RuleManager.prototype.isValidRule = function (rule) {
|
|
@@ -203,7 +205,7 @@ var RuleManager = /** @class */ (function () {
|
|
|
203
205
|
/**
|
|
204
206
|
* Process single rule item
|
|
205
207
|
* @param {Record<string, any>} data Single value or key-value data set to compare
|
|
206
|
-
* @param {
|
|
208
|
+
* @param {RuleElement} rule A single rule to compare
|
|
207
209
|
* @return {boolean | RuleError} Comparison result
|
|
208
210
|
* @private
|
|
209
211
|
*/
|
|
@@ -215,47 +217,49 @@ var RuleManager = /** @class */ (function () {
|
|
|
215
217
|
var negation = rule.matching.negated || false;
|
|
216
218
|
var matching = rule.matching.match_type;
|
|
217
219
|
if (this.getComparisonProcessorMethods().indexOf(matching) !== -1) {
|
|
218
|
-
if (data && typeof data === 'object'
|
|
220
|
+
if (data && typeof data === 'object') {
|
|
219
221
|
// Validate data key-value set.
|
|
220
|
-
if (data
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
var
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
222
|
+
if (this.isUsingCustomInterface(data)) {
|
|
223
|
+
// RuleElement object has to have `rule_type` field
|
|
224
|
+
if (rule === null || rule === void 0 ? void 0 : rule.rule_type) {
|
|
225
|
+
(_d = (_c = this._loggerManager) === null || _c === void 0 ? void 0 : _c.info) === null || _d === void 0 ? void 0 : _d.call(_c, 'RuleManager._processRuleItem()', jsSdkEnums.MESSAGES.RULE_MATCH_START.replace('#', rule.rule_type));
|
|
226
|
+
try {
|
|
227
|
+
for (var _r = __values(Object.getOwnPropertyNames(data.constructor.prototype)), _s = _r.next(); !_s.done; _s = _r.next()) {
|
|
228
|
+
var method = _s.value;
|
|
229
|
+
if (method === 'constructor')
|
|
230
|
+
continue;
|
|
231
|
+
var rule_method = jsSdkUtils.camelCase("get ".concat(rule.rule_type.replace(/_/g, ' ')));
|
|
232
|
+
if (method === rule_method ||
|
|
233
|
+
((_e = data === null || data === void 0 ? void 0 : data.mapper) === null || _e === void 0 ? void 0 : _e.call(data, method)) === rule_method) {
|
|
234
|
+
var dataValue = data[method](rule);
|
|
235
|
+
if (Object.values(jsSdkEnums.RuleError).includes(dataValue))
|
|
236
|
+
return dataValue;
|
|
237
|
+
if (rule.rule_type === 'js_condition')
|
|
238
|
+
return dataValue;
|
|
239
|
+
return this._comparisonProcessor[matching](dataValue, rule.value, negation);
|
|
240
|
+
}
|
|
231
241
|
}
|
|
232
242
|
}
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
243
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
244
|
+
finally {
|
|
245
|
+
try {
|
|
246
|
+
if (_s && !_s.done && (_a = _r.return)) _a.call(_r);
|
|
247
|
+
}
|
|
248
|
+
finally { if (e_1) throw e_1.error; }
|
|
238
249
|
}
|
|
239
|
-
finally { if (e_1) throw e_1.error; }
|
|
240
250
|
}
|
|
241
251
|
}
|
|
242
|
-
else if (
|
|
243
|
-
// Rule object has to have `rule_type` field
|
|
244
|
-
(_d = (_c = this._loggerManager) === null || _c === void 0 ? void 0 : _c.info) === null || _d === void 0 ? void 0 : _d.call(_c, 'RuleManager._processRuleItem()', jsSdkEnums.MESSAGES.RULE_MATCH_START.replace('#', rule.rule_type));
|
|
252
|
+
else if (jsSdkUtils.objectNotEmpty(data)) {
|
|
245
253
|
try {
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
var
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
return dataValue;
|
|
256
|
-
if (rule.rule_type === 'js_condition')
|
|
257
|
-
return dataValue;
|
|
258
|
-
return this._comparisonProcessor[matching](dataValue, rule.value, negation);
|
|
254
|
+
// only handle RuleElement with a `key` field
|
|
255
|
+
for (var _t = __values(Object.keys(data)), _u = _t.next(); !_u.done; _u = _t.next()) {
|
|
256
|
+
var key = _u.value;
|
|
257
|
+
var k = this._keys_case_sensitive ? key : key.toLowerCase();
|
|
258
|
+
var rule_k = this._keys_case_sensitive
|
|
259
|
+
? rule['key']
|
|
260
|
+
: String(rule['key']).toLowerCase();
|
|
261
|
+
if (k === rule_k) {
|
|
262
|
+
return this._comparisonProcessor[matching](data[key], rule.value, negation);
|
|
259
263
|
}
|
|
260
264
|
}
|
|
261
265
|
}
|
|
@@ -297,6 +301,16 @@ var RuleManager = /** @class */ (function () {
|
|
|
297
301
|
}
|
|
298
302
|
return false;
|
|
299
303
|
};
|
|
304
|
+
/**
|
|
305
|
+
* Check is rule data object is a custom interface instead of a literal object
|
|
306
|
+
* @param {Record<string, any>} data Single value or key-value data set to compare
|
|
307
|
+
* @return {boolean}
|
|
308
|
+
*/
|
|
309
|
+
RuleManager.prototype.isUsingCustomInterface = function (data) {
|
|
310
|
+
return (jsSdkUtils.objectNotEmpty(data) &&
|
|
311
|
+
Object.prototype.hasOwnProperty.call(data, 'name') &&
|
|
312
|
+
data.name === 'RuleData');
|
|
313
|
+
};
|
|
300
314
|
return RuleManager;
|
|
301
315
|
}());
|
|
302
316
|
|
package/lib/legacy/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/lib/legacy/index.min.js
CHANGED
|
@@ -4,5 +4,5 @@
|
|
|
4
4
|
* Copyright(c) 2020-2022 Convert Insights, Inc
|
|
5
5
|
* License Apache-2.0
|
|
6
6
|
*/
|
|
7
|
-
"use strict";var e=require("@convertcom/js-sdk-utils"),r=require("@convertcom/js-sdk-enums");function o(e){var r="function"==typeof Symbol&&Symbol.iterator,o=r&&e[r],t=0;if(o)return o.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&t>=e.length&&(e=void 0),{value:e&&e[t++],done:!e}}};throw new TypeError(r?"Object is not iterable.":"Symbol.iterator is not defined.")}"function"==typeof SuppressedError&&SuppressedError;var t=function(){function t(o,t){var l,a,
|
|
7
|
+
"use strict";var e=require("@convertcom/js-sdk-utils"),r=require("@convertcom/js-sdk-enums");function o(e){var r="function"==typeof Symbol&&Symbol.iterator,o=r&&e[r],t=0;if(o)return o.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&t>=e.length&&(e=void 0),{value:e&&e[t++],done:!e}}};throw new TypeError(r?"Object is not iterable.":"Symbol.iterator is not defined.")}"function"==typeof SuppressedError&&SuppressedError;var t=function(){function t(o,t){var l,n,a,i,s,c=(void 0===t?{}:t).loggerManager;this._comparisonProcessor=e.Comparisons,this._negation="!",this._keys_case_sensitive=true,this._loggerManager=c,this._comparisonProcessor=(null===(l=null==o?void 0:o.rules)||void 0===l?void 0:l.comparisonProcessor)||e.Comparisons,this._negation=String((null===(n=null==o?void 0:o.rules)||void 0===n?void 0:n.negation)||"!"),this._keys_case_sensitive=(null===(a=null==o?void 0:o.rules)||void 0===a?void 0:a.keys_case_sensitive)||true,this._mapper=(null==o?void 0:o.mapper)||function(e){return e},null===(s=null===(i=this._loggerManager)||void 0===i?void 0:i.trace)||void 0===s||s.call(i,"RuleManager()",r.MESSAGES.RULE_CONSTRUCTOR,this)}return Object.defineProperty(t.prototype,"comparisonProcessor",{get:function(){return this._comparisonProcessor},set:function(e){this._comparisonProcessor=e},enumerable:!1,configurable:!0}),t.prototype.getComparisonProcessorMethods=function(){var e=this;return Object.getOwnPropertyNames(this._comparisonProcessor).filter((function(r){return"function"==typeof e._comparisonProcessor[r]}))},t.prototype.isRuleMatched=function(o,t,l){var n,a,i,s,c,u,p,_,g,v,d;if(null===(a=null===(n=this._loggerManager)||void 0===n?void 0:n.trace)||void 0===a||a.call(n,"RuleManager.isRuleMatched()",this._mapper({data:o,ruleSet:t})),l&&(null===(s=null===(i=this._loggerManager)||void 0===i?void 0:i.info)||void 0===s||s.call(i,"RuleManager.isRuleMatched()",r.MESSAGES.PROCESSING_ENTITY.replace("#",l))),Object.prototype.hasOwnProperty.call(t,"OR")&&e.arrayNotEmpty(null==t?void 0:t.OR)){for(var R=0,h=t.OR.length;R<h;R++)if(d=this._processAND(o,t.OR[R]),Object.values(r.RuleError).includes(d)?null===(u=null===(c=this._loggerManager)||void 0===c?void 0:c.info)||void 0===u||u.call(c,"RuleManager.isRuleMatched()",l||"",r.ERROR_MESSAGES.RULE_ERROR):null===(_=null===(p=this._loggerManager)||void 0===p?void 0:p.info)||void 0===_||_.call(p,"RuleManager.isRuleMatched()",l||"",!1===d?r.MESSAGES.RULE_NOT_MATCH:r.MESSAGES.RULE_MATCH.replace("#",String(R))),!1!==d)return d}else null===(v=null===(g=this._loggerManager)||void 0===g?void 0:g.warn)||void 0===v||v.call(g,"RuleManager.isRuleMatched()",l||"",r.ERROR_MESSAGES.RULE_NOT_VALID);return!1},t.prototype.isValidRule=function(e){var r,o;return null===(o=null===(r=this._loggerManager)||void 0===r?void 0:r.trace)||void 0===o||o.call(r,"RuleManager.isValidRule()",this._mapper({rule:e})),Object.prototype.hasOwnProperty.call(e,"matching")&&"object"==typeof e.matching&&Object.prototype.hasOwnProperty.call(e.matching,"match_type")&&"string"==typeof e.matching.match_type&&Object.prototype.hasOwnProperty.call(e.matching,"negated")&&"boolean"==typeof e.matching.negated&&Object.prototype.hasOwnProperty.call(e,"value")},t.prototype._processAND=function(o,t){var l,n,a,i,s;if(Object.prototype.hasOwnProperty.call(t,"AND")&&e.arrayNotEmpty(null==t?void 0:t.AND)){for(var c=0,u=t.AND.length;c<u;c++)if(!1===(s=this._processORWHEN(o,t.AND[c])))return!1;return!1!==s&&(null===(n=null===(l=this._loggerManager)||void 0===l?void 0:l.info)||void 0===n||n.call(l,"RuleManager._processAND()",r.MESSAGES.RULE_MATCH_AND)),s}return null===(i=null===(a=this._loggerManager)||void 0===a?void 0:a.warn)||void 0===i||i.call(a,"RuleManager._processAND()",r.ERROR_MESSAGES.RULE_NOT_VALID),!1},t.prototype._processORWHEN=function(o,t){var l,n,a;if(Object.prototype.hasOwnProperty.call(t,"OR_WHEN")&&e.arrayNotEmpty(null==t?void 0:t.OR_WHEN)){for(var i=0,s=t.OR_WHEN.length;i<s;i++)if(!1!==(a=this._processRuleItem(o,t.OR_WHEN[i])))return a}else null===(n=null===(l=this._loggerManager)||void 0===l?void 0:l.warn)||void 0===n||n.call(l,"RuleManager._processORWHEN()",r.ERROR_MESSAGES.RULE_NOT_VALID);return!1},t.prototype._processRuleItem=function(t,l){var n,a,i,s,c,u,p,_,g,v,d,R,h,y,E,f,M;if(this.isValidRule(l))try{var m=l.matching.negated||!1,O=l.matching.match_type;if(-1!==this.getComparisonProcessorMethods().indexOf(O))if(t&&"object"==typeof t)if(this.isUsingCustomInterface(t)){if(null==l?void 0:l.rule_type){null===(u=null===(c=this._loggerManager)||void 0===c?void 0:c.info)||void 0===u||u.call(c,"RuleManager._processRuleItem()",r.MESSAGES.RULE_MATCH_START.replace("#",l.rule_type));try{for(var S=o(Object.getOwnPropertyNames(t.constructor.prototype)),A=S.next();!A.done;A=S.next()){var N=A.value;if("constructor"!==N){var b=e.camelCase("get ".concat(l.rule_type.replace(/_/g," ")));if(N===b||(null===(p=null==t?void 0:t.mapper)||void 0===p?void 0:p.call(t,N))===b){var P=t[N](l);return Object.values(r.RuleError).includes(P)||"js_condition"===l.rule_type?P:this._comparisonProcessor[O](P,l.value,m)}}}}catch(e){n={error:e}}finally{try{A&&!A.done&&(a=S.return)&&a.call(S)}finally{if(n)throw n.error}}}}else if(e.objectNotEmpty(t))try{for(var w=o(Object.keys(t)),T=w.next();!T.done;T=w.next()){var j=T.value;if((this._keys_case_sensitive?j:j.toLowerCase())===(this._keys_case_sensitive?l.key:String(l.key).toLowerCase()))return this._comparisonProcessor[O](t[j],l.value,m)}}catch(e){i={error:e}}finally{try{T&&!T.done&&(s=w.return)&&s.call(w)}finally{if(i)throw i.error}}else null===(g=null===(_=this._loggerManager)||void 0===_?void 0:_.trace)||void 0===g||g.call(_,"RuleManager._processRuleItem()",{warn:r.ERROR_MESSAGES.RULE_DATA_NOT_VALID,data:t});else null===(d=null===(v=this._loggerManager)||void 0===v?void 0:v.trace)||void 0===d||d.call(v,"RuleManager._processRuleItem()",{warn:r.ERROR_MESSAGES.RULE_NOT_VALID,data:t,rule:l});else null===(h=null===(R=this._loggerManager)||void 0===R?void 0:R.warn)||void 0===h||h.call(R,"RuleManager._processRuleItem()",r.ERROR_MESSAGES.RULE_MATCH_TYPE_NOT_SUPPORTED.replace("#",O))}catch(e){null===(E=null===(y=this._loggerManager)||void 0===y?void 0:y.error)||void 0===E||E.call(y,"RuleManager._processRuleItem()",{error:e.message})}else null===(M=null===(f=this._loggerManager)||void 0===f?void 0:f.warn)||void 0===M||M.call(f,"RuleManager._processRuleItem()",r.ERROR_MESSAGES.RULE_NOT_VALID);return!1},t.prototype.isUsingCustomInterface=function(r){return e.objectNotEmpty(r)&&Object.prototype.hasOwnProperty.call(r,"name")&&"RuleData"===r.name},t}();exports.RuleManager=t;
|
|
8
8
|
//# sourceMappingURL=index.min.js.map
|
package/lib/package.json
CHANGED
|
@@ -14,5 +14,11 @@
|
|
|
14
14
|
"directory": "packages/rules"
|
|
15
15
|
},
|
|
16
16
|
"license": "Apache-2.0",
|
|
17
|
-
"
|
|
17
|
+
"dependencies": {
|
|
18
|
+
"@convertcom/js-sdk-enums": ">=1.0.0",
|
|
19
|
+
"@convertcom/js-sdk-logger": ">=1.0.0",
|
|
20
|
+
"@convertcom/js-sdk-types": ">=1.0.0",
|
|
21
|
+
"@convertcom/js-sdk-utils": ">=1.0.0"
|
|
22
|
+
},
|
|
23
|
+
"version": "2.0.0"
|
|
18
24
|
}
|
package/package.json
CHANGED