@deflectbot/deflect-sdk 1.1.11 → 1.1.12
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.js +23 -33
- package/dist/types/index.d.ts +1 -2
- package/package.json +1 -1
- package/src/index.ts +26 -36
package/dist/index.js
CHANGED
|
@@ -9,9 +9,22 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
};
|
|
10
10
|
class Deflect {
|
|
11
11
|
constructor() {
|
|
12
|
-
this._prefetchedBlobUrl = null;
|
|
13
12
|
window.Deflect = window.Deflect || {};
|
|
14
13
|
window.Deflect.extraArgs = window.Deflect.extraArgs || {};
|
|
14
|
+
if (typeof window !== "undefined") {
|
|
15
|
+
window.addEventListener("load", () => {
|
|
16
|
+
setTimeout(() => {
|
|
17
|
+
this._warmupScript();
|
|
18
|
+
}, 500);
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
_warmupScript() {
|
|
23
|
+
if (!window.Deflect.siteKey)
|
|
24
|
+
return;
|
|
25
|
+
const nonce = Date.now().toString();
|
|
26
|
+
const scriptUrl = `https://js.deflect.bot/main.js?sitekey=${window.Deflect.siteKey}&_=${nonce}`;
|
|
27
|
+
fetch(scriptUrl, { cache: "no-store", method: "GET" }).catch(() => { });
|
|
15
28
|
}
|
|
16
29
|
setupReady() {
|
|
17
30
|
let resolveFn;
|
|
@@ -30,21 +43,6 @@ class Deflect {
|
|
|
30
43
|
window.Deflect.siteKey = params.siteKey;
|
|
31
44
|
console.log("Deflect configured with siteKey");
|
|
32
45
|
}
|
|
33
|
-
prefetchScript() {
|
|
34
|
-
if (!window.Deflect.siteKey || this._prefetchedBlobUrl)
|
|
35
|
-
return;
|
|
36
|
-
const nonce = Date.now().toString();
|
|
37
|
-
const scriptUrl = `https://js.deflect.bot/main.js?sitekey=${window.Deflect.siteKey}&_=${nonce}`;
|
|
38
|
-
fetch(scriptUrl, { cache: "no-store" })
|
|
39
|
-
.then((res) => __awaiter(this, void 0, void 0, function* () {
|
|
40
|
-
if (!res.ok)
|
|
41
|
-
return;
|
|
42
|
-
const text = yield res.text();
|
|
43
|
-
const blob = new Blob([text], { type: "text/javascript" });
|
|
44
|
-
this._prefetchedBlobUrl = URL.createObjectURL(blob);
|
|
45
|
-
}))
|
|
46
|
-
.catch(() => { });
|
|
47
|
-
}
|
|
48
46
|
solveChallenge() {
|
|
49
47
|
return __awaiter(this, void 0, void 0, function* () {
|
|
50
48
|
var _a;
|
|
@@ -52,26 +50,19 @@ class Deflect {
|
|
|
52
50
|
throw new Error("API key (siteKey) is missing in configuration");
|
|
53
51
|
}
|
|
54
52
|
this.setupReady();
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
else {
|
|
61
|
-
const nonce = Date.now().toString();
|
|
62
|
-
const scriptUrl = `https://js.deflect.bot/main.js?sitekey=${window.Deflect.siteKey}&_=${nonce}`;
|
|
63
|
-
const response = yield fetch(scriptUrl, { cache: "no-store" });
|
|
64
|
-
if (!response.ok) {
|
|
65
|
-
throw new Error("Failed to fetch the Deflect script");
|
|
66
|
-
}
|
|
67
|
-
sessionId = response.headers.get("session_id");
|
|
68
|
-
const text = yield response.text();
|
|
69
|
-
const blob = new Blob([text], { type: "text/javascript" });
|
|
70
|
-
blobUrl = URL.createObjectURL(blob);
|
|
53
|
+
const nonce = Date.now().toString();
|
|
54
|
+
const scriptUrl = `https://js.deflect.bot/main.js?sitekey=${window.Deflect.siteKey}&_=${nonce}`;
|
|
55
|
+
const response = yield fetch(scriptUrl, { cache: "no-store" });
|
|
56
|
+
if (!response.ok) {
|
|
57
|
+
throw new Error("Failed to fetch the Deflect script");
|
|
71
58
|
}
|
|
59
|
+
const sessionId = response.headers.get("session_id");
|
|
72
60
|
if (sessionId) {
|
|
73
61
|
window.Deflect.sessionId = sessionId;
|
|
74
62
|
}
|
|
63
|
+
const text = yield response.text();
|
|
64
|
+
const blob = new Blob([text], { type: "text/javascript" });
|
|
65
|
+
const blobUrl = URL.createObjectURL(blob);
|
|
75
66
|
const scriptEl = document.createElement("script");
|
|
76
67
|
scriptEl.type = "module";
|
|
77
68
|
scriptEl.src = blobUrl;
|
|
@@ -88,7 +79,6 @@ class Deflect {
|
|
|
88
79
|
const token = yield window.Deflect.getToken();
|
|
89
80
|
URL.revokeObjectURL(blobUrl);
|
|
90
81
|
scriptEl.remove();
|
|
91
|
-
this._prefetchedBlobUrl = null;
|
|
92
82
|
delete window.Deflect.getToken;
|
|
93
83
|
return token;
|
|
94
84
|
});
|
package/dist/types/index.d.ts
CHANGED
|
@@ -5,11 +5,10 @@ interface DeflectConfig {
|
|
|
5
5
|
};
|
|
6
6
|
}
|
|
7
7
|
declare class Deflect {
|
|
8
|
-
private _prefetchedBlobUrl;
|
|
9
8
|
constructor();
|
|
9
|
+
private _warmupScript;
|
|
10
10
|
private setupReady;
|
|
11
11
|
configure(params: DeflectConfig): void;
|
|
12
|
-
prefetchScript(): void;
|
|
13
12
|
solveChallenge(): Promise<string>;
|
|
14
13
|
}
|
|
15
14
|
declare const _default: Deflect;
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -4,11 +4,25 @@ interface DeflectConfig {
|
|
|
4
4
|
}
|
|
5
5
|
|
|
6
6
|
class Deflect {
|
|
7
|
-
private _prefetchedBlobUrl: string | null = null;
|
|
8
|
-
|
|
9
7
|
constructor() {
|
|
10
8
|
window.Deflect = window.Deflect || {};
|
|
11
9
|
window.Deflect.extraArgs = window.Deflect.extraArgs || {};
|
|
10
|
+
|
|
11
|
+
if (typeof window !== "undefined") {
|
|
12
|
+
window.addEventListener("load", () => {
|
|
13
|
+
setTimeout(() => {
|
|
14
|
+
this._warmupScript();
|
|
15
|
+
}, 500);
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
private _warmupScript(): void {
|
|
21
|
+
if (!window.Deflect.siteKey) return;
|
|
22
|
+
|
|
23
|
+
const nonce = Date.now().toString();
|
|
24
|
+
const scriptUrl = `https://js.deflect.bot/main.js?sitekey=${window.Deflect.siteKey}&_=${nonce}`;
|
|
25
|
+
fetch(scriptUrl, { cache: "no-store", method: "GET" }).catch(() => {});
|
|
12
26
|
}
|
|
13
27
|
|
|
14
28
|
private setupReady(): void {
|
|
@@ -30,22 +44,6 @@ class Deflect {
|
|
|
30
44
|
console.log("Deflect configured with siteKey");
|
|
31
45
|
}
|
|
32
46
|
|
|
33
|
-
prefetchScript(): void {
|
|
34
|
-
if (!window.Deflect.siteKey || this._prefetchedBlobUrl) return;
|
|
35
|
-
|
|
36
|
-
const nonce = Date.now().toString();
|
|
37
|
-
const scriptUrl = `https://js.deflect.bot/main.js?sitekey=${window.Deflect.siteKey}&_=${nonce}`;
|
|
38
|
-
|
|
39
|
-
fetch(scriptUrl, { cache: "no-store" })
|
|
40
|
-
.then(async (res) => {
|
|
41
|
-
if (!res.ok) return;
|
|
42
|
-
const text = await res.text();
|
|
43
|
-
const blob = new Blob([text], { type: "text/javascript" });
|
|
44
|
-
this._prefetchedBlobUrl = URL.createObjectURL(blob);
|
|
45
|
-
})
|
|
46
|
-
.catch(() => {});
|
|
47
|
-
}
|
|
48
|
-
|
|
49
47
|
async solveChallenge(): Promise<string> {
|
|
50
48
|
if (!window.Deflect.siteKey) {
|
|
51
49
|
throw new Error("API key (siteKey) is missing in configuration");
|
|
@@ -53,30 +51,23 @@ class Deflect {
|
|
|
53
51
|
|
|
54
52
|
this.setupReady();
|
|
55
53
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
if (this._prefetchedBlobUrl) {
|
|
60
|
-
blobUrl = this._prefetchedBlobUrl;
|
|
61
|
-
} else {
|
|
62
|
-
const nonce = Date.now().toString();
|
|
63
|
-
const scriptUrl = `https://js.deflect.bot/main.js?sitekey=${window.Deflect.siteKey}&_=${nonce}`;
|
|
64
|
-
const response = await fetch(scriptUrl, { cache: "no-store" });
|
|
65
|
-
|
|
66
|
-
if (!response.ok) {
|
|
67
|
-
throw new Error("Failed to fetch the Deflect script");
|
|
68
|
-
}
|
|
54
|
+
const nonce = Date.now().toString();
|
|
55
|
+
const scriptUrl = `https://js.deflect.bot/main.js?sitekey=${window.Deflect.siteKey}&_=${nonce}`;
|
|
56
|
+
const response = await fetch(scriptUrl, { cache: "no-store" });
|
|
69
57
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
const blob = new Blob([text], { type: "text/javascript" });
|
|
73
|
-
blobUrl = URL.createObjectURL(blob);
|
|
58
|
+
if (!response.ok) {
|
|
59
|
+
throw new Error("Failed to fetch the Deflect script");
|
|
74
60
|
}
|
|
75
61
|
|
|
62
|
+
const sessionId = response.headers.get("session_id");
|
|
76
63
|
if (sessionId) {
|
|
77
64
|
window.Deflect.sessionId = sessionId;
|
|
78
65
|
}
|
|
79
66
|
|
|
67
|
+
const text = await response.text();
|
|
68
|
+
const blob = new Blob([text], { type: "text/javascript" });
|
|
69
|
+
const blobUrl = URL.createObjectURL(blob);
|
|
70
|
+
|
|
80
71
|
const scriptEl = document.createElement("script");
|
|
81
72
|
scriptEl.type = "module";
|
|
82
73
|
scriptEl.src = blobUrl;
|
|
@@ -101,7 +92,6 @@ class Deflect {
|
|
|
101
92
|
|
|
102
93
|
URL.revokeObjectURL(blobUrl);
|
|
103
94
|
scriptEl.remove();
|
|
104
|
-
this._prefetchedBlobUrl = null;
|
|
105
95
|
|
|
106
96
|
delete window.Deflect.getToken;
|
|
107
97
|
|