@wix/sdk 1.15.24 → 1.15.25
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/build/rest-modules.d.ts +2 -2
- package/build/rest-modules.js +25 -6
- package/build/wixClient.js +36 -21
- package/cjs/build/rest-modules.d.ts +2 -2
- package/cjs/build/rest-modules.js +25 -6
- package/cjs/build/wixClient.js +36 -21
- package/package.json +8 -8
package/build/rest-modules.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { BuildRESTFunction, PublicMetadata, RESTFunctionDescriptor } from '@wix/sdk-types';
|
|
1
|
+
import { BuildRESTFunction, PublicMetadata, RESTFunctionDescriptor, WixClientErrorHandler } from '@wix/sdk-types';
|
|
2
2
|
export type RESTModuleOptions = {
|
|
3
3
|
HTTPHost?: string;
|
|
4
4
|
};
|
|
5
|
-
export declare function buildRESTDescriptor<T extends RESTFunctionDescriptor>(origFunc: T, publicMetadata: PublicMetadata, boundFetch: typeof fetch, wixAPIFetch: (relativeUrl: string, options: RequestInit) => Promise<Response>, getActiveToken?: () => string | undefined, options?: RESTModuleOptions, hostName?: string | undefined, useCDN?: boolean): BuildRESTFunction<T>;
|
|
5
|
+
export declare function buildRESTDescriptor<T extends RESTFunctionDescriptor>(origFunc: T, publicMetadata: PublicMetadata, boundFetch: typeof fetch, errorHandler: WixClientErrorHandler | undefined, wixAPIFetch: (relativeUrl: string, options: RequestInit) => Promise<Response>, getActiveToken?: () => string | undefined, options?: RESTModuleOptions, hostName?: string | undefined, useCDN?: boolean): BuildRESTFunction<T>;
|
package/build/rest-modules.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { biHeaderGenerator } from './bi/biHeaderGenerator.js';
|
|
2
2
|
import { DEFAULT_API_URL, DEFAULT_EDGE_API_URL } from './common.js';
|
|
3
3
|
import { runWithoutContext } from '@wix/sdk-runtime/context';
|
|
4
|
-
|
|
4
|
+
import { transformError } from '@wix/sdk-runtime/transform-error';
|
|
5
|
+
export function buildRESTDescriptor(origFunc, publicMetadata, boundFetch, errorHandler, wixAPIFetch, getActiveToken, options, hostName, useCDN) {
|
|
5
6
|
return runWithoutContext(() => origFunc({
|
|
6
7
|
request: async (factory) => {
|
|
7
8
|
const requestOptions = factory({
|
|
@@ -20,7 +21,7 @@ export function buildRESTDescriptor(origFunc, publicMetadata, boundFetch, wixAPI
|
|
|
20
21
|
}
|
|
21
22
|
try {
|
|
22
23
|
const biHeader = biHeaderGenerator(requestOptions, publicMetadata, hostName);
|
|
23
|
-
const
|
|
24
|
+
const requestOptionsInit = {
|
|
24
25
|
method: request.method,
|
|
25
26
|
...(request.data && {
|
|
26
27
|
body: JSON.stringify(request.data),
|
|
@@ -28,7 +29,8 @@ export function buildRESTDescriptor(origFunc, publicMetadata, boundFetch, wixAPI
|
|
|
28
29
|
headers: {
|
|
29
30
|
...biHeader,
|
|
30
31
|
},
|
|
31
|
-
}
|
|
32
|
+
};
|
|
33
|
+
const res = await boundFetch(url, requestOptionsInit);
|
|
32
34
|
if (res.status !== 200) {
|
|
33
35
|
let dataError = null;
|
|
34
36
|
try {
|
|
@@ -37,10 +39,18 @@ export function buildRESTDescriptor(origFunc, publicMetadata, boundFetch, wixAPI
|
|
|
37
39
|
catch (e) {
|
|
38
40
|
//
|
|
39
41
|
}
|
|
40
|
-
|
|
42
|
+
const error = errorBuilder(res.status, dataError?.message, dataError?.details, {
|
|
41
43
|
requestId: res.headers.get('X-Wix-Request-Id'),
|
|
42
44
|
details: dataError,
|
|
43
45
|
});
|
|
46
|
+
const transformedError = transformError(error);
|
|
47
|
+
errorHandler?.handleError(transformedError, {
|
|
48
|
+
requestOptions: {
|
|
49
|
+
url: request.url,
|
|
50
|
+
...requestOptionsInit,
|
|
51
|
+
},
|
|
52
|
+
});
|
|
53
|
+
throw error;
|
|
44
54
|
}
|
|
45
55
|
const data = await res.json();
|
|
46
56
|
return {
|
|
@@ -62,8 +72,17 @@ export function buildRESTDescriptor(origFunc, publicMetadata, boundFetch, wixAPI
|
|
|
62
72
|
getActiveToken,
|
|
63
73
|
}));
|
|
64
74
|
}
|
|
75
|
+
class SDKError extends Error {
|
|
76
|
+
response;
|
|
77
|
+
requestId;
|
|
78
|
+
constructor(params) {
|
|
79
|
+
super();
|
|
80
|
+
this.response = params.response;
|
|
81
|
+
this.requestId = params.requestId;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
65
84
|
const errorBuilder = (code, description, details, data) => {
|
|
66
|
-
return {
|
|
85
|
+
return new SDKError({
|
|
67
86
|
response: {
|
|
68
87
|
data: {
|
|
69
88
|
details: {
|
|
@@ -81,5 +100,5 @@ const errorBuilder = (code, description, details, data) => {
|
|
|
81
100
|
status: code,
|
|
82
101
|
},
|
|
83
102
|
requestId: data?.requestId,
|
|
84
|
-
};
|
|
103
|
+
});
|
|
85
104
|
};
|
package/build/wixClient.js
CHANGED
|
@@ -28,29 +28,44 @@ export function createClient(config) {
|
|
|
28
28
|
? { [X_WIX_CONSISTENT_HEADER]: _headers[X_WIX_CONSISTENT_HEADER] }
|
|
29
29
|
: {}),
|
|
30
30
|
};
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
if (typeof v === 'string') {
|
|
45
|
-
urlOrRequest.headers.set(k, v);
|
|
31
|
+
const errorHandler = config.host?.getErrorHandler?.();
|
|
32
|
+
try {
|
|
33
|
+
if (typeof urlOrRequest === 'string' || urlOrRequest instanceof URL) {
|
|
34
|
+
const response = await fetch(urlOrRequest, {
|
|
35
|
+
...requestInit,
|
|
36
|
+
headers,
|
|
37
|
+
});
|
|
38
|
+
errorHandler?.handleError(response, {
|
|
39
|
+
requestOptions: requestInit,
|
|
40
|
+
});
|
|
41
|
+
const consistentHeader = findConsistentHeader(response);
|
|
42
|
+
if (consistentHeader) {
|
|
43
|
+
_headers[X_WIX_CONSISTENT_HEADER] = consistentHeader;
|
|
46
44
|
}
|
|
45
|
+
return response;
|
|
47
46
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
47
|
+
else {
|
|
48
|
+
for (const [k, v] of Object.entries(headers)) {
|
|
49
|
+
if (typeof v === 'string') {
|
|
50
|
+
urlOrRequest.headers.set(k, v);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
const response = await fetch(urlOrRequest, requestInit);
|
|
54
|
+
errorHandler?.handleError(response, {
|
|
55
|
+
requestOptions: requestInit,
|
|
56
|
+
});
|
|
57
|
+
const consistentHeader = findConsistentHeader(response);
|
|
58
|
+
if (consistentHeader) {
|
|
59
|
+
_headers[X_WIX_CONSISTENT_HEADER] = consistentHeader;
|
|
60
|
+
}
|
|
61
|
+
return response;
|
|
52
62
|
}
|
|
53
|
-
|
|
63
|
+
}
|
|
64
|
+
catch (e) {
|
|
65
|
+
errorHandler?.handleError(e, {
|
|
66
|
+
requestOptions: requestInit,
|
|
67
|
+
});
|
|
68
|
+
throw e;
|
|
54
69
|
}
|
|
55
70
|
};
|
|
56
71
|
const { client: servicePluginsClient, initModule: initServicePluginModule } = servicePluginsModules(authStrategy);
|
|
@@ -102,7 +117,7 @@ export function createClient(config) {
|
|
|
102
117
|
const shouldUseCDN = config.useCDN === undefined ? config.auth?.shouldUseCDN : config.useCDN;
|
|
103
118
|
return buildRESTDescriptor(runWithoutContext(() => isAmbassadorModule(modules))
|
|
104
119
|
? toHTTPModule(modules)
|
|
105
|
-
: modules, metadata ?? {}, boundFetch, (relativeUrl, fetchOptions) => {
|
|
120
|
+
: modules, metadata ?? {}, boundFetch, config.host?.getErrorHandler?.(), (relativeUrl, fetchOptions) => {
|
|
106
121
|
const finalUrl = new URL(relativeUrl, `https://${apiBaseUrl}`);
|
|
107
122
|
finalUrl.host = apiBaseUrl;
|
|
108
123
|
finalUrl.protocol = 'https';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { BuildRESTFunction, PublicMetadata, RESTFunctionDescriptor } from '@wix/sdk-types';
|
|
1
|
+
import { BuildRESTFunction, PublicMetadata, RESTFunctionDescriptor, WixClientErrorHandler } from '@wix/sdk-types';
|
|
2
2
|
export type RESTModuleOptions = {
|
|
3
3
|
HTTPHost?: string;
|
|
4
4
|
};
|
|
5
|
-
export declare function buildRESTDescriptor<T extends RESTFunctionDescriptor>(origFunc: T, publicMetadata: PublicMetadata, boundFetch: typeof fetch, wixAPIFetch: (relativeUrl: string, options: RequestInit) => Promise<Response>, getActiveToken?: () => string | undefined, options?: RESTModuleOptions, hostName?: string | undefined, useCDN?: boolean): BuildRESTFunction<T>;
|
|
5
|
+
export declare function buildRESTDescriptor<T extends RESTFunctionDescriptor>(origFunc: T, publicMetadata: PublicMetadata, boundFetch: typeof fetch, errorHandler: WixClientErrorHandler | undefined, wixAPIFetch: (relativeUrl: string, options: RequestInit) => Promise<Response>, getActiveToken?: () => string | undefined, options?: RESTModuleOptions, hostName?: string | undefined, useCDN?: boolean): BuildRESTFunction<T>;
|
|
@@ -4,7 +4,8 @@ exports.buildRESTDescriptor = buildRESTDescriptor;
|
|
|
4
4
|
const biHeaderGenerator_js_1 = require("./bi/biHeaderGenerator.js");
|
|
5
5
|
const common_js_1 = require("./common.js");
|
|
6
6
|
const context_1 = require("@wix/sdk-runtime/context");
|
|
7
|
-
|
|
7
|
+
const transform_error_1 = require("@wix/sdk-runtime/transform-error");
|
|
8
|
+
function buildRESTDescriptor(origFunc, publicMetadata, boundFetch, errorHandler, wixAPIFetch, getActiveToken, options, hostName, useCDN) {
|
|
8
9
|
return (0, context_1.runWithoutContext)(() => origFunc({
|
|
9
10
|
request: async (factory) => {
|
|
10
11
|
const requestOptions = factory({
|
|
@@ -23,7 +24,7 @@ function buildRESTDescriptor(origFunc, publicMetadata, boundFetch, wixAPIFetch,
|
|
|
23
24
|
}
|
|
24
25
|
try {
|
|
25
26
|
const biHeader = (0, biHeaderGenerator_js_1.biHeaderGenerator)(requestOptions, publicMetadata, hostName);
|
|
26
|
-
const
|
|
27
|
+
const requestOptionsInit = {
|
|
27
28
|
method: request.method,
|
|
28
29
|
...(request.data && {
|
|
29
30
|
body: JSON.stringify(request.data),
|
|
@@ -31,7 +32,8 @@ function buildRESTDescriptor(origFunc, publicMetadata, boundFetch, wixAPIFetch,
|
|
|
31
32
|
headers: {
|
|
32
33
|
...biHeader,
|
|
33
34
|
},
|
|
34
|
-
}
|
|
35
|
+
};
|
|
36
|
+
const res = await boundFetch(url, requestOptionsInit);
|
|
35
37
|
if (res.status !== 200) {
|
|
36
38
|
let dataError = null;
|
|
37
39
|
try {
|
|
@@ -40,10 +42,18 @@ function buildRESTDescriptor(origFunc, publicMetadata, boundFetch, wixAPIFetch,
|
|
|
40
42
|
catch (e) {
|
|
41
43
|
//
|
|
42
44
|
}
|
|
43
|
-
|
|
45
|
+
const error = errorBuilder(res.status, dataError?.message, dataError?.details, {
|
|
44
46
|
requestId: res.headers.get('X-Wix-Request-Id'),
|
|
45
47
|
details: dataError,
|
|
46
48
|
});
|
|
49
|
+
const transformedError = (0, transform_error_1.transformError)(error);
|
|
50
|
+
errorHandler?.handleError(transformedError, {
|
|
51
|
+
requestOptions: {
|
|
52
|
+
url: request.url,
|
|
53
|
+
...requestOptionsInit,
|
|
54
|
+
},
|
|
55
|
+
});
|
|
56
|
+
throw error;
|
|
47
57
|
}
|
|
48
58
|
const data = await res.json();
|
|
49
59
|
return {
|
|
@@ -65,8 +75,17 @@ function buildRESTDescriptor(origFunc, publicMetadata, boundFetch, wixAPIFetch,
|
|
|
65
75
|
getActiveToken,
|
|
66
76
|
}));
|
|
67
77
|
}
|
|
78
|
+
class SDKError extends Error {
|
|
79
|
+
response;
|
|
80
|
+
requestId;
|
|
81
|
+
constructor(params) {
|
|
82
|
+
super();
|
|
83
|
+
this.response = params.response;
|
|
84
|
+
this.requestId = params.requestId;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
68
87
|
const errorBuilder = (code, description, details, data) => {
|
|
69
|
-
return {
|
|
88
|
+
return new SDKError({
|
|
70
89
|
response: {
|
|
71
90
|
data: {
|
|
72
91
|
details: {
|
|
@@ -84,5 +103,5 @@ const errorBuilder = (code, description, details, data) => {
|
|
|
84
103
|
status: code,
|
|
85
104
|
},
|
|
86
105
|
requestId: data?.requestId,
|
|
87
|
-
};
|
|
106
|
+
});
|
|
88
107
|
};
|
package/cjs/build/wixClient.js
CHANGED
|
@@ -32,29 +32,44 @@ function createClient(config) {
|
|
|
32
32
|
? { [exports.X_WIX_CONSISTENT_HEADER]: _headers[exports.X_WIX_CONSISTENT_HEADER] }
|
|
33
33
|
: {}),
|
|
34
34
|
};
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
if (typeof v === 'string') {
|
|
49
|
-
urlOrRequest.headers.set(k, v);
|
|
35
|
+
const errorHandler = config.host?.getErrorHandler?.();
|
|
36
|
+
try {
|
|
37
|
+
if (typeof urlOrRequest === 'string' || urlOrRequest instanceof URL) {
|
|
38
|
+
const response = await fetch(urlOrRequest, {
|
|
39
|
+
...requestInit,
|
|
40
|
+
headers,
|
|
41
|
+
});
|
|
42
|
+
errorHandler?.handleError(response, {
|
|
43
|
+
requestOptions: requestInit,
|
|
44
|
+
});
|
|
45
|
+
const consistentHeader = findConsistentHeader(response);
|
|
46
|
+
if (consistentHeader) {
|
|
47
|
+
_headers[exports.X_WIX_CONSISTENT_HEADER] = consistentHeader;
|
|
50
48
|
}
|
|
49
|
+
return response;
|
|
51
50
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
51
|
+
else {
|
|
52
|
+
for (const [k, v] of Object.entries(headers)) {
|
|
53
|
+
if (typeof v === 'string') {
|
|
54
|
+
urlOrRequest.headers.set(k, v);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
const response = await fetch(urlOrRequest, requestInit);
|
|
58
|
+
errorHandler?.handleError(response, {
|
|
59
|
+
requestOptions: requestInit,
|
|
60
|
+
});
|
|
61
|
+
const consistentHeader = findConsistentHeader(response);
|
|
62
|
+
if (consistentHeader) {
|
|
63
|
+
_headers[exports.X_WIX_CONSISTENT_HEADER] = consistentHeader;
|
|
64
|
+
}
|
|
65
|
+
return response;
|
|
56
66
|
}
|
|
57
|
-
|
|
67
|
+
}
|
|
68
|
+
catch (e) {
|
|
69
|
+
errorHandler?.handleError(e, {
|
|
70
|
+
requestOptions: requestInit,
|
|
71
|
+
});
|
|
72
|
+
throw e;
|
|
58
73
|
}
|
|
59
74
|
};
|
|
60
75
|
const { client: servicePluginsClient, initModule: initServicePluginModule } = (0, service_plugin_modules_js_1.servicePluginsModules)(authStrategy);
|
|
@@ -106,7 +121,7 @@ function createClient(config) {
|
|
|
106
121
|
const shouldUseCDN = config.useCDN === undefined ? config.auth?.shouldUseCDN : config.useCDN;
|
|
107
122
|
return (0, rest_modules_js_1.buildRESTDescriptor)((0, context_1.runWithoutContext)(() => (0, ambassador_modules_js_1.isAmbassadorModule)(modules))
|
|
108
123
|
? (0, ambassador_modules_js_1.toHTTPModule)(modules)
|
|
109
|
-
: modules, metadata ?? {}, boundFetch, (relativeUrl, fetchOptions) => {
|
|
124
|
+
: modules, metadata ?? {}, boundFetch, config.host?.getErrorHandler?.(), (relativeUrl, fetchOptions) => {
|
|
110
125
|
const finalUrl = new URL(relativeUrl, `https://${apiBaseUrl}`);
|
|
111
126
|
finalUrl.host = apiBaseUrl;
|
|
112
127
|
finalUrl.protocol = 'https';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wix/sdk",
|
|
3
|
-
"version": "1.15.
|
|
3
|
+
"version": "1.15.25",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Ronny Ringel",
|
|
@@ -73,11 +73,11 @@
|
|
|
73
73
|
},
|
|
74
74
|
"dependencies": {
|
|
75
75
|
"@wix/identity": "^1.0.104",
|
|
76
|
-
"@wix/image-kit": "^1.
|
|
76
|
+
"@wix/image-kit": "^1.111.0",
|
|
77
77
|
"@wix/redirects": "^1.0.70",
|
|
78
78
|
"@wix/sdk-context": "0.0.1",
|
|
79
|
-
"@wix/sdk-runtime": "0.3.
|
|
80
|
-
"@wix/sdk-types": "^1.13.
|
|
79
|
+
"@wix/sdk-runtime": "0.3.58",
|
|
80
|
+
"@wix/sdk-types": "^1.13.37",
|
|
81
81
|
"jose": "^5.10.0",
|
|
82
82
|
"type-fest": "^4.41.0"
|
|
83
83
|
},
|
|
@@ -86,19 +86,19 @@
|
|
|
86
86
|
},
|
|
87
87
|
"devDependencies": {
|
|
88
88
|
"@types/is-ci": "^3.0.4",
|
|
89
|
-
"@types/node": "^20.19.
|
|
89
|
+
"@types/node": "^20.19.9",
|
|
90
90
|
"@vitest/ui": "^1.6.1",
|
|
91
91
|
"@wix/ecom": "^1.0.886",
|
|
92
92
|
"@wix/events": "^1.0.382",
|
|
93
93
|
"@wix/metro": "^1.0.93",
|
|
94
94
|
"@wix/metro-runtime": "^1.1891.0",
|
|
95
|
-
"@wix/sdk-runtime": "0.3.
|
|
95
|
+
"@wix/sdk-runtime": "0.3.58",
|
|
96
96
|
"eslint": "^8.57.1",
|
|
97
97
|
"eslint-config-sdk": "0.0.0",
|
|
98
98
|
"graphql": "^16.8.0",
|
|
99
99
|
"is-ci": "^3.0.1",
|
|
100
100
|
"jsdom": "^22.1.0",
|
|
101
|
-
"msw": "^2.10.
|
|
101
|
+
"msw": "^2.10.4",
|
|
102
102
|
"typescript": "^5.8.3",
|
|
103
103
|
"vitest": "^1.6.1",
|
|
104
104
|
"vitest-teamcity-reporter": "^0.3.1"
|
|
@@ -126,5 +126,5 @@
|
|
|
126
126
|
"wallaby": {
|
|
127
127
|
"autoDetect": true
|
|
128
128
|
},
|
|
129
|
-
"falconPackageHash": "
|
|
129
|
+
"falconPackageHash": "5fe116d36737d407ace325165141af2b145afe6613771f7f278ce04a"
|
|
130
130
|
}
|