rdme
Version:
ReadMe's official CLI and GitHub Action.
279 lines (278 loc) • 11.5 kB
TypeScript
import type { SpecFileType } from './prepareOas.js';
import type { APIv2PageCommands, CommandClass } from '../index.js';
import type { Hook } from '@oclif/core';
/**
* This contains a few pieces of information about a file so
* we can properly construct a source URL for it.
*/
interface FilePathDetails {
/** The URL or local file path */
filePath: string;
/** This is derived from the `oas-normalize` `type` property. */
fileType: SpecFileType;
}
export interface Mappings {
categories: Record<string, string>;
parentPages: Record<string, string>;
}
/**
* A generic response body type for responses from the ReadMe API.
*/
export interface ResponseBody extends Record<string, any> {
}
export declare const emptyMappings: Mappings;
/**
* Getter function for a string to be used in the user-agent header based on the current
* environment. Used for API v1 requests.
*
*/
export declare function getUserAgent(): string;
/**
* Wrapper for the `fetch` API so we can add rdme-specific headers to all ReadMe API v1 requests.
*
* @deprecated This is for APIv1 only. Use {@link readmeAPIv2Fetch} instead, if possible.
*/
export declare function readmeAPIv1Fetch(
/** The pathname to make the request to. Must have a leading slash. */
pathname: string, options?: RequestInit,
/** optional object containing information about the file being sent.
* We use this to construct a full source URL for the file. */
fileOpts?: FilePathDetails): Promise<Response>;
/**
* Wrapper for the `fetch` API so we can add rdme-specific headers to all ReadMe API v2 requests.
*/
export declare function readmeAPIv2Fetch<T extends Hook.Context = Hook.Context>(
/**
* `this` does not have to be a hook, it can also be a Command class.
* This type ensures that `this` has the `config` and `debug` properties.
*/
this: T,
/** The pathname to make the request to. Must have a leading slash. */
pathname: string, options?: RequestInit,
/** optional object containing information about the file being sent.
* We use this to construct a full source URL for the file. */
fileOpts?: FilePathDetails): Promise<Response>;
/**
* Small handler for handling responses from ReadMe API v1.
*
* If we receive JSON errors, we throw an APIv1Error exception.
*
* If we receive non-JSON responses, we consider them errors and throw them.
*
* @deprecated This is for APIv1 only. Use {@link handleAPIv2Res} instead, if possible.
*/
export declare function handleAPIv1Res(res: Response,
/**
* If omitted (or set to true), the function will return an `APIv1Error`
* if the JSON body contains an `error` property. If set to false,
* the function will return a resolved promise containing the JSON object.
*/
rejectOnJsonError?: boolean): Promise<any>;
/**
* Small handler for handling responses from ReadMe API v2.
*
* If we receive JSON errors, we throw an APIError exception.
*
* If we receive non-JSON responses, we consider them errors and throw them.
*/
export declare function handleAPIv2Res<R extends ResponseBody = ResponseBody, T extends Hook.Context = Hook.Context>(
/**
* `this` does not have to be a hook, it can also be a Command class.
* This type ensures that `this` has the `config` and `debug` properties.
*/
this: T, res: Response): Promise<R>;
/**
* Returns the basic auth header and any other defined headers for use in `fetch` calls against ReadMe API v1.
*
* @deprecated This is for APIv1 only.
*/
export declare function cleanAPIv1Headers(key: string,
/** used for `x-readme-header` */
version?: string, headers?: Headers): import("undici-types").Headers;
/**
* Fetches the category and parent page mappings from the ReadMe API.
* Used for migrating frontmatter in Guides pages to the new API v2 format.
*/
export declare function fetchMappings(this: CommandClass['prototype']): Promise<Mappings>;
/**
* Fetches the schema for the current route from the OpenAPI description for ReadMe API v2.
*/
export declare function fetchSchema(this: APIv2PageCommands): Promise<{
readonly type: "object";
readonly properties: {
readonly allow_crawlers: {
readonly type: "string";
readonly enum: ["enabled", "disabled"];
readonly default: "enabled";
readonly description: "Allow indexing by robots.";
};
readonly category: {
readonly type: "object";
readonly properties: {
readonly uri: {
readonly type: "string";
readonly pattern: "\\/(versions|branches)\\/((v{0,1})(stable|([0-9]+)(?:\\.([0-9]+))?(?:\\.([0-9]+))?(-.*)?)(_(.*))?)\\/categories\\/(guides|reference)\\/((.*))";
readonly description: "A URI to the category resource.";
};
};
readonly additionalProperties: false;
};
readonly content: {
readonly type: "object";
readonly properties: {
readonly body: {
readonly type: "string";
readonly nullable: true;
};
readonly excerpt: {
readonly type: "string";
readonly nullable: true;
};
readonly link: {
readonly type: "object";
readonly properties: {
readonly url: {
readonly type: "string";
readonly nullable: true;
};
readonly new_tab: {
readonly type: "boolean";
readonly nullable: true;
};
};
readonly additionalProperties: false;
readonly description: "Information about where this page should redirect to; only available when `type` is `link`.";
};
readonly next: {
readonly type: "object";
readonly properties: {
readonly description: {
readonly type: "string";
readonly nullable: true;
};
readonly pages: {
readonly type: "array";
readonly items: {
readonly anyOf: [{
readonly type: "object";
readonly properties: {
readonly slug: {
readonly type: "string";
};
readonly title: {
readonly type: "string";
readonly nullable: true;
};
readonly type: {
readonly type: "string";
readonly enum: ["basic", "endpoint"];
};
};
readonly required: ["slug", "title", "type"];
readonly additionalProperties: false;
}, {
readonly type: "object";
readonly properties: {
readonly title: {
readonly type: "string";
readonly nullable: true;
};
readonly type: {
readonly type: "string";
readonly enum: ["link"];
};
readonly url: {
readonly type: "string";
};
};
readonly required: ["title", "type", "url"];
readonly additionalProperties: false;
}];
};
};
};
readonly additionalProperties: false;
};
};
readonly additionalProperties: false;
};
readonly metadata: {
readonly type: "object";
readonly properties: {
readonly description: {
readonly type: "string";
readonly nullable: true;
};
readonly keywords: {
readonly type: "string";
readonly nullable: true;
};
readonly title: {
readonly type: "string";
readonly nullable: true;
};
readonly image: {
readonly type: "object";
readonly properties: {
readonly uri: {
readonly type: "string";
readonly pattern: "\\/images\\/([a-f\\d]{24})";
readonly nullable: true;
};
};
readonly additionalProperties: false;
};
};
readonly additionalProperties: false;
};
readonly parent: {
readonly type: "object";
readonly properties: {
readonly uri: {
readonly type: "string";
readonly pattern: "\\/(versions|branches)\\/((v{0,1})(stable|([0-9]+)(?:\\.([0-9]+))?(?:\\.([0-9]+))?(-.*)?)(_(.*))?)\\/(guides|reference)\\/(([a-z0-9-_ ]|[^\\\\x00-\\\\x7F])+)";
readonly nullable: true;
};
};
readonly additionalProperties: false;
};
readonly privacy: {
readonly type: "object";
readonly properties: {
readonly view: {
readonly type: "string";
readonly enum: ["public", "anyone_with_link"];
readonly default: "anyone_with_link";
};
};
readonly additionalProperties: false;
};
readonly slug: {
readonly allOf: [{
readonly type: "string";
}, {
readonly type: "string";
readonly minLength: 1;
}];
readonly description: "The accessible URL slug for the page.";
};
readonly state: {
readonly type: "string";
readonly enum: ["current", "deprecated"];
readonly default: "current";
};
readonly title: {
readonly type: "string";
};
readonly type: {
readonly type: "string";
readonly enum: ["api_config", "basic", "endpoint", "link", "webhook"];
readonly default: "basic";
};
readonly position: {
readonly type: "number";
};
};
readonly additionalProperties: false;
}>;
export {};