Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
import { parseObject } from "../../common/utils.mjs";
import invisionCommunity from "../../invision_community.app.mjs";

export default {
key: "invision_community-create-forum-topic",
name: "Create Forum Topic",
description: "Creates a new forum topic. [See the documentation](https://invisioncommunity.com/developers/rest-api?endpoint=forums/topics/postindex)",
version: "0.0.1",
type: "action",
props: {
invisionCommunity,
forumId: {
propDefinition: [
invisionCommunity,
"forumId",
],
},
title: {
propDefinition: [
invisionCommunity,
"title",
],
},
postContent: {
propDefinition: [
invisionCommunity,
"postContent",
],
},
author: {
propDefinition: [
invisionCommunity,
"authorId",
],
},
tags: {
propDefinition: [
invisionCommunity,
"tags",
],
optional: true,
},
openTime: {
propDefinition: [
invisionCommunity,
"openTime",
],
optional: true,
},
closeTime: {
propDefinition: [
invisionCommunity,
"closeTime",
],
optional: true,
},
hidden: {
propDefinition: [
invisionCommunity,
"hidden",
],
},
pinned: {
propDefinition: [
invisionCommunity,
"pinned",
],
},
featured: {
propDefinition: [
invisionCommunity,
"featured",
],
},
Comment on lines +10 to +74
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tip

Codebase Verification

Ensure consistency in property definitions.

The properties in create-forum-topic.mjs should be consistent with those defined in invision_community.app.mjs. However, the extracted propDefinitions from invision_community.app.mjs do not include the properties such as forumId, title, postContent, authorId, tags, openTime, closeTime, hidden, pinned, and featured that are used in create-forum-topic.mjs. Please ensure these properties are defined in the invision_community.app.mjs file.

  • components/invision_community/actions/create-forum-topic/create-forum-topic.mjs:
    • forumId
    • title
    • postContent
    • authorId
    • tags
    • openTime
    • closeTime
    • hidden
    • pinned
    • featured
Analysis chain

Ensure consistency in property definitions.

The properties are well-defined using propDefinition from the invisionCommunity app module. However, it's important to ensure that all these properties are indeed defined and used in the invisionCommunity app module as expected.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Search for property definitions in the `invision_community.app.mjs` file.
rg --type mjs "propDefinitions:" "../../invision_community.app.mjs"

Length of output: 93



Script:

#!/bin/bash
# Description: Search for property definitions in the `invision_community.app.mjs` file.
rg --type js "propDefinitions:" "../../invision_community.app.mjs"

Length of output: 137



Script:

#!/bin/bash
# Description: Find the correct path for the `invision_community.app.mjs` file and search for property definitions.
# Step 1: Locate the `invision_community.app.mjs` file.
fd --type f --name "invision_community.app.mjs"

# Step 2: Search for `propDefinitions` in the located file.
fd --type f --name "invision_community.app.mjs" --exec rg "propDefinitions:" {}

Length of output: 629



Script:

#!/bin/bash
# Description: Find the correct path for the `invision_community.app.mjs` file and search for property definitions.
# Step 1: Locate the `invision_community.app.mjs` file.
fd -t f -e mjs -name "invision_community.app.mjs"

# Step 2: Search for `propDefinitions` in the located file.
fd -t f -e mjs -name "invision_community.app.mjs" --exec rg "propDefinitions:" {}

Length of output: 593



Script:

#!/bin/bash
# Description: Find the correct path for the `invision_community.app.mjs` file and search for property definitions.
# Step 1: Locate the `invision_community.app.mjs` file.
fd -t f -e mjs "invision_community.app.mjs"

# Step 2: Search for `propDefinitions` in the located file.
fd -t f -e mjs "invision_community.app.mjs" --exec rg "propDefinitions:" {}

Length of output: 197



Script:

#!/bin/bash
# Description: Extract and list all property definitions within `invision_community.app.mjs` to verify consistency.
# Step 1: Locate the `invision_community.app.mjs` file.
fd -t f -e mjs "invision_community.app.mjs"

# Step 2: Extract and list all property definitions within the located file.
fd -t f -e mjs "invision_community.app.mjs" --exec rg "propDefinitions:" {} -A 50

Length of output: 1392

},
async run({ $ }) {

const response = await this.invisionCommunity.createForumTopic({
$,
params: {
forum: this.forumId,
title: this.title,
post: this.postContent,
author: this.author,
tags: parseObject(this.tags)?.join(","),
open_time: this.openTime,
close_time: this.closeTime,
hidden: +this.hidden,
pinned: +this.pinned,
featured: +this.featured,
},
});
$.export("$summary", `Successfully created forum topic with title "${this.title}"`);
return response;
},
Comment on lines +76 to +95
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check for potential error handling in the run method.

The run method executes the forum topic creation but does not explicitly handle errors. Consider adding try-catch blocks to handle possible exceptions from the API call.

  async run({ $ }) {
+   try {
    const response = await this.invisionCommunity.createForumTopic({
      $,
      params: {
        forum: this.forumId,
        title: this.title,
        post: this.postContent,
        author: this.author,
        tags: parseObject(this.tags)?.join(","),
        open_time: this.openTime,
        close_time: this.closeTime,
        hidden: +this.hidden,
        pinned: +this.pinned,
        featured: +this.featured,
      },
    });
    $.export("$summary", `Successfully created forum topic with title "${this.title}"`);
    return response;
+   } catch (error) {
+       $.export("$error", "Failed to create forum topic: " + error.message);
+       throw error;
+   }
  },
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
async run({ $ }) {
const response = await this.invisionCommunity.createForumTopic({
$,
params: {
forum: this.forumId,
title: this.title,
post: this.postContent,
author: this.author,
tags: parseObject(this.tags)?.join(","),
open_time: this.openTime,
close_time: this.closeTime,
hidden: +this.hidden,
pinned: +this.pinned,
featured: +this.featured,
},
});
$.export("$summary", `Successfully created forum topic with title "${this.title}"`);
return response;
},
async run({ $ }) {
try {
const response = await this.invisionCommunity.createForumTopic({
$,
params: {
forum: this.forumId,
title: this.title,
post: this.postContent,
author: this.author,
tags: parseObject(this.tags)?.join(","),
open_time: this.openTime,
close_time: this.closeTime,
hidden: +this.hidden,
pinned: +this.pinned,
featured: +this.featured,
},
});
$.export("$summary", `Successfully created forum topic with title "${this.title}"`);
return response;
} catch (error) {
$.export("$error", "Failed to create forum topic: " + error.message);
throw error;
}
},

};
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import invisionCommunity from "../../invision_community.app.mjs";

