@raytio/core 11.1.0 → 11.3.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 +17 -2
- package/README.md +123 -33
- package/dist/accessApplication/api/__tests__/fetchKeysForSubmission.test.d.ts +1 -0
- package/dist/accessApplication/api/__tests__/fetchKeysForSubmission.test.js +28 -0
- package/dist/accessApplication/api/__tests__/fetchPOsOrAOsForSubmission.test.d.ts +1 -0
- package/dist/accessApplication/api/__tests__/fetchPOsOrAOsForSubmission.test.js +23 -0
- package/dist/accessApplication/api/__tests__/fetchRelationshipsForSubmission.test.d.ts +1 -0
- package/dist/accessApplication/api/__tests__/fetchRelationshipsForSubmission.test.js +27 -0
- package/dist/accessApplication/api/__tests__/getMissingDataForInstance.test.d.ts +1 -0
- package/dist/accessApplication/api/__tests__/getMissingDataForInstance.test.js +30 -0
- package/dist/accessApplication/api/fetchKeysForSubmission.d.ts +12 -0
- package/dist/accessApplication/api/fetchKeysForSubmission.js +16 -0
- package/dist/accessApplication/api/fetchPOsOrAOsForSubmission.d.ts +6 -0
- package/dist/accessApplication/api/fetchPOsOrAOsForSubmission.js +25 -0
- package/dist/accessApplication/api/fetchRelationshipsForSubmission.d.ts +6 -0
- package/dist/accessApplication/api/fetchRelationshipsForSubmission.js +10 -0
- package/dist/accessApplication/api/getMissingDataForInstance.d.ts +10 -0
- package/dist/accessApplication/api/getMissingDataForInstance.js +28 -0
- package/dist/accessApplication/api/index.d.ts +2 -0
- package/dist/accessApplication/api/index.js +18 -0
- package/dist/accessApplication/api/legacy/__tests__/convertRelationships.test.d.ts +1 -0
- package/dist/accessApplication/api/legacy/__tests__/convertRelationships.test.js +37 -0
- package/dist/accessApplication/api/legacy/convertRelationships.d.ts +16 -0
- package/dist/accessApplication/api/legacy/convertRelationships.js +21 -0
- package/dist/accessApplication/api/legacy/index.d.ts +1 -0
- package/dist/accessApplication/api/legacy/index.js +17 -0
- package/dist/accessApplication/createAA.js +6 -5
- package/dist/accessApplication/index.d.ts +1 -0
- package/dist/accessApplication/index.js +1 -0
- package/dist/crypto/cognitoAttributes.d.ts +1 -1
- package/dist/crypto/decryptSharedData.d.ts +2 -2
- package/dist/crypto/decryptSharedData.js +2 -5
- package/dist/crypto/getAADecryptor.d.ts +18 -3
- package/dist/crypto/getAADecryptor.js +34 -6
- package/dist/crypto/helpers.d.ts +2 -2
- package/dist/general/types.d.ts +9 -0
- package/dist/general/types.js +10 -1
- package/dist/rules/calculateScore.d.ts +1 -1
- package/dist/rules/convertInstanceToRuleInput.d.ts +3 -3
- package/dist/rules/convertInstanceToRuleInput.js +5 -2
- package/dist/rules/evaluateScoreCondition.d.ts +1 -1
- package/dist/rules/helpers/__tests__/getValuesFromPath.test.js +1 -1
- package/dist/rules/helpers/addInfiniteThresholdBoundaries.d.ts +1 -1
- package/dist/rules/helpers/checkTypeofValue.d.ts +1 -1
- package/dist/rules/helpers/getValuesFromPath.d.ts +1 -1
- package/dist/rules/helpers/thresholds.d.ts +1 -1
- package/dist/rules/operators/bool.d.ts +1 -1
- package/dist/rules/operators/date.d.ts +1 -1
- package/dist/rules/operators/hfield.d.ts +1 -1
- package/dist/rules/operators/hschema.d.ts +1 -1
- package/dist/rules/operators/index.d.ts +1 -1
- package/dist/rules/operators/number.d.ts +1 -1
- package/dist/rules/operators/string.d.ts +1 -1
- package/dist/rules/types/config.d.ts +4 -3
- package/dist/rules/types/dataValueTypes.d.ts +2 -3
- package/dist/rules/types/internal.d.ts +4 -3
- package/dist/rules/validate.d.ts +2 -2
- package/dist/schema/expandSchema/__tests__/expandSchema.test.js +8 -7
- package/dist/schema/expandSchema/__tests__/i18n.test.js +1 -1
- package/dist/schema/expandSchema/__tests__/maybeUseI18n.test.js +2 -2
- package/dist/schema/expandSchema/__tests__/processSchema.test.js +6 -6
- package/dist/schema/expandSchema/addLoadingTimes.d.ts +1 -1
- package/dist/schema/expandSchema/constants.d.ts +1 -1
- package/dist/schema/expandSchema/expandSchema.d.ts +1 -1
- package/dist/schema/expandSchema/maybeUseI18n.d.ts +1 -1
- package/dist/schema/expandSchema/processSchema.d.ts +3 -4
- package/dist/schema/expandSchema/processSchema.js +2 -2
- package/dist/schema/expandSchema/removePrivateFields.d.ts +8 -6
- package/dist/schema/expandSchema/sortSchemaProperties.d.ts +3 -3
- package/dist/schema/expandSchema/unwrapSchema.d.ts +2 -6
- package/dist/schema/expandSchema/unwrapSchema.js +1 -1
- package/dist/schema/labels.d.ts +2 -1
- package/dist/testHelpers.d.ts +9 -0
- package/dist/testHelpers.js +9 -0
- package/dist/verifications/cleanInstance.d.ts +1 -1
- package/dist/verifications/getPOVerification.d.ts +1 -1
- package/dist/verifications/getPOVerification.js +6 -2
- package/dist/verifications/getVerifiedBy.js +6 -1
- package/dist/verifications/index.d.ts +0 -1
- package/dist/verifications/index.js +0 -1
- package/dist/verifications/safeHarbour.d.ts +2 -2
- package/dist/verifications/verifyCheck/__tests__/getOwnRealVerifications.test.js +74 -9
- package/dist/verifications/verifyCheck/__tests__/getSomeoneElsesRealVerifications.test.js +2 -2
- package/dist/verifications/verifyCheck/getOwnRealVerifications.d.ts +1 -1
- package/dist/verifications/verifyCheck/getOwnRealVerifications.js +3 -1
- package/dist/verifications/verifyCheck/getSomeoneElsesRealVerifications.d.ts +1 -1
- package/dist/verifications/verifyCheck/getSomeoneElsesRealVerifications.js +1 -1
- package/dist/verifications/verifyCheck/operations/__tests__/checkOwnVerification.test.js +45 -5
- package/dist/verifications/verifyCheck/operations/__tests__/checkSomeoneElsesVerifications.test.js +2 -2
- package/dist/verifications/verifyCheck/operations/__tests__/sampleBundle.json +1 -0
- package/dist/verifications/verifyCheck/operations/checkOwnVerification.d.ts +4 -3
- package/dist/verifications/verifyCheck/operations/checkOwnVerification.js +17 -8
- package/package.json +6 -42
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.convertServerRelationship = void 0;
|
|
4
|
+
const ramda_1 = require("ramda");
|
|
5
|
+
/**
|
|
6
|
+
* Converts relationship type used by the server into the (Urn format) type used by the client
|
|
7
|
+
* @param serverRelationship relationship type used in the server
|
|
8
|
+
* @returns a Relationship (client-side type) that is equivalent to the inputted serverRelationship value
|
|
9
|
+
*/
|
|
10
|
+
function convertServerRelationship(serverRelationship) {
|
|
11
|
+
const { id, from_id } = serverRelationship;
|
|
12
|
+
/**
|
|
13
|
+
* This functionality is similar to LinkToCrust, but in this case the API has already worked out
|
|
14
|
+
* which instance the PO links to (if any) so we simply convert it into a {@link Urn}
|
|
15
|
+
*/
|
|
16
|
+
const end = "to_id" in serverRelationship
|
|
17
|
+
? `urn:profile_object:${serverRelationship.to_id}`
|
|
18
|
+
: `urn:instance:${serverRelationship.to_i_id}`;
|
|
19
|
+
return Object.assign({ p_id: id, start: `urn:profile_object:${from_id}`, end }, (0, ramda_1.omit)(["id", "from_id", "to_id", "to_i_id"], serverRelationship));
|
|
20
|
+
}
|
|
21
|
+
exports.convertServerRelationship = convertServerRelationship;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./convertRelationships";
|
|
@@ -0,0 +1,17 @@
|
|
|
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
|
+
__exportStar(require("./convertRelationships"), exports);
|
|
@@ -15,12 +15,13 @@ const createApplicationPublicKey = async ({ apiUrl, apiToken, aId, publicKey, })
|
|
|
15
15
|
body: JSON.stringify({ a_id: aId, key: publicKey }),
|
|
16
16
|
headers: { Authorization: `Bearer ${apiToken}` },
|
|
17
17
|
}).then(util_1.handleResponse);
|
|
18
|
-
|
|
18
|
+
// temporary typecast until this API is updated
|
|
19
|
+
return { publicKeyId: PO.n_id };
|
|
19
20
|
};
|
|
20
21
|
/** @internal */
|
|
21
|
-
const createApplicationEncryptedPrivateKey = ({ apiUrl, apiToken,
|
|
22
|
+
const createApplicationEncryptedPrivateKey = ({ apiUrl, apiToken, publicKeyId, encryptedPrivateKey, }) => fetch(`${apiUrl}/share/v2/access_application/public_key/${publicKeyId}/private_key`, {
|
|
22
23
|
method: "POST",
|
|
23
|
-
body: JSON.stringify({ n_id:
|
|
24
|
+
body: JSON.stringify({ n_id: publicKeyId, key: encryptedPrivateKey }),
|
|
24
25
|
headers: { Authorization: `Bearer ${apiToken}` },
|
|
25
26
|
}).then(util_1.handleResponse);
|
|
26
27
|
/** @internal */
|
|
@@ -54,7 +55,7 @@ async function createAA({ apiUrl, apiToken, userDoc, maxcryptor, application, })
|
|
|
54
55
|
application,
|
|
55
56
|
});
|
|
56
57
|
const { publicKey, encryptedPrivateKey } = await createApplicationEncryptor(userDoc, maxcryptor);
|
|
57
|
-
const {
|
|
58
|
+
const { publicKeyId } = await createApplicationPublicKey({
|
|
58
59
|
apiUrl,
|
|
59
60
|
apiToken,
|
|
60
61
|
aId: newApp.a_id,
|
|
@@ -63,7 +64,7 @@ async function createAA({ apiUrl, apiToken, userDoc, maxcryptor, application, })
|
|
|
63
64
|
await createApplicationEncryptedPrivateKey({
|
|
64
65
|
apiUrl,
|
|
65
66
|
apiToken,
|
|
66
|
-
|
|
67
|
+
publicKeyId,
|
|
67
68
|
encryptedPrivateKey,
|
|
68
69
|
});
|
|
69
70
|
return newApp;
|
|
@@ -14,4 +14,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./api"), exports);
|
|
17
18
|
__exportStar(require("./createAA"), exports);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Encrypted, Instance } from "@raytio/types";
|
|
1
|
+
import type { ApplicationEncryptor, Maxcryptor } from "@raytio/maxcryptor";
|
|
2
|
+
import type { Encrypted, Instance } from "@raytio/types";
|
|
3
3
|
/**
|
|
4
4
|
* Decrypts any encrypted properties included in the supplied `instanceData`.
|
|
5
5
|
* If nothing is encrypted the supplied `instanceData` is returned.
|
|
@@ -15,16 +15,13 @@ const decryptKeys_1 = require("./decryptKeys");
|
|
|
15
15
|
*/
|
|
16
16
|
const decryptSharedData = async ({ instanceData, maxcryptor, apiUrl, apiToken, onCorruptedData, }) => {
|
|
17
17
|
const { decryptor: applicationDecryptor } = await (0, getAADecryptor_1.getAADecryptor)({
|
|
18
|
-
aId: instanceData.
|
|
18
|
+
aId: instanceData.aa_id,
|
|
19
19
|
maxcryptor,
|
|
20
20
|
apiUrl,
|
|
21
21
|
apiToken,
|
|
22
22
|
});
|
|
23
23
|
const instance = Object.assign(Object.assign({}, instanceData), { profile_objects: await Promise.all(instanceData.profile_objects.map(async (PO) => {
|
|
24
|
-
const
|
|
25
|
-
? PO.n_id.split("::")[1]
|
|
26
|
-
: PO.n_id;
|
|
27
|
-
const keys = instanceData.keys[realNId];
|
|
24
|
+
const keys = instanceData.keys[PO.id];
|
|
28
25
|
const decryptedProperties = await (0, decryptKeys_1.decryptKeys)({
|
|
29
26
|
applicationDecryptor,
|
|
30
27
|
keys,
|
|
@@ -1,5 +1,19 @@
|
|
|
1
|
-
import { ApplicationEncryptor, Maxcryptor } from "@raytio/maxcryptor";
|
|
2
|
-
import {
|
|
1
|
+
import type { ApplicationEncryptor, Maxcryptor } from "@raytio/maxcryptor";
|
|
2
|
+
import type { AId, CommonFields as CommonNodeFields, KId } from "@raytio/types";
|
|
3
|
+
type PublicKeyNode = CommonNodeFields<KId> & {
|
|
4
|
+
public_key_name: string;
|
|
5
|
+
public_key_description: string;
|
|
6
|
+
public_key: JsonWebKey;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* Fetches the Public Key Information for an Access Application
|
|
10
|
+
* @returns the id and Key information of the Applications Public Key
|
|
11
|
+
*/
|
|
12
|
+
export declare function getAAPublicKey({ apiUrl, apiToken, aId, }: {
|
|
13
|
+
apiUrl: string;
|
|
14
|
+
apiToken: string;
|
|
15
|
+
aId: AId;
|
|
16
|
+
}): Promise<PublicKeyNode>;
|
|
3
17
|
/**
|
|
4
18
|
* Fetchs the public and private keys for an Access Application, then initializes
|
|
5
19
|
* the {@link https://npm.im/@raytio/maxcryptor|Maxcryptor}'s `ApplicationEncryptor`.
|
|
@@ -12,5 +26,6 @@ export declare function getAADecryptor({ aId, apiUrl, maxcryptor, apiToken, }: {
|
|
|
12
26
|
apiToken: string;
|
|
13
27
|
}): Promise<{
|
|
14
28
|
decryptor: ApplicationEncryptor;
|
|
15
|
-
|
|
29
|
+
publicKeyId: KId;
|
|
16
30
|
}>;
|
|
31
|
+
export {};
|
|
@@ -1,20 +1,48 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getAADecryptor = void 0;
|
|
3
|
+
exports.getAADecryptor = exports.getAAPublicKey = void 0;
|
|
4
4
|
const util_1 = require("../util");
|
|
5
|
+
/**
|
|
6
|
+
* Fetches the Public Key Information for an Access Application
|
|
7
|
+
* @returns the id and Key information of the Applications Public Key
|
|
8
|
+
*/
|
|
9
|
+
async function getAAPublicKey({ apiUrl, apiToken, aId, }) {
|
|
10
|
+
const [publicKey] = await fetch(`${apiUrl}/db/v1/dsm_access_application_public_keys?aa_id=eq.${aId}`, {
|
|
11
|
+
headers: { Authorization: `Bearer ${apiToken}` },
|
|
12
|
+
}).then(util_1.handleResponse);
|
|
13
|
+
if (!publicKey) {
|
|
14
|
+
throw new Error("Could not Find Encryption Key");
|
|
15
|
+
}
|
|
16
|
+
return publicKey;
|
|
17
|
+
}
|
|
18
|
+
exports.getAAPublicKey = getAAPublicKey;
|
|
19
|
+
/**
|
|
20
|
+
* Fetches the Private Key Information from a Public Key
|
|
21
|
+
* @returns An encrypted Private Key
|
|
22
|
+
*/
|
|
23
|
+
async function fetchPrivateKey({ apiUrl, apiToken, publicKeyId, }) {
|
|
24
|
+
const [privateKey] = await fetch(`${apiUrl}/db/v1/dsm_access_application_private_keys?aack_id=eq.${publicKeyId}`, { headers: { Authorization: `Bearer ${apiToken}` } }).then(util_1.handleResponse);
|
|
25
|
+
return privateKey.encrypted_private_key;
|
|
26
|
+
}
|
|
5
27
|
/**
|
|
6
28
|
* Fetchs the public and private keys for an Access Application, then initializes
|
|
7
29
|
* the {@link https://npm.im/@raytio/maxcryptor|Maxcryptor}'s `ApplicationEncryptor`.
|
|
8
30
|
* @returns an `ApplicationEncryptor` and the public key of the Access Application
|
|
9
31
|
*/
|
|
10
32
|
async function getAADecryptor({ aId, apiUrl, maxcryptor, apiToken, }) {
|
|
11
|
-
const {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
33
|
+
const { id: publicKeyId, public_key: publicKey } = await getAAPublicKey({
|
|
34
|
+
apiUrl,
|
|
35
|
+
apiToken,
|
|
36
|
+
aId,
|
|
37
|
+
});
|
|
38
|
+
const privateKey = await fetchPrivateKey({
|
|
39
|
+
apiUrl,
|
|
40
|
+
apiToken,
|
|
41
|
+
publicKeyId,
|
|
42
|
+
});
|
|
15
43
|
return {
|
|
16
44
|
decryptor: await maxcryptor.loadApplicationEncryptorForDecryption(publicKey, privateKey),
|
|
17
|
-
|
|
45
|
+
publicKeyId,
|
|
18
46
|
};
|
|
19
47
|
}
|
|
20
48
|
exports.getAADecryptor = getAADecryptor;
|
package/dist/crypto/helpers.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Encrypted } from "@raytio/types";
|
|
1
|
+
import type { Encrypted } from "@raytio/types";
|
|
2
2
|
/**
|
|
3
3
|
* Determines where the input is an encrypted Raytio object
|
|
4
4
|
* @param value anything
|
|
@@ -15,4 +15,4 @@ export declare const isEncryptedFile: (value: unknown) => value is Encrypted;
|
|
|
15
15
|
* Given a profile object's properties, returns the number
|
|
16
16
|
* of properties that are encryted.
|
|
17
17
|
*/
|
|
18
|
-
export declare const someEncrypted: <T extends object
|
|
18
|
+
export declare const someEncrypted: <T extends object>(obj: T) => number;
|
package/dist/general/types.d.ts
CHANGED
|
@@ -1,6 +1,15 @@
|
|
|
1
|
+
import type { AId, NId } from "@raytio/types";
|
|
1
2
|
/**
|
|
2
3
|
* to prevent a key from the JS object prototype (e.g. `__proto__`) from
|
|
3
4
|
* returning an unexpected value (see #1162)
|
|
4
5
|
* @ignore
|
|
5
6
|
*/
|
|
6
7
|
export declare function assertSafeProperty(key: string): asserts key is string;
|
|
8
|
+
/**
|
|
9
|
+
* the API returns hashed {@link NId}s in a separate field,
|
|
10
|
+
* which breaks the whole app. So, we move the hashed ID into
|
|
11
|
+
* the normal `n_id` field, and use a different format.
|
|
12
|
+
*
|
|
13
|
+
* This was first introduced in #1048
|
|
14
|
+
*/
|
|
15
|
+
export declare const createHashedNId: (nId: NId, aId: AId) => NId;
|
package/dist/general/types.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.assertSafeProperty = void 0;
|
|
3
|
+
exports.createHashedNId = exports.assertSafeProperty = void 0;
|
|
4
4
|
/**
|
|
5
5
|
* to prevent a key from the JS object prototype (e.g. `__proto__`) from
|
|
6
6
|
* returning an unexpected value (see #1162)
|
|
@@ -11,3 +11,12 @@ function assertSafeProperty(key) {
|
|
|
11
11
|
throw new Error("Unacceptable object property");
|
|
12
12
|
}
|
|
13
13
|
exports.assertSafeProperty = assertSafeProperty;
|
|
14
|
+
/**
|
|
15
|
+
* the API returns hashed {@link NId}s in a separate field,
|
|
16
|
+
* which breaks the whole app. So, we move the hashed ID into
|
|
17
|
+
* the normal `n_id` field, and use a different format.
|
|
18
|
+
*
|
|
19
|
+
* This was first introduced in #1048
|
|
20
|
+
*/
|
|
21
|
+
const createHashedNId = (nId, aId) => `HASHED::${nId}::${aId}`;
|
|
22
|
+
exports.createHashedNId = createHashedNId;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { RuleData, ScoreConfig, ScoreRule } from "./types";
|
|
1
|
+
import type { RuleData, ScoreConfig, ScoreRule } from "./types";
|
|
2
2
|
/** evaluates an individual rule, normally you should use {@link calculateScore} */
|
|
3
3
|
export declare function evaluateRule(rule: ScoreRule, data: RuleData): {
|
|
4
4
|
passed: boolean;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { ProfileObject, RealVer, Schema } from "@raytio/types";
|
|
2
|
-
import { RuleData } from "./types";
|
|
3
|
-
export declare const convertInstanceToRuleInput: (POs: ProfileObject[], realVers: RealVer[], getSchema: (schemaName:
|
|
1
|
+
import type { ProfileObject, RealVer, Schema, SchemaName } from "@raytio/types";
|
|
2
|
+
import type { RuleData } from "./types";
|
|
3
|
+
export declare const convertInstanceToRuleInput: (POs: ProfileObject[], realVers: RealVer[], getSchema: (schemaName: SchemaName) => Promise<Schema>) => Promise<RuleData>;
|
|
@@ -60,8 +60,11 @@ const convertInstanceToRuleInput = async (POs, realVers, getSchema) => {
|
|
|
60
60
|
});
|
|
61
61
|
const dateFieldByCategorys = (0, ramda_1.groupBy)(([fieldName]) => schema.properties[fieldName].tags.find(tag => tag.startsWith("group:date_picker")), validFields.filter(isDateField(schema)));
|
|
62
62
|
// the three date fields become one pseudo field for the score system
|
|
63
|
-
const pseudoDateFields = Object.entries(dateFieldByCategorys).map(([groupTag,
|
|
63
|
+
const pseudoDateFields = Object.entries(dateFieldByCategorys).map(([groupTag, _members]) => {
|
|
64
64
|
var _a;
|
|
65
|
+
// obviously this won't be undefined since we're
|
|
66
|
+
// looping through the object.
|
|
67
|
+
const members = _members;
|
|
65
68
|
const groupName = groupTag.split(":")[2] || "NO_NAME";
|
|
66
69
|
const memberFieldNames = members.map(x => x[0]);
|
|
67
70
|
const worstVer = (0, ramda_1.sort)((a, b) => b - a, // find the highest enum value (that's the worst)
|
|
@@ -108,7 +111,7 @@ const convertInstanceToRuleInput = async (POs, realVers, getSchema) => {
|
|
|
108
111
|
return subFields.map(subFieldName => {
|
|
109
112
|
const value = fieldValue[subFieldName];
|
|
110
113
|
const hsubfield = {
|
|
111
|
-
hField: null,
|
|
114
|
+
hField: null, // you can't access metadata on a subfield
|
|
112
115
|
type: getTypeofFieldValue(value),
|
|
113
116
|
value,
|
|
114
117
|
};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { ASTScoreConditionNode, RuleData } from "./types";
|
|
1
|
+
import type { ASTScoreConditionNode, RuleData } from "./types";
|
|
2
2
|
export declare function evaluateScoreCondition(node: ASTScoreConditionNode, data: RuleData): boolean;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { GetTSType, ValueType } from "../types";
|
|
1
|
+
import { type GetTSType, type 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
4
|
/**
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { RuleData, ValuePath } from "../types";
|
|
1
|
+
import type { RuleData, ValuePath } from "../types";
|
|
2
2
|
/** this returns an array because there might be multiple of the same schema shared */
|
|
3
3
|
export declare function getValuesFromPath(path: ValuePath, data: RuleData): unknown[];
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { OperatorDef, OperatorID } from "../types";
|
|
2
2
|
export declare const boolOperators: Partial<Record<OperatorID, OperatorDef>>;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { OperatorDef, OperatorID } from "../types";
|
|
2
2
|
export declare const dateOperators: Partial<Record<OperatorID, OperatorDef>>;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { OperatorDef, OperatorID } from "../types";
|
|
2
2
|
export declare const fieldOperators: Partial<Record<OperatorID, OperatorDef>>;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { OperatorDef, OperatorID } from "../types";
|
|
2
2
|
export declare const schemaOperators: Partial<Record<OperatorID, OperatorDef>>;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { OperatorDef, OperatorID } from "../types";
|
|
2
2
|
export declare const numberOperators: Partial<Record<OperatorID, OperatorDef>>;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { OperatorDef, OperatorID } from "../types";
|
|
2
2
|
export declare const stringOperators: Partial<Record<OperatorID, OperatorDef>>;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { SchemaName } from "@raytio/types";
|
|
2
|
+
import type { GetTSType } from "./dataValueTypes";
|
|
2
3
|
/**
|
|
3
4
|
* @ignore
|
|
4
5
|
* these are just IDs, the string is never parsed by anything.
|
|
@@ -11,9 +12,9 @@ export type OperatorID = "bool_eq" | "bool_neq" | "num_eq" | "num_neq" | "num_lt
|
|
|
11
12
|
/** @ignore */
|
|
12
13
|
export type ValuePathFieldProp = "meta" | "value" | "valueLength" | `subField|${string}`;
|
|
13
14
|
/** @ignore */
|
|
14
|
-
export type ValuePath = [type: "schema", schemaName:
|
|
15
|
+
export type ValuePath = [type: "schema", schemaName: SchemaName, prop: "meta"] | [
|
|
15
16
|
type: "field",
|
|
16
|
-
schemaName:
|
|
17
|
+
schemaName: SchemaName,
|
|
17
18
|
fieldName: string,
|
|
18
19
|
prop: ValuePathFieldProp
|
|
19
20
|
];
|
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
import { FieldVerification, NId, POVerification } from "@raytio/types";
|
|
1
|
+
import type { FieldVerification, NId, POVerification, SchemaName } from "@raytio/types";
|
|
2
2
|
import type { HFieldSymbol, HSchemaSymbol } from "../helpers";
|
|
3
3
|
/** undefined if not shared */
|
|
4
4
|
export type HField = {
|
|
5
5
|
__typeof__: typeof HFieldSymbol;
|
|
6
6
|
verification: FieldVerification;
|
|
7
7
|
verifiedBy: readonly NId[];
|
|
8
|
-
|
|
9
|
-
cameFromSchema: string;
|
|
8
|
+
cameFromSchema: SchemaName;
|
|
10
9
|
};
|
|
11
10
|
/** undefined if not shared */
|
|
12
11
|
export type HSchema = {
|
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import type { SchemaName } from "@raytio/types";
|
|
2
|
+
import type { GetTSType, HField, HSchema } from "./dataValueTypes";
|
|
3
|
+
import type { FieldValueTypes, ValueType } from "./config";
|
|
3
4
|
export type RuleDataProperty<T extends FieldValueTypes> = {
|
|
4
5
|
type: T;
|
|
5
6
|
value: GetTSType<T>;
|
|
6
7
|
hField: HField;
|
|
7
8
|
};
|
|
8
9
|
export type RuleData = {
|
|
9
|
-
[schemaName:
|
|
10
|
+
[schemaName: SchemaName]: {
|
|
10
11
|
hSchema: HSchema;
|
|
11
12
|
properties: {
|
|
12
13
|
[fieldName: string]: RuleDataProperty<FieldValueTypes>;
|
package/dist/rules/validate.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ScoreResult } from "./calculateScore";
|
|
2
|
-
import { ScoreConfig } from "./types";
|
|
1
|
+
import type { ScoreResult } from "./calculateScore";
|
|
2
|
+
import type { ScoreConfig } from "./types";
|
|
3
3
|
/** determines whether a `ScoreResult` object is valid */
|
|
4
4
|
export declare const isScoreResultValid: (x: unknown) => x is ScoreResult;
|
|
5
5
|
/** determines whether a `ScoreConfig` object is valid */
|
|
@@ -3,13 +3,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
const expandSchema_1 = require("../expandSchema");
|
|
4
4
|
const fromAPI = [
|
|
5
5
|
{
|
|
6
|
-
|
|
6
|
+
schema_name: "ps_Vessel",
|
|
7
7
|
start_date: "1970-01-01T00:00:00+00:00",
|
|
8
8
|
end_date: "2222-12-31T23:59:59+00:00",
|
|
9
9
|
active: true,
|
|
10
10
|
version_current: true,
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
schema_version: "0.0.7",
|
|
12
|
+
schema_type: "ps",
|
|
13
13
|
schema: {
|
|
14
14
|
$id: "https://api.rayt.io/graph/v1/schema/ps/ps_Vessel",
|
|
15
15
|
$schema: "http://json-schema.org/draft-07/schema#",
|
|
@@ -38,8 +38,8 @@ const fromAPI = [
|
|
|
38
38
|
},
|
|
39
39
|
},
|
|
40
40
|
{
|
|
41
|
-
|
|
42
|
-
|
|
41
|
+
schema_name: "ss_birth_year_integer",
|
|
42
|
+
schema_version: "0.0.1",
|
|
43
43
|
schema: {
|
|
44
44
|
$id: "this field often has typos. in this case its blatantly wrong",
|
|
45
45
|
$schema: "https://whatever",
|
|
@@ -61,14 +61,15 @@ describe("expandSchema", () => {
|
|
|
61
61
|
start_date: "1970-01-01T00:00:00+00:00",
|
|
62
62
|
end_date: "2222-12-31T23:59:59+00:00",
|
|
63
63
|
version: "0.0.7",
|
|
64
|
-
|
|
64
|
+
schema_type: "ps",
|
|
65
|
+
i18n: fromAPI[0].schema.i18n, // unchanged
|
|
65
66
|
isProfileSchema: true,
|
|
66
67
|
isSpSchema: false,
|
|
67
68
|
properties: {
|
|
68
69
|
manufacture_year: {
|
|
69
70
|
// $id was removed
|
|
70
71
|
$prop: "manufacture_year",
|
|
71
|
-
$ref: "ss_birth_year_integer",
|
|
72
|
+
$ref: "ss_birth_year_integer", // it added a $ref tag
|
|
72
73
|
maximum: 2022,
|
|
73
74
|
minimum: 1900,
|
|
74
75
|
title: "Year of birth",
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const i18n_1 = require("../i18n");
|
|
4
|
-
const DEFAULT_LOCALES = ["de-DE"]; // match what the client does in
|
|
4
|
+
const DEFAULT_LOCALES = ["de-DE"]; // match what the client does in vi.setup.ts
|
|
5
5
|
describe("getAllLocales", () => {
|
|
6
6
|
it("correctly expands languages with a country-componentand lowercases them", () => {
|
|
7
7
|
const expanded = (0, i18n_1.getAllLocales)([
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const maybeUseI18n_1 = require("../maybeUseI18n");
|
|
4
|
-
const DEFAULT_LOCALES = ["de-DE"]; // match what the client does in
|
|
4
|
+
const DEFAULT_LOCALES = ["de-DE"]; // match what the client does in vi.setup.ts
|
|
5
5
|
describe("maybeUseI18n", () => {
|
|
6
6
|
it("correctly applies schema-wise overrides", () => {
|
|
7
7
|
const originalSchema = {
|
|
@@ -82,7 +82,7 @@ describe("maybeUseI18n", () => {
|
|
|
82
82
|
};
|
|
83
83
|
const translatedSchema = (0, maybeUseI18n_1.maybeUseI18n)(originalSchema, DEFAULT_LOCALES);
|
|
84
84
|
expect(translatedSchema).toStrictEqual({
|
|
85
|
-
clientLocale: "de",
|
|
85
|
+
clientLocale: "de", // note how this is 'de', not 'de-de' because the schema defined 'de'
|
|
86
86
|
groupNames: {},
|
|
87
87
|
group_title: undefined,
|
|
88
88
|
properties: {
|
|
@@ -25,7 +25,7 @@ describe("processSchema", () => {
|
|
|
25
25
|
const allUnexpandedSchema = [
|
|
26
26
|
mock,
|
|
27
27
|
{
|
|
28
|
-
|
|
28
|
+
schema_name: "ss_first_name_01",
|
|
29
29
|
schema: {
|
|
30
30
|
properties: {},
|
|
31
31
|
tags: ["a tag from the child"],
|
|
@@ -53,7 +53,7 @@ describe("processSchema", () => {
|
|
|
53
53
|
});
|
|
54
54
|
});
|
|
55
55
|
it("should not expand normal properties", async () => {
|
|
56
|
-
const getIdentityToken =
|
|
56
|
+
const getIdentityToken = vi.fn(async () => { });
|
|
57
57
|
const properties = {
|
|
58
58
|
first_name: {
|
|
59
59
|
priority: 10,
|
|
@@ -95,14 +95,14 @@ describe("processSchema", () => {
|
|
|
95
95
|
const allUnexpandedSchema = [
|
|
96
96
|
mock,
|
|
97
97
|
{
|
|
98
|
-
|
|
98
|
+
schema_name: "ss_first_name_01",
|
|
99
99
|
schema: {
|
|
100
100
|
required: ["c", "d"],
|
|
101
101
|
properties: { first_name: { type: "string" } },
|
|
102
102
|
},
|
|
103
103
|
},
|
|
104
104
|
{
|
|
105
|
-
|
|
105
|
+
schema_name: "ss_last_name_01",
|
|
106
106
|
schema: {
|
|
107
107
|
required: ["e", "f"],
|
|
108
108
|
properties: { last_name: { type: "string" } },
|
|
@@ -119,7 +119,7 @@ describe("processSchema", () => {
|
|
|
119
119
|
verified_fields: undefined,
|
|
120
120
|
isProfileSchema: false,
|
|
121
121
|
isSpSchema: false,
|
|
122
|
-
allOf: mock.schema.allOf,
|
|
122
|
+
allOf: mock.schema.allOf, // removed later
|
|
123
123
|
definitions: mock.schema.definitions, // removed later
|
|
124
124
|
});
|
|
125
125
|
});
|
|
@@ -297,7 +297,7 @@ describe("processSchema", () => {
|
|
|
297
297
|
],
|
|
298
298
|
};
|
|
299
299
|
const moeSubSchema = {
|
|
300
|
-
|
|
300
|
+
schema_name: "ss_MOE_ID",
|
|
301
301
|
schema: {
|
|
302
302
|
type: "number",
|
|
303
303
|
properties: {},
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { Schema } from "@raytio/types";
|
|
1
|
+
import type { Schema } from "@raytio/types";
|
|
2
2
|
export declare const addLoadingTimes: (schema: Schema) => Schema;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { SchemaTag } from "@raytio/types";
|
|
1
|
+
import type { SchemaTag } from "@raytio/types";
|
|
2
2
|
export declare const TAG_DENYLIST: SchemaTag[];
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { Schema } from "@raytio/types";
|
|
1
|
+
import type { Schema } from "@raytio/types";
|
|
2
2
|
export declare const maybeUseI18n: (schema: Schema, userLocales: readonly string[]) => Schema;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { Schema, WrappedSchema } from "@raytio/types";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
}, allUnexpandedSchemas: WrappedSchema[]) => Schema;
|
|
1
|
+
import type { Schema, WrappedSchema } from "@raytio/types";
|
|
2
|
+
import type { unwrapSchema } from "./unwrapSchema";
|
|
3
|
+
export declare const processSchema: (schema: ReturnType<typeof unwrapSchema>, allUnexpandedSchemas: WrappedSchema[]) => Schema;
|
|
@@ -19,7 +19,7 @@ const processSchema = (schema, allUnexpandedSchemas) => {
|
|
|
19
19
|
const subSchemaName = (0, sortSchemaProperties_1.getNidFromUrn)((_a = schema.definitions) === null || _a === void 0 ? void 0 : _a[$ref.split("/")[2]].$ref);
|
|
20
20
|
if (!subSchemaName)
|
|
21
21
|
throw new Error("Invalid schema");
|
|
22
|
-
const subSchema = (_b = allUnexpandedSchemas.find(s => s.
|
|
22
|
+
const subSchema = (_b = allUnexpandedSchemas.find(s => s.schema_name === subSchemaName)) === null || _b === void 0 ? void 0 : _b.schema;
|
|
23
23
|
if (!subSchema) {
|
|
24
24
|
throw new Error(`Could not resolve subschema '${subSchemaName}'`);
|
|
25
25
|
}
|
|
@@ -44,7 +44,7 @@ const processSchema = (schema, allUnexpandedSchemas) => {
|
|
|
44
44
|
const subSchemaName = (0, sortSchemaProperties_1.getNidFromUrn)((_a = schema.definitions) === null || _a === void 0 ? void 0 : _a[$ref.split("/")[2]].$ref);
|
|
45
45
|
if (!subSchemaName)
|
|
46
46
|
throw new Error("Invalid schema");
|
|
47
|
-
const subSchema = (_b = allUnexpandedSchemas.find(s => s.
|
|
47
|
+
const subSchema = (_b = allUnexpandedSchemas.find(s => s.schema_name === subSchemaName)) === null || _b === void 0 ? void 0 : _b.schema;
|
|
48
48
|
if (!subSchema) {
|
|
49
49
|
throw new Error(`Could not resolve subschema '${subSchemaName}'`);
|
|
50
50
|
}
|