@rockcarver/frodo-cli 0.18.2-8 → 0.19.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.
Files changed (330) hide show
  1. package/CHANGELOG.md +119 -1
  2. package/esm/app.js +4 -1
  3. package/esm/app.js.map +1 -1
  4. package/esm/cli/FrodoCommand.js +133 -0
  5. package/esm/cli/FrodoCommand.js.map +1 -0
  6. package/esm/cli/_template/something-delete.js +9 -15
  7. package/esm/cli/_template/something-delete.js.map +1 -1
  8. package/esm/cli/_template/something-describe.js +9 -15
  9. package/esm/cli/_template/something-describe.js.map +1 -1
  10. package/esm/cli/_template/something-else-delete.js +9 -15
  11. package/esm/cli/_template/something-else-delete.js.map +1 -1
  12. package/esm/cli/_template/something-else-describe.js +9 -15
  13. package/esm/cli/_template/something-else-describe.js.map +1 -1
  14. package/esm/cli/_template/something-else-export.js +9 -15
  15. package/esm/cli/_template/something-else-export.js.map +1 -1
  16. package/esm/cli/_template/something-else-import.js +9 -15
  17. package/esm/cli/_template/something-else-import.js.map +1 -1
  18. package/esm/cli/_template/something-else-list.js +9 -15
  19. package/esm/cli/_template/something-else-list.js.map +1 -1
  20. package/esm/cli/_template/something-else.js +8 -8
  21. package/esm/cli/_template/something-else.js.map +1 -1
  22. package/esm/cli/_template/something-export.js +9 -15
  23. package/esm/cli/_template/something-export.js.map +1 -1
  24. package/esm/cli/_template/something-import.js +9 -15
  25. package/esm/cli/_template/something-import.js.map +1 -1
  26. package/esm/cli/_template/something-list.js +9 -15
  27. package/esm/cli/_template/something-list.js.map +1 -1
  28. package/esm/cli/_template/something-other-delete.js +9 -15
  29. package/esm/cli/_template/something-other-delete.js.map +1 -1
  30. package/esm/cli/_template/something-other-describe.js +9 -15
  31. package/esm/cli/_template/something-other-describe.js.map +1 -1
  32. package/esm/cli/_template/something-other-export.js +9 -15
  33. package/esm/cli/_template/something-other-export.js.map +1 -1
  34. package/esm/cli/_template/something-other-import.js +9 -15
  35. package/esm/cli/_template/something-other-import.js.map +1 -1
  36. package/esm/cli/_template/something-other-list.js +9 -15
  37. package/esm/cli/_template/something-other-list.js.map +1 -1
  38. package/esm/cli/_template/something-other.js +8 -8
  39. package/esm/cli/_template/something-other.js.map +1 -1
  40. package/esm/cli/_template/something.js +9 -10
  41. package/esm/cli/_template/something.js.map +1 -1
  42. package/esm/cli/admin/admin-add-autoid-static-user-mapping.js +8 -15
  43. package/esm/cli/admin/admin-add-autoid-static-user-mapping.js.map +1 -1
  44. package/esm/cli/admin/admin-create-oauth2-client-with-admin-privileges.js +9 -15
  45. package/esm/cli/admin/admin-create-oauth2-client-with-admin-privileges.js.map +1 -1
  46. package/esm/cli/admin/admin-get-access-token.js +9 -15
  47. package/esm/cli/admin/admin-get-access-token.js.map +1 -1
  48. package/esm/cli/admin/admin-grant-oauth2-client-admin-privileges.js +9 -15
  49. package/esm/cli/admin/admin-grant-oauth2-client-admin-privileges.js.map +1 -1
  50. package/esm/cli/admin/admin-hide-generic-extension-attributes.js +9 -15
  51. package/esm/cli/admin/admin-hide-generic-extension-attributes.js.map +1 -1
  52. package/esm/cli/admin/admin-list-oauth2-clients-with-admin-privileges.js +8 -15
  53. package/esm/cli/admin/admin-list-oauth2-clients-with-admin-privileges.js.map +1 -1
  54. package/esm/cli/admin/admin-list-oauth2-clients-with-custom-privileges.js +8 -15
  55. package/esm/cli/admin/admin-list-oauth2-clients-with-custom-privileges.js.map +1 -1
  56. package/esm/cli/admin/admin-list-static-user-mappings.js +9 -15
  57. package/esm/cli/admin/admin-list-static-user-mappings.js.map +1 -1
  58. package/esm/cli/admin/admin-remove-static-user-mapping.js +8 -15
  59. package/esm/cli/admin/admin-remove-static-user-mapping.js.map +1 -1
  60. package/esm/cli/admin/admin-repair-org-model.js +9 -15
  61. package/esm/cli/admin/admin-repair-org-model.js.map +1 -1
  62. package/esm/cli/admin/admin-revoke-oauth2-client-admin-privileges.js +9 -15
  63. package/esm/cli/admin/admin-revoke-oauth2-client-admin-privileges.js.map +1 -1
  64. package/esm/cli/admin/admin-show-generic-extension-attributes.js +9 -15
  65. package/esm/cli/admin/admin-show-generic-extension-attributes.js.map +1 -1
  66. package/esm/cli/admin/admin.js +14 -15
  67. package/esm/cli/admin/admin.js.map +1 -1
  68. package/esm/cli/agent/agent-delete.js +8 -15
  69. package/esm/cli/agent/agent-delete.js.map +1 -1
  70. package/esm/cli/agent/agent-describe.js +9 -15
  71. package/esm/cli/agent/agent-describe.js.map +1 -1
  72. package/esm/cli/agent/agent-export.js +8 -15
  73. package/esm/cli/agent/agent-export.js.map +1 -1
  74. package/esm/cli/agent/agent-gateway-delete.js +8 -15
  75. package/esm/cli/agent/agent-gateway-delete.js.map +1 -1
  76. package/esm/cli/agent/agent-gateway-describe.js +9 -15
  77. package/esm/cli/agent/agent-gateway-describe.js.map +1 -1
  78. package/esm/cli/agent/agent-gateway-export.js +8 -15
  79. package/esm/cli/agent/agent-gateway-export.js.map +1 -1
  80. package/esm/cli/agent/agent-gateway-import.js +8 -15
  81. package/esm/cli/agent/agent-gateway-import.js.map +1 -1
  82. package/esm/cli/agent/agent-gateway-list.js +9 -15
  83. package/esm/cli/agent/agent-gateway-list.js.map +1 -1
  84. package/esm/cli/agent/agent-gateway.js +8 -8
  85. package/esm/cli/agent/agent-gateway.js.map +1 -1
  86. package/esm/cli/agent/agent-import.js +8 -15
  87. package/esm/cli/agent/agent-import.js.map +1 -1
  88. package/esm/cli/agent/agent-java-delete.js +8 -15
  89. package/esm/cli/agent/agent-java-delete.js.map +1 -1
  90. package/esm/cli/agent/agent-java-describe.js +9 -15
  91. package/esm/cli/agent/agent-java-describe.js.map +1 -1
  92. package/esm/cli/agent/agent-java-export.js +8 -15
  93. package/esm/cli/agent/agent-java-export.js.map +1 -1
  94. package/esm/cli/agent/agent-java-import.js +8 -15
  95. package/esm/cli/agent/agent-java-import.js.map +1 -1
  96. package/esm/cli/agent/agent-java-list.js +9 -15
  97. package/esm/cli/agent/agent-java-list.js.map +1 -1
  98. package/esm/cli/agent/agent-java.js +8 -8
  99. package/esm/cli/agent/agent-java.js.map +1 -1
  100. package/esm/cli/agent/agent-list.js +9 -15
  101. package/esm/cli/agent/agent-list.js.map +1 -1
  102. package/esm/cli/agent/agent-web-delete.js +8 -15
  103. package/esm/cli/agent/agent-web-delete.js.map +1 -1
  104. package/esm/cli/agent/agent-web-describe.js +9 -15
  105. package/esm/cli/agent/agent-web-describe.js.map +1 -1
  106. package/esm/cli/agent/agent-web-export.js +8 -15
  107. package/esm/cli/agent/agent-web-export.js.map +1 -1
  108. package/esm/cli/agent/agent-web-import.js +8 -15
  109. package/esm/cli/agent/agent-web-import.js.map +1 -1
  110. package/esm/cli/agent/agent-web-list.js +9 -15
  111. package/esm/cli/agent/agent-web-list.js.map +1 -1
  112. package/esm/cli/agent/agent-web.js +8 -8
  113. package/esm/cli/agent/agent-web.js.map +1 -1
  114. package/esm/cli/agent/agent.js +10 -11
  115. package/esm/cli/agent/agent.js.map +1 -1
  116. package/esm/cli/app/app-delete.js +9 -12
  117. package/esm/cli/app/app-delete.js.map +1 -1
  118. package/esm/cli/app/app-describe.js +9 -12
  119. package/esm/cli/app/app-describe.js.map +1 -1
  120. package/esm/cli/app/app-export.js +28 -34
  121. package/esm/cli/app/app-export.js.map +1 -1
  122. package/esm/cli/app/app-import.js +11 -14
  123. package/esm/cli/app/app-import.js.map +1 -1
  124. package/esm/cli/app/app-list.js +11 -14
  125. package/esm/cli/app/app-list.js.map +1 -1
  126. package/esm/cli/app/app.js +8 -10
  127. package/esm/cli/app/app.js.map +1 -1
  128. package/esm/cli/conn/conn-delete.js +5 -5
  129. package/esm/cli/conn/conn-delete.js.map +1 -1
  130. package/esm/cli/conn/conn-describe.js +6 -5
  131. package/esm/cli/conn/conn-describe.js.map +1 -1
  132. package/esm/cli/conn/conn-list.js +6 -8
  133. package/esm/cli/conn/conn-list.js.map +1 -1
  134. package/esm/cli/conn/conn-save.js +72 -0
  135. package/esm/cli/conn/conn-save.js.map +1 -0
  136. package/esm/cli/conn/conn.js +10 -8
  137. package/esm/cli/conn/conn.js.map +1 -1
  138. package/esm/cli/email/email-template-export.js +29 -39
  139. package/esm/cli/email/email-template-export.js.map +1 -1
  140. package/esm/cli/email/email-template-import.js +34 -45
  141. package/esm/cli/email/email-template-import.js.map +1 -1
  142. package/esm/cli/email/email-template-list.js +12 -17
  143. package/esm/cli/email/email-template-list.js.map +1 -1
  144. package/esm/cli/email/email-template.js +6 -6
  145. package/esm/cli/email/email-template.js.map +1 -1
  146. package/esm/cli/email/email.js +2 -2
  147. package/esm/cli/email/email.js.map +1 -1
  148. package/esm/cli/esv/esv-apply.js +9 -12
  149. package/esm/cli/esv/esv-apply.js.map +1 -1
  150. package/esm/cli/esv/esv-secret-create.js +11 -14
  151. package/esm/cli/esv/esv-secret-create.js.map +1 -1
  152. package/esm/cli/esv/esv-secret-delete.js +23 -29
  153. package/esm/cli/esv/esv-secret-delete.js.map +1 -1
  154. package/esm/cli/esv/esv-secret-describe.js +11 -14
  155. package/esm/cli/esv/esv-secret-describe.js.map +1 -1
  156. package/esm/cli/esv/esv-secret-export.js +9 -12
  157. package/esm/cli/esv/esv-secret-export.js.map +1 -1
  158. package/esm/cli/esv/esv-secret-import.js +9 -12
  159. package/esm/cli/esv/esv-secret-import.js.map +1 -1
  160. package/esm/cli/esv/esv-secret-list.js +11 -14
  161. package/esm/cli/esv/esv-secret-list.js.map +1 -1
  162. package/esm/cli/esv/esv-secret-set.js +11 -14
  163. package/esm/cli/esv/esv-secret-set.js.map +1 -1
  164. package/esm/cli/esv/esv-secret-version-activate.js +18 -24
  165. package/esm/cli/esv/esv-secret-version-activate.js.map +1 -1
  166. package/esm/cli/esv/esv-secret-version-create.js +11 -14
  167. package/esm/cli/esv/esv-secret-version-create.js.map +1 -1
  168. package/esm/cli/esv/esv-secret-version-deactivate.js +18 -24
  169. package/esm/cli/esv/esv-secret-version-deactivate.js.map +1 -1
  170. package/esm/cli/esv/esv-secret-version-delete.js +23 -29
  171. package/esm/cli/esv/esv-secret-version-delete.js.map +1 -1
  172. package/esm/cli/esv/esv-secret-version-list.js +11 -14
  173. package/esm/cli/esv/esv-secret-version-list.js.map +1 -1
  174. package/esm/cli/esv/esv-secret-version.js +8 -8
  175. package/esm/cli/esv/esv-secret-version.js.map +1 -1
  176. package/esm/cli/esv/esv-secret.js +11 -11
  177. package/esm/cli/esv/esv-secret.js.map +1 -1
  178. package/esm/cli/esv/esv-variable-create.js +10 -14
  179. package/esm/cli/esv/esv-variable-create.js.map +1 -1
  180. package/esm/cli/esv/esv-variable-delete.js +23 -29
  181. package/esm/cli/esv/esv-variable-delete.js.map +1 -1
  182. package/esm/cli/esv/esv-variable-describe.js +11 -14
  183. package/esm/cli/esv/esv-variable-describe.js.map +1 -1
  184. package/esm/cli/esv/esv-variable-export.js +9 -12
  185. package/esm/cli/esv/esv-variable-export.js.map +1 -1
  186. package/esm/cli/esv/esv-variable-import.js +9 -12
  187. package/esm/cli/esv/esv-variable-import.js.map +1 -1
  188. package/esm/cli/esv/esv-variable-list.js +11 -14
  189. package/esm/cli/esv/esv-variable-list.js.map +1 -1
  190. package/esm/cli/esv/esv-variable-set.js +19 -26
  191. package/esm/cli/esv/esv-variable-set.js.map +1 -1
  192. package/esm/cli/esv/esv-variable.js +10 -10
  193. package/esm/cli/esv/esv-variable.js.map +1 -1
  194. package/esm/cli/esv/esv.js +5 -6
  195. package/esm/cli/esv/esv.js.map +1 -1
  196. package/esm/cli/idm/idm-count.js +12 -17
  197. package/esm/cli/idm/idm-count.js.map +1 -1
  198. package/esm/cli/idm/idm-export.js +29 -39
  199. package/esm/cli/idm/idm-export.js.map +1 -1
  200. package/esm/cli/idm/idm-import.js +29 -39
  201. package/esm/cli/idm/idm-import.js.map +1 -1
  202. package/esm/cli/idm/idm-list.js +11 -17
  203. package/esm/cli/idm/idm-list.js.map +1 -1
  204. package/esm/cli/idm/idm.js +6 -9
  205. package/esm/cli/idm/idm.js.map +1 -1
  206. package/esm/cli/idp/idp-export.js +11 -15
  207. package/esm/cli/idp/idp-export.js.map +1 -1
  208. package/esm/cli/idp/idp-import.js +32 -38
  209. package/esm/cli/idp/idp-import.js.map +1 -1
  210. package/esm/cli/idp/idp-list.js +9 -13
  211. package/esm/cli/idp/idp-list.js.map +1 -1
  212. package/esm/cli/idp/idp.js +5 -6
  213. package/esm/cli/idp/idp.js.map +1 -1
  214. package/esm/cli/info/info.js +19 -20
  215. package/esm/cli/info/info.js.map +1 -1
  216. package/esm/cli/journey/journey-delete.js +22 -28
  217. package/esm/cli/journey/journey-delete.js.map +1 -1
  218. package/esm/cli/journey/journey-describe.js +12 -19
  219. package/esm/cli/journey/journey-describe.js.map +1 -1
  220. package/esm/cli/journey/journey-disable.js +20 -26
  221. package/esm/cli/journey/journey-disable.js.map +1 -1
  222. package/esm/cli/journey/journey-enable.js +20 -26
  223. package/esm/cli/journey/journey-enable.js.map +1 -1
  224. package/esm/cli/journey/journey-export.js +37 -45
  225. package/esm/cli/journey/journey-export.js.map +1 -1
  226. package/esm/cli/journey/journey-import.js +44 -52
  227. package/esm/cli/journey/journey-import.js.map +1 -1
  228. package/esm/cli/journey/journey-list.js +10 -13
  229. package/esm/cli/journey/journey-list.js.map +1 -1
  230. package/esm/cli/journey/journey-prune.js +9 -13
  231. package/esm/cli/journey/journey-prune.js.map +1 -1
  232. package/esm/cli/journey/journey.js +10 -11
  233. package/esm/cli/journey/journey.js.map +1 -1
  234. package/esm/cli/logging/logs-fetch.js +17 -19
  235. package/esm/cli/logging/logs-fetch.js.map +1 -1
  236. package/esm/cli/logging/logs-list.js +19 -25
  237. package/esm/cli/logging/logs-list.js.map +1 -1
  238. package/esm/cli/logging/logs-tail.js +17 -19
  239. package/esm/cli/logging/logs-tail.js.map +1 -1
  240. package/esm/cli/logging/logs.js +7 -6
  241. package/esm/cli/logging/logs.js.map +1 -1
  242. package/esm/cli/realm/realm-add-custom-domain.js +11 -14
  243. package/esm/cli/realm/realm-add-custom-domain.js.map +1 -1
  244. package/esm/cli/realm/realm-describe.js +10 -14
  245. package/esm/cli/realm/realm-describe.js.map +1 -1
  246. package/esm/cli/realm/realm-list.js +11 -14
  247. package/esm/cli/realm/realm-list.js.map +1 -1
  248. package/esm/cli/realm/realm-remove-custom-domain.js +11 -14
  249. package/esm/cli/realm/realm-remove-custom-domain.js.map +1 -1
  250. package/esm/cli/realm/realm.js +7 -8
  251. package/esm/cli/realm/realm.js.map +1 -1
  252. package/esm/cli/saml/saml-cot-export.js +27 -36
  253. package/esm/cli/saml/saml-cot-export.js.map +1 -1
  254. package/esm/cli/saml/saml-cot-import.js +32 -41
  255. package/esm/cli/saml/saml-cot-import.js.map +1 -1
  256. package/esm/cli/saml/saml-cot-list.js +10 -16
  257. package/esm/cli/saml/saml-cot-list.js.map +1 -1
  258. package/esm/cli/saml/saml-cot.js +6 -6
  259. package/esm/cli/saml/saml-cot.js.map +1 -1
  260. package/esm/cli/saml/saml-delete.js +8 -15
  261. package/esm/cli/saml/saml-delete.js.map +1 -1
  262. package/esm/cli/saml/saml-describe.js +10 -16
  263. package/esm/cli/saml/saml-describe.js.map +1 -1
  264. package/esm/cli/saml/saml-export.js +9 -16
  265. package/esm/cli/saml/saml-export.js.map +1 -1
  266. package/esm/cli/saml/saml-import.js +45 -54
  267. package/esm/cli/saml/saml-import.js.map +1 -1
  268. package/esm/cli/saml/saml-list.js +11 -17
  269. package/esm/cli/saml/saml-list.js.map +1 -1
  270. package/esm/cli/saml/saml-metadata-export.js +21 -30
  271. package/esm/cli/saml/saml-metadata-export.js.map +1 -1
  272. package/esm/cli/saml/saml-metadata.js +4 -4
  273. package/esm/cli/saml/saml-metadata.js.map +1 -1
  274. package/esm/cli/saml/saml.js +9 -10
  275. package/esm/cli/saml/saml.js.map +1 -1
  276. package/esm/cli/script/script-delete.js +9 -12
  277. package/esm/cli/script/script-delete.js.map +1 -1
  278. package/esm/cli/script/script-describe.js +9 -12
  279. package/esm/cli/script/script-describe.js.map +1 -1
  280. package/esm/cli/script/script-export.js +28 -34
  281. package/esm/cli/script/script-export.js.map +1 -1
  282. package/esm/cli/script/script-import.js +10 -13
  283. package/esm/cli/script/script-import.js.map +1 -1
  284. package/esm/cli/script/script-list.js +10 -13
  285. package/esm/cli/script/script-list.js.map +1 -1
  286. package/esm/cli/script/script.js +7 -8
  287. package/esm/cli/script/script.js.map +1 -1
  288. package/esm/cli/service/service-delete.js +10 -16
  289. package/esm/cli/service/service-delete.js.map +1 -1
  290. package/esm/cli/service/service-export.js +12 -17
  291. package/esm/cli/service/service-export.js.map +1 -1
  292. package/esm/cli/service/service-import.js +12 -18
  293. package/esm/cli/service/service-import.js.map +1 -1
  294. package/esm/cli/service/service-list.js +9 -15
  295. package/esm/cli/service/service-list.js.map +1 -1
  296. package/esm/cli/service/service.js +6 -7
  297. package/esm/cli/service/service.js.map +1 -1
  298. package/esm/cli/theme/theme-delete.js +15 -26
  299. package/esm/cli/theme/theme-delete.js.map +1 -1
  300. package/esm/cli/theme/theme-export.js +14 -26
  301. package/esm/cli/theme/theme-export.js.map +1 -1
  302. package/esm/cli/theme/theme-import.js +16 -29
  303. package/esm/cli/theme/theme-import.js.map +1 -1
  304. package/esm/cli/theme/theme-list.js +12 -20
  305. package/esm/cli/theme/theme-list.js.map +1 -1
  306. package/esm/cli/theme/theme.js +6 -7
  307. package/esm/cli/theme/theme.js.map +1 -1
  308. package/esm/ops/ConnectionProfileOps.js +30 -0
  309. package/esm/ops/ConnectionProfileOps.js.map +1 -0
  310. package/esm/ops/EmailTemplateOps.js +267 -2
  311. package/esm/ops/EmailTemplateOps.js.map +1 -1
  312. package/esm/ops/IdmOps.js +317 -0
  313. package/esm/ops/IdmOps.js.map +1 -0
  314. package/esm/ops/JourneyOps.js +2 -1
  315. package/esm/ops/JourneyOps.js.map +1 -1
  316. package/esm/ops/ServiceOps.js +20 -20
  317. package/esm/ops/ServiceOps.js.map +1 -1
  318. package/esm/ops/ThemeOps.js +329 -0
  319. package/esm/ops/ThemeOps.js.map +1 -1
  320. package/esm/utils/Console.js +15 -25
  321. package/esm/utils/Console.js.map +1 -1
  322. package/esm/utils/ExportImportUtils.js +46 -0
  323. package/esm/utils/ExportImportUtils.js.map +1 -0
  324. package/package.json +6 -5
  325. package/esm/cli/cmd_common.js +0 -79
  326. package/esm/cli/cmd_common.js.map +0 -1
  327. package/esm/cli/conn/conn-add.js +0 -37
  328. package/esm/cli/conn/conn-add.js.map +0 -1
  329. package/esm/cli/journey/journey-delete.e2e.test_.js.map +0 -1
  330. package/esm/cli/journey/journey-list.e2e.test_.js.map +0 -1
