@sourceregistry/sveltekit-enhance 1.8.0 → 2.0.0

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
@@ -7,7 +7,7 @@
7
7
  [![npm version](https://img.shields.io/npm/v/@sourceregistry/sveltekit-enhance?style=flat-square&color=f96743)](https://www.npmjs.com/package/@sourceregistry/sveltekit-enhance)
8
8
  [![npm downloads](https://img.shields.io/npm/dm/@sourceregistry/sveltekit-enhance?style=flat-square)](https://www.npmjs.com/package/@sourceregistry/sveltekit-enhance)
9
9
  [![license](https://img.shields.io/npm/l/@sourceregistry/sveltekit-enhance?style=flat-square)](./LICENSE)
10
- [![SvelteKit](https://img.shields.io/badge/SvelteKit-%5E2.58-FF3E00?style=flat-square&logo=svelte&logoColor=white)](https://kit.svelte.dev)
10
+ [![SvelteKit](https://img.shields.io/badge/SvelteKit-3-FF3E00?style=flat-square&logo=svelte&logoColor=white)](https://svelte.dev/docs/kit)
11
11
  [![issues](https://img.shields.io/github/issues/SourceRegistry/sveltekit-enhance?style=flat-square)](https://github.com/SourceRegistry/sveltekit-enhance/issues)
12
12
 
13
13
  Wrap actions, loads, methods, and hooks with composable enhancers. Stack auth guards, feature flags, request tracing, and form parsing without touching SvelteKit's internals.
@@ -24,14 +24,14 @@ Wrap actions, loads, methods, and hooks with composable enhancers. Stack auth gu
24
24
  npm install @sourceregistry/sveltekit-enhance
25
25
  ```
26
26
 
27
- **Peer dependency:** `@sveltejs/kit ^2.58.0`
27
+ **Peer dependency:** `@sveltejs/kit ^3.0.1`
28
28
 
29
29
  ---
30
30
 
31
31
  ## Overview
32
32
 
33
33
  ```ts
34
- import { enhance, Auth, RequestCorrelation, RequestMonitor, Form } from '@sourceregistry/sveltekit-enhance';
34
+ import { enhance, Auth, FeatureFlag, RequestCorrelation, RequestMonitor, Form, success } from '@sourceregistry/sveltekit-enhance';
35
35
 
36
36
  // hooks.server.ts
37
37
  export const handle = enhance.handle(
@@ -242,7 +242,8 @@ export const handle = enhance.handle(myHandler, Devtools.ignore);
242
242
 
243
243
  ### `FeatureFlag`
244
244
 
245
- Guards routes behind SvelteKit public env vars (`$env/dynamic/public`). Always passes in `dev` mode.
245
+ Guards routes behind SvelteKit public env vars (`$app/env/public`). Declare each flag
246
+ with `public: true` in your app's `src/env.ts`. Always passes in `dev` mode.
246
247
 
247
248
  ```ts
248
249
  import { FeatureFlag } from '@sourceregistry/sveltekit-enhance';
@@ -1,4 +1,4 @@
1
- import { dev } from '$app/environment';
1
+ import { dev } from '$app/env';
2
2
  export const Devtools = {
3
3
  ignore: (input) => {
4
4
  if (input.url.pathname === '/.well-known/appspecific/com.chrome.devtools.json') {
@@ -1,10 +1,31 @@
1
- import { env } from '$env/dynamic/public';
2
1
  import { type EnhanceInput } from "../index.js";
2
+ export declare const FeatureFlagChecker: {
3
+ enabled: (value: string) => boolean;
4
+ disabled: (value: string) => boolean;
5
+ };
6
+ export declare const enabled: (value: string) => boolean;
7
+ export declare const disabled: (value: string) => boolean;
3
8
  export declare const FeatureFlag: {
4
- all: (...flags: (keyof typeof env)[]) => (input: EnhanceInput) => {
5
- flags: (string | number | symbol)[];
9
+ all: (...flags: string[]) => (input: EnhanceInput) => {
10
+ flags: string[];
6
11
  };
7
- oneOf: (...flags: (keyof typeof env)[]) => (input: EnhanceInput) => {
8
- flags: (string | number | symbol)[];
12
+ oneOf: (...flags: string[]) => (input: EnhanceInput) => {
13
+ flags: string[];
9
14
  };
15
+ /**
16
+ * @experimental
17
+ * @param flag
18
+ */
19
+ isEnabled: (flag: string) => boolean;
20
+ /**
21
+ * @experimental
22
+ * @param flag
23
+ */
24
+ isDisabled: (flag: string) => boolean;
25
+ /**
26
+ * @experimental
27
+ * @param flag
28
+ * @param predicate
29
+ */
30
+ is: (flag: string, predicate?: (value: string) => boolean) => boolean;
10
31
  };
@@ -1,12 +1,19 @@
1
- import { env } from '$env/dynamic/public';
2
- import { dev } from '$app/environment';
1
+ import * as publicEnv from '$app/env/public';
2
+ import { dev } from '$app/env';
3
3
  import { not_good } from "../index.js";
4
- const enabled = ['true', 'TRUE', 'on', 'ON', '1'];
4
+ const _enabled = ['true', 'TRUE', 'on', 'ON', '1'];
5
+ const env = publicEnv;
6
+ export const FeatureFlagChecker = {
7
+ enabled: (value) => _enabled.includes(value),
8
+ disabled: (value) => !_enabled.includes(value)
9
+ };
10
+ export const enabled = FeatureFlagChecker.enabled;
11
+ export const disabled = FeatureFlagChecker.disabled;
5
12
  export const FeatureFlag = {
6
13
  all: (...flags) => {
7
14
  return (input) => {
8
15
  // Which of the requested flags are *not* enabled
9
- const disabledFlags = flags.filter((flag) => !enabled.includes((env[flag] ?? '').toUpperCase()));
16
+ const disabledFlags = flags.filter((flag) => !_enabled.includes((env[flag] ?? '').toUpperCase()));
10
17
  if (!(disabledFlags.length === 0 || dev))
11
18
  not_good(input, 503, {
12
19
  message: 'Feature not enabled'
@@ -17,12 +24,28 @@ export const FeatureFlag = {
17
24
  oneOf: (...flags) => {
18
25
  return (input) => {
19
26
  // True if at least one of the given flags is enabled
20
- const anyEnabled = flags.some((flag) => enabled.includes((env[flag] ?? '').toUpperCase()));
27
+ const anyEnabled = flags.some((flag) => _enabled.includes((env[flag] ?? '').toUpperCase()));
21
28
  if (!(anyEnabled || dev))
22
29
  not_good(input, 503, {
23
30
  message: 'Feature not enabled'
24
31
  });
25
32
  return { flags };
26
33
  };
27
- }
34
+ },
35
+ /**
36
+ * @experimental
37
+ * @param flag
38
+ */
39
+ isEnabled: (flag) => FeatureFlag.is(flag),
40
+ /**
41
+ * @experimental
42
+ * @param flag
43
+ */
44
+ isDisabled: (flag) => FeatureFlag.is(flag, disabled),
45
+ /**
46
+ * @experimental
47
+ * @param flag
48
+ * @param predicate
49
+ */
50
+ is: (flag, predicate = enabled) => dev || predicate((env[flag] ?? '').toUpperCase())
28
51
  };
@@ -2,7 +2,7 @@ export * from './auth.js';
2
2
  export * from './cache.js';
3
3
  export * from './devtools.js';
4
4
  export * from './featureflag.js';
5
- export * from './form.ts';
5
+ export * from './form.js';
6
6
  export * from './request-correlation.js';
7
7
  export * from './request-monitor.js';
8
8
  export * from './request-rate-limit.js';
@@ -2,7 +2,7 @@ export * from './auth.js';
2
2
  export * from './cache.js';
3
3
  export * from './devtools.js';
4
4
  export * from './featureflag.js';
5
- export * from "./form.js";
5
+ export * from './form.js';
6
6
  export * from './request-correlation.js';
7
7
  export * from './request-monitor.js';
8
8
  export * from './request-rate-limit.js';
@@ -1,5 +1,5 @@
1
1
  import { Deferred } from "./internal/Deferred.js";
2
- import { dev } from '$app/environment';
2
+ import { dev } from '$app/env';
3
3
  export const StartUp = {
4
4
  await: (waitOn, config = {}) => {
5
5
  const { showPage = "/startup", showJSON = { error: 'service_starting', message: 'Application is initializing' }, allowedPaths = [], onFailure = (reason) => {
package/dist/index.d.ts CHANGED
@@ -1,4 +1,6 @@
1
- import { type Action, type ActionResult, type Cookies, redirect as SRedirect, type Handle, type RequestEvent, type ResolveOptions, type ServerLoadEvent } from '@sveltejs/kit';
1
+ import { type Action, type Cookies, redirect as SRedirect, type RequestEvent, type ServerLoadEvent } from '@sveltejs/kit';
2
+ import type { ActionResult } from '$app/forms';
3
+ import type { Handle, ResolveOptions } from '@sveltejs/kit/hooks';
2
4
  import type { RouteId as AppRouteId, LayoutParams as AppLayoutParams } from '$app/types';
3
5
  export type MaybePromise<T> = T | Promise<T>;
4
6
  export type EnhanceErrorHandler = <T = any>(err: unknown) => MaybePromise<T | Response | undefined | never | void>;
@@ -81,18 +83,18 @@ export declare const load: <Params extends AppLayoutParams<"/"> = AppLayoutParam
81
83
  export declare const method: <Params extends AppLayoutParams<"/"> = AppLayoutParams<"/">, RouteId extends AppRouteId | string | null = AppRouteId | string | null, const Enhances extends readonly EnhanceFunction<"method", Params, RouteId, object>[] = readonly EnhanceFunction<"method", Params, RouteId, object>[], EnhanceReturn extends Awaited<ConcatReturnTypes<Enhances>> = Awaited<ConcatReturnTypes<Enhances>>>(handle: EnhanceMethod<Params, RouteId, EnhanceReturn>, ...contexts: [...Enhances]) => (event: RequestEvent<Params, RouteId>) => Promise<Response>;
82
84
  export declare const handle: <const Enhances extends readonly EnhanceFunction<"handle">[] = readonly EnhanceFunction<"handle">[], EnhanceReturn extends Awaited<ConcatReturnTypes<Enhances>> = Awaited<ConcatReturnTypes<Enhances>>>(handle: EnhanceHandle<EnhanceReturn>, ...contexts: [...Enhances]) => Handle;
83
85
  export declare const enhance: {
84
- action: <Params extends AppLayoutParams<"/"> = Record<string, string>, OutputData extends Record<string, any> | void = void | Record<string, any>, RouteId extends AppRouteId | string | null = string | null, const Enhances extends readonly EnhanceFunction<"action", Params, RouteId, object>[] = readonly EnhanceFunction<"action", Params, RouteId, object>[], EnhanceReturn extends ConcatReturnTypes<Enhances> = ConcatReturnTypes<Enhances>>(action: EnhanceAction<Params, OutputData, RouteId, EnhanceReturn>, ...enhances: Enhances) => Action<Params, OutputData, RouteId>;
85
- load: <Params extends AppLayoutParams<"/"> = Record<string, string>, ParentData extends Record<string, any> = Record<string, any>, OutputData extends Record<string, any> | void = void | Record<string, any>, RouteId extends AppRouteId | null = string | null, const Enhances extends readonly EnhanceFunction<"load", Params, RouteId, object>[] = readonly EnhanceFunction<"load", Params, RouteId, object>[], EnhanceReturn extends ConcatReturnTypes<Enhances> = ConcatReturnTypes<Enhances>>(load: EnhanceLoad<Params, ParentData, OutputData, RouteId, EnhanceReturn>, ...contexts: Enhances) => (event: ServerLoadEvent<Params, ParentData, RouteId>) => Promise<OutputData>;
86
- method: <Params extends AppLayoutParams<"/"> = Record<string, string>, RouteId extends AppRouteId | string | null = string | null, const Enhances extends readonly EnhanceFunction<"method", Params, RouteId, object>[] = readonly EnhanceFunction<"method", Params, RouteId, object>[], EnhanceReturn extends Awaited<ConcatReturnTypes<Enhances>> = Awaited<ConcatReturnTypes<Enhances>>>(handle: EnhanceMethod<Params, RouteId, EnhanceReturn>, ...contexts: Enhances) => (event: RequestEvent<Params, RouteId>) => Promise<Response>;
87
- handle: <const Enhances extends readonly EnhanceFunction<"handle">[] = readonly EnhanceFunction<"handle", Record<string, string>, string | null, any>[], EnhanceReturn extends Awaited<ConcatReturnTypes<Enhances>> = Awaited<ConcatReturnTypes<Enhances>>>(handle: EnhanceHandle<EnhanceReturn>, ...contexts: Enhances) => Handle;
86
+ action: <Params extends AppLayoutParams<"/"> = Record<string, never>, OutputData extends Record<string, any> | void = void | Record<string, any>, RouteId extends AppRouteId | string | null = string | null, const Enhances extends readonly EnhanceFunction<"action", Params, RouteId, object>[] = readonly EnhanceFunction<"action", Params, RouteId, object>[], EnhanceReturn extends ConcatReturnTypes<Enhances> = ConcatReturnTypes<Enhances>>(action: EnhanceAction<Params, OutputData, RouteId, EnhanceReturn>, ...enhances: Enhances) => Action<Params, OutputData, RouteId>;
87
+ load: <Params extends AppLayoutParams<"/"> = Record<string, never>, ParentData extends Record<string, any> = Record<string, any>, OutputData extends Record<string, any> | void = void | Record<string, any>, RouteId extends AppRouteId | null = "/" | null, const Enhances extends readonly EnhanceFunction<"load", Params, RouteId, object>[] = readonly EnhanceFunction<"load", Params, RouteId, object>[], EnhanceReturn extends ConcatReturnTypes<Enhances> = ConcatReturnTypes<Enhances>>(load: EnhanceLoad<Params, ParentData, OutputData, RouteId, EnhanceReturn>, ...contexts: Enhances) => (event: ServerLoadEvent<Params, ParentData, RouteId>) => Promise<OutputData>;
88
+ method: <Params extends AppLayoutParams<"/"> = Record<string, never>, RouteId extends AppRouteId | string | null = string | null, const Enhances extends readonly EnhanceFunction<"method", Params, RouteId, object>[] = readonly EnhanceFunction<"method", Params, RouteId, object>[], EnhanceReturn extends Awaited<ConcatReturnTypes<Enhances>> = Awaited<ConcatReturnTypes<Enhances>>>(handle: EnhanceMethod<Params, RouteId, EnhanceReturn>, ...contexts: Enhances) => (event: RequestEvent<Params, RouteId>) => Promise<Response>;
89
+ handle: <const Enhances extends readonly EnhanceFunction<"handle">[] = readonly EnhanceFunction<"handle", Record<string, never>, string | null, any>[], EnhanceReturn extends Awaited<ConcatReturnTypes<Enhances>> = Awaited<ConcatReturnTypes<Enhances>>>(handle: EnhanceHandle<EnhanceReturn>, ...contexts: Enhances) => Handle;
88
90
  };
89
91
  export type Enhancers<Params extends AppLayoutParams<'/'> = AppLayoutParams<'/'>, RouteId extends AppRouteId | null = AppRouteId | null, EnhanceReturn extends never | any = any> = Record<string, EnhanceFunction<EnhanceCallType, Params, RouteId, EnhanceReturn>>;
90
92
  export type Func = (...args: any[]) => any;
91
93
  export type ConcatReturnTypes<T extends readonly Func[]> = T extends readonly [] ? Record<never, never> : T extends readonly [infer First, ...infer Rest] ? First extends Func ? Awaited<ReturnType<First>> & ConcatReturnTypes<Rest extends readonly Func[] ? Rest : []> : Record<never, never> : Record<never, never>;
92
94
  export declare const fail: <T extends Record<string, unknown> | undefined = undefined>(status: number, data: T) => never;
93
- export declare const error: (status: number, body?: {
94
- message: string;
95
- } extends App.Error ? App.Error | string | undefined : never) => never;
95
+ export declare const error: (status: number, body?: string | (Omit<App.Error, "status"> & {
96
+ status?: number;
97
+ })) => never;
96
98
  export declare const success: <T extends Record<string, unknown> | undefined = undefined>(data: T) => T;
97
99
  export declare const redirect: typeof SRedirect;
98
100
  export declare function not_good(input: {
package/dist/index.js CHANGED
@@ -231,7 +231,13 @@ export const enhance = {
231
231
  export const fail = (status, data) => {
232
232
  throw SFail(status, data);
233
233
  };
234
- export const error = (status, body) => SError(status, body);
234
+ export const error = (status, body) => {
235
+ if (typeof body !== 'object' || body === undefined) {
236
+ return SError(status, body);
237
+ }
238
+ const { message, status: _status, ...properties } = body;
239
+ return SError(status, message, properties);
240
+ };
235
241
  export const success = (data) => data;
236
242
  export const redirect = SRedirect;
237
243
  export function not_good(input, status, arg) {
package/package.json CHANGED
@@ -1,8 +1,11 @@
1
1
  {
2
2
  "name": "@sourceregistry/sveltekit-enhance",
3
- "version": "1.8.0",
3
+ "version": "2.0.0",
4
4
  "description": "Composable enhance and form utilities for SvelteKit actions, loads, methods, and hooks.",
5
5
  "author": "A.P.A. Slaa (a.p.a.slaa@projectsource.nl)",
6
+ "engines": {
7
+ "node": ">=22.17"
8
+ },
6
9
  "scripts": {
7
10
  "dev": "vite dev",
8
11
  "build": "vite build && npm run prepack",
@@ -23,9 +26,13 @@
23
26
  "sideEffects": [
24
27
  "**/*.css"
25
28
  ],
26
- "svelte": "./dist/client/index.js",
29
+ "svelte": "./dist/index.js",
27
30
  "types": "./dist/index.d.ts",
28
31
  "type": "module",
32
+ "imports": {
33
+ "#lib": "./src/lib/index.js",
34
+ "#lib/*": "./src/lib/*"
35
+ },
29
36
  "exports": {
30
37
  ".": {
31
38
  "types": "./dist/index.d.ts",
@@ -45,27 +52,27 @@
45
52
  "access": "public"
46
53
  },
47
54
  "peerDependencies": {
48
- "@sveltejs/kit": "^2.58.0"
55
+ "@sveltejs/kit": "^3.0.1"
49
56
  },
50
57
  "devDependencies": {
51
- "@semantic-release/changelog": "^6.0.3",
58
+ "@semantic-release/changelog": "^7.0.0",
52
59
  "@semantic-release/commit-analyzer": "^13.0.1",
53
- "@semantic-release/git": "^10.0.1",
54
- "@semantic-release/npm": "^13.1.5",
60
+ "@semantic-release/git": "^11.0.1",
61
+ "@semantic-release/npm": "^13.2.0",
55
62
  "@semantic-release/release-notes-generator": "^14.1.1",
56
- "@sveltejs/adapter-auto": "^7.0.1",
57
- "@sveltejs/kit": "^2.58.0",
58
- "@sveltejs/package": "^2.5.8",
59
- "@sveltejs/vite-plugin-svelte": "^7.0.0",
60
- "@types/node": "^26.1.2",
61
- "@vitest/coverage-v8": "^4.1.10",
62
- "publint": "^0.3.23",
63
- "svelte": "^5.56.8",
64
- "svelte-check": "^4.7.5",
63
+ "@sveltejs/adapter-auto": "^8.0.0",
64
+ "@sveltejs/kit": "^3.0.1",
65
+ "@sveltejs/package": "^3.0.0",
66
+ "@sveltejs/vite-plugin-svelte": "^7.3.1",
67
+ "@types/node": "^26.6.4",
68
+ "@vitest/coverage-v8": "^5.0.3",
69
+ "publint": "^0.3.25",
70
+ "svelte": "^5.57.2",
71
+ "svelte-check": "^4.7.6",
65
72
  "typedoc": "^0.28.20",
66
- "typescript": "^6.0.3",
67
- "vite": "^8.0.10",
68
- "vitest": "^4.1.5"
73
+ "typescript": "~6.0.3",
74
+ "vite": "^8.3.4",
75
+ "vitest": "^5.0.3"
69
76
  },
70
77
  "license": "Apache-2.0",
71
78
  "bugs": {