graphile-settings 6.20.2 → 6.21.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/esm/index.d.ts +0 -1
- package/esm/index.js +0 -2
- package/esm/presets/constructive-preset.js +2 -9
- package/esm/presigned-url-resolver.d.ts +3 -37
- package/esm/presigned-url-resolver.js +2 -84
- package/esm/upload-resolver.js +4 -8
- package/index.d.ts +0 -1
- package/index.js +1 -4
- package/package.json +19 -19
- package/presets/constructive-preset.js +1 -8
- package/presigned-url-resolver.d.ts +3 -37
- package/presigned-url-resolver.js +2 -87
- package/upload-resolver.js +3 -7
- package/bucket-provisioner-resolver.d.ts +0 -19
- package/bucket-provisioner-resolver.js +0 -48
- package/esm/bucket-provisioner-resolver.d.ts +0 -19
- package/esm/bucket-provisioner-resolver.js +0 -45
package/esm/index.d.ts
CHANGED
package/esm/index.js
CHANGED
|
@@ -46,5 +46,3 @@ export * from './presets/index';
|
|
|
46
46
|
export { makePgService };
|
|
47
47
|
// Presigned URL utilities
|
|
48
48
|
export { getPresignedUrlS3Config } from './presigned-url-resolver';
|
|
49
|
-
// Bucket provisioner utilities
|
|
50
|
-
export { getBucketProvisionerConnection } from './bucket-provisioner-resolver';
|
|
@@ -11,9 +11,8 @@ import { PresignedUrlPreset } from 'graphile-presigned-url-plugin';
|
|
|
11
11
|
import { RealtimeSubscriptionsPreset } from 'graphile-realtime-subscriptions';
|
|
12
12
|
import { createMatchesOperatorFactory, createTrgmOperatorFactories, UnifiedSearchPreset } from 'graphile-search';
|
|
13
13
|
import { UploadPreset } from 'graphile-upload-plugin';
|
|
14
|
-
import { getBucketProvisionerConnection } from '../bucket-provisioner-resolver';
|
|
15
14
|
import { ConflictDetectorPreset, EnableAllFilterColumnsPreset, InflectorLoggerPreset, InflektPreset, ManyToManyOptInPreset, MetaSchemaPreset, MinimalPreset, NoUniqueLookupPreset, PgTypeMappingsPreset, RequiredInputPreset } from '../plugins';
|
|
16
|
-
import {
|
|
15
|
+
import { getPresignedUrlS3Config } from '../presigned-url-resolver';
|
|
17
16
|
import { constructiveUploadFieldDefinitions } from '../upload-resolver';
|
|
18
17
|
/**
|
|
19
18
|
* grafast / @dataplan/pg require Node >= 22 (they call Promise.withResolvers()
|
|
@@ -140,13 +139,7 @@ export function createConstructivePreset(options) {
|
|
|
140
139
|
if (opts.enablePresignedUploads) {
|
|
141
140
|
presets.push(PresignedUrlPreset({
|
|
142
141
|
s3: getPresignedUrlS3Config,
|
|
143
|
-
|
|
144
|
-
ensureBucketProvisioned: createEnsureBucketProvisioned()
|
|
145
|
-
}), BucketProvisionerPreset({
|
|
146
|
-
connection: getBucketProvisionerConnection,
|
|
147
|
-
allowedOrigins: getAllowedOrigins(),
|
|
148
|
-
resolveBucketName: createBucketNameResolver()
|
|
149
|
-
}));
|
|
142
|
+
}), BucketProvisionerPreset());
|
|
150
143
|
}
|
|
151
144
|
if (opts.enableAggregates) {
|
|
152
145
|
presets.push(PgAggregatesPreset);
|
|
@@ -5,12 +5,9 @@
|
|
|
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
|
-
*
|
|
11
8
|
* Follows the same lazy-init pattern as upload-resolver.ts.
|
|
12
9
|
*/
|
|
13
|
-
import type {
|
|
10
|
+
import type { S3Config } from 'graphile-presigned-url-plugin';
|
|
14
11
|
/**
|
|
15
12
|
* Lazily initialize and return the S3Config for the presigned URL plugin.
|
|
16
13
|
*
|
|
@@ -20,38 +17,7 @@ import type { BucketNameResolver, EnsureBucketProvisioned, S3Config } from 'grap
|
|
|
20
17
|
*
|
|
21
18
|
* NOTE: The `bucket` field here is only the connection's default and is never
|
|
22
19
|
* uploaded to. Every managed upload names its bucket explicitly, resolved from
|
|
23
|
-
* the tenant's logical bucket row
|
|
24
|
-
*
|
|
20
|
+
* the tenant's logical bucket row; there is no environment-global upload
|
|
21
|
+
* bucket.
|
|
25
22
|
*/
|
|
26
23
|
export declare function getPresignedUrlS3Config(): S3Config;
|
|
27
|
-
/**
|
|
28
|
-
* Create a per-(database, bucketKey) bucket name resolver for the presigned
|
|
29
|
-
* URL plugin (argument order: `(databaseId, bucketKey)`).
|
|
30
|
-
*
|
|
31
|
-
* Uses CDN_BUCKET_NAME as a prefix. For each (database, bucketKey) pair, the
|
|
32
|
-
* S3 bucket name becomes `{prefix}-{bucketKey}-{digest}`.
|
|
33
|
-
*
|
|
34
|
-
* This aligns with the bucket provisioner plugin which creates separate
|
|
35
|
-
* S3 buckets per logical bucket key.
|
|
36
|
-
*/
|
|
37
|
-
export declare function createBucketNameResolver(): BucketNameResolver;
|
|
38
|
-
/**
|
|
39
|
-
* Resolve CORS allowed origins from the env/config system.
|
|
40
|
-
*
|
|
41
|
-
* Reads SERVER_ORIGIN from the standard env hierarchy
|
|
42
|
-
* (pgpmDefaults → config file → env vars) and wraps it in an array.
|
|
43
|
-
* Falls back to ['http://localhost:3000'] for local development.
|
|
44
|
-
*/
|
|
45
|
-
export declare function getAllowedOrigins(): string[];
|
|
46
|
-
/**
|
|
47
|
-
* Create a lazy bucket provisioner callback for the presigned URL plugin.
|
|
48
|
-
*
|
|
49
|
-
* On the first upload to an S3 bucket that doesn't exist yet, this callback
|
|
50
|
-
* uses the BucketProvisioner to create and fully configure the bucket
|
|
51
|
-
* (Block Public Access, CORS, policies, lifecycle rules for temp buckets).
|
|
52
|
-
*
|
|
53
|
-
* Uses the same S3 connection config as the bucket provisioner plugin
|
|
54
|
-
* (getBucketProvisionerConnection) and reads CORS origins from
|
|
55
|
-
* SERVER_ORIGIN env var (falls back to localhost for local dev).
|
|
56
|
-
*/
|
|
57
|
-
export declare function createEnsureBucketProvisioned(): EnsureBucketProvisioned;
|
|
@@ -5,16 +5,11 @@
|
|
|
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
|
-
*
|
|
11
8
|
* Follows the same lazy-init pattern as upload-resolver.ts.
|
|
12
9
|
*/
|
|
13
|
-
import { BucketProvisioner, mintPhysicalBucketName } from '@constructive-io/bucket-provisioner';
|
|
14
10
|
import { getEnvOptions } from '@constructive-io/graphql-env';
|
|
15
11
|
import { createS3Client } from '@constructive-io/s3-utils';
|
|
16
12
|
import { Logger } from '@pgpmjs/logger';
|
|
17
|
-
import { getBucketProvisionerConnection } from './bucket-provisioner-resolver';
|
|
18
13
|
const log = new Logger('presigned-url-resolver');
|
|
19
14
|
let s3Config = null;
|
|
20
15
|
/**
|
|
@@ -26,8 +21,8 @@ let s3Config = null;
|
|
|
26
21
|
*
|
|
27
22
|
* NOTE: The `bucket` field here is only the connection's default and is never
|
|
28
23
|
* uploaded to. Every managed upload names its bucket explicitly, resolved from
|
|
29
|
-
* the tenant's logical bucket row
|
|
30
|
-
*
|
|
24
|
+
* the tenant's logical bucket row; there is no environment-global upload
|
|
25
|
+
* bucket.
|
|
31
26
|
*/
|
|
32
27
|
export function getPresignedUrlS3Config() {
|
|
33
28
|
if (s3Config)
|
|
@@ -64,80 +59,3 @@ export function getPresignedUrlS3Config() {
|
|
|
64
59
|
};
|
|
65
60
|
return s3Config;
|
|
66
61
|
}
|
|
67
|
-
/**
|
|
68
|
-
* Read the configured physical-bucket-name prefix (CDN_BUCKET_NAME).
|
|
69
|
-
*
|
|
70
|
-
* There is no default: a missing prefix throws, mirroring
|
|
71
|
-
* getPresignedUrlS3Config, so an untenanted bucket name can never be minted.
|
|
72
|
-
*/
|
|
73
|
-
function getBucketNamePrefix() {
|
|
74
|
-
const { cdn } = getEnvOptions();
|
|
75
|
-
const prefix = cdn?.bucketName;
|
|
76
|
-
if (!prefix) {
|
|
77
|
-
throw new Error('[presigned-url-resolver] Missing CDN bucket name prefix. ' +
|
|
78
|
-
'Set CDN_BUCKET_NAME environment variable; there is no default bucket name.');
|
|
79
|
-
}
|
|
80
|
-
return prefix;
|
|
81
|
-
}
|
|
82
|
-
/**
|
|
83
|
-
* Create a per-(database, bucketKey) bucket name resolver for the presigned
|
|
84
|
-
* URL plugin (argument order: `(databaseId, bucketKey)`).
|
|
85
|
-
*
|
|
86
|
-
* Uses CDN_BUCKET_NAME as a prefix. For each (database, bucketKey) pair, the
|
|
87
|
-
* S3 bucket name becomes `{prefix}-{bucketKey}-{digest}`.
|
|
88
|
-
*
|
|
89
|
-
* This aligns with the bucket provisioner plugin which creates separate
|
|
90
|
-
* S3 buckets per logical bucket key.
|
|
91
|
-
*/
|
|
92
|
-
export function createBucketNameResolver() {
|
|
93
|
-
const prefix = getBucketNamePrefix();
|
|
94
|
-
return (databaseId, bucketKey) => mintPhysicalBucketName(prefix, databaseId, bucketKey);
|
|
95
|
-
}
|
|
96
|
-
/**
|
|
97
|
-
* Resolve CORS allowed origins from the env/config system.
|
|
98
|
-
*
|
|
99
|
-
* Reads SERVER_ORIGIN from the standard env hierarchy
|
|
100
|
-
* (pgpmDefaults → config file → env vars) and wraps it in an array.
|
|
101
|
-
* Falls back to ['http://localhost:3000'] for local development.
|
|
102
|
-
*/
|
|
103
|
-
export function getAllowedOrigins() {
|
|
104
|
-
const { server } = getEnvOptions();
|
|
105
|
-
if (server?.origin)
|
|
106
|
-
return [server.origin];
|
|
107
|
-
return ['*'];
|
|
108
|
-
}
|
|
109
|
-
/**
|
|
110
|
-
* Create a lazy bucket provisioner callback for the presigned URL plugin.
|
|
111
|
-
*
|
|
112
|
-
* On the first upload to an S3 bucket that doesn't exist yet, this callback
|
|
113
|
-
* uses the BucketProvisioner to create and fully configure the bucket
|
|
114
|
-
* (Block Public Access, CORS, policies, lifecycle rules for temp buckets).
|
|
115
|
-
*
|
|
116
|
-
* Uses the same S3 connection config as the bucket provisioner plugin
|
|
117
|
-
* (getBucketProvisionerConnection) and reads CORS origins from
|
|
118
|
-
* SERVER_ORIGIN env var (falls back to localhost for local dev).
|
|
119
|
-
*/
|
|
120
|
-
export function createEnsureBucketProvisioned() {
|
|
121
|
-
let provisioner = null;
|
|
122
|
-
return async (bucketName, accessType, databaseId, allowedOrigins) => {
|
|
123
|
-
// Per-database origins from storage_module, falling back to global SERVER_ORIGIN
|
|
124
|
-
const effectiveOrigins = (allowedOrigins && allowedOrigins.length > 0)
|
|
125
|
-
? allowedOrigins
|
|
126
|
-
: getAllowedOrigins();
|
|
127
|
-
if (!provisioner) {
|
|
128
|
-
provisioner = new BucketProvisioner({
|
|
129
|
-
connection: getBucketProvisionerConnection(),
|
|
130
|
-
allowedOrigins: effectiveOrigins,
|
|
131
|
-
});
|
|
132
|
-
}
|
|
133
|
-
log.info(`[lazy-provision] Provisioning S3 bucket "${bucketName}" ` +
|
|
134
|
-
`(type=${accessType}) for database ${databaseId}`);
|
|
135
|
-
await provisioner.provision({
|
|
136
|
-
bucketName,
|
|
137
|
-
accessType,
|
|
138
|
-
versioning: false,
|
|
139
|
-
allowedOrigins: effectiveOrigins,
|
|
140
|
-
});
|
|
141
|
-
log.info(`[lazy-provision] S3 bucket "${bucketName}" provisioned successfully`);
|
|
142
|
-
};
|
|
143
|
-
}
|
package/esm/upload-resolver.js
CHANGED
|
@@ -31,7 +31,7 @@ import { createHash, randomUUID } from 'crypto';
|
|
|
31
31
|
import { finalizeStagedUpload, resolveManagedUploadTarget, withRequestPgClient, } from 'graphile-presigned-url-plugin';
|
|
32
32
|
import { checkTypeAgreement } from 'mime-bytes';
|
|
33
33
|
import { Transform } from 'stream';
|
|
34
|
-
import {
|
|
34
|
+
import { getPresignedUrlS3Config } from './presigned-url-resolver';
|
|
35
35
|
const log = new Logger('upload-resolver');
|
|
36
36
|
const DEFAULT_IMAGE_MIME_TYPES = ['image/jpeg', 'image/png', 'image/svg+xml'];
|
|
37
37
|
let streamer = null;
|
|
@@ -62,20 +62,16 @@ function getStreamer() {
|
|
|
62
62
|
}
|
|
63
63
|
/**
|
|
64
64
|
* The upload lane's view of the presigned plugin's options: the same S3
|
|
65
|
-
* connection
|
|
66
|
-
*
|
|
65
|
+
* connection the presigned lane uses, so both transports resolve identical
|
|
66
|
+
* coordinates for a bucket.
|
|
67
67
|
*
|
|
68
|
-
* Built on first upload rather than at import time
|
|
69
|
-
* throws on a missing name prefix, and that must surface as a failed upload, not
|
|
70
|
-
* as a server that will not boot.
|
|
68
|
+
* Built on first upload rather than at import time.
|
|
71
69
|
*/
|
|
72
70
|
let managedOptions = null;
|
|
73
71
|
function getManagedOptions() {
|
|
74
72
|
if (!managedOptions) {
|
|
75
73
|
managedOptions = {
|
|
76
74
|
s3: getPresignedUrlS3Config,
|
|
77
|
-
resolveBucketName: createBucketNameResolver(),
|
|
78
|
-
ensureBucketProvisioned: createEnsureBucketProvisioned(),
|
|
79
75
|
};
|
|
80
76
|
}
|
|
81
77
|
return managedOptions;
|
package/index.d.ts
CHANGED
package/index.js
CHANGED
|
@@ -42,7 +42,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
42
42
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
43
43
|
};
|
|
44
44
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
45
|
-
exports.
|
|
45
|
+
exports.getPresignedUrlS3Config = exports.makePgService = exports.createConstructivePreset = exports.ConstructivePreset = void 0;
|
|
46
46
|
// Import modules for type augmentation
|
|
47
47
|
// These add properties to the GraphileConfig.Preset interface:
|
|
48
48
|
// - grafserv: adds 'grafserv' property
|
|
@@ -62,6 +62,3 @@ __exportStar(require("./presets/index"), exports);
|
|
|
62
62
|
// Presigned URL utilities
|
|
63
63
|
var presigned_url_resolver_1 = require("./presigned-url-resolver");
|
|
64
64
|
Object.defineProperty(exports, "getPresignedUrlS3Config", { enumerable: true, get: function () { return presigned_url_resolver_1.getPresignedUrlS3Config; } });
|
|
65
|
-
// Bucket provisioner utilities
|
|
66
|
-
var bucket_provisioner_resolver_1 = require("./bucket-provisioner-resolver");
|
|
67
|
-
Object.defineProperty(exports, "getBucketProvisionerConnection", { enumerable: true, get: function () { return bucket_provisioner_resolver_1.getBucketProvisionerConnection; } });
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "graphile-settings",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.21.0",
|
|
4
4
|
"author": "Constructive <developers@constructive.io>",
|
|
5
5
|
"description": "graphile settings",
|
|
6
6
|
"main": "index.js",
|
|
@@ -30,38 +30,38 @@
|
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"@aws-sdk/client-s3": "^3.1052.0",
|
|
33
|
-
"@constructive-io/bucket-provisioner": "^0.
|
|
34
|
-
"@constructive-io/graphql-env": "^3.31.
|
|
35
|
-
"@constructive-io/graphql-types": "^3.30.
|
|
36
|
-
"@constructive-io/s3-streamer": "^2.42.
|
|
33
|
+
"@constructive-io/bucket-provisioner": "^0.27.0",
|
|
34
|
+
"@constructive-io/graphql-env": "^3.31.1",
|
|
35
|
+
"@constructive-io/graphql-types": "^3.30.1",
|
|
36
|
+
"@constructive-io/s3-streamer": "^2.42.1",
|
|
37
37
|
"@constructive-io/s3-utils": "^2.32.0",
|
|
38
38
|
"@constructive-io/upload-names": "^2.30.0",
|
|
39
39
|
"@dataplan/json": "1.0.1",
|
|
40
40
|
"@dataplan/pg": "1.1.1",
|
|
41
41
|
"@graphile-contrib/pg-many-to-many": "2.0.0-rc.2",
|
|
42
42
|
"@pgpmjs/logger": "^2.25.0",
|
|
43
|
-
"@pgpmjs/types": "^2.52.
|
|
43
|
+
"@pgpmjs/types": "^2.52.1",
|
|
44
44
|
"@pgsql/quotes": "^18.2.4",
|
|
45
45
|
"cors": "^2.8.6",
|
|
46
46
|
"express": "^5.2.1",
|
|
47
47
|
"grafast": "1.1.2",
|
|
48
48
|
"grafserv": "1.0.1",
|
|
49
|
-
"graphile-bucket-provisioner-plugin": "1.
|
|
49
|
+
"graphile-bucket-provisioner-plugin": "1.15.0",
|
|
50
50
|
"graphile-build": "5.1.1",
|
|
51
51
|
"graphile-build-pg": "5.1.3",
|
|
52
|
-
"graphile-bulk-mutations": "^1.14.
|
|
52
|
+
"graphile-bulk-mutations": "^1.14.1",
|
|
53
53
|
"graphile-config": "1.1.0",
|
|
54
|
-
"graphile-connection-filter": "^2.14.
|
|
55
|
-
"graphile-history": "^1.6.
|
|
56
|
-
"graphile-i18n": "^2.14.
|
|
57
|
-
"graphile-llm": "^1.15.
|
|
58
|
-
"graphile-ltree": "^2.14.
|
|
54
|
+
"graphile-connection-filter": "^2.14.1",
|
|
55
|
+
"graphile-history": "^1.6.1",
|
|
56
|
+
"graphile-i18n": "^2.14.1",
|
|
57
|
+
"graphile-llm": "^1.15.1",
|
|
58
|
+
"graphile-ltree": "^2.14.1",
|
|
59
59
|
"graphile-meta": "^1.9.1",
|
|
60
|
-
"graphile-pg-aggregates": "^2.14.
|
|
61
|
-
"graphile-postgis": "^3.15.
|
|
62
|
-
"graphile-presigned-url-plugin": "^1.
|
|
60
|
+
"graphile-pg-aggregates": "^2.14.1",
|
|
61
|
+
"graphile-postgis": "^3.15.1",
|
|
62
|
+
"graphile-presigned-url-plugin": "^1.18.0",
|
|
63
63
|
"graphile-realtime-subscriptions": "^1.11.0",
|
|
64
|
-
"graphile-search": "^2.14.
|
|
64
|
+
"graphile-search": "^2.14.1",
|
|
65
65
|
"graphile-upload-plugin": "^2.26.0",
|
|
66
66
|
"graphile-utils": "5.0.3",
|
|
67
67
|
"graphql": "16.13.0",
|
|
@@ -80,7 +80,7 @@
|
|
|
80
80
|
"@types/express": "^5.0.6",
|
|
81
81
|
"@types/pg": "^8.20.4",
|
|
82
82
|
"@types/request-ip": "^0.0.41",
|
|
83
|
-
"graphile-test": "^5.14.
|
|
83
|
+
"graphile-test": "^5.14.1",
|
|
84
84
|
"makage": "^0.3.0",
|
|
85
85
|
"nodemon": "^3.1.14",
|
|
86
86
|
"ts-node": "^10.9.2"
|
|
@@ -92,5 +92,5 @@
|
|
|
92
92
|
"constructive",
|
|
93
93
|
"graphql"
|
|
94
94
|
],
|
|
95
|
-
"gitHead": "
|
|
95
|
+
"gitHead": "77d58bb93796be91d4e00156bb6847392584d3bc"
|
|
96
96
|
}
|
|
@@ -15,7 +15,6 @@ const graphile_presigned_url_plugin_1 = require("graphile-presigned-url-plugin")
|
|
|
15
15
|
const graphile_realtime_subscriptions_1 = require("graphile-realtime-subscriptions");
|
|
16
16
|
const graphile_search_1 = require("graphile-search");
|
|
17
17
|
const graphile_upload_plugin_1 = require("graphile-upload-plugin");
|
|
18
|
-
const bucket_provisioner_resolver_1 = require("../bucket-provisioner-resolver");
|
|
19
18
|
const plugins_1 = require("../plugins");
|
|
20
19
|
const presigned_url_resolver_1 = require("../presigned-url-resolver");
|
|
21
20
|
const upload_resolver_1 = require("../upload-resolver");
|
|
@@ -144,13 +143,7 @@ function createConstructivePreset(options) {
|
|
|
144
143
|
if (opts.enablePresignedUploads) {
|
|
145
144
|
presets.push((0, graphile_presigned_url_plugin_1.PresignedUrlPreset)({
|
|
146
145
|
s3: presigned_url_resolver_1.getPresignedUrlS3Config,
|
|
147
|
-
|
|
148
|
-
ensureBucketProvisioned: (0, presigned_url_resolver_1.createEnsureBucketProvisioned)()
|
|
149
|
-
}), (0, graphile_bucket_provisioner_plugin_1.BucketProvisionerPreset)({
|
|
150
|
-
connection: bucket_provisioner_resolver_1.getBucketProvisionerConnection,
|
|
151
|
-
allowedOrigins: (0, presigned_url_resolver_1.getAllowedOrigins)(),
|
|
152
|
-
resolveBucketName: (0, presigned_url_resolver_1.createBucketNameResolver)()
|
|
153
|
-
}));
|
|
146
|
+
}), (0, graphile_bucket_provisioner_plugin_1.BucketProvisionerPreset)());
|
|
154
147
|
}
|
|
155
148
|
if (opts.enableAggregates) {
|
|
156
149
|
presets.push(graphile_pg_aggregates_1.PgAggregatesPreset);
|
|
@@ -5,12 +5,9 @@
|
|
|
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
|
-
*
|
|
11
8
|
* Follows the same lazy-init pattern as upload-resolver.ts.
|
|
12
9
|
*/
|
|
13
|
-
import type {
|
|
10
|
+
import type { S3Config } from 'graphile-presigned-url-plugin';
|
|
14
11
|
/**
|
|
15
12
|
* Lazily initialize and return the S3Config for the presigned URL plugin.
|
|
16
13
|
*
|
|
@@ -20,38 +17,7 @@ import type { BucketNameResolver, EnsureBucketProvisioned, S3Config } from 'grap
|
|
|
20
17
|
*
|
|
21
18
|
* NOTE: The `bucket` field here is only the connection's default and is never
|
|
22
19
|
* uploaded to. Every managed upload names its bucket explicitly, resolved from
|
|
23
|
-
* the tenant's logical bucket row
|
|
24
|
-
*
|
|
20
|
+
* the tenant's logical bucket row; there is no environment-global upload
|
|
21
|
+
* bucket.
|
|
25
22
|
*/
|
|
26
23
|
export declare function getPresignedUrlS3Config(): S3Config;
|
|
27
|
-
/**
|
|
28
|
-
* Create a per-(database, bucketKey) bucket name resolver for the presigned
|
|
29
|
-
* URL plugin (argument order: `(databaseId, bucketKey)`).
|
|
30
|
-
*
|
|
31
|
-
* Uses CDN_BUCKET_NAME as a prefix. For each (database, bucketKey) pair, the
|
|
32
|
-
* S3 bucket name becomes `{prefix}-{bucketKey}-{digest}`.
|
|
33
|
-
*
|
|
34
|
-
* This aligns with the bucket provisioner plugin which creates separate
|
|
35
|
-
* S3 buckets per logical bucket key.
|
|
36
|
-
*/
|
|
37
|
-
export declare function createBucketNameResolver(): BucketNameResolver;
|
|
38
|
-
/**
|
|
39
|
-
* Resolve CORS allowed origins from the env/config system.
|
|
40
|
-
*
|
|
41
|
-
* Reads SERVER_ORIGIN from the standard env hierarchy
|
|
42
|
-
* (pgpmDefaults → config file → env vars) and wraps it in an array.
|
|
43
|
-
* Falls back to ['http://localhost:3000'] for local development.
|
|
44
|
-
*/
|
|
45
|
-
export declare function getAllowedOrigins(): string[];
|
|
46
|
-
/**
|
|
47
|
-
* Create a lazy bucket provisioner callback for the presigned URL plugin.
|
|
48
|
-
*
|
|
49
|
-
* On the first upload to an S3 bucket that doesn't exist yet, this callback
|
|
50
|
-
* uses the BucketProvisioner to create and fully configure the bucket
|
|
51
|
-
* (Block Public Access, CORS, policies, lifecycle rules for temp buckets).
|
|
52
|
-
*
|
|
53
|
-
* Uses the same S3 connection config as the bucket provisioner plugin
|
|
54
|
-
* (getBucketProvisionerConnection) and reads CORS origins from
|
|
55
|
-
* SERVER_ORIGIN env var (falls back to localhost for local dev).
|
|
56
|
-
*/
|
|
57
|
-
export declare function createEnsureBucketProvisioned(): EnsureBucketProvisioned;
|
|
@@ -6,21 +6,13 @@
|
|
|
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
|
-
*
|
|
12
9
|
* Follows the same lazy-init pattern as upload-resolver.ts.
|
|
13
10
|
*/
|
|
14
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
12
|
exports.getPresignedUrlS3Config = getPresignedUrlS3Config;
|
|
16
|
-
exports.createBucketNameResolver = createBucketNameResolver;
|
|
17
|
-
exports.getAllowedOrigins = getAllowedOrigins;
|
|
18
|
-
exports.createEnsureBucketProvisioned = createEnsureBucketProvisioned;
|
|
19
|
-
const bucket_provisioner_1 = require("@constructive-io/bucket-provisioner");
|
|
20
13
|
const graphql_env_1 = require("@constructive-io/graphql-env");
|
|
21
14
|
const s3_utils_1 = require("@constructive-io/s3-utils");
|
|
22
15
|
const logger_1 = require("@pgpmjs/logger");
|
|
23
|
-
const bucket_provisioner_resolver_1 = require("./bucket-provisioner-resolver");
|
|
24
16
|
const log = new logger_1.Logger('presigned-url-resolver');
|
|
25
17
|
let s3Config = null;
|
|
26
18
|
/**
|
|
@@ -32,8 +24,8 @@ let s3Config = null;
|
|
|
32
24
|
*
|
|
33
25
|
* NOTE: The `bucket` field here is only the connection's default and is never
|
|
34
26
|
* uploaded to. Every managed upload names its bucket explicitly, resolved from
|
|
35
|
-
* the tenant's logical bucket row
|
|
36
|
-
*
|
|
27
|
+
* the tenant's logical bucket row; there is no environment-global upload
|
|
28
|
+
* bucket.
|
|
37
29
|
*/
|
|
38
30
|
function getPresignedUrlS3Config() {
|
|
39
31
|
if (s3Config)
|
|
@@ -70,80 +62,3 @@ function getPresignedUrlS3Config() {
|
|
|
70
62
|
};
|
|
71
63
|
return s3Config;
|
|
72
64
|
}
|
|
73
|
-
/**
|
|
74
|
-
* Read the configured physical-bucket-name prefix (CDN_BUCKET_NAME).
|
|
75
|
-
*
|
|
76
|
-
* There is no default: a missing prefix throws, mirroring
|
|
77
|
-
* getPresignedUrlS3Config, so an untenanted bucket name can never be minted.
|
|
78
|
-
*/
|
|
79
|
-
function getBucketNamePrefix() {
|
|
80
|
-
const { cdn } = (0, graphql_env_1.getEnvOptions)();
|
|
81
|
-
const prefix = cdn?.bucketName;
|
|
82
|
-
if (!prefix) {
|
|
83
|
-
throw new Error('[presigned-url-resolver] Missing CDN bucket name prefix. ' +
|
|
84
|
-
'Set CDN_BUCKET_NAME environment variable; there is no default bucket name.');
|
|
85
|
-
}
|
|
86
|
-
return prefix;
|
|
87
|
-
}
|
|
88
|
-
/**
|
|
89
|
-
* Create a per-(database, bucketKey) bucket name resolver for the presigned
|
|
90
|
-
* URL plugin (argument order: `(databaseId, bucketKey)`).
|
|
91
|
-
*
|
|
92
|
-
* Uses CDN_BUCKET_NAME as a prefix. For each (database, bucketKey) pair, the
|
|
93
|
-
* S3 bucket name becomes `{prefix}-{bucketKey}-{digest}`.
|
|
94
|
-
*
|
|
95
|
-
* This aligns with the bucket provisioner plugin which creates separate
|
|
96
|
-
* S3 buckets per logical bucket key.
|
|
97
|
-
*/
|
|
98
|
-
function createBucketNameResolver() {
|
|
99
|
-
const prefix = getBucketNamePrefix();
|
|
100
|
-
return (databaseId, bucketKey) => (0, bucket_provisioner_1.mintPhysicalBucketName)(prefix, databaseId, bucketKey);
|
|
101
|
-
}
|
|
102
|
-
/**
|
|
103
|
-
* Resolve CORS allowed origins from the env/config system.
|
|
104
|
-
*
|
|
105
|
-
* Reads SERVER_ORIGIN from the standard env hierarchy
|
|
106
|
-
* (pgpmDefaults → config file → env vars) and wraps it in an array.
|
|
107
|
-
* Falls back to ['http://localhost:3000'] for local development.
|
|
108
|
-
*/
|
|
109
|
-
function getAllowedOrigins() {
|
|
110
|
-
const { server } = (0, graphql_env_1.getEnvOptions)();
|
|
111
|
-
if (server?.origin)
|
|
112
|
-
return [server.origin];
|
|
113
|
-
return ['*'];
|
|
114
|
-
}
|
|
115
|
-
/**
|
|
116
|
-
* Create a lazy bucket provisioner callback for the presigned URL plugin.
|
|
117
|
-
*
|
|
118
|
-
* On the first upload to an S3 bucket that doesn't exist yet, this callback
|
|
119
|
-
* uses the BucketProvisioner to create and fully configure the bucket
|
|
120
|
-
* (Block Public Access, CORS, policies, lifecycle rules for temp buckets).
|
|
121
|
-
*
|
|
122
|
-
* Uses the same S3 connection config as the bucket provisioner plugin
|
|
123
|
-
* (getBucketProvisionerConnection) and reads CORS origins from
|
|
124
|
-
* SERVER_ORIGIN env var (falls back to localhost for local dev).
|
|
125
|
-
*/
|
|
126
|
-
function createEnsureBucketProvisioned() {
|
|
127
|
-
let provisioner = null;
|
|
128
|
-
return async (bucketName, accessType, databaseId, allowedOrigins) => {
|
|
129
|
-
// Per-database origins from storage_module, falling back to global SERVER_ORIGIN
|
|
130
|
-
const effectiveOrigins = (allowedOrigins && allowedOrigins.length > 0)
|
|
131
|
-
? allowedOrigins
|
|
132
|
-
: getAllowedOrigins();
|
|
133
|
-
if (!provisioner) {
|
|
134
|
-
provisioner = new bucket_provisioner_1.BucketProvisioner({
|
|
135
|
-
connection: (0, bucket_provisioner_resolver_1.getBucketProvisionerConnection)(),
|
|
136
|
-
allowedOrigins: effectiveOrigins,
|
|
137
|
-
});
|
|
138
|
-
}
|
|
139
|
-
log.info(`[lazy-provision] Provisioning S3 bucket "${bucketName}" ` +
|
|
140
|
-
`(type=${accessType}) for database ${databaseId}`);
|
|
141
|
-
await provisioner.provision({
|
|
142
|
-
bucketName,
|
|
143
|
-
accessType,
|
|
144
|
-
versioning: false,
|
|
145
|
-
allowedOrigins: effectiveOrigins,
|
|
146
|
-
});
|
|
147
|
-
log.info(`[lazy-provision] S3 bucket "${bucketName}" provisioned successfully`);
|
|
148
|
-
};
|
|
149
|
-
}
|
package/upload-resolver.js
CHANGED
|
@@ -68,20 +68,16 @@ function getStreamer() {
|
|
|
68
68
|
}
|
|
69
69
|
/**
|
|
70
70
|
* The upload lane's view of the presigned plugin's options: the same S3
|
|
71
|
-
* connection
|
|
72
|
-
*
|
|
71
|
+
* connection the presigned lane uses, so both transports resolve identical
|
|
72
|
+
* coordinates for a bucket.
|
|
73
73
|
*
|
|
74
|
-
* Built on first upload rather than at import time
|
|
75
|
-
* throws on a missing name prefix, and that must surface as a failed upload, not
|
|
76
|
-
* as a server that will not boot.
|
|
74
|
+
* Built on first upload rather than at import time.
|
|
77
75
|
*/
|
|
78
76
|
let managedOptions = null;
|
|
79
77
|
function getManagedOptions() {
|
|
80
78
|
if (!managedOptions) {
|
|
81
79
|
managedOptions = {
|
|
82
80
|
s3: presigned_url_resolver_1.getPresignedUrlS3Config,
|
|
83
|
-
resolveBucketName: (0, presigned_url_resolver_1.createBucketNameResolver)(),
|
|
84
|
-
ensureBucketProvisioned: (0, presigned_url_resolver_1.createEnsureBucketProvisioned)(),
|
|
85
81
|
};
|
|
86
82
|
}
|
|
87
83
|
return managedOptions;
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Bucket provisioner resolver for the Constructive bucket provisioner plugin.
|
|
3
|
-
*
|
|
4
|
-
* Reads CDN/S3 configuration from the standard env system
|
|
5
|
-
* (getEnvOptions -> pgpmDefaults + config files + env vars) and lazily
|
|
6
|
-
* returns a StorageConnectionConfig on first use.
|
|
7
|
-
*
|
|
8
|
-
* Follows the same lazy-init pattern as presigned-url-resolver.ts.
|
|
9
|
-
*/
|
|
10
|
-
import type { StorageConnectionConfig } from 'graphile-bucket-provisioner-plugin';
|
|
11
|
-
/**
|
|
12
|
-
* Lazily initialize and return the StorageConnectionConfig for the
|
|
13
|
-
* bucket provisioner plugin.
|
|
14
|
-
*
|
|
15
|
-
* Reads CDN config on first call via getEnvOptions() (which already merges
|
|
16
|
-
* pgpmDefaults -> config file -> env vars) and caches the result.
|
|
17
|
-
* Same CDN config source as presigned-url-resolver.ts.
|
|
18
|
-
*/
|
|
19
|
-
export declare function getBucketProvisionerConnection(): StorageConnectionConfig;
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Bucket provisioner resolver for the Constructive bucket provisioner plugin.
|
|
4
|
-
*
|
|
5
|
-
* Reads CDN/S3 configuration from the standard env system
|
|
6
|
-
* (getEnvOptions -> pgpmDefaults + config files + env vars) and lazily
|
|
7
|
-
* returns a StorageConnectionConfig on first use.
|
|
8
|
-
*
|
|
9
|
-
* Follows the same lazy-init pattern as presigned-url-resolver.ts.
|
|
10
|
-
*/
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.getBucketProvisionerConnection = getBucketProvisionerConnection;
|
|
13
|
-
const graphql_env_1 = require("@constructive-io/graphql-env");
|
|
14
|
-
const logger_1 = require("@pgpmjs/logger");
|
|
15
|
-
const log = new logger_1.Logger('bucket-provisioner-resolver');
|
|
16
|
-
let connectionConfig = null;
|
|
17
|
-
/**
|
|
18
|
-
* Lazily initialize and return the StorageConnectionConfig for the
|
|
19
|
-
* bucket provisioner plugin.
|
|
20
|
-
*
|
|
21
|
-
* Reads CDN config on first call via getEnvOptions() (which already merges
|
|
22
|
-
* pgpmDefaults -> config file -> env vars) and caches the result.
|
|
23
|
-
* Same CDN config source as presigned-url-resolver.ts.
|
|
24
|
-
*/
|
|
25
|
-
function getBucketProvisionerConnection() {
|
|
26
|
-
if (connectionConfig)
|
|
27
|
-
return connectionConfig;
|
|
28
|
-
const { cdn } = (0, graphql_env_1.getEnvOptions)();
|
|
29
|
-
if (!cdn) {
|
|
30
|
-
throw new Error('[bucket-provisioner-resolver] CDN config not found. ' +
|
|
31
|
-
'Ensure CDN environment variables (AWS_ACCESS_KEY, AWS_SECRET_KEY, etc.) ' +
|
|
32
|
-
'are set or that pgpmDefaults provides CDN fields.');
|
|
33
|
-
}
|
|
34
|
-
const { provider, awsRegion, awsAccessKey, awsSecretKey, endpoint } = cdn;
|
|
35
|
-
if (!awsAccessKey || !awsSecretKey) {
|
|
36
|
-
throw new Error('[bucket-provisioner-resolver] Missing S3 credentials. ' +
|
|
37
|
-
'Set AWS_ACCESS_KEY and AWS_SECRET_KEY environment variables.');
|
|
38
|
-
}
|
|
39
|
-
log.info(`[bucket-provisioner-resolver] Initializing: provider=${provider} endpoint=${endpoint}`);
|
|
40
|
-
connectionConfig = {
|
|
41
|
-
provider: provider || 'minio',
|
|
42
|
-
region: awsRegion || 'us-east-1',
|
|
43
|
-
accessKeyId: awsAccessKey,
|
|
44
|
-
secretAccessKey: awsSecretKey,
|
|
45
|
-
...(endpoint ? { endpoint, forcePathStyle: true } : {}),
|
|
46
|
-
};
|
|
47
|
-
return connectionConfig;
|
|
48
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Bucket provisioner resolver for the Constructive bucket provisioner plugin.
|
|
3
|
-
*
|
|
4
|
-
* Reads CDN/S3 configuration from the standard env system
|
|
5
|
-
* (getEnvOptions -> pgpmDefaults + config files + env vars) and lazily
|
|
6
|
-
* returns a StorageConnectionConfig on first use.
|
|
7
|
-
*
|
|
8
|
-
* Follows the same lazy-init pattern as presigned-url-resolver.ts.
|
|
9
|
-
*/
|
|
10
|
-
import type { StorageConnectionConfig } from 'graphile-bucket-provisioner-plugin';
|
|
11
|
-
/**
|
|
12
|
-
* Lazily initialize and return the StorageConnectionConfig for the
|
|
13
|
-
* bucket provisioner plugin.
|
|
14
|
-
*
|
|
15
|
-
* Reads CDN config on first call via getEnvOptions() (which already merges
|
|
16
|
-
* pgpmDefaults -> config file -> env vars) and caches the result.
|
|
17
|
-
* Same CDN config source as presigned-url-resolver.ts.
|
|
18
|
-
*/
|
|
19
|
-
export declare function getBucketProvisionerConnection(): StorageConnectionConfig;
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Bucket provisioner resolver for the Constructive bucket provisioner plugin.
|
|
3
|
-
*
|
|
4
|
-
* Reads CDN/S3 configuration from the standard env system
|
|
5
|
-
* (getEnvOptions -> pgpmDefaults + config files + env vars) and lazily
|
|
6
|
-
* returns a StorageConnectionConfig on first use.
|
|
7
|
-
*
|
|
8
|
-
* Follows the same lazy-init pattern as presigned-url-resolver.ts.
|
|
9
|
-
*/
|
|
10
|
-
import { getEnvOptions } from '@constructive-io/graphql-env';
|
|
11
|
-
import { Logger } from '@pgpmjs/logger';
|
|
12
|
-
const log = new Logger('bucket-provisioner-resolver');
|
|
13
|
-
let connectionConfig = null;
|
|
14
|
-
/**
|
|
15
|
-
* Lazily initialize and return the StorageConnectionConfig for the
|
|
16
|
-
* bucket provisioner plugin.
|
|
17
|
-
*
|
|
18
|
-
* Reads CDN config on first call via getEnvOptions() (which already merges
|
|
19
|
-
* pgpmDefaults -> config file -> env vars) and caches the result.
|
|
20
|
-
* Same CDN config source as presigned-url-resolver.ts.
|
|
21
|
-
*/
|
|
22
|
-
export function getBucketProvisionerConnection() {
|
|
23
|
-
if (connectionConfig)
|
|
24
|
-
return connectionConfig;
|
|
25
|
-
const { cdn } = getEnvOptions();
|
|
26
|
-
if (!cdn) {
|
|
27
|
-
throw new Error('[bucket-provisioner-resolver] CDN config not found. ' +
|
|
28
|
-
'Ensure CDN environment variables (AWS_ACCESS_KEY, AWS_SECRET_KEY, etc.) ' +
|
|
29
|
-
'are set or that pgpmDefaults provides CDN fields.');
|
|
30
|
-
}
|
|
31
|
-
const { provider, awsRegion, awsAccessKey, awsSecretKey, endpoint } = cdn;
|
|
32
|
-
if (!awsAccessKey || !awsSecretKey) {
|
|
33
|
-
throw new Error('[bucket-provisioner-resolver] Missing S3 credentials. ' +
|
|
34
|
-
'Set AWS_ACCESS_KEY and AWS_SECRET_KEY environment variables.');
|
|
35
|
-
}
|
|
36
|
-
log.info(`[bucket-provisioner-resolver] Initializing: provider=${provider} endpoint=${endpoint}`);
|
|
37
|
-
connectionConfig = {
|
|
38
|
-
provider: provider || 'minio',
|
|
39
|
-
region: awsRegion || 'us-east-1',
|
|
40
|
-
accessKeyId: awsAccessKey,
|
|
41
|
-
secretAccessKey: awsSecretKey,
|
|
42
|
-
...(endpoint ? { endpoint, forcePathStyle: true } : {}),
|
|
43
|
-
};
|
|
44
|
-
return connectionConfig;
|
|
45
|
-
}
|