@wise/dynamic-flow-client 4.6.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.
Files changed (31) hide show
  1. package/build/main.js +504 -596
  2. package/build/main.mjs +504 -596
  3. package/build/types/revamp/domain/components/BooleanInputComponent.d.ts +5 -7
  4. package/build/types/revamp/domain/components/DateInputComponent.d.ts +5 -7
  5. package/build/types/revamp/domain/components/IntegerInputComponent.d.ts +5 -7
  6. package/build/types/revamp/domain/components/MultiSelectInputComponent.d.ts +2 -2
  7. package/build/types/revamp/domain/components/NumberInputComponent.d.ts +5 -7
  8. package/build/types/revamp/domain/components/PersistAsyncComponent.d.ts +18 -0
  9. package/build/types/revamp/domain/components/SelectInputComponent.d.ts +3 -3
  10. package/build/types/revamp/domain/components/TextInputComponent.d.ts +5 -7
  11. package/build/types/revamp/domain/components/UploadInputComponent.d.ts +6 -8
  12. package/build/types/revamp/domain/features/persistAsync/getComponentMultiPersistAsync.d.ts +9 -0
  13. package/build/types/revamp/domain/features/schema-on-change/getDebouncedSchemaOnChange.d.ts +10 -0
  14. package/build/types/revamp/domain/features/schema-on-change/getSchemaOnChange.d.ts +7 -0
  15. package/build/types/revamp/domain/mappers/schema/arraySchemaToComponent/arraySchemaToMultiUploadComponent.d.ts +1 -1
  16. package/build/types/revamp/domain/mappers/schema/persistAsyncSchemaToComponent.d.ts +6 -0
  17. package/build/types/revamp/domain/mappers/schema/tests/test-utils.d.ts +1 -0
  18. package/build/types/revamp/domain/mappers/schema/types.d.ts +1 -0
  19. package/build/types/revamp/domain/mappers/schema/utils/getPerformPersistAsyncFn.d.ts +4 -0
  20. package/build/types/revamp/domain/mappers/schema/utils/mapCommonSchemaProps.d.ts +1 -0
  21. package/build/types/revamp/domain/mappers/utils/behavior-utils.d.ts +1 -0
  22. package/build/types/revamp/domain/types.d.ts +9 -3
  23. package/build/types/revamp/flow/executeRefresh.d.ts +2 -2
  24. package/build/types/revamp/flow/executeSubmission.d.ts +5 -2
  25. package/build/types/revamp/flow/response-utils.d.ts +1 -0
  26. package/build/types/revamp/renderers/mappers/persistAsyncComponentToProps.d.ts +3 -0
  27. package/build/types/revamp/utils/type-utils.d.ts +1 -2
  28. package/package.json +15 -15
  29. package/build/types/revamp/domain/features/persistAsync/getComponentPersistAsync.d.ts +0 -21
  30. package/build/types/revamp/domain/features/refresh/getPerformRefresh.d.ts +0 -12
  31. package/build/types/revamp/domain/mappers/schema/utils/getPersistAsyncInitialState.d.ts +0 -5
