@webiny/api-file-manager 5.25.0-beta.6 → 5.25.1-beta.1
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 +18 -19
- package/plugins/crud/files.crud.js +18 -9
- package/plugins/crud/files.crud.js.map +1 -1
- package/plugins/crud/utils/checkBasePermissions.js +1 -1
- package/plugins/crud/utils/checkBasePermissions.js.map +1 -1
- package/plugins/definitions/FilesStorageOperationsProviderPlugin.d.ts +2 -2
- package/plugins/definitions/FilesStorageOperationsProviderPlugin.js.map +1 -1
- package/plugins/definitions/SettingsStorageOperationsProviderPlugin.d.ts +2 -2
- package/plugins/definitions/SettingsStorageOperationsProviderPlugin.js.map +1 -1
- package/plugins/definitions/SystemStorageOperationsProviderPlugin.d.ts +2 -2
- package/plugins/definitions/SystemStorageOperationsProviderPlugin.js.map +1 -1
- package/plugins/graphql.js +11 -3
- package/plugins/graphql.js.map +1 -1
- package/types.d.ts +4 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webiny/api-file-manager",
|
|
3
|
-
"version": "5.25.
|
|
3
|
+
"version": "5.25.1-beta.1",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"fm:base"
|
|
@@ -18,21 +18,20 @@
|
|
|
18
18
|
],
|
|
19
19
|
"license": "MIT",
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@babel/runtime": "7.
|
|
21
|
+
"@babel/runtime": "7.16.7",
|
|
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": "5.25.
|
|
29
|
-
"@webiny/handler-
|
|
30
|
-
"@webiny/handler-
|
|
31
|
-
"@webiny/
|
|
32
|
-
"@webiny/
|
|
33
|
-
"@webiny/
|
|
34
|
-
"
|
|
35
|
-
"aws-sdk": "2.1095.0",
|
|
23
|
+
"@webiny/api-security": "5.25.1-beta.1",
|
|
24
|
+
"@webiny/api-tenancy": "5.25.1-beta.1",
|
|
25
|
+
"@webiny/api-upgrade": "5.25.1-beta.1",
|
|
26
|
+
"@webiny/error": "5.25.1-beta.1",
|
|
27
|
+
"@webiny/handler": "5.25.1-beta.1",
|
|
28
|
+
"@webiny/handler-args": "5.25.1-beta.1",
|
|
29
|
+
"@webiny/handler-client": "5.25.1-beta.1",
|
|
30
|
+
"@webiny/handler-graphql": "5.25.1-beta.1",
|
|
31
|
+
"@webiny/plugins": "5.25.1-beta.1",
|
|
32
|
+
"@webiny/project-utils": "5.25.1-beta.1",
|
|
33
|
+
"@webiny/validation": "5.25.1-beta.1",
|
|
34
|
+
"aws-sdk": "2.1066.0",
|
|
36
35
|
"commodo-fields-object": "1.0.6",
|
|
37
36
|
"mdbid": "1.0.0",
|
|
38
37
|
"object-hash": "1.3.1",
|
|
@@ -45,9 +44,9 @@
|
|
|
45
44
|
"@babel/plugin-transform-runtime": "^7.16.4",
|
|
46
45
|
"@babel/preset-env": "^7.16.4",
|
|
47
46
|
"@babel/preset-typescript": "^7.16.0",
|
|
48
|
-
"@webiny/api-i18n": "^5.25.
|
|
49
|
-
"@webiny/api-i18n-ddb": "^5.25.
|
|
50
|
-
"@webiny/cli": "^5.25.
|
|
47
|
+
"@webiny/api-i18n": "^5.25.1-beta.1",
|
|
48
|
+
"@webiny/api-i18n-ddb": "^5.25.1-beta.1",
|
|
49
|
+
"@webiny/cli": "^5.25.1-beta.1",
|
|
51
50
|
"jest": "^26.6.3",
|
|
52
51
|
"rimraf": "^3.0.2",
|
|
53
52
|
"ttypescript": "^1.5.12",
|
|
@@ -72,5 +71,5 @@
|
|
|
72
71
|
]
|
|
73
72
|
}
|
|
74
73
|
},
|
|
75
|
-
"gitHead": "
|
|
74
|
+
"gitHead": "aeeff2c4da36d72638831e85f3fa1f815e9abb3e"
|
|
76
75
|
}
|
|
@@ -47,15 +47,21 @@ const checkOwnership = (file, permission, context) => {
|
|
|
47
47
|
};
|
|
48
48
|
|
|
49
49
|
const getLocaleCode = context => {
|
|
50
|
-
if (!context.
|
|
51
|
-
throw new _error.default("Missing
|
|
52
|
-
} else if (!context.i18nContent.locale) {
|
|
53
|
-
throw new _error.default("Missing i18nContent.locale on the FileManagerContext.", "MISSING_I18N_CONTENT_LOCALE");
|
|
54
|
-
} else if (!context.i18nContent.locale.code) {
|
|
55
|
-
throw new _error.default("Missing i18nContent.locale.code on the FileManagerContext.", "MISSING_I18N_CONTENT_LOCALE_CODE");
|
|
50
|
+
if (!context.i18n) {
|
|
51
|
+
throw new _error.default("Missing i18n on the FileManagerContext.", "MISSING_I18N");
|
|
56
52
|
}
|
|
57
53
|
|
|
58
|
-
|
|
54
|
+
const locale = context.i18n.getContentLocale();
|
|
55
|
+
|
|
56
|
+
if (!locale) {
|
|
57
|
+
throw new _error.default("Missing content locale on the FileManagerContext.", "MISSING_I18N_CONTENT_LOCALE");
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
if (!locale.code) {
|
|
61
|
+
throw new _error.default("Missing content locale code on the FileManagerContext.", "MISSING_I18N_CONTENT_LOCALE_CODE");
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return locale.code;
|
|
59
65
|
};
|
|
60
66
|
|
|
61
67
|
const filesContextCrudPlugin = new _handler.ContextPlugin(async context => {
|
|
@@ -388,14 +394,17 @@ const filesContextCrudPlugin = new _handler.ContextPlugin(async context => {
|
|
|
388
394
|
},
|
|
389
395
|
|
|
390
396
|
async listTags({
|
|
397
|
+
where: initialWhere,
|
|
391
398
|
after,
|
|
392
399
|
limit
|
|
393
400
|
}) {
|
|
394
401
|
await (0, _checkBasePermissions.default)(context);
|
|
395
|
-
|
|
402
|
+
|
|
403
|
+
const where = _objectSpread(_objectSpread({}, initialWhere), {}, {
|
|
396
404
|
tenant: context.tenancy.getCurrentTenant().id,
|
|
397
405
|
locale: getLocaleCode(context)
|
|
398
|
-
};
|
|
406
|
+
});
|
|
407
|
+
|
|
399
408
|
const params = {
|
|
400
409
|
where,
|
|
401
410
|
limit: limit || 100000,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["files.crud.ts"],"names":["BATCH_CREATE_MAX_FILES","checkOwnership","file","permission","context","own","identity","security","getIdentity","createdBy","id","NotAuthorizedError","getLocaleCode","i18nContent","WebinyError","locale","code","filesContextCrudPlugin","ContextPlugin","pluginType","FilesStorageOperationsProviderPlugin","type","providerPlugin","plugins","byType","find","storageOperations","provide","fileManager","filePlugins","FilePlugin","files","getFile","rwd","get","where","tenant","tenancy","getCurrentTenant","NotFoundError","createFile","input","tags","Array","isArray","meta","private","createdOn","Date","toISOString","displayName","webinyVersion","WEBINY_VERSION","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"],"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;AAC5F,MAAI,CAAAD,UAAU,SAAV,IAAAA,UAAU,WAAV,YAAAA,UAAU,CAAEE,GAAZ,MAAoB,IAAxB,EAA8B;AAC1B,UAAMC,QAAQ,GAAGF,OAAO,CAACG,QAAR,CAAiBC,WAAjB,EAAjB;;AACA,QAAIN,IAAI,CAACO,SAAL,CAAeC,EAAf,KAAsBJ,QAAQ,CAACI,EAAnC,EAAuC;AACnC,YAAM,IAAIC,+BAAJ,EAAN;AACH;AACJ;AACJ,CAPD;;AASA,MAAMC,aAAa,GAAIR,OAAD,IAAyC;AAC3D,MA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C,OAAhE;AAKA,YAAMkE,MAAM,GAAG;AACXnC,QAAAA,KADW;AAEXoC,QAAAA,KAAK,EAAEA,KAAK,IAAI,MAFL;AAGXI,QAAAA;AAHW,OAAf;;AAMA,UAAI;AACA,cAAM,CAACjC,IAAD,IAAS,MAAMhB,iBAAiB,CAACgB,IAAlB,CAAuB4B,MAAvB,CAArB;;AACA,YAAI3B,KAAK,CAACC,OAAN,CAAcF,IAAd,MAAwB,KAA5B,EAAmC;AAC/B,iBAAO,EAAP;AACH;AACD;AAChB;AACA;;;AACgB,eAAOA,IAAI,CAACmC,IAAL,EAAP;AACH,OATD,CASE,OAAOrB,EAAP,EAAW;AACT,cAAM,IAAI1C,cAAJ,CACF0C,EAAE,CAACC,OAAH,IAAc,4BADZ,EAEFD,EAAE,CAACxC,IAAH,IAAW,uBAFT,kCAIMwC,EAAE,CAACH,IAAH,IAAW,EAJjB;AAKEiB,UAAAA;AALF,WAAN;AAQH;AACJ;;AA3WuB,GAA5B;AA6WH,CApY8B,CAA/B;AAsYArD,sBAAsB,CAACqE,IAAvB,GAA8B,sBAA9B;eAEerE,sB","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.i18nContent) {\n throw new WebinyError(\n \"Missing i18nContent on the FileManagerContext.\",\n \"MISSING_I18N_CONTENT\"\n );\n } else if (!context.i18nContent.locale) {\n throw new WebinyError(\n \"Missing i18nContent.locale on the FileManagerContext.\",\n \"MISSING_I18N_CONTENT_LOCALE\"\n );\n } else if (!context.i18nContent.locale.code) {\n throw new WebinyError(\n \"Missing i18nContent.locale.code on the FileManagerContext.\",\n \"MISSING_I18N_CONTENT_LOCALE_CODE\"\n );\n }\n return context.i18nContent.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({ after, limit }) {\n await checkBasePermissions(context);\n\n const where: FileManagerFilesStorageOperationsTagsParamsWhere = {\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"]}
|
|
1
|
+
{"version":3,"sources":["files.crud.ts"],"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","rwd","get","where","tenant","tenancy","getCurrentTenant","NotFoundError","createFile","input","tags","Array","isArray","meta","private","createdOn","Date","toISOString","displayName","webinyVersion","WEBINY_VERSION","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"],"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;AAC5F,MAAI,CAAAD,UAAU,SAAV,IAAAA,UAAU,WAAV,YAAAA,UAAU,CAAEE,GAAZ,MAAoB,IAAxB,EAA8B;AAC1B,UAAMC,QAAQ,GAAGF,OAAO,CAACG,QAAR,CAAiBC,WAAjB,EAAjB;;AACA,QAAIN,IAAI,CAACO,S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pE,OAArB,CAAN;;AAEA,YAAMgC,KAAuD,mCACtDyC,YADsD;AAEzDxC,QAAAA,MAAM,EAAEjC,OAAO,CAACkC,OAAR,CAAgBC,gBAAhB,GAAmC7B,EAFc;AAGzDK,QAAAA,MAAM,EAAEH,aAAa,CAACR,OAAD;AAHoC,QAA7D;;AAMA,YAAMmE,MAAM,GAAG;AACXnC,QAAAA,KADW;AAEXoC,QAAAA,KAAK,EAAEA,KAAK,IAAI,MAFL;AAGXI,QAAAA;AAHW,OAAf;;AAMA,UAAI;AACA,cAAM,CAACjC,IAAD,IAAS,MAAMhB,iBAAiB,CAACgB,IAAlB,CAAuB4B,MAAvB,CAArB;;AACA,YAAI3B,KAAK,CAACC,OAAN,CAAcF,IAAd,MAAwB,KAA5B,EAAmC;AAC/B,iBAAO,EAAP;AACH;AACD;AAChB;AACA;;;AACgB,eAAOA,IAAI,CAACmC,IAAL,EAAP;AACH,OATD,CASE,OAAOrB,EAAP,EAAW;AACT,cAAM,IAAI3C,cAAJ,CACF2C,EAAE,CAACC,OAAH,IAAc,4BADZ,EAEFD,EAAE,CAACxC,IAAH,IAAW,uBAFT,kCAIMwC,EAAE,CAACH,IAAH,IAAW,EAJjB;AAKEiB,UAAAA;AALF,WAAN;AAQH;AACJ;;AA5WuB,GAA5B;AA8WH,CArY8B,CAA/B;AAuYArD,sBAAsB,CAACqE,IAAvB,GAA8B,sBAA9B;eAEerE,sB","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"]}
|
|
@@ -8,7 +8,7 @@ exports.default = void 0;
|
|
|
8
8
|
var _apiSecurity = require("@webiny/api-security");
|
|
9
9
|
|
|
10
10
|
var _default = async (context, check = {}) => {
|
|
11
|
-
await context.
|
|
11
|
+
await context.i18n.checkI18NContentPermission();
|
|
12
12
|
const filePermission = await context.security.getPermission("fm.file");
|
|
13
13
|
|
|
14
14
|
if (!filePermission) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["checkBasePermissions.ts"],"names":["context","check","
|
|
1
|
+
{"version":3,"sources":["checkBasePermissions.ts"],"names":["context","check","i18n","checkI18NContentPermission","filePermission","security","getPermission","NotAuthorizedError","rwd","hasRwd","filesFilePermission","includes"],"mappings":";;;;;;;AACA;;eAEe,OACXA,OADW,EAEXC,KAAuB,GAAG,EAFf,KAGe;AAC1B,QAAMD,OAAO,CAACE,IAAR,CAAaC,0BAAb,EAAN;AACA,QAAMC,cAAc,GAAG,MAAMJ,OAAO,CAACK,QAAR,CAAiBC,aAAjB,CAA+C,SAA/C,CAA7B;;AACA,MAAI,CAACF,cAAL,EAAqB;AACjB,UAAM,IAAIG,+BAAJ,EAAN;AACH;;AACD,MAAIN,KAAK,CAACO,GAAN,IAAa,CAACC,MAAM,CAACL,cAAD,EAAiBH,KAAK,CAACO,GAAvB,CAAxB,EAAqD;AACjD,UAAM,IAAID,+BAAJ,EAAN;AACH;;AAED,SAAOH,cAAP;AACH,C;;;;AAED,MAAMK,MAAM,GAAG,CAACC,mBAAD,EAAsCF,GAAtC,KAA+D;AAC1E,MAAI,OAAOE,mBAAmB,CAACF,GAA3B,KAAmC,QAAvC,EAAiD;AAC7C,WAAO,IAAP;AACH;;AAED,SAAOE,mBAAmB,CAACF,GAApB,CAAwBG,QAAxB,CAAiCH,GAAjC,CAAP;AACH,CAND","sourcesContent":["import { FileManagerContext, FilePermission } from \"~/types\";\nimport { NotAuthorizedError } from \"@webiny/api-security\";\n\nexport default async (\n context: FileManagerContext,\n check: { rwd?: string } = {}\n): Promise<FilePermission> => {\n await context.i18n.checkI18NContentPermission();\n const filePermission = await context.security.getPermission<FilePermission>(\"fm.file\");\n if (!filePermission) {\n throw new NotAuthorizedError();\n }\n if (check.rwd && !hasRwd(filePermission, check.rwd)) {\n throw new NotAuthorizedError();\n }\n\n return filePermission;\n};\n\nconst hasRwd = (filesFilePermission: FilePermission, rwd: string): boolean => {\n if (typeof filesFilePermission.rwd !== \"string\") {\n return true;\n }\n\n return filesFilePermission.rwd.includes(rwd);\n};\n"]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Plugin } from "@webiny/plugins";
|
|
2
2
|
import { FileManagerContext, FileManagerFilesStorageOperations } from "../../types";
|
|
3
|
-
export interface FilesStorageOperationsProviderPluginParams {
|
|
4
|
-
context:
|
|
3
|
+
export interface FilesStorageOperationsProviderPluginParams<T = FileManagerContext> {
|
|
4
|
+
context: T;
|
|
5
5
|
}
|
|
6
6
|
export declare abstract class FilesStorageOperationsProviderPlugin extends Plugin {
|
|
7
7
|
static readonly type: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["FilesStorageOperationsProviderPlugin.ts"],"names":["FilesStorageOperationsProviderPlugin","Plugin"],"mappings":";;;;;;;;;;;AAAA;;AAOO,MAAeA,oCAAf,SAA4DC,eAA5D,CAAmE;;;8BAApDD,oC,UAC6B,oC","sourcesContent":["import { Plugin } from \"@webiny/plugins\";\nimport { FileManagerContext, FileManagerFilesStorageOperations } from \"~/types\";\n\nexport interface FilesStorageOperationsProviderPluginParams {\n context:
|
|
1
|
+
{"version":3,"sources":["FilesStorageOperationsProviderPlugin.ts"],"names":["FilesStorageOperationsProviderPlugin","Plugin"],"mappings":";;;;;;;;;;;AAAA;;AAOO,MAAeA,oCAAf,SAA4DC,eAA5D,CAAmE;;;8BAApDD,oC,UAC6B,oC","sourcesContent":["import { Plugin } from \"@webiny/plugins\";\nimport { FileManagerContext, FileManagerFilesStorageOperations } from \"~/types\";\n\nexport interface FilesStorageOperationsProviderPluginParams<T = FileManagerContext> {\n context: T;\n}\n\nexport abstract class FilesStorageOperationsProviderPlugin extends Plugin {\n public static override readonly type: string = \"fm.storageOperationsProvider.files\";\n\n public abstract provide(\n params: FilesStorageOperationsProviderPluginParams\n ): Promise<FileManagerFilesStorageOperations>;\n}\n"]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Plugin } from "@webiny/plugins";
|
|
2
2
|
import { FileManagerContext, FileManagerSettingsStorageOperations } from "../../types";
|
|
3
|
-
export interface SettingsStorageOperationsProviderPluginParams {
|
|
4
|
-
context:
|
|
3
|
+
export interface SettingsStorageOperationsProviderPluginParams<T = FileManagerContext> {
|
|
4
|
+
context: T;
|
|
5
5
|
}
|
|
6
6
|
export declare abstract class SettingsStorageOperationsProviderPlugin extends Plugin {
|
|
7
7
|
static readonly type: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["SettingsStorageOperationsProviderPlugin.ts"],"names":["SettingsStorageOperationsProviderPlugin","Plugin"],"mappings":";;;;;;;;;;;AAAA;;AAOO,MAAeA,uCAAf,SAA+DC,eAA/D,CAAsE;;;8BAAvDD,uC,UAC6B,uC","sourcesContent":["import { Plugin } from \"@webiny/plugins\";\nimport { FileManagerContext, FileManagerSettingsStorageOperations } from \"~/types\";\n\nexport interface SettingsStorageOperationsProviderPluginParams {\n context:
|
|
1
|
+
{"version":3,"sources":["SettingsStorageOperationsProviderPlugin.ts"],"names":["SettingsStorageOperationsProviderPlugin","Plugin"],"mappings":";;;;;;;;;;;AAAA;;AAOO,MAAeA,uCAAf,SAA+DC,eAA/D,CAAsE;;;8BAAvDD,uC,UAC6B,uC","sourcesContent":["import { Plugin } from \"@webiny/plugins\";\nimport { FileManagerContext, FileManagerSettingsStorageOperations } from \"~/types\";\n\nexport interface SettingsStorageOperationsProviderPluginParams<T = FileManagerContext> {\n context: T;\n}\n\nexport abstract class SettingsStorageOperationsProviderPlugin extends Plugin {\n public static override readonly type: string = \"fm.storageOperationsProvider.settings\";\n\n public abstract provide(\n params: SettingsStorageOperationsProviderPluginParams\n ): Promise<FileManagerSettingsStorageOperations>;\n}\n"]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Plugin } from "@webiny/plugins";
|
|
2
2
|
import { FileManagerContext, FileManagerSystemStorageOperations } from "../../types";
|
|
3
|
-
export interface SystemStorageOperationsProviderPluginParams {
|
|
4
|
-
context:
|
|
3
|
+
export interface SystemStorageOperationsProviderPluginParams<T = FileManagerContext> {
|
|
4
|
+
context: T;
|
|
5
5
|
}
|
|
6
6
|
export declare abstract class SystemStorageOperationsProviderPlugin extends Plugin {
|
|
7
7
|
static readonly type: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["SystemStorageOperationsProviderPlugin.ts"],"names":["SystemStorageOperationsProviderPlugin","Plugin"],"mappings":";;;;;;;;;;;AAAA;;AAOO,MAAeA,qCAAf,SAA6DC,eAA7D,CAAoE;;;8BAArDD,qC,UAC6B,qC","sourcesContent":["import { Plugin } from \"@webiny/plugins\";\nimport { FileManagerContext, FileManagerSystemStorageOperations } from \"~/types\";\n\nexport interface SystemStorageOperationsProviderPluginParams {\n context:
|
|
1
|
+
{"version":3,"sources":["SystemStorageOperationsProviderPlugin.ts"],"names":["SystemStorageOperationsProviderPlugin","Plugin"],"mappings":";;;;;;;;;;;AAAA;;AAOO,MAAeA,qCAAf,SAA6DC,eAA7D,CAAoE;;;8BAArDD,qC,UAC6B,qC","sourcesContent":["import { Plugin } from \"@webiny/plugins\";\nimport { FileManagerContext, FileManagerSystemStorageOperations } from \"~/types\";\n\nexport interface SystemStorageOperationsProviderPluginParams<T = FileManagerContext> {\n context: T;\n}\n\nexport abstract class SystemStorageOperationsProviderPlugin extends Plugin {\n public static override readonly type: string = \"fm.storageOperationsProvider.system\";\n\n public abstract provide(\n params: SystemStorageOperationsProviderPluginParams\n ): Promise<FileManagerSystemStorageOperations>;\n}\n"]}
|
package/plugins/graphql.js
CHANGED
|
@@ -126,8 +126,16 @@ const plugin = {
|
|
|
126
126
|
tag: String
|
|
127
127
|
tag_in: [String!]
|
|
128
128
|
tag_and_in: [String!]
|
|
129
|
+
tag_startsWith: String
|
|
130
|
+
tag_not_startsWith: String
|
|
129
131
|
id_in: [ID!]
|
|
130
132
|
id: ID
|
|
133
|
+
createdBy: ID
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
input TagWhereInput {
|
|
137
|
+
tag_startsWith: String
|
|
138
|
+
tag_not_startsWith: String
|
|
131
139
|
}
|
|
132
140
|
|
|
133
141
|
type FmQuery {
|
|
@@ -143,7 +151,7 @@ const plugin = {
|
|
|
143
151
|
where: FileWhereInput
|
|
144
152
|
): FileListResponse
|
|
145
153
|
|
|
146
|
-
listTags: [String]
|
|
154
|
+
listTags(where: TagWhereInput): [String]
|
|
147
155
|
|
|
148
156
|
# Get installed version
|
|
149
157
|
version: String
|
|
@@ -220,12 +228,12 @@ const plugin = {
|
|
|
220
228
|
|
|
221
229
|
async version(_, __, context) {
|
|
222
230
|
const {
|
|
223
|
-
|
|
231
|
+
i18n,
|
|
224
232
|
tenancy,
|
|
225
233
|
fileManager
|
|
226
234
|
} = context;
|
|
227
235
|
|
|
228
|
-
if (!tenancy.getCurrentTenant() || !
|
|
236
|
+
if (!tenancy.getCurrentTenant() || !i18n.getContentLocale()) {
|
|
229
237
|
return null;
|
|
230
238
|
}
|
|
231
239
|
|
package/plugins/graphql.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["graphql.ts"],"names":["emptyResolver","resolve","fn","Response","e","ErrorResponse","plugin","type","schema","typeDefs","resolvers","File","src","file","_","context","settings","fileManager","getSettings","srcPrefix","key","Query","Mutation","FmQuery","getFile","args","files","id","listFiles","data","meta","ListResponse","listTags","error","version","__","i18nContent","tenancy","getCurrentTenant","getCurrentLocale","system","getVersion","FmMutation","createFile","updateFile","createFiles","createFilesInBatch","deleteFile","storage","delete","install","upgrade","updateSettings"],"mappings":";;;;;;;AAAA;;AAIA,MAAMA,aAAa,GAAG,OAAO,EAAP,CAAtB;AAEA;AACA;AACA;AACA;;;AAKA,MAAMC,OAAO,GAAG,MAAOC,EAAP,IAA+B;AAC3C,MAAI;AACA,WAAO,IAAIC,wBAAJ,CAAa,MAAMD,EAAE,EAArB,CAAP;AACH,GAFD,CAEE,OAAOE,CAAP,EAAU;AACR,WAAO,IAAIC,6BAAJ,CAAkBD,CAAlB,CAAP;AACH;AACJ,CAND;;AAQA,MAAME,MAA+C,GAAG;AACpDC,EAAAA,IAAI,EAAE,gBAD8C;AAEpDC,EAAAA,MAAM,EAAE;AACJC,IAAAA,QAAQ;AAAE;AAAe;AACjC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SA3JY;AA4JJC,IAAAA,SAAS,EAAE;AACPC,MAAAA,IAAI,EAAE;AACF,cAAMC,GAAN,CAAUC,IAAV,EAAgBC,CAAhB,EAAmBC,OAAnB,EAAgD;AAC5C,gBAAMC,QAAQ,GAAG,MAAMD,OAAO,CAACE,WAAR,CAAoBD,QAApB,CAA6BE,WAA7B,EAAvB;AACA,iBAAO,CAAC,CAAAF,QAAQ,SAAR,IAAAA,QAAQ,WAAR,YAAAA,QAAQ,CAAEG,SAAV,KAAuB,EAAxB,IAA8BN,IAAI,CAACO,GAA1C;AACH;;AAJC,OADC;AAOPC,MAAAA,KAAK,EAAE;AACHJ,QAAAA,WAAW,EAAEjB;AADV,OAPA;AAUPsB,MAAAA,QAAQ,EAAE;AACNL,QAAAA,WAAW,EAAEjB;AADP,OAVH;AAaPuB,MAAAA,OAAO,EAAE;AACLC,QAAAA,OAAO,CAACV,CAAD,EAAIW,IAAJ,EAAeV,OAAf,EAAwB;AAC3B,iBAAOd,OAAO,CAAC,MAAMc,OAAO,CAACE,WAAR,CAAoBS,KAApB,CAA0BF,OAA1B,CAAkCC,IAAI,CAACE,EAAvC,CAAP,CAAd;AACH,SAHI;;AAIL,cAAMC,SAAN,CAAgBd,CAAhB,EAAmBW,IAAnB,EAAwCV,OA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AA,SAAS,EAAEM,IAAI,CAACN;AAAlB,WAAnC,CADU,CAAd;AAGH,SAvBO;;AAwBR,cAAMgC,OAAN,CAAcrC,CAAd,EAAiBW,IAAjB,EAA4BV,OAA5B,EAAqC;AACjC,iBAAOd,OAAO,CAAC,MAAMc,OAAO,CAACE,WAAR,CAAoBuB,MAApB,CAA2BW,OAA3B,CAAmC1B,IAAI,CAACS,OAAxC,CAAP,CAAd;AACH,SA1BO;;AA2BR,cAAMkB,cAAN,CAAqBtC,CAArB,EAAwBW,IAAxB,EAAmCV,OAAnC,EAA4C;AACxC,iBAAOd,OAAO,CAAC,MAAMc,OAAO,CAACE,WAAR,CAAoBD,QAApB,CAA6BoC,cAA7B,CAA4C3B,IAAI,CAACI,IAAjD,CAAP,CAAd;AACH;;AA7BO;AA5CL;AA5JP;AAF4C,CAAxD;eA6OevB,M","sourcesContent":["import { Response, ErrorResponse, ListResponse } from \"@webiny/handler-graphql\";\nimport { FileManagerContext, FilesListOpts } from \"~/types\";\nimport { GraphQLSchemaPlugin } from \"@webiny/handler-graphql/types\";\n\nconst emptyResolver = () => ({});\n\n/**\n * Use any because it really can be any.\n * TODO @ts-refactor maybe use generics at some point?\n */\ninterface ResolveCallable {\n (): Promise<any>;\n}\n\nconst resolve = async (fn: ResolveCallable) => {\n try {\n return new Response(await fn());\n } catch (e) {\n return new ErrorResponse(e);\n }\n};\n\nconst plugin: GraphQLSchemaPlugin<FileManagerContext> = {\n type: \"graphql-schema\",\n schema: {\n typeDefs: /* GraphQL */ `\n type FmCreatedBy {\n id: ID\n displayName: String\n }\n\n input FileInput {\n key: String\n name: String\n size: Int\n type: String\n tags: [String]\n meta: JSON\n }\n\n type UploadFileResponseDataFile {\n name: String\n type: String\n size: Int\n key: String\n }\n\n type UploadFileResponseData {\n # Contains data that is necessary for initiating a file upload.\n data: JSON\n file: UploadFileResponseDataFile\n }\n\n type FileListMeta {\n cursor: String\n totalCount: Int\n hasMoreItems: Boolean\n }\n\n type FileError {\n code: String\n message: String\n data: JSON\n stack: String\n }\n\n type FileListResponse {\n data: [File]\n meta: FileListMeta\n error: FileError\n }\n\n type FileResponse {\n data: File\n error: FileError\n }\n\n type CreateFilesResponse {\n data: [File]!\n error: FileError\n }\n\n type File {\n id: ID\n key: String\n name: String\n size: Int\n type: String\n src: String\n tags: [String]\n meta: JSON\n createdOn: DateTime\n createdBy: FmCreatedBy\n }\n\n type FileManagerBooleanResponse {\n data: Boolean\n error: FileError\n }\n\n type FileManagerSettings {\n uploadMinFileSize: Number\n uploadMaxFileSize: Number\n srcPrefix: String\n }\n\n input FileManagerSettingsInput {\n uploadMinFileSize: Number\n uploadMaxFileSize: Number\n srcPrefix: String\n }\n\n type FileManagerSettingsResponse {\n data: FileManagerSettings\n error: FileError\n }\n\n input FileWhereInput {\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: [ID!]\n id: ID\n }\n\n type FmQuery {\n getFile(id: ID, where: JSON, sort: String): FileResponse\n\n listFiles(\n limit: Int\n after: String\n types: [String]\n tags: [String]\n ids: [ID]\n search: String\n where: FileWhereInput\n ): FileListResponse\n\n listTags: [String]\n\n # Get installed version\n version: String\n\n getSettings: FileManagerSettingsResponse\n }\n\n type FilesDeleteResponse {\n data: Boolean\n error: FileError\n }\n\n type FmMutation {\n createFile(data: FileInput!): FileResponse\n createFiles(data: [FileInput]!): CreateFilesResponse\n updateFile(id: ID!, data: FileInput!): FileResponse\n deleteFile(id: ID!): FilesDeleteResponse\n\n # Install File manager\n install(srcPrefix: String): FileManagerBooleanResponse\n\n upgrade(version: String!): FileManagerBooleanResponse\n\n updateSettings(data: FileManagerSettingsInput): FileManagerSettingsResponse\n }\n\n input FilesInstallInput {\n srcPrefix: String!\n }\n\n extend type Query {\n fileManager: FmQuery\n }\n\n extend type Mutation {\n fileManager: FmMutation\n }\n `,\n resolvers: {\n File: {\n async src(file, _, context: FileManagerContext) {\n const settings = await context.fileManager.settings.getSettings();\n return (settings?.srcPrefix || \"\") + file.key;\n }\n },\n Query: {\n fileManager: emptyResolver\n },\n Mutation: {\n fileManager: emptyResolver\n },\n FmQuery: {\n getFile(_, args: any, context) {\n return resolve(() => context.fileManager.files.getFile(args.id));\n },\n async listFiles(_, args: FilesListOpts, context) {\n try {\n const [data, meta] = await context.fileManager.files.listFiles(args);\n return new ListResponse(data, meta);\n } catch (e) {\n return new ErrorResponse(e);\n }\n },\n async listTags(_, args: any, context) {\n try {\n return await context.fileManager.files.listTags(args || {});\n } catch (error) {\n return new ErrorResponse(error);\n }\n },\n async version(_, __, context) {\n const { i18nContent, tenancy, fileManager } = context;\n if (!tenancy.getCurrentTenant() || !i18nContent.getCurrentLocale()) {\n return null;\n }\n\n return await fileManager.system.getVersion();\n },\n async getSettings(_, __, context) {\n return resolve(() => context.fileManager.settings.getSettings());\n }\n },\n FmMutation: {\n async createFile(_, args: any, context) {\n return resolve(() => context.fileManager.files.createFile(args.data));\n },\n async updateFile(_, args: any, context) {\n return resolve(() => context.fileManager.files.updateFile(args.id, args.data));\n },\n async createFiles(_, args: any, context) {\n return resolve(() => context.fileManager.files.createFilesInBatch(args.data));\n },\n async deleteFile(_, args: any, context) {\n return resolve(async () => {\n const file = await context.fileManager.files.getFile(args.id);\n return await context.fileManager.storage.delete({\n id: file.id,\n key: file.key\n });\n });\n },\n async install(_, args: any, context) {\n return resolve(() =>\n context.fileManager.system.install({ srcPrefix: args.srcPrefix })\n );\n },\n async upgrade(_, args: any, context) {\n return resolve(() => context.fileManager.system.upgrade(args.version));\n },\n async updateSettings(_, args: any, context) {\n return resolve(() => context.fileManager.settings.updateSettings(args.data));\n }\n }\n }\n }\n};\n\nexport default plugin;\n"]}
|
|
1
|
+
{"version":3,"sources":["graphql.ts"],"names":["emptyResolver","resolve","fn","Response","e","ErrorResponse","plugin","type","schema","typeDefs","resolvers","File","src","file","_","context","settings","fileManager","getSettings","srcPrefix","key","Query","Mutation","FmQuery","getFile","args","files","id","listFiles","data","meta","ListResponse","listTags","error","version","__","i18n","tenancy","getCurrentTenant","getContentLocale","system","getVersion","FmMutation","createFile","updateFile","createFiles","createFilesInBatch","deleteFile","storage","delete","install","upgrade","updateSettings"],"mappings":";;;;;;;AAAA;;AAIA,MAAMA,aAAa,GAAG,OAAO,EAAP,CAAtB;AAEA;AACA;AACA;AACA;;;AAKA,MAAMC,OAAO,GAAG,MAAOC,EAAP,IAA+B;AAC3C,MAAI;AACA,WAAO,IAAIC,wBAAJ,CAAa,MAAMD,EAAE,EAArB,CAAP;AACH,GAFD,CAEE,OAAOE,CAAP,EAAU;AACR,WAAO,IAAIC,6BAAJ,CAAkBD,CAAlB,CAAP;AACH;AACJ,CAND;;AAQA,MAAME,MAA+C,GAAG;AACpDC,EAAAA,IAAI,EAAE,gBAD8C;AAEpDC,EAAAA,MAAM,EAAE;AACJC,IAAAA,QAAQ;AAAE;AAAe;AACjC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;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A4C;AACxC,iBAAOd,OAAO,CAAC,MAAMc,OAAO,CAACE,WAAR,CAAoBD,QAApB,CAA6BoC,cAA7B,CAA4C3B,IAAI,CAACI,IAAjD,CAAP,CAAd;AACH;;AA7BO;AA5CL;AApKP;AAF4C,CAAxD;eAqPevB,M","sourcesContent":["import { Response, ErrorResponse, ListResponse } from \"@webiny/handler-graphql\";\nimport { FileManagerContext, FilesListOpts } from \"~/types\";\nimport { GraphQLSchemaPlugin } from \"@webiny/handler-graphql/types\";\n\nconst emptyResolver = () => ({});\n\n/**\n * Use any because it really can be any.\n * TODO @ts-refactor maybe use generics at some point?\n */\ninterface ResolveCallable {\n (): Promise<any>;\n}\n\nconst resolve = async (fn: ResolveCallable) => {\n try {\n return new Response(await fn());\n } catch (e) {\n return new ErrorResponse(e);\n }\n};\n\nconst plugin: GraphQLSchemaPlugin<FileManagerContext> = {\n type: \"graphql-schema\",\n schema: {\n typeDefs: /* GraphQL */ `\n type FmCreatedBy {\n id: ID\n displayName: String\n }\n\n input FileInput {\n key: String\n name: String\n size: Int\n type: String\n tags: [String]\n meta: JSON\n }\n\n type UploadFileResponseDataFile {\n name: String\n type: String\n size: Int\n key: String\n }\n\n type UploadFileResponseData {\n # Contains data that is necessary for initiating a file upload.\n data: JSON\n file: UploadFileResponseDataFile\n }\n\n type FileListMeta {\n cursor: String\n totalCount: Int\n hasMoreItems: Boolean\n }\n\n type FileError {\n code: String\n message: String\n data: JSON\n stack: String\n }\n\n type FileListResponse {\n data: [File]\n meta: FileListMeta\n error: FileError\n }\n\n type FileResponse {\n data: File\n error: FileError\n }\n\n type CreateFilesResponse {\n data: [File]!\n error: FileError\n }\n\n type File {\n id: ID\n key: String\n name: String\n size: Int\n type: String\n src: String\n tags: [String]\n meta: JSON\n createdOn: DateTime\n createdBy: FmCreatedBy\n }\n\n type FileManagerBooleanResponse {\n data: Boolean\n error: FileError\n }\n\n type FileManagerSettings {\n uploadMinFileSize: Number\n uploadMaxFileSize: Number\n srcPrefix: String\n }\n\n input FileManagerSettingsInput {\n uploadMinFileSize: Number\n uploadMaxFileSize: Number\n srcPrefix: String\n }\n\n type FileManagerSettingsResponse {\n data: FileManagerSettings\n error: FileError\n }\n\n input FileWhereInput {\n search: String\n type: String\n type_in: [String!]\n tag: String\n tag_in: [String!]\n tag_and_in: [String!]\n tag_startsWith: String\n tag_not_startsWith: String\n id_in: [ID!]\n id: ID\n createdBy: ID\n }\n\n input TagWhereInput {\n tag_startsWith: String\n tag_not_startsWith: String\n }\n\n type FmQuery {\n getFile(id: ID, where: JSON, sort: String): FileResponse\n\n listFiles(\n limit: Int\n after: String\n types: [String]\n tags: [String]\n ids: [ID]\n search: String\n where: FileWhereInput\n ): FileListResponse\n\n listTags(where: TagWhereInput): [String]\n\n # Get installed version\n version: String\n\n getSettings: FileManagerSettingsResponse\n }\n\n type FilesDeleteResponse {\n data: Boolean\n error: FileError\n }\n\n type FmMutation {\n createFile(data: FileInput!): FileResponse\n createFiles(data: [FileInput]!): CreateFilesResponse\n updateFile(id: ID!, data: FileInput!): FileResponse\n deleteFile(id: ID!): FilesDeleteResponse\n\n # Install File manager\n install(srcPrefix: String): FileManagerBooleanResponse\n\n upgrade(version: String!): FileManagerBooleanResponse\n\n updateSettings(data: FileManagerSettingsInput): FileManagerSettingsResponse\n }\n\n input FilesInstallInput {\n srcPrefix: String!\n }\n\n extend type Query {\n fileManager: FmQuery\n }\n\n extend type Mutation {\n fileManager: FmMutation\n }\n `,\n resolvers: {\n File: {\n async src(file, _, context: FileManagerContext) {\n const settings = await context.fileManager.settings.getSettings();\n return (settings?.srcPrefix || \"\") + file.key;\n }\n },\n Query: {\n fileManager: emptyResolver\n },\n Mutation: {\n fileManager: emptyResolver\n },\n FmQuery: {\n getFile(_, args: any, context) {\n return resolve(() => context.fileManager.files.getFile(args.id));\n },\n async listFiles(_, args: FilesListOpts, context) {\n try {\n const [data, meta] = await context.fileManager.files.listFiles(args);\n return new ListResponse(data, meta);\n } catch (e) {\n return new ErrorResponse(e);\n }\n },\n async listTags(_, args: any, context) {\n try {\n return await context.fileManager.files.listTags(args || {});\n } catch (error) {\n return new ErrorResponse(error);\n }\n },\n async version(_, __, context) {\n const { i18n, tenancy, fileManager } = context;\n if (!tenancy.getCurrentTenant() || !i18n.getContentLocale()) {\n return null;\n }\n\n return await fileManager.system.getVersion();\n },\n async getSettings(_, __, context) {\n return resolve(() => context.fileManager.settings.getSettings());\n }\n },\n FmMutation: {\n async createFile(_, args: any, context) {\n return resolve(() => context.fileManager.files.createFile(args.data));\n },\n async updateFile(_, args: any, context) {\n return resolve(() => context.fileManager.files.updateFile(args.id, args.data));\n },\n async createFiles(_, args: any, context) {\n return resolve(() => context.fileManager.files.createFilesInBatch(args.data));\n },\n async deleteFile(_, args: any, context) {\n return resolve(async () => {\n const file = await context.fileManager.files.getFile(args.id);\n return await context.fileManager.storage.delete({\n id: file.id,\n key: file.key\n });\n });\n },\n async install(_, args: any, context) {\n return resolve(() =>\n context.fileManager.system.install({ srcPrefix: args.srcPrefix })\n );\n },\n async upgrade(_, args: any, context) {\n return resolve(() => context.fileManager.system.upgrade(args.version));\n },\n async updateSettings(_, args: any, context) {\n return resolve(() => context.fileManager.settings.updateSettings(args.data));\n }\n }\n }\n }\n};\n\nexport default plugin;\n"]}
|
package/types.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
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
5
|
import { Context } from "@webiny/handler/types";
|
|
6
|
-
export interface FileManagerContext extends Context, SecurityContext, TenancyContext,
|
|
6
|
+
export interface FileManagerContext extends Context, SecurityContext, TenancyContext, I18NContext {
|
|
7
7
|
fileManager: {
|
|
8
8
|
files: FilesCRUD;
|
|
9
9
|
settings: SettingsCRUD;
|
|
@@ -79,6 +79,8 @@ interface FilesCrudListTagsWhere {
|
|
|
79
79
|
tag?: string;
|
|
80
80
|
tag_contains?: string;
|
|
81
81
|
tag_in?: string[];
|
|
82
|
+
tag_not_startsWith?: string;
|
|
83
|
+
tag_startsWith?: string;
|
|
82
84
|
}
|
|
83
85
|
interface FilesCrudListTagsParams {
|
|
84
86
|
where?: FilesCrudListTagsWhere;
|