@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.
@@ -5,5 +5,6 @@ export declare class FetchErrorResponse extends Error {
5
5
  details(): Promise<{
6
6
  details: any;
7
7
  message: string;
8
+ requestId: any;
8
9
  }>;
9
10
  }
@@ -27,5 +27,6 @@ const errorBuilder = (code, description, details, data) => {
27
27
  ...details,
28
28
  },
29
29
  message: description,
30
+ requestId: data?.requestId,
30
31
  };
31
32
  };
@@ -80,5 +80,6 @@ const errorBuilder = (code, description, details, data) => {
80
80
  },
81
81
  status: code,
82
82
  },
83
+ responseId: data?.requestId,
83
84
  };
84
85
  };
@@ -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.
@@ -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
- return fetch(urlOrRequest, {
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((await boundGetAuthHeaders()).headers)) {
32
- urlOrRequest.headers.set(k, v);
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 fetch(urlOrRequest, requestInit);
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
- return fetch(url, {
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
+ }
@@ -5,5 +5,6 @@ export declare class FetchErrorResponse extends Error {
5
5
  details(): Promise<{
6
6
  details: any;
7
7
  message: string;
8
+ requestId: any;
8
9
  }>;
9
10
  }
@@ -31,5 +31,6 @@ const errorBuilder = (code, description, details, data) => {
31
31
  ...details,
32
32
  },
33
33
  message: description,
34
+ requestId: data?.requestId,
34
35
  };
35
36
  };
@@ -83,5 +83,6 @@ const errorBuilder = (code, description, details, data) => {
83
83
  },
84
84
  status: code,
85
85
  },
86
+ responseId: data?.requestId,
86
87
  };
87
88
  };
@@ -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.
@@ -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
- return fetch(urlOrRequest, {
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((await boundGetAuthHeaders()).headers)) {
35
- urlOrRequest.headers.set(k, v);
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 fetch(urlOrRequest, requestInit);
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
- return fetch(url, {
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.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.104.0",
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.38",
80
- "@wix/sdk-types": "^1.13.6",
79
+ "@wix/sdk-runtime": "0.3.41",
80
+ "@wix/sdk-types": "^1.13.8",
81
81
  "jose": "^5.10.0",
82
- "type-fest": "^4.37.0"
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.25",
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.38",
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.2",
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": "94fee4575cb4611f81b11c3117a9db5e7b3bd872ecedbd09d4b0ad35"
129
+ "falconPackageHash": "15cdc535eb057c86440c170ebcfdb97303baab58214c17fe55d9f76b"
130
130
  }