Skip to content

Commit

Permalink
New Components - invision_community (#12623)
Browse files Browse the repository at this point in the history
* invision_community init

* [Components] invision_community #12563
Sources
 - New Member (Instant)
 - New Forum Topic (Instant)
 - New Topic Post (Instant)

Actions
 - Create Member
 - Update Member
 - Create Forum Topic

* pnpm update
  • Loading branch information
luancazarine committed Jul 1, 2024
1 parent f6d3a72 commit 0355b13
Show file tree
Hide file tree
Showing 14 changed files with 946 additions and 211 deletions.
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",
],
},
},
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;
},
};
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,
},
},
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;
},
};
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;
},
};
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;
};
Loading

0 comments on commit 0355b13

Please sign in to comment.