@wix/sdk 1.15.16 → 1.15.18
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/auth/SiteSessionAuth.d.ts +4 -0
- package/build/auth/SiteSessionAuth.js +7 -0
- package/build/auth/oauth2/OAuthStrategy.js +5 -0
- package/build/auth/oauth2/types.d.ts +4 -0
- package/build/auth/pre-warm-cookie.d.ts +3 -0
- package/build/auth/pre-warm-cookie.js +48 -0
- package/build/wixClient.d.ts +1 -0
- package/build/wixClient.js +36 -9
- package/cjs/build/auth/SiteSessionAuth.d.ts +4 -0
- package/cjs/build/auth/SiteSessionAuth.js +7 -0
- package/cjs/build/auth/oauth2/OAuthStrategy.js +5 -0
- package/cjs/build/auth/oauth2/types.d.ts +4 -0
- package/cjs/build/auth/pre-warm-cookie.d.ts +3 -0
- package/cjs/build/auth/pre-warm-cookie.js +53 -0
- package/cjs/build/wixClient.d.ts +1 -0
- package/cjs/build/wixClient.js +37 -9
- package/package.json +10 -10
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { RefreshToken, Tokens } from './oauth2/types.js';
|
|
2
|
+
import { isVisitorCookieWarmedUp, preWarmVisitorCookie } from './pre-warm-cookie.js';
|
|
2
3
|
export declare function SiteSessionAuth(config: {
|
|
3
4
|
clientId: string;
|
|
4
5
|
publicKey?: string;
|
|
@@ -12,7 +13,10 @@ export declare function SiteSessionAuth(config: {
|
|
|
12
13
|
};
|
|
13
14
|
}>;
|
|
14
15
|
setTokens: (tokens: Tokens) => void;
|
|
16
|
+
loggedIn: () => boolean;
|
|
15
17
|
getTokens: () => Tokens;
|
|
18
|
+
isSessionSynced: typeof isVisitorCookieWarmedUp;
|
|
19
|
+
syncToWixPages: typeof preWarmVisitorCookie;
|
|
16
20
|
};
|
|
17
21
|
export interface TokenResponse {
|
|
18
22
|
access_token: string;
|
|
@@ -2,6 +2,7 @@ import { biHeaderGenerator } from '../bi/biHeaderGenerator.js';
|
|
|
2
2
|
import { DEFAULT_API_URL } from '../common.js';
|
|
3
3
|
import { createAccessToken, isTokenExpired } from '../tokenHelpers.js';
|
|
4
4
|
import { TokenRole } from './oauth2/types.js';
|
|
5
|
+
import { isVisitorCookieWarmedUp, preWarmVisitorCookie, } from './pre-warm-cookie.js';
|
|
5
6
|
export function SiteSessionAuth(config) {
|
|
6
7
|
const _tokens = config.tokens || {
|
|
7
8
|
accessToken: { value: '', expiresAt: 0 },
|
|
@@ -60,12 +61,18 @@ export function SiteSessionAuth(config) {
|
|
|
60
61
|
refreshToken,
|
|
61
62
|
};
|
|
62
63
|
};
|
|
64
|
+
const loggedIn = () => {
|
|
65
|
+
return _tokens.refreshToken.role === TokenRole.MEMBER;
|
|
66
|
+
};
|
|
63
67
|
return {
|
|
64
68
|
generateVisitorTokens,
|
|
65
69
|
renewToken,
|
|
66
70
|
getAuthHeaders,
|
|
67
71
|
setTokens,
|
|
72
|
+
loggedIn,
|
|
68
73
|
getTokens: () => _tokens,
|
|
74
|
+
isSessionSynced: isVisitorCookieWarmedUp,
|
|
75
|
+
syncToWixPages: preWarmVisitorCookie,
|
|
69
76
|
};
|
|
70
77
|
}
|
|
71
78
|
const fetchTokens = async (payload, headers = {}) => {
|
|
@@ -8,6 +8,7 @@ import { addPostMessageListener, loadFrame } from '../../iframeUtils.js';
|
|
|
8
8
|
import { EMAIL_EXISTS, INVALID_CAPTCHA, INVALID_PASSWORD, MISSING_CAPTCHA, RESET_PASSWORD, } from './constants.js';
|
|
9
9
|
import { biHeaderGenerator } from '../../bi/biHeaderGenerator.js';
|
|
10
10
|
import { pkceChallenge } from './pkce-challenge.js';
|
|
11
|
+
import { isVisitorCookieWarmedUp, preWarmVisitorCookie, } from '../pre-warm-cookie.js';
|
|
11
12
|
const moduleWithTokens = { redirects, authentication, recovery, verification };
|
|
12
13
|
export function OAuthStrategy(config) {
|
|
13
14
|
const _tokens = config.tokens || {
|
|
@@ -350,6 +351,10 @@ export function OAuthStrategy(config) {
|
|
|
350
351
|
sendPasswordResetEmail,
|
|
351
352
|
captchaInvisibleSiteKey: '6LdoPaUfAAAAAJphvHoUoOob7mx0KDlXyXlgrx5v',
|
|
352
353
|
captchaVisibleSiteKey: '6Ld0J8IcAAAAANyrnxzrRlX1xrrdXsOmsepUYosy',
|
|
354
|
+
sessions: {
|
|
355
|
+
isSessionSynced: isVisitorCookieWarmedUp,
|
|
356
|
+
syncToWixPages: preWarmVisitorCookie,
|
|
357
|
+
},
|
|
353
358
|
};
|
|
354
359
|
}
|
|
355
360
|
const fetchTokens = async (payload, headers = {}) => {
|
|
@@ -79,6 +79,10 @@ export interface IOAuthStrategy extends AuthenticationStrategy {
|
|
|
79
79
|
* @returns Tokens (access and refresh) for the member
|
|
80
80
|
*/
|
|
81
81
|
getMemberTokensForExternalLogin: (memberId: string, apiKey: string) => Promise<Tokens>;
|
|
82
|
+
sessions: {
|
|
83
|
+
isSessionSynced: () => boolean;
|
|
84
|
+
syncToWixPages: () => Promise<void>;
|
|
85
|
+
};
|
|
82
86
|
}
|
|
83
87
|
export declare enum LoginState {
|
|
84
88
|
SUCCESS = "SUCCESS",
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { redirects } from '@wix/redirects';
|
|
2
|
+
export const LOCALSTORAGE_PREWARM_REDIRECT_KEY = 'wixRedirectSessionLastPreWarm';
|
|
3
|
+
export function isVisitorCookieWarmedUp() {
|
|
4
|
+
// Check if we already pre-warmed recently
|
|
5
|
+
const lastPreWarmTimeString = localStorage.getItem(LOCALSTORAGE_PREWARM_REDIRECT_KEY);
|
|
6
|
+
const currentTime = Date.now();
|
|
7
|
+
// If we have a stored timestamp, check if it's been less than a week
|
|
8
|
+
if (lastPreWarmTimeString) {
|
|
9
|
+
const lastPreWarmTime = parseInt(lastPreWarmTimeString, 10);
|
|
10
|
+
const oneWeekMs = 7 * 24 * 60 * 60 * 1000; // 7 days in milliseconds
|
|
11
|
+
if (currentTime - lastPreWarmTime < oneWeekMs) {
|
|
12
|
+
return true; // Was pre-warmed within the last week
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
return false; // We need to pre-warm
|
|
16
|
+
}
|
|
17
|
+
// Function to check if we need to pre-warm
|
|
18
|
+
export async function preWarmVisitorCookie() {
|
|
19
|
+
// Check if we already pre-warmed recently
|
|
20
|
+
if (isVisitorCookieWarmedUp()) {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
// If we get here, we need to pre-warm
|
|
24
|
+
localStorage.removeItem(LOCALSTORAGE_PREWARM_REDIRECT_KEY);
|
|
25
|
+
try {
|
|
26
|
+
await preWarmRedirectSessionWithIframe();
|
|
27
|
+
// Store the current timestamp
|
|
28
|
+
localStorage.setItem(LOCALSTORAGE_PREWARM_REDIRECT_KEY, Date.now().toString());
|
|
29
|
+
}
|
|
30
|
+
catch (ex) {
|
|
31
|
+
console.error('Error during redirect session pre-warm:', ex);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
async function preWarmRedirectSessionWithIframe() {
|
|
35
|
+
const resultWithCreateCookie = await redirects.createRedirectSession({
|
|
36
|
+
login: {},
|
|
37
|
+
});
|
|
38
|
+
const urlToRedirect = resultWithCreateCookie.redirectSession?.fullUrl;
|
|
39
|
+
if (!urlToRedirect) {
|
|
40
|
+
throw new Error('No redirect URL found');
|
|
41
|
+
}
|
|
42
|
+
const iframe = document.createElement('iframe');
|
|
43
|
+
iframe.style.display = 'none';
|
|
44
|
+
iframe.src = urlToRedirect;
|
|
45
|
+
const promise = new Promise((resolve) => (iframe.onload = resolve));
|
|
46
|
+
document.body.appendChild(iframe);
|
|
47
|
+
return promise;
|
|
48
|
+
}
|
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
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { RefreshToken, Tokens } from './oauth2/types.js';
|
|
2
|
+
import { isVisitorCookieWarmedUp, preWarmVisitorCookie } from './pre-warm-cookie.js';
|
|
2
3
|
export declare function SiteSessionAuth(config: {
|
|
3
4
|
clientId: string;
|
|
4
5
|
publicKey?: string;
|
|
@@ -12,7 +13,10 @@ export declare function SiteSessionAuth(config: {
|
|
|
12
13
|
};
|
|
13
14
|
}>;
|
|
14
15
|
setTokens: (tokens: Tokens) => void;
|
|
16
|
+
loggedIn: () => boolean;
|
|
15
17
|
getTokens: () => Tokens;
|
|
18
|
+
isSessionSynced: typeof isVisitorCookieWarmedUp;
|
|
19
|
+
syncToWixPages: typeof preWarmVisitorCookie;
|
|
16
20
|
};
|
|
17
21
|
export interface TokenResponse {
|
|
18
22
|
access_token: string;
|
|
@@ -5,6 +5,7 @@ const biHeaderGenerator_js_1 = require("../bi/biHeaderGenerator.js");
|
|
|
5
5
|
const common_js_1 = require("../common.js");
|
|
6
6
|
const tokenHelpers_js_1 = require("../tokenHelpers.js");
|
|
7
7
|
const types_js_1 = require("./oauth2/types.js");
|
|
8
|
+
const pre_warm_cookie_js_1 = require("./pre-warm-cookie.js");
|
|
8
9
|
function SiteSessionAuth(config) {
|
|
9
10
|
const _tokens = config.tokens || {
|
|
10
11
|
accessToken: { value: '', expiresAt: 0 },
|
|
@@ -63,12 +64,18 @@ function SiteSessionAuth(config) {
|
|
|
63
64
|
refreshToken,
|
|
64
65
|
};
|
|
65
66
|
};
|
|
67
|
+
const loggedIn = () => {
|
|
68
|
+
return _tokens.refreshToken.role === types_js_1.TokenRole.MEMBER;
|
|
69
|
+
};
|
|
66
70
|
return {
|
|
67
71
|
generateVisitorTokens,
|
|
68
72
|
renewToken,
|
|
69
73
|
getAuthHeaders,
|
|
70
74
|
setTokens,
|
|
75
|
+
loggedIn,
|
|
71
76
|
getTokens: () => _tokens,
|
|
77
|
+
isSessionSynced: pre_warm_cookie_js_1.isVisitorCookieWarmedUp,
|
|
78
|
+
syncToWixPages: pre_warm_cookie_js_1.preWarmVisitorCookie,
|
|
72
79
|
};
|
|
73
80
|
}
|
|
74
81
|
const fetchTokens = async (payload, headers = {}) => {
|
|
@@ -11,6 +11,7 @@ const iframeUtils_js_1 = require("../../iframeUtils.js");
|
|
|
11
11
|
const constants_js_1 = require("./constants.js");
|
|
12
12
|
const biHeaderGenerator_js_1 = require("../../bi/biHeaderGenerator.js");
|
|
13
13
|
const pkce_challenge_js_1 = require("./pkce-challenge.js");
|
|
14
|
+
const pre_warm_cookie_js_1 = require("../pre-warm-cookie.js");
|
|
14
15
|
const moduleWithTokens = { redirects: redirects_1.redirects, authentication: identity_1.authentication, recovery: identity_1.recovery, verification: identity_1.verification };
|
|
15
16
|
function OAuthStrategy(config) {
|
|
16
17
|
const _tokens = config.tokens || {
|
|
@@ -353,6 +354,10 @@ function OAuthStrategy(config) {
|
|
|
353
354
|
sendPasswordResetEmail,
|
|
354
355
|
captchaInvisibleSiteKey: '6LdoPaUfAAAAAJphvHoUoOob7mx0KDlXyXlgrx5v',
|
|
355
356
|
captchaVisibleSiteKey: '6Ld0J8IcAAAAANyrnxzrRlX1xrrdXsOmsepUYosy',
|
|
357
|
+
sessions: {
|
|
358
|
+
isSessionSynced: pre_warm_cookie_js_1.isVisitorCookieWarmedUp,
|
|
359
|
+
syncToWixPages: pre_warm_cookie_js_1.preWarmVisitorCookie,
|
|
360
|
+
},
|
|
356
361
|
};
|
|
357
362
|
}
|
|
358
363
|
const fetchTokens = async (payload, headers = {}) => {
|
|
@@ -79,6 +79,10 @@ export interface IOAuthStrategy extends AuthenticationStrategy {
|
|
|
79
79
|
* @returns Tokens (access and refresh) for the member
|
|
80
80
|
*/
|
|
81
81
|
getMemberTokensForExternalLogin: (memberId: string, apiKey: string) => Promise<Tokens>;
|
|
82
|
+
sessions: {
|
|
83
|
+
isSessionSynced: () => boolean;
|
|
84
|
+
syncToWixPages: () => Promise<void>;
|
|
85
|
+
};
|
|
82
86
|
}
|
|
83
87
|
export declare enum LoginState {
|
|
84
88
|
SUCCESS = "SUCCESS",
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LOCALSTORAGE_PREWARM_REDIRECT_KEY = void 0;
|
|
4
|
+
exports.isVisitorCookieWarmedUp = isVisitorCookieWarmedUp;
|
|
5
|
+
exports.preWarmVisitorCookie = preWarmVisitorCookie;
|
|
6
|
+
const redirects_1 = require("@wix/redirects");
|
|
7
|
+
exports.LOCALSTORAGE_PREWARM_REDIRECT_KEY = 'wixRedirectSessionLastPreWarm';
|
|
8
|
+
function isVisitorCookieWarmedUp() {
|
|
9
|
+
// Check if we already pre-warmed recently
|
|
10
|
+
const lastPreWarmTimeString = localStorage.getItem(exports.LOCALSTORAGE_PREWARM_REDIRECT_KEY);
|
|
11
|
+
const currentTime = Date.now();
|
|
12
|
+
// If we have a stored timestamp, check if it's been less than a week
|
|
13
|
+
if (lastPreWarmTimeString) {
|
|
14
|
+
const lastPreWarmTime = parseInt(lastPreWarmTimeString, 10);
|
|
15
|
+
const oneWeekMs = 7 * 24 * 60 * 60 * 1000; // 7 days in milliseconds
|
|
16
|
+
if (currentTime - lastPreWarmTime < oneWeekMs) {
|
|
17
|
+
return true; // Was pre-warmed within the last week
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return false; // We need to pre-warm
|
|
21
|
+
}
|
|
22
|
+
// Function to check if we need to pre-warm
|
|
23
|
+
async function preWarmVisitorCookie() {
|
|
24
|
+
// Check if we already pre-warmed recently
|
|
25
|
+
if (isVisitorCookieWarmedUp()) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
// If we get here, we need to pre-warm
|
|
29
|
+
localStorage.removeItem(exports.LOCALSTORAGE_PREWARM_REDIRECT_KEY);
|
|
30
|
+
try {
|
|
31
|
+
await preWarmRedirectSessionWithIframe();
|
|
32
|
+
// Store the current timestamp
|
|
33
|
+
localStorage.setItem(exports.LOCALSTORAGE_PREWARM_REDIRECT_KEY, Date.now().toString());
|
|
34
|
+
}
|
|
35
|
+
catch (ex) {
|
|
36
|
+
console.error('Error during redirect session pre-warm:', ex);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
async function preWarmRedirectSessionWithIframe() {
|
|
40
|
+
const resultWithCreateCookie = await redirects_1.redirects.createRedirectSession({
|
|
41
|
+
login: {},
|
|
42
|
+
});
|
|
43
|
+
const urlToRedirect = resultWithCreateCookie.redirectSession?.fullUrl;
|
|
44
|
+
if (!urlToRedirect) {
|
|
45
|
+
throw new Error('No redirect URL found');
|
|
46
|
+
}
|
|
47
|
+
const iframe = document.createElement('iframe');
|
|
48
|
+
iframe.style.display = 'none';
|
|
49
|
+
iframe.src = urlToRedirect;
|
|
50
|
+
const promise = new Promise((resolve) => (iframe.onload = resolve));
|
|
51
|
+
document.body.appendChild(iframe);
|
|
52
|
+
return promise;
|
|
53
|
+
}
|
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.18",
|
|
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.106.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.44",
|
|
80
|
+
"@wix/sdk-types": "^1.13.11",
|
|
81
81
|
"jose": "^5.10.0",
|
|
82
|
-
"type-fest": "^4.
|
|
82
|
+
"type-fest": "^4.40.0"
|
|
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.44",
|
|
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.7.
|
|
102
|
-
"typescript": "^5.8.
|
|
101
|
+
"msw": "^2.7.5",
|
|
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": "e3d0c83ac85d524c76ef64dd83246830dfaf13329dabde89941bfde8"
|
|
130
130
|
}
|