@nosecone/sveltekit 1.0.0-beta.9 → 1.1.0-rc

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.
Files changed (4) hide show
  1. package/README.md +45 -26
  2. package/index.d.ts +37 -8
  3. package/index.js +19 -6
  4. package/package.json +16 -16
package/README.md CHANGED
@@ -21,40 +21,56 @@ Protect your SvelteKit application with secure headers.
21
21
  - [npm package (`@nosecone/sveltekit`)](https://www.npmjs.com/package/@nosecone/sveltekit)
22
22
  - [GitHub source code (`nosecone-sveltekit/` in `arcjet/arcjet-js`)](https://github.com/arcjet/arcjet-js/tree/main/nosecone-sveltekit)
23
23
 
24
- ## Installation
24
+ ## What is this?
25
25
 
26
- ```shell
27
- npm install -S @nosecone/sveltekit
26
+ This is our adapter to integrate Nosecone into SvelteKit.
27
+ Nosecone makes it easy to add and configure security headers.
28
+ This package exists so that we can provide the best possible experience to
29
+ SvelteKit users.
30
+
31
+ ## When should I use this?
32
+
33
+ You can use this package with or without Arcjet to protect your app if you are
34
+ using SvelteKit.
35
+ Use [`@nosecone/next`][github-nosecone-next] if you use Next.js and
36
+ use [`nosecone`][github-nosecone] itself if you use a different framework.
37
+
38
+ ## Install
39
+
40
+ This package is ESM only.
41
+ Install with npm in Node.js:
42
+
43
+ ```sh
44
+ npm install @nosecone/sveltekit
28
45
  ```
29
46
 
30
47
  ## Example
31
48
 
32
- Update your `svelte.config.js` file for `csp`:
49
+ Configure `csp` from Nosecone in `svelte.config.js`:
33
50
 
34
51
  ```diff
35
- import adapter from "@sveltejs/adapter-auto";
36
- import { vitePreprocess } from "@sveltejs/vite-plugin-svelte";
37
- + import { csp } from "@nosecone/sveltekit"
38
-
39
- /** @type {import('@sveltejs/kit').Config} */
40
- const config = {
41
- // Consult https://kit.svelte.dev/docs/integrations#preprocessors
42
- // for more information about preprocessors
43
- preprocess: vitePreprocess(),
44
-
45
- kit: {
46
- + csp: csp(),
47
- // adapter-auto only supports some environments, see https://kit.svelte.dev/docs/adapter-auto for a list.
48
- // If your environment is not supported, or you settled on a specific environment, switch out the adapter.
49
- // See https://kit.svelte.dev/docs/adapters for more information about adapters.
50
- adapter: adapter(),
51
- },
52
- };
53
-
54
- export default config;
52
+ +import { csp } from "@nosecone/sveltekit"
53
+ import adapter from "@sveltejs/adapter-auto";
54
+ import { vitePreprocess } from "@sveltejs/vite-plugin-svelte";
55
+
56
+ /** @type {import('@sveltejs/kit').Config} */
57
+ const config = {
58
+ kit: {
59
+ // adapter-auto only supports some environments, see https://kit.svelte.dev/docs/adapter-auto for a list.
60
+ // If your environment is not supported, or you settled on a specific environment, switch out the adapter.
61
+ // See https://kit.svelte.dev/docs/adapters for more information about adapters.
62
+ adapter: adapter(),
63
+ + csp: csp(),
64
+ },
65
+ // Consult https://kit.svelte.dev/docs/integrations#preprocessors
66
+ // for more information about preprocessors
67
+ preprocess: vitePreprocess(),
68
+ };
69
+
70
+ export default config;
55
71
  ```
56
72
 
57
- Create a `src/hooks.server.ts` file with the contents:
73
+ …then use `createHook` from Nosecone in a `src/hooks.server.ts` file:
58
74
 
59
75
  ```ts
60
76
  import { createHook } from "@nosecone/sveltekit";
@@ -68,6 +84,9 @@ export const handle = sequence(
68
84
 
69
85
  ## License
70
86
 
71
- Licensed under the [Apache License, Version 2.0][apache-license].
87
+ [Apache License, Version 2.0][apache-license] © [Arcjet Labs, Inc.][arcjet]
72
88
 
73
89
  [apache-license]: http://www.apache.org/licenses/LICENSE-2.0
90
+ [arcjet]: https://arcjet.com
91
+ [github-nosecone-next]: https://github.com/arcjet/arcjet-js/tree/main/nosecone-next
92
+ [github-nosecone]: https://github.com/arcjet/arcjet-js/tree/main/nosecone
package/index.d.ts CHANGED
@@ -1,7 +1,10 @@
1
1
  import nosecone from "nosecone";
2
- import type { CspDirectives, NoseconeOptions } from "nosecone";
2
+ import type { CspDirectives, Options } from "nosecone";
3
3
  import type { Handle, KitConfig } from "@sveltejs/kit";
4
- export { withVercelToolbar, type NoseconeOptions } from "nosecone";
4
+ export { withVercelToolbar, type Options, type NoseconeOptions, } from "nosecone";
5
+ /**
6
+ * Nosecone SvelteKit defaults.
7
+ */
5
8
  export declare const defaults: {
6
9
  readonly directives: {
7
10
  readonly scriptSrc: readonly ["'strict-dynamic'"];
@@ -70,17 +73,43 @@ export declare const defaults: {
70
73
  };
71
74
  readonly xXssProtection: true;
72
75
  };
76
+ export { nosecone };
77
+ /**
78
+ * Create security headers.
79
+ *
80
+ * @deprecated
81
+ * Use the named export `nosecone` instead.
82
+ */
73
83
  export default nosecone;
74
84
  /**
75
85
  * Create a SvelteKit hook that sets secure headers on every request.
76
86
  *
77
- * @param options: Configuration to provide to Nosecone
78
- * @returns A SvelteKit hook that sets secure headers
87
+ * @param options
88
+ * Configuration to provide to Nosecone.
89
+ * @returns
90
+ * SvelteKit hook that sets secure headers.
79
91
  */
80
- export declare function createHook(options?: NoseconeOptions): Handle;
92
+ export declare function createHook(options?: Options): Handle;
81
93
  type SvelteKitCsp = Exclude<KitConfig["csp"], undefined>;
94
+ /**
95
+ * Content Security Policy configuration for SvelteKit.
96
+ */
82
97
  export type ContentSecurityPolicyConfig = {
83
- mode?: SvelteKitCsp["mode"];
84
- directives?: CspDirectives;
98
+ /**
99
+ * Mode of the `Content-Security-Policy` header.
100
+ */
101
+ mode?: SvelteKitCsp["mode"] | undefined;
102
+ /**
103
+ * Directives to use in the `Content-Security-Policy` header.
104
+ */
105
+ directives?: CspDirectives | undefined;
85
106
  };
86
- export declare function csp(options?: ContentSecurityPolicyConfig): SvelteKitCsp;
107
+ /**
108
+ * Create a SvelteKit Content Security Policy configuration.
109
+ *
110
+ * @param options
111
+ * Configuration.
112
+ * @returns
113
+ * SvelteKit Content Security Policy configuration.
114
+ */
115
+ export declare function csp(options?: ContentSecurityPolicyConfig | undefined): SvelteKitCsp;
package/index.js CHANGED
@@ -1,6 +1,9 @@
1
1
  import nosecone, { defaults as defaults$1, CONTENT_SECURITY_POLICY_DIRECTIVES, NoseconeValidationError, QUOTED } from 'nosecone';
2
- export { default, withVercelToolbar } from 'nosecone';
2
+ export { default, default as nosecone, withVercelToolbar } from 'nosecone';
3
3
 
4
+ /**
5
+ * Nosecone SvelteKit defaults.
6
+ */
4
7
  const defaults = {
5
8
  ...defaults$1,
6
9
  directives: {
@@ -11,8 +14,10 @@ const defaults = {
11
14
  /**
12
15
  * Create a SvelteKit hook that sets secure headers on every request.
13
16
  *
14
- * @param options: Configuration to provide to Nosecone
15
- * @returns A SvelteKit hook that sets secure headers
17
+ * @param options
18
+ * Configuration to provide to Nosecone.
19
+ * @returns
20
+ * SvelteKit hook that sets secure headers.
16
21
  */
17
22
  function createHook(options = defaults) {
18
23
  return async ({ event, resolve }) => {
@@ -73,10 +78,18 @@ function directivesToSvelteKitConfig(directives) {
73
78
  }
74
79
  return sveltekitDirectives;
75
80
  }
76
- function csp(options = { mode: "auto" }) {
81
+ /**
82
+ * Create a SvelteKit Content Security Policy configuration.
83
+ *
84
+ * @param options
85
+ * Configuration.
86
+ * @returns
87
+ * SvelteKit Content Security Policy configuration.
88
+ */
89
+ function csp(options) {
77
90
  return {
78
- mode: options.mode ? options.mode : "auto",
79
- directives: directivesToSvelteKitConfig(options.directives ?? defaults.contentSecurityPolicy.directives),
91
+ mode: options?.mode ? options.mode : "auto",
92
+ directives: directivesToSvelteKitConfig(options?.directives ?? defaults.contentSecurityPolicy.directives) || {},
80
93
  };
81
94
  }
82
95
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nosecone/sveltekit",
3
- "version": "1.0.0-beta.9",
3
+ "version": "1.1.0-rc",
4
4
  "description": "Protect your SvelteKit application with secure headers",
5
5
  "keywords": [
6
6
  "arcjet",
@@ -37,7 +37,7 @@
37
37
  "url": "https://arcjet.com"
38
38
  },
39
39
  "engines": {
40
- "node": ">=18"
40
+ "node": ">=20"
41
41
  },
42
42
  "type": "module",
43
43
  "main": "./index.js",
@@ -49,27 +49,27 @@
49
49
  "scripts": {
50
50
  "build": "rollup --config rollup.config.js",
51
51
  "lint": "eslint .",
52
- "prepublishOnly": "npm run build",
53
- "test": "npm run build && npm run lint"
52
+ "test-api": "node --test -- test/*.test.js",
53
+ "test-coverage": "node --experimental-test-coverage --test -- test/*.test.js",
54
+ "test": "npm run build && npm run lint && npm run test-coverage"
54
55
  },
55
56
  "dependencies": {
56
- "nosecone": "1.0.0-beta.9"
57
+ "nosecone": "1.1.0-rc"
57
58
  },
58
59
  "peerDependencies": {
59
60
  "@sveltejs/kit": ">=2"
60
61
  },
61
62
  "devDependencies": {
62
- "@arcjet/eslint-config": "1.0.0-beta.9",
63
- "@arcjet/rollup-config": "1.0.0-beta.9",
64
- "@arcjet/tsconfig": "1.0.0-beta.9",
65
- "@rollup/wasm-node": "4.44.2",
66
- "@sveltejs/kit": "2.22.2",
67
- "@sveltejs/vite-plugin-svelte": "5.1.0",
68
- "@types/node": "18.18.0",
69
- "eslint": "9.30.1",
70
- "svelte": "5.35.4",
71
- "typescript": "5.8.3",
72
- "vite": "7.0.3"
63
+ "@arcjet/eslint-config": "1.1.0-rc",
64
+ "@arcjet/rollup-config": "1.1.0-rc",
65
+ "@rollup/wasm-node": "4.57.0",
66
+ "@sveltejs/kit": "2.50.1",
67
+ "@sveltejs/vite-plugin-svelte": "6.2.4",
68
+ "@types/node": "25.0.10",
69
+ "eslint": "9.39.2",
70
+ "svelte": "5.48.3",
71
+ "typescript": "5.9.3",
72
+ "vite": "7.3.1"
73
73
  },
74
74
  "publishConfig": {
75
75
  "access": "public",