@wise/dynamic-flow-client 3.3.2 → 3.4.0-experimental-9862ccf

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 (168) hide show
  1. package/build/common/httpClientContext/HttpClientContext.js +35 -0
  2. package/build/common/httpClientContext/index.js +1 -0
  3. package/build/common/makeHttpClient/index.js +1 -0
  4. package/build/common/makeHttpClient/makeHttpClient.js +34 -0
  5. package/build/common/messages/generic-error.messages.js +18 -0
  6. package/build/common/messages/help.messages.js +8 -0
  7. package/build/common/messages/multi-file-upload.messages.js +18 -0
  8. package/build/common/messages/paragraph.messages.js +13 -0
  9. package/build/common/messages/repeatable.messages.js +23 -0
  10. package/build/common/messages/validation.array.messages.js +13 -0
  11. package/build/common/messages/validation.messages.js +53 -0
  12. package/build/common/utils/api-utils.js +4 -0
  13. package/build/legacy/common/constants/DateMode.js +4 -0
  14. package/build/legacy/common/constants/FeatureName.js +4 -0
  15. package/build/legacy/common/constants/FormControlType.js +21 -0
  16. package/build/legacy/common/constants/MonthFormat.js +4 -0
  17. package/build/legacy/common/constants/Size.js +7 -0
  18. package/build/legacy/common/constants/index.js +4 -0
  19. package/build/legacy/common/contexts/dynamicFlowContexts/DynamicFlowContexts.js +36 -0
  20. package/build/legacy/common/contexts/dynamicFlowContexts/usePendingPromiseCounter.js +13 -0
  21. package/build/legacy/common/contexts/eventsContext/EventsContext.js +38 -0
  22. package/build/legacy/common/contexts/featureContext/FeatureContext.js +22 -0
  23. package/build/legacy/common/contexts/index.js +3 -0
  24. package/build/legacy/common/contexts/logContext/LogContext.js +44 -0
  25. package/build/legacy/common/hooks/index.js +7 -0
  26. package/build/legacy/common/hooks/useDebouncedFunction/useDebouncedFunction.js +9 -0
  27. package/build/legacy/common/hooks/useExternal/useExternal.js +15 -0
  28. package/build/legacy/common/hooks/useExternalStepPolling/useExternalStepPolling.js +70 -0
  29. package/build/legacy/common/hooks/usePersistAsync/usePersistAsync.js +172 -0
  30. package/build/legacy/common/hooks/usePolling/usePolling.js +51 -0
  31. package/build/legacy/common/hooks/usePrevious/usePrevious.js +8 -0
  32. package/build/legacy/common/hooks/useStepPolling/useStepPolling.js +43 -0
  33. package/build/legacy/common/messages.js +8 -0
  34. package/build/legacy/common/utils/api-utils.js +6 -0
  35. package/build/legacy/common/utils/date-utils.js +22 -0
  36. package/build/legacy/common/utils/debounce.js +38 -0
  37. package/build/legacy/common/utils/file-utils.js +45 -0
  38. package/build/legacy/common/utils/id-utils.js +5 -0
  39. package/build/legacy/common/utils/index.js +11 -0
  40. package/build/legacy/common/utils/is-equal.js +21 -0
  41. package/build/legacy/common/utils/misc-utils.js +4 -0
  42. package/build/legacy/common/utils/mobile-utils.js +23 -0
  43. package/build/legacy/common/utils/model-utils.js +33 -0
  44. package/build/legacy/common/utils/schema-utils.js +97 -0
  45. package/build/legacy/common/utils/step-utils.js +32 -0
  46. package/build/legacy/common/validators/index.js +5 -0
  47. package/build/legacy/common/validators/models/model-utils.js +119 -0
  48. package/build/legacy/common/validators/models/model-validators.js +62 -0
  49. package/build/legacy/common/validators/schemas/schema-validators.js +101 -0
  50. package/build/legacy/common/validators/types/type-validators.js +14 -0
  51. package/build/legacy/common/validators/validationFailures/validation-failures.js +139 -0
  52. package/build/legacy/common/validators/validationFailures/validation-failures.utils.js +40 -0
  53. package/build/legacy/common/validators/values/value-validators.js +6 -0
  54. package/build/legacy/dynamic-flow-types.js +1 -0
  55. package/build/legacy/dynamicFlow/BackButton.js +22 -0
  56. package/build/legacy/dynamicFlow/DynamicFlowStep.js +37 -0
  57. package/build/legacy/formControl/FormControl.js +266 -0
  58. package/build/legacy/formControl/index.js +1 -0
  59. package/build/legacy/formControl/utils/getAutocompleteString.js +80 -0
  60. package/build/legacy/formControl/utils/index.js +2 -0
  61. package/build/legacy/formControl/utils/value-utils.js +108 -0
  62. package/build/legacy/jsonSchemaForm/allOfSchema/AllOfSchema.js +50 -0
  63. package/build/legacy/jsonSchemaForm/allOfSchema/index.js +1 -0
  64. package/build/legacy/jsonSchemaForm/arrayTypeSchema/ArraySchema.js +25 -0
  65. package/build/legacy/jsonSchemaForm/arrayTypeSchema/arrayListSchema/ArrayListSchema.js +30 -0
  66. package/build/legacy/jsonSchemaForm/arrayTypeSchema/arrayListSchema/multipleFileUploadSchema/MultipleFileUploadSchema.js +141 -0
  67. package/build/legacy/jsonSchemaForm/arrayTypeSchema/arrayListSchema/multipleFileUploadSchema/index.js +1 -0
  68. package/build/legacy/jsonSchemaForm/arrayTypeSchema/arrayListSchema/multipleFileUploadSchema/utils/index.js +2 -0
  69. package/build/legacy/jsonSchemaForm/arrayTypeSchema/arrayListSchema/multipleFileUploadSchema/utils/upload-utils.js +79 -0
  70. package/build/legacy/jsonSchemaForm/arrayTypeSchema/arrayListSchema/multipleFileUploadSchema/utils/useFormattedDefaultErrorMessages.js +14 -0
  71. package/build/legacy/jsonSchemaForm/arrayTypeSchema/arrayListSchema/repeatableSchema/ItemSummary.js +7 -0
  72. package/build/legacy/jsonSchemaForm/arrayTypeSchema/arrayListSchema/repeatableSchema/RepeatableSchema.js +134 -0
  73. package/build/legacy/jsonSchemaForm/arrayTypeSchema/arrayListSchema/repeatableSchema/RepeatableSchemaStep.js +85 -0
  74. package/build/legacy/jsonSchemaForm/arrayTypeSchema/arrayListSchema/repeatableSchema/utils/summary-utils.js +135 -0
  75. package/build/legacy/jsonSchemaForm/arrayTypeSchema/index.js +1 -0
  76. package/build/legacy/jsonSchemaForm/basicTypeSchema/BasicTypeSchema.js +111 -0
  77. package/build/legacy/jsonSchemaForm/basicTypeSchema/index.js +1 -0
  78. package/build/legacy/jsonSchemaForm/controlFeedback/ControlFeedback.js +86 -0
  79. package/build/legacy/jsonSchemaForm/controlFeedback/index.js +1 -0
  80. package/build/legacy/jsonSchemaForm/help/Help.js +20 -0
  81. package/build/legacy/jsonSchemaForm/help/index.js +1 -0
  82. package/build/legacy/jsonSchemaForm/objectSchema/ObjectSchema.js +77 -0
  83. package/build/legacy/jsonSchemaForm/objectSchema/index.js +1 -0
  84. package/build/legacy/jsonSchemaForm/oneOfSchema/OneOfSchema.js +155 -0
  85. package/build/legacy/jsonSchemaForm/oneOfSchema/index.js +1 -0
  86. package/build/legacy/jsonSchemaForm/oneOfSchema/utils.js +68 -0
  87. package/build/legacy/jsonSchemaForm/persistAsyncSchema/PersistAsyncSchema.js +26 -0
  88. package/build/legacy/jsonSchemaForm/persistAsyncSchema/index.js +1 -0
  89. package/build/legacy/jsonSchemaForm/persistAsyncSchema/persistAsyncBasicSchema/PersistAsyncBasicSchema.js +165 -0
  90. package/build/legacy/jsonSchemaForm/persistAsyncSchema/persistAsyncBasicSchema/index.js +1 -0
  91. package/build/legacy/jsonSchemaForm/persistAsyncSchema/persistAsyncBlobSchema/PersistAsyncBlobSchema.js +131 -0
  92. package/build/legacy/jsonSchemaForm/persistAsyncSchema/persistAsyncBlobSchema/UploadInputAdapter.js +31 -0
  93. package/build/legacy/jsonSchemaForm/persistAsyncSchema/persistAsyncBlobSchema/index.js +1 -0
  94. package/build/legacy/jsonSchemaForm/promotedOneOfSchema/PromotedOneOfSchema.js +72 -0
  95. package/build/legacy/jsonSchemaForm/promotedOneOfSchema/index.js +1 -0
  96. package/build/legacy/jsonSchemaForm/promotedOneOfSchema/promoted-one-of-utils.js +8 -0
  97. package/build/legacy/jsonSchemaForm/promotedOneOfSchema/promotedOneOfControl/PromotedOneOfCheckboxControl.js +27 -0
  98. package/build/legacy/jsonSchemaForm/promotedOneOfSchema/promotedOneOfControl/PromotedOneOfControl.js +31 -0
  99. package/build/legacy/jsonSchemaForm/promotedOneOfSchema/promotedOneOfControl/PromotedOneOfRadioControl.js +32 -0
  100. package/build/legacy/jsonSchemaForm/readOnlySchema/ReadOnlySchema.js +54 -0
  101. package/build/legacy/jsonSchemaForm/readOnlySchema/ReadOnlySchema.messages.js +13 -0
  102. package/build/legacy/jsonSchemaForm/readOnlySchema/index.js +1 -0
  103. package/build/legacy/jsonSchemaForm/schemaFormControl/SchemaFormControl.js +133 -0
  104. package/build/legacy/jsonSchemaForm/schemaFormControl/index.js +1 -0
  105. package/build/legacy/jsonSchemaForm/schemaFormControl/utils/index.js +1 -0
  106. package/build/legacy/jsonSchemaForm/schemaFormControl/utils/mapping-utils.js +107 -0
  107. package/build/legacy/layout/DynamicLayout.js +68 -0
  108. package/build/legacy/layout/alert/DynamicAlert.js +29 -0
  109. package/build/legacy/layout/box/DynamicBox.js +41 -0
  110. package/build/legacy/layout/button/DynamicButton.js +27 -0
  111. package/build/legacy/layout/button/utils.js +45 -0
  112. package/build/legacy/layout/columns/DynamicColumns.js +38 -0
  113. package/build/legacy/layout/decision/DynamicDecision.js +21 -0
  114. package/build/legacy/layout/divider/DynamicDivider.js +9 -0
  115. package/build/legacy/layout/external/DynamicExternal.js +32 -0
  116. package/build/legacy/layout/external/DynamicExternal.messages.js +8 -0
  117. package/build/legacy/layout/form/DynamicForm.js +22 -0
  118. package/build/legacy/layout/heading/DynamicHeading.js +51 -0
  119. package/build/legacy/layout/icon/DynamicIcon.js +17 -0
  120. package/build/legacy/layout/icon/FlagIcon.js +198 -0
  121. package/build/legacy/layout/icon/NamedIcon.js +19 -0
  122. package/build/legacy/layout/image/DynamicImage.js +111 -0
  123. package/build/legacy/layout/index.js +20 -0
  124. package/build/legacy/layout/instructions/DynamicInstructions.js +30 -0
  125. package/build/legacy/layout/list/DynamicStatusList.js +37 -0
  126. package/build/legacy/layout/loadingIndicator/DynamicLoadingIndicator.js +11 -0
  127. package/build/legacy/layout/markdown/DynamicMarkdown.js +23 -0
  128. package/build/legacy/layout/modal/DynamicModal.js +26 -0
  129. package/build/legacy/layout/paragraph/DynamicParagraph.js +46 -0
  130. package/build/legacy/layout/paragraph/useSnackBarIfAvailable.js +9 -0
  131. package/build/legacy/layout/review/DynamicReview.js +58 -0
  132. package/build/legacy/layout/search/DynamicSearch.js +58 -0
  133. package/build/legacy/layout/search/SearchInput.js +17 -0
  134. package/build/legacy/layout/search/SearchResults.js +31 -0
  135. package/build/legacy/layout/search/useSearch.js +137 -0
  136. package/build/legacy/layout/utils/getNavigationOptionMedia.js +28 -0
  137. package/build/legacy/layout/utils/index.js +32 -0
  138. package/build/legacy/step/cameraStep/CameraStep.js +124 -0
  139. package/build/legacy/step/cameraStep/cameraCapture/CameraCapture.js +161 -0
  140. package/build/legacy/step/cameraStep/cameraCapture/CameraCapture.messages.js +58 -0
  141. package/build/legacy/step/cameraStep/cameraCapture/components/bottomBar/BottomBar.js +28 -0
  142. package/build/legacy/step/cameraStep/cameraCapture/components/index.js +3 -0
  143. package/build/legacy/step/cameraStep/cameraCapture/components/orientationLockOverlay/OrientationLockOverlay.js +19 -0
  144. package/build/legacy/step/cameraStep/cameraCapture/components/orientationLockOverlay/OrientationLockOverlay.messages.js +8 -0
  145. package/build/legacy/step/cameraStep/cameraCapture/hooks/useFullScreenOrientationLock.js +60 -0
  146. package/build/legacy/step/cameraStep/cameraCapture/hooks/useVideoConstraints.js +80 -0
  147. package/build/legacy/step/cameraStep/cameraCapture/index.js +1 -0
  148. package/build/legacy/step/cameraStep/cameraCapture/overlay/Overlay.js +77 -0
  149. package/build/legacy/step/cameraStep/cameraCapture/screens/cameraErrorScreen/CameraErrorScreen.js +18 -0
  150. package/build/legacy/step/cameraStep/cameraCapture/screens/index.js +1 -0
  151. package/build/legacy/step/cameraStep/cameraCapture/tracking/index.js +109 -0
  152. package/build/legacy/step/cameraStep/cameraCapture/types/index.js +7 -0
  153. package/build/legacy/step/cameraStep/cameraCapture/utils/index.js +107 -0
  154. package/build/legacy/step/cameraStep/index.js +1 -0
  155. package/build/legacy/step/externalConfirmationStep/ExternalConfirmationStep.js +64 -0
  156. package/build/legacy/step/externalConfirmationStep/ExternalConfirmationStep.messages.js +23 -0
  157. package/build/legacy/step/externalConfirmationStep/index.js +1 -0
  158. package/build/legacy/step/index.js +3 -0
  159. package/build/legacy/step/layoutStep/LayoutStep.js +33 -0
  160. package/build/legacy/step/layoutStep/index.js +1 -0
  161. package/build/legacy/step/layoutStep/utils/index.js +2 -0
  162. package/build/legacy/step/layoutStep/utils/inline-reference-utils.js +105 -0
  163. package/build/legacy/step/layoutStep/utils/layout-utils.js +212 -0
  164. package/build/main.js +13 -28
  165. package/build/main.min.js +1 -1
  166. package/build/main.mjs +13 -28
  167. package/build/types/revamp/domain/features/events.d.ts +1 -1
  168. package/package.json +1 -1
