haystack-nclient
Version:
Project Haystack Network Client
171 lines (170 loc) • 5.06 kB
TypeScript
import { HList, HRef } from 'haystack-core';
/**
* @module HTTP utility methods.
*/
/**
* Returns the URL for an general API.
*
* @param params.origin The origin.
* @param params.path The path prefix to use.
* @returns A URL.
*/
export declare const getServiceUrl: getServiceUrlCallback;
/**
* The functional interface for getting the origin API url.
*/
export interface getServiceUrlCallback {
({ origin, path }: {
origin: string;
path: string;
}): string;
}
/**
* The functional interface for getting the op url.
*/
export interface getOpUrlCallback {
({ origin, pathPrefix, project, op, }: {
origin: string;
pathPrefix: string;
project: string;
op: string;
}): string;
}
/**
* Returns the URL for an op.
*
* @param params.origin The origin.
* @param params.pathPrefix The path prefix to use.
* @param params.project The project name.
* @param params.op The op name.
* @returns A URL.
*/
export declare const getOpUrl: getOpUrlCallback;
/**
* The functional interface for getting the op url.
*/
export interface getHaystackServiceUrlCallback {
({ origin, pathPrefix, project, path, }: {
origin: string;
pathPrefix: string;
project: string;
path: string;
}): string;
}
/**
* Returns the URL for a Haystack REST service.
*
* @param origin The origin for the service.
* @param pathPrefix The path prefix to use.
* @param project The project for the service. May be empty and if so shouldn't be included.
* @param path The service path.
* @returns A URL.
*/
export declare const getHaystackServiceUrl: getHaystackServiceUrlCallback;
/**
* The functional interface for getting the op url.
*/
export interface getHostServiceUrlCallback {
({ origin, pathPrefix, path, }: {
origin: string;
pathPrefix: string;
path: string;
}): string;
}
/**
* Returns the URL for a Host REST service.
*
* @param origin The origin for the service.
* @param pathPrefix The path prefix to use.
* @param path The service path.
* @returns A URL.
*/
export declare const getHostServiceUrl: getHostServiceUrlCallback;
/**
* Encode the object as a URI query segment.
*
* https://en.wikipedia.org/wiki/Uniform_Resource_Identifier
*
* @param obj The object to encode.
* @returns A query or empty string if there's noting to encode.
*/
export declare function encodeQuery(obj: Record<string, string | HRef | number | string[] | HRef[] | HList<HRef> | boolean | undefined>): string;
/**
* The CSRF key that needs to be added to all outgoing writable requests.
*/
export declare const SKYARC_ATTEST_KEY = "skyarc-attest-key";
/**
* The FIN authorization key that contains a requested CSRF key.
*/
export declare const FIN_AUTH_KEY = "fin-stack-auth";
/**
* The FIN authorization path to request a CSRF token.
*/
export declare const FIN_AUTH_PATH = "/finStackAuth";
/**
* The HTTP accept header.
*/
export declare const ACCEPT_HEADER = "accept";
/**
* The HTTP content type header.
*/
export declare const CONTENT_TYPE_HEADER = "content-type";
/**
* The zinc mime type.
*/
export declare const ZINC_MIME_TYPE = "text/zinc";
/**
* Return the origin for the specified resource.
*
* If the path is relative then an empty string is returned.
*
* @param resource The resouce to get the host from.
* @returns The host.
*/
export declare function getOrigin(resource: string): string;
/**
* An object literal for http headers.
*/
export interface HeadersObj {
[prop: string]: string;
}
/**
* Return true if the headers object has the specified header.
*
* @param headers The headers object.
* @param headerName The header name to look for.
* @returns True if the header is present.
*/
export declare function hasHeader(headers: HeadersInit | undefined, headerName: string): boolean;
/**
* Return the header value from the headers object. Return undefined if the
* value can't be found.
*
* @param headers The headers object.
* @param headerName The headers name to look for.
* @returns The header value as a string or undefined if it can't be found.
*/
export declare function getHeader(headers: HeadersInit | undefined, headerName: string): string | undefined;
/**
* Add the header and its value to an options object.
*
* @param options The options object that has a headers object.
* @param headerName The header name.
* @param headerValue The header value.
*/
export declare function addHeader(options: RequestInit, headerName: string, headerValue: string): void;
/**
* Remove the header value from the headers object by name.
*
* @param headers The headers object.
* @param headerName The headers name to look for.
* @returns The headers object
*/
export declare function removeHeader(headers: HeadersInit | undefined, headerName: string): HeadersInit | undefined;
/**
* Adds a starting slash and removes any ending slash.
*
* @param path The path to update.
* @returns The updated path.
*/
export declare function addStartSlashRemoveEndSlash(path: string): string;