@yrpri/api 9.0.77 → 9.0.78

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.
@@ -172,6 +172,9 @@ NotificationDeliveryWorker.prototype.process = function (notificationJson, callb
172
172
  else if (notification.AcActivities[0].community_id) {
173
173
  inviteFromName = notification.AcActivities[0].Community.name;
174
174
  }
175
+ if (process.env.DEFAULT_HOSTNAME) {
176
+ community.hostname = process.env.DEFAULT_HOSTNAME;
177
+ }
175
178
  queue.add('send-one-email', {
176
179
  subject: { translateToken: 'notification.email.user_invite', contentName: inviteFromName },
177
180
  template: 'user_invite',
@@ -1,4 +1,6 @@
1
1
  import express from "express";
2
+ import { marked } from "marked";
3
+ import HTMLtoDOCX from "html-to-docx";
2
4
  import auth from "../../authorization.cjs";
3
5
  import { YpAgentAssistant } from "../assistants/agentAssistant.js";
4
6
  import { YpAgentProductBundle } from "../models/agentProductBundle.js";
@@ -11,6 +13,7 @@ import { YpSubscriptionUser } from "../models/subscriptionUser.js";
11
13
  import { YpDiscount } from "../models/discount.js";
12
14
  import { sequelize } from "@policysynth/agents/dbModels/index.js";
13
15
  import { NotificationAgentQueueManager } from "../managers/notificationAgentQueueManager.js";
16
+ import { AgentQueueManager } from "@policysynth/agents/operations/agentQueueManager.js";
14
17
  const models = {
15
18
  YpAgentProduct,
16
19
  YpAgentProductBundle,
@@ -44,6 +47,35 @@ export class AssistantController {
44
47
  process.exit(1);
45
48
  }
46
49
  };
50
+ this.getDocxReport = async (req, res) => {
51
+ try {
52
+ const { agentId } = req.params;
53
+ let lastStatusMessage = await this.getLastStatusMessageFromDB(parseInt(agentId));
54
+ if (!lastStatusMessage) {
55
+ return res.status(404).send("No status message found.");
56
+ }
57
+ const regex = /<markdownReport>([\s\S]*?)<\/markdownReport>/i;
58
+ const match = lastStatusMessage.match(regex);
59
+ console.debug(`match: ${JSON.stringify(match, null, 2)}`);
60
+ if (!match || match.length < 2) {
61
+ console.error("No <markdownReport>...</markdownReport> content found.");
62
+ return res
63
+ .status(400)
64
+ .send("No <markdownReport>...</markdownReport> content found.");
65
+ }
66
+ const markdownContent = match[1];
67
+ const htmlContent = await marked(markdownContent);
68
+ const docxBuffer = await HTMLtoDOCX(htmlContent);
69
+ console.debug(`docxBuffer: ${docxBuffer.length}`);
70
+ res.setHeader("Content-Type", "application/vnd.openxmlformats-officedocument.wordprocessingml.document");
71
+ res.setHeader("Content-disposition", 'attachment; filename="converted.docx"');
72
+ return res.send(docxBuffer);
73
+ }
74
+ catch (error) {
75
+ console.error("Error converting Markdown to DOCX:", error);
76
+ return res.status(500).send("Server error");
77
+ }
78
+ };
47
79
  this.advanceOrStopCurrentWorkflowStep = async (req, res) => {
48
80
  const { groupId, agentId, runId } = req.params;
49
81
  const { status, wsClientId } = req.body;
@@ -271,6 +303,7 @@ export class AssistantController {
271
303
  }
272
304
  };
273
305
  this.wsClients = wsClients;
306
+ this.agentQueueManager = new AgentQueueManager();
274
307
  this.initializeRoutes();
275
308
  this.initializeModels();
276
309
  }
@@ -286,6 +319,11 @@ export class AssistantController {
286
319
  this.router.post("/:groupId/:agentId/startNextWorkflowStep", this.startNextWorkflowStep.bind(this));
287
320
  this.router.post("/:groupId/:agentId/stopCurrentWorkflowStep", this.stopCurrentWorkflowStep.bind(this));
288
321
  this.router.put("/:groupId/:agentId/:runId/advanceOrStopWorkflow", this.advanceOrStopCurrentWorkflowStep.bind(this));
322
+ this.router.get("/:groupId/:agentId/getDocxReport", auth.can("view domain"), this.getDocxReport.bind(this));
323
+ }
324
+ async getLastStatusMessageFromDB(agentId) {
325
+ const status = await this.agentQueueManager.getAgentStatus(agentId);
326
+ return status ? status.messages[status.messages.length - 1] : null;
289
327
  }
290
328
  async startVoiceSession(req, res) {
291
329
  try {
@@ -267,6 +267,9 @@ export class SubscriptionManager {
267
267
  if (step.agentClassUuid && agentUuidMap.has(step.agentClassUuid)) {
268
268
  newStep.agentId = agentUuidMap.get(step.agentClassUuid);
269
269
  }
270
+ else if (step.agentClassUuid) {
271
+ console.error("agentClassUuid not found in agentUuidMap", step.agentClassUuid);
272
+ }
270
273
  if (newStep.type === "engagmentFromInputConnector" && newStep.agentId) {
271
274
  newStep.groupId = agentInputConnectorGroupsIds.get(newStep.agentId);
272
275
  }
package/app.js CHANGED
@@ -203,11 +203,11 @@ export class YourPrioritiesApi {
203
203
  this.handleShortenedRedirects();
204
204
  this.initializeRateLimiting();
205
205
  this.setupDomainAndCommunity();
206
- this.setupStaticFileServing();
207
206
  this.setupSitemapRoute();
208
207
  this.initializePassportStrategies();
209
- this.checkAuthForSsoInit();
210
208
  this.addInviteAsAnonMiddleWare();
209
+ this.setupStaticFileServing();
210
+ this.checkAuthForSsoInit();
211
211
  this.initializeRoutes();
212
212
  this.initializeEsControllers();
213
213
  }
@@ -221,11 +221,11 @@ export class YourPrioritiesApi {
221
221
  this.handleShortenedRedirects();
222
222
  this.initializeRateLimiting();
223
223
  this.setupDomainAndCommunity();
224
- this.setupStaticFileServing();
225
224
  this.setupSitemapRoute();
226
225
  this.initializePassportStrategies();
227
- this.checkAuthForSsoInit();
228
226
  this.addInviteAsAnonMiddleWare();
227
+ this.setupStaticFileServing();
228
+ this.checkAuthForSsoInit();
229
229
  this.initializeRoutes();
230
230
  this.initializeEsControllers();
231
231
  }
@@ -327,7 +327,7 @@ export class YourPrioritiesApi {
327
327
  notifications_settings: models.AcNotification
328
328
  .anonymousNotificationSettings,
329
329
  status: "active",
330
- //TODO: Having this block security for the cloned groups, find a better solution
330
+ //TODO: Having this blocks security for the cloned groups, find a better solution
331
331
  //profile_data: { isAnonymousUser: true },
332
332
  });
333
333
  }
@@ -348,9 +348,15 @@ export class YourPrioritiesApi {
348
348
  // Mark invite as used
349
349
  invite.joined_at = new Date();
350
350
  await invite.save();
351
+ console.log("Invite joined at", invite.joined_at);
351
352
  await new Promise((resolve, reject) => {
352
353
  req.logIn(user, (error) => (error ? reject(error) : resolve()));
353
354
  });
355
+ console.log("User logged in for anon invite");
356
+ return next();
357
+ }
358
+ else {
359
+ console.error("Invite not found");
354
360
  return next();
355
361
  }
356
362
  }
@@ -1013,7 +1013,7 @@ router.post("/:groupId/sendEmailInvitesForAnons", auth.can("edit group"), async
1013
1013
  community_id: group.community_id,
1014
1014
  from_user_id: req.user.id,
1015
1015
  });
1016
- const invite_link = `/group/${group.id}?anonInvite=1&token=${token}`;
1016
+ const invite_link = `/group/${group.id}?anonInvite=1&token=${token}&forAgentBundle=1`;
1017
1017
  const createActivityPromise = new Promise((resolve, reject) => {
1018
1018
  models.AcActivity.inviteCreated({
1019
1019
  email: email,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yrpri/api",
3
- "version": "9.0.77",
3
+ "version": "9.0.78",
4
4
  "license": "MIT",
5
5
  "author": "Robert Bjarnason & Citizens Foundation",
6
6
  "repository": {
@@ -51,6 +51,7 @@
51
51
  "express-session": "git+https://github.com/rbjarnason/session.git#upgrade-21",
52
52
  "express-useragent": "^1.0.13",
53
53
  "farmhash": "3.3.1",
54
+ "html-to-docx": "^1.8.0",
54
55
  "i18next": "^23.12.2",
55
56
  "i18next-node-fs-backend": "^2.1.3",
56
57
  "image-size": "^1.0.2",
@@ -60,6 +61,7 @@
60
61
  "jsonrepair": "^3.5.0",
61
62
  "knuth-shuffle-seeded": "^1.0.6",
62
63
  "lodash": "^4.17.15",
64
+ "marked": "^15.0.4",
63
65
  "moment": "^2.24.0",
64
66
  "morgan": "~1.10.0",
65
67
  "multer": "1.4.5-lts.1",
@@ -111,6 +113,8 @@
111
113
  "@types/express": "^4.17.21",
112
114
  "@types/express-session": "^1.17.3",
113
115
  "@types/express-useragent": "^1.0.5",
116
+ "@types/html-docx-js": "^0.3.4",
117
+ "@types/marked": "^6.0.0",
114
118
  "@types/morgan": "^1.9.9",
115
119
  "@types/node": "^20.14.12",
116
120
  "@types/passport": "^1.0.16",