@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.mjs CHANGED
@@ -6608,6 +6608,90 @@ var createStepComponent = (stepProps) => {
6608
6608
  });
6609
6609
  };
6610
6610
 
6611
+ // src/revamp/flow/response-utils.ts
6612
+ var assertResponseIsValid = (response) => {
6613
+ if (!isResponse(response)) {
6614
+ throw new Error("Incorrect type of response from fetch. Expected object of type Response.");
6615
+ }
6616
+ if (response.bodyUsed) {
6617
+ throw new Error(
6618
+ "The body of the provided Response object has already been used. Every request must respond with a new Response object."
6619
+ );
6620
+ }
6621
+ };
6622
+ var isResponse = (response) => typeof response === "object" && response !== null && "clone" in response && "bodyUsed" in response;
6623
+ var parseResponseBodyAsJsonElement = async (response) => {
6624
+ try {
6625
+ return await response.json();
6626
+ } catch (e) {
6627
+ return null;
6628
+ }
6629
+ };
6630
+ function isActionResponseBody(body) {
6631
+ return validateActionResponse(body).valid;
6632
+ }
6633
+ function assertActionResponseBody(body) {
6634
+ if (!isObject(body) || !isObject(body.action)) {
6635
+ throw new Error(
6636
+ "Incorrect response body in action response. Expected an object satisfying the type { action: Action }."
6637
+ );
6638
+ }
6639
+ }
6640
+ function isErrorResponseBody(body) {
6641
+ return Boolean(
6642
+ isObject(body) && (body.refreshFormUrl || body.refreshUrl || body.validation || body.error || body.analytics)
6643
+ );
6644
+ }
6645
+ function assertStepResponseBody(body) {
6646
+ if (!isObject(body)) {
6647
+ throw new Error("Incorrect response body in step response. Expected an object.");
6648
+ }
6649
+ }
6650
+
6651
+ // src/revamp/domain/features/polling/getStepPolling.ts
6652
+ var getStepPolling = ({
6653
+ httpClient,
6654
+ pollingConfig,
6655
+ onAction
6656
+ }) => {
6657
+ const { interval, maxAttempts, url, onError } = pollingConfig;
6658
+ let abortController = new AbortController();
6659
+ const onFailure = () => {
6660
+ stop();
6661
+ void onAction(onError.action);
6662
+ };
6663
+ let attempts = 0;
6664
+ const poll = () => {
6665
+ attempts += 1;
6666
+ abortController.abort();
6667
+ abortController = new AbortController();
6668
+ const { signal } = abortController;
6669
+ httpClient(url, { signal }).then(async (response) => {
6670
+ if (!response.ok) {
6671
+ onFailure();
6672
+ return;
6673
+ }
6674
+ response.json().then((body) => {
6675
+ if (isActionResponseBody(body)) {
6676
+ void onAction(body.action);
6677
+ stop();
6678
+ }
6679
+ }).catch(() => {
6680
+ });
6681
+ }).catch(() => {
6682
+ });
6683
+ if (attempts >= maxAttempts && !signal.aborted) {
6684
+ onFailure();
6685
+ }
6686
+ };
6687
+ const intervalRef = setInterval(poll, interval * 1e3);
6688
+ const stop = () => {
6689
+ abortController.abort();
6690
+ clearTimeout(intervalRef);
6691
+ };
6692
+ return { stop };
6693
+ };
6694
+
6611
6695
  // src/revamp/domain/components/AlertComponent.ts
