@chainpatrol/sdk 0.4.0 → 0.5.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.mts +213 -0
- package/dist/index.d.ts +4 -10
- package/dist/index.js +2322 -1569
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2322 -1569
- package/dist/index.mjs.map +1 -1
- package/package.json +24 -9
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,213 @@
|
|
|
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 {
|
|
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
|
+
static StorageKeys: {
|
|
112
|
+
ALLOWLIST: string;
|
|
113
|
+
BLOCKLIST: string;
|
|
114
|
+
IGNORELIST: string;
|
|
115
|
+
};
|
|
116
|
+
private static readonly CHAINPATROL_WARNING_URL;
|
|
117
|
+
private static readonly Schema;
|
|
118
|
+
private mode;
|
|
119
|
+
private client?;
|
|
120
|
+
private storage;
|
|
121
|
+
private redirectUrl?;
|
|
122
|
+
private readonly logger;
|
|
123
|
+
constructor({ mode, storage, redirectUrl, }: {
|
|
124
|
+
mode: "local";
|
|
125
|
+
storage?: Storage;
|
|
126
|
+
redirectUrl?: string | ((url: string) => string);
|
|
127
|
+
});
|
|
128
|
+
constructor({ mode, apiKey, storage, redirectUrl, }: {
|
|
129
|
+
mode: "cloud";
|
|
130
|
+
apiKey: string;
|
|
131
|
+
storage?: Storage;
|
|
132
|
+
redirectUrl?: string | ((url: string) => string);
|
|
133
|
+
});
|
|
134
|
+
constructor({ mode, apiKey, proxyUrl, storage, redirectUrl, }: {
|
|
135
|
+
mode: "cloud";
|
|
136
|
+
apiKey: string;
|
|
137
|
+
proxyUrl?: string;
|
|
138
|
+
storage?: Storage;
|
|
139
|
+
redirectUrl?: string | ((url: string) => string);
|
|
140
|
+
});
|
|
141
|
+
url(url: string): Promise<URLResult>;
|
|
142
|
+
private generateDomains;
|
|
143
|
+
private urlHelper;
|
|
144
|
+
allow(url: string): Promise<{
|
|
145
|
+
ok: true;
|
|
146
|
+
url: string;
|
|
147
|
+
} | {
|
|
148
|
+
ok: false;
|
|
149
|
+
url: string;
|
|
150
|
+
error: string;
|
|
151
|
+
}>;
|
|
152
|
+
block(url: string): Promise<{
|
|
153
|
+
ok: true;
|
|
154
|
+
url: string;
|
|
155
|
+
} | {
|
|
156
|
+
ok: false;
|
|
157
|
+
url: string;
|
|
158
|
+
error: string;
|
|
159
|
+
}>;
|
|
160
|
+
ignore(url: string): Promise<{
|
|
161
|
+
ok: true;
|
|
162
|
+
url: string;
|
|
163
|
+
} | {
|
|
164
|
+
ok: false;
|
|
165
|
+
url: string;
|
|
166
|
+
error: string;
|
|
167
|
+
}>;
|
|
168
|
+
private parseDomainOrThrow;
|
|
169
|
+
private invalidateDomainInCaches;
|
|
170
|
+
private invalidateDomainInCache;
|
|
171
|
+
private addDomainToCache;
|
|
172
|
+
private isDomainInList;
|
|
173
|
+
private getListFromStorage;
|
|
174
|
+
private setListInStorage;
|
|
175
|
+
private getStatusFromCache;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
declare const Extension: () => {
|
|
179
|
+
get: (key: string) => Promise<any>;
|
|
180
|
+
set: (key: string, value: string) => Promise<void>;
|
|
181
|
+
delete: (key: string) => Promise<void>;
|
|
182
|
+
size: () => Promise<number>;
|
|
183
|
+
};
|
|
184
|
+
|
|
185
|
+
declare const Browser: () => {
|
|
186
|
+
get: (key: string) => Promise<string | null>;
|
|
187
|
+
set: (key: string, value: string) => Promise<void>;
|
|
188
|
+
delete: (key: string) => Promise<void>;
|
|
189
|
+
size: () => Promise<number>;
|
|
190
|
+
};
|
|
191
|
+
|
|
192
|
+
declare const Memory: () => {
|
|
193
|
+
get: (key: string) => Promise<string | null>;
|
|
194
|
+
set: (key: string, value: string) => Promise<void>;
|
|
195
|
+
delete: (key: string) => Promise<void>;
|
|
196
|
+
size: () => Promise<number>;
|
|
197
|
+
};
|
|
198
|
+
|
|
199
|
+
interface Context {
|
|
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 { index_Browser as Browser, index_Extension as Extension, index_Memory as Memory, type index_Storage as Storage, index_defineStorage as defineStorage };
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
export { type AssetStatus, type AssetType, ChainPatrolClient, ChainPatrolClientError, ChainPatrolClientErrorCodes, type ChainPatrolClientOptions, type DetectorAssetStatus, DomainParseError, type EventData, Events, Relay, index as Storage, ThreatDetector, type URLResult };
|
package/dist/index.d.ts
CHANGED
|
@@ -77,9 +77,9 @@ declare class ChainPatrolClient {
|
|
|
77
77
|
id: number;
|
|
78
78
|
createdAt: Date;
|
|
79
79
|
organization: {
|
|
80
|
-
slug: string;
|
|
81
|
-
name: string;
|
|
82
80
|
id: number;
|
|
81
|
+
name: string;
|
|
82
|
+
slug: string;
|
|
83
83
|
} | null;
|
|
84
84
|
}>;
|
|
85
85
|
};
|
|
@@ -207,13 +207,7 @@ declare const index_Memory: typeof Memory;
|
|
|
207
207
|
type index_Storage = Storage;
|
|
208
208
|
declare const index_defineStorage: typeof defineStorage;
|
|
209
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
|
-
};
|
|
210
|
+
export { index_Browser as Browser, index_Extension as Extension, index_Memory as Memory, type index_Storage as Storage, index_defineStorage as defineStorage };
|
|
217
211
|
}
|
|
218
212
|
|
|
219
|
-
export { AssetStatus, AssetType, ChainPatrolClient, ChainPatrolClientError, ChainPatrolClientErrorCodes, ChainPatrolClientOptions, DetectorAssetStatus, DomainParseError, EventData, Events, Relay, index as Storage, ThreatDetector, URLResult };
|
|
213
|
+
export { type AssetStatus, type AssetType, ChainPatrolClient, ChainPatrolClientError, ChainPatrolClientErrorCodes, type ChainPatrolClientOptions, type DetectorAssetStatus, DomainParseError, type EventData, Events, Relay, index as Storage, ThreatDetector, type URLResult };
|