@pipedream/linkedin 1.3.2 → 2.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.
@@ -1,10 +1,11 @@
1
+ import { ConfigurationError } from "@pipedream/platform";
1
2
  import linkedin from "../../linkedin.app.mjs";
2
3
 
3
4
  export default {
4
5
  key: "linkedin-create-comment",
5
6
  name: "Create Comment",
6
- description: "Create a comment on a share or user generated content post. [See the docs here](https://docs.microsoft.com/en-us/linkedin/marketing/integrations/community-management/shares/network-update-social-actions#create-comment)",
7
- version: "0.1.13",
7
+ description: "Create a comment on a share or user generated content post. [See the documentation](https://docs.microsoft.com/en-us/linkedin/marketing/integrations/community-management/shares/network-update-social-actions#create-comment)",
8
+ version: "1.0.0",
8
9
  annotations: {
9
10
  destructiveHint: true,
10
11
  openWorldHint: true,
@@ -29,9 +30,9 @@ export default {
29
30
  description: "Text of the comment. May contain attributes such as links to people and organizations.",
30
31
  },
31
32
  content: {
32
- type: "any",
33
+ type: "string[]",
33
34
  label: "Content",
34
- description: "Array of a media content entities.",
35
+ description: "Array of media content entities, one JSON string per entry, e.g. `{\"entity\":{\"image\":\"urn:li:image:ABC123\"}}`.",
35
36
  optional: true,
36
37
  },
37
38
  parentComment: {
@@ -41,6 +42,39 @@ export default {
41
42
  optional: true,
42
43
  },
43
44
  },
45
+ methods: {
46
+ // Also accepts the whole array as one JSON string (the pre-1.0 contract), and
47
+ // flattens an entry holding a JSON array of content entities.
48
+ parseContent(items) {
49
+ if (!items) {
50
+ return undefined;
51
+ }
52
+ const entries = (Array.isArray(items)
53
+ ? items
54
+ : [
55
+ items,
56
+ ])
57
+ .filter((item) => item !== undefined && item !== null && item !== "")
58
+ .flatMap((item) => {
59
+ if (typeof item !== "string") {
60
+ return item;
61
+ }
62
+ try {
63
+ return JSON.parse(item);
64
+ } catch (error) {
65
+ throw new ConfigurationError(`Content: \`${item}\` is not valid JSON`);
66
+ }
67
+ });
68
+ for (const entry of entries) {
69
+ if (typeof entry !== "object" || entry === null || Array.isArray(entry)) {
70
+ throw new ConfigurationError(`Content: \`${JSON.stringify(entry)}\` is not a JSON object`);
71
+ }
72
+ }
73
+ return entries.length
74
+ ? entries
75
+ : undefined;
76
+ },
77
+ },
44
78
  async run({ $ }) {
45
79
  const data = {
46
80
  object: this.urnToComment,
@@ -48,7 +82,7 @@ export default {
48
82
  message: {
49
83
  text: this.message,
50
84
  },
51
- content: this.content,
85
+ content: this.parseContent(this.content),
52
86
  parentComment: this.parentComment,
53
87
  };
54
88
  const response = await this.linkedin.createComment(encodeURIComponent(this.urnToComment), {
@@ -7,7 +7,7 @@ export default {
7
7
  key: "linkedin-create-image-post-organization",
8
8
  name: "Create Image Post (Organization)",
9
9
  description: "Create an image post on LinkedIn. [See the documentation](https://learn.microsoft.com/en-us/linkedin/marketing/integrations/community-management/shares/images-api?view=li-lms-2023-09&tabs=http#uploading-an-image)",
10
- version: "1.0.9",
10
+ version: "1.1.0",
11
11
  annotations: {
12
12
  destructiveHint: false,
13
13
  openWorldHint: true,
@@ -91,7 +91,8 @@ export default {
91
91
 
92
92
  await this.uploadImage(uploadUrl, formData);
93
93
 
94
- await this.linkedin.createPost({
94
+ const response = await this.linkedin.createPost({
95
+ returnFullResponse: true,
95
96
  data: {
96
97
  author: `urn:li:organization:${this.organizationId}`,
97
98
  lifecycleState: "PUBLISHED",
@@ -109,8 +110,15 @@ export default {
109
110
  $,
110
111
  });
111
112
 
112
- $.export("$summary", "Successfully posted image.");
113
+ // LinkedIn returns the new post's URN in the `x-restli-id` response header, not in the body
114
+ const postId = response?.headers?.["x-restli-id"];
115
+ $.export("$summary", postId
116
+ ? `Successfully posted image with ID ${postId}`
117
+ : "Successfully posted image.");
113
118
 
114
- // nothing to return
119
+ return {
120
+ id: postId,
121
+ image,
122
+ };
115
123
  },
116
124
  };
@@ -7,7 +7,7 @@ export default {
7
7
  key: "linkedin-create-image-post-user",
8
8
  name: "Create Image Post (User)",
9
9
  description: "Create an image post on LinkedIn. [See the documentation](https://learn.microsoft.com/en-us/linkedin/marketing/integrations/community-management/shares/images-api?view=li-lms-2023-09&tabs=http#uploading-an-image)",
10
- version: "1.0.9",
10
+ version: "1.1.0",
11
11
  annotations: {
12
12
  destructiveHint: false,
13
13
  openWorldHint: true,
@@ -95,7 +95,8 @@ export default {
95
95
  $,
96
96
  });
97
97
 
98
- await this.linkedin.createPost({
98
+ const response = await this.linkedin.createPost({
99
+ returnFullResponse: true,
99
100
  data: {
100
101
  author: `urn:li:person:${id}`,
101
102
  lifecycleState: "PUBLISHED",
@@ -113,8 +114,15 @@ export default {
113
114
  $,
114
115
  });
115
116
 
116
- $.export("$summary", "Successfully posted image.");
117
+ // LinkedIn returns the new post's URN in the `x-restli-id` response header, not in the body
118
+ const postId = response?.headers?.["x-restli-id"];
119
+ $.export("$summary", postId
120
+ ? `Successfully posted image with ID ${postId}`
121
+ : "Successfully posted image.");
117
122
 
118
- // nothing to return
123
+ return {
124
+ id: postId,
125
+ image,
126
+ };
119
127
  },
120
128
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pipedream/linkedin",
3
- "version": "1.3.2",
3
+ "version": "2.1.0",
4
4
  "description": "Pipedream Linkedin Components",
5
5
  "main": "linkedin.app.mjs",
6
6
  "keywords": [
@@ -14,7 +14,7 @@
14
14
  },
15
15
  "dependencies": {
16
16
  "@pipedream/platform": "^3.2.5",
17
- "axios": "^1.16.1",
17
+ "axios": "^1.20.0",
18
18
  "form-data": "^4.0.4"
19
19
  }
20
20
  }