Skip to content

Commit 539ae0c

Browse files
committed
new components
1 parent ff53669 commit 539ae0c

File tree

5 files changed

+75
-80
lines changed

5 files changed

+75
-80
lines changed

components/cliento/actions/get-ref-data/get-ref-data.mjs

Lines changed: 5 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -3,50 +3,17 @@ import cliento from "../../cliento.app.mjs";
33
export default {
44
key: "cliento-get-ref-data",
55
name: "Get Reference Data",
6-
description: "Fetch services, resources and mappings for the booking widget",
7-
version: "0.0.{{ts}}",
6+
description: "Fetch services, resources and mappings for the booking widget. [See the documentation](https://developers.cliento.com/docs/rest-api#fetch-ref-data)",
7+
version: "0.0.1",
88
type: "action",
99
props: {
1010
cliento,
11-
fromDate: {
12-
propDefinition: [
13-
cliento,
14-
"fromDate",
15-
],
16-
},
17-
toDate: {
18-
propDefinition: [
19-
cliento,
20-
"toDate",
21-
],
22-
},
23-
resourceIds: {
24-
propDefinition: [
25-
cliento,
26-
"resourceIds",
27-
],
28-
},
29-
serviceIds: {
30-
propDefinition: [
31-
cliento,
32-
"serviceIds",
33-
],
34-
},
3511
},
3612
async run({ $ }) {
37-
const settings = await this.cliento.fetchSettings();
38-
const refData = await this.cliento.fetchRefData();
39-
const slots = await this.cliento.fetchSlots({
40-
fromDate: this.fromDate,
41-
toDate: this.toDate,
42-
resourceIds: this.resourceIds,
43-
serviceIds: this.serviceIds,
13+
const response = await this.cliento.fetchRefData({
14+
$,
4415
});
4516
$.export("$summary", "Successfully fetched reference data");
46-
return {
47-
settings,
48-
refData,
49-
slots,
50-
};
17+
return response;
5118
},
5219
};

components/cliento/actions/get-settings/get-settings.mjs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,16 @@ import cliento from "../../cliento.app.mjs";
33
export default {
44
key: "cliento-get-settings",
55
name: "Fetch Settings",
6-
description: "Fetch settings and features for the booking widget",
7-
version: "0.0.{{ts}}",
6+
description: "Fetch settings and features for the booking widget. [See the documentation](https://developers.cliento.com/docs/rest-api#fetch-settings)",
7+
version: "0.0.1",
88
type: "action",
99
props: {
1010
cliento,
1111
},
1212
async run({ $ }) {
13-
const response = await this.cliento.fetchSettings();
13+
const response = await this.cliento.fetchSettings({
14+
$,
15+
});
1416
$.export("$summary", "Successfully fetched settings");
1517
return response;
1618
},

components/cliento/actions/get-slots/get-slots.mjs

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,36 +3,51 @@ import cliento from "../../cliento.app.mjs";
33
export default {
44
key: "cliento-get-slots",
55
name: "Get Slots",
6-
description: "Fetch available slots for the given service, resource and dates",
7-
version: "0.0.{{ts}}",
6+
description: "Fetch available slots for the given service, resource and dates. [See the documentation](https://developers.cliento.com/docs/rest-api#fetch-slots)",
7+
version: "0.0.1",
88
type: "action",
99
props: {
1010
cliento,
1111
fromDate: {
12-
...cliento.propDefinitions.fromDate,
13-
description: "The start date for the booking period (format: YYYY-MM-DD)",
12+
propDefinition: [
13+
cliento,
14+
"fromDate",
15+
],
1416
},
1517
toDate: {
16-
...cliento.propDefinitions.toDate,
17-
description: "The end date for the booking period (format: YYYY-MM-DD)",
18+
propDefinition: [
19+
cliento,
20+
"toDate",
21+
],
1822
},
1923
resourceIds: {
20-
...cliento.propDefinitions.resourceIds,
21-
description: "The IDs of the resources for the booking",
24+
propDefinition: [
25+
cliento,
26+
"resourceIds",
27+
],
2228
},
2329
serviceIds: {
24-
...cliento.propDefinitions.serviceIds,
25-
description: "The IDs of the services for the booking",
30+
propDefinition: [
31+
cliento,
32+
"serviceIds",
33+
],
2634
},
2735
},
2836
async run({ $ }) {
29-
const slots = await this.cliento.fetchSlots({
30-
fromDate: this.fromDate,
31-
toDate: this.toDate,
32-
resourceIds: this.resourceIds,
33-
serviceIds: this.serviceIds,
37+
const response = await this.cliento.fetchSlots({
38+
$,
39+
params: {
40+
fromDate: this.fromDate,
41+
toDate: this.toDate,
42+
resIds: this.resourceIds.join(),
43+
srvIds: this.serviceIds.join(),
44+
},
3445
});
35-
$.export("$summary", `Successfully fetched ${slots.length} slots`);
36-
return slots;
46+
if (response?.length) {
47+
$.export("$summary", `Successfully fetched ${response.length} slot${response.length === 1
48+
? ""
49+
: "s"}`);
50+
}
51+
return response;
3752
},
3853
};

components/cliento/cliento.app.mjs

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -18,57 +18,65 @@ export default {
1818
type: "string[]",
1919
label: "Resource IDs",
2020
description: "The IDs of the resources for the booking",
21+
async options() {
22+
const { resources } = await this.fetchRefData();
23+
return resources?.map(({
24+
id: value, name: label,
25+
}) => ({
26+
value,
27+
label,
28+
})) || [];
29+
},
2130
},
2231
serviceIds: {
2332
type: "string[]",
2433
label: "Service IDs",
2534
description: "The IDs of the services for the booking",
35+
async options() {
36+
const { services } = await this.fetchRefData();
37+
return services?.map(({
38+
serviceId: value, name: label,
39+
}) => ({
40+
value,
41+
label,
42+
})) || [];
43+
},
2644
},
2745
},
2846
methods: {
2947
_baseUrl() {
30-
return "https://api.cliento.com";
48+
return `https://cliento.com/api/v2/partner/cliento/${this.$auth.account_id}`;
3149
},
32-
async _makeRequest(opts = {}) {
50+
_makeRequest(opts = {}) {
3351
const {
3452
$ = this,
35-
method = "GET",
3653
path,
37-
headers,
3854
...otherOpts
3955
} = opts;
4056
return axios($, {
4157
...otherOpts,
42-
method,
43-
url: this._baseUrl() + path,
58+
url: `${this._baseUrl()}${path}`,
4459
headers: {
45-
...headers,
46-
"Authorization": `Bearer ${this.$auth.oauth_access_token}`,
60+
Accept: "application/json",
4761
},
4862
});
4963
},
50-
async fetchSettings() {
64+
fetchSettings(opts = {}) {
5165
return this._makeRequest({
5266
path: "/settings/",
67+
...opts,
5368
});
5469
},
55-
async fetchRefData() {
70+
fetchRefData(opts = {}) {
5671
return this._makeRequest({
5772
path: "/ref-data/",
73+
...opts,
5874
});
5975
},
60-
async fetchSlots({
61-
fromDate, toDate, resourceIds, serviceIds,
62-
}) {
63-
const params = {
64-
fromDate,
65-
toDate,
66-
resIds: resourceIds.join(","),
67-
srvIds: serviceIds.join(","),
68-
};
76+
fetchSlots(opts = {}) {
6977
return this._makeRequest({
7078
path: "/resources/slots",
71-
params,
79+
...opts,
7280
});
7381
},
7482
},

components/cliento/package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/cliento",
3-
"version": "0.0.1",
3+
"version": "0.1.0",
44
"description": "Pipedream Cliento Components",
55
"main": "cliento.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.0.3"
1417
}
15-
}
18+
}

0 commit comments

Comments
 (0)