UNPKG

@esri/arcgis-rest-request

Version:

Common methods and utilities for @esri/arcgis-rest-js packages.

93 lines (91 loc) 3.17 kB
import { IAuthenticationManager } from "./utils/IAuthenticationManager.js"; import { AuthenticationManagerBase } from "./AuthenticationManagerBase.js"; /** * Options for the `ApiKey` constructor. */ export interface IApiKeyOptions { key: string; username?: string; portal?: string; } /** * Used to authenticate methods in ArcGIS REST JS with an API keys. The instance of `ApiKeyManager` can be passed to {@linkcode IRequestOptions.authentication} to authenticate requests. * * ```js * import { ApiKeyManager } from '@esri/arcgis-rest-request'; * const apiKey = new ApiKeyManager.fromKey("..."); * ``` * * In most cases however the API key can be passed directly to the {@linkcode IRequestOptions.authentication}. */ export declare class ApiKeyManager extends AuthenticationManagerBase implements IAuthenticationManager { /** * The current portal the user is authenticated with. */ readonly portal: string; /** * The original API Key used to create this instance. */ private readonly key; /** * The preferred method for creating an instance of `ApiKeyManager`. */ static fromKey(apiKey: string | IApiKeyOptions): ApiKeyManager; constructor(options: IApiKeyOptions); /** * Gets the current access token (the API Key). */ get token(): string; /** * Gets the current access token (the API Key). */ getToken(url: string): Promise<string>; /** * Converts the `ApiKeyManager` instance to a JSON object. This is called when the instance is serialized to JSON with [`JSON.stringify()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify). * * ```js * import { ApiKeyManager } from '@esri/arcgis-rest-request'; * * const apiKey = new ApiKeyManager.fromKey("...") * * const json = JSON.stringify(session); * ``` * * @returns A plain object representation of the instance. */ toJSON(): { type: string; token: string; username: string; portal: string; }; /** * Serializes the ApiKeyManager instance to a JSON string. * * ```js * import { ApiKeyManager } from '@esri/arcgis-rest-request'; * * const apiKey = new ApiKeyManager.fromKey("...") * * localStorage.setItem("apiKey", apiKey.serialize()); * ``` * @returns {string} The serialized JSON string. */ serialize(): string; /** * Deserializes a JSON string previously created with {@linkcode ApiKeyManager.deserialize} to an {@linkcode ApiKeyManager} instance. * * ```js * import { ApiKeyManager } from '@esri/arcgis-rest-request'; * * const apiKey = ApiKeyManager.deserialize(localStorage.getItem("apiKey")); * ``` * @param {string} serialized - The serialized JSON string. * @returns {ApiKeyManager} The deserialized ApiKeyManager instance. */ static deserialize(serialized: string): ApiKeyManager; } /** * @deprecated - Use {@linkcode ApiKeyManager}. * @internal */ export declare function ApiKey(options: IApiKeyOptions): ApiKeyManager;