@wise/dynamic-flow-client 1.2.2 → 1.3.0

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
@@ -767,12 +767,24 @@ function inlineFormSchema({
767
767
  formComponent,
768
768
  schemas
769
769
  }) {
770
- if (isReference(formComponent.schema) && formComponent.schema.$ref) {
771
- return __spreadProps(__spreadValues({}, formComponent), {
770
+ if (formComponent.schemaId) {
771
+ return {
772
+ type: "form",
773
+ margin: formComponent.margin,
774
+ schema: getSchemaById(schemas, formComponent.schemaId)
775
+ };
776
+ }
777
+ if (formComponent.schema && isReference(formComponent.schema) && formComponent.schema.$ref) {
778
+ return {
779
+ type: "form",
780
+ margin: formComponent.margin,
772
781
  schema: getSchemaById(schemas, formComponent.schema.$ref)
773
- });
782
+ };
783
+ }
784
+ if (formComponent.schema && !isReference(formComponent.schema)) {
785
+ return __spreadValues({}, formComponent);
774
786
  }
775
- return __spreadValues({}, formComponent);
787
+ throw new Error('Invalid form layout component. Missing "schema" or "schemaId" properties.');
776
788
  }
777
789
  function inlineDecisionActions({
778
790
  decisionComponent,
@@ -5874,13 +5886,6 @@ function useDebouncedRefresh(fetchRefresh) {
5874
5886
 
5875
5887
  // src/dynamicFlow/utils/useDynamicFlowState.ts
5876
5888
  var import_react35 = require("react");
5877
-
5878
- // src/dynamicFlow/DynamicFlowTypes.ts
5879
- function isSchema(schema2) {
5880
- return Object.prototype.hasOwnProperty.call(schema2, "$ref") === false;
5881
- }
5882
-
5883
- // src/dynamicFlow/utils/useDynamicFlowState.ts
5884
5889
  var useDynamicFlowState = (initialStep) => {
5885
5890
  var _a, _b;
5886
5891
  const [formErrors, setFormErrors] = (0, import_react35.useState)((_a = initialStep == null ? void 0 : initialStep.errors) == null ? void 0 : _a.validation);
@@ -5950,7 +5955,7 @@ var getAllSchemasInLayout = (components) => components.flatMap((component) => {
5950
5955
  case "box":
5951
5956
  return getAllSchemasInLayout(component.components);
5952
5957
  case "form":
5953
- return isSchema(component.schema) ? [component.schema] : [];
5958
+ return isInlineSchema(component.schema) ? [component.schema] : [];
5954
5959
  default:
5955
5960
  return [];
5956
5961
  }
@@ -5963,6 +5968,9 @@ var areModelsValid = (formModels, schemas = []) => {
5963
5968
  return !isValidSchema(formModels[schema2.$id || ""] || {}, schema2);
5964
5969
  }));
5965
5970
  };
5971
+ var isInlineSchema = (schema2) => {
5972
+ return schema2 !== void 0 && typeof schema2 === "object" && Object.prototype.hasOwnProperty.call(schema2, "$ref") === false;
5973
+ };
5966
5974
 
5967
5975
  // src/dynamicFlow/utils/useLoader.tsx
5968
5976
  var import_components24 = require("@transferwise/components");
@@ -6122,7 +6130,7 @@ var parseErrorResponse = async (response) => {
6122
6130
  if (!isObject(jsonBody)) {
6123
6131
  throw new Error("Incorrect response body in error response. Expected an object.");
6124
6132
  }
6125
- if (!jsonBody.refreshFormUrl && !jsonBody.validation && !jsonBody.error) {
6133
+ if (!jsonBody.refreshFormUrl && !jsonBody.refreshUrl && !jsonBody.validation && !jsonBody.error) {
6126
6134
  throw jsonBody;
6127
6135
  }
6128
6136
  return jsonBody;
@@ -6302,8 +6310,9 @@ var DynamicFlowComponent = ({
6302
6310
  }
6303
6311
  };
6304
6312
  const updateAfterError = async (errorBody) => {
6305
- if (errorBody.refreshFormUrl) {
6306
- await performRefresh(errorBody.refreshFormUrl, combineModels2(models), etag);
6313
+ const refreshUrl = errorBody.refreshUrl || errorBody.refreshFormUrl;
6314
+ if (refreshUrl) {
6315
+ await performRefresh(refreshUrl, combineModels2(models), etag);
6307
6316
  }
6308
6317
  if (errorBody.validation) {
6309
6318
  setFormErrors(errorBody.validation);
@@ -6340,9 +6349,11 @@ var DynamicFlowComponent = ({
6340
6349
  const refreshOnChangeIfNeeded = (props, updatedModels) => {
6341
6350
  const { triggerSchema } = props;
6342
6351
  if (shouldTriggerRefresh(props)) {
6343
- const url = triggerSchema.refreshFormUrl || (step35 == null ? void 0 : step35.refreshFormUrl);
6344
- if (url) {
6345
- debouncedRefresh(url, combineModels2(updatedModels), etag, triggerSchema);
6352
+ const triggerSchemaRefreshUrl = triggerSchema.refreshUrl || triggerSchema.refreshFormUrl;
6353
+ const stepRefreshUrl = (step35 == null ? void 0 : step35.refreshUrl) || (step35 == null ? void 0 : step35.refreshFormUrl);
6354
+ const refreshUrl = triggerSchemaRefreshUrl || stepRefreshUrl;
6355
+ if (refreshUrl) {
6356
+ debouncedRefresh(refreshUrl, combineModels2(updatedModels), etag, triggerSchema);
6346
6357
  }
6347
6358
  }
6348
6359
  };
@@ -6396,7 +6407,8 @@ var shouldTriggerRefresh = (props) => {
6396
6407
  const { type, triggerSchema, triggerModel, lastTriggerModel = null } = props;
6397
6408
  const isValid = () => isValidSchema(triggerModel, triggerSchema);
6398
6409
  const wasValid = () => isValidSchema(lastTriggerModel, triggerSchema);
6399
- return type !== "init" && (triggerSchema == null ? void 0 : triggerSchema.refreshFormOnChange) && (isValid() || wasValid());
6410
+ const hasRefreshOnChange = (triggerSchema == null ? void 0 : triggerSchema.refreshStepOnChange) || (triggerSchema == null ? void 0 : triggerSchema.refreshFormOnChange);
6411
+ return type !== "init" && hasRefreshOnChange && (isValid() || wasValid());
6400
6412
  };
6401
6413
 
6402
6414
  // src/fixtures/components/index.ts
@@ -6512,7 +6524,7 @@ var step3 = {
6512
6524
  },
6513
6525
  {
6514
6526
  type: "form",
6515
- schema: { $ref: "#schema" }
6527
+ schemaId: "#schema"
6516
6528
  },
6517
6529
  ...buttons,
6518
6530
  {
@@ -6932,7 +6944,7 @@ var step16 = {
6932
6944
  {
6933
6945
  properties: {
6934
6946
  frontSideFile: {
6935
- refreshFormOnChange: false,
6947
+ refreshStepOnChange: false,
6936
6948
  format: "base64url",
6937
6949
  $id: "frontSideFile",
6938
6950
  title: "Passport photo page",
@@ -6950,77 +6962,24 @@ var step16 = {
6950
6962
  },
6951
6963
  required: ["frontSideFile"],
6952
6964
  displayOrder: ["frontSideFile"],
6953
- $id: "ee2501a9-2566-459b-a42e-f9f0932be0e6",
6954
- type: "object"
6955
- },
6956
- {
6957
- properties: {
6958
- type: {
6959
- refreshFormOnChange: false,
6960
- $id: "9200f887-bfdd-46ad-8386-e76f455a7cc8",
6961
- const: "ID_DOCUMENT_WITH_LIVENESS",
6962
- hidden: true,
6963
- type: "string"
6964
- }
6965
- },
6966
- required: ["type"],
6967
- displayOrder: ["type"],
6968
- $id: "c59a2881-a2e0-4108-b42e-0d30fc95bd7f",
6969
- type: "object"
6970
- },
6971
- {
6972
- properties: {
6973
- profileId: {
6974
- refreshFormOnChange: false,
6975
- $id: "75d888dc-208a-4d7d-a2a7-aeca0dd1b533",
6976
- const: 14551053,
6977
- hidden: true,
6978
- type: "integer"
6979
- }
6980
- },
6981
- required: ["profileId"],
6982
- displayOrder: ["profileId"],
6983
- $id: "3eec6add-2d0e-41d7-8317-49542c841484",
6984
- type: "object"
6985
- },
6986
- {
6987
- properties: {
6988
- sessionId: {
6989
- refreshFormOnChange: false,
6990
- $id: "df82adf3-8a66-46b5-bef8-72f59be2188d",
6991
- const: "62dfe7d026c6da1ac0db1ee4",
6992
- hidden: true,
6993
- type: "string"
6994
- }
6995
- },
6996
- required: ["sessionId"],
6997
- displayOrder: ["sessionId"],
6998
- $id: "e1a8fb67-9af2-47e8-97c1-f2a88e5d5f3a",
6965
+ $id: "#the-schema",
6999
6966
  type: "object"
7000
6967
  }
7001
6968
  ],
7002
- actions: [
7003
- {
7004
- url: "/v3/kyc-checks/87785/flow?actionId=SINGLE_PAGE_REVIEW&sessionId=62dfe7d026c6da1ac0db1ee4&",
7005
- type: "primary",
7006
- method: "POST",
7007
- disabled: false,
7008
- $id: "6789eac5-7bbe-49d8-9da8-6edb8e7ef165",
7009
- title: ""
7010
- }
7011
- ],
7012
6969
  layout: [
7013
6970
  {
7014
6971
  type: "form",
7015
- schema: {
7016
- $ref: "ee2501a9-2566-459b-a42e-f9f0932be0e6"
7017
- }
6972
+ schemaId: "#the-schema"
7018
6973
  },
7019
6974
  {
7020
6975
  components: [
7021
6976
  {
7022
6977
  action: {
7023
- $ref: "6789eac5-7bbe-49d8-9da8-6edb8e7ef165"
6978
+ url: "/submit",
6979
+ type: "primary",
6980
+ method: "POST",
6981
+ disabled: false,
6982
+ title: ""
7024
6983
  },
7025
6984
  margin: "lg",
7026
6985
  size: "md",
@@ -7032,17 +6991,8 @@ var step16 = {
7032
6991
  type: "box"
7033
6992
  }
7034
6993
  ],
7035
- model: {
7036
- profileId: 14551053,
7037
- sessionId: "62dfe7d026c6da1ac0db1ee4",
7038
- issuingCountry: "HU",
7039
- documentType: "PASSPORT",
7040
- type: "ID_DOCUMENT_WITH_LIVENESS",
7041
- key: {
7042
- value: "ID_DOCUMENT_WITH_LIVENESS14551053"
7043
- }
7044
- },
7045
- refreshFormUrl: "/"
6994
+ model: {},
6995
+ refreshUrl: "/"
7046
6996
  };
7047
6997
  var camera_capture_default = step16;
7048
6998
 
@@ -7110,7 +7060,7 @@ var step17 = {
7110
7060
  required: "Please enter currency."
7111
7061
  },
7112
7062
  default: "EUR",
7113
- refreshFormOnChange: true
7063
+ refreshStepOnChange: true
7114
7064
  },
7115
7065
  legalEntityType: {
7116
7066
  title: "Select recipient type",
@@ -7131,7 +7081,7 @@ var step17 = {
7131
7081
  validationMessages: {
7132
7082
  required: "Please specify the type of recipient."
7133
7083
  },
7134
- refreshFormOnChange: true
7084
+ refreshStepOnChange: true
7135
7085
  },
7136
7086
  email: {
7137
7087
  title: "Their email",
@@ -7142,10 +7092,10 @@ var step17 = {
7142
7092
  maxLength: "The email you have entered is too long.",
7143
7093
  pattern: "The email address is invalid."
7144
7094
  },
7145
- refreshFormOnChange: true,
7095
+ refreshStepOnChange: true,
7146
7096
  autofillProvider: "contact",
7147
7097
  autofillKey: "contact.email",
7148
- refreshFormUrl: "/steps/recipient",
7098
+ refreshUrl: "/steps/recipient",
7149
7099
  pattern: "\\s*[a-zA-Z0-9.!#$%&'*+\\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+\\s*",
7150
7100
  maxLength: 255
7151
7101
  }
@@ -7222,7 +7172,7 @@ var step17 = {
7222
7172
  pattern: "Please specify a valid IBAN.",
7223
7173
  required: "Please specify an IBAN."
7224
7174
  },
7225
- refreshFormOnChange: true,
7175
+ refreshStepOnChange: true,
7226
7176
  pattern: "^[a-zA-Z]{2}[a-zA-Z0-9 ]{12,40}$",
7227
7177
  minLength: 14,
7228
7178
  maxLength: 42
@@ -7334,13 +7284,11 @@ var step17 = {
7334
7284
  ]
7335
7285
  }
7336
7286
  ],
7337
- refreshFormUrl: "/steps/recipient",
7287
+ refreshUrl: "/steps/recipient",
7338
7288
  layout: [
7339
7289
  {
7340
7290
  type: "form",
7341
- schema: {
7342
- $ref: "#new-recipient"
7343
- }
7291
+ schemaId: "#new-recipient"
7344
7292
  },
7345
7293
  {
7346
7294
  type: "button",
@@ -7365,7 +7313,7 @@ var step18 = {
7365
7313
  title: "Edit recipient",
7366
7314
  schemas: [
7367
7315
  {
7368
- $id: "form",
7316
+ $id: "#form",
7369
7317
  allOf: [
7370
7318
  {
7371
7319
  type: "object",
@@ -7556,7 +7504,7 @@ var step18 = {
7556
7504
  }
7557
7505
  }
7558
7506
  },
7559
- refreshFormUrl: "/steps/recipientUpdate/?refresh",
7507
+ refreshUrl: "/steps/recipientUpdate/?refresh",
7560
7508
  model: {
7561
7509
  country: "GB",
7562
7510
  ownedByCustomer: false,
@@ -7586,10 +7534,8 @@ var step18 = {
7586
7534
  },
7587
7535
  layout: [
7588
7536
  {
7589
- schema: {
7590
- $ref: "form"
7591
- },
7592
- type: "form"
7537
+ type: "form",
7538
+ schemaId: "#form"
7593
7539
  },
7594
7540
  {
7595
7541
  type: "button",
@@ -7616,7 +7562,7 @@ var step19 = {
7616
7562
  displayOrder: ["frontSide"],
7617
7563
  properties: {
7618
7564
  frontSide: {
7619
- refreshFormOnChange: false,
7565
+ refreshStepOnChange: false,
7620
7566
  $id: "frontSide",
7621
7567
  persistAsync: {
7622
7568
  url: "/single-file-upload-url",
@@ -7645,7 +7591,7 @@ var step19 = {
7645
7591
  displayOrder: ["frontSide"],
7646
7592
  properties: {
7647
7593
  frontSide: {
7648
- refreshFormOnChange: false,
7594
+ refreshStepOnChange: false,
7649
7595
  $id: "backSide",
7650
7596
  persistAsync: {
7651
7597
  url: "/single-file-upload-url-fail",
@@ -7676,7 +7622,7 @@ var step19 = {
7676
7622
  },
7677
7623
  {
7678
7624
  type: "form",
7679
- schema: { $ref: "#schema-1" }
7625
+ schemaId: "#schema-1"
7680
7626
  },
7681
7627
  {
7682
7628
  type: "paragraph",
@@ -7684,7 +7630,7 @@ var step19 = {
7684
7630
  },
7685
7631
  {
7686
7632
  type: "form",
7687
- schema: { $ref: "#schema-2" }
7633
+ schemaId: "#schema-2"
7688
7634
  },
7689
7635
  {
7690
7636
  type: "button",
@@ -7717,7 +7663,7 @@ var step20 = {
7717
7663
  layout: [
7718
7664
  {
7719
7665
  type: "form",
7720
- schema: { $ref: "#the-schema" }
7666
+ schemaId: "#the-schema"
7721
7667
  }
7722
7668
  ],
7723
7669
  schemas: [
@@ -7856,7 +7802,7 @@ var step23 = {
7856
7802
  title: "Persist Async Feature",
7857
7803
  schemas: [
7858
7804
  {
7859
- $id: "the-schema",
7805
+ $id: "#the-schema",
7860
7806
  type: "object",
7861
7807
  title: "Some Object",
7862
7808
  displayOrder: ["nameToken"],
@@ -7881,7 +7827,7 @@ var step23 = {
7881
7827
  layout: [
7882
7828
  {
7883
7829
  type: "form",
7884
- schema: { $ref: "the-schema" }
7830
+ schemaId: "#the-schema"
7885
7831
  }
7886
7832
  ]
7887
7833
  };
@@ -7948,14 +7894,10 @@ var step25 = {
7948
7894
  layout: [
7949
7895
  {
7950
7896
  type: "form",
7951
- schema: {
7952
- $ref: "#the-schema"
7953
- }
7897
+ schemaId: "#the-schema"
7954
7898
  }
7955
7899
  ],
7956
- model: {
7957
- // name: 'Colin Robinson',
7958
- }
7900
+ model: {}
7959
7901
  };
7960
7902
  var validation_async_default = step25;
7961
7903
 
@@ -8646,7 +8588,7 @@ var step29 = {
8646
8588
  layout: [
8647
8589
  {
8648
8590
  type: "form",
8649
- schema: { $ref: "#the-schema" }
8591
+ schemaId: "#the-schema"
8650
8592
  },
8651
8593
  {
8652
8594
  type: "button",
@@ -8687,7 +8629,7 @@ var step30 = {
8687
8629
  layout: [
8688
8630
  {
8689
8631
  type: "form",
8690
- schema: { $ref: "#the-schema" }
8632
+ schemaId: "#the-schema"
8691
8633
  },
8692
8634
  {
8693
8635
  type: "button",
@@ -8908,7 +8850,7 @@ var step31 = {
8908
8850
  layout: [
8909
8851
  {
8910
8852
  type: "form",
8911
- schema: { $ref: "#the-schema" }
8853
+ schemaId: "#the-schema"
8912
8854
  },
8913
8855
  {
8914
8856
  type: "button",
@@ -8967,7 +8909,7 @@ var step32 = {
8967
8909
  layout: [
8968
8910
  {
8969
8911
  type: "form",
8970
- schema: { $ref: "#the-schema" }
8912
+ schemaId: "#the-schema"
8971
8913
  },
8972
8914
  {
8973
8915
  type: "button",
@@ -9007,7 +8949,7 @@ var step33 = {
9007
8949
  layout: [
9008
8950
  {
9009
8951
  type: "form",
9010
- schema: { $ref: "#schema-1" }
8952
+ schemaId: "#schema-1"
9011
8953
  },
9012
8954
  {
9013
8955
  type: "button",
@@ -9092,7 +9034,7 @@ var step34 = {
9092
9034
  layout: [
9093
9035
  {
9094
9036
  type: "form",
9095
- schema: { $ref: "#the-schema" }
9037
+ schemaId: "#the-schema"
9096
9038
  },
9097
9039
  {
9098
9040
  type: "button",