@sapphire/phisherman 1.4.2-next.76e95b3.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 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>Antonio 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>
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>
package/dist/index.d.ts CHANGED
@@ -1,3 +1,86 @@
1
- export * from './lib/Phisherman';
2
- export type { CheckReturnType, PhishermanOptions, PhishermanReportType, PhishermanReturnType } from './lib/PhishermanTypes';
3
- //# sourceMappingURL=index.d.ts.map
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
@@ -19,7 +19,10 @@ var __copyProps = (to, from, except, desc) => {
19
19
  }
20
20
  return to;
21
21
  };
22
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
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
+ ));
23
26
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
24
27
 
25
28
  // src/index.ts
@@ -40,13 +43,17 @@ var agent = `Sapphire Phisherman/1.0.0 (node-fetch) ${import_node_os.default.pla
40
43
  var storedApiKey;
41
44
  async function checkDomain(domain, apiKey = storedApiKey) {
42
45
  validateUrl(domain);
43
- const result = await (0, import_fetch.fetch)(`https://api.phisherman.gg/v2/domains/check/${domain}`, {
44
- headers: {
45
- "Content-Type": "application/json",
46
- "User-Agent": agent,
47
- Authorization: `Bearer ${apiKey}`
48
- }
49
- }, import_fetch.FetchResultTypes.JSON);
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
+ );
50
57
  return {
51
58
  ...result,
52
59
  isScam: result.classification === "safe" || result.classification === "unknown" ? false : true
@@ -55,43 +62,55 @@ async function checkDomain(domain, apiKey = storedApiKey) {
55
62
  __name(checkDomain, "checkDomain");
56
63
  function reportDomain(domain, apiKey = storedApiKey) {
57
64
  validateUrl(domain);
58
- return (0, import_fetch.fetch)(`https://api.phisherman.gg/v2/phish/report`, {
59
- method: import_fetch.FetchMethods.Put,
60
- headers: {
61
- "Content-Type": "application/json",
62
- "User-Agent": agent,
63
- Authorization: `Bearer ${apiKey}`
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
+ })
64
77
  },
65
- body: JSON.stringify({
66
- url: domain
67
- })
68
- }, import_fetch.FetchResultTypes.JSON);
78
+ import_fetch.FetchResultTypes.JSON
79
+ );
69
80
  }
70
81
  __name(reportDomain, "reportDomain");
71
82
  async function getDomainInfo(domain, apiKey = storedApiKey) {
72
83
  validateUrl(domain);
73
- const result = await (0, import_fetch.fetch)(`https://api.phisherman.gg/v2/domains/info/${domain}`, {
74
- headers: {
75
- "Content-Type": "application/json",
76
- "User-Agent": agent,
77
- Authorization: `Bearer ${apiKey}`
78
- }
79
- }, import_fetch.FetchResultTypes.JSON);
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
+ );
80
95
  return result[domain];
81
96
  }
82
97
  __name(getDomainInfo, "getDomainInfo");
83
98
  function reportCaughtPhish(domain, apiKey = storedApiKey, guildId = "") {
84
- return (0, import_fetch.fetch)(`https://api.phisherman.gg/v2/phish/caught/${domain}`, {
85
- method: import_fetch.FetchMethods.Post,
86
- headers: {
87
- "Content-Type": "application/json",
88
- "User-Agent": agent,
89
- Authorization: `Bearer ${apiKey}`
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
+ })
90
111
  },
91
- body: JSON.stringify({
92
- guild: Number(guildId)
93
- })
94
- }, import_fetch.FetchResultTypes.JSON);
112
+ import_fetch.FetchResultTypes.JSON
113
+ );
95
114
  }
96
115
  __name(reportCaughtPhish, "reportCaughtPhish");
