@entergreat/unipile-wrapper 1.0.6 → 1.0.9
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@entergreat/unipile-wrapper",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.9",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -21,6 +21,7 @@
|
|
|
21
21
|
"homepage": "https://github.com/nivkman/unipile-wrapper#readme",
|
|
22
22
|
"dependencies": {
|
|
23
23
|
"axios": "^1.7.9",
|
|
24
|
-
"cors": "^2.8.5"
|
|
24
|
+
"cors": "^2.8.5",
|
|
25
|
+
"form-data": "^4.0.0"
|
|
25
26
|
}
|
|
26
27
|
}
|
|
@@ -1,4 +1,14 @@
|
|
|
1
1
|
import { get, post, patch } from "../utils/api.js";
|
|
2
|
+
import FormData from "form-data";
|
|
3
|
+
|
|
4
|
+
function extractCompanyIdFromUrl(url) {
|
|
5
|
+
// Handle URLs like:
|
|
6
|
+
// https://www.linkedin.com/company/company-name/
|
|
7
|
+
// https://www.linkedin.com/company/12345678/
|
|
8
|
+
// https://linkedin.com/company/company-name
|
|
9
|
+
const match = url.match(/linkedin\.com\/company\/([^\/\?]+)/i);
|
|
10
|
+
return match ? match[1] : null;
|
|
11
|
+
}
|
|
2
12
|
|
|
3
13
|
function convertToBracketNotation(obj, prefix = '') {
|
|
4
14
|
const result = {};
|
|
@@ -141,7 +151,31 @@ export default class LinkedinService {
|
|
|
141
151
|
}
|
|
142
152
|
}
|
|
143
153
|
|
|
144
|
-
//
|
|
154
|
+
// retrieve LinkedIn company by URL or ID
|
|
155
|
+
async retrieveCompany({ accountId, companyId, companyUrl }) {
|
|
156
|
+
try {
|
|
157
|
+
if (!accountId) {
|
|
158
|
+
throw "account_id must be provided";
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
let id = companyId;
|
|
162
|
+
if (!id && companyUrl) {
|
|
163
|
+
id = extractCompanyIdFromUrl(companyUrl);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
if (!id) {
|
|
167
|
+
throw "company_id or company_url must be provided";
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
const url = `${this.unipileUrl}/linkedin/company/${id}?account_id=${accountId}`;
|
|
171
|
+
|
|
172
|
+
return await get(url, this.headers);
|
|
173
|
+
} catch (error) {
|
|
174
|
+
throw error;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
// edit LinkedIn profile (headline, summary - JSON format)
|
|
145
179
|
async editProfile({ accountId, profileData }) {
|
|
146
180
|
try {
|
|
147
181
|
if (!accountId) {
|
|
@@ -161,4 +195,60 @@ export default class LinkedinService {
|
|
|
161
195
|
throw error;
|
|
162
196
|
}
|
|
163
197
|
}
|
|
198
|
+
|
|
199
|
+
// add experience position (multipart/form-data format)
|
|
200
|
+
async addExperience({ accountId, experience }) {
|
|
201
|
+
try {
|
|
202
|
+
if (!accountId) {
|
|
203
|
+
throw "account_id must be provided";
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
if (!experience || !experience.role || !experience.company) {
|
|
207
|
+
throw "experience with role and company is required";
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
const url = `${this.unipileUrl}/users/me/edit?account_id=${accountId}`;
|
|
211
|
+
|
|
212
|
+
const formData = new FormData();
|
|
213
|
+
formData.append("type", "LINKEDIN");
|
|
214
|
+
formData.append("account_id", accountId);
|
|
215
|
+
formData.append("role", experience.role);
|
|
216
|
+
formData.append("company", experience.company);
|
|
217
|
+
|
|
218
|
+
if (experience.description) {
|
|
219
|
+
formData.append("description", experience.description);
|
|
220
|
+
}
|
|
221
|
+
if (experience.location) {
|
|
222
|
+
formData.append("location", experience.location);
|
|
223
|
+
}
|
|
224
|
+
if (experience.notify_network !== undefined) {
|
|
225
|
+
formData.append("notify_network", experience.notify_network.toString());
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
// Start date (required)
|
|
229
|
+
if (experience.start_month) {
|
|
230
|
+
formData.append("month", experience.start_month.toString());
|
|
231
|
+
}
|
|
232
|
+
if (experience.start_year) {
|
|
233
|
+
formData.append("year", experience.start_year.toString());
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
// End date (optional - for non-current positions)
|
|
237
|
+
if (experience.end_month) {
|
|
238
|
+
formData.append("month", experience.end_month.toString());
|
|
239
|
+
}
|
|
240
|
+
if (experience.end_year) {
|
|
241
|
+
formData.append("year", experience.end_year.toString());
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
const headers = {
|
|
245
|
+
...this.headers,
|
|
246
|
+
"content-type": "multipart/form-data",
|
|
247
|
+
};
|
|
248
|
+
|
|
249
|
+
return await patch(url, formData, headers);
|
|
250
|
+
} catch (error) {
|
|
251
|
+
throw error;
|
|
252
|
+
}
|
|
253
|
+
}
|
|
164
254
|
}
|