@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.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
@@ -3678,93 +3582,6 @@ var getAnalyticsFromErrorResponse = (json) => {
3678
3582
  return isObject(analytics) ? analytics : void 0;
3679
3583
  };
3680
3584
 
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
3585
  // src/revamp/domain/features/validationAsync/getPerformValidationAsync.ts
3769
3586
  var getPerformValidationAsync = ({
3770
3587
  httpClient,
@@ -3881,7 +3698,7 @@ var summaryIfProvides = (summary, { value, icon, image }) => {
3881
3698
  // src/revamp/domain/mappers/schema/utils/mapCommonSchemaProps.ts
3882
3699
  var mapCommonSchemaProps = (schemaMapperProps) => {
3883
3700
  var _a;
3884
- const { uid, schemaId, schema, required, validationErrors } = schemaMapperProps;
3701
+ const { uid, schemaId, schema, required, validationErrors, onPersistAsync } = schemaMapperProps;
3885
3702
  const { $id, analyticsId, control, description, icon, image, keywords, title, hidden } = schema;
3886
3703
  return __spreadValues(__spreadValues(__spreadValues({
3887
3704
  uid,
@@ -3898,6 +3715,7 @@ var mapCommonSchemaProps = (schemaMapperProps) => {
3898
3715
  keywords,
3899
3716
  required: Boolean(required),
3900
3717
  title,
3718
+ onPersistAsync,
3901
3719
  summariser: getSummariser(schema)
3902
3720
  }, schemaHasHelp(schema) ? { help: schema.help.markdown } : {}), schemaHasPlaceholder(schema) ? { placeholder: schema.placeholder } : {}), schema.alert ? { alert: mapSchemaAlert(schema.alert) } : {});
3903
3721
  };
@@ -3907,21 +3725,17 @@ var schemaHasPlaceholder = (schema) => Boolean("placeholder" in schema && schema
3907
3725
 
3908
3726
  // src/revamp/domain/mappers/schema/numberSchemaToComponent.ts
3909
3727
  var numberSchemaToComponent = (schemaMapperProps, mapperProps) => {
3910
- const { schema, model, localValue, required = false } = schemaMapperProps;
3728
+ const { schema, model, localValue, required = false, onPersistAsync } = schemaMapperProps;
3911
3729
  const { autocompleteHint, validationMessages, default: defaultValue, maximum, minimum } = schema;
3912
3730
  const { getErrorMessageFunctions, updateComponent, onBehavior, onValueChange } = mapperProps;
3913
3731
  const errorMessageFunctions = getErrorMessageFunctions(validationMessages);
3914
- const { performPersistAsync, persistedState } = getPersistAsyncInitialState(
3915
- schemaMapperProps,
3916
- mapperProps
3917
- );
3918
3732
  const { performValidationAsync, validationAsyncState } = getValidationAsyncInitialState(
3919
3733
  schemaMapperProps,
3920
3734
  mapperProps
3921
3735
  );
3922
3736
  const validLocalValue = isNumber(localValue) ? localValue : null;
3923
3737
  const validModel = isNumber(model) ? model : defaultValue != null ? defaultValue : null;
3924
- const value = performPersistAsync ? validLocalValue : validModel;
3738
+ const value = onPersistAsync ? validLocalValue : validModel;
3925
3739
  return createNumberInputComponent(
3926
3740
  __spreadProps(__spreadValues({}, mapCommonSchemaProps(schemaMapperProps)), {
3927
3741
  autoComplete: getAutocompleteString(autocompleteHint),
@@ -3933,10 +3747,8 @@ var numberSchemaToComponent = (schemaMapperProps, mapperProps) => {
3933
3747
  value,
3934
3748
  maximum,
3935
3749
  minimum,
3936
- persistedState,
3937
3750
  validationAsyncState,
3938
- performPersistAsync,
3939
- performRefresh: getPerformRefresh(schema, onBehavior),
3751
+ schemaOnChange: getSchemaOnChange(schema, onBehavior),
3940
3752
  performValidationAsync,
3941
3753
  onValueChange
3942
3754
  }),
@@ -4213,13 +4025,58 @@ var localValueToJsonElement = (localValue) => {
4213
4025
  };
4214
4026
  var getRandomInt = () => Math.floor(Math.random() * 1e8);
4215
4027
 
4216
- // src/revamp/domain/components/utils/file-utils.ts
4217
- var toBase64 = async (file) => new Promise((resolve, reject) => {
4218
- const reader = new FileReader();
4219
- reader.addEventListener("load", () => resolve(reader.result));
4220
- reader.addEventListener("error", reject);
4221
- reader.readAsDataURL(file);
4222
- });
4028
+ // src/revamp/domain/features/persistAsync/getComponentMultiPersistAsync.ts
4029
+ var getComponentMultiPersistAsync = (update, performPersistAsync) => (
4030
+ /**
4031
+ * Will update the persistedState when a new request is made, and will update
4032
+ * the value or set errors when the request completes.
4033
+ */
4034
+ async (component, index, value) => {
4035
+ if (isNullish(value)) {
4036
+ throw new Error("Value must be a file or base64 string.");
4037
+ }
4038
+ const newAbortController = new AbortController();
4039
+ const { signal } = newAbortController;
4040
+ const newSubmission = performPersistAsync({ value, signal }).then((newValue) => {
4041
+ update(component, (draft) => {
4042
+ draft.persistedState[index].lastResponse = newValue;
4043
+ });
4044
+ return newValue;
4045
+ }).catch((error) => {
4046
+ update(component, (draft) => {
4047
+ draft.persistedState = [
4048
+ ...draft.persistedState.slice(0, index),
4049
+ ...draft.persistedState.slice(index + 1)
4050
+ ];
4051
+ draft.value.splice(index, 1);
4052
+ draft.files.splice(index, 1);
4053
+ });
4054
+ throw error;
4055
+ });
4056
+ update(component, (draft) => {
4057
+ draft.persistedState = [
4058
+ ...draft.persistedState.slice(0, index),
4059
+ {
4060
+ id: getRandomId(),
4061
+ abortController: newAbortController,
4062
+ lastResponse: null,
4063
+ lastSubmitted: null,
4064
+ submission: newSubmission
4065
+ },
4066
+ ...draft.persistedState.slice(index)
4067
+ ];
4068
+ });
4069
+ return newSubmission;
4070
+ }
4071
+ );
4072
+
4073
+ // src/revamp/domain/components/utils/file-utils.ts
4074
+ var toBase64 = async (file) => new Promise((resolve, reject) => {
4075
+ const reader = new FileReader();
4076
+ reader.addEventListener("load", () => resolve(reader.result));
4077
+ reader.addEventListener("error", reject);
4078
+ reader.readAsDataURL(file);
4079
+ });
4223
4080
  var base64dataUrltoFile = (dataurl, filename) => {
4224
4081
  if (!isBase64DataUrl(dataurl)) {
4225
4082
  return null;
@@ -4341,6 +4198,82 @@ var createMultiUploadInputComponent = (uploadInputProps, updateComponent) => {
4341
4198
  });
4342
4199
  };
4343
4200
 
4201
+ // src/revamp/domain/features/persistAsync/getInitialPersistedState.ts
4202
+ var getInitialPersistedState = (lastSubmitted, model) => ({
4203
+ abortController: new AbortController(),
4204
+ lastSubmitted: !isNullish(model) ? lastSubmitted != null ? lastSubmitted : null : null,
4205
+ lastResponse: model != null ? model : null,
4206
+ submission: Promise.resolve(model != null ? model : null)
4207
+ });
4208
+
4209
+ // src/revamp/domain/features/persistAsync/getPerformPersistAsync.ts
4210
+ var getPerformPersistAsync = ({
4211
+ genericErrorMessage,
4212
+ httpClient,
4213
+ persistAsyncConfig,
4214
+ schemaId,
4215
+ logEvent,
4216
+ trackEvent
4217
+ }) => {
4218
+ const { idProperty, param, method, url } = persistAsyncConfig;
4219
+ const trackFailure = (json) => {
4220
+ const analytics = getAnalyticsFromErrorResponse(json);
4221
+ trackEvent("PersistAsync Failed", __spreadValues({ schema: schemaId }, analytics));
4222
+ };
4223
+ return async function performPersistAsync({ value, signal }) {
4224
+ let response;
4225
+ let json;
4226
+ try {
4227
+ trackEvent("PersistAsync Triggered", { schema: schemaId });
4228
+ response = await httpClient(
4229
+ url,
4230
+ constructPayload({ value, signal, requestConfig: { method, param } })
4231
+ );
4232
+ json = await response.json();
4233
+ if (response.ok && isObject(json)) {
4234
+ trackEvent("PersistAsync Succeeded", { schema: schemaId });
4235
+ if (json[idProperty] === void 0) {
4236
+ logEvent(
4237
+ "error",
4238
+ `Response from persist async did not contain expected property ${idProperty}.`
4239
+ );
4240
+ throw new Error(genericErrorMessage);
4241
+ }
4242
+ return json[idProperty];
4243
+ }
4244
+ } catch (e) {
4245
+ trackFailure();
4246
+ throw new Error(genericErrorMessage);
4247
+ }
4248
+ const validationError = !response.ok && isObject(json) ? getValidationError(param, json) : null;
4249
+ trackFailure(json);
4250
+ throw new Error(validationError != null ? validationError : genericErrorMessage);
4251
+ };
4252
+ };
4253
+ var getValidationError = (param, response) => {
4254
+ var _a;
4255
+ const message = (_a = response.validation) == null ? void 0 : _a[param];
4256
+ return isString(message) ? message : null;
4257
+ };
4258
+
4259
+ // src/revamp/domain/mappers/schema/utils/getPerformPersistAsyncFn.ts
4260
+ var getPerformPersistAsyncFn = (schema, persistAsyncConfig, mapperProps) => {
4261
+ const { getErrorMessageFunctions, httpClient, trackEvent, logEvent } = mapperProps;
4262
+ const { $id, analyticsId } = schema;
4263
+ const validationMessages = schemaHasValidationMessages(schema) ? schema.validationMessages : void 0;
4264
+ const errorMessageFunctions = getErrorMessageFunctions(validationMessages);
4265
+ const persistAsyncError = errorMessageFunctions.genericError();
4266
+ return getPerformPersistAsync({
4267
+ genericErrorMessage: persistAsyncError,
4268
+ httpClient,
4269
+ logEvent,
4270
+ persistAsyncConfig,
4271
+ schemaId: analyticsId != null ? analyticsId : $id,
4272
+ trackEvent
4273
+ });
4274
+ };
4275
+ var schemaHasValidationMessages = (schema) => Boolean("validationMessages" in schema && schema.validationMessages);
4276
+
4344
4277
  // src/revamp/domain/mappers/schema/arraySchemaToComponent/arraySchemaToMultiUploadComponent.ts
4345
4278
  var arraySchemaToMultiUploadComponent = (schemaMapperProps, mapperProps) => {
4346
4279
  var _a;
@@ -4367,7 +4300,7 @@ var arraySchemaToMultiUploadComponent = (schemaMapperProps, mapperProps) => {
4367
4300
  schema: __spreadProps(__spreadValues({}, uploadSchema), { hidden: (_a = schema.hidden) != null ? _a : uploadSchema.hidden, alert: schema.alert })
4368
4301
  });
4369
4302
  const { onValueChange } = mapperProps;
4370
- const { performPersistAsync } = getPersistAsyncInitialState(combinedSchemaProps, mapperProps);
4303
+ const performPersistAsync = persistAsyncConfig ? getPerformPersistAsyncFn(combinedSchemaProps.schema, persistAsyncConfig, mapperProps) : void 0;
4371
4304
  const value = performPersistAsync ? getValueForPersistAsync(localValue) : [];
4372
4305
  const persistedState = performPersistAsync && isArray(model) ? model.map((itemModel) => getInitialPersistedState(null, itemModel)) : [];
4373
4306
  return createMultiUploadInputComponent(
@@ -4423,7 +4356,7 @@ var createMultiSelectComponent = (multiSelectProps, updateComponent) => {
4423
4356
  options,
4424
4357
  initialValue,
4425
4358
  performValidationAsync,
4426
- performRefresh,
4359
+ schemaOnChange,
4427
4360
  onValueChange
4428
4361
  } = _a, rest = __objRest(_a, [
4429
4362
  "uid",
@@ -4431,13 +4364,14 @@ var createMultiSelectComponent = (multiSelectProps, updateComponent) => {
4431
4364
  "options",
4432
4365
  "initialValue",
4433
4366
  "performValidationAsync",
4434
- "performRefresh",
4367
+ "schemaOnChange",
4435
4368
  "onValueChange"
4436
4369
  ]);
4437
4370
  const update = getInputUpdateFunction(updateComponent);
4438
4371
  const children = options.map((option) => option.component);
4439
4372
  const selectedIndices = getInitialModelIndices(initialValue, children);
4440
4373
  const getValidationErrors = getLocalValueValidator(checks);
4374
+ const validateAsync = performValidationAsync ? getComponentValidationAsync(update, performValidationAsync) : void 0;
4441
4375
  const component = __spreadProps(__spreadValues({
4442
4376
  uid,
4443
4377
  type: "multi-select",
@@ -4454,12 +4388,16 @@ var createMultiSelectComponent = (multiSelectProps, updateComponent) => {
4454
4388
  draft.selectedIndices = indices;
4455
4389
  draft.errors = [];
4456
4390
  });
4457
- performRefresh == null ? void 0 : performRefresh();
4458
- onValueChange();
4391
+ schemaOnChange == null ? void 0 : schemaOnChange();
4459
4392
  const errors = getValidationErrors(this.getLocalValue());
4460
4393
  this._update((draft) => {
4461
4394
  draft.errors = errors;
4462
4395
  });
4396
+ if (this.validate()) {
4397
+ validateAsync == null ? void 0 : validateAsync(this, this.getLocalValue()).catch(() => {
4398
+ });
4399
+ }
4400
+ onValueChange();
4463
4401
  },
4464
4402
  onBlur() {
4465
4403
  },
@@ -4497,21 +4435,6 @@ var createMultiSelectComponent = (multiSelectProps, updateComponent) => {
4497
4435
  return this.selectedIndices.map((i) => this.children[i]);
4498
4436
  }
4499
4437
  });
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
4438
  return component;
4516
4439
  };
4517
4440
  var getInitialModelIndices = (model, options) => {
@@ -4578,7 +4501,7 @@ var arraySchemaToMultiSelectComponent = (schemaMapperProps, mapperProps) => {
4578
4501
  title,
4579
4502
  validationAsyncState,
4580
4503
  performValidationAsync,
4581
- performRefresh: getPerformRefresh(schema, onBehavior),
4504
+ schemaOnChange: getSchemaOnChange(schema, onBehavior),
4582
4505
  onValueChange
4583
4506
  }),
4584
4507
  updateComponent
@@ -4698,9 +4621,9 @@ var createUploadInputComponent = (uploadInputProps, updateComponent) => {
4698
4621
  checks,
4699
4622
  format,
4700
4623
  value,
4701
- performPersistAsync,
4702
- performRefresh,
4624
+ schemaOnChange,
4703
4625
  onValueChange,
4626
+ onPersistAsync,
4704
4627
  summariser
4705
4628
  } = _a, rest = __objRest(_a, [
4706
4629
  "uid",
@@ -4708,9 +4631,9 @@ var createUploadInputComponent = (uploadInputProps, updateComponent) => {
4708
4631
  "checks",
4709
4632
  "format",
4710
4633
  "value",
4711
- "performPersistAsync",
4712
- "performRefresh",
4634
+ "schemaOnChange",
4713
4635
  "onValueChange",
4636
+ "onPersistAsync",
4714
4637
  "summariser"
4715
4638
  ]);
4716
4639
  const update = getInputUpdateFunction(updateComponent);
@@ -4719,7 +4642,7 @@ var createUploadInputComponent = (uploadInputProps, updateComponent) => {
4719
4642
  type: "upload",
4720
4643
  uid,
4721
4644
  id,
4722
- format: "base64",
4645
+ format,
4723
4646
  value,
4724
4647
  _update(updateFn) {
4725
4648
  update(this, updateFn);
@@ -4735,12 +4658,16 @@ var createUploadInputComponent = (uploadInputProps, updateComponent) => {
4735
4658
  draft.errors = [];
4736
4659
  draft.value = updatedValue;
4737
4660
  });
4738
- performRefresh == null ? void 0 : performRefresh();
4661
+ schemaOnChange == null ? void 0 : schemaOnChange();
4739
4662
  onValueChange();
4663
+ onPersistAsync == null ? void 0 : onPersistAsync();
4740
4664
  },
4741
4665
  async getSubmittableValue() {
4742
4666
  const file = this.getLocalValue();
4743
- return file ? toBase64(file) : null;
4667
+ if (this.format === "base64" && file) {
4668
+ return toBase64(file);
4669
+ }
4670
+ return null;
4744
4671
  },
4745
4672
  getSubmittableValueSync() {
4746
4673
  return null;
@@ -4760,50 +4687,17 @@ var createUploadInputComponent = (uploadInputProps, updateComponent) => {
4760
4687
  return errors.length === 0;
4761
4688
  }
4762
4689
  }, 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
- });
4690
+ return uploadComponent;
4795
4691
  };
4796
4692
 
4797
4693
  // src/revamp/domain/mappers/schema/blobSchemaToComponent.ts
4798
4694
  var blobSchemaToComponent = (schemaMapperProps, mapperProps) => {
4799
- const { schema, localValue, model, required = false } = schemaMapperProps;
4695
+ const { schema, localValue, required = false, onPersistAsync } = schemaMapperProps;
4800
4696
  const { accepts, cameraConfig, maxSize, source, validationMessages } = schema;
4801
4697
  const { getErrorMessageFunctions, updateComponent, onValueChange } = mapperProps;
4802
4698
  const errorMessageFunctions = getErrorMessageFunctions(validationMessages);
4803
- const { performPersistAsync } = getPersistAsyncInitialState(schemaMapperProps, mapperProps);
4804
- const persistedState = performPersistAsync ? getInitialPersistedState(null, model) : getInitialPersistedState();
4805
4699
  const validLocalValue = isFile(localValue) ? localValue : null;
4806
- const value = performPersistAsync ? validLocalValue : null;
4700
+ const value = onPersistAsync ? validLocalValue : null;
4807
4701
  return createUploadInputComponent(
4808
4702
  __spreadProps(__spreadValues({}, mapCommonSchemaProps(schemaMapperProps)), {
4809
4703
  accepts,
@@ -4813,9 +4707,8 @@ var blobSchemaToComponent = (schemaMapperProps, mapperProps) => {
4813
4707
  maxSize,
4814
4708
  source,
4815
4709
  value,
4816
- persistedState,
4817
- performPersistAsync,
4818
4710
  checks: schema.hidden ? [] : [getRequiredCheck(required, errorMessageFunctions)],
4711
+ schemaOnChange: void 0,
4819
4712
  onValueChange
4820
4713
  }),
4821
4714
  updateComponent
@@ -4828,22 +4721,23 @@ var createBooleanInputComponent = (booleanInputProps, updateComponent) => {
4828
4721
  uid,
4829
4722
  id,
4830
4723
  value,
4831
- performPersistAsync,
4832
- performRefresh,
4724
+ schemaOnChange,
4833
4725
  performValidationAsync,
4834
4726
  onValueChange,
4727
+ onPersistAsync,
4835
4728
  summariser
4836
4729
  } = _a, rest = __objRest(_a, [
4837
4730
  "uid",
4838
4731
  "id",
4839
4732
  "value",
4840
- "performPersistAsync",
4841
- "performRefresh",
4733
+ "schemaOnChange",
4842
4734
  "performValidationAsync",
4843
4735
  "onValueChange",
4736
+ "onPersistAsync",
4844
4737
  "summariser"
4845
4738
  ]);
4846
4739
  const update = getInputUpdateFunction(updateComponent);
4740
+ const validateAsync = performValidationAsync ? getComponentValidationAsync(update, performValidationAsync) : void 0;
4847
4741
  const booleanComponent = __spreadValues({
4848
4742
  type: "boolean",
4849
4743
  uid,
@@ -4864,7 +4758,10 @@ var createBooleanInputComponent = (booleanInputProps, updateComponent) => {
4864
4758
  draft.errors = [];
4865
4759
  draft.value = updatedValue;
4866
4760
  });
4867
- performRefresh == null ? void 0 : performRefresh();
4761
+ schemaOnChange == null ? void 0 : schemaOnChange();
4762
+ onPersistAsync == null ? void 0 : onPersistAsync();
4763
+ validateAsync == null ? void 0 : validateAsync(this, this.getLocalValue()).catch(() => {
4764
+ });
4868
4765
  onValueChange();
4869
4766
  },
4870
4767
  async getSubmittableValue() {
@@ -4881,62 +4778,27 @@ var createBooleanInputComponent = (booleanInputProps, updateComponent) => {
4881
4778
  },
4882
4779
  validate: () => true
4883
4780
  }, 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
4781
  return booleanComponent;
4914
4782
  };
4915
4783
 
4916
4784
  // src/revamp/domain/mappers/schema/booleanSchemaToComponent.ts
4917
4785
  var booleanSchemaToComponent = (schemaMapperProps, mapperProps) => {
4918
- const { schema, localValue, model } = schemaMapperProps;
4786
+ const { schema, localValue, model, onPersistAsync } = schemaMapperProps;
4919
4787
  const { default: defaultValue } = schema;
4920
4788
  const { updateComponent, onBehavior, onValueChange } = mapperProps;
4921
- const performRefresh = getPerformRefresh(schema, onBehavior);
4922
- const { performPersistAsync, persistedState } = getPersistAsyncInitialState(
4923
- schemaMapperProps,
4924
- mapperProps
4925
- );
4789
+ const schemaOnChange = getSchemaOnChange(schema, onBehavior);
4926
4790
  const { performValidationAsync, validationAsyncState } = getValidationAsyncInitialState(
4927
4791
  schemaMapperProps,
4928
4792
  mapperProps
4929
4793
  );
4930
4794
  const validLocalValue = isBoolean(localValue) ? localValue : false;
4931
4795
  const validModel = getValidModel(model, defaultValue);
4932
- const value = performPersistAsync ? validLocalValue : validModel;
4796
+ const value = onPersistAsync ? validLocalValue : validModel;
4933
4797
  return createBooleanInputComponent(
4934
4798
  __spreadProps(__spreadValues({}, mapCommonSchemaProps(schemaMapperProps)), {
4935
4799
  value: value != null ? value : false,
4936
- persistedState,
4937
4800
  validationAsyncState,
4938
- performPersistAsync,
4939
- performRefresh,
4801
+ schemaOnChange,
4940
4802
  performValidationAsync,
4941
4803
  onValueChange
4942
4804
  }),
@@ -4992,25 +4854,26 @@ var createIntegerInputComponent = (integerInputProps, updateComponent) => {
4992
4854
  id,
4993
4855
  checks,
4994
4856
  value,
4995
- performPersistAsync,
4996
- performRefresh,
4857
+ schemaOnChange,
4997
4858
  performValidationAsync,
4998
4859
  onValueChange,
4860
+ onPersistAsync,
4999
4861
  summariser
5000
4862
  } = _a, rest = __objRest(_a, [
5001
4863
  "uid",
5002
4864
  "id",
5003
4865
  "checks",
5004
4866
  "value",
5005
- "performPersistAsync",
5006
- "performRefresh",
4867
+ "schemaOnChange",
5007
4868
  "performValidationAsync",
5008
4869
  "onValueChange",
4870
+ "onPersistAsync",
5009
4871
  "summariser"
5010
4872
  ]);
5011
4873
  const update = getInputUpdateFunction(updateComponent);
5012
4874
  const getValidationErrors = getLocalValueValidator(checks);
5013
- const performDebouncedRefresh = getDebouncedPerformRefresh(performRefresh, getValidationErrors);
4875
+ const performOnChange = getDebouncedSchemaOnChange(schemaOnChange, getValidationErrors);
4876
+ const validateAsync = performValidationAsync ? getDebouncedComponentValidationAsync(update, performValidationAsync) : void 0;
5014
4877
  const integerComponent = __spreadValues({
5015
4878
  type: "integer",
5016
4879
  uid,
@@ -5020,8 +4883,12 @@ var createIntegerInputComponent = (integerInputProps, updateComponent) => {
5020
4883
  update(this, updateFn);
5021
4884
  },
5022
4885
  onBlur() {
5023
- this.validate();
5024
- performDebouncedRefresh == null ? void 0 : performDebouncedRefresh.flush();
4886
+ const isValid = this.validate();
4887
+ performOnChange == null ? void 0 : performOnChange.flush();
4888
+ if (isValid) {
4889
+ onPersistAsync == null ? void 0 : onPersistAsync();
4890
+ validateAsync == null ? void 0 : validateAsync.flush();
4891
+ }
5025
4892
  },
5026
4893
  onFocus() {
5027
4894
  },
@@ -5033,7 +4900,11 @@ var createIntegerInputComponent = (integerInputProps, updateComponent) => {
5033
4900
  draft.validationAsyncState.messages = {};
5034
4901
  draft.value = updatedValue;
5035
4902
  });
5036
- performDebouncedRefresh == null ? void 0 : performDebouncedRefresh(prevValue, updatedValue);
4903
+ performOnChange == null ? void 0 : performOnChange(prevValue, updatedValue);
4904
+ const isValid = getValidationErrors(updatedValue).length === 0;
4905
+ if (isValid) {
4906
+ validateAsync == null ? void 0 : validateAsync(this, updatedValue);
4907
+ }
5037
4908
  onValueChange();
5038
4909
  },
5039
4910
  async getSubmittableValue() {
@@ -5057,62 +4928,22 @@ var createIntegerInputComponent = (integerInputProps, updateComponent) => {
5057
4928
  return errors.length === 0;
5058
4929
  }
5059
4930
  }, 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
4931
  return integerComponent;
5097
4932
  };
5098
4933
 
5099
4934
  // src/revamp/domain/mappers/schema/integerSchemaToComponent.ts
5100
4935
  var integerSchemaToComponent = (schemaMapperProps, mapperProps) => {
5101
- const { schema, localValue, model, required = false } = schemaMapperProps;
4936
+ const { schema, localValue, model, required = false, onPersistAsync } = schemaMapperProps;
5102
4937
  const { autocompleteHint, validationMessages, default: defaultValue, maximum, minimum } = schema;
5103
4938
  const { getErrorMessageFunctions, updateComponent, onBehavior, onValueChange } = mapperProps;
5104
4939
  const errorMessageFunctions = getErrorMessageFunctions(validationMessages);
5105
- const { performPersistAsync, persistedState } = getPersistAsyncInitialState(
5106
- schemaMapperProps,
5107
- mapperProps
5108
- );
5109
4940
  const { performValidationAsync, validationAsyncState } = getValidationAsyncInitialState(
5110
4941
  schemaMapperProps,
5111
4942
  mapperProps
5112
4943
  );
5113
4944
  const validLocalValue = isInteger(localValue) ? localValue : null;
5114
4945
  const validModel = isInteger(model) ? model : defaultValue != null ? defaultValue : null;
5115
- const value = performPersistAsync ? validLocalValue : validModel;
4946
+ const value = onPersistAsync ? validLocalValue : validModel;
5116
4947
  const checks = [
5117
4948
  getRequiredCheck(required, errorMessageFunctions),
5118
4949
  getBelowMinimumCheck(schema, errorMessageFunctions),
@@ -5124,11 +4955,9 @@ var integerSchemaToComponent = (schemaMapperProps, mapperProps) => {
5124
4955
  checks,
5125
4956
  maximum,
5126
4957
  minimum,
5127
- persistedState,
5128
4958
  value,
5129
4959
  validationAsyncState,
5130
- performPersistAsync,
5131
- performRefresh: getPerformRefresh(schema, onBehavior),
4960
+ schemaOnChange: getSchemaOnChange(schema, onBehavior),
5132
4961
  performValidationAsync,
5133
4962
  onValueChange
5134
4963
  }),
@@ -5283,7 +5112,7 @@ var nonNullishKeys = (model) => Object.keys(model).filter((key) => !isNullish(mo
5283
5112
 
5284
5113
  // src/revamp/domain/components/SelectInputComponent.ts
5285
5114
  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"]);
5115
+ const _a = selectProps, { uid, checks, initialModel, options, schemaOnChange, onValueChange, summariser } = _a, rest = __objRest(_a, ["uid", "checks", "initialModel", "options", "schemaOnChange", "onValueChange", "summariser"]);
5287
5116
  const children = options.map((option) => option.component);
5288
5117
  const matchingOptions = options.map(
5289
5118
  (option) => isPartialModelMatch(option.component.getSubmittableValueSync(), initialModel)
@@ -5344,7 +5173,7 @@ var createSelectInputComponent = (selectProps, updateComponent) => {
5344
5173
  draft.errors = [];
5345
5174
  draft.selectedIndex = updatedIndex;
5346
5175
  });
5347
- performRefresh == null ? void 0 : performRefresh();
5176
+ schemaOnChange == null ? void 0 : schemaOnChange();
5348
5177
  onValueChange();
5349
5178
  },
5350
5179
  validate() {
@@ -5416,7 +5245,7 @@ var oneOfSchemaToComponent = (schemaMapperProps, mapperProps) => {
5416
5245
  checks: schema.hidden ? [] : [getRequiredCheck(required, errorMessageFunctions)],
5417
5246
  options,
5418
5247
  initialModel,
5419
- performRefresh: getPerformRefresh(schema, onBehavior),
5248
+ schemaOnChange: getSchemaOnChange(schema, onBehavior),
5420
5249
  onValueChange,
5421
5250
  trackEvent
5422
5251
  }),
@@ -5435,25 +5264,26 @@ var createDateInputComponent = (textInputProps, updateComponent) => {
5435
5264
  uid,
5436
5265
  id,
5437
5266
  checks,
5438
- performPersistAsync,
5439
- performRefresh,
5267
+ schemaOnChange,
5440
5268
  performValidationAsync,
5441
5269
  onValueChange,
5270
+ onPersistAsync,
5442
5271
  summariser,
5443
5272
  value
5444
5273
  } = _a, rest = __objRest(_a, [
5445
5274
  "uid",
5446
5275
  "id",
5447
5276
  "checks",
5448
- "performPersistAsync",
5449
- "performRefresh",
5277
+ "schemaOnChange",
5450
5278
  "performValidationAsync",
5451
5279
  "onValueChange",
5280
+ "onPersistAsync",
5452
5281
  "summariser",
5453
5282
  "value"
5454
5283
  ]);
5455
5284
  const update = getInputUpdateFunction(updateComponent);
5456
5285
  const getValidationErrors = getLocalValueValidator(checks);
5286
+ const validateAsync = performValidationAsync ? getComponentValidationAsync(update, performValidationAsync) : void 0;
5457
5287
  const dateInputComponent = __spreadValues({
5458
5288
  type: "date",
5459
5289
  uid,
@@ -5463,7 +5293,11 @@ var createDateInputComponent = (textInputProps, updateComponent) => {
5463
5293
  update(this, updateFn);
5464
5294
  },
5465
5295
  onBlur() {
5466
- this.validate();
5296
+ const isValid = this.validate();
5297
+ if (isValid) {
5298
+ validateAsync == null ? void 0 : validateAsync(this, this.getLocalValue()).catch(() => {
5299
+ });
5300
+ }
5467
5301
  },
5468
5302
  onFocus() {
5469
5303
  },
@@ -5476,9 +5310,12 @@ var createDateInputComponent = (textInputProps, updateComponent) => {
5476
5310
  draft.value = updatedValue;
5477
5311
  });
5478
5312
  if (isOrWasValid(getValidationErrors, prevValue, updatedValue)) {
5479
- performRefresh == null ? void 0 : performRefresh();
5313
+ schemaOnChange == null ? void 0 : schemaOnChange();
5480
5314
  }
5481
5315
  onValueChange();
5316
+ if (getValidationErrors(updatedValue).length === 0) {
5317
+ onPersistAsync == null ? void 0 : onPersistAsync();
5318
+ }
5482
5319
  },
5483
5320
  async getSubmittableValue() {
5484
5321
  return this.getSubmittableValueSync();
@@ -5501,45 +5338,12 @@ var createDateInputComponent = (textInputProps, updateComponent) => {
5501
5338
  return errors.length === 0;
5502
5339
  }
5503
5340
  }, 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
5341
  return dateInputComponent;
5538
5342
  };
5539
5343
 
5540
5344
  // src/revamp/domain/mappers/schema/stringSchemaToComponent/stringSchemaToDateInputComponent.ts
5541
5345
  var stringSchemaToDateInputComponent = (schemaMapperProps, mapperProps) => {
5542
- const { schema, localValue, model, required = false } = schemaMapperProps;
5346
+ const { schema, localValue, model, required = false, onPersistAsync } = schemaMapperProps;
5543
5347
  const {
5544
5348
  autocompleteHint,
5545
5349
  default: defaultValue,
@@ -5549,17 +5353,13 @@ var stringSchemaToDateInputComponent = (schemaMapperProps, mapperProps) => {
5549
5353
  } = schema;
5550
5354
  const { getErrorMessageFunctions, updateComponent, onBehavior, onValueChange } = mapperProps;
5551
5355
  const errorMessageFunctions = getErrorMessageFunctions(schema.validationMessages);
5552
- const { performPersistAsync, persistedState } = getPersistAsyncInitialState(
5553
- schemaMapperProps,
5554
- mapperProps
5555
- );
5556
5356
  const { performValidationAsync, validationAsyncState } = getValidationAsyncInitialState(
5557
5357
  schemaMapperProps,
5558
5358
  mapperProps
5559
5359
  );
5560
5360
  const validLocalValue = isString(localValue) ? localValue : null;
5561
5361
  const validModel = isString(model) ? model : defaultValue != null ? defaultValue : null;
5562
- const value = performPersistAsync ? validLocalValue : validModel;
5362
+ const value = onPersistAsync ? validLocalValue : validModel;
5563
5363
  return createDateInputComponent(
5564
5364
  __spreadProps(__spreadValues({}, mapCommonSchemaProps(schemaMapperProps)), {
5565
5365
  autoComplete: getAutocompleteString(autocompleteHint),
@@ -5576,10 +5376,8 @@ var stringSchemaToDateInputComponent = (schemaMapperProps, mapperProps) => {
5576
5376
  }))
5577
5377
  } : void 0,
5578
5378
  value,
5579
- persistedState,
5580
5379
  validationAsyncState,
5581
- performPersistAsync,
5582
- performRefresh: getPerformRefresh(schema, onBehavior),
5380
+ schemaOnChange: getSchemaOnChange(schema, onBehavior),
5583
5381
  performValidationAsync,
5584
5382
  onValueChange
5585
5383
  }),
@@ -5594,8 +5392,6 @@ var stringSchemaToUploadInputComponent = (schemaMapperProps, mapperProps) => {
5594
5392
  const { accepts, autocompleteHint, cameraConfig, hidden, maxSize, source, validationMessages } = schema;
5595
5393
  const { getErrorMessageFunctions, updateComponent, onBehavior, onValueChange } = mapperProps;
5596
5394
  const errorMessageFunctions = getErrorMessageFunctions(validationMessages);
5597
- const { performPersistAsync } = getPersistAsyncInitialState(schemaMapperProps, mapperProps);
5598
- const persistedState = performPersistAsync ? getInitialPersistedState(null, model) : getInitialPersistedState();
5599
5395
  const validLocalValue = isFile(localValue) ? localValue : null;
5600
5396
  const value = (_a = getFileFromModel(model)) != null ? _a : validLocalValue;
5601
5397
  const checks = hidden ? [] : [
@@ -5613,9 +5409,7 @@ var stringSchemaToUploadInputComponent = (schemaMapperProps, mapperProps) => {
5613
5409
  maxSize,
5614
5410
  source,
5615
5411
  value,
5616
- persistedState,
5617
- performPersistAsync,
5618
- performRefresh: getPerformRefresh(schema, onBehavior),
5412
+ schemaOnChange: getSchemaOnChange(schema, onBehavior),
5619
5413
  onValueChange
5620
5414
  }),
5621
5415
  updateComponent
@@ -5629,26 +5423,27 @@ var createTextInputComponent = (textInputProps, updateComponent) => {
5629
5423
  uid,
5630
5424
  id,
5631
5425
  checks,
5632
- performPersistAsync,
5633
- performRefresh,
5426
+ schemaOnChange,
5634
5427
  performValidationAsync,
5635
5428
  onValueChange,
5429
+ onPersistAsync,
5636
5430
  summariser,
5637
5431
  value
5638
5432
  } = _a, rest = __objRest(_a, [
5639
5433
  "uid",
5640
5434
  "id",
5641
5435
  "checks",
5642
- "performPersistAsync",
5643
- "performRefresh",
5436
+ "schemaOnChange",
5644
5437
  "performValidationAsync",
5645
5438
  "onValueChange",
5439
+ "onPersistAsync",
5646
5440
  "summariser",
5647
5441
  "value"
5648
5442
  ]);
5649
5443
  const update = getInputUpdateFunction(updateComponent);
5650
5444
  const getValidationErrors = getLocalValueValidator(checks);
5651
- const performDebouncedRefresh = getDebouncedPerformRefresh(performRefresh, getValidationErrors);
5445
+ const performOnChange = getDebouncedSchemaOnChange(schemaOnChange, getValidationErrors);
5446
+ const validateAsync = performValidationAsync ? getDebouncedComponentValidationAsync(update, performValidationAsync) : void 0;
5652
5447
  const inputComponent = __spreadValues({
5653
5448
  type: "text",
5654
5449
  uid,
@@ -5658,8 +5453,12 @@ var createTextInputComponent = (textInputProps, updateComponent) => {
5658
5453
  update(this, updateFn);
5659
5454
  },
5660
5455
  onBlur() {
5661
- this.validate();
5662
- performDebouncedRefresh == null ? void 0 : performDebouncedRefresh.flush();
5456
+ const isValid = this.validate();
5457
+ performOnChange == null ? void 0 : performOnChange.flush();
5458
+ if (isValid) {
5459
+ onPersistAsync == null ? void 0 : onPersistAsync();
5460
+ validateAsync == null ? void 0 : validateAsync.flush();
5461
+ }
5663
5462
  },
5664
5463
  onFocus() {
5665
5464
  },
@@ -5671,7 +5470,14 @@ var createTextInputComponent = (textInputProps, updateComponent) => {
5671
5470
  draft.validationAsyncState.messages = {};
5672
5471
  draft.value = updatedValue;
5673
5472
  });
5674
- performDebouncedRefresh == null ? void 0 : performDebouncedRefresh(prevValue, updatedValue);
5473
+ performOnChange == null ? void 0 : performOnChange(prevValue, updatedValue);
5474
+ const isValid = getValidationErrors(updatedValue).length === 0;
5475
+ if (isValid) {
5476
+ validateAsync == null ? void 0 : validateAsync(this, updatedValue);
5477
+ }
5478
+ if (!updatedValue) {
5479
+ validateAsync == null ? void 0 : validateAsync.cancel();
5480
+ }
5675
5481
  onValueChange();
5676
5482
  },
5677
5483
  async getSubmittableValue() {
@@ -5694,51 +5500,12 @@ var createTextInputComponent = (textInputProps, updateComponent) => {
5694
5500
  return errors.length === 0;
5695
5501
  }
5696
5502
  }, 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
5503
  return inputComponent;
5737
5504
  };
5738
5505
 
5739
5506
  // src/revamp/domain/mappers/schema/stringSchemaToComponent/stringSchemaToTextInputComponent.ts
5740
5507
  var stringSchemaToTextInputComponent = (schemaMapperProps, mapperProps) => {
5741
- const { schema, localValue, model, required = false } = schemaMapperProps;
5508
+ const { schema, localValue, model, required = false, onPersistAsync } = schemaMapperProps;
5742
5509
  const {
5743
5510
  autocapitalization,
5744
5511
  autocompleteHint,
@@ -5754,17 +5521,13 @@ var stringSchemaToTextInputComponent = (schemaMapperProps, mapperProps) => {
5754
5521
  const { getErrorMessageFunctions, updateComponent, onBehavior, onValueChange, logEvent } = mapperProps;
5755
5522
  const controlForLegacyFormat = getControlForLegacyFormat(format);
5756
5523
  const errorMessageFunctions = getErrorMessageFunctions(validationMessages);
5757
- const { performPersistAsync, persistedState } = getPersistAsyncInitialState(
5758
- schemaMapperProps,
5759
- mapperProps
5760
- );
5761
5524
  const { performValidationAsync, validationAsyncState } = getValidationAsyncInitialState(
5762
5525
  schemaMapperProps,
5763
5526
  mapperProps
5764
5527
  );
5765
5528
  const validLocalValue = isString(localValue) ? localValue : null;
5766
5529
  const validModel = isString(model) ? model : defaultValue != null ? defaultValue : null;
5767
- const value = performPersistAsync ? validLocalValue : validModel;
5530
+ const value = onPersistAsync ? validLocalValue : validModel;
5768
5531
  return createTextInputComponent(
5769
5532
  __spreadProps(__spreadValues({}, mapCommonSchemaProps(schemaMapperProps)), {
5770
5533
  autocapitalization,
@@ -5785,10 +5548,8 @@ var stringSchemaToTextInputComponent = (schemaMapperProps, mapperProps) => {
5785
5548
  }))
5786
5549
  } : void 0,
5787
5550
  value,
5788
- persistedState,
5789
5551
  validationAsyncState,
5790
- performPersistAsync,
5791
- performRefresh: getPerformRefresh(schema, onBehavior),
5552
+ schemaOnChange: getSchemaOnChange(schema, onBehavior),
5792
5553
  performValidationAsync,
5793
5554
  onValueChange
5794
5555
  }),
@@ -5819,6 +5580,136 @@ var isStringSchemaWithBase64 = (schema) => {
5819
5580
  return schema.format === "base64url" && !("persistAsync" in schema);
5820
5581
  };
5821
5582
 
5583
+ // src/revamp/domain/components/utils/isExactLocalValueMatch.ts
5584
+ var isExactLocalValueMatch = (valueA, valueB) => {
5585
+ if (isArrayLocalValue(valueA) && isArrayLocalValue(valueB)) {
5586
+ return valueA.length === valueB.length && valueA.every((value, index) => isExactLocalValueMatch(value, valueB[index]));
5587
+ }
5588
+ if (isObjectLocalValue(valueA) && isObjectLocalValue(valueB)) {
5589
+ const keysA = Object.keys(valueA);
5590
+ const keysB = Object.keys(valueB);
5591
+ return keysA.length === keysB.length && keysA.every((key) => isExactLocalValueMatch(valueA[key], valueB[key]));
5592
+ }
5593
+ return valueA === valueB;
5594
+ };
5595
+
5596
+ // src/revamp/domain/components/PersistAsyncComponent.ts
5597
+ var createPersistAsyncComponent = (props, performPersistAsync, schemaOnChange, updateComponent) => {
5598
+ const { uid, schemaId, component, hidden, model, localValue } = props;
5599
+ const update = getInputUpdateFunction(updateComponent);
5600
+ const paComponent = {
5601
+ type: "persist-async",
5602
+ uid,
5603
+ schemaId,
5604
+ component,
5605
+ hidden,
5606
+ lastSubmitted: model != null ? localValue != null ? localValue : null : null,
5607
+ lastResponse: model != null ? model : null,
5608
+ submission: Promise.resolve(model != null ? model : null),
5609
+ abortController: new AbortController(),
5610
+ errors: [],
5611
+ _update(updateFn) {
5612
+ update(this, updateFn);
5613
+ },
5614
+ validate() {
5615
+ return this.component.validate();
5616
+ },
5617
+ getLocalValue() {
5618
+ return this.component.getLocalValue();
5619
+ },
5620
+ async getSubmittableValue() {
5621
+ return this.persist();
5622
+ },
5623
+ getSubmittableValueSync() {
5624
+ return this.lastResponse;
5625
+ },
5626
+ getSummary() {
5627
+ return this.component.getSummary();
5628
+ },
5629
+ async persist() {
5630
+ const childLocalValue = this.component.getLocalValue();
5631
+ if (isExactLocalValueMatch(childLocalValue, this.lastSubmitted)) {
5632
+ return this.submission;
5633
+ }
5634
+ const newAbortController = abortAndResetController(this.abortController);
5635
+ if (childLocalValue == null || childLocalValue === "") {
5636
+ const resolvedNull = Promise.resolve(null);
5637
+ this._update((draft) => {
5638
+ draft.abortController = newAbortController;
5639
+ draft.lastResponse = null;
5640
+ draft.lastSubmitted = childLocalValue;
5641
+ draft.submission = resolvedNull;
5642
+ draft.errors = [];
5643
+ });
5644
+ schemaOnChange == null ? void 0 : schemaOnChange();
5645
+ return resolvedNull;
5646
+ }
5647
+ const { signal } = newAbortController;
5648
+ const newSubmission = performPersistAsync({ value: childLocalValue, signal }).then((token) => {
5649
+ this._update((draft) => {
5650
+ draft.lastResponse = token;
5651
+ draft.errors = [];
5652
+ });
5653
+ schemaOnChange == null ? void 0 : schemaOnChange();
5654
+ return token;
5655
+ }).catch((error) => {
5656
+ if (error instanceof DOMException && error.name === "AbortError") {
5657
+ return null;
5658
+ }
5659
+ this._update((draft) => {
5660
+ draft.lastResponse = null;
5661
+ draft.lastSubmitted = null;
5662
+ draft.errors = error instanceof Error ? [error.message] : [];
5663
+ });
5664
+ throw error;
5665
+ });
5666
+ this._update((draft) => {
5667
+ draft.abortController = newAbortController;
5668
+ draft.lastSubmitted = childLocalValue;
5669
+ draft.lastResponse = null;
5670
+ draft.submission = newSubmission;
5671
+ draft.errors = [];
5672
+ });
5673
+ return newSubmission;
5674
+ }
5675
+ };
5676
+ return paComponent;
5677
+ };
5678
+
5679
+ // src/revamp/domain/mappers/schema/persistAsyncSchemaToComponent.ts
5680
+ var isSupported = (type) => ["boolean", "text", "date", "integer", "number", "upload"].includes(type);
5681
+ var persistAsyncSchemaToComponent = (schemaMapperProps, mapperProps) => {
5682
+ var _a;
5683
+ const { uid, schema, model, localValue } = schemaMapperProps;
5684
+ const { persistAsync } = schema;
5685
+ const performPersistAsync = getPerformPersistAsyncFn(schema, persistAsync, mapperProps);
5686
+ const onPersistAsync = () => {
5687
+ void paComponent.persist().catch(() => {
5688
+ });
5689
+ };
5690
+ const childComponent = mapSchemaToComponent(
5691
+ __spreadProps(__spreadValues({}, schemaMapperProps), { uid: `${uid}-persist`, schema: persistAsync.schema, onPersistAsync }),
5692
+ mapperProps
5693
+ );
5694
+ if (!isSupported(childComponent.type)) {
5695
+ return childComponent;
5696
+ }
5697
+ const paComponent = createPersistAsyncComponent(
5698
+ {
5699
+ uid,
5700
+ hidden: (_a = schema.hidden) != null ? _a : false,
5701
+ component: childComponent,
5702
+ schemaId: schema.$id,
5703
+ model,
5704
+ localValue
5705
+ },
5706
+ performPersistAsync,
5707
+ getSchemaOnChange(schema, mapperProps.onBehavior),
5708
+ mapperProps.updateComponent
5709
+ );
5710
+ return paComponent;
5711
+ };
5712
+
5822
5713
  // src/revamp/domain/mappers/mapSchemaToComponent.ts
5823
5714
  var mapSchemaToComponent = (schemaMapperProps, mapperProps) => {
5824
5715
  const { uid, schema } = schemaMapperProps;
@@ -5826,13 +5717,7 @@ var mapSchemaToComponent = (schemaMapperProps, mapperProps) => {
5826
5717
  return constSchemaToComponent(uid, __spreadProps(__spreadValues({}, schemaMapperProps), { schema }));
5827
5718
  }
5828
5719
  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
- );
5720
+ return persistAsyncSchemaToComponent(__spreadProps(__spreadValues({}, schemaMapperProps), { schema }), mapperProps);
5836
5721
  }
5837
5722
  if (isAllOfSchema(schema)) {
5838
5723
  return allOfSchemaToComponent(__spreadProps(__spreadValues({}, schemaMapperProps), { schema }), mapperProps);
@@ -5859,7 +5744,7 @@ var mapSchemaToComponent = (schemaMapperProps, mapperProps) => {
5859
5744
  return arraySchemaToComponent(__spreadProps(__spreadValues({}, schemaMapperProps), { schema }), mapperProps);
5860
5745
  }
5861
5746
  if (isBlobSchema(schema)) {
5862
- if (!schemaMapperProps.persistAsyncConfig) {
5747
+ if (!schemaMapperProps.onPersistAsync) {
5863
5748
  throw new Error(
5864
5749
  "Blob schemas can only be used as the schema of a persist async configuration."
5865
5750
  );
@@ -6061,8 +5946,8 @@ var executePoll = async (props) => {
6061
5946
 
6062
5947
  // src/revamp/flow/executeRefresh.ts
6063
5948
  var executeRefresh = async (props) => {
6064
- const { abortSignal, url, model, schemaId, etag, httpClient, trackEvent, logEvent } = props;
6065
- trackEvent("Refresh Triggered", { schema: schemaId });
5949
+ const { abortSignal, url, model, etag, analytics, httpClient, trackEvent, logEvent } = props;
5950
+ trackEvent("Refresh Triggered", analytics);
6066
5951
  try {
6067
5952
  const response = await httpClient(url != null ? url : "", {
6068
5953
  method: "POST",
@@ -6073,34 +5958,34 @@ var executeRefresh = async (props) => {
6073
5958
  signal: abortSignal
6074
5959
  });
6075
5960
  if (response.status === 304) {
6076
- trackEvent("Refresh Succeeded", { schema: schemaId });
5961
+ trackEvent("Refresh Succeeded", analytics);
6077
5962
  return { type: "noop" };
6078
5963
  }
6079
5964
  if (!response.ok) {
6080
5965
  const responseBody = await parseResponseBodyAsJsonElement(response).catch(() => ({}));
6081
5966
  const body2 = isErrorResponseBody(responseBody) ? responseBody : {};
6082
- trackEvent("Refresh Failed", __spreadProps(__spreadValues({}, body2.analytics), {
6083
- schema: schemaId,
5967
+ trackEvent("Refresh Failed", __spreadProps(__spreadValues(__spreadValues({}, analytics), body2.analytics), {
5968
+ statusCode: response.status
5969
+ }));
5970
+ logEvent("error", "Dynamic Flow - Refresh Failed", __spreadProps(__spreadValues({}, analytics), {
6084
5971
  statusCode: response.status
6085
5972
  }));
6086
- logEvent("error", "Dynamic Flow - Refresh Failed", { schemaId, statusCode: response.status });
6087
5973
  return { type: "error", body: body2, statusCode: response.status };
6088
5974
  }
6089
5975
  const newEtag = response.headers.get("etag") || null;
6090
5976
  const body = await parseResponseBodyAsJsonElement(response);
6091
5977
  assertStepResponseBody(body);
6092
- trackEvent("Refresh Succeeded", { schema: schemaId });
5978
+ trackEvent("Refresh Succeeded", analytics);
6093
5979
  return { type: "refresh-step", step: body, etag: newEtag };
6094
5980
  } catch (error) {
6095
5981
  if (error instanceof DOMException && error.name === "AbortError") {
6096
- trackEvent("Refresh Aborted", { schema: schemaId });
5982
+ trackEvent("Refresh Aborted", analytics);
6097
5983
  return { type: "noop" };
6098
5984
  }
6099
- trackEvent("Refresh Failed", { schema: schemaId });
6100
- logEvent("error", "Dynamic Flow - Refresh Failed", {
6101
- schemaId,
5985
+ trackEvent("Refresh Failed", analytics);
5986
+ logEvent("error", "Dynamic Flow - Refresh Failed", __spreadProps(__spreadValues({}, analytics), {
6102
5987
  errorMessage: getErrorMessage(error)
6103
- });
5988
+ }));
6104
5989
  return { type: "error", body: {} };
6105
5990
  }
6106
5991
  };
@@ -6579,7 +6464,7 @@ function useDynamicFlowCore(props) {
6579
6464
  break;
6580
6465
  }
6581
6466
  case "refresh": {
6582
- await onRefresh(behavior.schemaId, behavior.url);
6467
+ await onRefresh({ refreshUrl: behavior.url, analytics: behavior.analytics });
6583
6468
  break;
6584
6469
  }
6585
6470
  case "link": {
@@ -6666,7 +6551,7 @@ function useDynamicFlowCore(props) {
6666
6551
  }
6667
6552
  case "refresh": {
6668
6553
  const { refreshUrl, errors = {} } = command.body;
6669
- void onRefresh(void 0, refreshUrl, errors);
6554
+ void onRefresh({ refreshUrl, errorsOverride: errors });
6670
6555
  break;
6671
6556
  }
6672
6557
  case "behavior": {
@@ -6680,7 +6565,11 @@ function useDynamicFlowCore(props) {
6680
6565
  }
6681
6566
  }, []);
6682
6567
  const onRefresh = (0, import_react3.useCallback)(
6683
- async (schemaId, refreshUrl, errorsOverride) => {
6568
+ async ({
6569
+ refreshUrl,
6570
+ errorsOverride,
6571
+ analytics
6572
+ }) => {
6684
6573
  var _a2, _b;
6685
6574
  try {
6686
6575
  rootComponentRef.current.setLoadingState("refreshing");
@@ -6689,8 +6578,8 @@ function useDynamicFlowCore(props) {
6689
6578
  abortSignal: abortCurrentAndGetNewAbortSignal(),
6690
6579
  url: (_b = refreshUrl != null ? refreshUrl : rootComponentRef.current.getRefreshUrl()) != null ? _b : "",
6691
6580
  model,
6692
- schemaId,
6693
6581
  etag: etagRef.current,
6582
+ analytics,
6694
6583
  httpClient,
6695
6584
  trackEvent: trackCoreEvent,
6696
6585
  logEvent