Skip to content

Commit 8a4945f

Browse files
committed
wip
1 parent 577bd0f commit 8a4945f

File tree

7 files changed

+470
-7
lines changed

7 files changed

+470
-7
lines changed
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
import bookingExperts from "../../booking_experts.app.mjs";
2+
3+
export default {
4+
key: "booking_experts-list-bookings",
5+
name: "List Bookings",
6+
description: "Returns a list of bookings for an administration. [See the documentation](https://developers.bookingexperts.com/reference/administration-bookings-index)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
bookingExperts,
11+
administrationId: {
12+
propDefinition: [
13+
bookingExperts,
14+
"administrationId",
15+
],
16+
},
17+
ownerId: {
18+
propDefinition: [
19+
bookingExperts,
20+
"ownerId",
21+
(c) => ({
22+
administrationId: c.administrationId,
23+
}),
24+
],
25+
description: "Filter by owner",
26+
},
27+
channelId: {
28+
propDefinition: [
29+
bookingExperts,
30+
"channelId",
31+
(c) => ({
32+
administrationId: c.administrationId,
33+
}),
34+
],
35+
description: "Filter by channel",
36+
},
37+
reservationId: {
38+
propDefinition: [
39+
bookingExperts,
40+
"reservationId",
41+
(c) => ({
42+
administrationId: c.administrationId,
43+
}),
44+
],
45+
description: "Filter by reservation",
46+
},
47+
createdAt: {
48+
type: "string",
49+
label: "Created At",
50+
description: "Filter by created at date. Example: `2025-08-28`",
51+
optional: true,
52+
},
53+
updatedAt: {
54+
type: "string",
55+
label: "Updated At",
56+
description: "Filter by updated at date. Example: `2025-08-28`",
57+
optional: true,
58+
},
59+
page: {
60+
type: "integer",
61+
label: "Page",
62+
description: "Page number",
63+
optional: true,
64+
},
65+
perPage: {
66+
type: "integer",
67+
label: "Per Page",
68+
description: "Number of items per page",
69+
max: 100,
70+
optional: true,
71+
},
72+
},
73+
async run({ $ }) {
74+
const { data } = await this.bookingExperts.listBookings({
75+
$,
76+
administrationId: this.administrationId,
77+
params: {
78+
"filter[owner]": this.ownerId,
79+
"filter[channel]": this.channelId,
80+
"filter[reservations]": this.reservationId,
81+
"filter[created_at]": this.createdAt,
82+
"filter[updated_at]": this.updatedAt,
83+
"page[number]": this.page,
84+
"page[size]": this.perPage,
85+
},
86+
});
87+
$.export("$summary", `Found ${data.length} bookings`);
88+
return data;
89+
},
90+
};
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import bookingExperts from "../../booking_experts.app.mjs";
2+
import { ConfigurationError } from "@pipedream/platform";
3+
4+
export default {
5+
key: "booking_experts-search-contacts",
6+
name: "Search Contacts",
7+
description: "Search for contacts by name or email. [See the documentation](https://developers.bookingexperts.com/reference/contact-search-first)",
8+
version: "0.0.1",
9+
type: "action",
10+
props: {
11+
bookingExperts,
12+
email: {
13+
type: "string",
14+
label: "Email",
15+
description: "The email of the contact to search for",
16+
optional: true,
17+
},
18+
phone: {
19+
type: "string",
20+
label: "Phone",
21+
description: "The phone number of the contact to search for",
22+
optional: true,
23+
},
24+
},
25+
async run({ $ }) {
26+
if (!this.email && !this.phone) {
27+
throw new ConfigurationError("Either email or phone must be provided");
28+
}
29+
30+
try {
31+
const { data } = await this.bookingExperts.searchContacts({
32+
params: {
33+
email: this.email,
34+
phone: this.phone,
35+
},
36+
});
37+
if (data?.id) {
38+
$.export("$summary", "Found contact matching criteria");
39+
}
40+
return data;
41+
} catch (error) {
42+
if (error.response?.status === 404) {
43+
$.export("$summary", "No contact found matching criteria");
44+
return;
45+
}
46+
throw error;
47+
}
48+
},
49+
};
Lines changed: 147 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,153 @@
1+
import { axios } from "@pipedream/platform";
2+
13
export default {
24
type: "app",
35
app: "booking_experts",
4-
propDefinitions: {},
6+
propDefinitions: {
7+
administrationId: {
8+
type: "string",
9+
label: "Administration ID",
10+
description: "The ID of the administration",
11+
async options({ page }) {
12+
const { data } = await this.listAdministrations({
13+
params: {
14+
"page[number]": page + 1,
15+
},
16+
});
17+
return data?.map(({
18+
id, attributes,
19+
}) => ({
20+
label: attributes.name,
21+
value: id,
22+
})) || [];
23+
},
24+
},
25+
ownerId: {
26+
type: "string",
27+
label: "Owner ID",
28+
description: "The ID of an owner",
29+
optional: true,
30+
async options({
31+
page, administrationId,
32+
}) {
33+
const { data } = await this.listOwners({
34+
administrationId,
35+
params: {
36+
"page[number]": page + 1,
37+
},
38+
});
39+
return data?.map(({
40+
id, attributes,
41+
}) => ({
42+
label: attributes.first_name + " " + attributes.last_name,
43+
value: id,
44+
})) || [];
45+
},
46+
},
47+
channelId: {
48+
type: "string",
49+
label: "Channel ID",
50+
description: "The ID of a channel",
51+
optional: true,
52+
async options({
53+
page, administrationId,
54+
}) {
55+
const { data } = await this.listChannels({
56+
administrationId,
57+
params: {
58+
"page[number]": page + 1,
59+
},
60+
});
61+
return data?.map(({
62+
id, attributes,
63+
}) => ({
64+
label: attributes.name,
65+
value: id,
66+
})) || [];
67+
},
68+
},
69+
reservationId: {
70+
type: "string",
71+
label: "Reservation ID",
72+
description: "The ID of a reservation",
73+
optional: true,
74+
async options({
75+
page, administrationId,
76+
}) {
77+
const { data } = await this.listReservations({
78+
administrationId,
79+
params: {
80+
"page[number]": page + 1,
81+
},
82+
});
83+
return data?.map(({
84+
id, attributes,
85+
}) => ({
86+
label: `${attributes.start_date} - ${attributes.end_date}`,
87+
value: id,
88+
})) || [];
89+
},
90+
},
91+
},
592
methods: {
6-
// this.$auth contains connected account data
7-
authKeys() {
8-
console.log(Object.keys(this.$auth));
93+
_baseUrl() {
94+
return "https://api.bookingexperts.com/v3";
95+
},
96+
_makeRequest({
97+
$ = this, path, ...opts
98+
}) {
99+
return axios($, {
100+
url: `${this._baseUrl()}${path}`,
101+
headers: {
102+
"x-api-key": `${this.$auth.api_key}`,
103+
"accept": "application/vnd.api+json",
104+
},
105+
...opts,
106+
});
107+
},
108+
listAdministrations(opts = {}) {
109+
return this._makeRequest({
110+
path: "/administrations",
111+
...opts,
112+
});
113+
},
114+
listBookings({
115+
administrationId, ...opts
116+
}) {
117+
return this._makeRequest({
118+
path: `/administrations/${administrationId}/bookings`,
119+
...opts,
120+
});
121+
},
122+
listOwners({
123+
administrationId, ...opts
124+
}) {
125+
return this._makeRequest({
126+
path: `/administrations/${administrationId}/owners`,
127+
...opts,
128+
});
129+
},
130+
listChannels({
131+
administrationId, ...opts
132+
}) {
133+
return this._makeRequest({
134+
path: `/administrations/${administrationId}/channels`,
135+
...opts,
136+
});
137+
},
138+
listReservations({
139+
administrationId, ...opts
140+
}) {
141+
return this._makeRequest({
142+
path: `/administrations/${administrationId}/reservations`,
143+
...opts,
144+
});
145+
},
146+
searchContacts(opts = {}) {
147+
return this._makeRequest({
148+
path: "/contacts/search/first",
149+
...opts,
150+
});
9151
},
10152
},
11-
};
153+
};

