@chainpatrol/sdk 0.2.4 → 0.3.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/dist/index.d.ts CHANGED
@@ -47,6 +47,11 @@ type ChainPatrolClientOptions = {
47
47
  apiKey: string;
48
48
  baseUrl?: string;
49
49
  };
50
+ type ApiRequest = {
51
+ path: string[];
52
+ method: "GET" | "POST" | "PUT" | "DELETE";
53
+ body?: unknown;
54
+ };
50
55
  type AssetType = "URL" | "PAGE" | "ADDRESS";
51
56
  type AssetStatus = "ALLOWED" | "BLOCKED" | "UNKNOWN";
52
57
  declare class ChainPatrolClient {
@@ -54,7 +59,7 @@ declare class ChainPatrolClient {
54
59
  private readonly apiKey;
55
60
  private readonly logger;
56
61
  constructor(options: ChainPatrolClientOptions);
57
- private fetch;
62
+ fetch<TResult = unknown>(req: ApiRequest): Promise<TResult>;
58
63
  get asset(): {
59
64
  check: (req: AssetCheckInput) => Promise<AssetCheckOutput>;
60
65
  list: (req: AssetListInput) => Promise<AssetListOutput>;
package/dist/index.js CHANGED
@@ -473,48 +473,11 @@ zod.z.object({
473
473
  description: zod.z.string().optional(),
474
474
  assetGroupId: zod.z.number().optional()
475
475
  });
476
-
477
- // ../../internal/database/prisma/enums/index.ts
478
- var AssetType = {
479
- URL: "URL",
480
- PAGE: "PAGE",
481
- ADDRESS: "ADDRESS",
482
- DISCORD: "DISCORD",
483
- LINKEDIN: "LINKEDIN",
484
- TWITTER: "TWITTER",
485
- FACEBOOK: "FACEBOOK",
486
- YOUTUBE: "YOUTUBE",
487
- REDDIT: "REDDIT",
488
- TELEGRAM: "TELEGRAM"
489
- };
490
- var AssetStatus = {
491
- UNKNOWN: "UNKNOWN",
492
- ALLOWED: "ALLOWED",
493
- BLOCKED: "BLOCKED"
494
- };
495
-
496
- // ../../internal/validation/src/public/asset/check.ts
497
- var assetCheckInputSchema = zod.z.object({
498
- /** Asset content. Could be a domain, URL, or crypto address. */
499
- content: zod.z.string().describe("Asset content")
500
- }).describe("Check asset request body");
501
476
  zod.z.object({
502
- /**
503
- * - `ALLOWED` - the asset is on the allowlist
504
- * - `BLOCKED` - the asset is on the blocklist
505
- * - `UNKNOWN` - the asset's status is not known
506
- */
507
- status: zod.z.nativeEnum(AssetStatus).describe("The result of the asset status check"),
508
- /**
509
- * Optional reason for the asset's status.
510
- * If the asset is allowed or blocked, this will be the reason why.
511
- * ChainPatrol aggregates data from multiple sources, so this will
512
- * tell you which source blocked or allowed the asset.
513
- */
514
- reason: zod.z.string().optional().describe(`The reason for the result. If the result is \`BLOCKED\` this will be either
515
- \`report\` if it was reported on ChainPatrol or \`eth-phishing-detect\` if it was
516
- reported on the eth-phishing-detect list.`)
517
- }).describe("Check asset response body");
477
+ content: zod.z.string().min(1, { message: "Content must be at least 3 character" }).max(1e3, { message: "Content must be less than 1000 characters" }),
478
+ email: zod.z.string().email(),
479
+ description: zod.z.string().optional().default("")
480
+ });
518
481
 
519
482
  // ../../node_modules/luxon/src/errors.js
520
483
  var LuxonError = class extends Error {
@@ -1988,15 +1951,15 @@ var PolyNumberFormatter = class {
1988
1951
  var PolyDateFormatter = class {
1989
1952
  constructor(dt, intl, opts) {
1990
1953
  this.opts = opts;
1991
- let z6;
1954
+ let z9;
1992
1955
  if (dt.zone.isUniversal) {
1993
1956
  const gmtOffset = -1 * (dt.offset / 60);
1994
1957
  const offsetZ = gmtOffset >= 0 ? `Etc/GMT+${gmtOffset}` : `Etc/GMT${gmtOffset}`;
1995
1958
  if (dt.offset !== 0 && IANAZone.create(offsetZ).valid) {
1996
- z6 = offsetZ;
1959
+ z9 = offsetZ;
1997
1960
  this.dt = dt;
1998
1961
  } else {
1999
- z6 = "UTC";
1962
+ z9 = "UTC";
2000
1963
  if (opts.timeZoneName) {
2001
1964
  this.dt = dt;
2002
1965
  } else {
@@ -2007,11 +1970,11 @@ var PolyDateFormatter = class {
2007
1970
  this.dt = dt;
2008
1971
  } else {
2009
1972
  this.dt = dt;
2010
- z6 = dt.zone.name;
1973
+ z9 = dt.zone.name;
2011
1974
  }
2012
1975
  const intlOpts = __spreadValues({}, this.opts);
2013
- if (z6) {
2014
- intlOpts.timeZone = z6;
1976
+ if (z9) {
1977
+ intlOpts.timeZone = z9;
2015
1978
  }
2016
1979
  this.dtf = getCachedDTF(intl, intlOpts);
2017
1980
  }
@@ -6259,6 +6222,121 @@ function friendlyDateTime(dateTimeish) {
6259
6222
  );
6260
6223
  }
6261
6224
  }
6225
+
6226
+ // ../../internal/database/prisma/enums/index.ts
6227
+ var AssetType = {
6228
+ URL: "URL",
6229
+ PAGE: "PAGE",
6230
+ ADDRESS: "ADDRESS",
6231
+ DISCORD: "DISCORD",
6232
+ LINKEDIN: "LINKEDIN",
6233
+ TWITTER: "TWITTER",
6234
+ FACEBOOK: "FACEBOOK",
6235
+ YOUTUBE: "YOUTUBE",
6236
+ REDDIT: "REDDIT",
6237
+ TELEGRAM: "TELEGRAM",
6238
+ GOOGLE_APP_STORE: "GOOGLE_APP_STORE",
6239
+ APPLE_APP_STORE: "APPLE_APP_STORE",
6240
+ AMAZON_APP_STORE: "AMAZON_APP_STORE",
6241
+ MICROSOFT_APP_STORE: "MICROSOFT_APP_STORE",
6242
+ TIKTOK: "TIKTOK",
6243
+ INSTAGRAM: "INSTAGRAM",
6244
+ THREADS: "THREADS",
6245
+ MEDIUM: "MEDIUM",
6246
+ CHROME_WEB_STORE: "CHROME_WEB_STORE",
6247
+ MOZILLA_ADDONS: "MOZILLA_ADDONS",
6248
+ EMAIL: "EMAIL",
6249
+ PATREON: "PATREON"
6250
+ };
6251
+ var AssetStatus = {
6252
+ UNKNOWN: "UNKNOWN",
6253
+ ALLOWED: "ALLOWED",
6254
+ BLOCKED: "BLOCKED"
6255
+ };
6256
+
6257
+ // ../../internal/validation/src/public/asset/changelog.ts
6258
+ zod.z.object({
6259
+ /** The type of asset to retrieve. */
6260
+ type: zod.z.nativeEnum(AssetType).optional().describe("Asset type"),
6261
+ /** The content of the asset to retrieve. */
6262
+ content: zod.z.string().optional().describe("Asset content"),
6263
+ /** Optional filter determening from which status asset was updated. */
6264
+ fromStatus: zod.z.nativeEnum(AssetStatus).optional().describe("Status of the changed assets to retrieve"),
6265
+ /** Optional filter determening to which status asset was updated. */
6266
+ toStatus: zod.z.nativeEnum(AssetStatus).optional().describe("Status of the changed assets to retrieve"),
6267
+ /**
6268
+ * Optional start date for listing assets; should be in `YYYY-MM-DD` format and is inclusive.
6269
+ * Transformed into JavaScript Date objects from strings.
6270
+ * If the startDate is after the endDate, a validation error will occur.
6271
+ */
6272
+ startDate: zod.z.string().transform((str) => new Date(str)).optional().describe(
6273
+ "The start date to list items from. This should be in the format `YYYY-MM-DD` and is inclusive."
6274
+ ),
6275
+ /**
6276
+ * Optional end date for listing assets; should be in `YYYY-MM-DD` format and is inclusive.
6277
+ * Defaults to the current date if not provided.
6278
+ * Transformed into JavaScript Date objects from strings.
6279
+ * If the startDate is after the endDate, a validation error will occur.
6280
+ */
6281
+ endDate: zod.z.string().transform((str) => new Date(str)).optional().describe(
6282
+ "The end date to list items from. This should be in the format `YYYY-MM-DD` and is inclusive."
6283
+ )
6284
+ }).describe(
6285
+ `List asset request body
6286
+
6287
+ Defaults to getting all the updates in the last 1 day.
6288
+
6289
+ You can also choose a \`startDate\` and \`endDate\` for the range of asset updates, most
6290
+ timestamp formats should work, we use [Luxon](https://moment.github.io/luxon/#/parsing)
6291
+ for parsing the dates.`
6292
+ ).transform((data) => {
6293
+ if (data.startDate && !data.endDate) {
6294
+ data.endDate = DateTime.now().toJSDate();
6295
+ }
6296
+ return data;
6297
+ }).refine((data) => {
6298
+ if (data.startDate && data.endDate && data.startDate > data.endDate) {
6299
+ return {
6300
+ path: ["startDate"],
6301
+ message: "startDate must be before endDate"
6302
+ };
6303
+ }
6304
+ return true;
6305
+ });
6306
+ zod.z.object({
6307
+ /** An array of asset change with their content, type, status, and update timestamp. */
6308
+ changelog: zod.z.array(
6309
+ zod.z.object({
6310
+ assetId: zod.z.number().describe("Asset ID"),
6311
+ type: zod.z.nativeEnum(AssetType).describe("Asset type"),
6312
+ content: zod.z.string().describe("Asset content"),
6313
+ fromStatus: zod.z.nativeEnum(AssetStatus).describe("The result of the asset status check"),
6314
+ toStatus: zod.z.nativeEnum(AssetStatus).describe("Status to which asset was updated at `updatedAt`"),
6315
+ updatedAt: zod.z.date()
6316
+ })
6317
+ )
6318
+ }).describe("Successful operation");
6319
+ var assetCheckInputSchema = zod.z.object({
6320
+ /** Asset content. Could be a domain, URL, or crypto address. */
6321
+ content: zod.z.string().describe("Asset content")
6322
+ }).describe("Check asset request body");
6323
+ zod.z.object({
6324
+ /**
6325
+ * - `ALLOWED` - the asset is on the allowlist
6326
+ * - `BLOCKED` - the asset is on the blocklist
6327
+ * - `UNKNOWN` - the asset's status is not known
6328
+ */
6329
+ status: zod.z.nativeEnum(AssetStatus).describe("The result of the asset status check"),
6330
+ /**
6331
+ * Optional reason for the asset's status.
6332
+ * If the asset is allowed or blocked, this will be the reason why.
6333
+ * ChainPatrol aggregates data from multiple sources, so this will
6334
+ * tell you which source blocked or allowed the asset.
6335
+ */
6336
+ reason: zod.z.string().optional().describe(`The reason for the result. If the result is \`BLOCKED\` this will be either
6337
+ \`report\` if it was reported on ChainPatrol or \`eth-phishing-detect\` if it was
6338
+ reported on the eth-phishing-detect list.`)
6339
+ }).describe("Check asset response body");
6262
6340
  var assetListInputSchema = zod.z.object({
6263
6341
  /** The type of asset to retrieve. */
6264
6342
  type: zod.z.nativeEnum(AssetType).describe("Asset type"),
@@ -6377,20 +6455,35 @@ zod.z.object({
6377
6455
  name: zod.z.string().describe("Name of the organization")
6378
6456
  }).nullable().describe("Organization the report was created for")
6379
6457
  });
6458
+ zod.z.object({
6459
+ token: zod.z.string(),
6460
+ memo: zod.z.string(),
6461
+ additional_data: zod.z.object({
6462
+ location: zod.z.string()
6463
+ })
6464
+ });
6465
+ zod.z.object({
6466
+ result: zod.z.string()
6467
+ });
6380
6468
 
6381
6469
  // src/client.ts
6382
6470
  function trimTrailingSlashes(url) {
6383
6471
  return url.replace(/\/+$/, "");
6384
6472
  }
6473
+ var ChainPatrolClientError = class extends Error {
6474
+ constructor(message, code) {
6475
+ super(message);
6476
+ this.code = code;
6477
+ }
6478
+ };
6385
6479
  var ChainPatrolClient = class {
6386
6480
  constructor(options) {
6387
- this.logger = new Logger({ component: "ChainPatrolClient" });
6388
6481
  var _a;
6389
- console.log("CREATING CLIENT");
6390
- this.baseUrl = (_a = options.baseUrl) != null ? _a : "https://app.chainpatrol.io/api/";
6391
6482
  if (!options.apiKey) {
6392
- throw new Error("ChainPatrol API key is required");
6483
+ throw new ChainPatrolClientError("Missing API key", "MISSING_API_KEY");
6393
6484
  }
6485
+ this.baseUrl = (_a = options.baseUrl) != null ? _a : "https://app.chainpatrol.io/api/";
6486
+ this.logger = new Logger({ component: "ChainPatrolClient" });
6394
6487
  this.apiKey = options.apiKey;
6395
6488
  }
6396
6489
  fetch(req) {
@@ -6398,7 +6491,6 @@ var ChainPatrolClient = class {
6398
6491
  const url = `${trimTrailingSlashes(this.baseUrl)}/${req.path.join("/")}`;
6399
6492
  this.logger.debug("fetch", { url, req });
6400
6493
  const bodyString = JSON.stringify(req.body);
6401
- console.log("request body", bodyString);
6402
6494
  const res = yield fetch(url, {
6403
6495
  method: req.method,
6404
6496
  headers: {
@@ -6408,7 +6500,9 @@ var ChainPatrolClient = class {
6408
6500
  body: bodyString
6409
6501
  });
6410
6502
  if (!res.ok) {
6411
- throw new Error(yield res.text());
6503
+ const text = yield res.text();
6504
+ this.logger.error("fetch", { url, req, res: { status: res.status, text } });
6505
+ throw new ChainPatrolClientError(text, "API_ERROR");
6412
6506
  }
6413
6507
  return res.json();
6414
6508
  });