Skip to content

Commit 07cb2a1

Browse files
committed
tave init
1 parent 02197b3 commit 07cb2a1

File tree

8 files changed

+491
-3
lines changed

8 files changed

+491
-3
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import tave from "../../tave.app.mjs";
2+
3+
export default {
4+
key: "tave-create-contact",
5+
name: "Create Contact",
6+
description: "Creates a new contact in the Tave system. [See the documentation](https://tave.io/v2)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
tave,
11+
contact: {
12+
propDefinition: [
13+
tave,
14+
"contact",
15+
],
16+
},
17+
},
18+
async run({ $ }) {
19+
const response = await this.tave.createContact(this.contact);
20+
$.export("$summary", `Successfully created contact with name: ${response.name}`);
21+
return response;
22+
},
23+
};
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import tave from "../../tave.app.mjs";
2+
import { axios } from "@pipedream/platform";
3+
4+
export default {
5+
key: "tave-create-job",
6+
name: "Create Job",
7+
description: "Creates a new job in the Táve system with associated items typically linked with a job. [See the documentation](https://tave.io/v2)",
8+
version: "0.0.{{ts}}",
9+
type: "action",
10+
props: {
11+
tave,
12+
jobDetails: {
13+
propDefinition: [
14+
tave,
15+
"jobDetails",
16+
],
17+
},
18+
additionalItems: {
19+
type: "string",
20+
label: "Additional Items",
21+
description: "Additional items for the job",
22+
optional: true,
23+
},
24+
notes: {
25+
type: "string",
26+
label: "Notes",
27+
description: "Additional notes for the job",
28+
optional: true,
29+
},
30+
instructions: {
31+
type: "string",
32+
label: "Instructions",
33+
description: "Additional instructions for the job",
34+
optional: true,
35+
},
36+
},
37+
async run({ $ }) {
38+
const response = await this.tave.createJob({
39+
...this.jobDetails,
40+
additionalItems: this.additionalItems,
41+
notes: this.notes,
42+
instructions: this.instructions,
43+
});
44+
45+
$.export("$summary", `Successfully created job with specifics: ${this.jobDetails.specifics}`);
46+
return response;
47+
},
48+
};
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import tave from "../../tave.app.mjs";
2+
import { axios } from "@pipedream/platform";
3+
4+
export default {
5+
key: "tave-find-contact",
6+
name: "Find Contact",
7+
description: "Searches for an existing contact in the Tave system. [See the documentation](https://tave.io/v2)",
8+
version: "0.0.{{ts}}",
9+
type: "action",
10+
props: {
11+
tave,
12+
searchContact: {
13+
propDefinition: [
14+
tave,
15+
"searchContact",
16+
],
17+
},
18+
},
19+
async run({ $ }) {
20+
const response = await this.tave.searchContact(this.searchContact);
21+
$.export("$summary", `Successfully found contact(s) based on the query: ${this.searchContact}`);
22+
return response;
23+
},
24+
};

