@contember/engine-s3-plugin 2.2.0-alpha.2 → 2.2.0-alpha.5
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/dist/development/src/Config.cjs.map +1 -1
- package/dist/development/src/Config.js.map +1 -1
- package/dist/development/src/S3ObjectAuthorizator.cjs +12 -1
- package/dist/development/src/S3ObjectAuthorizator.cjs.map +1 -1
- package/dist/development/src/S3ObjectAuthorizator.js +12 -1
- package/dist/development/src/S3ObjectAuthorizator.js.map +1 -1
- package/dist/development/src/S3SchemaContributor.cjs +27 -3
- package/dist/development/src/S3SchemaContributor.cjs.map +1 -1
- package/dist/development/src/S3SchemaContributor.js +28 -4
- package/dist/development/src/S3SchemaContributor.js.map +1 -1
- package/dist/development/src/S3SchemaTypes.cjs +8 -0
- package/dist/development/src/S3SchemaTypes.cjs.map +1 -1
- package/dist/development/src/S3SchemaTypes.js +8 -0
- package/dist/development/src/S3SchemaTypes.js.map +1 -1
- package/dist/development/src/S3Service.cjs +44 -14
- package/dist/development/src/S3Service.cjs.map +1 -1
- package/dist/development/src/S3Service.js +44 -14
- package/dist/development/src/S3Service.js.map +1 -1
- package/dist/development/src/S3Signer.cjs +6 -1
- package/dist/development/src/S3Signer.cjs.map +1 -1
- package/dist/development/src/S3Signer.js +6 -1
- package/dist/development/src/S3Signer.js.map +1 -1
- package/dist/production/src/Config.cjs.map +1 -1
- package/dist/production/src/Config.js.map +1 -1
- package/dist/production/src/S3ObjectAuthorizator.cjs +12 -1
- package/dist/production/src/S3ObjectAuthorizator.cjs.map +1 -1
- package/dist/production/src/S3ObjectAuthorizator.js +12 -1
- package/dist/production/src/S3ObjectAuthorizator.js.map +1 -1
- package/dist/production/src/S3SchemaContributor.cjs +27 -3
- package/dist/production/src/S3SchemaContributor.cjs.map +1 -1
- package/dist/production/src/S3SchemaContributor.js +28 -4
- package/dist/production/src/S3SchemaContributor.js.map +1 -1
- package/dist/production/src/S3SchemaTypes.cjs +8 -0
- package/dist/production/src/S3SchemaTypes.cjs.map +1 -1
- package/dist/production/src/S3SchemaTypes.js +8 -0
- package/dist/production/src/S3SchemaTypes.js.map +1 -1
- package/dist/production/src/S3Service.cjs +44 -14
- package/dist/production/src/S3Service.cjs.map +1 -1
- package/dist/production/src/S3Service.js +44 -14
- package/dist/production/src/S3Service.js.map +1 -1
- package/dist/production/src/S3Signer.cjs +6 -1
- package/dist/production/src/S3Signer.cjs.map +1 -1
- package/dist/production/src/S3Signer.js +6 -1
- package/dist/production/src/S3Signer.js.map +1 -1
- package/dist/tests/tsconfig.tsbuildinfo +1 -1
- package/dist/types/Config.d.ts.map +1 -1
- package/dist/types/S3ConfigProcessor.d.ts.map +1 -1
- package/dist/types/S3ObjectAuthorizator.d.ts +9 -1
- package/dist/types/S3ObjectAuthorizator.d.ts.map +1 -1
- package/dist/types/S3SchemaContributor.d.ts +2 -0
- package/dist/types/S3SchemaContributor.d.ts.map +1 -1
- package/dist/types/S3SchemaTypes.d.ts +1 -0
- package/dist/types/S3SchemaTypes.d.ts.map +1 -1
- package/dist/types/S3Service.d.ts +22 -1
- package/dist/types/S3Service.d.ts.map +1 -1
- package/dist/types/S3Signer.d.ts +1 -1
- package/dist/types/S3Signer.d.ts.map +1 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +4 -4
- package/src/Config.ts +1 -0
- package/src/S3ObjectAuthorizator.ts +20 -0
- package/src/S3SchemaContributor.ts +29 -3
- package/src/S3SchemaTypes.ts +8 -0
- package/src/S3Service.ts +64 -14
- package/src/S3Signer.ts +8 -2
- package/tests/cases/authorizator.test.ts +11 -0
- package/tests/cases/signRequest.test.ts +81 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Config.cjs","sources":["../../../../packages/engine-s3-plugin/src/Config.ts"],"sourcesContent":["import * as Typesafe from '@contember/typesafe'\n\nexport enum S3Providers {\n\taws = 'aws',\n\tminio = 'minio',\n\tceph = 'ceph',\n\tlocalstack = 'localstack',\n\tcloudserver = 'cloudserver',\n}\n\nexport const s3ConfigSchema = Typesafe.intersection(\n\tTypesafe.object({\n\t\tbucket: Typesafe.string,\n\t\tregion: Typesafe.string,\n\t\tprefix: Typesafe.string,\n\t\tcredentials: Typesafe.object({\n\t\t\tkey: Typesafe.string,\n\t\t\tsecret: Typesafe.string,\n\t\t}),\n\t}),\n\tTypesafe.partial({\n\t\tendpoint: Typesafe.string,\n\t\tcdnEndpoint: Typesafe.string,\n\t\tprovider: Typesafe.enumeration(S3Providers.aws, S3Providers.minio, S3Providers.ceph, S3Providers.localstack, S3Providers.cloudserver),\n\t\tnoAcl: Typesafe.boolean,\n\t}),\n)\n\nexport type S3Config = ReturnType<typeof s3ConfigSchema>\n\nexport type Project3Config = { s3?: S3Config }\n\n// todo\nconst serversWithoutAclSupport = [S3Providers.minio]\n\nexport const resolveS3Config = (config: S3Config): S3Config => {\n\treturn {\n\t\tnoAcl: !!config.provider && serversWithoutAclSupport.includes(config.provider),\n\t\t...config,\n\t}\n}\n\nconst defaultRegion = 'eu-west-1'\n\nexport const resolveS3Endpoint = (\n\tconfig: S3Config,\n): {\n\tendpoint: string\n\tbasePath: string\n} => {\n\tconst hasLegacyPath = !!config.endpoint || config.bucket.includes('.')\n\tconst endpoint = config.endpoint || `https://${hasLegacyPath ? '' : `${config.bucket}.`}s3.${config.region || defaultRegion}.amazonaws.com`\n\tconst basePath = hasLegacyPath ? `/${config.bucket}` : ''\n\n\treturn { endpoint, basePath }\n}\n\nexport const resolveS3PublicBaseUrl = (config: S3Config): string => {\n\tif (config.cdnEndpoint) {\n\t\treturn config.cdnEndpoint\n\t}\n\tconst { endpoint, basePath } = resolveS3Endpoint(config)\n\treturn endpoint + basePath\n}\n"],"names":["Typesafe"],"mappings":";;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"Config.cjs","sources":["../../../../packages/engine-s3-plugin/src/Config.ts"],"sourcesContent":["import * as Typesafe from '@contember/typesafe'\n\nexport enum S3Providers {\n\taws = 'aws',\n\t// Path-style addressing with no object ACL — the right value for any MinIO-compatible server, SeaweedFS included.\n\tminio = 'minio',\n\tceph = 'ceph',\n\tlocalstack = 'localstack',\n\tcloudserver = 'cloudserver',\n}\n\nexport const s3ConfigSchema = Typesafe.intersection(\n\tTypesafe.object({\n\t\tbucket: Typesafe.string,\n\t\tregion: Typesafe.string,\n\t\tprefix: Typesafe.string,\n\t\tcredentials: Typesafe.object({\n\t\t\tkey: Typesafe.string,\n\t\t\tsecret: Typesafe.string,\n\t\t}),\n\t}),\n\tTypesafe.partial({\n\t\tendpoint: Typesafe.string,\n\t\tcdnEndpoint: Typesafe.string,\n\t\tprovider: Typesafe.enumeration(S3Providers.aws, S3Providers.minio, S3Providers.ceph, S3Providers.localstack, S3Providers.cloudserver),\n\t\tnoAcl: Typesafe.boolean,\n\t}),\n)\n\nexport type S3Config = ReturnType<typeof s3ConfigSchema>\n\nexport type Project3Config = { s3?: S3Config }\n\n// todo\nconst serversWithoutAclSupport = [S3Providers.minio]\n\nexport const resolveS3Config = (config: S3Config): S3Config => {\n\treturn {\n\t\tnoAcl: !!config.provider && serversWithoutAclSupport.includes(config.provider),\n\t\t...config,\n\t}\n}\n\nconst defaultRegion = 'eu-west-1'\n\nexport const resolveS3Endpoint = (\n\tconfig: S3Config,\n): {\n\tendpoint: string\n\tbasePath: string\n} => {\n\tconst hasLegacyPath = !!config.endpoint || config.bucket.includes('.')\n\tconst endpoint = config.endpoint || `https://${hasLegacyPath ? '' : `${config.bucket}.`}s3.${config.region || defaultRegion}.amazonaws.com`\n\tconst basePath = hasLegacyPath ? `/${config.bucket}` : ''\n\n\treturn { endpoint, basePath }\n}\n\nexport const resolveS3PublicBaseUrl = (config: S3Config): string => {\n\tif (config.cdnEndpoint) {\n\t\treturn config.cdnEndpoint\n\t}\n\tconst { endpoint, basePath } = resolveS3Endpoint(config)\n\treturn endpoint + basePath\n}\n"],"names":["Typesafe"],"m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file":"Config.js","sources":["../../../../packages/engine-s3-plugin/src/Config.ts"],"sourcesContent":["import * as Typesafe from '@contember/typesafe'\n\nexport enum S3Providers {\n\taws = 'aws',\n\tminio = 'minio',\n\tceph = 'ceph',\n\tlocalstack = 'localstack',\n\tcloudserver = 'cloudserver',\n}\n\nexport const s3ConfigSchema = Typesafe.intersection(\n\tTypesafe.object({\n\t\tbucket: Typesafe.string,\n\t\tregion: Typesafe.string,\n\t\tprefix: Typesafe.string,\n\t\tcredentials: Typesafe.object({\n\t\t\tkey: Typesafe.string,\n\t\t\tsecret: Typesafe.string,\n\t\t}),\n\t}),\n\tTypesafe.partial({\n\t\tendpoint: Typesafe.string,\n\t\tcdnEndpoint: Typesafe.string,\n\t\tprovider: Typesafe.enumeration(S3Providers.aws, S3Providers.minio, S3Providers.ceph, S3Providers.localstack, S3Providers.cloudserver),\n\t\tnoAcl: Typesafe.boolean,\n\t}),\n)\n\nexport type S3Config = ReturnType<typeof s3ConfigSchema>\n\nexport type Project3Config = { s3?: S3Config }\n\n// todo\nconst serversWithoutAclSupport = [S3Providers.minio]\n\nexport const resolveS3Config = (config: S3Config): S3Config => {\n\treturn {\n\t\tnoAcl: !!config.provider && serversWithoutAclSupport.includes(config.provider),\n\t\t...config,\n\t}\n}\n\nconst defaultRegion = 'eu-west-1'\n\nexport const resolveS3Endpoint = (\n\tconfig: S3Config,\n): {\n\tendpoint: string\n\tbasePath: string\n} => {\n\tconst hasLegacyPath = !!config.endpoint || config.bucket.includes('.')\n\tconst endpoint = config.endpoint || `https://${hasLegacyPath ? '' : `${config.bucket}.`}s3.${config.region || defaultRegion}.amazonaws.com`\n\tconst basePath = hasLegacyPath ? `/${config.bucket}` : ''\n\n\treturn { endpoint, basePath }\n}\n\nexport const resolveS3PublicBaseUrl = (config: S3Config): string => {\n\tif (config.cdnEndpoint) {\n\t\treturn config.cdnEndpoint\n\t}\n\tconst { endpoint, basePath } = resolveS3Endpoint(config)\n\treturn endpoint + basePath\n}\n"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"Config.js","sources":["../../../../packages/engine-s3-plugin/src/Config.ts"],"sourcesContent":["import * as Typesafe from '@contember/typesafe'\n\nexport enum S3Providers {\n\taws = 'aws',\n\t// Path-style addressing with no object ACL — the right value for any MinIO-compatible server, SeaweedFS included.\n\tminio = 'minio',\n\tceph = 'ceph',\n\tlocalstack = 'localstack',\n\tcloudserver = 'cloudserver',\n}\n\nexport const s3ConfigSchema = Typesafe.intersection(\n\tTypesafe.object({\n\t\tbucket: Typesafe.string,\n\t\tregion: Typesafe.string,\n\t\tprefix: Typesafe.string,\n\t\tcredentials: Typesafe.object({\n\t\t\tkey: Typesafe.string,\n\t\t\tsecret: Typesafe.string,\n\t\t}),\n\t}),\n\tTypesafe.partial({\n\t\tendpoint: Typesafe.string,\n\t\tcdnEndpoint: Typesafe.string,\n\t\tprovider: Typesafe.enumeration(S3Providers.aws, S3Providers.minio, S3Providers.ceph, S3Providers.localstack, S3Providers.cloudserver),\n\t\tnoAcl: Typesafe.boolean,\n\t}),\n)\n\nexport type S3Config = ReturnType<typeof s3ConfigSchema>\n\nexport type Project3Config = { s3?: S3Config }\n\n// todo\nconst serversWithoutAclSupport = [S3Providers.minio]\n\nexport const resolveS3Config = (config: S3Config): S3Config => {\n\treturn {\n\t\tnoAcl: !!config.provider && serversWithoutAclSupport.includes(config.provider),\n\t\t...config,\n\t}\n}\n\nconst defaultRegion = 'eu-west-1'\n\nexport const resolveS3Endpoint = (\n\tconfig: S3Config,\n): {\n\tendpoint: string\n\tbasePath: string\n} => {\n\tconst hasLegacyPath = !!config.endpoint || config.bucket.includes('.')\n\tconst endpoint = config.endpoint || `https://${hasLegacyPath ? '' : `${config.bucket}.`}s3.${config.region || defaultRegion}.amazonaws.com`\n\tconst basePath = hasLegacyPath ? `/${config.bucket}` : ''\n\n\treturn { endpoint, basePath }\n}\n\nexport const resolveS3PublicBaseUrl = (config: S3Config): string => {\n\tif (config.cdnEndpoint) {\n\t\treturn config.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,11 +6,13 @@ var __defProp = Object.defineProperty;
|
|
|
6
6
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
7
7
|
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
8
8
|
class S3ObjectAuthorizator {
|
|
9
|
-
constructor(uploadRules, readRules) {
|
|
9
|
+
constructor(uploadRules, readRules, deleteRules = []) {
|
|
10
10
|
__publicField(this, "uploadRules");
|
|
11
11
|
__publicField(this, "readRules");
|
|
12
|
+
__publicField(this, "deleteRules");
|
|
12
13
|
this.uploadRules = uploadRules;
|
|
13
14
|
this.readRules = readRules;
|
|
15
|
+
this.deleteRules = deleteRules;
|
|
14
16
|
}
|
|
15
17
|
verifyReadAccess({ key }) {
|
|
16
18
|
for (const rule of this.readRules) {
|
|
@@ -21,6 +23,15 @@ class S3ObjectAuthorizator {
|
|
|
21
23
|
}
|
|
22
24
|
throw new graphqlUtils.ForbiddenError(`Read access forbidden for object key ${key}`);
|
|
23
25
|
}
|
|
26
|
+
verifyDeleteAccess({ key }) {
|
|
27
|
+
for (const rule of this.deleteRules) {
|
|
28
|
+
rule.matcher ?? (rule.matcher = pm(rule.pattern));
|
|
29
|
+
if (rule.matcher(key)) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
throw new graphqlUtils.ForbiddenError(`Delete access forbidden for object key ${key}`);
|
|
34
|
+
}
|
|
24
35
|
verifyUploadAccess({ key, size }) {
|
|
25
36
|
const matchedPatterns = [];
|
|
26
37
|
for (const rule of this.uploadRules) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"S3ObjectAuthorizator.cjs","sources":["../../../../packages/engine-s3-plugin/src/S3ObjectAuthorizator.ts"],"sourcesContent":["/// <reference path=\"../types/picomatch/index.d.ts\" />\nimport pm from 'picomatch'\nimport { ForbiddenError } from '@contember/graphql-utils'\n\nexport type S3ObjectUploadRule = {\n\tpattern: string\n\tmaxSize?: number\n\tmatcher?: (key: string) => boolean\n}\n\nexport type S3ObjectReadRule = {\n\tpattern: string\n\tmatcher?: (key: string) => boolean\n}\n\nexport class S3ObjectAuthorizator {\n\tprivate readonly uploadRules: S3ObjectUploadRule[]\n\tprivate readonly readRules: S3ObjectReadRule[]\n\n\tconstructor(\n\t\tuploadRules: Omit<S3ObjectUploadRule, 'matcher'>[],\n\t\treadRules: Omit<S3ObjectReadRule, 'matcher'>[],\n\t) {\n\t\tthis.uploadRules = uploadRules\n\t\tthis.readRules = readRules\n\t}\n\n\tpublic verifyReadAccess({ key }: { key: string }): void {\n\t\tfor (const rule of this.readRules) {\n\t\t\trule.matcher ??= pm(rule.pattern)\n\n\t\t\tif (rule.matcher(key)) {\n\t\t\t\treturn\n\t\t\t}\n\t\t}\n\n\t\tthrow new ForbiddenError(`Read access forbidden for object key ${key}`)\n\t}\n\n\tpublic verifyUploadAccess({ key, size }: { key: string; size: number | null }): void {\n\t\tconst matchedPatterns: S3ObjectUploadRule[] = []\n\n\t\tfor (const rule of this.uploadRules) {\n\t\t\trule.matcher ??= pm(rule.pattern)\n\n\t\t\tif (rule.matcher(key)) {\n\t\t\t\tif (!rule.maxSize || (size !== null && size <= rule.maxSize)) {\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\t\tmatchedPatterns.push(rule)\n\t\t\t}\n\t\t}\n\n\t\tif (matchedPatterns.length > 0) {\n\t\t\tif (size === null) {\n\t\t\t\tthrow new ForbiddenError('File size must be provided')\n\t\t\t} else {\n\t\t\t\tthrow new ForbiddenError('Uploaded file is too large')\n\t\t\t}\n\t\t}\n\n\t\tthrow new ForbiddenError(`Upload access forbidden for object key ${key}`)\n\t}\n}\n"],"names":["ForbiddenError"],"mappings":";;;;;;;
|
|
1
|
+
{"version":3,"file":"S3ObjectAuthorizator.cjs","sources":["../../../../packages/engine-s3-plugin/src/S3ObjectAuthorizator.ts"],"sourcesContent":["/// <reference path=\"../types/picomatch/index.d.ts\" />\nimport pm from 'picomatch'\nimport { ForbiddenError } from '@contember/graphql-utils'\n\nexport type S3ObjectUploadRule = {\n\tpattern: string\n\tmaxSize?: number\n\tmatcher?: (key: string) => boolean\n}\n\nexport type S3ObjectReadRule = {\n\tpattern: string\n\tmatcher?: (key: string) => boolean\n}\n\nexport type S3ObjectDeleteRule = {\n\tpattern: string\n\tmatcher?: (key: string) => boolean\n}\n\nexport class S3ObjectAuthorizator {\n\tprivate readonly uploadRules: S3ObjectUploadRule[]\n\tprivate readonly readRules: S3ObjectReadRule[]\n\tprivate readonly deleteRules: S3ObjectDeleteRule[]\n\n\tconstructor(\n\t\tuploadRules: Omit<S3ObjectUploadRule, 'matcher'>[],\n\t\treadRules: Omit<S3ObjectReadRule, 'matcher'>[],\n\t\tdeleteRules: Omit<S3ObjectDeleteRule, 'matcher'>[] = [],\n\t) {\n\t\tthis.uploadRules = uploadRules\n\t\tthis.readRules = readRules\n\t\tthis.deleteRules = deleteRules\n\t}\n\n\tpublic verifyReadAccess({ key }: { key: string }): void {\n\t\tfor (const rule of this.readRules) {\n\t\t\trule.matcher ??= pm(rule.pattern)\n\n\t\t\tif (rule.matcher(key)) {\n\t\t\t\treturn\n\t\t\t}\n\t\t}\n\n\t\tthrow new ForbiddenError(`Read access forbidden for object key ${key}`)\n\t}\n\n\tpublic verifyDeleteAccess({ key }: { key: string }): void {\n\t\tfor (const rule of this.deleteRules) {\n\t\t\trule.matcher ??= pm(rule.pattern)\n\n\t\t\tif (rule.matcher(key)) {\n\t\t\t\treturn\n\t\t\t}\n\t\t}\n\n\t\tthrow new ForbiddenError(`Delete access forbidden for object key ${key}`)\n\t}\n\n\tpublic verifyUploadAccess({ key, size }: { key: string; size: number | null }): void {\n\t\tconst matchedPatterns: S3ObjectUploadRule[] = []\n\n\t\tfor (const rule of this.uploadRules) {\n\t\t\trule.matcher ??= pm(rule.pattern)\n\n\t\t\tif (rule.matcher(key)) {\n\t\t\t\tif (!rule.maxSize || (size !== null && size <= rule.maxSize)) {\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\t\tmatchedPatterns.push(rule)\n\t\t\t}\n\t\t}\n\n\t\tif (matchedPatterns.length > 0) {\n\t\t\tif (size === null) {\n\t\t\t\tthrow new ForbiddenError('File size must be provided')\n\t\t\t} else {\n\t\t\t\tthrow new ForbiddenError('Uploaded file is too large')\n\t\t\t}\n\t\t}\n\n\t\tthrow new ForbiddenError(`Upload access forbidden for object key ${key}`)\n\t}\n}\n"],"names":["ForbiddenError"],"mappings":";;;;;;;AAoBO,MAAM,qBAAqB;AAAA,EAKjC,YACC,aACA,WACA,cAAqD,CAAA,GACpD;AARF,kBAAA,MAAiB,aAAA;AACjB,kBAAA,MAAiB,WAAA;AACjB,kBAAA,MAAiB,aAAA;AAOhB,SAAK,cAAc;AACnB,SAAK,YAAY;AACjB,SAAK,cAAc;AAAA,EACpB;AAAA,EAEO,iBAAiB,EAAE,OAA8B;AACvD,eAAW,QAAQ,KAAK,WAAW;AAClC,WAAK,YAAL,KAAK,UAAY,GAAG,KAAK,OAAO;AAEhC,UAAI,KAAK,QAAQ,GAAG,GAAG;AACtB;AAAA,MACD;AAAA,IACD;AAEA,UAAM,IAAIA,aAAAA,eAAe,wCAAwC,GAAG,EAAE;AAAA,EACvE;AAAA,EAEO,mBAAmB,EAAE,OAA8B;AACzD,eAAW,QAAQ,KAAK,aAAa;AACpC,WAAK,YAAL,KAAK,UAAY,GAAG,KAAK,OAAO;AAEhC,UAAI,KAAK,QAAQ,GAAG,GAAG;AACtB;AAAA,MACD;AAAA,IACD;AAEA,UAAM,IAAIA,aAAAA,eAAe,0CAA0C,GAAG,EAAE;AAAA,EACzE;AAAA,EAEO,mBAAmB,EAAE,KAAK,QAAoD;AACpF,UAAM,kBAAwC,CAAA;AAE9C,eAAW,QAAQ,KAAK,aAAa;AACpC,WAAK,YAAL,KAAK,UAAY,GAAG,KAAK,OAAO;AAEhC,UAAI,KAAK,QAAQ,GAAG,GAAG;AACtB,YAAI,CAAC,KAAK,WAAY,SAAS,QAAQ,QAAQ,KAAK,SAAU;AAC7D;AAAA,QACD;AACA,wBAAgB,KAAK,IAAI;AAAA,MAC1B;AAAA,IACD;AAEA,QAAI,gBAAgB,SAAS,GAAG;AAC/B,UAAI,SAAS,MAAM;AAClB,cAAM,IAAIA,aAAAA,eAAe,4BAA4B;AAAA,MACtD,OAAO;AACN,cAAM,IAAIA,aAAAA,eAAe,4BAA4B;AAAA,MACtD;AAAA,IACD;AAEA,UAAM,IAAIA,aAAAA,eAAe,0CAA0C,GAAG,EAAE;AAAA,EACzE;AACD;;"}
|
|
@@ -4,11 +4,13 @@ var __defProp = Object.defineProperty;
|
|
|
4
4
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
5
5
|
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
6
6
|
class S3ObjectAuthorizator {
|
|
7
|
-
constructor(uploadRules, readRules) {
|
|
7
|
+
constructor(uploadRules, readRules, deleteRules = []) {
|
|
8
8
|
__publicField(this, "uploadRules");
|
|
9
9
|
__publicField(this, "readRules");
|
|
10
|
+
__publicField(this, "deleteRules");
|
|
10
11
|
this.uploadRules = uploadRules;
|
|
11
12
|
this.readRules = readRules;
|
|
13
|
+
this.deleteRules = deleteRules;
|
|
12
14
|
}
|
|
13
15
|
verifyReadAccess({ key }) {
|
|
14
16
|
for (const rule of this.readRules) {
|
|
@@ -19,6 +21,15 @@ class S3ObjectAuthorizator {
|
|
|
19
21
|
}
|
|
20
22
|
throw new ForbiddenError(`Read access forbidden for object key ${key}`);
|
|
21
23
|
}
|
|
24
|
+
verifyDeleteAccess({ key }) {
|
|
25
|
+
for (const rule of this.deleteRules) {
|
|
26
|
+
rule.matcher ?? (rule.matcher = pm(rule.pattern));
|
|
27
|
+
if (rule.matcher(key)) {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
throw new ForbiddenError(`Delete access forbidden for object key ${key}`);
|
|
32
|
+
}
|
|
22
33
|
verifyUploadAccess({ key, size }) {
|
|
23
34
|
const matchedPatterns = [];
|
|
24
35
|
for (const rule of this.uploadRules) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"S3ObjectAuthorizator.js","sources":["../../../../packages/engine-s3-plugin/src/S3ObjectAuthorizator.ts"],"sourcesContent":["/// <reference path=\"../types/picomatch/index.d.ts\" />\nimport pm from 'picomatch'\nimport { ForbiddenError } from '@contember/graphql-utils'\n\nexport type S3ObjectUploadRule = {\n\tpattern: string\n\tmaxSize?: number\n\tmatcher?: (key: string) => boolean\n}\n\nexport type S3ObjectReadRule = {\n\tpattern: string\n\tmatcher?: (key: string) => boolean\n}\n\nexport class S3ObjectAuthorizator {\n\tprivate readonly uploadRules: S3ObjectUploadRule[]\n\tprivate readonly readRules: S3ObjectReadRule[]\n\n\tconstructor(\n\t\tuploadRules: Omit<S3ObjectUploadRule, 'matcher'>[],\n\t\treadRules: Omit<S3ObjectReadRule, 'matcher'>[],\n\t) {\n\t\tthis.uploadRules = uploadRules\n\t\tthis.readRules = readRules\n\t}\n\n\tpublic verifyReadAccess({ key }: { key: string }): void {\n\t\tfor (const rule of this.readRules) {\n\t\t\trule.matcher ??= pm(rule.pattern)\n\n\t\t\tif (rule.matcher(key)) {\n\t\t\t\treturn\n\t\t\t}\n\t\t}\n\n\t\tthrow new ForbiddenError(`Read access forbidden for object key ${key}`)\n\t}\n\n\tpublic verifyUploadAccess({ key, size }: { key: string; size: number | null }): void {\n\t\tconst matchedPatterns: S3ObjectUploadRule[] = []\n\n\t\tfor (const rule of this.uploadRules) {\n\t\t\trule.matcher ??= pm(rule.pattern)\n\n\t\t\tif (rule.matcher(key)) {\n\t\t\t\tif (!rule.maxSize || (size !== null && size <= rule.maxSize)) {\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\t\tmatchedPatterns.push(rule)\n\t\t\t}\n\t\t}\n\n\t\tif (matchedPatterns.length > 0) {\n\t\t\tif (size === null) {\n\t\t\t\tthrow new ForbiddenError('File size must be provided')\n\t\t\t} else {\n\t\t\t\tthrow new ForbiddenError('Uploaded file is too large')\n\t\t\t}\n\t\t}\n\n\t\tthrow new ForbiddenError(`Upload access forbidden for object key ${key}`)\n\t}\n}\n"],"names":[],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"S3ObjectAuthorizator.js","sources":["../../../../packages/engine-s3-plugin/src/S3ObjectAuthorizator.ts"],"sourcesContent":["/// <reference path=\"../types/picomatch/index.d.ts\" />\nimport pm from 'picomatch'\nimport { ForbiddenError } from '@contember/graphql-utils'\n\nexport type S3ObjectUploadRule = {\n\tpattern: string\n\tmaxSize?: number\n\tmatcher?: (key: string) => boolean\n}\n\nexport type S3ObjectReadRule = {\n\tpattern: string\n\tmatcher?: (key: string) => boolean\n}\n\nexport type S3ObjectDeleteRule = {\n\tpattern: string\n\tmatcher?: (key: string) => boolean\n}\n\nexport class S3ObjectAuthorizator {\n\tprivate readonly uploadRules: S3ObjectUploadRule[]\n\tprivate readonly readRules: S3ObjectReadRule[]\n\tprivate readonly deleteRules: S3ObjectDeleteRule[]\n\n\tconstructor(\n\t\tuploadRules: Omit<S3ObjectUploadRule, 'matcher'>[],\n\t\treadRules: Omit<S3ObjectReadRule, 'matcher'>[],\n\t\tdeleteRules: Omit<S3ObjectDeleteRule, 'matcher'>[] = [],\n\t) {\n\t\tthis.uploadRules = uploadRules\n\t\tthis.readRules = readRules\n\t\tthis.deleteRules = deleteRules\n\t}\n\n\tpublic verifyReadAccess({ key }: { key: string }): void {\n\t\tfor (const rule of this.readRules) {\n\t\t\trule.matcher ??= pm(rule.pattern)\n\n\t\t\tif (rule.matcher(key)) {\n\t\t\t\treturn\n\t\t\t}\n\t\t}\n\n\t\tthrow new ForbiddenError(`Read access forbidden for object key ${key}`)\n\t}\n\n\tpublic verifyDeleteAccess({ key }: { key: string }): void {\n\t\tfor (const rule of this.deleteRules) {\n\t\t\trule.matcher ??= pm(rule.pattern)\n\n\t\t\tif (rule.matcher(key)) {\n\t\t\t\treturn\n\t\t\t}\n\t\t}\n\n\t\tthrow new ForbiddenError(`Delete access forbidden for object key ${key}`)\n\t}\n\n\tpublic verifyUploadAccess({ key, size }: { key: string; size: number | null }): void {\n\t\tconst matchedPatterns: S3ObjectUploadRule[] = []\n\n\t\tfor (const rule of this.uploadRules) {\n\t\t\trule.matcher ??= pm(rule.pattern)\n\n\t\t\tif (rule.matcher(key)) {\n\t\t\t\tif (!rule.maxSize || (size !== null && size <= rule.maxSize)) {\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\t\tmatchedPatterns.push(rule)\n\t\t\t}\n\t\t}\n\n\t\tif (matchedPatterns.length > 0) {\n\t\t\tif (size === null) {\n\t\t\t\tthrow new ForbiddenError('File size must be provided')\n\t\t\t} else {\n\t\t\t\tthrow new ForbiddenError('Uploaded file is too large')\n\t\t\t}\n\t\t}\n\n\t\tthrow new ForbiddenError(`Upload access forbidden for object key ${key}`)\n\t}\n}\n"],"names":[],"mappings":";;;;;AAoBO,MAAM,qBAAqB;AAAA,EAKjC,YACC,aACA,WACA,cAAqD,CAAA,GACpD;AARF,kBAAA,MAAiB,aAAA;AACjB,kBAAA,MAAiB,WAAA;AACjB,kBAAA,MAAiB,aAAA;AAOhB,SAAK,cAAc;AACnB,SAAK,YAAY;AACjB,SAAK,cAAc;AAAA,EACpB;AAAA,EAEO,iBAAiB,EAAE,OAA8B;AACvD,eAAW,QAAQ,KAAK,WAAW;AAClC,WAAK,YAAL,KAAK,UAAY,GAAG,KAAK,OAAO;AAEhC,UAAI,KAAK,QAAQ,GAAG,GAAG;AACtB;AAAA,MACD;AAAA,IACD;AAEA,UAAM,IAAI,eAAe,wCAAwC,GAAG,EAAE;AAAA,EACvE;AAAA,EAEO,mBAAmB,EAAE,OAA8B;AACzD,eAAW,QAAQ,KAAK,aAAa;AACpC,WAAK,YAAL,KAAK,UAAY,GAAG,KAAK,OAAO;AAEhC,UAAI,KAAK,QAAQ,GAAG,GAAG;AACtB;AAAA,MACD;AAAA,IACD;AAEA,UAAM,IAAI,eAAe,0CAA0C,GAAG,EAAE;AAAA,EACzE;AAAA,EAEO,mBAAmB,EAAE,KAAK,QAAoD;AACpF,UAAM,kBAAwC,CAAA;AAE9C,eAAW,QAAQ,KAAK,aAAa;AACpC,WAAK,YAAL,KAAK,UAAY,GAAG,KAAK,OAAO;AAEhC,UAAI,KAAK,QAAQ,GAAG,GAAG;AACtB,YAAI,CAAC,KAAK,WAAY,SAAS,QAAQ,QAAQ,KAAK,SAAU;AAC7D;AAAA,QACD;AACA,wBAAgB,KAAK,IAAI;AAAA,MAC1B;AAAA,IACD;AAEA,QAAI,gBAAgB,SAAS,GAAG;AAC/B,UAAI,SAAS,MAAM;AAClB,cAAM,IAAI,eAAe,4BAA4B;AAAA,MACtD,OAAO;AACN,cAAM,IAAI,eAAe,4BAA4B;AAAA,MACtD;AAAA,IACD;AAEA,UAAM,IAAI,eAAe,0CAA0C,GAAG,EAAE;AAAA,EACzE;AACD;"}
|
|
@@ -24,15 +24,21 @@ class S3SchemaContributor {
|
|
|
24
24
|
const readRules = rules.filter(([, it]) => it.read).map(([it]) => ({
|
|
25
25
|
pattern: it
|
|
26
26
|
}));
|
|
27
|
-
|
|
27
|
+
const deleteRules = rules.filter(([, it]) => it.delete).map(([it]) => ({
|
|
28
|
+
pattern: it
|
|
29
|
+
}));
|
|
30
|
+
if (uploadRules.length === 0 && readRules.length === 0 && deleteRules.length === 0) {
|
|
28
31
|
return void 0;
|
|
29
32
|
}
|
|
30
|
-
const authorizator = new S3ObjectAuthorizator.S3ObjectAuthorizator(uploadRules, readRules);
|
|
33
|
+
const authorizator = new S3ObjectAuthorizator.S3ObjectAuthorizator(uploadRules, readRules, deleteRules);
|
|
31
34
|
const uploadMutation = this.createUploadMutation(authorizator);
|
|
32
35
|
const readMutation = this.createReadMutation(authorizator);
|
|
36
|
+
const deleteMutation = this.createDeleteMutation(authorizator);
|
|
33
37
|
const mutation = {
|
|
34
38
|
generateUploadUrl: uploadMutation,
|
|
35
|
-
generateReadUrl: readMutation
|
|
39
|
+
generateReadUrl: readMutation,
|
|
40
|
+
// not "deleteObject" — a content mutation for an entity named "Object" would shadow it
|
|
41
|
+
deleteS3Object: deleteMutation
|
|
36
42
|
};
|
|
37
43
|
return {
|
|
38
44
|
mutation: new graphql.GraphQLObjectType({
|
|
@@ -70,6 +76,24 @@ class S3SchemaContributor {
|
|
|
70
76
|
}
|
|
71
77
|
};
|
|
72
78
|
}
|
|
79
|
+
createDeleteMutation(authorizator) {
|
|
80
|
+
return {
|
|
81
|
+
type: new graphql.GraphQLNonNull(S3SchemaTypes.S3DeletedObject),
|
|
82
|
+
args: {
|
|
83
|
+
objectKey: {
|
|
84
|
+
type: new graphql.GraphQLNonNull(graphql.GraphQLString)
|
|
85
|
+
}
|
|
86
|
+
},
|
|
87
|
+
resolve: async (parent, args, ctx) => {
|
|
88
|
+
if (!ctx.project.s3) {
|
|
89
|
+
throw new graphql.GraphQLError("S3 is not configured for this project");
|
|
90
|
+
}
|
|
91
|
+
const s3Config = Config.resolveS3Config(ctx.project.s3);
|
|
92
|
+
const s3 = this.s3Factory.create(s3Config, this.providers, authorizator);
|
|
93
|
+
return await s3.deleteObject({ objectKey: args.objectKey });
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
}
|
|
73
97
|
createUploadMutation(authorizator) {
|
|
74
98
|
return {
|
|
75
99
|
type: new graphql.GraphQLNonNull(S3SchemaTypes.S3SignedUpload),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"S3SchemaContributor.cjs","sources":["../../../../packages/engine-s3-plugin/src/S3SchemaContributor.ts"],"sourcesContent":["import {\n\tGraphQLError,\n\tGraphQLFieldConfig,\n\tGraphQLInt,\n\tGraphQLNonNull,\n\tGraphQLObjectType,\n\tGraphQLSchema,\n\tGraphQLSchemaConfig,\n\tGraphQLString,\n} from 'graphql'\nimport { S3Service, S3ServiceFactory } from './S3Service.js'\nimport { Project3Config, resolveS3Config, S3Config } from './Config.js'\nimport { GraphQLSchemaContributor, GraphQLSchemaContributorContext, Providers } from '@contember/engine-plugins'\nimport * as types from './S3SchemaTypes.js'\nimport { S3Acl, S3GenerateSignedUploadInput, S3SignedRead, S3SignedUpload } from './S3SchemaTypes.js'\nimport { S3ObjectAuthorizator } from './S3ObjectAuthorizator.js'\n\ninterface Identity {\n\tprojectRoles: string[]\n}\n\nexport type S3SchemaUploadAcl =\n\t| boolean\n\t| {\n\t\tmaxSize?: number\n\t}\n\nexport type S3SchemaAcl = Record<\n\tstring, // public/*.jpg\n\t{\n\t\tread?: boolean\n\t\tupload?: S3SchemaUploadAcl\n\t}\n>\n\nexport class S3SchemaContributor implements GraphQLSchemaContributor {\n\tconstructor(\n\t\tprivate readonly s3Factory: S3ServiceFactory,\n\t\tprivate readonly providers: Providers,\n\t) {}\n\n\tgetCacheKey?({ project }: GraphQLSchemaContributorContext): string {\n\t\treturn project.s3 ? 'yes' : 'no'\n\t}\n\n\tcreateSchema(context: GraphQLSchemaContributorContext): GraphQLSchemaConfig | undefined {\n\t\tif (!context.project.s3) {\n\t\t\treturn undefined\n\t\t}\n\t\tconst rules = context.identity.projectRoles.flatMap(it => Object.entries((context.schema.acl.roles[it]?.s3 as S3SchemaAcl) || {}))\n\n\t\tconst uploadRules = rules.filter(([, it]) => it.upload).map(([it, val]) => ({\n\t\t\tpattern: it,\n\t\t\t...(typeof val.upload !== 'boolean' ? val.upload : {}),\n\t\t}))\n\t\tconst readRules = rules.filter(([, it]) => it.read).map(([it]) => ({\n\t\t\tpattern: it,\n\t\t}))\n\n\t\tif (uploadRules.length === 0 && readRules.length === 0) {\n\t\t\treturn undefined\n\t\t}\n\n\t\tconst authorizator = new S3ObjectAuthorizator(uploadRules, readRules)\n\t\tconst uploadMutation = this.createUploadMutation(authorizator)\n\t\tconst readMutation = this.createReadMutation(authorizator)\n\t\tconst mutation = {\n\t\t\tgenerateUploadUrl: uploadMutation as GraphQLFieldConfig<any, any, any>,\n\t\t\tgenerateReadUrl: readMutation,\n\t\t}\n\t\treturn {\n\t\t\tmutation: new GraphQLObjectType({\n\t\t\t\tname: 'Mutation',\n\t\t\t\tfields: () => mutation,\n\t\t\t}),\n\t\t\tquery: new GraphQLObjectType({\n\t\t\t\tname: 'Query',\n\t\t\t\tfields: () => ({\n\t\t\t\t\ts3DummyQuery: {\n\t\t\t\t\t\ttype: GraphQLString,\n\t\t\t\t\t},\n\t\t\t\t}),\n\t\t\t}),\n\t\t}\n\t}\n\n\tprivate createReadMutation(authorizator: S3ObjectAuthorizator): GraphQLFieldConfig<any, { project: Project3Config }, any> {\n\t\treturn {\n\t\t\ttype: new GraphQLNonNull(S3SignedRead),\n\t\t\targs: {\n\t\t\t\tobjectKey: {\n\t\t\t\t\ttype: new GraphQLNonNull(GraphQLString),\n\t\t\t\t},\n\t\t\t\texpiration: {\n\t\t\t\t\ttype: GraphQLInt,\n\t\t\t\t},\n\t\t\t},\n\t\t\tresolve: async (parent: any, args: { objectKey: string; expiration?: number }, ctx: { project: Project3Config }) => {\n\t\t\t\tif (!ctx.project.s3) {\n\t\t\t\t\tthrow new GraphQLError('S3 is not configured for this project')\n\t\t\t\t}\n\t\t\t\tconst s3Config = resolveS3Config(ctx.project.s3)\n\t\t\t\tconst s3 = this.s3Factory.create(s3Config, this.providers, authorizator)\n\t\t\t\treturn s3.getSignedReadUrl({ objectKey: args.objectKey, expiration: args.expiration ?? null })\n\t\t\t},\n\t\t} as GraphQLFieldConfig<any, any, any>\n\t}\n\n\tprivate createUploadMutation(authorizator: S3ObjectAuthorizator): GraphQLFieldConfig<any, any, any> {\n\t\treturn {\n\t\t\ttype: new GraphQLNonNull(S3SignedUpload),\n\t\t\targs: {\n\t\t\t\tinput: { type: types.S3GenerateSignedUploadInput },\n\t\t\t\tcontentType: { type: GraphQLString, deprecationReason: 'Use input.contentType' },\n\t\t\t\texpiration: { type: GraphQLInt, deprecationReason: 'Use input.expiration' },\n\t\t\t\tprefix: { type: GraphQLString, deprecationReason: 'Use input.prefix' },\n\t\t\t\tacl: { type: types.S3Acl, deprecationReason: 'Use input.acl' },\n\t\t\t},\n\t\t\tresolve: async (\n\t\t\t\tparent: any,\n\t\t\t\targs: { input?: Partial<S3GenerateSignedUploadInput>; contentType?: string; acl?: S3Acl; expiration?: number; prefix?: string },\n\t\t\t\tctx: { project: Project3Config },\n\t\t\t) => {\n\t\t\t\tif (!ctx.project.s3) {\n\t\t\t\t\tthrow new GraphQLError('S3 is not configured for this project')\n\t\t\t\t}\n\t\t\t\tconst s3Config = resolveS3Config(ctx.project.s3)\n\t\t\t\tconst s3 = this.s3Factory.create(s3Config, this.providers, authorizator)\n\t\t\t\treturn s3.getSignedUploadUrl({\n\t\t\t\t\tacl: args.input?.acl ?? args.acl ?? null,\n\t\t\t\t\tcontentDisposition: args.input?.contentDisposition ?? null,\n\t\t\t\t\tcontentType: args.input?.contentType ?? args.contentType ?? null,\n\t\t\t\t\texpiration: args.input?.expiration ?? args.expiration ?? null,\n\t\t\t\t\textension: args.input?.extension ?? null,\n\t\t\t\t\tfileName: args.input?.fileName ?? null,\n\t\t\t\t\tprefix: args.input?.prefix ?? args.prefix ?? null,\n\t\t\t\t\tsuffix: args.input?.suffix ?? null,\n\t\t\t\t\tsize: args.input?.size ?? null,\n\t\t\t\t})\n\t\t\t},\n\t\t}\n\t}\n}\n"],"names":["S3ObjectAuthorizator","GraphQLObjectType","GraphQLString","GraphQLNonNull","S3SignedRead","GraphQLInt","GraphQLError","resolveS3Config","S3SignedUpload","types.S3GenerateSignedUploadInput","types.S3Acl"],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"file":"S3SchemaContributor.cjs","sources":["../../../../packages/engine-s3-plugin/src/S3SchemaContributor.ts"],"sourcesContent":["import {\n\tGraphQLError,\n\tGraphQLFieldConfig,\n\tGraphQLInt,\n\tGraphQLNonNull,\n\tGraphQLObjectType,\n\tGraphQLSchema,\n\tGraphQLSchemaConfig,\n\tGraphQLString,\n} from 'graphql'\nimport { S3Service, S3ServiceFactory } from './S3Service.js'\nimport { Project3Config, resolveS3Config, S3Config } from './Config.js'\nimport { GraphQLSchemaContributor, GraphQLSchemaContributorContext, Providers } from '@contember/engine-plugins'\nimport * as types from './S3SchemaTypes.js'\nimport { S3Acl, S3DeletedObject, S3GenerateSignedUploadInput, S3SignedRead, S3SignedUpload } from './S3SchemaTypes.js'\nimport { S3ObjectAuthorizator } from './S3ObjectAuthorizator.js'\n\ninterface Identity {\n\tprojectRoles: string[]\n}\n\nexport type S3SchemaUploadAcl =\n\t| boolean\n\t| {\n\t\tmaxSize?: number\n\t}\n\nexport type S3SchemaAcl = Record<\n\tstring, // public/*.jpg\n\t{\n\t\tread?: boolean\n\t\tupload?: S3SchemaUploadAcl\n\t\tdelete?: boolean\n\t}\n>\n\nexport class S3SchemaContributor implements GraphQLSchemaContributor {\n\tconstructor(\n\t\tprivate readonly s3Factory: S3ServiceFactory,\n\t\tprivate readonly providers: Providers,\n\t) {}\n\n\tgetCacheKey?({ project }: GraphQLSchemaContributorContext): string {\n\t\treturn project.s3 ? 'yes' : 'no'\n\t}\n\n\tcreateSchema(context: GraphQLSchemaContributorContext): GraphQLSchemaConfig | undefined {\n\t\tif (!context.project.s3) {\n\t\t\treturn undefined\n\t\t}\n\t\tconst rules = context.identity.projectRoles.flatMap(it => Object.entries((context.schema.acl.roles[it]?.s3 as S3SchemaAcl) || {}))\n\n\t\tconst uploadRules = rules.filter(([, it]) => it.upload).map(([it, val]) => ({\n\t\t\tpattern: it,\n\t\t\t...(typeof val.upload !== 'boolean' ? val.upload : {}),\n\t\t}))\n\t\tconst readRules = rules.filter(([, it]) => it.read).map(([it]) => ({\n\t\t\tpattern: it,\n\t\t}))\n\t\tconst deleteRules = rules.filter(([, it]) => it.delete).map(([it]) => ({\n\t\t\tpattern: it,\n\t\t}))\n\n\t\tif (uploadRules.length === 0 && readRules.length === 0 && deleteRules.length === 0) {\n\t\t\treturn undefined\n\t\t}\n\n\t\tconst authorizator = new S3ObjectAuthorizator(uploadRules, readRules, deleteRules)\n\t\tconst uploadMutation = this.createUploadMutation(authorizator)\n\t\tconst readMutation = this.createReadMutation(authorizator)\n\t\tconst deleteMutation = this.createDeleteMutation(authorizator)\n\t\tconst mutation = {\n\t\t\tgenerateUploadUrl: uploadMutation as GraphQLFieldConfig<any, any, any>,\n\t\t\tgenerateReadUrl: readMutation,\n\t\t\t// not \"deleteObject\" — a content mutation for an entity named \"Object\" would shadow it\n\t\t\tdeleteS3Object: deleteMutation,\n\t\t}\n\t\treturn {\n\t\t\tmutation: new GraphQLObjectType({\n\t\t\t\tname: 'Mutation',\n\t\t\t\tfields: () => mutation,\n\t\t\t}),\n\t\t\tquery: new GraphQLObjectType({\n\t\t\t\tname: 'Query',\n\t\t\t\tfields: () => ({\n\t\t\t\t\ts3DummyQuery: {\n\t\t\t\t\t\ttype: GraphQLString,\n\t\t\t\t\t},\n\t\t\t\t}),\n\t\t\t}),\n\t\t}\n\t}\n\n\tprivate createReadMutation(authorizator: S3ObjectAuthorizator): GraphQLFieldConfig<any, { project: Project3Config }, any> {\n\t\treturn {\n\t\t\ttype: new GraphQLNonNull(S3SignedRead),\n\t\t\targs: {\n\t\t\t\tobjectKey: {\n\t\t\t\t\ttype: new GraphQLNonNull(GraphQLString),\n\t\t\t\t},\n\t\t\t\texpiration: {\n\t\t\t\t\ttype: GraphQLInt,\n\t\t\t\t},\n\t\t\t},\n\t\t\tresolve: async (parent: any, args: { objectKey: string; expiration?: number }, ctx: { project: Project3Config }) => {\n\t\t\t\tif (!ctx.project.s3) {\n\t\t\t\t\tthrow new GraphQLError('S3 is not configured for this project')\n\t\t\t\t}\n\t\t\t\tconst s3Config = resolveS3Config(ctx.project.s3)\n\t\t\t\tconst s3 = this.s3Factory.create(s3Config, this.providers, authorizator)\n\t\t\t\treturn s3.getSignedReadUrl({ objectKey: args.objectKey, expiration: args.expiration ?? null })\n\t\t\t},\n\t\t} as GraphQLFieldConfig<any, any, any>\n\t}\n\n\tprivate createDeleteMutation(authorizator: S3ObjectAuthorizator): GraphQLFieldConfig<any, any, any> {\n\t\treturn {\n\t\t\ttype: new GraphQLNonNull(S3DeletedObject),\n\t\t\targs: {\n\t\t\t\tobjectKey: {\n\t\t\t\t\ttype: new GraphQLNonNull(GraphQLString),\n\t\t\t\t},\n\t\t\t},\n\t\t\tresolve: async (parent: any, args: { objectKey: string }, ctx: { project: Project3Config }) => {\n\t\t\t\tif (!ctx.project.s3) {\n\t\t\t\t\tthrow new GraphQLError('S3 is not configured for this project')\n\t\t\t\t}\n\t\t\t\tconst s3Config = resolveS3Config(ctx.project.s3)\n\t\t\t\tconst s3 = this.s3Factory.create(s3Config, this.providers, authorizator)\n\t\t\t\treturn await s3.deleteObject({ objectKey: args.objectKey })\n\t\t\t},\n\t\t}\n\t}\n\n\tprivate createUploadMutation(authorizator: S3ObjectAuthorizator): GraphQLFieldConfig<any, any, any> {\n\t\treturn {\n\t\t\ttype: new GraphQLNonNull(S3SignedUpload),\n\t\t\targs: {\n\t\t\t\tinput: { type: types.S3GenerateSignedUploadInput },\n\t\t\t\tcontentType: { type: GraphQLString, deprecationReason: 'Use input.contentType' },\n\t\t\t\texpiration: { type: GraphQLInt, deprecationReason: 'Use input.expiration' },\n\t\t\t\tprefix: { type: GraphQLString, deprecationReason: 'Use input.prefix' },\n\t\t\t\tacl: { type: types.S3Acl, deprecationReason: 'Use input.acl' },\n\t\t\t},\n\t\t\tresolve: async (\n\t\t\t\tparent: any,\n\t\t\t\targs: { input?: Partial<S3GenerateSignedUploadInput>; contentType?: string; acl?: S3Acl; expiration?: number; prefix?: string },\n\t\t\t\tctx: { project: Project3Config },\n\t\t\t) => {\n\t\t\t\tif (!ctx.project.s3) {\n\t\t\t\t\tthrow new GraphQLError('S3 is not configured for this project')\n\t\t\t\t}\n\t\t\t\tconst s3Config = resolveS3Config(ctx.project.s3)\n\t\t\t\tconst s3 = this.s3Factory.create(s3Config, this.providers, authorizator)\n\t\t\t\treturn s3.getSignedUploadUrl({\n\t\t\t\t\tacl: args.input?.acl ?? args.acl ?? null,\n\t\t\t\t\tcontentDisposition: args.input?.contentDisposition ?? null,\n\t\t\t\t\tcontentType: args.input?.contentType ?? args.contentType ?? null,\n\t\t\t\t\texpiration: args.input?.expiration ?? args.expiration ?? null,\n\t\t\t\t\textension: args.input?.extension ?? null,\n\t\t\t\t\tfileName: args.input?.fileName ?? null,\n\t\t\t\t\tprefix: args.input?.prefix ?? args.prefix ?? null,\n\t\t\t\t\tsuffix: args.input?.suffix ?? null,\n\t\t\t\t\tsize: args.input?.size ?? null,\n\t\t\t\t})\n\t\t\t},\n\t\t}\n\t}\n}\n"],"names":["S3ObjectAuthorizator","GraphQLObjectType","GraphQLString","GraphQLNonNull","S3SignedRead","GraphQLInt","GraphQLError","resolveS3Config","S3DeletedObject","S3SignedUpload","types.S3GenerateSignedUploadInput","types.S3Acl"],"mappings":";;;;;;AAoCO,MAAM,oBAAwD;AAAA,EACpE,YACkB,WACA,WAChB;AAFgB,SAAA,YAAA;AACA,SAAA,YAAA;AAAA,EACf;AAAA,EAEH,YAAa,EAAE,WAAoD;AAClE,WAAO,QAAQ,KAAK,QAAQ;AAAA,EAC7B;AAAA,EAEA,aAAa,SAA2E;AACvF,QAAI,CAAC,QAAQ,QAAQ,IAAI;AACxB,aAAO;AAAA,IACR;AACA,UAAM,QAAQ,QAAQ,SAAS,aAAa,QAAQ,QAAM,OAAO,QAAS,QAAQ,OAAO,IAAI,MAAM,EAAE,GAAG,MAAsB,CAAA,CAAE,CAAC;AAEjI,UAAM,cAAc,MAAM,OAAO,CAAC,CAAA,EAAG,EAAE,MAAM,GAAG,MAAM,EAAE,IAAI,CAAC,CAAC,IAAI,GAAG,OAAO;AAAA,MAC3E,SAAS;AAAA,MACT,GAAI,OAAO,IAAI,WAAW,YAAY,IAAI,SAAS,CAAA;AAAA,IAAC,EACnD;AACF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mB,gBAAA;AAAA,MAAgB;AAAA,MAE9D,SAAS,OACR,QACA,MACA,QACI;AACJ,YAAI,CAAC,IAAI,QAAQ,IAAI;AACpB,gBAAM,IAAIL,QAAAA,aAAa,uCAAuC;AAAA,QAC/D;AACA,cAAM,WAAWC,OAAAA,gBAAgB,IAAI,QAAQ,EAAE;AAC/C,cAAM,KAAK,KAAK,UAAU,OAAO,UAAU,KAAK,WAAW,YAAY;AACvE,eAAO,GAAG,mBAAmB;AAAA,UAC5B,KAAK,KAAK,OAAO,OAAO,KAAK,OAAO;AAAA,UACpC,oBAAoB,KAAK,OAAO,sBAAsB;AAAA,UACtD,aAAa,KAAK,OAAO,eAAe,KAAK,eAAe;AAAA,UAC5D,YAAY,KAAK,OAAO,cAAc,KAAK,cAAc;AAAA,UACzD,WAAW,KAAK,OAAO,aAAa;AAAA,UACpC,UAAU,KAAK,OAAO,YAAY;AAAA,UAClC,QAAQ,KAAK,OAAO,UAAU,KAAK,UAAU;AAAA,UAC7C,QAAQ,KAAK,OAAO,UAAU;AAAA,UAC9B,MAAM,KAAK,OAAO,QAAQ;AAAA,QAAA,CAC1B;AAAA,MACF;AAAA,IAAA;AAAA,EAEF;AACD;;"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { GraphQLObjectType, GraphQLString, GraphQLInt, GraphQLNonNull, GraphQLError } from "graphql";
|
|
2
2
|
import { resolveS3Config } from "./Config.js";
|
|
3
|
-
import { S3SignedRead, S3Acl, S3GenerateSignedUploadInput, S3SignedUpload } from "./S3SchemaTypes.js";
|
|
3
|
+
import { S3SignedRead, S3DeletedObject, S3Acl, S3GenerateSignedUploadInput, S3SignedUpload } from "./S3SchemaTypes.js";
|
|
4
4
|
import { S3ObjectAuthorizator } from "./S3ObjectAuthorizator.js";
|
|
5
5
|
class S3SchemaContributor {
|
|
6
6
|
constructor(s3Factory, providers) {
|
|
@@ -22,15 +22,21 @@ class S3SchemaContributor {
|
|
|
22
22
|
const readRules = rules.filter(([, it]) => it.read).map(([it]) => ({
|
|
23
23
|
pattern: it
|
|
24
24
|
}));
|
|
25
|
-
|
|
25
|
+
const deleteRules = rules.filter(([, it]) => it.delete).map(([it]) => ({
|
|
26
|
+
pattern: it
|
|
27
|
+
}));
|
|
28
|
+
if (uploadRules.length === 0 && readRules.length === 0 && deleteRules.length === 0) {
|
|
26
29
|
return void 0;
|
|
27
30
|
}
|
|
28
|
-
const authorizator = new S3ObjectAuthorizator(uploadRules, readRules);
|
|
31
|
+
const authorizator = new S3ObjectAuthorizator(uploadRules, readRules, deleteRules);
|
|
29
32
|
const uploadMutation = this.createUploadMutation(authorizator);
|
|
30
33
|
const readMutation = this.createReadMutation(authorizator);
|
|
34
|
+
const deleteMutation = this.createDeleteMutation(authorizator);
|
|
31
35
|
const mutation = {
|
|
32
36
|
generateUploadUrl: uploadMutation,
|
|
33
|
-
generateReadUrl: readMutation
|
|
37
|
+
generateReadUrl: readMutation,
|
|
38
|
+
// not "deleteObject" — a content mutation for an entity named "Object" would shadow it
|
|
39
|
+
deleteS3Object: deleteMutation
|
|
34
40
|
};
|
|
35
41
|
return {
|
|
36
42
|
mutation: new GraphQLObjectType({
|
|
@@ -68,6 +74,24 @@ class S3SchemaContributor {
|
|
|
68
74
|
}
|
|
69
75
|
};
|
|
70
76
|
}
|
|
77
|
+
createDeleteMutation(authorizator) {
|
|
78
|
+
return {
|
|
79
|
+
type: new GraphQLNonNull(S3DeletedObject),
|
|
80
|
+
args: {
|
|
81
|
+
objectKey: {
|
|
82
|
+
type: new GraphQLNonNull(GraphQLString)
|
|
83
|
+
}
|
|
84
|
+
},
|
|
85
|
+
resolve: async (parent, args, ctx) => {
|
|
86
|
+
if (!ctx.project.s3) {
|
|
87
|
+
throw new GraphQLError("S3 is not configured for this project");
|
|
88
|
+
}
|
|
89
|
+
const s3Config = resolveS3Config(ctx.project.s3);
|
|
90
|
+
const s3 = this.s3Factory.create(s3Config, this.providers, authorizator);
|
|
91
|
+
return await s3.deleteObject({ objectKey: args.objectKey });
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
}
|
|
71
95
|
createUploadMutation(authorizator) {
|
|
72
96
|
return {
|
|
73
97
|
type: new GraphQLNonNull(S3SignedUpload),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"S3SchemaContributor.js","sources":["../../../../packages/engine-s3-plugin/src/S3SchemaContributor.ts"],"sourcesContent":["import {\n\tGraphQLError,\n\tGraphQLFieldConfig,\n\tGraphQLInt,\n\tGraphQLNonNull,\n\tGraphQLObjectType,\n\tGraphQLSchema,\n\tGraphQLSchemaConfig,\n\tGraphQLString,\n} from 'graphql'\nimport { S3Service, S3ServiceFactory } from './S3Service.js'\nimport { Project3Config, resolveS3Config, S3Config } from './Config.js'\nimport { GraphQLSchemaContributor, GraphQLSchemaContributorContext, Providers } from '@contember/engine-plugins'\nimport * as types from './S3SchemaTypes.js'\nimport { S3Acl, S3GenerateSignedUploadInput, S3SignedRead, S3SignedUpload } from './S3SchemaTypes.js'\nimport { S3ObjectAuthorizator } from './S3ObjectAuthorizator.js'\n\ninterface Identity {\n\tprojectRoles: string[]\n}\n\nexport type S3SchemaUploadAcl =\n\t| boolean\n\t| {\n\t\tmaxSize?: number\n\t}\n\nexport type S3SchemaAcl = Record<\n\tstring, // public/*.jpg\n\t{\n\t\tread?: boolean\n\t\tupload?: S3SchemaUploadAcl\n\t}\n>\n\nexport class S3SchemaContributor implements GraphQLSchemaContributor {\n\tconstructor(\n\t\tprivate readonly s3Factory: S3ServiceFactory,\n\t\tprivate readonly providers: Providers,\n\t) {}\n\n\tgetCacheKey?({ project }: GraphQLSchemaContributorContext): string {\n\t\treturn project.s3 ? 'yes' : 'no'\n\t}\n\n\tcreateSchema(context: GraphQLSchemaContributorContext): GraphQLSchemaConfig | undefined {\n\t\tif (!context.project.s3) {\n\t\t\treturn undefined\n\t\t}\n\t\tconst rules = context.identity.projectRoles.flatMap(it => Object.entries((context.schema.acl.roles[it]?.s3 as S3SchemaAcl) || {}))\n\n\t\tconst uploadRules = rules.filter(([, it]) => it.upload).map(([it, val]) => ({\n\t\t\tpattern: it,\n\t\t\t...(typeof val.upload !== 'boolean' ? val.upload : {}),\n\t\t}))\n\t\tconst readRules = rules.filter(([, it]) => it.read).map(([it]) => ({\n\t\t\tpattern: it,\n\t\t}))\n\n\t\tif (uploadRules.length === 0 && readRules.length === 0) {\n\t\t\treturn undefined\n\t\t}\n\n\t\tconst authorizator = new S3ObjectAuthorizator(uploadRules, readRules)\n\t\tconst uploadMutation = this.createUploadMutation(authorizator)\n\t\tconst readMutation = this.createReadMutation(authorizator)\n\t\tconst mutation = {\n\t\t\tgenerateUploadUrl: uploadMutation as GraphQLFieldConfig<any, any, any>,\n\t\t\tgenerateReadUrl: readMutation,\n\t\t}\n\t\treturn {\n\t\t\tmutation: new GraphQLObjectType({\n\t\t\t\tname: 'Mutation',\n\t\t\t\tfields: () => mutation,\n\t\t\t}),\n\t\t\tquery: new GraphQLObjectType({\n\t\t\t\tname: 'Query',\n\t\t\t\tfields: () => ({\n\t\t\t\t\ts3DummyQuery: {\n\t\t\t\t\t\ttype: GraphQLString,\n\t\t\t\t\t},\n\t\t\t\t}),\n\t\t\t}),\n\t\t}\n\t}\n\n\tprivate createReadMutation(authorizator: S3ObjectAuthorizator): GraphQLFieldConfig<any, { project: Project3Config }, any> {\n\t\treturn {\n\t\t\ttype: new GraphQLNonNull(S3SignedRead),\n\t\t\targs: {\n\t\t\t\tobjectKey: {\n\t\t\t\t\ttype: new GraphQLNonNull(GraphQLString),\n\t\t\t\t},\n\t\t\t\texpiration: {\n\t\t\t\t\ttype: GraphQLInt,\n\t\t\t\t},\n\t\t\t},\n\t\t\tresolve: async (parent: any, args: { objectKey: string; expiration?: number }, ctx: { project: Project3Config }) => {\n\t\t\t\tif (!ctx.project.s3) {\n\t\t\t\t\tthrow new GraphQLError('S3 is not configured for this project')\n\t\t\t\t}\n\t\t\t\tconst s3Config = resolveS3Config(ctx.project.s3)\n\t\t\t\tconst s3 = this.s3Factory.create(s3Config, this.providers, authorizator)\n\t\t\t\treturn s3.getSignedReadUrl({ objectKey: args.objectKey, expiration: args.expiration ?? null })\n\t\t\t},\n\t\t} as GraphQLFieldConfig<any, any, any>\n\t}\n\n\tprivate createUploadMutation(authorizator: S3ObjectAuthorizator): GraphQLFieldConfig<any, any, any> {\n\t\treturn {\n\t\t\ttype: new GraphQLNonNull(S3SignedUpload),\n\t\t\targs: {\n\t\t\t\tinput: { type: types.S3GenerateSignedUploadInput },\n\t\t\t\tcontentType: { type: GraphQLString, deprecationReason: 'Use input.contentType' },\n\t\t\t\texpiration: { type: GraphQLInt, deprecationReason: 'Use input.expiration' },\n\t\t\t\tprefix: { type: GraphQLString, deprecationReason: 'Use input.prefix' },\n\t\t\t\tacl: { type: types.S3Acl, deprecationReason: 'Use input.acl' },\n\t\t\t},\n\t\t\tresolve: async (\n\t\t\t\tparent: any,\n\t\t\t\targs: { input?: Partial<S3GenerateSignedUploadInput>; contentType?: string; acl?: S3Acl; expiration?: number; prefix?: string },\n\t\t\t\tctx: { project: Project3Config },\n\t\t\t) => {\n\t\t\t\tif (!ctx.project.s3) {\n\t\t\t\t\tthrow new GraphQLError('S3 is not configured for this project')\n\t\t\t\t}\n\t\t\t\tconst s3Config = resolveS3Config(ctx.project.s3)\n\t\t\t\tconst s3 = this.s3Factory.create(s3Config, this.providers, authorizator)\n\t\t\t\treturn s3.getSignedUploadUrl({\n\t\t\t\t\tacl: args.input?.acl ?? args.acl ?? null,\n\t\t\t\t\tcontentDisposition: args.input?.contentDisposition ?? null,\n\t\t\t\t\tcontentType: args.input?.contentType ?? args.contentType ?? null,\n\t\t\t\t\texpiration: args.input?.expiration ?? args.expiration ?? null,\n\t\t\t\t\textension: args.input?.extension ?? null,\n\t\t\t\t\tfileName: args.input?.fileName ?? null,\n\t\t\t\t\tprefix: args.input?.prefix ?? args.prefix ?? null,\n\t\t\t\t\tsuffix: args.input?.suffix ?? null,\n\t\t\t\t\tsize: args.input?.size ?? null,\n\t\t\t\t})\n\t\t\t},\n\t\t}\n\t}\n}\n"],"names":["types.S3GenerateSignedUploadInput","types.S3Acl"],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"S3SchemaContributor.js","sources":["../../../../packages/engine-s3-plugin/src/S3SchemaContributor.ts"],"sourcesContent":["import {\n\tGraphQLError,\n\tGraphQLFieldConfig,\n\tGraphQLInt,\n\tGraphQLNonNull,\n\tGraphQLObjectType,\n\tGraphQLSchema,\n\tGraphQLSchemaConfig,\n\tGraphQLString,\n} from 'graphql'\nimport { S3Service, S3ServiceFactory } from './S3Service.js'\nimport { Project3Config, resolveS3Config, S3Config } from './Config.js'\nimport { GraphQLSchemaContributor, GraphQLSchemaContributorContext, Providers } from '@contember/engine-plugins'\nimport * as types from './S3SchemaTypes.js'\nimport { S3Acl, S3DeletedObject, S3GenerateSignedUploadInput, S3SignedRead, S3SignedUpload } from './S3SchemaTypes.js'\nimport { S3ObjectAuthorizator } from './S3ObjectAuthorizator.js'\n\ninterface Identity {\n\tprojectRoles: string[]\n}\n\nexport type S3SchemaUploadAcl =\n\t| boolean\n\t| {\n\t\tmaxSize?: number\n\t}\n\nexport type S3SchemaAcl = Record<\n\tstring, // public/*.jpg\n\t{\n\t\tread?: boolean\n\t\tupload?: S3SchemaUploadAcl\n\t\tdelete?: boolean\n\t}\n>\n\nexport class S3SchemaContributor implements GraphQLSchemaContributor {\n\tconstructor(\n\t\tprivate readonly s3Factory: S3ServiceFactory,\n\t\tprivate readonly providers: Providers,\n\t) {}\n\n\tgetCacheKey?({ project }: GraphQLSchemaContributorContext): string {\n\t\treturn project.s3 ? 'yes' : 'no'\n\t}\n\n\tcreateSchema(context: GraphQLSchemaContributorContext): GraphQLSchemaConfig | undefined {\n\t\tif (!context.project.s3) {\n\t\t\treturn undefined\n\t\t}\n\t\tconst rules = context.identity.projectRoles.flatMap(it => Object.entries((context.schema.acl.roles[it]?.s3 as S3SchemaAcl) || {}))\n\n\t\tconst uploadRules = rules.filter(([, it]) => it.upload).map(([it, val]) => ({\n\t\t\tpattern: it,\n\t\t\t...(typeof val.upload !== 'boolean' ? val.upload : {}),\n\t\t}))\n\t\tconst readRules = rules.filter(([, it]) => it.read).map(([it]) => ({\n\t\t\tpattern: it,\n\t\t}))\n\t\tconst deleteRules = rules.filter(([, it]) => it.delete).map(([it]) => ({\n\t\t\tpattern: it,\n\t\t}))\n\n\t\tif (uploadRules.length === 0 && readRules.length === 0 && deleteRules.length === 0) {\n\t\t\treturn undefined\n\t\t}\n\n\t\tconst authorizator = new S3ObjectAuthorizator(uploadRules, readRules, deleteRules)\n\t\tconst uploadMutation = this.createUploadMutation(authorizator)\n\t\tconst readMutation = this.createReadMutation(authorizator)\n\t\tconst deleteMutation = this.createDeleteMutation(authorizator)\n\t\tconst mutation = {\n\t\t\tgenerateUploadUrl: uploadMutation as GraphQLFieldConfig<any, any, any>,\n\t\t\tgenerateReadUrl: readMutation,\n\t\t\t// not \"deleteObject\" — a content mutation for an entity named \"Object\" would shadow it\n\t\t\tdeleteS3Object: deleteMutation,\n\t\t}\n\t\treturn {\n\t\t\tmutation: new GraphQLObjectType({\n\t\t\t\tname: 'Mutation',\n\t\t\t\tfields: () => mutation,\n\t\t\t}),\n\t\t\tquery: new GraphQLObjectType({\n\t\t\t\tname: 'Query',\n\t\t\t\tfields: () => ({\n\t\t\t\t\ts3DummyQuery: {\n\t\t\t\t\t\ttype: GraphQLString,\n\t\t\t\t\t},\n\t\t\t\t}),\n\t\t\t}),\n\t\t}\n\t}\n\n\tprivate createReadMutation(authorizator: S3ObjectAuthorizator): GraphQLFieldConfig<any, { project: Project3Config }, any> {\n\t\treturn {\n\t\t\ttype: new GraphQLNonNull(S3SignedRead),\n\t\t\targs: {\n\t\t\t\tobjectKey: {\n\t\t\t\t\ttype: new GraphQLNonNull(GraphQLString),\n\t\t\t\t},\n\t\t\t\texpiration: {\n\t\t\t\t\ttype: GraphQLInt,\n\t\t\t\t},\n\t\t\t},\n\t\t\tresolve: async (parent: any, args: { objectKey: string; expiration?: number }, ctx: { project: Project3Config }) => {\n\t\t\t\tif (!ctx.project.s3) {\n\t\t\t\t\tthrow new GraphQLError('S3 is not configured for this project')\n\t\t\t\t}\n\t\t\t\tconst s3Config = resolveS3Config(ctx.project.s3)\n\t\t\t\tconst s3 = this.s3Factory.create(s3Config, this.providers, authorizator)\n\t\t\t\treturn s3.getSignedReadUrl({ objectKey: args.objectKey, expiration: args.expiration ?? null })\n\t\t\t},\n\t\t} as GraphQLFieldConfig<any, any, any>\n\t}\n\n\tprivate createDeleteMutation(authorizator: S3ObjectAuthorizator): GraphQLFieldConfig<any, any, any> {\n\t\treturn {\n\t\t\ttype: new GraphQLNonNull(S3DeletedObject),\n\t\t\targs: {\n\t\t\t\tobjectKey: {\n\t\t\t\t\ttype: new GraphQLNonNull(GraphQLString),\n\t\t\t\t},\n\t\t\t},\n\t\t\tresolve: async (parent: any, args: { objectKey: string }, ctx: { project: Project3Config }) => {\n\t\t\t\tif (!ctx.project.s3) {\n\t\t\t\t\tthrow new GraphQLError('S3 is not configured for this project')\n\t\t\t\t}\n\t\t\t\tconst s3Config = resolveS3Config(ctx.project.s3)\n\t\t\t\tconst s3 = this.s3Factory.create(s3Config, this.providers, authorizator)\n\t\t\t\treturn await s3.deleteObject({ objectKey: args.objectKey })\n\t\t\t},\n\t\t}\n\t}\n\n\tprivate createUploadMutation(authorizator: S3ObjectAuthorizator): GraphQLFieldConfig<any, any, any> {\n\t\treturn {\n\t\t\ttype: new GraphQLNonNull(S3SignedUpload),\n\t\t\targs: {\n\t\t\t\tinput: { type: types.S3GenerateSignedUploadInput },\n\t\t\t\tcontentType: { type: GraphQLString, deprecationReason: 'Use input.contentType' },\n\t\t\t\texpiration: { type: GraphQLInt, deprecationReason: 'Use input.expiration' },\n\t\t\t\tprefix: { type: GraphQLString, deprecationReason: 'Use input.prefix' },\n\t\t\t\tacl: { type: types.S3Acl, deprecationReason: 'Use input.acl' },\n\t\t\t},\n\t\t\tresolve: async (\n\t\t\t\tparent: any,\n\t\t\t\targs: { input?: Partial<S3GenerateSignedUploadInput>; contentType?: string; acl?: S3Acl; expiration?: number; prefix?: string },\n\t\t\t\tctx: { project: Project3Config },\n\t\t\t) => {\n\t\t\t\tif (!ctx.project.s3) {\n\t\t\t\t\tthrow new GraphQLError('S3 is not configured for this project')\n\t\t\t\t}\n\t\t\t\tconst s3Config = resolveS3Config(ctx.project.s3)\n\t\t\t\tconst s3 = this.s3Factory.create(s3Config, this.providers, authorizator)\n\t\t\t\treturn s3.getSignedUploadUrl({\n\t\t\t\t\tacl: args.input?.acl ?? args.acl ?? null,\n\t\t\t\t\tcontentDisposition: args.input?.contentDisposition ?? null,\n\t\t\t\t\tcontentType: args.input?.contentType ?? args.contentType ?? null,\n\t\t\t\t\texpiration: args.input?.expiration ?? args.expiration ?? null,\n\t\t\t\t\textension: args.input?.extension ?? null,\n\t\t\t\t\tfileName: args.input?.fileName ?? null,\n\t\t\t\t\tprefix: args.input?.prefix ?? args.prefix ?? null,\n\t\t\t\t\tsuffix: args.input?.suffix ?? null,\n\t\t\t\t\tsize: args.input?.size ?? null,\n\t\t\t\t})\n\t\t\t},\n\t\t}\n\t}\n}\n"],"names":["types.S3GenerateSignedUploadInput","types.S3Acl"],"mappings":";;;;AAoCO,MAAM,oBAAwD;AAAA,EACpE,YACkB,WACA,WAChB;AAFgB,SAAA,YAAA;AACA,SAAA,YAAA;AAAA,EACf;AAAA,EAEH,YAAa,EAAE,WAAoD;AAClE,WAAO,QAAQ,KAAK,QAAQ;AAAA,EAC7B;AAAA,EAEA,aAAa,SAA2E;AACvF,QAAI,CAAC,QAAQ,QAAQ,IAAI;AACxB,aAAO;AAAA,IACR;AACA,UAAM,QAAQ,QAAQ,SAAS,aAAa,QAAQ,QAAM,OAAO,QAAS,QAAQ,OAAO,IAAI,MAAM,EAAE,GAAG,MAAsB,CAAA,CAAE,CAAC;AAEjI,UAAM,cAAc,MAAM,OAAO,CAAC,CAAA,EAAG,EAAE,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mB,gBAAA;AAAA,MAAgB;AAAA,MAE9D,SAAS,OACR,QACA,MACA,QACI;AACJ,YAAI,CAAC,IAAI,QAAQ,IAAI;AACpB,gBAAM,IAAI,aAAa,uCAAuC;AAAA,QAC/D;AACA,cAAM,WAAW,gBAAgB,IAAI,QAAQ,EAAE;AAC/C,cAAM,KAAK,KAAK,UAAU,OAAO,UAAU,KAAK,WAAW,YAAY;AACvE,eAAO,GAAG,mBAAmB;AAAA,UAC5B,KAAK,KAAK,OAAO,OAAO,KAAK,OAAO;AAAA,UACpC,oBAAoB,KAAK,OAAO,sBAAsB;AAAA,UACtD,aAAa,KAAK,OAAO,eAAe,KAAK,eAAe;AAAA,UAC5D,YAAY,KAAK,OAAO,cAAc,KAAK,cAAc;AAAA,UACzD,WAAW,KAAK,OAAO,aAAa;AAAA,UACpC,UAAU,KAAK,OAAO,YAAY;AAAA,UAClC,QAAQ,KAAK,OAAO,UAAU,KAAK,UAAU;AAAA,UAC7C,QAAQ,KAAK,OAAO,UAAU;AAAA,UAC9B,MAAM,KAAK,OAAO,QAAQ;AAAA,QAAA,CAC1B;AAAA,MACF;AAAA,IAAA;AAAA,EAEF;AACD;"}
|
|
@@ -40,6 +40,13 @@ const S3SignedUpload = new graphql.GraphQLObjectType({
|
|
|
40
40
|
publicUrl: { type: new graphql.GraphQLNonNull(graphql.GraphQLString) }
|
|
41
41
|
}
|
|
42
42
|
});
|
|
43
|
+
const S3DeletedObject = new graphql.GraphQLObjectType({
|
|
44
|
+
name: "S3DeletedObject",
|
|
45
|
+
fields: {
|
|
46
|
+
objectKey: { type: new graphql.GraphQLNonNull(graphql.GraphQLString) },
|
|
47
|
+
bucket: { type: new graphql.GraphQLNonNull(graphql.GraphQLString) }
|
|
48
|
+
}
|
|
49
|
+
});
|
|
43
50
|
const S3Acl = new graphql.GraphQLEnumType({
|
|
44
51
|
name: "S3Acl",
|
|
45
52
|
values: {
|
|
@@ -64,6 +71,7 @@ const S3GenerateSignedUploadInput = new graphql.GraphQLInputObjectType({
|
|
|
64
71
|
});
|
|
65
72
|
exports.S3Acl = S3Acl;
|
|
66
73
|
exports.S3ContentDisposition = S3ContentDisposition;
|
|
74
|
+
exports.S3DeletedObject = S3DeletedObject;
|
|
67
75
|
exports.S3GenerateSignedUploadInput = S3GenerateSignedUploadInput;
|
|
68
76
|
exports.S3Header = S3Header;
|
|
69
77
|
exports.S3SignedRead = S3SignedRead;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"S3SchemaTypes.cjs","sources":["../../../../packages/engine-s3-plugin/src/S3SchemaTypes.ts"],"sourcesContent":["import { GraphQLEnumType, GraphQLInputObjectType, GraphQLInt, GraphQLList, GraphQLNonNull, GraphQLObjectType, GraphQLString } from 'graphql'\n\nexport const S3Header = new GraphQLObjectType({\n\tname: 'S3Header',\n\tfields: {\n\t\tkey: { type: new GraphQLNonNull(GraphQLString) },\n\t\tvalue: { type: new GraphQLNonNull(GraphQLString) },\n\t},\n})\n\nexport const S3ContentDisposition = new GraphQLEnumType({\n\tname: 'S33ContentDisposition',\n\tvalues: {\n\t\tATTACHMENT: {},\n\t\tINLINE: {},\n\t},\n})\nexport type S3ContentDisposition = 'ATTACHMENT' | 'INLINE'\n\nexport const S3SignedRead = new GraphQLObjectType({\n\tname: 'S3SignedRead',\n\tfields: {\n\t\turl: { type: new GraphQLNonNull(GraphQLString) },\n\t\theaders: {\n\t\t\ttype: new GraphQLNonNull(new GraphQLList(new GraphQLNonNull(S3Header))),\n\t\t},\n\t\tmethod: { type: new GraphQLNonNull(GraphQLString) },\n\t\tobjectKey: { type: new GraphQLNonNull(GraphQLString) },\n\t\tbucket: { type: new GraphQLNonNull(GraphQLString) },\n\t},\n})\n\nexport const S3SignedUpload = new GraphQLObjectType({\n\tname: 'S3SignedUpload',\n\tfields: {\n\t\turl: { type: new GraphQLNonNull(GraphQLString) },\n\t\theaders: {\n\t\t\ttype: new GraphQLNonNull(new GraphQLList(new GraphQLNonNull(S3Header))),\n\t\t},\n\t\tmethod: { type: new GraphQLNonNull(GraphQLString) },\n\t\tobjectKey: { type: new GraphQLNonNull(GraphQLString) },\n\t\tbucket: { type: new GraphQLNonNull(GraphQLString) },\n\t\tpublicUrl: { type: new GraphQLNonNull(GraphQLString) },\n\t},\n})\n\nexport const S3Acl = new GraphQLEnumType({\n\tname: 'S3Acl',\n\tvalues: {\n\t\tPUBLIC_READ: {},\n\t\tPRIVATE: {},\n\t\tNONE: {},\n\t},\n})\n\nexport type S3Acl = 'PUBLIC_READ' | 'PRIVATE' | 'NONE'\n\nexport const S3GenerateSignedUploadInput = new GraphQLInputObjectType({\n\tname: 'S3GenerateSignedUploadInput',\n\tfields: {\n\t\tcontentType: { type: GraphQLString },\n\t\textension: { type: GraphQLString, description: 'If not provided, extension is detected from a content-type.' },\n\t\texpiration: { type: GraphQLInt, description: 'Signed URL expiration.' },\n\t\tsize: { type: GraphQLInt, description: 'Uploaded file size. Required when you enable ACL size limits.' },\n\t\tprefix: { type: GraphQLString, description: 'Can be used as a \"directory\".' },\n\t\tsuffix: { type: GraphQLString, description: 'Suffix after generated id and before the extension.' },\n\t\tfileName: { type: GraphQLString, description: 'This only affects Content-disposition header. Does not affect actual object key.' },\n\t\tcontentDisposition: { type: S3ContentDisposition },\n\t\tacl: { type: S3Acl, description: 'If not supported by S3 provider, an error is thrown.' },\n\t},\n})\nexport interface S3GenerateSignedUploadInput {\n\tcontentType: null | string\n\textension: null | string\n\texpiration: null | number\n\tsize: null | number\n\tprefix: null | string\n\tsuffix: null | string\n\tfileName: null | string\n\tcontentDisposition: null | S3ContentDisposition\n\tacl: null | S3Acl\n}\n"],"names":["GraphQLObjectType","GraphQLNonNull","GraphQLString","GraphQLEnumType","GraphQLList","GraphQLInputObjectType","GraphQLInt"],"mappings":";;;AAEO,MAAM,WAAW,IAAIA,QAAAA,kBAAkB;AAAA,EAC7C,MAAM;AAAA,EACN,QAAQ;AAAA,IACP,KAAK,EAAE,MAAM,IAAIC,QAAAA,eAAeC,QAAA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,QAAAA,eAAeC,QAAAA,aAAa,EAAA;AAAA,IAChD,WAAW,EAAE,MAAM,IAAID,QAAAA,eAAeC,QAAAA,aAAa,EAAA;AAAA,EAAE;AAEvD,CAAC;AAEM,MAAM,QAAQ,IAAIC,QAAAA,gBAAgB;AAAA,EACxC,MAAM;AAAA,EACN,QAAQ;AAAA,IACP,aAAa,CAAA;AAAA,IACb,SAAS,CAAA;AAAA,IACT,MAAM,CAAA;AAAA,EAAC;AAET,CAAC;AAIM,MAAM,8BAA8B,IAAIE,QAAAA,uBAAuB;AAAA,EACrE,MAAM;AAAA,EACN,QAAQ;AAAA,IACP,aAAa,EAAE,MAAMH,sBAAA;AAAA,IACrB,WAAW,EAAE,MAAMA,uBAAe,aAAa,8DAAA;AAAA,IAC/C,YAAY,EAAE,MAAMI,oBAAY,aAAa,yBAAA;AAAA,IAC7C,MAAM,EAAE,MAAMA,oBAAY,aAAa,gEAAA;AAAA,IACvC,QAAQ,EAAE,MAAMJ,uBAAe,aAAa,gCAAA;AAAA,IAC5C,QAAQ,EAAE,MAAMA,uBAAe,aAAa,sDAAA;AAAA,IAC5C,UAAU,EAAE,MAAMA,uBAAe,aAAa,mFAAA;AAAA,IAC9C,oBAAoB,EAAE,MAAM,qBAAA;AAAA,IAC5B,KAAK,EAAE,MAAM,OAAO,aAAa,uDAAA;AAAA,EAAuD;AAE1F,CAAC
|
|
1
|
+
{"version":3,"file":"S3SchemaTypes.cjs","sources":["../../../../packages/engine-s3-plugin/src/S3SchemaTypes.ts"],"sourcesContent":["import { GraphQLEnumType, GraphQLInputObjectType, GraphQLInt, GraphQLList, GraphQLNonNull, GraphQLObjectType, GraphQLString } from 'graphql'\n\nexport const S3Header = new GraphQLObjectType({\n\tname: 'S3Header',\n\tfields: {\n\t\tkey: { type: new GraphQLNonNull(GraphQLString) },\n\t\tvalue: { type: new GraphQLNonNull(GraphQLString) },\n\t},\n})\n\nexport const S3ContentDisposition = new GraphQLEnumType({\n\tname: 'S33ContentDisposition',\n\tvalues: {\n\t\tATTACHMENT: {},\n\t\tINLINE: {},\n\t},\n})\nexport type S3ContentDisposition = 'ATTACHMENT' | 'INLINE'\n\nexport const S3SignedRead = new GraphQLObjectType({\n\tname: 'S3SignedRead',\n\tfields: {\n\t\turl: { type: new GraphQLNonNull(GraphQLString) },\n\t\theaders: {\n\t\t\ttype: new GraphQLNonNull(new GraphQLList(new GraphQLNonNull(S3Header))),\n\t\t},\n\t\tmethod: { type: new GraphQLNonNull(GraphQLString) },\n\t\tobjectKey: { type: new GraphQLNonNull(GraphQLString) },\n\t\tbucket: { type: new GraphQLNonNull(GraphQLString) },\n\t},\n})\n\nexport const S3SignedUpload = new GraphQLObjectType({\n\tname: 'S3SignedUpload',\n\tfields: {\n\t\turl: { type: new GraphQLNonNull(GraphQLString) },\n\t\theaders: {\n\t\t\ttype: new GraphQLNonNull(new GraphQLList(new GraphQLNonNull(S3Header))),\n\t\t},\n\t\tmethod: { type: new GraphQLNonNull(GraphQLString) },\n\t\tobjectKey: { type: new GraphQLNonNull(GraphQLString) },\n\t\tbucket: { type: new GraphQLNonNull(GraphQLString) },\n\t\tpublicUrl: { type: new GraphQLNonNull(GraphQLString) },\n\t},\n})\n\nexport const S3DeletedObject = new GraphQLObjectType({\n\tname: 'S3DeletedObject',\n\tfields: {\n\t\tobjectKey: { type: new GraphQLNonNull(GraphQLString) },\n\t\tbucket: { type: new GraphQLNonNull(GraphQLString) },\n\t},\n})\n\nexport const S3Acl = new GraphQLEnumType({\n\tname: 'S3Acl',\n\tvalues: {\n\t\tPUBLIC_READ: {},\n\t\tPRIVATE: {},\n\t\tNONE: {},\n\t},\n})\n\nexport type S3Acl = 'PUBLIC_READ' | 'PRIVATE' | 'NONE'\n\nexport const S3GenerateSignedUploadInput = new GraphQLInputObjectType({\n\tname: 'S3GenerateSignedUploadInput',\n\tfields: {\n\t\tcontentType: { type: GraphQLString },\n\t\textension: { type: GraphQLString, description: 'If not provided, extension is detected from a content-type.' },\n\t\texpiration: { type: GraphQLInt, description: 'Signed URL expiration.' },\n\t\tsize: { type: GraphQLInt, description: 'Uploaded file size. Required when you enable ACL size limits.' },\n\t\tprefix: { type: GraphQLString, description: 'Can be used as a \"directory\".' },\n\t\tsuffix: { type: GraphQLString, description: 'Suffix after generated id and before the extension.' },\n\t\tfileName: { type: GraphQLString, description: 'This only affects Content-disposition header. Does not affect actual object key.' },\n\t\tcontentDisposition: { type: S3ContentDisposition },\n\t\tacl: { type: S3Acl, description: 'If not supported by S3 provider, an error is thrown.' },\n\t},\n})\nexport interface S3GenerateSignedUploadInput {\n\tcontentType: null | string\n\textension: null | string\n\texpiration: null | number\n\tsize: null | number\n\tprefix: null | string\n\tsuffix: null | string\n\tfileName: null | string\n\tcontentDisposition: null | S3ContentDisposition\n\tacl: null | S3Acl\n}\n"],"names":["GraphQLObjectType","GraphQLNonNull","GraphQLString","GraphQLEnumType","GraphQLList","GraphQLInputObjectType","GraphQLInt"],"mappings":";;;AAEO,MAAM,WAAW,IAAIA,QAAAA,kBAAkB;AAAA,EAC7C,MAAM;AAAA,EACN,QAAQ;AAAA,IACP,KAAK,EAAE,MAAM,IAAIC,QAAAA,eAAeC,QAAAA,aAAa,EAAA;AAAA,IAC7C,OAAO,EAAE,MAAM,IAAID,QAAAA,eAAeC,QAAAA,aAAa,EAAA;AAAA,EAAE;AAEnD,CAAC;AAEM,MAAM,uBAAuB,IAAIC,QAAAA,gBAAgB;AAAA,EACvD,MAAM;AAAA,EACN,QAAQ;AAAA,IACP,YAAY,CAAA;AAAA,IACZ,QAAQ,CAAA;AAAA,EAAC;AAEX,CAAC;AAGM,MAAM,eAAe,IAAIH,QAAAA,kBAAkB;AAAA,EACjD,MAAM;AAAA,EACN,QAAQ;AAAA,IACP,KAAK,EAAE,MAAM,IAAIC,QAAAA,eAAeC,QAAAA,aAAa,EAAA;AAAA,IAC7C,SAAS;AAAA,MACR,MAAM,IAAID,QAAAA,eAAe,IAAIG,QAAAA,YAAY,IAAIH,QAAAA,eAAe,Q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ACT,MAAM,CAAA;AAAA,EAAC;AAET,CAAC;AAIM,MAAM,8BAA8B,IAAIE,QAAAA,uBAAuB;AAAA,EACrE,MAAM;AAAA,EACN,QAAQ;AAAA,IACP,aAAa,EAAE,MAAMH,sBAAA;AAAA,IACrB,WAAW,EAAE,MAAMA,uBAAe,aAAa,8DAAA;AAAA,IAC/C,YAAY,EAAE,MAAMI,oBAAY,aAAa,yBAAA;AAAA,IAC7C,MAAM,EAAE,MAAMA,oBAAY,aAAa,gEAAA;AAAA,IACvC,QAAQ,EAAE,MAAMJ,uBAAe,aAAa,gCAAA;AAAA,IAC5C,QAAQ,EAAE,MAAMA,uBAAe,aAAa,sDAAA;AAAA,IAC5C,UAAU,EAAE,MAAMA,uBAAe,aAAa,mFAAA;AAAA,IAC9C,oBAAoB,EAAE,MAAM,qBAAA;AAAA,IAC5B,KAAK,EAAE,MAAM,OAAO,aAAa,uDAAA;AAAA,EAAuD;AAE1F,CAAC;;;;;;;;"}
|
|
@@ -38,6 +38,13 @@ const S3SignedUpload = new GraphQLObjectType({
|
|
|
38
38
|
publicUrl: { type: new GraphQLNonNull(GraphQLString) }
|
|
39
39
|
}
|
|
40
40
|
});
|
|
41
|
+
const S3DeletedObject = new GraphQLObjectType({
|
|
42
|
+
name: "S3DeletedObject",
|
|
43
|
+
fields: {
|
|
44
|
+
objectKey: { type: new GraphQLNonNull(GraphQLString) },
|
|
45
|
+
bucket: { type: new GraphQLNonNull(GraphQLString) }
|
|
46
|
+
}
|
|
47
|
+
});
|
|
41
48
|
const S3Acl = new GraphQLEnumType({
|
|
42
49
|
name: "S3Acl",
|
|
43
50
|
values: {
|
|
@@ -63,6 +70,7 @@ const S3GenerateSignedUploadInput = new GraphQLInputObjectType({
|
|
|
63
70
|
export {
|
|
64
71
|
S3Acl,
|
|
65
72
|
S3ContentDisposition,
|
|
73
|
+
S3DeletedObject,
|
|
66
74
|
S3GenerateSignedUploadInput,
|
|
67
75
|
S3Header,
|
|
68
76
|
S3SignedRead,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"S3SchemaTypes.js","sources":["../../../../packages/engine-s3-plugin/src/S3SchemaTypes.ts"],"sourcesContent":["import { GraphQLEnumType, GraphQLInputObjectType, GraphQLInt, GraphQLList, GraphQLNonNull, GraphQLObjectType, GraphQLString } from 'graphql'\n\nexport const S3Header = new GraphQLObjectType({\n\tname: 'S3Header',\n\tfields: {\n\t\tkey: { type: new GraphQLNonNull(GraphQLString) },\n\t\tvalue: { type: new GraphQLNonNull(GraphQLString) },\n\t},\n})\n\nexport const S3ContentDisposition = new GraphQLEnumType({\n\tname: 'S33ContentDisposition',\n\tvalues: {\n\t\tATTACHMENT: {},\n\t\tINLINE: {},\n\t},\n})\nexport type S3ContentDisposition = 'ATTACHMENT' | 'INLINE'\n\nexport const S3SignedRead = new GraphQLObjectType({\n\tname: 'S3SignedRead',\n\tfields: {\n\t\turl: { type: new GraphQLNonNull(GraphQLString) },\n\t\theaders: {\n\t\t\ttype: new GraphQLNonNull(new GraphQLList(new GraphQLNonNull(S3Header))),\n\t\t},\n\t\tmethod: { type: new GraphQLNonNull(GraphQLString) },\n\t\tobjectKey: { type: new GraphQLNonNull(GraphQLString) },\n\t\tbucket: { type: new GraphQLNonNull(GraphQLString) },\n\t},\n})\n\nexport const S3SignedUpload = new GraphQLObjectType({\n\tname: 'S3SignedUpload',\n\tfields: {\n\t\turl: { type: new GraphQLNonNull(GraphQLString) },\n\t\theaders: {\n\t\t\ttype: new GraphQLNonNull(new GraphQLList(new GraphQLNonNull(S3Header))),\n\t\t},\n\t\tmethod: { type: new GraphQLNonNull(GraphQLString) },\n\t\tobjectKey: { type: new GraphQLNonNull(GraphQLString) },\n\t\tbucket: { type: new GraphQLNonNull(GraphQLString) },\n\t\tpublicUrl: { type: new GraphQLNonNull(GraphQLString) },\n\t},\n})\n\nexport const S3Acl = new GraphQLEnumType({\n\tname: 'S3Acl',\n\tvalues: {\n\t\tPUBLIC_READ: {},\n\t\tPRIVATE: {},\n\t\tNONE: {},\n\t},\n})\n\nexport type S3Acl = 'PUBLIC_READ' | 'PRIVATE' | 'NONE'\n\nexport const S3GenerateSignedUploadInput = new GraphQLInputObjectType({\n\tname: 'S3GenerateSignedUploadInput',\n\tfields: {\n\t\tcontentType: { type: GraphQLString },\n\t\textension: { type: GraphQLString, description: 'If not provided, extension is detected from a content-type.' },\n\t\texpiration: { type: GraphQLInt, description: 'Signed URL expiration.' },\n\t\tsize: { type: GraphQLInt, description: 'Uploaded file size. Required when you enable ACL size limits.' },\n\t\tprefix: { type: GraphQLString, description: 'Can be used as a \"directory\".' },\n\t\tsuffix: { type: GraphQLString, description: 'Suffix after generated id and before the extension.' },\n\t\tfileName: { type: GraphQLString, description: 'This only affects Content-disposition header. Does not affect actual object key.' },\n\t\tcontentDisposition: { type: S3ContentDisposition },\n\t\tacl: { type: S3Acl, description: 'If not supported by S3 provider, an error is thrown.' },\n\t},\n})\nexport interface S3GenerateSignedUploadInput {\n\tcontentType: null | string\n\textension: null | string\n\texpiration: null | number\n\tsize: null | number\n\tprefix: null | string\n\tsuffix: null | string\n\tfileName: null | string\n\tcontentDisposition: null | S3ContentDisposition\n\tacl: null | S3Acl\n}\n"],"names":[],"mappings":";AAEO,MAAM,WAAW,IAAI,kBAAkB;AAAA,EAC7C,MAAM;AAAA,EACN,QAAQ;AAAA,IACP,KAAK,EAAE,MAAM,IAAI,eAAe,aAAa,EAAA;AAAA,IAC7C,OAAO,EAAE,MAAM,IAAI,eAAe,aAAa,EAAA;AAAA,EAAE;AAEnD,CAAC;AAEM,MAAM,uBAAuB,IAAI,gBAAgB;AAAA,EACvD,MAAM;AAAA,EACN,QAAQ;AAAA,IACP,YAAY,CAAA;AAAA,IACZ,QAAQ,CAAA;AAAA,EAAC;AAEX,CAAC;AAGM,MAAM,eAAe,IAAI,kBAAkB;AAAA,EACjD,MAAM;AAAA,EACN,QAAQ;AAAA,IACP,KAAK,EAAE,MAAM,IAAI,eAAe,aAAa,EAAA;AAA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AAAA,IAC5C,QAAQ,EAAE,MAAM,eAAe,aAAa,sDAAA;AAAA,IAC5C,UAAU,EAAE,MAAM,eAAe,aAAa,mFAAA;AAAA,IAC9C,oBAAoB,EAAE,MAAM,qBAAA;AAAA,IAC5B,KAAK,EAAE,MAAM,OAAO,aAAa,uDAAA;AAAA,EAAuD;AAE1F,CAAC;"}
|
|
1
|
+
{"version":3,"file":"S3SchemaTypes.js","sources":["../../../../packages/engine-s3-plugin/src/S3SchemaTypes.ts"],"sourcesContent":["import { GraphQLEnumType, GraphQLInputObjectType, GraphQLInt, GraphQLList, GraphQLNonNull, GraphQLObjectType, GraphQLString } from 'graphql'\n\nexport const S3Header = new GraphQLObjectType({\n\tname: 'S3Header',\n\tfields: {\n\t\tkey: { type: new GraphQLNonNull(GraphQLString) },\n\t\tvalue: { type: new GraphQLNonNull(GraphQLString) },\n\t},\n})\n\nexport const S3ContentDisposition = new GraphQLEnumType({\n\tname: 'S33ContentDisposition',\n\tvalues: {\n\t\tATTACHMENT: {},\n\t\tINLINE: {},\n\t},\n})\nexport type S3ContentDisposition = 'ATTACHMENT' | 'INLINE'\n\nexport const S3SignedRead = new GraphQLObjectType({\n\tname: 'S3SignedRead',\n\tfields: {\n\t\turl: { type: new GraphQLNonNull(GraphQLString) },\n\t\theaders: {\n\t\t\ttype: new GraphQLNonNull(new GraphQLList(new GraphQLNonNull(S3Header))),\n\t\t},\n\t\tmethod: { type: new GraphQLNonNull(GraphQLString) },\n\t\tobjectKey: { type: new GraphQLNonNull(GraphQLString) },\n\t\tbucket: { type: new GraphQLNonNull(GraphQLString) },\n\t},\n})\n\nexport const S3SignedUpload = new GraphQLObjectType({\n\tname: 'S3SignedUpload',\n\tfields: {\n\t\turl: { type: new GraphQLNonNull(GraphQLString) },\n\t\theaders: {\n\t\t\ttype: new GraphQLNonNull(new GraphQLList(new GraphQLNonNull(S3Header))),\n\t\t},\n\t\tmethod: { type: new GraphQLNonNull(GraphQLString) },\n\t\tobjectKey: { type: new GraphQLNonNull(GraphQLString) },\n\t\tbucket: { type: new GraphQLNonNull(GraphQLString) },\n\t\tpublicUrl: { type: new GraphQLNonNull(GraphQLString) },\n\t},\n})\n\nexport const S3DeletedObject = new GraphQLObjectType({\n\tname: 'S3DeletedObject',\n\tfields: {\n\t\tobjectKey: { type: new GraphQLNonNull(GraphQLString) },\n\t\tbucket: { type: new GraphQLNonNull(GraphQLString) },\n\t},\n})\n\nexport const S3Acl = new GraphQLEnumType({\n\tname: 'S3Acl',\n\tvalues: {\n\t\tPUBLIC_READ: {},\n\t\tPRIVATE: {},\n\t\tNONE: {},\n\t},\n})\n\nexport type S3Acl = 'PUBLIC_READ' | 'PRIVATE' | 'NONE'\n\nexport const S3GenerateSignedUploadInput = new GraphQLInputObjectType({\n\tname: 'S3GenerateSignedUploadInput',\n\tfields: {\n\t\tcontentType: { type: GraphQLString },\n\t\textension: { type: GraphQLString, description: 'If not provided, extension is detected from a content-type.' },\n\t\texpiration: { type: GraphQLInt, description: 'Signed URL expiration.' },\n\t\tsize: { type: GraphQLInt, description: 'Uploaded file size. Required when you enable ACL size limits.' },\n\t\tprefix: { type: GraphQLString, description: 'Can be used as a \"directory\".' },\n\t\tsuffix: { type: GraphQLString, description: 'Suffix after generated id and before the extension.' },\n\t\tfileName: { type: GraphQLString, description: 'This only affects Content-disposition header. Does not affect actual object key.' },\n\t\tcontentDisposition: { type: S3ContentDisposition },\n\t\tacl: { type: S3Acl, description: 'If not supported by S3 provider, an error is thrown.' },\n\t},\n})\nexport interface S3GenerateSignedUploadInput {\n\tcontentType: null | string\n\textension: null | string\n\texpiration: null | number\n\tsize: null | number\n\tprefix: null | string\n\tsuffix: null | string\n\tfileName: null | string\n\tcontentDisposition: null | S3ContentDisposition\n\tacl: null | S3Acl\n}\n"],"names":[],"mappings":";AAEO,MAAM,WAAW,IAAI,kBAAkB;AAAA,EAC7C,MAAM;AAAA,EACN,QAAQ;AAAA,IACP,KAAK,EAAE,MAAM,IAAI,eAAe,aAAa,EA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a,EAAA;AAAA,IACnD,QAAQ,EAAE,MAAM,IAAI,eAAe,aAAa,EAAA;AAAA,EAAE;AAEpD,CAAC;AAEM,MAAM,QAAQ,IAAI,gBAAgB;AAAA,EACxC,MAAM;AAAA,EACN,QAAQ;AAAA,IACP,aAAa,CAAA;AAAA,IACb,SAAS,CAAA;AAAA,IACT,MAAM,CAAA;AAAA,EAAC;AAET,CAAC;AAIM,MAAM,8BAA8B,IAAI,uBAAuB;AAAA,EACrE,MAAM;AAAA,EACN,QAAQ;AAAA,IACP,aAAa,EAAE,MAAM,cAAA;AAAA,IACrB,WAAW,EAAE,MAAM,eAAe,aAAa,8DAAA;AAAA,IAC/C,YAAY,EAAE,MAAM,YAAY,aAAa,yBAAA;AAAA,IAC7C,MAAM,EAAE,MAAM,YAAY,aAAa,gEAAA;AAAA,IACvC,QAAQ,EAAE,MAAM,eAAe,aAAa,gCAAA;AAAA,IAC5C,QAAQ,EAAE,MAAM,eAAe,aAAa,sDAAA;AAAA,IAC5C,UAAU,EAAE,MAAM,eAAe,aAAa,mFAAA;AAAA,IAC9C,oBAAoB,EAAE,MAAM,qBAAA;AAAA,IAC5B,KAAK,EAAE,MAAM,OAAO,aAAa,uDAAA;AAAA,EAAuD;AAE1F,CAAC;"}
|
|
@@ -7,11 +7,14 @@ const S3Signer = require("./S3Signer.cjs");
|
|
|
7
7
|
var __defProp = Object.defineProperty;
|
|
8
8
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
9
9
|
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
10
|
+
const deleteUrlExpiration = 60;
|
|
11
|
+
const deleteTimeoutMs = 1e4;
|
|
10
12
|
class S3Service {
|
|
11
|
-
constructor(config, providers, authorizator) {
|
|
13
|
+
constructor(config, providers, authorizator, fetch = (url, init) => globalThis.fetch(url, init)) {
|
|
12
14
|
this.config = config;
|
|
13
15
|
this.providers = providers;
|
|
14
16
|
this.authorizator = authorizator;
|
|
17
|
+
this.fetch = fetch;
|
|
15
18
|
__publicField(this, "publicBaseUrl");
|
|
16
19
|
__publicField(this, "signer");
|
|
17
20
|
this.publicBaseUrl = Config.resolveS3PublicBaseUrl(config);
|
|
@@ -66,34 +69,61 @@ class S3Service {
|
|
|
66
69
|
}
|
|
67
70
|
getSignedReadUrl({ objectKey, expiration }) {
|
|
68
71
|
const bucket = this.config.bucket;
|
|
69
|
-
const
|
|
70
|
-
|
|
71
|
-
objectKey = objectKey.substring(publicPrefix.length);
|
|
72
|
-
}
|
|
73
|
-
if (this.config.prefix && !objectKey.startsWith(this.config.prefix)) {
|
|
74
|
-
throw new graphqlUtils.ForbiddenError(
|
|
75
|
-
`Given object key "${objectKey}" does not start with a project prefix "${this.config.prefix}"`
|
|
76
|
-
);
|
|
77
|
-
}
|
|
78
|
-
const localObjectKey = this.config.prefix ? objectKey.substring(this.config.prefix.length + 1) : objectKey;
|
|
79
|
-
this.authorizator.verifyReadAccess({ key: localObjectKey });
|
|
72
|
+
const resolved = this.resolveObjectKey(objectKey);
|
|
73
|
+
this.authorizator.verifyReadAccess({ key: resolved.localObjectKey });
|
|
80
74
|
const url = this.signer.sign({
|
|
81
75
|
action: "read",
|
|
82
76
|
expiration: expiration ?? 3600,
|
|
83
|
-
key: objectKey,
|
|
77
|
+
key: resolved.objectKey,
|
|
84
78
|
headers: {}
|
|
85
79
|
});
|
|
86
80
|
return {
|
|
87
81
|
bucket,
|
|
88
|
-
objectKey,
|
|
82
|
+
objectKey: resolved.objectKey,
|
|
89
83
|
url,
|
|
90
84
|
headers: [],
|
|
91
85
|
method: "GET"
|
|
92
86
|
};
|
|
93
87
|
}
|
|
88
|
+
/**
|
|
89
|
+
* Unlike an upload or a read, a delete carries no payload, so the signed URL never leaves the server.
|
|
90
|
+
*/
|
|
91
|
+
async deleteObject({ objectKey }) {
|
|
92
|
+
const bucket = this.config.bucket;
|
|
93
|
+
const resolved = this.resolveObjectKey(objectKey);
|
|
94
|
+
this.authorizator.verifyDeleteAccess({ key: resolved.localObjectKey });
|
|
95
|
+
const url = this.signer.sign({
|
|
96
|
+
action: "delete",
|
|
97
|
+
expiration: deleteUrlExpiration,
|
|
98
|
+
key: resolved.objectKey,
|
|
99
|
+
headers: {}
|
|
100
|
+
});
|
|
101
|
+
const response = await this.fetch(url, { method: "DELETE", signal: AbortSignal.timeout(deleteTimeoutMs) });
|
|
102
|
+
if (!response.ok) {
|
|
103
|
+
throw new Error(`Failed to delete an object "${resolved.objectKey}": S3 responded with ${response.status}: ${await response.text()}`);
|
|
104
|
+
}
|
|
105
|
+
return {
|
|
106
|
+
bucket,
|
|
107
|
+
objectKey: resolved.objectKey
|
|
108
|
+
};
|
|
109
|
+
}
|
|
94
110
|
formatPublicUrl(key) {
|
|
95
111
|
return `${this.publicBaseUrl}/${key}`;
|
|
96
112
|
}
|
|
113
|
+
resolveObjectKey(objectKey) {
|
|
114
|
+
const publicPrefix = this.formatPublicUrl("");
|
|
115
|
+
if (objectKey.startsWith(publicPrefix)) {
|
|
116
|
+
objectKey = objectKey.substring(publicPrefix.length);
|
|
117
|
+
}
|
|
118
|
+
const prefix = this.config.prefix ? this.config.prefix + "/" : "";
|
|
119
|
+
if (prefix && !objectKey.startsWith(prefix)) {
|
|
120
|
+
throw new graphqlUtils.ForbiddenError(
|
|
121
|
+
`Given object key "${objectKey}" does not start with a project prefix "${this.config.prefix}"`
|
|
122
|
+
);
|
|
123
|
+
}
|
|
124
|
+
const localObjectKey = objectKey.substring(prefix.length);
|
|
125
|
+
return { objectKey, localObjectKey };
|
|
126
|
+
}
|
|
97
127
|
}
|
|
98
128
|
class S3ServiceFactory {
|
|
99
129
|
create(config, providers, authorizator) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"S3Service.cjs","sources":["../../../../packages/engine-s3-plugin/src/S3Service.ts"],"sourcesContent":["import { extension as resolveExtension } from 'mime-types'\nimport { resolveS3PublicBaseUrl, S3Config } from './Config.js'\nimport { ForbiddenError, UserInputError } from '@contember/graphql-utils'\nimport { Providers } from '@contember/engine-plugins'\nimport { S3Signer } from './S3Signer.js'\nimport { S3GenerateSignedUploadInput } from './S3SchemaTypes.js'\nimport { S3ObjectAuthorizator } from './S3ObjectAuthorizator.js'\n\ntype SignedReadUrl = {\n\turl: string\n\tbucket: string\n\tobjectKey: string\n\theaders: { key: string; value: string }[]\n\tmethod: string\n}\n\ntype SignedUploadUrl = {\n\tobjectKey: string\n\turl: string\n\tbucket: string\n\tpublicUrl: string\n\theaders: { key: string; value: string }[]\n\tmethod: string\n}\n\nexport class S3Service {\n\tprivate readonly publicBaseUrl: string\n\n\tprivate readonly signer: S3Signer\n\n\tconstructor(\n\t\tpublic readonly config: S3Config,\n\t\tprivate readonly providers: Pick<Providers, 'uuid' | 'now'>,\n\t\tprivate readonly authorizator: S3ObjectAuthorizator,\n\t) {\n\t\tthis.publicBaseUrl = resolveS3PublicBaseUrl(config)\n\t\tthis.signer = new S3Signer(config, providers)\n\t}\n\n\tpublic getSignedUploadUrl(\n\t\t{ acl, contentDisposition, contentType, expiration, prefix, suffix, fileName, extension, size }: S3GenerateSignedUploadInput,\n\t): SignedUploadUrl {\n\t\tconst ext = extension ?? ((contentType ? resolveExtension(contentType) : null) || 'bin')\n\t\tconst id = this.providers.uuid()\n\t\tconst localObjectKey = (prefix ? prefix + '/' : '') + `${id}${suffix ?? ''}.${ext}`\n\t\tthis.authorizator.verifyUploadAccess({ key: localObjectKey, size })\n\n\t\tconst objectKey = (this.config.prefix ? this.config.prefix + '/' : '') + localObjectKey\n\n\t\tconst bucket = this.config.bucket\n\t\tif (acl && this.config.noAcl) {\n\t\t\tthrow new UserInputError('ACL is not supported')\n\t\t}\n\n\t\tconst headers: Record<string, string> = {\n\t\t\t'Cache-Control': 'immutable',\n\t\t}\n\t\tif (contentType) {\n\t\t\theaders['Content-Type'] = contentType\n\t\t}\n\n\t\tif (!this.config.noAcl && acl !== 'NONE') {\n\t\t\tconst mapping = { PUBLIC_READ: 'public-read', PRIVATE: 'private' }\n\t\t\theaders['x-amz-acl'] = mapping[acl ?? 'PUBLIC_READ']\n\t\t}\n\t\tif (fileName || contentDisposition) {\n\t\t\tlet contentDispositionHeader = contentDisposition?.toLowerCase() ?? 'inline'\n\t\t\tif (fileName) {\n\t\t\t\tcontentDispositionHeader += `; filename*=UTF-8''${encodeURIComponent(fileName)}`\n\t\t\t}\n\t\t\theaders['Content-Disposition'] = contentDispositionHeader\n\t\t}\n\t\tconst headersToSend = Object.entries(headers).map(([key, value]) => ({ key, value }))\n\n\t\t// intentionally not sending following headers\n\t\tif (size) {\n\t\t\theaders['Content-Length'] = String(size)\n\t\t}\n\n\t\tconst url = this.signer.sign({\n\t\t\taction: 'upload',\n\t\t\texpiration: expiration ?? 3600,\n\t\t\tkey: objectKey,\n\t\t\theaders: { ...headers },\n\t\t})\n\n\t\tconst publicUrl = this.formatPublicUrl(objectKey)\n\t\treturn {\n\t\t\tbucket,\n\t\t\tobjectKey,\n\t\t\turl,\n\t\t\tpublicUrl,\n\t\t\theaders: headersToSend,\n\t\t\tmethod: 'PUT',\n\t\t}\n\t}\n\n\tpublic getSignedReadUrl({ objectKey, expiration }: { objectKey: string; expiration: number | null }): SignedReadUrl {\n\t\tconst bucket = this.config.bucket\n\
|
|
1
|
+
{"version":3,"file":"S3Service.cjs","sources":["../../../../packages/engine-s3-plugin/src/S3Service.ts"],"sourcesContent":["import { extension as resolveExtension } from 'mime-types'\nimport { resolveS3PublicBaseUrl, S3Config } from './Config.js'\nimport { ForbiddenError, UserInputError } from '@contember/graphql-utils'\nimport { Providers } from '@contember/engine-plugins'\nimport { S3Signer } from './S3Signer.js'\nimport { S3GenerateSignedUploadInput } from './S3SchemaTypes.js'\nimport { S3ObjectAuthorizator } from './S3ObjectAuthorizator.js'\n\ntype SignedReadUrl = {\n\turl: string\n\tbucket: string\n\tobjectKey: string\n\theaders: { key: string; value: string }[]\n\tmethod: string\n}\n\ntype SignedUploadUrl = {\n\tobjectKey: string\n\turl: string\n\tbucket: string\n\tpublicUrl: string\n\theaders: { key: string; value: string }[]\n\tmethod: string\n}\n\ntype DeletedObject = {\n\tbucket: string\n\tobjectKey: string\n}\n\nexport type S3FetchResponse = {\n\treadonly ok: boolean\n\treadonly status: number\n\ttext(): Promise<string>\n}\n\nexport type S3Fetch = (url: string, init: { method: string; signal: AbortSignal }) => Promise<S3FetchResponse>\n\nconst deleteUrlExpiration = 60\nconst deleteTimeoutMs = 10_000\n\nexport class S3Service {\n\tprivate readonly publicBaseUrl: string\n\n\tprivate readonly signer: S3Signer\n\n\tconstructor(\n\t\tpublic readonly config: S3Config,\n\t\tprivate readonly providers: Pick<Providers, 'uuid' | 'now'>,\n\t\tprivate readonly authorizator: S3ObjectAuthorizator,\n\t\tprivate readonly fetch: S3Fetch = (url, init) => globalThis.fetch(url, init),\n\t) {\n\t\tthis.publicBaseUrl = resolveS3PublicBaseUrl(config)\n\t\tthis.signer = new S3Signer(config, providers)\n\t}\n\n\tpublic getSignedUploadUrl(\n\t\t{ acl, contentDisposition, contentType, expiration, prefix, suffix, fileName, extension, size }: S3GenerateSignedUploadInput,\n\t): SignedUploadUrl {\n\t\tconst ext = extension ?? ((contentType ? resolveExtension(contentType) : null) || 'bin')\n\t\tconst id = this.providers.uuid()\n\t\tconst localObjectKey = (prefix ? prefix + '/' : '') + `${id}${suffix ?? ''}.${ext}`\n\t\tthis.authorizator.verifyUploadAccess({ key: localObjectKey, size })\n\n\t\tconst objectKey = (this.config.prefix ? this.config.prefix + '/' : '') + localObjectKey\n\n\t\tconst bucket = this.config.bucket\n\t\tif (acl && this.config.noAcl) {\n\t\t\tthrow new UserInputError('ACL is not supported')\n\t\t}\n\n\t\tconst headers: Record<string, string> = {\n\t\t\t'Cache-Control': 'immutable',\n\t\t}\n\t\tif (contentType) {\n\t\t\theaders['Content-Type'] = contentType\n\t\t}\n\n\t\tif (!this.config.noAcl && acl !== 'NONE') {\n\t\t\tconst mapping = { PUBLIC_READ: 'public-read', PRIVATE: 'private' }\n\t\t\theaders['x-amz-acl'] = mapping[acl ?? 'PUBLIC_READ']\n\t\t}\n\t\tif (fileName || contentDisposition) {\n\t\t\tlet contentDispositionHeader = contentDisposition?.toLowerCase() ?? 'inline'\n\t\t\tif (fileName) {\n\t\t\t\tcontentDispositionHeader += `; filename*=UTF-8''${encodeURIComponent(fileName)}`\n\t\t\t}\n\t\t\theaders['Content-Disposition'] = contentDispositionHeader\n\t\t}\n\t\tconst headersToSend = Object.entries(headers).map(([key, value]) => ({ key, value }))\n\n\t\t// intentionally not sending following headers\n\t\tif (size) {\n\t\t\theaders['Content-Length'] = String(size)\n\t\t}\n\n\t\tconst url = this.signer.sign({\n\t\t\taction: 'upload',\n\t\t\texpiration: expiration ?? 3600,\n\t\t\tkey: objectKey,\n\t\t\theaders: { ...headers },\n\t\t})\n\n\t\tconst publicUrl = this.formatPublicUrl(objectKey)\n\t\treturn {\n\t\t\tbucket,\n\t\t\tobjectKey,\n\t\t\turl,\n\t\t\tpublicUrl,\n\t\t\theaders: headersToSend,\n\t\t\tmethod: 'PUT',\n\t\t}\n\t}\n\n\tpublic getSignedReadUrl({ objectKey, expiration }: { objectKey: string; expiration: number | null }): SignedReadUrl {\n\t\tconst bucket = this.config.bucket\n\t\tconst resolved = this.resolveObjectKey(objectKey)\n\t\tthis.authorizator.verifyReadAccess({ key: resolved.localObjectKey })\n\n\t\tconst url = this.signer.sign({\n\t\t\taction: 'read',\n\t\t\texpiration: expiration ?? 3600,\n\t\t\tkey: resolved.objectKey,\n\t\t\theaders: {},\n\t\t})\n\n\t\treturn {\n\t\t\tbucket,\n\t\t\tobjectKey: resolved.objectKey,\n\t\t\turl,\n\t\t\theaders: [],\n\t\t\tmethod: 'GET',\n\t\t}\n\t}\n\n\t/**\n\t * Unlike an upload or a read, a delete carries no payload, so the signed URL never leaves the server.\n\t */\n\tpublic async deleteObject({ objectKey }: { objectKey: string }): Promise<DeletedObject> {\n\t\tconst bucket = this.config.bucket\n\t\tconst resolved = this.resolveObjectKey(objectKey)\n\t\tthis.authorizator.verifyDeleteAccess({ key: resolved.localObjectKey })\n\n\t\tconst url = this.signer.sign({\n\t\t\taction: 'delete',\n\t\t\texpiration: deleteUrlExpiration,\n\t\t\tkey: resolved.objectKey,\n\t\t\theaders: {},\n\t\t})\n\n\t\tconst response = await this.fetch(url, { method: 'DELETE', signal: AbortSignal.timeout(deleteTimeoutMs) })\n\t\tif (!response.ok) {\n\t\t\tthrow new Error(`Failed to delete an object \"${resolved.objectKey}\": S3 responded with ${response.status}: ${await response.text()}`)\n\t\t}\n\n\t\treturn {\n\t\t\tbucket,\n\t\t\tobjectKey: resolved.objectKey,\n\t\t}\n\t}\n\n\tpublic formatPublicUrl(key: string): string {\n\t\treturn `${this.publicBaseUrl}/${key}`\n\t}\n\n\tprivate resolveObjectKey(objectKey: string): { objectKey: string; localObjectKey: string } {\n\t\tconst publicPrefix = this.formatPublicUrl('')\n\t\tif (objectKey.startsWith(publicPrefix)) {\n\t\t\tobjectKey = objectKey.substring(publicPrefix.length)\n\t\t}\n\t\t// the separator is a part of the prefix: without it, a project prefixed \"blog\" reaches into \"blog-staging\" in a shared bucket\n\t\tconst prefix = this.config.prefix ? this.config.prefix + '/' : ''\n\t\tif (prefix && !objectKey.startsWith(prefix)) {\n\t\t\tthrow new ForbiddenError(\n\t\t\t\t`Given object key \"${objectKey}\" does not start with a project prefix \"${this.config.prefix}\"`,\n\t\t\t)\n\t\t}\n\t\tconst localObjectKey = objectKey.substring(prefix.length)\n\n\t\treturn { objectKey, localObjectKey }\n\t}\n}\n\nexport class S3ServiceFactory {\n\tpublic create(config: S3Config, providers: Providers, authorizator: S3ObjectAuthorizator) {\n\t\treturn new S3Service(config, providers, authorizator)\n\t}\n}\n"],"names":["resolveS3PublicBaseUrl","S3Signer","resolveExtension","UserInputError","ForbiddenError"],"mappings":";;;;;;;;;AAsCA,MAAM,sBAAsB;AAC5B,MAAM,kBAAkB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