@webiny/api-file-manager 5.30.0 → 5.31.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/handlers/download/index.d.ts +3 -8
- package/handlers/download/index.js +55 -54
- package/handlers/download/index.js.map +1 -1
- package/handlers/manage/index.d.ts +5 -5
- package/handlers/manage/index.js +48 -48
- package/handlers/manage/index.js.map +1 -1
- package/handlers/transform/index.d.ts +2 -5
- package/handlers/transform/index.js +64 -68
- package/handlers/transform/index.js.map +1 -1
- package/handlers/transform/loaders/imageLoader.d.ts +1 -0
- package/handlers/transform/loaders/imageLoader.js.map +1 -1
- package/handlers/transform/managers/imageManager.js +5 -2
- package/handlers/transform/managers/imageManager.js.map +1 -1
- package/handlers/types.d.ts +1 -26
- package/handlers/types.js.map +1 -1
- package/handlers/utils/index.d.ts +0 -1
- package/handlers/utils/index.js +0 -18
- package/handlers/utils/index.js.map +1 -1
- package/package.json +20 -19
- package/plugins/crud/files.crud.d.ts +1 -1
- package/plugins/crud/files.crud.js +2 -2
- package/plugins/crud/files.crud.js.map +1 -1
- package/plugins/crud/settings.crud.d.ts +1 -1
- package/plugins/crud/settings.crud.js +2 -2
- package/plugins/crud/settings.crud.js.map +1 -1
- package/plugins/crud/system.crud.d.ts +1 -1
- package/plugins/crud/system.crud.js +2 -2
- package/plugins/crud/system.crud.js.map +1 -1
- package/plugins/index.d.ts +1 -1
- package/plugins/storage/index.d.ts +1 -1
- package/plugins/storage/index.js +2 -2
- package/plugins/storage/index.js.map +1 -1
- package/types.d.ts +1 -1
- package/types.js.map +1 -1
- package/handlers/utils/createHandler.d.ts +0 -24
- package/handlers/utils/createHandler.js +0 -69
- package/handlers/utils/createHandler.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["canProcess","params","key","extension","SUPPORTED_IMAGES","includes","startsWith","OPTIMIZED_IMAGE_PREFIX","OPTIMIZED_TRANSFORMED_IMAGE_PREFIX","process","s3","deleteObject","getObjectParams","getImageKey","promise","SUPPORTED_TRANSFORMABLE_IMAGES","env","getEnvironment","imagesList","listObjects","Bucket","bucket","Prefix","getOptimizedTransformedImageKeyPrefix","Contents","imageObject","Key"],"sources":["imageManager.ts"],"sourcesContent":["import S3 from \"aws-sdk/clients/s3\";\nimport { getObjectParams, getEnvironment } from \"~/handlers/utils\";\nimport {\n SUPPORTED_IMAGES,\n SUPPORTED_TRANSFORMABLE_IMAGES,\n OPTIMIZED_IMAGE_PREFIX,\n OPTIMIZED_TRANSFORMED_IMAGE_PREFIX,\n getImageKey,\n getOptimizedTransformedImageKeyPrefix\n} from \"../utils\";\n\nexport interface ImageManagerCanProcessParams {\n key: string;\n extension: string;\n}\nexport interface ImageManagerProcessParams {\n s3: S3;\n key: string;\n extension: string;\n}\nexport default {\n canProcess: (params: ImageManagerCanProcessParams) => {\n const { key, extension } = params;\n if (SUPPORTED_IMAGES.includes(extension) === false) {\n return false;\n }\n\n return (\n key.startsWith(OPTIMIZED_IMAGE_PREFIX) ||\n key.startsWith(OPTIMIZED_TRANSFORMED_IMAGE_PREFIX)\n );\n },\n async process({ s3, key, extension }: ImageManagerProcessParams) {\n // 1. Get optimized image's key.\n\n await s3.deleteObject(getObjectParams(getImageKey({ key }))).promise();\n\n // 2. Search for all transformed images and delete those too.\n if (SUPPORTED_TRANSFORMABLE_IMAGES.includes(extension) === false) {\n return;\n }\n const env = getEnvironment();\n const imagesList = await s3\n .listObjects({\n Bucket: env.bucket,\n Prefix: getOptimizedTransformedImageKeyPrefix(key)\n })\n .promise();\n\n if (!imagesList.Contents) {\n return;\n }\n\n for (const imageObject of imagesList.Contents) {\n if (!imageObject.Key) {\n continue;\n }\n await s3.deleteObject(getObjectParams(imageObject.Key)).promise();\n }\n }\n};\n"],"mappings":";;;;;;;AACA;;AACA;;eAkBe;EACXA,UAAU,EAAGC,MAAD,IAA0C;IAClD,MAAM;MAAEC,GAAF;MAAOC;IAAP,IAAqBF,MAA3B;;IACA,IAAIG,wBAAA,CAAiBC,QAAjB,CAA0BF,SAA1B,MAAyC,KAA7C,EAAoD;MAChD,OAAO,KAAP;IACH
|
|
1
|
+
{"version":3,"names":["canProcess","params","key","extension","SUPPORTED_IMAGES","includes","startsWith","OPTIMIZED_IMAGE_PREFIX","OPTIMIZED_TRANSFORMED_IMAGE_PREFIX","process","s3","deleteObject","getObjectParams","getImageKey","promise","SUPPORTED_TRANSFORMABLE_IMAGES","env","getEnvironment","imagesList","listObjects","Bucket","bucket","Prefix","getOptimizedTransformedImageKeyPrefix","Contents","imageObject","Key"],"sources":["imageManager.ts"],"sourcesContent":["import S3 from \"aws-sdk/clients/s3\";\nimport { getObjectParams, getEnvironment } from \"~/handlers/utils\";\nimport {\n SUPPORTED_IMAGES,\n SUPPORTED_TRANSFORMABLE_IMAGES,\n OPTIMIZED_IMAGE_PREFIX,\n OPTIMIZED_TRANSFORMED_IMAGE_PREFIX,\n getImageKey,\n getOptimizedTransformedImageKeyPrefix\n} from \"../utils\";\n\nexport interface ImageManagerCanProcessParams {\n key: string;\n extension: string;\n}\nexport interface ImageManagerProcessParams {\n s3: S3;\n key: string;\n extension: string;\n}\nexport default {\n canProcess: (params: ImageManagerCanProcessParams) => {\n const { key, extension } = params;\n if (SUPPORTED_IMAGES.includes(extension) === false) {\n return false;\n }\n\n // We only want to process original images, and delete all variations of it at once.\n // We DO NOT want to process the event for the deletion of an optimized/transformed image.\n // Unfortunately, there's no way to filter those events on the S3 bucket itself, so we have to do it this way.\n return !(\n key.startsWith(OPTIMIZED_IMAGE_PREFIX) ||\n key.startsWith(OPTIMIZED_TRANSFORMED_IMAGE_PREFIX)\n );\n },\n async process({ s3, key, extension }: ImageManagerProcessParams) {\n // 1. Get optimized image's key.\n\n await s3.deleteObject(getObjectParams(getImageKey({ key }))).promise();\n\n // 2. Search for all transformed images and delete those too.\n if (SUPPORTED_TRANSFORMABLE_IMAGES.includes(extension) === false) {\n return;\n }\n const env = getEnvironment();\n const imagesList = await s3\n .listObjects({\n Bucket: env.bucket,\n Prefix: getOptimizedTransformedImageKeyPrefix(key)\n })\n .promise();\n\n if (!imagesList.Contents) {\n return;\n }\n\n for (const imageObject of imagesList.Contents) {\n if (!imageObject.Key) {\n continue;\n }\n await s3.deleteObject(getObjectParams(imageObject.Key)).promise();\n }\n }\n};\n"],"mappings":";;;;;;;AACA;;AACA;;eAkBe;EACXA,UAAU,EAAGC,MAAD,IAA0C;IAClD,MAAM;MAAEC,GAAF;MAAOC;IAAP,IAAqBF,MAA3B;;IACA,IAAIG,wBAAA,CAAiBC,QAAjB,CAA0BF,SAA1B,MAAyC,KAA7C,EAAoD;MAChD,OAAO,KAAP;IACH,CAJiD,CAMlD;IACA;IACA;;;IACA,OAAO,EACHD,GAAG,CAACI,UAAJ,CAAeC,8BAAf,KACAL,GAAG,CAACI,UAAJ,CAAeE,0CAAf,CAFG,CAAP;EAIH,CAdU;;EAeX,MAAMC,OAAN,CAAc;IAAEC,EAAF;IAAMR,GAAN;IAAWC;EAAX,CAAd,EAAiE;IAC7D;IAEA,MAAMO,EAAE,CAACC,YAAH,CAAgB,IAAAC,sBAAA,EAAgB,IAAAC,mBAAA,EAAY;MAAEX;IAAF,CAAZ,CAAhB,CAAhB,EAAuDY,OAAvD,EAAN,CAH6D,CAK7D;;IACA,IAAIC,sCAAA,CAA+BV,QAA/B,CAAwCF,SAAxC,MAAuD,KAA3D,EAAkE;MAC9D;IACH;;IACD,MAAMa,GAAG,GAAG,IAAAC,qBAAA,GAAZ;IACA,MAAMC,UAAU,GAAG,MAAMR,EAAE,CACtBS,WADoB,CACR;MACTC,MAAM,EAAEJ,GAAG,CAACK,MADH;MAETC,MAAM,EAAE,IAAAC,6CAAA,EAAsCrB,GAAtC;IAFC,CADQ,EAKpBY,OALoB,EAAzB;;IAOA,IAAI,CAACI,UAAU,CAACM,QAAhB,EAA0B;MACtB;IACH;;IAED,KAAK,MAAMC,WAAX,IAA0BP,UAAU,CAACM,QAArC,EAA+C;MAC3C,IAAI,CAACC,WAAW,CAACC,GAAjB,EAAsB;QAClB;MACH;;MACD,MAAMhB,EAAE,CAACC,YAAH,CAAgB,IAAAC,sBAAA,EAAgBa,WAAW,CAACC,GAA5B,CAAhB,EAAkDZ,OAAlD,EAAN;IACH;EACJ;;AA1CU,C"}
|
package/handlers/types.d.ts
CHANGED
|
@@ -1,25 +1,4 @@
|
|
|
1
|
-
export interface
|
|
2
|
-
httpMethod: "POST" | "OPTIONS";
|
|
3
|
-
}
|
|
4
|
-
interface S3Record {
|
|
5
|
-
s3: {
|
|
6
|
-
object: {
|
|
7
|
-
key?: string;
|
|
8
|
-
};
|
|
9
|
-
};
|
|
10
|
-
}
|
|
11
|
-
export interface ManageHandlerEventArgs extends HandlerEventArgs {
|
|
12
|
-
Records: S3Record[];
|
|
13
|
-
}
|
|
14
|
-
export interface DownloadHandlerEventArgs extends HandlerEventArgs {
|
|
15
|
-
pathParameters: {
|
|
16
|
-
path: string;
|
|
17
|
-
};
|
|
18
|
-
queryStringParameters?: {
|
|
19
|
-
width?: string;
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
export interface TransformHandlerEventArgs extends HandlerEventArgs {
|
|
1
|
+
export interface TransformHandlerEventPayload {
|
|
23
2
|
body: {
|
|
24
3
|
key: string;
|
|
25
4
|
transformations: {
|
|
@@ -27,7 +6,3 @@ export interface TransformHandlerEventArgs extends HandlerEventArgs {
|
|
|
27
6
|
};
|
|
28
7
|
};
|
|
29
8
|
}
|
|
30
|
-
export interface HandlerHeaders {
|
|
31
|
-
[key: string]: string | boolean | undefined;
|
|
32
|
-
}
|
|
33
|
-
export {};
|
package/handlers/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["export interface
|
|
1
|
+
{"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["export interface TransformHandlerEventPayload {\n body: {\n key: string;\n transformations: {\n width: string;\n };\n };\n}\n"],"mappings":""}
|
package/handlers/utils/index.js
CHANGED
|
@@ -5,10 +5,6 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
|
-
var _exportNames = {
|
|
9
|
-
getEnvironment: true,
|
|
10
|
-
getObjectParams: true
|
|
11
|
-
};
|
|
12
8
|
Object.defineProperty(exports, "getEnvironment", {
|
|
13
9
|
enumerable: true,
|
|
14
10
|
get: function () {
|
|
@@ -24,18 +20,4 @@ Object.defineProperty(exports, "getObjectParams", {
|
|
|
24
20
|
|
|
25
21
|
var _getEnvironment = _interopRequireDefault(require("./getEnvironment"));
|
|
26
22
|
|
|
27
|
-
var _createHandler = require("./createHandler");
|
|
28
|
-
|
|
29
|
-
Object.keys(_createHandler).forEach(function (key) {
|
|
30
|
-
if (key === "default" || key === "__esModule") return;
|
|
31
|
-
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
32
|
-
if (key in exports && exports[key] === _createHandler[key]) return;
|
|
33
|
-
Object.defineProperty(exports, key, {
|
|
34
|
-
enumerable: true,
|
|
35
|
-
get: function () {
|
|
36
|
-
return _createHandler[key];
|
|
37
|
-
}
|
|
38
|
-
});
|
|
39
|
-
});
|
|
40
|
-
|
|
41
23
|
var _getObjectParams = _interopRequireDefault(require("./getObjectParams"));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export { default as getEnvironment } from \"./getEnvironment\";\nexport
|
|
1
|
+
{"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export { default as getEnvironment } from \"./getEnvironment\";\nexport { default as getObjectParams } from \"./getObjectParams\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;;AACA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webiny/api-file-manager",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.31.0-beta.0",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"fm:base"
|
|
@@ -18,23 +18,24 @@
|
|
|
18
18
|
],
|
|
19
19
|
"license": "MIT",
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@babel/runtime": "7.18.
|
|
21
|
+
"@babel/runtime": "7.18.9",
|
|
22
22
|
"@commodo/fields": "1.1.2-beta.20",
|
|
23
|
-
"@webiny/api
|
|
24
|
-
"@webiny/api-
|
|
25
|
-
"@webiny/api-
|
|
26
|
-
"@webiny/
|
|
27
|
-
"@webiny/
|
|
28
|
-
"@webiny/handler
|
|
29
|
-
"@webiny/handler-
|
|
30
|
-
"@webiny/handler-
|
|
31
|
-
"@webiny/
|
|
32
|
-
"@webiny/
|
|
33
|
-
"@webiny/
|
|
34
|
-
"
|
|
23
|
+
"@webiny/api": "5.31.0-beta.0",
|
|
24
|
+
"@webiny/api-security": "5.31.0-beta.0",
|
|
25
|
+
"@webiny/api-tenancy": "5.31.0-beta.0",
|
|
26
|
+
"@webiny/api-upgrade": "5.31.0-beta.0",
|
|
27
|
+
"@webiny/error": "5.31.0-beta.0",
|
|
28
|
+
"@webiny/handler": "5.31.0-beta.0",
|
|
29
|
+
"@webiny/handler-aws": "5.31.0-beta.0",
|
|
30
|
+
"@webiny/handler-client": "5.31.0-beta.0",
|
|
31
|
+
"@webiny/handler-graphql": "5.31.0-beta.0",
|
|
32
|
+
"@webiny/plugins": "5.31.0-beta.0",
|
|
33
|
+
"@webiny/project-utils": "5.31.0-beta.0",
|
|
34
|
+
"@webiny/validation": "5.31.0-beta.0",
|
|
35
|
+
"aws-sdk": "2.1188.0",
|
|
35
36
|
"commodo-fields-object": "1.0.6",
|
|
36
37
|
"mdbid": "1.0.0",
|
|
37
|
-
"object-hash": "
|
|
38
|
+
"object-hash": "2.2.0",
|
|
38
39
|
"sanitize-filename": "1.6.3"
|
|
39
40
|
},
|
|
40
41
|
"devDependencies": {
|
|
@@ -44,9 +45,9 @@
|
|
|
44
45
|
"@babel/plugin-transform-runtime": "^7.16.4",
|
|
45
46
|
"@babel/preset-env": "^7.16.4",
|
|
46
47
|
"@babel/preset-typescript": "^7.16.0",
|
|
47
|
-
"@webiny/api-i18n": "^5.
|
|
48
|
-
"@webiny/api-i18n-ddb": "^5.
|
|
49
|
-
"@webiny/cli": "^5.
|
|
48
|
+
"@webiny/api-i18n": "^5.31.0-beta.0",
|
|
49
|
+
"@webiny/api-i18n-ddb": "^5.31.0-beta.0",
|
|
50
|
+
"@webiny/cli": "^5.31.0-beta.0",
|
|
50
51
|
"jest": "^28.1.0",
|
|
51
52
|
"rimraf": "^3.0.2",
|
|
52
53
|
"ttypescript": "^1.5.12",
|
|
@@ -71,5 +72,5 @@
|
|
|
71
72
|
]
|
|
72
73
|
}
|
|
73
74
|
},
|
|
74
|
-
"gitHead": "
|
|
75
|
+
"gitHead": "dea7c56325ff140ef0e2d761f3e65708d46d401e"
|
|
75
76
|
}
|
|
@@ -17,7 +17,7 @@ var _apiSecurity = require("@webiny/api-security");
|
|
|
17
17
|
|
|
18
18
|
var _checkBasePermissions = _interopRequireDefault(require("./utils/checkBasePermissions"));
|
|
19
19
|
|
|
20
|
-
var
|
|
20
|
+
var _api = require("@webiny/api");
|
|
21
21
|
|
|
22
22
|
var _FilePlugin = require("../definitions/FilePlugin");
|
|
23
23
|
|
|
@@ -64,7 +64,7 @@ const getLocaleCode = context => {
|
|
|
64
64
|
return locale.code;
|
|
65
65
|
};
|
|
66
66
|
|
|
67
|
-
const filesContextCrudPlugin = new
|
|
67
|
+
const filesContextCrudPlugin = new _api.ContextPlugin(async context => {
|
|
68
68
|
const pluginType = _FilesStorageOperationsProviderPlugin.FilesStorageOperationsProviderPlugin.type;
|
|
69
69
|
const providerPlugin = context.plugins.byType(pluginType).find(() => true);
|
|
70
70
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["BATCH_CREATE_MAX_FILES","checkOwnership","file","permission","context","own","identity","security","getIdentity","createdBy","id","NotAuthorizedError","getLocaleCode","i18n","WebinyError","locale","getContentLocale","code","filesContextCrudPlugin","ContextPlugin","pluginType","FilesStorageOperationsProviderPlugin","type","providerPlugin","plugins","byType","find","storageOperations","provide","fileManager","filePlugins","FilePlugin","files","getFile","checkBasePermissions","rwd","get","where","tenant","tenancy","getCurrentTenant","NotFoundError","createFile","input","mdbid","tags","Array","isArray","meta","private","createdOn","Date","toISOString","displayName","webinyVersion","WEBINY_VERSION","runLifecycleEvent","data","result","create","ex","message","updateFile","original","update","deleteFile","delete","createFilesInBatch","inputs","length","map","results","createBatch","listFiles","params","limit","search","types","ids","after","initialWhere","sort","initialSort","type_in","tag_in","tag","toLowerCase","id_in","list","listTags","name"],"sources":["files.crud.ts"],"sourcesContent":["/**\n * Package mdbid does not have types.\n */\n// @ts-ignore\nimport mdbid from \"mdbid\";\nimport { NotFoundError } from \"@webiny/handler-graphql\";\nimport { NotAuthorizedError } from \"@webiny/api-security\";\nimport {\n CreatedBy,\n File,\n FileManagerContext,\n FileManagerFilesStorageOperationsListParamsWhere,\n FileManagerFilesStorageOperationsTagsParamsWhere,\n FilePermission,\n FilesListOpts\n} from \"~/types\";\nimport checkBasePermissions from \"./utils/checkBasePermissions\";\nimport { ContextPlugin } from \"@webiny/handler\";\nimport { FilePlugin } from \"~/plugins/definitions/FilePlugin\";\nimport { FilesStorageOperationsProviderPlugin } from \"~/plugins/definitions/FilesStorageOperationsProviderPlugin\";\nimport WebinyError from \"@webiny/error\";\nimport { runLifecycleEvent } from \"~/plugins/crud/utils/lifecycleEvents\";\n\nconst BATCH_CREATE_MAX_FILES = 20;\n\n/**\n * If permission is limited to \"own\" files only, check that current identity owns the file.\n */\nconst checkOwnership = (file: File, permission: FilePermission, context: FileManagerContext) => {\n if (permission?.own === true) {\n const identity = context.security.getIdentity();\n if (file.createdBy.id !== identity.id) {\n throw new NotAuthorizedError();\n }\n }\n};\n\nconst getLocaleCode = (context: FileManagerContext): string => {\n if (!context.i18n) {\n throw new WebinyError(\"Missing i18n on the FileManagerContext.\", \"MISSING_I18N\");\n }\n\n const locale = context.i18n.getContentLocale();\n if (!locale) {\n throw new WebinyError(\n \"Missing content locale on the FileManagerContext.\",\n \"MISSING_I18N_CONTENT_LOCALE\"\n );\n }\n\n if (!locale.code) {\n throw new WebinyError(\n \"Missing content locale code on the FileManagerContext.\",\n \"MISSING_I18N_CONTENT_LOCALE_CODE\"\n );\n }\n return locale.code;\n};\n\nconst filesContextCrudPlugin = new ContextPlugin<FileManagerContext>(async context => {\n const pluginType = FilesStorageOperationsProviderPlugin.type;\n\n const providerPlugin = context.plugins\n .byType<FilesStorageOperationsProviderPlugin>(pluginType)\n .find(() => true);\n\n if (!providerPlugin) {\n throw new WebinyError(`Missing \"${pluginType}\" plugin.`, \"PLUGIN_NOT_FOUND\", {\n type: pluginType\n });\n }\n\n const storageOperations = await providerPlugin.provide({\n context\n });\n\n if (!context.fileManager) {\n context.fileManager = {} as any;\n }\n\n const filePlugins = context.plugins.byType<FilePlugin>(FilePlugin.type);\n\n context.fileManager.files = {\n async getFile(id: string) {\n const permission = await checkBasePermissions(context, { rwd: \"r\" });\n\n const file = await storageOperations.get({\n where: {\n id,\n tenant: context.tenancy.getCurrentTenant().id,\n locale: getLocaleCode(context)\n }\n });\n\n if (!file) {\n throw new NotFoundError(`File with id \"${id}\" does not exists.`);\n }\n\n checkOwnership(file, permission, context);\n\n return file;\n },\n async createFile(input) {\n await checkBasePermissions(context, { rwd: \"w\" });\n const identity = context.security.getIdentity();\n const tenant = context.tenancy.getCurrentTenant();\n\n const id = mdbid();\n\n const file: File = {\n ...input,\n tags: Array.isArray(input.tags) ? input.tags : [],\n id,\n meta: {\n private: false,\n ...(input.meta || {})\n },\n tenant: tenant.id,\n createdOn: new Date().toISOString(),\n createdBy: {\n id: identity.id,\n displayName: identity.displayName,\n type: identity.type\n },\n locale: getLocaleCode(context),\n webinyVersion: context.WEBINY_VERSION\n };\n\n try {\n await runLifecycleEvent(\"beforeCreate\", {\n context,\n plugins: filePlugins,\n data: file\n });\n const result = await storageOperations.create({\n file\n });\n await runLifecycleEvent(\"afterCreate\", {\n context,\n plugins: filePlugins,\n data: file,\n file: result\n });\n return result;\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not create a file.\",\n ex.code || \"CREATE_FILE_ERROR\",\n {\n ...(ex.data || {}),\n file\n }\n );\n }\n },\n async updateFile(id, input) {\n const permission = await checkBasePermissions(context, { rwd: \"w\" });\n\n const original = await storageOperations.get({\n where: {\n id,\n tenant: context.tenancy.getCurrentTenant().id,\n locale: getLocaleCode(context)\n }\n });\n\n if (!original) {\n throw new NotFoundError(`File with id \"${id}\" does not exists.`);\n }\n\n checkOwnership(original, permission, context);\n\n const file: File = {\n ...original,\n ...input,\n tags: Array.isArray(input.tags)\n ? input.tags\n : Array.isArray(original.tags)\n ? original.tags\n : [],\n id: original.id,\n webinyVersion: context.WEBINY_VERSION\n };\n\n try {\n await runLifecycleEvent(\"beforeUpdate\", {\n context,\n plugins: filePlugins,\n original,\n data: file\n });\n const result = await storageOperations.update({\n original,\n file\n });\n await runLifecycleEvent(\"afterUpdate\", {\n context,\n plugins: filePlugins,\n original,\n data: file,\n file: result\n });\n return result;\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not update a file.\",\n ex.code || \"UPDATE_FILE_ERROR\",\n {\n ...(ex.data || {}),\n original,\n file\n }\n );\n }\n },\n async deleteFile(id) {\n const permission = await checkBasePermissions(context, { rwd: \"d\" });\n\n const file = await storageOperations.get({\n where: {\n id,\n tenant: context.tenancy.getCurrentTenant().id,\n locale: getLocaleCode(context)\n }\n });\n if (!file) {\n throw new NotFoundError(`File with id \"${id}\" does not exists.`);\n }\n\n checkOwnership(file, permission, context);\n\n try {\n await runLifecycleEvent(\"beforeDelete\", {\n context,\n plugins: filePlugins,\n file\n });\n await storageOperations.delete({\n file\n });\n await runLifecycleEvent(\"afterDelete\", {\n context,\n plugins: filePlugins,\n file\n });\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not delete a file.\",\n ex.code || \"DELETE_FILE_ERROR\",\n {\n ...(ex.data || {}),\n id,\n file\n }\n );\n }\n\n return true;\n },\n async createFilesInBatch(inputs) {\n if (!Array.isArray(inputs)) {\n throw new WebinyError(`\"data\" must be an array.`, \"CREATE_FILES_NON_ARRAY\");\n }\n\n if (inputs.length === 0) {\n throw new WebinyError(\n `\"data\" argument must contain at least one file.`,\n \"CREATE_FILES_MIN_FILES\"\n );\n }\n\n if (inputs.length > BATCH_CREATE_MAX_FILES) {\n throw new WebinyError(\n `\"data\" argument must not contain more than ${BATCH_CREATE_MAX_FILES} files.`,\n \"CREATE_FILES_MAX_FILES\"\n );\n }\n\n await checkBasePermissions(context, { rwd: \"w\" });\n\n const identity = context.security.getIdentity();\n const tenant = context.tenancy.getCurrentTenant();\n const createdBy: CreatedBy = {\n id: identity.id,\n displayName: identity.displayName,\n type: identity.type\n };\n\n const files: File[] = inputs.map(input => {\n return {\n ...input,\n tags: Array.isArray(input.tags) ? input.tags : [],\n meta: {\n private: false,\n ...(input.meta || {})\n },\n id: mdbid(),\n tenant: tenant.id,\n createdOn: new Date().toISOString(),\n createdBy,\n locale: getLocaleCode(context),\n webinyVersion: context.WEBINY_VERSION\n };\n });\n\n try {\n await runLifecycleEvent(\"beforeBatchCreate\", {\n context,\n plugins: filePlugins,\n data: files\n });\n const results = await storageOperations.createBatch({\n files\n });\n await runLifecycleEvent(\"afterBatchCreate\", {\n context,\n plugins: filePlugins,\n data: files,\n files: results\n });\n return results;\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not create a batch of files.\",\n ex.code || \"CREATE_FILES_ERROR\",\n {\n ...(ex.data || {}),\n files\n }\n );\n }\n },\n async listFiles(params: FilesListOpts = {}) {\n const permission = await checkBasePermissions(context, { rwd: \"r\" });\n\n const {\n limit = 40,\n search = \"\",\n types = [],\n tags = [],\n ids = [],\n after = null,\n where: initialWhere,\n sort: initialSort\n } = params;\n\n const where: FileManagerFilesStorageOperationsListParamsWhere = {\n ...initialWhere,\n private: false,\n locale: getLocaleCode(context),\n tenant: context.tenancy.getCurrentTenant().id\n };\n /**\n * Always override the createdBy received from the user, if any.\n */\n if (permission.own === true) {\n const identity = context.security.getIdentity();\n where.createdBy = identity.id;\n }\n /**\n * We need to map the old GraphQL definition to the new one.\n * That GQL definition is marked as deprecated.\n */\n /**\n * To have standardized where objects across the applications, we transform the types into type_in.\n */\n if (Array.isArray(types) && types.length > 0 && !where.type_in) {\n where.type_in = types;\n }\n /**\n * We are assigning search to tag and name search.\n * This should be treated as OR condition in the storage operations.\n */\n if (search && !where.search) {\n where.search = search;\n }\n /**\n * Same as on types/type_in.\n */\n if (Array.isArray(tags) && tags.length > 0 && !where.tag_in) {\n where.tag_in = tags.map(tag => tag.toLowerCase());\n }\n /**\n * Same as on types/type_in.\n */\n if (Array.isArray(ids) && ids.length > 0 && !where.id_in) {\n where.id_in = ids;\n }\n\n const sort =\n Array.isArray(initialSort) && initialSort.length > 0 ? initialSort : [\"id_DESC\"];\n try {\n return await storageOperations.list({\n where,\n after,\n limit,\n sort\n });\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not list files by given parameters.\",\n ex.code || \"FILE_TAG_SEARCH_ERROR\",\n {\n ...(ex.data || {}),\n where,\n after,\n limit,\n sort\n }\n );\n }\n },\n async listTags({ where: initialWhere, after, limit }) {\n await checkBasePermissions(context);\n\n const where: FileManagerFilesStorageOperationsTagsParamsWhere = {\n ...initialWhere,\n tenant: context.tenancy.getCurrentTenant().id,\n locale: getLocaleCode(context)\n };\n\n const params = {\n where,\n limit: limit || 100000,\n after\n };\n\n try {\n const [tags] = await storageOperations.tags(params);\n if (Array.isArray(tags) === false) {\n return [];\n }\n /**\n * just to keep it standardized, sort by the tag ASC\n */\n return tags.sort();\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not search for tags.\",\n ex.code || \"FILE_TAG_SEARCH_ERROR\",\n {\n ...(ex.data || {}),\n params\n }\n );\n }\n }\n };\n});\n\nfilesContextCrudPlugin.name = \"FileManagerFilesCrud\";\n\nexport default filesContextCrudPlugin;\n"],"mappings":";;;;;;;;;;;AAIA;;AACA;;AACA;;AAUA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;;;AAEA,MAAMA,sBAAsB,GAAG,EAA/B;AAEA;AACA;AACA;;AACA,MAAMC,cAAc,GAAG,CAACC,IAAD,EAAaC,UAAb,EAAyCC,OAAzC,KAAyE;EAC5F,IAAI,CAAAD,UAAU,SAAV,IAAAA,UAAU,WAAV,YAAAA,UAAU,CAAEE,GAAZ,MAAoB,IAAxB,EAA8B;IAC1B,MAAMC,QAAQ,GAAGF,OAAO,CAACG,QAAR,CAAiBC,WAAjB,EAAjB;;IACA,IAAIN,IAAI,CAACO,SAAL,CAAeC,EAAf,KAAsBJ,QAAQ,CAACI,EAAnC,EAAuC;MACnC,MAAM,IAAIC,+BAAJ,EAAN;IACH;EACJ;AACJ,CAPD;;AASA,MAAMC,aAAa,GAAIR,OAAD,IAAyC;EAC3D,IAAI,CAACA,OAAO,CAACS,IAAb,EAAmB;IACf,MAAM,IAAIC,cAAJ,CAAgB,yCAAhB,EAA2D,cAA3D,CAAN;EACH;;EAED,MAAMC,MAAM,GAAGX,OAAO,CAACS,IAAR,CAAaG,gBAAb,EAAf;;EACA,IAAI,CAACD,MAAL,EAAa;IACT,MAAM,IAAID,cAAJ,CACF,mDADE,EAEF,6BAFE,CAAN;EAIH;;EAED,IAAI,CAACC,MAAM,CAACE,IAAZ,EAAkB;IACd,MAAM,IAAIH,cAAJ,CACF,wDADE,EAEF,kCAFE,CAAN;EAIH;;EACD,OAAOC,MAAM,CAACE,IAAd;AACH,CApBD;;AAsBA,MAAMC,sBAAsB,GAAG,IAAIC,sBAAJ,CAAsC,MAAMf,OAAN,IAAiB;EAClF,MAAMgB,UAAU,GAAGC,0EAAA,CAAqCC,IAAxD;EAEA,MAAMC,cAAc,GAAGnB,OAAO,CAACoB,OAAR,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BC,gBAAhB,GAAmC9B,EAFc;QAGzDK,MAAM,EAAEH,aAAa,CAACR,OAAD;MAHoC,EAA7D;;MAMA,MAAMsE,MAAM,GAAG;QACXrC,KADW;QAEXsC,KAAK,EAAEA,KAAK,IAAI,MAFL;QAGXI;MAHW,CAAf;;MAMA,IAAI;QACA,MAAM,CAAClC,IAAD,IAAS,MAAMlB,iBAAiB,CAACkB,IAAlB,CAAuB6B,MAAvB,CAArB;;QACA,IAAI5B,KAAK,CAACC,OAAN,CAAcF,IAAd,MAAwB,KAA5B,EAAmC;UAC/B,OAAO,EAAP;QACH;QACD;AAChB;AACA;;;QACgB,OAAOA,IAAI,CAACoC,IAAL,EAAP;MACH,CATD,CASE,OAAOrB,EAAP,EAAW;QACT,MAAM,IAAI9C,cAAJ,CACF8C,EAAE,CAACC,OAAH,IAAc,4BADZ,EAEFD,EAAE,CAAC3C,IAAH,IAAW,uBAFT,kCAIM2C,EAAE,CAACH,IAAH,IAAW,EAJjB;UAKEiB;QALF,GAAN;MAQH;IACJ;;EA5WuB,CAA5B;AA8WH,CArY8B,CAA/B;AAuYAxD,sBAAsB,CAACwE,IAAvB,GAA8B,sBAA9B;eAEexE,sB"}
|
|
1
|
+
{"version":3,"names":["BATCH_CREATE_MAX_FILES","checkOwnership","file","permission","context","own","identity","security","getIdentity","createdBy","id","NotAuthorizedError","getLocaleCode","i18n","WebinyError","locale","getContentLocale","code","filesContextCrudPlugin","ContextPlugin","pluginType","FilesStorageOperationsProviderPlugin","type","providerPlugin","plugins","byType","find","storageOperations","provide","fileManager","filePlugins","FilePlugin","files","getFile","checkBasePermissions","rwd","get","where","tenant","tenancy","getCurrentTenant","NotFoundError","createFile","input","mdbid","tags","Array","isArray","meta","private","createdOn","Date","toISOString","displayName","webinyVersion","WEBINY_VERSION","runLifecycleEvent","data","result","create","ex","message","updateFile","original","update","deleteFile","delete","createFilesInBatch","inputs","length","map","results","createBatch","listFiles","params","limit","search","types","ids","after","initialWhere","sort","initialSort","type_in","tag_in","tag","toLowerCase","id_in","list","listTags","name"],"sources":["files.crud.ts"],"sourcesContent":["/**\n * Package mdbid does not have types.\n */\n// @ts-ignore\nimport mdbid from \"mdbid\";\nimport { NotFoundError } from \"@webiny/handler-graphql\";\nimport { NotAuthorizedError } from \"@webiny/api-security\";\nimport {\n CreatedBy,\n File,\n FileManagerContext,\n FileManagerFilesStorageOperationsListParamsWhere,\n FileManagerFilesStorageOperationsTagsParamsWhere,\n FilePermission,\n FilesListOpts\n} from \"~/types\";\nimport checkBasePermissions from \"./utils/checkBasePermissions\";\nimport { ContextPlugin } from \"@webiny/api\";\nimport { FilePlugin } from \"~/plugins/definitions/FilePlugin\";\nimport { FilesStorageOperationsProviderPlugin } from \"~/plugins/definitions/FilesStorageOperationsProviderPlugin\";\nimport WebinyError from \"@webiny/error\";\nimport { runLifecycleEvent } from \"~/plugins/crud/utils/lifecycleEvents\";\n\nconst BATCH_CREATE_MAX_FILES = 20;\n\n/**\n * If permission is limited to \"own\" files only, check that current identity owns the file.\n */\nconst checkOwnership = (file: File, permission: FilePermission, context: FileManagerContext) => {\n if (permission?.own === true) {\n const identity = context.security.getIdentity();\n if (file.createdBy.id !== identity.id) {\n throw new NotAuthorizedError();\n }\n }\n};\n\nconst getLocaleCode = (context: FileManagerContext): string => {\n if (!context.i18n) {\n throw new WebinyError(\"Missing i18n on the FileManagerContext.\", \"MISSING_I18N\");\n }\n\n const locale = context.i18n.getContentLocale();\n if (!locale) {\n throw new WebinyError(\n \"Missing content locale on the FileManagerContext.\",\n \"MISSING_I18N_CONTENT_LOCALE\"\n );\n }\n\n if (!locale.code) {\n throw new WebinyError(\n \"Missing content locale code on the FileManagerContext.\",\n \"MISSING_I18N_CONTENT_LOCALE_CODE\"\n );\n }\n return locale.code;\n};\n\nconst filesContextCrudPlugin = new ContextPlugin<FileManagerContext>(async context => {\n const pluginType = FilesStorageOperationsProviderPlugin.type;\n\n const providerPlugin = context.plugins\n .byType<FilesStorageOperationsProviderPlugin>(pluginType)\n .find(() => true);\n\n if (!providerPlugin) {\n throw new WebinyError(`Missing \"${pluginType}\" plugin.`, \"PLUGIN_NOT_FOUND\", {\n type: pluginType\n });\n }\n\n const storageOperations = await providerPlugin.provide({\n context\n });\n\n if (!context.fileManager) {\n context.fileManager = {} as any;\n }\n\n const filePlugins = context.plugins.byType<FilePlugin>(FilePlugin.type);\n\n context.fileManager.files = {\n async getFile(id: string) {\n const permission = await checkBasePermissions(context, { rwd: \"r\" });\n\n const file = await storageOperations.get({\n where: {\n id,\n tenant: context.tenancy.getCurrentTenant().id,\n locale: getLocaleCode(context)\n }\n });\n\n if (!file) {\n throw new NotFoundError(`File with id \"${id}\" does not exists.`);\n }\n\n checkOwnership(file, permission, context);\n\n return file;\n },\n async createFile(input) {\n await checkBasePermissions(context, { rwd: \"w\" });\n const identity = context.security.getIdentity();\n const tenant = context.tenancy.getCurrentTenant();\n\n const id = mdbid();\n\n const file: File = {\n ...input,\n tags: Array.isArray(input.tags) ? input.tags : [],\n id,\n meta: {\n private: false,\n ...(input.meta || {})\n },\n tenant: tenant.id,\n createdOn: new Date().toISOString(),\n createdBy: {\n id: identity.id,\n displayName: identity.displayName,\n type: identity.type\n },\n locale: getLocaleCode(context),\n webinyVersion: context.WEBINY_VERSION\n };\n\n try {\n await runLifecycleEvent(\"beforeCreate\", {\n context,\n plugins: filePlugins,\n data: file\n });\n const result = await storageOperations.create({\n file\n });\n await runLifecycleEvent(\"afterCreate\", {\n context,\n plugins: filePlugins,\n data: file,\n file: result\n });\n return result;\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not create a file.\",\n ex.code || \"CREATE_FILE_ERROR\",\n {\n ...(ex.data || {}),\n file\n }\n );\n }\n },\n async updateFile(id, input) {\n const permission = await checkBasePermissions(context, { rwd: \"w\" });\n\n const original = await storageOperations.get({\n where: {\n id,\n tenant: context.tenancy.getCurrentTenant().id,\n locale: getLocaleCode(context)\n }\n });\n\n if (!original) {\n throw new NotFoundError(`File with id \"${id}\" does not exists.`);\n }\n\n checkOwnership(original, permission, context);\n\n const file: File = {\n ...original,\n ...input,\n tags: Array.isArray(input.tags)\n ? input.tags\n : Array.isArray(original.tags)\n ? original.tags\n : [],\n id: original.id,\n webinyVersion: context.WEBINY_VERSION\n };\n\n try {\n await runLifecycleEvent(\"beforeUpdate\", {\n context,\n plugins: filePlugins,\n original,\n data: file\n });\n const result = await storageOperations.update({\n original,\n file\n });\n await runLifecycleEvent(\"afterUpdate\", {\n context,\n plugins: filePlugins,\n original,\n data: file,\n file: result\n });\n return result;\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not update a file.\",\n ex.code || \"UPDATE_FILE_ERROR\",\n {\n ...(ex.data || {}),\n original,\n file\n }\n );\n }\n },\n async deleteFile(id) {\n const permission = await checkBasePermissions(context, { rwd: \"d\" });\n\n const file = await storageOperations.get({\n where: {\n id,\n tenant: context.tenancy.getCurrentTenant().id,\n locale: getLocaleCode(context)\n }\n });\n if (!file) {\n throw new NotFoundError(`File with id \"${id}\" does not exists.`);\n }\n\n checkOwnership(file, permission, context);\n\n try {\n await runLifecycleEvent(\"beforeDelete\", {\n context,\n plugins: filePlugins,\n file\n });\n await storageOperations.delete({\n file\n });\n await runLifecycleEvent(\"afterDelete\", {\n context,\n plugins: filePlugins,\n file\n });\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not delete a file.\",\n ex.code || \"DELETE_FILE_ERROR\",\n {\n ...(ex.data || {}),\n id,\n file\n }\n );\n }\n\n return true;\n },\n async createFilesInBatch(inputs) {\n if (!Array.isArray(inputs)) {\n throw new WebinyError(`\"data\" must be an array.`, \"CREATE_FILES_NON_ARRAY\");\n }\n\n if (inputs.length === 0) {\n throw new WebinyError(\n `\"data\" argument must contain at least one file.`,\n \"CREATE_FILES_MIN_FILES\"\n );\n }\n\n if (inputs.length > BATCH_CREATE_MAX_FILES) {\n throw new WebinyError(\n `\"data\" argument must not contain more than ${BATCH_CREATE_MAX_FILES} files.`,\n \"CREATE_FILES_MAX_FILES\"\n );\n }\n\n await checkBasePermissions(context, { rwd: \"w\" });\n\n const identity = context.security.getIdentity();\n const tenant = context.tenancy.getCurrentTenant();\n const createdBy: CreatedBy = {\n id: identity.id,\n displayName: identity.displayName,\n type: identity.type\n };\n\n const files: File[] = inputs.map(input => {\n return {\n ...input,\n tags: Array.isArray(input.tags) ? input.tags : [],\n meta: {\n private: false,\n ...(input.meta || {})\n },\n id: mdbid(),\n tenant: tenant.id,\n createdOn: new Date().toISOString(),\n createdBy,\n locale: getLocaleCode(context),\n webinyVersion: context.WEBINY_VERSION\n };\n });\n\n try {\n await runLifecycleEvent(\"beforeBatchCreate\", {\n context,\n plugins: filePlugins,\n data: files\n });\n const results = await storageOperations.createBatch({\n files\n });\n await runLifecycleEvent(\"afterBatchCreate\", {\n context,\n plugins: filePlugins,\n data: files,\n files: results\n });\n return results;\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not create a batch of files.\",\n ex.code || \"CREATE_FILES_ERROR\",\n {\n ...(ex.data || {}),\n files\n }\n );\n }\n },\n async listFiles(params: FilesListOpts = {}) {\n const permission = await checkBasePermissions(context, { rwd: \"r\" });\n\n const {\n limit = 40,\n search = \"\",\n types = [],\n tags = [],\n ids = [],\n after = null,\n where: initialWhere,\n sort: initialSort\n } = params;\n\n const where: FileManagerFilesStorageOperationsListParamsWhere = {\n ...initialWhere,\n private: false,\n locale: getLocaleCode(context),\n tenant: context.tenancy.getCurrentTenant().id\n };\n /**\n * Always override the createdBy received from the user, if any.\n */\n if (permission.own === true) {\n const identity = context.security.getIdentity();\n where.createdBy = identity.id;\n }\n /**\n * We need to map the old GraphQL definition to the new one.\n * That GQL definition is marked as deprecated.\n */\n /**\n * To have standardized where objects across the applications, we transform the types into type_in.\n */\n if (Array.isArray(types) && types.length > 0 && !where.type_in) {\n where.type_in = types;\n }\n /**\n * We are assigning search to tag and name search.\n * This should be treated as OR condition in the storage operations.\n */\n if (search && !where.search) {\n where.search = search;\n }\n /**\n * Same as on types/type_in.\n */\n if (Array.isArray(tags) && tags.length > 0 && !where.tag_in) {\n where.tag_in = tags.map(tag => tag.toLowerCase());\n }\n /**\n * Same as on types/type_in.\n */\n if (Array.isArray(ids) && ids.length > 0 && !where.id_in) {\n where.id_in = ids;\n }\n\n const sort =\n Array.isArray(initialSort) && initialSort.length > 0 ? initialSort : [\"id_DESC\"];\n try {\n return await storageOperations.list({\n where,\n after,\n limit,\n sort\n });\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not list files by given parameters.\",\n ex.code || \"FILE_TAG_SEARCH_ERROR\",\n {\n ...(ex.data || {}),\n where,\n after,\n limit,\n sort\n }\n );\n }\n },\n async listTags({ where: initialWhere, after, limit }) {\n await checkBasePermissions(context);\n\n const where: FileManagerFilesStorageOperationsTagsParamsWhere = {\n ...initialWhere,\n tenant: context.tenancy.getCurrentTenant().id,\n locale: getLocaleCode(context)\n };\n\n const params = {\n where,\n limit: limit || 100000,\n after\n };\n\n try {\n const [tags] = await storageOperations.tags(params);\n if (Array.isArray(tags) === false) {\n return [];\n }\n /**\n * just to keep it standardized, sort by the tag ASC\n */\n return tags.sort();\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not search for tags.\",\n ex.code || \"FILE_TAG_SEARCH_ERROR\",\n {\n ...(ex.data || {}),\n params\n }\n );\n }\n }\n };\n});\n\nfilesContextCrudPlugin.name = \"FileManagerFilesCrud\";\n\nexport default filesContextCrudPlugin;\n"],"mappings":";;;;;;;;;;;AAIA;;AACA;;AACA;;AAUA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;;;AAEA,MAAMA,sBAAsB,GAAG,EAA/B;AAEA;AACA;AACA;;AACA,MAAMC,cAAc,GAAG,CAACC,IAAD,EAAaC,UAAb,EAAyCC,OAAzC,KAAyE;EAC5F,IAAI,CAAAD,UAAU,SAAV,IAAAA,UAAU,WAAV,YAAAA,UAAU,CAAEE,GAAZ,MAAoB,IAAxB,EAA8B;IAC1B,MAAMC,QAAQ,GAAGF,OAA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ATD,CASE,OAAOrB,EAAP,EAAW;QACT,MAAM,IAAI9C,cAAJ,CACF8C,EAAE,CAACC,OAAH,IAAc,4BADZ,EAEFD,EAAE,CAAC3C,IAAH,IAAW,uBAFT,kCAIM2C,EAAE,CAACH,IAAH,IAAW,EAJjB;UAKEiB;QALF,GAAN;MAQH;IACJ;;EA5WuB,CAA5B;AA8WH,CArY8B,CAA/B;AAuYAxD,sBAAsB,CAACwE,IAAvB,GAA8B,sBAA9B;eAEexE,sB"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { FileManagerContext } from "../../types";
|
|
2
|
-
import { ContextPlugin } from "@webiny/
|
|
2
|
+
import { ContextPlugin } from "@webiny/api";
|
|
3
3
|
export declare const SETTINGS_KEY = "file-manager";
|
|
4
4
|
declare const settingsCrudContextPlugin: ContextPlugin<FileManagerContext>;
|
|
5
5
|
export default settingsCrudContextPlugin;
|
|
@@ -17,7 +17,7 @@ var _SettingsStorageOperationsProviderPlugin = require("../definitions/SettingsS
|
|
|
17
17
|
|
|
18
18
|
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
19
19
|
|
|
20
|
-
var
|
|
20
|
+
var _api = require("@webiny/api");
|
|
21
21
|
|
|
22
22
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
23
23
|
|
|
@@ -59,7 +59,7 @@ const UpdateDataModel = (0, _fields.withFields)({
|
|
|
59
59
|
return value;
|
|
60
60
|
})((0, _fields.string)())
|
|
61
61
|
})();
|
|
62
|
-
const settingsCrudContextPlugin = new
|
|
62
|
+
const settingsCrudContextPlugin = new _api.ContextPlugin(async context => {
|
|
63
63
|
const pluginType = _SettingsStorageOperationsProviderPlugin.SettingsStorageOperationsProviderPlugin.type;
|
|
64
64
|
const providerPlugin = context.plugins.byType(pluginType).find(() => true);
|
|
65
65
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["SETTINGS_KEY","CreateDataModel","withFields","uploadMinFileSize","number","value","validation","create","uploadMaxFileSize","srcPrefix","onSet","endsWith","string","UpdateDataModel","settingsCrudContextPlugin","ContextPlugin","context","pluginType","SettingsStorageOperationsProviderPlugin","type","providerPlugin","plugins","byType","find","WebinyError","storageOperations","provide","fileManager","settings","getSettings","get","createSettings","data","populate","validate","settingsData","toJSON","updateSettings","updatedValue","existingSettings","updatedSettings","onlyDirty","update","original","deleteSettings","delete","name"],"sources":["settings.crud.ts"],"sourcesContent":["/**\n * Package @commodo/fields does not have types.\n */\n// @ts-ignore\nimport { withFields, string, number, onSet } from \"@commodo/fields\";\nimport { validation } from \"@webiny/validation\";\nimport { FileManagerContext, FileManagerSettings } from \"~/types\";\nimport { SettingsStorageOperationsProviderPlugin } from \"~/plugins/definitions/SettingsStorageOperationsProviderPlugin\";\nimport WebinyError from \"@webiny/error\";\nimport { ContextPlugin } from \"@webiny/
|
|
1
|
+
{"version":3,"names":["SETTINGS_KEY","CreateDataModel","withFields","uploadMinFileSize","number","value","validation","create","uploadMaxFileSize","srcPrefix","onSet","endsWith","string","UpdateDataModel","settingsCrudContextPlugin","ContextPlugin","context","pluginType","SettingsStorageOperationsProviderPlugin","type","providerPlugin","plugins","byType","find","WebinyError","storageOperations","provide","fileManager","settings","getSettings","get","createSettings","data","populate","validate","settingsData","toJSON","updateSettings","updatedValue","existingSettings","updatedSettings","onlyDirty","update","original","deleteSettings","delete","name"],"sources":["settings.crud.ts"],"sourcesContent":["/**\n * Package @commodo/fields does not have types.\n */\n// @ts-ignore\nimport { withFields, string, number, onSet } from \"@commodo/fields\";\nimport { validation } from \"@webiny/validation\";\nimport { FileManagerContext, FileManagerSettings } from \"~/types\";\nimport { SettingsStorageOperationsProviderPlugin } from \"~/plugins/definitions/SettingsStorageOperationsProviderPlugin\";\nimport WebinyError from \"@webiny/error\";\nimport { ContextPlugin } from \"@webiny/api\";\n\n// TODO @ts-refactor verify that this is not used and remove it\nexport const SETTINGS_KEY = \"file-manager\";\n\nconst CreateDataModel = withFields({\n uploadMinFileSize: number({ value: 0, validation: validation.create(\"gte:0\") }),\n uploadMaxFileSize: number({ value: 26214401 }),\n srcPrefix: onSet((value?: string) => {\n // Make sure srcPrefix always ends with forward slash.\n if (typeof value === \"string\") {\n return value.endsWith(\"/\") ? value : value + \"/\";\n }\n return value;\n })(string({ value: \"/files/\" }))\n})();\n\nconst UpdateDataModel = withFields({\n uploadMinFileSize: number({\n validation: validation.create(\"gte:0\")\n }),\n uploadMaxFileSize: number(),\n srcPrefix: onSet((value?: string) => {\n // Make sure srcPrefix always ends with forward slash.\n if (typeof value === \"string\") {\n return value.endsWith(\"/\") ? value : value + \"/\";\n }\n return value;\n })(string())\n})();\n\nconst settingsCrudContextPlugin = new ContextPlugin<FileManagerContext>(async context => {\n const pluginType = SettingsStorageOperationsProviderPlugin.type;\n\n const providerPlugin = context.plugins\n .byType<SettingsStorageOperationsProviderPlugin>(pluginType)\n .find(() => true);\n\n if (!providerPlugin) {\n throw new WebinyError(`Missing \"${pluginType}\" plugin.`, \"PLUGIN_NOT_FOUND\", {\n type: pluginType\n });\n }\n\n const storageOperations = await providerPlugin.provide({\n context\n });\n\n if (!context.fileManager) {\n context.fileManager = {} as any;\n }\n\n context.fileManager.settings = {\n async getSettings() {\n return storageOperations.get();\n },\n async createSettings(data) {\n const settings = new CreateDataModel().populate(data);\n await settings.validate();\n\n const settingsData: FileManagerSettings = await settings.toJSON();\n\n return storageOperations.create({\n data: settingsData\n });\n },\n async updateSettings(data) {\n const updatedValue = new UpdateDataModel().populate(data);\n await updatedValue.validate();\n\n const existingSettings = (await storageOperations.get()) as FileManagerSettings;\n\n const updatedSettings: Partial<FileManagerSettings> = await updatedValue.toJSON({\n onlyDirty: true\n });\n\n return storageOperations.update({\n original: existingSettings,\n data: {\n ...existingSettings,\n ...updatedSettings\n }\n });\n },\n async deleteSettings() {\n await storageOperations.delete();\n\n return true;\n }\n };\n});\n\nsettingsCrudContextPlugin.name = \"FileMangerSettingsCrud\";\n\nexport default settingsCrudContextPlugin;\n"],"mappings":";;;;;;;;;;;AAIA;;AACA;;AAEA;;AACA;;AACA;;;;;;AAEA;AACO,MAAMA,YAAY,GAAG,cAArB;;AAEP,MAAMC,eAAe,GAAG,IAAAC,kBAAA,EAAW;EAC/BC,iBAAiB,EAAE,IAAAC,cAAA,EAAO;IAAEC,KAAK,EAAE,CAAT;IAAYC,UAAU,EAAEA,sBAAA,CAAWC,MAAX,CAAkB,OAAlB;EAAxB,CAAP,CADY;EAE/BC,iBAAiB,EAAE,IAAAJ,cAAA,EAAO;IAAEC,KAAK,EAAE;EAAT,CAAP,CAFY;EAG/BI,SAAS,EAAE,IAAAC,aAAA,EAAOL,KAAD,IAAoB;IACjC;IACA,IAAI,OAAOA,KAAP,KAAiB,QAArB,EAA+B;MAC3B,OAAOA,KAAK,CAACM,QAAN,CAAe,GAAf,IAAsBN,KAAtB,GAA8BA,KAAK,GAAG,GAA7C;IACH;;IACD,OAAOA,KAAP;EACH,CANU,EAMR,IAAAO,cAAA,EAAO;IAAEP,KAAK,EAAE;EAAT,CAAP,CANQ;AAHoB,CAAX,GAAxB;AAYA,MAAMQ,eAAe,GAAG,IAAAX,kBAAA,EAAW;EAC/BC,iBAAiB,EAAE,IAAAC,cAAA,EAAO;IACtBE,UAAU,EAAEA,sBAAA,CAAWC,MAAX,CAAkB,OAAlB;EADU,CAAP,CADY;EAI/BC,iBAAiB,EAAE,IAAAJ,cAAA,GAJY;EAK/BK,SAAS,EAAE,IAAAC,aAAA,EAAOL,KAAD,IAAoB;IACjC;IACA,IAAI,OAAOA,KAAP,KAAiB,QAArB,EAA+B;MAC3B,OAAOA,KAAK,CAACM,QAAN,CAAe,GAAf,IAAsBN,KAAtB,GAA8BA,KAAK,GAAG,GAA7C;IACH;;IACD,OAAOA,KAAP;EACH,CANU,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MK,gBAAgB,GAAI,MAAMd,iBAAiB,CAACK,GAAlB,EAAhC;MAEA,MAAMU,eAA6C,GAAG,MAAMF,YAAY,CAACF,MAAb,CAAoB;QAC5EK,SAAS,EAAE;MADiE,CAApB,CAA5D;MAIA,OAAOhB,iBAAiB,CAACiB,MAAlB,CAAyB;QAC5BC,QAAQ,EAAEJ,gBADkB;QAE5BP,IAAI,kCACGO,gBADH,GAEGC,eAFH;MAFwB,CAAzB,CAAP;IAOH,CA/B0B;;IAgC3B,MAAMI,cAAN,GAAuB;MACnB,MAAMnB,iBAAiB,CAACoB,MAAlB,EAAN;MAEA,OAAO,IAAP;IACH;;EApC0B,CAA/B;AAsCH,CA3DiC,CAAlC;AA6DA/B,yBAAyB,CAACgC,IAA1B,GAAiC,wBAAjC;eAEehC,yB"}
|
|
@@ -15,7 +15,7 @@ var _apiUpgrade = require("@webiny/api-upgrade");
|
|
|
15
15
|
|
|
16
16
|
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
17
17
|
|
|
18
|
-
var
|
|
18
|
+
var _api = require("@webiny/api");
|
|
19
19
|
|
|
20
20
|
var _utils = require("../../utils");
|
|
21
21
|
|
|
@@ -27,7 +27,7 @@ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (O
|
|
|
27
27
|
|
|
28
28
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
29
29
|
|
|
30
|
-
const systemCrudContextPlugin = new
|
|
30
|
+
const systemCrudContextPlugin = new _api.ContextPlugin(async context => {
|
|
31
31
|
const pluginType = _SystemStorageOperationsProviderPlugin.SystemStorageOperationsProviderPlugin.type;
|
|
32
32
|
const providerPlugin = context.plugins.byType(pluginType).find(() => true);
|
|
33
33
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["systemCrudContextPlugin","ContextPlugin","context","pluginType","SystemStorageOperationsProviderPlugin","type","providerPlugin","plugins","byType","find","WebinyError","storageOperations","provide","fileManager","getTenantId","tenancy","getCurrentTenant","id","system","getVersion","get","version","setVersion","data","tenant","update","original","ex","create","install","srcPrefix","identity","security","getIdentity","NotAuthorizedError","installationPlugins","InstallationPlugin","executeCallbacks","settings","createSettings","WEBINY_VERSION","upgrade","upgradePlugins","filter","pl","app","plugin","getApplicablePlugin","deployedVersion","installedAppVersion","upgradeToVersion","apply","name"],"sources":["system.crud.ts"],"sourcesContent":["import { NotAuthorizedError } from \"@webiny/api-security\";\nimport { getApplicablePlugin } from \"@webiny/api-upgrade\";\nimport { FileManagerContext, FileManagerSettings, FileManagerSystem } from \"~/types\";\nimport { UpgradePlugin } from \"@webiny/api-upgrade/types\";\nimport WebinyError from \"@webiny/error\";\nimport { ContextPlugin } from \"@webiny/
|
|
1
|
+
{"version":3,"names":["systemCrudContextPlugin","ContextPlugin","context","pluginType","SystemStorageOperationsProviderPlugin","type","providerPlugin","plugins","byType","find","WebinyError","storageOperations","provide","fileManager","getTenantId","tenancy","getCurrentTenant","id","system","getVersion","get","version","setVersion","data","tenant","update","original","ex","create","install","srcPrefix","identity","security","getIdentity","NotAuthorizedError","installationPlugins","InstallationPlugin","executeCallbacks","settings","createSettings","WEBINY_VERSION","upgrade","upgradePlugins","filter","pl","app","plugin","getApplicablePlugin","deployedVersion","installedAppVersion","upgradeToVersion","apply","name"],"sources":["system.crud.ts"],"sourcesContent":["import { NotAuthorizedError } from \"@webiny/api-security\";\nimport { getApplicablePlugin } from \"@webiny/api-upgrade\";\nimport { FileManagerContext, FileManagerSettings, FileManagerSystem } from \"~/types\";\nimport { UpgradePlugin } from \"@webiny/api-upgrade/types\";\nimport WebinyError from \"@webiny/error\";\nimport { ContextPlugin } from \"@webiny/api\";\nimport { executeCallbacks } from \"~/utils\";\nimport { InstallationPlugin } from \"~/plugins/definitions/InstallationPlugin\";\nimport { SystemStorageOperationsProviderPlugin } from \"~/plugins/definitions/SystemStorageOperationsProviderPlugin\";\n\nconst systemCrudContextPlugin = new ContextPlugin<FileManagerContext>(async context => {\n const pluginType = SystemStorageOperationsProviderPlugin.type;\n const providerPlugin = context.plugins\n .byType<SystemStorageOperationsProviderPlugin>(pluginType)\n .find(() => true);\n\n if (!providerPlugin) {\n throw new WebinyError(`Missing \"${pluginType}\" plugin.`, \"PLUGIN_NOT_FOUND\", {\n type: pluginType\n });\n }\n\n const storageOperations = await providerPlugin.provide({\n context\n });\n\n if (!context.fileManager) {\n context.fileManager = {} as any;\n }\n\n const getTenantId = (): string => {\n return context.tenancy.getCurrentTenant().id;\n };\n\n context.fileManager.system = {\n async getVersion() {\n const system = await storageOperations.get();\n\n return system ? system.version : null;\n },\n async setVersion(version: string) {\n const system = await storageOperations.get();\n\n if (system) {\n const data: FileManagerSystem = {\n ...system,\n tenant: system.tenant || getTenantId(),\n version\n };\n try {\n await storageOperations.update({\n original: system,\n data\n });\n return;\n } catch (ex) {\n throw new WebinyError(\n \"Could not update the system data.\",\n \"SYSTEM_UPDATE_ERROR\",\n {\n data\n }\n );\n }\n }\n\n const data: FileManagerSystem = {\n version,\n tenant: getTenantId()\n };\n try {\n await storageOperations.create({\n data\n });\n return;\n } catch (ex) {\n throw new WebinyError(\"Could not create the system data.\", \"SYSTEM_CREATE_ERROR\", {\n data\n });\n }\n },\n async install({ srcPrefix }) {\n const identity = context.security.getIdentity();\n if (!identity) {\n throw new NotAuthorizedError();\n }\n const { fileManager } = context;\n const version = await fileManager.system.getVersion();\n\n if (version) {\n throw new WebinyError(\n \"File Manager is already installed.\",\n \"FILES_INSTALL_ABORTED\"\n );\n }\n\n const data: Partial<FileManagerSettings> = {};\n\n if (srcPrefix) {\n data.srcPrefix = srcPrefix;\n }\n\n const installationPlugins = context.plugins.byType<InstallationPlugin>(\n InstallationPlugin.type\n );\n\n await executeCallbacks<InstallationPlugin[\"beforeInstall\"]>(\n installationPlugins,\n \"beforeInstall\",\n {\n context\n }\n );\n\n await fileManager.settings.createSettings(data);\n\n await fileManager.system.setVersion(context.WEBINY_VERSION);\n\n await executeCallbacks<InstallationPlugin[\"afterInstall\"]>(\n installationPlugins,\n \"afterInstall\",\n {\n context\n }\n );\n\n return true;\n },\n async upgrade(version) {\n const identity = context.security.getIdentity();\n if (!identity) {\n throw new NotAuthorizedError();\n }\n\n const upgradePlugins = context.plugins\n .byType<UpgradePlugin>(\"api-upgrade\")\n .filter(pl => pl.app === \"file-manager\");\n\n const plugin = getApplicablePlugin({\n deployedVersion: context.WEBINY_VERSION,\n installedAppVersion: await this.getVersion(),\n upgradePlugins,\n upgradeToVersion: version\n });\n\n await plugin.apply(context);\n\n // Store new app version\n await context.fileManager.system.setVersion(version);\n\n return true;\n }\n };\n});\n\nsystemCrudContextPlugin.name = \"FileManagerSystemCrud\";\n\nexport default systemCrudContextPlugin;\n"],"mappings":";;;;;;;;;;;AAAA;;AACA;;AAGA;;AACA;;AACA;;AACA;;AACA;;;;;;AAEA,MAAMA,uBAAuB,GAAG,IAAIC,kBAAJ,CAAsC,MAAMC,OAAN,IAAiB;EACnF,MAAMC,UAAU,GAAGC,4EAAA,CAAsCC,IAAzD;EACA,MAAMC,cAAc,GAAGJ,OAAO,CAACK,OAAR,CAClBC,MADkB,CAC4BL,UAD5B,EAElBM,IAFkB,CAEb,MAAM,IAFO,CAAvB;;EAIA,IAAI,CAACH,cAAL,EAAqB;IACjB,MAAM,IAAII,cAAJ,CAAiB,YAAWP,UAAW,WAAvC,EAAmD,kBAAnD,EAAuE;MACzEE,IAAI,EAAEF;IADmE,CAAvE,CAAN;EAGH;;EAED,MAAMQ,iBAAiB,GAAG,MAAML,cAAc,CAACM,OAAf,CAAuB;IACnDV;EADmD,CAAvB,CAAhC;;EAIA,IAAI,CAACA,OAAO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cAFN,CAAvB;MAIA,MAAMC,MAAM,GAAG,IAAAC,+BAAA,EAAoB;QAC/BC,eAAe,EAAE9C,OAAO,CAACsC,cADM;QAE/BS,mBAAmB,EAAE,MAAM,KAAK9B,UAAL,EAFI;QAG/BuB,cAH+B;QAI/BQ,gBAAgB,EAAE7B;MAJa,CAApB,CAAf;MAOA,MAAMyB,MAAM,CAACK,KAAP,CAAajD,OAAb,CAAN,CAjBmB,CAmBnB;;MACA,MAAMA,OAAO,CAACW,WAAR,CAAoBK,MAApB,CAA2BI,UAA3B,CAAsCD,OAAtC,CAAN;MAEA,OAAO,IAAP;IACH;;EArHwB,CAA7B;AAuHH,CA/I+B,CAAhC;AAiJArB,uBAAuB,CAACoD,IAAxB,GAA+B,uBAA/B;eAEepD,uB"}
|
package/plugins/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const _default: () => (import("@webiny/handler-graphql/types").GraphQLSchemaPlugin<import("../types").FileManagerContext> | import("./definitions/FilePlugin").FilePlugin[] | import("@webiny/
|
|
1
|
+
declare const _default: () => (import("@webiny/handler-graphql/types").GraphQLSchemaPlugin<import("../types").FileManagerContext> | import("./definitions/FilePlugin").FilePlugin[] | import("@webiny/api").ContextPlugin<import("../types").FileManagerContext>)[];
|
|
2
2
|
export default _default;
|
package/plugins/storage/index.js
CHANGED
|
@@ -5,11 +5,11 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
|
|
8
|
-
var
|
|
8
|
+
var _api = require("@webiny/api");
|
|
9
9
|
|
|
10
10
|
var _FileStorage = require("./FileStorage");
|
|
11
11
|
|
|
12
|
-
const fileStorageContextPlugin = new
|
|
12
|
+
const fileStorageContextPlugin = new _api.ContextPlugin(async context => {
|
|
13
13
|
if (!context.fileManager) {
|
|
14
14
|
/**
|
|
15
15
|
* We need to define the fileManager initial property as empty object.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["fileStorageContextPlugin","ContextPlugin","context","fileManager","storage","FileStorage"],"sources":["index.ts"],"sourcesContent":["import { FileManagerContext } from \"~/types\";\nimport { ContextPlugin } from \"@webiny/
|
|
1
|
+
{"version":3,"names":["fileStorageContextPlugin","ContextPlugin","context","fileManager","storage","FileStorage"],"sources":["index.ts"],"sourcesContent":["import { FileManagerContext } from \"~/types\";\nimport { ContextPlugin } from \"@webiny/api\";\nimport { FileStorage } from \"./FileStorage\";\n\nconst fileStorageContextPlugin = new ContextPlugin<FileManagerContext>(async context => {\n if (!context.fileManager) {\n /**\n * We need to define the fileManager initial property as empty object.\n * When casting as FileManagerContext, typescript is complaining.\n */\n context.fileManager = {} as any;\n }\n context.fileManager.storage = new FileStorage({\n context\n });\n});\n\nexport default fileStorageContextPlugin;\n"],"mappings":";;;;;;;AACA;;AACA;;AAEA,MAAMA,wBAAwB,GAAG,IAAIC,kBAAJ,CAAsC,MAAMC,OAAN,IAAiB;EACpF,IAAI,CAACA,OAAO,CAACC,WAAb,EAA0B;IACtB;AACR;AACA;AACA;IACQD,OAAO,CAACC,WAAR,GAAsB,EAAtB;EACH;;EACDD,OAAO,CAACC,WAAR,CAAoBC,OAApB,GAA8B,IAAIC,wBAAJ,CAAgB;IAC1CH;EAD0C,CAAhB,CAA9B;AAGH,CAXgC,CAAjC;eAaeF,wB"}
|
package/types.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { I18NContext } from "@webiny/api-i18n/types";
|
|
|
2
2
|
import { FileStorage } from "./plugins/storage/FileStorage";
|
|
3
3
|
import { TenancyContext } from "@webiny/api-tenancy/types";
|
|
4
4
|
import { SecurityContext, SecurityPermission } from "@webiny/api-security/types";
|
|
5
|
-
import { Context } from "@webiny/
|
|
5
|
+
import { Context } from "@webiny/api/types";
|
|
6
6
|
export interface FileManagerContext extends Context, SecurityContext, TenancyContext, I18NContext {
|
|
7
7
|
fileManager: {
|
|
8
8
|
files: FilesCRUD;
|
package/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import { I18NContext } from \"@webiny/api-i18n/types\";\nimport { FileStorage } from \"./plugins/storage/FileStorage\";\nimport { TenancyContext } from \"@webiny/api-tenancy/types\";\nimport { SecurityContext, SecurityPermission } from \"@webiny/api-security/types\";\nimport { Context } from \"@webiny/handler/types\";\n\nexport interface FileManagerContext extends Context, SecurityContext, TenancyContext, I18NContext {\n fileManager: {\n files: FilesCRUD;\n settings: SettingsCRUD;\n storage: FileStorage;\n system: SystemCRUD;\n };\n}\n\nexport interface FilePermission extends SecurityPermission {\n name: \"fm.file\";\n rwd?: string;\n own?: boolean;\n}\n\nexport interface File {\n id: string;\n key: string;\n size: number;\n type: string;\n name: string;\n meta: Record<string, any>;\n tags: string[];\n createdOn: string;\n createdBy: CreatedBy;\n /**\n * Added with new storage operations refactoring.\n */\n tenant: string;\n locale: string;\n webinyVersion: string;\n /**\n * User can add new fields to the File object so we must allow it in the types.\n */\n [key: string]: any;\n}\n\nexport interface CreatedBy {\n id: string;\n displayName: string | null;\n type: string;\n}\n\nexport interface FileInput {\n key: string;\n name: string;\n size: number;\n type: string;\n meta: Record<string, any>;\n tags: string[];\n}\n\nexport interface FileListWhereParams {\n search?: string;\n type?: string;\n type_in?: string[];\n tag?: string;\n tag_in?: string[];\n tag_and_in?: string[];\n id_in?: string[];\n id?: string;\n}\nexport interface FilesListOpts {\n search?: string;\n types?: string[];\n tags?: string[];\n ids?: string[];\n limit?: number;\n after?: string;\n where?: FileListWhereParams;\n sort?: string[];\n}\n\nexport interface FileListMeta {\n cursor: string | null;\n totalCount: number;\n hasMoreItems: boolean;\n}\n\ninterface FilesCrudListTagsWhere {\n tag?: string;\n tag_contains?: string;\n tag_in?: string[];\n tag_not_startsWith?: string;\n tag_startsWith?: string;\n}\ninterface FilesCrudListTagsParams {\n where?: FilesCrudListTagsWhere;\n limit?: number;\n after?: string;\n}\n\nexport interface FilesCRUD {\n getFile(id: string): Promise<File>;\n listFiles(opts?: FilesListOpts): Promise<[File[], FileListMeta]>;\n listTags(params: FilesCrudListTagsParams): Promise<string[]>;\n createFile(data: FileInput): Promise<File>;\n updateFile(id: string, data: Partial<FileInput>): Promise<File>;\n deleteFile(id: string): Promise<boolean>;\n createFilesInBatch(data: FileInput[]): Promise<File[]>;\n}\n\nexport interface SystemCRUD {\n getVersion(): Promise<string | null>;\n setVersion(version: string): Promise<void>;\n install(args: { srcPrefix: string }): Promise<boolean>;\n upgrade(version: string, data?: Record<string, any>): Promise<boolean>;\n}\n\nexport interface FileManagerSettings {\n key: string;\n uploadMinFileSize: number;\n uploadMaxFileSize: number;\n srcPrefix: string;\n}\n\nexport interface FileManagerSystem {\n version: string;\n tenant: string;\n}\n\nexport type SettingsCRUD = {\n getSettings(): Promise<FileManagerSettings | null>;\n createSettings(data?: Partial<FileManagerSettings>): Promise<FileManagerSettings>;\n updateSettings(data: Partial<FileManagerSettings>): Promise<FileManagerSettings>;\n deleteSettings(): Promise<boolean>;\n};\n/********\n * Storage operations\n *******/\n\n/**\n * @category StorageOperations\n * @category SystemStorageOperations\n * @category SystemStorageOperationsParams\n */\nexport interface FileManagerSystemStorageOperationsUpdateParams {\n /**\n * The system data to be updated.\n */\n original: FileManagerSystem;\n /**\n * The system data with the updated fields.\n */\n data: FileManagerSystem;\n}\n/**\n * @category StorageOperations\n * @category SystemStorageOperations\n * @category SystemStorageOperationsParams\n */\nexport interface FileManagerSystemStorageOperationsCreateParams {\n /**\n * The system fields.\n */\n data: FileManagerSystem;\n}\n\n/**\n * @category StorageOperations\n * @category SystemStorageOperations\n */\nexport interface FileManagerSystemStorageOperations {\n /**\n * Get the FileManager system data.\n */\n get: () => Promise<FileManagerSystem | null>;\n /**\n * Update the FileManager system data..\n */\n update: (params: FileManagerSystemStorageOperationsUpdateParams) => Promise<FileManagerSystem>;\n /**\n * Create the FileManagerSystemData\n */\n create: (params: FileManagerSystemStorageOperationsCreateParams) => Promise<FileManagerSystem>;\n}\n\n/**\n * @category StorageOperations\n * @category SettingsStorageOperations\n * @category SettingsStorageOperationsParams\n */\nexport interface FileManagerSettingsStorageOperationsUpdateParams {\n /**\n * Original settings to be updated.\n */\n original: FileManagerSettings;\n /**\n * The settings with the updated fields.\n */\n data: FileManagerSettings;\n}\n/**\n * @category StorageOperations\n * @category SettingsStorageOperations\n * @category SettingsStorageOperationsParams\n */\nexport interface FileManagerSettingsStorageOperationsCreateParams {\n /**\n * The settings fields.\n */\n data: FileManagerSettings;\n}\n\n/**\n * @category StorageOperations\n * @category SettingsStorageOperations\n */\nexport interface FileManagerSettingsStorageOperations {\n /**\n * Get the FileManager system data.\n */\n get: () => Promise<FileManagerSettings | null>;\n /**\n * Create the FileManagerSettingsData\n */\n create: (\n params: FileManagerSettingsStorageOperationsCreateParams\n ) => Promise<FileManagerSettings>;\n /**\n * Update the FileManager system data..\n */\n update: (\n params: FileManagerSettingsStorageOperationsUpdateParams\n ) => Promise<FileManagerSettings>;\n /**\n * Delete the existing settings.\n */\n delete: () => Promise<void>;\n}\n\n/**\n * @category StorageOperations\n * @category FilesStorageOperations\n * @category FilesStorageOperationsParams\n */\nexport interface FileManagerFilesStorageOperationsGetParams {\n where: {\n id: string;\n tenant: string;\n locale: string;\n };\n}\n/**\n * @category StorageOperations\n * @category FilesStorageOperations\n * @category FilesStorageOperationsParams\n */\nexport interface FileManagerFilesStorageOperationsCreateParams {\n file: File;\n}\n/**\n * @category StorageOperations\n * @category FilesStorageOperations\n * @category FilesStorageOperationsParams\n */\nexport interface FileManagerFilesStorageOperationsUpdateParams {\n original: File;\n file: File;\n}\n\n/**\n * @category StorageOperations\n * @category FilesStorageOperations\n * @category FilesStorageOperationsParams\n */\nexport interface FileManagerFilesStorageOperationsDeleteParams {\n file: File;\n}\n/**\n * @category StorageOperations\n * @category FilesStorageOperations\n * @category FilesStorageOperationsParams\n */\nexport interface FileManagerFilesStorageOperationsCreateBatchParams {\n files: File[];\n}\n/**\n * @category StorageOperations\n * @category FilesStorageOperations\n * @category FilesStorageOperationsParams\n */\nexport interface FileManagerFilesStorageOperationsListParamsWhere {\n id?: string;\n id_in?: string[];\n name?: string;\n name_contains?: string;\n tag?: string;\n tag_contains?: string;\n tag_in?: string[];\n createdBy?: string;\n locale: string;\n tenant: string;\n private?: boolean;\n type?: string;\n type_in?: string[];\n search?: string;\n}\n/**\n * @category StorageOperations\n * @category FilesStorageOperations\n * @category FilesStorageOperationsParams\n */\nexport interface FileManagerFilesStorageOperationsListParams {\n where: FileManagerFilesStorageOperationsListParamsWhere;\n sort: string[];\n limit: number;\n after: string | null;\n}\n\n/**\n * @category StorageOperations\n * @category FilesStorageOperations\n * @category FilesStorageOperationsParams\n */\nexport interface FileManagerFilesStorageOperationsListResponseMeta {\n hasMoreItems: boolean;\n totalCount: number;\n cursor: string | null;\n}\nexport type FileManagerFilesStorageOperationsListResponse = [\n File[],\n FileManagerFilesStorageOperationsListResponseMeta\n];\n\nexport type FileManagerFilesStorageOperationsTagsResponse = [\n string[],\n FileManagerFilesStorageOperationsListResponseMeta\n];\n\nexport interface FileManagerFilesStorageOperationsTagsParamsWhere extends FilesCrudListTagsWhere {\n locale: string;\n tenant: string;\n}\n/**\n * @category StorageOperations\n * @category FilesStorageOperations\n * @category FilesStorageOperationsParams\n */\nexport interface FileManagerFilesStorageOperationsTagsParams {\n where: FileManagerFilesStorageOperationsTagsParamsWhere;\n limit: number;\n after?: string;\n}\n/**\n * @category StorageOperations\n * @category FilesStorageOperations\n */\nexport interface FileManagerFilesStorageOperations {\n /**\n * Get a single file with given ID from the storage.\n */\n get: (params: FileManagerFilesStorageOperationsGetParams) => Promise<File | null>;\n /**\n * Insert the file data into the database.\n */\n create: (params: FileManagerFilesStorageOperationsCreateParams) => Promise<File>;\n /**\n * Update the file data in the database.\n */\n update: (params: FileManagerFilesStorageOperationsUpdateParams) => Promise<File>;\n /**\n * Delete the file from the database.\n */\n delete: (params: FileManagerFilesStorageOperationsDeleteParams) => Promise<void>;\n /**\n * Store multiple files at once to the database.\n */\n createBatch: (params: FileManagerFilesStorageOperationsCreateBatchParams) => Promise<File[]>;\n /**\n * Get a list of files filtered by given parameters.\n */\n list: (\n params: FileManagerFilesStorageOperationsListParams\n ) => Promise<FileManagerFilesStorageOperationsListResponse>;\n /**\n * Get a list of all file tags filtered by given parameters.\n */\n tags: (\n params: FileManagerFilesStorageOperationsTagsParams\n ) => Promise<FileManagerFilesStorageOperationsTagsResponse>;\n}\n"],"mappings":""}
|
|
1
|
+
{"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import { I18NContext } from \"@webiny/api-i18n/types\";\nimport { FileStorage } from \"./plugins/storage/FileStorage\";\nimport { TenancyContext } from \"@webiny/api-tenancy/types\";\nimport { SecurityContext, SecurityPermission } from \"@webiny/api-security/types\";\nimport { Context } from \"@webiny/api/types\";\n\nexport interface FileManagerContext extends Context, SecurityContext, TenancyContext, I18NContext {\n fileManager: {\n files: FilesCRUD;\n settings: SettingsCRUD;\n storage: FileStorage;\n system: SystemCRUD;\n };\n}\n\nexport interface FilePermission extends SecurityPermission {\n name: \"fm.file\";\n rwd?: string;\n own?: boolean;\n}\n\nexport interface File {\n id: string;\n key: string;\n size: number;\n type: string;\n name: string;\n meta: Record<string, any>;\n tags: string[];\n createdOn: string;\n createdBy: CreatedBy;\n /**\n * Added with new storage operations refactoring.\n */\n tenant: string;\n locale: string;\n webinyVersion: string;\n /**\n * User can add new fields to the File object so we must allow it in the types.\n */\n [key: string]: any;\n}\n\nexport interface CreatedBy {\n id: string;\n displayName: string | null;\n type: string;\n}\n\nexport interface FileInput {\n key: string;\n name: string;\n size: number;\n type: string;\n meta: Record<string, any>;\n tags: string[];\n}\n\nexport interface FileListWhereParams {\n search?: string;\n type?: string;\n type_in?: string[];\n tag?: string;\n tag_in?: string[];\n tag_and_in?: string[];\n id_in?: string[];\n id?: string;\n}\nexport interface FilesListOpts {\n search?: string;\n types?: string[];\n tags?: string[];\n ids?: string[];\n limit?: number;\n after?: string;\n where?: FileListWhereParams;\n sort?: string[];\n}\n\nexport interface FileListMeta {\n cursor: string | null;\n totalCount: number;\n hasMoreItems: boolean;\n}\n\ninterface FilesCrudListTagsWhere {\n tag?: string;\n tag_contains?: string;\n tag_in?: string[];\n tag_not_startsWith?: string;\n tag_startsWith?: string;\n}\ninterface FilesCrudListTagsParams {\n where?: FilesCrudListTagsWhere;\n limit?: number;\n after?: string;\n}\n\nexport interface FilesCRUD {\n getFile(id: string): Promise<File>;\n listFiles(opts?: FilesListOpts): Promise<[File[], FileListMeta]>;\n listTags(params: FilesCrudListTagsParams): Promise<string[]>;\n createFile(data: FileInput): Promise<File>;\n updateFile(id: string, data: Partial<FileInput>): Promise<File>;\n deleteFile(id: string): Promise<boolean>;\n createFilesInBatch(data: FileInput[]): Promise<File[]>;\n}\n\nexport interface SystemCRUD {\n getVersion(): Promise<string | null>;\n setVersion(version: string): Promise<void>;\n install(args: { srcPrefix: string }): Promise<boolean>;\n upgrade(version: string, data?: Record<string, any>): Promise<boolean>;\n}\n\nexport interface FileManagerSettings {\n key: string;\n uploadMinFileSize: number;\n uploadMaxFileSize: number;\n srcPrefix: string;\n}\n\nexport interface FileManagerSystem {\n version: string;\n tenant: string;\n}\n\nexport type SettingsCRUD = {\n getSettings(): Promise<FileManagerSettings | null>;\n createSettings(data?: Partial<FileManagerSettings>): Promise<FileManagerSettings>;\n updateSettings(data: Partial<FileManagerSettings>): Promise<FileManagerSettings>;\n deleteSettings(): Promise<boolean>;\n};\n/********\n * Storage operations\n *******/\n\n/**\n * @category StorageOperations\n * @category SystemStorageOperations\n * @category SystemStorageOperationsParams\n */\nexport interface FileManagerSystemStorageOperationsUpdateParams {\n /**\n * The system data to be updated.\n */\n original: FileManagerSystem;\n /**\n * The system data with the updated fields.\n */\n data: FileManagerSystem;\n}\n/**\n * @category StorageOperations\n * @category SystemStorageOperations\n * @category SystemStorageOperationsParams\n */\nexport interface FileManagerSystemStorageOperationsCreateParams {\n /**\n * The system fields.\n */\n data: FileManagerSystem;\n}\n\n/**\n * @category StorageOperations\n * @category SystemStorageOperations\n */\nexport interface FileManagerSystemStorageOperations {\n /**\n * Get the FileManager system data.\n */\n get: () => Promise<FileManagerSystem | null>;\n /**\n * Update the FileManager system data..\n */\n update: (params: FileManagerSystemStorageOperationsUpdateParams) => Promise<FileManagerSystem>;\n /**\n * Create the FileManagerSystemData\n */\n create: (params: FileManagerSystemStorageOperationsCreateParams) => Promise<FileManagerSystem>;\n}\n\n/**\n * @category StorageOperations\n * @category SettingsStorageOperations\n * @category SettingsStorageOperationsParams\n */\nexport interface FileManagerSettingsStorageOperationsUpdateParams {\n /**\n * Original settings to be updated.\n */\n original: FileManagerSettings;\n /**\n * The settings with the updated fields.\n */\n data: FileManagerSettings;\n}\n/**\n * @category StorageOperations\n * @category SettingsStorageOperations\n * @category SettingsStorageOperationsParams\n */\nexport interface FileManagerSettingsStorageOperationsCreateParams {\n /**\n * The settings fields.\n */\n data: FileManagerSettings;\n}\n\n/**\n * @category StorageOperations\n * @category SettingsStorageOperations\n */\nexport interface FileManagerSettingsStorageOperations {\n /**\n * Get the FileManager system data.\n */\n get: () => Promise<FileManagerSettings | null>;\n /**\n * Create the FileManagerSettingsData\n */\n create: (\n params: FileManagerSettingsStorageOperationsCreateParams\n ) => Promise<FileManagerSettings>;\n /**\n * Update the FileManager system data..\n */\n update: (\n params: FileManagerSettingsStorageOperationsUpdateParams\n ) => Promise<FileManagerSettings>;\n /**\n * Delete the existing settings.\n */\n delete: () => Promise<void>;\n}\n\n/**\n * @category StorageOperations\n * @category FilesStorageOperations\n * @category FilesStorageOperationsParams\n */\nexport interface FileManagerFilesStorageOperationsGetParams {\n where: {\n id: string;\n tenant: string;\n locale: string;\n };\n}\n/**\n * @category StorageOperations\n * @category FilesStorageOperations\n * @category FilesStorageOperationsParams\n */\nexport interface FileManagerFilesStorageOperationsCreateParams {\n file: File;\n}\n/**\n * @category StorageOperations\n * @category FilesStorageOperations\n * @category FilesStorageOperationsParams\n */\nexport interface FileManagerFilesStorageOperationsUpdateParams {\n original: File;\n file: File;\n}\n\n/**\n * @category StorageOperations\n * @category FilesStorageOperations\n * @category FilesStorageOperationsParams\n */\nexport interface FileManagerFilesStorageOperationsDeleteParams {\n file: File;\n}\n/**\n * @category StorageOperations\n * @category FilesStorageOperations\n * @category FilesStorageOperationsParams\n */\nexport interface FileManagerFilesStorageOperationsCreateBatchParams {\n files: File[];\n}\n/**\n * @category StorageOperations\n * @category FilesStorageOperations\n * @category FilesStorageOperationsParams\n */\nexport interface FileManagerFilesStorageOperationsListParamsWhere {\n id?: string;\n id_in?: string[];\n name?: string;\n name_contains?: string;\n tag?: string;\n tag_contains?: string;\n tag_in?: string[];\n createdBy?: string;\n locale: string;\n tenant: string;\n private?: boolean;\n type?: string;\n type_in?: string[];\n search?: string;\n}\n/**\n * @category StorageOperations\n * @category FilesStorageOperations\n * @category FilesStorageOperationsParams\n */\nexport interface FileManagerFilesStorageOperationsListParams {\n where: FileManagerFilesStorageOperationsListParamsWhere;\n sort: string[];\n limit: number;\n after: string | null;\n}\n\n/**\n * @category StorageOperations\n * @category FilesStorageOperations\n * @category FilesStorageOperationsParams\n */\nexport interface FileManagerFilesStorageOperationsListResponseMeta {\n hasMoreItems: boolean;\n totalCount: number;\n cursor: string | null;\n}\nexport type FileManagerFilesStorageOperationsListResponse = [\n File[],\n FileManagerFilesStorageOperationsListResponseMeta\n];\n\nexport type FileManagerFilesStorageOperationsTagsResponse = [\n string[],\n FileManagerFilesStorageOperationsListResponseMeta\n];\n\nexport interface FileManagerFilesStorageOperationsTagsParamsWhere extends FilesCrudListTagsWhere {\n locale: string;\n tenant: string;\n}\n/**\n * @category StorageOperations\n * @category FilesStorageOperations\n * @category FilesStorageOperationsParams\n */\nexport interface FileManagerFilesStorageOperationsTagsParams {\n where: FileManagerFilesStorageOperationsTagsParamsWhere;\n limit: number;\n after?: string;\n}\n/**\n * @category StorageOperations\n * @category FilesStorageOperations\n */\nexport interface FileManagerFilesStorageOperations {\n /**\n * Get a single file with given ID from the storage.\n */\n get: (params: FileManagerFilesStorageOperationsGetParams) => Promise<File | null>;\n /**\n * Insert the file data into the database.\n */\n create: (params: FileManagerFilesStorageOperationsCreateParams) => Promise<File>;\n /**\n * Update the file data in the database.\n */\n update: (params: FileManagerFilesStorageOperationsUpdateParams) => Promise<File>;\n /**\n * Delete the file from the database.\n */\n delete: (params: FileManagerFilesStorageOperationsDeleteParams) => Promise<void>;\n /**\n * Store multiple files at once to the database.\n */\n createBatch: (params: FileManagerFilesStorageOperationsCreateBatchParams) => Promise<File[]>;\n /**\n * Get a list of files filtered by given parameters.\n */\n list: (\n params: FileManagerFilesStorageOperationsListParams\n ) => Promise<FileManagerFilesStorageOperationsListResponse>;\n /**\n * Get a list of all file tags filtered by given parameters.\n */\n tags: (\n params: FileManagerFilesStorageOperationsTagsParams\n ) => Promise<FileManagerFilesStorageOperationsTagsResponse>;\n}\n"],"mappings":""}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { HandlerEventArgs, HandlerHeaders } from "../types";
|
|
2
|
-
import { Body } from "aws-sdk/clients/s3";
|
|
3
|
-
interface EventHandlerResponse {
|
|
4
|
-
data: Body | null;
|
|
5
|
-
statusCode?: number;
|
|
6
|
-
headers: HandlerHeaders;
|
|
7
|
-
}
|
|
8
|
-
export interface EventHandlerCallable<T> {
|
|
9
|
-
(event: T): Promise<EventHandlerResponse>;
|
|
10
|
-
}
|
|
11
|
-
export declare const createHandler: <T extends HandlerEventArgs>(eventHandler: EventHandlerCallable<T>) => (event: T) => Promise<{
|
|
12
|
-
isBase64Encoded: boolean;
|
|
13
|
-
statusCode: number;
|
|
14
|
-
headers: {
|
|
15
|
-
[x: string]: string | boolean | undefined;
|
|
16
|
-
};
|
|
17
|
-
body: string;
|
|
18
|
-
} | {
|
|
19
|
-
statusCode: number;
|
|
20
|
-
headers: HandlerHeaders;
|
|
21
|
-
body: string;
|
|
22
|
-
isBase64Encoded?: undefined;
|
|
23
|
-
}>;
|
|
24
|
-
export {};
|