Socket
Socket
Sign inDemoInstall

@wix/api-client

Package Overview
Dependencies
Maintainers
26
Versions
127
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@wix/api-client - npm Package Compare versions

Comparing version 1.12.6 to 1.12.7

17

build/auth/AppStrategy.d.ts

@@ -15,3 +15,19 @@ import { AuthenticationStrategy } from '@wix/sdk-types';

}>;
/**
* Return a new instance of the AppStrategy which uses an elevated access token
*/
elevated(): Promise<AppStrategy>;
/**
* Returns infromation about the active token
*/
getTokenInfo(): Promise<{
active: boolean;
subjectType: 'APP' | 'USER' | 'MEMBER' | 'VISITOR' | 'UNKNOWN';
subjectId: string;
exp: number;
iat: number;
clientId?: string;
siteId: string;
instanceId?: string;
}>;
};

@@ -26,2 +42,3 @@ /**

* @param opts.instanceId An optional instance ID of the Wix App instance the client is making requests on behalf of
* @param opts.accessToken An optional access token previously retrieved from a client Wix Extension
* @param opts.publicKey An optional public key for validating webhook requests (supports both PEM and base64 encoded keys)

@@ -28,0 +45,0 @@ * @returns An authentication strategy that can be used with WixClient

48

build/auth/AppStrategy.js

@@ -10,2 +10,3 @@ import { parsePublicKeyIfEncoded } from '../helpers.js';

* @param opts.instanceId An optional instance ID of the Wix App instance the client is making requests on behalf of
* @param opts.accessToken An optional access token previously retrieved from a client Wix Extension
* @param opts.publicKey An optional public key for validating webhook requests (supports both PEM and base64 encoded keys)

@@ -95,6 +96,6 @@ * @returns An authentication strategy that can be used with WixClient

async getAuthHeaders() {
if (!opts.appSecret) {
throw new Error('App secret is required for retrieveing app-level access tokens. Make sure to pass it to the AppStrategy');
}
if ('refreshToken' in opts || refreshToken) {
if (!opts.appSecret) {
throw new Error('App secret is required for retrieveing app-level access tokens. Make sure to pass it to the AppStrategy');
}
const tokensRes = await fetch('https://www.wixapis.com/oauth/access', {

@@ -124,2 +125,5 @@ method: 'POST',

else if ('instanceId' in opts) {
if (!opts.appSecret) {
throw new Error('App secret is required for retrieveing app-level access tokens. Make sure to pass it to the AppStrategy');
}
const tokensRes = await fetch('https://www.wixapis.com/oauth2/token', {

@@ -160,16 +164,4 @@ method: 'POST',

if ('accessToken' in opts && opts.accessToken) {
const tokenInfoRes = await fetch('https://www.wixapis.com/oauth2/token-info', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
token: opts.accessToken,
}),
});
if (tokenInfoRes.status !== 200) {
throw new Error(`Failed to get token info. Unexpected status code from Wix OAuth API: ${tokenInfoRes.status}`);
}
const tokenInfo = await tokenInfoRes.json();
if (tokenInfo.app_id !== opts.appId) {
const tokenInfo = await getTokenInfo(opts.accessToken);
if (tokenInfo.clientId !== opts.appId) {
throw new Error(`Invalid access token. The token is not issued for the app with ID "${opts.appId}"`);

@@ -210,3 +202,25 @@ }

},
async getTokenInfo() {
const tokenToCheck = refreshToken ?? ('accessToken' in opts ? opts.accessToken : undefined);
if (!tokenToCheck) {
throw new Error('Missing token to get info for. Either pass the token as an argument or provide it when initializing the AppStrategy');
}
return getTokenInfo(tokenToCheck);
},
};
}
async function getTokenInfo(token) {
const tokenInfoRes = await fetch('https://www.wixapis.com/oauth2/token-info', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
token,
}),
});
if (tokenInfoRes.status !== 200) {
throw new Error(`Failed to get token info. Unexpected status code from Wix OAuth API: ${tokenInfoRes.status}`);
}
return (await tokenInfoRes.json());
}
import { DocumentNode, GraphQLFormattedError } from 'graphql';
import { RESTFunctionDescriptor } from '@wix/sdk-types';
export type TypedQueryInput<Result = {

@@ -18,12 +19,12 @@ [key: string]: any;

};
export declare const graphql: ((query: string | String | DocumentNode | TypedQueryInput<unknown, any>, variables?: any, opts?: {
export declare const graphql: (<Result, Variables>(query: string | String | DocumentNode | TypedQueryInput<Result, Variables>, variables?: Variables | undefined, opts?: {
apiVersion: string;
}) => Promise<{
data: unknown;
data: Result;
errors?: GraphQLFormattedError[] | undefined;
}>) & ((restModuleOpts: import("@wix/sdk-types").HttpClient) => (query: string | String | DocumentNode | TypedQueryInput<unknown, any>, variables?: any, opts?: {
}>) & RESTFunctionDescriptor<(<Result, Variables>(query: string | String | DocumentNode | TypedQueryInput<Result, Variables>, variables?: Variables | undefined, opts?: {
apiVersion: string;
}) => Promise<{
data: unknown;
data: Result;
errors?: GraphQLFormattedError[] | undefined;
}>);
}>)>;
import { createRESTModule } from '@wix/sdk-runtime/rest-modules';
import { FetchErrorResponse } from './fetch-error.js';
export const graphql = createRESTModule((restModuleOpts) => {
export const graphql = createRESTModule(((restModuleOpts) => {
// eslint-disable-next-line @typescript-eslint/no-shadow

@@ -21,2 +21,2 @@ return async function graphql(query, variables, opts = {

};
});
}));
{
"name": "@wix/api-client",
"version": "1.12.6",
"version": "1.12.7",
"license": "UNLICENSED",

@@ -38,3 +38,3 @@ "main": "build/index.js",

"@wix/metro-runtime": "^1.1677.0",
"@wix/sdk": "1.12.6"
"@wix/sdk": "1.12.7"
},

@@ -52,3 +52,3 @@ "wix": {

},
"falconPackageHash": "85ec107dab046af2696f0de172e27a80d79aff3379c67823850efc5b"
"falconPackageHash": "e64e5aa9c365584c5d82d435e243cddf86e6fc4e798fd7f226e74c0f"
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc