@wix/sdk 1.15.15 → 1.15.17
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/fetch-error.d.ts +1 -0
- package/build/fetch-error.js +1 -0
- package/build/rest-modules.js +1 -0
- package/build/wixClient.d.ts +1 -0
- package/build/wixClient.js +36 -9
- package/cjs/build/fetch-error.d.ts +1 -0
- package/cjs/build/fetch-error.js +1 -0
- package/cjs/build/rest-modules.js +1 -0
- package/cjs/build/wixClient.d.ts +1 -0
- package/cjs/build/wixClient.js +37 -9
- package/package.json +9 -9
package/build/fetch-error.d.ts
CHANGED
package/build/fetch-error.js
CHANGED
package/build/rest-modules.js
CHANGED
package/build/wixClient.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ import { EventHandlersClient } from './event-handlers-modules.js';
|
|
|
5
5
|
import { ServicePluginsClient } from './service-plugin-modules.js';
|
|
6
6
|
export type ContextType = 'global' | 'module';
|
|
7
7
|
type Headers = Record<string, string>;
|
|
8
|
+
export declare const X_WIX_CONSISTENT_HEADER = "X-Wix-Consistent";
|
|
8
9
|
/**
|
|
9
10
|
* This type is used in `createClient` to ensure that the given host matches the host of the given descriptors.
|
|
10
11
|
* If the host does not match, the descriptor is replaced with a host module that will throw an error when used.
|
package/build/wixClient.js
CHANGED
|
@@ -9,6 +9,7 @@ import { buildRESTDescriptor } from './rest-modules.js';
|
|
|
9
9
|
import { eventHandlersModules, isEventHandlerModule, } from './event-handlers-modules.js';
|
|
10
10
|
import { isServicePluginModule, servicePluginsModules, } from './service-plugin-modules.js';
|
|
11
11
|
import { runWithoutContext } from '@wix/sdk-runtime/context';
|
|
12
|
+
export const X_WIX_CONSISTENT_HEADER = 'X-Wix-Consistent';
|
|
12
13
|
export function createClient(config) {
|
|
13
14
|
const _headers = config.headers || { Authorization: '' };
|
|
14
15
|
const authStrategy = config.auth ||
|
|
@@ -18,20 +19,37 @@ export function createClient(config) {
|
|
|
18
19
|
const boundGetAuthHeaders = authStrategy.getAuthHeaders.bind(undefined, config.host);
|
|
19
20
|
authStrategy.getAuthHeaders = boundGetAuthHeaders;
|
|
20
21
|
const fetchWithAuth = async (urlOrRequest, requestInit) => {
|
|
22
|
+
const authHeaders = await boundGetAuthHeaders();
|
|
23
|
+
const headers = {
|
|
24
|
+
...(requestInit?.headers ?? {}),
|
|
25
|
+
...authHeaders.headers,
|
|
26
|
+
...(_headers[X_WIX_CONSISTENT_HEADER]
|
|
27
|
+
? { [X_WIX_CONSISTENT_HEADER]: _headers[X_WIX_CONSISTENT_HEADER] }
|
|
28
|
+
: {}),
|
|
29
|
+
};
|
|
21
30
|
if (typeof urlOrRequest === 'string' || urlOrRequest instanceof URL) {
|
|
22
|
-
|
|
31
|
+
const response = await fetch(urlOrRequest, {
|
|
23
32
|
...requestInit,
|
|
24
|
-
headers
|
|
25
|
-
...requestInit?.headers,
|
|
26
|
-
...(await boundGetAuthHeaders()).headers,
|
|
27
|
-
},
|
|
33
|
+
headers,
|
|
28
34
|
});
|
|
35
|
+
const consistentHeader = findConsistentHeader(response);
|
|
36
|
+
if (consistentHeader) {
|
|
37
|
+
_headers[X_WIX_CONSISTENT_HEADER] = consistentHeader;
|
|
38
|
+
}
|
|
39
|
+
return response;
|
|
29
40
|
}
|
|
30
41
|
else {
|
|
31
|
-
for (const [k, v] of Object.entries(
|
|
32
|
-
|
|
42
|
+
for (const [k, v] of Object.entries(headers)) {
|
|
43
|
+
if (typeof v === 'string') {
|
|
44
|
+
urlOrRequest.headers.set(k, v);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
const response = await fetch(urlOrRequest, requestInit);
|
|
48
|
+
const consistentHeader = findConsistentHeader(response);
|
|
49
|
+
if (consistentHeader) {
|
|
50
|
+
_headers[X_WIX_CONSISTENT_HEADER] = consistentHeader;
|
|
33
51
|
}
|
|
34
|
-
return
|
|
52
|
+
return response;
|
|
35
53
|
}
|
|
36
54
|
};
|
|
37
55
|
const { client: servicePluginsClient, initModule: initServicePluginModule } = servicePluginsModules(authStrategy);
|
|
@@ -39,7 +57,7 @@ export function createClient(config) {
|
|
|
39
57
|
const boundFetch = async (url, options) => {
|
|
40
58
|
const authHeaders = await boundGetAuthHeaders();
|
|
41
59
|
const defaultContentTypeHeader = getDefaultContentHeader(options);
|
|
42
|
-
|
|
60
|
+
const response = await fetch(url, {
|
|
43
61
|
...options,
|
|
44
62
|
headers: {
|
|
45
63
|
...defaultContentTypeHeader,
|
|
@@ -49,6 +67,11 @@ export function createClient(config) {
|
|
|
49
67
|
...config.host?.essentials?.passThroughHeaders,
|
|
50
68
|
},
|
|
51
69
|
});
|
|
70
|
+
const consistentHeader = findConsistentHeader(response);
|
|
71
|
+
if (consistentHeader) {
|
|
72
|
+
_headers[X_WIX_CONSISTENT_HEADER] = consistentHeader;
|
|
73
|
+
}
|
|
74
|
+
return response;
|
|
52
75
|
};
|
|
53
76
|
// This is typed as `any` because when trying to properly type it as defined
|
|
54
77
|
// on the WixClient, typescript starts failing with `Type instantiation is
|
|
@@ -165,3 +188,7 @@ export function createClient(config) {
|
|
|
165
188
|
servicePlugins: servicePluginsClient,
|
|
166
189
|
};
|
|
167
190
|
}
|
|
191
|
+
function findConsistentHeader(response) {
|
|
192
|
+
return (response.headers?.get(X_WIX_CONSISTENT_HEADER) ??
|
|
193
|
+
response.headers?.get(X_WIX_CONSISTENT_HEADER.toLowerCase()));
|
|
194
|
+
}
|
package/cjs/build/fetch-error.js
CHANGED
package/cjs/build/wixClient.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ import { EventHandlersClient } from './event-handlers-modules.js';
|
|
|
5
5
|
import { ServicePluginsClient } from './service-plugin-modules.js';
|
|
6
6
|
export type ContextType = 'global' | 'module';
|
|
7
7
|
type Headers = Record<string, string>;
|
|
8
|
+
export declare const X_WIX_CONSISTENT_HEADER = "X-Wix-Consistent";
|
|
8
9
|
/**
|
|
9
10
|
* This type is used in `createClient` to ensure that the given host matches the host of the given descriptors.
|
|
10
11
|
* If the host does not match, the descriptor is replaced with a host module that will throw an error when used.
|
package/cjs/build/wixClient.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.X_WIX_CONSISTENT_HEADER = void 0;
|
|
3
4
|
exports.createClient = createClient;
|
|
4
5
|
const sdk_context_1 = require("@wix/sdk-context");
|
|
5
6
|
const sdk_types_1 = require("@wix/sdk-types");
|
|
@@ -12,6 +13,7 @@ const rest_modules_js_1 = require("./rest-modules.js");
|
|
|
12
13
|
const event_handlers_modules_js_1 = require("./event-handlers-modules.js");
|
|
13
14
|
const service_plugin_modules_js_1 = require("./service-plugin-modules.js");
|
|
14
15
|
const context_1 = require("@wix/sdk-runtime/context");
|
|
16
|
+
exports.X_WIX_CONSISTENT_HEADER = 'X-Wix-Consistent';
|
|
15
17
|
function createClient(config) {
|
|
16
18
|
const _headers = config.headers || { Authorization: '' };
|
|
17
19
|
const authStrategy = config.auth ||
|
|
@@ -21,20 +23,37 @@ function createClient(config) {
|
|
|
21
23
|
const boundGetAuthHeaders = authStrategy.getAuthHeaders.bind(undefined, config.host);
|
|
22
24
|
authStrategy.getAuthHeaders = boundGetAuthHeaders;
|
|
23
25
|
const fetchWithAuth = async (urlOrRequest, requestInit) => {
|
|
26
|
+
const authHeaders = await boundGetAuthHeaders();
|
|
27
|
+
const headers = {
|
|
28
|
+
...(requestInit?.headers ?? {}),
|
|
29
|
+
...authHeaders.headers,
|
|
30
|
+
...(_headers[exports.X_WIX_CONSISTENT_HEADER]
|
|
31
|
+
? { [exports.X_WIX_CONSISTENT_HEADER]: _headers[exports.X_WIX_CONSISTENT_HEADER] }
|
|
32
|
+
: {}),
|
|
33
|
+
};
|
|
24
34
|
if (typeof urlOrRequest === 'string' || urlOrRequest instanceof URL) {
|
|
25
|
-
|
|
35
|
+
const response = await fetch(urlOrRequest, {
|
|
26
36
|
...requestInit,
|
|
27
|
-
headers
|
|
28
|
-
...requestInit?.headers,
|
|
29
|
-
...(await boundGetAuthHeaders()).headers,
|
|
30
|
-
},
|
|
37
|
+
headers,
|
|
31
38
|
});
|
|
39
|
+
const consistentHeader = findConsistentHeader(response);
|
|
40
|
+
if (consistentHeader) {
|
|
41
|
+
_headers[exports.X_WIX_CONSISTENT_HEADER] = consistentHeader;
|
|
42
|
+
}
|
|
43
|
+
return response;
|
|
32
44
|
}
|
|
33
45
|
else {
|
|
34
|
-
for (const [k, v] of Object.entries(
|
|
35
|
-
|
|
46
|
+
for (const [k, v] of Object.entries(headers)) {
|
|
47
|
+
if (typeof v === 'string') {
|
|
48
|
+
urlOrRequest.headers.set(k, v);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
const response = await fetch(urlOrRequest, requestInit);
|
|
52
|
+
const consistentHeader = findConsistentHeader(response);
|
|
53
|
+
if (consistentHeader) {
|
|
54
|
+
_headers[exports.X_WIX_CONSISTENT_HEADER] = consistentHeader;
|
|
36
55
|
}
|
|
37
|
-
return
|
|
56
|
+
return response;
|
|
38
57
|
}
|
|
39
58
|
};
|
|
40
59
|
const { client: servicePluginsClient, initModule: initServicePluginModule } = (0, service_plugin_modules_js_1.servicePluginsModules)(authStrategy);
|
|
@@ -42,7 +61,7 @@ function createClient(config) {
|
|
|
42
61
|
const boundFetch = async (url, options) => {
|
|
43
62
|
const authHeaders = await boundGetAuthHeaders();
|
|
44
63
|
const defaultContentTypeHeader = (0, helpers_js_1.getDefaultContentHeader)(options);
|
|
45
|
-
|
|
64
|
+
const response = await fetch(url, {
|
|
46
65
|
...options,
|
|
47
66
|
headers: {
|
|
48
67
|
...defaultContentTypeHeader,
|
|
@@ -52,6 +71,11 @@ function createClient(config) {
|
|
|
52
71
|
...config.host?.essentials?.passThroughHeaders,
|
|
53
72
|
},
|
|
54
73
|
});
|
|
74
|
+
const consistentHeader = findConsistentHeader(response);
|
|
75
|
+
if (consistentHeader) {
|
|
76
|
+
_headers[exports.X_WIX_CONSISTENT_HEADER] = consistentHeader;
|
|
77
|
+
}
|
|
78
|
+
return response;
|
|
55
79
|
};
|
|
56
80
|
// This is typed as `any` because when trying to properly type it as defined
|
|
57
81
|
// on the WixClient, typescript starts failing with `Type instantiation is
|
|
@@ -168,3 +192,7 @@ function createClient(config) {
|
|
|
168
192
|
servicePlugins: servicePluginsClient,
|
|
169
193
|
};
|
|
170
194
|
}
|
|
195
|
+
function findConsistentHeader(response) {
|
|
196
|
+
return (response.headers?.get(exports.X_WIX_CONSISTENT_HEADER) ??
|
|
197
|
+
response.headers?.get(exports.X_WIX_CONSISTENT_HEADER.toLowerCase()));
|
|
198
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wix/sdk",
|
|
3
|
-
"version": "1.15.
|
|
3
|
+
"version": "1.15.17",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Ronny Ringel",
|
|
@@ -73,33 +73,33 @@
|
|
|
73
73
|
},
|
|
74
74
|
"dependencies": {
|
|
75
75
|
"@wix/identity": "^1.0.104",
|
|
76
|
-
"@wix/image-kit": "^1.
|
|
76
|
+
"@wix/image-kit": "^1.105.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.41",
|
|
80
|
+
"@wix/sdk-types": "^1.13.8",
|
|
81
81
|
"jose": "^5.10.0",
|
|
82
|
-
"type-fest": "^4.
|
|
82
|
+
"type-fest": "^4.39.1"
|
|
83
83
|
},
|
|
84
84
|
"optionalDependencies": {
|
|
85
85
|
"graphql": "^0.8.0 || ^0.9.0 || ^0.10.0 || ^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0 || ^16.0.0 || ^17.0.0"
|
|
86
86
|
},
|
|
87
87
|
"devDependencies": {
|
|
88
88
|
"@types/is-ci": "^3.0.4",
|
|
89
|
-
"@types/node": "^20.17.
|
|
89
|
+
"@types/node": "^20.17.30",
|
|
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.41",
|
|
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
101
|
"msw": "^2.7.3",
|
|
102
|
-
"typescript": "^5.8.
|
|
102
|
+
"typescript": "^5.8.3",
|
|
103
103
|
"vitest": "^1.6.1",
|
|
104
104
|
"vitest-teamcity-reporter": "^0.3.1"
|
|
105
105
|
},
|
|
@@ -126,5 +126,5 @@
|
|
|
126
126
|
"wallaby": {
|
|
127
127
|
"autoDetect": true
|
|
128
128
|
},
|
|
129
|
-
"falconPackageHash": "
|
|
129
|
+
"falconPackageHash": "15cdc535eb057c86440c170ebcfdb97303baab58214c17fe55d9f76b"
|
|
130
130
|
}
|