@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.
Files changed (54) hide show
  1. package/CHANGELOG.md +16 -1
  2. package/README.md +100 -1
  3. package/dist/crypto/getAADecryptor.js +32 -4
  4. package/dist/schema/expandSchema/__tests__/addLoadingTimes.test.d.ts +1 -0
  5. package/dist/schema/expandSchema/__tests__/addLoadingTimes.test.js +24 -0
  6. package/dist/schema/expandSchema/__tests__/expandSchema.test.d.ts +1 -0
  7. package/dist/schema/expandSchema/__tests__/expandSchema.test.js +96 -0
  8. package/dist/schema/expandSchema/__tests__/i18n.test.d.ts +1 -0
  9. package/dist/schema/expandSchema/__tests__/i18n.test.js +32 -0
  10. package/dist/schema/expandSchema/__tests__/maybeUseI18n.test.d.ts +1 -0
  11. package/dist/schema/expandSchema/__tests__/maybeUseI18n.test.js +98 -0
  12. package/dist/schema/expandSchema/__tests__/processSchema.test.d.ts +1 -0
  13. package/dist/schema/expandSchema/__tests__/processSchema.test.js +326 -0
  14. package/dist/schema/expandSchema/__tests__/sortSchemaProperties.test.d.ts +1 -0
  15. package/dist/schema/expandSchema/__tests__/sortSchemaProperties.test.js +182 -0
  16. package/dist/schema/expandSchema/__tests__/util.test.d.ts +1 -0
  17. package/dist/schema/expandSchema/__tests__/util.test.js +19 -0
  18. package/dist/schema/expandSchema/addLoadingTimes.d.ts +2 -0
  19. package/dist/schema/expandSchema/addLoadingTimes.js +12 -0
  20. package/dist/schema/expandSchema/constants.d.ts +2 -0
  21. package/dist/schema/expandSchema/constants.js +11 -0
  22. package/dist/schema/expandSchema/expandSchema.d.ts +7 -0
  23. package/dist/schema/expandSchema/expandSchema.js +19 -0
  24. package/dist/schema/expandSchema/i18n.d.ts +5 -0
  25. package/dist/schema/expandSchema/i18n.js +20 -0
  26. package/dist/schema/expandSchema/index.d.ts +3 -0
  27. package/dist/schema/expandSchema/index.js +21 -0
  28. package/dist/schema/expandSchema/maybeUseI18n.d.ts +2 -0
  29. package/dist/schema/expandSchema/maybeUseI18n.js +40 -0
  30. package/dist/schema/expandSchema/processSchema.d.ts +3 -0
  31. package/dist/schema/expandSchema/processSchema.js +94 -0
  32. package/dist/schema/expandSchema/removePrivateFields.d.ts +121 -0
  33. package/dist/schema/expandSchema/removePrivateFields.js +15 -0
  34. package/dist/schema/expandSchema/sortSchemaProperties.d.ts +21 -0
  35. package/dist/schema/expandSchema/sortSchemaProperties.js +40 -0
  36. package/dist/schema/expandSchema/unwrapSchema.d.ts +6 -0
  37. package/dist/schema/expandSchema/unwrapSchema.js +7 -0
  38. package/dist/schema/expandSchema/util.d.ts +6 -0
  39. package/dist/schema/expandSchema/util.js +15 -0
  40. package/dist/schema/index.d.ts +1 -0
  41. package/dist/schema/index.js +1 -0
  42. package/dist/testHelpers.d.ts +9 -0
  43. package/dist/testHelpers.js +9 -0
  44. package/dist/verifications/getPOVerification.js +6 -2
  45. package/dist/verifications/getVerifiedBy.js +6 -1
  46. package/dist/verifications/safeHarbour.d.ts +1 -1
  47. package/dist/verifications/safeHarbour.js +4 -11
  48. package/dist/verifications/verifyCheck/__tests__/getOwnRealVerifications.test.js +72 -7
  49. package/dist/verifications/verifyCheck/getOwnRealVerifications.js +3 -1
  50. package/dist/verifications/verifyCheck/operations/__tests__/checkOwnVerification.test.js +45 -5
  51. package/dist/verifications/verifyCheck/operations/__tests__/sampleBundle.json +1 -0
  52. package/dist/verifications/verifyCheck/operations/checkOwnVerification.d.ts +3 -2
  53. package/dist/verifications/verifyCheck/operations/checkOwnVerification.js +15 -8
  54. package/package.json +5 -5
@@ -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
+ schema_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
+ schema_name: "ss_first_name_01",
99
+ schema: {
100
+ required: ["c", "d"],
101
+ properties: { first_name: { type: "string" } },
102
+ },
103
+ },
104
+ {
105
+ schema_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
+ schema_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,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,2 @@
1
+ import { Schema } from "@raytio/types";
2
+ export declare const addLoadingTimes: (schema: Schema) => Schema;
@@ -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,2 @@
1
+ import { SchemaTag } from "@raytio/types";
2
+ export declare const TAG_DENYLIST: SchemaTag[];
@@ -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,5 @@
1
+ /**
2
+ * Selects the most suitable locale to use from a list of options.
3
+ * Returns undefined if there is no language that the user speaks
4
+ */
5
+ export declare const findSuitableLocale: (options: string[], langs: readonly string[]) => string | undefined;
@@ -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,3 @@
1
+ export * from "./expandSchema";
2
+ export * from "./sortSchemaProperties";
3
+ export { findSuitableLocale } from "./i18n";
@@ -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; } });
@@ -0,0 +1,2 @@
1
+ import { Schema } from "@raytio/types";
2
+ export declare const maybeUseI18n: (schema: Schema, userLocales: readonly string[]) => Schema;