@lvce-editor/shared-process 0.24.5 → 0.24.6

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/shared-process",
3
- "version": "0.24.5",
3
+ "version": "0.24.6",
4
4
  "main": "index.js",
5
5
  "type": "module",
6
6
  "keywords": [
@@ -18,12 +18,12 @@
18
18
  },
19
19
  "dependencies": {
20
20
  "@lvce-editor/assert": "^1.2.0",
21
- "@lvce-editor/extension-host-helper-process": "0.24.5",
21
+ "@lvce-editor/extension-host-helper-process": "0.24.6",
22
22
  "@lvce-editor/ipc": "^2.1.0",
23
23
  "@lvce-editor/json-rpc": "^1.0.0",
24
24
  "@lvce-editor/jsonc-parser": "^1.1.1",
25
25
  "@lvce-editor/pretty-error": "^1.5.0",
26
- "@lvce-editor/pty-host": "0.24.5",
26
+ "@lvce-editor/pty-host": "0.24.6",
27
27
  "@lvce-editor/verror": "^1.1.2",
28
28
  "@lvce-editor/web-socket-server": "^1.1.0",
29
29
  "debug": "^4.3.4",
@@ -0,0 +1,7 @@
1
+ import * as ContentSecurityPolicy from './ContentSecurityPolicy.js'
2
+
3
+ export const name = 'ContentSecurityPolicy'
4
+
5
+ export const Commands = {
6
+ set: ContentSecurityPolicy.set,
7
+ }
@@ -1,16 +1,8 @@
1
- import * as Character from '../Character/Character.js'
2
- import * as AddSemiColon from '../AddSemiColon/AddSemiColon.js'
1
+ import * as Assert from '../Assert/Assert.js'
2
+ import * as ContentSecurityPolicyState from '../ContentSecurityPolicyState/ContentSecurityPolicyState.js'
3
3
 
4
- export const key = 'Content-Security-Policy'
5
-
6
- export const value = [
7
- `default-src 'none'`,
8
- `font-src 'self'`,
9
- `frame-src *`,
10
- `img-src 'self' https: data:`,
11
- `script-src 'self'`,
12
- `media-src 'self'`,
13
- `style-src 'self'`,
14
- ]
15
- .map(AddSemiColon.addSemicolon)
16
- .join(Character.Space)
4
+ export const set = (url, contentSecurityPolicy) => {
5
+ Assert.string(url)
6
+ Assert.string(contentSecurityPolicy)
7
+ ContentSecurityPolicyState.set(url, contentSecurityPolicy)
8
+ }
@@ -0,0 +1,16 @@
1
+ import * as Character from '../Character/Character.js'
2
+ import * as AddSemiColon from '../AddSemiColon/AddSemiColon.js'
3
+
4
+ export const key = 'Content-Security-Policy'
5
+
6
+ export const value = [
7
+ `default-src 'none'`,
8
+ `font-src 'self'`,
9
+ `frame-src *`,
10
+ `img-src 'self' https: data:`,
11
+ `script-src 'self'`,
12
+ `media-src 'self'`,
13
+ `style-src 'self'`,
14
+ ]
15
+ .map(AddSemiColon.addSemicolon)
16
+ .join(Character.Space)
@@ -0,0 +1,9 @@
1
+ const map = Object.create(null)
2
+
3
+ export const set = (url, contentSecurityPolicy) => {
4
+ map[url] = contentSecurityPolicy
5
+ }
6
+
7
+ export const get = (url) => {
8
+ return map[url]
9
+ }
@@ -0,0 +1,6 @@
1
+ import * as Character from '../Character/Character.js'
2
+ import * as AddSemiColon from '../AddSemiColon/AddSemiColon.js'
3
+
4
+ export const key = 'Content-Security-Policy'
5
+
6
+ export const value = [`default-src 'none'`, `script-src 'self'`].map(AddSemiColon.addSemicolon).join(Character.Space)
@@ -28,7 +28,7 @@ export const getElectronFileResponse = async (url, request) => {
28
28
  }
29
29
  }
