@wise/dynamic-flow-client 4.7.0 → 4.7.1
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/main.js
CHANGED
|
@@ -3542,6 +3542,13 @@ var parseResponseBodyAsJsonElement = async (response) => {
|
|
|
3542
3542
|
return null;
|
|
3543
3543
|
}
|
|
3544
3544
|
};
|
|
3545
|
+
var parseResponseBodyAsText = async (response) => {
|
|
3546
|
+
try {
|
|
3547
|
+
return await response.text();
|
|
3548
|
+
} catch (e) {
|
|
3549
|
+
return null;
|
|
3550
|
+
}
|
|
3551
|
+
};
|
|
3545
3552
|
function isActionResponseBody(body) {
|
|
3546
3553
|
return (0, import_dynamic_flow_types.validateActionResponse)(body).valid;
|
|
3547
3554
|
}
|
|
@@ -6019,7 +6026,7 @@ var executeSubmission = async (props) => {
|
|
|
6019
6026
|
const extra = { actionId, errorMessage: "Network Error" };
|
|
6020
6027
|
trackEvent("Action Failed", extra);
|
|
6021
6028
|
logEvent("error", "Dynamic Flow - Action Failed Unexpectedly", extra);
|
|
6022
|
-
return { type: "error"
|
|
6029
|
+
return { type: "error" };
|
|
6023
6030
|
}
|
|
6024
6031
|
if (!response.ok) {
|
|
6025
6032
|
return handleErrorResponse(response, actionId);
|
|
@@ -6062,16 +6069,27 @@ var executeSubmission = async (props) => {
|
|
|
6062
6069
|
}
|
|
6063
6070
|
};
|
|
6064
6071
|
const handleErrorResponse = async (response, actionId) => {
|
|
6065
|
-
const body = await parseResponseBodyAsJsonElement(response);
|
|
6072
|
+
const body = await parseResponseBodyAsJsonElement(response.clone());
|
|
6066
6073
|
if (isErrorResponseBody(body)) {
|
|
6067
6074
|
const refreshUrl = body.refreshUrl || body.refreshFormUrl;
|
|
6068
6075
|
const { error, validation, analytics } = body;
|
|
6069
6076
|
trackEvent("Action Failed", __spreadProps(__spreadValues({}, analytics), { actionId, statusCode: response.status }));
|
|
6070
6077
|
const errors = { error, validation };
|
|
6071
|
-
return refreshUrl ? { type: "refresh", body: { refreshUrl, errors } } : {
|
|
6078
|
+
return refreshUrl ? { type: "refresh", body: { refreshUrl, errors } } : {
|
|
6079
|
+
type: "error",
|
|
6080
|
+
body: { errors, analytics },
|
|
6081
|
+
httpError: { statusCode: response.status }
|
|
6082
|
+
};
|
|
6072
6083
|
}
|
|
6073
6084
|
trackEvent("Action Failed", { actionId, statusCode: response.status });
|
|
6074
|
-
|
|
6085
|
+
const errorMessage = await parseResponseBodyAsText(response);
|
|
6086
|
+
return {
|
|
6087
|
+
type: "error",
|
|
6088
|
+
httpError: {
|
|
6089
|
+
message: errorMessage || void 0,
|
|
6090
|
+
statusCode: response.status
|
|
6091
|
+
}
|
|
6092
|
+
};
|
|
6075
6093
|
};
|
|
6076
6094
|
return triggerAction(props.action, props.model, props.isInitial);
|
|
6077
6095
|
};
|
|
@@ -6495,7 +6513,7 @@ function useDynamicFlowCore(props) {
|
|
|
6495
6513
|
}
|
|
6496
6514
|
}, []);
|
|
6497
6515
|
const onAction = (0, import_react3.useCallback)(async (action) => {
|
|
6498
|
-
var _a2;
|
|
6516
|
+
var _a2, _b, _c, _d, _e, _f, _g;
|
|
6499
6517
|
try {
|
|
6500
6518
|
rootComponentRef.current.setLoadingState("submitting");
|
|
6501
6519
|
const model = (_a2 = await rootComponentRef.current.getSubmittableValue()) != null ? _a2 : null;
|
|
@@ -6522,7 +6540,7 @@ function useDynamicFlowCore(props) {
|
|
|
6522
6540
|
}
|
|
6523
6541
|
case "error": {
|
|
6524
6542
|
const genericErrorMessage = getErrorMessageFunctions().genericErrorWithRetry();
|
|
6525
|
-
const
|
|
6543
|
+
const errors = (_c = (_b = command.body) == null ? void 0 : _b.errors) != null ? _c : { error: genericErrorMessage };
|
|
6526
6544
|
if (stepRef.current) {
|
|
6527
6545
|
updateStep(
|
|
6528
6546
|
__spreadProps(__spreadValues({}, stepRef.current), {
|
|
@@ -6539,12 +6557,13 @@ function useDynamicFlowCore(props) {
|
|
|
6539
6557
|
etagRef.current
|
|
6540
6558
|
);
|
|
6541
6559
|
} else {
|
|
6560
|
+
const errorMessage = ((_e = (_d = command.body) == null ? void 0 : _d.errors) == null ? void 0 : _e.error) || ((_f = command.httpError) == null ? void 0 : _f.message) || "Initial request failed";
|
|
6542
6561
|
closeWithError(
|
|
6543
|
-
new Error(
|
|
6562
|
+
new Error(errorMessage, {
|
|
6544
6563
|
cause: `method: ${action.method}, url: ${action.url}`
|
|
6545
6564
|
}),
|
|
6546
6565
|
{},
|
|
6547
|
-
command.statusCode
|
|
6566
|
+
(_g = command.httpError) == null ? void 0 : _g.statusCode
|
|
6548
6567
|
);
|
|
6549
6568
|
}
|
|
6550
6569
|
break;
|
package/build/main.mjs
CHANGED
|
@@ -3499,6 +3499,13 @@ var parseResponseBodyAsJsonElement = async (response) => {
|
|
|
3499
3499
|
return null;
|
|
3500
3500
|
}
|
|
3501
3501
|
};
|
|
3502
|
+
var parseResponseBodyAsText = async (response) => {
|
|
3503
|
+
try {
|
|
3504
|
+
return await response.text();
|
|
3505
|
+
} catch (e) {
|
|
3506
|
+
return null;
|
|
3507
|
+
}
|
|
3508
|
+
};
|
|
3502
3509
|
function isActionResponseBody(body) {
|
|
3503
3510
|
return validateActionResponse(body).valid;
|
|
3504
3511
|
}
|
|
@@ -5976,7 +5983,7 @@ var executeSubmission = async (props) => {
|
|
|
5976
5983
|
const extra = { actionId, errorMessage: "Network Error" };
|
|
5977
5984
|
trackEvent("Action Failed", extra);
|
|
5978
5985
|
logEvent("error", "Dynamic Flow - Action Failed Unexpectedly", extra);
|
|
5979
|
-
return { type: "error"
|
|
5986
|
+
return { type: "error" };
|
|
5980
5987
|
}
|
|
5981
5988
|
if (!response.ok) {
|
|
5982
5989
|
return handleErrorResponse(response, actionId);
|
|
@@ -6019,16 +6026,27 @@ var executeSubmission = async (props) => {
|
|
|
6019
6026
|
}
|
|
6020
6027
|
};
|
|
6021
6028
|
const handleErrorResponse = async (response, actionId) => {
|
|
6022
|
-
const body = await parseResponseBodyAsJsonElement(response);
|
|
6029
|
+
const body = await parseResponseBodyAsJsonElement(response.clone());
|
|
6023
6030
|
if (isErrorResponseBody(body)) {
|
|
6024
6031
|
const refreshUrl = body.refreshUrl || body.refreshFormUrl;
|
|
6025
6032
|
const { error, validation, analytics } = body;
|
|
6026
6033
|
trackEvent("Action Failed", __spreadProps(__spreadValues({}, analytics), { actionId, statusCode: response.status }));
|
|
6027
6034
|
const errors = { error, validation };
|
|
6028
|
-
return refreshUrl ? { type: "refresh", body: { refreshUrl, errors } } : {
|
|
6035
|
+
return refreshUrl ? { type: "refresh", body: { refreshUrl, errors } } : {
|
|
6036
|
+
type: "error",
|
|
6037
|
+
body: { errors, analytics },
|
|
6038
|
+
httpError: { statusCode: response.status }
|
|
6039
|
+
};
|
|
6029
6040
|
}
|
|
6030
6041
|
trackEvent("Action Failed", { actionId, statusCode: response.status });
|
|
6031
|
-
|
|
6042
|
+
const errorMessage = await parseResponseBodyAsText(response);
|
|
6043
|
+
return {
|
|
6044
|
+
type: "error",
|
|
6045
|
+
httpError: {
|
|
6046
|
+
message: errorMessage || void 0,
|
|
6047
|
+
statusCode: response.status
|
|
6048
|
+
}
|
|
6049
|
+
};
|
|
6032
6050
|
};
|
|
6033
6051
|
return triggerAction(props.action, props.model, props.isInitial);
|
|
6034
6052
|
};
|
|
@@ -6452,7 +6470,7 @@ function useDynamicFlowCore(props) {
|
|
|
6452
6470
|
}
|
|
6453
6471
|
}, []);
|
|
6454
6472
|
const onAction = useCallback2(async (action) => {
|
|
6455
|
-
var _a2;
|
|
6473
|
+
var _a2, _b, _c, _d, _e, _f, _g;
|
|
6456
6474
|
try {
|
|
6457
6475
|
rootComponentRef.current.setLoadingState("submitting");
|
|
6458
6476
|
const model = (_a2 = await rootComponentRef.current.getSubmittableValue()) != null ? _a2 : null;
|
|
@@ -6479,7 +6497,7 @@ function useDynamicFlowCore(props) {
|
|
|
6479
6497
|
}
|
|
6480
6498
|
case "error": {
|
|
6481
6499
|
const genericErrorMessage = getErrorMessageFunctions().genericErrorWithRetry();
|
|
6482
|
-
const
|
|
6500
|
+
const errors = (_c = (_b = command.body) == null ? void 0 : _b.errors) != null ? _c : { error: genericErrorMessage };
|
|
6483
6501
|
if (stepRef.current) {
|
|
6484
6502
|
updateStep(
|
|
6485
6503
|
__spreadProps(__spreadValues({}, stepRef.current), {
|
|
@@ -6496,12 +6514,13 @@ function useDynamicFlowCore(props) {
|
|
|
6496
6514
|
etagRef.current
|
|
6497
6515
|
);
|
|
6498
6516
|
} else {
|
|
6517
|
+
const errorMessage = ((_e = (_d = command.body) == null ? void 0 : _d.errors) == null ? void 0 : _e.error) || ((_f = command.httpError) == null ? void 0 : _f.message) || "Initial request failed";
|
|
6499
6518
|
closeWithError(
|
|
6500
|
-
new Error(
|
|
6519
|
+
new Error(errorMessage, {
|
|
6501
6520
|
cause: `method: ${action.method}, url: ${action.url}`
|
|
6502
6521
|
}),
|
|
6503
6522
|
{},
|
|
6504
|
-
command.statusCode
|
|
6523
|
+
(_g = command.httpError) == null ? void 0 : _g.statusCode
|
|
6505
6524
|
);
|
|
6506
6525
|
}
|
|
6507
6526
|
break;
|
|
@@ -10,11 +10,14 @@ type Command = {
|
|
|
10
10
|
etag: string | null;
|
|
11
11
|
} | {
|
|
12
12
|
type: 'error';
|
|
13
|
-
body
|
|
13
|
+
body?: {
|
|
14
14
|
analytics?: ErrorResponseBody['analytics'];
|
|
15
15
|
errors?: Step['errors'];
|
|
16
16
|
};
|
|
17
|
-
|
|
17
|
+
httpError?: {
|
|
18
|
+
message?: string;
|
|
19
|
+
statusCode?: number;
|
|
20
|
+
};
|
|
18
21
|
} | {
|
|
19
22
|
type: 'refresh';
|
|
20
23
|
body: {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { ActionResponseBody, ErrorResponseBody, JsonElement, ModalBehavior, Step } from '@wise/dynamic-flow-types/build/next';
|
|
2
2
|
export declare const assertResponseIsValid: (response: unknown) => void;
|
|
3
3
|
export declare const parseResponseBodyAsJsonElement: (response: Response) => Promise<JsonElement>;
|
|
4
|
+
export declare const parseResponseBodyAsText: (response: Response) => Promise<string | null>;
|
|
4
5
|
export declare function isActionResponseBody(body: unknown): body is ActionResponseBody;
|
|
5
6
|
export declare function assertActionResponseBody(body: unknown): asserts body is ActionResponseBody;
|
|
6
7
|
export declare function assertModalResponseBody(body: unknown): asserts body is Omit<ModalBehavior, 'type'>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wise/dynamic-flow-client",
|
|
3
|
-
"version": "4.7.
|
|
3
|
+
"version": "4.7.1",
|
|
4
4
|
"description": "Dynamic Flow web client",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"main": "./build/main.js",
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"@testing-library/jest-dom": "6.6.3",
|
|
47
47
|
"@testing-library/react": "16.3.0",
|
|
48
48
|
"@testing-library/user-event": "14.6.1",
|
|
49
|
-
"@transferwise/components": "46.
|
|
49
|
+
"@transferwise/components": "46.98.1",
|
|
50
50
|
"@transferwise/formatting": "^2.13.1",
|
|
51
51
|
"@transferwise/icons": "3.22.0",
|
|
52
52
|
"@transferwise/neptune-css": "14.24.4",
|
|
@@ -78,8 +78,8 @@
|
|
|
78
78
|
"stylelint-value-no-unknown-custom-properties": "6.0.1",
|
|
79
79
|
"tsx": "4.20.3",
|
|
80
80
|
"typescript": "5.8.3",
|
|
81
|
-
"@wise/dynamic-flow-
|
|
82
|
-
"@wise/dynamic-flow-
|
|
81
|
+
"@wise/dynamic-flow-fixtures": "0.0.1",
|
|
82
|
+
"@wise/dynamic-flow-renderers": "0.0.0"
|
|
83
83
|
},
|
|
84
84
|
"peerDependencies": {
|
|
85
85
|
"@transferwise/components": "^46.92.0",
|
|
@@ -95,7 +95,7 @@
|
|
|
95
95
|
"classnames": "2.5.1",
|
|
96
96
|
"react-webcam": "^7.2.0",
|
|
97
97
|
"screenfull": "^5.2.0",
|
|
98
|
-
"@wise/dynamic-flow-types": "3.5.
|
|
98
|
+
"@wise/dynamic-flow-types": "3.5.1"
|
|
99
99
|
},
|
|
100
100
|
"scripts": {
|
|
101
101
|
"dev": "pnpm build:visual-tests && storybook dev -p 3003",
|