@raytio/core 8.1.3 → 9.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/README.md +82 -11
- package/dist/accessApplication/createAA.js +0 -1
- package/dist/crypto/decryptKeys.js +0 -2
- package/dist/crypto/helpers.d.ts +1 -1
- package/dist/general/index.d.ts +1 -0
- package/dist/general/index.js +1 -0
- package/dist/general/types.d.ts +6 -0
- package/dist/general/types.js +13 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/rules/calculateScore.d.ts +11 -0
- package/dist/rules/calculateScore.js +52 -0
- package/dist/rules/convertInstanceToRuleInput.d.ts +3 -0
- package/dist/rules/convertInstanceToRuleInput.js +140 -0
- package/dist/rules/evaluateScoreCondition.d.ts +2 -0
- package/dist/rules/evaluateScoreCondition.js +45 -0
- package/dist/rules/helpers/addInfiniteThresholdBoundaries.d.ts +8 -0
- package/dist/rules/helpers/addInfiniteThresholdBoundaries.js +11 -0
- package/dist/rules/helpers/checkTypeofValue.d.ts +3 -0
- package/dist/rules/helpers/checkTypeofValue.js +43 -0
- package/dist/rules/helpers/getValuesFromPath.d.ts +3 -0
- package/dist/rules/helpers/getValuesFromPath.js +50 -0
- package/dist/rules/helpers/index.d.ts +5 -0
- package/dist/rules/helpers/index.js +17 -0
- package/dist/rules/helpers/symbols.d.ts +2 -0
- package/dist/rules/helpers/symbols.js +5 -0
- package/dist/rules/helpers/thresholds.d.ts +5 -0
- package/dist/rules/helpers/thresholds.js +47 -0
- package/dist/rules/index.d.ts +6 -0
- package/dist/rules/index.js +20 -0
- package/dist/rules/operators/bool.d.ts +2 -0
- package/dist/rules/operators/bool.js +17 -0
- package/dist/rules/operators/date.d.ts +2 -0
- package/dist/rules/operators/date.js +91 -0
- package/dist/rules/operators/hfield.d.ts +2 -0
- package/dist/rules/operators/hfield.js +33 -0
- package/dist/rules/operators/hschema.d.ts +2 -0
- package/dist/rules/operators/hschema.js +21 -0
- package/dist/rules/operators/index.d.ts +3 -0
- package/dist/rules/operators/index.js +11 -0
- package/dist/rules/operators/number.d.ts +2 -0
- package/dist/rules/operators/number.js +41 -0
- package/dist/rules/operators/string.d.ts +2 -0
- package/dist/rules/operators/string.js +58 -0
- package/dist/rules/types/config.d.ts +86 -0
- package/dist/rules/types/config.js +2 -0
- package/dist/rules/types/dataValueTypes.d.ts +19 -0
- package/dist/rules/types/dataValueTypes.js +4 -0
- package/dist/rules/types/index.d.ts +3 -0
- package/dist/rules/types/index.js +15 -0
- package/dist/rules/types/internal.d.ts +20 -0
- package/dist/rules/types/internal.js +2 -0
- package/dist/{verifications/checkVerifications.d.ts → util/canonicalJsonify.d.ts} +0 -0
- package/dist/util/canonicalJsonify.js +48 -0
- package/dist/util/handleResponse.js +0 -1
- package/dist/util/index.d.ts +1 -0
- package/dist/util/index.js +1 -0
- package/dist/verifications/getPOVerification.d.ts +5 -2
- package/dist/verifications/getPOVerification.js +3 -4
- package/dist/verifications/index.d.ts +1 -1
- package/dist/verifications/index.js +1 -1
- package/dist/verifications/safeHarbour.d.ts +1 -1
- package/dist/verifications/safeHarbour.js +2 -2
- package/dist/verifications/verifyCheck/getOwnRealVerifications.d.ts +13 -0
- package/dist/verifications/verifyCheck/getOwnRealVerifications.js +63 -0
- package/dist/verifications/{getRealVerifications.d.ts → verifyCheck/getSomeoneElsesRealVerifications.d.ts} +6 -2
- package/dist/verifications/{getRealVerifications.js → verifyCheck/getSomeoneElsesRealVerifications.js} +22 -15
- package/dist/verifications/verifyCheck/index.d.ts +2 -0
- package/dist/verifications/verifyCheck/index.js +14 -0
- package/dist/verifications/verifyCheck/operations/checkOwnVerification.d.ts +9 -0
- package/dist/verifications/verifyCheck/operations/checkOwnVerification.js +31 -0
- package/dist/verifications/verifyCheck/operations/checkSomeoneElsesVerifications.d.ts +1 -0
- package/dist/verifications/{checkVerifications.js → verifyCheck/operations/checkSomeoneElsesVerifications.js} +4 -4
- package/dist/verifications/verifyCheck/operations/index.d.ts +2 -0
- package/dist/verifications/verifyCheck/operations/index.js +14 -0
- package/package.json +7 -7
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
|
+
};
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
__exportStar(require("./addInfiniteThresholdBoundaries"), exports);
|
|
14
|
+
__exportStar(require("./checkTypeofValue"), exports);
|
|
15
|
+
__exportStar(require("./getValuesFromPath"), exports);
|
|
16
|
+
__exportStar(require("./symbols"), exports);
|
|
17
|
+
__exportStar(require("./thresholds"), exports);
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { Combinator, ScoreRule } from "../types";
|
|
2
|
+
/** @ignore */
|
|
3
|
+
export declare function getCombinator(combinator: Combinator): [func: (a: number, b: number) => number, initialValue: number];
|
|
4
|
+
/** @ignore */
|
|
5
|
+
export declare function getThresholdBoundary(combinator: Combinator, rules: ScoreRule[]): [lowest: number, highest: number];
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getThresholdBoundary = exports.getCombinator = void 0;
|
|
4
|
+
/** @ignore */
|
|
5
|
+
function getCombinator(combinator) {
|
|
6
|
+
switch (combinator) {
|
|
7
|
+
case "+":
|
|
8
|
+
return [(a, b) => a + b, 0];
|
|
9
|
+
case "*":
|
|
10
|
+
return [(a, b) => a * b, 1];
|
|
11
|
+
default:
|
|
12
|
+
throw new Error("Invalid combinator");
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
exports.getCombinator = getCombinator;
|
|
16
|
+
/** @ignore */
|
|
17
|
+
function getThresholdBoundary(combinator, rules) {
|
|
18
|
+
switch (combinator) {
|
|
19
|
+
case "+": {
|
|
20
|
+
const lowest = rules.reduce((ac, r) => ac + Math.min(r.falseWeight, r.trueWeight), 0);
|
|
21
|
+
const highest = rules.reduce((ac, r) => ac + Math.max(r.falseWeight, r.trueWeight), 0);
|
|
22
|
+
return [lowest, highest];
|
|
23
|
+
}
|
|
24
|
+
case "*": {
|
|
25
|
+
// eslint-disable-next-line fp/no-let
|
|
26
|
+
let [lowest, highest] = [Infinity, -Infinity];
|
|
27
|
+
// eslint-disable-next-line fp/no-loops, fp/no-let, fp/no-mutation
|
|
28
|
+
for (let i = 0; i < 2 * rules.length; i += 1) {
|
|
29
|
+
// loop for every possible combination (2*rules.rength), and check that combination
|
|
30
|
+
const product = i
|
|
31
|
+
.toString(2)
|
|
32
|
+
.padStart(rules.length, "0")
|
|
33
|
+
.split("")
|
|
34
|
+
.map((bool, j) => rules[j][bool === "1" ? "trueWeight" : "falseWeight"])
|
|
35
|
+
.reduce((a, b) => a * b, 1);
|
|
36
|
+
if (product > highest)
|
|
37
|
+
highest = product; // eslint-disable-line fp/no-mutation
|
|
38
|
+
if (product < lowest)
|
|
39
|
+
lowest = product; // eslint-disable-line fp/no-mutation
|
|
40
|
+
}
|
|
41
|
+
return [lowest, highest];
|
|
42
|
+
}
|
|
43
|
+
default:
|
|
44
|
+
throw new Error("Invalid combinator");
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
exports.getThresholdBoundary = getThresholdBoundary;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export * from "./calculateScore";
|
|
2
|
+
export * from "./convertInstanceToRuleInput";
|
|
3
|
+
export * from "./types/config";
|
|
4
|
+
export * from "./helpers/thresholds";
|
|
5
|
+
export * from "./helpers/addInfiniteThresholdBoundaries";
|
|
6
|
+
export { operators as scoreOperators } from "./operators";
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
|
+
};
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.scoreOperators = void 0;
|
|
14
|
+
__exportStar(require("./calculateScore"), exports);
|
|
15
|
+
__exportStar(require("./convertInstanceToRuleInput"), exports);
|
|
16
|
+
__exportStar(require("./types/config"), exports);
|
|
17
|
+
__exportStar(require("./helpers/thresholds"), exports);
|
|
18
|
+
__exportStar(require("./helpers/addInfiniteThresholdBoundaries"), exports);
|
|
19
|
+
var operators_1 = require("./operators");
|
|
20
|
+
Object.defineProperty(exports, "scoreOperators", { enumerable: true, get: function () { return operators_1.operators; } });
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.boolOperators = void 0;
|
|
4
|
+
exports.boolOperators = {
|
|
5
|
+
bool_eq: {
|
|
6
|
+
operands: ["Bool", "Bool"],
|
|
7
|
+
implementation(b1, b2) {
|
|
8
|
+
return b1 === b2;
|
|
9
|
+
},
|
|
10
|
+
},
|
|
11
|
+
bool_neq: {
|
|
12
|
+
operands: ["Bool", "Bool"],
|
|
13
|
+
implementation(b1, b2) {
|
|
14
|
+
return b1 !== b2;
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
};
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.dateOperators = void 0;
|
|
4
|
+
function getDateInXUnits(offset, unit) {
|
|
5
|
+
const d = new Date();
|
|
6
|
+
switch (unit) {
|
|
7
|
+
case "ms":
|
|
8
|
+
d.setMilliseconds(d.getMilliseconds() + offset);
|
|
9
|
+
break;
|
|
10
|
+
case "s":
|
|
11
|
+
d.setSeconds(d.getSeconds() + offset);
|
|
12
|
+
break;
|
|
13
|
+
case "m":
|
|
14
|
+
d.setMinutes(d.getMinutes() + offset);
|
|
15
|
+
break;
|
|
16
|
+
case "h":
|
|
17
|
+
d.setHours(d.getHours() + offset);
|
|
18
|
+
break;
|
|
19
|
+
case "D":
|
|
20
|
+
d.setDate(d.getDate() + offset);
|
|
21
|
+
break;
|
|
22
|
+
case "M":
|
|
23
|
+
d.setMonth(d.getMonth() + offset);
|
|
24
|
+
break;
|
|
25
|
+
case "W":
|
|
26
|
+
d.setDate(d.getDate() + 7 * offset);
|
|
27
|
+
break;
|
|
28
|
+
case "Y":
|
|
29
|
+
d.setFullYear(d.getFullYear() + offset);
|
|
30
|
+
break;
|
|
31
|
+
default:
|
|
32
|
+
throw new Error(`Invalid date unit: ${unit}`);
|
|
33
|
+
}
|
|
34
|
+
return d;
|
|
35
|
+
}
|
|
36
|
+
exports.dateOperators = {
|
|
37
|
+
date_eq: {
|
|
38
|
+
operands: ["Date", "Date"],
|
|
39
|
+
implementation(d1, d2) {
|
|
40
|
+
// only comaparing dates (not times), and in the UTC timezone.
|
|
41
|
+
const isoDate1 = d1.toISOString().split("T")[0];
|
|
42
|
+
const isoDate2 = d2.toISOString().split("T")[0];
|
|
43
|
+
return isoDate1 === isoDate2;
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
date_neq: {
|
|
47
|
+
operands: ["Date", "Date"],
|
|
48
|
+
implementation(d1, d2) {
|
|
49
|
+
// only comaparing dates (not times), and in the UTC timezone.
|
|
50
|
+
const isoDate1 = d1.toISOString().split("T")[0];
|
|
51
|
+
const isoDate2 = d2.toISOString().split("T")[0];
|
|
52
|
+
return isoDate1 !== isoDate2;
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
date_valid: {
|
|
56
|
+
operands: ["Date"],
|
|
57
|
+
implementation: (d) => !Number.isNaN(+d),
|
|
58
|
+
},
|
|
59
|
+
date_invalid: {
|
|
60
|
+
operands: ["Date"],
|
|
61
|
+
implementation: (d) => Number.isNaN(+d),
|
|
62
|
+
},
|
|
63
|
+
date_before: {
|
|
64
|
+
operands: ["Date", "Date"],
|
|
65
|
+
implementation: (d1, d2) => d1 < d2,
|
|
66
|
+
},
|
|
67
|
+
date_after: {
|
|
68
|
+
operands: ["Date", "Date"],
|
|
69
|
+
implementation: (d1, d2) => d1 > d2,
|
|
70
|
+
},
|
|
71
|
+
date_between: {
|
|
72
|
+
operands: ["Date", "Date", "Date"],
|
|
73
|
+
implementation(lhs, lower, upper) {
|
|
74
|
+
return lhs >= lower && lhs <= upper;
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
|
+
date_older_than: {
|
|
78
|
+
operands: ["Date", "Number", "DateUnit"],
|
|
79
|
+
implementation(date, num, unit) {
|
|
80
|
+
const XUnitsAgo = getDateInXUnits(-num, unit);
|
|
81
|
+
return date < XUnitsAgo;
|
|
82
|
+
},
|
|
83
|
+
},
|
|
84
|
+
date_newer_than: {
|
|
85
|
+
operands: ["Date", "Number", "DateUnit"],
|
|
86
|
+
implementation(date, num, unit) {
|
|
87
|
+
const inXUnits = getDateInXUnits(num, unit);
|
|
88
|
+
return date > inXUnits;
|
|
89
|
+
},
|
|
90
|
+
},
|
|
91
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.fieldOperators = void 0;
|
|
4
|
+
exports.fieldOperators = {
|
|
5
|
+
field_verifiedBy: {
|
|
6
|
+
operands: ["HField", "String"],
|
|
7
|
+
implementation(field, verifiedBy) {
|
|
8
|
+
return field.verifiedBy.includes(verifiedBy);
|
|
9
|
+
},
|
|
10
|
+
},
|
|
11
|
+
field_shared: {
|
|
12
|
+
operands: ["HField"],
|
|
13
|
+
implementation: () => true, // we can return true, because if the field didn't exist, this would never be called
|
|
14
|
+
},
|
|
15
|
+
field_hasVerStatus: {
|
|
16
|
+
operands: ["HField", "FieldVerification"],
|
|
17
|
+
implementation(field, status) {
|
|
18
|
+
return field.verification === status;
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
field_cameFromSchema: {
|
|
22
|
+
operands: ["HField", "String"],
|
|
23
|
+
implementation(field, schemaName) {
|
|
24
|
+
return field.cameFromSchema === schemaName;
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
field_ncameFromSchema: {
|
|
28
|
+
operands: ["HField", "String"],
|
|
29
|
+
implementation(field, schemaName) {
|
|
30
|
+
return field.cameFromSchema !== schemaName;
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.schemaOperators = void 0;
|
|
4
|
+
exports.schemaOperators = {
|
|
5
|
+
schema_verifiedBy: {
|
|
6
|
+
operands: ["HSchema", "String"],
|
|
7
|
+
implementation(schema, verifiedBy) {
|
|
8
|
+
return schema === null || schema === void 0 ? void 0 : schema.verifiedBy.includes(verifiedBy);
|
|
9
|
+
},
|
|
10
|
+
},
|
|
11
|
+
schema_shared: {
|
|
12
|
+
operands: ["HSchema"],
|
|
13
|
+
implementation: () => true, // we can return true, because if the schema didn't exist, this would never be called
|
|
14
|
+
},
|
|
15
|
+
schema_hasVerStatus: {
|
|
16
|
+
operands: ["HSchema", "POVerification"],
|
|
17
|
+
implementation(schema, status) {
|
|
18
|
+
return (schema === null || schema === void 0 ? void 0 : schema.verification) === status;
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.operators = void 0;
|
|
4
|
+
const bool_1 = require("./bool");
|
|
5
|
+
const date_1 = require("./date");
|
|
6
|
+
const hfield_1 = require("./hfield");
|
|
7
|
+
const hschema_1 = require("./hschema");
|
|
8
|
+
const number_1 = require("./number");
|
|
9
|
+
const string_1 = require("./string");
|
|
10
|
+
/** @ignore */
|
|
11
|
+
exports.operators = Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, bool_1.boolOperators), date_1.dateOperators), hfield_1.fieldOperators), hschema_1.schemaOperators), number_1.numberOperators), string_1.stringOperators);
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.numberOperators = void 0;
|
|
4
|
+
exports.numberOperators = {
|
|
5
|
+
num_eq: {
|
|
6
|
+
operands: ["Number", "Number"],
|
|
7
|
+
implementation(n1, n2) {
|
|
8
|
+
return n1 === n2;
|
|
9
|
+
},
|
|
10
|
+
},
|
|
11
|
+
num_neq: {
|
|
12
|
+
operands: ["Number", "Number"],
|
|
13
|
+
implementation(n1, n2) {
|
|
14
|
+
return n1 !== n2;
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
num_gt_eq: {
|
|
18
|
+
operands: ["Number", "Number"],
|
|
19
|
+
implementation(n1, n2) {
|
|
20
|
+
return n1 >= n2;
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
num_lt_eq: {
|
|
24
|
+
operands: ["Number", "Number"],
|
|
25
|
+
implementation(n1, n2) {
|
|
26
|
+
return n1 <= n2;
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
num_gt: {
|
|
30
|
+
operands: ["Number", "Number"],
|
|
31
|
+
implementation(n1, n2) {
|
|
32
|
+
return n1 > n2;
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
num_lt: {
|
|
36
|
+
operands: ["Number", "Number"],
|
|
37
|
+
implementation(n1, n2) {
|
|
38
|
+
return n1 < n2;
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
};
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.stringOperators = void 0;
|
|
4
|
+
// also string operators are case-insensitive
|
|
5
|
+
exports.stringOperators = {
|
|
6
|
+
string_eq: {
|
|
7
|
+
operands: ["String", "String"],
|
|
8
|
+
implementation(s1, s2) {
|
|
9
|
+
return s1.toLowerCase() === s2.toLowerCase();
|
|
10
|
+
},
|
|
11
|
+
},
|
|
12
|
+
string_neq: {
|
|
13
|
+
operands: ["String", "String"],
|
|
14
|
+
implementation(s1, s2) {
|
|
15
|
+
return s1.toLowerCase() !== s2.toLowerCase();
|
|
16
|
+
},
|
|
17
|
+
},
|
|
18
|
+
string_contains: {
|
|
19
|
+
operands: ["String", "String"],
|
|
20
|
+
implementation(s1, s2) {
|
|
21
|
+
return s1.toLowerCase().includes(s2.toLowerCase());
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
string_ncontains: {
|
|
25
|
+
operands: ["String", "String"],
|
|
26
|
+
implementation(s1, s2) {
|
|
27
|
+
return !s1.toLowerCase().includes(s2.toLowerCase());
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
string_startsWith: {
|
|
31
|
+
operands: ["String", "String"],
|
|
32
|
+
implementation(s1, s2) {
|
|
33
|
+
return s1.toLowerCase().startsWith(s2.toLowerCase());
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
string_nstartsWith: {
|
|
37
|
+
operands: ["String", "String"],
|
|
38
|
+
implementation(s1, s2) {
|
|
39
|
+
return !s1.toLowerCase().startsWith(s2.toLowerCase());
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
string_endsWith: {
|
|
43
|
+
operands: ["String", "String"],
|
|
44
|
+
implementation(s1, s2) {
|
|
45
|
+
return s1.toLowerCase().endsWith(s2.toLowerCase());
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
string_nendsWith: {
|
|
49
|
+
operands: ["String", "String"],
|
|
50
|
+
implementation(s1, s2) {
|
|
51
|
+
return !s1.toLowerCase().endsWith(s2.toLowerCase());
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
string_regex: {
|
|
55
|
+
operands: ["String", "RegEx"],
|
|
56
|
+
implementation: (str, regEx) => !!str.match(regEx),
|
|
57
|
+
},
|
|
58
|
+
};
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { GetTSType } from "./dataValueTypes";
|
|
2
|
+
/**
|
|
3
|
+
* @ignore
|
|
4
|
+
* these are just IDs, the string is never parsed by anything.
|
|
5
|
+
*
|
|
6
|
+
* However, since they're saved into the WizardConfig schema,
|
|
7
|
+
* we can't just rename or remove any, since that would break
|
|
8
|
+
* existing rules.
|
|
9
|
+
*/
|
|
10
|
+
export declare type OperatorID = "bool_eq" | "bool_neq" | "num_eq" | "num_neq" | "num_lt_eq" | "num_gt_eq" | "num_lt" | "num_gt" | "date_valid" | "date_invalid" | "date_before" | "date_after" | "date_eq" | "date_neq" | "date_older_than" | "date_newer_than" | "date_between" | "string_eq" | "string_neq" | "string_contains" | "string_ncontains" | "string_startsWith" | "string_nstartsWith" | "string_endsWith" | "string_nendsWith" | "string_regex" | "field_verifiedBy" | "field_shared" | "field_hasVerStatus" | "field_cameFromSchema" | "field_ncameFromSchema" | "schema_verifiedBy" | "schema_shared" | "schema_hasVerStatus";
|
|
11
|
+
/** @ignore */
|
|
12
|
+
export declare type ValuePathFieldProp = "meta" | "value" | "valueLength" | `subField|${string}`;
|
|
13
|
+
/** @ignore */
|
|
14
|
+
export declare type ValuePath = [type: "schema", schemaName: string, prop: "meta"] | [
|
|
15
|
+
type: "field",
|
|
16
|
+
schemaName: string,
|
|
17
|
+
fieldName: string,
|
|
18
|
+
prop: ValuePathFieldProp
|
|
19
|
+
];
|
|
20
|
+
/** @ignore */
|
|
21
|
+
export declare type ValueRefConst<T> = {
|
|
22
|
+
type: "constant";
|
|
23
|
+
value: T;
|
|
24
|
+
};
|
|
25
|
+
/** @ignore */
|
|
26
|
+
export declare type ValueRefVar = {
|
|
27
|
+
type: "variable";
|
|
28
|
+
path: ValuePath;
|
|
29
|
+
};
|
|
30
|
+
/** @ignore */
|
|
31
|
+
export declare type ValueRef<T> = ValueRefConst<T> | ValueRefVar;
|
|
32
|
+
/** @ignore these are the LHS & RHS operands which come from variables (or constants) */
|
|
33
|
+
export declare type FieldValueTypes = "Bool" | "Number" | "String" | "Date" | "Array" | "HField" | "HSchema";
|
|
34
|
+
/** @ignore these are the RHS-only operands which come from constants ONLY */
|
|
35
|
+
export declare type ConstValueTypes = "DateUnit" | "RegEx" | "FieldVerification" | "POVerification";
|
|
36
|
+
/** @ignore full list of operands which come from variables OR constants */
|
|
37
|
+
export declare type ValueType = ConstValueTypes | FieldValueTypes;
|
|
38
|
+
/** @ignore */
|
|
39
|
+
export declare type ValueDef<T = ValueType> = {
|
|
40
|
+
type: T;
|
|
41
|
+
value: ValueRef<GetTSType<T>>;
|
|
42
|
+
};
|
|
43
|
+
/** @ignore */
|
|
44
|
+
export declare type ASTScoreConditionNode = {
|
|
45
|
+
type: "ScoreCondition";
|
|
46
|
+
operator: OperatorID;
|
|
47
|
+
values: ValueDef<ValueType>[];
|
|
48
|
+
};
|
|
49
|
+
/** @ignore */
|
|
50
|
+
export declare type ASTLanguageOperatorNode = {
|
|
51
|
+
type: "LanguageOperator";
|
|
52
|
+
operator: "OR" | "AND";
|
|
53
|
+
children: ASTNode[];
|
|
54
|
+
};
|
|
55
|
+
/** @ignore */
|
|
56
|
+
export declare type ASTNode = ASTLanguageOperatorNode | ASTScoreConditionNode;
|
|
57
|
+
/** @ignore */
|
|
58
|
+
export declare type ScoreRule = {
|
|
59
|
+
/** user defined */
|
|
60
|
+
name: string;
|
|
61
|
+
/** user defined */
|
|
62
|
+
description?: string;
|
|
63
|
+
/** must be an integer */
|
|
64
|
+
trueWeight: number;
|
|
65
|
+
/** must be an integer */
|
|
66
|
+
falseWeight: number;
|
|
67
|
+
/** must have a single root node */
|
|
68
|
+
tree: [ASTNode];
|
|
69
|
+
};
|
|
70
|
+
/** @ignore e.g. 0-10 is "red". We only work with integers. Comparisons use >= and <= */
|
|
71
|
+
export declare type ScoreThreshold = {
|
|
72
|
+
from: number;
|
|
73
|
+
to: number;
|
|
74
|
+
name: string;
|
|
75
|
+
};
|
|
76
|
+
/** @ignore */
|
|
77
|
+
export declare type Combinator = "+" | "*";
|
|
78
|
+
/**
|
|
79
|
+
* @ignore
|
|
80
|
+
* the big object for configuring score rules
|
|
81
|
+
*/
|
|
82
|
+
export declare type ScoreConfig = {
|
|
83
|
+
combinator: Combinator;
|
|
84
|
+
scoreThresholds: ScoreThreshold[];
|
|
85
|
+
rules: ScoreRule[];
|
|
86
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { FieldVerification, NId, POVerification } from "@raytio/types";
|
|
2
|
+
import type { HFieldSymbol, HSchemaSymbol } from "../helpers";
|
|
3
|
+
/** undefined if not shared */
|
|
4
|
+
export declare type HField = {
|
|
5
|
+
__typeof__: typeof HFieldSymbol;
|
|
6
|
+
verification: FieldVerification;
|
|
7
|
+
verifiedBy: readonly NId[];
|
|
8
|
+
/** schemaName */
|
|
9
|
+
cameFromSchema: string;
|
|
10
|
+
};
|
|
11
|
+
/** undefined if not shared */
|
|
12
|
+
export declare type HSchema = {
|
|
13
|
+
__typeof__: typeof HSchemaSymbol;
|
|
14
|
+
verification?: POVerification;
|
|
15
|
+
verifiedBy: readonly NId[];
|
|
16
|
+
};
|
|
17
|
+
export declare const DATE_UNITS: readonly ["ms", "s", "m", "h", "D", "M", "W", "Y"];
|
|
18
|
+
export declare type DateUnit = typeof DATE_UNITS[number];
|
|
19
|
+
export declare type GetTSType<T> = T extends "Bool" ? boolean : T extends "Number" ? number : T extends "String" ? string : T extends "Date" ? Date : T extends "Array" ? unknown[] : T extends "HField" ? HField : T extends "HSchema" ? HSchema : T extends "DateUnit" ? DateUnit : T extends "RegEx" ? RegExp : T extends "FieldVerification" ? FieldVerification : T extends "POVerification" ? POVerification : never;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
|
+
};
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
__exportStar(require("./dataValueTypes"), exports);
|
|
14
|
+
__exportStar(require("./config"), exports);
|
|
15
|
+
__exportStar(require("./internal"), exports);
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { HField, HSchema, GetTSType } from "./dataValueTypes";
|
|
2
|
+
import { FieldValueTypes, ValueType } from "./config";
|
|
3
|
+
export declare type RuleDataProperty<T extends FieldValueTypes> = {
|
|
4
|
+
type: T;
|
|
5
|
+
value: GetTSType<T>;
|
|
6
|
+
hField: HField;
|
|
7
|
+
};
|
|
8
|
+
export declare type RuleData = {
|
|
9
|
+
[schemaName: string]: {
|
|
10
|
+
hSchema: HSchema;
|
|
11
|
+
properties: {
|
|
12
|
+
[fieldName: string]: RuleDataProperty<FieldValueTypes>;
|
|
13
|
+
};
|
|
14
|
+
}[];
|
|
15
|
+
};
|
|
16
|
+
export declare type OperatorDef = {
|
|
17
|
+
/** the first operand is the LHS, all others are RHS */
|
|
18
|
+
operands: ValueType[];
|
|
19
|
+
implementation: (...args: any[]) => boolean;
|
|
20
|
+
};
|
|
File without changes
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/* eslint-disable fp/no-mutating-methods, fp/no-mutation, fp/no-let, prefer-reflect */
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.canonicalJsonify = void 0;
|
|
5
|
+
const isObject = (a) => Object.prototype.toString.call(a) === "[object Object]"; // TODO: wtf ?
|
|
6
|
+
const REGEX =
|
|
7
|
+
// eslint-disable-next-line no-control-regex
|
|
8
|
+
/[\u0000-\u001F]|"|\\|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF]/g;
|
|
9
|
+
const SLASH_ESC = {
|
|
10
|
+
"\b": "\\b",
|
|
11
|
+
"\t": "\\t",
|
|
12
|
+
"\n": "\\n",
|
|
13
|
+
"\f": "\\f",
|
|
14
|
+
"\r": "\\r",
|
|
15
|
+
'"': '\\"',
|
|
16
|
+
"\\": "\\\\",
|
|
17
|
+
};
|
|
18
|
+
const replacer = (char) => SLASH_ESC[char] ||
|
|
19
|
+
`\\u${char.charCodeAt(0).toString(16).toUpperCase().padStart(4, "0")}`;
|
|
20
|
+
function copyObjectWithSortedKeys(object) {
|
|
21
|
+
if (isObject(object)) {
|
|
22
|
+
return `{${Object.keys(object)
|
|
23
|
+
.sort()
|
|
24
|
+
.map(key => `"${key}":${copyObjectWithSortedKeys(object[key])}`)
|
|
25
|
+
.join(",")}}`;
|
|
26
|
+
}
|
|
27
|
+
if (Array.isArray(object)) {
|
|
28
|
+
return `[${object.map(copyObjectWithSortedKeys).join(",")}]`;
|
|
29
|
+
}
|
|
30
|
+
if (typeof object === "number" && object % 1 !== 0) {
|
|
31
|
+
// float
|
|
32
|
+
const exponent = Math.round(Math.log10(Math.abs(object)));
|
|
33
|
+
let mantissa = `${object / 10 ** exponent}`;
|
|
34
|
+
if (!mantissa.includes("."))
|
|
35
|
+
mantissa += ".0";
|
|
36
|
+
return `${mantissa}E${exponent}`;
|
|
37
|
+
}
|
|
38
|
+
if (typeof object === "string")
|
|
39
|
+
return `"${object.replace(REGEX, replacer)}"`;
|
|
40
|
+
return object; // bool or int
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* @internal
|
|
44
|
+
* spec compliant, and matches
|
|
45
|
+
* https://gitlab.com/raytio/mono/-/blob/devo/common/signing/signing/canonical_json.py
|
|
46
|
+
*/
|
|
47
|
+
const canonicalJsonify = (object) => `${copyObjectWithSortedKeys(object)}`;
|
|
48
|
+
exports.canonicalJsonify = canonicalJsonify;
|
|
@@ -14,7 +14,6 @@ const handleResponse = async (response) => {
|
|
|
14
14
|
const json = await response.json();
|
|
15
15
|
// json could be a string | number
|
|
16
16
|
if (typeof json === "object" && "message" in json) {
|
|
17
|
-
// eslint-disable-next-line fp/no-throw
|
|
18
17
|
throw new Error(json.message);
|
|
19
18
|
}
|
|
20
19
|
return json;
|
package/dist/util/index.d.ts
CHANGED