universal-social-sdk 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/.env.example ADDED
@@ -0,0 +1,61 @@
1
+ # X / Twitter
2
+ X_API_KEY=
3
+ X_API_SECRET=
4
+ X_ACCESS_TOKEN=
5
+ X_ACCESS_SECRET=
6
+ X_BEARER_TOKEN=
7
+ X_CLIENT_ID=
8
+ X_CLIENT_SECRET=
9
+
10
+ # Facebook Pages + Instagram Graph (Meta)
11
+ META_APP_ID=
12
+ META_APP_SECRET=
13
+ FB_PAGE_ACCESS_TOKEN=
14
+ FB_PAGE_ID=
15
+ IG_ACCESS_TOKEN=
16
+ IG_USER_ID=
17
+ META_GRAPH_VERSION=v21.0
18
+
19
+ # LinkedIn
20
+ LINKEDIN_ACCESS_TOKEN=
21
+ LINKEDIN_REFRESH_TOKEN=
22
+ LINKEDIN_CLIENT_ID=
23
+ LINKEDIN_CLIENT_SECRET=
24
+ LINKEDIN_ORG_URN=
25
+ LINKEDIN_PERSON_URN=
26
+ LINKEDIN_API_VERSION=202510
27
+
28
+ # YouTube
29
+ YOUTUBE_ACCESS_TOKEN=
30
+ YOUTUBE_CHANNEL_ID=
31
+
32
+ # TikTok
33
+ TIKTOK_ACCESS_TOKEN=
34
+ TIKTOK_OPEN_ID=
35
+ TIKTOK_ADVERTISER_ID=
36
+
37
+ # Pinterest
38
+ PINTEREST_ACCESS_TOKEN=
39
+ PINTEREST_BOARD_ID=
40
+
41
+ # Bluesky
42
+ BLUESKY_SERVICE_URL=https://bsky.social
43
+ BLUESKY_IDENTIFIER=
44
+ BLUESKY_APP_PASSWORD=
45
+ BLUESKY_ACCESS_JWT=
46
+ BLUESKY_REFRESH_JWT=
47
+
48
+ # Mastodon
49
+ MASTODON_BASE_URL=
50
+ MASTODON_ACCESS_TOKEN=
51
+ MASTODON_ACCOUNT_ID=
52
+
53
+ # Threads
54
+ THREADS_ACCESS_TOKEN=
55
+ THREADS_USER_ID=
56
+
57
+ # SDK behavior
58
+ SOCIAL_SDK_MAX_RETRIES=3
59
+ SOCIAL_SDK_RETRY_BASE_MS=500
60
+ OLLAMA_HOST=http://127.0.0.1:11434
61
+ OLLAMA_MODEL=llama3.2:3b
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Gabo-Tech
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,329 @@
1
+ # universal-social-sdk
2
+
3
+ TypeScript-first, ESM-only, zero-bloat Node.js SDK that provides one unified interface for X, Facebook, Instagram, LinkedIn, YouTube, TikTok, Pinterest, Bluesky, Mastodon, and Threads.
4
+
5
+ [![CI](https://github.com/Gabo-Tech/universal-social-sdk/actions/workflows/ci.yml/badge.svg)](https://github.com/Gabo-Tech/universal-social-sdk/actions/workflows/ci.yml)
6
+ [![Release](https://github.com/Gabo-Tech/universal-social-sdk/actions/workflows/release.yml/badge.svg)](https://github.com/Gabo-Tech/universal-social-sdk/actions/workflows/release.yml)
7
+
8
+ ## Documentation
9
+
10
+ - [Project Structure](./docs/PROJECT_STRUCTURE.md)
11
+ - [NPM Package Guide](./docs/NPM_PACKAGE_GUIDE.md)
12
+ - [Contributing](./docs/CONTRIBUTING.md)
13
+ - [Code of Conduct](./CODE_OF_CONDUCT.md)
14
+ - [Security Policy](./SECURITY.md)
15
+
16
+ ## Install
17
+
18
+ ```bash
19
+ npm install universal-social-sdk
20
+ ```
21
+
22
+ ## Quick Start
23
+
24
+ ```ts
25
+ import { Instagram, X, Facebook, LinkedIn } from "universal-social-sdk";
26
+
27
+ await X.postTweet({ text: "Hello from universal SDK!" });
28
+ await Instagram.uploadReel({
29
+ videoUrl: "https://example.com/reel.mp4",
30
+ caption: "Hello world"
31
+ });
32
+ await Facebook.publishToPage({
33
+ message: "Shipping updates from one SDK"
34
+ });
35
+ await LinkedIn.createTextPost({
36
+ text: "Cross-platform publishing with one API"
37
+ });
38
+
39
+ import { YouTube, TikTok, Pinterest, Bluesky, Mastodon, Threads } from "universal-social-sdk";
40
+
41
+ await YouTube.listMyVideos({ maxResults: 5 });
42
+ await TikTok.listVideos({ maxCount: 10 });
43
+ await Pinterest.listBoards({});
44
+ await Bluesky.postText({ text: "Hello AT Protocol!" });
45
+ await Mastodon.createStatus({ text: "Hello Fediverse!" });
46
+ await Threads.postText({ text: "Hello Threads!" });
47
+ ```
48
+
49
+ ## Required Environment Variables
50
+
51
+ `universal-social-sdk` auto-loads `.env` with `dotenv`.
52
+
53
+ ### X / Twitter
54
+
55
+ - `X_API_KEY`
56
+ - `X_API_SECRET`
57
+ - `X_ACCESS_TOKEN`
58
+ - `X_ACCESS_SECRET`
59
+ - `X_BEARER_TOKEN` (optional for some read-only operations)
60
+ - `X_CLIENT_ID` (OAuth 2 workflows)
61
+ - `X_CLIENT_SECRET` (OAuth 2 workflows)
62
+
63
+ ### Meta (Facebook Pages + Instagram Graph)
64
+
65
+ - `META_APP_ID`
66
+ - `META_APP_SECRET`
67
+ - `FB_PAGE_ACCESS_TOKEN`
68
+ - `FB_PAGE_ID`
69
+ - `IG_ACCESS_TOKEN`
70
+ - `IG_USER_ID`
71
+ - `META_GRAPH_VERSION` (default `v21.0`)
72
+
73
+ ### LinkedIn
74
+
75
+ - `LINKEDIN_ACCESS_TOKEN`
76
+ - `LINKEDIN_REFRESH_TOKEN` (recommended for long-running apps)
77
+ - `LINKEDIN_CLIENT_ID`
78
+ - `LINKEDIN_CLIENT_SECRET`
79
+ - `LINKEDIN_ORG_URN` or `LINKEDIN_PERSON_URN`
80
+ - `LINKEDIN_API_VERSION` (default `202510`)
81
+
82
+ ### YouTube
83
+
84
+ - `YOUTUBE_ACCESS_TOKEN`
85
+ - `YOUTUBE_CHANNEL_ID`
86
+
87
+ ### TikTok
88
+
89
+ - `TIKTOK_ACCESS_TOKEN`
90
+ - `TIKTOK_OPEN_ID`
91
+ - `TIKTOK_ADVERTISER_ID`
92
+
93
+ ### Pinterest
94
+
95
+ - `PINTEREST_ACCESS_TOKEN`
96
+ - `PINTEREST_BOARD_ID`
97
+
98
+ ### Bluesky
99
+
100
+ - `BLUESKY_SERVICE_URL` (default `https://bsky.social`)
101
+ - `BLUESKY_IDENTIFIER`
102
+ - `BLUESKY_APP_PASSWORD`
103
+ - `BLUESKY_ACCESS_JWT`
104
+ - `BLUESKY_REFRESH_JWT`
105
+
106
+ ### Mastodon
107
+
108
+ - `MASTODON_BASE_URL`
109
+ - `MASTODON_ACCESS_TOKEN`
110
+ - `MASTODON_ACCOUNT_ID`
111
+
112
+ ### Threads
113
+
114
+ - `THREADS_ACCESS_TOKEN`
115
+ - `THREADS_USER_ID`
116
+
117
+ ### SDK / Updater
118
+
119
+ - `SOCIAL_SDK_MAX_RETRIES` (default `3`)
120
+ - `SOCIAL_SDK_RETRY_BASE_MS` (default `500`)
121
+ - `OLLAMA_HOST` (default `http://127.0.0.1:11434`)
122
+ - `OLLAMA_MODEL` (default `llama3.2:3b`)
123
+
124
+ ## CLI
125
+
126
+ ### Bootstrap
127
+
128
+ ```bash
129
+ npx universal-social-sdk init
130
+ ```
131
+
132
+ Creates `.env.example`, copies it to `.env` if missing, and prints OAuth setup links:
133
+
134
+ - X Developer Portal: <https://developer.x.com/en/portal/dashboard>
135
+ - Meta Developers: <https://developers.facebook.com/apps/>
136
+ - LinkedIn Developers: <https://www.linkedin.com/developers/apps>
137
+
138
+ ### Documentation Updater
139
+
140
+ ```bash
141
+ npx universal-social-sdk update
142
+ ```
143
+
144
+ ```bash
145
+ npx universal-social-sdk update --dry-run
146
+ npx universal-social-sdk update --model llama3.2
147
+ npx universal-social-sdk update --yes
148
+ ```
149
+
150
+ Flow:
151
+
152
+ 1. Crawls official docs pages for X, Meta Graph API, Instagram Graph API, and LinkedIn.
153
+ 2. Extracts clean text and table-like endpoint data with Cheerio.
154
+ 3. Sends doc snapshots to your local model runtime.
155
+ 4. Requests generated method updates + full TypeScript file content.
156
+ 5. Shows git-style diffs and asks for confirmation.
157
+ 6. Applies patches and rebuilds package.
158
+
159
+ ## Supported Methods
160
+
161
+ Method coverage by platform:
162
+
163
+ - `X`: posting, threads, replies, quote posts, likes, retweets, DMs, analytics, scheduling
164
+ - `Facebook`: page publishing, stories, comments, reactions, insights, scheduled posts
165
+ - `Instagram`: media/reels/stories, carousels, comments, moderation, insights
166
+ - `LinkedIn`: text/image/video/carousel posts, comments, likes, analytics, media upload
167
+ - `YouTube`: upload sessions, metadata updates, playlists, comments, channel analytics
168
+ - `TikTok`: video publish flow, comments/replies, likes, status checks, analytics
169
+ - `Pinterest`: pin/board management, comments/replies, pin/account analytics
170
+ - `Bluesky`: text posts, links, replies, likes/reposts, feed/search/thread retrieval
171
+ - `Mastodon`: statuses, media posts, favourites/boosts, context, scheduling
172
+ - `Threads`: text/image/video posts, replies, likes, thread/account insights
173
+
174
+ Complete method list is maintained in `supported-methods.json`.
175
+
176
+ ## OAuth Setup Guide
177
+
178
+ ### X
179
+
180
+ 1. Open <https://developer.x.com/en/portal/dashboard>.
181
+ 2. Create a Project and App.
182
+ 3. Enable OAuth 1.0a and OAuth 2.0, then generate user tokens.
183
+ 4. Add credentials into `.env`.
184
+ 5. Screenshot to keep: App keys and user token generation page.
185
+
186
+ ### Meta (Facebook + Instagram Graph)
187
+
188
+ 1. Open <https://developers.facebook.com/apps/>.
189
+ 2. Create app, add Facebook Login + Instagram Graph API products.
190
+ 3. Get Page access token (`pages_manage_posts`, `pages_read_engagement`, etc.).
191
+ 4. Map Page to Instagram professional account and capture `IG_USER_ID`.
192
+ 5. Screenshot to keep: App Review permissions and Access Token Debugger output.
193
+
194
+ ### LinkedIn
195
+
196
+ 1. Open <https://www.linkedin.com/developers/apps>.
197
+ 2. Create app and add Marketing APIs / Community Management products.
198
+ 3. Configure OAuth 2.0 redirect URLs and request required scopes.
199
+ 4. Exchange auth code for access token (and refresh token if enabled).
200
+ 5. Screenshot to keep: Products enabled page + OAuth scopes configuration.
201
+
202
+ ### YouTube
203
+
204
+ 1. Open <https://console.cloud.google.com/apis/library/youtube.googleapis.com>.
205
+ 2. Enable YouTube Data API v3 for your project.
206
+ 3. Configure OAuth consent and create OAuth client credentials.
207
+ 4. Exchange user authorization for `YOUTUBE_ACCESS_TOKEN`.
208
+
209
+ ### TikTok
210
+
211
+ 1. Open <https://developers.tiktok.com/>.
212
+ 2. Create app, configure login scopes and redirect URI.
213
+ 3. Complete OAuth flow and store long-lived `TIKTOK_ACCESS_TOKEN`.
214
+
215
+ ### Pinterest
216
+
217
+ 1. Open <https://developers.pinterest.com/>.
218
+ 2. Create app and configure OAuth redirect URI/scopes.
219
+ 3. Obtain `PINTEREST_ACCESS_TOKEN` and target `PINTEREST_BOARD_ID`.
220
+
221
+ ### Bluesky
222
+
223
+ 1. Open <https://bsky.app/settings/app-passwords>.
224
+ 2. Create an app password for your account.
225
+ 3. Set `BLUESKY_IDENTIFIER` and `BLUESKY_APP_PASSWORD`.
226
+
227
+ ### Mastodon
228
+
229
+ 1. Register an application on your Mastodon instance.
230
+ 2. Generate an access token with write/read scopes.
231
+ 3. Set `MASTODON_BASE_URL`, `MASTODON_ACCESS_TOKEN`, and `MASTODON_ACCOUNT_ID`.
232
+
233
+ ### Threads
234
+
235
+ 1. Open <https://developers.facebook.com/docs/threads>.
236
+ 2. Create app, request Threads API scopes, and generate user token.
237
+ 3. Set `THREADS_ACCESS_TOKEN` and `THREADS_USER_ID`.
238
+
239
+ ## Error Handling
240
+
241
+ All errors are normalized to `SocialError`.
242
+
243
+ ```ts
244
+ import { SocialError, X } from "universal-social-sdk";
245
+
246
+ try {
247
+ await X.postTweet({ text: "hello" });
248
+ } catch (error) {
249
+ if (error instanceof SocialError) {
250
+ console.error(error.platform, error.endpoint, error.message, error.statusCode);
251
+ }
252
+ }
253
+ ```
254
+
255
+ ## Rate Limit Handling
256
+
257
+ - Automatic retries on `429` and `5xx`.
258
+ - Exponential backoff defaults: `500ms`, `1000ms`, `2000ms`.
259
+ - Configure with:
260
+ - `SOCIAL_SDK_MAX_RETRIES`
261
+ - `SOCIAL_SDK_RETRY_BASE_MS`
262
+
263
+ ## Legal / Terms Notes
264
+
265
+ - You must comply with each platform’s Terms of Use, policy docs, and display requirements.
266
+ - Some actions require app review, partner approval, business verification, or specific account types.
267
+ - Messaging APIs (especially DMs) are often restricted to approved use cases.
268
+
269
+ ## Testing
270
+
271
+ ```bash
272
+ npm run test:unit
273
+ npm run test:integration
274
+ ```
275
+
276
+ Integration tests are environment-gated. Create `.env.test` from `.env.test.example` and use sandbox credentials.
277
+
278
+ ### Integration Test Env Matrix
279
+
280
+ | Platform | Required `.env.test` keys | Required CI secrets |
281
+ | --- | --- | --- |
282
+ | X | `X_API_KEY`, `X_API_SECRET`, `X_ACCESS_TOKEN`, `X_ACCESS_SECRET`, `X_TEST_TWEET_ID` | `X_API_KEY`, `X_API_SECRET`, `X_ACCESS_TOKEN`, `X_ACCESS_SECRET`, `X_TEST_TWEET_ID` |
283
+ | Facebook | `FB_PAGE_ACCESS_TOKEN`, `FB_PAGE_ID` | `FB_PAGE_ACCESS_TOKEN`, `FB_PAGE_ID` |
284
+ | Instagram | `IG_ACCESS_TOKEN`, `IG_USER_ID` | `IG_ACCESS_TOKEN`, `IG_USER_ID` |
285
+ | LinkedIn | `LINKEDIN_ACCESS_TOKEN`, `LINKEDIN_ORG_URN` | `LINKEDIN_ACCESS_TOKEN`, `LINKEDIN_ORG_URN` |
286
+ | YouTube | `YOUTUBE_ACCESS_TOKEN`, `YOUTUBE_CHANNEL_ID` | `YOUTUBE_ACCESS_TOKEN`, `YOUTUBE_CHANNEL_ID` |
287
+ | TikTok | `TIKTOK_ACCESS_TOKEN` | `TIKTOK_ACCESS_TOKEN` |
288
+ | Pinterest | `PINTEREST_ACCESS_TOKEN`, `PINTEREST_BOARD_ID` | `PINTEREST_ACCESS_TOKEN`, `PINTEREST_BOARD_ID` |
289
+ | Bluesky | `BLUESKY_IDENTIFIER`, `BLUESKY_APP_PASSWORD` (`BLUESKY_TEST_ACTOR` optional) | `BLUESKY_IDENTIFIER`, `BLUESKY_APP_PASSWORD`, `BLUESKY_TEST_ACTOR` |
290
+ | Mastodon | `MASTODON_BASE_URL`, `MASTODON_ACCESS_TOKEN`, `MASTODON_ACCOUNT_ID` | `MASTODON_BASE_URL`, `MASTODON_ACCESS_TOKEN`, `MASTODON_ACCOUNT_ID` |
291
+ | Threads | `THREADS_ACCESS_TOKEN`, `THREADS_USER_ID` | `THREADS_ACCESS_TOKEN`, `THREADS_USER_ID` |
292
+
293
+ ## GitHub Actions
294
+
295
+ This repo includes:
296
+
297
+ - `.github/workflows/ci.yml` for build + unit tests on every push/PR.
298
+ - `.github/workflows/release.yml` for npm publish on tag (`v*`) or manual dispatch.
299
+
300
+ Configure these repository secrets to enable integration CI:
301
+
302
+ - `X_API_KEY`
303
+ - `X_API_SECRET`
304
+ - `X_ACCESS_TOKEN`
305
+ - `X_ACCESS_SECRET`
306
+ - `X_TEST_TWEET_ID`
307
+ - `FB_PAGE_ACCESS_TOKEN`
308
+ - `FB_PAGE_ID`
309
+ - `IG_ACCESS_TOKEN`
310
+ - `IG_USER_ID`
311
+ - `LINKEDIN_ACCESS_TOKEN`
312
+ - `LINKEDIN_ORG_URN`
313
+ - `YOUTUBE_ACCESS_TOKEN`
314
+ - `YOUTUBE_CHANNEL_ID`
315
+ - `TIKTOK_ACCESS_TOKEN`
316
+ - `PINTEREST_ACCESS_TOKEN`
317
+ - `PINTEREST_BOARD_ID`
318
+ - `BLUESKY_IDENTIFIER`
319
+ - `BLUESKY_APP_PASSWORD`
320
+ - `BLUESKY_TEST_ACTOR` (optional; defaults to `BLUESKY_IDENTIFIER` when omitted)
321
+ - `MASTODON_BASE_URL`
322
+ - `MASTODON_ACCESS_TOKEN`
323
+ - `MASTODON_ACCOUNT_ID`
324
+ - `THREADS_ACCESS_TOKEN`
325
+ - `THREADS_USER_ID`
326
+
327
+ Configure this repository secret for publishing:
328
+
329
+ - `NPM_TOKEN`
@@ -0,0 +1 @@
1
+ #!/usr/bin/env node