@yrpri/api 9.0.103 → 9.0.104

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 (422) hide show
  1. package/package.json +1 -1
  2. package/dist/active-citizen/controllers/activities.cjs +0 -174
  3. package/dist/active-citizen/controllers/news_feeds.cjs +0 -96
  4. package/dist/active-citizen/controllers/notifications.cjs +0 -243
  5. package/dist/active-citizen/controllers/recommendations.cjs +0 -280
  6. package/dist/active-citizen/engine/allOurIdeas/aiHelper.js +0 -204
  7. package/dist/active-citizen/engine/allOurIdeas/explainAnswersAssistant.js +0 -66
  8. package/dist/active-citizen/engine/allOurIdeas/iconGenerator.js +0 -38
  9. package/dist/active-citizen/engine/analytics/export_anon_community_activities.js +0 -334
  10. package/dist/active-citizen/engine/analytics/importer.js +0 -308
  11. package/dist/active-citizen/engine/analytics/manager.cjs +0 -377
  12. package/dist/active-citizen/engine/analytics/plausible/manager.cjs +0 -500
  13. package/dist/active-citizen/engine/analytics/statsCalc.cjs +0 -194
  14. package/dist/active-citizen/engine/analytics/utils.cjs +0 -369
  15. package/dist/active-citizen/engine/marketing/campaign.cjs +0 -90
  16. package/dist/active-citizen/engine/moderation/fraud/CreateFraudAuditReport.cjs +0 -313
  17. package/dist/active-citizen/engine/moderation/fraud/FraudBase.cjs +0 -239
  18. package/dist/active-citizen/engine/moderation/fraud/FraudDeleteBase.cjs +0 -211
  19. package/dist/active-citizen/engine/moderation/fraud/FraudDeleteEndorsements.cjs +0 -120
  20. package/dist/active-citizen/engine/moderation/fraud/FraudDeletePointQualities.cjs +0 -114
  21. package/dist/active-citizen/engine/moderation/fraud/FraudDeletePoints.cjs +0 -101
  22. package/dist/active-citizen/engine/moderation/fraud/FraudDeletePosts.cjs +0 -84
  23. package/dist/active-citizen/engine/moderation/fraud/FraudDeleteRatings.cjs +0 -15
  24. package/dist/active-citizen/engine/moderation/fraud/FraudGetBase.cjs +0 -133
  25. package/dist/active-citizen/engine/moderation/fraud/FraudGetEndorsements.cjs +0 -185
  26. package/dist/active-citizen/engine/moderation/fraud/FraudGetPointQualities.cjs +0 -184
  27. package/dist/active-citizen/engine/moderation/fraud/FraudGetPoints.cjs +0 -170
  28. package/dist/active-citizen/engine/moderation/fraud/FraudGetPosts.cjs +0 -109
  29. package/dist/active-citizen/engine/moderation/fraud/FraudGetRatings.cjs +0 -140
  30. package/dist/active-citizen/engine/moderation/fraud/FraudScannerNotifier.cjs +0 -279
  31. package/dist/active-citizen/engine/moderation/get_moderation_items.cjs +0 -386
  32. package/dist/active-citizen/engine/moderation/image_labeling/CommunityLabeling.cjs +0 -49
  33. package/dist/active-citizen/engine/moderation/image_labeling/GroupLabeling.cjs +0 -68
  34. package/dist/active-citizen/engine/moderation/image_labeling/ImageLabelingBase.cjs +0 -288
  35. package/dist/active-citizen/engine/moderation/image_labeling/PointLabeling.cjs +0 -33
  36. package/dist/active-citizen/engine/moderation/image_labeling/PostLabeling.cjs +0 -56
  37. package/dist/active-citizen/engine/moderation/perspective_api_client.cjs +0 -106
  38. package/dist/active-citizen/engine/moderation/process_moderation_items.cjs +0 -344
  39. package/dist/active-citizen/engine/moderation/toxicity_analysis.cjs +0 -810
  40. package/dist/active-citizen/engine/news_feeds/activity_and_item_index_definitions.cjs +0 -15
  41. package/dist/active-citizen/engine/news_feeds/generate_dynamically.cjs +0 -362
  42. package/dist/active-citizen/engine/news_feeds/generate_from_notifications.cjs +0 -268
  43. package/dist/active-citizen/engine/news_feeds/news_feeds_utils.cjs +0 -439
  44. package/dist/active-citizen/engine/notifications/emails_utils.cjs +0 -569
  45. package/dist/active-citizen/engine/notifications/generate_point_notifications.cjs +0 -233
  46. package/dist/active-citizen/engine/notifications/generate_post_notifications.cjs +0 -118
  47. package/dist/active-citizen/engine/notifications/generate_post_status_change_notifications.cjs +0 -41
  48. package/dist/active-citizen/engine/notifications/notifications_utils.cjs +0 -148
  49. package/dist/active-citizen/engine/notifications/point_delivery.cjs +0 -54
  50. package/dist/active-citizen/engine/notifications/post_delivery.cjs +0 -31
  51. package/dist/active-citizen/engine/notifications/process_delayed_notifications.cjs +0 -471
  52. package/dist/active-citizen/engine/notifications/process_general_notifications.cjs +0 -212
  53. package/dist/active-citizen/engine/old/exporters/categories_dataset.js +0 -153
  54. package/dist/active-citizen/engine/old/exporters/dataset_tools.js +0 -80
  55. package/dist/active-citizen/engine/old/exporters/sentiment_dataset.js +0 -157
  56. package/dist/active-citizen/engine/recommendations/events_importer.cjs +0 -139
  57. package/dist/active-citizen/engine/recommendations/events_manager.cjs +0 -212
  58. package/dist/active-citizen/engine/reports/add_points_to_sheet.cjs +0 -83
  59. package/dist/active-citizen/engine/reports/commonUtils.js +0 -75
  60. package/dist/active-citizen/engine/reports/common_utils.cjs +0 -740
  61. package/dist/active-citizen/engine/reports/docx_group_report.cjs +0 -596
  62. package/dist/active-citizen/engine/reports/xlsAllOurIdeasExport.js +0 -232
  63. package/dist/active-citizen/engine/reports/xls_community_users_report.cjs +0 -277
  64. package/dist/active-citizen/engine/reports/xls_group_report.cjs +0 -718
  65. package/dist/active-citizen/llms/baseChatBot.js +0 -183
  66. package/dist/active-citizen/llms/imageGeneration/chatGptImageGenerator.js +0 -56
  67. package/dist/active-citizen/llms/imageGeneration/collectionImageGenerator.js +0 -109
  68. package/dist/active-citizen/llms/imageGeneration/dalleImageGenerator.js +0 -84
  69. package/dist/active-citizen/llms/imageGeneration/fluxImageGenerator.js +0 -49
  70. package/dist/active-citizen/llms/imageGeneration/iImageGenerator.js +0 -1
  71. package/dist/active-citizen/llms/imageGeneration/imageProcessorService.js +0 -64
  72. package/dist/active-citizen/llms/imageGeneration/imagenImageGenerator.js +0 -107
  73. package/dist/active-citizen/llms/imageGeneration/s3Service.js +0 -110
  74. package/dist/active-citizen/llms/llmTranslation.js +0 -472
  75. package/dist/active-citizen/models/ac_activity.cjs +0 -216
  76. package/dist/active-citizen/models/ac_background_job.cjs +0 -109
  77. package/dist/active-citizen/models/ac_campaign.cjs +0 -97
  78. package/dist/active-citizen/models/ac_client_activity.cjs +0 -23
  79. package/dist/active-citizen/models/ac_delayed_notification.cjs +0 -43
  80. package/dist/active-citizen/models/ac_following.cjs +0 -43
  81. package/dist/active-citizen/models/ac_list.cjs +0 -68
  82. package/dist/active-citizen/models/ac_list_users.cjs +0 -19
  83. package/dist/active-citizen/models/ac_mute.cjs +0 -27
  84. package/dist/active-citizen/models/ac_news_feed_item.cjs +0 -57
  85. package/dist/active-citizen/models/ac_news_feed_processed_range.cjs +0 -59
  86. package/dist/active-citizen/models/ac_notification.cjs +0 -292
  87. package/dist/active-citizen/models/ac_translation_cache.cjs +0 -750
  88. package/dist/active-citizen/models/ac_watching.cjs +0 -31
  89. package/dist/active-citizen/scripts/analytics/setup_all_plausible_goals.cjs +0 -13
  90. package/dist/active-citizen/scripts/fix_old_delayed_notifications.js +0 -63
  91. package/dist/active-citizen/scripts/kue_status.js +0 -31
  92. package/dist/active-citizen/scripts/kue_watch_stuck_jobs.js +0 -24
  93. package/dist/active-citizen/scripts/translation_clear_language.js +0 -117
  94. package/dist/active-citizen/scripts/translation_delete.js +0 -27
  95. package/dist/active-citizen/scripts/translation_replace_text_from_url.js +0 -180
  96. package/dist/active-citizen/scripts/translation_update.js +0 -28
  97. package/dist/active-citizen/scripts/translations_list.js +0 -27
  98. package/dist/active-citizen/utils/airbrake.cjs +0 -17
  99. package/dist/active-citizen/utils/get_anonymous_system_user.cjs +0 -21
  100. package/dist/active-citizen/utils/i18n.cjs +0 -3
  101. package/dist/active-citizen/utils/logger.cjs +0 -25
  102. package/dist/active-citizen/utils/redisConnection.cjs +0 -29
  103. package/dist/active-citizen/utils/to_json.cjs +0 -9
  104. package/dist/active-citizen/utils/translation_cloning.cjs +0 -171
  105. package/dist/active-citizen/utils/translation_helpers.cjs +0 -534
  106. package/dist/active-citizen/utils/truncate_text.cjs +0 -21
  107. package/dist/active-citizen/utils/updateAllLocalesFromEn.js +0 -253
  108. package/dist/active-citizen/utils/updateLocaleFolders.js +0 -34
  109. package/dist/active-citizen/workers/activity.cjs +0 -189
  110. package/dist/active-citizen/workers/anonymizations.cjs +0 -734
  111. package/dist/active-citizen/workers/bulk_status_update.cjs +0 -458
  112. package/dist/active-citizen/workers/delayed_jobs.cjs +0 -244
  113. package/dist/active-citizen/workers/deletions.cjs +0 -1911
  114. package/dist/active-citizen/workers/email.cjs +0 -9
  115. package/dist/active-citizen/workers/fraud_management.cjs +0 -109
  116. package/dist/active-citizen/workers/generativeAi.js +0 -56
  117. package/dist/active-citizen/workers/main.cjs +0 -89
  118. package/dist/active-citizen/workers/marketing.cjs +0 -25
  119. package/dist/active-citizen/workers/moderation.cjs +0 -73
  120. package/dist/active-citizen/workers/notification_delivery.cjs +0 -368
  121. package/dist/active-citizen/workers/notification_news_feed.cjs +0 -142
  122. package/dist/active-citizen/workers/queue.cjs +0 -99
  123. package/dist/active-citizen/workers/recount.cjs +0 -74
  124. package/dist/active-citizen/workers/reports.cjs +0 -42
  125. package/dist/active-citizen/workers/similarities.cjs +0 -21
  126. package/dist/active-citizen/workers/speech_to_text.cjs +0 -482
  127. package/dist/agents/assistants/agentAssistant.js +0 -88
  128. package/dist/agents/assistants/baseAssistant.js +0 -888
  129. package/dist/agents/assistants/baseAssistantWithVoice.js +0 -150
  130. package/dist/agents/assistants/modes/agentDirectConnection.js +0 -84
  131. package/dist/agents/assistants/modes/agentSelectionMode.js +0 -44
  132. package/dist/agents/assistants/modes/baseAssistantMode.js +0 -54
  133. package/dist/agents/assistants/modes/tools/agentTools.js +0 -447
  134. package/dist/agents/assistants/modes/tools/baseTools.js +0 -58
  135. package/dist/agents/assistants/modes/tools/loginTools.js +0 -156
  136. package/dist/agents/assistants/modes/tools/models/agents.js +0 -146
  137. package/dist/agents/assistants/modes/tools/models/subscriptions.js +0 -332
  138. package/dist/agents/assistants/modes/tools/models/users.js +0 -11
  139. package/dist/agents/assistants/modes/tools/navigationTools.js +0 -166
  140. package/dist/agents/assistants/modes/tools/subscriptionTools.js +0 -323
  141. package/dist/agents/assistants/modes/tools/workflowConverstationTools.js +0 -112
  142. package/dist/agents/assistants/voiceAssistant.js +0 -619
  143. package/dist/agents/controllers/agentProductController.js +0 -103
  144. package/dist/agents/controllers/agentSubscriptionController.js +0 -261
  145. package/dist/agents/controllers/assistantsController.js +0 -511
  146. package/dist/agents/controllers/policySynthAgents.js +0 -395
  147. package/dist/agents/managers/agentProductManager.js +0 -91
  148. package/dist/agents/managers/emailInvitesManager.js +0 -55
  149. package/dist/agents/managers/emailTemplateRenderer.js +0 -362
  150. package/dist/agents/managers/newAiModelSetup.js +0 -650
  151. package/dist/agents/managers/notificationAgentQueueManager.js +0 -510
  152. package/dist/agents/managers/subscriptionManager.js +0 -535
  153. package/dist/agents/managers/workflowConversationManager.js +0 -79
  154. package/dist/agents/models/agentProduct.js +0 -116
  155. package/dist/agents/models/agentProductBoosterPurchase.js +0 -58
  156. package/dist/agents/models/agentProductBundle.js +0 -68
  157. package/dist/agents/models/agentProductRun.js +0 -52
  158. package/dist/agents/models/discount.js +0 -88
  159. package/dist/agents/models/subscription.js +0 -79
  160. package/dist/agents/models/subscriptionPlan.js +0 -46
  161. package/dist/agents/models/subscriptionUser.js +0 -27
  162. package/dist/agents/models/testData/createEvolyAgentProduct.js +0 -477
  163. package/dist/agents/models/testData/old/updateAgentWorkflowConfiguration.js +0 -230
  164. package/dist/agents/models/testData/setupEvolyAgentProductConfig.js +0 -233
  165. package/dist/agents/models/testData/updateAgentWorkflowConfiguration.js +0 -230
  166. package/dist/agents/models/workflowConversation.js +0 -53
  167. package/dist/agents/tools/setTemplateWorkflowCommunityId.js +0 -46
  168. package/dist/app.js +0 -943
  169. package/dist/authorization.cjs +0 -1860
  170. package/dist/bot_control.js +0 -1930
  171. package/dist/config/config.cjs +0 -14
  172. package/dist/config/config.js +0 -14
  173. package/dist/controllers/allOurIdeas.js +0 -696
  174. package/dist/controllers/audios.cjs +0 -100
  175. package/dist/controllers/bulkStatusUpdates.cjs +0 -202
  176. package/dist/controllers/categories.cjs +0 -199
  177. package/dist/controllers/communities.cjs +0 -2996
  178. package/dist/controllers/domains.cjs +0 -1341
  179. package/dist/controllers/externalIds.cjs +0 -223
  180. package/dist/controllers/groups.cjs +0 -4309
  181. package/dist/controllers/images.cjs +0 -499
  182. package/dist/controllers/index.cjs +0 -449
  183. package/dist/controllers/legacyPages.cjs +0 -35
  184. package/dist/controllers/legacyPosts.cjs +0 -56
  185. package/dist/controllers/legacyUsers.cjs +0 -36
  186. package/dist/controllers/nonSpa.cjs +0 -574
  187. package/dist/controllers/organizations.cjs +0 -250
  188. package/dist/controllers/points.cjs +0 -1137
  189. package/dist/controllers/posts.cjs +0 -2036
  190. package/dist/controllers/ratings.cjs +0 -234
  191. package/dist/controllers/users.cjs +0 -2255
  192. package/dist/controllers/videos.cjs +0 -226
  193. package/dist/deleteUnwantedDeclerations.cjs +0 -55
  194. package/dist/migrations/agentAuditLogs.cjs +0 -46
  195. package/dist/migrations/agentClasses.cjs +0 -60
  196. package/dist/migrations/agentConnectorClasses.cjs +0 -61
  197. package/dist/migrations/agentConnectors.cjs +0 -50
  198. package/dist/migrations/agentEvals.cjs +0 -45
  199. package/dist/migrations/agentRegistries.cjs +0 -40
  200. package/dist/migrations/agents.cjs +0 -54
  201. package/dist/migrations/aiModels.cjs +0 -49
  202. package/dist/migrations/apiUsage.cjs +0 -47
  203. package/dist/migrations/apis.cjs +0 -49
  204. package/dist/migrations/groupPrivateData.cjs +0 -30
  205. package/dist/migrations/modelUsage.cjs +0 -60
  206. package/dist/migrations/oldMigrations/2019/20181030020612-AddActivitiesIndex.js +0 -23
  207. package/dist/migrations/oldMigrations/2019/20181102210612-AddFirstVideoFeatures.js +0 -360
  208. package/dist/migrations/oldMigrations/2019/20181212210612-ModerationFeatures.js +0 -29
  209. package/dist/migrations/oldMigrations/2019/2019010610612-CommunityFolders.js +0 -43
  210. package/dist/migrations/oldMigrations/2019/20190117020612-AddMissingIndexes.js +0 -24
  211. package/dist/migrations/oldMigrations/2019/20190117020612-RemoveUnusedIndexes.js +0 -29
  212. package/dist/migrations/oldMigrations/2019/20190127020612-RemoveUnusedIndexesPartThree.js +0 -22
  213. package/dist/migrations/oldMigrations/2019/20190127020612-RemoveUnusedIndexesPartTwo.js +0 -23
  214. package/dist/migrations/oldMigrations/2019/20190223020612-AddPrivateProfileDataToUsers.js +0 -18
  215. package/dist/migrations/oldMigrations/2019/20190706210612-AddCustomRatings.js +0 -43
  216. package/dist/migrations/oldMigrations/2019/20190829210612-AddGeneralStore.js +0 -36
  217. package/dist/migrations/oldMigrations/2019/20192811210612-AddAcClientActivities.js +0 -41
  218. package/dist/migrations/oldMigrations/2020/20190527020612-WorkOnIndexes.js +0 -88
  219. package/dist/migrations/oldMigrations/2020/20200409020612-AddBackgroundJob.js +0 -33
  220. package/dist/migrations/oldMigrations/2020/20200716210612-AddDataToCollections.js +0 -38
  221. package/dist/migrations/oldMigrations/2022/20220215100612-AddDataToEndorsements.js +0 -19
  222. package/dist/migrations/oldMigrations/2022/20220220100612-AddDataForFraudDetection.js +0 -19
  223. package/dist/migrations/oldMigrations/2022/20220903100612-AddPromotionFeatures.js +0 -127
  224. package/dist/migrations/oldMigrations/2022/onHold/20200527020612-AddCampaigns.js +0 -68
  225. package/dist/migrations/oldMigrations/2024/20241304175112-AddMediaSupportForHtmlGroups.cjs +0 -63
  226. package/dist/migrations/oldMigrations/older/20160511172514-AddNotificationFeatures.js +0 -14
  227. package/dist/migrations/oldMigrations/older/20161030020612-AddBulkStatusUpdate.js +0 -71
  228. package/dist/migrations/oldMigrations/older/20170514035258-add-metadata-to-invites.js +0 -12
  229. package/dist/migrations/oldMigrations/older/20180216020612-AddTranslationCaches.js +0 -46
  230. package/dist/migrations/oldMigrations/older/20180218210612-AddTranslationAndLanguages.js +0 -46
  231. package/dist/migrations/privateAccessStore.cjs +0 -55
  232. package/dist/migrations/zzz_associations.cjs +0 -154
  233. package/dist/migrations/zzzz_createUsersAndAdminsForClasses.cjs +0 -100
  234. package/dist/migrations/zzzzz_create_agent_runs.cjs +0 -606
  235. package/dist/migrations/zzzzzz_create_agent_runs_fix.cjs +0 -11
  236. package/dist/migrations/zzzzzzz_create_trees.cjs +0 -81
  237. package/dist/models/audio.cjs +0 -430
  238. package/dist/models/bulk_status_update.cjs +0 -58
  239. package/dist/models/campaign.cjs +0 -78
  240. package/dist/models/category.cjs +0 -94
  241. package/dist/models/community.cjs +0 -337
  242. package/dist/models/domain.cjs +0 -486
  243. package/dist/models/endorsement.cjs +0 -39
  244. package/dist/models/general_data_store.cjs +0 -20
  245. package/dist/models/group.cjs +0 -728
  246. package/dist/models/image.cjs +0 -579
  247. package/dist/models/index.cjs +0 -186
  248. package/dist/models/invite.cjs +0 -48
  249. package/dist/models/iso_country.cjs +0 -16
  250. package/dist/models/organization.cjs +0 -122
  251. package/dist/models/page.cjs +0 -273
  252. package/dist/models/point.cjs +0 -622
  253. package/dist/models/point_quality.cjs +0 -39
  254. package/dist/models/point_revision.cjs +0 -47
  255. package/dist/models/post.cjs +0 -680
  256. package/dist/models/post_revision.cjs +0 -38
  257. package/dist/models/post_status_change.cjs +0 -35
  258. package/dist/models/promotion.cjs +0 -34
  259. package/dist/models/rating.cjs +0 -51
  260. package/dist/models/relationship.cjs +0 -19
  261. package/dist/models/request_to_join.cjs +0 -20
  262. package/dist/models/user.cjs +0 -604
  263. package/dist/models/user_legacy_password.cjs +0 -13
  264. package/dist/models/video.cjs +0 -1137
  265. package/dist/publish.js +0 -40
  266. package/dist/repack.js +0 -53
  267. package/dist/scripts/addRatingUsersToGroup.js +0 -51
  268. package/dist/scripts/addUserToOrganization.js +0 -71
  269. package/dist/scripts/analyseRatingsForCommunity.js +0 -150
  270. package/dist/scripts/analyzeAndFixBrokenPointUsers.js +0 -28
  271. package/dist/scripts/analyzeEndorsementsByCountry.js +0 -70
  272. package/dist/scripts/analyzePostsForCommunity.js +0 -185
  273. package/dist/scripts/bulkStatusUpdates/listUpdates.js +0 -14
  274. package/dist/scripts/bulkStatusUpdates/mergeLatestPostsToUpdate.js +0 -110
  275. package/dist/scripts/bulkStatusUpdates/performUpdate.js +0 -116
  276. package/dist/scripts/bulkStatusUpdates/performUpdateForGroup.cjs +0 -124
  277. package/dist/scripts/bulkStatusUpdates/performUpdateForStatus.js +0 -141
  278. package/dist/scripts/change/changeVideoAspectTo.js +0 -34
  279. package/dist/scripts/change/setUseNewVersion.cjs +0 -22
  280. package/dist/scripts/changeCommunityGroupcount.js +0 -30
  281. package/dist/scripts/changeCommunityPostCount.js +0 -30
  282. package/dist/scripts/changeGroupPostCount.js +0 -30
  283. package/dist/scripts/changeLanguage.js +0 -50
  284. package/dist/scripts/changeOfficalStatus.js +0 -30
  285. package/dist/scripts/cleanups/deleteAnonNotifications.cjs +0 -91
  286. package/dist/scripts/cleanups/deleteLinkGroupsWithDeletedCommunities.js +0 -62
  287. package/dist/scripts/cleanups/deleteYearOldNotifications.cjs +0 -72
  288. package/dist/scripts/cleanups/removeAllUsersFromHiddenPublicGroup.js +0 -43
  289. package/dist/scripts/clearAllEndorsementInGroup.js +0 -50
  290. package/dist/scripts/cloning/clearUsersForCommunitiesFromUrl.js +0 -129
  291. package/dist/scripts/cloning/cloneFromUrlScript.js +0 -65
  292. package/dist/scripts/cloning/cloneWBFromUrlScriptAndCreateLinks.js +0 -140
  293. package/dist/scripts/cloning/cloneWBFromUrlScriptNoUsersOrPoints.js +0 -140
  294. package/dist/scripts/cloning/cloneWBSerbianFromUrlScriptAndCreateLinks.js +0 -131
  295. package/dist/scripts/cloning/copyCommunityConfigAndTranslationsFromURL.js +0 -173
  296. package/dist/scripts/cloning/copyCommunityOneGroupToDomainNoUsersNoEndorsements.js +0 -18
  297. package/dist/scripts/cloning/copyCommunityToDomainNoUsersNoEndorsements.js +0 -17
  298. package/dist/scripts/cloning/copyCommunityToDomainWithEverything.js +0 -17
  299. package/dist/scripts/cloning/copyCommunityToDomainWithOnlyGroups.js +0 -26
  300. package/dist/scripts/cloning/copyGroupConfigAndTranslationsFromURL.js +0 -205
  301. package/dist/scripts/cloning/copyPostToGroupOld.js +0 -397
  302. package/dist/scripts/cloning/copyPostVideosFromURL.js +0 -236
  303. package/dist/scripts/cloning/copyPostWithOutAnyVotingOrActivities.js +0 -17
  304. package/dist/scripts/cloning/deepCloneSerbianWBFromUrlScriptAndCreateLinks.js +0 -131
  305. package/dist/scripts/cloning/deepCloneWBFromUrlScriptAndCreateLinks.js +0 -139
  306. package/dist/scripts/cloning/setAdminsFromURL.js +0 -161
  307. package/dist/scripts/cloning/setExternalIdsFromURL.js +0 -129
  308. package/dist/scripts/countCommunity.js +0 -291
  309. package/dist/scripts/countCommunityUsers.js +0 -152
  310. package/dist/scripts/countDelayedNotifications.js +0 -18
  311. package/dist/scripts/countGroup.js +0 -246
  312. package/dist/scripts/countStuff.js +0 -67
  313. package/dist/scripts/countUniqueVotersInAGroup.js +0 -48
  314. package/dist/scripts/createInvitesAndShow.js +0 -75
  315. package/dist/scripts/database/sync_database.js +0 -14
  316. package/dist/scripts/database/sync_dev_database.js +0 -17
  317. package/dist/scripts/debugNotifications.js +0 -58
  318. package/dist/scripts/deleteAllNewsFeeds.js +0 -10
  319. package/dist/scripts/deleteCategory.js +0 -13
  320. package/dist/scripts/deleteOldAppActivities.js +0 -40
  321. package/dist/scripts/deletePostContactDataForCommunity.js +0 -53
  322. package/dist/scripts/destroy/destroy_all_but_one_domain.js +0 -1026
  323. package/dist/scripts/displayAuthorForPost.js +0 -16
  324. package/dist/scripts/endorsementFraudDetection/analyseEndorsementsForCommunity.js +0 -183
  325. package/dist/scripts/endorsementFraudDetection/bulkDeleteDuplicateEndorsmentsFromUrl.js +0 -208
  326. package/dist/scripts/exportAllStatusChanges.js +0 -36
  327. package/dist/scripts/exportClientAcitivity.js +0 -36
  328. package/dist/scripts/exportEndorsementsForCommunity.js +0 -79
  329. package/dist/scripts/exportPointQualitiesForCommunity.js +0 -84
  330. package/dist/scripts/exportPostsAndPointsForCommunity.js +0 -147
  331. package/dist/scripts/exportPostsDataSetForDomain.js +0 -244
  332. package/dist/scripts/exportPostsForGroup.js +0 -173
  333. package/dist/scripts/exportRatingsForPost.js +0 -15
  334. package/dist/scripts/exportUserEndorsementsWithUserAnalysis.js +0 -123
  335. package/dist/scripts/exportUsersForCommunity.js +0 -24
  336. package/dist/scripts/exportUsersForDomain.js +0 -24
  337. package/dist/scripts/exportUsersForGroup.js +0 -24
  338. package/dist/scripts/exports/ratingDistribution.js +0 -71
  339. package/dist/scripts/exports/whoEndorsedWhatByCommunity.js +0 -56
  340. package/dist/scripts/findUnusedClientImports.js +0 -56
  341. package/dist/scripts/fixAllPostPointCounts.js +0 -22
  342. package/dist/scripts/fixAnonNotificationsSettings.js +0 -48
  343. package/dist/scripts/fixCountKopavogur.js +0 -9
  344. package/dist/scripts/fixEndorsementsAfterCopyPostToGroup.js +0 -190
  345. package/dist/scripts/fixExternalUserId.js +0 -24
  346. package/dist/scripts/fixGroupAccess.js +0 -16
  347. package/dist/scripts/fixGroupIdeasAndPointsCount.js +0 -49
  348. package/dist/scripts/fixNotificationSettings.js +0 -39
  349. package/dist/scripts/fixSurveyRadioBakedInSubCodes.js +0 -64
  350. package/dist/scripts/fixWrongUserIdForStatusUpdates.js +0 -49
  351. package/dist/scripts/gallery/exportGalleryData.js +0 -40
  352. package/dist/scripts/gallery/importGalleryForCommunity.js +0 -168
  353. package/dist/scripts/gallery/readJsonAndDownloadImagesVersion2.js +0 -55
  354. package/dist/scripts/gallery/refreshAcApiPostIdsForCommunity.js +0 -58
  355. package/dist/scripts/genderAnalysis.js +0 -63
  356. package/dist/scripts/genderAnalysisByStatus.js +0 -62
  357. package/dist/scripts/importAllLocalesFromLocalFolders.js +0 -55
  358. package/dist/scripts/importDomain.js +0 -1652
  359. package/dist/scripts/keys/addOidcToDomain.cjs +0 -61
  360. package/dist/scripts/landUseGame/export3Ddata.js +0 -162
  361. package/dist/scripts/listLanguagesForGroup.js +0 -54
  362. package/dist/scripts/loadTestCreateDummyContentForGroup.js +0 -27
  363. package/dist/scripts/makeRecursiveMapData.js +0 -103
  364. package/dist/scripts/mapping/community_map_csv.js +0 -145
  365. package/dist/scripts/moveCommunityToDomain.js +0 -22
  366. package/dist/scripts/moveGroupToCommunity.js +0 -23
  367. package/dist/scripts/movePostToGroup.js +0 -101
  368. package/dist/scripts/movePostsToGroupsRecountGroupFromUrl.js +0 -297
  369. package/dist/scripts/oldMovePostToGroup.js +0 -153
  370. package/dist/scripts/processCsvForPdfUrls.js +0 -37
  371. package/dist/scripts/processCsvForTranslationAndToxicity.js +0 -125
  372. package/dist/scripts/recount/recount_recursive_communities.js +0 -125
  373. package/dist/scripts/recountALLCommunityGroupCounts.js +0 -37
  374. package/dist/scripts/recountAll.js +0 -97
  375. package/dist/scripts/recountCommunitesFromUrl.js +0 -58
  376. package/dist/scripts/recountCommunity.js +0 -19
  377. package/dist/scripts/recountGroup.js +0 -218
  378. package/dist/scripts/recountGroupNoUserChange.js +0 -219
  379. package/dist/scripts/resetAllEndorsementsForGroup.js +0 -57
  380. package/dist/scripts/resetEnTranslationForGroup.js +0 -45
  381. package/dist/scripts/setAdminOnAll.cjs +0 -107
  382. package/dist/scripts/setDomainAdmin.cjs +0 -43
  383. package/dist/scripts/setDomainLocales.js +0 -33
  384. package/dist/scripts/setEarlQuestionIdOnGroup.cjs +0 -29
  385. package/dist/scripts/setLanguageOnGroupCommunitesFromUrl.js +0 -86
  386. package/dist/scripts/setMemberOfAll.js +0 -101
  387. package/dist/scripts/setNewUserForContentOfCommunity.js +0 -189
  388. package/dist/scripts/setOfficialStatusOnAllPostsForCommunity.js +0 -35
  389. package/dist/scripts/setUserOnAll.js +0 -101
  390. package/dist/scripts/showCategoryForGroup.js +0 -18
  391. package/dist/scripts/showOldActivityTypes.js +0 -14
  392. package/dist/scripts/showPostsMissingCategoryForGroup.js +0 -17
  393. package/dist/scripts/showStatuses.js +0 -17
  394. package/dist/scripts/showUniqueVotersInCommunity.js +0 -61
  395. package/dist/scripts/showUserAgentsAndIpsForEmails.js +0 -66
  396. package/dist/scripts/simpleExportForGroupsForCommunity.js +0 -46
  397. package/dist/scripts/simpleExportForPointsForCommunity.js +0 -82
  398. package/dist/scripts/simpleExportForPostsForCommunity.js +0 -61
  399. package/dist/scripts/testForEndorsments.js +0 -21
  400. package/dist/scripts/undeleteGroupAndAllContent.js +0 -151
  401. package/dist/scripts/undeletePost.js +0 -135
  402. package/dist/scripts/unlinkSsn.js +0 -23
  403. package/dist/scripts/updateFromAlthingi.js +0 -303
  404. package/dist/server.js +0 -3
  405. package/dist/utils/airbrake.cjs +0 -17
  406. package/dist/utils/cjsCodeReview.js +0 -99
  407. package/dist/utils/community_mapping_tools.cjs +0 -124
  408. package/dist/utils/copy_utils.cjs +0 -1399
  409. package/dist/utils/docx_utils.cjs +0 -464
  410. package/dist/utils/export_utils.cjs +0 -491
  411. package/dist/utils/i18n.cjs +0 -17
  412. package/dist/utils/is_valid_db_id.cjs +0 -28
  413. package/dist/utils/logger.cjs +0 -25
  414. package/dist/utils/loggerTs.js +0 -26
  415. package/dist/utils/manifest_generator.cjs +0 -104
  416. package/dist/utils/parse_domain.cjs +0 -16
  417. package/dist/utils/recount_utils.cjs +0 -415
  418. package/dist/utils/sharing_parameters.cjs +0 -111
  419. package/dist/utils/sitemap_generator.cjs +0 -286
  420. package/dist/utils/to_json.cjs +0 -14
  421. package/dist/utils/ypLanguages.js +0 -747
  422. package/dist/webSockets.js +0 -77
