@hcaptcha/react-hcaptcha 1.6.0 → 1.7.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/README.md +2 -1
- package/dist/esm/index.js +12 -6
- package/dist/index.js +11 -6
- package/package.json +1 -1
- package/src/index.js +13 -6
- package/types/index.d.ts +1 -0
package/README.md
CHANGED
|
@@ -139,7 +139,8 @@ return <HCaptcha ref={captchaRef} onLoad={onLoad} sitekey={sitekey} {...props} /
|
|
|
139
139
|
|`reportapi`|String|No|`-`|See enterprise docs.|
|
|
140
140
|
|`sentry`|String|No|`-`|See enterprise docs.|
|
|
141
141
|
|`custom`|Boolean|No|`-`|See enterprise docs.|
|
|
142
|
-
|`loadAsync`|Boolean|No|`true`|Set if the script should be loaded asynchronously
|
|
142
|
+
|`loadAsync`|Boolean|No|`true`|Set if the script should be loaded asynchronously.|
|
|
143
|
+
|`scriptLocation`|Element|No|`document.head`| Location of where to append the script tag. Make sure to add it to an area that will persist to prevent loading multiple times in the same document view. Note: If `null` is provided, the `document.head` will be used.|
|
|
143
144
|
|
|
144
145
|
#### Events
|
|
145
146
|
|
package/dist/esm/index.js
CHANGED
|
@@ -17,7 +17,11 @@ var mountCaptchaScript = function mountCaptchaScript(params) {
|
|
|
17
17
|
params = {};
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
|
|
20
|
+
var parent = params.scriptLocation || document.head;
|
|
21
|
+
delete params.scriptLocation;
|
|
22
|
+
var doc = parent.ownerDocument || document;
|
|
23
|
+
|
|
24
|
+
if (doc.getElementById(SCRIPT_ID)) {
|
|
21
25
|
// API was already requested
|
|
22
26
|
return mountPromise;
|
|
23
27
|
} // Create global onload callback
|
|
@@ -26,7 +30,7 @@ var mountCaptchaScript = function mountCaptchaScript(params) {
|
|
|
26
30
|
window[HCAPTCHA_LOAD_FN_NAME] = resolveFn;
|
|
27
31
|
var domain = params.apihost || "https://js.hcaptcha.com";
|
|
28
32
|
delete params.apihost;
|
|
29
|
-
var script =
|
|
33
|
+
var script = doc.createElement("script");
|
|
30
34
|
script.id = SCRIPT_ID;
|
|
31
35
|
script.src = domain + "/1/api.js?render=explicit&onload=" + HCAPTCHA_LOAD_FN_NAME;
|
|
32
36
|
script.async = params.loadAsync !== undefined ? params.loadAsync : true;
|
|
@@ -38,7 +42,7 @@ var mountCaptchaScript = function mountCaptchaScript(params) {
|
|
|
38
42
|
|
|
39
43
|
var query = generateQuery(params);
|
|
40
44
|
script.src += query !== "" ? "&" + query : "";
|
|
41
|
-
|
|
45
|
+
parent.appendChild(script);
|
|
42
46
|
return mountPromise;
|
|
43
47
|
};
|
|
44
48
|
|
|
@@ -148,7 +152,8 @@ var HCaptcha = /*#__PURE__*/function (_React$Component) {
|
|
|
148
152
|
reportapi = _this$props.reportapi,
|
|
149
153
|
sentry = _this$props.sentry,
|
|
150
154
|
custom = _this$props.custom,
|
|
151
|
-
loadAsync = _this$props.loadAsync
|
|
155
|
+
loadAsync = _this$props.loadAsync,
|
|
156
|
+
scriptLocation = _this$props.scriptLocation;
|
|
152
157
|
var mountParams = {
|
|
153
158
|
apihost: apihost,
|
|
154
159
|
assethost: assethost,
|
|
@@ -160,7 +165,8 @@ var HCaptcha = /*#__PURE__*/function (_React$Component) {
|
|
|
160
165
|
reportapi: reportapi,
|
|
161
166
|
sentry: sentry,
|
|
162
167
|
custom: custom,
|
|
163
|
-
loadAsync: loadAsync
|
|
168
|
+
loadAsync: loadAsync,
|
|
169
|
+
scriptLocation: scriptLocation
|
|
164
170
|
};
|
|
165
171
|
mountCaptchaScript(mountParams).then(this.handleOnLoad)["catch"](this.handleError);
|
|
166
172
|
this.apiScriptRequested = true;
|
|
@@ -241,7 +247,7 @@ var HCaptcha = /*#__PURE__*/function (_React$Component) {
|
|
|
241
247
|
|
|
242
248
|
var ekey = hcaptcha.getRespKey(captchaId); //Get current challenge session id from hCaptcha widget
|
|
243
249
|
|
|
244
|
-
onVerify(token, ekey); //Dispatch event to verify user response
|
|
250
|
+
if (onVerify) onVerify(token, ekey); //Dispatch event to verify user response
|
|
245
251
|
};
|
|
246
252
|
|
|
247
253
|
_proto.handleExpire = function handleExpire() {
|
package/dist/index.js
CHANGED
|
@@ -43,8 +43,11 @@ var mountPromise = new Promise(function (resolve, reject) {
|
|
|
43
43
|
|
|
44
44
|
var mountCaptchaScript = function mountCaptchaScript() {
|
|
45
45
|
var params = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
46
|
+
var parent = params.scriptLocation || document.head;
|
|
47
|
+
delete params.scriptLocation;
|
|
48
|
+
var doc = parent.ownerDocument || document;
|
|
46
49
|
|
|
47
|
-
if (
|
|
50
|
+
if (doc.getElementById(SCRIPT_ID)) {
|
|
48
51
|
// API was already requested
|
|
49
52
|
return mountPromise;
|
|
50
53
|
} // Create global onload callback
|
|
@@ -53,7 +56,7 @@ var mountCaptchaScript = function mountCaptchaScript() {
|
|
|
53
56
|
window[HCAPTCHA_LOAD_FN_NAME] = resolveFn;
|
|
54
57
|
var domain = params.apihost || "https://js.hcaptcha.com";
|
|
55
58
|
delete params.apihost;
|
|
56
|
-
var script =
|
|
59
|
+
var script = doc.createElement("script");
|
|
57
60
|
script.id = SCRIPT_ID;
|
|
58
61
|
script.src = "".concat(domain, "/1/api.js?render=explicit&onload=").concat(HCAPTCHA_LOAD_FN_NAME);
|
|
59
62
|
script.async = params.loadAsync !== undefined ? params.loadAsync : true;
|
|
@@ -65,7 +68,7 @@ var mountCaptchaScript = function mountCaptchaScript() {
|
|
|
65
68
|
|
|
66
69
|
var query = (0, _utils.generateQuery)(params);
|
|
67
70
|
script.src += query !== "" ? "&".concat(query) : "";
|
|
68
|
-
|
|
71
|
+
parent.appendChild(script);
|
|
69
72
|
return mountPromise;
|
|
70
73
|
};
|
|
71
74
|
|
|
@@ -182,7 +185,8 @@ var HCaptcha = /*#__PURE__*/function (_React$Component) {
|
|
|
182
185
|
reportapi = _this$props.reportapi,
|
|
183
186
|
sentry = _this$props.sentry,
|
|
184
187
|
custom = _this$props.custom,
|
|
185
|
-
loadAsync = _this$props.loadAsync
|
|
188
|
+
loadAsync = _this$props.loadAsync,
|
|
189
|
+
scriptLocation = _this$props.scriptLocation;
|
|
186
190
|
var mountParams = {
|
|
187
191
|
apihost: apihost,
|
|
188
192
|
assethost: assethost,
|
|
@@ -194,7 +198,8 @@ var HCaptcha = /*#__PURE__*/function (_React$Component) {
|
|
|
194
198
|
reportapi: reportapi,
|
|
195
199
|
sentry: sentry,
|
|
196
200
|
custom: custom,
|
|
197
|
-
loadAsync: loadAsync
|
|
201
|
+
loadAsync: loadAsync,
|
|
202
|
+
scriptLocation: scriptLocation
|
|
198
203
|
};
|
|
199
204
|
mountCaptchaScript(mountParams).then(this.handleOnLoad)["catch"](this.handleError);
|
|
200
205
|
this.apiScriptRequested = true;
|
|
@@ -280,7 +285,7 @@ var HCaptcha = /*#__PURE__*/function (_React$Component) {
|
|
|
280
285
|
|
|
281
286
|
var ekey = hcaptcha.getRespKey(captchaId); //Get current challenge session id from hCaptcha widget
|
|
282
287
|
|
|
283
|
-
onVerify(token, ekey); //Dispatch event to verify user response
|
|
288
|
+
if (onVerify) onVerify(token, ekey); //Dispatch event to verify user response
|
|
284
289
|
}
|
|
285
290
|
}, {
|
|
286
291
|
key: "handleExpire",
|
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -14,7 +14,12 @@ const mountPromise = new Promise((resolve, reject) => {
|
|
|
14
14
|
|
|
15
15
|
// Generate hCaptcha API script
|
|
16
16
|
const mountCaptchaScript = (params={}) => {
|
|
17
|
-
|
|
17
|
+
const parent = params.scriptLocation || document.head;
|
|
18
|
+
delete params.scriptLocation;
|
|
19
|
+
|
|
20
|
+
const doc = parent.ownerDocument || document;
|
|
21
|
+
|
|
22
|
+
if (doc.getElementById(SCRIPT_ID)) {
|
|
18
23
|
// API was already requested
|
|
19
24
|
return mountPromise;
|
|
20
25
|
}
|
|
@@ -25,7 +30,7 @@ const mountCaptchaScript = (params={}) => {
|
|
|
25
30
|
const domain = params.apihost || "https://js.hcaptcha.com";
|
|
26
31
|
delete params.apihost;
|
|
27
32
|
|
|
28
|
-
const script =
|
|
33
|
+
const script = doc.createElement("script");
|
|
29
34
|
script.id = SCRIPT_ID;
|
|
30
35
|
script.src = `${domain}/1/api.js?render=explicit&onload=${HCAPTCHA_LOAD_FN_NAME}`;
|
|
31
36
|
|
|
@@ -37,7 +42,7 @@ const mountCaptchaScript = (params={}) => {
|
|
|
37
42
|
const query = generateQuery(params);
|
|
38
43
|
script.src += query !== ""? `&${query}` : "";
|
|
39
44
|
|
|
40
|
-
|
|
45
|
+
parent.appendChild(script);
|
|
41
46
|
return mountPromise;
|
|
42
47
|
};
|
|
43
48
|
|
|
@@ -143,7 +148,8 @@ class HCaptcha extends React.Component {
|
|
|
143
148
|
reportapi,
|
|
144
149
|
sentry,
|
|
145
150
|
custom,
|
|
146
|
-
loadAsync
|
|
151
|
+
loadAsync,
|
|
152
|
+
scriptLocation
|
|
147
153
|
} = this.props;
|
|
148
154
|
const mountParams = {
|
|
149
155
|
apihost,
|
|
@@ -156,7 +162,8 @@ class HCaptcha extends React.Component {
|
|
|
156
162
|
reportapi,
|
|
157
163
|
sentry,
|
|
158
164
|
custom,
|
|
159
|
-
loadAsync
|
|
165
|
+
loadAsync,
|
|
166
|
+
scriptLocation
|
|
160
167
|
};
|
|
161
168
|
|
|
162
169
|
mountCaptchaScript(mountParams)
|
|
@@ -232,7 +239,7 @@ class HCaptcha extends React.Component {
|
|
|
232
239
|
|
|
233
240
|
const token = hcaptcha.getResponse(captchaId) //Get response token from hCaptcha widget
|
|
234
241
|
const ekey = hcaptcha.getRespKey(captchaId) //Get current challenge session id from hCaptcha widget
|
|
235
|
-
onVerify(token, ekey) //Dispatch event to verify user response
|
|
242
|
+
if (onVerify) onVerify(token, ekey) //Dispatch event to verify user response
|
|
236
243
|
}
|
|
237
244
|
|
|
238
245
|
handleExpire () {
|