export default {
key: "invision_community-create-member",
name: "Create Member",
description: "Creates a new member. [See the documentation](https://invisioncommunity.com/developers/rest-api?endpoint=core/members/postindex)",
version: "0.0.1",
type: "action",
props: {
invisionCommunity,
name: {
propDefinition: [
invisionCommunity,
"name",
],
},
email: {
propDefinition: [
invisionCommunity,
"email",
],
},
password: {
propDefinition: [
invisionCommunity,
"password",
],
optional: true,
},
groupId: {
propDefinition: [
invisionCommunity,
"groupId",
],
optional: true,
},
validated: {
propDefinition: [
invisionCommunity,
"validated",
],
optional: true,
},
},
Comment on lines +10 to +44
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tip

Codebase Verification

Ensure consistency in property definitions.

The properties name, email, password, and groupId are defined in the propDefinitions object in the invision_community.app.mjs file. However, the validated property is missing.

  • Please define the validated property in the propDefinitions object in invision_community.app.mjs.
Analysis chain

Ensure consistency in property definitions.

The properties are well-defined using propDefinition from the invisionCommunity app module. However, it's important to ensure that all these properties are indeed defined and used in the invisionCommunity app module as expected.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Search for property definitions in the `invision_community.app.mjs` file.
rg --type mjs "propDefinitions:" "../../invision_community.app.mjs"

Length of output: 93



Script:

#!/bin/bash
# Description: Search for property definitions in the `invision_community.app.mjs` file.
rg "propDefinitions:" "../../invision_community.app.mjs"

Length of output: 127



Script:

#!/bin/bash
# Locate the `invision_community.app.mjs` file and then search for `propDefinitions` within it.
fd 'invision_community.app.mjs' | xargs rg 'propDefinitions:'

Length of output: 80



Script:

#!/bin/bash
# Search for specific properties within the `propDefinitions:` object in the `invision_community.app.mjs` file.
fd 'invision_community.app.mjs' | xargs rg -A 20 'propDefinitions:' | rg 'name|email|password|groupId|validated'

Length of output: 321

async run({ $ }) {
const response = await this.invisionCommunity.createMember({
$,
params: {
name: this.name,
email: this.email,
password: this.password,
group: this.groupId,
registrationIpAddress: this.registrationIpAddress,
validated: this.validated,
},
});

$.export("$summary", `Successfully created member with ID ${response.id}`);
return response;
},
Comment on lines +45 to +60
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check for potential error handling in the run method.

The run method executes the member creation but does not explicitly handle errors. Consider adding try-catch blocks to handle possible exceptions from the API call.

  async run({ $ }) {
+   try {
    const response = await this.invisionCommunity.createMember({
      $,
      params: {
        name: this.name,
        email: this.email,
        password: this.password,
        group: this.groupId,
        registrationIpAddress: this.registrationIpAddress,
        validated: this.validated,
      },
    });
    $.export("$summary", `Successfully created member with ID ${response.id}`);
    return response;
+   } catch (error) {
+       $.export("$error", "Failed to create member: " + error.message);
+       throw error;
+   }
  },
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
async run({ $ }) {
const response = await this.invisionCommunity.createMember({
$,
params: {
name: this.name,
email: this.email,
password: this.password,
group: this.groupId,
registrationIpAddress: this.registrationIpAddress,
validated: this.validated,
},
});
$.export("$summary", `Successfully created member with ID ${response.id}`);
return response;
},
async run({ $ }) {
try {
const response = await this.invisionCommunity.createMember({
$,
params: {
name: this.name,
email: this.email,
password: this.password,
group: this.groupId,
registrationIpAddress: this.registrationIpAddress,
validated: this.validated,
},
});
$.export("$summary", `Successfully created member with ID ${response.id}`);
return response;
} catch (error) {
$.export("$error", "Failed to create member: " + error.message);
throw error;
}
},

};
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import invisionCommunity from "../../invision_community.app.mjs";