package/build/main.js CHANGED
@@ -1573,6 +1573,17 @@ var objectComponentToProps = (component, rendererMapperProps) => {
1573
1573
  // src/revamp/renderers/mappers/paragraphComponentToProps.ts
1574
1574
  var paragraphComponentToProps = (component, rendererMapperProps) => __spreadValues(__spreadValues({}, pick(component, "uid", "type", "align", "control", "margin", "text")), rendererMapperProps);
1575
1575
 
1576
+ // src/revamp/renderers/mappers/persistAsyncComponentToProps.ts
1577
+ var persistAsyncComponentToProps = (component, rendererMapperProps) => {
1578
+ const props = componentToRendererProps(component.component, rendererMapperProps);
1579
+ if ("validationState" in props && component.errors.length > 0) {
1580
+ return __spreadProps(__spreadValues({}, props), {
1581
+ validationState: { status: "invalid", message: component.errors[0] }
1582
+ });
1583
+ }
1584
+ return props;
1585
+ };
1586
+
1576
1587
  // src/revamp/renderers/mappers/repeatableComponentToProps.ts
1577
1588
  var repeatableComponentToProps = (component, rendererMapperProps) => {
1578
1589
  const {
@@ -1876,6 +1887,8 @@ var getComponentProps = (component, rendererMapperProps) => {
1876
1887
  return tupleComponentToProps(component, rendererMapperProps);
1877
1888
  case "upload":
1878
1889
  return uploadInputComponentToProps(component, rendererMapperProps);
1890
+ case "persist-async":
1891
+ return persistAsyncComponentToProps(component, rendererMapperProps);
1879
1892
  default:
1880
1893
  throw new Error("Unknown component type");
1881
1894
  }
@@ -3081,26 +3094,44 @@ var getStepRefreshAfter = ({ refreshAfter, onBehavior }) => {
3081
3094
  }
3082
3095
  const timeLeft = Math.max(targetTime - Date.now(), ONE_SECOND);
3083
3096
  const timeout = setTimeout(() => {
3084
- void onBehavior({ type: "refresh", schemaId: "refreshAfter" });
3097
+ void onBehavior({ type: "refresh", analytics: { schema: "refreshAfter" } });
3085
3098
  }, timeLeft);
3086
3099
  return {
3087
3100
  stop: () => clearTimeout(timeout)
3088
3101
  };
3089
3102
  };
3090
3103
 
3091
- // src/revamp/domain/components/utils/isExactLocalValueMatch.ts
3092
- var isExactLocalValueMatch = (valueA, valueB) => {
3093
- if (isArrayLocalValue(valueA) && isArrayLocalValue(valueB)) {
3094
- return valueA.length === valueB.length && valueA.every((value, index) => isExactLocalValueMatch(value, valueB[index]));
3095
- }
3096
- if (isObjectLocalValue(valueA) && isObjectLocalValue(valueB)) {
3097
- const keysA = Object.keys(valueA);
3098
- const keysB = Object.keys(valueB);
3099
- return keysA.length === keysB.length && keysA.every((key) => isExactLocalValueMatch(valueA[key], valueB[key]));
3104
+ // src/revamp/domain/components/utils/isOrWasValid.ts
3105
+ var isOrWasValid = (getErrors, previous, current) => {
3106
+ const wasValid = getErrors(previous).length === 0 && previous !== null;
3107
+ const isValid = getErrors(current).length === 0;
3108
+ return wasValid || isValid;
3109
+ };
3110
+
3111
+ // src/revamp/domain/features/schema-on-change/getDebouncedSchemaOnChange.ts
3112
+ var getDebouncedSchemaOnChange = (onChange, getValidationErrors) => {
3113
+ if (!onChange) {
3114
+ return void 0;
3100
3115
  }
3101
- return valueA === valueB;
3116
+ const debouncedOnChange = debounce(onChange, 1e3);
3117
+ return onChange.behaviorType === "refresh" ? getSelectiveDebouncedSchemaOnChange(debouncedOnChange, getValidationErrors) : debouncedOnChange;
3118
+ };
3119
+ var getSelectiveDebouncedSchemaOnChange = (debouncedOnChange, getValidationErrors) => {
3120
+ const debouncedFn = (prevValue, updatedValue) => {
3121
+ if (isOrWasValid(getValidationErrors, prevValue, updatedValue) || (debouncedOnChange == null ? void 0 : debouncedOnChange.isPending())) {
3122
+ debouncedOnChange == null ? void 0 : debouncedOnChange();
3123
+ }
3124
+ };
3125
+ debouncedFn.flush = () => debouncedOnChange.flush();
3126
+ debouncedFn.cancel = () => debouncedOnChange.cancel();
3127
+ debouncedFn.isPending = () => debouncedOnChange.isPending();
3128
+ return debouncedFn;
3102
3129
  };
3103
3130
 
3131
+ // src/revamp/domain/features/validation/validation-functions.ts
3132
+ var validateComponents = (components) => components.reduce((acc, component) => component.validate() && acc, true);
3133
+ var getLocalValueValidator = (checks) => (currentValue) => checks.map((check) => check(currentValue)).filter(isString);
3134
+
3104
3135
  // src/revamp/domain/features/utils/http-utils.ts
3105
3136
  function constructPayload({
3106
3137
  value,
@@ -3128,143 +3159,6 @@ var abortAndResetController = (abortController) => {
3128
3159
  return new AbortController();
3129
3160
  };
3130
3161
 
3131
- // src/revamp/domain/features/persistAsync/getComponentPersistAsync.ts
3132
- var getComponentPersistAsync = (update, performPersistAsync) => (
3133
- /**
3134
- * Will update the persistedState when a new request is made, and will update
3135
- * the value or set errors when the request completes.
3136
- */
3137
- async (component, currentValue) => {
3138
- const { abortController, lastSubmitted, submission } = component.persistedState;
3139
- if (isExactLocalValueMatch(lastSubmitted, currentValue)) {
3140
- return submission;
3141
- }
3142
- const newAbortController = abortAndResetController(abortController);
3143
- if (isNullish(currentValue) || currentValue === "") {
3144
- const resolvedNull = Promise.resolve(null);
3145
- update(component, (draft) => {
3146
- draft.persistedState.abortController = newAbortController;
3147
- draft.persistedState.lastResponse = null;
3148
- draft.persistedState.lastSubmitted = currentValue;
3149
- draft.persistedState.submission = resolvedNull;
3150
- });
3151
- return resolvedNull;
3152
- }
3153
- const { signal } = newAbortController;
3154
- const newSubmission = performPersistAsync({ value: currentValue, signal }).then((newValue) => {
3155
- update(component, (draft) => {
3156
- draft.persistedState.lastResponse = newValue;
3157
- });
3158
- return newValue;
3159
- }).catch((error) => {
3160
- if (error instanceof DOMException && error.name === "AbortError") {
3161
- return null;
3162
- }
3163
- update(component, (draft) => {
3164
- draft.errors = [error.message];
3165
- draft.persistedState.lastResponse = null;
3166
- draft.persistedState.lastSubmitted = null;
3167
- });
3168
- throw error;
3169
- });
3170
- update(component, (draft) => {
3171
- draft.persistedState = {
3172
- abortController: newAbortController,
3173
- lastResponse: null,
3174
- lastSubmitted: currentValue,
3175
- submission: newSubmission
3176
- };
3177
- });
3178
- return newSubmission;
3179
- }
3180
- );
3181
- var getComponentMultiPersistAsync = (update, performPersistAsync) => (
3182
- /**
3183
- * Will update the persistedState when a new request is made, and will update
3184
- * the value or set errors when the request completes.
3185
- */
3186
- async (component, index, value) => {
3187
- if (isNullish(value)) {
3188
- throw new Error("Value must be a file or base64 string.");
3189
- }
3190
- const newAbortController = new AbortController();
3191
- const { signal } = newAbortController;
3192
- const newSubmission = performPersistAsync({ value, signal }).then((newValue) => {
3193
- update(component, (draft) => {
3194
- draft.persistedState[index].lastResponse = newValue;
3195
- });
3196
- return newValue;
3197
- }).catch((error) => {
3198
- update(component, (draft) => {
3199
- draft.persistedState = [
3200
- ...draft.persistedState.slice(0, index),
3201
- ...draft.persistedState.slice(index + 1)
3202
- ];
3203
- draft.value.splice(index, 1);
3204
- draft.files.splice(index, 1);
3205
- });
3206
- throw error;
3207
- });
3208
- update(component, (draft) => {
3209
- draft.persistedState = [
3210
- ...draft.persistedState.slice(0, index),
3211
- {
3212
- id: getRandomId(),
3213
- abortController: newAbortController,
3214
- lastResponse: null,
3215
- lastSubmitted: null,
3216
- submission: newSubmission
3217
- },
3218
- ...draft.persistedState.slice(index)
3219
- ];
3220
- });
3221
- return newSubmission;
3222
- }
3223
- );
3224
-
3225
- // src/revamp/domain/components/utils/isOrWasValid.ts
3226
- var isOrWasValid = (getErrors, previous, current) => {
3227
- const wasValid = getErrors(previous).length === 0 && previous !== null;
3228
- const isValid = getErrors(current).length === 0;
3229
- return wasValid || isValid;
3230
- };
3231
-
3232
- // src/revamp/domain/features/refresh/getPerformRefresh.ts
3233
- var getPerformRefresh = (schema, onBehavior) => {
3234
- var _a, _b;
3235
- if ("refreshStepOnChange" in schema && ((_a = schema.refreshStepOnChange) != null ? _a : false) || "refreshFormOnChange" in schema && ((_b = schema.refreshFormOnChange) != null ? _b : false)) {
3236
- const { $id, analyticsId, refreshUrl, refreshFormUrl } = schema;
3237
- const schemaId = analyticsId != null ? analyticsId : $id;
3238
- return () => {
3239
- void onBehavior({
3240
- type: "refresh",
3241
- schemaId,
3242
- url: refreshUrl != null ? refreshUrl : refreshFormUrl
3243
- });
3244
- };
3245
- }
3246
- return void 0;
3247
- };
3248
- var getDebouncedPerformRefresh = (performRefresh, getValidationErrors) => {
3249
- if (!performRefresh) {
3250
- return void 0;
3251
- }
3252
- const performDebouncedRefresh = debounce(performRefresh, 1e3);
3253
- const debouncedFn = (prevValue, updatedValue) => {
3254
- if (isOrWasValid(getValidationErrors, prevValue, updatedValue) || (performDebouncedRefresh == null ? void 0 : performDebouncedRefresh.isPending())) {
3255
- performDebouncedRefresh == null ? void 0 : performDebouncedRefresh();
3256
- }
3257
- };
3258
- debouncedFn.flush = () => performDebouncedRefresh.flush();
3259
- debouncedFn.cancel = () => performDebouncedRefresh.cancel();
3260
- debouncedFn.isPending = () => performDebouncedRefresh.isPending();
3261
- return debouncedFn;
3262
- };
3263
-
3264
- // src/revamp/domain/features/validation/validation-functions.ts
3265
- var validateComponents = (components) => components.reduce((acc, component) => component.validate() && acc, true);
3266
- var getLocalValueValidator = (checks) => (currentValue) => checks.map((check) => check(currentValue)).filter(isString);
3267
-
3268
3162
  // src/revamp/domain/features/validationAsync/getComponentValidationAsync.ts
3269
3163
  var getComponentValidationAsync = (update, performValidationAsync) => (
3270
3164
  /**
@@ -3318,24 +3212,25 @@ var createNumberInputComponent = (numberInputProps, updateComponent) => {
3318
3212
  uid,
3319
3213
  id,
3320
3214
  checks,
3321
- performPersistAsync,
3322
- performRefresh,
3215
+ schemaOnChange,
3323
3216
  performValidationAsync,
3324
3217
  onValueChange,
3218
+ onPersistAsync,
3325
3219
  summariser
3326
3220
  } = _a, rest = __objRest(_a, [
3327
3221
  "uid",
3328
3222
  "id",
3329
3223
  "checks",
3330
- "performPersistAsync",
3331
- "performRefresh",
3224
+ "schemaOnChange",
3332
3225
  "performValidationAsync",
3333
3226
  "onValueChange",
3227
+ "onPersistAsync",
3334
3228
  "summariser"
3335
3229
  ]);
3336
3230
  const update = getInputUpdateFunction(updateComponent);
3337
3231
  const getValidationErrors = getLocalValueValidator(checks);
3338
- const performDebouncedRefresh = getDebouncedPerformRefresh(performRefresh, getValidationErrors);
3232
+ const performOnChange = getDebouncedSchemaOnChange(schemaOnChange, getValidationErrors);
3233
+ const validateAsync = performValidationAsync ? getDebouncedComponentValidationAsync(update, performValidationAsync) : void 0;
3339
3234
  const numberComponent = __spreadValues({
3340
3235
  type: "number",
3341
3236
  uid,
@@ -3344,8 +3239,12 @@ var createNumberInputComponent = (numberInputProps, updateComponent) => {
3344
3239
  update(this, updateFn);
3345
3240
  },
3346
3241
  onBlur() {
3347
- this.validate();
3348
- performDebouncedRefresh == null ? void 0 : performDebouncedRefresh.flush();
3242
+ const isValid = this.validate();
3243
+ performOnChange == null ? void 0 : performOnChange.flush();
3244
+ if (isValid) {
3245
+ onPersistAsync == null ? void 0 : onPersistAsync();
3246
+ validateAsync == null ? void 0 : validateAsync.flush();
3247
+ }
3349
3248
  },
3350
3249
  onFocus() {
3351
3250
  },
@@ -3357,7 +3256,11 @@ var createNumberInputComponent = (numberInputProps, updateComponent) => {
3357
3256
  draft.validationAsyncState.messages = {};
3358
3257
  draft.value = updatedValue;
3359
3258
  });
3360
- performDebouncedRefresh == null ? void 0 : performDebouncedRefresh(prevValue, updatedValue);
3259
+ performOnChange == null ? void 0 : performOnChange(prevValue, updatedValue);
3260
+ const isValid = getValidationErrors(updatedValue).length === 0;
3261
+ if (isValid) {
3262
+ validateAsync == null ? void 0 : validateAsync(this, updatedValue);
3263
+ }
3361
3264
  onValueChange();
3362
3265
  },
3363
3266
  async getSubmittableValue() {
@@ -3381,43 +3284,44 @@ var createNumberInputComponent = (numberInputProps, updateComponent) => {
3381
3284
  return errors.length === 0;
3382
3285
  }
3383
3286
  }, rest);
3384
- if (performRefresh) {
3385
- return numberComponent;
3386
- }
3387
- if (performPersistAsync) {
3388
- const persist = getComponentPersistAsync(update, performPersistAsync);
3389
- return __spreadProps(__spreadValues({}, numberComponent), {
3390
- onBlur() {
3391
- if (this.validate()) {
3392
- persist(this, this.getLocalValue()).catch(() => {
3393
- });
3394
- }
3395
- },
3396
- async getSubmittableValue() {
3397
- return persist(this, this.getLocalValue());
3398
- },
3399
- getSubmittableValueSync() {
3400
- return this.persistedState.lastResponse;
3401
- }
3402
- });
3287
+ return numberComponent;
3288
+ };
3289
+
3290
+ // src/revamp/domain/features/schema-on-change/getSchemaOnChange.ts
3291
+ var getSchemaOnChange = (schema, onBehavior) => {
3292
+ var _a, _b;
3293
+ const behavior = (_b = (_a = getBehaviorFromSchemaOnChange(schema)) != null ? _a : getBehaviorFromSchemaRefreshStepOnChange(schema)) != null ? _b : void 0;
3294
+ if (behavior) {
3295
+ const onChange = () => {
3296
+ void onBehavior(behavior);
3297
+ };
3298
+ onChange.behaviorType = behavior.type;
3299
+ return onChange;
3403
3300
  }
3404
- if (performValidationAsync) {
3405
- const validateAsync = getDebouncedComponentValidationAsync(update, performValidationAsync);
3406
- return __spreadProps(__spreadValues({}, numberComponent), {
3407
- onBlur() {
3408
- if (this.validate()) {
3409
- validateAsync.flush();
3410
- }
3411
- },
3412
- onChange(updatedValue) {
3413
- numberComponent.onChange.call(this, updatedValue);
3414
- if (getValidationErrors(updatedValue).length === 0) {
3415
- validateAsync(this, updatedValue);
3416
- }
3417
- }
3301
+ return void 0;
3302
+ };
3303
+ var getBehaviorFromSchemaOnChange = (schema) => {
3304
+ if ("onChange" in schema && schema.onChange) {
3305
+ const { $id, analyticsId, onChange } = schema;
3306
+ const behavior = __spreadProps(__spreadValues({}, normaliseBehavior(onChange, [])), {
3307
+ analytics: { schema: analyticsId != null ? analyticsId : $id }
3418
3308
  });
3309
+ return behavior;
3419
3310
  }
3420
- return numberComponent;
3311
+ return void 0;
3312
+ };
3313
+ var getBehaviorFromSchemaRefreshStepOnChange = (schema) => {
3314
+ var _a, _b;
3315
+ if ("refreshStepOnChange" in schema && ((_a = schema.refreshStepOnChange) != null ? _a : false) || "refreshFormOnChange" in schema && ((_b = schema.refreshFormOnChange) != null ? _b : false)) {
3316
+ const { $id, analyticsId, refreshUrl, refreshFormUrl } = schema;
3317
+ const behavior = {
3318
+ type: "refresh",
3319
+ analytics: { schema: analyticsId != null ? analyticsId : $id },
3320
+ url: refreshUrl != null ? refreshUrl : refreshFormUrl
3321
+ };
3322
+ return behavior;
3323
+ }
3324
+ return void 0;
3421
3325
  };
3422
3326
 
3423
3327
  // src/revamp/domain/features/validation/validateStringPattern.ts
@@ -3638,6 +3542,13 @@ var parseResponseBodyAsJsonElement = async (response) => {
3638
3542
  return null;
3639
3543
  }
3640
3544
  };
3545
+ var parseResponseBodyAsText = async (response) => {
3546
+ try {
3547
+ return await response.text();
3548
+ } catch (e) {
3549
+ return null;
3550
+ }
3551
+ };
3641
3552
  function isActionResponseBody(body) {
3642
3553
  return (0, import_dynamic_flow_types.validateActionResponse)(body).valid;
3643
3554
  }
@@ -3678,93 +3589,6 @@ var getAnalyticsFromErrorResponse = (json) => {
3678
3589
  return isObject(analytics) ? analytics : void 0;
3679
3590
  };
3680
3591
 
3681
- // src/revamp/domain/features/persistAsync/getPerformPersistAsync.ts
3682
- var getPerformPersistAsync = ({
3683
- genericErrorMessage,
3684
- httpClient,
3685
- persistAsyncConfig,
3686
- schemaId,
3687
- logEvent,
3688
- trackEvent
3689
- }) => {
3690
- const { idProperty, param, method, url } = persistAsyncConfig;
3691
- const trackFailure = (json) => {
3692
- const analytics = getAnalyticsFromErrorResponse(json);
3693
- trackEvent("PersistAsync Failed", __spreadValues({ schema: schemaId }, analytics));
3694
- };
3695
- return async function performPersistAsync({ value, signal }) {
3696
- let response;
3697
- let json;
3698
- try {
3699
- trackEvent("PersistAsync Triggered", { schema: schemaId });
3700
- response = await httpClient(
3701
- url,
3702
- constructPayload({ value, signal, requestConfig: { method, param } })
3703
- );
3704
- json = await response.json();
3705
- if (response.ok && isObject(json)) {
3706
- trackEvent("PersistAsync Succeeded", { schema: schemaId });
3707
- if (json[idProperty] === void 0) {
3708
- logEvent(
3709
- "error",
3710
- `Response from persist async did not contain expected property ${idProperty}.`
3711
- );
3712
- throw new Error(genericErrorMessage);
3713
- }
3714
- return json[idProperty];
3715
- }
3716
- } catch (e) {
3717
- trackFailure();
3718
- throw new Error(genericErrorMessage);
3719
- }
3720
- const validationError = !response.ok && isObject(json) ? getValidationError(param, json) : null;
3721
- trackFailure(json);
3722
- throw new Error(validationError != null ? validationError : genericErrorMessage);
3723
- };
3724
- };
3725
- var getValidationError = (param, response) => {
3726
- var _a;
3727
- const message = (_a = response.validation) == null ? void 0 : _a[param];
3728
- return isString(message) ? message : null;
3729
- };
3730
-
3731
- // src/revamp/domain/features/persistAsync/getInitialPersistedState.ts
3732
- var getInitialPersistedState = (lastSubmitted, model) => ({
3733
- abortController: new AbortController(),
3734
- lastSubmitted: !isNullish(model) ? lastSubmitted != null ? lastSubmitted : null : null,
3735
- lastResponse: model != null ? model : null,
3736
- submission: Promise.resolve(model != null ? model : null)
3737
- });
3738
-
3739
- // src/revamp/domain/mappers/schema/utils/getPersistAsyncInitialState.ts
3740
- var getPersistAsyncInitialState = (schemaMapperProps, mapperProps) => {
3741
- const { localValue, model } = schemaMapperProps;
3742
- const performPersistAsync = getPerformPersisAsyncFn(schemaMapperProps, mapperProps);
3743
- const persistedState = performPersistAsync ? getInitialPersistedState(localValue, model) : getInitialPersistedState();
3744
- return { performPersistAsync, persistedState };
3745
- };
3746
- var getPerformPersisAsyncFn = (schemaMapperProps, mapperProps) => {
3747
- const { schema, persistAsyncConfig } = schemaMapperProps;
3748
- const { trackEvent, logEvent } = mapperProps;
3749
- if (!persistAsyncConfig) {
3750
- return void 0;
3751
- }
3752
- const { $id, analyticsId } = schema;
3753
- const { getErrorMessageFunctions, httpClient } = mapperProps;
3754
- const validationMessages = schemaHasValidationMessages(schema) ? schema.validationMessages : void 0;
3755
- const errorMessageFunctions = getErrorMessageFunctions(validationMessages);
3756
- const persistAsyncError = errorMessageFunctions.genericError();
3757
- return getPerformPersistAsync({
3758
- genericErrorMessage: persistAsyncError,
3759
- httpClient,
3760
- logEvent,
3761
- persistAsyncConfig,
3762
- schemaId: analyticsId != null ? analyticsId : $id,
3763
- trackEvent
3764
- });
3765
- };
3766
- var schemaHasValidationMessages = (schema) => Boolean("validationMessages" in schema && schema.validationMessages);
3767
-
3768
3592
  // src/revamp/domain/features/validationAsync/getPerformValidationAsync.ts
3769
3593
  var getPerformValidationAsync = ({
3770
3594
  httpClient,
@@ -3881,7 +3705,7 @@ var summaryIfProvides = (summary, { value, icon, image }) => {
3881
3705
  // src/revamp/domain/mappers/schema/utils/mapCommonSchemaProps.ts
3882
3706
  var mapCommonSchemaProps = (schemaMapperProps) => {
3883
3707
  var _a;
3884
- const { uid, schemaId, schema, required, validationErrors } = schemaMapperProps;
3708
+ const { uid, schemaId, schema, required, validationErrors, onPersistAsync } = schemaMapperProps;
3885
3709
  const { $id, analyticsId, control, description, icon, image, keywords, title, hidden } = schema;
3886
3710
  return __spreadValues(__spreadValues(__spreadValues({
3887
3711
  uid,
@@ -3898,6 +3722,7 @@ var mapCommonSchemaProps = (schemaMapperProps) => {
3898
3722
  keywords,
3899
3723
  required: Boolean(required),
3900
3724
  title,
3725
+ onPersistAsync,
3901
3726
  summariser: getSummariser(schema)
3902
3727
  }, schemaHasHelp(schema) ? { help: schema.help.markdown } : {}), schemaHasPlaceholder(schema) ? { placeholder: schema.placeholder } : {}), schema.alert ? { alert: mapSchemaAlert(schema.alert) } : {});
3903
3728
  };
@@ -3907,21 +3732,17 @@ var schemaHasPlaceholder = (schema) => Boolean("placeholder" in schema && schema
3907
3732
 
3908
3733
  // src/revamp/domain/mappers/schema/numberSchemaToComponent.ts
3909
3734
  var numberSchemaToComponent = (schemaMapperProps, mapperProps) => {
3910
- const { schema, model, localValue, required = false } = schemaMapperProps;
3735
+ const { schema, model, localValue, required = false, onPersistAsync } = schemaMapperProps;
3911
3736
  const { autocompleteHint, validationMessages, default: defaultValue, maximum, minimum } = schema;
3912
3737
  const { getErrorMessageFunctions, updateComponent, onBehavior, onValueChange } = mapperProps;
3913
3738
  const errorMessageFunctions = getErrorMessageFunctions(validationMessages);
3914
- const { performPersistAsync, persistedState } = getPersistAsyncInitialState(
3915
- schemaMapperProps,
3916
- mapperProps
3917
- );
3918
3739
  const { performValidationAsync, validationAsyncState } = getValidationAsyncInitialState(
3919
3740
  schemaMapperProps,
3920
3741
  mapperProps
3921
3742
  );
3922
3743
  const validLocalValue = isNumber(localValue) ? localValue : null;
3923
3744
  const validModel = isNumber(model) ? model : defaultValue != null ? defaultValue : null;
3924
- const value = performPersistAsync ? validLocalValue : validModel;
3745
+ const value = onPersistAsync ? validLocalValue : validModel;
3925
3746
  return createNumberInputComponent(
3926
3747
  __spreadProps(__spreadValues({}, mapCommonSchemaProps(schemaMapperProps)), {
3927
3748
  autoComplete: getAutocompleteString(autocompleteHint),
@@ -3933,10 +3754,8 @@ var numberSchemaToComponent = (schemaMapperProps, mapperProps) => {
3933
3754
  value,
3934
3755
  maximum,
3935
3756
  minimum,
3936
- persistedState,
3937
3757
  validationAsyncState,
3938
- performPersistAsync,
3939
- performRefresh: getPerformRefresh(schema, onBehavior),
3758
+ schemaOnChange: getSchemaOnChange(schema, onBehavior),
3940
3759
  performValidationAsync,
3941
3760
  onValueChange
3942
3761
  }),
@@ -4213,8 +4032,53 @@ var localValueToJsonElement = (localValue) => {
4213
4032
  };
4214
4033
  var getRandomInt = () => Math.floor(Math.random() * 1e8);
4215
4034
 
4216
- // src/revamp/domain/components/utils/file-utils.ts
4217
- var toBase64 = async (file) => new Promise((resolve, reject) => {
4035
+ // src/revamp/domain/features/persistAsync/getComponentMultiPersistAsync.ts
4036
+ var getComponentMultiPersistAsync = (update, performPersistAsync) => (
4037
+ /**
4038
+ * Will update the persistedState when a new request is made, and will update
4039
+ * the value or set errors when the request completes.
4040
+ */
4041
+ async (component, index, value) => {
4042
+ if (isNullish(value)) {
4043
+ throw new Error("Value must be a file or base64 string.");
4044
+ }
4045
+ const newAbortController = new AbortController();
4046
+ const { signal } = newAbortController;
4047
+ const newSubmission = performPersistAsync({ value, signal }).then((newValue) => {
4048
+ update(component, (draft) => {
4049
+ draft.persistedState[index].lastResponse = newValue;
4050
+ });
4051
+ return newValue;
4052
+ }).catch((error) => {
4053
+ update(component, (draft) => {
4054
+ draft.persistedState = [
4055
+ ...draft.persistedState.slice(0, index),
4056
+ ...draft.persistedState.slice(index + 1)
4057
+ ];
4058
+ draft.value.splice(index, 1);
4059
+ draft.files.splice(index, 1);
4060
+ });
4061
+ throw error;
4062
+ });
4063
+ update(component, (draft) => {
4064
+ draft.persistedState = [
4065
+ ...draft.persistedState.slice(0, index),
4066
+ {
4067
+ id: getRandomId(),
4068
+ abortController: newAbortController,
4069
+ lastResponse: null,
4070
+ lastSubmitted: null,
4071
+ submission: newSubmission
4072
+ },
4073
+ ...draft.persistedState.slice(index)
4074
+ ];
4075
+ });
4076
+ return newSubmission;
4077
+ }
4078
+ );
4079
+
4080
+ // src/revamp/domain/components/utils/file-utils.ts
4081
+ var toBase64 = async (file) => new Promise((resolve, reject) => {
4218
4082
  const reader = new FileReader();
4219
4083
  reader.addEventListener("load", () => resolve(reader.result));
4220
4084
  reader.addEventListener("error", reject);
@@ -4341,6 +4205,82 @@ var createMultiUploadInputComponent = (uploadInputProps, updateComponent) => {
4341
4205
  });
4342
4206
  };
4343
4207
 
4208
+ // src/revamp/domain/features/persistAsync/getInitialPersistedState.ts
4209
+ var getInitialPersistedState = (lastSubmitted, model) => ({
4210
+ abortController: new AbortController(),
4211
+ lastSubmitted: !isNullish(model) ? lastSubmitted != null ? lastSubmitted : null : null,
4212
+ lastResponse: model != null ? model : null,
4213
+ submission: Promise.resolve(model != null ? model : null)
4214
+ });
4215
+
4216
+ // src/revamp/domain/features/persistAsync/getPerformPersistAsync.ts
4217
+ var getPerformPersistAsync = ({
4218
+ genericErrorMessage,
4219
+ httpClient,
4220
+ persistAsyncConfig,
4221
+ schemaId,
4222
+ logEvent,
4223
+ trackEvent
4224
+ }) => {
4225
+ const { idProperty, param, method, url } = persistAsyncConfig;
4226
+ const trackFailure = (json) => {
4227
+ const analytics = getAnalyticsFromErrorResponse(json);
4228
+ trackEvent("PersistAsync Failed", __spreadValues({ schema: schemaId }, analytics));
4229
+ };
4230
+ return async function performPersistAsync({ value, signal }) {
4231
+ let response;
4232
+ let json;
4233
+ try {
4234
+ trackEvent("PersistAsync Triggered", { schema: schemaId });
4235
+ response = await httpClient(
4236
+ url,
4237
+ constructPayload({ value, signal, requestConfig: { method, param } })
4238
+ );
4239
+ json = await response.json();
4240
+ if (response.ok && isObject(json)) {
4241
+ trackEvent("PersistAsync Succeeded", { schema: schemaId });
4242
+ if (json[idProperty] === void 0) {
4243
+ logEvent(
4244
+ "error",
4245
+ `Response from persist async did not contain expected property ${idProperty}.`
4246
+ );
4247
+ throw new Error(genericErrorMessage);
4248
+ }
4249
+ return json[idProperty];
4250
+ }
4251
+ } catch (e) {
4252
+ trackFailure();
4253
+ throw new Error(genericErrorMessage);
4254
+ }
4255
+ const validationError = !response.ok && isObject(json) ? getValidationError(param, json) : null;
4256
+ trackFailure(json);
4257
+ throw new Error(validationError != null ? validationError : genericErrorMessage);
4258
+ };
4259
+ };
4260
+ var getValidationError = (param, response) => {
4261
+ var _a;
4262
+ const message = (_a = response.validation) == null ? void 0 : _a[param];
4263
+ return isString(message) ? message : null;
4264
+ };
4265
+
4266
+ // src/revamp/domain/mappers/schema/utils/getPerformPersistAsyncFn.ts
4267
+ var getPerformPersistAsyncFn = (schema, persistAsyncConfig, mapperProps) => {
4268
+ const { getErrorMessageFunctions, httpClient, trackEvent, logEvent } = mapperProps;
4269
+ const { $id, analyticsId } = schema;
4270
+ const validationMessages = schemaHasValidationMessages(schema) ? schema.validationMessages : void 0;
4271
+ const errorMessageFunctions = getErrorMessageFunctions(validationMessages);
4272
+ const persistAsyncError = errorMessageFunctions.genericError();
4273
+ return getPerformPersistAsync({
4274
+ genericErrorMessage: persistAsyncError,
4275
+ httpClient,
4276
+ logEvent,
4277
+ persistAsyncConfig,
4278
+ schemaId: analyticsId != null ? analyticsId : $id,
4279
+ trackEvent
4280
+ });
4281
+ };
4282
+ var schemaHasValidationMessages = (schema) => Boolean("validationMessages" in schema && schema.validationMessages);
4283
+
4344
4284
  // src/revamp/domain/mappers/schema/arraySchemaToComponent/arraySchemaToMultiUploadComponent.ts
4345
4285
  var arraySchemaToMultiUploadComponent = (schemaMapperProps, mapperProps) => {
4346
4286
  var _a;
@@ -4367,7 +4307,7 @@ var arraySchemaToMultiUploadComponent = (schemaMapperProps, mapperProps) => {
4367
4307
  schema: __spreadProps(__spreadValues({}, uploadSchema), { hidden: (_a = schema.hidden) != null ? _a : uploadSchema.hidden, alert: schema.alert })
4368
4308
  });
4369
4309
  const { onValueChange } = mapperProps;
4370
- const { performPersistAsync } = getPersistAsyncInitialState(combinedSchemaProps, mapperProps);
4310
+ const performPersistAsync = persistAsyncConfig ? getPerformPersistAsyncFn(combinedSchemaProps.schema, persistAsyncConfig, mapperProps) : void 0;
4371
4311
  const value = performPersistAsync ? getValueForPersistAsync(localValue) : [];
4372
4312
  const persistedState = performPersistAsync && isArray(model) ? model.map((itemModel) => getInitialPersistedState(null, itemModel)) : [];
4373
4313
  return createMultiUploadInputComponent(
@@ -4423,7 +4363,7 @@ var createMultiSelectComponent = (multiSelectProps, updateComponent) => {
4423
4363
  options,
4424
4364
  initialValue,
4425
4365
  performValidationAsync,
4426
- performRefresh,
4366
+ schemaOnChange,
4427
4367
  onValueChange
4428
4368
  } = _a, rest = __objRest(_a, [
4429
4369
  "uid",
@@ -4431,13 +4371,14 @@ var createMultiSelectComponent = (multiSelectProps, updateComponent) => {
4431
4371
  "options",
4432
4372
  "initialValue",
4433
4373
  "performValidationAsync",
4434
- "performRefresh",
4374
+ "schemaOnChange",
4435
4375
  "onValueChange"
4436
4376
  ]);
4437
4377
  const update = getInputUpdateFunction(updateComponent);
4438
4378
  const children = options.map((option) => option.component);
4439
4379
  const selectedIndices = getInitialModelIndices(initialValue, children);
4440
4380
  const getValidationErrors = getLocalValueValidator(checks);
4381
+ const validateAsync = performValidationAsync ? getComponentValidationAsync(update, performValidationAsync) : void 0;
4441
4382
  const component = __spreadProps(__spreadValues({
4442
4383
  uid,
4443
4384
  type: "multi-select",
@@ -4454,12 +4395,16 @@ var createMultiSelectComponent = (multiSelectProps, updateComponent) => {
4454
4395
  draft.selectedIndices = indices;
4455
4396
  draft.errors = [];
4456
4397
  });
4457
- performRefresh == null ? void 0 : performRefresh();
4458
- onValueChange();
4398
+ schemaOnChange == null ? void 0 : schemaOnChange();
4459
4399
  const errors = getValidationErrors(this.getLocalValue());
4460
4400
  this._update((draft) => {
4461
4401
  draft.errors = errors;
4462
4402
  });
4403
+ if (this.validate()) {
4404
+ validateAsync == null ? void 0 : validateAsync(this, this.getLocalValue()).catch(() => {
4405
+ });
4406
+ }
4407
+ onValueChange();
4463
4408
  },
4464
4409
  onBlur() {
4465
4410
  },
@@ -4497,21 +4442,6 @@ var createMultiSelectComponent = (multiSelectProps, updateComponent) => {
4497
4442
  return this.selectedIndices.map((i) => this.children[i]);
4498
4443
  }
4499
4444
  });
4500
- if (performRefresh) {
4501
- return component;
4502
- }
4503
- if (performValidationAsync) {
4504
- const validateAsync = getComponentValidationAsync(update, performValidationAsync);
4505
- return __spreadProps(__spreadValues({}, component), {
4506
- onSelect(indices) {
4507
- component.onSelect.call(this, indices);
4508
- if (this.validate()) {
4509
- validateAsync(this, this.getLocalValue()).catch(() => {
4510
- });
4511
- }
4512
- }
4513
- });
4514
- }
4515
4445
  return component;
4516
4446
  };
4517
4447
  var getInitialModelIndices = (model, options) => {
@@ -4578,7 +4508,7 @@ var arraySchemaToMultiSelectComponent = (schemaMapperProps, mapperProps) => {
4578
4508
  title,
4579
4509
  validationAsyncState,
4580
4510
  performValidationAsync,
4581
- performRefresh: getPerformRefresh(schema, onBehavior),
4511
+ schemaOnChange: getSchemaOnChange(schema, onBehavior),
4582
4512
  onValueChange
4583
4513
  }),
4584
4514
  updateComponent
@@ -4698,9 +4628,9 @@ var createUploadInputComponent = (uploadInputProps, updateComponent) => {
4698
4628
  checks,
4699
4629
  format,
4700
4630
  value,
4701
- performPersistAsync,
4702
- performRefresh,
4631
+ schemaOnChange,
4703
4632
  onValueChange,
4633
+ onPersistAsync,
4704
4634
  summariser
4705
4635
  } = _a, rest = __objRest(_a, [
4706
4636
  "uid",
@@ -4708,9 +4638,9 @@ var createUploadInputComponent = (uploadInputProps, updateComponent) => {
4708
4638
  "checks",
4709
4639
  "format",
4710
4640
  "value",
4711
- "performPersistAsync",
4712
- "performRefresh",
4641
+ "schemaOnChange",
4713
4642
  "onValueChange",
4643
+ "onPersistAsync",
4714
4644
  "summariser"
4715
4645
  ]);
4716
4646
  const update = getInputUpdateFunction(updateComponent);
@@ -4719,7 +4649,7 @@ var createUploadInputComponent = (uploadInputProps, updateComponent) => {
4719
4649
  type: "upload",
4720
4650
  uid,
4721
4651
  id,
4722
- format: "base64",
4652
+ format,
4723
4653
  value,
4724
4654
  _update(updateFn) {
4725
4655
  update(this, updateFn);
@@ -4735,12 +4665,16 @@ var createUploadInputComponent = (uploadInputProps, updateComponent) => {
4735
4665
  draft.errors = [];
4736
4666
  draft.value = updatedValue;
4737
4667
  });
4738
- performRefresh == null ? void 0 : performRefresh();
4668
+ schemaOnChange == null ? void 0 : schemaOnChange();
4739
4669
  onValueChange();
4670
+ onPersistAsync == null ? void 0 : onPersistAsync();
4740
4671
  },
4741
4672
  async getSubmittableValue() {
4742
4673
  const file = this.getLocalValue();
4743
- return file ? toBase64(file) : null;
4674
+ if (this.format === "base64" && file) {
4675
+ return toBase64(file);
4676
+ }
4677
+ return null;
4744
4678
  },
4745
4679
  getSubmittableValueSync() {
4746
4680
  return null;
@@ -4760,50 +4694,17 @@ var createUploadInputComponent = (uploadInputProps, updateComponent) => {
4760
4694
  return errors.length === 0;
4761
4695
  }
4762
4696
  }, rest);
4763
- if (!performPersistAsync) {
4764
- return uploadComponent;
4765
- }
4766
- const persist = getComponentPersistAsync(update, performPersistAsync);
4767
- return __spreadProps(__spreadValues({}, uploadComponent), {
4768
- format,
4769
- async onUpload(file) {
4770
- this._update((draft) => {
4771
- draft.errors = [];
4772
- draft.value = file;
4773
- });
4774
- onValueChange();
4775
- const submission = format === "base64" && file ? await toBase64(file) : file;
4776
- await persist(this, submission).catch((error) => {
4777
- this._update((draft) => {
4778
- draft.persistedState.lastResponse = null;
4779
- draft.persistedState.lastSubmitted = null;
4780
- draft.persistedState.submission = Promise.resolve(null);
4781
- draft.errors = [];
4782
- draft.value = null;
4783
- });
4784
- throw error;
4785
- });
4786
- onValueChange();
4787
- },
4788
- async getSubmittableValue() {
4789
- return this.persistedState.submission;
4790
- },
4791
- getSubmittableValueSync() {
4792
- return this.persistedState.lastResponse;
4793
- }
4794
- });
4697
+ return uploadComponent;
4795
4698
  };
4796
4699
 
4797
4700
  // src/revamp/domain/mappers/schema/blobSchemaToComponent.ts
4798
4701
  var blobSchemaToComponent = (schemaMapperProps, mapperProps) => {
4799
- const { schema, localValue, model, required = false } = schemaMapperProps;
4702
+ const { schema, localValue, required = false, onPersistAsync } = schemaMapperProps;
4800
4703
  const { accepts, cameraConfig, maxSize, source, validationMessages } = schema;
4801
4704
  const { getErrorMessageFunctions, updateComponent, onValueChange } = mapperProps;
4802
4705
  const errorMessageFunctions = getErrorMessageFunctions(validationMessages);
4803
- const { performPersistAsync } = getPersistAsyncInitialState(schemaMapperProps, mapperProps);
4804
- const persistedState = performPersistAsync ? getInitialPersistedState(null, model) : getInitialPersistedState();
4805
4706
  const validLocalValue = isFile(localValue) ? localValue : null;
4806
- const value = performPersistAsync ? validLocalValue : null;
4707
+ const value = onPersistAsync ? validLocalValue : null;
4807
4708
  return createUploadInputComponent(
4808
4709
  __spreadProps(__spreadValues({}, mapCommonSchemaProps(schemaMapperProps)), {
4809
4710
  accepts,
@@ -4813,9 +4714,8 @@ var blobSchemaToComponent = (schemaMapperProps, mapperProps) => {
4813
4714
  maxSize,
4814
4715
  source,
4815
4716
  value,
4816
- persistedState,
4817
- performPersistAsync,
4818
4717
  checks: schema.hidden ? [] : [getRequiredCheck(required, errorMessageFunctions)],
4718
+ schemaOnChange: void 0,
4819
4719
  onValueChange
4820
4720
  }),
4821
4721
  updateComponent
@@ -4828,22 +4728,23 @@ var createBooleanInputComponent = (booleanInputProps, updateComponent) => {
4828
4728
  uid,
4829
4729
  id,
4830
4730
  value,
4831
- performPersistAsync,
4832
- performRefresh,
4731
+ schemaOnChange,
4833
4732
  performValidationAsync,
4834
4733
  onValueChange,
4734
+ onPersistAsync,
4835
4735
  summariser
4836
4736
  } = _a, rest = __objRest(_a, [
4837
4737
  "uid",
4838
4738
  "id",
4839
4739
  "value",
4840
- "performPersistAsync",
4841
- "performRefresh",
4740
+ "schemaOnChange",
4842
4741
  "performValidationAsync",
4843
4742
  "onValueChange",
4743
+ "onPersistAsync",
4844
4744
  "summariser"
4845
4745
  ]);
4846
4746
  const update = getInputUpdateFunction(updateComponent);
4747
+ const validateAsync = performValidationAsync ? getComponentValidationAsync(update, performValidationAsync) : void 0;
4847
4748
  const booleanComponent = __spreadValues({
4848
4749
  type: "boolean",
4849
4750
  uid,
@@ -4864,7 +4765,10 @@ var createBooleanInputComponent = (booleanInputProps, updateComponent) => {
4864
4765
  draft.errors = [];
4865
4766
  draft.value = updatedValue;
4866
4767
  });
4867
- performRefresh == null ? void 0 : performRefresh();
4768
+ schemaOnChange == null ? void 0 : schemaOnChange();
4769
+ onPersistAsync == null ? void 0 : onPersistAsync();
4770
+ validateAsync == null ? void 0 : validateAsync(this, this.getLocalValue()).catch(() => {
4771
+ });
4868
4772
  onValueChange();
4869
4773
  },
4870
4774
  async getSubmittableValue() {
@@ -4881,62 +4785,27 @@ var createBooleanInputComponent = (booleanInputProps, updateComponent) => {
4881
4785
  },
4882
4786
  validate: () => true
4883
4787
  }, rest);
4884
- if (performRefresh) {
4885
- return booleanComponent;
4886
- }
4887
- if (performPersistAsync) {
4888
- const persist = getComponentPersistAsync(update, performPersistAsync);
4889
- return __spreadProps(__spreadValues({}, booleanComponent), {
4890
- onChange(updatedValue) {
4891
- booleanComponent.onChange.call(this, updatedValue);
4892
- persist(this, this.getLocalValue()).catch(() => {
4893
- });
4894
- },
4895
- async getSubmittableValue() {
4896
- return persist(this, this.getLocalValue());
4897
- },
4898
- getSubmittableValueSync() {
4899
- return this.persistedState.lastResponse;
4900
- }
4901
- });
4902
- }
4903
- if (performValidationAsync) {
4904
- const validateAsync = getComponentValidationAsync(update, performValidationAsync);
4905
- return __spreadProps(__spreadValues({}, booleanComponent), {
4906
- onChange(updatedValue) {
4907
- booleanComponent.onChange.call(this, updatedValue);
4908
- validateAsync(this, this.getLocalValue()).catch(() => {
4909
- });
4910
- }
4911
- });
4912
- }
4913
4788
  return booleanComponent;
4914
4789
  };
4915
4790
 
4916
4791
  // src/revamp/domain/mappers/schema/booleanSchemaToComponent.ts
4917
4792
  var booleanSchemaToComponent = (schemaMapperProps, mapperProps) => {
4918
- const { schema, localValue, model } = schemaMapperProps;
4793
+ const { schema, localValue, model, onPersistAsync } = schemaMapperProps;
4919
4794
  const { default: defaultValue } = schema;
4920
4795
  const { updateComponent, onBehavior, onValueChange } = mapperProps;
4921
- const performRefresh = getPerformRefresh(schema, onBehavior);
4922
- const { performPersistAsync, persistedState } = getPersistAsyncInitialState(
4923
- schemaMapperProps,
4924
- mapperProps
4925
- );
4796
+ const schemaOnChange = getSchemaOnChange(schema, onBehavior);
4926
4797
  const { performValidationAsync, validationAsyncState } = getValidationAsyncInitialState(
4927
4798
  schemaMapperProps,
4928
4799
  mapperProps
4929
4800
  );
4930
4801
  const validLocalValue = isBoolean(localValue) ? localValue : false;
4931
4802
  const validModel = getValidModel(model, defaultValue);
4932
- const value = performPersistAsync ? validLocalValue : validModel;
4803
+ const value = onPersistAsync ? validLocalValue : validModel;
4933
4804
  return createBooleanInputComponent(
4934
4805
  __spreadProps(__spreadValues({}, mapCommonSchemaProps(schemaMapperProps)), {
4935
4806
  value: value != null ? value : false,
4936
- persistedState,
4937
4807
  validationAsyncState,
4938
- performPersistAsync,
4939
- performRefresh,
4808
+ schemaOnChange,
4940
4809
  performValidationAsync,
4941
4810
  onValueChange
4942
4811
  }),
@@ -4992,25 +4861,26 @@ var createIntegerInputComponent = (integerInputProps, updateComponent) => {
4992
4861
  id,
4993
4862
  checks,
4994
4863
  value,
4995
- performPersistAsync,
4996
- performRefresh,
4864
+ schemaOnChange,
4997
4865
  performValidationAsync,
4998
4866
  onValueChange,
4867
+ onPersistAsync,
4999
4868
  summariser
5000
4869
  } = _a, rest = __objRest(_a, [
5001
4870
  "uid",
5002
4871
  "id",
5003
4872
  "checks",
5004
4873
  "value",
5005
- "performPersistAsync",
5006
- "performRefresh",
4874
+ "schemaOnChange",
5007
4875
  "performValidationAsync",
5008
4876
  "onValueChange",
4877
+ "onPersistAsync",
5009
4878
  "summariser"
5010
4879
  ]);
5011
4880
  const update = getInputUpdateFunction(updateComponent);
5012
4881
  const getValidationErrors = getLocalValueValidator(checks);
5013
- const performDebouncedRefresh = getDebouncedPerformRefresh(performRefresh, getValidationErrors);
4882
+ const performOnChange = getDebouncedSchemaOnChange(schemaOnChange, getValidationErrors);
4883
+ const validateAsync = performValidationAsync ? getDebouncedComponentValidationAsync(update, performValidationAsync) : void 0;
5014
4884
  const integerComponent = __spreadValues({
5015
4885
  type: "integer",
5016
4886
  uid,
@@ -5020,8 +4890,12 @@ var createIntegerInputComponent = (integerInputProps, updateComponent) => {
5020
4890
  update(this, updateFn);
5021
4891
  },
5022
4892
  onBlur() {
5023
- this.validate();
5024
- performDebouncedRefresh == null ? void 0 : performDebouncedRefresh.flush();
4893
+ const isValid = this.validate();
4894
+ performOnChange == null ? void 0 : performOnChange.flush();
4895
+ if (isValid) {
4896
+ onPersistAsync == null ? void 0 : onPersistAsync();
4897
+ validateAsync == null ? void 0 : validateAsync.flush();
4898
+ }
5025
4899
  },
5026
4900
  onFocus() {
5027
4901
  },
@@ -5033,7 +4907,11 @@ var createIntegerInputComponent = (integerInputProps, updateComponent) => {
5033
4907
  draft.validationAsyncState.messages = {};
5034
4908
  draft.value = updatedValue;
5035
4909
  });
5036
- performDebouncedRefresh == null ? void 0 : performDebouncedRefresh(prevValue, updatedValue);
4910
+ performOnChange == null ? void 0 : performOnChange(prevValue, updatedValue);
4911
+ const isValid = getValidationErrors(updatedValue).length === 0;
4912
+ if (isValid) {
4913
+ validateAsync == null ? void 0 : validateAsync(this, updatedValue);
4914
+ }
5037
4915
  onValueChange();
5038
4916
  },
5039
4917
  async getSubmittableValue() {
@@ -5057,62 +4935,22 @@ var createIntegerInputComponent = (integerInputProps, updateComponent) => {
5057
4935
  return errors.length === 0;
5058
4936
  }
5059
4937
  }, rest);
5060
- if (performRefresh) {
5061
- return integerComponent;
5062
- }
5063
- if (performPersistAsync) {
5064
- const persist = getComponentPersistAsync(update, performPersistAsync);
5065
- return __spreadProps(__spreadValues({}, integerComponent), {
5066
- onBlur() {
5067
- if (this.validate()) {
5068
- persist(this, this.getLocalValue()).catch(() => {
5069
- });
5070
- }
5071
- },
5072
- async getSubmittableValue() {
5073
- return persist(this, this.getLocalValue());
5074
- },
5075
- getSubmittableValueSync() {
5076
- return this.persistedState.lastResponse;
5077
- }
5078
- });
5079
- }
5080
- if (performValidationAsync) {
5081
- const validateAsync = getDebouncedComponentValidationAsync(update, performValidationAsync);
5082
- return __spreadProps(__spreadValues({}, integerComponent), {
5083
- onBlur() {
5084
- if (this.validate()) {
5085
- validateAsync.flush();
5086
- }
5087
- },
5088
- onChange(updatedValue) {
5089
- integerComponent.onChange.call(this, updatedValue);
5090
- if (getValidationErrors(updatedValue).length === 0) {
5091
- validateAsync(this, updatedValue);
5092
- }
5093
- }
5094
- });
5095
- }
5096
4938
  return integerComponent;
5097
4939
  };
5098
4940
 
5099
4941
  // src/revamp/domain/mappers/schema/integerSchemaToComponent.ts
5100
4942
  var integerSchemaToComponent = (schemaMapperProps, mapperProps) => {
5101
- const { schema, localValue, model, required = false } = schemaMapperProps;
4943
+ const { schema, localValue, model, required = false, onPersistAsync } = schemaMapperProps;
5102
4944
  const { autocompleteHint, validationMessages, default: defaultValue, maximum, minimum } = schema;
5103
4945
  const { getErrorMessageFunctions, updateComponent, onBehavior, onValueChange } = mapperProps;
5104
4946
  const errorMessageFunctions = getErrorMessageFunctions(validationMessages);
5105
- const { performPersistAsync, persistedState } = getPersistAsyncInitialState(
5106
- schemaMapperProps,
5107
- mapperProps
5108
- );
5109
4947
  const { performValidationAsync, validationAsyncState } = getValidationAsyncInitialState(
5110
4948
  schemaMapperProps,
5111
4949
  mapperProps
5112
4950
  );
5113
4951
  const validLocalValue = isInteger(localValue) ? localValue : null;
5114
4952
  const validModel = isInteger(model) ? model : defaultValue != null ? defaultValue : null;
5115
- const value = performPersistAsync ? validLocalValue : validModel;
4953
+ const value = onPersistAsync ? validLocalValue : validModel;
5116
4954
  const checks = [
5117
4955
  getRequiredCheck(required, errorMessageFunctions),
5118
4956
  getBelowMinimumCheck(schema, errorMessageFunctions),
@@ -5124,11 +4962,9 @@ var integerSchemaToComponent = (schemaMapperProps, mapperProps) => {
5124
4962
  checks,
5125
4963
  maximum,
5126
4964
  minimum,
5127
- persistedState,
5128
4965
  value,
5129
4966
  validationAsyncState,
5130
- performPersistAsync,
5131
- performRefresh: getPerformRefresh(schema, onBehavior),
4967
+ schemaOnChange: getSchemaOnChange(schema, onBehavior),
5132
4968
  performValidationAsync,
5133
4969
  onValueChange
5134
4970
  }),
@@ -5283,7 +5119,7 @@ var nonNullishKeys = (model) => Object.keys(model).filter((key) => !isNullish(mo
5283
5119
 
5284
5120
  // src/revamp/domain/components/SelectInputComponent.ts
5285
5121
  var createSelectInputComponent = (selectProps, updateComponent) => {
5286
- const _a = selectProps, { uid, checks, initialModel, options, performRefresh, onValueChange, summariser } = _a, rest = __objRest(_a, ["uid", "checks", "initialModel", "options", "performRefresh", "onValueChange", "summariser"]);
5122
+ const _a = selectProps, { uid, checks, initialModel, options, schemaOnChange, onValueChange, summariser } = _a, rest = __objRest(_a, ["uid", "checks", "initialModel", "options", "schemaOnChange", "onValueChange", "summariser"]);
5287
5123
  const children = options.map((option) => option.component);
5288
5124
  const matchingOptions = options.map(
5289
5125
  (option) => isPartialModelMatch(option.component.getSubmittableValueSync(), initialModel)
@@ -5344,7 +5180,7 @@ var createSelectInputComponent = (selectProps, updateComponent) => {
5344
5180
  draft.errors = [];
5345
5181
  draft.selectedIndex = updatedIndex;
5346
5182
  });
5347
- performRefresh == null ? void 0 : performRefresh();
5183
+ schemaOnChange == null ? void 0 : schemaOnChange();
5348
5184
  onValueChange();
5349
5185
  },
5350
5186
  validate() {
@@ -5416,7 +5252,7 @@ var oneOfSchemaToComponent = (schemaMapperProps, mapperProps) => {
5416
5252
  checks: schema.hidden ? [] : [getRequiredCheck(required, errorMessageFunctions)],
5417
5253
  options,
5418
5254
  initialModel,
5419
- performRefresh: getPerformRefresh(schema, onBehavior),
5255
+ schemaOnChange: getSchemaOnChange(schema, onBehavior),
5420
5256
  onValueChange,
5421
5257
  trackEvent
5422
5258
  }),
@@ -5435,25 +5271,26 @@ var createDateInputComponent = (textInputProps, updateComponent) => {
5435
5271
  uid,
5436
5272
  id,
5437
5273
  checks,
5438
- performPersistAsync,
5439
- performRefresh,
5274
+ schemaOnChange,
5440
5275
  performValidationAsync,
5441
5276
  onValueChange,
5277
+ onPersistAsync,
5442
5278
  summariser,
5443
5279
  value
5444
5280
  } = _a, rest = __objRest(_a, [
5445
5281
  "uid",
5446
5282
  "id",
5447
5283
  "checks",
5448
- "performPersistAsync",
5449
- "performRefresh",
5284
+ "schemaOnChange",
5450
5285
  "performValidationAsync",
5451
5286
  "onValueChange",
5287
+ "onPersistAsync",
5452
5288
  "summariser",
5453
5289
  "value"
5454
5290
  ]);
5455
5291
  const update = getInputUpdateFunction(updateComponent);
5456
5292
  const getValidationErrors = getLocalValueValidator(checks);
5293
+ const validateAsync = performValidationAsync ? getComponentValidationAsync(update, performValidationAsync) : void 0;
5457
5294
  const dateInputComponent = __spreadValues({
5458
5295
  type: "date",
5459
5296
  uid,
@@ -5463,7 +5300,11 @@ var createDateInputComponent = (textInputProps, updateComponent) => {
5463
5300
  update(this, updateFn);
5464
5301
  },
5465
5302
  onBlur() {
5466
- this.validate();
5303
+ const isValid = this.validate();
5304
+ if (isValid) {
5305
+ validateAsync == null ? void 0 : validateAsync(this, this.getLocalValue()).catch(() => {
5306
+ });
5307
+ }
5467
5308
  },
5468
5309
  onFocus() {
5469
5310
  },
@@ -5476,9 +5317,12 @@ var createDateInputComponent = (textInputProps, updateComponent) => {
5476
5317
  draft.value = updatedValue;
5477
5318
  });
5478
5319
  if (isOrWasValid(getValidationErrors, prevValue, updatedValue)) {
5479
- performRefresh == null ? void 0 : performRefresh();
5320
+ schemaOnChange == null ? void 0 : schemaOnChange();
5480
5321
  }
5481
5322
  onValueChange();
5323
+ if (getValidationErrors(updatedValue).length === 0) {
5324
+ onPersistAsync == null ? void 0 : onPersistAsync();
5325
+ }
5482
5326
  },
5483
5327
  async getSubmittableValue() {
5484
5328
  return this.getSubmittableValueSync();
@@ -5501,45 +5345,12 @@ var createDateInputComponent = (textInputProps, updateComponent) => {
5501
5345
  return errors.length === 0;
5502
5346
  }
5503
5347
  }, rest);
5504
- if (performRefresh) {
5505
- return dateInputComponent;
5506
- }
5507
- if (performPersistAsync) {
5508
- const persist = getComponentPersistAsync(update, performPersistAsync);
5509
- return __spreadProps(__spreadValues({}, dateInputComponent), {
5510
- onChange(updatedValue) {
5511
- dateInputComponent.onChange.call(this, updatedValue);
5512
- const isValid = getValidationErrors(updatedValue).length === 0;
5513
- if (isValid) {
5514
- persist(this, this.getLocalValue()).catch(() => {
5515
- });
5516
- }
5517
- },
5518
- async getSubmittableValue() {
5519
- return persist(this, this.getLocalValue());
5520
- },
5521
- getSubmittableValueSync() {
5522
- return this.persistedState.lastResponse;
5523
- }
5524
- });
5525
- }
5526
- if (performValidationAsync) {
5527
- const validateAsync = getComponentValidationAsync(update, performValidationAsync);
5528
- return __spreadProps(__spreadValues({}, dateInputComponent), {
5529
- onBlur() {
5530
- if (this.validate()) {
5531
- validateAsync(this, this.getLocalValue()).catch(() => {
5532
- });
5533
- }
5534
- }
5535
- });
5536
- }
5537
5348
  return dateInputComponent;
5538
5349
  };
5539
5350
 
5540
5351
  // src/revamp/domain/mappers/schema/stringSchemaToComponent/stringSchemaToDateInputComponent.ts
5541
5352
  var stringSchemaToDateInputComponent = (schemaMapperProps, mapperProps) => {
5542
- const { schema, localValue, model, required = false } = schemaMapperProps;
5353
+ const { schema, localValue, model, required = false, onPersistAsync } = schemaMapperProps;
5543
5354
  const {
5544
5355
  autocompleteHint,
5545
5356
  default: defaultValue,
@@ -5549,17 +5360,13 @@ var stringSchemaToDateInputComponent = (schemaMapperProps, mapperProps) => {
5549
5360
  } = schema;
5550
5361
  const { getErrorMessageFunctions, updateComponent, onBehavior, onValueChange } = mapperProps;
5551
5362
  const errorMessageFunctions = getErrorMessageFunctions(schema.validationMessages);
5552
- const { performPersistAsync, persistedState } = getPersistAsyncInitialState(
5553
- schemaMapperProps,
5554
- mapperProps
5555
- );
5556
5363
  const { performValidationAsync, validationAsyncState } = getValidationAsyncInitialState(
5557
5364
  schemaMapperProps,
5558
5365
  mapperProps
5559
5366
  );
5560
5367
  const validLocalValue = isString(localValue) ? localValue : null;
5561
5368
  const validModel = isString(model) ? model : defaultValue != null ? defaultValue : null;
5562
- const value = performPersistAsync ? validLocalValue : validModel;
5369
+ const value = onPersistAsync ? validLocalValue : validModel;
5563
5370
  return createDateInputComponent(
5564
5371
  __spreadProps(__spreadValues({}, mapCommonSchemaProps(schemaMapperProps)), {
5565
5372
  autoComplete: getAutocompleteString(autocompleteHint),
@@ -5576,10 +5383,8 @@ var stringSchemaToDateInputComponent = (schemaMapperProps, mapperProps) => {
5576
5383
  }))
5577
5384
  } : void 0,
5578
5385
  value,
5579
- persistedState,
5580
5386
  validationAsyncState,
5581
- performPersistAsync,
5582
- performRefresh: getPerformRefresh(schema, onBehavior),
5387
+ schemaOnChange: getSchemaOnChange(schema, onBehavior),
5583
5388
  performValidationAsync,
5584
5389
  onValueChange
5585
5390
  }),
@@ -5594,8 +5399,6 @@ var stringSchemaToUploadInputComponent = (schemaMapperProps, mapperProps) => {
5594
5399
  const { accepts, autocompleteHint, cameraConfig, hidden, maxSize, source, validationMessages } = schema;
5595
5400
  const { getErrorMessageFunctions, updateComponent, onBehavior, onValueChange } = mapperProps;
5596
5401
  const errorMessageFunctions = getErrorMessageFunctions(validationMessages);
5597
- const { performPersistAsync } = getPersistAsyncInitialState(schemaMapperProps, mapperProps);
5598
- const persistedState = performPersistAsync ? getInitialPersistedState(null, model) : getInitialPersistedState();
5599
5402
  const validLocalValue = isFile(localValue) ? localValue : null;
5600
5403
  const value = (_a = getFileFromModel(model)) != null ? _a : validLocalValue;
5601
5404
  const checks = hidden ? [] : [
@@ -5613,9 +5416,7 @@ var stringSchemaToUploadInputComponent = (schemaMapperProps, mapperProps) => {
5613
5416
  maxSize,
5614
5417
  source,
5615
5418
  value,
5616
- persistedState,
5617
- performPersistAsync,
5618
- performRefresh: getPerformRefresh(schema, onBehavior),
5419
+ schemaOnChange: getSchemaOnChange(schema, onBehavior),
5619
5420
  onValueChange
5620
5421
  }),
5621
5422
  updateComponent
@@ -5629,26 +5430,27 @@ var createTextInputComponent = (textInputProps, updateComponent) => {
5629
5430
  uid,
5630
5431
  id,
5631
5432
  checks,
5632
- performPersistAsync,
5633
- performRefresh,
5433
+ schemaOnChange,
5634
5434
  performValidationAsync,
5635
5435
  onValueChange,
5436
+ onPersistAsync,
5636
5437
  summariser,
5637
5438
  value
5638
5439
  } = _a, rest = __objRest(_a, [
5639
5440
  "uid",
5640
5441
  "id",
5641
5442
  "checks",
5642
- "performPersistAsync",
5643
- "performRefresh",
5443
+ "schemaOnChange",
5644
5444
  "performValidationAsync",
5645
5445
  "onValueChange",
5446
+ "onPersistAsync",
5646
5447
  "summariser",
5647
5448
  "value"
5648
5449
  ]);
5649
5450
  const update = getInputUpdateFunction(updateComponent);
5650
5451
  const getValidationErrors = getLocalValueValidator(checks);
5651
- const performDebouncedRefresh = getDebouncedPerformRefresh(performRefresh, getValidationErrors);
5452
+ const performOnChange = getDebouncedSchemaOnChange(schemaOnChange, getValidationErrors);
5453
+ const validateAsync = performValidationAsync ? getDebouncedComponentValidationAsync(update, performValidationAsync) : void 0;
5652
5454
  const inputComponent = __spreadValues({
5653
5455
  type: "text",
5654
5456
  uid,
@@ -5658,8 +5460,12 @@ var createTextInputComponent = (textInputProps, updateComponent) => {
5658
5460
  update(this, updateFn);
5659
5461
  },
5660
5462
  onBlur() {
5661
- this.validate();
5662
- performDebouncedRefresh == null ? void 0 : performDebouncedRefresh.flush();
5463
+ const isValid = this.validate();
5464
+ performOnChange == null ? void 0 : performOnChange.flush();
5465
+ if (isValid) {
5466
+ onPersistAsync == null ? void 0 : onPersistAsync();
5467
+ validateAsync == null ? void 0 : validateAsync.flush();
5468
+ }
5663
5469
  },
5664
5470
  onFocus() {
5665
5471
  },
@@ -5671,7 +5477,14 @@ var createTextInputComponent = (textInputProps, updateComponent) => {
5671
5477
  draft.validationAsyncState.messages = {};
5672
5478
  draft.value = updatedValue;
5673
5479
  });
5674
- performDebouncedRefresh == null ? void 0 : performDebouncedRefresh(prevValue, updatedValue);
5480
+ performOnChange == null ? void 0 : performOnChange(prevValue, updatedValue);
5481
+ const isValid = getValidationErrors(updatedValue).length === 0;
5482
+ if (isValid) {
5483
+ validateAsync == null ? void 0 : validateAsync(this, updatedValue);
5484
+ }
5485
+ if (!updatedValue) {
5486
+ validateAsync == null ? void 0 : validateAsync.cancel();
5487
+ }
5675
5488
  onValueChange();
5676
5489
  },
5677
5490
  async getSubmittableValue() {
@@ -5694,51 +5507,12 @@ var createTextInputComponent = (textInputProps, updateComponent) => {
5694
5507
  return errors.length === 0;
5695
5508
  }
5696
5509
  }, rest);
5697
- if (performRefresh) {
5698
- return inputComponent;
5699
- }
5700
- if (performPersistAsync) {
5701
- const persist = getComponentPersistAsync(update, performPersistAsync);
5702
- return __spreadProps(__spreadValues({}, inputComponent), {
5703
- onBlur() {
5704
- if (this.validate()) {
5705
- persist(this, this.getLocalValue()).catch(() => {
5706
- });
5707
- }
5708
- },
5709
- async getSubmittableValue() {
5710
- return persist(this, this.getLocalValue());
5711
- },
5712
- getSubmittableValueSync() {
5713
- return this.persistedState.lastResponse;
5714
- }
5715
- });
5716
- }
5717
- if (performValidationAsync) {
5718
- const validateAsync = getDebouncedComponentValidationAsync(update, performValidationAsync);
5719
- return __spreadProps(__spreadValues({}, inputComponent), {
5720
- onBlur() {
5721
- if (this.validate()) {
5722
- validateAsync.flush();
5723
- }
5724
- },
5725
- onChange(updatedValue) {
5726
- inputComponent.onChange.call(this, updatedValue);
5727
- if (getValidationErrors(updatedValue).length === 0) {
5728
- validateAsync(this, updatedValue);
5729
- }
5730
- if (!updatedValue) {
5731
- validateAsync.cancel();
5732
- }
5733
- }
5734
- });
5735
- }
5736
5510
  return inputComponent;
5737
5511
  };
5738
5512
 
5739
5513
  // src/revamp/domain/mappers/schema/stringSchemaToComponent/stringSchemaToTextInputComponent.ts
5740
5514
  var stringSchemaToTextInputComponent = (schemaMapperProps, mapperProps) => {
5741
- const { schema, localValue, model, required = false } = schemaMapperProps;
5515
+ const { schema, localValue, model, required = false, onPersistAsync } = schemaMapperProps;
5742
5516
  const {
5743
5517
  autocapitalization,
5744
5518
  autocompleteHint,
@@ -5754,17 +5528,13 @@ var stringSchemaToTextInputComponent = (schemaMapperProps, mapperProps) => {
5754
5528
  const { getErrorMessageFunctions, updateComponent, onBehavior, onValueChange, logEvent } = mapperProps;
5755
5529
  const controlForLegacyFormat = getControlForLegacyFormat(format);
5756
5530
  const errorMessageFunctions = getErrorMessageFunctions(validationMessages);
5757
- const { performPersistAsync, persistedState } = getPersistAsyncInitialState(
5758
- schemaMapperProps,
5759
- mapperProps
5760
- );
5761
5531
  const { performValidationAsync, validationAsyncState } = getValidationAsyncInitialState(
5762
5532
  schemaMapperProps,
5763
5533
  mapperProps
5764
5534
  );
5765
5535
  const validLocalValue = isString(localValue) ? localValue : null;
5766
5536
  const validModel = isString(model) ? model : defaultValue != null ? defaultValue : null;
5767
- const value = performPersistAsync ? validLocalValue : validModel;
5537
+ const value = onPersistAsync ? validLocalValue : validModel;
5768
5538
  return createTextInputComponent(
5769
5539
  __spreadProps(__spreadValues({}, mapCommonSchemaProps(schemaMapperProps)), {
5770
5540
  autocapitalization,
@@ -5785,10 +5555,8 @@ var stringSchemaToTextInputComponent = (schemaMapperProps, mapperProps) => {
5785
5555
  }))
5786
5556
  } : void 0,
5787
5557
  value,
5788
- persistedState,
5789
5558
  validationAsyncState,
5790
- performPersistAsync,
5791
- performRefresh: getPerformRefresh(schema, onBehavior),
5559
+ schemaOnChange: getSchemaOnChange(schema, onBehavior),
5792
5560
  performValidationAsync,
5793
5561
  onValueChange
5794
5562
  }),
@@ -5819,6 +5587,136 @@ var isStringSchemaWithBase64 = (schema) => {
5819
5587
  return schema.format === "base64url" && !("persistAsync" in schema);
5820
5588
  };
5821
5589
 
5590
+ // src/revamp/domain/components/utils/isExactLocalValueMatch.ts
5591
+ var isExactLocalValueMatch = (valueA, valueB) => {
5592
+ if (isArrayLocalValue(valueA) && isArrayLocalValue(valueB)) {
5593
+ return valueA.length === valueB.length && valueA.every((value, index) => isExactLocalValueMatch(value, valueB[index]));
5594
+ }
5595
+ if (isObjectLocalValue(valueA) && isObjectLocalValue(valueB)) {
5596
+ const keysA = Object.keys(valueA);
5597
+ const keysB = Object.keys(valueB);
5598
+ return keysA.length === keysB.length && keysA.every((key) => isExactLocalValueMatch(valueA[key], valueB[key]));
5599
+ }
5600
+ return valueA === valueB;
5601
+ };
5602
+
5603
+ // src/revamp/domain/components/PersistAsyncComponent.ts
5604
+ var createPersistAsyncComponent = (props, performPersistAsync, schemaOnChange, updateComponent) => {
5605
+ const { uid, schemaId, component, hidden, model, localValue } = props;
5606
+ const update = getInputUpdateFunction(updateComponent);
5607
+ const paComponent = {
5608
+ type: "persist-async",
5609
+ uid,
5610
+ schemaId,
5611
+ component,
5612
+ hidden,
5613
+ lastSubmitted: model != null ? localValue != null ? localValue : null : null,
5614
+ lastResponse: model != null ? model : null,
5615
+ submission: Promise.resolve(model != null ? model : null),
5616
+ abortController: new AbortController(),
5617
+ errors: [],
5618
+ _update(updateFn) {
5619
+ update(this, updateFn);
5620
+ },
5621
+ validate() {
5622
+ return this.component.validate();
5623
+ },
5624
+ getLocalValue() {
5625
+ return this.component.getLocalValue();
5626
+ },
5627
+ async getSubmittableValue() {
5628
+ return this.persist();
5629
+ },
5630
+ getSubmittableValueSync() {
5631
+ return this.lastResponse;
5632
+ },
5633
+ getSummary() {
5634
+ return this.component.getSummary();
5635
+ },
5636
+ async persist() {
5637
+ const childLocalValue = this.component.getLocalValue();
5638
+ if (isExactLocalValueMatch(childLocalValue, this.lastSubmitted)) {
5639
+ return this.submission;
5640
+ }
5641
+ const newAbortController = abortAndResetController(this.abortController);
5642
+ if (childLocalValue == null || childLocalValue === "") {
5643
+ const resolvedNull = Promise.resolve(null);
5644
+ this._update((draft) => {
5645
+ draft.abortController = newAbortController;
5646
+ draft.lastResponse = null;
5647
+ draft.lastSubmitted = childLocalValue;
5648
+ draft.submission = resolvedNull;
5649
+ draft.errors = [];
5650
+ });
5651
+ schemaOnChange == null ? void 0 : schemaOnChange();
5652
+ return resolvedNull;
5653
+ }
5654
+ const { signal } = newAbortController;
5655
+ const newSubmission = performPersistAsync({ value: childLocalValue, signal }).then((token) => {
5656
+ this._update((draft) => {
5657
+ draft.lastResponse = token;
5658
+ draft.errors = [];
5659
+ });
5660
+ schemaOnChange == null ? void 0 : schemaOnChange();
5661
+ return token;
5662
+ }).catch((error) => {
5663
+ if (error instanceof DOMException && error.name === "AbortError") {
5664
+ return null;
5665
+ }
5666
+ this._update((draft) => {
5667
+ draft.lastResponse = null;
5668
+ draft.lastSubmitted = null;
5669
+ draft.errors = error instanceof Error ? [error.message] : [];
5670
+ });
5671
+ throw error;
5672
+ });
5673
+ this._update((draft) => {
5674
+ draft.abortController = newAbortController;
5675
+ draft.lastSubmitted = childLocalValue;
5676
+ draft.lastResponse = null;
5677
+ draft.submission = newSubmission;
5678
+ draft.errors = [];
5679
+ });
5680
+ return newSubmission;
5681
+ }
5682
+ };
5683
+ return paComponent;
5684
+ };
5685
+
5686
+ // src/revamp/domain/mappers/schema/persistAsyncSchemaToComponent.ts
5687
+ var isSupported = (type) => ["boolean", "text", "date", "integer", "number", "upload"].includes(type);
5688
+ var persistAsyncSchemaToComponent = (schemaMapperProps, mapperProps) => {
5689
+ var _a;
5690
+ const { uid, schema, model, localValue } = schemaMapperProps;
5691
+ const { persistAsync } = schema;
5692
+ const performPersistAsync = getPerformPersistAsyncFn(schema, persistAsync, mapperProps);
5693
+ const onPersistAsync = () => {
5694
+ void paComponent.persist().catch(() => {
5695
+ });
5696
+ };
5697
+ const childComponent = mapSchemaToComponent(
5698
+ __spreadProps(__spreadValues({}, schemaMapperProps), { uid: `${uid}-persist`, schema: persistAsync.schema, onPersistAsync }),
5699
+ mapperProps
5700
+ );
5701
+ if (!isSupported(childComponent.type)) {
5702
+ return childComponent;
5703
+ }
5704
+ const paComponent = createPersistAsyncComponent(
5705
+ {
5706
+ uid,
5707
+ hidden: (_a = schema.hidden) != null ? _a : false,
5708
+ component: childComponent,
5709
+ schemaId: schema.$id,
5710
+ model,
5711
+ localValue
5712
+ },
5713
+ performPersistAsync,
5714
+ getSchemaOnChange(schema, mapperProps.onBehavior),
5715
+ mapperProps.updateComponent
5716
+ );
5717
+ return paComponent;
5718
+ };
5719
+
5822
5720
  // src/revamp/domain/mappers/mapSchemaToComponent.ts
5823
5721
  var mapSchemaToComponent = (schemaMapperProps, mapperProps) => {
5824
5722
  const { uid, schema } = schemaMapperProps;
@@ -5826,13 +5724,7 @@ var mapSchemaToComponent = (schemaMapperProps, mapperProps) => {
5826
5724
  return constSchemaToComponent(uid, __spreadProps(__spreadValues({}, schemaMapperProps), { schema }));
5827
5725
  }
5828
5726
  if (isSchemaWithPersistAsync(schema)) {
5829
- const { persistAsync } = schema;
5830
- const { idProperty, method, param, url } = persistAsync;
5831
- const persistAsyncConfig = { idProperty, method, param, url };
5832
- return mapSchemaToComponent(
5833
- __spreadProps(__spreadValues({}, schemaMapperProps), { persistAsyncConfig, schema: persistAsync.schema }),
5834
- mapperProps
5835
- );
5727
+ return persistAsyncSchemaToComponent(__spreadProps(__spreadValues({}, schemaMapperProps), { schema }), mapperProps);
5836
5728
  }
5837
5729
  if (isAllOfSchema(schema)) {
5838
5730
  return allOfSchemaToComponent(__spreadProps(__spreadValues({}, schemaMapperProps), { schema }), mapperProps);
@@ -5859,7 +5751,7 @@ var mapSchemaToComponent = (schemaMapperProps, mapperProps) => {
5859
5751
  return arraySchemaToComponent(__spreadProps(__spreadValues({}, schemaMapperProps), { schema }), mapperProps);
5860
5752
  }
5861
5753
  if (isBlobSchema(schema)) {
5862
- if (!schemaMapperProps.persistAsyncConfig) {
5754
+ if (!schemaMapperProps.onPersistAsync) {
5863
5755
  throw new Error(
5864
5756
  "Blob schemas can only be used as the schema of a persist async configuration."
5865
5757
  );
@@ -6061,8 +5953,8 @@ var executePoll = async (props) => {
6061
5953
 
6062
5954
  // src/revamp/flow/executeRefresh.ts
6063
5955
  var executeRefresh = async (props) => {
6064
- const { abortSignal, url, model, schemaId, etag, httpClient, trackEvent, logEvent } = props;
6065
- trackEvent("Refresh Triggered", { schema: schemaId });
5956
+ const { abortSignal, url, model, etag, analytics, httpClient, trackEvent, logEvent } = props;
5957
+ trackEvent("Refresh Triggered", analytics);
6066
5958
  try {
6067
5959
  const response = await httpClient(url != null ? url : "", {
6068
5960
  method: "POST",
@@ -6073,34 +5965,34 @@ var executeRefresh = async (props) => {
6073
5965
  signal: abortSignal
6074
5966
  });
6075
5967
  if (response.status === 304) {
6076
- trackEvent("Refresh Succeeded", { schema: schemaId });
5968
+ trackEvent("Refresh Succeeded", analytics);
6077
5969
  return { type: "noop" };
6078
5970
  }
6079
5971
  if (!response.ok) {
6080
5972
  const responseBody = await parseResponseBodyAsJsonElement(response).catch(() => ({}));
6081
5973
  const body2 = isErrorResponseBody(responseBody) ? responseBody : {};
6082
- trackEvent("Refresh Failed", __spreadProps(__spreadValues({}, body2.analytics), {
6083
- schema: schemaId,
5974
+ trackEvent("Refresh Failed", __spreadProps(__spreadValues(__spreadValues({}, analytics), body2.analytics), {
5975
+ statusCode: response.status
5976
+ }));
5977
+ logEvent("error", "Dynamic Flow - Refresh Failed", __spreadProps(__spreadValues({}, analytics), {
6084
5978
  statusCode: response.status
6085
5979
  }));
6086
- logEvent("error", "Dynamic Flow - Refresh Failed", { schemaId, statusCode: response.status });
6087
5980
  return { type: "error", body: body2, statusCode: response.status };
6088
5981
  }
6089
5982
  const newEtag = response.headers.get("etag") || null;
6090
5983
  const body = await parseResponseBodyAsJsonElement(response);
6091
5984
  assertStepResponseBody(body);
6092
- trackEvent("Refresh Succeeded", { schema: schemaId });
5985
+ trackEvent("Refresh Succeeded", analytics);
6093
5986
  return { type: "refresh-step", step: body, etag: newEtag };
6094
5987
  } catch (error) {
6095
5988
  if (error instanceof DOMException && error.name === "AbortError") {
6096
- trackEvent("Refresh Aborted", { schema: schemaId });
5989
+ trackEvent("Refresh Aborted", analytics);
6097
5990
  return { type: "noop" };
6098
5991
  }
6099
- trackEvent("Refresh Failed", { schema: schemaId });
6100
- logEvent("error", "Dynamic Flow - Refresh Failed", {
6101
- schemaId,
5992
+ trackEvent("Refresh Failed", analytics);
5993
+ logEvent("error", "Dynamic Flow - Refresh Failed", __spreadProps(__spreadValues({}, analytics), {
6102
5994
  errorMessage: getErrorMessage(error)
6103
- });
5995
+ }));
6104
5996
  return { type: "error", body: {} };
6105
5997
  }
6106
5998
  };
@@ -6134,7 +6026,7 @@ var executeSubmission = async (props) => {
6134
6026
  const extra = { actionId, errorMessage: "Network Error" };
6135
6027
  trackEvent("Action Failed", extra);
6136
6028
  logEvent("error", "Dynamic Flow - Action Failed Unexpectedly", extra);
6137
- return { type: "error", body: {} };
6029
+ return { type: "error" };
6138
6030
  }
6139
6031
  if (!response.ok) {
6140
6032
  return handleErrorResponse(response, actionId);
@@ -6177,16 +6069,27 @@ var executeSubmission = async (props) => {
6177
6069
  }
6178
6070
  };
6179
6071
  const handleErrorResponse = async (response, actionId) => {
6180
- const body = await parseResponseBodyAsJsonElement(response);
6072
+ const body = await parseResponseBodyAsJsonElement(response.clone());
6181
6073
  if (isErrorResponseBody(body)) {
6182
6074
  const refreshUrl = body.refreshUrl || body.refreshFormUrl;
6183
6075
  const { error, validation, analytics } = body;
6184
6076
  trackEvent("Action Failed", __spreadProps(__spreadValues({}, analytics), { actionId, statusCode: response.status }));
6185
6077
  const errors = { error, validation };
6186
- return refreshUrl ? { type: "refresh", body: { refreshUrl, errors } } : { type: "error", body: { errors, analytics }, statusCode: response.status };
6078
+ return refreshUrl ? { type: "refresh", body: { refreshUrl, errors } } : {
6079
+ type: "error",
6080
+ body: { errors, analytics },
6081
+ httpError: { statusCode: response.status }
6082
+ };
6187
6083
  }
6188
6084
  trackEvent("Action Failed", { actionId, statusCode: response.status });
6189
- return { type: "error", body: {}, statusCode: response.status };
6085
+ const errorMessage = await parseResponseBodyAsText(response);
6086
+ return {
6087
+ type: "error",
6088
+ httpError: {
6089
+ message: errorMessage || void 0,
6090
+ statusCode: response.status
6091
+ }
6092
+ };
6190
6093
  };
6191
6094
  return triggerAction(props.action, props.model, props.isInitial);
6192
6095
  };
@@ -6579,7 +6482,7 @@ function useDynamicFlowCore(props) {
6579
6482
  break;
6580
6483
  }
6581
6484
  case "refresh": {
6582
- await onRefresh(behavior.schemaId, behavior.url);
6485
+ await onRefresh({ refreshUrl: behavior.url, analytics: behavior.analytics });
6583
6486
  break;
6584
6487
  }
6585
6488
  case "link": {
@@ -6610,7 +6513,7 @@ function useDynamicFlowCore(props) {
6610
6513
  }
6611
6514
  }, []);
6612
6515
  const onAction = (0, import_react3.useCallback)(async (action) => {
6613
- var _a2;
6516
+ var _a2, _b, _c, _d, _e, _f, _g;
6614
6517
  try {
6615
6518
  rootComponentRef.current.setLoadingState("submitting");
6616
6519
  const model = (_a2 = await rootComponentRef.current.getSubmittableValue()) != null ? _a2 : null;
@@ -6637,7 +6540,7 @@ function useDynamicFlowCore(props) {
6637
6540
  }
6638
6541
  case "error": {
6639
6542
  const genericErrorMessage = getErrorMessageFunctions().genericErrorWithRetry();
6640
- const { errors = { error: genericErrorMessage } } = command.body;
6543
+ const errors = (_c = (_b = command.body) == null ? void 0 : _b.errors) != null ? _c : { error: genericErrorMessage };
6641
6544
  if (stepRef.current) {
6642
6545
  updateStep(
6643
6546
  __spreadProps(__spreadValues({}, stepRef.current), {
@@ -6654,19 +6557,20 @@ function useDynamicFlowCore(props) {
6654
6557
  etagRef.current
6655
6558
  );
6656
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";
6657
6561
  closeWithError(
6658
- new Error("Initial request failed", {
6562
+ new Error(errorMessage, {
6659
6563
  cause: `method: ${action.method}, url: ${action.url}`
6660
6564
  }),
6661
6565
  {},
6662
- command.statusCode
6566
+ (_g = command.httpError) == null ? void 0 : _g.statusCode
6663
6567
  );
6664
6568
  }
6665
6569
  break;
6666
6570
  }
6667
6571
  case "refresh": {
6668
6572
  const { refreshUrl, errors = {} } = command.body;
6669
- void onRefresh(void 0, refreshUrl, errors);
6573
+ void onRefresh({ refreshUrl, errorsOverride: errors });
6670
6574
  break;
6671
6575
  }
6672
6576
  case "behavior": {
@@ -6680,7 +6584,11 @@ function useDynamicFlowCore(props) {
6680
6584
  }
6681
6585
  }, []);
6682
6586
  const onRefresh = (0, import_react3.useCallback)(
6683
- async (schemaId, refreshUrl, errorsOverride) => {
6587
+ async ({
6588
+ refreshUrl,
6589
+ errorsOverride,
6590
+ analytics
6591
+ }) => {
6684
6592
  var _a2, _b;
6685
6593
  try {
6686
6594
  rootComponentRef.current.setLoadingState("refreshing");
@@ -6689,8 +6597,8 @@ function useDynamicFlowCore(props) {
6689
6597
  abortSignal: abortCurrentAndGetNewAbortSignal(),
6690
6598
  url: (_b = refreshUrl != null ? refreshUrl : rootComponentRef.current.getRefreshUrl()) != null ? _b : "",
6691
6599
  model,
6692
- schemaId,
6693
6600
  etag: etagRef.current,
6601
+ analytics,
6694
6602
  httpClient,
6695
6603
  trackEvent: trackCoreEvent,
6696
6604
  logEvent