@hcaptcha/react-hcaptcha 1.1.1 → 1.3.1
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 +3 -0
- package/dist/index.js +42 -16
- package/package.json +4 -1
- package/src/index.js +38 -15
- package/types/index.d.ts +3 -0
package/README.md
CHANGED
|
@@ -149,7 +149,10 @@ return <HCaptcha ref={captchaRef} onLoad={onLoad} sitekey={sitekey} {...props} /
|
|
|
149
149
|
|Method|Description|
|
|
150
150
|
|---|---|
|
|
151
151
|
|`execute()`|Programmatically trigger a challenge request. Additionally, this method can be run asynchronously and returns a promise with the `token` and `eKey` when the challenge is completed.|
|
|
152
|
+
|`getRespKey()`|Get the current challenge reference ID|
|
|
153
|
+
|`getResponse()`|Get the current challenge response token from completed challenge|
|
|
152
154
|
|`resetCaptcha()`|Reset the current challenge|
|
|
155
|
+
|`setData()`|See enterprise docs.|
|
|
153
156
|
|
|
154
157
|
|
|
155
158
|
**NOTE**: Make sure to reset the hCaptcha state when you submit your form by calling the method `.resetCaptcha` on your hCaptcha React Component! Passcodes are one-time use, so if your user submits the same passcode twice then it will be rejected by the server the second time.
|
package/dist/index.js
CHANGED
|
@@ -104,22 +104,23 @@ var HCaptcha = /*#__PURE__*/function (_React$Component) {
|
|
|
104
104
|
|
|
105
105
|
if (!isApiReady) {
|
|
106
106
|
//Check if hCaptcha has already been loaded, if not create script tag and wait to render captcha
|
|
107
|
-
if (
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
107
|
+
if (apiScriptRequested) {
|
|
108
|
+
return;
|
|
109
|
+
} // Only create the script tag once, use a global variable to track
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
mountCaptchaScript({
|
|
113
|
+
apihost: apihost,
|
|
114
|
+
assethost: assethost,
|
|
115
|
+
endpoint: endpoint,
|
|
116
|
+
hl: hl,
|
|
117
|
+
host: host,
|
|
118
|
+
imghost: imghost,
|
|
119
|
+
recaptchacompat: reCaptchaCompat === false ? "off" : null,
|
|
120
|
+
reportapi: reportapi,
|
|
121
|
+
sentry: sentry,
|
|
122
|
+
custom: custom
|
|
123
|
+
}); // Add onload callback to global onload listeners
|
|
123
124
|
|
|
124
125
|
onLoadListeners.push(this.handleOnLoad);
|
|
125
126
|
} else {
|
|
@@ -329,6 +330,31 @@ var HCaptcha = /*#__PURE__*/function (_React$Component) {
|
|
|
329
330
|
|
|
330
331
|
return hcaptcha.execute(captchaId, opts);
|
|
331
332
|
}
|
|
333
|
+
}, {
|
|
334
|
+
key: "setData",
|
|
335
|
+
value: function setData(data) {
|
|
336
|
+
var captchaId = this.state.captchaId;
|
|
337
|
+
|
|
338
|
+
if (!this.isReady()) {
|
|
339
|
+
return;
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
if (data && (0, _typeof2["default"])(data) !== "object") {
|
|
343
|
+
data = null;
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
hcaptcha.setData(captchaId, data);
|
|
347
|
+
}
|
|
348
|
+
}, {
|
|
349
|
+
key: "getResponse",
|
|
350
|
+
value: function getResponse() {
|
|
351
|
+
return hcaptcha.getResponse(this.state.captchaId);
|
|
352
|
+
}
|
|
353
|
+
}, {
|
|
354
|
+
key: "getRespKey",
|
|
355
|
+
value: function getRespKey() {
|
|
356
|
+
return hcaptcha.getRespKey(this.state.captchaId);
|
|
357
|
+
}
|
|
332
358
|
}, {
|
|
333
359
|
key: "render",
|
|
334
360
|
value: function render() {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hcaptcha/react-hcaptcha",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.1",
|
|
4
4
|
"types": "types/index.d.ts",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"files": [
|
|
@@ -43,5 +43,8 @@
|
|
|
43
43
|
"webpack": "^4.44.2",
|
|
44
44
|
"webpack-cli": "^3.3.12",
|
|
45
45
|
"webpack-dev-server": "^3.11.0"
|
|
46
|
+
},
|
|
47
|
+
"dependencies": {
|
|
48
|
+
"@babel/runtime": "^7.17.9"
|
|
46
49
|
}
|
|
47
50
|
}
|
package/src/index.js
CHANGED
|
@@ -67,23 +67,24 @@ class HCaptcha extends React.Component {
|
|
|
67
67
|
const { isApiReady } = this.state;
|
|
68
68
|
|
|
69
69
|
if (!isApiReady) { //Check if hCaptcha has already been loaded, if not create script tag and wait to render captcha
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
// Only create the script tag once, use a global variable to track
|
|
73
|
-
mountCaptchaScript({
|
|
74
|
-
apihost,
|
|
75
|
-
assethost,
|
|
76
|
-
endpoint,
|
|
77
|
-
hl,
|
|
78
|
-
host,
|
|
79
|
-
imghost,
|
|
80
|
-
recaptchacompat: reCaptchaCompat === false? "off" : null,
|
|
81
|
-
reportapi,
|
|
82
|
-
sentry,
|
|
83
|
-
custom
|
|
84
|
-
});
|
|
70
|
+
if (apiScriptRequested) {
|
|
71
|
+
return;
|
|
85
72
|
}
|
|
86
73
|
|
|
74
|
+
// Only create the script tag once, use a global variable to track
|
|
75
|
+
mountCaptchaScript({
|
|
76
|
+
apihost,
|
|
77
|
+
assethost,
|
|
78
|
+
endpoint,
|
|
79
|
+
hl,
|
|
80
|
+
host,
|
|
81
|
+
imghost,
|
|
82
|
+
recaptchacompat: reCaptchaCompat === false? "off" : null,
|
|
83
|
+
reportapi,
|
|
84
|
+
sentry,
|
|
85
|
+
custom
|
|
86
|
+
});
|
|
87
|
+
|
|
87
88
|
// Add onload callback to global onload listeners
|
|
88
89
|
onLoadListeners.push(this.handleOnLoad);
|
|
89
90
|
} else {
|
|
@@ -265,6 +266,28 @@ class HCaptcha extends React.Component {
|
|
|
265
266
|
return hcaptcha.execute(captchaId, opts);
|
|
266
267
|
}
|
|
267
268
|
|
|
269
|
+
setData (data) {
|
|
270
|
+
const { captchaId } = this.state;
|
|
271
|
+
|
|
272
|
+
if (!this.isReady()) {
|
|
273
|
+
return;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
if (data && typeof data !== "object") {
|
|
277
|
+
data = null;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
hcaptcha.setData(captchaId, data);
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
getResponse() {
|
|
284
|
+
return hcaptcha.getResponse(this.state.captchaId);
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
getRespKey() {
|
|
288
|
+
return hcaptcha.getRespKey(this.state.captchaId)
|
|
289
|
+
}
|
|
290
|
+
|
|
268
291
|
render () {
|
|
269
292
|
const { elementId } = this.state;
|
|
270
293
|
return <div ref={this.ref} id={elementId}></div>
|
package/types/index.d.ts
CHANGED
|
@@ -39,6 +39,9 @@ declare class HCaptcha extends React.Component<HCaptchaProps, HCaptchaState> {
|
|
|
39
39
|
resetCaptcha(): void;
|
|
40
40
|
renderCaptcha(): void;
|
|
41
41
|
removeCaptcha(): void;
|
|
42
|
+
getRespKey(): string;
|
|
43
|
+
getResponse(): string;
|
|
44
|
+
setData(data: object): void;
|
|
42
45
|
execute(opts: { async: true }): Promise<ExecuteResponse>;
|
|
43
46
|
execute(opts?: { async: false }): void;
|
|
44
47
|
execute(opts?: { async: boolean }): Promise<ExecuteResponse> | void;
|