@webiny/api-file-manager 5.36.2 → 5.37.0-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.
Files changed (98) hide show
  1. package/FileManagerContextSetup.d.ts +13 -0
  2. package/FileManagerContextSetup.js +113 -0
  3. package/FileManagerContextSetup.js.map +1 -0
  4. package/cmsFileStorage/CmsFilesStorage.d.ts +27 -0
  5. package/cmsFileStorage/CmsFilesStorage.js +173 -0
  6. package/cmsFileStorage/CmsFilesStorage.js.map +1 -0
  7. package/cmsFileStorage/ListFilesWhereProcessor.d.ts +7 -0
  8. package/cmsFileStorage/ListFilesWhereProcessor.js +35 -0
  9. package/cmsFileStorage/ListFilesWhereProcessor.js.map +1 -0
  10. package/cmsFileStorage/ListTagsWhereProcessor.d.ts +7 -0
  11. package/cmsFileStorage/ListTagsWhereProcessor.js +35 -0
  12. package/cmsFileStorage/ListTagsWhereProcessor.js.map +1 -0
  13. package/cmsFileStorage/createFileManagerPlugins.d.ts +5 -0
  14. package/cmsFileStorage/createFileManagerPlugins.js +34 -0
  15. package/cmsFileStorage/createFileManagerPlugins.js.map +1 -0
  16. package/cmsFileStorage/createModelField.d.ts +5 -0
  17. package/cmsFileStorage/createModelField.js +37 -0
  18. package/cmsFileStorage/createModelField.js.map +1 -0
  19. package/cmsFileStorage/file.model.d.ts +4 -0
  20. package/cmsFileStorage/file.model.js +124 -0
  21. package/cmsFileStorage/file.model.js.map +1 -0
  22. package/cmsFileStorage/isInstallationPending.d.ts +4 -0
  23. package/cmsFileStorage/isInstallationPending.js +21 -0
  24. package/cmsFileStorage/isInstallationPending.js.map +1 -0
  25. package/contants.d.ts +1 -0
  26. package/contants.js +8 -0
  27. package/contants.js.map +1 -0
  28. package/createFileManager/files.crud.js +39 -61
  29. package/createFileManager/files.crud.js.map +1 -1
  30. package/createFileManager/index.d.ts +4 -2
  31. package/createFileManager/index.js.map +1 -1
  32. package/createFileManager/permissions/FilesPermissions.d.ts +4 -0
  33. package/createFileManager/permissions/FilesPermissions.js +9 -0
  34. package/createFileManager/permissions/FilesPermissions.js.map +1 -0
  35. package/createFileManager/settings.crud.js.map +1 -1
  36. package/createFileManager/system.crud.js.map +1 -1
  37. package/graphql/baseSchema.d.ts +3 -0
  38. package/graphql/baseSchema.js +117 -0
  39. package/graphql/baseSchema.js.map +1 -0
  40. package/graphql/createFilesTypeDefs.d.ts +7 -0
  41. package/graphql/createFilesTypeDefs.js +162 -0
  42. package/graphql/createFilesTypeDefs.js.map +1 -0
  43. package/graphql/filesSchema.d.ts +4 -0
  44. package/graphql/filesSchema.js +83 -0
  45. package/graphql/filesSchema.js.map +1 -0
  46. package/graphql/index.d.ts +2 -2
  47. package/graphql/index.js +23 -278
  48. package/graphql/index.js.map +1 -1
  49. package/graphql/utils.d.ts +11 -0
  50. package/graphql/utils.js +22 -0
  51. package/graphql/utils.js.map +1 -0
  52. package/handlers/download/byAlias.js +9 -9
  53. package/handlers/download/byAlias.js.map +1 -1
  54. package/handlers/download/byExactKey.js +9 -9
  55. package/handlers/download/byExactKey.js.map +1 -1
  56. package/handlers/download/extractFileInformation.js.map +1 -1
  57. package/handlers/download/getS3Object.d.ts +2 -0
  58. package/handlers/download/getS3Object.js +39 -24
  59. package/handlers/download/getS3Object.js.map +1 -1
  60. package/handlers/download/index.js.map +1 -1
  61. package/handlers/manage/index.js.map +1 -1
  62. package/handlers/transform/index.js +5 -2
  63. package/handlers/transform/index.js.map +1 -1
  64. package/handlers/transform/legacyUtils.js.map +1 -1
  65. package/handlers/transform/loaders/imageLoader.js.map +1 -1
  66. package/handlers/transform/loaders/index.js.map +1 -1
  67. package/handlers/transform/loaders/sanitizeImageTransformations.js.map +1 -1
  68. package/handlers/transform/managers/imageManager.js.map +1 -1
  69. package/handlers/transform/managers/index.js.map +1 -1
  70. package/handlers/transform/optimizeImage.js.map +1 -1
  71. package/handlers/transform/transformImage.d.ts +5 -2
  72. package/handlers/transform/transformImage.js +7 -4
  73. package/handlers/transform/transformImage.js.map +1 -1
  74. package/handlers/transform/utils.js +2 -2
  75. package/handlers/transform/utils.js.map +1 -1
  76. package/handlers/utils/getEnvironment.js.map +1 -1
  77. package/handlers/utils/getObjectParams.js.map +1 -1
  78. package/handlers/utils/index.js.map +1 -1
  79. package/index.d.ts +3 -2
  80. package/index.js +20 -36
  81. package/index.js.map +1 -1
  82. package/modelModifier/CmsModelModifier.d.ts +24 -0
  83. package/modelModifier/CmsModelModifier.js +59 -0
  84. package/modelModifier/CmsModelModifier.js.map +1 -0
  85. package/package.json +26 -25
  86. package/plugins/FilePhysicalStoragePlugin.js.map +1 -1
  87. package/plugins/FileStorageTransformPlugin.js.map +1 -1
  88. package/plugins/index.js.map +1 -1
  89. package/storage/FileStorage.d.ts +2 -1
  90. package/storage/FileStorage.js +5 -4
  91. package/storage/FileStorage.js.map +1 -1
  92. package/types/file.d.ts +5 -1
  93. package/types/file.js.map +1 -1
  94. package/types.d.ts +16 -26
  95. package/types.js.map +1 -1
  96. package/createFileManager/checkBasePermissions.d.ts +0 -5
  97. package/createFileManager/checkBasePermissions.js +0 -24
  98. package/createFileManager/checkBasePermissions.js.map +0 -1
