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