@yrpri/api 9.0.115 → 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.
@@ -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/models/index.cjs CHANGED
@@ -5,6 +5,9 @@ const env = process.env.NODE_ENV || "development";
5
5
  const _ = require("lodash");
6
6
  const { Sequelize, DataTypes } = require("sequelize");
7
7
  let sequelize;
8
+ // -----------------------------------------------------------------------------
9
+ // DB bootstrap
10
+ // -----------------------------------------------------------------------------
8
11
  const Op = Sequelize.Op;
9
12
  const operatorsAliases = {
10
13
  $gt: Op.gt,
@@ -30,25 +33,20 @@ if (process.env.NODE_ENV === "production") {
30
33
  dialect: "postgres",
31
34
  minifyAliases: true,
32
35
  logging: false,
33
- operatorsAliases: operatorsAliases,
36
+ operatorsAliases,
34
37
  });
35
38
  }
36
39
  else {
37
40
  sequelize = new Sequelize(process.env.DATABASE_URL, {
38
41
  dialect: "postgres",
39
- dialectOptions: {
40
- ssl: {
41
- rejectUnauthorized: false,
42
- },
43
- },
42
+ dialectOptions: { ssl: { rejectUnauthorized: false } },
44
43
  minifyAliases: true,
45
44
  logging: false,
46
- operatorsAliases: operatorsAliases,
45
+ operatorsAliases,
47
46
  });
48
47
  }
49
48
  }
