@wise/dynamic-flow-client 4.6.0 → 4.7.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.
Files changed (29) hide show
  1. package/build/main.js +482 -593
  2. package/build/main.mjs +482 -593
  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/renderers/mappers/persistAsyncComponentToProps.d.ts +3 -0
  25. package/build/types/revamp/utils/type-utils.d.ts +1 -2
  26. package/package.json +16 -16
  27. package/build/types/revamp/domain/features/persistAsync/getComponentPersistAsync.d.ts +0 -21
  28. package/build/types/revamp/domain/features/refresh/getPerformRefresh.d.ts +0 -12
  29. package/build/types/revamp/domain/mappers/schema/utils/getPersistAsyncInitialState.d.ts +0 -5
package/build/main.mjs CHANGED
@@ -1530,6 +1530,17 @@ var objectComponentToProps = (component, rendererMapperProps) => {
1530
1530
  // src/revamp/renderers/mappers/paragraphComponentToProps.ts
1531
1531
  var paragraphComponentToProps = (component, rendererMapperProps) => __spreadValues(__spreadValues({}, pick(component, "uid", "type", "align", "control", "margin", "text")), rendererMapperProps);
1532
1532
 
1533
+ // src/revamp/renderers/mappers/persistAsyncComponentToProps.ts
1534
+ var persistAsyncComponentToProps = (component, rendererMapperProps) => {
1535
+ const props = componentToRendererProps(component.component, rendererMapperProps);
1536
+ if ("validationState" in props && component.errors.length > 0) {
1537
+ return __spreadProps(__spreadValues({}, props), {
1538
+ validationState: { status: "invalid", message: component.errors[0] }
1539
+ });
1540
+ }
1541
+ return props;
1542
+ };
1543
+
1533
1544
  // src/revamp/renderers/mappers/repeatableComponentToProps.ts
1534
1545
  var repeatableComponentToProps = (component, rendererMapperProps) => {
1535
1546
  const {
@@ -1833,6 +1844,8 @@ var getComponentProps = (component, rendererMapperProps) => {
1833
1844
  return tupleComponentToProps(component, rendererMapperProps);
1834
1845
  case "upload":
1835
1846
  return uploadInputComponentToProps(component, rendererMapperProps);
1847
+ case "persist-async":
1848
+ return persistAsyncComponentToProps(component, rendererMapperProps);
1836
1849
  default:
1837
1850
  throw new Error("Unknown component type");
1838
1851
  }
@@ -3038,26 +3051,44 @@ var getStepRefreshAfter = ({ refreshAfter, onBehavior }) => {
3038
3051
  }
3039
3052
  const timeLeft = Math.max(targetTime - Date.now(), ONE_SECOND);
3040
3053
  const timeout = setTimeout(() => {
3041
- void onBehavior({ type: "refresh", schemaId: "refreshAfter" });
3054
+ void onBehavior({ type: "refresh", analytics: { schema: "refreshAfter" } });
3042
3055
  }, timeLeft);
3043
3056
  return {
3044
3057
  stop: () => clearTimeout(timeout)
3045
3058
  };
3046
3059
  };
3047
3060
 
3048
- // src/revamp/domain/components/utils/isExactLocalValueMatch.ts
3049
- var isExactLocalValueMatch = (valueA, valueB) => {
3050
- if (isArrayLocalValue(valueA) && isArrayLocalValue(valueB)) {
3051
- return valueA.length === valueB.length && valueA.every((value, index) => isExactLocalValueMatch(value, valueB[index]));
3052
- }
3053
- if (isObjectLocalValue(valueA) && isObjectLocalValue(valueB)) {
3054
- const keysA = Object.keys(valueA);
3055
- const keysB = Object.keys(valueB);
3056
- return keysA.length === keysB.length && keysA.every((key) => isExactLocalValueMatch(valueA[key], valueB[key]));
3061
+ // src/revamp/domain/components/utils/isOrWasValid.ts
3062
+ var isOrWasValid = (getErrors, previous, current) => {
3063
+ const wasValid = getErrors(previous).length === 0 && previous !== null;
3064
+ const isValid = getErrors(current).length === 0;
3065
+ return wasValid || isValid;
3066
+ };
3067
+
3068
+ // src/revamp/domain/features/schema-on-change/getDebouncedSchemaOnChange.ts
3069
+ var getDebouncedSchemaOnChange = (onChange, getValidationErrors) => {
3070
+ if (!onChange) {
3071
+ return void 0;
3057
3072
  }
3058
- return valueA === valueB;
3073
+ const debouncedOnChange = debounce(onChange, 1e3);
3074
+ return onChange.behaviorType === "refresh" ? getSelectiveDebouncedSchemaOnChange(debouncedOnChange, getValidationErrors) : debouncedOnChange;
3075
+ };
3076
+ var getSelectiveDebouncedSchemaOnChange = (debouncedOnChange, getValidationErrors) => {
3077
+ const debouncedFn = (prevValue, updatedValue) => {
3078
+ if (isOrWasValid(getValidationErrors, prevValue, updatedValue) || (debouncedOnChange == null ? void 0 : debouncedOnChange.isPending())) {
3079
+ debouncedOnChange == null ? void 0 : debouncedOnChange();
3080
+ }
3081
+ };
3082
+ debouncedFn.flush = () => debouncedOnChange.flush();
3083
+ debouncedFn.cancel = () => debouncedOnChange.cancel();
3084
+ debouncedFn.isPending = () => debouncedOnChange.isPending();
3085
+ return debouncedFn;
3059
3086
  };
3060
3087
 
3088
+ // src/revamp/domain/features/validation/validation-functions.ts
3089
+ var validateComponents = (components) => components.reduce((acc, component) => component.validate() && acc, true);
3090
+ var getLocalValueValidator = (checks) => (currentValue) => checks.map((check) => check(currentValue)).filter(isString);
3091
+
3061
3092
  // src/revamp/domain/features/utils/http-utils.ts
3062
3093
  function constructPayload({
3063
3094
  value,
@@ -3085,143 +3116,6 @@ var abortAndResetController = (abortController) => {
3085
3116
  return new AbortController();
3086
3117
  };
3087
3118
 
3088
- // src/revamp/domain/features/persistAsync/getComponentPersistAsync.ts
3089
- var getComponentPersistAsync = (update, performPersistAsync) => (
3090
- /**
3091
- * Will update the persistedState when a new request is made, and will update
3092
- * the value or set errors when the request completes.
3093
- */
3094
- async (component, currentValue) => {
3095
- const { abortController, lastSubmitted, submission } = component.persistedState;
3096
- if (isExactLocalValueMatch(lastSubmitted, currentValue)) {
3097
- return submission;
3098
- }
3099
- const newAbortController = abortAndResetController(abortController);
3100
- if (isNullish(currentValue) || currentValue === "") {
3101
- const resolvedNull = Promise.resolve(null);
3102
- update(component, (draft) => {
3103
- draft.persistedState.abortController = newAbortController;
3104
- draft.persistedState.lastResponse = null;
3105
- draft.persistedState.lastSubmitted = currentValue;
3106
- draft.persistedState.submission = resolvedNull;
3107
- });
3108
- return resolvedNull;
3109
- }
3110
- const { signal } = newAbortController;
3111
- const newSubmission = performPersistAsync({ value: currentValue, signal }).then((newValue) => {
3112
- update(component, (draft) => {
3113
- draft.persistedState.lastResponse = newValue;
3114
- });
3115
- return newValue;
3116
- }).catch((error) => {
3117
- if (error instanceof DOMException && error.name === "AbortError") {
3118
- return null;
3119
- }
3120
- update(component, (draft) => {
3121
- draft.errors = [error.message];
3122
- draft.persistedState.lastResponse = null;
3123
- draft.persistedState.lastSubmitted = null;
3124
- });
3125
- throw error;
3126
- });
3127
- update(component, (draft) => {
3128
- draft.persistedState = {
3129
- abortController: newAbortController,
3130
- lastResponse: null,
3131
- lastSubmitted: currentValue,
3132
- submission: newSubmission
3133
- };
3134
- });
3135
- return newSubmission;
3136
- }
3137
- );
3138
- var getComponentMultiPersistAsync = (update, performPersistAsync) => (
3139
- /**
3140
- * Will update the persistedState when a new request is made, and will update
3141
- * the value or set errors when the request completes.
3142
- */
3143
- async (component, index, value) => {
3144
- if (isNullish(value)) {
3145
- throw new Error("Value must be a file or base64 string.");
3146
- }
3147
- const newAbortController = new AbortController();
3148
- const { signal } = newAbortController;
3149
- const newSubmission = performPersistAsync({ value, signal }).then((newValue) => {
3150
- update(component, (draft) => {
3151
- draft.persistedState[index].lastResponse = newValue;
3152
- });
3153
- return newValue;
3154
- }).catch((error) => {
3155
- update(component, (draft) => {
3156
- draft.persistedState = [
3157
- ...draft.persistedState.slice(0, index),
3158
- ...draft.persistedState.slice(index + 1)
3159
- ];
3160
- draft.value.splice(index, 1);
3161
- draft.files.splice(index, 1);
3162
- });
3163
- throw error;
3164
- });
3165
- update(component, (draft) => {
3166
- draft.persistedState = [
3167
- ...draft.persistedState.slice(0, index),
3168
- {
3169
- id: getRandomId(),
3170
- abortController: newAbortController,
3171
- lastResponse: null,
3172
- lastSubmitted: null,
3173
- submission: newSubmission
3174
- },
3175
- ...draft.persistedState.slice(index)
3176
- ];
3177
- });
3178
- return newSubmission;
3179
- }
3180
- );
3181
-
3182
- // src/revamp/domain/components/utils/isOrWasValid.ts
3183
- var isOrWasValid = (getErrors, previous, current) => {
3184
- const wasValid = getErrors(previous).length === 0 && previous !== null;
3185
- const isValid = getErrors(current).length === 0;
3186
- return wasValid || isValid;
3187
- };
3188
-
3189
- // src/revamp/domain/features/refresh/getPerformRefresh.ts
3190
- var getPerformRefresh = (schema, onBehavior) => {
3191
- var _a, _b;
3192
- if ("refreshStepOnChange" in schema && ((_a = schema.refreshStepOnChange) != null ? _a : false) || "refreshFormOnChange" in schema && ((_b = schema.refreshFormOnChange) != null ? _b : false)) {
3193
- const { $id, analyticsId, refreshUrl, refreshFormUrl } = schema;
3194
- const schemaId = analyticsId != null ? analyticsId : $id;
3195
- return () => {
3196
- void onBehavior({
3197
- type: "refresh",
3198
- schemaId,
3199
- url: refreshUrl != null ? refreshUrl : refreshFormUrl
3200
- });
3201
- };
3202
- }
3203
- return void 0;
3204
- };
3205
- var getDebouncedPerformRefresh = (performRefresh, getValidationErrors) => {
3206
- if (!performRefresh) {
3207
- return void 0;
3208
- }
3209
- const performDebouncedRefresh = debounce(performRefresh, 1e3);
3210
- const debouncedFn = (prevValue, updatedValue) => {
3211
- if (isOrWasValid(getValidationErrors, prevValue, updatedValue) || (performDebouncedRefresh == null ? void 0 : performDebouncedRefresh.isPending())) {
3212
- performDebouncedRefresh == null ? void 0 : performDebouncedRefresh();
3213
- }
3214
- };
3215
- debouncedFn.flush = () => performDebouncedRefresh.flush();
3216
- debouncedFn.cancel = () => performDebouncedRefresh.cancel();
3217
- debouncedFn.isPending = () => performDebouncedRefresh.isPending();
3218
- return debouncedFn;
3219
- };
3220
-
3221
- // src/revamp/domain/features/validation/validation-functions.ts
3222
- var validateComponents = (components) => components.reduce((acc, component) => component.validate() && acc, true);
3223
- var getLocalValueValidator = (checks) => (currentValue) => checks.map((check) => check(currentValue)).filter(isString);
3224
-
3225
3119
  // src/revamp/domain/features/validationAsync/getComponentValidationAsync.ts
3226
3120
  var getComponentValidationAsync = (update, performValidationAsync) => (
3227
3121
  /**
@@ -3275,24 +3169,25 @@ var createNumberInputComponent = (numberInputProps, updateComponent) => {
3275
3169
  uid,
3276
3170
  id,
3277
3171
  checks,
3278
- performPersistAsync,
3279
- performRefresh,
3172
+ schemaOnChange,
3280
3173
  performValidationAsync,
3281
3174
  onValueChange,
3175
+ onPersistAsync,
3282
3176
  summariser
3283
3177
  } = _a, rest = __objRest(_a, [
3284
3178
  "uid",
3285
3179
  "id",
3286
3180
  "checks",
3287
- "performPersistAsync",
3288
- "performRefresh",
3181
+ "schemaOnChange",
3289
3182
  "performValidationAsync",
3290
3183
  "onValueChange",
3184
+ "onPersistAsync",
3291
3185
  "summariser"
3292
3186
  ]);
3293
3187
  const update = getInputUpdateFunction(updateComponent);
3294
3188
  const getValidationErrors = getLocalValueValidator(checks);
3295
- const performDebouncedRefresh = getDebouncedPerformRefresh(performRefresh, getValidationErrors);
3189
+ const performOnChange = getDebouncedSchemaOnChange(schemaOnChange, getValidationErrors);
3190
+ const validateAsync = performValidationAsync ? getDebouncedComponentValidationAsync(update, performValidationAsync) : void 0;
3296
3191
  const numberComponent = __spreadValues({
3297
3192
  type: "number",
3298
3193
  uid,
@@ -3301,8 +3196,12 @@ var createNumberInputComponent = (numberInputProps, updateComponent) => {
3301
3196
  update(this, updateFn);
3302
3197
  },
3303
3198
  onBlur() {
3304
- this.validate();
3305
- performDebouncedRefresh == null ? void 0 : performDebouncedRefresh.flush();
3199
+ const isValid = this.validate();
3200
+ performOnChange == null ? void 0 : performOnChange.flush();
3201
+ if (isValid) {
3202
+ onPersistAsync == null ? void 0 : onPersistAsync();
3203
+ validateAsync == null ? void 0 : validateAsync.flush();
3204
+ }
3306
3205
  },
3307
3206
  onFocus() {
3308
3207
  },
@@ -3314,7 +3213,11 @@ var createNumberInputComponent = (numberInputProps, updateComponent) => {
3314
3213
  draft.validationAsyncState.messages = {};
3315
3214
  draft.value = updatedValue;
3316
3215
  });
3317
- performDebouncedRefresh == null ? void 0 : performDebouncedRefresh(prevValue, updatedValue);
3216
+ performOnChange == null ? void 0 : performOnChange(prevValue, updatedValue);
3217
+ const isValid = getValidationErrors(updatedValue).length === 0;
3218
+ if (isValid) {
3219
+ validateAsync == null ? void 0 : validateAsync(this, updatedValue);
3220
+ }
3318
3221
  onValueChange();
3319
3222
  },
3320
3223
  async getSubmittableValue() {
@@ -3338,43 +3241,44 @@ var createNumberInputComponent = (numberInputProps, updateComponent) => {
3338
3241
  return errors.length === 0;
3339
3242
  }
3340
3243
  }, rest);
3341
- if (performRefresh) {
3342
- return numberComponent;
3343
- }
3344
- if (performPersistAsync) {
3345
- const persist = getComponentPersistAsync(update, performPersistAsync);
3346
- return __spreadProps(__spreadValues({}, numberComponent), {
3347
- onBlur() {
3348
- if (this.validate()) {
3349
- persist(this, this.getLocalValue()).catch(() => {
3350
- });
3351
- }
3352
- },
3353
- async getSubmittableValue() {
3354
- return persist(this, this.getLocalValue());
3355
- },
3356
- getSubmittableValueSync() {
3357
- return this.persistedState.lastResponse;
3358
- }
3359
- });
3244
+ return numberComponent;
3245
+ };
3246
+
3247
+ // src/revamp/domain/features/schema-on-change/getSchemaOnChange.ts
3248
+ var getSchemaOnChange = (schema, onBehavior) => {
3249
+ var _a, _b;
3250
+ const behavior = (_b = (_a = getBehaviorFromSchemaOnChange(schema)) != null ? _a : getBehaviorFromSchemaRefreshStepOnChange(schema)) != null ? _b : void 0;
3251
+ if (behavior) {
3252
+ const onChange = () => {
3253
+ void onBehavior(behavior);
3254
+ };
3255
+ onChange.behaviorType = behavior.type;
3256
+ return onChange;
3360
3257
  }
3361
- if (performValidationAsync) {
3362
- const validateAsync = getDebouncedComponentValidationAsync(update, performValidationAsync);
3363
- return __spreadProps(__spreadValues({}, numberComponent), {
3364
- onBlur() {
3365
- if (this.validate()) {
3366
- validateAsync.flush();
3367
- }
3368
- },
3369
- onChange(updatedValue) {
3370
- numberComponent.onChange.call(this, updatedValue);
3371
- if (getValidationErrors(updatedValue).length === 0) {
3372
- validateAsync(this, updatedValue);
3373
- }
3374
- }
3258
+ return void 0;
3259
+ };
3260
+ var getBehaviorFromSchemaOnChange = (schema) => {
3261
+ if ("onChange" in schema && schema.onChange) {
3262
+ const { $id, analyticsId, onChange } = schema;
3263
+ const behavior = __spreadProps(__spreadValues({}, normaliseBehavior(onChange, [])), {
3264
+ analytics: { schema: analyticsId != null ? analyticsId : $id }
3375
3265
  });
3266
+ return behavior;
3376
3267
  }
3377
- return numberComponent;
3268
+ return void 0;
3269
+ };
3270
+ var getBehaviorFromSchemaRefreshStepOnChange = (schema) => {
3271
+ var _a, _b;
3272
+ if ("refreshStepOnChange" in schema && ((_a = schema.refreshStepOnChange) != null ? _a : false) || "refreshFormOnChange" in schema && ((_b = schema.refreshFormOnChange) != null ? _b : false)) {
3273
+ const { $id, analyticsId, refreshUrl, refreshFormUrl } = schema;
3274
+ const behavior = {
3275
+ type: "refresh",
3276
+ analytics: { schema: analyticsId != null ? analyticsId : $id },
3277
+ url: refreshUrl != null ? refreshUrl : refreshFormUrl
3278
+ };
3279
+ return behavior;
3280
+ }
3281
+ return void 0;
3378
3282
  };
3379
3283
 
3380
3284
  // src/revamp/domain/features/validation/validateStringPattern.ts
@@ -3635,93 +3539,6 @@ var getAnalyticsFromErrorResponse = (json) => {
3635
3539
  return isObject(analytics) ? analytics : void 0;
3636
3540
  };
3637
3541
 
3638
- // src/revamp/domain/features/persistAsync/getPerformPersistAsync.ts
3639
- var getPerformPersistAsync = ({
3640
- genericErrorMessage,
3641
- httpClient,
3642
- persistAsyncConfig,
3643
- schemaId,
3644
- logEvent,
3645
- trackEvent
3646
- }) => {
3647
- const { idProperty, param, method, url } = persistAsyncConfig;
3648
- const trackFailure = (json) => {
3649
- const analytics = getAnalyticsFromErrorResponse(json);
3650
- trackEvent("PersistAsync Failed", __spreadValues({ schema: schemaId }, analytics));
3651
- };
3652
- return async function performPersistAsync({ value, signal }) {
3653
- let response;
3654
- let json;
3655
- try {
3656
- trackEvent("PersistAsync Triggered", { schema: schemaId });
3657
- response = await httpClient(
3658
- url,
3659
- constructPayload({ value, signal, requestConfig: { method, param } })
3660
- );
3661
- json = await response.json();
3662
- if (response.ok && isObject(json)) {
3663
- trackEvent("PersistAsync Succeeded", { schema: schemaId });
3664
- if (json[idProperty] === void 0) {
3665
- logEvent(
3666
- "error",
3667
- `Response from persist async did not contain expected property ${idProperty}.`
3668
- );
3669
- throw new Error(genericErrorMessage);
3670
- }
3671
- return json[idProperty];
3672
- }
3673
- } catch (e) {
3674
- trackFailure();
3675
- throw new Error(genericErrorMessage);
3676
- }
3677
- const validationError = !response.ok && isObject(json) ? getValidationError(param, json) : null;
3678
- trackFailure(json);
3679
- throw new Error(validationError != null ? validationError : genericErrorMessage);
3680
- };
3681
- };
3682
- var getValidationError = (param, response) => {
3683
- var _a;
3684
- const message = (_a = response.validation) == null ? void 0 : _a[param];
3685
- return isString(message) ? message : null;
3686
- };
3687
-
3688
- // src/revamp/domain/features/persistAsync/getInitialPersistedState.ts
3689
- var getInitialPersistedState = (lastSubmitted, model) => ({
3690
- abortController: new AbortController(),
3691
- lastSubmitted: !isNullish(model) ? lastSubmitted != null ? lastSubmitted : null : null,
3692
- lastResponse: model != null ? model : null,
3693
- submission: Promise.resolve(model != null ? model : null)
3694
- });
3695
-
3696
- // src/revamp/domain/mappers/schema/utils/getPersistAsyncInitialState.ts
3697
- var getPersistAsyncInitialState = (schemaMapperProps, mapperProps) => {
3698
- const { localValue, model } = schemaMapperProps;
3699
- const performPersistAsync = getPerformPersisAsyncFn(schemaMapperProps, mapperProps);
3700
- const persistedState = performPersistAsync ? getInitialPersistedState(localValue, model) : getInitialPersistedState();
3701
- return { performPersistAsync, persistedState };
3702
- };
3703
- var getPerformPersisAsyncFn = (schemaMapperProps, mapperProps) => {
3704
- const { schema, persistAsyncConfig } = schemaMapperProps;
3705
- const { trackEvent, logEvent } = mapperProps;
3706
- if (!persistAsyncConfig) {
3707
- return void 0;
3708
- }
3709
- const { $id, analyticsId } = schema;
3710
- const { getErrorMessageFunctions, httpClient } = mapperProps;
3711
- const validationMessages = schemaHasValidationMessages(schema) ? schema.validationMessages : void 0;
3712
- const errorMessageFunctions = getErrorMessageFunctions(validationMessages);
3713
- const persistAsyncError = errorMessageFunctions.genericError();
3714
- return getPerformPersistAsync({
3715
- genericErrorMessage: persistAsyncError,
3716
- httpClient,
3717
- logEvent,
3718
- persistAsyncConfig,
3719
- schemaId: analyticsId != null ? analyticsId : $id,
3720
- trackEvent
3721
- });
3722
- };
3723
- var schemaHasValidationMessages = (schema) => Boolean("validationMessages" in schema && schema.validationMessages);
3724
-
3725
3542
  // src/revamp/domain/features/validationAsync/getPerformValidationAsync.ts
3726
3543
  var getPerformValidationAsync = ({
3727
3544
  httpClient,
@@ -3838,7 +3655,7 @@ var summaryIfProvides = (summary, { value, icon, image }) => {
3838
3655
  // src/revamp/domain/mappers/schema/utils/mapCommonSchemaProps.ts
3839
3656
  var mapCommonSchemaProps = (schemaMapperProps) => {
3840
3657
  var _a;
3841
- const { uid, schemaId, schema, required, validationErrors } = schemaMapperProps;
3658
+ const { uid, schemaId, schema, required, validationErrors, onPersistAsync } = schemaMapperProps;
3842
3659
  const { $id, analyticsId, control, description, icon, image, keywords, title, hidden } = schema;
3843
3660
  return __spreadValues(__spreadValues(__spreadValues({
3844
3661
  uid,
@@ -3855,6 +3672,7 @@ var mapCommonSchemaProps = (schemaMapperProps) => {
3855
3672
  keywords,
3856
3673
  required: Boolean(required),
3857
3674
  title,
3675
+ onPersistAsync,
3858
3676
  summariser: getSummariser(schema)
3859
3677
  }, schemaHasHelp(schema) ? { help: schema.help.markdown } : {}), schemaHasPlaceholder(schema) ? { placeholder: schema.placeholder } : {}), schema.alert ? { alert: mapSchemaAlert(schema.alert) } : {});
3860
3678
  };
@@ -3864,21 +3682,17 @@ var schemaHasPlaceholder = (schema) => Boolean("placeholder" in schema && schema
3864
3682
 
3865
3683
  // src/revamp/domain/mappers/schema/numberSchemaToComponent.ts
3866
3684
  var numberSchemaToComponent = (schemaMapperProps, mapperProps) => {
3867
- const { schema, model, localValue, required = false } = schemaMapperProps;
3685
+ const { schema, model, localValue, required = false, onPersistAsync } = schemaMapperProps;
3868
3686
  const { autocompleteHint, validationMessages, default: defaultValue, maximum, minimum } = schema;
3869
3687
  const { getErrorMessageFunctions, updateComponent, onBehavior, onValueChange } = mapperProps;
3870
3688
  const errorMessageFunctions = getErrorMessageFunctions(validationMessages);
3871
- const { performPersistAsync, persistedState } = getPersistAsyncInitialState(
3872
- schemaMapperProps,
3873
- mapperProps
3874
- );
3875
3689
  const { performValidationAsync, validationAsyncState } = getValidationAsyncInitialState(
3876
3690
  schemaMapperProps,
3877
3691
  mapperProps
3878
3692
  );
3879
3693
  const validLocalValue = isNumber(localValue) ? localValue : null;
3880
3694
  const validModel = isNumber(model) ? model : defaultValue != null ? defaultValue : null;
3881
- const value = performPersistAsync ? validLocalValue : validModel;
3695
+ const value = onPersistAsync ? validLocalValue : validModel;
3882
3696
  return createNumberInputComponent(
3883
3697
  __spreadProps(__spreadValues({}, mapCommonSchemaProps(schemaMapperProps)), {
3884
3698
  autoComplete: getAutocompleteString(autocompleteHint),
@@ -3890,10 +3704,8 @@ var numberSchemaToComponent = (schemaMapperProps, mapperProps) => {
3890
3704
  value,
3891
3705
  maximum,
3892
3706
  minimum,
3893
- persistedState,
3894
3707
  validationAsyncState,
3895
- performPersistAsync,
3896
- performRefresh: getPerformRefresh(schema, onBehavior),
3708
+ schemaOnChange: getSchemaOnChange(schema, onBehavior),
3897
3709
  performValidationAsync,
3898
3710
  onValueChange
3899
3711
  }),
@@ -4170,13 +3982,58 @@ var localValueToJsonElement = (localValue) => {
4170
3982
  };
4171
3983
  var getRandomInt = () => Math.floor(Math.random() * 1e8);
4172
3984
 
4173
- // src/revamp/domain/components/utils/file-utils.ts
4174
- var toBase64 = async (file) => new Promise((resolve, reject) => {
4175
- const reader = new FileReader();
4176
- reader.addEventListener("load", () => resolve(reader.result));
4177
- reader.addEventListener("error", reject);
4178
- reader.readAsDataURL(file);
4179
- });
3985
+ // src/revamp/domain/features/persistAsync/getComponentMultiPersistAsync.ts
3986
+ var getComponentMultiPersistAsync = (update, performPersistAsync) => (
3987
+ /**
3988
+ * Will update the persistedState when a new request is made, and will update
3989
+ * the value or set errors when the request completes.
3990
+ */
3991
+ async (component, index, value) => {
3992
+ if (isNullish(value)) {
3993
+ throw new Error("Value must be a file or base64 string.");
3994
+ }
3995
+ const newAbortController = new AbortController();
3996
+ const { signal } = newAbortController;
3997
+ const newSubmission = performPersistAsync({ value, signal }).then((newValue) => {
3998
+ update(component, (draft) => {
3999
+ draft.persistedState[index].lastResponse = newValue;
4000
+ });
4001
+ return newValue;
4002
+ }).catch((error) => {
4003
+ update(component, (draft) => {
4004
+ draft.persistedState = [
4005
+ ...draft.persistedState.slice(0, index),
4006
+ ...draft.persistedState.slice(index + 1)
4007
+ ];
4008
+ draft.value.splice(index, 1);
4009
+ draft.files.splice(index, 1);
4010
+ });
4011
+ throw error;
4012
+ });
4013
+ update(component, (draft) => {
4014
+ draft.persistedState = [
4015
+ ...draft.persistedState.slice(0, index),
4016
+ {
4017
+ id: getRandomId(),
4018
+ abortController: newAbortController,
4019
+ lastResponse: null,
4020
+ lastSubmitted: null,
4021
+ submission: newSubmission
4022
+ },
4023
+ ...draft.persistedState.slice(index)
4024
+ ];
4025
+ });
4026
+ return newSubmission;
4027
+ }
4028
+ );
4029
+
4030
+ // src/revamp/domain/components/utils/file-utils.ts
4031
+ var toBase64 = async (file) => new Promise((resolve, reject) => {
4032
+ const reader = new FileReader();
4033
+ reader.addEventListener("load", () => resolve(reader.result));
4034
+ reader.addEventListener("error", reject);
4035
+ reader.readAsDataURL(file);
4036
+ });
4180
4037
  var base64dataUrltoFile = (dataurl, filename) => {
4181
4038
  if (!isBase64DataUrl(dataurl)) {
4182
4039
  return null;
@@ -4298,6 +4155,82 @@ var createMultiUploadInputComponent = (uploadInputProps, updateComponent) => {
4298
4155
  });
4299
4156
  };
4300
4157
 
4158
+ // src/revamp/domain/features/persistAsync/getInitialPersistedState.ts
4159
+ var getInitialPersistedState = (lastSubmitted, model) => ({
4160
+ abortController: new AbortController(),
4161
+ lastSubmitted: !isNullish(model) ? lastSubmitted != null ? lastSubmitted : null : null,
4162
+ lastResponse: model != null ? model : null,
4163
+ submission: Promise.resolve(model != null ? model : null)
4164
+ });
4165
+
4166
+ // src/revamp/domain/features/persistAsync/getPerformPersistAsync.ts
4167
+ var getPerformPersistAsync = ({
4168
+ genericErrorMessage,
4169
+ httpClient,
4170
+ persistAsyncConfig,
4171
+ schemaId,
4172
+ logEvent,
4173
+ trackEvent
4174
+ }) => {
4175
+ const { idProperty, param, method, url } = persistAsyncConfig;
4176
+ const trackFailure = (json) => {
4177
+ const analytics = getAnalyticsFromErrorResponse(json);
4178
+ trackEvent("PersistAsync Failed", __spreadValues({ schema: schemaId }, analytics));
4179
+ };
4180
+ return async function performPersistAsync({ value, signal }) {
4181
+ let response;
4182
+ let json;
4183
+ try {
4184
+ trackEvent("PersistAsync Triggered", { schema: schemaId });
4185
+ response = await httpClient(
4186
+ url,
4187
+ constructPayload({ value, signal, requestConfig: { method, param } })
4188
+ );
4189
+ json = await response.json();
4190
+ if (response.ok && isObject(json)) {
4191
+ trackEvent("PersistAsync Succeeded", { schema: schemaId });
4192
+ if (json[idProperty] === void 0) {
4193
+ logEvent(
4194
+ "error",
4195
+ `Response from persist async did not contain expected property ${idProperty}.`
4196
+ );
4197
+ throw new Error(genericErrorMessage);
4198
+ }
4199
+ return json[idProperty];
4200
+ }
4201
+ } catch (e) {
4202
+ trackFailure();
4203
+ throw new Error(genericErrorMessage);
4204
+ }
4205
+ const validationError = !response.ok && isObject(json) ? getValidationError(param, json) : null;
4206
+ trackFailure(json);
4207
+ throw new Error(validationError != null ? validationError : genericErrorMessage);
4208
+ };
4209
+ };
4210
+ var getValidationError = (param, response) => {
4211
+ var _a;
4212
+ const message = (_a = response.validation) == null ? void 0 : _a[param];
4213
+ return isString(message) ? message : null;
4214
+ };
4215
+
4216
+ // src/revamp/domain/mappers/schema/utils/getPerformPersistAsyncFn.ts
4217
+ var getPerformPersistAsyncFn = (schema, persistAsyncConfig, mapperProps) => {
4218
+ const { getErrorMessageFunctions, httpClient, trackEvent, logEvent } = mapperProps;
4219
+ const { $id, analyticsId } = schema;
4220
+ const validationMessages = schemaHasValidationMessages(schema) ? schema.validationMessages : void 0;
4221
+ const errorMessageFunctions = getErrorMessageFunctions(validationMessages);
4222
+ const persistAsyncError = errorMessageFunctions.genericError();
4223
+ return getPerformPersistAsync({
4224
+ genericErrorMessage: persistAsyncError,
4225
+ httpClient,
4226
+ logEvent,
4227
+ persistAsyncConfig,
4228
+ schemaId: analyticsId != null ? analyticsId : $id,
4229
+ trackEvent
4230
+ });
4231
+ };
4232
+ var schemaHasValidationMessages = (schema) => Boolean("validationMessages" in schema && schema.validationMessages);
4233
+
4301
4234
  // src/revamp/domain/mappers/schema/arraySchemaToComponent/arraySchemaToMultiUploadComponent.ts
4302
4235
  var arraySchemaToMultiUploadComponent = (schemaMapperProps, mapperProps) => {
4303
4236
  var _a;
@@ -4324,7 +4257,7 @@ var arraySchemaToMultiUploadComponent = (schemaMapperProps, mapperProps) => {
4324
4257
  schema: __spreadProps(__spreadValues({}, uploadSchema), { hidden: (_a = schema.hidden) != null ? _a : uploadSchema.hidden, alert: schema.alert })
4325
4258
  });
4326
4259
  const { onValueChange } = mapperProps;
4327
- const { performPersistAsync } = getPersistAsyncInitialState(combinedSchemaProps, mapperProps);
4260
+ const performPersistAsync = persistAsyncConfig ? getPerformPersistAsyncFn(combinedSchemaProps.schema, persistAsyncConfig, mapperProps) : void 0;
4328
4261
  const value = performPersistAsync ? getValueForPersistAsync(localValue) : [];
4329
4262
  const persistedState = performPersistAsync && isArray(model) ? model.map((itemModel) => getInitialPersistedState(null, itemModel)) : [];
4330
4263
  return createMultiUploadInputComponent(
@@ -4380,7 +4313,7 @@ var createMultiSelectComponent = (multiSelectProps, updateComponent) => {
4380
4313
  options,
4381
4314
  initialValue,
4382
4315
  performValidationAsync,
4383
- performRefresh,
4316
+ schemaOnChange,
4384
4317
  onValueChange
4385
4318
  } = _a, rest = __objRest(_a, [
4386
4319
  "uid",
@@ -4388,13 +4321,14 @@ var createMultiSelectComponent = (multiSelectProps, updateComponent) => {
4388
4321
  "options",
4389
4322
  "initialValue",
4390
4323
  "performValidationAsync",
4391
- "performRefresh",
4324
+ "schemaOnChange",
4392
4325
  "onValueChange"
4393
4326
  ]);
4394
4327
  const update = getInputUpdateFunction(updateComponent);
4395
4328
  const children = options.map((option) => option.component);
4396
4329
  const selectedIndices = getInitialModelIndices(initialValue, children);
4397
4330
  const getValidationErrors = getLocalValueValidator(checks);
4331
+ const validateAsync = performValidationAsync ? getComponentValidationAsync(update, performValidationAsync) : void 0;
4398
4332
  const component = __spreadProps(__spreadValues({
4399
4333
  uid,
4400
4334
  type: "multi-select",
@@ -4411,12 +4345,16 @@ var createMultiSelectComponent = (multiSelectProps, updateComponent) => {
4411
4345
  draft.selectedIndices = indices;
4412
4346
  draft.errors = [];
4413
4347
  });
4414
- performRefresh == null ? void 0 : performRefresh();
4415
- onValueChange();
4348
+ schemaOnChange == null ? void 0 : schemaOnChange();
4416
4349
  const errors = getValidationErrors(this.getLocalValue());
4417
4350
  this._update((draft) => {
4418
4351
  draft.errors = errors;
4419
4352
  });
4353
+ if (this.validate()) {
4354
+ validateAsync == null ? void 0 : validateAsync(this, this.getLocalValue()).catch(() => {
4355
+ });
4356
+ }
4357
+ onValueChange();
4420
4358
  },
4421
4359
  onBlur() {
4422
4360
  },
@@ -4454,21 +4392,6 @@ var createMultiSelectComponent = (multiSelectProps, updateComponent) => {
4454
4392
  return this.selectedIndices.map((i) => this.children[i]);
4455
4393
  }
4456
4394
  });
4457
- if (performRefresh) {
4458
- return component;
4459
- }
4460
- if (performValidationAsync) {
4461
- const validateAsync = getComponentValidationAsync(update, performValidationAsync);
4462
- return __spreadProps(__spreadValues({}, component), {
4463
- onSelect(indices) {
4464
- component.onSelect.call(this, indices);
4465
- if (this.validate()) {
4466
- validateAsync(this, this.getLocalValue()).catch(() => {
4467
- });
4468
- }
4469
- }
4470
- });
4471
- }
4472
4395
  return component;
4473
4396
  };
4474
4397
  var getInitialModelIndices = (model, options) => {
@@ -4535,7 +4458,7 @@ var arraySchemaToMultiSelectComponent = (schemaMapperProps, mapperProps) => {
4535
4458
  title,
4536
4459
  validationAsyncState,
4537
4460
  performValidationAsync,
4538
- performRefresh: getPerformRefresh(schema, onBehavior),
4461
+ schemaOnChange: getSchemaOnChange(schema, onBehavior),
4539
4462
  onValueChange
4540
4463
  }),
4541
4464
  updateComponent
@@ -4655,9 +4578,9 @@ var createUploadInputComponent = (uploadInputProps, updateComponent) => {
4655
4578
  checks,
4656
4579
  format,
4657
4580
  value,
4658
- performPersistAsync,
4659
- performRefresh,
4581
+ schemaOnChange,
4660
4582
  onValueChange,
4583
+ onPersistAsync,
4661
4584
  summariser
4662
4585
  } = _a, rest = __objRest(_a, [
4663
4586
  "uid",
@@ -4665,9 +4588,9 @@ var createUploadInputComponent = (uploadInputProps, updateComponent) => {
4665
4588
  "checks",
4666
4589
  "format",
4667
4590
  "value",
4668
- "performPersistAsync",
4669
- "performRefresh",
4591
+ "schemaOnChange",
4670
4592
  "onValueChange",
4593
+ "onPersistAsync",
4671
4594
  "summariser"
4672
4595
  ]);
4673
4596
  const update = getInputUpdateFunction(updateComponent);
@@ -4676,7 +4599,7 @@ var createUploadInputComponent = (uploadInputProps, updateComponent) => {
4676
4599
  type: "upload",
4677
4600
  uid,
4678
4601
  id,
4679
- format: "base64",
4602
+ format,
4680
4603
  value,
4681
4604
  _update(updateFn) {
4682
4605
  update(this, updateFn);
@@ -4692,12 +4615,16 @@ var createUploadInputComponent = (uploadInputProps, updateComponent) => {
4692
4615
  draft.errors = [];
4693
4616
  draft.value = updatedValue;
4694
4617
  });
4695
- performRefresh == null ? void 0 : performRefresh();
4618
+ schemaOnChange == null ? void 0 : schemaOnChange();
4696
4619
  onValueChange();
4620
+ onPersistAsync == null ? void 0 : onPersistAsync();
4697
4621
  },
4698
4622
  async getSubmittableValue() {
4699
4623
  const file = this.getLocalValue();
4700
- return file ? toBase64(file) : null;
4624
+ if (this.format === "base64" && file) {
4625
+ return toBase64(file);
4626
+ }
4627
+ return null;
4701
4628
  },
4702
4629
  getSubmittableValueSync() {
4703
4630
  return null;
@@ -4717,50 +4644,17 @@ var createUploadInputComponent = (uploadInputProps, updateComponent) => {
4717
4644
  return errors.length === 0;
4718
4645
  }
4719
4646
  }, rest);
4720
- if (!performPersistAsync) {
4721
- return uploadComponent;
4722
- }
4723
- const persist = getComponentPersistAsync(update, performPersistAsync);
4724
- return __spreadProps(__spreadValues({}, uploadComponent), {
4725
- format,
4726
- async onUpload(file) {
4727
- this._update((draft) => {
4728
- draft.errors = [];
4729
- draft.value = file;
4730
- });
4731
- onValueChange();
4732
- const submission = format === "base64" && file ? await toBase64(file) : file;
4733
- await persist(this, submission).catch((error) => {
4734
- this._update((draft) => {
4735
- draft.persistedState.lastResponse = null;
4736
- draft.persistedState.lastSubmitted = null;
4737
- draft.persistedState.submission = Promise.resolve(null);
4738
- draft.errors = [];
4739
- draft.value = null;
4740
- });
4741
- throw error;
4742
- });
4743
- onValueChange();
4744
- },
4745
- async getSubmittableValue() {
4746
- return this.persistedState.submission;
4747
- },
4748
- getSubmittableValueSync() {
4749
- return this.persistedState.lastResponse;
4750
- }
4751
- });
4647
+ return uploadComponent;
4752
4648
  };
4753
4649
 
4754
4650
  // src/revamp/domain/mappers/schema/blobSchemaToComponent.ts
4755
4651
  var blobSchemaToComponent = (schemaMapperProps, mapperProps) => {
4756
- const { schema, localValue, model, required = false } = schemaMapperProps;
4652
+ const { schema, localValue, required = false, onPersistAsync } = schemaMapperProps;
4757
4653
  const { accepts, cameraConfig, maxSize, source, validationMessages } = schema;
4758
4654
  const { getErrorMessageFunctions, updateComponent, onValueChange } = mapperProps;
4759
4655
  const errorMessageFunctions = getErrorMessageFunctions(validationMessages);
4760
- const { performPersistAsync } = getPersistAsyncInitialState(schemaMapperProps, mapperProps);
4761
- const persistedState = performPersistAsync ? getInitialPersistedState(null, model) : getInitialPersistedState();
4762
4656
  const validLocalValue = isFile(localValue) ? localValue : null;
4763
- const value = performPersistAsync ? validLocalValue : null;
4657
+ const value = onPersistAsync ? validLocalValue : null;
4764
4658
  return createUploadInputComponent(
4765
4659
  __spreadProps(__spreadValues({}, mapCommonSchemaProps(schemaMapperProps)), {
4766
4660
  accepts,
@@ -4770,9 +4664,8 @@ var blobSchemaToComponent = (schemaMapperProps, mapperProps) => {
4770
4664
  maxSize,
4771
4665
  source,
4772
4666
  value,
4773
- persistedState,
4774
- performPersistAsync,
4775
4667
  checks: schema.hidden ? [] : [getRequiredCheck(required, errorMessageFunctions)],
4668
+ schemaOnChange: void 0,
4776
4669
  onValueChange
4777
4670
  }),
4778
4671
  updateComponent
@@ -4785,22 +4678,23 @@ var createBooleanInputComponent = (booleanInputProps, updateComponent) => {
4785
4678
  uid,
4786
4679
  id,
4787
4680
  value,
4788
- performPersistAsync,
4789
- performRefresh,
4681
+ schemaOnChange,
4790
4682
  performValidationAsync,
4791
4683
  onValueChange,
4684
+ onPersistAsync,
4792
4685
  summariser
4793
4686
  } = _a, rest = __objRest(_a, [
4794
4687
  "uid",
4795
4688
  "id",
4796
4689
  "value",
4797
- "performPersistAsync",
4798
- "performRefresh",
4690
+ "schemaOnChange",
4799
4691
  "performValidationAsync",
4800
4692
  "onValueChange",
4693
+ "onPersistAsync",
4801
4694
  "summariser"
4802
4695
  ]);
4803
4696
  const update = getInputUpdateFunction(updateComponent);
4697
+ const validateAsync = performValidationAsync ? getComponentValidationAsync(update, performValidationAsync) : void 0;
4804
4698
  const booleanComponent = __spreadValues({
4805
4699
  type: "boolean",
4806
4700
  uid,
@@ -4821,7 +4715,10 @@ var createBooleanInputComponent = (booleanInputProps, updateComponent) => {
4821
4715
  draft.errors = [];
4822
4716
  draft.value = updatedValue;
4823
4717
  });
4824
- performRefresh == null ? void 0 : performRefresh();
4718
+ schemaOnChange == null ? void 0 : schemaOnChange();
4719
+ onPersistAsync == null ? void 0 : onPersistAsync();
4720
+ validateAsync == null ? void 0 : validateAsync(this, this.getLocalValue()).catch(() => {
4721
+ });
4825
4722
  onValueChange();
4826
4723
  },
4827
4724
  async getSubmittableValue() {
@@ -4838,62 +4735,27 @@ var createBooleanInputComponent = (booleanInputProps, updateComponent) => {
4838
4735
  },
4839
4736
  validate: () => true
4840
4737
  }, rest);
4841
- if (performRefresh) {
4842
- return booleanComponent;
4843
- }
4844
- if (performPersistAsync) {
4845
- const persist = getComponentPersistAsync(update, performPersistAsync);
4846
- return __spreadProps(__spreadValues({}, booleanComponent), {
4847
- onChange(updatedValue) {
4848
- booleanComponent.onChange.call(this, updatedValue);
4849
- persist(this, this.getLocalValue()).catch(() => {
4850
- });
4851
- },
4852
- async getSubmittableValue() {
4853
- return persist(this, this.getLocalValue());
4854
- },
4855
- getSubmittableValueSync() {
4856
- return this.persistedState.lastResponse;
4857
- }
4858
- });
4859
- }
4860
- if (performValidationAsync) {
4861
- const validateAsync = getComponentValidationAsync(update, performValidationAsync);
4862
- return __spreadProps(__spreadValues({}, booleanComponent), {
4863
- onChange(updatedValue) {
4864
- booleanComponent.onChange.call(this, updatedValue);
4865
- validateAsync(this, this.getLocalValue()).catch(() => {
4866
- });
4867
- }
4868
- });
4869
- }
4870
4738
  return booleanComponent;
4871
4739
  };
4872
4740
 
4873
4741
  // src/revamp/domain/mappers/schema/booleanSchemaToComponent.ts
4874
4742
  var booleanSchemaToComponent = (schemaMapperProps, mapperProps) => {
4875
- const { schema, localValue, model } = schemaMapperProps;
4743
+ const { schema, localValue, model, onPersistAsync } = schemaMapperProps;
4876
4744
  const { default: defaultValue } = schema;
4877
4745
  const { updateComponent, onBehavior, onValueChange } = mapperProps;
4878
- const performRefresh = getPerformRefresh(schema, onBehavior);
4879
- const { performPersistAsync, persistedState } = getPersistAsyncInitialState(
4880
- schemaMapperProps,
4881
- mapperProps
4882
- );
4746
+ const schemaOnChange = getSchemaOnChange(schema, onBehavior);
4883
4747
  const { performValidationAsync, validationAsyncState } = getValidationAsyncInitialState(
4884
4748
  schemaMapperProps,
4885
4749
  mapperProps
4886
4750
  );
4887
4751
  const validLocalValue = isBoolean(localValue) ? localValue : false;
4888
4752
  const validModel = getValidModel(model, defaultValue);
4889
- const value = performPersistAsync ? validLocalValue : validModel;
4753
+ const value = onPersistAsync ? validLocalValue : validModel;
4890
4754
  return createBooleanInputComponent(
4891
4755
  __spreadProps(__spreadValues({}, mapCommonSchemaProps(schemaMapperProps)), {
4892
4756
  value: value != null ? value : false,
4893
- persistedState,
4894
4757
  validationAsyncState,
4895
- performPersistAsync,
4896
- performRefresh,
4758
+ schemaOnChange,
4897
4759
  performValidationAsync,
4898
4760
  onValueChange
4899
4761
  }),
@@ -4949,25 +4811,26 @@ var createIntegerInputComponent = (integerInputProps, updateComponent) => {
4949
4811
  id,
4950
4812
  checks,
4951
4813
  value,
4952
- performPersistAsync,
4953
- performRefresh,
4814
+ schemaOnChange,
4954
4815
  performValidationAsync,
4955
4816
  onValueChange,
4817
+ onPersistAsync,
4956
4818
  summariser
4957
4819
  } = _a, rest = __objRest(_a, [
4958
4820
  "uid",
4959
4821
  "id",
4960
4822
  "checks",
4961
4823
  "value",
4962
- "performPersistAsync",
4963
- "performRefresh",
4824
+ "schemaOnChange",
4964
4825
  "performValidationAsync",
4965
4826
  "onValueChange",
4827
+ "onPersistAsync",
4966
4828
  "summariser"
4967
4829
  ]);
4968
4830
  const update = getInputUpdateFunction(updateComponent);
4969
4831
  const getValidationErrors = getLocalValueValidator(checks);
4970
- const performDebouncedRefresh = getDebouncedPerformRefresh(performRefresh, getValidationErrors);
4832
+ const performOnChange = getDebouncedSchemaOnChange(schemaOnChange, getValidationErrors);
4833
+ const validateAsync = performValidationAsync ? getDebouncedComponentValidationAsync(update, performValidationAsync) : void 0;
4971
4834
  const integerComponent = __spreadValues({
4972
4835
  type: "integer",
4973
4836
  uid,
@@ -4977,8 +4840,12 @@ var createIntegerInputComponent = (integerInputProps, updateComponent) => {
4977
4840
  update(this, updateFn);
4978
4841
  },
4979
4842
  onBlur() {
4980
- this.validate();
4981
- performDebouncedRefresh == null ? void 0 : performDebouncedRefresh.flush();
4843
+ const isValid = this.validate();
4844
+ performOnChange == null ? void 0 : performOnChange.flush();
4845
+ if (isValid) {
4846
+ onPersistAsync == null ? void 0 : onPersistAsync();
4847
+ validateAsync == null ? void 0 : validateAsync.flush();
4848
+ }
4982
4849
  },
4983
4850
  onFocus() {
4984
4851
  },
@@ -4990,7 +4857,11 @@ var createIntegerInputComponent = (integerInputProps, updateComponent) => {
4990
4857
  draft.validationAsyncState.messages = {};
4991
4858
  draft.value = updatedValue;
4992
4859
  });
4993
- performDebouncedRefresh == null ? void 0 : performDebouncedRefresh(prevValue, updatedValue);
4860
+ performOnChange == null ? void 0 : performOnChange(prevValue, updatedValue);
4861
+ const isValid = getValidationErrors(updatedValue).length === 0;
4862
+ if (isValid) {
4863
+ validateAsync == null ? void 0 : validateAsync(this, updatedValue);
4864
+ }
4994
4865
  onValueChange();
4995
4866
  },
4996
4867
  async getSubmittableValue() {
@@ -5014,62 +4885,22 @@ var createIntegerInputComponent = (integerInputProps, updateComponent) => {
5014
4885
  return errors.length === 0;
5015
4886
  }
5016
4887
  }, rest);
5017
- if (performRefresh) {
5018
- return integerComponent;
5019
- }
5020
- if (performPersistAsync) {
5021
- const persist = getComponentPersistAsync(update, performPersistAsync);
5022
- return __spreadProps(__spreadValues({}, integerComponent), {
5023
- onBlur() {
5024
- if (this.validate()) {
5025
- persist(this, this.getLocalValue()).catch(() => {
5026
- });
5027
- }
5028
- },
5029
- async getSubmittableValue() {
5030
- return persist(this, this.getLocalValue());
5031
- },
5032
- getSubmittableValueSync() {
5033
- return this.persistedState.lastResponse;
5034
- }
5035
- });
5036
- }
5037
- if (performValidationAsync) {
5038
- const validateAsync = getDebouncedComponentValidationAsync(update, performValidationAsync);
5039
- return __spreadProps(__spreadValues({}, integerComponent), {
5040
- onBlur() {
5041
- if (this.validate()) {
5042
- validateAsync.flush();
5043
- }
5044
- },
5045
- onChange(updatedValue) {
5046
- integerComponent.onChange.call(this, updatedValue);
5047
- if (getValidationErrors(updatedValue).length === 0) {
5048
- validateAsync(this, updatedValue);
5049
- }
5050
- }
5051
- });
5052
- }
5053
4888
  return integerComponent;
5054
4889
  };
5055
4890
 
5056
4891
  // src/revamp/domain/mappers/schema/integerSchemaToComponent.ts
5057
4892
  var integerSchemaToComponent = (schemaMapperProps, mapperProps) => {
5058
- const { schema, localValue, model, required = false } = schemaMapperProps;
4893
+ const { schema, localValue, model, required = false, onPersistAsync } = schemaMapperProps;
5059
4894
  const { autocompleteHint, validationMessages, default: defaultValue, maximum, minimum } = schema;
5060
4895
  const { getErrorMessageFunctions, updateComponent, onBehavior, onValueChange } = mapperProps;
5061
4896
  const errorMessageFunctions = getErrorMessageFunctions(validationMessages);
5062
- const { performPersistAsync, persistedState } = getPersistAsyncInitialState(
5063
- schemaMapperProps,
5064
- mapperProps
5065
- );
5066
4897
  const { performValidationAsync, validationAsyncState } = getValidationAsyncInitialState(
5067
4898
  schemaMapperProps,
5068
4899
  mapperProps
5069
4900
  );
5070
4901
  const validLocalValue = isInteger(localValue) ? localValue : null;
5071
4902
  const validModel = isInteger(model) ? model : defaultValue != null ? defaultValue : null;
5072
- const value = performPersistAsync ? validLocalValue : validModel;
4903
+ const value = onPersistAsync ? validLocalValue : validModel;
5073
4904
  const checks = [
5074
4905
  getRequiredCheck(required, errorMessageFunctions),
5075
4906
  getBelowMinimumCheck(schema, errorMessageFunctions),
@@ -5081,11 +4912,9 @@ var integerSchemaToComponent = (schemaMapperProps, mapperProps) => {
5081
4912
  checks,
5082
4913
  maximum,
5083
4914
  minimum,
5084
- persistedState,
5085
4915
  value,
5086
4916
  validationAsyncState,
5087
- performPersistAsync,
5088
- performRefresh: getPerformRefresh(schema, onBehavior),
4917
+ schemaOnChange: getSchemaOnChange(schema, onBehavior),
5089
4918
  performValidationAsync,
5090
4919
  onValueChange
5091
4920
  }),
@@ -5240,7 +5069,7 @@ var nonNullishKeys = (model) => Object.keys(model).filter((key) => !isNullish(mo
5240
5069
 
5241
5070
  // src/revamp/domain/components/SelectInputComponent.ts
5242
5071
  var createSelectInputComponent = (selectProps, updateComponent) => {
5243
- const _a = selectProps, { uid, checks, initialModel, options, performRefresh, onValueChange, summariser } = _a, rest = __objRest(_a, ["uid", "checks", "initialModel", "options", "performRefresh", "onValueChange", "summariser"]);
5072
+ const _a = selectProps, { uid, checks, initialModel, options, schemaOnChange, onValueChange, summariser } = _a, rest = __objRest(_a, ["uid", "checks", "initialModel", "options", "schemaOnChange", "onValueChange", "summariser"]);
5244
5073
  const children = options.map((option) => option.component);
5245
5074
  const matchingOptions = options.map(
5246
5075
  (option) => isPartialModelMatch(option.component.getSubmittableValueSync(), initialModel)
@@ -5301,7 +5130,7 @@ var createSelectInputComponent = (selectProps, updateComponent) => {
5301
5130
  draft.errors = [];
5302
5131
  draft.selectedIndex = updatedIndex;
5303
5132
  });
5304
- performRefresh == null ? void 0 : performRefresh();
5133
+ schemaOnChange == null ? void 0 : schemaOnChange();
5305
5134
  onValueChange();
5306
5135
  },
5307
5136
  validate() {
@@ -5373,7 +5202,7 @@ var oneOfSchemaToComponent = (schemaMapperProps, mapperProps) => {
5373
5202
  checks: schema.hidden ? [] : [getRequiredCheck(required, errorMessageFunctions)],
5374
5203
  options,
5375
5204
  initialModel,
5376
- performRefresh: getPerformRefresh(schema, onBehavior),
5205
+ schemaOnChange: getSchemaOnChange(schema, onBehavior),
5377
5206
  onValueChange,
5378
5207
  trackEvent
5379
5208
  }),
@@ -5392,25 +5221,26 @@ var createDateInputComponent = (textInputProps, updateComponent) => {
5392
5221
  uid,
5393
5222
  id,
5394
5223
  checks,
5395
- performPersistAsync,
5396
- performRefresh,
5224
+ schemaOnChange,
5397
5225
  performValidationAsync,
5398
5226
  onValueChange,
5227
+ onPersistAsync,
5399
5228
  summariser,
5400
5229
  value
5401
5230
  } = _a, rest = __objRest(_a, [
5402
5231
  "uid",
5403
5232
  "id",
5404
5233
  "checks",
5405
- "performPersistAsync",
5406
- "performRefresh",
5234
+ "schemaOnChange",
5407
5235
  "performValidationAsync",
5408
5236
  "onValueChange",
5237
+ "onPersistAsync",
5409
5238
  "summariser",
5410
5239
  "value"
5411
5240
  ]);
5412
5241
  const update = getInputUpdateFunction(updateComponent);
5413
5242
  const getValidationErrors = getLocalValueValidator(checks);
5243
+ const validateAsync = performValidationAsync ? getComponentValidationAsync(update, performValidationAsync) : void 0;
5414
5244
  const dateInputComponent = __spreadValues({
5415
5245
  type: "date",
5416
5246
  uid,
@@ -5420,7 +5250,11 @@ var createDateInputComponent = (textInputProps, updateComponent) => {
5420
5250
  update(this, updateFn);
5421
5251
  },
5422
5252
  onBlur() {
5423
- this.validate();
5253
+ const isValid = this.validate();
5254
+ if (isValid) {
5255
+ validateAsync == null ? void 0 : validateAsync(this, this.getLocalValue()).catch(() => {
5256
+ });
5257
+ }
5424
5258
  },
5425
5259
  onFocus() {
5426
5260
  },
@@ -5433,9 +5267,12 @@ var createDateInputComponent = (textInputProps, updateComponent) => {
5433
5267
  draft.value = updatedValue;
5434
5268
  });
5435
5269
  if (isOrWasValid(getValidationErrors, prevValue, updatedValue)) {
5436
- performRefresh == null ? void 0 : performRefresh();
5270
+ schemaOnChange == null ? void 0 : schemaOnChange();
5437
5271
  }
5438
5272
  onValueChange();
5273
+ if (getValidationErrors(updatedValue).length === 0) {
5274
+ onPersistAsync == null ? void 0 : onPersistAsync();
5275
+ }
5439
5276
  },
5440
5277
  async getSubmittableValue() {
5441
5278
  return this.getSubmittableValueSync();
@@ -5458,45 +5295,12 @@ var createDateInputComponent = (textInputProps, updateComponent) => {
5458
5295
  return errors.length === 0;
5459
5296
  }
5460
5297
  }, rest);
5461
- if (performRefresh) {
5462
- return dateInputComponent;
5463
- }
5464
- if (performPersistAsync) {
5465
- const persist = getComponentPersistAsync(update, performPersistAsync);
5466
- return __spreadProps(__spreadValues({}, dateInputComponent), {
5467
- onChange(updatedValue) {
5468
- dateInputComponent.onChange.call(this, updatedValue);
5469
- const isValid = getValidationErrors(updatedValue).length === 0;
5470
- if (isValid) {
5471
- persist(this, this.getLocalValue()).catch(() => {
5472
- });
5473
- }
5474
- },
5475
- async getSubmittableValue() {
5476
- return persist(this, this.getLocalValue());
5477
- },
5478
- getSubmittableValueSync() {
5479
- return this.persistedState.lastResponse;
5480
- }
5481
- });
5482
- }
5483
- if (performValidationAsync) {
5484
- const validateAsync = getComponentValidationAsync(update, performValidationAsync);
5485
- return __spreadProps(__spreadValues({}, dateInputComponent), {
5486
- onBlur() {
5487
- if (this.validate()) {
5488
- validateAsync(this, this.getLocalValue()).catch(() => {
5489
- });
5490
- }
5491
- }
5492
- });
5493
- }
5494
5298
  return dateInputComponent;
5495
5299
  };
5496
5300
 
5497
5301
  // src/revamp/domain/mappers/schema/stringSchemaToComponent/stringSchemaToDateInputComponent.ts
5498
5302
  var stringSchemaToDateInputComponent = (schemaMapperProps, mapperProps) => {
5499
- const { schema, localValue, model, required = false } = schemaMapperProps;
5303
+ const { schema, localValue, model, required = false, onPersistAsync } = schemaMapperProps;
5500
5304
  const {
5501
5305
  autocompleteHint,
5502
5306
  default: defaultValue,
@@ -5506,17 +5310,13 @@ var stringSchemaToDateInputComponent = (schemaMapperProps, mapperProps) => {
5506
5310
  } = schema;
5507
5311
  const { getErrorMessageFunctions, updateComponent, onBehavior, onValueChange } = mapperProps;
5508
5312
  const errorMessageFunctions = getErrorMessageFunctions(schema.validationMessages);
5509
- const { performPersistAsync, persistedState } = getPersistAsyncInitialState(
5510
- schemaMapperProps,
5511
- mapperProps
5512
- );
5513
5313
  const { performValidationAsync, validationAsyncState } = getValidationAsyncInitialState(
5514
5314
  schemaMapperProps,
5515
5315
  mapperProps
5516
5316
  );
5517
5317
  const validLocalValue = isString(localValue) ? localValue : null;
5518
5318
  const validModel = isString(model) ? model : defaultValue != null ? defaultValue : null;
5519
- const value = performPersistAsync ? validLocalValue : validModel;
5319
+ const value = onPersistAsync ? validLocalValue : validModel;
5520
5320
  return createDateInputComponent(
5521
5321
  __spreadProps(__spreadValues({}, mapCommonSchemaProps(schemaMapperProps)), {
5522
5322
  autoComplete: getAutocompleteString(autocompleteHint),
@@ -5533,10 +5333,8 @@ var stringSchemaToDateInputComponent = (schemaMapperProps, mapperProps) => {
5533
5333
  }))
5534
5334
  } : void 0,
5535
5335
  value,
5536
- persistedState,
5537
5336
  validationAsyncState,
5538
- performPersistAsync,
5539
- performRefresh: getPerformRefresh(schema, onBehavior),
5337
+ schemaOnChange: getSchemaOnChange(schema, onBehavior),
5540
5338
  performValidationAsync,
5541
5339
  onValueChange
5542
5340
  }),
@@ -5551,8 +5349,6 @@ var stringSchemaToUploadInputComponent = (schemaMapperProps, mapperProps) => {
5551
5349
  const { accepts, autocompleteHint, cameraConfig, hidden, maxSize, source, validationMessages } = schema;
5552
5350
  const { getErrorMessageFunctions, updateComponent, onBehavior, onValueChange } = mapperProps;
5553
5351
  const errorMessageFunctions = getErrorMessageFunctions(validationMessages);
5554
- const { performPersistAsync } = getPersistAsyncInitialState(schemaMapperProps, mapperProps);
5555
- const persistedState = performPersistAsync ? getInitialPersistedState(null, model) : getInitialPersistedState();
5556
5352
  const validLocalValue = isFile(localValue) ? localValue : null;
5557
5353
  const value = (_a = getFileFromModel(model)) != null ? _a : validLocalValue;
5558
5354
  const checks = hidden ? [] : [
@@ -5570,9 +5366,7 @@ var stringSchemaToUploadInputComponent = (schemaMapperProps, mapperProps) => {
5570
5366
  maxSize,
5571
5367
  source,
5572
5368
  value,
5573
- persistedState,
5574
- performPersistAsync,
5575
- performRefresh: getPerformRefresh(schema, onBehavior),
5369
+ schemaOnChange: getSchemaOnChange(schema, onBehavior),
5576
5370
  onValueChange
5577
5371
  }),
5578
5372
  updateComponent
@@ -5586,26 +5380,27 @@ var createTextInputComponent = (textInputProps, updateComponent) => {
5586
5380
  uid,
5587
5381
  id,
5588
5382
  checks,
5589
- performPersistAsync,
5590
- performRefresh,
5383
+ schemaOnChange,
5591
5384
  performValidationAsync,
5592
5385
  onValueChange,
5386
+ onPersistAsync,
5593
5387
  summariser,
5594
5388
  value
5595
5389
  } = _a, rest = __objRest(_a, [
5596
5390
  "uid",
5597
5391
  "id",
5598
5392
  "checks",
5599
- "performPersistAsync",
5600
- "performRefresh",
5393
+ "schemaOnChange",
5601
5394
  "performValidationAsync",
5602
5395
  "onValueChange",
5396
+ "onPersistAsync",
5603
5397
  "summariser",
5604
5398
  "value"
5605
5399
  ]);
5606
5400
  const update = getInputUpdateFunction(updateComponent);
5607
5401
  const getValidationErrors = getLocalValueValidator(checks);
5608
- const performDebouncedRefresh = getDebouncedPerformRefresh(performRefresh, getValidationErrors);
5402
+ const performOnChange = getDebouncedSchemaOnChange(schemaOnChange, getValidationErrors);
5403
+ const validateAsync = performValidationAsync ? getDebouncedComponentValidationAsync(update, performValidationAsync) : void 0;
5609
5404
  const inputComponent = __spreadValues({
5610
5405
  type: "text",
5611
5406
  uid,
@@ -5615,8 +5410,12 @@ var createTextInputComponent = (textInputProps, updateComponent) => {
5615
5410
  update(this, updateFn);
5616
5411
  },
5617
5412
  onBlur() {
5618
- this.validate();
5619
- performDebouncedRefresh == null ? void 0 : performDebouncedRefresh.flush();
5413
+ const isValid = this.validate();
5414
+ performOnChange == null ? void 0 : performOnChange.flush();
5415
+ if (isValid) {
5416
+ onPersistAsync == null ? void 0 : onPersistAsync();
5417
+ validateAsync == null ? void 0 : validateAsync.flush();
5418
+ }
5620
5419
  },
5621
5420
  onFocus() {
5622
5421
  },
@@ -5628,7 +5427,14 @@ var createTextInputComponent = (textInputProps, updateComponent) => {
5628
5427
  draft.validationAsyncState.messages = {};
5629
5428
  draft.value = updatedValue;
5630
5429
  });
5631
- performDebouncedRefresh == null ? void 0 : performDebouncedRefresh(prevValue, updatedValue);
5430
+ performOnChange == null ? void 0 : performOnChange(prevValue, updatedValue);
5431
+ const isValid = getValidationErrors(updatedValue).length === 0;
5432
+ if (isValid) {
5433
+ validateAsync == null ? void 0 : validateAsync(this, updatedValue);
5434
+ }
5435
+ if (!updatedValue) {
5436
+ validateAsync == null ? void 0 : validateAsync.cancel();
5437
+ }
5632
5438
  onValueChange();
5633
5439
  },
5634
5440
  async getSubmittableValue() {
@@ -5651,51 +5457,12 @@ var createTextInputComponent = (textInputProps, updateComponent) => {
5651
5457
  return errors.length === 0;
5652
5458
  }
5653
5459
  }, rest);
5654
- if (performRefresh) {
5655
- return inputComponent;
5656
- }
5657
- if (performPersistAsync) {
5658
- const persist = getComponentPersistAsync(update, performPersistAsync);
5659
- return __spreadProps(__spreadValues({}, inputComponent), {
5660
- onBlur() {
5661
- if (this.validate()) {
5662
- persist(this, this.getLocalValue()).catch(() => {
5663
- });
5664
- }
5665
- },
5666
- async getSubmittableValue() {
5667
- return persist(this, this.getLocalValue());
5668
- },
5669
- getSubmittableValueSync() {
5670
- return this.persistedState.lastResponse;
5671
- }
5672
- });
5673
- }
5674
- if (performValidationAsync) {
5675
- const validateAsync = getDebouncedComponentValidationAsync(update, performValidationAsync);
5676
- return __spreadProps(__spreadValues({}, inputComponent), {
5677
- onBlur() {
5678
- if (this.validate()) {
5679
- validateAsync.flush();
5680
- }
5681
- },
5682
- onChange(updatedValue) {
5683
- inputComponent.onChange.call(this, updatedValue);
5684
- if (getValidationErrors(updatedValue).length === 0) {
5685
- validateAsync(this, updatedValue);
5686
- }
5687
- if (!updatedValue) {
5688
- validateAsync.cancel();
5689
- }
5690
- }
5691
- });
5692
- }
5693
5460
  return inputComponent;
5694
5461
  };
5695
5462
 
5696
5463
  // src/revamp/domain/mappers/schema/stringSchemaToComponent/stringSchemaToTextInputComponent.ts
5697
5464
  var stringSchemaToTextInputComponent = (schemaMapperProps, mapperProps) => {
5698
- const { schema, localValue, model, required = false } = schemaMapperProps;
5465
+ const { schema, localValue, model, required = false, onPersistAsync } = schemaMapperProps;
5699
5466
  const {
5700
5467
  autocapitalization,
5701
5468
  autocompleteHint,
@@ -5711,17 +5478,13 @@ var stringSchemaToTextInputComponent = (schemaMapperProps, mapperProps) => {
5711
5478
  const { getErrorMessageFunctions, updateComponent, onBehavior, onValueChange, logEvent } = mapperProps;
5712
5479
  const controlForLegacyFormat = getControlForLegacyFormat(format);
5713
5480
  const errorMessageFunctions = getErrorMessageFunctions(validationMessages);
5714
- const { performPersistAsync, persistedState } = getPersistAsyncInitialState(
5715
- schemaMapperProps,
5716
- mapperProps
5717
- );
5718
5481
  const { performValidationAsync, validationAsyncState } = getValidationAsyncInitialState(
5719
5482
  schemaMapperProps,
5720
5483
  mapperProps
5721
5484
  );
5722
5485
  const validLocalValue = isString(localValue) ? localValue : null;
5723
5486
  const validModel = isString(model) ? model : defaultValue != null ? defaultValue : null;
5724
- const value = performPersistAsync ? validLocalValue : validModel;
5487
+ const value = onPersistAsync ? validLocalValue : validModel;
5725
5488
  return createTextInputComponent(
5726
5489
  __spreadProps(__spreadValues({}, mapCommonSchemaProps(schemaMapperProps)), {
5727
5490
  autocapitalization,
@@ -5742,10 +5505,8 @@ var stringSchemaToTextInputComponent = (schemaMapperProps, mapperProps) => {
5742
5505
  }))
5743
5506
  } : void 0,
5744
5507
  value,
5745
- persistedState,
5746
5508
  validationAsyncState,
5747
- performPersistAsync,
5748
- performRefresh: getPerformRefresh(schema, onBehavior),
5509
+ schemaOnChange: getSchemaOnChange(schema, onBehavior),
5749
5510
  performValidationAsync,
5750
5511
  onValueChange
5751
5512
  }),
@@ -5776,6 +5537,136 @@ var isStringSchemaWithBase64 = (schema) => {
5776
5537
  return schema.format === "base64url" && !("persistAsync" in schema);
5777
5538
  };
5778
5539
 
5540
+ // src/revamp/domain/components/utils/isExactLocalValueMatch.ts
5541
+ var isExactLocalValueMatch = (valueA, valueB) => {
5542
+ if (isArrayLocalValue(valueA) && isArrayLocalValue(valueB)) {
5543
+ return valueA.length === valueB.length && valueA.every((value, index) => isExactLocalValueMatch(value, valueB[index]));
5544
+ }
5545
+ if (isObjectLocalValue(valueA) && isObjectLocalValue(valueB)) {
5546
+ const keysA = Object.keys(valueA);
5547
+ const keysB = Object.keys(valueB);
5548
+ return keysA.length === keysB.length && keysA.every((key) => isExactLocalValueMatch(valueA[key], valueB[key]));
5549
+ }
5550
+ return valueA === valueB;
5551
+ };
5552
+
5553
+ // src/revamp/domain/components/PersistAsyncComponent.ts
5554
+ var createPersistAsyncComponent = (props, performPersistAsync, schemaOnChange, updateComponent) => {
5555
+ const { uid, schemaId, component, hidden, model, localValue } = props;
5556
+ const update = getInputUpdateFunction(updateComponent);
5557
+ const paComponent = {
5558
+ type: "persist-async",
5559
+ uid,
5560
+ schemaId,
5561
+ component,
5562
+ hidden,
5563
+ lastSubmitted: model != null ? localValue != null ? localValue : null : null,
5564
+ lastResponse: model != null ? model : null,
5565
+ submission: Promise.resolve(model != null ? model : null),
5566
+ abortController: new AbortController(),
5567
+ errors: [],
5568
+ _update(updateFn) {
5569
+ update(this, updateFn);
5570
+ },
5571
+ validate() {
5572
+ return this.component.validate();
5573
+ },
5574
+ getLocalValue() {
5575
+ return this.component.getLocalValue();
5576
+ },
5577
+ async getSubmittableValue() {
5578
+ return this.persist();
5579
+ },
5580
+ getSubmittableValueSync() {
5581
+ return this.lastResponse;
5582
+ },
5583
+ getSummary() {
5584
+ return this.component.getSummary();
5585
+ },
5586
+ async persist() {
5587
+ const childLocalValue = this.component.getLocalValue();
5588
+ if (isExactLocalValueMatch(childLocalValue, this.lastSubmitted)) {
5589
+ return this.submission;
5590
+ }
5591
+ const newAbortController = abortAndResetController(this.abortController);
5592
+ if (childLocalValue == null || childLocalValue === "") {
5593
+ const resolvedNull = Promise.resolve(null);
5594
+ this._update((draft) => {
5595
+ draft.abortController = newAbortController;
5596
+ draft.lastResponse = null;
5597
+ draft.lastSubmitted = childLocalValue;
5598
+ draft.submission = resolvedNull;
5599
+ draft.errors = [];
5600
+ });
5601
+ schemaOnChange == null ? void 0 : schemaOnChange();
5602
+ return resolvedNull;
5603
+ }
5604
+ const { signal } = newAbortController;
5605
+ const newSubmission = performPersistAsync({ value: childLocalValue, signal }).then((token) => {
5606
+ this._update((draft) => {
5607
+ draft.lastResponse = token;
5608
+ draft.errors = [];
5609
+ });
5610
+ schemaOnChange == null ? void 0 : schemaOnChange();
5611
+ return token;
5612
+ }).catch((error) => {
5613
+ if (error instanceof DOMException && error.name === "AbortError") {
5614
+ return null;
5615
+ }
5616
+ this._update((draft) => {
5617
+ draft.lastResponse = null;
5618
+ draft.lastSubmitted = null;
5619
+ draft.errors = error instanceof Error ? [error.message] : [];
5620
+ });
5621
+ throw error;
5622
+ });
5623
+ this._update((draft) => {
5624
+ draft.abortController = newAbortController;
5625
+ draft.lastSubmitted = childLocalValue;
5626
+ draft.lastResponse = null;
5627
+ draft.submission = newSubmission;
5628
+ draft.errors = [];
5629
+ });
5630
+ return newSubmission;
5631
+ }
5632
+ };
5633
+ return paComponent;
5634
+ };
5635
+
5636
+ // src/revamp/domain/mappers/schema/persistAsyncSchemaToComponent.ts
5637
+ var isSupported = (type) => ["boolean", "text", "date", "integer", "number", "upload"].includes(type);
5638
+ var persistAsyncSchemaToComponent = (schemaMapperProps, mapperProps) => {
5639
+ var _a;
5640
+ const { uid, schema, model, localValue } = schemaMapperProps;
5641
+ const { persistAsync } = schema;
5642
+ const performPersistAsync = getPerformPersistAsyncFn(schema, persistAsync, mapperProps);
5643
+ const onPersistAsync = () => {
5644
+ void paComponent.persist().catch(() => {
5645
+ });
5646
+ };
5647
+ const childComponent = mapSchemaToComponent(
5648
+ __spreadProps(__spreadValues({}, schemaMapperProps), { uid: `${uid}-persist`, schema: persistAsync.schema, onPersistAsync }),
5649
+ mapperProps
5650
+ );
5651
+ if (!isSupported(childComponent.type)) {
5652
+ return childComponent;
5653
+ }
5654
+ const paComponent = createPersistAsyncComponent(
5655
+ {
5656
+ uid,
5657
+ hidden: (_a = schema.hidden) != null ? _a : false,
5658
+ component: childComponent,
5659
+ schemaId: schema.$id,
5660
+ model,
5661
+ localValue
5662
+ },
5663
+ performPersistAsync,
5664
+ getSchemaOnChange(schema, mapperProps.onBehavior),
5665
+ mapperProps.updateComponent
5666
+ );
5667
+ return paComponent;
5668
+ };
5669
+
5779
5670
  // src/revamp/domain/mappers/mapSchemaToComponent.ts
5780
5671
  var mapSchemaToComponent = (schemaMapperProps, mapperProps) => {
5781
5672
  const { uid, schema } = schemaMapperProps;
@@ -5783,13 +5674,7 @@ var mapSchemaToComponent = (schemaMapperProps, mapperProps) => {
5783
5674
  return constSchemaToComponent(uid, __spreadProps(__spreadValues({}, schemaMapperProps), { schema }));
5784
5675
  }
5785
5676
  if (isSchemaWithPersistAsync(schema)) {
5786
- const { persistAsync } = schema;
5787
- const { idProperty, method, param, url } = persistAsync;
5788
- const persistAsyncConfig = { idProperty, method, param, url };
5789
- return mapSchemaToComponent(
5790
- __spreadProps(__spreadValues({}, schemaMapperProps), { persistAsyncConfig, schema: persistAsync.schema }),
5791
- mapperProps
5792
- );
5677
+ return persistAsyncSchemaToComponent(__spreadProps(__spreadValues({}, schemaMapperProps), { schema }), mapperProps);
5793
5678
  }
5794
5679
  if (isAllOfSchema(schema)) {
5795
5680
  return allOfSchemaToComponent(__spreadProps(__spreadValues({}, schemaMapperProps), { schema }), mapperProps);
@@ -5816,7 +5701,7 @@ var mapSchemaToComponent = (schemaMapperProps, mapperProps) => {
5816
5701
  return arraySchemaToComponent(__spreadProps(__spreadValues({}, schemaMapperProps), { schema }), mapperProps);
5817
5702
  }
5818
5703
  if (isBlobSchema(schema)) {
5819
- if (!schemaMapperProps.persistAsyncConfig) {
5704
+ if (!schemaMapperProps.onPersistAsync) {
5820
5705
  throw new Error(
5821
5706
  "Blob schemas can only be used as the schema of a persist async configuration."
5822
5707
  );
@@ -6018,8 +5903,8 @@ var executePoll = async (props) => {
6018
5903
 
6019
5904
  // src/revamp/flow/executeRefresh.ts
6020
5905
  var executeRefresh = async (props) => {
6021
- const { abortSignal, url, model, schemaId, etag, httpClient, trackEvent, logEvent } = props;
6022
- trackEvent("Refresh Triggered", { schema: schemaId });
5906
+ const { abortSignal, url, model, etag, analytics, httpClient, trackEvent, logEvent } = props;
5907
+ trackEvent("Refresh Triggered", analytics);
6023
5908
  try {
6024
5909
  const response = await httpClient(url != null ? url : "", {
6025
5910
  method: "POST",
@@ -6030,34 +5915,34 @@ var executeRefresh = async (props) => {
6030
5915
  signal: abortSignal
6031
5916
  });
6032
5917
  if (response.status === 304) {
6033
- trackEvent("Refresh Succeeded", { schema: schemaId });
5918
+ trackEvent("Refresh Succeeded", analytics);
6034
5919
  return { type: "noop" };
6035
5920
  }
6036
5921
  if (!response.ok) {
6037
5922
  const responseBody = await parseResponseBodyAsJsonElement(response).catch(() => ({}));
6038
5923
  const body2 = isErrorResponseBody(responseBody) ? responseBody : {};
6039
- trackEvent("Refresh Failed", __spreadProps(__spreadValues({}, body2.analytics), {
6040
- schema: schemaId,
5924
+ trackEvent("Refresh Failed", __spreadProps(__spreadValues(__spreadValues({}, analytics), body2.analytics), {
5925
+ statusCode: response.status
5926
+ }));
5927
+ logEvent("error", "Dynamic Flow - Refresh Failed", __spreadProps(__spreadValues({}, analytics), {
6041
5928
  statusCode: response.status
6042
5929
  }));
6043
- logEvent("error", "Dynamic Flow - Refresh Failed", { schemaId, statusCode: response.status });
6044
5930
  return { type: "error", body: body2, statusCode: response.status };
6045
5931
  }
6046
5932
  const newEtag = response.headers.get("etag") || null;
6047
5933
  const body = await parseResponseBodyAsJsonElement(response);
6048
5934
  assertStepResponseBody(body);
6049
- trackEvent("Refresh Succeeded", { schema: schemaId });
5935
+ trackEvent("Refresh Succeeded", analytics);
6050
5936
  return { type: "refresh-step", step: body, etag: newEtag };
6051
5937
  } catch (error) {
6052
5938
  if (error instanceof DOMException && error.name === "AbortError") {
6053
- trackEvent("Refresh Aborted", { schema: schemaId });
5939
+ trackEvent("Refresh Aborted", analytics);
6054
5940
  return { type: "noop" };
6055
5941
  }
6056
- trackEvent("Refresh Failed", { schema: schemaId });
6057
- logEvent("error", "Dynamic Flow - Refresh Failed", {
6058
- schemaId,
5942
+ trackEvent("Refresh Failed", analytics);
5943
+ logEvent("error", "Dynamic Flow - Refresh Failed", __spreadProps(__spreadValues({}, analytics), {
6059
5944
  errorMessage: getErrorMessage(error)
6060
- });
5945
+ }));
6061
5946
  return { type: "error", body: {} };
6062
5947
  }
6063
5948
  };
@@ -6536,7 +6421,7 @@ function useDynamicFlowCore(props) {
6536
6421
  break;
6537
6422
  }
6538
6423
  case "refresh": {
6539
- await onRefresh(behavior.schemaId, behavior.url);
6424
+ await onRefresh({ refreshUrl: behavior.url, analytics: behavior.analytics });
6540
6425
  break;
6541
6426
  }
6542
6427
  case "link": {
@@ -6623,7 +6508,7 @@ function useDynamicFlowCore(props) {
6623
6508
  }
6624
6509
  case "refresh": {
6625
6510
  const { refreshUrl, errors = {} } = command.body;
6626
- void onRefresh(void 0, refreshUrl, errors);
6511
+ void onRefresh({ refreshUrl, errorsOverride: errors });
6627
6512
  break;
6628
6513
  }
6629
6514
  case "behavior": {
@@ -6637,7 +6522,11 @@ function useDynamicFlowCore(props) {
6637
6522
  }
6638
6523
  }, []);
6639
6524
  const onRefresh = useCallback2(
6640
- async (schemaId, refreshUrl, errorsOverride) => {
6525
+ async ({
6526
+ refreshUrl,
6527
+ errorsOverride,
6528
+ analytics
6529
+ }) => {
6641
6530
  var _a2, _b;
6642
6531
  try {
6643
6532
  rootComponentRef.current.setLoadingState("refreshing");
@@ -6646,8 +6535,8 @@ function useDynamicFlowCore(props) {
6646
6535
  abortSignal: abortCurrentAndGetNewAbortSignal(),
6647
6536
  url: (_b = refreshUrl != null ? refreshUrl : rootComponentRef.current.getRefreshUrl()) != null ? _b : "",
6648
6537
  model,
6649
- schemaId,
6650
6538
  etag: etagRef.current,
6539
+ analytics,
6651
6540
  httpClient,
6652
6541
  trackEvent: trackCoreEvent,
6653
6542
  logEvent