@wise/dynamic-flow-client 0.4.0 → 0.4.2

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 (233) hide show
  1. package/build/common/constants/DateMode.js +2 -2
  2. package/build/common/constants/FormControlType.js +2 -2
  3. package/build/common/constants/MonthFormat.js +2 -2
  4. package/build/common/constants/SchemaType.js +2 -2
  5. package/build/common/constants/Size.js +2 -2
  6. package/build/common/constants/index.js +1 -1
  7. package/build/common/contexts/dynamicFlowContexts/DynamicFlowContexts.js +15 -27
  8. package/build/common/contexts/dynamicFlowContexts/usePendingPromiseCounter.js +11 -9
  9. package/build/common/contexts/eventsContext/EventsContext.js +11 -28
  10. package/build/common/contexts/fetcherContexts/FetcherContexts.js +14 -27
  11. package/build/common/contexts/index.js +1 -1
  12. package/build/common/contexts/logContext/LogContext.js +12 -30
  13. package/build/common/hooks/index.js +1 -1
  14. package/build/common/hooks/useDebouncedFunction/useDebouncedFunction.js +3 -3
  15. package/build/common/hooks/useExternal/useExternal.js +8 -8
  16. package/build/common/hooks/useExternalStepPolling/useExternalStepPolling.js +20 -31
  17. package/build/common/hooks/usePersistAsync/usePersistAsync.js +60 -139
  18. package/build/common/hooks/usePolling/usePolling.js +20 -21
  19. package/build/common/hooks/usePrevious/usePrevious.js +5 -5
  20. package/build/common/hooks/useStepPolling/useStepPolling.js +15 -14
  21. package/build/common/makeFetcher/index.js +1 -1
  22. package/build/common/makeFetcher/makeFetcher.js +10 -24
  23. package/build/common/messages.js +5 -5
  24. package/build/common/utils/api-utils.js +3 -4
  25. package/build/common/utils/date-utils.js +11 -11
  26. package/build/common/utils/debounce.js +11 -15
  27. package/build/common/utils/file-utils.js +12 -25
  28. package/build/common/utils/id-utils.js +4 -5
  29. package/build/common/utils/index.js +1 -1
  30. package/build/common/utils/is-equal.js +8 -8
  31. package/build/common/utils/schema-utils.js +6 -6
  32. package/build/common/utils/step-utils.js +14 -14
  33. package/build/common/validators/index.js +7 -7
  34. package/build/common/validators/models/model-validators.js +8 -8
  35. package/build/common/validators/models/models.utils.js +29 -42
  36. package/build/common/validators/schemas/schema-validators.js +11 -13
  37. package/build/common/validators/types/type-validators.js +9 -13
  38. package/build/common/validators/validationFailures/validation-failures.js +14 -14
  39. package/build/common/validators/validationFailures/validation-failures.utils.js +5 -7
  40. package/build/common/validators/values/value-validators.js +4 -6
  41. package/build/dynamicFlow/DynamicFlow.js +185 -307
  42. package/build/dynamicFlow/DynamicFlowStep.js +12 -23
  43. package/build/dynamicFlow/DynamicFlowTypes.js +1 -1
  44. package/build/dynamicFlow/index.js +6 -14
  45. package/build/dynamicFlow/stories/DynamicFlow.story.js +20 -20
  46. package/build/dynamicFlow/stories/EditableDynamicFlow.js +20 -33
  47. package/build/dynamicFlow/stories/fixtureFetcher.js +46 -104
  48. package/build/dynamicFlow/utils/errorBoundary/ErrorBoundary.js +22 -40
  49. package/build/dynamicFlow/utils/errorBoundary/ErrorBoundary.messages.js +6 -6
  50. package/build/dynamicFlow/utils/errorBoundary/ErrorBoundaryAlert.js +10 -11
  51. package/build/dynamicFlow/utils/index.js +5 -2
  52. package/build/dynamicFlow/utils/responseParsers/response-parsers.js +53 -118
  53. package/build/dynamicFlow/utils/useDebouncedRefresh/useDebouncedRefresh.js +9 -9
  54. package/build/dynamicFlow/utils/useDynamicFlowState.js +51 -74
  55. package/build/dynamicFlow/utils/useLoader.js +9 -20
  56. package/build/fixtures/components/alert.js +8 -8
  57. package/build/fixtures/components/box.js +7 -7
  58. package/build/fixtures/components/button.js +25 -36
  59. package/build/fixtures/components/columns.js +10 -10
  60. package/build/fixtures/components/copyable.js +6 -6
  61. package/build/fixtures/components/decision.js +15 -15
  62. package/build/fixtures/components/heading.js +7 -7
  63. package/build/fixtures/components/image.js +10 -10
  64. package/build/fixtures/components/index.js +17 -25
  65. package/build/fixtures/components/info.js +22 -6
  66. package/build/fixtures/components/list.js +8 -8
  67. package/build/fixtures/components/loading-indicator.js +5 -5
  68. package/build/fixtures/components/paragraph.js +9 -9
  69. package/build/fixtures/components/review.js +11 -11
  70. package/build/fixtures/examples/camera-capture.js +29 -29
  71. package/build/fixtures/examples/index.js +9 -17
  72. package/build/fixtures/examples/recipient-update.js +69 -69
  73. package/build/fixtures/examples/recipient.js +63 -63
  74. package/build/fixtures/examples/single-file-upload.js +21 -21
  75. package/build/fixtures/examples/step-validation-errors.js +21 -21
  76. package/build/fixtures/features/action-response.js +8 -8
  77. package/build/fixtures/features/external.js +8 -8
  78. package/build/fixtures/features/index.js +9 -17
  79. package/build/fixtures/features/persist-async.js +11 -11
  80. package/build/fixtures/features/polling.js +9 -9
  81. package/build/fixtures/features/validation-async.js +10 -10
  82. package/build/fixtures/index.js +11 -22
  83. package/build/fixtures/jsonSchemaForm/allOf.js +30 -30
  84. package/build/fixtures/jsonSchemaForm/audRecipient.js +271 -271
  85. package/build/fixtures/jsonSchemaForm/currency.js +12 -12
  86. package/build/fixtures/jsonSchemaForm/multipleFileUploadBase64.js +11 -11
  87. package/build/fixtures/jsonSchemaForm/multipleFileUploadBlob.js +11 -11
  88. package/build/fixtures/jsonSchemaForm/oneOf.js +27 -27
  89. package/build/fixtures/jsonSchemaForm/oneOfTabs.js +16 -16
  90. package/build/fixtures/jsonSchemaForm/promotedOneOf.js +17 -17
  91. package/build/fixtures/jsonSchemaForm/promotedOneOfCheckbox.js +30 -30
  92. package/build/fixtures/jsonSchemaForm/simple.js +16 -16
  93. package/build/fixtures/jsonSchemaForm/uploadPersistAsync.js +19 -19
  94. package/build/fixtures/jsonSchemaForm/validationAsync.js +8 -8
  95. package/build/fixtures/layouts/all.js +37 -37
  96. package/build/fixtures/layouts/final-step-layout.js +9 -9
  97. package/build/fixtures/layouts/index.js +10 -18
  98. package/build/fixtures/layouts/list.js +10 -10
  99. package/build/fixtures/layouts/pay-in.js +23 -23
  100. package/build/fixtures/layouts/review.js +38 -38
  101. package/build/fixtures/layouts/success.js +15 -15
  102. package/build/fixtures/responses/action-response-final.js +8 -8
  103. package/build/fixtures/responses/action.js +3 -3
  104. package/build/fixtures/responses/exit.js +3 -3
  105. package/build/fixtures/responses/index.js +8 -16
  106. package/build/fixtures/responses/recipient-update-final.js +8 -8
  107. package/build/fixtures/schemas/basic-form.js +11 -11
  108. package/build/fixtures/schemas/index.js +8 -16
  109. package/build/fixtures/schemas/number-and-integer.js +11 -11
  110. package/build/fixtures/schemas/one-of.js +43 -46
  111. package/build/fixtures/schemas/string-formats.js +15 -15
  112. package/build/fixtures/utils/image-util.js +8 -8
  113. package/build/formControl/FormControl.js +118 -148
  114. package/build/formControl/index.js +6 -14
  115. package/build/formControl/utils/index.js +1 -1
  116. package/build/formControl/utils/value-utils.js +18 -23
  117. package/build/i18n/index.js +31 -31
  118. package/build/index.js +13 -10
  119. package/build/jsonSchemaForm/JsonSchemaForm.js +12 -24
  120. package/build/jsonSchemaForm/allOfSchema/AllOfSchema.js +24 -37
  121. package/build/jsonSchemaForm/allOfSchema/index.js +6 -14
  122. package/build/jsonSchemaForm/arrayTypeSchema/ArraySchema.js +9 -20
  123. package/build/jsonSchemaForm/arrayTypeSchema/arrayListSchema/ArrayListSchema.js +9 -20
  124. package/build/jsonSchemaForm/arrayTypeSchema/arrayListSchema/index.js +6 -14
  125. package/build/jsonSchemaForm/arrayTypeSchema/arrayListSchema/multipleFileUploadSchema/MultipleFileUploadSchema.js +56 -115
  126. package/build/jsonSchemaForm/arrayTypeSchema/arrayListSchema/multipleFileUploadSchema/MultipleFileUploadSchema.messages.js +7 -7
  127. package/build/jsonSchemaForm/arrayTypeSchema/arrayListSchema/multipleFileUploadSchema/index.js +6 -14
  128. package/build/jsonSchemaForm/arrayTypeSchema/arrayListSchema/multipleFileUploadSchema/utils/index.js +1 -1
  129. package/build/jsonSchemaForm/arrayTypeSchema/arrayListSchema/multipleFileUploadSchema/utils/upload-utils.js +19 -71
  130. package/build/jsonSchemaForm/arrayTypeSchema/arrayListSchema/multipleFileUploadSchema/utils/useFormattedDefaultErrorMessages.js +10 -11
  131. package/build/jsonSchemaForm/arrayTypeSchema/index.js +6 -14
  132. package/build/jsonSchemaForm/basicTypeSchema/BasicTypeSchema.js +45 -62
  133. package/build/jsonSchemaForm/basicTypeSchema/index.js +6 -14
  134. package/build/jsonSchemaForm/controlFeedback/ControlFeedback.js +39 -50
  135. package/build/jsonSchemaForm/controlFeedback/ControlFeedback.messages.js +18 -18
  136. package/build/jsonSchemaForm/controlFeedback/index.js +6 -14
  137. package/build/jsonSchemaForm/genericSchema/GenericSchema.js +52 -61
  138. package/build/jsonSchemaForm/genericSchema/index.js +6 -14
  139. package/build/jsonSchemaForm/help/Help.js +9 -9
  140. package/build/jsonSchemaForm/help/Help.messages.js +5 -5
  141. package/build/jsonSchemaForm/help/index.js +6 -14
  142. package/build/jsonSchemaForm/index.js +6 -14
  143. package/build/jsonSchemaForm/objectSchema/ObjectSchema.js +28 -49
  144. package/build/jsonSchemaForm/objectSchema/index.js +6 -14
  145. package/build/jsonSchemaForm/oneOfSchema/OneOfSchema.js +54 -74
  146. package/build/jsonSchemaForm/oneOfSchema/index.js +6 -14
  147. package/build/jsonSchemaForm/oneOfSchema/utils/const-schema-utils.js +3 -3
  148. package/build/jsonSchemaForm/oneOfSchema/utils/index.js +1 -1
  149. package/build/jsonSchemaForm/oneOfSchema/utils/one-of-utils.js +19 -20
  150. package/build/jsonSchemaForm/persistAsyncSchema/PersistAsyncSchema.js +11 -22
  151. package/build/jsonSchemaForm/persistAsyncSchema/PersistAsyncSchema.messages.js +5 -5
  152. package/build/jsonSchemaForm/persistAsyncSchema/index.js +6 -14
  153. package/build/jsonSchemaForm/persistAsyncSchema/persistAsyncBasicSchema/PersistAsyncBasicSchema.js +73 -127
  154. package/build/jsonSchemaForm/persistAsyncSchema/persistAsyncBasicSchema/index.js +6 -14
  155. package/build/jsonSchemaForm/persistAsyncSchema/persistAsyncBlobSchema/PersistAsyncBlobSchema.js +45 -110
  156. package/build/jsonSchemaForm/persistAsyncSchema/persistAsyncBlobSchema/UploadInputAdapter.js +17 -17
  157. package/build/jsonSchemaForm/persistAsyncSchema/persistAsyncBlobSchema/index.js +6 -14
  158. package/build/jsonSchemaForm/promotedOneOfSchema/PromotedOneOfSchema.js +28 -47
  159. package/build/jsonSchemaForm/promotedOneOfSchema/index.js +6 -14
  160. package/build/jsonSchemaForm/promotedOneOfSchema/promoted-one-of-utils.js +4 -4
  161. package/build/jsonSchemaForm/promotedOneOfSchema/promotedOneOfControl/PromotedOneOfCheckboxControl.js +13 -24
  162. package/build/jsonSchemaForm/promotedOneOfSchema/promotedOneOfControl/PromotedOneOfControl.js +11 -22
  163. package/build/jsonSchemaForm/promotedOneOfSchema/promotedOneOfControl/PromotedOneOfRadioControl.js +12 -23
  164. package/build/jsonSchemaForm/readOnlySchema/ReadOnlySchema.js +24 -26
  165. package/build/jsonSchemaForm/readOnlySchema/ReadOnlySchema.messages.js +6 -6
  166. package/build/jsonSchemaForm/readOnlySchema/index.js +6 -14
  167. package/build/jsonSchemaForm/schemaFormControl/SchemaFormControl.js +26 -39
  168. package/build/jsonSchemaForm/schemaFormControl/index.js +6 -14
  169. package/build/jsonSchemaForm/schemaFormControl/utils/currency-utils.js +5 -5
  170. package/build/jsonSchemaForm/schemaFormControl/utils/index.js +1 -1
  171. package/build/jsonSchemaForm/schemaFormControl/utils/mapping-utils.js +30 -47
  172. package/build/jsonSchemaForm/validationAsyncSchema/ValidationAsyncSchema.js +57 -119
  173. package/build/jsonSchemaForm/validationAsyncSchema/index.js +6 -14
  174. package/build/layout/DynamicLayout.js +10 -21
  175. package/build/layout/alert/DynamicAlert.js +9 -9
  176. package/build/layout/box/DynamicBox.js +12 -23
  177. package/build/layout/button/DynamicButton.js +16 -27
  178. package/build/layout/columns/DynamicColumns.js +13 -24
  179. package/build/layout/decision/DynamicDecision.js +16 -27
  180. package/build/layout/divider/DynamicDivider.js +7 -8
  181. package/build/layout/external/DynamicExternal.js +16 -28
  182. package/build/layout/external/DynamicExternal.messages.js +5 -5
  183. package/build/layout/form/DynamicForm.js +10 -21
  184. package/build/layout/heading/DynamicHeading.js +12 -23
  185. package/build/layout/icon/DynamicIcon.js +9 -10
  186. package/build/layout/image/DynamicImage.js +43 -93
  187. package/build/layout/index.js +21 -29
  188. package/build/layout/info/DynamicInfo.js +7 -19
  189. package/build/layout/list/DynamicList.js +14 -26
  190. package/build/layout/loadingIndicator/DynamicLoadingIndicator.js +8 -9
  191. package/build/layout/paragraph/DynamicParagraph.js +19 -37
  192. package/build/layout/paragraph/DynamicParagraph.messages.js +6 -6
  193. package/build/layout/paragraph/useSnackBarIfAvailable.js +4 -4
  194. package/build/layout/review/DynamicReview.js +14 -26
  195. package/build/layout/utils.js +4 -6
  196. package/build/step/cameraStep/CameraStep.js +42 -88
  197. package/build/step/cameraStep/cameraCapture/CameraCapture.js +48 -105
  198. package/build/step/cameraStep/cameraCapture/CameraCapture.messages.js +7 -7
  199. package/build/step/cameraStep/cameraCapture/components/index.js +10 -28
  200. package/build/step/cameraStep/cameraCapture/hooks/index.js +17 -72
  201. package/build/step/cameraStep/cameraCapture/index.js +6 -14
  202. package/build/step/cameraStep/cameraCapture/overlay/Overlay.js +33 -45
  203. package/build/step/cameraStep/cameraCapture/screens/CameraNotSupported/CameraNotSupported.js +8 -19
  204. package/build/step/cameraStep/cameraCapture/screens/CameraNotSupported/CameraNotSupported.messages.js +6 -6
  205. package/build/step/cameraStep/cameraCapture/screens/NoCameraAccess/NoCameraAccess.js +9 -21
  206. package/build/step/cameraStep/cameraCapture/screens/NoCameraAccess/NoCameraAccess.messages.js +7 -7
  207. package/build/step/cameraStep/cameraCapture/screens/index.js +6 -14
  208. package/build/step/cameraStep/cameraCapture/tracking/index.js +17 -99
  209. package/build/step/cameraStep/cameraCapture/utils/index.js +33 -96
  210. package/build/step/cameraStep/index.js +6 -14
  211. package/build/step/externalConfirmationStep/ExternalConfirmationStep.js +20 -21
  212. package/build/step/externalConfirmationStep/ExternalConfirmationStep.messages.js +8 -8
  213. package/build/step/externalConfirmationStep/index.js +6 -14
  214. package/build/step/index.js +7 -15
  215. package/build/step/layoutStep/LayoutStep.js +19 -19
  216. package/build/step/layoutStep/index.js +6 -14
  217. package/build/step/layoutStep/utils/index.js +3 -14
  218. package/build/step/layoutStep/utils/inline-reference-utils.js +29 -46
  219. package/build/step/layoutStep/utils/layout-utils.js +34 -53
  220. package/build/types/common/FormControl.js +1 -1
  221. package/build/types/index.js +13 -13
  222. package/build/types/specification/Action.js +1 -1
  223. package/build/types/specification/FileUploadSchema.js +1 -1
  224. package/build/types/specification/LayoutComponent.js +1 -1
  225. package/build/types/specification/Model.js +9 -17
  226. package/build/types/specification/PersistAsync.js +1 -1
  227. package/build/types/specification/Polling.js +1 -1
  228. package/build/types/specification/Promotion.js +1 -1
  229. package/build/types/specification/Schema.js +8 -8
  230. package/build/types/specification/Step.js +3 -5
  231. package/build/types/specification/ValidationAsync.js +1 -1
  232. package/build/types/specification/core.js +1 -1
  233. package/package.json +1 -1
