@sapphire/phisherman 2.0.2-next.f929edc5.0 → 2.0.2-pr-725.ceced33e.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.
@@ -9,7 +9,7 @@ var os__default = /*#__PURE__*/_interopDefault(os);
9
9
 
10
10
  var __defProp = Object.defineProperty;
11
11
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
12
- var packageVersion = "2.0.2-next.f929edc5.0";
12
+ var packageVersion = "2.0.2-pr-725.ceced33e.0";
13
13
  var agent = `Sapphire Phisherman/${packageVersion} (undici) ${os__default.default.platform()}/${os__default.default.release()} (https://github.com/sapphiredev/utilities/tree/main/packages/phisherman)`;
14
14
  var storedApiKey;
15
15
  async function checkDomain(domain, apiKey = storedApiKey) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/lib/Phisherman.ts"],"names":[],"mappings":";;;;AAAA,SAAS,OAAO,cAAc,wBAAoC;AAElE,OAAO,QAAQ;AAGf,IAAM,iBAAyB;AAE/B,IAAM,QAAQ,uBAAuB,cAAc,aAAa,GAAG,SAAS,CAAC,IAAI,GAAG,QAAQ,CAAC;AAI7F,IAAI;AAQJ,eAAsB,YAAY,QAAgB,SAAiB,cAAc;AAChF,cAAY,MAAM;AAClB,QAAM,SAAS,MAAM;AAAA,IACpB,8CAA8C,MAAM;AAAA,IACpD;AAAA,MACC,SAAS;AAAA,QACR,gBAAgB;AAAA,QAChB,cAAc;AAAA,QACd,eAAe,UAAU,MAAM;AAAA,MAChC;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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AAW,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","sourcesContent":["import { fetch, FetchMethods, FetchResultTypes, QueryError } from '@sapphire/fetch';\nimport type { PhishermanInfoType, PhishermanReportType, PhishermanReturnType } from './PhishermanTypes';\nimport os from 'node:os';\n\n// eslint-disable-next-line @typescript-eslint/no-inferrable-types\nconst packageVersion: string = '2.0.2-next.f929edc5.0';\n\nconst agent = `Sapphire Phisherman/${packageVersion} (undici) ${os.platform()}/${os.release()} (https://github.com/sapphiredev/utilities/tree/main/packages/phisherman)`;\n/**\n * The cached apiKey which was created using {@link setApiKey}\n */\nlet storedApiKey: string;\n\n/**\n * Checks if a link is detected as a scam or phishing link by phisherman.\n * @param domain The domain to check.\n * @param apiKey optionally pass a Phiserman API key for making this request. This will default to {@link storedApiKey}, which can be configured through {@link setApiKey}.\n * @since 1.0.0\n */\nexport async function checkDomain(domain: string, apiKey: string = storedApiKey) {\n\tvalidateUrl(domain);\n\tconst result = await fetch<PhishermanReturnType>(\n\t\t`https://api.phisherman.gg/v2/domains/check/${domain}`,\n\t\t{\n\t\t\theaders: {\n\t\t\t\t'Content-Type': 'application/json',\n\t\t\t\t'User-Agent': agent,\n\t\t\t\tAuthorization: `Bearer ${apiKey}`\n\t\t\t}\n\t\t},\n\t\tFetchResultTypes.JSON\n\t);\n\n\treturn {\n\t\t...result,\n\t\tisScam: result.classification === 'safe' || result.classification === 'unknown' ? false : true\n\t};\n}\n\n/**\n * Report a domain that is confirmed to be a scam or phishing domain to phisherman, to enhance their API.\n * @param domain The domain to report.\n * @param apiKey optionally pass a Phiserman API key for making this request. This will default to {@link storedApiKey}, which can be configured through {@link setApiKey}.\n * @since 1.0.0\n */\nexport function reportDomain(domain: string, apiKey: string = storedApiKey) {\n\tvalidateUrl(domain);\n\treturn fetch<PhishermanReportType>(\n\t\t`https://api.phisherman.gg/v2/phish/report`,\n\t\t{\n\t\t\tmethod: FetchMethods.Put,\n\t\t\theaders: {\n\t\t\t\t'Content-Type': 'application/json',\n\t\t\t\t'User-Agent': agent,\n\t\t\t\tAuthorization: `Bearer ${apiKey}`\n\t\t\t},\n\t\t\tbody: JSON.stringify({\n\t\t\t\turl: domain\n\t\t\t})\n\t\t},\n\t\tFetchResultTypes.JSON\n\t);\n}\n\n/**\n * Returns information for a domain.\n * @param domain The domain to get info about.\n * @param apiKey optionally pass a Phiserman API key for making this request. This will default to {@link storedApiKey}, which can be configured through {@link setApiKey}.\n * @since 1.1.0\n */\nexport async function getDomainInfo(domain: string, apiKey: string = storedApiKey) {\n\tvalidateUrl(domain);\n\tconst result = await fetch<PhishermanInfoType>(\n\t\t`https://api.phisherman.gg/v2/domains/info/${domain}`,\n\t\t{\n\t\t\theaders: {\n\t\t\t\t'Content-Type': 'application/json',\n\t\t\t\t'User-Agent': agent,\n\t\t\t\tAuthorization: `Bearer ${apiKey}`\n\t\t\t}\n\t\t},\n\t\tFetchResultTypes.JSON\n\t);\n\treturn result[domain];\n}\n\n/**\n * Report a caught phish back to phisherman to improve their analytics.\n * @param domain The domain which was caught.\n * @param apiKey @param apiKey optionally pass a Phiserman API key for making this request. This will default to {@link storedApiKey}, which can be configured through {@link setApiKey}.\n * @param guildId The id of the guild in which the domain was caught.\n * @since 1.1.0\n */\nexport function reportCaughtPhish(domain: string, apiKey: string = storedApiKey, guildId: string | number = '') {\n\treturn fetch<PhishermanReportType>(\n\t\t`https://api.phisherman.gg/v2/phish/caught/${domain}`,\n\t\t{\n\t\t\tmethod: FetchMethods.Post,\n\t\t\theaders: {\n\t\t\t\t'Content-Type': 'application/json',\n\t\t\t\t'User-Agent': agent,\n\t\t\t\tAuthorization: `Bearer ${apiKey}`\n\t\t\t},\n\t\t\tbody: JSON.stringify({\n\t\t\t\tguild: Number(guildId)\n\t\t\t})\n\t\t},\n\t\tFetchResultTypes.JSON\n\t);\n}\n\n/**\n * Set the phisherman's API key.\n * @param key The API key to access the phisherman API and cache within the code of the wrapper.\n * @since 1.0.0\n */\nexport async function setApiKey(key: string) {\n\tawait checkApiKey(key);\n\tstoredApiKey = key;\n}\n\nasync function checkApiKey(apiKey: string) {\n\ttry {\n\t\tawait fetch<{ message: string; success: false }>(\n\t\t\t`https://api.phisherman.gg/v2/domains/check/verified.test.phisherman.gg`,\n\t\t\t{\n\t\t\t\theaders: {\n\t\t\t\t\t'Content-Type': 'application/json',\n\t\t\t\t\t'User-Agent': agent,\n\t\t\t\t\tAuthorization: `Bearer ${apiKey}`\n\t\t\t\t}\n\t\t\t},\n\t\t\tFetchResultTypes.JSON\n\t\t);\n\t} catch (error) {\n\t\tconst typedError = error as QueryError;\n\n\t\tif (typedError.code === 401 && typedError.toJSON().message === 'missing permissions or invalid API key') {\n\t\t\tthrow new Error('[SapphirePhisherman]: Invalid API key provided');\n\t\t}\n\n\t\tthrow error;\n\t}\n}\n\nfunction validateUrl(domain: string) {\n\tconst regexp = /[-a-zA-Z0-9@:%._\\+~#=]{1,256}\\.[a-zA-Z0-9()]{1,6}\\b([-a-zA-Z0-9()@:%_\\+.~#?&//=]*)/gi;\n\tif (!domain.match(regexp)) throw new Error('[SapphirePhisherman]: Invalid domain provided');\n}\n"]}
