@agnocon/piece-bookedin 0.1.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/LICENSE.MIT-AP +24 -0
  2. package/dist/index.d.ts +2 -0
  3. package/dist/index.d.ts.map +1 -0
  4. package/dist/index.js +48 -0
  5. package/dist/index.js.map +1 -0
  6. package/dist/lib/actions/bulk-delete-leads.d.ts +4 -0
  7. package/dist/lib/actions/bulk-delete-leads.d.ts.map +1 -0
  8. package/dist/lib/actions/bulk-delete-leads.js +41 -0
  9. package/dist/lib/actions/bulk-delete-leads.js.map +1 -0
  10. package/dist/lib/actions/create-lead.d.ts +7 -0
  11. package/dist/lib/actions/create-lead.d.ts.map +1 -0
  12. package/dist/lib/actions/create-lead.js +59 -0
  13. package/dist/lib/actions/create-lead.js.map +1 -0
  14. package/dist/lib/actions/delete-lead.d.ts +4 -0
  15. package/dist/lib/actions/delete-lead.d.ts.map +1 -0
  16. package/dist/lib/actions/delete-lead.js +33 -0
  17. package/dist/lib/actions/delete-lead.js.map +1 -0
  18. package/dist/lib/actions/get-lead-stats.d.ts +2 -0
  19. package/dist/lib/actions/get-lead-stats.d.ts.map +1 -0
  20. package/dist/lib/actions/get-lead-stats.js +31 -0
  21. package/dist/lib/actions/get-lead-stats.js.map +1 -0
  22. package/dist/lib/actions/get-lead.d.ts +4 -0
  23. package/dist/lib/actions/get-lead.d.ts.map +1 -0
  24. package/dist/lib/actions/get-lead.js +33 -0
  25. package/dist/lib/actions/get-lead.js.map +1 -0
  26. package/dist/lib/actions/get-leads.d.ts +9 -0
  27. package/dist/lib/actions/get-leads.d.ts.map +1 -0
  28. package/dist/lib/actions/get-leads.js +78 -0
  29. package/dist/lib/actions/get-leads.js.map +1 -0
  30. package/dist/lib/actions/update-lead.d.ts +10 -0
  31. package/dist/lib/actions/update-lead.d.ts.map +1 -0
  32. package/dist/lib/actions/update-lead.js +86 -0
  33. package/dist/lib/actions/update-lead.js.map +1 -0
  34. package/dist/lib/auth.d.ts +2 -0
  35. package/dist/lib/auth.d.ts.map +1 -0
  36. package/dist/lib/auth.js +54 -0
  37. package/dist/lib/auth.js.map +1 -0
  38. package/dist/lib/common/props.d.ts +9 -0
  39. package/dist/lib/common/props.d.ts.map +1 -0
  40. package/dist/lib/common/props.js +125 -0
  41. package/dist/lib/common/props.js.map +1 -0
  42. package/package.json +46 -0
  43. package/src/index.ts +43 -0
  44. package/src/lib/actions/bulk-delete-leads.ts +40 -0
  45. package/src/lib/actions/create-lead.ts +57 -0
  46. package/src/lib/actions/delete-lead.ts +27 -0
  47. package/src/lib/actions/get-lead-stats.ts +25 -0
  48. package/src/lib/actions/get-lead.ts +27 -0
  49. package/src/lib/actions/get-leads.ts +69 -0
  50. package/src/lib/actions/update-lead.ts +92 -0
  51. package/src/lib/auth.ts +48 -0
  52. package/src/lib/common/props.ts +138 -0
