@contember/engine-s3-plugin 2.1.0-alpha.3 → 2.1.0-alpha.35
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +19 -14
- package/src/Config.ts +0 -1
- package/src/S3ConfigProcessor.ts +0 -1
- package/src/S3ObjectAuthorizator.ts +0 -1
- package/src/S3SchemaContributor.ts +2 -7
- package/src/S3SchemaTypes.ts +3 -10
- package/src/S3Service.ts +1 -2
- package/src/S3Signer.ts +1 -1
- package/tests/cases/authorizator.test.ts +1 -2
- package/tests/cases/signRequest.test.ts +54 -26
- package/types/picomatch/index.d.ts +1 -1
- package/dist/development/index.cjs +0 -27
- package/dist/development/index.cjs.map +0 -1
- package/dist/development/index.js +0 -28
- package/dist/development/index.js.map +0 -1
- package/dist/development/src/Config.cjs +0 -73
- package/dist/development/src/Config.cjs.map +0 -1
- package/dist/development/src/Config.js +0 -56
- package/dist/development/src/Config.js.map +0 -1
- package/dist/development/src/S3ConfigProcessor.cjs +0 -60
- package/dist/development/src/S3ConfigProcessor.cjs.map +0 -1
- package/dist/development/src/S3ConfigProcessor.js +0 -43
- package/dist/development/src/S3ConfigProcessor.js.map +0 -1
- package/dist/development/src/S3ObjectAuthorizator.cjs +0 -46
- package/dist/development/src/S3ObjectAuthorizator.cjs.map +0 -1
- package/dist/development/src/S3ObjectAuthorizator.js +0 -46
- package/dist/development/src/S3ObjectAuthorizator.js.map +0 -1
- package/dist/development/src/S3SchemaContributor.cjs +0 -107
- package/dist/development/src/S3SchemaContributor.cjs.map +0 -1
- package/dist/development/src/S3SchemaContributor.js +0 -107
- package/dist/development/src/S3SchemaContributor.js.map +0 -1
- package/dist/development/src/S3SchemaTypes.cjs +0 -71
- package/dist/development/src/S3SchemaTypes.cjs.map +0 -1
- package/dist/development/src/S3SchemaTypes.js +0 -71
- package/dist/development/src/S3SchemaTypes.js.map +0 -1
- package/dist/development/src/S3Service.cjs +0 -105
- package/dist/development/src/S3Service.cjs.map +0 -1
- package/dist/development/src/S3Service.js +0 -105
- package/dist/development/src/S3Service.js.map +0 -1
- package/dist/development/src/S3Signer.cjs +0 -84
- package/dist/development/src/S3Signer.cjs.map +0 -1
- package/dist/development/src/S3Signer.js +0 -84
- package/dist/development/src/S3Signer.js.map +0 -1
- package/dist/production/index.cjs +0 -27
- package/dist/production/index.cjs.map +0 -1
- package/dist/production/index.js +0 -28
- package/dist/production/index.js.map +0 -1
- package/dist/production/src/Config.cjs +0 -73
- package/dist/production/src/Config.cjs.map +0 -1
- package/dist/production/src/Config.js +0 -56
- package/dist/production/src/Config.js.map +0 -1
- package/dist/production/src/S3ConfigProcessor.cjs +0 -60
- package/dist/production/src/S3ConfigProcessor.cjs.map +0 -1
- package/dist/production/src/S3ConfigProcessor.js +0 -43
- package/dist/production/src/S3ConfigProcessor.js.map +0 -1
- package/dist/production/src/S3ObjectAuthorizator.cjs +0 -46
- package/dist/production/src/S3ObjectAuthorizator.cjs.map +0 -1
- package/dist/production/src/S3ObjectAuthorizator.js +0 -46
- package/dist/production/src/S3ObjectAuthorizator.js.map +0 -1
- package/dist/production/src/S3SchemaContributor.cjs +0 -107
- package/dist/production/src/S3SchemaContributor.cjs.map +0 -1
- package/dist/production/src/S3SchemaContributor.js +0 -107
- package/dist/production/src/S3SchemaContributor.js.map +0 -1
- package/dist/production/src/S3SchemaTypes.cjs +0 -71
- package/dist/production/src/S3SchemaTypes.cjs.map +0 -1
- package/dist/production/src/S3SchemaTypes.js +0 -71
- package/dist/production/src/S3SchemaTypes.js.map +0 -1
- package/dist/production/src/S3Service.cjs +0 -105
- package/dist/production/src/S3Service.cjs.map +0 -1
- package/dist/production/src/S3Service.js +0 -105
- package/dist/production/src/S3Service.js.map +0 -1
- package/dist/production/src/S3Signer.cjs +0 -84
- package/dist/production/src/S3Signer.cjs.map +0 -1
- package/dist/production/src/S3Signer.js +0 -84
- package/dist/production/src/S3Signer.js.map +0 -1
- package/dist/tests/cases/authorizator.test.d.ts +0 -2
- package/dist/tests/cases/authorizator.test.d.ts.map +0 -1
- package/dist/tests/cases/signRequest.test.d.ts +0 -2
- package/dist/tests/cases/signRequest.test.d.ts.map +0 -1
- package/dist/tests/tsconfig.tsbuildinfo +0 -1
- package/dist/types/Config.d.ts +0 -33
- package/dist/types/Config.d.ts.map +0 -1
- package/dist/types/S3ConfigProcessor.d.ts +0 -9
- package/dist/types/S3ConfigProcessor.d.ts.map +0 -1
- package/dist/types/S3ObjectAuthorizator.d.ts +0 -22
- package/dist/types/S3ObjectAuthorizator.d.ts.map +0 -1
- package/dist/types/S3SchemaContributor.d.ts +0 -21
- package/dist/types/S3SchemaContributor.d.ts.map +0 -1
- package/dist/types/S3SchemaTypes.d.ts +0 -21
- package/dist/types/S3SchemaTypes.d.ts.map +0 -1
- package/dist/types/S3Service.d.ts +0 -44
- package/dist/types/S3Service.d.ts.map +0 -1
- package/dist/types/S3Signer.d.ts +0 -22
- package/dist/types/S3Signer.d.ts.map +0 -1
- package/dist/types/index.d.ts +0 -13
- package/dist/types/index.d.ts.map +0 -1
- package/dist/types/tsconfig.tsbuildinfo +0 -1
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const pm = require("picomatch");
|
|
4
|
-
const graphqlUtils = require("@contember/graphql-utils");
|
|
5
|
-
var __defProp = Object.defineProperty;
|
|
6
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
7
|
-
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
8
|
-
class S3ObjectAuthorizator {
|
|
9
|
-
constructor(uploadRules, readRules) {
|
|
10
|
-
__publicField(this, "uploadRules");
|
|
11
|
-
__publicField(this, "readRules");
|
|
12
|
-
this.uploadRules = uploadRules;
|
|
13
|
-
this.readRules = readRules;
|
|
14
|
-
}
|
|
15
|
-
verifyReadAccess({ key }) {
|
|
16
|
-
for (const rule of this.readRules) {
|
|
17
|
-
rule.matcher ?? (rule.matcher = pm(rule.pattern));
|
|
18
|
-
if (rule.matcher(key)) {
|
|
19
|
-
return;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
throw new graphqlUtils.ForbiddenError(`Read access forbidden for object key ${key}`);
|
|
23
|
-
}
|
|
24
|
-
verifyUploadAccess({ key, size }) {
|
|
25
|
-
const matchedPatterns = [];
|
|
26
|
-
for (const rule of this.uploadRules) {
|
|
27
|
-
rule.matcher ?? (rule.matcher = pm(rule.pattern));
|
|
28
|
-
if (rule.matcher(key)) {
|
|
29
|
-
if (!rule.maxSize || size !== null && size <= rule.maxSize) {
|
|
30
|
-
return;
|
|
31
|
-
}
|
|
32
|
-
matchedPatterns.push(rule);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
if (matchedPatterns.length > 0) {
|
|
36
|
-
if (size === null) {
|
|
37
|
-
throw new graphqlUtils.ForbiddenError("File size must be provided");
|
|
38
|
-
} else {
|
|
39
|
-
throw new graphqlUtils.ForbiddenError("Uploaded file is too large");
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
throw new graphqlUtils.ForbiddenError(`Upload access forbidden for object key ${key}`);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
exports.S3ObjectAuthorizator = S3ObjectAuthorizator;
|
|
46
|
-
//# sourceMappingURL=S3ObjectAuthorizator.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"S3ObjectAuthorizator.cjs","sources":["../../../../packages/engine-s3-plugin/src/S3ObjectAuthorizator.ts"],"sourcesContent":["// eslint-disable-next-line @typescript-eslint/triple-slash-reference\n/// <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":";;;;;;;AAgBO,MAAM,qBAAqB;AAAA,EAIjC,YACC,aACA,WACC;AANe,kBAAA,MAAA,aAAA;AACA,kBAAA,MAAA,WAAA;AAMhB,SAAK,cAAc;AACnB,SAAK,YAAY;AAAA,EAAA;AAAA,EAGX,iBAAiB,EAAE,OAA8B;AAC5C,eAAA,QAAQ,KAAK,WAAW;AAClC,WAAK,YAAL,KAAK,UAAY,GAAG,KAAK,OAAO;AAE5B,UAAA,KAAK,QAAQ,GAAG,GAAG;AACtB;AAAA,MAAA;AAAA,IACD;AAGD,UAAM,IAAIA,aAAAA,eAAe,wCAAwC,GAAG,EAAE;AAAA,EAAA;AAAA,EAGhE,mBAAmB,EAAE,KAAK,QAAoD;AACpF,UAAM,kBAAwC,CAAC;AAEpC,eAAA,QAAQ,KAAK,aAAa;AACpC,WAAK,YAAL,KAAK,UAAY,GAAG,KAAK,OAAO;AAE5B,UAAA,KAAK,QAAQ,GAAG,GAAG;AACtB,YAAI,CAAC,KAAK,WAAY,SAAS,QAAQ,QAAQ,KAAK,SAAU;AAC7D;AAAA,QAAA;AAED,wBAAgB,KAAK,IAAI;AAAA,MAAA;AAAA,IAC1B;AAGG,QAAA,gBAAgB,SAAS,GAAG;AAC/B,UAAI,SAAS,MAAM;AACZ,cAAA,IAAIA,4BAAe,4BAA4B;AAAA,MAAA,OAC/C;AACA,cAAA,IAAIA,4BAAe,4BAA4B;AAAA,MAAA;AAAA,IACtD;AAGD,UAAM,IAAIA,aAAAA,eAAe,0CAA0C,GAAG,EAAE;AAAA,EAAA;AAE1E;;"}
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import pm from "picomatch";
|
|
2
|
-
import { ForbiddenError } from "@contember/graphql-utils";
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
5
|
-
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
6
|
-
class S3ObjectAuthorizator {
|
|
7
|
-
constructor(uploadRules, readRules) {
|
|
8
|
-
__publicField(this, "uploadRules");
|
|
9
|
-
__publicField(this, "readRules");
|
|
10
|
-
this.uploadRules = uploadRules;
|
|
11
|
-
this.readRules = readRules;
|
|
12
|
-
}
|
|
13
|
-
verifyReadAccess({ key }) {
|
|
14
|
-
for (const rule of this.readRules) {
|
|
15
|
-
rule.matcher ?? (rule.matcher = pm(rule.pattern));
|
|
16
|
-
if (rule.matcher(key)) {
|
|
17
|
-
return;
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
throw new ForbiddenError(`Read access forbidden for object key ${key}`);
|
|
21
|
-
}
|
|
22
|
-
verifyUploadAccess({ key, size }) {
|
|
23
|
-
const matchedPatterns = [];
|
|
24
|
-
for (const rule of this.uploadRules) {
|
|
25
|
-
rule.matcher ?? (rule.matcher = pm(rule.pattern));
|
|
26
|
-
if (rule.matcher(key)) {
|
|
27
|
-
if (!rule.maxSize || size !== null && size <= rule.maxSize) {
|
|
28
|
-
return;
|
|
29
|
-
}
|
|
30
|
-
matchedPatterns.push(rule);
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
if (matchedPatterns.length > 0) {
|
|
34
|
-
if (size === null) {
|
|
35
|
-
throw new ForbiddenError("File size must be provided");
|
|
36
|
-
} else {
|
|
37
|
-
throw new ForbiddenError("Uploaded file is too large");
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
throw new ForbiddenError(`Upload access forbidden for object key ${key}`);
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
export {
|
|
44
|
-
S3ObjectAuthorizator
|
|
45
|
-
};
|
|
46
|
-
//# sourceMappingURL=S3ObjectAuthorizator.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"S3ObjectAuthorizator.js","sources":["../../../../packages/engine-s3-plugin/src/S3ObjectAuthorizator.ts"],"sourcesContent":["// eslint-disable-next-line @typescript-eslint/triple-slash-reference\n/// <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":";;;;;AAgBO,MAAM,qBAAqB;AAAA,EAIjC,YACC,aACA,WACC;AANe,kBAAA,MAAA,aAAA;AACA,kBAAA,MAAA,WAAA;AAMhB,SAAK,cAAc;AACnB,SAAK,YAAY;AAAA,EAAA;AAAA,EAGX,iBAAiB,EAAE,OAA8B;AAC5C,eAAA,QAAQ,KAAK,WAAW;AAClC,WAAK,YAAL,KAAK,UAAY,GAAG,KAAK,OAAO;AAE5B,UAAA,KAAK,QAAQ,GAAG,GAAG;AACtB;AAAA,MAAA;AAAA,IACD;AAGD,UAAM,IAAI,eAAe,wCAAwC,GAAG,EAAE;AAAA,EAAA;AAAA,EAGhE,mBAAmB,EAAE,KAAK,QAAoD;AACpF,UAAM,kBAAwC,CAAC;AAEpC,eAAA,QAAQ,KAAK,aAAa;AACpC,WAAK,YAAL,KAAK,UAAY,GAAG,KAAK,OAAO;AAE5B,UAAA,KAAK,QAAQ,GAAG,GAAG;AACtB,YAAI,CAAC,KAAK,WAAY,SAAS,QAAQ,QAAQ,KAAK,SAAU;AAC7D;AAAA,QAAA;AAED,wBAAgB,KAAK,IAAI;AAAA,MAAA;AAAA,IAC1B;AAGG,QAAA,gBAAgB,SAAS,GAAG;AAC/B,UAAI,SAAS,MAAM;AACZ,cAAA,IAAI,eAAe,4BAA4B;AAAA,MAAA,OAC/C;AACA,cAAA,IAAI,eAAe,4BAA4B;AAAA,MAAA;AAAA,IACtD;AAGD,UAAM,IAAI,eAAe,0CAA0C,GAAG,EAAE;AAAA,EAAA;AAE1E;"}
|
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const graphql = require("graphql");
|
|
4
|
-
const Config = require("./Config.cjs");
|
|
5
|
-
const S3SchemaTypes = require("./S3SchemaTypes.cjs");
|
|
6
|
-
const S3ObjectAuthorizator = require("./S3ObjectAuthorizator.cjs");
|
|
7
|
-
class S3SchemaContributor {
|
|
8
|
-
constructor(s3Factory, providers) {
|
|
9
|
-
this.s3Factory = s3Factory;
|
|
10
|
-
this.providers = providers;
|
|
11
|
-
}
|
|
12
|
-
getCacheKey({ project }) {
|
|
13
|
-
return project.s3 ? "yes" : "no";
|
|
14
|
-
}
|
|
15
|
-
createSchema(context) {
|
|
16
|
-
if (!context.project.s3) {
|
|
17
|
-
return void 0;
|
|
18
|
-
}
|
|
19
|
-
const rules = context.identity.projectRoles.flatMap(
|
|
20
|
-
(it) => Object.entries(context.schema.acl.roles[it]?.s3 || {})
|
|
21
|
-
);
|
|
22
|
-
const uploadRules = rules.filter(([, it]) => it.upload).map(([it, val]) => ({
|
|
23
|
-
pattern: it,
|
|
24
|
-
...typeof val.upload !== "boolean" ? val.upload : {}
|
|
25
|
-
}));
|
|
26
|
-
const readRules = rules.filter(([, it]) => it.read).map(([it]) => ({
|
|
27
|
-
pattern: it
|
|
28
|
-
}));
|
|
29
|
-
if (uploadRules.length === 0 && readRules.length == 0) {
|
|
30
|
-
return void 0;
|
|
31
|
-
}
|
|
32
|
-
const authorizator = new S3ObjectAuthorizator.S3ObjectAuthorizator(uploadRules, readRules);
|
|
33
|
-
const uploadMutation = this.createUploadMutation(authorizator);
|
|
34
|
-
const readMutation = this.createReadMutation(authorizator);
|
|
35
|
-
const mutation = {
|
|
36
|
-
generateUploadUrl: uploadMutation,
|
|
37
|
-
generateReadUrl: readMutation
|
|
38
|
-
};
|
|
39
|
-
return {
|
|
40
|
-
mutation: new graphql.GraphQLObjectType({
|
|
41
|
-
name: "Mutation",
|
|
42
|
-
fields: () => mutation
|
|
43
|
-
}),
|
|
44
|
-
query: new graphql.GraphQLObjectType({
|
|
45
|
-
name: "Query",
|
|
46
|
-
fields: () => ({
|
|
47
|
-
s3DummyQuery: {
|
|
48
|
-
type: graphql.GraphQLString
|
|
49
|
-
}
|
|
50
|
-
})
|
|
51
|
-
})
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
createReadMutation(authorizator) {
|
|
55
|
-
return {
|
|
56
|
-
type: new graphql.GraphQLNonNull(S3SchemaTypes.S3SignedRead),
|
|
57
|
-
args: {
|
|
58
|
-
objectKey: {
|
|
59
|
-
type: new graphql.GraphQLNonNull(graphql.GraphQLString)
|
|
60
|
-
},
|
|
61
|
-
expiration: {
|
|
62
|
-
type: graphql.GraphQLInt
|
|
63
|
-
}
|
|
64
|
-
},
|
|
65
|
-
resolve: async (parent, args, ctx) => {
|
|
66
|
-
if (!ctx.project.s3) {
|
|
67
|
-
throw new graphql.GraphQLError("S3 is not configured for this project");
|
|
68
|
-
}
|
|
69
|
-
const s3Config = Config.resolveS3Config(ctx.project.s3);
|
|
70
|
-
const s3 = this.s3Factory.create(s3Config, this.providers, authorizator);
|
|
71
|
-
return s3.getSignedReadUrl({ objectKey: args.objectKey, expiration: args.expiration ?? null });
|
|
72
|
-
}
|
|
73
|
-
};
|
|
74
|
-
}
|
|
75
|
-
createUploadMutation(authorizator) {
|
|
76
|
-
return {
|
|
77
|
-
type: new graphql.GraphQLNonNull(S3SchemaTypes.S3SignedUpload),
|
|
78
|
-
args: {
|
|
79
|
-
input: { type: S3SchemaTypes.S3GenerateSignedUploadInput },
|
|
80
|
-
contentType: { type: graphql.GraphQLString, deprecationReason: "Use input.contentType" },
|
|
81
|
-
expiration: { type: graphql.GraphQLInt, deprecationReason: "Use input.expiration" },
|
|
82
|
-
prefix: { type: graphql.GraphQLString, deprecationReason: "Use input.prefix" },
|
|
83
|
-
acl: { type: S3SchemaTypes.S3Acl, deprecationReason: "Use input.acl" }
|
|
84
|
-
},
|
|
85
|
-
resolve: async (parent, args, ctx) => {
|
|
86
|
-
if (!ctx.project.s3) {
|
|
87
|
-
throw new graphql.GraphQLError("S3 is not configured for this project");
|
|
88
|
-
}
|
|
89
|
-
const s3Config = Config.resolveS3Config(ctx.project.s3);
|
|
90
|
-
const s3 = this.s3Factory.create(s3Config, this.providers, authorizator);
|
|
91
|
-
return s3.getSignedUploadUrl({
|
|
92
|
-
acl: args.input?.acl ?? args.acl ?? null,
|
|
93
|
-
contentDisposition: args.input?.contentDisposition ?? null,
|
|
94
|
-
contentType: args.input?.contentType ?? args.contentType ?? null,
|
|
95
|
-
expiration: args.input?.expiration ?? args.expiration ?? null,
|
|
96
|
-
extension: args.input?.extension ?? null,
|
|
97
|
-
fileName: args.input?.fileName ?? null,
|
|
98
|
-
prefix: args.input?.prefix ?? args.prefix ?? null,
|
|
99
|
-
suffix: args.input?.suffix ?? null,
|
|
100
|
-
size: args.input?.size ?? null
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
|
-
};
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
exports.S3SchemaContributor = S3SchemaContributor;
|
|
107
|
-
//# sourceMappingURL=S3SchemaContributor.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
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'\nimport { Project3Config, resolveS3Config, S3Config } from './Config'\nimport { GraphQLSchemaContributor, GraphQLSchemaContributorContext, Providers } from '@contember/engine-plugins'\nimport * as types from './S3SchemaTypes'\nimport { S3Acl, S3GenerateSignedUploadInput, S3SignedRead, S3SignedUpload } from './S3SchemaTypes'\nimport { S3ObjectAuthorizator } from './S3ObjectAuthorizator'\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\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 =>\n\t\t\tObject.entries((context.schema.acl.roles[it]?.s3 as S3SchemaAcl) || {}),\n\t\t)\n\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\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":";;;;;;AAoCO,MAAM,oBAAwD;AAAA,EACpE,YACkB,WACA,WAChB;AAFgB,SAAA,YAAA;AACA,SAAA,YAAA;AAAA,EAAA;AAAA,EAGlB,YAAa,EAAE,WAAoD;AAC3D,WAAA,QAAQ,KAAK,QAAQ;AAAA,EAAA;AAAA,EAG7B,aAAa,SAA2E;AACnF,QAAA,CAAC,QAAQ,QAAQ,IAAI;AACjB,aAAA;AAAA,IAAA;AAEF,UAAA,QAAQ,QAAQ,SAAS,aAAa;AAAA,MAAQ,CAAA,OACnD,OAAO,QAAS,QAAQ,OAAO,IAAI,MAAM,EAAE,GAAG,MAAsB,CAAE,CAAA;AAAA,IACvE;AAGA,UAAM,cAAc,MAAM,OAAO,CAAC,CAAG,EAAA,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,UAAM,YAAY,MAAM,OAAO,CAAC,CAAA,EAAG,EAAE,MAAM,GAAG,IAAI,EAAE,IAAI,CAAC,CAAC,EAAE,OAAO;AAAA,MAClE,SAAS;AAAA,IAAA,EACR;AAEF,QAAI,YAAY,WAAW,KAAK,UAAU,UAAU,GAAG;AAC/C,aAAA;AAAA,IAAA;AAGR,UAAM,eAAe,IAAIA,0CA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EAAE,MAAMP,uBAAe,mBAAmB,wBAAwB;AAAA,QAC/E,YAAY,EAAE,MAAMG,oBAAY,mBAAmB,uBAAuB;AAAA,QAC1E,QAAQ,EAAE,MAAMH,uBAAe,mBAAmB,mBAAmB;AAAA,QACrE,KAAK,EAAE,MAAMQ,cAAM,OAAO,mBAAmB,gBAAgB;AAAA,MAC9D;AAAA,MACA,SAAS,OACR,QACA,MACA,QACI;AACA,YAAA,CAAC,IAAI,QAAQ,IAAI;AACd,gBAAA,IAAIJ,qBAAa,uCAAuC;AAAA,QAAA;AAE/D,cAAM,WAAWC,OAAA,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,MAAA;AAAA,IAEH;AAAA,EAAA;AAEF;;"}
|
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
import { GraphQLObjectType, GraphQLString, GraphQLNonNull, GraphQLInt, GraphQLError } from "graphql";
|
|
2
|
-
import { resolveS3Config } from "./Config.js";
|
|
3
|
-
import { S3SignedRead, S3SignedUpload, S3GenerateSignedUploadInput, S3Acl } from "./S3SchemaTypes.js";
|
|
4
|
-
import { S3ObjectAuthorizator } from "./S3ObjectAuthorizator.js";
|
|
5
|
-
class S3SchemaContributor {
|
|
6
|
-
constructor(s3Factory, providers) {
|
|
7
|
-
this.s3Factory = s3Factory;
|
|
8
|
-
this.providers = providers;
|
|
9
|
-
}
|
|
10
|
-
getCacheKey({ project }) {
|
|
11
|
-
return project.s3 ? "yes" : "no";
|
|
12
|
-
}
|
|
13
|
-
createSchema(context) {
|
|
14
|
-
if (!context.project.s3) {
|
|
15
|
-
return void 0;
|
|
16
|
-
}
|
|
17
|
-
const rules = context.identity.projectRoles.flatMap(
|
|
18
|
-
(it) => Object.entries(context.schema.acl.roles[it]?.s3 || {})
|
|
19
|
-
);
|
|
20
|
-
const uploadRules = rules.filter(([, it]) => it.upload).map(([it, val]) => ({
|
|
21
|
-
pattern: it,
|
|
22
|
-
...typeof val.upload !== "boolean" ? val.upload : {}
|
|
23
|
-
}));
|
|
24
|
-
const readRules = rules.filter(([, it]) => it.read).map(([it]) => ({
|
|
25
|
-
pattern: it
|
|
26
|
-
}));
|
|
27
|
-
if (uploadRules.length === 0 && readRules.length == 0) {
|
|
28
|
-
return void 0;
|
|
29
|
-
}
|
|
30
|
-
const authorizator = new S3ObjectAuthorizator(uploadRules, readRules);
|
|
31
|
-
const uploadMutation = this.createUploadMutation(authorizator);
|
|
32
|
-
const readMutation = this.createReadMutation(authorizator);
|
|
33
|
-
const mutation = {
|
|
34
|
-
generateUploadUrl: uploadMutation,
|
|
35
|
-
generateReadUrl: readMutation
|
|
36
|
-
};
|
|
37
|
-
return {
|
|
38
|
-
mutation: new GraphQLObjectType({
|
|
39
|
-
name: "Mutation",
|
|
40
|
-
fields: () => mutation
|
|
41
|
-
}),
|
|
42
|
-
query: new GraphQLObjectType({
|
|
43
|
-
name: "Query",
|
|
44
|
-
fields: () => ({
|
|
45
|
-
s3DummyQuery: {
|
|
46
|
-
type: GraphQLString
|
|
47
|
-
}
|
|
48
|
-
})
|
|
49
|
-
})
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
createReadMutation(authorizator) {
|
|
53
|
-
return {
|
|
54
|
-
type: new GraphQLNonNull(S3SignedRead),
|
|
55
|
-
args: {
|
|
56
|
-
objectKey: {
|
|
57
|
-
type: new GraphQLNonNull(GraphQLString)
|
|
58
|
-
},
|
|
59
|
-
expiration: {
|
|
60
|
-
type: GraphQLInt
|
|
61
|
-
}
|
|
62
|
-
},
|
|
63
|
-
resolve: async (parent, args, ctx) => {
|
|
64
|
-
if (!ctx.project.s3) {
|
|
65
|
-
throw new GraphQLError("S3 is not configured for this project");
|
|
66
|
-
}
|
|
67
|
-
const s3Config = resolveS3Config(ctx.project.s3);
|
|
68
|
-
const s3 = this.s3Factory.create(s3Config, this.providers, authorizator);
|
|
69
|
-
return s3.getSignedReadUrl({ objectKey: args.objectKey, expiration: args.expiration ?? null });
|
|
70
|
-
}
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
|
-
createUploadMutation(authorizator) {
|
|
74
|
-
return {
|
|
75
|
-
type: new GraphQLNonNull(S3SignedUpload),
|
|
76
|
-
args: {
|
|
77
|
-
input: { type: S3GenerateSignedUploadInput },
|
|
78
|
-
contentType: { type: GraphQLString, deprecationReason: "Use input.contentType" },
|
|
79
|
-
expiration: { type: GraphQLInt, deprecationReason: "Use input.expiration" },
|
|
80
|
-
prefix: { type: GraphQLString, deprecationReason: "Use input.prefix" },
|
|
81
|
-
acl: { type: S3Acl, deprecationReason: "Use input.acl" }
|
|
82
|
-
},
|
|
83
|
-
resolve: async (parent, args, ctx) => {
|
|
84
|
-
if (!ctx.project.s3) {
|
|
85
|
-
throw new GraphQLError("S3 is not configured for this project");
|
|
86
|
-
}
|
|
87
|
-
const s3Config = resolveS3Config(ctx.project.s3);
|
|
88
|
-
const s3 = this.s3Factory.create(s3Config, this.providers, authorizator);
|
|
89
|
-
return s3.getSignedUploadUrl({
|
|
90
|
-
acl: args.input?.acl ?? args.acl ?? null,
|
|
91
|
-
contentDisposition: args.input?.contentDisposition ?? null,
|
|
92
|
-
contentType: args.input?.contentType ?? args.contentType ?? null,
|
|
93
|
-
expiration: args.input?.expiration ?? args.expiration ?? null,
|
|
94
|
-
extension: args.input?.extension ?? null,
|
|
95
|
-
fileName: args.input?.fileName ?? null,
|
|
96
|
-
prefix: args.input?.prefix ?? args.prefix ?? null,
|
|
97
|
-
suffix: args.input?.suffix ?? null,
|
|
98
|
-
size: args.input?.size ?? null
|
|
99
|
-
});
|
|
100
|
-
}
|
|
101
|
-
};
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
export {
|
|
105
|
-
S3SchemaContributor
|
|
106
|
-
};
|
|
107
|
-
//# sourceMappingURL=S3SchemaContributor.js.map
|
|
@@ -1 +0,0 @@
|
|
|
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'\nimport { Project3Config, resolveS3Config, S3Config } from './Config'\nimport { GraphQLSchemaContributor, GraphQLSchemaContributorContext, Providers } from '@contember/engine-plugins'\nimport * as types from './S3SchemaTypes'\nimport { S3Acl, S3GenerateSignedUploadInput, S3SignedRead, S3SignedUpload } from './S3SchemaTypes'\nimport { S3ObjectAuthorizator } from './S3ObjectAuthorizator'\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\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 =>\n\t\t\tObject.entries((context.schema.acl.roles[it]?.s3 as S3SchemaAcl) || {}),\n\t\t)\n\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\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":";;;;AAoCO,MAAM,oBAAwD;AAAA,EACpE,YACkB,WACA,WAChB;AAFgB,SAAA,YAAA;AACA,SAAA,YAAA;AAAA,EAAA;AAAA,EAGlB,YAAa,EAAE,WAAoD;AAC3D,WAAA,QAAQ,KAAK,QAAQ;AAAA,EAAA;AAAA,EAG7B,aAAa,SAA2E;AACnF,QAAA,CAAC,QAAQ,QAAQ,IAAI;AACjB,aAAA;AAAA,IAAA;AAEF,UAAA,QAAQ,QAAQ,SAAS,aAAa;AAAA,MAAQ,CAAA,OACnD,OAAO,QAAS,QAAQ,OAAO,IAAI,MAAM,EAAE,GAAG,MAAsB,CAAE,CAAA;AAAA,IACvE;AAGA,UAAM,cAAc,MAAM,OAAO,CAAC,CAAG,EAAA,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,UAAM,YAAY,MAAM,OAAO,CAAC,CAAA,EAAG,EAAE,MAAM,GAAG,IAAI,EAAE,IAAI,CAAC,CAAC,EAAE,OAAO;AAAA,MAClE,SAAS;AAAA,IAAA,EACR;AAEF,QAAI,YAAY,WAAW,KAAK,UAAU,UAAU,GAAG;AAC/C,aAAA;AAAA,IAAA;AAGR,UAAM,eAAe,IAAI,qBAAqB,aAAa,SAAS;AAC9D,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AQ,EAAE,MAAM,eAAe,mBAAmB,mBAAmB;AAAA,QACrE,KAAK,EAAE,MAAMC,OAAa,mBAAmB,gBAAgB;AAAA,MAC9D;AAAA,MACA,SAAS,OACR,QACA,MACA,QACI;AACA,YAAA,CAAC,IAAI,QAAQ,IAAI;AACd,gBAAA,IAAI,aAAa,uCAAuC;AAAA,QAAA;AAE/D,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,MAAA;AAAA,IAEH;AAAA,EAAA;AAEF;"}
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const graphql = require("graphql");
|
|
4
|
-
const S3Header = new graphql.GraphQLObjectType({
|
|
5
|
-
name: "S3Header",
|
|
6
|
-
fields: {
|
|
7
|
-
key: { type: new graphql.GraphQLNonNull(graphql.GraphQLString) },
|
|
8
|
-
value: { type: new graphql.GraphQLNonNull(graphql.GraphQLString) }
|
|
9
|
-
}
|
|
10
|
-
});
|
|
11
|
-
const S3ContentDisposition = new graphql.GraphQLEnumType({
|
|
12
|
-
name: "S33ContentDisposition",
|
|
13
|
-
values: {
|
|
14
|
-
ATTACHMENT: {},
|
|
15
|
-
INLINE: {}
|
|
16
|
-
}
|
|
17
|
-
});
|
|
18
|
-
const S3SignedRead = new graphql.GraphQLObjectType({
|
|
19
|
-
name: "S3SignedRead",
|
|
20
|
-
fields: {
|
|
21
|
-
url: { type: new graphql.GraphQLNonNull(graphql.GraphQLString) },
|
|
22
|
-
headers: {
|
|
23
|
-
type: new graphql.GraphQLNonNull(new graphql.GraphQLList(new graphql.GraphQLNonNull(S3Header)))
|
|
24
|
-
},
|
|
25
|
-
method: { type: new graphql.GraphQLNonNull(graphql.GraphQLString) },
|
|
26
|
-
objectKey: { type: new graphql.GraphQLNonNull(graphql.GraphQLString) },
|
|
27
|
-
bucket: { type: new graphql.GraphQLNonNull(graphql.GraphQLString) }
|
|
28
|
-
}
|
|
29
|
-
});
|
|
30
|
-
const S3SignedUpload = new graphql.GraphQLObjectType({
|
|
31
|
-
name: "S3SignedUpload",
|
|
32
|
-
fields: {
|
|
33
|
-
url: { type: new graphql.GraphQLNonNull(graphql.GraphQLString) },
|
|
34
|
-
headers: {
|
|
35
|
-
type: new graphql.GraphQLNonNull(new graphql.GraphQLList(new graphql.GraphQLNonNull(S3Header)))
|
|
36
|
-
},
|
|
37
|
-
method: { type: new graphql.GraphQLNonNull(graphql.GraphQLString) },
|
|
38
|
-
objectKey: { type: new graphql.GraphQLNonNull(graphql.GraphQLString) },
|
|
39
|
-
bucket: { type: new graphql.GraphQLNonNull(graphql.GraphQLString) },
|
|
40
|
-
publicUrl: { type: new graphql.GraphQLNonNull(graphql.GraphQLString) }
|
|
41
|
-
}
|
|
42
|
-
});
|
|
43
|
-
const S3Acl = new graphql.GraphQLEnumType({
|
|
44
|
-
name: "S3Acl",
|
|
45
|
-
values: {
|
|
46
|
-
PUBLIC_READ: {},
|
|
47
|
-
PRIVATE: {},
|
|
48
|
-
NONE: {}
|
|
49
|
-
}
|
|
50
|
-
});
|
|
51
|
-
const S3GenerateSignedUploadInput = new graphql.GraphQLInputObjectType({
|
|
52
|
-
name: "S3GenerateSignedUploadInput",
|
|
53
|
-
fields: {
|
|
54
|
-
contentType: { type: graphql.GraphQLString },
|
|
55
|
-
extension: { type: graphql.GraphQLString, description: "If not provided, extension is detected from a content-type." },
|
|
56
|
-
expiration: { type: graphql.GraphQLInt, description: "Signed URL expiration." },
|
|
57
|
-
size: { type: graphql.GraphQLInt, description: "Uploaded file size. Required when you enable ACL size limits." },
|
|
58
|
-
prefix: { type: graphql.GraphQLString, description: 'Can be used as a "directory".' },
|
|
59
|
-
suffix: { type: graphql.GraphQLString, description: "Suffix after generated id and before the extension." },
|
|
60
|
-
fileName: { type: graphql.GraphQLString, description: "This only affects Content-disposition header. Does not affect actual object key." },
|
|
61
|
-
contentDisposition: { type: S3ContentDisposition },
|
|
62
|
-
acl: { type: S3Acl, description: "If not supported by S3 provider, an error is thrown." }
|
|
63
|
-
}
|
|
64
|
-
});
|
|
65
|
-
exports.S3Acl = S3Acl;
|
|
66
|
-
exports.S3ContentDisposition = S3ContentDisposition;
|
|
67
|
-
exports.S3GenerateSignedUploadInput = S3GenerateSignedUploadInput;
|
|
68
|
-
exports.S3Header = S3Header;
|
|
69
|
-
exports.S3SignedRead = S3SignedRead;
|
|
70
|
-
exports.S3SignedUpload = S3SignedUpload;
|
|
71
|
-
//# sourceMappingURL=S3SchemaTypes.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"S3SchemaTypes.cjs","sources":["../../../../packages/engine-s3-plugin/src/S3SchemaTypes.ts"],"sourcesContent":["import {\n\tGraphQLEnumType,\n\tGraphQLInputObjectType,\n\tGraphQLInt,\n\tGraphQLList,\n\tGraphQLNonNull,\n\tGraphQLObjectType,\n\tGraphQLString,\n} 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', values: {\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":";;;AAUa,MAAA,WAAW,IAAIA,QAAAA,kBAAkB;AAAA,EAC7C,MAAM;AAAA,EACN,QAAQ;AAAA,IACP,KAAK,EAAE,MAAM,IAAIC,QAAA,eAAeC,QAAa,aAAA,EAAE;AAAA,IAC/C,OAAO,EAAE,MAAM,IAAID,QAAAA,eAAeC,QAAAA,aAAa,EAAE;AAAA,EAAA;AAEnD,CAAC;AAEY,MAAA,uBAAuB,IAAIC,QAAAA,gBAAgB;AAAA,EACvD,MAAM;AAAA,EAAyB,QAAQ;AAAA,IACtC,YAAY,CAAC;AAAA,IACb,QAAQ,CAAA;AAAA,EAAC;AAEX,CAAC;AAGY,MAAA,eAAe,IAAIH,QAAAA,kBAAkB;AAAA,EACjD,MAAM;AAAA,EACN,QAAQ;AAAA,IACP,KAAK,EAAE,MAAM,IAAIC,QAAA,eAAeC,QAAa,aAAA,EAAE;AAAA,IAC/C,SAAS;AAAA,MACR,MAAM,IAAID,QAAAA,eAAe,IAAIG,oBAAY,IAAIH,QAAAA,eAAe,QAAQ,CAAC,CAAC;AAAA,IACvE;AAAA,IACA,QAAQ,EAAE,MAAM,IAAIA,QAAA,eAAeC,QAAa,aAAA,EAAE;AAAA,IAClD,WAAW,E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,EAAE,MAAMA,uBAAe,aAAa,sDAAsD;AAAA,IAClG,UAAU,EAAE,MAAMA,uBAAe,aAAa,mFAAmF;AAAA,IACjI,oBAAoB,EAAE,MAAM,qBAAqB;AAAA,IACjD,KAAK,EAAE,MAAM,OAAO,aAAa,uDAAuD;AAAA,EAAA;AAE1F,CAAC;;;;;;;"}
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import { GraphQLObjectType, GraphQLNonNull, GraphQLString, GraphQLEnumType, GraphQLList, GraphQLInputObjectType, GraphQLInt } from "graphql";
|
|
2
|
-
const S3Header = new GraphQLObjectType({
|
|
3
|
-
name: "S3Header",
|
|
4
|
-
fields: {
|
|
5
|
-
key: { type: new GraphQLNonNull(GraphQLString) },
|
|
6
|
-
value: { type: new GraphQLNonNull(GraphQLString) }
|
|
7
|
-
}
|
|
8
|
-
});
|
|
9
|
-
const S3ContentDisposition = new GraphQLEnumType({
|
|
10
|
-
name: "S33ContentDisposition",
|
|
11
|
-
values: {
|
|
12
|
-
ATTACHMENT: {},
|
|
13
|
-
INLINE: {}
|
|
14
|
-
}
|
|
15
|
-
});
|
|
16
|
-
const S3SignedRead = new GraphQLObjectType({
|
|
17
|
-
name: "S3SignedRead",
|
|
18
|
-
fields: {
|
|
19
|
-
url: { type: new GraphQLNonNull(GraphQLString) },
|
|
20
|
-
headers: {
|
|
21
|
-
type: new GraphQLNonNull(new GraphQLList(new GraphQLNonNull(S3Header)))
|
|
22
|
-
},
|
|
23
|
-
method: { type: new GraphQLNonNull(GraphQLString) },
|
|
24
|
-
objectKey: { type: new GraphQLNonNull(GraphQLString) },
|
|
25
|
-
bucket: { type: new GraphQLNonNull(GraphQLString) }
|
|
26
|
-
}
|
|
27
|
-
});
|
|
28
|
-
const S3SignedUpload = new GraphQLObjectType({
|
|
29
|
-
name: "S3SignedUpload",
|
|
30
|
-
fields: {
|
|
31
|
-
url: { type: new GraphQLNonNull(GraphQLString) },
|
|
32
|
-
headers: {
|
|
33
|
-
type: new GraphQLNonNull(new GraphQLList(new GraphQLNonNull(S3Header)))
|
|
34
|
-
},
|
|
35
|
-
method: { type: new GraphQLNonNull(GraphQLString) },
|
|
36
|
-
objectKey: { type: new GraphQLNonNull(GraphQLString) },
|
|
37
|
-
bucket: { type: new GraphQLNonNull(GraphQLString) },
|
|
38
|
-
publicUrl: { type: new GraphQLNonNull(GraphQLString) }
|
|
39
|
-
}
|
|
40
|
-
});
|
|
41
|
-
const S3Acl = new GraphQLEnumType({
|
|
42
|
-
name: "S3Acl",
|
|
43
|
-
values: {
|
|
44
|
-
PUBLIC_READ: {},
|
|
45
|
-
PRIVATE: {},
|
|
46
|
-
NONE: {}
|
|
47
|
-
}
|
|
48
|
-
});
|
|
49
|
-
const S3GenerateSignedUploadInput = new GraphQLInputObjectType({
|
|
50
|
-
name: "S3GenerateSignedUploadInput",
|
|
51
|
-
fields: {
|
|
52
|
-
contentType: { type: GraphQLString },
|
|
53
|
-
extension: { type: GraphQLString, description: "If not provided, extension is detected from a content-type." },
|
|
54
|
-
expiration: { type: GraphQLInt, description: "Signed URL expiration." },
|
|
55
|
-
size: { type: GraphQLInt, description: "Uploaded file size. Required when you enable ACL size limits." },
|
|
56
|
-
prefix: { type: GraphQLString, description: 'Can be used as a "directory".' },
|
|
57
|
-
suffix: { type: GraphQLString, description: "Suffix after generated id and before the extension." },
|
|
58
|
-
fileName: { type: GraphQLString, description: "This only affects Content-disposition header. Does not affect actual object key." },
|
|
59
|
-
contentDisposition: { type: S3ContentDisposition },
|
|
60
|
-
acl: { type: S3Acl, description: "If not supported by S3 provider, an error is thrown." }
|
|
61
|
-
}
|
|
62
|
-
});
|
|
63
|
-
export {
|
|
64
|
-
S3Acl,
|
|
65
|
-
S3ContentDisposition,
|
|
66
|
-
S3GenerateSignedUploadInput,
|
|
67
|
-
S3Header,
|
|
68
|
-
S3SignedRead,
|
|
69
|
-
S3SignedUpload
|
|
70
|
-
};
|
|
71
|
-
//# sourceMappingURL=S3SchemaTypes.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"S3SchemaTypes.js","sources":["../../../../packages/engine-s3-plugin/src/S3SchemaTypes.ts"],"sourcesContent":["import {\n\tGraphQLEnumType,\n\tGraphQLInputObjectType,\n\tGraphQLInt,\n\tGraphQLList,\n\tGraphQLNonNull,\n\tGraphQLObjectType,\n\tGraphQLString,\n} 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', values: {\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":";AAUa,MAAA,WAAW,IAAI,kBAAkB;AAAA,EAC7C,MAAM;AAAA,EACN,QAAQ;AAAA,IACP,KAAK,EAAE,MAAM,IAAI,eAAe,aAAa,EAAE;AAAA,IAC/C,OAAO,EAAE,MAAM,IAAI,eAAe,aAAa,EAAE;AAAA,EAAA;AAEnD,CAAC;AAEY,MAAA,uBAAuB,IAAI,gBAAgB;AAAA,EACvD,MAAM;AAAA,EAAyB,QAAQ;AAAA,IACtC,YAAY,CAAC;AAAA,IACb,QAAQ,CAAA;AAAA,EAAC;AAEX,CAAC;AAGY,MAAA,eAAe,IAAI,kBAAkB;AAAA,EACjD,MAAM;AAAA,EACN,QAAQ;AAAA,IACP,KAAK,EAAE,MAA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E,MAAM,eAAe,aAAa,gCAAgC;AAAA,IAC5E,QAAQ,EAAE,MAAM,eAAe,aAAa,sDAAsD;AAAA,IAClG,UAAU,EAAE,MAAM,eAAe,aAAa,mFAAmF;AAAA,IACjI,oBAAoB,EAAE,MAAM,qBAAqB;AAAA,IACjD,KAAK,EAAE,MAAM,OAAO,aAAa,uDAAuD;AAAA,EAAA;AAE1F,CAAC;"}
|
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const mimeTypes = require("mime-types");
|
|
4
|
-
const Config = require("./Config.cjs");
|
|
5
|
-
const graphqlUtils = require("@contember/graphql-utils");
|
|
6
|
-
const S3Signer = require("./S3Signer.cjs");
|
|
7
|
-
var __defProp = Object.defineProperty;
|
|
8
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
9
|
-
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
10
|
-
class S3Service {
|
|
11
|
-
constructor(config, providers, authorizator) {
|
|
12
|
-
this.config = config;
|
|
13
|
-
this.providers = providers;
|
|
14
|
-
this.authorizator = authorizator;
|
|
15
|
-
__publicField(this, "publicBaseUrl");
|
|
16
|
-
__publicField(this, "signer");
|
|
17
|
-
this.publicBaseUrl = Config.resolveS3PublicBaseUrl(config);
|
|
18
|
-
this.signer = new S3Signer.S3Signer(config, providers);
|
|
19
|
-
}
|
|
20
|
-
getSignedUploadUrl({ acl, contentDisposition, contentType, expiration, prefix, suffix, fileName, extension, size }) {
|
|
21
|
-
const ext = extension ?? ((contentType ? mimeTypes.extension(contentType) : null) || "bin");
|
|
22
|
-
const id = this.providers.uuid();
|
|
23
|
-
const localObjectKey = (prefix ? prefix + "/" : "") + `${id}${suffix ?? ""}.${ext}`;
|
|
24
|
-
this.authorizator.verifyUploadAccess({ key: localObjectKey, size });
|
|
25
|
-
const objectKey = (this.config.prefix ? this.config.prefix + "/" : "") + localObjectKey;
|
|
26
|
-
const bucket = this.config.bucket;
|
|
27
|
-
if (acl && this.config.noAcl) {
|
|
28
|
-
throw new graphqlUtils.UserInputError("ACL is not supported");
|
|
29
|
-
}
|
|
30
|
-
const headers = {
|
|
31
|
-
"Cache-Control": "immutable"
|
|
32
|
-
};
|
|
33
|
-
if (contentType) {
|
|
34
|
-
headers["Content-Type"] = contentType;
|
|
35
|
-
}
|
|
36
|
-
if (!this.config.noAcl && acl !== "NONE") {
|
|
37
|
-
const mapping = { PUBLIC_READ: "public-read", PRIVATE: "private" };
|
|
38
|
-
headers["x-amz-acl"] = mapping[acl ?? "PUBLIC_READ"];
|
|
39
|
-
}
|
|
40
|
-
if (fileName || contentDisposition) {
|
|
41
|
-
let contentDispositionHeader = contentDisposition?.toLowerCase() ?? "inline";
|
|
42
|
-
if (fileName) {
|
|
43
|
-
contentDispositionHeader += `; filename*=UTF-8''${encodeURIComponent(fileName)}`;
|
|
44
|
-
}
|
|
45
|
-
headers["Content-Disposition"] = contentDispositionHeader;
|
|
46
|
-
}
|
|
47
|
-
const headersToSend = Object.entries(headers).map(([key, value]) => ({ key, value }));
|
|
48
|
-
if (size) {
|
|
49
|
-
headers["Content-Length"] = String(size);
|
|
50
|
-
}
|
|
51
|
-
const url = this.signer.sign({
|
|
52
|
-
action: "upload",
|
|
53
|
-
expiration: expiration ?? 3600,
|
|
54
|
-
key: objectKey,
|
|
55
|
-
headers: { ...headers }
|
|
56
|
-
});
|
|
57
|
-
const publicUrl = this.formatPublicUrl(objectKey);
|
|
58
|
-
return {
|
|
59
|
-
bucket,
|
|
60
|
-
objectKey,
|
|
61
|
-
url,
|
|
62
|
-
publicUrl,
|
|
63
|
-
headers: headersToSend,
|
|
64
|
-
method: "PUT"
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
getSignedReadUrl({ objectKey, expiration }) {
|
|
68
|
-
const bucket = this.config.bucket;
|
|
69
|
-
const publicPrefix = this.formatPublicUrl("");
|
|
70
|
-
if (objectKey.startsWith(publicPrefix)) {
|
|
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 });
|
|
80
|
-
const url = this.signer.sign({
|
|
81
|
-
action: "read",
|
|
82
|
-
expiration: expiration ?? 3600,
|
|
83
|
-
key: objectKey,
|
|
84
|
-
headers: {}
|
|
85
|
-
});
|
|
86
|
-
return {
|
|
87
|
-
bucket,
|
|
88
|
-
objectKey,
|
|
89
|
-
url,
|
|
90
|
-
headers: [],
|
|
91
|
-
method: "GET"
|
|
92
|
-
};
|
|
93
|
-
}
|
|
94
|
-
formatPublicUrl(key) {
|
|
95
|
-
return `${this.publicBaseUrl}/${key}`;
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
class S3ServiceFactory {
|
|
99
|
-
create(config, providers, authorizator) {
|
|
100
|
-
return new S3Service(config, providers, authorizator);
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
exports.S3Service = S3Service;
|
|
104
|
-
exports.S3ServiceFactory = S3ServiceFactory;
|
|
105
|
-
//# sourceMappingURL=S3Service.cjs.map
|