@sapphire/phisherman 1.1.0 → 1.2.0-next.365a53a.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
@@ -115,6 +115,10 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
115
115
  <td align="center"><a href="https://gitlab.com/DavidPH/"><img src="https://avatars.githubusercontent.com/u/44669930?v=4?s=100" width="100px;" alt=""/><br /><sub><b>David</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=DavidPHH" title="Code">💻</a></td>
116
116
  <td align="center"><a href="https://github.com/apps/renovate"><img src="https://avatars.githubusercontent.com/in/2740?v=4?s=100" width="100px;" alt=""/><br /><sub><b>renovate[bot]</b></sub></a><br /><a href="#maintenance-renovate[bot]" title="Maintenance">🚧</a></td>
117
117
  <td align="center"><a href="https://renovate.whitesourcesoftware.com/"><img src="https://avatars.githubusercontent.com/u/25180681?v=4?s=100" width="100px;" alt=""/><br /><sub><b>WhiteSource Renovate</b></sub></a><br /><a href="#maintenance-renovate-bot" title="Maintenance">🚧</a></td>
118
+ <td align="center"><a href="https://fc5570.me/"><img src="https://avatars.githubusercontent.com/u/68158483?v=4?s=100" width="100px;" alt=""/><br /><sub><b>FC</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=FC5570" title="Code">💻</a></td>
119
+ <td align="center"><a href="https://github.com/Tokipudi"><img src="https://avatars.githubusercontent.com/u/29551076?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Jérémy de Saint Denis</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=Tokipudi" title="Code">💻</a></td>
120
+ <td align="center"><a href="https://github.com/ItsMrCube"><img src="https://avatars.githubusercontent.com/u/25201357?v=4?s=100" width="100px;" alt=""/><br /><sub><b>MrCube</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=ItsMrCube" title="Code">💻</a></td>
121
+ <td align="center"><a href="https://github.com/bitomic"><img src="https://avatars.githubusercontent.com/u/35199700?v=4?s=100" width="100px;" alt=""/><br /><sub><b>bitomic</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=bitomic" title="Code">💻</a></td>
118
122
  </tr>
119
123
  </table>
120
124
 
