@raytio/core 9.0.3 → 10.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/CHANGELOG.md ADDED
@@ -0,0 +1,153 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [Unreleased]
9
+
10
+ ## 10.0.0 (2022-04-11)
11
+
12
+ - 💥 BREAKING CHANGE: `calculateScore` is now an async function, and returns extra diagnostics.
13
+
14
+ ## 9.0.3 (2022-02-22)
15
+
16
+ - fixed a bug which caused valid live persons to show up as Not Verified.
17
+
18
+ ## 9.0.2 (2022-02-10)
19
+
20
+ - removed the `UNSAFE_treatNoValueAsVerified` option. This option was never documented or officially supported, so this is not considered a breaking change.
21
+ - use the `date_component` schema field tag in date-related code
22
+
23
+ ## 9.0.1 (2022-02-09)
24
+
25
+ - update `@raytio/types` to v6
26
+
27
+ ## 9.0.0 (2022-02-01)
28
+
29
+ - 💥 BREAKING CHANGE: the value returned by `getPOVerification` has changed slightly: the `details` property is now an object
30
+ - 💥 BREAKING CHANGE: `getRealVerifications` has been removed. It has been replaced by the following two methods:
31
+ - `getSomeoneElsesRealVerifications` is identical to the former `getRealVerifications` - it requires calling the API
32
+ - `getOwnRealVerifications` verifies the signature locally, but can only be used if you're verifying your own data.
33
+ - create the `calculateScore` and `convertInstanceToRuleInput` for working with SubmissionRules
34
+ - support 1 level of sub-fields in SubmissionRules
35
+ - 💥 BREAKING CHANGE: `getSomeoneElsesRealVerifications` now requires you to supply the `aId` of the submission
36
+
37
+ ## 8.1.3 (2021-10-05)
38
+
39
+ - published updated README.md
40
+
41
+ ## 8.1.2 (2021-09-24)
42
+
43
+ - update API format for `nId`s that start with `HASHED::`
44
+ - move `cleanInstance` to `@raytio/core`
45
+
46
+ ## 8.1.1 (2021-09-15)
47
+
48
+ - fix a bug with `nId`s that start with `HASHED::`
49
+
50
+ ## 8.1.0 (2021-08-31)
51
+
52
+ - update `getRealVerifications` to support `nId`s that start with `HASHED::`
53
+ - changed the behaviour of `isConditionMet` when the condition is an empty object. It now returns false in this case
54
+ - use new format for verify_check API
55
+
56
+ ## 8.0.0 (2021-07-28)
57
+
58
+ - support conditionally verifiable fields. This only works if the schema is processed by `processSchema`
59
+ - added `isConditionMet` to assit conditionally hidden/required/verifiable fields
60
+ - 💥 BREAKING CHANGE: `getPOVerification` no longer accepts `allSchema` and `schemaName` as an argument, this has been replaced with `schema`.
61
+ - 💥 BREAKING CHANGE: `calcSafeHarbourScore` is now async and no longer accepts `allSchema`, ths has been replaced with an argumnet called `getSchema`.
62
+
63
+ ## 7.0.0 (2021-04-07)
64
+
65
+ - 💥 BREAKING CHANGE: (TS) `POVerification` and `FieldVerification` are now enums, not string unions
66
+ - fixed a commonjs export bug in v6.0.1
67
+
68
+ ## 6.0.1 (2021-04-06)
69
+
70
+ - update `calcSafeHarbourScore` to ignore duplicate verifications
71
+
72
+ ## 6.0.0 (2021-03-05)
73
+
74
+ - 💥 BREAKING CHANGE: `decryptSharedData` now return `instance` and `applicationDecryptor`
75
+
76
+ ## 5.0.0 (2021-03-03)
77
+
78
+ - deps: upgrade maxcryptor to `0.3.0`
79
+ - 💥 BREAKING CHANGE: (TS) all IDs (e.g. `n_id`, `a_id`) now use nominal types (e.g. `NId`, `AId`)
80
+ - 💥 BREAKING CHANGE: require TypeScipt@4.2 or later
81
+
82
+ ## 4.0.1 (2021-02-05)
83
+
84
+ - fixed an npm publishing issue with `v4.0.0`
85
+
86
+ ## 4.0.0 (2021-02-04)
87
+
88
+ - 💥 BREAKING CHANGE: `LABELS_DENYLIST` is no longer exported. It was never documented and there should be no reason to use it. Use `findSchemaLabel` instead.
89
+ - 💥 BREAKING CHANGE: `createAA` should be supplied an `org_id` within the `application` attribute, not as a seperate attribute called `orgId`.
90
+ - 💥 BREAKING CHANGE: `decryptSharedData` no longer needs an `aId` attribute since it can get that information from the `instance` attribute. This isn't a breaking change per-se, but will cause type errors.
91
+ - use `unknown` instead of `any` in some predominantly internal types.
92
+
93
+ ## 3.2.2 (2021-01-19)
94
+
95
+ - reverted a bug fix from v3.2.1 which was a work-around for badly formatted data.
96
+
97
+ ## 3.2.1 (2021-01-18)
98
+
99
+ - fixed a bug where verified numbers weren't showing up as verified (reverted in v3.2.2)
100
+ - added `onCorruptedData` option to `decryptSharedData`
101
+
102
+ ## 3.2.0 (2021-01-06)
103
+
104
+ - added `toCognitoAttributes` and `fromCognitoAttributes`
105
+ - properly handle errors from all API requests
106
+
107
+ ## 3.1.0 (2020-12-19)
108
+
109
+ - add function to create an access application (`createAA`)
110
+
111
+ ## 3.0.0 (2020-12-17)
112
+
113
+ - 💥 BREAKING CHANGE: change safe harbour calculation to compare against a base person, instead of using relationships
114
+
115
+ ## 2.2.0 (2020-12-16)
116
+
117
+ - add Safe Harbour Compliance calculation (`calcSafeHarbourScore`)
118
+
119
+ ## 2.1.0 (2020-12-11)
120
+
121
+ - add a new type of [`FieldVerification`](https://www.npmjs.com/package/@raytio/types#fieldverification): `Expired`
122
+ - add a new type of [`POVerification`](https://www.npmjs.com/package/@raytio/types#poverification): `Expired`
123
+ - add a `expired` attribute to [`RealVer`](https://www.npmjs.com/package/@raytio/types#realver).
124
+ - update `getPOVerification` to return `Expired` for verifications where all fields are expired
125
+ - [internal] snapshot tests for auto generated documentation
126
+
127
+ ## 2.0.0 (2020-12-07)
128
+
129
+ - 💥 BREAKING CHANGE: support multiple verifications for the same data. This means that the `details` attribute returned by `getPOVerification` is now an array of [`VerificationProvider`](https://www.npmjs.com/package/@raytio/types#verificationprovider), instead of one [`VerificationProvider`](https://www.npmjs.com/package/@raytio/types#verificationprovider).
130
+
131
+ ## 1.0.4 (2020-12-06)
132
+
133
+ - fixed a bug where verification details were wrong if the same field name and value were verified by two sources
134
+ - include metadata from the verifier in `RealVer`s
135
+ - fix a bug where verifications for referenced files weren't working
136
+
137
+ ## 1.0.3 (2020-11-23)
138
+
139
+ - add `UNSAFE_treatNoValueAsVerified` option to getRealVerifications
140
+ - add `date` to `RealVer` type.
141
+
142
+ ## 1.0.2 (2020-11-20)
143
+
144
+ - `findSchemaLabel` can cope with it's argument being undefined.
145
+ - added `"receiverCreated"` to the list of internal labels
146
+
147
+ ## 1.0.1 (2020-11-18)
148
+
149
+ - `getRealVerifications` no longer requires an `apiToken` argument, since the API is available without authentication.
150
+
151
+ ## 1.0.0 (2020-11-11)
152
+
153
+ First stable release
package/README.md CHANGED
@@ -95,7 +95,7 @@ ___
95
95
 
96
96
  ### calculateScore
97
97
 
98
- ▸ **calculateScore**(`ruleConfig`, `ruleInput`): `ScoreResult`
98
+ ▸ **calculateScore**(`ruleConfig`, `ruleInput`): `Promise`<`ScoreResult`\>
99
99
 
100
100
  the main function to calculate a score and category.
101
101
  Might throw an error.
@@ -109,7 +109,7 @@ Might throw an error.
109
109
 
110
110
  #### Returns
111
111
 
112
- `ScoreResult`
112
+ `Promise`<`ScoreResult`\>
113
113
 
114
114
  ___
115
115
 
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -17,7 +17,7 @@ exports.isEncrypted = isEncrypted;
17
17
  * @param value anything
18
18
  * @returns true or false depending on whether the input is an encrypted Raytio file
19
19
  */
20
- const isEncryptedFile = (value) => { var _a, _b; return (0, exports.isEncrypted)(value) && ((_b = (_a = value === null || value === void 0 ? void 0 : value.encrypted_data) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.substr(0, 4)) === "urn:"; };
20
+ const isEncryptedFile = (value) => { var _a, _b; return (0, exports.isEncrypted)(value) && ((_b = (_a = value === null || value === void 0 ? void 0 : value.encrypted_data) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.slice(0, 4)) === "urn:"; };
21
21
  exports.isEncryptedFile = isEncryptedFile;
22
22
  /**
23
23
  * Given a profile object's properties, returns the number
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
package/dist/index.js CHANGED
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -3,9 +3,19 @@ import { RuleData, ScoreConfig } from "./types";
3
3
  export declare type ScoreResult = {
4
4
  score: number;
5
5
  category: string;
6
+ diagnostics: {
7
+ config: {
8
+ id: string;
9
+ rules: {
10
+ id: string;
11
+ name: string;
12
+ passed: boolean;
13
+ }[];
14
+ };
15
+ };
6
16
  };
7
17
  /**
8
18
  * the main function to calculate a score and category.
9
19
  * Might throw an error.
10
20
  */
11
- export declare function calculateScore(ruleConfig: ScoreConfig, ruleInput: RuleData): ScoreResult;
21
+ export declare function calculateScore(ruleConfig: ScoreConfig, ruleInput: RuleData): Promise<ScoreResult>;
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.calculateScore = void 0;
4
4
  const evaluateScoreCondition_1 = require("./evaluateScoreCondition");
5
5
  const helpers_1 = require("./helpers");
6
+ const general_1 = require("../general");
6
7
  function evaluateASTNode(node, data) {
7
8
  if (node.type === "LanguageOperator") {
8
9
  if (!node.children.length) {
@@ -27,16 +28,26 @@ function evaluateRule(rule, data) {
27
28
  throw new Error("A rule may only have 1 root node");
28
29
  }
29
30
  const rulePassed = rule.tree.every(n => evaluateASTNode(n, data));
30
- return rulePassed ? rule.trueWeight : rule.falseWeight;
31
+ return {
32
+ passed: rulePassed,
33
+ score: rulePassed ? rule.trueWeight : rule.falseWeight,
34
+ };
31
35
  }
36
+ /**
37
+ * We guarantee that the same configId or ruleId will always produce the same output.
38
+ * This is the closest thing we have to versioning.
39
+ */
40
+ const jsonId = (json) => (0, general_1.hashPassword)(JSON.stringify(json)).then(hash => hash.slice(0, 10));
32
41
  /**
33
42
  * the main function to calculate a score and category.
34
43
  * Might throw an error.
35
44
  */
36
- function calculateScore(ruleConfig, ruleInput) {
45
+ async function calculateScore(ruleConfig, ruleInput) {
37
46
  const result = ruleConfig.rules.map(rule => evaluateRule(rule, ruleInput));
38
47
  const [addOrMultiply, initialValue] = (0, helpers_1.getCombinator)(ruleConfig.combinator);
39
- const finalScore = result.reduce(addOrMultiply, initialValue);
48
+ const finalScore = result
49
+ .map(x => x.score)
50
+ .reduce(addOrMultiply, initialValue);
40
51
  const matchingCategories = (0, helpers_1.addInfiniteThresholdBoundaries)(ruleConfig.scoreThresholds).filter(threshold => finalScore >= threshold.from && finalScore <= threshold.to);
41
52
  if (matchingCategories.length === 0) {
42
53
  throw new Error(`No categories match the final score (${finalScore})`);
@@ -47,6 +58,16 @@ function calculateScore(ruleConfig, ruleInput) {
47
58
  return {
48
59
  score: finalScore,
49
60
  category: matchingCategories[0].name,
61
+ diagnostics: {
62
+ config: {
63
+ id: await jsonId(ruleConfig),
64
+ rules: await Promise.all(result.map(async ({ passed }, i) => {
65
+ const r = ruleConfig.rules[i];
66
+ const ruleId = await jsonId(r);
67
+ return { id: ruleId, name: r.name, passed };
68
+ })),
69
+ },
70
+ },
50
71
  };
51
72
  }
52
73
  exports.calculateScore = calculateScore;
@@ -27,7 +27,7 @@ function evaluateScoreCondition(node, data) {
27
27
  const values = rawValues[i];
28
28
  if (!values.length) {
29
29
  // TODO: if one of the values required for your rule doesn't exist, then what?
30
- // for now, the rule will return value
30
+ // for now, the rule will return false.
31
31
  return false;
32
32
  }
33
33
  // also check if the claimed type of the value matches the actual type of the value
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
package/package.json CHANGED
@@ -1,12 +1,13 @@
1
1
  {
2
2
  "name": "@raytio/core",
3
- "version": "9.0.3",
3
+ "version": "10.0.0",
4
4
  "license": "MIT",
5
5
  "main": "index",
6
6
  "types": "index",
7
7
  "files": [
8
8
  "index.js",
9
9
  "index.d.ts",
10
+ "CHANGELOG.md",
10
11
  "dist"
11
12
  ],
12
13
  "scripts": {
@@ -16,14 +17,14 @@
16
17
  },
17
18
  "dependencies": {
18
19
  "@raytio/maxcryptor": "3.1.0",
19
- "@raytio/types": "6.0.0",
20
+ "@raytio/types": "6.0.1",
20
21
  "ramda": "0.28.0"
21
22
  },
22
23
  "devDependencies": {
23
- "@types/ramda": "0.27.64",
24
+ "@types/ramda": "0.28.11",
24
25
  "jest": "27.5.1",
25
26
  "localstorage-polyfill": "1.0.1",
26
- "ts-jest": "27.1.3"
27
+ "ts-jest": "27.1.4"
27
28
  },
28
29
  "jest": {
29
30
  "transform": {