@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,750 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
const { Translate } = require("@google-cloud/translate").v2;
|
|
3
|
-
const farmhash = require("farmhash");
|
|
4
|
-
const log = require("../utils/logger.cjs");
|
|
5
|
-
const PAIRWISE_API_HOST = process.env.PAIRWISE_API_HOST;
|
|
6
|
-
const PAIRWISE_USERNAME = process.env.PAIRWISE_USERNAME;
|
|
7
|
-
const PAIRWISE_PASSWORD = process.env.PAIRWISE_PASSWORD;
|
|
8
|
-
const HAS_LLM = process.env.OPENAI_API_KEY;
|
|
9
|
-
const defaultAuthHeader = {
|
|
10
|
-
"Content-Type": "application/json",
|
|
11
|
-
Authorization: `Basic ${Buffer.from(`${PAIRWISE_USERNAME}:${PAIRWISE_PASSWORD}`).toString("base64")}`,
|
|
12
|
-
};
|
|
13
|
-
const defaultHeader = {
|
|
14
|
-
...{ "Content-Type": "application/json" },
|
|
15
|
-
...defaultAuthHeader,
|
|
16
|
-
};
|
|
17
|
-
module.exports = (sequelize, DataTypes) => {
|
|
18
|
-
let AcTranslationCache = sequelize.define("AcTranslationCache", {
|
|
19
|
-
index_key: { type: DataTypes.STRING, allowNull: false },
|
|
20
|
-
content: { type: DataTypes.TEXT, allowNull: false },
|
|
21
|
-
}, {
|
|
22
|
-
indexes: [
|
|
23
|
-
{
|
|
24
|
-
name: "main_index",
|
|
25
|
-
fields: ["index_key"],
|
|
26
|
-
},
|
|
27
|
-
],
|
|
28
|
-
underscored: true,
|
|
29
|
-
timestamps: true,
|
|
30
|
-
createdAt: "created_at",
|
|
31
|
-
updatedAt: "updated_at",
|
|
32
|
-
tableName: "translation_cache",
|
|
33
|
-
});
|
|
34
|
-
AcTranslationCache.translationModelName = "gpt-4o";
|
|
35
|
-
AcTranslationCache.translationMaxTokens = 2048;
|
|
36
|
-
AcTranslationCache.translationTemperature = 0.7;
|
|
37
|
-
AcTranslationCache.allowedTextTypesForSettingLanguage = [
|
|
38
|
-
"pointContent",
|
|
39
|
-
"postName",
|
|
40
|
-
"postContent",
|
|
41
|
-
"groupName",
|
|
42
|
-
"groupContent",
|
|
43
|
-
"communityName",
|
|
44
|
-
"communityContent",
|
|
45
|
-
"domainName",
|
|
46
|
-
"domainContent",
|
|
47
|
-
"domainWelcomeHtml",
|
|
48
|
-
"statusChangeContent",
|
|
49
|
-
"aoiChoiceContent",
|
|
50
|
-
"aoiQuestionName",
|
|
51
|
-
];
|
|
52
|
-
AcTranslationCache.getContentToTranslate = async (req, modelInstance) => {
|
|
53
|
-
try {
|
|
54
|
-
if (req.query.textType == "aoiChoiceContent") {
|
|
55
|
-
const choiceResponse = await fetch(`${PAIRWISE_API_HOST}/choices/${req.params.extraId}.json?question_id=${req.params.questionId}`, {
|
|
56
|
-
method: "GET",
|
|
57
|
-
headers: defaultHeader,
|
|
58
|
-
});
|
|
59
|
-
if (!choiceResponse.ok) {
|
|
60
|
-
console.error("Failed to fetch answers");
|
|
61
|
-
return null;
|
|
62
|
-
}
|
|
63
|
-
const choice = await choiceResponse.json();
|
|
64
|
-
if (choice) {
|
|
65
|
-
try {
|
|
66
|
-
const data = JSON.parse(choice.data);
|
|
67
|
-
return data["content"];
|
|
68
|
-
}
|
|
69
|
-
catch (error) {
|
|
70
|
-
console.error("Failed to parse choice data", error);
|
|
71
|
-
return null;
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
else {
|
|
75
|
-
return "No translation";
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
else if (req.query.textType == "aoiQuestionName") {
|
|
79
|
-
const questionResponse = await fetch(`${PAIRWISE_API_HOST}/questions/${req.params.extraId}.json`, {
|
|
80
|
-
method: "GET",
|
|
81
|
-
headers: defaultHeader,
|
|
82
|
-
});
|
|
83
|
-
if (!questionResponse.ok) {
|
|
84
|
-
console.error("Failed to fetch question");
|
|
85
|
-
return null;
|
|
86
|
-
}
|
|
87
|
-
const question = await questionResponse.json();
|
|
88
|
-
if (question) {
|
|
89
|
-
return question.name;
|
|
90
|
-
}
|
|
91
|
-
else {
|
|
92
|
-
return null;
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
else {
|
|
96
|
-
switch (req.query.textType) {
|
|
97
|
-
case "postName":
|
|
98
|
-
case "domainName":
|
|
99
|
-
case "communityName":
|
|
100
|
-
case "groupName":
|
|
101
|
-
return modelInstance.name;
|
|
102
|
-
case "postContent":
|
|
103
|
-
case "domainContent":
|
|
104
|
-
case "communityContent":
|
|
105
|
-
return modelInstance.description;
|
|
106
|
-
case "pointContent":
|
|
107
|
-
return modelInstance.PointRevisions[modelInstance.PointRevisions.length - 1].content;
|
|
108
|
-
case "statusChangeContent":
|
|
109
|
-
return modelInstance.content;
|
|
110
|
-
case "groupContent":
|
|
111
|
-
return modelInstance.objectives;
|
|
112
|
-
case "pointAdminCommentContent":
|
|
113
|
-
if (modelInstance.public_data &&
|
|
114
|
-
modelInstance.public_data.admin_comment &&
|
|
115
|
-
modelInstance.public_data.admin_comment.text) {
|
|
116
|
-
return modelInstance.public_data.admin_comment.text;
|
|
117
|
-
}
|
|
118
|
-
else {
|
|
119
|
-
return "No translation";
|
|
120
|
-
}
|
|
121
|
-
case "postTags":
|
|
122
|
-
if (modelInstance.public_data && modelInstance.public_data.tags) {
|
|
123
|
-
return modelInstance.public_data.tags;
|
|
124
|
-
}
|
|
125
|
-
else {
|
|
126
|
-
return "No translation";
|
|
127
|
-
}
|
|
128
|
-
case "customRatingName":
|
|
129
|
-
if (modelInstance.Group.configuration.customRatings &&
|
|
130
|
-
modelInstance.Group.configuration.customRatings[modelInstance.custom_rating_index]) {
|
|
131
|
-
return modelInstance.Group.configuration.customRatings[modelInstance.custom_rating_index].name;
|
|
132
|
-
}
|
|
133
|
-
else {
|
|
134
|
-
return "No translation";
|
|
135
|
-
}
|
|
136
|
-
case "aoiWelcomeMessage":
|
|
137
|
-
return modelInstance.configuration.allOurIdeas.earl.configuration.welcome_message;
|
|
138
|
-
case "aoiWelcomeHtml":
|
|
139
|
-
return modelInstance.configuration.allOurIdeas.earl.configuration.welcome_html;
|
|
140
|
-
case "domainWelcomeHtml":
|
|
141
|
-
return modelInstance.configuration.welcomeHtmlInsteadOfCommunitiesList.replace("<AOI_SITE_STATS>", "");
|
|
142
|
-
case "alternativeTextForNewIdeaButton":
|
|
143
|
-
return modelInstance.configuration.alternativeTextForNewIdeaButton;
|
|
144
|
-
case "alternativeTextForNewIdeaButtonClosed":
|
|
145
|
-
return modelInstance.configuration
|
|
146
|
-
.alternativeTextForNewIdeaButtonClosed;
|
|
147
|
-
case "alternativeTextForNewIdeaButtonHeader":
|
|
148
|
-
return modelInstance.configuration
|
|
149
|
-
.alternativeTextForNewIdeaButtonHeader;
|
|
150
|
-
case "alternativeTextForNewIdeaSaveButton":
|
|
151
|
-
return modelInstance.configuration
|
|
152
|
-
.alternativeTextForNewIdeaSaveButton;
|
|
153
|
-
case "customCategoryQuestionText":
|
|
154
|
-
return modelInstance.configuration.customCategoryQuestionText;
|
|
155
|
-
case "urlToReviewActionText":
|
|
156
|
-
return modelInstance.configuration.urlToReviewActionText;
|
|
157
|
-
case "customThankYouTextNewPosts":
|
|
158
|
-
return modelInstance.configuration.customThankYouTextNewPosts;
|
|
159
|
-
case "customTitleQuestionText":
|
|
160
|
-
return modelInstance.configuration.customTitleQuestionText;
|
|
161
|
-
case "customFilterText":
|
|
162
|
-
return modelInstance.configuration.customFilterText;
|
|
163
|
-
case "customAdminCommentsTitle":
|
|
164
|
-
return modelInstance.configuration.customAdminCommentsTitle;
|
|
165
|
-
case "alternativePointForHeader":
|
|
166
|
-
return modelInstance.configuration.alternativePointForHeader;
|
|
167
|
-
case "customTabTitleNewLocation":
|
|
168
|
-
return modelInstance.configuration.customTabTitleNewLocation;
|
|
169
|
-
case "alternativePointAgainstHeader":
|
|
170
|
-
return modelInstance.configuration.alternativePointAgainstHeader;
|
|
171
|
-
case "alternativePointForLabel":
|
|
172
|
-
return modelInstance.configuration.alternativePointForLabel;
|
|
173
|
-
case "alternativePointAgainstLabel":
|
|
174
|
-
return modelInstance.configuration.alternativePointAgainstLabel;
|
|
175
|
-
case "categoryName":
|
|
176
|
-
return modelInstance.name;
|
|
177
|
-
case "postTranscriptContent":
|
|
178
|
-
return modelInstance.public_data &&
|
|
179
|
-
modelInstance.public_data.transcript
|
|
180
|
-
? modelInstance.public_data.transcript.text
|
|
181
|
-
: null;
|
|
182
|
-
default:
|
|
183
|
-
console.error("No valid textType for translation");
|
|
184
|
-
return null;
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
catch (error) {
|
|
189
|
-
console.error("Failed to get content to translate", error);
|
|
190
|
-
return null;
|
|
191
|
-
}
|
|
192
|
-
};
|
|
193
|
-
// Post Edit
|
|
194
|
-
// When AutoTranslate event ask for all the strings from the StructuredQuestions
|
|
195
|
-
// Replace the StructuredQuestions with translates, store original value and redraw
|
|
196
|
-
// When AutoTranslate stops reinstate the original structured questions
|
|
197
|
-
// In Post
|
|
198
|
-
// When AutoTranslate ask for all the strings for StructuredAnswers & Questions
|
|
199
|
-
// Recreate structure and redraw
|
|
200
|
-
// When AutoTranslate stops
|
|
201
|
-
// Same in XLS and DOCX exports
|
|
202
|
-
AcTranslationCache.getSurveyAnswerTranslations = async (postId, targetLanguage, done) => {
|
|
203
|
-
targetLanguage = AcTranslationCache.fixUpLanguage(targetLanguage);
|
|
204
|
-
sequelize.models.Post.unscoped()
|
|
205
|
-
.findOne({
|
|
206
|
-
where: {
|
|
207
|
-
id: postId,
|
|
208
|
-
},
|
|
209
|
-
attributes: ["id", "public_data", "language"],
|
|
210
|
-
})
|
|
211
|
-
.then(async (post) => {
|
|
212
|
-
if (post.public_data &&
|
|
213
|
-
post.public_data.structuredAnswersJson &&
|
|
214
|
-
post.public_data.structuredAnswersJson.length > 0) {
|
|
215
|
-
const textStrings = [];
|
|
216
|
-
let combinedText = "";
|
|
217
|
-
for (const answer of post.public_data.structuredAnswersJson) {
|
|
218
|
-
if (answer.value !== undefined && answer.value !== null) {
|
|
219
|
-
const safeValue = typeof answer.value === "string" ? answer.value : String(answer.value);
|
|
220
|
-
textStrings.push(safeValue);
|
|
221
|
-
combinedText += safeValue;
|
|
222
|
-
}
|
|
223
|
-
else {
|
|
224
|
-
textStrings.push("");
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
const contentHash = farmhash.hash32(combinedText).toString();
|
|
228
|
-
let indexKey = `PostAnswer-${post.id}-${targetLanguage}-${contentHash}`;
|
|
229
|
-
AcTranslationCache.getSurveyTranslations(indexKey, textStrings, targetLanguage, post, done);
|
|
230
|
-
}
|
|
231
|
-
else {
|
|
232
|
-
done(null, []);
|
|
233
|
-
}
|
|
234
|
-
})
|
|
235
|
-
.catch((error) => {
|
|
236
|
-
done(error);
|
|
237
|
-
});
|
|
238
|
-
};
|
|
239
|
-
AcTranslationCache.addSubOptionsElements = (textStrings, combinedText, subOptions) => {
|
|
240
|
-
for (let i = 0; i < subOptions.length; i++) {
|
|
241
|
-
const text = subOptions[i].text;
|
|
242
|
-
if (text) {
|
|
243
|
-
textStrings.push(text);
|
|
244
|
-
combinedText += text;
|
|
245
|
-
}
|
|
246
|
-
else {
|
|
247
|
-
textStrings.push("");
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
return combinedText;
|
|
251
|
-
};
|
|
252
|
-
AcTranslationCache.addSubOptionsToTranslationStrings = (textStrings, combinedText, question) => {
|
|
253
|
-
if (question.radioButtons && question.radioButtons.length > 0) {
|
|
254
|
-
return AcTranslationCache.addSubOptionsElements(textStrings, combinedText, question.radioButtons);
|
|
255
|
-
}
|
|
256
|
-
else if (question.checkboxes && question.checkboxes.length > 0) {
|
|
257
|
-
return AcTranslationCache.addSubOptionsElements(textStrings, combinedText, question.checkboxes);
|
|
258
|
-
}
|
|
259
|
-
else if (question.dropdownOptions &&
|
|
260
|
-
question.dropdownOptions.length > 0) {
|
|
261
|
-
return AcTranslationCache.addSubOptionsElements(textStrings, combinedText, question.dropdownOptions);
|
|
262
|
-
}
|
|
263
|
-
};
|
|
264
|
-
//TODO: Reduce amount of duplicate code
|
|
265
|
-
AcTranslationCache.getRegistrationQuestionTranslations = async (groupId, targetLanguage, done) => {
|
|
266
|
-
targetLanguage = AcTranslationCache.fixUpLanguage(targetLanguage);
|
|
267
|
-
sequelize.models.Group.findOne({
|
|
268
|
-
where: {
|
|
269
|
-
id: groupId,
|
|
270
|
-
},
|
|
271
|
-
attributes: ["id", "configuration"],
|
|
272
|
-
})
|
|
273
|
-
.then(async (group) => {
|
|
274
|
-
if (group.configuration &&
|
|
275
|
-
group.configuration.registrationQuestionsJson &&
|
|
276
|
-
group.configuration.registrationQuestionsJson.length > 0) {
|
|
277
|
-
const textStrings = [];
|
|
278
|
-
let combinedText = "";
|
|
279
|
-
for (const question of group.configuration
|
|
280
|
-
.registrationQuestionsJson) {
|
|
281
|
-
if (question.text) {
|
|
282
|
-
textStrings.push(question.text);
|
|
283
|
-
combinedText += question.text;
|
|
284
|
-
}
|
|
285
|
-
else {
|
|
286
|
-
textStrings.push("");
|
|
287
|
-
}
|
|
288
|
-
if (question.type === "radios" ||
|
|
289
|
-
question.type === "checkboxes" ||
|
|
290
|
-
question.type === "dropdown") {
|
|
291
|
-
combinedText =
|
|
292
|
-
AcTranslationCache.addSubOptionsToTranslationStrings(textStrings, combinedText, question);
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
const contentHash = farmhash.hash32(combinedText).toString();
|
|
296
|
-
let indexKey = `GroupRegQuestions-${group.id}-${targetLanguage}-${contentHash}`;
|
|
297
|
-
AcTranslationCache.getSurveyTranslations(indexKey, textStrings, targetLanguage, null, done);
|
|
298
|
-
}
|
|
299
|
-
else {
|
|
300
|
-
done(null, []);
|
|
301
|
-
}
|
|
302
|
-
})
|
|
303
|
-
.catch((error) => {
|
|
304
|
-
done(error);
|
|
305
|
-
});
|
|
306
|
-
};
|
|
307
|
-
AcTranslationCache.getSurveyQuestionTranslations = async (groupId, targetLanguage, done) => {
|
|
308
|
-
targetLanguage = AcTranslationCache.fixUpLanguage(targetLanguage);
|
|
309
|
-
sequelize.models.Group.findOne({
|
|
310
|
-
where: {
|
|
311
|
-
id: groupId,
|
|
312
|
-
},
|
|
313
|
-
attributes: ["id", "configuration"],
|
|
314
|
-
})
|
|
315
|
-
.then(async (group) => {
|
|
316
|
-
if (group.configuration &&
|
|
317
|
-
group.configuration.structuredQuestionsJson &&
|
|
318
|
-
group.configuration.structuredQuestionsJson.length > 0) {
|
|
319
|
-
const textStrings = [];
|
|
320
|
-
let combinedText = "";
|
|
321
|
-
for (const question of group.configuration.structuredQuestionsJson) {
|
|
322
|
-
if (question.text) {
|
|
323
|
-
textStrings.push(question.text);
|
|
324
|
-
combinedText += question.text;
|
|
325
|
-
}
|
|
326
|
-
else {
|
|
327
|
-
textStrings.push("");
|
|
328
|
-
}
|
|
329
|
-
if (question.type === "radios" ||
|
|
330
|
-
question.type === "checkboxes" ||
|
|
331
|
-
question.type === "dropdown") {
|
|
332
|
-
combinedText =
|
|
333
|
-
AcTranslationCache.addSubOptionsToTranslationStrings(textStrings, combinedText, question);
|
|
334
|
-
}
|
|
335
|
-
}
|
|
336
|
-
const contentHash = farmhash.hash32(combinedText).toString();
|
|
337
|
-
let indexKey = `GroupQuestions-${group.id}-${targetLanguage}-${contentHash}`;
|
|
338
|
-
AcTranslationCache.getSurveyTranslations(indexKey, textStrings, targetLanguage, null, done);
|
|
339
|
-
}
|
|
340
|
-
else {
|
|
341
|
-
done(null, []);
|
|
342
|
-
}
|
|
343
|
-
})
|
|
344
|
-
.catch((error) => {
|
|
345
|
-
done(error);
|
|
346
|
-
});
|
|
347
|
-
};
|
|
348
|
-
AcTranslationCache.getSurveyTranslations = (indexKey, textStrings, targetLanguage, saveLanguageToModel, done) => {
|
|
349
|
-
sequelize.models.AcTranslationCache.findOne({
|
|
350
|
-
where: {
|
|
351
|
-
index_key: indexKey,
|
|
352
|
-
},
|
|
353
|
-
})
|
|
354
|
-
.then(async (translationModel) => {
|
|
355
|
-
if (translationModel) {
|
|
356
|
-
done(null, JSON.parse(translationModel.content));
|
|
357
|
-
}
|
|
358
|
-
else {
|
|
359
|
-
try {
|
|
360
|
-
const results = await AcTranslationCache.getSurveyTranslationsFromGoogle(textStrings, targetLanguage);
|
|
361
|
-
const translatedStrings = results[0];
|
|
362
|
-
const languageInfo = results[1];
|
|
363
|
-
if (translatedStrings && translatedStrings.length > 0) {
|
|
364
|
-
const content = JSON.stringify(translatedStrings);
|
|
365
|
-
sequelize.models.AcTranslationCache.create({
|
|
366
|
-
index_key: indexKey,
|
|
367
|
-
content: content,
|
|
368
|
-
})
|
|
369
|
-
.then((model) => {
|
|
370
|
-
if (saveLanguageToModel &&
|
|
371
|
-
languageInfo.data &&
|
|
372
|
-
languageInfo.data.translations &&
|
|
373
|
-
languageInfo.data.translations.length > 0) {
|
|
374
|
-
saveLanguageToModel
|
|
375
|
-
.update({
|
|
376
|
-
language: languageInfo.data.translations[0]
|
|
377
|
-
.detectedSourceLanguage,
|
|
378
|
-
})
|
|
379
|
-
.then(() => {
|
|
380
|
-
done(null, translatedStrings);
|
|
381
|
-
})
|
|
382
|
-
.catch((error) => {
|
|
383
|
-
done(error);
|
|
384
|
-
});
|
|
385
|
-
}
|
|
386
|
-
else {
|
|
387
|
-
done(null, translatedStrings);
|
|
388
|
-
}
|
|
389
|
-
})
|
|
390
|
-
.catch((error) => {
|
|
391
|
-
done(error);
|
|
392
|
-
});
|
|
393
|
-
}
|
|
394
|
-
else {
|
|
395
|
-
done(null, []);
|
|
396
|
-
}
|
|
397
|
-
}
|
|
398
|
-
catch (error) {
|
|
399
|
-
done(error);
|
|
400
|
-
}
|
|
401
|
-
}
|
|
402
|
-
})
|
|
403
|
-
.catch((error) => {
|
|
404
|
-
done(error);
|
|
405
|
-
});
|
|
406
|
-
};
|
|
407
|
-
AcTranslationCache.getSurveyTranslationsFromGoogle = async (textsToTranslate, targetLanguage) => {
|
|
408
|
-
return new Promise(async (resolve, reject) => {
|
|
409
|
-
if (!AcTranslationCache.ypLanguages) {
|
|
410
|
-
const { YpLanguages } = await import("../../utils/ypLanguages.js");
|
|
411
|
-
AcTranslationCache.ypLanguages = YpLanguages;
|
|
412
|
-
}
|
|
413
|
-
if (HAS_LLM &&
|
|
414
|
-
AcTranslationCache.ypLanguages.isoCodesNotInGoogleTranslate.includes(targetLanguage)) {
|
|
415
|
-
return await AcTranslationCache.getSurveyTranslationsFromLlmFallback(textsToTranslate, targetLanguage);
|
|
416
|
-
}
|
|
417
|
-
else {
|
|
418
|
-
if (!process.env.GOOGLE_APPLICATION_CREDENTIALS_JSON) {
|
|
419
|
-
reject("No google credentials found");
|
|
420
|
-
}
|
|
421
|
-
else {
|
|
422
|
-
const translateAPI = new Translate({
|
|
423
|
-
credentials: JSON.parse(process.env.GOOGLE_APPLICATION_CREDENTIALS_JSON),
|
|
424
|
-
projectId: process.env.GOOGLE_TRANSLATE_PROJECT_ID
|
|
425
|
-
? process.env.GOOGLE_TRANSLATE_PROJECT_ID
|
|
426
|
-
: undefined,
|
|
427
|
-
});
|
|
428
|
-
try {
|
|
429
|
-
// Split the texts into chunks of 128 or fewer
|
|
430
|
-
const chunkSize = 128;
|
|
431
|
-
const translatedStrings = [];
|
|
432
|
-
let languageInfo = {};
|
|
433
|
-
for (let i = 0; i < textsToTranslate.length; i += chunkSize) {
|
|
434
|
-
const chunk = textsToTranslate.slice(i, i + chunkSize);
|
|
435
|
-
console.log("Calling Google Translate...");
|
|
436
|
-
const [translatedChunk, info] = await translateAPI.translate(chunk, targetLanguage);
|
|
437
|
-
translatedStrings.push(...translatedChunk);
|
|
438
|
-
if (i === 0) {
|
|
439
|
-
// Keep the language info from the first chunk
|
|
440
|
-
languageInfo = info;
|
|
441
|
-
}
|
|
442
|
-
}
|
|
443
|
-
resolve([translatedStrings, languageInfo]);
|
|
444
|
-
}
|
|
445
|
-
catch (error) {
|
|
446
|
-
reject(error);
|
|
447
|
-
}
|
|
448
|
-
}
|
|
449
|
-
}
|
|
450
|
-
});
|
|
451
|
-
};
|
|
452
|
-
AcTranslationCache.getTranslationFromGoogle = async (textType, indexKey, contentToTranslate, targetLanguage, modelInstance, callback) => {
|
|
453
|
-
if (!AcTranslationCache.ypLanguages) {
|
|
454
|
-
const { YpLanguages } = await import("../../utils/ypLanguages.js");
|
|
455
|
-
AcTranslationCache.ypLanguages = YpLanguages;
|
|
456
|
-
}
|
|
457
|
-
if (HAS_LLM &&
|
|
458
|
-
AcTranslationCache.ypLanguages.isoCodesNotInGoogleTranslate.includes(targetLanguage)) {
|
|
459
|
-
AcTranslationCache.llmGoogleTranslateFallback(textType, indexKey, contentToTranslate, targetLanguage, modelInstance, callback);
|
|
460
|
-
}
|
|
461
|
-
else {
|
|
462
|
-
let translateAPI;
|
|
463
|
-
try {
|
|
464
|
-
translateAPI = new Translate({
|
|
465
|
-
credentials: JSON.parse(process.env.GOOGLE_APPLICATION_CREDENTIALS_JSON),
|
|
466
|
-
projectId: process.env.GOOGLE_TRANSLATE_PROJECT_ID
|
|
467
|
-
? process.env.GOOGLE_TRANSLATE_PROJECT_ID
|
|
468
|
-
: undefined,
|
|
469
|
-
});
|
|
470
|
-
}
|
|
471
|
-
catch (error) {
|
|
472
|
-
console.error("Failed to get translation from Google", error);
|
|
473
|
-
}
|
|
474
|
-
if (!translateAPI) {
|
|
475
|
-
callback("No translation API");
|
|
476
|
-
return;
|
|
477
|
-
}
|
|
478
|
-
console.log("Calling Google Translate...");
|
|
479
|
-
translateAPI
|
|
480
|
-
.translate(contentToTranslate, targetLanguage)
|
|
481
|
-
.then((results) => {
|
|
482
|
-
const translationResults = results[1];
|
|
483
|
-
if (translationResults &&
|
|
484
|
-
translationResults.data &&
|
|
485
|
-
translationResults.data.translations &&
|
|
486
|
-
translationResults.data.translations.length > 0) {
|
|
487
|
-
const translation = translationResults.data.translations[0];
|
|
488
|
-
sequelize.models.AcTranslationCache.create({
|
|
489
|
-
index_key: indexKey,
|
|
490
|
-
content: translation.translatedText,
|
|
491
|
-
})
|
|
492
|
-
.then(() => {
|
|
493
|
-
if (textType === "postTranscriptContent" ||
|
|
494
|
-
textType === "pointAdminCommentContent") {
|
|
495
|
-
if (textType === "postTranscriptContent") {
|
|
496
|
-
modelInstance.set("public_data.transcript.language", translation.detectedSourceLanguage);
|
|
497
|
-
}
|
|
498
|
-
else {
|
|
499
|
-
modelInstance.set("public_data.admin_comment.language", translation.detectedSourceLanguage);
|
|
500
|
-
}
|
|
501
|
-
modelInstance
|
|
502
|
-
.save()
|
|
503
|
-
.then(() => {
|
|
504
|
-
callback(null, { content: translation.translatedText });
|
|
505
|
-
})
|
|
506
|
-
.catch((error) => {
|
|
507
|
-
callback(error);
|
|
508
|
-
});
|
|
509
|
-
}
|
|
510
|
-
else {
|
|
511
|
-
if (AcTranslationCache.allowedTextTypesForSettingLanguage.indexOf(textType) > -1) {
|
|
512
|
-
modelInstance
|
|
513
|
-
.update({
|
|
514
|
-
language: translation.detectedSourceLanguage,
|
|
515
|
-
})
|
|
516
|
-
.then(() => {
|
|
517
|
-
callback(null, { content: translation.translatedText });
|
|
518
|
-
})
|
|
519
|
-
.catch((error) => {
|
|
520
|
-
callback(error);
|
|
521
|
-
});
|
|
522
|
-
}
|
|
523
|
-
else {
|
|
524
|
-
callback(null, { content: translation.translatedText });
|
|
525
|
-
}
|
|
526
|
-
}
|
|
527
|
-
})
|
|
528
|
-
.catch((error) => {
|
|
529
|
-
callback(error);
|
|
530
|
-
});
|
|
531
|
-
}
|
|
532
|
-
else {
|
|
533
|
-
callback("No translations");
|
|
534
|
-
}
|
|
535
|
-
})
|
|
536
|
-
.catch((error) => {
|
|
537
|
-
callback(error);
|
|
538
|
-
});
|
|
539
|
-
}
|
|
540
|
-
};
|
|
541
|
-
AcTranslationCache.getSurveyTranslationsFromLlmFallback = async (textsToTranslate, targetLanguage) => {
|
|
542
|
-
return new Promise(async (resolve, reject) => {
|
|
543
|
-
if (!AcTranslationCache.llmTranslation) {
|
|
544
|
-
const { YpLlmTranslation } = await import("../llms/llmTranslation.js");
|
|
545
|
-
AcTranslationCache.llmTranslation = new YpLlmTranslation();
|
|
546
|
-
}
|
|
547
|
-
try {
|
|
548
|
-
const translatedStrings = await AcTranslationCache.llmTranslation.getListTranslation(targetLanguage, textsToTranslate);
|
|
549
|
-
if (translatedStrings) {
|
|
550
|
-
const languageInfo = { detectedSourceLanguage: targetLanguage };
|
|
551
|
-
resolve([translatedStrings, languageInfo]);
|
|
552
|
-
}
|
|
553
|
-
else {
|
|
554
|
-
reject("No translations");
|
|
555
|
-
}
|
|
556
|
-
}
|
|
557
|
-
catch (error) {
|
|
558
|
-
reject(error);
|
|
559
|
-
}
|
|
560
|
-
});
|
|
561
|
-
};
|
|
562
|
-
AcTranslationCache.llmGoogleTranslateFallback = async (textType, indexKey, contentToTranslate, targetLanguage, modelInstance, callback) => {
|
|
563
|
-
if (!AcTranslationCache.llmTranslation) {
|
|
564
|
-
const { YpLlmTranslation } = await import("../llms/llmTranslation.js");
|
|
565
|
-
AcTranslationCache.llmTranslation = new YpLlmTranslation();
|
|
566
|
-
}
|
|
567
|
-
try {
|
|
568
|
-
// Adjusted to use getGeneralQuestion for translation
|
|
569
|
-
const translatedTextData = await AcTranslationCache.llmTranslation.getOneTranslation(targetLanguage, contentToTranslate);
|
|
570
|
-
if (!translatedTextData) {
|
|
571
|
-
callback("No translations");
|
|
572
|
-
return;
|
|
573
|
-
}
|
|
574
|
-
else {
|
|
575
|
-
// Assuming sequelize is available in this scope for database interaction
|
|
576
|
-
sequelize.models.AcTranslationCache.create({
|
|
577
|
-
index_key: indexKey,
|
|
578
|
-
content: translatedTextData,
|
|
579
|
-
})
|
|
580
|
-
.then(() => {
|
|
581
|
-
// Handling textType-specific logic similar to other methods
|
|
582
|
-
if (textType === "postTranscriptContent" ||
|
|
583
|
-
textType === "pointAdminCommentContent") {
|
|
584
|
-
// Presuming a need to set language details based on detected language
|
|
585
|
-
// Since getGeneralQuestion might not return detectedSourceLanguage,
|
|
586
|
-
// you might need to adjust this logic accordingly
|
|
587
|
-
modelInstance.set(textType === "postTranscriptContent"
|
|
588
|
-
? "public_data.transcript.language"
|
|
589
|
-
: "public_data.admin_comment.language", targetLanguage // As a fallback, using targetLanguage directly
|
|
590
|
-
);
|
|
591
|
-
modelInstance
|
|
592
|
-
.save()
|
|
593
|
-
.then(() => {
|
|
594
|
-
callback(null, { content: translatedTextData });
|
|
595
|
-
})
|
|
596
|
-
.catch((error) => {
|
|
597
|
-
callback(error);
|
|
598
|
-
});
|
|
599
|
-
}
|
|
600
|
-
else {
|
|
601
|
-
if (AcTranslationCache.allowedTextTypesForSettingLanguage.indexOf(textType) > -1) {
|
|
602
|
-
modelInstance
|
|
603
|
-
.update({
|
|
604
|
-
language: targetLanguage, // Again, using targetLanguage as a fallback
|
|
605
|
-
})
|
|
606
|
-
.then(() => {
|
|
607
|
-
callback(null, { content: translatedTextData });
|
|
608
|
-
})
|
|
609
|
-
.catch((error) => {
|
|
610
|
-
callback(error);
|
|
611
|
-
});
|
|
612
|
-
}
|
|
613
|
-
else {
|
|
614
|
-
callback(null, { content: translatedTextData });
|
|
615
|
-
}
|
|
616
|
-
}
|
|
617
|
-
})
|
|
618
|
-
.catch((error) => {
|
|
619
|
-
callback(error);
|
|
620
|
-
});
|
|
621
|
-
}
|
|
622
|
-
}
|
|
623
|
-
catch (error) {
|
|
624
|
-
console.error("Failed to translate with LLM", error);
|
|
625
|
-
callback(error);
|
|
626
|
-
}
|
|
627
|
-
};
|
|
628
|
-
AcTranslationCache.getAoiTranslationFromLlm = async (textType, indexKey, contentToTranslate, targetLanguage, modelInstance, callback) => {
|
|
629
|
-
if (!HAS_LLM) {
|
|
630
|
-
callback("No LLM to translate with");
|
|
631
|
-
return;
|
|
632
|
-
}
|
|
633
|
-
console.log(`contentToTranslate ${contentToTranslate}`);
|
|
634
|
-
if (!AcTranslationCache.llmTranslation) {
|
|
635
|
-
const { YpLlmTranslation } = await import("../llms/llmTranslation.js");
|
|
636
|
-
AcTranslationCache.llmTranslation = new YpLlmTranslation();
|
|
637
|
-
}
|
|
638
|
-
const getTranslationData = async () => {
|
|
639
|
-
switch (textType) {
|
|
640
|
-
case "aoiChoiceContent":
|
|
641
|
-
return await AcTranslationCache.llmTranslation.getChoiceTranslation(targetLanguage, contentToTranslate);
|
|
642
|
-
case "aoiQuestionName":
|
|
643
|
-
return await AcTranslationCache.llmTranslation.getQuestionTranslation(targetLanguage, contentToTranslate);
|
|
644
|
-
case "aoiWelcomeHtml":
|
|
645
|
-
case "domainWelcomeHtml":
|
|
646
|
-
return await AcTranslationCache.llmTranslation.getHtmlTranslation(targetLanguage, contentToTranslate);
|
|
647
|
-
case "aoiWelcomeMessage":
|
|
648
|
-
return await AcTranslationCache.llmTranslation.getOneTranslation(targetLanguage, contentToTranslate);
|
|
649
|
-
default:
|
|
650
|
-
return null;
|
|
651
|
-
}
|
|
652
|
-
};
|
|
653
|
-
const translatedTextData = await getTranslationData();
|
|
654
|
-
if (!translatedTextData) {
|
|
655
|
-
callback("No translations");
|
|
656
|
-
return;
|
|
657
|
-
}
|
|
658
|
-
sequelize.models.AcTranslationCache.create({
|
|
659
|
-
index_key: indexKey,
|
|
660
|
-
content: translatedTextData,
|
|
661
|
-
})
|
|
662
|
-
.then(() => {
|
|
663
|
-
callback(null, { content: translatedTextData });
|
|
664
|
-
})
|
|
665
|
-
.catch((error) => {
|
|
666
|
-
callback(error);
|
|
667
|
-
});
|
|
668
|
-
};
|
|
669
|
-
AcTranslationCache.fixUpLanguage = (targetLanguage) => {
|
|
670
|
-
targetLanguage = targetLanguage.replace("_", "-");
|
|
671
|
-
if (targetLanguage !== "sr-latin" &&
|
|
672
|
-
targetLanguage !== "zh-CN" &&
|
|
673
|
-
targetLanguage !== "zh-TW") {
|
|
674
|
-
targetLanguage = targetLanguage.split("-")[0];
|
|
675
|
-
}
|
|
676
|
-
if (targetLanguage === "sr-latin") {
|
|
677
|
-
targetLanguage = "sr-Latn";
|
|
678
|
-
}
|
|
679
|
-
return targetLanguage;
|
|
680
|
-
};
|
|
681
|
-
AcTranslationCache.getTranslation = async (req, modelInstance, callback) => {
|
|
682
|
-
const contentToTranslate = await sequelize.models.AcTranslationCache.getContentToTranslate(req, modelInstance);
|
|
683
|
-
if (contentToTranslate &&
|
|
684
|
-
contentToTranslate !== "" &&
|
|
685
|
-
contentToTranslate.length > 1 &&
|
|
686
|
-
isNaN(contentToTranslate)) {
|
|
687
|
-
const contentHash = farmhash.hash32(contentToTranslate).toString();
|
|
688
|
-
const textType = req.query.textType;
|
|
689
|
-
let targetLanguage = req.query.targetLanguage;
|
|
690
|
-
targetLanguage = AcTranslationCache.fixUpLanguage(targetLanguage);
|
|
691
|
-
let indexKey = `${textType}-${modelInstance.id}-${targetLanguage}-${contentHash}`;
|
|
692
|
-
sequelize.models.AcTranslationCache.findOne({
|
|
693
|
-
where: {
|
|
694
|
-
index_key: indexKey,
|
|
695
|
-
},
|
|
696
|
-
})
|
|
697
|
-
.then((translationModel) => {
|
|
698
|
-
if (translationModel) {
|
|
699
|
-
callback(null, { content: translationModel.content });
|
|
700
|
-
}
|
|
701
|
-
else {
|
|
702
|
-
if ([
|
|
703
|
-
"aoiChoiceContent",
|
|
704
|
-
"aoiQuestionName",
|
|
705
|
-
"aoiWelcomeHtml",
|
|
706
|
-
"domainWelcomeHtml",
|
|
707
|
-
"aoiWelcomeMessage",
|
|
708
|
-
].includes(textType)) {
|
|
709
|
-
sequelize.models.AcTranslationCache.getAoiTranslationFromLlm(textType, indexKey, contentToTranslate, targetLanguage, modelInstance, callback);
|
|
710
|
-
}
|
|
711
|
-
else {
|
|
712
|
-
sequelize.models.AcTranslationCache.getTranslationFromGoogle(textType, indexKey, contentToTranslate, targetLanguage, modelInstance, callback);
|
|
713
|
-
}
|
|
714
|
-
}
|
|
715
|
-
})
|
|
716
|
-
.catch((error) => {
|
|
717
|
-
callback(error);
|
|
718
|
-
});
|
|
719
|
-
}
|
|
720
|
-
else {
|
|
721
|
-
log.warn("Empty or short string for translation", {
|
|
722
|
-
textType: req.query.textType,
|
|
723
|
-
targetLanguage: req.query.targetLanguage,
|
|
724
|
-
});
|
|
725
|
-
if (!modelInstance.language &&
|
|
726
|
-
![
|
|
727
|
-
"aoiChoiceContent",
|
|
728
|
-
"aoiQuestionName",
|
|
729
|
-
"aoiWelcomeHtml",
|
|
730
|
-
"domainWelcomeHtml",
|
|
731
|
-
"aoiWelcomeMessage",
|
|
732
|
-
].includes(req.query.textType)) {
|
|
733
|
-
modelInstance
|
|
734
|
-
.update({
|
|
735
|
-
language: "??",
|
|
736
|
-
})
|
|
737
|
-
.then(() => {
|
|
738
|
-
callback(null, { content: contentToTranslate });
|
|
739
|
-
})
|
|
740
|
-
.catch((error) => {
|
|
741
|
-
callback(error);
|
|
742
|
-
});
|
|
743
|
-
}
|
|
744
|
-
else {
|
|
745
|
-
callback();
|
|
746
|
-
}
|
|
747
|
-
}
|
|
748
|
-
};
|
|
749
|
-
return AcTranslationCache;
|
|
750
|
-
};
|