@wix/sdk 1.21.2 → 1.21.4
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/oauth2/OAuthStrategy.d.ts +7 -1
- package/build/auth/oauth2/OAuthStrategy.js +10 -3
- package/build/auth/oauth2/types.d.ts +10 -0
- package/build/rest-modules.d.ts +3 -1
- package/build/rest-modules.js +2 -1
- package/build/wixClient.js +3 -1
- package/cjs/build/auth/oauth2/OAuthStrategy.d.ts +7 -1
- package/cjs/build/auth/oauth2/OAuthStrategy.js +10 -3
- package/cjs/build/auth/oauth2/types.d.ts +10 -0
- package/cjs/build/rest-modules.d.ts +3 -1
- package/cjs/build/rest-modules.js +2 -1
- package/cjs/build/wixClient.js +3 -1
- package/package.json +6 -6
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { IOAuthStrategy, Tokens, TokenStorage } from './types.js';
|
|
1
|
+
import { IOAuthStrategy, TokenRequestOptions, Tokens, TokenStorage } from './types.js';
|
|
2
2
|
/**
|
|
3
3
|
* OAuth authentication strategy for Wix SDK.
|
|
4
4
|
* @param config - Configuration object
|
|
@@ -8,6 +8,8 @@ import { IOAuthStrategy, Tokens, TokenStorage } from './types.js';
|
|
|
8
8
|
* @param config.tokenStorage - Custom storage implementation (mutually exclusive with `tokens`).
|
|
9
9
|
* When provided, the strategy delegates all token persistence to this storage.
|
|
10
10
|
* The storage's `getTokens()` must always return `Tokens` (use `EMPTY_TOKENS` as fallback).
|
|
11
|
+
* @param config.tokenRequestOptions - Optional request options (e.g., custom headers) for all token requests.
|
|
12
|
+
* Useful for passing 'client-binding' header in public rendering flows.
|
|
11
13
|
* @returns OAuth strategy instance
|
|
12
14
|
* @example
|
|
13
15
|
* // Default in-memory storage with initial tokens
|
|
@@ -15,10 +17,14 @@ import { IOAuthStrategy, Tokens, TokenStorage } from './types.js';
|
|
|
15
17
|
* @example
|
|
16
18
|
* // Custom storage (e.g., cookies)
|
|
17
19
|
* OAuthStrategy({ clientId: 'xxx', tokenStorage: myCookieStorage })
|
|
20
|
+
* @example
|
|
21
|
+
* // With custom headers for all token requests
|
|
22
|
+
* OAuthStrategy({ clientId: 'xxx', tokenRequestOptions: { headers: { 'client-binding': '...' } } })
|
|
18
23
|
*/
|
|
19
24
|
export declare function OAuthStrategy(config: {
|
|
20
25
|
clientId: string;
|
|
21
26
|
publicKey?: string;
|
|
27
|
+
tokenRequestOptions?: TokenRequestOptions;
|
|
22
28
|
} & ({
|
|
23
29
|
tokens?: Tokens;
|
|
24
30
|
tokenStorage?: never;
|
|
@@ -20,6 +20,8 @@ const moduleWithTokens = { redirects, authentication, recovery, verification };
|
|
|
20
20
|
* @param config.tokenStorage - Custom storage implementation (mutually exclusive with `tokens`).
|
|
21
21
|
* When provided, the strategy delegates all token persistence to this storage.
|
|
22
22
|
* The storage's `getTokens()` must always return `Tokens` (use `EMPTY_TOKENS` as fallback).
|
|
23
|
+
* @param config.tokenRequestOptions - Optional request options (e.g., custom headers) for all token requests.
|
|
24
|
+
* Useful for passing 'client-binding' header in public rendering flows.
|
|
23
25
|
* @returns OAuth strategy instance
|
|
24
26
|
* @example
|
|
25
27
|
* // Default in-memory storage with initial tokens
|
|
@@ -27,8 +29,12 @@ const moduleWithTokens = { redirects, authentication, recovery, verification };
|
|
|
27
29
|
* @example
|
|
28
30
|
* // Custom storage (e.g., cookies)
|
|
29
31
|
* OAuthStrategy({ clientId: 'xxx', tokenStorage: myCookieStorage })
|
|
32
|
+
* @example
|
|
33
|
+
* // With custom headers for all token requests
|
|
34
|
+
* OAuthStrategy({ clientId: 'xxx', tokenRequestOptions: { headers: { 'client-binding': '...' } } })
|
|
30
35
|
*/
|
|
31
36
|
export function OAuthStrategy(config) {
|
|
37
|
+
const _tokenRequestHeaders = config.tokenRequestOptions?.headers ?? {};
|
|
32
38
|
const _tokenStorage = config.tokenStorage ??
|
|
33
39
|
createLocalTokenStorage(config.tokens ?? EMPTY_TOKENS);
|
|
34
40
|
const getTokens = () => _tokenStorage.getTokens();
|
|
@@ -81,7 +87,7 @@ export function OAuthStrategy(config) {
|
|
|
81
87
|
const tokensResponse = await fetchTokens({
|
|
82
88
|
clientId: config.clientId,
|
|
83
89
|
grantType: 'anonymous',
|
|
84
|
-
});
|
|
90
|
+
}, _tokenRequestHeaders);
|
|
85
91
|
return {
|
|
86
92
|
accessToken: createAccessToken(tokensResponse.access_token, tokensResponse.expires_in),
|
|
87
93
|
refreshToken: {
|
|
@@ -94,7 +100,7 @@ export function OAuthStrategy(config) {
|
|
|
94
100
|
const tokensResponse = await fetchTokens({
|
|
95
101
|
refreshToken: refreshToken.value,
|
|
96
102
|
grantType: 'refresh_token',
|
|
97
|
-
});
|
|
103
|
+
}, _tokenRequestHeaders);
|
|
98
104
|
const accessToken = createAccessToken(tokensResponse.access_token, tokensResponse.expires_in);
|
|
99
105
|
return {
|
|
100
106
|
accessToken,
|
|
@@ -175,7 +181,7 @@ export function OAuthStrategy(config) {
|
|
|
175
181
|
...(oauthData.redirectUri && { redirectUri: oauthData.redirectUri }),
|
|
176
182
|
code,
|
|
177
183
|
codeVerifier: oauthData.codeVerifier,
|
|
178
|
-
});
|
|
184
|
+
}, _tokenRequestHeaders);
|
|
179
185
|
return {
|
|
180
186
|
accessToken: createAccessToken(tokensResponse.access_token, tokensResponse.expires_in),
|
|
181
187
|
refreshToken: {
|
|
@@ -350,6 +356,7 @@ export function OAuthStrategy(config) {
|
|
|
350
356
|
member_id: memberId,
|
|
351
357
|
}, {
|
|
352
358
|
Authorization: getTokens().accessToken.value + ',' + apiKey,
|
|
359
|
+
..._tokenRequestHeaders,
|
|
353
360
|
});
|
|
354
361
|
return {
|
|
355
362
|
accessToken: createAccessToken(tokensResponse.access_token, tokensResponse.expires_in),
|
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
import { authentication } from '@wix/identity';
|
|
2
2
|
import { AuthenticationStrategy } from '@wix/sdk-types';
|
|
3
|
+
/**
|
|
4
|
+
* Options for token-related API requests.
|
|
5
|
+
*/
|
|
6
|
+
export interface TokenRequestOptions {
|
|
7
|
+
/**
|
|
8
|
+
* Custom headers to include in the token request.
|
|
9
|
+
* Useful for passing 'client-binding' header in public rendering flows.
|
|
10
|
+
*/
|
|
11
|
+
headers?: Record<string, string>;
|
|
12
|
+
}
|
|
3
13
|
export interface Tokens {
|
|
4
14
|
accessToken: AccessToken;
|
|
5
15
|
refreshToken: RefreshToken;
|
package/build/rest-modules.d.ts
CHANGED
|
@@ -2,4 +2,6 @@ import { BuildRESTFunction, PublicMetadata, RESTFunctionDescriptor, WixClientErr
|
|
|
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, errorHandler: WixClientErrorHandler | undefined, wixAPIFetch: (relativeUrl: string, options: RequestInit) => Promise<Response>, getActiveToken?: () => string | undefined,
|
|
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, getAuthHeaders?: () => Promise<{
|
|
6
|
+
headers: Record<string, string>;
|
|
7
|
+
}>, options?: RESTModuleOptions, hostName?: string | undefined, useCDN?: boolean): BuildRESTFunction<T>;
|
package/build/rest-modules.js
CHANGED
|
@@ -2,7 +2,7 @@ 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
|
+
export function buildRESTDescriptor(origFunc, publicMetadata, boundFetch, errorHandler, wixAPIFetch, getActiveToken, getAuthHeaders, options, hostName, useCDN) {
|
|
6
6
|
return runWithoutContext(() => origFunc({
|
|
7
7
|
request: async (factory) => {
|
|
8
8
|
const requestOptions = factory({
|
|
@@ -82,6 +82,7 @@ export function buildRESTDescriptor(origFunc, publicMetadata, boundFetch, errorH
|
|
|
82
82
|
fetchWithAuth: boundFetch,
|
|
83
83
|
wixAPIFetch,
|
|
84
84
|
getActiveToken,
|
|
85
|
+
getAuthHeaders,
|
|
85
86
|
}));
|
|
86
87
|
}
|
|
87
88
|
class SDKError extends Error {
|
package/build/wixClient.js
CHANGED
|
@@ -137,7 +137,9 @@ export function createClient(config) {
|
|
|
137
137
|
finalUrl.host = apiBaseUrl;
|
|
138
138
|
finalUrl.protocol = 'https';
|
|
139
139
|
return boundFetch(finalUrl.toString(), fetchOptions);
|
|
140
|
-
}, getAuthStrategy().getActiveToken,
|
|
140
|
+
}, getAuthStrategy().getActiveToken,
|
|
141
|
+
// async wrapper normalizes the sync/async union from AuthenticationStrategy.getAuthHeaders
|
|
142
|
+
async () => boundGetAuthHeaders(), { HTTPHost: apiBaseUrl }, config.host?.name, shouldUseCDN);
|
|
141
143
|
}
|
|
142
144
|
else if (isObject(modules)) {
|
|
143
145
|
return Object.fromEntries(Object.entries(modules).map(([key, value]) => {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { IOAuthStrategy, Tokens, TokenStorage } from './types.js';
|
|
1
|
+
import { IOAuthStrategy, TokenRequestOptions, Tokens, TokenStorage } from './types.js';
|
|
2
2
|
/**
|
|
3
3
|
* OAuth authentication strategy for Wix SDK.
|
|
4
4
|
* @param config - Configuration object
|
|
@@ -8,6 +8,8 @@ import { IOAuthStrategy, Tokens, TokenStorage } from './types.js';
|
|
|
8
8
|
* @param config.tokenStorage - Custom storage implementation (mutually exclusive with `tokens`).
|
|
9
9
|
* When provided, the strategy delegates all token persistence to this storage.
|
|
10
10
|
* The storage's `getTokens()` must always return `Tokens` (use `EMPTY_TOKENS` as fallback).
|
|
11
|
+
* @param config.tokenRequestOptions - Optional request options (e.g., custom headers) for all token requests.
|
|
12
|
+
* Useful for passing 'client-binding' header in public rendering flows.
|
|
11
13
|
* @returns OAuth strategy instance
|
|
12
14
|
* @example
|
|
13
15
|
* // Default in-memory storage with initial tokens
|
|
@@ -15,10 +17,14 @@ import { IOAuthStrategy, Tokens, TokenStorage } from './types.js';
|
|
|
15
17
|
* @example
|
|
16
18
|
* // Custom storage (e.g., cookies)
|
|
17
19
|
* OAuthStrategy({ clientId: 'xxx', tokenStorage: myCookieStorage })
|
|
20
|
+
* @example
|
|
21
|
+
* // With custom headers for all token requests
|
|
22
|
+
* OAuthStrategy({ clientId: 'xxx', tokenRequestOptions: { headers: { 'client-binding': '...' } } })
|
|
18
23
|
*/
|
|
19
24
|
export declare function OAuthStrategy(config: {
|
|
20
25
|
clientId: string;
|
|
21
26
|
publicKey?: string;
|
|
27
|
+
tokenRequestOptions?: TokenRequestOptions;
|
|
22
28
|
} & ({
|
|
23
29
|
tokens?: Tokens;
|
|
24
30
|
tokenStorage?: never;
|
|
@@ -23,6 +23,8 @@ const moduleWithTokens = { redirects: redirects_1.redirects, authentication: ide
|
|
|
23
23
|
* @param config.tokenStorage - Custom storage implementation (mutually exclusive with `tokens`).
|
|
24
24
|
* When provided, the strategy delegates all token persistence to this storage.
|
|
25
25
|
* The storage's `getTokens()` must always return `Tokens` (use `EMPTY_TOKENS` as fallback).
|
|
26
|
+
* @param config.tokenRequestOptions - Optional request options (e.g., custom headers) for all token requests.
|
|
27
|
+
* Useful for passing 'client-binding' header in public rendering flows.
|
|
26
28
|
* @returns OAuth strategy instance
|
|
27
29
|
* @example
|
|
28
30
|
* // Default in-memory storage with initial tokens
|
|
@@ -30,8 +32,12 @@ const moduleWithTokens = { redirects: redirects_1.redirects, authentication: ide
|
|
|
30
32
|
* @example
|
|
31
33
|
* // Custom storage (e.g., cookies)
|
|
32
34
|
* OAuthStrategy({ clientId: 'xxx', tokenStorage: myCookieStorage })
|
|
35
|
+
* @example
|
|
36
|
+
* // With custom headers for all token requests
|
|
37
|
+
* OAuthStrategy({ clientId: 'xxx', tokenRequestOptions: { headers: { 'client-binding': '...' } } })
|
|
33
38
|
*/
|
|
34
39
|
function OAuthStrategy(config) {
|
|
40
|
+
const _tokenRequestHeaders = config.tokenRequestOptions?.headers ?? {};
|
|
35
41
|
const _tokenStorage = config.tokenStorage ??
|
|
36
42
|
(0, token_storage_js_1.createLocalTokenStorage)(config.tokens ?? token_storage_js_1.EMPTY_TOKENS);
|
|
37
43
|
const getTokens = () => _tokenStorage.getTokens();
|
|
@@ -84,7 +90,7 @@ function OAuthStrategy(config) {
|
|
|
84
90
|
const tokensResponse = await fetchTokens({
|
|
85
91
|
clientId: config.clientId,
|
|
86
92
|
grantType: 'anonymous',
|
|
87
|
-
});
|
|
93
|
+
}, _tokenRequestHeaders);
|
|
88
94
|
return {
|
|
89
95
|
accessToken: (0, tokenHelpers_js_1.createAccessToken)(tokensResponse.access_token, tokensResponse.expires_in),
|
|
90
96
|
refreshToken: {
|
|
@@ -97,7 +103,7 @@ function OAuthStrategy(config) {
|
|
|
97
103
|
const tokensResponse = await fetchTokens({
|
|
98
104
|
refreshToken: refreshToken.value,
|
|
99
105
|
grantType: 'refresh_token',
|
|
100
|
-
});
|
|
106
|
+
}, _tokenRequestHeaders);
|
|
101
107
|
const accessToken = (0, tokenHelpers_js_1.createAccessToken)(tokensResponse.access_token, tokensResponse.expires_in);
|
|
102
108
|
return {
|
|
103
109
|
accessToken,
|
|
@@ -178,7 +184,7 @@ function OAuthStrategy(config) {
|
|
|
178
184
|
...(oauthData.redirectUri && { redirectUri: oauthData.redirectUri }),
|
|
179
185
|
code,
|
|
180
186
|
codeVerifier: oauthData.codeVerifier,
|
|
181
|
-
});
|
|
187
|
+
}, _tokenRequestHeaders);
|
|
182
188
|
return {
|
|
183
189
|
accessToken: (0, tokenHelpers_js_1.createAccessToken)(tokensResponse.access_token, tokensResponse.expires_in),
|
|
184
190
|
refreshToken: {
|
|
@@ -353,6 +359,7 @@ function OAuthStrategy(config) {
|
|
|
353
359
|
member_id: memberId,
|
|
354
360
|
}, {
|
|
355
361
|
Authorization: getTokens().accessToken.value + ',' + apiKey,
|
|
362
|
+
..._tokenRequestHeaders,
|
|
356
363
|
});
|
|
357
364
|
return {
|
|
358
365
|
accessToken: (0, tokenHelpers_js_1.createAccessToken)(tokensResponse.access_token, tokensResponse.expires_in),
|
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
import { authentication } from '@wix/identity';
|
|
2
2
|
import { AuthenticationStrategy } from '@wix/sdk-types';
|
|
3
|
+
/**
|
|
4
|
+
* Options for token-related API requests.
|
|
5
|
+
*/
|
|
6
|
+
export interface TokenRequestOptions {
|
|
7
|
+
/**
|
|
8
|
+
* Custom headers to include in the token request.
|
|
9
|
+
* Useful for passing 'client-binding' header in public rendering flows.
|
|
10
|
+
*/
|
|
11
|
+
headers?: Record<string, string>;
|
|
12
|
+
}
|
|
3
13
|
export interface Tokens {
|
|
4
14
|
accessToken: AccessToken;
|
|
5
15
|
refreshToken: RefreshToken;
|
|
@@ -2,4 +2,6 @@ import { BuildRESTFunction, PublicMetadata, RESTFunctionDescriptor, WixClientErr
|
|
|
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, errorHandler: WixClientErrorHandler | undefined, wixAPIFetch: (relativeUrl: string, options: RequestInit) => Promise<Response>, getActiveToken?: () => string | undefined,
|
|
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, getAuthHeaders?: () => Promise<{
|
|
6
|
+
headers: Record<string, string>;
|
|
7
|
+
}>, options?: RESTModuleOptions, hostName?: string | undefined, useCDN?: boolean): BuildRESTFunction<T>;
|
|
@@ -5,7 +5,7 @@ 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
|
+
function buildRESTDescriptor(origFunc, publicMetadata, boundFetch, errorHandler, wixAPIFetch, getActiveToken, getAuthHeaders, options, hostName, useCDN) {
|
|
9
9
|
return (0, context_1.runWithoutContext)(() => origFunc({
|
|
10
10
|
request: async (factory) => {
|
|
11
11
|
const requestOptions = factory({
|
|
@@ -85,6 +85,7 @@ function buildRESTDescriptor(origFunc, publicMetadata, boundFetch, errorHandler,
|
|
|
85
85
|
fetchWithAuth: boundFetch,
|
|
86
86
|
wixAPIFetch,
|
|
87
87
|
getActiveToken,
|
|
88
|
+
getAuthHeaders,
|
|
88
89
|
}));
|
|
89
90
|
}
|
|
90
91
|
class SDKError extends Error {
|
package/cjs/build/wixClient.js
CHANGED
|
@@ -141,7 +141,9 @@ function createClient(config) {
|
|
|
141
141
|
finalUrl.host = apiBaseUrl;
|
|
142
142
|
finalUrl.protocol = 'https';
|
|
143
143
|
return boundFetch(finalUrl.toString(), fetchOptions);
|
|
144
|
-
}, getAuthStrategy().getActiveToken,
|
|
144
|
+
}, getAuthStrategy().getActiveToken,
|
|
145
|
+
// async wrapper normalizes the sync/async union from AuthenticationStrategy.getAuthHeaders
|
|
146
|
+
async () => boundGetAuthHeaders(), { HTTPHost: apiBaseUrl }, config.host?.name, shouldUseCDN);
|
|
145
147
|
}
|
|
146
148
|
else if ((0, helpers_js_1.isObject)(modules)) {
|
|
147
149
|
return Object.fromEntries(Object.entries(modules).map(([key, value]) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wix/sdk",
|
|
3
|
-
"version": "1.21.
|
|
3
|
+
"version": "1.21.4",
|
|
4
4
|
"author": {
|
|
5
5
|
"name": "Ronny Ringel",
|
|
6
6
|
"email": "ronnyr@wix.com"
|
|
@@ -10,8 +10,8 @@
|
|
|
10
10
|
"@wix/image-kit": "^1.114.0",
|
|
11
11
|
"@wix/redirects": "^1.0.70",
|
|
12
12
|
"@wix/sdk-context": "0.0.1",
|
|
13
|
-
"@wix/sdk-runtime": "1.0.
|
|
14
|
-
"@wix/sdk-types": "1.17.
|
|
13
|
+
"@wix/sdk-runtime": "1.0.9",
|
|
14
|
+
"@wix/sdk-types": "1.17.5",
|
|
15
15
|
"jose": "^5.10.0",
|
|
16
16
|
"type-fest": "^4.41.0"
|
|
17
17
|
},
|
|
@@ -22,8 +22,8 @@
|
|
|
22
22
|
"@wix/ecom": "^1.0.886",
|
|
23
23
|
"@wix/events": "^1.0.382",
|
|
24
24
|
"@wix/metro": "^1.0.93",
|
|
25
|
-
"@wix/metro-runtime": "
|
|
26
|
-
"@wix/sdk-runtime": "1.0.
|
|
25
|
+
"@wix/metro-runtime": "1.1891.0",
|
|
26
|
+
"@wix/sdk-runtime": "1.0.9",
|
|
27
27
|
"eslint": "^8.57.1",
|
|
28
28
|
"eslint-config-sdk": "1.0.0",
|
|
29
29
|
"graphql": "^16.8.0",
|
|
@@ -126,5 +126,5 @@
|
|
|
126
126
|
"yoshiFlowLibrary": {
|
|
127
127
|
"buildEsmWithBabel": true
|
|
128
128
|
},
|
|
129
|
-
"falconPackageHash": "
|
|
129
|
+
"falconPackageHash": "70bda4c4228f2ead0966aa46c8ffdcb308ad656a0797bb9f1b29002e"
|
|
130
130
|
}
|