components/booking_experts/package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/booking_experts",
3-
"version": "0.0.1",
3+
"version": "0.1.0",
44
"description": "Pipedream Booking Experts Components",
55
"main": "booking_experts.app.mjs",
66
"keywords": [
@@ -11,5 +11,8 @@
1111
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
1212
"publishConfig": {
1313
"access": "public"
14+
},
15+
"dependencies": {
16+
"@pipedream/platform": "^3.1.0"
1417
}
15-
}
18+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import common from "../common/base-polling.mjs";
2+
3+
export default {
4+
...common,
5+
key: "booking_experts-booking-updated",
6+
name: "Booking Updated",
7+
description: "Emit new event for each booking updated. [See the documentation](https://developers.bookingexperts.com/reference/administration-bookings-index)",
8+
version: "0.0.1",
9+
type: "source",
10+
dedupe: "unique",
11+
props: {
12+
...common.props,
13+
administrationId: {
14+
propDefinition: [
15+
common.props.bookingExperts,
16+
"administrationId",
17+
],
18+
},
19+
},
20+
methods: {
21+
...common.methods,
22+
getResourceFn() {
23+
return this.bookingExperts.listBookings;
24+
},
25+
getArgs() {
26+
return {
27+
administrationId: this.administrationId,
28+
params: {
29+
sort: "-updated_at",
30+
},
31+
};
32+
},
33+
getTsField() {
34+
return "updated_at";
35+
},
36+
generateMeta(booking) {
37+
return {
38+
id: booking.id,
39+
summary: `Booking updated: ${booking.id}`,
40+
ts: Date.parse(booking.attributes.updated_at),
41+
};
42+
},
43+
},
44+
};

0 commit comments

Comments
 (0)