@decisions/api-helpers
Version:
JavaScript toolkit for REST, etc. for external UIs using Decisions as a back-end.
58 lines (57 loc) • 2.89 kB
TypeScript
export declare function getReportUrl(reportId: string): string;
export declare function getFlowIdUrl(flowId: string): string;
export declare function getRuleIdUrl(ruleId: string): string;
/**
* Creates Flow url for a flow reference by "Alias". Assumes this was done to create
* "pretty" paths and that the provided url is not
* @param flowAlias create a flow URL based on alias
*/
export declare function getFlowAliasUrl(flowAlias: string): string;
export declare function getServiceEndPointUrl(path: string): string;
/**
* Get a formatted URL, including current session ID
* @param type "ReportId" | "FlowId" | "FlowAlias" depending on what's being fetched
* @param id id, path, or alias, depending on the integration type.
* @return url with sessionId query parameter appended.
*/
export declare function getUrlWithSessionId(type: "ReportId" | "FlowId" | "FlowAlias" | "RuleId", id: string, output?: "Json" | "RawJson"): string;
declare type ResolvingCallback<T> = (json: T) => void;
declare type Reject = (reason?: any) => void;
/**
* Handle edge cases where odd behavior from the Decisions (5.x) back-end and the
* odd behaviors of the TypeScript fetch API collide. Namely, 500s and 403s are still
* getting passed to the `.then` block of the fetch promise, and the response from
* the decisions back-end for those error codes is a non-JSON string.
*
* @param resolvingCallback callback to parse data out and resolve the promise as
* the use-case demands
* @param reject promise reject callback to reject due to API errors.
*/
export declare function getResponseJson<T>(response: Response, resolvingCallback: ResolvingCallback<T>, reject: Reject): void;
/**
* Convenience function to have 'null' query params for empty strings.
*
* Some end-points don't handle empty-string query params.
* Most UIs don't handle 'null' input values.
* @param param to encode
* @returns encoded part or null.
*/
export declare function encodeWithNullForEmpty(param: string): string;
/**
* Convenience GET fetch wrapper, which covers some idiosyncracies in the Decisions API, related to return types,
* and common result wrappers.
* @param url to fetch
* @param propertyName to pull data from, if provided
* @returns promise resolving expected type
*/
export declare function getWrappedFetch<T>(url: string, propertyName?: string): Promise<T>;
/**
* Convenience POST fetch wrapper, which covers some idiosyncracies in the Decisions API, related to return types,
* and common result wrappers.
* @param url to fetch
* @param propertyName to pull data from, if provided
* @returns promise resolving expected type
*/
export declare function getWrappedPostFetch<T>(url: string, body: object, propertyName?: string): Promise<T>;
export declare function makePostFetchInit(body: object): RequestInit;
export {};