@nosecone/sveltekit 1.0.0-beta.1 → 1.0.0-beta.11

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 +48 -26
  2. package/index.d.ts +37 -8
  3. package/index.js +19 -6
  4. package/package.json +36 -17
package/README.md CHANGED
@@ -18,40 +18,59 @@
18
18
 
19
19
  Protect your SvelteKit application with secure headers.
20
20
 
21
- ## Installation
21
+ - [npm package (`@nosecone/sveltekit`)](https://www.npmjs.com/package/@nosecone/sveltekit)
22
+ - [GitHub source code (`nosecone-sveltekit/` in `arcjet/arcjet-js`)](https://github.com/arcjet/arcjet-js/tree/main/nosecone-sveltekit)
22
23
 
23
- ```shell
24
- npm install -S @nosecone/sveltekit
24
+ ## What is this?
25
+
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
25
45
  ```
26
46
 
27
47
  ## Example
28
48
 
29
- Update your `svelte.config.js` file for `csp`:
49
+ Configure `csp` from Nosecone in `svelte.config.js`:
30
50
 
31
51
  ```diff
32
- import adapter from "@sveltejs/adapter-auto";
33
- import { vitePreprocess } from "@sveltejs/vite-plugin-svelte";
34
- + import { csp } from "@nosecone/sveltekit"
35
-
36
- /** @type {import('@sveltejs/kit').Config} */
37
- const config = {
38
- // Consult https://kit.svelte.dev/docs/integrations#preprocessors
39
- // for more information about preprocessors
40
- preprocess: vitePreprocess(),
41
-
42
- kit: {
43
- + csp: csp(),
44
- // adapter-auto only supports some environments, see https://kit.svelte.dev/docs/adapter-auto for a list.
45
- // If your environment is not supported, or you settled on a specific environment, switch out the adapter.
46
- // See https://kit.svelte.dev/docs/adapters for more information about adapters.
47
- adapter: adapter(),
48
- },
49
- };
50
-
51
- 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;
52
71
  ```
53
72
 
54
- Create a `src/hooks.server.ts` file with the contents:
73
+ …then use `createHook` from Nosecone in a `src/hooks.server.ts` file:
55
74
 
56
75
  ```ts
57
76
  import { createHook } from "@nosecone/sveltekit";
@@ -65,6 +84,9 @@ export const handle = sequence(
65
84
 
66
85
  ## License
67
86
 
68
- Licensed under the [Apache License, Version 2.0][apache-license].
87
+ [Apache License, Version 2.0][apache-license] © [Arcjet Labs, Inc.][arcjet]
69
88
 
70
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,7 +1,25 @@
1
1
  {
2
2
  "name": "@nosecone/sveltekit",
3
- "version": "1.0.0-beta.1",
3
+ "version": "1.0.0-beta.11",
4
4
  "description": "Protect your SvelteKit application with secure headers",
5
+ "keywords": [
6
+ "arcjet",
7
+ "coep",
8
+ "coep",
9
+ "content-security-policy",
10
+ "coop",
11
+ "corp",
12
+ "cross-origin-embedder-policy",
13
+ "cross-origin-opener-policy",
14
+ "cross-origin-resource-policy",
15
+ "csp",
16
+ "header",
17
+ "http",
18
+ "nosecone",
19
+ "protect",
20
+ "sveltekit",
21
+ "svelte"
22
+ ],
5
23
  "license": "Apache-2.0",
6
24
  "homepage": "https://arcjet.com",
7
25
  "repository": {
@@ -25,33 +43,34 @@
25
43
  "main": "./index.js",
26
44
  "types": "./index.d.ts",
27
45
  "files": [
28
- "LICENSE",
29
- "README.md",
30
- "*.js",
31
- "*.d.ts",
32
- "!*.config.js"
46
+ "index.d.ts",
47
+ "index.js"
33
48
  ],
34
49
  "scripts": {
35
- "prepublishOnly": "npm run build",
36
50
  "build": "rollup --config rollup.config.js",
37
51
  "lint": "eslint .",
38
- "pretest": "npm run build",
39
- "test": "node --test"
52
+ "prepublishOnly": "npm run build",
53
+ "test-api": "node --test",
54
+ "test-coverage": "node --experimental-test-coverage --test",
55
+ "test": "npm run build && npm run lint && npm run test-coverage"
40
56
  },
41
57
  "dependencies": {
42
- "nosecone": "1.0.0-beta.1"
58
+ "nosecone": "1.0.0-beta.11"
43
59
  },
44
60
  "peerDependencies": {
45
61
  "@sveltejs/kit": ">=2"
46
62
  },
47
63
  "devDependencies": {
48
- "@arcjet/eslint-config": "1.0.0-beta.1",
49
- "@arcjet/rollup-config": "1.0.0-beta.1",
50
- "@arcjet/tsconfig": "1.0.0-beta.1",
51
- "@rollup/wasm-node": "4.30.1",
52
- "@sveltejs/kit": "^2.15.2",
53
- "@types/node": "18.18.0",
54
- "typescript": "5.7.3"
64
+ "@arcjet/eslint-config": "1.0.0-beta.11",
65
+ "@arcjet/rollup-config": "1.0.0-beta.11",
66
+ "@rollup/wasm-node": "4.50.0",
67
+ "@sveltejs/kit": "2.37.0",
68
+ "@sveltejs/vite-plugin-svelte": "6.1.4",
69
+ "@types/node": "24.3.0",
70
+ "eslint": "9.34.0",
71
+ "svelte": "5.38.6",
72
+ "typescript": "5.9.2",
73
+ "vite": "7.1.4"
55
74
  },
56
75
  "publishConfig": {
57
76
  "access": "public",