@sapphire/phisherman 1.4.2-next.76e4efd.0 β 1.4.2-next.78a79ca.0
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 +9 -2
- package/dist/index.d.ts +86 -3
- package/dist/index.js +66 -42
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +61 -41
- package/dist/index.mjs.map +1 -1
- package/package.json +9 -5
- package/dist/lib/Phisherman.d.ts +0 -41
- package/dist/lib/PhishermanTypes.d.ts +0 -49
package/README.md
CHANGED
|
@@ -86,7 +86,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
|
|
|
86
86
|
<table>
|
|
87
87
|
<tr>
|
|
88
88
|
<td align="center"><a href="https://favware.tech/"><img src="https://avatars3.githubusercontent.com/u/4019718?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Jeroen Claassens</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=favna" title="Code">π»</a> <a href="#infra-favna" title="Infrastructure (Hosting, Build-Tools, etc)">π</a> <a href="#projectManagement-favna" title="Project Management">π</a> <a href="https://github.com/sapphiredev/utilities/commits?author=favna" title="Documentation">π</a> <a href="https://github.com/sapphiredev/utilities/commits?author=favna" title="Tests">β οΈ</a></td>
|
|
89
|
-
<td align="center"><a href="https://github.com/kyranet"><img src="https://avatars0.githubusercontent.com/u/24852502?v=4?s=100" width="100px;" alt=""/><br /><sub><b>
|
|
89
|
+
<td align="center"><a href="https://github.com/kyranet"><img src="https://avatars0.githubusercontent.com/u/24852502?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Aura RomΓ‘n</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=kyranet" title="Code">π»</a> <a href="#projectManagement-kyranet" title="Project Management">π</a> <a href="https://github.com/sapphiredev/utilities/pulls?q=is%3Apr+reviewed-by%3Akyranet" title="Reviewed Pull Requests">π</a> <a href="https://github.com/sapphiredev/utilities/commits?author=kyranet" title="Tests">β οΈ</a></td>
|
|
90
90
|
<td align="center"><a href="https://github.com/PyroTechniac"><img src="https://avatars2.githubusercontent.com/u/39341355?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Gryffon Bellish</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=PyroTechniac" title="Code">π»</a> <a href="https://github.com/sapphiredev/utilities/pulls?q=is%3Apr+reviewed-by%3APyroTechniac" title="Reviewed Pull Requests">π</a> <a href="https://github.com/sapphiredev/utilities/commits?author=PyroTechniac" title="Tests">β οΈ</a></td>
|
|
91
91
|
<td align="center"><a href="https://github.com/vladfrangu"><img src="https://avatars3.githubusercontent.com/u/17960496?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Vlad Frangu</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=vladfrangu" title="Code">π»</a> <a href="https://github.com/sapphiredev/utilities/issues?q=author%3Avladfrangu" title="Bug reports">π</a> <a href="https://github.com/sapphiredev/utilities/pulls?q=is%3Apr+reviewed-by%3Avladfrangu" title="Reviewed Pull Requests">π</a> <a href="#userTesting-vladfrangu" title="User Testing">π</a> <a href="https://github.com/sapphiredev/utilities/commits?author=vladfrangu" title="Tests">β οΈ</a></td>
|
|
92
92
|
<td align="center"><a href="https://github.com/Stitch07"><img src="https://avatars0.githubusercontent.com/u/29275227?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Stitch07</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=Stitch07" title="Code">π»</a> <a href="#projectManagement-Stitch07" title="Project Management">π</a> <a href="https://github.com/sapphiredev/utilities/commits?author=Stitch07" title="Tests">β οΈ</a></td>
|
|
@@ -96,7 +96,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
|
|
|
96
96
|
<tr>
|
|
97
97
|
<td align="center"><a href="https://github.com/Nytelife26"><img src="https://avatars1.githubusercontent.com/u/22531310?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Tyler J Russell</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=Nytelife26" title="Documentation">π</a></td>
|
|
98
98
|
<td align="center"><a href="https://github.com/Alcremie"><img src="https://avatars0.githubusercontent.com/u/54785334?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Ivan Lieder</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=Alcremie" title="Code">π»</a> <a href="https://github.com/sapphiredev/utilities/issues?q=author%3AAlcremie" title="Bug reports">π</a></td>
|
|
99
|
-
<td align="center"><a href="https://github.com/RealShadowNova"><img src="https://avatars3.githubusercontent.com/u/46537907?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Hezekiah Hendry</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=RealShadowNova" title="Code">π»</a></td>
|
|
99
|
+
<td align="center"><a href="https://github.com/RealShadowNova"><img src="https://avatars3.githubusercontent.com/u/46537907?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Hezekiah Hendry</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=RealShadowNova" title="Code">π»</a> <a href="#tool-RealShadowNova" title="Tools">π§</a></td>
|
|
100
100
|
<td align="center"><a href="https://github.com/Vetlix"><img src="https://avatars.githubusercontent.com/u/31412314?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Vetlix</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=Vetlix" title="Code">π»</a></td>
|
|
101
101
|
<td align="center"><a href="https://github.com/ethamitc"><img src="https://avatars.githubusercontent.com/u/27776796?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Ethan Mitchell</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=ethamitc" title="Documentation">π</a></td>
|
|
102
102
|
<td align="center"><a href="https://github.com/noftaly"><img src="https://avatars.githubusercontent.com/u/34779161?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Elliot</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=noftaly" title="Code">π»</a></td>
|
|
@@ -127,6 +127,13 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
|
|
|
127
127
|
<td align="center"><a href="https://axis.moe/"><img src="https://avatars.githubusercontent.com/u/54381371?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Jonathan</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=axisiscool" title="Code">π»</a></td>
|
|
128
128
|
<td align="center"><a href="https://github.com/imranbarbhuiya"><img src="https://avatars.githubusercontent.com/u/74945038?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Parbez</b></sub></a><br /><a href="#maintenance-imranbarbhuiya" title="Maintenance">π§</a></td>
|
|
129
129
|
<td align="center"><a href="https://github.com/NotKaskus"><img src="https://avatars.githubusercontent.com/u/75168528?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Paul Andrew</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=NotKaskus" title="Documentation">π</a></td>
|
|
130
|
+
<td align="center"><a href="https://linktr.ee/mzato0001"><img src="https://avatars.githubusercontent.com/u/62367547?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Mzato</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=Mzato0001" title="Code">π»</a> <a href="https://github.com/sapphiredev/utilities/issues?q=author%3AMzato0001" title="Bug reports">π</a></td>
|
|
131
|
+
</tr>
|
|
132
|
+
<tr>
|
|
133
|
+
<td align="center"><a href="https://github.com/MajesticString"><img src="https://avatars.githubusercontent.com/u/66224939?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Harry Allen</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=MajesticString" title="Documentation">π</a></td>
|
|
134
|
+
<td align="center"><a href="https://github.com/EvolutionX-10"><img src="https://avatars.githubusercontent.com/u/85353424?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Evo</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=EvolutionX-10" title="Code">π»</a></td>
|
|
135
|
+
<td align="center"><a href="https://enes.ovh/"><img src="https://avatars.githubusercontent.com/u/61084101?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Enes GenΓ§</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=enxg" title="Code">π»</a></td>
|
|
136
|
+
<td align="center"><a href="https://github.com/muchnameless"><img src="https://avatars.githubusercontent.com/u/12682826?v=4?s=100" width="100px;" alt=""/><br /><sub><b>muchnameless</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=muchnameless" title="Code">π»</a></td>
|
|
130
137
|
</tr>
|
|
131
138
|
</table>
|
|
132
139
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,86 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
interface PhishermanOptions {
|
|
2
|
+
apiKey: string;
|
|
3
|
+
}
|
|
4
|
+
interface PhishermanReturnType {
|
|
5
|
+
verifiedPhish: boolean;
|
|
6
|
+
classification: 'malicious' | 'suspicious' | 'safe' | 'unknown';
|
|
7
|
+
}
|
|
8
|
+
declare type CheckReturnType = PhishermanReturnType & {
|
|
9
|
+
isScam: boolean;
|
|
10
|
+
};
|
|
11
|
+
interface PhishermanReportType {
|
|
12
|
+
success: boolean;
|
|
13
|
+
message: string;
|
|
14
|
+
}
|
|
15
|
+
interface PhishermanInfo {
|
|
16
|
+
status: string;
|
|
17
|
+
created: string;
|
|
18
|
+
lastChecked: string;
|
|
19
|
+
verifiedPhish: boolean;
|
|
20
|
+
classification: string;
|
|
21
|
+
firstSeen: string;
|
|
22
|
+
lastSeen: string;
|
|
23
|
+
targetedBrand: string;
|
|
24
|
+
phishCaught: number;
|
|
25
|
+
details: Details;
|
|
26
|
+
}
|
|
27
|
+
interface Details {
|
|
28
|
+
phishTankId: string;
|
|
29
|
+
urlScanId: string;
|
|
30
|
+
websiteScreenshot: string;
|
|
31
|
+
ip_address: string;
|
|
32
|
+
asn: Asn;
|
|
33
|
+
registry: string;
|
|
34
|
+
country: Country;
|
|
35
|
+
}
|
|
36
|
+
interface Asn {
|
|
37
|
+
asn: string;
|
|
38
|
+
asn_name: string;
|
|
39
|
+
route: string;
|
|
40
|
+
}
|
|
41
|
+
interface Country {
|
|
42
|
+
code: string;
|
|
43
|
+
name: string;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Checks if a link is detected as a scam or phishing link by phisherman.
|
|
48
|
+
* @param domain The domain to check.
|
|
49
|
+
* @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}.
|
|
50
|
+
* @since 1.0.0
|
|
51
|
+
*/
|
|
52
|
+
declare function checkDomain(domain: string, apiKey?: string): Promise<{
|
|
53
|
+
isScam: boolean;
|
|
54
|
+
verifiedPhish: boolean;
|
|
55
|
+
classification: "malicious" | "suspicious" | "safe" | "unknown";
|
|
56
|
+
}>;
|
|
57
|
+
/**
|
|
58
|
+
* Report a domain that is confirmed to be a scam or phishing domain to phisherman, to enhance their API.
|
|
59
|
+
* @param domain The domain to report.
|
|
60
|
+
* @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}.
|
|
61
|
+
* @since 1.0.0
|
|
62
|
+
*/
|
|
63
|
+
declare function reportDomain(domain: string, apiKey?: string): Promise<PhishermanReportType>;
|
|
64
|
+
/**
|
|
65
|
+
* Returns information for a domain.
|
|
66
|
+
* @param domain The domain to get info about.
|
|
67
|
+
* @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}.
|
|
68
|
+
* @since 1.1.0
|
|
69
|
+
*/
|
|
70
|
+
declare function getDomainInfo(domain: string, apiKey?: string): Promise<PhishermanInfo>;
|
|
71
|
+
/**
|
|
72
|
+
* Report a caught phish back to phisherman to improve their analytics.
|
|
73
|
+
* @param domain The domain which was caught.
|
|
74
|
+
* @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}.
|
|
75
|
+
* @param guildId The id of the guild in which the domain was caught.
|
|
76
|
+
* @since 1.1.0
|
|
77
|
+
*/
|
|
78
|
+
declare function reportCaughtPhish(domain: string, apiKey?: string, guildId?: string | number): Promise<PhishermanReportType>;
|
|
79
|
+
/**
|
|
80
|
+
* Set the phisherman's API key.
|
|
81
|
+
* @param key The API key to access the phisherman API and cache within the code of the wrapper.
|
|
82
|
+
* @since 1.0.0
|
|
83
|
+
*/
|
|
84
|
+
declare function setApiKey(key: string): Promise<void>;
|
|
85
|
+
|
|
86
|
+
export { CheckReturnType, PhishermanOptions, PhishermanReportType, PhishermanReturnType, checkDomain, getDomainInfo, reportCaughtPhish, reportDomain, setApiKey };
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
"use strict";
|
|
2
3
|
var __create = Object.create;
|
|
3
4
|
var __defProp = Object.defineProperty;
|
|
4
5
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
@@ -18,7 +19,10 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
19
|
}
|
|
19
20
|
return to;
|
|
20
21
|
};
|
|
21
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
22
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
23
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
24
|
+
mod
|
|
25
|
+
));
|
|
22
26
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
23
27
|
|
|
24
28
|
// src/index.ts
|
|
@@ -39,13 +43,17 @@ var agent = `Sapphire Phisherman/1.0.0 (node-fetch) ${import_node_os.default.pla
|
|
|
39
43
|
var storedApiKey;
|
|
40
44
|
async function checkDomain(domain, apiKey = storedApiKey) {
|
|
41
45
|
validateUrl(domain);
|
|
42
|
-
const result = await (0, import_fetch.fetch)(
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
46
|
+
const result = await (0, import_fetch.fetch)(
|
|
47
|
+
`https://api.phisherman.gg/v2/domains/check/${domain}`,
|
|
48
|
+
{
|
|
49
|
+
headers: {
|
|
50
|
+
"Content-Type": "application/json",
|
|
51
|
+
"User-Agent": agent,
|
|
52
|
+
Authorization: `Bearer ${apiKey}`
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
import_fetch.FetchResultTypes.JSON
|
|
56
|
+
);
|
|
49
57
|
return {
|
|
50
58
|
...result,
|
|
51
59
|
isScam: result.classification === "safe" || result.classification === "unknown" ? false : true
|
|
@@ -54,43 +62,55 @@ async function checkDomain(domain, apiKey = storedApiKey) {
|
|
|
54
62
|
__name(checkDomain, "checkDomain");
|
|
55
63
|
function reportDomain(domain, apiKey = storedApiKey) {
|
|
56
64
|
validateUrl(domain);
|
|
57
|
-
return (0, import_fetch.fetch)(
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
65
|
+
return (0, import_fetch.fetch)(
|
|
66
|
+
`https://api.phisherman.gg/v2/phish/report`,
|
|
67
|
+
{
|
|
68
|
+
method: import_fetch.FetchMethods.Put,
|
|
69
|
+
headers: {
|
|
70
|
+
"Content-Type": "application/json",
|
|
71
|
+
"User-Agent": agent,
|
|
72
|
+
Authorization: `Bearer ${apiKey}`
|
|
73
|
+
},
|
|
74
|
+
body: JSON.stringify({
|
|
75
|
+
url: domain
|
|
76
|
+
})
|
|
63
77
|
},
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
})
|
|
67
|
-
}, import_fetch.FetchResultTypes.JSON);
|
|
78
|
+
import_fetch.FetchResultTypes.JSON
|
|
79
|
+
);
|
|
68
80
|
}
|
|
69
81
|
__name(reportDomain, "reportDomain");
|
|
70
82
|
async function getDomainInfo(domain, apiKey = storedApiKey) {
|
|
71
83
|
validateUrl(domain);
|
|
72
|
-
const result = await (0, import_fetch.fetch)(
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
84
|
+
const result = await (0, import_fetch.fetch)(
|
|
85
|
+
`https://api.phisherman.gg/v2/domains/info/${domain}`,
|
|
86
|
+
{
|
|
87
|
+
headers: {
|
|
88
|
+
"Content-Type": "application/json",
|
|
89
|
+
"User-Agent": agent,
|
|
90
|
+
Authorization: `Bearer ${apiKey}`
|
|
91
|
+
}
|
|
92
|
+
},
|
|
93
|
+
import_fetch.FetchResultTypes.JSON
|
|
94
|
+
);
|
|
79
95
|
return result[domain];
|
|
80
96
|
}
|
|
81
97
|
__name(getDomainInfo, "getDomainInfo");
|
|
82
98
|
function reportCaughtPhish(domain, apiKey = storedApiKey, guildId = "") {
|
|
83
|
-
return (0, import_fetch.fetch)(
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
99
|
+
return (0, import_fetch.fetch)(
|
|
100
|
+
`https://api.phisherman.gg/v2/phish/caught/${domain}`,
|
|
101
|
+
{
|
|
102
|
+
method: import_fetch.FetchMethods.Post,
|
|
103
|
+
headers: {
|
|
104
|
+
"Content-Type": "application/json",
|
|
105
|
+
"User-Agent": agent,
|
|
106
|
+
Authorization: `Bearer ${apiKey}`
|
|
107
|
+
},
|
|
108
|
+
body: JSON.stringify({
|
|
109
|
+
guild: Number(guildId)
|
|
110
|
+
})
|
|
89
111
|
},
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
})
|
|
93
|
-
}, import_fetch.FetchResultTypes.JSON);
|
|
112
|
+
import_fetch.FetchResultTypes.JSON
|
|
113
|
+
);
|
|
94
114
|
}
|
|
95
115
|
__name(reportCaughtPhish, "reportCaughtPhish");
|
|
96
116
|
async function setApiKey(key) {
|
|
@@ -100,13 +120,17 @@ async function setApiKey(key) {
|
|
|
100
120
|
__name(setApiKey, "setApiKey");
|
|
101
121
|
async function checkApiKey(apiKey) {
|
|
102
122
|
try {
|
|
103
|
-
await (0, import_fetch.fetch)(
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
123
|
+
await (0, import_fetch.fetch)(
|
|
124
|
+
`https://api.phisherman.gg/v2/domains/check/verified.test.phisherman.gg`,
|
|
125
|
+
{
|
|
126
|
+
headers: {
|
|
127
|
+
"Content-Type": "application/json",
|
|
128
|
+
"User-Agent": agent,
|
|
129
|
+
Authorization: `Bearer ${apiKey}`
|
|
130
|
+
}
|
|
131
|
+
},
|
|
132
|
+
import_fetch.FetchResultTypes.JSON
|
|
133
|
+
);
|
|
110
134
|
} catch (error) {
|
|
111
135
|
const typedError = error;
|
|
112
136
|
if (typedError.code === 401 && typedError.toJSON().message === "missing permissions or invalid API key") {
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/lib/Phisherman.ts"],"sourcesContent":["export * from './lib/Phisherman';\nexport type { CheckReturnType, PhishermanOptions, PhishermanReportType, PhishermanReturnType } from './lib/PhishermanTypes';\n","import { fetch, FetchMethods, FetchResultTypes, QueryError } from '@sapphire/fetch';\nimport type { PhishermanInfoType, PhishermanReportType, PhishermanReturnType } from './PhishermanTypes';\nimport os from 'node:os';\n\nconst agent = `Sapphire Phisherman/1.0.0 (node-fetch) ${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"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/lib/Phisherman.ts"],"sourcesContent":["export * from './lib/Phisherman';\nexport type { CheckReturnType, PhishermanOptions, PhishermanReportType, PhishermanReturnType } from './lib/PhishermanTypes';\n","import { fetch, FetchMethods, FetchResultTypes, QueryError } from '@sapphire/fetch';\nimport type { PhishermanInfoType, PhishermanReportType, PhishermanReturnType } from './PhishermanTypes';\nimport os from 'node:os';\n\nconst agent = `Sapphire Phisherman/1.0.0 (node-fetch) ${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"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,mBAAkE;AAElE,qBAAe;AAEf,IAAM,QAAQ,0CAA0C,eAAAA,QAAG,SAAS,KAAK,eAAAA,QAAG,QAAQ;AAIpF,IAAI;AAQJ,eAAsB,YAAY,QAAgB,SAAiB,cAAc;AAChF,cAAY,MAAM;AAClB,QAAM,SAAS,UAAM;AAAA,IACpB,8CAA8C;AAAA,IAC9C;AAAA,MACC,SAAS;AAAA,QACR,gBAAgB;AAAA,QAChB,cAAc;AAAA,QACd,eAAe,UAAU;AAAA,MAC1B;AAAA,IACD;AAAA,IACA,8BAAiB;AAAA,EAClB;AAEA,SAAO;AAAA,IACN,GAAG;AAAA,IACH,QAAQ,OAAO,mBAAmB,UAAU,OAAO,mBAAmB,YAAY,QAAQ;AAAA,EAC3F;AACD;AAlBsB;AA0Bf,SAAS,aAAa,QAAgB,SAAiB,cAAc;AAC3E,cAAY,MAAM;AAClB,aAAO;AAAA,IACN;AAAA,IACA;AAAA,MACC,QAAQ,0BAAa;AAAA,MACrB,SAAS;AAAA,QACR,gBAAgB;AAAA,QAChB,cAAc;AAAA,QACd,eAAe,UAAU;AAAA,MAC1B;AAAA,MACA,MAAM,KAAK,UAAU;AAAA,QACpB,KAAK;AAAA,MACN,CAAC;AAAA,IACF;AAAA,IACA,8BAAiB;AAAA,EAClB;AACD;AAjBgB;AAyBhB,eAAsB,cAAc,QAAgB,SAAiB,cAAc;AAClF,cAAY,MAAM;AAClB,QAAM,SAAS,UAAM;AAAA,IACpB,6CAA6C;AAAA,IAC7C;AAAA,MACC,SAAS;AAAA,QACR,gBAAgB;AAAA,QAChB,cAAc;AAAA,QACd,eAAe,UAAU;AAAA,MAC1B;AAAA,IACD;AAAA,IACA,8BAAiB;AAAA,EAClB;AACA,SAAO,OAAO;AACf;AAdsB;AAuBf,SAAS,kBAAkB,QAAgB,SAAiB,cAAc,UAA2B,IAAI;AAC/G,aAAO;AAAA,IACN,6CAA6C;AAAA,IAC7C;AAAA,MACC,QAAQ,0BAAa;AAAA,MACrB,SAAS;AAAA,QACR,gBAAgB;AAAA,QAChB,cAAc;AAAA,QACd,eAAe,UAAU;AAAA,MAC1B;AAAA,MACA,MAAM,KAAK,UAAU;AAAA,QACpB,OAAO,OAAO,OAAO;AAAA,MACtB,CAAC;AAAA,IACF;AAAA,IACA,8BAAiB;AAAA,EAClB;AACD;AAhBgB;AAuBhB,eAAsB,UAAU,KAAa;AAC5C,QAAM,YAAY,GAAG;AACrB,iBAAe;AAChB;AAHsB;AAKtB,eAAe,YAAY,QAAgB;AAC1C,MAAI;AACH,cAAM;AAAA,MACL;AAAA,MACA;AAAA,QACC,SAAS;AAAA,UACR,gBAAgB;AAAA,UAChB,cAAc;AAAA,UACd,eAAe,UAAU;AAAA,QAC1B;AAAA,MACD;AAAA,MACA,8BAAiB;AAAA,IAClB;AAAA,EACD,SAAS,OAAP;AACD,UAAM,aAAa;AAEnB,QAAI,WAAW,SAAS,OAAO,WAAW,OAAO,EAAE,YAAY,0CAA0C;AACxG,YAAM,IAAI,MAAM,gDAAgD;AAAA,IACjE;AAEA,UAAM;AAAA,EACP;AACD;AAtBe;AAwBf,SAAS,YAAY,QAAgB;AACpC,QAAM,SAAS;AACf,MAAI,CAAC,OAAO,MAAM,MAAM;AAAG,UAAM,IAAI,MAAM,+CAA+C;AAC3F;AAHS;","names":["os"]}
|
package/dist/index.mjs
CHANGED
|
@@ -8,13 +8,17 @@ var agent = `Sapphire Phisherman/1.0.0 (node-fetch) ${os.platform()}/${os.releas
|
|
|
8
8
|
var storedApiKey;
|
|
9
9
|
async function checkDomain(domain, apiKey = storedApiKey) {
|
|
10
10
|
validateUrl(domain);
|
|
11
|
-
const result = await fetch(
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
11
|
+
const result = await fetch(
|
|
12
|
+
`https://api.phisherman.gg/v2/domains/check/${domain}`,
|
|
13
|
+
{
|
|
14
|
+
headers: {
|
|
15
|
+
"Content-Type": "application/json",
|
|
16
|
+
"User-Agent": agent,
|
|
17
|
+
Authorization: `Bearer ${apiKey}`
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
FetchResultTypes.JSON
|
|
21
|
+
);
|
|
18
22
|
return {
|
|
19
23
|
...result,
|
|
20
24
|
isScam: result.classification === "safe" || result.classification === "unknown" ? false : true
|
|
@@ -23,43 +27,55 @@ async function checkDomain(domain, apiKey = storedApiKey) {
|
|
|
23
27
|
__name(checkDomain, "checkDomain");
|
|
24
28
|
function reportDomain(domain, apiKey = storedApiKey) {
|
|
25
29
|
validateUrl(domain);
|
|
26
|
-
return fetch(
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
30
|
+
return fetch(
|
|
31
|
+
`https://api.phisherman.gg/v2/phish/report`,
|
|
32
|
+
{
|
|
33
|
+
method: FetchMethods.Put,
|
|
34
|
+
headers: {
|
|
35
|
+
"Content-Type": "application/json",
|
|
36
|
+
"User-Agent": agent,
|
|
37
|
+
Authorization: `Bearer ${apiKey}`
|
|
38
|
+
},
|
|
39
|
+
body: JSON.stringify({
|
|
40
|
+
url: domain
|
|
41
|
+
})
|
|
32
42
|
},
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
})
|
|
36
|
-
}, FetchResultTypes.JSON);
|
|
43
|
+
FetchResultTypes.JSON
|
|
44
|
+
);
|
|
37
45
|
}
|
|
38
46
|
__name(reportDomain, "reportDomain");
|
|
39
47
|
async function getDomainInfo(domain, apiKey = storedApiKey) {
|
|
40
48
|
validateUrl(domain);
|
|
41
|
-
const result = await fetch(
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
49
|
+
const result = await fetch(
|
|
50
|
+
`https://api.phisherman.gg/v2/domains/info/${domain}`,
|
|
51
|
+
{
|
|
52
|
+
headers: {
|
|
53
|
+
"Content-Type": "application/json",
|
|
54
|
+
"User-Agent": agent,
|
|
55
|
+
Authorization: `Bearer ${apiKey}`
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
FetchResultTypes.JSON
|
|
59
|
+
);
|
|
48
60
|
return result[domain];
|
|
49
61
|
}
|
|
50
62
|
__name(getDomainInfo, "getDomainInfo");
|
|
51
63
|
function reportCaughtPhish(domain, apiKey = storedApiKey, guildId = "") {
|
|
52
|
-
return fetch(
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
64
|
+
return fetch(
|
|
65
|
+
`https://api.phisherman.gg/v2/phish/caught/${domain}`,
|
|
66
|
+
{
|
|
67
|
+
method: FetchMethods.Post,
|
|
68
|
+
headers: {
|
|
69
|
+
"Content-Type": "application/json",
|
|
70
|
+
"User-Agent": agent,
|
|
71
|
+
Authorization: `Bearer ${apiKey}`
|
|
72
|
+
},
|
|
73
|
+
body: JSON.stringify({
|
|
74
|
+
guild: Number(guildId)
|
|
75
|
+
})
|
|
58
76
|
},
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
})
|
|
62
|
-
}, FetchResultTypes.JSON);
|
|
77
|
+
FetchResultTypes.JSON
|
|
78
|
+
);
|
|
63
79
|
}
|
|
64
80
|
__name(reportCaughtPhish, "reportCaughtPhish");
|
|
65
81
|
async function setApiKey(key) {
|
|
@@ -69,13 +85,17 @@ async function setApiKey(key) {
|
|
|
69
85
|
__name(setApiKey, "setApiKey");
|
|
70
86
|
async function checkApiKey(apiKey) {
|
|
71
87
|
try {
|
|
72
|
-
await fetch(
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
88
|
+
await fetch(
|
|
89
|
+
`https://api.phisherman.gg/v2/domains/check/verified.test.phisherman.gg`,
|
|
90
|
+
{
|
|
91
|
+
headers: {
|
|
92
|
+
"Content-Type": "application/json",
|
|
93
|
+
"User-Agent": agent,
|
|
94
|
+
Authorization: `Bearer ${apiKey}`
|
|
95
|
+
}
|
|
96
|
+
},
|
|
97
|
+
FetchResultTypes.JSON
|
|
98
|
+
);
|
|
79
99
|
} catch (error) {
|
|
80
100
|
const typedError = error;
|
|
81
101
|
if (typedError.code === 401 && typedError.toJSON().message === "missing permissions or invalid API key") {
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/lib/Phisherman.ts"],"sourcesContent":["import { fetch, FetchMethods, FetchResultTypes, QueryError } from '@sapphire/fetch';\nimport type { PhishermanInfoType, PhishermanReportType, PhishermanReturnType } from './PhishermanTypes';\nimport os from 'node:os';\n\nconst agent = `Sapphire Phisherman/1.0.0 (node-fetch) ${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"],"mappings":";;;;AAAA;
|
|
1
|
+
{"version":3,"sources":["../src/lib/Phisherman.ts"],"sourcesContent":["import { fetch, FetchMethods, FetchResultTypes, QueryError } from '@sapphire/fetch';\nimport type { PhishermanInfoType, PhishermanReportType, PhishermanReturnType } from './PhishermanTypes';\nimport os from 'node:os';\n\nconst agent = `Sapphire Phisherman/1.0.0 (node-fetch) ${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"],"mappings":";;;;AAAA,SAAS,OAAO,cAAc,wBAAoC;AAElE,OAAO,QAAQ;AAEf,IAAM,QAAQ,0CAA0C,GAAG,SAAS,KAAK,GAAG,QAAQ;AAIpF,IAAI;AAQJ,eAAsB,YAAY,QAAgB,SAAiB,cAAc;AAChF,cAAY,MAAM;AAClB,QAAM,SAAS,MAAM;AAAA,IACpB,8CAA8C;AAAA,IAC9C;AAAA,MACC,SAAS;AAAA,QACR,gBAAgB;AAAA,QAChB,cAAc;AAAA,QACd,eAAe,UAAU;AAAA,MAC1B;AAAA,IACD;AAAA,IACA,iBAAiB;AAAA,EAClB;AAEA,SAAO;AAAA,IACN,GAAG;AAAA,IACH,QAAQ,OAAO,mBAAmB,UAAU,OAAO,mBAAmB,YAAY,QAAQ;AAAA,EAC3F;AACD;AAlBsB;AA0Bf,SAAS,aAAa,QAAgB,SAAiB,cAAc;AAC3E,cAAY,MAAM;AAClB,SAAO;AAAA,IACN;AAAA,IACA;AAAA,MACC,QAAQ,aAAa;AAAA,MACrB,SAAS;AAAA,QACR,gBAAgB;AAAA,QAChB,cAAc;AAAA,QACd,eAAe,UAAU;AAAA,MAC1B;AAAA,MACA,MAAM,KAAK,UAAU;AAAA,QACpB,KAAK;AAAA,MACN,CAAC;AAAA,IACF;AAAA,IACA,iBAAiB;AAAA,EAClB;AACD;AAjBgB;AAyBhB,eAAsB,cAAc,QAAgB,SAAiB,cAAc;AAClF,cAAY,MAAM;AAClB,QAAM,SAAS,MAAM;AAAA,IACpB,6CAA6C;AAAA,IAC7C;AAAA,MACC,SAAS;AAAA,QACR,gBAAgB;AAAA,QAChB,cAAc;AAAA,QACd,eAAe,UAAU;AAAA,MAC1B;AAAA,IACD;AAAA,IACA,iBAAiB;AAAA,EAClB;AACA,SAAO,OAAO;AACf;AAdsB;AAuBf,SAAS,kBAAkB,QAAgB,SAAiB,cAAc,UAA2B,IAAI;AAC/G,SAAO;AAAA,IACN,6CAA6C;AAAA,IAC7C;AAAA,MACC,QAAQ,aAAa;AAAA,MACrB,SAAS;AAAA,QACR,gBAAgB;AAAA,QAChB,cAAc;AAAA,QACd,eAAe,UAAU;AAAA,MAC1B;AAAA,MACA,MAAM,KAAK,UAAU;AAAA,QACpB,OAAO,OAAO,OAAO;AAAA,MACtB,CAAC;AAAA,IACF;AAAA,IACA,iBAAiB;AAAA,EAClB;AACD;AAhBgB;AAuBhB,eAAsB,UAAU,KAAa;AAC5C,QAAM,YAAY,GAAG;AACrB,iBAAe;AAChB;AAHsB;AAKtB,eAAe,YAAY,QAAgB;AAC1C,MAAI;AACH,UAAM;AAAA,MACL;AAAA,MACA;AAAA,QACC,SAAS;AAAA,UACR,gBAAgB;AAAA,UAChB,cAAc;AAAA,UACd,eAAe,UAAU;AAAA,QAC1B;AAAA,MACD;AAAA,MACA,iBAAiB;AAAA,IAClB;AAAA,EACD,SAAS,OAAP;AACD,UAAM,aAAa;AAEnB,QAAI,WAAW,SAAS,OAAO,WAAW,OAAO,EAAE,YAAY,0CAA0C;AACxG,YAAM,IAAI,MAAM,gDAAgD;AAAA,IACjE;AAEA,UAAM;AAAA,EACP;AACD;AAtBe;AAwBf,SAAS,YAAY,QAAgB;AACpC,QAAM,SAAS;AACf,MAAI,CAAC,OAAO,MAAM,MAAM;AAAG,UAAM,IAAI,MAAM,+CAA+C;AAC3F;AAHS;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sapphire/phisherman",
|
|
3
|
-
"version": "1.4.2-next.
|
|
3
|
+
"version": "1.4.2-next.78a79ca.0",
|
|
4
4
|
"description": "Wrapper around phisherman to easily check and report domains",
|
|
5
5
|
"author": "@sapphire",
|
|
6
6
|
"license": "MIT",
|
|
@@ -15,13 +15,14 @@
|
|
|
15
15
|
"homepage": "https://github.com/sapphiredev/utilities/tree/main/packages/phisherman",
|
|
16
16
|
"scripts": {
|
|
17
17
|
"lint": "eslint src --ext ts --fix",
|
|
18
|
-
"build": "tsup
|
|
18
|
+
"build": "tsup",
|
|
19
|
+
"docs": "typedoc-json-parser",
|
|
19
20
|
"prepack": "yarn build",
|
|
20
21
|
"bump": "cliff-jumper",
|
|
21
22
|
"check-update": "cliff-jumper --dry-run"
|
|
22
23
|
},
|
|
23
24
|
"dependencies": {
|
|
24
|
-
"@sapphire/fetch": "^2.
|
|
25
|
+
"@sapphire/fetch": "^2.4.2-next.78a79ca.0"
|
|
25
26
|
},
|
|
26
27
|
"repository": {
|
|
27
28
|
"type": "git",
|
|
@@ -56,7 +57,10 @@
|
|
|
56
57
|
"access": "public"
|
|
57
58
|
},
|
|
58
59
|
"devDependencies": {
|
|
59
|
-
"
|
|
60
|
-
"
|
|
60
|
+
"@favware/cliff-jumper": "^1.8.7",
|
|
61
|
+
"tsup": "^6.2.3",
|
|
62
|
+
"typedoc": "^0.23.14",
|
|
63
|
+
"typedoc-json-parser": "^4.0.0",
|
|
64
|
+
"typescript": "^4.8.3"
|
|
61
65
|
}
|
|
62
66
|
}
|
package/dist/lib/Phisherman.d.ts
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import type { PhishermanReportType } from './PhishermanTypes';
|
|
2
|
-
/**
|
|
3
|
-
* Checks if a link is detected as a scam or phishing link by phisherman.
|
|
4
|
-
* @param domain The domain to check.
|
|
5
|
-
* @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}.
|
|
6
|
-
* @since 1.0.0
|
|
7
|
-
*/
|
|
8
|
-
export declare function checkDomain(domain: string, apiKey?: string): Promise<{
|
|
9
|
-
isScam: boolean;
|
|
10
|
-
verifiedPhish: boolean;
|
|
11
|
-
classification: "malicious" | "suspicious" | "safe" | "unknown";
|
|
12
|
-
}>;
|
|
13
|
-
/**
|
|
14
|
-
* Report a domain that is confirmed to be a scam or phishing domain to phisherman, to enhance their API.
|
|
15
|
-
* @param domain The domain to report.
|
|
16
|
-
* @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}.
|
|
17
|
-
* @since 1.0.0
|
|
18
|
-
*/
|
|
19
|
-
export declare function reportDomain(domain: string, apiKey?: string): Promise<PhishermanReportType>;
|
|
20
|
-
/**
|
|
21
|
-
* Returns information for a domain.
|
|
22
|
-
* @param domain The domain to get info about.
|
|
23
|
-
* @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}.
|
|
24
|
-
* @since 1.1.0
|
|
25
|
-
*/
|
|
26
|
-
export declare function getDomainInfo(domain: string, apiKey?: string): Promise<import("./PhishermanTypes").PhishermanInfo>;
|
|
27
|
-
/**
|
|
28
|
-
* Report a caught phish back to phisherman to improve their analytics.
|
|
29
|
-
* @param domain The domain which was caught.
|
|
30
|
-
* @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}.
|
|
31
|
-
* @param guildId The id of the guild in which the domain was caught.
|
|
32
|
-
* @since 1.1.0
|
|
33
|
-
*/
|
|
34
|
-
export declare function reportCaughtPhish(domain: string, apiKey?: string, guildId?: string | number): Promise<PhishermanReportType>;
|
|
35
|
-
/**
|
|
36
|
-
* Set the phisherman's API key.
|
|
37
|
-
* @param key The API key to access the phisherman API and cache within the code of the wrapper.
|
|
38
|
-
* @since 1.0.0
|
|
39
|
-
*/
|
|
40
|
-
export declare function setApiKey(key: string): Promise<void>;
|
|
41
|
-
//# sourceMappingURL=Phisherman.d.ts.map
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
export interface PhishermanOptions {
|
|
2
|
-
apiKey: string;
|
|
3
|
-
}
|
|
4
|
-
export interface PhishermanReturnType {
|
|
5
|
-
verifiedPhish: boolean;
|
|
6
|
-
classification: 'malicious' | 'suspicious' | 'safe' | 'unknown';
|
|
7
|
-
}
|
|
8
|
-
export declare type CheckReturnType = PhishermanReturnType & {
|
|
9
|
-
isScam: boolean;
|
|
10
|
-
};
|
|
11
|
-
export interface PhishermanReportType {
|
|
12
|
-
success: boolean;
|
|
13
|
-
message: string;
|
|
14
|
-
}
|
|
15
|
-
export interface PhishermanInfo {
|
|
16
|
-
status: string;
|
|
17
|
-
created: string;
|
|
18
|
-
lastChecked: string;
|
|
19
|
-
verifiedPhish: boolean;
|
|
20
|
-
classification: string;
|
|
21
|
-
firstSeen: string;
|
|
22
|
-
lastSeen: string;
|
|
23
|
-
targetedBrand: string;
|
|
24
|
-
phishCaught: number;
|
|
25
|
-
details: Details;
|
|
26
|
-
}
|
|
27
|
-
export interface PhishermanInfoType {
|
|
28
|
-
[key: string]: PhishermanInfo;
|
|
29
|
-
}
|
|
30
|
-
interface Details {
|
|
31
|
-
phishTankId: string;
|
|
32
|
-
urlScanId: string;
|
|
33
|
-
websiteScreenshot: string;
|
|
34
|
-
ip_address: string;
|
|
35
|
-
asn: Asn;
|
|
36
|
-
registry: string;
|
|
37
|
-
country: Country;
|
|
38
|
-
}
|
|
39
|
-
interface Asn {
|
|
40
|
-
asn: string;
|
|
41
|
-
asn_name: string;
|
|
42
|
-
route: string;
|
|
43
|
-
}
|
|
44
|
-
interface Country {
|
|
45
|
-
code: string;
|
|
46
|
-
name: string;
|
|
47
|
-
}
|
|
48
|
-
export {};
|
|
49
|
-
//# sourceMappingURL=PhishermanTypes.d.ts.map
|