@wix/bex-utils 2.58.0 → 2.60.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.
@@ -5173,7 +5173,7 @@ function reportErrorBi(errorHandler, params) {
5173
5173
  errorMessage,
5174
5174
  exceptionMessage,
5175
5175
  httpError,
5176
- error
5176
+ errorHandlerState
5177
5177
  } = errorAccessor;
5178
5178
  const config = httpError == null ? void 0 : httpError.config;
5179
5179
  biLogger.report(withoutDefaults(httpClientErrorSrc176Evid404)({
@@ -5191,11 +5191,11 @@ function reportErrorBi(errorHandler, params) {
5191
5191
  request_id: httpError == null ? void 0 : httpError.requestId,
5192
5192
  hasInternetConnection: onlineManager.onLine,
5193
5193
  pageUrl: webWindow == null || (_webWindow$location = webWindow.location) == null ? void 0 : _webWindow$location.href,
5194
- session_id: error == null ? void 0 : error._errorHandlerSessionId,
5194
+ session_id: errorHandlerState == null ? void 0 : errorHandlerState.sessionId,
5195
5195
  serverUrl: (config == null ? void 0 : config.url) || (requestOptions == null ? void 0 : requestOptions.url),
5196
5196
  method: (config == null ? void 0 : config.method) || (requestOptions == null ? void 0 : requestOptions.method) || "unknown",
5197
- entity_fqdn: config == null ? void 0 : config.entityFqdn,
5198
- method_fqn: config == null ? void 0 : config.methodFqn,
5197
+ entity_fqdn: (config == null ? void 0 : config.entityFqdn) || (requestOptions == null ? void 0 : requestOptions.entityFqdn),
5198
+ method_fqn: (config == null ? void 0 : config.methodFqn) || (requestOptions == null ? void 0 : requestOptions.methodFqn),
5199
5199
  server_artifactid: config == null ? void 0 : config.artifactId
5200
5200
  }));
5201
5201
  }
@@ -5407,9 +5407,14 @@ init_define_process_env();
5407
5407
 
5408
5408
  // ../../node_modules/@wix/error-handler/dist/esm/util/httpErrorDecoders.js
5409
5409
  init_define_process_env();
5410
+
5411
+ // ../../node_modules/@wix/error-handler/dist/esm/util/isObject.js
5412
+ init_define_process_env();
5410
5413
  function isObject(thing) {
5411
5414
  return thing != null;
5412
5415
  }
5416
+
5417
+ // ../../node_modules/@wix/error-handler/dist/esm/util/httpErrorDecoders.js
5413
5418
  function isHttpError(err) {
5414
5419
  return isObject(err) && err.response != null;
5415
5420
  }