@@ -1,4 +1,27 @@
1
- import { EmailTemplateRaw } from '@rockcarver/frodo-lib';
1
+ import fs from 'fs';
2
+ import { EmailTemplate, ExportImportUtils } from '@rockcarver/frodo-lib';
3
+ import { getTypedFilename, saveJsonToFile } from '../utils/ExportImportUtils';
4
+ import { createProgressIndicator, updateProgressIndicator, stopProgressIndicator, printMessage, createTable } from '../utils/Console';
5
+ import wordwrap from './utils/Wordwrap';
6
+ const EMAIL_TEMPLATE_FILE_TYPE = 'template.email';
7
+ const {
8
+ EMAIL_TEMPLATE_TYPE,
9
+ getEmailTemplate,
10
+ getEmailTemplates,
11
+ putEmailTemplate
12
+ } = EmailTemplate;
13
+ const {
14
+ validateImport
15
+ } = ExportImportUtils;
16
+ const regexEmailTemplateType = new RegExp(`${EMAIL_TEMPLATE_TYPE}/`, 'g');
17
+
18
+ // use a function vs a template variable to avoid problems in loops
19
+ function getFileDataTemplate() {
20
+ return {
21
+ meta: {},
22
+ emailTemplate: {}
23
+ };
24
+ }
2
25
 