@@ -0,0 +1,48 @@
1
+ import { PieceAuth } from '@agnocon/pieces-framework';
2
+ import { httpClient, HttpMethod } from '@agnocon/pieces-common';
3
+ import { BASE_URL, extractApiKey } from './common/props';
4
+
5
+ export const bookedinAuth = PieceAuth.SecretText({
6
+ displayName: 'API Key',
7
+ required: true,
8
+ description: `To connect your Bookedin account, please follow these steps to retrieve your API Key:
9
+
10
+ 1. Log in to your Bookedin Dashboard: dashboard.bookedin.ai
11
+ 2. From the left menu, go to **Business**
12
+ 3. Open **Settings**
13
+ 4. Click on **API Key**
14
+ 5. Copy your API Key (starts with **sk_…**)
15
+ 6. Paste the key below to authorize the integration
16
+
17
+ Your API Key allows Activepieces to securely access your Bookedin leads, agents, and booking data.
18
+ `,
19
+ validate: async ({ auth }) => {
20
+ try {
21
+ const apiKey = extractApiKey(auth);
22
+
23
+ if (!apiKey) {
24
+ return { valid: false, error: 'API Key is empty' };
25
+ }
26
+
27
+ await httpClient.sendRequest({
28
+ method: HttpMethod.GET,
29
+ url: `${BASE_URL}/agents/`,
30
+ headers: {
31
+ 'X-API-Key': apiKey as string,
32
+ 'accept': 'application/json'
33
+ },
34
+ queryParams: {
35
+ skip: '0',
36
+ limit: '1'
37
+ }
38
+ });
39
+ return { valid: true };
40
+ } catch (e: any) {
41
+ const errorMessage = e?.response?.body?.detail || e?.message || 'Connection failed';
42
+ return {
43
+ valid: false,
44
+ error: errorMessage
45
+ };
46
+ }
47
+ },
48
+ });
@@ -0,0 +1,138 @@
1
+ import { Property } from '@agnocon/pieces-framework';
2
+ import { httpClient, HttpMethod } from '@agnocon/pieces-common';
3
+ import { bookedinAuth } from '../auth';
4
+
5
+ export const BASE_URL = 'https://api.bookedin.ai/api/v1';
6
+
7
+ export const getBookedinHeaders = (apiKey: string) => {
8
+ return {
9
+ 'X-API-Key': apiKey,
10
+ 'accept': 'application/json',
11
+ };
12
+ };
13
+
14
+
15
+ export const extractApiKey = (auth: unknown): string => {
16
+ if (typeof auth === 'string') {
17
+ return auth;
18
+ }
19
+ const authObj = auth as { secret_text?: string; auth?: string };
20
+ return authObj?.secret_text || authObj?.auth || '';
21
+ };
22
+
23
+
24
+ const fetchLeadOptions = async (apiKey: string) => {
25
+ const response = await httpClient.sendRequest<{
26
+ items: Array<{
27
+ id: string;
28
+ contact: {
29
+ name: {
30
+ first: string;
31
+ last: string;
32
+ };
33
+ email: string;
34
+ };
35
+ }>;
36
+ }>({
37
+ method: HttpMethod.GET,
38
+ url: `${BASE_URL}/leads/`,
39
+ headers: getBookedinHeaders(apiKey),
40
+ queryParams: {
41
+ limit: '100',
42
+ skip: '0',
43
+ },
44
+ });
45
+
46
+ return response.body.items.map((lead) => {
47
+ const firstName = lead.contact?.name?.first || '';
48
+ const lastName = lead.contact?.name?.last || '';
49
+ const email = lead.contact?.email || '';
50
+ const name = [firstName, lastName].filter(Boolean).join(' ').trim();
51
+ const label = name ? `${name} (${email})` : email || lead.id;
52
+
53
+ return {
54
+ label,
55
+ value: lead.id,
56
+ };
57
+ });
58
+ };
59
+
60
+ export const leadIdDropdown = Property.Dropdown({
61
+ auth: bookedinAuth,
62
+ displayName: 'Lead',
63
+ description: 'Select a lead',
64
+ required: true,
65
+ refreshers: [],
66
+ options: async ({ auth }) => {
67
+ if (!auth) {
68
+ return {
69
+ disabled: true,
70
+ placeholder: 'Please connect your account first',
71
+ options: [],
72
+ };
73
+ }
74
+
75
+ try {
76
+ const apiKey = extractApiKey(auth);
77
+ if (!apiKey) {
78
+ return {
79
+ disabled: true,
80
+ placeholder: 'API key is missing',
81
+ options: [],
82
+ };
83
+ }
84
+
85
+ const options = await fetchLeadOptions(apiKey);
86
+ return {
87
+ disabled: false,
88
+ options,
89
+ };
90
+ } catch (error) {
91
+ return {
92
+ disabled: true,
93
+ placeholder: 'Failed to load leads. Please check your connection.',
94
+ options: [],
95
+ };
96
+ }
97
+ },
98
+ });
99
+
100
+ export const leadIdsMultiSelectDropdown = Property.MultiSelectDropdown({
101
+ auth: bookedinAuth,
102
+ displayName: 'Leads',
103
+ description: 'Select leads to delete (max 500)',
104
+ required: true,
105
+ refreshers: [],
106
+ options: async ({ auth }) => {
107
+ if (!auth) {
108
+ return {
109
+ disabled: true,
110
+ placeholder: 'Please connect your account first',
111
+ options: [],
112
+ };
113
+ }
114
+
115
+ try {
116
+ const apiKey = extractApiKey(auth);
117
+ if (!apiKey) {
118
+ return {
119
+ disabled: true,
120
+ placeholder: 'API key is missing',
121
+ options: [],
122
+ };
123
+ }
124
+
125
+ const options = await fetchLeadOptions(apiKey);
126
+ return {
127
+ disabled: false,
128
+ options,
129
+ };
130
+ } catch (error) {
131
+ return {
132
+ disabled: true,
133
+ placeholder: 'Failed to load leads. Please check your connection.',
134
+ options: [],
135
+ };
136
+ }
137
+ },
138
+ });