97
116
  async function setApiKey(key) {
@@ -101,13 +120,17 @@ async function setApiKey(key) {
101
120
  __name(setApiKey, "setApiKey");
102
121
  async function checkApiKey(apiKey) {
103
122
  try {
104
- await (0, import_fetch.fetch)(`https://api.phisherman.gg/v2/domains/check/verified.test.phisherman.gg`, {
105
- headers: {
106
- "Content-Type": "application/json",
107
- "User-Agent": agent,
108
- Authorization: `Bearer ${apiKey}`
109
- }
110
- }, import_fetch.FetchResultTypes.JSON);
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
+ );
111
134
  } catch (error) {
112
135
  const typedError = error;
113
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":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;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A,IACA,MAAM,KAAK,UAAU;AAAA,MACpB,OAAO,OAAO,OAAO;AAAA,IACtB,CAAC;AAAA,EACF,GACA,8BAAiB,IAClB;AACD;AAhBgB;AAuBhB,yBAAgC,KAAa;AAC5C,QAAM,YAAY,GAAG;AACrB,iBAAe;AAChB;AAHsB;AAKtB,2BAA2B,QAAgB;AAC1C,MAAI;AACH,UAAM,wBACL,0EACA;AAAA,MACC,SAAS;AAAA,QACR,gBAAgB;AAAA,QAChB,cAAc;AAAA,QACd,eAAe,UAAU;AAAA,MAC1B;AAAA,IACD,GACA,8BAAiB,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,qBAAqB,QAAgB;AACpC,QAAM,SAAS;AACf,MAAI,CAAC,OAAO,MAAM,MAAM;AAAG,UAAM,IAAI,MAAM,+CAA+C;AAC3F;AAHS;","names":[]}
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 regex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;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(`https://api.phisherman.gg/v2/domains/check/${domain}`, {
12
- headers: {
13
- "Content-Type": "application/json",
14
- "User-Agent": agent,
15
- Authorization: `Bearer ${apiKey}`
16
- }
17
- }, FetchResultTypes.JSON);
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(`https://api.phisherman.gg/v2/phish/report`, {
27
- method: FetchMethods.Put,
28
- headers: {
29
- "Content-Type": "application/json",
30
- "User-Agent": agent,
31
- Authorization: `Bearer ${apiKey}`
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
- body: JSON.stringify({
34
- url: domain
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(`https://api.phisherman.gg/v2/domains/info/${domain}`, {
42
- headers: {
43
- "Content-Type": "application/json",
44
- "User-Agent": agent,
45
- Authorization: `Bearer ${apiKey}`
46
- }
47
- }, FetchResultTypes.JSON);
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(`https://api.phisherman.gg/v2/phish/caught/${domain}`, {
53
- method: FetchMethods.Post,
54
- headers: {
55
- "Content-Type": "application/json",
56
- "User-Agent": agent,
57
- Authorization: `Bearer ${apiKey}`
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
- body: JSON.stringify({
60
- guild: Number(guildId)
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(`https://api.phisherman.gg/v2/domains/check/verified.test.phisherman.gg`, {
73
- headers: {
74
- "Content-Type": "application/json",
75
- "User-Agent": agent,
76
- Authorization: `Bearer ${apiKey}`
77
- }
78
- }, FetchResultTypes.JSON);
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") {
@@ -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;AAEA;AAEA,IAAM,QAAQ,0CAA0C,GAAG,SAAS,KAAK,GAAG,QAAQ;AAIpF,IAAI;AAQJ,2BAAkC,QAAgB,SAAiB,cAAc;AAChF,cAAY,MAAM;AAClB,QAAM,SAAS,MAAM,MACpB,8CAA8C,UAC9C;AAAA,IACC,SAAS;AAAA,MACR,gBAAgB;AAAA,MAChB,cAAc;AAAA,MACd,eAAe,UAAU;AAAA,IAC1B;AAAA,EACD,GACA,iBAAiB,IAClB;AAEA,SAAO;AAAA,IACN,GAAG;AAAA,IACH,QAAQ,OAAO,mBAAmB,UAAU,OAAO,mBAAmB,YAAY,QAAQ;AAAA,EAC3F;AACD;AAlBsB;AA0Bf,sBAAsB,QAAgB,SAAiB,cAAc;AAC3E,cAAY,MAAM;AAClB,SAAO,MACN,6CACA;AAAA,IACC,QAAQ,aAAa;AAAA,IACrB,SAAS;AAAA,MAC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C,OAAO,MAAM,MAAM;AAAG,UAAM,IAAI,MAAM,+CAA+C;AAC3F;AAHS;","names":[]}
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,SAA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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.76e95b3.0",
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 && tsc -b src",
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.4.2-next.76e95b3.0"
25
+ "@sapphire/fetch": "^2.4.2-next.78a79ca.0"
25
26
  },
26
27
  "repository": {
27
28
  "type": "git",
@@ -56,8 +57,10 @@
56
57
  "access": "public"
57
58
  },
58
59
  "devDependencies": {
59
- "@favware/cliff-jumper": "^1.8.6",
60
- "tsup": "^6.2.1",
61
- "typescript": "^4.7.4"
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"
62
65
  }
63
66
  }
@@ -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