@picahq/toolkit 0.1.0
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.
- package/LICENSE +674 -0
- package/README.md +97 -0
- package/dist/apis/action.d.ts +69 -0
- package/dist/apis/action.js +201 -0
- package/dist/apis/available-actions.d.ts +26 -0
- package/dist/apis/available-actions.js +41 -0
- package/dist/apis/available-connectors.d.ts +24 -0
- package/dist/apis/available-connectors.js +40 -0
- package/dist/apis/connections.d.ts +29 -0
- package/dist/apis/connections.js +74 -0
- package/dist/apis/execute.d.ts +42 -0
- package/dist/apis/execute.js +185 -0
- package/dist/index.d.ts +36 -0
- package/dist/index.js +228 -0
- package/dist/prompts/default.d.ts +16 -0
- package/dist/prompts/default.js +114 -0
- package/dist/prompts/knowledge.d.ts +15 -0
- package/dist/prompts/knowledge.js +109 -0
- package/dist/schemas/actions.d.ts +69 -0
- package/dist/schemas/actions.js +43 -0
- package/dist/schemas/connections.d.ts +69 -0
- package/dist/schemas/connections.js +42 -0
- package/dist/schemas/execute.d.ts +128 -0
- package/dist/schemas/execute.js +69 -0
- package/dist/schemas/index.d.ts +3 -0
- package/dist/schemas/index.js +3 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/types/client.d.ts +144 -0
- package/dist/types/client.js +9 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/index.js +2 -0
- package/dist/types/pica.d.ts +133 -0
- package/dist/types/pica.js +9 -0
- package/dist/utils/helpers.d.ts +92 -0
- package/dist/utils/helpers.js +206 -0
- package/dist/utils/index.d.ts +2 -0
- package/dist/utils/index.js +2 -0
- package/dist/utils/log-messages.d.ts +21 -0
- package/dist/utils/log-messages.js +26 -0
- package/package.json +73 -0
package/README.md
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
# Pica ToolKit
|
|
2
|
+
|
|
3
|
+
[](https://npmjs.com/package/@picahq/toolkit)
|
|
4
|
+
|
|
5
|
+
<img src="https://assets.picaos.com/github/pica-toolkit-banner.svg" alt="Pica ToolKit Banner" style="border-radius: 5px;">
|
|
6
|
+
|
|
7
|
+
Pica's ToolKit provides enterprise-grade integration capabilities for AI agents built with the Vercel AI SDK. Through Pica's integration layer, agents can seamlessly interact with third-party services and APIs while maintaining enterprise security, compliance, and reliability standards.
|
|
8
|
+
|
|
9
|
+
## Installation
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm install @picahq/toolkit
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Setup
|
|
16
|
+
|
|
17
|
+
1. Create a new [Pica account](https://app.picaos.com)
|
|
18
|
+
2. Create a Connection via the [Pica Dashboard](https://app.picaos.com/connections)
|
|
19
|
+
3. Create a [Pica API key](https://app.picaos.com/settings/api-keys)
|
|
20
|
+
4. Set the API key as an environment variable: `PICA_SECRET_KEY=<your-api-key>`
|
|
21
|
+
|
|
22
|
+
## Usage
|
|
23
|
+
|
|
24
|
+
The Pica ToolKit seamlessly integrates with [Vercel AI SDK](https://ai-sdk.dev/docs/introduction), enabling powerful AI capabilities in your applications. Below is a simple example showing how to implement it in a Vercel Agent with read-only permissions on a Gmail connection.
|
|
25
|
+
|
|
26
|
+
```typescript
|
|
27
|
+
import { Pica } from '@picahq/ai';
|
|
28
|
+
import { openai } from '@ai-sdk/openai';
|
|
29
|
+
import {
|
|
30
|
+
streamText,
|
|
31
|
+
UIMessage,
|
|
32
|
+
convertToModelMessages,
|
|
33
|
+
stepCountIs
|
|
34
|
+
} from 'ai';
|
|
35
|
+
|
|
36
|
+
export async function POST(req: Request) {
|
|
37
|
+
const { messages }: { messages: UIMessage[] } = await req.json();
|
|
38
|
+
|
|
39
|
+
const pica = new Pica(process.env.PICA_SECRET_KEY!, {
|
|
40
|
+
connectors: ["test::gmail::default::6faf1d3707f846ef89295c836df71c94"],
|
|
41
|
+
permissions: "read"
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
const systemPrompt = await pica.getSystemPrompt();
|
|
45
|
+
|
|
46
|
+
const result = streamText({
|
|
47
|
+
model: openai("gpt-4.1"),
|
|
48
|
+
messages: convertToModelMessages(messages),
|
|
49
|
+
tools: {
|
|
50
|
+
...pica.tools() // Load the Pica ToolKit
|
|
51
|
+
},
|
|
52
|
+
system: systemPrompt,
|
|
53
|
+
stopWhen: stepCountIs(25)
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
return result.toUIMessageStreamResponse();
|
|
57
|
+
}
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
> ⭐️ Experience the Pica ToolKit's capabilities firsthand through our interactive demo chat application [here](https://github.com/picahq/toolkit-demo)
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
## What can Pica do?
|
|
64
|
+
|
|
65
|
+
After installing the SDK and integrating your platforms through the [Pica dashboard](https://app.picaos.com/connections), you can effortlessly create sophisticated AI agents to orchestrate and automate your business workflows.
|
|
66
|
+
|
|
67
|
+

|
|
68
|
+
|
|
69
|
+
Here are some powerful examples use cases:
|
|
70
|
+
|
|
71
|
+
### Communication & Productivity
|
|
72
|
+
- Compose and send Gmail emails containing meeting summaries to team members
|
|
73
|
+
- Schedule Google Calendar events with specified date/time parameters
|
|
74
|
+
- Post messages with campaign analytics to designated Slack channels
|
|
75
|
+
- Search and retrieve Q3 planning materials from Google Drive
|
|
76
|
+
|
|
77
|
+
### Data Access & Analysis
|
|
78
|
+
- Execute PostgreSQL queries to identify top customer segments
|
|
79
|
+
- Generate new Google Sheets workbooks populated with sales metrics
|
|
80
|
+
- Retrieve closing opportunity data from Salesforce CRM
|
|
81
|
+
- Maintain project tracking databases in Notion workspaces
|
|
82
|
+
|
|
83
|
+
### Business Operations
|
|
84
|
+
- Create customer support cases in Zendesk from feedback data
|
|
85
|
+
- Process customer refund transactions via Stripe
|
|
86
|
+
- Convert website inquiries into HubSpot lead entries
|
|
87
|
+
- Generate client invoices through QuickBooks integration
|
|
88
|
+
|
|
89
|
+
### AI & Content
|
|
90
|
+
- Create DALL-E images matching product requirements
|
|
91
|
+
- Convert meeting audio to text using ElevenLabs
|
|
92
|
+
- Conduct market research via Tavily/SerpApi integrations
|
|
93
|
+
- Perform sentiment analysis on support interactions
|
|
94
|
+
|
|
95
|
+
## License
|
|
96
|
+
|
|
97
|
+
This project is licensed under the GPL-3.0 license. See the [LICENSE](LICENSE) file for details.
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pica ToolKit - Actions API
|
|
3
|
+
*
|
|
4
|
+
* This is the actions API for the Pica ToolKit.
|
|
5
|
+
* This API searches for actions on a given platform and also fetches the knowledge for the actions.
|
|
6
|
+
*
|
|
7
|
+
* @fileoverview Actions API for the Pica ToolKit
|
|
8
|
+
* @author Pica
|
|
9
|
+
*/
|
|
10
|
+
import { PicaOptions, PlatformAction, ActionReference, ActionKnowledge, ActionsKnowledgeResponse } from "../types";
|
|
11
|
+
interface SearchPlatformActionsParams {
|
|
12
|
+
baseUrl: string;
|
|
13
|
+
secret: string;
|
|
14
|
+
platform: string;
|
|
15
|
+
query: string;
|
|
16
|
+
options?: PicaOptions;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Search for actions on a given platform
|
|
20
|
+
* @param baseUrl - The base URL of the Pica API
|
|
21
|
+
* @param secret - The Pica API key
|
|
22
|
+
* @param platform - The platform to search actions for
|
|
23
|
+
* @param query - The query to search for
|
|
24
|
+
* @param options - The options for the Pica client
|
|
25
|
+
* @returns The actions found for the platform that match the query
|
|
26
|
+
*/
|
|
27
|
+
export declare function searchPlatformActions({ baseUrl, secret, platform, query, options, }: SearchPlatformActionsParams): Promise<ActionReference[]>;
|
|
28
|
+
/**
|
|
29
|
+
* Clean the actions to return only the actions that match the permissions and allowed actions
|
|
30
|
+
* @param actions - The actions to clean
|
|
31
|
+
* @param options - The options for the Pica client
|
|
32
|
+
* @returns The cleaned actions
|
|
33
|
+
*/
|
|
34
|
+
export declare function clean(actions: PlatformAction[], options?: PicaOptions): ActionReference[];
|
|
35
|
+
interface GetActionsKnowledgeParams {
|
|
36
|
+
baseUrl: string;
|
|
37
|
+
secret: string;
|
|
38
|
+
systemIds: string[];
|
|
39
|
+
options?: PicaOptions;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Get the knowledge for a given system ID
|
|
43
|
+
* @param baseUrl - The base URL of the Pica API
|
|
44
|
+
* @param secret - The Pica API key
|
|
45
|
+
* @param systemIds - The system IDs to get knowledge for
|
|
46
|
+
* @param options - The options for the Pica client
|
|
47
|
+
* @returns The knowledge for the system IDs
|
|
48
|
+
*/
|
|
49
|
+
export declare function getActionsKnowledge({ baseUrl, secret, systemIds, options, }: GetActionsKnowledgeParams): Promise<ActionsKnowledgeResponse>;
|
|
50
|
+
/**
|
|
51
|
+
* Fetch action references for multiple action IDs using Promise.all
|
|
52
|
+
* @param baseUrl - The base URL of the Pica API
|
|
53
|
+
* @param secret - The Pica API key
|
|
54
|
+
* @param platform - The platform to filter actions by
|
|
55
|
+
* @param actionIds - Array of action IDs to fetch references for
|
|
56
|
+
* @param options - The options for the Pica client
|
|
57
|
+
* @returns Array of ActionReference objects filtered by platform
|
|
58
|
+
*/
|
|
59
|
+
export declare function getActionReferences(baseUrl: string, secret: string, platform: string, actionIds: string[], options?: PicaOptions): Promise<ActionReference[]>;
|
|
60
|
+
/**
|
|
61
|
+
* Fetch the action spec for a given system ID
|
|
62
|
+
* @param baseUrl - The base URL of the Pica API
|
|
63
|
+
* @param secret - The Pica API key
|
|
64
|
+
* @param actionSystemId - The system ID of the action to fetch spec for
|
|
65
|
+
* @param options - The options for the Pica client
|
|
66
|
+
* @returns The action method, path, and tags
|
|
67
|
+
*/
|
|
68
|
+
export declare function getActionSpec(baseUrl: string, secret: string, actionSystemId: string, options?: PicaOptions): Promise<ActionKnowledge | null>;
|
|
69
|
+
export {};
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pica ToolKit - Actions API
|
|
3
|
+
*
|
|
4
|
+
* This is the actions API for the Pica ToolKit.
|
|
5
|
+
* This API searches for actions on a given platform and also fetches the knowledge for the actions.
|
|
6
|
+
*
|
|
7
|
+
* @fileoverview Actions API for the Pica ToolKit
|
|
8
|
+
* @author Pica
|
|
9
|
+
*/
|
|
10
|
+
import axios from "axios";
|
|
11
|
+
import { isInitializingWithAllActions, parseSystemId, normalizeActionId } from "../utils";
|
|
12
|
+
const SEARCH_ACTIONS_URL = "/v1/available-actions/search";
|
|
13
|
+
const KNOWLEDGE_URL = "/v1/knowledge";
|
|
14
|
+
/**
|
|
15
|
+
* Search for actions on a given platform
|
|
16
|
+
* @param baseUrl - The base URL of the Pica API
|
|
17
|
+
* @param secret - The Pica API key
|
|
18
|
+
* @param platform - The platform to search actions for
|
|
19
|
+
* @param query - The query to search for
|
|
20
|
+
* @param options - The options for the Pica client
|
|
21
|
+
* @returns The actions found for the platform that match the query
|
|
22
|
+
*/
|
|
23
|
+
export async function searchPlatformActions({ baseUrl, secret, platform, query, options, }) {
|
|
24
|
+
const url = new URL(`${baseUrl}${SEARCH_ACTIONS_URL}/${platform}`);
|
|
25
|
+
url.searchParams.set('query', query);
|
|
26
|
+
url.searchParams.set('limit', '5');
|
|
27
|
+
try {
|
|
28
|
+
const response = await axios.get(url.toString(), {
|
|
29
|
+
headers: {
|
|
30
|
+
"Content-Type": "application/json",
|
|
31
|
+
"x-pica-secret": secret,
|
|
32
|
+
...options?.headers
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
const cleanedActions = clean(response.data, options);
|
|
36
|
+
// If no actions found from search and we have specific action IDs, fetch them directly
|
|
37
|
+
if (cleanedActions.length === 0 && !isInitializingWithAllActions(options?.actions)) {
|
|
38
|
+
return await getActionReferences(baseUrl, secret, platform, options?.actions || [], options);
|
|
39
|
+
}
|
|
40
|
+
return cleanedActions;
|
|
41
|
+
}
|
|
42
|
+
catch (error) {
|
|
43
|
+
throw error;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Clean the actions to return only the actions that match the permissions and allowed actions
|
|
48
|
+
* @param actions - The actions to clean
|
|
49
|
+
* @param options - The options for the Pica client
|
|
50
|
+
* @returns The cleaned actions
|
|
51
|
+
*/
|
|
52
|
+
export function clean(actions, options) {
|
|
53
|
+
const permissionFilteredActions = filterByPermissions(actions, options?.permissions);
|
|
54
|
+
const actionFilteredActions = filterByAllowedActions(permissionFilteredActions, options?.actions);
|
|
55
|
+
return actionFilteredActions.map(action => {
|
|
56
|
+
const fullId = action.systemId;
|
|
57
|
+
const parts = parseSystemId(fullId);
|
|
58
|
+
return {
|
|
59
|
+
title: action.title,
|
|
60
|
+
method: action.method,
|
|
61
|
+
path: action.path,
|
|
62
|
+
systemId: {
|
|
63
|
+
fullId,
|
|
64
|
+
parts
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Filter the actions to return only the actions that match the permissions
|
|
71
|
+
* @param actions - The actions to filter
|
|
72
|
+
* @param permissions - The permissions to filter by
|
|
73
|
+
* @returns The filtered actions
|
|
74
|
+
*/
|
|
75
|
+
function filterByPermissions(actions, permissions) {
|
|
76
|
+
if (!permissions || permissions === "admin") {
|
|
77
|
+
return actions;
|
|
78
|
+
}
|
|
79
|
+
if (permissions === "read") {
|
|
80
|
+
return actions.filter(action => action.method === "GET");
|
|
81
|
+
}
|
|
82
|
+
if (permissions === "write") {
|
|
83
|
+
return actions.filter(action => action.method === "POST" ||
|
|
84
|
+
action.method === "PUT" ||
|
|
85
|
+
action.method === "PATCH");
|
|
86
|
+
}
|
|
87
|
+
return actions;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Filter the actions to return only the actions that are in the allowed actions list
|
|
91
|
+
* @param actions - The actions to filter
|
|
92
|
+
* @param allowedActions - The allowed action systemIds
|
|
93
|
+
* @returns The filtered actions
|
|
94
|
+
*/
|
|
95
|
+
function filterByAllowedActions(actions, allowedActions) {
|
|
96
|
+
if (!allowedActions || allowedActions.length === 0) {
|
|
97
|
+
return [];
|
|
98
|
+
}
|
|
99
|
+
if (isInitializingWithAllActions(allowedActions)) {
|
|
100
|
+
return actions;
|
|
101
|
+
}
|
|
102
|
+
return actions.filter(action => allowedActions.includes(action.systemId));
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Get the knowledge for a given system ID
|
|
106
|
+
* @param baseUrl - The base URL of the Pica API
|
|
107
|
+
* @param secret - The Pica API key
|
|
108
|
+
* @param systemIds - The system IDs to get knowledge for
|
|
109
|
+
* @param options - The options for the Pica client
|
|
110
|
+
* @returns The knowledge for the system IDs
|
|
111
|
+
*/
|
|
112
|
+
export async function getActionsKnowledge({ baseUrl, secret, systemIds, options, }) {
|
|
113
|
+
const knowledgeMap = {};
|
|
114
|
+
const promises = systemIds.map(async (systemId) => {
|
|
115
|
+
try {
|
|
116
|
+
const url = new URL(`${baseUrl}${KNOWLEDGE_URL}`);
|
|
117
|
+
url.searchParams.set('_id', normalizeActionId(systemId));
|
|
118
|
+
const response = await axios.get(url.toString(), {
|
|
119
|
+
headers: {
|
|
120
|
+
"Content-Type": "application/json",
|
|
121
|
+
"x-pica-secret": secret,
|
|
122
|
+
...options?.headers
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
if (response.data.rows && response.data.rows.length > 0) {
|
|
126
|
+
const actionKnowledge = response.data.rows[0];
|
|
127
|
+
knowledgeMap[systemId] = actionKnowledge.knowledge;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
catch (error) {
|
|
131
|
+
console.error(`Error fetching knowledge for action '${systemId}':`, error);
|
|
132
|
+
throw error;
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
await Promise.all(promises);
|
|
136
|
+
return knowledgeMap;
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Fetch action references for multiple action IDs using Promise.all
|
|
140
|
+
* @param baseUrl - The base URL of the Pica API
|
|
141
|
+
* @param secret - The Pica API key
|
|
142
|
+
* @param platform - The platform to filter actions by
|
|
143
|
+
* @param actionIds - Array of action IDs to fetch references for
|
|
144
|
+
* @param options - The options for the Pica client
|
|
145
|
+
* @returns Array of ActionReference objects filtered by platform
|
|
146
|
+
*/
|
|
147
|
+
export async function getActionReferences(baseUrl, secret, platform, actionIds, options) {
|
|
148
|
+
try {
|
|
149
|
+
const promises = actionIds.map(async (actionId) => {
|
|
150
|
+
const actionKnowledge = await getActionSpec(baseUrl, secret, actionId, options);
|
|
151
|
+
if (!actionKnowledge || actionKnowledge.connectionPlatform !== platform) {
|
|
152
|
+
return null;
|
|
153
|
+
}
|
|
154
|
+
const fullId = actionKnowledge._id;
|
|
155
|
+
const parts = parseSystemId(fullId);
|
|
156
|
+
return {
|
|
157
|
+
title: actionKnowledge.title,
|
|
158
|
+
method: actionKnowledge.method,
|
|
159
|
+
path: actionKnowledge.path,
|
|
160
|
+
systemId: { fullId, parts }
|
|
161
|
+
};
|
|
162
|
+
});
|
|
163
|
+
const results = await Promise.all(promises);
|
|
164
|
+
return results.filter((result) => result !== null);
|
|
165
|
+
}
|
|
166
|
+
catch (error) {
|
|
167
|
+
console.error('Error fetching action specs for IDs:', error);
|
|
168
|
+
throw error;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Fetch the action spec for a given system ID
|
|
173
|
+
* @param baseUrl - The base URL of the Pica API
|
|
174
|
+
* @param secret - The Pica API key
|
|
175
|
+
* @param actionSystemId - The system ID of the action to fetch spec for
|
|
176
|
+
* @param options - The options for the Pica client
|
|
177
|
+
* @returns The action method, path, and tags
|
|
178
|
+
*/
|
|
179
|
+
export async function getActionSpec(baseUrl, secret, actionSystemId, options) {
|
|
180
|
+
try {
|
|
181
|
+
const normalizedSystemId = normalizeActionId(actionSystemId);
|
|
182
|
+
const url = new URL(`${baseUrl}${KNOWLEDGE_URL}`);
|
|
183
|
+
url.searchParams.set('_id', normalizedSystemId);
|
|
184
|
+
const response = await axios.get(url.toString(), {
|
|
185
|
+
headers: {
|
|
186
|
+
"Content-Type": "application/json",
|
|
187
|
+
"x-pica-secret": secret,
|
|
188
|
+
...options?.headers
|
|
189
|
+
}
|
|
190
|
+
});
|
|
191
|
+
// Extract knowledge from the first (and only) row
|
|
192
|
+
if (response.data.rows && response.data.rows.length > 0) {
|
|
193
|
+
return response.data.rows[0];
|
|
194
|
+
}
|
|
195
|
+
return null;
|
|
196
|
+
}
|
|
197
|
+
catch (error) {
|
|
198
|
+
console.error(`Error fetching action spec for '${actionSystemId}':`, error);
|
|
199
|
+
throw error;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pica ToolKit - Available Actions API
|
|
3
|
+
*
|
|
4
|
+
* This is the available actions API for the Pica ToolKit.
|
|
5
|
+
* This API lists available actions for a given platform from the Pica API.
|
|
6
|
+
*
|
|
7
|
+
* @fileoverview Available Actions API for the Pica ToolKit
|
|
8
|
+
* @author Pica
|
|
9
|
+
*/
|
|
10
|
+
import { PicaOptions, AvailableAction } from "../types";
|
|
11
|
+
interface GetAvailableActionsParams {
|
|
12
|
+
baseUrl: string;
|
|
13
|
+
secret: string;
|
|
14
|
+
platform: string;
|
|
15
|
+
options?: PicaOptions;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Get the available actions for a given platform
|
|
19
|
+
* @param baseUrl - The base URL of the Pica API
|
|
20
|
+
* @param secret - The Pica API key
|
|
21
|
+
* @param platform - The platform to get available actions for
|
|
22
|
+
* @param options - The options for the Pica client
|
|
23
|
+
* @returns The available actions for the platform
|
|
24
|
+
*/
|
|
25
|
+
export declare function getAvailableActions({ baseUrl, secret, platform, options, }: GetAvailableActionsParams): Promise<AvailableAction[]>;
|
|
26
|
+
export {};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pica ToolKit - Available Actions API
|
|
3
|
+
*
|
|
4
|
+
* This is the available actions API for the Pica ToolKit.
|
|
5
|
+
* This API lists available actions for a given platform from the Pica API.
|
|
6
|
+
*
|
|
7
|
+
* @fileoverview Available Actions API for the Pica ToolKit
|
|
8
|
+
* @author Pica
|
|
9
|
+
*/
|
|
10
|
+
import axios from "axios";
|
|
11
|
+
import { paginateResults } from "../utils";
|
|
12
|
+
const GET_AVAILABLE_ACTIONS_URL = "/v1/available-actions";
|
|
13
|
+
/**
|
|
14
|
+
* Get the available actions for a given platform
|
|
15
|
+
* @param baseUrl - The base URL of the Pica API
|
|
16
|
+
* @param secret - The Pica API key
|
|
17
|
+
* @param platform - The platform to get available actions for
|
|
18
|
+
* @param options - The options for the Pica client
|
|
19
|
+
* @returns The available actions for the platform
|
|
20
|
+
*/
|
|
21
|
+
export async function getAvailableActions({ baseUrl, secret, platform, options, }) {
|
|
22
|
+
const url = new URL(`${baseUrl}${GET_AVAILABLE_ACTIONS_URL}/${platform}`);
|
|
23
|
+
const fetchPage = async (page, limit) => {
|
|
24
|
+
const response = await axios.get(url.toString(), {
|
|
25
|
+
headers: {
|
|
26
|
+
"Content-Type": "application/json",
|
|
27
|
+
"x-pica-secret": secret,
|
|
28
|
+
...options?.headers
|
|
29
|
+
},
|
|
30
|
+
params: { page, limit }
|
|
31
|
+
});
|
|
32
|
+
return response.data;
|
|
33
|
+
};
|
|
34
|
+
try {
|
|
35
|
+
return await paginateResults(fetchPage);
|
|
36
|
+
}
|
|
37
|
+
catch (error) {
|
|
38
|
+
console.error(`Error fetching available actions for platform '${platform}':`, error);
|
|
39
|
+
throw error;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pica ToolKit - Available Connectors API
|
|
3
|
+
*
|
|
4
|
+
* This is the available connectors API for the Pica ToolKit.
|
|
5
|
+
* This API lists available connectors offered by Pica.
|
|
6
|
+
*
|
|
7
|
+
* @fileoverview Available Connectors API for the Pica ToolKit
|
|
8
|
+
* @author Pica
|
|
9
|
+
*/
|
|
10
|
+
import { PicaOptions, Connector } from "../types";
|
|
11
|
+
interface GetAvailableConnectorsParams {
|
|
12
|
+
baseUrl: string;
|
|
13
|
+
secret: string;
|
|
14
|
+
options?: PicaOptions;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Get the available connectors
|
|
18
|
+
* @param baseUrl - The base URL of the Pica API
|
|
19
|
+
* @param secret - The Pica API key
|
|
20
|
+
* @param options - The options for the Pica client
|
|
21
|
+
* @returns The available connectors
|
|
22
|
+
*/
|
|
23
|
+
export declare function getAvailableConnectors({ baseUrl, secret, options, }: GetAvailableConnectorsParams): Promise<Connector[]>;
|
|
24
|
+
export {};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pica ToolKit - Available Connectors API
|
|
3
|
+
*
|
|
4
|
+
* This is the available connectors API for the Pica ToolKit.
|
|
5
|
+
* This API lists available connectors offered by Pica.
|
|
6
|
+
*
|
|
7
|
+
* @fileoverview Available Connectors API for the Pica ToolKit
|
|
8
|
+
* @author Pica
|
|
9
|
+
*/
|
|
10
|
+
import axios from "axios";
|
|
11
|
+
import { paginateResults } from "../utils";
|
|
12
|
+
const GET_AVAILABLE_CONNECTORS_URL = "/v1/available-connectors";
|
|
13
|
+
/**
|
|
14
|
+
* Get the available connectors
|
|
15
|
+
* @param baseUrl - The base URL of the Pica API
|
|
16
|
+
* @param secret - The Pica API key
|
|
17
|
+
* @param options - The options for the Pica client
|
|
18
|
+
* @returns The available connectors
|
|
19
|
+
*/
|
|
20
|
+
export async function getAvailableConnectors({ baseUrl, secret, options, }) {
|
|
21
|
+
const url = new URL(baseUrl + GET_AVAILABLE_CONNECTORS_URL);
|
|
22
|
+
const fetchPage = async (page, limit) => {
|
|
23
|
+
const response = await axios.get(url.toString(), {
|
|
24
|
+
headers: {
|
|
25
|
+
"Content-Type": "application/json",
|
|
26
|
+
"x-pica-secret": secret,
|
|
27
|
+
...options?.headers
|
|
28
|
+
},
|
|
29
|
+
params: { page, limit }
|
|
30
|
+
});
|
|
31
|
+
return response.data;
|
|
32
|
+
};
|
|
33
|
+
try {
|
|
34
|
+
return await paginateResults(fetchPage);
|
|
35
|
+
}
|
|
36
|
+
catch (error) {
|
|
37
|
+
console.error("Error fetching available connectors:", error);
|
|
38
|
+
throw error;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pica ToolKit - Connections API
|
|
3
|
+
*
|
|
4
|
+
* This is the connections API for the Pica ToolKit.
|
|
5
|
+
* This API lists and cleans connections from the Pica Vault API.
|
|
6
|
+
*
|
|
7
|
+
* @fileoverview Connections API for the Pica ToolKit
|
|
8
|
+
* @author Pica
|
|
9
|
+
*/
|
|
10
|
+
import { Connection, PicaOptions, ConnectionReference } from "../types";
|
|
11
|
+
interface ListConnectionsParams {
|
|
12
|
+
baseUrl: string;
|
|
13
|
+
secret: string;
|
|
14
|
+
options?: PicaOptions;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
*
|
|
18
|
+
* @param baseUrl - The base URL of the Pica API
|
|
19
|
+
* @param secret - The Pica API key
|
|
20
|
+
* @param options - The options for the Pica client
|
|
21
|
+
* @returns The connections connected to the Pica account
|
|
22
|
+
*/
|
|
23
|
+
export declare function listConnections({ baseUrl, secret, options, }: ListConnectionsParams): Promise<Connection[]>;
|
|
24
|
+
/**
|
|
25
|
+
* @param connections - The connections to clean
|
|
26
|
+
* @returns The cleaned connections with typed connection references
|
|
27
|
+
*/
|
|
28
|
+
export declare function clean(connections: Connection[]): ConnectionReference[];
|
|
29
|
+
export {};
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pica ToolKit - Connections API
|
|
3
|
+
*
|
|
4
|
+
* This is the connections API for the Pica ToolKit.
|
|
5
|
+
* This API lists and cleans connections from the Pica Vault API.
|
|
6
|
+
*
|
|
7
|
+
* @fileoverview Connections API for the Pica ToolKit
|
|
8
|
+
* @author Pica
|
|
9
|
+
*/
|
|
10
|
+
import axios from "axios";
|
|
11
|
+
import { paginateResults, parseConnectionKey } from "../utils";
|
|
12
|
+
const GET_CONNECTIONS_URL = "/v1/vault/connections";
|
|
13
|
+
/**
|
|
14
|
+
*
|
|
15
|
+
* @param baseUrl - The base URL of the Pica API
|
|
16
|
+
* @param secret - The Pica API key
|
|
17
|
+
* @param options - The options for the Pica client
|
|
18
|
+
* @returns The connections connected to the Pica account
|
|
19
|
+
*/
|
|
20
|
+
export async function listConnections({ baseUrl, secret, options, }) {
|
|
21
|
+
const url = new URL(baseUrl + GET_CONNECTIONS_URL);
|
|
22
|
+
const params = {};
|
|
23
|
+
if (!options?.connectors?.includes("*")) {
|
|
24
|
+
if (options?.connectors?.length) {
|
|
25
|
+
params.keys = options.connectors.join(",");
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
return [];
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
if (options?.identityType) {
|
|
32
|
+
params.identityType = options.identityType;
|
|
33
|
+
}
|
|
34
|
+
if (options?.identity) {
|
|
35
|
+
params.identity = options.identity;
|
|
36
|
+
}
|
|
37
|
+
const fetchPage = async (page, limit) => {
|
|
38
|
+
const response = await axios.get(url.toString(), {
|
|
39
|
+
headers: {
|
|
40
|
+
"Content-Type": "application/json",
|
|
41
|
+
"x-pica-secret": secret,
|
|
42
|
+
...options?.headers
|
|
43
|
+
},
|
|
44
|
+
params: { ...params, page, limit }
|
|
45
|
+
});
|
|
46
|
+
return response.data;
|
|
47
|
+
};
|
|
48
|
+
try {
|
|
49
|
+
return await paginateResults(fetchPage);
|
|
50
|
+
}
|
|
51
|
+
catch (error) {
|
|
52
|
+
console.error("Error fetching user's connections:", error);
|
|
53
|
+
throw error;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* @param connections - The connections to clean
|
|
58
|
+
* @returns The cleaned connections with typed connection references
|
|
59
|
+
*/
|
|
60
|
+
export function clean(connections) {
|
|
61
|
+
return connections
|
|
62
|
+
.filter(conn => conn.active)
|
|
63
|
+
.map(conn => {
|
|
64
|
+
const fullKey = conn.key;
|
|
65
|
+
const parts = parseConnectionKey(fullKey);
|
|
66
|
+
return {
|
|
67
|
+
platform: parts.platform,
|
|
68
|
+
key: {
|
|
69
|
+
fullKey,
|
|
70
|
+
parts
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
});
|
|
74
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pica ToolKit - Execute API
|
|
3
|
+
*
|
|
4
|
+
* This is the execute API for the Pica ToolKit.
|
|
5
|
+
* This API executes actions on connected platforms via the Pica Passthrough API.
|
|
6
|
+
*
|
|
7
|
+
* @fileoverview Execute API for the Pica ToolKit
|
|
8
|
+
* @author Pica
|
|
9
|
+
*/
|
|
10
|
+
import { PicaOptions, ExecuteActionResponse } from "../types";
|
|
11
|
+
interface ExecuteActionParams {
|
|
12
|
+
baseUrl: string;
|
|
13
|
+
secret: string;
|
|
14
|
+
actionSystemId: string;
|
|
15
|
+
connectionKey: string;
|
|
16
|
+
data?: any;
|
|
17
|
+
pathVariables?: Record<string, string | number | boolean>;
|
|
18
|
+
queryParams?: Record<string, any>;
|
|
19
|
+
headers?: Record<string, any>;
|
|
20
|
+
isFormData?: boolean;
|
|
21
|
+
isFormUrlEncoded?: boolean;
|
|
22
|
+
returnRequestConfigWithoutExecution?: boolean;
|
|
23
|
+
options?: PicaOptions;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Execute an action
|
|
27
|
+
* @param baseUrl - The base URL of the Pica API
|
|
28
|
+
* @param secret - The Pica API key
|
|
29
|
+
* @param actionSystemId - The system ID of the action to execute
|
|
30
|
+
* @param connectionKey - The connection key to use for executing the action
|
|
31
|
+
* @param data - The data to execute the action with
|
|
32
|
+
* @param pathVariables - The path variables to execute the action with
|
|
33
|
+
* @param queryParams - The query parameters to execute the action with
|
|
34
|
+
* @param headers - The headers to execute the action with
|
|
35
|
+
* @param isFormData - Whether to execute the action as a form data request
|
|
36
|
+
* @param isFormUrlEncoded - Whether to execute the action as a form urlencoded request
|
|
37
|
+
* @param returnRequestConfigWithoutExecution - Whether to return request config without executing
|
|
38
|
+
* @param options - The options for the Pica client
|
|
39
|
+
* @returns The response from the action
|
|
40
|
+
*/
|
|
41
|
+
export declare function executeAction({ baseUrl, secret, actionSystemId, connectionKey, data, pathVariables, queryParams, headers, isFormData, isFormUrlEncoded, returnRequestConfigWithoutExecution, options, }: ExecuteActionParams): Promise<ExecuteActionResponse>;
|
|
42
|
+
export {};
|