Options
All
  • Public
  • Public/Protected
  • All
Menu

JS SDK for building backends with Foxy Hypermedia API. 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.

Hierarchy

Index

Constructors

constructor

  • new API(params: BackendAPIInit): API
  • Parameters

    • params: BackendAPIInit

    Returns API

Properties

Protected _cache

_cache: Storage

Resolver cache implementing Web Storage API.

Protected _console

_console: Consola

Shared Consola instance.

Protected _fetch

_fetch: Window["fetch"]

Custom Fetch API implementation for making authenticated requests.

Protected _path

_path: CurieChain

Path to this resource node as base URL followed by a list of curies.

base

base: URL

Bookmark URL for this API. This is where the tree traversal begins. We also use this URL as a base for relative paths.

cache

cache: Storage

Resolver cache implementing Web Storage API. Every resolved path will be stored here for future use. You can clear this cache by calling clear().

clientId

clientId: string

clientSecret

clientSecret: string

console

console: Consola

Consola instance. If you extend this class and add logging in your code, use this instead of native console.

refreshToken

refreshToken: string

storage

storage: Storage

Credentials storage implementing Web Storage API. Access tokens and other related info will be stored here. Clearing this storage will log you out.

version

version: BackendAPIVersion

Static ACCESS_TOKEN

ACCESS_TOKEN: "access_token" = "access_token"

Static AuthError

AuthError: AuthError = AuthError

Static BASE_URL

BASE_URL: URL = new URL('https://api.foxycart.com/')

Static Node

Node: Node = Node

Static REFRESH_THRESHOLD

REFRESH_THRESHOLD: number = 5 * 60 * 1000

Static ResolutionError

ResolutionError: ResolutionError = ResolutionError

Static Response

Response: Response = Response

Static VERSION

VERSION: BackendAPIVersion = "1"

Static WHATWGHeaders

WHATWGHeaders: { constructor: any; prototype: __type } = Headers

Polyfilled version of the built-in Headers class. If you need to pass an instance of Headers to .fetch(), use this class instead of the built-in one to avoid this issue.

Type declaration

  • constructor: function
    • new __type(init?: HeadersInit): __type
    • Parameters

      • Optional init: HeadersInit

      Returns __type

  • prototype: __type

Static WHATWGRequest

WHATWGRequest: { constructor: any; prototype: __type } = Request

Polyfilled version of the built-in Request class. If you need to pass an instance of Request to .fetch(), use this class instead of the built-in one to avoid this issue.

Type declaration

  • constructor: function
    • new __type(input: RequestInfo, init?: RequestInit): __type
    • Parameters

      • input: RequestInfo
      • Optional init: RequestInit

      Returns __type

  • prototype: __type

Static WHATWGResponse

WHATWGResponse: { constructor: any; prototype: __type; error: any; redirect: any } = Response

Polyfilled version of the built-in Response class. If you need to check the return value of .fetch(), use this class instead of the built-in one to avoid this issue.

Type declaration

  • constructor: function
    • new __type(body?: BodyInit | null, init?: ResponseInit): __type
    • Parameters

      • Optional body: BodyInit | null
      • Optional init: ResponseInit

      Returns __type

  • prototype: __type
  • error: function
    • Returns __type

  • redirect: function
    • redirect(url: string, status?: undefined | number): __type
    • Parameters

      • url: string
      • Optional status: undefined | number

      Returns __type

Static whatwgFetch

whatwgFetch: fetch = fetch

Polyfilled version of the built-in fetch function. If you need to call fetch() with poyfilled request, response or headers, use this function instead of the built-in one to avoid this issue.

Methods

Protected _resolve

  • _resolve(): Promise<URL>
  • Resolves resource URL from a curie chain. The first element in the path must be a URL.

    throws

    Throws {@link APIResolutionError} when once of the resources can't be reached.

    Returns Promise<URL>

    Resolved URL.

