universal-social-sdk 1.0.1 → 1.1.1

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 CHANGED
@@ -59,3 +59,14 @@ SOCIAL_SDK_MAX_RETRIES=3
59
59
  SOCIAL_SDK_RETRY_BASE_MS=500
60
60
  OLLAMA_HOST=http://127.0.0.1:11434
61
61
  OLLAMA_MODEL=llama3.2:3b
62
+ UPDATER_LLM_PROVIDER=openrouter
63
+ UPDATER_LLM_BASE_URL=https://openrouter.ai/api/v1
64
+ UPDATER_LLM_API_KEY=
65
+ UPDATER_LLM_MODEL=google/gemma-3-4b-it:free
66
+ UPDATER_LLM_APP_NAME=universal-social-sdk-updater
67
+ UPDATER_LLM_APP_URL=https://github.com/Gabo-Tech/universal-social-sdk
68
+ UPDATER_LLM_MAX_TOKENS=1200
69
+ UPDATER_LLM_MAX_DOC_CHARS_PER_PAGE=6000
70
+ UPDATER_LLM_MAX_ENDPOINT_ROWS_PER_PAGE=40
71
+ UPDATER_LLM_MAX_MODEL_ATTEMPTS=4
72
+ UPDATER_LLM_FALLBACK_MODELS=google/gemma-3-4b-it:free,qwen/qwen3-4b:free,openai/gpt-oss-20b:free
package/CHANGELOG.md CHANGED
@@ -7,6 +7,44 @@ and this project follows [Semantic Versioning](https://semver.org/spec/v2.0.0.ht
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ### Added
11
+
12
+ - Non-interactive updater mode for CI/automation (`--ci`, `--open-pr`, `--branch-prefix`, `--base`, `--artifacts-dir`).
13
+ - Structured updater artifacts (`.artifacts/update-plan.json`, `.artifacts/update-diff-summary.json`, `.artifacts/pr-title.txt`, `.artifacts/pr-body.md`).
14
+ - Strict Ollama patch-plan schema validation with typed `changes` metadata (platform, endpoint, change type, confidence).
15
+ - Updater LLM provider abstraction with OpenRouter support (`UPDATER_LLM_*`, `OPENROUTER_*`) while keeping legacy Ollama compatibility.
16
+ - Scheduled PR automation workflow: `.github/workflows/auto-update-pr.yml`.
17
+ - Workflow-dispatch `dry_run` mode for updater automation (detect and generate artifacts without opening PRs).
18
+ - Unit tests covering updater plan validation and no-change detection behavior.
19
+
20
+ ### Changed
21
+
22
+ - Updater CI mode now enforces `npm run build` and `npm run test:unit` before PR automation proceeds.
23
+ - Auto-update PR workflow now excludes `.artifacts/*` from commits while still using artifacts for PR metadata.
24
+
25
+ ## [1.1.0] - 2026-03-08
26
+
27
+ ### Added
28
+
29
+ - `src/webhooks` module with:
30
+ - Meta and X signature verification helpers
31
+ - normalized webhook event parsing helpers
32
+ - `WebhookRouter` for typed and wildcard event dispatch
33
+ - Unit tests for webhook verification, normalization, and routing.
34
+ - `src/queue` module with:
35
+ - `QueueAdapter` interface
36
+ - `InMemoryQueueAdapter`
37
+ - skeleton adapters for BullMQ and SQS
38
+ - queue adapter registry (`setQueueAdapter`, `getQueueAdapter`, `resetQueueAdapter`)
39
+ - Scheduler integration to route scheduled jobs through the active queue adapter.
40
+ - Unit tests for queue adapter registry and scheduler behavior.
41
+ - Added typed response interfaces and explicit return contracts across all public platform methods.
42
+ - Refined response contracts with platform-specific action/delete/result aliases for stronger API clarity.
43
+ - Added internal normalized result helpers so action/delete/mutation/detail responses remain stable even if upstream provider payloads drift.
44
+ - Added `docs/RESPONSE_CONTRACTS.md` with stable contract reference and integration guidance.
45
+ - Exported response interfaces from package root.
46
+ - Unit test coverage for typed response shapes.
47
+
10
48
  ## [1.0.1] - 2026-03-08
11
49
 
12
50
  ### Added
package/README.md CHANGED
@@ -9,7 +9,9 @@ TypeScript-first, ESM-only, zero-bloat Node.js SDK that provides one unified int
9
9
 
10
10
  - [Project Structure](./docs/PROJECT_STRUCTURE.md)
11
11
  - [NPM Package Guide](./docs/NPM_PACKAGE_GUIDE.md)
12
+ - [Response Contracts](./docs/RESPONSE_CONTRACTS.md)
12
13
  - [Contributing](./docs/CONTRIBUTING.md)
14
+ - [Roadmap v1.1.0](./docs/ROADMAP_v1.1.0.md)
13
15
  - [Code of Conduct](./CODE_OF_CONDUCT.md)
14
16
  - [Security Policy](./SECURITY.md)
15
17
  - [Changelog](./CHANGELOG.md)
@@ -55,6 +57,7 @@ Run bundled examples:
55
57
  npm run example:x
56
58
  npm run example:instagram
57
59
  npm run example:bluesky
60
+ npm run example:queue
58
61
  ```
59
62
 
60
63
  Files:
@@ -62,6 +65,60 @@ Files:
62
65
  - `examples/x-post.mjs`
63
66
  - `examples/instagram-reel.mjs`
64
67
  - `examples/bluesky-post.mjs`
68
+ - `examples/queue-in-memory.mjs`
69
+
70
+ ## Queue Adapters
71
+
72
+ The scheduler uses a queue adapter. By default it uses an in-memory adapter.
73
+
74
+ ```ts
75
+ import { InMemoryQueueAdapter, setQueueAdapter } from "universal-social-sdk";
76
+
77
+ setQueueAdapter(new InMemoryQueueAdapter());
78
+ ```
79
+
80
+ Adapter exports:
81
+
82
+ - `InMemoryQueueAdapter` (default behavior)
83
+ - `BullMQAdapter` (skeleton)
84
+ - `SQSAdapter` (skeleton)
85
+
86
+ The scheduler APIs (for example `X.scheduleTweet`) will use the active adapter automatically.
87
+
88
+ ## Typed Responses
89
+
90
+ All public SDK methods now return concrete TypeScript interfaces, including platform-specific action/delete aliases for clearer contracts.
91
+ Action/delete/mutation/detail responses are normalized into stable contracts (`success`, `action`/`targetId`/`resourceId`, `raw`) so provider endpoint changes are isolated to SDK internals.
92
+
93
+ ```ts
94
+ import { X } from "universal-social-sdk";
95
+ import type { XPostResult } from "universal-social-sdk";
96
+
97
+ const result: XPostResult = await X.postTweet({ text: "typed response" });
98
+ console.log(result.data.id);
99
+ ```
100
+
101
+ ## Webhooks
102
+
103
+ The SDK includes webhook utilities for Meta-style and X-style signatures, normalized event parsing, and a lightweight router.
104
+
105
+ ```ts
106
+ import {
107
+ WebhookRouter,
108
+ verifyMetaWebhookSignature,
109
+ verifyXWebhookSignature
110
+ } from "universal-social-sdk";
111
+
112
+ const router = new WebhookRouter();
113
+
114
+ router.on("meta.feed", async (event) => {
115
+ console.log("Meta feed event", event.payload);
116
+ });
117
+
118
+ router.on("x.tweet_create_events", async (event) => {
119
+ console.log("X tweet event", event.payload);
120
+ });
121
+ ```
65
122
 
66
123
  ## Required Environment Variables
67
124
 
@@ -135,8 +192,19 @@ Files:
135
192
 
136
193
  - `SOCIAL_SDK_MAX_RETRIES` (default `3`)
137
194
  - `SOCIAL_SDK_RETRY_BASE_MS` (default `500`)
138
- - `OLLAMA_HOST` (default `http://127.0.0.1:11434`)
139
- - `OLLAMA_MODEL` (default `llama3.2:3b`)
195
+ - `UPDATER_LLM_PROVIDER` (`openrouter` or `ollama`, default `openrouter` when API key is present, otherwise `ollama`)
196
+ - `UPDATER_LLM_BASE_URL` (default `https://openrouter.ai/api/v1`)
197
+ - `UPDATER_LLM_API_KEY` (or `OPENROUTER_API_KEY`)
198
+ - `UPDATER_LLM_MODEL` (or `OPENROUTER_MODEL`, default `google/gemma-3-4b-it:free` for OpenRouter, `llama3.2:3b` for Ollama)
199
+ - `UPDATER_LLM_APP_NAME` (optional request metadata)
200
+ - `UPDATER_LLM_APP_URL` (optional request metadata)
201
+ - `UPDATER_LLM_MAX_TOKENS` (default `1200`)
202
+ - `UPDATER_LLM_MAX_DOC_CHARS_PER_PAGE` (default `6000`)
203
+ - `UPDATER_LLM_MAX_ENDPOINT_ROWS_PER_PAGE` (default `40`)
204
+ - `UPDATER_LLM_MAX_MODEL_ATTEMPTS` (default `4`)
205
+ - `UPDATER_LLM_FALLBACK_MODELS` (comma-separated OpenRouter model IDs used after primary model fails)
206
+ - `OLLAMA_HOST` (legacy local runtime support, default `http://127.0.0.1:11434`)
207
+ - `OLLAMA_MODEL` (legacy local runtime support)
140
208
 
141
209
  ## CLI
142
210
 
@@ -161,17 +229,29 @@ npx universal-social-sdk update
161
229
  ```bash
162
230
  npx universal-social-sdk update --dry-run
163
231
  npx universal-social-sdk update --model llama3.2
232
+ npx universal-social-sdk update --fallback-models "google/gemma-3-4b-it:free,qwen/qwen3-4b:free"
233
+ npx universal-social-sdk update --max-model-attempts 5
164
234
  npx universal-social-sdk update --yes
235
+ npx universal-social-sdk update --ci --open-pr --base main --branch-prefix chore/updater
165
236
  ```
166
237
 
167
238
  Flow:
168
239
 
169
240
  1. Crawls official docs pages for X, Meta Graph API, Instagram Graph API, and LinkedIn.
170
241
  2. Extracts clean text and table-like endpoint data with Cheerio.
171
- 3. Sends doc snapshots to your local model runtime.
242
+ 3. Sends doc snapshots to your configured LLM provider (OpenRouter or local runtime).
243
+ - In OpenRouter mode, retries across a fallback model chain for `402/404/408/429` model-level failures with a short backoff between attempts.
172
244
  4. Requests generated method updates + full TypeScript file content.
173
- 5. Shows git-style diffs and asks for confirmation.
174
- 6. Applies patches and rebuilds package.
245
+ 5. Runs safety checks to reject suspicious placeholder rewrites or destructive class replacements.
246
+ 6. Shows git-style diffs and asks for confirmation.
247
+ 7. Applies patches and rebuilds package.
248
+
249
+ CI/PR mode writes deterministic artifacts in `.artifacts/`:
250
+
251
+ - `update-plan.json`
252
+ - `update-diff-summary.json`
253
+ - `pr-title.txt`
254
+ - `pr-body.md`
175
255
 
176
256
  ## Supported Methods
177
257
 
@@ -313,6 +393,12 @@ This repo includes:
313
393
 
314
394
  - `.github/workflows/ci.yml` for build + unit tests on every push/PR.
315
395
  - `.github/workflows/release.yml` for npm publish on tag (`v*`) or manual dispatch.
396
+ - `.github/workflows/auto-update-pr.yml` for scheduled doc crawling + updater PR generation.
397
+ - Generates `.artifacts/*` for PR metadata during the run but does not commit artifact files.
398
+
399
+ Manual dry-run option for updater workflow:
400
+
401
+ - In **Actions -> Auto Update PR -> Run workflow**, set `dry_run=true` to run detection and artifact generation only (no branch/PR).
316
402
 
317
403
  Configure these repository secrets to enable integration CI:
318
404
 
@@ -344,3 +430,18 @@ Configure these repository secrets to enable integration CI:
344
430
  Configure this repository secret for publishing:
345
431
 
346
432
  - `NPM_TOKEN`
433
+
434
+ Configure this repository secret for scheduled updater PRs:
435
+
436
+ - `UPDATER_LLM_PROVIDER` (`openrouter` or `ollama`)
437
+ - `UPDATER_LLM_API_KEY` (required for `openrouter`; or use `OPENROUTER_API_KEY`)
438
+ - `UPDATER_LLM_MODEL` (optional)
439
+ - `UPDATER_LLM_BASE_URL` (optional; defaults to OpenRouter URL)
440
+ - `UPDATER_LLM_MAX_TOKENS` (optional; cap completion size/cost)
441
+ - `UPDATER_LLM_MAX_MODEL_ATTEMPTS` (optional)
442
+ - `UPDATER_LLM_FALLBACK_MODELS` (optional comma-separated model chain)
443
+
444
+ Alternative OpenRouter-compatible secret names also supported:
445
+
446
+ - `OPENROUTER_API_KEY`
447
+ - `OPENROUTER_MODEL`