pim-import 2.39.6 → 2.40.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/dist/algolia/clean.js +100 -0
- package/dist/algolia/clean.js.map +1 -0
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/algolia/clean.ts +135 -0
- package/src/index.ts +1 -0
- package/src/types.ts +10 -0
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.removeRecordsByStatus = void 0;
|
|
4
|
+
const contentful_1 = require("../libs/contentful");
|
|
5
|
+
const logs_1 = require("../libs/logs");
|
|
6
|
+
const config_1 = require("./config");
|
|
7
|
+
const utils_1 = require("../utils");
|
|
8
|
+
const getObjects = async (contentType, offset, limit, status = "Draft", catalogCode) => {
|
|
9
|
+
const env = await contentful_1.getEnvironment();
|
|
10
|
+
const opts = {
|
|
11
|
+
content_type: contentType,
|
|
12
|
+
limit,
|
|
13
|
+
skip: offset,
|
|
14
|
+
locale: "*",
|
|
15
|
+
select: "sys",
|
|
16
|
+
};
|
|
17
|
+
const hasMultiCatalogsFields = [
|
|
18
|
+
"topicProduct",
|
|
19
|
+
"topicFamily",
|
|
20
|
+
"topicDownload",
|
|
21
|
+
];
|
|
22
|
+
if (catalogCode && hasMultiCatalogsFields.includes(contentType)) {
|
|
23
|
+
opts["fields.catalogs.sys.id[in]"] = catalogCode;
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
opts["fields.catalog.sys.id"] = catalogCode;
|
|
27
|
+
}
|
|
28
|
+
switch (status) {
|
|
29
|
+
case "Published":
|
|
30
|
+
opts["sys.archivedAt[exists]"] = false;
|
|
31
|
+
opts["sys.publishedAt[exists]"] = true;
|
|
32
|
+
break;
|
|
33
|
+
case "Changed":
|
|
34
|
+
opts["sys.archivedAt[exists]"] = false;
|
|
35
|
+
opts["sys.publishedAt[exists]"] = true;
|
|
36
|
+
opts.changed = true;
|
|
37
|
+
break;
|
|
38
|
+
case "Draft":
|
|
39
|
+
opts["sys.archivedAt[exists]"] = false;
|
|
40
|
+
opts["sys.publishedAt[exists]"] = false;
|
|
41
|
+
opts.changed = true;
|
|
42
|
+
break;
|
|
43
|
+
case "Archived":
|
|
44
|
+
opts["sys.archivedAt[exists]"] = true;
|
|
45
|
+
break;
|
|
46
|
+
}
|
|
47
|
+
const { items, total } = await env.getEntries(opts);
|
|
48
|
+
const objectIds = items.map((item) => item.sys.id);
|
|
49
|
+
const count = Number(offset) + objectIds.length;
|
|
50
|
+
return {
|
|
51
|
+
objectIds,
|
|
52
|
+
offset: Number(offset) + Number(limit),
|
|
53
|
+
limit: Number(limit),
|
|
54
|
+
completed: count >= total,
|
|
55
|
+
total,
|
|
56
|
+
};
|
|
57
|
+
};
|
|
58
|
+
const removeRecordsByStatus = async (indexKey, offset = 0, limit = 50, status = "Draft", catalogCode) => {
|
|
59
|
+
const timeStart = new Date();
|
|
60
|
+
logs_1.log(`removeRecordsByStatus - offset: ${offset} limit: ${limit} catalog: ${catalogCode} status: ${status}`);
|
|
61
|
+
let contentType;
|
|
62
|
+
switch (indexKey) {
|
|
63
|
+
case "families":
|
|
64
|
+
contentType = "topicFamily";
|
|
65
|
+
break;
|
|
66
|
+
case "subFamilies":
|
|
67
|
+
contentType = "topicSubFamily";
|
|
68
|
+
break;
|
|
69
|
+
case "models":
|
|
70
|
+
contentType = "topicModel";
|
|
71
|
+
break;
|
|
72
|
+
case "subModels":
|
|
73
|
+
contentType = "topicSubModel";
|
|
74
|
+
break;
|
|
75
|
+
case "products":
|
|
76
|
+
contentType = "topicProduct";
|
|
77
|
+
break;
|
|
78
|
+
case "downloads":
|
|
79
|
+
contentType = "topicDownload";
|
|
80
|
+
break;
|
|
81
|
+
case "projects":
|
|
82
|
+
contentType = "topicProject";
|
|
83
|
+
break;
|
|
84
|
+
}
|
|
85
|
+
if (!contentType) {
|
|
86
|
+
logs_1.log(`No contentType available for ${indexKey} indexKey`, "WARN");
|
|
87
|
+
return false;
|
|
88
|
+
}
|
|
89
|
+
const records = await getObjects(contentType, offset, limit, status, catalogCode);
|
|
90
|
+
const index = config_1.getIndex(indexKey);
|
|
91
|
+
logs_1.log(`${records.objectIds?.length} of ${records.total}`);
|
|
92
|
+
logs_1.log(`Deleting ${records.objectIds?.length} ${catalogCode} entries with status ${status} from ${index.indexName} index...`);
|
|
93
|
+
await index.deleteObjects(records.objectIds);
|
|
94
|
+
const timeEnd = new Date();
|
|
95
|
+
const seconds = utils_1.secondBetweenTwoDate(timeStart, timeEnd);
|
|
96
|
+
logs_1.log(`Execution time: ${seconds} seconds`);
|
|
97
|
+
return { ...records };
|
|
98
|
+
};
|
|
99
|
+
exports.removeRecordsByStatus = removeRecordsByStatus;
|
|
100
|
+
//# sourceMappingURL=clean.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"clean.js","sourceRoot":"","sources":["../../src/algolia/clean.ts"],"names":[],"mappings":";;;AAAA,mDAAoD;AAMpD,uCAAmC;AACnC,qCAAyD;AACzD,oCAAgD;AAEhD,MAAM,UAAU,GAAG,KAAK,EACtB,WAAmB,EACnB,MAAc,EACd,KAAa,EACb,SAA+B,OAAO,EACtC,WAA+B,EACI,EAAE;IACrC,MAAM,GAAG,GAAG,MAAM,2BAAc,EAAE,CAAC;IACnC,MAAM,IAAI,GAAQ;QAChB,YAAY,EAAE,WAAW;QACzB,KAAK;QACL,IAAI,EAAE,MAAM;QACZ,MAAM,EAAE,GAAG;QACX,MAAM,EAAE,KAAK;KACd,CAAC;IAEF,MAAM,sBAAsB,GAAG;QAC7B,cAAc;QACd,aAAa;QACb,eAAe;KAChB,CAAC;IACF,IAAI,WAAW,IAAI,sBAAsB,CAAC,QAAQ,CAAC,WAAW,CAAC,EAAE;QAC/D,IAAI,CAAC,4BAA4B,CAAC,GAAG,WAAW,CAAC;KAClD;SAAM;QACL,IAAI,CA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I,IAAI,EAAE,CAAC;IAC3B,MAAM,OAAO,GAAG,4BAAoB,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;IACzD,UAAG,CAAC,mBAAmB,OAAO,UAAU,CAAC,CAAC;IAE1C,OAAO,EAAE,GAAG,OAAO,EAAE,CAAC;AACxB,CAAC,CAAC;AA/DW,QAAA,qBAAqB,yBA+DhC"}
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.importDownloads = exports.removeProjectObject = exports.reindexProjects = exports.reindexProject = exports.removeDownloadObject = exports.reindexDownloads = exports.reindexDownload = exports.removeModelObject = exports.reindexModels = exports.reindexModel = exports.removeSubModelObject = exports.reindexSubModels = exports.reindexSubModel = exports.removeProductObject = exports.reindexProducts = exports.reindexProduct = exports.removeSubFamilyObject = exports.reindexSubFamily = exports.reindexSubFamilies = exports.removeFamilyObject = exports.reindexFamily = exports.reindexFamilies = exports.resetIndexSettings = exports.audit = exports.getAllProductEntriesByCatalog = exports.setProductRelationships = exports.setProductsRelationships = exports.importProductByCode = exports.importFamilies = exports.importSubFamilies = exports.importSubModels = exports.importModels = exports.dailyProductsUpdate = exports.importLatestProducts = exports.importCategoriesAndSubFamilies = exports.importDictionaryProductSubLine = exports.importDictionaryProductLine = exports.importDictionaryIcons = exports.importDictionaryFields = exports.getFileFromS3 = exports.saveJsonToS3 = exports.uploadS3 = exports.initS3 = exports.getTopicPage = exports.getEntryByID = exports.deleteEntries = exports.deletePages = exports.initBaseEntries = exports.initContentful = exports.initPim = void 0;
|
|
4
|
-
exports.initLog = exports.setLogId = exports.log = exports.getStaticDailyProducts = exports.getLocalISOTime = void 0;
|
|
4
|
+
exports.removeRecordsByStatus = exports.initLog = exports.setLogId = exports.log = exports.getStaticDailyProducts = exports.getLocalISOTime = void 0;
|
|
5
5
|
const sentry_1 = require("./libs/sentry");
|
|
6
6
|
sentry_1.initSentry();
|
|
7
7
|
var config_1 = require("./pim/config");
|
|
@@ -83,4 +83,6 @@ var logs_1 = require("./libs/logs");
|
|
|
83
83
|
Object.defineProperty(exports, "log", { enumerable: true, get: function () { return logs_1.log; } });
|
|
84
84
|
Object.defineProperty(exports, "setLogId", { enumerable: true, get: function () { return logs_1.setLogId; } });
|
|
85
85
|
Object.defineProperty(exports, "initLog", { enumerable: true, get: function () { return logs_1.initLog; } });
|
|
86
|
+
var clean_1 = require("./algolia/clean");
|
|
87
|
+
Object.defineProperty(exports, "removeRecordsByStatus", { enumerable: true, get: function () { return clean_1.removeRecordsByStatus; } });
|
|
86
88
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;AAAA,0CAA2C;AAC3C,mBAAU,EAAE,CAAC;AACb,uCAA+C;AAAtC,iGAAA,IAAI,OAAW;AACxB,gDAO2B;AANzB,4GAAA,IAAI,OAAkB;AACtB,6GAAA,eAAe,OAAA;AACf,yGAAA,WAAW,OAAA;AACX,2GAAA,aAAa,OAAA;AACb,0GAAA,YAAY,OAAA;AACZ,0GAAA,YAAY,OAAA;AAEd,gCAKmB;AAJjB,4FAAA,IAAI,OAAU;AACd,8FAAA,MAAM,OAAY;AAClB,kGAAA,YAAY,OAAA;AACZ,mGAAA,aAAa,OAAA;AAEf,uDAKkC;AAJhC,oHAAA,sBAAsB,OAAA;AACtB,mHAAA,qBAAqB,OAAA;AACrB,yHAAA,2BAA2B,OAAA;AAC3B,4HAAA,8BAA8B,OAAA;AAEhC,mDAAwE;AAA/D,0HAAA,8BAA8B,OAAA;AACvC,+DAAoE;AAA3D,sHAAA,oBAAoB,OAAA;AAC7B,yEAAwE;AAA/D,0HAAA,mBAAmB,OAAA;AAC5B,+CAAoD;AAA3C,sGAAA,YAAY,OAAA;AACrB,qDAA0D;AAAjD,4GAAA,eAAe,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,2GAAA,eAAe,OAAA;AACf,+GAAA,mBAAmB,OAAA;AAErB,iDAI6B;AAH3B,4GAAA,eAAe,OAAA;AACf,6GAAA,gBAAgB,OAAA;AAChB,iHAAA,oBAAoB,OAAA;AAEtB,2CAI0B;AAHxB,sGAAA,YAAY,OAAA;AACZ,uGAAA,aAAa,OAAA;AACb,2GAAA,iBAAiB,OAAA;AAEnB,iDAI6B;AAH3B,4GAAA,eAAe,OAAA;AACf,6GAAA,gBAAgB,OAAA;AAChB,iHAAA,oBAAoB,OAAA;AAEtB,+CAI4B;AAH1B,0GAAA,cAAc,OAAA;AACd,2GAAA,eAAe,OAAA;AACf,+GAAA,mBAAmB,OAAA;AAErB,6CAAqD;AAA5C,yGAAA,eAAe,OAAA;AACxB,iCAA0C;AAAjC,wGAAA,eAAe,OAAA;AACxB,6CAAyD;AAAhD,mHAAA,sBAAsB,OAAA;AAC/B,oCAAqD;AAA5C,2FAAA,GAAG,OAAA;AAAE,gGAAA,QAAQ,OAAA;AAAE,+FAAA,OAAO,OAAA;AAC/B,yCAAwD;AAA/C,8GAAA,qBAAqB,OAAA"}
|
package/package.json
CHANGED
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { getEnvironment } from "../libs/contentful";
|
|
2
|
+
import {
|
|
3
|
+
AvailableCatalogs,
|
|
4
|
+
AvailableEntryStatus,
|
|
5
|
+
AlgoliaPaginateObjectIds,
|
|
6
|
+
} from "../types";
|
|
7
|
+
import { log } from "../libs/logs";
|
|
8
|
+
import { getIndex, AvailableIndicesKey } from "./config";
|
|
9
|
+
import { secondBetweenTwoDate } from "../utils";
|
|
10
|
+
|
|
11
|
+
const getObjects = async (
|
|
12
|
+
contentType: string,
|
|
13
|
+
offset: number,
|
|
14
|
+
limit: number,
|
|
15
|
+
status: AvailableEntryStatus = "Draft",
|
|
16
|
+
catalogCode?: AvailableCatalogs
|
|
17
|
+
): Promise<AlgoliaPaginateObjectIds> => {
|
|
18
|
+
const env = await getEnvironment();
|
|
19
|
+
const opts: any = {
|
|
20
|
+
content_type: contentType,
|
|
21
|
+
limit,
|
|
22
|
+
skip: offset,
|
|
23
|
+
locale: "*",
|
|
24
|
+
select: "sys",
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
const hasMultiCatalogsFields = [
|
|
28
|
+
"topicProduct",
|
|
29
|
+
"topicFamily",
|
|
30
|
+
"topicDownload",
|
|
31
|
+
];
|
|
32
|
+
if (catalogCode && hasMultiCatalogsFields.includes(contentType)) {
|
|
33
|
+
opts["fields.catalogs.sys.id[in]"] = catalogCode;
|
|
34
|
+
} else {
|
|
35
|
+
opts["fields.catalog.sys.id"] = catalogCode;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
switch (status) {
|
|
39
|
+
case "Published":
|
|
40
|
+
opts["sys.archivedAt[exists]"] = false;
|
|
41
|
+
opts["sys.publishedAt[exists]"] = true;
|
|
42
|
+
break;
|
|
43
|
+
case "Changed":
|
|
44
|
+
opts["sys.archivedAt[exists]"] = false;
|
|
45
|
+
opts["sys.publishedAt[exists]"] = true;
|
|
46
|
+
opts.changed = true;
|
|
47
|
+
break;
|
|
48
|
+
case "Draft":
|
|
49
|
+
opts["sys.archivedAt[exists]"] = false;
|
|
50
|
+
opts["sys.publishedAt[exists]"] = false;
|
|
51
|
+
opts.changed = true;
|
|
52
|
+
break;
|
|
53
|
+
case "Archived":
|
|
54
|
+
opts["sys.archivedAt[exists]"] = true;
|
|
55
|
+
break;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const { items, total } = await env.getEntries(opts);
|
|
59
|
+
|
|
60
|
+
const objectIds = items.map((item) => item.sys.id);
|
|
61
|
+
const count: number = Number(offset) + objectIds.length;
|
|
62
|
+
|
|
63
|
+
return {
|
|
64
|
+
objectIds,
|
|
65
|
+
offset: Number(offset) + Number(limit),
|
|
66
|
+
limit: Number(limit),
|
|
67
|
+
completed: count >= total, // if is true the import is completed
|
|
68
|
+
total,
|
|
69
|
+
};
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
export const removeRecordsByStatus = async (
|
|
73
|
+
indexKey: AvailableIndicesKey,
|
|
74
|
+
offset: number = 0,
|
|
75
|
+
limit: number = 50,
|
|
76
|
+
status: AvailableEntryStatus = "Draft",
|
|
77
|
+
catalogCode?: AvailableCatalogs
|
|
78
|
+
) => {
|
|
79
|
+
const timeStart = new Date();
|
|
80
|
+
log(
|
|
81
|
+
`removeRecordsByStatus - offset: ${offset} limit: ${limit} catalog: ${catalogCode} status: ${status}`
|
|
82
|
+
);
|
|
83
|
+
|
|
84
|
+
let contentType;
|
|
85
|
+
switch (indexKey) {
|
|
86
|
+
case "families":
|
|
87
|
+
contentType = "topicFamily";
|
|
88
|
+
break;
|
|
89
|
+
case "subFamilies":
|
|
90
|
+
contentType = "topicSubFamily";
|
|
91
|
+
break;
|
|
92
|
+
case "models":
|
|
93
|
+
contentType = "topicModel";
|
|
94
|
+
break;
|
|
95
|
+
case "subModels":
|
|
96
|
+
contentType = "topicSubModel";
|
|
97
|
+
break;
|
|
98
|
+
case "products":
|
|
99
|
+
contentType = "topicProduct";
|
|
100
|
+
break;
|
|
101
|
+
case "downloads":
|
|
102
|
+
contentType = "topicDownload";
|
|
103
|
+
break;
|
|
104
|
+
case "projects":
|
|
105
|
+
contentType = "topicProject";
|
|
106
|
+
break;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
if (!contentType) {
|
|
110
|
+
log(`No contentType available for ${indexKey} indexKey`, "WARN");
|
|
111
|
+
return false;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
const records = await getObjects(
|
|
115
|
+
contentType,
|
|
116
|
+
offset,
|
|
117
|
+
limit,
|
|
118
|
+
status,
|
|
119
|
+
catalogCode
|
|
120
|
+
);
|
|
121
|
+
|
|
122
|
+
// Delete records from Algolia
|
|
123
|
+
const index = getIndex(indexKey);
|
|
124
|
+
log(`${records.objectIds?.length} of ${records.total}`);
|
|
125
|
+
log(
|
|
126
|
+
`Deleting ${records.objectIds?.length} ${catalogCode} entries with status ${status} from ${index.indexName} index...`
|
|
127
|
+
);
|
|
128
|
+
await index.deleteObjects(records.objectIds as string[]);
|
|
129
|
+
|
|
130
|
+
const timeEnd = new Date();
|
|
131
|
+
const seconds = secondBetweenTwoDate(timeStart, timeEnd);
|
|
132
|
+
log(`Execution time: ${seconds} seconds`);
|
|
133
|
+
|
|
134
|
+
return { ...records };
|
|
135
|
+
};
|
package/src/index.ts
CHANGED
|
@@ -88,3 +88,4 @@ export { importDownloads } from "./downloads/import";
|
|
|
88
88
|
export { getLocalISOTime } from "./utils";
|
|
89
89
|
export { getStaticDailyProducts } from "./pim/endpoints";
|
|
90
90
|
export { log, setLogId, initLog } from "./libs/logs";
|
|
91
|
+
export { removeRecordsByStatus } from "./algolia/clean";
|
package/src/types.ts
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
export type AvailableCatalogs = "ARCHITECTURAL" | "OUTDOOR" | "DECORATIVE";
|
|
2
2
|
|
|
3
|
+
export type AvailableEntryStatus =
|
|
4
|
+
| "Published"
|
|
5
|
+
| "Changed"
|
|
6
|
+
| "Draft"
|
|
7
|
+
| "Archived";
|
|
8
|
+
|
|
3
9
|
/**
|
|
4
10
|
* Not empty array type
|
|
5
11
|
*
|
|
@@ -123,6 +129,10 @@ export interface AlgoliaPaginateRecords extends PaginationResults {
|
|
|
123
129
|
objects: Readonly<Record<string, any>>[];
|
|
124
130
|
}
|
|
125
131
|
|
|
132
|
+
export interface AlgoliaPaginateObjectIds extends PaginationResults {
|
|
133
|
+
objectIds: string[];
|
|
134
|
+
}
|
|
135
|
+
|
|
126
136
|
export type AssetPropFields = {
|
|
127
137
|
/** Title for this asset */
|
|
128
138
|
title: {
|