@@ -0,0 +1,119 @@
1
+ var __assign = (this && this.__assign) || function () {
2
+ __assign = Object.assign || function(t) {
3
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
4
+ s = arguments[i];
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
+ t[p] = s[p];
7
+ }
8
+ return t;
9
+ };
10
+ return __assign.apply(this, arguments);
11
+ };
12
+ import { isObjectModel, isArraySchema, isListArraySchema } from '../../utils';
13
+ import { isArray, isBoolean, isNull, isNumber, isString, isUndefined, } from '../types/type-validators';
14
+ import { isEmpty } from '../values/value-validators';
15
+ import { getValidBasicModelOrNull, getValidModelParts, getValidObjectModelParts, } from './model-validators';
16
+ export function cleanBasicModelWithOneOfSchema(model, schema) {
17
+ return schema.oneOf.some(function (nestedSchema) { return getValidBasicModelOrNull(model, nestedSchema) === model; })
18
+ ? model
19
+ : null;
20
+ }
21
+ export function cleanArrayModelWithOneOfSchema(model, schema) {
22
+ var _a;
23
+ var validModels = schema.oneOf
24
+ .map(function (nestedSchema) { return getValidArrayModelOrNull(model, nestedSchema); })
25
+ .filter(function (item) { return item !== null; });
26
+ if (validModels.length === 0) {
27
+ return null;
28
+ }
29
+ return (_a = validModels.find(function (model) { return model.some(function (item) { return item !== null; }); })) !== null && _a !== void 0 ? _a : validModels[0];
30
+ }
31
+ function getValidArrayModelOrNull(model, schema) {
32
+ if (!isArraySchema(schema)) {
33
+ return null;
34
+ }
35
+ if (!isListArraySchema(schema)) {
36
+ return null; // we don't support tuples at the moment
37
+ }
38
+ return cleanModelWithArraySchema(model, schema);
39
+ }
40
+ export function cleanModelWithStringSchema(model) {
41
+ return isString(model) && !isEmpty(model) ? model : null;
42
+ }
43
+ export function cleanModelWithNumberSchema(model) {
44
+ return isNumber(model) ? model : null;
45
+ }
46
+ export function cleanModelWithBooleanSchema(model) {
47
+ return isBoolean(model) ? model : null;
48
+ }
49
+ export function cleanModelWithArraySchema(model, schema) {
50
+ if (!isArray(model)) {
51
+ return null;
52
+ }
53
+ if (!isListArraySchema(schema)) {
54
+ return null; // we don't support tuples at the moment
55
+ }
56
+ if (model.length > 0) {
57
+ var expectedType_1 = typeof model[0];
58
+ // eslint-disable-next-line valid-typeof
59
+ if (!model.every(function (item) { return typeof item === expectedType_1; })) {
60
+ return new Array(model.length).fill(null);
61
+ }
62
+ }
63
+ return model.map(function (childModel) { return getValidModelParts(childModel, schema.items); });
64
+ }
65
+ export function cleanObjectModelWithObjectSchema(model, schema) {
66
+ return Object.keys(schema.properties).reduce(function (cleanedModel, property) {
67
+ var _a;
68
+ // If the property exists in the model, clean it, and add it
69
+ if (model && !isUndefined(model[property])) {
70
+ var subModel = model[property];
71
+ var subSchema = schema.properties[property];
72
+ var newValue = getValidModelParts(subModel, subSchema);
73
+ if (!isNull(newValue)) {
74
+ return __assign(__assign({}, cleanedModel), (_a = {}, _a[property] = newValue, _a));
75
+ }
76
+ }
77
+ return cleanedModel;
78
+ }, {});
79
+ }
80
+ export function cleanObjectModelWithAllOfSchema(model, schema) {
81
+ return schema.allOf.reduce(function (cleanObjectModel, nestedSchema) {
82
+ var validSubsetOfModel = getValidObjectModelParts(model, nestedSchema);
83
+ if (isObjectModel(validSubsetOfModel)) {
84
+ // Extend model with valid subset
85
+ return __assign(__assign({}, cleanObjectModel), validSubsetOfModel);
86
+ }
87
+ return cleanObjectModel;
88
+ }, {});
89
+ }
90
+ export function cleanObjectModelWithOneOfSchema(model, schema) {
91
+ return schema.oneOf
92
+ .map(function (nestedSchema) { return getValidObjectModelParts(model, nestedSchema); })
93
+ .reduce(function (combined, current) {
94
+ // If we didn't find anything valid yet, and current is good, return it
95
+ if (isNull(combined)) {
96
+ return current;
97
+ }
98
+ // If we're dealing with two objects, deep merge them into one
99
+ if (isObjectModel(combined) && isObjectModel(current)) {
100
+ return deepMergeObject(combined, current);
101
+ }
102
+ // If the current one is null, return what we already had
103
+ if (isNull(current)) {
104
+ return combined;
105
+ }
106
+ return current;
107
+ }, null);
108
+ }
109
+ function deepMergeObject(object1, object2) {
110
+ return Object.keys(object2).reduce(function (acc, property) {
111
+ var _a, _b;
112
+ var object1Property = object1[property];
113
+ var object2Property = object2[property];
114
+ if (isObjectModel(object1Property) && isObjectModel(object2Property)) {
115
+ return __assign(__assign({}, acc), (_a = {}, _a[property] = deepMergeObject(object1Property, object2Property), _a));
116
+ }
117
+ return __assign(__assign({}, acc), (_b = {}, _b[property] = object2[property], _b));
118
+ }, __assign({}, object1));
119
+ }
@@ -0,0 +1,62 @@
1
+ import { isArrayModel, isObjectModel, isBasicSchema, isOneOfSchema, isArraySchema, isObjectSchema, isEqual, } from '../../utils';
2
+ import { isNull, isUndefined } from '..';
3
+ import { cleanArrayModelWithOneOfSchema, cleanBasicModelWithOneOfSchema, cleanModelWithArraySchema, cleanModelWithBooleanSchema, cleanModelWithNumberSchema, cleanModelWithStringSchema, cleanObjectModelWithAllOfSchema, cleanObjectModelWithObjectSchema, cleanObjectModelWithOneOfSchema, } from './model-utils';
4
+ export var getValidModelParts = function (model, schema) {
5
+ if (isObjectModel(model)) {
6
+ return getValidObjectModelParts(model, schema);
7
+ }
8
+ if (isArrayModel(model)) {
9
+ return getValidArrayModelParts(model, schema);
10
+ }
11
+ return getValidBasicModelOrNull(model, schema);
12
+ };
13
+ export function getValidBasicModelOrNull(model, schema) {
14
+ if (isNull(model)) {
15
+ return null;
16
+ }
17
+ if (schema.oneOf) {
18
+ return cleanBasicModelWithOneOfSchema(model, schema);
19
+ }
20
+ if (!isUndefined(schema["const"]) && model === schema["const"]) {
21
+ return model;
22
+ }
23
+ if (schema.type) {
24
+ switch (schema.type) {
25
+ case 'string':
26
+ return cleanModelWithStringSchema(model);
27
+ case 'number':
28
+ case 'integer':
29
+ return cleanModelWithNumberSchema(model);
30
+ case 'boolean':
31
+ return cleanModelWithBooleanSchema(model);
32
+ default:
33
+ return null;
34
+ }
35
+ }
36
+ // Unrecognised schema
37
+ return null;
38
+ }
39
+ export function getValidObjectModelParts(model, schema) {
40
+ if (isBasicSchema(schema) || isArraySchema(schema) || isNull(model)) {
41
+ return null;
42
+ }
43
+ if (schema.allOf) {
44
+ return cleanObjectModelWithAllOfSchema(model, schema);
45
+ }
46
+ if (schema.oneOf) {
47
+ return cleanObjectModelWithOneOfSchema(model, schema);
48
+ }
49
+ if (!isUndefined(schema["const"]) && isEqual(model, schema["const"])) {
50
+ return model;
51
+ }
52
+ return isObjectSchema(schema) ? cleanObjectModelWithObjectSchema(model, schema) : null;
53
+ }
54
+ function getValidArrayModelParts(model, schema) {
55
+ if (isOneOfSchema(schema)) {
56
+ return cleanArrayModelWithOneOfSchema(model, schema);
57
+ }
58
+ if (!isArraySchema(schema)) {
59
+ return null;
60
+ }
61
+ return cleanModelWithArraySchema(model, schema);
62
+ }
@@ -0,0 +1,101 @@
1
+ import { isListArraySchema } from '../../utils';
2
+ import { isObject, isArray } from '../types/type-validators';
3
+ import { getStringValidationFailures, getNumberValidationFailures, getIntegerValidationFailures, getBooleanValidationFailures, getConstValidationFailures, getArrayValidationFailures, getBlobValidationFailures, } from '../validationFailures/validation-failures';
4
+ function isValidStringSchema(value, schema) {
5
+ return !getStringValidationFailures(value, schema).length;
6
+ }
7
+ function isValidNumberSchema(value, schema) {
8
+ return !getNumberValidationFailures(value, schema).length;
9
+ }
10
+ function isValidIntegerSchema(value, schema) {
11
+ return !getIntegerValidationFailures(value, schema).length;
12
+ }
13
+ function isValidBooleanSchema(value, schema) {
14
+ return !getBooleanValidationFailures(value, schema).length;
15
+ }
16
+ function isValidConstSchema(value, schema) {
17
+ return !getConstValidationFailures(value, schema).length;
18
+ }
19
+ function isValidObjectSchema(value, schema) {
20
+ if (!isObject(value) || schema.type !== 'object' || !isObject(schema.properties)) {
21
+ return false;
22
+ }
23
+ return Object.keys(schema.properties)
24
+ .map(function (propertyName) {
25
+ return isObjectPropertyValid(value[propertyName], schema.properties[propertyName], schema.required && schema.required.includes(propertyName));
26
+ })
27
+ .every(function (property) { return property; });
28
+ }
29
+ function isObjectPropertyValid(propertyValue, propertySchema, isRequired) {
30
+ if (propertySchema.hidden) {
31
+ return true;
32
+ }
33
+ if (typeof propertyValue === 'undefined') {
34
+ return !isRequired;
35
+ }
36
+ return isValidSchema(propertyValue, propertySchema);
37
+ }
38
+ function isValidArraySchema(value, schema) {
39
+ if (schema.type !== 'array' || !isObject(schema.items)) {
40
+ return false;
41
+ }
42
+ if (getArrayValidationFailures(value, schema).length > 0) {
43
+ return false;
44
+ }
45
+ return (Array.isArray(value) &&
46
+ isListArraySchema(schema) && // TupleArraySchema not yet supported
47
+ value.map(function (item) { return isValidSchema(item, schema.items); }).every(function (valid) { return valid; }));
48
+ }
49
+ function isValidOneOfSchema(value, schema) {
50
+ if (!isArray(schema.oneOf)) {
51
+ return false;
52
+ }
53
+ return schema.oneOf.some(function (childSchema) { return isValidSchema(value, childSchema); });
54
+ }
55
+ function isValidAllOfSchema(value, schema) {
56
+ if (!isArray(schema.allOf)) {
57
+ return false;
58
+ }
59
+ return schema.allOf
60
+ .map(function (childSchema) { return isValidSchema(value, childSchema); })
61
+ .every(function (valid) { return valid; });
62
+ }
63
+ function isValidBlobSchema(value, schema) {
64
+ return !getBlobValidationFailures(value, schema).length;
65
+ }
66
+ /**
67
+ * Validate any value against a given schema
68
+ *
69
+ * @param value
70
+ * @param schema
71
+ */
72
+ function isValidSchema(value, schema) {
73
+ if (schema.oneOf) {
74
+ return isValidOneOfSchema(value, schema);
75
+ }
76
+ if (schema.allOf) {
77
+ return isValidAllOfSchema(value, schema);
78
+ }
79
+ if (schema["const"]) {
80
+ return isValidConstSchema(value, schema);
81
+ }
82
+ switch (schema.type) {
83
+ case 'string':
84
+ return isValidStringSchema(value, schema);
85
+ case 'number':
86
+ return isValidNumberSchema(value, schema);
87
+ case 'integer':
88
+ return isValidIntegerSchema(value, schema);
89
+ case 'boolean':
90
+ return isValidBooleanSchema(value, schema);
91
+ case 'array':
92
+ return isValidArraySchema(value, schema);
93
+ case 'object':
94
+ return isValidObjectSchema(value, schema);
95
+ case 'blob':
96
+ return isValidBlobSchema(value, schema);
97
+ default:
98
+ return false;
99
+ }
100
+ }
101
+ export { isValidSchema };
@@ -0,0 +1,14 @@
1
+ export var isString = function (value) { return typeof value === 'string'; };
2
+ export var isNumber = function (value) {
3
+ return typeof value === 'number' && !Number.isNaN(value);
4
+ };
5
+ export var isInteger = function (value) {
6
+ return isNumber(value) && Math.floor(value) === value;
7
+ };
8
+ export var isBoolean = function (value) { return typeof value === 'boolean'; };
9
+ export var isObject = function (value) {
10
+ return !isNull(value) && !isUndefined(value) && (value === null || value === void 0 ? void 0 : value.constructor) === Object;
11
+ };
12
+ export var isArray = function (value) { return Array.isArray(value); };
13
+ export var isNull = function (value) { return value === null; };
14
+ export var isUndefined = function (value) { return typeof value === 'undefined'; };
@@ -0,0 +1,139 @@
1
+ import { isEqual, isObjectModel, isStringSchema } from '../../utils';
2
+ import { isArray, isString, isNumber, isInteger, isBoolean, isNull, } from '../types/type-validators';
3
+ import { isValidRequired, isValidMinLength, isValidMaxLength, isValidPattern, isValidMaximum, isValidMinimum, isValidMinItems, isValidMaxItems, isValidRequiredArray, } from './validation-failures.utils';
4
+ function getValidationFailures(value, schema, isRequired) {
5
+ if (schema["const"]) {
6
+ return getConstValidationFailures(value, schema, isRequired);
7
+ }
8
+ if (isNull(value)) {
9
+ return isRequired ? ['required'] : [];
10
+ }
11
+ if (isStringSchema(schema)) {
12
+ return getStringValidationFailures(value, schema, isRequired);
13
+ }
14
+ switch (schema.type) {
15
+ case 'number':
16
+ return getNumberValidationFailures(value, schema, isRequired);
17
+ case 'integer':
18
+ return getIntegerValidationFailures(value, schema, isRequired);
19
+ case 'boolean':
20
+ return getBooleanValidationFailures(value, schema, isRequired);
21
+ case 'array':
22
+ return getArrayValidationFailures(value, schema, isRequired);
23
+ case 'object':
24
+ return getObjectValidationFailures(value, schema);
25
+ default:
26
+ return [];
27
+ }
28
+ }
29
+ function getStringValidationFailures(value, schema, isRequired) {
30
+ if (!isString(value) && !isNull(value)) {
31
+ return ['type'];
32
+ }
33
+ if (value === '' && isRequired) {
34
+ return ['required'];
35
+ }
36
+ var failures = [];
37
+ if (!isValidRequired(value, isRequired)) {
38
+ failures.push('required');
39
+ }
40
+ if (!isValidMinLength(value, schema.minLength)) {
41
+ failures.push('minLength');
42
+ }
43
+ if (!isValidMaxLength(value, schema.maxLength)) {
44
+ failures.push('maxLength');
45
+ }
46
+ if (!isValidPattern(value, schema.pattern)) {
47
+ failures.push('pattern');
48
+ }
49
+ if (!isValidMinimum(value, schema.minimum)) {
50
+ failures.push('minimum');
51
+ }
52
+ if (!isValidMaximum(value, schema.maximum)) {
53
+ failures.push('maximum');
54
+ }
55
+ return failures;
56
+ }
57
+ function getNumberValidationFailures(value, schema, isRequired) {
58
+ if (!isNumber(value) && !isNull(value)) {
59
+ return ['type'];
60
+ }
61
+ var failures = [];
62
+ if (!isValidRequired(value, isRequired)) {
63
+ failures.push('required');
64
+ }
65
+ if (!isValidMinimum(value, schema.minimum)) {
66
+ failures.push('minimum');
67
+ }
68
+ if (!isValidMaximum(value, schema.maximum)) {
69
+ failures.push('maximum');
70
+ }
71
+ return failures;
72
+ }
73
+ function getIntegerValidationFailures(value, schema, isRequired) {
74
+ if (!isInteger(value)) {
75
+ return ['type'];
76
+ }
77
+ return getNumberValidationFailures(value, schema, isRequired);
78
+ }
79
+ function getBooleanValidationFailures(value, _schema, isRequired) {
80
+ if (!isBoolean(value) && !isNull(value)) {
81
+ return ['type'];
82
+ }
83
+ var failures = [];
84
+ if (!isValidRequired(value, isRequired)) {
85
+ failures.push('required');
86
+ }
87
+ return failures;
88
+ }
89
+ function getConstValidationFailures(value, schema, isRequired) {
90
+ if (!isValidRequired(value, isRequired)) {
91
+ return ['required'];
92
+ }
93
+ if (!isEqual(value, schema["const"])) {
94
+ return ['const'];
95
+ }
96
+ return [];
97
+ }
98
+ function getArrayValidationFailures(value, schema, isRequired) {
99
+ if (!isArray(value) && !isNull(value)) {
100
+ return ['type'];
101
+ }
102
+ if (!isValidRequiredArray(value, isRequired)) {
103
+ return ['required'];
104
+ }
105
+ var failures = [];
106
+ if (!isValidMinItems(value, schema.minItems)) {
107
+ failures.push('minItems');
108
+ }
109
+ if (!isValidMaxItems(value, schema.maxItems)) {
110
+ failures.push('maxItems');
111
+ }
112
+ return failures;
113
+ }
114
+ function getBlobValidationFailures(value, _schema) {
115
+ if (isNull(value)) {
116
+ return ['type'];
117
+ }
118
+ return [];
119
+ }
120
+ /**
121
+ * When validating an object we only checking that it is an object and that it
122
+ * has the required properties, we do not check if the properties are valid.
123
+ *
124
+ * @param value
125
+ * @param schema
126
+ */
127
+ function getObjectValidationFailures(value, schema) {
128
+ if (!isObjectModel(value)) {
129
+ return ['type'];
130
+ }
131
+ if (!isArray(schema.required)) {
132
+ return [];
133
+ }
134
+ var allPresent = schema.required
135
+ .map(function (property) { return typeof value[property] !== 'undefined'; })
136
+ .reduce(function (propertyInModel, validSoFar) { return propertyInModel && validSoFar; }, true);
137
+ return allPresent ? [] : ['required'];
138
+ }
139
+ export { getValidationFailures, getStringValidationFailures, getNumberValidationFailures, getIntegerValidationFailures, getBooleanValidationFailures, getConstValidationFailures, getArrayValidationFailures, getObjectValidationFailures, getBlobValidationFailures, };
@@ -0,0 +1,40 @@
1
+ import { isArray, isNumber, isString, isUndefined } from '..';
2
+ function isValidRequired(value, isRequired) {
3
+ if (isRequired === void 0) { isRequired = false; }
4
+ return !isRequired || !isUndefined(value);
5
+ }
6
+ function isValidRequiredArray(value, isRequired) {
7
+ if (isRequired === void 0) { isRequired = false; }
8
+ return !isRequired || isArray(value);
9
+ }
10
+ function isValidMinLength(value, minLength) {
11
+ return !isNumber(minLength) || (isString(value) && value.length >= minLength);
12
+ }
13
+ function isValidMaxLength(value, maxLength) {
14
+ return !isNumber(maxLength) || (isString(value) && value.length <= maxLength);
15
+ }
16
+ function isValidPattern(value, pattern) {
17
+ if (pattern === undefined) {
18
+ return true; // no pattern, therefore the value is valid
19
+ }
20
+ if (value === undefined || value === null) {
21
+ return false; // no value, but there's a pattern, therefore the value is NOT valid
22
+ }
23
+ var regex = new RegExp(pattern);
24
+ return Boolean(regex.test(value));
25
+ }
26
+ function isValidMaximum(value, maximum) {
27
+ return ((!isNumber(maximum) && !isString(maximum)) ||
28
+ ((isNumber(value) || isString(value)) && value <= maximum));
29
+ }
30
+ function isValidMinimum(value, minimum) {
31
+ return ((!isNumber(minimum) && !isString(minimum)) ||
32
+ ((isNumber(value) || isString(value)) && value >= minimum));
33
+ }
34
+ function isValidMinItems(value, minItems) {
35
+ return !isNumber(minItems) || (isArray(value) && value.length >= minItems);
36
+ }
37
+ function isValidMaxItems(value, maxItems) {
38
+ return !isNumber(maxItems) || (isArray(value) && value.length <= maxItems);
39
+ }
40
+ export { isValidRequired, isValidMinLength, isValidMaxLength, isValidPattern, isValidMaximum, isValidMinimum, isValidMinItems, isValidMaxItems, isValidRequiredArray, };
@@ -0,0 +1,6 @@
1
+ import { isString, isObject, isArray } from '../types/type-validators';
2
+ var isEmpty = function (value) {
3
+ return (isString(value) && value.length === 0) ||
4
+ ((isObject(value) || isArray(value)) && Object.keys(value).length === 0);
5
+ };
6
+ export { isEmpty };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,22 @@
1
+ var __assign = (this && this.__assign) || function () {
2
+ __assign = Object.assign || function(t) {
3
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
4
+ s = arguments[i];
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
+ t[p] = s[p];
7
+ }
8
+ return t;
9
+ };
10
+ return __assign.apply(this, arguments);
11
+ };
12
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
13
+ import { Avatar } from '@transferwise/components';
14
+ import { ArrowLeft } from '@transferwise/icons';
15
+ function BackButton(_a) {
16
+ var title = _a.title, action = _a.action, onAction = _a.onAction;
17
+ return (_jsxs("a", __assign({ href: "/", className: "df-back-btn", "aria-label": title, onClick: function (event) {
18
+ event.preventDefault();
19
+ onAction(__assign(__assign({}, action), { skipValidation: true }));
20
+ } }, { children: [_jsx("span", __assign({ className: "sr-only" }, { children: title })), _jsx(Avatar, __assign({ type: "icon" }, { children: _jsx(ArrowLeft, { size: "24" }) }))] })));
21
+ }
22
+ export default BackButton;
@@ -0,0 +1,37 @@
1
+ var __assign = (this && this.__assign) || function () {
2
+ __assign = Object.assign || function(t) {
3
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
4
+ s = arguments[i];
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
+ t[p] = s[p];
7
+ }
8
+ return t;
9
+ };
10
+ return __assign.apply(this, arguments);
11
+ };
12
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
13
+ import { useExternal } from '../common/hooks';
14
+ import { isCameraStep } from '../common/utils';
15
+ import { DynamicAlert } from '../layout';
16
+ import { CameraStep, LayoutStep, ExternalConfirmationStep } from '../step';
17
+ import BackButton from './BackButton';
18
+ export function DynamicFlowStep(props) {
19
+ var _a, _b, _c;
20
+ var step = props.step, globalError = props.globalError, onAction = props.onAction;
21
+ var externalUrl = (_a = step === null || step === void 0 ? void 0 : step.external) === null || _a === void 0 ? void 0 : _a.url;
22
+ var backButton = ((_b = step === null || step === void 0 ? void 0 : step.navigation) === null || _b === void 0 ? void 0 : _b.back) || ((_c = step === null || step === void 0 ? void 0 : step.navigation) === null || _c === void 0 ? void 0 : _c.backButton);
23
+ var _d = useExternal(externalUrl), requiresManualTrigger = _d.requiresManualTrigger, dismissConfirmation = _d.dismissConfirmation;
24
+ if (step === undefined) {
25
+ if (globalError) {
26
+ return (_jsx(DynamicAlert, { component: { context: 'negative', markdown: globalError, margin: 'lg' } }));
27
+ }
28
+ return null;
29
+ }
30
+ if (externalUrl && requiresManualTrigger) {
31
+ return _jsx(ExternalConfirmationStep, { url: externalUrl, onClose: dismissConfirmation });
32
+ }
33
+ if (isCameraStep(step)) {
34
+ return _jsx(CameraStep, __assign({}, props, { step: step }));
35
+ }
36
+ return (_jsxs(_Fragment, { children: [backButton && _jsx(BackButton, __assign({}, backButton, { onAction: onAction })), globalError ? (_jsx(DynamicAlert, { component: { context: 'negative', markdown: globalError, margin: 'lg' } })) : null, _jsx(LayoutStep, __assign({}, props, { stepSpecification: step }))] }));
37
+ }