mindee
Version:
Mindee Client Library for Node.js
47 lines (46 loc) • 1.97 kB
TypeScript
import { StringDict } from "../parsing/common";
import { Buffer } from "buffer";
import { CommonResponse } from "../parsing/v2";
/**
* Local response loaded from a file.
* Note: Has to be initialized through init() before use.
*/
export declare class LocalResponse {
private file;
private readonly inputHandle;
protected initialized: boolean;
/**
* Creates an instance of LocalResponse.
*/
constructor(inputFile: Buffer | string);
init(): Promise<void>;
/**
* Returns the dictionary representation of the file.
* @returns A JSON-like object.
*/
asDict(): Promise<StringDict>;
/**
* Returns the HMAC signature of the local response, from the secret key provided.
* @param secretKey - Secret key, either a string or a byte/byte array.
* @returns The HMAC signature of the local response.
*/
getHmacSignature(secretKey: string | Buffer | Uint8Array): string;
/**
* Checks if the HMAC signature of the local response is valid.
* @param secretKey - Secret key, either a string or a byte/byte array.
* @param signature - The signature to be compared with.
* @returns True if the HMAC signature is valid.
*/
isValidHmacSignature(secretKey: string | Buffer | Uint8Array, signature: string): boolean;
/**
* Deserialize the loaded local response into the requested CommonResponse-derived class.
*
* Typically used when dealing with V2 webhook callbacks.
*
* @typeParam ResponseT - A class that extends `CommonResponse`.
* @param responseClass - The constructor of the class into which the payload should be deserialized.
* @returns An instance of `responseClass` populated with the file content.
* @throws MindeeError If the provided class cannot be instantiated.
*/
deserializeResponse<ResponseT extends CommonResponse>(responseClass: new (serverResponse: StringDict) => ResponseT): Promise<ResponseT>;
}