@sapphire/phisherman 2.0.2-next.f83936db.0 → 2.0.2-next.fb147ec0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +0 -1
- package/dist/cjs/index.cjs +3 -4
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.cts +4 -1
- package/dist/esm/index.d.mts +4 -1
- package/dist/esm/index.mjs +4 -5
- package/dist/esm/index.mjs.map +1 -1
- package/package.json +13 -12
package/README.md
CHANGED
|
@@ -7,7 +7,6 @@
|
|
|
7
7
|
**Wrapper around [Phisherman](https://phisherman.gg) to easily check and report domains**
|
|
8
8
|
|
|
9
9
|
[](https://github.com/sapphiredev/utilities/blob/main/LICENSE.md)
|
|
10
|
-
[](https://codecov.io/gh/sapphiredev/utilities)
|
|
11
10
|
[](https://bundlephobia.com/result?p=@sapphire/phisherman)
|
|
12
11
|
[](https://www.npmjs.com/package/@sapphire/phisherman)
|
|
13
12
|
|
package/dist/cjs/index.cjs
CHANGED
|
@@ -9,7 +9,7 @@ var os__default = /*#__PURE__*/_interopDefault(os);
|
|
|
9
9
|
|
|
10
10
|
var __defProp = Object.defineProperty;
|
|
11
11
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
12
|
-
var packageVersion = "2.0.2-next.
|
|
12
|
+
var packageVersion = "2.0.2-next.fb147ec0";
|
|
13
13
|
var agent = `Sapphire Phisherman/${packageVersion} (undici) ${os__default.default.platform()}/${os__default.default.release()} (https://github.com/sapphiredev/utilities/tree/main/packages/phisherman)`;
|
|
14
14
|
var storedApiKey;
|
|
15
15
|
async function checkDomain(domain, apiKey = storedApiKey) {
|
|
@@ -113,8 +113,7 @@ async function checkApiKey(apiKey) {
|
|
|
113
113
|
__name(checkApiKey, "checkApiKey");
|
|
114
114
|
function validateUrl(domain) {
|
|
115
115
|
const regexp = /[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)/gi;
|
|
116
|
-
if (!domain.match(regexp))
|
|
117
|
-
throw new Error("[SapphirePhisherman]: Invalid domain provided");
|
|
116
|
+
if (!domain.match(regexp)) throw new Error("[SapphirePhisherman]: Invalid domain provided");
|
|
118
117
|
}
|
|
119
118
|
__name(validateUrl, "validateUrl");
|
|
120
119
|
|
|
@@ -123,5 +122,5 @@ exports.getDomainInfo = getDomainInfo;
|
|
|
123
122
|
exports.reportCaughtPhish = reportCaughtPhish;
|
|
124
123
|
exports.reportDomain = reportDomain;
|
|
125
124
|
exports.setApiKey = setApiKey;
|
|
126
|
-
//# sourceMappingURL=
|
|
125
|
+
//# sourceMappingURL=index.cjs.map
|
|
127
126
|
//# sourceMappingURL=index.cjs.map
|
package/dist/cjs/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/lib/Phisherman.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../src/lib/Phisherman.ts"],"names":["os","fetch","FetchResultTypes","FetchMethods"],"mappings":";;;;;;;;;;;AAKA,IAAM,cAAA,GAAyB,qBAAA;AAE/B,IAAM,KAAA,GAAQ,CAAA,oBAAA,EAAuB,cAAc,CAAA,UAAA,EAAaA,mBAAA,CAAG,UAAU,CAAA,CAAA,EAAIA,mBAAA,CAAG,OAAA,EAAS,CAAA,yEAAA,CAAA;AAI7F,IAAI,YAAA;AAQJ,eAAsB,WAAA,CAAY,MAAA,EAAgB,MAAA,GAAiB,YAAA,EAAc;AAChF,EAAA,WAAA,CAAY,MAAM,CAAA;AAClB,EAAA,MAAM,SAAS,MAAMC,WAAA;AAAA,IACpB,8CAA8C,MAAM,CAAA,CAAA;AAAA,IACpD;AAAA,MACC,OAAA,EAAS;AAAA,QACR,cAAA,EAAgB,kBAAA;AAAA,QAChB,YAAA,EAAc,KAAA;AAAA,QACd,aAAA,EAAe,UAAU,MAAM,CAAA;AAAA;AAChC,KACD;AAAA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aAAA,CAAA;AAwBf,SAAS,YAAY,MAAA,EAAgB;AACpC,EAAA,MAAM,MAAA,GAAS,sFAAA;AACf,EAAA,IAAI,CAAC,OAAO,KAAA,CAAM,MAAM,GAAG,MAAM,IAAI,MAAM,+CAA+C,CAAA;AAC3F;AAHS,MAAA,CAAA,WAAA,EAAA,aAAA,CAAA","file":"index.cjs","sourcesContent":["import { fetch, FetchMethods, FetchResultTypes, QueryError } from '@sapphire/fetch';\nimport type { PhishermanInfoType, PhishermanReportType, PhishermanReturnType } from './PhishermanTypes';\nimport os from 'node:os';\n\n// eslint-disable-next-line @typescript-eslint/no-inferrable-types\nconst packageVersion: string = '2.0.2-next.fb147ec0';\n\nconst agent = `Sapphire Phisherman/${packageVersion} (undici) ${os.platform()}/${os.release()} (https://github.com/sapphiredev/utilities/tree/main/packages/phisherman)`;\n/**\n * The cached apiKey which was created using {@link setApiKey}\n */\nlet storedApiKey: string;\n\n/**\n * Checks if a link is detected as a scam or phishing link by phisherman.\n * @param domain The domain to check.\n * @param apiKey optionally pass a Phiserman API key for making this request. This will default to {@link storedApiKey}, which can be configured through {@link setApiKey}.\n * @since 1.0.0\n */\nexport async function checkDomain(domain: string, apiKey: string = storedApiKey) {\n\tvalidateUrl(domain);\n\tconst result = await fetch<PhishermanReturnType>(\n\t\t`https://api.phisherman.gg/v2/domains/check/${domain}`,\n\t\t{\n\t\t\theaders: {\n\t\t\t\t'Content-Type': 'application/json',\n\t\t\t\t'User-Agent': agent,\n\t\t\t\tAuthorization: `Bearer ${apiKey}`\n\t\t\t}\n\t\t},\n\t\tFetchResultTypes.JSON\n\t);\n\n\treturn {\n\t\t...result,\n\t\tisScam: result.classification === 'safe' || result.classification === 'unknown' ? false : true\n\t};\n}\n\n/**\n * Report a domain that is confirmed to be a scam or phishing domain to phisherman, to enhance their API.\n * @param domain The domain to report.\n * @param apiKey optionally pass a Phiserman API key for making this request. This will default to {@link storedApiKey}, which can be configured through {@link setApiKey}.\n * @since 1.0.0\n */\nexport function reportDomain(domain: string, apiKey: string = storedApiKey) {\n\tvalidateUrl(domain);\n\treturn fetch<PhishermanReportType>(\n\t\t`https://api.phisherman.gg/v2/phish/report`,\n\t\t{\n\t\t\tmethod: FetchMethods.Put,\n\t\t\theaders: {\n\t\t\t\t'Content-Type': 'application/json',\n\t\t\t\t'User-Agent': agent,\n\t\t\t\tAuthorization: `Bearer ${apiKey}`\n\t\t\t},\n\t\t\tbody: JSON.stringify({\n\t\t\t\turl: domain\n\t\t\t})\n\t\t},\n\t\tFetchResultTypes.JSON\n\t);\n}\n\n/**\n * Returns information for a domain.\n * @param domain The domain to get info about.\n * @param apiKey optionally pass a Phiserman API key for making this request. This will default to {@link storedApiKey}, which can be configured through {@link setApiKey}.\n * @since 1.1.0\n */\nexport async function getDomainInfo(domain: string, apiKey: string = storedApiKey) {\n\tvalidateUrl(domain);\n\tconst result = await fetch<PhishermanInfoType>(\n\t\t`https://api.phisherman.gg/v2/domains/info/${domain}`,\n\t\t{\n\t\t\theaders: {\n\t\t\t\t'Content-Type': 'application/json',\n\t\t\t\t'User-Agent': agent,\n\t\t\t\tAuthorization: `Bearer ${apiKey}`\n\t\t\t}\n\t\t},\n\t\tFetchResultTypes.JSON\n\t);\n\treturn result[domain];\n}\n\n/**\n * Report a caught phish back to phisherman to improve their analytics.\n * @param domain The domain which was caught.\n * @param apiKey @param apiKey optionally pass a Phiserman API key for making this request. This will default to {@link storedApiKey}, which can be configured through {@link setApiKey}.\n * @param guildId The id of the guild in which the domain was caught.\n * @since 1.1.0\n */\nexport function reportCaughtPhish(domain: string, apiKey: string = storedApiKey, guildId: string | number = '') {\n\treturn fetch<PhishermanReportType>(\n\t\t`https://api.phisherman.gg/v2/phish/caught/${domain}`,\n\t\t{\n\t\t\tmethod: FetchMethods.Post,\n\t\t\theaders: {\n\t\t\t\t'Content-Type': 'application/json',\n\t\t\t\t'User-Agent': agent,\n\t\t\t\tAuthorization: `Bearer ${apiKey}`\n\t\t\t},\n\t\t\tbody: JSON.stringify({\n\t\t\t\tguild: Number(guildId)\n\t\t\t})\n\t\t},\n\t\tFetchResultTypes.JSON\n\t);\n}\n\n/**\n * Set the phisherman's API key.\n * @param key The API key to access the phisherman API and cache within the code of the wrapper.\n * @since 1.0.0\n */\nexport async function setApiKey(key: string) {\n\tawait checkApiKey(key);\n\tstoredApiKey = key;\n}\n\nasync function checkApiKey(apiKey: string) {\n\ttry {\n\t\tawait fetch<{ message: string; success: false }>(\n\t\t\t`https://api.phisherman.gg/v2/domains/check/verified.test.phisherman.gg`,\n\t\t\t{\n\t\t\t\theaders: {\n\t\t\t\t\t'Content-Type': 'application/json',\n\t\t\t\t\t'User-Agent': agent,\n\t\t\t\t\tAuthorization: `Bearer ${apiKey}`\n\t\t\t\t}\n\t\t\t},\n\t\t\tFetchResultTypes.JSON\n\t\t);\n\t} catch (error) {\n\t\tconst typedError = error as QueryError;\n\n\t\tif (typedError.code === 401 && typedError.toJSON().message === 'missing permissions or invalid API key') {\n\t\t\tthrow new Error('[SapphirePhisherman]: Invalid API key provided');\n\t\t}\n\n\t\tthrow error;\n\t}\n}\n\nfunction validateUrl(domain: string) {\n\tconst regexp = /[-a-zA-Z0-9@:%._\\+~#=]{1,256}\\.[a-zA-Z0-9()]{1,6}\\b([-a-zA-Z0-9()@:%_\\+.~#?&//=]*)/gi;\n\tif (!domain.match(regexp)) throw new Error('[SapphirePhisherman]: Invalid domain provided');\n}\n"]}
|
package/dist/cjs/index.d.cts
CHANGED
|
@@ -24,6 +24,9 @@ interface PhishermanInfo {
|
|
|
24
24
|
phishCaught: number;
|
|
25
25
|
details: Details;
|
|
26
26
|
}
|
|
27
|
+
interface PhishermanInfoType {
|
|
28
|
+
[key: string]: PhishermanInfo;
|
|
29
|
+
}
|
|
27
30
|
interface Details {
|
|
28
31
|
phishTankId: string;
|
|
29
32
|
urlScanId: string;
|
|
@@ -83,4 +86,4 @@ declare function reportCaughtPhish(domain: string, apiKey?: string, guildId?: st
|
|
|
83
86
|
*/
|
|
84
87
|
declare function setApiKey(key: string): Promise<void>;
|
|
85
88
|
|
|
86
|
-
export { type CheckReturnType, type PhishermanOptions, type PhishermanReportType, type PhishermanReturnType, checkDomain, getDomainInfo, reportCaughtPhish, reportDomain, setApiKey };
|
|
89
|
+
export { type CheckReturnType, type PhishermanInfo, type PhishermanInfoType, type PhishermanOptions, type PhishermanReportType, type PhishermanReturnType, checkDomain, getDomainInfo, reportCaughtPhish, reportDomain, setApiKey };
|
package/dist/esm/index.d.mts
CHANGED
|
@@ -24,6 +24,9 @@ interface PhishermanInfo {
|
|
|
24
24
|
phishCaught: number;
|
|
25
25
|
details: Details;
|
|
26
26
|
}
|
|
27
|
+
interface PhishermanInfoType {
|
|
28
|
+
[key: string]: PhishermanInfo;
|
|
29
|
+
}
|
|
27
30
|
interface Details {
|
|
28
31
|
phishTankId: string;
|
|
29
32
|
urlScanId: string;
|
|
@@ -83,4 +86,4 @@ declare function reportCaughtPhish(domain: string, apiKey?: string, guildId?: st
|
|
|
83
86
|
*/
|
|
84
87
|
declare function setApiKey(key: string): Promise<void>;
|
|
85
88
|
|
|
86
|
-
export { type CheckReturnType, type PhishermanOptions, type PhishermanReportType, type PhishermanReturnType, checkDomain, getDomainInfo, reportCaughtPhish, reportDomain, setApiKey };
|
|
89
|
+
export { type CheckReturnType, type PhishermanInfo, type PhishermanInfoType, type PhishermanOptions, type PhishermanReportType, type PhishermanReturnType, checkDomain, getDomainInfo, reportCaughtPhish, reportDomain, setApiKey };
|
package/dist/esm/index.mjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { fetch, FetchResultTypes, FetchMethods } from '@sapphire/fetch';
|
|
2
|
-
import os from '
|
|
2
|
+
import os from 'os';
|
|
3
3
|
|
|
4
4
|
var __defProp = Object.defineProperty;
|
|
5
5
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
6
|
-
var packageVersion = "2.0.2-next.
|
|
6
|
+
var packageVersion = "2.0.2-next.fb147ec0";
|
|
7
7
|
var agent = `Sapphire Phisherman/${packageVersion} (undici) ${os.platform()}/${os.release()} (https://github.com/sapphiredev/utilities/tree/main/packages/phisherman)`;
|
|
8
8
|
var storedApiKey;
|
|
9
9
|
async function checkDomain(domain, apiKey = storedApiKey) {
|
|
@@ -107,11 +107,10 @@ async function checkApiKey(apiKey) {
|
|
|
107
107
|
__name(checkApiKey, "checkApiKey");
|
|
108
108
|
function validateUrl(domain) {
|
|
109
109
|
const regexp = /[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)/gi;
|
|
110
|
-
if (!domain.match(regexp))
|
|
111
|
-
throw new Error("[SapphirePhisherman]: Invalid domain provided");
|
|
110
|
+
if (!domain.match(regexp)) throw new Error("[SapphirePhisherman]: Invalid domain provided");
|
|
112
111
|
}
|
|
113
112
|
__name(validateUrl, "validateUrl");
|
|
114
113
|
|
|
115
114
|
export { checkDomain, getDomainInfo, reportCaughtPhish, reportDomain, setApiKey };
|
|
116
|
-
//# sourceMappingURL=
|
|
115
|
+
//# sourceMappingURL=index.mjs.map
|
|
117
116
|
//# sourceMappingURL=index.mjs.map
|
package/dist/esm/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/lib/Phisherman.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../src/lib/Phisherman.ts"],"names":[],"mappings":";;;;;AAKA,IAAM,cAAA,GAAyB,qBAAA;AAE/B,IAAM,KAAA,GAAQ,CAAA,oBAAA,EAAuB,cAAc,CAAA,UAAA,EAAa,EAAA,CAAG,UAAU,CAAA,CAAA,EAAI,EAAA,CAAG,OAAA,EAAS,CAAA,yEAAA,CAAA;AAI7F,IAAI,YAAA;AAQJ,eAAsB,WAAA,CAAY,MAAA,EAAgB,MAAA,GAAiB,YAAA,EAAc;AAChF,EAAA,WAAA,CAAY,MAAM,CAAA;AAClB,EAAA,MAAM,SAA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W,IAAA,KAAS,GAAA,IAAO,WAAW,MAAA,EAAO,CAAE,YAAY,wCAAA,EAA0C;AACxG,MAAA,MAAM,IAAI,MAAM,gDAAgD,CAAA;AAAA,IACjE;AAEA,IAAA,MAAM,KAAA;AAAA,EACP;AACD;AAtBe,MAAA,CAAA,WAAA,EAAA,aAAA,CAAA;AAwBf,SAAS,YAAY,MAAA,EAAgB;AACpC,EAAA,MAAM,MAAA,GAAS,sFAAA;AACf,EAAA,IAAI,CAAC,OAAO,KAAA,CAAM,MAAM,GAAG,MAAM,IAAI,MAAM,+CAA+C,CAAA;AAC3F;AAHS,MAAA,CAAA,WAAA,EAAA,aAAA,CAAA","file":"index.mjs","sourcesContent":["import { fetch, FetchMethods, FetchResultTypes, QueryError } from '@sapphire/fetch';\nimport type { PhishermanInfoType, PhishermanReportType, PhishermanReturnType } from './PhishermanTypes';\nimport os from 'node:os';\n\n// eslint-disable-next-line @typescript-eslint/no-inferrable-types\nconst packageVersion: string = '2.0.2-next.fb147ec0';\n\nconst agent = `Sapphire Phisherman/${packageVersion} (undici) ${os.platform()}/${os.release()} (https://github.com/sapphiredev/utilities/tree/main/packages/phisherman)`;\n/**\n * The cached apiKey which was created using {@link setApiKey}\n */\nlet storedApiKey: string;\n\n/**\n * Checks if a link is detected as a scam or phishing link by phisherman.\n * @param domain The domain to check.\n * @param apiKey optionally pass a Phiserman API key for making this request. This will default to {@link storedApiKey}, which can be configured through {@link setApiKey}.\n * @since 1.0.0\n */\nexport async function checkDomain(domain: string, apiKey: string = storedApiKey) {\n\tvalidateUrl(domain);\n\tconst result = await fetch<PhishermanReturnType>(\n\t\t`https://api.phisherman.gg/v2/domains/check/${domain}`,\n\t\t{\n\t\t\theaders: {\n\t\t\t\t'Content-Type': 'application/json',\n\t\t\t\t'User-Agent': agent,\n\t\t\t\tAuthorization: `Bearer ${apiKey}`\n\t\t\t}\n\t\t},\n\t\tFetchResultTypes.JSON\n\t);\n\n\treturn {\n\t\t...result,\n\t\tisScam: result.classification === 'safe' || result.classification === 'unknown' ? false : true\n\t};\n}\n\n/**\n * Report a domain that is confirmed to be a scam or phishing domain to phisherman, to enhance their API.\n * @param domain The domain to report.\n * @param apiKey optionally pass a Phiserman API key for making this request. This will default to {@link storedApiKey}, which can be configured through {@link setApiKey}.\n * @since 1.0.0\n */\nexport function reportDomain(domain: string, apiKey: string = storedApiKey) {\n\tvalidateUrl(domain);\n\treturn fetch<PhishermanReportType>(\n\t\t`https://api.phisherman.gg/v2/phish/report`,\n\t\t{\n\t\t\tmethod: FetchMethods.Put,\n\t\t\theaders: {\n\t\t\t\t'Content-Type': 'application/json',\n\t\t\t\t'User-Agent': agent,\n\t\t\t\tAuthorization: `Bearer ${apiKey}`\n\t\t\t},\n\t\t\tbody: JSON.stringify({\n\t\t\t\turl: domain\n\t\t\t})\n\t\t},\n\t\tFetchResultTypes.JSON\n\t);\n}\n\n/**\n * Returns information for a domain.\n * @param domain The domain to get info about.\n * @param apiKey optionally pass a Phiserman API key for making this request. This will default to {@link storedApiKey}, which can be configured through {@link setApiKey}.\n * @since 1.1.0\n */\nexport async function getDomainInfo(domain: string, apiKey: string = storedApiKey) {\n\tvalidateUrl(domain);\n\tconst result = await fetch<PhishermanInfoType>(\n\t\t`https://api.phisherman.gg/v2/domains/info/${domain}`,\n\t\t{\n\t\t\theaders: {\n\t\t\t\t'Content-Type': 'application/json',\n\t\t\t\t'User-Agent': agent,\n\t\t\t\tAuthorization: `Bearer ${apiKey}`\n\t\t\t}\n\t\t},\n\t\tFetchResultTypes.JSON\n\t);\n\treturn result[domain];\n}\n\n/**\n * Report a caught phish back to phisherman to improve their analytics.\n * @param domain The domain which was caught.\n * @param apiKey @param apiKey optionally pass a Phiserman API key for making this request. This will default to {@link storedApiKey}, which can be configured through {@link setApiKey}.\n * @param guildId The id of the guild in which the domain was caught.\n * @since 1.1.0\n */\nexport function reportCaughtPhish(domain: string, apiKey: string = storedApiKey, guildId: string | number = '') {\n\treturn fetch<PhishermanReportType>(\n\t\t`https://api.phisherman.gg/v2/phish/caught/${domain}`,\n\t\t{\n\t\t\tmethod: FetchMethods.Post,\n\t\t\theaders: {\n\t\t\t\t'Content-Type': 'application/json',\n\t\t\t\t'User-Agent': agent,\n\t\t\t\tAuthorization: `Bearer ${apiKey}`\n\t\t\t},\n\t\t\tbody: JSON.stringify({\n\t\t\t\tguild: Number(guildId)\n\t\t\t})\n\t\t},\n\t\tFetchResultTypes.JSON\n\t);\n}\n\n/**\n * Set the phisherman's API key.\n * @param key The API key to access the phisherman API and cache within the code of the wrapper.\n * @since 1.0.0\n */\nexport async function setApiKey(key: string) {\n\tawait checkApiKey(key);\n\tstoredApiKey = key;\n}\n\nasync function checkApiKey(apiKey: string) {\n\ttry {\n\t\tawait fetch<{ message: string; success: false }>(\n\t\t\t`https://api.phisherman.gg/v2/domains/check/verified.test.phisherman.gg`,\n\t\t\t{\n\t\t\t\theaders: {\n\t\t\t\t\t'Content-Type': 'application/json',\n\t\t\t\t\t'User-Agent': agent,\n\t\t\t\t\tAuthorization: `Bearer ${apiKey}`\n\t\t\t\t}\n\t\t\t},\n\t\t\tFetchResultTypes.JSON\n\t\t);\n\t} catch (error) {\n\t\tconst typedError = error as QueryError;\n\n\t\tif (typedError.code === 401 && typedError.toJSON().message === 'missing permissions or invalid API key') {\n\t\t\tthrow new Error('[SapphirePhisherman]: Invalid API key provided');\n\t\t}\n\n\t\tthrow error;\n\t}\n}\n\nfunction validateUrl(domain: string) {\n\tconst regexp = /[-a-zA-Z0-9@:%._\\+~#=]{1,256}\\.[a-zA-Z0-9()]{1,6}\\b([-a-zA-Z0-9()@:%_\\+.~#?&//=]*)/gi;\n\tif (!domain.match(regexp)) throw new Error('[SapphirePhisherman]: Invalid domain provided');\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sapphire/phisherman",
|
|
3
|
-
"version": "2.0.2-next.
|
|
3
|
+
"version": "2.0.2-next.fb147ec0",
|
|
4
4
|
"description": "Wrapper around phisherman to easily check and report domains",
|
|
5
5
|
"author": "@sapphire",
|
|
6
6
|
"license": "MIT",
|
|
@@ -20,15 +20,16 @@
|
|
|
20
20
|
"homepage": "https://github.com/sapphiredev/utilities/tree/main/packages/phisherman",
|
|
21
21
|
"scripts": {
|
|
22
22
|
"lint": "eslint src --ext ts --fix",
|
|
23
|
-
"build": "tsup && yarn build:rename-cjs-index",
|
|
24
|
-
"build:rename-cjs-index": "tsx
|
|
23
|
+
"build": "yarn gen-index && tsup && yarn build:rename-cjs-index",
|
|
24
|
+
"build:rename-cjs-index": "tsx ../../scripts/rename-cjs-index.cts",
|
|
25
25
|
"docs": "typedoc-json-parser",
|
|
26
26
|
"prepack": "yarn build",
|
|
27
27
|
"bump": "cliff-jumper",
|
|
28
|
-
"check-update": "cliff-jumper --dry-run"
|
|
28
|
+
"check-update": "cliff-jumper --dry-run",
|
|
29
|
+
"gen-index": "tsx ../../scripts/gen-index.cts phisherman --write"
|
|
29
30
|
},
|
|
30
31
|
"dependencies": {
|
|
31
|
-
"@sapphire/fetch": "^3.0.
|
|
32
|
+
"@sapphire/fetch": "^3.0.5"
|
|
32
33
|
},
|
|
33
34
|
"repository": {
|
|
34
35
|
"type": "git",
|
|
@@ -60,13 +61,13 @@
|
|
|
60
61
|
"access": "public"
|
|
61
62
|
},
|
|
62
63
|
"devDependencies": {
|
|
63
|
-
"@favware/cliff-jumper": "^
|
|
64
|
-
"@sapphire/result": "^2.
|
|
64
|
+
"@favware/cliff-jumper": "^6.0.0",
|
|
65
|
+
"@sapphire/result": "^2.7.2",
|
|
65
66
|
"esbuild-plugin-version-injector": "^1.2.1",
|
|
66
|
-
"tsup": "^8.0
|
|
67
|
-
"tsx": "^4.
|
|
68
|
-
"typedoc": "^0.
|
|
69
|
-
"typedoc-json-parser": "^10.
|
|
70
|
-
"typescript": "
|
|
67
|
+
"tsup": "^8.5.0",
|
|
68
|
+
"tsx": "^4.20.3",
|
|
69
|
+
"typedoc": "^0.26.11",
|
|
70
|
+
"typedoc-json-parser": "^10.2.0",
|
|
71
|
+
"typescript": "~5.4.5"
|
|
71
72
|
}
|
|
72
73
|
}
|