zyket 1.2.14 → 1.2.16

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": "zyket",
3
- "version": "1.2.14",
3
+ "version": "1.2.16",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"
@@ -22,7 +22,7 @@ module.exports = [
22
22
  eventsActivated ? ["events", EventService, ["@service_container"]] : null,
23
23
  databaseActivated ? ["database", Database, ["@service_container", process.env.DATABASE_URL]] : null,
24
24
  ["cache", Cache, ["@service_container", process.env.CACHE_URL || '']],
25
- s3Activated ? ["s3", S3, ["@service_container", process.env.S3_ENDPOINT, process.env.S3_PORT, process.env.S3_USE_SSL === "true", process.env.S3_ACCESS_KEY, process.env.S3_SECRET_KEY]] : null,
25
+ s3Activated ? ["s3", S3, ["@service_container", process.env.S3_ENDPOINT, process.env.S3_PORT, process.env.S3_USE_SSL === "true", process.env.S3_ACCESS_KEY, process.env.S3_SECRET_KEY, process.env.S3_PUBLIC_BUCKETS, process.env.S3_PRIVATE_BUCKETS]] : null,
26
26
  schedulerActivated ? ["scheduler", Scheduler, ["@service_container"]] : null,
27
27
  bullmqActivated ? ["bullmq", require("./bullmq"), ["@service_container"]] : null,
28
28
  socketActivated ? ["socketio", SocketIO, ["@service_container"]] : null,
@@ -8,8 +8,10 @@ module.exports = class S3 extends Service {
8
8
  #useSSL
9
9
  #accessKey
10
10
  #secretKey
11
+ #publicBuckets
12
+ #privateBuckets
11
13
 
12
- constructor(container, endPoint, port, useSSL, accessKey, secretKey) {
14
+ constructor(container, endPoint, port, useSSL, accessKey, secretKey, publicBuckets, privateBuckets) {
13
15
  super('s3')
14
16
  this.#container = container
15
17
  this.#endPoint = endPoint
@@ -17,6 +19,8 @@ module.exports = class S3 extends Service {
17
19
  this.#useSSL = useSSL
18
20
  this.#accessKey = accessKey
19
21
  this.#secretKey = secretKey
22
+ this.#publicBuckets = this.#parseBuckets(publicBuckets)
23
+ this.#privateBuckets = this.#parseBuckets(privateBuckets)
20
24
  }
21
25
 
22
26
  async boot() {
@@ -27,6 +31,53 @@ module.exports = class S3 extends Service {
27
31
  accessKey: this.#accessKey,
28
32
  secretKey: this.#secretKey
29
33
  })
34
+
35
+ await this.initBuckets()
36
+ }
37
+
38
+ #parseBuckets(value) {
39
+ if (!value) return []
40
+ return value
41
+ .split(',')
42
+ .map((name) => name.trim())
43
+ .filter(Boolean)
44
+ }
45
+
46
+ async initBuckets() {
47
+ for (const bucketName of this.#privateBuckets) {
48
+ await this.ensureBucket(bucketName, false)
49
+ }
50
+ for (const bucketName of this.#publicBuckets) {
51
+ await this.ensureBucket(bucketName, true)
52
+ }
53
+ }
54
+
55
+ async ensureBucket(bucketName, isPublic = false) {
56
+ const exists = await this.client.bucketExists(bucketName)
57
+ if (!exists) {
58
+ this.#container.get('logger').info(`Creating ${isPublic ? 'public' : 'private'} bucket ${bucketName}`)
59
+ await this.client.makeBucket(bucketName, 'us-east-1')
60
+ }
61
+
62
+ if (isPublic) {
63
+ await this.setBucketPublic(bucketName)
64
+ }
65
+ }
66
+
67
+ async setBucketPublic(bucketName) {
68
+ const policy = {
69
+ Version: '2012-10-17',
70
+ Statement: [
71
+ {
72
+ Effect: 'Allow',
73
+ Principal: { AWS: ['*'] },
74
+ Action: ['s3:GetObject'],
75
+ Resource: [`arn:aws:s3:::${bucketName}/*`],
76
+ },
77
+ ],
78
+ }
79
+ this.#container.get('logger').debug(`Setting public read policy on bucket ${bucketName}`)
80
+ return this.client.setBucketPolicy(bucketName, JSON.stringify(policy))
30
81
  }
31
82
 
32
83
  async saveFile(bucketName, fileName, file, contentType = 'binary/octet-stream') {
@@ -39,6 +39,10 @@ module.exports = class Vite extends Service {
39
39
  preview: {
40
40
  port: this.#port,
41
41
  strictPort: false,
42
+ // Listen on 0.0.0.0 so a reverse proxy can reach it, and accept
43
+ // requests for any Host (the proxy forwards the public domain).
44
+ host: true,
45
+ allowedHosts: true,
42
46
  },
43
47
  });
44
48
 
@@ -57,6 +61,8 @@ module.exports = class Vite extends Service {
57
61
  server: {
58
62
  port: this.#port,
59
63
  strictPort: false,
64
+ host: true,
65
+ allowedHosts: true,
60
66
  },
61
67
  });
62
68
 
@@ -31,6 +31,8 @@ module.exports = class EnvManager {
31
31
  S3_USE_SSL: true,
32
32
  S3_ACCESS_KEY: '',
33
33
  S3_SECRET_KEY: '',
34
+ S3_PUBLIC_BUCKETS: '',
35
+ S3_PRIVATE_BUCKETS: '',
34
36
  DISABLE_LOGGER: false,
35
37
  LOG_DIRECTORY: "./logs",
36
38
  QUEUES: '',