50
49
  else {
51
- let config;
52
50
  try {
53
51
  sequelize = new Sequelize(process.env.YP_DEV_DATABASE_NAME, process.env.YP_DEV_DATABASE_USERNAME, process.env.YP_DEV_DATABASE_PASSWORD, {
54
52
  dialect: "postgres",
@@ -56,19 +54,19 @@ else {
56
54
  host: process.env.YP_DEV_DATABASE_HOST,
57
55
  port: process.env.YP_DEV_DATABASE_PORT,
58
56
  minifyAliases: true,
59
- dialectOptions: {
60
- ssl: false,
61
- rejectUnauthorized: false,
62
- },
57
+ dialectOptions: { ssl: false, rejectUnauthorized: false },
63
58
  logging: false,
64
- operatorsAliases: operatorsAliases,
59
+ operatorsAliases,
65
60
  });
66
61
  }
67
62
  catch (error) {
68
- console.error("Error reading or parsing config file:", error);
63
+ console.error("Error configuring Sequelize:", error);
69
64
  process.exit(1);
70
65
  }
71
66
  }
67
+ // -----------------------------------------------------------------------------
68
+ // Model loading
69
+ // -----------------------------------------------------------------------------
72
70
  const db = {};
73
71
  async function createCompoundIndexes(indexCommands) {
74
72
  for (const command of indexCommands) {
@@ -77,8 +75,8 @@ async function createCompoundIndexes(indexCommands) {
77
75
  console.log(`Successfully created index with command: ${command}`);
78
76
  }
79
77
  catch (error) {
80
- if (error.message.indexOf("already exists") > -1) {
81
- //console.log("already exists")
78
+ if (error.message.includes("already exists")) {
79
+ /* ignore duplicate index */
82
80
  }
83
81
  else {
84
82
  console.error(`Error creating index with command: ${command}`);
@@ -148,30 +146,35 @@ const compoundIndexCommands = [
148
146
  `CREATE INDEX posts_idx2_counter_sum_group_id_deleted ON posts ((counter_endorsements_up-counter_endorsements_down),group_id,deleted)`,
149
147
  `CREATE INDEX posts_idx2_counter_sum_group_id_category_id_deleted ON posts ((counter_endorsements_up-counter_endorsements_down),group_id,category_id,deleted)`,
150
148
  ];
151
- // Read models from local folder
149
+ // Load local models (.cjs only)
152
150
  fs.readdirSync(__dirname)
153
- .filter((file) => {
154
- return file.indexOf(".") !== 0 && file.endsWith(".cjs") && !file.endsWith(".d.cjs") && !file.endsWith(".d.cts") && file !== "index.cjs";
155
- })
151
+ .filter((file) => file.indexOf(".") !== 0 &&
152
+ file.endsWith(".cjs") &&
153
+ !file.endsWith(".d.cjs") &&
154
+ !file.endsWith(".d.cts") &&
155
+ file !== "index.cjs")
156
156
  .forEach((file) => {
157
157
  const model = require(path.join(__dirname, file))(sequelize, DataTypes);
158
158
  db[model.name] = model;
159
159
  });
160
- // Read from active citizen,
161
- const acDirname = __dirname + "/../services/models";
160
+ // Load from ActiveCitizen services/models (.cjs only)
161
+ const acDirname = path.join(__dirname, "..", "services", "models");
162
162
  fs.readdirSync(acDirname)
163
- .filter((file) => {
164
- return file.indexOf(".") !== 0 && file.endsWith(".cjs") && !file.endsWith(".d.cjs") && !file.endsWith(".d.cts");
165
- })
163
+ .filter((file) => file.indexOf(".") !== 0 &&
164
+ file.endsWith(".cjs") &&
165
+ !file.endsWith(".d.cjs") &&
166
+ !file.endsWith(".d.cts"))
166
167
  .forEach((file) => {
167
168
  const model = require(path.join(acDirname, file))(sequelize, DataTypes);
168
169
  db[model.name] = model;
169
170
  });
171
+ // Wire up associations
170
172
  Object.keys(db).forEach((modelName) => {
171
173
  if ("associate" in db[modelName]) {
172
174
  db[modelName].associate(db);
173
175
  }
174
176
  });
177
+ // Sync & index creation
175
178
  if (process.env.FORCE_DB_SYNC || process.env.NODE_ENV === "development") {
176
179
  sequelize.sync().then(async () => {
177
180
  await createCompoundIndexes(compoundIndexCommands);
@@ -181,6 +184,7 @@ if (process.env.FORCE_DB_SYNC || process.env.NODE_ENV === "development") {
181
184
  else if (process.env.FORCE_DB_INDEX_SYNC) {
182
185
  createCompoundIndexes(compoundIndexCommands);
183
186
  }
187
+ // Expose
184
188
  db.sequelize = sequelize;
185
189
  db.Sequelize = Sequelize;
186
190
  module.exports = db;
@@ -1,2 +1,46 @@
1
+ import type { Sequelize as SequelizeBaseType, Model, ModelStatic } from "sequelize";
2
+ type ModelInstance<T extends object> = Model<T, Partial<T>> & T;
3
+ type AudioInstance = ModelInstance<YpAudioData>;
4
+ type CategoryInstance = ModelInstance<YpCategoryData>;
5
+ type CommunityInstance = ModelInstance<YpCommunityData>;
6
+ type DomainInstance = ModelInstance<YpDomainData>;
7
+ type EndorsementInstance = ModelInstance<YpEndorsement>;
8
+ type GroupInstance = ModelInstance<YpGroupData>;
9
+ type ImageInstance = ModelInstance<YpImageData>;
10
+ type PageInstance = ModelInstance<YpHelpPageData>;
11
+ type PointInstance = ModelInstance<YpPointData>;
12
+ type PointQualityInstance = ModelInstance<YpPointQuality>;
13
+ type PointRevisionInstance = ModelInstance<YpPointRevision>;
14
+ type PostInstance = ModelInstance<YpPostData>;
15
+ type PostStatusChangeInstance = ModelInstance<YpPostStatusChange>;
16
+ type OrganizationInstance = ModelInstance<YpOrganizationData>;
17
+ type RatingInstance = ModelInstance<YpRatingData>;
18
+ type UserInstance = ModelInstance<YpUserData>;
19
+ type VideoInstance = ModelInstance<YpVideoData>;
20
+ type AcActivityInstance = ModelInstance<AcActivityData>;
21
+ type AcNotificationInstance = ModelInstance<AcNotificationData>;
22
+ interface DeclaredYpModels {
23
+ sequelize: SequelizeBaseType;
24
+ Sequelize: typeof SequelizeBaseType;
25
+ Audio: ModelStatic<AudioInstance>;
26
+ Category: ModelStatic<CategoryInstance>;
27
+ Community: ModelStatic<CommunityInstance>;
28
+ Domain: ModelStatic<DomainInstance>;
29
+ Endorsement: ModelStatic<EndorsementInstance>;
30
+ Group: ModelStatic<GroupInstance>;
31
+ Image: ModelStatic<ImageInstance>;
32
+ Page: ModelStatic<PageInstance>;
33
+ Point: ModelStatic<PointInstance>;
34
+ PointQuality: ModelStatic<PointQualityInstance>;
35
+ PointRevision: ModelStatic<PointRevisionInstance>;
36
+ Post: ModelStatic<PostInstance>;
37
+ PostStatusChange: ModelStatic<PostStatusChangeInstance>;
38
+ Organization: ModelStatic<OrganizationInstance>;
39
+ Rating: ModelStatic<RatingInstance>;
40
+ User: ModelStatic<UserInstance>;
41
+ Video: ModelStatic<VideoInstance>;
42
+ AcActivity: ModelStatic<AcActivityInstance>;
43
+ AcNotification: ModelStatic<AcNotificationInstance>;
44
+ }
45
+ declare const db: DeclaredYpModels;
1
46
  export = db;
2
- declare const db: typeof import("models/index.cjs");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yrpri/api",
3
- "version": "9.0.115",
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.94",
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",
@@ -134,7 +134,8 @@
134
134
  },
135
135
  "scripts": {
136
136
  "copyInLocalAgents": "cp -R ../../policy-synth/agents/ts-out/* ./node_modules/@policysynth/agents/;cp ../../policy-synth/agents/src/*.d.ts ./node_modules/@policysynth/agents/;",
137
- "publish_live": "npm run build:dev;copyfiles './src/utils/**/*.d.ts' './src/controllers/**/*.d.ts' './src/agents/**/*.d.ts' './src/models/**/*.d.ts' './src/services/controllers/**/*.d.ts' './src/services/models/**/*.d.ts' 'ts-out/';npm pack && node repack && node publish.js https://registry.npmjs.org/",
137
+ "publish_live_with_copy": "npm run build:dev;copyfiles './src/utils/**/*.d.ts' './src/controllers/**/*.d.ts' './src/agents/**/*.d.ts' './src/models/**/*.d.ts' './src/services/controllers/**/*.d.ts' './src/services/models/**/*.d.ts' 'ts-out/';npm pack && node repack && node publish.js https://registry.npmjs.org/",
138
+ "publish_live": "npm run build:dev;npm pack && node repack && node publish.js https://registry.npmjs.org/",
138
139
  "publish_local": "npm run build;npm pack && node repack && node publish.js http://localhost:4873",
139
140
  "start": "nodemon -e ts ts-out/server.js",
140
141
  "watch-start": "DEBUG=router:* tsc --project ./src --outDir ./ts-out -w & nodemon -q ./ts-out/server.js",
@@ -1,17 +1,17 @@
1
1
  export function getPointDomainIncludes(id: any): {
2
- model: any;
2
+ model: import("sequelize").ModelStatic<import("sequelize").Model<YpPostData, Partial<YpPostData>> & YpPostData>;
3
3
  required: boolean;
4
4
  attributes: never[];
5
5
  include: {
6
- model: any;
6
+ model: import("sequelize").ModelStatic<import("sequelize").Model<YpGroupData, Partial<YpGroupData>> & YpGroupData>;
7
7
  required: boolean;
8
8
  attributes: never[];
9
9
  include: {
10
- model: any;
10
+ model: import("sequelize").ModelStatic<import("sequelize").Model<YpCommunityData, Partial<YpCommunityData>> & YpCommunityData>;
11
11
  required: boolean;
12
12
  attributes: never[];
13
13
  include: {
14
- model: any;
14
+ model: import("sequelize").ModelStatic<import("sequelize").Model<YpDomainData, Partial<YpDomainData>> & YpDomainData>;
15
15
  where: {
16
16
  id: any;
17
17
  };
@@ -22,15 +22,15 @@ export function getPointDomainIncludes(id: any): {
22
22
  }[];
23
23
  }[];
24
24
  export function getDomainIncludes(id: any): {
25
- model: any;
25
+ model: import("sequelize").ModelStatic<import("sequelize").Model<YpGroupData, Partial<YpGroupData>> & YpGroupData>;
26
26
  required: boolean;
27
27
  attributes: never[];
28
28
  include: {
29
- model: any;
29
+ model: import("sequelize").ModelStatic<import("sequelize").Model<YpCommunityData, Partial<YpCommunityData>> & YpCommunityData>;
30
30
  required: boolean;
31
31
  attributes: never[];
32
32
  include: {
33
- model: any;
33
+ model: import("sequelize").ModelStatic<import("sequelize").Model<YpDomainData, Partial<YpDomainData>> & YpDomainData>;
34
34
  where: {
35
35
  id: any;
36
36
  };
@@ -40,15 +40,15 @@ export function getDomainIncludes(id: any): {
40
40
  }[];
41
41
  }[];
42
42
  export function getPointCommunityIncludes(id: any): {
43
- model: any;
43
+ model: import("sequelize").ModelStatic<import("sequelize").Model<YpPostData, Partial<YpPostData>> & YpPostData>;
44
44
  required: boolean;
45
45
  attributes: never[];
46
46
  include: {
47
- model: any;
47
+ model: import("sequelize").ModelStatic<import("sequelize").Model<YpGroupData, Partial<YpGroupData>> & YpGroupData>;
48
48
  required: boolean;
49
49
  attributes: never[];
50
50
  include: {
51
- model: any;
51
+ model: import("sequelize").ModelStatic<import("sequelize").Model<YpCommunityData, Partial<YpCommunityData>> & YpCommunityData>;
52
52
  where: {
53
53
  id: any;
54
54
  };
@@ -58,11 +58,11 @@ export function getPointCommunityIncludes(id: any): {
58
58
  }[];
59
59
  }[];
60
60
  export function getCommunityIncludes(id: any): {
61
- model: any;
61
+ model: import("sequelize").ModelStatic<import("sequelize").Model<YpGroupData, Partial<YpGroupData>> & YpGroupData>;
62
62
  required: boolean;
63
63
  attributes: never[];
64
64
  include: {
65
- model: any;
65
+ model: import("sequelize").ModelStatic<import("sequelize").Model<YpCommunityData, Partial<YpCommunityData>> & YpCommunityData>;
66
66
  where: {
67
67
  id: any;
68
68
  };
@@ -71,11 +71,11 @@ export function getCommunityIncludes(id: any): {
71
71
  }[];
72
72
  }[];
73
73
  export function getPointGroupIncludes(id: any): {
74
- model: any;
74
+ model: import("sequelize").ModelStatic<import("sequelize").Model<YpPostData, Partial<YpPostData>> & YpPostData>;
75
75
  required: boolean;
76
76
  attributes: never[];
77
77
  include: {
78
- model: any;
78
+ model: import("sequelize").ModelStatic<import("sequelize").Model<YpGroupData, Partial<YpGroupData>> & YpGroupData>;
79
79
  required: boolean;
80
80
  where: {
81
81
  id: any;
@@ -84,7 +84,7 @@ export function getPointGroupIncludes(id: any): {
84
84
  }[];
85
85
  }[];
86
86
  export function getGroupIncludes(id: any): {
87
- model: any;
87
+ model: import("sequelize").ModelStatic<import("sequelize").Model<YpGroupData, Partial<YpGroupData>> & YpGroupData>;
88
88
  required: boolean;
89
89
  where: {
90
90
  id: any;
@@ -1,13 +1,13 @@
1
1
  export function domainIncludes(domainId: any): {
2
- model: any;
2
+ model: import("sequelize").ModelStatic<import("sequelize").Model<YpGroupData, Partial<YpGroupData>> & YpGroupData>;
3
3
  required: boolean;
4
4
  attributes: string[];
5
5
  include: {
6
- model: any;
6
+ model: import("sequelize").ModelStatic<import("sequelize").Model<YpCommunityData, Partial<YpCommunityData>> & YpCommunityData>;
7
7
  required: boolean;
8
8
  attributes: string[];
9
9
  include: {
10
- model: any;
10
+ model: import("sequelize").ModelStatic<import("sequelize").Model<YpDomainData, Partial<YpDomainData>> & YpDomainData>;
11
11
  attributes: string[];
12
12
  where: {
13
13
  id: any;
@@ -17,11 +17,11 @@ export function domainIncludes(domainId: any): {
17
17
  }[];
18
18
  }[];
19
19
  export function communityIncludes(communityId: any): {
20
- model: any;
20
+ model: import("sequelize").ModelStatic<import("sequelize").Model<YpGroupData, Partial<YpGroupData>> & YpGroupData>;
21
21
  required: boolean;
22
22
  attributes: string[];
23
23
  include: {
24
- model: any;
24
+ model: import("sequelize").ModelStatic<import("sequelize").Model<YpCommunityData, Partial<YpCommunityData>> & YpCommunityData>;
25
25
  required: boolean;
26
26
  attributes: string[];
27
27
  where: {
@@ -30,7 +30,7 @@ export function communityIncludes(communityId: any): {
30
30
  }[];
31
31
  }[];
32
32
  export function groupIncludes(groupId: any): {
33
- model: any;
33
+ model: import("sequelize").ModelStatic<import("sequelize").Model<YpGroupData, Partial<YpGroupData>> & YpGroupData>;
34
34
  required: boolean;
35
35
  attributes: string[];
36
36
  where: {
@@ -38,7 +38,7 @@ export function groupIncludes(groupId: any): {
38
38
  };
39
39
  }[];
40
40
  export function userIncludes(userId: any): {
41
- model: any;
41
+ model: import("sequelize").ModelStatic<import("sequelize").Model<YpUserData, Partial<YpUserData>> & YpUserData>;
42
42
  attributes: any;
43
43
  required: boolean;
44
44
  where: {
@@ -1,11 +1,22 @@
1
1
  export function activitiesDefaultIncludes(options: any): ({
2
- model: any;
2
+ model: import("sequelize").ModelStatic<import("sequelize").Model<YpUserData, Partial<YpUserData>> & YpUserData>;
3
3
  required: boolean;
4
4
  attributes: any;
5
+ include: {
6
+ model: import("sequelize").ModelStatic<import("sequelize").Model<YpImageData, Partial<YpImageData>> & YpImageData>;
7
+ as: string;
8
+ attributes: any;
9
+ required: boolean;
10
+ }[];
5
11
  where?: undefined;
12
+ } | {
13
+ model: import("sequelize").ModelStatic<import("sequelize").Model<YpDomainData, Partial<YpDomainData>> & YpDomainData>;
14
+ required: boolean;
15
+ attributes: any;
6
16
  include?: undefined;
17
+ where?: undefined;
7
18
  } | {
8
- model: any;
19
+ model: import("sequelize").ModelStatic<import("sequelize").Model<YpCommunityData, Partial<YpCommunityData>> & YpCommunityData>;
9
20
  required: boolean;
10
21
  attributes: any;
11
22
  where: {
@@ -14,7 +25,13 @@ export function activitiesDefaultIncludes(options: any): ({
14
25
  };
15
26
  include?: undefined;
16
27
  } | {
17
- model: any;
28
+ model: import("sequelize").ModelStatic<import("sequelize").Model<YpCommunityData, Partial<YpCommunityData>> & YpCommunityData>;
29
+ attributes: any;
30
+ required: boolean;
31
+ include?: undefined;
32
+ where?: undefined;
33
+ } | {
34
+ model: import("sequelize").ModelStatic<import("sequelize").Model<YpGroupData, Partial<YpGroupData>> & YpGroupData>;
18
35
  required: boolean;
19
36
  attributes: any;
20
37
  where: {
@@ -24,32 +41,55 @@ export function activitiesDefaultIncludes(options: any): ({
24
41
  access?: undefined;
25
42
  };
26
43
  include: {
27
- model: any;
44
+ model: import("sequelize").ModelStatic<import("sequelize").Model<YpImageData, Partial<YpImageData>> & YpImageData>;
28
45
  as: string;
29
46
  attributes: any;
30
47
  required: boolean;
31
48
  }[];
32
49
  } | {
33
- model: any;
50
+ model: import("sequelize").ModelStatic<import("sequelize").Model<YpGroupData, Partial<YpGroupData>> & YpGroupData>;
51
+ required: boolean;
52
+ attributes: any;
53
+ include: {
54
+ model: import("sequelize").ModelStatic<import("sequelize").Model<YpImageData, Partial<YpImageData>> & YpImageData>;
55
+ as: string;
56
+ attributes: any;
57
+ required: boolean;
58
+ }[];
59
+ where?: undefined;
60
+ } | {
61
+ model: import("sequelize").ModelStatic<import("sequelize").Model<YpPostData, Partial<YpPostData>> & YpPostData>;
34
62
  required: boolean;
35
63
  attributes: any;
36
64
  include: ({
37
- model: any;
65
+ model: import("sequelize").ModelStatic<import("sequelize").Model<YpGroupData, Partial<YpGroupData>> & YpGroupData>;
38
66
  required: boolean;
39
67
  attributes: string[];
40
68
  as?: undefined;
41
69
  include?: undefined;
42
70
  } | {
43
- model: any;
71
+ model: import("sequelize").ModelStatic<import("sequelize").Model<YpUserData, Partial<YpUserData>> & YpUserData>;
72
+ attributes: string[];
73
+ required: boolean;
74
+ as?: undefined;
75
+ include?: undefined;
76
+ } | {
77
+ model: import("sequelize").ModelStatic<import("sequelize").Model<YpImageData, Partial<YpImageData>> & YpImageData>;
44
78
  as: string;
45
79
  attributes: any;
46
80
  required: boolean;
47
81
  include?: undefined;
48
82
  } | {
49
- model: any;
83
+ model: import("sequelize").ModelStatic<import("sequelize").Model<YpAudioData, Partial<YpAudioData>> & YpAudioData>;
84
+ required: boolean;
85
+ attributes: string[];
86
+ as: string;
87
+ include?: undefined;
88
+ } | {
89
+ model: import("sequelize").ModelStatic<import("sequelize").Model<YpCategoryData, Partial<YpCategoryData>> & YpCategoryData>;
50
90
  required: boolean;
51
91
  include: {
52
- model: any;
92
+ model: import("sequelize").ModelStatic<import("sequelize").Model<YpImageData, Partial<YpImageData>> & YpImageData>;
53
93
  attributes: any;
54
94
  required: boolean;
55
95
  as: string;
@@ -59,33 +99,45 @@ export function activitiesDefaultIncludes(options: any): ({
59
99
  })[];
60
100
  where?: undefined;
61
101
  } | {
62
- model: any;
102
+ model: import("sequelize").ModelStatic<import("sequelize").Model<YpPointData, Partial<YpPointData>> & YpPointData>;
63
103
  required: boolean;
64
104
  attributes: any[];
65
105
  include: ({
66
- model: any;
106
+ model: import("sequelize").ModelStatic<import("sequelize").Model<YpPointRevision, Partial<YpPointRevision>> & YpPointRevision>;
67
107
  attributes: any;
68
108
  include: {
69
- model: any;
109
+ model: import("sequelize").ModelStatic<import("sequelize").Model<YpUserData, Partial<YpUserData>> & YpUserData>;
70
110
  attributes: any;
71
111
  required: boolean;
72
112
  }[];
73
113
  required: boolean;
74
114
  as?: undefined;
75
115
  } | {
76
- model: any;
116
+ model: import("sequelize").ModelStatic<import("sequelize").Model<YpAudioData, Partial<YpAudioData>> & YpAudioData>;
77
117
  required: boolean;
78
118
  attributes: string[];
79
119
  as: string;
80
120
  include?: undefined;
81
121
  } | {
82
- model: any;
122
+ model: import("sequelize").ModelStatic<import("sequelize").Model<YpPostData, Partial<YpPostData>> & YpPostData>;
123
+ attributes: string[];
124
+ required: boolean;
125
+ include?: undefined;
126
+ as?: undefined;
127
+ } | {
128
+ model: import("sequelize").ModelStatic<import("sequelize").Model<YpUserData, Partial<YpUserData>> & YpUserData>;
83
129
  attributes: string[];
84
130
  required: boolean;
85
131
  include?: undefined;
86
132
  as?: undefined;
87
133
  })[];
88
134
  where?: undefined;
135
+ } | {
136
+ model: import("sequelize").ModelStatic<import("sequelize").Model<YpPostStatusChange, Partial<YpPostStatusChange>> & YpPostStatusChange>;
137
+ attributes: any;
138
+ required: boolean;
139
+ include?: undefined;
140
+ where?: undefined;
89
141
  })[];
90
142
  export function getCommonWhereOptions(options: any): {
91
143
  status: string;
@@ -1,8 +1,8 @@
1
1
  import fs from "fs";
2
2
  import path from "path";
3
- import { fileURLToPath, pathToFileURL } from 'url';
4
- import crypto from 'crypto';
5
- import bcrypt from 'bcrypt';
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
- 'CREATE INDEX idx2_group_categories_name ON Categories (group_id, name)',
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
- 'CREATE INDEX points_idx2_counter_sum_post_id_status_value_deleted ON points ((counter_quality_up-counter_quality_down), post_id, status, value, deleted)',
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
- '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)',
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.readdirSync(modelsPath)
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.readdirSync(acModelsPath)
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] && typeof mainDb[modelName].associate === "function") {
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: 'active',
332
+ status: "active",
330
333
  // Attempt to set default notifications, fallback if AcNotification not on mainDb
331
- notifications_settings: mainDb.AcNotification ? mainDb.AcNotification.defaultNotificationSettings : { email: true },
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('hex') + ".seed.local"; // Shorter and identifiable
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 ? mainDb.Domain.ACCESS_PUBLIC : 0, // Use constant if available
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 === 'function') {
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 === 'function') {
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
  }