@webiny/api-file-manager 0.0.0-unstable.2696f9d9e8 → 0.0.0-unstable.2aaa1916d9
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/FileManagerContextSetup.d.ts +2 -2
- package/FileManagerContextSetup.js +9 -9
- package/FileManagerContextSetup.js.map +1 -1
- package/README.md +1 -1
- package/cmsFileStorage/CmsFilesStorage.d.ts +3 -3
- package/cmsFileStorage/CmsFilesStorage.js +34 -46
- package/cmsFileStorage/CmsFilesStorage.js.map +1 -1
- package/cmsFileStorage/ListFilesWhereProcessor.d.ts +2 -2
- package/cmsFileStorage/ListFilesWhereProcessor.js.map +1 -1
- package/cmsFileStorage/ListTagsWhereProcessor.d.ts +2 -2
- package/cmsFileStorage/ListTagsWhereProcessor.js.map +1 -1
- package/cmsFileStorage/file.model.d.ts +1 -1
- package/cmsFileStorage/file.model.js +27 -22
- package/cmsFileStorage/file.model.js.map +1 -1
- package/contants.js +1 -2
- package/contants.js.map +1 -1
- package/createFileManager/files.crud.d.ts +3 -3
- package/createFileManager/files.crud.js.map +1 -1
- package/createFileManager/index.d.ts +2 -14
- package/createFileManager/index.js.map +1 -1
- package/createFileManager/permissions/FilesPermissions.d.ts +1 -1
- package/createFileManager/permissions/FilesPermissions.js.map +1 -1
- package/createFileManager/permissions/SettingsPermissions.d.ts +4 -0
- package/createFileManager/permissions/SettingsPermissions.js +11 -0
- package/createFileManager/permissions/SettingsPermissions.js.map +1 -0
- package/createFileManager/settings.crud.d.ts +3 -3
- package/createFileManager/settings.crud.js +54 -44
- package/createFileManager/settings.crud.js.map +1 -1
- package/createFileManager/system.crud.d.ts +3 -3
- package/createFileManager/system.crud.js.map +1 -1
- package/createFileManager/types.d.ts +16 -0
- package/createFileManager/types.js +7 -0
- package/createFileManager/types.js.map +1 -0
- package/delivery/AssetDelivery/AliasAssetRequestResolver.d.ts +5 -4
- package/delivery/AssetDelivery/AliasAssetRequestResolver.js.map +1 -1
- package/delivery/AssetDelivery/Asset.d.ts +5 -3
- package/delivery/AssetDelivery/Asset.js +12 -7
- package/delivery/AssetDelivery/Asset.js.map +1 -1
- package/delivery/AssetDelivery/AssetDeliveryConfig.d.ts +8 -8
- package/delivery/AssetDelivery/AssetDeliveryConfig.js.map +1 -1
- package/delivery/AssetDelivery/AssetRequest.d.ts +3 -2
- package/delivery/AssetDelivery/AssetRequest.js.map +1 -1
- package/delivery/AssetDelivery/FilesAssetRequestResolver.d.ts +2 -2
- package/delivery/AssetDelivery/FilesAssetRequestResolver.js +8 -4
- package/delivery/AssetDelivery/FilesAssetRequestResolver.js.map +1 -1
- package/delivery/AssetDelivery/NullAssetOutputStrategy.d.ts +1 -1
- package/delivery/AssetDelivery/NullAssetOutputStrategy.js.map +1 -1
- package/delivery/AssetDelivery/NullAssetReply.js.map +1 -1
- package/delivery/AssetDelivery/NullAssetResolver.d.ts +2 -2
- package/delivery/AssetDelivery/NullAssetResolver.js.map +1 -1
- package/delivery/AssetDelivery/NullRequestResolver.d.ts +1 -1
- package/delivery/AssetDelivery/NullRequestResolver.js.map +1 -1
- package/delivery/AssetDelivery/SetCacheControlHeaders.d.ts +2 -2
- package/delivery/AssetDelivery/SetCacheControlHeaders.js.map +1 -1
- package/delivery/AssetDelivery/SetResponseHeaders.d.ts +3 -3
- package/delivery/AssetDelivery/SetResponseHeaders.js.map +1 -1
- package/delivery/AssetDelivery/abstractions/AssetContentsReader.d.ts +2 -1
- package/delivery/AssetDelivery/abstractions/AssetContentsReader.js.map +1 -1
- package/delivery/AssetDelivery/abstractions/AssetOutputStrategy.d.ts +1 -1
- package/delivery/AssetDelivery/abstractions/AssetOutputStrategy.js.map +1 -1
- package/delivery/AssetDelivery/abstractions/AssetProcessor.d.ts +1 -1
- package/delivery/AssetDelivery/abstractions/AssetProcessor.js.map +1 -1
- package/delivery/AssetDelivery/abstractions/AssetReply.js.map +1 -1
- package/delivery/AssetDelivery/abstractions/AssetRequestResolver.d.ts +2 -2
- package/delivery/AssetDelivery/abstractions/AssetRequestResolver.js.map +1 -1
- package/delivery/AssetDelivery/abstractions/AssetResolver.d.ts +1 -1
- package/delivery/AssetDelivery/abstractions/AssetResolver.js.map +1 -1
- package/delivery/AssetDelivery/abstractions/AssetTransformationStrategy.d.ts +1 -1
- package/delivery/AssetDelivery/abstractions/AssetTransformationStrategy.js.map +1 -1
- package/delivery/AssetDelivery/createAssetDeliveryPluginLoader.d.ts +1 -1
- package/delivery/AssetDelivery/createAssetDeliveryPluginLoader.js.map +1 -1
- package/delivery/AssetDelivery/privateFiles/AssetAuthorizer.d.ts +1 -1
- package/delivery/AssetDelivery/privateFiles/AssetAuthorizer.js.map +1 -1
- package/delivery/AssetDelivery/privateFiles/NotAuthorizedAssetReply.js +1 -1
- package/delivery/AssetDelivery/privateFiles/NotAuthorizedAssetReply.js.map +1 -1
- package/delivery/AssetDelivery/privateFiles/NotAuthorizedOutputStrategy.d.ts +1 -1
- package/delivery/AssetDelivery/privateFiles/NotAuthorizedOutputStrategy.js.map +1 -1
- package/delivery/AssetDelivery/privateFiles/PrivateAuthenticatedAuthorizer.d.ts +2 -2
- package/delivery/AssetDelivery/privateFiles/PrivateAuthenticatedAuthorizer.js.map +1 -1
- package/delivery/AssetDelivery/privateFiles/PrivateCache.d.ts +5 -3
- package/delivery/AssetDelivery/privateFiles/PrivateCache.js +17 -7
- package/delivery/AssetDelivery/privateFiles/PrivateCache.js.map +1 -1
- package/delivery/AssetDelivery/privateFiles/PrivateFileAssetRequestResolver.d.ts +3 -2
- package/delivery/AssetDelivery/privateFiles/PrivateFileAssetRequestResolver.js.map +1 -1
- package/delivery/AssetDelivery/privateFiles/PrivateFilesAssetProcessor.d.ts +3 -3
- package/delivery/AssetDelivery/privateFiles/PrivateFilesAssetProcessor.js +7 -6
- package/delivery/AssetDelivery/privateFiles/PrivateFilesAssetProcessor.js.map +1 -1
- package/delivery/AssetDelivery/privateFiles/PublicCache.d.ts +5 -3
- package/delivery/AssetDelivery/privateFiles/PublicCache.js +17 -7
- package/delivery/AssetDelivery/privateFiles/PublicCache.js.map +1 -1
- package/delivery/AssetDelivery/privateFiles/RedirectToPrivateUrlOutputStrategy.d.ts +2 -1
- package/delivery/AssetDelivery/privateFiles/RedirectToPrivateUrlOutputStrategy.js.map +1 -1
- package/delivery/AssetDelivery/privateFiles/RedirectToPublicUrlOutputStrategy.d.ts +2 -1
- package/delivery/AssetDelivery/privateFiles/RedirectToPublicUrlOutputStrategy.js.map +1 -1
- package/delivery/AssetDelivery/privateFiles/internalIdentity.d.ts +1 -1
- package/delivery/AssetDelivery/privateFiles/internalIdentity.js +1 -2
- package/delivery/AssetDelivery/privateFiles/internalIdentity.js.map +1 -1
- package/delivery/AssetDelivery/transformation/PassthroughAssetProcessor.d.ts +1 -1
- package/delivery/AssetDelivery/transformation/PassthroughAssetProcessor.js.map +1 -1
- package/delivery/AssetDelivery/transformation/PassthroughAssetTransformationStrategy.d.ts +1 -1
- package/delivery/AssetDelivery/transformation/PassthroughAssetTransformationStrategy.js.map +1 -1
- package/delivery/AssetDelivery/transformation/TransformationAssetProcessor.d.ts +1 -1
- package/delivery/AssetDelivery/transformation/TransformationAssetProcessor.js +1 -0
- package/delivery/AssetDelivery/transformation/TransformationAssetProcessor.js.map +1 -1
- package/delivery/index.d.ts +2 -0
- package/delivery/index.js +22 -0
- package/delivery/index.js.map +1 -1
- package/delivery/setupAssetDelivery.d.ts +3 -3
- package/delivery/setupAssetDelivery.js +15 -11
- package/delivery/setupAssetDelivery.js.map +1 -1
- package/enterprise/applyThreatScanning.d.ts +2 -0
- package/enterprise/applyThreatScanning.js +20 -0
- package/enterprise/applyThreatScanning.js.map +1 -0
- package/graphql/baseSchema.d.ts +1 -1
- package/graphql/baseSchema.js +2 -1
- package/graphql/baseSchema.js.map +1 -1
- package/graphql/createFilesTypeDefs.d.ts +1 -1
- package/graphql/createFilesTypeDefs.js +2 -3
- package/graphql/createFilesTypeDefs.js.map +1 -1
- package/graphql/filesSchema.d.ts +2 -2
- package/graphql/filesSchema.js +1 -3
- package/graphql/filesSchema.js.map +1 -1
- package/graphql/getFileByUrl.d.ts +1 -1
- package/graphql/getFileByUrl.js.map +1 -1
- package/graphql/index.d.ts +1 -1
- package/graphql/index.js +3 -3
- package/graphql/index.js.map +1 -1
- package/graphql/utils.d.ts +1 -1
- package/graphql/utils.js.map +1 -1
- package/handlers/manage/imageManager.d.ts +1 -1
- package/handlers/manage/imageManager.js +1 -2
- package/handlers/manage/imageManager.js.map +1 -1
- package/handlers/manage/index.js.map +1 -1
- package/handlers/manage/legacyUtils.js +4 -8
- package/handlers/manage/legacyUtils.js.map +1 -1
- package/handlers/manage/utils.js +4 -8
- package/handlers/manage/utils.js.map +1 -1
- package/handlers/types.js.map +1 -1
- package/handlers/utils/getEnvironment.js.map +1 -1
- package/handlers/utils/getObjectParams.js.map +1 -1
- package/handlers/utils/index.js.map +1 -1
- package/index.d.ts +4 -4
- package/index.js +4 -0
- package/index.js.map +1 -1
- package/modelModifier/CmsModelModifier.d.ts +3 -3
- package/modelModifier/CmsModelModifier.js +2 -2
- package/modelModifier/CmsModelModifier.js.map +1 -1
- package/package.json +25 -35
- package/plugins/FilePhysicalStoragePlugin.d.ts +2 -1
- package/plugins/FilePhysicalStoragePlugin.js.map +1 -1
- package/plugins/FileStorageTransformPlugin.d.ts +1 -1
- package/plugins/FileStorageTransformPlugin.js.map +1 -1
- package/plugins/index.js.map +1 -1
- package/storage/FileStorage.d.ts +5 -4
- package/storage/FileStorage.js.map +1 -1
- package/types/file.d.ts +3 -2
- package/types/file.js.map +1 -1
- package/types/file.lifecycle.d.ts +2 -2
- package/types/file.lifecycle.js.map +1 -1
- package/types.d.ts +17 -15
- package/types.js.map +1 -1
- package/cmsFileStorage/createFileManagerPlugins.d.ts +0 -7
- package/cmsFileStorage/createFileManagerPlugins.js +0 -17
- package/cmsFileStorage/createFileManagerPlugins.js.map +0 -1
- package/cmsFileStorage/createModelField.d.ts +0 -5
- package/cmsFileStorage/createModelField.js +0 -41
- package/cmsFileStorage/createModelField.js.map +0 -1
- package/cmsFileStorage/isInstallationPending.d.ts +0 -4
- package/cmsFileStorage/isInstallationPending.js +0 -23
- package/cmsFileStorage/isInstallationPending.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_handlerGraphql","require","_pubsub","_error","_interopRequireDefault","_contants","_apiSecurity","_date","_identity","createFilesCrud","config","storageOperations","filesPermissions","getLocaleCode","getTenantId","getIdentity","WEBINY_VERSION","onFileBeforeCreate","createTopic","onFileAfterCreate","onFileBeforeBatchCreate","onFileAfterBatchCreate","onFileBeforeUpdate","onFileAfterUpdate","onFileBeforeDelete","onFileAfterDelete","getFile","id","ensure","rwd","file","files","get","where","tenant","locale","NotFoundError","owns","createdBy","createFile","input","meta","key","split","currentDateTime","Date","currentIdentity","tags","Array","isArray","aliases","location","folderId","ROOT_FOLDER","private","createdOn","getDate","modifiedOn","savedOn","utilsGetIdentity","modifiedBy","savedBy","webinyVersion","publish","result","create","ex","NotAuthorizedError","WebinyError","message","code","data","updateFile","original","update","deleteFile","delete","createFilesInBatch","inputs","map","results","createBatch","listFiles","params","limit","after","initialWhere","sort","initialSort","search","private_not","canAccessOnlyOwnRecords","identity","length","list","listTags","exports"],"sources":["files.crud.ts"],"sourcesContent":["import { NotFoundError } from \"@webiny/handler-graphql\";\nimport { createTopic } from \"@webiny/pubsub\";\nimport WebinyError from \"@webiny/error\";\nimport {\n File,\n FileManagerFilesStorageOperationsListParamsWhere,\n FileManagerFilesStorageOperationsTagsParamsWhere,\n FilesCRUD,\n FilesListOpts\n} from \"~/types\";\nimport { FileManagerConfig } from \"~/createFileManager/index\";\nimport { ROOT_FOLDER } from \"~/contants\";\nimport { NotAuthorizedError } from \"@webiny/api-security\";\nimport { getDate } from \"@webiny/api-headless-cms/utils/date\";\nimport { getIdentity as utilsGetIdentity } from \"@webiny/api-headless-cms/utils/identity\";\n\nexport const createFilesCrud = (config: FileManagerConfig): FilesCRUD => {\n const {\n storageOperations,\n filesPermissions,\n getLocaleCode,\n getTenantId,\n getIdentity,\n WEBINY_VERSION\n } = config;\n\n return {\n onFileBeforeCreate: createTopic(\"fileManager.onFileBeforeCreate\"),\n onFileAfterCreate: createTopic(\"fileManager.onFileAfterCreate\"),\n onFileBeforeBatchCreate: createTopic(\"fileManager.onFileBeforeBatchCreate\"),\n onFileAfterBatchCreate: createTopic(\"fileManager.onFileAfterBatchCreate\"),\n onFileBeforeUpdate: createTopic(\"fileManager.onFileBeforeUpdate\"),\n onFileAfterUpdate: createTopic(\"fileManager.onFileAfterUpdate\"),\n onFileBeforeDelete: createTopic(\"fileManager.onFileBeforeDelete\"),\n onFileAfterDelete: createTopic(\"fileManager.onFileAfterDelete\"),\n async getFile(id: string) {\n await filesPermissions.ensure({ rwd: \"r\" });\n\n const file = await storageOperations.files.get({\n where: {\n id,\n tenant: getTenantId(),\n locale: getLocaleCode()\n }\n });\n\n if (!file) {\n throw new NotFoundError(`File with id \"${id}\" does not exists.`);\n }\n\n await filesPermissions.ensure({ owns: file.createdBy });\n\n return file;\n },\n async createFile(input, meta) {\n await filesPermissions.ensure({ rwd: \"w\" });\n\n // Extract ID from file key\n const [id] = input.key.split(\"/\");\n\n const currentDateTime = new Date();\n const currentIdentity = getIdentity();\n\n const file: File = {\n ...input,\n tags: Array.isArray(input.tags) ? input.tags : [],\n aliases: Array.isArray(input.aliases) ? input.aliases : [],\n id: input.id || id,\n location: {\n folderId: input.location?.folderId ?? ROOT_FOLDER\n },\n meta: {\n private: false,\n ...(input.meta || {})\n },\n\n createdOn: getDate(input.createdOn, currentDateTime),\n modifiedOn: getDate(input.modifiedOn, null),\n savedOn: getDate(input.savedOn, currentDateTime),\n createdBy: utilsGetIdentity(input.createdBy, currentIdentity),\n modifiedBy: utilsGetIdentity(input.modifiedBy, null),\n savedBy: utilsGetIdentity(input.savedBy, currentIdentity),\n\n tenant: getTenantId(),\n locale: getLocaleCode(),\n webinyVersion: WEBINY_VERSION\n };\n\n try {\n await this.onFileBeforeCreate.publish({ file, meta });\n\n const result = await storageOperations.files.create({ file });\n\n await this.onFileAfterCreate.publish({ file, meta });\n return result;\n } catch (ex) {\n // If a `NotAuthorizedError` error was thrown, then we just want to rethrow it.\n if (ex instanceof NotAuthorizedError) {\n throw ex;\n }\n\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 await filesPermissions.ensure({ rwd: \"w\" });\n\n const original = await storageOperations.files.get({\n where: {\n id,\n tenant: getTenantId(),\n locale: getLocaleCode()\n }\n });\n\n if (!original) {\n throw new NotFoundError(`File with id \"${id}\" does not exists.`);\n }\n\n await filesPermissions.ensure({ owns: original.createdBy });\n\n const currentDateTime = new Date();\n const currentIdentity = getIdentity();\n\n const file: File = {\n ...original,\n ...input,\n\n createdOn: getDate(input.createdOn, original.createdOn),\n modifiedOn: getDate(input.modifiedOn, currentDateTime),\n savedOn: getDate(input.savedOn, currentDateTime),\n createdBy: utilsGetIdentity(input.createdBy, original.createdBy),\n modifiedBy: utilsGetIdentity(input.modifiedBy, currentIdentity),\n savedBy: utilsGetIdentity(input.savedBy, currentIdentity),\n\n tags: Array.isArray(input.tags)\n ? input.tags\n : Array.isArray(original.tags)\n ? original.tags\n : [],\n aliases: Array.isArray(input.aliases)\n ? input.aliases\n : Array.isArray(original.aliases)\n ? original.aliases\n : [],\n id: original.id,\n webinyVersion: WEBINY_VERSION\n };\n\n try {\n await this.onFileBeforeUpdate.publish({\n original,\n file,\n input\n });\n\n const result = await storageOperations.files.update({\n original,\n file\n });\n\n await this.onFileAfterUpdate.publish({\n original,\n file,\n input\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 await filesPermissions.ensure({ rwd: \"d\" });\n\n const file = await storageOperations.files.get({\n where: {\n id,\n tenant: getTenantId(),\n locale: getLocaleCode()\n }\n });\n\n if (!file) {\n throw new NotFoundError(`File with id \"${id}\" does not exists.`);\n }\n\n await filesPermissions.ensure({ owns: file.createdBy });\n\n try {\n await this.onFileBeforeDelete.publish({ file });\n\n await storageOperations.files.delete({\n file\n });\n\n await this.onFileAfterDelete.publish({ file });\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, meta) {\n await filesPermissions.ensure({ rwd: \"w\" });\n\n const tenant = getTenantId();\n const locale = getLocaleCode();\n\n const currentIdentity = getIdentity();\n const currentDateTime = new Date();\n\n const files: File[] = inputs.map(input => {\n return {\n ...input,\n tags: Array.isArray(input.tags) ? input.tags : [],\n aliases: Array.isArray(input.aliases) ? input.aliases : [],\n meta: {\n private: false,\n ...(input.meta || {})\n },\n location: {\n folderId: input.location?.folderId ?? ROOT_FOLDER\n },\n\n createdOn: getDate(currentDateTime),\n modifiedOn: null,\n savedOn: getDate(currentDateTime),\n createdBy: utilsGetIdentity(currentIdentity),\n modifiedBy: null,\n savedBy: utilsGetIdentity(currentIdentity),\n\n tenant,\n locale,\n webinyVersion: WEBINY_VERSION\n };\n });\n\n try {\n await this.onFileBeforeBatchCreate.publish({ files, meta });\n const results = await storageOperations.files.createBatch({\n files\n });\n await this.onFileAfterBatchCreate.publish({ files, meta });\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 await filesPermissions.ensure({ rwd: \"r\" });\n\n const {\n limit = 40,\n after = null,\n where: initialWhere,\n sort: initialSort,\n search\n } = params;\n\n const where: FileManagerFilesStorageOperationsListParamsWhere = {\n ...{ meta: { private_not: true }, ...initialWhere },\n locale: getLocaleCode(),\n tenant: getTenantId()\n };\n\n /**\n * Always override the createdBy received from the user, if any.\n */\n if (await filesPermissions.canAccessOnlyOwnRecords()) {\n const identity = getIdentity();\n where.createdBy = identity.id;\n }\n\n const sort =\n Array.isArray(initialSort) && initialSort.length > 0 ? initialSort : [\"id_DESC\"];\n try {\n return await storageOperations.files.list({\n where,\n after,\n limit,\n sort,\n search\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 filesPermissions.ensure();\n\n const where: FileManagerFilesStorageOperationsTagsParamsWhere = {\n ...initialWhere,\n tenant: getTenantId(),\n locale: getLocaleCode()\n };\n\n const params = {\n where,\n limit: limit || 1000000,\n after\n };\n\n try {\n return await storageOperations.files.tags(params);\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"],"mappings":";;;;;;;AAAA,IAAAA,eAAA,GAAAC,OAAA;AACA,IAAAC,OAAA,GAAAD,OAAA;AACA,IAAAE,MAAA,GAAAC,sBAAA,CAAAH,OAAA;AASA,IAAAI,SAAA,GAAAJ,OAAA;AACA,IAAAK,YAAA,GAAAL,OAAA;AACA,IAAAM,KAAA,GAAAN,OAAA;AACA,IAAAO,SAAA,GAAAP,OAAA;AAEO,MAAMQ,eAAe,GAAIC,MAAyB,IAAgB;EACrE,MAAM;IACFC,iBAAiB;IACjBC,gBAAgB;IAChBC,aAAa;IACbC,WAAW;IACXC,WAAW;IACXC;EACJ,CAAC,GAAGN,MAAM;EAEV,OAAO;IACHO,kBAAkB,EAAE,IAAAC,mBAAW,EAAC,gCAAgC,CAAC;IACjEC,iBAAi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OAAO,IAAI,4BAA4B,EAC1CH,EAAE,CAACI,IAAI,IAAI,uBAAuB,EAClC;UACI,IAAIJ,EAAE,CAACK,IAAI,IAAI,CAAC,CAAC,CAAC;UAClBY;QACJ,CACJ,CAAC;MACL;IACJ;EACJ,CAAC;AACL,CAAC;AAACa,OAAA,CAAAvF,eAAA,GAAAA,eAAA"}
|
|
1
|
+
{"version":3,"names":["_handlerGraphql","require","_pubsub","_error","_interopRequireDefault","_contants","_apiSecurity","_date","_identity","createFilesCrud","config","storageOperations","filesPermissions","getLocaleCode","getTenantId","getIdentity","WEBINY_VERSION","onFileBeforeCreate","createTopic","onFileAfterCreate","onFileBeforeBatchCreate","onFileAfterBatchCreate","onFileBeforeUpdate","onFileAfterUpdate","onFileBeforeDelete","onFileAfterDelete","getFile","id","ensure","rwd","file","files","get","where","tenant","locale","NotFoundError","owns","createdBy","createFile","input","meta","key","split","currentDateTime","Date","currentIdentity","tags","Array","isArray","aliases","location","folderId","ROOT_FOLDER","private","createdOn","getDate","modifiedOn","savedOn","utilsGetIdentity","modifiedBy","savedBy","webinyVersion","publish","result","create","ex","NotAuthorizedError","WebinyError","message","code","data","updateFile","original","update","deleteFile","delete","createFilesInBatch","inputs","map","results","createBatch","listFiles","params","limit","after","initialWhere","sort","initialSort","search","private_not","canAccessOnlyOwnRecords","identity","length","list","listTags","exports"],"sources":["files.crud.ts"],"sourcesContent":["import { NotFoundError } from \"@webiny/handler-graphql\";\nimport { createTopic } from \"@webiny/pubsub\";\nimport WebinyError from \"@webiny/error\";\nimport type {\n File,\n FileManagerFilesStorageOperationsListParamsWhere,\n FileManagerFilesStorageOperationsTagsParamsWhere,\n FilesCRUD,\n FilesListOpts\n} from \"~/types\";\nimport type { FileManagerConfig } from \"~/createFileManager/types\";\nimport { ROOT_FOLDER } from \"~/contants\";\nimport { NotAuthorizedError } from \"@webiny/api-security\";\nimport { getDate } from \"@webiny/api-headless-cms/utils/date\";\nimport { getIdentity as utilsGetIdentity } from \"@webiny/api-headless-cms/utils/identity\";\nimport type { CmsEntryListSort } from \"@webiny/api-headless-cms/types\";\n\nexport const createFilesCrud = (\n config: Pick<\n FileManagerConfig,\n | \"storageOperations\"\n | \"filesPermissions\"\n | \"getLocaleCode\"\n | \"getTenantId\"\n | \"getIdentity\"\n | \"WEBINY_VERSION\"\n >\n): FilesCRUD => {\n const {\n storageOperations,\n filesPermissions,\n getLocaleCode,\n getTenantId,\n getIdentity,\n WEBINY_VERSION\n } = config;\n\n return {\n onFileBeforeCreate: createTopic(\"fileManager.onFileBeforeCreate\"),\n onFileAfterCreate: createTopic(\"fileManager.onFileAfterCreate\"),\n onFileBeforeBatchCreate: createTopic(\"fileManager.onFileBeforeBatchCreate\"),\n onFileAfterBatchCreate: createTopic(\"fileManager.onFileAfterBatchCreate\"),\n onFileBeforeUpdate: createTopic(\"fileManager.onFileBeforeUpdate\"),\n onFileAfterUpdate: createTopic(\"fileManager.onFileAfterUpdate\"),\n onFileBeforeDelete: createTopic(\"fileManager.onFileBeforeDelete\"),\n onFileAfterDelete: createTopic(\"fileManager.onFileAfterDelete\"),\n async getFile(id: string) {\n await filesPermissions.ensure({ rwd: \"r\" });\n\n const file = await storageOperations.files.get({\n where: {\n id,\n tenant: getTenantId(),\n locale: getLocaleCode()\n }\n });\n\n if (!file) {\n throw new NotFoundError(`File with id \"${id}\" does not exists.`);\n }\n\n await filesPermissions.ensure({ owns: file.createdBy });\n\n return file;\n },\n async createFile(input, meta) {\n await filesPermissions.ensure({ rwd: \"w\" });\n\n // Extract ID from file key\n const [id] = input.key.split(\"/\");\n\n const currentDateTime = new Date();\n const currentIdentity = getIdentity();\n\n const file: File = {\n ...input,\n tags: Array.isArray(input.tags) ? input.tags : [],\n aliases: Array.isArray(input.aliases) ? input.aliases : [],\n id: input.id || id,\n location: {\n folderId: input.location?.folderId ?? ROOT_FOLDER\n },\n meta: {\n private: false,\n ...(input.meta || {})\n },\n\n createdOn: getDate(input.createdOn, currentDateTime),\n modifiedOn: getDate(input.modifiedOn, null),\n savedOn: getDate(input.savedOn, currentDateTime),\n createdBy: utilsGetIdentity(input.createdBy, currentIdentity),\n modifiedBy: utilsGetIdentity(input.modifiedBy, null),\n savedBy: utilsGetIdentity(input.savedBy, currentIdentity),\n\n tenant: getTenantId(),\n locale: getLocaleCode(),\n webinyVersion: WEBINY_VERSION\n };\n\n try {\n await this.onFileBeforeCreate.publish({ file, meta });\n\n const result = await storageOperations.files.create({ file });\n\n await this.onFileAfterCreate.publish({ file, meta });\n return result;\n } catch (ex) {\n // If a `NotAuthorizedError` error was thrown, then we just want to rethrow it.\n if (ex instanceof NotAuthorizedError) {\n throw ex;\n }\n\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 await filesPermissions.ensure({ rwd: \"w\" });\n\n const original = await storageOperations.files.get({\n where: {\n id,\n tenant: getTenantId(),\n locale: getLocaleCode()\n }\n });\n\n if (!original) {\n throw new NotFoundError(`File with id \"${id}\" does not exists.`);\n }\n\n await filesPermissions.ensure({ owns: original.createdBy });\n\n const currentDateTime = new Date();\n const currentIdentity = getIdentity();\n\n const file: File = {\n ...original,\n ...input,\n\n createdOn: getDate(input.createdOn, original.createdOn),\n modifiedOn: getDate(input.modifiedOn, currentDateTime),\n savedOn: getDate(input.savedOn, currentDateTime),\n createdBy: utilsGetIdentity(input.createdBy, original.createdBy),\n modifiedBy: utilsGetIdentity(input.modifiedBy, currentIdentity),\n savedBy: utilsGetIdentity(input.savedBy, currentIdentity),\n\n tags: Array.isArray(input.tags)\n ? input.tags\n : Array.isArray(original.tags)\n ? original.tags\n : [],\n aliases: Array.isArray(input.aliases)\n ? input.aliases\n : Array.isArray(original.aliases)\n ? original.aliases\n : [],\n id: original.id,\n webinyVersion: WEBINY_VERSION\n };\n\n try {\n await this.onFileBeforeUpdate.publish({\n original,\n file,\n input\n });\n\n const result = await storageOperations.files.update({\n original,\n file\n });\n\n await this.onFileAfterUpdate.publish({\n original,\n file,\n input\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 await filesPermissions.ensure({ rwd: \"d\" });\n\n const file = await storageOperations.files.get({\n where: {\n id,\n tenant: getTenantId(),\n locale: getLocaleCode()\n }\n });\n\n if (!file) {\n throw new NotFoundError(`File with id \"${id}\" does not exists.`);\n }\n\n await filesPermissions.ensure({ owns: file.createdBy });\n\n try {\n await this.onFileBeforeDelete.publish({ file });\n\n await storageOperations.files.delete({\n file\n });\n\n await this.onFileAfterDelete.publish({ file });\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, meta) {\n await filesPermissions.ensure({ rwd: \"w\" });\n\n const tenant = getTenantId();\n const locale = getLocaleCode();\n\n const currentIdentity = getIdentity();\n const currentDateTime = new Date();\n\n const files: File[] = inputs.map(input => {\n return {\n ...input,\n tags: Array.isArray(input.tags) ? input.tags : [],\n aliases: Array.isArray(input.aliases) ? input.aliases : [],\n meta: {\n private: false,\n ...(input.meta || {})\n },\n location: {\n folderId: input.location?.folderId ?? ROOT_FOLDER\n },\n\n createdOn: getDate(currentDateTime),\n modifiedOn: null,\n savedOn: getDate(currentDateTime),\n createdBy: utilsGetIdentity(currentIdentity),\n modifiedBy: null,\n savedBy: utilsGetIdentity(currentIdentity),\n\n tenant,\n locale,\n webinyVersion: WEBINY_VERSION\n };\n });\n\n try {\n await this.onFileBeforeBatchCreate.publish({ files, meta });\n const results = await storageOperations.files.createBatch({\n files\n });\n await this.onFileAfterBatchCreate.publish({ files, meta });\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 await filesPermissions.ensure({ rwd: \"r\" });\n\n const {\n limit = 40,\n after = null,\n where: initialWhere,\n sort: initialSort,\n search\n } = params;\n\n const where: FileManagerFilesStorageOperationsListParamsWhere = {\n ...{ meta: { private_not: true }, ...initialWhere },\n locale: getLocaleCode(),\n tenant: getTenantId()\n };\n\n /**\n * Always override the createdBy received from the user, if any.\n */\n if (await filesPermissions.canAccessOnlyOwnRecords()) {\n const identity = getIdentity();\n where.createdBy = identity.id;\n }\n\n const sort: CmsEntryListSort =\n Array.isArray(initialSort) && initialSort.length > 0 ? initialSort : [\"id_DESC\"];\n try {\n return await storageOperations.files.list({\n where,\n after,\n limit,\n sort,\n search\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 filesPermissions.ensure();\n\n const where: FileManagerFilesStorageOperationsTagsParamsWhere = {\n ...initialWhere,\n tenant: getTenantId(),\n locale: getLocaleCode()\n };\n\n const params = {\n where,\n limit: limit || 1000000,\n after\n };\n\n try {\n return await storageOperations.files.tags(params);\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"],"mappings":";;;;;;;AAAA,IAAAA,eAAA,GAAAC,OAAA;AACA,IAAAC,OAAA,GAAAD,OAAA;AACA,IAAAE,MAAA,GAAAC,sBAAA,CAAAH,OAAA;AASA,IAAAI,SAAA,GAAAJ,OAAA;AACA,IAAAK,YAAA,GAAAL,OAAA;AACA,IAAAM,KAAA,GAAAN,OAAA;AACA,IAAAO,SAAA,GAAAP,OAAA;AAG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AAK;QACLmD,KAAK,EAAEA,KAAK,IAAI,OAAO;QACvBC;MACJ,CAAC;MAED,IAAI;QACA,OAAO,MAAM1E,iBAAiB,CAACoB,KAAK,CAACgB,IAAI,CAACoC,MAAM,CAAC;MACrD,CAAC,CAAC,OAAOjB,EAAE,EAAE;QACT,MAAM,IAAIE,cAAW,CACjBF,EAAE,CAACG,OAAO,IAAI,4BAA4B,EAC1CH,EAAE,CAACI,IAAI,IAAI,uBAAuB,EAClC;UACI,IAAIJ,EAAE,CAACK,IAAI,IAAI,CAAC,CAAC,CAAC;UAClBY;QACJ,CACJ,CAAC;MACL;IACJ;EACJ,CAAC;AACL,CAAC;AAACa,OAAA,CAAAvF,eAAA,GAAAA,eAAA","ignoreList":[]}
|
|
@@ -1,15 +1,3 @@
|
|
|
1
|
-
import { FileManagerContextObject
|
|
2
|
-
import {
|
|
3
|
-
import { FileStorage } from "../storage/FileStorage";
|
|
4
|
-
import { FilesPermissions } from "./permissions/FilesPermissions";
|
|
5
|
-
export interface FileManagerConfig {
|
|
6
|
-
storageOperations: FileManagerStorageOperations;
|
|
7
|
-
filesPermissions: FilesPermissions;
|
|
8
|
-
getTenantId: () => string;
|
|
9
|
-
getLocaleCode: () => string;
|
|
10
|
-
getIdentity: () => SecurityIdentity;
|
|
11
|
-
getPermissions: GetPermissions;
|
|
12
|
-
storage: FileStorage;
|
|
13
|
-
WEBINY_VERSION: string;
|
|
14
|
-
}
|
|
1
|
+
import type { FileManagerContextObject } from "../types";
|
|
2
|
+
import type { FileManagerConfig } from "./types";
|
|
15
3
|
export declare const createFileManager: (config: FileManagerConfig) => FileManagerContextObject;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_files","require","_settings","_system","createFileManager","config","filesCrud","createFilesCrud","settingsCrud","createSettingsCrud","systemCrud","createSystemCrud","storage","exports"],"sources":["index.ts"],"sourcesContent":["import { FileManagerContextObject
|
|
1
|
+
{"version":3,"names":["_files","require","_settings","_system","createFileManager","config","filesCrud","createFilesCrud","settingsCrud","createSettingsCrud","systemCrud","createSystemCrud","storage","exports"],"sources":["index.ts"],"sourcesContent":["import type { FileManagerContextObject } from \"~/types\";\nimport { createFilesCrud } from \"~/createFileManager/files.crud\";\nimport { createSettingsCrud } from \"~/createFileManager/settings.crud\";\nimport { createSystemCrud } from \"~/createFileManager/system.crud\";\nimport type { FileManagerConfig } from \"~/createFileManager/types\";\n\nexport const createFileManager = (config: FileManagerConfig): FileManagerContextObject => {\n const filesCrud = createFilesCrud(config);\n const settingsCrud = createSettingsCrud(config);\n const systemCrud = createSystemCrud(config);\n\n return {\n ...filesCrud,\n ...settingsCrud,\n ...systemCrud,\n storage: config.storage\n };\n};\n"],"mappings":";;;;;;AACA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,SAAA,GAAAD,OAAA;AACA,IAAAE,OAAA,GAAAF,OAAA;AAGO,MAAMG,iBAAiB,GAAIC,MAAyB,IAA+B;EACtF,MAAMC,SAAS,GAAG,IAAAC,sBAAe,EAACF,MAAM,CAAC;EACzC,MAAMG,YAAY,GAAG,IAAAC,4BAAkB,EAACJ,MAAM,CAAC;EAC/C,MAAMK,UAAU,GAAG,IAAAC,wBAAgB,EAACN,MAAM,CAAC;EAE3C,OAAO;IACH,GAAGC,SAAS;IACZ,GAAGE,YAAY;IACf,GAAGE,UAAU;IACbE,OAAO,EAAEP,MAAM,CAACO;EACpB,CAAC;AACL,CAAC;AAACC,OAAA,CAAAT,iBAAA,GAAAA,iBAAA","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_AppPermissions","require","FilesPermissions","AppPermissions","exports"],"sources":["FilesPermissions.ts"],"sourcesContent":["import { AppPermissions } from \"@webiny/api-security/utils/AppPermissions\";\nimport { FilePermission } from \"~/types\";\n\nexport class FilesPermissions extends AppPermissions<FilePermission> {}\n"],"mappings":";;;;;;AAAA,IAAAA,eAAA,GAAAC,OAAA;AAGO,MAAMC,gBAAgB,SAASC,8BAAc,CAAiB;AAAEC,OAAA,CAAAF,gBAAA,GAAAA,gBAAA"}
|
|
1
|
+
{"version":3,"names":["_AppPermissions","require","FilesPermissions","AppPermissions","exports"],"sources":["FilesPermissions.ts"],"sourcesContent":["import { AppPermissions } from \"@webiny/api-security/utils/AppPermissions\";\nimport type { FilePermission } from \"~/types\";\n\nexport class FilesPermissions extends AppPermissions<FilePermission> {}\n"],"mappings":";;;;;;AAAA,IAAAA,eAAA,GAAAC,OAAA;AAGO,MAAMC,gBAAgB,SAASC,8BAAc,CAAiB;AAAEC,OAAA,CAAAF,gBAAA,GAAAA,gBAAA","ignoreList":[]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.SettingsPermissions = void 0;
|
|
7
|
+
var _AppPermissions = require("@webiny/api-security/utils/AppPermissions");
|
|
8
|
+
class SettingsPermissions extends _AppPermissions.AppPermissions {}
|
|
9
|
+
exports.SettingsPermissions = SettingsPermissions;
|
|
10
|
+
|
|
11
|
+
//# sourceMappingURL=SettingsPermissions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_AppPermissions","require","SettingsPermissions","AppPermissions","exports"],"sources":["SettingsPermissions.ts"],"sourcesContent":["import { AppPermissions } from \"@webiny/api-security/utils/AppPermissions\";\nimport type { SettingsPermission } from \"~/types\";\n\nexport class SettingsPermissions extends AppPermissions<SettingsPermission> {}\n"],"mappings":";;;;;;AAAA,IAAAA,eAAA,GAAAC,OAAA;AAGO,MAAMC,mBAAmB,SAASC,8BAAc,CAAqB;AAAEC,OAAA,CAAAF,mBAAA,GAAAA,mBAAA","ignoreList":[]}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { SettingsCRUD } from "../types";
|
|
2
|
-
import { FileManagerConfig } from "./
|
|
3
|
-
export declare const createSettingsCrud: ({ storageOperations, getTenantId }: FileManagerConfig) => SettingsCRUD;
|
|
1
|
+
import type { SettingsCRUD } from "../types";
|
|
2
|
+
import type { FileManagerConfig } from "./types";
|
|
3
|
+
export declare const createSettingsCrud: ({ storageOperations, getTenantId, settingsPermissions }: Pick<FileManagerConfig, "storageOperations" | "getTenantId" | "settingsPermissions">) => SettingsCRUD;
|
|
@@ -1,49 +1,45 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
3
4
|
Object.defineProperty(exports, "__esModule", {
|
|
4
5
|
value: true
|
|
5
6
|
});
|
|
6
7
|
exports.createSettingsCrud = void 0;
|
|
7
8
|
var _pubsub = require("@webiny/pubsub");
|
|
8
|
-
var
|
|
9
|
-
var
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
srcPrefix: (
|
|
22
|
-
// Make sure srcPrefix always ends with forward slash.
|
|
9
|
+
var _zod = _interopRequireDefault(require("zod"));
|
|
10
|
+
var _utils = require("@webiny/utils");
|
|
11
|
+
const MIN_FILE_SIZE = 0;
|
|
12
|
+
const MAX_FILE_SIZE = 10737418240;
|
|
13
|
+
const uploadMinFileSizeValidation = _zod.default.number().min(MIN_FILE_SIZE, {
|
|
14
|
+
message: `Value needs to be greater than or equal to ${MIN_FILE_SIZE}.`
|
|
15
|
+
}).optional();
|
|
16
|
+
const uploadMaxFileSizeValidation = _zod.default.number().max(MAX_FILE_SIZE, {
|
|
17
|
+
message: `Value needs to be lesser than or equal to ${MAX_FILE_SIZE}.`
|
|
18
|
+
}).optional();
|
|
19
|
+
const createDataModelValidation = _zod.default.object({
|
|
20
|
+
uploadMinFileSize: uploadMinFileSizeValidation.default(MIN_FILE_SIZE),
|
|
21
|
+
uploadMaxFileSize: uploadMaxFileSizeValidation.default(MAX_FILE_SIZE),
|
|
22
|
+
srcPrefix: _zod.default.string().optional().default("/files/").transform(value => {
|
|
23
23
|
if (typeof value === "string") {
|
|
24
24
|
return value.endsWith("/") ? value : value + "/";
|
|
25
25
|
}
|
|
26
26
|
return value;
|
|
27
|
-
})
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
validation: _validation.validation.create("gte:0")
|
|
34
|
-
}),
|
|
35
|
-
uploadMaxFileSize: (0, _fields.number)(),
|
|
36
|
-
srcPrefix: (0, _fields.onSet)(value => {
|
|
37
|
-
// Make sure srcPrefix always ends with forward slash.
|
|
27
|
+
})
|
|
28
|
+
});
|
|
29
|
+
const updateDataModelValidation = _zod.default.object({
|
|
30
|
+
uploadMinFileSize: uploadMinFileSizeValidation,
|
|
31
|
+
uploadMaxFileSize: uploadMaxFileSizeValidation,
|
|
32
|
+
srcPrefix: _zod.default.string().optional().transform(value => {
|
|
38
33
|
if (typeof value === "string") {
|
|
39
34
|
return value.endsWith("/") ? value : value + "/";
|
|
40
35
|
}
|
|
41
36
|
return value;
|
|
42
|
-
})
|
|
43
|
-
})
|
|
37
|
+
})
|
|
38
|
+
});
|
|
44
39
|
const createSettingsCrud = ({
|
|
45
40
|
storageOperations,
|
|
46
|
-
getTenantId
|
|
41
|
+
getTenantId,
|
|
42
|
+
settingsPermissions
|
|
47
43
|
}) => {
|
|
48
44
|
return {
|
|
49
45
|
onSettingsBeforeUpdate: (0, _pubsub.createTopic)("fileManager.onSettingsBeforeUpdate"),
|
|
@@ -54,47 +50,61 @@ const createSettingsCrud = ({
|
|
|
54
50
|
});
|
|
55
51
|
},
|
|
56
52
|
async createSettings(data) {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
53
|
+
await settingsPermissions.ensure();
|
|
54
|
+
const results = createDataModelValidation.safeParse(data);
|
|
55
|
+
if (!results.success) {
|
|
56
|
+
throw (0, _utils.createZodError)(results.error);
|
|
57
|
+
}
|
|
60
58
|
return storageOperations.settings.create({
|
|
61
59
|
data: {
|
|
62
|
-
...
|
|
60
|
+
...results.data,
|
|
63
61
|
tenant: getTenantId()
|
|
64
62
|
}
|
|
65
63
|
});
|
|
66
64
|
},
|
|
67
65
|
async updateSettings(data) {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
66
|
+
await settingsPermissions.ensure();
|
|
67
|
+
const results = updateDataModelValidation.safeParse(data);
|
|
68
|
+
if (!results.success) {
|
|
69
|
+
throw (0, _utils.createZodError)(results.error);
|
|
70
|
+
}
|
|
71
|
+
const original = await storageOperations.settings.get({
|
|
71
72
|
tenant: getTenantId()
|
|
72
73
|
});
|
|
73
|
-
const
|
|
74
|
-
|
|
75
|
-
}
|
|
74
|
+
const newSettings = {
|
|
75
|
+
...(original || {})
|
|
76
|
+
};
|
|
77
|
+
for (const key in results.data) {
|
|
78
|
+
// @ts-expect-error
|
|
79
|
+
const value = results.data[key];
|
|
80
|
+
if (value === undefined) {
|
|
81
|
+
continue;
|
|
82
|
+
}
|
|
83
|
+
// @ts-expect-error
|
|
84
|
+
newSettings[key] = value;
|
|
85
|
+
}
|
|
76
86
|
const settings = {
|
|
77
|
-
...
|
|
78
|
-
...updatedSettings,
|
|
87
|
+
...newSettings,
|
|
79
88
|
tenant: getTenantId()
|
|
80
89
|
};
|
|
81
90
|
await this.onSettingsBeforeUpdate.publish({
|
|
82
91
|
input: data,
|
|
83
|
-
original
|
|
92
|
+
original,
|
|
84
93
|
settings
|
|
85
94
|
});
|
|
86
95
|
const result = await storageOperations.settings.update({
|
|
87
|
-
original
|
|
96
|
+
original,
|
|
88
97
|
data: settings
|
|
89
98
|
});
|
|
90
99
|
await this.onSettingsAfterUpdate.publish({
|
|
91
100
|
input: data,
|
|
92
|
-
original
|
|
101
|
+
original,
|
|
93
102
|
settings: result
|
|
94
103
|
});
|
|
95
104
|
return result;
|
|
96
105
|
},
|
|
97
106
|
async deleteSettings() {
|
|
107
|
+
await settingsPermissions.ensure();
|
|
98
108
|
await storageOperations.settings.delete({
|
|
99
109
|
tenant: getTenantId()
|
|
100
110
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_pubsub","require","
|
|
1
|
+
{"version":3,"names":["_pubsub","require","_zod","_interopRequireDefault","_utils","MIN_FILE_SIZE","MAX_FILE_SIZE","uploadMinFileSizeValidation","zod","number","min","message","optional","uploadMaxFileSizeValidation","max","createDataModelValidation","object","uploadMinFileSize","default","uploadMaxFileSize","srcPrefix","string","transform","value","endsWith","updateDataModelValidation","createSettingsCrud","storageOperations","getTenantId","settingsPermissions","onSettingsBeforeUpdate","createTopic","onSettingsAfterUpdate","getSettings","settings","get","tenant","createSettings","data","ensure","results","safeParse","success","createZodError","error","create","updateSettings","original","newSettings","key","undefined","publish","input","result","update","deleteSettings","delete","exports"],"sources":["settings.crud.ts"],"sourcesContent":["import { createTopic } from \"@webiny/pubsub\";\nimport type { FileManagerSettings, SettingsCRUD } from \"~/types\";\nimport type { FileManagerConfig } from \"./types\";\nimport zod from \"zod\";\nimport { createZodError } from \"@webiny/utils\";\n\nconst MIN_FILE_SIZE = 0;\nconst MAX_FILE_SIZE = 10737418240;\n\nconst uploadMinFileSizeValidation = zod\n .number()\n .min(MIN_FILE_SIZE, {\n message: `Value needs to be greater than or equal to ${MIN_FILE_SIZE}.`\n })\n .optional();\nconst uploadMaxFileSizeValidation = zod\n .number()\n .max(MAX_FILE_SIZE, {\n message: `Value needs to be lesser than or equal to ${MAX_FILE_SIZE}.`\n })\n .optional();\n\nconst createDataModelValidation = zod.object({\n uploadMinFileSize: uploadMinFileSizeValidation.default(MIN_FILE_SIZE),\n uploadMaxFileSize: uploadMaxFileSizeValidation.default(MAX_FILE_SIZE),\n srcPrefix: zod\n .string()\n .optional()\n .default(\"/files/\")\n .transform(value => {\n if (typeof value === \"string\") {\n return value.endsWith(\"/\") ? value : value + \"/\";\n }\n return value;\n })\n});\n\nconst updateDataModelValidation = zod.object({\n uploadMinFileSize: uploadMinFileSizeValidation,\n uploadMaxFileSize: uploadMaxFileSizeValidation,\n srcPrefix: zod\n .string()\n .optional()\n .transform(value => {\n if (typeof value === \"string\") {\n return value.endsWith(\"/\") ? value : value + \"/\";\n }\n return value;\n })\n});\n\nexport const createSettingsCrud = ({\n storageOperations,\n getTenantId,\n settingsPermissions\n}: Pick<\n FileManagerConfig,\n \"storageOperations\" | \"getTenantId\" | \"settingsPermissions\"\n>): SettingsCRUD => {\n return {\n onSettingsBeforeUpdate: createTopic(\"fileManager.onSettingsBeforeUpdate\"),\n onSettingsAfterUpdate: createTopic(\"fileManager.onSettingsAfterUpdate\"),\n async getSettings() {\n return storageOperations.settings.get({ tenant: getTenantId() });\n },\n async createSettings(data) {\n await settingsPermissions.ensure();\n\n const results = createDataModelValidation.safeParse(data);\n if (!results.success) {\n throw createZodError(results.error);\n }\n\n return storageOperations.settings.create({\n data: {\n ...results.data,\n tenant: getTenantId()\n }\n });\n },\n async updateSettings(data) {\n await settingsPermissions.ensure();\n const results = updateDataModelValidation.safeParse(data);\n if (!results.success) {\n throw createZodError(results.error);\n }\n\n const original = (await storageOperations.settings.get({\n tenant: getTenantId()\n })) as FileManagerSettings;\n const newSettings: FileManagerSettings = {\n ...(original || {})\n };\n\n for (const key in results.data) {\n // @ts-expect-error\n const value = results.data[key];\n if (value === undefined) {\n continue;\n }\n // @ts-expect-error\n newSettings[key] = value;\n }\n\n const settings: FileManagerSettings = {\n ...newSettings,\n tenant: getTenantId()\n };\n\n await this.onSettingsBeforeUpdate.publish({\n input: data,\n original,\n settings\n });\n const result = await storageOperations.settings.update({\n original,\n data: settings\n });\n await this.onSettingsAfterUpdate.publish({\n input: data,\n original,\n settings: result\n });\n\n return result;\n },\n async deleteSettings() {\n await settingsPermissions.ensure();\n await storageOperations.settings.delete({ tenant: getTenantId() });\n\n return true;\n }\n };\n};\n"],"mappings":";;;;;;;AAAA,IAAAA,OAAA,GAAAC,OAAA;AAGA,IAAAC,IAAA,GAAAC,sB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erConfig } from "./
|
|
3
|
-
export declare const createSystemCrud: ({ storageOperations, getTenantId, getIdentity, WEBINY_VERSION }: FileManagerConfig) => SystemCRUD;
|
|
1
|
+
import type { SystemCRUD } from "../types";
|
|
2
|
+
import type { FileManagerConfig } from "./types";
|
|
3
|
+
export declare const createSystemCrud: ({ storageOperations, getTenantId, getIdentity, WEBINY_VERSION }: Pick<FileManagerConfig, "storageOperations" | "getTenantId" | "getIdentity" | "WEBINY_VERSION">) => SystemCRUD;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_pubsub","require","_apiSecurity","_error","_interopRequireDefault","createSystemCrud","storageOperations","getTenantId","getIdentity","WEBINY_VERSION","onSystemBeforeInstall","createTopic","onSystemAfterInstall","getVersion","system","get","tenant","version","setVersion","data","update","original","ex","WebinyError","create","install","srcPrefix","identity","NotAuthorizedError","publish","createSettings","exports"],"sources":["system.crud.ts"],"sourcesContent":["import { createTopic } from \"@webiny/pubsub\";\nimport { NotAuthorizedError } from \"@webiny/api-security\";\nimport {\n FileManagerContextObject,\n FileManagerSettings,\n FileManagerSystem,\n SystemCRUD\n} from \"~/types\";\nimport WebinyError from \"@webiny/error\";\nimport { FileManagerConfig } from \"~/createFileManager/
|
|
1
|
+
{"version":3,"names":["_pubsub","require","_apiSecurity","_error","_interopRequireDefault","createSystemCrud","storageOperations","getTenantId","getIdentity","WEBINY_VERSION","onSystemBeforeInstall","createTopic","onSystemAfterInstall","getVersion","system","get","tenant","version","setVersion","data","update","original","ex","WebinyError","create","install","srcPrefix","identity","NotAuthorizedError","publish","createSettings","exports"],"sources":["system.crud.ts"],"sourcesContent":["import { createTopic } from \"@webiny/pubsub\";\nimport { NotAuthorizedError } from \"@webiny/api-security\";\nimport type {\n FileManagerContextObject,\n FileManagerSettings,\n FileManagerSystem,\n SystemCRUD\n} from \"~/types\";\nimport WebinyError from \"@webiny/error\";\nimport type { FileManagerConfig } from \"~/createFileManager/types\";\n\nexport const createSystemCrud = ({\n storageOperations,\n getTenantId,\n getIdentity,\n WEBINY_VERSION\n}: Pick<\n FileManagerConfig,\n \"storageOperations\" | \"getTenantId\" | \"getIdentity\" | \"WEBINY_VERSION\"\n>): SystemCRUD => {\n return {\n onSystemBeforeInstall: createTopic(\"fileManager.onSystemBeforeInstall\"),\n onSystemAfterInstall: createTopic(\"fileManager.onSystemAfterInstall\"),\n async getVersion() {\n const system = await storageOperations.system.get({ tenant: getTenantId() });\n\n return system ? system.version : null;\n },\n async setVersion(version: string) {\n const system = await storageOperations.system.get({ tenant: getTenantId() });\n\n if (system) {\n const data: FileManagerSystem = {\n ...system,\n tenant: system.tenant || getTenantId(),\n version\n };\n try {\n await storageOperations.system.update({\n original: system,\n data\n });\n return;\n } catch (ex) {\n throw new WebinyError(\n \"Could not update the system data.\",\n \"SYSTEM_UPDATE_ERROR\",\n {\n data\n }\n );\n }\n }\n\n const data: FileManagerSystem = {\n version,\n tenant: getTenantId()\n };\n try {\n await storageOperations.system.create({\n data\n });\n return;\n } catch (ex) {\n throw new WebinyError(\"Could not create the system data.\", \"SYSTEM_CREATE_ERROR\", {\n data\n });\n }\n },\n async install(this: FileManagerContextObject, { srcPrefix }) {\n const identity = getIdentity();\n\n if (!identity) {\n throw new NotAuthorizedError();\n }\n\n const version = await this.getVersion();\n\n if (version) {\n throw new WebinyError(\n \"File Manager is already installed.\",\n \"FILES_INSTALL_ABORTED\"\n );\n }\n\n const data: Partial<FileManagerSettings> = {};\n\n if (srcPrefix) {\n data.srcPrefix = srcPrefix;\n }\n\n await this.onSystemBeforeInstall.publish({});\n\n await this.createSettings(data);\n await this.setVersion(WEBINY_VERSION);\n\n await this.onSystemAfterInstall.publish({});\n\n return true;\n }\n };\n};\n"],"mappings":";;;;;;;AAAA,IAAAA,OAAA,GAAAC,OAAA;AACA,IAAAC,YAAA,GAAAD,OAAA;AAOA,IAAAE,MAAA,GAAAC,sBAAA,CAAAH,OAAA;AAGO,MAAMI,gBAAgB,GAAGA,CAAC;EAC7BC,iBAAi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AAE;UAC9EJ;QACJ,CAAC,CAAC;MACN;IACJ,CAAC;IACD,MAAMM,OAAOA,CAAiC;MAAEC;IAAU,CAAC,EAAE;MACzD,MAAMC,QAAQ,GAAGnB,WAAW,CAAC,CAAC;MAE9B,IAAI,CAACmB,QAAQ,EAAE;QACX,MAAM,IAAIC,+BAAkB,CAAC,CAAC;MAClC;MAEA,MAAMX,OAAO,GAAG,MAAM,IAAI,CAACJ,UAAU,CAAC,CAAC;MAEvC,IAAII,OAAO,EAAE;QACT,MAAM,IAAIM,cAAW,CACjB,oCAAoC,EACpC,uBACJ,CAAC;MACL;MAEA,MAAMJ,IAAkC,GAAG,CAAC,CAAC;MAE7C,IAAIO,SAAS,EAAE;QACXP,IAAI,CAACO,SAAS,GAAGA,SAAS;MAC9B;MAEA,MAAM,IAAI,CAAChB,qBAAqB,CAACmB,OAAO,CAAC,CAAC,CAAC,CAAC;MAE5C,MAAM,IAAI,CAACC,cAAc,CAACX,IAAI,CAAC;MAC/B,MAAM,IAAI,CAACD,UAAU,CAACT,cAAc,CAAC;MAErC,MAAM,IAAI,CAACG,oBAAoB,CAACiB,OAAO,CAAC,CAAC,CAAC,CAAC;MAE3C,OAAO,IAAI;IACf;EACJ,CAAC;AACL,CAAC;AAACE,OAAA,CAAA1B,gBAAA,GAAAA,gBAAA","ignoreList":[]}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { FileManagerStorageOperations } from "../types";
|
|
2
|
+
import type { FilesPermissions } from "./permissions/FilesPermissions";
|
|
3
|
+
import type { GetPermissions, SecurityIdentity } from "@webiny/api-security/types";
|
|
4
|
+
import type { FileStorage } from "../storage/FileStorage";
|
|
5
|
+
import type { SettingsPermissions } from "./permissions/SettingsPermissions";
|
|
6
|
+
export interface FileManagerConfig {
|
|
7
|
+
storageOperations: FileManagerStorageOperations;
|
|
8
|
+
filesPermissions: FilesPermissions;
|
|
9
|
+
settingsPermissions: SettingsPermissions;
|
|
10
|
+
getTenantId: () => string;
|
|
11
|
+
getLocaleCode: () => string;
|
|
12
|
+
getIdentity: () => SecurityIdentity;
|
|
13
|
+
getPermissions: GetPermissions;
|
|
14
|
+
storage: FileStorage;
|
|
15
|
+
WEBINY_VERSION: string;
|
|
16
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import type { FileManagerStorageOperations } from \"~/types\";\nimport type { FilesPermissions } from \"./permissions/FilesPermissions\";\nimport type { GetPermissions, SecurityIdentity } from \"@webiny/api-security/types\";\nimport type { FileStorage } from \"~/storage/FileStorage\";\nimport type { SettingsPermissions } from \"./permissions/SettingsPermissions\";\n\nexport interface FileManagerConfig {\n storageOperations: FileManagerStorageOperations;\n filesPermissions: FilesPermissions;\n settingsPermissions: SettingsPermissions;\n getTenantId: () => string;\n getLocaleCode: () => string;\n getIdentity: () => SecurityIdentity;\n getPermissions: GetPermissions;\n storage: FileStorage;\n WEBINY_VERSION: string;\n}\n"],"mappings":"","ignoreList":[]}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { Request } from "@webiny/handler/types";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import type { Request } from "@webiny/handler/types";
|
|
2
|
+
import type { DynamoDBDocument } from "@webiny/aws-sdk/client-dynamodb";
|
|
3
|
+
import type { AssetRequestResolver } from "..";
|
|
4
|
+
import { AssetRequest } from "..";
|
|
4
5
|
export declare class AliasAssetRequestResolver implements AssetRequestResolver {
|
|
5
6
|
private documentClient;
|
|
6
7
|
private resolver;
|
|
7
|
-
constructor(documentClient:
|
|
8
|
+
constructor(documentClient: DynamoDBDocument, resolver: AssetRequestResolver);
|
|
8
9
|
resolve(request: Request): Promise<AssetRequest | undefined>;
|
|
9
10
|
private getFileByAlias;
|
|
10
11
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_clientDynamodb","require","_","AliasAssetRequestResolver","constructor","documentClient","resolver","resolve","request","resolvedAsset","params","query","path","decodeURI","tenant","fileKey","getFileByAlias","undefined","original","options","AssetRequest","key","context","url","alias","Items","send","QueryCommand","TableName","String","process","env","DB_TABLE","IndexName","Limit","KeyConditionExpression","ExpressionAttributeValues","S","Array","isArray","item","data","unmarshall","exports"],"sources":["AliasAssetRequestResolver.ts"],"sourcesContent":["import { Request } from \"@webiny/handler/types\";\nimport {
|
|
1
|
+
{"version":3,"names":["_clientDynamodb","require","_","AliasAssetRequestResolver","constructor","documentClient","resolver","resolve","request","resolvedAsset","params","query","path","decodeURI","tenant","fileKey","getFileByAlias","undefined","original","options","AssetRequest","key","context","url","alias","Items","send","QueryCommand","TableName","String","process","env","DB_TABLE","IndexName","Limit","KeyConditionExpression","ExpressionAttributeValues","S","Array","isArray","item","data","unmarshall","exports"],"sources":["AliasAssetRequestResolver.ts"],"sourcesContent":["import type { Request } from \"@webiny/handler/types\";\nimport type { DynamoDBDocument } from \"@webiny/aws-sdk/client-dynamodb\";\nimport { QueryCommand, unmarshall } from \"@webiny/aws-sdk/client-dynamodb\";\nimport type { AssetRequestResolver } from \"~/delivery\";\nimport { AssetRequest } from \"~/delivery\";\n\nexport class AliasAssetRequestResolver implements AssetRequestResolver {\n private documentClient: DynamoDBDocument;\n private resolver: AssetRequestResolver;\n\n constructor(documentClient: DynamoDBDocument, resolver: AssetRequestResolver) {\n this.documentClient = documentClient;\n this.resolver = resolver;\n }\n\n async resolve(request: Request): Promise<AssetRequest | undefined> {\n const resolvedAsset = await this.resolver.resolve(request);\n\n if (resolvedAsset) {\n return resolvedAsset;\n }\n\n const params = (request.params as Record<string, any>) ?? {};\n const query = (request.query as Record<string, any>) ?? {};\n const path = decodeURI(params[\"*\"]);\n\n const tenant = query.tenant || \"root\";\n const fileKey = await this.getFileByAlias(tenant, path);\n\n if (!fileKey) {\n return undefined;\n }\n\n const { original, ...options } = query;\n\n return new AssetRequest({\n key: fileKey,\n context: {\n url: request.url\n },\n options: {\n original: original !== undefined,\n ...options\n }\n });\n }\n\n private async getFileByAlias(tenant: string, alias: string): Promise<string | null> {\n const { Items } = await this.documentClient.send(\n new QueryCommand({\n TableName: String(process.env.DB_TABLE),\n IndexName: \"GSI1\",\n Limit: 1,\n KeyConditionExpression: \"GSI1_PK = :GSI1_PK AND GSI1_SK = :GSI1_SK\",\n ExpressionAttributeValues: {\n \":GSI1_PK\": { S: `T#${tenant}#FM#FILE_ALIASES` },\n \":GSI1_SK\": { S: alias }\n }\n })\n );\n\n if (!Array.isArray(Items)) {\n return null;\n }\n const [item] = Items;\n if (!item) {\n return null;\n }\n const { data } = unmarshall(item);\n\n return data?.key ?? null;\n }\n}\n"],"mappings":";;;;;;AAEA,IAAAA,eAAA,GAAAC,OAAA;AAEA,IAAAC,CAAA,GAAAD,OAAA;AAEO,MAAME,yBAAyB,CAAiC;EAInEC,WAAWA,CAACC,cAAgC,EAAEC,QAA8B,EAAE;IAC1E,IAAI,CAACD,cAAc,GAAGA,cAAc;IACpC,IAAI,CAACC,QAAQ,GAAGA,QAAQ;EAC5B;EAEA,MAAMC,OAAOA,CAACC,OAAgB,EAAqC;IAC/D,MAAMC,aAAa,GAAG,MAAM,IAAI,CAACH,QAAQ,CAACC,OAAO,CAACC,OAAO,CAAC;IAE1D,IAAIC,aAAa,EAAE;MACf,OAAOA,aAAa;IACxB;IAEA,MAAMC,MAAM,GAAIF,OAAO,CAACE,MAAM,IAA4B,CAAC,CAAC;IAC5D,MAAMC,KAAK,GAAIH,OAAO,CAACG,KAAK,IAA4B,CAAC,CAAC;IAC1D,MAAMC,IAAI,GAAGC,SAAS,CAACH,MAAM,CAAC,GAAG,CAAC,CAAC;IAEnC,MAAMI,MAAM,GAAGH,KAAK,CAACG,MAAM,IAAI,MAAM;IACrC,MAAMC,OAAO,GAAG,MAAM,IAAI,CAACC,cAAc,CAACF,MAAM,EAAEF,IAAI,CAAC;IAEvD,IAAI,CAACG,OAAO,EAAE;MACV,OAAOE,SAAS;IACpB;IAEA,MAAM;MAAEC,QAAQ;MAAE,GAAGC;IAAQ,CAAC,GAAGR,KAAK;IAEtC,OAAO,IAAIS,cAAY,CAAC;MACpBC,GAAG,EAAEN,OAAO;MACZO,OAAO,EAAE;QACLC,GAAG,EAAEf,OAAO,CAACe;MACjB,CAAC;MACDJ,OAAO,EAAE;QACLD,QAAQ,EAAEA,QAAQ,KAAKD,SAAS;QAChC,GAAGE;MACP;IACJ,CAAC,CAAC;EACN;EAEA,MAAcH,cAAcA,CAACF,MAAc,EAAEU,KAAa,EAA0B;IAChF,MAAM;MAAEC;IAAM,CAAC,GAAG,MAAM,IAAI,CAACpB,cAAc,CAACqB,IAAI,CAC5C,IAAIC,4BAAY,CAAC;MACbC,SAAS,EAAEC,MAAM,CAACC,OAAO,CAACC,GAAG,CAACC,QAAQ,CAAC;MACvCC,SAAS,EAAE,MAAM;MACjBC,KAAK,EAAE,CAAC;MACRC,sBAAsB,EAAE,2CAA2C;MACnEC,yBAAyB,EAAE;QACvB,UAAU,EAAE;UAAEC,CAAC,EAAE,KAAKvB,MAAM;QAAmB,CAAC;QAChD,UAAU,EAAE;UAAEuB,CAAC,EAAEb;QAAM;MAC3B;IACJ,CAAC,CACL,CAAC;IAED,IAAI,CAACc,KAAK,CAACC,OAAO,CAACd,KAAK,CAAC,EAAE;MACvB,OAAO,IAAI;IACf;IACA,MAAM,CAACe,IAAI,CAAC,GAAGf,KAAK;IACpB,IAAI,CAACe,IAAI,EAAE;MACP,OAAO,IAAI;IACf;IACA,MAAM;MAAEC;IAAK,CAAC,GAAG,IAAAC,0BAAU,EAACF,IAAI,CAAC;IAEjC,OAAOC,IAAI,EAAEpB,GAAG,IAAI,IAAI;EAC5B;AACJ;AAACsB,OAAA,CAAAxC,yBAAA,GAAAA,yBAAA","ignoreList":[]}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
/// <reference types="node" />
|
|
3
|
+
import type { AssetContentsReader, AssetOutputStrategy } from "..";
|
|
4
|
+
type Setter<T> = (arg: T | undefined) => T;
|
|
4
5
|
export interface AssetData {
|
|
5
6
|
id: string;
|
|
6
7
|
tenant: string;
|
|
@@ -15,11 +16,12 @@ export declare class Asset {
|
|
|
15
16
|
private contentsReader;
|
|
16
17
|
constructor(props: AssetData);
|
|
17
18
|
clone(): Asset;
|
|
19
|
+
withProps(props: Partial<AssetData>): Asset;
|
|
18
20
|
getId(): string;
|
|
19
21
|
getTenant(): string;
|
|
20
22
|
getLocale(): string;
|
|
21
23
|
getKey(): string;
|
|
22
|
-
getSize():
|
|
24
|
+
getSize(): number;
|
|
23
25
|
getContentType(): string;
|
|
24
26
|
getExtension(): string;
|
|
25
27
|
getContents(): Promise<Buffer>;
|
|
@@ -9,10 +9,16 @@ class Asset {
|
|
|
9
9
|
this.props = props;
|
|
10
10
|
}
|
|
11
11
|
clone() {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
return this.withProps(structuredClone(this.props));
|
|
13
|
+
}
|
|
14
|
+
withProps(props) {
|
|
15
|
+
const newAsset = new Asset({
|
|
16
|
+
...this.props,
|
|
17
|
+
...props
|
|
18
|
+
});
|
|
19
|
+
newAsset.contentsReader = this.contentsReader;
|
|
20
|
+
newAsset.outputStrategy = this.outputStrategy;
|
|
21
|
+
return newAsset;
|
|
16
22
|
}
|
|
17
23
|
getId() {
|
|
18
24
|
return this.props.id;
|
|
@@ -26,9 +32,8 @@ class Asset {
|
|
|
26
32
|
getKey() {
|
|
27
33
|
return this.props.key;
|
|
28
34
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
return buffer.length;
|
|
35
|
+
getSize() {
|
|
36
|
+
return this.props.size;
|
|
32
37
|
}
|
|
33
38
|
getContentType() {
|
|
34
39
|
return this.props.contentType;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["Asset","constructor","props","clone","
|
|
1
|
+
{"version":3,"names":["Asset","constructor","props","clone","withProps","structuredClone","newAsset","contentsReader","outputStrategy","getId","id","getTenant","tenant","getLocale","locale","getKey","key","getSize","size","getContentType","contentType","getExtension","split","pop","getContents","Error","read","setContentsReader","reader","output","setOutputStrategy","setter","exports"],"sources":["Asset.ts"],"sourcesContent":["import type { AssetContentsReader, AssetOutputStrategy } from \"~/delivery\";\n\ntype Setter<T> = (arg: T | undefined) => T;\n\nexport interface AssetData {\n id: string;\n tenant: string;\n locale: string;\n key: string;\n size: number;\n contentType: string;\n}\n\nexport class Asset {\n protected readonly props: AssetData;\n private outputStrategy: AssetOutputStrategy | undefined;\n private contentsReader: AssetContentsReader | undefined;\n\n constructor(props: AssetData) {\n this.props = props;\n }\n\n clone() {\n return this.withProps(structuredClone(this.props));\n }\n\n withProps(props: Partial<AssetData>) {\n const newAsset = new Asset({ ...this.props, ...props });\n newAsset.contentsReader = this.contentsReader;\n newAsset.outputStrategy = this.outputStrategy;\n return newAsset;\n }\n\n getId() {\n return this.props.id;\n }\n getTenant() {\n return this.props.tenant;\n }\n getLocale() {\n return this.props.locale;\n }\n getKey() {\n return this.props.key;\n }\n getSize() {\n return this.props.size;\n }\n getContentType() {\n return this.props.contentType;\n }\n getExtension() {\n return this.getKey().split(\".\").pop() ?? \"\";\n }\n\n getContents() {\n if (!this.contentsReader) {\n throw Error(`Asset contents reader was not configured!`);\n }\n return this.contentsReader.read(this);\n }\n\n setContentsReader(reader: AssetContentsReader) {\n this.contentsReader = reader;\n }\n\n output() {\n if (!this.outputStrategy) {\n throw Error(`Asset output strategy was not configured!`);\n }\n\n return this.outputStrategy.output(this);\n }\n\n setOutputStrategy(setter: Setter<AssetOutputStrategy> | AssetOutputStrategy) {\n if (typeof setter === \"function\") {\n this.outputStrategy = setter(this.outputStrategy);\n } else {\n this.outputStrategy = setter;\n }\n }\n}\n"],"mappings":";;;;;;AAaO,MAAMA,KAAK,CAAC;EAKfC,WAAWA,CAACC,KAAgB,EAAE;IAC1B,IAAI,CAACA,KAAK,GAAGA,KAAK;EACtB;EAEAC,KAAKA,CAAA,EA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