Skip to content

Commit 20501fb

Browse files
authored
Merge pull request #97 from Adammatthiesen/update
2 parents 9d60158 + d0c0013 commit 20501fb

File tree

4 files changed

+106
-4
lines changed

4 files changed

+106
-4
lines changed

.changeset/four-trains-argue.md

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
---
2+
"astro-turnstile": patch
3+
---
4+
5+
[Fix/Docs]:
6+
7+
- Update Type `AstroTurnstileOptions` to reflect the correct default values by switching from `z.infer` to a `typeof Schema._input` which properly shows the type as it would be used by the enduser
8+
9+
```ts
10+
// Previously
11+
type AstroTurnstileOptions = {
12+
endpointPath: string;
13+
disableClientScript: boolean;
14+
disableDevToolbar: boolean;
15+
verbose: boolean;
16+
}
17+
18+
// Now
19+
type AstroTurnstileOptions = {
20+
endpointPath?: string | undefined;
21+
disableClientScript?: boolean | undefined;
22+
disableDevToolbar?: boolean | undefined;
23+
verbose?: boolean | undefined;
24+
} | undefined
25+
```
26+
27+
- Update readme to include instructions and more information about what is available to users from the integration

package/README.md

+72-2
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,80 @@ export default defineConfig({
6868

6969
### Configuration
7070

71+
#### `.env` File
72+
7173
You will need to add these 2 values to your `.env` file:
7274

73-
- `siteKey` (required): Your Turnstile site key
74-
- `secretKey` (required): Your Turnstile secret key - this should be kept secret
75+
- `TURNSTILE_SITE_KEY` (required): Your Turnstile site key
76+
- `TURNSTILE_SECRET_KEY` (required): Your Turnstile secret key - this should be kept secret
77+
78+
#### Astro Config Options
79+
80+
**`verbose`**
81+
- Type: `boolean`
82+
- Default: `false`
83+
84+
Enable verbose logging.
85+
86+
**`disableClientScript`**
87+
- Type: `boolean`
88+
- Default: `false`
89+
90+
Disable the client-side script injection.
91+
92+
By default, the client-side script is injected into the Astro project on every page. In some cases, you may want to disable this behavior, and manually inject the script where needed. This option allows you to disable the client-side script injection.
93+
94+
Note: If you disable the client-side script injection, you will need to manually inject the Turnstile client-side script into your Astro project.
95+
96+
**`disableDevToolbar`**
97+
- Type: `boolean`
98+
- Default: `false`
99+
100+
Disable the Astro Turnstile Dev Toolbar App.
101+
102+
**`endpointPath`**
103+
- Type: `string`
104+
- Default: `/verify`
105+
106+
The path to the injected Turnstile API endpoint.
107+
108+
### Usage
109+
110+
The following components are made available to the end user:
111+
112+
- **`TurnstileWidget`** - The main widget component for displaying the Turnstile captcha field in forms
113+
- Available Props:
114+
- **`theme`**:
115+
- Type: `"auto"` | `"light"` | `"dark"` | `undefined`
116+
- Default: `"auto"`
117+
- **`size`**:
118+
- Type: `"normal"` | `"compact"` | `"flexible"` | `undefined`
119+
- Default: `"normal"`
120+
- **`margin`**:
121+
- Type: `string` | `undefined`
122+
- Default: `"0.5rem"`
123+
124+
- `TurnstileForm` - A helper form element that assists you in building your forms with Turnstile verification built in
125+
- Available Props:
126+
- (All the props from Widget)
127+
- **`enctype`**
128+
- Type: `"multipart/form-data"` | `"application/x-www-form-urlencoded"` | `"submit"` | `undefined`
129+
- Default: `"application/x-www-form-urlencoded"`
130+
- **`action`**
131+
- Type: `string` | `null` | `undefined`
132+
- **`method`**
133+
- Type: `string` | `null` | `undefined`
134+
135+
These components can be accessed by either of the following methods:
136+
137+
```ts
138+
// Option 1: Runtime virtual module
139+
import { TurnstileWidget, TurnstileForm } from 'astro-turnstile:components';
140+
141+
// Option 2: Direct package exports
142+
import { TurnstileWidget, TurnstileForm } from 'astro-turnstile/components';
143+
144+
```
75145

76146
## Contributing
77147

package/src/schema.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -109,4 +109,9 @@ export const AstroTurnstileOptionsSchema = z
109109
/**
110110
* Astro-Turnstile configuration options type.
111111
*/
112-
export type AstroTurnstileOptions = z.infer<typeof AstroTurnstileOptionsSchema>;
112+
export type AstroTurnstileOptions = typeof AstroTurnstileOptionsSchema._input;
113+
114+
/**
115+
* Astro-Turnstile configuration options type used by the `virtual:astro-turnstile/config` module.
116+
*/
117+
export type AstroTurnstileConfig = z.infer<typeof AstroTurnstileOptionsSchema>;

package/src/stubs.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ config.addSingleLineNote(
1212
// Add the module to the file
1313
config.addModule("virtual:astro-turnstile/config", {
1414
defaultExport: {
15-
typeDef: `import("${name}/schema").AstroTurnstileOptions`,
15+
typeDef: `import("${name}/schema").AstroTurnstileConfig`,
1616
singleLineDescription: "The Turnstile configuration options",
1717
},
1818
});

0 commit comments

Comments
 (0)