1
+ {"version":3,"sources":["../../src/lib/Phisherman.ts"],"names":[],"mappings":";;;;AAAA,SAAS,OAAO,cAAc,wBAAoC;AAElE,OAAO,QAAQ;AAGf,IAAM,iBAAyB;AAE/B,IAAM,QAAQ,uBAAuB,cAAc,aAAa,GAAG,SAAS,CAAC,IAAI,GAAG,QAAQ,CAAC;AAI7F,IAAI;AAQJ,eAAsB,YAAY,QAAgB,SAAiB,cAAc;AAChF,cAAY,MAAM;AAClB,QAAM,SAAS,MAAM;AAAA,IACpB,8CAA8C,MAAM;AAAA,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,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,MAAM;AAAA,QAChC;AAAA,MACD;AAAA,MACA,iBAAiB;AAAA,IAClB;AAAA,EACD,SAAS,OAAO;AACf,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","sourcesContent":["import { fetch, FetchMethods, FetchResultTypes, QueryError } from '@sapphire/fetch';\nimport type { PhishermanInfoType, PhishermanReportType, PhishermanReturnType } from './PhishermanTypes';\nimport os from 'node:os';\n\n// eslint-disable-next-line @typescript-eslint/no-inferrable-types\nconst packageVersion: string = '2.0.2-pr-725.ceced33e.0';\n\nconst agent = `Sapphire Phisherman/${packageVersion} (undici) ${os.platform()}/${os.release()} (https://github.com/sapphiredev/utilities/tree/main/packages/phisherman)`;\n/**\n * The cached apiKey which was created using {@link setApiKey}\n */\nlet storedApiKey: string;\n\n/**\n * Checks if a link is detected as a scam or phishing link by phisherman.\n * @param domain The domain to check.\n * @param apiKey optionally pass a Phiserman API key for making this request. This will default to {@link storedApiKey}, which can be configured through {@link setApiKey}.\n * @since 1.0.0\n */\nexport async function checkDomain(domain: string, apiKey: string = storedApiKey) {\n\tvalidateUrl(domain);\n\tconst result = await fetch<PhishermanReturnType>(\n\t\t`https://api.phisherman.gg/v2/domains/check/${domain}`,\n\t\t{\n\t\t\theaders: {\n\t\t\t\t'Content-Type': 'application/json',\n\t\t\t\t'User-Agent': agent,\n\t\t\t\tAuthorization: `Bearer ${apiKey}`\n\t\t\t}\n\t\t},\n\t\tFetchResultTypes.JSON\n\t);\n\n\treturn {\n\t\t...result,\n\t\tisScam: result.classification === 'safe' || result.classification === 'unknown' ? false : true\n\t};\n}\n\n/**\n * Report a domain that is confirmed to be a scam or phishing domain to phisherman, to enhance their API.\n * @param domain The domain to report.\n * @param apiKey optionally pass a Phiserman API key for making this request. This will default to {@link storedApiKey}, which can be configured through {@link setApiKey}.\n * @since 1.0.0\n */\nexport function reportDomain(domain: string, apiKey: string = storedApiKey) {\n\tvalidateUrl(domain);\n\treturn fetch<PhishermanReportType>(\n\t\t`https://api.phisherman.gg/v2/phish/report`,\n\t\t{\n\t\t\tmethod: FetchMethods.Put,\n\t\t\theaders: {\n\t\t\t\t'Content-Type': 'application/json',\n\t\t\t\t'User-Agent': agent,\n\t\t\t\tAuthorization: `Bearer ${apiKey}`\n\t\t\t},\n\t\t\tbody: JSON.stringify({\n\t\t\t\turl: domain\n\t\t\t})\n\t\t},\n\t\tFetchResultTypes.JSON\n\t);\n}\n\n/**\n * Returns information for a domain.\n * @param domain The domain to get info about.\n * @param apiKey optionally pass a Phiserman API key for making this request. This will default to {@link storedApiKey}, which can be configured through {@link setApiKey}.\n * @since 1.1.0\n */\nexport async function getDomainInfo(domain: string, apiKey: string = storedApiKey) {\n\tvalidateUrl(domain);\n\tconst result = await fetch<PhishermanInfoType>(\n\t\t`https://api.phisherman.gg/v2/domains/info/${domain}`,\n\t\t{\n\t\t\theaders: {\n\t\t\t\t'Content-Type': 'application/json',\n\t\t\t\t'User-Agent': agent,\n\t\t\t\tAuthorization: `Bearer ${apiKey}`\n\t\t\t}\n\t\t},\n\t\tFetchResultTypes.JSON\n\t);\n\treturn result[domain];\n}\n\n/**\n * Report a caught phish back to phisherman to improve their analytics.\n * @param domain The domain which was caught.\n * @param apiKey @param apiKey optionally pass a Phiserman API key for making this request. This will default to {@link storedApiKey}, which can be configured through {@link setApiKey}.\n * @param guildId The id of the guild in which the domain was caught.\n * @since 1.1.0\n */\nexport function reportCaughtPhish(domain: string, apiKey: string = storedApiKey, guildId: string | number = '') {\n\treturn fetch<PhishermanReportType>(\n\t\t`https://api.phisherman.gg/v2/phish/caught/${domain}`,\n\t\t{\n\t\t\tmethod: FetchMethods.Post,\n\t\t\theaders: {\n\t\t\t\t'Content-Type': 'application/json',\n\t\t\t\t'User-Agent': agent,\n\t\t\t\tAuthorization: `Bearer ${apiKey}`\n\t\t\t},\n\t\t\tbody: JSON.stringify({\n\t\t\t\tguild: Number(guildId)\n\t\t\t})\n\t\t},\n\t\tFetchResultTypes.JSON\n\t);\n}\n\n/**\n * Set the phisherman's API key.\n * @param key The API key to access the phisherman API and cache within the code of the wrapper.\n * @since 1.0.0\n */\nexport async function setApiKey(key: string) {\n\tawait checkApiKey(key);\n\tstoredApiKey = key;\n}\n\nasync function checkApiKey(apiKey: string) {\n\ttry {\n\t\tawait fetch<{ message: string; success: false }>(\n\t\t\t`https://api.phisherman.gg/v2/domains/check/verified.test.phisherman.gg`,\n\t\t\t{\n\t\t\t\theaders: {\n\t\t\t\t\t'Content-Type': 'application/json',\n\t\t\t\t\t'User-Agent': agent,\n\t\t\t\t\tAuthorization: `Bearer ${apiKey}`\n\t\t\t\t}\n\t\t\t},\n\t\t\tFetchResultTypes.JSON\n\t\t);\n\t} catch (error) {\n\t\tconst typedError = error as QueryError;\n\n\t\tif (typedError.code === 401 && typedError.toJSON().message === 'missing permissions or invalid API key') {\n\t\t\tthrow new Error('[SapphirePhisherman]: Invalid API key provided');\n\t\t}\n\n\t\tthrow error;\n\t}\n}\n\nfunction validateUrl(domain: string) {\n\tconst regexp = /[-a-zA-Z0-9@:%._\\+~#=]{1,256}\\.[a-zA-Z0-9()]{1,6}\\b([-a-zA-Z0-9()@:%_\\+.~#?&//=]*)/gi;\n\tif (!domain.match(regexp)) throw new Error('[SapphirePhisherman]: Invalid domain provided');\n}\n"]}
@@ -3,7 +3,7 @@ import os from 'node:os';
3
3
 