package/dist/app.js DELETED
@@ -1,943 +0,0 @@
1
- import express from "express";
2
- import session from "express-session";
3
- import path from "path";
4
- import morgan from "morgan";
5
- import bodyParser from "body-parser";
6
- import { RedisStore } from "connect-redis";
7
- import useragent from "express-useragent";
8
- import requestIp from "request-ip";
9
- import compression from "compression";
10
- import { isbot } from "isbot";
11
- import rateLimit from "express-rate-limit";
12
- import passport from "passport";
13
- import models from "./models/index.cjs";
14
- if (process.env.NEW_RELIC_APP_NAME) {
15
- import("newrelic")
16
- .then((newrelic) => {
17
- console.log("New Relic imported", newrelic);
18
- })
19
- .catch((err) => {
20
- console.error("Failed to import New Relic", err);
21
- });
22
- }
23
- import auth from "./authorization.cjs";
24
- import index from "./controllers/index.cjs";
25
- import news_feeds from "./active-citizen/controllers/news_feeds.cjs";
26
- import activities from "./active-citizen/controllers/activities.cjs";
27
- import notifications from "./active-citizen/controllers/notifications.cjs";
28
- import recommendations from "./active-citizen/controllers/recommendations.cjs";
29
- import posts from "./controllers/posts.cjs";
30
- import groups from "./controllers/groups.cjs";
31
- import communities from "./controllers/communities.cjs";
32
- import domains from "./controllers/domains.cjs";
33
- import organizations from "./controllers/organizations.cjs";
34
- import points from "./controllers/points.cjs";
35
- import users from "./controllers/users.cjs";
36
- import categories from "./controllers/categories.cjs";
37
- import images from "./controllers/images.cjs";
38
- import externalIds from "./controllers/externalIds.cjs";
39
- import ratings from "./controllers/ratings.cjs";
40
- import bulkStatusUpdates from "./controllers/bulkStatusUpdates.cjs";
41
- import videos from "./controllers/videos.cjs";
42
- import audios from "./controllers/audios.cjs";
43
- import legacyPosts from "./controllers/legacyPosts.cjs";
44
- import legacyUsers from "./controllers/legacyUsers.cjs";
45
- import legacyPages from "./controllers/legacyPages.cjs";
46
- import nonSPArouter from "./controllers/nonSpa.cjs";
47
- import generateSitemap from "./utils/sitemap_generator.cjs";
48
- import generateManifest from "./utils/manifest_generator.cjs";
49
- import toJson from "./utils/to_json.cjs";
50
- //@ts-ignore
51
- import sso from "passport-sso";
52
- import cors from "cors";
53
- import log from "./utils/loggerTs.js";
54
- import { createClient } from "redis";
55
- import { Notifier } from "@airbrake/node";
56
- import { fileURLToPath } from "url";
57
- const __dirname = path.dirname(fileURLToPath(import.meta.url));
58
- let airbrake;
59
- if (process.env.AIRBRAKE_PROJECT_ID && process.env.AIRBRAKE_API_KEY) {
60
- airbrake = new Notifier({
61
- projectId: parseInt(process.env.AIRBRAKE_PROJECT_ID),
62
- projectKey: process.env.AIRBRAKE_API_KEY,
63
- performanceStats: false,
64
- });
65
- }
66
- process.on("uncaughtException", (err) => {
67
- console.error("There was an uncaught error", err);
68
- log.error("There was an uncaught error", err);
69
- if (err.stack) {
70
- console.error(err.stack);
71
- log.error(err.stack);
72
- }
73
- if (airbrake) {
74
- airbrake.notify(err).then((airbrakeErr) => {
75
- if (airbrakeErr.error) {
76
- log.error("AirBrake Error Internal", {
77
- context: "airbrake",
78
- err: airbrakeErr.error,
79
- errorStatus: 500,
80
- });
81
- }
82
- });
83
- }
84
- //TODO: What else do we want to do here? We need to exit but can we restart it right away?
85
- process.exit(1);
86
- });
87
- process.on("unhandledRejection", (reason, promise) => {
88
- console.error("Unhandled Rejection at:", promise, "reason:", reason);
89
- log.error("Unhandled Rejection at:", promise, "reason:", reason);
90
- if (reason.stack) {
91
- console.error(reason.stack);
92
- log.error("Unhandled Rejection at:", promise, "reason:", reason);
93
- }
94
- if (airbrake) {
95
- airbrake.notify(reason).then((airbrakeErr) => {
96
- if (airbrakeErr.error) {
97
- log.error("AirBrake Error", {
98
- context: "airbrake",
99
- err: airbrakeErr.error,
100
- errorStatus: 500,
101
- });
102
- }
103
- });
104
- }
105
- //TODO: Look if this is safe to do in production, should be
106
- if (process.env.NODE_ENV !== "production") {
107
- process.exit(1);
108
- }
109
- });
110
- import { botsWithJavascript, isBadBot, } from "./bot_control.js";
111
- import { Op } from "sequelize";
112
- import { WebSocketsManager } from "./webSockets.js";
113
- export class YourPrioritiesApi {
114
- constructor(port = undefined) {
115
- this.determineVersion = (req) => {
116
- // Check query parameter first
117
- if (req.query.useNewVersion === "true")
118
- return true;
119
- if (req.query.useNewVersion === "false")
120
- return false;
121
- // Then check session
122
- if (req.session.useNewVersion === true)
123
- return true;
124
- if (req.session.useNewVersion === false)
125
- return false;
126
- // Finally, check domain configuration
127
- if (req.ypDomain?.configuration?.useNewVersion === true)
128
- return true;
129
- // Default to false (old version)
130
- return false;
131
- };
132
- this.bearerCallback = function () {
133
- return console.log("The user has tried to authenticate with a bearer token");
134
- };
135
- this.completeRegisterUserLogin = (user, // Replace 'any' with the actual user type
136
- loginType, req, // Replace 'any' with 'YpRequest' if it's the correct type
137
- done) => {
138
- user.last_login_at = new Date().getTime(); // Assuming your database expects a timestamp
139
- user
140
- .save()
141
- .then(() => {
142
- models.AcActivity.createActivity({
143
- type: "activity.user.login",
144
- userId: user.id,
145
- domainId: req.ypDomain.id,
146
- communityId: req.ypCommunity ? req.ypCommunity.id : null,
147
- object: {
148
- loginType: loginType,
149
- userDepartment: user.private_profile_data
150
- ? user.private_profile_data.saml_agency
151
- : null,
152
- samlProvider: user.private_profile_data
153
- ? user.private_profile_data.saml_provider
154
- : null,
155
- },
156
- access: models.AcActivity.PRIVATE,
157
- }, (error) => {
158
- if (error) {
159
- log.error("Error creating activity for user login", { error });
160
- }
161
- done();
162
- });
163
- })
164
- .catch((error) => {
165
- log.error("Error saving user for login registration", { error });
166
- done();
167
- });
168
- };
169
- this.registerUserLogin = (user, userId, loginProvider, req, done) => {
170
- if (user && user.private_profile_data) {
171
- this.completeRegisterUserLogin(user, loginProvider, req, done);
172
- }
173
- else {
174
- models.User.findOne({
175
- where: { id: userId },
176
- attributes: ["id", "private_profile_data", "last_login_at"],
177
- })
178
- .then((user) => {
179
- if (user) {
180
- this.completeRegisterUserLogin(user, loginProvider, req, done);
181
- }
182
- else {
183
- log.error("Did not find user for login registration", { userId });
184
- done();
185
- }
186
- })
187
- .catch((error) => {
188
- log.error("Error saving user for login registration", { error });
189
- done();
190
- });
191
- }
192
- };
193
- this.app = express();
194
- this.port = port || (process.env.PORT ? parseInt(process.env.PORT) : 4242);
195
- this.wsClients = new Map();
196
- this.initializeRedis();
197
- this.addRedisToRequest();
198
- this.addDirnameToRequest();
199
- this.forceHttps();
200
- this.initializeMiddlewares();
201
- this.setupNewWebAppVersionHandling();
202
- this.handleShortenedRedirects();
203
- this.initializeRateLimiting();
204
- this.setupDomainAndCommunity();
205
- this.setupSitemapRoute();
206
- this.initializePassportStrategies();
207
- this.addInviteAsAnonMiddleWare();
208
- this.setupStaticFileServing();
209
- this.checkAuthForSsoInit();
210
- this.initializeRoutes();
211
- this.initializeEsControllers();
212
- }
213
- async initialize() {
214
- await this.initializeRedis();
215
- this.addRedisToRequest();
216
- this.addDirnameToRequest();
217
- this.forceHttps();
218
- this.initializeMiddlewares();
219
- this.setupNewWebAppVersionHandling();
220
- this.handleShortenedRedirects();
221
- this.initializeRateLimiting();
222
- this.setupDomainAndCommunity();
223
- this.setupSitemapRoute();
224
- this.initializePassportStrategies();
225
- this.addInviteAsAnonMiddleWare();
226
- this.setupStaticFileServing();
227
- this.checkAuthForSsoInit();
228
- this.initializeRoutes();
229
- this.initializeEsControllers();
230
- }
231
- setupNewWebAppVersionHandling() {
232
- this.app.use((req, res, next) => {
233
- req.useNewVersion = this.determineVersion(req);
234
- if (req.session) {
235
- req.session.useNewVersion = req.useNewVersion;
236
- }
237
- else {
238
- console.error("Session not found in request");
239
- }
240
- next();
241
- });
242
- }
243
- async initializeRedis() {
244
- if (process.env.REDIS_URL) {
245
- let redisUrl = process.env.REDIS_URL;
246
- if (redisUrl.startsWith("redis://h:")) {
247
- redisUrl = redisUrl.replace("redis://h:", "redis://:");
248
- }
249
- this.redisClient = createClient({
250
- legacyMode: false,
251
- url: redisUrl,
252
- pingInterval: 10000,
253
- socket: {
254
- tls: redisUrl.startsWith("rediss://"),
255
- rejectUnauthorized: false,
256
- },
257
- });
258
- }
259
- else {
260
- this.redisClient = createClient({ legacyMode: false });
261
- }
262
- this.redisClient.on("error", (err) => {
263
- console.error("App Redis client error", err);
264
- });
265
- this.redisClient.on("connect", () => {
266
- console.log("App Redis client is connected");
267
- });
268
- this.redisClient.on("reconnecting", () => {
269
- console.log("App Redis client is reconnecting");
270
- });
271
- this.redisClient.on("ready", () => {
272
- console.log("App Redis client is ready");
273
- });
274
- try {
275
- await this.redisClient.connect();
276
- }
277
- catch (err) {
278
- console.error("App Failed to connect Redis client", err);
279
- }
280
- }
281
- addRedisToRequest() {
282
- this.app.use((req, res, next) => {
283
- if (this.redisClient && typeof this.redisClient.get === "function") {
284
- req.redisClient = this.redisClient;
285
- }
286
- else {
287
- log.error("Redis client get method not found or client not initialized");
288
- }
289
- next();
290
- });
291
- }
292
- addDirnameToRequest() {
293
- this.app.use((req, res, next) => {
294
- req.dirName = __dirname;
295
- next();
296
- });
297
- }
298
- addInviteAsAnonMiddleWare() {
299
- this.app.use(async (req, res, next) => {
300
- if (req.query.anonInvite && req.query.token) {
301
- const token = req.query.token;
302
- try {
303
- //TODO: Fix this "as any" in all places
304
- const invite = await models.Invite.findOne({
305
- where: {
306
- token,
307
- joined_at: null,
308
- type: models.Invite
309
- .INVITE_TO_COMMUNITY_AND_GROUP_AS_ANON,
310
- deleted: false,
311
- [Op.or]: [
312
- { expires_at: null },
313
- { expires_at: { [Op.gt]: new Date() } },
314
- ],
315
- },
316
- });
317
- if (invite) {
318
- const anonEmail = req.sessionID + "_v3anonymous@citizens.is";
319
- let user;
320
- if (req.user) {
321
- user = req.user;
322
- }
323
- else {
324
- user = await models.User.findOne({
325
- where: { email: anonEmail },
326
- });
327
- }
328
- if (!user) {
329
- user = await models.User.create({
330
- email: anonEmail,
331
- name: "Invited User",
332
- notifications_settings: models.AcNotification
333
- .anonymousNotificationSettings,
334
- status: "active",
335
- //TODO: Having this blocks security for the cloned groups, find a better solution
336
- //profile_data: { isAnonymousUser: true },
337
- });
338
- }
339
- // Associate user with community
340
- if (invite.community_id) {
341
- const community = await models.Community.findByPk(invite.community_id);
342
- if (community) {
343
- await community.addCommunityUsers(user);
344
- }
345
- }
346
- // Associate user with group
347
- if (invite.group_id) {
348
- const group = await models.Group.findByPk(invite.group_id);
349
- if (group) {
350
- await group.addGroupUsers(user);
351
- }
352
- }
353
- // Mark invite as used
354
- invite.joined_at = new Date();
355
- await invite.save();
356
- console.log("Invite joined at", invite.joined_at);
357
- await new Promise((resolve, reject) => {
358
- req.logIn(user, (error) => (error ? reject(error) : resolve()));
359
- });
360
- console.log("User logged in for anon invite");
361
- return next();
362
- }
363
- else {
364
- console.error("Invite not found");
365
- return next();
366
- }
367
- }
368
- catch (err) {
369
- log.error("Error in anonInvite middleware", { err });
370
- }
371
- }
372
- next();
373
- });
374
- }
375
- forceHttps() {
376
- if (this.app.get("env") !== "development" &&
377
- !process.env.DISABLE_FORCE_HTTPS) {
378
- this.app.use((req, res, next) => {
379
- if (!/https/.test(req.protocol)) {
380
- res.redirect("https://" + req.headers.host + req.url);
381
- }
382
- else {
383
- return next();
384
- }
385
- });
386
- }
387
- }
388
- handleShortenedRedirects() {
389
- this.app.use((req, res, next) => {
390
- if (req.path.startsWith("/s/")) {
391
- res.redirect(`${req.protocol}://${req.headers.host}${req.url.replace("/s/", "/survey/")}`);
392
- }
393
- else if (req.path.startsWith("/g/")) {
394
- res.redirect(`${req.protocol}://${req.headers.host}${req.url.replace("/g/", "/group/")}`);
395
- }
396
- else if (req.path.startsWith("/c/")) {
397
- res.redirect(`${req.protocol}://${req.headers.host}${req.url.replace("/c/", "/community/")}`);
398
- }
399
- else {
400
- return next();
401
- }
402
- });
403
- }
404
- handleServiceWorker(req, res) {
405
- res.setHeader("Cache-Control", "no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0");
406
- res.setHeader("Last-Modified", new Date().toUTCString());
407
- const filePath = req.path.includes("/sw.js")
408
- ? path.join(__dirname, "../webAppsDist/client/dist/sw.js")
409
- : path.join(__dirname, "../webAppsDist/old/client/build/bundled/service-worker.js");
410
- res.sendFile(filePath);
411
- }
412
- setupDomainAndCommunity() {
413
- this.app.use((req, res, next) => {
414
- models.Domain.setYpDomain(req, res, () => {
415
- log.info("Domain", {
416
- id: req.ypDomain ? req.ypDomain.id : "-1",
417
- n: req.ypDomain ? req.ypDomain.domain_name : "?",
418
- });
419
- models.Community.setYpCommunity(req, res, () => {
420
- log.info("Community", {
421
- id: req.ypCommunity ? req.ypCommunity.id : null,
422
- n: req.ypCommunity ? req.ypCommunity.hostname : null,
423
- });
424
- next();
425
- });
426
- });
427
- });
428
- }
429
- async initializeRateLimiting() {
430
- const botRateLimiter = rateLimit({
431
- windowMs: process.env.RATE_LIMITER_WINDOW_MS
432
- ? parseInt(process.env.RATE_LIMITER_WINDOW_MS, 10)
433
- : 15 * 60 * 1000, // 15 minutes
434
- max: process.env.RATE_LIMITER_MAX
435
- ? parseInt(process.env.RATE_LIMITER_MAX, 10)
436
- : 30,
437
- });
438
- this.app.use((req, res, next) => {
439
- let ua = req.headers["user-agent"] || "";
440
- if (req.headers["content-type"] !== "application/json" &&
441
- req.originalUrl &&
442
- !req.originalUrl.endsWith("/sitemap.xml")) {
443
- const isBotBad = isBadBot(ua.toLowerCase());
444
- if (!req.headers["x-api-key"] &&
445
- !botsWithJavascript(ua) &&
446
- (isbot(ua) || isBadBot(ua))) {
447
- if (isBotBad) {
448
- botRateLimiter(req, res, () => {
449
- nonSPArouter(req, res, next);
450
- });
451
- }
452
- else {
453
- nonSPArouter(req, res, next);
454
- }
455
- }
456
- else {
457
- next();
458
- }
459
- }
460
- else {
461
- next();
462
- }
463
- });
464
- }
465
- setupSitemapRoute() {
466
- this.app.get("/sitemap.xml", async (req, res) => {
467
- try {
468
- const url = req.get("host") + req.originalUrl;
469
- const redisKey = "cache:sitemapv14:" + url;
470
- const sitemap = await req.redisClient.get(redisKey);
471
- if (sitemap) {
472
- res.header("Content-Type", "application/xml");
473
- res.send(sitemap);
474
- }
475
- else {
476
- generateSitemap(req, res);
477
- }
478
- }
479
- catch (error) {
480
- log.error("Error getting sitemap from redis", { error });
481
- generateSitemap(req, res);
482
- }
483
- });
484
- }
485
- checkAuthForSsoInit() {
486
- this.app.use((req, res, next) => {
487
- if (req.url.indexOf("/auth") > -1 ||
488
- req.url.indexOf("/login") > -1 ||
489
- req.url.indexOf("saml_assertion") > -1) {
490
- sso.init(req.ypDomain?.loginHosts, req.ypDomain?.loginProviders, {
491
- authorize: this.bearerCallback,
492
- login: models.User.localCallback,
493
- });
494
- req.sso = sso;
495
- }
496
- next();
497
- });
498
- }
499
- initializeMiddlewares() {
500
- this.app.use(morgan("combined"));
501
- this.app.use(useragent.express());
502
- this.app.use(requestIp.mw());
503
- this.app.use(bodyParser.json({ limit: "100mb", strict: false }));
504
- this.app.use(bodyParser.urlencoded({ limit: "100mb", extended: true }));
505
- this.app.use(cors());
506
- this.app.use(compression());
507
- this.app.set("views", __dirname + "/views");
508
- this.app.set("view engine", "pug");
509
- const store = new RedisStore({ client: this.redisClient, ttl: 86400 });
510
- const sessionConfig = {
511
- store: store,
512
- name: "yrpri.sid",
513
- secret: process.env.SESSION_SECRET || "not so secret... use env var.",
514
- resave: false,
515
- proxy: process.env.USING_NGINX_PROXY ? true : undefined,
516
- cookie: { autoSubDomain: true },
517
- saveUninitialized: false,
518
- };
519
- if (this.app.get("env") === "production") {
520
- this.app.set("trust proxy", 3); // Trust three proxies
521
- //@ts-ignore
522
- sessionConfig.cookie.secure = true; // serve secure cookies
523
- }
524
- //@ts-ignore
525
- this.app.use(session(sessionConfig));
526
- }
527
- async initializeEsControllers() {
528
- console.log("Initializing ES controllers");
529
- const { AllOurIdeasController } = await import("./controllers/allOurIdeas.js");
530
- console.log("Initializing ES controllers 2 " + this.wsClients);
531
- const aoiController = new AllOurIdeasController(this.wsClients);
532
- console.log(`Controller path: ${aoiController.path} ${aoiController.router}`);
533
- this.app.use(aoiController.path, aoiController.router);
534
- const { PolicySynthAgentsController } = await import("./agents/controllers/policySynthAgents.js");
535
- const policySynthAgentsController = new PolicySynthAgentsController(this.wsClients);
536
- this.app.use(policySynthAgentsController.path, policySynthAgentsController.router);
537
- const { AssistantController } = await import("./agents/controllers/assistantsController.js");
538
- const assistantController = new AssistantController(this.wsClients);
539
- this.app.use(assistantController.path, assistantController.router);
540
- // Setup those here so they wont override the ES controllers
541
- this.setupErrorHandler();
542
- }
543
- setupStaticFileServing() {
544
- const baseDir = path.join(__dirname, "../webAppsDist");
545
- this.app.use((req, res, next) => {
546
- if (req.path.endsWith(".js")) {
547
- res.setHeader("Cache-Control", "public, max-age=31536000, s-maxage=86400, stale-while-revalidate=86400"); // 1 year cache, 1 day revalidate
548
- }
549
- else if (req.path.match(/\.(png|jpg|jpeg|gif)$/)) {
550
- res.setHeader("Cache-Control", "public, max-age=2592000, s-maxage=86400, stale-while-revalidate=86400"); // 1 month cache, 1 day revalidate
551
- }
552
- else if (req.path.endsWith(".json")) {
553
- res.setHeader("Cache-Control", "public, max-age=43200, s-maxage=60, stale-while-revalidate=60"); // 12 hour cache, 5 minutes revalidate
554
- }
555
- next();
556
- });
557
- this.app.get("/sw.js", this.handleServiceWorker);
558
- this.app.get("/service-worker.js", this.handleServiceWorker);
559
- // Promotion app
560
- const promotionAppPath = path.join(baseDir, "old/promotion_app/dist");
561
- this.app.use("/promotion", express.static(promotionAppPath));
562
- this.app.use("/promotion/domain/*", express.static(promotionAppPath));
563
- this.app.use("/promotion/organization/*", express.static(promotionAppPath));
564
- this.app.use("/promotion/community/*", express.static(promotionAppPath));
565
- this.app.use("/promotion/group/*", express.static(promotionAppPath));
566
- this.app.use("/promotion/post/*", express.static(promotionAppPath));
567
- this.app.use("/promotion/locales/en/*", express.static(path.join(promotionAppPath, "locales/en")));
568
- this.app.use("/promotion/locales/is/*", express.static(path.join(promotionAppPath, "locales/is")));
569
- // Land use game
570
- const landUseGamePath = path.join(baseDir, "land_use_game/dist");
571
- this.app.use("/land_use", express.static(landUseGamePath));
572
- this.app.use("/land_use/*", express.static(landUseGamePath));
573
- this.app.use("/land_use/locales/en/*", express.static(path.join(landUseGamePath, "locales/en")));
574
- this.app.use("/land_use/locales/is/*", express.static(path.join(landUseGamePath, "locales/is")));
575
- this.app.use("/Assets", express.static(path.join(landUseGamePath, "Assets")));
576
- this.app.use("/ThirdParty", express.static(path.join(landUseGamePath, "ThirdParty")));
577
- this.app.use("/Widgets", express.static(path.join(landUseGamePath, "Widgets")));
578
- this.app.use("/Workers", express.static(path.join(landUseGamePath, "Workers")));
579
- // Middleware to set paths based on query parameters
580
- this.app.use((req, res, next) => {
581
- const baseDir = path.join(__dirname, "../webAppsDist");
582
- const useNewVersion = req.useNewVersion;
583
- // Set the paths depending on the version
584
- req.adminAppPath = useNewVersion
585
- ? path.join(baseDir, "client/dist")
586
- : path.join(baseDir, "old/translationApp/dist");
587
- req.clientAppPath = useNewVersion
588
- ? path.join(baseDir, "client/dist")
589
- : path.join(baseDir, "old/client/build/bundled");
590
- const staticPath = req.path.startsWith("/admin")
591
- ? req.adminAppPath
592
- : req.clientAppPath;
593
- //console.log("Static path", staticPath);
594
- // Check if the request is for index.html
595
- if (req.path === "/" || req.path === "/index.html") {
596
- index(req, res, next); // Use your dynamic handler
597
- }
598
- else {
599
- express.static(staticPath)(req, res, next);
600
- }
601
- });
602
- }
603
- initializeRoutes() {
604
- this.app.use("/", index);
605
- this.app.use("/index.html", index);
606
- this.app.use("/domain", index);
607
- this.app.use("/community", index);
608
- this.app.use("/organization", index);
609
- this.app.use("/agent_bundle/*", index);
610
- this.app.use("/group", index);
611
- this.app.use("/post", index);
612
- this.app.use("/user", index);
613
- this.app.use("/admin", index);
614
- this.app.use("/survey*", index);
615
- this.app.use("/api/domains", domains);
616
- this.app.use("/api/organizations", organizations);
617
- this.app.use("/api/communities", communities);
618
- this.app.use("/api/groups", groups);
619
- this.app.use("/api/posts", posts);
620
- this.app.use("/api/points", points);
621
- this.app.use("/api/images", images);
622
- this.app.use("/api/videos", videos);
623
- this.app.use("/api/audios", audios);
624
- this.app.use("/api/categories", categories);
625
- this.app.use("/api/externalIds", externalIds);
626
- this.app.use("/api/users", users);
627
- this.app.use("/api/news_feeds", news_feeds);
628
- this.app.use("/api/activities", activities);
629
- this.app.use("/api/notifications", notifications);
630
- this.app.use("/api/bulk_status_updates", bulkStatusUpdates);
631
- this.app.use("/api/recommendations", recommendations);
632
- this.app.use("/api/ratings", ratings);
633
- this.app.use("/ideas", legacyPosts);
634
- this.app.use("/users", legacyUsers);
635
- this.app.use("/pages", legacyPages);
636
- // Additional routes for authentication and other functionalities
637
- this.app.post("/authenticate_from_island_is", (req, res) => {
638
- console.log("SAML SAML 1", { domainId: req.ypDomain.id });
639
- req.sso.authenticate(`saml-strategy-${req.ypDomain.id}`, {}, req, res, (error) => {
640
- console.log("SAML SAML 2", {
641
- domainId: req.ypDomain.id,
642
- err: error,
643
- });
644
- if (error) {
645
- console.error("Error from SAML login", { err: error });
646
- error.url = req.url;
647
- res.sendStatus(401);
648
- }
649
- else {
650
- if (req.user.DestinationSSN === "6012101260") {
651
- console.log("SAML SAML 3", { domainId: req.ypDomain.id });
652
- res.render("samlLoginComplete", {});
653
- }
654
- else {
655
- console.error("Error from SAML login", {
656
- err: "Failed DestinationSSN check",
657
- });
658
- res.sendStatus(401);
659
- }
660
- }
661
- });
662
- });
663
- this.app.post("/saml_assertion", (req, res) => {
664
- console.log("SAML SAML 1 General", { domainId: req.ypDomain.id });
665
- req.sso.authenticate(`saml-strategy-${req.ypDomain.id}`, {}, req, res, (error, user) => {
666
- console.log("SAML SAML 2 General", {
667
- domainId: req.ypDomain.id,
668
- err: error,
669
- });
670
- if (error) {
671
- console.error("Error from SAML General login", { err: error });
672
- if (error === "customError") {
673
- res.render("samlCustomError", {
674
- customErrorHTML: req.ypDomain.configuration.customSAMLErrorHTML,
675
- closeWindowText: "Close window",
676
- });
677
- }
678
- else {
679
- error.url = req.url;
680
- console.error("Error from SAML General login", { err: error });
681
- res.sendStatus(500);
682
- }
683
- }
684
- else {
685
- console.log("SAML SAML 3 General", { domainId: req.ypDomain.id });
686
- res.render("samlLoginComplete", {});
687
- }
688
- });
689
- });
690
- this.app.get("/manifest.json", (req, res) => {
691
- generateManifest(req, res);
692
- });
693
- }
694
- initializePassportStrategies() {
695
- this.app.use(passport.initialize());
696
- this.app.use(passport.session());
697
- passport.serializeUser((req, profile, done) => {
698
- log.info("----> User Serialized", { loginProvider: profile.provider });
699
- if (profile.provider === "facebook") {
700
- models.User.serializeFacebookUser(profile, req.ypDomain, (error, user) => {
701
- if (error) {
702
- log.error("Error in User Serialized from Facebook", {
703
- err: error,
704
- });
705
- done(error);
706
- }
707
- else {
708
- log.info("User Serialized", {
709
- context: "loginFromFacebook",
710
- userId: user.id,
711
- });
712
- // Assuming registerUserLogin is defined elsewhere in your application
713
- this.registerUserLogin(user, user.id, "facebook", req, () => {
714
- done(null, { userId: user.id, loginProvider: "facebook" });
715
- });
716
- }
717
- });
718
- }
719
- else if (profile.provider === "saml") {
720
- models.User.serializeSamlUser(profile, req, (error, user) => {
721
- if (error) {
722
- log.error("Error in User Serialized from SAML", { err: error });
723
- done(error);
724
- }
725
- else {
726
- log.info("User Serialized", {
727
- context: "loginFromSaml",
728
- userId: user.id,
729
- });
730
- this.registerUserLogin(user, user.id, "saml", req, () => {
731
- done(null, { userId: user.id, loginProvider: "saml" });
732
- });
733
- }
734
- });
735
- }
736
- else if (profile.provider === "oidc") {
737
- models.User.serializeOidcUser(profile, req, (error, user) => {
738
- if (error) {
739
- log.error("Error in User Serialized from OIDC", { err: error });
740
- done(error);
741
- }
742
- else {
743
- log.info("User Serialized", {
744
- context: "loginFromOidc",
745
- userId: user.id,
746
- });
747
- this.registerUserLogin(user, user.id, "oidc", req, () => {
748
- done(null, { userId: user.id, loginProvider: "saml" });
749
- });
750
- }
751
- });
752
- }
753
- else {
754
- log.info("User Serialized", {
755
- context: "serializeUser",
756
- userEmail: profile.email,
757
- userId: profile.id,
758
- });
759
- this.registerUserLogin(null, parseInt(profile.id), "email", req, () => {
760
- done(null, {
761
- userId: parseInt(profile.id),
762
- loginProvider: "email",
763
- });
764
- });
765
- }
766
- });
767
- passport.deserializeUser((sessionUser, done) => {
768
- models.User.findOne({
769
- where: { id: sessionUser.userId },
770
- attributes: [
771
- "id",
772
- "name",
773
- "email",
774
- "default_locale",
775
- "facebook_id",
776
- "twitter_id",
777
- "google_id",
778
- "github_id",
779
- "ssn",
780
- "profile_data",
781
- "private_profile_data",
782
- ],
783
- include: [
784
- {
785
- model: models.Image,
786
- as: "UserProfileImages",
787
- required: false,
788
- },
789
- {
790
- model: models.Image,
791
- as: "UserHeaderImages",
792
- required: false,
793
- },
794
- ],
795
- })
796
- .then((user) => {
797
- if (user) {
798
- user.loginProvider = sessionUser.loginProvider;
799
- if (user.private_profile_data?.saml_agency &&
800
- sessionUser.loginProvider === "saml") {
801
- user.isSamlEmployee = true;
802
- log.info("SAML isSamlEmployee is true");
803
- }
804
- done(null, user);
805
- }
806
- else {
807
- log.error("User Deserialized Not found", {
808
- context: "deserializeUser",
809
- });
810
- if (airbrake) {
811
- airbrake
812
- .notify("User Deserialized Not found")
813
- .then((airbrakeErr) => {
814
- if (airbrakeErr.error) {
815
- log.error("AirBrake Error", {
816
- context: "airbrake",
817
- err: airbrakeErr.error,
818
- errorStatus: 500,
819
- });
820
- }
821
- });
822
- }
823
- done(null, false);
824
- }
825
- })
826
- .catch((error) => {
827
- log.error("User Deserialize Error", {
828
- context: "deserializeUser",
829
- err: error,
830
- errorStatus: 500,
831
- });
832
- if (airbrake) {
833
- airbrake.notify(error).then((airbrakeErr) => {
834
- if (airbrakeErr.error) {
835
- log.error("AirBrake Error", {
836
- context: "airbrake",
837
- err: airbrakeErr.error,
838
- errorStatus: 500,
839
- });
840
- }
841
- });
842
- }
843
- done(null, false);
844
- });
845
- });
846
- }
847
- setupErrorHandler() {
848
- this.app.use((err, req, res, next) => {
849
- if (err instanceof auth.UnauthorizedError) {
850
- log.info("Anon debug UnauthorizedError", { user: req.user });
851
- log.error("User Unauthorized", {
852
- context: "unauthorizedError",
853
- user: toJson(req.user),
854
- err: "Unauthorized",
855
- errorStatus: 401,
856
- });
857
- res.sendStatus(401);
858
- }
859
- else {
860
- next(err);
861
- }
862
- });
863
- this.app.use((req, res, next) => {
864
- const err = new Error("Not Found");
865
- err.status = 404;
866
- log.warn("Not Found", {
867
- context: "notFound",
868
- user: toJson(req.user),
869
- err: "Not Found",
870
- errorStatus: 404,
871
- });
872
- next(err);
873
- });
874
- this.app.use((err, req, res, next) => {
875
- let status = err.status || 500;
876
- if (err.message && err.message.includes("Expected url like")) {
877
- status = 404;
878
- }
879
- let body = null;
880
- try {
881
- if (req.body) {
882
- body = JSON.stringify(req.body);
883
- }
884
- }
885
- catch (bodyError) {
886
- log.error("General Error: Body JSON parsing error", {
887
- err: bodyError,
888
- });
889
- }
890
- log.error("General Error", {
891
- context: "generalError",
892
- user: req.user ? toJson(req.user) : null,
893
- err: err,
894
- protocol: req.protocol,
895
- host: req.get("host"),
896
- originalUrl: req.originalUrl,
897
- body,
898
- errStack: err.stack,
899
- errorStatus: status,
900
- });
901
- err.url = req.url;
902
- err.params = req.params;
903
- if (status !== 404 && status !== 401) {
904
- // Optionally notify an error tracking service like Airbrake
905
- if (airbrake) {
906
- airbrake.notify(err).then((airbrakeErr) => {
907
- if (airbrakeErr.error) {
908
- log.error("AirBrake Error", {
909
- context: "airbrake",
910
- user: toJson(req.user),
911
- err: airbrakeErr.error,
912
- errorStatus: 500,
913
- });
914
- }
915
- });
916
- }
917
- }
918
- res.sendStatus(status);
919
- });
920
- }
921
- async listen() {
922
- const server = await this.setupHttpsServer();
923
- this.webSocketsManager = new WebSocketsManager(this.wsClients, this.redisClient, server);
924
- await this.webSocketsManager.listen();
925
- }
926
- setupHttpsServer() {
927
- let server;
928
- const portNumber = process.env.PORT ? parseInt(process.env.PORT) : 4242;
929
- if (process.env.YOUR_PRIORITIES_LISTEN_HOST) {
930
- server = this.app.listen(portNumber, process.env.YOUR_PRIORITIES_LISTEN_HOST, () => {
931
- log.info(`Your Priorities Platform API Server listening on port ${process.env.YOUR_PRIORITIES_LISTEN_HOST}:${this.app.get("port")} on ${process.env.NODE_ENV}`);
932
- });
933
- }
934
- else {
935
- server = this.app.listen(portNumber, function () {
936
- log.info("Your Priorities Platform API Server listening on port " +
937
- server.address().port +
938
- ` on ${process.env.NODE_ENV}`);
939
- });
940
- }
941
- return server;
942
- }
943
- }