@nosecone/sveltekit 1.7.0-rc.0 → 1.7.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/index.d.ts ADDED
@@ -0,0 +1,115 @@
1
+ import nosecone from "nosecone";
2
+ import type { CspDirectives, Options } from "nosecone";
3
+ import type { Handle, KitConfig } from "@sveltejs/kit";
4
+ export { withVercelToolbar, type Options, type NoseconeOptions, } from "nosecone";
5
+ /**
6
+ * Nosecone SvelteKit defaults.
7
+ */
8
+ export declare const defaults: {
9
+ readonly directives: {
10
+ readonly scriptSrc: readonly ["'strict-dynamic'"];
11
+ readonly baseUri: readonly ["'none'"];
12
+ readonly childSrc: readonly ["'none'"];
13
+ readonly connectSrc: readonly ["'self'"];
14
+ readonly defaultSrc: readonly ["'self'"];
15
+ readonly fontSrc: readonly ["'self'"];
16
+ readonly formAction: readonly ["'self'"];
17
+ readonly frameAncestors: readonly ["'none'"];
18
+ readonly frameSrc: readonly ["'none'"];
19
+ readonly imgSrc: readonly ["'self'", "blob:", "data:"];
20
+ readonly manifestSrc: readonly ["'self'"];
21
+ readonly mediaSrc: readonly ["'self'"];
22
+ readonly objectSrc: readonly ["'none'"];
23
+ readonly styleSrc: readonly ["'self'"];
24
+ readonly workerSrc: readonly ["'self'"];
25
+ };
26
+ readonly contentSecurityPolicy: {
27
+ readonly directives: {
28
+ readonly baseUri: readonly ["'none'"];
29
+ readonly childSrc: readonly ["'none'"];
30
+ readonly connectSrc: readonly ["'self'"];
31
+ readonly defaultSrc: readonly ["'self'"];
32
+ readonly fontSrc: readonly ["'self'"];
33
+ readonly formAction: readonly ["'self'"];
34
+ readonly frameAncestors: readonly ["'none'"];
35
+ readonly frameSrc: readonly ["'none'"];
36
+ readonly imgSrc: readonly ["'self'", "blob:", "data:"];
37
+ readonly manifestSrc: readonly ["'self'"];
38
+ readonly mediaSrc: readonly ["'self'"];
39
+ readonly objectSrc: readonly ["'none'"];
40
+ readonly scriptSrc: readonly ["'self'"];
41
+ readonly styleSrc: readonly ["'self'"];
42
+ readonly workerSrc: readonly ["'self'"];
43
+ };
44
+ };
45
+ readonly crossOriginEmbedderPolicy: {
46
+ readonly policy: "require-corp";
47
+ };
48
+ readonly crossOriginOpenerPolicy: {
49
+ readonly policy: "same-origin";
50
+ };
51
+ readonly crossOriginResourcePolicy: {
52
+ readonly policy: "same-origin";
53
+ };
54
+ readonly originAgentCluster: true;
55
+ readonly referrerPolicy: {
56
+ readonly policy: readonly ["no-referrer"];
57
+ };
58
+ readonly strictTransportSecurity: {
59
+ readonly maxAge: number;
60
+ readonly includeSubDomains: true;
61
+ readonly preload: false;
62
+ };
63
+ readonly xContentTypeOptions: true;
64
+ readonly xDnsPrefetchControl: {
65
+ readonly allow: false;
66
+ };
67
+ readonly xDownloadOptions: true;
68
+ readonly xFrameOptions: {
69
+ readonly action: "sameorigin";
70
+ };
71
+ readonly xPermittedCrossDomainPolicies: {
72
+ readonly permittedPolicies: "none";
73
+ };
74
+ readonly xXssProtection: true;
75
+ };
76
+ export { nosecone };
77
+ /**
78
+ * Create security headers.
79
+ *
80
+ * @deprecated
81
+ * Use the named export `nosecone` instead.
82
+ */
83
+ export default nosecone;
84
+ /**
85
+ * Create a SvelteKit hook that sets secure headers on every request.
86
+ *
87
+ * @param options
88
+ * Configuration to provide to Nosecone.
89
+ * @returns
90
+ * SvelteKit hook that sets secure headers.
91
+ */
92
+ export declare function createHook(options?: Options): Handle;
93
+ type SvelteKitCsp = Exclude<KitConfig["csp"], undefined>;
94
+ /**
95
+ * Content Security Policy configuration for SvelteKit.
96
+ */
97
+ export type ContentSecurityPolicyConfig = {
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;
106
+ };
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 ADDED
@@ -0,0 +1,96 @@
1
+ import nosecone, { defaults as defaults$1, CONTENT_SECURITY_POLICY_DIRECTIVES, NoseconeValidationError, QUOTED } from 'nosecone';
2
+ export { default, default as nosecone, withVercelToolbar } from 'nosecone';
3
+
4
+ /**
5
+ * Nosecone SvelteKit defaults.
6
+ */
7
+ const defaults = {
8
+ ...defaults$1,
9
+ directives: {
10
+ ...defaults$1.contentSecurityPolicy.directives,
11
+ scriptSrc: ["'strict-dynamic'"],
12
+ },
13
+ };
14
+ /**
15
+ * Create a SvelteKit hook that sets secure headers on every request.
16
+ *
17
+ * @param options
18
+ * Configuration to provide to Nosecone.
19
+ * @returns
20
+ * SvelteKit hook that sets secure headers.
21
+ */
22
+ function createHook(options = defaults) {
23
+ return async ({ event, resolve }) => {
24
+ const response = await resolve(event);
25
+ const headers = nosecone(options);
26
+ for (const [headerName, headerValue] of headers.entries()) {
27
+ // Only add headers that aren't already set. For example, SvelteKit will
28
+ // likely have added `Content-Security-Policy` if configured with `csp`
29
+ if (!response.headers.has(headerName)) {
30
+ response.headers.set(headerName, headerValue);
31
+ }
32
+ }
33
+ return response;
34
+ };
35
+ }
36
+ function unquote(value) {
37
+ for (const [unquoted, quoted] of QUOTED) {
38
+ if (value === quoted) {
39
+ return unquoted;
40
+ }
41
+ }
42
+ return value;
43
+ }
44
+ function resolveValue(v) {
45
+ if (typeof v === "function") {
46
+ return v();
47
+ }
48
+ else {
49
+ return v;
50
+ }
51
+ }
52
+ function directivesToSvelteKitConfig(directives) {
53
+ const sveltekitDirectives = {};
54
+ for (const [optionKey, optionValues] of Object.entries(directives)) {
55
+ const key = CONTENT_SECURITY_POLICY_DIRECTIVES.get(
56
+ // @ts-expect-error because we're validating this option key
57
+ optionKey);
58
+ if (!key) {
59
+ throw new NoseconeValidationError(`${optionKey} is not a Content-Security-Policy directive`);
60
+ }
61
+ // Skip anything falsey
62
+ if (!optionValues) {
63
+ continue;
64
+ }
65
+ // TODO: What do we want to do if array is empty? I think they work differently for some directives
66
+ const resolvedValues = Array.isArray(optionValues)
67
+ ? new Set(optionValues.map(resolveValue))
68
+ : new Set();
69
+ // TODO: Add validations for SvelteKit CSP directives
70
+ const values = Array.from(resolvedValues);
71
+ if (key === "upgrade-insecure-requests") {
72
+ sveltekitDirectives[key] = true;
73
+ }
74
+ else {
75
+ // @ts-expect-error because we're mapping to SvelteKit options
76
+ sveltekitDirectives[key] = values.map(unquote);
77
+ }
78
+ }
79
+ return sveltekitDirectives;
80
+ }
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) {
90
+ return {
91
+ mode: options?.mode ? options.mode : "auto",
92
+ directives: directivesToSvelteKitConfig(options?.directives ?? defaults.contentSecurityPolicy.directives) || {},
93
+ };
94
+ }
95
+
96
+ export { createHook, csp, defaults };
package/package.json CHANGED
@@ -1,10 +1,11 @@
1
1
  {
2
2
  "name": "@nosecone/sveltekit",
3
- "version": "1.7.0-rc.0",
3
+ "version": "1.7.0",
4
4
  "description": "Protect your SvelteKit application with secure headers",
5
5
  "keywords": [
6
6
  "arcjet",
7
7
  "coep",
8
+ "coep",
8
9
  "content-security-policy",
9
10
  "coop",
10
11
  "corp",
@@ -16,65 +17,62 @@
16
17
  "http",
17
18
  "nosecone",
18
19
  "protect",
19
- "svelte",
20
- "sveltekit"
20
+ "sveltekit",
21
+ "svelte"
21
22
  ],
23
+ "license": "Apache-2.0",
22
24
  "homepage": "https://arcjet.com",
25
+ "repository": {
26
+ "type": "git",
27
+ "url": "git+https://github.com/arcjet/arcjet-js.git",
28
+ "directory": "nosecone-sveltekit"
29
+ },
23
30
  "bugs": {
24
31
  "url": "https://github.com/arcjet/arcjet-js/issues",
25
32
  "email": "support@arcjet.com"
26
33
  },
27
- "license": "Apache-2.0",
28
34
  "author": {
29
35
  "name": "Arcjet",
30
36
  "email": "support@arcjet.com",
31
37
  "url": "https://arcjet.com"
32
38
  },
33
- "repository": {
34
- "type": "git",
35
- "url": "git+https://github.com/arcjet/arcjet-js.git",
36
- "directory": "nosecone-sveltekit"
39
+ "engines": {
40
+ "node": ">=22.21.0 <23 || >=24.5.0"
37
41
  },
42
+ "type": "module",
43
+ "main": "./index.js",
44
+ "types": "./index.d.ts",
38
45
  "files": [
39
- "dist"
46
+ "index.d.ts",
47
+ "index.js"
40
48
  ],
41
- "type": "module",
42
- "main": "./dist/index.js",
43
- "types": "./dist/index.d.ts",
44
- "exports": {
45
- ".": {
46
- "types": "./dist/index.d.ts",
47
- "default": "./dist/index.js"
48
- },
49
- "./package.json": "./package.json"
50
- },
51
- "publishConfig": {
52
- "access": "public",
53
- "tag": "latest"
54
- },
55
49
  "scripts": {
56
- "build": "tsdown",
57
- "typecheck": "tsgo --noEmit",
58
- "test-api": "node --test -- test/*.test.ts",
59
- "test-coverage": "node --experimental-test-coverage --test -- test/*.test.ts",
60
- "test": "npm run build && npm run test-coverage"
50
+ "build": "rollup --config rollup.config.js",
51
+ "lint": "eslint .",
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"
61
55
  },
62
56
  "dependencies": {
63
- "nosecone": "1.7.0-rc.0"
57
+ "nosecone": "1.7.0"
58
+ },
59
+ "peerDependencies": {
60
+ "@sveltejs/kit": ">=2"
64
61
  },
65
62
  "devDependencies": {
63
+ "@arcjet/eslint-config": "1.7.0",
64
+ "@arcjet/rollup-config": "1.7.0",
65
+ "@rollup/wasm-node": "4.62.2",
66
66
  "@sveltejs/kit": "2.66.0",
67
67
  "@sveltejs/vite-plugin-svelte": "7.1.2",
68
68
  "@types/node": "22.19.21",
69
+ "eslint": "9.39.4",
69
70
  "svelte": "5.56.3",
70
- "tsdown": "0.22.3",
71
- "typescript": "6.0.3",
71
+ "typescript": "5.9.3",
72
72
  "vite": "8.0.16"
73
73
  },
74
- "peerDependencies": {
75
- "@sveltejs/kit": ">=2"
76
- },
77
- "engines": {
78
- "node": ">=22.21.0 <23 || >=24.5.0"
74
+ "publishConfig": {
75
+ "access": "public",
76
+ "tag": "latest"
79
77
  }
80
78
  }
package/dist/index.d.ts DELETED
@@ -1,109 +0,0 @@
1
- import nosecone, { CspDirectives, NoseconeOptions, Options, Options as Options$1, withVercelToolbar } from "nosecone";
2
- import { Handle, KitConfig } from "@sveltejs/kit";
3
-
4
- //#region src/index.d.ts
5
- /**
6
- * Nosecone SvelteKit defaults.
7
- */
8
- declare const defaults: {
9
- readonly directives: {
10
- readonly scriptSrc: readonly ["'strict-dynamic'"];
11
- readonly baseUri: readonly ["'none'"];
12
- readonly childSrc: readonly ["'none'"];
13
- readonly connectSrc: readonly ["'self'"];
14
- readonly defaultSrc: readonly ["'self'"];
15
- readonly fontSrc: readonly ["'self'"];
16
- readonly formAction: readonly ["'self'"];
17
- readonly frameAncestors: readonly ["'none'"];
18
- readonly frameSrc: readonly ["'none'"];
19
- readonly imgSrc: readonly ["'self'", "blob:", "data:"];
20
- readonly manifestSrc: readonly ["'self'"];
21
- readonly mediaSrc: readonly ["'self'"];
22
- readonly objectSrc: readonly ["'none'"];
23
- readonly styleSrc: readonly ["'self'"];
24
- readonly workerSrc: readonly ["'self'"];
25
- };
26
- readonly contentSecurityPolicy: {
27
- readonly directives: {
28
- readonly baseUri: readonly ["'none'"];
29
- readonly childSrc: readonly ["'none'"];
30
- readonly connectSrc: readonly ["'self'"];
31
- readonly defaultSrc: readonly ["'self'"];
32
- readonly fontSrc: readonly ["'self'"];
33
- readonly formAction: readonly ["'self'"];
34
- readonly frameAncestors: readonly ["'none'"];
35
- readonly frameSrc: readonly ["'none'"];
36
- readonly imgSrc: readonly ["'self'", "blob:", "data:"];
37
- readonly manifestSrc: readonly ["'self'"];
38
- readonly mediaSrc: readonly ["'self'"];
39
- readonly objectSrc: readonly ["'none'"];
40
- readonly scriptSrc: readonly ["'self'"];
41
- readonly styleSrc: readonly ["'self'"];
42
- readonly workerSrc: readonly ["'self'"];
43
- };
44
- };
45
- readonly crossOriginEmbedderPolicy: {
46
- readonly policy: "require-corp";
47
- };
48
- readonly crossOriginOpenerPolicy: {
49
- readonly policy: "same-origin";
50
- };
51
- readonly crossOriginResourcePolicy: {
52
- readonly policy: "same-origin";
53
- };
54
- readonly originAgentCluster: true;
55
- readonly referrerPolicy: {
56
- readonly policy: readonly ["no-referrer"];
57
- };
58
- readonly strictTransportSecurity: {
59
- readonly maxAge: 31536000;
60
- readonly includeSubDomains: true;
61
- readonly preload: false;
62
- };
63
- readonly xContentTypeOptions: true;
64
- readonly xDnsPrefetchControl: {
65
- readonly allow: false;
66
- };
67
- readonly xDownloadOptions: true;
68
- readonly xFrameOptions: {
69
- readonly action: "sameorigin";
70
- };
71
- readonly xPermittedCrossDomainPolicies: {
72
- readonly permittedPolicies: "none";
73
- };
74
- readonly xXssProtection: true;
75
- };
76
- /**
77
- * Create a SvelteKit hook that sets secure headers on every request.
78
- *
79
- * @param options
80
- * Configuration to provide to Nosecone.
81
- * @returns
82
- * SvelteKit hook that sets secure headers.
83
- */
84
- declare function createHook(options?: Options$1): Handle;
85
- type SvelteKitCsp = Exclude<KitConfig["csp"], undefined>;
86
- /**
87
- * Content Security Policy configuration for SvelteKit.
88
- */
89
- type ContentSecurityPolicyConfig = {
90
- /**
91
- * Mode of the `Content-Security-Policy` header.
92
- */
93
- mode?: SvelteKitCsp["mode"] | undefined;
94
- /**
95
- * Directives to use in the `Content-Security-Policy` header.
96
- */
97
- directives?: CspDirectives | undefined;
98
- };
99
- /**
100
- * Create a SvelteKit Content Security Policy configuration.
101
- *
102
- * @param options
103
- * Configuration.
104
- * @returns
105
- * SvelteKit Content Security Policy configuration.
106
- */
107
- declare function csp(options?: ContentSecurityPolicyConfig | undefined): SvelteKitCsp;
108
- //#endregion
109
- export { ContentSecurityPolicyConfig, type NoseconeOptions, type Options, createHook, csp, nosecone as default, nosecone, defaults, withVercelToolbar };
package/dist/index.js DELETED
@@ -1,72 +0,0 @@
1
- import nosecone, { CONTENT_SECURITY_POLICY_DIRECTIVES, NoseconeValidationError, QUOTED, defaults as defaults$1, withVercelToolbar } from "nosecone";
2
- //#region src/index.ts
3
- /**
4
- * Nosecone SvelteKit defaults.
5
- */
6
- const defaults = {
7
- ...defaults$1,
8
- directives: {
9
- ...defaults$1.contentSecurityPolicy.directives,
10
- scriptSrc: ["'strict-dynamic'"]
11
- }
12
- };
13
- /**
14
- * Create security headers.
15
- *
16
- * @deprecated
17
- * Use the named export `nosecone` instead.
18
- */
19
- var src_default = nosecone;
20
- /**
21
- * Create a SvelteKit hook that sets secure headers on every request.
22
- *
23
- * @param options
24
- * Configuration to provide to Nosecone.
25
- * @returns
26
- * SvelteKit hook that sets secure headers.
27
- */
28
- function createHook(options = defaults) {
29
- return async ({ event, resolve }) => {
30
- const response = await resolve(event);
31
- const headers = nosecone(options);
32
- for (const [headerName, headerValue] of headers.entries()) if (!response.headers.has(headerName)) response.headers.set(headerName, headerValue);
33
- return response;
34
- };
35
- }
36
- function unquote(value) {
37
- for (const [unquoted, quoted] of QUOTED) if (value === quoted) return unquoted;
38
- return value;
39
- }
40
- function resolveValue(v) {
41
- if (typeof v === "function") return v();
42
- else return v;
43
- }
44
- function directivesToSvelteKitConfig(directives) {
45
- const sveltekitDirectives = {};
46
- for (const [optionKey, optionValues] of Object.entries(directives)) {
47
- const key = CONTENT_SECURITY_POLICY_DIRECTIVES.get(optionKey);
48
- if (!key) throw new NoseconeValidationError(`${optionKey} is not a Content-Security-Policy directive`);
49
- if (!optionValues) continue;
50
- const resolvedValues = Array.isArray(optionValues) ? new Set(optionValues.map(resolveValue)) : /* @__PURE__ */ new Set();
51
- const values = Array.from(resolvedValues);
52
- if (key === "upgrade-insecure-requests") sveltekitDirectives[key] = true;
53
- else sveltekitDirectives[key] = values.map(unquote);
54
- }
55
- return sveltekitDirectives;
56
- }
57
- /**
58
- * Create a SvelteKit Content Security Policy configuration.
59
- *
60
- * @param options
61
- * Configuration.
62
- * @returns
63
- * SvelteKit Content Security Policy configuration.
64
- */
65
- function csp(options) {
66
- return {
67
- mode: options?.mode ? options.mode : "auto",
68
- directives: directivesToSvelteKitConfig(options?.directives ?? defaults.contentSecurityPolicy.directives) || {}
69
- };
70
- }
71
- //#endregion
72
- export { createHook, csp, src_default as default, defaults, nosecone, withVercelToolbar };