@strapi/data-transfer 4.21.0 → 4.21.1

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/dist/index.mjs CHANGED
@@ -2,7 +2,7 @@ import { Transform, PassThrough, Writable, Readable, Duplex, pipeline } from "st
2
2
  import path, { extname, join, posix } from "path";
3
3
  import { EOL } from "os";
4
4
  import { chain } from "stream-chain";
5
- import { isArray, zip, isObject, uniq, isEqual, mapValues, pick, reject as reject$1, capitalize, isNumber, isEmpty, last, difference, set, omit, has, pipe, assign, map as map$1, size, isNil, clone, get, once, castArray, keyBy, isString, isNaN, merge, isFinite, toNumber } from "lodash/fp";
5
+ import { isArray, zip, isObject, uniq, isEqual, mapValues, pick, reject as reject$1, capitalize, isNumber, isEmpty, last, difference, set, omit, get, has, pipe, assign, map as map$1, size, isNil, clone, once, castArray, keyBy, isString, isNaN, merge, isFinite, toNumber } from "lodash/fp";
6
6
  import { diff as diff$1 } from "semver";
7
7
  import { scryptSync, createCipheriv, createDecipheriv, randomUUID } from "crypto";
8
8
  import { EventEmitter } from "events";
@@ -1262,6 +1262,34 @@ const deleteComponent = async (uid, componentToDelete) => {
1262
1262
  await deleteComponents(uid, componentToDelete);
1263
1263
  await strapi.query(uid).delete({ where: { id: componentToDelete.id } });
1264
1264
  };
1265
+ const resolveComponentUID = ({
1266
+ paths,
1267
+ strapi: strapi2,
1268
+ data,
1269
+ contentType
1270
+ }) => {
1271
+ let value = data;
1272
+ let cType = contentType;
1273
+ for (const path2 of paths) {
1274
+ value = get(path2, value);
1275
+ if (typeof cType === "function") {
1276
+ cType = cType(value);
1277
+ }
1278
+ if (path2 in cType.attributes) {
1279
+ const attribute = cType.attributes[path2];
1280
+ if (attribute.type === "component") {
1281
+ cType = strapi2.getModel(attribute.component);
1282
+ }
1283
+ if (attribute.type === "dynamiczone") {
1284
+ cType = ({ __component }) => strapi2.getModel(__component);
1285
+ }
1286
+ }
1287
+ }
1288
+ if ("uid" in cType) {
1289
+ return cType.uid;
1290
+ }
1291
+ return void 0;
1292
+ };
1265
1293
  const sanitizeComponentLikeAttributes = (model, data) => {
1266
1294
  const { attributes } = model;
1267
1295
  const componentLikeAttributesKey = Object.entries(attributes).filter(([, attribute]) => attribute.type === "component" || attribute.type === "dynamiczone").map(([key]) => key);
@@ -1627,29 +1655,6 @@ const createEntitiesWriteStream = (options) => {
1627
1655
  const { type, id, data } = entity2;
1628
1656
  const { create, getDeepPopulateComponentLikeQuery } = query(type);
1629
1657
  const contentType = strapi2.getModel(type);
1630
- let cType = contentType;
1631
- const resolveType = (paths) => {
1632
- let value = data;
1633
- for (const path2 of paths) {
1634
- value = get(path2, value);
1635
- if (typeof cType === "function") {
1636
- cType = cType(value);
1637
- }
1638
- if (path2 in cType.attributes) {
1639
- const attribute = cType.attributes[path2];
1640
- if (attribute.type === "component") {
1641
- cType = strapi2.getModel(attribute.component);
1642
- }
1643
- if (attribute.type === "dynamiczone") {
1644
- cType = ({ __component }) => strapi2.getModel(__component);
1645
- }
1646
- }
1647
- }
1648
- if ("uid" in cType) {
1649
- return cType.uid;
1650
- }
1651
- return void 0;
1652
- };
1653
1658
  try {
1654
1659
  const created = await create({
1655
1660
  data,
@@ -1660,7 +1665,7 @@ const createEntitiesWriteStream = (options) => {
1660
1665
  updateMappingTable(type, id, created.id);
1661
1666
  diffs.forEach((diff2) => {
1662
1667
  if (diff2.kind === "modified" && last(diff2.path) === "id") {
1663
- const target = resolveType(diff2.path);
1668
+ const target = resolveComponentUID({ paths: diff2.path, data, contentType, strapi: strapi2 });
1664
1669
  if (!target) {
1665
1670
  return;
1666
1671
  }
@@ -2276,11 +2281,31 @@ function getFileStats(filepath, isLocal = false) {
2276
2281
  });
2277
2282
  });
2278
2283
  }
2284
+ async function signFile(file2) {
2285
+ const { provider } = strapi.plugins.upload;
2286
+ const { provider: providerName } = strapi.config.get("plugin.upload");
2287
+ const isPrivate = await provider.isPrivate();
2288
+ if (file2?.provider === providerName && isPrivate) {
2289
+ const signUrl = async (file22) => {
2290
+ const signedUrl = await provider.getSignedUrl(file22);
2291
+ file22.url = signedUrl.url;
2292
+ };
2293
+ await signUrl(file2);
2294
+ if (file2.formats) {
2295
+ for (const format of Object.keys(file2.formats)) {
2296
+ await signUrl(file2.formats[format]);
2297
+ }
2298
+ }
2299
+ }
2300
+ }
2279
2301
  const createAssetsStream = (strapi2) => {
2280
2302
  const generator = async function* () {
2281
2303
  const stream2 = strapi2.db.queryBuilder("plugin::upload.file").select("*").stream();
2282
2304
  for await (const file2 of stream2) {
2283
2305
  const isLocalProvider = file2.provider === "local";
2306
+ if (!isLocalProvider) {
2307
+ await signFile(file2);
2308
+ }
2284
2309
  const filepath = isLocalProvider ? join(strapi2.dirs.static.public, file2.url) : file2.url;
2285
2310
  const stats = await getFileStats(filepath, isLocalProvider);
2286
2311
  const stream22 = getFileStream(filepath, isLocalProvider);