@@ -1,131 +1,66 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __generator = (this && this.__generator) || function (thisArg, body) {
12
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
- function verb(n) { return function (v) { return step([n, v]); }; }
15
- function step(op) {
16
- if (f) throw new TypeError("Generator is already executing.");
17
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
- 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;
19
- if (y = 0, t) op = [op[0] & 2, t.value];
20
- switch (op[0]) {
21
- case 0: case 1: t = op; break;
22
- case 4: _.label++; return { value: op[1], done: false };
23
- case 5: _.label++; y = op[1]; op = [0]; continue;
24
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
- default:
26
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
- if (t[2]) _.ops.pop();
31
- _.trys.pop(); continue;
32
- }
33
- op = body.call(thisArg, _);
34
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
- }
37
- };
38
- exports.__esModule = true;
2
+ Object.defineProperty(exports, "__esModule", { value: true });
39
3
  exports.parseExitResponse = exports.parseErrorResponse = exports.parseFetchResponse = void 0;
40
- var validators_1 = require("../../../common/validators");
41
- var parseFetchResponse = function (response) { return __awaiter(void 0, void 0, void 0, function () {
42
- var jsonBody, action, etag;
4
+ const validators_1 = require("../../../common/validators");
5
+ const parseFetchResponse = async (response) => {
43
6
  var _a;
44
- var _b;
45
- return __generator(this, function (_c) {
46
- switch (_c.label) {
47
- case 0:
48
- assertResponseIsValid(response);
49
- if (!((_b = response.headers) === null || _b === void 0 ? void 0 : _b.has('X-Df-Exit'))) return [3 /*break*/, 2];
50
- _a = { type: 'exit' };
51
- return [4 /*yield*/, (0, exports.parseExitResponse)(response)];
52
- case 1: return [2 /*return*/, (_a.result = _c.sent(), _a)];
53
- case 2: return [4 /*yield*/, parseResponseJson(response)];
54
- case 3:
55
- jsonBody = _c.sent();
56
- if (!(0, validators_1.isObject)(jsonBody)) {
57
- throw new Error('Incorrect response body in response. Expected an object.');
58
- }
59
- if (jsonBody.action) {
60
- if (!(0, validators_1.isObject)(jsonBody.action)) {
61
- throw new Error('Incorrect response body in action response. Expected an object satisfying the type { action: Action }.');
62
- }
63
- action = jsonBody.action;
64
- if (action.exit === true && (0, validators_1.isObject)(action.result)) {
65
- return [2 /*return*/, { type: 'exit', result: action.result }];
66
- }
67
- return [2 /*return*/, { type: 'action', action: jsonBody.action }];
68
- }
69
- etag = response.headers.get('etag') || undefined;
70
- return [2 /*return*/, { type: 'step', step: jsonBody, etag: etag }];
7
+ assertResponseIsValid(response);
8
+ if ((_a = response.headers) === null || _a === void 0 ? void 0 : _a.has('X-Df-Exit')) {
9
+ return { type: 'exit', result: await (0, exports.parseExitResponse)(response) };
10
+ }
11
+ const jsonBody = await parseResponseJson(response);
12
+ if (!(0, validators_1.isObject)(jsonBody)) {
13
+ throw new Error('Incorrect response body in response. Expected an object.');
14
+ }
15
+ if (jsonBody.action) {
16
+ if (!(0, validators_1.isObject)(jsonBody.action)) {
17
+ throw new Error('Incorrect response body in action response. Expected an object satisfying the type { action: Action }.');
71
18
  }
72
- });
73
- }); };
74
- exports.parseFetchResponse = parseFetchResponse;
75
- var parseErrorResponse = function (response) { return __awaiter(void 0, void 0, void 0, function () {
76
- var jsonBody;
77
- return __generator(this, function (_a) {
78
- switch (_a.label) {
79
- case 0:
80
- assertResponseIsValid(response);
81
- return [4 /*yield*/, parseResponseJson(response)];
82
- case 1:
83
- jsonBody = _a.sent();
84
- if (!(0, validators_1.isObject)(jsonBody)) {
85
- throw new Error('Incorrect response body in error response. Expected an object.');
86
- }
87
- return [2 /*return*/, jsonBody];
19
+ const action = jsonBody.action;
20
+ if (action.exit === true && (0, validators_1.isObject)(action.result)) {
21
+ return { type: 'exit', result: action.result };
88
22
  }
89
- });
90
- }); };
23
+ return { type: 'action', action: jsonBody.action };
24
+ }
25
+ const etag = response.headers.get('etag') || undefined;
26
+ return { type: 'step', step: jsonBody, etag };
27
+ };
28
+ exports.parseFetchResponse = parseFetchResponse;
29
+ const parseErrorResponse = async (response) => {
30
+ assertResponseIsValid(response);
31
+ const jsonBody = await parseResponseJson(response);
32
+ if (!(0, validators_1.isObject)(jsonBody)) {
33
+ throw new Error('Incorrect response body in error response. Expected an object.');
34
+ }
35
+ return jsonBody;
36
+ };
91
37
  exports.parseErrorResponse = parseErrorResponse;
92
- var parseExitResponse = function (response) { return __awaiter(void 0, void 0, void 0, function () {
93
- var result;
94
- return __generator(this, function (_a) {
95
- switch (_a.label) {
96
- case 0:
97
- assertResponseIsValid(response);
98
- return [4 /*yield*/, parseResponseJson(response)];
99
- case 1:
100
- result = _a.sent();
101
- if ((0, validators_1.isObject)(result) || result === null) {
102
- return [2 /*return*/, result];
103
- }
104
- return [2 /*return*/, null];
105
- }
106
- });
107
- }); };
38
+ const parseExitResponse = async (response) => {
39
+ assertResponseIsValid(response);
40
+ const result = await parseResponseJson(response);
41
+ if ((0, validators_1.isObject)(result) || result === null) {
42
+ return result;
43
+ }
44
+ return null;
45
+ };
108
46
  exports.parseExitResponse = parseExitResponse;
109
- var parseResponseJson = function (response) { return __awaiter(void 0, void 0, void 0, function () {
110
- var _a;
111
- return __generator(this, function (_b) {
112
- switch (_b.label) {
113
- case 0:
114
- _b.trys.push([0, 2, , 3]);
115
- return [4 /*yield*/, response.json()];
116
- case 1: return [2 /*return*/, (_b.sent())];
117
- case 2:
118
- _a = _b.sent();
119
- return [2 /*return*/, null];
120
- case 3: return [2 /*return*/];
121
- }
122
- });
123
- }); };
124
- var assertResponseIsValid = function (response) {
125
- if (!(response instanceof Response)) {
47
+ const parseResponseJson = async (response) => {
48
+ try {
49
+ return (await response.json());
50
+ }
51
+ catch (_a) {
52
+ return null;
53
+ }
54
+ };
55
+ const assertResponseIsValid = (response) => {
56
+ if (!isResponse(response)) {
126
57
  throw new Error('Incorrect type of response from fetch. Expected object of type Response.');
127
58
  }
128
59
  if (response.bodyUsed) {
129
60
  throw new Error('The body of the provided Response object has already been used. Every request must respond with a new Response object.');
130
61
  }
131
62
  };
63
+ const isResponse = (response) => typeof response === 'object' &&
64
+ response !== null &&
65
+ 'clone' in response &&
66
+ 'bodyUsed' in response;
@@ -1,23 +1,23 @@
1
1
  "use strict";
2
- exports.__esModule = true;
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.useDebouncedRefresh = void 0;
4
- var react_1 = require("react");
5
- var utils_1 = require("../../../common/utils");
6
- var DEBOUNCE_DELAY = 1000; // milliseconds
4
+ const react_1 = require("react");
5
+ const utils_1 = require("../../../common/utils");
6
+ const DEBOUNCE_DELAY = 1000; // milliseconds
7
7
  function useDebouncedRefresh(fetchRefresh) {
8
- var map = (0, react_1.useRef)(new Map());
9
- var retrieveOrCreate = function (key) {
8
+ const map = (0, react_1.useRef)(new Map());
9
+ const retrieveOrCreate = (key) => {
10
10
  if (map.current.has(key)) {
11
11
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
12
12
  return map.current.get(key);
13
13
  }
14
- var debouncedFetchRefresh = (0, utils_1.debounce)(function (action, data, etag) { return fetchRefresh(action, data, etag); }, DEBOUNCE_DELAY);
14
+ const debouncedFetchRefresh = (0, utils_1.debounce)((action, data, etag) => fetchRefresh(action, data, etag), DEBOUNCE_DELAY);
15
15
  map.current.set(key, debouncedFetchRefresh);
16
16
  return debouncedFetchRefresh;
17
17
  };
18
18
  return function (action, data, etag, schema) {
19
- var key = action.url || '';
20
- var debouncedFetchRefresh = retrieveOrCreate(key);
19
+ const key = action.url || '';
20
+ const debouncedFetchRefresh = retrieveOrCreate(key);
21
21
  void debouncedFetchRefresh(action, data, etag);
22
22
  if (!schema || !(0, utils_1.shouldDebounceSchema)(schema)) {
23
23
  void debouncedFetchRefresh.flush();
@@ -1,109 +1,86 @@
1
1
  "use strict";
2
- var __assign = (this && this.__assign) || function () {
3
- __assign = Object.assign || function(t) {
4
- for (var s, i = 1, n = arguments.length; i < n; i++) {
5
- s = arguments[i];
6
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
- t[p] = s[p];
8
- }
9
- return t;
10
- };
11
- return __assign.apply(this, arguments);
12
- };
13
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
14
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
15
- if (ar || !(i in from)) {
16
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
17
- ar[i] = from[i];
18
- }
19
- }
20
- return to.concat(ar || Array.prototype.slice.call(from));
21
- };
22
- exports.__esModule = true;
2
+ Object.defineProperty(exports, "__esModule", { value: true });
23
3
  exports.useDynamicFlowState = void 0;
24
- var react_1 = require("react");
25
- var validators_1 = require("../../common/validators");
26
- var DynamicFlowTypes_1 = require("../DynamicFlowTypes");
27
- var useDynamicFlowState = function (initialStep) {
4
+ const react_1 = require("react");
5
+ const validators_1 = require("../../common/validators");
6
+ const DynamicFlowTypes_1 = require("../DynamicFlowTypes");
7
+ const useDynamicFlowState = (initialStep) => {
28
8
  var _a, _b;
29
- var _c = (0, react_1.useState)((_a = initialStep === null || initialStep === void 0 ? void 0 : initialStep.errors) === null || _a === void 0 ? void 0 : _a.validation), formErrors = _c[0], setFormErrors = _c[1];
30
- var _d = (0, react_1.useState)((_b = initialStep === null || initialStep === void 0 ? void 0 : initialStep.errors) === null || _b === void 0 ? void 0 : _b.error), globalError = _d[0], setGlobalError = _d[1];
31
- var _e = (0, react_1.useState)({
9
+ const [formErrors, setFormErrors] = (0, react_1.useState)((_a = initialStep === null || initialStep === void 0 ? void 0 : initialStep.errors) === null || _a === void 0 ? void 0 : _a.validation);
10
+ const [globalError, setGlobalError] = (0, react_1.useState)((_b = initialStep === null || initialStep === void 0 ? void 0 : initialStep.errors) === null || _b === void 0 ? void 0 : _b.error);
11
+ const [stepAndModels, setStepAndModels] = (0, react_1.useState)({
32
12
  step: initialStep || undefined,
33
13
  models: (initialStep === null || initialStep === void 0 ? void 0 : initialStep.model)
34
14
  ? buildInitialModels(initialStep.model, getAllSchemas(initialStep))
35
15
  : {},
36
- etag: undefined
37
- }), stepAndModels = _e[0], setStepAndModels = _e[1];
38
- var step = stepAndModels.step, models = stepAndModels.models, etag = stepAndModels.etag;
39
- var setStepAndEtag = function (step, etag) {
16
+ etag: undefined,
17
+ });
18
+ const { step, models, etag } = stepAndModels;
19
+ const setStepAndEtag = (step, etag) => {
40
20
  var _a, _b, _c, _d;
41
- setStepAndModels(function (previous) { return ({
21
+ setStepAndModels((previous) => ({
42
22
  step: step,
43
23
  models: step.model ? buildInitialModels(step.model, getAllSchemas(step)) : previous.models,
44
- etag: etag
45
- }); });
24
+ etag,
25
+ }));
46
26
  setFormErrors((_b = (_a = step === null || step === void 0 ? void 0 : step.errors) === null || _a === void 0 ? void 0 : _a.validation) !== null && _b !== void 0 ? _b : null);
47
27
  setGlobalError((_d = (_c = step === null || step === void 0 ? void 0 : step.errors) === null || _c === void 0 ? void 0 : _c.error) !== null && _d !== void 0 ? _d : null);
48
28
  };
49
- var setSchemaModel = function (schemaId, objectModel, onModelsUpdated) {
50
- setStepAndModels(function (previous) {
51
- var _a;
52
- var updatedModels = __assign(__assign({}, previous.models), (_a = {}, _a[schemaId] = objectModel, _a));
53
- var updatedState = {
29
+ const setSchemaModel = (schemaId, objectModel, onModelsUpdated) => {
30
+ setStepAndModels((previous) => {
31
+ const updatedModels = Object.assign(Object.assign({}, previous.models), { [schemaId]: objectModel });
32
+ const updatedState = {
54
33
  step: previous.step,
55
34
  models: updatedModels,
56
- etag: previous.etag
35
+ etag: previous.etag,
57
36
  };
58
37
  onModelsUpdated(updatedModels);
59
38
  return updatedState;
60
39
  });
61
40
  };
62
- var modelIsValid = (0, react_1.useMemo)(function () { return areModelsValid(models, getAllSchemas(step)); }, [models, step]);
41
+ const modelIsValid = (0, react_1.useMemo)(() => areModelsValid(models, getAllSchemas(step)), [models, step]);
63
42
  return {
64
- formErrors: formErrors,
65
- globalError: globalError,
43
+ formErrors,
44
+ globalError,
66
45
  step: step,
67
- models: models,
68
- etag: etag,
69
- modelIsValid: modelIsValid,
70
- setFormErrors: setFormErrors,
71
- setGlobalError: setGlobalError,
72
- setStepAndEtag: setStepAndEtag,
73
- setSchemaModel: setSchemaModel
46
+ models,
47
+ etag,
48
+ modelIsValid,
49
+ setFormErrors,
50
+ setGlobalError,
51
+ setStepAndEtag,
52
+ setSchemaModel,
74
53
  };
75
54
  };
76
55
  exports.useDynamicFlowState = useDynamicFlowState;
77
- var buildInitialModels = function (model, schemas) {
78
- if (schemas === void 0) { schemas = []; }
79
- return schemas.reduce(function (acc, schema) {
80
- var _a;
56
+ const buildInitialModels = (model, schemas = []) => {
57
+ return schemas.reduce((acc, schema) => {
81
58
  if (!schema.$id) {
82
59
  // TODO: MC-3224
83
60
  // eslint-disable-next-line no-console
84
61
  console.warn('Schema without $id property found.');
85
62
  }
86
- return __assign(__assign({}, acc), (_a = {}, _a[schema.$id || ''] = (0, validators_1.getValidObjectModelParts)(model, schema) || {}, _a));
63
+ return Object.assign(Object.assign({}, acc), { [schema.$id || '']: (0, validators_1.getValidObjectModelParts)(model, schema) || {} });
87
64
  }, {});
88
65
  };
89
- var getAllSchemas = function (step) { return __spreadArray(__spreadArray([], getAllSchemasInLayout((step === null || step === void 0 ? void 0 : step.layout) || []), true), ((step === null || step === void 0 ? void 0 : step.schemas) || []), true); };
90
- var getAllSchemasInLayout = function (components) {
91
- return components.flatMap(function (component) {
92
- switch (component.type) {
93
- case 'columns':
94
- return __spreadArray([], getAllSchemasInLayout(__spreadArray(__spreadArray([], component.left, true), component.right, true)), true);
95
- case 'box':
96
- return getAllSchemasInLayout(component.components);
97
- case 'form':
98
- return (0, DynamicFlowTypes_1.isSchema)(component.schema) ? [component.schema] : [];
99
- default:
100
- return [];
101
- }
102
- });
103
- };
104
- var areModelsValid = function (formModels, schemas) {
105
- if (schemas === void 0) { schemas = []; }
106
- return !(schemas === null || schemas === void 0 ? void 0 : schemas.some(function (schema) {
66
+ const getAllSchemas = (step) => [
67
+ ...getAllSchemasInLayout((step === null || step === void 0 ? void 0 : step.layout) || []),
68
+ ...((step === null || step === void 0 ? void 0 : step.schemas) || []),
69
+ ];
70
+ const getAllSchemasInLayout = (components) => components.flatMap((component) => {
71
+ switch (component.type) {
72
+ case 'columns':
73
+ return [...getAllSchemasInLayout([...component.left, ...component.right])];
74
+ case 'box':
75
+ return getAllSchemasInLayout(component.components);
76
+ case 'form':
77
+ return (0, DynamicFlowTypes_1.isSchema)(component.schema) ? [component.schema] : [];
78
+ default:
79
+ return [];
80
+ }
81
+ });
82
+ const areModelsValid = (formModels, schemas = []) => {
83
+ return !(schemas === null || schemas === void 0 ? void 0 : schemas.some((schema) => {
107
84
  if (!schema.$id) {
108
85
  // TODO: MC-3224
109
86
  // eslint-disable-next-line no-console
@@ -1,26 +1,15 @@
1
1
  "use strict";
2
- var __assign = (this && this.__assign) || function () {
3
- __assign = Object.assign || function(t) {
4
- for (var s, i = 1, n = arguments.length; i < n; i++) {
5
- s = arguments[i];
6
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
- t[p] = s[p];
8
- }
9
- return t;
10
- };
11
- return __assign.apply(this, arguments);
12
- };
13
- exports.__esModule = true;
2
+ Object.defineProperty(exports, "__esModule", { value: true });
14
3
  exports.useLoader = void 0;
15
- var jsx_runtime_1 = require("react/jsx-runtime");
16
- var components_1 = require("@transferwise/components");
17
- var react_1 = require("react");
4
+ const jsx_runtime_1 = require("react/jsx-runtime");
5
+ const components_1 = require("@transferwise/components");
6
+ const react_1 = require("react");
18
7
  function useLoader(loaderConfig, initialState) {
19
- var config = __assign({ size: components_1.Size.EXTRA_LARGE, initial: true, submission: false }, loaderConfig);
20
- var _a = (0, react_1.useState)(initialState), loadingState = _a[0], setLoadingState = _a[1];
21
- var shouldDisplayLoader = (config.initial && loadingState === 'initial') ||
8
+ const config = Object.assign({ size: components_1.Size.EXTRA_LARGE, initial: true, submission: false }, loaderConfig);
9
+ const [loadingState, setLoadingState] = (0, react_1.useState)(initialState);
10
+ const shouldDisplayLoader = (config.initial && loadingState === 'initial') ||
22
11
  (config.submission && loadingState === 'submission');
23
- var loader = shouldDisplayLoader ? ((0, jsx_runtime_1.jsx)(components_1.Loader, { size: config.size, classNames: { 'tw-loader': 'tw-loader m-x-auto' }, "data-testid": "loader" })) : null;
24
- return { loadingState: loadingState, setLoadingState: setLoadingState, loader: loader };
12
+ const loader = shouldDisplayLoader ? ((0, jsx_runtime_1.jsx)(components_1.Loader, { size: config.size, classNames: { 'tw-loader': 'tw-loader m-x-auto' }, "data-testid": "loader" })) : null;
13
+ return { loadingState, setLoadingState, loader };
25
14
  }
26
15
  exports.useLoader = useLoader;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
- exports.__esModule = true;
3
- var step = {
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const step = {
4
4
  type: 'form',
5
5
  key: 'Components/Alert',
6
6
  title: 'Alert Component',
@@ -11,23 +11,23 @@ var step = {
11
11
  {
12
12
  type: 'alert',
13
13
  markdown: 'This is an alert with "neutral" context. A subset of Markdown features are supported, like **bold text**, and __italic__ I think. But no line breaks nor links.',
14
- context: 'neutral'
14
+ context: 'neutral',
15
15
  },
16
16
  {
17
17
  type: 'alert',
18
18
  markdown: 'This is an alert with "warning" context. A subset of Markdown features are supported, like **bold text**, and __italic__ I think. But no line breaks nor links.',
19
- context: 'warning'
19
+ context: 'warning',
20
20
  },
21
21
  {
22
22
  type: 'alert',
23
23
  markdown: 'This is an alert with "positive" context. A subset of Markdown features are supported, like **bold text**, and __italic__ I think. But no line breaks nor links.',
24
- context: 'positive'
24
+ context: 'positive',
25
25
  },
26
26
  {
27
27
  type: 'alert',
28
28
  markdown: 'This is an alert with "negative" context. A subset of Markdown features are supported, like **bold text**, and __italic__ I think. But no line breaks nor links.',
29
- context: 'negative'
29
+ context: 'negative',
30
30
  },
31
- ]
31
+ ],
32
32
  };
33
- exports["default"] = step;
33
+ exports.default = step;
@@ -1,22 +1,22 @@
1
1
  "use strict";
2
- exports.__esModule = true;
3
- var step = {
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const step = {
4
4
  type: 'form',
5
5
  key: 'Components/Box',
6
6
  title: 'Box Component',
7
7
  description: 'Box is a container for other layour components. It can have a border!',
8
8
  actions: [],
9
9
  schemas: [],
10
- layout: ['xs', 'sm', 'md', 'lg', 'xl'].map(function (size) { return ({
10
+ layout: ['xs', 'sm', 'md', 'lg', 'xl'].map((size) => ({
11
11
  type: 'box',
12
12
  width: size,
13
13
  border: true,
14
14
  components: [
15
15
  {
16
16
  type: 'paragraph',
17
- text: "This paragraph is inside a box with border: \"true\" and width: \"".concat(size, "\".")
17
+ text: `This paragraph is inside a box with border: "true" and width: "${size}".`,
18
18
  },
19
- ]
20
- }); })
19
+ ],
20
+ })),
21
21
  };
22
- exports["default"] = step;
22
+ exports.default = step;
@@ -1,27 +1,16 @@
1
1
  "use strict";
2
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
3
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
4
- if (ar || !(i in from)) {
5
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
6
- ar[i] = from[i];
7
- }
8
- }
9
- return to.concat(ar || Array.prototype.slice.call(from));
10
- };
11
- exports.__esModule = true;
12
- var buttons = ['primary', 'secondary', 'negative', 'link'].map(function (type, i) {
13
- return ({
14
- type: 'button',
15
- action: {
16
- url: '/action-url',
17
- method: 'POST',
18
- title: "Button ".concat(i + 1, ", type: \"").concat(type, "\""),
19
- type: type,
20
- data: { 'button-number': i + 1 }
21
- }
22
- });
23
- });
24
- var step = {
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const buttons = ['primary', 'secondary', 'negative', 'link'].map((type, i) => ({
4
+ type: 'button',
5
+ action: {
6
+ url: '/action-url',
7
+ method: 'POST',
8
+ title: `Button ${i + 1}, type: "${type}"`,
9
+ type,
10
+ data: { 'button-number': i + 1 },
11
+ },
12
+ }));
13
+ const step = {
25
14
  type: 'form',
26
15
  key: 'Components/Button',
27
16
  title: 'Button Component',
@@ -35,33 +24,33 @@ var step = {
35
24
  properties: {
36
25
  'form-field': {
37
26
  type: 'string',
38
- "default": 'Some text',
39
- title: 'Enter any text. It will be submitted under "form-field".'
40
- }
41
- }
27
+ default: 'Some text',
28
+ title: 'Enter any text. It will be submitted under "form-field".',
29
+ },
30
+ },
42
31
  },
43
32
  ],
44
33
  layout: [
45
34
  {
46
35
  type: 'box',
47
36
  width: 'md',
48
- components: __spreadArray(__spreadArray([
37
+ components: [
49
38
  {
50
39
  type: 'paragraph',
51
- text: 'Action buttons merge the form data with their own action.data before submitting it to the specified URL.'
40
+ text: 'Action buttons merge the form data with their own action.data before submitting it to the specified URL.',
52
41
  },
53
42
  {
54
43
  type: 'form',
55
- schema: { $ref: '#schema' }
56
- }
57
- ], buttons, true), [
44
+ schema: { $ref: '#schema' },
45
+ },
46
+ ...buttons,
58
47
  {
59
48
  type: 'paragraph',
60
49
  text: 'Press any buttons and see the fetcher calls below.',
61
- align: 'center'
50
+ align: 'center',
62
51
  },
63
- ], false)
52
+ ],
64
53
  },
65
- ]
54
+ ],
66
55
  };
67
- exports["default"] = step;
56
+ exports.default = step;
@@ -1,10 +1,10 @@
1
1
  "use strict";
2
- exports.__esModule = true;
3
- var step = {
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const step = {
4
4
  type: 'form',
5
5
  key: 'Components/Columns',
6
6
  title: 'Columns Component',
7
- description: "Arrange components in two columns (when there's enough space)",
7
+ description: `Arrange components in two columns (when there's enough space)`,
8
8
  actions: [],
9
9
  schemas: [],
10
10
  layout: [
@@ -17,8 +17,8 @@ var step = {
17
17
  title: 'Save',
18
18
  type: 'primary',
19
19
  exit: true,
20
- result: { side: 'left' }
21
- }
20
+ result: { side: 'left' },
21
+ },
22
22
  },
23
23
  ],
24
24
  right: [
@@ -28,11 +28,11 @@ var step = {
28
28
  title: 'Delete',
29
29
  type: 'negative',
30
30
  exit: true,
31
- result: { side: 'right' }
32
- }
31
+ result: { side: 'right' },
32
+ },
33
33
  },
34
- ]
34
+ ],
35
35
  },
36
- ]
36
+ ],
37
37
  };
38
- exports["default"] = step;
38
+ exports.default = step;