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
package/src/libs/imgix.ts DELETED
@@ -1,297 +0,0 @@
1
- import ImgixAPI from "imgix-management-js";
2
- import { getPimDomain } from "../pim/endpoints";
3
- import { log } from "./logs";
4
- import { ImgixAttributes, RequiredImgixAttributes, ImgixData } from "../types";
5
- import {
6
- getEntryByID,
7
- getEnvironmentDefaultLocaleCode,
8
- } from "./contentful-cda";
9
- import axios from "@atoms-studio/axios";
10
- import https from "https";
11
- import mime from "mime-types";
12
- import { basename, getAllTranslations } from "../utils";
13
-
14
- let imgix: ImgixAPI;
15
- export const getImgix = () => {
16
- if (imgix) {
17
- return imgix;
18
- }
19
-
20
- imgix = new ImgixAPI({
21
- apiKey: process.env.FPI_IMGIX_API_KEY || "",
22
- });
23
-
24
- return imgix;
25
- };
26
-
27
- export const getSources = async () => {
28
- const imgix = getImgix();
29
- return await imgix.request("sources");
30
- };
31
-
32
- /**
33
- * Get origin path by pim url
34
- *
35
- * @example
36
- * from: https://dam.flos.net/damflos/products//ARCHITECTURAL/ARCHITECTURAL_SYSTEMS_LED-CURTAIN/03.3901.30C/FLOS-LED-CURTAIN-WHITE-1950X1950.JPG
37
- * to: damflos/products//ARCHITECTURAL/ARCHITECTURAL_SYSTEMS_LED-CURTAIN/03.3901.30C/FLOS-LED-CURTAIN-WHITE-1950X1950.JPG
38
- *
39
- * @param pimImgUrl
40
- * @returns
41
- */
42
- export const getOriginPathByPimUrl = (pimImgUrl: string) => {
43
- const pimDomain = getPimDomain();
44
- return pimImgUrl.substring(pimImgUrl.indexOf(pimDomain) + pimDomain.length);
45
- };
46
-
47
- /**
48
- * Get file name by pim url
49
- *
50
- * @example
51
- * from: https://dam.flos.net/damflos/products//ARCHITECTURAL/ARCHITECTURAL_SYSTEMS_LED-CURTAIN/03.3901.30C/FLOS-LED-CURTAIN-WHITE-1950X1950.JPG
52
- * to: FLOS-LED-CURTAIN-WHITE-1950X1950.JPG
53
- *
54
- * @param pimImgUrl
55
- * @returns
56
- */
57
- export const getNameByPimUrl = (pimImgUrl: string) => {
58
- return pimImgUrl.substring(pimImgUrl.lastIndexOf("/") + 1);
59
- };
60
-
61
- /**
62
- * Get content type by pim url
63
- *
64
- * @example
65
- * from: https://dam.flos.net/damflos/products//ARCHITECTURAL/ARCHITECTURAL_SYSTEMS_LED-CURTAIN/03.3901.30C/FLOS-LED-CURTAIN-WHITE-1950X1950.JPG
66
- * to: image/jpeg
67
- *
68
- * @param pimImgUrl
69
- * @returns
70
- */
71
- export const getContentTypeByPimUrl = (pimImgUrl: string) => {
72
- return mime.lookup(pimImgUrl) || "";
73
- };
74
-
75
- export const getImageAttributesByOriginPath = async (
76
- originPath: string,
77
- sourceId: string
78
- ) => {
79
- const url = `assets/${sourceId}${originPath}`;
80
- log(`getImageAttributesByOriginPath: ${url}`);
81
- try {
82
- const imgix = getImgix();
83
- const response = await imgix.request(url);
84
- const imgDetails: any = response;
85
- return imgDetails?.data?.attributes as ImgixAttributes;
86
- } catch (err: any) {
87
- console.log(err.response.errors);
88
- log(
89
- `${err.response.errors[0].detail} sourceId: ${sourceId} originPath: ${originPath}`,
90
- "WARN"
91
- );
92
- return {};
93
- }
94
- };
95
-
96
- export const getImageAttributesByPimUrl = async (
97
- pimUrl: string
98
- ): Promise<ImgixAttributes> => {
99
- const originPath = getOriginPathByPimUrl(pimUrl);
100
- const sourceId = process.env.FPI_IMGIX_PIM_SOURCE_ID || "";
101
-
102
- return (await getImageAttributesByOriginPath(
103
- originPath,
104
- sourceId
105
- )) as ImgixAttributes;
106
- };
107
-
108
- /**
109
- * Get imgix PIM URL by origin path
110
- *
111
- * @axample
112
- * from: /damflos/products//ARCHITECTURAL/ARCHITECTURAL_SYSTEMS_LED-CURTAIN/03.3901.30C/FLOS-LED-CURTAIN-WHITE-1950X1950.JPG
113
- * to: https://flos-pim.imgix.net/damflos/products//ARCHITECTURAL/ARCHITECTURAL_SYSTEMS_LED-CURTAIN/03.3901.30C/FLOS-LED-CURTAIN-WHITE-1950X1950.JPG
114
- *
115
- * @param originPath
116
- * @returns
117
- */
118
- export const getImgixPimUrlByOriginPath = (originPath: string) => {
119
- return `https://${process.env.FPI_IMGIX_PIM_IMAGE_DOMAIN}${originPath}`;
120
- };
121
-
122
- /**
123
- * Get imgix ASSET URL by origin path
124
- *
125
- * @param originPath
126
- * @returns
127
- */
128
- const getImgixAssetUrlByOriginPath = (originPath: string) => {
129
- return `https://${process.env.FPI_IMGIX_ASSET_IMAGE_DOMAIN}${originPath}`;
130
- };
131
-
132
- /**
133
- * get Imigix data from Imgix attributes
134
- *
135
- * @param imgAttributes
136
- * @returns
137
- */
138
- const getImgixDataFromImgixAttributes = (
139
- imgAttributes: RequiredImgixAttributes
140
- ) => {
141
- const imgixData: ImgixData = {
142
- url: getImgixPimUrlByOriginPath(imgAttributes.origin_path),
143
- details: {
144
- size: imgAttributes.file_size,
145
- image: {
146
- width: imgAttributes.media_width,
147
- height: imgAttributes.media_height,
148
- },
149
- },
150
- fileName: imgAttributes?.name || "",
151
- contentType: imgAttributes.content_type,
152
- };
153
- return imgixData;
154
- };
155
-
156
- /**
157
- * Get image attributes to set on wrapperImgix (PIM SOURCE)
158
- *
159
- * @param pimUrl
160
- * @returns
161
- */
162
- export const getWrapperImgixAttributesByPimUrl = async (pimUrl: string) => {
163
- const allImgAttributes = await getImageAttributesByPimUrl(pimUrl);
164
- let imgixData: ImgixData | null = null;
165
-
166
- if (Object.entries(allImgAttributes).length) {
167
- imgixData = getImgixDataFromImgixAttributes(allImgAttributes);
168
- }
169
-
170
- return imgixData;
171
- };
172
-
173
- /**
174
- * Get default image attributes to set on wrapperImgix (PIM SOURCE),
175
- * skipping the Imgix request
176
- *
177
- * @param pimUrl
178
- * @returns
179
- */
180
- export const getDefaultWrapperImgixAttributesByPimUrl = (pimUrl: string) => {
181
- const defaultImgAttributes: RequiredImgixAttributes = {
182
- origin_path: getOriginPathByPimUrl(pimUrl),
183
- file_size: 0,
184
- media_width: 1920,
185
- media_height: 1920,
186
- content_type: getContentTypeByPimUrl(pimUrl),
187
- // name: getNameByPimUrl(pimUrl),
188
- };
189
-
190
- const imgixData: ImgixData =
191
- getImgixDataFromImgixAttributes(defaultImgAttributes);
192
-
193
- return imgixData;
194
- };
195
-
196
- export const getWrapperImgixFields = async (wrapperImgixId: string) => {
197
- const wrapperImgix = await getEntryByID(wrapperImgixId, "wrapperImgix");
198
-
199
- if (!wrapperImgix) return {};
200
- const defaultEnvironmentLocaleCode = await getEnvironmentDefaultLocaleCode();
201
-
202
- const fields = {
203
- file: wrapperImgix?.fields?.imgixData?.[defaultEnvironmentLocaleCode] || {},
204
- focalPoint:
205
- wrapperImgix?.fields?.focalPoint?.[defaultEnvironmentLocaleCode]
206
- ?.focalPoint || {},
207
- altText: await getAllTranslations(wrapperImgix?.fields?.altText || {}),
208
- caption: await getAllTranslations(wrapperImgix?.fields?.caption || {}),
209
- hoverTitle: await getAllTranslations(
210
- wrapperImgix?.fields?.hoverTitle || {}
211
- ),
212
- forceHoverTitle:
213
- !!wrapperImgix?.fields?.forceHoverTitle?.[defaultEnvironmentLocaleCode],
214
- };
215
-
216
- return fields;
217
- };
218
-
219
- /**
220
- * Get image attributes to se on wrapperImgix (ASSET SOURCE)
221
- *
222
- * @param imgixAsset
223
- * @returns
224
- */
225
- export const getWrapperImgixAttributesByAsset = async (
226
- imgixAttributes: ImgixAttributes
227
- ): Promise<ImgixData> => {
228
- return {
229
- url: getImgixAssetUrlByOriginPath(imgixAttributes.origin_path),
230
- details: {
231
- size: imgixAttributes.file_size,
232
- image: {
233
- width: imgixAttributes.media_width,
234
- height: imgixAttributes.media_height,
235
- },
236
- },
237
- fileName: imgixAttributes?.name || "",
238
- contentType: imgixAttributes.content_type,
239
- };
240
- };
241
-
242
- export const uploadAssetByUrl = async (
243
- url: string
244
- ): Promise<ImgixData | undefined> => {
245
- log(`uploadAssetByUrl - ${url}`);
246
-
247
- const sourceId = process.env.FPI_IMGIX_ASSETS_SOURCE_ID || "";
248
- const fileName = basename(url);
249
- const originPath = `/${fileName}`;
250
- const imgix = getImgix();
251
-
252
- // Check if already exists
253
- const imageAttributes = (await getImageAttributesByOriginPath(
254
- originPath,
255
- sourceId
256
- )) as ImgixAttributes;
257
-
258
- if (Object.entries(imageAttributes).length) {
259
- return getWrapperImgixAttributesByAsset(imageAttributes);
260
- } else {
261
- try {
262
- log(`uploadAssetByUrl upload - ${url}`);
263
-
264
- // Upload new asset
265
- const agent = new https.Agent({
266
- rejectUnauthorized: false,
267
- });
268
- const fileRes = await axios.get(url, {
269
- httpsAgent: agent,
270
- responseType: "arraybuffer",
271
- });
272
- const requestUrl = `sources/upload/${sourceId}/${fileName}`;
273
- const response = (await imgix.request(requestUrl, {
274
- method: "POST",
275
- body: fileRes.data,
276
- })) as any;
277
- return getWrapperImgixAttributesByAsset(response?.data?.attributes);
278
- } catch (err: any) {
279
- console.log(err);
280
- return undefined;
281
- }
282
- }
283
- };
284
-
285
- export const purgeImageCacheByUrl = async (url: string) => {
286
- const imageUrl = url.replace(/([^:]\/)\/+/g, "$1");
287
-
288
- try {
289
- const imgix = getImgix();
290
- await imgix.request("purge", {
291
- method: "POST",
292
- body: { data: { attributes: { url: imageUrl }, type: "purges" } },
293
- });
294
- } catch (error: any) {
295
- log(`Error clearing cache for ${url}: ${error.message}`, "ERROR");
296
- }
297
- };
package/src/libs/logs.ts DELETED
@@ -1,121 +0,0 @@
1
- import winston from "winston";
2
- // @ts-ignore
3
- import { S3StreamLogger } from "s3-streamlogger";
4
-
5
- export type LogLevels =
6
- | "VERBOSE"
7
- | "DEBUG"
8
- | "INFO"
9
- | "WARN"
10
- | "ERROR"
11
- | "SILLY"
12
- | "HTTP";
13
- export const logStatus = true;
14
- let logId: string = "";
15
- let logPath: string = "";
16
- let logFilename: string = "";
17
- let Logger: any = null;
18
- export let serverUtils: any = null;
19
-
20
- export const setLogId = (id: string) => {
21
- if (logId !== id) {
22
- logId = id;
23
- }
24
- };
25
-
26
- export const setLogPath = (path: string) => {
27
- if (logPath !== path) {
28
- logPath = path;
29
-
30
- if (Logger) {
31
- Logger = getLogger();
32
- }
33
- }
34
- };
35
-
36
- export const setLogFilename = (filename: string) => {
37
- if (logFilename !== filename) {
38
- filename = filename.toString();
39
- if (!/[.]/.exec(filename)) {
40
- filename += ".log";
41
- }
42
- logFilename = filename;
43
-
44
- if (Logger) {
45
- Logger = getLogger();
46
- }
47
- }
48
- };
49
-
50
- export const setServerUtils = (utils: any) => {
51
- serverUtils = utils;
52
- };
53
-
54
- export const getLogFolder = () => {
55
- return logPath ? `logs/${logPath}/` : `logs/`;
56
- };
57
-
58
- export const getLogger = () => {
59
- const options = {
60
- bucket: process.env.FPI_AWS_S3_BUCKET,
61
- config: {
62
- credentials: {
63
- accessKeyId: process.env.FPI_AWS_ACCESS_KEY,
64
- secretAccessKey: process.env.FPI_AWS_SECRET_ACCESS_KEY,
65
- },
66
- region: process.env.FPI_AWS_REGION,
67
- tls: true,
68
- },
69
- folder: getLogFolder(),
70
- name_format: logFilename,
71
- };
72
-
73
- const s3_stream = new S3StreamLogger(options);
74
-
75
- const transport = new winston.transports.Stream({
76
- stream: s3_stream,
77
- });
78
-
79
- s3_stream.on("error", (err: any) => {
80
- console.log(err);
81
- });
82
-
83
- const logger = winston.createLogger({
84
- level: "info",
85
- format: winston.format.json(),
86
- transports: [transport],
87
- });
88
-
89
- Logger = logger;
90
-
91
- return logger;
92
- };
93
-
94
- export const log = (message: string, level: LogLevels = "INFO") => {
95
- if (!Logger) {
96
- // Logger = getLogger();
97
- }
98
- const winstonLevel: string = level.toLowerCase();
99
- message = logId ? `[${logId}] - ${message}` : message;
100
-
101
- if (level === "ERROR") {
102
- if (Logger) {
103
- Logger.log(winstonLevel, message);
104
- throw new Error(message);
105
- } else {
106
- throw new Error(message);
107
- }
108
- } else if (logStatus) {
109
- if (Logger) {
110
- console.log(`${level} - ${message}`);
111
- Logger.log(winstonLevel, message);
112
- } else {
113
- const date = new Date();
114
- const dateFormat =
115
- [date.getMonth() + 1, date.getDate(), date.getFullYear()].join("/") +
116
- " " +
117
- [date.getHours(), date.getMinutes(), date.getSeconds()].join(":");
118
- console.log(`[${dateFormat}] ${level} - ${message}`);
119
- }
120
- }
121
- };
@@ -1,37 +0,0 @@
1
- import dotenv from "dotenv";
2
- import axios from "@atoms-studio/axios";
3
- import { log, serverUtils } from "./logs";
4
- dotenv.config();
5
-
6
- export const netlifyBuild = async () => {
7
- let logMsg = `Triggering Netlify build...`;
8
- log(logMsg, "INFO");
9
- if (serverUtils) {
10
- serverUtils.log(logMsg);
11
- }
12
-
13
- if (!process.env.FPI_NETLIFY_BUILD_HOOK) {
14
- logMsg = `FPI_NETLIFY_BUILD_HOOK environment variable not found`;
15
- if (serverUtils) {
16
- serverUtils.log(logMsg);
17
- }
18
- log(logMsg, "ERROR");
19
- return;
20
- }
21
-
22
- const options = {
23
- method: "POST",
24
- url: process.env.FPI_NETLIFY_BUILD_HOOK,
25
- };
26
-
27
- try {
28
- await axios.request(options);
29
- logMsg = `Netlify build triggered`;
30
- log(logMsg, "INFO");
31
- if (serverUtils) {
32
- serverUtils.log(logMsg);
33
- }
34
- } catch (err: any) {
35
- console.log(err.message);
36
- }
37
- };
@@ -1,104 +0,0 @@
1
- import dotenv from "dotenv";
2
- import axios from "@atoms-studio/axios";
3
- import { format } from "date-fns";
4
- dotenv.config();
5
-
6
- /**
7
- * Send notifications to the Teams channel
8
- *
9
- * @param message
10
- * @param success
11
- * @returns
12
- */
13
- export const notify = async (message: string, success: boolean = true) => {
14
- if (!process.env.FPI_TEAMS_NOTIFICATIONS_URL) return;
15
-
16
- const status = success ? "Completed" : "Failed";
17
- const intro = `PIM IMPORT: ${status}`;
18
- const dateText = format(Date.now(), "dd/MM/yyyy HH:mm:ss");
19
-
20
- const options = {
21
- method: "POST",
22
- url: process.env.FPI_TEAMS_NOTIFICATIONS_URL,
23
- data: {
24
- type: "message",
25
- attachments: [
26
- {
27
- contentType: "application/vnd.microsoft.card.adaptive",
28
- contentUrl: null,
29
-
30
- content: {
31
- type: "AdaptiveCard",
32
- data: {
33
- finishedAt: "2017-02-14T06:08:39Z",
34
- duration: "5 minutes",
35
- },
36
- body: [
37
- {
38
- type: "ColumnSet",
39
- columns: [
40
- {
41
- type: "Column",
42
- items: [
43
- {
44
- type: "Image",
45
- url: success
46
- ? "https://api.iconify.design/emojione:white-heavy-check-mark.svg?color=currentColor"
47
- : "https://api.iconify.design/emojione:cross-mark-button.svg?color=currentColor",
48
- style: "person",
49
- width: "50px",
50
- height: "50px",
51
- },
52
- ],
53
- width: "auto",
54
- },
55
- {
56
- type: "Column",
57
- items: [
58
- {
59
- type: "TextBlock",
60
- weight: "bolder",
61
- text: intro,
62
- wrap: true,
63
- size: "medium",
64
- },
65
- {
66
- type: "TextBlock",
67
- spacing: "None",
68
- text: dateText,
69
- isSubtle: true,
70
- wrap: true,
71
- },
72
- ],
73
- width: "stretch",
74
- },
75
- ],
76
- },
77
- {
78
- type: "TextBlock",
79
- wrap: true,
80
- text: message,
81
- horizontalAlignment: "Left",
82
- },
83
- ],
84
- // actions: [
85
- // {
86
- // type: "Action.OpenUrl",
87
- // title: "View task",
88
- // url: `${process.env.AJ__APP_URL}/ui/queue/${row.task_id}#${job.id}`,
89
- // },
90
- // ],
91
- $schema: "http://adaptivecards.io/schemas/adaptive-card.json",
92
- version: "1.4",
93
- },
94
- },
95
- ],
96
- },
97
- };
98
-
99
- try {
100
- await axios.request(options);
101
- } catch (err: any) {
102
- console.log(err.message);
103
- }
104
- };
package/src/libs/pdf.ts DELETED
@@ -1,107 +0,0 @@
1
- import { secondBetweenTwoDate } from "../utils";
2
- import { log, serverUtils } from "./logs";
3
- import axios from "@atoms-studio/axios";
4
-
5
- interface HeaderColumns {
6
- left?: string;
7
- right?: string;
8
- }
9
- interface FooterColumns {
10
- topLeft?: string;
11
- topRight?: string;
12
- bottomLeft?: string;
13
- bottomRight?: string;
14
- mail?: string;
15
- }
16
-
17
- interface PDFHeaderAndFooter {
18
- header?: HeaderColumns;
19
- footer?: FooterColumns;
20
- }
21
-
22
- export const generatePDFByUrl = async (
23
- url: string,
24
- fileName: string = "",
25
- contents?: PDFHeaderAndFooter
26
- ) => {
27
- const pdf = await generatePDFByAWSLambda(url, fileName, contents);
28
-
29
- return pdf;
30
- };
31
-
32
- /**
33
- * Generate PDF by URL
34
- *
35
- * @param url E.g. https://my-site.com/slug
36
- * @param fileName E.g. my-file.pdf
37
- * @param contents E.g. {header{left:'Foo', right:'Bar'}, footer{left:'Foo', right:'Bar'}}
38
- * @returns
39
- */
40
- const generatePDFByAWSLambda = async (
41
- url: string,
42
- fileName: string = "",
43
- contents?: PDFHeaderAndFooter
44
- ) => {
45
- let logMsg = `generatePDFByUrl - url: ${url}`;
46
- log(logMsg, "DEBUG");
47
- if (serverUtils) {
48
- serverUtils.log(logMsg);
49
- }
50
-
51
- if (!process.env.FPID_AWS_GEN_PDF_LAMBDA_URL) {
52
- logMsg = `FPID_AWS_GEN_PDF_LAMBDA_URL environment variable not found`;
53
- if (serverUtils) {
54
- serverUtils.log(logMsg);
55
- }
56
- log(logMsg, "ERROR");
57
- return null;
58
- }
59
-
60
- const timeStart = new Date();
61
-
62
- logMsg = `Axios request...`;
63
- log(logMsg, "DEBUG");
64
- if (serverUtils) {
65
- serverUtils.log(logMsg);
66
- }
67
-
68
- const options: any = {
69
- method: "POST",
70
- url: process.env.FPID_AWS_GEN_PDF_LAMBDA_URL,
71
- data: {
72
- url,
73
- fileName,
74
- contents,
75
- },
76
- // timeout: 30000, // Aws Lambda limit
77
- };
78
- try {
79
- const response = await axios.request(options);
80
-
81
- logMsg = `End axios request - ${secondBetweenTwoDate(
82
- timeStart,
83
- new Date()
84
- )} seconds`;
85
- log(logMsg, "DEBUG");
86
- if (serverUtils) {
87
- serverUtils.log(logMsg);
88
- }
89
-
90
- return response.data;
91
- } catch (error: any) {
92
- console.log("ERROR");
93
- if (error.response) {
94
- // Request made and server responded
95
- console.log(error.response.data);
96
- console.log(error.response.status);
97
- console.log(error.response.headers);
98
- } else if (error.request) {
99
- // The request was made but no response was received
100
- console.log(error.request);
101
- } else {
102
- // Something happened in setting up the request that triggered an Error
103
- console.log("Error", error.message);
104
- }
105
- return false;
106
- }
107
- };