@raytio/core 11.0.0 → 11.2.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 +16 -1
- package/README.md +100 -1
- package/dist/crypto/getAADecryptor.js +32 -4
- 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 +96 -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 +3 -0
- package/dist/schema/expandSchema/processSchema.js +94 -0
- package/dist/schema/expandSchema/removePrivateFields.d.ts +121 -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 +1 -0
- package/dist/schema/index.js +1 -0
- package/dist/testHelpers.d.ts +9 -0
- package/dist/testHelpers.js +9 -0
- package/dist/verifications/getPOVerification.js +6 -2
- package/dist/verifications/getVerifiedBy.js +6 -1
- package/dist/verifications/safeHarbour.d.ts +1 -1
- package/dist/verifications/safeHarbour.js +4 -11
- package/dist/verifications/verifyCheck/__tests__/getOwnRealVerifications.test.js +72 -7
- package/dist/verifications/verifyCheck/getOwnRealVerifications.js +3 -1
- package/dist/verifications/verifyCheck/operations/__tests__/checkOwnVerification.test.js +45 -5
- package/dist/verifications/verifyCheck/operations/__tests__/sampleBundle.json +1 -0
- package/dist/verifications/verifyCheck/operations/checkOwnVerification.d.ts +3 -2
- package/dist/verifications/verifyCheck/operations/checkOwnVerification.js +15 -8
- package/package.json +5 -5
package/CHANGELOG.md
CHANGED
|
@@ -5,9 +5,24 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
<!--
|
|
9
|
+
If you think there are missing entries, go to:
|
|
10
|
+
https://gitlab.com/raytio/raytio-client-v2/-/commits/master/packages/core
|
|
11
|
+
to see all commits that touched this package.
|
|
12
|
+
-->
|
|
13
|
+
|
|
8
14
|
## [Unreleased]
|
|
9
15
|
|
|
10
|
-
## 11.
|
|
16
|
+
## 11.2.0 (2023-07-03)
|
|
17
|
+
|
|
18
|
+
- Support key rotation
|
|
19
|
+
- Support the new Schema API format
|
|
20
|
+
|
|
21
|
+
## 11.1.0 (2023-04-20)
|
|
22
|
+
|
|
23
|
+
- Move `expandSchema` into core
|
|
24
|
+
|
|
25
|
+
## 11.0.0 (2023-04-20)
|
|
11
26
|
|
|
12
27
|
- 💥 BREAKING CHANGE: Changed the input arguments of `convertInstanceToRuleInput` to only require a list of `ProfileObject`s, instead of the whole `Instance` object.
|
|
13
28
|
- Any profile object with an expired field is now considered `Expired`, even if other fields are verified.
|
package/README.md
CHANGED
|
@@ -32,9 +32,12 @@ If you wish to use `@raytio/core` directly, an example of configuring polyfills
|
|
|
32
32
|
- [createAA](#createaa)
|
|
33
33
|
- [decryptSharedData](#decryptshareddata)
|
|
34
34
|
- [evaluateRule](#evaluaterule)
|
|
35
|
+
- [expandSchema](#expandschema)
|
|
35
36
|
- [findSchemaLabel](#findschemalabel)
|
|
37
|
+
- [findSuitableLocale](#findsuitablelocale)
|
|
36
38
|
- [fromCognitoAttributes](#fromcognitoattributes)
|
|
37
39
|
- [getAADecryptor](#getaadecryptor)
|
|
40
|
+
- [getNidFromUrn](#getnidfromurn)
|
|
38
41
|
- [getOwnRealVerifications](#getownrealverifications)
|
|
39
42
|
- [getPOVerification](#getpoverification)
|
|
40
43
|
- [getSomeoneElsesRealVerifications](#getsomeoneelsesrealverifications)
|
|
@@ -46,6 +49,7 @@ If you wish to use `@raytio/core` directly, an example of configuring polyfills
|
|
|
46
49
|
- [isScoreResultValid](#isscoreresultvalid)
|
|
47
50
|
- [repairDate](#repairdate)
|
|
48
51
|
- [someEncrypted](#someencrypted)
|
|
52
|
+
- [sortSchemaProperties](#sortschemaproperties)
|
|
49
53
|
- [toCognitoAttributes](#tocognitoattributes)
|
|
50
54
|
|
|
51
55
|
## Type Aliases
|
|
@@ -134,7 +138,7 @@ ___
|
|
|
134
138
|
|
|
135
139
|
### checkJsonSignature
|
|
136
140
|
|
|
137
|
-
▸ **checkJsonSignature**(`data`, `signature`): `Promise`<`boolean`\>
|
|
141
|
+
▸ **checkJsonSignature**(`data`, `signature`, `keyId`): `Promise`<`boolean`\>
|
|
138
142
|
|
|
139
143
|
checks that a json object was signed by the provided signature. Unless you're
|
|
140
144
|
dealing with bundled verifications, you should use `getOwnRealVerifications`
|
|
@@ -146,6 +150,7 @@ or `getSomeoneElsesRealVerifications` instead.
|
|
|
146
150
|
| :------ | :------ |
|
|
147
151
|
| `data` | `unknown` |
|
|
148
152
|
| `signature` | `string` |
|
|
153
|
+
| `keyId` | `undefined` \| `string` |
|
|
149
154
|
|
|
150
155
|
#### Returns
|
|
151
156
|
|
|
@@ -275,6 +280,28 @@ evaluates an individual rule, normally you should use [calculateScore](#calculat
|
|
|
275
280
|
|
|
276
281
|
___
|
|
277
282
|
|
|
283
|
+
### expandSchema
|
|
284
|
+
|
|
285
|
+
▸ **expandSchema**(`wrappedSchema`, `allUnexpandedSchemas`, `userLocales`): `Schema`
|
|
286
|
+
|
|
287
|
+
❣️ This is the main function to transform a schema from
|
|
288
|
+
the JSON that the API returns, into a `Schema` object that's useful
|
|
289
|
+
to the client.
|
|
290
|
+
|
|
291
|
+
#### Parameters
|
|
292
|
+
|
|
293
|
+
| Name | Type |
|
|
294
|
+
| :------ | :------ |
|
|
295
|
+
| `wrappedSchema` | `WrappedSchema` |
|
|
296
|
+
| `allUnexpandedSchemas` | `WrappedSchema`[] |
|
|
297
|
+
| `userLocales` | readonly `string`[] |
|
|
298
|
+
|
|
299
|
+
#### Returns
|
|
300
|
+
|
|
301
|
+
`Schema`
|
|
302
|
+
|
|
303
|
+
___
|
|
304
|
+
|
|
278
305
|
### findSchemaLabel
|
|
279
306
|
|
|
280
307
|
▸ **findSchemaLabel**(`labels`): `undefined` \| `string`
|
|
@@ -293,6 +320,26 @@ Finds the label (on a profile object) which is the schema name
|
|
|
293
320
|
|
|
294
321
|
___
|
|
295
322
|
|
|
323
|
+
### findSuitableLocale
|
|
324
|
+
|
|
325
|
+
▸ **findSuitableLocale**(`options`, `langs`): `undefined` \| `string`
|
|
326
|
+
|
|
327
|
+
Selects the most suitable locale to use from a list of options.
|
|
328
|
+
Returns undefined if there is no language that the user speaks
|
|
329
|
+
|
|
330
|
+
#### Parameters
|
|
331
|
+
|
|
332
|
+
| Name | Type |
|
|
333
|
+
| :------ | :------ |
|
|
334
|
+
| `options` | `string`[] |
|
|
335
|
+
| `langs` | readonly `string`[] |
|
|
336
|
+
|
|
337
|
+
#### Returns
|
|
338
|
+
|
|
339
|
+
`undefined` \| `string`
|
|
340
|
+
|
|
341
|
+
___
|
|
342
|
+
|
|
296
343
|
### fromCognitoAttributes
|
|
297
344
|
|
|
298
345
|
▸ **fromCognitoAttributes**(`attributes`): `UserDoc`
|
|
@@ -337,6 +384,38 @@ an `ApplicationEncryptor` and the public key of the Access Application
|
|
|
337
384
|
|
|
338
385
|
___
|
|
339
386
|
|
|
387
|
+
### getNidFromUrn
|
|
388
|
+
|
|
389
|
+
▸ **getNidFromUrn**(`urn`): `NId`
|
|
390
|
+
|
|
391
|
+
two overloads - if you provide undefined, you might get undefined back
|
|
392
|
+
|
|
393
|
+
#### Parameters
|
|
394
|
+
|
|
395
|
+
| Name | Type |
|
|
396
|
+
| :------ | :------ |
|
|
397
|
+
| `urn` | `Urn` |
|
|
398
|
+
|
|
399
|
+
#### Returns
|
|
400
|
+
|
|
401
|
+
`NId`
|
|
402
|
+
|
|
403
|
+
▸ **getNidFromUrn**(`urn`): `undefined` \| `NId`
|
|
404
|
+
|
|
405
|
+
two overloads - if you provide undefined, you might get undefined back
|
|
406
|
+
|
|
407
|
+
#### Parameters
|
|
408
|
+
|
|
409
|
+
| Name | Type |
|
|
410
|
+
| :------ | :------ |
|
|
411
|
+
| `urn` | `undefined` \| `Urn` |
|
|
412
|
+
|
|
413
|
+
#### Returns
|
|
414
|
+
|
|
415
|
+
`undefined` \| `NId`
|
|
416
|
+
|
|
417
|
+
___
|
|
418
|
+
|
|
340
419
|
### getOwnRealVerifications
|
|
341
420
|
|
|
342
421
|
▸ **getOwnRealVerifications**(`«destructured»`): `Promise`<`RealVer`[]\>
|
|
@@ -591,6 +670,26 @@ of properties that are encryted.
|
|
|
591
670
|
|
|
592
671
|
___
|
|
593
672
|
|
|
673
|
+
### sortSchemaProperties
|
|
674
|
+
|
|
675
|
+
▸ **sortSchemaProperties**(`properties`): `Section`[]
|
|
676
|
+
|
|
677
|
+
Schema properties are an object, so they need to be converted into an
|
|
678
|
+
array, grouped by the group tag, and then sorted based on the `priority`
|
|
679
|
+
attribute within their group.
|
|
680
|
+
|
|
681
|
+
#### Parameters
|
|
682
|
+
|
|
683
|
+
| Name | Type |
|
|
684
|
+
| :------ | :------ |
|
|
685
|
+
| `properties` | `Record`<`string`, `SchemaField`\> |
|
|
686
|
+
|
|
687
|
+
#### Returns
|
|
688
|
+
|
|
689
|
+
`Section`[]
|
|
690
|
+
|
|
691
|
+
___
|
|
692
|
+
|
|
594
693
|
### toCognitoAttributes
|
|
595
694
|
|
|
596
695
|
▸ **toCognitoAttributes**(`userDoc`): `Object`
|
|
@@ -2,16 +2,44 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getAADecryptor = 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 fetchPublicKey({ 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
|
+
const { id, public_key } = publicKey;
|
|
17
|
+
return { n_id: id, properties: public_key };
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Fetches the Private Key Information from a Public Key
|
|
21
|
+
* @returns An encrypted Private Key
|
|
22
|
+
*/
|
|
23
|
+
async function fetchPrivateKey({ apiUrl, apiToken, publicKeyNId, }) {
|
|
24
|
+
const [privateKey] = await fetch(`${apiUrl}/db/v1/dsm_access_application_private_keys?aack_id=eq.${publicKeyNId}`, { 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 { n_id: publicKeyNId, properties: publicKey } = (await
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
33
|
+
const { n_id: publicKeyNId, properties: publicKey } = (await fetchPublicKey({
|
|
34
|
+
apiUrl,
|
|
35
|
+
apiToken,
|
|
36
|
+
aId,
|
|
37
|
+
}));
|
|
38
|
+
const privateKey = await fetchPrivateKey({
|
|
39
|
+
apiUrl,
|
|
40
|
+
apiToken,
|
|
41
|
+
publicKeyNId,
|
|
42
|
+
});
|
|
15
43
|
return {
|
|
16
44
|
decryptor: await maxcryptor.loadApplicationEncryptorForDecryption(publicKey, privateKey),
|
|
17
45
|
publicKeyNId,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const addLoadingTimes_1 = require("../addLoadingTimes");
|
|
4
|
+
describe("addLoadingTimes", () => {
|
|
5
|
+
it("parses loading times from the schema tags", () => {
|
|
6
|
+
const schema = {
|
|
7
|
+
name: "hi",
|
|
8
|
+
tags: [
|
|
9
|
+
"a:b",
|
|
10
|
+
"c",
|
|
11
|
+
"time:action1:20",
|
|
12
|
+
"time:action2:5",
|
|
13
|
+
"time:action3:0",
|
|
14
|
+
"time:action4:not a number",
|
|
15
|
+
],
|
|
16
|
+
};
|
|
17
|
+
expect((0, addLoadingTimes_1.addLoadingTimes)(schema)).toStrictEqual(Object.assign(Object.assign({}, schema), { timing: {
|
|
18
|
+
action1: 20,
|
|
19
|
+
action2: 5,
|
|
20
|
+
action3: 0,
|
|
21
|
+
action4: NaN,
|
|
22
|
+
} }));
|
|
23
|
+
});
|
|
24
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const expandSchema_1 = require("../expandSchema");
|
|
4
|
+
const fromAPI = [
|
|
5
|
+
{
|
|
6
|
+
schema_name: "ps_Vessel",
|
|
7
|
+
start_date: "1970-01-01T00:00:00+00:00",
|
|
8
|
+
end_date: "2222-12-31T23:59:59+00:00",
|
|
9
|
+
active: true,
|
|
10
|
+
version_current: true,
|
|
11
|
+
schema_version: "0.0.7",
|
|
12
|
+
schema_type: "ps",
|
|
13
|
+
schema: {
|
|
14
|
+
$id: "https://api.rayt.io/graph/v1/schema/ps/ps_Vessel",
|
|
15
|
+
$schema: "http://json-schema.org/draft-07/schema#",
|
|
16
|
+
title: "Vessel/Boat",
|
|
17
|
+
description: "A schema that describes a maritime vessel",
|
|
18
|
+
i18n: {
|
|
19
|
+
"mi-NZ": {
|
|
20
|
+
$schema: { title: "Waka" },
|
|
21
|
+
vesselName: { title: "nga waka ingoa" },
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
tags: ["time:action1:20"],
|
|
25
|
+
required: ["vesselName"],
|
|
26
|
+
properties: {
|
|
27
|
+
manufacture_year: {
|
|
28
|
+
allOf: [
|
|
29
|
+
{ $ref: "#/definitions/ss_birth_year_integer" },
|
|
30
|
+
{ tags: ["aaa"], priority: 700 },
|
|
31
|
+
],
|
|
32
|
+
},
|
|
33
|
+
vesselName: { type: "string", title: "Vessel Name", priority: 1000 },
|
|
34
|
+
},
|
|
35
|
+
definitions: {
|
|
36
|
+
ss_birth_year_integer: { $ref: "urn:schema:ss_birth_year_integer" },
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
schema_name: "ss_birth_year_integer",
|
|
42
|
+
schema_version: "0.0.1",
|
|
43
|
+
schema: {
|
|
44
|
+
$id: "this field often has typos. in this case its blatantly wrong",
|
|
45
|
+
$schema: "https://whatever",
|
|
46
|
+
maximum: 2022,
|
|
47
|
+
minimum: 1900,
|
|
48
|
+
tags: ["type:globally_unique_field"],
|
|
49
|
+
title: "Year of birth",
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
];
|
|
53
|
+
describe("expandSchema", () => {
|
|
54
|
+
it("can do the entire expansion process", () => {
|
|
55
|
+
expect((0, expandSchema_1.expandSchema)(fromAPI[0], fromAPI, ["lb-LU"])).toStrictEqual({
|
|
56
|
+
wasExpandedByClient: true,
|
|
57
|
+
// $schema was removed
|
|
58
|
+
name: "ps_Vessel",
|
|
59
|
+
title: "Vessel/Boat",
|
|
60
|
+
description: "A schema that describes a maritime vessel",
|
|
61
|
+
start_date: "1970-01-01T00:00:00+00:00",
|
|
62
|
+
end_date: "2222-12-31T23:59:59+00:00",
|
|
63
|
+
version: "0.0.7",
|
|
64
|
+
schema_type: "ps",
|
|
65
|
+
i18n: fromAPI[0].schema.i18n,
|
|
66
|
+
isProfileSchema: true,
|
|
67
|
+
isSpSchema: false,
|
|
68
|
+
properties: {
|
|
69
|
+
manufacture_year: {
|
|
70
|
+
// $id was removed
|
|
71
|
+
$prop: "manufacture_year",
|
|
72
|
+
$ref: "ss_birth_year_integer",
|
|
73
|
+
maximum: 2022,
|
|
74
|
+
minimum: 1900,
|
|
75
|
+
title: "Year of birth",
|
|
76
|
+
// it merged the allOf into a single object
|
|
77
|
+
priority: 700,
|
|
78
|
+
tags: ["aaa", "type:globally_unique_field"],
|
|
79
|
+
},
|
|
80
|
+
vesselName: {
|
|
81
|
+
$prop: "vesselName",
|
|
82
|
+
// no $ref attribute
|
|
83
|
+
priority: 1000,
|
|
84
|
+
title: "Vessel Name",
|
|
85
|
+
type: "string",
|
|
86
|
+
},
|
|
87
|
+
},
|
|
88
|
+
required: ["vesselName"],
|
|
89
|
+
tags: ["time:action1:20"],
|
|
90
|
+
timing: {
|
|
91
|
+
action1: 20,
|
|
92
|
+
},
|
|
93
|
+
verified_fields: undefined,
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const i18n_1 = require("../i18n");
|
|
4
|
+
const DEFAULT_LOCALES = ["de-DE"]; // match what the client does in jest.setup.ts
|
|
5
|
+
describe("getAllLocales", () => {
|
|
6
|
+
it("correctly expands languages with a country-componentand lowercases them", () => {
|
|
7
|
+
const expanded = (0, i18n_1.getAllLocales)([
|
|
8
|
+
"en-NZ",
|
|
9
|
+
"de-CH",
|
|
10
|
+
"be",
|
|
11
|
+
"ar-001",
|
|
12
|
+
"az-Cyrl-AZ",
|
|
13
|
+
]);
|
|
14
|
+
expect(expanded).toStrictEqual([
|
|
15
|
+
"en-nz",
|
|
16
|
+
"en",
|
|
17
|
+
"de-ch",
|
|
18
|
+
"de",
|
|
19
|
+
"be",
|
|
20
|
+
"ar-001",
|
|
21
|
+
"ar",
|
|
22
|
+
"az-cyrl-az",
|
|
23
|
+
"az",
|
|
24
|
+
]);
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
describe("findSuitableLocale", () => {
|
|
28
|
+
it("picks the most appropriate option", () => {
|
|
29
|
+
// the users's locale is `de-DE`, so it picked the most appropriate one from the options: `de-AT`
|
|
30
|
+
expect((0, i18n_1.findSuitableLocale)(["en-029", "de-AT", "fr-FR"], DEFAULT_LOCALES)).toBe("de-AT");
|
|
31
|
+
});
|
|
32
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const maybeUseI18n_1 = require("../maybeUseI18n");
|
|
4
|
+
const DEFAULT_LOCALES = ["de-DE"]; // match what the client does in jest.setup.ts
|
|
5
|
+
describe("maybeUseI18n", () => {
|
|
6
|
+
it("correctly applies schema-wise overrides", () => {
|
|
7
|
+
const originalSchema = {
|
|
8
|
+
schema_group: "old_schemas",
|
|
9
|
+
title: "Default title",
|
|
10
|
+
description: "default desc",
|
|
11
|
+
i18n: {
|
|
12
|
+
"de-de": {
|
|
13
|
+
$schema: {
|
|
14
|
+
title: "der Name dieses Schema",
|
|
15
|
+
description: "eine Beschreibung in Deutsch",
|
|
16
|
+
},
|
|
17
|
+
old_schemas: {
|
|
18
|
+
title_plural: "All the old sChema",
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
const translatedSchema = (0, maybeUseI18n_1.maybeUseI18n)(originalSchema, DEFAULT_LOCALES);
|
|
24
|
+
expect(translatedSchema).toStrictEqual({
|
|
25
|
+
schema_group: "old_schemas",
|
|
26
|
+
group_title: "All the old sChema",
|
|
27
|
+
title: "der Name dieses Schema",
|
|
28
|
+
description: "eine Beschreibung in Deutsch",
|
|
29
|
+
clientLocale: "de-de",
|
|
30
|
+
groupNames: {},
|
|
31
|
+
properties: {},
|
|
32
|
+
i18n: originalSchema.i18n,
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
it("corretly creates a groupNames property with the correct locale", () => {
|
|
36
|
+
const originalSchema = {
|
|
37
|
+
i18n: {
|
|
38
|
+
"en-nz": {
|
|
39
|
+
"group:DoB": { title: "Your date of birth" },
|
|
40
|
+
},
|
|
41
|
+
"fr-fr": {
|
|
42
|
+
"group:DoB": { title: "anniversaire" },
|
|
43
|
+
},
|
|
44
|
+
"de-de": {
|
|
45
|
+
"group:DoB": { title: "dein Geburtstag" },
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
properties: {
|
|
49
|
+
year_of_birth: {
|
|
50
|
+
tags: ["group:DoB"],
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
};
|
|
54
|
+
const translatedSchema = (0, maybeUseI18n_1.maybeUseI18n)(originalSchema, DEFAULT_LOCALES);
|
|
55
|
+
expect(translatedSchema).toStrictEqual({
|
|
56
|
+
clientLocale: "de-de",
|
|
57
|
+
groupNames: {
|
|
58
|
+
DoB: "dein Geburtstag",
|
|
59
|
+
},
|
|
60
|
+
group_title: undefined,
|
|
61
|
+
properties: originalSchema.properties,
|
|
62
|
+
i18n: originalSchema.i18n,
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
it("correctly applies overrides to certain schema fields", () => {
|
|
66
|
+
const originalSchema = {
|
|
67
|
+
i18n: {
|
|
68
|
+
"en-029": {
|
|
69
|
+
year_of_birth: { title: "Your year of birth" },
|
|
70
|
+
},
|
|
71
|
+
de: {
|
|
72
|
+
// also testing whether it utilizes "de" even tho locale is "de-DE"
|
|
73
|
+
year_of_birth: { title: "dein Geburtsjahr", randomProp: 1 },
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
properties: {
|
|
77
|
+
year_of_birth: {
|
|
78
|
+
title: "Default field title",
|
|
79
|
+
tags: ["group:DoB"],
|
|
80
|
+
},
|
|
81
|
+
},
|
|
82
|
+
};
|
|
83
|
+
const translatedSchema = (0, maybeUseI18n_1.maybeUseI18n)(originalSchema, DEFAULT_LOCALES);
|
|
84
|
+
expect(translatedSchema).toStrictEqual({
|
|
85
|
+
clientLocale: "de",
|
|
86
|
+
groupNames: {},
|
|
87
|
+
group_title: undefined,
|
|
88
|
+
properties: {
|
|
89
|
+
year_of_birth: {
|
|
90
|
+
title: "dein Geburtsjahr",
|
|
91
|
+
randomProp: 1,
|
|
92
|
+
tags: ["group:DoB"],
|
|
93
|
+
},
|
|
94
|
+
},
|
|
95
|
+
i18n: originalSchema.i18n,
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|