@raytio/core 10.1.0 → 11.1.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 +198 -59
- package/dist/{util/hash.d.ts → __tests__/docs.test.d.ts} +1 -1
- package/dist/__tests__/docs.test.js +24 -0
- package/dist/accessApplication/createAA.d.ts +17 -17
- package/dist/accessApplication/createAA.js +71 -71
- package/dist/accessApplication/index.d.ts +1 -1
- package/dist/accessApplication/index.js +17 -17
- package/dist/crypto/cognitoAttributes.d.ts +15 -15
- package/dist/crypto/cognitoAttributes.js +33 -33
- package/dist/crypto/decryptKeys.d.ts +1 -1
- package/dist/crypto/decryptKeys.js +33 -33
- package/dist/crypto/decryptSharedData.d.ts +26 -26
- package/dist/crypto/decryptSharedData.js +38 -38
- package/dist/crypto/getAADecryptor.d.ts +16 -16
- package/dist/crypto/getAADecryptor.js +20 -20
- package/dist/crypto/helpers.d.ts +18 -18
- package/dist/crypto/helpers.js +26 -26
- package/dist/crypto/index.d.ts +4 -4
- package/dist/crypto/index.js +21 -21
- package/dist/general/conditional.d.ts +17 -17
- package/dist/general/conditional.js +32 -32
- package/dist/general/date.d.ts +2 -2
- package/dist/general/date.js +18 -18
- package/dist/general/index.d.ts +4 -4
- package/dist/general/index.js +20 -20
- package/dist/general/password.d.ts +10 -10
- package/dist/general/password.js +31 -31
- package/dist/general/types.d.ts +6 -6
- package/dist/general/types.js +13 -13
- package/dist/index.d.ts +6 -6
- package/dist/index.js +22 -22
- package/dist/rules/calculateScore.d.ts +28 -23
- package/dist/rules/calculateScore.js +82 -76
- package/dist/rules/convertInstanceToRuleInput.d.ts +3 -3
- package/dist/rules/convertInstanceToRuleInput.js +138 -139
- package/dist/rules/evaluateScoreCondition.d.ts +2 -2
- package/dist/rules/evaluateScoreCondition.js +44 -45
- package/dist/{verifications/checkVerifications.d.ts → rules/helpers/__tests__/addInfiniteThresholdBoundaries.test.d.ts} +1 -1
- package/dist/rules/helpers/__tests__/addInfiniteThresholdBoundaries.test.js +27 -0
- package/dist/{verifications/checkVerificationsNew.d.ts → rules/helpers/__tests__/checkTypeofValue.test.d.ts} +1 -1
- package/dist/rules/helpers/__tests__/checkTypeofValue.test.js +49 -0
- package/dist/{verifications/verifyCheck/util/canonicalJsonify.d.ts → rules/helpers/__tests__/getValuesFromPath.test.d.ts} +1 -1
- 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/addInfiniteThresholdBoundaries.d.ts +8 -8
- package/dist/rules/helpers/addInfiniteThresholdBoundaries.js +11 -11
- package/dist/rules/helpers/checkTypeofValue.d.ts +9 -9
- package/dist/rules/helpers/checkTypeofValue.js +60 -55
- package/dist/rules/helpers/getValuesFromPath.d.ts +3 -3
- package/dist/rules/helpers/getValuesFromPath.js +50 -50
- package/dist/rules/helpers/index.d.ts +5 -5
- package/dist/rules/helpers/index.js +21 -21
- package/dist/rules/helpers/symbols.d.ts +2 -2
- package/dist/rules/helpers/symbols.js +5 -5
- package/dist/rules/helpers/thresholds.d.ts +5 -5
- package/dist/rules/helpers/thresholds.js +46 -47
- package/dist/rules/index.d.ts +7 -7
- package/dist/rules/index.js +25 -25
- 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/operators/bool.d.ts +2 -2
- package/dist/rules/operators/bool.js +17 -17
- package/dist/rules/operators/date.d.ts +2 -2
- package/dist/rules/operators/date.js +91 -91
- package/dist/rules/operators/hfield.d.ts +2 -2
- package/dist/rules/operators/hfield.js +33 -33
- package/dist/rules/operators/hschema.d.ts +2 -2
- package/dist/rules/operators/hschema.js +21 -21
- package/dist/rules/operators/index.d.ts +3 -3
- package/dist/rules/operators/index.js +11 -11
- package/dist/rules/operators/number.d.ts +2 -2
- package/dist/rules/operators/number.js +41 -41
- package/dist/rules/operators/string.d.ts +2 -2
- package/dist/rules/operators/string.js +58 -58
- package/dist/rules/types/config.d.ts +95 -91
- package/dist/rules/types/config.js +2 -2
- package/dist/rules/types/dataValueTypes.d.ts +19 -19
- package/dist/rules/types/dataValueTypes.js +4 -4
- package/dist/rules/types/index.d.ts +3 -3
- package/dist/rules/types/index.js +19 -19
- package/dist/rules/types/internal.d.ts +20 -20
- package/dist/rules/types/internal.js +2 -2
- package/dist/rules/validate.d.ts +6 -6
- package/dist/rules/validate.js +14 -14
- package/dist/rules/version.d.ts +1 -1
- package/dist/rules/version.js +5 -5
- package/dist/schema/expandSchema/__tests__/addLoadingTimes.test.d.ts +1 -0
- package/dist/schema/expandSchema/__tests__/addLoadingTimes.test.js +24 -0
- package/dist/schema/expandSchema/__tests__/expandSchema.test.d.ts +1 -0
- package/dist/schema/expandSchema/__tests__/expandSchema.test.js +95 -0
- package/dist/schema/expandSchema/__tests__/i18n.test.d.ts +1 -0
- package/dist/schema/expandSchema/__tests__/i18n.test.js +32 -0
- package/dist/schema/expandSchema/__tests__/maybeUseI18n.test.d.ts +1 -0
- package/dist/schema/expandSchema/__tests__/maybeUseI18n.test.js +98 -0
- package/dist/schema/expandSchema/__tests__/processSchema.test.d.ts +1 -0
- package/dist/schema/expandSchema/__tests__/processSchema.test.js +326 -0
- package/dist/schema/expandSchema/__tests__/sortSchemaProperties.test.d.ts +1 -0
- package/dist/schema/expandSchema/__tests__/sortSchemaProperties.test.js +182 -0
- package/dist/schema/expandSchema/__tests__/util.test.d.ts +1 -0
- package/dist/schema/expandSchema/__tests__/util.test.js +19 -0
- package/dist/schema/expandSchema/addLoadingTimes.d.ts +2 -0
- package/dist/schema/expandSchema/addLoadingTimes.js +12 -0
- package/dist/schema/expandSchema/constants.d.ts +2 -0
- package/dist/schema/expandSchema/constants.js +11 -0
- package/dist/schema/expandSchema/expandSchema.d.ts +7 -0
- package/dist/schema/expandSchema/expandSchema.js +19 -0
- package/dist/schema/expandSchema/i18n.d.ts +5 -0
- package/dist/schema/expandSchema/i18n.js +20 -0
- package/dist/schema/expandSchema/index.d.ts +3 -0
- package/dist/schema/expandSchema/index.js +21 -0
- package/dist/schema/expandSchema/maybeUseI18n.d.ts +2 -0
- package/dist/schema/expandSchema/maybeUseI18n.js +40 -0
- package/dist/schema/expandSchema/processSchema.d.ts +4 -0
- package/dist/schema/expandSchema/processSchema.js +94 -0
- package/dist/schema/expandSchema/removePrivateFields.d.ts +119 -0
- package/dist/schema/expandSchema/removePrivateFields.js +15 -0
- package/dist/schema/expandSchema/sortSchemaProperties.d.ts +21 -0
- package/dist/schema/expandSchema/sortSchemaProperties.js +40 -0
- package/dist/schema/expandSchema/unwrapSchema.d.ts +6 -0
- package/dist/schema/expandSchema/unwrapSchema.js +7 -0
- package/dist/schema/expandSchema/util.d.ts +6 -0
- package/dist/schema/expandSchema/util.js +15 -0
- package/dist/schema/index.d.ts +2 -1
- package/dist/schema/index.js +18 -17
- package/dist/schema/labels.d.ts +2 -2
- package/dist/schema/labels.js +20 -20
- package/dist/util/canonicalJsonify.d.ts +1 -1
- package/dist/util/canonicalJsonify.js +50 -50
- package/dist/util/handleResponse.d.ts +1 -1
- package/dist/util/handleResponse.js +21 -21
- package/dist/util/index.d.ts +2 -2
- package/dist/util/index.js +18 -18
- package/dist/verifications/cleanInstance.d.ts +9 -9
- package/dist/verifications/cleanInstance.js +15 -15
- package/dist/verifications/getPOVerification.d.ts +19 -16
- package/dist/verifications/getPOVerification.js +105 -94
- package/dist/verifications/getVerifiedBy.d.ts +1 -1
- package/dist/verifications/getVerifiedBy.js +19 -19
- package/dist/verifications/index.d.ts +5 -5
- package/dist/verifications/index.js +21 -21
- package/dist/verifications/maybeRereference.d.ts +1 -1
- package/dist/verifications/maybeRereference.js +10 -10
- package/dist/verifications/safeHarbour.d.ts +20 -20
- package/dist/verifications/safeHarbour.js +67 -74
- 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.d.ts +13 -13
- package/dist/verifications/verifyCheck/getOwnRealVerifications.js +66 -64
- package/dist/verifications/verifyCheck/getSomeoneElsesRealVerifications.d.ts +19 -19
- package/dist/verifications/verifyCheck/getSomeoneElsesRealVerifications.js +72 -72
- package/dist/verifications/verifyCheck/index.d.ts +3 -3
- package/dist/verifications/verifyCheck/index.js +21 -21
- 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 +15 -15
- package/dist/verifications/verifyCheck/operations/checkOwnVerification.js +39 -39
- package/dist/verifications/verifyCheck/operations/checkSomeoneElsesVerifications.d.ts +1 -1
- package/dist/verifications/verifyCheck/operations/checkSomeoneElsesVerifications.js +16 -16
- package/dist/verifications/verifyCheck/operations/index.d.ts +2 -2
- package/dist/verifications/verifyCheck/operations/index.js +18 -18
- package/package.json +13 -10
- package/dist/rules/helpers/getLhsTypeofValue.d.ts +0 -0
- package/dist/rules/helpers/getLhsTypeofValue.js +0 -1
- package/dist/rules/helpers/getValueFromPath.d.ts +0 -2
- package/dist/rules/helpers/getValueFromPath.js +0 -35
- package/dist/rules/helpers/rebuildInfiniteValues.d.ts +0 -3
- package/dist/rules/helpers/rebuildInfiniteValues.js +0 -6
- package/dist/rules/isScoreResultValid.d.ts +0 -2
- package/dist/rules/isScoreResultValid.js +0 -9
- package/dist/rules/operators/array.d.ts +0 -2
- package/dist/rules/operators/array.js +0 -74
- package/dist/rules/types/operators.d.ts +0 -19
- package/dist/rules/types/operators.js +0 -2
- package/dist/rules/types/score.d.ts +0 -50
- package/dist/rules/types/score.js +0 -2
- package/dist/util/conditional.d.ts +0 -7
- package/dist/util/conditional.js +0 -15
- package/dist/util/hash.js +0 -11
- package/dist/verifications/checkSingleVerification.d.ts +0 -9
- package/dist/verifications/checkSingleVerification.js +0 -29
- package/dist/verifications/checkVerifications.js +0 -16
- package/dist/verifications/checkVerificationsNew.js +0 -16
- package/dist/verifications/getOwnRealVerifications.d.ts +0 -14
- package/dist/verifications/getOwnRealVerifications.js +0 -64
- package/dist/verifications/getRealVerifications.d.ts +0 -22
- package/dist/verifications/getRealVerifications.js +0 -71
- package/dist/verifications/verifyCheck/util/canonicalJsonify.js +0 -48
- package/dist/verifications/verifyCheck/util/getValuesForAField.d.ts +0 -2
- package/dist/verifications/verifyCheck/util/getValuesForAField.js +0 -9
- package/dist/verifications/verifyCheck/util/index.d.ts +0 -2
- package/dist/verifications/verifyCheck/util/index.js +0 -14
|
@@ -0,0 +1,326 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const processSchema_1 = require("../processSchema");
|
|
4
|
+
describe("processSchema", () => {
|
|
5
|
+
it("should correctly merge properties with a reference", async () => {
|
|
6
|
+
const mock = {
|
|
7
|
+
schema: {
|
|
8
|
+
definitions: {
|
|
9
|
+
firstname: { $ref: "urn:schema:ss_first_name_01" },
|
|
10
|
+
},
|
|
11
|
+
properties: {
|
|
12
|
+
first_name: {
|
|
13
|
+
allOf: [
|
|
14
|
+
{ $ref: "#/definitions/firstname" },
|
|
15
|
+
{
|
|
16
|
+
priority: 10,
|
|
17
|
+
duplicateStringField: "from main schema",
|
|
18
|
+
tags: ["customTag"],
|
|
19
|
+
},
|
|
20
|
+
],
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
const allUnexpandedSchema = [
|
|
26
|
+
mock,
|
|
27
|
+
{
|
|
28
|
+
name: "ss_first_name_01",
|
|
29
|
+
schema: {
|
|
30
|
+
properties: {},
|
|
31
|
+
tags: ["a tag from the child"],
|
|
32
|
+
duplicateStringField: "from sub schema",
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
];
|
|
36
|
+
const expected = {
|
|
37
|
+
first_name: {
|
|
38
|
+
$prop: "first_name",
|
|
39
|
+
$ref: "ss_first_name_01",
|
|
40
|
+
priority: 10,
|
|
41
|
+
duplicateStringField: "from main schema",
|
|
42
|
+
tags: ["customTag", "a tag from the child"],
|
|
43
|
+
},
|
|
44
|
+
};
|
|
45
|
+
expect((0, processSchema_1.processSchema)(mock.schema, allUnexpandedSchema)).toStrictEqual({
|
|
46
|
+
properties: expected,
|
|
47
|
+
required: [],
|
|
48
|
+
tags: [],
|
|
49
|
+
verified_fields: undefined,
|
|
50
|
+
isProfileSchema: false,
|
|
51
|
+
isSpSchema: false,
|
|
52
|
+
definitions: mock.schema.definitions, // removed at a later stage
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
it("should not expand normal properties", async () => {
|
|
56
|
+
const getIdentityToken = jest.fn(async () => { });
|
|
57
|
+
const properties = {
|
|
58
|
+
first_name: {
|
|
59
|
+
priority: 10,
|
|
60
|
+
tags: ["customTag"],
|
|
61
|
+
},
|
|
62
|
+
};
|
|
63
|
+
const actual = (0, processSchema_1.processSchema)({ properties }, []);
|
|
64
|
+
expect(getIdentityToken).not.toHaveBeenCalled();
|
|
65
|
+
expect(actual).toStrictEqual({
|
|
66
|
+
properties: {
|
|
67
|
+
first_name: {
|
|
68
|
+
$prop: "first_name",
|
|
69
|
+
priority: 10,
|
|
70
|
+
tags: ["customTag"],
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
required: [],
|
|
74
|
+
tags: [],
|
|
75
|
+
verified_fields: undefined,
|
|
76
|
+
isProfileSchema: false,
|
|
77
|
+
isSpSchema: false,
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
it("should correctly expand refs from a schema-wide allOf filter", async () => {
|
|
81
|
+
const mock = {
|
|
82
|
+
schema: {
|
|
83
|
+
required: ["a", "b"],
|
|
84
|
+
definitions: {
|
|
85
|
+
firstname: { $ref: "urn:schema:ss_first_name_01" },
|
|
86
|
+
lastname: { $ref: "urn:schema:ss_last_name_01" },
|
|
87
|
+
},
|
|
88
|
+
allOf: [
|
|
89
|
+
{ $ref: "#/definitions/firstname" },
|
|
90
|
+
{ $ref: "#/definitions/lastname" },
|
|
91
|
+
],
|
|
92
|
+
// note how there are no properties on the schema. this is possible if there is an allOf
|
|
93
|
+
},
|
|
94
|
+
};
|
|
95
|
+
const allUnexpandedSchema = [
|
|
96
|
+
mock,
|
|
97
|
+
{
|
|
98
|
+
name: "ss_first_name_01",
|
|
99
|
+
schema: {
|
|
100
|
+
required: ["c", "d"],
|
|
101
|
+
properties: { first_name: { type: "string" } },
|
|
102
|
+
},
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
name: "ss_last_name_01",
|
|
106
|
+
schema: {
|
|
107
|
+
required: ["e", "f"],
|
|
108
|
+
properties: { last_name: { type: "string" } },
|
|
109
|
+
},
|
|
110
|
+
},
|
|
111
|
+
];
|
|
112
|
+
expect((0, processSchema_1.processSchema)(mock.schema, allUnexpandedSchema)).toStrictEqual({
|
|
113
|
+
required: ["a", "b", "c", "d", "e", "f"],
|
|
114
|
+
properties: {
|
|
115
|
+
first_name: { type: "string", $prop: "first_name" },
|
|
116
|
+
last_name: { type: "string", $prop: "last_name" },
|
|
117
|
+
},
|
|
118
|
+
tags: [],
|
|
119
|
+
verified_fields: undefined,
|
|
120
|
+
isProfileSchema: false,
|
|
121
|
+
isSpSchema: false,
|
|
122
|
+
allOf: mock.schema.allOf,
|
|
123
|
+
definitions: mock.schema.definitions, // removed later
|
|
124
|
+
});
|
|
125
|
+
});
|
|
126
|
+
it("handles fields that conditionally show", async () => {
|
|
127
|
+
const schema = {
|
|
128
|
+
properties: {},
|
|
129
|
+
allOf: [
|
|
130
|
+
{
|
|
131
|
+
if: { properties: { country: { enum: ["AU"] } } },
|
|
132
|
+
then: {
|
|
133
|
+
required: ["sublocality"],
|
|
134
|
+
properties: { sublocality: { lookup: "AUSTRALIA" } },
|
|
135
|
+
},
|
|
136
|
+
},
|
|
137
|
+
{
|
|
138
|
+
if: { properties: { country: { enum: ["NZ"] } } },
|
|
139
|
+
then: {
|
|
140
|
+
properties: { sublocality: { lookup: "NEW ZEALAND" } },
|
|
141
|
+
},
|
|
142
|
+
},
|
|
143
|
+
],
|
|
144
|
+
};
|
|
145
|
+
expect((0, processSchema_1.processSchema)(schema, [])).toStrictEqual({
|
|
146
|
+
properties: {
|
|
147
|
+
// by default it's not shown
|
|
148
|
+
// it converted the one field into two conditionally shown fields
|
|
149
|
+
"sublocality <=> country=AU": {
|
|
150
|
+
$prop: "sublocality",
|
|
151
|
+
if: { country: ["AU"] },
|
|
152
|
+
lookup: "AUSTRALIA",
|
|
153
|
+
},
|
|
154
|
+
"sublocality <=> country=NZ": {
|
|
155
|
+
$prop: "sublocality",
|
|
156
|
+
if: { country: ["NZ"] },
|
|
157
|
+
lookup: "NEW ZEALAND",
|
|
158
|
+
},
|
|
159
|
+
},
|
|
160
|
+
required: [
|
|
161
|
+
{
|
|
162
|
+
field: "sublocality",
|
|
163
|
+
if: {
|
|
164
|
+
country: ["AU"],
|
|
165
|
+
},
|
|
166
|
+
},
|
|
167
|
+
],
|
|
168
|
+
tags: [],
|
|
169
|
+
verified_fields: undefined,
|
|
170
|
+
isProfileSchema: false,
|
|
171
|
+
isSpSchema: false,
|
|
172
|
+
allOf: schema.allOf,
|
|
173
|
+
});
|
|
174
|
+
});
|
|
175
|
+
it("handles fields that conditionally change properties", async () => {
|
|
176
|
+
const schema = {
|
|
177
|
+
properties: { sublocality: { lookup: "NONE" } },
|
|
178
|
+
allOf: [
|
|
179
|
+
{
|
|
180
|
+
if: { properties: { country: { enum: ["AU", "US"] } } },
|
|
181
|
+
then: {
|
|
182
|
+
required: ["sublocality"],
|
|
183
|
+
properties: { sublocality: { lookup: "AUSTRALIA OR US" } },
|
|
184
|
+
},
|
|
185
|
+
},
|
|
186
|
+
{
|
|
187
|
+
if: {
|
|
188
|
+
properties: {
|
|
189
|
+
country: { enum: ["NZ"] },
|
|
190
|
+
island: { enum: ["SouthIsland"] },
|
|
191
|
+
},
|
|
192
|
+
},
|
|
193
|
+
then: {
|
|
194
|
+
properties: {
|
|
195
|
+
sublocality: { lookup: "NEW ZEALAND AND south island" },
|
|
196
|
+
},
|
|
197
|
+
},
|
|
198
|
+
},
|
|
199
|
+
],
|
|
200
|
+
};
|
|
201
|
+
expect((0, processSchema_1.processSchema)(schema, [])).toStrictEqual({
|
|
202
|
+
properties: {
|
|
203
|
+
// it kept the original field but added two conditionally shown fields
|
|
204
|
+
sublocality: {
|
|
205
|
+
$prop: "sublocality",
|
|
206
|
+
lookup: "NONE",
|
|
207
|
+
},
|
|
208
|
+
"sublocality <=> country=AU|US": {
|
|
209
|
+
$prop: "sublocality",
|
|
210
|
+
if: { country: ["AU", "US"] },
|
|
211
|
+
lookup: "AUSTRALIA OR US",
|
|
212
|
+
},
|
|
213
|
+
"sublocality <=> country=NZ & island=SouthIsland": {
|
|
214
|
+
$prop: "sublocality",
|
|
215
|
+
if: { country: ["NZ"], island: ["SouthIsland"] },
|
|
216
|
+
lookup: "NEW ZEALAND AND south island",
|
|
217
|
+
},
|
|
218
|
+
},
|
|
219
|
+
required: [
|
|
220
|
+
{
|
|
221
|
+
field: "sublocality",
|
|
222
|
+
if: { country: ["AU", "US"] },
|
|
223
|
+
},
|
|
224
|
+
],
|
|
225
|
+
tags: [],
|
|
226
|
+
verified_fields: undefined,
|
|
227
|
+
isProfileSchema: false,
|
|
228
|
+
isSpSchema: false,
|
|
229
|
+
allOf: schema.allOf,
|
|
230
|
+
});
|
|
231
|
+
});
|
|
232
|
+
it("handles fields that are conditionally verifiable", async () => {
|
|
233
|
+
const schema = {
|
|
234
|
+
properties: {},
|
|
235
|
+
allOf: [
|
|
236
|
+
{
|
|
237
|
+
if: { properties: { birth_year: { enum: [17, 18] } } },
|
|
238
|
+
then: {
|
|
239
|
+
verified_fields: ["first_name"],
|
|
240
|
+
},
|
|
241
|
+
},
|
|
242
|
+
],
|
|
243
|
+
};
|
|
244
|
+
expect((0, processSchema_1.processSchema)(schema, [])).toStrictEqual({
|
|
245
|
+
properties: {},
|
|
246
|
+
required: [],
|
|
247
|
+
tags: [],
|
|
248
|
+
verified_fields: [{ field: "first_name", if: { birth_year: [17, 18] } }],
|
|
249
|
+
isProfileSchema: false,
|
|
250
|
+
isSpSchema: false,
|
|
251
|
+
allOf: schema.allOf,
|
|
252
|
+
});
|
|
253
|
+
});
|
|
254
|
+
it("makes the whole schema verifiable if there are any conditionally verifiable fields", async () => {
|
|
255
|
+
const schema = {
|
|
256
|
+
properties: {},
|
|
257
|
+
tags: ["abc"],
|
|
258
|
+
allOf: [
|
|
259
|
+
{
|
|
260
|
+
if: { properties: { birth_year: { enum: [17, 18] } } },
|
|
261
|
+
then: {
|
|
262
|
+
tags: ["action:verify", "xyz"],
|
|
263
|
+
},
|
|
264
|
+
},
|
|
265
|
+
],
|
|
266
|
+
};
|
|
267
|
+
expect((0, processSchema_1.processSchema)(schema, [])).toStrictEqual({
|
|
268
|
+
properties: {},
|
|
269
|
+
required: [],
|
|
270
|
+
tags: ["abc", "action:verify"],
|
|
271
|
+
verified_fields: undefined,
|
|
272
|
+
isProfileSchema: false,
|
|
273
|
+
isSpSchema: false,
|
|
274
|
+
allOf: schema.allOf,
|
|
275
|
+
});
|
|
276
|
+
});
|
|
277
|
+
it("handles nested allOfs", async () => {
|
|
278
|
+
const schema = {
|
|
279
|
+
definitions: {
|
|
280
|
+
ref_to_MOE_ID: { $ref: "urn:schema:ss_MOE_ID" },
|
|
281
|
+
},
|
|
282
|
+
properties: {},
|
|
283
|
+
allOf: [
|
|
284
|
+
{
|
|
285
|
+
if: { properties: { country: { enum: ["NZ"] } } },
|
|
286
|
+
then: {
|
|
287
|
+
properties: {
|
|
288
|
+
MOE_ID: {
|
|
289
|
+
allOf: [
|
|
290
|
+
{ $ref: "#/definitions/ref_to_MOE_ID" },
|
|
291
|
+
{ title: "MinEdu ID" },
|
|
292
|
+
],
|
|
293
|
+
},
|
|
294
|
+
},
|
|
295
|
+
},
|
|
296
|
+
},
|
|
297
|
+
],
|
|
298
|
+
};
|
|
299
|
+
const moeSubSchema = {
|
|
300
|
+
name: "ss_MOE_ID",
|
|
301
|
+
schema: {
|
|
302
|
+
type: "number",
|
|
303
|
+
properties: {},
|
|
304
|
+
},
|
|
305
|
+
};
|
|
306
|
+
expect((0, processSchema_1.processSchema)(schema, [schema, moeSubSchema])).toStrictEqual({
|
|
307
|
+
allOf: schema.allOf,
|
|
308
|
+
definitions: schema.definitions,
|
|
309
|
+
isProfileSchema: false,
|
|
310
|
+
isSpSchema: false,
|
|
311
|
+
properties: {
|
|
312
|
+
"MOE_ID <=> country=NZ": {
|
|
313
|
+
$prop: "MOE_ID",
|
|
314
|
+
$ref: "ss_MOE_ID",
|
|
315
|
+
if: { country: ["NZ"] },
|
|
316
|
+
// it merged in props from 3 different places
|
|
317
|
+
title: "MinEdu ID",
|
|
318
|
+
type: "number",
|
|
319
|
+
},
|
|
320
|
+
},
|
|
321
|
+
required: [],
|
|
322
|
+
tags: [],
|
|
323
|
+
verified_fields: undefined,
|
|
324
|
+
});
|
|
325
|
+
});
|
|
326
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const sortSchemaProperties_1 = require("../sortSchemaProperties");
|
|
4
|
+
describe("sortSchemaProperties tests", () => {
|
|
5
|
+
it("correctly sorts the fields by priority and groups", () => {
|
|
6
|
+
const actual = (0, sortSchemaProperties_1.sortSchemaProperties)({
|
|
7
|
+
first_name: {
|
|
8
|
+
tags: ["group:name"],
|
|
9
|
+
priority: 10,
|
|
10
|
+
n_id: "first_name",
|
|
11
|
+
$prop: "first_name",
|
|
12
|
+
},
|
|
13
|
+
last_name: {
|
|
14
|
+
tags: ["group:name"],
|
|
15
|
+
priority: 20,
|
|
16
|
+
n_id: "last_name",
|
|
17
|
+
$prop: "last_name",
|
|
18
|
+
},
|
|
19
|
+
gender: {
|
|
20
|
+
tags: ["globally_unique_field", "group:gender"],
|
|
21
|
+
priority: 5,
|
|
22
|
+
n_id: "gender",
|
|
23
|
+
$prop: "gender",
|
|
24
|
+
},
|
|
25
|
+
oof: { priority: 30, n_id: "abc123", $prop: "oof" },
|
|
26
|
+
another_field_without_tags_and_no_nid: {
|
|
27
|
+
priority: 50,
|
|
28
|
+
$prop: "another_field_without_tags_and_no_nid",
|
|
29
|
+
},
|
|
30
|
+
another_field_without_tags: {
|
|
31
|
+
priority: 40,
|
|
32
|
+
n_id: "xyz789",
|
|
33
|
+
$prop: "another_field_without_tags",
|
|
34
|
+
},
|
|
35
|
+
middle_name: {
|
|
36
|
+
tags: ["group:name"],
|
|
37
|
+
priority: 15,
|
|
38
|
+
n_id: "middle_name",
|
|
39
|
+
$prop: "middle_name",
|
|
40
|
+
},
|
|
41
|
+
});
|
|
42
|
+
const expected = [
|
|
43
|
+
{
|
|
44
|
+
title: "gender",
|
|
45
|
+
items: [
|
|
46
|
+
{
|
|
47
|
+
$prop: "gender",
|
|
48
|
+
priority: 5,
|
|
49
|
+
tags: ["globally_unique_field", "group:gender"],
|
|
50
|
+
n_id: "gender",
|
|
51
|
+
},
|
|
52
|
+
],
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
title: "name",
|
|
56
|
+
items: [
|
|
57
|
+
{
|
|
58
|
+
priority: 10,
|
|
59
|
+
tags: ["group:name"],
|
|
60
|
+
n_id: "first_name",
|
|
61
|
+
$prop: "first_name",
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
priority: 15,
|
|
65
|
+
tags: ["group:name"],
|
|
66
|
+
n_id: "middle_name",
|
|
67
|
+
$prop: "middle_name",
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
priority: 20,
|
|
71
|
+
tags: ["group:name"],
|
|
72
|
+
n_id: "last_name",
|
|
73
|
+
$prop: "last_name",
|
|
74
|
+
},
|
|
75
|
+
],
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
title: "-notag-common",
|
|
79
|
+
items: [
|
|
80
|
+
{ priority: 30, n_id: "abc123", $prop: "oof" },
|
|
81
|
+
{ priority: 40, n_id: "xyz789", $prop: "another_field_without_tags" },
|
|
82
|
+
{ priority: 50, $prop: "another_field_without_tags_and_no_nid" },
|
|
83
|
+
],
|
|
84
|
+
},
|
|
85
|
+
];
|
|
86
|
+
expect(actual).toStrictEqual(expected);
|
|
87
|
+
});
|
|
88
|
+
it("Deals with nested data", () => {
|
|
89
|
+
const result = (0, sortSchemaProperties_1.sortSchemaProperties)({
|
|
90
|
+
id: {
|
|
91
|
+
priority: 100,
|
|
92
|
+
tags: ["group:provider_product"],
|
|
93
|
+
type: "string",
|
|
94
|
+
description: "The unique id of the product",
|
|
95
|
+
title: "Product ID",
|
|
96
|
+
$prop: "id",
|
|
97
|
+
},
|
|
98
|
+
metadata: {
|
|
99
|
+
$prop: "metadata",
|
|
100
|
+
properties: {},
|
|
101
|
+
items: {
|
|
102
|
+
id: {
|
|
103
|
+
priority: 100,
|
|
104
|
+
tags: ["group:provider_product"],
|
|
105
|
+
type: "string",
|
|
106
|
+
description: "The unique id of the product",
|
|
107
|
+
title: "Product ID",
|
|
108
|
+
},
|
|
109
|
+
},
|
|
110
|
+
type: "object",
|
|
111
|
+
title: "Product details",
|
|
112
|
+
priority: 300,
|
|
113
|
+
tags: ["group:provider_product"],
|
|
114
|
+
description: "Additional information about the product",
|
|
115
|
+
},
|
|
116
|
+
});
|
|
117
|
+
expect(result).toStrictEqual([
|
|
118
|
+
{
|
|
119
|
+
items: [
|
|
120
|
+
{
|
|
121
|
+
$prop: "id",
|
|
122
|
+
description: "The unique id of the product",
|
|
123
|
+
priority: 100,
|
|
124
|
+
tags: ["group:provider_product"],
|
|
125
|
+
title: "Product ID",
|
|
126
|
+
type: "string",
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
$prop: "metadata",
|
|
130
|
+
description: "Additional information about the product",
|
|
131
|
+
items: {
|
|
132
|
+
id: {
|
|
133
|
+
description: "The unique id of the product",
|
|
134
|
+
priority: 100,
|
|
135
|
+
tags: ["group:provider_product"],
|
|
136
|
+
title: "Product ID",
|
|
137
|
+
type: "string",
|
|
138
|
+
},
|
|
139
|
+
},
|
|
140
|
+
priority: 300,
|
|
141
|
+
properties: {},
|
|
142
|
+
tags: ["group:provider_product"],
|
|
143
|
+
title: "Product details",
|
|
144
|
+
type: "object",
|
|
145
|
+
},
|
|
146
|
+
],
|
|
147
|
+
title: "provider_product",
|
|
148
|
+
},
|
|
149
|
+
]);
|
|
150
|
+
});
|
|
151
|
+
it("makes use of sub groups within the same group", () => {
|
|
152
|
+
const actual = (0, sortSchemaProperties_1.sortSchemaProperties)({
|
|
153
|
+
date_of_birth: { $prop: "date_of_birth", tags: ["group:date:birth"] },
|
|
154
|
+
month_of_birth: { $prop: "month_of_birth", tags: ["group:date:birth"] },
|
|
155
|
+
year_of_birth: { $prop: "year_of_birth", tags: ["group:date:birth"] },
|
|
156
|
+
date_of_expiry: { $prop: "date_of_expiry", tags: ["group:date:expiry"] },
|
|
157
|
+
month_of_expiry: {
|
|
158
|
+
$prop: "month_of_expiry",
|
|
159
|
+
tags: ["group:date:expiry"],
|
|
160
|
+
},
|
|
161
|
+
year_of_expiry: { $prop: "year_of_expiry", tags: ["group:date:expiry"] },
|
|
162
|
+
});
|
|
163
|
+
expect(actual).toStrictEqual([
|
|
164
|
+
{
|
|
165
|
+
title: "date:birth",
|
|
166
|
+
items: [
|
|
167
|
+
{ $prop: "date_of_birth", tags: ["group:date:birth"] },
|
|
168
|
+
{ $prop: "month_of_birth", tags: ["group:date:birth"] },
|
|
169
|
+
{ $prop: "year_of_birth", tags: ["group:date:birth"] },
|
|
170
|
+
],
|
|
171
|
+
},
|
|
172
|
+
{
|
|
173
|
+
title: "date:expiry",
|
|
174
|
+
items: [
|
|
175
|
+
{ $prop: "date_of_expiry", tags: ["group:date:expiry"] },
|
|
176
|
+
{ $prop: "month_of_expiry", tags: ["group:date:expiry"] },
|
|
177
|
+
{ $prop: "year_of_expiry", tags: ["group:date:expiry"] },
|
|
178
|
+
],
|
|
179
|
+
},
|
|
180
|
+
]);
|
|
181
|
+
});
|
|
182
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const util_1 = require("../util");
|
|
4
|
+
describe("getConditionId", () => {
|
|
5
|
+
it.each `
|
|
6
|
+
iff | id
|
|
7
|
+
${{ country: ["NZ"] }} | ${"country=NZ"}
|
|
8
|
+
${{ country: ["NZ", "AU"] }} | ${"country=AU|NZ"}
|
|
9
|
+
${{ country: ["AU", "NZ"] }} | ${"country=AU|NZ"}
|
|
10
|
+
${{ country: ["NZ"], age: [17] }} | ${"age=17 & country=NZ"}
|
|
11
|
+
${{ country: ["NZ"], age: [17, 18] }} | ${"age=17|18 & country=NZ"}
|
|
12
|
+
${{ country: ["NZ", "AU"], age: [17, 18] }} | ${"age=17|18 & country=AU|NZ"}
|
|
13
|
+
${{}} | ${""}
|
|
14
|
+
${{ country: [] }} | ${"country="}
|
|
15
|
+
${{ country: [], age: [] }} | ${"age= & country="}
|
|
16
|
+
`("generates IDs ($id)", ({ iff, id }) => {
|
|
17
|
+
expect((0, util_1.getConditionId)(iff)).toBe(id);
|
|
18
|
+
});
|
|
19
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.addLoadingTimes = void 0;
|
|
4
|
+
const addLoadingTimes = (schema) => {
|
|
5
|
+
var _a;
|
|
6
|
+
const timeTags = (_a = schema.tags) === null || _a === void 0 ? void 0 : _a.filter(x => x.startsWith("time:")).map(tag => {
|
|
7
|
+
const [, name, time] = tag.split(":");
|
|
8
|
+
return [name, +time];
|
|
9
|
+
});
|
|
10
|
+
return Object.assign(Object.assign({}, schema), { timing: Object.fromEntries(timeTags || []) });
|
|
11
|
+
};
|
|
12
|
+
exports.addLoadingTimes = addLoadingTimes;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TAG_DENYLIST = void 0;
|
|
4
|
+
// if a schema has any of these tags, it will not be shown on the user profile
|
|
5
|
+
exports.TAG_DENYLIST = [
|
|
6
|
+
"type:client_only",
|
|
7
|
+
"type:globally_unique_field",
|
|
8
|
+
"type:marketplace",
|
|
9
|
+
"type:service_offer",
|
|
10
|
+
"type:service_provider",
|
|
11
|
+
];
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Schema, WrappedSchema } from "@raytio/types";
|
|
2
|
+
/**
|
|
3
|
+
* ❣️ This is the main function to transform a schema from
|
|
4
|
+
* the JSON that the API returns, into a `Schema` object that's useful
|
|
5
|
+
* to the client.
|
|
6
|
+
*/
|
|
7
|
+
export declare function expandSchema(wrappedSchema: WrappedSchema, allUnexpandedSchemas: WrappedSchema[], userLocales: readonly string[]): Schema;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.expandSchema = void 0;
|
|
4
|
+
const addLoadingTimes_1 = require("./addLoadingTimes");
|
|
5
|
+
const maybeUseI18n_1 = require("./maybeUseI18n");
|
|
6
|
+
const processSchema_1 = require("./processSchema");
|
|
7
|
+
const removePrivateFields_1 = require("./removePrivateFields");
|
|
8
|
+
const unwrapSchema_1 = require("./unwrapSchema");
|
|
9
|
+
/**
|
|
10
|
+
* ❣️ This is the main function to transform a schema from
|
|
11
|
+
* the JSON that the API returns, into a `Schema` object that's useful
|
|
12
|
+
* to the client.
|
|
13
|
+
*/
|
|
14
|
+
function expandSchema(wrappedSchema, allUnexpandedSchemas, userLocales) {
|
|
15
|
+
// TODO: use Ramda's pipe
|
|
16
|
+
const schema = (0, removePrivateFields_1.removePrivateFields)((0, maybeUseI18n_1.maybeUseI18n)((0, addLoadingTimes_1.addLoadingTimes)((0, processSchema_1.processSchema)((0, unwrapSchema_1.unwrapSchema)(wrappedSchema), allUnexpandedSchemas)), userLocales));
|
|
17
|
+
return Object.assign({ wasExpandedByClient: true }, schema);
|
|
18
|
+
}
|
|
19
|
+
exports.expandSchema = expandSchema;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.findSuitableLocale = exports.getAllLocales = void 0;
|
|
4
|
+
const ramda_1 = require("ramda");
|
|
5
|
+
/** @deprecated @internal exported only for unit tests, use `findSuitableLocale` instead */
|
|
6
|
+
const getAllLocales = (langs) => (0, ramda_1.uniq)(langs.flatMap(locale => [
|
|
7
|
+
locale.toLowerCase(),
|
|
8
|
+
locale.toLowerCase().split("-")[0],
|
|
9
|
+
]));
|
|
10
|
+
exports.getAllLocales = getAllLocales;
|
|
11
|
+
/**
|
|
12
|
+
* Selects the most suitable locale to use from a list of options.
|
|
13
|
+
* Returns undefined if there is no language that the user speaks
|
|
14
|
+
*/
|
|
15
|
+
const findSuitableLocale = (options, langs) => {
|
|
16
|
+
const userLocales = (0, exports.getAllLocales)(langs);
|
|
17
|
+
return (userLocales.find(locale => options.includes(locale)) ||
|
|
18
|
+
options.find(locale => userLocales.includes(locale.split("-")[0])));
|
|
19
|
+
};
|
|
20
|
+
exports.findSuitableLocale = findSuitableLocale;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = 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);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.findSuitableLocale = void 0;
|
|
18
|
+
__exportStar(require("./expandSchema"), exports);
|
|
19
|
+
__exportStar(require("./sortSchemaProperties"), exports);
|
|
20
|
+
var i18n_1 = require("./i18n");
|
|
21
|
+
Object.defineProperty(exports, "findSuitableLocale", { enumerable: true, get: function () { return i18n_1.findSuitableLocale; } });
|