UNPKG

akismet

Version:
221 lines (220 loc) 7.12 kB
/** * Defines the settings for the Akismet client. */ interface AkismetOptions { /** * The front page or home URL of the instance making the request. For a blog * or wiki this would be the front page. * * _Note:_ Must be a full URI, including `http://`. */ blog?: string; /** * Akismet API key */ apiKey: string; /** * Akismet API URL, defaults to `rest.akismet.com` */ host?: string; /** * Akismet API endpoint, defaults to `apiKey.rest.akismet.com` */ endPoint?: string; /** * Akismet API server port, defaults to `80` */ port?: number; /** * The user agent string passed to Akismet API, defaults to * `Generic Node.js/1.0.0 | Akismet/3.1.7` */ userAgent?: string; /** * The character set of comment texts, defaults to `utf-8` */ charSet?: string; } /** * Defines the set of parameters passed to the Akismet API. */ interface AkismetParameters { /** * The front page or home URL of the instance making the request. For a blog * or wiki this would be the front page. * * _Note:_ Must be a full URI, including `http://`. */ blog?: string; /** * IP address of the comment submitter. */ user_ip: string; /** * User agent string of the web browser submitting the comment - typically the * `HTTP_USER_AGENT` cgi variable. Not to be confused with the user agent of * your Akismet library. */ user_agent?: string; /** * The content of the `HTTP_REFERER` header should be sent here. * (note spelling of `referrer`). */ referrer?: string; /** * The full permanent URL of the entry the comment was submitted to. */ permalink?: string; /** * A string that describes the type of content being sent. Examples: * - `comment`: A blog comment. * - `forum-post`: A top-level forum post. * - `reply`: A reply to a top-level forum post. * - `blog-post`: A blog post. * - `contact-form`: A contact form or feedback form submission. * - `signup`: A new user account. * - `message`: A message sent between just a few users. * * You may send a value not listed above if none of them accurately describe * your content. This is further explained here: * http://blog.akismet.com/2012/06/19/pro-tip-tell-us-your-comment_type/ */ comment_type?: string; /** * Name submitted with the comment. */ comment_author?: string; /** * Email address submitted with the comment. */ comment_author_email?: string; /** * URL submitted with comment. */ comment_author_url?: string; /** * The content that was submitted. */ comment_content?: string; /** * The UTC timestamp of the creation of the comment, in ISO 8601 format. * May be omitted if the comment is sent to the API at the time it is created. */ comment_date_gmt?: string; /** * The UTC timestamp of the publication time for the post, page or thread on * which the comment was posted. */ comment_post_modified_gmt?: string; /** * Indicates the language(s) in use on the blog or site, in ISO 639-1 format, * comma-separated. A site with articles in English and French might use `en, fr_ca`. */ blog_lang?: string; /** * The character encoding for the form values included in `comment_*` parameters, * such as `UTF-8` or `ISO-8859-1`. */ blog_charset?: string; /** * The user role of the user who submitted the comment. This is an optional parameter. * If you set it to `administrator`, Akismet will always return `false`. */ user_role?: string; /** * This is an optional parameter. You can pass `1` when submitting test queries to Akismet. */ is_test?: number; /** * **Other server environmental variables:** * In PHP, there is an array of environmental variables called `$_SERVER` that * contains information about the Web server itself as well as a key/value for * every HTTP header sent with the request. This data is highly useful to Akismet. * How the submitted content interacts with the server can be very telling, * so please include as much of it as possible. */ [key: string]: any; } /** * Defines the callback for the `verifyKey` function. * * @param err - error message returned from the server. * @param isValid - `true` if the API key is valid; otherwise `false`. */ declare type VerifyKeyCallback = (err: string | null, isValid: boolean) => void; /** * Defines the callback for the `checkComment` function. * * @param err - error message returned from the server. * @param isSpam - `true` if the content is spam; otherwise `false`. */ declare type CheckCommentCallback = (err: string | null, isSpam: boolean) => void; /** * Defines the callback for the `submitSpam` and `submitHam` functions. * * @param err - error message returned from the server. */ declare type SubmitCallback = (err: string | null) => void; /** * Represents the Akismet API client. */ export declare class AkismetClient { private _blog; private _apiKey; private _host; private _endPoint; private _port; private _userAgent; private _charSet; /** * Initialize the Akismet client. * * @param options - client settings */ constructor(options: AkismetOptions); /** * Verifies the API key. * * @param callback - callback function */ verifyKey(callback: VerifyKeyCallback): void; /** * Checks if a comment is spam. * * @param options - options to send to the Akismet API * @param callback - callback function */ checkComment(options: AkismetParameters, callback: CheckCommentCallback): void; /** * Marks a comment as spam and reports to the Akismet API. * * @param options - options to send to the Akismet API * @param callback - callback function */ submitSpam(options: AkismetParameters, callback: SubmitCallback): void; /** * Marks a comment as NOT spam and reports to the Akismet API. * * @param options - options to send to the Akismet API * @param callback - callback function */ submitHam(options: AkismetParameters, callback: SubmitCallback): void; /** * Posts a request to the Akismet API server. */ private _postRequest; /** * Historic alias of `checkComment`. * * @param options - options to send to the Akismet API * @param callback - callback function */ private checkSpam; } /** * Creates and returns a new Akismet client. * * @param options - client settings */ export declare function client(options: AkismetOptions): AkismetClient; export {};