6612
6696
  var createAlertComponent = (alertProps) => __spreadProps(__spreadValues({
6613
6697
  type: "alert"
@@ -7317,46 +7401,6 @@ var autocompleteTokenMap = {
7317
7401
  pager: "pager"
7318
7402
  };
7319
7403
 
7320
- // src/revamp/flow/response-utils.ts
7321
- var assertResponseIsValid = (response) => {
7322
- if (!isResponse(response)) {
7323
- throw new Error("Incorrect type of response from fetch. Expected object of type Response.");
7324
- }
7325
- if (response.bodyUsed) {
7326
- throw new Error(
7327
- "The body of the provided Response object has already been used. Every request must respond with a new Response object."
7328
- );
7329
- }
7330
- };
7331
- var isResponse = (response) => typeof response === "object" && response !== null && "clone" in response && "bodyUsed" in response;
7332
- var parseResponseBodyAsJsonElement = async (response) => {
7333
- try {
7334
- return await response.json();
7335
- } catch (e) {
7336
- return null;
7337
- }
7338
- };
7339
- function isActionResponseBody(body) {
7340
- return validateActionResponse(body).valid;
7341
- }
7342
- function assertActionResponseBody(body) {
7343
- if (!isObject(body) || !isObject(body.action)) {
7344
- throw new Error(
7345
- "Incorrect response body in action response. Expected an object satisfying the type { action: Action }."
7346
- );
7347
- }
7348
- }
7349
- function isErrorResponseBody(body) {
7350
- return Boolean(
7351
- isObject(body) && (body.refreshFormUrl || body.refreshUrl || body.validation || body.error || body.analytics)
7352
- );
7353
- }
7354
- function assertStepResponseBody(body) {
7355
- if (!isObject(body)) {
7356
- throw new Error("Incorrect response body in step response. Expected an object.");
7357
- }
7358
- }
7359
-
7360
7404
  // src/revamp/domain/features/utils/response-utils.ts
7361
7405
  var getAnalyticsFromErrorResponse = (json) => {
7362
7406
  if (!isErrorResponseBody(json)) {
@@ -9394,7 +9438,7 @@ var createFormComponent = (formProps) => __spreadProps(__spreadValues({}, formPr
9394
9438
  // src/revamp/domain/mappers/layout/formLayoutToComponent.ts
9395
9439
  var formLayoutToComponent = (uid, { schemaId, schema: schemaRef, control, margin = "md" }, mapperProps) => {
9396
9440
  const { step, stepLocalValue } = mapperProps;
9397
- const { model, errors, schemas } = step;
9441
+ const { schemas, model, errors } = step;
9398
9442
  const id = schemaId != null ? schemaId : schemaRef == null ? void 0 : schemaRef.$ref;
9399
9443
  const schema = schemas.find((s) => s.$id === id);
9400
9444
  if (!schema) {
@@ -9856,48 +9900,37 @@ var mapLayoutToComponent = (uid, layout, mapperProps) => {
9856
9900
  }
9857
9901
  };
9858
9902
 
9859
- // src/revamp/domain/features/polling/getStepPolling.ts
9860
- var getStepPolling = ({
9861
- httpClient,
9862
- pollingConfig,
9863
- onAction
9864
- }) => {
9865
- const { interval, maxAttempts, url, onError } = pollingConfig;
9866
- let abortController = new AbortController();
9867
- const onFailure = () => {
9868
- stop();
9869
- void onAction(onError.action);
9870
- };
9871
- let attempts = 0;
9872
- const poll = () => {
9873
- attempts += 1;
9874
- abortController.abort();
9875
- abortController = new AbortController();
9876
- const { signal } = abortController;
9877
- httpClient(url, { signal }).then(async (response) => {
9878
- if (!response.ok) {
9879
- onFailure();
9880
- return;
9881
- }
9882
- response.json().then((body) => {
9883
- if (isActionResponseBody(body)) {
9884
- void onAction(body.action);
9885
- stop();
9886
- }
9887
- }).catch(() => {
9888
- });
9889
- }).catch(() => {
9903
+ // src/revamp/domain/mappers/mapUnreferencedSchemas.ts
9904
+ var mapUnreferencedSchemas = (mapperProps) => {
9905
+ const { step } = mapperProps;
9906
+ const { model } = step;
9907
+ return getUnreferencedSchemas(step).map((schema) => __spreadProps(__spreadValues({}, schema), { hidden: true })).map((schema, index) => {
9908
+ const uid = `unreferenced-schema-${index}`;
9909
+ return createFormComponent({
9910
+ uid,
9911
+ components: [
9912
+ mapSchemaToComponent(
9913
+ {
9914
+ uid: `${uid}.form`,
9915
+ schema,
9916
+ model: model != null ? model : null,
9917
+ localValue: null,
9918
+ required: false
9919
+ },
9920
+ mapperProps
9921
+ )
9922
+ ],
9923
+ control: void 0,
9924
+ margin: "xs"
9890
9925
  });
9891
- if (attempts >= maxAttempts && !signal.aborted) {
9892
- onFailure();
9893
- }
9894
- };
9895
- const intervalRef = setInterval(poll, interval * 1e3);
9896
- const stop = () => {
9897
- abortController.abort();
9898
- clearTimeout(intervalRef);
9899
- };
9900
- return { stop };
9926
+ });
9927
+ };
9928
+ var getUnreferencedSchemas = (step) => {
9929
+ const { schemas, layout } = step;
9930
+ const stringifiedLayout = JSON.stringify(layout);
9931
+ return schemas.filter(
9932
+ (schema) => !stringifiedLayout.includes(`"schemaId":"${schema.$id}"`) && !stringifiedLayout.includes(`"schema":{"$ref":"${schema.$id}"`)
9933
+ );
9901
9934
  };
9902
9935
 
9903
9936
  // src/revamp/domain/mappers/mapStepToComponent.ts
@@ -9943,17 +9976,16 @@ var mapStepToComponent = (_a) => {
9943
9976
  };
9944
9977
  const onRefresh = async (schemaId, url) => restProps.onRefresh(schemaId, url != null ? url : refreshUrl);
9945
9978
  const stepPolling = polling ? getStepPolling({ httpClient, pollingConfig: polling, onAction: restProps.onAction }) : void 0;
9979
+ const mapperProps = __spreadProps(__spreadValues({}, restProps), { trackEvent, onAction, onRefresh });
9980
+ const unreferencedSchemaFormComponents = mapUnreferencedSchemas(mapperProps);
9946
9981
  const layoutComponents = layout.map(
9947
- (layoutComponent, index) => mapLayoutToComponent(`${uid}.layout-${index}`, layoutComponent, __spreadProps(__spreadValues({}, restProps), {
9948
- trackEvent,
9949
- onAction,
9950
- onRefresh
9951
- }))
9982
+ (layoutComponent, index) => mapLayoutToComponent(`${uid}.layout-${index}`, layoutComponent, mapperProps)
9952
9983
  );
9984
+ const components = [...unreferencedSchemaFormComponents, ...layoutComponents];
9953
9985
  const stepComponent = createStepComponent({
9954
9986
  uid,
9955
9987
  back,
9956
- components: layoutComponents,
9988
+ components,
9957
9989
  description,
9958
9990
  error: errors == null ? void 0 : errors.error,
9959
9991
  external,
@@ -0,0 +1,3 @@
1
+ import type { DomainComponent } from '../types';
2
+ import type { MapperProps } from './schema/types';
3
+ export declare const mapUnreferencedSchemas: (mapperProps: MapperProps) => DomainComponent[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wise/dynamic-flow-client",
3
- "version": "3.12.0",
3
+ "version": "3.12.1",
4
4
  "description": "Dynamic Flow web client",
5
5
  "license": "Apache-2.0",
6
6
  "main": "./build/main.min.js",