@yrpri/api 9.0.116 → 9.0.117
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/controllers/users.cjs +1 -1
- package/models/domain.cjs +1 -0
- package/package.json +2 -2
- package/utils/seedModels.js +29 -17
package/controllers/users.cjs
CHANGED
|
@@ -143,7 +143,7 @@ router.post('/login', function (req, res) {
|
|
|
143
143
|
const startTime = new Date();
|
|
144
144
|
log.info('User Login start', { elapsedTime: (new Date() - startTime), userId: req.user ? req.user.id : null });
|
|
145
145
|
req.sso.authenticate('local-strategy', {}, req, res, function (err, user) {
|
|
146
|
-
log.info(`User Login before get ${req.user ? "HASUSER" : "NOUSER"}`, { elapsedTime: (new Date() - startTime), userId: req.user ? req.user.id : null });
|
|
146
|
+
log.info(`User Login before get ${req.user ? "HASUSER" : "NOUSER"}`, err, { elapsedTime: (new Date() - startTime), userId: req.user ? req.user.id : null });
|
|
147
147
|
getUserWithAll(req.user.id, true, async function (error, user) {
|
|
148
148
|
log.info('User Login completed', { elapsedTime: (new Date() - startTime), userId: req.user ? req.user.id : null });
|
|
149
149
|
if (error || !user) {
|
package/models/domain.cjs
CHANGED
|
@@ -365,6 +365,7 @@ module.exports = (sequelize, DataTypes) => {
|
|
|
365
365
|
req.url.indexOf("/login") > -1 ||
|
|
366
366
|
req.url.indexOf("saml_assertion") > -1) {
|
|
367
367
|
sequelize.models.Domain.getLoginProviders(req, domain, (error, providers) => {
|
|
368
|
+
log.info("Login Providers", { providers });
|
|
368
369
|
req.ypDomain.loginProviders = providers;
|
|
369
370
|
sequelize.models.Domain.getLoginHosts(domain, (error, hosts) => {
|
|
370
371
|
req.ypDomain.loginHosts = hosts;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yrpri/api",
|
|
3
|
-
"version": "9.0.
|
|
3
|
+
"version": "9.0.117",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "Robert Bjarnason & Citizens Foundation",
|
|
6
6
|
"repository": {
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"@google-cloud/vertexai": "^1.10.0",
|
|
26
26
|
"@google-cloud/vision": "^5.1.0",
|
|
27
27
|
"@node-saml/passport-saml": "^5.0.1",
|
|
28
|
-
"@policysynth/agents": "^1.3.
|
|
28
|
+
"@policysynth/agents": "^1.3.95",
|
|
29
29
|
"async": "^3.2.6",
|
|
30
30
|
"authorized": "^1.0.0",
|
|
31
31
|
"aws-sdk": "^2.1692.0",
|
package/utils/seedModels.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import fs from "fs";
|
|
2
2
|
import path from "path";
|
|
3
|
-
import { fileURLToPath, pathToFileURL } from
|
|
4
|
-
import crypto from
|
|
5
|
-
import bcrypt from
|
|
3
|
+
import { fileURLToPath, pathToFileURL } from "url";
|
|
4
|
+
import crypto from "crypto";
|
|
5
|
+
import bcrypt from "bcrypt";
|
|
6
6
|
import { Sequelize, DataTypes, Op } from "sequelize";
|
|
7
7
|
import { sequelize as psSequelize } from "@policysynth/agents/dbModels/index.js";
|
|
8
8
|
const __filename = fileURLToPath(import.meta.url);
|
|
@@ -134,7 +134,7 @@ const mainCompoundIndexCommands = [
|
|
|
134
134
|
'CREATE INDEX groupheaderimage_idx2_group_id_c ON "GroupHeaderImage" (group_id, created_at)',
|
|
135
135
|
'CREATE INDEX grouplogoimage_idx2_group_id_c ON "GroupLogoImage" (group_id, created_at)',
|
|
136
136
|
'CREATE INDEX grouplogovideo_idx2_group_id_c ON "GroupLogoVideo" (group_id, created_at)',
|
|
137
|
-
|
|
137
|
+
"CREATE INDEX idx2_group_categories_name ON Categories (group_id, name)",
|
|
138
138
|
'CREATE INDEX organizationlogoimag_idx_organization_id ON "OrganizationLogoImage" (organization_id)',
|
|
139
139
|
'CREATE INDEX organizationlogoimag_idx_organization_id_u ON "OrganizationLogoImage" (organization_id, updated_at)',
|
|
140
140
|
'CREATE INDEX organizationlogoimag_idx_organization_id_c ON "OrganizationLogoImage" (organization_id, created_at)',
|
|
@@ -145,7 +145,7 @@ const mainCompoundIndexCommands = [
|
|
|
145
145
|
'CREATE INDEX pointvideo_idx2_point_id_u ON "PointVideo" (point_id, updated_at)',
|
|
146
146
|
'CREATE INDEX pointaudio_idx2_point_id_c ON "PointAudio" (point_id, created_at)',
|
|
147
147
|
'CREATE INDEX pointvideo_idx2_point_id_c ON "PointVideo" (point_id, created_at)',
|
|
148
|
-
|
|
148
|
+
"CREATE INDEX points_idx2_counter_sum_post_id_status_value_deleted ON points ((counter_quality_up-counter_quality_down), post_id, status, value, deleted)",
|
|
149
149
|
'CREATE INDEX userprofileimage_idx2_user_id ON "UserProfileImage" (user_id)',
|
|
150
150
|
'CREATE INDEX userprofileimage_idx2_user_id_u ON "UserProfileImage" (user_id, updated_at)',
|
|
151
151
|
'CREATE INDEX userprofileimage_idx2_user_id_c ON "UserProfileImage" (user_id, created_at)',
|
|
@@ -167,8 +167,8 @@ const mainCompoundIndexCommands = [
|
|
|
167
167
|
'CREATE INDEX idx2_post_images_c ON "PostImage" (post_id, created_at)',
|
|
168
168
|
'CREATE INDEX idx2_post_audios_c ON "PostAudio" (post_id, created_at)',
|
|
169
169
|
'CREATE INDEX idx2_post_videos_c ON "PostVideo" (post_id, created_at)',
|
|
170
|
-
|
|
171
|
-
|
|
170
|
+
"CREATE INDEX posts_idx2_counter_sum_group_id_deleted ON posts ((counter_endorsements_up-counter_endorsements_down),group_id,deleted)",
|
|
171
|
+
"CREATE INDEX posts_idx2_counter_sum_group_id_category_id_deleted ON posts ((counter_endorsements_up-counter_endorsements_down),group_id,category_id,deleted)",
|
|
172
172
|
];
|
|
173
173
|
async function createMainCompoundIndexes(sequelizeInstance, indexCommands) {
|
|
174
174
|
for (const command of indexCommands) {
|
|
@@ -190,7 +190,8 @@ async function createMainCompoundIndexes(sequelizeInstance, indexCommands) {
|
|
|
190
190
|
async function syncMainDatabase() {
|
|
191
191
|
console.log("Starting main database synchronization...");
|
|
192
192
|
const modelsPath = path.join(__dirname, "../models");
|
|
193
|
-
const modelFiles = fs
|
|
193
|
+
const modelFiles = fs
|
|
194
|
+
.readdirSync(modelsPath)
|
|
194
195
|
.filter((file) => file.indexOf(".") !== 0 &&
|
|
195
196
|
file.endsWith(".cjs") &&
|
|
196
197
|
!file.endsWith(".d.cjs") &&
|
|
@@ -212,7 +213,8 @@ async function syncMainDatabase() {
|
|
|
212
213
|
}
|
|
213
214
|
const acModelsPath = path.join(__dirname, "../services/models");
|
|
214
215
|
if (fs.existsSync(acModelsPath)) {
|
|
215
|
-
const acModelFiles = fs
|
|
216
|
+
const acModelFiles = fs
|
|
217
|
+
.readdirSync(acModelsPath)
|
|
216
218
|
.filter((file) => file.indexOf(".") !== 0 &&
|
|
217
219
|
file.endsWith(".cjs") &&
|
|
218
220
|
!file.endsWith(".d.cjs") &&
|
|
@@ -236,7 +238,8 @@ async function syncMainDatabase() {
|
|
|
236
238
|
console.warn(`Directory not found, skipping services models: ${acModelsPath}`);
|
|
237
239
|
}
|
|
238
240
|
Object.keys(mainDb).forEach((modelName) => {
|
|
239
|
-
if (mainDb[modelName] &&
|
|
241
|
+
if (mainDb[modelName] &&
|
|
242
|
+
typeof mainDb[modelName].associate === "function") {
|
|
240
243
|
mainDb[modelName].associate(mainDb);
|
|
241
244
|
}
|
|
242
245
|
});
|
|
@@ -326,9 +329,11 @@ async function seedAllModels() {
|
|
|
326
329
|
const newUser = mainDb.User.build({
|
|
327
330
|
email: userEmail,
|
|
328
331
|
name: userName, // Or a dedicated name argument if preferred
|
|
329
|
-
status:
|
|
332
|
+
status: "active",
|
|
330
333
|
// Attempt to set default notifications, fallback if AcNotification not on mainDb
|
|
331
|
-
notifications_settings: mainDb.AcNotification
|
|
334
|
+
notifications_settings: mainDb.AcNotification
|
|
335
|
+
? mainDb.AcNotification.defaultNotificationSettings
|
|
336
|
+
: { email: true },
|
|
332
337
|
});
|
|
333
338
|
// createPasswordHash is an instance method on User model from user.cjs
|
|
334
339
|
const salt = bcrypt.genSaltSync(10);
|
|
@@ -336,31 +341,38 @@ async function seedAllModels() {
|
|
|
336
341
|
await newUser.save();
|
|
337
342
|
console.log(`User ${newUser.email} created with ID: ${newUser.id}`);
|
|
338
343
|
// Create Domain
|
|
339
|
-
const randomDomainName = crypto.randomBytes(8).toString(
|
|
344
|
+
const randomDomainName = crypto.randomBytes(8).toString("hex") + ".seed.local"; // Shorter and identifiable
|
|
340
345
|
console.log(`Attempting to create domain: ${randomDomainName} for user ${newUser.id}`);
|
|
341
346
|
const newDomain = mainDb.Domain.build({
|
|
342
347
|
name: `Default Domain for ${userName}`,
|
|
343
348
|
domain_name: randomDomainName,
|
|
344
|
-
access: mainDb.Domain.ACCESS_PUBLIC !== undefined
|
|
349
|
+
access: mainDb.Domain.ACCESS_PUBLIC !== undefined
|
|
350
|
+
? mainDb.Domain.ACCESS_PUBLIC
|
|
351
|
+
: 0, // Use constant if available
|
|
345
352
|
default_locale: "en",
|
|
346
|
-
ip_address: "::1",
|
|
353
|
+
ip_address: "::1", // Using localhost IP
|
|
347
354
|
user_agent: "seedModelsScript/1.0",
|
|
348
355
|
user_id: newUser.id, // Associate domain with the new user
|
|
349
356
|
configuration: {},
|
|
357
|
+
secret_api_keys: {},
|
|
358
|
+
data: {},
|
|
359
|
+
other_social_media_info: {},
|
|
360
|
+
public_api_keys: {},
|
|
361
|
+
info_texts: {},
|
|
350
362
|
// Fill other required non-nullable fields based on domain.cjs definition if any
|
|
351
363
|
// deleted: false, (already defaults to false)
|
|
352
364
|
});
|
|
353
365
|
await newDomain.save();
|
|
354
366
|
console.log(`Domain ${newDomain.name} created with ID: ${newDomain.id} and domain_name: ${newDomain.domain_name}`);
|
|
355
367
|
// Associate User with Domain
|
|
356
|
-
if (typeof newDomain.addDomainUsers ===
|
|
368
|
+
if (typeof newDomain.addDomainUsers === "function") {
|
|
357
369
|
await newDomain.addDomainUsers(newUser);
|
|
358
370
|
console.log(`User ${newUser.email} added to domain ${newDomain.domain_name} as a user.`);
|
|
359
371
|
}
|
|
360
372
|
else {
|
|
361
373
|
console.warn(`newDomain.addDomainUsers is not a function. Skipping adding user to domain users.`);
|
|
362
374
|
}
|
|
363
|
-
if (typeof newDomain.addDomainAdmins ===
|
|
375
|
+
if (typeof newDomain.addDomainAdmins === "function") {
|
|
364
376
|
await newDomain.addDomainAdmins(newUser);
|
|
365
377
|
console.log(`User ${newUser.email} added to domain ${newDomain.domain_name} as an admin.`);
|
|
366
378
|
}
|