@raytio/core 10.0.0 → 10.0.1

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/CHANGELOG.md CHANGED
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## 10.0.1 (2022-07-06)
11
+
12
+ - added 2 methods (`isScoreResultValid` and `isScoreConfigValid`) to verify if stored score-data is valid
13
+
10
14
  ## 10.0.0 (2022-04-11)
11
15
 
12
16
  - 💥 BREAKING CHANGE: `calculateScore` is now an async function, and returns extra diagnostics.
package/README.md CHANGED
@@ -40,6 +40,8 @@ If you wish to use `@raytio/core` directly, an example of configuring polyfills
40
40
  - [isConditionMet](#isconditionmet)
41
41
  - [isEncrypted](#isencrypted)
42
42
  - [isEncryptedFile](#isencryptedfile)
43
+ - [isScoreConfigValid](#isscoreconfigvalid)
44
+ - [isScoreResultValid](#isscoreresultvalid)
43
45
  - [someEncrypted](#someencrypted)
44
46
  - [toCognitoAttributes](#tocognitoattributes)
45
47
 
@@ -373,6 +375,8 @@ ___
373
375
 
374
376
  ▸ **hashPassword**(`password`): `Promise`<`string`\>
375
377
 
378
+ **`deprecated`** legacy feature, see #1252
379
+
376
380
  AWS Cognito never gets the raw password. We send them
377
381
  a hashed verison using PBKDF2 with SHA-256 and 10,000
378
382
  iterations.
@@ -451,6 +455,42 @@ true or false depending on whether the input is an encrypted Raytio file
451
455
 
452
456
  ___
453
457
 
458
+ ### isScoreConfigValid
459
+
460
+ ▸ `Const` **isScoreConfigValid**(`x`): x is ScoreConfig
461
+
462
+ determines whether a `ScoreConfig` object is valid
463
+
464
+ #### Parameters
465
+
466
+ | Name | Type |
467
+ | :------ | :------ |
468
+ | `x` | `unknown` |
469
+
470
+ #### Returns
471
+
472
+ x is ScoreConfig
473
+
474
+ ___
475
+
476
+ ### isScoreResultValid
477
+
478
+ ▸ `Const` **isScoreResultValid**(`x`): x is ScoreResult
479
+
480
+ determines whether a `ScoreResult` object is valid
481
+
482
+ #### Parameters
483
+
484
+ | Name | Type |
485
+ | :------ | :------ |
486
+ | `x` | `unknown` |
487
+
488
+ #### Returns
489
+
490
+ x is ScoreResult
491
+
492
+ ___
493
+
454
494
  ### someEncrypted
455
495
 
456
496
  ▸ `Const` **someEncrypted**<`T`, `K`\>(...`args`): `number`
@@ -1,4 +1,6 @@
1
1
  /**
2
+ * @deprecated legacy feature, see #1252
3
+ *
2
4
  * AWS Cognito never gets the raw password. We send them
3
5
  * a hashed verison using PBKDF2 with SHA-256 and 10,000
4
6
  * iterations.
@@ -5,6 +5,8 @@ exports.hashPassword = void 0;
5
5
  /** @internal */
6
6
  const SALT = "247 213 94 9 15 236 156 48 194 177 107 216 198 215 169 239";
7
7
  /**
8
+ * @deprecated legacy feature, see #1252
9
+ *
8
10
  * AWS Cognito never gets the raw password. We send them
9
11
  * a hashed verison using PBKDF2 with SHA-256 and 10,000
10
12
  * iterations.
@@ -3,7 +3,9 @@ import { RuleData, ScoreConfig } from "./types";
3
3
  export declare type ScoreResult = {
4
4
  score: number;
5
5
  category: string;
6
+ categoryColour: string | undefined;
6
7
  diagnostics: {
8
+ version: string;
7
9
  config: {
8
10
  id: string;
9
11
  rules: {
@@ -4,6 +4,7 @@ exports.calculateScore = void 0;
4
4
  const evaluateScoreCondition_1 = require("./evaluateScoreCondition");
5
5
  const helpers_1 = require("./helpers");
6
6
  const general_1 = require("../general");
7
+ const version_1 = require("./version");
7
8
  function evaluateASTNode(node, data) {
8
9
  if (node.type === "LanguageOperator") {
9
10
  if (!node.children.length) {
@@ -58,7 +59,9 @@ async function calculateScore(ruleConfig, ruleInput) {
58
59
  return {
59
60
  score: finalScore,
60
61
  category: matchingCategories[0].name,
62
+ categoryColour: matchingCategories[0].colour,
61
63
  diagnostics: {
64
+ version: version_1.SUBMISSION_RULES_VERSION,
62
65
  config: {
63
66
  id: await jsonId(ruleConfig),
64
67
  rules: await Promise.all(result.map(async ({ passed }, i) => {
@@ -21,7 +21,7 @@ function evaluateScoreCondition(node, data) {
21
21
  : (0, helpers_1.getValuesFromPath)(x.value.path, data))
22
22
  .map(valuesForArg => valuesForArg.filter(v => typeof v !== "undefined"));
23
23
  for (const [i, argType] of op.operands.entries()) {
24
- if (argType !== node.values[i].type) {
24
+ if ((0, helpers_1.simplifyValueType)(argType) !== (0, helpers_1.simplifyValueType)(node.values[i].type)) {
25
25
  throw new TypeError(`Operator argument ${i} expected ${argType} but got ${node.values[i].type} for '${node.operator}'`);
26
26
  }
27
27
  const values = rawValues[i];
@@ -1,3 +1,9 @@
1
1
  import { GetTSType, ValueType } from "../types";
2
2
  /** asserts that the provided `value` meets the constaints of `type` */
3
3
  export declare function checkTypeofValue<T extends ValueType>(type: T, value: unknown): value is GetTSType<T>;
4
+ /**
5
+ * Some types are effectively equivilant (e.g. n_id and string).
6
+ * Any exceptions defined here should use the same validator in
7
+ * `checkTypeofValue` above.
8
+ */
9
+ export declare function simplifyValueType(type: ValueType): ValueType;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.checkTypeofValue = void 0;
3
+ exports.simplifyValueType = exports.checkTypeofValue = void 0;
4
4
  const types_1 = require("@raytio/types");
5
5
  const symbols_1 = require("./symbols");
6
6
  const types_2 = require("../types");
@@ -34,6 +34,7 @@ function checkTypeofValue(type, value) {
34
34
  return typeof value === "number" && value in types_1.POVerification;
35
35
  case "RegEx":
36
36
  return value instanceof RegExp;
37
+ case "Verifier":
37
38
  case "String":
38
39
  return typeof value === "string";
39
40
  default:
@@ -41,3 +42,14 @@ function checkTypeofValue(type, value) {
41
42
  }
42
43
  }
43
44
  exports.checkTypeofValue = checkTypeofValue;
45
+ /**
46
+ * Some types are effectively equivilant (e.g. n_id and string).
47
+ * Any exceptions defined here should use the same validator in
48
+ * `checkTypeofValue` above.
49
+ */
50
+ function simplifyValueType(type) {
51
+ if (type === "Verifier")
52
+ return "String";
53
+ return type;
54
+ }
55
+ exports.simplifyValueType = simplifyValueType;
@@ -1,5 +1,6 @@
1
1
  export * from "./calculateScore";
2
2
  export * from "./convertInstanceToRuleInput";
3
+ export * from "./validate";
3
4
  export * from "./types/config";
4
5
  export * from "./helpers/thresholds";
5
6
  export * from "./helpers/addInfiniteThresholdBoundaries";
@@ -17,6 +17,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
17
17
  exports.scoreOperators = void 0;
18
18
  __exportStar(require("./calculateScore"), exports);
19
19
  __exportStar(require("./convertInstanceToRuleInput"), exports);
20
+ __exportStar(require("./validate"), exports);
20
21
  __exportStar(require("./types/config"), exports);
21
22
  __exportStar(require("./helpers/thresholds"), exports);
22
23
  __exportStar(require("./helpers/addInfiniteThresholdBoundaries"), exports);
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.fieldOperators = void 0;
4
4
  exports.fieldOperators = {
5
5
  field_verifiedBy: {
6
- operands: ["HField", "String"],
6
+ operands: ["HField", "Verifier"],
7
7
  implementation(field, verifiedBy) {
8
8
  return field.verifiedBy.includes(verifiedBy);
9
9
  },
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.schemaOperators = void 0;
4
4
  exports.schemaOperators = {
5
5
  schema_verifiedBy: {
6
- operands: ["HSchema", "String"],
6
+ operands: ["HSchema", "Verifier"],
7
7
  implementation(schema, verifiedBy) {
8
8
  return schema === null || schema === void 0 ? void 0 : schema.verifiedBy.includes(verifiedBy);
9
9
  },
@@ -32,7 +32,7 @@ export declare type ValueRef<T> = ValueRefConst<T> | ValueRefVar;
32
32
  /** @ignore these are the LHS & RHS operands which come from variables (or constants) */
33
33
  export declare type FieldValueTypes = "Bool" | "Number" | "String" | "Date" | "Array" | "HField" | "HSchema";
34
34
  /** @ignore these are the RHS-only operands which come from constants ONLY */
35
- export declare type ConstValueTypes = "DateUnit" | "RegEx" | "FieldVerification" | "POVerification";
35
+ export declare type ConstValueTypes = "DateUnit" | "RegEx" | "Verifier" | "FieldVerification" | "POVerification";
36
36
  /** @ignore full list of operands which come from variables OR constants */
37
37
  export declare type ValueType = ConstValueTypes | FieldValueTypes;
38
38
  /** @ignore */
@@ -72,6 +72,11 @@ export declare type ScoreThreshold = {
72
72
  from: number;
73
73
  to: number;
74
74
  name: string;
75
+ /**
76
+ * A hex code, including the hash.
77
+ * For compatibility reasons we must assume it could be missing
78
+ */
79
+ colour: string | undefined;
75
80
  };
76
81
  /** @ignore */
77
82
  export declare type Combinator = "+" | "*";
@@ -16,4 +16,4 @@ export declare type HSchema = {
16
16
  };
17
17
  export declare const DATE_UNITS: readonly ["ms", "s", "m", "h", "D", "M", "W", "Y"];
18
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;
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 "Verifier" ? NId : T extends "FieldVerification" ? FieldVerification : T extends "POVerification" ? POVerification : never;
@@ -0,0 +1,6 @@
1
+ import { ScoreResult } from "./calculateScore";
2
+ import { ScoreConfig } from "./types";
3
+ /** determines whether a `ScoreResult` object is valid */
4
+ export declare const isScoreResultValid: (x: unknown) => x is ScoreResult;
5
+ /** determines whether a `ScoreConfig` object is valid */
6
+ export declare const isScoreConfigValid: (x: unknown) => x is ScoreConfig;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isScoreConfigValid = exports.isScoreResultValid = void 0;
4
+ const ramda_1 = require("ramda");
5
+ /** @internal - separate function so that TS understands whats going on */
6
+ const isObjectLike = (x) => typeof x === "object" && !!x && "score" in x && "category" in x;
7
+ /** determines whether a `ScoreResult` object is valid */
8
+ const isScoreResultValid = (x) => isObjectLike(x) &&
9
+ typeof x.category === "string" &&
10
+ typeof x.score === "number";
11
+ exports.isScoreResultValid = isScoreResultValid;
12
+ /** determines whether a `ScoreConfig` object is valid */
13
+ const isScoreConfigValid = (x) => typeof x === "object" && !!x && !(0, ramda_1.isEmpty)(x) && !Array.isArray(x);
14
+ exports.isScoreConfigValid = isScoreConfigValid;
@@ -0,0 +1 @@
1
+ export declare const SUBMISSION_RULES_VERSION = "sr1.3.0";
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SUBMISSION_RULES_VERSION = void 0;
4
+ // this must be kept in sync with ./CHANGELOG.md. See that file for more info
5
+ exports.SUBMISSION_RULES_VERSION = "sr1.3.0";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@raytio/core",
3
- "version": "10.0.0",
3
+ "version": "10.0.1",
4
4
  "license": "MIT",
5
5
  "main": "index",
6
6
  "types": "index",
@@ -17,14 +17,14 @@
17
17
  },
18
18
  "dependencies": {
19
19
  "@raytio/maxcryptor": "3.1.0",
20
- "@raytio/types": "6.0.1",
20
+ "@raytio/types": "6.0.2",
21
21
  "ramda": "0.28.0"
22
22
  },
23
23
  "devDependencies": {
24
- "@types/ramda": "0.28.11",
25
- "jest": "27.5.1",
24
+ "@types/ramda": "0.28.14",
25
+ "jest": "28.1.2",
26
26
  "localstorage-polyfill": "1.0.1",
27
- "ts-jest": "27.1.4"
27
+ "ts-jest": "28.0.5"
28
28
  },
29
29
  "jest": {
30
30
  "transform": {