@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.
Files changed (208) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/README.md +198 -59
  3. package/dist/{util/hash.d.ts → __tests__/docs.test.d.ts} +1 -1
  4. package/dist/__tests__/docs.test.js +24 -0
  5. package/dist/accessApplication/createAA.d.ts +17 -17
  6. package/dist/accessApplication/createAA.js +71 -71
  7. package/dist/accessApplication/index.d.ts +1 -1
  8. package/dist/accessApplication/index.js +17 -17
  9. package/dist/crypto/cognitoAttributes.d.ts +15 -15
  10. package/dist/crypto/cognitoAttributes.js +33 -33
  11. package/dist/crypto/decryptKeys.d.ts +1 -1
  12. package/dist/crypto/decryptKeys.js +33 -33
  13. package/dist/crypto/decryptSharedData.d.ts +26 -26
  14. package/dist/crypto/decryptSharedData.js +38 -38
  15. package/dist/crypto/getAADecryptor.d.ts +16 -16
  16. package/dist/crypto/getAADecryptor.js +20 -20
  17. package/dist/crypto/helpers.d.ts +18 -18
  18. package/dist/crypto/helpers.js +26 -26
  19. package/dist/crypto/index.d.ts +4 -4
  20. package/dist/crypto/index.js +21 -21
  21. package/dist/general/conditional.d.ts +17 -17
  22. package/dist/general/conditional.js +32 -32
  23. package/dist/general/date.d.ts +2 -2
  24. package/dist/general/date.js +18 -18
  25. package/dist/general/index.d.ts +4 -4
  26. package/dist/general/index.js +20 -20
  27. package/dist/general/password.d.ts +10 -10
  28. package/dist/general/password.js +31 -31
  29. package/dist/general/types.d.ts +6 -6
  30. package/dist/general/types.js +13 -13
  31. package/dist/index.d.ts +6 -6
  32. package/dist/index.js +22 -22
  33. package/dist/rules/calculateScore.d.ts +28 -23
  34. package/dist/rules/calculateScore.js +82 -76
  35. package/dist/rules/convertInstanceToRuleInput.d.ts +3 -3
  36. package/dist/rules/convertInstanceToRuleInput.js +138 -139
  37. package/dist/rules/evaluateScoreCondition.d.ts +2 -2
  38. package/dist/rules/evaluateScoreCondition.js +44 -45
  39. package/dist/{verifications/checkVerifications.d.ts → rules/helpers/__tests__/addInfiniteThresholdBoundaries.test.d.ts} +1 -1
  40. package/dist/rules/helpers/__tests__/addInfiniteThresholdBoundaries.test.js +27 -0
  41. package/dist/{verifications/checkVerificationsNew.d.ts → rules/helpers/__tests__/checkTypeofValue.test.d.ts} +1 -1
  42. package/dist/rules/helpers/__tests__/checkTypeofValue.test.js +49 -0
  43. package/dist/{verifications/verifyCheck/util/canonicalJsonify.d.ts → rules/helpers/__tests__/getValuesFromPath.test.d.ts} +1 -1
  44. package/dist/rules/helpers/__tests__/getValuesFromPath.test.js +67 -0
  45. package/dist/rules/helpers/__tests__/thresholds.test.d.ts +1 -0
  46. package/dist/rules/helpers/__tests__/thresholds.test.js +32 -0
  47. package/dist/rules/helpers/addInfiniteThresholdBoundaries.d.ts +8 -8
  48. package/dist/rules/helpers/addInfiniteThresholdBoundaries.js +11 -11
  49. package/dist/rules/helpers/checkTypeofValue.d.ts +9 -9
  50. package/dist/rules/helpers/checkTypeofValue.js +60 -55
  51. package/dist/rules/helpers/getValuesFromPath.d.ts +3 -3
  52. package/dist/rules/helpers/getValuesFromPath.js +50 -50
  53. package/dist/rules/helpers/index.d.ts +5 -5
  54. package/dist/rules/helpers/index.js +21 -21
  55. package/dist/rules/helpers/symbols.d.ts +2 -2
  56. package/dist/rules/helpers/symbols.js +5 -5
  57. package/dist/rules/helpers/thresholds.d.ts +5 -5
  58. package/dist/rules/helpers/thresholds.js +46 -47
  59. package/dist/rules/index.d.ts +7 -7
  60. package/dist/rules/index.js +25 -25
  61. package/dist/rules/operators/__tests__/bool.test.d.ts +1 -0
  62. package/dist/rules/operators/__tests__/bool.test.js +21 -0
  63. package/dist/rules/operators/__tests__/date.test.d.ts +1 -0
  64. package/dist/rules/operators/__tests__/date.test.js +81 -0
  65. package/dist/rules/operators/__tests__/hfield.test.d.ts +1 -0
  66. package/dist/rules/operators/__tests__/hfield.test.js +38 -0
  67. package/dist/rules/operators/__tests__/hschema.test.d.ts +1 -0
  68. package/dist/rules/operators/__tests__/hschema.test.js +24 -0
  69. package/dist/rules/operators/__tests__/number.test.d.ts +1 -0
  70. package/dist/rules/operators/__tests__/number.test.js +53 -0
  71. package/dist/rules/operators/__tests__/string.test.d.ts +1 -0
  72. package/dist/rules/operators/__tests__/string.test.js +74 -0
  73. package/dist/rules/operators/bool.d.ts +2 -2
  74. package/dist/rules/operators/bool.js +17 -17
  75. package/dist/rules/operators/date.d.ts +2 -2
  76. package/dist/rules/operators/date.js +91 -91
  77. package/dist/rules/operators/hfield.d.ts +2 -2
  78. package/dist/rules/operators/hfield.js +33 -33
  79. package/dist/rules/operators/hschema.d.ts +2 -2
  80. package/dist/rules/operators/hschema.js +21 -21
  81. package/dist/rules/operators/index.d.ts +3 -3
  82. package/dist/rules/operators/index.js +11 -11
  83. package/dist/rules/operators/number.d.ts +2 -2
  84. package/dist/rules/operators/number.js +41 -41
  85. package/dist/rules/operators/string.d.ts +2 -2
  86. package/dist/rules/operators/string.js +58 -58
  87. package/dist/rules/types/config.d.ts +95 -91
  88. package/dist/rules/types/config.js +2 -2
  89. package/dist/rules/types/dataValueTypes.d.ts +19 -19
  90. package/dist/rules/types/dataValueTypes.js +4 -4
  91. package/dist/rules/types/index.d.ts +3 -3
  92. package/dist/rules/types/index.js +19 -19
  93. package/dist/rules/types/internal.d.ts +20 -20
  94. package/dist/rules/types/internal.js +2 -2
  95. package/dist/rules/validate.d.ts +6 -6
  96. package/dist/rules/validate.js +14 -14
  97. package/dist/rules/version.d.ts +1 -1
  98. package/dist/rules/version.js +5 -5
  99. package/dist/schema/expandSchema/__tests__/addLoadingTimes.test.d.ts +1 -0
  100. package/dist/schema/expandSchema/__tests__/addLoadingTimes.test.js +24 -0
  101. package/dist/schema/expandSchema/__tests__/expandSchema.test.d.ts +1 -0
  102. package/dist/schema/expandSchema/__tests__/expandSchema.test.js +95 -0
  103. package/dist/schema/expandSchema/__tests__/i18n.test.d.ts +1 -0
  104. package/dist/schema/expandSchema/__tests__/i18n.test.js +32 -0
  105. package/dist/schema/expandSchema/__tests__/maybeUseI18n.test.d.ts +1 -0
  106. package/dist/schema/expandSchema/__tests__/maybeUseI18n.test.js +98 -0
  107. package/dist/schema/expandSchema/__tests__/processSchema.test.d.ts +1 -0
  108. package/dist/schema/expandSchema/__tests__/processSchema.test.js +326 -0
  109. package/dist/schema/expandSchema/__tests__/sortSchemaProperties.test.d.ts +1 -0
  110. package/dist/schema/expandSchema/__tests__/sortSchemaProperties.test.js +182 -0
  111. package/dist/schema/expandSchema/__tests__/util.test.d.ts +1 -0
  112. package/dist/schema/expandSchema/__tests__/util.test.js +19 -0
  113. package/dist/schema/expandSchema/addLoadingTimes.d.ts +2 -0
  114. package/dist/schema/expandSchema/addLoadingTimes.js +12 -0
  115. package/dist/schema/expandSchema/constants.d.ts +2 -0
  116. package/dist/schema/expandSchema/constants.js +11 -0
  117. package/dist/schema/expandSchema/expandSchema.d.ts +7 -0
  118. package/dist/schema/expandSchema/expandSchema.js +19 -0
  119. package/dist/schema/expandSchema/i18n.d.ts +5 -0
  120. package/dist/schema/expandSchema/i18n.js +20 -0
  121. package/dist/schema/expandSchema/index.d.ts +3 -0
  122. package/dist/schema/expandSchema/index.js +21 -0
  123. package/dist/schema/expandSchema/maybeUseI18n.d.ts +2 -0
  124. package/dist/schema/expandSchema/maybeUseI18n.js +40 -0
  125. package/dist/schema/expandSchema/processSchema.d.ts +4 -0
  126. package/dist/schema/expandSchema/processSchema.js +94 -0
  127. package/dist/schema/expandSchema/removePrivateFields.d.ts +119 -0
  128. package/dist/schema/expandSchema/removePrivateFields.js +15 -0
  129. package/dist/schema/expandSchema/sortSchemaProperties.d.ts +21 -0
  130. package/dist/schema/expandSchema/sortSchemaProperties.js +40 -0
  131. package/dist/schema/expandSchema/unwrapSchema.d.ts +6 -0
  132. package/dist/schema/expandSchema/unwrapSchema.js +7 -0
  133. package/dist/schema/expandSchema/util.d.ts +6 -0
  134. package/dist/schema/expandSchema/util.js +15 -0
  135. package/dist/schema/index.d.ts +2 -1
  136. package/dist/schema/index.js +18 -17
  137. package/dist/schema/labels.d.ts +2 -2
  138. package/dist/schema/labels.js +20 -20
  139. package/dist/util/canonicalJsonify.d.ts +1 -1
  140. package/dist/util/canonicalJsonify.js +50 -50
  141. package/dist/util/handleResponse.d.ts +1 -1
  142. package/dist/util/handleResponse.js +21 -21
  143. package/dist/util/index.d.ts +2 -2
  144. package/dist/util/index.js +18 -18
  145. package/dist/verifications/cleanInstance.d.ts +9 -9
  146. package/dist/verifications/cleanInstance.js +15 -15
  147. package/dist/verifications/getPOVerification.d.ts +19 -16
  148. package/dist/verifications/getPOVerification.js +105 -94
  149. package/dist/verifications/getVerifiedBy.d.ts +1 -1
  150. package/dist/verifications/getVerifiedBy.js +19 -19
  151. package/dist/verifications/index.d.ts +5 -5
  152. package/dist/verifications/index.js +21 -21
  153. package/dist/verifications/maybeRereference.d.ts +1 -1
  154. package/dist/verifications/maybeRereference.js +10 -10
  155. package/dist/verifications/safeHarbour.d.ts +20 -20
  156. package/dist/verifications/safeHarbour.js +67 -74
  157. package/dist/verifications/verifyCheck/__tests__/getOwnRealVerifications.test.d.ts +1 -0
  158. package/dist/verifications/verifyCheck/__tests__/getOwnRealVerifications.test.js +152 -0
  159. package/dist/verifications/verifyCheck/__tests__/getSomeoneElsesRealVerifications.test.d.ts +1 -0
  160. package/dist/verifications/verifyCheck/__tests__/getSomeoneElsesRealVerifications.test.js +205 -0
  161. package/dist/verifications/verifyCheck/getOwnRealVerifications.d.ts +13 -13
  162. package/dist/verifications/verifyCheck/getOwnRealVerifications.js +66 -64
  163. package/dist/verifications/verifyCheck/getSomeoneElsesRealVerifications.d.ts +19 -19
  164. package/dist/verifications/verifyCheck/getSomeoneElsesRealVerifications.js +72 -72
  165. package/dist/verifications/verifyCheck/index.d.ts +3 -3
  166. package/dist/verifications/verifyCheck/index.js +21 -21
  167. package/dist/verifications/verifyCheck/operations/__tests__/checkOwnVerification.test.d.ts +1 -0
  168. package/dist/verifications/verifyCheck/operations/__tests__/checkOwnVerification.test.js +91 -0
  169. package/dist/verifications/verifyCheck/operations/__tests__/checkSomeoneElsesVerifications.test.d.ts +1 -0
  170. package/dist/verifications/verifyCheck/operations/__tests__/checkSomeoneElsesVerifications.test.js +49 -0
  171. package/dist/verifications/verifyCheck/operations/__tests__/sampleBundle.json +43 -0
  172. package/dist/verifications/verifyCheck/operations/checkOwnVerification.d.ts +15 -15
  173. package/dist/verifications/verifyCheck/operations/checkOwnVerification.js +39 -39
  174. package/dist/verifications/verifyCheck/operations/checkSomeoneElsesVerifications.d.ts +1 -1
  175. package/dist/verifications/verifyCheck/operations/checkSomeoneElsesVerifications.js +16 -16
  176. package/dist/verifications/verifyCheck/operations/index.d.ts +2 -2
  177. package/dist/verifications/verifyCheck/operations/index.js +18 -18
  178. package/package.json +13 -10
  179. package/dist/rules/helpers/getLhsTypeofValue.d.ts +0 -0
  180. package/dist/rules/helpers/getLhsTypeofValue.js +0 -1
  181. package/dist/rules/helpers/getValueFromPath.d.ts +0 -2
  182. package/dist/rules/helpers/getValueFromPath.js +0 -35
  183. package/dist/rules/helpers/rebuildInfiniteValues.d.ts +0 -3
  184. package/dist/rules/helpers/rebuildInfiniteValues.js +0 -6
  185. package/dist/rules/isScoreResultValid.d.ts +0 -2
  186. package/dist/rules/isScoreResultValid.js +0 -9
  187. package/dist/rules/operators/array.d.ts +0 -2
  188. package/dist/rules/operators/array.js +0 -74
  189. package/dist/rules/types/operators.d.ts +0 -19
  190. package/dist/rules/types/operators.js +0 -2
  191. package/dist/rules/types/score.d.ts +0 -50
  192. package/dist/rules/types/score.js +0 -2
  193. package/dist/util/conditional.d.ts +0 -7
  194. package/dist/util/conditional.js +0 -15
  195. package/dist/util/hash.js +0 -11
  196. package/dist/verifications/checkSingleVerification.d.ts +0 -9
  197. package/dist/verifications/checkSingleVerification.js +0 -29
  198. package/dist/verifications/checkVerifications.js +0 -16
  199. package/dist/verifications/checkVerificationsNew.js +0 -16
  200. package/dist/verifications/getOwnRealVerifications.d.ts +0 -14
  201. package/dist/verifications/getOwnRealVerifications.js +0 -64
  202. package/dist/verifications/getRealVerifications.d.ts +0 -22
  203. package/dist/verifications/getRealVerifications.js +0 -71
  204. package/dist/verifications/verifyCheck/util/canonicalJsonify.js +0 -48
  205. package/dist/verifications/verifyCheck/util/getValuesForAField.d.ts +0 -2
  206. package/dist/verifications/verifyCheck/util/getValuesForAField.js +0 -9
  207. package/dist/verifications/verifyCheck/util/index.d.ts +0 -2
  208. package/dist/verifications/verifyCheck/util/index.js +0 -14
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ var __rest = (this && this.__rest) || function (s, e) {
3
+ var t = {};
4
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
5
+ t[p] = s[p];
6
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
7
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
8
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
9
+ t[p[i]] = s[p[i]];
10
+ }
11
+ return t;
12
+ };
13
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ exports.maybeUseI18n = void 0;
15
+ const ramda_1 = require("ramda");
16
+ const i18n_1 = require("./i18n");
17
+ const getGroupNames = (0, ramda_1.pipe)(ramda_1.toPairs,
18
+ // @ts-expect-error
19
+ (0, ramda_1.filter)(([key]) => key.startsWith("group:")),
20
+ // @ts-expect-error
21
+ (0, ramda_1.map)(([key, value]) => [key.replace("group:", ""), value.title]), ramda_1.fromPairs);
22
+ const maybeUseI18n = (schema, userLocales) => {
23
+ var _a;
24
+ if (!schema.i18n)
25
+ return schema;
26
+ // try to find an exact match in schema.i18n. The fallback: if the schema
27
+ // only has en-nz, but the user speaks en-US, then use en-nz.
28
+ const localeToUse = (0, i18n_1.findSuitableLocale)(Object.keys(schema.i18n), userLocales);
29
+ // the schema has an i18n property, but it doesn't include a lang that the user speaks
30
+ if (!localeToUse)
31
+ return schema;
32
+ const _b = schema.i18n[localeToUse], { $schema } = _b, translations = __rest(_b, ["$schema"]);
33
+ return Object.assign(Object.assign(Object.assign(Object.assign({}, schema), { clientLocale: localeToUse }), $schema), { group_title: schema.schema_group &&
34
+ (((_a = translations[schema.schema_group]) === null || _a === void 0 ? void 0 : _a.title_plural) || schema.schema_group),
35
+ // add a `groupNames` property to the schema
36
+ groupNames: getGroupNames(translations),
37
+ // maybe apply translations per field
38
+ properties: (0, ramda_1.mapObjIndexed)((field, fieldName) => (Object.assign(Object.assign({}, field), translations[fieldName])), schema.properties) });
39
+ };
40
+ exports.maybeUseI18n = maybeUseI18n;
@@ -0,0 +1,4 @@
1
+ import { Schema, WrappedSchema } from "@raytio/types";
2
+ export declare const processSchema: (schema: WrappedSchema["schema"] & {
3
+ version: string;
4
+ }, allUnexpandedSchemas: WrappedSchema[]) => Schema;
@@ -0,0 +1,94 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.processSchema = void 0;
4
+ const ramda_1 = require("ramda");
5
+ const constants_1 = require("./constants");
6
+ const sortSchemaProperties_1 = require("./sortSchemaProperties");
7
+ const util_1 = require("./util");
8
+ const convertIfEnum = (0, ramda_1.mapObjIndexed)(y => Object.values(y)[0]);
9
+ const processSchema = (schema, allUnexpandedSchemas) => {
10
+ var _a, _b, _c, _d, _e, _f, _g;
11
+ const expandField = (property, key) => {
12
+ var _a, _b;
13
+ if (!property.allOf)
14
+ return Object.assign(Object.assign({}, property), { $prop: key });
15
+ // this property references another schema
16
+ const [{ $ref }, custom] = property.allOf;
17
+ if (!$ref)
18
+ throw new Error("allOf missing $ref");
19
+ const subSchemaName = (0, sortSchemaProperties_1.getNidFromUrn)((_a = schema.definitions) === null || _a === void 0 ? void 0 : _a[$ref.split("/")[2]].$ref);
20
+ if (!subSchemaName)
21
+ throw new Error("Invalid schema");
22
+ const subSchema = (_b = allUnexpandedSchemas.find(s => s.name === subSchemaName)) === null || _b === void 0 ? void 0 : _b.schema;
23
+ if (!subSchema) {
24
+ throw new Error(`Could not resolve subschema '${subSchemaName}'`);
25
+ }
26
+ return (0, ramda_1.pipe)((0, ramda_1.dissoc)("properties"), // subSchema don't have properties so remove
27
+ (0, ramda_1.mergeWith)((main, sub) => {
28
+ // merge custom props in; concatting arrays, but picking
29
+ // the main value only for strings.
30
+ if (typeof main === "string")
31
+ return main;
32
+ return [...main, ...sub];
33
+ }, custom), (f) => (Object.assign(Object.assign({}, f), { $ref: subSchemaName })), // add $ref to the subSchema
34
+ // add $ref to the subSchema
35
+ field => (Object.assign(Object.assign({}, field), { $prop: key })))(subSchema);
36
+ };
37
+ const exandedProps = (0, ramda_1.mapObjIndexed)(expandField, schema.properties);
38
+ const allOfRequired = [];
39
+ const globallyReferencedSubSchema = (_b = (_a = schema.allOf) === null || _a === void 0 ? void 0 : _a.reduce((ac, { $ref }) => {
40
+ var _a, _b;
41
+ // TODO: should this block of code re-use `expandField`?
42
+ if (!$ref)
43
+ return ac; // this allOf entry is not a reference
44
+ const subSchemaName = (0, sortSchemaProperties_1.getNidFromUrn)((_a = schema.definitions) === null || _a === void 0 ? void 0 : _a[$ref.split("/")[2]].$ref);
45
+ if (!subSchemaName)
46
+ throw new Error("Invalid schema");
47
+ const subSchema = (_b = allUnexpandedSchemas.find(s => s.name === subSchemaName)) === null || _b === void 0 ? void 0 : _b.schema;
48
+ if (!subSchema) {
49
+ throw new Error(`Could not resolve subschema '${subSchemaName}'`);
50
+ }
51
+ if (subSchema.required) {
52
+ // eslint-disable-next-line fp/no-mutating-methods
53
+ allOfRequired.push(...subSchema.required);
54
+ }
55
+ return Object.assign(Object.assign({}, ac), (0, ramda_1.mapObjIndexed)((field, fieldName) => (Object.assign(Object.assign({}, field), { $prop: fieldName })), subSchema.properties));
56
+ }, {})) !== null && _b !== void 0 ? _b : {};
57
+ // IF properties THEN required
58
+ const conditionallyRequired = ((_c = schema.allOf) === null || _c === void 0 ? void 0 : _c.filter(x => { var _a, _b; return ((_a = x.if) === null || _a === void 0 ? void 0 : _a.properties) && ((_b = x.then) === null || _b === void 0 ? void 0 : _b.required); }).flatMap(x => x.then.required.map(field => ({
59
+ field: field,
60
+ if: convertIfEnum(x.if.properties),
61
+ })))) || [];
62
+ // IF properties THEN properties
63
+ const conditionalProperties = ((_d = schema.allOf) === null || _d === void 0 ? void 0 : _d.filter(x => { var _a, _b; return ((_a = x.if) === null || _a === void 0 ? void 0 : _a.properties) && ((_b = x.then) === null || _b === void 0 ? void 0 : _b.properties); }).reduce((ac, ifThen) => {
64
+ const props = Object.fromEntries(Object.entries(ifThen.then.properties).map(([k, v]) => {
65
+ const iff = convertIfEnum(ifThen.if.properties);
66
+ return [
67
+ `${k} <=> ${(0, util_1.getConditionId)(iff)}`,
68
+ Object.assign(Object.assign({}, expandField(v, k)), { if: iff, $prop: k }),
69
+ ];
70
+ }));
71
+ return Object.assign(Object.assign({}, ac), props);
72
+ }, {})) || {};
73
+ // IF properties THEN verifiable
74
+ const conditionallyVerifiable = ((_e = schema.allOf) === null || _e === void 0 ? void 0 : _e.filter(x => { var _a, _b; return ((_a = x.if) === null || _a === void 0 ? void 0 : _a.properties) && ((_b = x.then) === null || _b === void 0 ? void 0 : _b.verified_fields); }).flatMap(x => x.then.verified_fields.map(field => ({
75
+ field: field,
76
+ if: convertIfEnum(x.if.properties),
77
+ })))) || [];
78
+ const verifiedFields = (0, ramda_1.uniq)([
79
+ ...(schema.verified_fields || []),
80
+ ...conditionallyVerifiable,
81
+ ]);
82
+ const shouldBeConditionallyVerified = (_f = schema.allOf) === null || _f === void 0 ? void 0 : _f.some(x => { var _a, _b; return (_b = (_a = x.then) === null || _a === void 0 ? void 0 : _a.tags) === null || _b === void 0 ? void 0 : _b.includes("action:verify"); });
83
+ return Object.assign(Object.assign({}, schema), { properties: Object.assign(Object.assign(Object.assign({}, exandedProps), globallyReferencedSubSchema), conditionalProperties), required: (0, ramda_1.uniq)([
84
+ ...(schema.required || []),
85
+ ...allOfRequired,
86
+ ...conditionallyRequired,
87
+ ]),
88
+ // important that it's undefined instead of empty array so that it's falsy
89
+ verified_fields: verifiedFields.length ? verifiedFields : undefined, tags: (0, ramda_1.uniq)([
90
+ ...(schema.tags || []),
91
+ ...(shouldBeConditionallyVerified ? ["action:verify"] : []),
92
+ ]), isProfileSchema: !constants_1.TAG_DENYLIST.some(tag => { var _a; return (_a = schema.tags) === null || _a === void 0 ? void 0 : _a.includes(tag); }) && !!schema.title, isSpSchema: ((_g = schema.tags) === null || _g === void 0 ? void 0 : _g.includes("type:service_provider")) || false });
93
+ };
94
+ exports.processSchema = processSchema;
@@ -0,0 +1,119 @@
1
+ import { Schema } from "@raytio/types";
2
+ export declare const removePrivateFields: (schema: Schema) => {
3
+ properties: Record<string, Omit<import("@raytio/types").SchemaField, "$id" | "allOf" | "$schema" | "definitions">>;
4
+ type?: import("@raytio/types").DataTypes | undefined;
5
+ name: string;
6
+ title: string;
7
+ description: string;
8
+ title_plural?: string | undefined;
9
+ schema_group?: string | undefined;
10
+ tags?: import("@raytio/types").SchemaTag[] | undefined;
11
+ i18n?: {
12
+ [locale: string]: {
13
+ [fieldNameOrGroupName: string]: import("@raytio/types").ServerSchemaField & {
14
+ title_plural?: string | undefined;
15
+ };
16
+ $schema: {
17
+ title: string;
18
+ title_plural?: string | undefined;
19
+ description?: string | undefined;
20
+ };
21
+ $loading_extract: {
22
+ title: string;
23
+ };
24
+ $loading_verify: {
25
+ title: string;
26
+ };
27
+ $loading_save: {
28
+ title: string;
29
+ };
30
+ $loading_update: {
31
+ title: string;
32
+ };
33
+ $loading_upload: {
34
+ title: string;
35
+ };
36
+ $loading_create_sub_obj: {
37
+ title: string;
38
+ };
39
+ $loading_permission: {
40
+ title: string;
41
+ };
42
+ $loading_link_to_person: {
43
+ title: string;
44
+ };
45
+ $loading_delete_pending_ver: {
46
+ title: string;
47
+ };
48
+ $loading_pending_ver_resubmit: {
49
+ title: string;
50
+ };
51
+ $loading_long_verification_message: {
52
+ title?: string | undefined;
53
+ description?: string | undefined;
54
+ };
55
+ };
56
+ } | undefined;
57
+ relationships?: {
58
+ relationship_name: string;
59
+ direction: "from";
60
+ type: string;
61
+ required_relationship?: boolean | undefined;
62
+ oneOf?: string[] | undefined;
63
+ anyOf?: string[] | undefined;
64
+ multiple?: boolean | undefined;
65
+ properties?: {
66
+ [fieldName: string]: import("@raytio/types").SchemaField;
67
+ } | undefined;
68
+ required?: string[] | undefined;
69
+ }[] | undefined;
70
+ display?: {
71
+ head_main?: {
72
+ fields: string[];
73
+ format?: string | undefined;
74
+ } | undefined;
75
+ head_sub?: {
76
+ fields: string[];
77
+ format?: string | undefined;
78
+ } | undefined;
79
+ expand?: {
80
+ fields: string[];
81
+ label: string;
82
+ }[] | undefined;
83
+ } | undefined;
84
+ onboard_properties?: {
85
+ profile_objects?: {
86
+ schema_name: string;
87
+ properties: Record<string, unknown>;
88
+ }[] | undefined;
89
+ relationships?: {
90
+ from: string;
91
+ to: string;
92
+ type: string;
93
+ properties?: Record<string, string> | undefined;
94
+ }[] | undefined;
95
+ organizations?: {
96
+ properties: import("@raytio/types").Organization;
97
+ access_applications?: {
98
+ properties: Omit<import("@raytio/types").AA, "org_id">;
99
+ links?: {
100
+ description: string;
101
+ wizardConfig: Omit<import("@raytio/types").WizardConfig, "a_id">;
102
+ }[] | undefined;
103
+ }[] | undefined;
104
+ }[] | undefined;
105
+ return_to?: string | undefined;
106
+ } | undefined;
107
+ group_title?: string | undefined;
108
+ verified_fields?: (string | import("@raytio/types").ConditionallyRequired)[] | undefined;
109
+ required?: (string | import("@raytio/types").ConditionallyRequired)[] | undefined;
110
+ wasExpandedByClient?: boolean | undefined;
111
+ start_date?: string | undefined;
112
+ end_date?: string | undefined;
113
+ groupNames?: Record<string, string> | undefined;
114
+ clientLocale?: string | undefined;
115
+ version: string;
116
+ timing?: Record<"extract" | "live_person" | "verify_pending_delay", number> | undefined;
117
+ isProfileSchema?: boolean | undefined;
118
+ isSpSchema?: boolean | undefined;
119
+ };
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.removePrivateFields = void 0;
4
+ const ramda_1 = require("ramda");
5
+ /** we don't expose these to the rest of the client to avoid confusion or misusing them */
6
+ const PRIVATE_FIELDS = [
7
+ "$id",
8
+ "$schema",
9
+ "definitions",
10
+ "allOf",
11
+ ];
12
+ const removePrivateFields = (schema) => (Object.assign(Object.assign({}, (0, ramda_1.omit)(PRIVATE_FIELDS, schema)), {
13
+ // and from each field in `properties`
14
+ properties: (0, ramda_1.mapObjIndexed)((0, ramda_1.omit)(PRIVATE_FIELDS), schema.properties) }));
15
+ exports.removePrivateFields = removePrivateFields;
@@ -0,0 +1,21 @@
1
+ import { NId, SchemaField, Urn } from "@raytio/types";
2
+ /** two overloads - if you provide undefined, you might get undefined back */
3
+ export declare const getNidFromUrn: {
4
+ (urn: Urn): NId;
5
+ (urn: Urn | undefined): NId | undefined;
6
+ };
7
+ type Key = string;
8
+ type Tag = string;
9
+ type Section = {
10
+ title: Tag;
11
+ items: SchemaField[];
12
+ };
13
+ /** @ignore */
14
+ export declare const NO_TAG = "-notag-common";
15
+ /**
16
+ * Schema properties are an object, so they need to be converted into an
17
+ * array, grouped by the group tag, and then sorted based on the `priority`
18
+ * attribute within their group.
19
+ */
20
+ export declare function sortSchemaProperties(properties: Record<Key, SchemaField>): Section[];
21
+ export {};
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.sortSchemaProperties = exports.NO_TAG = exports.getNidFromUrn = void 0;
4
+ const ramda_1 = require("ramda");
5
+ /** two overloads - if you provide undefined, you might get undefined back */
6
+ exports.getNidFromUrn = ((urn) => urn === null || urn === void 0 ? void 0 : urn.split(":")[2]);
7
+ /** @ignore */
8
+ exports.NO_TAG = "-notag-common";
9
+ /**
10
+ * Schema properties are an object, so they need to be converted into an
11
+ * array, grouped by the group tag, and then sorted based on the `priority`
12
+ * attribute within their group.
13
+ */
14
+ function sortSchemaProperties(properties) {
15
+ const tagToSection = (field) => {
16
+ var _a;
17
+ // if there is a tag prefixed with `group:`, then use it
18
+ const groupTags = [
19
+ ...new Set((_a = field.tags) === null || _a === void 0 ? void 0 : _a.filter(tag => tag.startsWith("group:"))),
20
+ ];
21
+ if (groupTags === null || groupTags === void 0 ? void 0 : groupTags.length) {
22
+ const group = groupTags[0].replace("group:", "");
23
+ return group;
24
+ }
25
+ // if there is no group tag, put all those fields together in a group called "common"
26
+ return exports.NO_TAG;
27
+ };
28
+ const assocAsArray = (acum, curr) => (0, ramda_1.mergeWithKey)((k, a, b) => [...a, ...b], acum, curr);
29
+ const keyedByTag = Object.values((0, ramda_1.mapObjIndexed)((field, fieldName) => ({
30
+ // add prop anyway, just incase it's missing
31
+ [tagToSection(field)]: Object.assign(Object.assign({}, field), { $prop: fieldName }),
32
+ }), properties));
33
+ const keyedByTagSingleton = (0, ramda_1.map)(a => ({ [Object.keys(a)[0]]: [a[Object.keys(a)[0]]] }), keyedByTag);
34
+ const unsorted = (0, ramda_1.reduce)(assocAsArray, {}, keyedByTagSingleton);
35
+ const objWithSortedChildren = (0, ramda_1.mapObjIndexed)(fieldObjList => (0, ramda_1.sort)((a, b) => { var _a, _b; return ((_a = a.priority) !== null && _a !== void 0 ? _a : 0) - ((_b = b.priority) !== null && _b !== void 0 ? _b : 0); }, fieldObjList), unsorted);
36
+ // defined seperately because typescript gets confused
37
+ const unsortedFinal = Object.entries(objWithSortedChildren).map(([title, items]) => ({ title, items: (0, ramda_1.uniqBy)(f => f.$prop, items) }));
38
+ return (0, ramda_1.sortBy)(x => x.items[0].priority, unsortedFinal); // sort by priority of first child
39
+ }
40
+ exports.sortSchemaProperties = sortSchemaProperties;
@@ -0,0 +1,6 @@
1
+ import { WrappedSchema } from "@raytio/types";
2
+ export declare function unwrapSchema(wrapped: WrappedSchema): WrappedSchema["schema"] & {
3
+ version: string;
4
+ start_date?: string;
5
+ end_date?: string;
6
+ };
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.unwrapSchema = void 0;
4
+ function unwrapSchema(wrapped) {
5
+ return Object.assign(Object.assign({}, wrapped.schema), { name: wrapped.name, start_date: wrapped.start_date, end_date: wrapped.end_date, version: wrapped.version });
6
+ }
7
+ exports.unwrapSchema = unwrapSchema;
@@ -0,0 +1,6 @@
1
+ /**
2
+ * this is NOT meant to be machine readable, just unique.
3
+ * and it should make logical sense to a human. It is LOSSY,
4
+ * e.g. null and '' (empty string) become the same thing.
5
+ */
6
+ export declare const getConditionId: (iff: Record<string, string[]>) => string;
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ // this file is not exposed to the rest of the app, it's util functions
3
+ // used by other schema helpers
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ exports.getConditionId = void 0;
6
+ const ramda_1 = require("ramda");
7
+ // the sorting algorithm isn't important, as long as it's consistent
8
+ const sort = (0, ramda_1.sortBy)((x) => x);
9
+ /**
10
+ * this is NOT meant to be machine readable, just unique.
11
+ * and it should make logical sense to a human. It is LOSSY,
12
+ * e.g. null and '' (empty string) become the same thing.
13
+ */
14
+ const getConditionId = (iff) => sort(Object.entries(iff).map(([kk, vv]) => `${kk}=${sort(vv).join("|")}`)).join(" & ");
15
+ exports.getConditionId = getConditionId;
@@ -1 +1,2 @@
1
- export * from "./labels";
1
+ export * from "./expandSchema";
2
+ export * from "./labels";
@@ -1,17 +1,18 @@
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("./labels"), exports);
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("./expandSchema"), exports);
18
+ __exportStar(require("./labels"), exports);
@@ -1,2 +1,2 @@
1
- /** Finds the label (on a profile object) which is the schema name */
2
- export declare const findSchemaLabel: (labels: string[] | undefined) => string | undefined;
1
+ /** Finds the label (on a profile object) which is the schema name */
2
+ export declare const findSchemaLabel: (labels: string[] | undefined) => string | undefined;
@@ -1,20 +1,20 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.findSchemaLabel = void 0;
4
- /**
5
- * every possible label should be listed here, beacuse the client
6
- * finds the schemaName by searching the list of labels for the
7
- * first one that is not in this list
8
- * @internal
9
- */
10
- const LABELS_DENYLIST = [
11
- "Document",
12
- "ProfileObject",
13
- "ApplicationObject",
14
- "ServiceProvider",
15
- "receiverCreated",
16
- ];
17
- /** Finds the label (on a profile object) which is the schema name */
18
- const findSchemaLabel = (labels) => labels === null || labels === void 0 ? void 0 : labels.find(label => !LABELS_DENYLIST.includes(label) &&
19
- !label.startsWith("related_service_provider:"));
20
- exports.findSchemaLabel = findSchemaLabel;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.findSchemaLabel = void 0;
4
+ /**
5
+ * every possible label should be listed here, because the client
6
+ * finds the schemaName by searching the list of labels for the
7
+ * first one that is not in this list
8
+ * @internal
9
+ */
10
+ const LABELS_DENYLIST = [
11
+ "Document",
12
+ "ProfileObject",
13
+ "ApplicationObject",
14
+ "ServiceProvider",
15
+ "receiverCreated",
16
+ ];
17
+ /** Finds the label (on a profile object) which is the schema name */
18
+ const findSchemaLabel = (labels) => labels === null || labels === void 0 ? void 0 : labels.find(label => !LABELS_DENYLIST.includes(label) &&
19
+ !label.startsWith("related_service_provider:"));
20
+ exports.findSchemaLabel = findSchemaLabel;
@@ -1 +1 @@
1
- export {};
1
+ export {};
@@ -1,50 +1,50 @@
1
- "use strict";
2
- /* eslint-disable fp/no-mutating-methods, fp/no-mutation, fp/no-let, prefer-reflect */
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.canonicalJsonify = void 0;
5
- const isObject = (a) => Object.prototype.toString.call(a) === "[object Object]"; // TODO: wtf ?
6
- const REGEX =
7
- // eslint-disable-next-line no-control-regex
8
- /[\u0000-\u001F]|"|\\|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF]/g;
9
- const SLASH_ESC = {
10
- "\b": "\\b",
11
- "\t": "\\t",
12
- "\n": "\\n",
13
- "\f": "\\f",
14
- "\r": "\\r",
15
- '"': '\\"',
16
- "\\": "\\\\",
17
- };
18
- const replacer = (char) => SLASH_ESC[char] ||
19
- `\\u${char.charCodeAt(0).toString(16).toUpperCase().padStart(4, "0")}`;
20
- function copyObjectWithSortedKeys(object) {
21
- if (isObject(object)) {
22
- return `{${Object.keys(object)
23
- .sort()
24
- .map(key => `"${key}":${copyObjectWithSortedKeys(object[key])}`)
25
- .join(",")}}`;
26
- }
27
- if (Array.isArray(object)) {
28
- return `[${object.map(copyObjectWithSortedKeys).join(",")}]`;
29
- }
30
- if (typeof object === "number" && object % 1 !== 0) {
31
- if (Number.isNaN(object) || !Number.isFinite(object))
32
- return "null";
33
- // float
34
- const exponent = Math.floor(Math.log10(Math.abs(object)));
35
- let mantissa = `${object / 10 ** exponent}`;
36
- if (!mantissa.includes("."))
37
- mantissa += ".0";
38
- return `${mantissa}E${exponent}`;
39
- }
40
- if (typeof object === "string")
41
- return `"${object.replace(REGEX, replacer)}"`;
42
- return object; // bool or int
43
- }
44
- /**
45
- * @internal
46
- * spec compliant, and matches
47
- * https://gitlab.com/raytio/mono/-/blob/devo/common/signing/signing/canonical_json.py
48
- */
49
- const canonicalJsonify = (object) => `${copyObjectWithSortedKeys(object)}`;
50
- exports.canonicalJsonify = canonicalJsonify;
1
+ "use strict";
2
+ /* eslint-disable fp/no-mutating-methods, fp/no-mutation, prefer-reflect */
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.canonicalJsonify = void 0;
5
+ const isObject = (a) => Object.prototype.toString.call(a) === "[object Object]"; // TODO: wtf ?
6
+ const REGEX =
7
+ // eslint-disable-next-line no-control-regex
8
+ /[\u0000-\u001F]|"|\\|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF]/g;
9
+ const SLASH_ESC = {
10
+ "\b": "\\b",
11
+ "\t": "\\t",
12
+ "\n": "\\n",
13
+ "\f": "\\f",
14
+ "\r": "\\r",
15
+ '"': '\\"',
16
+ "\\": "\\\\",
17
+ };
18
+ const replacer = (char) => SLASH_ESC[char] ||
19
+ `\\u${char.charCodeAt(0).toString(16).toUpperCase().padStart(4, "0")}`;
20
+ function copyObjectWithSortedKeys(object) {
21
+ if (isObject(object)) {
22
+ return `{${Object.keys(object)
23
+ .sort()
24
+ .map(key => `"${key}":${copyObjectWithSortedKeys(object[key])}`)
25
+ .join(",")}}`;
26
+ }
27
+ if (Array.isArray(object)) {
28
+ return `[${object.map(copyObjectWithSortedKeys).join(",")}]`;
29
+ }
30
+ if (typeof object === "number" && object % 1 !== 0) {
31
+ if (Number.isNaN(object) || !Number.isFinite(object))
32
+ return "null";
33
+ // float
34
+ const exponent = Math.floor(Math.log10(Math.abs(object)));
35
+ let mantissa = `${object / 10 ** exponent}`;
36
+ if (!mantissa.includes("."))
37
+ mantissa += ".0";
38
+ return `${mantissa}E${exponent}`;
39
+ }
40
+ if (typeof object === "string")
41
+ return `"${object.replace(REGEX, replacer)}"`;
42
+ return object; // bool or int
43
+ }
44
+ /**
45
+ * @internal
46
+ * spec compliant, and matches
47
+ * https://gitlab.com/raytio/mono/-/blob/devo/common/signing/signing/canonical_json.py
48
+ */
49
+ const canonicalJsonify = (object) => `${copyObjectWithSortedKeys(object)}`;
50
+ exports.canonicalJsonify = canonicalJsonify;
@@ -1 +1 @@
1
- export {};
1
+ export {};
@@ -1,21 +1,21 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.handleResponse = void 0;
4
- /**
5
- * @internal
6
- * Throws an error if the API request fails.
7
- * Drop-in replacement for `response.json()`
8
- * @example
9
- * ```
10
- * const json = await fetch(...).then(handleResponse)
11
- * ```
12
- */
13
- const handleResponse = async (response) => {
14
- const json = await response.json();
15
- // json could be a string | number
16
- if (typeof json === "object" && "message" in json) {
17
- throw new Error(json.message);
18
- }
19
- return json;
20
- };
21
- exports.handleResponse = handleResponse;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.handleResponse = void 0;
4
+ /**
5
+ * @internal
6
+ * Throws an error if the API request fails.
7
+ * Drop-in replacement for `response.json()`
8
+ * @example
9
+ * ```
10
+ * const json = await fetch(...).then(handleResponse)
11
+ * ```
12
+ */
13
+ const handleResponse = async (response) => {
14
+ const json = await response.json();
15
+ // json could be a string | number
16
+ if (typeof json === "object" && json && "message" in json) {
17
+ throw new Error(json.message);
18
+ }
19
+ return json;
20
+ };
21
+ exports.handleResponse = handleResponse;
@@ -1,2 +1,2 @@
1
- export * from "./canonicalJsonify";
2
- export * from "./handleResponse";
1
+ export * from "./canonicalJsonify";
2
+ export * from "./handleResponse";