package/dist/index.js CHANGED
@@ -1,5 +1,131 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
- (0, tslib_1.__exportStar)(require("./lib/Phisherman"), exports);
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
9
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
10
+ var __export = (target, all) => {
11
+ for (var name in all)
12
+ __defProp(target, name, { get: all[name], enumerable: true });
13
+ };
14
+ var __reExport = (target, module2, copyDefault, desc) => {
15
+ if (module2 && typeof module2 === "object" || typeof module2 === "function") {
16
+ for (let key of __getOwnPropNames(module2))
17
+ if (!__hasOwnProp.call(target, key) && (copyDefault || key !== "default"))
18
+ __defProp(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable });
19
+ }
20
+ return target;
21
+ };
22
+ var __toESM = (module2, isNodeMode) => {
23
+ return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", !isNodeMode && module2 && module2.__esModule ? { get: () => module2.default, enumerable: true } : { value: module2, enumerable: true })), module2);
24
+ };
25
+ var __toCommonJS = /* @__PURE__ */ ((cache) => {
26
+ return (module2, temp) => {
27
+ return cache && cache.get(module2) || (temp = __reExport(__markAsModule({}), module2, 1), cache && cache.set(module2, temp), temp);
28
+ };
29
+ })(typeof WeakMap !== "undefined" ? /* @__PURE__ */ new WeakMap() : 0);
30
+
31
+ // src/index.ts
32
+ var src_exports = {};
33
+ __export(src_exports, {
34
+ checkDomain: () => checkDomain,
35
+ getDomainInfo: () => getDomainInfo,
36
+ reportCaughtPhish: () => reportCaughtPhish,
37
+ reportDomain: () => reportDomain,
38
+ setApiKey: () => setApiKey
39
+ });
40
+
41
+ // src/lib/Phisherman.ts
42
+ var import_fetch = require("@sapphire/fetch");
43
+ var import_node_os = __toESM(require("os"));
44
+ var agent = `Sapphire Phisherman/1.0.0 (node-fetch) ${import_node_os.default.platform()}/${import_node_os.default.release()} (https://github.com/sapphiredev/utilities/tree/main/packages/phisherman)`;
45
+ var storedApiKey;
46
+ async function checkDomain(domain, apiKey = storedApiKey) {
47
+ const result = await (0, import_fetch.fetch)(`https://api.phisherman.gg/v2/domains/check/${domain}`, {
48
+ headers: {
49
+ "Content-Type": "application/json",
50
+ "User-Agent": agent,
51
+ Authorization: `Bearer ${apiKey}`
52
+ }
53
+ }, import_fetch.FetchResultTypes.JSON);
54
+ return {
55
+ ...result,
56
+ isScam: result.classification === "safe" || result.classification === "unknown" ? false : true
57
+ };
58
+ }
59
+ __name(checkDomain, "checkDomain");
60
+ function reportDomain(domain, apiKey = storedApiKey) {
61
+ return (0, import_fetch.fetch)(`https://api.phisherman.gg/v2/phish/report`, {
62
+ method: import_fetch.FetchMethods.Put,
63
+ headers: {
64
+ "Content-Type": "application/json",
65
+ "User-Agent": agent,
66
+ Authorization: `Bearer ${apiKey}`
67
+ },
68
+ body: JSON.stringify({
69
+ url: domain
70
+ })
71
+ }, import_fetch.FetchResultTypes.JSON);
72
+ }
73
+ __name(reportDomain, "reportDomain");
74
+ async function getDomainInfo(domain, apiKey = storedApiKey) {
75
+ const result = await (0, import_fetch.fetch)(`https://api.phisherman.gg/v2/domains/info/${domain}`, {
76
+ headers: {
77
+ "Content-Type": "application/json",
78
+ "User-Agent": ``,
79
+ Authorization: `Bearer ${apiKey}`
80
+ }
81
+ }, import_fetch.FetchResultTypes.JSON);
82
+ return result[domain];
83
+ }
84
+ __name(getDomainInfo, "getDomainInfo");
85
+ function reportCaughtPhish(domain, apiKey = storedApiKey, guildId = "") {
86
+ return (0, import_fetch.fetch)(`https://api.phisherman.gg/v2/phish/caught/${domain}`, {
87
+ method: import_fetch.FetchMethods.Post,
88
+ headers: {
89
+ "Content-Type": "application/json",
90
+ "User-Agent": agent,
91
+ Authorization: `Bearer ${apiKey}`
92
+ },
93
+ body: JSON.stringify({
94
+ guild: Number(guildId)
95
+ })
96
+ }, import_fetch.FetchResultTypes.JSON);
97
+ }
98
+ __name(reportCaughtPhish, "reportCaughtPhish");
99
+ async function setApiKey(key) {
100
+ await checkApiKey(key);
101
+ storedApiKey = key;
102
+ }
103
+ __name(setApiKey, "setApiKey");
104
+ async function checkApiKey(apiKey) {
105
+ try {
106
+ await (0, import_fetch.fetch)(`https://api.phisherman.gg/v2/domains/check/verified.test.phisherman.gg`, {
107
+ headers: {
108
+ "Content-Type": "application/json",
109
+ "User-Agent": agent,
110
+ Authorization: `Bearer ${apiKey}`
111
+ }
112
+ }, import_fetch.FetchResultTypes.JSON);
113
+ } catch (error) {
114
+ const typedError = error;
115
+ if (typedError.code === 401 && typedError.toJSON().message === "missing permissions or invalid API key") {
116
+ throw new Error("[SapphirePhisherman]: Invalid API key provided");
117
+ }
118
+ throw error;
119
+ }
120
+ }
121
+ __name(checkApiKey, "checkApiKey");
122
+ module.exports = __toCommonJS(src_exports);
123
+ // Annotate the CommonJS export names for ESM import in node:
124
+ 0 && (module.exports = {
125
+ checkDomain,
126
+ getDomainInfo,
127
+ reportCaughtPhish,
128
+ reportDomain,
129
+ setApiKey
130
+ });
5
131
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,gEAAiC"}
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\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\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\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': ``,\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"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,mBAAkE;AAElE,qBAAe;AAEf,IAAM,QAAQ,0CAA0C,uBAAG,cAAc,uBAAG;AAI5E,IAAI;AAQJ,2BAAkC,QAAgB,SAAiB,cAAc;AAChF,QAAM,SAAS,MAAM,wBACpB,8CAA8C,UAC9C;AAAA,IACC,SAAS;AAAA,MACR,gBAAgB;AAAA,MAChB,cAAc;AAAA,MACd,eAAe,UAAU;AAAA;AAAA,KAG3B,8BAAiB;AAGlB,SAAO;AAAA,OACH;AAAA,IACH,QAAQ,OAAO,mBAAmB,UAAU,OAAO,mBAAmB,YAAY,QAAQ;AAAA;AAAA;AAftE;AAyBf,sBAAsB,QAAgB,SAAiB,cAAc;AAC3E,SAAO,wBACN,6CACA;AAAA,IACC,QAAQ,0BAAa;AAAA,IACrB,SAAS;AAAA,MACR,gBAAgB;AAAA,MAChB,cAAc;AAAA,MACd,eAAe,UAAU;AAAA;AAAA,IAE1B,MAAM,KAAK,UAAU;AAAA,MACpB,KAAK;AAAA;AAAA,KAGP,8BAAiB;AAAA;AAdH;AAwBhB,6BAAoC,QAAgB,SAAiB,cAAc;AAClF,QAAM,SAAS,MAAM,wBACpB,6CAA6C,UAC7C;AAAA,IACC,SAAS;AAAA,MACR,gBAAgB;AAAA,MAChB,cAAc;AAAA,MACd,eAAe,UAAU;AAAA;AAAA,KAG3B,8BAAiB;AAElB,SAAO,OAAO;AAAA;AAZO;AAsBf,2BAA2B,QAAgB,SAAiB,cAAc,UAA2B,IAAI;AAC/G,SAAO,wBACN,6CAA6C,UAC7C;AAAA,IACC,QAAQ,0BAAa;AAAA,IACrB,SAAS;AAAA,MACR,gBAAgB;AAAA,MAChB,cAAc;AAAA,MACd,eAAe,UAAU;AAAA;AAAA,IAE1B,MAAM,KAAK,UAAU;AAAA,MACpB,OAAO,OAAO;AAAA;AAAA,KAGhB,8BAAiB;AAAA;AAdH;AAuBhB,yBAAgC,KAAa;AAC5C,QAAM,YAAY;AAClB,iBAAe;AAAA;AAFM;AAKtB,2BAA2B,QAAgB;AAC1C,MAAI;AACH,UAAM,wBACL,0EACA;AAAA,MACC,SAAS;AAAA,QACR,gBAAgB;AAAA,QAChB,cAAc;AAAA,QACd,eAAe,UAAU;AAAA;AAAA,OAG3B,8BAAiB;AAAA,WAEV,OAAP;AACD,UAAM,aAAa;AAEnB,QAAI,WAAW,SAAS,OAAO,WAAW,SAAS,YAAY,0CAA0C;AACxG,YAAM,IAAI,MAAM;AAAA;AAGjB,UAAM;AAAA;AAAA;AApBO;","names":[]}
package/dist/index.mjs CHANGED
@@ -1,8 +1,92 @@
1
- import mod from "./index.js";
1
+ var __defProp = Object.defineProperty;
2
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
2
3
 
