@yrpri/api 9.0.101 → 9.0.103

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 (638) hide show
  1. package/active-citizen/engine/allOurIdeas/explainAnswersAssistant.js +11 -1
  2. package/active-citizen/llms/baseChatBot.js +8 -75
  3. package/active-citizen/llms/imageGeneration/chatGptImageGenerator.js +56 -0
  4. package/active-citizen/llms/imageGeneration/collectionImageGenerator.js +6 -0
  5. package/agents/assistants/agentAssistant.js +3 -2
  6. package/agents/assistants/baseAssistant.js +7 -30
  7. package/agents/assistants/baseAssistantWithVoice.js +3 -3
  8. package/agents/assistants/voiceAssistant.js +2 -2
  9. package/agents/controllers/agentProductController.js +2 -1
  10. package/agents/controllers/agentSubscriptionController.js +20 -11
  11. package/agents/controllers/assistantsController.js +171 -127
  12. package/agents/controllers/policySynthAgents.js +33 -12
  13. package/agents/managers/newAiModelSetup.js +96 -0
  14. package/agents/managers/subscriptionManager.js +2 -2
  15. package/app.js +12 -12
  16. package/authorization.cjs +4 -0
  17. package/controllers/allOurIdeas.js +2 -1
  18. package/controllers/communities.cjs +47 -1
  19. package/controllers/groups.cjs +67 -4
  20. package/controllers/index.cjs +7 -7
  21. package/controllers/nonSpa.cjs +1 -1
  22. package/dist/active-citizen/controllers/activities.cjs +174 -0
  23. package/dist/active-citizen/controllers/news_feeds.cjs +96 -0
  24. package/dist/active-citizen/controllers/notifications.cjs +243 -0
  25. package/dist/active-citizen/controllers/recommendations.cjs +280 -0
  26. package/dist/active-citizen/engine/allOurIdeas/aiHelper.js +204 -0
  27. package/dist/active-citizen/engine/allOurIdeas/explainAnswersAssistant.js +66 -0
  28. package/dist/active-citizen/engine/allOurIdeas/iconGenerator.js +38 -0
  29. package/dist/active-citizen/engine/analytics/export_anon_community_activities.js +334 -0
  30. package/dist/active-citizen/engine/analytics/importer.js +308 -0
  31. package/dist/active-citizen/engine/analytics/manager.cjs +377 -0
  32. package/dist/active-citizen/engine/analytics/plausible/manager.cjs +500 -0
  33. package/dist/active-citizen/engine/analytics/statsCalc.cjs +194 -0
  34. package/dist/active-citizen/engine/analytics/utils.cjs +369 -0
  35. package/dist/active-citizen/engine/marketing/campaign.cjs +90 -0
  36. package/dist/active-citizen/engine/moderation/fraud/CreateFraudAuditReport.cjs +313 -0
  37. package/dist/active-citizen/engine/moderation/fraud/FraudBase.cjs +239 -0
  38. package/dist/active-citizen/engine/moderation/fraud/FraudDeleteBase.cjs +211 -0
  39. package/dist/active-citizen/engine/moderation/fraud/FraudDeleteEndorsements.cjs +120 -0
  40. package/dist/active-citizen/engine/moderation/fraud/FraudDeletePointQualities.cjs +114 -0
  41. package/dist/active-citizen/engine/moderation/fraud/FraudDeletePoints.cjs +101 -0
  42. package/dist/active-citizen/engine/moderation/fraud/FraudDeletePosts.cjs +84 -0
  43. package/dist/active-citizen/engine/moderation/fraud/FraudDeleteRatings.cjs +15 -0
  44. package/dist/active-citizen/engine/moderation/fraud/FraudGetBase.cjs +133 -0
  45. package/dist/active-citizen/engine/moderation/fraud/FraudGetEndorsements.cjs +185 -0
  46. package/dist/active-citizen/engine/moderation/fraud/FraudGetPointQualities.cjs +184 -0
  47. package/dist/active-citizen/engine/moderation/fraud/FraudGetPoints.cjs +170 -0
  48. package/dist/active-citizen/engine/moderation/fraud/FraudGetPosts.cjs +109 -0
  49. package/dist/active-citizen/engine/moderation/fraud/FraudGetRatings.cjs +140 -0
  50. package/dist/active-citizen/engine/moderation/fraud/FraudScannerNotifier.cjs +279 -0
  51. package/dist/active-citizen/engine/moderation/get_moderation_items.cjs +386 -0
  52. package/dist/active-citizen/engine/moderation/image_labeling/CommunityLabeling.cjs +49 -0
  53. package/dist/active-citizen/engine/moderation/image_labeling/GroupLabeling.cjs +68 -0
  54. package/dist/active-citizen/engine/moderation/image_labeling/ImageLabelingBase.cjs +288 -0
  55. package/dist/active-citizen/engine/moderation/image_labeling/PointLabeling.cjs +33 -0
  56. package/dist/active-citizen/engine/moderation/image_labeling/PostLabeling.cjs +56 -0
  57. package/dist/active-citizen/engine/moderation/perspective_api_client.cjs +106 -0
  58. package/dist/active-citizen/engine/moderation/process_moderation_items.cjs +344 -0
  59. package/dist/active-citizen/engine/moderation/toxicity_analysis.cjs +810 -0
  60. package/dist/active-citizen/engine/news_feeds/activity_and_item_index_definitions.cjs +15 -0
  61. package/dist/active-citizen/engine/news_feeds/generate_dynamically.cjs +362 -0
  62. package/dist/active-citizen/engine/news_feeds/generate_from_notifications.cjs +268 -0
  63. package/dist/active-citizen/engine/news_feeds/news_feeds_utils.cjs +439 -0
  64. package/dist/active-citizen/engine/notifications/emails_utils.cjs +569 -0
  65. package/dist/active-citizen/engine/notifications/generate_point_notifications.cjs +233 -0
  66. package/dist/active-citizen/engine/notifications/generate_post_notifications.cjs +118 -0
  67. package/dist/active-citizen/engine/notifications/generate_post_status_change_notifications.cjs +41 -0
  68. package/dist/active-citizen/engine/notifications/notifications_utils.cjs +148 -0
  69. package/dist/active-citizen/engine/notifications/point_delivery.cjs +54 -0
  70. package/dist/active-citizen/engine/notifications/post_delivery.cjs +31 -0
  71. package/dist/active-citizen/engine/notifications/process_delayed_notifications.cjs +471 -0
  72. package/dist/active-citizen/engine/notifications/process_general_notifications.cjs +212 -0
  73. package/dist/active-citizen/engine/old/exporters/categories_dataset.js +153 -0
  74. package/dist/active-citizen/engine/old/exporters/dataset_tools.js +80 -0
  75. package/dist/active-citizen/engine/old/exporters/sentiment_dataset.js +157 -0
  76. package/dist/active-citizen/engine/recommendations/events_importer.cjs +139 -0
  77. package/dist/active-citizen/engine/recommendations/events_manager.cjs +212 -0
  78. package/dist/active-citizen/engine/reports/add_points_to_sheet.cjs +83 -0
  79. package/dist/active-citizen/engine/reports/commonUtils.js +75 -0
  80. package/dist/active-citizen/engine/reports/common_utils.cjs +740 -0
  81. package/dist/active-citizen/engine/reports/docx_group_report.cjs +596 -0
  82. package/dist/active-citizen/engine/reports/xlsAllOurIdeasExport.js +232 -0
  83. package/dist/active-citizen/engine/reports/xls_community_users_report.cjs +277 -0
  84. package/dist/active-citizen/engine/reports/xls_group_report.cjs +718 -0
  85. package/dist/active-citizen/llms/baseChatBot.js +183 -0
  86. package/dist/active-citizen/llms/imageGeneration/chatGptImageGenerator.js +56 -0
  87. package/dist/active-citizen/llms/imageGeneration/collectionImageGenerator.js +109 -0
  88. package/dist/active-citizen/llms/imageGeneration/dalleImageGenerator.js +84 -0
  89. package/dist/active-citizen/llms/imageGeneration/fluxImageGenerator.js +49 -0
  90. package/dist/active-citizen/llms/imageGeneration/imageProcessorService.js +64 -0
  91. package/dist/active-citizen/llms/imageGeneration/imagenImageGenerator.js +107 -0
  92. package/dist/active-citizen/llms/imageGeneration/s3Service.js +110 -0
  93. package/dist/active-citizen/llms/llmTranslation.js +472 -0
  94. package/dist/active-citizen/models/ac_activity.cjs +216 -0
  95. package/dist/active-citizen/models/ac_background_job.cjs +109 -0
  96. package/dist/active-citizen/models/ac_campaign.cjs +97 -0
  97. package/dist/active-citizen/models/ac_client_activity.cjs +23 -0
  98. package/dist/active-citizen/models/ac_delayed_notification.cjs +43 -0
  99. package/dist/active-citizen/models/ac_following.cjs +43 -0
  100. package/dist/active-citizen/models/ac_list.cjs +68 -0
  101. package/dist/active-citizen/models/ac_list_users.cjs +19 -0
  102. package/dist/active-citizen/models/ac_mute.cjs +27 -0
  103. package/dist/active-citizen/models/ac_news_feed_item.cjs +57 -0
  104. package/dist/active-citizen/models/ac_news_feed_processed_range.cjs +59 -0
  105. package/dist/active-citizen/models/ac_notification.cjs +292 -0
  106. package/dist/active-citizen/models/ac_translation_cache.cjs +750 -0
  107. package/dist/active-citizen/models/ac_watching.cjs +31 -0
  108. package/dist/active-citizen/scripts/analytics/setup_all_plausible_goals.cjs +13 -0
  109. package/dist/active-citizen/scripts/fix_old_delayed_notifications.js +63 -0
  110. package/dist/active-citizen/scripts/kue_status.js +31 -0
  111. package/dist/active-citizen/scripts/kue_watch_stuck_jobs.js +24 -0
  112. package/dist/active-citizen/scripts/translation_clear_language.js +117 -0
  113. package/dist/active-citizen/scripts/translation_delete.js +27 -0
  114. package/dist/active-citizen/scripts/translation_replace_text_from_url.js +180 -0
  115. package/dist/active-citizen/scripts/translation_update.js +28 -0
  116. package/dist/active-citizen/scripts/translations_list.js +27 -0
  117. package/{active-citizen/utils/airbrake.js → dist/active-citizen/utils/airbrake.cjs} +1 -1
  118. package/dist/active-citizen/utils/get_anonymous_system_user.cjs +21 -0
  119. package/dist/active-citizen/utils/i18n.cjs +3 -0
  120. package/dist/active-citizen/utils/logger.cjs +25 -0
  121. package/dist/active-citizen/utils/redisConnection.cjs +29 -0
  122. package/dist/active-citizen/utils/to_json.cjs +9 -0
  123. package/dist/active-citizen/utils/translation_cloning.cjs +171 -0
  124. package/dist/active-citizen/utils/translation_helpers.cjs +534 -0
  125. package/dist/active-citizen/utils/truncate_text.cjs +21 -0
  126. package/dist/active-citizen/utils/updateAllLocalesFromEn.js +253 -0
  127. package/dist/active-citizen/utils/updateLocaleFolders.js +34 -0
  128. package/dist/active-citizen/workers/activity.cjs +189 -0
  129. package/dist/active-citizen/workers/anonymizations.cjs +734 -0
  130. package/dist/active-citizen/workers/bulk_status_update.cjs +458 -0
  131. package/dist/active-citizen/workers/delayed_jobs.cjs +244 -0
  132. package/dist/active-citizen/workers/deletions.cjs +1911 -0
  133. package/dist/active-citizen/workers/email.cjs +9 -0
  134. package/dist/active-citizen/workers/fraud_management.cjs +109 -0
  135. package/dist/active-citizen/workers/generativeAi.js +56 -0
  136. package/dist/active-citizen/workers/main.cjs +89 -0
  137. package/dist/active-citizen/workers/marketing.cjs +25 -0
  138. package/dist/active-citizen/workers/moderation.cjs +73 -0
  139. package/dist/active-citizen/workers/notification_delivery.cjs +368 -0
  140. package/dist/active-citizen/workers/notification_news_feed.cjs +142 -0
  141. package/dist/active-citizen/workers/queue.cjs +99 -0
  142. package/dist/active-citizen/workers/recount.cjs +74 -0
  143. package/dist/active-citizen/workers/reports.cjs +42 -0
  144. package/dist/active-citizen/workers/similarities.cjs +21 -0
  145. package/dist/active-citizen/workers/speech_to_text.cjs +482 -0
  146. package/dist/agents/assistants/agentAssistant.js +88 -0
  147. package/dist/agents/assistants/baseAssistant.js +888 -0
  148. package/dist/agents/assistants/baseAssistantWithVoice.js +150 -0
  149. package/dist/agents/assistants/modes/agentDirectConnection.js +84 -0
  150. package/dist/agents/assistants/modes/agentSelectionMode.js +44 -0
  151. package/dist/agents/assistants/modes/baseAssistantMode.js +54 -0
  152. package/dist/agents/assistants/modes/tools/agentTools.js +447 -0
  153. package/dist/agents/assistants/modes/tools/baseTools.js +58 -0
  154. package/dist/agents/assistants/modes/tools/loginTools.js +156 -0
  155. package/dist/agents/assistants/modes/tools/models/agents.js +146 -0
  156. package/dist/agents/assistants/modes/tools/models/subscriptions.js +332 -0
  157. package/dist/agents/assistants/modes/tools/models/users.js +11 -0
  158. package/dist/agents/assistants/modes/tools/navigationTools.js +166 -0
  159. package/{agents/assistants/modes/tools/workflowConversationTools.js → dist/agents/assistants/modes/tools/subscriptionTools.js} +1 -4
  160. package/{agents/assistants/modes/tools/workflowTools.js → dist/agents/assistants/modes/tools/workflowConverstationTools.js} +1 -1
  161. package/dist/agents/assistants/voiceAssistant.js +619 -0
  162. package/dist/agents/controllers/agentProductController.js +103 -0
  163. package/dist/agents/controllers/agentSubscriptionController.js +261 -0
  164. package/dist/agents/controllers/assistantsController.js +511 -0
  165. package/dist/agents/controllers/policySynthAgents.js +395 -0
  166. package/{agents → dist/agents/managers}/agentProductManager.js +2 -2
  167. package/dist/agents/managers/emailInvitesManager.js +55 -0
  168. package/dist/agents/managers/emailTemplateRenderer.js +362 -0
  169. package/dist/agents/managers/newAiModelSetup.js +650 -0
  170. package/dist/agents/managers/notificationAgentQueueManager.js +510 -0
  171. package/dist/agents/managers/subscriptionManager.js +535 -0
  172. package/dist/agents/managers/workflowConversationManager.js +79 -0
  173. package/dist/agents/models/agentProduct.js +116 -0
  174. package/dist/agents/models/agentProductBoosterPurchase.js +58 -0
  175. package/dist/agents/models/agentProductBundle.js +68 -0
  176. package/dist/agents/models/agentProductRun.js +52 -0
  177. package/dist/agents/models/discount.js +88 -0
  178. package/dist/agents/models/subscription.js +79 -0
  179. package/dist/agents/models/subscriptionPlan.js +46 -0
  180. package/dist/agents/models/subscriptionUser.js +27 -0
  181. package/dist/agents/models/testData/createEvolyAgentProduct.js +477 -0
  182. package/dist/agents/models/testData/old/updateAgentWorkflowConfiguration.js +230 -0
  183. package/dist/agents/models/testData/setupEvolyAgentProductConfig.js +233 -0
  184. package/dist/agents/models/testData/updateAgentWorkflowConfiguration.js +230 -0
  185. package/{agents/models/workflowConverstation.js → dist/agents/models/workflowConversation.js} +1 -1
  186. package/{agents/tools/updateTemplateWorkflow.js → dist/agents/tools/setTemplateWorkflowCommunityId.js} +1 -0
  187. package/dist/app.js +943 -0
  188. package/dist/authorization.cjs +1860 -0
  189. package/dist/bot_control.js +1930 -0
  190. package/dist/config/config.cjs +14 -0
  191. package/dist/config/config.js +14 -0
  192. package/dist/controllers/allOurIdeas.js +696 -0
  193. package/dist/controllers/audios.cjs +100 -0
  194. package/dist/controllers/bulkStatusUpdates.cjs +202 -0
  195. package/dist/controllers/categories.cjs +199 -0
  196. package/dist/controllers/communities.cjs +2996 -0
  197. package/dist/controllers/domains.cjs +1341 -0
  198. package/dist/controllers/externalIds.cjs +223 -0
  199. package/dist/controllers/groups.cjs +4309 -0
  200. package/dist/controllers/images.cjs +499 -0
  201. package/dist/controllers/index.cjs +449 -0
  202. package/dist/controllers/legacyPages.cjs +35 -0
  203. package/dist/controllers/legacyPosts.cjs +56 -0
  204. package/dist/controllers/legacyUsers.cjs +36 -0
  205. package/dist/controllers/nonSpa.cjs +574 -0
  206. package/dist/controllers/organizations.cjs +250 -0
  207. package/dist/controllers/points.cjs +1137 -0
  208. package/dist/controllers/posts.cjs +2036 -0
  209. package/dist/controllers/ratings.cjs +234 -0
  210. package/dist/controllers/users.cjs +2255 -0
  211. package/dist/controllers/videos.cjs +226 -0
  212. package/dist/deleteUnwantedDeclerations.cjs +55 -0
  213. package/dist/migrations/agentAuditLogs.cjs +46 -0
  214. package/dist/migrations/agentClasses.cjs +60 -0
  215. package/dist/migrations/agentConnectorClasses.cjs +61 -0
  216. package/dist/migrations/agentConnectors.cjs +50 -0
  217. package/dist/migrations/agentEvals.cjs +45 -0
  218. package/dist/migrations/agentRegistries.cjs +40 -0
  219. package/dist/migrations/agents.cjs +54 -0
  220. package/dist/migrations/aiModels.cjs +49 -0
  221. package/dist/migrations/apiUsage.cjs +47 -0
  222. package/dist/migrations/apis.cjs +49 -0
  223. package/dist/migrations/groupPrivateData.cjs +30 -0
  224. package/dist/migrations/modelUsage.cjs +60 -0
  225. package/dist/migrations/oldMigrations/2019/20181030020612-AddActivitiesIndex.js +23 -0
  226. package/dist/migrations/oldMigrations/2019/20181102210612-AddFirstVideoFeatures.js +360 -0
  227. package/dist/migrations/oldMigrations/2019/20181212210612-ModerationFeatures.js +29 -0
  228. package/dist/migrations/oldMigrations/2019/2019010610612-CommunityFolders.js +43 -0
  229. package/dist/migrations/oldMigrations/2019/20190117020612-AddMissingIndexes.js +24 -0
  230. package/dist/migrations/oldMigrations/2019/20190117020612-RemoveUnusedIndexes.js +29 -0
  231. package/dist/migrations/oldMigrations/2019/20190127020612-RemoveUnusedIndexesPartThree.js +22 -0
  232. package/dist/migrations/oldMigrations/2019/20190127020612-RemoveUnusedIndexesPartTwo.js +23 -0
  233. package/{migrations/200824_create_embeddings_and_org_update.cjs → dist/migrations/oldMigrations/2019/20190223020612-AddPrivateProfileDataToUsers.js} +6 -3
  234. package/dist/migrations/oldMigrations/2019/20190706210612-AddCustomRatings.js +43 -0
  235. package/dist/migrations/oldMigrations/2019/20190829210612-AddGeneralStore.js +36 -0
  236. package/dist/migrations/oldMigrations/2019/20192811210612-AddAcClientActivities.js +41 -0
  237. package/dist/migrations/oldMigrations/2020/20190527020612-WorkOnIndexes.js +88 -0
  238. package/dist/migrations/oldMigrations/2020/20200409020612-AddBackgroundJob.js +33 -0
  239. package/dist/migrations/oldMigrations/2020/20200716210612-AddDataToCollections.js +38 -0
  240. package/dist/migrations/oldMigrations/2022/20220215100612-AddDataToEndorsements.js +19 -0
  241. package/dist/migrations/oldMigrations/2022/20220220100612-AddDataForFraudDetection.js +19 -0
  242. package/dist/migrations/oldMigrations/2022/20220903100612-AddPromotionFeatures.js +127 -0
  243. package/dist/migrations/oldMigrations/2022/onHold/20200527020612-AddCampaigns.js +68 -0
  244. package/dist/migrations/oldMigrations/2024/20241304175112-AddMediaSupportForHtmlGroups.cjs +63 -0
  245. package/dist/migrations/oldMigrations/older/20160511172514-AddNotificationFeatures.js +14 -0
  246. package/dist/migrations/oldMigrations/older/20161030020612-AddBulkStatusUpdate.js +71 -0
  247. package/dist/migrations/oldMigrations/older/20170514035258-add-metadata-to-invites.js +12 -0
  248. package/dist/migrations/oldMigrations/older/20180216020612-AddTranslationCaches.js +46 -0
  249. package/dist/migrations/oldMigrations/older/20180218210612-AddTranslationAndLanguages.js +46 -0
  250. package/dist/migrations/privateAccessStore.cjs +55 -0
  251. package/dist/migrations/zzz_associations.cjs +154 -0
  252. package/dist/migrations/zzzzz_create_agent_runs.cjs +606 -0
  253. package/dist/migrations/zzzzzz_create_agent_runs_fix.cjs +11 -0
  254. package/dist/migrations/zzzzzzz_create_trees.cjs +81 -0
  255. package/dist/models/audio.cjs +430 -0
  256. package/dist/models/bulk_status_update.cjs +58 -0
  257. package/dist/models/campaign.cjs +78 -0
  258. package/dist/models/category.cjs +94 -0
  259. package/dist/models/community.cjs +337 -0
  260. package/dist/models/domain.cjs +486 -0
  261. package/dist/models/endorsement.cjs +39 -0
  262. package/dist/models/general_data_store.cjs +20 -0
  263. package/dist/models/group.cjs +728 -0
  264. package/dist/models/image.cjs +579 -0
  265. package/dist/models/index.cjs +186 -0
  266. package/dist/models/invite.cjs +48 -0
  267. package/dist/models/iso_country.cjs +16 -0
  268. package/dist/models/organization.cjs +122 -0
  269. package/dist/models/page.cjs +273 -0
  270. package/dist/models/point.cjs +622 -0
  271. package/dist/models/point_quality.cjs +39 -0
  272. package/dist/models/point_revision.cjs +47 -0
  273. package/dist/models/post.cjs +680 -0
  274. package/dist/models/post_revision.cjs +38 -0
  275. package/dist/models/post_status_change.cjs +35 -0
  276. package/dist/models/promotion.cjs +34 -0
  277. package/dist/models/rating.cjs +51 -0
  278. package/dist/models/relationship.cjs +19 -0
  279. package/dist/models/request_to_join.cjs +20 -0
  280. package/dist/models/user.cjs +604 -0
  281. package/dist/models/user_legacy_password.cjs +13 -0
  282. package/dist/models/video.cjs +1137 -0
  283. package/dist/publish.js +40 -0
  284. package/dist/repack.js +53 -0
  285. package/dist/scripts/addRatingUsersToGroup.js +51 -0
  286. package/dist/scripts/addUserToOrganization.js +71 -0
  287. package/dist/scripts/analyseRatingsForCommunity.js +150 -0
  288. package/dist/scripts/analyzeAndFixBrokenPointUsers.js +28 -0
  289. package/dist/scripts/analyzeEndorsementsByCountry.js +70 -0
  290. package/dist/scripts/analyzePostsForCommunity.js +185 -0
  291. package/dist/scripts/bulkStatusUpdates/listUpdates.js +14 -0
  292. package/dist/scripts/bulkStatusUpdates/mergeLatestPostsToUpdate.js +110 -0
  293. package/dist/scripts/bulkStatusUpdates/performUpdate.js +116 -0
  294. package/{scripts/bulkStatusUpdates/performUpdateForGroup.js → dist/scripts/bulkStatusUpdates/performUpdateForGroup.cjs} +1 -2
  295. package/dist/scripts/bulkStatusUpdates/performUpdateForStatus.js +141 -0
  296. package/dist/scripts/change/changeVideoAspectTo.js +34 -0
  297. package/dist/scripts/change/setUseNewVersion.cjs +22 -0
  298. package/dist/scripts/changeCommunityGroupcount.js +30 -0
  299. package/dist/scripts/changeCommunityPostCount.js +30 -0
  300. package/dist/scripts/changeGroupPostCount.js +30 -0
  301. package/dist/scripts/changeLanguage.js +50 -0
  302. package/dist/scripts/changeOfficalStatus.js +30 -0
  303. package/{scripts/cleanups/deleteAnonNotifications.js → dist/scripts/cleanups/deleteAnonNotifications.cjs} +1 -1
  304. package/dist/scripts/cleanups/deleteLinkGroupsWithDeletedCommunities.js +62 -0
  305. package/dist/scripts/cleanups/deleteYearOldNotifications.cjs +72 -0
  306. package/dist/scripts/cleanups/removeAllUsersFromHiddenPublicGroup.js +43 -0
  307. package/dist/scripts/clearAllEndorsementInGroup.js +50 -0
  308. package/dist/scripts/cloning/clearUsersForCommunitiesFromUrl.js +129 -0
  309. package/dist/scripts/cloning/cloneFromUrlScript.js +65 -0
  310. package/dist/scripts/cloning/cloneWBFromUrlScriptAndCreateLinks.js +140 -0
  311. package/dist/scripts/cloning/cloneWBFromUrlScriptNoUsersOrPoints.js +140 -0
  312. package/dist/scripts/cloning/cloneWBSerbianFromUrlScriptAndCreateLinks.js +131 -0
  313. package/dist/scripts/cloning/copyCommunityConfigAndTranslationsFromURL.js +173 -0
  314. package/dist/scripts/cloning/copyCommunityOneGroupToDomainNoUsersNoEndorsements.js +18 -0
  315. package/dist/scripts/cloning/copyCommunityToDomainNoUsersNoEndorsements.js +17 -0
  316. package/dist/scripts/cloning/copyCommunityToDomainWithEverything.js +17 -0
  317. package/dist/scripts/cloning/copyCommunityToDomainWithOnlyGroups.js +26 -0
  318. package/dist/scripts/cloning/copyGroupConfigAndTranslationsFromURL.js +205 -0
  319. package/dist/scripts/cloning/copyPostToGroupOld.js +397 -0
  320. package/dist/scripts/cloning/copyPostVideosFromURL.js +236 -0
  321. package/dist/scripts/cloning/copyPostWithOutAnyVotingOrActivities.js +17 -0
  322. package/dist/scripts/cloning/deepCloneSerbianWBFromUrlScriptAndCreateLinks.js +131 -0
  323. package/dist/scripts/cloning/deepCloneWBFromUrlScriptAndCreateLinks.js +139 -0
  324. package/dist/scripts/cloning/setAdminsFromURL.js +161 -0
  325. package/dist/scripts/cloning/setExternalIdsFromURL.js +129 -0
  326. package/dist/scripts/countCommunity.js +291 -0
  327. package/dist/scripts/countCommunityUsers.js +152 -0
  328. package/dist/scripts/countDelayedNotifications.js +18 -0
  329. package/dist/scripts/countGroup.js +246 -0
  330. package/dist/scripts/countStuff.js +67 -0
  331. package/dist/scripts/countUniqueVotersInAGroup.js +48 -0
  332. package/dist/scripts/createInvitesAndShow.js +75 -0
  333. package/dist/scripts/database/sync_database.js +14 -0
  334. package/dist/scripts/database/sync_dev_database.js +17 -0
  335. package/dist/scripts/debugNotifications.js +58 -0
  336. package/dist/scripts/deleteAllNewsFeeds.js +10 -0
  337. package/dist/scripts/deleteCategory.js +13 -0
  338. package/dist/scripts/deleteOldAppActivities.js +40 -0
  339. package/dist/scripts/deletePostContactDataForCommunity.js +53 -0
  340. package/dist/scripts/destroy/destroy_all_but_one_domain.js +1026 -0
  341. package/dist/scripts/displayAuthorForPost.js +16 -0
  342. package/dist/scripts/endorsementFraudDetection/analyseEndorsementsForCommunity.js +183 -0
  343. package/dist/scripts/endorsementFraudDetection/bulkDeleteDuplicateEndorsmentsFromUrl.js +208 -0
  344. package/dist/scripts/exportAllStatusChanges.js +36 -0
  345. package/dist/scripts/exportClientAcitivity.js +36 -0
  346. package/dist/scripts/exportEndorsementsForCommunity.js +79 -0
  347. package/dist/scripts/exportPointQualitiesForCommunity.js +84 -0
  348. package/dist/scripts/exportPostsAndPointsForCommunity.js +147 -0
  349. package/dist/scripts/exportPostsDataSetForDomain.js +244 -0
  350. package/dist/scripts/exportPostsForGroup.js +173 -0
  351. package/dist/scripts/exportRatingsForPost.js +15 -0
  352. package/dist/scripts/exportUserEndorsementsWithUserAnalysis.js +123 -0
  353. package/dist/scripts/exportUsersForCommunity.js +24 -0
  354. package/dist/scripts/exportUsersForDomain.js +24 -0
  355. package/dist/scripts/exportUsersForGroup.js +24 -0
  356. package/dist/scripts/exports/ratingDistribution.js +71 -0
  357. package/dist/scripts/exports/whoEndorsedWhatByCommunity.js +56 -0
  358. package/dist/scripts/findUnusedClientImports.js +56 -0
  359. package/dist/scripts/fixAllPostPointCounts.js +22 -0
  360. package/dist/scripts/fixAnonNotificationsSettings.js +48 -0
  361. package/dist/scripts/fixCountKopavogur.js +9 -0
  362. package/dist/scripts/fixEndorsementsAfterCopyPostToGroup.js +190 -0
  363. package/dist/scripts/fixExternalUserId.js +24 -0
  364. package/dist/scripts/fixGroupAccess.js +16 -0
  365. package/dist/scripts/fixGroupIdeasAndPointsCount.js +49 -0
  366. package/dist/scripts/fixNotificationSettings.js +39 -0
  367. package/dist/scripts/fixSurveyRadioBakedInSubCodes.js +64 -0
  368. package/dist/scripts/fixWrongUserIdForStatusUpdates.js +49 -0
  369. package/dist/scripts/gallery/exportGalleryData.js +40 -0
  370. package/dist/scripts/gallery/importGalleryForCommunity.js +168 -0
  371. package/dist/scripts/gallery/readJsonAndDownloadImagesVersion2.js +55 -0
  372. package/dist/scripts/gallery/refreshAcApiPostIdsForCommunity.js +58 -0
  373. package/dist/scripts/genderAnalysis.js +63 -0
  374. package/dist/scripts/genderAnalysisByStatus.js +62 -0
  375. package/dist/scripts/importAllLocalesFromLocalFolders.js +55 -0
  376. package/dist/scripts/importDomain.js +1652 -0
  377. package/dist/scripts/keys/addOidcToDomain.cjs +61 -0
  378. package/dist/scripts/landUseGame/export3Ddata.js +162 -0
  379. package/dist/scripts/listLanguagesForGroup.js +54 -0
  380. package/dist/scripts/loadTestCreateDummyContentForGroup.js +27 -0
  381. package/dist/scripts/makeRecursiveMapData.js +103 -0
  382. package/dist/scripts/mapping/community_map_csv.js +145 -0
  383. package/dist/scripts/moveCommunityToDomain.js +22 -0
  384. package/dist/scripts/moveGroupToCommunity.js +23 -0
  385. package/dist/scripts/movePostToGroup.js +101 -0
  386. package/dist/scripts/movePostsToGroupsRecountGroupFromUrl.js +297 -0
  387. package/dist/scripts/oldMovePostToGroup.js +153 -0
  388. package/dist/scripts/processCsvForPdfUrls.js +37 -0
  389. package/dist/scripts/processCsvForTranslationAndToxicity.js +125 -0
  390. package/dist/scripts/recount/recount_recursive_communities.js +125 -0
  391. package/dist/scripts/recountALLCommunityGroupCounts.js +37 -0
  392. package/dist/scripts/recountAll.js +97 -0
  393. package/dist/scripts/recountCommunitesFromUrl.js +58 -0
  394. package/dist/scripts/recountCommunity.js +19 -0
  395. package/dist/scripts/recountGroup.js +218 -0
  396. package/dist/scripts/recountGroupNoUserChange.js +219 -0
  397. package/dist/scripts/resetAllEndorsementsForGroup.js +57 -0
  398. package/dist/scripts/resetEnTranslationForGroup.js +45 -0
  399. package/dist/scripts/setAdminOnAll.cjs +107 -0
  400. package/{scripts/change → dist/scripts}/setDomainAdmin.cjs +0 -2
  401. package/dist/scripts/setDomainLocales.js +33 -0
  402. package/dist/scripts/setEarlQuestionIdOnGroup.cjs +29 -0
  403. package/dist/scripts/setLanguageOnGroupCommunitesFromUrl.js +86 -0
  404. package/dist/scripts/setMemberOfAll.js +101 -0
  405. package/dist/scripts/setNewUserForContentOfCommunity.js +189 -0
  406. package/dist/scripts/setOfficialStatusOnAllPostsForCommunity.js +35 -0
  407. package/dist/scripts/setUserOnAll.js +101 -0
  408. package/dist/scripts/showCategoryForGroup.js +18 -0
  409. package/dist/scripts/showOldActivityTypes.js +14 -0
  410. package/dist/scripts/showPostsMissingCategoryForGroup.js +17 -0
  411. package/dist/scripts/showStatuses.js +17 -0
  412. package/dist/scripts/showUniqueVotersInCommunity.js +61 -0
  413. package/dist/scripts/showUserAgentsAndIpsForEmails.js +66 -0
  414. package/dist/scripts/simpleExportForGroupsForCommunity.js +46 -0
  415. package/dist/scripts/simpleExportForPointsForCommunity.js +82 -0
  416. package/dist/scripts/simpleExportForPostsForCommunity.js +61 -0
  417. package/dist/scripts/testForEndorsments.js +21 -0
  418. package/dist/scripts/undeleteGroupAndAllContent.js +151 -0
  419. package/dist/scripts/undeletePost.js +135 -0
  420. package/dist/scripts/unlinkSsn.js +23 -0
  421. package/dist/scripts/updateFromAlthingi.js +303 -0
  422. package/dist/server.js +3 -0
  423. package/dist/utils/airbrake.cjs +17 -0
  424. package/dist/utils/cjsCodeReview.js +99 -0
  425. package/dist/utils/community_mapping_tools.cjs +124 -0
  426. package/dist/utils/copy_utils.cjs +1399 -0
  427. package/dist/utils/docx_utils.cjs +464 -0
  428. package/dist/utils/export_utils.cjs +491 -0
  429. package/dist/utils/i18n.cjs +17 -0
  430. package/dist/utils/is_valid_db_id.cjs +28 -0
  431. package/dist/utils/logger.cjs +25 -0
  432. package/dist/utils/loggerTs.js +26 -0
  433. package/dist/utils/manifest_generator.cjs +104 -0
  434. package/dist/utils/parse_domain.cjs +16 -0
  435. package/dist/utils/recount_utils.cjs +415 -0
  436. package/dist/utils/sharing_parameters.cjs +111 -0
  437. package/dist/utils/sitemap_generator.cjs +286 -0
  438. package/dist/utils/to_json.cjs +14 -0
  439. package/dist/utils/ypLanguages.js +747 -0
  440. package/dist/webSockets.js +77 -0
  441. package/package.json +46 -44
  442. package/server.d.ts +104 -2
  443. package/utils/copy_utils.cjs +7 -1
  444. package/active-citizen/engine/allOurIdeas/aiHelper.d.ts +0 -21
  445. package/active-citizen/engine/allOurIdeas/aiHelper.d.ts.map +0 -1
  446. package/active-citizen/engine/allOurIdeas/explainAnswersAssistant.d.ts.map +0 -1
  447. package/active-citizen/engine/allOurIdeas/iconGenerator.d.ts +0 -12
  448. package/active-citizen/engine/allOurIdeas/iconGenerator.d.ts.map +0 -1
  449. package/active-citizen/engine/analytics/export_anon_community_activities.d.ts.map +0 -1
  450. package/active-citizen/engine/analytics/importer.d.ts.map +0 -1
  451. package/active-citizen/engine/old/exporters/categories_dataset.d.ts.map +0 -1
  452. package/active-citizen/engine/old/exporters/dataset_tools.d.ts.map +0 -1
  453. package/active-citizen/engine/old/exporters/sentiment_dataset.d.ts.map +0 -1
  454. package/active-citizen/engine/reports/xls_all_our_ideas_export.js +0 -141
  455. package/active-citizen/llms/baseChatBot.d.ts +0 -51
  456. package/active-citizen/llms/baseChatBot.d.ts.map +0 -1
  457. package/active-citizen/llms/collectionImageGenerator.js +0 -357
  458. package/active-citizen/llms/llmTranslation.d.ts +0 -24
  459. package/active-citizen/llms/llmTranslation.d.ts.map +0 -1
  460. package/active-citizen/scripts/fix_old_delayed_notifications.d.ts.map +0 -1
  461. package/active-citizen/scripts/kue_status.d.ts.map +0 -1
  462. package/active-citizen/scripts/kue_watch_stuck_jobs.d.ts.map +0 -1
  463. package/active-citizen/scripts/translation_clear_language.d.ts.map +0 -1
  464. package/active-citizen/scripts/translation_delete.d.ts.map +0 -1
  465. package/active-citizen/scripts/translation_replace_text_from_url.d.ts.map +0 -1
  466. package/active-citizen/scripts/translation_update.d.ts.map +0 -1
  467. package/active-citizen/scripts/translations_list.d.ts.map +0 -1
  468. package/active-citizen/utils/airbrake.d.ts.map +0 -1
  469. package/active-citizen/utils/updateAllLocalesFromEn.d.ts +0 -21
  470. package/active-citizen/utils/updateAllLocalesFromEn.d.ts.map +0 -1
  471. package/active-citizen/utils/updateLocaleFolders.d.ts +0 -2
  472. package/active-citizen/utils/updateLocaleFolders.d.ts.map +0 -1
  473. package/active-citizen/workers/cloudflare/voiceSession/worker.js +0 -213
  474. package/active-citizen/workers/generativeAi.d.ts.map +0 -1
  475. package/agents/assistants/agentAssistantOld.js +0 -863
  476. package/agents/assistants/modes/agentConfigurationMode.js +0 -63
  477. package/agents/assistants/modes/agentOperationsMode.js +0 -195
  478. package/agents/assistants/modes/commonTools.js +0 -58
  479. package/agents/assistants/modes/directConversationMode.js +0 -14
  480. package/agents/assistants/modes/toolHandlers/accountHandlers.js +0 -46
  481. package/agents/assistants/modes/toolHandlers/commonHandlers.js +0 -57
  482. package/agents/assistants/modes/toolHandlers/commonTools.js +0 -58
  483. package/agents/assistants/modes/toolHandlers/loginHandlers.js +0 -46
  484. package/agents/assistants/modes/toolHandlers/subscriptionHandlers.js +0 -469
  485. package/agents/assistants/modes/tools/agentConnectionTools.js +0 -326
  486. package/agents/assistants/modes/tools/commonHandlers.js +0 -57
  487. package/agents/assistants/modes/tools/loginHandlers.js +0 -46
  488. package/agents/assistants/modes/tools/subscriptionHandlers.js +0 -469
  489. package/agents/controllers/assistantController.js +0 -243
  490. package/agents/managers/workflowManager.js +0 -76
  491. package/agents/models/testData/setupConfig.js +0 -140
  492. package/agents/models/workflow.js +0 -53
  493. package/agents/subscriptionManager.js +0 -218
  494. package/app.d.ts +0 -40
  495. package/app.d.ts.map +0 -1
  496. package/bot_control.d.ts.map +0 -1
  497. package/publish.d.ts.map +0 -1
  498. package/repack.d.ts.map +0 -1
  499. package/scripts/addRatingUsersToGroup.d.ts.map +0 -1
  500. package/scripts/addUserToOrganization.d.ts.map +0 -1
  501. package/scripts/analyseRatingsForCommunity.d.ts.map +0 -1
  502. package/scripts/analyzeAndFixBrokenPointUsers.d.ts.map +0 -1
  503. package/scripts/analyzeEndorsementsByCountry.d.ts.map +0 -1
  504. package/scripts/analyzePostsForCommunity.d.ts.map +0 -1
  505. package/scripts/bulkStatusUpdates/listUpdates.d.ts.map +0 -1
  506. package/scripts/bulkStatusUpdates/mergeLatestPostsToUpdate.d.ts.map +0 -1
  507. package/scripts/bulkStatusUpdates/performUpdate.d.ts.map +0 -1
  508. package/scripts/bulkStatusUpdates/performUpdateForGroup.d.ts.map +0 -1
  509. package/scripts/bulkStatusUpdates/performUpdateForStatus.d.ts.map +0 -1
  510. package/scripts/change/changeVideoAspectTo.d.ts.map +0 -1
  511. package/scripts/changeCommunityGroupcount.d.ts.map +0 -1
  512. package/scripts/changeCommunityPostCount.d.ts.map +0 -1
  513. package/scripts/changeGroupPostCount.d.ts.map +0 -1
  514. package/scripts/changeLanguage.d.ts.map +0 -1
  515. package/scripts/changeOfficalStatus.d.ts.map +0 -1
  516. package/scripts/cleanups/deleteAnonNotifications.d.ts.map +0 -1
  517. package/scripts/cleanups/deleteLinkGroupsWithDeletedCommunities.d.ts.map +0 -1
  518. package/scripts/cleanups/removeAllUsersFromHiddenPublicGroup.d.ts.map +0 -1
  519. package/scripts/clearAllEndorsementInGroup.d.ts.map +0 -1
  520. package/scripts/cloning/clearUsersForCommunitiesFromUrl.d.ts.map +0 -1
  521. package/scripts/cloning/cloneFromUrlScript.d.ts.map +0 -1
  522. package/scripts/cloning/cloneWBFromUrlScriptAndCreateLinks.d.ts.map +0 -1
  523. package/scripts/cloning/cloneWBFromUrlScriptNoUsersOrPoints.d.ts.map +0 -1
  524. package/scripts/cloning/cloneWBSerbianFromUrlScriptAndCreateLinks.d.ts.map +0 -1
  525. package/scripts/cloning/copyCommunityConfigAndTranslationsFromURL.d.ts.map +0 -1
  526. package/scripts/cloning/copyCommunityOneGroupToDomainNoUsersNoEndorsements.d.ts.map +0 -1
  527. package/scripts/cloning/copyCommunityToDomainNoUsersNoEndorsements.d.ts.map +0 -1
  528. package/scripts/cloning/copyCommunityToDomainWithEverything.d.ts.map +0 -1
  529. package/scripts/cloning/copyCommunityToDomainWithOnlyGroups.d.ts.map +0 -1
  530. package/scripts/cloning/copyGroupConfigAndTranslationsFromURL.d.ts.map +0 -1
  531. package/scripts/cloning/copyPostToGroupOld.d.ts.map +0 -1
  532. package/scripts/cloning/copyPostVideosFromURL.d.ts.map +0 -1
  533. package/scripts/cloning/copyPostWithOutAnyVotingOrActivities.d.ts.map +0 -1
  534. package/scripts/cloning/deepCloneSerbianWBFromUrlScriptAndCreateLinks.d.ts.map +0 -1
  535. package/scripts/cloning/deepCloneWBFromUrlScriptAndCreateLinks.d.ts.map +0 -1
  536. package/scripts/cloning/setAdminsFromURL.d.ts.map +0 -1
  537. package/scripts/cloning/setExternalIdsFromURL.d.ts.map +0 -1
  538. package/scripts/countCommunity.d.ts.map +0 -1
  539. package/scripts/countCommunityUsers.d.ts.map +0 -1
  540. package/scripts/countDelayedNotifications.d.ts.map +0 -1
  541. package/scripts/countGroup.d.ts.map +0 -1
  542. package/scripts/countStuff.d.ts.map +0 -1
  543. package/scripts/countUniqueVotersInAGroup.d.ts.map +0 -1
  544. package/scripts/createInvitesAndShow.d.ts.map +0 -1
  545. package/scripts/database/seedTestAiModels.js +0 -64
  546. package/scripts/database/sync_database.d.ts.map +0 -1
  547. package/scripts/database/sync_dev_database.d.ts.map +0 -1
  548. package/scripts/debugNotifications.d.ts.map +0 -1
  549. package/scripts/deleteAllNewsFeeds.d.ts.map +0 -1
  550. package/scripts/deleteCategory.d.ts.map +0 -1
  551. package/scripts/deleteOldAppActivities.d.ts.map +0 -1
  552. package/scripts/deletePostContactDataForCommunity.d.ts.map +0 -1
  553. package/scripts/destroy/destroy_all_but_one_domain.d.ts.map +0 -1
  554. package/scripts/displayAuthorForPost.d.ts.map +0 -1
  555. package/scripts/endorsementFraudDetection/analyseEndorsementsForCommunity.d.ts.map +0 -1
  556. package/scripts/endorsementFraudDetection/bulkDeleteDuplicateEndorsmentsFromUrl.d.ts.map +0 -1
  557. package/scripts/exportAllStatusChanges.d.ts.map +0 -1
  558. package/scripts/exportClientAcitivity.d.ts.map +0 -1
  559. package/scripts/exportEndorsementsForCommunity.d.ts.map +0 -1
  560. package/scripts/exportPointQualitiesForCommunity.d.ts.map +0 -1
  561. package/scripts/exportPostsAndPointsForCommunity.d.ts.map +0 -1
  562. package/scripts/exportPostsDataSetForDomain.d.ts.map +0 -1
  563. package/scripts/exportPostsForGroup.d.ts.map +0 -1
  564. package/scripts/exportRatingsForPost.d.ts.map +0 -1
  565. package/scripts/exportUserEndorsementsWithUserAnalysis.d.ts.map +0 -1
  566. package/scripts/exportUsersForCommunity.d.ts.map +0 -1
  567. package/scripts/exportUsersForDomain.d.ts.map +0 -1
  568. package/scripts/exportUsersForGroup.d.ts.map +0 -1
  569. package/scripts/exports/ratingDistribution.d.ts.map +0 -1
  570. package/scripts/exports/whoEndorsedWhatByCommunity.d.ts.map +0 -1
  571. package/scripts/findUnusedClientImports.d.ts.map +0 -1
  572. package/scripts/fixAllPostPointCounts.d.ts.map +0 -1
  573. package/scripts/fixAnonNotificationsSettings.d.ts.map +0 -1
  574. package/scripts/fixCountKopavogur.d.ts.map +0 -1
  575. package/scripts/fixEndorsementsAfterCopyPostToGroup.d.ts.map +0 -1
  576. package/scripts/fixExternalUserId.d.ts.map +0 -1
  577. package/scripts/fixGroupAccess.d.ts.map +0 -1
  578. package/scripts/fixGroupIdeasAndPointsCount.d.ts.map +0 -1
  579. package/scripts/fixNotificationSettings.d.ts.map +0 -1
  580. package/scripts/fixSurveyRadioBakedInSubCodes.d.ts.map +0 -1
  581. package/scripts/fixWrongUserIdForStatusUpdates.d.ts.map +0 -1
  582. package/scripts/gallery/exportGalleryData.d.ts.map +0 -1
  583. package/scripts/gallery/importGalleryForCommunity.d.ts.map +0 -1
  584. package/scripts/gallery/readJsonAndDownloadImagesVersion2.d.ts.map +0 -1
  585. package/scripts/gallery/refreshAcApiPostIdsForCommunity.d.ts.map +0 -1
  586. package/scripts/genderAnalysis.d.ts.map +0 -1
  587. package/scripts/genderAnalysisByStatus.d.ts.map +0 -1
  588. package/scripts/importAllLocalesFromLocalFolders.d.ts.map +0 -1
  589. package/scripts/importDomain.d.ts.map +0 -1
  590. package/scripts/landUseGame/export3Ddata.d.ts.map +0 -1
  591. package/scripts/listLanguagesForGroup.d.ts.map +0 -1
  592. package/scripts/loadTestCreateDummyContentForGroup.d.ts.map +0 -1
  593. package/scripts/makeRecursiveMapData.d.ts.map +0 -1
  594. package/scripts/mapping/community_map_csv.d.ts.map +0 -1
  595. package/scripts/moveCommunityToDomain.d.ts.map +0 -1
  596. package/scripts/moveGroupToCommunity.d.ts.map +0 -1
  597. package/scripts/movePostToGroup.d.ts.map +0 -1
  598. package/scripts/movePostsToGroupsRecountGroupFromUrl.d.ts.map +0 -1
  599. package/scripts/oldMovePostToGroup.d.ts.map +0 -1
  600. package/scripts/processCsvForPdfUrls.d.ts.map +0 -1
  601. package/scripts/processCsvForTranslationAndToxicity.d.ts.map +0 -1
  602. package/scripts/recount/recount_recursive_communities.d.ts.map +0 -1
  603. package/scripts/recountALLCommunityGroupCounts.d.ts.map +0 -1
  604. package/scripts/recountAll.d.ts.map +0 -1
  605. package/scripts/recountCommunitesFromUrl.d.ts.map +0 -1
  606. package/scripts/recountCommunity.d.ts.map +0 -1
  607. package/scripts/recountGroup.d.ts.map +0 -1
  608. package/scripts/recountGroupNoUserChange.d.ts.map +0 -1
  609. package/scripts/resetAllEndorsementsForGroup.d.ts.map +0 -1
  610. package/scripts/resetEnTranslationForGroup.d.ts.map +0 -1
  611. package/scripts/setDomainLocales.d.ts.map +0 -1
  612. package/scripts/setLanguageOnGroupCommunitesFromUrl.d.ts.map +0 -1
  613. package/scripts/setMemberOfAll.d.ts.map +0 -1
  614. package/scripts/setNewUserForContentOfCommunity.d.ts.map +0 -1
  615. package/scripts/setOfficialStatusOnAllPostsForCommunity.d.ts.map +0 -1
  616. package/scripts/setUserOnAll.d.ts.map +0 -1
  617. package/scripts/showCategoryForGroup.d.ts.map +0 -1
  618. package/scripts/showOldActivityTypes.d.ts.map +0 -1
  619. package/scripts/showPostsMissingCategoryForGroup.d.ts.map +0 -1
  620. package/scripts/showStatuses.d.ts.map +0 -1
  621. package/scripts/showUniqueVotersInCommunity.d.ts.map +0 -1
  622. package/scripts/showUserAgentsAndIpsForEmails.d.ts.map +0 -1
  623. package/scripts/simpleExportForGroupsForCommunity.d.ts.map +0 -1
  624. package/scripts/simpleExportForPointsForCommunity.d.ts.map +0 -1
  625. package/scripts/simpleExportForPostsForCommunity.d.ts.map +0 -1
  626. package/scripts/testForEndorsments.d.ts.map +0 -1
  627. package/scripts/undeleteGroupAndAllContent.d.ts.map +0 -1
  628. package/scripts/undeletePost.d.ts.map +0 -1
  629. package/scripts/unlinkSsn.d.ts.map +0 -1
  630. package/scripts/updateFromAlthingi.d.ts.map +0 -1
  631. package/server.d.ts.map +0 -1
  632. package/utils/copyGroup.js +0 -246
  633. package/utils/loggerTs.d.ts +0 -4
  634. package/utils/loggerTs.d.ts.map +0 -1
  635. package/utils/ypLanguages.d.ts +0 -18
  636. package/utils/ypLanguages.d.ts.map +0 -1
  637. /package/{agents/tools/updateCommunityWorkflow.js → dist/active-citizen/llms/imageGeneration/iImageGenerator.js} +0 -0
  638. /package/{migrations/270724_createUsersAndAdminsForClasses.cjs → dist/migrations/zzzz_createUsersAndAdminsForClasses.cjs} +0 -0