delete

  • delete(): Promise<Response<Graph>>
  • Resolves the URL of this node and sends a DELETE request, removing this resource.

    Returns Promise<Response<Graph>>

    Instance of {@link APIResponse} representing this resource.

fetch

  • fetch(...args: Parameters<Window["fetch"]>): ReturnType<Window["fetch"]>
  • Makes a raw and, if possible, authenticated request to the API. This method implements native Fetch API.

    Parameters

    • Rest ...args: Parameters<Window["fetch"]>

      Fetch API arguments (url and request parameters).

    Returns ReturnType<Window["fetch"]>

    Fetch API response.

follow

  • follow<C>(curie: C): Node<Graph["links"][C]>
  • Resource path builder. Calling this method instructs our SDK to find the provided curie in this resource's links and navigate to its location on request.

    Type parameters

    • C: keyof Graph["links"]

    Parameters

    • curie: C

      Curie to follow.

    Returns Node<Graph["links"][C]>

    Instance of {@link APINode} representing the resource at curie location.

get

  • get(): Promise<Response<Graph>>
  • get<Q>(query: Q): Promise<Response<Graph, Q>>
  • Resolves the URL of this node and sends a GET request using provided parameters.

    Returns Promise<Response<Graph>>

    Instance of {@link APIResponse} representing this resource.

  • Resolves the URL of this node and sends a GET request using provided parameters.

    Type parameters

    Parameters

    • query: Q

      Query parameters such as zoom, fields etc.

    Returns Promise<Response<Graph, Q>>

    Instance of {@link APIResponse} representing this resource.

patch

  • patch(body?: Partial<Graph["props"]>): Promise<Response<Graph>>
  • Resolves the URL of this node and sends a PATCH request with provided properties, updating this resource.

    Parameters

    • Optional body: Partial<Graph["props"]>

      Partial resource object.

    Returns Promise<Response<Graph>>

    Instance of {@link APIResponse} representing this resource.

post

  • post(body?: Graph["props"]): Promise<Response<Graph>>
  • Resolves the URL of this node and sends a POST request with provided properties, creating a resource or triggering an action.

    Parameters

    • Optional body: Graph["props"]

      Complete resource object.

    Returns Promise<Response<Graph>>

    Instance of {@link APIResponse} representing this resource.

put

  • put(body?: Graph["props"]): Promise<Response<Graph>>
  • Resolves the URL of this node and sends a PUT request with provided properties, replacing the existing resource.

    Parameters

    • Optional body: Graph["props"]

      Complete resource object.

    Returns Promise<Response<Graph>>

    Instance of {@link APIResponse} representing this resource.

Static getToken

  • getToken(opts: GrantOpts): Promise<Token | null>
  • getToken(opts: GrantOpts, throwOnFailure: true): Promise<Token>
  • Fetches a new access token in exchange for an authorization code or a refresh token. See more in our authentication docs.

    Parameters

    • opts: GrantOpts

      Request options.

    Returns Promise<Token | null>

    Access token with additional info on success, null on failure.

  • Parameters

    • opts: GrantOpts
    • throwOnFailure: true

    Returns Promise<Token>

Object literals

Static v8n

v8n: object

classConstructor

classConstructor: any = v8n().schema({base: v8n().optional(v8n().instanceOf(URL)),cache: v8n().optional(storageV8N),clientId: v8n().string(),clientSecret: v8n().string(),level: v8n().optional(v8n().integer()),refreshToken: v8n().string(),storage: v8n().optional(storageV8N),version: v8n().optional(v8n().passesAnyOf(v8n().exact('1'))),})

getAccessToken

getAccessToken: any = v8n().passesAnyOf(v8n().schema({ code: v8n().string() }), v8n().schema({ refreshToken: v8n().string() })).schema({base: v8n().optional(v8n().instanceOf(URL)),clientId: v8n().string(),clientSecret: v8n().string(),version: v8n().optional(v8n().passesAnyOf(v8n().exact('1'))),})

Generated using TypeDoc