@chainpatrol/sdk 0.5.0 → 0.6.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 +1 -1
- package/dist/index.d.mts +24 -43
- package/dist/index.d.ts +24 -43
- package/dist/index.js +231 -144
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +231 -144
- package/dist/index.mjs.map +1 -1
- package/package.json +11 -10
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(
|
|
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(
|
|
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
|
|
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
|
-
|
|
1287
|
+
z15 = offsetZ;
|
|
1188
1288
|
this.dt = dt;
|
|
1189
1289
|
} else {
|
|
1190
|
-
|
|
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
|
-
|
|
1298
|
+
z15 = dt.zone.name;
|
|
1199
1299
|
} else {
|
|
1200
|
-
|
|
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 ||
|
|
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 < -
|
|
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/
|
|
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:
|
|
7294
|
+
status: AssetStatus.BLOCKED
|
|
7178
7295
|
}));
|
|
7179
7296
|
}
|
|
7180
7297
|
return v;
|
|
@@ -7215,12 +7332,86 @@ 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
|
+
executiveSummary: zod.z.string(),
|
|
7359
|
+
overviewText: zod.z.string(),
|
|
7360
|
+
overviewDisplayLocation: zod.z.enum(["cover", "separate"]).default("cover"),
|
|
7361
|
+
publishedDate: zod.z.string().default(() => (/* @__PURE__ */ new Date()).toISOString().split("T")[0]),
|
|
7362
|
+
caseStudies: zod.z.array(
|
|
7363
|
+
zod.z.object({
|
|
7364
|
+
id: zod.z.string(),
|
|
7365
|
+
title: zod.z.string(),
|
|
7366
|
+
description: zod.z.string(),
|
|
7367
|
+
assetId: zod.z.number().optional(),
|
|
7368
|
+
proposalId: zod.z.number().optional(),
|
|
7369
|
+
screenshotUrl: zod.z.string().nullable().optional(),
|
|
7370
|
+
screenshotUrls: zod.z.array(zod.z.string()).optional(),
|
|
7371
|
+
imageUrl: zod.z.string().optional()
|
|
7372
|
+
})
|
|
7373
|
+
),
|
|
7374
|
+
productUpdates: zod.z.array(
|
|
7375
|
+
zod.z.object({
|
|
7376
|
+
id: zod.z.string(),
|
|
7377
|
+
title: zod.z.string(),
|
|
7378
|
+
content: zod.z.string(),
|
|
7379
|
+
createdAt: zod.z.string().optional()
|
|
7380
|
+
})
|
|
7381
|
+
),
|
|
7382
|
+
recommendations: zod.z.array(
|
|
7383
|
+
zod.z.object({
|
|
7384
|
+
id: zod.z.string(),
|
|
7385
|
+
title: zod.z.string(),
|
|
7386
|
+
content: zod.z.string()
|
|
7387
|
+
})
|
|
7388
|
+
),
|
|
7389
|
+
customMetrics: zod.z.object({
|
|
7390
|
+
totalReports: zod.z.number(),
|
|
7391
|
+
threatsBlocked: zod.z.number(),
|
|
7392
|
+
domainsBlocked: zod.z.number(),
|
|
7393
|
+
takedownsFiled: zod.z.number(),
|
|
7394
|
+
falsePositives: zod.z.number(),
|
|
7395
|
+
additionalNotes: zod.z.string().optional()
|
|
7396
|
+
}),
|
|
7397
|
+
recentTakedowns: zod.z.array(
|
|
7398
|
+
zod.z.object({
|
|
7399
|
+
id: zod.z.number(),
|
|
7400
|
+
content: zod.z.string(),
|
|
7401
|
+
type: zod.z.string(),
|
|
7402
|
+
createdAt: zod.z.coerce.date(),
|
|
7403
|
+
takedownCompletedAt: zod.z.coerce.date().nullable(),
|
|
7404
|
+
description: zod.z.string().nullable().optional()
|
|
7405
|
+
})
|
|
7406
|
+
).default([]),
|
|
7407
|
+
customPages: zod.z.array(
|
|
7408
|
+
zod.z.object({
|
|
7409
|
+
id: zod.z.string(),
|
|
7410
|
+
title: zod.z.string(),
|
|
7411
|
+
content: zod.z.string()
|
|
7412
|
+
})
|
|
7413
|
+
).default([])
|
|
7414
|
+
});
|
|
7224
7415
|
|
|
7225
7416
|
// src/client.ts
|
|
7226
7417
|
function trimTrailingSlashes(url) {
|
|
@@ -7305,112 +7496,6 @@ var ChainPatrolClient = class {
|
|
|
7305
7496
|
}
|
|
7306
7497
|
};
|
|
7307
7498
|
|
|
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
7499
|
// src/detector.ts
|
|
7415
7500
|
var DomainParseError = class extends Error {
|
|
7416
7501
|
constructor(message) {
|
|
@@ -7501,9 +7586,9 @@ var _ThreatDetector = class _ThreatDetector {
|
|
|
7501
7586
|
const res = yield this.client.asset.check({ content: domain });
|
|
7502
7587
|
this.logger.debug("Updating cache", { domain, status: res.status });
|
|
7503
7588
|
if (res.status === "ALLOWED") {
|
|
7504
|
-
yield this.addDomainToCache(domain,
|
|
7589
|
+
yield this.addDomainToCache(domain, StorageKeys.ALLOWLIST);
|
|
7505
7590
|
} else if (res.status === "BLOCKED") {
|
|
7506
|
-
yield this.addDomainToCache(domain,
|
|
7591
|
+
yield this.addDomainToCache(domain, StorageKeys.BLOCKLIST);
|
|
7507
7592
|
}
|
|
7508
7593
|
status = res.status;
|
|
7509
7594
|
} catch (e) {
|
|
@@ -7538,7 +7623,7 @@ var _ThreatDetector = class _ThreatDetector {
|
|
|
7538
7623
|
const domain = this.parseDomainOrThrow(url);
|
|
7539
7624
|
this.logger.debug("Allowing URL", { url, domain });
|
|
7540
7625
|
yield this.invalidateDomainInCaches(domain);
|
|
7541
|
-
yield this.addDomainToCache(domain,
|
|
7626
|
+
yield this.addDomainToCache(domain, StorageKeys.ALLOWLIST);
|
|
7542
7627
|
return {
|
|
7543
7628
|
ok: true,
|
|
7544
7629
|
url: domain
|
|
@@ -7559,7 +7644,7 @@ var _ThreatDetector = class _ThreatDetector {
|
|
|
7559
7644
|
const domain = this.parseDomainOrThrow(url);
|
|
7560
7645
|
this.logger.debug("Blocking URL", { url, domain });
|
|
7561
7646
|
yield this.invalidateDomainInCaches(domain);
|
|
7562
|
-
yield this.addDomainToCache(domain,
|
|
7647
|
+
yield this.addDomainToCache(domain, StorageKeys.BLOCKLIST);
|
|
7563
7648
|
return {
|
|
7564
7649
|
ok: true,
|
|
7565
7650
|
url: domain
|
|
@@ -7579,7 +7664,7 @@ var _ThreatDetector = class _ThreatDetector {
|
|
|
7579
7664
|
try {
|
|
7580
7665
|
const domain = this.parseDomainOrThrow(url);
|
|
7581
7666
|
this.logger.debug("Ignoring URL", { url, domain });
|
|
7582
|
-
yield this.addDomainToCache(domain,
|
|
7667
|
+
yield this.addDomainToCache(domain, StorageKeys.IGNORELIST);
|
|
7583
7668
|
return {
|
|
7584
7669
|
ok: true,
|
|
7585
7670
|
url: domain
|
|
@@ -7628,8 +7713,8 @@ var _ThreatDetector = class _ThreatDetector {
|
|
|
7628
7713
|
}
|
|
7629
7714
|
invalidateDomainInCaches(domain) {
|
|
7630
7715
|
return __async(this, null, function* () {
|
|
7631
|
-
yield this.invalidateDomainInCache(domain,
|
|
7632
|
-
yield this.invalidateDomainInCache(domain,
|
|
7716
|
+
yield this.invalidateDomainInCache(domain, StorageKeys.ALLOWLIST);
|
|
7717
|
+
yield this.invalidateDomainInCache(domain, StorageKeys.BLOCKLIST);
|
|
7633
7718
|
});
|
|
7634
7719
|
}
|
|
7635
7720
|
invalidateDomainInCache(domain, key) {
|
|
@@ -7686,11 +7771,11 @@ var _ThreatDetector = class _ThreatDetector {
|
|
|
7686
7771
|
}
|
|
7687
7772
|
getStatusFromCache(domain) {
|
|
7688
7773
|
return __async(this, null, function* () {
|
|
7689
|
-
if (yield this.isDomainInList(domain,
|
|
7774
|
+
if (yield this.isDomainInList(domain, StorageKeys.IGNORELIST)) {
|
|
7690
7775
|
return "IGNORED";
|
|
7691
|
-
} else if (yield this.isDomainInList(domain,
|
|
7776
|
+
} else if (yield this.isDomainInList(domain, StorageKeys.BLOCKLIST)) {
|
|
7692
7777
|
return "BLOCKED";
|
|
7693
|
-
} else if (yield this.isDomainInList(domain,
|
|
7778
|
+
} else if (yield this.isDomainInList(domain, StorageKeys.ALLOWLIST)) {
|
|
7694
7779
|
return "ALLOWED";
|
|
7695
7780
|
} else {
|
|
7696
7781
|
return "UNKNOWN";
|
|
@@ -7698,11 +7783,6 @@ var _ThreatDetector = class _ThreatDetector {
|
|
|
7698
7783
|
});
|
|
7699
7784
|
}
|
|
7700
7785
|
};
|
|
7701
|
-
_ThreatDetector.StorageKeys = {
|
|
7702
|
-
ALLOWLIST: "chainpatrol.allowed",
|
|
7703
|
-
BLOCKLIST: "chainpatrol.blocked",
|
|
7704
|
-
IGNORELIST: "chainpatrol.ignored"
|
|
7705
|
-
};
|
|
7706
7786
|
_ThreatDetector.CHAINPATROL_WARNING_URL = "https://app.chainpatrol.io/warning";
|
|
7707
7787
|
_ThreatDetector.Schema = zod.z.object({
|
|
7708
7788
|
version: zod.z.literal(1),
|
|
@@ -7712,13 +7792,20 @@ _ThreatDetector.Schema = zod.z.object({
|
|
|
7712
7792
|
});
|
|
7713
7793
|
var ThreatDetector = _ThreatDetector;
|
|
7714
7794
|
|
|
7795
|
+
// src/index.ts
|
|
7796
|
+
var Storage = {
|
|
7797
|
+
Memory,
|
|
7798
|
+
Extension,
|
|
7799
|
+
Browser
|
|
7800
|
+
};
|
|
7801
|
+
|
|
7715
7802
|
exports.ChainPatrolClient = ChainPatrolClient;
|
|
7716
7803
|
exports.ChainPatrolClientError = ChainPatrolClientError;
|
|
7717
7804
|
exports.ChainPatrolClientErrorCodes = ChainPatrolClientErrorCodes;
|
|
7718
7805
|
exports.DomainParseError = DomainParseError;
|
|
7719
7806
|
exports.Events = Events;
|
|
7720
7807
|
exports.Relay = Relay;
|
|
7721
|
-
exports.Storage =
|
|
7808
|
+
exports.Storage = Storage;
|
|
7722
7809
|
exports.ThreatDetector = ThreatDetector;
|
|
7723
7810
|
//# sourceMappingURL=index.js.map
|
|
7724
7811
|
//# sourceMappingURL=index.js.map
|