@wix/sdk 1.12.6 → 1.12.7
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/AppStrategy.d.ts +17 -0
- package/build/auth/AppStrategy.js +31 -17
- package/build/graphql.d.ts +6 -5
- package/build/graphql.js +2 -2
- package/cjs/build/auth/AppStrategy.d.ts +17 -0
- package/cjs/build/auth/AppStrategy.js +31 -17
- package/cjs/build/graphql.d.ts +6 -5
- package/cjs/build/graphql.js +2 -2
- package/package.json +2 -2
|
@@ -12,7 +12,23 @@ export type AppStrategy = AuthenticationStrategy<undefined> & {
|
|
|
12
12
|
accessToken: string;
|
|
13
13
|
refreshToken: string;
|
|
14
14
|
}>;
|
|
15
|
+
/**
|
|
16
|
+
* Return a new instance of the AppStrategy which uses an elevated access token
|
|
17
|
+
*/
|
|
15
18
|
elevated(): Promise<AppStrategy>;
|
|
19
|
+
/**
|
|
20
|
+
* Returns infromation about the active token
|
|
21
|
+
*/
|
|
22
|
+
getTokenInfo(): Promise<{
|
|
23
|
+
active: boolean;
|
|
24
|
+
subjectType: 'APP' | 'USER' | 'MEMBER' | 'VISITOR' | 'UNKNOWN';
|
|
25
|
+
subjectId: string;
|
|
26
|
+
exp: number;
|
|
27
|
+
iat: number;
|
|
28
|
+
clientId?: string;
|
|
29
|
+
siteId: string;
|
|
30
|
+
instanceId?: string;
|
|
31
|
+
}>;
|
|
16
32
|
};
|
|
17
33
|
/**
|
|
18
34
|
* Creates an authentication strategy for Wix Apps OAuth installation process.
|
|
@@ -22,6 +38,7 @@ export type AppStrategy = AuthenticationStrategy<undefined> & {
|
|
|
22
38
|
* @param opts.appSecret The Wix App Secret
|
|
23
39
|
* @param opts.refreshToken An optional refresh token previously retrieved from Wix OAuth API
|
|
24
40
|
* @param opts.instanceId An optional instance ID of the Wix App instance the client is making requests on behalf of
|
|
41
|
+
* @param opts.accessToken An optional access token previously retrieved from a client Wix Extension
|
|
25
42
|
* @param opts.publicKey An optional public key for validating webhook requests (supports both PEM and base64 encoded keys)
|
|
26
43
|
* @returns An authentication strategy that can be used with WixClient
|
|
27
44
|
* @example
|
|
@@ -7,6 +7,7 @@ import { parsePublicKeyIfEncoded } from '../helpers.js';
|
|
|
7
7
|
* @param opts.appSecret The Wix App Secret
|
|
8
8
|
* @param opts.refreshToken An optional refresh token previously retrieved from Wix OAuth API
|
|
9
9
|
* @param opts.instanceId An optional instance ID of the Wix App instance the client is making requests on behalf of
|
|
10
|
+
* @param opts.accessToken An optional access token previously retrieved from a client Wix Extension
|
|
10
11
|
* @param opts.publicKey An optional public key for validating webhook requests (supports both PEM and base64 encoded keys)
|
|
11
12
|
* @returns An authentication strategy that can be used with WixClient
|
|
12
13
|
* @example
|
|
@@ -91,10 +92,10 @@ export function AppStrategy(opts) {
|
|
|
91
92
|
};
|
|
92
93
|
},
|
|
93
94
|
async getAuthHeaders() {
|
|
94
|
-
if (!opts.appSecret) {
|
|
95
|
-
throw new Error('App secret is required for retrieveing app-level access tokens. Make sure to pass it to the AppStrategy');
|
|
96
|
-
}
|
|
97
95
|
if ('refreshToken' in opts || refreshToken) {
|
|
96
|
+
if (!opts.appSecret) {
|
|
97
|
+
throw new Error('App secret is required for retrieveing app-level access tokens. Make sure to pass it to the AppStrategy');
|
|
98
|
+
}
|
|
98
99
|
const tokensRes = await fetch('https://www.wixapis.com/oauth/access', {
|
|
99
100
|
method: 'POST',
|
|
100
101
|
headers: {
|
|
@@ -119,6 +120,9 @@ export function AppStrategy(opts) {
|
|
|
119
120
|
};
|
|
120
121
|
}
|
|
121
122
|
else if ('instanceId' in opts) {
|
|
123
|
+
if (!opts.appSecret) {
|
|
124
|
+
throw new Error('App secret is required for retrieveing app-level access tokens. Make sure to pass it to the AppStrategy');
|
|
125
|
+
}
|
|
122
126
|
const tokensRes = await fetch('https://www.wixapis.com/oauth2/token', {
|
|
123
127
|
method: 'POST',
|
|
124
128
|
headers: {
|
|
@@ -154,20 +158,8 @@ export function AppStrategy(opts) {
|
|
|
154
158
|
},
|
|
155
159
|
async elevated() {
|
|
156
160
|
if ('accessToken' in opts && opts.accessToken) {
|
|
157
|
-
const
|
|
158
|
-
|
|
159
|
-
headers: {
|
|
160
|
-
'Content-Type': 'application/json',
|
|
161
|
-
},
|
|
162
|
-
body: JSON.stringify({
|
|
163
|
-
token: opts.accessToken,
|
|
164
|
-
}),
|
|
165
|
-
});
|
|
166
|
-
if (tokenInfoRes.status !== 200) {
|
|
167
|
-
throw new Error(`Failed to get token info. Unexpected status code from Wix OAuth API: ${tokenInfoRes.status}`);
|
|
168
|
-
}
|
|
169
|
-
const tokenInfo = await tokenInfoRes.json();
|
|
170
|
-
if (tokenInfo.app_id !== opts.appId) {
|
|
161
|
+
const tokenInfo = await getTokenInfo(opts.accessToken);
|
|
162
|
+
if (tokenInfo.clientId !== opts.appId) {
|
|
171
163
|
throw new Error(`Invalid access token. The token is not issued for the app with ID "${opts.appId}"`);
|
|
172
164
|
}
|
|
173
165
|
if (!tokenInfo.instanceId) {
|
|
@@ -203,5 +195,27 @@ export function AppStrategy(opts) {
|
|
|
203
195
|
valid: true,
|
|
204
196
|
};
|
|
205
197
|
},
|
|
198
|
+
async getTokenInfo() {
|
|
199
|
+
const tokenToCheck = refreshToken ?? ('accessToken' in opts ? opts.accessToken : undefined);
|
|
200
|
+
if (!tokenToCheck) {
|
|
201
|
+
throw new Error('Missing token to get info for. Either pass the token as an argument or provide it when initializing the AppStrategy');
|
|
202
|
+
}
|
|
203
|
+
return getTokenInfo(tokenToCheck);
|
|
204
|
+
},
|
|
206
205
|
};
|
|
207
206
|
}
|
|
207
|
+
async function getTokenInfo(token) {
|
|
208
|
+
const tokenInfoRes = await fetch('https://www.wixapis.com/oauth2/token-info', {
|
|
209
|
+
method: 'POST',
|
|
210
|
+
headers: {
|
|
211
|
+
'Content-Type': 'application/json',
|
|
212
|
+
},
|
|
213
|
+
body: JSON.stringify({
|
|
214
|
+
token,
|
|
215
|
+
}),
|
|
216
|
+
});
|
|
217
|
+
if (tokenInfoRes.status !== 200) {
|
|
218
|
+
throw new Error(`Failed to get token info. Unexpected status code from Wix OAuth API: ${tokenInfoRes.status}`);
|
|
219
|
+
}
|
|
220
|
+
return (await tokenInfoRes.json());
|
|
221
|
+
}
|
package/build/graphql.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { DocumentNode, GraphQLFormattedError } from 'graphql';
|
|
2
|
+
import { RESTFunctionDescriptor } from '@wix/sdk-types';
|
|
2
3
|
export type TypedQueryInput<Result = {
|
|
3
4
|
[key: string]: any;
|
|
4
5
|
}, Variables = {
|
|
@@ -15,14 +16,14 @@ export type TypedQueryInput<Result = {
|
|
|
15
16
|
*/
|
|
16
17
|
__ensureTypesOfVariablesAndResultMatching?: (variables: Variables) => Result;
|
|
17
18
|
};
|
|
18
|
-
export declare const graphql: ((query: string | String | DocumentNode | TypedQueryInput<
|
|
19
|
+
export declare const graphql: (<Result, Variables>(query: string | String | DocumentNode | TypedQueryInput<Result, Variables>, variables?: Variables | undefined, opts?: {
|
|
19
20
|
apiVersion: string;
|
|
20
21
|
}) => Promise<{
|
|
21
|
-
data:
|
|
22
|
+
data: Result;
|
|
22
23
|
errors?: GraphQLFormattedError[] | undefined;
|
|
23
|
-
}>) & (
|
|
24
|
+
}>) & RESTFunctionDescriptor<(<Result, Variables>(query: string | String | DocumentNode | TypedQueryInput<Result, Variables>, variables?: Variables | undefined, opts?: {
|
|
24
25
|
apiVersion: string;
|
|
25
26
|
}) => Promise<{
|
|
26
|
-
data:
|
|
27
|
+
data: Result;
|
|
27
28
|
errors?: GraphQLFormattedError[] | undefined;
|
|
28
|
-
}>)
|
|
29
|
+
}>)>;
|
package/build/graphql.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createRESTModule } from '@wix/sdk-runtime/rest-modules';
|
|
2
2
|
import { FetchErrorResponse } from './fetch-error.js';
|
|
3
|
-
export const graphql = createRESTModule((restModuleOpts) => {
|
|
3
|
+
export const graphql = createRESTModule(((restModuleOpts) => {
|
|
4
4
|
// eslint-disable-next-line @typescript-eslint/no-shadow
|
|
5
5
|
return async function graphql(query, variables, opts = {
|
|
6
6
|
apiVersion: 'alpha',
|
|
@@ -18,4 +18,4 @@ export const graphql = createRESTModule((restModuleOpts) => {
|
|
|
18
18
|
const { data, errors } = await res.json();
|
|
19
19
|
return { data: data ?? {}, errors };
|
|
20
20
|
};
|
|
21
|
-
});
|
|
21
|
+
}));
|
|
@@ -12,7 +12,23 @@ export type AppStrategy = AuthenticationStrategy<undefined> & {
|
|
|
12
12
|
accessToken: string;
|
|
13
13
|
refreshToken: string;
|
|
14
14
|
}>;
|
|
15
|
+
/**
|
|
16
|
+
* Return a new instance of the AppStrategy which uses an elevated access token
|
|
17
|
+
*/
|
|
15
18
|
elevated(): Promise<AppStrategy>;
|
|
19
|
+
/**
|
|
20
|
+
* Returns infromation about the active token
|
|
21
|
+
*/
|
|
22
|
+
getTokenInfo(): Promise<{
|
|
23
|
+
active: boolean;
|
|
24
|
+
subjectType: 'APP' | 'USER' | 'MEMBER' | 'VISITOR' | 'UNKNOWN';
|
|
25
|
+
subjectId: string;
|
|
26
|
+
exp: number;
|
|
27
|
+
iat: number;
|
|
28
|
+
clientId?: string;
|
|
29
|
+
siteId: string;
|
|
30
|
+
instanceId?: string;
|
|
31
|
+
}>;
|
|
16
32
|
};
|
|
17
33
|
/**
|
|
18
34
|
* Creates an authentication strategy for Wix Apps OAuth installation process.
|
|
@@ -22,6 +38,7 @@ export type AppStrategy = AuthenticationStrategy<undefined> & {
|
|
|
22
38
|
* @param opts.appSecret The Wix App Secret
|
|
23
39
|
* @param opts.refreshToken An optional refresh token previously retrieved from Wix OAuth API
|
|
24
40
|
* @param opts.instanceId An optional instance ID of the Wix App instance the client is making requests on behalf of
|
|
41
|
+
* @param opts.accessToken An optional access token previously retrieved from a client Wix Extension
|
|
25
42
|
* @param opts.publicKey An optional public key for validating webhook requests (supports both PEM and base64 encoded keys)
|
|
26
43
|
* @returns An authentication strategy that can be used with WixClient
|
|
27
44
|
* @example
|
|
@@ -33,6 +33,7 @@ const helpers_js_1 = require("../helpers.js");
|
|
|
33
33
|
* @param opts.appSecret The Wix App Secret
|
|
34
34
|
* @param opts.refreshToken An optional refresh token previously retrieved from Wix OAuth API
|
|
35
35
|
* @param opts.instanceId An optional instance ID of the Wix App instance the client is making requests on behalf of
|
|
36
|
+
* @param opts.accessToken An optional access token previously retrieved from a client Wix Extension
|
|
36
37
|
* @param opts.publicKey An optional public key for validating webhook requests (supports both PEM and base64 encoded keys)
|
|
37
38
|
* @returns An authentication strategy that can be used with WixClient
|
|
38
39
|
* @example
|
|
@@ -117,10 +118,10 @@ function AppStrategy(opts) {
|
|
|
117
118
|
};
|
|
118
119
|
},
|
|
119
120
|
async getAuthHeaders() {
|
|
120
|
-
if (!opts.appSecret) {
|
|
121
|
-
throw new Error('App secret is required for retrieveing app-level access tokens. Make sure to pass it to the AppStrategy');
|
|
122
|
-
}
|
|
123
121
|
if ('refreshToken' in opts || refreshToken) {
|
|
122
|
+
if (!opts.appSecret) {
|
|
123
|
+
throw new Error('App secret is required for retrieveing app-level access tokens. Make sure to pass it to the AppStrategy');
|
|
124
|
+
}
|
|
124
125
|
const tokensRes = await fetch('https://www.wixapis.com/oauth/access', {
|
|
125
126
|
method: 'POST',
|
|
126
127
|
headers: {
|
|
@@ -145,6 +146,9 @@ function AppStrategy(opts) {
|
|
|
145
146
|
};
|
|
146
147
|
}
|
|
147
148
|
else if ('instanceId' in opts) {
|
|
149
|
+
if (!opts.appSecret) {
|
|
150
|
+
throw new Error('App secret is required for retrieveing app-level access tokens. Make sure to pass it to the AppStrategy');
|
|
151
|
+
}
|
|
148
152
|
const tokensRes = await fetch('https://www.wixapis.com/oauth2/token', {
|
|
149
153
|
method: 'POST',
|
|
150
154
|
headers: {
|
|
@@ -180,20 +184,8 @@ function AppStrategy(opts) {
|
|
|
180
184
|
},
|
|
181
185
|
async elevated() {
|
|
182
186
|
if ('accessToken' in opts && opts.accessToken) {
|
|
183
|
-
const
|
|
184
|
-
|
|
185
|
-
headers: {
|
|
186
|
-
'Content-Type': 'application/json',
|
|
187
|
-
},
|
|
188
|
-
body: JSON.stringify({
|
|
189
|
-
token: opts.accessToken,
|
|
190
|
-
}),
|
|
191
|
-
});
|
|
192
|
-
if (tokenInfoRes.status !== 200) {
|
|
193
|
-
throw new Error(`Failed to get token info. Unexpected status code from Wix OAuth API: ${tokenInfoRes.status}`);
|
|
194
|
-
}
|
|
195
|
-
const tokenInfo = await tokenInfoRes.json();
|
|
196
|
-
if (tokenInfo.app_id !== opts.appId) {
|
|
187
|
+
const tokenInfo = await getTokenInfo(opts.accessToken);
|
|
188
|
+
if (tokenInfo.clientId !== opts.appId) {
|
|
197
189
|
throw new Error(`Invalid access token. The token is not issued for the app with ID "${opts.appId}"`);
|
|
198
190
|
}
|
|
199
191
|
if (!tokenInfo.instanceId) {
|
|
@@ -229,6 +221,28 @@ function AppStrategy(opts) {
|
|
|
229
221
|
valid: true,
|
|
230
222
|
};
|
|
231
223
|
},
|
|
224
|
+
async getTokenInfo() {
|
|
225
|
+
const tokenToCheck = refreshToken ?? ('accessToken' in opts ? opts.accessToken : undefined);
|
|
226
|
+
if (!tokenToCheck) {
|
|
227
|
+
throw new Error('Missing token to get info for. Either pass the token as an argument or provide it when initializing the AppStrategy');
|
|
228
|
+
}
|
|
229
|
+
return getTokenInfo(tokenToCheck);
|
|
230
|
+
},
|
|
232
231
|
};
|
|
233
232
|
}
|
|
234
233
|
exports.AppStrategy = AppStrategy;
|
|
234
|
+
async function getTokenInfo(token) {
|
|
235
|
+
const tokenInfoRes = await fetch('https://www.wixapis.com/oauth2/token-info', {
|
|
236
|
+
method: 'POST',
|
|
237
|
+
headers: {
|
|
238
|
+
'Content-Type': 'application/json',
|
|
239
|
+
},
|
|
240
|
+
body: JSON.stringify({
|
|
241
|
+
token,
|
|
242
|
+
}),
|
|
243
|
+
});
|
|
244
|
+
if (tokenInfoRes.status !== 200) {
|
|
245
|
+
throw new Error(`Failed to get token info. Unexpected status code from Wix OAuth API: ${tokenInfoRes.status}`);
|
|
246
|
+
}
|
|
247
|
+
return (await tokenInfoRes.json());
|
|
248
|
+
}
|
package/cjs/build/graphql.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { DocumentNode, GraphQLFormattedError } from 'graphql';
|
|
2
|
+
import { RESTFunctionDescriptor } from '@wix/sdk-types';
|
|
2
3
|
export type TypedQueryInput<Result = {
|
|
3
4
|
[key: string]: any;
|
|
4
5
|
}, Variables = {
|
|
@@ -15,14 +16,14 @@ export type TypedQueryInput<Result = {
|
|
|
15
16
|
*/
|
|
16
17
|
__ensureTypesOfVariablesAndResultMatching?: (variables: Variables) => Result;
|
|
17
18
|
};
|
|
18
|
-
export declare const graphql: ((query: string | String | DocumentNode | TypedQueryInput<
|
|
19
|
+
export declare const graphql: (<Result, Variables>(query: string | String | DocumentNode | TypedQueryInput<Result, Variables>, variables?: Variables | undefined, opts?: {
|
|
19
20
|
apiVersion: string;
|
|
20
21
|
}) => Promise<{
|
|
21
|
-
data:
|
|
22
|
+
data: Result;
|
|
22
23
|
errors?: GraphQLFormattedError[] | undefined;
|
|
23
|
-
}>) & (
|
|
24
|
+
}>) & RESTFunctionDescriptor<(<Result, Variables>(query: string | String | DocumentNode | TypedQueryInput<Result, Variables>, variables?: Variables | undefined, opts?: {
|
|
24
25
|
apiVersion: string;
|
|
25
26
|
}) => Promise<{
|
|
26
|
-
data:
|
|
27
|
+
data: Result;
|
|
27
28
|
errors?: GraphQLFormattedError[] | undefined;
|
|
28
|
-
}>)
|
|
29
|
+
}>)>;
|
package/cjs/build/graphql.js
CHANGED
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.graphql = void 0;
|
|
4
4
|
const rest_modules_1 = require("@wix/sdk-runtime/rest-modules");
|
|
5
5
|
const fetch_error_js_1 = require("./fetch-error.js");
|
|
6
|
-
exports.graphql = (0, rest_modules_1.createRESTModule)((restModuleOpts) => {
|
|
6
|
+
exports.graphql = (0, rest_modules_1.createRESTModule)(((restModuleOpts) => {
|
|
7
7
|
// eslint-disable-next-line @typescript-eslint/no-shadow
|
|
8
8
|
return async function graphql(query, variables, opts = {
|
|
9
9
|
apiVersion: 'alpha',
|
|
@@ -21,4 +21,4 @@ exports.graphql = (0, rest_modules_1.createRESTModule)((restModuleOpts) => {
|
|
|
21
21
|
const { data, errors } = await res.json();
|
|
22
22
|
return { data: data ?? {}, errors };
|
|
23
23
|
};
|
|
24
|
-
});
|
|
24
|
+
}));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wix/sdk",
|
|
3
|
-
"version": "1.12.
|
|
3
|
+
"version": "1.12.7",
|
|
4
4
|
"license": "UNLICENSED",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Ronny Ringel",
|
|
@@ -122,5 +122,5 @@
|
|
|
122
122
|
"wallaby": {
|
|
123
123
|
"autoDetect": true
|
|
124
124
|
},
|
|
125
|
-
"falconPackageHash": "
|
|
125
|
+
"falconPackageHash": "225bbf7de21c21bb40a3f13f6b1b7013827df311a9c450869d201177"
|
|
126
126
|
}
|