@webiny/api-page-builder-import-export 5.38.0-beta.3 → 5.38.0-beta.4

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.
@@ -71,6 +71,9 @@ const uploadAssets = async params => {
71
71
  const newKey = `${id}/${toImport.key.replace(`${toImport.id}/`, "")}`;
72
72
  const newFile = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, toImport), {}, {
73
73
  id,
74
+ location: {
75
+ folderId: "root"
76
+ },
74
77
  key: newKey,
75
78
  meta: (0, _objectSpread2.default)((0, _objectSpread2.default)({}, toImport.meta), {}, {
76
79
  originalKey: toImport.key
@@ -1 +1 @@
1
- {"version":3,"names":["_utils","require","_uploadFilesFromS","notAPreviouslyImportedFile","importedImages","file","some","existingImportedImage","meta","originalKey","key","notAnExistingFile","existingFiles","existingFile","uploadAssets","params","context","files","fileUploadsData","oldIdToNewFileMap","Map","process","env","NODE_ENV","fileManager","listFiles","where","originalKey_in","map","importedImage","fileBeingImported","find","set","id","id_in","newFilesToImport","filter","uploadFileMap","createFilesInput","toImport","mdbid","newKey","replace","newFile","_objectSpread2","default","push","assets","uploadFilesFromS3","createFilesInBatch","exports"],"sources":["uploadAssets.ts"],"sourcesContent":["import { mdbid } from \"@webiny/utils\";\nimport { PbImportExportContext } from \"~/graphql/types\";\nimport { File, FileInput } from \"@webiny/api-file-manager/types\";\nimport { UploadFileMap, uploadFilesFromS3 } from \"~/import/utils/uploadFilesFromS3\";\nimport { FileUploadsData } from \"~/types\";\n\ninterface UploadAssetsParams {\n context: PbImportExportContext;\n files: File[];\n fileUploadsData: FileUploadsData;\n}\n\nfunction notAPreviouslyImportedFile(importedImages: File[]) {\n return (file: File) => {\n return !importedImages.some(\n existingImportedImage => existingImportedImage.meta.originalKey === file.key\n );\n };\n}\n\nfunction notAnExistingFile(existingFiles: File[]) {\n return (file: File) => {\n return !existingFiles.some(existingFile => existingFile.key === file.key);\n };\n}\n\nexport const uploadAssets = async (params: UploadAssetsParams) => {\n const { context, files, fileUploadsData } = params;\n\n const oldIdToNewFileMap = new Map<string, FileInput>();\n\n /**\n * This function contains logic of file download from S3.\n * Current we're not mocking zip file download from S3 in tests at the moment.\n * So, we're manually mocking it in case of test just by returning an empty object.\n */\n if (process.env.NODE_ENV === \"test\") {\n return oldIdToNewFileMap;\n }\n\n // Check if the requested files were already imported in the past.\n const [importedImages] = await context.fileManager.listFiles({\n where: { meta: { originalKey_in: files.map(file => file.key) } }\n });\n\n // Link files that were already imported.\n for (const importedImage of importedImages) {\n const fileBeingImported = files.find(file => file.key === importedImage.meta.originalKey);\n\n if (fileBeingImported) {\n oldIdToNewFileMap.set(fileBeingImported.id, importedImage);\n }\n }\n\n // Check if files with such IDs already exist.\n const [existingFiles] = await context.fileManager.listFiles({\n where: { id_in: files.map(file => file.id) }\n });\n\n const newFilesToImport = files\n .filter(notAnExistingFile(existingFiles))\n .filter(notAPreviouslyImportedFile(importedImages));\n\n // A map of temporary file keys (created during ZIP upload) to permanent file keys.\n const uploadFileMap: UploadFileMap = new Map();\n\n // Array of file inputs, to insert into the DB.\n const createFilesInput: FileInput[] = [];\n\n for (const toImport of newFilesToImport) {\n // We generate a new file id, key, and add `meta.originalKey` property to prevent duplicates on future imports.\n const id = mdbid();\n const newKey = `${id}/${toImport.key.replace(`${toImport.id}/`, \"\")}`;\n const newFile: FileInput = {\n ...toImport,\n id,\n key: newKey,\n meta: { ...toImport.meta, originalKey: toImport.key }\n };\n\n createFilesInput.push(newFile);\n oldIdToNewFileMap.set(toImport.id, newFile);\n uploadFileMap.set(fileUploadsData.assets[toImport.key], newFile);\n }\n\n await uploadFilesFromS3(uploadFileMap);\n\n await context.fileManager.createFilesInBatch(createFilesInput);\n\n return oldIdToNewFileMap;\n};\n"],"mappings":";;;;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAGA,IAAAC,iBAAA,GAAAD,OAAA;AASA,SAASE,0BAA0BA,CAACC,cAAsB,EAAE;EACxD,OAAQC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AACQ,WAAW,CAACyB,kBAAkB,CAACX,gBAAgB,CAAC;EAE9D,OAAOnB,iBAAiB;AAC5B,CAAC;AAAC+B,OAAA,CAAApC,YAAA,GAAAA,YAAA"}
1
+ {"version":3,"names":["_utils","require","_uploadFilesFromS","notAPreviouslyImportedFile","importedImages","file","some","existingImportedImage","meta","originalKey","key","notAnExistingFile","existingFiles","existingFile","uploadAssets","params","context","files","fileUploadsData","oldIdToNewFileMap","Map","process","env","NODE_ENV","fileManager","listFiles","where","originalKey_in","map","importedImage","fileBeingImported","find","set","id","id_in","newFilesToImport","filter","uploadFileMap","createFilesInput","toImport","mdbid","newKey","replace","newFile","_objectSpread2","default","location","folderId","push","assets","uploadFilesFromS3","createFilesInBatch","exports"],"sources":["uploadAssets.ts"],"sourcesContent":["import { mdbid } from \"@webiny/utils\";\nimport { PbImportExportContext } from \"~/graphql/types\";\nimport { File, FileInput } from \"@webiny/api-file-manager/types\";\nimport { UploadFileMap, uploadFilesFromS3 } from \"~/import/utils/uploadFilesFromS3\";\nimport { FileUploadsData } from \"~/types\";\n\ninterface UploadAssetsParams {\n context: PbImportExportContext;\n files: File[];\n fileUploadsData: FileUploadsData;\n}\n\nfunction notAPreviouslyImportedFile(importedImages: File[]) {\n return (file: File) => {\n return !importedImages.some(\n existingImportedImage => existingImportedImage.meta.originalKey === file.key\n );\n };\n}\n\nfunction notAnExistingFile(existingFiles: File[]) {\n return (file: File) => {\n return !existingFiles.some(existingFile => existingFile.key === file.key);\n };\n}\n\nexport const uploadAssets = async (params: UploadAssetsParams) => {\n const { context, files, fileUploadsData } = params;\n\n const oldIdToNewFileMap = new Map<string, FileInput>();\n\n /**\n * This function contains logic of file download from S3.\n * Current we're not mocking zip file download from S3 in tests at the moment.\n * So, we're manually mocking it in case of test just by returning an empty object.\n */\n if (process.env.NODE_ENV === \"test\") {\n return oldIdToNewFileMap;\n }\n\n // Check if the requested files were already imported in the past.\n const [importedImages] = await context.fileManager.listFiles({\n where: { meta: { originalKey_in: files.map(file => file.key) } }\n });\n\n // Link files that were already imported.\n for (const importedImage of importedImages) {\n const fileBeingImported = files.find(file => file.key === importedImage.meta.originalKey);\n\n if (fileBeingImported) {\n oldIdToNewFileMap.set(fileBeingImported.id, importedImage);\n }\n }\n\n // Check if files with such IDs already exist.\n const [existingFiles] = await context.fileManager.listFiles({\n where: { id_in: files.map(file => file.id) }\n });\n\n const newFilesToImport = files\n .filter(notAnExistingFile(existingFiles))\n .filter(notAPreviouslyImportedFile(importedImages));\n\n // A map of temporary file keys (created during ZIP upload) to permanent file keys.\n const uploadFileMap: UploadFileMap = new Map();\n\n // Array of file inputs, to insert into the DB.\n const createFilesInput: FileInput[] = [];\n\n for (const toImport of newFilesToImport) {\n // We generate a new file id, key, and add `meta.originalKey` property to prevent duplicates on future imports.\n const id = mdbid();\n const newKey = `${id}/${toImport.key.replace(`${toImport.id}/`, \"\")}`;\n const newFile: FileInput = {\n ...toImport,\n id,\n location: {\n folderId: \"root\"\n },\n key: newKey,\n meta: { ...toImport.meta, originalKey: toImport.key }\n };\n\n createFilesInput.push(newFile);\n oldIdToNewFileMap.set(toImport.id, newFile);\n uploadFileMap.set(fileUploadsData.assets[toImport.key], newFile);\n }\n\n await uploadFilesFromS3(uploadFileMap);\n\n await context.fileManager.createFilesInBatch(createFilesInput);\n\n return oldIdToNewFileMap;\n};\n"],"mappings":";;;;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAGA,IAAAC,iBAAA,GAAAD,OAAA;AASA,SAASE,0BAA0BA,CAACC,cAAsB,EAAE;EACxD,OAAQC,IAAU,IAAK;IACnB,OAAO,CAACD,cAAc,CAACE,IAAI,CACvBC,qBAAqB,IAAIA,qBAAqB,CAACC,IAAI,CAACC,WAAW,KAAKJ,IAAI,CAACK,GAC7E,CAAC;EACL,CAAC;AACL;AAEA,SAASC,iBAAiBA,CAACC,aAAqB,EAAE;EAC9C,OAAQP,IAAU,IAAK;IACnB,OAAO,CAACO,aAAa,CAACN,IAAI,CAACO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.0-beta.3",
3
+ "version": "5.38.0-beta.4",
4
4
  "main": "index.js",
5
5
  "keywords": [
6
6
  "pbie:base"
@@ -16,18 +16,18 @@
16
16
  "dependencies": {
17
17
  "@babel/runtime": "7.22.6",
18
18
  "@commodo/fields": "1.1.2-beta.20",
19
- "@webiny/api": "5.38.0-beta.3",
20
- "@webiny/api-file-manager": "5.38.0-beta.3",
21
- "@webiny/api-form-builder": "5.38.0-beta.3",
22
- "@webiny/api-page-builder": "5.38.0-beta.3",
23
- "@webiny/api-security": "5.38.0-beta.3",
24
- "@webiny/error": "5.38.0-beta.3",
25
- "@webiny/handler": "5.38.0-beta.3",
26
- "@webiny/handler-aws": "5.38.0-beta.3",
27
- "@webiny/handler-graphql": "5.38.0-beta.3",
28
- "@webiny/pubsub": "5.38.0-beta.3",
29
- "@webiny/utils": "5.38.0-beta.3",
30
- "@webiny/validation": "5.38.0-beta.3",
19
+ "@webiny/api": "5.38.0-beta.4",
20
+ "@webiny/api-file-manager": "5.38.0-beta.4",
21
+ "@webiny/api-form-builder": "5.38.0-beta.4",
22
+ "@webiny/api-page-builder": "5.38.0-beta.4",
23
+ "@webiny/api-security": "5.38.0-beta.4",
24
+ "@webiny/error": "5.38.0-beta.4",
25
+ "@webiny/handler": "5.38.0-beta.4",
26
+ "@webiny/handler-aws": "5.38.0-beta.4",
27
+ "@webiny/handler-graphql": "5.38.0-beta.4",
28
+ "@webiny/pubsub": "5.38.0-beta.4",
29
+ "@webiny/utils": "5.38.0-beta.4",
30
+ "@webiny/validation": "5.38.0-beta.4",
31
31
  "archiver": "5.3.1",
32
32
  "commodo-fields-object": "1.0.6",
33
33
  "dot-prop-immutable": "2.1.1",
@@ -48,13 +48,13 @@
48
48
  "@types/archiver": "5.3.1",
49
49
  "@types/node-fetch": "2.6.2",
50
50
  "@types/yauzl": "2.10.0",
51
- "@webiny/api-authentication": "5.38.0-beta.3",
52
- "@webiny/api-dynamodb-to-elasticsearch": "5.38.0-beta.3",
53
- "@webiny/api-tenancy": "5.38.0-beta.3",
54
- "@webiny/api-wcp": "5.38.0-beta.3",
55
- "@webiny/cli": "5.38.0-beta.3",
56
- "@webiny/db": "5.38.0-beta.3",
57
- "@webiny/project-utils": "5.38.0-beta.3",
51
+ "@webiny/api-authentication": "5.38.0-beta.4",
52
+ "@webiny/api-dynamodb-to-elasticsearch": "5.38.0-beta.4",
53
+ "@webiny/api-tenancy": "5.38.0-beta.4",
54
+ "@webiny/api-wcp": "5.38.0-beta.4",
55
+ "@webiny/cli": "5.38.0-beta.4",
56
+ "@webiny/db": "5.38.0-beta.4",
57
+ "@webiny/project-utils": "5.38.0-beta.4",
58
58
  "jest": "29.5.0",
59
59
  "jest-dynalite": "3.6.1",
60
60
  "rimraf": "3.0.2",
@@ -76,5 +76,5 @@
76
76
  ]
77
77
  }
78
78
  },
79
- "gitHead": "fa1befb07e92cfe36928481333308d88c3348d6b"
79
+ "gitHead": "0c2b5da146d534d7856ebe185671bc306a4e82e8"
80
80
  }