@wise/dynamic-flow-client 3.3.2 → 3.4.0-experimental-ed080a1

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 +2 -2
@@ -0,0 +1,172 @@
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
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
13
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
14
+ return new (P || (P = Promise))(function (resolve, reject) {
15
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
16
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
17
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
18
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
19
+ });
20
+ };
21
+ var __generator = (this && this.__generator) || function (thisArg, body) {
22
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
23
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
24
+ function verb(n) { return function (v) { return step([n, v]); }; }
25
+ function step(op) {
26
+ if (f) throw new TypeError("Generator is already executing.");
27
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
28
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
29
+ if (y = 0, t) op = [op[0] & 2, t.value];
30
+ switch (op[0]) {
31
+ case 0: case 1: t = op; break;
32
+ case 4: _.label++; return { value: op[1], done: false };
33
+ case 5: _.label++; y = op[1]; op = [0]; continue;
34
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
35
+ default:
36
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
37
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
38
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
39
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
40
+ if (t[2]) _.ops.pop();
41
+ _.trys.pop(); continue;
42
+ }
43
+ op = body.call(thisArg, _);
44
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
45
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
46
+ }
47
+ };
48
+ import { useState } from 'react';
49
+ import { useIntl } from 'react-intl';
50
+ import { isBlobSchema } from '../../utils';
51
+ import { isNull, isObject, isNumber, isString, isValidSchema } from '../../validators';
52
+ import messages from '../../../../common/messages/generic-error.messages';
53
+ import { getErrorFromResponse } from '../../../jsonSchemaForm/persistAsyncSchema/persistAsyncBasicSchema/PersistAsyncBasicSchema'; // FIXME: extract these functions form that schema component to either here or their own module
54
+ import { useHttpClient } from '../../../../common/httpClientContext';
55
+ export var usePersistAsync = function (persistAsync) {
56
+ var _a = useState(null), abortController = _a[0], setAbortController = _a[1];
57
+ var httpClient = useHttpClient();
58
+ var intl = useIntl();
59
+ var schema = persistAsync.schema;
60
+ function handlePersistAsync(model) {
61
+ return __awaiter(this, void 0, void 0, function () {
62
+ var isInvalidSchema;
63
+ return __generator(this, function (_a) {
64
+ switch (_a.label) {
65
+ case 0:
66
+ isInvalidSchema = model instanceof Blob ? !isBlobSchema(schema) : !isValidSchema(model, schema);
67
+ if (isNull(model) || isInvalidSchema) {
68
+ handleError();
69
+ }
70
+ return [4 /*yield*/, performPersistAsync(model)];
71
+ case 1:
72
+ // eslint-disable-next-line @typescript-eslint/return-await
73
+ return [2 /*return*/, _a.sent()];
74
+ }
75
+ });
76
+ });
77
+ }
78
+ var abortCurrentRequestAndGetNewAbortSignal = function () {
79
+ if (abortController) {
80
+ abortController.abort();
81
+ }
82
+ var newAbortController = new AbortController();
83
+ setAbortController(newAbortController);
84
+ return newAbortController.signal;
85
+ };
86
+ function constructFetchInit(model) {
87
+ var _a;
88
+ var isBlob = isBlobSchema(schema);
89
+ var signal = abortCurrentRequestAndGetNewAbortSignal();
90
+ var requestKey = persistAsync.param;
91
+ var requestBody = isBlob
92
+ ? wrapInFormData(requestKey, model)
93
+ : JSON.stringify((_a = {}, _a[requestKey] = model, _a));
94
+ return {
95
+ method: persistAsync.method,
96
+ headers: __assign({}, (!isBlob && { 'Content-Type': 'application/json' })),
97
+ body: requestBody,
98
+ signal: signal
99
+ };
100
+ }
101
+ function performPersistAsync(payload) {
102
+ return __awaiter(this, void 0, void 0, function () {
103
+ var response, jsonResponse, id, error_1;
104
+ return __generator(this, function (_a) {
105
+ switch (_a.label) {
106
+ case 0:
107
+ _a.trys.push([0, 3, , 4]);
108
+ return [4 /*yield*/, httpClient(persistAsync.url, constructFetchInit(payload))];
109
+ case 1:
110
+ response = _a.sent();
111
+ if (!response.ok) {
112
+ // eslint-disable-next-line @typescript-eslint/return-await
113
+ return [2 /*return*/, handleHTTPError(response)];
114
+ }
115
+ return [4 /*yield*/, response.json()];
116
+ case 2:
117
+ jsonResponse = _a.sent();
118
+ if (isObject(jsonResponse)) {
119
+ id = jsonResponse[persistAsync.idProperty];
120
+ if (isString(id) || isNumber(id)) {
121
+ return [2 /*return*/, { data: id }];
122
+ }
123
+ }
124
+ return [2 /*return*/, handleError()];
125
+ case 3:
126
+ error_1 = _a.sent();
127
+ return [2 /*return*/, handleError(error_1)];
128
+ case 4: return [2 /*return*/];
129
+ }
130
+ });
131
+ });
132
+ }
133
+ function handleHTTPError(response) {
134
+ return __awaiter(this, void 0, void 0, function () {
135
+ var jsonResponse, error;
136
+ return __generator(this, function (_a) {
137
+ switch (_a.label) {
138
+ case 0:
139
+ if (!(response.status === 422)) return [3 /*break*/, 2];
140
+ return [4 /*yield*/, response.json()];
141
+ case 1:
142
+ jsonResponse = _a.sent();
143
+ if (isObject(jsonResponse)) {
144
+ error = getErrorFromResponse(persistAsync.param, jsonResponse);
145
+ if (isString(error)) {
146
+ throw new Error(error);
147
+ }
148
+ }
149
+ _a.label = 2;
150
+ case 2: throw new Error(intl.formatMessage(messages.genericErrorRetryHint));
151
+ }
152
+ });
153
+ });
154
+ }
155
+ var handleError = function (error) {
156
+ var message = hasStringMessage(error)
157
+ ? error.message
158
+ : intl.formatMessage(messages.genericErrorRetryHint);
159
+ throw new Error(message);
160
+ };
161
+ return handlePersistAsync;
162
+ };
163
+ function wrapInFormData(key, value) {
164
+ var formData = new FormData();
165
+ if (value !== null) {
166
+ formData.append(key, value);
167
+ }
168
+ return formData;
169
+ }
170
+ function hasStringMessage(value) {
171
+ return isObject(value) && 'message' in value && typeof value.message === 'string';
172
+ }
@@ -0,0 +1,51 @@
1
+ import { useEffect, useMemo, useRef } from 'react';
2
+ export function usePolling(_a) {
3
+ var asyncFn = _a.asyncFn, interval = _a.interval, maxAttempts = _a.maxAttempts, maxConsecutiveFails = _a.maxConsecutiveFails, onPollingResponse = _a.onPollingResponse, onFailure = _a.onFailure;
4
+ var onPollingResponseReference = useRef(onPollingResponse);
5
+ var onFailureReference = useRef(onFailure);
6
+ var poll = useMemo(function () {
7
+ return createPollingClosure(asyncFn, maxAttempts, maxConsecutiveFails, function (pollingResponse) { return onPollingResponseReference.current(pollingResponse); }, function () { return onFailureReference.current(); });
8
+ }, [asyncFn, maxAttempts, maxConsecutiveFails]);
9
+ // eslint-disable-next-line consistent-return
10
+ useEffect(function () {
11
+ if (interval > 0) {
12
+ var intervalReference_1 = setInterval(function () {
13
+ poll();
14
+ }, interval);
15
+ return function () { return clearInterval(intervalReference_1); };
16
+ }
17
+ }, [poll, interval]);
18
+ useEffect(function () {
19
+ onPollingResponseReference.current = onPollingResponse;
20
+ onFailureReference.current = onFailure;
21
+ }, [onPollingResponse, onFailure]);
22
+ }
23
+ export function createPollingClosure(asyncFn, maxAttempts, maxConsecutiveFails, onPollingResponse, onFailure) {
24
+ var isPolling = true;
25
+ var consecutiveFailures = 0;
26
+ var attemptCount = 0;
27
+ return asyncFn
28
+ ? function () {
29
+ if (isPolling) {
30
+ attemptCount++;
31
+ asyncFn()
32
+ .then(function (pollingResponse) {
33
+ consecutiveFailures = 0;
34
+ isPolling = onPollingResponse(pollingResponse);
35
+ })["catch"](function (error) {
36
+ // do not fail on network errors
37
+ if (error.message !== 'network failed') {
38
+ consecutiveFailures += 1;
39
+ }
40
+ })["finally"](function () {
41
+ if (consecutiveFailures >= maxConsecutiveFails || attemptCount >= maxAttempts) {
42
+ onFailure();
43
+ isPolling = false;
44
+ }
45
+ });
46
+ }
47
+ }
48
+ : function () {
49
+ //
50
+ };
51
+ }
@@ -0,0 +1,8 @@
1
+ import { useEffect, useRef } from 'react';
2
+ export var usePrevious = function (value) {
3
+ var reference = useRef();
4
+ useEffect(function () {
5
+ reference.current = value;
6
+ }, [value]);
7
+ return reference.current;
8
+ };
@@ -0,0 +1,43 @@
1
+ import { useCallback, useMemo } from 'react';
2
+ import { usePolling } from '..';
3
+ import { useHttpClient } from '../../../../common/httpClientContext';
4
+ export function useStepPolling(polling, onAction) {
5
+ var httpClient = useHttpClient();
6
+ var asyncFn = useMemo(function () {
7
+ if (polling) {
8
+ return function () {
9
+ return httpClient(polling.url)
10
+ .then(function (response) {
11
+ if (response.ok) {
12
+ return response
13
+ .json()
14
+ .then(function (pollingResponse) { return pollingResponse; })["catch"](function (error) { return null; });
15
+ }
16
+ throw new Error('failed');
17
+ })["catch"](function (error) {
18
+ throw new Error(error.message === 'failed' ? 'failed' : 'network failed');
19
+ });
20
+ };
21
+ }
22
+ return undefined;
23
+ }, [polling, httpClient]);
24
+ var onPollingResponse = useCallback(function (pollingResponse) {
25
+ if (pollingResponse === null || pollingResponse === void 0 ? void 0 : pollingResponse.action) {
26
+ onAction(pollingResponse.action);
27
+ return false; // stop polling
28
+ }
29
+ return true; // continue polling
30
+ }, [onAction]);
31
+ usePolling({
32
+ asyncFn: asyncFn,
33
+ interval: 1000 * ((polling === null || polling === void 0 ? void 0 : polling.interval) || 0),
34
+ maxAttempts: (polling === null || polling === void 0 ? void 0 : polling.maxAttempts) || 0,
35
+ maxConsecutiveFails: 1,
36
+ onPollingResponse: onPollingResponse,
37
+ onFailure: useCallback(function () {
38
+ if (polling) {
39
+ onAction(polling.onError.action);
40
+ }
41
+ }, [onAction, polling])
42
+ });
43
+ }
@@ -0,0 +1,8 @@
1
+ import { defineMessages } from 'react-intl';
2
+ export default defineMessages({
3
+ required: {
4
+ id: 'dynamicFlows.DefaultErrorMessages.required',
5
+ defaultMessage: 'Please fill out this field.',
6
+ description: 'Customer has left the required field empty'
7
+ }
8
+ });
@@ -0,0 +1,6 @@
1
+ export function isStatus2xx(status) {
2
+ return status >= 200 && status < 300;
3
+ }
4
+ export function isStatus422(status) {
5
+ return status === 422;
6
+ }
@@ -0,0 +1,22 @@
1
+ import { isNumber } from '../validators';
2
+ // function taken from: https://stackoverflow.com/questions/23593052/format-javascript-date-as-yyyy-mm-dd
3
+ function formatDate(date) {
4
+ var d = new Date(date);
5
+ var month = String(d.getMonth() + 1);
6
+ var day = String(d.getDate());
7
+ var year = d.getFullYear();
8
+ var formattedMonth = month.length < 2 ? "0".concat(month) : month;
9
+ var formattedDay = day.length < 2 ? "0".concat(day) : day;
10
+ return [year, formattedMonth, formattedDay].join('-');
11
+ }
12
+ export var dateStringToDate = function (dateString) {
13
+ if (!dateString) {
14
+ return null;
15
+ }
16
+ var _a = dateString.split('-').map(function (number) { return parseInt(number, 10); }), year = _a[0], month = _a[1], date = _a[2];
17
+ if (!isNumber(year) || !isNumber(month) || !isNumber(date)) {
18
+ return null;
19
+ }
20
+ return new Date(year, month - 1, date);
21
+ };
22
+ export var dateToDateString = function (date) { return formatDate(date); };
@@ -0,0 +1,38 @@
1
+ export var debounce = function (callback, waitMs) {
2
+ var timeoutId;
3
+ var lastArgs;
4
+ var clearTimer = function () {
5
+ if (timeoutId) {
6
+ clearTimeout(timeoutId);
7
+ timeoutId = null;
8
+ }
9
+ lastArgs = null;
10
+ };
11
+ var debouncedFn = function () {
12
+ var args = [];
13
+ for (var _i = 0; _i < arguments.length; _i++) {
14
+ args[_i] = arguments[_i];
15
+ }
16
+ lastArgs = args;
17
+ if (timeoutId !== null) {
18
+ clearTimeout(timeoutId);
19
+ }
20
+ timeoutId = setTimeout(function () {
21
+ callback.apply(void 0, lastArgs);
22
+ timeoutId = null;
23
+ lastArgs = null;
24
+ }, waitMs);
25
+ };
26
+ debouncedFn.cancel = function () {
27
+ if (timeoutId !== null) {
28
+ clearTimer();
29
+ }
30
+ };
31
+ debouncedFn.flush = function () {
32
+ if (timeoutId !== null) {
33
+ callback.apply(void 0, lastArgs);
34
+ clearTimer();
35
+ }
36
+ };
37
+ return debouncedFn;
38
+ };
@@ -0,0 +1,45 @@
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
+ export function toKilobytes(sizeInBytes) {
13
+ var ONE_KB_IN_BYTES = 1024;
14
+ return Math.floor(sizeInBytes / ONE_KB_IN_BYTES);
15
+ }
16
+ // TODO: Refactor: This is duplicate logic as in CameraStep.tsx
17
+ export var toBase64 = function (file) {
18
+ return new Promise(function (resolve, reject) {
19
+ // we can safely assume the type of reader.result is string
20
+ // because we're calling reader.readAsDataURL
21
+ // https://developer.mozilla.org/en-US/docs/Web/API/FileReader/result
22
+ var reader = new FileReader();
23
+ reader.readAsDataURL(file);
24
+ reader.addEventListener('load', function () { return resolve(reader.result); });
25
+ reader.addEventListener('error', function (error) { return reject(error); });
26
+ });
27
+ };
28
+ export function areFilesSame(newFiles, files) {
29
+ var fileIdToExistingFileMap = files.reduce(function (map, fileObject) {
30
+ var _a;
31
+ return (__assign(__assign({}, map), (_a = {}, _a[fileObject.id] = fileObject, _a)));
32
+ }, {});
33
+ for (var _i = 0, newFiles_1 = newFiles; _i < newFiles_1.length; _i++) {
34
+ var newFile = newFiles_1[_i];
35
+ var existingFileObject = fileIdToExistingFileMap[newFile.id];
36
+ var fileDoesNotExistAlready = !existingFileObject;
37
+ if (fileDoesNotExistAlready) {
38
+ return false;
39
+ }
40
+ if (existingFileObject.status !== newFile.status) {
41
+ return false;
42
+ }
43
+ }
44
+ return true;
45
+ }
@@ -0,0 +1,5 @@
1
+ export var generateRandomId = function (prefix) {
2
+ if (prefix === void 0) { prefix = ''; }
3
+ var prefixString = prefix ? "".concat(prefix, "-") : '';
4
+ return "".concat(prefixString).concat(Math.floor(100000000 * Math.random()));
5
+ };
@@ -0,0 +1,11 @@
1
+ export * from './api-utils';
2
+ export * from './date-utils';
3
+ export * from './debounce';
4
+ export * from './is-equal';
5
+ export * from './file-utils';
6
+ export * from './id-utils';
7
+ export * from './step-utils';
8
+ export * from './model-utils';
9
+ export * from './misc-utils';
10
+ export * from './schema-utils';
11
+ export * from './mobile-utils';
@@ -0,0 +1,21 @@
1
+ export var isEqual = function (a, b) {
2
+ if (a === b) {
3
+ return true;
4
+ }
5
+ if (Array.isArray(a) && Array.isArray(b)) {
6
+ return a.length === b.length && a.every(function (item, index) { return isEqual(item, b[index]); });
7
+ }
8
+ if (isNonNullObject(a) && isNonNullObject(b) && isObjectEquals(a, b)) {
9
+ return true;
10
+ }
11
+ return false;
12
+ };
13
+ var isObjectEquals = function (a, b) {
14
+ var keysA = Object.keys(a);
15
+ var keysB = Object.keys(b);
16
+ return (keysA.length === keysB.length &&
17
+ keysA.every(function (key) { return Object.hasOwnProperty.call(b, key) && isEqual(a[key], b[key]); }));
18
+ };
19
+ var isNonNullObject = function (a) {
20
+ return typeof a === 'object' && a !== null;
21
+ };
@@ -0,0 +1,4 @@
1
+ import { isNull, isString } from '../validators';
2
+ export var isBasicError = function (error) {
3
+ return isString(error) || isNull(error);
4
+ };
@@ -0,0 +1,23 @@
1
+ export var isMobile = function () { return isMobileScreenSize() && (isTouchScreen() || isMobileUA()); };
2
+ export var isMobileUA = function (userAgent) {
3
+ if (userAgent === void 0) { userAgent = window.navigator.userAgent; }
4
+ // eslint-disable-next-line regexp/no-unused-capturing-group
5
+ return /mobi|\b(iphone|android|blackberry|webos|windows phone)\b/i.test(userAgent);
6
+ };
7
+ export var isMobileScreenSize = function (width, height) {
8
+ if (width === void 0) { width = window.screen.width; }
9
+ if (height === void 0) { height = window.screen.height; }
10
+ return width < 768 || height < 768;
11
+ };
12
+ export var isTouchScreen = function (navigator, matchMedia) {
13
+ if (navigator === void 0) { navigator = window.navigator; }
14
+ if (matchMedia === void 0) { matchMedia = window.matchMedia; }
15
+ if ('maxTouchPoints' in navigator) {
16
+ return navigator.maxTouchPoints > 0;
17
+ }
18
+ var mQ = matchMedia === null || matchMedia === void 0 ? void 0 : matchMedia('(pointer:coarse)');
19
+ if ((mQ === null || mQ === void 0 ? void 0 : mQ.media) === '(pointer:coarse)') {
20
+ return Boolean(mQ.matches);
21
+ }
22
+ return false;
23
+ };
@@ -0,0 +1,33 @@
1
+ import { isArray, isBoolean, isNull, isNumber, isString } from '../validators';
2
+ export var isObjectModel = function (model) {
3
+ return typeof model === 'object' && model !== null && model.constructor === Object;
4
+ };
5
+ export var isNullableObjectModel = function (model) {
6
+ return isNull(model) || isObjectModel(model);
7
+ };
8
+ export var isNullableBasicModel = function (model) {
9
+ return isBoolean(model) || isNumber(model) || isString(model) || isNull(model);
10
+ };
11
+ export var isNullableStringModel = function (model) {
12
+ return isString(model) || isNull(model);
13
+ };
14
+ export var isArrayModel = function (model) {
15
+ if (isArray(model)) {
16
+ if (model.length === 0) {
17
+ return true;
18
+ }
19
+ return model.every(function (item) {
20
+ return typeof item === 'string' ||
21
+ typeof item === 'number' ||
22
+ typeof item === 'boolean' ||
23
+ typeof item === 'object';
24
+ });
25
+ }
26
+ return false;
27
+ };
28
+ export var isNullableArrayModel = function (model) {
29
+ if (isNull(model)) {
30
+ return true;
31
+ }
32
+ return isArrayModel(model);
33
+ };
@@ -0,0 +1,97 @@
1
+ import { isObject, isUndefined } from '../validators';
2
+ export function isConstSchema(schema) {
3
+ return !isUndefined(schema === null || schema === void 0 ? void 0 : schema["const"]);
4
+ }
5
+ export function isNoNConstSchema(schema) {
6
+ return Boolean(schema) && !isConstSchema(schema);
7
+ }
8
+ export var isReadOnlySchema = function (schema) {
9
+ return Boolean(schema.readOnly) && isBasicSchema(schema);
10
+ };
11
+ export var isPromotedOneOfSchema = function (schema) {
12
+ return Boolean(schema.oneOf) && Boolean(schema.promotion);
13
+ };
14
+ export var basicTypes = new Set(['string', 'number', 'integer', 'boolean']);
15
+ export function isBasicSchema(schema) {
16
+ return (basicTypes.has(schema.type || '') ||
17
+ ('const' in schema && schema["const"] !== undefined && !isObject(schema["const"])));
18
+ }
19
+ export function isObjectSchema(schema) {
20
+ return schema.type === 'object';
21
+ }
22
+ export function isOneOfObjectSchema(schema) {
23
+ return isOneOfSchema(schema) && schema.oneOf.every(function (subSchema) { return subSchema.type === 'object'; });
24
+ }
25
+ export function isOneOfSchema(schema) {
26
+ return Boolean(schema.oneOf);
27
+ }
28
+ export function isAllOfSchema(schema) {
29
+ return Boolean(schema.allOf);
30
+ }
31
+ export function isBlobSchema(schema) {
32
+ return schema.type === 'blob';
33
+ }
34
+ export function isArraySchema(schema) {
35
+ return schema.type === 'array';
36
+ }
37
+ export function isTupleArraySchema(schema) {
38
+ var schemaItems = schema.items;
39
+ return Array.isArray(schemaItems);
40
+ }
41
+ export function isListArraySchema(schema) {
42
+ var schemaItems = schema.items;
43
+ return !Array.isArray(schemaItems);
44
+ }
45
+ export function isStringSchema(schema) {
46
+ return schema.type === 'string';
47
+ }
48
+ export function isPersistAsyncSchema(schema) {
49
+ return Boolean(schema.persistAsync);
50
+ }
51
+ export function isPersistAsyncFileSchema(schema) {
52
+ return (isPersistAsyncSchema(schema) &&
53
+ (isBlobSchema(schema.persistAsync.schema) || isBase64FileSchema(schema.persistAsync.schema)));
54
+ }
55
+ export var isValidationAsyncSchema = function (schema) {
56
+ return isBasicSchema(schema) && Boolean(schema.validationAsync);
57
+ };
58
+ function isBase64FileSchema(schema) {
59
+ return schema.type === 'string' && schema.format === 'base64url';
60
+ }
61
+ export function isFileUploadSchema(schema) {
62
+ return schema.type === 'string' && schema.format === 'base64url';
63
+ }
64
+ export var isMultipleFileUploadSchema = function (schema) {
65
+ return isArraySchema(schema) && isListArraySchema(schema) && isPersistAsyncFileSchema(schema.items);
66
+ };
67
+ export var getSchemaType = function (schema) {
68
+ // Order of application is important here
69
+ if (isReadOnlySchema(schema)) {
70
+ return 'readOnly';
71
+ }
72
+ if (isPersistAsyncSchema(schema)) {
73
+ return 'persistAsync';
74
+ }
75
+ if (isValidationAsyncSchema(schema)) {
76
+ return 'validationAsync';
77
+ }
78
+ if (isObjectSchema(schema)) {
79
+ return 'object';
80
+ }
81
+ if (isArraySchema(schema)) {
82
+ return 'array';
83
+ }
84
+ if (isPromotedOneOfSchema(schema)) {
85
+ return 'promotedOneOf';
86
+ }
87
+ if (isOneOfSchema(schema)) {
88
+ return 'oneOf';
89
+ }
90
+ if (isAllOfSchema(schema)) {
91
+ return 'allOf';
92
+ }
93
+ if (isBasicSchema(schema)) {
94
+ return 'basic';
95
+ }
96
+ return null;
97
+ };
@@ -0,0 +1,32 @@
1
+ import { isObjectSchema, isFileUploadSchema } from './schema-utils';
2
+ export var isCameraStep = function (step) {
3
+ return isFormStep(step) && hasSingleAction(step) && hasSingleFileUploadSchemaWithCameraOnly(step);
4
+ };
5
+ var isFormStep = function (step) { return !step.type || step.type === 'form'; };
6
+ var hasSingleAction = function (step) { var _a; return ((_a = step === null || step === void 0 ? void 0 : step.actions) === null || _a === void 0 ? void 0 : _a.length) === 1; };
7
+ var hasSingleFileUploadSchemaWithCameraOnly = function (step) {
8
+ if (!step.schemas) {
9
+ return false;
10
+ }
11
+ var schemas = filterHiddenSchemas(step.schemas);
12
+ if ((schemas === null || schemas === void 0 ? void 0 : schemas.length) !== 1) {
13
+ return false;
14
+ }
15
+ var firstSchema = schemas[0];
16
+ if (!isObjectSchema(firstSchema) || Object.values(firstSchema.properties).length !== 1) {
17
+ return false;
18
+ }
19
+ var childSchema = Object.values(firstSchema.properties)[0];
20
+ if (!isFileUploadSchema(childSchema)) {
21
+ return false;
22
+ }
23
+ return childSchema.source === 'camera';
24
+ };
25
+ export var filterHiddenSchemas = function (schemas) {
26
+ return schemas.filter(function (schema) {
27
+ if (isObjectSchema(schema)) {
28
+ return Object.values((schema === null || schema === void 0 ? void 0 : schema.properties) || {}).find(function (schema) { return (schema === null || schema === void 0 ? void 0 : schema.hidden) !== true; });
29
+ }
30
+ return (schema === null || schema === void 0 ? void 0 : schema.hidden) !== true;
31
+ });
32
+ };
@@ -0,0 +1,5 @@
1
+ export { getValidModelParts, getValidObjectModelParts, getValidBasicModelOrNull, } from './models/model-validators';
2
+ export { isValidSchema } from './schemas/schema-validators';
3
+ export { getValidationFailures, getArrayValidationFailures, } from './validationFailures/validation-failures';
4
+ export * from './types/type-validators';
5
+ export * from './values/value-validators';