@onderwijsin/nuxt-turnstile 0.2.10 → 0.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 +7 -3
- package/dist/module.json +1 -1
- package/dist/module.mjs +12 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -103,9 +103,10 @@ export default defineEventHandler(async (event) => {
|
|
|
103
103
|
});
|
|
104
104
|
```
|
|
105
105
|
|
|
106
|
-
The helper reads `x-turnstile-token` and verifies it
|
|
107
|
-
missing, failed, unavailable, or mismatched-action tokens. In development, an
|
|
108
|
-
local forms usable; in production, it produces
|
|
106
|
+
The helper reads `x-turnstile-token` and verifies it directly with Cloudflare's Turnstile siteverify
|
|
107
|
+
endpoint. It rejects missing, failed, unavailable, or mismatched-action tokens. In development, an
|
|
108
|
+
absent secret leaves local forms usable; in production, it produces
|
|
109
|
+
`TURNSTILE_SERVER_MISCONFIGURED`.
|
|
109
110
|
|
|
110
111
|
Cloudflare's official test credentials return `metadata.result_with_testing_key: true` without an
|
|
111
112
|
`action`. The helper accepts only that verified test-key response without action matching, so test
|
|
@@ -135,6 +136,9 @@ Stable error codes are `TURNSTILE_TOKEN_MISSING`, `TURNSTILE_VALIDATION_FAILED`,
|
|
|
135
136
|
`TURNSTILE_SERVER_MISCONFIGURED`. Apply authorization and business validation in the consuming route
|
|
136
137
|
after Turnstile succeeds; the module does not replace the route's existing submit or business logic.
|
|
137
138
|
|
|
139
|
+
`verifyTurnstileToken` is also auto-imported for server-only use when the raw Cloudflare
|
|
140
|
+
verification response is needed. Prefer `assertTurnstileToken` for protected application routes.
|
|
141
|
+
|
|
138
142
|
## Compatibility
|
|
139
143
|
|
|
140
144
|
- Nuxt 4
|
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { defineNuxtModule, useLogger, createResolver, addTypeTemplate, addImportsDir, addServerScanDir } from '@nuxt/kit';
|
|
2
2
|
import { defu } from 'defu';
|
|
3
3
|
import { enabled, resolveModuleName, resolveLoggerScope, moduleSetup, validateModuleOptions, transpileRuntime, moduleDependenciesWhenEnabled } from '@onderwijsin/nuxt-module-utils/build';
|
|
4
|
+
import { isRecord, hasKey, isArray, isString } from '@onderwijsin/nuxt-module-utils/shared';
|
|
4
5
|
import { z } from 'zod';
|
|
5
6
|
|
|
6
|
-
const version = "0.
|
|
7
|
+
const version = "0.3.1";
|
|
7
8
|
|
|
8
9
|
const turnstileOptionsSchema = z.object({
|
|
9
10
|
enabled,
|
|
@@ -22,6 +23,9 @@ const DEFAULTS = {
|
|
|
22
23
|
adminToken: "",
|
|
23
24
|
adminHeaderName: "x-admin-token"
|
|
24
25
|
};
|
|
26
|
+
function isUpstreamTurnstileVerifierPreset(preset) {
|
|
27
|
+
return isRecord(preset) && isString(preset.from) && preset.from.includes("@nuxtjs/turnstile") && isArray(preset.imports) && preset.imports.includes("verifyTurnstileToken");
|
|
28
|
+
}
|
|
25
29
|
const module$1 = defineNuxtModule({
|
|
26
30
|
meta: {
|
|
27
31
|
name: MODULE_NAME,
|
|
@@ -59,6 +63,13 @@ const module$1 = defineNuxtModule({
|
|
|
59
63
|
);
|
|
60
64
|
nuxt.options.turnstile = defu(nuxt.options.turnstile, {});
|
|
61
65
|
nuxt.options.turnstile.siteKey ??= options.siteKey;
|
|
66
|
+
nuxt.hook("nitro:config", (nitro) => {
|
|
67
|
+
const imports = nitro.imports;
|
|
68
|
+
if (!isRecord(imports) || !hasKey(imports, "presets")) return;
|
|
69
|
+
const presets = imports.presets;
|
|
70
|
+
if (!isArray(presets)) return;
|
|
71
|
+
imports.presets = presets.filter((preset) => !isUpstreamTurnstileVerifierPreset(preset));
|
|
72
|
+
});
|
|
62
73
|
transpileRuntime(nuxt, runtimeDir);
|
|
63
74
|
addImportsDir(resolver.resolve(runtimeDir, "app", "composables"));
|
|
64
75
|
addServerScanDir(resolver.resolve(runtimeDir, "server"));
|
package/package.json
CHANGED