@merchi/cart 1.4.57 → 1.4.58
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,9 +1,9 @@
|
|
|
1
|
-
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
1
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
3
2
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
4
3
|
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
5
4
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
6
5
|
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
6
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
7
7
|
import { captureUnexpected } from '@merchi/error-catch';
|
|
8
8
|
|
|
9
9
|
/**
|
|
@@ -41,17 +41,26 @@ var OPERATIONS = {
|
|
|
41
41
|
export function reportCartFailure(error, source) {
|
|
42
42
|
var handledValidation = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
43
43
|
try {
|
|
44
|
+
// A UI callback returning only confirms display, not a validation failure.
|
|
45
|
+
// Keep this predicate aligned with error-catch safeOperationSuppression.
|
|
46
|
+
var failure = error;
|
|
47
|
+
var validation = false;
|
|
48
|
+
try {
|
|
49
|
+
validation = handledValidation && failure !== null && _typeof(failure) === 'object' && [400, 409, 422].includes(failure.statusCode) && [3, 5, 6, 7].includes(failure.errorCode);
|
|
50
|
+
} catch (_unused) {
|
|
51
|
+
// Classification must not prevent the reporter from handling this value.
|
|
52
|
+
}
|
|
44
53
|
captureUnexpected(error, {
|
|
45
54
|
source: 'manual',
|
|
46
55
|
digest: source,
|
|
47
56
|
operation: _objectSpread({
|
|
48
57
|
name: OPERATIONS[source],
|
|
49
|
-
outcome:
|
|
50
|
-
},
|
|
58
|
+
outcome: validation ? 'handled' : 'failed'
|
|
59
|
+
}, validation ? {
|
|
51
60
|
reason: 'validation'
|
|
52
61
|
} : {})
|
|
53
62
|
});
|
|
54
|
-
} catch (
|
|
63
|
+
} catch (_unused2) {
|
|
55
64
|
// Reporting must not replace the original failure.
|
|
56
65
|
}
|
|
57
66
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { configureFrontendErrors } from '@merchi/error-catch';
|
|
2
|
-
import { reportAddCartItemFailure } from './reportFailure';
|
|
2
|
+
import { reportAddCartItemFailure, reportCartFailure } from './reportFailure';
|
|
3
3
|
function apiError(statusCode, message) {
|
|
4
4
|
var error = new Error(message);
|
|
5
5
|
error.name = 'ApiError';
|
|
@@ -36,11 +36,40 @@ describe('reportAddCartItemFailure', function () {
|
|
|
36
36
|
source: 'manual',
|
|
37
37
|
operation: {
|
|
38
38
|
name: 'cart.add_item',
|
|
39
|
-
outcome: '
|
|
40
|
-
reason: 'validation'
|
|
39
|
+
outcome: 'failed'
|
|
41
40
|
}
|
|
42
41
|
});
|
|
43
42
|
});
|
|
43
|
+
it.each(['Load failed', 'Failed to fetch'])('does not label %s as handled validation', function (message) {
|
|
44
|
+
reportAddCartItemFailure(new TypeError(message), jest.fn());
|
|
45
|
+
expect(events).toHaveLength(1);
|
|
46
|
+
expect(events[0].operation).toEqual({
|
|
47
|
+
name: 'cart.add_item',
|
|
48
|
+
outcome: 'failed'
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
it.each([400, 409, 422])('preserves handled known-input suppression for status %s', function (status) {
|
|
52
|
+
for (var _i = 0, _arr = [3, 5, 6, 7]; _i < _arr.length; _i++) {
|
|
53
|
+
var code = _arr[_i];
|
|
54
|
+
var error = Object.assign(apiError(status, 'input error'), {
|
|
55
|
+
errorCode: code
|
|
56
|
+
});
|
|
57
|
+
reportAddCartItemFailure(error, jest.fn());
|
|
58
|
+
}
|
|
59
|
+
expect(events).toEqual([]);
|
|
60
|
+
});
|
|
61
|
+
it.each([[400, 2], [400, 0], [400, 1], [401, 3], [403, 3], [404, 3], [429, 3], [500, 3], [undefined, 3], [422, undefined], ['422', 3], [422, '3']])('retains unresolved API failure (%s, %s) without a validation label', function (statusCode, errorCode) {
|
|
62
|
+
var error = Object.assign(new Error('request failed'), {
|
|
63
|
+
statusCode: statusCode,
|
|
64
|
+
errorCode: errorCode
|
|
65
|
+
});
|
|
66
|
+
reportAddCartItemFailure(error, jest.fn());
|
|
67
|
+
expect(events).toHaveLength(1);
|
|
68
|
+
expect(events[0].operation).toEqual({
|
|
69
|
+
name: 'cart.add_item',
|
|
70
|
+
outcome: 'failed'
|
|
71
|
+
});
|
|
72
|
+
});
|
|
44
73
|
it('normalises a non-Error rejection and forwards the original value', function () {
|
|
45
74
|
var onError = jest.fn();
|
|
46
75
|
reportAddCartItemFailure('stock check failed', onError);
|
|
@@ -48,7 +77,11 @@ describe('reportAddCartItemFailure', function () {
|
|
|
48
77
|
expect(events[0]).toMatchObject({
|
|
49
78
|
digest: 'cart.addItem',
|
|
50
79
|
errorType: 'NonErrorException',
|
|
51
|
-
message: 'stock check failed'
|
|
80
|
+
message: 'stock check failed',
|
|
81
|
+
operation: {
|
|
82
|
+
name: 'cart.add_item',
|
|
83
|
+
outcome: 'failed'
|
|
84
|
+
}
|
|
52
85
|
});
|
|
53
86
|
});
|
|
54
87
|
it('skips an expected client error and still calls onError', function () {
|
|
@@ -58,6 +91,14 @@ describe('reportAddCartItemFailure', function () {
|
|
|
58
91
|
expect(onError).toHaveBeenCalledWith(error);
|
|
59
92
|
expect(events).toEqual([]);
|
|
60
93
|
});
|
|
94
|
+
it('retains validation-shaped failures without confirmed UI handling', function () {
|
|
95
|
+
reportCartFailure(apiError(422, 'input error'), 'cart.addItem');
|
|
96
|
+
expect(events).toHaveLength(1);
|
|
97
|
+
expect(events[0].operation).toEqual({
|
|
98
|
+
name: 'cart.add_item',
|
|
99
|
+
outcome: 'failed'
|
|
100
|
+
});
|
|
101
|
+
});
|
|
61
102
|
it('reports a server error', function () {
|
|
62
103
|
var error = apiError(500, 'cart service down');
|
|
63
104
|
var onError = jest.fn();
|
|
@@ -99,4 +140,32 @@ describe('reportCartFailure before error-catch is configured', function () {
|
|
|
99
140
|
expect(errorCatch.getDefaultFrontendErrorReporter()).toBeUndefined();
|
|
100
141
|
});
|
|
101
142
|
});
|
|
143
|
+
});
|
|
144
|
+
describe('classification failures', function () {
|
|
145
|
+
it('still calls the reporter when a diagnostic getter throws', function () {
|
|
146
|
+
jest.isolateModules(function () {
|
|
147
|
+
var capture = jest.fn();
|
|
148
|
+
jest.doMock('@merchi/error-catch', function () {
|
|
149
|
+
return {
|
|
150
|
+
captureUnexpected: capture
|
|
151
|
+
};
|
|
152
|
+
});
|
|
153
|
+
var reporting = require('./reportFailure');
|
|
154
|
+
var error = Object.defineProperty(new TypeError('Load failed'), 'statusCode', {
|
|
155
|
+
get: function get() {
|
|
156
|
+
throw new Error('unreadable status');
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
var callback = jest.fn();
|
|
160
|
+
reporting.reportAddCartItemFailure(error, callback);
|
|
161
|
+
expect(callback).toHaveBeenCalledWith(error);
|
|
162
|
+
expect(capture).toHaveBeenCalledWith(error, expect.objectContaining({
|
|
163
|
+
operation: {
|
|
164
|
+
name: 'cart.add_item',
|
|
165
|
+
outcome: 'failed'
|
|
166
|
+
}
|
|
167
|
+
}));
|
|
168
|
+
jest.dontMock('@merchi/error-catch');
|
|
169
|
+
});
|
|
170
|
+
});
|
|
102
171
|
});
|
|
@@ -7,12 +7,12 @@ exports.CART_FAILURE_SOURCES = void 0;
|
|
|
7
7
|
exports.reportAddCartItemFailure = reportAddCartItemFailure;
|
|
8
8
|
exports.reportCartFailure = reportCartFailure;
|
|
9
9
|
var _errorCatch = require("@merchi/error-catch");
|
|
10
|
-
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
11
10
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
12
11
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
13
12
|
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
14
13
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
15
14
|
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
15
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
16
16
|
/**
|
|
17
17
|
* Call-site tags recorded on the error-catch event.
|
|
18
18
|
*
|
|
@@ -48,17 +48,26 @@ var OPERATIONS = {
|
|
|
48
48
|
function reportCartFailure(error, source) {
|
|
49
49
|
var handledValidation = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
50
50
|
try {
|
|
51
|
+
// A UI callback returning only confirms display, not a validation failure.
|
|
52
|
+
// Keep this predicate aligned with error-catch safeOperationSuppression.
|
|
53
|
+
var failure = error;
|
|
54
|
+
var validation = false;
|
|
55
|
+
try {
|
|
56
|
+
validation = handledValidation && failure !== null && _typeof(failure) === 'object' && [400, 409, 422].includes(failure.statusCode) && [3, 5, 6, 7].includes(failure.errorCode);
|
|
57
|
+
} catch (_unused) {
|
|
58
|
+
// Classification must not prevent the reporter from handling this value.
|
|
59
|
+
}
|
|
51
60
|
(0, _errorCatch.captureUnexpected)(error, {
|
|
52
61
|
source: 'manual',
|
|
53
62
|
digest: source,
|
|
54
63
|
operation: _objectSpread({
|
|
55
64
|
name: OPERATIONS[source],
|
|
56
|
-
outcome:
|
|
57
|
-
},
|
|
65
|
+
outcome: validation ? 'handled' : 'failed'
|
|
66
|
+
}, validation ? {
|
|
58
67
|
reason: 'validation'
|
|
59
68
|
} : {})
|
|
60
69
|
});
|
|
61
|
-
} catch (
|
|
70
|
+
} catch (_unused2) {
|
|
62
71
|
// Reporting must not replace the original failure.
|
|
63
72
|
}
|
|
64
73
|
}
|
package/package.json
CHANGED
|
@@ -43,10 +43,34 @@ describe('reportAddCartItemFailure', () => {
|
|
|
43
43
|
errorType: 'TypeError',
|
|
44
44
|
message: 'cart item create failed',
|
|
45
45
|
source: 'manual',
|
|
46
|
-
operation: { name: 'cart.add_item', outcome: '
|
|
46
|
+
operation: { name: 'cart.add_item', outcome: 'failed' },
|
|
47
47
|
});
|
|
48
48
|
});
|
|
49
49
|
|
|
50
|
+
it.each(['Load failed', 'Failed to fetch'])('does not label %s as handled validation', (message) => {
|
|
51
|
+
reportAddCartItemFailure(new TypeError(message), jest.fn());
|
|
52
|
+
expect(events).toHaveLength(1);
|
|
53
|
+
expect(events[0].operation).toEqual({ name: 'cart.add_item', outcome: 'failed' });
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it.each([400, 409, 422])('preserves handled known-input suppression for status %s', (status) => {
|
|
57
|
+
for (const code of [3, 5, 6, 7]) {
|
|
58
|
+
const error = Object.assign(apiError(status, 'input error'), { errorCode: code });
|
|
59
|
+
reportAddCartItemFailure(error, jest.fn());
|
|
60
|
+
}
|
|
61
|
+
expect(events).toEqual([]);
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it.each([
|
|
65
|
+
[400, 2], [400, 0], [400, 1], [401, 3], [403, 3], [404, 3],
|
|
66
|
+
[429, 3], [500, 3], [undefined, 3], [422, undefined], ['422', 3], [422, '3'],
|
|
67
|
+
])('retains unresolved API failure (%s, %s) without a validation label', (statusCode, errorCode) => {
|
|
68
|
+
const error = Object.assign(new Error('request failed'), { statusCode, errorCode });
|
|
69
|
+
reportAddCartItemFailure(error, jest.fn());
|
|
70
|
+
expect(events).toHaveLength(1);
|
|
71
|
+
expect(events[0].operation).toEqual({ name: 'cart.add_item', outcome: 'failed' });
|
|
72
|
+
});
|
|
73
|
+
|
|
50
74
|
it('normalises a non-Error rejection and forwards the original value', () => {
|
|
51
75
|
const onError = jest.fn();
|
|
52
76
|
|
|
@@ -57,6 +81,7 @@ describe('reportAddCartItemFailure', () => {
|
|
|
57
81
|
digest: 'cart.addItem',
|
|
58
82
|
errorType: 'NonErrorException',
|
|
59
83
|
message: 'stock check failed',
|
|
84
|
+
operation: { name: 'cart.add_item', outcome: 'failed' },
|
|
60
85
|
});
|
|
61
86
|
});
|
|
62
87
|
|
|
@@ -70,6 +95,12 @@ describe('reportAddCartItemFailure', () => {
|
|
|
70
95
|
expect(events).toEqual([]);
|
|
71
96
|
});
|
|
72
97
|
|
|
98
|
+
it('retains validation-shaped failures without confirmed UI handling', () => {
|
|
99
|
+
reportCartFailure(apiError(422, 'input error'), 'cart.addItem');
|
|
100
|
+
expect(events).toHaveLength(1);
|
|
101
|
+
expect(events[0].operation).toEqual({ name: 'cart.add_item', outcome: 'failed' });
|
|
102
|
+
});
|
|
103
|
+
|
|
73
104
|
it('reports a server error', () => {
|
|
74
105
|
const error = apiError(500, 'cart service down');
|
|
75
106
|
const onError = jest.fn();
|
|
@@ -109,3 +140,23 @@ describe('reportCartFailure before error-catch is configured', () => {
|
|
|
109
140
|
});
|
|
110
141
|
});
|
|
111
142
|
});
|
|
143
|
+
|
|
144
|
+
describe('classification failures', () => {
|
|
145
|
+
it('still calls the reporter when a diagnostic getter throws', () => {
|
|
146
|
+
jest.isolateModules(() => {
|
|
147
|
+
const capture = jest.fn();
|
|
148
|
+
jest.doMock('@merchi/error-catch', () => ({ captureUnexpected: capture }));
|
|
149
|
+
const reporting = require('./reportFailure');
|
|
150
|
+
const error = Object.defineProperty(new TypeError('Load failed'), 'statusCode', {
|
|
151
|
+
get() { throw new Error('unreadable status'); },
|
|
152
|
+
});
|
|
153
|
+
const callback = jest.fn();
|
|
154
|
+
reporting.reportAddCartItemFailure(error, callback);
|
|
155
|
+
expect(callback).toHaveBeenCalledWith(error);
|
|
156
|
+
expect(capture).toHaveBeenCalledWith(error, expect.objectContaining({
|
|
157
|
+
operation: { name: 'cart.add_item', outcome: 'failed' },
|
|
158
|
+
}));
|
|
159
|
+
jest.dontMock('@merchi/error-catch');
|
|
160
|
+
});
|
|
161
|
+
});
|
|
162
|
+
});
|
|
@@ -35,13 +35,24 @@ export type CartFailureSource =
|
|
|
35
35
|
*/
|
|
36
36
|
export function reportCartFailure(error: unknown, source: CartFailureSource, handledValidation = false): void {
|
|
37
37
|
try {
|
|
38
|
+
// A UI callback returning only confirms display, not a validation failure.
|
|
39
|
+
// Keep this predicate aligned with error-catch safeOperationSuppression.
|
|
40
|
+
const failure = error as { statusCode?: unknown; errorCode?: unknown } | null;
|
|
41
|
+
let validation = false;
|
|
42
|
+
try {
|
|
43
|
+
validation = handledValidation && failure !== null && typeof failure === 'object' &&
|
|
44
|
+
[400, 409, 422].includes(failure.statusCode as number) &&
|
|
45
|
+
[3, 5, 6, 7].includes(failure.errorCode as number);
|
|
46
|
+
} catch {
|
|
47
|
+
// Classification must not prevent the reporter from handling this value.
|
|
48
|
+
}
|
|
38
49
|
captureUnexpected(error, {
|
|
39
50
|
source: 'manual',
|
|
40
51
|
digest: source,
|
|
41
52
|
operation: {
|
|
42
53
|
name: OPERATIONS[source],
|
|
43
|
-
outcome:
|
|
44
|
-
...(
|
|
54
|
+
outcome: validation ? 'handled' : 'failed',
|
|
55
|
+
...(validation ? { reason: 'validation' as const } : {}),
|
|
45
56
|
},
|
|
46
57
|
});
|
|
47
58
|
} catch {
|