3
- export default mod;
4
- export const checkDomain = mod.checkDomain;
5
- export const getDomainInfo = mod.getDomainInfo;
6
- export const reportCaughtPhish = mod.reportCaughtPhish;
7
- export const reportDomain = mod.reportDomain;
8
- export const setApiKey = mod.setApiKey;
4
+ // src/lib/Phisherman.ts
5
+ import { fetch, FetchMethods, FetchResultTypes } from "@sapphire/fetch";
6
+ import os from "node:os";
7
+ var agent = `Sapphire Phisherman/1.0.0 (node-fetch) ${os.platform()}/${os.release()} (https://github.com/sapphiredev/utilities/tree/main/packages/phisherman)`;
8
+ var storedApiKey;
9
+ async function checkDomain(domain, apiKey = storedApiKey) {
10
+ const result = await fetch(`https://api.phisherman.gg/v2/domains/check/${domain}`, {
11
+ headers: {
12
+ "Content-Type": "application/json",
13
+ "User-Agent": agent,
14
+ Authorization: `Bearer ${apiKey}`
15
+ }
16
+ }, FetchResultTypes.JSON);
17
+ return {
18
+ ...result,
19
+ isScam: result.classification === "safe" || result.classification === "unknown" ? false : true
20
+ };
21
+ }
22
+ __name(checkDomain, "checkDomain");
23
+ function reportDomain(domain, apiKey = storedApiKey) {
24
+ return fetch(`https://api.phisherman.gg/v2/phish/report`, {
25
+ method: FetchMethods.Put,
26
+ headers: {
27
+ "Content-Type": "application/json",
28
+ "User-Agent": agent,
29
+ Authorization: `Bearer ${apiKey}`
30
+ },
31
+ body: JSON.stringify({
32
+ url: domain
33
+ })
34
+ }, FetchResultTypes.JSON);
35
+ }
36
+ __name(reportDomain, "reportDomain");
37
+ async function getDomainInfo(domain, apiKey = storedApiKey) {
38
+ const result = await fetch(`https://api.phisherman.gg/v2/domains/info/${domain}`, {
39
+ headers: {
40
+ "Content-Type": "application/json",
41
+ "User-Agent": ``,
42
+ Authorization: `Bearer ${apiKey}`
43
+ }
44
+ }, FetchResultTypes.JSON);
45
+ return result[domain];
46
+ }
47
+ __name(getDomainInfo, "getDomainInfo");
48
+ function reportCaughtPhish(domain, apiKey = storedApiKey, guildId = "") {
49
+ return fetch(`https://api.phisherman.gg/v2/phish/caught/${domain}`, {
50
+ method: FetchMethods.Post,
51
+ headers: {
52
+ "Content-Type": "application/json",
53
+ "User-Agent": agent,
54
+ Authorization: `Bearer ${apiKey}`
55
+ },
56
+ body: JSON.stringify({
57
+ guild: Number(guildId)
58
+ })
59
+ }, FetchResultTypes.JSON);
60
+ }
61
+ __name(reportCaughtPhish, "reportCaughtPhish");
62
+ async function setApiKey(key) {
63
+ await checkApiKey(key);
64
+ storedApiKey = key;
65
+ }
66
+ __name(setApiKey, "setApiKey");
67
+ async function checkApiKey(apiKey) {
68
+ try {
69
+ await fetch(`https://api.phisherman.gg/v2/domains/check/verified.test.phisherman.gg`, {
70
+ headers: {
71
+ "Content-Type": "application/json",
72
+ "User-Agent": agent,
73
+ Authorization: `Bearer ${apiKey}`
74
+ }
75
+ }, FetchResultTypes.JSON);
76
+ } catch (error) {
77
+ const typedError = error;
78
+ if (typedError.code === 401 && typedError.toJSON().message === "missing permissions or invalid API key") {
79
+ throw new Error("[SapphirePhisherman]: Invalid API key provided");
80
+ }
81
+ throw error;
82
+ }
83
+ }
84
+ __name(checkApiKey, "checkApiKey");
85
+ export {
86
+ checkDomain,
87
+ getDomainInfo,
88
+ reportCaughtPhish,
89
+ reportDomain,
90
+ setApiKey
91
+ };
92
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +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\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\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\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': ``,\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"],"mappings":";;;;AAAA;AAEA;AAEA,IAAM,QAAQ,0CAA0C,GAAG,cAAc,GAAG;AAI5E,IAAI;AAQJ,2BAAkC,QAAgB,SAAiB,cAAc;AAChF,QAAM,SAAS,MAAM,MACpB,8CAA8C,UAC9C;AAAA,IACC,SAAS;AAAA,MACR,gBAAgB;AAAA,MAChB,cAAc;AAAA,MACd,eAAe,UAAU;AAAA;AAAA,KAG3B,iBAAiB;AAGlB,SAAO;AAAA,OACH;AAAA,IACH,QAAQ,OAAO,mBAAmB,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 @@
1
1
  {
2
2
  "name": "@sapphire/phisherman",
3
- "version": "1.1.0",
3
+ "version": "1.2.0-next.365a53a.0",
4
4
  "description": "Wrapper around phisherman to easily check and report domains",
5
5
  "author": "@sapphire",
6
6
  "license": "MIT",
@@ -15,12 +15,11 @@
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": "tsc -b src && yarn esm:default",
19
- "esm:default": "gen-esm-wrapper dist/index.js dist/index.mjs",
18
+ "build": "tsup && tsc -b src",
20
19
  "prepublishOnly": "yarn build"
21
20
  },
