@venturekit-pro/social 0.0.0-dev.20260815191300 → 0.0.0-dev.20260816114351
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/dist/adapters/facebook.d.ts +11 -2
- package/dist/adapters/facebook.d.ts.map +1 -1
- package/dist/adapters/facebook.js +110 -28
- package/dist/adapters/facebook.js.map +1 -1
- package/dist/adapters/linkedin.d.ts +17 -14
- package/dist/adapters/linkedin.d.ts.map +1 -1
- package/dist/adapters/linkedin.js +116 -77
- package/dist/adapters/linkedin.js.map +1 -1
- package/dist/types.d.ts +1 -1
- package/package.json +4 -4
|
@@ -2,8 +2,11 @@
|
|
|
2
2
|
* Facebook (Pages) adapter — Meta Graph API.
|
|
3
3
|
*
|
|
4
4
|
* Endpoints:
|
|
5
|
-
* - Text post:
|
|
6
|
-
* -
|
|
5
|
+
* - Text post: `POST /v18.0/<page-id>/feed`
|
|
6
|
+
* - Single photo: `POST /v18.0/<page-id>/photos`
|
|
7
|
+
* - Multi-photo: `POST /v18.0/<page-id>/photos` (published=false)
|
|
8
|
+
* per photo, then `POST /v18.0/<page-id>/feed`
|
|
9
|
+
* with `attached_media` referencing all photo ids.
|
|
7
10
|
*
|
|
8
11
|
* Auth: Page access token via `?access_token=…` OR
|
|
9
12
|
* `Authorization: Bearer …`. We use the header form so the
|
|
@@ -20,6 +23,12 @@
|
|
|
20
23
|
* because the adapter downloads the image in-process (where it CAN
|
|
21
24
|
* reach a presigned / private URL) and pushes the bytes to Meta.
|
|
22
25
|
*
|
|
26
|
+
* Multi-photo posts (2–10 images) create an album-style feed post:
|
|
27
|
+
* each image is pre-uploaded to `/<page-id>/photos` with
|
|
28
|
+
* `published=false`, then a single `/<page-id>/feed` post references
|
|
29
|
+
* all uploaded photo ids via the `attached_media` field. This is the
|
|
30
|
+
* only Graph API flow that produces a multi-image post on a Page.
|
|
31
|
+
*
|
|
23
32
|
* Meta's /photos endpoint accepts JPEG and PNG only. The format is
|
|
24
33
|
* read from the downloaded bytes rather than `media.mimeType`, and
|
|
25
34
|
* anything else (e.g. WebP, which the CMS uses for blog covers) is
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"facebook.d.ts","sourceRoot":"","sources":["../../src/adapters/facebook.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"facebook.d.ts","sourceRoot":"","sources":["../../src/adapters/facebook.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AACnD,OAAO,KAAK,EAIV,yBAAyB,EAE1B,MAAM,aAAa,CAAC;AAmBrB,eAAO,MAAM,oBAAoB,EAAE,yBAelC,CAAC;AAEF,MAAM,WAAW,qBAAqB;IACpC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,WAAW,CAAC,EAAE,OAAO,CAAC,yBAAyB,CAAC,CAAC;CAClD;AAED,wBAAgB,qBAAqB,CACnC,MAAM,GAAE,qBAA0B,GACjC,aAAa,CA0Hf"}
|
|
@@ -2,8 +2,11 @@
|
|
|
2
2
|
* Facebook (Pages) adapter — Meta Graph API.
|
|
3
3
|
*
|
|
4
4
|
* Endpoints:
|
|
5
|
-
* - Text post:
|
|
6
|
-
* -
|
|
5
|
+
* - Text post: `POST /v18.0/<page-id>/feed`
|
|
6
|
+
* - Single photo: `POST /v18.0/<page-id>/photos`
|
|
7
|
+
* - Multi-photo: `POST /v18.0/<page-id>/photos` (published=false)
|
|
8
|
+
* per photo, then `POST /v18.0/<page-id>/feed`
|
|
9
|
+
* with `attached_media` referencing all photo ids.
|
|
7
10
|
*
|
|
8
11
|
* Auth: Page access token via `?access_token=…` OR
|
|
9
12
|
* `Authorization: Bearer …`. We use the header form so the
|
|
@@ -20,6 +23,12 @@
|
|
|
20
23
|
* because the adapter downloads the image in-process (where it CAN
|
|
21
24
|
* reach a presigned / private URL) and pushes the bytes to Meta.
|
|
22
25
|
*
|
|
26
|
+
* Multi-photo posts (2–10 images) create an album-style feed post:
|
|
27
|
+
* each image is pre-uploaded to `/<page-id>/photos` with
|
|
28
|
+
* `published=false`, then a single `/<page-id>/feed` post references
|
|
29
|
+
* all uploaded photo ids via the `attached_media` field. This is the
|
|
30
|
+
* only Graph API flow that produces a multi-image post on a Page.
|
|
31
|
+
*
|
|
23
32
|
* Meta's /photos endpoint accepts JPEG and PNG only. The format is
|
|
24
33
|
* read from the downloaded bytes rather than `media.mimeType`, and
|
|
25
34
|
* anything else (e.g. WebP, which the CMS uses for blog covers) is
|
|
@@ -27,6 +36,7 @@
|
|
|
27
36
|
* dependency. The constraints allow WebP so validation doesn't block
|
|
28
37
|
* the post before the adapter can convert it.
|
|
29
38
|
*/
|
|
39
|
+
import { SocialPublishError, SocialValidationError } from '../types.js';
|
|
30
40
|
import { vendorFetch } from '../http.js';
|
|
31
41
|
import { downloadMedia, ensureUploadableImage, filenameForMime, } from '../media.js';
|
|
32
42
|
import { validatePost } from '../validation.js';
|
|
@@ -34,6 +44,8 @@ const META_GRAPH_BASE = 'https://graph.facebook.com';
|
|
|
34
44
|
const META_GRAPH_VERSION = 'v18.0';
|
|
35
45
|
/** MIME types Meta's /photos endpoint actually accepts. */
|
|
36
46
|
const FACEBOOK_UPLOAD_MIME = new Set(['image/jpeg', 'image/png']);
|
|
47
|
+
/** Maximum photos per album-style feed post (Meta's hard limit). */
|
|
48
|
+
const MAX_FB_PHOTOS = 10;
|
|
37
49
|
export const FACEBOOK_CONSTRAINTS = {
|
|
38
50
|
maxBodyChars: 63206, // Meta's published max; 2000 is the recommended ceiling
|
|
39
51
|
minBodyChars: 1,
|
|
@@ -42,7 +54,10 @@ export const FACEBOOK_CONSTRAINTS = {
|
|
|
42
54
|
// WebP is allowed at validation time so the adapter can convert it
|
|
43
55
|
// to JPEG before uploading — Meta's /photos endpoint rejects WebP.
|
|
44
56
|
allowedMimeTypes: ['image/jpeg', 'image/png', 'image/webp'],
|
|
45
|
-
|
|
57
|
+
// Facebook supports album-style posts with up to 10 photos via
|
|
58
|
+
// `attached_media` on the /feed endpoint. Single-photo posts still go
|
|
59
|
+
// through /photos; 2+ photos use the multi-upload flow.
|
|
60
|
+
maxMediaCount: 10,
|
|
46
61
|
allowedAspectRatios: ['1:1', '4:3', '16:9', '4:5'],
|
|
47
62
|
maxMediaSizeBytes: 10 * 1024 * 1024,
|
|
48
63
|
supportsFirstComment: false,
|
|
@@ -63,45 +78,86 @@ export function createFacebookAdapter(config = {}) {
|
|
|
63
78
|
},
|
|
64
79
|
async publish(post, credentials) {
|
|
65
80
|
const pageId = stripPagePrefix(credentials.authorRef);
|
|
66
|
-
const
|
|
81
|
+
const mediaCount = post.media?.length ?? 0;
|
|
67
82
|
// Text / link posts hit /<page-id>/feed — no image, so the
|
|
68
83
|
// original JSON body path is correct.
|
|
69
|
-
if (
|
|
84
|
+
if (mediaCount === 0) {
|
|
70
85
|
const endpoint = `/${version}/${encodeURIComponent(pageId)}/feed`;
|
|
71
|
-
const body = buildFeedBody(post);
|
|
72
86
|
const res = await vendorFetch('facebook', `${baseUrl}${endpoint}`, {
|
|
73
87
|
method: 'POST',
|
|
74
88
|
headers: {
|
|
75
89
|
Authorization: `Bearer ${credentials.accessToken}`,
|
|
76
90
|
'Content-Type': 'application/json',
|
|
77
91
|
},
|
|
78
|
-
body: JSON.stringify(
|
|
92
|
+
body: JSON.stringify(buildFeedBody(post)),
|
|
79
93
|
});
|
|
80
94
|
return parseResult(res, post);
|
|
81
95
|
}
|
|
82
|
-
//
|
|
83
|
-
//
|
|
84
|
-
// `
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
//
|
|
91
|
-
//
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
96
|
+
// Meta hard-caps an album at 10 photos. `validate()` already
|
|
97
|
+
// reports this, but `publish()` can be called without it (and
|
|
98
|
+
// `config.constraints` can raise `maxMediaCount` past the vendor
|
|
99
|
+
// limit), so refuse loudly rather than silently dropping content.
|
|
100
|
+
if (mediaCount > MAX_FB_PHOTOS) {
|
|
101
|
+
throw new SocialValidationError(`[social/facebook] Too many photos (${mediaCount}; Meta allows ${MAX_FB_PHOTOS} per post).`, { platform: 'facebook' });
|
|
102
|
+
}
|
|
103
|
+
// Single photo posts hit /<page-id>/photos with multipart form
|
|
104
|
+
// data. We download the image in-process and upload the bytes via
|
|
105
|
+
// the `source` field — Meta's servers don't need to fetch
|
|
106
|
+
// anything.
|
|
107
|
+
if (mediaCount === 1) {
|
|
108
|
+
const endpoint = `/${version}/${encodeURIComponent(pageId)}/photos`;
|
|
109
|
+
const form = await photoForm(post.media[0], constraints.maxMediaSizeBytes);
|
|
110
|
+
form.append('message', post.body);
|
|
111
|
+
// Do NOT set Content-Type manually — fetch() sets the multipart
|
|
112
|
+
// boundary automatically from FormData. A manual header would
|
|
113
|
+
// omit the boundary and Meta would reject the request.
|
|
114
|
+
const res = await vendorFetch('facebook', `${baseUrl}${endpoint}`, {
|
|
115
|
+
method: 'POST',
|
|
116
|
+
headers: { Authorization: `Bearer ${credentials.accessToken}` },
|
|
117
|
+
body: form,
|
|
118
|
+
});
|
|
119
|
+
return parseResult(res, post);
|
|
120
|
+
}
|
|
121
|
+
// Multi-photo posts (2–10 images) create an album-style feed
|
|
122
|
+
// post. Each image is pre-uploaded to /<page-id>/photos with
|
|
123
|
+
// `published=false` (multipart form data), then a single
|
|
124
|
+
// /<page-id>/feed post references all uploaded photo ids via
|
|
125
|
+
// `attached_media`.
|
|
126
|
+
const photosEndpoint = `/${version}/${encodeURIComponent(pageId)}/photos`;
|
|
127
|
+
const feedEndpoint = `/${version}/${encodeURIComponent(pageId)}/feed`;
|
|
128
|
+
const attachedMedia = [];
|
|
129
|
+
for (const media of post.media) {
|
|
130
|
+
const form = await photoForm(media, constraints.maxMediaSizeBytes);
|
|
131
|
+
form.append('published', 'false');
|
|
132
|
+
const uploadRes = await vendorFetch('facebook', `${baseUrl}${photosEndpoint}`, {
|
|
133
|
+
method: 'POST',
|
|
134
|
+
headers: { Authorization: `Bearer ${credentials.accessToken}` },
|
|
135
|
+
body: form,
|
|
136
|
+
});
|
|
137
|
+
const uploadJson = uploadRes.body;
|
|
138
|
+
const photoId = uploadJson?.id;
|
|
139
|
+
if (!photoId) {
|
|
140
|
+
throw new SocialPublishError('[social/facebook] Multi-photo upload returned no id; vendor body: ' +
|
|
141
|
+
uploadRes.bodyText.slice(0, 200), { platform: 'facebook', raw: uploadRes.body });
|
|
142
|
+
}
|
|
143
|
+
attachedMedia.push({ media_fbid: photoId });
|
|
144
|
+
}
|
|
145
|
+
// Create the feed post referencing all uploaded photos. `link` is
|
|
146
|
+
// deliberately omitted: Meta cannot render a link preview and
|
|
147
|
+
// `attached_media` on the same story — same rule as LinkedIn.
|
|
148
|
+
const feedBody = {
|
|
149
|
+
message: post.body,
|
|
150
|
+
attached_media: attachedMedia,
|
|
151
|
+
};
|
|
152
|
+
const feedRes = await vendorFetch('facebook', `${baseUrl}${feedEndpoint}`, {
|
|
100
153
|
method: 'POST',
|
|
101
|
-
headers: {
|
|
102
|
-
|
|
154
|
+
headers: {
|
|
155
|
+
Authorization: `Bearer ${credentials.accessToken}`,
|
|
156
|
+
'Content-Type': 'application/json',
|
|
157
|
+
},
|
|
158
|
+
body: JSON.stringify(feedBody),
|
|
103
159
|
});
|
|
104
|
-
return parseResult(
|
|
160
|
+
return parseResult(feedRes, post);
|
|
105
161
|
},
|
|
106
162
|
};
|
|
107
163
|
}
|
|
@@ -131,4 +187,30 @@ function parseResult(res, post) {
|
|
|
131
187
|
raw: json,
|
|
132
188
|
};
|
|
133
189
|
}
|
|
190
|
+
/**
|
|
191
|
+
* Build the multipart body for one `/<page-id>/photos` upload.
|
|
192
|
+
*
|
|
193
|
+
* Downloading in-process is what makes photo posts work everywhere:
|
|
194
|
+
* the URLs the CMS produces (presigned S3, MinIO on localhost, a
|
|
195
|
+
* private bucket with no CDN) are reachable from the publishing worker
|
|
196
|
+
* but not from Meta's servers, so we push the bytes rather than hand
|
|
197
|
+
* Meta a `url` to fetch.
|
|
198
|
+
*
|
|
199
|
+
* `downloadMedia` enforces the http(s)-only rule, the per-attachment
|
|
200
|
+
* byte cap and the abort timeout; `ensureUploadableImage` transcodes
|
|
201
|
+
* anything Meta's /photos endpoint won't take. The effective format
|
|
202
|
+
* comes from the payload's magic number, NOT `media.mimeType` — that
|
|
203
|
+
* field is caller metadata and goes stale (a WebP recorded as
|
|
204
|
+
* `image/jpeg` is exactly the failure this path guards against).
|
|
205
|
+
*
|
|
206
|
+
* The caller appends the fields that differ per flow (`message` for a
|
|
207
|
+
* single photo, `published=false` for an album member).
|
|
208
|
+
*/
|
|
209
|
+
async function photoForm(media, maxBytes) {
|
|
210
|
+
const downloaded = await downloadMedia(media.url, 'facebook', { maxBytes });
|
|
211
|
+
const { bytes, mimeType } = await ensureUploadableImage(downloaded, media.mimeType, FACEBOOK_UPLOAD_MIME, 'facebook');
|
|
212
|
+
const form = new FormData();
|
|
213
|
+
form.append('source', new Blob([bytes], { type: mimeType }), filenameForMime(mimeType));
|
|
214
|
+
return form;
|
|
215
|
+
}
|
|
134
216
|
//# sourceMappingURL=facebook.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"facebook.js","sourceRoot":"","sources":["../../src/adapters/facebook.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"facebook.js","sourceRoot":"","sources":["../../src/adapters/facebook.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AAUH,OAAO,EAAE,kBAAkB,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AACxE,OAAO,EAAE,WAAW,EAAoB,MAAM,YAAY,CAAC;AAC3D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EAAE,CAAC,EAC/D,eAAe,CAAC,QAAQ,CAAC,CAC1B,CAAC;IACF,OAAO,IAAI,CAAC;AACd,CAAC"}
|
|
@@ -1,29 +1,32 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* LinkedIn adapter —
|
|
2
|
+
* LinkedIn adapter — Posts API (REST).
|
|
3
3
|
*
|
|
4
|
-
* Endpoint: `POST https://api.linkedin.com/
|
|
4
|
+
* Endpoint: `POST https://api.linkedin.com/rest/posts`
|
|
5
5
|
* Auth: OAuth 2.0 bearer token in `Authorization: Bearer …`
|
|
6
6
|
* Author: `urn:li:organization:<id>` or `urn:li:person:<id>`
|
|
7
7
|
* — caller supplies via `credentials.authorRef`.
|
|
8
8
|
*
|
|
9
|
-
* The adapter implements text
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
9
|
+
* The adapter implements text, image, multi-image, and link-preview
|
|
10
|
+
* posts. Link previews use `content.article` (the Posts API does NOT
|
|
11
|
+
* scrape URLs — `title` and `description` are required fields we
|
|
12
|
+
* derive from the body). CTA buttons (`contentCallToActionLabel`) only
|
|
13
|
+
* render on sponsored content (ads), not organic posts, so we don't
|
|
14
|
+
* use them.
|
|
13
15
|
*
|
|
14
16
|
* Image staging:
|
|
15
|
-
* If `media.url` is already a LinkedIn
|
|
16
|
-
* (`urn:li:
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
* 1. `POST /
|
|
17
|
+
* If `media.url` is already a LinkedIn image URN
|
|
18
|
+
* (`urn:li:image:…`) — e.g. the caller pre-staged the upload — the
|
|
19
|
+
* adapter uses it directly. Otherwise the adapter performs LinkedIn's
|
|
20
|
+
* two-step staging automatically:
|
|
21
|
+
* 1. `POST /rest/images?action=initializeUpload` → upload URL + image URN
|
|
20
22
|
* 2. `PUT` the image bytes to the upload URL
|
|
21
|
-
* 3. Use the
|
|
23
|
+
* 3. Use the image URN in the post's `content.media` or
|
|
24
|
+
* `content.multiImage` field
|
|
22
25
|
* This means callers can pass a plain image URL (presigned S3, CDN,
|
|
23
26
|
* etc.) without implementing the staging protocol themselves.
|
|
24
27
|
*
|
|
25
|
-
* LinkedIn's
|
|
26
|
-
*
|
|
28
|
+
* LinkedIn's Images API accepts JPEG and PNG only (not WebP). The
|
|
29
|
+
* format is read from the downloaded bytes rather than
|
|
27
30
|
* `media.mimeType`, and anything else is converted to JPEG before
|
|
28
31
|
* upload. Conversion requires the optional `sharp` peer dependency;
|
|
29
32
|
* if it's not installed, the adapter throws a clear error.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"linkedin.d.ts","sourceRoot":"","sources":["../../src/adapters/linkedin.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"linkedin.d.ts","sourceRoot":"","sources":["../../src/adapters/linkedin.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AACnD,OAAO,KAAK,EAIV,yBAAyB,EAG1B,MAAM,aAAa,CAAC;AAkBrB,eAAO,MAAM,oBAAoB,EAAE,yBAUlC,CAAC;AAEF,MAAM,WAAW,qBAAqB;IACpC,kEAAkE;IAClE,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,sEAAsE;IACtE,WAAW,CAAC,EAAE,OAAO,CAAC,yBAAyB,CAAC,CAAC;CAClD;AAED;;;GAGG;AACH,wBAAgB,qBAAqB,CACnC,MAAM,GAAE,qBAA0B,GACjC,aAAa,CAiFf"}
|
|
@@ -1,29 +1,32 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* LinkedIn adapter —
|
|
2
|
+
* LinkedIn adapter — Posts API (REST).
|
|
3
3
|
*
|
|
4
|
-
* Endpoint: `POST https://api.linkedin.com/
|
|
4
|
+
* Endpoint: `POST https://api.linkedin.com/rest/posts`
|
|
5
5
|
* Auth: OAuth 2.0 bearer token in `Authorization: Bearer …`
|
|
6
6
|
* Author: `urn:li:organization:<id>` or `urn:li:person:<id>`
|
|
7
7
|
* — caller supplies via `credentials.authorRef`.
|
|
8
8
|
*
|
|
9
|
-
* The adapter implements text
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
9
|
+
* The adapter implements text, image, multi-image, and link-preview
|
|
10
|
+
* posts. Link previews use `content.article` (the Posts API does NOT
|
|
11
|
+
* scrape URLs — `title` and `description` are required fields we
|
|
12
|
+
* derive from the body). CTA buttons (`contentCallToActionLabel`) only
|
|
13
|
+
* render on sponsored content (ads), not organic posts, so we don't
|
|
14
|
+
* use them.
|
|
13
15
|
*
|
|
14
16
|
* Image staging:
|
|
15
|
-
* If `media.url` is already a LinkedIn
|
|
16
|
-
* (`urn:li:
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
* 1. `POST /
|
|
17
|
+
* If `media.url` is already a LinkedIn image URN
|
|
18
|
+
* (`urn:li:image:…`) — e.g. the caller pre-staged the upload — the
|
|
19
|
+
* adapter uses it directly. Otherwise the adapter performs LinkedIn's
|
|
20
|
+
* two-step staging automatically:
|
|
21
|
+
* 1. `POST /rest/images?action=initializeUpload` → upload URL + image URN
|
|
20
22
|
* 2. `PUT` the image bytes to the upload URL
|
|
21
|
-
* 3. Use the
|
|
23
|
+
* 3. Use the image URN in the post's `content.media` or
|
|
24
|
+
* `content.multiImage` field
|
|
22
25
|
* This means callers can pass a plain image URL (presigned S3, CDN,
|
|
23
26
|
* etc.) without implementing the staging protocol themselves.
|
|
24
27
|
*
|
|
25
|
-
* LinkedIn's
|
|
26
|
-
*
|
|
28
|
+
* LinkedIn's Images API accepts JPEG and PNG only (not WebP). The
|
|
29
|
+
* format is read from the downloaded bytes rather than
|
|
27
30
|
* `media.mimeType`, and anything else is converted to JPEG before
|
|
28
31
|
* upload. Conversion requires the optional `sharp` peer dependency;
|
|
29
32
|
* if it's not installed, the adapter throws a clear error.
|
|
@@ -33,6 +36,12 @@ import { vendorFetch } from '../http.js';
|
|
|
33
36
|
import { downloadMedia, ensureUploadableImage } from '../media.js';
|
|
34
37
|
import { validatePost } from '../validation.js';
|
|
35
38
|
const LINKEDIN_API_BASE = 'https://api.linkedin.com';
|
|
39
|
+
/**
|
|
40
|
+
* Required on every versioned (`/rest/*`) call. Format is `YYYYMM`;
|
|
41
|
+
* LinkedIn retires versions on a rolling ~1-year window, so this is
|
|
42
|
+
* the single place to bump.
|
|
43
|
+
*/
|
|
44
|
+
const LINKEDIN_VERSION = '202511';
|
|
36
45
|
/** LinkedIn's feedshare-image recipe accepts JPEG and PNG only. */
|
|
37
46
|
const LINKEDIN_ACCEPTED_MIME = new Set(['image/jpeg', 'image/png']);
|
|
38
47
|
export const LINKEDIN_CONSTRAINTS = {
|
|
@@ -65,37 +74,44 @@ export function createLinkedInAdapter(config = {}) {
|
|
|
65
74
|
},
|
|
66
75
|
async publish(post, credentials) {
|
|
67
76
|
// Stage images that aren't already LinkedIn URNs.
|
|
68
|
-
|
|
77
|
+
//
|
|
78
|
+
// A link preview wins over media (`buildPostBody` emits
|
|
79
|
+
// `content.article` and ignores `stagedMedia`), so skip staging
|
|
80
|
+
// outright when `post.link` is set: uploading images the body
|
|
81
|
+
// will discard costs three vendor round-trips each and lets an
|
|
82
|
+
// irrelevant staging failure abort an otherwise-valid link post.
|
|
83
|
+
const media = post.link ? [] : (post.media ?? []);
|
|
69
84
|
const stagedMedia = [];
|
|
70
85
|
for (const m of media) {
|
|
71
|
-
if (m.url.startsWith('urn:li:
|
|
86
|
+
if (m.url.startsWith('urn:li:image:')) {
|
|
72
87
|
// Caller already staged the upload — use the URN directly.
|
|
73
88
|
stagedMedia.push(m.url);
|
|
74
89
|
}
|
|
75
90
|
else {
|
|
76
|
-
// Auto-stage: download →
|
|
91
|
+
// Auto-stage: download → initializeUpload → PUT bytes → URN.
|
|
77
92
|
stagedMedia.push(await stageImage(baseUrl, credentials, m, constraints.maxMediaSizeBytes));
|
|
78
93
|
}
|
|
79
94
|
}
|
|
80
|
-
|
|
95
|
+
// Use the Posts API (/rest/posts). The older UGC Posts API
|
|
96
|
+
// (/v2/ugcPosts) is legacy and doesn't support the current
|
|
97
|
+
// content model (article / multiImage).
|
|
98
|
+
const body = buildPostBody(post, credentials, stagedMedia);
|
|
81
99
|
const headers = {
|
|
82
100
|
Authorization: `Bearer ${credentials.accessToken}`,
|
|
83
101
|
'Content-Type': 'application/json',
|
|
84
102
|
'X-Restli-Protocol-Version': '2.0.0',
|
|
103
|
+
'Linkedin-Version': LINKEDIN_VERSION,
|
|
85
104
|
};
|
|
86
|
-
|
|
87
|
-
// equivalent, and it cannot travel in the body either (see
|
|
88
|
-
// `UgcPostBody`). Retries are deduped caller-side.
|
|
89
|
-
const res = await vendorFetch('linkedin', `${baseUrl}/v2/ugcPosts`, {
|
|
105
|
+
const res = await vendorFetch('linkedin', `${baseUrl}/rest/posts`, {
|
|
90
106
|
method: 'POST',
|
|
91
107
|
headers,
|
|
92
108
|
body: JSON.stringify(body),
|
|
93
109
|
});
|
|
110
|
+
// The Posts API returns the post URN in the `x-restli-id` header
|
|
111
|
+
// (e.g. "urn:li:share:6844785523593134080") and an empty body.
|
|
94
112
|
const json = res.body;
|
|
95
|
-
const externalRef = json?.id ?? res.headers.get('x-linkedin-id') ?? '';
|
|
113
|
+
const externalRef = json?.id ?? res.headers.get('x-restli-id') ?? res.headers.get('x-linkedin-id') ?? '';
|
|
96
114
|
if (!externalRef) {
|
|
97
|
-
// LinkedIn always returns 201 with an id; if we didn't get
|
|
98
|
-
// one, the post probably WASN'T accepted — fail loud.
|
|
99
115
|
throw new Error('[social/linkedin] Publish returned no id; vendor body: ' + res.bodyText.slice(0, 200));
|
|
100
116
|
}
|
|
101
117
|
// First-comment companion thread. Best-effort: the post is
|
|
@@ -105,7 +121,6 @@ export function createLinkedInAdapter(config = {}) {
|
|
|
105
121
|
}
|
|
106
122
|
return {
|
|
107
123
|
externalRef,
|
|
108
|
-
// The public URL form is `https://www.linkedin.com/feed/update/<urn>`.
|
|
109
124
|
publishedUrl: `https://www.linkedin.com/feed/update/${encodeURIComponent(externalRef)}`,
|
|
110
125
|
publishedAt: new Date().toISOString(),
|
|
111
126
|
idempotencyKey: post.idempotencyKey,
|
|
@@ -117,68 +132,68 @@ export function createLinkedInAdapter(config = {}) {
|
|
|
117
132
|
}
|
|
118
133
|
// ─── Internal: image staging ──────────────────────────────────────────
|
|
119
134
|
/**
|
|
120
|
-
* Download an image from a URL, convert to JPEG if needed,
|
|
121
|
-
* the upload with LinkedIn, push the bytes, and return
|
|
135
|
+
* Download an image from a URL, convert to JPEG if needed, initialize
|
|
136
|
+
* the upload with LinkedIn's Images API, push the bytes, and return
|
|
137
|
+
* the image URN (`urn:li:image:...`).
|
|
138
|
+
*
|
|
139
|
+
* Uses the Images API (`POST /rest/images?action=initializeUpload`)
|
|
140
|
+
* which returns `urn:li:image:...` URNs compatible with the Posts API.
|
|
141
|
+
* The older Assets API returned `urn:li:digitalmediaAsset:...` URNs
|
|
142
|
+
* which the Posts API rejects.
|
|
122
143
|
*/
|
|
123
144
|
async function stageImage(baseUrl, credentials, media, maxBytes) {
|
|
124
145
|
// Download the image (the calling process can reach presigned /
|
|
125
146
|
// private URLs that LinkedIn's servers cannot), then transcode if
|
|
126
|
-
// the
|
|
147
|
+
// the image recipe won't take the format.
|
|
127
148
|
const downloaded = await downloadMedia(media.url, 'linkedin', { maxBytes });
|
|
128
149
|
const { bytes, mimeType } = await ensureUploadableImage(downloaded, media.mimeType, LINKEDIN_ACCEPTED_MIME, 'linkedin');
|
|
129
|
-
// Step 1:
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
registerUploadRequest: {
|
|
133
|
-
recipes: ['urn:li:digitalmediaRecipe:feedshare-image'],
|
|
150
|
+
// Step 1: initialize the upload via the Images API.
|
|
151
|
+
const initBody = {
|
|
152
|
+
initializeUploadRequest: {
|
|
134
153
|
owner: credentials.authorRef,
|
|
135
|
-
serviceRelationships: [
|
|
136
|
-
{
|
|
137
|
-
relationshipType: 'OWNER',
|
|
138
|
-
identifier: 'urn:li:userGeneratedContent',
|
|
139
|
-
},
|
|
140
|
-
],
|
|
141
|
-
supportedUploadMechanism: ['SYNCHRONOUS_UPLOAD'],
|
|
142
154
|
},
|
|
143
155
|
};
|
|
144
|
-
const
|
|
156
|
+
const initRes = await vendorFetch('linkedin', `${baseUrl}/rest/images?action=initializeUpload`, {
|
|
145
157
|
method: 'POST',
|
|
146
158
|
headers: {
|
|
147
159
|
Authorization: `Bearer ${credentials.accessToken}`,
|
|
148
160
|
'Content-Type': 'application/json',
|
|
149
161
|
'X-Restli-Protocol-Version': '2.0.0',
|
|
162
|
+
'Linkedin-Version': LINKEDIN_VERSION,
|
|
150
163
|
},
|
|
151
|
-
body: JSON.stringify(
|
|
164
|
+
body: JSON.stringify(initBody),
|
|
152
165
|
});
|
|
153
|
-
const
|
|
154
|
-
const
|
|
155
|
-
const
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
regRes.bodyText.slice(0, 500), { platform: 'linkedin', status: regRes.status, raw: regRes.body });
|
|
166
|
+
const initJson = initRes.body;
|
|
167
|
+
const uploadUrl = initJson?.value?.uploadUrl;
|
|
168
|
+
const imageUrn = initJson?.value?.image;
|
|
169
|
+
if (!uploadUrl || !imageUrn) {
|
|
170
|
+
throw new SocialPublishError('[social/linkedin] initializeUpload returned no upload URL / image URN; vendor body: ' +
|
|
171
|
+
initRes.bodyText.slice(0, 500), { platform: 'linkedin', status: initRes.status, raw: initRes.body });
|
|
160
172
|
}
|
|
161
173
|
// Step 2: upload the bytes. The upload URL is a one-shot signed
|
|
162
174
|
// endpoint rather than the LinkedIn API proper, but it still goes
|
|
163
175
|
// through `vendorFetch` so the call inherits the abort timeout and
|
|
164
|
-
// the status → typed-error mapping.
|
|
165
|
-
// asked us to echo back.
|
|
176
|
+
// the status → typed-error mapping.
|
|
166
177
|
await vendorFetch('linkedin', uploadUrl, {
|
|
167
178
|
method: 'PUT',
|
|
168
179
|
headers: {
|
|
169
180
|
'Content-Type': mimeType,
|
|
170
|
-
...(uploadMech?.headers ?? {}),
|
|
171
181
|
},
|
|
172
182
|
body: bytes,
|
|
173
183
|
});
|
|
174
|
-
return
|
|
184
|
+
return imageUrn;
|
|
175
185
|
}
|
|
176
186
|
// ─── Internal: first-comment ──────────────────────────────────────────
|
|
177
187
|
/**
|
|
178
|
-
* Post a first-comment under a freshly-published
|
|
188
|
+
* Post a first-comment under a freshly-published post via the
|
|
179
189
|
* `socialActions/{urn}/comments` endpoint. The comment is authored by
|
|
180
190
|
* the same actor as the post (`credentials.authorRef`).
|
|
181
191
|
*
|
|
192
|
+
* Still on `/v2`: comments have no `/rest` equivalent that accepts a
|
|
193
|
+
* `urn:li:share` object. `Linkedin-Version` is sent anyway so the call
|
|
194
|
+
* doesn't break when LinkedIn folds this endpoint into the versioned
|
|
195
|
+
* surface — the header is ignored on unversioned routes.
|
|
196
|
+
*
|
|
182
197
|
* Best-effort by contract: the post is already live, so a failed
|
|
183
198
|
* comment must never unwind a successful publish. We swallow vendor
|
|
184
199
|
* errors here and let the caller's publish result stand.
|
|
@@ -191,6 +206,7 @@ async function postFirstComment(baseUrl, credentials, postUrn, text) {
|
|
|
191
206
|
Authorization: `Bearer ${credentials.accessToken}`,
|
|
192
207
|
'Content-Type': 'application/json',
|
|
193
208
|
'X-Restli-Protocol-Version': '2.0.0',
|
|
209
|
+
'Linkedin-Version': LINKEDIN_VERSION,
|
|
194
210
|
},
|
|
195
211
|
body: JSON.stringify({
|
|
196
212
|
actor: credentials.authorRef,
|
|
@@ -203,36 +219,59 @@ async function postFirstComment(baseUrl, credentials, postUrn, text) {
|
|
|
203
219
|
// Swallowed — see doc comment.
|
|
204
220
|
}
|
|
205
221
|
}
|
|
206
|
-
function
|
|
222
|
+
function buildPostBody(post, credentials, stagedMedia) {
|
|
207
223
|
const hasMedia = stagedMedia.length > 0;
|
|
208
|
-
const
|
|
224
|
+
const hasLink = !!post.link;
|
|
225
|
+
const altTexts = post.media ?? [];
|
|
209
226
|
const body = {
|
|
210
227
|
author: credentials.authorRef,
|
|
228
|
+
commentary: post.body,
|
|
229
|
+
visibility: 'PUBLIC',
|
|
211
230
|
lifecycleState: 'PUBLISHED',
|
|
212
|
-
|
|
213
|
-
'
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
},
|
|
231
|
+
distribution: {
|
|
232
|
+
feedDistribution: 'MAIN_FEED',
|
|
233
|
+
targetEntities: [],
|
|
234
|
+
thirdPartyDistributionChannels: [],
|
|
217
235
|
},
|
|
218
|
-
|
|
236
|
+
isReshareDisabledByAuthor: false,
|
|
219
237
|
};
|
|
220
|
-
if (
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
status: 'READY',
|
|
232
|
-
originalUrl: post.link,
|
|
238
|
+
if (hasLink && post.link) {
|
|
239
|
+
// Link preview post (content.article). LinkedIn can't combine
|
|
240
|
+
// a link preview with images, so media is dropped — same rule
|
|
241
|
+
// as Facebook. The Posts API does NOT scrape URLs, so title
|
|
242
|
+
// and description are required fields we derive from the body.
|
|
243
|
+
const firstLine = post.body.split('\n').find((l) => l.trim()) ?? post.body;
|
|
244
|
+
body.content = {
|
|
245
|
+
article: {
|
|
246
|
+
source: post.link,
|
|
247
|
+
title: firstLine.slice(0, 200),
|
|
248
|
+
description: post.body.slice(0, 400),
|
|
233
249
|
},
|
|
234
|
-
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
else if (hasMedia) {
|
|
253
|
+
if (stagedMedia.length === 1) {
|
|
254
|
+
// Single image — use content.media
|
|
255
|
+
body.content = {
|
|
256
|
+
media: {
|
|
257
|
+
id: stagedMedia[0],
|
|
258
|
+
...(altTexts[0]?.altText ? { title: altTexts[0].altText } : {}),
|
|
259
|
+
},
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
else {
|
|
263
|
+
// Multiple images (2-20) — use content.multiImage
|
|
264
|
+
body.content = {
|
|
265
|
+
multiImage: {
|
|
266
|
+
images: stagedMedia.map((urn, i) => ({
|
|
267
|
+
id: urn,
|
|
268
|
+
...(altTexts[i]?.altText ? { altText: altTexts[i].altText } : {}),
|
|
269
|
+
})),
|
|
270
|
+
},
|
|
271
|
+
};
|
|
272
|
+
}
|
|
235
273
|
}
|
|
274
|
+
// else: text-only post, no content field
|
|
236
275
|
return body;
|
|
237
276
|
}
|
|
238
277
|
//# sourceMappingURL=linkedin.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"linkedin.js","sourceRoot":"","sources":["../../src/adapters/linkedin.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"linkedin.js","sourceRoot":"","sources":["../../src/adapters/linkedin.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AAWH,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACzC,OAAO,EAAE,aAAa,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AACnE,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAEhD,MAAM,iBAAiB,GAAG,0BAA0B,CAAC;AAErD;;;;GAIG;AACH,MAAM,gBAAgB,GAAG,QAAQ,CAAC;AAElC,mEAAmE;AACnE,MAAM,sBAAsB,GAAG,IAAI,GAAG,CAAC,CAAC,YAAY,EAAE,WAAW,CAAC,CAAC,CAAC;AAEpE,MAAM,CAAC,MAAM,oBAAoB,GAA8B;IAC7D,YAAY,EAAE,IAAI;IAClB,YAAY,EAAE,CAAC;IACf,WAAW,EAAE,CAAC;IACd,WAAW,EAAE,CAAC;IACd,gBAAgB,EAAE,CAAC,YAAY,EAAE,WAAW,EAAE,YAAY,CAAC;IAC3D,aAAa,EAAE,CAAC;IAChB,mBAAmB,EAAE,CAAC,KAAK,EAAE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AAG,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;iBAChE;aACF,CAAC;QACJ,CAAC;aAAM,CAAC;YACN,kDAAkD;YAClD,IAAI,CAAC,OAAO,GAAG;gBACb,UAAU,EAAE;oBACV,MAAM,EAAE,WAAW,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC;wBACnC,EAAE,EAAE,GAAG;wBACP,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC,OAAQ,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;qBACnE,CAAC,CAAC;iBACJ;aACF,CAAC;QACJ,CAAC;IACH,CAAC;IACD,yCAAyC;IAEzC,OAAO,IAAI,CAAC;AACd,CAAC"}
|
package/dist/types.d.ts
CHANGED
|
@@ -94,7 +94,7 @@ export interface SocialPost {
|
|
|
94
94
|
/**
|
|
95
95
|
* Caller-side idempotency token. This is NEVER sent to a vendor: none
|
|
96
96
|
* of the supported platforms expose an idempotency field, and
|
|
97
|
-
* LinkedIn's
|
|
97
|
+
* LinkedIn's Posts API rejects unknown body fields outright with
|
|
98
98
|
* `403 ACCESS_DENIED`. Adapters echo it back on `PublishResult` so the
|
|
99
99
|
* caller can dedupe retries against its own records.
|
|
100
100
|
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@venturekit-pro/social",
|
|
3
|
-
"version": "0.0.0-dev.
|
|
3
|
+
"version": "0.0.0-dev.20260816114351",
|
|
4
4
|
"description": "Social-platform publishing adapters + catalog for VentureKit applications",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -55,10 +55,10 @@
|
|
|
55
55
|
"publishing"
|
|
56
56
|
],
|
|
57
57
|
"dependencies": {
|
|
58
|
-
"@venturekit/core": "0.0.0-dev.
|
|
58
|
+
"@venturekit/core": "0.0.0-dev.20260816114351"
|
|
59
59
|
},
|
|
60
60
|
"peerDependencies": {
|
|
61
|
-
"@venturekit/data": "0.0.0-dev.
|
|
61
|
+
"@venturekit/data": "0.0.0-dev.20260816114351",
|
|
62
62
|
"sharp": ">=0.32"
|
|
63
63
|
},
|
|
64
64
|
"peerDependenciesMeta": {
|
|
@@ -71,7 +71,7 @@
|
|
|
71
71
|
},
|
|
72
72
|
"devDependencies": {
|
|
73
73
|
"@types/node": "^26.1.2",
|
|
74
|
-
"@venturekit/data": "0.0.0-dev.
|
|
74
|
+
"@venturekit/data": "0.0.0-dev.20260816114351",
|
|
75
75
|
"sharp": "^0.35.3",
|
|
76
76
|
"typescript": "^5.3.0"
|
|
77
77
|
},
|