@commercetools-frontend/sdk 21.3.4 → 21.8.1
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.
- package/LICENSE +1 -1
- package/README.md +5 -4
- package/dist/commercetools-frontend-sdk.cjs.dev.js +3 -2
- package/dist/commercetools-frontend-sdk.cjs.prod.js +3 -2
- package/dist/commercetools-frontend-sdk.esm.js +3 -2
- package/dist/declarations/src/test-utils/test-utils.d.ts +20 -2
- package/dist/declarations/src/types.d.ts +2 -0
- package/package.json +3 -3
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -103,7 +103,7 @@ The supported `options` can be found in the `api-request-builder`'s documentatio
|
|
|
103
103
|
## Action creators for external API usage
|
|
104
104
|
|
|
105
105
|
By default, all requests with the SDK are configured to be sent to the MC API.
|
|
106
|
-
However, Custom Applications using the [Proxy to external API](https://docs.commercetools.com/custom-applications/
|
|
106
|
+
However, Custom Applications using the [Proxy to external API](https://docs.commercetools.com/custom-applications/concepts/integrate-with-your-own-api) need to configure the request a bit differently, and send additional headers.
|
|
107
107
|
|
|
108
108
|
To make it easier to make requests to the proxy endpoint using the SDK, there is a new action creator wrapper that comes with built-in configuration options.
|
|
109
109
|
|
|
@@ -120,10 +120,11 @@ The options for the action creators are the same as the **Usage with `uri`**, ex
|
|
|
120
120
|
|
|
121
121
|
The `forwardTo` action creators additionally set the following headers:
|
|
122
122
|
|
|
123
|
-
- `X-Forward-To`
|
|
124
123
|
- `Accept-version`
|
|
124
|
+
- `X-Forward-To`
|
|
125
|
+
- `X-Forward-To-Audience-Policy`
|
|
125
126
|
|
|
126
|
-
For more information, check the [Proxy to external API](https://docs.commercetools.com/custom-applications/
|
|
127
|
+
For more information, check the [Proxy to external API](https://docs.commercetools.com/custom-applications/concepts/integrate-with-your-own-api) documentation.
|
|
127
128
|
|
|
128
129
|
## Error handling
|
|
129
130
|
|
|
@@ -131,7 +132,7 @@ Failed requests will result in a rejected promise. The `sdk-client`'s error hand
|
|
|
131
132
|
|
|
132
133
|
The `sdk` package does not provide any error handling out of the box. It's the application's responsibility to handle errors (e.g. show a notification, track the error).
|
|
133
134
|
|
|
134
|
-
The
|
|
135
|
+
The Merchant Center has a `handleActionError` function which is what we currently use for error handling. It logs the error to the tracking tool (Sentry) and shows a notification to the client. This should be used whenever a more special error handling is not necessary.
|
|
135
136
|
|
|
136
137
|
## Example
|
|
137
138
|
|
|
@@ -273,7 +273,8 @@ var enhancePayloadForForwardToProxy = function enhancePayloadForForwardToProxy(p
|
|
|
273
273
|
return _objectSpread$3(_objectSpread$3({}, customForwardHeaders), {}, _defineProperty({}, "x-forward-header-".concat(headerName), headerValue));
|
|
274
274
|
}, {})), {}, {
|
|
275
275
|
'Accept-version': 'v2',
|
|
276
|
-
'X-Forward-To': payload.uri
|
|
276
|
+
'X-Forward-To': payload.uri,
|
|
277
|
+
'X-Forward-To-Audience-Policy': payload.audiencePolicy || 'forward-url-full-path'
|
|
277
278
|
})
|
|
278
279
|
};
|
|
279
280
|
};
|
|
@@ -323,7 +324,7 @@ var index = /*#__PURE__*/Object.freeze({
|
|
|
323
324
|
});
|
|
324
325
|
|
|
325
326
|
// NOTE: This string will be replaced on build time with the package version.
|
|
326
|
-
var version = "21.
|
|
327
|
+
var version = "21.8.1";
|
|
327
328
|
|
|
328
329
|
/* eslint-disable no-console */
|
|
329
330
|
var isLoggerEnabled = function isLoggerEnabled() {
|
|
@@ -264,7 +264,8 @@ var enhancePayloadForForwardToProxy = function enhancePayloadForForwardToProxy(p
|
|
|
264
264
|
return _objectSpread$2(_objectSpread$2({}, customForwardHeaders), {}, _defineProperty({}, "x-forward-header-".concat(headerName), headerValue));
|
|
265
265
|
}, {})), {}, {
|
|
266
266
|
'Accept-version': 'v2',
|
|
267
|
-
'X-Forward-To': payload.uri
|
|
267
|
+
'X-Forward-To': payload.uri,
|
|
268
|
+
'X-Forward-To-Audience-Policy': payload.audiencePolicy || 'forward-url-full-path'
|
|
268
269
|
})
|
|
269
270
|
};
|
|
270
271
|
};
|
|
@@ -314,7 +315,7 @@ var index = /*#__PURE__*/Object.freeze({
|
|
|
314
315
|
});
|
|
315
316
|
|
|
316
317
|
// NOTE: This string will be replaced on build time with the package version.
|
|
317
|
-
var version = "21.
|
|
318
|
+
var version = "21.8.1";
|
|
318
319
|
|
|
319
320
|
var removeMcPrefix = function removeMcPrefix(host) {
|
|
320
321
|
return host.replace(/^mc(-(\d){4,})?\.(.*)$/, '$3');
|
|
@@ -251,7 +251,8 @@ var enhancePayloadForForwardToProxy = function enhancePayloadForForwardToProxy(p
|
|
|
251
251
|
return _objectSpread$3(_objectSpread$3({}, customForwardHeaders), {}, _defineProperty({}, "x-forward-header-".concat(headerName), headerValue));
|
|
252
252
|
}, {})), {}, {
|
|
253
253
|
'Accept-version': 'v2',
|
|
254
|
-
'X-Forward-To': payload.uri
|
|
254
|
+
'X-Forward-To': payload.uri,
|
|
255
|
+
'X-Forward-To-Audience-Policy': payload.audiencePolicy || 'forward-url-full-path'
|
|
255
256
|
})
|
|
256
257
|
};
|
|
257
258
|
};
|
|
@@ -301,7 +302,7 @@ var index = /*#__PURE__*/Object.freeze({
|
|
|
301
302
|
});
|
|
302
303
|
|
|
303
304
|
// NOTE: This string will be replaced on build time with the package version.
|
|
304
|
-
var version = "21.
|
|
305
|
+
var version = "21.8.1";
|
|
305
306
|
|
|
306
307
|
/* eslint-disable no-console */
|
|
307
308
|
var isLoggerEnabled = function isLoggerEnabled() {
|
|
@@ -1,7 +1,25 @@
|
|
|
1
|
-
/// <reference types="commercetools__sdk-client" />
|
|
2
1
|
import type { Dispatch } from 'redux';
|
|
3
|
-
import type { HttpErrorType } from '@commercetools/sdk-client';
|
|
4
2
|
import type { TSdkAction, Json } from '../types';
|
|
3
|
+
export declare type Headers = {
|
|
4
|
+
[key: string]: string;
|
|
5
|
+
};
|
|
6
|
+
export declare type MethodType = 'GET' | 'POST' | 'DELETE' | 'HEAD' | 'OPTIONS' | 'PUT' | 'PATCH' | 'TRACE';
|
|
7
|
+
export declare type ClientRequest = {
|
|
8
|
+
uri: string;
|
|
9
|
+
method: MethodType;
|
|
10
|
+
body?: unknown;
|
|
11
|
+
headers?: Headers;
|
|
12
|
+
};
|
|
13
|
+
export declare type HttpErrorType = {
|
|
14
|
+
name: string;
|
|
15
|
+
message: string;
|
|
16
|
+
code: number;
|
|
17
|
+
status: number;
|
|
18
|
+
statusCode: number;
|
|
19
|
+
originalRequest: ClientRequest;
|
|
20
|
+
body?: Json;
|
|
21
|
+
headers?: Headers;
|
|
22
|
+
};
|
|
5
23
|
interface TSdkMockBase {
|
|
6
24
|
action: TSdkAction;
|
|
7
25
|
}
|
|
@@ -3,6 +3,7 @@ export declare type Json = {
|
|
|
3
3
|
[key: string]: unknown;
|
|
4
4
|
};
|
|
5
5
|
export declare type THttpMethod = 'GET' | 'POST' | 'DELETE' | 'HEAD';
|
|
6
|
+
export declare type TForwardToAudiencePolicy = 'forward-url-full-path' | 'forward-url-origin';
|
|
6
7
|
export declare type TSdkActionPayloadMethod<Method extends THttpMethod> = {
|
|
7
8
|
method: Method;
|
|
8
9
|
};
|
|
@@ -17,6 +18,7 @@ export interface TSdkActionPayloadBase {
|
|
|
17
18
|
}
|
|
18
19
|
export interface TSdkActionPayloadForUri extends TSdkActionPayloadBase {
|
|
19
20
|
uri: string;
|
|
21
|
+
audiencePolicy?: TForwardToAudiencePolicy;
|
|
20
22
|
}
|
|
21
23
|
export interface TSdkActionPayloadForService extends TSdkActionPayloadBase {
|
|
22
24
|
service: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@commercetools-frontend/sdk",
|
|
3
|
-
"version": "21.
|
|
3
|
+
"version": "21.8.1",
|
|
4
4
|
"description": "Tools for declarative fetching",
|
|
5
5
|
"bugs": "https://github.com/commercetools/merchant-center-application-kit/issues",
|
|
6
6
|
"repository": {
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"dependencies": {
|
|
24
24
|
"@babel/runtime": "^7.17.9",
|
|
25
25
|
"@babel/runtime-corejs3": "^7.17.9",
|
|
26
|
-
"@commercetools-frontend/constants": "21.
|
|
26
|
+
"@commercetools-frontend/constants": "21.8.1",
|
|
27
27
|
"@commercetools/api-request-builder": "5.6.3",
|
|
28
28
|
"@commercetools/http-user-agent": "2.1.2",
|
|
29
29
|
"@commercetools/sdk-client": "2.1.2",
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"@types/uuid": "8.3.4",
|
|
45
45
|
"react": "17.0.2",
|
|
46
46
|
"react-redux": "7.2.8",
|
|
47
|
-
"redux": "4.
|
|
47
|
+
"redux": "4.2.0",
|
|
48
48
|
"redux-thunk": "2.4.1"
|
|
49
49
|
},
|
|
50
50
|
"peerDependencies": {
|