@@ -5428,7 +5433,7 @@ function isObject2(thing) {
5428
5433
  function isSdkError(err) {
5429
5434
  return isObject2(err) && err.status != null;
5430
5435
  }
5431
- function toMinimalHttpError(err) {
5436
+ function sdkErrorToMinimalHttpError(err) {
5432
5437
  return {
5433
5438
  response: {
5434
5439
  data: {
@@ -5440,6 +5445,20 @@ function toMinimalHttpError(err) {
5440
5445
  };
5441
5446
  }
5442
5447
 
5448
+ // ../../node_modules/@wix/error-handler/dist/esm/util/responseErrorDecoders.js
5449
+ init_define_process_env();
5450
+ function responseToMinimalHttpError(err) {
5451
+ var _err$_errorHandlerSta;
5452
+ const data = (_err$_errorHandlerSta = err._errorHandlerState) == null ? void 0 : _err$_errorHandlerSta.responseData;
5453
+ return {
5454
+ response: {
5455
+ data,
5456
+ status: err.status
5457
+ },
5458
+ requestId: err.headers.get("X-Wix-Request-Id")
5459
+ };
5460
+ }
5461
+
5443
5462
  // ../../node_modules/@wix/error-handler/dist/esm/state/ErrorAccessor.js
5444
5463
  var ErrorAccessor = class {
5445
5464
  constructor(params) {
@@ -5451,7 +5470,10 @@ var ErrorAccessor = class {
5451
5470
  }
5452
5471
  get error() {
5453
5472
  var _a;
5454
- return (_a = this._error) != null ? _a : this._error = this.inputError instanceof Error ? this.inputError : null;
5473
+ const {
5474
+ inputError
5475
+ } = this;
5476
+ return (_a = this._error) != null ? _a : this._error = typeof Response !== "undefined" && inputError instanceof Response ? inputError : inputError instanceof Error ? inputError : null;
5455
5477
  }
5456
5478
  /**
5457
5479
  * The message of the JS error, for example: `Network Error`
@@ -5468,7 +5490,17 @@ var ErrorAccessor = class {
5468
5490
  const {
5469
5491
  inputError
5470
5492
  } = this;
5471
- return (_a = this._httpError) != null ? _a : this._httpError = isHttpError(inputError) ? inputError : isSdkError(inputError) ? toMinimalHttpError(inputError) : null;
5493
+ return (_a = this._httpError) != null ? _a : this._httpError = isHttpError(inputError) ? inputError : typeof Response !== "undefined" && inputError instanceof Response ? responseToMinimalHttpError(inputError) : isSdkError(inputError) ? sdkErrorToMinimalHttpError(inputError) : null;
5494
+ }
5495
+ get errorHandlerState() {
5496
+ var _a;
5497
+ const {
5498
+ error
5499
+ } = this;
5500
+ if (!error) {
5501
+ return null;
5502
+ }
5503
+ return (_a = error._errorHandlerState) != null ? _a : error._errorHandlerState = {};
5472
5504
  }
5473
5505
  /**
5474
5506
  * errno symbolic name** like `ENETUNREACH`, Not http status code
@@ -5636,7 +5668,7 @@ var translationsImportsMap = {
5636
5668
  ))),
5637
5669
  pt: () => Promise.resolve().then(() => __toESM(__require(
5638
5670
  /* webpackChunkName: "common-errors_pt-json" */
5639
- "./common-errors_pt-KN3WJMAE.mjs"
5671
+ "./common-errors_pt-VTB6AMOH.mjs"
5640
5672
  ))),
5641
5673
  ro: () => Promise.resolve().then(() => __toESM(__require(
5642
5674
  /* webpackChunkName: "common-errors_ro-json" */
@@ -5710,16 +5742,18 @@ var TranslationsState = class {
5710
5742
  disableAutoInit: true
5711
5743
  });
5712
5744
  this._initPromise = new Promise(async (resolve) => {
5745
+ var _this$i18n$on, _this$i18n2;
5713
5746
  let failedLoading = false;
5714
5747
  const onFailedLoading = (lng, _ns, err) => {
5748
+ var _this$i18n$off, _this$i18n;
5715
5749
  if (lng !== "en") {
5716
5750
  return;
5717
5751
  }
5718
- this.i18n.off("failedLoading", onFailedLoading);
5752
+ (_this$i18n$off = (_this$i18n = this.i18n).off) == null || _this$i18n$off.call(_this$i18n, "failedLoading", onFailedLoading);
5719
5753
  failedLoading = true;
5720
5754
  resolve(err);
5721
5755
  };
5722
- this.i18n.on("failedLoading", onFailedLoading);
5756
+ (_this$i18n$on = (_this$i18n2 = this.i18n).on) == null || _this$i18n$on.call(_this$i18n2, "failedLoading", onFailedLoading);
5723
5757
  try {
5724
5758
  await this.i18n.init();
5725
5759
  if (failedLoading) {
@@ -5752,7 +5786,7 @@ function reportErrorResolutionBi(errorHandler, params) {
5752
5786
  biLogger
5753
5787
  } = errorHandler;
5754
5788
  const {
5755
- error,
5789
+ errorHandlerState,
5756
5790
  applicationError
5757
5791
  } = errorAccessor;
5758
5792
  const code = applicationError == null ? void 0 : applicationError.code;
@@ -5760,7 +5794,7 @@ function reportErrorResolutionBi(errorHandler, params) {
5760
5794
  biLogger.report(withoutDefaults(httpClientErrorMappingSrc176Evid100)({
5761
5795
  error_opt_out: applicationErrorMapping === false,
5762
5796
  is_override_error: String(errorCodesMap != null),
5763
- session_id: error == null ? void 0 : error._errorHandlerSessionId
5797
+ session_id: errorHandlerState == null ? void 0 : errorHandlerState.sessionId
5764
5798
  }));
5765
5799
  }
5766
5800
 
@@ -5837,13 +5871,13 @@ function reportGetResolvedErrorBi(errorHandler, params) {
5837
5871
  translations
5838
5872
  } = errorHandler;
5839
5873
  const {
5840
- error
5874
+ errorHandlerState
5841
5875
  } = errorAccessor;
5842
5876
  const {
5843
5877
  consumerResolvedError
5844
5878
  } = errorResolution != null ? errorResolution : {};
5845
5879
  biLogger.report(withoutDefaults(getResolvedErrorSrc176Evid101)({
5846
- session_id: error == null ? void 0 : error._errorHandlerSessionId,
5880
+ session_id: errorHandlerState == null ? void 0 : errorHandlerState.sessionId,
5847
5881
  translated_message: message,
5848
5882
  action_text: action == null ? void 0 : action.text,
5849
5883
  is_consumer_resolved_error: consumerResolvedError != null,
@@ -5855,7 +5889,7 @@ function reportGetResolvedErrorBi(errorHandler, params) {
5855
5889
  // ../../node_modules/@wix/error-handler/dist/esm/error-handler/reportShowErrorBi.js
5856
5890
  init_define_process_env();
5857
5891
  function reportShowErrorBi(errorHandler, params) {
5858
- var _errorAccessor$error;
5892
+ var _errorAccessor$errorH;
5859
5893
  const {
5860
5894
  message,
5861
5895
  action,
@@ -5866,7 +5900,7 @@ function reportShowErrorBi(errorHandler, params) {
5866
5900
  translations
5867
5901
  } = errorHandler;
5868
5902
  biLogger.report(withoutDefaults(showErrorSrc176Evid102)({
5869
- session_id: (_errorAccessor$error = errorAccessor.error) == null ? void 0 : _errorAccessor$error._errorHandlerSessionId,
5903
+ session_id: (_errorAccessor$errorH = errorAccessor.errorHandlerState) == null ? void 0 : _errorAccessor$errorH.sessionId,
5870
5904
  displayed_message: message,
5871
5905
  displayed_action: action == null ? void 0 : action.text,
5872
5906
  action_was_provided: String((action == null ? void 0 : action.onClick) != null),
@@ -5933,9 +5967,9 @@ function reportErrorRetryBi(errorHandler, params) {
5933
5967
  errorAccessor
5934
5968
  } = params;
5935
5969
  const {
5936
- error
5970
+ errorHandlerState
5937
5971
  } = errorAccessor;
5938
- const sessionId = error == null ? void 0 : error._errorHandlerSessionId;
5972
+ const sessionId = errorHandlerState == null ? void 0 : errorHandlerState.sessionId;
5939
5973
  if (!sessionId) {
5940
5974
  return;
5941
5975
  }
@@ -5948,12 +5982,19 @@ function reportErrorRetryBi(errorHandler, params) {
5948
5982
  init_define_process_env();
5949
5983
  var ErrorHandlerV2 = class {
5950
5984
  constructor(_errorHandler) {
5985
+ var _this = this;
5951
5986
  _defineProperty(this, "errorHandler", void 0);
5952
- _defineProperty(this, "withErrorHandler", async (fn, errorCodesMap) => {
5953
- return this.errorHandler.withErrorHandler(fn, {
5987
+ _defineProperty(this, "withErrorHandler", async function(fn, errorCodesMap, options) {
5988
+ if (options === void 0) {
5989
+ options = {};
5990
+ }
5991
+ const {
5992
+ errorHandler
5993
+ } = _this;
5994
+ const ops = {
5954
5995
  errorCodesMap: {
5955
5996
  validationError: errorCodesMap,
5956
- statusCodeError: errorCodesMap,
5997
+ statusCodeError: options.statusCodesOverrides,
5957
5998
  applicationError: Object.entries(errorCodesMap).reduce((acc, _ref) => {
5958
5999
  let [key, value] = _ref;
5959
6000
  if (value) {
@@ -5961,9 +6002,23 @@ var ErrorHandlerV2 = class {
5961
6002
  }
5962
6003
  return acc;
5963
6004
  }, {}),
5964
- serverError: errorCodesMap.serverError
6005
+ serverError: options.serverErrorOverride
5965
6006
  }
5966
- });
6007
+ };
6008
+ const response = await errorHandler.withErrorHandler(fn, ops);
6009
+ if (typeof Response !== "undefined" && response instanceof Response) {
6010
+ const errorAccessor = new ErrorAccessor({
6011
+ error: response
6012
+ });
6013
+ errorHandler._setErrorHandlerErrorCodesMap(errorAccessor, ops);
6014
+ const {
6015
+ errorHandlerState
6016
+ } = errorAccessor;
6017
+ if (!response.ok && errorHandlerState) {
6018
+ errorHandlerState.responseData = await response.json().catch(() => null);
6019
+ }
6020
+ }
6021
+ return response;
5967
6022
  });
5968
6023
  _defineProperty(this, "getResolvedError", (error) => {
5969
6024
  var _a, _b;
@@ -5979,10 +6034,10 @@ var ErrorHandlerV2 = class {
5979
6034
  });
5980
6035
  const {
5981
6036
  httpError,
5982
- error: e
6037
+ errorHandlerState
5983
6038
  } = errorAccessor;
5984
6039
  const errorResolution = errorHandler._resolveError(errorAccessor);
5985
- const resolvedError = e == null ? void 0 : e._errorHandlerResolvedError;
6040
+ const resolvedError = errorHandlerState == null ? void 0 : errorHandlerState.resolvedError;
5986
6041
  const message = (_a = resolvedError == null ? void 0 : resolvedError.message) != null ? _a : fallbackMessage;
5987
6042
  const action = resolvedError == null ? void 0 : resolvedError.action;
5988
6043
  const requestId = (_b = resolvedError == null ? void 0 : resolvedError.requestId) != null ? _b : httpError == null ? void 0 : httpError.requestId;
@@ -6011,7 +6066,16 @@ var ErrorHandlerV2 = class {
6011
6066
  this.errorHandler.reportRetryAttempt(error);
6012
6067
  });
6013
6068
  _defineProperty(this, "handleError", (error, options) => {
6014
- this.errorHandler.handleError(error, options);
6069
+ const {
6070
+ errorHandler
6071
+ } = this;
6072
+ if (typeof Response !== "undefined" && error instanceof Response) {
6073
+ if (!error.ok) {
6074
+ errorHandler.handleError(error, options);
6075
+ }
6076
+ } else {
6077
+ errorHandler.handleError(error, options);
6078
+ }
6015
6079
  });
6016
6080
  this.errorHandler = _errorHandler;
6017
6081
  }
@@ -6072,7 +6136,10 @@ var ErrorHandler = class {
6072
6136
  try {
6073
6137
  return await fn();
6074
6138
  } catch (error) {
6075
- this._setErrorHandlerErrorCodesMap(error, options);
6139
+ const errorAccessor = new ErrorAccessor({
6140
+ error
6141
+ });
6142
+ this._setErrorHandlerErrorCodesMap(errorAccessor, options);
6076
6143
  if (define_process_env_default.NODE_ENV === "test" && !this._skipWaitTranslations) {
6077
6144
  await this.commonErrorsMapState.getInitPromise();
6078
6145
  }
@@ -6092,10 +6159,10 @@ var ErrorHandler = class {
6092
6159
  applicationError,
6093
6160
  validationError,
6094
6161
  httpError,
6095
- error: e
6162
+ errorHandlerState
6096
6163
  } = errorAccessor;
6097
6164
  const errorResolution = this._resolveError(errorAccessor);
6098
- const resolvedError = e == null ? void 0 : e._errorHandlerResolvedError;
6165
+ const resolvedError = errorHandlerState == null ? void 0 : errorHandlerState.resolvedError;
6099
6166
  const message = (_a2 = resolvedError == null ? void 0 : resolvedError.message) != null ? _a2 : fallbackMessage;
6100
6167
  reportGetResolvedErrorBi(this, {
6101
6168
  message,
@@ -6148,10 +6215,10 @@ var ErrorHandler = class {
6148
6215
  error
6149
6216
  });
6150
6217
  const {
6151
- error: e
6218
+ errorHandlerState
6152
6219
  } = errorAccessor;
6153
6220
  this._resolveError(errorAccessor);
6154
- const resolvedError = e == null ? void 0 : e._errorHandlerResolvedError;
6221
+ const resolvedError = errorHandlerState == null ? void 0 : errorHandlerState.resolvedError;
6155
6222
  const showErrorProps = {
6156
6223
  ...resolvedError,
6157
6224
  ...props
@@ -6197,43 +6264,40 @@ var ErrorHandler = class {
6197
6264
  }
6198
6265
  _setErrorHandlerSessionId(errorAccessor) {
6199
6266
  const {
6200
- error
6267
+ errorHandlerState
6201
6268
  } = errorAccessor;
6202
- if (!error) {
6269
+ if (!errorHandlerState) {
6203
6270
  return;
6204
6271
  }
6205
- error._errorHandlerSessionId = v4_default();
6272
+ errorHandlerState.sessionId = v4_default();
6206
6273
  }
6207
6274
  _setErrorHandlerResolvedError(errorAccessor, errorResolution) {
6208
6275
  const {
6209
- error
6276
+ errorHandlerState
6210
6277
  } = errorAccessor;
6211
- if (!error) {
6278
+ if (!errorHandlerState) {
6212
6279
  return;
6213
6280
  }
6214
- error._errorHandlerResolvedError = errorResolution.errorToShow;
6281
+ errorHandlerState.resolvedError = errorResolution.errorToShow;
6215
6282
  }
6216
- _setErrorHandlerErrorCodesMap(error, options) {
6283
+ _setErrorHandlerErrorCodesMap(errorAccessor, options) {
6217
6284
  if (options === void 0) {
6218
6285
  options = {};
6219
6286
  }
6220
6287
  const {
6221
6288
  errorCodesMap
6222
6289
  } = options;
6223
- const errorAccessor = new ErrorAccessor({
6224
- error
6225
- });
6226
6290
  reportErrorResolutionBi(this, {
6227
6291
  errorAccessor,
6228
6292
  errorCodesMap
6229
6293
  });
6230
6294
  const {
6231
- error: e
6295
+ errorHandlerState
6232
6296
  } = errorAccessor;
6233
- if (!e) {
6297
+ if (!errorHandlerState) {
6234
6298
  return;
6235
6299
  }
6236
- e._errorHandlerErrorCodesMap = errorCodesMap;
6300
+ errorHandlerState.errorCodesMap = errorCodesMap;
6237
6301
  }
6238
6302
  _isErrorHandlerDisabled() {
6239
6303
  const {
@@ -6243,14 +6307,14 @@ var ErrorHandler = class {
6243
6307
  }
6244
6308
  _resolveError(errorAccessor, options) {
6245
6309
  var _a;
6246
- var _errorAccessor$error;
6310
+ var _errorAccessor$errorH;
6247
6311
  if (options === void 0) {
6248
6312
  options = {};
6249
6313
  }
6250
6314
  if (this._isErrorHandlerDisabled()) {
6251
6315
  return;
6252
6316
  }
6253
- const errorCodesMap = (_a = options.errorCodesMap) != null ? _a : (_errorAccessor$error = errorAccessor.error) == null ? void 0 : _errorAccessor$error._errorHandlerErrorCodesMap;
6317
+ const errorCodesMap = (_a = options.errorCodesMap) != null ? _a : (_errorAccessor$errorH = errorAccessor.errorHandlerState) == null ? void 0 : _errorAccessor$errorH.errorCodesMap;
6254
6318
  const errorResolution = createErrorResolution(this, {
6255
6319
  errorAccessor,
6256
6320
  errorCodesMap