@raytio/core 10.0.1 → 11.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 +10 -0
- package/README.md +129 -55
- package/dist/__tests__/docs.test.d.ts +1 -0
- package/dist/__tests__/docs.test.js +24 -0
- package/dist/crypto/getAADecryptor.d.ts +8 -3
- package/dist/crypto/helpers.d.ts +2 -2
- package/dist/general/conditional.d.ts +12 -2
- package/dist/general/conditional.js +11 -1
- package/dist/general/date.d.ts +2 -0
- package/dist/general/date.js +18 -0
- package/dist/general/index.d.ts +1 -0
- package/dist/general/index.js +1 -0
- package/dist/rules/calculateScore.d.ts +7 -2
- package/dist/rules/calculateScore.js +8 -2
- package/dist/rules/convertInstanceToRuleInput.d.ts +2 -2
- package/dist/rules/convertInstanceToRuleInput.js +2 -3
- package/dist/rules/evaluateScoreCondition.js +0 -1
- package/dist/rules/helpers/__tests__/addInfiniteThresholdBoundaries.test.d.ts +1 -0
- package/dist/rules/helpers/__tests__/addInfiniteThresholdBoundaries.test.js +27 -0
- package/dist/rules/helpers/__tests__/checkTypeofValue.test.d.ts +1 -0
- package/dist/rules/helpers/__tests__/checkTypeofValue.test.js +49 -0
- package/dist/rules/helpers/__tests__/getValuesFromPath.test.d.ts +1 -0
- package/dist/rules/helpers/__tests__/getValuesFromPath.test.js +67 -0
- package/dist/rules/helpers/__tests__/thresholds.test.d.ts +1 -0
- package/dist/rules/helpers/__tests__/thresholds.test.js +32 -0
- package/dist/rules/helpers/checkTypeofValue.js +11 -6
- package/dist/rules/helpers/thresholds.js +1 -2
- package/dist/rules/operators/__tests__/bool.test.d.ts +1 -0
- package/dist/rules/operators/__tests__/bool.test.js +21 -0
- package/dist/rules/operators/__tests__/date.test.d.ts +1 -0
- package/dist/rules/operators/__tests__/date.test.js +81 -0
- package/dist/rules/operators/__tests__/hfield.test.d.ts +1 -0
- package/dist/rules/operators/__tests__/hfield.test.js +38 -0
- package/dist/rules/operators/__tests__/hschema.test.d.ts +1 -0
- package/dist/rules/operators/__tests__/hschema.test.js +24 -0
- package/dist/rules/operators/__tests__/number.test.d.ts +1 -0
- package/dist/rules/operators/__tests__/number.test.js +53 -0
- package/dist/rules/operators/__tests__/string.test.d.ts +1 -0
- package/dist/rules/operators/__tests__/string.test.js +74 -0
- package/dist/rules/types/config.d.ts +21 -17
- package/dist/rules/types/dataValueTypes.d.ts +4 -4
- package/dist/rules/types/internal.d.ts +3 -3
- package/dist/rules/version.d.ts +1 -1
- package/dist/rules/version.js +1 -1
- package/dist/schema/labels.js +1 -1
- package/dist/util/canonicalJsonify.js +1 -1
- package/dist/util/handleResponse.js +1 -1
- package/dist/verifications/getPOVerification.d.ts +7 -4
- package/dist/verifications/getPOVerification.js +15 -4
- package/dist/verifications/safeHarbour.d.ts +2 -2
- package/dist/verifications/verifyCheck/__tests__/getOwnRealVerifications.test.d.ts +1 -0
- package/dist/verifications/verifyCheck/__tests__/getOwnRealVerifications.test.js +152 -0
- package/dist/verifications/verifyCheck/__tests__/getSomeoneElsesRealVerifications.test.d.ts +1 -0
- package/dist/verifications/verifyCheck/__tests__/getSomeoneElsesRealVerifications.test.js +205 -0
- package/dist/verifications/verifyCheck/getOwnRealVerifications.js +5 -2
- package/dist/verifications/verifyCheck/getSomeoneElsesRealVerifications.d.ts +1 -1
- package/dist/verifications/verifyCheck/getSomeoneElsesRealVerifications.js +3 -2
- package/dist/verifications/verifyCheck/operations/__tests__/checkOwnVerification.test.d.ts +1 -0
- package/dist/verifications/verifyCheck/operations/__tests__/checkOwnVerification.test.js +91 -0
- package/dist/verifications/verifyCheck/operations/__tests__/checkSomeoneElsesVerifications.test.d.ts +1 -0
- package/dist/verifications/verifyCheck/operations/__tests__/checkSomeoneElsesVerifications.test.js +49 -0
- package/dist/verifications/verifyCheck/operations/__tests__/sampleBundle.json +43 -0
- package/dist/verifications/verifyCheck/operations/checkOwnVerification.d.ts +1 -1
- package/dist/verifications/verifyCheck/operations/checkOwnVerification.js +1 -1
- package/package.json +13 -10
|
@@ -7,55 +7,57 @@ import { GetTSType } from "./dataValueTypes";
|
|
|
7
7
|
* we can't just rename or remove any, since that would break
|
|
8
8
|
* existing rules.
|
|
9
9
|
*/
|
|
10
|
-
export
|
|
10
|
+
export 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
11
|
/** @ignore */
|
|
12
|
-
export
|
|
12
|
+
export type ValuePathFieldProp = "meta" | "value" | "valueLength" | `subField|${string}`;
|
|
13
13
|
/** @ignore */
|
|
14
|
-
export
|
|
14
|
+
export type ValuePath = [type: "schema", schemaName: string, prop: "meta"] | [
|
|
15
15
|
type: "field",
|
|
16
16
|
schemaName: string,
|
|
17
17
|
fieldName: string,
|
|
18
18
|
prop: ValuePathFieldProp
|
|
19
19
|
];
|
|
20
20
|
/** @ignore */
|
|
21
|
-
export
|
|
21
|
+
export type ValueRefConst<T> = {
|
|
22
22
|
type: "constant";
|
|
23
23
|
value: T;
|
|
24
24
|
};
|
|
25
25
|
/** @ignore */
|
|
26
|
-
export
|
|
26
|
+
export type ValueRefVar = {
|
|
27
27
|
type: "variable";
|
|
28
28
|
path: ValuePath;
|
|
29
29
|
};
|
|
30
30
|
/** @ignore */
|
|
31
|
-
export
|
|
31
|
+
export type ValueRef<T> = ValueRefConst<T> | ValueRefVar;
|
|
32
32
|
/** @ignore these are the LHS & RHS operands which come from variables (or constants) */
|
|
33
|
-
export
|
|
33
|
+
export 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
|
|
35
|
+
export type ConstValueTypes = "DateUnit" | "RegEx" | "Verifier" | "FieldVerification" | "POVerification";
|
|
36
36
|
/** @ignore full list of operands which come from variables OR constants */
|
|
37
|
-
export
|
|
37
|
+
export type ValueType = ConstValueTypes | FieldValueTypes;
|
|
38
38
|
/** @ignore */
|
|
39
|
-
export
|
|
39
|
+
export type ValueDef<T = ValueType> = {
|
|
40
40
|
type: T;
|
|
41
41
|
value: ValueRef<GetTSType<T>>;
|
|
42
42
|
};
|
|
43
43
|
/** @ignore */
|
|
44
|
-
export
|
|
44
|
+
export type ASTScoreConditionNode = {
|
|
45
45
|
type: "ScoreCondition";
|
|
46
46
|
operator: OperatorID;
|
|
47
47
|
values: ValueDef<ValueType>[];
|
|
48
48
|
};
|
|
49
49
|
/** @ignore */
|
|
50
|
-
export
|
|
50
|
+
export type ASTLanguageOperatorNode = {
|
|
51
51
|
type: "LanguageOperator";
|
|
52
52
|
operator: "OR" | "AND";
|
|
53
53
|
children: ASTNode[];
|
|
54
54
|
};
|
|
55
55
|
/** @ignore */
|
|
56
|
-
export
|
|
56
|
+
export type ASTNode = ASTLanguageOperatorNode | ASTScoreConditionNode;
|
|
57
57
|
/** @ignore */
|
|
58
|
-
export
|
|
58
|
+
export type ScoreRule = {
|
|
59
|
+
/** UUID for the rule. Configs created before Feb 2023 won't have this field */
|
|
60
|
+
id: string | undefined;
|
|
59
61
|
/** user defined */
|
|
60
62
|
name: string;
|
|
61
63
|
/** user defined */
|
|
@@ -66,9 +68,11 @@ export declare type ScoreRule = {
|
|
|
66
68
|
falseWeight: number;
|
|
67
69
|
/** must have a single root node */
|
|
68
70
|
tree: [ASTNode];
|
|
71
|
+
/** if undefined, assume true. Configs created before Feb 2023 won't have this field */
|
|
72
|
+
enabled: boolean | undefined;
|
|
69
73
|
};
|
|
70
74
|
/** @ignore e.g. 0-10 is "red". We only work with integers. Comparisons use >= and <= */
|
|
71
|
-
export
|
|
75
|
+
export type ScoreThreshold = {
|
|
72
76
|
from: number;
|
|
73
77
|
to: number;
|
|
74
78
|
name: string;
|
|
@@ -79,12 +83,12 @@ export declare type ScoreThreshold = {
|
|
|
79
83
|
colour: string | undefined;
|
|
80
84
|
};
|
|
81
85
|
/** @ignore */
|
|
82
|
-
export
|
|
86
|
+
export type Combinator = "+" | "*";
|
|
83
87
|
/**
|
|
84
88
|
* @ignore
|
|
85
89
|
* the big object for configuring score rules
|
|
86
90
|
*/
|
|
87
|
-
export
|
|
91
|
+
export type ScoreConfig = {
|
|
88
92
|
combinator: Combinator;
|
|
89
93
|
scoreThresholds: ScoreThreshold[];
|
|
90
94
|
rules: ScoreRule[];
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { FieldVerification, NId, POVerification } from "@raytio/types";
|
|
2
2
|
import type { HFieldSymbol, HSchemaSymbol } from "../helpers";
|
|
3
3
|
/** undefined if not shared */
|
|
4
|
-
export
|
|
4
|
+
export type HField = {
|
|
5
5
|
__typeof__: typeof HFieldSymbol;
|
|
6
6
|
verification: FieldVerification;
|
|
7
7
|
verifiedBy: readonly NId[];
|
|
@@ -9,11 +9,11 @@ export declare type HField = {
|
|
|
9
9
|
cameFromSchema: string;
|
|
10
10
|
};
|
|
11
11
|
/** undefined if not shared */
|
|
12
|
-
export
|
|
12
|
+
export type HSchema = {
|
|
13
13
|
__typeof__: typeof HSchemaSymbol;
|
|
14
14
|
verification?: POVerification;
|
|
15
15
|
verifiedBy: readonly NId[];
|
|
16
16
|
};
|
|
17
17
|
export declare const DATE_UNITS: readonly ["ms", "s", "m", "h", "D", "M", "W", "Y"];
|
|
18
|
-
export
|
|
19
|
-
export
|
|
18
|
+
export type DateUnit = (typeof DATE_UNITS)[number];
|
|
19
|
+
export 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,11 +1,11 @@
|
|
|
1
1
|
import { HField, HSchema, GetTSType } from "./dataValueTypes";
|
|
2
2
|
import { FieldValueTypes, ValueType } from "./config";
|
|
3
|
-
export
|
|
3
|
+
export type RuleDataProperty<T extends FieldValueTypes> = {
|
|
4
4
|
type: T;
|
|
5
5
|
value: GetTSType<T>;
|
|
6
6
|
hField: HField;
|
|
7
7
|
};
|
|
8
|
-
export
|
|
8
|
+
export type RuleData = {
|
|
9
9
|
[schemaName: string]: {
|
|
10
10
|
hSchema: HSchema;
|
|
11
11
|
properties: {
|
|
@@ -13,7 +13,7 @@ export declare type RuleData = {
|
|
|
13
13
|
};
|
|
14
14
|
}[];
|
|
15
15
|
};
|
|
16
|
-
export
|
|
16
|
+
export type OperatorDef = {
|
|
17
17
|
/** the first operand is the LHS, all others are RHS */
|
|
18
18
|
operands: ValueType[];
|
|
19
19
|
implementation: (...args: any[]) => boolean;
|
package/dist/rules/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const SUBMISSION_RULES_VERSION = "sr1.
|
|
1
|
+
export declare const SUBMISSION_RULES_VERSION = "sr1.4.0";
|
package/dist/rules/version.js
CHANGED
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.SUBMISSION_RULES_VERSION = void 0;
|
|
4
4
|
// this must be kept in sync with ./CHANGELOG.md. See that file for more info
|
|
5
|
-
exports.SUBMISSION_RULES_VERSION = "sr1.
|
|
5
|
+
exports.SUBMISSION_RULES_VERSION = "sr1.4.0";
|
package/dist/schema/labels.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.findSchemaLabel = void 0;
|
|
4
4
|
/**
|
|
5
|
-
* every possible label should be listed here,
|
|
5
|
+
* every possible label should be listed here, because the client
|
|
6
6
|
* finds the schemaName by searching the list of labels for the
|
|
7
7
|
* first one that is not in this list
|
|
8
8
|
* @internal
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
/* eslint-disable fp/no-mutating-methods, fp/no-mutation,
|
|
2
|
+
/* eslint-disable fp/no-mutating-methods, fp/no-mutation, prefer-reflect */
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.canonicalJsonify = void 0;
|
|
5
5
|
const isObject = (a) => Object.prototype.toString.call(a) === "[object Object]"; // TODO: wtf ?
|
|
@@ -13,7 +13,7 @@ exports.handleResponse = void 0;
|
|
|
13
13
|
const handleResponse = async (response) => {
|
|
14
14
|
const json = await response.json();
|
|
15
15
|
// json could be a string | number
|
|
16
|
-
if (typeof json === "object" && "message" in json) {
|
|
16
|
+
if (typeof json === "object" && json && "message" in json) {
|
|
17
17
|
throw new Error(json.message);
|
|
18
18
|
}
|
|
19
19
|
return json;
|
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
import { FieldVerification, ProfileObject, POVerification, RealVer, Schema, VerificationProvider, ProfileObjectForUpload, NId } from "@raytio/types";
|
|
2
|
+
export type VerDetails = {
|
|
3
|
+
sourceNId?: NId;
|
|
4
|
+
verifiers: VerificationProvider[];
|
|
5
|
+
/** field only present for expired verifications */
|
|
6
|
+
expiryDate?: Date;
|
|
7
|
+
};
|
|
2
8
|
/**
|
|
3
9
|
* Determines the verification status of a profile object, and its individual fields.
|
|
4
10
|
*/
|
|
@@ -8,9 +14,6 @@ export declare function getPOVerification({ PO, schema, realVers, }: {
|
|
|
8
14
|
realVers: RealVer[];
|
|
9
15
|
}): {
|
|
10
16
|
status: POVerification;
|
|
11
|
-
details:
|
|
12
|
-
sourceNId?: NId;
|
|
13
|
-
verifiers: VerificationProvider[];
|
|
14
|
-
};
|
|
17
|
+
details: VerDetails;
|
|
15
18
|
fieldVerifications: Record<string, FieldVerification>;
|
|
16
19
|
};
|
|
@@ -12,12 +12,17 @@ const schema_1 = require("../schema");
|
|
|
12
12
|
* Determines the verification status of a profile object, and its individual fields.
|
|
13
13
|
*/
|
|
14
14
|
function getPOVerification({ PO, schema, realVers, }) {
|
|
15
|
-
var _a, _b;
|
|
15
|
+
var _a, _b, _c;
|
|
16
16
|
// safe guard to avoid a misleading response from this function
|
|
17
17
|
const schemaName = PO.schema || (0, schema_1.findSchemaLabel)(PO.labels);
|
|
18
18
|
if (schema.name !== schemaName) {
|
|
19
19
|
throw new Error(`Wrong schema supplied to getPOVerification: ${schema.name} != ${schemaName}`);
|
|
20
20
|
}
|
|
21
|
+
if (!PO.n_id) {
|
|
22
|
+
// TODO: (semver breaking) immediately return NotVerified here
|
|
23
|
+
// eslint-disable-next-line no-console
|
|
24
|
+
console.warn("No n_id supplied to getPOVerification. You may be seeing incorrect and misleading verifications");
|
|
25
|
+
}
|
|
21
26
|
const someAreEncrypted = !!(0, crypto_1.someEncrypted)(PO.properties);
|
|
22
27
|
if (someAreEncrypted) {
|
|
23
28
|
return {
|
|
@@ -61,8 +66,8 @@ function getPOVerification({ PO, schema, realVers, }) {
|
|
|
61
66
|
if (!Object.values(shouldBeVerifiedProps).length) {
|
|
62
67
|
return types_1.POVerification.NotVerified;
|
|
63
68
|
}
|
|
64
|
-
const
|
|
65
|
-
if (
|
|
69
|
+
const anyExpired = Object.values(fieldVerifications).some(x => x === types_1.FieldVerification.Expired);
|
|
70
|
+
if (anyExpired)
|
|
66
71
|
return types_1.POVerification.Expired;
|
|
67
72
|
const anyVerfiedFalse = Object.values(fieldVerifications).some(x => x === types_1.FieldVerification.VerifiedFalse);
|
|
68
73
|
if (anyVerfiedFalse)
|
|
@@ -85,9 +90,15 @@ function getPOVerification({ PO, schema, realVers, }) {
|
|
|
85
90
|
realVers,
|
|
86
91
|
shouldBeVerifiedProps,
|
|
87
92
|
});
|
|
93
|
+
// find the earliest expiry date if there is one
|
|
94
|
+
const maybeExpiryDate = ((_c = (0, ramda_1.sortBy)(ver => +ver.expired, realVers.filter(ver => ver.belongsToNId === PO.n_id && ver.expired))[0]) === null || _c === void 0 ? void 0 : _c.expired) || undefined;
|
|
88
95
|
return {
|
|
89
96
|
status,
|
|
90
|
-
details: {
|
|
97
|
+
details: {
|
|
98
|
+
sourceNId: PO.n_id,
|
|
99
|
+
verifiers,
|
|
100
|
+
expiryDate: status === types_1.POVerification.Expired ? maybeExpiryDate : undefined,
|
|
101
|
+
},
|
|
91
102
|
fieldVerifications,
|
|
92
103
|
};
|
|
93
104
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { ProfileObject, RealVer, Schema } from "@raytio/types";
|
|
2
2
|
/** an object listing the `xId`s for each SafeHarbourCode */
|
|
3
|
-
export
|
|
3
|
+
export type SafeHarbourObj = Partial<Record<SafeHarbourCode, string[]>>;
|
|
4
4
|
/** the response from {@link calcSafeHarbourScore} */
|
|
5
|
-
export
|
|
5
|
+
export type SafeHarbourResult = {
|
|
6
6
|
isSafe: boolean;
|
|
7
7
|
flags: SafeHarbourObj;
|
|
8
8
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const __1 = require("..");
|
|
4
|
+
const operations_1 = require("../operations");
|
|
5
|
+
jest.mock("../operations");
|
|
6
|
+
/**
|
|
7
|
+
* in this test case:
|
|
8
|
+
* - there are valid verifications for fName=Max and fName=Erika, but we don't which
|
|
9
|
+
* verification corresponds to which value.
|
|
10
|
+
* - there is an invalid verification (tampered with) for lName=Mustermann
|
|
11
|
+
* - there are verifications for non-existant POs and fields, which will be skipped
|
|
12
|
+
*
|
|
13
|
+
* Also note:
|
|
14
|
+
* - the verification for fName=Max is expired
|
|
15
|
+
* - the verification for fName=Erika is "VerifiedFalse"
|
|
16
|
+
*/
|
|
17
|
+
describe("getOwnRealVerifications", () => {
|
|
18
|
+
beforeAll(() => {
|
|
19
|
+
operations_1.checkOwnVerification.mockImplementation(async ({ signature }) => {
|
|
20
|
+
if (signature === "signatureForLastNameMustermannFromN2")
|
|
21
|
+
return false;
|
|
22
|
+
return true;
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
it("calls the verifyCheck function for each PO, keeping only the valid ones", async () => {
|
|
26
|
+
const profileObjects = [
|
|
27
|
+
{ n_id: "n1", properties: { fName: "Max", lName: "Mustermann" } },
|
|
28
|
+
{ n_id: "n2", properties: { fName: "Erika", lName: "Mustermann" } },
|
|
29
|
+
];
|
|
30
|
+
const verifications = [
|
|
31
|
+
{
|
|
32
|
+
n_id: "nv1",
|
|
33
|
+
properties: {
|
|
34
|
+
valid_until: "2020-08-28T23:12:35.678Z",
|
|
35
|
+
verifications: [
|
|
36
|
+
{
|
|
37
|
+
signature: "signatureForFirstNameMax",
|
|
38
|
+
data: {
|
|
39
|
+
field: "fName",
|
|
40
|
+
verifier_source_id: "Ministry of pike river mine re-entry",
|
|
41
|
+
verifier_service_id: "Minister for pike river re-entry",
|
|
42
|
+
verifier_id: "v1",
|
|
43
|
+
verification_date: "2020-08-28T23:11:20.592912",
|
|
44
|
+
request_div: "x1",
|
|
45
|
+
passed: true,
|
|
46
|
+
source_n_id: "n1",
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
],
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
n_id: "nv2",
|
|
54
|
+
properties: {
|
|
55
|
+
verifications: [
|
|
56
|
+
{
|
|
57
|
+
signature: "signatureForFirstNameErika",
|
|
58
|
+
data: {
|
|
59
|
+
field: "fName",
|
|
60
|
+
verifier_source_id: "Ministry of pike river mine re-entry",
|
|
61
|
+
verifier_service_id: "Minister for pike river re-entry",
|
|
62
|
+
verifier_id: "v1",
|
|
63
|
+
verification_date: "2020-08-28T23:11:20.592912",
|
|
64
|
+
request_div: "x2",
|
|
65
|
+
passed: false,
|
|
66
|
+
source_n_id: "n2",
|
|
67
|
+
},
|
|
68
|
+
},
|
|
69
|
+
],
|
|
70
|
+
},
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
n_id: "nv3",
|
|
74
|
+
properties: {
|
|
75
|
+
verifications: [
|
|
76
|
+
{
|
|
77
|
+
signature: "signatureForLastNameMustermannFromN2",
|
|
78
|
+
data: {
|
|
79
|
+
field: "lName",
|
|
80
|
+
verifier_source_id: "Ministry of pike river mine re-entry",
|
|
81
|
+
verifier_service_id: "Minister for pike river re-entry",
|
|
82
|
+
verifier_id: "v1",
|
|
83
|
+
verification_date: "2020-08-28T23:11:20.592912",
|
|
84
|
+
request_div: "x3",
|
|
85
|
+
passed: false,
|
|
86
|
+
source_n_id: "n2", // this ver was for lName=Mustermann in n2, so doesn't apply to lName=Mustermann in n1 !
|
|
87
|
+
},
|
|
88
|
+
},
|
|
89
|
+
],
|
|
90
|
+
},
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
n_id: "nv4",
|
|
94
|
+
properties: {
|
|
95
|
+
verifications: [{ data: { source_n_id: "doesn't exist" } }],
|
|
96
|
+
},
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
n_id: "nv5",
|
|
100
|
+
properties: {
|
|
101
|
+
verifications: [
|
|
102
|
+
{ data: { source_n_id: "n2", field: "doesn't exist" } },
|
|
103
|
+
],
|
|
104
|
+
},
|
|
105
|
+
},
|
|
106
|
+
];
|
|
107
|
+
const realVers = await (0, __1.getOwnRealVerifications)({
|
|
108
|
+
profileObjects,
|
|
109
|
+
verifications,
|
|
110
|
+
userId: "geesepolice2002",
|
|
111
|
+
});
|
|
112
|
+
expect(operations_1.checkOwnVerification).toHaveBeenCalledTimes(3);
|
|
113
|
+
// 3 times, not 5. Because this new method doesn't need to build a big matrix of possible combinations
|
|
114
|
+
expect(realVers).toStrictEqual([
|
|
115
|
+
{
|
|
116
|
+
fieldName: "fName",
|
|
117
|
+
value: "Max",
|
|
118
|
+
belongsToNId: "n1",
|
|
119
|
+
nID: "nv1",
|
|
120
|
+
expired: new Date("2020-08-28T23:12:35.678Z"),
|
|
121
|
+
metadata: undefined,
|
|
122
|
+
provider: {
|
|
123
|
+
dataSourceNId: "Ministry of pike river mine re-entry",
|
|
124
|
+
date: new Date("2020-08-28T23:11:20.592Z"),
|
|
125
|
+
serviceProviderNId: "Minister for pike river re-entry",
|
|
126
|
+
verifierNId: "v1",
|
|
127
|
+
},
|
|
128
|
+
signature: "signatureForFirstNameMax",
|
|
129
|
+
verified: true,
|
|
130
|
+
xId: "x1",
|
|
131
|
+
},
|
|
132
|
+
{
|
|
133
|
+
fieldName: "fName",
|
|
134
|
+
value: "Erika",
|
|
135
|
+
belongsToNId: "n2",
|
|
136
|
+
nID: "nv2",
|
|
137
|
+
expired: false,
|
|
138
|
+
metadata: undefined,
|
|
139
|
+
provider: {
|
|
140
|
+
dataSourceNId: "Ministry of pike river mine re-entry",
|
|
141
|
+
date: new Date("2020-08-28T23:11:20.592Z"),
|
|
142
|
+
serviceProviderNId: "Minister for pike river re-entry",
|
|
143
|
+
verifierNId: "v1",
|
|
144
|
+
},
|
|
145
|
+
signature: "signatureForFirstNameErika",
|
|
146
|
+
verified: false,
|
|
147
|
+
xId: "x2",
|
|
148
|
+
},
|
|
149
|
+
// note how lastName is not included since it's invalid
|
|
150
|
+
]);
|
|
151
|
+
});
|
|
152
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const getSomeoneElsesRealVerifications_1 = require("../getSomeoneElsesRealVerifications");
|
|
4
|
+
const operations_1 = require("../operations");
|
|
5
|
+
jest.mock("../operations");
|
|
6
|
+
const checkVerificationsResp = [
|
|
7
|
+
{
|
|
8
|
+
verified: false,
|
|
9
|
+
signature: "sig2",
|
|
10
|
+
data: {
|
|
11
|
+
field: "a",
|
|
12
|
+
value: 1,
|
|
13
|
+
verifier_source_id: "verifier_source_id",
|
|
14
|
+
verifier_service_id: "verifier_service_id",
|
|
15
|
+
verifier_id: "verifier_id",
|
|
16
|
+
date: "date",
|
|
17
|
+
request_div: "request_div",
|
|
18
|
+
passed: "passed",
|
|
19
|
+
source_n_id: "source_n_id",
|
|
20
|
+
verification_date: "2003-05-18T11:22:33.456790",
|
|
21
|
+
},
|
|
22
|
+
n_id: "my_field",
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
verified: true,
|
|
26
|
+
signature: "sig",
|
|
27
|
+
data: {
|
|
28
|
+
field: "email_address",
|
|
29
|
+
value: "jean@example.com",
|
|
30
|
+
verifier_source_id: "verifier_source_id",
|
|
31
|
+
verifier_service_id: "verifier_service_id",
|
|
32
|
+
verifier_id: "verifier_id",
|
|
33
|
+
date: "date",
|
|
34
|
+
request_div: "request_div",
|
|
35
|
+
passed: "passed",
|
|
36
|
+
source_n_id: "source_n_id",
|
|
37
|
+
verification_date: "2020-08-28T23:11:20.592912",
|
|
38
|
+
metadata: {
|
|
39
|
+
status: "pending",
|
|
40
|
+
send_code_attempts: [
|
|
41
|
+
{
|
|
42
|
+
channel: "email",
|
|
43
|
+
time: "2020-08-28T23:11:24.157Z",
|
|
44
|
+
channel_id: "abc",
|
|
45
|
+
},
|
|
46
|
+
],
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
n_id: "my_email",
|
|
50
|
+
},
|
|
51
|
+
];
|
|
52
|
+
const profileObjects = [
|
|
53
|
+
{ properties: { a: 1 } },
|
|
54
|
+
{ properties: { email_address: "jean@example.com" } },
|
|
55
|
+
{
|
|
56
|
+
properties: {
|
|
57
|
+
my_photo: {
|
|
58
|
+
content: "...",
|
|
59
|
+
content_type: "...",
|
|
60
|
+
n_id: "n_id_of_my_ss_File",
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
},
|
|
64
|
+
];
|
|
65
|
+
const verifications = [
|
|
66
|
+
{
|
|
67
|
+
n_id: "my_email",
|
|
68
|
+
properties: {
|
|
69
|
+
verifications: [
|
|
70
|
+
{
|
|
71
|
+
data: {
|
|
72
|
+
source: "EMAIL_ADDRESS",
|
|
73
|
+
passed: false,
|
|
74
|
+
request_div: "140c20e3-5146-4123-8e75-fe9064a6b71f",
|
|
75
|
+
source_n_id: "3ec48392-4211-4c6a-92f9-50031f0f5716",
|
|
76
|
+
verifier_source_id: "d796a383-5622-4e05-93b2-2fbe292d76fa",
|
|
77
|
+
metadata: {
|
|
78
|
+
url: "https://verify.twilio.com/v2/Services/VAa447486967ee88c1f59e2896f617f981/Verifications/VE398de58af34b4ef22fa24a404f30898d",
|
|
79
|
+
send_code_attempts: [
|
|
80
|
+
{
|
|
81
|
+
channel: "email",
|
|
82
|
+
time: "2020-08-28T23:11:24.157Z",
|
|
83
|
+
channel_id: "pCmrKC4qQBSC_3m3crMctA",
|
|
84
|
+
},
|
|
85
|
+
],
|
|
86
|
+
status: "pending",
|
|
87
|
+
id: "VE398de58af34b4ef22fa24a404f30898d",
|
|
88
|
+
},
|
|
89
|
+
verifier_id: "d796a383-5622-4e05-93b2-2fbe292d76fa",
|
|
90
|
+
field: "email_address",
|
|
91
|
+
verifier_div: "7137da93-0a53-4de7-b6df-3aa4b2b8d5e6",
|
|
92
|
+
v_id: "d6c5246c-1141-4d0a-929f-1ed0aa00b52d",
|
|
93
|
+
verification_date: "2020-08-28T23:11:20.592912",
|
|
94
|
+
valid_until: "2020-08-28T23:12:35.678Z",
|
|
95
|
+
},
|
|
96
|
+
signature: "abcdefghijklmopqrstuvwxyz",
|
|
97
|
+
},
|
|
98
|
+
],
|
|
99
|
+
field: "email_address",
|
|
100
|
+
initiator_n_id: "3ec48392-4211-4c6a-92f9-50031f0f5716",
|
|
101
|
+
n_id: "my_email",
|
|
102
|
+
},
|
|
103
|
+
labels: ["ss_Verification", "ProfileObject"],
|
|
104
|
+
referenceList: {},
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
n_id: "my_photo",
|
|
108
|
+
properties: {
|
|
109
|
+
verifications: [
|
|
110
|
+
{
|
|
111
|
+
data: {
|
|
112
|
+
passed: false,
|
|
113
|
+
request_div: "a",
|
|
114
|
+
source_n_id: "b",
|
|
115
|
+
verifier_source_id: "c",
|
|
116
|
+
verifier_id: "d",
|
|
117
|
+
field: "my_photo",
|
|
118
|
+
verifier_div: "e",
|
|
119
|
+
v_id: "f",
|
|
120
|
+
verification_date: "2020-12-05T11:22:33.456789",
|
|
121
|
+
valid_until: "2020-08-28T23:12:35.678Z",
|
|
122
|
+
},
|
|
123
|
+
signature: "abcdefghijklmopqrstuvwxyz",
|
|
124
|
+
},
|
|
125
|
+
],
|
|
126
|
+
field: "my_photo",
|
|
127
|
+
initiator_n_id: "3ec48392-4211-4c6a-92f9-50031f0f5716",
|
|
128
|
+
n_id: "my_photo",
|
|
129
|
+
},
|
|
130
|
+
labels: ["ss_Verification", "ProfileObject"],
|
|
131
|
+
referenceList: {},
|
|
132
|
+
},
|
|
133
|
+
];
|
|
134
|
+
describe("getSomeoneElsesRealVerifications", () => {
|
|
135
|
+
beforeEach(() => {
|
|
136
|
+
jest.resetAllMocks();
|
|
137
|
+
operations_1.checkSomeoneElsesVerifications.mockResolvedValue(checkVerificationsResp);
|
|
138
|
+
});
|
|
139
|
+
it("returns an empty array if provided nothing", async () => {
|
|
140
|
+
const result = await (0, getSomeoneElsesRealVerifications_1.getSomeoneElsesRealVerifications)({
|
|
141
|
+
apiUrl: "https://example.com",
|
|
142
|
+
profileObjects: [],
|
|
143
|
+
verifications: [],
|
|
144
|
+
});
|
|
145
|
+
expect(result).toStrictEqual([]);
|
|
146
|
+
expect(operations_1.checkSomeoneElsesVerifications).not.toHaveBeenCalled();
|
|
147
|
+
});
|
|
148
|
+
it("processes the user's verifications correctly", async () => {
|
|
149
|
+
const result = await (0, getSomeoneElsesRealVerifications_1.getSomeoneElsesRealVerifications)({
|
|
150
|
+
apiUrl: "https://example.com",
|
|
151
|
+
profileObjects,
|
|
152
|
+
verifications,
|
|
153
|
+
});
|
|
154
|
+
expect(result).toStrictEqual([
|
|
155
|
+
{
|
|
156
|
+
belongsToNId: "source_n_id",
|
|
157
|
+
expired: false,
|
|
158
|
+
fieldName: "email_address",
|
|
159
|
+
metadata: {
|
|
160
|
+
send_code_attempts: [
|
|
161
|
+
{
|
|
162
|
+
channel: "email",
|
|
163
|
+
channel_id: "abc",
|
|
164
|
+
time: "2020-08-28T23:11:24.157Z",
|
|
165
|
+
},
|
|
166
|
+
],
|
|
167
|
+
status: "pending",
|
|
168
|
+
},
|
|
169
|
+
nID: "my_email",
|
|
170
|
+
provider: {
|
|
171
|
+
dataSourceNId: "verifier_source_id",
|
|
172
|
+
date: new Date("2020-08-28T23:11:20.592912Z"),
|
|
173
|
+
serviceProviderNId: "verifier_service_id",
|
|
174
|
+
verifierNId: "verifier_id",
|
|
175
|
+
},
|
|
176
|
+
signature: "sig",
|
|
177
|
+
value: "jean@example.com",
|
|
178
|
+
verified: "passed",
|
|
179
|
+
xId: "request_div",
|
|
180
|
+
},
|
|
181
|
+
]);
|
|
182
|
+
expect(operations_1.checkSomeoneElsesVerifications).toHaveBeenCalledTimes(1);
|
|
183
|
+
expect(operations_1.checkSomeoneElsesVerifications).toHaveBeenNthCalledWith(1, {
|
|
184
|
+
apiUrl: "https://example.com",
|
|
185
|
+
controller: undefined,
|
|
186
|
+
toVerify: [
|
|
187
|
+
{
|
|
188
|
+
verifications: [
|
|
189
|
+
{ n_id: "my_email", signature: "abcdefghijklmopqrstuvwxyz" },
|
|
190
|
+
],
|
|
191
|
+
data_to_verify: [{ value: "jean@example.com" }],
|
|
192
|
+
},
|
|
193
|
+
{
|
|
194
|
+
verifications: [
|
|
195
|
+
{ n_id: "my_photo", signature: "abcdefghijklmopqrstuvwxyz" },
|
|
196
|
+
],
|
|
197
|
+
data_to_verify: [
|
|
198
|
+
// note how it re-created the $reference
|
|
199
|
+
{ value: { $ref: "urn:profile_object:n_id_of_my_ss_File" } },
|
|
200
|
+
],
|
|
201
|
+
},
|
|
202
|
+
],
|
|
203
|
+
});
|
|
204
|
+
});
|
|
205
|
+
});
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getOwnRealVerifications = void 0;
|
|
4
|
+
const general_1 = require("../../general");
|
|
4
5
|
const maybeRereference_1 = require("../maybeRereference");
|
|
5
6
|
const operations_1 = require("./operations");
|
|
6
7
|
/**
|
|
@@ -46,9 +47,11 @@ const getOwnRealVerifications = async ({ verifications, profileObjects, userId,
|
|
|
46
47
|
dataSourceNId: data.verifier_source_id,
|
|
47
48
|
serviceProviderNId: data.verifier_service_id,
|
|
48
49
|
verifierNId: data.verifier_id,
|
|
49
|
-
date:
|
|
50
|
+
date: (0, general_1.repairDate)(data.verification_date),
|
|
50
51
|
},
|
|
51
|
-
expired:
|
|
52
|
+
expired: ver.properties.valid_until
|
|
53
|
+
? (0, general_1.repairDate)(ver.properties.valid_until)
|
|
54
|
+
: false,
|
|
52
55
|
metadata: data.metadata,
|
|
53
56
|
xId: data.request_div,
|
|
54
57
|
signature,
|