3
26
  /**
4
27
  * Get a one-line description of the email template
@@ -27,9 +50,251 @@ export function getTableHeaderMd() {
27
50
  * @returns {string} a table-row of the email template in markdown
28
51
  */
29
52
  export function getTableRowMd(templateObj) {
30
- const templateId = templateObj._id.replace(`${EmailTemplateRaw.EMAIL_TEMPLATE_TYPE}/`, '');
53
+ const templateId = templateObj._id.replace(`${EMAIL_TEMPLATE_TYPE}/`, '');
31
54
  const locales = `${templateObj.defaultLocale}${Object.keys(templateObj.subject).length > 1 ? ` (${Object.keys(templateObj.subject).filter(locale => locale !== templateObj.defaultLocale).join(',')})` : ''}`;
32
55
  const row = `| ${templateObj.name ? templateObj.name : templateId} | ${locales} | ${templateObj.subject[templateObj.defaultLocale]} | \`${templateId}\` |`;
33
56
  return row;
34
57
  }
58
+
59
+ /**
60
+ * List email templates
61
+ * @param {boolean} long Long list format with details
62
+ * @return {Promise<unknown[]>} a promise that resolves to an array of email template objects
63
+ */
64
+ export async function listEmailTemplates(long = false) {
65
+ let emailTemplates = [];
66
+ try {
67
+ emailTemplates = (await getEmailTemplates()).result;
68
+ } catch (error) {
69
+ printMessage(`Error retrieving email templates: ${error.message}`, 'error');
70
+ }
71
+ emailTemplates.sort((a, b) => a._id.localeCompare(b._id));
72
+ if (!long) {
73
+ for (const [, emailTemplate] of emailTemplates.entries()) {
74
+ printMessage(`${emailTemplate._id.replace(`${EMAIL_TEMPLATE_TYPE}/`, '')}`, 'data');
75
+ }
76
+ } else {
77
+ const table = createTable(['Id'['brightCyan'], 'Name'['brightCyan'], 'Status'['brightCyan'], 'Locale(s)'['brightCyan'], 'From'['brightCyan'], 'Subject'['brightCyan']]);
78
+ for (const emailTemplate of emailTemplates) {
79
+ table.push([
80
+ // Id
81
+ `${emailTemplate._id.replace(`${EMAIL_TEMPLATE_TYPE}/`, '')}`,
82
+ // Name
83
+ `${emailTemplate.displayName ? emailTemplate.displayName : ''}`,
84
+ // Status
85
+ emailTemplate.enabled === false ? 'disabled'['brightRed'] : 'enabled'['brightGreen'],
86
+ // Locale(s)
87
+ `${emailTemplate.defaultLocale}${Object.keys(emailTemplate.subject).length > 1 ? ` (${Object.keys(emailTemplate.subject).filter(locale => locale !== emailTemplate.defaultLocale).join(',')})` : ''}`,
88
+ // From
89
+ `${emailTemplate.from ? emailTemplate.from : ''}`,
90
+ // Subject
91
+ wordwrap(emailTemplate.subject[emailTemplate.defaultLocale], 40)]);
92
+ }
93
+ printMessage(table.toString(), 'data');
94
+ }
95
+ return emailTemplates;
96
+ }
97
+
98
+ /**
99
+ * Export single email template to a file
100
+ * @param {string} templateId email template id to export
101
+ * @param {string} file filename where to export the template data
102
+ */
103
+ export async function exportEmailTemplateToFile(templateId, file) {
104
+ let fileName = file;
105
+ if (!fileName) {
106
+ fileName = getTypedFilename(templateId, EMAIL_TEMPLATE_FILE_TYPE);
107
+ }
108
+ createProgressIndicator('determinate', 1, `Exporting ${templateId}`);
109
+ try {
110
+ const templateData = await getEmailTemplate(templateId);
111
+ updateProgressIndicator(`Writing file ${fileName}`);
112
+ const fileData = getFileDataTemplate();
113
+ fileData.emailTemplate[templateId] = templateData;
114
+ saveJsonToFile(fileData, fileName);
115
+ stopProgressIndicator(`Exported ${templateId['brightCyan']} to ${fileName['brightCyan']}.`);
116
+ } catch (err) {
117
+ stopProgressIndicator(`${err}`);
118
+ printMessage(err, 'error');
119
+ }
120
+ }
121
+
122
+ /**
123
+ * Export all email templates to file
124
+ * @param {String} file optional filename
125
+ */
126
+ export async function exportEmailTemplatesToFile(file) {
127
+ let fileName = file;
128
+ if (!fileName) {
129
+ fileName = getTypedFilename(`allEmailTemplates`, EMAIL_TEMPLATE_FILE_TYPE);
130
+ }
131
+ try {
132
+ const fileData = getFileDataTemplate();
133
+ const response = await getEmailTemplates();
134
+ const templates = response.result;
135
+ createProgressIndicator('determinate', response.resultCount, 'Exporting email templates');
136
+ for (const template of templates) {
137
+ const templateId = template._id.replace(`${EMAIL_TEMPLATE_TYPE}/`, '');
138
+ updateProgressIndicator(`Exporting ${templateId}`);
139
+ fileData.emailTemplate[templateId] = template;
140
+ }
141
+ saveJsonToFile(fileData, fileName);
142
+ stopProgressIndicator(`${response.resultCount} templates exported to ${fileName}.`);
143
+ } catch (err) {
144
+ stopProgressIndicator(`${err}`);
145
+ printMessage(err, 'error');
146
+ }
147
+ }
148
+
149
+ /**
150
+ * Export all email templates to separate files
151
+ */
152
+ export async function exportEmailTemplatesToFiles() {
153
+ try {
154
+ const response = await getEmailTemplates();
155
+ const templates = response.result;
156
+ createProgressIndicator('determinate', response.resultCount, 'Exporting email templates');
157
+ for (const template of templates) {
158
+ const templateId = template._id.replace(`${EMAIL_TEMPLATE_TYPE}/`, '');
159
+ const fileName = getTypedFilename(templateId, EMAIL_TEMPLATE_FILE_TYPE);
160
+ const fileData = getFileDataTemplate();
161
+ updateProgressIndicator(`Exporting ${templateId}`);
162
+ fileData.emailTemplate[templateId] = template;
163
+ saveJsonToFile(fileData, fileName);
164
+ }
165
+ stopProgressIndicator(`${response.resultCount} templates exported.`);
166
+ } catch (err) {
167
+ stopProgressIndicator(`${err}`);
168
+ printMessage(err, 'error');
169
+ }
170
+ }
171
+
172
+ /**
173
+ * Import email template by id from file
174
+ * @param {String} templateId email template id
175
+ * @param {String} file optional filename
176
+ */
177
+ export async function importEmailTemplateFromFile(templateId, file) {
178
+ // eslint-disable-next-line no-param-reassign
179
+ templateId = templateId.replaceAll(`${EMAIL_TEMPLATE_TYPE}/`, '');
180
+ fs.readFile(file, 'utf8', async (err, data) => {
181
+ if (err) throw err;
182
+ const fileData = JSON.parse(data);
183
+ if (validateImport(fileData.meta)) {
184
+ createProgressIndicator('determinate', 1, `Importing ${templateId}`);
185
+ if (fileData.emailTemplate[templateId]) {
186
+ try {
187
+ await putEmailTemplate(templateId, fileData.emailTemplate[templateId]);
188
+ updateProgressIndicator(`Importing ${templateId}`);
189
+ stopProgressIndicator(`Imported ${templateId}`);
190
+ } catch (putEmailTemplateError) {
191
+ stopProgressIndicator(`${putEmailTemplateError}`);
192
+ printMessage(putEmailTemplateError, 'error');
193
+ }
194
+ } else {
195
+ stopProgressIndicator(`Email template ${templateId.brightCyan} not found in ${file.brightCyan}!`);
196
+ printMessage(`Email template ${templateId.brightCyan} not found in ${file.brightCyan}!`, 'error');
197
+ }
198
+ } else {
199
+ printMessage('Import validation failed...', 'error');
200
+ }
201
+ });
202
+ }
203
+
204
+ /**
205
+ * Import all email templates from file
206
+ * @param {String} file optional filename
207
+ */
208
+ export async function importEmailTemplatesFromFile(file) {
209
+ fs.readFile(file, 'utf8', async (err, data) => {
210
+ if (err) throw err;
211
+ const fileData = JSON.parse(data);
212
+ if (validateImport(fileData.meta)) {
213
+ createProgressIndicator('determinate', Object.keys(fileData.emailTemplate).length, `Importing email templates`);
214
+ for (const id in fileData.emailTemplate) {
215
+ if ({}.hasOwnProperty.call(fileData.emailTemplate, id)) {
216
+ const templateId = id.replace(regexEmailTemplateType, '');
217
+ try {
218
+ // eslint-disable-next-line no-await-in-loop
219
+ await putEmailTemplate(templateId, fileData.emailTemplate[templateId]);
220
+ updateProgressIndicator(`Imported ${templateId}`);
221
+ } catch (putEmailTemplateError) {
222
+ printMessage(`\nError importing ${templateId}`, 'error');
223
+ printMessage(putEmailTemplateError.response.data, 'error');
224
+ }
225
+ }
226
+ }
227
+ stopProgressIndicator(`Done.`);
228
+ } else {
229
+ printMessage('Import validation failed...', 'error');
230
+ }
231
+ });
232
+ }
233
+
234
+ /**
235
+ * Import all email templates from separate files
236
+ */
237
+ export async function importEmailTemplatesFromFiles() {
238
+ const names = fs.readdirSync('.');
239
+ const jsonFiles = names.filter(name => name.toLowerCase().endsWith(`${EMAIL_TEMPLATE_FILE_TYPE}.json`));
240
+ createProgressIndicator('determinate', jsonFiles.length, 'Importing email templates...');
241
+ let total = 0;
242
+ let totalErrors = 0;
243
+ for (const file of jsonFiles) {
244
+ const data = fs.readFileSync(file, 'utf8');
245
+ const fileData = JSON.parse(data);
246
+ if (validateImport(fileData.meta)) {
247
+ total += Object.keys(fileData.emailTemplate).length;
248
+ let errors = 0;
249
+ for (const id in fileData.emailTemplate) {
250
+ if ({}.hasOwnProperty.call(fileData.emailTemplate, id)) {
251
+ const templateId = id.replace(regexEmailTemplateType, '');
252
+ try {
253
+ // eslint-disable-next-line no-await-in-loop
254
+ await putEmailTemplate(templateId, fileData.emailTemplate[templateId]);
255
+ } catch (putEmailTemplateError) {
256
+ errors += 1;
257
+ printMessage(`\nError importing ${templateId}`, 'error');
258
+ printMessage(putEmailTemplateError.response.data, 'error');
259
+ }
260
+ }
261
+ }
262
+ totalErrors += errors;
263
+ updateProgressIndicator(`Imported ${file}`);
264
+ } else {
265
+ printMessage(`Validation of ${file} failed!`, 'error');
266
+ }
267
+ }
268
+ stopProgressIndicator(`Imported ${total - totalErrors} of ${total} email template(s) from ${jsonFiles.length} file(s).`);
269
+ }
270
+
271
+ /**
272
+ * Import first email template from file
273
+ * @param {String} file optional filename
274
+ */
275
+ export async function importFirstEmailTemplateFromFile(file) {
276
+ fs.readFile(file, 'utf8', async (err, data) => {
277
+ if (err) throw err;
278
+ const fileData = JSON.parse(data);
279
+ if (validateImport(fileData.meta)) {
280
+ createProgressIndicator('determinate', 1, `Importing first email template`);
281
+ for (const id in fileData.emailTemplate) {
282
+ if ({}.hasOwnProperty.call(fileData.emailTemplate, id)) {
283
+ try {
284
+ await putEmailTemplate(id.replace(regexEmailTemplateType, ''), fileData.emailTemplate[id]);
285
+ updateProgressIndicator(`Imported ${id}`);
286
+ stopProgressIndicator(`Imported ${id}`);
287
+ } catch (putEmailTemplateError) {
288
+ stopProgressIndicator(`Error importing email template ${id}`);
289
+ printMessage(`\nError importing email template ${id}`, 'error');
290
+ printMessage(putEmailTemplateError.response.data, 'error');
291
+ }
292
+ break;
293
+ }
294
+ }
295
+ } else {
296
+ printMessage('Import validation failed...', 'error');
297
+ }
298
+ });
299
+ }
35
300
  //# sourceMappingURL=EmailTemplateOps.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"EmailTemplateOps.js","names":["EmailTemplateRaw","getOneLineDescription","templateObj","description","_id","split","displayName","defaultLocale","subject","Object","values","getTableHeaderMd","markdown","getTableRowMd","templateId","replace","EMAIL_TEMPLATE_TYPE","locales","keys","length","filter","locale","join","row","name"],"sources":["ops/EmailTemplateOps.ts"],"sourcesContent":["import { EmailTemplateSkeleton } from '@rockcarver/frodo-lib/types/api/ApiTypes';\nimport { EmailTemplateRaw } from '@rockcarver/frodo-lib';\n\n/**\n * Get a one-line description of the email template\n * @param {EmailTemplateSkeleton} templateObj email template object to describe\n * @returns {string} a one-line description\n */\nexport function getOneLineDescription(\n templateObj: EmailTemplateSkeleton\n): string {\n const description = `[${templateObj._id.split('/')[1]['brightCyan']}] ${\n templateObj.displayName ? templateObj.displayName : ''\n } - ${\n templateObj.defaultLocale\n ? templateObj.subject[templateObj.defaultLocale]\n : Object.values(templateObj.subject)[0]\n }`;\n return description;\n}\n\n/**\n * Get markdown table header\n * @returns {string} markdown table header\n */\nexport function getTableHeaderMd(): string {\n let markdown = '';\n markdown += '| Display Name | Locale(s) | Subject | Id |\\n';\n markdown += '| ------------ | --------- | ------- | ---|';\n return markdown;\n}\n\n/**\n * Get a table-row of the email template in markdown\n * @param {EmailTemplateSkeleton} templateObj email template object to describe\n * @returns {string} a table-row of the email template in markdown\n */\nexport function getTableRowMd(templateObj: EmailTemplateSkeleton): string {\n const templateId = templateObj._id.replace(\n `${EmailTemplateRaw.EMAIL_TEMPLATE_TYPE}/`,\n ''\n );\n const locales = `${templateObj.defaultLocale}${\n Object.keys(templateObj.subject).length > 1\n ? ` (${Object.keys(templateObj.subject)\n .filter((locale) => locale !== templateObj.defaultLocale)\n .join(',')})`\n : ''\n }`;\n const row = `| ${\n templateObj.name ? templateObj.name : templateId\n } | ${locales} | ${\n templateObj.subject[templateObj.defaultLocale]\n } | \\`${templateId}\\` |`;\n return row;\n}\n"],"mappings":"AACA,SAASA,gBAAgB,QAAQ,uBAAuB;;AAExD;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,qBAAqB,CACnCC,WAAkC,EAC1B;EACR,MAAMC,WAAW,GAAI,IAAGD,WAAW,CAACE,GAAG,CAACC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,YAAY,CAAE,KAClEH,WAAW,CAACI,WAAW,GAAGJ,WAAW,CAACI,WAAW,GAAG,EACrD,MACCJ,WAAW,CAACK,aAAa,GACrBL,WAAW,CAACM,OAAO,CAACN,WAAW,CAACK,aAAa,CAAC,GAC9CE,MAAM,CAACC,MAAM,CAACR,WAAW,CAACM,OAAO,CAAC,CAAC,CAAC,CACzC,EAAC;EACF,OAAOL,WAAW;AACpB;;AAEA;AACA;AACA;AACA;AACA,OAAO,SAASQ,gBAAgB,GAAW;EACzC,IAAIC,QAAQ,GAAG,EAAE;EACjBA,QAAQ,IAAI,+CAA+C;EAC3DA,QAAQ,IAAI,6CAA6C;EACzD,OAAOA,QAAQ;AACjB;;AAEA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,aAAa,CAACX,WAAkC,EAAU;EACxE,MAAMY,UAAU,GAAGZ,WAAW,CAACE,GAAG,CAACW,OAAO,CACvC,GAAEf,gBAAgB,CAACgB,mBAAoB,GAAE,EAC1C,EAAE,CACH;EACD,MAAMC,OAAO,GAAI,GAAEf,WAAW,CAACK,aAAc,GAC3CE,MAAM,CAACS,IAAI,CAAChB,WAAW,CAACM,OAAO,CAAC,CAACW,MAAM,GAAG,CAAC,GACtC,KAAIV,MAAM,CAACS,IAAI,CAAChB,WAAW,CAACM,OAAO,CAAC,CAClCY,MAAM,CAAEC,MAAM,IAAKA,MAAM,KAAKnB,WAAW,CAACK,aAAa,CAAC,CACxDe,IAAI,CAAC,GAAG,CAAE,GAAE,GACf,EACL,EAAC;EACF,MAAMC,GAAG,GAAI,KACXrB,WAAW,CAACsB,IAAI,GAAGtB,WAAW,CAACsB,IAAI,GAAGV,UACvC,MAAKG,OAAQ,MACZf,WAAW,CAACM,OAAO,CAACN,WAAW,CAACK,aAAa,CAC9C,QAAOO,UAAW,MAAK;EACxB,OAAOS,GAAG;AACZ"}
