@webiny/api-file-manager 6.4.5 → 6.6.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/FileManagerAppFeature.d.ts +5 -0
- package/FileManagerAppFeature.js +21 -0
- package/FileManagerAppFeature.js.map +1 -0
- package/delivery/AssetDeliveryRoute.d.ts +14 -0
- package/delivery/AssetDeliveryRoute.js +65 -0
- package/delivery/AssetDeliveryRoute.js.map +1 -0
- package/delivery/setupAssetDelivery.d.ts +1 -1
- package/delivery/setupAssetDelivery.js +1 -66
- package/delivery/setupAssetDelivery.js.map +1 -1
- package/domain/settings/validation.js +1 -1
- package/domain/settings/validation.js.map +1 -1
- package/exports/api/file-manager/assetDelivery.d.ts +10 -0
- package/exports/api/file-manager/assetDelivery.js +8 -0
- package/exports/api/file-manager/file.d.ts +1 -0
- package/exports/api/file-manager/file.js +1 -0
- package/features/FileManagerFeature.js +6 -0
- package/features/FileManagerFeature.js.map +1 -1
- package/features/FileModelContextualSchema.d.ts +13 -0
- package/features/FileModelContextualSchema.js +31 -0
- package/features/FileModelContextualSchema.js.map +1 -0
- package/features/assetDelivery/Asset/Asset.d.ts +8 -0
- package/features/assetDelivery/Asset/Asset.js +14 -0
- package/features/assetDelivery/Asset/Asset.js.map +1 -0
- package/features/assetDelivery/Asset/abstractions.d.ts +10 -0
- package/features/assetDelivery/Asset/abstractions.js +5 -0
- package/features/assetDelivery/Asset/abstractions.js.map +1 -0
- package/features/assetDelivery/Asset/index.d.ts +1 -0
- package/features/assetDelivery/Asset/index.js +1 -0
- package/features/assetDelivery/FilesAssetRequestResolver.js +2 -2
- package/features/assetDelivery/FilesAssetRequestResolver.js.map +1 -1
- package/features/assetDelivery/ObjectKey/ObjectKey.d.ts +8 -0
- package/features/assetDelivery/ObjectKey/ObjectKey.js +28 -0
- package/features/assetDelivery/ObjectKey/ObjectKey.js.map +1 -0
- package/features/assetDelivery/ObjectKey/abstractions.d.ts +12 -0
- package/features/assetDelivery/ObjectKey/abstractions.js +5 -0
- package/features/assetDelivery/ObjectKey/abstractions.js.map +1 -0
- package/features/assetDelivery/ObjectKey/index.d.ts +1 -0
- package/features/assetDelivery/ObjectKey/index.js +1 -0
- package/features/assetDelivery/StreamAssetReply/StreamAssetReply.d.ts +8 -0
- package/features/assetDelivery/StreamAssetReply/StreamAssetReply.js +22 -0
- package/features/assetDelivery/StreamAssetReply/StreamAssetReply.js.map +1 -0
- package/features/assetDelivery/StreamAssetReply/abstractions.d.ts +11 -0
- package/features/assetDelivery/StreamAssetReply/abstractions.js +5 -0
- package/features/assetDelivery/StreamAssetReply/abstractions.js.map +1 -0
- package/features/assetDelivery/StreamAssetReply/index.d.ts +1 -0
- package/features/assetDelivery/StreamAssetReply/index.js +1 -0
- package/features/assetDelivery/abstractions.d.ts +23 -12
- package/features/assetDelivery/abstractions.js.map +1 -1
- package/features/assetDelivery/feature.js +6 -0
- package/features/assetDelivery/feature.js.map +1 -1
- package/features/assetDelivery/privateFiles/PrivateFileAssetRequestResolver.js +2 -2
- package/features/assetDelivery/privateFiles/PrivateFileAssetRequestResolver.js.map +1 -1
- package/features/assetDelivery/transformation/AssetKeyGenerator.d.ts +9 -0
- package/features/assetDelivery/transformation/AssetKeyGenerator.js +24 -0
- package/features/assetDelivery/transformation/AssetKeyGenerator.js.map +1 -0
- package/features/assetDelivery/transformation/CallableContentsReader.d.ts +11 -0
- package/features/assetDelivery/transformation/CallableContentsReader.js +14 -0
- package/features/assetDelivery/transformation/CallableContentsReader.js.map +1 -0
- package/features/assetDelivery/transformation/WidthCollection.d.ts +8 -0
- package/features/assetDelivery/transformation/WidthCollection.js +22 -0
- package/features/assetDelivery/transformation/WidthCollection.js.map +1 -0
- package/features/assetDelivery/transformation/index.d.ts +4 -0
- package/features/assetDelivery/transformation/index.js +4 -0
- package/features/assetDelivery/transformation/utils.d.ts +9 -0
- package/features/assetDelivery/transformation/utils.js +31 -0
- package/features/assetDelivery/transformation/utils.js.map +1 -0
- package/features/extractMetadata/ExtractMetadataHandler.d.ts +11 -0
- package/features/extractMetadata/ExtractMetadataHandler.js +25 -0
- package/features/extractMetadata/ExtractMetadataHandler.js.map +1 -0
- package/features/extractMetadata/ExtractMetadataInput.d.ts +3 -0
- package/features/extractMetadata/ExtractMetadataInput.js +0 -0
- package/features/file/FileUrlGenerator/FileUrlGenerator.d.ts +14 -0
- package/features/file/FileUrlGenerator/FileUrlGenerator.js +25 -0
- package/features/file/FileUrlGenerator/FileUrlGenerator.js.map +1 -0
- package/features/file/FileUrlGenerator/abstractions.d.ts +3 -3
- package/features/file/FileUrlGenerator/abstractions.js +1 -1
- package/features/file/FileUrlGenerator/abstractions.js.map +1 -1
- package/features/file/FileUrlGenerator/feature.d.ts +4 -0
- package/features/file/FileUrlGenerator/feature.js +11 -0
- package/features/file/FileUrlGenerator/feature.js.map +1 -0
- package/features/file/FileUrlGenerator/index.d.ts +1 -0
- package/features/file/FileUrlGenerator/index.js +1 -0
- package/features/file/GetFileByUrl/GetFileByUrlUseCase.d.ts +15 -0
- package/features/file/GetFileByUrl/GetFileByUrlUseCase.js +37 -0
- package/features/file/GetFileByUrl/GetFileByUrlUseCase.js.map +1 -0
- package/features/file/GetFileByUrl/abstractions.d.ts +18 -0
- package/features/file/GetFileByUrl/abstractions.js +5 -0
- package/features/file/GetFileByUrl/abstractions.js.map +1 -0
- package/features/file/GetFileByUrl/feature.d.ts +4 -0
- package/features/file/GetFileByUrl/feature.js +11 -0
- package/features/file/GetFileByUrl/feature.js.map +1 -0
- package/features/file/GetFileByUrl/index.d.ts +1 -0
- package/features/file/GetFileByUrl/index.js +1 -0
- package/features/settings/SettingsInstaller/SettingsInstaller.d.ts +3 -1
- package/features/settings/SettingsInstaller/SettingsInstaller.js +7 -4
- package/features/settings/SettingsInstaller/SettingsInstaller.js.map +1 -1
- package/features/upload/CompleteMultiPartUpload/abstractions.d.ts +12 -0
- package/features/upload/CompleteMultiPartUpload/abstractions.js +5 -0
- package/features/upload/CompleteMultiPartUpload/abstractions.js.map +1 -0
- package/features/upload/CompleteMultiPartUpload/index.d.ts +1 -0
- package/features/upload/CompleteMultiPartUpload/index.js +1 -0
- package/features/upload/CreateMultiPartUpload/abstractions.d.ts +14 -0
- package/features/upload/CreateMultiPartUpload/abstractions.js +5 -0
- package/features/upload/CreateMultiPartUpload/abstractions.js.map +1 -0
- package/features/upload/CreateMultiPartUpload/index.d.ts +1 -0
- package/features/upload/CreateMultiPartUpload/index.js +1 -0
- package/features/upload/GetUploadPayload/abstractions.d.ts +10 -0
- package/features/upload/GetUploadPayload/abstractions.js +5 -0
- package/features/upload/GetUploadPayload/abstractions.js.map +1 -0
- package/features/upload/GetUploadPayload/index.d.ts +1 -0
- package/features/upload/GetUploadPayload/index.js +1 -0
- package/features/upload/ReadFileMetadata/MetadataReader.d.ts +11 -0
- package/features/upload/ReadFileMetadata/MetadataReader.js +21 -0
- package/features/upload/ReadFileMetadata/MetadataReader.js.map +1 -0
- package/features/upload/ReadFileMetadata/abstractions.d.ts +15 -0
- package/features/upload/ReadFileMetadata/abstractions.js +5 -0
- package/features/upload/ReadFileMetadata/abstractions.js.map +1 -0
- package/features/upload/ReadFileMetadata/feature.d.ts +4 -0
- package/features/upload/ReadFileMetadata/feature.js +11 -0
- package/features/upload/ReadFileMetadata/feature.js.map +1 -0
- package/features/upload/ReadFileMetadata/index.d.ts +1 -0
- package/features/upload/ReadFileMetadata/index.js +1 -0
- package/features/upload/WriteFileMetadata/MetadataWriter.d.ts +14 -0
- package/features/upload/WriteFileMetadata/MetadataWriter.js +36 -0
- package/features/upload/WriteFileMetadata/MetadataWriter.js.map +1 -0
- package/features/upload/WriteFileMetadata/WriteMetadataAfterBatchCreateHandler.d.ts +11 -0
- package/features/upload/WriteFileMetadata/WriteMetadataAfterBatchCreateHandler.js +20 -0
- package/features/upload/WriteFileMetadata/WriteMetadataAfterBatchCreateHandler.js.map +1 -0
- package/features/upload/WriteFileMetadata/WriteMetadataAfterCreateHandler.d.ts +11 -0
- package/features/upload/WriteFileMetadata/WriteMetadataAfterCreateHandler.js +22 -0
- package/features/upload/WriteFileMetadata/WriteMetadataAfterCreateHandler.js.map +1 -0
- package/features/upload/WriteFileMetadata/abstractions.d.ts +9 -0
- package/features/upload/WriteFileMetadata/abstractions.js +5 -0
- package/features/upload/WriteFileMetadata/abstractions.js.map +1 -0
- package/features/upload/WriteFileMetadata/feature.d.ts +4 -0
- package/features/upload/WriteFileMetadata/feature.js +15 -0
- package/features/upload/WriteFileMetadata/feature.js.map +1 -0
- package/features/upload/index.d.ts +17 -0
- package/features/upload/index.js +10 -0
- package/features/upload/types.d.ts +28 -0
- package/features/upload/types.js +0 -0
- package/features/upload/utils/FileExtension.d.ts +6 -0
- package/features/upload/utils/FileExtension.js +16 -0
- package/features/upload/utils/FileExtension.js.map +1 -0
- package/features/upload/utils/FileKey.d.ts +11 -0
- package/features/upload/utils/FileKey.js +33 -0
- package/features/upload/utils/FileKey.js.map +1 -0
- package/features/upload/utils/FileNormalizer.d.ts +13 -0
- package/features/upload/utils/FileNormalizer.js +41 -0
- package/features/upload/utils/FileNormalizer.js.map +1 -0
- package/features/upload/utils/FileUploadModifier.d.ts +30 -0
- package/features/upload/utils/FileUploadModifier.js +39 -0
- package/features/upload/utils/FileUploadModifier.js.map +1 -0
- package/features/upload/utils/checkPermissions.d.ts +5 -0
- package/features/upload/utils/checkPermissions.js +22 -0
- package/features/upload/utils/checkPermissions.js.map +1 -0
- package/features/upload/utils/createFileNormalizerFromContext.d.ts +3 -0
- package/features/upload/utils/createFileNormalizerFromContext.js +9 -0
- package/features/upload/utils/createFileNormalizerFromContext.js.map +1 -0
- package/features/upload/utils/mimeTypes.d.ts +1 -0
- package/features/upload/utils/mimeTypes.js +9 -0
- package/features/upload/utils/mimeTypes.js.map +1 -0
- package/graphql/FmGraphQLSchema.d.ts +25 -0
- package/graphql/FmGraphQLSchema.js +451 -0
- package/graphql/FmGraphQLSchema.js.map +1 -0
- package/index.d.ts +3 -6
- package/index.js +3 -32
- package/index.js.map +1 -1
- package/package.json +24 -17
- package/graphql/baseSchema.d.ts +0 -3
- package/graphql/baseSchema.js +0 -100
- package/graphql/baseSchema.js.map +0 -1
- package/graphql/createFilesTypeDefs.d.ts +0 -8
- package/graphql/createFilesTypeDefs.js +0 -191
- package/graphql/createFilesTypeDefs.js.map +0 -1
- package/graphql/filesSchema.d.ts +0 -4
- package/graphql/filesSchema.js +0 -96
- package/graphql/filesSchema.js.map +0 -1
- package/graphql/getFileByUrl.d.ts +0 -3
- package/graphql/getFileByUrl.js +0 -61
- package/graphql/getFileByUrl.js.map +0 -1
- package/graphql/index.d.ts +0 -4
- package/graphql/index.js +0 -47
- package/graphql/index.js.map +0 -1
- package/graphql/utils.d.ts +0 -11
- package/graphql/utils.js +0 -12
- package/graphql/utils.js.map +0 -1
- package/modelModifier/CmsModelModifier.d.ts +0 -26
- package/modelModifier/CmsModelModifier.js +0 -51
- package/modelModifier/CmsModelModifier.js.map +0 -1
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { PresignedPostPayloadData } from "../../../features/upload/types.js";
|
|
2
|
+
export declare class FileKey {
|
|
3
|
+
private data;
|
|
4
|
+
private extension;
|
|
5
|
+
private key;
|
|
6
|
+
constructor(data: PresignedPostPayloadData);
|
|
7
|
+
getExtension(): string;
|
|
8
|
+
setKey(key: string): this;
|
|
9
|
+
toString(): string;
|
|
10
|
+
private getSanitizedKey;
|
|
11
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import sanitize_filename from "sanitize-filename";
|
|
2
|
+
import { FileExtension } from "./FileExtension.js";
|
|
3
|
+
class FileKey {
|
|
4
|
+
constructor(data){
|
|
5
|
+
this.data = data;
|
|
6
|
+
this.extension = new FileExtension(data);
|
|
7
|
+
this.key = this.getSanitizedKey();
|
|
8
|
+
}
|
|
9
|
+
getExtension() {
|
|
10
|
+
return this.extension.getValue();
|
|
11
|
+
}
|
|
12
|
+
setKey(key) {
|
|
13
|
+
this.key = key;
|
|
14
|
+
return this;
|
|
15
|
+
}
|
|
16
|
+
toString() {
|
|
17
|
+
return [
|
|
18
|
+
this.data.keyPrefix,
|
|
19
|
+
this.data.id,
|
|
20
|
+
this.key
|
|
21
|
+
].filter(Boolean).join("/");
|
|
22
|
+
}
|
|
23
|
+
getSanitizedKey() {
|
|
24
|
+
const key = sanitize_filename(this.data.key || this.data.name).replace(/\s/g, "");
|
|
25
|
+
return [
|
|
26
|
+
key,
|
|
27
|
+
this.getExtension()
|
|
28
|
+
].filter(Boolean).join(".");
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
export { FileKey };
|
|
32
|
+
|
|
33
|
+
//# sourceMappingURL=FileKey.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features/upload/utils/FileKey.js","sources":["../../../../src/features/upload/utils/FileKey.ts"],"sourcesContent":["import sanitizeFilename from \"sanitize-filename\";\nimport type { PresignedPostPayloadData } from \"~/features/upload/types.js\";\nimport { FileExtension } from \"./FileExtension.js\";\n\nexport class FileKey {\n private data: PresignedPostPayloadData;\n private extension: FileExtension;\n private key: string;\n\n constructor(data: PresignedPostPayloadData) {\n this.data = data;\n this.extension = new FileExtension(data);\n this.key = this.getSanitizedKey();\n }\n\n getExtension() {\n return this.extension.getValue();\n }\n\n setKey(key: string) {\n this.key = key;\n return this;\n }\n\n toString() {\n return [this.data.keyPrefix, this.data.id, this.key].filter(Boolean).join(\"/\");\n }\n\n private getSanitizedKey() {\n const key = sanitizeFilename(this.data.key || this.data.name).replace(/\\s/g, \"\");\n\n return [key, this.getExtension()].filter(Boolean).join(\".\");\n }\n}\n"],"names":["FileKey","data","FileExtension","key","Boolean","sanitizeFilename"],"mappings":";;AAIO,MAAMA;IAKT,YAAYC,IAA8B,CAAE;QACxC,IAAI,CAAC,IAAI,GAAGA;QACZ,IAAI,CAAC,SAAS,GAAG,IAAIC,cAAcD;QACnC,IAAI,CAAC,GAAG,GAAG,IAAI,CAAC,eAAe;IACnC;IAEA,eAAe;QACX,OAAO,IAAI,CAAC,SAAS,CAAC,QAAQ;IAClC;IAEA,OAAOE,GAAW,EAAE;QAChB,IAAI,CAAC,GAAG,GAAGA;QACX,OAAO,IAAI;IACf;IAEA,WAAW;QACP,OAAO;YAAC,IAAI,CAAC,IAAI,CAAC,SAAS;YAAE,IAAI,CAAC,IAAI,CAAC,EAAE;YAAE,IAAI,CAAC,GAAG;SAAC,CAAC,MAAM,CAACC,SAAS,IAAI,CAAC;IAC9E;IAEQ,kBAAkB;QACtB,MAAMD,MAAME,kBAAiB,IAAI,CAAC,IAAI,CAAC,GAAG,IAAI,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,OAAO,CAAC,OAAO;QAE7E,OAAO;YAACF;YAAK,IAAI,CAAC,YAAY;SAAG,CAAC,MAAM,CAACC,SAAS,IAAI,CAAC;IAC3D;AACJ"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { FileData, PresignedPostPayloadData } from "../../../features/upload/types.js";
|
|
2
|
+
import type { FileModifier } from "./FileUploadModifier.js";
|
|
3
|
+
export interface FileToSign {
|
|
4
|
+
name: string;
|
|
5
|
+
key: string;
|
|
6
|
+
type: string;
|
|
7
|
+
size: number;
|
|
8
|
+
}
|
|
9
|
+
export declare class FileNormalizer {
|
|
10
|
+
private readonly modifier;
|
|
11
|
+
constructor(modifier?: FileModifier);
|
|
12
|
+
normalizeFile(payload: PresignedPostPayloadData): Promise<FileData>;
|
|
13
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { mdbid } from "@webiny/utils";
|
|
2
|
+
import { FileKey } from "./FileKey.js";
|
|
3
|
+
import { mimeTypes as external_mimeTypes_js_mimeTypes } from "./mimeTypes.js";
|
|
4
|
+
const extensionToMime = new Map();
|
|
5
|
+
for (const [mime, extensions] of Object.entries(external_mimeTypes_js_mimeTypes))for (const ext of extensions)if (!extensionToMime.has(ext)) extensionToMime.set(ext, mime);
|
|
6
|
+
function resolveTypeFromName(name) {
|
|
7
|
+
const ext = name.slice(name.lastIndexOf(".") + 1).toLowerCase();
|
|
8
|
+
return extensionToMime.get(ext) || "application/octet-stream";
|
|
9
|
+
}
|
|
10
|
+
class FileNormalizer {
|
|
11
|
+
constructor(modifier){
|
|
12
|
+
this.modifier = modifier;
|
|
13
|
+
}
|
|
14
|
+
async normalizeFile(payload) {
|
|
15
|
+
const data = {
|
|
16
|
+
...payload,
|
|
17
|
+
id: payload.id || mdbid(),
|
|
18
|
+
type: payload.type || resolveTypeFromName(payload.name)
|
|
19
|
+
};
|
|
20
|
+
const key = new FileKey(data);
|
|
21
|
+
const defaultKey = key.toString();
|
|
22
|
+
const file = {
|
|
23
|
+
name: data.name,
|
|
24
|
+
type: data.type,
|
|
25
|
+
key: defaultKey,
|
|
26
|
+
size: data.size
|
|
27
|
+
};
|
|
28
|
+
if (this.modifier) Object.assign(file, await this.modifier(file));
|
|
29
|
+
if (defaultKey !== file.key) key.setKey(file.key);
|
|
30
|
+
return {
|
|
31
|
+
id: data.id,
|
|
32
|
+
key: key.toString(),
|
|
33
|
+
name: file.name,
|
|
34
|
+
size: file.size,
|
|
35
|
+
type: file.type
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
export { FileNormalizer };
|
|
40
|
+
|
|
41
|
+
//# sourceMappingURL=FileNormalizer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features/upload/utils/FileNormalizer.js","sources":["../../../../src/features/upload/utils/FileNormalizer.ts"],"sourcesContent":["import { mdbid } from \"@webiny/utils\";\nimport type { FileData, PresignedPostPayloadData } from \"~/features/upload/types.js\";\nimport { FileKey } from \"./FileKey.js\";\nimport { mimeTypes } from \"./mimeTypes.js\";\nimport type { FileModifier } from \"./FileUploadModifier.js\";\n\nexport interface FileToSign {\n name: string;\n key: string;\n type: string;\n size: number;\n}\n\nconst extensionToMime = new Map<string, string>();\nfor (const [mime, extensions] of Object.entries(mimeTypes)) {\n for (const ext of extensions) {\n if (!extensionToMime.has(ext)) {\n extensionToMime.set(ext, mime);\n }\n }\n}\n\nfunction resolveTypeFromName(name: string): string {\n const ext = name.slice(name.lastIndexOf(\".\") + 1).toLowerCase();\n return extensionToMime.get(ext) || \"application/octet-stream\";\n}\n\n/*\n * FileNormalizer normalizes file data, before it's signed for upload.\n * It generates a unique file id, and makes sure that the file key includes the unique id.\n */\nexport class FileNormalizer {\n private readonly modifier: FileModifier | undefined;\n\n constructor(modifier?: FileModifier) {\n this.modifier = modifier;\n }\n\n async normalizeFile(payload: PresignedPostPayloadData): Promise<FileData> {\n const data = {\n ...payload,\n id: payload.id || mdbid(),\n type: payload.type || resolveTypeFromName(payload.name)\n };\n\n const key = new FileKey(data);\n const defaultKey = key.toString();\n\n const file: FileToSign = {\n name: data.name,\n type: data.type,\n key: defaultKey,\n size: data.size\n };\n\n if (this.modifier) {\n Object.assign(file, await this.modifier(file));\n }\n\n if (defaultKey !== file.key) {\n key.setKey(file.key);\n }\n\n return {\n id: data.id,\n key: key.toString(),\n name: file.name,\n size: file.size,\n type: file.type\n };\n }\n}\n"],"names":["extensionToMime","Map","mime","extensions","Object","mimeTypes","ext","resolveTypeFromName","name","FileNormalizer","modifier","payload","data","mdbid","key","FileKey","defaultKey","file"],"mappings":";;;AAaA,MAAMA,kBAAkB,IAAIC;AAC5B,KAAK,MAAM,CAACC,MAAMC,WAAW,IAAIC,OAAO,OAAO,CAACC,iCAC5C,KAAK,MAAMC,OAAOH,WACd,IAAI,CAACH,gBAAgB,GAAG,CAACM,MACrBN,gBAAgB,GAAG,CAACM,KAAKJ;AAKrC,SAASK,oBAAoBC,IAAY;IACrC,MAAMF,MAAME,KAAK,KAAK,CAACA,KAAK,WAAW,CAAC,OAAO,GAAG,WAAW;IAC7D,OAAOR,gBAAgB,GAAG,CAACM,QAAQ;AACvC;AAMO,MAAMG;IAGT,YAAYC,QAAuB,CAAE;QACjC,IAAI,CAAC,QAAQ,GAAGA;IACpB;IAEA,MAAM,cAAcC,OAAiC,EAAqB;QACtE,MAAMC,OAAO;YACT,GAAGD,OAAO;YACV,IAAIA,QAAQ,EAAE,IAAIE;YAClB,MAAMF,QAAQ,IAAI,IAAIJ,oBAAoBI,QAAQ,IAAI;QAC1D;QAEA,MAAMG,MAAM,IAAIC,QAAQH;QACxB,MAAMI,aAAaF,IAAI,QAAQ;QAE/B,MAAMG,OAAmB;YACrB,MAAML,KAAK,IAAI;YACf,MAAMA,KAAK,IAAI;YACf,KAAKI;YACL,MAAMJ,KAAK,IAAI;QACnB;QAEA,IAAI,IAAI,CAAC,QAAQ,EACbR,OAAO,MAAM,CAACa,MAAM,MAAM,IAAI,CAAC,QAAQ,CAACA;QAG5C,IAAID,eAAeC,KAAK,GAAG,EACvBH,IAAI,MAAM,CAACG,KAAK,GAAG;QAGvB,OAAO;YACH,IAAIL,KAAK,EAAE;YACX,KAAKE,IAAI,QAAQ;YACjB,MAAMG,KAAK,IAAI;YACf,MAAMA,KAAK,IAAI;YACf,MAAMA,KAAK,IAAI;QACnB;IACJ;AACJ"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { Plugin } from "@webiny/plugins";
|
|
2
|
+
import type { FileToSign } from "./FileNormalizer.js";
|
|
3
|
+
interface Setter<T> {
|
|
4
|
+
(param: T): T;
|
|
5
|
+
}
|
|
6
|
+
declare class FileUploadModifier {
|
|
7
|
+
private fileSetters;
|
|
8
|
+
setFile(setter: Setter<FileToSign>): void;
|
|
9
|
+
execute(file: FileToSign): Promise<FileToSign>;
|
|
10
|
+
}
|
|
11
|
+
interface FileUploadModifierCallbackParams {
|
|
12
|
+
modifier: {
|
|
13
|
+
setFile: FileUploadModifier["setFile"];
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
export declare class FileUploadModifierPlugin extends Plugin {
|
|
17
|
+
static type: string;
|
|
18
|
+
private readonly cb;
|
|
19
|
+
constructor(cb: FileUploadModifierCallable);
|
|
20
|
+
execute(params: FileUploadModifierCallbackParams): void;
|
|
21
|
+
}
|
|
22
|
+
interface FileUploadModifierCallable {
|
|
23
|
+
(params: FileUploadModifierCallbackParams): void;
|
|
24
|
+
}
|
|
25
|
+
export declare const createFileUploadModifier: (cb: FileUploadModifierCallable) => FileUploadModifierPlugin;
|
|
26
|
+
export interface FileModifier {
|
|
27
|
+
(file: FileToSign): Promise<Partial<FileToSign>> | Partial<FileToSign>;
|
|
28
|
+
}
|
|
29
|
+
export declare const createModifierFromPlugins: (plugins?: FileUploadModifierPlugin[]) => FileModifier;
|
|
30
|
+
export {};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import p_reduce from "p-reduce";
|
|
2
|
+
import { Plugin } from "@webiny/plugins";
|
|
3
|
+
class FileUploadModifier {
|
|
4
|
+
setFile(setter) {
|
|
5
|
+
this.fileSetters.push(setter);
|
|
6
|
+
}
|
|
7
|
+
execute(file) {
|
|
8
|
+
return p_reduce(this.fileSetters, async (file, setter)=>({
|
|
9
|
+
...file,
|
|
10
|
+
...await setter(file)
|
|
11
|
+
}), file);
|
|
12
|
+
}
|
|
13
|
+
constructor(){
|
|
14
|
+
this.fileSetters = [];
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
class FileUploadModifierPlugin extends Plugin {
|
|
18
|
+
static{
|
|
19
|
+
this.type = "fm.uploadModifier";
|
|
20
|
+
}
|
|
21
|
+
constructor(cb){
|
|
22
|
+
super();
|
|
23
|
+
this.cb = cb;
|
|
24
|
+
}
|
|
25
|
+
execute(params) {
|
|
26
|
+
return this.cb(params);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
const createFileUploadModifier = (cb)=>new FileUploadModifierPlugin(cb);
|
|
30
|
+
const createModifierFromPlugins = (plugins = [])=>{
|
|
31
|
+
const modifier = new FileUploadModifier();
|
|
32
|
+
plugins.forEach((pl)=>pl.execute({
|
|
33
|
+
modifier
|
|
34
|
+
}));
|
|
35
|
+
return (file)=>modifier.execute(file);
|
|
36
|
+
};
|
|
37
|
+
export { FileUploadModifierPlugin, createFileUploadModifier, createModifierFromPlugins };
|
|
38
|
+
|
|
39
|
+
//# sourceMappingURL=FileUploadModifier.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features/upload/utils/FileUploadModifier.js","sources":["../../../../src/features/upload/utils/FileUploadModifier.ts"],"sourcesContent":["import pReduce from \"p-reduce\";\nimport { Plugin } from \"@webiny/plugins\";\nimport type { FileToSign } from \"./FileNormalizer.js\";\n\ninterface Setter<T> {\n (param: T): T;\n}\n\nclass FileUploadModifier {\n private fileSetters: Setter<FileToSign>[] = [];\n\n setFile(setter: Setter<FileToSign>): void {\n this.fileSetters.push(setter);\n }\n\n execute(file: FileToSign) {\n return pReduce(\n this.fileSetters,\n async (file, setter) => {\n /* We need to spread the original file, then add (potentially) partial changes. */\n return { ...file, ...(await setter(file)) };\n },\n file\n );\n }\n}\n\ninterface FileUploadModifierCallbackParams {\n modifier: {\n setFile: FileUploadModifier[\"setFile\"];\n };\n}\n\nexport class FileUploadModifierPlugin extends Plugin {\n public static override type = \"fm.uploadModifier\";\n private readonly cb: FileUploadModifierCallable;\n\n constructor(cb: FileUploadModifierCallable) {\n super();\n this.cb = cb;\n }\n\n execute(params: FileUploadModifierCallbackParams) {\n return this.cb(params);\n }\n}\n\ninterface FileUploadModifierCallable {\n (params: FileUploadModifierCallbackParams): void;\n}\n\nexport const createFileUploadModifier = (cb: FileUploadModifierCallable) => {\n return new FileUploadModifierPlugin(cb);\n};\n\nexport interface FileModifier {\n (file: FileToSign): Promise<Partial<FileToSign>> | Partial<FileToSign>;\n}\n\nexport const createModifierFromPlugins = (\n plugins: FileUploadModifierPlugin[] = []\n): FileModifier => {\n const modifier = new FileUploadModifier();\n plugins.forEach(pl => pl.execute({ modifier }));\n\n return (file: FileToSign) => modifier.execute(file);\n};\n"],"names":["FileUploadModifier","setter","file","pReduce","FileUploadModifierPlugin","Plugin","cb","params","createFileUploadModifier","createModifierFromPlugins","plugins","modifier","pl"],"mappings":";;AAQA,MAAMA;IAGF,QAAQC,MAA0B,EAAQ;QACtC,IAAI,CAAC,WAAW,CAAC,IAAI,CAACA;IAC1B;IAEA,QAAQC,IAAgB,EAAE;QACtB,OAAOC,SACH,IAAI,CAAC,WAAW,EAChB,OAAOD,MAAMD,SAEF;gBAAE,GAAGC,IAAI;gBAAE,GAAI,MAAMD,OAAOC,KAAK;YAAE,IAE9CA;IAER;;aAfQ,WAAW,GAAyB,EAAE;;AAgBlD;AAQO,MAAME,iCAAiCC;;aACnB,IAAI,GAAG;;IAG9B,YAAYC,EAA8B,CAAE;QACxC,KAAK;QACL,IAAI,CAAC,EAAE,GAAGA;IACd;IAEA,QAAQC,MAAwC,EAAE;QAC9C,OAAO,IAAI,CAAC,EAAE,CAACA;IACnB;AACJ;AAMO,MAAMC,2BAA2B,CAACF,KAC9B,IAAIF,yBAAyBE;AAOjC,MAAMG,4BAA4B,CACrCC,UAAsC,EAAE;IAExC,MAAMC,WAAW,IAAIX;IACrBU,QAAQ,OAAO,CAACE,CAAAA,KAAMA,GAAG,OAAO,CAAC;YAAED;QAAS;IAE5C,OAAO,CAACT,OAAqBS,SAAS,OAAO,CAACT;AAClD"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { FilePermission } from "../../../types.js";
|
|
2
|
+
import { IdentityContext } from "@webiny/api-core/features/security/IdentityContext/index.js";
|
|
3
|
+
export declare const checkPermissions: (identityContext: IdentityContext.Interface, check?: {
|
|
4
|
+
rwd?: string;
|
|
5
|
+
}) => Promise<FilePermission[]>;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { NotAuthorizedError } from "@webiny/api-core/features/security/shared/index.js";
|
|
2
|
+
const checkPermissions = async (identityContext, check = {})=>{
|
|
3
|
+
const filePermissions = await identityContext.getPermissions("fm.file");
|
|
4
|
+
const relevantFilePermissions = filePermissions.filter((current)=>{
|
|
5
|
+
if (check.rwd && !hasRwd(current, check.rwd)) return false;
|
|
6
|
+
return true;
|
|
7
|
+
});
|
|
8
|
+
if (0 === relevantFilePermissions.length) throw new NotAuthorizedError();
|
|
9
|
+
return relevantFilePermissions;
|
|
10
|
+
};
|
|
11
|
+
const hasRwd = (filesFilePermissions, rwd)=>{
|
|
12
|
+
if (!Array.isArray(filesFilePermissions)) filesFilePermissions = [
|
|
13
|
+
filesFilePermissions
|
|
14
|
+
];
|
|
15
|
+
if (!rwd) return true;
|
|
16
|
+
const permissionWithoutRwdRestrictions = filesFilePermissions.some((permission)=>"string" != typeof permission.rwd);
|
|
17
|
+
if (permissionWithoutRwdRestrictions) return true;
|
|
18
|
+
return filesFilePermissions.some((permission)=>permission.rwd && permission.rwd.includes(rwd));
|
|
19
|
+
};
|
|
20
|
+
export { checkPermissions };
|
|
21
|
+
|
|
22
|
+
//# sourceMappingURL=checkPermissions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features/upload/utils/checkPermissions.js","sources":["../../../../src/features/upload/utils/checkPermissions.ts"],"sourcesContent":["import type { FilePermission } from \"~/types.js\";\nimport { NotAuthorizedError } from \"@webiny/api-core/features/security/shared/index.js\";\nimport { IdentityContext } from \"@webiny/api-core/features/security/IdentityContext/index.js\";\n\nexport const checkPermissions = async (\n identityContext: IdentityContext.Interface,\n check: { rwd?: string } = {}\n) => {\n const filePermissions = await identityContext.getPermissions<FilePermission>(\"fm.file\");\n\n const relevantFilePermissions = filePermissions.filter(current => {\n if (check.rwd && !hasRwd(current, check.rwd)) {\n return false;\n }\n\n return true;\n });\n\n if (relevantFilePermissions.length === 0) {\n throw new NotAuthorizedError();\n }\n\n return relevantFilePermissions;\n};\n\nconst hasRwd = (filesFilePermissions: FilePermission | FilePermission[], rwd: string): boolean => {\n if (!Array.isArray(filesFilePermissions)) {\n filesFilePermissions = [filesFilePermissions];\n }\n\n if (!rwd) {\n return true;\n }\n\n /* Is there a permission that doesn't restrict RWD, all RWD permissions are allowed. */\n const permissionWithoutRwdRestrictions = filesFilePermissions.some(permission => {\n return typeof permission.rwd !== \"string\";\n });\n\n if (permissionWithoutRwdRestrictions) {\n return true;\n }\n\n return filesFilePermissions.some(permission => {\n return permission.rwd && permission.rwd.includes(rwd);\n });\n};\n"],"names":["checkPermissions","identityContext","check","filePermissions","relevantFilePermissions","current","hasRwd","NotAuthorizedError","filesFilePermissions","rwd","Array","permissionWithoutRwdRestrictions","permission"],"mappings":";AAIO,MAAMA,mBAAmB,OAC5BC,iBACAC,QAA0B,CAAC,CAAC;IAE5B,MAAMC,kBAAkB,MAAMF,gBAAgB,cAAc,CAAiB;IAE7E,MAAMG,0BAA0BD,gBAAgB,MAAM,CAACE,CAAAA;QACnD,IAAIH,MAAM,GAAG,IAAI,CAACI,OAAOD,SAASH,MAAM,GAAG,GACvC,OAAO;QAGX,OAAO;IACX;IAEA,IAAIE,AAAmC,MAAnCA,wBAAwB,MAAM,EAC9B,MAAM,IAAIG;IAGd,OAAOH;AACX;AAEA,MAAME,SAAS,CAACE,sBAAyDC;IACrE,IAAI,CAACC,MAAM,OAAO,CAACF,uBACfA,uBAAuB;QAACA;KAAqB;IAGjD,IAAI,CAACC,KACD,OAAO;IAIX,MAAME,mCAAmCH,qBAAqB,IAAI,CAACI,CAAAA,aACxD,AAA0B,YAA1B,OAAOA,WAAW,GAAG;IAGhC,IAAID,kCACA,OAAO;IAGX,OAAOH,qBAAqB,IAAI,CAACI,CAAAA,aACtBA,WAAW,GAAG,IAAIA,WAAW,GAAG,CAAC,QAAQ,CAACH;AAEzD"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { FileNormalizer } from "./FileNormalizer.js";
|
|
2
|
+
import { FileUploadModifierPlugin, createModifierFromPlugins } from "./FileUploadModifier.js";
|
|
3
|
+
const createFileNormalizerFromContext = (context)=>{
|
|
4
|
+
const modifierPlugins = context.plugins.byType(FileUploadModifierPlugin.type);
|
|
5
|
+
return new FileNormalizer(createModifierFromPlugins(modifierPlugins));
|
|
6
|
+
};
|
|
7
|
+
export { createFileNormalizerFromContext };
|
|
8
|
+
|
|
9
|
+
//# sourceMappingURL=createFileNormalizerFromContext.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features/upload/utils/createFileNormalizerFromContext.js","sources":["../../../../src/features/upload/utils/createFileNormalizerFromContext.ts"],"sourcesContent":["import type { Context } from \"@webiny/api/types.js\";\nimport { FileNormalizer } from \"./FileNormalizer.js\";\nimport { createModifierFromPlugins } from \"./FileUploadModifier.js\";\nimport { FileUploadModifierPlugin } from \"./FileUploadModifier.js\";\n\nexport const createFileNormalizerFromContext = (context: Context) => {\n const modifierPlugins = context.plugins.byType<FileUploadModifierPlugin>(\n FileUploadModifierPlugin.type\n );\n\n return new FileNormalizer(createModifierFromPlugins(modifierPlugins));\n};\n"],"names":["createFileNormalizerFromContext","context","modifierPlugins","FileUploadModifierPlugin","FileNormalizer","createModifierFromPlugins"],"mappings":";;AAKO,MAAMA,kCAAkC,CAACC;IAC5C,MAAMC,kBAAkBD,QAAQ,OAAO,CAAC,MAAM,CAC1CE,yBAAyB,IAAI;IAGjC,OAAO,IAAIC,eAAeC,0BAA0BH;AACxD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const mimeTypes: Record<string, string[]>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features/upload/utils/mimeTypes.js","sources":["../../../../src/features/upload/utils/mimeTypes.ts"],"sourcesContent":["import vendorTypes from \"mime/types/other.js\";\nimport standardTypes from \"mime/types/standard.js\";\n\n/*\n * We need to get all extensions that are defined for a specific content type.\n * This operation is not available via the `mime` package, so we create such an object ourselves.\n */\nexport const mimeTypes: Record<string, string[]> = {\n ...vendorTypes,\n ...standardTypes\n};\n"],"names":["mimeTypes","vendorTypes","standardTypes"],"mappings":";;AAOO,MAAMA,sBAAsC;IAC/C,GAAGC,KAAW;IACd,GAAGC,QAAa;AACpB"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { GraphQLSchemaFactory } from "@webiny/api-graphql/graphql/abstractions.js";
|
|
2
|
+
import { ListModelsUseCase } from "@webiny/api-headless-cms/features/contentModel/ListModels/index.js";
|
|
3
|
+
import { CmsModelFieldToGraphQLRegistry } from "@webiny/api-headless-cms/exports/api/cms/graphql.js";
|
|
4
|
+
import { IdentityContext } from "@webiny/api-core/exports/api/security.js";
|
|
5
|
+
import { FileUrlGenerator } from "../features/file/FileUrlGenerator/abstractions.js";
|
|
6
|
+
import { FileModel } from "../domain/file/abstractions.js";
|
|
7
|
+
declare class FmGraphQLSchema_ implements GraphQLSchemaFactory.Interface {
|
|
8
|
+
private readonly identityContext;
|
|
9
|
+
private readonly listModelsUseCase;
|
|
10
|
+
private readonly fieldRegistry;
|
|
11
|
+
private readonly fileModel;
|
|
12
|
+
private readonly fileUrlGenerator;
|
|
13
|
+
constructor(identityContext: IdentityContext.Interface, listModelsUseCase: ListModelsUseCase.Interface, fieldRegistry: CmsModelFieldToGraphQLRegistry.Interface, fileModel: FileModel.Interface, fileUrlGenerator: FileUrlGenerator.Interface);
|
|
14
|
+
execute(builder: GraphQLSchemaFactory.SchemaBuilder): Promise<GraphQLSchemaFactory.SchemaBuilder>;
|
|
15
|
+
private addBaseTypeDefs;
|
|
16
|
+
private addFileTypeDefs;
|
|
17
|
+
private addSettingsResolvers;
|
|
18
|
+
private addFileQueryResolvers;
|
|
19
|
+
private addFileMutationResolvers;
|
|
20
|
+
private loadModels;
|
|
21
|
+
}
|
|
22
|
+
export declare const FmGraphQLSchema: typeof FmGraphQLSchema_ & {
|
|
23
|
+
__abstraction: import("@webiny/di").Abstraction<import("@webiny/api-graphql/graphql/abstractions.public").IGraphQLSchemaFactory>;
|
|
24
|
+
};
|
|
25
|
+
export {};
|