@cedx/akismet
Advanced tools
Comparing version 16.2.1 to 17.0.0
/** | ||
* Represents the author of a comment. | ||
*/ | ||
export declare class Author { | ||
/** | ||
* The author's mail address. If you set it to `"akismet-guaranteed-spam@example.com"`, Akismet will always return `true`. | ||
*/ | ||
email: string; | ||
/** | ||
* The author's IP address. | ||
*/ | ||
ipAddress: string; | ||
/** | ||
* The author's name. If you set it to `"viagra-test-123"`, Akismet will always return `true`. | ||
*/ | ||
name: string; | ||
/** | ||
* The author's role. If you set it to `"administrator"`, Akismet will always return `false`. | ||
*/ | ||
role: string; | ||
/** | ||
* The URL of the author's website. | ||
*/ | ||
url: URL | null; | ||
/** | ||
* The author's user agent, that is the string identifying the Web browser used to submit comments. | ||
*/ | ||
userAgent: string; | ||
/** | ||
* Creates a new author. | ||
* @param options An object providing values to initialize this instance. | ||
*/ | ||
constructor(options?: Partial<AuthorOptions>); | ||
/** | ||
* Creates a new author from the specified JSON object. | ||
* @param json A JSON object representing an author. | ||
* @returns The instance corresponding to the specified JSON object. | ||
*/ | ||
static fromJson(json: Record<string, any>): Author; | ||
/** | ||
* Returns a JSON representation of this object. | ||
* @returns The JSON representation of this object. | ||
*/ | ||
toJSON(): Record<string, any>; | ||
export class Author { | ||
/** | ||
* The author's mail address. If you set it to `"akismet-guaranteed-spam@example.com"`, Akismet will always return `true`. | ||
*/ | ||
email: string; | ||
/** | ||
* The author's IP address. | ||
*/ | ||
ipAddress: string; | ||
/** | ||
* The author's name. If you set it to `"viagra-test-123"`, Akismet will always return `true`. | ||
*/ | ||
name: string; | ||
/** | ||
* The author's role. If you set it to `"administrator"`, Akismet will always return `false`. | ||
*/ | ||
role: string; | ||
/** | ||
* The URL of the author's website. | ||
*/ | ||
url: URL|null; | ||
/** | ||
* The author's user agent, that is the string identifying the Web browser used to submit comments. | ||
*/ | ||
userAgent: string; | ||
/** | ||
* Creates a new author. | ||
* @param options An object providing values to initialize this instance. | ||
*/ | ||
constructor(options?: AuthorOptions); | ||
/** | ||
* Creates a new author from the specified JSON object. | ||
* @param json A JSON object representing an author. | ||
* @returns The instance corresponding to the specified JSON object. | ||
*/ | ||
static fromJson(json: Record<string, any>): Author; | ||
/** | ||
* Returns a JSON representation of this object. | ||
* @returns The JSON representation of this object. | ||
*/ | ||
toJSON(): Record<string, any>; | ||
} | ||
/** | ||
* Defines the options of an {@link Author} instance. | ||
*/ | ||
export interface AuthorOptions { | ||
/** | ||
* The author's mail address. If you set it to `"akismet-guaranteed-spam@example.com"`, Akismet will always return `true`. | ||
*/ | ||
email: string; | ||
/** | ||
* The author's IP address. | ||
*/ | ||
ipAddress: string; | ||
/** | ||
* The author's name. If you set it to `"viagra-test-123"`, Akismet will always return `true`. | ||
*/ | ||
name: string; | ||
/** | ||
* The author's role. If you set it to `"administrator"`, Akismet will always return `false`. | ||
*/ | ||
role: string; | ||
/** | ||
* The URL of the author's website. | ||
*/ | ||
url: URL | string; | ||
/** | ||
* The author's user agent, that is the string identifying the Web browser used to submit comments. | ||
*/ | ||
userAgent: string; | ||
} | ||
export type AuthorOptions = Partial<{ | ||
/** | ||
* The author's mail address. If you set it to `"akismet-guaranteed-spam@example.com"`, Akismet will always return `true`. | ||
*/ | ||
email: string; | ||
/** | ||
* The author's IP address. | ||
*/ | ||
ipAddress: string; | ||
/** | ||
* The author's name. If you set it to `"viagra-test-123"`, Akismet will always return `true`. | ||
*/ | ||
name: string; | ||
/** | ||
* The author's role. If you set it to `"administrator"`, Akismet will always return `false`. | ||
*/ | ||
role: string; | ||
/** | ||
* The URL of the author's website. | ||
*/ | ||
url: URL|string; | ||
/** | ||
* The author's user agent, that is the string identifying the Web browser used to submit comments. | ||
*/ | ||
userAgent: string; | ||
}>; | ||
/** | ||
* Specifies the role of an author. | ||
*/ | ||
export declare const AuthorRole: Readonly<{ | ||
/** | ||
* The author is an administrator. | ||
*/ | ||
administrator: "administrator"; | ||
export const AuthorRole: Readonly<{ | ||
/** | ||
* The author is an administrator. | ||
*/ | ||
administrator: "administrator" | ||
}>; | ||
/** | ||
@@ -88,2 +107,1 @@ * Specifies the role of an author. | ||
export type AuthorRole = typeof AuthorRole[keyof typeof AuthorRole]; | ||
//# sourceMappingURL=author.d.ts.map |
@@ -1,83 +0,62 @@ | ||
/** | ||
* Represents the author of a comment. | ||
*/ | ||
export class Author { | ||
/** | ||
* The author's mail address. If you set it to `"akismet-guaranteed-spam@example.com"`, Akismet will always return `true`. | ||
*/ | ||
email; | ||
/** | ||
* The author's IP address. | ||
*/ | ||
ipAddress; | ||
/** | ||
* The author's name. If you set it to `"viagra-test-123"`, Akismet will always return `true`. | ||
*/ | ||
name; | ||
/** | ||
* The author's role. If you set it to `"administrator"`, Akismet will always return `false`. | ||
*/ | ||
role; | ||
/** | ||
* The URL of the author's website. | ||
*/ | ||
url; | ||
/** | ||
* The author's user agent, that is the string identifying the Web browser used to submit comments. | ||
*/ | ||
userAgent; | ||
/** | ||
* Creates a new author. | ||
* @param options An object providing values to initialize this instance. | ||
*/ | ||
constructor(options = {}) { | ||
this.email = options.email ?? ""; | ||
this.ipAddress = options.ipAddress ?? ""; | ||
this.name = options.name ?? ""; | ||
this.role = options.role ?? ""; | ||
this.url = options.url ? new URL(options.url) : null; | ||
this.userAgent = options.userAgent ?? ""; | ||
// Represents the author of a comment. | ||
export var Author = class Author { | ||
// Creates a new author. | ||
constructor(options = {}) { | ||
var ref, ref1, ref2, ref3, ref4; | ||
// The author's mail address. If you set it to `"akismet-guaranteed-spam@example.com"`, Akismet will always return `true`. | ||
this.email = (ref = options.email) != null ? ref : ""; | ||
// The author's IP address. | ||
this.ipAddress = (ref1 = options.ipAddress) != null ? ref1 : ""; | ||
// The author's name. If you set it to `"viagra-test-123"`, Akismet will always return `true`. | ||
this.name = (ref2 = options.name) != null ? ref2 : ""; | ||
// The author's role. If you set it to `"administrator"`, Akismet will always return `false`. | ||
this.role = (ref3 = options.role) != null ? ref3 : ""; | ||
// The URL of the author's website. | ||
this.url = options.url ? new URL(options.url) : null; | ||
// The author's user agent, that is the string identifying the Web browser used to submit comments. | ||
this.userAgent = (ref4 = options.userAgent) != null ? ref4 : ""; | ||
} | ||
// Creates a new author from the specified JSON object. | ||
static fromJson(json) { | ||
return new this({ | ||
email: typeof json.comment_author_email === "string" ? json.comment_author_email : "", | ||
ipAddress: typeof json.user_ip === "string" ? json.user_ip : "", | ||
name: typeof json.comment_author === "string" ? json.comment_author : "", | ||
role: typeof json.user_role === "string" ? json.user_role : "", | ||
url: typeof json.comment_author_url === "string" ? json.comment_author_url : "", | ||
userAgent: typeof json.user_agent === "string" ? json.user_agent : "" | ||
}); | ||
} | ||
// Returns a JSON representation of this object. | ||
toJSON() { | ||
var map; | ||
map = { | ||
user_ip: this.ipAddress | ||
}; | ||
if (this.email) { | ||
map.comment_author_email = this.email; | ||
} | ||
/** | ||
* Creates a new author from the specified JSON object. | ||
* @param json A JSON object representing an author. | ||
* @returns The instance corresponding to the specified JSON object. | ||
*/ | ||
static fromJson(json) { | ||
return new this({ | ||
email: typeof json.comment_author_email == "string" ? json.comment_author_email : "", | ||
ipAddress: typeof json.user_ip == "string" ? json.user_ip : "", | ||
name: typeof json.comment_author == "string" ? json.comment_author : "", | ||
role: typeof json.user_role == "string" ? json.user_role : "", | ||
url: typeof json.comment_author_url == "string" ? json.comment_author_url : "", | ||
userAgent: typeof json.user_agent == "string" ? json.user_agent : "" | ||
}); | ||
if (this.name) { | ||
map.comment_author = this.name; | ||
} | ||
/** | ||
* Returns a JSON representation of this object. | ||
* @returns The JSON representation of this object. | ||
*/ | ||
toJSON() { | ||
const map = { user_ip: this.ipAddress }; | ||
if (this.email) | ||
map.comment_author_email = this.email; | ||
if (this.name) | ||
map.comment_author = this.name; | ||
if (this.role) | ||
map.user_role = this.role; | ||
if (this.url) | ||
map.comment_author_url = this.url.href; | ||
if (this.userAgent) | ||
map.user_agent = this.userAgent; | ||
return map; | ||
if (this.role) { | ||
map.user_role = this.role; | ||
} | ||
} | ||
/** | ||
* Specifies the role of an author. | ||
*/ | ||
export const AuthorRole = Object.freeze({ | ||
/** | ||
* The author is an administrator. | ||
*/ | ||
administrator: "administrator" | ||
if (this.url) { | ||
map.comment_author_url = this.url.href; | ||
} | ||
if (this.userAgent) { | ||
map.user_agent = this.userAgent; | ||
} | ||
return map; | ||
} | ||
}; | ||
// Specifies the role of an author. | ||
export var AuthorRole = Object.freeze({ | ||
// The author is an administrator. | ||
administrator: "administrator" | ||
}); |
/** | ||
* Represents the front page or home URL transmitted when making requests. | ||
*/ | ||
export declare class Blog { | ||
/** | ||
* The character encoding for the values included in comments. | ||
*/ | ||
charset: string; | ||
/** | ||
* The languages in use on the blog or site, in ISO 639-1 format. | ||
*/ | ||
languages: Array<string>; | ||
/** | ||
* The blog or site URL. | ||
*/ | ||
url: URL | null; | ||
/** | ||
* Creates a new blog. | ||
* @param options An object providing values to initialize this instance. | ||
*/ | ||
constructor(options?: Partial<BlogOptions>); | ||
/** | ||
* Creates a new blog from the specified JSON object. | ||
* @param json A JSON object representing a blog. | ||
* @returns The instance corresponding to the specified JSON object. | ||
*/ | ||
static fromJson(json: Record<string, any>): Blog; | ||
/** | ||
* Returns a JSON representation of this object. | ||
* @returns The JSON representation of this object. | ||
*/ | ||
toJSON(): Record<string, any>; | ||
export class Blog { | ||
/** | ||
* The character encoding for the values included in comments. | ||
*/ | ||
charset: string; | ||
/** | ||
* The languages in use on the blog or site, in ISO 639-1 format. | ||
*/ | ||
languages: Set<string>; | ||
/** | ||
* The blog or site URL. | ||
*/ | ||
url: URL|null; | ||
/** | ||
* Creates a new blog. | ||
* @param options An object providing values to initialize this instance. | ||
*/ | ||
constructor(options?: BlogOptions); | ||
/** | ||
* Creates a new blog from the specified JSON object. | ||
* @param json A JSON object representing a blog. | ||
* @returns The instance corresponding to the specified JSON object. | ||
*/ | ||
static fromJson(json: Record<string, any>): Blog; | ||
/** | ||
* Returns a JSON representation of this object. | ||
* @returns The JSON representation of this object. | ||
*/ | ||
toJSON(): Record<string, any>; | ||
} | ||
/** | ||
* Defines the options of a {@link Blog} instance. | ||
*/ | ||
export interface BlogOptions { | ||
/** | ||
* The character encoding for the values included in comments. | ||
*/ | ||
charset: string; | ||
/** | ||
* The languages in use on the blog or site, in ISO 639-1 format. | ||
*/ | ||
languages: Array<string>; | ||
/** | ||
* The blog or site URL. | ||
*/ | ||
url: URL | string; | ||
} | ||
//# sourceMappingURL=blog.d.ts.map | ||
export type BlogOptions = Partial<{ | ||
/** | ||
* The character encoding for the values included in comments. | ||
*/ | ||
charset: string; | ||
/** | ||
* The languages in use on the blog or site, in ISO 639-1 format. | ||
*/ | ||
languages: Array<string>; | ||
/** | ||
* The blog or site URL. | ||
*/ | ||
url: URL|string; | ||
}>; |
@@ -1,50 +0,40 @@ | ||
/** | ||
* Represents the front page or home URL transmitted when making requests. | ||
*/ | ||
export class Blog { | ||
/** | ||
* The character encoding for the values included in comments. | ||
*/ | ||
charset; | ||
/** | ||
* The languages in use on the blog or site, in ISO 639-1 format. | ||
*/ | ||
languages; | ||
/** | ||
* The blog or site URL. | ||
*/ | ||
url; | ||
/** | ||
* Creates a new blog. | ||
* @param options An object providing values to initialize this instance. | ||
*/ | ||
constructor(options = {}) { | ||
this.charset = options.charset ?? ""; | ||
this.languages = options.languages ?? []; | ||
this.url = options.url ? new URL(options.url) : null; | ||
// Represents the front page or home URL transmitted when making requests. | ||
export var Blog = class Blog { | ||
// Creates a new blog. | ||
constructor(options = {}) { | ||
var ref, ref1; | ||
// The character encoding for the values included in comments. | ||
this.charset = (ref = options.charset) != null ? ref : ""; | ||
// The languages in use on the blog or site, in ISO 639-1 format. | ||
this.languages = new Set((ref1 = options.languages) != null ? ref1 : []); | ||
// The blog or site URL. | ||
this.url = options.url ? new URL(options.url) : null; | ||
} | ||
// Creates a new blog from the specified JSON object. | ||
static fromJson(json) { | ||
return new this({ | ||
charset: typeof json.blog_charset === "string" ? json.blog_charset : "", | ||
languages: typeof json.blog_lang === "string" ? json.blog_lang.split(",").map(function(language) { | ||
return language.trim(); | ||
}) : [], | ||
url: typeof json.blog === "string" ? json.blog : "" | ||
}); | ||
} | ||
// Returns a JSON representation of this object. | ||
toJSON() { | ||
var map, ref, ref1; | ||
map = { | ||
blog: (ref = (ref1 = this.url) != null ? ref1.href : void 0) != null ? ref : "" | ||
}; | ||
if (this.charset) { | ||
map.blog_charset = this.charset; | ||
} | ||
/** | ||
* Creates a new blog from the specified JSON object. | ||
* @param json A JSON object representing a blog. | ||
* @returns The instance corresponding to the specified JSON object. | ||
*/ | ||
static fromJson(json) { | ||
return new this({ | ||
charset: typeof json.blog_charset == "string" ? json.blog_charset : "", | ||
languages: typeof json.blog_lang == "string" ? json.blog_lang.split(",").map(language => language.trim()) : [], | ||
url: typeof json.blog == "string" ? json.blog : "" | ||
}); | ||
if (this.languages.size) { | ||
map.blog_lang = Array.from(this.languages).join(","); | ||
} | ||
/** | ||
* Returns a JSON representation of this object. | ||
* @returns The JSON representation of this object. | ||
*/ | ||
toJSON() { | ||
const map = { blog: this.url?.href ?? "" }; | ||
if (this.charset) | ||
map.blog_charset = this.charset; | ||
if (this.languages.length) | ||
map.blog_lang = this.languages.join(); | ||
return map; | ||
} | ||
} | ||
return map; | ||
} | ||
}; |
/** | ||
* Specifies the result of a comment check. | ||
*/ | ||
export declare const CheckResult: Readonly<{ | ||
/** | ||
* The comment is not a spam (i.e. a ham). | ||
*/ | ||
ham: 0; | ||
/** | ||
* The comment is a spam. | ||
*/ | ||
spam: 1; | ||
/** | ||
* The comment is a pervasive spam (i.e. it can be safely discarded). | ||
*/ | ||
pervasiveSpam: 2; | ||
export const CheckResult: Readonly<{ | ||
/** | ||
* The comment is not a spam (i.e. a ham). | ||
*/ | ||
ham: 0, | ||
/** | ||
* The comment is a spam. | ||
*/ | ||
spam: 1, | ||
/** | ||
* The comment is a pervasive spam (i.e. it can be safely discarded). | ||
*/ | ||
pervasiveSpam: 2 | ||
}>; | ||
/** | ||
@@ -22,2 +26,1 @@ * Specifies the result of a comment check. | ||
export type CheckResult = typeof CheckResult[keyof typeof CheckResult]; | ||
//# sourceMappingURL=check_result.d.ts.map |
@@ -1,17 +0,9 @@ | ||
/** | ||
* Specifies the result of a comment check. | ||
*/ | ||
export const CheckResult = Object.freeze({ | ||
/** | ||
* The comment is not a spam (i.e. a ham). | ||
*/ | ||
ham: 0, | ||
/** | ||
* The comment is a spam. | ||
*/ | ||
spam: 1, | ||
/** | ||
* The comment is a pervasive spam (i.e. it can be safely discarded). | ||
*/ | ||
pervasiveSpam: 2 | ||
// Specifies the result of a comment check. | ||
export var CheckResult = Object.freeze({ | ||
// The comment is not a spam (i.e. a ham). | ||
ham: 0, | ||
// The comment is a spam. | ||
spam: 1, | ||
// The comment is a pervasive spam (i.e. it can be safely discarded). | ||
pervasiveSpam: 2 | ||
}); |
@@ -1,77 +0,90 @@ | ||
import type { Blog } from "./blog.js"; | ||
import { CheckResult } from "./check_result.js"; | ||
import type { Comment } from "./comment.js"; | ||
import {Blog} from "./blog.js"; | ||
import {CheckResult} from "./check_result.js"; | ||
import {Comment} from "./comment.js"; | ||
/** | ||
* Submits comments to the [Akismet](https://akismet.com) service. | ||
*/ | ||
export declare class Client { | ||
#private; | ||
/** | ||
* The Akismet API key. | ||
*/ | ||
readonly apiKey: string; | ||
/** | ||
* The base URL of the remote API endpoint. | ||
*/ | ||
readonly baseUrl: URL; | ||
/** | ||
* The front page or home URL of the instance making requests. | ||
*/ | ||
readonly blog: Blog; | ||
/** | ||
* Value indicating whether the client operates in test mode. | ||
*/ | ||
readonly isTest: boolean; | ||
/** | ||
* The user agent string to use when making requests. | ||
*/ | ||
readonly userAgent: string; | ||
/** | ||
* Creates a new client. | ||
* @param apiKey The Akismet API key. | ||
* @param blog The front page or home URL of the instance making requests. | ||
* @param options An object providing values to initialize this instance. | ||
*/ | ||
constructor(apiKey: string, blog: Blog, options?: Partial<ClientOptions>); | ||
/** | ||
* Checks the specified comment against the service database, and returns a value indicating whether it is spam. | ||
* @param comment The comment to be checked. | ||
* @returns A value indicating whether the specified comment is spam. | ||
*/ | ||
checkComment(comment: Comment): Promise<CheckResult>; | ||
/** | ||
* Submits the specified comment that was incorrectly marked as spam but should not have been. | ||
* @param comment The comment to be submitted. | ||
* @returns Resolves once the comment has been submitted. | ||
*/ | ||
submitHam(comment: Comment): Promise<void>; | ||
/** | ||
* Submits the specified comment that was not marked as spam but should have been. | ||
* @param comment The comment to be submitted. | ||
* @returns Resolves once the comment has been submitted. | ||
*/ | ||
submitSpam(comment: Comment): Promise<void>; | ||
/** | ||
* Checks the API key against the service database, and returns a value indicating whether it is valid. | ||
* @returns `true` if the specified API key is valid, otherwise `false`. | ||
*/ | ||
verifyKey(): Promise<boolean>; | ||
export class Client { | ||
/** | ||
* The Akismet API key. | ||
*/ | ||
apiKey: string; | ||
/** | ||
* The base URL of the remote API endpoint. | ||
*/ | ||
baseUrl: URL; | ||
/** | ||
* The front page or home URL of the instance making requests. | ||
*/ | ||
blog: Blog; | ||
/** | ||
* Value indicating whether the client operates in test mode. | ||
*/ | ||
isTest: boolean; | ||
/** | ||
* The user agent string to use when making requests. | ||
*/ | ||
userAgent: string; | ||
/** | ||
* Creates a new client. | ||
* @param apiKey The Akismet API key. | ||
* @param blog The front page or home URL of the instance making requests. | ||
* @param options An object providing values to initialize this instance. | ||
*/ | ||
constructor(apiKey: string, blog: Blog, options?: ClientOptions); | ||
/** | ||
* Checks the specified comment against the service database, and returns a value indicating whether it is spam. | ||
* @param comment The comment to be checked. | ||
* @returns A value indicating whether the specified comment is spam. | ||
*/ | ||
checkComment(comment: Comment): Promise<CheckResult>; | ||
/** | ||
* Submits the specified comment that was incorrectly marked as spam but should not have been. | ||
* @param comment The comment to be submitted. | ||
* @returns Resolves once the comment has been submitted. | ||
*/ | ||
submitHam(comment: Comment): Promise<void>; | ||
/** | ||
* Submits the specified comment that was not marked as spam but should have been. | ||
* @param comment The comment to be submitted. | ||
* @returns Resolves once the comment has been submitted. | ||
*/ | ||
submitSpam(comment: Comment): Promise<void>; | ||
/** | ||
* Checks the API key against the service database, and returns a value indicating whether it is valid. | ||
* @returns `true` if the specified API key is valid, otherwise `false`. | ||
*/ | ||
verifyKey(): Promise<boolean>; | ||
} | ||
/** | ||
* Defines the options of a {@link Client} instance. | ||
*/ | ||
export interface ClientOptions { | ||
/** | ||
* The base URL of the remote API endpoint. | ||
*/ | ||
baseUrl: URL | string; | ||
/** | ||
* Value indicating whether the client operates in test mode. | ||
*/ | ||
isTest: boolean; | ||
/** | ||
* The user agent string to use when making requests. | ||
*/ | ||
userAgent: string; | ||
} | ||
//# sourceMappingURL=client.d.ts.map | ||
export type ClientOptions = Partial<{ | ||
/** | ||
* The base URL of the remote API endpoint. | ||
*/ | ||
baseUrl: URL|string; | ||
/** | ||
* Value indicating whether the client operates in test mode. | ||
*/ | ||
isTest: boolean; | ||
/** | ||
* The user agent string to use when making requests. | ||
*/ | ||
userAgent: string; | ||
}>; |
@@ -1,123 +0,121 @@ | ||
import process from "node:process"; | ||
import { CheckResult } from "./check_result.js"; | ||
/** | ||
* Submits comments to the [Akismet](https://akismet.com) service. | ||
*/ | ||
export class Client { | ||
/** | ||
* The response returned by the `submit-ham` and `submit-spam` endpoints when the outcome is a success. | ||
*/ | ||
static #success = "Thanks for making the web a better place."; | ||
/** | ||
* The package version. | ||
*/ | ||
static #version = "16.2.1"; | ||
/** | ||
* The Akismet API key. | ||
*/ | ||
apiKey; | ||
/** | ||
* The base URL of the remote API endpoint. | ||
*/ | ||
baseUrl; | ||
/** | ||
* The front page or home URL of the instance making requests. | ||
*/ | ||
blog; | ||
/** | ||
* Value indicating whether the client operates in test mode. | ||
*/ | ||
isTest; | ||
/** | ||
* The user agent string to use when making requests. | ||
*/ | ||
userAgent; | ||
/** | ||
* Creates a new client. | ||
* @param apiKey The Akismet API key. | ||
* @param blog The front page or home URL of the instance making requests. | ||
* @param options An object providing values to initialize this instance. | ||
*/ | ||
import { | ||
CheckResult | ||
} from "./check_result.js"; | ||
export var Client = (function() { | ||
// Submits comments to the [Akismet](https://akismet.com) service. | ||
class Client { | ||
// Creates a new client. | ||
constructor(apiKey, blog, options = {}) { | ||
const { baseUrl = "https://rest.akismet.com" } = options; | ||
const url = baseUrl instanceof URL ? baseUrl.href : baseUrl; | ||
this.apiKey = apiKey; | ||
this.baseUrl = new URL(url.endsWith("/") ? url : `${url}/`); | ||
this.blog = blog; | ||
this.isTest = options.isTest ?? false; | ||
const [nodeVersion] = process.version.slice(1).split("."); | ||
this.userAgent = options.userAgent ?? `Node.js/${nodeVersion} | Akismet/${Client.#version}`; | ||
var baseUrl, nodeVersion, ref, ref1, url; | ||
({baseUrl = "https://rest.akismet.com"} = options); | ||
[nodeVersion] = process.version.slice(1).split("."); | ||
url = baseUrl instanceof URL ? baseUrl.href : baseUrl; | ||
// The Akismet API key. | ||
this.apiKey = apiKey; | ||
// The base URL of the remote API endpoint. | ||
this.baseUrl = new URL(url.endsWith("/") ? url : `${url}/`); | ||
// The front page or home URL of the instance making requests. | ||
this.blog = blog; | ||
// Value indicating whether the client operates in test mode. | ||
this.isTest = (ref = options.isTest) != null ? ref : false; | ||
// The user agent string to use when making requests. | ||
this.userAgent = (ref1 = options.userAgent) != null ? ref1 : `Node.js/${nodeVersion} | Akismet/${Client._version}`; | ||
} | ||
/** | ||
* Checks the specified comment against the service database, and returns a value indicating whether it is spam. | ||
* @param comment The comment to be checked. | ||
* @returns A value indicating whether the specified comment is spam. | ||
*/ | ||
// Checks the specified comment against the service database, and returns a value indicating whether it is spam. | ||
async checkComment(comment) { | ||
const response = await this.#fetch("1.1/comment-check", comment.toJSON()); | ||
return await response.text() == "false" | ||
? CheckResult.ham | ||
: response.headers.get("x-akismet-pro-tip") == "discard" ? CheckResult.pervasiveSpam : CheckResult.spam; | ||
var response; | ||
response = (await this._fetch("1.1/comment-check", comment.toJSON())); | ||
switch (false) { | ||
case (await response.text()) !== "false": | ||
return CheckResult.ham; | ||
case response.headers.get("x-akismet-pro-tip") !== "discard": | ||
return CheckResult.pervasiveSpam; | ||
default: | ||
return CheckResult.spam; | ||
} | ||
} | ||
/** | ||
* Submits the specified comment that was incorrectly marked as spam but should not have been. | ||
* @param comment The comment to be submitted. | ||
* @returns Resolves once the comment has been submitted. | ||
*/ | ||
// Submits the specified comment that was incorrectly marked as spam but should not have been. | ||
async submitHam(comment) { | ||
const response = await this.#fetch("1.1/submit-ham", comment.toJSON()); | ||
if (await response.text() != Client.#success) | ||
throw Error("Invalid server response."); | ||
var response; | ||
response = (await this._fetch("1.1/submit-ham", comment.toJSON())); | ||
if ((await response.text()) !== Client._success) { | ||
throw Error("Invalid server response."); | ||
} | ||
} | ||
/** | ||
* Submits the specified comment that was not marked as spam but should have been. | ||
* @param comment The comment to be submitted. | ||
* @returns Resolves once the comment has been submitted. | ||
*/ | ||
// Submits the specified comment that was not marked as spam but should have been. | ||
async submitSpam(comment) { | ||
const response = await this.#fetch("1.1/submit-spam", comment.toJSON()); | ||
if (await response.text() != Client.#success) | ||
throw Error("Invalid server response."); | ||
var response; | ||
response = (await this._fetch("1.1/submit-spam", comment.toJSON())); | ||
if ((await response.text()) !== Client._success) { | ||
throw Error("Invalid server response."); | ||
} | ||
} | ||
/** | ||
* Checks the API key against the service database, and returns a value indicating whether it is valid. | ||
* @returns `true` if the specified API key is valid, otherwise `false`. | ||
*/ | ||
// Checks the API key against the service database, and returns a value indicating whether it is valid. | ||
async verifyKey() { | ||
try { | ||
const response = await this.#fetch("1.1/verify-key"); | ||
return await response.text() == "valid"; | ||
var response; | ||
try { | ||
response = (await this._fetch("1.1/verify-key")); | ||
return (await response.text()) === "valid"; | ||
} catch (error) { | ||
return false; | ||
} | ||
} | ||
// Queries the service by posting the specified fields to a given end point, and returns the response. | ||
async _fetch(endpoint, fields = {}) { | ||
var body, headers, index, item, key, ref, response, value, x; | ||
body = new URLSearchParams({ | ||
...this.blog.toJSON(), | ||
api_key: this.apiKey | ||
}); | ||
if (this.isTest) { | ||
body.set("is_test", "1"); | ||
} | ||
ref = Object.entries(fields); | ||
for (x of ref) { | ||
[key, value] = x; | ||
if (!Array.isArray(value)) { | ||
body.set(key, String(value)); | ||
} else { | ||
index = 0; | ||
for (item of value) { | ||
body.set(`${key}[${index++}]`, String(item)); | ||
} | ||
} | ||
catch { | ||
return false; | ||
} | ||
} | ||
response = (await fetch(new URL(endpoint, this.baseUrl), { | ||
method: "POST", | ||
headers: { | ||
"user-agent": this.userAgent | ||
}, | ||
body | ||
})); | ||
if (!response.ok) { | ||
throw Error(`${response.status} ${response.statusText}`); | ||
} | ||
({headers} = response); | ||
if (headers.has("x-akismet-alert-code")) { | ||
throw Error(`${headers.get("x-akismet-alert-code")} ${headers.get("x-akismet-alert-msg")}`); | ||
} | ||
if (headers.has("x-akismet-debug-help")) { | ||
throw Error(headers.get("x-akismet-debug-help")); | ||
} | ||
return response; | ||
} | ||
/** | ||
* Queries the service by posting the specified fields to a given end point, and returns the response. | ||
* @param endpoint The URL of the end point to query. | ||
* @param fields The fields describing the query body. | ||
* @returns The server response. | ||
*/ | ||
async #fetch(endpoint, fields = {}) { | ||
const body = new URLSearchParams({ ...this.blog.toJSON(), api_key: this.apiKey }); | ||
if (this.isTest) | ||
body.set("is_test", "1"); | ||
for (const [key, value] of Object.entries(fields)) | ||
if (!Array.isArray(value)) | ||
body.set(key, String(value)); | ||
else { | ||
let index = 0; | ||
for (const item of value) | ||
body.set(`${key}[${index++}]`, String(item)); | ||
} | ||
const response = await fetch(new URL(endpoint, this.baseUrl), { method: "POST", headers: { "user-agent": this.userAgent }, body }); | ||
if (!response.ok) | ||
throw Error(`${response.status} ${response.statusText}`); | ||
const { headers } = response; | ||
if (headers.has("x-akismet-alert-code")) | ||
throw Error(`${headers.get("x-akismet-alert-code")} ${headers.get("x-akismet-alert-msg")}`); | ||
if (headers.has("x-akismet-debug-help")) | ||
throw Error(headers.get("x-akismet-debug-help")); | ||
return response; | ||
} | ||
} | ||
}; | ||
// The response returned by the "submit-ham" and "submit-spam" endpoints when the outcome is a success. | ||
Client._success = "Thanks for making the web a better place."; | ||
// The package version. | ||
Client._version = "17.0.0"; | ||
return Client; | ||
}).call(this); |
@@ -1,133 +0,165 @@ | ||
import { Author } from "./author.js"; | ||
import {Author} from "./author.js"; | ||
/** | ||
* Represents a comment submitted by an author. | ||
*/ | ||
export declare class Comment { | ||
/** | ||
* The comment's author. | ||
*/ | ||
author: Author | null; | ||
/** | ||
* The comment's content. | ||
*/ | ||
content: string; | ||
/** | ||
* The context in which this comment was posted. | ||
*/ | ||
context: Array<string>; | ||
/** | ||
* The UTC timestamp of the creation of the comment. | ||
*/ | ||
date: Date | null; | ||
/** | ||
* The permanent location of the entry the comment is submitted to. | ||
*/ | ||
permalink: URL | null; | ||
/** | ||
* The UTC timestamp of the publication time for the post, page or thread on which the comment was posted. | ||
*/ | ||
postModified: Date | null; | ||
/** | ||
* A string describing why the content is being rechecked. | ||
*/ | ||
recheckReason: string; | ||
/** | ||
* The URL of the webpage that linked to the entry being requested. | ||
*/ | ||
referrer: URL | null; | ||
/** | ||
* The comment's type. | ||
*/ | ||
type: string; | ||
/** | ||
* Creates a new comment. | ||
* @param options An object providing values to initialize this instance. | ||
*/ | ||
constructor(options?: Partial<CommentOptions>); | ||
/** | ||
* Creates a new comment from the specified JSON object. | ||
* @param json A JSON object representing a comment. | ||
* @returns The instance corresponding to the specified JSON object. | ||
*/ | ||
static fromJson(json: Record<string, any>): Comment; | ||
/** | ||
* Returns a JSON representation of this object. | ||
* @returns The JSON representation of this object. | ||
*/ | ||
toJSON(): Record<string, any>; | ||
export class Comment { | ||
/** | ||
* The comment's author. | ||
*/ | ||
author: Author|null; | ||
/** | ||
* The comment's content. | ||
*/ | ||
content: string; | ||
/** | ||
* The context in which this comment was posted. | ||
*/ | ||
context: Array<string>; | ||
/** | ||
* The UTC timestamp of the creation of the comment. | ||
*/ | ||
date: Date|null; | ||
/** | ||
* The permanent location of the entry the comment is submitted to. | ||
*/ | ||
permalink: URL|null; | ||
/** | ||
* The UTC timestamp of the publication time for the post, page or thread on which the comment was posted. | ||
*/ | ||
postModified: Date|null; | ||
/** | ||
* A string describing why the content is being rechecked. | ||
*/ | ||
recheckReason: string; | ||
/** | ||
* The URL of the webpage that linked to the entry being requested. | ||
*/ | ||
referrer: URL|null; | ||
/** | ||
* The comment's type. | ||
*/ | ||
type: string; | ||
/** | ||
* Creates a new comment. | ||
* @param options An object providing values to initialize this instance. | ||
*/ | ||
constructor(options?: CommentOptions); | ||
/** | ||
* Creates a new comment from the specified JSON object. | ||
* @param json A JSON object representing a comment. | ||
* @returns The instance corresponding to the specified JSON object. | ||
*/ | ||
static fromJson(json: Record<string, any>): Comment; | ||
/** | ||
* Returns a JSON representation of this object. | ||
* @returns The JSON representation of this object. | ||
*/ | ||
toJSON(): Record<string, any>; | ||
} | ||
/** | ||
* Defines the options of a {@link Comment} instance. | ||
*/ | ||
export interface CommentOptions { | ||
/** | ||
* The comment's author. | ||
*/ | ||
author: Author | null; | ||
/** | ||
* The comment's content. | ||
*/ | ||
content: string; | ||
/** | ||
* The context in which this comment was posted. | ||
*/ | ||
context: Array<string>; | ||
/** | ||
* The UTC timestamp of the creation of the comment. | ||
*/ | ||
date: Date | null; | ||
/** | ||
* The permanent location of the entry the comment is submitted to. | ||
*/ | ||
permalink: URL | string; | ||
/** | ||
* The UTC timestamp of the publication time for the post, page or thread on which the comment was posted. | ||
*/ | ||
postModified: Date | null; | ||
/** | ||
* A string describing why the content is being rechecked. | ||
*/ | ||
recheckReason: string; | ||
/** | ||
* The URL of the webpage that linked to the entry being requested. | ||
*/ | ||
referrer: URL | string; | ||
/** | ||
* The comment's type. | ||
*/ | ||
type: string; | ||
} | ||
export type CommentOptions = Partial<{ | ||
/** | ||
* The comment's author. | ||
*/ | ||
author: Author|null; | ||
/** | ||
* The comment's content. | ||
*/ | ||
content: string; | ||
/** | ||
* The context in which this comment was posted. | ||
*/ | ||
context: Array<string>; | ||
/** | ||
* The UTC timestamp of the creation of the comment. | ||
*/ | ||
date: Date|null; | ||
/** | ||
* The permanent location of the entry the comment is submitted to. | ||
*/ | ||
permalink: URL|string; | ||
/** | ||
* The UTC timestamp of the publication time for the post, page or thread on which the comment was posted. | ||
*/ | ||
postModified: Date|null; | ||
/** | ||
* A string describing why the content is being rechecked. | ||
*/ | ||
recheckReason: string; | ||
/** | ||
* The URL of the webpage that linked to the entry being requested. | ||
*/ | ||
referrer: URL|string; | ||
/** | ||
* The comment's type. | ||
*/ | ||
type: string; | ||
}>; | ||
/** | ||
* Specifies the type of a comment. | ||
*/ | ||
export declare const CommentType: Readonly<{ | ||
/** | ||
* A blog post. | ||
*/ | ||
blogPost: "blog-post"; | ||
/** | ||
* A blog comment. | ||
*/ | ||
comment: "comment"; | ||
/** | ||
* A contact form or feedback form submission. | ||
*/ | ||
contactForm: "contact-form"; | ||
/** | ||
* A top-level forum post. | ||
*/ | ||
forumPost: "forum-post"; | ||
/** | ||
* A message sent between just a few users. | ||
*/ | ||
message: "message"; | ||
/** | ||
* A reply to a top-level forum post. | ||
*/ | ||
reply: "reply"; | ||
/** | ||
* A new user account. | ||
*/ | ||
signup: "signup"; | ||
export const CommentType: Readonly<{ | ||
/** | ||
* A blog post. | ||
*/ | ||
blogPost: "blog-post", | ||
/** | ||
* A blog comment. | ||
*/ | ||
comment: "comment", | ||
/** | ||
* A contact form or feedback form submission. | ||
*/ | ||
contactForm: "contact-form", | ||
/** | ||
* A top-level forum post. | ||
*/ | ||
forumPost: "forum-post", | ||
/** | ||
* A message sent between just a few users. | ||
*/ | ||
message: "message", | ||
/** | ||
* A reply to a top-level forum post. | ||
*/ | ||
reply: "reply", | ||
/** | ||
* A new user account. | ||
*/ | ||
signup: "signup" | ||
}>; | ||
/** | ||
@@ -137,2 +169,1 @@ * Specifies the type of a comment. | ||
export type CommentType = typeof CommentType[keyof typeof CommentType]; | ||
//# sourceMappingURL=comment.d.ts.map |
@@ -1,133 +0,98 @@ | ||
import { Author } from "./author.js"; | ||
/** | ||
* Represents a comment submitted by an author. | ||
*/ | ||
export class Comment { | ||
/** | ||
* The comment's author. | ||
*/ | ||
author; | ||
/** | ||
* The comment's content. | ||
*/ | ||
content; | ||
/** | ||
* The context in which this comment was posted. | ||
*/ | ||
context; | ||
/** | ||
* The UTC timestamp of the creation of the comment. | ||
*/ | ||
date; | ||
/** | ||
* The permanent location of the entry the comment is submitted to. | ||
*/ | ||
permalink; | ||
/** | ||
* The UTC timestamp of the publication time for the post, page or thread on which the comment was posted. | ||
*/ | ||
postModified; | ||
/** | ||
* A string describing why the content is being rechecked. | ||
*/ | ||
recheckReason; | ||
/** | ||
* The URL of the webpage that linked to the entry being requested. | ||
*/ | ||
referrer; | ||
/** | ||
* The comment's type. | ||
*/ | ||
type; | ||
/** | ||
* Creates a new comment. | ||
* @param options An object providing values to initialize this instance. | ||
*/ | ||
constructor(options = {}) { | ||
this.author = options.author ?? null; | ||
this.content = options.content ?? ""; | ||
this.context = options.context ?? []; | ||
this.date = options.date ?? null; | ||
this.permalink = options.permalink ? new URL(options.permalink) : null; | ||
this.postModified = options.postModified ?? null; | ||
this.recheckReason = options.recheckReason ?? ""; | ||
this.referrer = options.referrer ? new URL(options.referrer) : null; | ||
this.type = options.type ?? ""; | ||
import { | ||
Author | ||
} from "./author.js"; | ||
// Represents a comment submitted by an author. | ||
export var Comment = class Comment { | ||
// Creates a new comment. | ||
constructor(options = {}) { | ||
var ref, ref1, ref2, ref3, ref4, ref5, ref6; | ||
// The comment's author. | ||
this.author = (ref = options.author) != null ? ref : null; | ||
// The comment's content. | ||
this.content = (ref1 = options.content) != null ? ref1 : ""; | ||
// The context in which this comment was posted. | ||
this.context = (ref2 = options.context) != null ? ref2 : []; | ||
// The UTC timestamp of the creation of the comment. | ||
this.date = (ref3 = options.date) != null ? ref3 : null; | ||
// The permanent location of the entry the comment is submitted to. | ||
this.permalink = options.permalink ? new URL(options.permalink) : null; | ||
// The UTC timestamp of the publication time for the post, page or thread on which the comment was posted. | ||
this.postModified = (ref4 = options.postModified) != null ? ref4 : null; | ||
// A string describing why the content is being rechecked. | ||
this.recheckReason = (ref5 = options.recheckReason) != null ? ref5 : ""; | ||
// The URL of the webpage that linked to the entry being requested. | ||
this.referrer = options.referrer ? new URL(options.referrer) : null; | ||
// The comment's type. | ||
this.type = (ref6 = options.type) != null ? ref6 : ""; | ||
} | ||
// Creates a new comment from the specified JSON object. | ||
static fromJson(json) { | ||
var hasAuthor; | ||
hasAuthor = Object.keys(json).filter(function(key) { | ||
return key.startsWith("comment_author" || key.startsWith("user")); | ||
}).length > 0; | ||
return new this({ | ||
author: hasAuthor ? Author.fromJson(json) : null, | ||
content: typeof json.comment_content === "string" ? json.comment_content : "", | ||
context: Array.isArray(json.comment_context) ? json.comment_context : [], | ||
date: typeof json.comment_date_gmt === "string" ? new Date(json.comment_date_gmt) : null, | ||
permalink: typeof json.permalink === "string" ? json.permalink : "", | ||
postModified: typeof json.comment_post_modified_gmt === "string" ? new Date(json.comment_post_modified_gmt) : null, | ||
recheckReason: typeof json.recheck_reason === "string" ? json.recheck_reason : "", | ||
referrer: typeof json.referrer === "string" ? json.referrer : "", | ||
type: typeof json.comment_type === "string" ? json.comment_type : "" | ||
}); | ||
} | ||
// Returns a JSON representation of this object. | ||
toJSON() { | ||
var map, ref, ref1; | ||
map = (ref = (ref1 = this.author) != null ? ref1.toJSON() : void 0) != null ? ref : {}; | ||
if (this.content) { | ||
map.comment_content = this.content; | ||
} | ||
/** | ||
* Creates a new comment from the specified JSON object. | ||
* @param json A JSON object representing a comment. | ||
* @returns The instance corresponding to the specified JSON object. | ||
*/ | ||
static fromJson(json) { | ||
const hasAuthor = Object.keys(json).filter(key => key.startsWith("comment_author") || key.startsWith("user")).length > 0; | ||
return new this({ | ||
author: hasAuthor ? Author.fromJson(json) : null, | ||
content: typeof json.comment_content == "string" ? json.comment_content : "", | ||
context: Array.isArray(json.comment_context) ? json.comment_context : [], | ||
date: typeof json.comment_date_gmt == "string" ? new Date(json.comment_date_gmt) : null, | ||
permalink: typeof json.permalink == "string" ? json.permalink : "", | ||
postModified: typeof json.comment_post_modified_gmt == "string" ? new Date(json.comment_post_modified_gmt) : null, | ||
recheckReason: typeof json.recheck_reason == "string" ? json.recheck_reason : "", | ||
referrer: typeof json.referrer == "string" ? json.referrer : "", | ||
type: typeof json.comment_type == "string" ? json.comment_type : "" | ||
}); | ||
if (this.context.length) { | ||
map.comment_context = this.context; | ||
} | ||
/** | ||
* Returns a JSON representation of this object. | ||
* @returns The JSON representation of this object. | ||
*/ | ||
toJSON() { | ||
const map = this.author ? this.author.toJSON() : {}; | ||
if (this.content) | ||
map.comment_content = this.content; | ||
if (this.context.length) | ||
map.comment_context = this.context; | ||
if (this.date) | ||
map.comment_date_gmt = this.date.toJSON(); | ||
if (this.permalink) | ||
map.permalink = this.permalink.href; | ||
if (this.postModified) | ||
map.comment_post_modified_gmt = this.postModified.toJSON(); | ||
if (this.recheckReason) | ||
map.recheck_reason = this.recheckReason; | ||
if (this.referrer) | ||
map.referrer = this.referrer.href; | ||
if (this.type) | ||
map.comment_type = this.type; | ||
return map; | ||
if (this.date) { | ||
map.comment_date_gmt = this.date.toJSON(); | ||
} | ||
} | ||
/** | ||
* Specifies the type of a comment. | ||
*/ | ||
export const CommentType = Object.freeze({ | ||
/** | ||
* A blog post. | ||
*/ | ||
blogPost: "blog-post", | ||
/** | ||
* A blog comment. | ||
*/ | ||
comment: "comment", | ||
/** | ||
* A contact form or feedback form submission. | ||
*/ | ||
contactForm: "contact-form", | ||
/** | ||
* A top-level forum post. | ||
*/ | ||
forumPost: "forum-post", | ||
/** | ||
* A message sent between just a few users. | ||
*/ | ||
message: "message", | ||
/** | ||
* A reply to a top-level forum post. | ||
*/ | ||
reply: "reply", | ||
/** | ||
* A new user account. | ||
*/ | ||
signup: "signup" | ||
if (this.permalink) { | ||
map.permalink = this.permalink.href; | ||
} | ||
if (this.postModified) { | ||
map.comment_post_modified_gmt = this.postModified.toJSON(); | ||
} | ||
if (this.recheckReason) { | ||
map.recheck_reason = this.recheckReason; | ||
} | ||
if (this.referrer) { | ||
map.referrer = this.referrer.href; | ||
} | ||
if (this.type) { | ||
map.comment_type = this.type; | ||
} | ||
return map; | ||
} | ||
}; | ||
// Specifies the type of a comment. | ||
export var CommentType = Object.freeze({ | ||
// A blog post. | ||
blogPost: "blog-post", | ||
// A blog comment. | ||
comment: "comment", | ||
// A contact form or feedback form submission. | ||
contactForm: "contact-form", | ||
// A top-level forum post. | ||
forumPost: "forum-post", | ||
// A message sent between just a few users. | ||
message: "message", | ||
// A reply to a top-level forum post. | ||
reply: "reply", | ||
// A new user account. | ||
signup: "signup" | ||
}); |
@@ -7,2 +7,1 @@ export * from "./author.js"; | ||
export * from "./usage.js"; | ||
//# sourceMappingURL=index.d.ts.map |
export * from "./author.js"; | ||
export * from "./blog.js"; | ||
export * from "./check_result.js"; | ||
export * from "./client.js"; | ||
export * from "./comment.js"; | ||
export * from "./usage.js"; |
/** | ||
* Provides API usage for a given month. | ||
*/ | ||
export declare class Usage { | ||
/** | ||
* The number of monthly API calls your plan entitles you to. | ||
*/ | ||
limit: number; | ||
/** | ||
* The percentage of the limit used since the beginning of the month. | ||
*/ | ||
percentage: number; | ||
/** | ||
* Value indicating whether the requests are being throttled for having consistently gone over the limit. | ||
*/ | ||
throttled: boolean; | ||
/** | ||
* The number of calls (spam + ham) since the beginning of the month. | ||
*/ | ||
usage: number; | ||
/** | ||
* Creates a new usage. | ||
* @param options An object providing values to initialize this instance. | ||
*/ | ||
constructor(options?: Partial<UsageOptions>); | ||
/** | ||
* Creates a new usage from the specified JSON object. | ||
* @param json A JSON object representing a usage. | ||
* @returns The instance corresponding to the specified JSON object. | ||
*/ | ||
static fromJson(json: Record<string, any>): Usage; | ||
export class Usage { | ||
/** | ||
* The number of monthly API calls your plan entitles you to. | ||
*/ | ||
limit: number; | ||
/** | ||
* The percentage of the limit used since the beginning of the month. | ||
*/ | ||
percentage: number; | ||
/** | ||
* Value indicating whether the requests are being throttled for having consistently gone over the limit. | ||
*/ | ||
throttled: boolean; | ||
/** | ||
* The number of calls (spam + ham) since the beginning of the month. | ||
*/ | ||
usage: number; | ||
/** | ||
* Creates a new usage. | ||
* @param options An object providing values to initialize this instance. | ||
*/ | ||
constructor(options?: UsageOptions); | ||
/** | ||
* Creates a new usage from the specified JSON object. | ||
* @param json A JSON object representing a usage. | ||
* @returns The instance corresponding to the specified JSON object. | ||
*/ | ||
static fromJson(json: Record<string, any>): Usage; | ||
} | ||
/** | ||
* Defines the options of a {@link Usage} instance. | ||
*/ | ||
export interface UsageOptions { | ||
/** | ||
* The number of monthly API calls your plan entitles you to. | ||
*/ | ||
limit: number; | ||
/** | ||
* The percentage of the limit used since the beginning of the month. | ||
*/ | ||
percentage: number; | ||
/** | ||
* Value indicating whether the requests are being throttled for having consistently gone over the limit. | ||
*/ | ||
throttled: boolean; | ||
/** | ||
* The number of calls (spam + ham) since the beginning of the month. | ||
*/ | ||
usage: number; | ||
} | ||
//# sourceMappingURL=usage.d.ts.map | ||
export type UsageOptions = Partial<{ | ||
/** | ||
* The number of monthly API calls your plan entitles you to. | ||
*/ | ||
limit: number; | ||
/** | ||
* The percentage of the limit used since the beginning of the month. | ||
*/ | ||
percentage: number; | ||
/** | ||
* Value indicating whether the requests are being throttled for having consistently gone over the limit. | ||
*/ | ||
throttled: boolean; | ||
/** | ||
* The number of calls (spam + ham) since the beginning of the month. | ||
*/ | ||
usage: number; | ||
}>; |
@@ -1,44 +0,26 @@ | ||
/** | ||
* Provides API usage for a given month. | ||
*/ | ||
export class Usage { | ||
/** | ||
* The number of monthly API calls your plan entitles you to. | ||
*/ | ||
limit; | ||
/** | ||
* The percentage of the limit used since the beginning of the month. | ||
*/ | ||
percentage; | ||
/** | ||
* Value indicating whether the requests are being throttled for having consistently gone over the limit. | ||
*/ | ||
throttled; | ||
/** | ||
* The number of calls (spam + ham) since the beginning of the month. | ||
*/ | ||
usage; | ||
/** | ||
* Creates a new usage. | ||
* @param options An object providing values to initialize this instance. | ||
*/ | ||
constructor(options = {}) { | ||
this.limit = options.limit ?? -1; | ||
this.percentage = options.percentage ?? 0; | ||
this.throttled = options.throttled ?? false; | ||
this.usage = options.usage ?? 0; | ||
} | ||
/** | ||
* Creates a new usage from the specified JSON object. | ||
* @param json A JSON object representing a usage. | ||
* @returns The instance corresponding to the specified JSON object. | ||
*/ | ||
static fromJson(json) { | ||
return new this({ | ||
limit: Number.isInteger(json.limit) ? json.limit : -1, | ||
percentage: typeof json.percentage == "number" ? json.percentage : 0, | ||
throttled: typeof json.throttled == "boolean" ? json.throttled : false, | ||
usage: Number.isInteger(json.usage) ? json.usage : 0 | ||
}); | ||
} | ||
} | ||
// Provides API usage for a given month. | ||
export var Usage = class Usage { | ||
// Creates a new usage. | ||
constructor(options = {}) { | ||
var ref, ref1, ref2, ref3; | ||
// The number of monthly API calls your plan entitles you to. | ||
this.limit = (ref = options.limit) != null ? ref : -1; | ||
// The percentage of the limit used since the beginning of the month. | ||
this.percentage = (ref1 = options.percentage) != null ? ref1 : 0; | ||
// Value indicating whether the requests are being throttled for having consistently gone over the limit. | ||
this.throttled = (ref2 = options.throttled) != null ? ref2 : false; | ||
// The number of calls (spam + ham) since the beginning of the month. | ||
this.usage = (ref3 = options.usage) != null ? ref3 : 0; | ||
} | ||
// Creates a new usage from the specified JSON object. | ||
static fromJson(json) { | ||
return new this({ | ||
limit: Number.isInteger(json.limit) ? json.limit : -1, | ||
percentage: typeof json.percentage === "number" ? json.percentage : 0, | ||
throttled: typeof json.throttled === "boolean" ? json.throttled : false, | ||
usage: Number.isInteger(json.usage) ? json.usage : 0 | ||
}); | ||
} | ||
}; |
@@ -9,3 +9,3 @@ { | ||
"type": "module", | ||
"version": "16.2.1", | ||
"version": "17.0.0", | ||
"author": { | ||
@@ -17,10 +17,5 @@ "email": "cedric@belin.io", | ||
"devDependencies": { | ||
"@types/eslint__js": "^8.42.3", | ||
"@types/gulp": "^4.0.17", | ||
"@types/node": "^22.7.4", | ||
"del": "^7.1.0", | ||
"execa": "^9.4.0", | ||
"gulp": "^5.0.0", | ||
"typescript": "^5.6.2", | ||
"typescript-eslint": "^8.8.0" | ||
"@coffeelint/cli": "^5.2.11", | ||
"@types/node": "^22.9.0", | ||
"coffeescript": "^2.7.0" | ||
}, | ||
@@ -36,4 +31,3 @@ "engines": { | ||
"lib/", | ||
"src/", | ||
"tsconfig.json" | ||
"src/" | ||
], | ||
@@ -49,5 +43,4 @@ "keywords": [ | ||
"scripts": { | ||
"prepack": "gulp", | ||
"test": "gulp build && node --test --test-reporter=spec" | ||
"test": "cake test" | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
3
40001
25
765
2