graphile-settings 4.19.0 → 4.20.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.
|
@@ -7,7 +7,7 @@ import { PresignedUrlPreset } from 'graphile-presigned-url-plugin';
|
|
|
7
7
|
import { BucketProvisionerPreset } from 'graphile-bucket-provisioner-plugin';
|
|
8
8
|
import { SqlExpressionValidatorPreset } from 'graphile-sql-expression-validator';
|
|
9
9
|
import { constructiveUploadFieldDefinitions } from '../upload-resolver';
|
|
10
|
-
import { getPresignedUrlS3Config } from '../presigned-url-resolver';
|
|
10
|
+
import { getPresignedUrlS3Config, createBucketNameResolver, createEnsureBucketProvisioned, getAllowedOrigins } from '../presigned-url-resolver';
|
|
11
11
|
import { getBucketProvisionerConnection } from '../bucket-provisioner-resolver';
|
|
12
12
|
/**
|
|
13
13
|
* Constructive PostGraphile v5 Preset
|
|
@@ -77,10 +77,14 @@ export const ConstructivePreset = {
|
|
|
77
77
|
uploadFieldDefinitions: constructiveUploadFieldDefinitions,
|
|
78
78
|
maxFileSize: 10 * 1024 * 1024, // 10MB
|
|
79
79
|
}),
|
|
80
|
-
PresignedUrlPreset({
|
|
80
|
+
PresignedUrlPreset({
|
|
81
|
+
s3: getPresignedUrlS3Config,
|
|
82
|
+
resolveBucketName: createBucketNameResolver(),
|
|
83
|
+
ensureBucketProvisioned: createEnsureBucketProvisioned(),
|
|
84
|
+
}),
|
|
81
85
|
BucketProvisionerPreset({
|
|
82
86
|
connection: getBucketProvisionerConnection,
|
|
83
|
-
allowedOrigins:
|
|
87
|
+
allowedOrigins: getAllowedOrigins(),
|
|
84
88
|
}),
|
|
85
89
|
SqlExpressionValidatorPreset(),
|
|
86
90
|
PgTypeMappingsPreset,
|
|
@@ -5,14 +5,55 @@
|
|
|
5
5
|
* (getEnvOptions → pgpmDefaults + config files + env vars) and lazily
|
|
6
6
|
* initializes an S3Client on first use.
|
|
7
7
|
*
|
|
8
|
+
* Also provides a per-database bucket name resolver that derives the
|
|
9
|
+
* S3 bucket name from the database UUID + a configurable prefix.
|
|
10
|
+
*
|
|
8
11
|
* Follows the same lazy-init pattern as upload-resolver.ts.
|
|
9
12
|
*/
|
|
10
|
-
import type { S3Config } from 'graphile-presigned-url-plugin';
|
|
13
|
+
import type { S3Config, BucketNameResolver, EnsureBucketProvisioned } from 'graphile-presigned-url-plugin';
|
|
11
14
|
/**
|
|
12
15
|
* Lazily initialize and return the S3Config for the presigned URL plugin.
|
|
13
16
|
*
|
|
14
17
|
* Reads CDN config on first call via getEnvOptions() (which already merges
|
|
15
18
|
* pgpmDefaults → config file → env vars), creates an S3Client, and caches
|
|
16
19
|
* the result. Same CDN config as upload-resolver.ts.
|
|
20
|
+
*
|
|
21
|
+
* NOTE: The `bucket` field here is the global fallback bucket name
|
|
22
|
+
* (from BUCKET_NAME env var). When `resolveBucketName` is provided,
|
|
23
|
+
* per-database bucket names take precedence for all S3 operations.
|
|
17
24
|
*/
|
|
18
25
|
export declare function getPresignedUrlS3Config(): S3Config;
|
|
26
|
+
/**
|
|
27
|
+
* Create a per-database bucket name resolver.
|
|
28
|
+
*
|
|
29
|
+
* Uses the BUCKET_NAME env var as a prefix. For each database, the S3 bucket
|
|
30
|
+
* name becomes `{prefix}-{databaseId}` (e.g., "myapp-abc123def456").
|
|
31
|
+
*
|
|
32
|
+
* In local development with MinIO (default BUCKET_NAME="test-bucket"),
|
|
33
|
+
* all databases share the same bucket for simplicity — the resolver
|
|
34
|
+
* returns the prefix as-is when it looks like a local dev bucket.
|
|
35
|
+
*
|
|
36
|
+
* In production, set BUCKET_NAME to your org prefix (e.g., "myapp")
|
|
37
|
+
* and each database gets its own isolated S3 bucket.
|
|
38
|
+
*/
|
|
39
|
+
export declare function createBucketNameResolver(): BucketNameResolver;
|
|
40
|
+
/**
|
|
41
|
+
* Resolve CORS allowed origins from the env/config system.
|
|
42
|
+
*
|
|
43
|
+
* Reads SERVER_ORIGIN from the standard env hierarchy
|
|
44
|
+
* (pgpmDefaults → config file → env vars) and wraps it in an array.
|
|
45
|
+
* Falls back to ['http://localhost:3000'] for local development.
|
|
46
|
+
*/
|
|
47
|
+
export declare function getAllowedOrigins(): string[];
|
|
48
|
+
/**
|
|
49
|
+
* Create a lazy bucket provisioner callback for the presigned URL plugin.
|
|
50
|
+
*
|
|
51
|
+
* On the first upload to an S3 bucket that doesn't exist yet, this callback
|
|
52
|
+
* uses the BucketProvisioner to create and fully configure the bucket
|
|
53
|
+
* (Block Public Access, CORS, policies, lifecycle rules for temp buckets).
|
|
54
|
+
*
|
|
55
|
+
* Uses the same S3 connection config as the bucket provisioner plugin
|
|
56
|
+
* (getBucketProvisionerConnection) and reads CORS origins from
|
|
57
|
+
* SERVER_ORIGIN env var (falls back to localhost for local dev).
|
|
58
|
+
*/
|
|
59
|
+
export declare function createEnsureBucketProvisioned(): EnsureBucketProvisioned;
|
|
@@ -5,11 +5,16 @@
|
|
|
5
5
|
* (getEnvOptions → pgpmDefaults + config files + env vars) and lazily
|
|
6
6
|
* initializes an S3Client on first use.
|
|
7
7
|
*
|
|
8
|
+
* Also provides a per-database bucket name resolver that derives the
|
|
9
|
+
* S3 bucket name from the database UUID + a configurable prefix.
|
|
10
|
+
*
|
|
8
11
|
* Follows the same lazy-init pattern as upload-resolver.ts.
|
|
9
12
|
*/
|
|
10
13
|
import { S3Client } from '@aws-sdk/client-s3';
|
|
11
14
|
import { getEnvOptions } from '@constructive-io/graphql-env';
|
|
12
15
|
import { Logger } from '@pgpmjs/logger';
|
|
16
|
+
import { BucketProvisioner } from '@constructive-io/bucket-provisioner';
|
|
17
|
+
import { getBucketProvisionerConnection } from './bucket-provisioner-resolver';
|
|
13
18
|
const log = new Logger('presigned-url-resolver');
|
|
14
19
|
let s3Config = null;
|
|
15
20
|
/**
|
|
@@ -18,6 +23,10 @@ let s3Config = null;
|
|
|
18
23
|
* Reads CDN config on first call via getEnvOptions() (which already merges
|
|
19
24
|
* pgpmDefaults → config file → env vars), creates an S3Client, and caches
|
|
20
25
|
* the result. Same CDN config as upload-resolver.ts.
|
|
26
|
+
*
|
|
27
|
+
* NOTE: The `bucket` field here is the global fallback bucket name
|
|
28
|
+
* (from BUCKET_NAME env var). When `resolveBucketName` is provided,
|
|
29
|
+
* per-database bucket names take precedence for all S3 operations.
|
|
21
30
|
*/
|
|
22
31
|
export function getPresignedUrlS3Config() {
|
|
23
32
|
if (s3Config)
|
|
@@ -40,3 +49,71 @@ export function getPresignedUrlS3Config() {
|
|
|
40
49
|
};
|
|
41
50
|
return s3Config;
|
|
42
51
|
}
|
|
52
|
+
/**
|
|
53
|
+
* Create a per-database bucket name resolver.
|
|
54
|
+
*
|
|
55
|
+
* Uses the BUCKET_NAME env var as a prefix. For each database, the S3 bucket
|
|
56
|
+
* name becomes `{prefix}-{databaseId}` (e.g., "myapp-abc123def456").
|
|
57
|
+
*
|
|
58
|
+
* In local development with MinIO (default BUCKET_NAME="test-bucket"),
|
|
59
|
+
* all databases share the same bucket for simplicity — the resolver
|
|
60
|
+
* returns the prefix as-is when it looks like a local dev bucket.
|
|
61
|
+
*
|
|
62
|
+
* In production, set BUCKET_NAME to your org prefix (e.g., "myapp")
|
|
63
|
+
* and each database gets its own isolated S3 bucket.
|
|
64
|
+
*/
|
|
65
|
+
export function createBucketNameResolver() {
|
|
66
|
+
const { cdn } = getEnvOptions();
|
|
67
|
+
const prefix = cdn?.bucketName || 'test-bucket';
|
|
68
|
+
return (databaseId) => {
|
|
69
|
+
return `${prefix}-${databaseId}`;
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Resolve CORS allowed origins from the env/config system.
|
|
74
|
+
*
|
|
75
|
+
* Reads SERVER_ORIGIN from the standard env hierarchy
|
|
76
|
+
* (pgpmDefaults → config file → env vars) and wraps it in an array.
|
|
77
|
+
* Falls back to ['http://localhost:3000'] for local development.
|
|
78
|
+
*/
|
|
79
|
+
export function getAllowedOrigins() {
|
|
80
|
+
const { server } = getEnvOptions();
|
|
81
|
+
if (server?.origin)
|
|
82
|
+
return [server.origin];
|
|
83
|
+
return ['*'];
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Create a lazy bucket provisioner callback for the presigned URL plugin.
|
|
87
|
+
*
|
|
88
|
+
* On the first upload to an S3 bucket that doesn't exist yet, this callback
|
|
89
|
+
* uses the BucketProvisioner to create and fully configure the bucket
|
|
90
|
+
* (Block Public Access, CORS, policies, lifecycle rules for temp buckets).
|
|
91
|
+
*
|
|
92
|
+
* Uses the same S3 connection config as the bucket provisioner plugin
|
|
93
|
+
* (getBucketProvisionerConnection) and reads CORS origins from
|
|
94
|
+
* SERVER_ORIGIN env var (falls back to localhost for local dev).
|
|
95
|
+
*/
|
|
96
|
+
export function createEnsureBucketProvisioned() {
|
|
97
|
+
let provisioner = null;
|
|
98
|
+
return async (bucketName, accessType, databaseId, allowedOrigins) => {
|
|
99
|
+
// Per-database origins from storage_module, falling back to global SERVER_ORIGIN
|
|
100
|
+
const effectiveOrigins = (allowedOrigins && allowedOrigins.length > 0)
|
|
101
|
+
? allowedOrigins
|
|
102
|
+
: getAllowedOrigins();
|
|
103
|
+
if (!provisioner) {
|
|
104
|
+
provisioner = new BucketProvisioner({
|
|
105
|
+
connection: getBucketProvisionerConnection(),
|
|
106
|
+
allowedOrigins: effectiveOrigins,
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
log.info(`[lazy-provision] Provisioning S3 bucket "${bucketName}" ` +
|
|
110
|
+
`(type=${accessType}) for database ${databaseId}`);
|
|
111
|
+
await provisioner.provision({
|
|
112
|
+
bucketName,
|
|
113
|
+
accessType,
|
|
114
|
+
versioning: false,
|
|
115
|
+
allowedOrigins: effectiveOrigins,
|
|
116
|
+
});
|
|
117
|
+
log.info(`[lazy-provision] S3 bucket "${bucketName}" provisioned successfully`);
|
|
118
|
+
};
|
|
119
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "graphile-settings",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.20.0",
|
|
4
4
|
"author": "Constructive <developers@constructive.io>",
|
|
5
5
|
"description": "graphile settings",
|
|
6
6
|
"main": "index.js",
|
|
@@ -30,6 +30,7 @@
|
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"@aws-sdk/client-s3": "^3.1009.0",
|
|
33
|
+
"@constructive-io/bucket-provisioner": "^0.2.0",
|
|
33
34
|
"@constructive-io/graphql-env": "^3.5.4",
|
|
34
35
|
"@constructive-io/graphql-types": "^3.4.4",
|
|
35
36
|
"@constructive-io/s3-streamer": "^2.17.4",
|
|
@@ -48,10 +49,10 @@
|
|
|
48
49
|
"graphile-build": "5.0.0",
|
|
49
50
|
"graphile-build-pg": "5.0.0",
|
|
50
51
|
"graphile-config": "1.0.0",
|
|
51
|
-
"graphile-connection-filter": "^1.
|
|
52
|
-
"graphile-postgis": "^2.
|
|
53
|
-
"graphile-presigned-url-plugin": "^0.
|
|
54
|
-
"graphile-search": "^1.
|
|
52
|
+
"graphile-connection-filter": "^1.4.0",
|
|
53
|
+
"graphile-postgis": "^2.10.0",
|
|
54
|
+
"graphile-presigned-url-plugin": "^0.4.0",
|
|
55
|
+
"graphile-search": "^1.6.0",
|
|
55
56
|
"graphile-sql-expression-validator": "^2.6.2",
|
|
56
57
|
"graphile-upload-plugin": "^2.5.2",
|
|
57
58
|
"graphile-utils": "5.0.0",
|
|
@@ -70,10 +71,10 @@
|
|
|
70
71
|
"@types/express": "^5.0.6",
|
|
71
72
|
"@types/pg": "^8.18.0",
|
|
72
73
|
"@types/request-ip": "^0.0.41",
|
|
73
|
-
"graphile-test": "^4.
|
|
74
|
+
"graphile-test": "^4.8.0",
|
|
74
75
|
"makage": "^0.3.0",
|
|
75
76
|
"nodemon": "^3.1.14",
|
|
76
|
-
"pgsql-test": "^4.
|
|
77
|
+
"pgsql-test": "^4.8.0",
|
|
77
78
|
"ts-node": "^10.9.2"
|
|
78
79
|
},
|
|
79
80
|
"keywords": [
|
|
@@ -83,5 +84,5 @@
|
|
|
83
84
|
"constructive",
|
|
84
85
|
"graphql"
|
|
85
86
|
],
|
|
86
|
-
"gitHead": "
|
|
87
|
+
"gitHead": "3bf7c522cf9f9d2595750ac7cea81d470b3e6c30"
|
|
87
88
|
}
|
|
@@ -80,10 +80,14 @@ exports.ConstructivePreset = {
|
|
|
80
80
|
uploadFieldDefinitions: upload_resolver_1.constructiveUploadFieldDefinitions,
|
|
81
81
|
maxFileSize: 10 * 1024 * 1024, // 10MB
|
|
82
82
|
}),
|
|
83
|
-
(0, graphile_presigned_url_plugin_1.PresignedUrlPreset)({
|
|
83
|
+
(0, graphile_presigned_url_plugin_1.PresignedUrlPreset)({
|
|
84
|
+
s3: presigned_url_resolver_1.getPresignedUrlS3Config,
|
|
85
|
+
resolveBucketName: (0, presigned_url_resolver_1.createBucketNameResolver)(),
|
|
86
|
+
ensureBucketProvisioned: (0, presigned_url_resolver_1.createEnsureBucketProvisioned)(),
|
|
87
|
+
}),
|
|
84
88
|
(0, graphile_bucket_provisioner_plugin_1.BucketProvisionerPreset)({
|
|
85
89
|
connection: bucket_provisioner_resolver_1.getBucketProvisionerConnection,
|
|
86
|
-
allowedOrigins:
|
|
90
|
+
allowedOrigins: (0, presigned_url_resolver_1.getAllowedOrigins)(),
|
|
87
91
|
}),
|
|
88
92
|
(0, graphile_sql_expression_validator_1.SqlExpressionValidatorPreset)(),
|
|
89
93
|
plugins_1.PgTypeMappingsPreset,
|
|
@@ -5,14 +5,55 @@
|
|
|
5
5
|
* (getEnvOptions → pgpmDefaults + config files + env vars) and lazily
|
|
6
6
|
* initializes an S3Client on first use.
|
|
7
7
|
*
|
|
8
|
+
* Also provides a per-database bucket name resolver that derives the
|
|
9
|
+
* S3 bucket name from the database UUID + a configurable prefix.
|
|
10
|
+
*
|
|
8
11
|
* Follows the same lazy-init pattern as upload-resolver.ts.
|
|
9
12
|
*/
|
|
10
|
-
import type { S3Config } from 'graphile-presigned-url-plugin';
|
|
13
|
+
import type { S3Config, BucketNameResolver, EnsureBucketProvisioned } from 'graphile-presigned-url-plugin';
|
|
11
14
|
/**
|
|
12
15
|
* Lazily initialize and return the S3Config for the presigned URL plugin.
|
|
13
16
|
*
|
|
14
17
|
* Reads CDN config on first call via getEnvOptions() (which already merges
|
|
15
18
|
* pgpmDefaults → config file → env vars), creates an S3Client, and caches
|
|
16
19
|
* the result. Same CDN config as upload-resolver.ts.
|
|
20
|
+
*
|
|
21
|
+
* NOTE: The `bucket` field here is the global fallback bucket name
|
|
22
|
+
* (from BUCKET_NAME env var). When `resolveBucketName` is provided,
|
|
23
|
+
* per-database bucket names take precedence for all S3 operations.
|
|
17
24
|
*/
|
|
18
25
|
export declare function getPresignedUrlS3Config(): S3Config;
|
|
26
|
+
/**
|
|
27
|
+
* Create a per-database bucket name resolver.
|
|
28
|
+
*
|
|
29
|
+
* Uses the BUCKET_NAME env var as a prefix. For each database, the S3 bucket
|
|
30
|
+
* name becomes `{prefix}-{databaseId}` (e.g., "myapp-abc123def456").
|
|
31
|
+
*
|
|
32
|
+
* In local development with MinIO (default BUCKET_NAME="test-bucket"),
|
|
33
|
+
* all databases share the same bucket for simplicity — the resolver
|
|
34
|
+
* returns the prefix as-is when it looks like a local dev bucket.
|
|
35
|
+
*
|
|
36
|
+
* In production, set BUCKET_NAME to your org prefix (e.g., "myapp")
|
|
37
|
+
* and each database gets its own isolated S3 bucket.
|
|
38
|
+
*/
|
|
39
|
+
export declare function createBucketNameResolver(): BucketNameResolver;
|
|
40
|
+
/**
|
|
41
|
+
* Resolve CORS allowed origins from the env/config system.
|
|
42
|
+
*
|
|
43
|
+
* Reads SERVER_ORIGIN from the standard env hierarchy
|
|
44
|
+
* (pgpmDefaults → config file → env vars) and wraps it in an array.
|
|
45
|
+
* Falls back to ['http://localhost:3000'] for local development.
|
|
46
|
+
*/
|
|
47
|
+
export declare function getAllowedOrigins(): string[];
|
|
48
|
+
/**
|
|
49
|
+
* Create a lazy bucket provisioner callback for the presigned URL plugin.
|
|
50
|
+
*
|
|
51
|
+
* On the first upload to an S3 bucket that doesn't exist yet, this callback
|
|
52
|
+
* uses the BucketProvisioner to create and fully configure the bucket
|
|
53
|
+
* (Block Public Access, CORS, policies, lifecycle rules for temp buckets).
|
|
54
|
+
*
|
|
55
|
+
* Uses the same S3 connection config as the bucket provisioner plugin
|
|
56
|
+
* (getBucketProvisionerConnection) and reads CORS origins from
|
|
57
|
+
* SERVER_ORIGIN env var (falls back to localhost for local dev).
|
|
58
|
+
*/
|
|
59
|
+
export declare function createEnsureBucketProvisioned(): EnsureBucketProvisioned;
|
|
@@ -6,13 +6,21 @@
|
|
|
6
6
|
* (getEnvOptions → pgpmDefaults + config files + env vars) and lazily
|
|
7
7
|
* initializes an S3Client on first use.
|
|
8
8
|
*
|
|
9
|
+
* Also provides a per-database bucket name resolver that derives the
|
|
10
|
+
* S3 bucket name from the database UUID + a configurable prefix.
|
|
11
|
+
*
|
|
9
12
|
* Follows the same lazy-init pattern as upload-resolver.ts.
|
|
10
13
|
*/
|
|
11
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
15
|
exports.getPresignedUrlS3Config = getPresignedUrlS3Config;
|
|
16
|
+
exports.createBucketNameResolver = createBucketNameResolver;
|
|
17
|
+
exports.getAllowedOrigins = getAllowedOrigins;
|
|
18
|
+
exports.createEnsureBucketProvisioned = createEnsureBucketProvisioned;
|
|
13
19
|
const client_s3_1 = require("@aws-sdk/client-s3");
|
|
14
20
|
const graphql_env_1 = require("@constructive-io/graphql-env");
|
|
15
21
|
const logger_1 = require("@pgpmjs/logger");
|
|
22
|
+
const bucket_provisioner_1 = require("@constructive-io/bucket-provisioner");
|
|
23
|
+
const bucket_provisioner_resolver_1 = require("./bucket-provisioner-resolver");
|
|
16
24
|
const log = new logger_1.Logger('presigned-url-resolver');
|
|
17
25
|
let s3Config = null;
|
|
18
26
|
/**
|
|
@@ -21,6 +29,10 @@ let s3Config = null;
|
|
|
21
29
|
* Reads CDN config on first call via getEnvOptions() (which already merges
|
|
22
30
|
* pgpmDefaults → config file → env vars), creates an S3Client, and caches
|
|
23
31
|
* the result. Same CDN config as upload-resolver.ts.
|
|
32
|
+
*
|
|
33
|
+
* NOTE: The `bucket` field here is the global fallback bucket name
|
|
34
|
+
* (from BUCKET_NAME env var). When `resolveBucketName` is provided,
|
|
35
|
+
* per-database bucket names take precedence for all S3 operations.
|
|
24
36
|
*/
|
|
25
37
|
function getPresignedUrlS3Config() {
|
|
26
38
|
if (s3Config)
|
|
@@ -43,3 +55,71 @@ function getPresignedUrlS3Config() {
|
|
|
43
55
|
};
|
|
44
56
|
return s3Config;
|
|
45
57
|
}
|
|
58
|
+
/**
|
|
59
|
+
* Create a per-database bucket name resolver.
|
|
60
|
+
*
|
|
61
|
+
* Uses the BUCKET_NAME env var as a prefix. For each database, the S3 bucket
|
|
62
|
+
* name becomes `{prefix}-{databaseId}` (e.g., "myapp-abc123def456").
|
|
63
|
+
*
|
|
64
|
+
* In local development with MinIO (default BUCKET_NAME="test-bucket"),
|
|
65
|
+
* all databases share the same bucket for simplicity — the resolver
|
|
66
|
+
* returns the prefix as-is when it looks like a local dev bucket.
|
|
67
|
+
*
|
|
68
|
+
* In production, set BUCKET_NAME to your org prefix (e.g., "myapp")
|
|
69
|
+
* and each database gets its own isolated S3 bucket.
|
|
70
|
+
*/
|
|
71
|
+
function createBucketNameResolver() {
|
|
72
|
+
const { cdn } = (0, graphql_env_1.getEnvOptions)();
|
|
73
|
+
const prefix = cdn?.bucketName || 'test-bucket';
|
|
74
|
+
return (databaseId) => {
|
|
75
|
+
return `${prefix}-${databaseId}`;
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Resolve CORS allowed origins from the env/config system.
|
|
80
|
+
*
|
|
81
|
+
* Reads SERVER_ORIGIN from the standard env hierarchy
|
|
82
|
+
* (pgpmDefaults → config file → env vars) and wraps it in an array.
|
|
83
|
+
* Falls back to ['http://localhost:3000'] for local development.
|
|
84
|
+
*/
|
|
85
|
+
function getAllowedOrigins() {
|
|
86
|
+
const { server } = (0, graphql_env_1.getEnvOptions)();
|
|
87
|
+
if (server?.origin)
|
|
88
|
+
return [server.origin];
|
|
89
|
+
return ['*'];
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Create a lazy bucket provisioner callback for the presigned URL plugin.
|
|
93
|
+
*
|
|
94
|
+
* On the first upload to an S3 bucket that doesn't exist yet, this callback
|
|
95
|
+
* uses the BucketProvisioner to create and fully configure the bucket
|
|
96
|
+
* (Block Public Access, CORS, policies, lifecycle rules for temp buckets).
|
|
97
|
+
*
|
|
98
|
+
* Uses the same S3 connection config as the bucket provisioner plugin
|
|
99
|
+
* (getBucketProvisionerConnection) and reads CORS origins from
|
|
100
|
+
* SERVER_ORIGIN env var (falls back to localhost for local dev).
|
|
101
|
+
*/
|
|
102
|
+
function createEnsureBucketProvisioned() {
|
|
103
|
+
let provisioner = null;
|
|
104
|
+
return async (bucketName, accessType, databaseId, allowedOrigins) => {
|
|
105
|
+
// Per-database origins from storage_module, falling back to global SERVER_ORIGIN
|
|
106
|
+
const effectiveOrigins = (allowedOrigins && allowedOrigins.length > 0)
|
|
107
|
+
? allowedOrigins
|
|
108
|
+
: getAllowedOrigins();
|
|
109
|
+
if (!provisioner) {
|
|
110
|
+
provisioner = new bucket_provisioner_1.BucketProvisioner({
|
|
111
|
+
connection: (0, bucket_provisioner_resolver_1.getBucketProvisionerConnection)(),
|
|
112
|
+
allowedOrigins: effectiveOrigins,
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
log.info(`[lazy-provision] Provisioning S3 bucket "${bucketName}" ` +
|
|
116
|
+
`(type=${accessType}) for database ${databaseId}`);
|
|
117
|
+
await provisioner.provision({
|
|
118
|
+
bucketName,
|
|
119
|
+
accessType,
|
|
120
|
+
versioning: false,
|
|
121
|
+
allowedOrigins: effectiveOrigins,
|
|
122
|
+
});
|
|
123
|
+
log.info(`[lazy-provision] S3 bucket "${bucketName}" provisioned successfully`);
|
|
124
|
+
};
|
|
125
|
+
}
|