UNPKG

@foxy.io/sdk

Version:

Universal SDK for a full server-side and a limited in-browser access to Foxy hAPI.

62 lines (61 loc) 2.66 kB
import * as Core from '../core/index.js'; import type { Graph } from './Graph'; import type { LogLevel } from 'consola'; /** In order to facilitate any major, unforeseen breaking changes in the future, we require each request to include API version. We hope to rarely (never?) change it but by requiring it up front, we can ensure what you get today is what you’ll get tomorrow. */ declare type BackendAPIVersion = '1'; /** Contructor parameters of the {@link BackendAPI} class. */ declare type BackendAPIInit = { refreshToken: string; clientSecret: string; clientId: string; level?: LogLevel; storage?: Storage; version?: BackendAPIVersion; base?: URL; cache?: Storage; }; declare type GrantOpts = ({ code: string; } | { refreshToken: string; }) & { clientSecret: string; clientId: string; version?: BackendAPIVersion; base?: URL; }; declare type Token = { refresh_token: string; access_token: string; expires_in: number; token_type: string; scope: string; }; /** JS SDK for building backends with [Foxy Hypermedia API](https://api.foxy.io/docs). Hypermedia API is designed to give you complete control over all aspects of your Foxy accounts, whether working with a single store or automating the provisioning of thousands. Anything you can do within the Foxy administration, you can also do through the API. This means that you can embed Foxy into any application (CMS, LMS, CRM, etc.) and expose as much or as little of Foxy's functionality as desired. */ export declare class API extends Core.API<Graph> { static readonly REFRESH_THRESHOLD: number; static readonly ACCESS_TOKEN = "access_token"; static readonly BASE_URL: URL; static readonly VERSION: BackendAPIVersion; static readonly v8n: { classConstructor: any; getAccessToken: any; }; /** * Fetches a new access token in exchange for an authorization code * or a refresh token. See more in our [authentication docs](https://api.foxy.io/docs/authentication). * * @param opts Request options. * @param throwOnFailure If true, this method will throw an error instead of returning null on failure to obtain a token. * @returns Access token with additional info on success, null on failure. */ static getToken(opts: GrantOpts): Promise<Token | null>; static getToken(opts: GrantOpts, throwOnFailure: true): Promise<Token>; readonly refreshToken: string; readonly clientSecret: string; readonly clientId: string; readonly version: BackendAPIVersion; constructor(params: BackendAPIInit); private __fetch; } export {};