pim-import 4.5.13 → 4.7.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.
@@ -23,6 +23,7 @@ import {
23
23
  getLocalISOTime,
24
24
  } from "../../utils";
25
25
  import { CfLocalizedEntryField, PaginationResults } from "../../types";
26
+ import { addDesignerData } from "./designers";
26
27
 
27
28
  // const getComponentSubFamilyPagesData = async (
28
29
  // componentID: string,
@@ -197,6 +198,7 @@ const getTopicFamilyData = async (
197
198
  family: FamilyDetails,
198
199
  topicFamily: Entry
199
200
  ) => {
201
+ const defaultEnvironmentLocaleCode = await getEnvironmentDefaultLocaleCode();
200
202
  const data: CreateEntryProps = {
201
203
  fields: topicFamily?.fields || {},
202
204
  };
@@ -205,6 +207,23 @@ const getTopicFamilyData = async (
205
207
  data.fields = await addFieldValue(data, "priority", family.priority);
206
208
  data.fields.description = getPimTranslations(family, "description1");
207
209
 
210
+ // Designer
211
+ if (family?.designers) {
212
+ const designer = family.designers[0];
213
+ if (designer?.code) {
214
+ log(`set ${designer.code} designer relation`);
215
+ data.fields = await addDesignerData(data, designer);
216
+ } else {
217
+ log(`no designer found`, "WARN");
218
+ if (data.fields.designer?.[defaultEnvironmentLocaleCode]) {
219
+ log(
220
+ `remove old designer relation with ${data.fields.designer?.[defaultEnvironmentLocaleCode].sys.id}`
221
+ );
222
+ data.fields.designer = {};
223
+ }
224
+ }
225
+ }
226
+
208
227
  // lastPimSyncDate
209
228
  data.fields = await addFieldValue(data, "lastPimSyncDate", getLocalISOTime());
210
229
 
@@ -31,7 +31,6 @@ import {
31
31
  getDictionaryJson,
32
32
  getAllEntries,
33
33
  archiveEntry,
34
- addDesignerData,
35
34
  } from "../../libs/contentful";
36
35
  import type {
37
36
  Entry,
@@ -64,6 +63,7 @@ import {
64
63
  } from "../../libs/imgix";
65
64
  import { generatePDFByUrl } from "../../libs/pdf";
66
65
  import { reindexProduct } from "../../algolia/products";
66
+ import { addDesignerData } from "./designers";
67
67
 
68
68
  export type AvailableProductStatus =
69
69
  | "To be review"
@@ -9,7 +9,6 @@ import {
9
9
  cfLocales,
10
10
  addToRelationFields,
11
11
  addFieldValue,
12
- addDesignerData,
13
12
  } from "../../libs/contentful";
14
13
  import { log, serverUtils } from "../../libs/logs";
15
14
  import type {
@@ -37,6 +36,7 @@ import {
37
36
  } from "../../types";
38
37
  import { updateSubFamiliesRelToEntry, getCategoryTopicCode } from "./catalogs";
39
38
  import { pageResponse } from "../../algolia/families";
39
+ import { addDesignerData } from "./designers";
40
40
 
41
41
  const getComponentModelPagesData = async (
42
42
  componentID: string,
@@ -11,7 +11,7 @@ export interface FamilyDetails {
11
11
  description1_no?: string;
12
12
  description1_da?: string;
13
13
  description1_ru?: string;
14
- designers?: null[] | null;
14
+ designers?: Data[] | null;
15
15
  }
16
16
  export interface Data {
17
17
  code: string;
package/types/index.d.ts CHANGED
@@ -28,3 +28,4 @@ export { getStaticDailyProducts, getLatestProducts } from "./pim/endpoints";
28
28
  export { log, setServerUtils, setLogId, setLogPath, setLogFilename, getLogFolder, } from "./libs/logs";
29
29
  export { removeRecordsByStatus } from "./algolia/clean";
30
30
  export { generatePDFByUrl } from "./libs/pdf";
31
+ export { importDesigners, importDesigner } from "./pim/methods/designers";
@@ -2,7 +2,6 @@ import type { Entry, CreateEntryProps, EntryProps } from "contentful-management/
2
2
  import type { QueryOptions } from "contentful-management/dist/typings/common-types";
3
3
  import { Environment, Locale, CreateAssetProps } from "contentful-management/types";
4
4
  import { ContentfulLocale, AvailableCatalogs, TopicDetailsResponse, AssetPropFields, OtherFilters, WrapperImageFields } from "../types";
5
- import { GenericData } from "../resources/ProductDetails";
6
5
  export declare type Config = {
7
6
  accessToken: string;
8
7
  spaceId: string;
@@ -56,6 +55,4 @@ export declare const getDictionaryLocaleValue: (locale: string, fieldKey: string
56
55
  export declare const getTopicPage: (topicId: string, select?: string) => Promise<Entry>;
57
56
  export declare const createWrapperImgix: (id: string, data: WrapperImageFields) => Promise<Entry>;
58
57
  export declare const archiveEntry: (entry: Entry, isProduct?: boolean) => Promise<Entry>;
59
- export declare const getDesignerData: (designer: GenericData) => Promise<CreateEntryProps<import("contentful-management/types").KeyValueMap>>;
60
- export declare const addDesignerData: (data: any, designer: GenericData, manyReferences?: boolean) => Promise<any>;
61
58
  export declare const getEntries: (opts: QueryOptions) => Promise<import("contentful-management/dist/typings/common-types").Collection<import("contentful-management/dist/typings/entities/entry").Entry, EntryProps<Record<string, any>>>>;
@@ -0,0 +1,6 @@
1
+ import { Entry, CreateEntryProps } from "contentful-management/dist/typings/entities/entry";
2
+ import { GenericData } from "../../resources/ProductDetails";
3
+ export declare const getDesignerData: (designer: GenericData) => Promise<CreateEntryProps<import("contentful-management/types").KeyValueMap>>;
4
+ export declare const addDesignerData: (data: any, designer: GenericData, manyReferences?: boolean) => Promise<any>;
5
+ export declare const importDesigner: (designer: GenericData, skipUpdate?: boolean) => Promise<Entry>;
6
+ export declare const importDesigners: () => Promise<void>;
@@ -11,7 +11,7 @@ export interface FamilyDetails {
11
11
  description1_no?: string;
12
12
  description1_da?: string;
13
13
  description1_ru?: string;
14
- designers?: null[] | null;
14
+ designers?: Data[] | null;
15
15
  }
16
16
  export interface Data {
17
17
  code: string;