@open-tender/utils 0.1.85 → 0.1.87

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.
@@ -1,4 +1,4 @@
1
- import { RequestError } from '@open-tender/types';
1
+ import { CheckoutError, CheckoutErrorParams, RequestError } from '@open-tender/types';
2
2
  export declare const handleRespError: (err: RequestError) => {
3
3
  title: string;
4
4
  detail: string | undefined;
@@ -12,6 +12,7 @@ export declare const processError: (msg: string | null) => string;
12
12
  export declare const handleFormErrors: (params: Record<string, string | null>) => Record<string, string>;
13
13
  export declare const makeFormErrors: (error: RequestError) => Record<string, string>;
14
14
  export declare const handleCheckoutErrors: (errors: RequestError, asMessages?: boolean) => Record<string, unknown>;
15
+ export declare const makeCheckError: (params: CheckoutErrorParams) => CheckoutError;
15
16
  export declare const errMessages: {
16
17
  unknown: string;
17
18
  forbidden: string;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.errMessages = exports.handleCheckoutErrors = exports.makeFormErrors = exports.handleFormErrors = exports.processError = exports.handleRespError = void 0;
3
+ exports.errMessages = exports.makeCheckError = exports.handleCheckoutErrors = exports.makeFormErrors = exports.handleFormErrors = exports.processError = exports.handleRespError = void 0;
4
4
  const helpers_1 = require("./helpers");
5
5
  const handleRespError = (err) => {
6
6
  const error = typeof err === 'string' ? { detail: err } : err;
@@ -112,6 +112,19 @@ const handleCheckoutErrors = (errors, asMessages = true) => {
112
112
  return errObj;
113
113
  };
114
114
  exports.handleCheckoutErrors = handleCheckoutErrors;
115
+ const makeCheckError = (params) => {
116
+ if (!params || (0, helpers_1.isEmpty)(params))
117
+ return null;
118
+ const error = {
119
+ code: 'CHECK_ERRORS',
120
+ detail: 'The parameters of your request were invalid.',
121
+ status: 400,
122
+ title: 'Checkout Errors',
123
+ params
124
+ };
125
+ return error;
126
+ };
127
+ exports.makeCheckError = makeCheckError;
115
128
  exports.errMessages = {
116
129
  unknown: 'Unknown error. Please contact Open Tender support.',
117
130
  forbidden: 'Your account does not have access to this page. Please contact your brand admin to request access.',
@@ -1,4 +1,4 @@
1
- import { RequestError } from '@open-tender/types';
1
+ import { CheckoutError, CheckoutErrorParams, RequestError } from '@open-tender/types';
2
2
  export declare const handleRespError: (err: RequestError) => {
3
3
  title: string;
4
4
  detail: string | undefined;
@@ -12,6 +12,7 @@ export declare const processError: (msg: string | null) => string;
12
12
  export declare const handleFormErrors: (params: Record<string, string | null>) => Record<string, string>;
13
13
  export declare const makeFormErrors: (error: RequestError) => Record<string, string>;
14
14
  export declare const handleCheckoutErrors: (errors: RequestError, asMessages?: boolean) => Record<string, unknown>;
15
+ export declare const makeCheckError: (params: CheckoutErrorParams) => CheckoutError;
15
16
  export declare const errMessages: {
16
17
  unknown: string;
17
18
  forbidden: string;
@@ -104,6 +104,18 @@ export const handleCheckoutErrors = (errors, asMessages = true) => {
104
104
  }, { form: 'There are one or more errors below' });
105
105
  return errObj;
106
106
  };
107
+ export const makeCheckError = (params) => {
108
+ if (!params || isEmpty(params))
109
+ return null;
110
+ const error = {
111
+ code: 'CHECK_ERRORS',
112
+ detail: 'The parameters of your request were invalid.',
113
+ status: 400,
114
+ title: 'Checkout Errors',
115
+ params
116
+ };
117
+ return error;
118
+ };
107
119
  export const errMessages = {
108
120
  unknown: 'Unknown error. Please contact Open Tender support.',
109
121
  forbidden: 'Your account does not have access to this page. Please contact your brand admin to request access.',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@open-tender/utils",
3
- "version": "0.1.85",
3
+ "version": "0.1.87",
4
4
  "description": "A library of utils for use with Open Tender applications that utilize our cloud-based Order API.",
5
5
  "main": "./dist/cjs/index.js",
6
6
  "module": "./dist/esm/index.js",