@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.mjs
CHANGED
|
@@ -33,10 +33,6 @@ var __objRest = (source, exclude) => {
|
|
|
33
33
|
}
|
|
34
34
|
return target;
|
|
35
35
|
};
|
|
36
|
-
var __export = (target, all) => {
|
|
37
|
-
for (var name in all)
|
|
38
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
39
|
-
};
|
|
40
36
|
var __async = (__this, __arguments, generator) => {
|
|
41
37
|
return new Promise((resolve, reject) => {
|
|
42
38
|
var fulfilled = (value) => {
|
|
@@ -58,6 +54,110 @@ var __async = (__this, __arguments, generator) => {
|
|
|
58
54
|
});
|
|
59
55
|
};
|
|
60
56
|
|
|
57
|
+
// src/constants.ts
|
|
58
|
+
var StorageKeys = {
|
|
59
|
+
ALLOWLIST: "chainpatrol.allowed",
|
|
60
|
+
BLOCKLIST: "chainpatrol.blocked",
|
|
61
|
+
IGNORELIST: "chainpatrol.ignored"
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
// src/storage/define-storage.ts
|
|
65
|
+
function defineStorage(config) {
|
|
66
|
+
return () => config({
|
|
67
|
+
keys: Object.values(StorageKeys)
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// src/storage/browser.ts
|
|
72
|
+
function isStorageAvailable(type) {
|
|
73
|
+
let storage;
|
|
74
|
+
try {
|
|
75
|
+
storage = window[type];
|
|
76
|
+
const x = "__storage_test__";
|
|
77
|
+
storage.setItem(x, x);
|
|
78
|
+
storage.removeItem(x);
|
|
79
|
+
return true;
|
|
80
|
+
} catch (e) {
|
|
81
|
+
return e instanceof DOMException && // everything except Firefox
|
|
82
|
+
(e.code === 22 || // Firefox
|
|
83
|
+
e.code === 1014 || // test name field too, because code might not be present
|
|
84
|
+
// everything except Firefox
|
|
85
|
+
e.name === "QuotaExceededError" || // Firefox
|
|
86
|
+
e.name === "NS_ERROR_DOM_QUOTA_REACHED") && // acknowledge QuotaExceededError only if there's something already stored
|
|
87
|
+
storage && storage.length !== 0;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
var Browser = defineStorage(({ keys }) => {
|
|
91
|
+
if (!isStorageAvailable("localStorage")) {
|
|
92
|
+
throw new Error("localStorage is not available");
|
|
93
|
+
}
|
|
94
|
+
return {
|
|
95
|
+
get: (key) => __async(null, null, function* () {
|
|
96
|
+
return localStorage.getItem(key);
|
|
97
|
+
}),
|
|
98
|
+
set: (key, value) => __async(null, null, function* () {
|
|
99
|
+
localStorage.setItem(key, value);
|
|
100
|
+
}),
|
|
101
|
+
delete: (key) => __async(null, null, function* () {
|
|
102
|
+
localStorage.removeItem(key);
|
|
103
|
+
}),
|
|
104
|
+
size: () => __async(null, null, function* () {
|
|
105
|
+
var _a, _b;
|
|
106
|
+
let total = 0;
|
|
107
|
+
for (let i = 0; i < localStorage.length; i++) {
|
|
108
|
+
const key = localStorage.key(i);
|
|
109
|
+
if (key && keys.includes(key)) {
|
|
110
|
+
total += (_b = (_a = localStorage.getItem(key)) == null ? void 0 : _a.length) != null ? _b : 0;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
return total;
|
|
114
|
+
})
|
|
115
|
+
};
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
// src/storage/extension.ts
|
|
119
|
+
var Extension = defineStorage(({ keys }) => {
|
|
120
|
+
return {
|
|
121
|
+
get: (key) => __async(null, null, function* () {
|
|
122
|
+
const result = yield chrome.storage.local.get(key);
|
|
123
|
+
return result[key];
|
|
124
|
+
}),
|
|
125
|
+
set: (key, value) => __async(null, null, function* () {
|
|
126
|
+
yield chrome.storage.local.set({ [key]: value });
|
|
127
|
+
}),
|
|
128
|
+
delete: (key) => __async(null, null, function* () {
|
|
129
|
+
yield chrome.storage.local.remove(key);
|
|
130
|
+
}),
|
|
131
|
+
size: () => __async(null, null, function* () {
|
|
132
|
+
const usageBytes = yield chrome.storage.local.getBytesInUse(keys);
|
|
133
|
+
return usageBytes;
|
|
134
|
+
})
|
|
135
|
+
};
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
// src/storage/memory.ts
|
|
139
|
+
var Memory = defineStorage(() => {
|
|
140
|
+
const storage = /* @__PURE__ */ new Map();
|
|
141
|
+
return {
|
|
142
|
+
get: (key) => __async(null, null, function* () {
|
|
143
|
+
return storage.get(key) || null;
|
|
144
|
+
}),
|
|
145
|
+
set: (key, value) => __async(null, null, function* () {
|
|
146
|
+
storage.set(key, value);
|
|
147
|
+
}),
|
|
148
|
+
delete: (key) => __async(null, null, function* () {
|
|
149
|
+
storage.delete(key);
|
|
150
|
+
}),
|
|
151
|
+
size: () => __async(null, null, function* () {
|
|
152
|
+
let total = 0;
|
|
153
|
+
for (const value of storage.values()) {
|
|
154
|
+
total += value.length;
|
|
155
|
+
}
|
|
156
|
+
return total;
|
|
157
|
+
})
|
|
158
|
+
};
|
|
159
|
+
});
|
|
160
|
+
|
|
61
161
|
// src/events.ts
|
|
62
162
|
var ContinueAtOwnRisk = "CHAINPATROL_CONTINUE_AT_OWN_RISK";
|
|
63
163
|
var IgnorelistUpdated = "CHAINPATROL_IGNORELIST_UPDATED";
|
|
@@ -143,7 +243,7 @@ function getBackgroundScriptHandle() {
|
|
|
143
243
|
removeListener: (callback) => {
|
|
144
244
|
runtime.onMessage.removeListener(callback);
|
|
145
245
|
},
|
|
146
|
-
postMessage: (message) => __async(
|
|
246
|
+
postMessage: (message) => __async(null, null, function* () {
|
|
147
247
|
const [tab] = yield globalThis.chrome.tabs.query({
|
|
148
248
|
active: true,
|
|
149
249
|
lastFocusedWindow: true
|
|
@@ -165,7 +265,7 @@ function getContentScriptHandle() {
|
|
|
165
265
|
removeListener: (callback) => {
|
|
166
266
|
runtime.onMessage.removeListener(callback);
|
|
167
267
|
},
|
|
168
|
-
postMessage: (message) => __async(
|
|
268
|
+
postMessage: (message) => __async(null, null, function* () {
|
|
169
269
|
runtime.sendMessage(message).catch((error) => {
|
|
170
270
|
console.error("Failed to send message", { message, error });
|
|
171
271
|
});
|
|
@@ -283,7 +383,7 @@ var supportedProtocols = /* @__PURE__ */ new Set([
|
|
|
283
383
|
var hasCustomProtocol = (urlString) => {
|
|
284
384
|
try {
|
|
285
385
|
const { protocol } = new URL(urlString);
|
|
286
|
-
return protocol.endsWith(":") && !supportedProtocols.has(protocol);
|
|
386
|
+
return protocol.endsWith(":") && !protocol.includes(".") && !supportedProtocols.has(protocol);
|
|
287
387
|
} catch (e) {
|
|
288
388
|
return false;
|
|
289
389
|
}
|
|
@@ -494,7 +594,7 @@ z.object({
|
|
|
494
594
|
assetId: z.number(),
|
|
495
595
|
name: z.string().optional(),
|
|
496
596
|
description: z.string().optional(),
|
|
497
|
-
assetGroupId: z.number().optional(),
|
|
597
|
+
assetGroupId: z.number().nullable().optional(),
|
|
498
598
|
updatedByOrganizationId: z.number().optional()
|
|
499
599
|
});
|
|
500
600
|
z.object({
|
|
@@ -1175,17 +1275,17 @@ var PolyDateFormatter = class {
|
|
|
1175
1275
|
constructor(dt, intl, opts) {
|
|
1176
1276
|
this.opts = opts;
|
|
1177
1277
|
this.originalZone = void 0;
|
|
1178
|
-
let
|
|
1278
|
+
let z15 = void 0;
|
|
1179
1279
|
if (this.opts.timeZone) {
|
|
1180
1280
|
this.dt = dt;
|
|
1181
1281
|
} else if (dt.zone.type === "fixed") {
|
|
1182
1282
|
const gmtOffset = -1 * (dt.offset / 60);
|
|
1183
1283
|
const offsetZ = gmtOffset >= 0 ? `Etc/GMT+${gmtOffset}` : `Etc/GMT${gmtOffset}`;
|
|
1184
1284
|
if (dt.offset !== 0 && IANAZone.create(offsetZ).valid) {
|
|
1185
|
-
|
|
1285
|
+
z15 = offsetZ;
|
|
1186
1286
|
this.dt = dt;
|
|
1187
1287
|
} else {
|
|
1188
|
-
|
|
1288
|
+
z15 = "UTC";
|
|
1189
1289
|
this.dt = dt.offset === 0 ? dt : dt.setZone("UTC").plus({ minutes: dt.offset });
|
|
1190
1290
|
this.originalZone = dt.zone;
|
|
1191
1291
|
}
|
|
@@ -1193,14 +1293,14 @@ var PolyDateFormatter = class {
|
|
|
1193
1293
|
this.dt = dt;
|
|
1194
1294
|
} else if (dt.zone.type === "iana") {
|
|
1195
1295
|
this.dt = dt;
|
|
1196
|
-
|
|
1296
|
+
z15 = dt.zone.name;
|
|
1197
1297
|
} else {
|
|
1198
|
-
|
|
1298
|
+
z15 = "UTC";
|
|
1199
1299
|
this.dt = dt.setZone("UTC").plus({ minutes: dt.offset });
|
|
1200
1300
|
this.originalZone = dt.zone;
|
|
1201
1301
|
}
|
|
1202
1302
|
const intlOpts = __spreadValues({}, this.opts);
|
|
1203
|
-
intlOpts.timeZone = intlOpts.timeZone ||
|
|
1303
|
+
intlOpts.timeZone = intlOpts.timeZone || z15;
|
|
1204
1304
|
this.dtf = getCachedDTF(intl, intlOpts);
|
|
1205
1305
|
}
|
|
1206
1306
|
format() {
|
|
@@ -5320,7 +5420,7 @@ var DateTime = class _DateTime {
|
|
|
5320
5420
|
throw new InvalidArgumentError(
|
|
5321
5421
|
`fromMillis requires a numerical input, but received a ${typeof milliseconds} with value ${milliseconds}`
|
|
5322
5422
|
);
|
|
5323
|
-
} else if (milliseconds < -
|
|
5423
|
+
} else if (milliseconds < -MAX_DATE || milliseconds > MAX_DATE) {
|
|
5324
5424
|
return _DateTime.invalid("Timestamp out of range");
|
|
5325
5425
|
} else {
|
|
5326
5426
|
return new _DateTime({
|
|
@@ -6917,7 +7017,7 @@ function friendlyDateTime(dateTimeish) {
|
|
|
6917
7017
|
}
|
|
6918
7018
|
}
|
|
6919
7019
|
|
|
6920
|
-
// ../../internal/database/
|
|
7020
|
+
// ../../internal/database/src/generated/enums.ts
|
|
6921
7021
|
var AssetType = {
|
|
6922
7022
|
URL: "URL",
|
|
6923
7023
|
PAGE: "PAGE",
|
|
@@ -6950,13 +7050,26 @@ var AssetType = {
|
|
|
6950
7050
|
DISCORD_USER: "DISCORD_USER",
|
|
6951
7051
|
QUORA: "QUORA",
|
|
6952
7052
|
GITHUB: "GITHUB",
|
|
6953
|
-
TEACHABLE: "TEACHABLE"
|
|
7053
|
+
TEACHABLE: "TEACHABLE",
|
|
7054
|
+
SUBSTACK: "SUBSTACK",
|
|
7055
|
+
DEBANK: "DEBANK",
|
|
7056
|
+
TAWK_TO: "TAWK_TO",
|
|
7057
|
+
JOTFORM: "JOTFORM",
|
|
7058
|
+
PRIMAL: "PRIMAL",
|
|
7059
|
+
BLUESKY: "BLUESKY",
|
|
7060
|
+
SNAPCHAT: "SNAPCHAT",
|
|
7061
|
+
DESO: "DESO"
|
|
6954
7062
|
};
|
|
6955
7063
|
var AssetStatus = {
|
|
6956
7064
|
UNKNOWN: "UNKNOWN",
|
|
6957
7065
|
ALLOWED: "ALLOWED",
|
|
6958
7066
|
BLOCKED: "BLOCKED"
|
|
6959
7067
|
};
|
|
7068
|
+
var ProposalReviewStatus = {
|
|
7069
|
+
PENDING: "PENDING",
|
|
7070
|
+
APPROVED: "APPROVED",
|
|
7071
|
+
REJECTED: "REJECTED"
|
|
7072
|
+
};
|
|
6960
7073
|
|
|
6961
7074
|
// ../../internal/validation/src/public/asset/changelog.ts
|
|
6962
7075
|
var DateString = z.string().regex(/^\d{4}-\d{2}-\d{2}$/, "Must be in the format `YYYY-MM-DD`").pipe(z.coerce.date());
|
|
@@ -7026,6 +7139,7 @@ var AssetRecordSource = /* @__PURE__ */ ((AssetRecordSource2) => {
|
|
|
7026
7139
|
AssetRecordSource2["EthPhishingDetect"] = "eth-phishing-detect";
|
|
7027
7140
|
AssetRecordSource2["Phishfort"] = "phishfort";
|
|
7028
7141
|
AssetRecordSource2["Seal"] = "seal";
|
|
7142
|
+
AssetRecordSource2["PolkadotPhishing"] = "polkadot-phishing";
|
|
7029
7143
|
return AssetRecordSource2;
|
|
7030
7144
|
})(AssetRecordSource || {});
|
|
7031
7145
|
var AssetStatusReason = /* @__PURE__ */ ((AssetStatusReason2) => {
|
|
@@ -7034,6 +7148,7 @@ var AssetStatusReason = /* @__PURE__ */ ((AssetStatusReason2) => {
|
|
|
7034
7148
|
AssetStatusReason2["SourceError"] = "source-error";
|
|
7035
7149
|
AssetStatusReason2["ParentDomain"] = "parent-domain";
|
|
7036
7150
|
AssetStatusReason2["HostingDomain"] = "hosting-domain";
|
|
7151
|
+
AssetStatusReason2["Timeout"] = "timeout";
|
|
7037
7152
|
return AssetStatusReason2;
|
|
7038
7153
|
})(AssetStatusReason || {});
|
|
7039
7154
|
var AssetCheckErrorCodes = /* @__PURE__ */ ((AssetCheckErrorCodes2) => {
|
|
@@ -7082,7 +7197,7 @@ var assetListInputSchema = z.object({
|
|
|
7082
7197
|
endDate: z.string().transform((str) => new Date(str)).optional().describe(
|
|
7083
7198
|
"The end date to list assets from. This should be in the format `YYYY-MM-DD` and is inclusive."
|
|
7084
7199
|
),
|
|
7085
|
-
per_page: z.number().int().min(1).max(1e4).optional().describe("The number of assets to return per page"),
|
|
7200
|
+
per_page: z.number().int().min(1).max(1e4).optional().default(100).describe("The number of assets to return per page"),
|
|
7086
7201
|
/**
|
|
7087
7202
|
* Optional next_page cursor for pagination; indicates where the next page of results should start.
|
|
7088
7203
|
*/
|
|
@@ -7133,13 +7248,15 @@ var reportCreateInputSchema = z.object({
|
|
|
7133
7248
|
/** Optional Telegram Group ID associated with the organization. */
|
|
7134
7249
|
telegramGroupId: z.string().describe("Telegram Group ID linked to the organization on ChainPatrol").optional(),
|
|
7135
7250
|
/** Title of the report. */
|
|
7136
|
-
title: z.string().min(3).describe("Title of the report"),
|
|
7251
|
+
title: z.string().min(3).describe("Title of the report").optional(),
|
|
7137
7252
|
/** Description of the report, supporting markdown syntax. */
|
|
7138
|
-
description: z.string().describe("Description of the report. Supports markdown"),
|
|
7253
|
+
description: z.string().describe("Description of the report. Supports markdown").optional(),
|
|
7139
7254
|
/** Optional contact information of the reporter. */
|
|
7140
7255
|
contactInfo: z.string().optional(),
|
|
7141
7256
|
/** Optional list of URLs for images to be attached to the report. */
|
|
7142
7257
|
attachmentUrls: z.array(z.string().url()).optional().describe("URLs of images to attach to the report"),
|
|
7258
|
+
/** Optional link to the external submission (e.g. Telegram message link) */
|
|
7259
|
+
externalSubmissionLink: z.string().url().optional().describe("Link to the external submission (e.g. Telegram message link)"),
|
|
7143
7260
|
/**
|
|
7144
7261
|
* List of assets with their content and proposed status.
|
|
7145
7262
|
* Each asset can optionally include a screenshot object.
|
|
@@ -7172,7 +7289,7 @@ var reportCreateInputSchema = z.object({
|
|
|
7172
7289
|
if (v.rawAssetsInput && v.assets.length === 0) {
|
|
7173
7290
|
v.assets = v.rawAssetsInput.split("\n").map((line) => line.trim()).filter((line) => line.length > 0).map((line) => ({
|
|
7174
7291
|
content: line,
|
|
7175
|
-
status:
|
|
7292
|
+
status: AssetStatus.BLOCKED
|
|
7176
7293
|
}));
|
|
7177
7294
|
}
|
|
7178
7295
|
return v;
|
|
@@ -7213,12 +7330,86 @@ z.object({
|
|
|
7213
7330
|
z.object({
|
|
7214
7331
|
id: z.number(),
|
|
7215
7332
|
content: z.string(),
|
|
7216
|
-
status: z.nativeEnum(AssetStatus)
|
|
7333
|
+
status: z.nativeEnum(AssetStatus),
|
|
7334
|
+
reviewStatus: z.nativeEnum(ProposalReviewStatus)
|
|
7217
7335
|
})
|
|
7218
7336
|
)
|
|
7219
7337
|
})
|
|
7220
7338
|
)
|
|
7221
7339
|
});
|
|
7340
|
+
z.object({
|
|
7341
|
+
selectedOrgs: z.array(
|
|
7342
|
+
z.object({
|
|
7343
|
+
id: z.number(),
|
|
7344
|
+
name: z.string(),
|
|
7345
|
+
slug: z.string(),
|
|
7346
|
+
avatarUrl: z.string().nullable().optional()
|
|
7347
|
+
})
|
|
7348
|
+
),
|
|
7349
|
+
parentOrg: z.string(),
|
|
7350
|
+
startDate: z.string(),
|
|
7351
|
+
endDate: z.string(),
|
|
7352
|
+
weekNumber: z.number().max(53).optional(),
|
|
7353
|
+
organizationLogo: z.string(),
|
|
7354
|
+
organizationLogos: z.record(z.string(), z.string()),
|
|
7355
|
+
hiddenLogos: z.record(z.string(), z.boolean()).default({}),
|
|
7356
|
+
executiveSummary: z.string(),
|
|
7357
|
+
overviewText: z.string(),
|
|
7358
|
+
overviewDisplayLocation: z.enum(["cover", "separate"]).default("cover"),
|
|
7359
|
+
publishedDate: z.string().default(() => (/* @__PURE__ */ new Date()).toISOString().split("T")[0]),
|
|
7360
|
+
caseStudies: z.array(
|
|
7361
|
+
z.object({
|
|
7362
|
+
id: z.string(),
|
|
7363
|
+
title: z.string(),
|
|
7364
|
+
description: z.string(),
|
|
7365
|
+
assetId: z.number().optional(),
|
|
7366
|
+
proposalId: z.number().optional(),
|
|
7367
|
+
screenshotUrl: z.string().nullable().optional(),
|
|
7368
|
+
screenshotUrls: z.array(z.string()).optional(),
|
|
7369
|
+
imageUrl: z.string().optional()
|
|
7370
|
+
})
|
|
7371
|
+
),
|
|
7372
|
+
productUpdates: z.array(
|
|
7373
|
+
z.object({
|
|
7374
|
+
id: z.string(),
|
|
7375
|
+
title: z.string(),
|
|
7376
|
+
content: z.string(),
|
|
7377
|
+
createdAt: z.string().optional()
|
|
7378
|
+
})
|
|
7379
|
+
),
|
|
7380
|
+
recommendations: z.array(
|
|
7381
|
+
z.object({
|
|
7382
|
+
id: z.string(),
|
|
7383
|
+
title: z.string(),
|
|
7384
|
+
content: z.string()
|
|
7385
|
+
})
|
|
7386
|
+
),
|
|
7387
|
+
customMetrics: z.object({
|
|
7388
|
+
totalReports: z.number(),
|
|
7389
|
+
threatsBlocked: z.number(),
|
|
7390
|
+
domainsBlocked: z.number(),
|
|
7391
|
+
takedownsFiled: z.number(),
|
|
7392
|
+
falsePositives: z.number(),
|
|
7393
|
+
additionalNotes: z.string().optional()
|
|
7394
|
+
}),
|
|
7395
|
+
recentTakedowns: z.array(
|
|
7396
|
+
z.object({
|
|
7397
|
+
id: z.number(),
|
|
7398
|
+
content: z.string(),
|
|
7399
|
+
type: z.string(),
|
|
7400
|
+
createdAt: z.coerce.date(),
|
|
7401
|
+
takedownCompletedAt: z.coerce.date().nullable(),
|
|
7402
|
+
description: z.string().nullable().optional()
|
|
7403
|
+
})
|
|
7404
|
+
).default([]),
|
|
7405
|
+
customPages: z.array(
|
|
7406
|
+
z.object({
|
|
7407
|
+
id: z.string(),
|
|
7408
|
+
title: z.string(),
|
|
7409
|
+
content: z.string()
|
|
7410
|
+
})
|
|
7411
|
+
).default([])
|
|
7412
|
+
});
|
|
7222
7413
|
|
|
7223
7414
|
// src/client.ts
|
|
7224
7415
|
function trimTrailingSlashes(url) {
|
|
@@ -7303,112 +7494,6 @@ var ChainPatrolClient = class {
|
|
|
7303
7494
|
}
|
|
7304
7495
|
};
|
|
7305
7496
|
|
|
7306
|
-
// src/storage/index.ts
|
|
7307
|
-
var storage_exports = {};
|
|
7308
|
-
__export(storage_exports, {
|
|
7309
|
-
Browser: () => Browser,
|
|
7310
|
-
Extension: () => Extension,
|
|
7311
|
-
Memory: () => Memory,
|
|
7312
|
-
defineStorage: () => defineStorage
|
|
7313
|
-
});
|
|
7314
|
-
|
|
7315
|
-
// src/storage/define-storage.ts
|
|
7316
|
-
function defineStorage(config) {
|
|
7317
|
-
return () => config({
|
|
7318
|
-
keys: Object.values(ThreatDetector.StorageKeys)
|
|
7319
|
-
});
|
|
7320
|
-
}
|
|
7321
|
-
|
|
7322
|
-
// src/storage/extension.ts
|
|
7323
|
-
var Extension = defineStorage(({ keys }) => {
|
|
7324
|
-
return {
|
|
7325
|
-
get: (key) => __async(void 0, null, function* () {
|
|
7326
|
-
const result = yield chrome.storage.local.get(key);
|
|
7327
|
-
return result[key];
|
|
7328
|
-
}),
|
|
7329
|
-
set: (key, value) => __async(void 0, null, function* () {
|
|
7330
|
-
yield chrome.storage.local.set({ [key]: value });
|
|
7331
|
-
}),
|
|
7332
|
-
delete: (key) => __async(void 0, null, function* () {
|
|
7333
|
-
yield chrome.storage.local.remove(key);
|
|
7334
|
-
}),
|
|
7335
|
-
size: () => __async(void 0, null, function* () {
|
|
7336
|
-
const usageBytes = yield chrome.storage.local.getBytesInUse(keys);
|
|
7337
|
-
return usageBytes;
|
|
7338
|
-
})
|
|
7339
|
-
};
|
|
7340
|
-
});
|
|
7341
|
-
|
|
7342
|
-
// src/storage/browser.ts
|
|
7343
|
-
function isStorageAvailable(type) {
|
|
7344
|
-
let storage;
|
|
7345
|
-
try {
|
|
7346
|
-
storage = window[type];
|
|
7347
|
-
const x = "__storage_test__";
|
|
7348
|
-
storage.setItem(x, x);
|
|
7349
|
-
storage.removeItem(x);
|
|
7350
|
-
return true;
|
|
7351
|
-
} catch (e) {
|
|
7352
|
-
return e instanceof DOMException && // everything except Firefox
|
|
7353
|
-
(e.code === 22 || // Firefox
|
|
7354
|
-
e.code === 1014 || // test name field too, because code might not be present
|
|
7355
|
-
// everything except Firefox
|
|
7356
|
-
e.name === "QuotaExceededError" || // Firefox
|
|
7357
|
-
e.name === "NS_ERROR_DOM_QUOTA_REACHED") && // acknowledge QuotaExceededError only if there's something already stored
|
|
7358
|
-
storage && storage.length !== 0;
|
|
7359
|
-
}
|
|
7360
|
-
}
|
|
7361
|
-
var Browser = defineStorage(({ keys }) => {
|
|
7362
|
-
if (!isStorageAvailable("localStorage")) {
|
|
7363
|
-
throw new Error("localStorage is not available");
|
|
7364
|
-
}
|
|
7365
|
-
return {
|
|
7366
|
-
get: (key) => __async(void 0, null, function* () {
|
|
7367
|
-
return localStorage.getItem(key);
|
|
7368
|
-
}),
|
|
7369
|
-
set: (key, value) => __async(void 0, null, function* () {
|
|
7370
|
-
localStorage.setItem(key, value);
|
|
7371
|
-
}),
|
|
7372
|
-
delete: (key) => __async(void 0, null, function* () {
|
|
7373
|
-
localStorage.removeItem(key);
|
|
7374
|
-
}),
|
|
7375
|
-
size: () => __async(void 0, null, function* () {
|
|
7376
|
-
var _a, _b;
|
|
7377
|
-
let total = 0;
|
|
7378
|
-
for (let i = 0; i < localStorage.length; i++) {
|
|
7379
|
-
const key = localStorage.key(i);
|
|
7380
|
-
if (key && keys.includes(key)) {
|
|
7381
|
-
total += (_b = (_a = localStorage.getItem(key)) == null ? void 0 : _a.length) != null ? _b : 0;
|
|
7382
|
-
}
|
|
7383
|
-
}
|
|
7384
|
-
return total;
|
|
7385
|
-
})
|
|
7386
|
-
};
|
|
7387
|
-
});
|
|
7388
|
-
|
|
7389
|
-
// src/storage/memory.ts
|
|
7390
|
-
var Memory = defineStorage(() => {
|
|
7391
|
-
const storage = /* @__PURE__ */ new Map();
|
|
7392
|
-
return {
|
|
7393
|
-
get: (key) => __async(void 0, null, function* () {
|
|
7394
|
-
return storage.get(key) || null;
|
|
7395
|
-
}),
|
|
7396
|
-
set: (key, value) => __async(void 0, null, function* () {
|
|
7397
|
-
storage.set(key, value);
|
|
7398
|
-
}),
|
|
7399
|
-
delete: (key) => __async(void 0, null, function* () {
|
|
7400
|
-
storage.delete(key);
|
|
7401
|
-
}),
|
|
7402
|
-
size: () => __async(void 0, null, function* () {
|
|
7403
|
-
let total = 0;
|
|
7404
|
-
for (const value of storage.values()) {
|
|
7405
|
-
total += value.length;
|
|
7406
|
-
}
|
|
7407
|
-
return total;
|
|
7408
|
-
})
|
|
7409
|
-
};
|
|
7410
|
-
});
|
|
7411
|
-
|
|
7412
7497
|
// src/detector.ts
|
|
7413
7498
|
var DomainParseError = class extends Error {
|
|
7414
7499
|
constructor(message) {
|
|
@@ -7499,9 +7584,9 @@ var _ThreatDetector = class _ThreatDetector {
|
|
|
7499
7584
|
const res = yield this.client.asset.check({ content: domain });
|
|
7500
7585
|
this.logger.debug("Updating cache", { domain, status: res.status });
|
|
7501
7586
|
if (res.status === "ALLOWED") {
|
|
7502
|
-
yield this.addDomainToCache(domain,
|
|
7587
|
+
yield this.addDomainToCache(domain, StorageKeys.ALLOWLIST);
|
|
7503
7588
|
} else if (res.status === "BLOCKED") {
|
|
7504
|
-
yield this.addDomainToCache(domain,
|
|
7589
|
+
yield this.addDomainToCache(domain, StorageKeys.BLOCKLIST);
|
|
7505
7590
|
}
|
|
7506
7591
|
status = res.status;
|
|
7507
7592
|
} catch (e) {
|
|
@@ -7536,7 +7621,7 @@ var _ThreatDetector = class _ThreatDetector {
|
|
|
7536
7621
|
const domain = this.parseDomainOrThrow(url);
|
|
7537
7622
|
this.logger.debug("Allowing URL", { url, domain });
|
|
7538
7623
|
yield this.invalidateDomainInCaches(domain);
|
|
7539
|
-
yield this.addDomainToCache(domain,
|
|
7624
|
+
yield this.addDomainToCache(domain, StorageKeys.ALLOWLIST);
|
|
7540
7625
|
return {
|
|
7541
7626
|
ok: true,
|
|
7542
7627
|
url: domain
|
|
@@ -7557,7 +7642,7 @@ var _ThreatDetector = class _ThreatDetector {
|
|
|
7557
7642
|
const domain = this.parseDomainOrThrow(url);
|
|
7558
7643
|
this.logger.debug("Blocking URL", { url, domain });
|
|
7559
7644
|
yield this.invalidateDomainInCaches(domain);
|
|
7560
|
-
yield this.addDomainToCache(domain,
|
|
7645
|
+
yield this.addDomainToCache(domain, StorageKeys.BLOCKLIST);
|
|
7561
7646
|
return {
|
|
7562
7647
|
ok: true,
|
|
7563
7648
|
url: domain
|
|
@@ -7577,7 +7662,7 @@ var _ThreatDetector = class _ThreatDetector {
|
|
|
7577
7662
|
try {
|
|
7578
7663
|
const domain = this.parseDomainOrThrow(url);
|
|
7579
7664
|
this.logger.debug("Ignoring URL", { url, domain });
|
|
7580
|
-
yield this.addDomainToCache(domain,
|
|
7665
|
+
yield this.addDomainToCache(domain, StorageKeys.IGNORELIST);
|
|
7581
7666
|
return {
|
|
7582
7667
|
ok: true,
|
|
7583
7668
|
url: domain
|
|
@@ -7626,8 +7711,8 @@ var _ThreatDetector = class _ThreatDetector {
|
|
|
7626
7711
|
}
|
|
7627
7712
|
invalidateDomainInCaches(domain) {
|
|
7628
7713
|
return __async(this, null, function* () {
|
|
7629
|
-
yield this.invalidateDomainInCache(domain,
|
|
7630
|
-
yield this.invalidateDomainInCache(domain,
|
|
7714
|
+
yield this.invalidateDomainInCache(domain, StorageKeys.ALLOWLIST);
|
|
7715
|
+
yield this.invalidateDomainInCache(domain, StorageKeys.BLOCKLIST);
|
|
7631
7716
|
});
|
|
7632
7717
|
}
|
|
7633
7718
|
invalidateDomainInCache(domain, key) {
|
|
@@ -7684,11 +7769,11 @@ var _ThreatDetector = class _ThreatDetector {
|
|
|
7684
7769
|
}
|
|
7685
7770
|
getStatusFromCache(domain) {
|
|
7686
7771
|
return __async(this, null, function* () {
|
|
7687
|
-
if (yield this.isDomainInList(domain,
|
|
7772
|
+
if (yield this.isDomainInList(domain, StorageKeys.IGNORELIST)) {
|
|
7688
7773
|
return "IGNORED";
|
|
7689
|
-
} else if (yield this.isDomainInList(domain,
|
|
7774
|
+
} else if (yield this.isDomainInList(domain, StorageKeys.BLOCKLIST)) {
|
|
7690
7775
|
return "BLOCKED";
|
|
7691
|
-
} else if (yield this.isDomainInList(domain,
|
|
7776
|
+
} else if (yield this.isDomainInList(domain, StorageKeys.ALLOWLIST)) {
|
|
7692
7777
|
return "ALLOWED";
|
|
7693
7778
|
} else {
|
|
7694
7779
|
return "UNKNOWN";
|
|
@@ -7696,11 +7781,6 @@ var _ThreatDetector = class _ThreatDetector {
|
|
|
7696
7781
|
});
|
|
7697
7782
|
}
|
|
7698
7783
|
};
|
|
7699
|
-
_ThreatDetector.StorageKeys = {
|
|
7700
|
-
ALLOWLIST: "chainpatrol.allowed",
|
|
7701
|
-
BLOCKLIST: "chainpatrol.blocked",
|
|
7702
|
-
IGNORELIST: "chainpatrol.ignored"
|
|
7703
|
-
};
|
|
7704
7784
|
_ThreatDetector.CHAINPATROL_WARNING_URL = "https://app.chainpatrol.io/warning";
|
|
7705
7785
|
_ThreatDetector.Schema = z.object({
|
|
7706
7786
|
version: z.literal(1),
|
|
@@ -7710,6 +7790,13 @@ _ThreatDetector.Schema = z.object({
|
|
|
7710
7790
|
});
|
|
7711
7791
|
var ThreatDetector = _ThreatDetector;
|
|
7712
7792
|
|
|
7713
|
-
|
|
7793
|
+
// src/index.ts
|
|
7794
|
+
var Storage = {
|
|
7795
|
+
Memory,
|
|
7796
|
+
Extension,
|
|
7797
|
+
Browser
|
|
7798
|
+
};
|
|
7799
|
+
|
|
7800
|
+
export { ChainPatrolClient, ChainPatrolClientError, ChainPatrolClientErrorCodes, DomainParseError, Events, Relay, Storage, ThreatDetector };
|
|
7714
7801
|
//# sourceMappingURL=index.mjs.map
|
|
7715
7802
|
//# sourceMappingURL=index.mjs.map
|