@onderwijsin/nuxt-turnstile 0.2.1 → 0.2.3

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 CHANGED
@@ -22,13 +22,13 @@ export default defineNuxtConfig({
22
22
 
23
23
  The module's options are:
24
24
 
25
- | Option | Default | Purpose |
26
- | ----------------- | ----------------- | ------------------------------------------------- |
27
- | `enabled` | `true` | Enables or disables module setup |
28
- | `siteKey` | `""` | Public key used by the Turnstile widget |
29
- | `secretKey` | `""` | Server-only key used for verification |
30
- | `adminToken` | `""` | Optional trusted token that bypasses verification |
31
- | `adminHeaderName` | `"x-admin-token"` | Header accepted for `adminToken` |
25
+ | Option | Default | Purpose |
26
+ | ----------------- | ----------------- | ----------------------------------------------------- |
27
+ | `enabled` | `true` | Enables or disables module setup and its dependencies |
28
+ | `siteKey` | `""` | Public key used by the Turnstile widget |
29
+ | `secretKey` | `""` | Server-only key used for verification |
30
+ | `adminToken` | `""` | Optional trusted token that bypasses verification |
31
+ | `adminHeaderName` | `"x-admin-token"` | Header accepted for `adminToken` |
32
32
 
33
33
  `siteKey` is public and is also passed to `@nuxtjs/turnstile`. Keep `secretKey` and `adminToken`
34
34
  private. In production, prefer `NUXT_TURNSTILE_SECRET_KEY` for the private runtime value. The
package/dist/module.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@onderwijsin/nuxt-turnstile",
3
3
  "configKey": "turnstile",
4
- "version": "0.2.1",
4
+ "version": "0.2.3",
5
5
  "compatibility": {
6
6
  "nuxt": "^4.0.0"
7
7
  },
package/dist/module.mjs CHANGED
@@ -1,87 +1,9 @@
1
1
  import { defineNuxtModule, useLogger, createResolver, addTypeTemplate, addImportsDir, addServerScanDir } from '@nuxt/kit';
2
2
  import { defu } from 'defu';
3
+ import { enabled, resolveModuleName, resolveLoggerScope, moduleSetup, validateModuleOptions, transpileRuntime } from '@onderwijsin/nuxt-module-utils/shared';
3
4
  import { z } from 'zod';
4
5
 
5
- var NUMBER_CHAR_RE = /\d/;
6
- var STR_SPLITTERS = ["-", "_", "/", "."];
7
- function isUppercase(char = "") {
8
- if (NUMBER_CHAR_RE.test(char)) {
9
- return void 0;
10
- }
11
- return char !== char.toLowerCase();
12
- }
13
- function splitByCase(str, separators) {
14
- const splitters = STR_SPLITTERS;
15
- const parts = [];
16
- let buff = "";
17
- let previousUpper;
18
- let previousSplitter;
19
- for (const char of str) {
20
- const isSplitter = splitters.includes(char);
21
- if (isSplitter === true) {
22
- parts.push(buff);
23
- buff = "";
24
- previousUpper = void 0;
25
- continue;
26
- }
27
- const isUpper = isUppercase(char);
28
- if (previousSplitter === false) {
29
- if (previousUpper === false && isUpper === true) {
30
- parts.push(buff);
31
- buff = char;
32
- previousUpper = isUpper;
33
- continue;
34
- }
35
- if (previousUpper === true && isUpper === false && buff.length > 1) {
36
- const lastChar = buff.at(-1);
37
- parts.push(buff.slice(0, Math.max(0, buff.length - 1)));
38
- buff = lastChar + char;
39
- previousUpper = isUpper;
40
- continue;
41
- }
42
- }
43
- buff += char;
44
- previousUpper = isUpper;
45
- previousSplitter = isSplitter;
46
- }
47
- parts.push(buff);
48
- return parts;
49
- }
50
- function kebabCase(str, joiner) {
51
- return str ? (Array.isArray(str) ? str : splitByCase(str)).map((p) => p.toLowerCase()).join("-") : "";
52
- }
53
- var enabled = z.boolean().default(true);
54
- function resolveModuleName(moduleKey) {
55
- return `@onderwijsin/nuxt-${kebabCase(moduleKey)}`;
56
- }
57
- function resolveLoggerScope(moduleKey) {
58
- return kebabCase(moduleKey);
59
- }
60
- function transpileRuntime(nuxt, runtimeDir) {
61
- nuxt.options.build.transpile.push(runtimeDir);
62
- }
63
- function moduleSetup(MODULE_NAME, options, log) {
64
- const start = () => log.start(`Loading module ${MODULE_NAME}`);
65
- const end = () => log.success(`Module ${MODULE_NAME} Loaded`);
66
- const isEnabled = () => {
67
- if ("enabled" in options && options.enabled === false) {
68
- log.info(`Module ${MODULE_NAME} is disabled. Skipping setup...`);
69
- return false;
70
- }
71
- return true;
72
- };
73
- return { start, end, isEnabled };
74
- }
75
- function validateModuleOptions(options, schema, log) {
76
- const result = schema.safeParse(options);
77
- if (result.success) {
78
- return result.data;
79
- }
80
- log.info(z.prettifyError(result.error));
81
- throw new Error("Invalid module options \u261D. Exiting.");
82
- }
83
-
84
- const version = "0.2.1";
6
+ const version = "0.2.3";
85
7
 
86
8
  const turnstileOptionsSchema = z.object({
87
9
  enabled,
@@ -108,7 +30,7 @@ const module$1 = defineNuxtModule({
108
30
  compatibility: { nuxt: "^4.0.0" }
109
31
  },
110
32
  defaults: DEFAULTS,
111
- moduleDependencies: {
33
+ moduleDependencies: (nuxt) => nuxt.options.turnstile === false || nuxt.options.turnstile?.enabled === false ? {} : {
112
34
  "@nuxt/ui": { version: ">=4.0.0" },
113
35
  "@nuxtjs/turnstile": { version: ">=1.1.3" }
114
36
  },
@@ -1,8 +1,8 @@
1
1
  import { createError, getRequestHeader } from "h3";
2
2
  import { useRuntimeConfig } from "#imports";
3
3
  import { verifyTurnstileToken } from "@nuxtjs/turnstile/runtime/server/utils/verify.js";
4
- import { isAdmin } from "module-utils/server";
5
- import { attempt } from "module-utils/shared";
4
+ import { isAdmin } from "@onderwijsin/nuxt-module-utils/server";
5
+ import { attempt } from "@onderwijsin/nuxt-module-utils/shared";
6
6
  import { z } from "zod";
7
7
  import { TURNSTILE_TOKEN_HEADER } from "../../constants.js";
8
8
  const turnstileVerificationSchema = z.object({
package/package.json CHANGED
@@ -1,12 +1,16 @@
1
1
  {
2
2
  "name": "@onderwijsin/nuxt-turnstile",
3
- "version": "0.2.1",
3
+ "version": "0.2.3",
4
4
  "description": "Nuxt Turnstile integration with client helpers and server-side validation.",
5
5
  "homepage": "https://github.com/onderwijsin/nuxt-modules#readme",
6
6
  "bugs": {
7
7
  "url": "https://github.com/onderwijsin/nuxt-modules/issues"
8
8
  },
9
9
  "license": "MIT",
10
+ "author": {
11
+ "name": "Remi Huigen",
12
+ "email": "remihuigen@proton.me"
13
+ },
10
14
  "repository": {
11
15
  "type": "git",
12
16
  "url": "git+https://github.com/onderwijsin/nuxt-modules.git",
@@ -38,15 +42,15 @@
38
42
  "@nuxtjs/turnstile": "1.1.3",
39
43
  "defu": "6.1.7",
40
44
  "h3": "1.15.11",
41
- "zod": "4.4.3"
45
+ "zod": "4.4.3",
46
+ "@onderwijsin/nuxt-module-utils": "^0.1.0"
42
47
  },
43
48
  "devDependencies": {
44
49
  "@nuxt/module-builder": "1.0.3",
45
50
  "@nuxt/test-utils": "4.1.0",
46
51
  "nuxt": "4.5.2",
47
52
  "typescript": "5.9.3",
48
- "unbuild": "3.6.1",
49
- "module-utils": "0.0.0"
53
+ "unbuild": "3.6.1"
50
54
  },
51
55
  "engines": {
52
56
  "node": ">=22"