@@ -0,0 +1,13 @@
1
+ import { FileManagerContext } from "./types";
2
+ import { FileManagerConfig } from "./createFileManager";
3
+ export declare class FileManagerContextSetup {
4
+ private readonly context;
5
+ constructor(context: FileManagerContext);
6
+ setupContext(storageOperations: FileManagerConfig["storageOperations"]): Promise<import("./types").FileManagerContextObject>;
7
+ private getLocaleCode;
8
+ private getIdentity;
9
+ private getTenantId;
10
+ private getPermissions;
11
+ private setupCmsStorageOperations;
12
+ private getModel;
13
+ }
@@ -0,0 +1,113 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.FileManagerContextSetup = void 0;
8
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
9
+ var _createFileManager = require("./createFileManager");
10
+ var _FileStorage = require("./storage/FileStorage");
11
+ var _error = _interopRequireDefault(require("@webiny/error"));
12
+ var _isInstallationPending = require("./cmsFileStorage/isInstallationPending");
13
+ var _createFileManagerPlugins = require("./cmsFileStorage/createFileManagerPlugins");
14
+ var _file = require("./cmsFileStorage/file.model");
15
+ var _CmsFilesStorage = require("./cmsFileStorage/CmsFilesStorage");
16
+ var _CmsModelModifier = require("./modelModifier/CmsModelModifier");
17
+ var _apiHeadlessCms = require("@webiny/api-headless-cms");
18
+ var _FilesPermissions = require("./createFileManager/permissions/FilesPermissions");
19
+ class FileManagerContextSetup {
20
+ constructor(context) {
21
+ (0, _defineProperty2.default)(this, "context", void 0);
22
+ this.context = context;
23
+ }
24
+ async setupContext(storageOperations) {
25
+ if (storageOperations.beforeInit) {
26
+ await storageOperations.beforeInit(this.context);
27
+ }
28
+ const fileStorageOps = await this.context.security.withoutAuthorization(() => {
29
+ return this.setupCmsStorageOperations(storageOperations.aliases);
30
+ });
31
+ if (fileStorageOps) {
32
+ storageOperations.files = fileStorageOps;
33
+ }
34
+ const filesPermissions = new _FilesPermissions.FilesPermissions({
35
+ getIdentity: this.context.security.getIdentity,
36
+ getPermissions: () => this.context.security.getPermissions("fm.file"),
37
+ fullAccessPermissionName: "fm.*"
38
+ });
39
+ return (0, _createFileManager.createFileManager)({
40
+ storageOperations,
41
+ filesPermissions,
42
+ getTenantId: this.getTenantId.bind(this),
43
+ getLocaleCode: this.getLocaleCode.bind(this),
44
+ getIdentity: this.getIdentity.bind(this),
45
+ getPermissions: this.getPermissions.bind(this),
46
+ storage: new _FileStorage.FileStorage({
47
+ context: this.context
48
+ }),
49
+ // TODO: maybe this is no longer necessary, as this wil be managed by CMS?
50
+ WEBINY_VERSION: this.context.WEBINY_VERSION
51
+ });
52
+ }
53
+ getLocaleCode() {
54
+ const locale = this.context.i18n.getContentLocale();
55
+ if (!locale) {
56
+ throw new _error.default("Missing locale on context.i18n locale in File Manager API.", "LOCALE_ERROR");
57
+ }
58
+ return locale.code;
59
+ }
60
+ getIdentity() {
61
+ return this.context.security.getIdentity();
62
+ }
63
+ getTenantId() {
64
+ return this.context.tenancy.getCurrentTenant().id;
65
+ }
66
+ async getPermissions(name) {
67
+ return this.context.security.getPermissions(name);
68
+ }
69
+ async setupCmsStorageOperations(aliases) {
70
+ if ((0, _isInstallationPending.isInstallationPending)({
71
+ tenancy: this.context.tenancy,
72
+ i18n: this.context.i18n
73
+ })) {
74
+ console.log("Installation pending!");
75
+ return;
76
+ }
77
+
78
+ // This registers code plugins (model group, models)
79
+ const {
80
+ groupPlugin,
81
+ fileModelDefinition
82
+ } = (0, _createFileManagerPlugins.createFileManagerPlugins)();
83
+ const modelModifiers = this.context.plugins.byType(_CmsModelModifier.CmsModelModifierPlugin.type);
84
+ for (const modifier of modelModifiers) {
85
+ await modifier.modifyModel(fileModelDefinition);
86
+ }
87
+
88
+ // Finally, register all plugins
89
+ this.context.plugins.register([groupPlugin, new _apiHeadlessCms.CmsModelPlugin(fileModelDefinition)]);
90
+
91
+ // Now load the file model registered in the previous step
92
+ const fileModel = await this.getModel(_file.FILE_MODEL_ID);
93
+
94
+ // Overwrite the original `files` storage ops
95
+ return await _CmsFilesStorage.CmsFilesStorage.create({
96
+ fileModel,
97
+ cms: this.context.cms,
98
+ security: this.context.security,
99
+ aliases
100
+ });
101
+ }
102
+ async getModel(modelId) {
103
+ const model = await this.context.cms.getModel(modelId);
104
+ if (!model) {
105
+ throw new _error.default({
106
+ code: "MODEL_NOT_FOUND",
107
+ message: `Content model "${modelId}" was not found!`
108
+ });
109
+ }
110
+ return model;
111
+ }
112
+ }
113
+ exports.FileManagerContextSetup = FileManagerContextSetup;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_createFileManager","require","_FileStorage","_error","_interopRequireDefault","_isInstallationPending","_createFileManagerPlugins","_file","_CmsFilesStorage","_CmsModelModifier","_apiHeadlessCms","_FilesPermissions","FileManagerContextSetup","constructor","context","_defineProperty2","default","setupContext","storageOperations","beforeInit","fileStorageOps","security","withoutAuthorization","setupCmsStorageOperations","aliases","files","filesPermissions","FilesPermissions","getIdentity","getPermissions","fullAccessPermissionName","createFileManager","getTenantId","bind","getLocaleCode","storage","FileStorage","WEBINY_VERSION","locale","i18n","getContentLocale","WebinyError","code","tenancy","getCurrentTenant","id","name","isInstallationPending","console","log","groupPlugin","fileModelDefinition","createFileManagerPlugins","modelModifiers","plugins","byType","CmsModelModifierPlugin","type","modifier","modifyModel","register","CmsModelPlugin","fileModel","getModel","FILE_MODEL_ID","CmsFilesStorage","create","cms","modelId","model","message","exports"],"sources":["FileManagerContextSetup.ts"],"sourcesContent":["import { FileManagerAliasesStorageOperations, FileManagerContext } from \"~/types\";\nimport { createFileManager, FileManagerConfig } from \"~/createFileManager\";\nimport { FileStorage } from \"~/storage/FileStorage\";\nimport WebinyError from \"@webiny/error\";\nimport { SecurityPermission } from \"@webiny/api-security/types\";\nimport { isInstallationPending } from \"~/cmsFileStorage/isInstallationPending\";\nimport { createFileManagerPlugins } from \"~/cmsFileStorage/createFileManagerPlugins\";\nimport { FILE_MODEL_ID } from \"~/cmsFileStorage/file.model\";\nimport { CmsFilesStorage } from \"~/cmsFileStorage/CmsFilesStorage\";\nimport { CmsModelModifierPlugin } from \"~/modelModifier/CmsModelModifier\";\nimport { CmsModelPlugin } from \"@webiny/api-headless-cms\";\nimport { FilesPermissions } from \"~/createFileManager/permissions/FilesPermissions\";\n\nexport class FileManagerContextSetup {\n private readonly context: FileManagerContext;\n\n constructor(context: FileManagerContext) {\n this.context = context;\n }\n\n async setupContext(storageOperations: FileManagerConfig[\"storageOperations\"]) {\n if (storageOperations.beforeInit) {\n await storageOperations.beforeInit(this.context);\n }\n\n const fileStorageOps = await this.context.security.withoutAuthorization(() => {\n return this.setupCmsStorageOperations(storageOperations.aliases);\n });\n\n if (fileStorageOps) {\n storageOperations.files = fileStorageOps;\n }\n\n const filesPermissions = new FilesPermissions({\n getIdentity: this.context.security.getIdentity,\n getPermissions: () => this.context.security.getPermissions(\"fm.file\"),\n fullAccessPermissionName: \"fm.*\"\n });\n\n return createFileManager({\n storageOperations,\n filesPermissions,\n getTenantId: this.getTenantId.bind(this),\n getLocaleCode: this.getLocaleCode.bind(this),\n getIdentity: this.getIdentity.bind(this),\n getPermissions: this.getPermissions.bind(this),\n storage: new FileStorage({\n context: this.context\n }),\n // TODO: maybe this is no longer necessary, as this wil be managed by CMS?\n WEBINY_VERSION: this.context.WEBINY_VERSION\n });\n }\n\n private getLocaleCode() {\n const locale = this.context.i18n.getContentLocale();\n if (!locale) {\n throw new WebinyError(\n \"Missing locale on context.i18n locale in File Manager API.\",\n \"LOCALE_ERROR\"\n );\n }\n return locale.code;\n }\n\n private getIdentity() {\n return this.context.security.getIdentity();\n }\n\n private getTenantId() {\n return this.context.tenancy.getCurrentTenant().id;\n }\n\n private async getPermissions<T extends SecurityPermission = SecurityPermission>(\n name: string\n ): Promise<T[]> {\n return this.context.security.getPermissions(name);\n }\n\n private async setupCmsStorageOperations(aliases: FileManagerAliasesStorageOperations) {\n if (isInstallationPending({ tenancy: this.context.tenancy, i18n: this.context.i18n })) {\n console.log(\"Installation pending!\");\n return;\n }\n\n // This registers code plugins (model group, models)\n const { groupPlugin, fileModelDefinition } = createFileManagerPlugins();\n\n const modelModifiers = this.context.plugins.byType<CmsModelModifierPlugin>(\n CmsModelModifierPlugin.type\n );\n\n for (const modifier of modelModifiers) {\n await modifier.modifyModel(fileModelDefinition);\n }\n\n // Finally, register all plugins\n this.context.plugins.register([groupPlugin, new CmsModelPlugin(fileModelDefinition)]);\n\n // Now load the file model registered in the previous step\n const fileModel = await this.getModel(FILE_MODEL_ID);\n\n // Overwrite the original `files` storage ops\n return await CmsFilesStorage.create({\n fileModel,\n cms: this.context.cms,\n security: this.context.security,\n aliases\n });\n }\n\n private async getModel(modelId: string) {\n const model = await this.context.cms.getModel(modelId);\n if (!model) {\n throw new WebinyError({\n code: \"MODEL_NOT_FOUND\",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AAK,CAAC,CAAC,EAAE;MACnFS,OAAO,CAACC,GAAG,CAAC,uBAAuB,CAAC;MACpC;IACJ;;IAEA;IACA,MAAM;MAAEC,WAAW;MAAEC;IAAoB,CAAC,GAAG,IAAAC,kDAAwB,EAAC,CAAC;IAEvE,MAAMC,cAAc,GAAG,IAAI,CAACvC,OAAO,CAACwC,OAAO,CAACC,MAAM,CAC9CC,wCAAsB,CAACC,IAC3B,CAAC;IAED,KAAK,MAAMC,QAAQ,IAAIL,cAAc,EAAE;MACnC,MAAMK,QAAQ,CAACC,WAAW,CAACR,mBAAmB,CAAC;IACnD;;IAEA;IACA,IAAI,CAACrC,OAAO,CAACwC,OAAO,CAACM,QAAQ,CAAC,CAACV,WAAW,EAAE,IAAIW,8BAAc,CAACV,mBAAmB,CAAC,CAAC,CAAC;;IAErF;IACA,MAAMW,SAAS,GAAG,MAAM,IAAI,CAACC,QAAQ,CAACC,mBAAa,CAAC;;IAEpD;IACA,OAAO,MAAMC,gCAAe,CAACC,MAAM,CAAC;MAChCJ,SAAS;MACTK,GAAG,EAAE,IAAI,CAACrD,OAAO,CAACqD,GAAG;MACrB9C,QAAQ,EAAE,IAAI,CAACP,OAAO,CAACO,QAAQ;MAC/BG;IACJ,CAAC,CAAC;EACN;EAEA,MAAcuC,QAAQA,CAACK,OAAe,EAAE;IACpC,MAAMC,KAAK,GAAG,MAAM,IAAI,CAACvD,OAAO,CAACqD,GAAG,CAACJ,QAAQ,CAACK,OAAO,CAAC;IACtD,IAAI,CAACC,KAAK,EAAE;MACR,MAAM,IAAI5B,cAAW,CAAC;QAClBC,IAAI,EAAE,iBAAiB;QACvB4B,OAAO,EAAG,kBAAiBF,OAAQ;MACvC,CAAC,CAAC;IACN;IAEA,OAAOC,KAAK;EAChB;AACJ;AAACE,OAAA,CAAA3D,uBAAA,GAAAA,uBAAA"}
@@ -0,0 +1,27 @@
1
+ import { CmsModel, HeadlessCms } from "@webiny/api-headless-cms/types";
2
+ import { Security } from "@webiny/api-security/types";
3
+ import { File, FileManagerAliasesStorageOperations, FileManagerFilesStorageOperations, FileManagerFilesStorageOperationsCreateBatchParams, FileManagerFilesStorageOperationsCreateParams, FileManagerFilesStorageOperationsDeleteParams, FileManagerFilesStorageOperationsGetParams, FileManagerFilesStorageOperationsListParams, FileManagerFilesStorageOperationsListResponse, FileManagerFilesStorageOperationsTagsParams, FileManagerFilesStorageOperationsTagsResponse, FileManagerFilesStorageOperationsUpdateParams } from "../types";
4
+ export declare class CmsFilesStorage implements FileManagerFilesStorageOperations {
5
+ private readonly cms;
6
+ private readonly security;
7
+ private readonly model;
8
+ private readonly aliases;
9
+ private readonly filesWhereProcessor;
10
+ private readonly tagsWhereProcessor;
11
+ static create(params: {
12
+ fileModel: CmsModel;
13
+ cms: HeadlessCms;
14
+ security: Security;
15
+ aliases: FileManagerAliasesStorageOperations;
16
+ }): Promise<CmsFilesStorage>;
17
+ private constructor();
18
+ private modelWithContext;
19
+ create({ file }: FileManagerFilesStorageOperationsCreateParams): Promise<File>;
20
+ createBatch({ files }: FileManagerFilesStorageOperationsCreateBatchParams): Promise<File[]>;
21
+ delete({ file }: FileManagerFilesStorageOperationsDeleteParams): Promise<void>;
22
+ get({ where }: FileManagerFilesStorageOperationsGetParams): Promise<File | null>;
23
+ list(params: FileManagerFilesStorageOperationsListParams): Promise<FileManagerFilesStorageOperationsListResponse>;
24
+ tags(params: FileManagerFilesStorageOperationsTagsParams): Promise<FileManagerFilesStorageOperationsTagsResponse[]>;
25
+ update({ file }: FileManagerFilesStorageOperationsUpdateParams): Promise<File>;
26
+ private getFileFieldValues;
27
+ }
@@ -0,0 +1,173 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.CmsFilesStorage = void 0;
8
+ var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
9
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
10
+ var _omit = _interopRequireDefault(require("lodash/omit"));
11
+ var _ListFilesWhereProcessor = require("./ListFilesWhereProcessor");
12
+ var _ListTagsWhereProcessor = require("./ListTagsWhereProcessor");
13
+ var _contants = require("../contants");
14
+ class CmsFilesStorage {
15
+ static async create(params) {
16
+ return new CmsFilesStorage(params.fileModel, params.cms, params.security, params.aliases);
17
+ }
18
+ constructor(fileModel, cms, security, aliases) {
19
+ (0, _defineProperty2.default)(this, "cms", void 0);
20
+ (0, _defineProperty2.default)(this, "security", void 0);
21
+ (0, _defineProperty2.default)(this, "model", void 0);
22
+ (0, _defineProperty2.default)(this, "aliases", void 0);
23
+ (0, _defineProperty2.default)(this, "filesWhereProcessor", void 0);
24
+ (0, _defineProperty2.default)(this, "tagsWhereProcessor", void 0);
25
+ this.model = fileModel;
26
+ this.aliases = aliases;
27
+ this.cms = cms;
28
+ this.security = security;
29
+ this.filesWhereProcessor = new _ListFilesWhereProcessor.ListFilesWhereProcessor();
30
+ this.tagsWhereProcessor = new _ListTagsWhereProcessor.ListTagsWhereProcessor();
31
+ }
32
+ modelWithContext({
33
+ tenant,
34
+ locale
35
+ }) {
36
+ return (0, _objectSpread2.default)((0, _objectSpread2.default)({}, this.model), {}, {
37
+ tenant,
38
+ locale
39
+ });
40
+ }
41
+ async create({
42
+ file
43
+ }) {
44
+ var _file$location;
45
+ const model = this.modelWithContext(file);
46
+ if (!((_file$location = file.location) !== null && _file$location !== void 0 && _file$location.folderId)) {
47
+ file.location = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, file.location), {}, {
48
+ folderId: _contants.ROOT_FOLDER
49
+ });
50
+ }
51
+ const entry = await this.security.withoutAuthorization(() => {
52
+ return this.cms.createEntry(model, (0, _objectSpread2.default)((0, _objectSpread2.default)({}, file), {}, {
53
+ wbyAco_location: file.location
54
+ }));
55
+ });
56
+ await this.aliases.storeAliases(file);
57
+ return this.getFileFieldValues(entry);
58
+ }
59
+ async createBatch({
60
+ files
61
+ }) {
62
+ return await Promise.all(files.map(file => {
63
+ return this.create({
64
+ file
65
+ });
66
+ }));
67
+ }
68
+ async delete({
69
+ file
70
+ }) {
71
+ const model = this.modelWithContext(file);
72
+ await this.security.withoutAuthorization(() => {
73
+ return this.cms.deleteEntry(model, file.id);
74
+ });
75
+ await this.aliases.deleteAliases(file);
76
+ }
77
+ async get({
78
+ where
79
+ }) {
80
+ const {
81
+ id,
82
+ tenant,
83
+ locale
84
+ } = where;
85
+ const model = this.modelWithContext({
86
+ tenant,
87
+ locale
88
+ });
89
+ const entry = await this.security.withoutAuthorization(() => {
90
+ return this.cms.getEntry(model, {
91
+ where: {
92
+ entryId: id,
93
+ latest: true
94
+ }
95
+ });
96
+ });
97
+ return entry ? this.getFileFieldValues(entry) : null;
98
+ }
99
+ async list(params) {
100
+ const tenant = params.where.tenant;
101
+ const locale = params.where.locale;
102
+ const model = this.modelWithContext({
103
+ tenant,
104
+ locale
105
+ });
106
+ const [entries, meta] = await this.security.withoutAuthorization(() => {
107
+ const where = this.filesWhereProcessor.process(params.where);
108
+ return this.cms.listLatestEntries(model, {
109
+ after: params.after,
110
+ limit: params.limit,
111
+ sort: params.sort,
112
+ where,
113
+ search: params.search
114
+ });
115
+ });
116
+ return [entries.map(entry => this.getFileFieldValues(entry)), meta];
117
+ }
118
+ async tags(params) {
119
+ const tenant = params.where.tenant;
120
+ const locale = params.where.locale;
121
+ const model = this.modelWithContext({
122
+ tenant,
123
+ locale
124
+ });
125
+ const uniqueValues = await this.security.withoutAuthorization(() => {
126
+ return this.cms.getUniqueFieldValues(model, {
127
+ fieldId: "tags",
128
+ where: (0, _objectSpread2.default)((0, _objectSpread2.default)({}, this.tagsWhereProcessor.process(params.where)), {}, {
129
+ latest: true
130
+ })
131
+ });
132
+ });
133
+ return uniqueValues.map(uv => ({
134
+ tag: uv.value,
135
+ count: uv.count
136
+ })).sort((a, b) => {
137
+ return a.tag < b.tag ? -1 : 1;
138
+ }).sort((a, b) => {
139
+ return a.count > b.count ? -1 : 1;
140
+ });
141
+ }
142
+ async update({
143
+ file
144
+ }) {
145
+ const model = this.modelWithContext(file);
146
+ return await this.security.withoutAuthorization(async () => {
147
+ const entry = await this.cms.getEntry(model, {
148
+ where: {
149
+ entryId: file.id,
150
+ latest: true
151
+ }
152
+ });
153
+ const values = (0, _omit.default)(file, ["id", "createdOn", "createdBy", "tenant", "locale", "webinyVersion"]);
154
+ const updatedEntry = await this.cms.updateEntry(model, entry.id, (0, _objectSpread2.default)((0, _objectSpread2.default)({}, values), {}, {
155
+ wbyAco_location: values.location ?? entry.location
156
+ }));
157
+ await this.aliases.storeAliases(file);
158
+ return this.getFileFieldValues(updatedEntry);
159
+ });
160
+ }
161
+ getFileFieldValues(entry) {
162
+ return (0, _objectSpread2.default)({
163
+ id: entry.entryId,
164
+ createdBy: entry.createdBy,
165
+ createdOn: entry.createdOn,
166
+ savedOn: entry.savedOn,
167
+ locale: entry.locale,
168
+ tenant: entry.tenant,
169
+ webinyVersion: entry.webinyVersion
170
+ }, entry.values);
171
+ }
172
+ }
173
+ exports.CmsFilesStorage = CmsFilesStorage;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_omit","_interopRequireDefault","require","_ListFilesWhereProcessor","_ListTagsWhereProcessor","_contants","CmsFilesStorage","create","params","fileModel","cms","security","aliases","constructor","_defineProperty2","default","model","filesWhereProcessor","ListFilesWhereProcessor","tagsWhereProcessor","ListTagsWhereProcessor","modelWithContext","tenant","locale","_objectSpread2","file","_file$location","location","folderId","ROOT_FOLDER","entry","withoutAuthorization","createEntry","wbyAco_location","storeAliases","getFileFieldValues","createBatch","files","Promise","all","map","delete","deleteEntry","id","deleteAliases","get","where","getEntry","entryId","latest","list","entries","meta","process","listLatestEntries","after","limit","sort","search","tags","uniqueValues","getUniqueFieldValues","fieldId","uv","tag","value","count","a","b","update","values","omit","updatedEntry","updateEntry","createdBy","createdOn","savedOn","webinyVersion","exports"],"sources":["CmsFilesStorage.ts"],"sourcesContent":["import omit from \"lodash/omit\";\nimport { CmsEntry, CmsModel, HeadlessCms } from \"@webiny/api-headless-cms/types\";\nimport { Security } from \"@webiny/api-security/types\";\nimport {\n File,\n FileManagerAliasesStorageOperations,\n FileManagerFilesStorageOperations,\n FileManagerFilesStorageOperationsCreateBatchParams,\n FileManagerFilesStorageOperationsCreateParams,\n FileManagerFilesStorageOperationsDeleteParams,\n FileManagerFilesStorageOperationsGetParams,\n FileManagerFilesStorageOperationsListParams,\n FileManagerFilesStorageOperationsListResponse,\n FileManagerFilesStorageOperationsTagsParams,\n FileManagerFilesStorageOperationsTagsResponse,\n FileManagerFilesStorageOperationsUpdateParams\n} from \"~/types\";\nimport { ListFilesWhereProcessor } from \"~/cmsFileStorage/ListFilesWhereProcessor\";\nimport { ListTagsWhereProcessor } from \"~/cmsFileStorage/ListTagsWhereProcessor\";\nimport { ROOT_FOLDER } from \"~/contants\";\n\ninterface ModelContext {\n tenant: string;\n locale: string;\n}\n\nexport class CmsFilesStorage implements FileManagerFilesStorageOperations {\n private readonly cms: HeadlessCms;\n private readonly security: Security;\n private readonly model: CmsModel;\n private readonly aliases: FileManagerAliasesStorageOperations;\n private readonly filesWhereProcessor: ListFilesWhereProcessor;\n private readonly tagsWhereProcessor: ListTagsWhereProcessor;\n\n static async create(params: {\n fileModel: CmsModel;\n cms: HeadlessCms;\n security: Security;\n aliases: FileManagerAliasesStorageOperations;\n }) {\n return new CmsFilesStorage(params.fileModel, params.cms, params.security, params.aliases);\n }\n\n private constructor(\n fileModel: CmsModel,\n cms: HeadlessCms,\n security: Security,\n aliases: FileManagerAliasesStorageOperations\n ) {\n this.model = fileModel;\n this.aliases = aliases;\n this.cms = cms;\n this.security = security;\n this.filesWhereProcessor = new ListFilesWhereProcessor();\n this.tagsWhereProcessor = new ListTagsWhereProcessor();\n }\n\n private modelWithContext({ tenant, locale }: ModelContext): CmsModel {\n return { ...this.model, tenant, locale };\n }\n\n async create({ file }: FileManagerFilesStorageOperationsCreateParams): Promise<File> {\n const model = this.modelWithContext(file);\n\n if (!file.location?.folderId) {\n file.location = {\n ...file.location,\n folderId: ROOT_FOLDER\n };\n }\n\n const entry = await this.security.withoutAuthorization(() => {\n return this.cms.createEntry(model, { ...file, wbyAco_location: file.location });\n });\n\n await this.aliases.storeAliases(file);\n\n return this.getFileFieldValues(entry);\n }\n\n async createBatch({\n files\n }: FileManagerFilesStorageOperationsCreateBatchParams): Promise<File[]> {\n return await Promise.all(\n files.map(file => {\n return this.create({ file });\n })\n );\n }\n\n async delete({ file }: FileManagerFilesStorageOperationsDeleteParams): Promise<void> {\n const model = this.modelWithContext(file);\n await this.security.withoutAuthorization(() => {\n return this.cms.deleteEntry(model, file.id);\n });\n\n await this.aliases.deleteAliases(file);\n }\n\n async get({ where }: FileManagerFilesStorageOperationsGetParams): Promise<File | null> {\n const { id, tenant, locale } = where;\n const model = this.modelWithContext({ tenant, locale });\n const entry = await this.security.withoutAuthorization(() => {\n return this.cms.getEntry(model, { where: { entryId: id, latest: true } });\n });\n return entry ? this.getFileFieldValues(entry) : null;\n }\n\n async list(\n params: FileManagerFilesStorageOperationsListParams\n ): Promise<FileManagerFilesStorageOperationsListResponse> {\n const tenant = params.where.tenant;\n const locale = params.where.locale;\n\n const model = this.modelWithContext({ tenant, locale });\n const [entries, meta] = await this.security.withoutAuthorization(() => {\n const where = this.filesWhereProcessor.process(params.where);\n return this.cms.listLatestEntries(model, {\n after: params.after,\n limit: params.limit,\n sort: params.sort,\n where,\n search: params.search\n });\n });\n\n return [entries.map(entry => this.getFileFieldValues(entry)), meta];\n }\n\n async tags(\n params: FileManagerFilesStorageOperationsTagsParams\n ): Promise<FileManagerFilesStorageOperationsTagsResponse[]> {\n const tenant = params.where.tenant;\n const locale = params.where.locale;\n const model = this.modelWithContext({ tenant, locale });\n const uniqueValues = await this.security.withoutAuthorization(() => {\n return this.cms.getUniqueFieldValues(model, {\n fieldId: \"tags\",\n where: {\n ...this.tagsWhereProcessor.process(params.where),\n latest: true\n }\n });\n });\n\n return uniqueValues\n .map(uv => ({\n tag: uv.value,\n count: uv.count\n }))\n .sort((a, b) => {\n return a.tag < b.tag ? -1 : 1;\n })\n .sort((a, b) => {\n return a.count > b.count ? -1 : 1;\n });\n }\n\n async update({ file }: FileManagerFilesStorageOperationsUpdateParams): Promise<File> {\n const model = this.modelWithContext(file);\n\n return await this.security.withoutAuthorization(async () => {\n const entry = await this.cms.getEntry(model, {\n where: { entryId: file.id, latest: true }\n });\n\n const values = omit(file, [\n \"id\",\n \"createdOn\",\n \"createdBy\",\n \"tenant\",\n \"locale\",\n \"webinyVersion\"\n ]);\n\n const updatedEntry = await this.cms.updateEntry(model, entry.id, {\n ...values,\n wbyAco_location: values.location ?? entry.location\n });\n\n await this.aliases.storeAliases(file);\n\n return this.getFileFieldValues(updatedEntry);\n });\n }\n\n private getFileFieldValues(entry: CmsEntry) {\n return {\n id: entry.entryId,\n createdBy: entry.createdBy,\n createdOn: entry.createdOn,\n savedOn: entry.savedOn,\n locale: entry.locale,\n tenant: entry.tenant,\n webinyVersion: entry.webinyVersion,\n ...entry.values\n } as File;\n }\n}\n"],"mappings":";;;;;;;;;AAAA,IAAAA,KAAA,GAAAC,sBAAA,CAAAC,OAAA;AAiBA,IAAAC,wBAAA,GAAAD,OAAA;AACA,IAAAE,uBAAA,GAAAF,OAAA;AACA,IAAAG,SAAA,GAAAH,OAAA;AAOO,MAAMI,eAAe,CAA8C;EAQtE,aAAaC,MAAMA,CAACC,MAKnB,EAAE;IACC,OAAO,IAAIF,eAAe,CAACE,MAAM,CAACC,SAAS,EAAED,MAAM,CAACE,GAAG,EAAEF,MAAM,CAACG,QAAQ,EAAEH,MAAM,CAACI,OAAO,CAAC;EAC7F;EAEQC,WAAWA,CACfJ,SAAmB,EACnBC,GAAgB,EAChBC,QAAkB,EAClBC,OAA4C,EAC9C;IAAA,IAAAE,gBAAA,CAAAC,OAAA;IAAA,IAAAD,gBAAA,CAAAC,OAAA;IAAA,IAAAD,gBAAA,CAAAC,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EF,MAAM+C,YAAY,GAAG,MAAM,IAAI,CAAC9D,GAAG,CAAC+D,WAAW,CAACzD,KAAK,EAAEc,KAAK,CAACa,EAAE,MAAAnB,cAAA,CAAAT,OAAA,MAAAS,cAAA,CAAAT,OAAA,MACxDuD,MAAM;QACTrC,eAAe,EAAEqC,MAAM,CAAC3C,QAAQ,IAAIG,KAAK,CAACH;MAAQ,EACrD,CAAC;MAEF,MAAM,IAAI,CAACf,OAAO,CAACsB,YAAY,CAACT,IAAI,CAAC;MAErC,OAAO,IAAI,CAACU,kBAAkB,CAACqC,YAAY,CAAC;IAChD,CAAC,CAAC;EACN;EAEQrC,kBAAkBA,CAACL,KAAe,EAAE;IACxC,WAAAN,cAAA,CAAAT,OAAA;MACI4B,EAAE,EAAEb,KAAK,CAACkB,OAAO;MACjB0B,SAAS,EAAE5C,KAAK,CAAC4C,SAAS;MAC1BC,SAAS,EAAE7C,KAAK,CAAC6C,SAAS;MAC1BC,OAAO,EAAE9C,KAAK,CAAC8C,OAAO;MACtBrD,MAAM,EAAEO,KAAK,CAACP,MAAM;MACpBD,MAAM,EAAEQ,KAAK,CAACR,MAAM;MACpBuD,aAAa,EAAE/C,KAAK,CAAC+C;IAAa,GAC/B/C,KAAK,CAACwC,MAAM;EAEvB;AACJ;AAACQ,OAAA,CAAAxE,eAAA,GAAAA,eAAA"}
@@ -0,0 +1,7 @@
1
+ import { CmsEntryListWhere } from "@webiny/api-headless-cms/types";
2
+ import { FileManagerFilesStorageOperationsListParamsWhere } from "../types";
3
+ export declare class ListFilesWhereProcessor {
4
+ private readonly skipKeys;
5
+ private readonly keyMap;
6
+ process(input: FileManagerFilesStorageOperationsListParamsWhere): CmsEntryListWhere;
7
+ }
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.ListFilesWhereProcessor = void 0;
8
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
9
+ class ListFilesWhereProcessor {
10
+ constructor() {
11
+ (0, _defineProperty2.default)(this, "skipKeys", ["tenant", "locale"]);
12
+ (0, _defineProperty2.default)(this, "keyMap", {
13
+ id: "entryId",
14
+ id_in: "entryId_in"
15
+ });
16
+ }
17
+ process(input) {
18
+ const where = {
19
+ meta: {
20
+ private_not: true
21
+ }
22
+ };
23
+ Object.keys(input).filter(key => !this.skipKeys.includes(key)).forEach(key => {
24
+ const remappedKey = this.keyMap[key];
25
+ const value = input[key];
26
+ if (remappedKey && value !== undefined) {
27
+ where[remappedKey] = value;
28
+ } else if (value !== undefined) {
29
+ where[key] = value;
30
+ }
31
+ });
32
+ return where;
33
+ }
34
+ }
35
+ exports.ListFilesWhereProcessor = ListFilesWhereProcessor;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["ListFilesWhereProcessor","constructor","_defineProperty2","default","id","id_in","process","input","where","meta","private_not","Object","keys","filter","key","skipKeys","includes","forEach","remappedKey","keyMap","value","undefined","exports"],"sources":["ListFilesWhereProcessor.ts"],"sourcesContent":["import { CmsEntryListWhere } from \"@webiny/api-headless-cms/types\";\nimport { FileManagerFilesStorageOperationsListParamsWhere } from \"~/types\";\n\ntype StandardFileKey = keyof FileManagerFilesStorageOperationsListParamsWhere;\ntype CmsEntryListWhereKey = keyof CmsEntryListWhere;\n\nexport class ListFilesWhereProcessor {\n private readonly skipKeys = [\"tenant\", \"locale\"];\n private readonly keyMap: Partial<Record<StandardFileKey, CmsEntryListWhereKey>> = {\n id: \"entryId\",\n id_in: \"entryId_in\"\n };\n\n process(input: FileManagerFilesStorageOperationsListParamsWhere): CmsEntryListWhere {\n const where: CmsEntryListWhere = { meta: { private_not: true } };\n\n Object.keys(input)\n .filter(key => !this.skipKeys.includes(key))\n .forEach(key => {\n const remappedKey = this.keyMap[key];\n const value = input[key];\n\n if (remappedKey && value !== undefined) {\n where[remappedKey] = value;\n } else if (value !== undefined) {\n where[key] = value;\n }\n });\n\n return where;\n }\n}\n"],"mappings":";;;;;;;;AAMO,MAAMA,uBAAuB,CAAC;EAAAC,YAAA;IAAA,IAAAC,gBAAA,CAAAC,OAAA,oBACL,CAAC,QAAQ,EAAE,QAAQ,CAAC;IAAA,IAAAD,gBAAA,CAAAC,OAAA,kBACkC;MAC9EC,EAAE,EAAE,SAAS;MACbC,KAAK,EAAE;IACX,CAAC;EAAA;EAEDC,OAAOA,CAACC,KAAuD,EAAqB;IAChF,MAAMC,KAAwB,GAAG;MAAEC,IAAI,EAAE;QAAEC,WAAW,EAAE;MAAK;IAAE,CAAC;IAEhEC,MAAM,CAACC,IAAI,CAACL,KAAK,CAAC,CACbM,MAAM,CAACC,GAAG,IAAI,CAAC,IAAI,CAACC,QAAQ,CAACC,QAAQ,CAACF,GAAG,CAAC,CAAC,CAC3CG,OAAO,CAACH,GAAG,IAAI;MACZ,MAAMI,WAAW,GAAG,IAAI,CAACC,MAAM,CAACL,GAAG,CAAC;MACpC,MAAMM,KAAK,GAAGb,KAAK,CAACO,GAAG,CAAC;MAExB,IAAII,WAAW,IAAIE,KAAK,KAAKC,SAAS,EAAE;QACpCb,KAAK,CAACU,WAAW,CAAC,GAAGE,KAAK;MAC9B,CAAC,MAAM,IAAIA,KAAK,KAAKC,SAAS,EAAE;QAC5Bb,KAAK,CAACM,GAAG,CAAC,GAAGM,KAAK;MACtB;IACJ,CAAC,CAAC;IAEN,OAAOZ,KAAK;EAChB;AACJ;AAACc,OAAA,CAAAtB,uBAAA,GAAAA,uBAAA"}
@@ -0,0 +1,7 @@
1
+ import { CmsEntryListWhere } from "@webiny/api-headless-cms/types";
2
+ import { FileManagerFilesStorageOperationsListParamsWhere } from "../types";
3
+ export declare class ListTagsWhereProcessor {
4
+ private readonly skipKeys;
5
+ private readonly keyMap;
6
+ process(input: FileManagerFilesStorageOperationsListParamsWhere): CmsEntryListWhere;
7
+ }
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.ListTagsWhereProcessor = void 0;
8
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
9
+ class ListTagsWhereProcessor {
10
+ constructor() {
11
+ (0, _defineProperty2.default)(this, "skipKeys", ["tenant", "locale"]);
12
+ (0, _defineProperty2.default)(this, "keyMap", {
13
+ tag_startsWith: "tags_startsWith",
14
+ tag_not_startsWith: "tags_not_startsWith"
15
+ });
16
+ }
17
+ process(input) {
18
+ const where = {
19
+ meta: {
20
+ private_not: true
21
+ }
22
+ };
23
+ Object.keys(input).filter(key => !this.skipKeys.includes(key)).forEach(key => {
24
+ const remappedKey = this.keyMap[key];
25
+ const value = input[key];
26
+ if (remappedKey && value !== undefined) {
27
+ where[remappedKey] = value;
28
+ } else if (value !== undefined) {
29
+ where[key] = value;
30
+ }
31
+ });
32
+ return where;
33
+ }
34
+ }
35
+ exports.ListTagsWhereProcessor = ListTagsWhereProcessor;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["ListTagsWhereProcessor","constructor","_defineProperty2","default","tag_startsWith","tag_not_startsWith","process","input","where","meta","private_not","Object","keys","filter","key","skipKeys","includes","forEach","remappedKey","keyMap","value","undefined","exports"],"sources":["ListTagsWhereProcessor.ts"],"sourcesContent":["import { CmsEntryListWhere } from \"@webiny/api-headless-cms/types\";\nimport { FileManagerFilesStorageOperationsListParamsWhere } from \"~/types\";\n\ntype StandardFileKey = keyof FileManagerFilesStorageOperationsListParamsWhere;\ntype CmsEntryListWhereKey = keyof CmsEntryListWhere;\n\nexport class ListTagsWhereProcessor {\n private readonly skipKeys = [\"tenant\", \"locale\"];\n private readonly keyMap: Partial<Record<StandardFileKey, CmsEntryListWhereKey>> = {\n tag_startsWith: \"tags_startsWith\",\n tag_not_startsWith: \"tags_not_startsWith\"\n };\n\n process(input: FileManagerFilesStorageOperationsListParamsWhere): CmsEntryListWhere {\n const where: CmsEntryListWhere = { meta: { private_not: true } };\n\n Object.keys(input)\n .filter(key => !this.skipKeys.includes(key))\n .forEach(key => {\n const remappedKey = this.keyMap[key];\n const value = input[key];\n\n if (remappedKey && value !== undefined) {\n where[remappedKey] = value;\n } else if (value !== undefined) {\n where[key] = value;\n }\n });\n\n return where;\n }\n}\n"],"mappings":";;;;;;;;AAMO,MAAMA,sBAAsB,CAAC;EAAAC,YAAA;IAAA,IAAAC,gBAAA,CAAAC,OAAA,oBACJ,CAAC,QAAQ,EAAE,QAAQ,CAAC;IAAA,IAAAD,gBAAA,CAAAC,OAAA,kBACkC;MAC9EC,cAAc,EAAE,iBAAiB;MACjCC,kBAAkB,EAAE;IACxB,CAAC;EAAA;EAEDC,OAAOA,CAACC,KAAuD,EAAqB;IAChF,MAAMC,KAAwB,GAAG;MAAEC,IAAI,EAAE;QAAEC,WAAW,EAAE;MAAK;IAAE,CAAC;IAEhEC,MAAM,CAACC,IAAI,CAACL,KAAK,CAAC,CACbM,MAAM,CAACC,GAAG,IAAI,CAAC,IAAI,CAACC,QAAQ,CAACC,QAAQ,CAACF,GAAG,CAAC,CAAC,CAC3CG,OAAO,CAACH,GAAG,IAAI;MACZ,MAAMI,WAAW,GAAG,IAAI,CAACC,MAAM,CAACL,GAAG,CAAC;MACpC,MAAMM,KAAK,GAAGb,KAAK,CAACO,GAAG,CAAC;MAExB,IAAII,WAAW,IAAIE,KAAK,KAAKC,SAAS,EAAE;QACpCb,KAAK,CAACU,WAAW,CAAC,GAAGE,KAAK;MAC9B,CAAC,MAAM,IAAIA,KAAK,KAAKC,SAAS,EAAE;QAC5Bb,KAAK,CAACM,GAAG,CAAC,GAAGM,KAAK;MACtB;IACJ,CAAC,CAAC;IAEN,OAAOZ,KAAK;EAChB;AACJ;AAACc,OAAA,CAAAtB,sBAAA,GAAAA,sBAAA"}
@@ -0,0 +1,5 @@
1
+ import { CmsGroupPlugin } from "@webiny/api-headless-cms";
2
+ export declare const createFileManagerPlugins: () => {
3
+ groupPlugin: CmsGroupPlugin;
4
+ fileModelDefinition: import("@webiny/api-headless-cms").CmsPrivateModelFull;
5
+ };
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.createFileManagerPlugins = void 0;
7
+ var _apiHeadlessCms = require("@webiny/api-headless-cms");
8
+ var _file = require("./file.model");
9
+ // import { modelFactory } from "~/cmsFileStorage/modelFactory";
10
+
11
+ const createFileManagerPlugins = () => {
12
+ const groupId = "contentModelGroup_fm";
13
+ const groupPlugin = new _apiHeadlessCms.CmsGroupPlugin({
14
+ id: groupId,
15
+ slug: "fileManager",
16
+ name: "File Manager",
17
+ description: "Group for File Manager models",
18
+ icon: "fas/folder",
19
+ isPrivate: true
20
+ });
21
+
22
+ // const models = modelDefinitions.map(modelDefinition => {
23
+ // return modelFactory({
24
+ // group: cmsGroupPlugin.contentModelGroup,
25
+ // modelDefinition
26
+ // });
27
+ // });
28
+
29
+ return {
30
+ groupPlugin,
31
+ fileModelDefinition: (0, _file.createFileModelDefinition)(groupPlugin.contentModelGroup)
32
+ };
33
+ };
34
+ exports.createFileManagerPlugins = createFileManagerPlugins;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_apiHeadlessCms","require","_file","createFileManagerPlugins","groupId","groupPlugin","CmsGroupPlugin","id","slug","name","description","icon","isPrivate","fileModelDefinition","createFileModelDefinition","contentModelGroup","exports"],"sources":["createFileManagerPlugins.ts"],"sourcesContent":["import { CmsGroupPlugin } from \"@webiny/api-headless-cms\";\n// import { modelFactory } from \"~/cmsFileStorage/modelFactory\";\nimport { createFileModelDefinition } from \"~/cmsFileStorage/file.model\";\n\nexport const createFileManagerPlugins = () => {\n const groupId = \"contentModelGroup_fm\";\n\n const groupPlugin = new CmsGroupPlugin({\n id: groupId,\n slug: \"fileManager\",\n name: \"File Manager\",\n description: \"Group for File Manager models\",\n icon: \"fas/folder\",\n isPrivate: true\n });\n\n // const models = modelDefinitions.map(modelDefinition => {\n // return modelFactory({\n // group: cmsGroupPlugin.contentModelGroup,\n // modelDefinition\n // });\n // });\n\n return {\n groupPlugin,\n fileModelDefinition: createFileModelDefinition(groupPlugin.contentModelGroup)\n };\n};\n"],"mappings":";;;;;;AAAA,IAAAA,eAAA,GAAAC,OAAA;AAEA,IAAAC,KAAA,GAAAD,OAAA;AADA;;AAGO,MAAME,wBAAwB,GAAGA,CAAA,KAAM;EAC1C,MAAMC,OAAO,GAAG,sBAAsB;EAEtC,MAAMC,WAAW,GAAG,IAAIC,8BAAc,CAAC;IACnCC,EAAE,EAAEH,OAAO;IACXI,IAAI,EAAE,aAAa;IACnBC,IAAI,EAAE,cAAc;IACpBC,WAAW,EAAE,+BAA+B;IAC5CC,IAAI,EAAE,YAAY;IAClBC,SAAS,EAAE;EACf,CAAC,CAAC;;EAEF;EACA;EACA;EACA;EACA;EACA;;EAEA,OAAO;IACHP,WAAW;IACXQ,mBAAmB,EAAE,IAAAC,+BAAyB,EAACT,WAAW,CAACU,iBAAiB;EAChF,CAAC;AACL,CAAC;AAACC,OAAA,CAAAb,wBAAA,GAAAA,wBAAA"}
@@ -0,0 +1,5 @@
1
+ import { CmsModelField } from "@webiny/api-headless-cms/types";
2
+ export interface CreateModelFieldParams extends Omit<CmsModelField, "id" | "storageId" | "fieldId"> {
3
+ fieldId?: string;
4
+ }
5
+ export declare const createModelField: (params: CreateModelFieldParams) => CmsModelField;
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.createModelField = void 0;
8
+ var _camelCase = _interopRequireDefault(require("lodash/camelCase"));
9
+ const createModelField = params => {
10
+ const {
11
+ label,
12
+ fieldId: initialFieldId,
13
+ type,
14
+ settings = {},
15
+ listValidation = [],
16
+ validation = [],
17
+ multipleValues = false,
18
+ predefinedValues = {
19
+ values: [],
20
+ enabled: false
21
+ }
22
+ } = params;
23
+ const fieldId = initialFieldId ? (0, _camelCase.default)(initialFieldId) : (0, _camelCase.default)(label);
24
+ return {
25
+ id: fieldId,
26
+ storageId: `${type}@${fieldId}`,
27
+ fieldId,
28
+ label,
29
+ type,
30
+ settings,
31
+ listValidation,
32
+ validation,
33
+ multipleValues,
34
+ predefinedValues
35
+ };
36
+ };
37
+ exports.createModelField = createModelField;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_camelCase","_interopRequireDefault","require","createModelField","params","label","fieldId","initialFieldId","type","settings","listValidation","validation","multipleValues","predefinedValues","values","enabled","camelCase","id","storageId","exports"],"sources":["createModelField.ts"],"sourcesContent":["import { CmsModelField } from \"@webiny/api-headless-cms/types\";\nimport camelCase from \"lodash/camelCase\";\n\nexport interface CreateModelFieldParams\n extends Omit<CmsModelField, \"id\" | \"storageId\" | \"fieldId\"> {\n fieldId?: string;\n}\n\nexport const createModelField = (params: CreateModelFieldParams): CmsModelField => {\n const {\n label,\n fieldId: initialFieldId,\n type,\n settings = {},\n listValidation = [],\n validation = [],\n multipleValues = false,\n predefinedValues = {\n values: [],\n enabled: false\n }\n } = params;\n\n const fieldId = initialFieldId ? camelCase(initialFieldId) : camelCase(label);\n\n return {\n id: fieldId,\n storageId: `${type}@${fieldId}`,\n fieldId,\n label,\n type,\n settings,\n listValidation,\n validation,\n multipleValues,\n predefinedValues\n };\n};\n"],"mappings":";;;;;;;AACA,IAAAA,UAAA,GAAAC,sBAAA,CAAAC,OAAA;AAOO,MAAMC,gBAAgB,GAAIC,MAA8B,IAAoB;EAC/E,MAAM;IACFC,KAAK;IACLC,OAAO,EAAEC,cAAc;IACvBC,IAAI;IACJC,QAAQ,GAAG,CAAC,CAAC;IACbC,cAAc,GAAG,EAAE;IACnBC,UAAU,GAAG,EAAE;IACfC,cAAc,GAAG,KAAK;IACtBC,gBAAgB,GAAG;MACfC,MAAM,EAAE,EAAE;MACVC,OAAO,EAAE;IACb;EACJ,CAAC,GAAGX,MAAM;EAEV,MAAME,OAAO,GAAGC,cAAc,GAAG,IAAAS,kBAAS,EAACT,cAAc,CAAC,GAAG,IAAAS,kBAAS,EAACX,KAAK,CAAC;EAE7E,OAAO;IACHY,EAAE,EAAEX,OAAO;IACXY,SAAS,EAAG,GAAEV,IAAK,IAAGF,OAAQ,EAAC;IAC/BA,OAAO;IACPD,KAAK;IACLG,IAAI;IACJC,QAAQ;IACRC,cAAc;IACdC,UAAU;IACVC,cAAc;IACdC;EACJ,CAAC;AACL,CAAC;AAACM,OAAA,CAAAhB,gBAAA,GAAAA,gBAAA"}
@@ -0,0 +1,4 @@
1
+ import { CmsPrivateModelFull } from "@webiny/api-headless-cms";
2
+ import { CmsModelGroup } from "@webiny/api-headless-cms/types";
3
+ export declare const FILE_MODEL_ID = "fmFile";
4
+ export declare const createFileModelDefinition: (group: CmsModelGroup) => CmsPrivateModelFull;