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