@wix/sdk 1.15.17 → 1.15.19
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 +6 -0
- package/build/auth/pre-warm-cookie.d.ts +5 -0
- package/build/auth/pre-warm-cookie.js +48 -0
- 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 +6 -0
- package/cjs/build/auth/pre-warm-cookie.d.ts +5 -0
- package/cjs/build/auth/pre-warm-cookie.js +53 -0
- package/package.json +9 -9
|
@@ -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,12 @@ 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: (opts: {
|
|
85
|
+
force?: boolean;
|
|
86
|
+
}) => Promise<void>;
|
|
87
|
+
};
|
|
82
88
|
}
|
|
83
89
|
export declare enum LoginState {
|
|
84
90
|
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(opts) {
|
|
19
|
+
// Check if we already pre-warmed recently
|
|
20
|
+
if (!opts.force && 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
|
+
}
|
|
@@ -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,12 @@ 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: (opts: {
|
|
85
|
+
force?: boolean;
|
|
86
|
+
}) => Promise<void>;
|
|
87
|
+
};
|
|
82
88
|
}
|
|
83
89
|
export declare enum LoginState {
|
|
84
90
|
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(opts) {
|
|
24
|
+
// Check if we already pre-warmed recently
|
|
25
|
+
if (!opts.force && 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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wix/sdk",
|
|
3
|
-
"version": "1.15.
|
|
3
|
+
"version": "1.15.19",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Ronny Ringel",
|
|
@@ -73,32 +73,32 @@
|
|
|
73
73
|
},
|
|
74
74
|
"dependencies": {
|
|
75
75
|
"@wix/identity": "^1.0.104",
|
|
76
|
-
"@wix/image-kit": "^1.
|
|
76
|
+
"@wix/image-kit": "^1.107.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.46",
|
|
80
|
+
"@wix/sdk-types": "^1.13.14",
|
|
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.31",
|
|
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.46",
|
|
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.
|
|
101
|
+
"msw": "^2.7.5",
|
|
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": "592894e577597079e92bb18739c16bf2a548927578b05cef9baa1885"
|
|
130
130
|
}
|