4
4
  var __defProp = Object.defineProperty;
5
5
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
6
- var packageVersion = "2.0.2-next.f929edc5.0";
6
+ var packageVersion = "2.0.2-pr-725.ceced33e.0";
7
7
  var agent = `Sapphire Phisherman/${packageVersion} (undici) ${os.platform()}/${os.release()} (https://github.com/sapphiredev/utilities/tree/main/packages/phisherman)`;
8
8
  var storedApiKey;
9
9
  async function checkDomain(domain, apiKey = storedApiKey) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/lib/Phisherman.ts"],"names":[],"mappings":";;;;AAAA,SAAS,OAAO,cAAc,wBAAoC;AAElE,OAAO,QAAQ;AAGf,IAAM,iBAAyB;AAE/B,IAAM,QAAQ,uBAAuB,cAAc,aAAa,GAAG,SAAS,CAAC,IAAI,GAAG,QAAQ,CAAC;AAI7F,IAAI;AAQJ,eAAsB,YAAY,QAAgB,SAAiB,cAAc;AAChF,cAAY,MAAM;AAClB,QAAM,SAAS,MAAM;AAAA,IACpB,8CAA8C,MAAM;AAAA,IACpD;AAAA,MACC,SAAS;AAAA,QACR,gBAAgB;AAAA,QAChB,cAAc;AAAA,QACd,eAAe,UAAU,MAAM;AAAA,MAChC;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,MAAM;AAAA,MAChC;AAAA,MACA,MAAM,KAAK,UAA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YAAY,QAAgB;AACpC,QAAM,SAAS;AACf,MAAI,CAAC,OAAO,MAAM,MAAM;AAAG,UAAM,IAAI,MAAM,+CAA+C;AAC3F;AAHS","sourcesContent":["import { fetch, FetchMethods, FetchResultTypes, QueryError } from '@sapphire/fetch';\nimport type { PhishermanInfoType, PhishermanReportType, PhishermanReturnType } from './PhishermanTypes';\nimport os from 'node:os';\n\n// eslint-disable-next-line @typescript-eslint/no-inferrable-types\nconst packageVersion: string = '2.0.2-next.f929edc5.0';\n\nconst agent = `Sapphire Phisherman/${packageVersion} (undici) ${os.platform()}/${os.release()} (https://github.com/sapphiredev/utilities/tree/main/packages/phisherman)`;\n/**\n * The cached apiKey which was created using {@link setApiKey}\n */\nlet storedApiKey: string;\n\n/**\n * Checks if a link is detected as a scam or phishing link by phisherman.\n * @param domain The domain to check.\n * @param apiKey optionally pass a Phiserman API key for making this request. This will default to {@link storedApiKey}, which can be configured through {@link setApiKey}.\n * @since 1.0.0\n */\nexport async function checkDomain(domain: string, apiKey: string = storedApiKey) {\n\tvalidateUrl(domain);\n\tconst result = await fetch<PhishermanReturnType>(\n\t\t`https://api.phisherman.gg/v2/domains/check/${domain}`,\n\t\t{\n\t\t\theaders: {\n\t\t\t\t'Content-Type': 'application/json',\n\t\t\t\t'User-Agent': agent,\n\t\t\t\tAuthorization: `Bearer ${apiKey}`\n\t\t\t}\n\t\t},\n\t\tFetchResultTypes.JSON\n\t);\n\n\treturn {\n\t\t...result,\n\t\tisScam: result.classification === 'safe' || result.classification === 'unknown' ? false : true\n\t};\n}\n\n/**\n * Report a domain that is confirmed to be a scam or phishing domain to phisherman, to enhance their API.\n * @param domain The domain to report.\n * @param apiKey optionally pass a Phiserman API key for making this request. This will default to {@link storedApiKey}, which can be configured through {@link setApiKey}.\n * @since 1.0.0\n */\nexport function reportDomain(domain: string, apiKey: string = storedApiKey) {\n\tvalidateUrl(domain);\n\treturn fetch<PhishermanReportType>(\n\t\t`https://api.phisherman.gg/v2/phish/report`,\n\t\t{\n\t\t\tmethod: FetchMethods.Put,\n\t\t\theaders: {\n\t\t\t\t'Content-Type': 'application/json',\n\t\t\t\t'User-Agent': agent,\n\t\t\t\tAuthorization: `Bearer ${apiKey}`\n\t\t\t},\n\t\t\tbody: JSON.stringify({\n\t\t\t\turl: domain\n\t\t\t})\n\t\t},\n\t\tFetchResultTypes.JSON\n\t);\n}\n\n/**\n * Returns information for a domain.\n * @param domain The domain to get info about.\n * @param apiKey optionally pass a Phiserman API key for making this request. This will default to {@link storedApiKey}, which can be configured through {@link setApiKey}.\n * @since 1.1.0\n */\nexport async function getDomainInfo(domain: string, apiKey: string = storedApiKey) {\n\tvalidateUrl(domain);\n\tconst result = await fetch<PhishermanInfoType>(\n\t\t`https://api.phisherman.gg/v2/domains/info/${domain}`,\n\t\t{\n\t\t\theaders: {\n\t\t\t\t'Content-Type': 'application/json',\n\t\t\t\t'User-Agent': agent,\n\t\t\t\tAuthorization: `Bearer ${apiKey}`\n\t\t\t}\n\t\t},\n\t\tFetchResultTypes.JSON\n\t);\n\treturn result[domain];\n}\n\n/**\n * Report a caught phish back to phisherman to improve their analytics.\n * @param domain The domain which was caught.\n * @param apiKey @param apiKey optionally pass a Phiserman API key for making this request. This will default to {@link storedApiKey}, which can be configured through {@link setApiKey}.\n * @param guildId The id of the guild in which the domain was caught.\n * @since 1.1.0\n */\nexport function reportCaughtPhish(domain: string, apiKey: string = storedApiKey, guildId: string | number = '') {\n\treturn fetch<PhishermanReportType>(\n\t\t`https://api.phisherman.gg/v2/phish/caught/${domain}`,\n\t\t{\n\t\t\tmethod: FetchMethods.Post,\n\t\t\theaders: {\n\t\t\t\t'Content-Type': 'application/json',\n\t\t\t\t'User-Agent': agent,\n\t\t\t\tAuthorization: `Bearer ${apiKey}`\n\t\t\t},\n\t\t\tbody: JSON.stringify({\n\t\t\t\tguild: Number(guildId)\n\t\t\t})\n\t\t},\n\t\tFetchResultTypes.JSON\n\t);\n}\n\n/**\n * Set the phisherman's API key.\n * @param key The API key to access the phisherman API and cache within the code of the wrapper.\n * @since 1.0.0\n */\nexport async function setApiKey(key: string) {\n\tawait checkApiKey(key);\n\tstoredApiKey = key;\n}\n\nasync function checkApiKey(apiKey: string) {\n\ttry {\n\t\tawait fetch<{ message: string; success: false }>(\n\t\t\t`https://api.phisherman.gg/v2/domains/check/verified.test.phisherman.gg`,\n\t\t\t{\n\t\t\t\theaders: {\n\t\t\t\t\t'Content-Type': 'application/json',\n\t\t\t\t\t'User-Agent': agent,\n\t\t\t\t\tAuthorization: `Bearer ${apiKey}`\n\t\t\t\t}\n\t\t\t},\n\t\t\tFetchResultTypes.JSON\n\t\t);\n\t} catch (error) {\n\t\tconst typedError = error as QueryError;\n\n\t\tif (typedError.code === 401 && typedError.toJSON().message === 'missing permissions or invalid API key') {\n\t\t\tthrow new Error('[SapphirePhisherman]: Invalid API key provided');\n\t\t}\n\n\t\tthrow error;\n\t}\n}\n\nfunction validateUrl(domain: string) {\n\tconst regexp = /[-a-zA-Z0-9@:%._\\+~#=]{1,256}\\.[a-zA-Z0-9()]{1,6}\\b([-a-zA-Z0-9()@:%_\\+.~#?&//=]*)/gi;\n\tif (!domain.match(regexp)) throw new Error('[SapphirePhisherman]: Invalid domain provided');\n}\n"]}
