@wix/sdk 1.15.24 → 1.15.26
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 +27 -6
- package/build/wixClient.js +47 -21
- package/cjs/build/rest-modules.d.ts +2 -2
- package/cjs/build/rest-modules.js +27 -6
- package/cjs/build/wixClient.js +47 -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,20 @@ 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
|
+
method: request.method,
|
|
51
|
+
entityFqdn: requestOptions.entityFqdn,
|
|
52
|
+
methodFqn: requestOptions.methodFqn,
|
|
53
|
+
},
|
|
54
|
+
});
|
|
55
|
+
throw error;
|
|
44
56
|
}
|
|
45
57
|
const data = await res.json();
|
|
46
58
|
return {
|
|
@@ -62,8 +74,17 @@ export function buildRESTDescriptor(origFunc, publicMetadata, boundFetch, wixAPI
|
|
|
62
74
|
getActiveToken,
|
|
63
75
|
}));
|
|
64
76
|
}
|
|
77
|
+
class SDKError extends Error {
|
|
78
|
+
response;
|
|
79
|
+
requestId;
|
|
80
|
+
constructor(params) {
|
|
81
|
+
super();
|
|
82
|
+
this.response = params.response;
|
|
83
|
+
this.requestId = params.requestId;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
65
86
|
const errorBuilder = (code, description, details, data) => {
|
|
66
|
-
return {
|
|
87
|
+
return new SDKError({
|
|
67
88
|
response: {
|
|
68
89
|
data: {
|
|
69
90
|
details: {
|
|
@@ -81,5 +102,5 @@ const errorBuilder = (code, description, details, data) => {
|
|
|
81
102
|
status: code,
|
|
82
103
|
},
|
|
83
104
|
requestId: data?.requestId,
|
|
84
|
-
};
|
|
105
|
+
});
|
|
85
106
|
};
|
package/build/wixClient.js
CHANGED
|
@@ -28,29 +28,55 @@ 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
|
-
|
|
45
|
-
|
|
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: {
|
|
40
|
+
url: urlOrRequest.toString(),
|
|
41
|
+
method: requestInit?.method,
|
|
42
|
+
},
|
|
43
|
+
});
|
|
44
|
+
const consistentHeader = findConsistentHeader(response);
|
|
45
|
+
if (consistentHeader) {
|
|
46
|
+
_headers[X_WIX_CONSISTENT_HEADER] = consistentHeader;
|
|
46
47
|
}
|
|
48
|
+
return response;
|
|
47
49
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
50
|
+
else {
|
|
51
|
+
for (const [k, v] of Object.entries(headers)) {
|
|
52
|
+
if (typeof v === 'string') {
|
|
53
|
+
urlOrRequest.headers.set(k, v);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
const response = await fetch(urlOrRequest, requestInit);
|
|
57
|
+
errorHandler?.handleError(response, {
|
|
58
|
+
requestOptions: {
|
|
59
|
+
url: urlOrRequest.url,
|
|
60
|
+
method: requestInit?.method,
|
|
61
|
+
},
|
|
62
|
+
});
|
|
63
|
+
const consistentHeader = findConsistentHeader(response);
|
|
64
|
+
if (consistentHeader) {
|
|
65
|
+
_headers[X_WIX_CONSISTENT_HEADER] = consistentHeader;
|
|
66
|
+
}
|
|
67
|
+
return response;
|
|
52
68
|
}
|
|
53
|
-
|
|
69
|
+
}
|
|
70
|
+
catch (e) {
|
|
71
|
+
errorHandler?.handleError(e, {
|
|
72
|
+
requestOptions: {
|
|
73
|
+
url: typeof urlOrRequest === 'string' || urlOrRequest instanceof URL
|
|
74
|
+
? urlOrRequest.toString()
|
|
75
|
+
: urlOrRequest.url,
|
|
76
|
+
method: requestInit?.method,
|
|
77
|
+
},
|
|
78
|
+
});
|
|
79
|
+
throw e;
|
|
54
80
|
}
|
|
55
81
|
};
|
|
56
82
|
const { client: servicePluginsClient, initModule: initServicePluginModule } = servicePluginsModules(authStrategy);
|
|
@@ -102,7 +128,7 @@ export function createClient(config) {
|
|
|
102
128
|
const shouldUseCDN = config.useCDN === undefined ? config.auth?.shouldUseCDN : config.useCDN;
|
|
103
129
|
return buildRESTDescriptor(runWithoutContext(() => isAmbassadorModule(modules))
|
|
104
130
|
? toHTTPModule(modules)
|
|
105
|
-
: modules, metadata ?? {}, boundFetch, (relativeUrl, fetchOptions) => {
|
|
131
|
+
: modules, metadata ?? {}, boundFetch, config.host?.getErrorHandler?.(), (relativeUrl, fetchOptions) => {
|
|
106
132
|
const finalUrl = new URL(relativeUrl, `https://${apiBaseUrl}`);
|
|
107
133
|
finalUrl.host = apiBaseUrl;
|
|
108
134
|
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,20 @@ 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
|
+
method: request.method,
|
|
54
|
+
entityFqdn: requestOptions.entityFqdn,
|
|
55
|
+
methodFqn: requestOptions.methodFqn,
|
|
56
|
+
},
|
|
57
|
+
});
|
|
58
|
+
throw error;
|
|
47
59
|
}
|
|
48
60
|
const data = await res.json();
|
|
49
61
|
return {
|
|
@@ -65,8 +77,17 @@ function buildRESTDescriptor(origFunc, publicMetadata, boundFetch, wixAPIFetch,
|
|
|
65
77
|
getActiveToken,
|
|
66
78
|
}));
|
|
67
79
|
}
|
|
80
|
+
class SDKError extends Error {
|
|
81
|
+
response;
|
|
82
|
+
requestId;
|
|
83
|
+
constructor(params) {
|
|
84
|
+
super();
|
|
85
|
+
this.response = params.response;
|
|
86
|
+
this.requestId = params.requestId;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
68
89
|
const errorBuilder = (code, description, details, data) => {
|
|
69
|
-
return {
|
|
90
|
+
return new SDKError({
|
|
70
91
|
response: {
|
|
71
92
|
data: {
|
|
72
93
|
details: {
|
|
@@ -84,5 +105,5 @@ const errorBuilder = (code, description, details, data) => {
|
|
|
84
105
|
status: code,
|
|
85
106
|
},
|
|
86
107
|
requestId: data?.requestId,
|
|
87
|
-
};
|
|
108
|
+
});
|
|
88
109
|
};
|
package/cjs/build/wixClient.js
CHANGED
|
@@ -32,29 +32,55 @@ 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
|
-
|
|
49
|
-
|
|
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: {
|
|
44
|
+
url: urlOrRequest.toString(),
|
|
45
|
+
method: requestInit?.method,
|
|
46
|
+
},
|
|
47
|
+
});
|
|
48
|
+
const consistentHeader = findConsistentHeader(response);
|
|
49
|
+
if (consistentHeader) {
|
|
50
|
+
_headers[exports.X_WIX_CONSISTENT_HEADER] = consistentHeader;
|
|
50
51
|
}
|
|
52
|
+
return response;
|
|
51
53
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
54
|
+
else {
|
|
55
|
+
for (const [k, v] of Object.entries(headers)) {
|
|
56
|
+
if (typeof v === 'string') {
|
|
57
|
+
urlOrRequest.headers.set(k, v);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
const response = await fetch(urlOrRequest, requestInit);
|
|
61
|
+
errorHandler?.handleError(response, {
|
|
62
|
+
requestOptions: {
|
|
63
|
+
url: urlOrRequest.url,
|
|
64
|
+
method: requestInit?.method,
|
|
65
|
+
},
|
|
66
|
+
});
|
|
67
|
+
const consistentHeader = findConsistentHeader(response);
|
|
68
|
+
if (consistentHeader) {
|
|
69
|
+
_headers[exports.X_WIX_CONSISTENT_HEADER] = consistentHeader;
|
|
70
|
+
}
|
|
71
|
+
return response;
|
|
56
72
|
}
|
|
57
|
-
|
|
73
|
+
}
|
|
74
|
+
catch (e) {
|
|
75
|
+
errorHandler?.handleError(e, {
|
|
76
|
+
requestOptions: {
|
|
77
|
+
url: typeof urlOrRequest === 'string' || urlOrRequest instanceof URL
|
|
78
|
+
? urlOrRequest.toString()
|
|
79
|
+
: urlOrRequest.url,
|
|
80
|
+
method: requestInit?.method,
|
|
81
|
+
},
|
|
82
|
+
});
|
|
83
|
+
throw e;
|
|
58
84
|
}
|
|
59
85
|
};
|
|
60
86
|
const { client: servicePluginsClient, initModule: initServicePluginModule } = (0, service_plugin_modules_js_1.servicePluginsModules)(authStrategy);
|
|
@@ -106,7 +132,7 @@ function createClient(config) {
|
|
|
106
132
|
const shouldUseCDN = config.useCDN === undefined ? config.auth?.shouldUseCDN : config.useCDN;
|
|
107
133
|
return (0, rest_modules_js_1.buildRESTDescriptor)((0, context_1.runWithoutContext)(() => (0, ambassador_modules_js_1.isAmbassadorModule)(modules))
|
|
108
134
|
? (0, ambassador_modules_js_1.toHTTPModule)(modules)
|
|
109
|
-
: modules, metadata ?? {}, boundFetch, (relativeUrl, fetchOptions) => {
|
|
135
|
+
: modules, metadata ?? {}, boundFetch, config.host?.getErrorHandler?.(), (relativeUrl, fetchOptions) => {
|
|
110
136
|
const finalUrl = new URL(relativeUrl, `https://${apiBaseUrl}`);
|
|
111
137
|
finalUrl.host = apiBaseUrl;
|
|
112
138
|
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.26",
|
|
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.59",
|
|
80
|
+
"@wix/sdk-types": "^1.13.38",
|
|
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.59",
|
|
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": "a9ba398976c6118284790b3662705dea38ee7caeb3959007dae2023b"
|
|
130
130
|
}
|