@aifeatures/react 0.1.7 → 0.1.8
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.cjs +12 -28
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -4
- package/dist/index.d.ts +3 -4
- package/dist/index.js +13 -29
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -37,7 +37,6 @@ function AifeaturesCaptcha({
|
|
|
37
37
|
className
|
|
38
38
|
}) {
|
|
39
39
|
const [sitekey, setSitekey] = (0, import_react.useState)(null);
|
|
40
|
-
const [token, setToken] = (0, import_react.useState)("");
|
|
41
40
|
const [isLoading, setIsLoading] = (0, import_react.useState)(true);
|
|
42
41
|
(0, import_react.useEffect)(() => {
|
|
43
42
|
setIsLoading(true);
|
|
@@ -48,34 +47,19 @@ function AifeaturesCaptcha({
|
|
|
48
47
|
setIsLoading(false);
|
|
49
48
|
});
|
|
50
49
|
}, [formId, apiUrl]);
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
onVerify?.(newToken);
|
|
54
|
-
};
|
|
55
|
-
const handleError = () => {
|
|
56
|
-
setToken("");
|
|
57
|
-
onError?.();
|
|
58
|
-
};
|
|
59
|
-
const handleExpire = () => {
|
|
60
|
-
setToken("");
|
|
61
|
-
onError?.();
|
|
62
|
-
};
|
|
63
|
-
if (isLoading) {
|
|
64
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("input", { type: "hidden", name: "aifeatures-captcha-token", value: "" });
|
|
50
|
+
if (isLoading || !sitekey) {
|
|
51
|
+
return null;
|
|
65
52
|
}
|
|
66
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
}
|
|
77
|
-
)
|
|
78
|
-
] });
|
|
53
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
54
|
+
import_react_turnstile.Turnstile,
|
|
55
|
+
{
|
|
56
|
+
siteKey: sitekey,
|
|
57
|
+
onSuccess: onVerify,
|
|
58
|
+
onError,
|
|
59
|
+
onExpire: onError,
|
|
60
|
+
options: { theme: "light" }
|
|
61
|
+
}
|
|
62
|
+
) });
|
|
79
63
|
}
|
|
80
64
|
// Annotate the CommonJS export names for ESM import in node:
|
|
81
65
|
0 && (module.exports = {
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/AifeaturesCaptcha.tsx"],"sourcesContent":["export { AifeaturesCaptcha } from './AifeaturesCaptcha';\nexport type { AifeaturesCaptchaProps } from './AifeaturesCaptcha';\n","import { useState, useEffect } from 'react';\nimport { Turnstile } from '@marsidev/react-turnstile';\n\nexport interface AifeaturesCaptchaProps {\n /** Form ID from aifeatures - used to fetch the Turnstile sitekey */\n formId: string;\n /** Base URL for the aifeatures API (defaults to https://aifeatures.dev) */\n apiUrl?: string;\n /** Called when CAPTCHA verification succeeds */\n onVerify?: (token: string) => void;\n /** Called when CAPTCHA verification fails or expires */\n onError?: () => void;\n /** Additional class name for the container */\n className?: string;\n}\n\ninterface FormConfig {\n id: string;\n name: string;\n endpoint_url: string;\n turnstile_sitekey: string | null;\n}\n\n/**\n * A CAPTCHA component that handles Turnstile verification for aifeatures forms.\n *\n * Drop this into any form to add CAPTCHA protection.
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/AifeaturesCaptcha.tsx"],"sourcesContent":["export { AifeaturesCaptcha } from './AifeaturesCaptcha';\nexport type { AifeaturesCaptchaProps } from './AifeaturesCaptcha';\n","import { useState, useEffect } from 'react';\nimport { Turnstile } from '@marsidev/react-turnstile';\n\nexport interface AifeaturesCaptchaProps {\n /** Form ID from aifeatures - used to fetch the Turnstile sitekey */\n formId: string;\n /** Base URL for the aifeatures API (defaults to https://aifeatures.dev) */\n apiUrl?: string;\n /** Called when CAPTCHA verification succeeds */\n onVerify?: (token: string) => void;\n /** Called when CAPTCHA verification fails or expires */\n onError?: () => void;\n /** Additional class name for the container */\n className?: string;\n}\n\ninterface FormConfig {\n id: string;\n name: string;\n endpoint_url: string;\n turnstile_sitekey: string | null;\n}\n\n/**\n * A CAPTCHA component that handles Turnstile verification for aifeatures forms.\n *\n * Drop this into any form to add CAPTCHA protection. The Turnstile widget\n * automatically adds a hidden `cf-turnstile-response` input to the form.\n *\n * @example\n * ```tsx\n * <form action={`https://aifeatures.dev/f/${formId}`} method=\"POST\">\n * <input name=\"email\" type=\"email\" required />\n * <textarea name=\"message\" />\n * <AifeaturesCaptcha formId={formId} />\n * <button type=\"submit\">Send</button>\n * </form>\n * ```\n */\nexport function AifeaturesCaptcha({\n formId,\n apiUrl = 'https://aifeatures.dev',\n onVerify,\n onError,\n className,\n}: AifeaturesCaptchaProps) {\n const [sitekey, setSitekey] = useState<string | null>(null);\n const [isLoading, setIsLoading] = useState(true);\n\n useEffect(() => {\n setIsLoading(true);\n fetch(`${apiUrl}/f/${formId}/config`)\n .then((r) => r.json())\n .then((config: FormConfig) => {\n setSitekey(config.turnstile_sitekey);\n setIsLoading(false);\n })\n .catch(() => {\n setIsLoading(false);\n });\n }, [formId, apiUrl]);\n\n if (isLoading || !sitekey) {\n return null;\n }\n\n return (\n <div className={className}>\n <Turnstile\n siteKey={sitekey}\n onSuccess={onVerify}\n onError={onError}\n onExpire={onError}\n options={{ theme: 'light' }}\n />\n </div>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,mBAAoC;AACpC,6BAA0B;AAmEpB;AA7BC,SAAS,kBAAkB;AAAA,EAChC;AAAA,EACA,SAAS;AAAA,EACT;AAAA,EACA;AAAA,EACA;AACF,GAA2B;AACzB,QAAM,CAAC,SAAS,UAAU,QAAI,uBAAwB,IAAI;AAC1D,QAAM,CAAC,WAAW,YAAY,QAAI,uBAAS,IAAI;AAE/C,8BAAU,MAAM;AACd,iBAAa,IAAI;AACjB,UAAM,GAAG,MAAM,MAAM,MAAM,SAAS,EACjC,KAAK,CAAC,MAAM,EAAE,KAAK,CAAC,EACpB,KAAK,CAAC,WAAuB;AAC5B,iBAAW,OAAO,iBAAiB;AACnC,mBAAa,KAAK;AAAA,IACpB,CAAC,EACA,MAAM,MAAM;AACX,mBAAa,KAAK;AAAA,IACpB,CAAC;AAAA,EACL,GAAG,CAAC,QAAQ,MAAM,CAAC;AAEnB,MAAI,aAAa,CAAC,SAAS;AACzB,WAAO;AAAA,EACT;AAEA,SACE,4CAAC,SAAI,WACH;AAAA,IAAC;AAAA;AAAA,MACC,SAAS;AAAA,MACT,WAAW;AAAA,MACX;AAAA,MACA,UAAU;AAAA,MACV,SAAS,EAAE,OAAO,QAAQ;AAAA;AAAA,EAC5B,GACF;AAEJ;","names":[]}
|
package/dist/index.d.cts
CHANGED
|
@@ -15,9 +15,8 @@ interface AifeaturesCaptchaProps {
|
|
|
15
15
|
/**
|
|
16
16
|
* A CAPTCHA component that handles Turnstile verification for aifeatures forms.
|
|
17
17
|
*
|
|
18
|
-
* Drop this into any form to add CAPTCHA protection.
|
|
19
|
-
*
|
|
20
|
-
* - The Turnstile widget (only if CAPTCHA is enabled for the form)
|
|
18
|
+
* Drop this into any form to add CAPTCHA protection. The Turnstile widget
|
|
19
|
+
* automatically adds a hidden `cf-turnstile-response` input to the form.
|
|
21
20
|
*
|
|
22
21
|
* @example
|
|
23
22
|
* ```tsx
|
|
@@ -29,6 +28,6 @@ interface AifeaturesCaptchaProps {
|
|
|
29
28
|
* </form>
|
|
30
29
|
* ```
|
|
31
30
|
*/
|
|
32
|
-
declare function AifeaturesCaptcha({ formId, apiUrl, onVerify, onError, className, }: AifeaturesCaptchaProps): react_jsx_runtime.JSX.Element;
|
|
31
|
+
declare function AifeaturesCaptcha({ formId, apiUrl, onVerify, onError, className, }: AifeaturesCaptchaProps): react_jsx_runtime.JSX.Element | null;
|
|
33
32
|
|
|
34
33
|
export { AifeaturesCaptcha, type AifeaturesCaptchaProps };
|
package/dist/index.d.ts
CHANGED
|
@@ -15,9 +15,8 @@ interface AifeaturesCaptchaProps {
|
|
|
15
15
|
/**
|
|
16
16
|
* A CAPTCHA component that handles Turnstile verification for aifeatures forms.
|
|
17
17
|
*
|
|
18
|
-
* Drop this into any form to add CAPTCHA protection.
|
|
19
|
-
*
|
|
20
|
-
* - The Turnstile widget (only if CAPTCHA is enabled for the form)
|
|
18
|
+
* Drop this into any form to add CAPTCHA protection. The Turnstile widget
|
|
19
|
+
* automatically adds a hidden `cf-turnstile-response` input to the form.
|
|
21
20
|
*
|
|
22
21
|
* @example
|
|
23
22
|
* ```tsx
|
|
@@ -29,6 +28,6 @@ interface AifeaturesCaptchaProps {
|
|
|
29
28
|
* </form>
|
|
30
29
|
* ```
|
|
31
30
|
*/
|
|
32
|
-
declare function AifeaturesCaptcha({ formId, apiUrl, onVerify, onError, className, }: AifeaturesCaptchaProps): react_jsx_runtime.JSX.Element;
|
|
31
|
+
declare function AifeaturesCaptcha({ formId, apiUrl, onVerify, onError, className, }: AifeaturesCaptchaProps): react_jsx_runtime.JSX.Element | null;
|
|
33
32
|
|
|
34
33
|
export { AifeaturesCaptcha, type AifeaturesCaptchaProps };
|
package/dist/index.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// src/AifeaturesCaptcha.tsx
|
|
4
4
|
import { useState, useEffect } from "react";
|
|
5
5
|
import { Turnstile } from "@marsidev/react-turnstile";
|
|
6
|
-
import { jsx
|
|
6
|
+
import { jsx } from "react/jsx-runtime";
|
|
7
7
|
function AifeaturesCaptcha({
|
|
8
8
|
formId,
|
|
9
9
|
apiUrl = "https://aifeatures.dev",
|
|
@@ -12,7 +12,6 @@ function AifeaturesCaptcha({
|
|
|
12
12
|
className
|
|
13
13
|
}) {
|
|
14
14
|
const [sitekey, setSitekey] = useState(null);
|
|
15
|
-
const [token, setToken] = useState("");
|
|
16
15
|
const [isLoading, setIsLoading] = useState(true);
|
|
17
16
|
useEffect(() => {
|
|
18
17
|
setIsLoading(true);
|
|
@@ -23,34 +22,19 @@ function AifeaturesCaptcha({
|
|
|
23
22
|
setIsLoading(false);
|
|
24
23
|
});
|
|
25
24
|
}, [formId, apiUrl]);
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
onVerify?.(newToken);
|
|
29
|
-
};
|
|
30
|
-
const handleError = () => {
|
|
31
|
-
setToken("");
|
|
32
|
-
onError?.();
|
|
33
|
-
};
|
|
34
|
-
const handleExpire = () => {
|
|
35
|
-
setToken("");
|
|
36
|
-
onError?.();
|
|
37
|
-
};
|
|
38
|
-
if (isLoading) {
|
|
39
|
-
return /* @__PURE__ */ jsx("input", { type: "hidden", name: "aifeatures-captcha-token", value: "" });
|
|
25
|
+
if (isLoading || !sitekey) {
|
|
26
|
+
return null;
|
|
40
27
|
}
|
|
41
|
-
return /* @__PURE__ */
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
}
|
|
52
|
-
)
|
|
53
|
-
] });
|
|
28
|
+
return /* @__PURE__ */ jsx("div", { className, children: /* @__PURE__ */ jsx(
|
|
29
|
+
Turnstile,
|
|
30
|
+
{
|
|
31
|
+
siteKey: sitekey,
|
|
32
|
+
onSuccess: onVerify,
|
|
33
|
+
onError,
|
|
34
|
+
onExpire: onError,
|
|
35
|
+
options: { theme: "light" }
|
|
36
|
+
}
|
|
37
|
+
) });
|
|
54
38
|
}
|
|
55
39
|
export {
|
|
56
40
|
AifeaturesCaptcha
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/AifeaturesCaptcha.tsx"],"sourcesContent":["import { useState, useEffect } from 'react';\nimport { Turnstile } from '@marsidev/react-turnstile';\n\nexport interface AifeaturesCaptchaProps {\n /** Form ID from aifeatures - used to fetch the Turnstile sitekey */\n formId: string;\n /** Base URL for the aifeatures API (defaults to https://aifeatures.dev) */\n apiUrl?: string;\n /** Called when CAPTCHA verification succeeds */\n onVerify?: (token: string) => void;\n /** Called when CAPTCHA verification fails or expires */\n onError?: () => void;\n /** Additional class name for the container */\n className?: string;\n}\n\ninterface FormConfig {\n id: string;\n name: string;\n endpoint_url: string;\n turnstile_sitekey: string | null;\n}\n\n/**\n * A CAPTCHA component that handles Turnstile verification for aifeatures forms.\n *\n * Drop this into any form to add CAPTCHA protection.
|
|
1
|
+
{"version":3,"sources":["../src/AifeaturesCaptcha.tsx"],"sourcesContent":["import { useState, useEffect } from 'react';\nimport { Turnstile } from '@marsidev/react-turnstile';\n\nexport interface AifeaturesCaptchaProps {\n /** Form ID from aifeatures - used to fetch the Turnstile sitekey */\n formId: string;\n /** Base URL for the aifeatures API (defaults to https://aifeatures.dev) */\n apiUrl?: string;\n /** Called when CAPTCHA verification succeeds */\n onVerify?: (token: string) => void;\n /** Called when CAPTCHA verification fails or expires */\n onError?: () => void;\n /** Additional class name for the container */\n className?: string;\n}\n\ninterface FormConfig {\n id: string;\n name: string;\n endpoint_url: string;\n turnstile_sitekey: string | null;\n}\n\n/**\n * A CAPTCHA component that handles Turnstile verification for aifeatures forms.\n *\n * Drop this into any form to add CAPTCHA protection. The Turnstile widget\n * automatically adds a hidden `cf-turnstile-response` input to the form.\n *\n * @example\n * ```tsx\n * <form action={`https://aifeatures.dev/f/${formId}`} method=\"POST\">\n * <input name=\"email\" type=\"email\" required />\n * <textarea name=\"message\" />\n * <AifeaturesCaptcha formId={formId} />\n * <button type=\"submit\">Send</button>\n * </form>\n * ```\n */\nexport function AifeaturesCaptcha({\n formId,\n apiUrl = 'https://aifeatures.dev',\n onVerify,\n onError,\n className,\n}: AifeaturesCaptchaProps) {\n const [sitekey, setSitekey] = useState<string | null>(null);\n const [isLoading, setIsLoading] = useState(true);\n\n useEffect(() => {\n setIsLoading(true);\n fetch(`${apiUrl}/f/${formId}/config`)\n .then((r) => r.json())\n .then((config: FormConfig) => {\n setSitekey(config.turnstile_sitekey);\n setIsLoading(false);\n })\n .catch(() => {\n setIsLoading(false);\n });\n }, [formId, apiUrl]);\n\n if (isLoading || !sitekey) {\n return null;\n }\n\n return (\n <div className={className}>\n <Turnstile\n siteKey={sitekey}\n onSuccess={onVerify}\n onError={onError}\n onExpire={onError}\n options={{ theme: 'light' }}\n />\n </div>\n );\n}\n"],"mappings":";;;AAAA,SAAS,UAAU,iBAAiB;AACpC,SAAS,iBAAiB;AAmEpB;AA7BC,SAAS,kBAAkB;AAAA,EAChC;AAAA,EACA,SAAS;AAAA,EACT;AAAA,EACA;AAAA,EACA;AACF,GAA2B;AACzB,QAAM,CAAC,SAAS,UAAU,IAAI,SAAwB,IAAI;AAC1D,QAAM,CAAC,WAAW,YAAY,IAAI,SAAS,IAAI;AAE/C,YAAU,MAAM;AACd,iBAAa,IAAI;AACjB,UAAM,GAAG,MAAM,MAAM,MAAM,SAAS,EACjC,KAAK,CAAC,MAAM,EAAE,KAAK,CAAC,EACpB,KAAK,CAAC,WAAuB;AAC5B,iBAAW,OAAO,iBAAiB;AACnC,mBAAa,KAAK;AAAA,IACpB,CAAC,EACA,MAAM,MAAM;AACX,mBAAa,KAAK;AAAA,IACpB,CAAC;AAAA,EACL,GAAG,CAAC,QAAQ,MAAM,CAAC;AAEnB,MAAI,aAAa,CAAC,SAAS;AACzB,WAAO;AAAA,EACT;AAEA,SACE,oBAAC,SAAI,WACH;AAAA,IAAC;AAAA;AAAA,MACC,SAAS;AAAA,MACT,WAAW;AAAA,MACX;AAAA,MACA,UAAU;AAAA,MACV,SAAS,EAAE,OAAO,QAAQ;AAAA;AAAA,EAC5B,GACF;AAEJ;","names":[]}
|