1
+ {"version":3,"sources":["../../src/lib/Phisherman.ts"],"names":[],"mappings":";;;;AAAA,SAAS,OAAO,cAAc,wBAAoC;AAElE,OAAO,QAAQ;AAGf,IAAM,iBAAyB;AAE/B,IAAM,QAAQ,uBAAuB,cAAc,aAAa,GAAG,SAAS,CAAC,IAAI,GAAG,QAAQ,CAAC;AAI7F,IAAI;AAQJ,eAAsB,YAAY,QAAgB,SAAiB,cAAc;AAChF,cAAY,MAAM;AAClB,QAAM,SAAS,MAAM;AAAA,IACpB,8CAA8C,MAAM;AAAA,IACpD;AAAA,MACC,SAAS;AAAA,QACR,gBAAgB;AAAA,QAChB,cAAc;AAAA,QACd,eAAe,UAAU,MAAM;AAAA,MAChC;AAAA,IACD;AAAA,IACA,i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B;AAC1C,MAAI;AACH,UAAM;AAAA,MACL;AAAA,MACA;AAAA,QACC,SAAS;AAAA,UACR,gBAAgB;AAAA,UAChB,cAAc;AAAA,UACd,eAAe,UAAU,MAAM;AAAA,QAChC;AAAA,MACD;AAAA,MACA,iBAAiB;AAAA,IAClB;AAAA,EACD,SAAS,OAAO;AACf,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","sourcesContent":["import { fetch, FetchMethods, FetchResultTypes, QueryError } from '@sapphire/fetch';\nimport type { PhishermanInfoType, PhishermanReportType, PhishermanReturnType } from './PhishermanTypes';\nimport os from 'node:os';\n\n// eslint-disable-next-line @typescript-eslint/no-inferrable-types\nconst packageVersion: string = '2.0.2-pr-725.ceced33e.0';\n\nconst agent = `Sapphire Phisherman/${packageVersion} (undici) ${os.platform()}/${os.release()} (https://github.com/sapphiredev/utilities/tree/main/packages/phisherman)`;\n/**\n * The cached apiKey which was created using {@link setApiKey}\n */\nlet storedApiKey: string;\n\n/**\n * Checks if a link is detected as a scam or phishing link by phisherman.\n * @param domain The domain to check.\n * @param apiKey optionally pass a Phiserman API key for making this request. This will default to {@link storedApiKey}, which can be configured through {@link setApiKey}.\n * @since 1.0.0\n */\nexport async function checkDomain(domain: string, apiKey: string = storedApiKey) {\n\tvalidateUrl(domain);\n\tconst result = await fetch<PhishermanReturnType>(\n\t\t`https://api.phisherman.gg/v2/domains/check/${domain}`,\n\t\t{\n\t\t\theaders: {\n\t\t\t\t'Content-Type': 'application/json',\n\t\t\t\t'User-Agent': agent,\n\t\t\t\tAuthorization: `Bearer ${apiKey}`\n\t\t\t}\n\t\t},\n\t\tFetchResultTypes.JSON\n\t);\n\n\treturn {\n\t\t...result,\n\t\tisScam: result.classification === 'safe' || result.classification === 'unknown' ? false : true\n\t};\n}\n\n/**\n * Report a domain that is confirmed to be a scam or phishing domain to phisherman, to enhance their API.\n * @param domain The domain to report.\n * @param apiKey optionally pass a Phiserman API key for making this request. This will default to {@link storedApiKey}, which can be configured through {@link setApiKey}.\n * @since 1.0.0\n */\nexport function reportDomain(domain: string, apiKey: string = storedApiKey) {\n\tvalidateUrl(domain);\n\treturn fetch<PhishermanReportType>(\n\t\t`https://api.phisherman.gg/v2/phish/report`,\n\t\t{\n\t\t\tmethod: FetchMethods.Put,\n\t\t\theaders: {\n\t\t\t\t'Content-Type': 'application/json',\n\t\t\t\t'User-Agent': agent,\n\t\t\t\tAuthorization: `Bearer ${apiKey}`\n\t\t\t},\n\t\t\tbody: JSON.stringify({\n\t\t\t\turl: domain\n\t\t\t})\n\t\t},\n\t\tFetchResultTypes.JSON\n\t);\n}\n\n/**\n * Returns information for a domain.\n * @param domain The domain to get info about.\n * @param apiKey optionally pass a Phiserman API key for making this request. This will default to {@link storedApiKey}, which can be configured through {@link setApiKey}.\n * @since 1.1.0\n */\nexport async function getDomainInfo(domain: string, apiKey: string = storedApiKey) {\n\tvalidateUrl(domain);\n\tconst result = await fetch<PhishermanInfoType>(\n\t\t`https://api.phisherman.gg/v2/domains/info/${domain}`,\n\t\t{\n\t\t\theaders: {\n\t\t\t\t'Content-Type': 'application/json',\n\t\t\t\t'User-Agent': agent,\n\t\t\t\tAuthorization: `Bearer ${apiKey}`\n\t\t\t}\n\t\t},\n\t\tFetchResultTypes.JSON\n\t);\n\treturn result[domain];\n}\n\n/**\n * Report a caught phish back to phisherman to improve their analytics.\n * @param domain The domain which was caught.\n * @param apiKey @param apiKey optionally pass a Phiserman API key for making this request. This will default to {@link storedApiKey}, which can be configured through {@link setApiKey}.\n * @param guildId The id of the guild in which the domain was caught.\n * @since 1.1.0\n */\nexport function reportCaughtPhish(domain: string, apiKey: string = storedApiKey, guildId: string | number = '') {\n\treturn fetch<PhishermanReportType>(\n\t\t`https://api.phisherman.gg/v2/phish/caught/${domain}`,\n\t\t{\n\t\t\tmethod: FetchMethods.Post,\n\t\t\theaders: {\n\t\t\t\t'Content-Type': 'application/json',\n\t\t\t\t'User-Agent': agent,\n\t\t\t\tAuthorization: `Bearer ${apiKey}`\n\t\t\t},\n\t\t\tbody: JSON.stringify({\n\t\t\t\tguild: Number(guildId)\n\t\t\t})\n\t\t},\n\t\tFetchResultTypes.JSON\n\t);\n}\n\n/**\n * Set the phisherman's API key.\n * @param key The API key to access the phisherman API and cache within the code of the wrapper.\n * @since 1.0.0\n */\nexport async function setApiKey(key: string) {\n\tawait checkApiKey(key);\n\tstoredApiKey = key;\n}\n\nasync function checkApiKey(apiKey: string) {\n\ttry {\n\t\tawait fetch<{ message: string; success: false }>(\n\t\t\t`https://api.phisherman.gg/v2/domains/check/verified.test.phisherman.gg`,\n\t\t\t{\n\t\t\t\theaders: {\n\t\t\t\t\t'Content-Type': 'application/json',\n\t\t\t\t\t'User-Agent': agent,\n\t\t\t\t\tAuthorization: `Bearer ${apiKey}`\n\t\t\t\t}\n\t\t\t},\n\t\t\tFetchResultTypes.JSON\n\t\t);\n\t} catch (error) {\n\t\tconst typedError = error as QueryError;\n\n\t\tif (typedError.code === 401 && typedError.toJSON().message === 'missing permissions or invalid API key') {\n\t\t\tthrow new Error('[SapphirePhisherman]: Invalid API key provided');\n\t\t}\n\n\t\tthrow error;\n\t}\n}\n\nfunction validateUrl(domain: string) {\n\tconst regexp = /[-a-zA-Z0-9@:%._\\+~#=]{1,256}\\.[a-zA-Z0-9()]{1,6}\\b([-a-zA-Z0-9()@:%_\\+.~#?&//=]*)/gi;\n\tif (!domain.match(regexp)) throw new Error('[SapphirePhisherman]: Invalid domain provided');\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sapphire/phisherman",
3
- "version": "2.0.2-next.f929edc5.0",
3
+ "version": "2.0.2-pr-725.ceced33e.0",
4
4
  "description": "Wrapper around phisherman to easily check and report domains",
5
5
  "author": "@sapphire",
6
6
  "license": "MIT",
@@ -60,12 +60,12 @@
60
60
  "access": "public"
61
61
  },
62
62
  "devDependencies": {
63
- "@favware/cliff-jumper": "^2.2.3",
63
+ "@favware/cliff-jumper": "^3.0.1",
64
64
  "@sapphire/result": "^2.6.6",
65
65
  "esbuild-plugin-version-injector": "^1.2.1",
66
66
  "tsup": "^8.0.2",
67
- "typedoc": "^0.25.8",
67
+ "typedoc": "^0.25.12",
68
68
  "typedoc-json-parser": "^9.0.1",
69
- "typescript": "^5.3.3"
69
+ "typescript": "^5.4.2"
70
70
  }
71
71
  }