@@ -0,0 +1,1341 @@
1
+ "use strict";
2
+ var express = require('express');
3
+ var router = express.Router();
4
+ var models = require("../models/index.cjs");
5
+ var auth = require('../authorization.cjs');
6
+ var log = require('../utils/logger.cjs');
7
+ var toJson = require('../utils/to_json.cjs');
8
+ var _ = require('lodash');
9
+ var async = require('async');
10
+ var queue = require('../active-citizen/workers/queue.cjs');
11
+ var performSingleModerationAction = require('../active-citizen/engine/moderation/process_moderation_items.cjs').performSingleModerationAction;
12
+ const getAllModeratedItemsByDomain = require('../active-citizen/engine/moderation/get_moderation_items.cjs').getAllModeratedItemsByDomain;
13
+ const getLoginsExportDataForDomain = require('../utils/export_utils.cjs').getLoginsExportDataForDomain;
14
+ var sanitizeFilename = require("sanitize-filename");
15
+ var moment = require('moment');
16
+ const { plausibleStatsProxy } = require("../active-citizen/engine/analytics/plausible/manager.cjs");
17
+ const { countAllModeratedItemsByDomain } = require("../active-citizen/engine/moderation/get_moderation_items.cjs");
18
+ const { isValidDbId } = require("../utils/is_valid_db_id.cjs");
19
+ const getFromAnalyticsApi = require('../active-citizen/engine/analytics/manager.cjs').getFromAnalyticsApi;
20
+ const triggerSimilaritiesTraining = require('../active-citizen/engine/analytics/manager.cjs').triggerSimilaritiesTraining;
21
+ const sendBackAnalyticsResultsOrError = require('../active-citizen/engine/analytics/manager.cjs').sendBackAnalyticsResultsOrError;
22
+ const countModelRowsByTimePeriod = require('../active-citizen/engine/analytics/statsCalc.cjs').countModelRowsByTimePeriod;
23
+ const getDomainIncludes = require('../active-citizen/engine/analytics/statsCalc.cjs').getDomainIncludes;
24
+ const getPointDomainIncludes = require('../active-citizen/engine/analytics/statsCalc.cjs').getPointDomainIncludes;
25
+ const getParsedSimilaritiesContent = require('../active-citizen/engine/analytics/manager.cjs').getParsedSimilaritiesContent;
26
+ const crypto = require('crypto');
27
+ var sendDomainOrError = function (res, domain, context, user, error, errorStatus) {
28
+ if (error || !domain) {
29
+ if (errorStatus === 404 || (error && error.message && error.message.indexOf("invalid input syntax for type integer") > -1)) {
30
+ log.warn("Domain Not Found", { context: context, domain: toJson(domain), user: toJson(user), err: error,
31
+ errorStatus: 404 });
32
+ errorStatus = 404;
33
+ }
34
+ else {
35
+ log.error("Domain Error", { context: context, domain: toJson(domain), user: toJson(user), err: error,
36
+ errorStatus: errorStatus ? errorStatus : 500 });
37
+ }
38
+ if (errorStatus) {
39
+ res.sendStatus(errorStatus);
40
+ }
41
+ else {
42
+ res.sendStatus(500);
43
+ }
44
+ }
45
+ else {
46
+ res.send(domain);
47
+ }
48
+ };
49
+ var truthValueFromBody = function (bodyParameter) {
50
+ return (bodyParameter && bodyParameter !== "");
51
+ };
52
+ var getAvailableCommunityFolders = function (req, domainId, done) {
53
+ let adminCommunities = [];
54
+ async.series([
55
+ function (seriesCallback) {
56
+ if (req.user) {
57
+ async.parallel([
58
+ function (parallelCallback) {
59
+ models.Community.findAll({
60
+ where: {
61
+ is_community_folder: true,
62
+ domain_id: domainId
63
+ },
64
+ attributes: ['id', 'name'],
65
+ include: [
66
+ {
67
+ model: models.User,
68
+ as: 'CommunityAdmins',
69
+ attributes: ['id'],
70
+ required: true,
71
+ where: {
72
+ id: req.user.id
73
+ }
74
+ }
75
+ ]
76
+ }).then(function (communities) {
77
+ adminCommunities = communities;
78
+ parallelCallback();
79
+ }).catch(function (error) {
80
+ parallelCallback(error);
81
+ });
82
+ }
83
+ ], function (error) {
84
+ seriesCallback(error);
85
+ });
86
+ }
87
+ else {
88
+ seriesCallback();
89
+ }
90
+ }
91
+ ], function (error) {
92
+ if (!error) {
93
+ done(error, adminCommunities);
94
+ }
95
+ else {
96
+ done(error);
97
+ }
98
+ });
99
+ };
100
+ var getDomain = function (req, domainId, done) {
101
+ var domain;
102
+ var attributes = null;
103
+ async.series([
104
+ function (seriesCallback) {
105
+ auth.hasDomainAdmin(domainId, req, function (error, isAdmin) {
106
+ if (!isAdmin) {
107
+ attributes = models.Domain.defaultAttributesPublic;
108
+ }
109
+ seriesCallback(error);
110
+ });
111
+ },
112
+ function (seriesCallback) {
113
+ models.Domain.findOne({
114
+ where: { id: domainId },
115
+ attributes: attributes,
116
+ order: [
117
+ [{ model: models.Image, as: 'DomainLogoImages' }, 'created_at', 'asc'],
118
+ [{ model: models.Image, as: 'DomainHeaderImages' }, 'created_at', 'asc'],
119
+ [{ model: models.Video, as: "DomainLogoVideos" }, 'updated_at', 'desc'],
120
+ [{ model: models.Video, as: "DomainLogoVideos" }, { model: models.Image, as: 'VideoImages' }, 'updated_at', 'asc']
121
+ ],
122
+ include: [
123
+ {
124
+ model: models.Image,
125
+ as: 'DomainLogoImages',
126
+ attributes: models.Image.defaultAttributesPublic,
127
+ required: false
128
+ },
129
+ {
130
+ model: models.Video,
131
+ as: 'DomainLogoVideos',
132
+ attributes: ['id', 'formats', 'viewable', 'public_meta'],
133
+ required: false,
134
+ include: [
135
+ {
136
+ model: models.Image,
137
+ as: 'VideoImages',
138
+ attributes: ["formats", 'updated_at'],
139
+ required: false
140
+ },
141
+ ]
142
+ },
143
+ {
144
+ model: models.Image,
145
+ as: 'DomainHeaderImages',
146
+ attributes: models.Image.defaultAttributesPublic,
147
+ required: false
148
+ }
149
+ ]
150
+ }).then(function (domainIn) {
151
+ domain = domainIn;
152
+ if (domain) {
153
+ models.Community.findAll({
154
+ where: {
155
+ domain_id: domain.id,
156
+ access: {
157
+ $ne: models.Community.ACCESS_SECRET
158
+ },
159
+ configuration: {
160
+ [models.Sequelize.Op.or]: [
161
+ {
162
+ customBackURL: {
163
+ [models.Sequelize.Op.is]: null
164
+ }
165
+ },
166
+ {
167
+ alwaysShowOnDomainPage: true
168
+ }
169
+ ]
170
+ },
171
+ $or: [
172
+ {
173
+ counter_users: {
174
+ $gt: process.env.MINIMUM_USERS_FOR_COMMUNITY_TO_SHOW ? parseInt(process.env.MINIMUM_USERS_FOR_COMMUNITY_TO_SHOW) : 21
175
+ },
176
+ },
177
+ {
178
+ status: "featured"
179
+ },
180
+ {
181
+ is_community_folder: {
182
+ $ne: false
183
+ }
184
+ }
185
+ ],
186
+ status: {
187
+ $ne: 'hidden'
188
+ },
189
+ in_community_folder_id: null
190
+ },
191
+ limit: 500,
192
+ attributes: models.Community.defaultAttributesPublic,
193
+ order: [
194
+ ['counter_users', 'desc'],
195
+ [{ model: models.Image, as: 'CommunityLogoImages' }, 'created_at', 'asc']
196
+ ],
197
+ include: [
198
+ {
199
+ model: models.Image,
200
+ as: 'CommunityLogoImages',
201
+ attributes: models.Image.defaultAttributesPublic,
202
+ required: false
203
+ },
204
+ {
205
+ model: models.Community,
206
+ as: 'CommunityFolders',
207
+ attributes: ['id', 'name', 'counter_users', 'counter_posts', 'counter_groups'],
208
+ required: false,
209
+ },
210
+ {
211
+ model: models.Domain,
212
+ as: 'Domain',
213
+ attributes: ['id', 'configuration', 'name'],
214
+ required: false
215
+ },
216
+ {
217
+ model: models.Image,
218
+ as: 'CommunityHeaderImages',
219
+ attributes: models.Image.defaultAttributesPublic,
220
+ required: false
221
+ }
222
+ ]
223
+ }).then(function (communities) {
224
+ log.info('Domain Viewed', { domainId: domain ? domain.id : -1, userId: req.user ? req.user.id : -1 });
225
+ if (req.ypDomain && req.ypDomain.secret_api_keys &&
226
+ req.ypDomain.secret_api_keys.saml && req.ypDomain.secret_api_keys.saml.entryPoint &&
227
+ req.ypDomain.secret_api_keys.saml.entryPoint.length > 6) {
228
+ domain.dataValues.samlLoginProvided = true;
229
+ }
230
+ if (req.ypDomain && req.ypDomain.secret_api_keys &&
231
+ req.ypDomain.secret_api_keys.facebook && req.ypDomain.secret_api_keys.facebook.client_secret &&
232
+ req.ypDomain.secret_api_keys.facebook.client_secret.length > 6) {
233
+ domain.dataValues.facebookLoginProvided = true;
234
+ }
235
+ if (req.ypDomain && process.env.GOOGLE_MAPS_API_KEY) {
236
+ domain.dataValues.googleMapsApiKey = process.env.GOOGLE_MAPS_API_KEY;
237
+ }
238
+ if (req.ypDomain && process.env.ZIGGEO_ENABLED) {
239
+ domain.dataValues.ziggeoEnabled = process.env.ZIGGEO_ENABLED;
240
+ }
241
+ if (req.ypDomain && process.env.OPENAI_API_KEY) {
242
+ domain.dataValues.hasLlm = true;
243
+ }
244
+ domain.dataValues.Communities = communities;
245
+ if (process.env.LOGIN_CALLBACK_CUSTOM_HOSTNAME) {
246
+ domain.dataValues.loginCallbackCustomHostName = process.env.LOGIN_CALLBACK_CUSTOM_HOSTNAME;
247
+ }
248
+ seriesCallback(null);
249
+ return null;
250
+ }).catch(function (error) {
251
+ seriesCallback(error);
252
+ });
253
+ }
254
+ else {
255
+ seriesCallback("Not found");
256
+ }
257
+ return null;
258
+ }).catch(function (error) {
259
+ seriesCallback(error);
260
+ });
261
+ },
262
+ function (seriesCallback) {
263
+ if (req.user && domain) {
264
+ var adminCommunities, userCommunities;
265
+ async.parallel([
266
+ function (parallelCallback) {
267
+ models.Community.findAll({
268
+ where: {
269
+ domain_id: domain.id,
270
+ in_community_folder_id: null,
271
+ configuration: {
272
+ [models.Sequelize.Op.or]: [
273
+ {
274
+ customBackURL: {
275
+ [models.Sequelize.Op.is]: null
276
+ }
277
+ },
278
+ {
279
+ alwaysShowOnDomainPage: true
280
+ }
281
+ ]
282
+ },
283
+ },
284
+ limit: 500,
285
+ attributes: models.Community.defaultAttributesPublic,
286
+ order: [
287
+ ['counter_users', 'desc'],
288
+ [{ model: models.Image, as: 'CommunityLogoImages' }, 'created_at', 'asc']
289
+ ],
290
+ include: [
291
+ {
292
+ model: models.Image, as: 'CommunityLogoImages',
293
+ attributes: models.Image.defaultAttributesPublic,
294
+ required: false
295
+ },
296
+ {
297
+ model: models.Image, as: 'CommunityHeaderImages',
298
+ attributes: models.Image.defaultAttributesPublic,
299
+ required: false
300
+ },
301
+ {
302
+ model: models.Community,
303
+ as: 'CommunityFolders',
304
+ attributes: ['id', 'name', 'counter_users', 'counter_posts', 'counter_groups'],
305
+ required: false,
306
+ },
307
+ {
308
+ model: models.Domain,
309
+ as: 'Domain',
310
+ attributes: ['id', 'configuration', 'name'],
311
+ required: false
312
+ },
313
+ {
314
+ model: models.User,
315
+ as: 'CommunityAdmins',
316
+ attributes: ['id'],
317
+ required: true,
318
+ where: {
319
+ id: req.user.id
320
+ }
321
+ }
322
+ ]
323
+ }).then(function (communities) {
324
+ adminCommunities = communities;
325
+ parallelCallback();
326
+ }).catch(function (error) {
327
+ parallelCallback(error);
328
+ });
329
+ },
330
+ function (parallelCallback) {
331
+ models.Community.findAll({
332
+ where: {
333
+ domain_id: domain.id,
334
+ in_community_folder_id: null,
335
+ configuration: {
336
+ [models.Sequelize.Op.or]: [
337
+ {
338
+ customBackURL: {
339
+ [models.Sequelize.Op.is]: null
340
+ }
341
+ },
342
+ {
343
+ alwaysShowOnDomainPage: true
344
+ }
345
+ ]
346
+ },
347
+ },
348
+ limit: 500,
349
+ attributes: models.Community.defaultAttributesPublic,
350
+ order: [
351
+ ['counter_users', 'desc'],
352
+ [{ model: models.Image, as: 'CommunityLogoImages' }, 'created_at', 'asc']
353
+ ],
354
+ include: [
355
+ {
356
+ model: models.Image, as: 'CommunityLogoImages',
357
+ attributes: models.Image.defaultAttributesPublic,
358
+ required: false
359
+ },
360
+ {
361
+ model: models.Community,
362
+ as: 'CommunityFolders',
363
+ attributes: ['id', 'name', 'counter_users', 'counter_posts', 'counter_groups'],
364
+ required: false,
365
+ },
366
+ {
367
+ model: models.Image, as: 'CommunityHeaderImages',
368
+ required: false
369
+ },
370
+ {
371
+ model: models.User,
372
+ as: 'CommunityUsers',
373
+ attributes: ['id'],
374
+ required: true,
375
+ where: {
376
+ id: req.user.id
377
+ }
378
+ }
379
+ ]
380
+ }).then(function (communities) {
381
+ userCommunities = communities;
382
+ parallelCallback();
383
+ }).catch(function (error) {
384
+ parallelCallback(error);
385
+ });
386
+ }
387
+ ], function (error) {
388
+ var combinedCommunities = _.concat(adminCommunities, userCommunities);
389
+ combinedCommunities = _.concat(domain.dataValues.Communities, combinedCommunities);
390
+ combinedCommunities = _.uniqBy(combinedCommunities, function (community) {
391
+ return community.id;
392
+ });
393
+ domain.dataValues.Communities = combinedCommunities;
394
+ seriesCallback(error);
395
+ });
396
+ }
397
+ else {
398
+ seriesCallback();
399
+ }
400
+ }
401
+ ], function (error) {
402
+ done(error, domain);
403
+ });
404
+ };
405
+ var getDomainAndUser = function (domainId, userId, userEmail, callback) {
406
+ var user, domain;
407
+ async.series([
408
+ function (seriesCallback) {
409
+ models.Domain.findOne({
410
+ where: {
411
+ id: domainId
412
+ }
413
+ }).then(function (domainIn) {
414
+ if (domainIn) {
415
+ domain = domainIn;
416
+ }
417
+ seriesCallback();
418
+ }).catch(function (error) {
419
+ seriesCallback(error);
420
+ });
421
+ },
422
+ function (seriesCallback) {
423
+ if (userId) {
424
+ models.User.findOne({
425
+ where: {
426
+ id: userId
427
+ },
428
+ attributes: ['id', 'email', 'name', 'created_at']
429
+ }).then(function (userIn) {
430
+ if (userIn) {
431
+ user = userIn;
432
+ }
433
+ seriesCallback();
434
+ }).catch(function (error) {
435
+ seriesCallback(error);
436
+ });
437
+ }
438
+ else {
439
+ seriesCallback();
440
+ }
441
+ },
442
+ function (seriesCallback) {
443
+ if (userEmail) {
444
+ models.User.findOne({
445
+ where: {
446
+ email: userEmail
447
+ },
448
+ attributes: ['id', 'email', 'name', 'created_at']
449
+ }).then(function (userIn) {
450
+ if (userIn) {
451
+ user = userIn;
452
+ }
453
+ seriesCallback();
454
+ }).catch(function (error) {
455
+ seriesCallback(error);
456
+ });
457
+ }
458
+ else {
459
+ seriesCallback();
460
+ }
461
+ }
462
+ ], function (error) {
463
+ if (error) {
464
+ callback(error);
465
+ }
466
+ else {
467
+ callback(null, domain, user);
468
+ }
469
+ });
470
+ };
471
+ router.get('/:domainId/availableCommunityFolders', auth.can('view domain'), function (req, res) {
472
+ getAvailableCommunityFolders(req, req.params.domainId, function (error, availableCommunityFolders) {
473
+ if (error) {
474
+ log.error('Could not get availableCommunityFolders', { err: error, user: req.user ? toJson(req.user.simple()) : null });
475
+ res.sendStatus(500);
476
+ }
477
+ else if (availableCommunityFolders) {
478
+ res.send(availableCommunityFolders);
479
+ }
480
+ else {
481
+ res.sendStatus(404);
482
+ }
483
+ });
484
+ });
485
+ router.delete('/:domainId/:activityId/delete_activity', auth.can('edit domain'), function (req, res) {
486
+ models.AcActivity.findOne({
487
+ where: {
488
+ domain_id: req.params.domainId,
489
+ id: req.params.activityId
490
+ }
491
+ }).then(function (activity) {
492
+ activity.deleted = true;
493
+ activity.save().then(function () {
494
+ res.send({ activityId: activity.id });
495
+ });
496
+ }).catch(function (error) {
497
+ log.error('Could not delete activity for domain', {
498
+ err: error,
499
+ context: 'delete_activity',
500
+ user: toJson(req.user.simple())
501
+ });
502
+ res.sendStatus(500);
503
+ });
504
+ });
505
+ router.get('/:domainId/pages', auth.can('view domain'), function (req, res) {
506
+ models.Page.getPages(req, { domain_id: req.params.domainId }, function (error, pages) {
507
+ if (error) {
508
+ log.error('Could not get pages for domain', { err: error, context: 'pages', user: req.user ? toJson(req.user.simple()) : null });
509
+ res.sendStatus(500);
510
+ }
511
+ else {
512
+ log.info('Got Pages', { userId: req.user ? req.user.id : null });
513
+ res.send(pages);
514
+ }
515
+ });
516
+ });
517
+ router.get('/:domainId/pages_for_admin', auth.can('edit domain'), function (req, res) {
518
+ models.Page.getPagesForAdmin(req, { domain_id: req.params.domainId }, function (error, pages) {
519
+ if (error) {
520
+ log.error('Could not get page for admin for domain', { err: error, context: 'pages_for_admin', user: toJson(req.user.simple()) });
521
+ res.sendStatus(500);
522
+ }
523
+ else {
524
+ log.info('Got Pages For Admin', { userId: req.user ? req.user.id : null });
525
+ res.send(pages);
526
+ }
527
+ });
528
+ });
529
+ router.post('/:domainId/add_page', auth.can('edit domain'), function (req, res) {
530
+ models.Page.newPage(req, { domain_id: req.params.domainId, content: {}, title: {} }, function (error, pages) {
531
+ if (error) {
532
+ log.error('Could not create page for admin for domain', { err: error, context: 'new_page', user: toJson(req.user.simple()) });
533
+ res.sendStatus(500);
534
+ }
535
+ else {
536
+ log.info('New Community Page', { context: 'new_page', user: toJson(req.user.simple()) });
537
+ res.sendStatus(200);
538
+ }
539
+ });
540
+ });
541
+ router.get('/:domainId/users', auth.can('edit domain'), function (req, res) {
542
+ models.Domain.findOne({
543
+ where: {
544
+ id: req.params.domainId
545
+ },
546
+ include: [
547
+ {
548
+ model: models.User,
549
+ attributes: _.concat(models.User.defaultAttributesWithSocialMediaPublicAndEmail, ['created_at', 'last_login_at']),
550
+ as: 'DomainUsers',
551
+ required: true,
552
+ include: [
553
+ {
554
+ model: models.Organization,
555
+ attributes: ['id', 'name'],
556
+ as: 'OrganizationUsers',
557
+ required: false
558
+ }
559
+ ]
560
+ }
561
+ ]
562
+ }).then(function (domain) {
563
+ log.info('Got users for domain', { context: 'users', user: toJson(req.user.simple()) });
564
+ if (domain) {
565
+ res.send(domain.DomainUsers);
566
+ }
567
+ else {
568
+ res.send([]);
569
+ }
570
+ }).catch(function (error) {
571
+ log.error('Could not get users for domain', { err: error, context: 'users', user: toJson(req.user.simple()) });
572
+ res.sendStatus(500);
573
+ });
574
+ });
575
+ router.get('/:domainId/admin_users', auth.can('edit domain'), function (req, res) {
576
+ models.Domain.findOne({
577
+ where: {
578
+ id: req.params.domainId
579
+ },
580
+ include: [
581
+ {
582
+ model: models.User,
583
+ attributes: _.concat(models.User.defaultAttributesWithSocialMediaPublicAndEmail, ['created_at', 'last_login_at']),
584
+ as: 'DomainAdmins',
585
+ required: true,
586
+ include: [
587
+ {
588
+ model: models.Organization,
589
+ attributes: ['id', 'name'],
590
+ as: 'OrganizationUsers',
591
+ required: false
592
+ }
593
+ ]
594
+ }
595
+ ]
596
+ }).then(function (domain) {
597
+ log.info('Got admins for domain', { context: 'users', user: toJson(req.user.simple()) });
598
+ if (domain) {
599
+ res.send(domain.DomainAdmins);
600
+ }
601
+ else {
602
+ res.send([]);
603
+ }
604
+ }).catch(function (error) {
605
+ log.error('Could not get admin users for domain', { err: error, context: 'users', user: toJson(req.user.simple()) });
606
+ res.sendStatus(500);
607
+ });
608
+ });
609
+ router.put('/:domainId/:pageId/update_page_locale', auth.can('edit domain'), function (req, res) {
610
+ models.Page.updatePageLocale(req, { domain_id: req.params.domainId, id: req.params.pageId }, function (error) {
611
+ if (error) {
612
+ log.error('Could not update locale for admin for domain', { err: error, context: 'update_page_locale', user: toJson(req.user.simple()) });
613
+ res.sendStatus(500);
614
+ }
615
+ else {
616
+ log.info('Community Page Locale Updated', { context: 'update_page_locale', user: toJson(req.user.simple()) });
617
+ res.sendStatus(200);
618
+ }
619
+ });
620
+ });
621
+ router.put('/:domainId/:pageId/update_page_weight', auth.can('edit domain'), function (req, res) {
622
+ models.Page.updatePageWeight(req, { domain_id: req.params.domainId, id: req.params.pageId }, function (error) {
623
+ if (error) {
624
+ log.error('Could not update weight for admin for domain', { err: error, context: 'update_page_weight', user: toJson(req.user.simple()) });
625
+ res.sendStatus(500);
626
+ }
627
+ else {
628
+ log.info('Community Page Weight Updated', { context: 'update_page_weight', user: toJson(req.user.simple()) });
629
+ res.sendStatus(200);
630
+ }
631
+ });
632
+ });
633
+ router.put('/:domainId/:pageId/publish_page', auth.can('edit domain'), function (req, res) {
634
+ models.Page.publishPage(req, { domain_id: req.params.domainId, id: req.params.pageId }, function (error) {
635
+ if (error) {
636
+ log.error('Could not publish page for admin for domain', { err: error, context: 'publish_page', user: toJson(req.user.simple()) });
637
+ res.sendStatus(500);
638
+ }
639
+ else {
640
+ log.info('Community Page Published', { context: 'publish_page', user: toJson(req.user.simple()) });
641
+ res.sendStatus(200);
642
+ }
643
+ });
644
+ });
645
+ router.put('/:domainId/:pageId/un_publish_page', auth.can('edit domain'), function (req, res) {
646
+ models.Page.unPublishPage(req, { domain_id: req.params.domainId, id: req.params.pageId }, function (error) {
647
+ if (error) {
648
+ log.error('Could not un-publish page for admin for domain', { err: error, context: 'un_publish_page', user: toJson(req.user.simple()) });
649
+ res.sendStatus(500);
650
+ }
651
+ else {
652
+ log.info('Community Page Un-Published', { context: 'un_publish_page', user: toJson(req.user.simple()) });
653
+ res.sendStatus(200);
654
+ }
655
+ });
656
+ });
657
+ router.delete('/:domainId/:pageId/delete_page', auth.can('edit domain'), function (req, res) {
658
+ models.Page.deletePage(req, { domain_id: req.params.domainId, id: req.params.pageId }, function (error) {
659
+ if (error) {
660
+ log.error('Could not delete page for admin for domain', { err: error, context: 'delete_page', user: toJson(req.user.simple()) });
661
+ res.sendStatus(500);
662
+ }
663
+ else {
664
+ log.info('Commuity Page Published', { context: 'delete_page', user: toJson(req.user.simple()) });
665
+ res.sendStatus(200);
666
+ }
667
+ });
668
+ });
669
+ router.post('/:domainId/news_story', auth.isLoggedInNoAnonymousCheck, auth.can('view domain'), function (req, res) {
670
+ models.Point.createNewsStory(req, req.body, function (error) {
671
+ if (error) {
672
+ log.error('Could not save news story point on domain', { err: error, context: 'news_story', user: toJson(req.user.simple()) });
673
+ res.sendStatus(500);
674
+ }
675
+ else {
676
+ log.info('Point News Story Created', { context: 'news_story', user: toJson(req.user.simple()) });
677
+ res.sendStatus(200);
678
+ }
679
+ });
680
+ });
681
+ router.get('/oldBoot', function (req, res) {
682
+ getDomain(req, req.ypDomain.id, function (error, domain) {
683
+ if (error) {
684
+ if (error == 'Not found')
685
+ sendDomainOrError(res, null, 'view', req.user, error, 404);
686
+ else
687
+ sendDomainOrError(res, null, 'view', req.user, error);
688
+ }
689
+ else {
690
+ if (req.ypCommunity && req.ypCommunity.id) {
691
+ log.info('Domain Lookup Found Community', { community: req.ypCommunity.hostname, context: 'index', user: toJson(req.user) });
692
+ res.send({ community: req.ypCommunity, domain: domain });
693
+ }
694
+ else {
695
+ log.info('Domain Lookup Found Domain', { domainId: domain ? domain.id : -1, context: 'index', userId: req.user ? req.user.id : -1 });
696
+ res.send({ domain: domain });
697
+ }
698
+ }
699
+ });
700
+ });
701
+ router.get('/', function (req, res) {
702
+ if (req.ypDomain.secret_api_keys &&
703
+ req.ypDomain.secret_api_keys.saml && req.ypDomain.secret_api_keys.saml.entryPoint &&
704
+ req.ypDomain.secret_api_keys.saml.entryPoint.length > 6) {
705
+ req.ypDomain.dataValues.samlLoginProvided = true;
706
+ }
707
+ if (req.ypDomain.secret_api_keys &&
708
+ req.ypDomain.secret_api_keys.facebook && req.ypDomain.secret_api_keys.facebook.client_secret &&
709
+ req.ypDomain.secret_api_keys.facebook.client_secret.length > 6) {
710
+ req.ypDomain.dataValues.facebookLoginProvided = true;
711
+ }
712
+ if (process.env.GOOGLE_MAPS_API_KEY) {
713
+ req.ypDomain.dataValues.googleMapsApiKey = process.env.GOOGLE_MAPS_API_KEY;
714
+ }
715
+ if (process.env.ZIGGEO_ENABLED) {
716
+ req.ypDomain.dataValues.ziggeoEnabled = process.env.ZIGGEO_ENABLED;
717
+ }
718
+ if (process.env.OPENAI_API_KEY) {
719
+ req.ypDomain.dataValues.hasLlm = true;
720
+ }
721
+ if (process.env.CESIUM_ACCESS_TOKEN) {
722
+ req.ypDomain.dataValues.ionToken = process.env.CESIUM_ACCESS_TOKEN;
723
+ }
724
+ if (process.env.LOGIN_CALLBACK_CUSTOM_HOSTNAME) {
725
+ req.ypDomain.dataValues.loginCallbackCustomHostName = process.env.LOGIN_CALLBACK_CUSTOM_HOSTNAME;
726
+ }
727
+ const domain = { ...req.ypDomain.dataValues };
728
+ delete domain["secret_api_keys"];
729
+ delete domain["user_agent"];
730
+ delete domain["ip_address"];
731
+ res.send({ community: (req.ypCommunity && req.ypCommunity.id) ? req.ypCommunity : undefined, domain: domain });
732
+ });
733
+ router.get('/:id/translatedText', auth.can('view domain'), function (req, res) {
734
+ if (req.query.textType.indexOf("domain") > -1) {
735
+ models.Domain.findOne({
736
+ where: {
737
+ id: req.params.id
738
+ },
739
+ attributes: ['id', 'name', 'description', 'configuration']
740
+ }).then(function (domain) {
741
+ if (domain) {
742
+ models.AcTranslationCache.getTranslation(req, domain, function (error, translation) {
743
+ if (error) {
744
+ sendDomainOrError(res, req.params.id, 'translated', req.user, error, 500);
745
+ }
746
+ else {
747
+ res.send(translation);
748
+ }
749
+ });
750
+ log.info('Domain translatedTitle', { context: 'translated' });
751
+ }
752
+ else {
753
+ sendDomainOrError(res, req.params.id, 'translated', req.user, 'Not found', 404);
754
+ }
755
+ }).catch(function (error) {
756
+ sendDomainOrError(res, null, 'translated', req.user, error);
757
+ });
758
+ }
759
+ else {
760
+ sendDomainOrError(res, req.params.id, 'translated', req.user, 'Wrong textType', 401);
761
+ }
762
+ });
763
+ router.get('/:id', auth.can('view domain'), function (req, res) {
764
+ if (isValidDbId(req.params.id)) {
765
+ getDomain(req, req.params.id, function (error, domain) {
766
+ if (error) {
767
+ sendDomainOrError(res, null, 'view', req.user, error);
768
+ }
769
+ else {
770
+ log.info('Domain Viewed', { id: domain ? domain.id : -1, userId: req.user ? req.user.id : null });
771
+ res.send(domain);
772
+ }
773
+ });
774
+ }
775
+ else {
776
+ res.sendStatus(404);
777
+ }
778
+ });
779
+ // Function to update domain properties
780
+ function updateDomainProperties(domain, req) {
781
+ domain.ensureApiKeySetup();
782
+ domain.set('secret_api_keys.facebook.client_id', req.body.facebookClientId);
783
+ domain.set('secret_api_keys.facebook.client_secret', req.body.facebookClientSecret);
784
+ domain.set('secret_api_keys.google.client_id', req.body.googleClientId);
785
+ domain.set('secret_api_keys.google.client_secret', req.body.googleClientSecret);
786
+ domain.set('secret_api_keys.twitter.client_id', req.body.twitterClientId);
787
+ domain.set('secret_api_keys.twitter.client_secret', req.body.twitterClientSecret);
788
+ domain.set('secret_api_keys.github.client_id', req.body.githubClientId);
789
+ domain.set('secret_api_keys.github.client_secret', req.body.githubClientSecret);
790
+ domain.set('configuration.welcomeHtmlInsteadOfCommunitiesList', (req.body.welcomeHtmlInsteadOfCommunitiesList && req.body.welcomeHtmlInsteadOfCommunitiesList !== "") ? req.body.welcomeHtmlInsteadOfCommunitiesList : null);
791
+ domain.set('configuration.hideAppBarIfWelcomeHtml', truthValueFromBody(req.body.hideAppBarIfWelcomeHtml));
792
+ if (req.body.samlEntryPoint) {
793
+ domain.set('secret_api_keys.saml.entryPoint', req.body.samlEntryPoint);
794
+ domain.set('secret_api_keys.saml.callbackUrl', req.body.samlCallbackUrl);
795
+ domain.set('secret_api_keys.saml.cert', req.body.samlCert);
796
+ domain.set('secret_api_keys.saml.issuer', req.body.samlIssuer);
797
+ domain.set('secret_api_keys.saml.identifierFormat', req.body.samlIdentifierFormat);
798
+ }
799
+ if (!domain.configuration) {
800
+ domain.set('configuration', {});
801
+ }
802
+ domain.set('configuration.customSamlLoginText', (req.body.customSamlLoginText && req.body.customSamlLoginText !== "") ? req.body.customSamlLoginText : null);
803
+ domain.set('configuration.samlLoginButtonUrl', (req.body.samlLoginButtonUrl && req.body.samlLoginButtonUrl !== "") ? req.body.samlLoginButtonUrl : null);
804
+ domain.set('configuration.customSAMLErrorHTML', (req.body.customSAMLErrorHTML && req.body.customSAMLErrorHTML !== "") ? req.body.customSAMLErrorHTML : null);
805
+ domain.set('configuration.preloadCssUrl', (req.body.preloadCssUrl && req.body.preloadCssUrl !== "") ? req.body.preloadCssUrl : null);
806
+ domain.set('configuration.plausibleDataDomains', (req.body.plausibleDataDomains && req.body.plausibleDataDomains !== "") ? req.body.plausibleDataDomains : null);
807
+ domain.set('configuration.ziggeoApplicationToken', (req.body.ziggeoApplicationToken && req.body.ziggeoApplicationToken !== "") ? req.body.ziggeoApplicationToken : null);
808
+ domain.set('configuration.ga4Tag', (req.body.ga4Tag && req.body.ga4Tag !== "") ? req.body.ga4Tag : null);
809
+ domain.set('configuration.useLoginOnDomainIfNotLoggedIn', truthValueFromBody(req.body.useLoginOnDomainIfNotLoggedIn));
810
+ if (req.body.google_analytics_code && req.body.google_analytics_code !== "") {
811
+ domain.google_analytics_code = req.body.google_analytics_code;
812
+ }
813
+ else {
814
+ domain.google_analytics_code = null;
815
+ }
816
+ const ltpConfigText = (req.body.ltp && req.body.ltp !== "") ? req.body.ltp : null;
817
+ if (ltpConfigText) {
818
+ try {
819
+ const cleaned = ltpConfigText.trim().replace(/\n/g, '').replace(/\r/g, '');
820
+ const parsedJson = JSON.parse(cleaned);
821
+ domain.set('configuration.ltp', parsedJson);
822
+ }
823
+ catch (error) {
824
+ domain.set('configuration.ltp', null);
825
+ log.error("Error in parsing ltp", { error });
826
+ }
827
+ }
828
+ else {
829
+ domain.set('configuration.ltp', null);
830
+ }
831
+ const theme = (req.body.theme && req.body.theme !== "") ? req.body.theme : null;
832
+ if (theme) {
833
+ try {
834
+ const cleaned = theme.trim().replace(/\n/g, '').replace(/\r/g, '');
835
+ const parsedJson = JSON.parse(cleaned);
836
+ domain.set('configuration.theme', parsedJson);
837
+ }
838
+ catch (error) {
839
+ domain.set('configuration.theme', null);
840
+ log.error("Error in parsing theme", { error });
841
+ }
842
+ }
843
+ else {
844
+ domain.set('configuration.theme', null);
845
+ }
846
+ domain.set('configuration.customUserRegistrationText', (req.body.customUserRegistrationText && req.body.customUserRegistrationText !== "") ? req.body.customUserRegistrationText : null);
847
+ domain.set('configuration.forceSecureSamlEmployeeLogin', truthValueFromBody(req.body.forceSecureSamlEmployeeLogin));
848
+ domain.set('configuration.disableNameAutoTranslation', truthValueFromBody(req.body.disableNameAutoTranslation));
849
+ if (req.body.appHomeScreenIconImageId && req.body.appHomeScreenIconImageId !== "") {
850
+ domain.set('configuration.appHomeScreenIconImageId', req.body.appHomeScreenIconImageId);
851
+ }
852
+ domain.set('configuration.appHomeScreenShortName', (req.body.appHomeScreenShortName && req.body.appHomeScreenShortName !== "") ? req.body.appHomeScreenShortName : null);
853
+ domain.set('configuration.useVideoCover', truthValueFromBody(req.body.useVideoCover));
854
+ domain.set('configuration.hideDomainNews', truthValueFromBody(req.body.hideDomainNews));
855
+ domain.set('configuration.hideDomainTabs', truthValueFromBody(req.body.hideDomainTabs));
856
+ domain.set('configuration.hideAllTabs', truthValueFromBody(req.body.hideAllTabs));
857
+ domain.set('configuration.useFixedTopAppBar', truthValueFromBody(req.body.useFixedTopAppBar));
858
+ domain.set('configuration.disableArrowBasedTopNavigation', truthValueFromBody(req.body.disableArrowBasedTopNavigation));
859
+ domain.set('configuration.onlyAllowCreateUserOnInvite', truthValueFromBody(req.body.onlyAllowCreateUserOnInvite));
860
+ domain.name = req.body.name;
861
+ domain.description = req.body.description;
862
+ domain.only_admins_can_create_communities = truthValueFromBody(req.body.onlyAdminsCanCreateCommunities);
863
+ domain.theme_id = req.body.themeId ? parseInt(req.body.themeId) : null;
864
+ if (req.body.defaultLocale && req.body.defaultLocale !== "") {
865
+ domain.default_locale = req.body.defaultLocale;
866
+ }
867
+ }
868
+ // Update existing domain
869
+ router.put('/:id', auth.can('edit domain'), function (req, res) {
870
+ models.Domain.findOne({
871
+ where: { id: req.params.id }
872
+ }).then(function (domain) {
873
+ if (domain) {
874
+ updateDomainProperties(domain, req);
875
+ domain.save().then(function () {
876
+ queue.add('process-similarities', { type: 'update-collection', domainId: domain.id }, 'low');
877
+ log.info('Domain Updated', { domain: toJson(domain), user: toJson(req.user) });
878
+ domain.setupImages(req.body, function (err) {
879
+ if (err) {
880
+ res.sendStatus(500);
881
+ log.error('Domain Error Setup images', { domain: toJson(domain), user: toJson(req.user), err: err });
882
+ }
883
+ else {
884
+ res.send(domain);
885
+ }
886
+ });
887
+ });
888
+ }
889
+ else {
890
+ sendDomainOrError(res, req.params.id, 'update', req.user, 'Not found', 404);
891
+ }
892
+ }).catch(function (error) {
893
+ sendDomainOrError(res, null, 'update', req.user, error);
894
+ });
895
+ });
896
+ router.get('/:id/my_domains', auth.can('view domain'), function (req, res) {
897
+ models.Domain.findAll({
898
+ attributes: ['id', 'name'],
899
+ include: [
900
+ {
901
+ model: models.User,
902
+ as: 'DomainUsers',
903
+ attributes: [],
904
+ where: { id: req.user.id },
905
+ required: false
906
+ },
907
+ {
908
+ model: models.User,
909
+ as: 'DomainAdmins',
910
+ attributes: [],
911
+ where: { id: req.user.id },
912
+ required: false
913
+ }
914
+ ],
915
+ where: {
916
+ [models.Sequelize.Op.or]: [
917
+ { '$DomainUsers.id$': { [models.Sequelize.Op.eq]: req.user.id } },
918
+ { '$DomainAdmins.id$': { [models.Sequelize.Op.eq]: req.user.id } }
919
+ ]
920
+ }
921
+ }).then(function (domains) {
922
+ // Deduplicate the domains in case the user is both an admin and a user
923
+ const uniqueDomains = _.uniqBy(domains, 'id');
924
+ const domainList = uniqueDomains.map(domain => ({ id: domain.id, name: domain.name }));
925
+ log.info('Retrieved user domains', { userId: req.user.id });
926
+ res.send(domainList);
927
+ }).catch(function (error) {
928
+ log.error('Could not retrieve user domains', { err: error, context: 'my_domains', user: toJson(req.user.simple()) });
929
+ res.sendStatus(500);
930
+ });
931
+ });
932
+ router.post('/:id', auth.can('edit domain'), function (req, res) {
933
+ const randomDomainName = crypto.randomBytes(16).toString('hex'); // Generate 32 character random string
934
+ var domain = models.Domain.build({
935
+ name: req.body.name,
936
+ description: req.body.description,
937
+ user_id: req.user.id,
938
+ user_agent: req.useragent.source,
939
+ ip_address: req.clientIp,
940
+ access: req.body.access ? req.body.access : 2,
941
+ status: "active",
942
+ domain_name: randomDomainName
943
+ });
944
+ updateDomainProperties(domain, req);
945
+ domain.save()
946
+ .then(function () {
947
+ return domain.addDomainUsers(req.user);
948
+ })
949
+ .then(function () {
950
+ return domain.addDomainAdmins(req.user);
951
+ })
952
+ .then(function () {
953
+ // Success path
954
+ queue.add('process-similarities', { type: 'update-collection', domainId: domain.id }, 'low');
955
+ log.info('Domain Created', { domain: toJson(domain), context: 'create', user: toJson(req.user) });
956
+ domain.setupImages(req.body, function (err) {
957
+ if (err) {
958
+ res.sendStatus(500);
959
+ log.error('Domain Error Setup images', { domain: toJson(domain), user: toJson(req.user), err: err });
960
+ }
961
+ else {
962
+ res.send(domain);
963
+ }
964
+ });
965
+ })
966
+ .catch(function (error) {
967
+ // Handle any error that occurred in any of the previous promises
968
+ log.error('Error during domain creation', { err: error, domainId: domain.id, user: toJson(req.user) });
969
+ res.sendStatus(500);
970
+ });
971
+ });
972
+ router.delete('/:id', auth.can('edit domain'), function (req, res) {
973
+ models.Domain.findOne({
974
+ where: { id: req.params.id }
975
+ }).then(function (domain) {
976
+ if (domain) {
977
+ domain.deleted = true;
978
+ domain.save().then(function () {
979
+ log.info('Domain Deleted', { group: toJson(group), context: 'delete', user: toJson(req.user) });
980
+ queue.add('process-similarities', { type: 'update-collection', domainId: domain.id }, 'low');
981
+ res.sendStatus(200);
982
+ });
983
+ }
984
+ else {
985
+ sendDomainOrError(res, req.params.id, 'delete', req.user, 'Not found', 404);
986
+ }
987
+ }).catch(function (error) {
988
+ sendDomainOrError(res, null, 'delete', req.user, error);
989
+ });
990
+ });
991
+ router.get(':id/news', auth.can('view domain'), function (req, res) {
992
+ models.AcActivity.findOne({
993
+ where: { domain_id: req.params.id },
994
+ order: [
995
+ [{ model: models.Domain }, 'created_at', 'asc']
996
+ ],
997
+ limit: 200
998
+ }).then(function (news) {
999
+ if (news) {
1000
+ log.info('Domain News', { domain: toJson(news), context: 'get', user: toJson(req.user) });
1001
+ res.send(news);
1002
+ }
1003
+ else {
1004
+ log.warn("Domain News Not Found", {
1005
+ context: context, domain: toJson(domain), user: toJson(user), err: "Not found",
1006
+ errorStatus: errorStatus ? errorStatus : 404
1007
+ });
1008
+ res.sendStatus(404);
1009
+ }
1010
+ }).catch(function (error) {
1011
+ log.error("Domain News Error", { context: context, domain: toJson(domain), user: toJson(user), err: error,
1012
+ errorStatus: errorStatus ? errorStatus : 500 });
1013
+ res.sendStatus(500);
1014
+ });
1015
+ });
1016
+ // MODERATION
1017
+ router.delete('/:domainId/:itemId/:itemType/:actionType/process_one_moderation_item', auth.can('edit domain'), (req, res) => {
1018
+ performSingleModerationAction(req, res, {
1019
+ domainId: req.params.domainId,
1020
+ itemId: req.params.itemId,
1021
+ itemType: req.params.itemType,
1022
+ actionType: req.params.actionType
1023
+ });
1024
+ });
1025
+ router.delete('/:domainId/:actionType/process_many_moderation_item', auth.can('edit domain'), (req, res) => {
1026
+ queue.add('process-moderation', {
1027
+ type: 'perform-many-moderation-actions',
1028
+ items: req.body.items,
1029
+ actionType: req.params.actionType,
1030
+ domainId: req.params.domainId
1031
+ }, 'critical');
1032
+ res.send({});
1033
+ });
1034
+ router.get('/:domainId/flagged_content', auth.can('edit domain'), (req, res) => {
1035
+ getAllModeratedItemsByDomain({ domainId: req.params.domainId }, (error, items) => {
1036
+ if (error) {
1037
+ log.error("Error getting items for moderation", { error });
1038
+ res.sendStatus(500);
1039
+ }
1040
+ else {
1041
+ res.send(items);
1042
+ }
1043
+ });
1044
+ });
1045
+ router.get('/:domainId/moderate_all_content', auth.can('edit domain'), (req, res) => {
1046
+ getAllModeratedItemsByDomain({ domainId: req.params.domainId, allContent: true }, (error, items) => {
1047
+ if (error) {
1048
+ log.error("Error getting items for moderation", { error });
1049
+ res.sendStatus(500);
1050
+ }
1051
+ else {
1052
+ res.send(items);
1053
+ }
1054
+ });
1055
+ });
1056
+ router.get('/:domainId/flagged_content_count', auth.can('edit domain'), (req, res) => {
1057
+ countAllModeratedItemsByDomain({ domainId: req.params.domainId }, (error, count) => {
1058
+ if (error) {
1059
+ log.error("Error getting items for moderation", { error });
1060
+ res.sendStatus(500);
1061
+ }
1062
+ else {
1063
+ res.send({ count });
1064
+ }
1065
+ });
1066
+ });
1067
+ router.delete('/:domainId/remove_many_admins', auth.can('edit domain'), (req, res) => {
1068
+ queue.add('process-deletion', { type: 'remove-many-domain-admins', userIds: req.body.userIds, domainId: req.params.domainId }, 'high');
1069
+ log.info('Remove many domain admins started', { context: 'remove_many_admins', domainId: req.params.domainId, user: toJson(req.user.simple()) });
1070
+ res.sendStatus(200);
1071
+ });
1072
+ router.delete('/:domainId/remove_many_users_and_delete_content', auth.can('edit domain'), function (req, res) {
1073
+ queue.add('process-deletion', { type: 'remove-many-domain-users-and-delete-content', userIds: req.body.userIds, domainId: req.params.domainId }, 'high');
1074
+ log.info('Remove many and delete many domain users content', { context: 'remove_many_users_and_delete_content', domainId: req.params.domainId, user: toJson(req.user.simple()) });
1075
+ res.sendStatus(200);
1076
+ });
1077
+ router.delete('/:domainId/remove_many_users', auth.can('edit domain'), function (req, res) {
1078
+ queue.add('process-deletion', { type: 'remove-many-domain-users', userIds: req.body.userIds, domainId: req.params.domainId }, 'high');
1079
+ log.info('Remove many domain admins started', { context: 'remove_many_users', domainId: req.params.domainId, user: toJson(req.user.simple()) });
1080
+ res.sendStatus(200);
1081
+ });
1082
+ router.delete('/:domainId/:userId/remove_and_delete_user_content', auth.can('edit domain'), function (req, res) {
1083
+ getDomainAndUser(req.params.domainId, req.params.userId, null, function (error, domain, user) {
1084
+ if (error) {
1085
+ log.error('Could not remove_user', { err: error, domainId: req.params.domainId, userRemovedId: req.params.userId, context: 'remove_user', user: toJson(req.user.simple()) });
1086
+ res.sendStatus(500);
1087
+ }
1088
+ else if (user && domain) {
1089
+ domain.removeDomainUsers(user).then(function (results) {
1090
+ queue.add('process-deletion', { type: 'delete-domain-user-content', userId: req.params.userId, domainId: req.params.domainId }, 'high');
1091
+ log.info('User removed from domain', { context: 'remove_and_delete_user_content', domainId: req.params.domainId, userRemovedId: req.params.userId, user: toJson(req.user.simple()) });
1092
+ res.sendStatus(200);
1093
+ });
1094
+ }
1095
+ else {
1096
+ res.sendStatus(404);
1097
+ }
1098
+ });
1099
+ });
1100
+ router.delete('/:domainId/:userId/remove_admin', auth.can('edit domain'), function (req, res) {
1101
+ getDomainAndUser(req.params.domainId, req.params.userId, null, function (error, domain, user) {
1102
+ if (error) {
1103
+ log.error('Could not remove admin', { err: error, domainId: req.params.domainId, userRemovedId: req.params.userId, context: 'remove_admin', user: req.user ? toJson(req.user.simple()) : null });
1104
+ res.sendStatus(500);
1105
+ }
1106
+ else if (user && domain) {
1107
+ domain.removeDomainAdmins(user).then(function (results) {
1108
+ log.info('Admin removed', { context: 'remove_admin', domainId: req.params.domainId, userRemovedId: req.params.userId, user: req.user ? toJson(req.user.simple()) : null });
1109
+ res.sendStatus(200);
1110
+ });
1111
+ }
1112
+ else {
1113
+ res.sendStatus(404);
1114
+ }
1115
+ });
1116
+ });
1117
+ router.post('/:domainId/:email/add_admin', auth.can('edit domain'), function (req, res) {
1118
+ getDomainAndUser(req.params.domainId, null, req.params.email, function (error, domain, user) {
1119
+ if (error) {
1120
+ log.error('Could not add admin', { err: error, domainId: req.params.domainId, userAddEmail: req.params.email, context: 'remove_admin', user: req.user ? toJson(req.user.simple()) : null });
1121
+ res.sendStatus(500);
1122
+ }
1123
+ else if (user && domain) {
1124
+ domain.addDomainAdmins(user).then(function (results) {
1125
+ log.info('Admin Added', { context: 'add_admin', domainId: req.params.domainId, userAddEmail: req.params.email, user: req.user ? toJson(req.user.simple()) : null });
1126
+ res.sendStatus(200);
1127
+ });
1128
+ }
1129
+ else {
1130
+ res.sendStatus(404);
1131
+ }
1132
+ });
1133
+ });
1134
+ router.delete('/:domainId/:userId/remove_user', auth.can('edit domain'), function (req, res) {
1135
+ getDomainAndUser(req.params.domainId, req.params.userId, null, function (error, domain, user) {
1136
+ if (error) {
1137
+ log.error('Could not remove_user', { err: error, domainId: req.params.domainId, userRemovedId: req.params.userId, context: 'remove_user', user: req.user ? toJson(req.user.simple()) : null });
1138
+ res.sendStatus(500);
1139
+ }
1140
+ else if (user && domain) {
1141
+ domain.removeDomainUsers(user).then(function (results) {
1142
+ if (domain.counter_users > 0) {
1143
+ domain.decrement("counter_users");
1144
+ }
1145
+ log.info('User removed', { context: 'remove_user', domainId: req.params.domainId, userRemovedId: req.params.userId, user: req.user ? toJson(req.user.simple()) : null });
1146
+ res.sendStatus(200);
1147
+ });
1148
+ }
1149
+ else {
1150
+ res.sendStatus(404);
1151
+ }
1152
+ });
1153
+ });
1154
+ router.get('/:domainId/export_logins', auth.can('edit domain'), function (req, res) {
1155
+ getLoginsExportDataForDomain(req.params.domainId, req.ypDomain.domain_name, function (error, fileData) {
1156
+ if (error) {
1157
+ log.error('Could not export logins for domain', { err: error, context: 'export_group', user: toJson(req.user.simple()) });
1158
+ res.sendStatus(500);
1159
+ }
1160
+ else {
1161
+ models.Domain.findOne({
1162
+ where: {
1163
+ id: req.params.domainId
1164
+ },
1165
+ attributes: ["id", "name"]
1166
+ }).then(function (model) {
1167
+ if (model) {
1168
+ log.info('Got Login Exports', { context: 'export_logins', user: toJson(req.user.simple()) });
1169
+ var domainName = sanitizeFilename(model.name).replace(/ /g, '');
1170
+ var dateString = moment(new Date()).format("DD_MM_YY_HH_mm");
1171
+ var filename = 'logins_export_for_domain_id_' + model.id + '_' +
1172
+ domainName + '_' + dateString + '.csv';
1173
+ res.set({ 'content-type': 'application/octet-stream; charset=utf-8' });
1174
+ res.charset = 'utf-8';
1175
+ res.attachment(filename);
1176
+ res.send(fileData);
1177
+ }
1178
+ else {
1179
+ log.error('Cant find domain', { err: error, context: 'export_logins', user: toJson(req.user.simple()) });
1180
+ res.sendStatus(404);
1181
+ }
1182
+ }).catch(function (error) {
1183
+ log.error('Could not export for domain', { err: error, context: 'export_logins', user: toJson(req.user.simple()) });
1184
+ res.sendStatus(500);
1185
+ });
1186
+ }
1187
+ });
1188
+ });
1189
+ // WORD CLOUD
1190
+ router.get('/:id/wordcloud', auth.can('edit domain'), function (req, res) {
1191
+ getFromAnalyticsApi(req, "wordclouds", "domain", req.params.id, function (error, content) {
1192
+ sendBackAnalyticsResultsOrError(req, res, error, content);
1193
+ });
1194
+ });
1195
+ // SIMILARITIES
1196
+ router.get('/:id/similarities_weights', auth.can('edit domain'), function (req, res) {
1197
+ getFromAnalyticsApi(req, "similarities_weights", "domain", req.params.id, function (error, content) {
1198
+ sendBackAnalyticsResultsOrError(req, res, error ? error : content.body ? null : 'noBody', getParsedSimilaritiesContent(content));
1199
+ });
1200
+ });
1201
+ // STATS
1202
+ router.get('/:id/stats_posts', auth.can('edit domain'), function (req, res) {
1203
+ countModelRowsByTimePeriod(req, "stats_posts" + req.params.id + "_domain", models.Post, {}, getDomainIncludes(req.params.id), (error, results) => {
1204
+ sendBackAnalyticsResultsOrError(req, res, error, results);
1205
+ });
1206
+ });
1207
+ router.get('/:id/stats_points', auth.can('edit domain'), function (req, res) {
1208
+ countModelRowsByTimePeriod(req, "stats_points" + req.params.id + "_domain", models.Point, {}, getPointDomainIncludes(req.params.id), (error, results) => {
1209
+ sendBackAnalyticsResultsOrError(req, res, error, results);
1210
+ });
1211
+ });
1212
+ router.get('/:id/stats_votes', auth.can('edit domain'), function (req, res) {
1213
+ countModelRowsByTimePeriod(req, "stats_votes_" + req.params.id + "_domain", models.AcActivity, {
1214
+ type: {
1215
+ $in: [
1216
+ "activity.post.opposition.new", "activity.post.endorsement.new",
1217
+ "activity.point.helpful.new", "activity.point.unhelpful.new"
1218
+ ]
1219
+ }
1220
+ }, getDomainIncludes(req.params.id), (error, results) => {
1221
+ sendBackAnalyticsResultsOrError(req, res, error, results);
1222
+ });
1223
+ });
1224
+ router.put('/:domainId/plausibleStatsProxy', auth.can('edit domain'), async (req, res) => {
1225
+ try {
1226
+ const plausibleData = await plausibleStatsProxy(req.body.plausibleUrl, { domainId: req.params.domainId });
1227
+ res.send(plausibleData);
1228
+ }
1229
+ catch (error) {
1230
+ log.error('Could not get plausibleStatsProxy', { err: error, context: 'getPlausibleSeries', user: toJson(req.user.simple()) });
1231
+ res.sendStatus(500);
1232
+ }
1233
+ });
1234
+ router.get('/:domainId/get_campaigns', auth.can('edit domain'), async (req, res) => {
1235
+ try {
1236
+ const campaigns = await models.Campaign.findAll({
1237
+ where: {
1238
+ domain_id: req.params.domainId,
1239
+ active: true
1240
+ },
1241
+ order: [
1242
+ ['created_at', 'desc']
1243
+ ],
1244
+ attributes: ['id', 'configuration']
1245
+ });
1246
+ res.send(campaigns);
1247
+ }
1248
+ catch (error) {
1249
+ log.error('Could not get campaigns', { err: error, context: 'get_campaigns', user: toJson(req.user.simple()) });
1250
+ res.sendStatus(500);
1251
+ }
1252
+ });
1253
+ router.post('/:domainId/create_campaign', auth.can('edit domain'), async (req, res) => {
1254
+ try {
1255
+ const campaign = models.Campaign.build({
1256
+ domain_id: req.params.domainId,
1257
+ configuration: req.body.configuration,
1258
+ user_id: req.user.id
1259
+ });
1260
+ await campaign.save();
1261
+ //TODO: Toxicity check
1262
+ res.send(campaign);
1263
+ }
1264
+ catch (error) {
1265
+ log.error('Could not create_campaign campaigns', { err: error, context: 'create_campaign', user: toJson(req.user.simple()) });
1266
+ res.sendStatus(500);
1267
+ }
1268
+ });
1269
+ router.put('/:domainId/:campaignId/update_campaign', auth.can('edit domain'), async (req, res) => {
1270
+ try {
1271
+ const campaign = await models.Campaign.findOne({
1272
+ where: {
1273
+ id: req.params.campaignId,
1274
+ domain_id: req.params.domainId
1275
+ },
1276
+ attributes: ['id', 'configuration']
1277
+ });
1278
+ campaign.configuration = req.body.configuration;
1279
+ await campaign.save();
1280
+ //TODO: Toxicity check
1281
+ res.send(campaign);
1282
+ }
1283
+ catch (error) {
1284
+ log.error('Could not create_campaign campaigns', { err: error, context: 'create_campaign', user: toJson(req.user.simple()) });
1285
+ res.sendStatus(500);
1286
+ }
1287
+ });
1288
+ router.delete('/:domainId/:campaignId/delete_campaign', auth.can('edit domain'), async (req, res) => {
1289
+ try {
1290
+ const campaign = await models.Campaign.findOne({
1291
+ where: {
1292
+ id: req.params.campaignId,
1293
+ domain_id: req.params.domainId
1294
+ },
1295
+ attributes: ['id']
1296
+ });
1297
+ campaign.deleted = true;
1298
+ await campaign.save();
1299
+ res.sendStatus(200);
1300
+ }
1301
+ catch (error) {
1302
+ log.error('Could not delete_campaign campaigns', { err: error, context: 'delete_campaign', user: toJson(req.user.simple()) });
1303
+ res.sendStatus(500);
1304
+ }
1305
+ });
1306
+ //TODO: Move permission back to edit after figuring out how
1307
+ router.post('/:domainId/:start_generating/ai_image', auth.can('view domain'), function (req, res) {
1308
+ models.AcBackgroundJob.createJob({}, {}, (error, jobId) => {
1309
+ if (error) {
1310
+ log.error('Could not create backgroundJob', { err: error, context: 'start_generating_ai_image', user: toJson(req.user.simple()) });
1311
+ res.sendStatus(500);
1312
+ }
1313
+ else {
1314
+ queue.add('process-generative-ai', {
1315
+ type: "collection-image",
1316
+ userId: req.user.id,
1317
+ jobId: jobId,
1318
+ collectionId: req.params.domainId,
1319
+ collectionType: "domain",
1320
+ prompt: req.body.prompt,
1321
+ imageType: req.body.imageType
1322
+ }, 'critical');
1323
+ res.send({ jobId });
1324
+ }
1325
+ });
1326
+ });
1327
+ //TODO: Move permission back to edit after figuring out how
1328
+ router.get('/:domainId/:jobId/poll_for_generating_ai_image', auth.can('view domain'), function (req, res) {
1329
+ models.AcBackgroundJob.findOne({
1330
+ where: {
1331
+ id: req.params.jobId
1332
+ },
1333
+ attributes: ['id', 'progress', 'error', 'data']
1334
+ }).then(job => {
1335
+ res.send(job);
1336
+ }).catch(error => {
1337
+ log.error('Could not get backgroundJob', { err: error, context: 'poll_for_generating_ai_image', user: toJson(req.user.simple()) });
1338
+ res.sendStatus(500);
1339
+ });
1340
+ });
1341
+ module.exports = router;