@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,1860 @@
1
+ "use strict";
2
+ var auth = require("authorized");
3
+ var models = require("./models/index.cjs");
4
+ var log = require("./utils/logger.cjs");
5
+ var toJson = require("./utils/to_json.cjs");
6
+ var isAuthenticatedAndCorrectLoginProvider = function (req, group, done) {
7
+ var isCorrectLoginProviderAndAgency = true;
8
+ if (group) {
9
+ if ((group.configuration && group.configuration.forceSecureSamlLogin) ||
10
+ (group.Community &&
11
+ group.Community.configuration &&
12
+ group.Community.configuration.forceSecureSamlLogin)) {
13
+ if (req.user) {
14
+ group.hasGroupAdmins(req.user).then(function (result) {
15
+ if (!result) {
16
+ if (req.user.loginProvider !== "saml")
17
+ isCorrectLoginProviderAndAgency = false;
18
+ if (group.configuration.forceSecureSamlEmployeeLogin &&
19
+ (!req.user.private_profile_data ||
20
+ !req.user.private_profile_data.saml_agency)) {
21
+ isCorrectLoginProviderAndAgency = false;
22
+ }
23
+ if (group.Community.configuration &&
24
+ group.Community.configuration.ssnLoginListDataId &&
25
+ req.user.ssn) {
26
+ models.GeneralDataStore.findOne({
27
+ where: {
28
+ id: group.Community.configuration.ssnLoginListDataId,
29
+ "data.ssns::jsonb": {
30
+ $contains: '["' + req.user.ssn + '"]',
31
+ },
32
+ },
33
+ attributes: ["id"],
34
+ })
35
+ .then((item) => {
36
+ if (item) {
37
+ isCorrectLoginProviderAndAgency = true;
38
+ }
39
+ else {
40
+ isCorrectLoginProviderAndAgency = false;
41
+ }
42
+ done(auth.isAuthenticated(req, group) &&
43
+ isCorrectLoginProviderAndAgency);
44
+ })
45
+ .catch((error) => {
46
+ log.error("Error in isAuthenticatedAndCorrectLoginProvider", {
47
+ error,
48
+ });
49
+ done(auth.isAuthenticated(req, group) && false);
50
+ });
51
+ }
52
+ else {
53
+ done(auth.isAuthenticated(req, group) &&
54
+ isCorrectLoginProviderAndAgency);
55
+ }
56
+ }
57
+ else {
58
+ done(auth.isAuthenticated(req, group) &&
59
+ isCorrectLoginProviderAndAgency);
60
+ }
61
+ });
62
+ }
63
+ else {
64
+ isCorrectLoginProviderAndAgency = false;
65
+ done(auth.isAuthenticated(req, group) && isCorrectLoginProviderAndAgency);
66
+ }
67
+ }
68
+ else {
69
+ done(auth.isAuthenticated(req, group) && isCorrectLoginProviderAndAgency);
70
+ }
71
+ }
72
+ else {
73
+ log.error("Error no group for isAuthenticatedAndCorrectLoginProvider");
74
+ done(false);
75
+ }
76
+ };
77
+ auth.isAuthenticated = function (req, group) {
78
+ if (group) {
79
+ if (group.configuration) {
80
+ if (group.configuration.allowAnonymousUsers ||
81
+ group.configuration.allowOneTimeLoginWithName) {
82
+ log.info("isAuthenticated: Group allows anonymous users");
83
+ }
84
+ else {
85
+ log.info("isAuthenticated: Group does not allow anonymous users");
86
+ }
87
+ }
88
+ else {
89
+ log.info("isAuthenticated: No group config");
90
+ }
91
+ }
92
+ else {
93
+ log.info("isAuthenticated: No group");
94
+ }
95
+ if (req.user) {
96
+ if (req.user &&
97
+ req.user.profile_data &&
98
+ req.user.profile_data.isAnonymousUser) {
99
+ log.info("isAuthenticated: Is anonymous user");
100
+ }
101
+ else {
102
+ log.info("isAuthenticated: Is regular user");
103
+ }
104
+ }
105
+ else if (false &&
106
+ process.env.PS_TEMP_AGENTS_FABRIC_GROUP_API_KEY &&
107
+ req.headers["x-api-key"] === process.env.PS_TEMP_AGENTS_FABRIC_GROUP_API_KEY) {
108
+ log.info("isAuthenticated: Is API key user");
109
+ return true;
110
+ }
111
+ else {
112
+ log.info("isAuthenticated: No user");
113
+ }
114
+ if (req.user &&
115
+ req.user.profile_data &&
116
+ req.user.profile_data.isAnonymousUser === true) {
117
+ return (group &&
118
+ group.configuration &&
119
+ (group.configuration.allowAnonymousUsers ||
120
+ group.configuration.allowOneTimeLoginWithName));
121
+ }
122
+ else {
123
+ return req.isAuthenticated();
124
+ }
125
+ };
126
+ auth.isAuthenticatedNoAnonymousCheck = function (req) {
127
+ return req.isAuthenticated();
128
+ };
129
+ auth.authNeedsGroupForCreate = function (group, req, done) {
130
+ if (process.env.PS_TEMP_AGENTS_FABRIC_GROUP_API_KEY &&
131
+ req.headers["x-api-key"] === process.env.PS_TEMP_AGENTS_FABRIC_GROUP_API_KEY) {
132
+ done(null, true);
133
+ }
134
+ else {
135
+ models.Group.findOne({
136
+ where: { id: group.id },
137
+ attributes: ["id", "access", "user_id", "configuration"],
138
+ include: [
139
+ {
140
+ model: models.Community,
141
+ required: true,
142
+ attributes: ["id", "access", "user_id", "configuration"],
143
+ },
144
+ ],
145
+ })
146
+ .then(function (group) {
147
+ isAuthenticatedAndCorrectLoginProvider(req, group, function (results) {
148
+ if (!results) {
149
+ done(null, false);
150
+ }
151
+ else {
152
+ if (group.access === models.Group.ACCESS_PUBLIC) {
153
+ done(null, true);
154
+ }
155
+ else if (req.user && group.user_id === req.user.id) {
156
+ done(null, true);
157
+ }
158
+ else {
159
+ auth.isGroupMemberOrOpenToCommunityMember(group, req, done);
160
+ }
161
+ }
162
+ });
163
+ })
164
+ .catch(function (error) {
165
+ log.error("Error in authentication", { error });
166
+ done(null, false);
167
+ });
168
+ }
169
+ };
170
+ auth.hasCommunitySsnLoginListAccess = function (community, req, done) {
171
+ if (community.configuration &&
172
+ community.configuration.ssnLoginListDataId &&
173
+ req.user.ssn) {
174
+ models.GeneralDataStore.findOne({
175
+ where: {
176
+ id: community.configuration.ssnLoginListDataId,
177
+ "data.ssns::jsonb": {
178
+ $contains: '["' + req.user.ssn + '"]',
179
+ },
180
+ },
181
+ attributes: ["id"],
182
+ })
183
+ .then((item) => {
184
+ if (item) {
185
+ done(null, true);
186
+ }
187
+ else {
188
+ done(null, false);
189
+ }
190
+ })
191
+ .catch((error) => {
192
+ done(error, false);
193
+ });
194
+ }
195
+ else {
196
+ done(null, false);
197
+ }
198
+ };
199
+ auth.hasCommunityAccess = function (community, req, done) {
200
+ community
201
+ .hasCommunityUsers(req.user)
202
+ .then(function (result) {
203
+ if (result) {
204
+ done(null, true);
205
+ }
206
+ else {
207
+ community.hasCommunityAdmins(req.user).then(function (result) {
208
+ if (result) {
209
+ done(null, true);
210
+ }
211
+ else {
212
+ auth.hasCommunitySsnLoginListAccess(community, req, done);
213
+ }
214
+ });
215
+ }
216
+ })
217
+ .catch(function (error) {
218
+ log.error("Error in authentication", { error });
219
+ done(null, false);
220
+ });
221
+ };
222
+ auth.authNeedsGroupAdminForCreate = function (group, req, done) {
223
+ models.Group.findOne({
224
+ where: { id: group.id },
225
+ attributes: ["id", "access", "user_id"],
226
+ include: [
227
+ {
228
+ model: models.Community,
229
+ required: true,
230
+ attributes: ["id", "access", "user_id", "configuration"],
231
+ },
232
+ ],
233
+ })
234
+ .then(function (group) {
235
+ if (!auth.isAuthenticated(req, group)) {
236
+ done(null, false);
237
+ }
238
+ else if (group.user_id === req.user.id) {
239
+ done(null, true);
240
+ }
241
+ else {
242
+ group
243
+ .hasGroupAdmins(req.user)
244
+ .then(function (result) {
245
+ if (result) {
246
+ done(null, true);
247
+ }
248
+ else if (group.access === models.Group.ACCESS_OPEN_TO_COMMUNITY) {
249
+ group.Community.hasCommunityAdmins(req.user).then(function (result) {
250
+ if (result) {
251
+ done(null, true);
252
+ }
253
+ else {
254
+ done(null, false);
255
+ }
256
+ });
257
+ }
258
+ else {
259
+ done(null, false);
260
+ }
261
+ })
262
+ .catch(function (error) {
263
+ log.error("Error in authentication", { error });
264
+ done(null, false);
265
+ });
266
+ }
267
+ })
268
+ .catch(function (error) {
269
+ log.error("Error in authentication", { error });
270
+ done(null, false);
271
+ });
272
+ };
273
+ auth.authNeedsCommunnityAdminForCreate = function (community, req, done) {
274
+ models.Community.findOne({
275
+ where: { id: community.id },
276
+ attributes: ["id", "access", "user_id", "configuration"],
277
+ })
278
+ .then(function (community) {
279
+ if (!auth.isAuthenticated(req)) {
280
+ done(null, false);
281
+ }
282
+ else if (community.user_id === req.user.id) {
283
+ done(null, true);
284
+ }
285
+ else {
286
+ community.hasCommunityAdmins(req.user).then(function (result) {
287
+ if (result) {
288
+ done(null, true);
289
+ }
290
+ else {
291
+ done(null, false);
292
+ }
293
+ });
294
+ }
295
+ })
296
+ .catch(function (error) {
297
+ log.error("Error in authentication", { error });
298
+ done(null, false);
299
+ });
300
+ };
301
+ auth.hasDomainAdmin = function (domainId, req, done) {
302
+ models.Domain.findOne({
303
+ where: { id: domainId },
304
+ attributes: ["id", "access"],
305
+ })
306
+ .then(function (domain) {
307
+ if (!auth.isAuthenticated(req)) {
308
+ done(null, false);
309
+ }
310
+ else if (domain.user_id === req.user.id) {
311
+ done(null, true);
312
+ }
313
+ else {
314
+ domain.hasDomainAdmins(req.user).then(function (result) {
315
+ if (result) {
316
+ done(null, true);
317
+ }
318
+ else {
319
+ done(null, false);
320
+ }
321
+ });
322
+ }
323
+ })
324
+ .catch(function (error) {
325
+ log.error("Error in authentication", { error });
326
+ done(null, false);
327
+ });
328
+ };
329
+ auth.isGroupMemberOrOpenToCommunityMember = function (group, req, done) {
330
+ if (group) {
331
+ if (group.Community &&
332
+ group.access === models.Group.ACCESS_OPEN_TO_COMMUNITY &&
333
+ group.Community.access === models.Community.ACCESS_PUBLIC) {
334
+ done(null, true);
335
+ }
336
+ else if (!auth.isAuthenticated(req) &&
337
+ //TODO: Come up with a better way to handle this than a master API key
338
+ !process.env.PS_TEMP_AGENTS_FABRIC_GROUP_API_KEY) {
339
+ done(null, false);
340
+ }
341
+ else if (!auth.isAuthenticated(req) &&
342
+ process.env.PS_TEMP_AGENTS_FABRIC_GROUP_API_KEY) {
343
+ if (req.headers["x-api-key"] ===
344
+ process.env.PS_TEMP_AGENTS_FABRIC_GROUP_API_KEY) {
345
+ done(null, true);
346
+ }
347
+ else {
348
+ done(null, false);
349
+ }
350
+ }
351
+ else {
352
+ group
353
+ .hasGroupUsers(req.user)
354
+ .then(function (result) {
355
+ if (result) {
356
+ done(null, true);
357
+ }
358
+ else if (group.Community &&
359
+ (group.access === models.Group.ACCESS_OPEN_TO_COMMUNITY ||
360
+ group.access === models.Group.ACCESS_PUBLIC)) {
361
+ if (group.Community.access === models.Community.ACCESS_PUBLIC) {
362
+ done(null, true);
363
+ }
364
+ else {
365
+ group.Community.hasCommunityUsers(req.user).then(function (result) {
366
+ if (result) {
367
+ done(null, true);
368
+ }
369
+ else {
370
+ group.Community.hasCommunityAdmins(req.user).then(function (result) {
371
+ if (result) {
372
+ done(null, true);
373
+ }
374
+ else {
375
+ auth.hasCommunitySsnLoginListAccess(group.Community, req, done);
376
+ }
377
+ });
378
+ }
379
+ });
380
+ }
381
+ }
382
+ else {
383
+ group.hasGroupAdmins(req.user).then(function (result) {
384
+ if (result) {
385
+ done(null, true);
386
+ }
387
+ else {
388
+ done(null, false);
389
+ }
390
+ });
391
+ }
392
+ })
393
+ .catch(function (error) {
394
+ done(error, false);
395
+ });
396
+ }
397
+ }
398
+ else {
399
+ done(null, false);
400
+ }
401
+ };
402
+ auth.isLoggedIn = function (req, res, next) {
403
+ if (auth.isAuthenticated(req)) {
404
+ log.info("Logged in", {
405
+ context: "isLoggedInAuth",
406
+ userId: req.user ? req.user.id : -1,
407
+ });
408
+ return next();
409
+ }
410
+ else {
411
+ log.info("Not Logged in", { context: "isLoggedInAuth", errorStatus: 401 });
412
+ next({ status: 401, error: "Not authorized" });
413
+ }
414
+ };
415
+ auth.isLoggedInNoAnonymousCheck = function (req, res, next) {
416
+ if (auth.isAuthenticatedNoAnonymousCheck(req)) {
417
+ log.info("User is Logged in", {
418
+ context: "isLoggedInNoAnonymousCheck",
419
+ userId: req.user ? req.user.id : -1,
420
+ });
421
+ return next();
422
+ }
423
+ else {
424
+ log.info("Not Logged in", {
425
+ context: "isLoggedInNoAnonymousCheck",
426
+ errorStatus: 401,
427
+ });
428
+ next({ status: 401, error: "Not authorized" });
429
+ }
430
+ };
431
+ // ADMIN AND VIEW
432
+ // User admin
433
+ auth.role("user.admin", function (user, req, done) {
434
+ if (!auth.isAuthenticatedNoAnonymousCheck(req)) {
435
+ done(null, false);
436
+ }
437
+ else {
438
+ models.User.findOne({
439
+ where: { id: user.id },
440
+ attributes: ["id"],
441
+ })
442
+ .then(function (user) {
443
+ if (user.id === req.user.id) {
444
+ done(null, true);
445
+ }
446
+ else {
447
+ done(null, false);
448
+ }
449
+ })
450
+ .catch(function (error) {
451
+ log.error("Error in authentication", { error });
452
+ done(null, false);
453
+ });
454
+ }
455
+ });
456
+ auth.entity("user", function (req, done) {
457
+ var match = req.originalUrl.match(/users\/(\w+)/);
458
+ if (!match) {
459
+ done(new Error("Expected url like /users/:userId"));
460
+ }
461
+ else {
462
+ var user = { id: match[1] };
463
+ done(null, user);
464
+ }
465
+ });
466
+ // Domain admin and view
467
+ auth.role("domain.admin", function (domain, req, done) {
468
+ if (!auth.isAuthenticated(req)) {
469
+ done();
470
+ }
471
+ else {
472
+ models.Domain.findOne({
473
+ where: { id: domain.id },
474
+ attributes: ["id", "access"],
475
+ })
476
+ .then(function (domain) {
477
+ if (domain.user_id === req.user.id) {
478
+ done(null, true);
479
+ }
480
+ else {
481
+ domain.hasDomainAdmins(req.user).then(function (result) {
482
+ if (result) {
483
+ done(null, true);
484
+ }
485
+ else {
486
+ done(null, false);
487
+ }
488
+ });
489
+ }
490
+ })
491
+ .catch(function (error) {
492
+ log.error("Error in authentication", { error });
493
+ done(null, false);
494
+ });
495
+ }
496
+ });
497
+ auth.role("domain.viewUser", function (domain, req, done) {
498
+ if (domain) {
499
+ models.Domain.findOne({
500
+ where: { id: domain.id },
501
+ attributes: ["id", "access"],
502
+ })
503
+ .then(function (domain) {
504
+ if (domain) {
505
+ if (domain.access === models.Domain.ACCESS_PUBLIC) {
506
+ done(null, true);
507
+ }
508
+ else if (!auth.isAuthenticated(req)) {
509
+ done(null, false);
510
+ }
511
+ else if (domain.user_id === req.user.id) {
512
+ done(null, true);
513
+ }
514
+ else {
515
+ domain.hasDomainUsers(req.user).then(function (result) {
516
+ if (result) {
517
+ done(null, true);
518
+ }
519
+ else {
520
+ domain.hasDomainAdmins(req.user).then(function (result) {
521
+ if (result) {
522
+ done(null, true);
523
+ }
524
+ else {
525
+ done(null, false);
526
+ }
527
+ });
528
+ }
529
+ });
530
+ }
531
+ }
532
+ else {
533
+ done(null, false);
534
+ }
535
+ })
536
+ .catch(function (error) {
537
+ log.error("Error in authentication", { error });
538
+ done(null, false);
539
+ });
540
+ }
541
+ else {
542
+ done(null, false);
543
+ }
544
+ });
545
+ auth.entity("domain", function (req, done) {
546
+ var match = req.originalUrl.match(/domains\/(\w+)/);
547
+ if (!match)
548
+ match = req.originalUrl.match(/videos\/(\w+)/);
549
+ if (!match)
550
+ match = req.originalUrl.match(/communities\/(\w+)/);
551
+ if (!match)
552
+ match = req.originalUrl.match(/groups\/(\w+)/);
553
+ if (!match)
554
+ match = req.originalUrl.match(/images\/(\w+)/);
555
+ if (!match)
556
+ match = req.originalUrl.match(/allOurIdeas\/(\w+)/);
557
+ if (!match)
558
+ match = req.originalUrl.match(/assistants\/(\w+)/);
559
+ if (!match) {
560
+ done(new Error("Expected url like /domains/:domainId"));
561
+ }
562
+ else {
563
+ var domain = { id: match[1] };
564
+ done(null, domain);
565
+ }
566
+ });
567
+ // Organization admin and view
568
+ auth.role("organization.admin", function (organization, req, done) {
569
+ if (!auth.isAuthenticated(req)) {
570
+ done();
571
+ }
572
+ else {
573
+ models.Organization.findOne({
574
+ where: { id: organization.id },
575
+ attributes: ["id", "access", "user_id"],
576
+ })
577
+ .then(function (organization) {
578
+ if (organization.user_id === req.user.id) {
579
+ done(null, true);
580
+ }
581
+ else {
582
+ organization.hasOrganizationAdmins(req.user).then(function (result) {
583
+ if (result) {
584
+ done(null, true);
585
+ }
586
+ else {
587
+ done(null, false);
588
+ }
589
+ });
590
+ }
591
+ })
592
+ .catch(function (error) {
593
+ log.error("Error in authentication", { error });
594
+ done(null, false);
595
+ });
596
+ }
597
+ });
598
+ auth.role("organization.viewUser", function (organization, req, done) {
599
+ models.Organization.findOne({
600
+ where: { id: organization.id },
601
+ attributes: ["id", "access", "user_id"],
602
+ })
603
+ .then(function (organization) {
604
+ if (organization.access === models.Organization.ACCESS_PUBLIC) {
605
+ done(null, true);
606
+ }
607
+ else if (!auth.isAuthenticated(req)) {
608
+ done(null, false);
609
+ }
610
+ else if (organization.user_id === req.user.id) {
611
+ done(null, true);
612
+ }
613
+ else {
614
+ organization.hasUser(req.user).then(function (result) {
615
+ if (result) {
616
+ done(null, true);
617
+ }
618
+ else {
619
+ done(null, false);
620
+ }
621
+ });
622
+ }
623
+ })
624
+ .catch(function (error) {
625
+ log.error("Error in authentication", { error });
626
+ done(null, false);
627
+ });
628
+ });
629
+ auth.entity("organization", function (req, done) {
630
+ var match = req.originalUrl.match(/organizations\/(\w+)/);
631
+ if (!match) {
632
+ done(new Error("Expected url like /organizations/:organizationId"));
633
+ }
634
+ else {
635
+ var organization = { id: match[1] };
636
+ done(null, organization);
637
+ }
638
+ });
639
+ // Bulk Status Updates Admin
640
+ auth.role("bulkStatusUpdates.admin", function (community, req, done) {
641
+ if (!auth.isAuthenticated(req)) {
642
+ done();
643
+ }
644
+ else {
645
+ models.Community.findOne({
646
+ where: { id: community.id },
647
+ attributes: ["id", "access", "user_id", "configuration"],
648
+ })
649
+ .then(function (community) {
650
+ if (community.user_id === req.user.id) {
651
+ done(null, true);
652
+ }
653
+ else {
654
+ community.hasCommunityAdmins(req.user).then(function (result) {
655
+ if (result) {
656
+ done(null, true);
657
+ }
658
+ else {
659
+ done(null, false);
660
+ }
661
+ });
662
+ }
663
+ })
664
+ .catch(function (error) {
665
+ log.error("Error in authentication", { error });
666
+ done(null, false);
667
+ });
668
+ }
669
+ });
670
+ auth.entity("bulkStatusUpdates", function (req, done) {
671
+ var match = req.originalUrl.match(/bulk_status_updates\/(\w+)/);
672
+ if (!match) {
673
+ done(new Error("Expected url like /bulk_status_updates/:communityId"));
674
+ }
675
+ else {
676
+ var community = { id: match[1] };
677
+ done(null, community);
678
+ }
679
+ });
680
+ auth.role("community.marketing", async (community, req, done) => {
681
+ if (!auth.isAuthenticated(req)) {
682
+ done();
683
+ }
684
+ else {
685
+ models.Community.findOne({
686
+ where: { id: community.id },
687
+ attributes: ["id", "access", "user_id", "configuration"],
688
+ })
689
+ .then(async (community) => {
690
+ if (community.user_id === req.user.id) {
691
+ done(null, true);
692
+ }
693
+ else {
694
+ try {
695
+ if (await community.hasCommunityAdmins(req.user))
696
+ done(null, true);
697
+ else {
698
+ if (await community.hasCommunityPromoters(req.user)) {
699
+ done(null, true);
700
+ }
701
+ else {
702
+ done(null, false);
703
+ }
704
+ }
705
+ }
706
+ catch (error) {
707
+ log.error("Error in authentication", { error });
708
+ done(null, false);
709
+ }
710
+ }
711
+ })
712
+ .catch(function (error) {
713
+ log.error("Error in authentication", { error });
714
+ done(null, false);
715
+ });
716
+ }
717
+ });
718
+ auth.role("group.marketing", async (group, req, done) => {
719
+ if (!auth.isAuthenticated(req)) {
720
+ done();
721
+ }
722
+ else {
723
+ models.Group.findOne({
724
+ where: { id: group.id },
725
+ attributes: ["id", "access", "user_id", "configuration"],
726
+ })
727
+ .then(async (group) => {
728
+ if (group.user_id === req.user.id) {
729
+ done(null, true);
730
+ }
731
+ else {
732
+ try {
733
+ if (await group.hasGroupAdmins(req.user))
734
+ done(null, true);
735
+ else {
736
+ if (await group.hasGroupPromoters(req.user)) {
737
+ done(null, true);
738
+ }
739
+ else {
740
+ done(null, false);
741
+ }
742
+ }
743
+ }
744
+ catch (error) {
745
+ log.error("Error in authentication", { error });
746
+ done(null, false);
747
+ }
748
+ }
749
+ })
750
+ .catch(function (error) {
751
+ log.error("Error in authentication", { error });
752
+ done(null, false);
753
+ });
754
+ }
755
+ });
756
+ // Community admin and view
757
+ auth.role("community.admin", function (community, req, done) {
758
+ if (!auth.isAuthenticated(req)) {
759
+ done();
760
+ }
761
+ else {
762
+ models.Community.findOne({
763
+ where: { id: community.id },
764
+ attributes: ["id", "access", "user_id", "configuration"],
765
+ })
766
+ .then(function (community) {
767
+ if (community.user_id === req.user.id) {
768
+ done(null, true);
769
+ }
770
+ else {
771
+ community.hasCommunityAdmins(req.user).then(function (result) {
772
+ if (result) {
773
+ done(null, true);
774
+ }
775
+ else {
776
+ done(null, false);
777
+ }
778
+ });
779
+ }
780
+ })
781
+ .catch(function (error) {
782
+ log.error("Error in authentication", { error });
783
+ done(null, false);
784
+ });
785
+ }
786
+ });
787
+ auth.role("community.viewUser", function (community, req, done) {
788
+ models.Community.findOne({
789
+ where: { id: community.id },
790
+ attributes: ["id", "access", "user_id", "configuration"],
791
+ })
792
+ .then(function (community) {
793
+ if (!community) {
794
+ done(null, false);
795
+ }
796
+ else if (community.access === models.Community.ACCESS_PUBLIC) {
797
+ done(null, true);
798
+ }
799
+ else if (!auth.isAuthenticated(req)) {
800
+ done(null, false);
801
+ }
802
+ else if (community.user_id === req.user.id) {
803
+ done(null, true);
804
+ }
805
+ else {
806
+ auth.hasCommunityAccess(community, req, done);
807
+ }
808
+ })
809
+ .catch(function (error) {
810
+ log.error("Error in authentication", { error });
811
+ done(null, false);
812
+ });
813
+ });
814
+ auth.entity("community", function (req, done) {
815
+ var match = req.originalUrl.match(/communities\/(\w+)/);
816
+ if (!match)
817
+ match = req.originalUrl.match(/videos\/(\w+)/);
818
+ if (!match)
819
+ match = req.originalUrl.match(/images\/(\w+)/);
820
+ if (!match) {
821
+ done(new Error("Expected url like /communities/:communityId"));
822
+ }
823
+ else {
824
+ var community = { id: match[1] };
825
+ done(null, community);
826
+ }
827
+ });
828
+ // Group admin and view
829
+ auth.role("group.admin", function (group, req, done) {
830
+ if (!auth.isAuthenticated(req)) {
831
+ done();
832
+ }
833
+ else {
834
+ models.Group.findOne({
835
+ where: { id: group.id },
836
+ attributes: ["id", "access", "user_id"],
837
+ })
838
+ .then(function (group) {
839
+ if (group.user_id === req.user.id) {
840
+ done(null, true);
841
+ }
842
+ else {
843
+ group.hasGroupAdmins(req.user).then(function (result) {
844
+ if (result) {
845
+ done(null, true);
846
+ }
847
+ else {
848
+ done(null, false);
849
+ }
850
+ });
851
+ }
852
+ })
853
+ .catch(function (error) {
854
+ log.error("Error in authentication", { error });
855
+ done(null, false);
856
+ });
857
+ }
858
+ });
859
+ auth.role("group.viewUser", function (group, req, done) {
860
+ models.Group.findOne({
861
+ where: { id: group.id },
862
+ attributes: ["id", "access", "user_id", "configuration"],
863
+ include: [
864
+ {
865
+ model: models.Community,
866
+ required: true,
867
+ attributes: ["id", "access", "user_id", "configuration"],
868
+ },
869
+ ],
870
+ })
871
+ .then(function (group) {
872
+ if (!group) {
873
+ done(null, false);
874
+ }
875
+ else if (group.access === models.Group.ACCESS_PUBLIC &&
876
+ group.Community.access === models.Community.ACCESS_PUBLIC) {
877
+ done(null, true);
878
+ }
879
+ else if (req.user && group.user_id === req.user.id) {
880
+ done(null, true);
881
+ }
882
+ else {
883
+ auth.isGroupMemberOrOpenToCommunityMember(group, req, done);
884
+ }
885
+ })
886
+ .catch(function (error) {
887
+ log.error("Error in authentication", { error });
888
+ done(null, false);
889
+ });
890
+ });
891
+ auth.role("group.addTo", function (group, req, done) {
892
+ models.Group.findOne({
893
+ where: { id: group.id },
894
+ attributes: ["id", "access", "user_id", "configuration"],
895
+ include: [
896
+ {
897
+ model: models.Community,
898
+ required: true,
899
+ attributes: ["id", "access", "user_id", "configuration"],
900
+ },
901
+ ],
902
+ })
903
+ .then(function (group) {
904
+ isAuthenticatedAndCorrectLoginProvider(req, group, function (results) {
905
+ if (!results) {
906
+ done(null, false);
907
+ }
908
+ else {
909
+ if (group.access === models.Group.ACCESS_PUBLIC &&
910
+ group.Community.access === models.Community.ACCESS_PUBLIC) {
911
+ done(null, true);
912
+ }
913
+ else if (req.user && group.user_id === req.user.id) {
914
+ done(null, true);
915
+ }
916
+ else {
917
+ auth.isGroupMemberOrOpenToCommunityMember(group, req, done);
918
+ }
919
+ }
920
+ });
921
+ })
922
+ .catch(function (error) {
923
+ log.error("Error in authentication", { error });
924
+ done(null, false);
925
+ });
926
+ });
927
+ auth.entity("group", function (req, done) {
928
+ var match = req.originalUrl.match(/groups\/(\w+)/);
929
+ if (!match)
930
+ match = req.originalUrl.match(/videos\/(\w+)/);
931
+ if (!match)
932
+ match = req.originalUrl.match(/allOurIdeas\/(\w+)/);
933
+ if (!match)
934
+ match = req.originalUrl.match(/agents\/(\w+)/);
935
+ if (!match)
936
+ match = req.originalUrl.match(/assistants\/(\w+)/);
937
+ if (!match)
938
+ match = req.originalUrl.match(/ltp\/crt\/(\w+)/);
939
+ if (!match)
940
+ match = req.originalUrl.match(/images\/(\w+)/);
941
+ if (!match) {
942
+ done(new Error("Expected url like /groups/:groupId"));
943
+ }
944
+ else {
945
+ var group = { id: match[1] };
946
+ done(null, group);
947
+ }
948
+ });
949
+ // Post admin and view
950
+ auth.role("post.admin", function (post, req, done) {
951
+ models.Post.findOne({
952
+ where: { id: post.id },
953
+ attributes: ["id", "user_id"],
954
+ include: [
955
+ {
956
+ model: models.Group,
957
+ attributes: ["id", "access", "user_id", "configuration"],
958
+ },
959
+ ],
960
+ })
961
+ .then(function (post) {
962
+ if (post) {
963
+ var group = post.Group;
964
+ if (!auth.isAuthenticated(req, group)) {
965
+ done(null, false);
966
+ }
967
+ else if (post.user_id === req.user.id) {
968
+ done(null, true);
969
+ }
970
+ else {
971
+ group.hasGroupAdmins(req.user).then(function (result) {
972
+ if (result) {
973
+ done(null, true);
974
+ }
975
+ else {
976
+ done(null, false);
977
+ }
978
+ });
979
+ }
980
+ }
981
+ else {
982
+ done(null, false);
983
+ }
984
+ })
985
+ .catch(function (error) {
986
+ log.error("Error in authentication", { error });
987
+ done(null, false);
988
+ });
989
+ });
990
+ auth.role("post.statusChange", function (post, req, done) {
991
+ if (!auth.isAuthenticated(req)) {
992
+ done();
993
+ }
994
+ else {
995
+ models.Post.findOne({
996
+ where: { id: post.id },
997
+ attributes: ["id", "user_id"],
998
+ include: [
999
+ {
1000
+ model: models.Group,
1001
+ attributes: ["id", "access", "user_id", "configuration"],
1002
+ },
1003
+ ],
1004
+ })
1005
+ .then(function (post) {
1006
+ var group = post.Group;
1007
+ if (!auth.isAuthenticated(req)) {
1008
+ done(null, false);
1009
+ }
1010
+ else {
1011
+ group.hasGroupAdmins(req.user).then(function (result) {
1012
+ if (result) {
1013
+ done(null, true);
1014
+ }
1015
+ else {
1016
+ done(null, false);
1017
+ }
1018
+ });
1019
+ }
1020
+ })
1021
+ .catch(function (error) {
1022
+ log.error("Error in authentication", { error });
1023
+ done(null, false);
1024
+ });
1025
+ }
1026
+ });
1027
+ auth.role("post.viewUser", function (post, req, done) {
1028
+ //TODO: Profile this function for that second level Community include
1029
+ models.Post.findOne({
1030
+ where: { id: post.id },
1031
+ attributes: ["id", "user_id"],
1032
+ include: [
1033
+ {
1034
+ model: models.Group,
1035
+ required: true,
1036
+ attributes: ["id", "access", "user_id", "configuration"],
1037
+ include: [
1038
+ {
1039
+ model: models.Community,
1040
+ required: true,
1041
+ attributes: ["id", "access", "user_id", "configuration"],
1042
+ },
1043
+ ],
1044
+ },
1045
+ ],
1046
+ })
1047
+ .then(function (post) {
1048
+ if (post) {
1049
+ var group = post.Group;
1050
+ if (group.access === models.Group.ACCESS_PUBLIC) {
1051
+ done(null, true);
1052
+ }
1053
+ else if (req.user && post.user_id === req.user.id) {
1054
+ done(null, true);
1055
+ }
1056
+ else {
1057
+ auth.isGroupMemberOrOpenToCommunityMember(group, req, done);
1058
+ }
1059
+ }
1060
+ else {
1061
+ done(null, false);
1062
+ }
1063
+ })
1064
+ .catch(function (error) {
1065
+ log.error("Error in authentication", { error });
1066
+ done(null, false);
1067
+ });
1068
+ });
1069
+ auth.role("post.vote", function (post, req, done) {
1070
+ log.info("In post.vote");
1071
+ models.Post.findOne({
1072
+ where: { id: post.id },
1073
+ attributes: ["id", "user_id"],
1074
+ include: [
1075
+ {
1076
+ model: models.Group,
1077
+ attributes: ["id", "access", "user_id", "configuration"],
1078
+ include: [
1079
+ {
1080
+ model: models.Community,
1081
+ required: true,
1082
+ attributes: ["id", "access", "user_id", "configuration"],
1083
+ },
1084
+ ],
1085
+ },
1086
+ ],
1087
+ })
1088
+ .then(function (post) {
1089
+ log.info("In post.vote found post");
1090
+ if (post) {
1091
+ if (process.env.PS_TEMP_AGENTS_FABRIC_GROUP_API_KEY &&
1092
+ req.headers["x-api-key"] ===
1093
+ process.env.PS_TEMP_AGENTS_FABRIC_GROUP_API_KEY) {
1094
+ done(null, true);
1095
+ }
1096
+ else {
1097
+ isAuthenticatedAndCorrectLoginProvider(req, post.Group, function (results) {
1098
+ if (!results) {
1099
+ done(null, false);
1100
+ }
1101
+ else {
1102
+ if (post.Group.access === models.Group.ACCESS_PUBLIC) {
1103
+ done(null, true);
1104
+ }
1105
+ else if (req.user && post.user_id === req.user.id) {
1106
+ done(null, true);
1107
+ }
1108
+ else {
1109
+ auth.isGroupMemberOrOpenToCommunityMember(post.Group, req, done);
1110
+ }
1111
+ }
1112
+ });
1113
+ }
1114
+ }
1115
+ else {
1116
+ done(null, false);
1117
+ }
1118
+ })
1119
+ .catch(function (error) {
1120
+ log.error("Error in authentication", { error });
1121
+ done(null, false);
1122
+ });
1123
+ });
1124
+ auth.entity("post", function (req, done) {
1125
+ var match = req.originalUrl.match(/posts\/(\w+)/);
1126
+ if (!match)
1127
+ match = req.originalUrl.match(/images\/(\w+)/);
1128
+ if (!match)
1129
+ match = req.originalUrl.match(/videos\/(\w+)/);
1130
+ if (!match)
1131
+ match = req.originalUrl.match(/ratings\/(\w+)/);
1132
+ if (!match)
1133
+ match = req.originalUrl.match(/agents\/(\w+)/);
1134
+ if (!match)
1135
+ match = req.originalUrl.match(/ltp\/crt\/(\w+)/);
1136
+ if (!match)
1137
+ match = req.originalUrl.match(/audios\/(\w+)/);
1138
+ if (!match)
1139
+ done(new Error("Expected url like /posts/:postId or /images/:postId"));
1140
+ if (match) {
1141
+ var post = { id: match[1] };
1142
+ done(null, post);
1143
+ }
1144
+ });
1145
+ // Post admin and view
1146
+ auth.role("point.admin", function (point, req, done) {
1147
+ models.Point.findOne({
1148
+ where: { id: point.id },
1149
+ attributes: ["id", "user_id"],
1150
+ include: [
1151
+ {
1152
+ model: models.Post,
1153
+ attributes: ["id", "user_id"],
1154
+ include: [
1155
+ {
1156
+ model: models.Group,
1157
+ attributes: ["id", "access", "user_id", "configuration"],
1158
+ required: false,
1159
+ },
1160
+ ],
1161
+ required: false,
1162
+ },
1163
+ {
1164
+ model: models.Group,
1165
+ attributes: ["id", "access", "user_id", "configuration"],
1166
+ required: false,
1167
+ },
1168
+ ],
1169
+ })
1170
+ .then(function (point) {
1171
+ var group;
1172
+ if (point) {
1173
+ if (point.Post) {
1174
+ group = point.Post.Group;
1175
+ }
1176
+ else {
1177
+ group = point.Group;
1178
+ }
1179
+ if (!auth.isAuthenticated(req, group)) {
1180
+ done(null, false);
1181
+ }
1182
+ else if (point && group) {
1183
+ if (point.user_id === req.user.id) {
1184
+ done(null, true);
1185
+ }
1186
+ else {
1187
+ group.hasGroupAdmins(req.user).then(function (result) {
1188
+ if (result) {
1189
+ done(null, true);
1190
+ }
1191
+ else {
1192
+ done(null, false);
1193
+ }
1194
+ });
1195
+ }
1196
+ }
1197
+ else {
1198
+ done(null, false);
1199
+ }
1200
+ }
1201
+ else {
1202
+ done(null, false);
1203
+ }
1204
+ })
1205
+ .catch(function (error) {
1206
+ log.error("Error in authentication", { error });
1207
+ done(null, false);
1208
+ });
1209
+ });
1210
+ auth.role("point.viewUser", function (point, req, done) {
1211
+ models.Point.findOne({
1212
+ where: { id: point.id },
1213
+ attributes: ["id", "user_id"],
1214
+ include: [
1215
+ {
1216
+ model: models.Post,
1217
+ attributes: ["id", "user_id"],
1218
+ include: [
1219
+ {
1220
+ model: models.Group,
1221
+ attributes: ["id", "access", "user_id", "configuration"],
1222
+ required: false,
1223
+ include: [
1224
+ {
1225
+ model: models.Community,
1226
+ required: false,
1227
+ attributes: ["id", "access", "user_id", "configuration"],
1228
+ },
1229
+ ],
1230
+ },
1231
+ ],
1232
+ required: false,
1233
+ },
1234
+ {
1235
+ model: models.Group,
1236
+ attributes: ["id", "access", "user_id", "configuration"],
1237
+ required: false,
1238
+ include: [
1239
+ {
1240
+ model: models.Community,
1241
+ required: false,
1242
+ attributes: ["id", "access", "user_id", "configuration"],
1243
+ },
1244
+ ],
1245
+ },
1246
+ ],
1247
+ })
1248
+ .then(function (point) {
1249
+ var group;
1250
+ if (point && point.Post) {
1251
+ group = point.Post.Group;
1252
+ }
1253
+ else if (point) {
1254
+ group = point.Group;
1255
+ }
1256
+ if (point && group) {
1257
+ if (group.access === models.Group.ACCESS_PUBLIC) {
1258
+ done(null, true);
1259
+ }
1260
+ else if (req.user && point.user_id === req.user.id) {
1261
+ done(null, true);
1262
+ }
1263
+ else if (group.Community) {
1264
+ auth.isGroupMemberOrOpenToCommunityMember(group, req, done);
1265
+ }
1266
+ else {
1267
+ done(null, false);
1268
+ }
1269
+ }
1270
+ else {
1271
+ done(null, false);
1272
+ }
1273
+ })
1274
+ .catch(function (error) {
1275
+ log.error("Error in authentication", { error });
1276
+ done(null, false);
1277
+ });
1278
+ });
1279
+ auth.role("point.addTo", function (point, req, done) {
1280
+ models.Point.findOne({
1281
+ where: { id: point.id },
1282
+ attributes: ["id", "user_id"],
1283
+ include: [
1284
+ {
1285
+ model: models.Post,
1286
+ attributes: ["id", "user_id"],
1287
+ include: [
1288
+ {
1289
+ model: models.Group,
1290
+ attributes: ["id", "access", "user_id", "configuration"],
1291
+ required: false,
1292
+ include: [
1293
+ {
1294
+ model: models.Community,
1295
+ required: false,
1296
+ attributes: ["id", "access", "user_id", "configuration"],
1297
+ },
1298
+ ],
1299
+ },
1300
+ ],
1301
+ required: false,
1302
+ },
1303
+ {
1304
+ model: models.Group,
1305
+ attributes: ["id", "access", "user_id", "configuration"],
1306
+ required: false,
1307
+ },
1308
+ ],
1309
+ })
1310
+ .then(function (point) {
1311
+ var group;
1312
+ if (point && point.Post) {
1313
+ group = point.Post.Group;
1314
+ }
1315
+ else if (point) {
1316
+ group = point.Group;
1317
+ }
1318
+ if (point) {
1319
+ isAuthenticatedAndCorrectLoginProvider(req, group, function (results) {
1320
+ if (!results) {
1321
+ done(null, false);
1322
+ }
1323
+ else {
1324
+ if (group.access === models.Group.ACCESS_PUBLIC) {
1325
+ done(null, true);
1326
+ }
1327
+ else if (req.user && point.user_id === req.user.id) {
1328
+ done(null, true);
1329
+ }
1330
+ else if (group.Community) {
1331
+ auth.isGroupMemberOrOpenToCommunityMember(group, req, done);
1332
+ }
1333
+ else {
1334
+ done(null, false);
1335
+ }
1336
+ }
1337
+ });
1338
+ }
1339
+ else {
1340
+ done(null, false);
1341
+ }
1342
+ })
1343
+ .catch(function (error) {
1344
+ log.error("Error in authentication", { error });
1345
+ done(null, false);
1346
+ });
1347
+ });
1348
+ //TODO: Use this pattern of activities everywhere here for optimization
1349
+ auth.role("image.viewUser", function (image, req, done) {
1350
+ models.Image.findOne({
1351
+ where: { id: image.id },
1352
+ attributes: ["id", "user_id"],
1353
+ include: [
1354
+ {
1355
+ model: models.Post,
1356
+ as: "PostUserImages",
1357
+ attributes: ["id"],
1358
+ include: [
1359
+ {
1360
+ model: models.Group,
1361
+ attributes: ["id", "access", "user_id", "configuration"],
1362
+ include: [
1363
+ {
1364
+ model: models.Community,
1365
+ required: false,
1366
+ attributes: ["id", "access", "user_id", "configuration"],
1367
+ },
1368
+ ],
1369
+ },
1370
+ ],
1371
+ },
1372
+ ],
1373
+ })
1374
+ .then(function (image) {
1375
+ var group;
1376
+ if (image && image.PostUserImages && image.PostUserImages.length > 0) {
1377
+ group = image.PostUserImages[0].Group;
1378
+ }
1379
+ if (group) {
1380
+ if (group.access === models.Group.ACCESS_PUBLIC) {
1381
+ done(null, true);
1382
+ }
1383
+ else if (req.user && group.user_id === req.user.id) {
1384
+ done(null, true);
1385
+ }
1386
+ else if (group.Community) {
1387
+ auth.isGroupMemberOrOpenToCommunityMember(group, req, done);
1388
+ }
1389
+ else {
1390
+ done(null, false);
1391
+ }
1392
+ }
1393
+ else {
1394
+ done(null, false);
1395
+ }
1396
+ })
1397
+ .catch(function (error) {
1398
+ log.error("Error in authentication", { error });
1399
+ done(null, false);
1400
+ });
1401
+ });
1402
+ auth.role("point.vote", function (point, req, done) {
1403
+ models.Point.findOne({
1404
+ where: { id: point.id },
1405
+ attributes: ["id", "user_id"],
1406
+ include: [
1407
+ {
1408
+ model: models.Post,
1409
+ include: [
1410
+ {
1411
+ model: models.Group,
1412
+ attributes: ["id", "access", "user_id", "configuration"],
1413
+ required: false,
1414
+ include: [
1415
+ {
1416
+ model: models.Community,
1417
+ required: false,
1418
+ attributes: ["id", "access", "user_id", "configuration"],
1419
+ },
1420
+ ],
1421
+ },
1422
+ ],
1423
+ required: false,
1424
+ },
1425
+ {
1426
+ model: models.Group,
1427
+ attributes: ["id", "access", "user_id", "configuration"],
1428
+ required: false,
1429
+ },
1430
+ ],
1431
+ })
1432
+ .then(function (point) {
1433
+ var group;
1434
+ if (point) {
1435
+ if (point.Post) {
1436
+ group = point.Post.Group;
1437
+ }
1438
+ else {
1439
+ group = point.Group;
1440
+ }
1441
+ isAuthenticatedAndCorrectLoginProvider(req, group, function (results) {
1442
+ if (!results) {
1443
+ done(null, false);
1444
+ }
1445
+ else {
1446
+ if (group.access === models.Group.ACCESS_PUBLIC) {
1447
+ done(null, true);
1448
+ }
1449
+ else if (req.user && point.user_id === req.user.id) {
1450
+ done(null, true);
1451
+ }
1452
+ else if (group.Community) {
1453
+ auth.isGroupMemberOrOpenToCommunityMember(group, req, done);
1454
+ }
1455
+ else {
1456
+ done(null, false);
1457
+ }
1458
+ }
1459
+ });
1460
+ }
1461
+ else {
1462
+ done(null, false);
1463
+ }
1464
+ })
1465
+ .catch(function (error) {
1466
+ log.error("Error in authentication", { error });
1467
+ done(null, false);
1468
+ });
1469
+ });
1470
+ auth.entity("point", function (req, done) {
1471
+ var match = req.originalUrl.match(/points\/(\w+)/);
1472
+ if (!match)
1473
+ match = req.originalUrl.match(/videos\/(\w+)/);
1474
+ if (!match)
1475
+ match = req.originalUrl.match(/audios\/(\w+)/);
1476
+ if (!match) {
1477
+ done(new Error("Expected url like /points/:pointId"));
1478
+ }
1479
+ else {
1480
+ var point = { id: match[1] };
1481
+ done(null, point);
1482
+ }
1483
+ });
1484
+ auth.entity("image", function (req, done) {
1485
+ var match = req.originalUrl.match(/images\/(\w+)/);
1486
+ if (!match) {
1487
+ done(new Error("Expected url like /images/:imageId"));
1488
+ }
1489
+ else {
1490
+ var image = { id: match[1] };
1491
+ done(null, image);
1492
+ }
1493
+ });
1494
+ // Category admin and view
1495
+ auth.role("category.admin", function (category, req, done) {
1496
+ if (!auth.isAuthenticated(req)) {
1497
+ done();
1498
+ }
1499
+ else {
1500
+ models.Category.findOne({
1501
+ where: { id: category.id },
1502
+ include: [models.Group],
1503
+ })
1504
+ .then(function (category) {
1505
+ var group = category.Group;
1506
+ if (!auth.isAuthenticated(req)) {
1507
+ done(null, false);
1508
+ }
1509
+ else if (category.user_id === req.user.id) {
1510
+ done(null, true);
1511
+ }
1512
+ else {
1513
+ group.hasGroupAdmins(req.user).then(function (result) {
1514
+ if (result) {
1515
+ done(null, true);
1516
+ }
1517
+ else {
1518
+ done(null, false);
1519
+ }
1520
+ });
1521
+ }
1522
+ })
1523
+ .catch(function (error) {
1524
+ log.error("Error in authentication", { error });
1525
+ done(null, false);
1526
+ });
1527
+ }
1528
+ });
1529
+ auth.role("category.viewUser", function (category, req, done) {
1530
+ models.Category.findOne({
1531
+ where: { id: category.id },
1532
+ include: [
1533
+ {
1534
+ model: models.Group,
1535
+ attributes: ["id", "access", "user_id"],
1536
+ required: false,
1537
+ include: [
1538
+ {
1539
+ model: models.Community,
1540
+ required: false,
1541
+ attributes: ["id", "access", "user_id", "configuration"],
1542
+ },
1543
+ ],
1544
+ },
1545
+ ],
1546
+ })
1547
+ .then(function (category) {
1548
+ var group = category.Group;
1549
+ if (group.access === models.Group.ACCESS_PUBLIC) {
1550
+ done(null, true);
1551
+ }
1552
+ else if (req.user && category.user_id === req.user.id) {
1553
+ done(null, true);
1554
+ }
1555
+ else if (group.Community) {
1556
+ auth.isGroupMemberOrOpenToCommunityMember(group, req, done);
1557
+ }
1558
+ else {
1559
+ done(null, false);
1560
+ }
1561
+ })
1562
+ .catch(function (error) {
1563
+ log.error("Error in authentication", { error });
1564
+ done(null, false);
1565
+ });
1566
+ });
1567
+ auth.entity("category", function (req, done) {
1568
+ var match = req.originalUrl.match(/categories\/(\w+)/);
1569
+ if (!match) {
1570
+ done(new Error("Expected url like /categories/:categoryId"));
1571
+ }
1572
+ else {
1573
+ var category = { id: match[1] };
1574
+ done(null, category);
1575
+ }
1576
+ });
1577
+ // CREATE
1578
+ // Create bulkStatusUpdate
1579
+ auth.role("createCommunityBulkStatusUpdate.createBulkStatusUpdate", function (community, req, done) {
1580
+ auth.authNeedsCommunnityAdminForCreate(community, req, done);
1581
+ });
1582
+ auth.entity("createCommunityBulkStatusUpdate", function (req, done) {
1583
+ var match = req.originalUrl.match(/bulk_status_updates\/(\w+)/);
1584
+ if (!match) {
1585
+ done(new Error("Expected url like /bulk_status_update/:communityId"));
1586
+ }
1587
+ else {
1588
+ var community = { id: match[1] };
1589
+ done(null, community);
1590
+ }
1591
+ });
1592
+ // Create category
1593
+ auth.role("createGroupCategory.createCategory", function (group, req, done) {
1594
+ auth.authNeedsGroupAdminForCreate(group, req, done);
1595
+ });
1596
+ auth.entity("createGroupCategory", function (req, done) {
1597
+ var match = req.originalUrl.match(/categories\/(\w+)/);
1598
+ if (!match) {
1599
+ done(new Error("Expected url like /categories/:groupId"));
1600
+ }
1601
+ else {
1602
+ var group = { id: match[1] };
1603
+ done(null, group);
1604
+ }
1605
+ });
1606
+ // Create post
1607
+ auth.role("createGroupPost.createPost", function (group, req, done) {
1608
+ auth.authNeedsGroupForCreate(group, req, done);
1609
+ });
1610
+ auth.entity("createGroupPost", function (req, done) {
1611
+ var match = req.originalUrl.match(/posts\/(\w+)/);
1612
+ if (!match)
1613
+ match = req.originalUrl.match(/videos\/(\w+)/);
1614
+ if (!match)
1615
+ match = req.originalUrl.match(/audios\/(\w+)/);
1616
+ if (!match)
1617
+ match = req.originalUrl.match(/agents\/(\w+)/);
1618
+ if (!match)
1619
+ match = req.originalUrl.match(/ltp\/crt\/(\w+)/);
1620
+ if (!match) {
1621
+ done(new Error("Expected url like /posts/:groupId"));
1622
+ }
1623
+ else {
1624
+ var group = { id: match[1] };
1625
+ done(null, group);
1626
+ }
1627
+ });
1628
+ // Create point
1629
+ auth.role("createGroupPoint.createPoint", function (group, req, done) {
1630
+ auth.authNeedsGroupForCreate(group, req, done);
1631
+ });
1632
+ auth.entity("createGroupPoint", function (req, done) {
1633
+ var match = req.originalUrl.match(/points\/(\w+)/);
1634
+ if (!match) {
1635
+ done(new Error("Expected url like /points/:groupId"));
1636
+ }
1637
+ else {
1638
+ var group = { id: match[1] };
1639
+ done(null, group);
1640
+ }
1641
+ });
1642
+ // Create group
1643
+ auth.role("createCommunityGroup.createGroup", function (community, req, done) {
1644
+ console.error(`createCommunityGroup.createGroup`);
1645
+ models.Community.findOne({
1646
+ where: { id: community.id },
1647
+ })
1648
+ .then(function (community) {
1649
+ console.log(`community`, community);
1650
+ console.log(`XXX: ${auth.isAuthenticated(req)} ${process.env.PS_TEMP_AGENTS_FABRIC_GROUP_API_KEY}`);
1651
+ if (!auth.isAuthenticated(req) &&
1652
+ //TODO: Come up with a better way to handle this than a master API key
1653
+ !process.env.PS_TEMP_AGENTS_FABRIC_GROUP_API_KEY) {
1654
+ done(null, false);
1655
+ }
1656
+ else if (!auth.isAuthenticated(req) &&
1657
+ process.env.PS_TEMP_AGENTS_FABRIC_GROUP_API_KEY) {
1658
+ console.log(`XXXY: ${req.headers["x-api-key"]}`);
1659
+ if (req.headers["x-api-key"] ===
1660
+ process.env.PS_TEMP_AGENTS_FABRIC_GROUP_API_KEY) {
1661
+ done(null, true);
1662
+ }
1663
+ else {
1664
+ done(null, false);
1665
+ }
1666
+ }
1667
+ else if (community.access === models.Community.ACCESS_PUBLIC) {
1668
+ done(null, true);
1669
+ }
1670
+ else if (community.user_id === req.user.id) {
1671
+ done(null, true);
1672
+ }
1673
+ else {
1674
+ auth.hasCommunityAccess(community, req, done);
1675
+ }
1676
+ })
1677
+ .catch(function (error) {
1678
+ log.error("Error in authentication", { error });
1679
+ done(null, false);
1680
+ });
1681
+ });
1682
+ auth.entity("createCommunityGroup", function (req, done) {
1683
+ var match = req.originalUrl.match(/groups\/(\w+)/);
1684
+ if (!match)
1685
+ match = req.originalUrl.match(/allOurIdeas\/(\w+)/);
1686
+ if (!match) {
1687
+ done(new Error("Expected url like /groups/:communityId"));
1688
+ }
1689
+ else {
1690
+ var community = { id: match[1] };
1691
+ done(null, community);
1692
+ }
1693
+ });
1694
+ // Create community
1695
+ auth.role("createDomainCommunity.createCommunity", function (domain, req, done) {
1696
+ models.Domain.findOne({
1697
+ where: { id: domain.id },
1698
+ })
1699
+ .then(function (domain) {
1700
+ if (!domain || !auth.isAuthenticated(req)) {
1701
+ done(null, false);
1702
+ }
1703
+ else if (domain.access === models.Domain.ACCESS_PUBLIC) {
1704
+ done(null, true);
1705
+ }
1706
+ else if (domain.user_id === req.user.id) {
1707
+ done(null, true);
1708
+ }
1709
+ else {
1710
+ domain.hasDomainUsers(req.user).then(function (result) {
1711
+ if (result) {
1712
+ done(null, true);
1713
+ }
1714
+ else {
1715
+ domain.hasDomainAdmins(req.user).then(function (result) {
1716
+ if (result) {
1717
+ done(null, true);
1718
+ }
1719
+ else {
1720
+ done(null, false);
1721
+ }
1722
+ });
1723
+ }
1724
+ });
1725
+ }
1726
+ })
1727
+ .catch(function (error) {
1728
+ log.error("Error in authentication", { error });
1729
+ done(null, false);
1730
+ });
1731
+ });
1732
+ auth.entity("createDomainCommunity", function (req, done) {
1733
+ let match = req.originalUrl.match(/communities\/(\w+)/) ||
1734
+ req.originalUrl.match(/groups\/(\w+)/) ||
1735
+ req.originalUrl.match(/allOurIdeas\/(\w+)/);
1736
+ if (!match) {
1737
+ done(new Error("Expected url like /communities/:communityId"));
1738
+ }
1739
+ else {
1740
+ var community = { id: match[1] };
1741
+ done(null, community);
1742
+ }
1743
+ });
1744
+ // Create organization
1745
+ auth.role("createDomainOrganization.createDomainOrganization", function (domain, req, done) {
1746
+ models.Domain.findOne({
1747
+ where: { id: domain.id },
1748
+ })
1749
+ .then(function (domain) {
1750
+ if (!auth.isAuthenticated(req)) {
1751
+ done(null, false);
1752
+ }
1753
+ else if (domain.access === models.Domain.ACCESS_PUBLIC) {
1754
+ done(null, true);
1755
+ }
1756
+ else if (domain.user_id === req.user.id) {
1757
+ done(null, true);
1758
+ }
1759
+ else {
1760
+ domain.hasDomainUsers(req.user).then(function (result) {
1761
+ if (result) {
1762
+ done(null, true);
1763
+ }
1764
+ else {
1765
+ done(null, false);
1766
+ }
1767
+ });
1768
+ }
1769
+ })
1770
+ .catch(function (error) {
1771
+ log.error("Error in authentication", { error });
1772
+ done(null, false);
1773
+ });
1774
+ });
1775
+ auth.role("createCommunityOrganization.createCommunityOrganization", function (domain, req, done) {
1776
+ models.Community.findOne({
1777
+ where: { id: community.id },
1778
+ })
1779
+ .then(function (community) {
1780
+ if (!auth.isAuthenticated(req)) {
1781
+ done(null, false);
1782
+ }
1783
+ else if (community.access === models.Domain.ACCESS_PUBLIC) {
1784
+ done(null, true);
1785
+ }
1786
+ else if (community.user_id === req.user.id) {
1787
+ done(null, true);
1788
+ }
1789
+ else {
1790
+ auth.hasCommunityAccess(community, req, done);
1791
+ }
1792
+ })
1793
+ .catch(function (error) {
1794
+ log.error("Error in authentication", { error });
1795
+ done(null, false);
1796
+ });
1797
+ });
1798
+ auth.entity("createDomainOrganization", function (req, done) {
1799
+ var match = req.originalUrl.match(/organizations\/(\w+)/);
1800
+ if (!match) {
1801
+ done(new Error("Expected url like /organizations/:domainId"));
1802
+ }
1803
+ else {
1804
+ var domain = { id: match[1] };
1805
+ done(null, domain);
1806
+ }
1807
+ });
1808
+ auth.entity("createCommunityOrganization", function (req, done) {
1809
+ var match = req.originalUrl.match(/organizations\/(\w+)/);
1810
+ if (!match) {
1811
+ done(new Error("Expected url like /organizations/:communityId"));
1812
+ }
1813
+ else {
1814
+ var community = { id: match[1] };
1815
+ done(null, community);
1816
+ }
1817
+ });
1818
+ auth.action("edit domain", ["domain.admin"]);
1819
+ auth.action("edit organization", ["organization.admin"]);
1820
+ auth.action("edit community", ["community.admin"]);
1821
+ auth.action("edit group", ["group.admin"]);
1822
+ auth.action("edit post", ["post.admin"]);
1823
+ auth.action("send status change", ["post.statusChange"]);
1824
+ auth.action("edit user", ["user.admin"]);
1825
+ auth.action("edit category", ["category.admin"]);
1826
+ auth.action("edit point", ["point.admin"]);
1827
+ auth.action("delete point", ["point.admin"]);
1828
+ auth.action("edit bulkStatusUpdate", ["bulkStatusUpdates.admin"]);
1829
+ auth.action("edit community marketing", ["community.marketing"]);
1830
+ auth.action("edit group marketing", ["group.marketing"]);
1831
+ auth.action("view organization", ["organization.viewUser"]);
1832
+ auth.action("view domain", ["domain.viewUser"]);
1833
+ auth.action("view community", ["community.viewUser"]);
1834
+ auth.action("view group", ["group.viewUser"]);
1835
+ auth.action("add to group", ["group.addTo"]);
1836
+ auth.action("view post", ["post.viewUser"]);
1837
+ auth.action("view category", ["category.viewUser"]);
1838
+ auth.action("view point", ["point.viewUser"]);
1839
+ auth.action("add to point", ["point.addTo"]);
1840
+ auth.action("view image", ["image.viewUser"]);
1841
+ auth.action("vote on post", ["post.vote"]);
1842
+ auth.action("vote on point", ["point.vote"]);
1843
+ auth.action("rate post", ["post.vote"]);
1844
+ auth.action("add post user images", ["post.vote"]);
1845
+ auth.action("create domainOrganization", [
1846
+ "createDomainOrganization.createDomainOrganization",
1847
+ ]);
1848
+ auth.action("create communityOrganization", [
1849
+ "createCommunityOrganization.createCommunityOrganization",
1850
+ ]);
1851
+ auth.action("create community", ["createDomainCommunity.createCommunity"]);
1852
+ auth.action("create group", ["createCommunityGroup.createGroup"]);
1853
+ auth.action("create post", ["createGroupPost.createPost"]);
1854
+ auth.action("create media", ["createGroupPost.createPost"]);
1855
+ auth.action("create category", ["createGroupCategory.createCategory"]);
1856
+ auth.action("create point", ["createGroupPoint.createPoint"]);
1857
+ auth.action("create bulkStatusUpdate", [
1858
+ "createCommunityBulkStatusUpdate.createBulkStatusUpdate",
1859
+ ]);
1860
+ module.exports = auth;