@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.
- package/build/common/constants/DateMode.js +2 -2
- package/build/common/constants/FormControlType.js +2 -2
- package/build/common/constants/MonthFormat.js +2 -2
- package/build/common/constants/SchemaType.js +2 -2
- package/build/common/constants/Size.js +2 -2
- package/build/common/constants/index.js +1 -1
- package/build/common/contexts/dynamicFlowContexts/DynamicFlowContexts.js +15 -27
- package/build/common/contexts/dynamicFlowContexts/usePendingPromiseCounter.js +11 -9
- package/build/common/contexts/eventsContext/EventsContext.js +11 -28
- package/build/common/contexts/fetcherContexts/FetcherContexts.js +14 -27
- package/build/common/contexts/index.js +1 -1
- package/build/common/contexts/logContext/LogContext.js +12 -30
- package/build/common/hooks/index.js +1 -1
- package/build/common/hooks/useDebouncedFunction/useDebouncedFunction.js +3 -3
- package/build/common/hooks/useExternal/useExternal.js +8 -8
- package/build/common/hooks/useExternalStepPolling/useExternalStepPolling.js +20 -31
- package/build/common/hooks/usePersistAsync/usePersistAsync.js +60 -139
- package/build/common/hooks/usePolling/usePolling.js +20 -21
- package/build/common/hooks/usePrevious/usePrevious.js +5 -5
- package/build/common/hooks/useStepPolling/useStepPolling.js +15 -14
- package/build/common/makeFetcher/index.js +1 -1
- package/build/common/makeFetcher/makeFetcher.js +10 -24
- package/build/common/messages.js +5 -5
- package/build/common/utils/api-utils.js +3 -4
- package/build/common/utils/date-utils.js +11 -11
- package/build/common/utils/debounce.js +11 -15
- package/build/common/utils/file-utils.js +12 -25
- package/build/common/utils/id-utils.js +4 -5
- package/build/common/utils/index.js +1 -1
- package/build/common/utils/is-equal.js +8 -8
- package/build/common/utils/schema-utils.js +6 -6
- package/build/common/utils/step-utils.js +14 -14
- package/build/common/validators/index.js +7 -7
- package/build/common/validators/models/model-validators.js +8 -8
- package/build/common/validators/models/models.utils.js +29 -42
- package/build/common/validators/schemas/schema-validators.js +11 -13
- package/build/common/validators/types/type-validators.js +9 -13
- package/build/common/validators/validationFailures/validation-failures.js +14 -14
- package/build/common/validators/validationFailures/validation-failures.utils.js +5 -7
- package/build/common/validators/values/value-validators.js +4 -6
- package/build/dynamicFlow/DynamicFlow.js +185 -307
- package/build/dynamicFlow/DynamicFlowStep.js +12 -23
- package/build/dynamicFlow/DynamicFlowTypes.js +1 -1
- package/build/dynamicFlow/index.js +6 -14
- package/build/dynamicFlow/stories/DynamicFlow.story.js +20 -20
- package/build/dynamicFlow/stories/EditableDynamicFlow.js +20 -33
- package/build/dynamicFlow/stories/fixtureFetcher.js +46 -104
- package/build/dynamicFlow/utils/errorBoundary/ErrorBoundary.js +22 -40
- package/build/dynamicFlow/utils/errorBoundary/ErrorBoundary.messages.js +6 -6
- package/build/dynamicFlow/utils/errorBoundary/ErrorBoundaryAlert.js +10 -11
- package/build/dynamicFlow/utils/index.js +5 -2
- package/build/dynamicFlow/utils/responseParsers/response-parsers.js +53 -118
- package/build/dynamicFlow/utils/useDebouncedRefresh/useDebouncedRefresh.js +9 -9
- package/build/dynamicFlow/utils/useDynamicFlowState.js +51 -74
- package/build/dynamicFlow/utils/useLoader.js +9 -20
- package/build/fixtures/components/alert.js +8 -8
- package/build/fixtures/components/box.js +7 -7
- package/build/fixtures/components/button.js +25 -36
- package/build/fixtures/components/columns.js +10 -10
- package/build/fixtures/components/copyable.js +6 -6
- package/build/fixtures/components/decision.js +15 -15
- package/build/fixtures/components/heading.js +7 -7
- package/build/fixtures/components/image.js +10 -10
- package/build/fixtures/components/index.js +17 -25
- package/build/fixtures/components/info.js +22 -6
- package/build/fixtures/components/list.js +8 -8
- package/build/fixtures/components/loading-indicator.js +5 -5
- package/build/fixtures/components/paragraph.js +9 -9
- package/build/fixtures/components/review.js +11 -11
- package/build/fixtures/examples/camera-capture.js +29 -29
- package/build/fixtures/examples/index.js +9 -17
- package/build/fixtures/examples/recipient-update.js +69 -69
- package/build/fixtures/examples/recipient.js +63 -63
- package/build/fixtures/examples/single-file-upload.js +21 -21
- package/build/fixtures/examples/step-validation-errors.js +21 -21
- package/build/fixtures/features/action-response.js +8 -8
- package/build/fixtures/features/external.js +8 -8
- package/build/fixtures/features/index.js +9 -17
- package/build/fixtures/features/persist-async.js +11 -11
- package/build/fixtures/features/polling.js +9 -9
- package/build/fixtures/features/validation-async.js +10 -10
- package/build/fixtures/index.js +11 -22
- package/build/fixtures/jsonSchemaForm/allOf.js +30 -30
- package/build/fixtures/jsonSchemaForm/audRecipient.js +271 -271
- package/build/fixtures/jsonSchemaForm/currency.js +12 -12
- package/build/fixtures/jsonSchemaForm/multipleFileUploadBase64.js +11 -11
- package/build/fixtures/jsonSchemaForm/multipleFileUploadBlob.js +11 -11
- package/build/fixtures/jsonSchemaForm/oneOf.js +27 -27
- package/build/fixtures/jsonSchemaForm/oneOfTabs.js +16 -16
- package/build/fixtures/jsonSchemaForm/promotedOneOf.js +17 -17
- package/build/fixtures/jsonSchemaForm/promotedOneOfCheckbox.js +30 -30
- package/build/fixtures/jsonSchemaForm/simple.js +16 -16
- package/build/fixtures/jsonSchemaForm/uploadPersistAsync.js +19 -19
- package/build/fixtures/jsonSchemaForm/validationAsync.js +8 -8
- package/build/fixtures/layouts/all.js +37 -37
- package/build/fixtures/layouts/final-step-layout.js +9 -9
- package/build/fixtures/layouts/index.js +10 -18
- package/build/fixtures/layouts/list.js +10 -10
- package/build/fixtures/layouts/pay-in.js +23 -23
- package/build/fixtures/layouts/review.js +38 -38
- package/build/fixtures/layouts/success.js +15 -15
- package/build/fixtures/responses/action-response-final.js +8 -8
- package/build/fixtures/responses/action.js +3 -3
- package/build/fixtures/responses/exit.js +3 -3
- package/build/fixtures/responses/index.js +8 -16
- package/build/fixtures/responses/recipient-update-final.js +8 -8
- package/build/fixtures/schemas/basic-form.js +11 -11
- package/build/fixtures/schemas/index.js +8 -16
- package/build/fixtures/schemas/number-and-integer.js +11 -11
- package/build/fixtures/schemas/one-of.js +43 -46
- package/build/fixtures/schemas/string-formats.js +15 -15
- package/build/fixtures/utils/image-util.js +8 -8
- package/build/formControl/FormControl.js +118 -148
- package/build/formControl/index.js +6 -14
- package/build/formControl/utils/index.js +1 -1
- package/build/formControl/utils/value-utils.js +18 -23
- package/build/i18n/index.js +31 -31
- package/build/index.js +13 -10
- package/build/jsonSchemaForm/JsonSchemaForm.js +12 -24
- package/build/jsonSchemaForm/allOfSchema/AllOfSchema.js +24 -37
- package/build/jsonSchemaForm/allOfSchema/index.js +6 -14
- package/build/jsonSchemaForm/arrayTypeSchema/ArraySchema.js +9 -20
- package/build/jsonSchemaForm/arrayTypeSchema/arrayListSchema/ArrayListSchema.js +9 -20
- package/build/jsonSchemaForm/arrayTypeSchema/arrayListSchema/index.js +6 -14
- package/build/jsonSchemaForm/arrayTypeSchema/arrayListSchema/multipleFileUploadSchema/MultipleFileUploadSchema.js +56 -115
- package/build/jsonSchemaForm/arrayTypeSchema/arrayListSchema/multipleFileUploadSchema/MultipleFileUploadSchema.messages.js +7 -7
- package/build/jsonSchemaForm/arrayTypeSchema/arrayListSchema/multipleFileUploadSchema/index.js +6 -14
- package/build/jsonSchemaForm/arrayTypeSchema/arrayListSchema/multipleFileUploadSchema/utils/index.js +1 -1
- package/build/jsonSchemaForm/arrayTypeSchema/arrayListSchema/multipleFileUploadSchema/utils/upload-utils.js +19 -71
- package/build/jsonSchemaForm/arrayTypeSchema/arrayListSchema/multipleFileUploadSchema/utils/useFormattedDefaultErrorMessages.js +10 -11
- package/build/jsonSchemaForm/arrayTypeSchema/index.js +6 -14
- package/build/jsonSchemaForm/basicTypeSchema/BasicTypeSchema.js +45 -62
- package/build/jsonSchemaForm/basicTypeSchema/index.js +6 -14
- package/build/jsonSchemaForm/controlFeedback/ControlFeedback.js +39 -50
- package/build/jsonSchemaForm/controlFeedback/ControlFeedback.messages.js +18 -18
- package/build/jsonSchemaForm/controlFeedback/index.js +6 -14
- package/build/jsonSchemaForm/genericSchema/GenericSchema.js +52 -61
- package/build/jsonSchemaForm/genericSchema/index.js +6 -14
- package/build/jsonSchemaForm/help/Help.js +9 -9
- package/build/jsonSchemaForm/help/Help.messages.js +5 -5
- package/build/jsonSchemaForm/help/index.js +6 -14
- package/build/jsonSchemaForm/index.js +6 -14
- package/build/jsonSchemaForm/objectSchema/ObjectSchema.js +28 -49
- package/build/jsonSchemaForm/objectSchema/index.js +6 -14
- package/build/jsonSchemaForm/oneOfSchema/OneOfSchema.js +54 -74
- package/build/jsonSchemaForm/oneOfSchema/index.js +6 -14
- package/build/jsonSchemaForm/oneOfSchema/utils/const-schema-utils.js +3 -3
- package/build/jsonSchemaForm/oneOfSchema/utils/index.js +1 -1
- package/build/jsonSchemaForm/oneOfSchema/utils/one-of-utils.js +19 -20
- package/build/jsonSchemaForm/persistAsyncSchema/PersistAsyncSchema.js +11 -22
- package/build/jsonSchemaForm/persistAsyncSchema/PersistAsyncSchema.messages.js +5 -5
- package/build/jsonSchemaForm/persistAsyncSchema/index.js +6 -14
- package/build/jsonSchemaForm/persistAsyncSchema/persistAsyncBasicSchema/PersistAsyncBasicSchema.js +73 -127
- package/build/jsonSchemaForm/persistAsyncSchema/persistAsyncBasicSchema/index.js +6 -14
- package/build/jsonSchemaForm/persistAsyncSchema/persistAsyncBlobSchema/PersistAsyncBlobSchema.js +45 -110
- package/build/jsonSchemaForm/persistAsyncSchema/persistAsyncBlobSchema/UploadInputAdapter.js +17 -17
- package/build/jsonSchemaForm/persistAsyncSchema/persistAsyncBlobSchema/index.js +6 -14
- package/build/jsonSchemaForm/promotedOneOfSchema/PromotedOneOfSchema.js +28 -47
- package/build/jsonSchemaForm/promotedOneOfSchema/index.js +6 -14
- package/build/jsonSchemaForm/promotedOneOfSchema/promoted-one-of-utils.js +4 -4
- package/build/jsonSchemaForm/promotedOneOfSchema/promotedOneOfControl/PromotedOneOfCheckboxControl.js +13 -24
- package/build/jsonSchemaForm/promotedOneOfSchema/promotedOneOfControl/PromotedOneOfControl.js +11 -22
- package/build/jsonSchemaForm/promotedOneOfSchema/promotedOneOfControl/PromotedOneOfRadioControl.js +12 -23
- package/build/jsonSchemaForm/readOnlySchema/ReadOnlySchema.js +24 -26
- package/build/jsonSchemaForm/readOnlySchema/ReadOnlySchema.messages.js +6 -6
- package/build/jsonSchemaForm/readOnlySchema/index.js +6 -14
- package/build/jsonSchemaForm/schemaFormControl/SchemaFormControl.js +26 -39
- package/build/jsonSchemaForm/schemaFormControl/index.js +6 -14
- package/build/jsonSchemaForm/schemaFormControl/utils/currency-utils.js +5 -5
- package/build/jsonSchemaForm/schemaFormControl/utils/index.js +1 -1
- package/build/jsonSchemaForm/schemaFormControl/utils/mapping-utils.js +30 -47
- package/build/jsonSchemaForm/validationAsyncSchema/ValidationAsyncSchema.js +57 -119
- package/build/jsonSchemaForm/validationAsyncSchema/index.js +6 -14
- package/build/layout/DynamicLayout.js +10 -21
- package/build/layout/alert/DynamicAlert.js +9 -9
- package/build/layout/box/DynamicBox.js +12 -23
- package/build/layout/button/DynamicButton.js +16 -27
- package/build/layout/columns/DynamicColumns.js +13 -24
- package/build/layout/decision/DynamicDecision.js +16 -27
- package/build/layout/divider/DynamicDivider.js +7 -8
- package/build/layout/external/DynamicExternal.js +16 -28
- package/build/layout/external/DynamicExternal.messages.js +5 -5
- package/build/layout/form/DynamicForm.js +10 -21
- package/build/layout/heading/DynamicHeading.js +12 -23
- package/build/layout/icon/DynamicIcon.js +9 -10
- package/build/layout/image/DynamicImage.js +43 -93
- package/build/layout/index.js +21 -29
- package/build/layout/info/DynamicInfo.js +7 -19
- package/build/layout/list/DynamicList.js +14 -26
- package/build/layout/loadingIndicator/DynamicLoadingIndicator.js +8 -9
- package/build/layout/paragraph/DynamicParagraph.js +19 -37
- package/build/layout/paragraph/DynamicParagraph.messages.js +6 -6
- package/build/layout/paragraph/useSnackBarIfAvailable.js +4 -4
- package/build/layout/review/DynamicReview.js +14 -26
- package/build/layout/utils.js +4 -6
- package/build/step/cameraStep/CameraStep.js +42 -88
- package/build/step/cameraStep/cameraCapture/CameraCapture.js +48 -105
- package/build/step/cameraStep/cameraCapture/CameraCapture.messages.js +7 -7
- package/build/step/cameraStep/cameraCapture/components/index.js +10 -28
- package/build/step/cameraStep/cameraCapture/hooks/index.js +17 -72
- package/build/step/cameraStep/cameraCapture/index.js +6 -14
- package/build/step/cameraStep/cameraCapture/overlay/Overlay.js +33 -45
- package/build/step/cameraStep/cameraCapture/screens/CameraNotSupported/CameraNotSupported.js +8 -19
- package/build/step/cameraStep/cameraCapture/screens/CameraNotSupported/CameraNotSupported.messages.js +6 -6
- package/build/step/cameraStep/cameraCapture/screens/NoCameraAccess/NoCameraAccess.js +9 -21
- package/build/step/cameraStep/cameraCapture/screens/NoCameraAccess/NoCameraAccess.messages.js +7 -7
- package/build/step/cameraStep/cameraCapture/screens/index.js +6 -14
- package/build/step/cameraStep/cameraCapture/tracking/index.js +17 -99
- package/build/step/cameraStep/cameraCapture/utils/index.js +33 -96
- package/build/step/cameraStep/index.js +6 -14
- package/build/step/externalConfirmationStep/ExternalConfirmationStep.js +20 -21
- package/build/step/externalConfirmationStep/ExternalConfirmationStep.messages.js +8 -8
- package/build/step/externalConfirmationStep/index.js +6 -14
- package/build/step/index.js +7 -15
- package/build/step/layoutStep/LayoutStep.js +19 -19
- package/build/step/layoutStep/index.js +6 -14
- package/build/step/layoutStep/utils/index.js +3 -14
- package/build/step/layoutStep/utils/inline-reference-utils.js +29 -46
- package/build/step/layoutStep/utils/layout-utils.js +34 -53
- package/build/types/common/FormControl.js +1 -1
- package/build/types/index.js +13 -13
- package/build/types/specification/Action.js +1 -1
- package/build/types/specification/FileUploadSchema.js +1 -1
- package/build/types/specification/LayoutComponent.js +1 -1
- package/build/types/specification/Model.js +9 -17
- package/build/types/specification/PersistAsync.js +1 -1
- package/build/types/specification/Polling.js +1 -1
- package/build/types/specification/Promotion.js +1 -1
- package/build/types/specification/Schema.js +8 -8
- package/build/types/specification/Step.js +3 -5
- package/build/types/specification/ValidationAsync.js +1 -1
- package/build/types/specification/core.js +1 -1
- package/package.json +1 -1
|
@@ -1,131 +1,66 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
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
|
-
|
|
41
|
-
|
|
42
|
-
var jsonBody, action, etag;
|
|
4
|
+
const validators_1 = require("../../../common/validators");
|
|
5
|
+
const parseFetchResponse = async (response) => {
|
|
43
6
|
var _a;
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
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
|
-
|
|
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
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
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
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
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
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.useDebouncedRefresh = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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
|
-
|
|
9
|
-
|
|
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
|
-
|
|
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
|
-
|
|
20
|
-
|
|
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
|
-
|
|
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
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
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
|
-
|
|
30
|
-
|
|
31
|
-
|
|
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
|
-
})
|
|
38
|
-
|
|
39
|
-
|
|
16
|
+
etag: undefined,
|
|
17
|
+
});
|
|
18
|
+
const { step, models, etag } = stepAndModels;
|
|
19
|
+
const setStepAndEtag = (step, etag) => {
|
|
40
20
|
var _a, _b, _c, _d;
|
|
41
|
-
setStepAndModels(
|
|
21
|
+
setStepAndModels((previous) => ({
|
|
42
22
|
step: step,
|
|
43
23
|
models: step.model ? buildInitialModels(step.model, getAllSchemas(step)) : previous.models,
|
|
44
|
-
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
|
-
|
|
50
|
-
setStepAndModels(
|
|
51
|
-
|
|
52
|
-
|
|
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
|
-
|
|
41
|
+
const modelIsValid = (0, react_1.useMemo)(() => areModelsValid(models, getAllSchemas(step)), [models, step]);
|
|
63
42
|
return {
|
|
64
|
-
formErrors
|
|
65
|
-
globalError
|
|
43
|
+
formErrors,
|
|
44
|
+
globalError,
|
|
66
45
|
step: step,
|
|
67
|
-
models
|
|
68
|
-
etag
|
|
69
|
-
modelIsValid
|
|
70
|
-
setFormErrors
|
|
71
|
-
setGlobalError
|
|
72
|
-
setStepAndEtag
|
|
73
|
-
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
|
-
|
|
78
|
-
|
|
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
|
|
63
|
+
return Object.assign(Object.assign({}, acc), { [schema.$id || '']: (0, validators_1.getValidObjectModelParts)(model, schema) || {} });
|
|
87
64
|
}, {});
|
|
88
65
|
};
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
return !(schemas === null || schemas === void 0 ? void 0 : schemas.some(
|
|
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
|
-
|
|
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
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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
|
-
|
|
24
|
-
return { loadingState
|
|
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
|
|
3
|
-
|
|
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
|
|
33
|
+
exports.default = step;
|
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
exports
|
|
3
|
-
|
|
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(
|
|
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:
|
|
17
|
+
text: `This paragraph is inside a box with border: "true" and width: "${size}".`,
|
|
18
18
|
},
|
|
19
|
-
]
|
|
20
|
-
})
|
|
19
|
+
],
|
|
20
|
+
})),
|
|
21
21
|
};
|
|
22
|
-
exports
|
|
22
|
+
exports.default = step;
|
|
@@ -1,27 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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
|
-
|
|
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:
|
|
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
|
-
|
|
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
|
-
],
|
|
52
|
+
],
|
|
64
53
|
},
|
|
65
|
-
]
|
|
54
|
+
],
|
|
66
55
|
};
|
|
67
|
-
exports
|
|
56
|
+
exports.default = step;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
exports
|
|
3
|
-
|
|
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:
|
|
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
|
|
38
|
+
exports.default = step;
|