@entergreat/unipile-wrapper 1.0.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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Niv Kaufman
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,143 @@
1
+ # Unipile Wrapper
2
+
3
+ ## Overview 🌐
4
+ A lightweight JavaScript wrapper for Unipile's social network automation platform. This wrapper simplifies the interaction with Unipile's API, currently focusing on LinkedIn automation features. The wrapper provides an easy-to-use interface for common LinkedIn operations while handling the underlying API communication with Unipile.
5
+
6
+ ## Features ✨
7
+ - Simplified interface for Unipile's LinkedIn API
8
+ - Easy account connection using li_at cookies
9
+ - Streamlined search capabilities (URL-based and parameter-based)
10
+ - Built-in pagination support
11
+ - Clean error handling
12
+ - Promise-based async/await interface
13
+
14
+ ## Prerequisites 📋
15
+ - An active Unipile account
16
+ - Unipile API token
17
+ - Access to a Unipile subdomain and port
18
+
19
+ ## Installation 🛠️
20
+ ```bash
21
+ npm install @entergreat/unipile-wrapper
22
+ ```
23
+
24
+ ## Configuration ⚙️
25
+ Initialize the wrapper with your Unipile credentials:
26
+
27
+ ```javascript
28
+ import { LinkedinService } from 'unipile-linkedin-wrapper';
29
+
30
+ const linkedinService = new LinkedinService({
31
+ unipileToken: 'your-unipile-token',
32
+ subdomain: 'your-subdomain',
33
+ port: 'port-number'
34
+ });
35
+ ```
36
+
37
+ ## Usage 🚀
38
+
39
+ ### Connect LinkedIn Account
40
+ Add a LinkedIn account to Unipile using a li_at cookie:
41
+
42
+ ```javascript
43
+ try {
44
+ const account = await linkedinService.connect({
45
+ loginCookie: 'your-li-at-cookie'
46
+ });
47
+ console.log('Successfully connected account to Unipile:', account);
48
+ } catch (error) {
49
+ console.error('Connection failed:', error);
50
+ }
51
+ ```
52
+
53
+ ### Search LinkedIn
54
+ #### Using Parameters
55
+ ```javascript
56
+ const searchParams = {
57
+ keywords: 'software engineer',
58
+ location: 'United States',
59
+ // Additional LinkedIn search parameters
60
+ };
61
+
62
+ try {
63
+ const results = await linkedinService.searchByParams({
64
+ accountId: 'your-unipile-account-id',
65
+ params: searchParams,
66
+ cursor: '', // for pagination
67
+ limit: 10
68
+ });
69
+ console.log('Search results:', results);
70
+ } catch (error) {
71
+ console.error('Search failed:', error);
72
+ }
73
+ ```
74
+
75
+ #### Using LinkedIn URL
76
+ ```javascript
77
+ try {
78
+ const results = await linkedinService.searchByUrl({
79
+ accountId: 'your-unipile-account-id',
80
+ searchUrl: 'linkedin-search-url',
81
+ cursor: '', // for pagination
82
+ limit: 10
83
+ });
84
+ console.log('Search results:', results);
85
+ } catch (error) {
86
+ console.error('Search failed:', error);
87
+ }
88
+ ```
89
+
90
+ ## API Reference 📚
91
+
92
+ ### LinkedinService
93
+
94
+ #### Constructor
95
+ ```javascript
96
+ new LinkedinService({
97
+ unipileToken: string, // Your Unipile API token
98
+ subdomain: string, // Your Unipile subdomain
99
+ port: number // Unipile port number
100
+ })
101
+ ```
102
+
103
+ #### Methods
104
+
105
+ ##### connect({ loginCookie: string })
106
+ Connects a LinkedIn account to Unipile using a li_at cookie.
107
+ - **Parameters:**
108
+ - `loginCookie`: LinkedIn li_at cookie value
109
+ - **Returns:** Promise with Unipile account connection details
110
+
111
+ ##### searchByParams({ accountId: string, params?: object, cursor?: string, limit?: number })
112
+ Performs a LinkedIn search through Unipile using specified parameters.
113
+ - **Parameters:**
114
+ - `accountId`: Unipile account ID (required)
115
+ - `params`: LinkedIn search parameters (optional, default: {})
116
+ - `cursor`: Pagination cursor (optional, default: "")
117
+ - `limit`: Results per page (optional, default: 10)
118
+ - **Returns:** Promise with search results
119
+ - **Note:** Automatically sets `api: "classic"` and `category: "people"`
120
+
121
+ ##### searchByUrl({ accountId: string, searchUrl: string, cursor?: string, limit?: number })
122
+ Performs a LinkedIn search through Unipile using a LinkedIn search URL.
123
+ - **Parameters:**
124
+ - `accountId`: Unipile account ID (required)
125
+ - `searchUrl`: LinkedIn search URL (required)
126
+ - `cursor`: Pagination cursor (optional, default: "")
127
+ - `limit`: Results per page (optional, default: 10)
128
+ - **Returns:** Promise with search results
129
+
130
+ ## Error Handling ⚠️
131
+ The wrapper provides error handling for common Unipile API interactions:
132
+ - Validates required parameters (e.g., accountId)
133
+ - Propagates Unipile API errors with original error messages
134
+ - Wraps API calls in try-catch blocks for easier error handling
135
+
136
+ ## Dependencies 🔧
137
+ - Requires `api.js` utility for HTTP requests to Unipile API
138
+
139
+ ## Contributing 🤝
140
+ Contributions are welcome! Feel free to submit issues and pull requests.
141
+
142
+ ## License 📄
143
+ MIT License - see LICENSE file for details
package/package.json ADDED
@@ -0,0 +1,26 @@
1
+ {
2
+ "name": "@entergreat/unipile-wrapper",
3
+ "version": "1.0.0",
4
+ "description": "",
5
+ "main": "src/index.js",
6
+ "type": "module",
7
+ "scripts": {
8
+ "test": "echo \"Error: no test specified\" && exit 1",
9
+ "start": "src/index.js"
10
+ },
11
+ "repository": {
12
+ "type": "git",
13
+ "url": "git+https://github.com/nivkman/unipile-wrapper.git"
14
+ },
15
+ "keywords": [],
16
+ "author": "",
17
+ "license": "ISC",
18
+ "bugs": {
19
+ "url": "https://github.com/nivkman/unipile-wrapper/issues"
20
+ },
21
+ "homepage": "https://github.com/nivkman/unipile-wrapper#readme",
22
+ "dependencies": {
23
+ "axios": "^1.7.9",
24
+ "cors": "^2.8.5"
25
+ }
26
+ }
package/src/index.js ADDED
@@ -0,0 +1,3 @@
1
+ import LinkedinService from "./services/linkedinService.js";
2
+
3
+ export { LinkedinService };
@@ -0,0 +1,73 @@
1
+ import { post } from "../utils/api.js";
2
+
3
+ export default class LinkedinService {
4
+ constructor({uniphileToken, subdomain, port}) {
5
+ this.unipileUrl = `https://${subdomain}.unipile.com:${port}/api/v1`;
6
+ this.headers = {
7
+ accept: "application/json",
8
+ "content-type": "application/json",
9
+ "X-API-KEY": uniphileToken,
10
+ };
11
+ }
12
+
13
+ // connect to linkedin account via li_at cookie
14
+ async connect({loginCookie}) {
15
+ try {
16
+ const body = {
17
+ provider: "LINKEDIN",
18
+ access_token: loginCookie,
19
+ };
20
+
21
+ return await post(`${this.unipileUrl}/accounts`, body, this.headers);
22
+ } catch (error) {
23
+ throw error;
24
+ }
25
+ }
26
+
27
+ // preform a linkedin search by params
28
+ async searchByParams({accountId, params = {}, cursor = "", limit = 10}) {
29
+ try {
30
+ if (!accountId) {
31
+ throw "account_id must be provided";
32
+ }
33
+
34
+ let url = `${this.unipileUrl}/linkedin/search?account_id=${accountId}&limit=${limit}`;
35
+
36
+ params["api"] = "classic";
37
+ params["category"] = "people";
38
+
39
+ if (cursor) {
40
+ url += `&cursor=${cursor}`;
41
+ }
42
+
43
+ return await post(url, params, this.headers);
44
+ } catch (error) {
45
+ throw error;
46
+ }
47
+ }
48
+
49
+ // preform a linkedin search by url
50
+ async searchByUrl({accountId, searchUrl, cursor = "", limit = 10}) {
51
+ try {
52
+ if (!accountId) {
53
+ throw "account_id must be provided";
54
+ }
55
+
56
+ const body = {
57
+ api: "classic",
58
+ category: "people",
59
+ url: searchUrl,
60
+ };
61
+
62
+ let url = `${this.unipileUrl}/linkedin/search?account_id=${accountId}&limit=${limit}`;
63
+
64
+ if (cursor) {
65
+ url += `&cursor=${cursor}`;
66
+ }
67
+
68
+ return await post(url, body, this.headers);
69
+ } catch (error) {
70
+ throw error;
71
+ }
72
+ }
73
+ }
@@ -0,0 +1,19 @@
1
+ import axios from "axios";
2
+
3
+ export const get = async (route, headers = {}) => {
4
+ try {
5
+ const response = await axios.get(route, { headers });
6
+ return response.data;
7
+ } catch (error) {
8
+ throw error;
9
+ }
10
+ };
11
+
12
+ export const post = async (route, body = {}, headers = {}) => {
13
+ try {
14
+ const response = await axios.post(route, body, { headers });
15
+ return response.data;
16
+ } catch (error) {
17
+ throw error;
18
+ }
19
+ };