@chainpatrol/sdk 0.5.0 → 0.7.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.js CHANGED
@@ -35,10 +35,6 @@ var __objRest = (source, exclude) => {
35
35
  }
36
36
  return target;
37
37
  };
38
- var __export = (target, all) => {
39
- for (var name in all)
40
- __defProp(target, name, { get: all[name], enumerable: true });
41
- };
42
38
  var __async = (__this, __arguments, generator) => {
43
39
  return new Promise((resolve, reject) => {
44
40
  var fulfilled = (value) => {
@@ -60,6 +56,110 @@ var __async = (__this, __arguments, generator) => {
60
56
  });
61
57
  };
62
58
 
59
+ // src/constants.ts
60
+ var StorageKeys = {
61
+ ALLOWLIST: "chainpatrol.allowed",
62
+ BLOCKLIST: "chainpatrol.blocked",
63
+ IGNORELIST: "chainpatrol.ignored"
64
+ };
65
+
66
+ // src/storage/define-storage.ts
67
+ function defineStorage(config) {
68
+ return () => config({
69
+ keys: Object.values(StorageKeys)
70
+ });
71
+ }
72
+
73
+ // src/storage/browser.ts
74
+ function isStorageAvailable(type) {
75
+ let storage;
76
+ try {
77
+ storage = window[type];
78
+ const x = "__storage_test__";
79
+ storage.setItem(x, x);
80
+ storage.removeItem(x);
81
+ return true;
82
+ } catch (e) {
83
+ return e instanceof DOMException && // everything except Firefox
84
+ (e.code === 22 || // Firefox
85
+ e.code === 1014 || // test name field too, because code might not be present
86
+ // everything except Firefox
87
+ e.name === "QuotaExceededError" || // Firefox
88
+ e.name === "NS_ERROR_DOM_QUOTA_REACHED") && // acknowledge QuotaExceededError only if there's something already stored
89
+ storage && storage.length !== 0;
90
+ }
91
+ }
92
+ var Browser = defineStorage(({ keys }) => {
93
+ if (!isStorageAvailable("localStorage")) {
94
+ throw new Error("localStorage is not available");
95
+ }
96
+ return {
97
+ get: (key) => __async(null, null, function* () {
98
+ return localStorage.getItem(key);
99
+ }),
100
+ set: (key, value) => __async(null, null, function* () {
101
+ localStorage.setItem(key, value);
102
+ }),
103
+ delete: (key) => __async(null, null, function* () {
104
+ localStorage.removeItem(key);
105
+ }),
106
+ size: () => __async(null, null, function* () {
107
+ var _a, _b;
108
+ let total = 0;
109
+ for (let i = 0; i < localStorage.length; i++) {
110
+ const key = localStorage.key(i);
111
+ if (key && keys.includes(key)) {
112
+ total += (_b = (_a = localStorage.getItem(key)) == null ? void 0 : _a.length) != null ? _b : 0;
113
+ }
114
+ }
115
+ return total;
116
+ })
117
+ };
118
+ });
119
+
120
+ // src/storage/extension.ts
121
+ var Extension = defineStorage(({ keys }) => {
122
+ return {
123
+ get: (key) => __async(null, null, function* () {
124
+ const result = yield chrome.storage.local.get(key);
125
+ return result[key];
126
+ }),
127
+ set: (key, value) => __async(null, null, function* () {
128
+ yield chrome.storage.local.set({ [key]: value });
129
+ }),
130
+ delete: (key) => __async(null, null, function* () {
131
+ yield chrome.storage.local.remove(key);
132
+ }),
133
+ size: () => __async(null, null, function* () {
134
+ const usageBytes = yield chrome.storage.local.getBytesInUse(keys);
135
+ return usageBytes;
136
+ })
137
+ };
138
+ });
139
+
140
+ // src/storage/memory.ts
141
+ var Memory = defineStorage(() => {
142
+ const storage = /* @__PURE__ */ new Map();
143
+ return {
144
+ get: (key) => __async(null, null, function* () {
145
+ return storage.get(key) || null;
146
+ }),
147
+ set: (key, value) => __async(null, null, function* () {
148
+ storage.set(key, value);
149
+ }),
150
+ delete: (key) => __async(null, null, function* () {
151
+ storage.delete(key);
152
+ }),
153
+ size: () => __async(null, null, function* () {
154
+ let total = 0;
155
+ for (const value of storage.values()) {
156
+ total += value.length;
157
+ }
158
+ return total;
159
+ })
160
+ };
161
+ });
162
+
63
163
  // src/events.ts
64
164
  var ContinueAtOwnRisk = "CHAINPATROL_CONTINUE_AT_OWN_RISK";
65
165
  var IgnorelistUpdated = "CHAINPATROL_IGNORELIST_UPDATED";
@@ -145,7 +245,7 @@ function getBackgroundScriptHandle() {
145
245
  removeListener: (callback) => {
146
246
  runtime.onMessage.removeListener(callback);
147
247
  },
148
- postMessage: (message) => __async(this, null, function* () {
248
+ postMessage: (message) => __async(null, null, function* () {
149
249
  const [tab] = yield globalThis.chrome.tabs.query({
150
250
  active: true,
151
251
  lastFocusedWindow: true
@@ -167,7 +267,7 @@ function getContentScriptHandle() {
167
267
  removeListener: (callback) => {
168
268
  runtime.onMessage.removeListener(callback);
169
269
  },
170
- postMessage: (message) => __async(this, null, function* () {
270
+ postMessage: (message) => __async(null, null, function* () {
171
271
  runtime.sendMessage(message).catch((error) => {
172
272
  console.error("Failed to send message", { message, error });
173
273
  });
@@ -285,7 +385,7 @@ var supportedProtocols = /* @__PURE__ */ new Set([
285
385
  var hasCustomProtocol = (urlString) => {
286
386
  try {
287
387
  const { protocol } = new URL(urlString);
288
- return protocol.endsWith(":") && !supportedProtocols.has(protocol);
388
+ return protocol.endsWith(":") && !protocol.includes(".") && !supportedProtocols.has(protocol);
289
389
  } catch (e) {
290
390
  return false;
291
391
  }
@@ -496,7 +596,7 @@ zod.z.object({
496
596
  assetId: zod.z.number(),
497
597
  name: zod.z.string().optional(),
498
598
  description: zod.z.string().optional(),
499
- assetGroupId: zod.z.number().optional(),
599
+ assetGroupId: zod.z.number().nullable().optional(),
500
600
  updatedByOrganizationId: zod.z.number().optional()
501
601
  });
502
602
  zod.z.object({
@@ -1177,17 +1277,17 @@ var PolyDateFormatter = class {
1177
1277
  constructor(dt, intl, opts) {
1178
1278
  this.opts = opts;
1179
1279
  this.originalZone = void 0;
1180
- let z14 = void 0;
1280
+ let z15 = void 0;
1181
1281
  if (this.opts.timeZone) {
1182
1282
  this.dt = dt;
1183
1283
  } else if (dt.zone.type === "fixed") {
1184
1284
  const gmtOffset = -1 * (dt.offset / 60);
1185
1285
  const offsetZ = gmtOffset >= 0 ? `Etc/GMT+${gmtOffset}` : `Etc/GMT${gmtOffset}`;
1186
1286
  if (dt.offset !== 0 && IANAZone.create(offsetZ).valid) {
1187
- z14 = offsetZ;
1287
+ z15 = offsetZ;
1188
1288
  this.dt = dt;
1189
1289
  } else {
1190
- z14 = "UTC";
1290
+ z15 = "UTC";
1191
1291
  this.dt = dt.offset === 0 ? dt : dt.setZone("UTC").plus({ minutes: dt.offset });
1192
1292
  this.originalZone = dt.zone;
1193
1293
  }
@@ -1195,14 +1295,14 @@ var PolyDateFormatter = class {
1195
1295
  this.dt = dt;
1196
1296
  } else if (dt.zone.type === "iana") {
1197
1297
  this.dt = dt;
1198
- z14 = dt.zone.name;
1298
+ z15 = dt.zone.name;
1199
1299
  } else {
1200
- z14 = "UTC";
1300
+ z15 = "UTC";
1201
1301
  this.dt = dt.setZone("UTC").plus({ minutes: dt.offset });
1202
1302
  this.originalZone = dt.zone;
1203
1303
  }
1204
1304
  const intlOpts = __spreadValues({}, this.opts);
1205
- intlOpts.timeZone = intlOpts.timeZone || z14;
1305
+ intlOpts.timeZone = intlOpts.timeZone || z15;
1206
1306
  this.dtf = getCachedDTF(intl, intlOpts);
1207
1307
  }
1208
1308
  format() {
@@ -5322,7 +5422,7 @@ var DateTime = class _DateTime {
5322
5422
  throw new InvalidArgumentError(
5323
5423
  `fromMillis requires a numerical input, but received a ${typeof milliseconds} with value ${milliseconds}`
5324
5424
  );
5325
- } else if (milliseconds < -864e13 || milliseconds > MAX_DATE) {
5425
+ } else if (milliseconds < -MAX_DATE || milliseconds > MAX_DATE) {
5326
5426
  return _DateTime.invalid("Timestamp out of range");
5327
5427
  } else {
5328
5428
  return new _DateTime({
@@ -6919,7 +7019,7 @@ function friendlyDateTime(dateTimeish) {
6919
7019
  }
6920
7020
  }
6921
7021
 
6922
- // ../../internal/database/prisma/enums/index.ts
7022
+ // ../../internal/database/src/generated/enums.ts
6923
7023
  var AssetType = {
6924
7024
  URL: "URL",
6925
7025
  PAGE: "PAGE",
@@ -6952,13 +7052,26 @@ var AssetType = {
6952
7052
  DISCORD_USER: "DISCORD_USER",
6953
7053
  QUORA: "QUORA",
6954
7054
  GITHUB: "GITHUB",
6955
- TEACHABLE: "TEACHABLE"
7055
+ TEACHABLE: "TEACHABLE",
7056
+ SUBSTACK: "SUBSTACK",
7057
+ DEBANK: "DEBANK",
7058
+ TAWK_TO: "TAWK_TO",
7059
+ JOTFORM: "JOTFORM",
7060
+ PRIMAL: "PRIMAL",
7061
+ BLUESKY: "BLUESKY",
7062
+ SNAPCHAT: "SNAPCHAT",
7063
+ DESO: "DESO"
6956
7064
  };
6957
7065
  var AssetStatus = {
6958
7066
  UNKNOWN: "UNKNOWN",
6959
7067
  ALLOWED: "ALLOWED",
6960
7068
  BLOCKED: "BLOCKED"
6961
7069
  };
7070
+ var ProposalReviewStatus = {
7071
+ PENDING: "PENDING",
7072
+ APPROVED: "APPROVED",
7073
+ REJECTED: "REJECTED"
7074
+ };
6962
7075
 
6963
7076
  // ../../internal/validation/src/public/asset/changelog.ts
6964
7077
  var DateString = zod.z.string().regex(/^\d{4}-\d{2}-\d{2}$/, "Must be in the format `YYYY-MM-DD`").pipe(zod.z.coerce.date());
@@ -7028,6 +7141,7 @@ var AssetRecordSource = /* @__PURE__ */ ((AssetRecordSource2) => {
7028
7141
  AssetRecordSource2["EthPhishingDetect"] = "eth-phishing-detect";
7029
7142
  AssetRecordSource2["Phishfort"] = "phishfort";
7030
7143
  AssetRecordSource2["Seal"] = "seal";
7144
+ AssetRecordSource2["PolkadotPhishing"] = "polkadot-phishing";
7031
7145
  return AssetRecordSource2;
7032
7146
  })(AssetRecordSource || {});
7033
7147
  var AssetStatusReason = /* @__PURE__ */ ((AssetStatusReason2) => {
@@ -7036,6 +7150,7 @@ var AssetStatusReason = /* @__PURE__ */ ((AssetStatusReason2) => {
7036
7150
  AssetStatusReason2["SourceError"] = "source-error";
7037
7151
  AssetStatusReason2["ParentDomain"] = "parent-domain";
7038
7152
  AssetStatusReason2["HostingDomain"] = "hosting-domain";
7153
+ AssetStatusReason2["Timeout"] = "timeout";
7039
7154
  return AssetStatusReason2;
7040
7155
  })(AssetStatusReason || {});
7041
7156
  var AssetCheckErrorCodes = /* @__PURE__ */ ((AssetCheckErrorCodes2) => {
@@ -7084,7 +7199,7 @@ var assetListInputSchema = zod.z.object({
7084
7199
  endDate: zod.z.string().transform((str) => new Date(str)).optional().describe(
7085
7200
  "The end date to list assets from. This should be in the format `YYYY-MM-DD` and is inclusive."
7086
7201
  ),
7087
- per_page: zod.z.number().int().min(1).max(1e4).optional().describe("The number of assets to return per page"),
7202
+ per_page: zod.z.number().int().min(1).max(1e4).optional().default(100).describe("The number of assets to return per page"),
7088
7203
  /**
7089
7204
  * Optional next_page cursor for pagination; indicates where the next page of results should start.
7090
7205
  */
@@ -7135,13 +7250,15 @@ var reportCreateInputSchema = zod.z.object({
7135
7250
  /** Optional Telegram Group ID associated with the organization. */
7136
7251
  telegramGroupId: zod.z.string().describe("Telegram Group ID linked to the organization on ChainPatrol").optional(),
7137
7252
  /** Title of the report. */
7138
- title: zod.z.string().min(3).describe("Title of the report"),
7253
+ title: zod.z.string().min(3).describe("Title of the report").optional(),
7139
7254
  /** Description of the report, supporting markdown syntax. */
7140
- description: zod.z.string().describe("Description of the report. Supports markdown"),
7255
+ description: zod.z.string().describe("Description of the report. Supports markdown").optional(),
7141
7256
  /** Optional contact information of the reporter. */
7142
7257
  contactInfo: zod.z.string().optional(),
7143
7258
  /** Optional list of URLs for images to be attached to the report. */
7144
7259
  attachmentUrls: zod.z.array(zod.z.string().url()).optional().describe("URLs of images to attach to the report"),
7260
+ /** Optional link to the external submission (e.g. Telegram message link) */
7261
+ externalSubmissionLink: zod.z.string().url().optional().describe("Link to the external submission (e.g. Telegram message link)"),
7145
7262
  /**
7146
7263
  * List of assets with their content and proposed status.
7147
7264
  * Each asset can optionally include a screenshot object.
@@ -7174,7 +7291,7 @@ var reportCreateInputSchema = zod.z.object({
7174
7291
  if (v.rawAssetsInput && v.assets.length === 0) {
7175
7292
  v.assets = v.rawAssetsInput.split("\n").map((line) => line.trim()).filter((line) => line.length > 0).map((line) => ({
7176
7293
  content: line,
7177
- status: "BLOCKED"
7294
+ status: AssetStatus.BLOCKED
7178
7295
  }));
7179
7296
  }
7180
7297
  return v;
@@ -7215,12 +7332,106 @@ zod.z.object({
7215
7332
  zod.z.object({
7216
7333
  id: zod.z.number(),
7217
7334
  content: zod.z.string(),
7218
- status: zod.z.nativeEnum(AssetStatus)
7335
+ status: zod.z.nativeEnum(AssetStatus),
7336
+ reviewStatus: zod.z.nativeEnum(ProposalReviewStatus)
7219
7337
  })
7220
7338
  )
7221
7339
  })
7222
7340
  )
7223
7341
  });
7342
+ zod.z.object({
7343
+ selectedOrgs: zod.z.array(
7344
+ zod.z.object({
7345
+ id: zod.z.number(),
7346
+ name: zod.z.string(),
7347
+ slug: zod.z.string(),
7348
+ avatarUrl: zod.z.string().nullable().optional()
7349
+ })
7350
+ ),
7351
+ parentOrg: zod.z.string(),
7352
+ startDate: zod.z.string(),
7353
+ endDate: zod.z.string(),
7354
+ weekNumber: zod.z.number().max(53).optional(),
7355
+ organizationLogo: zod.z.string(),
7356
+ organizationLogos: zod.z.record(zod.z.string(), zod.z.string()),
7357
+ hiddenLogos: zod.z.record(zod.z.string(), zod.z.boolean()).default({}),
7358
+ logoCustomization: zod.z.object({
7359
+ position: zod.z.object({
7360
+ x: zod.z.number(),
7361
+ y: zod.z.number()
7362
+ }),
7363
+ size: zod.z.object({
7364
+ width: zod.z.number(),
7365
+ height: zod.z.number()
7366
+ }),
7367
+ scale: zod.z.number().min(0.1).max(3).default(1)
7368
+ }).optional(),
7369
+ executiveSummary: zod.z.string(),
7370
+ overviewText: zod.z.string(),
7371
+ overviewDisplayLocation: zod.z.enum(["cover", "separate"]).default("cover"),
7372
+ publishedDate: zod.z.string().default(() => (/* @__PURE__ */ new Date()).toISOString().split("T")[0]),
7373
+ caseStudies: zod.z.array(
7374
+ zod.z.object({
7375
+ id: zod.z.string(),
7376
+ title: zod.z.string(),
7377
+ description: zod.z.string(),
7378
+ assetId: zod.z.number().optional(),
7379
+ proposalId: zod.z.number().optional(),
7380
+ screenshotUrl: zod.z.string().nullable().optional(),
7381
+ screenshotUrls: zod.z.array(zod.z.string()).optional(),
7382
+ imageUrl: zod.z.string().optional(),
7383
+ takedownCompletedAt: zod.z.string().nullable().optional()
7384
+ })
7385
+ ),
7386
+ productUpdates: zod.z.array(
7387
+ zod.z.object({
7388
+ id: zod.z.string(),
7389
+ title: zod.z.string(),
7390
+ content: zod.z.string(),
7391
+ createdAt: zod.z.string().optional()
7392
+ })
7393
+ ),
7394
+ recommendations: zod.z.array(
7395
+ zod.z.object({
7396
+ id: zod.z.string(),
7397
+ title: zod.z.string(),
7398
+ content: zod.z.string()
7399
+ })
7400
+ ),
7401
+ customMetrics: zod.z.object({
7402
+ totalReports: zod.z.number(),
7403
+ threatsBlocked: zod.z.number(),
7404
+ domainsBlocked: zod.z.number(),
7405
+ takedownsFiled: zod.z.number(),
7406
+ falsePositives: zod.z.number(),
7407
+ additionalNotes: zod.z.string().optional()
7408
+ }),
7409
+ recentTakedowns: zod.z.array(
7410
+ zod.z.object({
7411
+ id: zod.z.number(),
7412
+ content: zod.z.string(),
7413
+ type: zod.z.string(),
7414
+ createdAt: zod.z.coerce.date(),
7415
+ takedownCompletedAt: zod.z.coerce.date().nullable(),
7416
+ description: zod.z.string().nullable().optional()
7417
+ })
7418
+ ).default([]),
7419
+ customPages: zod.z.array(
7420
+ zod.z.object({
7421
+ id: zod.z.string(),
7422
+ title: zod.z.string(),
7423
+ content: zod.z.string()
7424
+ })
7425
+ ).default([]),
7426
+ faqs: zod.z.record(
7427
+ zod.z.string(),
7428
+ zod.z.object({
7429
+ title: zod.z.string(),
7430
+ content: zod.z.string(),
7431
+ enabled: zod.z.boolean().default(true)
7432
+ })
7433
+ ).default({})
7434
+ });
7224
7435
 
7225
7436
  // src/client.ts
7226
7437
  function trimTrailingSlashes(url) {
@@ -7239,28 +7450,36 @@ var ChainPatrolClientErrorCodes = /* @__PURE__ */ ((ChainPatrolClientErrorCodes2
7239
7450
  })(ChainPatrolClientErrorCodes || {});
7240
7451
  var ChainPatrolClient = class {
7241
7452
  constructor(options) {
7242
- var _a;
7453
+ var _a, _b;
7243
7454
  if (!options.apiKey) {
7244
7455
  throw new ChainPatrolClientError(
7245
7456
  "Missing API key",
7246
7457
  "MISSING_API_KEY" /* MISSING_API_KEY */
7247
7458
  );
7248
7459
  }
7249
- this.baseUrl = (_a = options.baseUrl) != null ? _a : "https://app.chainpatrol.io/api/";
7460
+ this.baseUrl = trimTrailingSlashes(
7461
+ (_a = options.baseUrl) != null ? _a : "https://app.chainpatrol.io/api/"
7462
+ );
7250
7463
  this.logger = new Logger({ component: "ChainPatrolClient" });
7251
7464
  this.apiKey = options.apiKey;
7465
+ this.fetchOptions = (_b = options.fetchOptions) != null ? _b : {};
7252
7466
  }
7253
7467
  fetch(req) {
7254
7468
  return __async(this, null, function* () {
7469
+ var _a;
7255
7470
  const url = `${trimTrailingSlashes(this.baseUrl)}/${req.path.join("/")}`;
7256
7471
  this.logger.debug("fetch", { url, req });
7257
7472
  const bodyString = JSON.stringify(req.body);
7258
7473
  const res = yield fetch(url, {
7259
7474
  method: req.method,
7260
- headers: {
7475
+ headers: __spreadValues({
7261
7476
  "Content-Type": "application/json",
7262
7477
  "X-Api-Key": this.apiKey
7263
- },
7478
+ }, (_a = this.fetchOptions.headers) != null ? _a : {}),
7479
+ signal: this.fetchOptions.signal,
7480
+ redirect: this.fetchOptions.redirect,
7481
+ mode: this.fetchOptions.mode,
7482
+ credentials: this.fetchOptions.credentials,
7264
7483
  body: bodyString
7265
7484
  });
7266
7485
  if (!res.ok) {
@@ -7305,112 +7524,6 @@ var ChainPatrolClient = class {
7305
7524
  }
7306
7525
  };
7307
7526
 
7308
- // src/storage/index.ts
7309
- var storage_exports = {};
7310
- __export(storage_exports, {
7311
- Browser: () => Browser,
7312
- Extension: () => Extension,
7313
- Memory: () => Memory,
7314
- defineStorage: () => defineStorage
7315
- });
7316
-
7317
- // src/storage/define-storage.ts
7318
- function defineStorage(config) {
7319
- return () => config({
7320
- keys: Object.values(ThreatDetector.StorageKeys)
7321
- });
7322
- }
7323
-
7324
- // src/storage/extension.ts
7325
- var Extension = defineStorage(({ keys }) => {
7326
- return {
7327
- get: (key) => __async(void 0, null, function* () {
7328
- const result = yield chrome.storage.local.get(key);
7329
- return result[key];
7330
- }),
7331
- set: (key, value) => __async(void 0, null, function* () {
7332
- yield chrome.storage.local.set({ [key]: value });
7333
- }),
7334
- delete: (key) => __async(void 0, null, function* () {
7335
- yield chrome.storage.local.remove(key);
7336
- }),
7337
- size: () => __async(void 0, null, function* () {
7338
- const usageBytes = yield chrome.storage.local.getBytesInUse(keys);
7339
- return usageBytes;
7340
- })
7341
- };
7342
- });
7343
-
7344
- // src/storage/browser.ts
7345
- function isStorageAvailable(type) {
7346
- let storage;
7347
- try {
7348
- storage = window[type];
7349
- const x = "__storage_test__";
7350
- storage.setItem(x, x);
7351
- storage.removeItem(x);
7352
- return true;
7353
- } catch (e) {
7354
- return e instanceof DOMException && // everything except Firefox
7355
- (e.code === 22 || // Firefox
7356
- e.code === 1014 || // test name field too, because code might not be present
7357
- // everything except Firefox
7358
- e.name === "QuotaExceededError" || // Firefox
7359
- e.name === "NS_ERROR_DOM_QUOTA_REACHED") && // acknowledge QuotaExceededError only if there's something already stored
7360
- storage && storage.length !== 0;
7361
- }
7362
- }
7363
- var Browser = defineStorage(({ keys }) => {
7364
- if (!isStorageAvailable("localStorage")) {
7365
- throw new Error("localStorage is not available");
7366
- }
7367
- return {
7368
- get: (key) => __async(void 0, null, function* () {
7369
- return localStorage.getItem(key);
7370
- }),
7371
- set: (key, value) => __async(void 0, null, function* () {
7372
- localStorage.setItem(key, value);
7373
- }),
7374
- delete: (key) => __async(void 0, null, function* () {
7375
- localStorage.removeItem(key);
7376
- }),
7377
- size: () => __async(void 0, null, function* () {
7378
- var _a, _b;
7379
- let total = 0;
7380
- for (let i = 0; i < localStorage.length; i++) {
7381
- const key = localStorage.key(i);
7382
- if (key && keys.includes(key)) {
7383
- total += (_b = (_a = localStorage.getItem(key)) == null ? void 0 : _a.length) != null ? _b : 0;
7384
- }
7385
- }
7386
- return total;
7387
- })
7388
- };
7389
- });
7390
-
7391
- // src/storage/memory.ts
7392
- var Memory = defineStorage(() => {
7393
- const storage = /* @__PURE__ */ new Map();
7394
- return {
7395
- get: (key) => __async(void 0, null, function* () {
7396
- return storage.get(key) || null;
7397
- }),
7398
- set: (key, value) => __async(void 0, null, function* () {
7399
- storage.set(key, value);
7400
- }),
7401
- delete: (key) => __async(void 0, null, function* () {
7402
- storage.delete(key);
7403
- }),
7404
- size: () => __async(void 0, null, function* () {
7405
- let total = 0;
7406
- for (const value of storage.values()) {
7407
- total += value.length;
7408
- }
7409
- return total;
7410
- })
7411
- };
7412
- });
7413
-
7414
7527
  // src/detector.ts
7415
7528
  var DomainParseError = class extends Error {
7416
7529
  constructor(message) {
@@ -7501,9 +7614,9 @@ var _ThreatDetector = class _ThreatDetector {
7501
7614
  const res = yield this.client.asset.check({ content: domain });
7502
7615
  this.logger.debug("Updating cache", { domain, status: res.status });
7503
7616
  if (res.status === "ALLOWED") {
7504
- yield this.addDomainToCache(domain, _ThreatDetector.StorageKeys.ALLOWLIST);
7617
+ yield this.addDomainToCache(domain, StorageKeys.ALLOWLIST);
7505
7618
  } else if (res.status === "BLOCKED") {
7506
- yield this.addDomainToCache(domain, _ThreatDetector.StorageKeys.BLOCKLIST);
7619
+ yield this.addDomainToCache(domain, StorageKeys.BLOCKLIST);
7507
7620
  }
7508
7621
  status = res.status;
7509
7622
  } catch (e) {
@@ -7538,7 +7651,7 @@ var _ThreatDetector = class _ThreatDetector {
7538
7651
  const domain = this.parseDomainOrThrow(url);
7539
7652
  this.logger.debug("Allowing URL", { url, domain });
7540
7653
  yield this.invalidateDomainInCaches(domain);
7541
- yield this.addDomainToCache(domain, _ThreatDetector.StorageKeys.ALLOWLIST);
7654
+ yield this.addDomainToCache(domain, StorageKeys.ALLOWLIST);
7542
7655
  return {
7543
7656
  ok: true,
7544
7657
  url: domain
@@ -7559,7 +7672,7 @@ var _ThreatDetector = class _ThreatDetector {
7559
7672
  const domain = this.parseDomainOrThrow(url);
7560
7673
  this.logger.debug("Blocking URL", { url, domain });
7561
7674
  yield this.invalidateDomainInCaches(domain);
7562
- yield this.addDomainToCache(domain, _ThreatDetector.StorageKeys.BLOCKLIST);
7675
+ yield this.addDomainToCache(domain, StorageKeys.BLOCKLIST);
7563
7676
  return {
7564
7677
  ok: true,
7565
7678
  url: domain
@@ -7579,7 +7692,7 @@ var _ThreatDetector = class _ThreatDetector {
7579
7692
  try {
7580
7693
  const domain = this.parseDomainOrThrow(url);
7581
7694
  this.logger.debug("Ignoring URL", { url, domain });
7582
- yield this.addDomainToCache(domain, _ThreatDetector.StorageKeys.IGNORELIST);
7695
+ yield this.addDomainToCache(domain, StorageKeys.IGNORELIST);
7583
7696
  return {
7584
7697
  ok: true,
7585
7698
  url: domain
@@ -7628,8 +7741,8 @@ var _ThreatDetector = class _ThreatDetector {
7628
7741
  }
7629
7742
  invalidateDomainInCaches(domain) {
7630
7743
  return __async(this, null, function* () {
7631
- yield this.invalidateDomainInCache(domain, _ThreatDetector.StorageKeys.ALLOWLIST);
7632
- yield this.invalidateDomainInCache(domain, _ThreatDetector.StorageKeys.BLOCKLIST);
7744
+ yield this.invalidateDomainInCache(domain, StorageKeys.ALLOWLIST);
7745
+ yield this.invalidateDomainInCache(domain, StorageKeys.BLOCKLIST);
7633
7746
  });
7634
7747
  }
7635
7748
  invalidateDomainInCache(domain, key) {
@@ -7686,11 +7799,11 @@ var _ThreatDetector = class _ThreatDetector {
7686
7799
  }
7687
7800
  getStatusFromCache(domain) {
7688
7801
  return __async(this, null, function* () {
7689
- if (yield this.isDomainInList(domain, _ThreatDetector.StorageKeys.IGNORELIST)) {
7802
+ if (yield this.isDomainInList(domain, StorageKeys.IGNORELIST)) {
7690
7803
  return "IGNORED";
7691
- } else if (yield this.isDomainInList(domain, _ThreatDetector.StorageKeys.BLOCKLIST)) {
7804
+ } else if (yield this.isDomainInList(domain, StorageKeys.BLOCKLIST)) {
7692
7805
  return "BLOCKED";
7693
- } else if (yield this.isDomainInList(domain, _ThreatDetector.StorageKeys.ALLOWLIST)) {
7806
+ } else if (yield this.isDomainInList(domain, StorageKeys.ALLOWLIST)) {
7694
7807
  return "ALLOWED";
7695
7808
  } else {
7696
7809
  return "UNKNOWN";
@@ -7698,11 +7811,6 @@ var _ThreatDetector = class _ThreatDetector {
7698
7811
  });
7699
7812
  }
7700
7813
  };
7701
- _ThreatDetector.StorageKeys = {
7702
- ALLOWLIST: "chainpatrol.allowed",
7703
- BLOCKLIST: "chainpatrol.blocked",
7704
- IGNORELIST: "chainpatrol.ignored"
7705
- };
7706
7814
  _ThreatDetector.CHAINPATROL_WARNING_URL = "https://app.chainpatrol.io/warning";
7707
7815
  _ThreatDetector.Schema = zod.z.object({
7708
7816
  version: zod.z.literal(1),
@@ -7712,13 +7820,20 @@ _ThreatDetector.Schema = zod.z.object({
7712
7820
  });
7713
7821
  var ThreatDetector = _ThreatDetector;
7714
7822
 
7823
+ // src/index.ts
7824
+ var Storage = {
7825
+ Memory,
7826
+ Extension,
7827
+ Browser
7828
+ };
7829
+
7715
7830
  exports.ChainPatrolClient = ChainPatrolClient;
7716
7831
  exports.ChainPatrolClientError = ChainPatrolClientError;
7717
7832
  exports.ChainPatrolClientErrorCodes = ChainPatrolClientErrorCodes;
7718
7833
  exports.DomainParseError = DomainParseError;
7719
7834
  exports.Events = Events;
7720
7835
  exports.Relay = Relay;
7721
- exports.Storage = storage_exports;
7836
+ exports.Storage = Storage;
7722
7837
  exports.ThreatDetector = ThreatDetector;
7723
7838
  //# sourceMappingURL=index.js.map
7724
7839
  //# sourceMappingURL=index.js.map