@onderwijsin/nuxt-turnstile 0.2.2 → 0.2.4

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/module.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@onderwijsin/nuxt-turnstile",
3
3
  "configKey": "turnstile",
4
- "version": "0.2.2",
4
+ "version": "0.2.4",
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, moduleDependenciesWhenEnabled } 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.2";
6
+ const version = "0.2.4";
85
7
 
86
8
  const turnstileOptionsSchema = z.object({
87
9
  enabled,
@@ -108,10 +30,10 @@ const module$1 = defineNuxtModule({
108
30
  compatibility: { nuxt: "^4.0.0" }
109
31
  },
110
32
  defaults: DEFAULTS,
111
- moduleDependencies: (nuxt) => nuxt.options.turnstile === false || nuxt.options.turnstile?.enabled === false ? {} : {
33
+ moduleDependencies: (nuxt) => moduleDependenciesWhenEnabled(nuxt.options.turnstile, {
112
34
  "@nuxt/ui": { version: ">=4.0.0" },
113
35
  "@nuxtjs/turnstile": { version: ">=1.1.3" }
114
- },
36
+ }),
115
37
  setup(rawOptions, nuxt) {
116
38
  const log = useLogger(resolveLoggerScope(MODULE_KEY));
117
39
  const { start, end, isEnabled } = moduleSetup(MODULE_NAME, rawOptions, log);
@@ -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/index.js";
5
- import { attempt } from "../../module-utils/shared/index.js";
4
+ import { isAdmin } from "@onderwijsin/nuxt-module-utils/server";
5
+ import { attempt, hasKey, isNumber, isRecord } 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({
@@ -78,7 +78,5 @@ export function createTurnstileErrorData(code, expectedAction) {
78
78
  return expectedAction ? { code, expectedAction } : { code };
79
79
  }
80
80
  export function isErrorWithStatusCode(error) {
81
- return Boolean(
82
- error && typeof error === "object" && "statusCode" in error && typeof error.statusCode === "number"
83
- );
81
+ return isRecord(error) && hasKey(error, "statusCode") && isNumber(error.statusCode);
84
82
  }
package/package.json CHANGED
@@ -1,12 +1,16 @@
1
1
  {
2
2
  "name": "@onderwijsin/nuxt-turnstile",
3
- "version": "0.2.2",
3
+ "version": "0.2.4",
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.2.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"
@@ -1,2 +0,0 @@
1
-
2
- export { }
@@ -1 +0,0 @@
1
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -1,130 +0,0 @@
1
- // src/shared/attempt.ts
2
- async function attempt(operation) {
3
- return Promise.resolve().then(operation).then(
4
- (data) => ({ data, error: null }),
5
- (error) => ({ data: null, error })
6
- );
7
- }
8
- async function attemptWithRetry(operation, { attempts = 3, delayMs = 250, exponentialBackoff = true } = {}) {
9
- let result = await attempt(operation);
10
- for (let attemptNumber = 1; result.error !== null && attemptNumber < attempts; attemptNumber += 1) {
11
- await new Promise((resolve) => {
12
- const delay = exponentialBackoff ? delayMs * 2 ** (attemptNumber - 1) : delayMs;
13
- setTimeout(resolve, delay);
14
- });
15
- result = await attempt(operation);
16
- }
17
- return result;
18
- }
19
-
20
- // src/shared/entries.ts
21
- function toEntries(value) {
22
- return Object.entries(value);
23
- }
24
- function fromEntries(entries) {
25
- return Object.fromEntries(entries);
26
- }
27
-
28
- // ../../node_modules/.pnpm/scule@1.3.0/node_modules/scule/dist/index.mjs
29
- var NUMBER_CHAR_RE = /\d/;
30
- var STR_SPLITTERS = ["-", "_", "/", "."];
31
- function isUppercase(char = "") {
32
- if (NUMBER_CHAR_RE.test(char)) {
33
- return void 0;
34
- }
35
- return char !== char.toLowerCase();
36
- }
37
- function splitByCase(str, separators) {
38
- const splitters = separators ?? STR_SPLITTERS;
39
- const parts = [];
40
- if (!str || typeof str !== "string") {
41
- return parts;
42
- }
43
- let buff = "";
44
- let previousUpper;
45
- let previousSplitter;
46
- for (const char of str) {
47
- const isSplitter = splitters.includes(char);
48
- if (isSplitter === true) {
49
- parts.push(buff);
50
- buff = "";
51
- previousUpper = void 0;
52
- continue;
53
- }
54
- const isUpper = isUppercase(char);
55
- if (previousSplitter === false) {
56
- if (previousUpper === false && isUpper === true) {
57
- parts.push(buff);
58
- buff = char;
59
- previousUpper = isUpper;
60
- continue;
61
- }
62
- if (previousUpper === true && isUpper === false && buff.length > 1) {
63
- const lastChar = buff.at(-1);
64
- parts.push(buff.slice(0, Math.max(0, buff.length - 1)));
65
- buff = lastChar + char;
66
- previousUpper = isUpper;
67
- continue;
68
- }
69
- }
70
- buff += char;
71
- previousUpper = isUpper;
72
- previousSplitter = isSplitter;
73
- }
74
- parts.push(buff);
75
- return parts;
76
- }
77
- function kebabCase(str, joiner) {
78
- return str ? (Array.isArray(str) ? str : splitByCase(str)).map((p) => p.toLowerCase()).join(joiner ?? "-") : "";
79
- }
80
-
81
- // src/shared/setup.ts
82
- import { z } from "zod";
83
- var enabled = z.boolean().default(true);
84
- function resolveModuleName(moduleKey) {
85
- return `@onderwijsin/nuxt-${kebabCase(moduleKey)}`;
86
- }
87
- function resolveLoggerScope(moduleKey) {
88
- return kebabCase(moduleKey);
89
- }
90
- function isPrepareMode(nuxt) {
91
- return !!nuxt?.options._prepare;
92
- }
93
- function transpileRuntime(nuxt, runtimeDir) {
94
- nuxt.options.build.transpile.push(runtimeDir);
95
- }
96
- function moduleSetup(MODULE_NAME, options, log) {
97
- const start = () => log.start(`Loading module ${MODULE_NAME}`);
98
- const end = () => log.success(`Module ${MODULE_NAME} Loaded`);
99
- const isEnabled = () => {
100
- if ("enabled" in options && options.enabled === false) {
101
- log.info(`Module ${MODULE_NAME} is disabled. Skipping setup...`);
102
- return false;
103
- }
104
- return true;
105
- };
106
- return { start, end, isEnabled };
107
- }
108
- function validateModuleOptions(options, schema, log) {
109
- const result = schema.safeParse(options);
110
- if (result.success) {
111
- return result.data;
112
- }
113
- log.info(z.prettifyError(result.error));
114
- throw new Error("Invalid module options \u261D. Exiting.");
115
- }
116
-
117
- export {
118
- attempt,
119
- attemptWithRetry,
120
- toEntries,
121
- fromEntries,
122
- enabled,
123
- resolveModuleName,
124
- resolveLoggerScope,
125
- isPrepareMode,
126
- transpileRuntime,
127
- moduleSetup,
128
- validateModuleOptions
129
- };
130
- //# sourceMappingURL=chunk-ZVWYKKRI.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/shared/attempt.ts","../src/shared/entries.ts","../../../node_modules/.pnpm/scule@1.3.0/node_modules/scule/dist/index.mjs","../src/shared/setup.ts"],"sourcesContent":["/** The result of an attempted operation whose failure is represented as data instead of a thrown error. */\nexport type AttemptResult<T> = { data: T; error: null } | { data: null; error: unknown };\n\n/**\n * Attempts an operation and exposes a possible failure as data.\n *\n * @param operation - The operation to execute.\n * @returns The operation result or the captured error.\n */\nexport async function attempt<T>(operation: () => T | Promise<T>): Promise<AttemptResult<T>> {\n return Promise.resolve()\n .then(operation)\n .then(\n (data) => ({ data, error: null }) as AttemptResult<T>,\n (error) => ({ data: null, error }) as AttemptResult<T>\n );\n}\n\n/** Options controlling bounded retries for attempted operations. */\nexport type AttemptRetryOptions = {\n /** Total number of times to execute the operation. */\n attempts?: number;\n /** Initial delay in milliseconds before retrying. */\n delayMs?: number;\n /** Whether to double the duration of each delay. @default true */\n exponentialBackoff?: boolean;\n};\n\n/**\n * Attempts an operation until it succeeds or exhausts a bounded exponential-backoff retry budget.\n *\n * @param operation Work that can be safely retried after a rejection.\n * @param options The total attempt count and initial delay between failed attempts.\n * @param options.attempts Total number of operation executions.\n * @param options.delayMs Initial delay before the first retry in milliseconds.\n * @param options.exponentialBackoff Whether each retry delay doubles.\n * @returns The successful result or the error from the final attempt.\n */\nexport async function attemptWithRetry<T>(\n operation: () => T | Promise<T>,\n { attempts = 3, delayMs = 250, exponentialBackoff = true }: AttemptRetryOptions = {}\n): Promise<AttemptResult<T>> {\n let result = await attempt(operation);\n\n for (\n let attemptNumber = 1;\n result.error !== null && attemptNumber < attempts;\n attemptNumber += 1\n ) {\n await new Promise<void>((resolve) => {\n const delay = exponentialBackoff ? delayMs * 2 ** (attemptNumber - 1) : delayMs;\n setTimeout(resolve, delay);\n });\n\n result = await attempt(operation);\n }\n\n return result;\n}\n","/**\n * Returns an object's own enumerable string-keyed entries with typed keys and values.\n * @param value - Object whose entries should be returned.\n * @returns Typed key/value pairs from the object.\n */\nexport function toEntries<T extends object>(value: T): [keyof T, T[keyof T]][] {\n return Object.entries(value) as [keyof T, T[keyof T]][];\n}\n\n/**\n * Creates an object from typed key/value entries.\n * @param entries - Key/value pairs to combine into an object.\n * @returns An object indexed by the entry keys and containing their values.\n */\nexport function fromEntries<K extends PropertyKey, V>(\n entries: Iterable<readonly [K, V]>\n): Record<K, V> {\n return Object.fromEntries(entries) as Record<K, V>;\n}\n","const NUMBER_CHAR_RE = /\\d/;\nconst STR_SPLITTERS = [\"-\", \"_\", \"/\", \".\"];\nfunction isUppercase(char = \"\") {\n if (NUMBER_CHAR_RE.test(char)) {\n return void 0;\n }\n return char !== char.toLowerCase();\n}\nfunction splitByCase(str, separators) {\n const splitters = separators ?? STR_SPLITTERS;\n const parts = [];\n if (!str || typeof str !== \"string\") {\n return parts;\n }\n let buff = \"\";\n let previousUpper;\n let previousSplitter;\n for (const char of str) {\n const isSplitter = splitters.includes(char);\n if (isSplitter === true) {\n parts.push(buff);\n buff = \"\";\n previousUpper = void 0;\n continue;\n }\n const isUpper = isUppercase(char);\n if (previousSplitter === false) {\n if (previousUpper === false && isUpper === true) {\n parts.push(buff);\n buff = char;\n previousUpper = isUpper;\n continue;\n }\n if (previousUpper === true && isUpper === false && buff.length > 1) {\n const lastChar = buff.at(-1);\n parts.push(buff.slice(0, Math.max(0, buff.length - 1)));\n buff = lastChar + char;\n previousUpper = isUpper;\n continue;\n }\n }\n buff += char;\n previousUpper = isUpper;\n previousSplitter = isSplitter;\n }\n parts.push(buff);\n return parts;\n}\nfunction upperFirst(str) {\n return str ? str[0].toUpperCase() + str.slice(1) : \"\";\n}\nfunction lowerFirst(str) {\n return str ? str[0].toLowerCase() + str.slice(1) : \"\";\n}\nfunction pascalCase(str, opts) {\n return str ? (Array.isArray(str) ? str : splitByCase(str)).map((p) => upperFirst(opts?.normalize ? p.toLowerCase() : p)).join(\"\") : \"\";\n}\nfunction camelCase(str, opts) {\n return lowerFirst(pascalCase(str || \"\", opts));\n}\nfunction kebabCase(str, joiner) {\n return str ? (Array.isArray(str) ? str : splitByCase(str)).map((p) => p.toLowerCase()).join(joiner ?? \"-\") : \"\";\n}\nfunction snakeCase(str) {\n return kebabCase(str || \"\", \"_\");\n}\nfunction flatCase(str) {\n return kebabCase(str || \"\", \"\");\n}\nfunction trainCase(str, opts) {\n return (Array.isArray(str) ? str : splitByCase(str)).filter(Boolean).map((p) => upperFirst(opts?.normalize ? p.toLowerCase() : p)).join(\"-\");\n}\nconst titleCaseExceptions = /^(a|an|and|as|at|but|by|for|if|in|is|nor|of|on|or|the|to|with)$/i;\nfunction titleCase(str, opts) {\n return (Array.isArray(str) ? str : splitByCase(str)).filter(Boolean).map(\n (p) => titleCaseExceptions.test(p) ? p.toLowerCase() : upperFirst(opts?.normalize ? p.toLowerCase() : p)\n ).join(\" \");\n}\n\nexport { camelCase, flatCase, isUppercase, kebabCase, lowerFirst, pascalCase, snakeCase, splitByCase, titleCase, trainCase, upperFirst };\n","import { kebabCase } from \"scule\";\nimport type { Nuxt } from \"@nuxt/schema\";\nimport type { ConsolaInstance } from \"consola\";\nimport { z } from \"zod\";\nimport type { ZodType } from \"zod\";\n\nexport interface BaseModuleOptions {\n /** Indicates if the module is enabled */\n enabled?: boolean;\n}\n\n/** Shared schema for the module enabled option. */\nexport const enabled = z.boolean().default(true);\n\n/**\n * Resolves a config key to a namespaced Nuxt module name.\n * @param moduleKey - The module config key.\n * @returns The namespaced module name.\n */\nexport function resolveModuleName(moduleKey: string): string {\n return `@onderwijsin/nuxt-${kebabCase(moduleKey)}`;\n}\n\n/**\n * Resolves a module key to a logger scope.\n * @param moduleKey - The module config key.\n * @returns The logger scope.\n */\nexport function resolveLoggerScope(moduleKey: string): string {\n return kebabCase(moduleKey);\n}\n\n/**\n * Returns whether Nuxt is preparing the project.\n * @param nuxt - The Nuxt context.\n * @returns Whether prepare mode is active.\n */\nexport function isPrepareMode(nuxt: Nuxt): boolean {\n return !!nuxt?.options._prepare;\n}\n\n/**\n * Adds a module's runtime directory to Nuxt's transpilation list.\n * @param nuxt - The Nuxt context being configured.\n * @param runtimeDir - Absolute path to the module runtime directory.\n */\nexport function transpileRuntime(nuxt: Nuxt, runtimeDir: string): void {\n nuxt.options.build.transpile.push(runtimeDir);\n}\n\n/**\n * Creates shared lifecycle helpers for a Nuxt module.\n * @param MODULE_NAME - The module name.\n * @param options - The module options.\n * @param log - The module logger.\n * @returns Module lifecycle helpers.\n */\nexport function moduleSetup<T extends BaseModuleOptions>(\n MODULE_NAME: string,\n options: T,\n log: ConsolaInstance\n) {\n const start = () => log.start(`Loading module ${MODULE_NAME}`);\n const end = () => log.success(`Module ${MODULE_NAME} Loaded`);\n const isEnabled = (): boolean => {\n if (\"enabled\" in options && options.enabled === false) {\n log.info(`Module ${MODULE_NAME} is disabled. Skipping setup...`);\n return false;\n }\n return true;\n };\n\n return { start, end, isEnabled };\n}\n\n/**\n * Validates module options against a Zod schema.\n * @param options - The module options.\n * @param schema - The complete module-specific Zod schema, including `enabled`.\n * @param log - The module logger.\n * @returns The validated options.\n * @throws When validation fails.\n */\nexport function validateModuleOptions<S extends ZodType>(\n options: unknown,\n schema: S,\n log: ConsolaInstance\n): z.output<S> {\n const result = schema.safeParse(options);\n\n if (result.success) {\n return result.data;\n }\n\n log.info(z.prettifyError(result.error));\n throw new Error(\"Invalid module options ☝. Exiting.\");\n}\n"],"mappings":";AASA,eAAsB,QAAW,WAA4D;AAC3F,SAAO,QAAQ,QAAQ,EACpB,KAAK,SAAS,EACd;AAAA,IACC,CAAC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AAA,EACT;AAEA,SAAO,EAAE,OAAO,KAAK,UAAU;AACjC;AAUO,SAAS,sBACd,SACA,QACA,KACa;AACb,QAAM,SAAS,OAAO,UAAU,OAAO;AAEvC,MAAI,OAAO,SAAS;AAClB,WAAO,OAAO;AAAA,EAChB;AAEA,MAAI,KAAK,EAAE,cAAc,OAAO,KAAK,CAAC;AACtC,QAAM,IAAI,MAAM,yCAAoC;AACtD;","names":[]}
@@ -1,5 +0,0 @@
1
- export { AttemptResult, AttemptRetryOptions, attempt, attemptWithRetry, fromEntries, toEntries } from './shared/index.js';
2
- export { B as BaseModuleOptions, e as enabled, i as isPrepareMode, m as moduleSetup, r as resolveLoggerScope, a as resolveModuleName, t as transpileRuntime, v as validateModuleOptions } from './types-DSdytTo1.js';
3
- import '@nuxt/schema';
4
- import 'consola';
5
- import 'zod';
@@ -1,27 +0,0 @@
1
- import {
2
- attempt,
3
- attemptWithRetry,
4
- enabled,
5
- fromEntries,
6
- isPrepareMode,
7
- moduleSetup,
8
- resolveLoggerScope,
9
- resolveModuleName,
10
- toEntries,
11
- transpileRuntime,
12
- validateModuleOptions
13
- } from "./chunk-ZVWYKKRI.js";
14
- export {
15
- attempt,
16
- attemptWithRetry,
17
- enabled,
18
- fromEntries,
19
- isPrepareMode,
20
- moduleSetup,
21
- resolveLoggerScope,
22
- resolveModuleName,
23
- toEntries,
24
- transpileRuntime,
25
- validateModuleOptions
26
- };
27
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -1,20 +0,0 @@
1
- import { H3Event } from 'h3';
2
-
3
- /**
4
- * Checks whether a request token matches a configured header or bearer token.
5
- * @param event - The H3 request event.
6
- * @param token - The expected token.
7
- * @param headerName - The custom token header name.
8
- * @returns Whether the token matches.
9
- */
10
- declare function hasMatchingRequestToken(event: H3Event, token: string | undefined, headerName: string): boolean;
11
- /**
12
- * Checks whether a request carries a valid administrator token.
13
- * @param event - The H3 request event.
14
- * @param token - The expected administrator token.
15
- * @param headerName - The custom token header name.
16
- * @returns Whether the token matches.
17
- */
18
- declare function isAdmin(event: H3Event, token: string | undefined, headerName: string): boolean;
19
-
20
- export { hasMatchingRequestToken, isAdmin };
@@ -1,22 +0,0 @@
1
- // src/server/token.ts
2
- import { getRequestHeader } from "h3";
3
- function hasMatchingRequestToken(event, token, headerName) {
4
- const normalizedToken = token?.trim();
5
- if (!normalizedToken) return false;
6
- const headerToken = getRequestHeader(event, headerName)?.trim();
7
- if (headerToken === normalizedToken) return true;
8
- const authorizationHeader = getRequestHeader(event, "authorization")?.trim();
9
- if (!authorizationHeader) return false;
10
- const [scheme, ...valueParts] = authorizationHeader.split(/\s+/);
11
- if (scheme?.toLowerCase() !== "bearer") return false;
12
- const bearerToken = valueParts.join(" ").trim();
13
- return bearerToken.length > 0 && bearerToken === normalizedToken;
14
- }
15
- function isAdmin(event, token, headerName) {
16
- return hasMatchingRequestToken(event, token, headerName);
17
- }
18
- export {
19
- hasMatchingRequestToken,
20
- isAdmin
21
- };
22
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/server/token.ts"],"sourcesContent":["import type { H3Event } from \"h3\";\nimport { getRequestHeader } from \"h3\";\n\n/**\n * Checks whether a request token matches a configured header or bearer token.\n * @param event - The H3 request event.\n * @param token - The expected token.\n * @param headerName - The custom token header name.\n * @returns Whether the token matches.\n */\nexport function hasMatchingRequestToken(\n event: H3Event,\n token: string | undefined,\n headerName: string\n): boolean {\n const normalizedToken = token?.trim();\n if (!normalizedToken) return false;\n\n const headerToken = getRequestHeader(event, headerName)?.trim();\n if (headerToken === normalizedToken) return true;\n\n const authorizationHeader = getRequestHeader(event, \"authorization\")?.trim();\n if (!authorizationHeader) return false;\n\n const [scheme, ...valueParts] = authorizationHeader.split(/\\s+/);\n if (scheme?.toLowerCase() !== \"bearer\") return false;\n\n const bearerToken = valueParts.join(\" \").trim();\n return bearerToken.length > 0 && bearerToken === normalizedToken;\n}\n\n/**\n * Checks whether a request carries a valid administrator token.\n * @param event - The H3 request event.\n * @param token - The expected administrator token.\n * @param headerName - The custom token header name.\n * @returns Whether the token matches.\n */\nexport function isAdmin(event: H3Event, token: string | undefined, headerName: string): boolean {\n return hasMatchingRequestToken(event, token, headerName);\n}\n"],"mappings":";AACA,SAAS,wBAAwB;AAS1B,SAAS,wBACd,OACA,OACA,YACS;AACT,QAAM,kBAAkB,OAAO,KAAK;AACpC,MAAI,CAAC,gBAAiB,QAAO;AAE7B,QAAM,cAAc,iBAAiB,OAAO,UAAU,GAAG,KAAK;AAC9D,MAAI,gBAAgB,gBAAiB,QAAO;AAE5C,QAAM,sBAAsB,iBAAiB,OAAO,eAAe,GAAG,KAAK;AAC3E,MAAI,CAAC,oBAAqB,QAAO;AAEjC,QAAM,CAAC,QAAQ,GAAG,UAAU,IAAI,oBAAoB,MAAM,KAAK;AAC/D,MAAI,QAAQ,YAAY,MAAM,SAAU,QAAO;AAE/C,QAAM,cAAc,WAAW,KAAK,GAAG,EAAE,KAAK;AAC9C,SAAO,YAAY,SAAS,KAAK,gBAAgB;AACnD;AASO,SAAS,QAAQ,OAAgB,OAA2B,YAA6B;AAC9F,SAAO,wBAAwB,OAAO,OAAO,UAAU;AACzD;","names":[]}
@@ -1,55 +0,0 @@
1
- export { B as BaseModuleOptions, e as enabled, i as isPrepareMode, m as moduleSetup, r as resolveLoggerScope, a as resolveModuleName, t as transpileRuntime, v as validateModuleOptions } from '../types-DSdytTo1.js';
2
- import '@nuxt/schema';
3
- import 'consola';
4
- import 'zod';
5
-
6
- /** The result of an attempted operation whose failure is represented as data instead of a thrown error. */
7
- type AttemptResult<T> = {
8
- data: T;
9
- error: null;
10
- } | {
11
- data: null;
12
- error: unknown;
13
- };
14
- /**
15
- * Attempts an operation and exposes a possible failure as data.
16
- *
17
- * @param operation - The operation to execute.
18
- * @returns The operation result or the captured error.
19
- */
20
- declare function attempt<T>(operation: () => T | Promise<T>): Promise<AttemptResult<T>>;
21
- /** Options controlling bounded retries for attempted operations. */
22
- type AttemptRetryOptions = {
23
- /** Total number of times to execute the operation. */
24
- attempts?: number;
25
- /** Initial delay in milliseconds before retrying. */
26
- delayMs?: number;
27
- /** Whether to double the duration of each delay. @default true */
28
- exponentialBackoff?: boolean;
29
- };
30
- /**
31
- * Attempts an operation until it succeeds or exhausts a bounded exponential-backoff retry budget.
32
- *
33
- * @param operation Work that can be safely retried after a rejection.
34
- * @param options The total attempt count and initial delay between failed attempts.
35
- * @param options.attempts Total number of operation executions.
36
- * @param options.delayMs Initial delay before the first retry in milliseconds.
37
- * @param options.exponentialBackoff Whether each retry delay doubles.
38
- * @returns The successful result or the error from the final attempt.
39
- */
40
- declare function attemptWithRetry<T>(operation: () => T | Promise<T>, { attempts, delayMs, exponentialBackoff }?: AttemptRetryOptions): Promise<AttemptResult<T>>;
41
-
42
- /**
43
- * Returns an object's own enumerable string-keyed entries with typed keys and values.
44
- * @param value - Object whose entries should be returned.
45
- * @returns Typed key/value pairs from the object.
46
- */
47
- declare function toEntries<T extends object>(value: T): [keyof T, T[keyof T]][];
48
- /**
49
- * Creates an object from typed key/value entries.
50
- * @param entries - Key/value pairs to combine into an object.
51
- * @returns An object indexed by the entry keys and containing their values.
52
- */
53
- declare function fromEntries<K extends PropertyKey, V>(entries: Iterable<readonly [K, V]>): Record<K, V>;
54
-
55
- export { type AttemptResult, type AttemptRetryOptions, attempt, attemptWithRetry, fromEntries, toEntries };
@@ -1,27 +0,0 @@
1
- import {
2
- attempt,
3
- attemptWithRetry,
4
- enabled,
5
- fromEntries,
6
- isPrepareMode,
7
- moduleSetup,
8
- resolveLoggerScope,
9
- resolveModuleName,
10
- toEntries,
11
- transpileRuntime,
12
- validateModuleOptions
13
- } from "../chunk-ZVWYKKRI.js";
14
- export {
15
- attempt,
16
- attemptWithRetry,
17
- enabled,
18
- fromEntries,
19
- isPrepareMode,
20
- moduleSetup,
21
- resolveLoggerScope,
22
- resolveModuleName,
23
- toEntries,
24
- transpileRuntime,
25
- validateModuleOptions
26
- };
27
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -1,57 +0,0 @@
1
- import { Nuxt } from '@nuxt/schema';
2
- import { ConsolaInstance } from 'consola';
3
- import { z, ZodType } from 'zod';
4
-
5
- interface BaseModuleOptions {
6
- /** Indicates if the module is enabled */
7
- enabled?: boolean;
8
- }
9
- /** Shared schema for the module enabled option. */
10
- declare const enabled: z.ZodDefault<z.ZodBoolean>;
11
- /**
12
- * Resolves a config key to a namespaced Nuxt module name.
13
- * @param moduleKey - The module config key.
14
- * @returns The namespaced module name.
15
- */
16
- declare function resolveModuleName(moduleKey: string): string;
17
- /**
18
- * Resolves a module key to a logger scope.
19
- * @param moduleKey - The module config key.
20
- * @returns The logger scope.
21
- */
22
- declare function resolveLoggerScope(moduleKey: string): string;
23
- /**
24
- * Returns whether Nuxt is preparing the project.
25
- * @param nuxt - The Nuxt context.
26
- * @returns Whether prepare mode is active.
27
- */
28
- declare function isPrepareMode(nuxt: Nuxt): boolean;
29
- /**
30
- * Adds a module's runtime directory to Nuxt's transpilation list.
31
- * @param nuxt - The Nuxt context being configured.
32
- * @param runtimeDir - Absolute path to the module runtime directory.
33
- */
34
- declare function transpileRuntime(nuxt: Nuxt, runtimeDir: string): void;
35
- /**
36
- * Creates shared lifecycle helpers for a Nuxt module.
37
- * @param MODULE_NAME - The module name.
38
- * @param options - The module options.
39
- * @param log - The module logger.
40
- * @returns Module lifecycle helpers.
41
- */
42
- declare function moduleSetup<T extends BaseModuleOptions>(MODULE_NAME: string, options: T, log: ConsolaInstance): {
43
- start: () => void;
44
- end: () => void;
45
- isEnabled: () => boolean;
46
- };
47
- /**
48
- * Validates module options against a Zod schema.
49
- * @param options - The module options.
50
- * @param schema - The complete module-specific Zod schema, including `enabled`.
51
- * @param log - The module logger.
52
- * @returns The validated options.
53
- * @throws When validation fails.
54
- */
55
- declare function validateModuleOptions<S extends ZodType>(options: unknown, schema: S, log: ConsolaInstance): z.output<S>;
56
-
57
- export { type BaseModuleOptions as B, resolveModuleName as a, enabled as e, isPrepareMode as i, moduleSetup as m, resolveLoggerScope as r, transpileRuntime as t, validateModuleOptions as v };
@@ -1,4 +0,0 @@
1
- export { B as BaseModuleOptions } from './types-DSdytTo1.js';
2
- import '@nuxt/schema';
3
- import 'consola';
4
- import 'zod';
@@ -1 +0,0 @@
1
- //# sourceMappingURL=types.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}