@chainpatrol/sdk 0.4.1 → 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 +194 -0
- package/dist/index.d.ts +24 -49
- package/dist/index.js +2540 -1720
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2540 -1720
- package/dist/index.mjs.map +1 -1
- package/package.json +28 -13
package/README.md
CHANGED
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
import { AssetCheckInput, AssetCheckOutput, AssetListInput, AssetListOutput, ReportCreateInput } from '@chainpatrol/validation';
|
|
2
|
+
|
|
3
|
+
declare const ContinueAtOwnRisk = "CHAINPATROL_CONTINUE_AT_OWN_RISK";
|
|
4
|
+
declare const IgnorelistUpdated = "CHAINPATROL_IGNORELIST_UPDATED";
|
|
5
|
+
declare const CloseCurrentTab = "CHAINPATROL_CLOSE_CURRENT_TAB";
|
|
6
|
+
declare const Events: {
|
|
7
|
+
readonly ContinueAtOwnRisk: "CHAINPATROL_CONTINUE_AT_OWN_RISK";
|
|
8
|
+
readonly IgnorelistUpdated: "CHAINPATROL_IGNORELIST_UPDATED";
|
|
9
|
+
readonly CloseCurrentTab: "CHAINPATROL_CLOSE_CURRENT_TAB";
|
|
10
|
+
};
|
|
11
|
+
type EventData = {
|
|
12
|
+
[ContinueAtOwnRisk]: {
|
|
13
|
+
domain: string;
|
|
14
|
+
};
|
|
15
|
+
[IgnorelistUpdated]: {
|
|
16
|
+
domain: string;
|
|
17
|
+
};
|
|
18
|
+
[CloseCurrentTab]: {};
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
type Handle = {
|
|
22
|
+
addListener: (callback: (message: any) => void) => void;
|
|
23
|
+
removeListener: (callback: (message: any) => void) => void;
|
|
24
|
+
postMessage: (message: any) => void;
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Relay contains methods for implementing an event relay. It is used to
|
|
28
|
+
* forward events between Javascript contexts:
|
|
29
|
+
*
|
|
30
|
+
* `<window>` <-> `<content script>` <-> `<background script>`
|
|
31
|
+
*
|
|
32
|
+
* Call `Relay.send` to send an event from one context to another. Call
|
|
33
|
+
* `Relay.on` to listen for events in the current context. Call `Relay.run`
|
|
34
|
+
* to start listening for events in the current context and forward them
|
|
35
|
+
* to all other contexts.
|
|
36
|
+
*/
|
|
37
|
+
declare class Relay {
|
|
38
|
+
protected static handles: Handle[];
|
|
39
|
+
private static readonly logger;
|
|
40
|
+
static send<EventType extends keyof EventData>(type: EventType, data: EventData[EventType]): void;
|
|
41
|
+
static run(events: (keyof EventData)[]): () => void;
|
|
42
|
+
private static handleMessage;
|
|
43
|
+
static on<EventType extends keyof EventData>(targetEvent: EventType, callback: (data: EventData[EventType]) => void): () => void;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
type ChainPatrolClientOptions = {
|
|
47
|
+
apiKey: string;
|
|
48
|
+
baseUrl?: string;
|
|
49
|
+
};
|
|
50
|
+
type ApiRequest = {
|
|
51
|
+
path: string[];
|
|
52
|
+
method: "GET" | "POST" | "PUT" | "DELETE";
|
|
53
|
+
body?: unknown;
|
|
54
|
+
};
|
|
55
|
+
type AssetType = "URL" | "PAGE" | "ADDRESS";
|
|
56
|
+
type AssetStatus = "ALLOWED" | "BLOCKED" | "UNKNOWN";
|
|
57
|
+
declare class ChainPatrolClientError extends Error {
|
|
58
|
+
readonly code: ChainPatrolClientErrorCodes;
|
|
59
|
+
constructor(message: string, code: ChainPatrolClientErrorCodes);
|
|
60
|
+
}
|
|
61
|
+
declare enum ChainPatrolClientErrorCodes {
|
|
62
|
+
MISSING_API_KEY = "MISSING_API_KEY",
|
|
63
|
+
API_ERROR = "API_ERROR"
|
|
64
|
+
}
|
|
65
|
+
declare class ChainPatrolClient {
|
|
66
|
+
readonly baseUrl: string;
|
|
67
|
+
private readonly apiKey;
|
|
68
|
+
private readonly logger;
|
|
69
|
+
constructor(options: ChainPatrolClientOptions);
|
|
70
|
+
fetch<TResult = unknown>(req: ApiRequest): Promise<TResult>;
|
|
71
|
+
get asset(): {
|
|
72
|
+
check: (req: AssetCheckInput) => Promise<AssetCheckOutput>;
|
|
73
|
+
list: (req: AssetListInput) => Promise<AssetListOutput>;
|
|
74
|
+
};
|
|
75
|
+
get report(): {
|
|
76
|
+
create: (req: ReportCreateInput) => Promise<{
|
|
77
|
+
id: number;
|
|
78
|
+
createdAt: Date;
|
|
79
|
+
organization: {
|
|
80
|
+
id: number;
|
|
81
|
+
name: string;
|
|
82
|
+
slug: string;
|
|
83
|
+
} | null;
|
|
84
|
+
}>;
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
interface Storage$1 {
|
|
89
|
+
get: (key: string) => Promise<string | null>;
|
|
90
|
+
set: (key: string, value: string) => Promise<void>;
|
|
91
|
+
delete: (key: string) => Promise<void>;
|
|
92
|
+
size: () => Promise<number>;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
type Prettify<T> = T extends infer U ? (U extends string ? U : never) : never;
|
|
96
|
+
type DetectorAssetStatus = Prettify<AssetStatus | "IGNORED">;
|
|
97
|
+
type URLResult = {
|
|
98
|
+
ok: true;
|
|
99
|
+
status: DetectorAssetStatus;
|
|
100
|
+
url: string;
|
|
101
|
+
redirectUrl?: string;
|
|
102
|
+
} | {
|
|
103
|
+
ok: false;
|
|
104
|
+
url: string;
|
|
105
|
+
error: string;
|
|
106
|
+
};
|
|
107
|
+
declare class DomainParseError extends Error {
|
|
108
|
+
constructor(message: string);
|
|
109
|
+
}
|
|
110
|
+
declare class ThreatDetector {
|
|
111
|
+
private static readonly CHAINPATROL_WARNING_URL;
|
|
112
|
+
private static readonly Schema;
|
|
113
|
+
private mode;
|
|
114
|
+
private client?;
|
|
115
|
+
private storage;
|
|
116
|
+
private redirectUrl?;
|
|
117
|
+
private readonly logger;
|
|
118
|
+
constructor({ mode, storage, redirectUrl, }: {
|
|
119
|
+
mode: "local";
|
|
120
|
+
storage?: Storage$1;
|
|
121
|
+
redirectUrl?: string | ((url: string) => string);
|
|
122
|
+
});
|
|
123
|
+
constructor({ mode, apiKey, storage, redirectUrl, }: {
|
|
124
|
+
mode: "cloud";
|
|
125
|
+
apiKey: string;
|
|
126
|
+
storage?: Storage$1;
|
|
127
|
+
redirectUrl?: string | ((url: string) => string);
|
|
128
|
+
});
|
|
129
|
+
constructor({ mode, apiKey, proxyUrl, storage, redirectUrl, }: {
|
|
130
|
+
mode: "cloud";
|
|
131
|
+
apiKey: string;
|
|
132
|
+
proxyUrl?: string;
|
|
133
|
+
storage?: Storage$1;
|
|
134
|
+
redirectUrl?: string | ((url: string) => string);
|
|
135
|
+
});
|
|
136
|
+
url(url: string): Promise<URLResult>;
|
|
137
|
+
private generateDomains;
|
|
138
|
+
private urlHelper;
|
|
139
|
+
allow(url: string): Promise<{
|
|
140
|
+
ok: true;
|
|
141
|
+
url: string;
|
|
142
|
+
} | {
|
|
143
|
+
ok: false;
|
|
144
|
+
url: string;
|
|
145
|
+
error: string;
|
|
146
|
+
}>;
|
|
147
|
+
block(url: string): Promise<{
|
|
148
|
+
ok: true;
|
|
149
|
+
url: string;
|
|
150
|
+
} | {
|
|
151
|
+
ok: false;
|
|
152
|
+
url: string;
|
|
153
|
+
error: string;
|
|
154
|
+
}>;
|
|
155
|
+
ignore(url: string): Promise<{
|
|
156
|
+
ok: true;
|
|
157
|
+
url: string;
|
|
158
|
+
} | {
|
|
159
|
+
ok: false;
|
|
160
|
+
url: string;
|
|
161
|
+
error: string;
|
|
162
|
+
}>;
|
|
163
|
+
private parseDomainOrThrow;
|
|
164
|
+
private invalidateDomainInCaches;
|
|
165
|
+
private invalidateDomainInCache;
|
|
166
|
+
private addDomainToCache;
|
|
167
|
+
private isDomainInList;
|
|
168
|
+
private getListFromStorage;
|
|
169
|
+
private setListInStorage;
|
|
170
|
+
private getStatusFromCache;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
declare const Storage: {
|
|
174
|
+
Memory: () => {
|
|
175
|
+
get: (key: string) => Promise<string | null>;
|
|
176
|
+
set: (key: string, value: string) => Promise<void>;
|
|
177
|
+
delete: (key: string) => Promise<void>;
|
|
178
|
+
size: () => Promise<number>;
|
|
179
|
+
};
|
|
180
|
+
Extension: () => {
|
|
181
|
+
get: (key: string) => Promise<any>;
|
|
182
|
+
set: (key: string, value: string) => Promise<void>;
|
|
183
|
+
delete: (key: string) => Promise<void>;
|
|
184
|
+
size: () => Promise<number>;
|
|
185
|
+
};
|
|
186
|
+
Browser: () => {
|
|
187
|
+
get: (key: string) => Promise<string | null>;
|
|
188
|
+
set: (key: string, value: string) => Promise<void>;
|
|
189
|
+
delete: (key: string) => Promise<void>;
|
|
190
|
+
size: () => Promise<number>;
|
|
191
|
+
};
|
|
192
|
+
};
|
|
193
|
+
|
|
194
|
+
export { type AssetStatus, type AssetType, ChainPatrolClient, ChainPatrolClientError, ChainPatrolClientErrorCodes, type ChainPatrolClientOptions, type DetectorAssetStatus, DomainParseError, type EventData, Events, Relay, Storage, ThreatDetector, type URLResult };
|
package/dist/index.d.ts
CHANGED
|
@@ -85,7 +85,7 @@ declare class ChainPatrolClient {
|
|
|
85
85
|
};
|
|
86
86
|
}
|
|
87
87
|
|
|
88
|
-
interface Storage {
|
|
88
|
+
interface Storage$1 {
|
|
89
89
|
get: (key: string) => Promise<string | null>;
|
|
90
90
|
set: (key: string, value: string) => Promise<void>;
|
|
91
91
|
delete: (key: string) => Promise<void>;
|
|
@@ -108,11 +108,6 @@ declare class DomainParseError extends Error {
|
|
|
108
108
|
constructor(message: string);
|
|
109
109
|
}
|
|
110
110
|
declare class ThreatDetector {
|
|
111
|
-
static StorageKeys: {
|
|
112
|
-
ALLOWLIST: string;
|
|
113
|
-
BLOCKLIST: string;
|
|
114
|
-
IGNORELIST: string;
|
|
115
|
-
};
|
|
116
111
|
private static readonly CHAINPATROL_WARNING_URL;
|
|
117
112
|
private static readonly Schema;
|
|
118
113
|
private mode;
|
|
@@ -122,20 +117,20 @@ declare class ThreatDetector {
|
|
|
122
117
|
private readonly logger;
|
|
123
118
|
constructor({ mode, storage, redirectUrl, }: {
|
|
124
119
|
mode: "local";
|
|
125
|
-
storage?: Storage;
|
|
120
|
+
storage?: Storage$1;
|
|
126
121
|
redirectUrl?: string | ((url: string) => string);
|
|
127
122
|
});
|
|
128
123
|
constructor({ mode, apiKey, storage, redirectUrl, }: {
|
|
129
124
|
mode: "cloud";
|
|
130
125
|
apiKey: string;
|
|
131
|
-
storage?: Storage;
|
|
126
|
+
storage?: Storage$1;
|
|
132
127
|
redirectUrl?: string | ((url: string) => string);
|
|
133
128
|
});
|
|
134
129
|
constructor({ mode, apiKey, proxyUrl, storage, redirectUrl, }: {
|
|
135
130
|
mode: "cloud";
|
|
136
131
|
apiKey: string;
|
|
137
132
|
proxyUrl?: string;
|
|
138
|
-
storage?: Storage;
|
|
133
|
+
storage?: Storage$1;
|
|
139
134
|
redirectUrl?: string | ((url: string) => string);
|
|
140
135
|
});
|
|
141
136
|
url(url: string): Promise<URLResult>;
|
|
@@ -175,45 +170,25 @@ declare class ThreatDetector {
|
|
|
175
170
|
private getStatusFromCache;
|
|
176
171
|
}
|
|
177
172
|
|
|
178
|
-
declare const
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
};
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
173
|
+
declare const Storage: {
|
|
174
|
+
Memory: () => {
|
|
175
|
+
get: (key: string) => Promise<string | null>;
|
|
176
|
+
set: (key: string, value: string) => Promise<void>;
|
|
177
|
+
delete: (key: string) => Promise<void>;
|
|
178
|
+
size: () => Promise<number>;
|
|
179
|
+
};
|
|
180
|
+
Extension: () => {
|
|
181
|
+
get: (key: string) => Promise<any>;
|
|
182
|
+
set: (key: string, value: string) => Promise<void>;
|
|
183
|
+
delete: (key: string) => Promise<void>;
|
|
184
|
+
size: () => Promise<number>;
|
|
185
|
+
};
|
|
186
|
+
Browser: () => {
|
|
187
|
+
get: (key: string) => Promise<string | null>;
|
|
188
|
+
set: (key: string, value: string) => Promise<void>;
|
|
189
|
+
delete: (key: string) => Promise<void>;
|
|
190
|
+
size: () => Promise<number>;
|
|
191
|
+
};
|
|
197
192
|
};
|
|
198
193
|
|
|
199
|
-
|
|
200
|
-
keys: string[];
|
|
201
|
-
}
|
|
202
|
-
declare function defineStorage<T extends Storage>(config: (ctx: Context) => T): () => T;
|
|
203
|
-
|
|
204
|
-
declare const index_Browser: typeof Browser;
|
|
205
|
-
declare const index_Extension: typeof Extension;
|
|
206
|
-
declare const index_Memory: typeof Memory;
|
|
207
|
-
type index_Storage = Storage;
|
|
208
|
-
declare const index_defineStorage: typeof defineStorage;
|
|
209
|
-
declare namespace index {
|
|
210
|
-
export {
|
|
211
|
-
index_Browser as Browser,
|
|
212
|
-
index_Extension as Extension,
|
|
213
|
-
index_Memory as Memory,
|
|
214
|
-
index_Storage as Storage,
|
|
215
|
-
index_defineStorage as defineStorage,
|
|
216
|
-
};
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
export { AssetStatus, AssetType, ChainPatrolClient, ChainPatrolClientError, ChainPatrolClientErrorCodes, ChainPatrolClientOptions, DetectorAssetStatus, DomainParseError, EventData, Events, Relay, index as Storage, ThreatDetector, URLResult };
|
|
194
|
+
export { type AssetStatus, type AssetType, ChainPatrolClient, ChainPatrolClientError, ChainPatrolClientErrorCodes, type ChainPatrolClientOptions, type DetectorAssetStatus, DomainParseError, type EventData, Events, Relay, Storage, ThreatDetector, type URLResult };
|