@point-api/js-sdk
Version:
Javascript SDK for Point API
66 lines (65 loc) • 2.58 kB
TypeScript
import AccountApiModule from "./ApiModules/account";
import { AutocompleteSession } from "./ApiModules/autocompleteSession";
import SnippetsApiModule from "./ApiModules/snippets";
import InteractionsApiModule from "./ApiModules/interactions";
export interface ErrorResponse {
error: string;
}
/**
* Point API base interface
*/
export interface PointApi {
/** Email address of Point user account */
emailAddress: string;
/** Point API URL */
readonly apiUrl: string;
/**
* API submodules
*/
readonly account: AccountApiModule;
readonly snippets: SnippetsApiModule;
readonly interactions: InteractionsApiModule;
setCredentials: (emailAddress: string, apiKey: string) => void;
initAutocompleteSessionAsync: (searchType: string) => Promise<AutocompleteSession>;
authFetch: (method: string, url: string, data?: object, headers?: Record<string, string>) => Promise<Response>;
fetch: (method: string, url: string, data?: object, headers?: Record<string, string>) => Promise<Response>;
}
/**
* Point Api Instance
*/
export default class PointApiImpl implements PointApi {
/** Email address of Point user account */
emailAddress: string;
/** Point API URL */
readonly apiUrl: string;
readonly account: AccountApiModule;
readonly snippets: SnippetsApiModule;
readonly interactions: InteractionsApiModule;
/** Point API version */
private readonly ApiVersionAccept;
private readonly authManager;
/**
*
* @param emailAddress Email address of Point user account
* @param apiKey User's API Key
* @param apiUrl Point API URL
*/
constructor(emailAddress: string, apiKey: string, apiUrl?: string);
setCredentials(emailAddress: string, apiKey: string): void;
/**
* Initializes a new autocomplete session. A promise will return if connection is successfully made.
*
* @param searchType how to search for matching suggestions (standard, keyword, hybdrid)
*/
initAutocompleteSessionAsync(searchType: string): Promise<AutocompleteSession>;
/**
* Fetches the URL from the server endpoint.
*
* @param method HTTP method type
* @param url Endpoint URL (e.g. /auth or /account)
* @param data Payload for the body of the request (e.g. in POST)
* @param headers Headers to add to the request
*/
authFetch(method: string, url: string, data?: object, headers?: object): Promise<Response>;
fetch(method: string, url: string, data?: object, headers?: Record<string, string>): Promise<Response>;
}