/**
* State object
* @typedef {Object} CHTHttpState
* @private
* @property data - the parsed response body
* @property response - the response from the CHT HTTP server, including headers, statusCode, body, etc
* @property references - an array of all previous data objects used in the Job
**/
/**
* Options provided to the HTTP request
* @typedef {Object} RequestOptions
* @property {object|string} body - body data to append to the request. JSON will be converted to a string (but a content-type header will not be attached to the request).
* @property {object} errors - Map of errorCodes -> error messages, ie, `{ 404: 'Resource not found;' }`. Pass `false` to suppress errors for this code.
* @property {object} form - Pass a JSON object to be serialised into a multipart HTML form (as FormData) in the body.
* @property {object} query - An object of query parameters to be encoded into the URL.
* @property {object} headers - An object of headers to append to the request.
* @property {string} parseAs - Parse the response body as json, text or stream. By default will use the response headers.
* @property {number} timeout - Request timeout in ms. Default: 300 seconds.
*/
/**
* Make a GET request against the base URL.
* @example
Get a list of contacts
* get("/api/v2/export/contacts");
* @example Filter contacts given a name
* get("/api/v2/export/contacts", {
query: {"filters": {
"search": "jim"
}}
});
* @function
* @public
* @param {string} path - Path to resource
* @param {RequestOptions} options - Options to configure the HTTP request
* @param {function} [callback] - Optional callback to handle the response
* @returns {Operation}
* @state {CHTHttpState}
*/
export function get(path: string, options: RequestOptions, callback?: Function): Operation;
/**
* Make a POST request against the base url
* @example Create a new person
* post("/api/v1/people", {
"name": "Hannah",
"phone": "+254712345678",
"type": "contact",
"contact_type": "patient", });
* @function
* @public
* @param {string} path - Path to resource
* @param {object} body - Object which will be attached to the POST body
* @param {RequestOptions} options - Optional request options
* @param {function} [callback] - Optional callback to handle the response
* @returns {Operation}
* @state {CHTHttpState}
*/
export function post(path: string, body: object, options: RequestOptions, callback?: Function): Operation;
/**
* Make a PUT request against the base url
* @example Update settings
* put("/api/v1/settings",{query:{overwrite:true}});
* @function
* @public
* @param {string} path - Path to resource
* @param {RequestOptions} options - Options to configure the HTTP request
* @param {function} [callback] - Optional callback to handle the response
* @returns {Operation}
* @state {CHTHttpState}
*/
export function put(path: string, options: RequestOptions, callback?: Function): Operation;
/**
* Make a general HTTP request to CHT
* @example
* request("POST","/api/v1/people", {
"name": "Hannah",
"phone": "+254712345678",
"type": "contact",
"contact_type": "patient", });
* @function
* @public
* @param {string} method - HTTP method to use
* @param {string} path - Path to resource
* @param {object} data - Object which will be attached to the POST body
* @param {RequestOptions} options - Optional request options
* @param {function} [callback] - Optional callback to handle the response
* @returns {Operation}
* @state {CHTHttpState}
*/
export function request(method: string, path: string, body: any, options?: RequestOptions, callback?: Function): Operation;
/**
* State object
*/
export type CHTHttpState = any;
/**
* Options provided to the HTTP request
*/
export type RequestOptions = {
/**
* - body data to append to the request. JSON will be converted to a string (but a content-type header will not be attached to the request).
*/
body: object | string;
/**
* - Map of errorCodes -> error messages, ie, `{ 404: 'Resource not found;' }`. Pass `false` to suppress errors for this code.
*/
errors: object;
/**
* - Pass a JSON object to be serialised into a multipart HTML form (as FormData) in the body.
*/
form: object;
/**
* - An object of query parameters to be encoded into the URL.
*/
query: object;
/**
* - An object of headers to append to the request.
*/
headers: object;
/**
* - Parse the response body as json, text or stream. By default will use the response headers.
*/
parseAs: string;
/**
* - Request timeout in ms. Default: 300 seconds.
*/
timeout: number;
};
export { dataPath, dataValue, dateFns, cursor, each, field, fields, fn, lastReferenceValue, merge, sourceValue, as } from "@openfn/language-common";