@nascentdigital/funnel-cms 6.1.9 → 7.0.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.
@@ -148,14 +148,25 @@ export declare namespace CollectionClient {
148
148
  type Result = Schema.Collection.Data.AsGroup;
149
149
  }
150
150
  namespace Duplicate {
151
- type TargetCollection = 'current' | 'new';
152
- export type Args = {
153
- source: Schema.Collection.Id;
154
- targetCollection: TargetCollection;
155
- targetLanguage: Language;
156
- };
157
- export type Result = Schema.Collection.Data.AsGroup;
158
- export {};
151
+ type Args = Args.Extend | Args.Fork;
152
+ namespace Args {
153
+ type Source = {
154
+ groupId: Schema.Collection.GroupId;
155
+ language: Language;
156
+ };
157
+ type Extend = {
158
+ operation: 'extend';
159
+ language: Language;
160
+ source: Source;
161
+ };
162
+ type Fork = {
163
+ operation: 'fork';
164
+ language: Language;
165
+ name: string;
166
+ source: Source;
167
+ };
168
+ }
169
+ type Result = Schema.Collection.Data.AsGroup;
159
170
  }
160
171
  namespace Update {
161
172
  type Args = Update;
@@ -1,17 +1,18 @@
1
- import { Schema } from '@nascentdigital/funnel-core';
1
+ import { Logger, Schema } from '@nascentdigital/funnel-core';
2
2
  import { CollectionClient } from '../api';
3
3
  import { IContentfulContentClient } from './IContentfulContentClient';
4
4
  import { ContentfulCollectionData } from './models';
5
5
  export declare class ContentfulCollectionClient implements CollectionClient {
6
6
  readonly cms: IContentfulContentClient;
7
+ readonly log: Logger;
7
8
  constructor(cms: IContentfulContentClient);
8
9
  getOverview(args: CollectionClient.GetOverview.Args): Promise<CollectionClient.GetOverview.Result>;
9
10
  getItems({ language, ...args }: CollectionClient.GetItems.Args): Promise<CollectionClient.GetItems.Result>;
10
11
  find(args: CollectionClient.Find.Args): Promise<CollectionClient.Find.Result>;
11
- getGroup(args: CollectionClient.GetGroup.Args): Promise<ContentfulCollectionClient.GetGroup.Result>;
12
+ getGroup({ type, brand, language, groupId, version }: CollectionClient.GetGroup.Args): Promise<ContentfulCollectionClient.GetGroup.Result>;
12
13
  get(args: CollectionClient.Get.Args): Promise<ContentfulCollectionClient.Get.Result>;
13
14
  create(args: CollectionClient.Create.Args): Promise<ContentfulCollectionClient.Create.Result>;
14
- duplicate(args: CollectionClient.Duplicate.Args): Promise<CollectionClient.Duplicate.Result>;
15
+ duplicate({ source, ...target }: CollectionClient.Duplicate.Args): Promise<CollectionClient.Duplicate.Result>;
15
16
  update(args: CollectionClient.Update.Args): Promise<ContentfulCollectionClient.Update.Result>;
16
17
  replace(args: CollectionClient.Replace.Args): Promise<CollectionClient.Replace.Result>;
17
18
  unpublish(args: CollectionClient.Unpublish.Args): Promise<CollectionClient.Unpublish.Result>;
@@ -20,6 +20,7 @@ const models_1 = require("./models");
20
20
  class ContentfulCollectionClient {
21
21
  constructor(cms) {
22
22
  this.cms = cms;
23
+ this.log = funnel_core_1.Logger.get('cms:collection');
23
24
  }
24
25
  async getOverview(args) {
25
26
  // fetch all collections
@@ -88,17 +89,16 @@ class ContentfulCollectionClient {
88
89
  async find(args) {
89
90
  throw new funnel_core_1.NotImplementedError();
90
91
  }
91
- async getGroup(args) {
92
+ async getGroup({ type, brand, language, groupId, version }) {
92
93
  var _a, _b;
93
94
  // fetch items (bail if there are no instances
94
95
  const { cms } = this;
95
- const { entries } = await cms.getEntries(Object.assign({ content_type: models_1.ContentfulCollectionData.contentType, version: args.version, select: getCollectionSelect(funnel_core_1.Schema.Collection.Data.AsGroup.Instance.props) }, getCollectionQueryParams(args)));
96
+ const { entries } = await cms.getEntries(Object.assign({ content_type: models_1.ContentfulCollectionData.contentType, version, select: getCollectionSelect(funnel_core_1.Schema.Collection.Data.AsGroup.Instance.props) }, getCollectionQueryParams({ brand, groupId, version })));
96
97
  // bail if no items
97
98
  if (entries.length === 0) {
98
99
  return undefined;
99
100
  }
100
101
  // create group
101
- const { type, brand, language, groupId, version } = args;
102
102
  const schema = funnel_core_1.Schema.Site.getCollection(type);
103
103
  const instances = entries.map(entry => models_1.ContentfulCollectionData.deserialize(entry, funnel_core_1.Schema.Collection.Data.AsGroup.Instance.props));
104
104
  const result = {
@@ -232,8 +232,120 @@ class ContentfulCollectionClient {
232
232
  }
233
233
  }
234
234
  }
235
- async duplicate(args) {
236
- throw new funnel_core_1.NotImplementedError();
235
+ async duplicate(_a) {
236
+ var _b, _c;
237
+ var { source } = _a, target = __rest(_a, ["source"]);
238
+ // get collection by group id
239
+ const { cms, log } = this;
240
+ const { groupId, language: sourceLanguage } = source;
241
+ const { entries: sourceGroup } = await cms.getEntries(Object.assign(Object.assign({ content_type: models_1.ContentfulCollectionData.contentType, version: 'draft', select: getCollectionSelect(['id', 'language']) }, getCollectionQueryParams({ groupId })), { pagination: 'all' }));
242
+ // throw if there is no source collection
243
+ const sourceRef = sourceGroup.find(collection => collection.language === sourceLanguage);
244
+ if (!sourceRef) {
245
+ throw new funnel_core_1.NotFoundError(`Unable to resolve collection in group "${groupId}" in "${sourceLanguage}"`);
246
+ }
247
+ // make sure target language doesn't already exist in group
248
+ if (target.operation === 'extend') {
249
+ if (sourceGroup.some(collection => collection.language === target.language)) {
250
+ throw new funnel_core_1.InvalidOperationError(`There is already a collection in group "${groupId}" with language "${target.language}"`);
251
+ }
252
+ }
253
+ // get full source with refs
254
+ const { entries: [sourceEntry], references } = await cms.getEntries(Object.assign({ content_type: models_1.ContentfulCollectionData.contentType, includeLinks: true, version: 'draft', pagination: { page: 1, pageSize: 1 }, select: getCollectionSelect(funnel_core_1.Schema.Collection.Data.AsContent.props) }, getCollectionQueryParams({ ids: [sourceRef.id] })));
255
+ if (!sourceEntry) {
256
+ throw new funnel_core_1.NotFoundError(`Unable to resolve collection with id "${sourceRef.id}"`);
257
+ }
258
+ const sourceCollection = models_1.ContentfulCollectionData.deserialize(sourceEntry);
259
+ const sourceRefIds = ((_b = sourceEntry.references) !== null && _b !== void 0 ? _b : [])
260
+ .filter(link => link.sys.linkType === 'Entry')
261
+ .map(link => link.sys.id);
262
+ const sourceReferences = models_1.ContentfulCollectionData.deserializeRefs(references);
263
+ const sourcePageRefs = Object.values(sourceReferences.pages)
264
+ .filter(page => sourceRefIds.includes(page.id))
265
+ .map(page => ({
266
+ id: page.id,
267
+ groupId: page.groupId
268
+ }));
269
+ const sourceCollectionRefs = Object.values(sourceReferences.collections)
270
+ .filter(collection => sourceRefIds.includes(collection.id))
271
+ .map(collection => ({
272
+ id: collection.id,
273
+ groupId: collection.groupId
274
+ }));
275
+ // translate references
276
+ // FIXME: this will not work for page references
277
+ const { pages: translatedPages, collections: translatedCollections } = await cms.getTranslatedReferences({
278
+ from: { region: '__none', language: sourceLanguage },
279
+ to: { region: '__none', language: target.language },
280
+ pages: sourcePageRefs,
281
+ collections: sourceCollectionRefs
282
+ });
283
+ const translatedRefs = [...translatedPages, ...translatedCollections].filter(funnel_core_1.Value.isDefined);
284
+ // update refs
285
+ const updateRefs = (source, mappings) => {
286
+ // skip if there's no json
287
+ if (!source) {
288
+ return source;
289
+ }
290
+ // or if there's no mappings
291
+ else if (mappings.length === 0) {
292
+ return source;
293
+ }
294
+ // serialize
295
+ let serialized = JSON.stringify(source);
296
+ // replace
297
+ for (const { from, to } of mappings) {
298
+ serialized = serialized.replaceAll(`"${from}"`, `"${to}"`);
299
+ }
300
+ // deserialize
301
+ return JSON.parse(serialized);
302
+ };
303
+ // create duplicate collection
304
+ try {
305
+ const targetData = {
306
+ groupId: target.operation === 'extend'
307
+ ? sourceCollection.groupId
308
+ : funnel_core_1.Value.uuid(),
309
+ version: 1,
310
+ type: sourceCollection.type,
311
+ brand: sourceCollection.brand,
312
+ language: target.language,
313
+ name: sourceCollection.name,
314
+ tags: sourceCollection.tags,
315
+ state: 'draft',
316
+ errors: sourceCollection.errors,
317
+ fields: updateRefs(sourceCollection.fields, translatedRefs)
318
+ };
319
+ const targetModel = funnel_core_1.Schema.CollectionModel.from(targetData);
320
+ targetModel.sync();
321
+ // create target collection
322
+ const targetEntry = await cms.createEntry(models_1.ContentfulCollectionData.contentType, Object.assign(Object.assign({}, targetData), { valid: !sourceCollection.errors, references: ((_c = sourceEntry.references) !== null && _c !== void 0 ? _c : []).map(link => {
323
+ var _a, _b;
324
+ // replace entry ids if mapped
325
+ if (link.sys.linkType === 'Entry') {
326
+ link.sys.id = (_b = (_a = translatedRefs.find(({ from }) => from === link.sys.id)) === null || _a === void 0 ? void 0 : _a.to) !== null && _b !== void 0 ? _b : link.sys.id;
327
+ }
328
+ // return link
329
+ return link;
330
+ }) }));
331
+ // get group for duplicated collection
332
+ const group = await this.getGroup({
333
+ brand: targetEntry.brand,
334
+ groupId: targetEntry.groupId,
335
+ type: targetEntry.type,
336
+ language: targetEntry.language,
337
+ version: 'draft'
338
+ });
339
+ if (!group) {
340
+ throw new funnel_core_1.NotFoundError(`Cannot find group "${targetEntry.groupId}" after creating duplicate collection`);
341
+ }
342
+ // return group
343
+ return group;
344
+ }
345
+ // handle errors
346
+ catch (e) {
347
+ throw funnel_core_1.IsometricErrorUtils.coerceError(e);
348
+ }
237
349
  }
238
350
  async update(args) {
239
351
  var _a;
@@ -283,7 +395,7 @@ class ContentfulCollectionClient {
283
395
  exports.ContentfulCollectionClient = ContentfulCollectionClient;
284
396
  function getCollectionQueryParams(query) {
285
397
  // build filters
286
- const { ids = [], groupId, brand, type, slug, language, name, tags = [], tagsMatch = 'any', version } = query;
398
+ const { ids = [], groupId, brand, type, slug, language, name, tags = [], tagsMatch = 'any' } = query;
287
399
  const filters = {};
288
400
  // filter id(s)
289
401
  if (ids.length === 1) {
@@ -349,6 +461,7 @@ function getCollectionSelect(props) {
349
461
  case 'type':
350
462
  case 'language':
351
463
  case 'name':
464
+ case 'fields':
352
465
  case 'tags':
353
466
  case 'state':
354
467
  case 'errors':
@@ -41,6 +41,7 @@ export declare class ContentfulContentClient implements ContentClient, IContentf
41
41
  updateEntry<TEntry extends ContentfulData>(entry: ContentfulData.Update<TEntry>): Promise<TEntry>;
42
42
  uploadAsset(args: IContentfulContentClient.UploadAsset.Args): Promise<IContentfulContentClient.UploadAsset.Result>;
43
43
  getTranslatedReferences({ to, pages, collections }: IContentfulContentClient.GetTranslatedReferences.Args): Promise<IContentfulContentClient.GetTranslatedReferences.Result>;
44
+ private getReadonlyClient;
44
45
  static forEditor({ sdk, contentApiPath }: ContentfulContentClient.ForEditorArgs): Promise<ContentfulContentClient>;
45
46
  }
46
47
  export declare namespace ContentfulContentClient {
@@ -103,7 +103,7 @@ class ContentfulContentClient {
103
103
  var { entryId, includeLinks = false, version = 'draft' } = _a, query = __rest(_a, ["entryId", "includeLinks", "version"]);
104
104
  this.log.v('getEntry - fetching for', Object.assign({ entryId, version, includeLinks }, query));
105
105
  // get entry
106
- const client = version === 'published' ? this.cda : this.cpa;
106
+ const { client, normalizer } = this.getReadonlyClient(version);
107
107
  const result = await client.entry.getMany({
108
108
  query: Object.assign(Object.assign({ 'sys.id': entryId }, query), { include: includeLinks === true
109
109
  ? 10
@@ -112,8 +112,8 @@ class ContentfulContentClient {
112
112
  const { items: [item], includes } = result;
113
113
  this.log.v('getEntry - fetched', result);
114
114
  // bind references
115
- const entry = item ? models_2.ContentfulData.fromCdaData(item) : undefined;
116
- const references = (_c = (_b = includes === null || includes === void 0 ? void 0 : includes.Entry) === null || _b === void 0 ? void 0 : _b.map(link => models_2.ContentfulData.fromCdaData(link))) !== null && _c !== void 0 ? _c : [];
115
+ const entry = item ? normalizer(item) : undefined;
116
+ const references = (_c = (_b = includes === null || includes === void 0 ? void 0 : includes.Entry) === null || _b === void 0 ? void 0 : _b.map(link => normalizer(link))) !== null && _c !== void 0 ? _c : [];
117
117
  // return normalized item
118
118
  return { entry, references };
119
119
  }
@@ -129,7 +129,7 @@ class ContentfulContentClient {
129
129
  let hasMorePages = true;
130
130
  let totalItems = undefined;
131
131
  // loop until no more pages
132
- const client = version === 'published' ? this.cda : this.cpa;
132
+ const { client, normalizer } = this.getReadonlyClient(version);
133
133
  const entries = [];
134
134
  const includes = [];
135
135
  do {
@@ -141,7 +141,7 @@ class ContentfulContentClient {
141
141
  }), { items } = _d, response = __rest(_d, ["items"]);
142
142
  this.log.v('getEntries - fetching page', Object.assign({ items }, response));
143
143
  // add items
144
- items.forEach(item => entries.push(models_2.ContentfulData.fromCdaData(item)));
144
+ items.forEach(item => entries.push(normalizer(item)));
145
145
  includes.push(...((_c = (_b = response.includes) === null || _b === void 0 ? void 0 : _b.Entry) !== null && _c !== void 0 ? _c : []));
146
146
  // update paging info
147
147
  totalItemFetched += items.length;
@@ -153,7 +153,7 @@ class ContentfulContentClient {
153
153
  } while (hasMorePages);
154
154
  this.log.v('getEntries - fetched all', { entries, includes });
155
155
  // normalize references
156
- const references = includes.map(link => models_2.ContentfulData.fromCdaData(link));
156
+ const references = includes.map(link => normalizer(link));
157
157
  // return
158
158
  return {
159
159
  entries,
@@ -288,6 +288,16 @@ class ContentfulContentClient {
288
288
  collections: translatedCollections
289
289
  };
290
290
  }
291
+ getReadonlyClient(version = 'draft') {
292
+ // published
293
+ if (version === 'published') {
294
+ return { client: this.cda, normalizer: models_2.ContentfulData.fromCdaData };
295
+ }
296
+ // draft
297
+ else {
298
+ return { client: this.cpa, normalizer: models_2.ContentfulData.fromCpaData };
299
+ }
300
+ }
291
301
  static async forEditor({ sdk, contentApiPath }) {
292
302
  var _a;
293
303
  const log = funnel_core_1.Logger.get('cms:client');
@@ -38,8 +38,21 @@ export declare namespace ContentfulData {
38
38
  };
39
39
  function calcState<TState extends string = string>({ updatedOn, publishedOn }: Pick<ContentfulData, 'updatedOn' | 'publishedOn'>): TState;
40
40
  function toEntryData<T extends Record<string, any>>(entry: T, locale: string): Fields<T>;
41
+ /**
42
+ * Normalize data from entry API
43
+ */
41
44
  function fromEntryData<T extends ContentfulData>(entry: EntryAPI): T;
45
+ /**
46
+ * Normalize data from content delivery API
47
+ */
42
48
  function fromCdaData<T extends ContentfulData>({ sys, fields }: Entry): T;
49
+ /**
50
+ * Normalize data from content management API
51
+ */
43
52
  function fromCmaData<T extends ContentfulData>({ sys, fields }: EntryProps, locale: string): T;
53
+ /**
54
+ * Normalize data from content preview API
55
+ */
56
+ function fromCpaData<T extends ContentfulData>({ sys, fields }: Entry): T;
44
57
  function findReferences(source: object): References;
45
58
  }
@@ -37,6 +37,9 @@ var ContentfulData;
37
37
  }, {});
38
38
  }
39
39
  ContentfulData.toEntryData = toEntryData;
40
+ /**
41
+ * Normalize data from entry API
42
+ */
40
43
  function fromEntryData(entry) {
41
44
  // get sys
42
45
  const sys = entry.getSys();
@@ -57,18 +60,23 @@ var ContentfulData;
57
60
  publishedOn, state: calcState({ updatedOn, publishedOn }) });
58
61
  }
59
62
  ContentfulData.fromEntryData = fromEntryData;
63
+ /**
64
+ * Normalize data from content delivery API
65
+ */
60
66
  function fromCdaData({ sys, fields }) {
61
- // simplify fields (remove locale)
62
- const normalizedFields = {};
63
- for (const key in fields) {
64
- normalizedFields[key] = fields[key];
65
- }
67
+ // parse date strings
68
+ const createdOn = Date.parse(sys.createdAt);
69
+ const updatedOn = Date.parse(sys.updatedAt);
66
70
  // return normalized form
67
- return Object.assign(Object.assign({}, normalizedFields), { __type: sys.contentType.sys.id, __version: sys.revision, id: sys.id, createdOn: Date.parse(sys.createdAt), updatedOn: Date.parse(sys.updatedAt),
71
+ return Object.assign(Object.assign({}, fields), { __type: sys.contentType.sys.id, __version: undefined, id: sys.id, createdOn,
72
+ updatedOn,
68
73
  // using updatedAt since it has to be published for delivery api
69
- publishedOn: Date.parse(sys.updatedAt), state: 'published' });
74
+ publishedOn: updatedOn, state: 'published' });
70
75
  }
71
76
  ContentfulData.fromCdaData = fromCdaData;
77
+ /**
78
+ * Normalize data from content management API
79
+ */
72
80
  function fromCmaData({ sys, fields }, locale) {
73
81
  // simplify fields (remove locale)
74
82
  const normalizedFields = {};
@@ -87,6 +95,24 @@ var ContentfulData;
87
95
  publishedOn, state: calcState({ updatedOn, publishedOn }) });
88
96
  }
89
97
  ContentfulData.fromCmaData = fromCmaData;
98
+ /**
99
+ * Normalize data from content preview API
100
+ */
101
+ function fromCpaData({ sys, fields }) {
102
+ // parse date strings
103
+ const createdOn = Date.parse(sys.createdAt);
104
+ const updatedOn = Date.parse(sys.updatedAt);
105
+ const publishedOn = 'publishedAt' in sys
106
+ ? sys.publishedAt === undefined
107
+ ? undefined
108
+ : Date.parse(sys.publishedAt)
109
+ : undefined;
110
+ // return normalized form
111
+ return Object.assign(Object.assign({}, fields), { __type: sys.contentType.sys.id, __version: undefined, id: sys.id, createdOn,
112
+ updatedOn,
113
+ publishedOn, state: calcState({ updatedOn, publishedOn }) });
114
+ }
115
+ ContentfulData.fromCpaData = fromCpaData;
90
116
  function findReferences(source) {
91
117
  // prepare sets
92
118
  const references = [];
@@ -9,7 +9,7 @@ export declare class StrapiCollectionClient implements CollectionClient {
9
9
  getGroup({ version, type, brand, groupId, language }: CollectionClient.GetGroup.Args): Promise<CollectionClient.GetGroup.Result>;
10
10
  get({ version, id }: CollectionClient.Get.Args): Promise<CollectionClient.Get.Result>;
11
11
  create(args: CollectionClient.Create.Args): Promise<CollectionClient.Create.Result>;
12
- duplicate({ source: collectionId, targetCollection, targetLanguage }: CollectionClient.Duplicate.Args): Promise<CollectionClient.Duplicate.Result>;
12
+ duplicate(args: CollectionClient.Duplicate.Args): Promise<CollectionClient.Duplicate.Result>;
13
13
  update(args: CollectionClient.Update.Args): Promise<CollectionClient.Update.Result>;
14
14
  replace({ updatedCollection, version, skipSync }: CollectionClient.Replace.Args): Promise<CollectionClient.Replace.Result>;
15
15
  unpublish(collectionId: CollectionClient.Unpublish.Args): Promise<CollectionClient.Unpublish.Result>;
@@ -276,7 +276,7 @@ class StrapiCollectionClient {
276
276
  }
277
277
  }
278
278
  }
279
- async duplicate({ source: collectionId, targetCollection, targetLanguage }) {
279
+ async duplicate(args) {
280
280
  // resolve current user (or throw)
281
281
  const { client, users } = this.provider;
282
282
  const strapiUrl = client.baseURL;
@@ -285,22 +285,27 @@ class StrapiCollectionClient {
285
285
  throw new funnel_core_1.NotAuthenticatedError();
286
286
  }
287
287
  // get collection by id
288
+ const { source } = args;
288
289
  const collectionCollection = client.collection('collections');
289
- const { data: sourceData } = await collectionCollection.findOne(collectionId, {
290
- fields: serialization_1.CollectionData.getStrapiFilter(funnel_core_1.Schema.Collection.Data.Props.all),
291
- status: 'draft',
292
- populate: serialization_1.CollectionData.populate
293
- });
294
- const sourceCollection = sourceData;
290
+ const { data } = await collectionCollection.find(Object.assign(Object.assign({ fields: serialization_1.CollectionData.getStrapiFilter(funnel_core_1.Schema.Collection.Data.Props.all) }, getCollectionQueryParams({
291
+ version: 'draft',
292
+ groupId: source.groupId,
293
+ language: source.language
294
+ })), { populate: serialization_1.CollectionData.populate }));
295
+ const sourceCollection = data[0];
295
296
  // throw if there's no collection
296
297
  if (!sourceCollection) {
297
- throw new funnel_core_1.NotFoundError(`Unable to resolve collection with id "${collectionId}"`);
298
+ throw new funnel_core_1.NotFoundError(`Unable to resolve collection for group "${source.groupId}" in "${source.language}"`);
298
299
  }
299
300
  // make sure target language doesn't already exist if we are targeting the current group
300
- if (targetCollection === 'current') {
301
- const { data: collectionsWithTargetLanguage } = await collectionCollection.find(Object.assign({ fields: ['documentId'] }, getCollectionQueryParams({ version: 'draft', groupId: sourceCollection.groupId, language: targetLanguage })));
301
+ if (args.operation === 'extend') {
302
+ const { data: collectionsWithTargetLanguage } = await collectionCollection.find(Object.assign({ fields: ['documentId'] }, getCollectionQueryParams({
303
+ version: 'draft',
304
+ groupId: sourceCollection.groupId,
305
+ language: args.language
306
+ })));
302
307
  if (collectionsWithTargetLanguage.length > 0) {
303
- throw new funnel_core_1.InvalidOperationError(`There is already a collection in group "${sourceCollection.groupId}" with ${targetLanguage} language`);
308
+ throw new funnel_core_1.InvalidOperationError(`There is already a collection in group "${sourceCollection.groupId}" with ${args.language} language`);
304
309
  }
305
310
  }
306
311
  // get refs from source collection
@@ -309,11 +314,11 @@ class StrapiCollectionClient {
309
314
  let targetCollectionRefIds;
310
315
  let targetBody;
311
316
  // if we are targeting a different language then we need to "translate" the references
312
- if (targetLanguage !== sourceCollection.lang) {
317
+ if (args.language !== sourceCollection.lang) {
313
318
  // fetch target language refs
314
319
  const { collectionIdMappings } = await Strapi_1.Strapi.translateReferences({
315
320
  client,
316
- targetLanguage,
321
+ targetLanguage: args.language,
317
322
  collectionRefs
318
323
  });
319
324
  // set target values
@@ -336,9 +341,9 @@ class StrapiCollectionClient {
336
341
  // create duplicate collection
337
342
  try {
338
343
  // create target collection using content of source
339
- const { data: dupData } = await collectionCollection.create(Object.assign({ groupId: targetCollection === 'current'
344
+ const { data: dupData } = await collectionCollection.create(Object.assign({ groupId: args.operation === 'extend'
340
345
  ? sourceCollection.groupId
341
- : funnel_core_1.Value.uuid(), version: 1, type: sourceCollection.type, brand: sourceCollection.brand, lang: targetLanguage, name: sourceCollection.name, tags: sourceCollection.tags, state: 'draft', errors: sourceCollection.errors, assetRefs: { set: assetRefs.map(ref => ref.documentId) }, collectionRefs: { set: targetCollectionRefIds } }, targetBody), { status: 'draft', populate: serialization_1.CollectionData.populate });
346
+ : funnel_core_1.Value.uuid(), version: 1, type: sourceCollection.type, brand: sourceCollection.brand, lang: args.language, name: sourceCollection.name, tags: sourceCollection.tags, state: 'draft', errors: sourceCollection.errors, assetRefs: { set: assetRefs.map(ref => ref.documentId) }, collectionRefs: { set: targetCollectionRefIds } }, targetBody), { status: 'draft', populate: serialization_1.CollectionData.populate });
342
347
  const dupCollectionData = dupData;
343
348
  console.debug('[StrapiCollectionClient] duplicate: created duplicate collection', { dupCollectionData });
344
349
  // touch new duplicated collection
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nascentdigital/funnel-cms",
3
- "version": "6.1.9",
3
+ "version": "7.0.0",
4
4
  "repository": {
5
5
  "url": "git+https://github.com/nascentdigital/funnel.git",
6
6
  "directory": "libs/cms"
@@ -48,5 +48,5 @@
48
48
  "ts-jest": "^29",
49
49
  "type-fest": "^4"
50
50
  },
51
- "gitHead": "83ecdaec850b6acd417f60a890e4a62c6534da12"
51
+ "gitHead": "4da4fb0b92a8e3cb75bf668e0c9f63d82783f59b"
52
52
  }