@prosopo/procaptcha-bundle 0.2.0 → 0.2.2
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/cjs/index.cjs +100 -0
- package/package.json +14 -7
- package/vite.cjs.config.ts +6 -0
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
|
|
3
|
+
const jsxRuntime = require("react/jsx-runtime");
|
|
4
|
+
const types = require("@prosopo/types");
|
|
5
|
+
const common = require("@prosopo/common");
|
|
6
|
+
const procaptcha = require("@prosopo/procaptcha");
|
|
7
|
+
const procaptchaReact = require("@prosopo/procaptcha-react");
|
|
8
|
+
const util = require("@prosopo/util");
|
|
9
|
+
const client = require("react-dom/client");
|
|
10
|
+
function getConfig(siteKey) {
|
|
11
|
+
if (!siteKey) {
|
|
12
|
+
siteKey = process.env.DAPP_SITE_KEY || process.env.PROSOPO_SITE_KEY || "";
|
|
13
|
+
}
|
|
14
|
+
return {
|
|
15
|
+
logLevel: common.LogLevel.enum.info,
|
|
16
|
+
defaultEnvironment: process.env.DEFAULT_ENVIRONMENT || types.EnvironmentTypesSchema.enum.development,
|
|
17
|
+
userAccountAddress: "",
|
|
18
|
+
web2: true,
|
|
19
|
+
dappName: "Prosopo",
|
|
20
|
+
account: {
|
|
21
|
+
address: siteKey
|
|
22
|
+
},
|
|
23
|
+
networks: {
|
|
24
|
+
[types.EnvironmentTypesSchema.enum.development]: {
|
|
25
|
+
endpoint: process.env.SUBSTRATE_NODE_URL || "ws://127.0.0.1:9944",
|
|
26
|
+
contract: {
|
|
27
|
+
address: process.env.PROTOCOL_CONTRACT_ADDRESS || "",
|
|
28
|
+
name: "prosopo"
|
|
29
|
+
},
|
|
30
|
+
accounts: []
|
|
31
|
+
},
|
|
32
|
+
[types.EnvironmentTypesSchema.enum.rococo]: {
|
|
33
|
+
endpoint: process.env.SUBSTRATE_NODE_URL || "wss://rococo-contracts-rpc.polkadot.io:443",
|
|
34
|
+
contract: {
|
|
35
|
+
address: process.env.PROTOCOL_CONTRACT_ADDRESS || "5HiVWQhJrysNcFNEWf2crArKht16zrhro3FcekVWocyQjx5u",
|
|
36
|
+
name: "prosopo"
|
|
37
|
+
},
|
|
38
|
+
accounts: []
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
solutionThreshold: 80,
|
|
42
|
+
serverUrl: process.env.SERVER_URL || ""
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
function getParentForm(element) {
|
|
46
|
+
let parent = element.parentElement;
|
|
47
|
+
while (parent) {
|
|
48
|
+
if (parent.tagName === "FORM") {
|
|
49
|
+
return parent;
|
|
50
|
+
}
|
|
51
|
+
parent = parent.parentElement;
|
|
52
|
+
}
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
function render(callbacks) {
|
|
56
|
+
const elements = Array.from(document.getElementsByClassName("procaptcha"));
|
|
57
|
+
const siteKey = util.at(elements, 0).getAttribute("data-sitekey") || void 0;
|
|
58
|
+
const config = getConfig(siteKey);
|
|
59
|
+
if (!callbacks) {
|
|
60
|
+
callbacks = {};
|
|
61
|
+
}
|
|
62
|
+
for (const element of elements) {
|
|
63
|
+
for (const callbackName of procaptcha.ProcapchaEventNames) {
|
|
64
|
+
const dataCallbackName = `data-${callbackName.toLowerCase()}`;
|
|
65
|
+
const callback = element.getAttribute(dataCallbackName);
|
|
66
|
+
if (callback) {
|
|
67
|
+
callbacks[callbackName] = window[callback.replace("window.", "")];
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
const customTheme = element.getAttribute(`data-custom-theme`);
|
|
71
|
+
if (customTheme) {
|
|
72
|
+
config["sx"] = JSON.parse(customTheme);
|
|
73
|
+
}
|
|
74
|
+
if (!callbacks["onHuman"]) {
|
|
75
|
+
callbacks["onHuman"] = function(payload) {
|
|
76
|
+
const form = getParentForm(element);
|
|
77
|
+
if (form) {
|
|
78
|
+
const input = document.createElement("input");
|
|
79
|
+
input.type = "hidden";
|
|
80
|
+
input.name = types.ApiParams.procaptchaResponse, input.value = JSON.stringify(payload);
|
|
81
|
+
form.appendChild(input);
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
const root = client.createRoot(element);
|
|
86
|
+
root.render(/* @__PURE__ */ jsxRuntime.jsx(procaptchaReact.Procaptcha, { config, callbacks }));
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
function ready(fn) {
|
|
90
|
+
if (document && document.readyState != "loading") {
|
|
91
|
+
console.log("document.readyState ready!");
|
|
92
|
+
fn();
|
|
93
|
+
} else {
|
|
94
|
+
console.log("DOMContentLoaded listener!");
|
|
95
|
+
document.addEventListener("DOMContentLoaded", fn);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
ready(render);
|
|
99
|
+
exports.default = ready;
|
|
100
|
+
exports.render = render;
|
package/package.json
CHANGED
|
@@ -1,15 +1,22 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prosopo/procaptcha-bundle",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"author": "PROSOPO LIMITED <info@prosopo.io>",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"main": "./dist/index.js",
|
|
7
7
|
"type": "module",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": "./dist/index.js",
|
|
11
|
+
"require": "./dist/cjs/index.cjs"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
8
14
|
"types": "./dist/index.d.ts",
|
|
9
15
|
"source": "./src/index.tsx",
|
|
10
16
|
"scripts": {
|
|
11
17
|
"clean": "tsc --build --clean",
|
|
12
18
|
"build": "tsc --build --verbose",
|
|
19
|
+
"build:cjs": "npx vite --config vite.cjs.config.ts build",
|
|
13
20
|
"start": "vite serve --mode development --host",
|
|
14
21
|
"build:dev": "npm run build && vite build --mode development --debug",
|
|
15
22
|
"build:prod": "npm run build && vite build --mode production",
|
|
@@ -24,11 +31,11 @@
|
|
|
24
31
|
"@emotion/styled": "^11.11.0",
|
|
25
32
|
"@mui/icons-material": "^5.14.3",
|
|
26
33
|
"@mui/material": "^5.14.5",
|
|
27
|
-
"@prosopo/common": "0.2.
|
|
28
|
-
"@prosopo/procaptcha": "0.2.
|
|
29
|
-
"@prosopo/procaptcha-react": "0.2.
|
|
30
|
-
"@prosopo/types": "0.2.
|
|
31
|
-
"@prosopo/util": "0.2.
|
|
34
|
+
"@prosopo/common": "0.2.2",
|
|
35
|
+
"@prosopo/procaptcha": "0.2.2",
|
|
36
|
+
"@prosopo/procaptcha-react": "0.2.2",
|
|
37
|
+
"@prosopo/types": "0.2.2",
|
|
38
|
+
"@prosopo/util": "0.2.2"
|
|
32
39
|
},
|
|
33
40
|
"repository": {
|
|
34
41
|
"type": "git",
|
|
@@ -44,7 +51,7 @@
|
|
|
44
51
|
},
|
|
45
52
|
"devDependencies": {
|
|
46
53
|
"@originjs/vite-plugin-commonjs": "^1.0.3",
|
|
47
|
-
"@prosopo/config": "0.2.
|
|
54
|
+
"@prosopo/config": "0.2.2",
|
|
48
55
|
"@rollup/plugin-typescript": "^11.1.2",
|
|
49
56
|
"@vitejs/plugin-react": "^4.0.4",
|
|
50
57
|
"tslib": "^2.6.2",
|