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
97 changes: 97 additions & 0 deletions components/pencil_spaces/actions/create-space/create-space.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
import { VISIBILITY_OPTIONS } from "../../common/constants.mjs";
import { parseObject } from "../../common/utils.mjs";
import pencilSpaces from "../../pencil_spaces.app.mjs";

export default {
key: "pencil_spaces-create-space",
name: "Create A Space",
description: "Create a new space in Pencil Spaces. [See the documentation](https://api.pencilspaces.com/reference#tag/spaces/POST/spaces/create)",
version: "0.0.1",
type: "action",
props: {
pencilSpaces,
title: {
type: "string",
label: "Title",
description: "The title of the Space. If not provided and `Space To Clone Id` is set, the existing Space name will be used. If not, a random Space name will be generated.",
optional: true,
},
spaceToCloneId: {
propDefinition: [
pencilSpaces,
"spaceToCloneId",
],
optional: true,
},
ownerId: {
propDefinition: [
pencilSpaces,
"ownerId",
],
optional: true,
},
hostIds: {
propDefinition: [
pencilSpaces,
"ownerId",
],
type: "string[]",
label: "Host Ids",
description: "The hosts you wish to invite to the Space. The user associated with your API key will always be added as a host.",
optional: true,
},
participantIds: {
propDefinition: [
pencilSpaces,
"ownerId",
],
type: "string[]",
label: "Participant Ids",
description: "The participants you wish to invite to the Space.",
optional: true,
},
visibility: {
type: "string",
label: "Visibility",
description: "The visibility of the Space.",
options: VISIBILITY_OPTIONS,
optional: true,
},
notifyInvitees: {
type: "boolean",
label: "Notify Invitees",
description: "Whether you want to automatically notify invitees when you create your Space.",
},
siteId: {
propDefinition: [
pencilSpaces,
"siteId",
],
optional: true,
},
},
async run({ $ }) {
const response = await this.pencilSpaces.createSpace({
$,
data: {
title: this.title,
spaceToCloneId: this.spaceToCloneId,
ownerId: {
userId: this.ownerId,
},
hostIds: parseObject(this.hostIds)?.map((hostId) => ({
userId: hostId,
})),
participantIds: parseObject(this.participantIds)?.map((participantId) => ({
userId: participantId,
})),
visibility: this.visibility,
notifyInvitees: this.notifyInvitees,
siteId: this.siteId,
},
});

$.export("$summary", `Successfully created space with ID: "${response.spaceId}"`);
return response;
},
};
10 changes: 10 additions & 0 deletions components/pencil_spaces/common/constants.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export const VISIBILITY_OPTIONS = [
{
label: "Public",
value: "public",
},
{
label: "Private",
value: "private",
},
];
24 changes: 24 additions & 0 deletions components/pencil_spaces/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;
};
7 changes: 5 additions & 2 deletions components/pencil_spaces/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/pencil_spaces",
"version": "0.0.1",
"version": "0.1.0",
"description": "Pipedream Pencil Spaces Components",
"main": "pencil_spaces.app.mjs",
"keywords": [
Expand All @@ -11,5 +11,8 @@
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
"publishConfig": {
"access": "public"
},
"dependencies": {
"@pipedream/platform": "^3.1.0"
}
}
}
106 changes: 101 additions & 5 deletions components/pencil_spaces/pencil_spaces.app.mjs
Original file line number Diff line number Diff line change
@@ -1,11 +1,107 @@
import { axios } from "@pipedream/platform";

export default {
type: "app",
app: "pencil_spaces",
propDefinitions: {},
propDefinitions: {
spaceToCloneId: {
type: "string",
label: "Space To Clone Id",
description: "The space ID of the Space you want to clone. You may only clone Spaces that are templates, Spaces for which you are a host, and Spaces which you can access as an admin due to your institution settings.",
async options({ page }) {
const { results } = await this.listSpaces({
params: {
pageNumber: page + 1,
},
});

return results.map(({
spaceId: value, title: label,
}) => ({
label,
value,
}));
},
},
ownerId: {
type: "string",
label: "Owner Id",
description: "The ID of the user who will be the owner of the space. If not provided, the current user will be the owner.",
async options({ page }) {
const { results } = await this.listUsers({
params: {
pageNumber: page + 1,
},
});

return results.map(({
userId: value, email: label,
}) => ({
label,
value,
}));
},
},
siteId: {
type: "string",
label: "Site Id",
description: "The ID of the site you want to create the Space in.",
async options() {
const { results } = await this.listSites();

return results.map(({
id: value, name: label,
}) => ({
label,
value,
}));
},
},
},
methods: {
// this.$auth contains connected account data
authKeys() {
console.log(Object.keys(this.$auth));
_baseUrl() {
return this.$auth.api_url;
},
_headers(headers = {}) {
return {
...headers,
"Authorization": `Bearer ${this.$auth.api_key}`,
"Content-Type": "application/json",
};
},
async _makeRequest({
$ = this, path, headers, ...opts
}) {
return axios($, {
url: `${this._baseUrl()}${path}`,
headers: this._headers(headers),
...opts,
});
},
listSpaces(opts = {}) {
return this._makeRequest({
path: "spaces",
...opts,
});
},
listUsers(opts = {}) {
return this._makeRequest({
path: "users",
...opts,
});
},
listSites(opts = {}) {
return this._makeRequest({
path: "sites",
...opts,
});
},
createSpace(opts = {}) {
return this._makeRequest({
method: "POST",
path: "spaces/create",
...opts,
});
},
},
};
};
18 changes: 7 additions & 11 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading