@7365admin1/core 3.13.0 → 3.14.0

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/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @iservice365/core
2
2
 
3
+ ## 3.14.0
4
+
5
+ ### Minor Changes
6
+
7
+ - f0f905e: release changes in incident report api, member api, etc.
8
+
3
9
  ## 3.13.0
4
10
 
5
11
  ### Minor Changes
package/dist/index.js CHANGED
@@ -9171,6 +9171,7 @@ var APP_POOL_MAINTENANCE = process.env.APP_POOL_MAINTENANCE ?? "http://localhost
9171
9171
  var ENCRYPTION_KEY = process.env.ENCRYPTION_KEY ?? "";
9172
9172
  var DOMAIN = process.env.DOMAIN ?? "localhost";
9173
9173
  var OPEN_AI_API_KEY = process.env.OPEN_AI_API_KEY;
9174
+ var ANTHROPIC_API_KEY = process.env.ANTHROPIC_API_KEY;
9174
9175
  var STORAGE_API = process.env.STORAGE_API;
9175
9176
 
9176
9177
  // src/services/auth.service.ts
@@ -9661,59 +9662,41 @@ function useMemberRepo() {
9661
9662
  try {
9662
9663
  const items = await collection.aggregate([
9663
9664
  { $match: query },
9664
- { $sort: { _id: -1 } },
9665
- { $skip: page * limit },
9666
- { $limit: limit },
9667
- {
9668
- $lookup: {
9669
- from: "organizations",
9670
- localField: "org",
9671
- foreignField: "_id",
9672
- as: "orgData"
9673
- }
9674
- },
9675
- {
9676
- $unwind: {
9677
- path: "$orgData",
9678
- preserveNullAndEmptyArrays: true
9679
- }
9680
- },
9681
9665
  {
9682
9666
  $lookup: {
9683
9667
  from: "organizations",
9684
9668
  localField: "org",
9685
9669
  foreignField: "_id",
9686
- as: "defaultSite"
9670
+ as: "org"
9687
9671
  }
9688
9672
  },
9689
9673
  {
9690
9674
  $unwind: {
9691
- path: "$defaultSite",
9675
+ path: "$org",
9692
9676
  preserveNullAndEmptyArrays: true
9693
9677
  }
9694
9678
  },
9695
9679
  {
9696
9680
  $group: {
9697
- _id: "$org",
9698
- text: { $first: "$orgName" },
9699
- value: { $first: "$org" },
9700
- defaultSite: { $first: "$defaultSite.defaultSite" },
9701
- onboardingRequired: {
9702
- $first: "$orgData.onboardingRequired"
9703
- },
9704
- onboardingCompleted: {
9705
- $first: "$orgData.onboardingCompleted"
9706
- },
9707
- onboardingCompletedAt: {
9708
- $first: "$orgData.onboardingCompletedAt"
9709
- }
9681
+ _id: "$org._id",
9682
+ text: { $first: "$org.name" },
9683
+ value: { $first: "$org._id" },
9684
+ type: { $first: "$org.type" },
9685
+ defaultSite: { $first: "$org.defaultSite" },
9686
+ onboardingRequired: { $first: "$org.onboardingRequired" },
9687
+ onboardingCompleted: { $first: "$org.onboardingCompleted" },
9688
+ onboardingCompletedAt: { $first: "$org.onboardingCompletedAt" }
9710
9689
  }
9711
9690
  },
9691
+ { $sort: { _id: -1 } },
9692
+ { $skip: page * limit },
9693
+ { $limit: limit },
9712
9694
  {
9713
9695
  $project: {
9714
9696
  _id: 0,
9715
9697
  text: 1,
9716
9698
  value: 1,
9699
+ type: 1,
9717
9700
  defaultSite: 1,
9718
9701
  onboardingRequired: 1,
9719
9702
  onboardingCompleted: 1,
@@ -11563,21 +11546,10 @@ function useSiteRepo() {
11563
11546
  throw new import_node_server_utils19.BadRequestError("Invalid site ID format.");
11564
11547
  }
11565
11548
  try {
11566
- const cacheKey = (0, import_node_server_utils19.makeCacheKey)(namespace_collection, { _id });
11567
- const cachedData = await getCache(cacheKey);
11568
- if (cachedData) {
11569
- import_node_server_utils19.logger.info(`Cache hit for key: ${cacheKey}`);
11570
- return cachedData;
11571
- }
11572
11549
  const data = await collection.aggregate([{ $match: { _id, status: { $ne: "deleted" } } }]).toArray();
11573
11550
  if (!data || !data.length) {
11574
11551
  throw new import_node_server_utils19.NotFoundError("Site not found.");
11575
11552
  }
11576
- setCache(cacheKey, data[0], 15 * 60).then(() => {
11577
- import_node_server_utils19.logger.info(`Cache set for key: ${cacheKey}`);
11578
- }).catch((err) => {
11579
- import_node_server_utils19.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
11580
- });
11581
11553
  return data[0];
11582
11554
  } catch (error) {
11583
11555
  throw error;
@@ -54580,7 +54552,7 @@ function useIncidentReportRepo() {
54580
54552
  }
54581
54553
 
54582
54554
  // src/services/incident-report.service.ts
54583
- var import_openai = __toESM(require("openai"));
54555
+ var import_sdk = __toESM(require("@anthropic-ai/sdk"));
54584
54556
  function useIncidentReportService() {
54585
54557
  const {
54586
54558
  add: _add,
@@ -54673,20 +54645,12 @@ function useIncidentReportService() {
54673
54645
  }
54674
54646
  }
54675
54647
  async function createIncidentSummary(value) {
54676
- const session = import_node_server_utils182.useAtlas.getClient()?.startSession();
54677
- session?.startTransaction();
54678
54648
  const sample = `On August 4, 2024, an incident report labeled IR10 was submitted following an earthquake that occurred between 10:00 AM and 10:30 AM at a designated test site. The report indicated that the incident was reported by a complainant named Maryam, who provided her contact information as +65-123456789. The recipient of the complaint was Rash, whose contact number is +65-987654321. The description of the complaint detailed a historical context regarding the origins of Lorem Ipsum text, an academic piece that has been referenced throughout centuries.
54679
- ' +
54680
- '
54681
- ' +
54682
- 'The report highlighted that no individuals were directly affected or injured in the incident. However, there was damage to property associated with the incident, particularly mentioning an individual named Ruzzy, with contact +65-34567777889, who experienced property damage. The report states that this damage was also elaborated upon with historical context, reiterating similar pieces of information on the classical literature that influenced the Lorem Ipsum narrative.
54683
- ' +
54684
- '
54685
- ' +
54686
- "No authorities were called, and the incident's resolution was marked at 11:00 AM, with actions taken by Ola, the shift in charge during the incident. The management was informed of the incident at 10:08 AM, and security implications were considered but not detailed. The report remains pending and does not mention a reason for rejection or approval status. The incident is documented with attached photographs. The overall status of the report remains pending as of the latest update.`;
54687
- const openai = new import_openai.default({
54688
- apiKey: OPEN_AI_API_KEY
54689
- });
54649
+
54650
+ The report highlighted that no individuals were directly affected or injured in the incident. However, there was damage to property associated with the incident, particularly mentioning an individual named Ruzzy, with contact +65-34567777889, who experienced property damage. The report states that this damage was also elaborated upon with historical context, reiterating similar pieces of information on the classical literature that influenced the Lorem Ipsum narrative.
54651
+
54652
+ No authorities were called, and the incident's resolution was marked at 11:00 AM, with actions taken by Ola, the shift in charge during the incident. The management was informed of the incident at 10:08 AM, and security implications were considered but not detailed. The report remains pending and does not mention a reason for rejection or approval status. The incident is documented with attached photographs. The overall status of the report remains pending as of the latest update.`;
54653
+ const anthropic = new import_sdk.default({ apiKey: ANTHROPIC_API_KEY });
54690
54654
  try {
54691
54655
  if (value?.incidentInformation?.siteInfo?.site) {
54692
54656
  const site = await _getSiteById(
@@ -54703,19 +54667,15 @@ function useIncidentReportService() {
54703
54667
  value.organization = org.name;
54704
54668
  }
54705
54669
  }
54706
- const completion = await openai.chat.completions.create({
54707
- model: "gpt-4o-mini",
54708
- messages: [
54709
- {
54710
- role: "system",
54711
- content: `You write a comprehensive summary for incident reports, exclude the attachment, and make it in essay format, and don't add any explaination to how the summary is about, and don't use the mongodb id number for the summary and Must include the following answers to What happened ?, Where did it happened ?, Who was involved ?, How did it happened?, Why did it happened?, Is there any security implications due to incident ?, just keep it plain since we will save it directly into the database. here's a sample: ${sample}`
54712
- },
54713
- { role: "user", content: JSON.stringify(value) }
54714
- ]
54670
+ const response = await anthropic.messages.create({
54671
+ model: "claude-sonnet-4-6",
54672
+ max_tokens: 1024,
54673
+ system: `You write a comprehensive summary for incident reports, exclude the attachment, and make it in essay format, and don't add any explaination to how the summary is about, and don't use the mongodb id number for the summary and Must include the following answers to What happened ?, Where did it happened ?, Who was involved ?, How did it happened?, Why did it happened?, Is there any security implications due to incident ?, just keep it plain since we will save it directly into the database. here's a sample: ${sample}`,
54674
+ messages: [{ role: "user", content: JSON.stringify(value) }]
54715
54675
  });
54716
- const briefsummary = completion?.choices[0]?.message?.content;
54717
- if (briefsummary) {
54718
- return briefsummary;
54676
+ const briefSummary = response.content[0].type === "text" ? response.content[0].text : null;
54677
+ if (briefSummary) {
54678
+ return briefSummary;
54719
54679
  } else {
54720
54680
  return "Failed to generate a summary.";
54721
54681
  }