@deflectbot/deflect-sdk 1.0.3 → 1.0.5
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 +0 -2
- package/package.json +1 -1
- package/src/index.js +30 -10
- package/src/types/deflect-sdk.d.ts +13 -0
package/README.md
CHANGED
|
@@ -2,8 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|

|
|
4
4
|

|
|
5
|
-

|
|
6
|
-

|
|
7
5
|
|
|
8
6
|
Deflect is an antibot solution that works with Vue, React, NextJS, and other JavaScript frameworks.
|
|
9
7
|
|
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -1,24 +1,44 @@
|
|
|
1
1
|
class Deflect {
|
|
2
2
|
constructor() {
|
|
3
|
-
|
|
3
|
+
window.Deflect = window.Deflect || {};
|
|
4
4
|
}
|
|
5
5
|
|
|
6
|
-
|
|
7
6
|
configure(params) {
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
if (!params.siteKey) {
|
|
8
|
+
throw new Error('siteKey is required in configuration');
|
|
9
|
+
}
|
|
10
|
+
window.Deflect.siteKey = params.siteKey;
|
|
10
11
|
}
|
|
11
12
|
|
|
12
13
|
solveChallenge() {
|
|
13
14
|
return new Promise((resolve, reject) => {
|
|
14
|
-
if (!
|
|
15
|
-
return reject("
|
|
15
|
+
if (!window.Deflect.siteKey) {
|
|
16
|
+
return reject("siteKey is missing in configuration");
|
|
16
17
|
}
|
|
17
18
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
const scriptUrl = `https://js.deflect.bot/main.js?site=${window.Deflect.siteKey}`;
|
|
20
|
+
|
|
21
|
+
const script = document.createElement("script");
|
|
22
|
+
script.src = scriptUrl;
|
|
23
|
+
script.onload = () => {
|
|
24
|
+
if (typeof window.Deflect === 'undefined' || typeof window.Deflect.getToken !== 'function') {
|
|
25
|
+
return reject("Deflect script did not load properly");
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
window.Deflect.getToken()
|
|
29
|
+
.then((token) => {
|
|
30
|
+
resolve(token);
|
|
31
|
+
})
|
|
32
|
+
.catch((err) => {
|
|
33
|
+
reject(`Failed to get token: ${err}`);
|
|
34
|
+
});
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
script.onerror = () => {
|
|
38
|
+
reject("Failed to load the Deflect script");
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
document.head.appendChild(script);
|
|
22
42
|
});
|
|
23
43
|
}
|
|
24
44
|
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
declare module "@deflectbot/deflect-sdk" {
|
|
2
|
+
interface DeflectConfig {
|
|
3
|
+
siteKey: string;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
interface Deflect {
|
|
7
|
+
configure(params: DeflectConfig): void;
|
|
8
|
+
solveChallenge(): Promise<string>;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const Deflect: Deflect;
|
|
12
|
+
export default Deflect;
|
|
13
|
+
}
|