@cedx/akismet
Advanced tools
Comparing version 16.0.1 to 16.0.2
# MIT License | ||
Copyright © 2014-2022 Cédric Belin | ||
Copyright © 2014-2023 Cédric Belin | ||
@@ -4,0 +4,0 @@ Permission is hereby granted, free of charge, to any person obtaining a copy |
@@ -9,3 +9,3 @@ { | ||
"type": "module", | ||
"version": "16.0.1", | ||
"version": "16.0.2", | ||
"author": { | ||
@@ -18,12 +18,13 @@ "email": "cedric@belin.io", | ||
"@babel/eslint-parser": "^7.19.1", | ||
"@babel/plugin-syntax-import-assertions": "^7.18.6", | ||
"@types/gulp": "^4.0.9", | ||
"@types/node": "^18.11.0", | ||
"@babel/plugin-syntax-import-assertions": "^7.20.0", | ||
"@types/gulp": "^4.0.10", | ||
"@types/node": "^18.11.18", | ||
"c8": "^7.12.0", | ||
"del": "^7.0.0", | ||
"eslint": "^8.25.0", | ||
"eslint": "^8.31.0", | ||
"execa": "^6.1.0", | ||
"gulp": "^4.0.2", | ||
"typedoc": "^0.23.17", | ||
"typescript": "^4.8.4" | ||
"gulp-replace": "^1.1.4", | ||
"typedoc": "^0.23.24", | ||
"typescript": "^4.9.4" | ||
}, | ||
@@ -30,0 +31,0 @@ "engines": { |
import {version} from "node:process"; | ||
import {CheckResult} from "./check_result.js"; | ||
import pkg from "../package.json" assert {type: "json"}; | ||
@@ -11,2 +10,14 @@ /** | ||
/** | ||
* The response returned by the `submit-ham` and `submit-spam` endpoints when the outcome is a success. | ||
* @type {string} | ||
*/ | ||
static #success = "Thanks for making the web a better place."; | ||
/** | ||
* The package version. | ||
* @type {string} | ||
*/ | ||
static #version = "16.0.2"; | ||
/** | ||
* The Akismet API key. | ||
@@ -53,8 +64,2 @@ * @type {string} | ||
/** | ||
* The response returned by the `submit-ham` and `submit-spam` endpoints when the outcome is a success. | ||
* @type {string} | ||
*/ | ||
static #successfulResponse = "Thanks for making the web a better place."; | ||
/** | ||
* Creates a new client. | ||
@@ -70,3 +75,3 @@ * @param {string} apiKey The Akismet API key. | ||
this.isTest = options.isTest ?? false; | ||
this.userAgent = options.userAgent ?? `Node.js/${version.slice(1)} | Akismet/${pkg.version}`; | ||
this.userAgent = options.userAgent ?? `Node.js/${version.slice(1)} | Akismet/${Client.#version}`; | ||
this.#endpoint = new URL(`${this.baseUrl.protocol}//${this.apiKey}.${this.baseUrl.host}${this.baseUrl.pathname}`); | ||
@@ -94,3 +99,3 @@ } | ||
const response = await this.#fetch(new URL("submit-ham", this.#endpoint), comment.toJSON()); | ||
if (await response.text() != Client.#successfulResponse) throw new Error("Invalid server response."); | ||
if (await response.text() != Client.#success) throw Error("Invalid server response."); | ||
} | ||
@@ -105,3 +110,3 @@ | ||
const response = await this.#fetch(new URL("submit-spam", this.#endpoint), comment.toJSON()); | ||
if (await response.text() != Client.#successfulResponse) throw new Error("Invalid server response."); | ||
if (await response.text() != Client.#success) throw Error("Invalid server response."); | ||
} | ||
@@ -128,18 +133,12 @@ | ||
const params = { | ||
method: "POST", | ||
headers: {"content-type": "application/x-www-form-urlencoded", "user-agent": this.userAgent}, | ||
body | ||
}; | ||
const response = await fetch(endpoint, {method: "POST", headers: {"User-Agent": this.userAgent}, body}); | ||
if (!response.ok) throw Error(`${response.status} ${response.statusText}`); | ||
const response = await fetch(endpoint, params); | ||
if (!response.ok) throw new Error(`${response.status} ${response.statusText}`); | ||
if (response.headers.has("X-akismet-alert-code")) { | ||
const code = response.headers.get("X-akismet-alert-code") ?? ""; | ||
throw Object.assign(new Error(response.headers.get("X-akismet-alert-msg") ?? ""), {name: code ? `AkismetError #${code}` : "AkismetError"}); | ||
throw Object.assign(Error(response.headers.get("X-akismet-alert-msg") ?? ""), {name: code ? `AkismetError #${code}` : "AkismetError"}); | ||
} | ||
if (response.headers.has("X-akismet-debug-help")) | ||
throw Object.assign(new Error(response.headers.get("X-akismet-debug-help") ?? ""), {name: "AkismetError"}); | ||
throw Object.assign(Error(response.headers.get("X-akismet-debug-help") ?? ""), {name: "AkismetError"}); | ||
@@ -146,0 +145,0 @@ return response; |
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
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
34919
840
12