Skip to content

Commit 49771c3

Browse files
authored
New Components - suitedash (#14311)
* init * new components * pnpm-lock.yaml * updates
1 parent 4141ea4 commit 49771c3

File tree

11 files changed

+472
-19
lines changed

11 files changed

+472
-19
lines changed

components/suitedash/.gitignore

-3
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
import suitedash from "../../suitedash.app.mjs";
2+
3+
export default {
4+
key: "suitedash-create-company",
5+
name: "Create Company",
6+
description: "Creates a new company in SuiteDash. [See the documentation](https://app.suitedash.com/secure-api/swagger)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
suitedash,
11+
companyName: {
12+
propDefinition: [
13+
suitedash,
14+
"companyName",
15+
],
16+
},
17+
companyRole: {
18+
propDefinition: [
19+
suitedash,
20+
"role",
21+
],
22+
},
23+
firstName: {
24+
type: "string",
25+
label: "First Name",
26+
description: "First name of the company's primary contact",
27+
},
28+
lastName: {
29+
type: "string",
30+
label: "Last Name",
31+
description: "Last name of the company's primary contact",
32+
},
33+
email: {
34+
type: "string",
35+
label: "Email",
36+
description: "Email address of the company's primary contact",
37+
},
38+
sendWelcomeEmail: {
39+
type: "boolean",
40+
label: "Send Welcome Email",
41+
description: "Send welcome email to the primary contact. Default: `false`",
42+
optional: true,
43+
default: false,
44+
},
45+
createPrimaryContactIfNotExists: {
46+
type: "boolean",
47+
label: "Create Primary Contact If Not Exists",
48+
description: "Create a Primary Contact with all provided data if the email does not exist. Default: `true`",
49+
optional: true,
50+
default: true,
51+
},
52+
preventIndividualMode: {
53+
type: "boolean",
54+
label: "Prevent Individual Mode",
55+
description: "Prevent this Primary Contact from switching into `Individual Mode`. Default: `false`",
56+
optional: true,
57+
default: false,
58+
},
59+
},
60+
async run({ $ }) {
61+
const response = await this.suitedash.createCompany({
62+
$,
63+
data: {
64+
name: this.companyName,
65+
role: this.companyRole,
66+
primaryContact: {
67+
first_name: this.firstName,
68+
last_name: this.lastName,
69+
email: this.email,
70+
send_welcome_email: this.sendWelcomeEmail,
71+
create_primary_contact_if_not_exists: this.createPrimaryContactIfNotExists,
72+
prevent_individual_mode: this.preventIndividualMode,
73+
},
74+
},
75+
});
76+
$.export("$summary", `Successfully created company ${this.companyName}`);
77+
return response;
78+
},
79+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import suitedash from "../../suitedash.app.mjs";
2+
3+
export default {
4+
key: "suitedash-create-contact",
5+
name: "Create Contact",
6+
description: "Creates a new contact in SuiteDash. [See the documentation](https://app.suitedash.com/secure-api/swagger)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
suitedash,
11+
firstName: {
12+
type: "string",
13+
label: "Contact First Name",
14+
description: "The first name of the new contact",
15+
},
16+
lastName: {
17+
type: "string",
18+
label: "Contact Last Name",
19+
description: "The last name of the new contact",
20+
},
21+
email: {
22+
type: "string",
23+
label: "Contact Email",
24+
description: "The email of the new contact",
25+
},
26+
role: {
27+
propDefinition: [
28+
suitedash,
29+
"role",
30+
],
31+
label: "Contact Role",
32+
description: "The role of the new contact",
33+
},
34+
sendWelcomeEmail: {
35+
type: "boolean",
36+
label: "Send Welcome Email",
37+
description: "Whether to send a welcome email to the new contact",
38+
optional: true,
39+
},
40+
},
41+
async run({ $ }) {
42+
const response = await this.suitedash.createContact({
43+
$,
44+
data: {
45+
first_name: this.firstName,
46+
last_name: this.lastName,
47+
email: this.email,
48+
role: this.role,
49+
send_welcome_email: this.sendWelcomeEmail,
50+
},
51+
});
52+
$.export("$summary", `Successfully created contact ${this.firstName} ${this.lastName}`);
53+
return response;
54+
},
55+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
import suitedash from "../../suitedash.app.mjs";
2+
import { ConfigurationError } from "@pipedream/platform";
3+
4+
export default {
5+
key: "suitedash-update-company",
6+
name: "Update Company",
7+
description: "Updates an existing company's details in SuiteDash. [See the documentation](https://app.suitedash.com/secure-api/swagger)",
8+
version: "0.0.1",
9+
type: "action",
10+
props: {
11+
suitedash,
12+
companyId: {
13+
propDefinition: [
14+
suitedash,
15+
"companyId",
16+
],
17+
},
18+
companyName: {
19+
propDefinition: [
20+
suitedash,
21+
"companyName",
22+
],
23+
optional: true,
24+
},
25+
website: {
26+
type: "string",
27+
label: "Website",
28+
description: "The website of the company.",
29+
optional: true,
30+
},
31+
phone: {
32+
type: "string",
33+
label: "Phone",
34+
description: "The phone number of the company",
35+
optional: true,
36+
},
37+
companyAddress: {
38+
type: "string",
39+
label: "Company Address",
40+
description: "The full address of the company. Example: dba Staybridge Suites Mount Laurel 324 Church Road Mount Laurel, NJ 09478",
41+
optional: true,
42+
},
43+
tags: {
44+
type: "string[]",
45+
label: "Tags",
46+
description: "An array of tags associated with the company",
47+
optional: true,
48+
},
49+
backgroundInfo: {
50+
type: "string",
51+
label: "Background Info",
52+
description: "Background information about the company",
53+
optional: true,
54+
},
55+
},
56+
async run({ $ }) {
57+
if (!this.companyName
58+
&& !this.website
59+
&& !this.phone
60+
&& !this.companyAddress
61+
&& !this.tags
62+
&& !this.backgroundInfo
63+
) {
64+
throw new ConfigurationError("Please enter at least one field to update");
65+
}
66+
67+
const response = await this.suitedash.updateCompany({
68+
$,
69+
companyId: this.companyId,
70+
data: {
71+
name: this.companyName,
72+
website: this.website,
73+
phone: this.phone,
74+
full_address: this.companyAddress,
75+
tags: this.tags,
76+
background_info: this.backgroundInfo,
77+
},
78+
});
79+
$.export("$summary", `Successfully updated company ${this.companyId}`);
80+
return response;
81+
},
82+
};

components/suitedash/app/suitedash.app.ts

-13
This file was deleted.

components/suitedash/package.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
{
22
"name": "@pipedream/suitedash",
3-
"version": "0.0.2",
3+
"version": "0.1.0",
44
"description": "Pipedream SuiteDash Components",
55
"main": "dist/app/suitedash.app.mjs",
66
"keywords": [
77
"pipedream",
88
"suitedash"
99
],
10-
"files": ["dist"],
1110
"homepage": "https://pipedream.com/apps/suitedash",
1211
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
1312
"publishConfig": {
1413
"access": "public"
14+
},
15+
"dependencies": {
16+
"@pipedream/platform": "^3.0.3"
1517
}
1618
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
import suitedash from "../../suitedash.app.mjs";
2+
import { DEFAULT_POLLING_SOURCE_TIMER_INTERVAL } from "@pipedream/platform";
3+
4+
export default {
5+
props: {
6+
suitedash,
7+
db: "$.service.db",
8+
timer: {
9+
type: "$.interface.timer",
10+
default: {
11+
intervalSeconds: DEFAULT_POLLING_SOURCE_TIMER_INTERVAL,
12+
},
13+
},
14+
},
15+
hooks: {
16+
async deploy() {
17+
await this.processEvent(25);
18+
},
19+
},
20+
methods: {
21+
_getLastTs() {
22+
return this.db.get("lastTs") || 0;
23+
},
24+
_setLastTs(lastTs) {
25+
this.db.set("lastTs", lastTs);
26+
},
27+
getParams() {
28+
return {};
29+
},
30+
getTsField() {
31+
return "created";
32+
},
33+
generateMeta(item) {
34+
return {
35+
id: item.uid,
36+
summary: this.getSummary(item),
37+
ts: Date.parse(item[this.getTsField()]),
38+
};
39+
},
40+
getFn() {
41+
throw new Error("getFn is not implemented");
42+
},
43+
getSummary() {
44+
throw new Error("getSummary is not implemented");
45+
},
46+
async processEvent(max) {
47+
const lastTs = this._getLastTs();
48+
let maxTs = lastTs;
49+
let results = [];
50+
51+
const items = this.suitedash.paginate({
52+
fn: this.getFn(),
53+
params: this.getParams(),
54+
});
55+
56+
for await (const item of items) {
57+
const ts = Date.parse(item[this.getTsField()]);
58+
if (ts >= lastTs) {
59+
results.push(item);
60+
maxTs = Math.max(ts, maxTs);
61+
}
62+
}
63+
64+
this._setLastTs(maxTs);
65+
66+
if (max) {
67+
results = results.slice(-1 * max);
68+
}
69+
70+
results.forEach((item) => {
71+
const meta = this.generateMeta(item);
72+
this.$emit(item, meta);
73+
});
74+
},
75+
},
76+
async run() {
77+
await this.processEvent();
78+
},
79+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import common from "../common/base.mjs";
2+
3+
export default {
4+
...common,
5+
key: "suitedash-new-company",
6+
name: "New Company Created",
7+
description: "Emit new event when a new company is created in SuiteDash",
8+
version: "0.0.1",
9+
type: "source",
10+
dedupe: "unique",
11+
methods: {
12+
...common.methods,
13+
getFn() {
14+
return this.suitedash.listCompanies;
15+
},
16+
getSummary(company) {
17+
if (!company || typeof company !== "object") {
18+
return "New Company: Unknown";
19+
}
20+
const name = company.name || "Unnamed";
21+
return `New Company: ${name}`;
22+
},
23+
},
24+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import common from "../common/base.mjs";
2+
3+
export default {
4+
...common,
5+
key: "suitedash-new-contact",
6+
name: "New Contact Created",
7+
description: "Emit new event when a new contact is created.",
8+
version: "0.0.1",
9+
type: "source",
10+
dedupe: "unique",
11+
methods: {
12+
...common.methods,
13+
getFn() {
14+
return this.suitedash.listContacts;
15+
},
16+
getSummary(contact) {
17+
const firstName = contact.first_name || "";
18+
const lastName = contact.last_name || "";
19+
const fullName = [
20+
firstName,
21+
lastName,
22+
].filter(Boolean).join(" ") || "Unknown";
23+
return `New Contact: ${fullName}`;
24+
},
25+
},
26+
};

0 commit comments

Comments
 (0)