@wise/dynamic-flow-client 3.12.0 → 3.12.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 +120 -88
- package/build/main.min.js +1 -1
- package/build/main.mjs +120 -88
- package/build/types/revamp/domain/mappers/mapUnreferencedSchemas.d.ts +3 -0
- package/package.json +1 -1
package/build/main.js
CHANGED
|
@@ -6630,6 +6630,90 @@ var createStepComponent = (stepProps) => {
|
|
|
6630
6630
|
});
|
|
6631
6631
|
};
|
|
6632
6632
|
|
|
6633
|
+
// src/revamp/flow/response-utils.ts
|
|
6634
|
+
var assertResponseIsValid = (response) => {
|
|
6635
|
+
if (!isResponse(response)) {
|
|
6636
|
+
throw new Error("Incorrect type of response from fetch. Expected object of type Response.");
|
|
6637
|
+
}
|
|
6638
|
+
if (response.bodyUsed) {
|
|
6639
|
+
throw new Error(
|
|
6640
|
+
"The body of the provided Response object has already been used. Every request must respond with a new Response object."
|
|
6641
|
+
);
|
|
6642
|
+
}
|
|
6643
|
+
};
|
|
6644
|
+
var isResponse = (response) => typeof response === "object" && response !== null && "clone" in response && "bodyUsed" in response;
|
|
6645
|
+
var parseResponseBodyAsJsonElement = async (response) => {
|
|
6646
|
+
try {
|
|
6647
|
+
return await response.json();
|
|
6648
|
+
} catch (e) {
|
|
6649
|
+
return null;
|
|
6650
|
+
}
|
|
6651
|
+
};
|
|
6652
|
+
function isActionResponseBody(body) {
|
|
6653
|
+
return validateActionResponse(body).valid;
|
|
6654
|
+
}
|
|
6655
|
+
function assertActionResponseBody(body) {
|
|
6656
|
+
if (!isObject(body) || !isObject(body.action)) {
|
|
6657
|
+
throw new Error(
|
|
6658
|
+
"Incorrect response body in action response. Expected an object satisfying the type { action: Action }."
|
|
6659
|
+
);
|
|
6660
|
+
}
|
|
6661
|
+
}
|
|
6662
|
+
function isErrorResponseBody(body) {
|
|
6663
|
+
return Boolean(
|
|
6664
|
+
isObject(body) && (body.refreshFormUrl || body.refreshUrl || body.validation || body.error || body.analytics)
|
|
6665
|
+
);
|
|
6666
|
+
}
|
|
6667
|
+
function assertStepResponseBody(body) {
|
|
6668
|
+
if (!isObject(body)) {
|
|
6669
|
+
throw new Error("Incorrect response body in step response. Expected an object.");
|
|
6670
|
+
}
|
|
6671
|
+
}
|
|
6672
|
+
|
|
6673
|
+
// src/revamp/domain/features/polling/getStepPolling.ts
|
|
6674
|
+
var getStepPolling = ({
|
|
6675
|
+
httpClient,
|
|
6676
|
+
pollingConfig,
|
|
6677
|
+
onAction
|
|
6678
|
+
}) => {
|
|
6679
|
+
const { interval, maxAttempts, url, onError } = pollingConfig;
|
|
6680
|
+
let abortController = new AbortController();
|
|
6681
|
+
const onFailure = () => {
|
|
6682
|
+
stop();
|
|
6683
|
+
void onAction(onError.action);
|
|
6684
|
+
};
|
|
6685
|
+
let attempts = 0;
|
|
6686
|
+
const poll = () => {
|
|
6687
|
+
attempts += 1;
|
|
6688
|
+
abortController.abort();
|
|
6689
|
+
abortController = new AbortController();
|
|
6690
|
+
const { signal } = abortController;
|
|
6691
|
+
httpClient(url, { signal }).then(async (response) => {
|
|
6692
|
+
if (!response.ok) {
|
|
6693
|
+
onFailure();
|
|
6694
|
+
return;
|
|
6695
|
+
}
|
|
6696
|
+
response.json().then((body) => {
|
|
6697
|
+
if (isActionResponseBody(body)) {
|
|
6698
|
+
void onAction(body.action);
|
|
6699
|
+
stop();
|
|
6700
|
+
}
|
|
6701
|
+
}).catch(() => {
|
|
6702
|
+
});
|
|
6703
|
+
}).catch(() => {
|
|
6704
|
+
});
|
|
6705
|
+
if (attempts >= maxAttempts && !signal.aborted) {
|
|
6706
|
+
onFailure();
|
|
6707
|
+
}
|
|
6708
|
+
};
|
|
6709
|
+
const intervalRef = setInterval(poll, interval * 1e3);
|
|
6710
|
+
const stop = () => {
|
|
6711
|
+
abortController.abort();
|
|
6712
|
+
clearTimeout(intervalRef);
|
|
6713
|
+
};
|
|
6714
|
+
return { stop };
|
|
6715
|
+
};
|
|
6716
|
+
|
|
6633
6717
|
// src/revamp/domain/components/AlertComponent.ts
|
|
6634
6718
|
var createAlertComponent = (alertProps) => __spreadProps(__spreadValues({
|
|
6635
6719
|
type: "alert"
|
|
@@ -7339,46 +7423,6 @@ var autocompleteTokenMap = {
|
|
|
7339
7423
|
pager: "pager"
|
|
7340
7424
|
};
|
|
7341
7425
|
|
|
7342
|
-
// src/revamp/flow/response-utils.ts
|
|
7343
|
-
var assertResponseIsValid = (response) => {
|
|
7344
|
-
if (!isResponse(response)) {
|
|
7345
|
-
throw new Error("Incorrect type of response from fetch. Expected object of type Response.");
|
|
7346
|
-
}
|
|
7347
|
-
if (response.bodyUsed) {
|
|
7348
|
-
throw new Error(
|
|
7349
|
-
"The body of the provided Response object has already been used. Every request must respond with a new Response object."
|
|
7350
|
-
);
|
|
7351
|
-
}
|
|
7352
|
-
};
|
|
7353
|
-
var isResponse = (response) => typeof response === "object" && response !== null && "clone" in response && "bodyUsed" in response;
|
|
7354
|
-
var parseResponseBodyAsJsonElement = async (response) => {
|
|
7355
|
-
try {
|
|
7356
|
-
return await response.json();
|
|
7357
|
-
} catch (e) {
|
|
7358
|
-
return null;
|
|
7359
|
-
}
|
|
7360
|
-
};
|
|
7361
|
-
function isActionResponseBody(body) {
|
|
7362
|
-
return validateActionResponse(body).valid;
|
|
7363
|
-
}
|
|
7364
|
-
function assertActionResponseBody(body) {
|
|
7365
|
-
if (!isObject(body) || !isObject(body.action)) {
|
|
7366
|
-
throw new Error(
|
|
7367
|
-
"Incorrect response body in action response. Expected an object satisfying the type { action: Action }."
|
|
7368
|
-
);
|
|
7369
|
-
}
|
|
7370
|
-
}
|
|
7371
|
-
function isErrorResponseBody(body) {
|
|
7372
|
-
return Boolean(
|
|
7373
|
-
isObject(body) && (body.refreshFormUrl || body.refreshUrl || body.validation || body.error || body.analytics)
|
|
7374
|
-
);
|
|
7375
|
-
}
|
|
7376
|
-
function assertStepResponseBody(body) {
|
|
7377
|
-
if (!isObject(body)) {
|
|
7378
|
-
throw new Error("Incorrect response body in step response. Expected an object.");
|
|
7379
|
-
}
|
|
7380
|
-
}
|
|
7381
|
-
|
|
7382
7426
|
// src/revamp/domain/features/utils/response-utils.ts
|
|
7383
7427
|
var getAnalyticsFromErrorResponse = (json) => {
|
|
7384
7428
|
if (!isErrorResponseBody(json)) {
|
|
@@ -9416,7 +9460,7 @@ var createFormComponent = (formProps) => __spreadProps(__spreadValues({}, formPr
|
|
|
9416
9460
|
// src/revamp/domain/mappers/layout/formLayoutToComponent.ts
|
|
9417
9461
|
var formLayoutToComponent = (uid, { schemaId, schema: schemaRef, control, margin = "md" }, mapperProps) => {
|
|
9418
9462
|
const { step, stepLocalValue } = mapperProps;
|
|
9419
|
-
const { model, errors
|
|
9463
|
+
const { schemas, model, errors } = step;
|
|
9420
9464
|
const id = schemaId != null ? schemaId : schemaRef == null ? void 0 : schemaRef.$ref;
|
|
9421
9465
|
const schema = schemas.find((s) => s.$id === id);
|
|
9422
9466
|
if (!schema) {
|
|
@@ -9878,48 +9922,37 @@ var mapLayoutToComponent = (uid, layout, mapperProps) => {
|
|
|
9878
9922
|
}
|
|
9879
9923
|
};
|
|
9880
9924
|
|
|
9881
|
-
// src/revamp/domain/
|
|
9882
|
-
var
|
|
9883
|
-
|
|
9884
|
-
|
|
9885
|
-
|
|
9886
|
-
|
|
9887
|
-
|
|
9888
|
-
|
|
9889
|
-
|
|
9890
|
-
|
|
9891
|
-
|
|
9892
|
-
|
|
9893
|
-
|
|
9894
|
-
|
|
9895
|
-
|
|
9896
|
-
|
|
9897
|
-
|
|
9898
|
-
|
|
9899
|
-
|
|
9900
|
-
|
|
9901
|
-
|
|
9902
|
-
|
|
9903
|
-
}
|
|
9904
|
-
response.json().then((body) => {
|
|
9905
|
-
if (isActionResponseBody(body)) {
|
|
9906
|
-
void onAction(body.action);
|
|
9907
|
-
stop();
|
|
9908
|
-
}
|
|
9909
|
-
}).catch(() => {
|
|
9910
|
-
});
|
|
9911
|
-
}).catch(() => {
|
|
9925
|
+
// src/revamp/domain/mappers/mapUnreferencedSchemas.ts
|
|
9926
|
+
var mapUnreferencedSchemas = (mapperProps) => {
|
|
9927
|
+
const { step } = mapperProps;
|
|
9928
|
+
const { model } = step;
|
|
9929
|
+
return getUnreferencedSchemas(step).map((schema) => __spreadProps(__spreadValues({}, schema), { hidden: true })).map((schema, index) => {
|
|
9930
|
+
const uid = `unreferenced-schema-${index}`;
|
|
9931
|
+
return createFormComponent({
|
|
9932
|
+
uid,
|
|
9933
|
+
components: [
|
|
9934
|
+
mapSchemaToComponent(
|
|
9935
|
+
{
|
|
9936
|
+
uid: `${uid}.form`,
|
|
9937
|
+
schema,
|
|
9938
|
+
model: model != null ? model : null,
|
|
9939
|
+
localValue: null,
|
|
9940
|
+
required: false
|
|
9941
|
+
},
|
|
9942
|
+
mapperProps
|
|
9943
|
+
)
|
|
9944
|
+
],
|
|
9945
|
+
control: void 0,
|
|
9946
|
+
margin: "xs"
|
|
9912
9947
|
});
|
|
9913
|
-
|
|
9914
|
-
|
|
9915
|
-
|
|
9916
|
-
};
|
|
9917
|
-
const
|
|
9918
|
-
|
|
9919
|
-
|
|
9920
|
-
|
|
9921
|
-
};
|
|
9922
|
-
return { stop };
|
|
9948
|
+
});
|
|
9949
|
+
};
|
|
9950
|
+
var getUnreferencedSchemas = (step) => {
|
|
9951
|
+
const { schemas, layout } = step;
|
|
9952
|
+
const stringifiedLayout = JSON.stringify(layout);
|
|
9953
|
+
return schemas.filter(
|
|
9954
|
+
(schema) => !stringifiedLayout.includes(`"schemaId":"${schema.$id}"`) && !stringifiedLayout.includes(`"schema":{"$ref":"${schema.$id}"`)
|
|
9955
|
+
);
|
|
9923
9956
|
};
|
|
9924
9957
|
|
|
9925
9958
|
// src/revamp/domain/mappers/mapStepToComponent.ts
|
|
@@ -9965,17 +9998,16 @@ var mapStepToComponent = (_a) => {
|
|
|
9965
9998
|
};
|
|
9966
9999
|
const onRefresh = async (schemaId, url) => restProps.onRefresh(schemaId, url != null ? url : refreshUrl);
|
|
9967
10000
|
const stepPolling = polling ? getStepPolling({ httpClient, pollingConfig: polling, onAction: restProps.onAction }) : void 0;
|
|
10001
|
+
const mapperProps = __spreadProps(__spreadValues({}, restProps), { trackEvent, onAction, onRefresh });
|
|
10002
|
+
const unreferencedSchemaFormComponents = mapUnreferencedSchemas(mapperProps);
|
|
9968
10003
|
const layoutComponents = layout.map(
|
|
9969
|
-
(layoutComponent, index) => mapLayoutToComponent(`${uid}.layout-${index}`, layoutComponent,
|
|
9970
|
-
trackEvent,
|
|
9971
|
-
onAction,
|
|
9972
|
-
onRefresh
|
|
9973
|
-
}))
|
|
10004
|
+
(layoutComponent, index) => mapLayoutToComponent(`${uid}.layout-${index}`, layoutComponent, mapperProps)
|
|
9974
10005
|
);
|
|
10006
|
+
const components = [...unreferencedSchemaFormComponents, ...layoutComponents];
|
|
9975
10007
|
const stepComponent = createStepComponent({
|
|
9976
10008
|
uid,
|
|
9977
10009
|
back,
|
|
9978
|
-
components
|
|
10010
|
+
components,
|
|
9979
10011
|
description,
|
|
9980
10012
|
error: errors == null ? void 0 : errors.error,
|
|
9981
10013
|
external,
|