@commercetools-frontend/actions-global 0.0.0-CRAFT-1791-20251006162610

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 (24) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +13 -0
  3. package/dist/commercetools-frontend-actions-global.cjs.d.ts +2 -0
  4. package/dist/commercetools-frontend-actions-global.cjs.dev.js +226 -0
  5. package/dist/commercetools-frontend-actions-global.cjs.js +7 -0
  6. package/dist/commercetools-frontend-actions-global.cjs.prod.js +216 -0
  7. package/dist/commercetools-frontend-actions-global.esm.js +196 -0
  8. package/dist/declarations/src/actions/handle-action-error.d.ts +27 -0
  9. package/dist/declarations/src/actions/hide-all-page-notifications.d.ts +6 -0
  10. package/dist/declarations/src/actions/index.d.ts +5 -0
  11. package/dist/declarations/src/actions/show-api-error-notification.d.ts +8 -0
  12. package/dist/declarations/src/actions/show-notification.d.ts +3 -0
  13. package/dist/declarations/src/actions/show-unexpected-error-notification.d.ts +8 -0
  14. package/dist/declarations/src/export-types.d.ts +2 -0
  15. package/dist/declarations/src/hooks/index.d.ts +5 -0
  16. package/dist/declarations/src/hooks/use-hide-all-page-notifications.d.ts +3 -0
  17. package/dist/declarations/src/hooks/use-on-action-error.d.ts +2 -0
  18. package/dist/declarations/src/hooks/use-show-api-error-notification.d.ts +15 -0
  19. package/dist/declarations/src/hooks/use-show-notification.d.ts +41 -0
  20. package/dist/declarations/src/hooks/use-show-unexpected-error-notification.d.ts +15 -0
  21. package/dist/declarations/src/index.d.ts +5 -0
  22. package/dist/declarations/src/types.d.ts +19 -0
  23. package/dist/declarations/src/version.d.ts +2 -0
  24. package/package.json +55 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) commercetools GmbH
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,13 @@
1
+ # @commercetools-frontend/actions-global
2
+
3
+ <p align="center">
4
+ <a href="https://www.npmjs.com/package/@commercetools-frontend/actions-global"><img src="https://badgen.net/npm/v/@commercetools-frontend/actions-global" alt="Latest release (latest dist-tag)" /></a> <a href="https://www.npmjs.com/package/@commercetools-frontend/actions-global"><img src="https://badgen.net/npm/v/@commercetools-frontend/actions-global/next" alt="Latest release (next dist-tag)" /></a> <a href="https://bundlephobia.com/result?p=@commercetools-frontend/actions-global"><img src="https://badgen.net/bundlephobia/minzip/@commercetools-frontend/actions-global" alt="Minified + GZipped size" /></a> <a href="https://github.com/commercetools/merchant-center-application-kit/blob/main/LICENSE"><img src="https://badgen.net/github/license/commercetools/merchant-center-application-kit" alt="GitHub license" /></a>
5
+ </p>
6
+
7
+ Global redux actions for Merchant Center customizations.
8
+
9
+ ## Install
10
+
11
+ ```bash
12
+ $ npm install --save @commercetools-frontend/actions-global
13
+ ```
@@ -0,0 +1,2 @@
1
+ export * from "./declarations/src/index.js";
2
+ //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY29tbWVyY2V0b29scy1mcm9udGVuZC1hY3Rpb25zLWdsb2JhbC5janMuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4vZGVjbGFyYXRpb25zL3NyYy9pbmRleC5kLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBIn0=
@@ -0,0 +1,226 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var history = require('@commercetools-frontend/browser-history');
6
+ var constants = require('@commercetools-frontend/constants');
7
+ var sentry = require('@commercetools-frontend/sentry');
8
+ var _Array$isArray = require('@babel/runtime-corejs3/core-js-stable/array/is-array');
9
+ var _defineProperty = require('@babel/runtime-corejs3/helpers/defineProperty');
10
+ var _includesInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/includes');
11
+ var _Object$values = require('@babel/runtime-corejs3/core-js-stable/object/values');
12
+ var _Object$keys = require('@babel/runtime-corejs3/core-js-stable/object/keys');
13
+ var _Object$getOwnPropertySymbols = require('@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols');
14
+ var _filterInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/filter');
15
+ var _Object$getOwnPropertyDescriptor = require('@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor');
16
+ var _forEachInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/for-each');
17
+ var _Object$getOwnPropertyDescriptors = require('@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptors');
18
+ var _Object$defineProperties = require('@babel/runtime-corejs3/core-js-stable/object/define-properties');
19
+ var _Object$defineProperty = require('@babel/runtime-corejs3/core-js-stable/object/define-property');
20
+ var isNumber = require('lodash/isNumber');
21
+ var notifications = require('@commercetools-frontend/notifications');
22
+ var react = require('react');
23
+ var reactRedux = require('react-redux');
24
+
25
+ function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
26
+
27
+ var history__default = /*#__PURE__*/_interopDefault(history);
28
+ var _Array$isArray__default = /*#__PURE__*/_interopDefault(_Array$isArray);
29
+ var _includesInstanceProperty__default = /*#__PURE__*/_interopDefault(_includesInstanceProperty);
30
+ var _Object$values__default = /*#__PURE__*/_interopDefault(_Object$values);
31
+ var _Object$keys__default = /*#__PURE__*/_interopDefault(_Object$keys);
32
+ var _Object$getOwnPropertySymbols__default = /*#__PURE__*/_interopDefault(_Object$getOwnPropertySymbols);
33
+ var _filterInstanceProperty__default = /*#__PURE__*/_interopDefault(_filterInstanceProperty);
34
+ var _Object$getOwnPropertyDescriptor__default = /*#__PURE__*/_interopDefault(_Object$getOwnPropertyDescriptor);
35
+ var _forEachInstanceProperty__default = /*#__PURE__*/_interopDefault(_forEachInstanceProperty);
36
+ var _Object$getOwnPropertyDescriptors__default = /*#__PURE__*/_interopDefault(_Object$getOwnPropertyDescriptors);
37
+ var _Object$defineProperties__default = /*#__PURE__*/_interopDefault(_Object$defineProperties);
38
+ var _Object$defineProperty__default = /*#__PURE__*/_interopDefault(_Object$defineProperty);
39
+ var isNumber__default = /*#__PURE__*/_interopDefault(isNumber);
40
+
41
+ // NOTE: This string will be replaced on build time with the package version.
42
+ var version = "24.7.2";
43
+
44
+ function ownKeys$1(e, r) { var t = _Object$keys__default["default"](e); if (_Object$getOwnPropertySymbols__default["default"]) { var o = _Object$getOwnPropertySymbols__default["default"](e); r && (o = _filterInstanceProperty__default["default"](o).call(o, function (r) { return _Object$getOwnPropertyDescriptor__default["default"](e, r).enumerable; })), t.push.apply(t, o); } return t; }
45
+ function _objectSpread$1(e) { for (var r = 1; r < arguments.length; r++) { var _context2, _context3; var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? _forEachInstanceProperty__default["default"](_context2 = ownKeys$1(Object(t), !0)).call(_context2, function (r) { _defineProperty(e, r, t[r]); }) : _Object$getOwnPropertyDescriptors__default["default"] ? _Object$defineProperties__default["default"](e, _Object$getOwnPropertyDescriptors__default["default"](t)) : _forEachInstanceProperty__default["default"](_context3 = ownKeys$1(Object(t))).call(_context3, function (r) { _Object$defineProperty__default["default"](e, r, _Object$getOwnPropertyDescriptor__default["default"](t, r)); }); } return e; }
46
+ function showNotification(notification) {
47
+ let meta = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
48
+ if (process.env.NODE_ENV !== 'production') if (notification.domain) {
49
+ var _context;
50
+ if (!_includesInstanceProperty__default["default"](_context = _Object$values__default["default"](constants.NOTIFICATION_DOMAINS)).call(_context, notification.domain))
51
+ // eslint-disable-next-line no-console
52
+ console.warn(`Unknown notification domain "${notification.domain}"`, notification);
53
+ }
54
+ // eslint-disable-next-line no-console
55
+ else console.warn('Notification is missing domain', notification);
56
+ let dismissAfter = meta.dismissAfter;
57
+ if (!isNumber__default["default"](dismissAfter)) dismissAfter = notification.kind === constants.NOTIFICATION_KINDS_SIDE.success ? 5000 : 0;
58
+ return notifications.addNotification(notification, _objectSpread$1(_objectSpread$1({}, meta), {}, {
59
+ dismissAfter
60
+ }));
61
+ }
62
+
63
+ function showApiErrorNotification(_ref) {
64
+ let errors = _ref.errors;
65
+ return showNotification({
66
+ id: 0,
67
+ domain: constants.DOMAINS.PAGE,
68
+ kind: 'api-error',
69
+ values: {
70
+ // NOTE: Some sources or errors (e.g. GraphQL) return an array or object.
71
+ // The cast into an array happens here so that consumers can pass both types.
72
+ errors: _Array$isArray__default["default"](errors) ? errors : [errors]
73
+ }
74
+ }, {
75
+ dismissAfter: 0
76
+ });
77
+ }
78
+
79
+ function showUnexpectedErrorNotification() {
80
+ let _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
81
+ errorId = _ref.errorId;
82
+ return showNotification({
83
+ id: 0,
84
+ domain: constants.DOMAINS.PAGE,
85
+ kind: 'unexpected-error',
86
+ values: {
87
+ errorId
88
+ }
89
+ }, {
90
+ dismissAfter: 0
91
+ });
92
+ }
93
+
94
+ function isApiError(error) {
95
+ return error.body !== undefined;
96
+ }
97
+ function handleActionError(error) {
98
+ return dispatch => {
99
+ // On production we send the errors to Sentry.
100
+ // eslint-disable-next-line no-console
101
+ if (window.app.env !== 'production') console.error(error, error instanceof Error && error.stack);
102
+ if (!isApiError(error)) {
103
+ const errorId = sentry.reportErrorToSentry(error);
104
+ return dispatch(showUnexpectedErrorNotification({
105
+ errorId
106
+ }));
107
+ }
108
+
109
+ // When unauthorized, log the user out.
110
+ if (error.statusCode === constants.STATUS_CODES.UNAUTHORIZED) {
111
+ history__default["default"].push(`/logout?reason=${constants.LOGOUT_REASONS.UNAUTHORIZED}`);
112
+ }
113
+
114
+ // We need to do the return, because if not we see an error notification
115
+ // The error is handled with the handleUnavailableResource HoC to show the PageNotFound component
116
+ // when the api returns 404
117
+ if (error.statusCode === constants.STATUS_CODES.NOT_FOUND) return null;
118
+ return dispatch(showApiErrorNotification({
119
+ errors: error.body.errors || [
120
+ // Pass a fallback error so that our error components can handle it
121
+ {
122
+ message: error.body.message
123
+ }]
124
+ }));
125
+ };
126
+ }
127
+
128
+ function hideAllPageNotifications() {
129
+ return {
130
+ type: constants.HIDE_ALL_PAGE_NOTIFICATIONS
131
+ };
132
+ }
133
+
134
+ function ownKeys(e, r) { var t = _Object$keys__default["default"](e); if (_Object$getOwnPropertySymbols__default["default"]) { var o = _Object$getOwnPropertySymbols__default["default"](e); r && (o = _filterInstanceProperty__default["default"](o).call(o, function (r) { return _Object$getOwnPropertyDescriptor__default["default"](e, r).enumerable; })), t.push.apply(t, o); } return t; }
135
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var _context, _context2; var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? _forEachInstanceProperty__default["default"](_context = ownKeys(Object(t), !0)).call(_context, function (r) { _defineProperty(e, r, t[r]); }) : _Object$getOwnPropertyDescriptors__default["default"] ? _Object$defineProperties__default["default"](e, _Object$getOwnPropertyDescriptors__default["default"](t)) : _forEachInstanceProperty__default["default"](_context2 = ownKeys(Object(t))).call(_context2, function (r) { _Object$defineProperty__default["default"](e, r, _Object$getOwnPropertyDescriptor__default["default"](t, r)); }); } return e; }
136
+
137
+ /**
138
+ * Dispatch a notification.
139
+ *
140
+ * @example
141
+ * const showSuccessNotification = useShowNotification();
142
+ * showSuccessNotification({
143
+ * domain: NOTIFICATION_DOMAINS.SIDE,
144
+ * kind: NOTIFICATION_KINDS_SIDE.success,
145
+ * text: "All good!",
146
+ * });
147
+ */
148
+
149
+ /**
150
+ * Dispatch a notification.
151
+ *
152
+ * @deprecated: Avoid passing the notification options here.
153
+ * Instead define them in the notification function itself.
154
+ *
155
+ * @example
156
+ * Bad:
157
+ * const showSuccessNotification = useShowNotification({
158
+ * domain: NOTIFICATION_DOMAINS.SIDE,
159
+ * kind: NOTIFICATION_KINDS_SIDE.success,
160
+ * });
161
+ * showSuccessNotification({
162
+ * text: "All good!",
163
+ * });
164
+ *
165
+ * Good:
166
+ * const showSuccessNotification = useShowNotification();
167
+ * showSuccessNotification({
168
+ * domain: NOTIFICATION_DOMAINS.SIDE,
169
+ * kind: NOTIFICATION_KINDS_SIDE.success,
170
+ * text: "All good!",
171
+ * });
172
+ */
173
+
174
+ function useShowNotification(notificationFragment) {
175
+ const dispatch = reactRedux.useDispatch();
176
+ return react.useCallback((content, meta) => {
177
+ const notification = showNotification(_objectSpread(_objectSpread({}, notificationFragment), content), meta);
178
+ return dispatch(notification);
179
+ }, [dispatch, notificationFragment]);
180
+ }
181
+
182
+ /**
183
+ * Dispatch an API error notification.
184
+ *
185
+ * @example
186
+ * const showApiErrorNotification = useShowApiErrorNotification();
187
+ * showApiErrorNotification({ errors });
188
+ */
189
+ function useShowApiErrorNotification() {
190
+ const dispatch = reactRedux.useDispatch();
191
+ return react.useCallback(options => dispatch(showApiErrorNotification(options)), [dispatch]);
192
+ }
193
+
194
+ /**
195
+ * Dispatch an unexpected error notification.
196
+ *
197
+ * @example
198
+ * const showUnexpectedErrorNotification = useShowUnexpectedErrorNotification();
199
+ * showUnexpectedErrorNotification({ errors });
200
+ */
201
+ function useShowUnexpectedErrorNotification() {
202
+ const dispatch = reactRedux.useDispatch();
203
+ return react.useCallback(options => dispatch(showUnexpectedErrorNotification(options)), [dispatch]);
204
+ }
205
+
206
+ function useHideAllPageNotifications() {
207
+ const dispatch = reactRedux.useDispatch();
208
+ return react.useCallback(() => dispatch(hideAllPageNotifications()), [dispatch]);
209
+ }
210
+
211
+ function useOnActionError() {
212
+ const dispatch = reactRedux.useDispatch();
213
+ return react.useCallback(error => dispatch(handleActionError(error)), [dispatch]);
214
+ }
215
+
216
+ exports.handleActionError = handleActionError;
217
+ exports.hideAllPageNotifications = hideAllPageNotifications;
218
+ exports.showApiErrorNotification = showApiErrorNotification;
219
+ exports.showNotification = showNotification;
220
+ exports.showUnexpectedErrorNotification = showUnexpectedErrorNotification;
221
+ exports.useHideAllPageNotifications = useHideAllPageNotifications;
222
+ exports.useOnActionError = useOnActionError;
223
+ exports.useShowApiErrorNotification = useShowApiErrorNotification;
224
+ exports.useShowNotification = useShowNotification;
225
+ exports.useShowUnexpectedErrorNotification = useShowUnexpectedErrorNotification;
226
+ exports.version = version;
@@ -0,0 +1,7 @@
1
+ 'use strict';
2
+
3
+ if (process.env.NODE_ENV === "production") {
4
+ module.exports = require("./commercetools-frontend-actions-global.cjs.prod.js");
5
+ } else {
6
+ module.exports = require("./commercetools-frontend-actions-global.cjs.dev.js");
7
+ }
@@ -0,0 +1,216 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var history = require('@commercetools-frontend/browser-history');
6
+ var constants = require('@commercetools-frontend/constants');
7
+ var sentry = require('@commercetools-frontend/sentry');
8
+ var _Array$isArray = require('@babel/runtime-corejs3/core-js-stable/array/is-array');
9
+ var _defineProperty = require('@babel/runtime-corejs3/helpers/defineProperty');
10
+ require('@babel/runtime-corejs3/core-js-stable/instance/includes');
11
+ require('@babel/runtime-corejs3/core-js-stable/object/values');
12
+ var _Object$keys = require('@babel/runtime-corejs3/core-js-stable/object/keys');
13
+ var _Object$getOwnPropertySymbols = require('@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols');
14
+ var _filterInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/filter');
15
+ var _Object$getOwnPropertyDescriptor = require('@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor');
16
+ var _forEachInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/for-each');
17
+ var _Object$getOwnPropertyDescriptors = require('@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptors');
18
+ var _Object$defineProperties = require('@babel/runtime-corejs3/core-js-stable/object/define-properties');
19
+ var _Object$defineProperty = require('@babel/runtime-corejs3/core-js-stable/object/define-property');
20
+ var isNumber = require('lodash/isNumber');
21
+ var notifications = require('@commercetools-frontend/notifications');
22
+ var react = require('react');
23
+ var reactRedux = require('react-redux');
24
+
25
+ function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
26
+
27
+ var history__default = /*#__PURE__*/_interopDefault(history);
28
+ var _Array$isArray__default = /*#__PURE__*/_interopDefault(_Array$isArray);
29
+ var _Object$keys__default = /*#__PURE__*/_interopDefault(_Object$keys);
30
+ var _Object$getOwnPropertySymbols__default = /*#__PURE__*/_interopDefault(_Object$getOwnPropertySymbols);
31
+ var _filterInstanceProperty__default = /*#__PURE__*/_interopDefault(_filterInstanceProperty);
32
+ var _Object$getOwnPropertyDescriptor__default = /*#__PURE__*/_interopDefault(_Object$getOwnPropertyDescriptor);
33
+ var _forEachInstanceProperty__default = /*#__PURE__*/_interopDefault(_forEachInstanceProperty);
34
+ var _Object$getOwnPropertyDescriptors__default = /*#__PURE__*/_interopDefault(_Object$getOwnPropertyDescriptors);
35
+ var _Object$defineProperties__default = /*#__PURE__*/_interopDefault(_Object$defineProperties);
36
+ var _Object$defineProperty__default = /*#__PURE__*/_interopDefault(_Object$defineProperty);
37
+ var isNumber__default = /*#__PURE__*/_interopDefault(isNumber);
38
+
39
+ // NOTE: This string will be replaced on build time with the package version.
40
+ var version = "24.7.2";
41
+
42
+ function ownKeys$1(e, r) { var t = _Object$keys__default["default"](e); if (_Object$getOwnPropertySymbols__default["default"]) { var o = _Object$getOwnPropertySymbols__default["default"](e); r && (o = _filterInstanceProperty__default["default"](o).call(o, function (r) { return _Object$getOwnPropertyDescriptor__default["default"](e, r).enumerable; })), t.push.apply(t, o); } return t; }
43
+ function _objectSpread$1(e) { for (var r = 1; r < arguments.length; r++) { var _context2, _context3; var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? _forEachInstanceProperty__default["default"](_context2 = ownKeys$1(Object(t), !0)).call(_context2, function (r) { _defineProperty(e, r, t[r]); }) : _Object$getOwnPropertyDescriptors__default["default"] ? _Object$defineProperties__default["default"](e, _Object$getOwnPropertyDescriptors__default["default"](t)) : _forEachInstanceProperty__default["default"](_context3 = ownKeys$1(Object(t))).call(_context3, function (r) { _Object$defineProperty__default["default"](e, r, _Object$getOwnPropertyDescriptor__default["default"](t, r)); }); } return e; }
44
+ function showNotification(notification) {
45
+ let meta = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
46
+ let dismissAfter = meta.dismissAfter;
47
+ if (!isNumber__default["default"](dismissAfter)) dismissAfter = notification.kind === constants.NOTIFICATION_KINDS_SIDE.success ? 5000 : 0;
48
+ return notifications.addNotification(notification, _objectSpread$1(_objectSpread$1({}, meta), {}, {
49
+ dismissAfter
50
+ }));
51
+ }
52
+
53
+ function showApiErrorNotification(_ref) {
54
+ let errors = _ref.errors;
55
+ return showNotification({
56
+ id: 0,
57
+ domain: constants.DOMAINS.PAGE,
58
+ kind: 'api-error',
59
+ values: {
60
+ // NOTE: Some sources or errors (e.g. GraphQL) return an array or object.
61
+ // The cast into an array happens here so that consumers can pass both types.
62
+ errors: _Array$isArray__default["default"](errors) ? errors : [errors]
63
+ }
64
+ }, {
65
+ dismissAfter: 0
66
+ });
67
+ }
68
+
69
+ function showUnexpectedErrorNotification() {
70
+ let _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
71
+ errorId = _ref.errorId;
72
+ return showNotification({
73
+ id: 0,
74
+ domain: constants.DOMAINS.PAGE,
75
+ kind: 'unexpected-error',
76
+ values: {
77
+ errorId
78
+ }
79
+ }, {
80
+ dismissAfter: 0
81
+ });
82
+ }
83
+
84
+ function isApiError(error) {
85
+ return error.body !== undefined;
86
+ }
87
+ function handleActionError(error) {
88
+ return dispatch => {
89
+ // On production we send the errors to Sentry.
90
+ // eslint-disable-next-line no-console
91
+ if (window.app.env !== 'production') console.error(error, error instanceof Error && error.stack);
92
+ if (!isApiError(error)) {
93
+ const errorId = sentry.reportErrorToSentry(error);
94
+ return dispatch(showUnexpectedErrorNotification({
95
+ errorId
96
+ }));
97
+ }
98
+
99
+ // When unauthorized, log the user out.
100
+ if (error.statusCode === constants.STATUS_CODES.UNAUTHORIZED) {
101
+ history__default["default"].push(`/logout?reason=${constants.LOGOUT_REASONS.UNAUTHORIZED}`);
102
+ }
103
+
104
+ // We need to do the return, because if not we see an error notification
105
+ // The error is handled with the handleUnavailableResource HoC to show the PageNotFound component
106
+ // when the api returns 404
107
+ if (error.statusCode === constants.STATUS_CODES.NOT_FOUND) return null;
108
+ return dispatch(showApiErrorNotification({
109
+ errors: error.body.errors || [
110
+ // Pass a fallback error so that our error components can handle it
111
+ {
112
+ message: error.body.message
113
+ }]
114
+ }));
115
+ };
116
+ }
117
+
118
+ function hideAllPageNotifications() {
119
+ return {
120
+ type: constants.HIDE_ALL_PAGE_NOTIFICATIONS
121
+ };
122
+ }
123
+
124
+ function ownKeys(e, r) { var t = _Object$keys__default["default"](e); if (_Object$getOwnPropertySymbols__default["default"]) { var o = _Object$getOwnPropertySymbols__default["default"](e); r && (o = _filterInstanceProperty__default["default"](o).call(o, function (r) { return _Object$getOwnPropertyDescriptor__default["default"](e, r).enumerable; })), t.push.apply(t, o); } return t; }
125
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var _context, _context2; var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? _forEachInstanceProperty__default["default"](_context = ownKeys(Object(t), !0)).call(_context, function (r) { _defineProperty(e, r, t[r]); }) : _Object$getOwnPropertyDescriptors__default["default"] ? _Object$defineProperties__default["default"](e, _Object$getOwnPropertyDescriptors__default["default"](t)) : _forEachInstanceProperty__default["default"](_context2 = ownKeys(Object(t))).call(_context2, function (r) { _Object$defineProperty__default["default"](e, r, _Object$getOwnPropertyDescriptor__default["default"](t, r)); }); } return e; }
126
+
127
+ /**
128
+ * Dispatch a notification.
129
+ *
130
+ * @example
131
+ * const showSuccessNotification = useShowNotification();
132
+ * showSuccessNotification({
133
+ * domain: NOTIFICATION_DOMAINS.SIDE,
134
+ * kind: NOTIFICATION_KINDS_SIDE.success,
135
+ * text: "All good!",
136
+ * });
137
+ */
138
+
139
+ /**
140
+ * Dispatch a notification.
141
+ *
142
+ * @deprecated: Avoid passing the notification options here.
143
+ * Instead define them in the notification function itself.
144
+ *
145
+ * @example
146
+ * Bad:
147
+ * const showSuccessNotification = useShowNotification({
148
+ * domain: NOTIFICATION_DOMAINS.SIDE,
149
+ * kind: NOTIFICATION_KINDS_SIDE.success,
150
+ * });
151
+ * showSuccessNotification({
152
+ * text: "All good!",
153
+ * });
154
+ *
155
+ * Good:
156
+ * const showSuccessNotification = useShowNotification();
157
+ * showSuccessNotification({
158
+ * domain: NOTIFICATION_DOMAINS.SIDE,
159
+ * kind: NOTIFICATION_KINDS_SIDE.success,
160
+ * text: "All good!",
161
+ * });
162
+ */
163
+
164
+ function useShowNotification(notificationFragment) {
165
+ const dispatch = reactRedux.useDispatch();
166
+ return react.useCallback((content, meta) => {
167
+ const notification = showNotification(_objectSpread(_objectSpread({}, notificationFragment), content), meta);
168
+ return dispatch(notification);
169
+ }, [dispatch, notificationFragment]);
170
+ }
171
+
172
+ /**
173
+ * Dispatch an API error notification.
174
+ *
175
+ * @example
176
+ * const showApiErrorNotification = useShowApiErrorNotification();
177
+ * showApiErrorNotification({ errors });
178
+ */
179
+ function useShowApiErrorNotification() {
180
+ const dispatch = reactRedux.useDispatch();
181
+ return react.useCallback(options => dispatch(showApiErrorNotification(options)), [dispatch]);
182
+ }
183
+
184
+ /**
185
+ * Dispatch an unexpected error notification.
186
+ *
187
+ * @example
188
+ * const showUnexpectedErrorNotification = useShowUnexpectedErrorNotification();
189
+ * showUnexpectedErrorNotification({ errors });
190
+ */
191
+ function useShowUnexpectedErrorNotification() {
192
+ const dispatch = reactRedux.useDispatch();
193
+ return react.useCallback(options => dispatch(showUnexpectedErrorNotification(options)), [dispatch]);
194
+ }
195
+
196
+ function useHideAllPageNotifications() {
197
+ const dispatch = reactRedux.useDispatch();
198
+ return react.useCallback(() => dispatch(hideAllPageNotifications()), [dispatch]);
199
+ }
200
+
201
+ function useOnActionError() {
202
+ const dispatch = reactRedux.useDispatch();
203
+ return react.useCallback(error => dispatch(handleActionError(error)), [dispatch]);
204
+ }
205
+
206
+ exports.handleActionError = handleActionError;
207
+ exports.hideAllPageNotifications = hideAllPageNotifications;
208
+ exports.showApiErrorNotification = showApiErrorNotification;
209
+ exports.showNotification = showNotification;
210
+ exports.showUnexpectedErrorNotification = showUnexpectedErrorNotification;
211
+ exports.useHideAllPageNotifications = useHideAllPageNotifications;
212
+ exports.useOnActionError = useOnActionError;
213
+ exports.useShowApiErrorNotification = useShowApiErrorNotification;
214
+ exports.useShowNotification = useShowNotification;
215
+ exports.useShowUnexpectedErrorNotification = useShowUnexpectedErrorNotification;
216
+ exports.version = version;
@@ -0,0 +1,196 @@
1
+ import history from '@commercetools-frontend/browser-history';
2
+ import { NOTIFICATION_DOMAINS, NOTIFICATION_KINDS_SIDE, DOMAINS, STATUS_CODES, LOGOUT_REASONS, HIDE_ALL_PAGE_NOTIFICATIONS } from '@commercetools-frontend/constants';
3
+ import { reportErrorToSentry } from '@commercetools-frontend/sentry';
4
+ import _Array$isArray from '@babel/runtime-corejs3/core-js-stable/array/is-array';
5
+ import _defineProperty from '@babel/runtime-corejs3/helpers/esm/defineProperty';
6
+ import _includesInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/includes';
7
+ import _Object$values from '@babel/runtime-corejs3/core-js-stable/object/values';
8
+ import _Object$keys from '@babel/runtime-corejs3/core-js-stable/object/keys';
9
+ import _Object$getOwnPropertySymbols from '@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols';
10
+ import _filterInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/filter';
11
+ import _Object$getOwnPropertyDescriptor from '@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor';
12
+ import _forEachInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/for-each';
13
+ import _Object$getOwnPropertyDescriptors from '@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptors';
14
+ import _Object$defineProperties from '@babel/runtime-corejs3/core-js-stable/object/define-properties';
15
+ import _Object$defineProperty from '@babel/runtime-corejs3/core-js-stable/object/define-property';
16
+ import isNumber from 'lodash/isNumber';
17
+ import { addNotification } from '@commercetools-frontend/notifications';
18
+ import { useCallback } from 'react';
19
+ import { useDispatch } from 'react-redux';
20
+
21
+ // NOTE: This string will be replaced on build time with the package version.
22
+ var version = "24.7.2";
23
+
24
+ function ownKeys$1(e, r) { var t = _Object$keys(e); if (_Object$getOwnPropertySymbols) { var o = _Object$getOwnPropertySymbols(e); r && (o = _filterInstanceProperty(o).call(o, function (r) { return _Object$getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
25
+ function _objectSpread$1(e) { for (var r = 1; r < arguments.length; r++) { var _context2, _context3; var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? _forEachInstanceProperty(_context2 = ownKeys$1(Object(t), !0)).call(_context2, function (r) { _defineProperty(e, r, t[r]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(e, _Object$getOwnPropertyDescriptors(t)) : _forEachInstanceProperty(_context3 = ownKeys$1(Object(t))).call(_context3, function (r) { _Object$defineProperty(e, r, _Object$getOwnPropertyDescriptor(t, r)); }); } return e; }
26
+ function showNotification(notification) {
27
+ let meta = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
28
+ if (process.env.NODE_ENV !== 'production') if (notification.domain) {
29
+ var _context;
30
+ if (!_includesInstanceProperty(_context = _Object$values(NOTIFICATION_DOMAINS)).call(_context, notification.domain))
31
+ // eslint-disable-next-line no-console
32
+ console.warn(`Unknown notification domain "${notification.domain}"`, notification);
33
+ }
34
+ // eslint-disable-next-line no-console
35
+ else console.warn('Notification is missing domain', notification);
36
+ let dismissAfter = meta.dismissAfter;
37
+ if (!isNumber(dismissAfter)) dismissAfter = notification.kind === NOTIFICATION_KINDS_SIDE.success ? 5000 : 0;
38
+ return addNotification(notification, _objectSpread$1(_objectSpread$1({}, meta), {}, {
39
+ dismissAfter
40
+ }));
41
+ }
42
+
43
+ function showApiErrorNotification(_ref) {
44
+ let errors = _ref.errors;
45
+ return showNotification({
46
+ id: 0,
47
+ domain: DOMAINS.PAGE,
48
+ kind: 'api-error',
49
+ values: {
50
+ // NOTE: Some sources or errors (e.g. GraphQL) return an array or object.
51
+ // The cast into an array happens here so that consumers can pass both types.
52
+ errors: _Array$isArray(errors) ? errors : [errors]
53
+ }
54
+ }, {
55
+ dismissAfter: 0
56
+ });
57
+ }
58
+
59
+ function showUnexpectedErrorNotification() {
60
+ let _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
61
+ errorId = _ref.errorId;
62
+ return showNotification({
63
+ id: 0,
64
+ domain: DOMAINS.PAGE,
65
+ kind: 'unexpected-error',
66
+ values: {
67
+ errorId
68
+ }
69
+ }, {
70
+ dismissAfter: 0
71
+ });
72
+ }
73
+
74
+ function isApiError(error) {
75
+ return error.body !== undefined;
76
+ }
77
+ function handleActionError(error) {
78
+ return dispatch => {
79
+ // On production we send the errors to Sentry.
80
+ // eslint-disable-next-line no-console
81
+ if (window.app.env !== 'production') console.error(error, error instanceof Error && error.stack);
82
+ if (!isApiError(error)) {
83
+ const errorId = reportErrorToSentry(error);
84
+ return dispatch(showUnexpectedErrorNotification({
85
+ errorId
86
+ }));
87
+ }
88
+
89
+ // When unauthorized, log the user out.
90
+ if (error.statusCode === STATUS_CODES.UNAUTHORIZED) {
91
+ history.push(`/logout?reason=${LOGOUT_REASONS.UNAUTHORIZED}`);
92
+ }
93
+
94
+ // We need to do the return, because if not we see an error notification
95
+ // The error is handled with the handleUnavailableResource HoC to show the PageNotFound component
96
+ // when the api returns 404
97
+ if (error.statusCode === STATUS_CODES.NOT_FOUND) return null;
98
+ return dispatch(showApiErrorNotification({
99
+ errors: error.body.errors || [
100
+ // Pass a fallback error so that our error components can handle it
101
+ {
102
+ message: error.body.message
103
+ }]
104
+ }));
105
+ };
106
+ }
107
+
108
+ function hideAllPageNotifications() {
109
+ return {
110
+ type: HIDE_ALL_PAGE_NOTIFICATIONS
111
+ };
112
+ }
113
+
114
+ function ownKeys(e, r) { var t = _Object$keys(e); if (_Object$getOwnPropertySymbols) { var o = _Object$getOwnPropertySymbols(e); r && (o = _filterInstanceProperty(o).call(o, function (r) { return _Object$getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
115
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var _context, _context2; var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? _forEachInstanceProperty(_context = ownKeys(Object(t), !0)).call(_context, function (r) { _defineProperty(e, r, t[r]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(e, _Object$getOwnPropertyDescriptors(t)) : _forEachInstanceProperty(_context2 = ownKeys(Object(t))).call(_context2, function (r) { _Object$defineProperty(e, r, _Object$getOwnPropertyDescriptor(t, r)); }); } return e; }
116
+
117
+ /**
118
+ * Dispatch a notification.
119
+ *
120
+ * @example
121
+ * const showSuccessNotification = useShowNotification();
122
+ * showSuccessNotification({
123
+ * domain: NOTIFICATION_DOMAINS.SIDE,
124
+ * kind: NOTIFICATION_KINDS_SIDE.success,
125
+ * text: "All good!",
126
+ * });
127
+ */
128
+
129
+ /**
130
+ * Dispatch a notification.
131
+ *
132
+ * @deprecated: Avoid passing the notification options here.
133
+ * Instead define them in the notification function itself.
134
+ *
135
+ * @example
136
+ * Bad:
137
+ * const showSuccessNotification = useShowNotification({
138
+ * domain: NOTIFICATION_DOMAINS.SIDE,
139
+ * kind: NOTIFICATION_KINDS_SIDE.success,
140
+ * });
141
+ * showSuccessNotification({
142
+ * text: "All good!",
143
+ * });
144
+ *
145
+ * Good:
146
+ * const showSuccessNotification = useShowNotification();
147
+ * showSuccessNotification({
148
+ * domain: NOTIFICATION_DOMAINS.SIDE,
149
+ * kind: NOTIFICATION_KINDS_SIDE.success,
150
+ * text: "All good!",
151
+ * });
152
+ */
153
+
154
+ function useShowNotification(notificationFragment) {
155
+ const dispatch = useDispatch();
156
+ return useCallback((content, meta) => {
157
+ const notification = showNotification(_objectSpread(_objectSpread({}, notificationFragment), content), meta);
158
+ return dispatch(notification);
159
+ }, [dispatch, notificationFragment]);
160
+ }
161
+
162
+ /**
163
+ * Dispatch an API error notification.
164
+ *
165
+ * @example
166
+ * const showApiErrorNotification = useShowApiErrorNotification();
167
+ * showApiErrorNotification({ errors });
168
+ */
169
+ function useShowApiErrorNotification() {
170
+ const dispatch = useDispatch();
171
+ return useCallback(options => dispatch(showApiErrorNotification(options)), [dispatch]);
172
+ }
173
+
174
+ /**
175
+ * Dispatch an unexpected error notification.
176
+ *
177
+ * @example
178
+ * const showUnexpectedErrorNotification = useShowUnexpectedErrorNotification();
179
+ * showUnexpectedErrorNotification({ errors });
180
+ */
181
+ function useShowUnexpectedErrorNotification() {
182
+ const dispatch = useDispatch();
183
+ return useCallback(options => dispatch(showUnexpectedErrorNotification(options)), [dispatch]);
184
+ }
185
+
186
+ function useHideAllPageNotifications() {
187
+ const dispatch = useDispatch();
188
+ return useCallback(() => dispatch(hideAllPageNotifications()), [dispatch]);
189
+ }
190
+
191
+ function useOnActionError() {
192
+ const dispatch = useDispatch();
193
+ return useCallback(error => dispatch(handleActionError(error)), [dispatch]);
194
+ }
195
+
196
+ export { handleActionError, hideAllPageNotifications, showApiErrorNotification, showNotification, showUnexpectedErrorNotification, useHideAllPageNotifications, useOnActionError, useShowApiErrorNotification, useShowNotification, useShowUnexpectedErrorNotification, version };
@@ -0,0 +1,27 @@
1
+ import type { ThunkDispatch } from 'redux-thunk';
2
+ import type { TAppNotificationApiError, TStatusCode } from '@commercetools-frontend/constants';
3
+ import showApiErrorNotification from "./show-api-error-notification.js";
4
+ import showUnexpectedErrorNotification from "./show-unexpected-error-notification.js";
5
+ type ApiError = {
6
+ statusCode: TStatusCode;
7
+ body: {
8
+ message: string;
9
+ errors?: TAppNotificationApiError | TAppNotificationApiError[];
10
+ };
11
+ };
12
+ export type ActionError = Error | ApiError;
13
+ export type DispatchActionError = ThunkDispatch<null, null, ReturnType<typeof showApiErrorNotification> | ReturnType<typeof showUnexpectedErrorNotification>>;
14
+ export default function handleActionError(error: ActionError): (dispatch: DispatchActionError) => import("@commercetools-frontend/notifications").TAddNotificationAction<import("@commercetools-frontend/constants").TAppNotificationOfDomain & {
15
+ kind: import("@commercetools-frontend/constants").TAppNotificationKindPage;
16
+ } & {
17
+ id: number;
18
+ text?: undefined;
19
+ values?: import("@commercetools-frontend/constants").TAppNotificationValuesApiError<{}> | undefined;
20
+ } & import("@commercetools-frontend/notifications").TNotification> | import("@commercetools-frontend/notifications").TAddNotificationAction<import("@commercetools-frontend/constants").TAppNotificationOfDomain & {
21
+ kind: import("@commercetools-frontend/constants").TAppNotificationKindPage;
22
+ } & {
23
+ id: number;
24
+ text?: undefined;
25
+ values?: import("@commercetools-frontend/constants").TAppNotificationValuesUnexpectedError | undefined;
26
+ } & import("@commercetools-frontend/notifications").TNotification> | null;
27
+ export {};
@@ -0,0 +1,6 @@
1
+ import { HIDE_ALL_PAGE_NOTIFICATIONS } from '@commercetools-frontend/constants';
2
+ type HideAllPageNotificationAction = {
3
+ type: typeof HIDE_ALL_PAGE_NOTIFICATIONS;
4
+ };
5
+ export default function hideAllPageNotifications(): HideAllPageNotificationAction;
6
+ export {};
@@ -0,0 +1,5 @@
1
+ export { default as handleActionError } from "./handle-action-error.js";
2
+ export { default as hideAllPageNotifications } from "./hide-all-page-notifications.js";
3
+ export { default as showApiErrorNotification } from "./show-api-error-notification.js";
4
+ export { default as showNotification } from "./show-notification.js";
5
+ export { default as showUnexpectedErrorNotification } from "./show-unexpected-error-notification.js";
@@ -0,0 +1,8 @@
1
+ import type { TApiErrorNotificationOptions } from "../types.js";
2
+ export default function showApiErrorNotification({ errors, }: TApiErrorNotificationOptions): import("@commercetools-frontend/notifications").TAddNotificationAction<import("@commercetools-frontend/constants").TAppNotificationOfDomain & {
3
+ kind: import("@commercetools-frontend/constants").TAppNotificationKindPage;
4
+ } & {
5
+ id: number;
6
+ text?: undefined;
7
+ values?: import("@commercetools-frontend/constants").TAppNotificationValuesApiError<{}> | undefined;
8
+ } & import("@commercetools-frontend/notifications").TNotification>;
@@ -0,0 +1,3 @@
1
+ import type { TNotificationMetaOptions, TNotification } from '@commercetools-frontend/notifications';
2
+ import type { TShowNotification } from "../types.js";
3
+ export default function showNotification<Notification extends TShowNotification>(notification: Notification, meta?: TNotificationMetaOptions): import("@commercetools-frontend/notifications").TAddNotificationAction<Notification & TNotification>;
@@ -0,0 +1,8 @@
1
+ import type { TAppNotificationValuesUnexpectedError } from '@commercetools-frontend/constants';
2
+ export default function showUnexpectedErrorNotification({ errorId, }?: TAppNotificationValuesUnexpectedError): import("@commercetools-frontend/notifications").TAddNotificationAction<import("@commercetools-frontend/constants").TAppNotificationOfDomain & {
3
+ kind: import("@commercetools-frontend/constants").TAppNotificationKindPage;
4
+ } & {
5
+ id: number;
6
+ text?: undefined;
7
+ values?: TAppNotificationValuesUnexpectedError | undefined;
8
+ } & import("@commercetools-frontend/notifications").TNotification>;
@@ -0,0 +1,2 @@
1
+ import type { DispatchActionError } from "./actions/handle-action-error.js";
2
+ export type TDispatchActionError = DispatchActionError;
@@ -0,0 +1,5 @@
1
+ export { default as useShowNotification } from "./use-show-notification.js";
2
+ export { default as useShowApiErrorNotification } from "./use-show-api-error-notification.js";
3
+ export { default as useShowUnexpectedErrorNotification } from "./use-show-unexpected-error-notification.js";
4
+ export { default as useHideAllPageNotifications } from "./use-hide-all-page-notifications.js";
5
+ export { default as useOnActionError } from "./use-on-action-error.js";
@@ -0,0 +1,3 @@
1
+ export default function useHideAllPageNotifications(): () => {
2
+ type: typeof import("@commercetools-frontend/constants").HIDE_ALL_PAGE_NOTIFICATIONS;
3
+ };
@@ -0,0 +1,2 @@
1
+ import type { ActionError } from "../actions/handle-action-error.js";
2
+ export default function useOnActionError(): (error: ActionError) => import("redux").UnknownAction;
@@ -0,0 +1,15 @@
1
+ import type { TApiErrorNotificationOptions } from "../types.js";
2
+ /**
3
+ * Dispatch an API error notification.
4
+ *
5
+ * @example
6
+ * const showApiErrorNotification = useShowApiErrorNotification();
7
+ * showApiErrorNotification({ errors });
8
+ */
9
+ export default function useShowApiErrorNotification(): (options: TApiErrorNotificationOptions) => import("@commercetools-frontend/notifications").TAddNotificationAction<import("@commercetools-frontend/constants").TAppNotificationOfDomain & {
10
+ kind: import("@commercetools-frontend/constants").TAppNotificationKindPage;
11
+ } & {
12
+ id: number;
13
+ text?: undefined;
14
+ values?: import("@commercetools-frontend/constants").TAppNotificationValuesApiError<{}> | undefined;
15
+ } & import("@commercetools-frontend/notifications").TNotification>;
@@ -0,0 +1,41 @@
1
+ import type { TNotificationMetaOptions, TAddNotificationAction, TNotification } from '@commercetools-frontend/notifications';
2
+ import type { TShowNotification } from "../types.js";
3
+ type TNotificationHook<Notification extends TShowNotification> = (content: Notification, meta?: TNotificationMetaOptions) => TAddNotificationAction<Notification & TNotification>;
4
+ /**
5
+ * Dispatch a notification.
6
+ *
7
+ * @example
8
+ * const showSuccessNotification = useShowNotification();
9
+ * showSuccessNotification({
10
+ * domain: NOTIFICATION_DOMAINS.SIDE,
11
+ * kind: NOTIFICATION_KINDS_SIDE.success,
12
+ * text: "All good!",
13
+ * });
14
+ */
15
+ declare function useShowNotification<Notification extends TShowNotification>(): TNotificationHook<Notification>;
16
+ /**
17
+ * Dispatch a notification.
18
+ *
19
+ * @deprecated: Avoid passing the notification options here.
20
+ * Instead define them in the notification function itself.
21
+ *
22
+ * @example
23
+ * Bad:
24
+ * const showSuccessNotification = useShowNotification({
25
+ * domain: NOTIFICATION_DOMAINS.SIDE,
26
+ * kind: NOTIFICATION_KINDS_SIDE.success,
27
+ * });
28
+ * showSuccessNotification({
29
+ * text: "All good!",
30
+ * });
31
+ *
32
+ * Good:
33
+ * const showSuccessNotification = useShowNotification();
34
+ * showSuccessNotification({
35
+ * domain: NOTIFICATION_DOMAINS.SIDE,
36
+ * kind: NOTIFICATION_KINDS_SIDE.success,
37
+ * text: "All good!",
38
+ * });
39
+ */
40
+ declare function useShowNotification<Notification extends TShowNotification>(notificationFragment: Partial<Notification>): TNotificationHook<Notification>;
41
+ export default useShowNotification;
@@ -0,0 +1,15 @@
1
+ import type { TAppNotificationValuesUnexpectedError } from '@commercetools-frontend/constants';
2
+ /**
3
+ * Dispatch an unexpected error notification.
4
+ *
5
+ * @example
6
+ * const showUnexpectedErrorNotification = useShowUnexpectedErrorNotification();
7
+ * showUnexpectedErrorNotification({ errors });
8
+ */
9
+ export default function useShowUnexpectedErrorNotification(): (options: TAppNotificationValuesUnexpectedError) => import("@commercetools-frontend/notifications").TAddNotificationAction<import("@commercetools-frontend/constants").TAppNotificationOfDomain & {
10
+ kind: import("@commercetools-frontend/constants").TAppNotificationKindPage;
11
+ } & {
12
+ id: number;
13
+ text?: undefined;
14
+ values?: TAppNotificationValuesUnexpectedError | undefined;
15
+ } & import("@commercetools-frontend/notifications").TNotification>;
@@ -0,0 +1,5 @@
1
+ export { default as version } from "./version.js";
2
+ export * from "./actions/index.js";
3
+ export * from "./hooks/index.js";
4
+ export * from "./types.js";
5
+ export * from "./export-types.js";
@@ -0,0 +1,19 @@
1
+ import type { TAppNotification, TAppNotificationDomain, TAppNotificationKind, TAppNotificationApiError, TAppNotificationValuesApiError, TAppNotificationValuesUnexpectedError } from '@commercetools-frontend/constants';
2
+ export type TShowNotification = {
3
+ domain: TAppNotificationDomain;
4
+ kind: TAppNotificationKind;
5
+ text?: string;
6
+ };
7
+ export type TApiErrorNotification = TAppNotification<{
8
+ domain: 'page';
9
+ kind: 'api-error';
10
+ values: TAppNotificationValuesApiError;
11
+ }>;
12
+ export type TUnexpectedErrorNotification = TAppNotification<{
13
+ domain: 'page';
14
+ kind: 'unexpected-error';
15
+ values: TAppNotificationValuesUnexpectedError;
16
+ }>;
17
+ export type TApiErrorNotificationOptions = {
18
+ errors: TAppNotificationApiError | TAppNotificationApiError[];
19
+ };
@@ -0,0 +1,2 @@
1
+ declare const _default: "__@APPLICATION_KIT_PACKAGE/VERSION_OF_RELEASE__";
2
+ export default _default;
package/package.json ADDED
@@ -0,0 +1,55 @@
1
+ {
2
+ "name": "@commercetools-frontend/actions-global",
3
+ "version": "0.0.0-CRAFT-1791-20251006162610",
4
+ "description": "Global redux actions for a MC application",
5
+ "bugs": "https://github.com/commercetools/merchant-center-application-kit/issues",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://github.com/commercetools/merchant-center-application-kit.git",
9
+ "directory": "packages/actions-global"
10
+ },
11
+ "homepage": "https://docs.commercetools.com/merchant-center-customizations",
12
+ "keywords": [
13
+ "javascript",
14
+ "frontend",
15
+ "react",
16
+ "toolkit"
17
+ ],
18
+ "license": "MIT",
19
+ "publishConfig": {
20
+ "access": "public"
21
+ },
22
+ "main": "dist/commercetools-frontend-actions-global.cjs.js",
23
+ "module": "dist/commercetools-frontend-actions-global.esm.js",
24
+ "files": [
25
+ "dist",
26
+ "package.json",
27
+ "LICENSE",
28
+ "README.md"
29
+ ],
30
+ "dependencies": {
31
+ "@babel/runtime": "^7.22.15",
32
+ "@babel/runtime-corejs3": "^7.22.15",
33
+ "@commercetools-frontend/browser-history": "0.0.0-CRAFT-1791-20251006162610",
34
+ "@commercetools-frontend/constants": "0.0.0-CRAFT-1791-20251006162610",
35
+ "@commercetools-frontend/notifications": "0.0.0-CRAFT-1791-20251006162610",
36
+ "@commercetools-frontend/sentry": "0.0.0-CRAFT-1791-20251006162610",
37
+ "@types/lodash": "^4.14.198",
38
+ "@types/react": "^19.0.3",
39
+ "@types/react-redux": "^7.1.26",
40
+ "lodash": "4.17.21",
41
+ "redux-thunk": "3.1.0"
42
+ },
43
+ "devDependencies": {
44
+ "@types/jest": "^29.5.14",
45
+ "jest": "29.7.0",
46
+ "react": "19.0.0",
47
+ "react-redux": "9.2.0",
48
+ "redux": "5.0.1"
49
+ },
50
+ "peerDependencies": {
51
+ "react": "19.x",
52
+ "react-redux": "7.x || 9.x",
53
+ "redux": "4.x || 5.x"
54
+ }
55
+ }