@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,173 +1,119 @@
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
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
39
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
40
4
  };
41
- exports.__esModule = true;
5
+ Object.defineProperty(exports, "__esModule", { value: true });
42
6
  exports.getErrorFromResponse = exports.getIdFromResponse = void 0;
43
- var jsx_runtime_1 = require("react/jsx-runtime");
44
- var react_1 = require("react");
45
- var react_intl_1 = require("react-intl");
46
- var constants_1 = require("../../../common/constants");
47
- var contexts_1 = require("../../../common/contexts");
48
- var hooks_1 = require("../../../common/hooks");
49
- var utils_1 = require("../../../common/utils");
50
- var validators_1 = require("../../../common/validators");
51
- var allOf_1 = __importDefault(require("../../../fixtures/jsonSchemaForm/allOf"));
52
- var basicTypeSchema_1 = __importDefault(require("../../basicTypeSchema"));
53
- var SchemaFormControl_1 = require("../../schemaFormControl/SchemaFormControl");
54
- var PersistAsyncSchema_messages_1 = __importDefault(require("../PersistAsyncSchema.messages"));
7
+ const jsx_runtime_1 = require("react/jsx-runtime");
8
+ const react_1 = require("react");
9
+ const react_intl_1 = require("react-intl");
10
+ const constants_1 = require("../../../common/constants");
11
+ const contexts_1 = require("../../../common/contexts");
12
+ const hooks_1 = require("../../../common/hooks");
13
+ const utils_1 = require("../../../common/utils");
14
+ const validators_1 = require("../../../common/validators");
15
+ const allOf_1 = __importDefault(require("../../../fixtures/jsonSchemaForm/allOf"));
16
+ const basicTypeSchema_1 = __importDefault(require("../../basicTypeSchema"));
17
+ const SchemaFormControl_1 = require("../../schemaFormControl/SchemaFormControl");
18
+ const PersistAsyncSchema_messages_1 = __importDefault(require("../PersistAsyncSchema.messages"));
55
19
  // TODO: LOW avoid type assertion below -- consider throwing if return value is not the expected type
