@deflectbot/deflect-sdk 1.3.1 → 1.3.3
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.js +4 -32
- package/dist/index.min.js +1 -1
- package/package.json +3 -8
package/README.md
CHANGED
|
@@ -28,7 +28,7 @@ npm install --save @castleio/sdk
|
|
|
28
28
|
Use `@deflect-sdk@latest` to always use the latest version, or specify a version with `@deflect-sdk@x.x.x`.
|
|
29
29
|
|
|
30
30
|
```html
|
|
31
|
-
<script src="https://cdn.jsdelivr.net/npm/@deflectbot/deflect-sdk@latest/dist/index.min.js"
|
|
31
|
+
<script src="https://cdn.jsdelivr.net/npm/@deflectbot/deflect-sdk@latest/dist/index.min.js"></script>
|
|
32
32
|
```
|
|
33
33
|
|
|
34
34
|
## Configuration
|
package/dist/index.js
CHANGED
|
@@ -1,29 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
2
|
+
(() => {
|
|
3
3
|
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
4
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
-
for (let key of __getOwnPropNames(from))
|
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
21
|
-
|
|
22
|
-
// src/global.ts
|
|
23
|
-
var global_exports = {};
|
|
24
|
-
__export(global_exports, {
|
|
25
|
-
default: () => global_default
|
|
26
|
-
});
|
|
27
5
|
|
|
28
6
|
// src/index.ts
|
|
29
7
|
var Deflect = class {
|
|
@@ -63,9 +41,6 @@ var Deflect = (() => {
|
|
|
63
41
|
}
|
|
64
42
|
buildScriptUrl(actionId) {
|
|
65
43
|
const baseUrl = this.config?.scriptUrl || "https://js.deflect.bot/main.js";
|
|
66
|
-
if (this.config?.scriptUrl) {
|
|
67
|
-
return baseUrl;
|
|
68
|
-
}
|
|
69
44
|
const nonce = Date.now().toString();
|
|
70
45
|
return `${baseUrl}?action_id=${actionId}&_=${nonce}`;
|
|
71
46
|
}
|
|
@@ -211,12 +186,9 @@ var Deflect = (() => {
|
|
|
211
186
|
return false;
|
|
212
187
|
}
|
|
213
188
|
};
|
|
214
|
-
var
|
|
215
|
-
|
|
216
|
-
// src/global.ts
|
|
189
|
+
var DeflectInstance = new Deflect();
|
|
217
190
|
if (typeof window !== "undefined") {
|
|
218
|
-
window.Deflect =
|
|
191
|
+
window.Deflect = DeflectInstance;
|
|
219
192
|
}
|
|
220
|
-
var
|
|
221
|
-
return __toCommonJS(global_exports);
|
|
193
|
+
var src_default = DeflectInstance;
|
|
222
194
|
})();
|
package/dist/index.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";(()=>{var o=class{constructor(){this.config=null;this.scriptCache=null;this.isWarmupInProgress=!1;this.initializeGlobalState(),this.setupAutomaticWarmup()}initializeGlobalState(){typeof window>"u"||(window.Deflect=window.Deflect||{})}setupAutomaticWarmup(){typeof window>"u"||(document.readyState==="loading"?document.addEventListener("DOMContentLoaded",()=>this.tryWarmup()):setTimeout(()=>this.tryWarmup(),100))}async tryWarmup(){if(!(!this.config?.actionId||this.isWarmupInProgress||this.scriptCache)){this.isWarmupInProgress=!0;try{this.scriptCache=await this.fetchScript()}catch{}finally{this.isWarmupInProgress=!1}}}buildScriptUrl(e){let t=this.config?.scriptUrl||"https://js.deflect.bot/main.js",r=Date.now().toString();return`${t}?action_id=${e}&_=${r}`}async fetchScript(){if(!this.config?.actionId)throw new Error("actionId is required");let e=this.buildScriptUrl(this.config.actionId),t=await fetch(e,{cache:"no-store"});if(!t.ok)throw new Error(`Failed to fetch script: ${t.status}`);return{content:await t.text(),sessionId:t.headers.get("session_id")||void 0}}async executeScript(e){e.sessionId&&typeof window<"u"&&(window.Deflect.sessionId=e.sessionId);let t=this.createReadyPromise(),r=this.createScriptBlob(e.content),i=await this.loadScriptElement(r);try{await t;let n=await this.getTokenFromScript();return this.prefetchNextScript(),n}finally{this.cleanup(r,i)}}prefetchNextScript(){this.tryWarmup().catch(()=>{})}createReadyPromise(){return new Promise(e=>{typeof window<"u"&&(window.Deflect.ready={promise:new Promise(t=>{window.Deflect.ready.resolve=t}),resolve:()=>e()})})}createScriptBlob(e){let t=new Blob([e],{type:"text/javascript"});return URL.createObjectURL(t)}async loadScriptElement(e){return new Promise((t,r)=>{let i=document.createElement("script");i.type="module",i.src=e,i.onload=()=>t(i),i.onerror=()=>r(new Error("Script failed to load")),document.head.appendChild(i)})}async getTokenFromScript(){if(typeof window>"u"||typeof window.Deflect?.getToken!="function")throw new Error("Script did not load properly - getToken not available");try{return await window.Deflect.getToken()}catch(e){throw new Error(`Script execution failed: ${e}`)}}cleanup(e,t){URL.revokeObjectURL(e),t.remove(),typeof window<"u"&&window.Deflect?.getToken&&delete window.Deflect.getToken}configure(e){if(!e.actionId?.trim())throw new Error("actionId is required and cannot be empty");this.config={...e},typeof window<"u"&&(window.Deflect.actionId=e.actionId),this.tryWarmup()}async solveChallenge(){return this.getToken()}async getToken(){if(!this.config?.actionId)throw new Error("Must call configure() before solveChallenge()");let e;return this.scriptCache&&!this.isWarmupInProgress?(e=this.scriptCache,this.scriptCache=null):e=await this.fetchScript(),this.executeScript(e)}async warmup(){if(!this.config?.actionId)return!1;try{return await this.tryWarmup(),this.scriptCache!==null}catch{return!1}}clearCache(){this.scriptCache=null}async injectToken(e){if(!e||!e.target||!(e.target instanceof HTMLFormElement))throw new Error("injectToken: must be called from a form submit event");e.preventDefault();let t=e.target,r=await this.getToken();Array.from(t.querySelectorAll('input[name="deflect_token"]')).forEach(n=>n.remove());let i=document.createElement("input");return i.type="hidden",i.name="deflect_token",i.value=r,t.appendChild(i),t.submit(),!1}},c=new o;typeof window<"u"&&(window.Deflect=c);var a=c;})();
|
package/package.json
CHANGED
|
@@ -1,19 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@deflectbot/deflect-sdk",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.3",
|
|
4
4
|
"description": "SDK for deflect.bot - Use it for seamless captcha integration on any website.",
|
|
5
5
|
"main": "dist/index.min.js",
|
|
6
|
-
"browser": "dist/index.min.js",
|
|
7
6
|
"unpkg": "dist/index.min.js",
|
|
8
7
|
"jsdelivr": "dist/index.min.js",
|
|
9
8
|
"files": [
|
|
10
9
|
"dist/**/*"
|
|
11
10
|
],
|
|
12
11
|
"scripts": {
|
|
13
|
-
"build": "
|
|
14
|
-
"build:global": "npm run build:global:dev && npm run build:global:min",
|
|
15
|
-
"build:global:dev": "esbuild src/global.ts --bundle --format=iife --global-name=Deflect --outfile=dist/index.js --keep-names",
|
|
16
|
-
"build:global:min": "esbuild src/global.ts --bundle --format=iife --global-name=Deflect --minify --outfile=dist/index.min.js"
|
|
12
|
+
"build": "esbuild src/index.ts --bundle --format=iife --outfile=dist/index.js --keep-names && esbuild src/index.ts --bundle --format=iife --minify --outfile=dist/index.min.js"
|
|
17
13
|
},
|
|
18
14
|
"author": "Deflect",
|
|
19
15
|
"license": "MIT",
|
|
@@ -27,6 +23,5 @@
|
|
|
27
23
|
},
|
|
28
24
|
"publishConfig": {
|
|
29
25
|
"access": "public"
|
|
30
|
-
}
|
|
31
|
-
"dependencies": {}
|
|
26
|
+
}
|
|
32
27
|
}
|