@synthient/synthient 1.0.1 → 2.0.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/src/models.ts DELETED
@@ -1,276 +0,0 @@
1
- /**
2
- * The three types of tokens that can be issued.
3
- * METRICS - Metrics token, used for gathering data.
4
- * SIGN - Sign token, used for verifying the challenge.
5
- * STRICT - Strict token, used for strict verification.
6
- */
7
- export enum TokenType {
8
- METRICS = "metrics",
9
- SIGN = "sign",
10
- STRICT = "strict",
11
- }
12
-
13
- /**
14
- * Translates the risk level into an action to take.
15
- * ALLOW - Allow the visitor to continue.
16
- * REDIRECT - Redirect the visitor to a different page or have them perform another form of verification.
17
- * BLOCK - Block the visitor from accessing.
18
- */
19
- export enum ActionType {
20
- ALLOW = 0,
21
- REDIRECT = 1,
22
- BLOCK = 2,
23
- }
24
-
25
- /**
26
- * Risk level of the visitor. Simplified for ease of use.
27
- * Under certain circumstances, you may want to use the risk score.
28
- */
29
- export enum RiskLevel {
30
- LOW = 0,
31
- MEDIUM = 1,
32
- HIGH = 2,
33
- }
34
-
35
- /**
36
- * Base response model.
37
- * Represents a response containing a message.
38
- */
39
- export class BaseResponse {
40
- message: string;
41
-
42
- /**
43
- * Constructs a new BaseResponse.
44
- *
45
- * @param message - The response message.
46
- */
47
- constructor(message: string) {
48
- this.message = message;
49
- }
50
- }
51
-
52
- /**
53
- * Device model, contains core information relating to the visitor device.
54
- */
55
- export class Device {
56
- model?: string;
57
- brand?: string;
58
- os: string;
59
- version: string;
60
-
61
- /**
62
- * Constructs a new Device.
63
- *
64
- * @param model - The model of the device, if available.
65
- * @param brand - The brand of the device.
66
- * @param os - The operating system of the device.
67
- * @param version - The version of the operating system.
68
- */
69
- constructor(model: string | undefined, brand: string, os: string, version: string) {
70
- this.model = model;
71
- this.brand = brand;
72
- this.os = os;
73
- this.version = version;
74
- }
75
- }
76
-
77
- /**
78
- * Browser model, contains information about the browser being used.
79
- */
80
- export class Browser {
81
- name: string;
82
- version: string;
83
-
84
- /**
85
- * Constructs a new Browser.
86
- *
87
- * @param name - The name of the browser.
88
- * @param version - The version of the browser.
89
- */
90
- constructor(name: string, version: string) {
91
- this.name = name;
92
- this.version = version;
93
- }
94
- }
95
-
96
- /**
97
- * IpData model, contains information about the IP address
98
- */
99
- export class IpData {
100
- is_vpn: boolean;
101
- is_proxy: boolean;
102
- is_tor: boolean;
103
- is_relay: boolean;
104
- asn: string;
105
-
106
- /**
107
- * Constructs a new IpData.
108
- *
109
- * @param is_vpn - If the IP address is a VPN.
110
- * @param is_proxy - If the IP address is a proxy.
111
- * @param is_tor - If the IP address is a TOR node.
112
- * @param is_relay - If the IP address is a relay.
113
- * @param asn - The ASN of the IP address.
114
- */
115
- constructor(is_vpn: boolean, is_proxy: boolean, is_tor: boolean, is_relay: boolean, asn: string) {
116
- this.is_vpn = is_vpn;
117
- this.is_proxy = is_proxy;
118
- this.is_tor = is_tor;
119
- this.is_relay = is_relay;
120
- this.asn = asn;
121
- }
122
- }
123
-
124
- /**
125
- * Location model, contains information about the location of the IP address.
126
- */
127
- export class Location {
128
- city: string;
129
- region: string;
130
- country: string;
131
- region_code: string;
132
- country_code: string;
133
- latitude: number;
134
- longitude: number;
135
-
136
- /**
137
- * Constructs a new Location.
138
- *
139
- * @param city - The city of the IP address.
140
- * @param region - The region of the IP address.
141
- * @param country - The country of the IP address.
142
- * @param region_code - The region code of the IP address.
143
- * @param country_code - The country code of the IP address.
144
- * @param latitude - The latitude of the IP address.
145
- * @param longitude - The longitude of the IP address.
146
- */
147
- constructor(city: string, region: string, country: string, region_code: string, country_code: string, latitude: number, longitude: number) {
148
- this.city = city;
149
- this.region = region;
150
- this.country = country;
151
- this.region_code = region_code;
152
- this.country_code = country_code;
153
- this.latitude = latitude;
154
- this.longitude = longitude;
155
- }
156
- }
157
-
158
- /**
159
- * Response model for the lookup endpoint.
160
- */
161
- export class LookupResponse {
162
- token: string;
163
- token_type: TokenType;
164
- session: string;
165
- device?: Device;
166
- browser?: Browser;
167
- ip: string;
168
- ip_data?: IpData;
169
- location?: Location;
170
- page?: string;
171
- risk_score: number;
172
- is_incognito: boolean;
173
- is_bot: boolean;
174
- is_vm: boolean;
175
- solved?: boolean;
176
- consumed: boolean;
177
-
178
- /**
179
- * Constructs a new LookupResponse.
180
- *
181
- * @param token - The token of the visitor.
182
- * @param token_type - The type of token that was issued (metrics, sign, strict).
183
- * @param session - The persistent session of the visitor, will not change.
184
- * @param device - The device information of the visitor.
185
- * @param browser - The browser information of the visitor.
186
- * @param ip - The IP address of the visitor.
187
- * @param ip_data - The IP data of the visitor.
188
- * @param location - The location of the visitor.
189
- * @param page - The page the visitor is on.
190
- * @param risk_score - The risk score of the visitor.
191
- * @param is_incognito - If the visitor is in incognito mode.
192
- * @param is_bot - If the visitor is a bot.
193
- * @param is_vm - If the visitor is using a VM.
194
- * @param solved - If the visitor has solved the captcha (if applicable).
195
- * @param consumed - If the token has been consumed (used before).
196
- */
197
- constructor(
198
- token: string,
199
- token_type: TokenType,
200
- session: string,
201
- device: Device | undefined,
202
- browser: Browser | undefined,
203
- ip: string,
204
- ip_data: IpData | undefined,
205
- location: Location | undefined,
206
- page: string | undefined,
207
- risk_score: number,
208
- is_incognito: boolean,
209
- is_bot: boolean,
210
- is_vm: boolean,
211
- solved: boolean | undefined,
212
- consumed: boolean
213
- ) {
214
- this.token = token;
215
- this.token_type = token_type;
216
- this.session = session;
217
- this.device = device;
218
- this.browser = browser;
219
- this.ip = ip;
220
- this.ip_data = ip_data;
221
- this.location = location;
222
- this.page = page;
223
- this.risk_score = risk_score;
224
- this.is_incognito = is_incognito;
225
- this.is_bot = is_bot;
226
- this.is_vm = is_vm;
227
- this.solved = solved;
228
- this.consumed = consumed;
229
- }
230
-
231
- /**
232
- * Computes the risk level based on the risk score.
233
- */
234
- get risk_level(): RiskLevel {
235
- if (this.risk_score < 20) return RiskLevel.LOW;
236
- if (this.risk_score < 50) return RiskLevel.MEDIUM;
237
- return RiskLevel.HIGH;
238
- }
239
- }
240
-
241
- /**
242
- * Response model for the visits endpoint.
243
- */
244
- export class VisitResponse extends BaseResponse {
245
- session: string;
246
- visits: LookupResponse[];
247
- has_next: boolean;
248
-
249
- /**
250
- * Constructs a new VisitResponse.
251
- *
252
- * @param session - The session of the visitor.
253
- * @param visits - The list of visit responses.
254
- * @param has_next - Whether there are more visits.
255
- */
256
- constructor(session: string, visits: LookupResponse[], has_next: boolean) {
257
- super('');
258
- this.session = session;
259
- this.visits = visits;
260
- this.has_next = has_next;
261
- }
262
- }
263
-
264
- /**
265
- * Response model for the delete endpoint.
266
- */
267
- export class DeleteResponse extends BaseResponse {
268
- /**
269
- * Constructs a new DeleteResponse.
270
- *
271
- * @param message - The response message from the server.
272
- */
273
- constructor(message: string) {
274
- super(message);
275
- }
276
- }
package/src/utils.ts DELETED
@@ -1,28 +0,0 @@
1
- import { LookupResponse, TokenType, ActionType } from './models';
2
-
3
- /**
4
- * Verify the token.
5
- * @param lookup - The response from the lookup endpoint.
6
- * @param token_type - The type of token that was issued.
7
- * @returns A boolean indicating if the token is valid.
8
- */
9
- export function verifyToken(lookup: LookupResponse, token_type: TokenType): boolean {
10
- return (
11
- lookup.consumed === false &&
12
- (lookup.solved !== undefined ? lookup.solved : true) === true &&
13
- token_type === lookup.token_type
14
- );
15
- }
16
-
17
- /**
18
- * Determine the action to take based on the lookup response.
19
- * @param lookup - The response from the lookup endpoint.
20
- * @param token_type - The type of token that was issued.
21
- * @returns The action to take.
22
- */
23
- export function determineAction(lookup: LookupResponse, token_type: TokenType): ActionType {
24
- if (verifyToken(lookup, token_type)) {
25
- return (lookup.risk_level as unknown) as ActionType;
26
- }
27
- return ActionType.BLOCK;
28
- }
package/tsconfig.json DELETED
@@ -1,15 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "target": "es6",
4
- "module": "commonjs",
5
- "strict": true,
6
- "esModuleInterop": true,
7
- "skipLibCheck": true,
8
- "outDir": "./dist",
9
- "rootDir": "./src",
10
- "declaration": true,
11
- "declarationDir": "./dist"
12
- },
13
- "include": ["src"]
14
- }
15
-