30
30
  const content = await GetElectronFileResponseContent.getElectronFileResponseContent(request, absolutePath, url)
31
- const headers = GetHeaders.getHeaders(absolutePath)
31
+ const headers = GetHeaders.getHeaders(absolutePath, pathName)
32
32
  headers['Cache-Control'] = 'public, max-age=0, must-revalidate'
33
33
  if (etag) {
34
34
  headers['Etag'] = etag
@@ -1,6 +1,7 @@
1
1
  import { extname } from 'path'
2
2
  import * as GetHeadersExtensionHostWorker from '../GetHeadersExtensionHostWorker/GetHeadersExtensionHostWorker.js'
3
3
  import * as GetHeadersMainFrame from '../GetHeadersMainFrame/GetHeadersMainFrame.js'
4
+ import * as GetHeadersTestWorker from '../GetHeadersTestWorker/GetHeadersTestWorker.js'
4
5
  import * as GetHeadersOtherWorker from '../GetHeadersOtherWorker/GetHeadersOtherWorker.js'
5
6
  import * as GetHeadersRendererWorker from '../GetHeadersRendererWorker/GetHeadersRendererWorker.js'
6
7
  import * as GetMimeType from '../GetMimeType/GetMimeType.js'
@@ -9,19 +10,23 @@ const getHeadersDefault = () => {
9
10
  return {}
10
11
  }
11
12
 
12
- const getExtraHeaders = (url, fileExtension) => {
13
+ const getExtraHeaders = (pathName, fileExtension) => {
13
14
  switch (fileExtension) {
14
15
  case '.html':
15
16
  return GetHeadersMainFrame.getHeadersMainFrame()
16
17
  case '.js':
17
- if (url.endsWith('rendererWorkerMain.js')) {
18
+ case '.ts':
19
+ if (pathName.endsWith('testWorkerMain.js') || pathName.endsWith('testWorkerMain.ts')) {
20
+ return GetHeadersTestWorker.getHeadersExtensionHostWorker()
21
+ }
22
+ if (pathName.endsWith('rendererWorkerMain.js')) {
18
23
  return GetHeadersRendererWorker.getHeadersRendererWorker()
19
24
  }
20
- if (url.endsWith('extensionHostWorkerMain.js')) {
25
+ if (pathName.endsWith('extensionHostWorkerMain.js')) {
21
26
  return GetHeadersExtensionHostWorker.getHeadersExtensionHostWorker()
22
27
  }
23
- if (url.endsWith('WorkerMain.js')) {
24
- return GetHeadersOtherWorker.getHeadersOtherWorker()
28
+ if (pathName.endsWith('WorkerMain.js') || pathName.endsWith('WorkerMain.ts')) {
29
+ return GetHeadersOtherWorker.getHeadersOtherWorker(pathName)
25
30
  }
26
31
  return getHeadersDefault()
27
32
  default:
@@ -29,13 +34,13 @@ const getExtraHeaders = (url, fileExtension) => {
29
34
  }
30
35
  }
31
36
 
32
- export const getHeaders = (absolutePath) => {
37
+ export const getHeaders = (absolutePath, pathName) => {
33
38
  const extension = extname(absolutePath)
34
39
  const mime = GetMimeType.getMimeType(extension)
35
40
  const headers = {
36
41
  'Content-Type': mime,
37
42
  }
38
- const extraHeaders = getExtraHeaders(absolutePath, extension)
43
+ const extraHeaders = getExtraHeaders(pathName, extension)
39
44
  return {
40
45
  ...headers,
41
46
  ...extraHeaders,
@@ -1,10 +1,10 @@
1
- import * as ContentSecurityPolicy from '../ContentSecurityPolicy/ContentSecurityPolicy.js'
1
+ import * as ContentSecurityPolicyDocument from '../ContentSecurityPolicyDocument/ContentSecurityPolicyDocument.js'
2
2
  import * as CrossOriginEmbedderPolicy from '../CrossOriginEmbedderPolicy/CrossOriginEmbedderPolicy.js'
3
3
  import * as CrossOriginOpenerPolicy from '../CrossOriginOpenerPolicy/CrossOriginOpenerPolicy.js'
4
4
 
5
5
  export const getHeadersMainFrame = () => {
6
6
  return {
7
- [ContentSecurityPolicy.key]: ContentSecurityPolicy.value,
7
+ [ContentSecurityPolicyDocument.key]: ContentSecurityPolicyDocument.value,
8
8
  [CrossOriginOpenerPolicy.key]: CrossOriginOpenerPolicy.value,
9
9
  [CrossOriginEmbedderPolicy.key]: CrossOriginEmbedderPolicy.value,
10
10
  }
@@ -1,7 +1,13 @@
1
+ import * as ContentSecurityPolicyState from '../ContentSecurityPolicyState/ContentSecurityPolicyState.js'
1
2
  import * as CrossOriginEmbedderPolicy from '../CrossOriginEmbedderPolicy/CrossOriginEmbedderPolicy.js'
2
3
 
3
- export const getHeadersOtherWorker = () => {
4
- return {
4
+ export const getHeadersOtherWorker = (url) => {
5
+ const headers = {
5
6
  [CrossOriginEmbedderPolicy.key]: CrossOriginEmbedderPolicy.value,
6
7
  }
8
+ const dynamicCsp = ContentSecurityPolicyState.get(url)
9
+ if (dynamicCsp) {
10
+ headers['Content-Security-Policy'] = dynamicCsp
11
+ }
12
+ return headers
7
13
  }
@@ -0,0 +1,9 @@
1
+ import * as ContentSecurityPolicyTestWorker from '../ContentSecurityPolicyTestWorker/ContentSecurityPolicyTestWorker.js'
2
+ import * as CrossOriginEmbedderPolicy from '../CrossOriginEmbedderPolicy/CrossOriginEmbedderPolicy.js'
3
+
4
+ export const getHeadersExtensionHostWorker = () => {
5
+ return {
6
+ [CrossOriginEmbedderPolicy.key]: CrossOriginEmbedderPolicy.value,
7
+ [ContentSecurityPolicyTestWorker.key]: ContentSecurityPolicyTestWorker.value,
8
+ }
9
+ }
@@ -148,6 +148,8 @@ export const load = (moduleId) => {
148
148
  return import('../ElectronWebContentsView/ElectronWebContentsView.ipc.js')
149
149
  case ModuleId.ElectronWebContentsViewFunctions:
150
150
  return import('../ElectronWebContentsViewFunctions/ElectronWebContentsViewFunctions.ipc.js')
151
+ case ModuleId.ContentSecurityPolicy:
152
+ return import('../ContentSecurityPolicy/ContentSecurityPolicy.ipc.js')
151
153
  default:
152
154
  throw new Error(`module ${moduleId} not found`)
153
155
  }
@@ -73,3 +73,4 @@ export const ElectronWebContents = 66
73
73
  export const ElectronWebContentsView = 67
74
74
  export const ElectronWebContentsViewFunctions = 68
75
75
  export const HandleRequestTest = 69
76
+ export const ContentSecurityPolicy = 70
@@ -323,6 +323,8 @@ export const getModuleId = (commandId) => {
323
323
  return ModuleId.ElectronWebContentsView
324
324
  case 'HandleRequestTest.handleRequestTest':
325
325
  return ModuleId.HandleRequestTest
326
+ case 'ContentSecurityPolicy.set':
327
+ return ModuleId.ContentSecurityPolicy
326
328
  default:
327
329
  throw new CommandNotFoundError(commandId)
328
330
  }
@@ -61,11 +61,11 @@ export const getSetupName = () => {
61
61
  return 'Lvce-Setup'
62
62
  }
63
63
 
64
- export const version = '0.24.5'
64
+ export const version = '0.24.6'
65
65
 
66
- export const commit = '0319484'
66
+ export const commit = '4d24d4d'
67
67
 
68
- export const date = '2024-03-22T20:31:46.000Z'
68
+ export const date = '2024-03-23T08:10:57.000Z'
69
69
 
70
70
  export const getVersion = () => {
71
71
  return version