@ngx-smz/core 21.0.4 → 21.1.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.
@@ -6262,6 +6262,7 @@ class FormGroupComponent {
6262
6262
  // this.viewdata.isValid = this.viewdata.form.valid;
6263
6263
  const runCustomFunctionsOnLoad = this.config.behaviors?.runCustomFunctionsOnLoad ?? false;
6264
6264
  let isStatusChangesEmitted = false;
6265
+ let data = null;
6265
6266
  // Esse if garante a execução do custom behaviour na primeira inicialização, já que com o adiamento feito no status changes abaixo,
6266
6267
  // ele não passa mais por la
6267
6268
  if (runCustomFunctionsOnLoad) {
@@ -6271,7 +6272,18 @@ class FormGroupComponent {
6271
6272
  else {
6272
6273
  if (!this.config.behaviors?.skipEmitChangesOnLoad) {
6273
6274
  isStatusChangesEmitted = true;
6274
- this.statusChanges.emit(this.getData());
6275
+ data = this.getData();
6276
+ this.statusChanges.emit(data);
6277
+ }
6278
+ }
6279
+ if (this.config.behaviors?.emitAllOutputsOnLoad) {
6280
+ if (data == null) {
6281
+ data = this.getData();
6282
+ }
6283
+ this.initialStateChanged.emit(data);
6284
+ this.previousStateChanged.emit(data);
6285
+ if (!isStatusChangesEmitted) {
6286
+ this.statusChanges.emit(data);
6275
6287
  }
6276
6288
  }
6277
6289
  this.callVisibilityFunctions();
@@ -6289,16 +6301,6 @@ class FormGroupComponent {
6289
6301
  });
6290
6302
  this.fixRadioBug();
6291
6303
  this.resetState();
6292
- if (this.config.behaviors?.emitAllOutputsOnLoad) {
6293
- setTimeout(() => {
6294
- const data = this.getData();
6295
- this.initialStateChanged.emit(data);
6296
- this.previousStateChanged.emit(data);
6297
- if (!isStatusChangesEmitted) {
6298
- this.statusChanges.emit(data);
6299
- }
6300
- }, 0);
6301
- }
6302
6304
  }, 0);
6303
6305
  }, 0);
6304
6306
  }, 0);