1
+ {"version":3,"file":"EmailTemplateOps.js","names":["fs","EmailTemplate","ExportImportUtils","getTypedFilename","saveJsonToFile","createProgressIndicator","updateProgressIndicator","stopProgressIndicator","printMessage","createTable","wordwrap","EMAIL_TEMPLATE_FILE_TYPE","EMAIL_TEMPLATE_TYPE","getEmailTemplate","getEmailTemplates","putEmailTemplate","validateImport","regexEmailTemplateType","RegExp","getFileDataTemplate","meta","emailTemplate","getOneLineDescription","templateObj","description","_id","split","displayName","defaultLocale","subject","Object","values","getTableHeaderMd","markdown","getTableRowMd","templateId","replace","locales","keys","length","filter","locale","join","row","name","listEmailTemplates","long","emailTemplates","result","error","message","sort","a","b","localeCompare","entries","table","push","enabled","from","toString","exportEmailTemplateToFile","file","fileName","templateData","fileData","err","exportEmailTemplatesToFile","response","templates","resultCount","template","exportEmailTemplatesToFiles","importEmailTemplateFromFile","replaceAll","readFile","data","JSON","parse","putEmailTemplateError","brightCyan","importEmailTemplatesFromFile","id","hasOwnProperty","call","importEmailTemplatesFromFiles","names","readdirSync","jsonFiles","toLowerCase","endsWith","total","totalErrors","readFileSync","errors","importFirstEmailTemplateFromFile"],"sources":["ops/EmailTemplateOps.ts"],"sourcesContent":["import fs from 'fs';\nimport { EmailTemplateSkeleton } from '@rockcarver/frodo-lib/types/api/ApiTypes';\nimport { EmailTemplate, ExportImportUtils } from '@rockcarver/frodo-lib';\nimport { getTypedFilename, saveJsonToFile } from '../utils/ExportImportUtils';\nimport {\n createProgressIndicator,\n updateProgressIndicator,\n stopProgressIndicator,\n printMessage,\n createTable,\n} from '../utils/Console';\nimport wordwrap from './utils/Wordwrap';\n\nconst EMAIL_TEMPLATE_FILE_TYPE = 'template.email';\nconst {\n EMAIL_TEMPLATE_TYPE,\n getEmailTemplate,\n getEmailTemplates,\n putEmailTemplate,\n} = EmailTemplate;\nconst { validateImport } = ExportImportUtils;\n\nconst regexEmailTemplateType = new RegExp(`${EMAIL_TEMPLATE_TYPE}/`, 'g');\n\n// use a function vs a template variable to avoid problems in loops\nfunction getFileDataTemplate() {\n return {\n meta: {},\n emailTemplate: {},\n };\n}\n\n/**\n * Get a one-line description of the email template\n * @param {EmailTemplateSkeleton} templateObj email template object to describe\n * @returns {string} a one-line description\n */\nexport function getOneLineDescription(\n templateObj: EmailTemplateSkeleton\n): string {\n const description = `[${templateObj._id.split('/')[1]['brightCyan']}] ${\n templateObj.displayName ? templateObj.displayName : ''\n } - ${\n templateObj.defaultLocale\n ? templateObj.subject[templateObj.defaultLocale]\n : Object.values(templateObj.subject)[0]\n }`;\n return description;\n}\n\n/**\n * Get markdown table header\n * @returns {string} markdown table header\n */\nexport function getTableHeaderMd(): string {\n let markdown = '';\n markdown += '| Display Name | Locale(s) | Subject | Id |\\n';\n markdown += '| ------------ | --------- | ------- | ---|';\n return markdown;\n}\n\n/**\n * Get a table-row of the email template in markdown\n * @param {EmailTemplateSkeleton} templateObj email template object to describe\n * @returns {string} a table-row of the email template in markdown\n */\nexport function getTableRowMd(templateObj: EmailTemplateSkeleton): string {\n const templateId = templateObj._id.replace(`${EMAIL_TEMPLATE_TYPE}/`, '');\n const locales = `${templateObj.defaultLocale}${\n Object.keys(templateObj.subject).length > 1\n ? ` (${Object.keys(templateObj.subject)\n .filter((locale) => locale !== templateObj.defaultLocale)\n .join(',')})`\n : ''\n }`;\n const row = `| ${\n templateObj.name ? templateObj.name : templateId\n } | ${locales} | ${\n templateObj.subject[templateObj.defaultLocale]\n } | \\`${templateId}\\` |`;\n return row;\n}\n\n/**\n * List email templates\n * @param {boolean} long Long list format with details\n * @return {Promise<unknown[]>} a promise that resolves to an array of email template objects\n */\nexport async function listEmailTemplates(long = false): Promise<unknown[]> {\n let emailTemplates = [];\n try {\n emailTemplates = (await getEmailTemplates()).result;\n } catch (error) {\n printMessage(`Error retrieving email templates: ${error.message}`, 'error');\n }\n emailTemplates.sort((a, b) => a._id.localeCompare(b._id));\n if (!long) {\n for (const [, emailTemplate] of emailTemplates.entries()) {\n printMessage(\n `${emailTemplate._id.replace(`${EMAIL_TEMPLATE_TYPE}/`, '')}`,\n 'data'\n );\n }\n } else {\n const table = createTable([\n 'Id'['brightCyan'],\n 'Name'['brightCyan'],\n 'Status'['brightCyan'],\n 'Locale(s)'['brightCyan'],\n 'From'['brightCyan'],\n 'Subject'['brightCyan'],\n ]);\n for (const emailTemplate of emailTemplates) {\n table.push([\n // Id\n `${emailTemplate._id.replace(`${EMAIL_TEMPLATE_TYPE}/`, '')}`,\n // Name\n `${emailTemplate.displayName ? emailTemplate.displayName : ''}`,\n // Status\n emailTemplate.enabled === false\n ? 'disabled'['brightRed']\n : 'enabled'['brightGreen'],\n // Locale(s)\n `${emailTemplate.defaultLocale}${\n Object.keys(emailTemplate.subject).length > 1\n ? ` (${Object.keys(emailTemplate.subject)\n .filter((locale) => locale !== emailTemplate.defaultLocale)\n .join(',')})`\n : ''\n }`,\n // From\n `${emailTemplate.from ? emailTemplate.from : ''}`,\n // Subject\n wordwrap(emailTemplate.subject[emailTemplate.defaultLocale], 40),\n ]);\n }\n printMessage(table.toString(), 'data');\n }\n return emailTemplates;\n}\n\n/**\n * Export single email template to a file\n * @param {string} templateId email template id to export\n * @param {string} file filename where to export the template data\n */\nexport async function exportEmailTemplateToFile(\n templateId: string,\n file: string\n) {\n let fileName = file;\n if (!fileName) {\n fileName = getTypedFilename(templateId, EMAIL_TEMPLATE_FILE_TYPE);\n }\n createProgressIndicator('determinate', 1, `Exporting ${templateId}`);\n try {\n const templateData = await getEmailTemplate(templateId);\n updateProgressIndicator(`Writing file ${fileName}`);\n const fileData = getFileDataTemplate();\n fileData.emailTemplate[templateId] = templateData;\n saveJsonToFile(fileData, fileName);\n stopProgressIndicator(\n `Exported ${templateId['brightCyan']} to ${fileName['brightCyan']}.`\n );\n } catch (err) {\n stopProgressIndicator(`${err}`);\n printMessage(err, 'error');\n }\n}\n\n/**\n * Export all email templates to file\n * @param {String} file optional filename\n */\nexport async function exportEmailTemplatesToFile(file) {\n let fileName = file;\n if (!fileName) {\n fileName = getTypedFilename(`allEmailTemplates`, EMAIL_TEMPLATE_FILE_TYPE);\n }\n try {\n const fileData = getFileDataTemplate();\n const response = await getEmailTemplates();\n const templates = response.result;\n createProgressIndicator(\n 'determinate',\n response.resultCount,\n 'Exporting email templates'\n );\n for (const template of templates) {\n const templateId = template._id.replace(`${EMAIL_TEMPLATE_TYPE}/`, '');\n updateProgressIndicator(`Exporting ${templateId}`);\n fileData.emailTemplate[templateId] = template;\n }\n saveJsonToFile(fileData, fileName);\n stopProgressIndicator(\n `${response.resultCount} templates exported to ${fileName}.`\n );\n } catch (err) {\n stopProgressIndicator(`${err}`);\n printMessage(err, 'error');\n }\n}\n\n/**\n * Export all email templates to separate files\n */\nexport async function exportEmailTemplatesToFiles() {\n try {\n const response = await getEmailTemplates();\n const templates = response.result;\n createProgressIndicator(\n 'determinate',\n response.resultCount,\n 'Exporting email templates'\n );\n for (const template of templates) {\n const templateId = template._id.replace(`${EMAIL_TEMPLATE_TYPE}/`, '');\n const fileName = getTypedFilename(templateId, EMAIL_TEMPLATE_FILE_TYPE);\n const fileData = getFileDataTemplate();\n updateProgressIndicator(`Exporting ${templateId}`);\n fileData.emailTemplate[templateId] = template;\n saveJsonToFile(fileData, fileName);\n }\n stopProgressIndicator(`${response.resultCount} templates exported.`);\n } catch (err) {\n stopProgressIndicator(`${err}`);\n printMessage(err, 'error');\n }\n}\n\n/**\n * Import email template by id from file\n * @param {String} templateId email template id\n * @param {String} file optional filename\n */\nexport async function importEmailTemplateFromFile(templateId, file) {\n // eslint-disable-next-line no-param-reassign\n templateId = templateId.replaceAll(`${EMAIL_TEMPLATE_TYPE}/`, '');\n fs.readFile(file, 'utf8', async (err, data) => {\n if (err) throw err;\n const fileData = JSON.parse(data);\n if (validateImport(fileData.meta)) {\n createProgressIndicator('determinate', 1, `Importing ${templateId}`);\n if (fileData.emailTemplate[templateId]) {\n try {\n await putEmailTemplate(\n templateId,\n fileData.emailTemplate[templateId]\n );\n updateProgressIndicator(`Importing ${templateId}`);\n stopProgressIndicator(`Imported ${templateId}`);\n } catch (putEmailTemplateError) {\n stopProgressIndicator(`${putEmailTemplateError}`);\n printMessage(putEmailTemplateError, 'error');\n }\n } else {\n stopProgressIndicator(\n `Email template ${templateId.brightCyan} not found in ${file.brightCyan}!`\n );\n printMessage(\n `Email template ${templateId.brightCyan} not found in ${file.brightCyan}!`,\n 'error'\n );\n }\n } else {\n printMessage('Import validation failed...', 'error');\n }\n });\n}\n\n/**\n * Import all email templates from file\n * @param {String} file optional filename\n */\nexport async function importEmailTemplatesFromFile(file) {\n fs.readFile(file, 'utf8', async (err, data) => {\n if (err) throw err;\n const fileData = JSON.parse(data);\n if (validateImport(fileData.meta)) {\n createProgressIndicator(\n 'determinate',\n Object.keys(fileData.emailTemplate).length,\n `Importing email templates`\n );\n for (const id in fileData.emailTemplate) {\n if ({}.hasOwnProperty.call(fileData.emailTemplate, id)) {\n const templateId = id.replace(regexEmailTemplateType, '');\n try {\n // eslint-disable-next-line no-await-in-loop\n await putEmailTemplate(\n templateId,\n fileData.emailTemplate[templateId]\n );\n updateProgressIndicator(`Imported ${templateId}`);\n } catch (putEmailTemplateError) {\n printMessage(`\\nError importing ${templateId}`, 'error');\n printMessage(putEmailTemplateError.response.data, 'error');\n }\n }\n }\n stopProgressIndicator(`Done.`);\n } else {\n printMessage('Import validation failed...', 'error');\n }\n });\n}\n\n/**\n * Import all email templates from separate files\n */\nexport async function importEmailTemplatesFromFiles() {\n const names = fs.readdirSync('.');\n const jsonFiles = names.filter((name) =>\n name.toLowerCase().endsWith(`${EMAIL_TEMPLATE_FILE_TYPE}.json`)\n );\n createProgressIndicator(\n 'determinate',\n jsonFiles.length,\n 'Importing email templates...'\n );\n let total = 0;\n let totalErrors = 0;\n for (const file of jsonFiles) {\n const data = fs.readFileSync(file, 'utf8');\n const fileData = JSON.parse(data);\n if (validateImport(fileData.meta)) {\n total += Object.keys(fileData.emailTemplate).length;\n let errors = 0;\n for (const id in fileData.emailTemplate) {\n if ({}.hasOwnProperty.call(fileData.emailTemplate, id)) {\n const templateId = id.replace(regexEmailTemplateType, '');\n try {\n // eslint-disable-next-line no-await-in-loop\n await putEmailTemplate(\n templateId,\n fileData.emailTemplate[templateId]\n );\n } catch (putEmailTemplateError) {\n errors += 1;\n printMessage(`\\nError importing ${templateId}`, 'error');\n printMessage(putEmailTemplateError.response.data, 'error');\n }\n }\n }\n totalErrors += errors;\n updateProgressIndicator(`Imported ${file}`);\n } else {\n printMessage(`Validation of ${file} failed!`, 'error');\n }\n }\n stopProgressIndicator(\n `Imported ${total - totalErrors} of ${total} email template(s) from ${\n jsonFiles.length\n } file(s).`\n );\n}\n\n/**\n * Import first email template from file\n * @param {String} file optional filename\n */\nexport async function importFirstEmailTemplateFromFile(file) {\n fs.readFile(file, 'utf8', async (err, data) => {\n if (err) throw err;\n const fileData = JSON.parse(data);\n if (validateImport(fileData.meta)) {\n createProgressIndicator(\n 'determinate',\n 1,\n `Importing first email template`\n );\n for (const id in fileData.emailTemplate) {\n if ({}.hasOwnProperty.call(fileData.emailTemplate, id)) {\n try {\n await putEmailTemplate(\n id.replace(regexEmailTemplateType, ''),\n fileData.emailTemplate[id]\n );\n updateProgressIndicator(`Imported ${id}`);\n stopProgressIndicator(`Imported ${id}`);\n } catch (putEmailTemplateError) {\n stopProgressIndicator(`Error importing email template ${id}`);\n printMessage(`\\nError importing email template ${id}`, 'error');\n printMessage(putEmailTemplateError.response.data, 'error');\n }\n break;\n }\n }\n } else {\n printMessage('Import validation failed...', 'error');\n }\n });\n}\n"],"mappings":"AAAA,OAAOA,EAAE,MAAM,IAAI;AAEnB,SAASC,aAAa,EAAEC,iBAAiB,QAAQ,uBAAuB;AACxE,SAASC,gBAAgB,EAAEC,cAAc,QAAQ,4BAA4B;AAC7E,SACEC,uBAAuB,EACvBC,uBAAuB,EACvBC,qBAAqB,EACrBC,YAAY,EACZC,WAAW,QACN,kBAAkB;AACzB,OAAOC,QAAQ,MAAM,kBAAkB;AAEvC,MAAMC,wBAAwB,GAAG,gBAAgB;AACjD,MAAM;EACJC,mBAAmB;EACnBC,gBAAgB;EAChBC,iBAAiB;EACjBC;AACF,CAAC,GAAGd,aAAa;AACjB,MAAM;EAAEe;AAAe,CAAC,GAAGd,iBAAiB;AAE5C,MAAMe,sBAAsB,GAAG,IAAIC,MAAM,CAAE,GAAEN,mBAAoB,G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OAAO,CAAC;UAC5D;UACA;QACF;MACF;IACF,CAAC,MAAM;MACLpE,YAAY,CAAC,6BAA6B,EAAE,OAAO,CAAC;IACtD;EACF,CAAC,CAAC;AACJ"}
@@ -0,0 +1,317 @@
1
+ /* eslint-disable no-await-in-loop */
2
+ import fs from 'fs';
3
+ import fse from 'fs-extra';
4
+ import path from 'path';
5
+ import propertiesReader from 'properties-reader';
6
+ import replaceall from 'replaceall';
7
+ import { Idm, Utils, ValidationUtils } from '@rockcarver/frodo-lib';
8
+ import { createProgressIndicator, printMessage, stopProgressIndicator } from '../utils/Console';
9
+ import { getTypedFilename } from '../utils/ExportImportUtils';
10
+ const {
11
+ readFiles,
12
+ unSubstituteEnvParams
13
+ } = Utils;
14
+ const {
15
+ validateScriptHooks
16
+ } = ValidationUtils;
17
+ const {
18
+ getAllConfigEntities,
19
+ getConfigEntity,
20
+ putConfigEntity,
21
+ queryAllManagedObjectsByType
22
+ } = Idm;
23
+ /**
24
+ * List all IDM configuration objects
25
+ */
26
+ export async function listAllConfigEntities() {
27
+ try {
28
+ const {
29
+ configurations
30
+ } = await getAllConfigEntities();
31
+ for (const configEntity of configurations) {
32
+ printMessage(`${configEntity._id}`, 'data');
33
+ }
34
+ } catch (getAllConfigEntitiesError) {
35
+ printMessage(getAllConfigEntitiesError, 'error');
36
+ printMessage(`Error getting config entities: ${getAllConfigEntitiesError}`, 'error');
37
+ }
38
+ }
39
+
40
+ /**
41
+ * Export an IDM configuration object.
42
+ * @param {String} id the desired configuration object
43
+ * @param {String} file optional export file
44
+ */
45
+ export async function exportConfigEntity(id, file) {
46
+ let fileName = file;
47
+ if (!fileName) {
48
+ fileName = getTypedFilename(`${id}`, 'idm');
49
+ }
50
+ const configEntity = await getConfigEntity(id);
51
+ fs.writeFile(fileName, JSON.stringify(configEntity, null, 2), err => {
52
+ if (err) {
53
+ return printMessage(`ERROR - can't save ${id} export to file`, 'error');
54
+ }
55
+ return '';
56
+ });
57
+ }
58
+
59
+ /**
60
+ * Export all IDM configuration objects into separate JSON files in a directory specified by <directory>
61
+ * @param {String} directory export directory
62
+ */
63
+ export async function exportAllRawConfigEntities(directory) {
64
+ try {
65
+ const {
66
+ configurations
67
+ } = await getAllConfigEntities();
68
+ if (!fs.existsSync(directory)) {
69
+ fs.mkdirSync(directory);
70
+ }
71
+ createProgressIndicator('indeterminate', undefined, 'Exporting config objects...');
72
+ const entityPromises = [];
73
+ for (const configEntity of configurations) {
74
+ entityPromises.push(getConfigEntity(configEntity._id).catch(getConfigEntityError => {
75
+ var _getConfigEntityError, _getConfigEntityError2, _getConfigEntityError3, _getConfigEntityError4, _getConfigEntityError5, _getConfigEntityError6;
76
+ if (!(((_getConfigEntityError = getConfigEntityError.response) === null || _getConfigEntityError === void 0 ? void 0 : _getConfigEntityError.status) === 403 && ((_getConfigEntityError2 = getConfigEntityError.response) === null || _getConfigEntityError2 === void 0 ? void 0 : (_getConfigEntityError3 = _getConfigEntityError2.data) === null || _getConfigEntityError3 === void 0 ? void 0 : _getConfigEntityError3.message) === 'This operation is not available in ForgeRock Identity Cloud.') &&
77
+ // https://bugster.forgerock.org/jira/browse/OPENIDM-18270
78
+ !(((_getConfigEntityError4 = getConfigEntityError.response) === null || _getConfigEntityError4 === void 0 ? void 0 : _getConfigEntityError4.status) === 404 && ((_getConfigEntityError5 = getConfigEntityError.response) === null || _getConfigEntityError5 === void 0 ? void 0 : (_getConfigEntityError6 = _getConfigEntityError5.data) === null || _getConfigEntityError6 === void 0 ? void 0 : _getConfigEntityError6.message) === 'No configuration exists for id org.apache.felix.fileinstall/openidm')) {
79
+ var _getConfigEntityError7;
80
+ printMessage((_getConfigEntityError7 = getConfigEntityError.response) === null || _getConfigEntityError7 === void 0 ? void 0 : _getConfigEntityError7.data, 'error');
81
+ printMessage(`Error getting config entity ${configEntity._id}: ${getConfigEntityError}`, 'error');
82
+ }
83
+ }));
84
+ }
85
+ const results = await Promise.all(entityPromises);
86
+ for (const item of results) {
87
+ if (item != null) {
88
+ fse.outputFile(`${directory}/${item._id}.json`, JSON.stringify(item, null, 2), err => {
89
+ if (err) {
90
+ return printMessage(`ERROR - can't save config ${item._id} to file - ${err}`, 'error');
91
+ }
92
+ });
93
+ }
94
+ }
95
+ stopProgressIndicator('Exported config objects.', 'success');
96
+ } catch (getAllConfigEntitiesError) {
97
+ printMessage(getAllConfigEntitiesError, 'error');
98
+ printMessage(`Error getting config entities: ${getAllConfigEntitiesError}`, 'error');
99
+ }
100
+ }
101
+
102
+ /**
103
+ * Export all IDM configuration objects
104
+ * @param {String} directory export directory
105
+ * @param {String} entitiesFile JSON file that specifies the config entities to export/import
106
+ * @param {String} envFile File that defines environment specific variables for replacement during configuration export/import
107
+ */
108
+ export async function exportAllConfigEntities(directory, entitiesFile, envFile) {
109
+ let entriesToExport = [];
110
+ // read list of entities to export
111
+ fs.readFile(entitiesFile, 'utf8', async (err, data) => {
112
+ if (err) throw err;
113
+ const entriesData = JSON.parse(data);
114
+ entriesToExport = entriesData.idm;
115
+ // console.log(`entriesToExport ${entriesToExport}`);
116
+
117
+ // read list of configs to parameterize for environment specific values
118
+ const envParams = propertiesReader(envFile);
119
+ try {
120
+ const {
121
+ configurations
122
+ } = await getAllConfigEntities();
123
+ // create export directory if not exist
124
+ if (!fs.existsSync(directory)) {
125
+ fs.mkdirSync(directory);
126
+ }
127
+ createProgressIndicator('indeterminate', undefined, 'Exporting config objects...');
128
+ const entityPromises = [];
129
+ for (const configEntity of configurations) {
130
+ if (entriesToExport.includes(configEntity._id)) {
131
+ entityPromises.push(getConfigEntity(configEntity._id));
132
+ }
133
+ }
134
+ const results = await Promise.all(entityPromises);
135
+ for (const item of results) {
136
+ if (item != null) {
137
+ let configEntityString = JSON.stringify(item, null, 2);
138
+ envParams.each((key, value) => {
139
+ configEntityString = replaceall(value, `\${${key}}`, configEntityString);
140
+ });
141
+ fse.outputFile(`${directory}/${item._id}.json`, configEntityString, error => {
142
+ if (err) {
143
+ return printMessage(`ERROR - can't save config ${item._id} to file - ${error}`, 'error');
144
+ }
145
+ });
146
+ }
147
+ }
148
+ stopProgressIndicator(null, 'success');
149
+ } catch (getAllConfigEntitiesError) {
150
+ printMessage(getAllConfigEntitiesError, 'error');
151
+ printMessage(`Error getting config entities: ${getAllConfigEntitiesError}`, 'error');
152
+ }
153
+ });
154
+ }
155
+
156
+ /**
157
+ * Import an IDM configuration object.
158
+ * @param entityId the configuration object to import
159
+ * @param file optional file to import
160
+ */
161
+ export async function importConfigEntity(entityId, file, validate) {
162
+ if (!file) {
163
+ file = getTypedFilename(entityId, 'idm');
164
+ }
165
+ const entityData = fs.readFileSync(path.resolve(process.cwd(), file), 'utf8');
166
+ const jsObject = JSON.parse(entityData);
167
+ const isValid = validateScriptHooks(jsObject);
168
+ if (validate && !isValid) {
169
+ printMessage('Invalid IDM configuration object', 'error');
170
+ return;
171
+ }
172
+ try {
173
+ await putConfigEntity(entityId, entityData);
174
+ } catch (putConfigEntityError) {
175
+ printMessage(putConfigEntityError, 'error');
176
+ printMessage(`Error: ${putConfigEntityError}`, 'error');
177
+ }
178
+ }
179
+
180
+ /**
181
+ * Import all IDM configuration objects from separate JSON files in a directory specified by <directory>
182
+ * @param baseDirectory export directory
183
+ * @param validate validate script hooks
184
+ */
185
+ export async function importAllRawConfigEntities(baseDirectory, validate) {
186
+ if (!fs.existsSync(baseDirectory)) {
187
+ return;
188
+ }
189
+ const files = await readFiles(baseDirectory);
190
+ const jsonFiles = files.filter(({
191
+ path
192
+ }) => path.toLowerCase().endsWith('.json')).map(({
193
+ path,
194
+ content
195
+ }) => ({
196
+ // Remove .json extension
197
+ entityId: path.substring(0, path.length - 5),
198
+ content,
199
+ path
200
+ }));
201
+ let everyScriptValid = true;
202
+ for (const file of jsonFiles) {
203
+ const jsObject = JSON.parse(file.content);
204
+ const isScriptValid = validateScriptHooks(jsObject);
205
+ if (!isScriptValid) {
206
+ printMessage(`Invalid script hook in ${file.path}`, 'error');
207
+ everyScriptValid = false;
208
+ }
209
+ }
210
+ if (validate && !everyScriptValid) {
211
+ return;
212
+ }
213
+ createProgressIndicator('indeterminate', undefined, 'Importing config objects...');
214
+ const entityPromises = jsonFiles.map(file => {
215
+ return putConfigEntity(file.entityId, file.content);
216
+ });
217
+ const results = await Promise.allSettled(entityPromises);
218
+ const errors = results.filter(result => result.status === 'rejected');
219
+ if (errors.length > 0) {
220
+ printMessage(`Failed to import ${errors.length} config objects:`, 'error');
221
+ for (const error of errors) {
222
+ printMessage(`- ${error.reason}`, 'error');
223
+ }
224
+ stopProgressIndicator(`Failed to import ${errors.length} config objects`, 'error');
225
+ return;
226
+ }
227
+ stopProgressIndicator(`Imported ${results.length} config objects`, 'success');
228
+ }
229
+
230
+ /**
231
+ * Import all IDM configuration objects
232
+ * @param baseDirectory import directory
233
+ * @param entitiesFile JSON file that specifies the config entities to export/import
234
+ * @param envFile File that defines environment specific variables for replacement during configuration export/import
235
+ * @param validate validate script hooks
236
+ */
237
+ export async function importAllConfigEntities(baseDirectory, entitiesFile, envFile, validate) {
238
+ if (!fs.existsSync(baseDirectory)) {
239
+ return;
240
+ }
241
+ const entriesToImport = JSON.parse(fs.readFileSync(entitiesFile, 'utf8')).idm;
242
+ const envReader = propertiesReader(envFile);
243
+ const files = await readFiles(baseDirectory);
244
+ const jsonFiles = files.filter(({
245
+ path
246
+ }) => path.toLowerCase().endsWith('.json')).map(({
247
+ content,
248
+ path
249
+ }) => ({
250
+ // Remove .json extension
251
+ entityId: path.substring(0, path.length - 5),
252
+ content,
253
+ path
254
+ }));
255
+ let everyScriptValid = true;
256
+ for (const file of jsonFiles) {
257
+ const jsObject = JSON.parse(file.content);
258
+ const isScriptValid = validateScriptHooks(jsObject);
259
+ if (!isScriptValid) {
260
+ printMessage(`Invalid script hook in ${file.path}`, 'error');
261
+ everyScriptValid = false;
262
+ }
263
+ }
264
+ if (validate && !everyScriptValid) {
265
+ return;
266
+ }
267
+ createProgressIndicator('indeterminate', undefined, 'Importing config objects...');
268
+ const entityPromises = jsonFiles.filter(({
269
+ entityId
270
+ }) => {
271
+ return entriesToImport.includes(entityId);
272
+ }).map(({
273
+ entityId,
274
+ content
275
+ }) => {
276
+ const unsubstituted = unSubstituteEnvParams(content, envReader);
277
+ return putConfigEntity(entityId, unsubstituted);
278
+ });
279
+ const results = await Promise.allSettled(entityPromises);
280
+ const errors = results.filter(result => result.status === 'rejected');
281
+ if (errors.length > 0) {
282
+ printMessage(`Failed to import ${errors.length} config objects:`, 'error');
283
+ for (const error of errors) {
284
+ printMessage(`- ${error.reason}`, 'error');
285
+ }
286
+ stopProgressIndicator(`Failed to import ${errors.length} config objects`, 'error');
287
+ return;
288
+ }
289
+ stopProgressIndicator(`Imported ${results.length} config objects`, 'success');
290
+ }
291
+
292
+ /**
293
+ * Count number of managed objects of a given type
294
+ * @param {String} type managed object type, e.g. alpha_user
295
+ */
296
+ export async function countManagedObjects(type) {
297
+ let count = 0;
298
+ let result = {
299
+ result: [],
300
+ resultCount: 0,
301
+ pagedResultsCookie: null,
302
+ totalPagedResultsPolicy: 'NONE',
303
+ totalPagedResults: -1,
304
+ remainingPagedResults: -1
305
+ };
306
+ try {
307
+ do {
308
+ result = await queryAllManagedObjectsByType(type, [], result.pagedResultsCookie);
309
+ count += result.resultCount;
310
+ } while (result.pagedResultsCookie);
311
+ printMessage(`${type}: ${count}`);
312
+ } catch (error) {
313
+ printMessage(error.response.data, 'error');
314
+ printMessage(`Error querying managed objects by type: ${error}`, 'error');
315
+ }
316
+ }
317
+ //# sourceMappingURL=IdmOps.js.map