@yrpri/api 9.0.103 → 9.0.104
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/dist/active-citizen/controllers/activities.cjs +0 -174
- package/dist/active-citizen/controllers/news_feeds.cjs +0 -96
- package/dist/active-citizen/controllers/notifications.cjs +0 -243
- package/dist/active-citizen/controllers/recommendations.cjs +0 -280
- package/dist/active-citizen/engine/allOurIdeas/aiHelper.js +0 -204
- package/dist/active-citizen/engine/allOurIdeas/explainAnswersAssistant.js +0 -66
- package/dist/active-citizen/engine/allOurIdeas/iconGenerator.js +0 -38
- package/dist/active-citizen/engine/analytics/export_anon_community_activities.js +0 -334
- package/dist/active-citizen/engine/analytics/importer.js +0 -308
- package/dist/active-citizen/engine/analytics/manager.cjs +0 -377
- package/dist/active-citizen/engine/analytics/plausible/manager.cjs +0 -500
- package/dist/active-citizen/engine/analytics/statsCalc.cjs +0 -194
- package/dist/active-citizen/engine/analytics/utils.cjs +0 -369
- package/dist/active-citizen/engine/marketing/campaign.cjs +0 -90
- package/dist/active-citizen/engine/moderation/fraud/CreateFraudAuditReport.cjs +0 -313
- package/dist/active-citizen/engine/moderation/fraud/FraudBase.cjs +0 -239
- package/dist/active-citizen/engine/moderation/fraud/FraudDeleteBase.cjs +0 -211
- package/dist/active-citizen/engine/moderation/fraud/FraudDeleteEndorsements.cjs +0 -120
- package/dist/active-citizen/engine/moderation/fraud/FraudDeletePointQualities.cjs +0 -114
- package/dist/active-citizen/engine/moderation/fraud/FraudDeletePoints.cjs +0 -101
- package/dist/active-citizen/engine/moderation/fraud/FraudDeletePosts.cjs +0 -84
- package/dist/active-citizen/engine/moderation/fraud/FraudDeleteRatings.cjs +0 -15
- package/dist/active-citizen/engine/moderation/fraud/FraudGetBase.cjs +0 -133
- package/dist/active-citizen/engine/moderation/fraud/FraudGetEndorsements.cjs +0 -185
- package/dist/active-citizen/engine/moderation/fraud/FraudGetPointQualities.cjs +0 -184
- package/dist/active-citizen/engine/moderation/fraud/FraudGetPoints.cjs +0 -170
- package/dist/active-citizen/engine/moderation/fraud/FraudGetPosts.cjs +0 -109
- package/dist/active-citizen/engine/moderation/fraud/FraudGetRatings.cjs +0 -140
- package/dist/active-citizen/engine/moderation/fraud/FraudScannerNotifier.cjs +0 -279
- package/dist/active-citizen/engine/moderation/get_moderation_items.cjs +0 -386
- package/dist/active-citizen/engine/moderation/image_labeling/CommunityLabeling.cjs +0 -49
- package/dist/active-citizen/engine/moderation/image_labeling/GroupLabeling.cjs +0 -68
- package/dist/active-citizen/engine/moderation/image_labeling/ImageLabelingBase.cjs +0 -288
- package/dist/active-citizen/engine/moderation/image_labeling/PointLabeling.cjs +0 -33
- package/dist/active-citizen/engine/moderation/image_labeling/PostLabeling.cjs +0 -56
- package/dist/active-citizen/engine/moderation/perspective_api_client.cjs +0 -106
- package/dist/active-citizen/engine/moderation/process_moderation_items.cjs +0 -344
- package/dist/active-citizen/engine/moderation/toxicity_analysis.cjs +0 -810
- package/dist/active-citizen/engine/news_feeds/activity_and_item_index_definitions.cjs +0 -15
- package/dist/active-citizen/engine/news_feeds/generate_dynamically.cjs +0 -362
- package/dist/active-citizen/engine/news_feeds/generate_from_notifications.cjs +0 -268
- package/dist/active-citizen/engine/news_feeds/news_feeds_utils.cjs +0 -439
- package/dist/active-citizen/engine/notifications/emails_utils.cjs +0 -569
- package/dist/active-citizen/engine/notifications/generate_point_notifications.cjs +0 -233
- package/dist/active-citizen/engine/notifications/generate_post_notifications.cjs +0 -118
- package/dist/active-citizen/engine/notifications/generate_post_status_change_notifications.cjs +0 -41
- package/dist/active-citizen/engine/notifications/notifications_utils.cjs +0 -148
- package/dist/active-citizen/engine/notifications/point_delivery.cjs +0 -54
- package/dist/active-citizen/engine/notifications/post_delivery.cjs +0 -31
- package/dist/active-citizen/engine/notifications/process_delayed_notifications.cjs +0 -471
- package/dist/active-citizen/engine/notifications/process_general_notifications.cjs +0 -212
- package/dist/active-citizen/engine/old/exporters/categories_dataset.js +0 -153
- package/dist/active-citizen/engine/old/exporters/dataset_tools.js +0 -80
- package/dist/active-citizen/engine/old/exporters/sentiment_dataset.js +0 -157
- package/dist/active-citizen/engine/recommendations/events_importer.cjs +0 -139
- package/dist/active-citizen/engine/recommendations/events_manager.cjs +0 -212
- package/dist/active-citizen/engine/reports/add_points_to_sheet.cjs +0 -83
- package/dist/active-citizen/engine/reports/commonUtils.js +0 -75
- package/dist/active-citizen/engine/reports/common_utils.cjs +0 -740
- package/dist/active-citizen/engine/reports/docx_group_report.cjs +0 -596
- package/dist/active-citizen/engine/reports/xlsAllOurIdeasExport.js +0 -232
- package/dist/active-citizen/engine/reports/xls_community_users_report.cjs +0 -277
- package/dist/active-citizen/engine/reports/xls_group_report.cjs +0 -718
- package/dist/active-citizen/llms/baseChatBot.js +0 -183
- package/dist/active-citizen/llms/imageGeneration/chatGptImageGenerator.js +0 -56
- package/dist/active-citizen/llms/imageGeneration/collectionImageGenerator.js +0 -109
- package/dist/active-citizen/llms/imageGeneration/dalleImageGenerator.js +0 -84
- package/dist/active-citizen/llms/imageGeneration/fluxImageGenerator.js +0 -49
- package/dist/active-citizen/llms/imageGeneration/iImageGenerator.js +0 -1
- package/dist/active-citizen/llms/imageGeneration/imageProcessorService.js +0 -64
- package/dist/active-citizen/llms/imageGeneration/imagenImageGenerator.js +0 -107
- package/dist/active-citizen/llms/imageGeneration/s3Service.js +0 -110
- package/dist/active-citizen/llms/llmTranslation.js +0 -472
- package/dist/active-citizen/models/ac_activity.cjs +0 -216
- package/dist/active-citizen/models/ac_background_job.cjs +0 -109
- package/dist/active-citizen/models/ac_campaign.cjs +0 -97
- package/dist/active-citizen/models/ac_client_activity.cjs +0 -23
- package/dist/active-citizen/models/ac_delayed_notification.cjs +0 -43
- package/dist/active-citizen/models/ac_following.cjs +0 -43
- package/dist/active-citizen/models/ac_list.cjs +0 -68
- package/dist/active-citizen/models/ac_list_users.cjs +0 -19
- package/dist/active-citizen/models/ac_mute.cjs +0 -27
- package/dist/active-citizen/models/ac_news_feed_item.cjs +0 -57
- package/dist/active-citizen/models/ac_news_feed_processed_range.cjs +0 -59
- package/dist/active-citizen/models/ac_notification.cjs +0 -292
- package/dist/active-citizen/models/ac_translation_cache.cjs +0 -750
- package/dist/active-citizen/models/ac_watching.cjs +0 -31
- package/dist/active-citizen/scripts/analytics/setup_all_plausible_goals.cjs +0 -13
- package/dist/active-citizen/scripts/fix_old_delayed_notifications.js +0 -63
- package/dist/active-citizen/scripts/kue_status.js +0 -31
- package/dist/active-citizen/scripts/kue_watch_stuck_jobs.js +0 -24
- package/dist/active-citizen/scripts/translation_clear_language.js +0 -117
- package/dist/active-citizen/scripts/translation_delete.js +0 -27
- package/dist/active-citizen/scripts/translation_replace_text_from_url.js +0 -180
- package/dist/active-citizen/scripts/translation_update.js +0 -28
- package/dist/active-citizen/scripts/translations_list.js +0 -27
- package/dist/active-citizen/utils/airbrake.cjs +0 -17
- package/dist/active-citizen/utils/get_anonymous_system_user.cjs +0 -21
- package/dist/active-citizen/utils/i18n.cjs +0 -3
- package/dist/active-citizen/utils/logger.cjs +0 -25
- package/dist/active-citizen/utils/redisConnection.cjs +0 -29
- package/dist/active-citizen/utils/to_json.cjs +0 -9
- package/dist/active-citizen/utils/translation_cloning.cjs +0 -171
- package/dist/active-citizen/utils/translation_helpers.cjs +0 -534
- package/dist/active-citizen/utils/truncate_text.cjs +0 -21
- package/dist/active-citizen/utils/updateAllLocalesFromEn.js +0 -253
- package/dist/active-citizen/utils/updateLocaleFolders.js +0 -34
- package/dist/active-citizen/workers/activity.cjs +0 -189
- package/dist/active-citizen/workers/anonymizations.cjs +0 -734
- package/dist/active-citizen/workers/bulk_status_update.cjs +0 -458
- package/dist/active-citizen/workers/delayed_jobs.cjs +0 -244
- package/dist/active-citizen/workers/deletions.cjs +0 -1911
- package/dist/active-citizen/workers/email.cjs +0 -9
- package/dist/active-citizen/workers/fraud_management.cjs +0 -109
- package/dist/active-citizen/workers/generativeAi.js +0 -56
- package/dist/active-citizen/workers/main.cjs +0 -89
- package/dist/active-citizen/workers/marketing.cjs +0 -25
- package/dist/active-citizen/workers/moderation.cjs +0 -73
- package/dist/active-citizen/workers/notification_delivery.cjs +0 -368
- package/dist/active-citizen/workers/notification_news_feed.cjs +0 -142
- package/dist/active-citizen/workers/queue.cjs +0 -99
- package/dist/active-citizen/workers/recount.cjs +0 -74
- package/dist/active-citizen/workers/reports.cjs +0 -42
- package/dist/active-citizen/workers/similarities.cjs +0 -21
- package/dist/active-citizen/workers/speech_to_text.cjs +0 -482
- package/dist/agents/assistants/agentAssistant.js +0 -88
- package/dist/agents/assistants/baseAssistant.js +0 -888
- package/dist/agents/assistants/baseAssistantWithVoice.js +0 -150
- package/dist/agents/assistants/modes/agentDirectConnection.js +0 -84
- package/dist/agents/assistants/modes/agentSelectionMode.js +0 -44
- package/dist/agents/assistants/modes/baseAssistantMode.js +0 -54
- package/dist/agents/assistants/modes/tools/agentTools.js +0 -447
- package/dist/agents/assistants/modes/tools/baseTools.js +0 -58
- package/dist/agents/assistants/modes/tools/loginTools.js +0 -156
- package/dist/agents/assistants/modes/tools/models/agents.js +0 -146
- package/dist/agents/assistants/modes/tools/models/subscriptions.js +0 -332
- package/dist/agents/assistants/modes/tools/models/users.js +0 -11
- package/dist/agents/assistants/modes/tools/navigationTools.js +0 -166
- package/dist/agents/assistants/modes/tools/subscriptionTools.js +0 -323
- package/dist/agents/assistants/modes/tools/workflowConverstationTools.js +0 -112
- package/dist/agents/assistants/voiceAssistant.js +0 -619
- package/dist/agents/controllers/agentProductController.js +0 -103
- package/dist/agents/controllers/agentSubscriptionController.js +0 -261
- package/dist/agents/controllers/assistantsController.js +0 -511
- package/dist/agents/controllers/policySynthAgents.js +0 -395
- package/dist/agents/managers/agentProductManager.js +0 -91
- package/dist/agents/managers/emailInvitesManager.js +0 -55
- package/dist/agents/managers/emailTemplateRenderer.js +0 -362
- package/dist/agents/managers/newAiModelSetup.js +0 -650
- package/dist/agents/managers/notificationAgentQueueManager.js +0 -510
- package/dist/agents/managers/subscriptionManager.js +0 -535
- package/dist/agents/managers/workflowConversationManager.js +0 -79
- package/dist/agents/models/agentProduct.js +0 -116
- package/dist/agents/models/agentProductBoosterPurchase.js +0 -58
- package/dist/agents/models/agentProductBundle.js +0 -68
- package/dist/agents/models/agentProductRun.js +0 -52
- package/dist/agents/models/discount.js +0 -88
- package/dist/agents/models/subscription.js +0 -79
- package/dist/agents/models/subscriptionPlan.js +0 -46
- package/dist/agents/models/subscriptionUser.js +0 -27
- package/dist/agents/models/testData/createEvolyAgentProduct.js +0 -477
- package/dist/agents/models/testData/old/updateAgentWorkflowConfiguration.js +0 -230
- package/dist/agents/models/testData/setupEvolyAgentProductConfig.js +0 -233
- package/dist/agents/models/testData/updateAgentWorkflowConfiguration.js +0 -230
- package/dist/agents/models/workflowConversation.js +0 -53
- package/dist/agents/tools/setTemplateWorkflowCommunityId.js +0 -46
- package/dist/app.js +0 -943
- package/dist/authorization.cjs +0 -1860
- package/dist/bot_control.js +0 -1930
- package/dist/config/config.cjs +0 -14
- package/dist/config/config.js +0 -14
- package/dist/controllers/allOurIdeas.js +0 -696
- package/dist/controllers/audios.cjs +0 -100
- package/dist/controllers/bulkStatusUpdates.cjs +0 -202
- package/dist/controllers/categories.cjs +0 -199
- package/dist/controllers/communities.cjs +0 -2996
- package/dist/controllers/domains.cjs +0 -1341
- package/dist/controllers/externalIds.cjs +0 -223
- package/dist/controllers/groups.cjs +0 -4309
- package/dist/controllers/images.cjs +0 -499
- package/dist/controllers/index.cjs +0 -449
- package/dist/controllers/legacyPages.cjs +0 -35
- package/dist/controllers/legacyPosts.cjs +0 -56
- package/dist/controllers/legacyUsers.cjs +0 -36
- package/dist/controllers/nonSpa.cjs +0 -574
- package/dist/controllers/organizations.cjs +0 -250
- package/dist/controllers/points.cjs +0 -1137
- package/dist/controllers/posts.cjs +0 -2036
- package/dist/controllers/ratings.cjs +0 -234
- package/dist/controllers/users.cjs +0 -2255
- package/dist/controllers/videos.cjs +0 -226
- package/dist/deleteUnwantedDeclerations.cjs +0 -55
- package/dist/migrations/agentAuditLogs.cjs +0 -46
- package/dist/migrations/agentClasses.cjs +0 -60
- package/dist/migrations/agentConnectorClasses.cjs +0 -61
- package/dist/migrations/agentConnectors.cjs +0 -50
- package/dist/migrations/agentEvals.cjs +0 -45
- package/dist/migrations/agentRegistries.cjs +0 -40
- package/dist/migrations/agents.cjs +0 -54
- package/dist/migrations/aiModels.cjs +0 -49
- package/dist/migrations/apiUsage.cjs +0 -47
- package/dist/migrations/apis.cjs +0 -49
- package/dist/migrations/groupPrivateData.cjs +0 -30
- package/dist/migrations/modelUsage.cjs +0 -60
- package/dist/migrations/oldMigrations/2019/20181030020612-AddActivitiesIndex.js +0 -23
- package/dist/migrations/oldMigrations/2019/20181102210612-AddFirstVideoFeatures.js +0 -360
- package/dist/migrations/oldMigrations/2019/20181212210612-ModerationFeatures.js +0 -29
- package/dist/migrations/oldMigrations/2019/2019010610612-CommunityFolders.js +0 -43
- package/dist/migrations/oldMigrations/2019/20190117020612-AddMissingIndexes.js +0 -24
- package/dist/migrations/oldMigrations/2019/20190117020612-RemoveUnusedIndexes.js +0 -29
- package/dist/migrations/oldMigrations/2019/20190127020612-RemoveUnusedIndexesPartThree.js +0 -22
- package/dist/migrations/oldMigrations/2019/20190127020612-RemoveUnusedIndexesPartTwo.js +0 -23
- package/dist/migrations/oldMigrations/2019/20190223020612-AddPrivateProfileDataToUsers.js +0 -18
- package/dist/migrations/oldMigrations/2019/20190706210612-AddCustomRatings.js +0 -43
- package/dist/migrations/oldMigrations/2019/20190829210612-AddGeneralStore.js +0 -36
- package/dist/migrations/oldMigrations/2019/20192811210612-AddAcClientActivities.js +0 -41
- package/dist/migrations/oldMigrations/2020/20190527020612-WorkOnIndexes.js +0 -88
- package/dist/migrations/oldMigrations/2020/20200409020612-AddBackgroundJob.js +0 -33
- package/dist/migrations/oldMigrations/2020/20200716210612-AddDataToCollections.js +0 -38
- package/dist/migrations/oldMigrations/2022/20220215100612-AddDataToEndorsements.js +0 -19
- package/dist/migrations/oldMigrations/2022/20220220100612-AddDataForFraudDetection.js +0 -19
- package/dist/migrations/oldMigrations/2022/20220903100612-AddPromotionFeatures.js +0 -127
- package/dist/migrations/oldMigrations/2022/onHold/20200527020612-AddCampaigns.js +0 -68
- package/dist/migrations/oldMigrations/2024/20241304175112-AddMediaSupportForHtmlGroups.cjs +0 -63
- package/dist/migrations/oldMigrations/older/20160511172514-AddNotificationFeatures.js +0 -14
- package/dist/migrations/oldMigrations/older/20161030020612-AddBulkStatusUpdate.js +0 -71
- package/dist/migrations/oldMigrations/older/20170514035258-add-metadata-to-invites.js +0 -12
- package/dist/migrations/oldMigrations/older/20180216020612-AddTranslationCaches.js +0 -46
- package/dist/migrations/oldMigrations/older/20180218210612-AddTranslationAndLanguages.js +0 -46
- package/dist/migrations/privateAccessStore.cjs +0 -55
- package/dist/migrations/zzz_associations.cjs +0 -154
- package/dist/migrations/zzzz_createUsersAndAdminsForClasses.cjs +0 -100
- package/dist/migrations/zzzzz_create_agent_runs.cjs +0 -606
- package/dist/migrations/zzzzzz_create_agent_runs_fix.cjs +0 -11
- package/dist/migrations/zzzzzzz_create_trees.cjs +0 -81
- package/dist/models/audio.cjs +0 -430
- package/dist/models/bulk_status_update.cjs +0 -58
- package/dist/models/campaign.cjs +0 -78
- package/dist/models/category.cjs +0 -94
- package/dist/models/community.cjs +0 -337
- package/dist/models/domain.cjs +0 -486
- package/dist/models/endorsement.cjs +0 -39
- package/dist/models/general_data_store.cjs +0 -20
- package/dist/models/group.cjs +0 -728
- package/dist/models/image.cjs +0 -579
- package/dist/models/index.cjs +0 -186
- package/dist/models/invite.cjs +0 -48
- package/dist/models/iso_country.cjs +0 -16
- package/dist/models/organization.cjs +0 -122
- package/dist/models/page.cjs +0 -273
- package/dist/models/point.cjs +0 -622
- package/dist/models/point_quality.cjs +0 -39
- package/dist/models/point_revision.cjs +0 -47
- package/dist/models/post.cjs +0 -680
- package/dist/models/post_revision.cjs +0 -38
- package/dist/models/post_status_change.cjs +0 -35
- package/dist/models/promotion.cjs +0 -34
- package/dist/models/rating.cjs +0 -51
- package/dist/models/relationship.cjs +0 -19
- package/dist/models/request_to_join.cjs +0 -20
- package/dist/models/user.cjs +0 -604
- package/dist/models/user_legacy_password.cjs +0 -13
- package/dist/models/video.cjs +0 -1137
- package/dist/publish.js +0 -40
- package/dist/repack.js +0 -53
- package/dist/scripts/addRatingUsersToGroup.js +0 -51
- package/dist/scripts/addUserToOrganization.js +0 -71
- package/dist/scripts/analyseRatingsForCommunity.js +0 -150
- package/dist/scripts/analyzeAndFixBrokenPointUsers.js +0 -28
- package/dist/scripts/analyzeEndorsementsByCountry.js +0 -70
- package/dist/scripts/analyzePostsForCommunity.js +0 -185
- package/dist/scripts/bulkStatusUpdates/listUpdates.js +0 -14
- package/dist/scripts/bulkStatusUpdates/mergeLatestPostsToUpdate.js +0 -110
- package/dist/scripts/bulkStatusUpdates/performUpdate.js +0 -116
- package/dist/scripts/bulkStatusUpdates/performUpdateForGroup.cjs +0 -124
- package/dist/scripts/bulkStatusUpdates/performUpdateForStatus.js +0 -141
- package/dist/scripts/change/changeVideoAspectTo.js +0 -34
- package/dist/scripts/change/setUseNewVersion.cjs +0 -22
- package/dist/scripts/changeCommunityGroupcount.js +0 -30
- package/dist/scripts/changeCommunityPostCount.js +0 -30
- package/dist/scripts/changeGroupPostCount.js +0 -30
- package/dist/scripts/changeLanguage.js +0 -50
- package/dist/scripts/changeOfficalStatus.js +0 -30
- package/dist/scripts/cleanups/deleteAnonNotifications.cjs +0 -91
- package/dist/scripts/cleanups/deleteLinkGroupsWithDeletedCommunities.js +0 -62
- package/dist/scripts/cleanups/deleteYearOldNotifications.cjs +0 -72
- package/dist/scripts/cleanups/removeAllUsersFromHiddenPublicGroup.js +0 -43
- package/dist/scripts/clearAllEndorsementInGroup.js +0 -50
- package/dist/scripts/cloning/clearUsersForCommunitiesFromUrl.js +0 -129
- package/dist/scripts/cloning/cloneFromUrlScript.js +0 -65
- package/dist/scripts/cloning/cloneWBFromUrlScriptAndCreateLinks.js +0 -140
- package/dist/scripts/cloning/cloneWBFromUrlScriptNoUsersOrPoints.js +0 -140
- package/dist/scripts/cloning/cloneWBSerbianFromUrlScriptAndCreateLinks.js +0 -131
- package/dist/scripts/cloning/copyCommunityConfigAndTranslationsFromURL.js +0 -173
- package/dist/scripts/cloning/copyCommunityOneGroupToDomainNoUsersNoEndorsements.js +0 -18
- package/dist/scripts/cloning/copyCommunityToDomainNoUsersNoEndorsements.js +0 -17
- package/dist/scripts/cloning/copyCommunityToDomainWithEverything.js +0 -17
- package/dist/scripts/cloning/copyCommunityToDomainWithOnlyGroups.js +0 -26
- package/dist/scripts/cloning/copyGroupConfigAndTranslationsFromURL.js +0 -205
- package/dist/scripts/cloning/copyPostToGroupOld.js +0 -397
- package/dist/scripts/cloning/copyPostVideosFromURL.js +0 -236
- package/dist/scripts/cloning/copyPostWithOutAnyVotingOrActivities.js +0 -17
- package/dist/scripts/cloning/deepCloneSerbianWBFromUrlScriptAndCreateLinks.js +0 -131
- package/dist/scripts/cloning/deepCloneWBFromUrlScriptAndCreateLinks.js +0 -139
- package/dist/scripts/cloning/setAdminsFromURL.js +0 -161
- package/dist/scripts/cloning/setExternalIdsFromURL.js +0 -129
- package/dist/scripts/countCommunity.js +0 -291
- package/dist/scripts/countCommunityUsers.js +0 -152
- package/dist/scripts/countDelayedNotifications.js +0 -18
- package/dist/scripts/countGroup.js +0 -246
- package/dist/scripts/countStuff.js +0 -67
- package/dist/scripts/countUniqueVotersInAGroup.js +0 -48
- package/dist/scripts/createInvitesAndShow.js +0 -75
- package/dist/scripts/database/sync_database.js +0 -14
- package/dist/scripts/database/sync_dev_database.js +0 -17
- package/dist/scripts/debugNotifications.js +0 -58
- package/dist/scripts/deleteAllNewsFeeds.js +0 -10
- package/dist/scripts/deleteCategory.js +0 -13
- package/dist/scripts/deleteOldAppActivities.js +0 -40
- package/dist/scripts/deletePostContactDataForCommunity.js +0 -53
- package/dist/scripts/destroy/destroy_all_but_one_domain.js +0 -1026
- package/dist/scripts/displayAuthorForPost.js +0 -16
- package/dist/scripts/endorsementFraudDetection/analyseEndorsementsForCommunity.js +0 -183
- package/dist/scripts/endorsementFraudDetection/bulkDeleteDuplicateEndorsmentsFromUrl.js +0 -208
- package/dist/scripts/exportAllStatusChanges.js +0 -36
- package/dist/scripts/exportClientAcitivity.js +0 -36
- package/dist/scripts/exportEndorsementsForCommunity.js +0 -79
- package/dist/scripts/exportPointQualitiesForCommunity.js +0 -84
- package/dist/scripts/exportPostsAndPointsForCommunity.js +0 -147
- package/dist/scripts/exportPostsDataSetForDomain.js +0 -244
- package/dist/scripts/exportPostsForGroup.js +0 -173
- package/dist/scripts/exportRatingsForPost.js +0 -15
- package/dist/scripts/exportUserEndorsementsWithUserAnalysis.js +0 -123
- package/dist/scripts/exportUsersForCommunity.js +0 -24
- package/dist/scripts/exportUsersForDomain.js +0 -24
- package/dist/scripts/exportUsersForGroup.js +0 -24
- package/dist/scripts/exports/ratingDistribution.js +0 -71
- package/dist/scripts/exports/whoEndorsedWhatByCommunity.js +0 -56
- package/dist/scripts/findUnusedClientImports.js +0 -56
- package/dist/scripts/fixAllPostPointCounts.js +0 -22
- package/dist/scripts/fixAnonNotificationsSettings.js +0 -48
- package/dist/scripts/fixCountKopavogur.js +0 -9
- package/dist/scripts/fixEndorsementsAfterCopyPostToGroup.js +0 -190
- package/dist/scripts/fixExternalUserId.js +0 -24
- package/dist/scripts/fixGroupAccess.js +0 -16
- package/dist/scripts/fixGroupIdeasAndPointsCount.js +0 -49
- package/dist/scripts/fixNotificationSettings.js +0 -39
- package/dist/scripts/fixSurveyRadioBakedInSubCodes.js +0 -64
- package/dist/scripts/fixWrongUserIdForStatusUpdates.js +0 -49
- package/dist/scripts/gallery/exportGalleryData.js +0 -40
- package/dist/scripts/gallery/importGalleryForCommunity.js +0 -168
- package/dist/scripts/gallery/readJsonAndDownloadImagesVersion2.js +0 -55
- package/dist/scripts/gallery/refreshAcApiPostIdsForCommunity.js +0 -58
- package/dist/scripts/genderAnalysis.js +0 -63
- package/dist/scripts/genderAnalysisByStatus.js +0 -62
- package/dist/scripts/importAllLocalesFromLocalFolders.js +0 -55
- package/dist/scripts/importDomain.js +0 -1652
- package/dist/scripts/keys/addOidcToDomain.cjs +0 -61
- package/dist/scripts/landUseGame/export3Ddata.js +0 -162
- package/dist/scripts/listLanguagesForGroup.js +0 -54
- package/dist/scripts/loadTestCreateDummyContentForGroup.js +0 -27
- package/dist/scripts/makeRecursiveMapData.js +0 -103
- package/dist/scripts/mapping/community_map_csv.js +0 -145
- package/dist/scripts/moveCommunityToDomain.js +0 -22
- package/dist/scripts/moveGroupToCommunity.js +0 -23
- package/dist/scripts/movePostToGroup.js +0 -101
- package/dist/scripts/movePostsToGroupsRecountGroupFromUrl.js +0 -297
- package/dist/scripts/oldMovePostToGroup.js +0 -153
- package/dist/scripts/processCsvForPdfUrls.js +0 -37
- package/dist/scripts/processCsvForTranslationAndToxicity.js +0 -125
- package/dist/scripts/recount/recount_recursive_communities.js +0 -125
- package/dist/scripts/recountALLCommunityGroupCounts.js +0 -37
- package/dist/scripts/recountAll.js +0 -97
- package/dist/scripts/recountCommunitesFromUrl.js +0 -58
- package/dist/scripts/recountCommunity.js +0 -19
- package/dist/scripts/recountGroup.js +0 -218
- package/dist/scripts/recountGroupNoUserChange.js +0 -219
- package/dist/scripts/resetAllEndorsementsForGroup.js +0 -57
- package/dist/scripts/resetEnTranslationForGroup.js +0 -45
- package/dist/scripts/setAdminOnAll.cjs +0 -107
- package/dist/scripts/setDomainAdmin.cjs +0 -43
- package/dist/scripts/setDomainLocales.js +0 -33
- package/dist/scripts/setEarlQuestionIdOnGroup.cjs +0 -29
- package/dist/scripts/setLanguageOnGroupCommunitesFromUrl.js +0 -86
- package/dist/scripts/setMemberOfAll.js +0 -101
- package/dist/scripts/setNewUserForContentOfCommunity.js +0 -189
- package/dist/scripts/setOfficialStatusOnAllPostsForCommunity.js +0 -35
- package/dist/scripts/setUserOnAll.js +0 -101
- package/dist/scripts/showCategoryForGroup.js +0 -18
- package/dist/scripts/showOldActivityTypes.js +0 -14
- package/dist/scripts/showPostsMissingCategoryForGroup.js +0 -17
- package/dist/scripts/showStatuses.js +0 -17
- package/dist/scripts/showUniqueVotersInCommunity.js +0 -61
- package/dist/scripts/showUserAgentsAndIpsForEmails.js +0 -66
- package/dist/scripts/simpleExportForGroupsForCommunity.js +0 -46
- package/dist/scripts/simpleExportForPointsForCommunity.js +0 -82
- package/dist/scripts/simpleExportForPostsForCommunity.js +0 -61
- package/dist/scripts/testForEndorsments.js +0 -21
- package/dist/scripts/undeleteGroupAndAllContent.js +0 -151
- package/dist/scripts/undeletePost.js +0 -135
- package/dist/scripts/unlinkSsn.js +0 -23
- package/dist/scripts/updateFromAlthingi.js +0 -303
- package/dist/server.js +0 -3
- package/dist/utils/airbrake.cjs +0 -17
- package/dist/utils/cjsCodeReview.js +0 -99
- package/dist/utils/community_mapping_tools.cjs +0 -124
- package/dist/utils/copy_utils.cjs +0 -1399
- package/dist/utils/docx_utils.cjs +0 -464
- package/dist/utils/export_utils.cjs +0 -491
- package/dist/utils/i18n.cjs +0 -17
- package/dist/utils/is_valid_db_id.cjs +0 -28
- package/dist/utils/logger.cjs +0 -25
- package/dist/utils/loggerTs.js +0 -26
- package/dist/utils/manifest_generator.cjs +0 -104
- package/dist/utils/parse_domain.cjs +0 -16
- package/dist/utils/recount_utils.cjs +0 -415
- package/dist/utils/sharing_parameters.cjs +0 -111
- package/dist/utils/sitemap_generator.cjs +0 -286
- package/dist/utils/to_json.cjs +0 -14
- package/dist/utils/ypLanguages.js +0 -747
- package/dist/webSockets.js +0 -77
|
@@ -1,696 +0,0 @@
|
|
|
1
|
-
//import models from "../models/index.js";
|
|
2
|
-
import models from "../models/index.cjs";
|
|
3
|
-
import auth from "../authorization.cjs";
|
|
4
|
-
import express from "express";
|
|
5
|
-
import crypto from "crypto";
|
|
6
|
-
const dbModels = models;
|
|
7
|
-
const Group = dbModels.Group;
|
|
8
|
-
const User = dbModels.User;
|
|
9
|
-
const AcBackgroundJob = dbModels.AcBackgroundJob;
|
|
10
|
-
const PAIRWISE_API_HOST = process.env.PAIRWISE_API_HOST;
|
|
11
|
-
const PAIRWISE_USERNAME = process.env.PAIRWISE_USERNAME;
|
|
12
|
-
const PAIRWISE_PASSWORD = process.env.PAIRWISE_PASSWORD;
|
|
13
|
-
const defaultAuthHeader = {
|
|
14
|
-
"Content-Type": "application/json",
|
|
15
|
-
Authorization: `Basic ${Buffer.from(`${PAIRWISE_USERNAME}:${PAIRWISE_PASSWORD}`).toString("base64")}`,
|
|
16
|
-
};
|
|
17
|
-
const defaultHeader = {
|
|
18
|
-
...{ "Content-Type": "application/json" },
|
|
19
|
-
...defaultAuthHeader,
|
|
20
|
-
};
|
|
21
|
-
//import auth from "../authorization.js";
|
|
22
|
-
import { AiHelper } from "../active-citizen/engine/allOurIdeas/aiHelper.js";
|
|
23
|
-
import { ExplainAnswersAssistant } from "../active-citizen/engine/allOurIdeas/explainAnswersAssistant.js";
|
|
24
|
-
import OpenAI from "openai";
|
|
25
|
-
import queue from "../active-citizen/workers/queue.cjs";
|
|
26
|
-
export class AllOurIdeasController {
|
|
27
|
-
constructor(wsClients) {
|
|
28
|
-
this.path = "/api/allOurIdeas";
|
|
29
|
-
this.router = express.Router();
|
|
30
|
-
this.wsClients = wsClients;
|
|
31
|
-
this.initializeRoutes();
|
|
32
|
-
}
|
|
33
|
-
async initializeRoutes() {
|
|
34
|
-
this.router.get("/:groupId", auth.can("view group"), this.showEarl.bind(this));
|
|
35
|
-
this.router.put("/:groupId/:type/start_report_creation", auth.can("edit group"), this.exportXls.bind(this));
|
|
36
|
-
this.router.get("/:groupId/:jobId/report_creation_progress", auth.can("edit group"), this.getXlsExportProgress.bind(this));
|
|
37
|
-
this.router.get("/:domainId/getAoiSiteStats", auth.can("view domain"), this.getAoiSiteStats.bind(this));
|
|
38
|
-
this.router.post("/:domainId/questions/throughDomain", auth.can("create community"), this.createQuestion.bind(this));
|
|
39
|
-
this.router.post("/:communityId/questions", auth.can("create group"), this.createQuestion.bind(this));
|
|
40
|
-
this.router.put("/:domainId/generateIdeas/throughDomain", auth.can("create community"), this.generateIdeas.bind(this));
|
|
41
|
-
this.router.put("/:communityId/generateIdeas", auth.can("create group"), this.generateIdeas.bind(this));
|
|
42
|
-
this.router.put("/:groupId/llmAnswerExplain", auth.can("view group"), this.llmAnswerExplain.bind(this));
|
|
43
|
-
this.router.get("/:domainId/choices/:questionId/throughDomain", auth.can("create community"), this.getChoices.bind(this));
|
|
44
|
-
this.router.get("/:groupId/choices/:questionId/throughGroup", auth.can("view group"), this.getChoices.bind(this));
|
|
45
|
-
this.router.get("/:communityId/choices/:questionId", auth.can("create group"), this.getChoices.bind(this));
|
|
46
|
-
this.router.post("/:groupId/questions/:questionId/prompts/:promptId/votes", auth.can("view group"), this.vote.bind(this));
|
|
47
|
-
this.router.post("/:groupId/questions/:questionId/prompts/:promptId/skips", auth.can("view group"), this.skip.bind(this));
|
|
48
|
-
this.router.post("/:groupId/questions/:questionId/addIdea", auth.can("view group"), this.addIdea.bind(this));
|
|
49
|
-
this.router.get("/:groupId/questions/:wsClientSocketId/:analysisIndex/:analysisTypeIndex/analysis", auth.can("view group"), this.analysis.bind(this));
|
|
50
|
-
this.router.put("/:communityId/questions/:questionId/choices/:choiceId", auth.can("create group"), this.updateCoiceData.bind(this));
|
|
51
|
-
this.router.put("/:domainId/questions/:questionId/choices/:choiceId/throughDomain", auth.can("create community"), this.updateCoiceData.bind(this));
|
|
52
|
-
this.router.put("/:groupId/questions/:questionId/choices/:choiceId/throughGroup", auth.can("view group"), this.updateCoiceData.bind(this));
|
|
53
|
-
this.router.put("/:communityId/questions/:questionId/choices/:choiceId/active", auth.can("create group"), this.updateActive.bind(this));
|
|
54
|
-
this.router.put("/:domainId/questions/:questionId/choices/:choiceId/active/throughDomain", auth.can("create community"), this.updateActive.bind(this));
|
|
55
|
-
this.router.put("/:communityId/questions/:questionId/name", auth.can("create group"), this.updateQuestionName.bind(this));
|
|
56
|
-
this.router.put("/:domainId/questions/:questionId/name/throughDomain", auth.can("create community"), this.updateQuestionName.bind(this));
|
|
57
|
-
this.router.get("/:groupId/content/:extraId/:questionId/translatedText", auth.can("view group"), this.getTranslatedText.bind(this));
|
|
58
|
-
this.router.get("/:groupId/content/:extraId/translatedText", auth.can("view group"), this.getTranslatedText.bind(this));
|
|
59
|
-
}
|
|
60
|
-
async getAoiSiteStats(req, res) {
|
|
61
|
-
try {
|
|
62
|
-
const choiceResponse = await fetch(`${PAIRWISE_API_HOST}/questions/site_stats.json`, {
|
|
63
|
-
method: "GET",
|
|
64
|
-
headers: defaultAuthHeader,
|
|
65
|
-
});
|
|
66
|
-
const totalGroupCount = await Group.count();
|
|
67
|
-
if (!choiceResponse.ok) {
|
|
68
|
-
console.error(choiceResponse.statusText);
|
|
69
|
-
throw new Error("Choice creation failed.");
|
|
70
|
-
}
|
|
71
|
-
const stats = (await choiceResponse.json());
|
|
72
|
-
// Add original allourideas.org stats (as of 24/3/2024)
|
|
73
|
-
stats.choices_count = stats.choices_count + 1499910;
|
|
74
|
-
stats.total_questions = totalGroupCount + 27555;
|
|
75
|
-
stats.votes_count = stats.votes_count + 60200000;
|
|
76
|
-
if (stats) {
|
|
77
|
-
res.send(stats);
|
|
78
|
-
}
|
|
79
|
-
else {
|
|
80
|
-
res.status(404).send("Not found");
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
catch (error) {
|
|
84
|
-
console.error(error);
|
|
85
|
-
res
|
|
86
|
-
.status(500)
|
|
87
|
-
.json({ error: "Failed to fetch total vote and questions count" });
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
async addIdea(req, res) {
|
|
91
|
-
const { newIdea, id } = req.body;
|
|
92
|
-
const { groupId } = req.params;
|
|
93
|
-
const locale = req.query.locale;
|
|
94
|
-
let choiceParams = {
|
|
95
|
-
visitor_identifier: req.session.id,
|
|
96
|
-
data: {
|
|
97
|
-
content: newIdea,
|
|
98
|
-
isGeneratingImage: undefined,
|
|
99
|
-
},
|
|
100
|
-
question_id: req.params.questionId,
|
|
101
|
-
};
|
|
102
|
-
//@ts-ignore
|
|
103
|
-
choiceParams["local_identifier"] = req.user ? req.user.id : req.session.id;
|
|
104
|
-
console.log(`choiceParams: ${JSON.stringify(choiceParams)}`);
|
|
105
|
-
try {
|
|
106
|
-
const group = (await Group.findOne({
|
|
107
|
-
where: {
|
|
108
|
-
id: groupId,
|
|
109
|
-
},
|
|
110
|
-
attributes: ["id", "configuration"],
|
|
111
|
-
}));
|
|
112
|
-
const aoiConfig = group.configuration.allOurIdeas;
|
|
113
|
-
if (group && aoiConfig?.earl) {
|
|
114
|
-
const choiceResponse = await fetch(`${PAIRWISE_API_HOST}/choices.json`, {
|
|
115
|
-
method: "POST",
|
|
116
|
-
headers: defaultAuthHeader,
|
|
117
|
-
body: JSON.stringify(choiceParams),
|
|
118
|
-
});
|
|
119
|
-
if (!choiceResponse.ok) {
|
|
120
|
-
console.error(choiceResponse.statusText);
|
|
121
|
-
throw new Error("Choice creation failed.");
|
|
122
|
-
}
|
|
123
|
-
const choice = (await choiceResponse.json());
|
|
124
|
-
choice.data = JSON.parse(choice.data);
|
|
125
|
-
let flagged = false;
|
|
126
|
-
if (process.env.OPENAI_API_KEY &&
|
|
127
|
-
aoiConfig.earl?.configuration?.enableAiModeration) {
|
|
128
|
-
flagged = await this.getModerationFlag(newIdea);
|
|
129
|
-
if (flagged) {
|
|
130
|
-
await this.deactivateChoice(req, choice);
|
|
131
|
-
console.log("----------------------------------");
|
|
132
|
-
console.log(`Flagged BY OPENAI: ${flagged}`);
|
|
133
|
-
console.log("----------------------------------");
|
|
134
|
-
}
|
|
135
|
-
else {
|
|
136
|
-
console.log(`Not flagged BY OPENAI Moderation API: ${flagged}`);
|
|
137
|
-
if (aoiConfig.earl?.configuration?.moderationPrompt) {
|
|
138
|
-
const aiHelper = new AiHelper();
|
|
139
|
-
const passedModeration = await aiHelper.getModerationResponse(aoiConfig.earl.configuration.moderationPrompt, aoiConfig.earl.question?.name, newIdea);
|
|
140
|
-
if (!passedModeration) {
|
|
141
|
-
await this.deactivateChoice(req, choice);
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
else {
|
|
147
|
-
console.log(`Adding idea to moderation queue`);
|
|
148
|
-
await this.deactivateChoice(req, choice);
|
|
149
|
-
}
|
|
150
|
-
// Implement email notification logic based on choice's active status
|
|
151
|
-
res.json({
|
|
152
|
-
active: choice.active,
|
|
153
|
-
flagged: flagged,
|
|
154
|
-
choice: choice,
|
|
155
|
-
choice_status: choice.active ? "active" : "inactive",
|
|
156
|
-
message: `You just submitted: ${escape(newIdea)}`, // Use a proper escape function
|
|
157
|
-
});
|
|
158
|
-
}
|
|
159
|
-
else {
|
|
160
|
-
res.status(404).send("Not found");
|
|
161
|
-
return;
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
catch (error) {
|
|
165
|
-
console.error(error);
|
|
166
|
-
res.status(500).json({ error: "Addition of new idea failed" });
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
async getModerationFlag(data) {
|
|
170
|
-
const openaiClient = new OpenAI({
|
|
171
|
-
apiKey: process.env.OPENAI_API_KEY,
|
|
172
|
-
});
|
|
173
|
-
const moderationResponse = await openaiClient.moderations.create({
|
|
174
|
-
input: data,
|
|
175
|
-
});
|
|
176
|
-
return moderationResponse.results[0].flagged;
|
|
177
|
-
}
|
|
178
|
-
async getModerationResults(data) {
|
|
179
|
-
const openaiClient = new OpenAI({
|
|
180
|
-
apiKey: process.env.OPENAI_API_KEY,
|
|
181
|
-
});
|
|
182
|
-
const moderationResponse = await openaiClient.completions.create({
|
|
183
|
-
model: "",
|
|
184
|
-
prompt: data,
|
|
185
|
-
max_tokens: 1,
|
|
186
|
-
});
|
|
187
|
-
}
|
|
188
|
-
async deactivateChoice(req, choice) {
|
|
189
|
-
try {
|
|
190
|
-
const response = await fetch(`${PAIRWISE_API_HOST}/questions/${req.params.questionId}/choices/${choice.id}.json`, {
|
|
191
|
-
method: "PUT",
|
|
192
|
-
headers: defaultHeader,
|
|
193
|
-
body: JSON.stringify({
|
|
194
|
-
active: false,
|
|
195
|
-
}),
|
|
196
|
-
});
|
|
197
|
-
choice.active = false;
|
|
198
|
-
}
|
|
199
|
-
catch (error) {
|
|
200
|
-
console.error(error);
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
async getTranslatedText(req, res) {
|
|
204
|
-
try {
|
|
205
|
-
//@ts-ignore
|
|
206
|
-
models.AcTranslationCache.getTranslation(req, {}, function (error, translation) {
|
|
207
|
-
if (error) {
|
|
208
|
-
console.error(error);
|
|
209
|
-
res.status(500).send("A getTranslatedText error occurred");
|
|
210
|
-
}
|
|
211
|
-
else {
|
|
212
|
-
res.send(translation);
|
|
213
|
-
}
|
|
214
|
-
});
|
|
215
|
-
}
|
|
216
|
-
catch (error) {
|
|
217
|
-
console.error(error);
|
|
218
|
-
res.status(500).send("A getTranslatedText error occurred");
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
async generateIdeas(req, res) {
|
|
222
|
-
const { currentIdeas, wsClientSocketId, question } = req.body;
|
|
223
|
-
console.log(`generateIdeas: ${wsClientSocketId}`);
|
|
224
|
-
const swClientSocket = this.wsClients.get(wsClientSocketId);
|
|
225
|
-
if (swClientSocket) {
|
|
226
|
-
const aiHelper = new AiHelper(swClientSocket);
|
|
227
|
-
await aiHelper.getAnswerIdeas(question, currentIdeas, "");
|
|
228
|
-
res.sendStatus(200);
|
|
229
|
-
}
|
|
230
|
-
else {
|
|
231
|
-
//TODO: Have it refresh the websocket on the client
|
|
232
|
-
res.status(404).send("Websocket not found");
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
async getXlsExportProgress(req, res) {
|
|
236
|
-
AcBackgroundJob.findOne({
|
|
237
|
-
where: {
|
|
238
|
-
id: req.params.jobId,
|
|
239
|
-
},
|
|
240
|
-
attributes: ["id", "progress", "error", "data"],
|
|
241
|
-
})
|
|
242
|
-
.then((job) => {
|
|
243
|
-
res.send(job);
|
|
244
|
-
})
|
|
245
|
-
.catch((error) => {
|
|
246
|
-
console.error("Could not get backgroundJob", {
|
|
247
|
-
err: error,
|
|
248
|
-
context: "start_report_creation"
|
|
249
|
-
});
|
|
250
|
-
res.sendStatus(500);
|
|
251
|
-
});
|
|
252
|
-
}
|
|
253
|
-
async exportXls(req, res) {
|
|
254
|
-
AcBackgroundJob.createJob({}, {}, (error, jobId) => {
|
|
255
|
-
if (error) {
|
|
256
|
-
console.error("Could not create backgroundJob", {
|
|
257
|
-
err: error,
|
|
258
|
-
context: "start_report_creation",
|
|
259
|
-
});
|
|
260
|
-
res.sendStatus(500);
|
|
261
|
-
}
|
|
262
|
-
else {
|
|
263
|
-
let reportType;
|
|
264
|
-
reportType = "start-aoi-xls-report-generation";
|
|
265
|
-
queue.add("process-reports", {
|
|
266
|
-
type: reportType,
|
|
267
|
-
questionId: req.query.questionId,
|
|
268
|
-
userId: req.user.id,
|
|
269
|
-
exportType: req.params.type,
|
|
270
|
-
fileEnding: req.params.fileEnding ? req.params.fileEnding : "xlsx",
|
|
271
|
-
translateLanguage: req.query.translateLanguage,
|
|
272
|
-
selectedFraudAuditId: req.body.selectedFraudAuditId,
|
|
273
|
-
jobId: jobId,
|
|
274
|
-
communityId: req.params.communityId,
|
|
275
|
-
}, "critical");
|
|
276
|
-
res.send({ jobId });
|
|
277
|
-
}
|
|
278
|
-
});
|
|
279
|
-
}
|
|
280
|
-
async llmAnswerExplain(req, res) {
|
|
281
|
-
const { wsClientId, chatLog, languageName } = req.body;
|
|
282
|
-
console.log(`explainConversation: ${wsClientId}`);
|
|
283
|
-
const explainer = new ExplainAnswersAssistant(wsClientId, this.wsClients, languageName);
|
|
284
|
-
await explainer.explainConversation(chatLog);
|
|
285
|
-
res.sendStatus(200);
|
|
286
|
-
}
|
|
287
|
-
async showEarl(req, res) {
|
|
288
|
-
const { groupId } = req.params;
|
|
289
|
-
const locale = req.query.locale;
|
|
290
|
-
try {
|
|
291
|
-
const group = (await Group.findOne({
|
|
292
|
-
where: {
|
|
293
|
-
id: groupId,
|
|
294
|
-
},
|
|
295
|
-
}));
|
|
296
|
-
const aoiConfig = group.configuration.allOurIdeas;
|
|
297
|
-
if (group && aoiConfig?.earl) {
|
|
298
|
-
const showParams = {
|
|
299
|
-
with_prompt: true,
|
|
300
|
-
with_appearance: true,
|
|
301
|
-
with_visitor_stats: true,
|
|
302
|
-
visitor_identifier: req.session.id,
|
|
303
|
-
};
|
|
304
|
-
const questionResponse = await fetch(`${PAIRWISE_API_HOST}/questions/${aoiConfig.earl.question_id}.json?${new URLSearchParams(showParams).toString()}`, {
|
|
305
|
-
method: "GET",
|
|
306
|
-
headers: defaultHeader,
|
|
307
|
-
});
|
|
308
|
-
if (!questionResponse.ok) {
|
|
309
|
-
throw new Error("Failed to fetch question");
|
|
310
|
-
}
|
|
311
|
-
const question = (await questionResponse.json());
|
|
312
|
-
const { picked_prompt_id } = question;
|
|
313
|
-
const question_id = question.id;
|
|
314
|
-
console.log(`picked_prompt_id: ${picked_prompt_id}`);
|
|
315
|
-
console.log(`question_id: ${question_id}`);
|
|
316
|
-
const promptResponse = await fetch(`${PAIRWISE_API_HOST}/questions/${question_id}/prompts/${picked_prompt_id}.json`, {
|
|
317
|
-
method: "GET",
|
|
318
|
-
headers: defaultHeader,
|
|
319
|
-
});
|
|
320
|
-
if (!promptResponse.ok) {
|
|
321
|
-
throw new Error("Failed to fetch prompt");
|
|
322
|
-
}
|
|
323
|
-
const prompt = await promptResponse.json();
|
|
324
|
-
res.json({
|
|
325
|
-
prompt: prompt,
|
|
326
|
-
question: question,
|
|
327
|
-
});
|
|
328
|
-
}
|
|
329
|
-
else {
|
|
330
|
-
res.status(404).send("Not found");
|
|
331
|
-
}
|
|
332
|
-
}
|
|
333
|
-
catch (error) {
|
|
334
|
-
console.error(error);
|
|
335
|
-
res.status(500).send("An error occurred");
|
|
336
|
-
}
|
|
337
|
-
}
|
|
338
|
-
async vote(req, res) {
|
|
339
|
-
const { id, question_id, direction } = req.body;
|
|
340
|
-
const voteOptions = this.getVoteRequestOptions(req, "vote");
|
|
341
|
-
const nextPromptOptions = this.getNextPromptOptions(req);
|
|
342
|
-
if (direction) {
|
|
343
|
-
try {
|
|
344
|
-
const response = await fetch(`${PAIRWISE_API_HOST}/questions/${req.params.questionId}/prompts/${req.params.promptId}/vote`, {
|
|
345
|
-
method: "PUT",
|
|
346
|
-
headers: defaultHeader,
|
|
347
|
-
body: JSON.stringify({
|
|
348
|
-
question_id,
|
|
349
|
-
vote: voteOptions,
|
|
350
|
-
next_prompt: nextPromptOptions,
|
|
351
|
-
}),
|
|
352
|
-
});
|
|
353
|
-
if (!response.ok)
|
|
354
|
-
throw new Error("Vote unsuccessful.");
|
|
355
|
-
const nextPrompt = (await response.json());
|
|
356
|
-
const result = {
|
|
357
|
-
newleft: nextPrompt.left_choice_text,
|
|
358
|
-
newright: nextPrompt.right_choice_text,
|
|
359
|
-
left_choice_id: nextPrompt.left_choice_id,
|
|
360
|
-
left_choice_url: this.getQuestionChoicePath(question_id, nextPrompt.left_choice_id),
|
|
361
|
-
right_choice_id: nextPrompt.right_choice_id,
|
|
362
|
-
right_choice_url: this.getQuestionChoicePath(question_id, nextPrompt.right_choice_id),
|
|
363
|
-
appearance_lookup: nextPrompt.appearance_id,
|
|
364
|
-
prompt_id: nextPrompt.id,
|
|
365
|
-
};
|
|
366
|
-
res.json(result);
|
|
367
|
-
}
|
|
368
|
-
catch (error) {
|
|
369
|
-
console.error(error);
|
|
370
|
-
res.status(422).send("Vote unsuccessful.");
|
|
371
|
-
}
|
|
372
|
-
}
|
|
373
|
-
else {
|
|
374
|
-
res.status(422).send("Vote unsuccessful.");
|
|
375
|
-
}
|
|
376
|
-
}
|
|
377
|
-
async createQuestion(req, res) {
|
|
378
|
-
const questionParams = req.body;
|
|
379
|
-
console.log(`in createQuestion: ${JSON.stringify(questionParams.ideas)}`);
|
|
380
|
-
if (questionParams.ideas.length < 4) {
|
|
381
|
-
return res.status(400).json({ error: "Invalid input" });
|
|
382
|
-
}
|
|
383
|
-
const requestBody = {
|
|
384
|
-
name: questionParams.question,
|
|
385
|
-
ideas: questionParams.ideas
|
|
386
|
-
.filter((i) => i.length > 3)
|
|
387
|
-
.join("\r\n"),
|
|
388
|
-
url: "noUrl",
|
|
389
|
-
information: "noInformation",
|
|
390
|
-
userId: req.user.id,
|
|
391
|
-
};
|
|
392
|
-
try {
|
|
393
|
-
const response = await fetch(`${PAIRWISE_API_HOST}/questions.json`, {
|
|
394
|
-
method: "POST",
|
|
395
|
-
headers: defaultHeader,
|
|
396
|
-
body: JSON.stringify(requestBody),
|
|
397
|
-
});
|
|
398
|
-
if (!response.ok) {
|
|
399
|
-
throw new Error("Failed to create question");
|
|
400
|
-
}
|
|
401
|
-
const question = (await response.json());
|
|
402
|
-
res.json({ question_id: question.id });
|
|
403
|
-
}
|
|
404
|
-
catch (error) {
|
|
405
|
-
console.error(error);
|
|
406
|
-
res
|
|
407
|
-
.status(500)
|
|
408
|
-
.json({ error: "An error occurred during question creation" });
|
|
409
|
-
}
|
|
410
|
-
}
|
|
411
|
-
async updateCoiceData(req, res) {
|
|
412
|
-
try {
|
|
413
|
-
const response = await fetch(`${PAIRWISE_API_HOST}/questions/${req.params.questionId}/choices/${req.params.choiceId}.json`, {
|
|
414
|
-
method: "PUT",
|
|
415
|
-
headers: defaultHeader,
|
|
416
|
-
body: JSON.stringify({
|
|
417
|
-
data: req.body.data,
|
|
418
|
-
}),
|
|
419
|
-
});
|
|
420
|
-
if (!response.ok)
|
|
421
|
-
throw new Error("Choice update failed.");
|
|
422
|
-
res.status(200).json({ message: "Choice data updated" });
|
|
423
|
-
}
|
|
424
|
-
catch (error) {
|
|
425
|
-
console.error(error);
|
|
426
|
-
res.status(422).json({ error: "Choice update failed" });
|
|
427
|
-
}
|
|
428
|
-
}
|
|
429
|
-
async updateActive(req, res) {
|
|
430
|
-
try {
|
|
431
|
-
const response = await fetch(`${PAIRWISE_API_HOST}/questions/${req.params.questionId}/choices/${req.params.choiceId}.json`, {
|
|
432
|
-
method: "PUT",
|
|
433
|
-
headers: defaultHeader,
|
|
434
|
-
body: JSON.stringify({
|
|
435
|
-
active: req.body.active,
|
|
436
|
-
}),
|
|
437
|
-
});
|
|
438
|
-
if (!response.ok)
|
|
439
|
-
throw new Error("Choice active failed.");
|
|
440
|
-
res.status(200).json({ message: "Choice active updated" });
|
|
441
|
-
}
|
|
442
|
-
catch (error) {
|
|
443
|
-
console.error(error);
|
|
444
|
-
res.status(422).json({ error: "Choice active failed" });
|
|
445
|
-
}
|
|
446
|
-
}
|
|
447
|
-
async updateQuestionName(req, res) {
|
|
448
|
-
try {
|
|
449
|
-
const response = await fetch(`${PAIRWISE_API_HOST}/questions/${req.params.questionId}.json`, {
|
|
450
|
-
method: "PUT",
|
|
451
|
-
headers: defaultHeader,
|
|
452
|
-
body: JSON.stringify({
|
|
453
|
-
name: req.body.name,
|
|
454
|
-
}),
|
|
455
|
-
});
|
|
456
|
-
if (!response.ok)
|
|
457
|
-
throw new Error("Question update name failed.");
|
|
458
|
-
res.status(200).json({ message: "Question name updated" });
|
|
459
|
-
}
|
|
460
|
-
catch (error) {
|
|
461
|
-
console.error(error);
|
|
462
|
-
res.status(422).json({ error: "Question update name failed" });
|
|
463
|
-
}
|
|
464
|
-
}
|
|
465
|
-
async skip(req, res) {
|
|
466
|
-
const { id, question_id } = req.body;
|
|
467
|
-
const skipOptions = this.getVoteRequestOptions(req, "skip");
|
|
468
|
-
const nextPromptOptions = this.getNextPromptOptions(req);
|
|
469
|
-
try {
|
|
470
|
-
const response = await fetch(`${PAIRWISE_API_HOST}/questions/${req.params.questionId}/prompts/${req.params.promptId}/skip.json`, {
|
|
471
|
-
method: "PUT",
|
|
472
|
-
headers: defaultHeader,
|
|
473
|
-
body: JSON.stringify({
|
|
474
|
-
question_id,
|
|
475
|
-
skip: skipOptions,
|
|
476
|
-
next_prompt: nextPromptOptions,
|
|
477
|
-
}),
|
|
478
|
-
});
|
|
479
|
-
if (!response.ok)
|
|
480
|
-
throw new Error("Skip failed.");
|
|
481
|
-
const nextPrompt = (await response.json());
|
|
482
|
-
const result = {
|
|
483
|
-
newleft: nextPrompt.left_choice_text,
|
|
484
|
-
newright: nextPrompt.right_choice_text,
|
|
485
|
-
left_choice_id: nextPrompt.left_choice_id,
|
|
486
|
-
left_choice_url: this.getQuestionChoicePath(question_id, nextPrompt.left_choice_id),
|
|
487
|
-
right_choice_id: nextPrompt.right_choice_id,
|
|
488
|
-
right_choice_url: this.getQuestionChoicePath(question_id, nextPrompt.right_choice_id),
|
|
489
|
-
appearance_lookup: nextPrompt.appearance_id,
|
|
490
|
-
prompt_id: nextPrompt.id,
|
|
491
|
-
};
|
|
492
|
-
res.json(result);
|
|
493
|
-
}
|
|
494
|
-
catch (error) {
|
|
495
|
-
console.error(error);
|
|
496
|
-
res.status(422).json({ error: "Skip failed" });
|
|
497
|
-
}
|
|
498
|
-
}
|
|
499
|
-
async analysis(req, res) {
|
|
500
|
-
const { groupId, wsClientSocketId, analysisIndex, analysisTypeIndex } = req.params;
|
|
501
|
-
console.log(`--------------------> ${groupId} ${analysisIndex} ${analysisTypeIndex}`);
|
|
502
|
-
try {
|
|
503
|
-
const group = await Group.findOne({ where: { id: groupId } });
|
|
504
|
-
if (!group) {
|
|
505
|
-
res.status(404).send("Group not found");
|
|
506
|
-
return;
|
|
507
|
-
}
|
|
508
|
-
const aoiConfig = group.configuration.allOurIdeas;
|
|
509
|
-
if (!aoiConfig?.earl) {
|
|
510
|
-
res.status(404).send("Configuration missing");
|
|
511
|
-
return;
|
|
512
|
-
}
|
|
513
|
-
const questionId = aoiConfig.earl.question_id;
|
|
514
|
-
const showParams = {
|
|
515
|
-
with_prompt: "true",
|
|
516
|
-
with_appearance: "true",
|
|
517
|
-
with_visitor_stats: "true",
|
|
518
|
-
visitor_identifier: req.session.id,
|
|
519
|
-
};
|
|
520
|
-
const questionResponse = await fetch(`${PAIRWISE_API_HOST}/questions/${questionId}.json?${new URLSearchParams(showParams).toString()}`, {
|
|
521
|
-
method: "GET",
|
|
522
|
-
headers: defaultHeader,
|
|
523
|
-
});
|
|
524
|
-
if (!questionResponse.ok) {
|
|
525
|
-
throw new Error("Failed to fetch question for analysis");
|
|
526
|
-
}
|
|
527
|
-
const question = (await questionResponse.json());
|
|
528
|
-
// Additional logic adapted from Ruby for fetching and sorting choices
|
|
529
|
-
console.log(`@question is ${question}. ${group.configuration.allOurIdeas.earl.configuration.analysis_config}`);
|
|
530
|
-
const analysisConfig = group.configuration.allOurIdeas.earl.configuration.analysis_config;
|
|
531
|
-
console.log(`@analysisConfig is ${analysisConfig}.`);
|
|
532
|
-
const analysisIdeaConfig = analysisConfig.analyses[parseInt(analysisIndex)];
|
|
533
|
-
console.log(`@analysisIdeaConfig is ${analysisIdeaConfig}.`);
|
|
534
|
-
const ideasIdsRange = analysisIdeaConfig.ideasIdsRange;
|
|
535
|
-
console.log(`@ideasIdsRange is ${ideasIdsRange}.`);
|
|
536
|
-
const analysisType = analysisIdeaConfig.analysisTypes[parseInt(analysisTypeIndex, 10)];
|
|
537
|
-
console.log(`Analysis Type: ${analysisType}`);
|
|
538
|
-
const perPage = Math.abs(ideasIdsRange);
|
|
539
|
-
console.log(`Per page: ${perPage}`);
|
|
540
|
-
const totalActiveChoices = question.choices_count - question.inactive_choices_count;
|
|
541
|
-
const offset = ideasIdsRange < 0 ? Math.max(totalActiveChoices - perPage, 0) : 0;
|
|
542
|
-
console.log(`Offset: ${offset}`);
|
|
543
|
-
const choicesResponse = await fetch(`${PAIRWISE_API_HOST}/questions/${questionId}/choices.json?all=1&show_all=true&limit=${perPage}&offset=${offset}`, {
|
|
544
|
-
headers: defaultAuthHeader,
|
|
545
|
-
});
|
|
546
|
-
const choices = (await choicesResponse.json());
|
|
547
|
-
for (const choice of choices) {
|
|
548
|
-
try {
|
|
549
|
-
choice.data = JSON.parse(choice.data);
|
|
550
|
-
}
|
|
551
|
-
catch (error) {
|
|
552
|
-
choice.data = {
|
|
553
|
-
content: choice.data,
|
|
554
|
-
choiceId: choice.id,
|
|
555
|
-
};
|
|
556
|
-
console.warn(error);
|
|
557
|
-
}
|
|
558
|
-
}
|
|
559
|
-
console.log(`Number of choices fetched: ${choices.length}`);
|
|
560
|
-
const sortedChoices = choices.sort((a, b) => a.id - b.id);
|
|
561
|
-
console.log(`Sorted choice IDs: ${sortedChoices.map((choice) => choice.id)}`);
|
|
562
|
-
const choiceIds = sortedChoices.map((choice) => `${choice.id}`).join("-");
|
|
563
|
-
const promptHash = crypto
|
|
564
|
-
.createHash("sha256")
|
|
565
|
-
.update(analysisType.contextPrompt)
|
|
566
|
-
.digest("hex")
|
|
567
|
-
.substring(0, 8);
|
|
568
|
-
const usedLanguageName = req.query.languageName || "English";
|
|
569
|
-
const analysisCacheKey = `${questionId}_${analysisTypeIndex}_${choiceIds}_${usedLanguageName}_${promptHash}_ai_analysis_v14`;
|
|
570
|
-
console.log(`analysisCacheKey is ${analysisCacheKey} prompt ${analysisType.contextPrompt.substring(0, 15)}...`);
|
|
571
|
-
// Implement caching logic here
|
|
572
|
-
let cachedAnalysis = await req.redisClient.get(analysisCacheKey);
|
|
573
|
-
if (!cachedAnalysis) {
|
|
574
|
-
const topOrBottomText = ideasIdsRange < 0
|
|
575
|
-
? `Bottom ${perPage} answers`
|
|
576
|
-
: `Top ${perPage} answers`;
|
|
577
|
-
const swClientSocket = this.wsClients.get(wsClientSocketId);
|
|
578
|
-
const aiHelper = new AiHelper(swClientSocket);
|
|
579
|
-
await aiHelper.getAiAnalysis(questionId, analysisType.contextPrompt, choices, analysisCacheKey, req.redisClient, usedLanguageName, topOrBottomText, analysisType.label);
|
|
580
|
-
}
|
|
581
|
-
res.json({
|
|
582
|
-
selectedChoices: choices,
|
|
583
|
-
cachedAnalysis,
|
|
584
|
-
});
|
|
585
|
-
}
|
|
586
|
-
catch (error) {
|
|
587
|
-
console.error(error);
|
|
588
|
-
res
|
|
589
|
-
.status(500)
|
|
590
|
-
.send("An error occurred while processing the analysis request");
|
|
591
|
-
}
|
|
592
|
-
}
|
|
593
|
-
async fetchChoices(questionId, showAll) {
|
|
594
|
-
let url = `${PAIRWISE_API_HOST}/questions/${questionId}/choices.json${showAll ? "?include_inactive=true&show_all=true" : ""}`;
|
|
595
|
-
const response = await fetch(url, {
|
|
596
|
-
headers: defaultAuthHeader,
|
|
597
|
-
});
|
|
598
|
-
if (!response.ok) {
|
|
599
|
-
throw new Error(`Failed to fetch choices: ${response.statusText}`);
|
|
600
|
-
}
|
|
601
|
-
const choices = (await response.json());
|
|
602
|
-
// Process choices as needed
|
|
603
|
-
return choices;
|
|
604
|
-
}
|
|
605
|
-
async getChoices(req, res) {
|
|
606
|
-
try {
|
|
607
|
-
const questionId = req.params.questionId;
|
|
608
|
-
const showAll = req.query.showAll;
|
|
609
|
-
let url = `${PAIRWISE_API_HOST}/questions/${questionId}/choices.json${showAll ? "?include_inactive=true&show_all=true" : ""}`;
|
|
610
|
-
const response = await fetch(url, {
|
|
611
|
-
headers: defaultAuthHeader,
|
|
612
|
-
});
|
|
613
|
-
if (!response.ok) {
|
|
614
|
-
throw new Error(`Failed to fetch choices: ${response.statusText}`);
|
|
615
|
-
}
|
|
616
|
-
const choices = (await response.json());
|
|
617
|
-
for (let choice of choices) {
|
|
618
|
-
try {
|
|
619
|
-
choice.data = JSON.parse(choice.data);
|
|
620
|
-
}
|
|
621
|
-
catch (error) {
|
|
622
|
-
choice.data = {
|
|
623
|
-
content: choice.data,
|
|
624
|
-
choiceId: choice.id,
|
|
625
|
-
};
|
|
626
|
-
console.error(error);
|
|
627
|
-
}
|
|
628
|
-
}
|
|
629
|
-
res.json(choices);
|
|
630
|
-
}
|
|
631
|
-
catch (error) {
|
|
632
|
-
console.error(error);
|
|
633
|
-
res.status(500).send("An error occurred");
|
|
634
|
-
}
|
|
635
|
-
}
|
|
636
|
-
// You need to implement these functions based on your application's logic
|
|
637
|
-
getQuestionChoicePath(questionId, choiceId) {
|
|
638
|
-
// Implement logic to generate choice path
|
|
639
|
-
return `/questions/${questionId}/choices/${choiceId}.json`;
|
|
640
|
-
}
|
|
641
|
-
getNextPromptOptions(req) {
|
|
642
|
-
const nextPromptParams = {
|
|
643
|
-
with_appearance: true,
|
|
644
|
-
with_visitor_stats: true,
|
|
645
|
-
visitor_identifier: req.user
|
|
646
|
-
? req.user.id
|
|
647
|
-
: req.session.id,
|
|
648
|
-
};
|
|
649
|
-
return nextPromptParams;
|
|
650
|
-
}
|
|
651
|
-
getVoteRequestOptions(req, requestType) {
|
|
652
|
-
const session = req.session; // Assuming express-session middleware is used
|
|
653
|
-
const params = req.query;
|
|
654
|
-
const body = req.body; // Assuming body-parser middleware is used for JSON body parsing
|
|
655
|
-
console.log(`getVoteRequestOptions: ${JSON.stringify(params)} s: ${session}`);
|
|
656
|
-
const options = {
|
|
657
|
-
visitor_identifier: req.user
|
|
658
|
-
? req.user.id
|
|
659
|
-
: req.session.id,
|
|
660
|
-
// Use a static value of 5 if in test environment, so we can mock resulting API queries
|
|
661
|
-
time_viewed: process.env.NODE_ENV === "test" ? 5 : body.time_viewed,
|
|
662
|
-
appearance_lookup: body.appearance_lookup,
|
|
663
|
-
};
|
|
664
|
-
const trackingData = {
|
|
665
|
-
user_agent_hash: crypto
|
|
666
|
-
.createHash("sha256")
|
|
667
|
-
.update(req.headers["user-agent"] || "")
|
|
668
|
-
.digest("hex"),
|
|
669
|
-
ip_address: req.ip,
|
|
670
|
-
browser_id: params.checksum_a,
|
|
671
|
-
fp: params.checksum_b,
|
|
672
|
-
fp_confidence: params.checksum_c,
|
|
673
|
-
// Directly include UTM parameters if they exist
|
|
674
|
-
utm_source: params.utm_source,
|
|
675
|
-
utm_medium: params.utm_medium,
|
|
676
|
-
utm_campaign: params.utm_campaign,
|
|
677
|
-
utm_term: params.utm_term,
|
|
678
|
-
utm_content: params.utm_content,
|
|
679
|
-
utm_referrer: params.utm_referrer,
|
|
680
|
-
};
|
|
681
|
-
options.tracking = trackingData;
|
|
682
|
-
console.log(`---------------------- ${JSON.stringify(trackingData)}`);
|
|
683
|
-
switch (requestType) {
|
|
684
|
-
case "vote":
|
|
685
|
-
options.direction = body.direction;
|
|
686
|
-
break;
|
|
687
|
-
case "skip":
|
|
688
|
-
options.skip_reason = body.cant_decide_reason;
|
|
689
|
-
break;
|
|
690
|
-
case "skip_after_flag":
|
|
691
|
-
options.skip_reason = body.flag_reason;
|
|
692
|
-
break;
|
|
693
|
-
}
|
|
694
|
-
return options;
|
|
695
|
-
}
|
|
696
|
-
}
|