@webiny/api-file-manager 5.27.0 → 5.29.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/handlers/download/index.js.map +1 -1
- package/handlers/manage/index.js.map +1 -1
- package/handlers/transform/index.js.map +1 -1
- package/handlers/transform/loaders/imageLoader.js.map +1 -1
- package/handlers/transform/loaders/index.js.map +1 -1
- package/handlers/transform/loaders/sanitizeImageTransformations.js.map +1 -1
- package/handlers/transform/managers/imageManager.js.map +1 -1
- package/handlers/transform/managers/index.js.map +1 -1
- package/handlers/transform/optimizeImage.js.map +1 -1
- package/handlers/transform/transformImage.js.map +1 -1
- package/handlers/transform/utils.js.map +1 -1
- package/handlers/types.js.map +1 -1
- package/handlers/utils/createHandler.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/package.json +18 -18
- package/plugins/crud/files/validation.js.map +1 -1
- package/plugins/crud/files.crud.js.map +1 -1
- package/plugins/crud/settings.crud.js.map +1 -1
- package/plugins/crud/system.crud.js.map +1 -1
- package/plugins/crud/utils/checkBasePermissions.js.map +1 -1
- package/plugins/crud/utils/createFileModel.js.map +1 -1
- package/plugins/crud/utils/lifecycleEvents.js.map +1 -1
- package/plugins/definitions/FilePhysicalStoragePlugin.js.map +1 -1
- package/plugins/definitions/FilePlugin.js.map +1 -1
- package/plugins/definitions/FileStorageTransformPlugin.js.map +1 -1
- package/plugins/definitions/FilesStorageOperationsProviderPlugin.js.map +1 -1
- package/plugins/definitions/InstallationPlugin.js.map +1 -1
- package/plugins/definitions/SettingsStorageOperationsProviderPlugin.js.map +1 -1
- package/plugins/definitions/SystemStorageOperationsProviderPlugin.js.map +1 -1
- package/plugins/graphql.js.map +1 -1
- package/plugins/index.js.map +1 -1
- package/plugins/storage/FileStorage.js.map +1 -1
- package/plugins/storage/index.js.map +1 -1
- package/types.js.map +1 -1
- package/utils.js.map +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["MAX_RETURN_CONTENT_LENGTH","DEFAULT_CACHE_MAX_AGE","extractFilenameOptions","event","path","sanitizeFilename","pathParameters","filename","decodeURI","options","queryStringParameters","extension","pathLib","extname","getS3Object","s3","context","loader","loaders","canProcess","file","name","process","params","getObjectParams","object","getObject","promise","type","handle","eventHandler","region","getEnvironment","S3","contentLength","ContentLength","undefined","data","Body","headers","ContentType","putObjectAcl","Bucket","ACL","Key","statusCode","Location","handler","createHandler","invocationArgs"],"sources":["index.ts"],"sourcesContent":["import { HandlerPlugin } from \"@webiny/handler/types\";\nimport S3 from \"aws-sdk/clients/s3\";\nimport sanitizeFilename from \"sanitize-filename\";\nimport pathLib from \"path\";\nimport { createHandler, getEnvironment, getObjectParams, EventHandlerCallable } from \"../utils\";\nimport loaders from \"../transform/loaders\";\nimport { ArgsContext } from \"@webiny/handler-args/types\";\nimport { DownloadHandlerEventArgs } from \"~/handlers/types\";\nimport { ClientContext } from \"@webiny/handler-client/types\";\n\nconst MAX_RETURN_CONTENT_LENGTH = 5000000; // ~4.77MB\nconst DEFAULT_CACHE_MAX_AGE = 30758400; // 1 year\n\ninterface Context extends ClientContext, ArgsContext<DownloadHandlerEventArgs> {}\n/**\n * Based on given path, extracts file key and additional options sent via query params.\n * @param event\n */\nconst extractFilenameOptions = (event: DownloadHandlerEventArgs) => {\n const path = sanitizeFilename(event.pathParameters.path);\n return {\n filename: decodeURI(path),\n options: event.queryStringParameters,\n extension: pathLib.extname(path)\n };\n};\n\nconst getS3Object = async (event: DownloadHandlerEventArgs, s3: S3, context: Context) => {\n const { options, filename, extension } = extractFilenameOptions(event);\n\n for (const loader of loaders) {\n const canProcess = loader.canProcess({\n context,\n s3,\n options,\n file: {\n name: filename,\n extension\n }\n });\n\n if (!canProcess) {\n continue;\n }\n return loader.process({\n context,\n s3,\n options,\n file: {\n name: filename,\n extension\n }\n });\n }\n\n // If no processors handled the file request, just return the S3 object by default.\n const params = getObjectParams(filename);\n return {\n object: await s3.getObject(params).promise(),\n params: params\n };\n};\n\nexport default (): HandlerPlugin<Context> => ({\n type: \"handler\",\n name: \"handler-download-file\",\n async handle(context) {\n const eventHandler: EventHandlerCallable<DownloadHandlerEventArgs> = async event => {\n const { region } = getEnvironment();\n const s3 = new S3({ region });\n\n const { params, object } = await getS3Object(event, s3, context);\n\n const contentLength = object.ContentLength === undefined ? 0 : object.ContentLength;\n if (contentLength < MAX_RETURN_CONTENT_LENGTH) {\n return {\n /**\n * It is safe to cast as buffer or unknown\n */\n data: object.Body || null,\n headers: {\n \"Content-Type\": object.ContentType,\n \"Cache-Control\": \"public, max-age=\" + DEFAULT_CACHE_MAX_AGE\n }\n };\n }\n\n // Lambda can return max 6MB of content, so if our object's size is larger, we are sending\n // a 301 Redirect, redirecting the user to the public URL of the object in S3.\n await s3\n .putObjectAcl({\n Bucket: params.Bucket,\n ACL: \"public-read\",\n Key: params.Key\n })\n .promise();\n\n return {\n data: null,\n statusCode: 301,\n headers: {\n Location: `https://${params.Bucket}.s3.amazonaws.com/${params.Key}`\n }\n };\n };\n const handler = createHandler(eventHandler);\n\n return await handler(context.invocationArgs);\n }\n});\n"],"mappings":";;;;;;;;;AACA;;AACA;;AACA;;AACA;;AACA;;AAKA,MAAMA,yBAAyB,GAAG,OAAlC,C,CAA2C;;AAC3C,MAAMC,qBAAqB,GAAG,QAA9B,C,CAAwC;;AAGxC;AACA;AACA;AACA;AACA,MAAMC,sBAAsB,GAAIC,KAAD,IAAqC;EAChE,MAAMC,IAAI,GAAG,IAAAC,yBAAA,EAAiBF,KAAK,CAACG,cAAN,CAAqBF,IAAtC,CAAb;EACA,OAAO;IACHG,QAAQ,EAAEC,SAAS,CAACJ,IAAD,CADhB;IAEHK,OAAO,EAAEN,KAAK,CAACO,qBAFZ;IAGHC,SAAS,EAAEC,aAAA,CAAQC,OAAR,CAAgBT,IAAhB;EAHR,CAAP;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,aAAa,GAAGT,MAAM,CAACU,aAAP,KAAyBC,SAAzB,GAAqC,CAArC,GAAyCX,MAAM,CAACU,aAAtE;;MACA,IAAID,aAAa,GAAGlC,yBAApB,EAA+C;QAC3C,OAAO;UACH;AACpB;AACA;UACoBqC,IAAI,EAAEZ,MAAM,CAACa,IAAP,IAAe,IAJlB;UAKHC,OAAO,EAAE;YACL,gBAAgBd,MAAM,CAACe,WADlB;YAEL,iBAAiB,qBAAqBvC;UAFjC;QALN,CAAP;MAUH,CAlB+E,CAoBhF;MACA;;;MACA,MAAMc,EAAE,CACH0B,YADC,CACY;QACVC,MAAM,EAAEnB,MAAM,CAACmB,MADL;QAEVC,GAAG,EAAE,aAFK;QAGVC,GAAG,EAAErB,MAAM,CAACqB;MAHF,CADZ,EAMDjB,OANC,EAAN;MAQA,OAAO;QACHU,IAAI,EAAE,IADH;QAEHQ,UAAU,EAAE,GAFT;QAGHN,OAAO,EAAE;UACLO,QAAQ,EAAG,WAAUvB,MAAM,CAACmB,MAAO,qBAAoBnB,MAAM,CAACqB,GAAI;QAD7D;MAHN,CAAP;IAOH,CArCD;;IAsCA,MAAMG,OAAO,GAAG,IAAAC,oBAAA,EAAclB,YAAd,CAAhB;IAEA,OAAO,MAAMiB,OAAO,CAAC/B,OAAO,CAACiC,cAAT,CAApB;EACH;;AA7CyC,CAA/B,C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["type","name","handle","context","eventHandler","event","keys","i","Records","length","record","s3","object","key","push","region","getEnvironment","S3","extension","path","extname","manager","managers","canProcess","process","handler","createHandler","invocationArgs"],"sources":["index.ts"],"sourcesContent":["import path from \"path\";\nimport S3 from \"aws-sdk/clients/s3\";\nimport { HandlerPlugin } from \"@webiny/handler/types\";\nimport { createHandler, getEnvironment, EventHandlerCallable } from \"../utils\";\nimport managers from \"../transform/managers\";\nimport { ArgsContext } from \"@webiny/handler-args/types\";\nimport { ManageHandlerEventArgs } from \"~/handlers/types\";\n\nexport default (): HandlerPlugin<ArgsContext<ManageHandlerEventArgs>> => ({\n type: \"handler\",\n name: \"handler-download-file\",\n async handle(context) {\n // TODO @ts-refactor check in createHandler for returns types that eventHandler must return\n // @ts-ignore\n const eventHandler: EventHandlerCallable<ManageHandlerEventArgs> = async event => {\n const keys: string[] = [];\n for (let i = 0; i < event.Records.length; i++) {\n const record = event.Records[i];\n if (typeof record.s3.object.key === \"string\") {\n keys.push(record.s3.object.key);\n }\n }\n\n const { region } = getEnvironment();\n const s3 = new S3({ region });\n\n for (const key of keys) {\n const extension = path.extname(key);\n\n for (const manager of managers) {\n const canProcess = manager.canProcess({\n key,\n extension\n });\n\n if (!canProcess) {\n continue;\n }\n await manager.process({\n s3,\n key,\n extension\n });\n }\n }\n };\n\n const handler = createHandler(eventHandler);\n\n return await handler(context.invocationArgs);\n }\n});\n"],"mappings":";;;;;;;;;AAAA;;AACA;;AAEA;;AACA;;eAIe,OAA2D;EACtEA,IAAI,EAAE,SADgE;EAEtEC,IAAI,EAAE,uBAFgE;;EAGtE,MAAMC,MAAN,CAAaC,OAAb,EAAsB;IAClB;IACA;IACA,MAAMC,YAA0D,GAAG,MAAMC,KAAN,IAAe;MAC9E,MAAMC,IAAc,GAAG,EAAvB;;MACA,KAAK,IAAIC,CAAC,GAAG,CAAb,EAAgBA,CAAC,GAAGF,KAAK,CAACG,OAAN,CAAcC,MAAlC,EAA0CF,CAAC,EAA3C,EAA+C;QAC3C,MAAMG,MAAM,GAAGL,KAAK,CAACG,OAAN,CAAcD,CAAd,CAAf;;QACA,IAAI,OAAOG,MAAM,CAACC,EAAP,CAAUC,MAAV,CAAiBC,GAAxB,KAAgC,QAApC,EAA8C;UAC1CP,IAAI,CAACQ,IAAL,CAAUJ,MAAM,CAACC,EAAP,CAAUC,MAAV,CAAiBC,GAA3B;QACH;MACJ;;MAED,MAAM;QAAEE;MAAF,IAAa,IAAAC,qBAAA,GAAnB;MACA,MAAML,EAAE,GAAG,IAAIM,UAAJ,CAAO;QAAEF;MAAF,CAAP,CAAX;;MAEA,KAAK,MAAMF,GAAX,IAAkBP,IAAlB,EAAwB;QACpB,MAAMY,SAAS,GAAGC,aAAA,CAAKC,OAAL,CAAaP,GAAb,CAAlB;;QAEA,KAAK,MAAMQ,OAAX,IAAsBC,iBAAtB,EAAgC;UAC5B,MAAMC,UAAU,GAAGF,OAAO,CAACE,UAAR,CAAmB;YAClCV,GADkC;YAElCK;UAFkC,CAAnB,CAAnB;;UAKA,IAAI,CAACK,UAAL,EAAiB;YACb;UACH;;UACD,MAAMF,OAAO,CAACG,OAAR,CAAgB;YAClBb,EADkB;YAElBE,GAFkB;YAGlBK;UAHkB,CAAhB,CAAN;QAKH;MACJ;IACJ,CA/BD;;IAiCA,MAAMO,OAAO,GAAG,IAAAC,oBAAA,EAActB,YAAd,CAAhB;IAEA,OAAO,MAAMqB,OAAO,CAACtB,OAAO,CAACwB,cAAT,CAApB;EACH;;AA1CqE,CAA3D,C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["type","name","handle","context","eventHandler","body","transformations","key","env","getEnvironment","s3","S3","region","optimizedImageObject","params","initial","getObjectParams","optimized","getImageKey","optimizedTransformed","getObject","promise","e","putObject","ContentType","Body","optimizeImage","error","message","transformImage","handler","createHandler","invocationArgs"],"sources":["index.ts"],"sourcesContent":["import S3 from \"aws-sdk/clients/s3\";\nimport transformImage from \"./transformImage\";\nimport optimizeImage from \"./optimizeImage\";\nimport { createHandler, EventHandlerCallable, getEnvironment, getObjectParams } from \"../utils\";\nimport { getImageKey } from \"./utils\";\nimport { HandlerPlugin } from \"@webiny/handler/types\";\nimport { ArgsContext } from \"@webiny/handler-args/types\";\nimport { TransformHandlerEventArgs } from \"~/handlers/types\";\n\nexport default (): HandlerPlugin<ArgsContext<TransformHandlerEventArgs>> => ({\n type: \"handler\",\n name: \"handler-download-file\",\n async handle(context) {\n // TODO @ts-refactor check in createHandler for returns types that eventHandler must return\n // @ts-ignore\n const eventHandler: EventHandlerCallable<TransformHandlerEventArgs> = async ({\n body: { transformations, key }\n }) => {\n try {\n const env = getEnvironment();\n const s3 = new S3({ region: env.region });\n\n let optimizedImageObject: S3.Types.GetObjectOutput;\n\n const params = {\n initial: getObjectParams(key),\n optimized: getObjectParams(getImageKey({ key })),\n optimizedTransformed: getObjectParams(getImageKey({ key, transformations }))\n };\n\n // 1. Get optimized image.\n try {\n optimizedImageObject = await s3.getObject(params.optimized).promise();\n } catch (e) {\n // If not found, try to create it by loading the initially uploaded image.\n optimizedImageObject = await s3.getObject(params.initial).promise();\n\n await s3\n .putObject({\n ...params.optimized,\n ContentType: optimizedImageObject.ContentType,\n Body: await optimizeImage(\n optimizedImageObject.Body as Buffer,\n optimizedImageObject.ContentType as string\n )\n })\n .promise();\n\n optimizedImageObject = await s3.getObject(params.optimized).promise();\n }\n\n // 2. If no transformations requested, just exit.\n if (!transformations) {\n return { error: false, message: \"\" };\n }\n\n // 3. If transformations requested, apply them in save it into the bucket.\n await s3\n .putObject({\n ...params.optimizedTransformed,\n ContentType: optimizedImageObject.ContentType,\n Body: await transformImage(\n optimizedImageObject.Body as Buffer,\n transformations\n )\n })\n .promise();\n\n return { error: false, message: \"\" };\n } catch (e) {\n return { error: true, message: e.message };\n }\n };\n const handler = createHandler(eventHandler);\n\n return await handler(context.invocationArgs);\n }\n});\n"],"mappings":";;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;;;;;eAKe,OAA8D;EACzEA,IAAI,EAAE,SADmE;EAEzEC,IAAI,EAAE,uBAFmE;;EAGzE,MAAMC,MAAN,CAAaC,OAAb,EAAsB;IAClB;IACA;IACA,MAAMC,YAA6D,GAAG,OAAO;MACzEC,IAAI,EAAE;QAAEC,eAAF;QAAmBC;MAAnB;IADmE,CAAP,KAEhE;MACF,IAAI;QACA,MAAMC,GAAG,GAAG,IAAAC,qBAAA,GAAZ;QACA,MAAMC,EAAE,GAAG,IAAIC,UAAJ,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CAACY,IADb,EAERnB,eAFQ;QAJd,IASDe,OATC,EAAN;QAWA,OAAO;UAAEM,KAAK,EAAE,KAAT;UAAgBC,OAAO,EAAE;QAAzB,CAAP;MACH,CAnDD,CAmDE,OAAON,CAAP,EAAU;QACR,OAAO;UAAEK,KAAK,EAAE,IAAT;UAAeC,OAAO,EAAEN,CAAC,CAACM;QAA1B,CAAP;MACH;IACJ,CAzDD;;IA0DA,MAAME,OAAO,GAAG,IAAAC,oBAAA,EAAc3B,YAAd,CAAhB;IAEA,OAAO,MAAM0B,OAAO,CAAC3B,OAAO,CAAC6B,cAAT,CAApB;EACH;;AAnEwE,CAA9D,C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["IMAGE_TRANSFORMER_FUNCTION","process","env","callImageTransformerLambda","key","transformations","context","handlerClient","invoke","name","payload","body","canProcess","params","SUPPORTED_IMAGES","includes","file","extension","s3","options","objectParams","sanitizeImageTransformations","SUPPORTED_TRANSFORMABLE_IMAGES","getObjectParams","getImageKey","object","getObject","promise","e","imageTransformerLambdaResponse","error","Error","message"],"sources":["imageLoader.ts"],"sourcesContent":["import sanitizeImageTransformations from \"./sanitizeImageTransformations\";\nimport { getObjectParams } from \"../../utils\";\nimport { SUPPORTED_IMAGES, SUPPORTED_TRANSFORMABLE_IMAGES, getImageKey } from \"../utils\";\nimport { ClientContext } from \"@webiny/handler-client/types\";\nimport S3 from \"aws-sdk/clients/s3\";\n\nconst IMAGE_TRANSFORMER_FUNCTION = process.env.IMAGE_TRANSFORMER_FUNCTION as string;\n\ninterface TransformerParams {\n context: ClientContext;\n key: string;\n transformations?: any;\n}\n\nconst callImageTransformerLambda = async ({ key, transformations, context }: TransformerParams) => {\n return await context.handlerClient.invoke({\n name: IMAGE_TRANSFORMER_FUNCTION,\n payload: {\n body: {\n key,\n transformations\n }\n }\n });\n};\ninterface File {\n extension: string;\n name: string;\n}\ninterface Options {\n width?: string;\n}\nexport interface CanProcessParams {\n s3: S3;\n file: File;\n options?: Options;\n context: ClientContext;\n}\nexport interface ProcessParams {\n s3: S3;\n file: File;\n options?: Options;\n context: ClientContext;\n}\nexport default {\n canProcess: (params: CanProcessParams) => {\n return SUPPORTED_IMAGES.includes(params.file.extension);\n },\n async process({ s3, file, options, context }: ProcessParams) {\n // Loaders must return {object, params} object.\n let objectParams;\n\n const transformations = sanitizeImageTransformations(options);\n\n if (transformations && SUPPORTED_TRANSFORMABLE_IMAGES.includes(file.extension)) {\n objectParams = getObjectParams(getImageKey({ key: file.name, transformations }));\n try {\n return {\n object: await s3.getObject(objectParams).promise(),\n params: objectParams\n };\n } catch (e) {\n const imageTransformerLambdaResponse = await callImageTransformerLambda({\n key: file.name,\n transformations,\n context\n });\n\n if (imageTransformerLambdaResponse.error) {\n throw Error(imageTransformerLambdaResponse.message);\n }\n\n return {\n object: await s3.getObject(objectParams).promise(),\n params: objectParams\n };\n }\n }\n\n objectParams = getObjectParams(getImageKey({ key: file.name }));\n try {\n return {\n object: await s3.getObject(objectParams).promise(),\n params: objectParams\n };\n } catch (e) {\n const imageTransformerLambdaResponse = await callImageTransformerLambda({\n key: file.name,\n context\n });\n\n if (imageTransformerLambdaResponse.error) {\n throw Error(imageTransformerLambdaResponse.message);\n }\n\n return {\n object: await s3.getObject(objectParams).promise(),\n params: objectParams\n };\n }\n }\n};\n"],"mappings":";;;;;;;;;AAAA;;AACA;;AACA;;AAIA,MAAMA,0BAA0B,GAAGC,OAAO,CAACC,GAAR,CAAYF,0BAA/C;;AAQA,MAAMG,0BAA0B,GAAG,OAAO;EAAEC,GAAF;EAAOC,eAAP;EAAwBC;AAAxB,CAAP,KAAgE;EAC/F,OAAO,MAAMA,OAAO,CAACC,aAAR,CAAsBC,MAAtB,CAA6B;IACtCC,IAAI,EAAET,0BADgC;IAEtCU,OAAO,EAAE;MACLC,IAAI,EAAE;QACFP,GADE;QAEFC;MAFE;IADD;EAF6B,CAA7B,CAAb;AASH,CAVD;;eA8Be;EAC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O;QACHgB,MAAM,EAAE,MAAMP,EAAE,CAACQ,SAAH,CAAaN,YAAb,EAA2BO,OAA3B,EADX;QAEHd,MAAM,EAAEO;MAFL,CAAP;IAIH,CALD,CAKE,OAAOQ,CAAP,EAAU;MACR,MAAMC,8BAA8B,GAAG,MAAM1B,0BAA0B,CAAC;QACpEC,GAAG,EAAEY,IAAI,CAACP,IAD0D;QAEpEH;MAFoE,CAAD,CAAvE;;MAKA,IAAIuB,8BAA8B,CAACC,KAAnC,EAA0C;QACtC,MAAMC,KAAK,CAACF,8BAA8B,CAACG,OAAhC,CAAX;MACH;;MAED,OAAO;QACHP,MAAM,EAAE,MAAMP,EAAE,CAACQ,SAAH,CAAaN,YAAb,EAA2BO,OAA3B,EADX;QAEHd,MAAM,EAAEO;MAFL,CAAP;IAIH;EACJ;;AAxDU,C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["imageLoader"],"sources":["index.ts"],"sourcesContent":["import imageLoader from \"./imageLoader\";\n\nexport default [imageLoader];\n"],"mappings":";;;;;;;;;AAAA;;eAEe,CAACA,oBAAD,C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["SUPPORTED_IMAGE_RESIZE_WIDTHS","args","transformations","width","parseInt","i","length","Object","keys"],"sources":["sanitizeImageTransformations.ts"],"sourcesContent":["const SUPPORTED_IMAGE_RESIZE_WIDTHS: number[] = [100, 300, 500, 750, 1000, 1500, 2500];\n\nexport interface SanitizeImageArgs {\n width?: string;\n}\n\nexport interface SanitizeImageTransformations {\n width: number;\n}\n/**\n * Takes only allowed transformations into consideration, and discards the rest.\n */\nexport default (args?: SanitizeImageArgs): SanitizeImageTransformations | null => {\n const transformations: Partial<SanitizeImageTransformations> = {};\n\n if (!args || !args.width) {\n return null;\n }\n const width = parseInt(args.width);\n if (width <= 0) {\n return null;\n }\n transformations.width = SUPPORTED_IMAGE_RESIZE_WIDTHS[0];\n let i = SUPPORTED_IMAGE_RESIZE_WIDTHS.length;\n while (i >= 0) {\n if (width === SUPPORTED_IMAGE_RESIZE_WIDTHS[i]) {\n transformations.width = SUPPORTED_IMAGE_RESIZE_WIDTHS[i];\n break;\n }\n\n if (width > SUPPORTED_IMAGE_RESIZE_WIDTHS[i]) {\n // Use next larger width. If there isn't any, use current.\n transformations.width = SUPPORTED_IMAGE_RESIZE_WIDTHS[i + 1];\n if (!transformations.width) {\n transformations.width = SUPPORTED_IMAGE_RESIZE_WIDTHS[i];\n }\n break;\n }\n\n i--;\n }\n\n if (Object.keys(transformations).length > 0) {\n /**\n * It is safe to cast.\n */\n return transformations as SanitizeImageTransformations;\n }\n\n return null;\n};\n"],"mappings":";;;;;;AAAA,MAAMA,6BAAuC,GAAG,CAAC,GAAD,EAAM,GAAN,EAAW,GAAX,EAAgB,GAAhB,EAAqB,IAArB,EAA2B,IAA3B,EAAiC,IAAjC,CAAhD;;AASA;AACA;AACA;eACgBC,IAAD,IAAmE;EAC9E,MAAMC,eAAsD,GAAG,EAA/D;;EAEA,IAAI,CAACD,IAAD,IAAS,CAACA,IAAI,CAACE,KAAnB,EAA0B;IACtB,OAAO,IAAP;EACH;;EACD,MAAMA,KAAK,GAAGC,QAAQ,CAACH,IAAI,CAACE,KAAN,CAAtB;;EACA,IAAIA,KAAK,IAAI,CAAb,EAAgB;IACZ,OAAO,IAAP;EACH;;EACDD,eAAe,CAACC,KAAhB,GAAwBH,6BAA6B,CAAC,CAAD,CAArD;EACA,IAAIK,CAAC,GAAGL,6BAA6B,CAACM,MAAtC;;EACA,OAAOD,CAAC,IAAI,CAAZ,EAAe;IACX,IAAIF,KAAK,KAAKH,6BAA6B,CAACK,CAAD,CAA3C,EAAgD;MAC5CH,eAAe,CAACC,KAAhB,GAAwBH,6BAA6B,CAACK,CAAD,CAArD;MACA;IACH;;IAED,IAAIF,KAAK,GAAGH,6BAA6B,CAACK,CAAD,CAAzC,EAA8C;MAC1C;MACAH,eAAe,CAACC,KAAhB,GAAwBH,6BAA6B,CAACK,CAAC,GAAG,CAAL,CAArD;;MACA,IAAI,CAACH,eAAe,CAACC,KAArB,EAA4B;QACxBD,eAAe,CAACC,KAAhB,GAAwBH,6BAA6B,CAACK,CAAD,CAArD;MACH;;MACD;IACH;;IAEDA,CAAC;EACJ;;EAED,IAAIE,MAAM,CAACC,IAAP,CAAYN,eAAZ,EAA6BI,MAA7B,GAAsC,CAA1C,EAA6C;IACzC;AACR;AACA;IACQ,OAAOJ,eAAP;EACH;;EAED,OAAO,IAAP;AACH,C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["canProcess","params","key","extension","SUPPORTED_IMAGES","includes","startsWith","OPTIMIZED_IMAGE_PREFIX","OPTIMIZED_TRANSFORMED_IMAGE_PREFIX","process","s3","deleteObject","getObjectParams","getImageKey","promise","SUPPORTED_TRANSFORMABLE_IMAGES","env","getEnvironment","imagesList","listObjects","Bucket","bucket","Prefix","getOptimizedTransformedImageKeyPrefix","Contents","imageObject","Key"],"sources":["imageManager.ts"],"sourcesContent":["import S3 from \"aws-sdk/clients/s3\";\nimport { getObjectParams, getEnvironment } from \"~/handlers/utils\";\nimport {\n SUPPORTED_IMAGES,\n SUPPORTED_TRANSFORMABLE_IMAGES,\n OPTIMIZED_IMAGE_PREFIX,\n OPTIMIZED_TRANSFORMED_IMAGE_PREFIX,\n getImageKey,\n getOptimizedTransformedImageKeyPrefix\n} from \"../utils\";\n\nexport interface ImageManagerCanProcessParams {\n key: string;\n extension: string;\n}\nexport interface ImageManagerProcessParams {\n s3: S3;\n key: string;\n extension: string;\n}\nexport default {\n canProcess: (params: ImageManagerCanProcessParams) => {\n const { key, extension } = params;\n if (SUPPORTED_IMAGES.includes(extension) === false) {\n return false;\n }\n\n return (\n key.startsWith(OPTIMIZED_IMAGE_PREFIX) ||\n key.startsWith(OPTIMIZED_TRANSFORMED_IMAGE_PREFIX)\n );\n },\n async process({ s3, key, extension }: ImageManagerProcessParams) {\n // 1. Get optimized image's key.\n\n await s3.deleteObject(getObjectParams(getImageKey({ key }))).promise();\n\n // 2. Search for all transformed images and delete those too.\n if (SUPPORTED_TRANSFORMABLE_IMAGES.includes(extension) === false) {\n return;\n }\n const env = getEnvironment();\n const imagesList = await s3\n .listObjects({\n Bucket: env.bucket,\n Prefix: getOptimizedTransformedImageKeyPrefix(key)\n })\n .promise();\n\n if (!imagesList.Contents) {\n return;\n }\n\n for (const imageObject of imagesList.Contents) {\n if (!imageObject.Key) {\n continue;\n }\n await s3.deleteObject(getObjectParams(imageObject.Key)).promise();\n }\n }\n};\n"],"mappings":";;;;;;;AACA;;AACA;;eAkBe;EACXA,UAAU,EAAGC,MAAD,IAA0C;IAClD,MAAM;MAAEC,GAAF;MAAOC;IAAP,IAAqBF,MAA3B;;IACA,IAAIG,wBAAA,CAAiBC,QAAjB,CAA0BF,SAA1B,MAAyC,KAA7C,EAAoD;MAChD,OAAO,KAAP;IACH;;IAED,OACID,GAAG,CAACI,UAAJ,CAAeC,8BAAf,KACAL,GAAG,CAACI,UAAJ,CAAeE,0CAAf,CAFJ;EAIH,CAXU;;EAYX,MAAMC,OAAN,CAAc;IAAEC,EAAF;IAAMR,GAAN;IAAWC;EAAX,CAAd,EAAiE;IAC7D;IAEA,MAAMO,EAAE,CAACC,YAAH,CAAgB,IAAAC,sBAAA,EAAgB,IAAAC,mBAAA,EAAY;MAAEX;IAAF,CAAZ,CAAhB,CAAhB,EAAuDY,OAAvD,EAAN,CAH6D,CAK7D;;IACA,IAAIC,sCAAA,CAA+BV,QAA/B,CAAwCF,SAAxC,MAAuD,KAA3D,EAAkE;MAC9D;IACH;;IACD,MAAMa,GAAG,GAAG,IAAAC,qBAAA,GAAZ;IACA,MAAMC,UAAU,GAAG,MAAMR,EAAE,CACtBS,WADoB,CACR;MACTC,MAAM,EAAEJ,GAAG,CAACK,MADH;MAETC,MAAM,EAAE,IAAAC,6CAAA,EAAsCrB,GAAtC;IAFC,CADQ,EAKpBY,OALoB,EAAzB;;IAOA,IAAI,CAACI,UAAU,CAACM,QAAhB,EAA0B;MACtB;IACH;;IAED,KAAK,MAAMC,WAAX,IAA0BP,UAAU,CAACM,QAArC,EAA+C;MAC3C,IAAI,CAACC,WAAW,CAACC,GAAjB,EAAsB;QAClB;MACH;;MACD,MAAMhB,EAAE,CAACC,YAAH,CAAgB,IAAAC,sBAAA,EAAgBa,WAAW,CAACC,GAA5B,CAAhB,EAAkDZ,OAAlD,EAAN;IACH;EACJ;;AAvCU,C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["imageManager"],"sources":["index.ts"],"sourcesContent":["import imageManager from \"./imageManager\";\n\nexport default [imageManager];\n"],"mappings":";;;;;;;;;AAAA;;eAEe,CAACA,qBAAD,C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["buffer","type","sharp","resize","width","withoutEnlargement","fit","png","compressionLevel","adaptiveFiltering","force","withMetadata","toBuffer","toFormat","quality"],"sources":["optimizeImage.ts"],"sourcesContent":["/**\n * Sharp is included in the AWS Lambda layer\n */\n// @ts-ignore\nimport sharp from \"sharp\";\nimport { Body } from \"aws-sdk/clients/s3\";\n\nexport default async (buffer: Body, type: string): Promise<Body> => {\n switch (type) {\n case \"image/png\": {\n return await sharp(buffer)\n .resize({ width: 2560, withoutEnlargement: true, fit: \"inside\" })\n .png({ compressionLevel: 9, adaptiveFiltering: true, force: true })\n .withMetadata()\n .toBuffer();\n }\n case \"image/jpeg\":\n case \"image/jpg\": {\n return await sharp(buffer)\n .resize({ width: 2560, withoutEnlargement: true, fit: \"inside\" })\n .toFormat(\"jpeg\", { quality: 90 })\n .toBuffer();\n }\n default:\n return buffer;\n }\n};\n"],"mappings":";;;;;;;;;AAIA;;AAJA;AACA;AACA;AACA;eAIe,OAAOA,MAAP,EAAqBC,IAArB,KAAqD;EAChE,QAAQA,IAAR;IACI,KAAK,WAAL;MAAkB;QACd,OAAO,MAAM,IAAAC,cAAA,EAAMF,MAAN,EACRG,MADQ,CACD;UAAEC,KAAK,EAAE,IAAT;UAAeC,kBAAkB,EAAE,IAAnC;UAAyCC,GAAG,EAAE;QAA9C,CADC,EAERC,GAFQ,CAEJ;UAAEC,gBAAgB,EAAE,CAApB;UAAuBC,iBAAiB,EAAE,IAA1C;UAAgDC,KAAK,EAAE;QAAvD,CAFI,EAGRC,YAHQ,GAIRC,QAJQ,EAAb;MAKH;;IACD,KAAK,YAAL;IACA,KAAK,WAAL;MAAkB;QACd,OAAO,MAAM,IAAAV,cAAA,EAAMF,MAAN,EACRG,MADQ,CACD;UAAEC,KAAK,EAAE,IAAT;UAAeC,kBAAkB,EAAE,IAAnC;UAAyCC,GAAG,EAAE;QAA9C,CADC,EAERO,QAFQ,CAEC,MAFD,EAES;UAAEC,OAAO,EAAE;QAAX,CAFT,EAGRF,QAHQ,EAAb;MAIH;;IACD;MACI,OAAOZ,MAAP;EAhBR;AAkBH,C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["buffer","transformations","width","sharp","resize","toBuffer"],"sources":["transformImage.ts"],"sourcesContent":["/**\n * Sharp is included in the AWS Lambda layer\n */\n// @ts-ignore\nimport sharp from \"sharp\";\nimport { Body } from \"aws-sdk/clients/s3\";\n\ninterface Transformation {\n width: string;\n}\n/**\n * Only processing \"width\" at the moment.\n * Check \"sanitizeImageTransformations.js\" to allow additional image processing transformations.\n */\nexport default async (buffer: Body, transformations: Transformation): Promise<Body> => {\n const { width } = transformations;\n return await sharp(buffer).resize({ width }).toBuffer();\n};\n"],"mappings":";;;;;;;;;AAIA;;AAJA;AACA;AACA;AACA;;AAOA;AACA;AACA;AACA;eACe,OAAOA,MAAP,EAAqBC,eAArB,KAAwE;EACnF,MAAM;IAAEC;EAAF,IAAYD,eAAlB;EACA,OAAO,MAAM,IAAAE,cAAA,EAAMH,MAAN,EAAcI,MAAd,CAAqB;IAAEF;EAAF,CAArB,EAAgCG,QAAhC,EAAb;AACH,C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["SUPPORTED_IMAGES","SUPPORTED_TRANSFORMABLE_IMAGES","OPTIMIZED_TRANSFORMED_IMAGE_PREFIX","OPTIMIZED_IMAGE_PREFIX","getOptimizedImageKeyPrefix","key","objectHash","getOptimizedTransformedImageKeyPrefix","getImageKey","transformations","prefix"],"sources":["utils.ts"],"sourcesContent":["import objectHash from \"object-hash\";\n\nconst SUPPORTED_IMAGES = [\".jpg\", \".jpeg\", \".png\", \".svg\", \".gif\"];\nconst SUPPORTED_TRANSFORMABLE_IMAGES = [\".jpg\", \".jpeg\", \".png\"];\n\nconst OPTIMIZED_TRANSFORMED_IMAGE_PREFIX = \"img-o-t-\";\nconst OPTIMIZED_IMAGE_PREFIX = \"img-o-\";\n\nconst getOptimizedImageKeyPrefix = (key: string): string => {\n return `${OPTIMIZED_IMAGE_PREFIX}${objectHash(key)}-`;\n};\n\nconst getOptimizedTransformedImageKeyPrefix = (key: string): string => {\n return `${OPTIMIZED_TRANSFORMED_IMAGE_PREFIX}${objectHash(key)}-`;\n};\n\ninterface GetImageKeyParams {\n key: string;\n transformations?: any;\n}\n\nconst getImageKey = ({ key, transformations }: GetImageKeyParams): string => {\n if (!transformations) {\n const prefix = getOptimizedImageKeyPrefix(key);\n return prefix + key;\n }\n\n const prefix = getOptimizedTransformedImageKeyPrefix(key);\n return `${prefix}${objectHash(transformations)}-${key}`;\n};\n\nexport {\n SUPPORTED_IMAGES,\n SUPPORTED_TRANSFORMABLE_IMAGES,\n OPTIMIZED_TRANSFORMED_IMAGE_PREFIX,\n OPTIMIZED_IMAGE_PREFIX,\n getImageKey,\n getOptimizedImageKeyPrefix,\n getOptimizedTransformedImageKeyPrefix\n};\n"],"mappings":";;;;;;;;;AAAA;;AAEA,MAAMA,gBAAgB,GAAG,CAAC,MAAD,EAAS,OAAT,EAAkB,MAAlB,EAA0B,MAA1B,EAAkC,MAAlC,CAAzB;;AACA,MAAMC,8BAA8B,GAAG,CAAC,MAAD,EAAS,OAAT,EAAkB,MAAlB,CAAvC;;AAEA,MAAMC,kCAAkC,GAAG,UAA3C;;AACA,MAAMC,sBAAsB,GAAG,QAA/B;;;AAEA,MAAMC,0BAA0B,GAAIC,GAAD,IAAyB;EACxD,OAAQ,GAAEF,sBAAuB,GAAE,IAAAG,mBAAA,EAAWD,GAAX,CAAgB,GAAnD;AACH,CAFD;;;;AAIA,MAAME,qCAAqC,GAAIF,GAAD,IAAyB;EACnE,OAAQ,GAAEH,kCAAmC,GAAE,IAAAI,mBAAA,EAAWD,GAAX,CAAgB,GAA/D;AACH,CAFD;;;;AASA,MAAMG,WAAW,GAAG,CAAC;EAAEH,GAAF;EAAOI;AAAP,CAAD,KAAyD;EACzE,IAAI,CAACA,eAAL,EAAsB;IAClB,MAAMC,MAAM,GAAGN,0BAA0B,CAACC,GAAD,CAAzC;IACA,OAAOK,MAAM,GAAGL,GAAhB;EACH;;EAED,MAAMK,MAAM,GAAGH,qCAAqC,CAACF,GAAD,CAApD;EACA,OAAQ,GAAEK,MAAO,GAAE,IAAAJ,mBAAA,EAAWG,eAAX,CAA4B,IAAGJ,GAAI,EAAtD;AACH,CARD"}
|
package/handlers/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["export interface HandlerEventArgs {\n httpMethod: \"POST\" | \"OPTIONS\";\n}\ninterface S3Record {\n s3: {\n object: {\n key?: string;\n };\n };\n}\nexport interface ManageHandlerEventArgs extends HandlerEventArgs {\n Records: S3Record[];\n}\nexport interface DownloadHandlerEventArgs extends HandlerEventArgs {\n pathParameters: {\n path: string;\n };\n queryStringParameters?: {\n width?: string;\n };\n}\n\nexport interface TransformHandlerEventArgs extends HandlerEventArgs {\n body: {\n key: string;\n transformations: {\n width: string;\n };\n };\n}\n\nexport interface HandlerHeaders {\n [key: string]: string | boolean | undefined;\n}\n"],"mappings":""}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["baseHeaders","DEFAULT_CACHE_MAX_AGE","createHandler","eventHandler","event","httpMethod","body","statusCode","headers","data","isBuffer","Buffer","toString","JSON","stringify","error","message","isBase64Encoded","e"],"sources":["createHandler.ts"],"sourcesContent":["import { HandlerEventArgs, HandlerHeaders } from \"~/handlers/types\";\nimport { Body } from \"aws-sdk/clients/s3\";\n\n/**\n * We need to respond with adequate CORS headers.\n */\nconst baseHeaders: HandlerHeaders = {\n \"Access-Control-Allow-Origin\": \"*\",\n \"Access-Control-Allow-Credentials\": true\n};\nconst DEFAULT_CACHE_MAX_AGE = 30758400; // 1 year\n\ninterface EventHandlerResponse {\n data: Body | null;\n statusCode?: number;\n headers: HandlerHeaders;\n}\nexport interface EventHandlerCallable<T> {\n (event: T): Promise<EventHandlerResponse>;\n}\n\nexport const createHandler = <T extends HandlerEventArgs>(\n eventHandler: EventHandlerCallable<T>\n) => {\n return async (event: T) => {\n if (event.httpMethod === \"OPTIONS\") {\n return {\n body: \"\",\n statusCode: 204,\n headers: {\n ...baseHeaders,\n \"Cache-Control\": \"public, max-age=\" + DEFAULT_CACHE_MAX_AGE\n }\n };\n }\n\n try {\n const { data, statusCode, headers = {} } = await eventHandler(event);\n const isBuffer = Buffer.isBuffer(data);\n const body = isBuffer\n ? (data as Buffer).toString(\"base64\")\n : JSON.stringify({\n error: false,\n data,\n message: null\n });\n\n return {\n isBase64Encoded: isBuffer,\n statusCode: statusCode || 200,\n headers: { ...baseHeaders, ...headers },\n body\n };\n } catch (e) {\n return {\n statusCode: 500,\n headers: baseHeaders,\n body: JSON.stringify({\n error: true,\n data: null,\n message: e.message\n })\n };\n }\n };\n};\n"],"mappings":";;;;;;;;;;;;;;;AAGA;AACA;AACA;AACA,MAAMA,WAA2B,GAAG;E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3_BUCKET","region","AWS_REGION"],"sources":["getEnvironment.ts"],"sourcesContent":["export default () => ({\n bucket: process.env.S3_BUCKET as string,\n region: process.env.AWS_REGION as string\n});\n"],"mappings":";;;;;;;eAAe,OAAO;EAClBA,MAAM,EAAEC,OAAO,CAACC,GAAR,CAAYC,SADF;EAElBC,MAAM,EAAEH,OAAO,CAACC,GAAR,CAAYG;AAFF,CAAP,C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["filename","bucket","Bucket","getEnvironment","Key"],"sources":["getObjectParams.ts"],"sourcesContent":["import getEnvironment from \"./getEnvironment\";\n\nexport interface ObjectParamsResponse {\n Bucket: string;\n Key: string;\n}\n/**\n * Returns website's Bucket and file's Key values.\n */\nexport default (filename: string): ObjectParamsResponse => {\n const { bucket: Bucket } = getEnvironment();\n\n return {\n Bucket,\n Key: `${filename}`\n };\n};\n"],"mappings":";;;;;;;;;AAAA;;AAMA;AACA;AACA;eACgBA,QAAD,IAA4C;EACvD,MAAM;IAAEC,MAAM,EAAEC;EAAV,IAAqB,IAAAC,uBAAA,GAA3B;EAEA,OAAO;IACHD,MADG;IAEHE,GAAG,EAAG,GAAEJ,QAAS;EAFd,CAAP;AAIH,C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export { default as getEnvironment } from \"./getEnvironment\";\nexport * from \"./createHandler\";\nexport { default as getObjectParams } from \"./getObjectParams\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AAAA;EAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;;AACA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webiny/api-file-manager",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.29.0-beta.0",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"fm:base"
|
|
@@ -18,20 +18,20 @@
|
|
|
18
18
|
],
|
|
19
19
|
"license": "MIT",
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@babel/runtime": "7.
|
|
21
|
+
"@babel/runtime": "7.18.3",
|
|
22
22
|
"@commodo/fields": "1.1.2-beta.20",
|
|
23
|
-
"@webiny/api-security": "5.
|
|
24
|
-
"@webiny/api-tenancy": "5.
|
|
25
|
-
"@webiny/api-upgrade": "5.
|
|
26
|
-
"@webiny/error": "5.
|
|
27
|
-
"@webiny/handler": "5.
|
|
28
|
-
"@webiny/handler-args": "5.
|
|
29
|
-
"@webiny/handler-client": "5.
|
|
30
|
-
"@webiny/handler-graphql": "5.
|
|
31
|
-
"@webiny/plugins": "5.
|
|
32
|
-
"@webiny/project-utils": "5.
|
|
33
|
-
"@webiny/validation": "5.
|
|
34
|
-
"aws-sdk": "2.
|
|
23
|
+
"@webiny/api-security": "5.29.0-beta.0",
|
|
24
|
+
"@webiny/api-tenancy": "5.29.0-beta.0",
|
|
25
|
+
"@webiny/api-upgrade": "5.29.0-beta.0",
|
|
26
|
+
"@webiny/error": "5.29.0-beta.0",
|
|
27
|
+
"@webiny/handler": "5.29.0-beta.0",
|
|
28
|
+
"@webiny/handler-args": "5.29.0-beta.0",
|
|
29
|
+
"@webiny/handler-client": "5.29.0-beta.0",
|
|
30
|
+
"@webiny/handler-graphql": "5.29.0-beta.0",
|
|
31
|
+
"@webiny/plugins": "5.29.0-beta.0",
|
|
32
|
+
"@webiny/project-utils": "5.29.0-beta.0",
|
|
33
|
+
"@webiny/validation": "5.29.0-beta.0",
|
|
34
|
+
"aws-sdk": "2.1161.0",
|
|
35
35
|
"commodo-fields-object": "1.0.6",
|
|
36
36
|
"mdbid": "1.0.0",
|
|
37
37
|
"object-hash": "1.3.1",
|
|
@@ -44,9 +44,9 @@
|
|
|
44
44
|
"@babel/plugin-transform-runtime": "^7.16.4",
|
|
45
45
|
"@babel/preset-env": "^7.16.4",
|
|
46
46
|
"@babel/preset-typescript": "^7.16.0",
|
|
47
|
-
"@webiny/api-i18n": "^5.
|
|
48
|
-
"@webiny/api-i18n-ddb": "^5.
|
|
49
|
-
"@webiny/cli": "^5.
|
|
47
|
+
"@webiny/api-i18n": "^5.29.0-beta.0",
|
|
48
|
+
"@webiny/api-i18n-ddb": "^5.29.0-beta.0",
|
|
49
|
+
"@webiny/cli": "^5.29.0-beta.0",
|
|
50
50
|
"jest": "^26.6.3",
|
|
51
51
|
"rimraf": "^3.0.2",
|
|
52
52
|
"ttypescript": "^1.5.12",
|
|
@@ -71,5 +71,5 @@
|
|
|
71
71
|
]
|
|
72
72
|
}
|
|
73
73
|
},
|
|
74
|
-
"gitHead": "
|
|
74
|
+
"gitHead": "e221dc575942c512548be142e20c5bd1231edcda"
|
|
75
75
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["FilePlugin","beforeCreate","data","FileModel","createFileModel","fileData","populate","validate","beforeUpdate","updatedFileData","beforeBatchCreate","input","fileInstance"],"sources":["validation.ts"],"sourcesContent":["import { FilePlugin } from \"~/plugins/definitions/FilePlugin\";\nimport createFileModel from \"~/plugins/crud/utils/createFileModel\";\n\nexport default (): FilePlugin[] => [\n new FilePlugin({\n beforeCreate: async ({ data }) => {\n const FileModel = createFileModel();\n const fileData = new FileModel().populate(data);\n await fileData.validate();\n },\n beforeUpdate: async ({ data }) => {\n const FileModel = createFileModel(false);\n const updatedFileData = new FileModel().populate(data);\n await updatedFileData.validate();\n },\n beforeBatchCreate: async ({ data }) => {\n const FileModel = createFileModel();\n for (const input of data) {\n const fileInstance = new FileModel().populate(input);\n await fileInstance.validate();\n }\n }\n })\n];\n"],"mappings":";;;;;;;;;AAAA;;AACA;;eAEe,MAAoB,CAC/B,IAAIA,sBAAJ,CAAe;EACXC,YAAY,EAAE,OAAO;IAAEC;EAAF,CAAP,KAAoB;IAC9B,MAAMC,SAAS,GAAG,IAAAC,wBAAA,GAAlB;IACA,MAAMC,QAAQ,GAAG,IAAIF,SAAJ,GAAgBG,QAAhB,CAAyBJ,IAAzB,CAAjB;IACA,MAAMG,QAAQ,CAACE,QAAT,EAAN;EACH,CALU;EAMXC,YAAY,EAAE,OAAO;IAAEN;EAAF,CAAP,KAAoB;IAC9B,MAAMC,SAAS,GAAG,IAAAC,wBAAA,EAAgB,KAAhB,CAAlB;IACA,MAAMK,eAAe,GAAG,IAAIN,SAAJ,GAAgBG,QAAhB,CAAyBJ,IAAzB,CAAxB;IACA,MAAMO,eAAe,CAACF,QAAhB,EAAN;EACH,CAVU;EAWXG,iBAAiB,EAAE,OAAO;IAAER;EAAF,CAAP,KAAoB;IACnC,MAAMC,SAAS,GAAG,IAAAC,wBAAA,GAAlB;;IACA,KAAK,MAAMO,KAAX,IAAoBT,IAApB,EAA0B;MACtB,MAAMU,YAAY,GAAG,IAAIT,SAAJ,GAAgBG,QAAhB,CAAyBK,KAAzB,CAArB;MACA,MAAMC,YAAY,CAACL,QAAb,EAAN;IACH;EACJ;AAjBU,CAAf,CAD+B,C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["files.crud.ts"],"names":["BATCH_CREATE_MAX_FILES","checkOwnership","file","permission","context","own","identity","security","getIdentity","createdBy","id","NotAuthorizedError","getLocaleCode","i18n","WebinyError","locale","getContentLocale","code","filesContextCrudPlugin","ContextPlugin","pluginType","FilesStorageOperationsProviderPlugin","type","providerPlugin","plugins","byType","find","storageOperations","provide","fileManager","filePlugins","FilePlugin","files","getFile","rwd","get","where","tenant","tenancy","getCurrentTenant","NotFoundError","createFile","input","tags","Array","isArray","meta","private","createdOn","Date","toISOString","displayName","webinyVersion","WEBINY_VERSION","data","result","create","ex","message","updateFile","original","update","deleteFile","delete","createFilesInBatch","inputs","length","map","results","createBatch","listFiles","params","limit","search","types","ids","after","initialWhere","sort","initialSort","type_in","tag_in","tag","toLowerCase","id_in","list","listTags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uYArD,sBAAsB,CAACqE,IAAvB,GAA8B,sBAA9B;eAEerE,sB","sourcesContent":["/**\n * Package mdbid does not have types.\n */\n// @ts-ignore\nimport mdbid from \"mdbid\";\nimport { NotFoundError } from \"@webiny/handler-graphql\";\nimport { NotAuthorizedError } from \"@webiny/api-security\";\nimport {\n CreatedBy,\n File,\n FileManagerContext,\n FileManagerFilesStorageOperationsListParamsWhere,\n FileManagerFilesStorageOperationsTagsParamsWhere,\n FilePermission,\n FilesListOpts\n} from \"~/types\";\nimport checkBasePermissions from \"./utils/checkBasePermissions\";\nimport { ContextPlugin } from \"@webiny/handler\";\nimport { FilePlugin } from \"~/plugins/definitions/FilePlugin\";\nimport { FilesStorageOperationsProviderPlugin } from \"~/plugins/definitions/FilesStorageOperationsProviderPlugin\";\nimport WebinyError from \"@webiny/error\";\nimport { runLifecycleEvent } from \"~/plugins/crud/utils/lifecycleEvents\";\n\nconst BATCH_CREATE_MAX_FILES = 20;\n\n/**\n * If permission is limited to \"own\" files only, check that current identity owns the file.\n */\nconst checkOwnership = (file: File, permission: FilePermission, context: FileManagerContext) => {\n if (permission?.own === true) {\n const identity = context.security.getIdentity();\n if (file.createdBy.id !== identity.id) {\n throw new NotAuthorizedError();\n }\n }\n};\n\nconst getLocaleCode = (context: FileManagerContext): string => {\n if (!context.i18n) {\n throw new WebinyError(\"Missing i18n on the FileManagerContext.\", \"MISSING_I18N\");\n }\n\n const locale = context.i18n.getContentLocale();\n if (!locale) {\n throw new WebinyError(\n \"Missing content locale on the FileManagerContext.\",\n \"MISSING_I18N_CONTENT_LOCALE\"\n );\n }\n\n if (!locale.code) {\n throw new WebinyError(\n \"Missing content locale code on the FileManagerContext.\",\n \"MISSING_I18N_CONTENT_LOCALE_CODE\"\n );\n }\n return locale.code;\n};\n\nconst filesContextCrudPlugin = new ContextPlugin<FileManagerContext>(async context => {\n const pluginType = FilesStorageOperationsProviderPlugin.type;\n\n const providerPlugin = context.plugins\n .byType<FilesStorageOperationsProviderPlugin>(pluginType)\n .find(() => true);\n\n if (!providerPlugin) {\n throw new WebinyError(`Missing \"${pluginType}\" plugin.`, \"PLUGIN_NOT_FOUND\", {\n type: pluginType\n });\n }\n\n const storageOperations = await providerPlugin.provide({\n context\n });\n\n if (!context.fileManager) {\n context.fileManager = {} as any;\n }\n\n const filePlugins = context.plugins.byType<FilePlugin>(FilePlugin.type);\n\n context.fileManager.files = {\n async getFile(id: string) {\n const permission = await checkBasePermissions(context, { rwd: \"r\" });\n\n const file = await storageOperations.get({\n where: {\n id,\n tenant: context.tenancy.getCurrentTenant().id,\n locale: getLocaleCode(context)\n }\n });\n\n if (!file) {\n throw new NotFoundError(`File with id \"${id}\" does not exists.`);\n }\n\n checkOwnership(file, permission, context);\n\n return file;\n },\n async createFile(input) {\n await checkBasePermissions(context, { rwd: \"w\" });\n const identity = context.security.getIdentity();\n const tenant = context.tenancy.getCurrentTenant();\n\n const id = mdbid();\n\n const file: File = {\n ...input,\n tags: Array.isArray(input.tags) ? input.tags : [],\n id,\n meta: {\n private: false,\n ...(input.meta || {})\n },\n tenant: tenant.id,\n createdOn: new Date().toISOString(),\n createdBy: {\n id: identity.id,\n displayName: identity.displayName,\n type: identity.type\n },\n locale: getLocaleCode(context),\n webinyVersion: context.WEBINY_VERSION\n };\n\n try {\n await runLifecycleEvent(\"beforeCreate\", {\n context,\n plugins: filePlugins,\n data: file\n });\n const result = await storageOperations.create({\n file\n });\n await runLifecycleEvent(\"afterCreate\", {\n context,\n plugins: filePlugins,\n data: file,\n file: result\n });\n return result;\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not create a file.\",\n ex.code || \"CREATE_FILE_ERROR\",\n {\n ...(ex.data || {}),\n file\n }\n );\n }\n },\n async updateFile(id, input) {\n const permission = await checkBasePermissions(context, { rwd: \"w\" });\n\n const original = await storageOperations.get({\n where: {\n id,\n tenant: context.tenancy.getCurrentTenant().id,\n locale: getLocaleCode(context)\n }\n });\n\n if (!original) {\n throw new NotFoundError(`File with id \"${id}\" does not exists.`);\n }\n\n checkOwnership(original, permission, context);\n\n const file: File = {\n ...original,\n ...input,\n tags: Array.isArray(input.tags)\n ? input.tags\n : Array.isArray(original.tags)\n ? original.tags\n : [],\n id: original.id,\n webinyVersion: context.WEBINY_VERSION\n };\n\n try {\n await runLifecycleEvent(\"beforeUpdate\", {\n context,\n plugins: filePlugins,\n original,\n data: file\n });\n const result = await storageOperations.update({\n original,\n file\n });\n await runLifecycleEvent(\"afterUpdate\", {\n context,\n plugins: filePlugins,\n original,\n data: file,\n file: result\n });\n return result;\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not update a file.\",\n ex.code || \"UPDATE_FILE_ERROR\",\n {\n ...(ex.data || {}),\n original,\n file\n }\n );\n }\n },\n async deleteFile(id) {\n const permission = await checkBasePermissions(context, { rwd: \"d\" });\n\n const file = await storageOperations.get({\n where: {\n id,\n tenant: context.tenancy.getCurrentTenant().id,\n locale: getLocaleCode(context)\n }\n });\n if (!file) {\n throw new NotFoundError(`File with id \"${id}\" does not exists.`);\n }\n\n checkOwnership(file, permission, context);\n\n try {\n await runLifecycleEvent(\"beforeDelete\", {\n context,\n plugins: filePlugins,\n file\n });\n await storageOperations.delete({\n file\n });\n await runLifecycleEvent(\"afterDelete\", {\n context,\n plugins: filePlugins,\n file\n });\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not delete a file.\",\n ex.code || \"DELETE_FILE_ERROR\",\n {\n ...(ex.data || {}),\n id,\n file\n }\n );\n }\n\n return true;\n },\n async createFilesInBatch(inputs) {\n if (!Array.isArray(inputs)) {\n throw new WebinyError(`\"data\" must be an array.`, \"CREATE_FILES_NON_ARRAY\");\n }\n\n if (inputs.length === 0) {\n throw new WebinyError(\n `\"data\" argument must contain at least one file.`,\n \"CREATE_FILES_MIN_FILES\"\n );\n }\n\n if (inputs.length > BATCH_CREATE_MAX_FILES) {\n throw new WebinyError(\n `\"data\" argument must not contain more than ${BATCH_CREATE_MAX_FILES} files.`,\n \"CREATE_FILES_MAX_FILES\"\n );\n }\n\n await checkBasePermissions(context, { rwd: \"w\" });\n\n const identity = context.security.getIdentity();\n const tenant = context.tenancy.getCurrentTenant();\n const createdBy: CreatedBy = {\n id: identity.id,\n displayName: identity.displayName,\n type: identity.type\n };\n\n const files: File[] = inputs.map(input => {\n return {\n ...input,\n tags: Array.isArray(input.tags) ? input.tags : [],\n meta: {\n private: false,\n ...(input.meta || {})\n },\n id: mdbid(),\n tenant: tenant.id,\n createdOn: new Date().toISOString(),\n createdBy,\n locale: getLocaleCode(context),\n webinyVersion: context.WEBINY_VERSION\n };\n });\n\n try {\n await runLifecycleEvent(\"beforeBatchCreate\", {\n context,\n plugins: filePlugins,\n data: files\n });\n const results = await storageOperations.createBatch({\n files\n });\n await runLifecycleEvent(\"afterBatchCreate\", {\n context,\n plugins: filePlugins,\n data: files,\n files: results\n });\n return results;\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not create a batch of files.\",\n ex.code || \"CREATE_FILES_ERROR\",\n {\n ...(ex.data || {}),\n files\n }\n );\n }\n },\n async listFiles(params: FilesListOpts = {}) {\n const permission = await checkBasePermissions(context, { rwd: \"r\" });\n\n const {\n limit = 40,\n search = \"\",\n types = [],\n tags = [],\n ids = [],\n after = null,\n where: initialWhere,\n sort: initialSort\n } = params;\n\n const where: FileManagerFilesStorageOperationsListParamsWhere = {\n ...initialWhere,\n private: false,\n locale: getLocaleCode(context),\n tenant: context.tenancy.getCurrentTenant().id\n };\n /**\n * Always override the createdBy received from the user, if any.\n */\n if (permission.own === true) {\n const identity = context.security.getIdentity();\n where.createdBy = identity.id;\n }\n /**\n * We need to map the old GraphQL definition to the new one.\n * That GQL definition is marked as deprecated.\n */\n /**\n * To have standardized where objects across the applications, we transform the types into type_in.\n */\n if (Array.isArray(types) && types.length > 0 && !where.type_in) {\n where.type_in = types;\n }\n /**\n * We are assigning search to tag and name search.\n * This should be treated as OR condition in the storage operations.\n */\n if (search && !where.search) {\n where.search = search;\n }\n /**\n * Same as on types/type_in.\n */\n if (Array.isArray(tags) && tags.length > 0 && !where.tag_in) {\n where.tag_in = tags.map(tag => tag.toLowerCase());\n }\n /**\n * Same as on types/type_in.\n */\n if (Array.isArray(ids) && ids.length > 0 && !where.id_in) {\n where.id_in = ids;\n }\n\n const sort =\n Array.isArray(initialSort) && initialSort.length > 0 ? initialSort : [\"id_DESC\"];\n try {\n return await storageOperations.list({\n where,\n after,\n limit,\n sort\n });\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not list files by given parameters.\",\n ex.code || \"FILE_TAG_SEARCH_ERROR\",\n {\n ...(ex.data || {}),\n where,\n after,\n limit,\n sort\n }\n );\n }\n },\n async listTags({ where: initialWhere, after, limit }) {\n await checkBasePermissions(context);\n\n const where: FileManagerFilesStorageOperationsTagsParamsWhere = {\n ...initialWhere,\n tenant: context.tenancy.getCurrentTenant().id,\n locale: getLocaleCode(context)\n };\n\n const params = {\n where,\n limit: limit || 100000,\n after\n };\n\n try {\n const [tags] = await storageOperations.tags(params);\n if (Array.isArray(tags) === false) {\n return [];\n }\n /**\n * just to keep it standardized, sort by the tag ASC\n */\n return tags.sort();\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not search for tags.\",\n ex.code || \"FILE_TAG_SEARCH_ERROR\",\n {\n ...(ex.data || {}),\n params\n }\n );\n }\n }\n };\n});\n\nfilesContextCrudPlugin.name = \"FileManagerFilesCrud\";\n\nexport default filesContextCrudPlugin;\n"]}
|
|
1
|
+
{"version":3,"names":["BATCH_CREATE_MAX_FILES","checkOwnership","file","permission","context","own","identity","security","getIdentity","createdBy","id","NotAuthorizedError","getLocaleCode","i18n","WebinyError","locale","getContentLocale","code","filesContextCrudPlugin","ContextPlugin","pluginType","FilesStorageOperationsProviderPlugin","type","providerPlugin","plugins","byType","find","storageOperations","provide","fileManager","filePlugins","FilePlugin","files","getFile","checkBasePermissions","rwd","get","where","tenant","tenancy","getCurrentTenant","NotFoundError","createFile","input","mdbid","tags","Array","isArray","meta","private","createdOn","Date","toISOString","displayName","webinyVersion","WEBINY_VERSION","runLifecycleEvent","data","result","create","ex","message","updateFile","original","update","deleteFile","delete","createFilesInBatch","inputs","length","map","results","createBatch","listFiles","params","limit","search","types","ids","after","initialWhere","sort","initialSort","type_in","tag_in","tag","toLowerCase","id_in","list","listTags","name"],"sources":["files.crud.ts"],"sourcesContent":["/**\n * Package mdbid does not have types.\n */\n// @ts-ignore\nimport mdbid from \"mdbid\";\nimport { NotFoundError } from \"@webiny/handler-graphql\";\nimport { NotAuthorizedError } from \"@webiny/api-security\";\nimport {\n CreatedBy,\n File,\n FileManagerContext,\n FileManagerFilesStorageOperationsListParamsWhere,\n FileManagerFilesStorageOperationsTagsParamsWhere,\n FilePermission,\n FilesListOpts\n} from \"~/types\";\nimport checkBasePermissions from \"./utils/checkBasePermissions\";\nimport { ContextPlugin } from \"@webiny/handler\";\nimport { FilePlugin } from \"~/plugins/definitions/FilePlugin\";\nimport { FilesStorageOperationsProviderPlugin } from \"~/plugins/definitions/FilesStorageOperationsProviderPlugin\";\nimport WebinyError from \"@webiny/error\";\nimport { runLifecycleEvent } from \"~/plugins/crud/utils/lifecycleEvents\";\n\nconst BATCH_CREATE_MAX_FILES = 20;\n\n/**\n * If permission is limited to \"own\" files only, check that current identity owns the file.\n */\nconst checkOwnership = (file: File, permission: FilePermission, context: FileManagerContext) => {\n if (permission?.own === true) {\n const identity = context.security.getIdentity();\n if (file.createdBy.id !== identity.id) {\n throw new NotAuthorizedError();\n }\n }\n};\n\nconst getLocaleCode = (context: FileManagerContext): string => {\n if (!context.i18n) {\n throw new WebinyError(\"Missing i18n on the FileManagerContext.\", \"MISSING_I18N\");\n }\n\n const locale = context.i18n.getContentLocale();\n if (!locale) {\n throw new WebinyError(\n \"Missing content locale on the FileManagerContext.\",\n \"MISSING_I18N_CONTENT_LOCALE\"\n );\n }\n\n if (!locale.code) {\n throw new WebinyError(\n \"Missing content locale code on the FileManagerContext.\",\n \"MISSING_I18N_CONTENT_LOCALE_CODE\"\n );\n }\n return locale.code;\n};\n\nconst filesContextCrudPlugin = new ContextPlugin<FileManagerContext>(async context => {\n const pluginType = FilesStorageOperationsProviderPlugin.type;\n\n const providerPlugin = context.plugins\n .byType<FilesStorageOperationsProviderPlugin>(pluginType)\n .find(() => true);\n\n if (!providerPlugin) {\n throw new WebinyError(`Missing \"${pluginType}\" plugin.`, \"PLUGIN_NOT_FOUND\", {\n type: pluginType\n });\n }\n\n const storageOperations = await providerPlugin.provide({\n context\n });\n\n if (!context.fileManager) {\n context.fileManager = {} as any;\n }\n\n const filePlugins = context.plugins.byType<FilePlugin>(FilePlugin.type);\n\n context.fileManager.files = {\n async getFile(id: string) {\n const permission = await checkBasePermissions(context, { rwd: \"r\" });\n\n const file = await storageOperations.get({\n where: {\n id,\n tenant: context.tenancy.getCurrentTenant().id,\n locale: getLocaleCode(context)\n }\n });\n\n if (!file) {\n throw new NotFoundError(`File with id \"${id}\" does not exists.`);\n }\n\n checkOwnership(file, permission, context);\n\n return file;\n },\n async createFile(input) {\n await checkBasePermissions(context, { rwd: \"w\" });\n const identity = context.security.getIdentity();\n const tenant = context.tenancy.getCurrentTenant();\n\n const id = mdbid();\n\n const file: File = {\n ...input,\n tags: Array.isArray(input.tags) ? input.tags : [],\n id,\n meta: {\n private: false,\n ...(input.meta || {})\n },\n tenant: tenant.id,\n createdOn: new Date().toISOString(),\n createdBy: {\n id: identity.id,\n displayName: identity.displayName,\n type: identity.type\n },\n locale: getLocaleCode(context),\n webinyVersion: context.WEBINY_VERSION\n };\n\n try {\n await runLifecycleEvent(\"beforeCreate\", {\n context,\n plugins: filePlugins,\n data: file\n });\n const result = await storageOperations.create({\n file\n });\n await runLifecycleEvent(\"afterCreate\", {\n context,\n plugins: filePlugins,\n data: file,\n file: result\n });\n return result;\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not create a file.\",\n ex.code || \"CREATE_FILE_ERROR\",\n {\n ...(ex.data || {}),\n file\n }\n );\n }\n },\n async updateFile(id, input) {\n const permission = await checkBasePermissions(context, { rwd: \"w\" });\n\n const original = await storageOperations.get({\n where: {\n id,\n tenant: context.tenancy.getCurrentTenant().id,\n locale: getLocaleCode(context)\n }\n });\n\n if (!original) {\n throw new NotFoundError(`File with id \"${id}\" does not exists.`);\n }\n\n checkOwnership(original, permission, context);\n\n const file: File = {\n ...original,\n ...input,\n tags: Array.isArray(input.tags)\n ? input.tags\n : Array.isArray(original.tags)\n ? original.tags\n : [],\n id: original.id,\n webinyVersion: context.WEBINY_VERSION\n };\n\n try {\n await runLifecycleEvent(\"beforeUpdate\", {\n context,\n plugins: filePlugins,\n original,\n data: file\n });\n const result = await storageOperations.update({\n original,\n file\n });\n await runLifecycleEvent(\"afterUpdate\", {\n context,\n plugins: filePlugins,\n original,\n data: file,\n file: result\n });\n return result;\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not update a file.\",\n ex.code || \"UPDATE_FILE_ERROR\",\n {\n ...(ex.data || {}),\n original,\n file\n }\n );\n }\n },\n async deleteFile(id) {\n const permission = await checkBasePermissions(context, { rwd: \"d\" });\n\n const file = await storageOperations.get({\n where: {\n id,\n tenant: context.tenancy.getCurrentTenant().id,\n locale: getLocaleCode(context)\n }\n });\n if (!file) {\n throw new NotFoundError(`File with id \"${id}\" does not exists.`);\n }\n\n checkOwnership(file, permission, context);\n\n try {\n await runLifecycleEvent(\"beforeDelete\", {\n context,\n plugins: filePlugins,\n file\n });\n await storageOperations.delete({\n file\n });\n await runLifecycleEvent(\"afterDelete\", {\n context,\n plugins: filePlugins,\n file\n });\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not delete a file.\",\n ex.code || \"DELETE_FILE_ERROR\",\n {\n ...(ex.data || {}),\n id,\n file\n }\n );\n }\n\n return true;\n },\n async createFilesInBatch(inputs) {\n if (!Array.isArray(inputs)) {\n throw new WebinyError(`\"data\" must be an array.`, \"CREATE_FILES_NON_ARRAY\");\n }\n\n if (inputs.length === 0) {\n throw new WebinyError(\n `\"data\" argument must contain at least one file.`,\n \"CREATE_FILES_MIN_FILES\"\n );\n }\n\n if (inputs.length > BATCH_CREATE_MAX_FILES) {\n throw new WebinyError(\n `\"data\" argument must not contain more than ${BATCH_CREATE_MAX_FILES} files.`,\n \"CREATE_FILES_MAX_FILES\"\n );\n }\n\n await checkBasePermissions(context, { rwd: \"w\" });\n\n const identity = context.security.getIdentity();\n const tenant = context.tenancy.getCurrentTenant();\n const createdBy: CreatedBy = {\n id: identity.id,\n displayName: identity.displayName,\n type: identity.type\n };\n\n const files: File[] = inputs.map(input => {\n return {\n ...input,\n tags: Array.isArray(input.tags) ? input.tags : [],\n meta: {\n private: false,\n ...(input.meta || {})\n },\n id: mdbid(),\n tenant: tenant.id,\n createdOn: new Date().toISOString(),\n createdBy,\n locale: getLocaleCode(context),\n webinyVersion: context.WEBINY_VERSION\n };\n });\n\n try {\n await runLifecycleEvent(\"beforeBatchCreate\", {\n context,\n plugins: filePlugins,\n data: files\n });\n const results = await storageOperations.createBatch({\n files\n });\n await runLifecycleEvent(\"afterBatchCreate\", {\n context,\n plugins: filePlugins,\n data: files,\n files: results\n });\n return results;\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not create a batch of files.\",\n ex.code || \"CREATE_FILES_ERROR\",\n {\n ...(ex.data || {}),\n files\n }\n );\n }\n },\n async listFiles(params: FilesListOpts = {}) {\n const permission = await checkBasePermissions(context, { rwd: \"r\" });\n\n const {\n limit = 40,\n search = \"\",\n types = [],\n tags = [],\n ids = [],\n after = null,\n where: initialWhere,\n sort: initialSort\n } = params;\n\n const where: FileManagerFilesStorageOperationsListParamsWhere = {\n ...initialWhere,\n private: false,\n locale: getLocaleCode(context),\n tenant: context.tenancy.getCurrentTenant().id\n };\n /**\n * Always override the createdBy received from the user, if any.\n */\n if (permission.own === true) {\n const identity = context.security.getIdentity();\n where.createdBy = identity.id;\n }\n /**\n * We need to map the old GraphQL definition to the new one.\n * That GQL definition is marked as deprecated.\n */\n /**\n * To have standardized where objects across the applications, we transform the types into type_in.\n */\n if (Array.isArray(types) && types.length > 0 && !where.type_in) {\n where.type_in = types;\n }\n /**\n * We are assigning search to tag and name search.\n * This should be treated as OR condition in the storage operations.\n */\n if (search && !where.search) {\n where.search = search;\n }\n /**\n * Same as on types/type_in.\n */\n if (Array.isArray(tags) && tags.length > 0 && !where.tag_in) {\n where.tag_in = tags.map(tag => tag.toLowerCase());\n }\n /**\n * Same as on types/type_in.\n */\n if (Array.isArray(ids) && ids.length > 0 && !where.id_in) {\n where.id_in = ids;\n }\n\n const sort =\n Array.isArray(initialSort) && initialSort.length > 0 ? initialSort : [\"id_DESC\"];\n try {\n return await storageOperations.list({\n where,\n after,\n limit,\n sort\n });\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not list files by given parameters.\",\n ex.code || \"FILE_TAG_SEARCH_ERROR\",\n {\n ...(ex.data || {}),\n where,\n after,\n limit,\n sort\n }\n );\n }\n },\n async listTags({ where: initialWhere, after, limit }) {\n await checkBasePermissions(context);\n\n const where: FileManagerFilesStorageOperationsTagsParamsWhere = {\n ...initialWhere,\n tenant: context.tenancy.getCurrentTenant().id,\n locale: getLocaleCode(context)\n };\n\n const params = {\n where,\n limit: limit || 100000,\n after\n };\n\n try {\n const [tags] = await storageOperations.tags(params);\n if (Array.isArray(tags) === false) {\n return [];\n }\n /**\n * just to keep it standardized, sort by the tag ASC\n */\n return tags.sort();\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not search for tags.\",\n ex.code || \"FILE_TAG_SEARCH_ERROR\",\n {\n ...(ex.data || {}),\n params\n }\n );\n }\n }\n };\n});\n\nfilesContextCrudPlugin.name = \"FileManagerFilesCrud\";\n\nexport default filesContextCrudPlugin;\n"],"mappings":";;;;;;;;;;;AAIA;;AACA;;AACA;;AAUA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;;;AAEA,MAAMA,sBAAsB,GAAG,EAA/B;AAEA;AACA;AACA;;AACA,MAAMC,cAAc,GAAG,CAACC,IAAD,EAAa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AvB,CAArB;;QACA,IAAI5B,KAAK,CAACC,OAAN,CAAcF,IAAd,MAAwB,KAA5B,EAAmC;UAC/B,OAAO,EAAP;QACH;QACD;AAChB;AACA;;;QACgB,OAAOA,IAAI,CAACoC,IAAL,EAAP;MACH,CATD,CASE,OAAOrB,EAAP,EAAW;QACT,MAAM,IAAI9C,cAAJ,CACF8C,EAAE,CAACC,OAAH,IAAc,4BADZ,EAEFD,EAAE,CAAC3C,IAAH,IAAW,uBAFT,kCAIM2C,EAAE,CAACH,IAAH,IAAW,EAJjB;UAKEiB;QALF,GAAN;MAQH;IACJ;;EA5WuB,CAA5B;AA8WH,CArY8B,CAA/B;AAuYAxD,sBAAsB,CAACwE,IAAvB,GAA8B,sBAA9B;eAEexE,sB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["SETTINGS_KEY","CreateDataModel","withFields","uploadMinFileSize","number","value","validation","create","uploadMaxFileSize","srcPrefix","onSet","endsWith","string","UpdateDataModel","settingsCrudContextPlugin","ContextPlugin","context","pluginType","SettingsStorageOperationsProviderPlugin","type","providerPlugin","plugins","byType","find","WebinyError","storageOperations","provide","fileManager","settings","getSettings","get","createSettings","data","populate","validate","settingsData","toJSON","updateSettings","updatedValue","existingSettings","updatedSettings","onlyDirty","update","original","deleteSettings","delete","name"],"sources":["settings.crud.ts"],"sourcesContent":["/**\n * Package @commodo/fields does not have types.\n */\n// @ts-ignore\nimport { withFields, string, number, onSet } from \"@commodo/fields\";\nimport { validation } from \"@webiny/validation\";\nimport { FileManagerContext, FileManagerSettings } from \"~/types\";\nimport { SettingsStorageOperationsProviderPlugin } from \"~/plugins/definitions/SettingsStorageOperationsProviderPlugin\";\nimport WebinyError from \"@webiny/error\";\nimport { ContextPlugin } from \"@webiny/handler\";\n\n// TODO @ts-refactor verify that this is not used and remove it\nexport const SETTINGS_KEY = \"file-manager\";\n\nconst CreateDataModel = withFields({\n uploadMinFileSize: number({ value: 0, validation: validation.create(\"gte:0\") }),\n uploadMaxFileSize: number({ value: 26214401 }),\n srcPrefix: onSet((value?: string) => {\n // Make sure srcPrefix always ends with forward slash.\n if (typeof value === \"string\") {\n return value.endsWith(\"/\") ? value : value + \"/\";\n }\n return value;\n })(string({ value: \"/files/\" }))\n})();\n\nconst UpdateDataModel = withFields({\n uploadMinFileSize: number({\n validation: validation.create(\"gte:0\")\n }),\n uploadMaxFileSize: number(),\n srcPrefix: onSet((value?: string) => {\n // Make sure srcPrefix always ends with forward slash.\n if (typeof value === \"string\") {\n return value.endsWith(\"/\") ? value : value + \"/\";\n }\n return value;\n })(string())\n})();\n\nconst settingsCrudContextPlugin = new ContextPlugin<FileManagerContext>(async context => {\n const pluginType = SettingsStorageOperationsProviderPlugin.type;\n\n const providerPlugin = context.plugins\n .byType<SettingsStorageOperationsProviderPlugin>(pluginType)\n .find(() => true);\n\n if (!providerPlugin) {\n throw new WebinyError(`Missing \"${pluginType}\" plugin.`, \"PLUGIN_NOT_FOUND\", {\n type: pluginType\n });\n }\n\n const storageOperations = await providerPlugin.provide({\n context\n });\n\n if (!context.fileManager) {\n context.fileManager = {} as any;\n }\n\n context.fileManager.settings = {\n async getSettings() {\n return storageOperations.get();\n },\n async createSettings(data) {\n const settings = new CreateDataModel().populate(data);\n await settings.validate();\n\n const settingsData: FileManagerSettings = await settings.toJSON();\n\n return storageOperations.create({\n data: settingsData\n });\n },\n async updateSettings(data) {\n const updatedValue = new UpdateDataModel().populate(data);\n await updatedValue.validate();\n\n const existingSettings = (await storageOperations.get()) as FileManagerSettings;\n\n const updatedSettings: Partial<FileManagerSettings> = await updatedValue.toJSON({\n onlyDirty: true\n });\n\n return storageOperations.update({\n original: existingSettings,\n data: {\n ...existingSettings,\n ...updatedSettings\n }\n });\n },\n async deleteSettings() {\n await storageOperations.delete();\n\n return true;\n }\n };\n});\n\nsettingsCrudContextPlugin.name = \"FileMangerSettingsCrud\";\n\nexport default settingsCrudContextPlugin;\n"],"mappings":";;;;;;;;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A5D;MAIA,OAAOhB,iBAAiB,CAACiB,MAAlB,CAAyB;QAC5BC,QAAQ,EAAEJ,gBADkB;QAE5BP,IAAI,kCACGO,gBADH,GAEGC,eAFH;MAFwB,CAAzB,CAAP;IAOH,CA/B0B;;IAgC3B,MAAMI,cAAN,GAAuB;MACnB,MAAMnB,iBAAiB,CAACoB,MAAlB,EAAN;MAEA,OAAO,IAAP;IACH;;EApC0B,CAA/B;AAsCH,CA3DiC,CAAlC;AA6DA/B,yBAAyB,CAACgC,IAA1B,GAAiC,wBAAjC;eAEehC,yB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["systemCrudContextPlugin","ContextPlugin","context","pluginType","SystemStorageOperationsProviderPlugin","type","providerPlugin","plugins","byType","find","WebinyError","storageOperations","provide","fileManager","getTenantId","tenancy","getCurrentTenant","id","system","getVersion","get","version","setVersion","data","tenant","update","original","ex","create","install","srcPrefix","identity","security","getIdentity","NotAuthorizedError","installationPlugins","InstallationPlugin","executeCallbacks","settings","createSettings","WEBINY_VERSION","upgrade","upgradePlugins","filter","pl","app","plugin","getApplicablePlugin","deployedVersion","installedAppVersion","upgradeToVersion","apply","name"],"sources":["system.crud.ts"],"sourcesContent":["import { NotAuthorizedError } from \"@webiny/api-security\";\nimport { getApplicablePlugin } from \"@webiny/api-upgrade\";\nimport { FileManagerContext, FileManagerSettings, FileManagerSystem } from \"~/types\";\nimport { UpgradePlugin } from \"@webiny/api-upgrade/types\";\nimport WebinyError from \"@webiny/error\";\nimport { ContextPlugin } from \"@webiny/handler\";\nimport { executeCallbacks } from \"~/utils\";\nimport { InstallationPlugin } from \"~/plugins/definitions/InstallationPlugin\";\nimport { SystemStorageOperationsProviderPlugin } from \"~/plugins/definitions/SystemStorageOperationsProviderPlugin\";\n\nconst systemCrudContextPlugin = new ContextPlugin<FileManagerContext>(async context => {\n const pluginType = SystemStorageOperationsProviderPlugin.type;\n const providerPlugin = context.plugins\n .byType<SystemStorageOperationsProviderPlugin>(pluginType)\n .find(() => true);\n\n if (!providerPlugin) {\n throw new WebinyError(`Missing \"${pluginType}\" plugin.`, \"PLUGIN_NOT_FOUND\", {\n type: pluginType\n });\n }\n\n const storageOperations = await providerPlugin.provide({\n context\n });\n\n if (!context.fileManager) {\n context.fileManager = {} as any;\n }\n\n const getTenantId = (): string => {\n return context.tenancy.getCurrentTenant().id;\n };\n\n context.fileManager.system = {\n async getVersion() {\n const system = await storageOperations.get();\n\n return system ? system.version : null;\n },\n async setVersion(version: string) {\n const system = await storageOperations.get();\n\n if (system) {\n const data: FileManagerSystem = {\n ...system,\n tenant: system.tenant || getTenantId(),\n version\n };\n try {\n await storageOperations.update({\n original: system,\n data\n });\n return;\n } catch (ex) {\n throw new WebinyError(\n \"Could not update the system data.\",\n \"SYSTEM_UPDATE_ERROR\",\n {\n data\n }\n );\n }\n }\n\n const data: FileManagerSystem = {\n version,\n tenant: getTenantId()\n };\n try {\n await storageOperations.create({\n data\n });\n return;\n } catch (ex) {\n throw new WebinyError(\"Could not create the system data.\", \"SYSTEM_CREATE_ERROR\", {\n data\n });\n }\n },\n async install({ srcPrefix }) {\n const identity = context.security.getIdentity();\n if (!identity) {\n throw new NotAuthorizedError();\n }\n const { fileManager } = context;\n const version = await fileManager.system.getVersion();\n\n if (version) {\n throw new WebinyError(\n \"File Manager is already installed.\",\n \"FILES_INSTALL_ABORTED\"\n );\n }\n\n const data: Partial<FileManagerSettings> = {};\n\n if (srcPrefix) {\n data.srcPrefix = srcPrefix;\n }\n\n const installationPlugins = context.plugins.byType<InstallationPlugin>(\n InstallationPlugin.type\n );\n\n await executeCallbacks<InstallationPlugin[\"beforeInstall\"]>(\n installationPlugins,\n \"beforeInstall\",\n {\n context\n }\n );\n\n await fileManager.settings.createSettings(data);\n\n await fileManager.system.setVersion(context.WEBINY_VERSION);\n\n await executeCallbacks<InstallationPlugin[\"afterInstall\"]>(\n installationPlugins,\n \"afterInstall\",\n {\n context\n }\n );\n\n return true;\n },\n async upgrade(version) {\n const identity = context.security.getIdentity();\n if (!identity) {\n throw new NotAuthorizedError();\n }\n\n const upgradePlugins = context.plugins\n .byType<UpgradePlugin>(\"api-upgrade\")\n .filter(pl => pl.app === \"file-manager\");\n\n const plugin = getApplicablePlugin({\n deployedVersion: context.WEBINY_VERSION,\n installedAppVersion: await this.getVersion(),\n upgradePlugins,\n upgradeToVersion: version\n });\n\n await plugin.apply(context);\n\n // Store new app version\n await context.fileManager.system.setVersion(version);\n\n return true;\n }\n };\n});\n\nsystemCrudContextPlugin.name = \"FileManagerSystemCrud\";\n\nexport default systemCrudContextPlugin;\n"],"mappings":";;;;;;;;;;;AAAA;;AACA;;AAGA;;AACA;;AACA;;AACA;;AACA;;;;;;AAEA,MAAMA,uBAAuB,GAAG,IAAIC,sBAAJ,CAAsC,MAAMC,OAAN,IAAiB;EACnF,MAAMC,UAAU,GAAGC,4EAAA,CAAsCC,IAAzD;EACA,MAAMC,cAAc,GAAGJ,OAAO,CAACK,OAAR,CAClBC,MADkB,CAC4BL,UAD5B,EAElBM,IAFkB,CAEb,MAAM,IAFO,CAAvB;;EAIA,IAAI,CAACH,cAAL,EAAqB;IACjB,MAAM,IAAII,cAAJ,CAAiB,YAAWP,UAAW,WAAvC,EAAmD,kBAAnD,EAAuE;MACzEE,IAAI,EAAEF;IADmE,CAAvE,CAAN;EAGH;;EAED,MAAMQ,iBAAiB,GAAG,MAAML,cAAc,CAACM,OAAf,CAAuB;IACnDV;EADmD,CAAvB,CAAhC;;EAIA,IAAI,CAACA,OAAO,CAACW,WAAb,EAA0B;IACtBX,OAAO,CAACW,WAAR,GAAsB,EAAtB;EACH;;EAED,MAAMC,WAAW,GAAG,MAAc;IAC9B,OAAOZ,OAAO,CAACa,OAAR,CAAgBC,gBAAhB,GAAmCC,EAA1C;EACH,CAFD;;EAIAf,OAAO,CAACW,WAAR,CAAoBK,MAApB,GAA6B;IACzB,MAAMC,UAAN,GAAmB;MACf,MAAMD,MAAM,GAAG,M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AmBnB;;MACA,MAAMA,OAAO,CAACW,WAAR,CAAoBK,MAApB,CAA2BI,UAA3B,CAAsCD,OAAtC,CAAN;MAEA,OAAO,IAAP;IACH;;EArHwB,CAA7B;AAuHH,CA/I+B,CAAhC;AAiJArB,uBAAuB,CAACoD,IAAxB,GAA+B,uBAA/B;eAEepD,uB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["context","check","i18n","checkI18NContentPermission","filePermission","security","getPermission","NotAuthorizedError","rwd","hasRwd","filesFilePermission","includes"],"sources":["checkBasePermissions.ts"],"sourcesContent":["import { FileManagerContext, FilePermission } from \"~/types\";\nimport { NotAuthorizedError } from \"@webiny/api-security\";\n\nexport default async (\n context: FileManagerContext,\n check: { rwd?: string } = {}\n): Promise<FilePermission> => {\n await context.i18n.checkI18NContentPermission();\n const filePermission = await context.security.getPermission<FilePermission>(\"fm.file\");\n if (!filePermission) {\n throw new NotAuthorizedError();\n }\n if (check.rwd && !hasRwd(filePermission, check.rwd)) {\n throw new NotAuthorizedError();\n }\n\n return filePermission;\n};\n\nconst hasRwd = (filesFilePermission: FilePermission, rwd: string): boolean => {\n if (typeof filesFilePermission.rwd !== \"string\") {\n return true;\n }\n\n return filesFilePermission.rwd.includes(rwd);\n};\n"],"mappings":";;;;;;;AACA;;eAEe,OACXA,OADW,EAEXC,KAAuB,GAAG,EAFf,KAGe;EAC1B,MAAMD,OAAO,CAACE,IAAR,CAAaC,0BAAb,EAAN;EACA,MAAMC,cAAc,GAAG,MAAMJ,OAAO,CAACK,QAAR,CAAiBC,aAAjB,CAA+C,SAA/C,CAA7B;;EACA,IAAI,CAACF,cAAL,EAAqB;IACjB,MAAM,IAAIG,+BAAJ,EAAN;EACH;;EACD,IAAIN,KAAK,CAACO,GAAN,IAAa,CAACC,MAAM,CAACL,cAAD,EAAiBH,KAAK,CAACO,GAAvB,CAAxB,EAAqD;IACjD,MAAM,IAAID,+BAAJ,EAAN;EACH;;EAED,OAAOH,cAAP;AACH,C;;;;AAED,MAAMK,MAAM,GAAG,CAACC,mBAAD,EAAsCF,GAAtC,KAA+D;EAC1E,IAAI,OAAOE,mBAAmB,CAACF,GAA3B,KAAmC,QAAvC,EAAiD;IAC7C,OAAO,IAAP;EACH;;EAED,OAAOE,mBAAmB,CAACF,GAApB,CAAwBG,QAAxB,CAAiCH,GAAjC,CAAP;AACH,CAND"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["create","withFields","key","string","validation","name","size","number","type","meta","object","value","private","tags","onSet","Array","isArray","map","item","toLowerCase","list","length","Error","i","tag"],"sources":["createFileModel.ts"],"sourcesContent":["/**\n * Package @commodo/fields does not have types\n */\n// @ts-ignore\nimport { withFields, string, number, onSet } from \"@commodo/fields\";\n/**\n * Package commodo-fields-object does not have types\n */\n// @ts-ignore\nimport { object } from \"commodo-fields-object\";\nimport { validation } from \"@webiny/validation\";\n\n/**\n * TODO @ts-refactor change for JOI or some other validation library\n */\nexport default (create = true) => {\n return withFields({\n key: string({\n validation: validation.create(`${create ? \"required,\" : \"\"}maxLength:1000`)\n }),\n name: string({ validation: validation.create(\"maxLength:1000\") }),\n size: number(),\n type: string({ validation: validation.create(\"maxLength:255\") }),\n meta: object({ value: { private: false } }),\n tags: onSet((value: string[]) => {\n if (!Array.isArray(value)) {\n return null;\n }\n\n return value.map(item => item.toLowerCase());\n })(\n string({\n list: true,\n validation: (tags: string[]) => {\n if (!Array.isArray(tags)) {\n return;\n }\n\n if (tags.length > 15) {\n throw Error(\"You cannot set more than 15 tags.\");\n }\n\n for (let i = 0; i < tags.length; i++) {\n const tag = tags[i];\n if (typeof tag !== \"string\") {\n throw Error(\"Tag must be typeof string.\");\n }\n\n if (tag.length > 50) {\n throw Error(`Tag ${tag} is more than 50 characters long.`);\n }\n }\n }\n })\n )\n })();\n};\n"],"mappings":";;;;;;;AAIA;;AAKA;;AACA;;AAVA;AACA;AACA;AACA;;AAEA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GAAG,GAAGX,IAAI,CAACU,CAAD,CAAhB;;UACA,IAAI,OAAOC,GAAP,KAAe,QAAnB,EAA6B;YACzB,MAAMF,KAAK,CAAC,4BAAD,CAAX;UACH;;UAED,IAAIE,GAAG,CAACH,MAAJ,GAAa,EAAjB,EAAqB;YACjB,MAAMC,KAAK,CAAE,OAAME,GAAI,mCAAZ,CAAX;UACH;QACJ;MACJ;IArBE,CAAP,CAPE;EARQ,CAAX,GAAP;AAwCH,C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["runLifecycleEvent","hook","params","plugins","rest","length","plugin"],"sources":["lifecycleEvents.ts"],"sourcesContent":["// TODO @ts-refactor introduce pubsub methods\nimport { FilePlugin, FilePluginParams } from \"~/plugins/definitions/FilePlugin\";\nimport { FileManagerContext } from \"~/types\";\n\nexport const runLifecycleEvent = async (\n hook: keyof FilePluginParams,\n params: { context: FileManagerContext; plugins: FilePlugin[] } & Record<string, any>\n): Promise<void> => {\n const { plugins, ...rest } = params;\n if (plugins.length === 0) {\n return;\n }\n for (const plugin of plugins) {\n if (!plugin[hook]) {\n continue;\n }\n /**\n * Keep any because we do not know which hook needs to be executed. This will be removed, so it does not matter.\n */\n await plugin[hook](rest as any);\n }\n};\n"],"mappings":";;;;;;;;;;;;;AAAA;AAIO,MAAMA,iBAAiB,GAAG,OAC7BC,IAD6B,EAE7BC,MAF6B,KAGb;EAChB,MAAM;IAAEC;EAAF,IAAuBD,MAA7B;EAAA,MAAoBE,IAApB,0CAA6BF,MAA7B;;EACA,IAAIC,OAAO,CAACE,MAAR,KAAmB,CAAvB,EAA0B;IACtB;EACH;;EACD,KAAK,MAAMC,MAAX,IAAqBH,OAArB,EAA8B;IAC1B,IAAI,CAACG,MAAM,CAACL,IAAD,CAAX,EAAmB;MACf;IACH;IACD;AACR;AACA;;;IACQ,MAAMK,MAAM,CAACL,IAAD,CAAN,CAAaG,IAAb,CAAN;EACH;AACJ,CAjBM"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["FilePhysicalStoragePlugin","Plugin","constructor","params","_params","upload","WebinyError","delete"],"sources":["FilePhysicalStoragePlugin.ts"],"sourcesContent":["import { Plugin } from \"@webiny/plugins\";\nimport WebinyError from \"@webiny/error\";\nimport { FileManagerSettings } from \"~/types\";\n\nexport interface FilePhysicalStoragePluginParams<\n U extends FilePhysicalStoragePluginUploadParams,\n D extends FilePhysicalStoragePluginDeleteParams\n> {\n upload: (args: U) => Promise<any>;\n delete: (args: D) => Promise<void>;\n}\n\nexport interface FilePhysicalStoragePluginUploadParams {\n settings: FileManagerSettings;\n buffer: Buffer;\n}\n\nexport interface FilePhysicalStoragePluginDeleteParams {\n key: string;\n}\n\nexport class FilePhysicalStoragePlugin<\n U extends FilePhysicalStoragePluginUploadParams = FilePhysicalStoragePluginUploadParams,\n D extends FilePhysicalStoragePluginDeleteParams = FilePhysicalStoragePluginDeleteParams\n> extends Plugin {\n public static override readonly type: string = \"api-file-manager-storage\";\n private readonly _params: FilePhysicalStoragePluginParams<U, D>;\n\n public constructor(params: FilePhysicalStoragePluginParams<U, D>) {\n super();\n this._params = params;\n }\n\n public async upload(params: U): Promise<any> {\n if (!this._params.upload) {\n throw new WebinyError(\n `You must define the \"upload\" method of this plugin.`,\n \"UPLOAD_METHOD_ERROR\"\n );\n }\n return this._params.upload(params);\n }\n\n public async delete(params: D): Promise<any> {\n if (!this._params.delete) {\n throw new WebinyError(\n `You must define the \"delete\" method of this plugin.`,\n \"DELETE_METHOD_ERROR\"\n );\n }\n return this._params.delete(params);\n }\n}\n"],"mappings":";;;;;;;;;;;AAAA;;AACA;;AAoBO,MAAMA,yBAAN,SAGGC,eAHH,CAGU;EAINC,WAAW,CAACC,MAAD,EAAgD;IAC9D;IAD8D;IAE9D,KAAKC,OAAL,GAAeD,MAAf;EACH;;EAEkB,MAANE,MAAM,CAACF,MAAD,EAA0B;IACzC,IAAI,CAAC,KAAKC,OAAL,CAAaC,MAAlB,EAA0B;MACtB,MAAM,IAAIC,cAAJ,CACD,qDADC,EAEF,qBAFE,CAAN;IAIH;;IACD,OAAO,KAAKF,OAAL,CAAaC,MAAb,CAAoBF,MAApB,CAAP;EACH;;EAEkB,MAANI,MAAM,CAACJ,MAAD,EAA0B;IACzC,IAAI,CAAC,KAAKC,OAAL,CAAaG,MAAlB,EAA0B;MACtB,MAAM,IAAID,cAAJ,CACD,qDADC,EAEF,qBAFE,CAAN;IAIH;;IACD,OAAO,KAAKF,OAAL,CAAaG,MAAb,CAAoBJ,MAApB,CAAP;EACH;;AA3BY;;;8BAHJH,yB,UAIsC,0B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["FilePlugin","Plugin","constructor","params","_params","beforeCreate","_execute","afterCreate","beforeUpdate","afterUpdate","beforeBatchCreate","afterBatchCreate","beforeDelete","afterDelete","callback","cb"],"sources":["FilePlugin.ts"],"sourcesContent":["import { Plugin } from \"@webiny/plugins\";\nimport { File, FileManagerContext } from \"~/types\";\n\n/**\n * Parameters for beforeCreate lifecycle.\n */\nexport interface BeforeCreateParams {\n context: FileManagerContext;\n /**\n * Data to be inserted into the storage.\n */\n data: File;\n}\n/**\n * Parameters for afterCreate lifecycle.\n */\nexport interface AfterCreateParams {\n context: FileManagerContext;\n /**\n * Data that was inserted into the storage.\n */\n data: File;\n /**\n * Result of the storage operations create method.\n * Possibly changed something on the \"data\".\n */\n file: File;\n}\n/**\n * Parameters for beforeUpdate lifecycle.\n */\nexport interface BeforeUpdateParams {\n context: FileManagerContext;\n /**\n * Original file from the storage.\n */\n original: File;\n /**\n * Data to be updated to the storage.\n */\n data: File;\n}\n/**\n * Parameters for afterUpdate lifecycle.\n */\nexport interface AfterUpdateParams {\n context: FileManagerContext;\n /**\n * Original file from the storage.\n */\n original: File;\n /**\n * Data that was updated in the storage.\n */\n data: File;\n /**\n * Result of the storage operations update method.\n * Possibly changed something on the \"data\".\n */\n file: File;\n}\n/**\n * Parameters for beforeBatchCreate lifecycle.\n */\nexport interface BeforeBatchCreateParams {\n context: FileManagerContext;\n /**\n * Files to be inserted into the storage.\n */\n data: File[];\n}\n\n/**\n * Parameters for afterBatchCreate lifecycle.\n */\nexport interface AfterBatchCreateParams {\n context: FileManagerContext;\n /**\n * Files that were inserted into the storage.\n */\n data: File[];\n /**\n * Results of the insert.\n */\n files: File[];\n}\n/**\n * Parameters for beforeDelete lifecycle.\n */\nexport interface BeforeDeleteParams {\n context: FileManagerContext;\n /**\n * File to be deleted from the storage.\n */\n file: File;\n}\n/**\n * Parameters for afterDelete lifecycle.\n */\nexport interface AfterDeleteParams {\n context: FileManagerContext;\n /**\n * File that was deleted from the storage.\n */\n file: File;\n}\n\n/**\n * Definition for the constructor parameters of the FilePlugin.\n *\n * @category FilePlugin\n */\nexport interface FilePluginParams {\n beforeCreate?: (params: BeforeCreateParams) => Promise<void>;\n afterCreate?: (params: AfterCreateParams) => Promise<void>;\n beforeUpdate?: (params: BeforeUpdateParams) => Promise<void>;\n afterUpdate?: (params: AfterUpdateParams) => Promise<void>;\n beforeBatchCreate?: (params: BeforeBatchCreateParams) => Promise<void>;\n afterBatchCreate?: (params: AfterBatchCreateParams) => Promise<void>;\n beforeDelete?: (params: BeforeDeleteParams) => Promise<void>;\n afterDelete?: (params: AfterDeleteParams) => Promise<void>;\n}\n\nexport class FilePlugin extends Plugin {\n public static override readonly type: string = \"fm.file\";\n private readonly _params: FilePluginParams;\n\n public constructor(params?: FilePluginParams) {\n super();\n this._params = params || ({} as any);\n }\n\n public async beforeCreate(params: BeforeCreateParams): Promise<void> {\n await this._execute(\"beforeCreate\", params);\n }\n\n public async afterCreate(params: AfterCreateParams): Promise<void> {\n await this._execute(\"afterCreate\", params);\n }\n\n public async beforeUpdate(params: BeforeUpdateParams): Promise<void> {\n await this._execute(\"beforeUpdate\", params);\n }\n\n public async afterUpdate(params: AfterUpdateParams): Promise<void> {\n await this._execute(\"afterUpdate\", params);\n }\n\n public async beforeBatchCreate(params: BeforeBatchCreateParams): Promise<void> {\n await this._execute(\"beforeBatchCreate\", params);\n }\n\n public async afterBatchCreate(params: AfterBatchCreateParams): Promise<void> {\n await this._execute(\"afterBatchCreate\", params);\n }\n\n public async beforeDelete(params: BeforeDeleteParams): Promise<void> {\n await this._execute(\"beforeDelete\", params);\n }\n\n public async afterDelete(params: AfterDeleteParams): Promise<void> {\n await this._execute(\"afterDelete\", params);\n }\n /**\n * Keep any here because it can be a number of params. Method is internal so no need to complicate the code.\n */\n private async _execute(callback: keyof FilePluginParams, params: any): Promise<void> {\n const cb = this._params[callback];\n if (typeof cb !== \"function\") {\n return;\n }\n await cb(params);\n }\n}\n"],"mappings":";;;;;;;;;;;AAAA;;AA2HO,MAAMA,UAAN,SAAyBC,eAAzB,CAAgC;EAI5BC,WAAW,CAACC,MAAD,EAA4B;IAC1C;IAD0C;IAE1C,KAAKC,OAAL,GAAeD,MAAM,IAAK,EAA1B;EACH;;EAEwB,MAAZE,YAAY,CAACF,MAAD,EAA4C;IACjE,MAAM,KAAKG,QAAL,CAAc,cAAd,EAA8BH,MAA9B,CAAN;EACH;;EAEuB,MAAXI,WAAW,CAACJ,MAAD,EAA2C;IAC/D,MAAM,KAAKG,QAAL,CAAc,aAAd,EAA6BH,MAA7B,CAAN;EACH;;EAEwB,MAAZK,YAAY,CAACL,MAAD,EAA4C;IACjE,MAAM,KAAKG,QAAL,CAAc,cAAd,EAA8BH,MAA9B,CAAN;EACH;;EAEuB,MAAXM,WAAW,CAACN,MAAD,EAA2C;IAC/D,MAAM,KAAKG,QAAL,CAAc,aAAd,EAA6BH,MAA7B,CAAN;EACH;;EAE6B,MAAjBO,iBAAiB,CAACP,MAAD,EAAiD;IAC3E,MAAM,KAAKG,QAAL,CAAc,mBAAd,EAAmCH,MAAnC,CAAN;EACH;;EAE4B,MAAhBQ,gBAAgB,CAACR,MAAD,EAAgD;IACzE,MAAM,KAAKG,QAAL,CAAc,kBAAd,EAAkCH,MAAlC,CAAN;EACH;;EAEwB,MAAZS,YAAY,CAACT,MAAD,EAA4C;IACjE,MAAM,KAAKG,QAAL,CAAc,cAAd,EAA8BH,MAA9B,CAAN;EACH;;EAEuB,MAAXU,WAAW,CAACV,MAAD,EAA2C;IAC/D,MAAM,KAAKG,QAAL,CAAc,aAAd,EAA6BH,MAA7B,CAAN;EACH;EACD;AACJ;AACA;;;EAC0B,MAARG,QAAQ,CAACQ,QAAD,EAAmCX,MAAnC,EAA+D;IACjF,MAAMY,EAAE,GAAG,KAAKX,OAAL,CAAaU,QAAb,CAAX;;IACA,IAAI,OAAOC,EAAP,KAAc,UAAlB,EAA8B;MAC1B;IACH;;IACD,MAAMA,EAAE,CAACZ,MAAD,CAAR;EACH;;AAjDkC;;;8BAA1BH,U,UACsC,S"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["FileStorageTransformPlugin","Plugin","constructor","params","_params","toStorage","file","fromStorage"],"sources":["FileStorageTransformPlugin.ts"],"sourcesContent":["import { Plugin } from \"@webiny/plugins\";\nimport { File } from \"~/types\";\n\nexport interface FileStorageTransformPluginToParams {\n /**\n * File that is being sent to the storage operations method.\n */\n file: File & Record<string, any>;\n}\n\nexport interface FileStorageTransformPluginFromParams {\n /**\n * File that was fetched from the storage operations method.\n */\n file: File & Record<string, any>;\n}\n\nexport interface FileStorageTransformPluginParams {\n toStorage?: (params: FileStorageTransformPluginToParams) => Promise<File & Record<string, any>>;\n fromStorage?: (\n params: FileStorageTransformPluginFromParams\n ) => Promise<File & Record<string, any>>;\n}\n\nexport class FileStorageTransformPlugin extends Plugin {\n public static override readonly type: string = \"fm.files.storage.transform\";\n private readonly _params: FileStorageTransformPluginParams;\n\n public constructor(params: FileStorageTransformPluginParams) {\n super();\n\n this._params = params;\n }\n\n /**\n * Transform the file value into something that can be stored.\n * Be aware that you must return the whole file object.\n */\n public async toStorage(\n params: FileStorageTransformPluginToParams\n ): Promise<File & Record<string, any>> {\n if (!this._params.toStorage) {\n return params.file;\n }\n return this._params.toStorage(params);\n }\n /**\n * Transform the file value from the storage type to one required by our system.\n * Be aware that you must return the whole file object.\n * This method MUST reverse what ever toStorage method changed on the file object.\n */\n public async fromStorage(\n params: FileStorageTransformPluginFromParams\n ): Promise<File & Record<string, any>> {\n if (!this._params.fromStorage) {\n return params.file;\n }\n return this._params.fromStorage(params);\n }\n}\n"],"mappings":";;;;;;;;;;;AAAA;;AAwBO,MAAMA,0BAAN,SAAyCC,eAAzC,CAAgD;EAI5CC,WAAW,CAACC,MAAD,EAA2C;IACzD;IADyD;IAGzD,KAAKC,OAAL,GAAeD,MAAf;EACH;EAED;AACJ;AACA;AACA;;;EAC0B,MAATE,SAAS,CAClBF,MADkB,EAEiB;IACnC,IAAI,CAAC,KAAKC,OAAL,CAAaC,SAAlB,EAA6B;MACzB,OAAOF,MAAM,CAACG,IAAd;IACH;;IACD,OAAO,KAAKF,OAAL,CAAaC,SAAb,CAAuBF,MAAvB,CAAP;EACH;EACD;AACJ;AACA;AACA;AACA;;;EAC4B,MAAXI,WAAW,CACpBJ,MADoB,EAEe;IACnC,IAAI,CAAC,KAAKC,OAAL,CAAaG,WAAlB,EAA+B;MAC3B,OAAOJ,MAAM,CAACG,IAAd;IACH;;IACD,OAAO,KAAKF,OAAL,CAAaG,WAAb,CAAyBJ,MAAzB,CAAP;EACH;;AAlCkD;;;8BAA1CH,0B,UACsC,4B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["FilesStorageOperationsProviderPlugin","Plugin"],"sources":["FilesStorageOperationsProviderPlugin.ts"],"sourcesContent":["import { Plugin } from \"@webiny/plugins\";\nimport { FileManagerContext, FileManagerFilesStorageOperations } from \"~/types\";\n\nexport interface FilesStorageOperationsProviderPluginParams<T = FileManagerContext> {\n context: T;\n}\n\nexport abstract class FilesStorageOperationsProviderPlugin extends Plugin {\n public static override readonly type: string = \"fm.storageOperationsProvider.files\";\n\n public abstract provide(\n params: FilesStorageOperationsProviderPluginParams\n ): Promise<FileManagerFilesStorageOperations>;\n}\n"],"mappings":";;;;;;;;;;;AAAA;;AAOO,MAAeA,oCAAf,SAA4DC,eAA5D,CAAmE;;;8BAApDD,oC,UAC6B,oC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["InstallationPlugin","Plugin","constructor","config","_config","beforeInstall","params","_execute","afterInstall","callback","cb"],"sources":["InstallationPlugin.ts"],"sourcesContent":["import { FileManagerContext } from \"~/types\";\nimport { Plugin } from \"@webiny/plugins\";\n\nexport interface InstallationPluginParams {\n context: FileManagerContext;\n}\nexport type CallbackFunction<TParams> = (params: TParams) => Promise<void>;\n\ninterface InstallationPluginConfig {\n beforeInstall?: CallbackFunction<InstallationPluginParams>;\n afterInstall?: CallbackFunction<InstallationPluginParams>;\n}\n\nexport abstract class InstallationPlugin extends Plugin {\n public static override readonly type: string = \"fm.install\";\n private readonly _config: Partial<InstallationPluginConfig>;\n\n constructor(config?: Partial<InstallationPluginConfig>) {\n super();\n this._config = config || {};\n }\n\n public async beforeInstall(params: InstallationPluginParams): Promise<void> {\n return this._execute(\"beforeInstall\", params);\n }\n\n public async afterInstall(params: InstallationPluginParams): Promise<void> {\n return this._execute(\"afterInstall\", params);\n }\n\n private async _execute(\n callback: keyof InstallationPluginConfig,\n params: InstallationPluginParams\n ): Promise<void> {\n const cb = this._config[callback];\n if (!cb) {\n return;\n }\n return cb(params);\n }\n}\n"],"mappings":";;;;;;;;;;;AACA;;AAYO,MAAeA,kBAAf,SAA0CC,eAA1C,CAAiD;EAIpDC,WAAW,CAACC,MAAD,EAA6C;IACpD;IADoD;IAEpD,KAAKC,OAAL,GAAeD,MAAM,IAAI,EAAzB;EACH;;EAEyB,MAAbE,aAAa,CAACC,MAAD,EAAkD;IACxE,OAAO,KAAKC,QAAL,CAAc,eAAd,EAA+BD,MAA/B,CAAP;EACH;;EAEwB,MAAZE,YAAY,CAACF,MAAD,EAAkD;IACvE,OAAO,KAAKC,QAAL,CAAc,cAAd,EAA8BD,MAA9B,CAAP;EACH;;EAEqB,MAARC,QAAQ,CAClBE,QADkB,EAElBH,MAFkB,EAGL;IACb,MAAMI,EAAE,GAAG,KAAKN,OAAL,CAAaK,QAAb,CAAX;;IACA,IAAI,CAACC,EAAL,EAAS;MACL;IACH;;IACD,OAAOA,EAAE,CAACJ,MAAD,CAAT;EACH;;AA1BmD;;;8BAAlCN,kB,UAC6B,Y"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["SettingsStorageOperationsProviderPlugin","Plugin"],"sources":["SettingsStorageOperationsProviderPlugin.ts"],"sourcesContent":["import { Plugin } from \"@webiny/plugins\";\nimport { FileManagerContext, FileManagerSettingsStorageOperations } from \"~/types\";\n\nexport interface SettingsStorageOperationsProviderPluginParams<T = FileManagerContext> {\n context: T;\n}\n\nexport abstract class SettingsStorageOperationsProviderPlugin extends Plugin {\n public static override readonly type: string = \"fm.storageOperationsProvider.settings\";\n\n public abstract provide(\n params: SettingsStorageOperationsProviderPluginParams\n ): Promise<FileManagerSettingsStorageOperations>;\n}\n"],"mappings":";;;;;;;;;;;AAAA;;AAOO,MAAeA,uCAAf,SAA+DC,eAA/D,CAAsE;;;8BAAvDD,uC,UAC6B,uC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["SystemStorageOperationsProviderPlugin","Plugin"],"sources":["SystemStorageOperationsProviderPlugin.ts"],"sourcesContent":["import { Plugin } from \"@webiny/plugins\";\nimport { FileManagerContext, FileManagerSystemStorageOperations } from \"~/types\";\n\nexport interface SystemStorageOperationsProviderPluginParams<T = FileManagerContext> {\n context: T;\n}\n\nexport abstract class SystemStorageOperationsProviderPlugin extends Plugin {\n public static override readonly type: string = \"fm.storageOperationsProvider.system\";\n\n public abstract provide(\n params: SystemStorageOperationsProviderPluginParams\n ): Promise<FileManagerSystemStorageOperations>;\n}\n"],"mappings":";;;;;;;;;;;AAAA;;AAOO,MAAeA,qCAAf,SAA6DC,eAA7D,CAAoE;;;8BAArDD,qC,UAC6B,qC"}
|
package/plugins/graphql.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["graphql.ts"],"names":["emptyResolver","resolve","fn","Response","e","ErrorResponse","plugin","type","schema","typeDefs","resolvers","File","src","file","_","context","settings","fileManager","getSettings","srcPrefix","key","Query","Mutation","FmQuery","getFile","args","files","id","listFiles","data","meta","ListResponse","listTags","error","version","__","i18n","tenancy","getCurrentTenant","getContentLocale","system","getVersion","FmMutation","createFile","updateFile","createFiles","createFilesInBatch","deleteFile","storage","delete","install","upgrade","updateSettings"],"mappings":";;;;;;;AAAA;;AAIA,MAAMA,aAAa,GAAG,OAAO,EAAP,CAAtB;AAEA;AACA;AACA;AACA;;;AAKA,MAAMC,OAAO,GAAG,MAAOC,EAAP,IAA+B;AAC3C,MAAI;AACA,WAAO,IAAIC,wBAAJ,CAAa,MAAMD,EAAE,EAArB,CAAP;AACH,GAFD,CAEE,OAAOE,CAAP,EAAU;AACR,WAAO,IAAIC,6BAAJ,CAAkBD,CAAlB,CAAP;AACH;AACJ,CAND;;AAQA,MAAME,MAA+C,GAAG;AACpDC,EAAAA,IAAI,EAAE,gBAD8C;AAEpDC,EAAAA,MAAM,EAAE;AACJC,IAAAA,QAAQ;AAAE;AAAe;AACjC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAnKY;AAoKJC,IAAAA,SAAS,EAAE;AACPC,MAAAA,IAAI,EAAE;AACF,cAAMC,GAAN,CAAUC,IAAV,EAAgBC,CAAhB,EAAmBC,OAAnB,EAAgD;AAC5C,gBAAMC,QAAQ,GAAG,MAAMD,OAAO,CAACE,WAAR,CAAoBD,QAApB,CAA6BE,WAA7B,EAAvB;AACA,iBAAO,CAAC,CAAAF,QAAQ,SAAR,IAAAA,QAAQ,WAAR,YAAAA,QAAQ,CAAEG,SAAV,KAAuB,EAAxB,IAA8BN,IAAI,CAACO,GAA1C;AACH;;AAJC,OADC;AAOPC,MAAAA,KAAK,EAAE;AACHJ,QAAAA,WAAW,EAAEjB;AADV,OAPA;AAUPsB,MAAAA,QAAQ,EAAE;AACNL,QAAAA,WAAW,EAAEjB;AADP,OAVH;AAaPuB,MAAAA,OAAO,EAAE;AACLC,QAAAA,OAAO,CAACV,CAAD,EAAIW,IAAJ,EAAeV,OAAf,EAAwB;AAC3B,iBAAOd,OAAO,CAAC,MAAMc,OAAO,CAACE,WAAR,CAAoBS,KAApB,CAA0BF,OAA1B,CAAkCC,IAAI,CAACE,EAAvC,CAAP,CAAd;AACH,SAHI;;AAIL,cAAMC,SAAN,CAAgBd,CAA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U,OAA3B,CAAmC;AAAE/B,YAAAA,SAAS,EAAEM,IAAI,CAACN;AAAlB,WAAnC,CADU,CAAd;AAGH,SAvBO;;AAwBR,cAAMgC,OAAN,CAAcrC,CAAd,EAAiBW,IAAjB,EAA4BV,OAA5B,EAAqC;AACjC,iBAAOd,OAAO,CAAC,MAAMc,OAAO,CAACE,WAAR,CAAoBuB,MAApB,CAA2BW,OAA3B,CAAmC1B,IAAI,CAACS,OAAxC,CAAP,CAAd;AACH,SA1BO;;AA2BR,cAAMkB,cAAN,CAAqBtC,CAArB,EAAwBW,IAAxB,EAAmCV,OAAnC,EAA4C;AACxC,iBAAOd,OAAO,CAAC,MAAMc,OAAO,CAACE,WAAR,CAAoBD,QAApB,CAA6BoC,cAA7B,CAA4C3B,IAAI,CAACI,IAAjD,CAAP,CAAd;AACH;;AA7BO;AA5CL;AApKP;AAF4C,CAAxD;eAqPevB,M","sourcesContent":["import { Response, ErrorResponse, ListResponse } from \"@webiny/handler-graphql\";\nimport { FileManagerContext, FilesListOpts } from \"~/types\";\nimport { GraphQLSchemaPlugin } from \"@webiny/handler-graphql/types\";\n\nconst emptyResolver = () => ({});\n\n/**\n * Use any because it really can be any.\n * TODO @ts-refactor maybe use generics at some point?\n */\ninterface ResolveCallable {\n (): Promise<any>;\n}\n\nconst resolve = async (fn: ResolveCallable) => {\n try {\n return new Response(await fn());\n } catch (e) {\n return new ErrorResponse(e);\n }\n};\n\nconst plugin: GraphQLSchemaPlugin<FileManagerContext> = {\n type: \"graphql-schema\",\n schema: {\n typeDefs: /* GraphQL */ `\n type FmCreatedBy {\n id: ID\n displayName: String\n }\n\n input FileInput {\n key: String\n name: String\n size: Int\n type: String\n tags: [String]\n meta: JSON\n }\n\n type UploadFileResponseDataFile {\n name: String\n type: String\n size: Int\n key: String\n }\n\n type UploadFileResponseData {\n # Contains data that is necessary for initiating a file upload.\n data: JSON\n file: UploadFileResponseDataFile\n }\n\n type FileListMeta {\n cursor: String\n totalCount: Int\n hasMoreItems: Boolean\n }\n\n type FileError {\n code: String\n message: String\n data: JSON\n stack: String\n }\n\n type FileListResponse {\n data: [File]\n meta: FileListMeta\n error: FileError\n }\n\n type FileResponse {\n data: File\n error: FileError\n }\n\n type CreateFilesResponse {\n data: [File]!\n error: FileError\n }\n\n type File {\n id: ID\n key: String\n name: String\n size: Int\n type: String\n src: String\n tags: [String]\n meta: JSON\n createdOn: DateTime\n createdBy: FmCreatedBy\n }\n\n type FileManagerBooleanResponse {\n data: Boolean\n error: FileError\n }\n\n type FileManagerSettings {\n uploadMinFileSize: Number\n uploadMaxFileSize: Number\n srcPrefix: String\n }\n\n input FileManagerSettingsInput {\n uploadMinFileSize: Number\n uploadMaxFileSize: Number\n srcPrefix: String\n }\n\n type FileManagerSettingsResponse {\n data: FileManagerSettings\n error: FileError\n }\n\n input FileWhereInput {\n search: String\n type: String\n type_in: [String!]\n tag: String\n tag_in: [String!]\n tag_and_in: [String!]\n tag_startsWith: String\n tag_not_startsWith: String\n id_in: [ID!]\n id: ID\n createdBy: ID\n }\n\n input TagWhereInput {\n tag_startsWith: String\n tag_not_startsWith: String\n }\n\n type FmQuery {\n getFile(id: ID, where: JSON, sort: String): FileResponse\n\n listFiles(\n limit: Int\n after: String\n types: [String]\n tags: [String]\n ids: [ID]\n search: String\n where: FileWhereInput\n ): FileListResponse\n\n listTags(where: TagWhereInput): [String]\n\n # Get installed version\n version: String\n\n getSettings: FileManagerSettingsResponse\n }\n\n type FilesDeleteResponse {\n data: Boolean\n error: FileError\n }\n\n type FmMutation {\n createFile(data: FileInput!): FileResponse\n createFiles(data: [FileInput]!): CreateFilesResponse\n updateFile(id: ID!, data: FileInput!): FileResponse\n deleteFile(id: ID!): FilesDeleteResponse\n\n # Install File manager\n install(srcPrefix: String): FileManagerBooleanResponse\n\n upgrade(version: String!): FileManagerBooleanResponse\n\n updateSettings(data: FileManagerSettingsInput): FileManagerSettingsResponse\n }\n\n input FilesInstallInput {\n srcPrefix: String!\n }\n\n extend type Query {\n fileManager: FmQuery\n }\n\n extend type Mutation {\n fileManager: FmMutation\n }\n `,\n resolvers: {\n File: {\n async src(file, _, context: FileManagerContext) {\n const settings = await context.fileManager.settings.getSettings();\n return (settings?.srcPrefix || \"\") + file.key;\n }\n },\n Query: {\n fileManager: emptyResolver\n },\n Mutation: {\n fileManager: emptyResolver\n },\n FmQuery: {\n getFile(_, args: any, context) {\n return resolve(() => context.fileManager.files.getFile(args.id));\n },\n async listFiles(_, args: FilesListOpts, context) {\n try {\n const [data, meta] = await context.fileManager.files.listFiles(args);\n return new ListResponse(data, meta);\n } catch (e) {\n return new ErrorResponse(e);\n }\n },\n async listTags(_, args: any, context) {\n try {\n return await context.fileManager.files.listTags(args || {});\n } catch (error) {\n return new ErrorResponse(error);\n }\n },\n async version(_, __, context) {\n const { i18n, tenancy, fileManager } = context;\n if (!tenancy.getCurrentTenant() || !i18n.getContentLocale()) {\n return null;\n }\n\n return await fileManager.system.getVersion();\n },\n async getSettings(_, __, context) {\n return resolve(() => context.fileManager.settings.getSettings());\n }\n },\n FmMutation: {\n async createFile(_, args: any, context) {\n return resolve(() => context.fileManager.files.createFile(args.data));\n },\n async updateFile(_, args: any, context) {\n return resolve(() => context.fileManager.files.updateFile(args.id, args.data));\n },\n async createFiles(_, args: any, context) {\n return resolve(() => context.fileManager.files.createFilesInBatch(args.data));\n },\n async deleteFile(_, args: any, context) {\n return resolve(async () => {\n const file = await context.fileManager.files.getFile(args.id);\n return await context.fileManager.storage.delete({\n id: file.id,\n key: file.key\n });\n });\n },\n async install(_, args: any, context) {\n return resolve(() =>\n context.fileManager.system.install({ srcPrefix: args.srcPrefix })\n );\n },\n async upgrade(_, args: any, context) {\n return resolve(() => context.fileManager.system.upgrade(args.version));\n },\n async updateSettings(_, args: any, context) {\n return resolve(() => context.fileManager.settings.updateSettings(args.data));\n }\n }\n }\n }\n};\n\nexport default plugin;\n"]}
|
|
1
|
+
{"version":3,"names":["emptyResolver","resolve","fn","Response","e","ErrorResponse","plugin","type","schema","typeDefs","resolvers","File","src","file","_","context","settings","fileManager","getSettings","srcPrefix","key","Query","Mutation","FmQuery","getFile","args","files","id","listFiles","data","meta","ListResponse","listTags","error","version","__","i18n","tenancy","getCurrentTenant","getContentLocale","system","getVersion","FmMutation","createFile","updateFile","createFiles","createFilesInBatch","deleteFile","storage","delete","install","upgrade","updateSettings"],"sources":["graphql.ts"],"sourcesContent":["import { Response, ErrorResponse, ListResponse } from \"@webiny/handler-graphql\";\nimport { FileManagerContext, FilesListOpts } from \"~/types\";\nimport { GraphQLSchemaPlugin } from \"@webiny/handler-graphql/types\";\n\nconst emptyResolver = () => ({});\n\n/**\n * Use any because it really can be any.\n * TODO @ts-refactor maybe use generics at some point?\n */\ninterface ResolveCallable {\n (): Promise<any>;\n}\n\nconst resolve = async (fn: ResolveCallable) => {\n try {\n return new Response(await fn());\n } catch (e) {\n return new ErrorResponse(e);\n }\n};\n\nconst plugin: GraphQLSchemaPlugin<FileManagerContext> = {\n type: \"graphql-schema\",\n schema: {\n typeDefs: /* GraphQL */ `\n type FmCreatedBy {\n id: ID\n displayName: String\n }\n\n input FileInput {\n key: String\n name: String\n size: Int\n type: String\n tags: [String]\n meta: JSON\n }\n\n type UploadFileResponseDataFile {\n name: String\n type: String\n size: Int\n key: String\n }\n\n type UploadFileResponseData {\n # Contains data that is necessary for initiating a file upload.\n data: JSON\n file: UploadFileResponseDataFile\n }\n\n type FileListMeta {\n cursor: String\n totalCount: Int\n hasMoreItems: Boolean\n }\n\n type FileError {\n code: String\n message: String\n data: JSON\n stack: String\n }\n\n type FileListResponse {\n data: [File]\n meta: FileListMeta\n error: FileError\n }\n\n type FileResponse {\n data: File\n error: FileError\n }\n\n type CreateFilesResponse {\n data: [File]!\n error: FileError\n }\n\n type File {\n id: ID\n key: String\n name: String\n size: Int\n type: String\n src: String\n tags: [String]\n meta: JSON\n createdOn: DateTime\n createdBy: FmCreatedBy\n }\n\n type FileManagerBooleanResponse {\n data: Boolean\n error: FileError\n }\n\n type FileManagerSettings {\n uploadMinFileSize: Number\n uploadMaxFileSize: Number\n srcPrefix: String\n }\n\n input FileManagerSettingsInput {\n uploadMinFileSize: Number\n uploadMaxFileSize: Number\n srcPrefix: String\n }\n\n type FileManagerSettingsResponse {\n data: FileManagerSettings\n error: FileError\n }\n\n input FileWhereInput {\n search: String\n type: String\n type_in: [String!]\n tag: String\n tag_in: [String!]\n tag_and_in: [String!]\n tag_startsWith: String\n tag_not_startsWith: String\n id_in: [ID!]\n id: ID\n createdBy: ID\n }\n\n input TagWhereInput {\n tag_startsWith: String\n tag_not_startsWith: String\n }\n\n type FmQuery {\n getFile(id: ID, where: JSON, sort: String): FileResponse\n\n listFiles(\n limit: Int\n after: String\n types: [String]\n tags: [String]\n ids: [ID]\n search: String\n where: FileWhereInput\n ): FileListResponse\n\n listTags(where: TagWhereInput): [String]\n\n # Get installed version\n version: String\n\n getSettings: FileManagerSettingsResponse\n }\n\n type FilesDeleteResponse {\n data: Boolean\n error: FileError\n }\n\n type FmMutation {\n createFile(data: FileInput!): FileResponse\n createFiles(data: [FileInput]!): CreateFilesResponse\n updateFile(id: ID!, data: FileInput!): FileResponse\n deleteFile(id: ID!): FilesDeleteResponse\n\n # Install File manager\n install(srcPrefix: String): FileManagerBooleanResponse\n\n upgrade(version: String!): FileManagerBooleanResponse\n\n updateSettings(data: FileManagerSettingsInput): FileManagerSettingsResponse\n }\n\n input FilesInstallInput {\n srcPrefix: String!\n }\n\n extend type Query {\n fileManager: FmQuery\n }\n\n extend type Mutation {\n fileManager: FmMutation\n }\n `,\n resolvers: {\n File: {\n async src(file, _, context: FileManagerContext) {\n const settings = await context.fileManager.settings.getSettings();\n return (settings?.srcPrefix || \"\") + file.key;\n }\n },\n Query: {\n fileManager: emptyResolver\n },\n Mutation: {\n fileManager: emptyResolver\n },\n FmQuery: {\n getFile(_, args: any, context) {\n return resolve(() => context.fileManager.files.getFile(args.id));\n },\n async listFiles(_, args: FilesListOpts, context) {\n try {\n const [data, meta] = await context.fileManager.files.listFiles(args);\n return new ListResponse(data, meta);\n } catch (e) {\n return new ErrorResponse(e);\n }\n },\n async listTags(_, args: any, context) {\n try {\n return await context.fileManager.files.listTags(args || {});\n } catch (error) {\n return new ErrorResponse(error);\n }\n },\n async version(_, __, context) {\n const { i18n, tenancy, fileManager } = context;\n if (!tenancy.getCurrentTenant() || !i18n.getContentLocale()) {\n return null;\n }\n\n return await fileManager.system.getVersion();\n },\n async getSettings(_, __, context) {\n return resolve(() => context.fileManager.settings.getSettings());\n }\n },\n FmMutation: {\n async createFile(_, args: any, context) {\n return resolve(() => context.fileManager.files.createFile(args.data));\n },\n async updateFile(_, args: any, context) {\n return resolve(() => context.fileManager.files.updateFile(args.id, args.data));\n },\n async createFiles(_, args: any, context) {\n return resolve(() => context.fileManager.files.createFilesInBatch(args.data));\n },\n async deleteFile(_, args: any, context) {\n return resolve(async () => {\n const file = await context.fileManager.files.getFile(args.id);\n return await context.fileManager.storage.delete({\n id: file.id,\n key: file.key\n });\n });\n },\n async install(_, args: any, context) {\n return resolve(() =>\n context.fileManager.system.install({ srcPrefix: args.srcPrefix })\n );\n },\n async upgrade(_, args: any, context) {\n return resolve(() => context.fileManager.system.upgrade(args.version));\n },\n async updateSettings(_, args: any, context) {\n return resolve(() => context.fileManager.settings.updateSettings(args.data));\n }\n }\n }\n }\n};\n\nexport default plugin;\n"],"mappings":";;;;;;;AAAA;;AAIA,MAAMA,aAAa,GAAG,OAAO,EAAP,CAAtB;AAEA;AACA;AACA;AACA;;;AAKA,MAAMC,OAAO,GAAG,MAAOC,EAAP,IAA+B;EAC3C,IAAI;IACA,OAAO,IAAIC,wBAAJ,CAAa,MAAMD,EAAE,EAArB,CAAP;EACH,CAFD,CAEE,OAAOE,CAAP,EAAU;IACR,OAAO,IAAIC,6BAAJ,CAAkBD,CAAlB,CAAP;EACH;AACJ,CAND;;AAQA,MAAME,MAA+C,GAAG;EACpDC,IAAI,EAAE,gBAD8C;EAEpDC,MAAM,EAAE;IACJC,QAAQ;IAAE;IAAe;AACjC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAnKY;IAoKJC,SAAS,EAAE;MACPC,IAAI,EAAE;QACF,MAAMC,GAAN,CAAUC,IAAV,EAAgBC,CAAhB,EAAmBC,OAAnB,EAAgD;UAC5C,MAAMC,QAAQ,GAAG,MAAMD,OAAO,CAACE,WAAR,CAAoBD,QAApB,CAA6BE,WAA7B,EAAvB;UACA,OAAO,CAAC,CAAAF,QAAQ,SAAR,IAAAA,QAAQ,WAAR,YAAAA,QAAQ,CAAEG,SAAV,KAAuB,EAAxB,IAA8BN,IAAI,CAACO,GAA1C;QACH;;MAJC,CADC;MAOPC,KAAK,EAAE;QACHJ,WAAW,EAAEjB;MADV,CAPA;MAUPsB,QAAQ,EAAE;QACNL,WAAW,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ACO;YAFkC,CAAnC,CAAb;UAIH,CANa,CAAd;QAOH,CAlBO;;QAmBR,MAAM8B,OAAN,CAAcpC,CAAd,EAAiBW,IAAjB,EAA4BV,OAA5B,EAAqC;UACjC,OAAOd,OAAO,CAAC,MACXc,OAAO,CAACE,WAAR,CAAoBuB,MAApB,CAA2BU,OAA3B,CAAmC;YAAE/B,SAAS,EAAEM,IAAI,CAACN;UAAlB,CAAnC,CADU,CAAd;QAGH,CAvBO;;QAwBR,MAAMgC,OAAN,CAAcrC,CAAd,EAAiBW,IAAjB,EAA4BV,OAA5B,EAAqC;UACjC,OAAOd,OAAO,CAAC,MAAMc,OAAO,CAACE,WAAR,CAAoBuB,MAApB,CAA2BW,OAA3B,CAAmC1B,IAAI,CAACS,OAAxC,CAAP,CAAd;QACH,CA1BO;;QA2BR,MAAMkB,cAAN,CAAqBtC,CAArB,EAAwBW,IAAxB,EAAmCV,OAAnC,EAA4C;UACxC,OAAOd,OAAO,CAAC,MAAMc,OAAO,CAACE,WAAR,CAAoBD,QAApB,CAA6BoC,cAA7B,CAA4C3B,IAAI,CAACI,IAAjD,CAAP,CAAd;QACH;;MA7BO;IA5CL;EApKP;AAF4C,CAAxD;eAqPevB,M"}
|
package/plugins/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["systemCRUD","settingsCRUD","filesCRUD","storage","graphql","fileValidationPlugin"],"sources":["index.ts"],"sourcesContent":["import graphql from \"./graphql\";\nimport filesCRUD from \"./crud/files.crud\";\nimport fileValidationPlugin from \"./crud/files/validation\";\nimport settingsCRUD from \"./crud/settings.crud\";\nimport systemCRUD from \"./crud/system.crud\";\nimport storage from \"./storage\";\n\nexport default () => [\n systemCRUD,\n settingsCRUD,\n filesCRUD,\n storage,\n graphql,\n fileValidationPlugin()\n];\n"],"mappings":";;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;AACA;;eAEe,MAAM,CACjBA,eADiB,EAEjBC,iBAFiB,EAGjBC,cAHiB,EAIjBC,gBAJiB,EAKjBC,gBALiB,EAMjB,IAAAC,mBAAA,GANiB,C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["storagePluginType","FileStorage","constructor","context","storagePlugin","plugins","byType","pop","WebinyError","upload","params","settings","fileManager","getSettings","file","fileData","files","createFile","meta","private","Boolean","hideInFileManager","tags","Array","isArray","uploadFiles","promises","item","push","uploadFileResponses","Promise","all","filesData","map","response","createFilesInBatch","delete","id","key","deleteFile"],"sources":["FileStorage.ts"],"sourcesContent":["import { FileManagerContext } from \"~/types\";\nimport WebinyError from \"@webiny/error\";\nimport { FilePhysicalStoragePlugin } from \"~/plugins/definitions/FilePhysicalStoragePlugin\";\n\nexport type Result = Record<string, any>;\n\nconst storagePluginType = \"api-file-manager-storage\";\n\nexport interface FileStorageUploadParams {\n buffer: Buffer;\n hideInFileManager: boolean | string;\n tags?: string[];\n size: number;\n name: string;\n keyPrefix: string;\n type: string;\n}\nexport interface FileStorageDeleteParams {\n id: string;\n key: string;\n}\n\nexport interface FileStorageUploadMultipleParams {\n files: FileStorageUploadParams[];\n}\n\nexport interface FileStorageParams {\n context: FileManagerContext;\n}\nexport class FileStorage {\n private readonly storagePlugin: FilePhysicalStoragePlugin;\n private readonly context: FileManagerContext;\n\n constructor({ context }: FileStorageParams) {\n const storagePlugin = context.plugins\n .byType<FilePhysicalStoragePlugin>(storagePluginType)\n .pop();\n if (!storagePlugin) {\n throw new WebinyError(\n `Missing plugin of type \"${storagePluginType}\".`,\n \"STORAGE_PLUGIN_ERROR\"\n );\n }\n this.storagePlugin = storagePlugin;\n this.context = context;\n }\n\n async upload(params: FileStorageUploadParams): Promise<Result> {\n const settings = await this.context.fileManager.settings.getSettings();\n if (!settings) {\n throw new WebinyError(\"Missing File Manager Settings.\", \"FILE_MANAGER_ERROR\");\n }\n // Add file to cloud storage.\n const { file: fileData } = await this.storagePlugin.upload({\n ...params,\n settings\n });\n\n const { fileManager } = this.context;\n\n // Save file in DB.\n return await fileManager.files.createFile({\n ...(fileData as any),\n meta: {\n private: Boolean(params.hideInFileManager)\n },\n tags: Array.isArray(params.tags) ? params.tags : []\n });\n }\n\n async uploadFiles(params: FileStorageUploadMultipleParams) {\n const settings = await this.context.fileManager.settings.getSettings();\n if (!settings) {\n throw new WebinyError(\"Missing File Manager Settings.\", \"FILE_MANAGER_ERROR\");\n }\n // Upload files to cloud storage.\n const promises = [];\n for (const item of params.files) {\n promises.push(\n this.storagePlugin.upload({\n ...item,\n settings\n })\n );\n }\n // Wait for all to resolve.\n const uploadFileResponses = await Promise.all(promises);\n\n const filesData = uploadFileResponses.map(response => response.file);\n\n const { fileManager } = this.context;\n // Save files in DB.\n return fileManager.files.createFilesInBatch(filesData);\n }\n\n async delete(params: FileStorageDeleteParams) {\n const { id, key } = params;\n const { fileManager } = this.context;\n // Delete file from cloud storage.\n await this.storagePlugin.delete({\n key\n });\n // Delete file from the DB.\n return await fileManager.files.deleteFile(id);\n }\n}\n"],"mappings":";;;;;;;;;;;AACA;;;;;;AAKA,MAAMA,iBAAiB,GAAG,0BAA1B;;AAuBO,MAAMC,WAAN,CAAkB;EAIrBC,WAAW,CAAC;IAAEC;EAAF,CAAD,EAAiC;IAAA;IAAA;IACxC,MAAMC,aAAa,GAAGD,OAAO,CAACE,OAAR,CACjBC,MADiB,CACiBN,iBADjB,EAEjBO,GAFiB,EAAtB;;IAGA,IAAI,CAACH,aAAL,EAAoB;MAChB,MAAM,IAAII,cAAJ,CACD,2BAA0BR,iBAAkB,IAD3C,EAEF,sBAFE,CAAN;IAIH;;IACD,KAAKI,aAAL,GAAqBA,aAArB;IACA,KAAKD,OAAL,GAAeA,OAAf;EACH;;EAEW,MAANM,MAAM,CAACC,MAAD,EAAmD;IAC3D,MAAMC,QAAQ,GAAG,MAAM,KAAKR,OAAL,CAAaS,WAAb,CAAyBD,QAAzB,CAAkCE,WAAlC,EAAvB;;IACA,IAAI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B,CApBuD,CAqBvD;;IACA,OAAOS,WAAW,CAACI,KAAZ,CAAkBmB,kBAAlB,CAAqCH,SAArC,CAAP;EACH;;EAEW,MAANI,MAAM,CAAC1B,MAAD,EAAkC;IAC1C,MAAM;MAAE2B,EAAF;MAAMC;IAAN,IAAc5B,MAApB;IACA,MAAM;MAAEE;IAAF,IAAkB,KAAKT,OAA7B,CAF0C,CAG1C;;IACA,MAAM,KAAKC,aAAL,CAAmBgC,MAAnB,CAA0B;MAC5BE;IAD4B,CAA1B,CAAN,CAJ0C,CAO1C;;IACA,OAAO,MAAM1B,WAAW,CAACI,KAAZ,CAAkBuB,UAAlB,CAA6BF,EAA7B,CAAb;EACH;;AA3EoB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["fileStorageContextPlugin","ContextPlugin","context","fileManager","storage","FileStorage"],"sources":["index.ts"],"sourcesContent":["import { FileManagerContext } from \"~/types\";\nimport { ContextPlugin } from \"@webiny/handler\";\nimport { FileStorage } from \"./FileStorage\";\n\nconst fileStorageContextPlugin = new ContextPlugin<FileManagerContext>(async context => {\n if (!context.fileManager) {\n /**\n * We need to define the fileManager initial property as empty object.\n * When casting as FileManagerContext, typescript is complaining.\n */\n context.fileManager = {} as any;\n }\n context.fileManager.storage = new FileStorage({\n context\n });\n});\n\nexport default fileStorageContextPlugin;\n"],"mappings":";;;;;;;AACA;;AACA;;AAEA,MAAMA,wBAAwB,GAAG,IAAIC,sBAAJ,CAAsC,MAAMC,OAAN,IAAiB;EACpF,IAAI,CAACA,OAAO,CAACC,WAAb,EAA0B;IACtB;AACR;AACA;AACA;IACQD,OAAO,CAACC,WAAR,GAAsB,EAAtB;EACH;;EACDD,OAAO,CAACC,WAAR,CAAoBC,OAApB,GAA8B,IAAIC,wBAAJ,CAAgB;IAC1CH;EAD0C,CAAhB,CAA9B;AAGH,CAXgC,CAAjC;eAaeF,wB"}
|
package/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[],"names":[],"mappings":"","sourcesContent":[]}
|
|
1
|
+
{"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import { I18NContext } from \"@webiny/api-i18n/types\";\nimport { FileStorage } from \"./plugins/storage/FileStorage\";\nimport { TenancyContext } from \"@webiny/api-tenancy/types\";\nimport { SecurityContext, SecurityPermission } from \"@webiny/api-security/types\";\nimport { Context } from \"@webiny/handler/types\";\n\nexport interface FileManagerContext extends Context, SecurityContext, TenancyContext, I18NContext {\n fileManager: {\n files: FilesCRUD;\n settings: SettingsCRUD;\n storage: FileStorage;\n system: SystemCRUD;\n };\n}\n\nexport interface FilePermission extends SecurityPermission {\n name: \"fm.file\";\n rwd?: string;\n own?: boolean;\n}\n\nexport interface File {\n id: string;\n key: string;\n size: number;\n type: string;\n name: string;\n meta: Record<string, any>;\n tags: string[];\n createdOn: string;\n createdBy: CreatedBy;\n /**\n * Added with new storage operations refactoring.\n */\n tenant: string;\n locale: string;\n webinyVersion: string;\n /**\n * User can add new fields to the File object so we must allow it in the types.\n */\n [key: string]: any;\n}\n\nexport interface CreatedBy {\n id: string;\n displayName: string | null;\n type: string;\n}\n\nexport interface FileInput {\n key: string;\n name: string;\n size: number;\n type: string;\n meta: Record<string, any>;\n tags: string[];\n}\n\nexport interface FileListWhereParams {\n search?: string;\n type?: string;\n type_in?: string[];\n tag?: string;\n tag_in?: string[];\n tag_and_in?: string[];\n id_in?: string[];\n id?: string;\n}\nexport interface FilesListOpts {\n search?: string;\n types?: string[];\n tags?: string[];\n ids?: string[];\n limit?: number;\n after?: string;\n where?: FileListWhereParams;\n sort?: string[];\n}\n\nexport interface FileListMeta {\n cursor: string | null;\n totalCount: number;\n hasMoreItems: boolean;\n}\n\ninterface FilesCrudListTagsWhere {\n tag?: string;\n tag_contains?: string;\n tag_in?: string[];\n tag_not_startsWith?: string;\n tag_startsWith?: string;\n}\ninterface FilesCrudListTagsParams {\n where?: FilesCrudListTagsWhere;\n limit?: number;\n after?: string;\n}\n\nexport interface FilesCRUD {\n getFile(id: string): Promise<File>;\n listFiles(opts?: FilesListOpts): Promise<[File[], FileListMeta]>;\n listTags(params: FilesCrudListTagsParams): Promise<string[]>;\n createFile(data: FileInput): Promise<File>;\n updateFile(id: string, data: Partial<FileInput>): Promise<File>;\n deleteFile(id: string): Promise<boolean>;\n createFilesInBatch(data: FileInput[]): Promise<File[]>;\n}\n\nexport interface SystemCRUD {\n getVersion(): Promise<string | null>;\n setVersion(version: string): Promise<void>;\n install(args: { srcPrefix: string }): Promise<boolean>;\n upgrade(version: string, data?: Record<string, any>): Promise<boolean>;\n}\n\nexport interface FileManagerSettings {\n key: string;\n uploadMinFileSize: number;\n uploadMaxFileSize: number;\n srcPrefix: string;\n}\n\nexport interface FileManagerSystem {\n version: string;\n tenant: string;\n}\n\nexport type SettingsCRUD = {\n getSettings(): Promise<FileManagerSettings | null>;\n createSettings(data?: Partial<FileManagerSettings>): Promise<FileManagerSettings>;\n updateSettings(data: Partial<FileManagerSettings>): Promise<FileManagerSettings>;\n deleteSettings(): Promise<boolean>;\n};\n/********\n * Storage operations\n *******/\n\n/**\n * @category StorageOperations\n * @category SystemStorageOperations\n * @category SystemStorageOperationsParams\n */\nexport interface FileManagerSystemStorageOperationsUpdateParams {\n /**\n * The system data to be updated.\n */\n original: FileManagerSystem;\n /**\n * The system data with the updated fields.\n */\n data: FileManagerSystem;\n}\n/**\n * @category StorageOperations\n * @category SystemStorageOperations\n * @category SystemStorageOperationsParams\n */\nexport interface FileManagerSystemStorageOperationsCreateParams {\n /**\n * The system fields.\n */\n data: FileManagerSystem;\n}\n\n/**\n * @category StorageOperations\n * @category SystemStorageOperations\n */\nexport interface FileManagerSystemStorageOperations {\n /**\n * Get the FileManager system data.\n */\n get: () => Promise<FileManagerSystem | null>;\n /**\n * Update the FileManager system data..\n */\n update: (params: FileManagerSystemStorageOperationsUpdateParams) => Promise<FileManagerSystem>;\n /**\n * Create the FileManagerSystemData\n */\n create: (params: FileManagerSystemStorageOperationsCreateParams) => Promise<FileManagerSystem>;\n}\n\n/**\n * @category StorageOperations\n * @category SettingsStorageOperations\n * @category SettingsStorageOperationsParams\n */\nexport interface FileManagerSettingsStorageOperationsUpdateParams {\n /**\n * Original settings to be updated.\n */\n original: FileManagerSettings;\n /**\n * The settings with the updated fields.\n */\n data: FileManagerSettings;\n}\n/**\n * @category StorageOperations\n * @category SettingsStorageOperations\n * @category SettingsStorageOperationsParams\n */\nexport interface FileManagerSettingsStorageOperationsCreateParams {\n /**\n * The settings fields.\n */\n data: FileManagerSettings;\n}\n\n/**\n * @category StorageOperations\n * @category SettingsStorageOperations\n */\nexport interface FileManagerSettingsStorageOperations {\n /**\n * Get the FileManager system data.\n */\n get: () => Promise<FileManagerSettings | null>;\n /**\n * Create the FileManagerSettingsData\n */\n create: (\n params: FileManagerSettingsStorageOperationsCreateParams\n ) => Promise<FileManagerSettings>;\n /**\n * Update the FileManager system data..\n */\n update: (\n params: FileManagerSettingsStorageOperationsUpdateParams\n ) => Promise<FileManagerSettings>;\n /**\n * Delete the existing settings.\n */\n delete: () => Promise<void>;\n}\n\n/**\n * @category StorageOperations\n * @category FilesStorageOperations\n * @category FilesStorageOperationsParams\n */\nexport interface FileManagerFilesStorageOperationsGetParams {\n where: {\n id: string;\n tenant: string;\n locale: string;\n };\n}\n/**\n * @category StorageOperations\n * @category FilesStorageOperations\n * @category FilesStorageOperationsParams\n */\nexport interface FileManagerFilesStorageOperationsCreateParams {\n file: File;\n}\n/**\n * @category StorageOperations\n * @category FilesStorageOperations\n * @category FilesStorageOperationsParams\n */\nexport interface FileManagerFilesStorageOperationsUpdateParams {\n original: File;\n file: File;\n}\n\n/**\n * @category StorageOperations\n * @category FilesStorageOperations\n * @category FilesStorageOperationsParams\n */\nexport interface FileManagerFilesStorageOperationsDeleteParams {\n file: File;\n}\n/**\n * @category StorageOperations\n * @category FilesStorageOperations\n * @category FilesStorageOperationsParams\n */\nexport interface FileManagerFilesStorageOperationsCreateBatchParams {\n files: File[];\n}\n/**\n * @category StorageOperations\n * @category FilesStorageOperations\n * @category FilesStorageOperationsParams\n */\nexport interface FileManagerFilesStorageOperationsListParamsWhere {\n id?: string;\n id_in?: string[];\n name?: string;\n name_contains?: string;\n tag?: string;\n tag_contains?: string;\n tag_in?: string[];\n createdBy?: string;\n locale: string;\n tenant: string;\n private?: boolean;\n type?: string;\n type_in?: string[];\n search?: string;\n}\n/**\n * @category StorageOperations\n * @category FilesStorageOperations\n * @category FilesStorageOperationsParams\n */\nexport interface FileManagerFilesStorageOperationsListParams {\n where: FileManagerFilesStorageOperationsListParamsWhere;\n sort: string[];\n limit: number;\n after: string | null;\n}\n\n/**\n * @category StorageOperations\n * @category FilesStorageOperations\n * @category FilesStorageOperationsParams\n */\nexport interface FileManagerFilesStorageOperationsListResponseMeta {\n hasMoreItems: boolean;\n totalCount: number;\n cursor: string | null;\n}\nexport type FileManagerFilesStorageOperationsListResponse = [\n File[],\n FileManagerFilesStorageOperationsListResponseMeta\n];\n\nexport type FileManagerFilesStorageOperationsTagsResponse = [\n string[],\n FileManagerFilesStorageOperationsListResponseMeta\n];\n\nexport interface FileManagerFilesStorageOperationsTagsParamsWhere extends FilesCrudListTagsWhere {\n locale: string;\n tenant: string;\n}\n/**\n * @category StorageOperations\n * @category FilesStorageOperations\n * @category FilesStorageOperationsParams\n */\nexport interface FileManagerFilesStorageOperationsTagsParams {\n where: FileManagerFilesStorageOperationsTagsParamsWhere;\n limit: number;\n after?: string;\n}\n/**\n * @category StorageOperations\n * @category FilesStorageOperations\n */\nexport interface FileManagerFilesStorageOperations {\n /**\n * Get a single file with given ID from the storage.\n */\n get: (params: FileManagerFilesStorageOperationsGetParams) => Promise<File | null>;\n /**\n * Insert the file data into the database.\n */\n create: (params: FileManagerFilesStorageOperationsCreateParams) => Promise<File>;\n /**\n * Update the file data in the database.\n */\n update: (params: FileManagerFilesStorageOperationsUpdateParams) => Promise<File>;\n /**\n * Delete the file from the database.\n */\n delete: (params: FileManagerFilesStorageOperationsDeleteParams) => Promise<void>;\n /**\n * Store multiple files at once to the database.\n */\n createBatch: (params: FileManagerFilesStorageOperationsCreateBatchParams) => Promise<File[]>;\n /**\n * Get a list of files filtered by given parameters.\n */\n list: (\n params: FileManagerFilesStorageOperationsListParams\n ) => Promise<FileManagerFilesStorageOperationsListResponse>;\n /**\n * Get a list of all file tags filtered by given parameters.\n */\n tags: (\n params: FileManagerFilesStorageOperationsTagsParams\n ) => Promise<FileManagerFilesStorageOperationsTagsResponse>;\n}\n"],"mappings":""}
|
package/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["executeCallbacks","plugins","hook","args","plugin"],"sources":["utils.ts"],"sourcesContent":["import { Plugin } from \"@webiny/plugins/types\";\n\ntype CallbackFallback = (args: any) => void | Promise<void>;\n\nexport const executeCallbacks = async <\n TCallbackFunction extends CallbackFallback = CallbackFallback\n>(\n plugins: Plugin[],\n hook: string,\n args: Parameters<TCallbackFunction>[0]\n) => {\n for (const plugin of plugins) {\n if (typeof plugin[hook] === \"function\") {\n await plugin[hook](args);\n }\n }\n};\n"],"mappings":";;;;;;;AAIO,MAAMA,gBAAgB,GAAG,OAG5BC,OAH4B,EAI5BC,IAJ4B,EAK5BC,IAL4B,KAM3B;EACD,KAAK,MAAMC,MAAX,IAAqBH,OAArB,EAA8B;IAC1B,IAAI,OAAOG,MAAM,CAACF,IAAD,CAAb,KAAwB,UAA5B,EAAwC;MACpC,MAAME,MAAM,CAACF,IAAD,CAAN,CAAaC,IAAb,CAAN;IACH;EACJ;AACJ,CAZM"}
|