@wix/sdk 1.21.1 → 1.21.3
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/event-handlers-modules.d.ts +2 -1
- package/build/event-handlers-modules.js +5 -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/event-handlers-modules.d.ts +2 -1
- package/cjs/build/event-handlers-modules.js +5 -1
- package/package.json +5 -5
|
@@ -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;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AuthenticationStrategy, EventDefinition, EventHandler, EventIdentity } from '@wix/sdk-types';
|
|
1
|
+
import { AuthenticationStrategy, EventDefinition, EventHandler, EventIdentity, AccountInfo } from '@wix/sdk-types';
|
|
2
2
|
import { Emitter } from './nanoevents.js';
|
|
3
3
|
export declare const isEventHandlerModule: (val: any) => val is EventDefinition<unknown, string>;
|
|
4
4
|
export declare function buildEventDefinition<T extends EventDefinition<any, string>>(eventDefinition: T, registerHandler: (eventDefinition: T, handler: EventHandler<T>) => void): (handler: EventHandler<T>) => void;
|
|
@@ -11,6 +11,7 @@ type ResolvePossibleEvents<T extends EventDefinition<any>[]> = {
|
|
|
11
11
|
export type ProcessedEvent<T extends EventDefinition<any>[] = []> = {
|
|
12
12
|
instanceId: string;
|
|
13
13
|
identity?: EventIdentity;
|
|
14
|
+
accountInfo?: AccountInfo;
|
|
14
15
|
} & (T['length'] extends 0 ? {
|
|
15
16
|
eventType: string;
|
|
16
17
|
payload: unknown;
|
|
@@ -82,7 +82,7 @@ export function eventHandlersModules(getAuthStrategy) {
|
|
|
82
82
|
async process(jwt, opts = {
|
|
83
83
|
expectedEvents: [],
|
|
84
84
|
}) {
|
|
85
|
-
const { eventType, identity, instanceId, payload } = await this.parseJWT(jwt);
|
|
85
|
+
const { eventType, identity, instanceId, payload, accountInfo } = await this.parseJWT(jwt);
|
|
86
86
|
const allExpectedEvents = [
|
|
87
87
|
...opts.expectedEvents,
|
|
88
88
|
...Array.from(eventHandlers.keys()).map((type) => ({ type })),
|
|
@@ -97,12 +97,14 @@ export function eventHandlersModules(getAuthStrategy) {
|
|
|
97
97
|
await Promise.all(handlers.map(({ eventDefinition, handler }) => runHandler(eventDefinition, handler, payload, {
|
|
98
98
|
instanceId,
|
|
99
99
|
identity,
|
|
100
|
+
accountInfo,
|
|
100
101
|
})));
|
|
101
102
|
return {
|
|
102
103
|
instanceId,
|
|
103
104
|
eventType,
|
|
104
105
|
payload,
|
|
105
106
|
identity,
|
|
107
|
+
accountInfo,
|
|
106
108
|
};
|
|
107
109
|
},
|
|
108
110
|
async processRequest(request, opts) {
|
|
@@ -123,6 +125,7 @@ export function eventHandlersModules(getAuthStrategy) {
|
|
|
123
125
|
}
|
|
124
126
|
const parsedDecoded = JSON.parse(decoded.data);
|
|
125
127
|
const eventType = parsedDecoded.eventType;
|
|
128
|
+
const accountInfo = parsedDecoded.accountInfo;
|
|
126
129
|
const instanceId = parsedDecoded.instanceId;
|
|
127
130
|
const identity = parsedDecoded.identity
|
|
128
131
|
? JSON.parse(parsedDecoded.identity)
|
|
@@ -133,6 +136,7 @@ export function eventHandlersModules(getAuthStrategy) {
|
|
|
133
136
|
eventType,
|
|
134
137
|
payload,
|
|
135
138
|
identity,
|
|
139
|
+
accountInfo,
|
|
136
140
|
};
|
|
137
141
|
},
|
|
138
142
|
async parseRequest(request) {
|
|
@@ -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;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AuthenticationStrategy, EventDefinition, EventHandler, EventIdentity } from '@wix/sdk-types';
|
|
1
|
+
import { AuthenticationStrategy, EventDefinition, EventHandler, EventIdentity, AccountInfo } from '@wix/sdk-types';
|
|
2
2
|
import { Emitter } from './nanoevents.js';
|
|
3
3
|
export declare const isEventHandlerModule: (val: any) => val is EventDefinition<unknown, string>;
|
|
4
4
|
export declare function buildEventDefinition<T extends EventDefinition<any, string>>(eventDefinition: T, registerHandler: (eventDefinition: T, handler: EventHandler<T>) => void): (handler: EventHandler<T>) => void;
|
|
@@ -11,6 +11,7 @@ type ResolvePossibleEvents<T extends EventDefinition<any>[]> = {
|
|
|
11
11
|
export type ProcessedEvent<T extends EventDefinition<any>[] = []> = {
|
|
12
12
|
instanceId: string;
|
|
13
13
|
identity?: EventIdentity;
|
|
14
|
+
accountInfo?: AccountInfo;
|
|
14
15
|
} & (T['length'] extends 0 ? {
|
|
15
16
|
eventType: string;
|
|
16
17
|
payload: unknown;
|
|
@@ -88,7 +88,7 @@ function eventHandlersModules(getAuthStrategy) {
|
|
|
88
88
|
async process(jwt, opts = {
|
|
89
89
|
expectedEvents: [],
|
|
90
90
|
}) {
|
|
91
|
-
const { eventType, identity, instanceId, payload } = await this.parseJWT(jwt);
|
|
91
|
+
const { eventType, identity, instanceId, payload, accountInfo } = await this.parseJWT(jwt);
|
|
92
92
|
const allExpectedEvents = [
|
|
93
93
|
...opts.expectedEvents,
|
|
94
94
|
...Array.from(eventHandlers.keys()).map((type) => ({ type })),
|
|
@@ -103,12 +103,14 @@ function eventHandlersModules(getAuthStrategy) {
|
|
|
103
103
|
await Promise.all(handlers.map(({ eventDefinition, handler }) => runHandler(eventDefinition, handler, payload, {
|
|
104
104
|
instanceId,
|
|
105
105
|
identity,
|
|
106
|
+
accountInfo,
|
|
106
107
|
})));
|
|
107
108
|
return {
|
|
108
109
|
instanceId,
|
|
109
110
|
eventType,
|
|
110
111
|
payload,
|
|
111
112
|
identity,
|
|
113
|
+
accountInfo,
|
|
112
114
|
};
|
|
113
115
|
},
|
|
114
116
|
async processRequest(request, opts) {
|
|
@@ -129,6 +131,7 @@ function eventHandlersModules(getAuthStrategy) {
|
|
|
129
131
|
}
|
|
130
132
|
const parsedDecoded = JSON.parse(decoded.data);
|
|
131
133
|
const eventType = parsedDecoded.eventType;
|
|
134
|
+
const accountInfo = parsedDecoded.accountInfo;
|
|
132
135
|
const instanceId = parsedDecoded.instanceId;
|
|
133
136
|
const identity = parsedDecoded.identity
|
|
134
137
|
? JSON.parse(parsedDecoded.identity)
|
|
@@ -139,6 +142,7 @@ function eventHandlersModules(getAuthStrategy) {
|
|
|
139
142
|
eventType,
|
|
140
143
|
payload,
|
|
141
144
|
identity,
|
|
145
|
+
accountInfo,
|
|
142
146
|
};
|
|
143
147
|
},
|
|
144
148
|
async parseRequest(request) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wix/sdk",
|
|
3
|
-
"version": "1.21.
|
|
3
|
+
"version": "1.21.3",
|
|
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.7",
|
|
14
|
+
"@wix/sdk-types": "1.17.3",
|
|
15
15
|
"jose": "^5.10.0",
|
|
16
16
|
"type-fest": "^4.41.0"
|
|
17
17
|
},
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"@wix/events": "^1.0.382",
|
|
24
24
|
"@wix/metro": "^1.0.93",
|
|
25
25
|
"@wix/metro-runtime": "^1.1891.0",
|
|
26
|
-
"@wix/sdk-runtime": "1.0.
|
|
26
|
+
"@wix/sdk-runtime": "1.0.7",
|
|
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": "85c30d8bf85fa6b345737b139ab7ebaf274735a08a7bcac2a23b5ebf"
|
|
130
130
|
}
|