Skip to content

Commit 2846097

Browse files
lcaresiadanhsiungGTFalcao
authored
[Components] plecto #13237 (#17366)
* Adding app scaffolding for explorium * Added actions * Added actions * Added actions * Added actions --------- Co-authored-by: danhsiung <[email protected]> Co-authored-by: Guilherme Falcão <[email protected]>
1 parent 8b0a8ca commit 2846097

File tree

5 files changed

+158
-19
lines changed

5 files changed

+158
-19
lines changed

components/plecto/.gitignore

Lines changed: 0 additions & 3 deletions
This file was deleted.
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import app from "../../plecto.app.mjs";
2+
3+
export default {
4+
key: "plecto-create-registration",
5+
name: "Create Registration",
6+
description: "Creates a new registration in Plecto. [See the documentation](https://docs.plecto.com/kb/guide/en/overview-of-plecto-api-endpoints-Qvm3c3ucy1/Steps/3879885,3896454)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
app,
11+
dataSource: {
12+
propDefinition: [
13+
app,
14+
"dataSource",
15+
],
16+
},
17+
member: {
18+
propDefinition: [
19+
app,
20+
"member",
21+
],
22+
},
23+
externalId: {
24+
propDefinition: [
25+
app,
26+
"externalId",
27+
],
28+
},
29+
date: {
30+
propDefinition: [
31+
app,
32+
"date",
33+
],
34+
},
35+
customFields: {
36+
propDefinition: [
37+
app,
38+
"customFields",
39+
],
40+
},
41+
},
42+
async run({ $ }) {
43+
const customFields = typeof this.customFields === "string"
44+
? JSON.parse(this.customFields)
45+
: this.customFields;
46+
47+
const response = await this.app.createRegistration({
48+
$,
49+
data: {
50+
"data_source": this.dataSource,
51+
"member": this.member,
52+
"external_id": this.externalId,
53+
"date": this.date,
54+
...customFields,
55+
},
56+
});
57+
$.export("$summary", "Successfully created registration with ID: " + response.id);
58+
return response;
59+
},
60+
};

components/plecto/app/plecto.app.ts

Lines changed: 0 additions & 13 deletions
This file was deleted.

components/plecto/package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
{
22
"name": "@pipedream/plecto",
3-
"version": "0.0.2",
3+
"version": "0.1.0",
44
"description": "Pipedream Plecto Components",
5-
"main": "dist/app/plecto.app.mjs",
5+
"main": "plecto.app.mjs",
66
"keywords": [
77
"pipedream",
88
"plecto"
99
],
10-
"files": ["dist"],
1110
"homepage": "https://pipedream.com/apps/plecto",
1211
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
1312
"publishConfig": {

components/plecto/plecto.app.mjs

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
import { axios } from "@pipedream/platform";
2+
3+
export default {
4+
type: "app",
5+
app: "plecto",
6+
propDefinitions: {
7+
dataSource: {
8+
type: "string",
9+
label: "Data Source",
10+
description: "ID of the data source of the registration",
11+
async options() {
12+
const response = await this.getDataSources();
13+
return response.map(({
14+
uuid, title,
15+
}) => ({
16+
value: uuid,
17+
label: title,
18+
}));
19+
},
20+
},
21+
member: {
22+
type: "string",
23+
label: "Member",
24+
description: "ID of the member associated with this registration",
25+
async options() {
26+
const response = await this.getMembers();
27+
return response.map(({
28+
uuid, name,
29+
}) => ({
30+
value: uuid,
31+
label: name,
32+
}));
33+
},
34+
},
35+
externalId: {
36+
type: "string",
37+
label: "External ID",
38+
description: "External ID to prevent duplicate registrations",
39+
optional: true,
40+
},
41+
date: {
42+
type: "string",
43+
label: "Date",
44+
description: "Date and time of the registration in ISO 8601 format",
45+
optional: true,
46+
},
47+
customFields: {
48+
type: "object",
49+
label: "Custom Fields",
50+
description: "Custom fields representing the product information. For example. `{ \"Product Name\": \"Green tea\", \"Units Sold\": 2 }`",
51+
optional: true,
52+
},
53+
},
54+
methods: {
55+
_baseUrl() {
56+
return "https://app.plecto.com/api/v2";
57+
},
58+
async _makeRequest(opts = {}) {
59+
const {
60+
$ = this,
61+
path,
62+
auth,
63+
...otherOpts
64+
} = opts;
65+
return axios($, {
66+
...otherOpts,
67+
url: this._baseUrl() + path,
68+
auth: {
69+
username: `${this.$auth.username}`,
70+
password: `${this.$auth.password}`,
71+
...auth,
72+
},
73+
});
74+
},
75+
76+
async createRegistration(args = {}) {
77+
return this._makeRequest({
78+
path: "/registrations/",
79+
method: "post",
80+
...args,
81+
});
82+
},
83+
async getDataSources(args = {}) {
84+
return this._makeRequest({
85+
path: "/datasources/",
86+
...args,
87+
});
88+
},
89+
async getMembers(args = {}) {
90+
return this._makeRequest({
91+
path: "/members/",
92+
...args,
93+
});
94+
},
95+
},
96+
};

0 commit comments

Comments
 (0)