@@ -8988,7 +8990,17 @@ class CustomError {
8988
8990
  messages;
8989
8991
  redirectTo;
8990
8992
  static getErrorMessages(error) {
8991
- const isDebugMode = GlobalInjector.config.debugMode;
8993
+ const config = GlobalInjector.config;
8994
+ const isDebugMode = config.debugMode;
8995
+ if (config.rbkUtils.httpBehaviors.useCustomErrorMessages) {
8996
+ const errorMessages = config.rbkUtils.httpBehaviors.extractErrorMessageCallback(error);
8997
+ if (isDebugMode) {
8998
+ console.log('>> useCustomErrorMessages is true');
8999
+ console.log('>> api error response', error);
9000
+ console.log('>> extracted error messages', errorMessages);
9001
+ }
9002
+ return errorMessages;
9003
+ }
8992
9004
  const results = [];
8993
9005
  if (isDebugMode) {
8994
9006
  console.log('>> getErrorMessages(state)');
@@ -50794,6 +50806,91 @@ __decorate([
50794
50806
  Selector([AuthenticationState])
50795
50807
  ], TenantAuthenticationSelectors, "hasClaimAccess", null);
50796
50808
 
50809
+ function isStringArrayLike(value) {
50810
+ if (!Array.isArray(value)) {
50811
+ return false;
50812
+ }
50813
+ return value.every((entry) => typeof entry === 'string');
50814
+ }
50815
+ function isRfcProblemDetailsBaseLike(errorValue) {
50816
+ if (typeof errorValue !== 'object' || errorValue === null) {
50817
+ return false;
50818
+ }
50819
+ return true;
50820
+ }
50821
+ function isSafeExceptionResponseLike(errorValue, rfcTypeValue) {
50822
+ if (!isRfcProblemDetailsBaseLike(errorValue)) {
50823
+ return false;
50824
+ }
50825
+ const typedErrorValue = errorValue;
50826
+ const isCorrectType = typedErrorValue.type === rfcTypeValue;
50827
+ const isDetailString = typeof typedErrorValue.detail === 'string';
50828
+ const isErrorsAbsent = typeof typedErrorValue.errors === 'undefined';
50829
+ if (!isCorrectType) {
50830
+ return false;
50831
+ }
50832
+ if (!isDetailString) {
50833
+ return false;
50834
+ }
50835
+ if (!isErrorsAbsent) {
50836
+ return false;
50837
+ }
50838
+ return true;
50839
+ }
50840
+ function isValidationExceptionResponseLike(errorValue, rfcTypeValue) {
50841
+ if (!isRfcProblemDetailsBaseLike(errorValue)) {
50842
+ return false;
50843
+ }
50844
+ const typedErrorValue = errorValue;
50845
+ const isCorrectType = typedErrorValue.type === rfcTypeValue;
50846
+ const isDetailString = typeof typedErrorValue.detail === 'string';
50847
+ const errorsValue = typedErrorValue.errors;
50848
+ if (!isCorrectType) {
50849
+ return false;
50850
+ }
50851
+ if (!isDetailString) {
50852
+ return false;
50853
+ }
50854
+ if (typeof errorsValue !== 'object' || errorsValue === null || Array.isArray(errorsValue)) {
50855
+ return false;
50856
+ }
50857
+ const errorsRecord = errorsValue;
50858
+ const errorArrays = Object.values(errorsRecord);
50859
+ for (const errorArray of errorArrays) {
50860
+ if (!isStringArrayLike(errorArray)) {
50861
+ return false;
50862
+ }
50863
+ }
50864
+ return true;
50865
+ }
50866
+ function extractRfc9110ProblemDetails(error) {
50867
+ const errorMessages = [];
50868
+ const errorPayload = error instanceof HttpErrorResponse ? error.error : error;
50869
+ const rfcTypeValue = 'https://tools.ietf.org/html/rfc9110#section-15.5.1';
50870
+ if (isSafeExceptionResponseLike(errorPayload, rfcTypeValue)) {
50871
+ errorMessages.push(errorPayload.detail);
50872
+ return errorMessages;
50873
+ }
50874
+ if (isValidationExceptionResponseLike(errorPayload, rfcTypeValue)) {
50875
+ const validationDetail = errorPayload.detail;
50876
+ const errorItems = [];
50877
+ for (const errorValues of Object.values(errorPayload.errors)) {
50878
+ errorItems.push(...errorValues);
50879
+ }
50880
+ if (errorItems.length === 0) {
50881
+ errorMessages.push(validationDetail);
50882
+ return errorMessages;
50883
+ }
50884
+ errorMessages.push(validationDetail);
50885
+ errorMessages.push(...errorItems);
50886
+ return errorMessages;
50887
+ }
50888
+ if (typeof errorPayload === 'string') {
50889
+ errorMessages.push(errorPayload);
50890
+ }
50891
+ return errorMessages;
50892
+ }
50893
+
50797
50894
  /* eslint-disable @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-return, @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/explicit-function-return-type, @typescript-eslint/typedef, no-underscore-dangle, no-console, eqeqeq, @typescript-eslint/no-unused-vars, @typescript-eslint/no-useless-constructor, @typescript-eslint/explicit-member-accessibility, max-len, no-prototype-builtins, @typescript-eslint/no-shadow, @typescript-eslint/no-empty-object-type */
50798
50895
  class SmzUiHttpBehaviorsBuilder extends SmzBuilderUtilities {
50799
50896
  _builder;
@@ -50802,10 +50899,24 @@ class SmzUiHttpBehaviorsBuilder extends SmzBuilderUtilities {
50802
50899
  super();
50803
50900
  this._builder = _builder;
50804
50901
  }
50805
- useErrorToastNotifications() {
50902
+ useErrorHandlingAsToast() {
50806
50903
  this._builder._state.rbkUtils.httpBehaviors.defaultParameters.errorHandlingType = 'toast';
50807
50904
  return this.that;
50808
50905
  }
50906
+ useErrorHandlingAsDialog() {
50907
+ this._builder._state.rbkUtils.httpBehaviors.defaultParameters.errorHandlingType = 'dialog';
50908
+ return this.that;
50909
+ }
50910
+ useRfc9110ProblemDetails() {
50911
+ this._builder._state.rbkUtils.httpBehaviors.extractErrorMessageCallback = extractRfc9110ProblemDetails;
50912
+ this._builder._state.rbkUtils.httpBehaviors.useCustomErrorMessages = true;
50913
+ return this.that;
50914
+ }
50915
+ useCustomProblemDetails(extractor) {
50916
+ this._builder._state.rbkUtils.httpBehaviors.extractErrorMessageCallback = extractor;
50917
+ this._builder._state.rbkUtils.httpBehaviors.useCustomErrorMessages = true;
50918
+ return this.that;
50919
+ }
50809
50920
  get builder() {
50810
50921
  return this._builder;
50811
50922
  }
@@ -51097,6 +51208,8 @@ class SmzUiBuilder extends SmzBuilderUtilities {
51097
51208
  useWindowsAuthentication: false,
51098
51209
  mockedUserId: null
51099
51210
  },
51211
+ useCustomErrorMessages: false,
51212
+ extractErrorMessageCallback: (error) => [],
51100
51213
  },
51101
51214
  toastConfig: {
51102
51215
  severity: 'success',