22
21
  "dependencies": {
23
- "@sapphire/fetch": "^2.0.3"
22
+ "@sapphire/fetch": "^2.1.0-next.365a53a.0"
24
23
  },
25
24
  "repository": {
26
25
  "type": "git",
@@ -53,5 +52,5 @@
53
52
  "publishConfig": {
54
53
  "access": "public"
55
54
  },
56
- "gitHead": "2298d6c1213995f7f3c3ad2b92778129de361786"
55
+ "gitHead": "365a53a5517a01a0926cf28a83c96b63f32ed9f8"
57
56
  }
@@ -1,118 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.setApiKey = exports.reportCaughtPhish = exports.getDomainInfo = exports.reportDomain = exports.checkDomain = void 0;
4
- const tslib_1 = require("tslib");
5
- const fetch_1 = require("@sapphire/fetch");
6
- const node_os_1 = (0, tslib_1.__importDefault)(require("node:os"));
7
- const agent = `Sapphire Phisherman/1.0.0 (node-fetch) ${node_os_1.default.platform()}/${node_os_1.default.release()} (https://github.com/sapphiredev/utilities/tree/main/packages/phisherman)`;
8
- /**
9
- * The cached apiKey which was created using {@link setApiKey}
10
- */
11
- let storedApiKey;
12
- /**
13
- * Checks if a link is detected as a scam or phishing link by phisherman.
14
- * @param domain The domain to check.
15
- * @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}.
16
- * @since 1.0.0
17
- */
18
- async function checkDomain(domain, apiKey = storedApiKey) {
19
- const result = await (0, fetch_1.fetch)(`https://api.phisherman.gg/v2/domains/check/${domain}`, {
20
- headers: {
21
- 'Content-Type': 'application/json',
22
- 'User-Agent': agent,
23
- Authorization: `Bearer ${apiKey}`
24
- }
25
- }, "json" /* JSON */);
26
- return {
27
- ...result,
28
- isScam: result.classification === 'safe' || result.classification === 'unknown' ? false : true
29
- };
30
- }
31
- exports.checkDomain = checkDomain;
32
- /**
33
- * Report a domain that is confirmed to be a scam or phishing domain to phisherman, to enhance their API.
34
- * @param domain The domain to report.
35
- * @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}.
36
- * @since 1.0.0
37
- */
38
- function reportDomain(domain, apiKey = storedApiKey) {
39
- return (0, fetch_1.fetch)(`https://api.phisherman.gg/v2/phish/report`, {
40
- method: "PUT" /* Put */,
41
- headers: {
42
- 'Content-Type': 'application/json',
43
- 'User-Agent': agent,
44
- Authorization: `Bearer ${apiKey}`
45
- },
46
- body: JSON.stringify({
47
- url: domain
48
- })
49
- }, "json" /* JSON */);
50
- }
51
- exports.reportDomain = reportDomain;
52
- /**
53
- * Returns information for a domain.
54
- * @param domain The domain to get info about.
55
- * @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}.
56
- * @since 1.1.0
57
- */
58
- async function getDomainInfo(domain, apiKey = storedApiKey) {
59
- const result = await (0, fetch_1.fetch)(`https://api.phisherman.gg/v2/domains/info/${domain}`, {
60
- headers: {
61
- 'Content-Type': 'application/json',
62
- 'User-Agent': ``,
63
- Authorization: `Bearer ${apiKey}`
64
- }
65
- }, "json" /* JSON */);
66
- return result[domain];
67
- }
68
- exports.getDomainInfo = getDomainInfo;
69
- /**
70
- * Report a caught phish back to phisherman to improve their analytics.
71
- * @param domain The domain which was caught.
72
- * @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}.
73
- * @param guildId The id of the guild in which the domain was caught.
74
- * @since 1.1.0
75
- */
76
- function reportCaughtPhish(domain, apiKey = storedApiKey, guildId = '') {
77
- return (0, fetch_1.fetch)(`https://api.phisherman.gg/v2/phish/caught/${domain}`, {
78
- method: "POST" /* Post */,
79
- headers: {
80
- 'Content-Type': 'application/json',
81
- 'User-Agent': agent,
82
- Authorization: `Bearer ${apiKey}`
83
- },
84
- body: JSON.stringify({
85
- guild: Number(guildId)
86
- })
87
- }, "json" /* JSON */);
88
- }
89
- exports.reportCaughtPhish = reportCaughtPhish;
90
- /**
91
- * Set the phisherman's API key.
92
- * @param key The API key to access the phisherman API and cache within the code of the wrapper.
93
- * @since 1.0.0
94
- */
95
- async function setApiKey(key) {
96
- await checkApiKey(key);
97
- storedApiKey = key;
98
- }
99
- exports.setApiKey = setApiKey;
100
- async function checkApiKey(apiKey) {
101
- try {
102
- await (0, fetch_1.fetch)(`https://api.phisherman.gg/v2/domains/check/verified.test.phisherman.gg`, {
103
- headers: {
104
- 'Content-Type': 'application/json',
105
- 'User-Agent': agent,
106
- Authorization: `Bearer ${apiKey}`
107
- }
108
- }, "json" /* JSON */);
109
- }
110
- catch (error) {
111
- const typedError = error;
112
- if (typedError.code === 401 && typedError.toJSON().message === 'missing permissions or invalid API key') {
113
- throw new Error('[SapphirePhisherman]: Invalid API key provided');
114
- }
115
- throw error;
116
- }
117
- }
118
- //# sourceMappingURL=Phisherman.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Phisherman.js","sourceRoot":"","sources":["../../src/lib/Phisherman.ts"],"names":[],"mappings":";;;;AAAA,2CAAoF;AAEpF,mEAAyB;AAEzB,MAAM,KAAK,GAAG,0CAA0C,iBAAE,CAAC,QAAQ,EAAE,IAAI,iBAAE,CAAC,OAAO,EAAE,2EAA2E,CAAC;AACjK;;GAEG;AACH,IAAI,YAAoB,CAAC;AAEzB;;;;;GAKG;AACI,KAAK,UAAU,WAAW,CAAC,MAAc,EAAE,SAAiB,YAA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E,EACrD;QACC,MAAM,mBAAmB;QACzB,OAAO,EAAE;YACR,cAAc,EAAE,kBAAkB;YAClC,YAAY,EAAE,KAAK;YACnB,aAAa,EAAE,UAAU,MAAM,EAAE;SACjC;QACD,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC;YACpB,KAAK,EAAE,MAAM,CAAC,OAAO,CAAC;SACtB,CAAC;KACF,oBAED,CAAC;AACH,CAAC;AAhBD,8CAgBC;AAED;;;;GAIG;AACI,KAAK,UAAU,SAAS,CAAC,GAAW;IAC1C,MAAM,WAAW,CAAC,GAAG,CAAC,CAAC;IACvB,YAAY,GAAG,GAAG,CAAC;AACpB,CAAC;AAHD,8BAGC;AAED,KAAK,UAAU,WAAW,CAAC,MAAc;IACxC,IAAI;QACH,MAAM,IAAA,aAAK,EACV,wEAAwE,EACxE;YACC,OAAO,EAAE;gBACR,cAAc,EAAE,kBAAkB;gBAClC,YAAY,EAAE,KAAK;gBACnB,aAAa,EAAE,UAAU,MAAM,EAAE;aACjC;SACD,oBAED,CAAC;KACF;IAAC,OAAO,KAAK,EAAE;QACf,MAAM,UAAU,GAAG,KAAmB,CAAC;QAEvC,IAAI,UAAU,CAAC,IAAI,KAAK,GAAG,IAAI,UAAU,CAAC,MAAM,EAAE,CAAC,OAAO,KAAK,wCAAwC,EAAE;YACxG,MAAM,IAAI,KAAK,CAAC,gDAAgD,CAAC,CAAC;SAClE;QAED,MAAM,KAAK,CAAC;KACZ;AACF,CAAC"}
@@ -1,3 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=PhishermanTypes.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"PhishermanTypes.js","sourceRoot":"","sources":["../../src/lib/PhishermanTypes.ts"],"names":[],"mappings":""}