Options
All
  • Public
  • Public/Protected
  • All
Menu

Customer API for adding custom functionality to websites and web apps with our Customer Portal.

IMPORTANT: this client is not compatible with the beta version of Customer API. If you're still on beta, please consider updating your code to the latest stable version. You can use @foxy.io/sdk prior to 1.0.0-beta.15 or a custom API client until you transition.

Hierarchy

Index

Constructors

constructor

  • new API(params: ConstructorParameters<typeof API>[0]): API
  • Parameters

    • params: ConstructorParameters<typeof API>[0]

    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().

console

console: Consola

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

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.

Static AuthError

AuthError: AuthError = AuthError

Static Node

Node: Node = Node

Static ResolutionError

ResolutionError: ResolutionError = ResolutionError

Static Response

Response: Response = Response

Static SESSION

SESSION: "session" = "session"

Storage key for session data.

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 v8n

v8n: { classConstructor: any } & { credentials: any; email: any } = Object.assign({}, Core.API.v8n, {credentials: v8n().schema({email: v8n().string(),newPassword: v8n().optional(v8n().string()),password: v8n().string(),}),email: v8n().string(),})

Validators for the method arguments in this class (internal).

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.

sendPasswordResetEmail

  • sendPasswordResetEmail(params: { email: string }): Promise<void>
  • Initiates password reset for a customer with the given email. If such customer exists, they will receive an email from Foxy with further instructions.

    Parameters

    • params: { email: string }

      Password reset parameters.

      • email: string

        Customer email.

    Returns Promise<void>

signIn

  • signIn(credentials: Credentials): Promise<void>
  • Creates a Customer Portal session for a customer with the given credentials. Incorrect email and password will trigger Core.API.AuthError with code UNAUTHORIZED.

    Parameters

    • credentials: Credentials

      Customer email and password (one-time code).

    Returns Promise<void>

signOut

  • signOut(): Promise<void>
  • Destroys current session and clears local session data.

    Returns Promise<void>

Generated using TypeDoc