56
- var getIdFromResponse = function (idProperty, response) {
20
+ const getIdFromResponse = (idProperty, response) => {
57
21
  return response[idProperty];
58
22
  };
59
23
  exports.getIdFromResponse = getIdFromResponse;
60
- var getErrorFromResponse = function (errorProperty, response) {
24
+ const getErrorFromResponse = (errorProperty, response) => {
61
25
  var _a;
62
26
  return (_a = response.validation) === null || _a === void 0 ? void 0 : _a[errorProperty];
63
27
  };
64
28
  exports.getErrorFromResponse = getErrorFromResponse;
65
- var controlTypesWithPersistOnChange = new Set([
29
+ const controlTypesWithPersistOnChange = new Set([
66
30
  constants_1.FormControlType.RADIO,
67
31
  constants_1.FormControlType.SELECT,
68
32
  constants_1.FormControlType.DATELOOKUP,
69
33
  constants_1.FormControlType.FILE,
70
34
  constants_1.FormControlType.UPLOAD,
71
35
  ]);
72
- var PersistAsyncBasicSchema = function (props) {
73
- var intl = (0, react_intl_1.useIntl)();
74
- var fetcher = (0, contexts_1.useFetcher)();
75
- var onEvent = (0, contexts_1.useEventDispatcher)();
76
- var _a = (0, react_1.useState)(null), persistAsyncModel = _a[0], setPersistAsyncModel = _a[1];
77
- var previousPersistAsyncModel = (0, hooks_1.usePrevious)(persistAsyncModel);
78
- var _b = (0, react_1.useState)(null), persistAsyncError = _b[0], setPersistAsyncError = _b[1];
79
- var _c = (0, react_1.useState)(false), fieldSubmitted = _c[0], setFieldSubmitted = _c[1];
80
- var _d = (0, react_1.useState)(null), abortController = _d[0], setAbortController = _d[1];
81
- (0, react_1.useEffect)(function () {
36
+ const PersistAsyncBasicSchema = (props) => {
37
+ const intl = (0, react_intl_1.useIntl)();
38
+ const fetcher = (0, contexts_1.useFetcher)();
39
+ const onEvent = (0, contexts_1.useEventDispatcher)();
40
+ const [persistAsyncModel, setPersistAsyncModel] = (0, react_1.useState)(null);
41
+ const previousPersistAsyncModel = (0, hooks_1.usePrevious)(persistAsyncModel);
42
+ const [persistAsyncError, setPersistAsyncError] = (0, react_1.useState)(null);
43
+ const [fieldSubmitted, setFieldSubmitted] = (0, react_1.useState)(false);
44
+ const [abortController, setAbortController] = (0, react_1.useState)(null);
45
+ (0, react_1.useEffect)(() => {
82
46
  if (controlTypesWithPersistOnChange.has(
83
47
  // TODO: LOW avoid type assertion below -- control type may be nullish. consider ?? ''
84
48
  (0, SchemaFormControl_1.getControlType)(props.schema.persistAsync.schema))) {
85
49
  persistAsyncIfValid();
86
50
  }
87
51
  }, [persistAsyncModel]);
88
- var setGenericPersistAsyncError = function () {
89
- return setPersistAsyncError(intl.formatMessage(PersistAsyncSchema_messages_1["default"].genericError));
90
- };
91
- var getPersistAsyncResponse = function (currentPersistAsyncModel, persistAsyncSpec) { return __awaiter(void 0, void 0, void 0, function () {
92
- var signal, requestBody, persistAsyncFetch, response, responseBody, _a, idProperty, param, id, validation, error, _b;
93
- var _c;
94
- return __generator(this, function (_d) {
95
- switch (_d.label) {
96
- case 0:
97
- signal = abortCurrentRequestAndGetNewAbortSignal();
98
- requestBody = (_c = {}, _c[persistAsyncSpec.param] = currentPersistAsyncModel, _c);
99
- setFieldSubmitted(true); // persist async initiated implied the field has been submitted
100
- _d.label = 1;
101
- case 1:
102
- _d.trys.push([1, 4, , 5]);
103
- onEvent('Dynamic Flow - PersistAsync', { status: 'pending', schemaId: allOf_1["default"].$id });
104
- persistAsyncFetch = fetcher(persistAsyncSpec.url, {
105
- method: persistAsyncSpec.method,
106
- headers: { 'Content-Type': 'application/json' },
107
- body: JSON.stringify(requestBody),
108
- signal: signal
109
- });
110
- props.onPersistAsync(persistAsyncFetch);
111
- return [4 /*yield*/, persistAsyncFetch];
112
- case 2:
113
- response = _d.sent();
114
- return [4 /*yield*/, response.json()];
115
- case 3:
116
- responseBody = _d.sent();
117
- if (!(0, validators_1.isObject)(responseBody)) {
118
- throw new Error('Response is not an object');
119
- }
120
- _a = props.schema.persistAsync, idProperty = _a.idProperty, param = _a.param;
121
- if ((0, utils_1.isStatus2xx)(response.status)) {
122
- id = (0, exports.getIdFromResponse)(idProperty, responseBody);
123
- props.onChange({ model: id, triggerSchema: props.schema, triggerModel: id });
124
- }
125
- else if ((0, utils_1.isStatus422)(response.status)) {
126
- validation = responseBody.validation;
127
- error = ((0, validators_1.isObject)(validation) && (validation === null || validation === void 0 ? void 0 : validation[param])) || null;
128
- setPersistAsyncError(error);
129
- props.onChange({ model: null, triggerSchema: props.schema, triggerModel: null });
130
- }
131
- else {
132
- setGenericPersistAsyncError();
133
- }
134
- onEvent('Dynamic Flow - PersistAsync', { status: 'success', schemaId: allOf_1["default"].$id });
135
- return [3 /*break*/, 5];
136
- case 4:
137
- _b = _d.sent();
138
- onEvent('Dynamic Flow - PersistAsync', { status: 'failure', schemaId: allOf_1["default"].$id });
139
- setGenericPersistAsyncError();
140
- return [3 /*break*/, 5];
141
- case 5: return [2 /*return*/];
52
+ const setGenericPersistAsyncError = () => setPersistAsyncError(intl.formatMessage(PersistAsyncSchema_messages_1.default.genericError));
53
+ const getPersistAsyncResponse = async (currentPersistAsyncModel, persistAsyncSpec) => {
54
+ const signal = abortCurrentRequestAndGetNewAbortSignal();
55
+ const requestBody = { [persistAsyncSpec.param]: currentPersistAsyncModel };
56
+ setFieldSubmitted(true); // persist async initiated implied the field has been submitted
57
+ try {
58
+ onEvent('Dynamic Flow - PersistAsync', { status: 'pending', schemaId: allOf_1.default.$id });
59
+ const persistAsyncFetch = fetcher(persistAsyncSpec.url, {
60
+ method: persistAsyncSpec.method,
61
+ headers: { 'Content-Type': 'application/json' },
62
+ body: JSON.stringify(requestBody),
63
+ signal,
64
+ });
65
+ props.onPersistAsync(persistAsyncFetch);
66
+ const response = await persistAsyncFetch;
67
+ const responseBody = await response.json();
68
+ if (!(0, validators_1.isObject)(responseBody)) {
69
+ throw new Error('Response is not an object');
70
+ }
71
+ const { idProperty, param } = props.schema.persistAsync;
72
+ if ((0, utils_1.isStatus2xx)(response.status)) {
73
+ const id = (0, exports.getIdFromResponse)(idProperty, responseBody);
74
+ props.onChange({ model: id, triggerSchema: props.schema, triggerModel: id });
142
75
  }
143
- });
144
- }); };
145
- var abortCurrentRequestAndGetNewAbortSignal = function () {
76
+ else if ((0, utils_1.isStatus422)(response.status)) {
77
+ const { validation } = responseBody;
78
+ const error = ((0, validators_1.isObject)(validation) && (validation === null || validation === void 0 ? void 0 : validation[param])) || null;
79
+ setPersistAsyncError(error);
80
+ props.onChange({ model: null, triggerSchema: props.schema, triggerModel: null });
81
+ }
82
+ else {
83
+ setGenericPersistAsyncError();
84
+ }
85
+ onEvent('Dynamic Flow - PersistAsync', { status: 'success', schemaId: allOf_1.default.$id });
86
+ }
87
+ catch (_a) {
88
+ onEvent('Dynamic Flow - PersistAsync', { status: 'failure', schemaId: allOf_1.default.$id });
89
+ setGenericPersistAsyncError();
90
+ }
91
+ };
92
+ const abortCurrentRequestAndGetNewAbortSignal = () => {
146
93
  if (abortController) {
147
94
  abortController.abort();
148
95
  }
149
- var newAbortController = new AbortController();
96
+ const newAbortController = new AbortController();
150
97
  setAbortController(newAbortController);
151
98
  return newAbortController.signal;
152
99
  };
153
- var persistAsyncIfValid = function () {
100
+ const persistAsyncIfValid = () => {
154
101
  if (!(0, validators_1.isNull)(persistAsyncModel) && !(0, utils_1.isEqual)(persistAsyncModel, previousPersistAsyncModel)) {
155
102
  void getPersistAsyncResponse(persistAsyncModel, props.schema.persistAsync);
156
103
  }
157
104
  };
158
- var onBlur = function () {
105
+ const onBlur = () => {
159
106
  persistAsyncIfValid();
160
107
  };
161
- var persistAsyncOnChange = function (_a) {
162
- var newPersistAsyncModel = _a.model;
108
+ const persistAsyncOnChange = ({ model: newPersistAsyncModel }) => {
163
109
  setPersistAsyncError(null);
164
110
  if ((0, validators_1.isValidSchema)(newPersistAsyncModel, props.schema.persistAsync.schema)) {
165
111
  setPersistAsyncModel(newPersistAsyncModel);
166
112
  }
167
113
  };
168
- return ((0, jsx_runtime_1.jsx)(basicTypeSchema_1["default"], { required: props.required, submitted: props.submitted || fieldSubmitted, schema: props.schema.persistAsync.schema, errors: persistAsyncError || props.errors, model: null, infoMessage: null, onChange: persistAsyncOnChange, onBlur: onBlur }));
114
+ return ((0, jsx_runtime_1.jsx)(basicTypeSchema_1.default, { required: props.required, submitted: props.submitted || fieldSubmitted, schema: props.schema.persistAsync.schema, errors: persistAsyncError || props.errors, model: null, infoMessage: null, onChange: persistAsyncOnChange, onBlur: onBlur }));
169
115
  };
170
116
  PersistAsyncBasicSchema.defaultProps = {
171
- required: false
117
+ required: false,
172
118
  };
173
- exports["default"] = PersistAsyncBasicSchema;
119
+ exports.default = PersistAsyncBasicSchema;
@@ -1,16 +1,8 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- exports.__esModule = true;
14
- exports["default"] = void 0;
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.default = void 0;
15
7
  var PersistAsyncBasicSchema_1 = require("./PersistAsyncBasicSchema");
16
- __createBinding(exports, PersistAsyncBasicSchema_1, "default");
8
+ Object.defineProperty(exports, "default", { enumerable: true, get: function () { return __importDefault(PersistAsyncBasicSchema_1).default; } });
@@ -1,131 +1,66 @@
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 __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
14
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
15
- return new (P || (P = Promise))(function (resolve, reject) {
16
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
17
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
18
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
19
- step((generator = generator.apply(thisArg, _arguments || [])).next());
20
- });
21
- };
22
- var __generator = (this && this.__generator) || function (thisArg, body) {
23
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
24
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
25
- function verb(n) { return function (v) { return step([n, v]); }; }
26
- function step(op) {
27
- if (f) throw new TypeError("Generator is already executing.");
28
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
29
- 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;
30
- if (y = 0, t) op = [op[0] & 2, t.value];
31
- switch (op[0]) {
32
- case 0: case 1: t = op; break;
33
- case 4: _.label++; return { value: op[1], done: false };
34
- case 5: _.label++; y = op[1]; op = [0]; continue;
35
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
36
- default:
37
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
38
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
39
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
40
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
41
- if (t[2]) _.ops.pop();
42
- _.trys.pop(); continue;
43
- }
44
- op = body.call(thisArg, _);
45
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
46
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
47
- }
48
- };
49
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
50
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
51
4
  };
52
- exports.__esModule = true;
53
- var jsx_runtime_1 = require("react/jsx-runtime");
54
- var classnames_1 = __importDefault(require("classnames"));
55
- var react_1 = require("react");
56
- var contexts_1 = require("../../../common/contexts");
57
- var utils_1 = require("../../../common/utils");
58
- var validators_1 = require("../../../common/validators");
59
- var controlFeedback_1 = __importDefault(require("../../controlFeedback"));
60
- var utils_2 = require("../../schemaFormControl/utils");
61
- var PersistAsyncBasicSchema_1 = require("../persistAsyncBasicSchema/PersistAsyncBasicSchema");
62
- var UploadInputAdapter_1 = require("./UploadInputAdapter");
63
- var PersistAsyncBlobSchema = function (props) {
64
- var _a = (0, react_1.useState)({}), persistAsyncValidationMessages = _a[0], setPersistAsyncValidationMessages = _a[1];
65
- var _b = (0, react_1.useState)(null), persistAsyncValidations = _b[0], setPersistAsyncValidations = _b[1];
66
- var _c = (0, react_1.useState)([]), validations = _c[0], setValidations = _c[1];
67
- var _d = (0, react_1.useState)(false), changed = _d[0], setChanged = _d[1];
68
- var fetcher = (0, contexts_1.useFetcher)();
69
- var onEvent = (0, contexts_1.useEventDispatcher)();
70
- var refreshValidations = function () {
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const jsx_runtime_1 = require("react/jsx-runtime");
7
+ const classnames_1 = __importDefault(require("classnames"));
8
+ const react_1 = require("react");
9
+ const contexts_1 = require("../../../common/contexts");
10
+ const utils_1 = require("../../../common/utils");
11
+ const validators_1 = require("../../../common/validators");
12
+ const controlFeedback_1 = __importDefault(require("../../controlFeedback"));
13
+ const utils_2 = require("../../schemaFormControl/utils");
14
+ const PersistAsyncBasicSchema_1 = require("../persistAsyncBasicSchema/PersistAsyncBasicSchema");
15
+ const UploadInputAdapter_1 = require("./UploadInputAdapter");
16
+ const PersistAsyncBlobSchema = (props) => {
17
+ const [persistAsyncValidationMessages, setPersistAsyncValidationMessages] = (0, react_1.useState)({});
18
+ const [persistAsyncValidations, setPersistAsyncValidations] = (0, react_1.useState)(null);
19
+ const [validations, setValidations] = (0, react_1.useState)([]);
20
+ const [changed, setChanged] = (0, react_1.useState)(false);
21
+ const fetcher = (0, contexts_1.useFetcher)();
22
+ const onEvent = (0, contexts_1.useEventDispatcher)();
23
+ const refreshValidations = () => {
71
24
  if (props.submitted) {
72
25
  setValidations((0, validators_1.getValidationFailures)(props.model, props.schema, !!props.required));
73
26
  }
74
27
  };
75
28
  (0, react_1.useEffect)(refreshValidations, [props.model, props.submitted]);
76
- var onSuccess = function (httpResponse, _fileName) { return __awaiter(void 0, void 0, void 0, function () {
77
- var jsonResponse, id;
78
- return __generator(this, function (_a) {
79
- switch (_a.label) {
80
- case 0: return [4 /*yield*/, httpResponse.json()];
81
- case 1:
82
- jsonResponse = (_a.sent());
83
- id = (0, PersistAsyncBasicSchema_1.getIdFromResponse)(props.schema.persistAsync.idProperty, jsonResponse);
84
- props.onChange({ model: id, triggerSchema: props.schema, triggerModel: id });
85
- setChanged(true);
86
- onEvent('Dynamic Flow - PersistAsync', { status: 'success', schemaId: props.schema.$id });
87
- return [2 /*return*/];
88
- }
89
- });
90
- }); };
91
- var onFailure = function (errorResponse) { return __awaiter(void 0, void 0, void 0, function () {
92
- var jsonResponse;
93
- return __generator(this, function (_a) {
94
- switch (_a.label) {
95
- case 0:
96
- if (!(errorResponse.response && (0, utils_1.isStatus422)(errorResponse.response.status))) return [3 /*break*/, 2];
97
- return [4 /*yield*/, errorResponse.response.json()];
98
- case 1:
99
- jsonResponse = (_a.sent());
100
- setPersistAsyncValidationMessages(jsonResponse.validation || {});
101
- setPersistAsyncValidations([props.schema.persistAsync.param]);
102
- _a.label = 2;
103
- case 2:
104
- props.onChange({ model: null, triggerSchema: props.schema, triggerModel: null });
105
- setChanged(true);
106
- onEvent('Dynamic Flow - PersistAsync', { status: 'failure', schemaId: props.schema.$id });
107
- return [2 /*return*/];
108
- }
109
- });
110
- }); };
111
- var onCancel = function () {
29
+ const onSuccess = async (httpResponse, _fileName) => {
30
+ const jsonResponse = (await httpResponse.json());
31
+ const id = (0, PersistAsyncBasicSchema_1.getIdFromResponse)(props.schema.persistAsync.idProperty, jsonResponse);
32
+ props.onChange({ model: id, triggerSchema: props.schema, triggerModel: id });
33
+ setChanged(true);
34
+ onEvent('Dynamic Flow - PersistAsync', { status: 'success', schemaId: props.schema.$id });
35
+ };
36
+ const onFailure = async (errorResponse) => {
37
+ if (errorResponse.response && (0, utils_1.isStatus422)(errorResponse.response.status)) {
38
+ const jsonResponse = (await errorResponse.response.json());
39
+ setPersistAsyncValidationMessages(jsonResponse.validation || {});
40
+ setPersistAsyncValidations([props.schema.persistAsync.param]);
41
+ }
42
+ props.onChange({ model: null, triggerSchema: props.schema, triggerModel: null });
43
+ setChanged(true);
44
+ onEvent('Dynamic Flow - PersistAsync', { status: 'failure', schemaId: props.schema.$id });
45
+ };
46
+ const onCancel = () => {
112
47
  setPersistAsyncValidations(null);
113
48
  props.onChange({ model: null, triggerSchema: props.schema, triggerModel: null });
114
49
  setChanged(true);
115
50
  };
116
- var _e = props.schema.persistAsync, url = _e.url, method = _e.method;
117
- var combinedValidations = persistAsyncValidations || validations;
118
- var formGroupClasses = {
51
+ const { url, method } = props.schema.persistAsync;
52
+ const combinedValidations = persistAsyncValidations || validations;
53
+ const formGroupClasses = {
119
54
  'form-group': true,
120
- 'has-error': (props.submitted || changed) && !!combinedValidations.length
55
+ 'has-error': (props.submitted || changed) && !!combinedValidations.length,
121
56
  };
122
- return ((0, jsx_runtime_1.jsxs)("div", __assign({ className: (0, classnames_1["default"])(formGroupClasses) }, { children: [(0, jsx_runtime_1.jsx)(UploadInputAdapter_1.UploadInputAdapter, __assign({ id: props.schema.$id ||
57
+ return ((0, jsx_runtime_1.jsxs)("div", Object.assign({ className: (0, classnames_1.default)(formGroupClasses) }, { children: [(0, jsx_runtime_1.jsx)(UploadInputAdapter_1.UploadInputAdapter, Object.assign({ id: props.schema.$id ||
123
58
  props.schema.persistAsync.schema.$id ||
124
59
  props.schema.persistAsync.idProperty,
125
60
  // TODO: LOW avoid type assertion -- model can be null, but fileId must be number | string -- or maybe make fileId: string| number | undefined
126
- fileId: props.model, idProperty: props.schema.persistAsync.idProperty, animationDelay: 0, maxSize: props.schema.persistAsync.schema.maxSize, usLabel: props.schema.title || props.schema.persistAsync.schema.title, usPlaceholder: props.schema.description || props.schema.persistAsync.schema.description, httpOptions: { url: url, method: method, fileInputName: props.schema.persistAsync.param }, fetcher: fetcher, onSuccess: onSuccess, onFailure: onFailure, onCancel: onCancel }, (0, utils_2.mapSchemaToUploadOptions)(props.schema.persistAsync.schema))), (0, jsx_runtime_1.jsx)(controlFeedback_1["default"], { blurred: true, focused: false, changed: changed, submitted: props.submitted, errors: props.errors, schema: props.schema, validations: combinedValidations, validationMessages: __assign({ required: 'Value is required...' }, persistAsyncValidationMessages), infoMessage: null })] })));
61
+ fileId: props.model, idProperty: props.schema.persistAsync.idProperty, animationDelay: 0, maxSize: props.schema.persistAsync.schema.maxSize, usLabel: props.schema.title || props.schema.persistAsync.schema.title, usPlaceholder: props.schema.description || props.schema.persistAsync.schema.description, httpOptions: { url, method, fileInputName: props.schema.persistAsync.param }, fetcher: fetcher, onSuccess: onSuccess, onFailure: onFailure, onCancel: onCancel }, (0, utils_2.mapSchemaToUploadOptions)(props.schema.persistAsync.schema))), (0, jsx_runtime_1.jsx)(controlFeedback_1.default, { blurred: true, focused: false, changed: changed, submitted: props.submitted, errors: props.errors, schema: props.schema, validations: combinedValidations, validationMessages: Object.assign({ required: 'Value is required...' }, persistAsyncValidationMessages), infoMessage: null })] })));
127
62
  };
128
63
  PersistAsyncBlobSchema.defaultProps = {
129
- required: false
64
+ required: false,
130
65
  };
131
- exports["default"] = PersistAsyncBlobSchema;
66
+ exports.default = PersistAsyncBlobSchema;
@@ -1,34 +1,34 @@
1
1
  "use strict";
2
- exports.__esModule = true;
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.UploadInputAdapter = void 0;
4
- var jsx_runtime_1 = require("react/jsx-runtime");
5
- var components_1 = require("@transferwise/components");
6
- var react_1 = require("react");
7
- var contexts_1 = require("../../../common/contexts");
8
- var utils_1 = require("../../../common/utils");
9
- var UploadInputAdapter = function (props) {
10
- var id = props.id, _a = props.fetcher, fetcher = _a === void 0 ? fetch : _a, httpOptions = props.httpOptions, fileId = props.fileId, idProperty = props.idProperty, usAccept = props.usAccept, maxSize = props.maxSize, usPlaceholder = props.usPlaceholder, onSuccess = props.onSuccess, onFailure = props.onFailure, onCancel = props.onCancel;
11
- var onEvent = (0, contexts_1.useEventDispatcher)();
12
- var files = (0, react_1.useMemo)(function () { return (fileId ? [{ id: fileId, status: components_1.Status.SUCCEEDED }] : []); }, [fileId]);
13
- var uploadFile = function (formData) {
4
+ const jsx_runtime_1 = require("react/jsx-runtime");
5
+ const components_1 = require("@transferwise/components");
6
+ const react_1 = require("react");
7
+ const contexts_1 = require("../../../common/contexts");
8
+ const utils_1 = require("../../../common/utils");
9
+ const UploadInputAdapter = (props) => {
10
+ const { id, fetcher = fetch, httpOptions, fileId, idProperty, usAccept, maxSize, usPlaceholder, onSuccess, onFailure, onCancel, } = props;
11
+ const onEvent = (0, contexts_1.useEventDispatcher)();
12
+ const files = (0, react_1.useMemo)(() => (fileId ? [{ id: fileId, status: components_1.Status.SUCCEEDED }] : []), [fileId]);
13
+ const uploadFile = (formData) => {
14
14
  onEvent('Dynamic Flow - PersistAsync', { status: 'pending', schemaId: id });
15
- return fetcher("".concat(httpOptions.url), {
15
+ return fetcher(`${httpOptions.url}`, {
16
16
  method: httpOptions.method || 'POST',
17
- body: formData
18
- }).then(function (response) {
17
+ body: formData,
18
+ }).then((response) => {
19
19
  if (response.ok) {
20
20
  onSuccess && onSuccess(response.clone());
21
- return response.json().then(function (responseBody) {
21
+ return response.json().then((responseBody) => {
22
22
  return { id: responseBody[idProperty] };
23
23
  });
24
24
  }
25
25
  else {
26
- onFailure && onFailure({ response: response });
26
+ onFailure && onFailure({ response });
27
27
  return Promise.reject();
28
28
  }
29
29
  });
30
30
  };
31
- return ((0, jsx_runtime_1.jsx)(components_1.UploadInput, { id: id, fileInputName: httpOptions.fileInputName, files: files, uploadButtonTitle: props.usLabel, sizeLimit: maxSize ? (0, utils_1.toKilobytes)(maxSize) : undefined, fileTypes: usAccept, description: usPlaceholder, onUploadFile: uploadFile, onDeleteFile: function (_id) {
31
+ return ((0, jsx_runtime_1.jsx)(components_1.UploadInput, { id: id, fileInputName: httpOptions.fileInputName, files: files, uploadButtonTitle: props.usLabel, sizeLimit: maxSize ? (0, utils_1.toKilobytes)(maxSize) : undefined, fileTypes: usAccept, description: usPlaceholder, onUploadFile: uploadFile, onDeleteFile: (_id) => {
32
32
  onCancel && onCancel();
33
33
  return Promise.resolve();
34
34
  } }));
@@ -1,16 +1,8 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- exports.__esModule = true;
14
- exports["default"] = void 0;
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.default = void 0;
15
7
  var PersistAsyncBlobSchema_1 = require("./PersistAsyncBlobSchema");
16
- __createBinding(exports, PersistAsyncBlobSchema_1, "default");
8
+ Object.defineProperty(exports, "default", { enumerable: true, get: function () { return __importDefault(PersistAsyncBlobSchema_1).default; } });