export default {
key: "invision_community-update-member",
name: "Update Member",
description: "Updates an existing member's details. [See the documentation](https://invisioncommunity.com/developers/rest-api?endpoint=core/members/postitem)",
version: "0.0.1",
type: "action",
props: {
invisionCommunity,
memberId: {
propDefinition: [
invisionCommunity,
"memberId",
],
},
name: {
propDefinition: [
invisionCommunity,
"name",
],
optional: true,
},
email: {
propDefinition: [
invisionCommunity,
"email",
],
optional: true,
},
password: {
propDefinition: [
invisionCommunity,
"password",
],
optional: true,
},
groupId: {
propDefinition: [
invisionCommunity,
"groupId",
],
optional: true,
},
validated: {
propDefinition: [
invisionCommunity,
"validated",
],
optional: true,
},
},
async run({ $ }) {
const response = await this.invisionCommunity.updateMember({
$,
memberId: this.memberId,
params: {
name: this.name,
email: this.email,
password: this.password,
group: this.groupId,
registrationIpAddress: this.registrationIpAddress,
validated: this.validated,
},
});
$.export("$summary", `Successfully updated member with Id: ${this.memberId}`);
return response;
},
Comment on lines +53 to +68
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check for potential error handling in the run method.

The run method executes the member update but does not explicitly handle errors. Consider adding try-catch blocks to handle possible exceptions from the API call.

  async run({ $ }) {
+   try {
    const response = await this.invisionCommunity.updateMember({
      $,
      memberId: this.memberId,
      params: {
        name: this.name,
        email: this.email,
        password: this.password,
        group: this.groupId,
        registrationIpAddress: this.registrationIpAddress,
        validated: this.validated,
      },
    });
    $.export("$summary", `Successfully updated member with Id: ${this.memberId}`);
    return response;
+   } catch (error) {
+       $.export("$error", "Failed to update member: " + error.message);
+       throw error;
+   }
  },
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
async run({ $ }) {
const response = await this.invisionCommunity.updateMember({
$,
memberId: this.memberId,
params: {
name: this.name,
email: this.email,
password: this.password,
group: this.groupId,
registrationIpAddress: this.registrationIpAddress,
validated: this.validated,
},
});
$.export("$summary", `Successfully updated member with Id: ${this.memberId}`);
return response;
},
async run({ $ }) {
try {
const response = await this.invisionCommunity.updateMember({
$,
memberId: this.memberId,
params: {
name: this.name,
email: this.email,
password: this.password,
group: this.groupId,
registrationIpAddress: this.registrationIpAddress,
validated: this.validated,
},
});
$.export("$summary", `Successfully updated member with Id: ${this.memberId}`);
return response;
} catch (error) {
$.export("$error", "Failed to update member: " + error.message);
throw error;
}
},

};
24 changes: 24 additions & 0 deletions components/invision_community/common/utils.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
export const parseObject = (obj) => {
if (!obj) return undefined;

if (Array.isArray(obj)) {
return obj.map((item) => {
if (typeof item === "string") {
try {
return JSON.parse(item);
} catch (e) {
return item;
}
}
return item;
});
}
if (typeof obj === "string") {
try {
return JSON.parse(obj);
} catch (e) {
return obj;
}
}
return obj;
};
Comment on lines +1 to +24
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding error logging in parseObject.

The function silently catches and ignores JSON parsing errors. Adding error logging could help in debugging issues related to JSON parsing.

-        } catch (e) {
+        } catch (error) {
+          console.error("JSON parsing error:", error);
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
export const parseObject = (obj) => {
if (!obj) return undefined;
if (Array.isArray(obj)) {
return obj.map((item) => {
if (typeof item === "string") {
try {
return JSON.parse(item);
} catch (e) {
return item;
}
}
return item;
});
}
if (typeof obj === "string") {
try {
return JSON.parse(obj);
} catch (e) {
return obj;
}
}
return obj;
};
export const parseObject = (obj) => {
if (!obj) return undefined;
if (Array.isArray(obj)) {
return obj.map((item) => {
if (typeof item === "string") {
try {
return JSON.parse(item);
} catch (error) {
console.error("JSON parsing error:", error);
return item;
}
}
return item;
});
}
if (typeof obj === "string") {
try {
return JSON.parse(obj);
} catch (error) {
console.error("JSON parsing error:", error);
return obj;
}
}
return obj;
};

Loading