components/tave/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@
1212
"publishConfig": {
1313
"access": "public"
1414
}
15-
}
15+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import tave from "../../tave.app.mjs";
2+
import { axios } from "@pipedream/platform";
3+
4+
export default {
5+
key: "tave-new-contact-instant",
6+
name: "New Contact Created",
7+
description: "Emit new event when a contact is created. [See the documentation](https://tave.io/v2)",
8+
version: "0.0.{{ts}}",
9+
type: "source",
10+
dedupe: "unique",
11+
props: {
12+
tave,
13+
http: {
14+
type: "$.interface.http",
15+
customResponse: false,
16+
},
17+
db: "$.service.db",
18+
clientId: {
19+
propDefinition: [
20+
tave,
21+
"clientId",
22+
],
23+
},
24+
},
25+
methods: {
26+
async _emitWebhookEvent(contact) {
27+
this.$emit(contact, {
28+
id: contact.id,
29+
summary: `New contact created: ${contact.name}`,
30+
ts: contact.createdAt
31+
? Date.parse(contact.createdAt)
32+
: Date.now(),
33+
});
34+
},
35+
_getWebhookId() {
36+
return this.db.get("webhookId");
37+
},
38+
_setWebhookId(id) {
39+
this.db.set("webhookId", id);
40+
},
41+
},
42+
hooks: {
43+
async deploy() {
44+
const events = await this.tave.emitNewContactEvent(this.clientId);
45+
for (const event of events) {
46+
this._emitWebhookEvent(event);
47+
}
48+
},
49+
async activate() {
50+
const hookId = await this.tave.emitNewContactEvent(this.clientId);
51+
this._setWebhookId(hookId);
52+
},
53+
async deactivate() {
54+
const hookId = this._getWebhookId();
55+
if (hookId) {
56+
await this.tave.emitNewContactEvent(this.clientId); // Assuming the method handles the deletion
57+
}
58+
},
59+
},
60+
async run(event) {
61+
const contact = event.body;
62+
this._emitWebhookEvent(contact);
63+
},
64+
};
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
import tave from "../../tave.app.mjs";
2+
import { axios } from "@pipedream/platform";
3+
4+
export default {
5+
key: "tave-new-order-booked-instant",
6+
name: "New Order Booked",
7+
description: "Emit new event when an order is booked, including manually booked orders in manager and electronic bookings in client access. [See the documentation](https://tave.io/v2)",
8+
version: "0.0.{{ts}}",
9+
type: "source",
10+
dedupe: "unique",
11+
props: {
12+
tave,
13+
http: {
14+
type: "$.interface.http",
15+
customResponse: true,
16+
},
17+
db: "$.service.db",
18+
orderId: {
19+
propDefinition: [
20+
tave,
21+
"orderId",
22+
],
23+
},
24+
managerId: {
25+
propDefinition: [
26+
tave,
27+
"managerId",
28+
],
29+
},
30+
clientId: {
31+
propDefinition: [
32+
tave,
33+
"clientId",
34+
],
35+
},
36+
},
37+
methods: {
38+
_getWebhookId() {
39+
return this.db.get("webhookId");
40+
},
41+
_setWebhookId(id) {
42+
this.db.set("webhookId", id);
43+
},
44+
},
45+
hooks: {
46+
async deploy() {
47+
const events = await this.tave.emitNewOrderEvent(this.orderId, this.managerId, this.clientId);
48+
for (const event of events.slice(-50)) {
49+
this.$emit(event, {
50+
id: event.id,
51+
summary: `New order booked with ID ${event.id}`,
52+
ts: Date.parse(event.createdAt),
53+
});
54+
}
55+
},
56+
async activate() {
57+
const hookId = await this.tave.emitNewOrderEvent(this.orderId, this.managerId, this.clientId);
58+
this._setWebhookId(hookId);
59+
},
60+
async deactivate() {
61+
const id = this._getWebhookId();
62+
if (id) {
63+
await this.tave._makeRequest({
64+
method: "DELETE",
65+
path: `/webhooks/${id}`,
66+
});
67+
}
68+
},
69+
},
70+
async run(event) {
71+
const { body } = event;
72+
const expectedSignature = {}; // Add logic to compute expected signature
73+
const webhookSignature = event.headers["x-webhook-signature"];
74+
75+
if (webhookSignature !== expectedSignature) {
76+
this.http.respond({
77+
status: 401,
78+
body: "Unauthorized",
79+
});
80+
return;
81+
}
82+
83+
this.http.respond({
84+
status: 200,
85+
body: "OK",
86+
});
87+
88+
this.$emit(body, {
89+
id: body.orderId,
90+
summary: `Order booked: ${body.orderId}`,
91+
ts: Date.parse(body.createdAt),
92+
});
93+
},
94+
};
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import tave from "../../tave.app.mjs";
2+
import { axios } from "@pipedream/platform";
3+
4+
export default {
5+
key: "tave-new-payment-instant",
6+
name: "New Payment Created",
7+
description: "Emit new event when a new payment is created. [See the documentation](https://tave.io/v2/docs)",
8+
version: "0.0.{{ts}}",
9+
type: "source",
10+
dedupe: "unique",
11+
props: {
12+
tave,
13+
http: {
14+
type: "$.interface.http",
15+
customResponse: false,
16+
},
17+
db: "$.service.db",
18+
paymentId: {
19+
propDefinition: [
20+
tave,
21+
"paymentId",
22+
],
23+
},
24+
orderId: {
25+
propDefinition: [
26+
tave,
27+
"orderId",
28+
],
29+
optional: true,
30+
},
31+
},
32+
methods: {
33+
_getWebhookId() {
34+
return this.db.get("webhookId");
35+
},
36+
_setWebhookId(id) {
37+
this.db.set("webhookId", id);
38+
},
39+
},
40+
hooks: {
41+
async deploy() {
42+
const events = await this.tave.emitNewPaymentEvent(this.paymentId, this.orderId);
43+
for (const event of events) {
44+
this.$emit(event, {
45+
id: event.id,
46+
summary: `Historical payment event for payment ID: ${event.id}`,
47+
ts: Date.now(),
48+
});
49+
}
50+
},
51+
async activate() {
52+
const hookId = await this.tave.emitNewPaymentEvent(this.paymentId, this.orderId);
53+
this._setWebhookId(hookId);
54+
},
55+
async deactivate() {
56+
const hookId = this._getWebhookId();
57+
// Implement the logic to delete the webhook, if supported by the API
58+
},
59+
},
60+
async run(event) {
61+
this.$emit(event.body, {
62+
id: event.body.paymentId,
63+
summary: `New payment created with ID: ${event.body.paymentId}`,
64+
ts: Date.now(),
65+
});
66+
},
67+
};

0 commit comments

Comments
 (0)