pim-import 5.0.0 → 5.0.2

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.
Files changed (249) hide show
  1. package/dist/algolia/clean.js +0 -1
  2. package/dist/algolia/config.js +0 -1
  3. package/dist/algolia/downloads.js +0 -1
  4. package/dist/algolia/families.js +0 -1
  5. package/dist/algolia/inspirations.js +0 -1
  6. package/dist/algolia/models.js +0 -1
  7. package/dist/algolia/news.js +0 -1
  8. package/dist/algolia/pressRelease.js +0 -1
  9. package/dist/algolia/pressReview.js +0 -1
  10. package/dist/algolia/products.js +0 -1
  11. package/dist/algolia/projects.js +0 -1
  12. package/dist/algolia/stories.js +0 -1
  13. package/dist/algolia/subFamilies.js +0 -1
  14. package/dist/algolia/subModels.js +0 -1
  15. package/dist/browser.js +0 -1
  16. package/dist/downloads/classes/manageEntry.js +0 -1
  17. package/dist/downloads/import.js +0 -1
  18. package/dist/index.js +0 -1
  19. package/dist/libs/contentful-cda.js +0 -1
  20. package/dist/libs/contentful.js +0 -1
  21. package/dist/libs/imgix.js +0 -1
  22. package/dist/libs/logs.js +0 -1
  23. package/dist/libs/netlify.js +0 -1
  24. package/dist/libs/notifications.js +0 -1
  25. package/dist/libs/pdf.js +0 -1
  26. package/dist/libs/s3.js +0 -1
  27. package/dist/libs/sentry.js +0 -1
  28. package/dist/pim/config.js +0 -1
  29. package/dist/pim/endpoints.js +0 -1
  30. package/dist/pim/methods/bulkPublish.js +0 -1
  31. package/dist/pim/methods/catalogs.js +0 -1
  32. package/dist/pim/methods/checkTopicDraftAndPagePublished.js +0 -1
  33. package/dist/pim/methods/designers.js +0 -1
  34. package/dist/pim/methods/dictionary.js +0 -1
  35. package/dist/pim/methods/families.js +0 -1
  36. package/dist/pim/methods/latestProducts.js +0 -1
  37. package/dist/pim/methods/migrateEntryFields.js +0 -1
  38. package/dist/pim/methods/models.js +0 -1
  39. package/dist/pim/methods/pages/catalogs.js +0 -1
  40. package/dist/pim/methods/pages/families.js +0 -1
  41. package/dist/pim/methods/pages/subfamilies.js +0 -1
  42. package/dist/pim/methods/products.js +0 -1
  43. package/dist/pim/methods/subfamilies.js +0 -1
  44. package/dist/pim/methods/submodels.js +0 -1
  45. package/dist/pim/request.js +0 -1
  46. package/dist/resources/AllProducts.js +0 -1
  47. package/dist/resources/Audit.js +0 -1
  48. package/dist/resources/CatalogDetails.js +0 -1
  49. package/dist/resources/CollectionModels.js +0 -1
  50. package/dist/resources/CollectionSubFamilies.js +0 -1
  51. package/dist/resources/CollectionSubModels.js +0 -1
  52. package/dist/resources/DProductSubLine.js +0 -1
  53. package/dist/resources/FamilyDetails.js +0 -1
  54. package/dist/resources/ProductDetails.js +0 -1
  55. package/dist/resources/ProductRelation.js +0 -1
  56. package/dist/resources/cfFields.js +0 -1
  57. package/dist/types.js +0 -1
  58. package/dist/utils.js +0 -1
  59. package/package.json +7 -2
  60. package/.env.example +0 -46
  61. package/.nvmrc +0 -1
  62. package/.vscode/settings.json +0 -21
  63. package/dist/algolia/clean.js.map +0 -1
  64. package/dist/algolia/config.js.map +0 -1
  65. package/dist/algolia/downloads.js.map +0 -1
  66. package/dist/algolia/families.js.map +0 -1
  67. package/dist/algolia/inspirations.js.map +0 -1
  68. package/dist/algolia/models.js.map +0 -1
  69. package/dist/algolia/news.js.map +0 -1
  70. package/dist/algolia/pressRelease.js.map +0 -1
  71. package/dist/algolia/pressReview.js.map +0 -1
  72. package/dist/algolia/products.js.map +0 -1
  73. package/dist/algolia/projects.js.map +0 -1
  74. package/dist/algolia/stories.js.map +0 -1
  75. package/dist/algolia/subFamilies.js.map +0 -1
  76. package/dist/algolia/subModels.js.map +0 -1
  77. package/dist/browser.js.map +0 -1
  78. package/dist/downloads/classes/manageEntry.js.map +0 -1
  79. package/dist/downloads/import.js.map +0 -1
  80. package/dist/index.js.map +0 -1
  81. package/dist/libs/contentful-cda.js.map +0 -1
  82. package/dist/libs/contentful.js.map +0 -1
  83. package/dist/libs/imgix.js.map +0 -1
  84. package/dist/libs/logs.js.map +0 -1
  85. package/dist/libs/netlify.js.map +0 -1
  86. package/dist/libs/notifications.js.map +0 -1
  87. package/dist/libs/pdf.js.map +0 -1
  88. package/dist/libs/s3.js.map +0 -1
  89. package/dist/libs/sentry.js.map +0 -1
  90. package/dist/pim/config.js.map +0 -1
  91. package/dist/pim/endpoints.js.map +0 -1
  92. package/dist/pim/methods/bulkPublish.js.map +0 -1
  93. package/dist/pim/methods/catalogs.js.map +0 -1
  94. package/dist/pim/methods/checkTopicDraftAndPagePublished.js.map +0 -1
  95. package/dist/pim/methods/designers.js.map +0 -1
  96. package/dist/pim/methods/dictionary.js.map +0 -1
  97. package/dist/pim/methods/families.js.map +0 -1
  98. package/dist/pim/methods/latestProducts.js.map +0 -1
  99. package/dist/pim/methods/migrateEntryFields.js.map +0 -1
  100. package/dist/pim/methods/models.js.map +0 -1
  101. package/dist/pim/methods/pages/catalogs.js.map +0 -1
  102. package/dist/pim/methods/pages/families.js.map +0 -1
  103. package/dist/pim/methods/pages/subfamilies.js.map +0 -1
  104. package/dist/pim/methods/products.js.map +0 -1
  105. package/dist/pim/methods/subfamilies.js.map +0 -1
  106. package/dist/pim/methods/submodels.js.map +0 -1
  107. package/dist/pim/request.js.map +0 -1
  108. package/dist/resources/AllProducts.js.map +0 -1
  109. package/dist/resources/Audit.js.map +0 -1
  110. package/dist/resources/CatalogDetails.js.map +0 -1
  111. package/dist/resources/CollectionModels.js.map +0 -1
  112. package/dist/resources/CollectionSubFamilies.js.map +0 -1
  113. package/dist/resources/CollectionSubModels.js.map +0 -1
  114. package/dist/resources/DProductSubLine.js.map +0 -1
  115. package/dist/resources/FamilyDetails.js.map +0 -1
  116. package/dist/resources/ProductDetails.js.map +0 -1
  117. package/dist/resources/ProductRelation.js.map +0 -1
  118. package/dist/resources/cfFields.js.map +0 -1
  119. package/dist/types.js.map +0 -1
  120. package/dist/utils.js.map +0 -1
  121. package/docs/import-data-from-the-dictionary.md +0 -83
  122. package/docs/import-products.md +0 -61
  123. package/docs/import-taxonomies-from-the-catalog.md +0 -60
  124. package/docs/settings.md +0 -47
  125. package/jest.config.js +0 -16
  126. package/local-fn/reindex.js +0 -182
  127. package/src/algolia/clean.ts +0 -164
  128. package/src/algolia/config.ts +0 -390
  129. package/src/algolia/downloads.ts +0 -346
  130. package/src/algolia/families.ts +0 -652
  131. package/src/algolia/inspirations.ts +0 -315
  132. package/src/algolia/models.ts +0 -589
  133. package/src/algolia/news.ts +0 -258
  134. package/src/algolia/pressRelease.ts +0 -255
  135. package/src/algolia/pressReview.ts +0 -247
  136. package/src/algolia/products.ts +0 -731
  137. package/src/algolia/projects.ts +0 -339
  138. package/src/algolia/stories.ts +0 -347
  139. package/src/algolia/subFamilies.ts +0 -709
  140. package/src/algolia/subModels.ts +0 -359
  141. package/src/browser.ts +0 -122
  142. package/src/downloads/classes/manageEntry.ts +0 -99
  143. package/src/downloads/csv/legal.csv +0 -5
  144. package/src/downloads/csv/products.csv +0 -373
  145. package/src/downloads/import.ts +0 -381
  146. package/src/index.ts +0 -140
  147. package/src/libs/contentful-cda.ts +0 -543
  148. package/src/libs/contentful.ts +0 -1453
  149. package/src/libs/imgix.ts +0 -297
  150. package/src/libs/logs.ts +0 -121
  151. package/src/libs/netlify.ts +0 -37
  152. package/src/libs/notifications.ts +0 -104
  153. package/src/libs/pdf.ts +0 -107
  154. package/src/libs/s3.ts +0 -305
  155. package/src/libs/sentry.ts +0 -33
  156. package/src/pim/config.ts +0 -84
  157. package/src/pim/data/productFields.json +0 -1178
  158. package/src/pim/endpoints.ts +0 -364
  159. package/src/pim/methods/bulkPublish.ts +0 -266
  160. package/src/pim/methods/catalogs.ts +0 -586
  161. package/src/pim/methods/checkTopicDraftAndPagePublished.ts +0 -70
  162. package/src/pim/methods/designers.ts +0 -128
  163. package/src/pim/methods/dictionary.ts +0 -611
  164. package/src/pim/methods/families.ts +0 -345
  165. package/src/pim/methods/latestProducts.ts +0 -70
  166. package/src/pim/methods/migrateEntryFields.ts +0 -99
  167. package/src/pim/methods/models.ts +0 -349
  168. package/src/pim/methods/pages/catalogs.ts +0 -28
  169. package/src/pim/methods/pages/families.ts +0 -50
  170. package/src/pim/methods/pages/subfamilies.ts +0 -98
  171. package/src/pim/methods/products.ts +0 -3297
  172. package/src/pim/methods/subfamilies.ts +0 -706
  173. package/src/pim/methods/submodels.ts +0 -262
  174. package/src/pim/request.ts +0 -61
  175. package/src/resources/AllProducts.ts +0 -41
  176. package/src/resources/Audit.ts +0 -24
  177. package/src/resources/CatalogDetails.ts +0 -51
  178. package/src/resources/CollectionModels.ts +0 -42
  179. package/src/resources/CollectionSubFamilies.ts +0 -45
  180. package/src/resources/CollectionSubModels.ts +0 -36
  181. package/src/resources/DProductSubLine.ts +0 -34
  182. package/src/resources/FamilyDetails.ts +0 -31
  183. package/src/resources/ProductDetails.ts +0 -352
  184. package/src/resources/ProductRelation.ts +0 -24
  185. package/src/resources/cfFields.ts +0 -8
  186. package/src/types.ts +0 -268
  187. package/src/utils.ts +0 -553
  188. package/tsconfig.json +0 -93
  189. package/tslint.json +0 -22
  190. package/types/libs/puppeteer.d.ts +0 -17
  191. package/types/pim/methods/checkIp.d.ts +0 -1
  192. /package/{types → dist}/algolia/clean.d.ts +0 -0
  193. /package/{types → dist}/algolia/config.d.ts +0 -0
  194. /package/{types → dist}/algolia/downloads.d.ts +0 -0
  195. /package/{types → dist}/algolia/families.d.ts +0 -0
  196. /package/{types → dist}/algolia/inspirations.d.ts +0 -0
  197. /package/{types → dist}/algolia/models.d.ts +0 -0
  198. /package/{types → dist}/algolia/news.d.ts +0 -0
  199. /package/{types → dist}/algolia/pressRelease.d.ts +0 -0
  200. /package/{types → dist}/algolia/pressReview.d.ts +0 -0
  201. /package/{types → dist}/algolia/products.d.ts +0 -0
  202. /package/{types → dist}/algolia/projects.d.ts +0 -0
  203. /package/{types → dist}/algolia/stories.d.ts +0 -0
  204. /package/{types → dist}/algolia/subFamilies.d.ts +0 -0
  205. /package/{types → dist}/algolia/subModels.d.ts +0 -0
  206. /package/{types → dist}/browser.d.ts +0 -0
  207. /package/{types → dist}/downloads/classes/manageEntry.d.ts +0 -0
  208. /package/{types → dist}/downloads/import.d.ts +0 -0
  209. /package/{types → dist}/index.d.ts +0 -0
  210. /package/{types → dist}/libs/contentful-cda.d.ts +0 -0
  211. /package/{types → dist}/libs/contentful.d.ts +0 -0
  212. /package/{types → dist}/libs/imgix.d.ts +0 -0
  213. /package/{types → dist}/libs/logs.d.ts +0 -0
  214. /package/{types → dist}/libs/netlify.d.ts +0 -0
  215. /package/{types → dist}/libs/notifications.d.ts +0 -0
  216. /package/{types → dist}/libs/pdf.d.ts +0 -0
  217. /package/{types → dist}/libs/s3.d.ts +0 -0
  218. /package/{types → dist}/libs/sentry.d.ts +0 -0
  219. /package/{types → dist}/pim/config.d.ts +0 -0
  220. /package/{types → dist}/pim/endpoints.d.ts +0 -0
  221. /package/{types → dist}/pim/methods/bulkPublish.d.ts +0 -0
  222. /package/{types → dist}/pim/methods/catalogs.d.ts +0 -0
  223. /package/{types → dist}/pim/methods/checkTopicDraftAndPagePublished.d.ts +0 -0
  224. /package/{types → dist}/pim/methods/designers.d.ts +0 -0
  225. /package/{types → dist}/pim/methods/dictionary.d.ts +0 -0
  226. /package/{types → dist}/pim/methods/families.d.ts +0 -0
  227. /package/{types → dist}/pim/methods/latestProducts.d.ts +0 -0
  228. /package/{types → dist}/pim/methods/migrateEntryFields.d.ts +0 -0
  229. /package/{types → dist}/pim/methods/models.d.ts +0 -0
  230. /package/{types → dist}/pim/methods/pages/catalogs.d.ts +0 -0
  231. /package/{types → dist}/pim/methods/pages/families.d.ts +0 -0
  232. /package/{types → dist}/pim/methods/pages/subfamilies.d.ts +0 -0
  233. /package/{types → dist}/pim/methods/products.d.ts +0 -0
  234. /package/{types → dist}/pim/methods/subfamilies.d.ts +0 -0
  235. /package/{types → dist}/pim/methods/submodels.d.ts +0 -0
  236. /package/{types → dist}/pim/request.d.ts +0 -0
  237. /package/{types → dist}/resources/AllProducts.d.ts +0 -0
  238. /package/{types → dist}/resources/Audit.d.ts +0 -0
  239. /package/{types → dist}/resources/CatalogDetails.d.ts +0 -0
  240. /package/{types → dist}/resources/CollectionModels.d.ts +0 -0
  241. /package/{types → dist}/resources/CollectionSubFamilies.d.ts +0 -0
  242. /package/{types → dist}/resources/CollectionSubModels.d.ts +0 -0
  243. /package/{types → dist}/resources/DProductSubLine.d.ts +0 -0
  244. /package/{types → dist}/resources/FamilyDetails.d.ts +0 -0
  245. /package/{types → dist}/resources/ProductDetails.d.ts +0 -0
  246. /package/{types → dist}/resources/ProductRelation.d.ts +0 -0
  247. /package/{types → dist}/resources/cfFields.d.ts +0 -0
  248. /package/{types → dist}/types.d.ts +0 -0
  249. /package/{types → dist}/utils.d.ts +0 -0
