@webiny/api-file-manager-s3 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/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["fileStorageS3","graphqlFileStorageS3"],"sources":["index.ts"],"sourcesContent":["import graphqlFileStorageS3 from \"./plugins/graphqlFileStorageS3\";\nimport fileStorageS3 from \"./plugins/fileStorageS3\";\n\nexport default () => [fileStorageS3(), graphqlFileStorageS3];\n"],"mappings":";;;;;;;;;AAAA;;AACA;;eAEe,MAAM,CAAC,IAAAA,qBAAA,GAAD,EAAkBC,4BAAlB,C"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webiny/api-file-manager-s3",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.29.0-beta.0",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -10,10 +10,10 @@
|
|
|
10
10
|
"author": "Webiny Ltd",
|
|
11
11
|
"license": "MIT",
|
|
12
12
|
"dependencies": {
|
|
13
|
-
"@webiny/api-file-manager": "5.
|
|
14
|
-
"@webiny/error": "5.
|
|
15
|
-
"@webiny/handler-graphql": "5.
|
|
16
|
-
"@webiny/validation": "5.
|
|
13
|
+
"@webiny/api-file-manager": "5.29.0-beta.0",
|
|
14
|
+
"@webiny/error": "5.29.0-beta.0",
|
|
15
|
+
"@webiny/handler-graphql": "5.29.0-beta.0",
|
|
16
|
+
"@webiny/validation": "5.29.0-beta.0",
|
|
17
17
|
"form-data": "3.0.1",
|
|
18
18
|
"node-fetch": "2.6.7",
|
|
19
19
|
"sanitize-filename": "1.6.3",
|
|
@@ -23,8 +23,8 @@
|
|
|
23
23
|
"@babel/cli": "^7.16.0",
|
|
24
24
|
"@babel/core": "^7.16.0",
|
|
25
25
|
"@types/node-fetch": "^2.6.1",
|
|
26
|
-
"@webiny/cli": "^5.
|
|
27
|
-
"@webiny/project-utils": "^5.
|
|
26
|
+
"@webiny/cli": "^5.29.0-beta.0",
|
|
27
|
+
"@webiny/project-utils": "^5.29.0-beta.0",
|
|
28
28
|
"rimraf": "^3.0.2",
|
|
29
29
|
"typescript": "4.5.5"
|
|
30
30
|
},
|
|
@@ -36,5 +36,5 @@
|
|
|
36
36
|
"build": "yarn webiny run build",
|
|
37
37
|
"watch": "yarn webiny run watch"
|
|
38
38
|
},
|
|
39
|
-
"gitHead": "
|
|
39
|
+
"gitHead": "e221dc575942c512548be142e20c5bd1231edcda"
|
|
40
40
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["S3_BUCKET","process","env","FilePhysicalStoragePlugin","upload","params","settings","buffer","data","preSignedPostPayload","file","getPresignedPostPayload","response","uploadFileToS3","ok","Error","delete","key","s3","S3","deleteObject","Bucket","Key","promise"],"sources":["fileStorageS3.ts"],"sourcesContent":["import S3 from \"aws-sdk/clients/s3\";\nimport getPresignedPostPayload from \"../utils/getPresignedPostPayload\";\nimport uploadFileToS3 from \"../utils/uploadFileToS3\";\nimport {\n FilePhysicalStoragePlugin,\n FilePhysicalStoragePluginUploadParams\n} from \"@webiny/api-file-manager/plugins/definitions/FilePhysicalStoragePlugin\";\nimport { PresignedPostPayloadData } from \"~/types\";\n\nconst S3_BUCKET = process.env.S3_BUCKET;\n\nexport interface S3FilePhysicalStoragePluginUploadParams\n extends FilePhysicalStoragePluginUploadParams,\n PresignedPostPayloadData {}\n\nexport default (): FilePhysicalStoragePlugin => {\n /**\n * We need to extends the type for FilePhysicalStoragePlugin.\n * Otherwise the getPresignedPostPayload does not know it has all required values in params.\n */\n return new FilePhysicalStoragePlugin<S3FilePhysicalStoragePluginUploadParams>({\n upload: async params => {\n const { settings, buffer, ...data } = params;\n\n const { data: preSignedPostPayload, file } = await getPresignedPostPayload(\n data,\n settings\n );\n\n const response = await uploadFileToS3(buffer, preSignedPostPayload);\n if (!response.ok) {\n throw Error(\"Unable to upload file.\");\n }\n\n return {\n data: preSignedPostPayload,\n file\n };\n },\n delete: async params => {\n const { key } = params;\n const s3 = new S3();\n\n if (!key || !S3_BUCKET) {\n return;\n }\n\n await s3\n .deleteObject({\n Bucket: S3_BUCKET,\n Key: key\n })\n .promise();\n }\n });\n};\n"],"mappings":";;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;;AAMA,MAAMA,SAAS,GAAGC,OAAO,CAACC,GAAR,CAAYF,SAA9B;;eAMe,MAAiC;EAC5C;AACJ;AACA;AACA;EACI,OAAO,IAAIG,oDAAJ,CAAuE;IAC1EC,MAAM,EAAE,MAAMC,MAAN,IAAgB;MACpB,MAAM;QAAEC,QAAF;QAAYC;MAAZ,IAAgCF,MAAtC;MAAA,MAA6BG,IAA7B,0CAAsCH,MAAtC;MAEA,MAAM;QAAEG,IAAI,EAAEC,oBAAR;QAA8BC;MAA9B,IAAuC,MAAM,IAAAC,gCAAA,EAC/CH,IAD+C,EAE/CF,QAF+C,CAAnD;MAKA,MAAMM,QAAQ,GAAG,MAAM,IAAAC,sBAAA,EAAeN,MAAf,EAAuBE,oBAAvB,CAAvB;;MACA,IAAI,CAACG,QAAQ,CAACE,EAAd,EAAkB;QACd,MAAMC,KAAK,CAAC,wBAAD,CAAX;MACH;;MAED,OAAO;QACHP,IAAI,EAAEC,oBADH;QAEHC;MAFG,CAAP;IAIH,CAlByE;IAmB1EM,MAAM,EAAE,MAAMX,MAAN,IAAgB;MACpB,MAAM;QAAEY;MAAF,IAAUZ,MAAhB;MACA,MAAMa,EAAE,GAAG,IAAIC,UAAJ,EAAX;;MAEA,IAAI,CAACF,GAAD,IAAQ,CAACjB,SAAb,EAAwB;QACpB;MACH;;MAED,MAAMkB,EAAE,CACHE,YADC,CACY;QACVC,MAAM,EAAErB,SADE;QAEVsB,GAAG,EAAEL;MAFK,CADZ,EAKDM,OALC,EAAN;IAMH;EAjCyE,CAAvE,CAAP;AAmCH,C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["BATCH_UPLOAD_MAX_FILES","plugin","type","name","schema","typeDefs","resolvers","FmQuery","getPreSignedPostPayload","_","args","context","checkBasePermissions","rwd","data","settings","fileManager","getSettings","WebinyError","file","response","getPresignedPostPayload","Response","e","ErrorResponse","message","code","getPreSignedPostPayloads","files","Array","isArray","length","promises","item","push","Promise","all"],"sources":["graphqlFileStorageS3.ts"],"sourcesContent":["import { GraphQLSchemaPlugin } from \"@webiny/handler-graphql/types\";\nimport { ErrorResponse, Response } from \"@webiny/handler-graphql/responses\";\nimport checkBasePermissions from \"@webiny/api-file-manager/plugins/crud/utils/checkBasePermissions\";\nimport { FileManagerContext } from \"@webiny/api-file-manager/types\";\nimport getPresignedPostPayload from \"../utils/getPresignedPostPayload\";\nimport WebinyError from \"@webiny/error\";\n\nconst BATCH_UPLOAD_MAX_FILES = 20;\n\nconst plugin: GraphQLSchemaPlugin<FileManagerContext> = {\n type: \"graphql-schema\",\n name: \"graphql-schema-api-file-manager-s3\",\n schema: {\n typeDefs: /* GraphQL */ `\n input PreSignedPostPayloadInput {\n name: String!\n type: String!\n size: Int!\n }\n\n type GetPreSignedPostPayloadResponseDataFile {\n name: String\n type: String\n size: Int\n key: String\n }\n\n type GetPreSignedPostPayloadResponseData {\n # Contains data that is necessary for initiating a file upload.\n data: JSON\n file: UploadFileResponseDataFile\n }\n\n type GetPreSignedPostPayloadResponse {\n error: FileError\n data: GetPreSignedPostPayloadResponseData\n }\n\n type GetPreSignedPostPayloadsResponse {\n error: FileError\n data: [GetPreSignedPostPayloadResponseData]!\n }\n\n extend type FmQuery {\n getPreSignedPostPayload(\n data: PreSignedPostPayloadInput!\n ): GetPreSignedPostPayloadResponse\n getPreSignedPostPayloads(\n data: [PreSignedPostPayloadInput]!\n ): GetPreSignedPostPayloadsResponse\n }\n `,\n resolvers: {\n FmQuery: {\n getPreSignedPostPayload: async (_, args: any, context) => {\n try {\n await checkBasePermissions(context, { rwd: \"w\" });\n\n const { data } = args;\n const settings = await context.fileManager.settings.getSettings();\n if (!settings) {\n throw new WebinyError(\n \"Missing File Manager Settings.\",\n \"FILE_MANAGER_SETTINGS_ERROR\",\n {\n file: data\n }\n );\n }\n const response = await getPresignedPostPayload(data, settings);\n\n return new Response(response);\n } catch (e) {\n return new ErrorResponse({\n message: e.message,\n code: e.code,\n data: e.data\n });\n }\n },\n getPreSignedPostPayloads: async (_, args: any, context) => {\n await checkBasePermissions(context, { rwd: \"w\" });\n\n const { data: files } = args;\n if (!Array.isArray(files)) {\n return new ErrorResponse({\n code: \"UPLOAD_FILES_NON_ARRAY\",\n message: `\"data\" argument must be an array.`\n });\n }\n\n if (files.length === 0) {\n return new ErrorResponse({\n code: \"UPLOAD_FILES_MIN_FILES\",\n message: `\"data\" argument must contain at least one file.`\n });\n }\n\n if (files.length > BATCH_UPLOAD_MAX_FILES) {\n return new ErrorResponse({\n code: \"UPLOAD_FILES_MAX_FILES\",\n message: `\"data\" argument must not contain more than ${BATCH_UPLOAD_MAX_FILES} files.`\n });\n }\n\n try {\n const settings = await context.fileManager.settings.getSettings();\n if (!settings) {\n throw new WebinyError(\n \"Missing File Manager Settings.\",\n \"FILE_MANAGER_SETTINGS_ERROR\",\n {\n files\n }\n );\n }\n\n const promises = [];\n for (const item of files) {\n promises.push(getPresignedPostPayload(item, settings));\n }\n\n return new Response(await Promise.all(promises));\n } catch (e) {\n return new ErrorResponse({\n message: e.message,\n code: e.code,\n data: e.data\n });\n }\n }\n }\n }\n }\n};\n\nexport default plugin;\n"],"mappings":";;;;;;;;;AACA;;AACA;;AAEA;;AACA;;AAEA,MAAMA,sBAAsB,GAAG,EAA/B;AAEA,MAAMC,MAA+C,GAAG;EACpDC,IAAI,EAAE,gBAD8C;EAEpDC,IAAI,EAAE,oCAF8C;EAGpDC,MAAM,EAAE;IACJC,QAAQ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xD;eA+Heb,M"}
|
package/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import S3 from \"aws-sdk/clients/s3\";\n\nexport interface PresignedPostPayloadData {\n name: string;\n type: string;\n size: number;\n keyPrefix: string;\n}\n\nexport interface PresignedPostPayloadDataResponse {\n data: S3.PresignedPost;\n file: {\n name: string;\n key: string;\n type: string;\n size: number;\n };\n}\n"],"mappings":""}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["S3_BUCKET","process","env","UPLOAD_MAX_FILE_SIZE_DEFAULT","sanitizeFileSizeValue","value","defaultValue","validation","validateSync","e","data","settings","type","contentType","Error","key","sanitizeFilename","name","uniqueId","keyPrefix","replace","uploadMinFileSize","uploadMaxFileSize","params","Expires","Bucket","Conditions","Fields","startsWith","slice","s3","S3","payload","createPresignedPost","file","size"],"sources":["getPresignedPostPayload.ts"],"sourcesContent":["import uniqueId from \"uniqid\";\nimport sanitizeFilename from \"sanitize-filename\";\nimport S3 from \"aws-sdk/clients/s3\";\nimport { validation } from \"@webiny/validation\";\nimport { PresignedPostPayloadData, PresignedPostPayloadDataResponse } from \"~/types\";\nimport { FileManagerSettings } from \"@webiny/api-file-manager/types\";\n\nconst S3_BUCKET = process.env.S3_BUCKET;\nconst UPLOAD_MAX_FILE_SIZE_DEFAULT = 26214400; // 25MB\n\nconst sanitizeFileSizeValue = (value: number, defaultValue: number): number => {\n try {\n validation.validateSync(value, \"required,numeric,gte:0\");\n return value;\n } catch (e) {\n // TODO @ts-refactor No need to log the error?\n return defaultValue;\n }\n};\n\nexport default async (\n data: PresignedPostPayloadData,\n settings: FileManagerSettings\n): Promise<PresignedPostPayloadDataResponse> => {\n // If type is missing, let's use the default \"application/octet-stream\" type,\n // which is also the default type that the Amazon S3 would use.\n if (!data.type) {\n data.type = \"application/octet-stream\";\n }\n\n const contentType = data.type;\n if (!contentType) {\n throw Error(`File's content type could not be resolved.`);\n }\n\n let key = sanitizeFilename(data.name);\n if (key) {\n key = uniqueId() + \"-\" + key;\n }\n\n if (data.keyPrefix) {\n key = `${sanitizeFilename(data.keyPrefix)}-${key}`;\n }\n\n // Replace all whitespace.\n key = key.replace(/\\s/g, \"\");\n\n const uploadMinFileSize = sanitizeFileSizeValue(settings.uploadMinFileSize, 0);\n const uploadMaxFileSize = sanitizeFileSizeValue(\n settings.uploadMaxFileSize,\n UPLOAD_MAX_FILE_SIZE_DEFAULT\n );\n\n const params = {\n Expires: 60,\n Bucket: S3_BUCKET,\n Conditions: [[\"content-length-range\", uploadMinFileSize, uploadMaxFileSize]], // 0 Bytes - 25MB\n Fields: {\n \"Content-Type\": contentType,\n key\n }\n };\n\n if (params.Fields.key.startsWith(\"/\")) {\n params.Fields.key = params.Fields.key.slice(1);\n }\n\n const s3 = new S3();\n const payload = s3.createPresignedPost(params);\n\n return {\n data: payload,\n file: {\n name: key,\n key,\n type: contentType,\n size: data.size\n }\n };\n};\n"],"mappings":";;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AAIA,MAAMA,SAAS,GAAGC,OAAO,CAACC,GAAR,CAAYF,SAA9B;AACA,MAAMG,4BAA4B,GAAG,QAArC,C,CAA+C;;AAE/C,MAAMC,qBAAqB,GAAG,CAACC,KAAD,EAAgBC,YAAhB,KAAiD;EAC3E,IAAI;IACAC,sBAAA,CAAWC,YAAX,CAAwBH,KAAxB,EAA+B,wBAA/B;;IACA,OAAOA,KAAP;EACH,CAHD,CAGE,OAAOI,CAAP,EAAU;IACR;IACA,OAAOH,YAAP;EACH;AACJ,CARD;;eAUe,OACXI,IADW,EAEXC,QAFW,KAGiC;EAC5C;EACA;EACA,IAAI,CAACD,IAAI,CAACE,IAAV,EAAgB;IACZF,IAAI,CAACE,IAAL,GAAY,0BAAZ;EACH;;EAED,MAAMC,WAAW,GAAGH,IAAI,CAACE,IAAzB;;EACA,IAAI,CAACC,WAAL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E,IAAI,EAAE;MACFjB,IAAI,EAAEF,GADJ;MAEFA,GAFE;MAGFH,IAAI,EAAEC,WAHJ;MAIFsB,IAAI,EAAEzB,IAAI,CAACyB;IAJT;EAFH,CAAP;AASH,C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["buffer","preSignedPostPayload","formData","FormData","Object","keys","fields","forEach","key","append","fetch","url","method","body"],"sources":["uploadFileToS3.ts"],"sourcesContent":["import FormData from \"form-data\";\nimport fetch, { Response } from \"node-fetch\";\nimport S3 from \"aws-sdk/clients/s3\";\n\nexport default async (\n buffer: Buffer,\n preSignedPostPayload: S3.PresignedPost\n): Promise<Response> => {\n const formData = new FormData();\n // Add all pre signed payload field to \"FormData\".\n Object.keys(preSignedPostPayload.fields).forEach(key => {\n formData.append(key, preSignedPostPayload.fields[key]);\n });\n // Add file content to \"FormData\".\n formData.append(\"file\", buffer);\n // Finally make the upload request to S3.\n return fetch(preSignedPostPayload.url, {\n method: \"POST\",\n body: formData\n });\n};\n"],"mappings":";;;;;;;;;AAAA;;AACA;;eAGe,OACXA,MADW,EAEXC,oBAFW,KAGS;EACpB,MAAMC,QAAQ,GAAG,IAAIC,iBAAJ,EAAjB,CADoB,CAEpB;;EACAC,MAAM,CAACC,IAAP,CAAYJ,oBAAoB,CAACK,MAAjC,EAAyCC,OAAzC,CAAiDC,GAAG,IAAI;IACpDN,QAAQ,CAACO,MAAT,CAAgBD,GAAhB,EAAqBP,oBAAoB,CAACK,MAArB,CAA4BE,GAA5B,CAArB;EACH,CAFD,EAHoB,CAMpB;;EACAN,QAAQ,CAACO,MAAT,CAAgB,MAAhB,EAAwBT,MAAxB,EAPoB,CAQpB;;EACA,OAAO,IAAAU,kBAAA,EAAMT,oBAAoB,CAACU,GAA3B,EAAgC;IACnCC,MAAM,EAAE,MAD2B;IAEnCC,IAAI,EAAEX;EAF6B,CAAhC,CAAP;AAIH,C"}
|