rentdynamics
Version:
Package to help facilitate communicating with the Rent Dynamics API
118 lines • 5.18 kB
TypeScript
/** Payload is known as the "body" of a Request. The payload must be JSON serializable. */
type Payload = any;
/**
* Client is a convenience class for interacting with the Rent Dynamics services.
*
* Note if this class does not suit your needs, it may be wise to roll your own implementation using
* the {@linkcode ClientHelpers} class.
*/
export declare class Client {
/**
* authToken if defined, authToken is used to make authenticated requests. Note authToken is not
* typically get/set manually, but instead is managed through the login/logout methods.
*/
authToken: string | undefined;
private readonly helpers;
constructor(options: ClientOptions);
/**
* get wraps a request library to work with the Rent Dynamics API.
* @param endpoint the path following the baseUrl.
* @example get('/foo');
*/
get(endpoint: string): Promise<Response>;
/**
* put wraps a request library to work with the Rent Dynamics API.
* @param endpoint the path following the baseUrl.
* @param payload a JSON serializable object.
* @example put('/foo', { bar: 1 });
*/
put(endpoint: string, payload: Payload): Promise<Response>;
/**
* post wraps a request library to work with the Rent Dynamics API.
* @param endpoint the path following the baseUrl.
* @param payload a JSON serializable object.
* @example post('/foo', { bar: 1 });
*/
post(endpoint: string, payload: Payload): Promise<Response>;
/**
* delete wraps a request library to work with the Rent Dynamics API.
* @param endpoint the path following the baseUrl.
* @example delete('/foo/1');
*/
delete(endpoint: string): Promise<Response>;
/**
* login enables an instance of {@linkcode Client} to make authenticated requests to the Rent
* Dynamics API.
*/
login(username: string, password: string): Promise<Response>;
/** logout invalidates the users session generated by {@linkcode login}. */
logout(): Promise<Response>;
}
/** BASE_URL is a collection of base urls for each dev/prod Rent Dynamics service. */
export declare enum BASE_URL {
DEV_RD = "https://api.rentdynamics.dev",
PROD_RD = "https://api.rentdynamics.com",
DEV_RP = "https://api-dev.rentplus.com",
PROD_RP = "https://api.rentplus.com"
}
export type RdEncoder = Pick<TextEncoder, 'encode'>;
export type RdCryptographer = Pick<SubtleCrypto, 'importKey'> & Pick<SubtleCrypto, 'sign'> & Pick<SubtleCrypto, 'digest'>;
/** ClientOptions is consumed and updated by {@linkcode ClientHelpers}. */
export declare class ClientOptions {
/** apiKey if defined apiKey is used to calculate auth headers. */
apiKey: string | undefined;
/** apiSecretKey if defined apiSecretKey is used to calculate auth headers. */
apiSecretKey: string | undefined;
/**
* baseUrl is the base request url. The default is the development rentdynamics api. A custom
* string may be provided beyond the {@linkcode BASE_URL} options.
*/
baseUrl: BASE_URL | string;
/**
* getEncoder is used to encode text. The encoder can be overridden as needed. For example in a
* node environment.
* @example
* const options = new ClientOptions();
* options.getEncoder = async () => new (await import('util')).TextEncoder();
*/
getEncoder: () => Promise<RdEncoder>;
/**
* getCryptographer is used for cryptography. The cryptographer can be overridden as needed. For
* example in a node environment.
* @example
* const options = new ClientOptions();
* options.getCryptographer = async () => (await import('crypto')).subtle;
*/
getCryptographer: () => Promise<RdCryptographer>;
}
/**
* ClientHelpers is a collection of utilities consumed by {@linkcode Client}. ClientHelpers can be
* used to calculate headers in case a consumer wants to build their own API client.
*/
export declare class ClientHelpers {
private options;
constructor(options: ClientOptions);
/**
* baseUrl is the base url used throughout the {@linkcode ClientHelpers} instance. It is initially
* configured through {@linkcode ClientOptions}.
*/
get baseUrl(): string;
/**
* getTimestamp is used to calculate the timestamp header. This method is not likely to be called
* on it's own. Instead, it is typically used to mock the current time.
*/
getTimestamp(): number;
/**
* getHeaders creates headers for the given params. If an auth token is included, this method will
* generate an `Authorization` header.
*/
getHeaders(endpoint: string, payload?: Payload | undefined, authToken?: string | undefined): Promise<Record<string, string>>;
/** formatPayload formats the payload for nonce calculation. */
formatPayload(payload: Payload): Payload;
/** getNonce calculates the nonce for the given params. */
getNonce(timestamp: number, url: string, payloadStr?: string): Promise<string>;
/** encryptPassword encrypts the password for login. */
encryptPassword(password: string): Promise<string>;
}
export {};
//# sourceMappingURL=index.d.ts.map