@@ -1,364 +0,0 @@
1
- import { getRequest } from "./request";
2
- import { AvailableCatalogs } from "../types";
3
- import { CatalogDetails } from "../resources/CatalogDetails";
4
- import { Audit } from "../resources/Audit";
5
- import { CollectionModels } from "../resources/CollectionModels";
6
- import { CollectionSubModels } from "../resources/CollectionSubModels";
7
- import { CollectionSubFamilies } from "../resources/CollectionSubFamilies";
8
- import { FamilyDetails } from "../resources/FamilyDetails";
9
- import { secondBetweenTwoDate } from "../utils";
10
- import { log } from "../libs/logs";
11
- import { saveJsonToS3, getFileFromS3 } from "../libs/s3";
12
- import axios from "@atoms-studio/axios";
13
- import { ungzip } from "node-gzip";
14
- import { checkConfig, config } from "./config";
15
-
16
- type AvailableOtherCatalogDataEndpoint = "models" | "submodels" | "subfamilies";
17
-
18
- /**
19
- * Get pim domain by pim base url
20
- *
21
- * @returns
22
- */
23
- export const getPimDomain = () => {
24
- const pimBaseUrl = process.env.FPI_PIM_BASE_URL || "";
25
- return pimBaseUrl.substring(
26
- pimBaseUrl.indexOf("://") + 3,
27
- pimBaseUrl.indexOf("/.rest")
28
- );
29
- };
30
-
31
- /**
32
- * Get the catalog taxonomy hierarchy
33
- *
34
- * @returns
35
- */
36
- export const getCatalogTaxonomiesHierarchy = async (
37
- catalogCode: AvailableCatalogs,
38
- jsonFile?: null
39
- ) => {
40
- try {
41
- const timeStart = new Date();
42
-
43
- let data: CatalogDetails[];
44
- if (!jsonFile) {
45
- const res = await getRequest("catalogs", {
46
- params: { onlyweb: true, catalog: catalogCode },
47
- });
48
- data = res.data;
49
- } else {
50
- data = jsonFile;
51
- }
52
-
53
- const catalogData = data.find(
54
- (item: any) => item.data.code === catalogCode
55
- );
56
-
57
- const timeEnd = new Date();
58
- const seconds = secondBetweenTwoDate(timeStart, timeEnd);
59
- log(`Request time: ${seconds} seconds - endpoint: catalogs`);
60
-
61
- if (!catalogData) {
62
- throw new Error(`No catalog data found. Catalog code: ${catalogCode}`);
63
- }
64
-
65
- return catalogData;
66
- } catch (err: any) {
67
- throw new Error(err);
68
- }
69
- };
70
-
71
- /**
72
- * Get the dictionary
73
- *
74
- * @returns
75
- */
76
- export const getDictionary = async () => {
77
- try {
78
- const timeStart = new Date();
79
-
80
- const { data } = await getRequest("dictionary", {
81
- params: { onlyweb: true },
82
- });
83
-
84
- const timeEnd = new Date();
85
- const seconds = secondBetweenTwoDate(timeStart, timeEnd);
86
- log(`Request time: ${seconds} seconds - endpoint: dictionary`);
87
-
88
- return data;
89
- } catch (err: any) {
90
- throw new Error(err);
91
- }
92
- };
93
-
94
- /**
95
- * Get all products
96
- *
97
- * @param {string} lastModified [lastModified=""] - The last modified data. Format: 20200426T07:50:00 - yearmonthdayThour:minute:second
98
- * @param {string} catalogCode [catalogCode=""] - The catalog code. Format: ARCHITECTURAL
99
- * @returns
100
- */
101
- export const getAllProducts = async (
102
- lastModified: string | null = null,
103
- catalogCode: AvailableCatalogs | null = null
104
- ) => {
105
- try {
106
- const timeStart = new Date();
107
-
108
- const opts: any = {
109
- onlyweb: true,
110
- };
111
-
112
- if (lastModified) {
113
- opts.lastModified = lastModified;
114
- }
115
-
116
- if (catalogCode) {
117
- opts.catalogCode = catalogCode;
118
- }
119
-
120
- const { data } = await getRequest("products", {
121
- params: opts,
122
- });
123
-
124
- const timeEnd = new Date();
125
- const seconds = secondBetweenTwoDate(timeStart, timeEnd);
126
- log(`Request time: ${seconds} seconds - endpoint: products`);
127
-
128
- return data;
129
- } catch (err: any) {
130
- throw new Error(err);
131
- }
132
- };
133
-
134
- /**
135
- * Get latest products
136
- *
137
- * @param {string} lastModified The last modified data. Format: 20200426T07:50:00 - yearmonthdayThour:minute:second
138
- * @param {string} catalogCode The catalog code. Format: ARCHITECTURAL
139
- * @param {number} offset Default 0
140
- * @param {number} limit The maximum number of records to return. Default 100
141
- * @param {string} lastModifiedTo The last modified to data. Format: 20200426T07:50:00 - yearmonthdayThour:minute:second
142
- * @returns
143
- */
144
- export const getLatestProducts = async (
145
- catalogCode: AvailableCatalogs,
146
- lastModified: string,
147
- offset: number = 0,
148
- limit: number = 100,
149
- lastModifiedTo: string = ""
150
- ) => {
151
- try {
152
- const timeStart = new Date();
153
-
154
- const opts = {
155
- onlyweb: true,
156
- lastModified,
157
- catalog: catalogCode,
158
- offset: offset,
159
- limit: limit,
160
- lastModifiedTo,
161
- };
162
-
163
- const { data } = await getRequest("latest-products/full", {
164
- params: opts,
165
- });
166
-
167
- const timeEnd = new Date();
168
- const seconds = secondBetweenTwoDate(timeStart, timeEnd);
169
- log(`Request time: ${seconds} seconds - endpoint: latest-products/full`);
170
-
171
- return data;
172
- } catch (err: any) {
173
- throw new Error(err);
174
- }
175
- };
176
-
177
- /**
178
- * Get product details
179
- *
180
- * @param {string} code The product sku. Format: "06.5312.CZ"
181
- * @returns
182
- */
183
- export const getProductDetails = async (code: string) => {
184
- try {
185
- const timeStart = new Date();
186
-
187
- const { data } = await getRequest(`product/full/${code}`);
188
-
189
- const timeEnd = new Date();
190
- const seconds = secondBetweenTwoDate(timeStart, timeEnd);
191
- log(`Request time: ${seconds} seconds - endpoint: product/full/${code}`);
192
-
193
- return data;
194
- } catch (err: any) {
195
- throw new Error(err);
196
- }
197
- };
198
-
199
- /**
200
- * Get product details
201
- *
202
- * @param {string} lastModified The last modified data. Format: 20200426T07:50:00 - yearmonthdayThour:minute:second
203
- * @returns
204
- */
205
- export const getAudit = async (lastModified: string = ""): Promise<Audit[]> => {
206
- try {
207
- const timeStart = new Date();
208
-
209
- const opts: any = {};
210
-
211
- if (lastModified) {
212
- opts.fromDate = lastModified;
213
- }
214
-
215
- const { data } = await getRequest(`products/audit`, { params: opts });
216
-
217
- const timeEnd = new Date();
218
- const seconds = secondBetweenTwoDate(timeStart, timeEnd);
219
- log(`Request time: ${seconds} seconds - endpoint: products/audit`);
220
-
221
- return data;
222
- } catch (err: any) {
223
- throw new Error(err);
224
- }
225
- };
226
-
227
- /**
228
- * Get static daily products
229
- *
230
- * @param {string} catalogCode The catalog code. Format: ARCHITECTURAL
231
- * @param {string} day The last modified data. Format: 20200426 - yearmonthday
232
- * @param {boolean} saveToS3 If is true save tje JSON file to s3
233
- * @returns
234
- */
235
- export const getStaticDailyProducts = async (
236
- catalogCode: AvailableCatalogs,
237
- day: string,
238
- saveToS3: boolean = false
239
- ) => {
240
- try {
241
- const timeStart = new Date();
242
-
243
- const filename = `staticDaily-${catalogCode}.json`;
244
- const path = `staticDaily/${day}`;
245
- if (saveToS3) {
246
- log(`Check if already saved to S3`);
247
- const alreadyExists = await getFileFromS3(`${path}/${filename}`);
248
- if (alreadyExists) {
249
- log(`Daily update data already exists to ${path}/${filename}`);
250
- return `${path}/${filename}`;
251
- }
252
- }
253
-
254
- const opts = {
255
- day: day,
256
- catalog: catalogCode,
257
- };
258
- checkConfig();
259
-
260
- log(`Requesting daily update on ${config.baseURL}static-daily-products`);
261
- log(`Params: ${JSON.stringify(opts)}`);
262
- const { data } = await axios.get(`${config.baseURL}static-daily-products`, {
263
- params: opts,
264
- responseType: "arraybuffer",
265
- });
266
-
267
- const jsonFile = (await ungzip(data)).toString();
268
-
269
- if (!jsonFile) {
270
- log(`No updates found. Catalog: ${catalogCode} - Day: ${day}`);
271
- return false;
272
- }
273
-
274
- if (saveToS3) {
275
- const timeEndSub = new Date();
276
- const secondsSub = secondBetweenTwoDate(timeStart, timeEndSub);
277
- log(
278
- `Request time: ${secondsSub} seconds - endpoint: static-daily-products`
279
- );
280
-
281
- await saveJsonToS3(jsonFile, filename, path);
282
-
283
- log(`Founded ${JSON.parse(jsonFile).length} products`);
284
-
285
- return `${path}/${filename}`;
286
- }
287
-
288
- const timeEnd = new Date();
289
- const seconds = secondBetweenTwoDate(timeStart, timeEnd);
290
- log(`Request time: ${seconds} seconds - endpoint: static-daily-products`);
291
-
292
- return JSON.parse(jsonFile);
293
- } catch (err: any) {
294
- log(`No updates or wrong url. Catalog: ${catalogCode} - Day: ${day}`);
295
- return false;
296
- }
297
- };
298
-
299
- /**
300
- * Get other catalog data
301
- *
302
- * @example
303
- * const subModels = await getOtherCatalogData<CollectionSubModels>(
304
- * "submodels",
305
- * offset,
306
- * limit
307
- * );
308
- *
309
- * @param {string} endpoint The available values are: models or submodels or subfamilies
310
- * @param {number} offset Default 0
311
- * @param {number} limit Range 0-50. Default 50
312
- * @returns
313
- */
314
- type AvailableOtherCatalogCollection =
315
- | CollectionModels
316
- | CollectionSubModels
317
- | CollectionSubFamilies;
318
- export const getOtherCatalogData = async <
319
- T extends AvailableOtherCatalogCollection
320
- >(
321
- endpoint: AvailableOtherCatalogDataEndpoint,
322
- offset: number = 0,
323
- limit: number = 50
324
- ): Promise<T> => {
325
- try {
326
- const timeStart = new Date();
327
-
328
- const opts: any = {
329
- onlyweb: true,
330
- offset,
331
- limit,
332
- };
333
-
334
- const { data } = await getRequest(endpoint, { params: opts });
335
-
336
- const timeEnd = new Date();
337
- const seconds = secondBetweenTwoDate(timeStart, timeEnd);
338
- log(`Request time: ${seconds} seconds - endpoint: ${endpoint}`);
339
-
340
- return data;
341
- } catch (err: any) {
342
- throw new Error(err);
343
- }
344
- };
345
-
346
- export const getFamilies = async (): Promise<FamilyDetails[]> => {
347
- try {
348
- const timeStart = new Date();
349
-
350
- const opts: any = {
351
- onlyweb: true,
352
- };
353
-
354
- const { data } = await getRequest("families", { params: opts });
355
-
356
- const timeEnd = new Date();
357
- const seconds = secondBetweenTwoDate(timeStart, timeEnd);
358
- log(`Request time: ${seconds} seconds - endpoint: families`);
359
-
360
- return data;
361
- } catch (err: any) {
362
- throw new Error(err);
363
- }
364
- };
@@ -1,266 +0,0 @@
1
- import { AvailableCatalogs } from "../../types";
2
- import type { Entry } from "contentful-management/dist/typings/entities/entry";
3
- import {
4
- getEnvironmentDefaultLocaleCode,
5
- getEntryByID,
6
- getEnvironment,
7
- } from "../../libs/contentful";
8
- import { log, serverUtils } from "../../libs/logs";
9
- import { getProductPageIdByCode } from "./products";
10
- import { reindexProduct } from "../../algolia/products";
11
-
12
- const publishEntry = async (entryId: string, type: string) => {
13
- const entry = await getEntryByID(entryId, type);
14
- if (entry && entry.isDraft()) {
15
- log(`Publish entry ${entryId} with type ${type}`);
16
- await entry.publish();
17
- } else if (!entry) {
18
- log(`Entry not found ${entryId} with type ${type}`, "WARN");
19
- }
20
- };
21
-
22
- export const publishTopicProduct = async (productEntry: Entry) => {
23
- // const defEnvLocaleCode = await getEnvironmentDefaultLocaleCode();
24
-
25
- // page
26
- const pageId = getProductPageIdByCode(productEntry.sys.id);
27
- await publishEntry(pageId, "page");
28
-
29
- // // catalogs
30
- // if (productEntry?.fields?.catalogs?.[defEnvLocaleCode].length) {
31
- // for (const catalog of productEntry.fields.catalogs[defEnvLocaleCode]) {
32
- // await publishEntry(catalog.sys.id, "topicCatalog");
33
- // await publishEntry(`${catalog.sys.id}_PAGE`, "page");
34
- // }
35
- // }
36
-
37
- // // Thumbnail Imgix
38
- // if (productEntry?.fields?.thumbnailImgix?.[defEnvLocaleCode]) {
39
- // const thumbnailImgix =
40
- // productEntry?.fields?.thumbnailImgix?.[defEnvLocaleCode];
41
- // if (thumbnailImgix) {
42
- // await publishEntry(thumbnailImgix.sys.id, "wrapperImgix");
43
- // }
44
- // }
45
-
46
- // // Designers
47
- // if (productEntry?.fields?.designers?.[defEnvLocaleCode].length) {
48
- // for (const designer of productEntry.fields.designers[defEnvLocaleCode]) {
49
- // await publishEntry(designer.sys.id, "topicDesigner");
50
- // }
51
- // }
52
-
53
- // // categoriesArchitectural
54
- // if (
55
- // productEntry?.fields?.categoriesArchitectural?.[defEnvLocaleCode].length
56
- // ) {
57
- // for (const category of productEntry.fields.categoriesArchitectural[
58
- // defEnvLocaleCode
59
- // ]) {
60
- // await publishEntry(category.sys.id, "topicCategory");
61
- // await publishEntry(`${category.sys.id}_PAGE`, "page");
62
- // }
63
- // }
64
-
65
- // // categoriesOutdoor
66
- // if (productEntry?.fields?.categoriesOutdoor?.[defEnvLocaleCode].length) {
67
- // for (const category of productEntry.fields.categoriesOutdoor[
68
- // defEnvLocaleCode
69
- // ]) {
70
- // await publishEntry(category.sys.id, "topicCategory");
71
- // await publishEntry(`${category.sys.id}_PAGE`, "page");
72
- // }
73
- // }
74
-
75
- // // categoriesDecorative
76
- // if (productEntry?.fields?.categoriesDecorative?.[defEnvLocaleCode].length) {
77
- // for (const category of productEntry.fields.categoriesDecorative[
78
- // defEnvLocaleCode
79
- // ]) {
80
- // await publishEntry(category.sys.id, "topicCategory");
81
- // await publishEntry(`${category.sys.id}_PAGE`, "page");
82
- // }
83
- // }
84
-
85
- // // categoriesDecorative
86
- // if (productEntry?.fields?.families?.[defEnvLocaleCode].length) {
87
- // for (const family of productEntry.fields.families[defEnvLocaleCode]) {
88
- // await publishEntry(family.sys.id, "topicFamily");
89
- // await publishEntry(`${family.sys.id}_PAGE`, "page");
90
- // }
91
- // }
92
-
93
- // // subFamiliesArchitectural
94
- // if (
95
- // productEntry?.fields?.subFamiliesArchitectural?.[defEnvLocaleCode].length
96
- // ) {
97
- // for (const subFamily of productEntry.fields.subFamiliesArchitectural[
98
- // defEnvLocaleCode
99
- // ]) {
100
- // await publishEntry(subFamily.sys.id, "topicSubFamily");
101
- // await publishEntry(`${subFamily.sys.id}_PAGE`, "page");
102
- // }
103
- // }
104
-
105
- // // subFamiliesOutdoor
106
- // if (productEntry?.fields?.subFamiliesOutdoor?.[defEnvLocaleCode].length) {
107
- // for (const subFamily of productEntry.fields.subFamiliesOutdoor[
108
- // defEnvLocaleCode
109
- // ]) {
110
- // await publishEntry(subFamily.sys.id, "topicSubFamily");
111
- // await publishEntry(`${subFamily.sys.id}_PAGE`, "page");
112
- // }
113
- // }
114
-
115
- // // subFamiliesDecorative
116
- // if (productEntry?.fields?.subFamiliesDecorative?.[defEnvLocaleCode].length) {
117
- // for (const subFamily of productEntry.fields.subFamiliesDecorative[
118
- // defEnvLocaleCode
119
- // ]) {
120
- // await publishEntry(subFamily.sys.id, "topicSubFamily");
121
- // await publishEntry(`${subFamily.sys.id}_PAGE`, "page");
122
- // }
123
- // }
124
-
125
- // // modelsArchitectural
126
- // if (productEntry?.fields?.modelsArchitectural?.[defEnvLocaleCode].length) {
127
- // for (const model of productEntry.fields.modelsArchitectural[
128
- // defEnvLocaleCode
129
- // ]) {
130
- // await publishEntry(model.sys.id, "topicModel");
131
- // await publishEntry(`${model.sys.id}_PAGE`, "page");
132
- // }
133
- // }
134
-
135
- // // modelsOutdoor
136
- // if (productEntry?.fields?.modelsOutdoor?.[defEnvLocaleCode].length) {
137
- // for (const model of productEntry.fields.modelsOutdoor[defEnvLocaleCode]) {
138
- // await publishEntry(model.sys.id, "topicModel");
139
- // await publishEntry(`${model.sys.id}_PAGE`, "page");
140
- // }
141
- // }
142
-
143
- // // modelsDecorative
144
- // if (productEntry?.fields?.modelsDecorative?.[defEnvLocaleCode].length) {
145
- // for (const model of productEntry.fields.modelsDecorative[
146
- // defEnvLocaleCode
147
- // ]) {
148
- // await publishEntry(model.sys.id, "topicModel");
149
- // await publishEntry(`${model.sys.id}_PAGE`, "page");
150
- // }
151
- // }
152
-
153
- // // subModelsArchitectural
154
- // if (productEntry?.fields?.subModelsArchitectural?.[defEnvLocaleCode].length) {
155
- // for (const subModel of productEntry.fields.subModelsArchitectural[
156
- // defEnvLocaleCode
157
- // ]) {
158
- // await publishEntry(subModel.sys.id, "topicSubModel");
159
- // }
160
- // }
161
-
162
- // // subModelsOutdoor
163
- // if (productEntry?.fields?.subModelsOutdoor?.[defEnvLocaleCode].length) {
164
- // for (const subModel of productEntry.fields.subModelsOutdoor[
165
- // defEnvLocaleCode
166
- // ]) {
167
- // await publishEntry(subModel.sys.id, "topicSubModel");
168
- // }
169
- // }
170
-
171
- // // subModelsDecorative
172
- // if (productEntry?.fields?.subModelsDecorative?.[defEnvLocaleCode].length) {
173
- // for (const subModel of productEntry.fields.subModelsDecorative[
174
- // defEnvLocaleCode
175
- // ]) {
176
- // await publishEntry(subModel.sys.id, "topicSubModel");
177
- // }
178
- // }
179
-
180
- // // productLine
181
- // if (productEntry?.fields?.productLine?.[defEnvLocaleCode]) {
182
- // const productLine = productEntry?.fields?.productLine?.[defEnvLocaleCode];
183
- // await publishEntry(productLine.sys.id, "topicProductLine");
184
- // }
185
-
186
- // // productSubLine
187
- // if (productEntry?.fields?.productSubLine?.[defEnvLocaleCode]) {
188
- // const productSubLine =
189
- // productEntry?.fields?.productSubLine?.[defEnvLocaleCode];
190
- // await publishEntry(productSubLine.sys.id, "topicProductSubLine");
191
- // }
192
-
193
- // product
194
- await productEntry.publish();
195
- };
196
-
197
- export const publishAllProductDrafts = async (
198
- filters: { catalog?: AvailableCatalogs; family?: string },
199
- limit: number = 100
200
- ) => {
201
- let logMsg = `publishAllProductDrafts catalog: ${filters?.catalog} family: ${filters?.family} limit: ${limit}`;
202
- log(logMsg);
203
- if (serverUtils) {
204
- serverUtils.log(logMsg);
205
- }
206
- const env = await getEnvironment();
207
- const defEnvLocaleCode = await getEnvironmentDefaultLocaleCode();
208
-
209
- const opts: any = {
210
- content_type: "topicProduct",
211
- limit,
212
- skip: 0,
213
- locale: defEnvLocaleCode,
214
- "sys.archivedAt[exists]": false,
215
- "sys.publishedAt[exists]": false,
216
- changed: true,
217
- };
218
- if (filters?.catalog) {
219
- opts["fields.catalogs.sys.id"] = filters.catalog;
220
- }
221
- if (filters?.family) {
222
- opts["fields.families.sys.id"] = filters.family;
223
- }
224
- const { items, total } = await env.getEntries(opts);
225
-
226
- let count = 0;
227
- for (const item of items) {
228
- logMsg = `${++count} of ${limit} - total: ${total}`;
229
- log(logMsg);
230
- if (serverUtils) {
231
- serverUtils.log(logMsg);
232
- }
233
- if (["0000000-TEST"].includes(item.sys.id)) {
234
- logMsg = `Skip product test ${item.sys.id}`;
235
- } else {
236
- try {
237
- logMsg = `Publishing product: ${item.sys.id}`;
238
- if (serverUtils) {
239
- serverUtils.log(logMsg);
240
- }
241
- await publishTopicProduct(item);
242
- logMsg = `Reindex product: ${item.sys.id}`;
243
- if (serverUtils) {
244
- serverUtils.log(logMsg);
245
- }
246
- await reindexProduct(item.sys.id, true);
247
-
248
- if (serverUtils) {
249
- const progress = Math.floor((count / items.length) * 100);
250
- serverUtils.updateProgress(progress);
251
- }
252
- } catch (err: any) {
253
- logMsg = `Publish entry ${item.sys.id} failed`;
254
- if (serverUtils) {
255
- serverUtils.log(logMsg);
256
- }
257
- }
258
- }
259
- }
260
-
261
- const completed = Number(limit) >= total;
262
- return {
263
- completed,
264
- total,
265
- };
266
- };