thumbgate 1.4.3 → 1.4.5
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/.claude-plugin/marketplace.json +2 -2
- package/.claude-plugin/plugin.json +1 -1
- package/.well-known/llms.txt +12 -8
- package/.well-known/mcp/server-card.json +1 -1
- package/README.md +18 -8
- package/adapters/README.md +1 -1
- package/adapters/claude/.mcp.json +2 -2
- package/adapters/codex/config.toml +2 -2
- package/adapters/mcp/server-stdio.js +1 -1
- package/adapters/opencode/opencode.json +1 -1
- package/config/github-about.json +2 -2
- package/package.json +158 -10
- package/scripts/billing.js +5 -2
- package/scripts/statusline.sh +1 -0
- package/src/api/server.js +113 -16
- package/src/index.js +3 -0
- package/.claude-plugin/bundle/icon.png +0 -0
- package/.claude-plugin/bundle/icon.svg +0 -18
- package/.claude-plugin/bundle/server/index.js +0 -24
- package/adapters/chatgpt/INSTALL.md +0 -158
- package/adapters/perplexity/.mcp.json +0 -36
- package/adapters/perplexity/config.toml +0 -16
- package/adapters/perplexity/opencode.json +0 -29
- package/bin/memory.sh +0 -64
- package/bin/obsidian-sync.sh +0 -20
- package/plugins/amp-skill/INSTALL.md +0 -52
- package/plugins/amp-skill/SKILL.md +0 -64
- package/plugins/claude-codex-bridge/.claude-plugin/plugin.json +0 -22
- package/plugins/claude-codex-bridge/.mcp.json +0 -14
- package/plugins/claude-codex-bridge/INSTALL.md +0 -43
- package/plugins/claude-codex-bridge/README.md +0 -46
- package/plugins/claude-codex-bridge/scripts/codex-bridge.js +0 -286
- package/plugins/claude-codex-bridge/skills/adversarial-review/SKILL.md +0 -24
- package/plugins/claude-codex-bridge/skills/result/SKILL.md +0 -22
- package/plugins/claude-codex-bridge/skills/review/SKILL.md +0 -28
- package/plugins/claude-codex-bridge/skills/second-pass/SKILL.md +0 -27
- package/plugins/claude-codex-bridge/skills/setup/SKILL.md +0 -21
- package/plugins/claude-codex-bridge/skills/status/SKILL.md +0 -19
- package/plugins/claude-skill/INSTALL.md +0 -55
- package/plugins/claude-skill/SKILL.md +0 -46
- package/plugins/codex-profile/.codex-plugin/plugin.json +0 -43
- package/plugins/codex-profile/.mcp.json +0 -14
- package/plugins/codex-profile/AGENTS.md +0 -20
- package/plugins/codex-profile/INSTALL.md +0 -89
- package/plugins/codex-profile/README.md +0 -61
- package/plugins/cursor-marketplace/.cursor-plugin/plugin.json +0 -23
- package/plugins/cursor-marketplace/CHANGELOG.md +0 -30
- package/plugins/cursor-marketplace/LICENSE +0 -21
- package/plugins/cursor-marketplace/README.md +0 -124
- package/plugins/cursor-marketplace/agents/reliability-reviewer.md +0 -31
- package/plugins/cursor-marketplace/assets/logo-400x400.png +0 -0
- package/plugins/cursor-marketplace/commands/capture-feedback.md +0 -33
- package/plugins/cursor-marketplace/commands/check-gates.md +0 -25
- package/plugins/cursor-marketplace/commands/show-lessons.md +0 -27
- package/plugins/cursor-marketplace/hooks/hooks.json +0 -10
- package/plugins/cursor-marketplace/mcp.json +0 -14
- package/plugins/cursor-marketplace/rules/feedback-capture.mdc +0 -34
- package/plugins/cursor-marketplace/rules/pre-action-gates.mdc +0 -30
- package/plugins/cursor-marketplace/rules/session-continuity.mdc +0 -28
- package/plugins/cursor-marketplace/scripts/gate-check.sh +0 -21
- package/plugins/cursor-marketplace/skills/capture-feedback/SKILL.md +0 -48
- package/plugins/cursor-marketplace/skills/prevention-rules/SKILL.md +0 -31
- package/plugins/cursor-marketplace/skills/recall-context/SKILL.md +0 -30
- package/plugins/cursor-marketplace/skills/search-lessons/SKILL.md +0 -33
- package/plugins/gemini-extension/INSTALL.md +0 -92
- package/plugins/gemini-extension/gemini_prompt.txt +0 -14
- package/plugins/gemini-extension/tool_contract.json +0 -45
- package/plugins/opencode-profile/INSTALL.md +0 -57
- package/public/assets/instagram-card.png +0 -0
- package/public/assets/tiktok-agent-memory.mp4 +0 -0
- package/public/blog.html +0 -474
- package/public/compare/mem0.html +0 -189
- package/public/compare/speclock.html +0 -180
- package/public/compare.html +0 -310
- package/public/dashboard.html +0 -1100
- package/public/guide.html +0 -317
- package/public/guides/claude-code-prevent-repeated-mistakes.html +0 -161
- package/public/guides/codex-cli-guardrails.html +0 -158
- package/public/guides/cursor-prevent-repeated-mistakes.html +0 -161
- package/public/guides/pre-action-gates.html +0 -162
- package/public/guides/stop-repeated-ai-agent-mistakes.html +0 -159
- package/public/index.html +0 -1225
- package/public/js/buyer-intent.js +0 -252
- package/public/learn/agent-harness-pattern.html +0 -180
- package/public/learn/ai-agent-persistent-memory.html +0 -203
- package/public/learn/learn.css +0 -45
- package/public/learn/mcp-pre-action-gates-explained.html +0 -172
- package/public/learn/stop-ai-agent-force-push.html +0 -134
- package/public/learn/vibe-coding-safety-net.html +0 -142
- package/public/learn.html +0 -274
- package/public/lessons.html +0 -967
- package/public/llm-context.md +0 -156
- package/public/pro.html +0 -1087
- package/public/vercel.json +0 -8
- package/scripts/a2ui-engine.js +0 -73
- package/scripts/adk-consolidator.js +0 -274
- package/scripts/agent-security-hardening.js +0 -225
- package/scripts/ai-search-visibility.js +0 -116
- package/scripts/autonomous-sales-agent.js +0 -39
- package/scripts/autoresearch-runner.js +0 -216
- package/scripts/background-agent-governance.js +0 -229
- package/scripts/behavioral-extraction.js +0 -93
- package/scripts/budget-enforcer.js +0 -173
- package/scripts/budget-guard.js +0 -173
- package/scripts/build-claude-mcpb.js +0 -255
- package/scripts/build-codex-plugin.js +0 -152
- package/scripts/capture-railway-diagnostics.sh +0 -97
- package/scripts/changeset-check.js +0 -372
- package/scripts/check-congruence.js +0 -443
- package/scripts/computer-use-firewall.js +0 -280
- package/scripts/content-engine/linkedin-content-generator.js +0 -154
- package/scripts/content-engine/output/linkedin-memento-validation.md +0 -17
- package/scripts/content-engine/output/linkedin-posts-2026-04-09.md +0 -175
- package/scripts/content-engine/reddit-thread-finder.js +0 -154
- package/scripts/context-engine.js +0 -710
- package/scripts/daily-digest.js +0 -11
- package/scripts/data-governance.js +0 -173
- package/scripts/deploy-gcp.sh +0 -44
- package/scripts/deploy-policy.js +0 -249
- package/scripts/disagreement-mining.js +0 -315
- package/scripts/dpo-optimizer.js +0 -206
- package/scripts/ensure-repo-bootstrap.js +0 -130
- package/scripts/ephemeral-agent-store.js +0 -212
- package/scripts/eval-harness.js +0 -56
- package/scripts/export-kto-pairs.js +0 -309
- package/scripts/export-training.js +0 -446
- package/scripts/feedback-fallback.js +0 -111
- package/scripts/feedback-inbox-read.js +0 -162
- package/scripts/feedback-root-consolidator.js +0 -233
- package/scripts/feedback-to-memory.js +0 -185
- package/scripts/gate-satisfy.js +0 -42
- package/scripts/generate-paperbanana-diagrams.sh +0 -99
- package/scripts/generate-pretool-hook.sh +0 -40
- package/scripts/github-about.js +0 -430
- package/scripts/github-outreach.js +0 -65
- package/scripts/gtm-revenue-loop.js +0 -535
- package/scripts/hallucination-detector.js +0 -226
- package/scripts/hf-papers.js +0 -317
- package/scripts/hook-auto-capture.sh +0 -100
- package/scripts/hook-stop-pr-thread-check.sh +0 -68
- package/scripts/hook-stop-self-score.sh +0 -51
- package/scripts/hook-stop-verify-deploy.sh +0 -31
- package/scripts/hook-verify-before-done.sh +0 -20
- package/scripts/managed-dpo-export.js +0 -91
- package/scripts/markdown-escape.js +0 -12
- package/scripts/marketing-experiment.js +0 -657
- package/scripts/memalign-recall.js +0 -111
- package/scripts/memory-migration.js +0 -296
- package/scripts/meta-policy.js +0 -190
- package/scripts/metered-billing.js +0 -16
- package/scripts/model-tier-router.js +0 -310
- package/scripts/money-watcher.js +0 -218
- package/scripts/multi-hop-recall.js +0 -240
- package/scripts/per-step-scoring.js +0 -163
- package/scripts/perplexity-command-center.js +0 -644
- package/scripts/perplexity-marketing.js +0 -454
- package/scripts/pii-scanner.js +0 -153
- package/scripts/plan-gate.js +0 -154
- package/scripts/post-everywhere.js +0 -341
- package/scripts/post-to-x-retry.sh +0 -22
- package/scripts/post-to-x.js +0 -369
- package/scripts/pr-manager.js +0 -421
- package/scripts/principle-extractor.js +0 -162
- package/scripts/pro-features.js +0 -41
- package/scripts/prompt-dlp.js +0 -222
- package/scripts/prove-adapters.js +0 -860
- package/scripts/prove-attribution.js +0 -361
- package/scripts/prove-automation.js +0 -651
- package/scripts/prove-autoresearch.js +0 -304
- package/scripts/prove-claim-verification.js +0 -277
- package/scripts/prove-cloudflare-sandbox.js +0 -161
- package/scripts/prove-data-pipeline.js +0 -408
- package/scripts/prove-data-quality.js +0 -227
- package/scripts/prove-evolution.js +0 -352
- package/scripts/prove-harnesses.js +0 -287
- package/scripts/prove-intelligence.js +0 -257
- package/scripts/prove-lancedb.js +0 -425
- package/scripts/prove-local-intelligence.js +0 -340
- package/scripts/prove-loop-closure.js +0 -263
- package/scripts/prove-packaged-runtime.js +0 -327
- package/scripts/prove-predictive-insights.js +0 -355
- package/scripts/prove-runtime.js +0 -363
- package/scripts/prove-seo-gsd.js +0 -234
- package/scripts/prove-settings.js +0 -279
- package/scripts/prove-subway-upgrades.js +0 -277
- package/scripts/prove-tessl.js +0 -229
- package/scripts/prove-training-export.js +0 -325
- package/scripts/prove-workflow-contract.js +0 -112
- package/scripts/prove-xmemory.js +0 -332
- package/scripts/publish-decision.js +0 -159
- package/scripts/ralph-loop.js +0 -376
- package/scripts/ralph-mode-ci.js +0 -434
- package/scripts/reddit-dm-outreach.js +0 -192
- package/scripts/reddit-monitor-cron.sh +0 -26
- package/scripts/reminder-engine.js +0 -132
- package/scripts/revenue-status.js +0 -472
- package/scripts/rotate-stripe-webhook-secret.js +0 -314
- package/scripts/schedule-manager.js +0 -249
- package/scripts/self-healing-check.js +0 -193
- package/scripts/session-analyzer.js +0 -533
- package/scripts/shieldcortex-memory-firewall-runner.mjs +0 -53
- package/scripts/skill-exporter.js +0 -260
- package/scripts/skill-materializer.js +0 -134
- package/scripts/skill-packs.js +0 -136
- package/scripts/skill-proposer.js +0 -99
- package/scripts/skill-quality-tracker.js +0 -282
- package/scripts/slow-loop.js +0 -72
- package/scripts/social-analytics/db/marketing-db.js +0 -179
- package/scripts/social-analytics/db/schema.sql +0 -55
- package/scripts/social-analytics/digest.js +0 -256
- package/scripts/social-analytics/engagement-audit.js +0 -185
- package/scripts/social-analytics/generate-instagram-card.js +0 -123
- package/scripts/social-analytics/generate-slides.js +0 -268
- package/scripts/social-analytics/instagram-thumbgate-post.js +0 -111
- package/scripts/social-analytics/install-growth-automation.js +0 -114
- package/scripts/social-analytics/load-env.js +0 -77
- package/scripts/social-analytics/mcp-server.js +0 -289
- package/scripts/social-analytics/normalizer.js +0 -580
- package/scripts/social-analytics/notify.js +0 -162
- package/scripts/social-analytics/poll-all.js +0 -107
- package/scripts/social-analytics/pollers/github.js +0 -195
- package/scripts/social-analytics/pollers/instagram.js +0 -253
- package/scripts/social-analytics/pollers/linkedin.js +0 -340
- package/scripts/social-analytics/pollers/plausible.js +0 -245
- package/scripts/social-analytics/pollers/reddit.js +0 -306
- package/scripts/social-analytics/pollers/threads.js +0 -233
- package/scripts/social-analytics/pollers/tiktok.js +0 -203
- package/scripts/social-analytics/pollers/x.js +0 -227
- package/scripts/social-analytics/pollers/youtube.js +0 -304
- package/scripts/social-analytics/pollers/zernio.js +0 -183
- package/scripts/social-analytics/post-video.js +0 -316
- package/scripts/social-analytics/publish-instagram-thumbgate.js +0 -104
- package/scripts/social-analytics/publish-thumbgate-launch.js +0 -322
- package/scripts/social-analytics/publishers/devto.js +0 -122
- package/scripts/social-analytics/publishers/instagram.js +0 -317
- package/scripts/social-analytics/publishers/linkedin.js +0 -294
- package/scripts/social-analytics/publishers/reddit.js +0 -385
- package/scripts/social-analytics/publishers/threads.js +0 -275
- package/scripts/social-analytics/publishers/tiktok.js +0 -217
- package/scripts/social-analytics/publishers/x.js +0 -259
- package/scripts/social-analytics/publishers/youtube.js +0 -223
- package/scripts/social-analytics/publishers/zernio.js +0 -568
- package/scripts/social-analytics/reconcile-thumbgate-campaign.js +0 -165
- package/scripts/social-analytics/run-digest.js +0 -34
- package/scripts/social-analytics/schedule-thumbgate-campaign.js +0 -275
- package/scripts/social-analytics/store.js +0 -455
- package/scripts/social-analytics/sync-launch-assets.js +0 -185
- package/scripts/social-analytics/utm.js +0 -143
- package/scripts/social-pipeline.js +0 -2626
- package/scripts/social-post-hourly.js +0 -228
- package/scripts/social-quality-gate.js +0 -134
- package/scripts/social-reply-monitor.js +0 -592
- package/scripts/status-dashboard.js +0 -155
- package/scripts/stripe-live-status.js +0 -115
- package/scripts/subagent-profiles.js +0 -79
- package/scripts/sync-branch-protection.js +0 -340
- package/scripts/sync-gh-secrets-from-env.sh +0 -70
- package/scripts/sync-github-about.js +0 -55
- package/scripts/sync-version.js +0 -479
- package/scripts/synthetic-dpo.js +0 -234
- package/scripts/tessl-export.js +0 -369
- package/scripts/test-coverage.js +0 -128
- package/scripts/thumbgate-bench.js +0 -494
- package/scripts/thumbgate_session_start.sh +0 -32
- package/scripts/train_from_feedback.py +0 -929
- package/scripts/validate-feedback.js +0 -581
- package/scripts/verify-obsidian-setup.sh +0 -269
- package/scripts/verify-run.js +0 -269
- package/scripts/weekly-auto-post.js +0 -124
- package/scripts/x-autonomous-marketing.js +0 -139
|
@@ -1,568 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* zernio.js
|
|
5
|
-
* Unified publisher via Zernio API.
|
|
6
|
-
*
|
|
7
|
-
* Required env vars:
|
|
8
|
-
* ZERNIO_API_KEY — Bearer token for https://zernio.com/api/v1
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
const fs = require('node:fs');
|
|
12
|
-
const path = require('node:path');
|
|
13
|
-
const crypto = require('node:crypto');
|
|
14
|
-
const { tagUrlsInText } = require('../utm');
|
|
15
|
-
const { loadLocalEnv } = require('../load-env');
|
|
16
|
-
|
|
17
|
-
const ZERNIO_UTM = { source: 'zernio', medium: 'social', campaign: 'organic' };
|
|
18
|
-
|
|
19
|
-
const ZERNIO_BASE = 'https://zernio.com/api/v1';
|
|
20
|
-
const DEFAULT_DEDUP_LOG_PATH = path.join(__dirname, '..', '..', '..', '.thumbgate', 'zernio-dedup-log.json');
|
|
21
|
-
|
|
22
|
-
loadLocalEnv();
|
|
23
|
-
|
|
24
|
-
// ---------------------------------------------------------------------------
|
|
25
|
-
// Dedup — backed by marketing DB (SQLite) with JSON-file fallback
|
|
26
|
-
// ---------------------------------------------------------------------------
|
|
27
|
-
|
|
28
|
-
let _mktgDb = null;
|
|
29
|
-
function getMktgDb() {
|
|
30
|
-
if (process.env.THUMBGATE_DEDUP_LOG_PATH && !process.env.THUMBGATE_ANALYTICS_DB) {
|
|
31
|
-
return null;
|
|
32
|
-
}
|
|
33
|
-
if (_mktgDb) return _mktgDb;
|
|
34
|
-
try {
|
|
35
|
-
_mktgDb = require('../db/marketing-db');
|
|
36
|
-
return _mktgDb;
|
|
37
|
-
} catch {
|
|
38
|
-
return null; // graceful degradation to JSON log
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
function buildDedupKey(content, platform) {
|
|
43
|
-
const hash = crypto.createHash('sha256').update(content.trim()).digest('hex').slice(0, 16);
|
|
44
|
-
return `${platform}::${hash}`;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
// Legacy JSON log helpers (fallback when DB unavailable)
|
|
48
|
-
function getDedupLogPath() {
|
|
49
|
-
return process.env.THUMBGATE_DEDUP_LOG_PATH || DEFAULT_DEDUP_LOG_PATH;
|
|
50
|
-
}
|
|
51
|
-
function loadDedupLog() {
|
|
52
|
-
try {
|
|
53
|
-
const p = getDedupLogPath();
|
|
54
|
-
if (fs.existsSync(p)) return JSON.parse(fs.readFileSync(p, 'utf8'));
|
|
55
|
-
} catch { /* ignore */ }
|
|
56
|
-
return {};
|
|
57
|
-
}
|
|
58
|
-
function saveDedupLog(log) {
|
|
59
|
-
const p = getDedupLogPath();
|
|
60
|
-
fs.mkdirSync(path.dirname(p), { recursive: true });
|
|
61
|
-
fs.writeFileSync(p, JSON.stringify(log, null, 2));
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
function isDuplicate(content, platform) {
|
|
65
|
-
// Use marketing DB only when not in test mode (test mode sets THUMBGATE_DEDUP_LOG_PATH)
|
|
66
|
-
if (!process.env.THUMBGATE_DEDUP_LOG_PATH) {
|
|
67
|
-
const db = getMktgDb();
|
|
68
|
-
if (db) {
|
|
69
|
-
const hash = db.hashContent(content);
|
|
70
|
-
return !!db.isDuplicate(platform, hash, 1); // 24-hour window
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
// JSON log fallback (always used in tests)
|
|
74
|
-
const log = loadDedupLog();
|
|
75
|
-
const entry = log[buildDedupKey(content, platform)];
|
|
76
|
-
if (!entry) return false;
|
|
77
|
-
return Date.now() - new Date(entry.postedAt).getTime() < 86_400_000;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
function recordPost(content, platform, extra = {}) {
|
|
81
|
-
const db = getMktgDb();
|
|
82
|
-
if (db) {
|
|
83
|
-
db.record({
|
|
84
|
-
type: 'post', platform,
|
|
85
|
-
contentHash: db.hashContent(content),
|
|
86
|
-
postUrl: extra.postUrl || null,
|
|
87
|
-
postId: extra.postId || null,
|
|
88
|
-
campaign: extra.campaign || 'organic',
|
|
89
|
-
tags: extra.tags || [],
|
|
90
|
-
});
|
|
91
|
-
return;
|
|
92
|
-
}
|
|
93
|
-
// fallback
|
|
94
|
-
const log = loadDedupLog();
|
|
95
|
-
const key = buildDedupKey(content, platform);
|
|
96
|
-
log[key] = { platform, postedAt: new Date().toISOString() };
|
|
97
|
-
const cutoff = Date.now() - 7 * 86_400_000;
|
|
98
|
-
for (const [k, v] of Object.entries(log)) {
|
|
99
|
-
if (new Date(v.postedAt).getTime() < cutoff) delete log[k];
|
|
100
|
-
}
|
|
101
|
-
saveDedupLog(log);
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
function requireApiKey() {
|
|
105
|
-
const key = process.env.ZERNIO_API_KEY;
|
|
106
|
-
if (!key) {
|
|
107
|
-
throw new Error('ZERNIO_API_KEY environment variable is required');
|
|
108
|
-
}
|
|
109
|
-
return key;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
class ZernioQuotaError extends Error {
|
|
113
|
-
constructor(message, details = {}) {
|
|
114
|
-
super(message);
|
|
115
|
-
this.name = 'ZernioQuotaError';
|
|
116
|
-
this.code = 'ZERNIO_POST_LIMIT_REACHED';
|
|
117
|
-
this.billingPeriod = details.billingPeriod || null;
|
|
118
|
-
this.current = Number.isFinite(details.current) ? details.current : null;
|
|
119
|
-
this.endpoint = details.endpoint || null;
|
|
120
|
-
this.limit = Number.isFinite(details.limit) ? details.limit : null;
|
|
121
|
-
this.method = details.method || null;
|
|
122
|
-
this.planName = details.planName || null;
|
|
123
|
-
this.status = details.status || null;
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
function parseZernioErrorText(errorText) {
|
|
128
|
-
if (!errorText || typeof errorText !== 'string') return null;
|
|
129
|
-
try {
|
|
130
|
-
const parsed = JSON.parse(errorText);
|
|
131
|
-
return parsed && typeof parsed === 'object' ? parsed : null;
|
|
132
|
-
} catch {
|
|
133
|
-
return null;
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
function isZernioQuotaError(error) {
|
|
138
|
-
return Boolean(
|
|
139
|
-
error &&
|
|
140
|
-
(error instanceof ZernioQuotaError || error.code === 'ZERNIO_POST_LIMIT_REACHED')
|
|
141
|
-
);
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
function isZernioQuotaPayload(status, payload, errorText) {
|
|
145
|
-
const message = String(payload?.error || payload?.message || errorText || '');
|
|
146
|
-
return status === 403 && /post limit reached/i.test(message);
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
function resolveAccountId(account) {
|
|
150
|
-
if (!account || typeof account !== 'object') {
|
|
151
|
-
return '';
|
|
152
|
-
}
|
|
153
|
-
return String(account.accountId || account._id || account.id || '').trim();
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
function normalizeAccount(account) {
|
|
157
|
-
if (!account || typeof account !== 'object') {
|
|
158
|
-
return null;
|
|
159
|
-
}
|
|
160
|
-
const platform = String(account.platform || '').trim();
|
|
161
|
-
const accountId = resolveAccountId(account);
|
|
162
|
-
return {
|
|
163
|
-
...account,
|
|
164
|
-
platform,
|
|
165
|
-
accountId,
|
|
166
|
-
};
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
function normalizePlatforms(platforms) {
|
|
170
|
-
return platforms
|
|
171
|
-
.map(normalizeAccount)
|
|
172
|
-
.filter(Boolean)
|
|
173
|
-
.map((platform) => ({
|
|
174
|
-
platform: platform.platform,
|
|
175
|
-
accountId: platform.accountId,
|
|
176
|
-
}));
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
function groupAccountsByPlatform(accounts) {
|
|
180
|
-
const groups = new Map();
|
|
181
|
-
for (const account of accounts) {
|
|
182
|
-
if (!account || !account.platform || !account.accountId) {
|
|
183
|
-
continue;
|
|
184
|
-
}
|
|
185
|
-
const existing = groups.get(account.platform) || [];
|
|
186
|
-
existing.push({
|
|
187
|
-
platform: account.platform,
|
|
188
|
-
accountId: account.accountId,
|
|
189
|
-
});
|
|
190
|
-
groups.set(account.platform, existing);
|
|
191
|
-
}
|
|
192
|
-
return groups;
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
function inferContentType(filePath) {
|
|
196
|
-
const ext = path.extname(String(filePath || '')).toLowerCase();
|
|
197
|
-
if (ext === '.jpg' || ext === '.jpeg') return 'image/jpeg';
|
|
198
|
-
if (ext === '.png') return 'image/png';
|
|
199
|
-
if (ext === '.webp') return 'image/webp';
|
|
200
|
-
if (ext === '.gif') return 'image/gif';
|
|
201
|
-
if (ext === '.mp4') return 'video/mp4';
|
|
202
|
-
if (ext === '.mov') return 'video/quicktime';
|
|
203
|
-
if (ext === '.webm') return 'video/webm';
|
|
204
|
-
return 'application/octet-stream';
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
function inferMediaType(contentType) {
|
|
208
|
-
if (String(contentType || '').startsWith('video/')) {
|
|
209
|
-
return 'video';
|
|
210
|
-
}
|
|
211
|
-
return 'image';
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
function normalizePostResult(payload) {
|
|
215
|
-
const data = payload && typeof payload === 'object' ? (payload.data ?? payload) : {};
|
|
216
|
-
const post = data.post && typeof data.post === 'object' ? data.post : null;
|
|
217
|
-
const id = data.id || data._id || post?._id || post?.id || null;
|
|
218
|
-
return {
|
|
219
|
-
...data,
|
|
220
|
-
id,
|
|
221
|
-
post: post || data.post,
|
|
222
|
-
};
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
async function zernioFetch(method, endpoint, body = null) {
|
|
226
|
-
const apiKey = requireApiKey();
|
|
227
|
-
const url = `${ZERNIO_BASE}${endpoint}`;
|
|
228
|
-
|
|
229
|
-
const options = {
|
|
230
|
-
method,
|
|
231
|
-
headers: {
|
|
232
|
-
Authorization: `Bearer ${apiKey}`,
|
|
233
|
-
'Content-Type': 'application/json',
|
|
234
|
-
},
|
|
235
|
-
};
|
|
236
|
-
|
|
237
|
-
if (body !== null) {
|
|
238
|
-
options.body = JSON.stringify(body);
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
const res = await fetch(url, options);
|
|
242
|
-
|
|
243
|
-
if (!res.ok) {
|
|
244
|
-
const errorText = await res.text().catch(() => '');
|
|
245
|
-
const payload = parseZernioErrorText(errorText);
|
|
246
|
-
if (isZernioQuotaPayload(res.status, payload, errorText)) {
|
|
247
|
-
throw new ZernioQuotaError(payload?.error || 'Zernio post limit reached', {
|
|
248
|
-
billingPeriod: payload?.billingPeriod,
|
|
249
|
-
current: Number(payload?.current),
|
|
250
|
-
endpoint,
|
|
251
|
-
limit: Number(payload?.limit),
|
|
252
|
-
method,
|
|
253
|
-
planName: payload?.planName,
|
|
254
|
-
status: res.status,
|
|
255
|
-
});
|
|
256
|
-
}
|
|
257
|
-
throw new Error(`Zernio API ${res.status} for ${method} ${endpoint}: ${errorText}`);
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
return res.json();
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
async function listPosts(options = {}) {
|
|
264
|
-
const query = new URLSearchParams();
|
|
265
|
-
if (options.limit) query.set('limit', String(options.limit));
|
|
266
|
-
if (options.page) query.set('page', String(options.page));
|
|
267
|
-
if (options.status) query.set('status', String(options.status));
|
|
268
|
-
|
|
269
|
-
const suffix = query.toString() ? `?${query.toString()}` : '';
|
|
270
|
-
const json = await zernioFetch('GET', `/posts${suffix}`);
|
|
271
|
-
return Array.isArray(json.posts) ? json.posts : (json.data?.posts || json.data || []);
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
async function deletePost(postId) {
|
|
275
|
-
if (!postId) throw new Error('deletePost: postId is required');
|
|
276
|
-
const json = await zernioFetch('DELETE', `/posts/${encodeURIComponent(String(postId).trim())}`);
|
|
277
|
-
return json.data ?? json;
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
async function requestMediaPresign(filename, contentType, size) {
|
|
281
|
-
if (!filename) throw new Error('requestMediaPresign: filename is required');
|
|
282
|
-
if (!contentType) throw new Error('requestMediaPresign: contentType is required');
|
|
283
|
-
|
|
284
|
-
const json = await zernioFetch('POST', '/media/presign', {
|
|
285
|
-
filename,
|
|
286
|
-
contentType,
|
|
287
|
-
size,
|
|
288
|
-
});
|
|
289
|
-
|
|
290
|
-
return json.data ?? json;
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
async function uploadLocalMedia(filePath, options = {}) {
|
|
294
|
-
const resolvedPath = path.resolve(String(filePath || ''));
|
|
295
|
-
if (!fs.existsSync(resolvedPath)) {
|
|
296
|
-
throw new Error(`uploadLocalMedia: file not found at ${resolvedPath}`);
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
const stats = fs.statSync(resolvedPath);
|
|
300
|
-
const filename = options.filename || path.basename(resolvedPath);
|
|
301
|
-
const contentType = options.contentType || inferContentType(resolvedPath);
|
|
302
|
-
const presign = await requestMediaPresign(filename, contentType, stats.size);
|
|
303
|
-
|
|
304
|
-
if (!presign.uploadUrl || !presign.publicUrl) {
|
|
305
|
-
throw new Error('uploadLocalMedia: presign response missing uploadUrl or publicUrl');
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
const uploadResponse = await fetch(presign.uploadUrl, {
|
|
309
|
-
method: 'PUT',
|
|
310
|
-
headers: {
|
|
311
|
-
'Content-Type': contentType,
|
|
312
|
-
},
|
|
313
|
-
body: fs.readFileSync(resolvedPath),
|
|
314
|
-
});
|
|
315
|
-
|
|
316
|
-
if (!uploadResponse.ok) {
|
|
317
|
-
const errorText = await uploadResponse.text().catch(() => '');
|
|
318
|
-
throw new Error(`uploadLocalMedia: upload failed with ${uploadResponse.status}: ${errorText}`);
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
return {
|
|
322
|
-
contentType,
|
|
323
|
-
key: presign.key || '',
|
|
324
|
-
size: stats.size,
|
|
325
|
-
type: presign.type || inferMediaType(contentType),
|
|
326
|
-
url: presign.publicUrl,
|
|
327
|
-
};
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
/**
|
|
331
|
-
* Publishes a post immediately to one or more platforms.
|
|
332
|
-
* @param {string} content
|
|
333
|
-
* @param {Array<{platform: string, accountId: string}>} platforms
|
|
334
|
-
* @returns {Promise<object>}
|
|
335
|
-
*/
|
|
336
|
-
async function publishPost(content, platforms, options = {}) {
|
|
337
|
-
if (!content) throw new Error('publishPost: content is required');
|
|
338
|
-
if (!Array.isArray(platforms) || platforms.length === 0) {
|
|
339
|
-
throw new Error('publishPost: platforms must be a non-empty array');
|
|
340
|
-
}
|
|
341
|
-
|
|
342
|
-
const normalizedPlatforms = normalizePlatforms(platforms);
|
|
343
|
-
if (normalizedPlatforms.length === 0 || normalizedPlatforms.some((entry) => !entry.platform || !entry.accountId)) {
|
|
344
|
-
throw new Error('publishPost: each platform entry requires platform and accountId');
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
// Tag trackable URLs with Zernio UTM parameters before publishing
|
|
348
|
-
content = tagUrlsInText(content, options.utm || ZERNIO_UTM);
|
|
349
|
-
|
|
350
|
-
const qualityGate = require('../../social-quality-gate');
|
|
351
|
-
const gateResult = qualityGate.gatePost(content);
|
|
352
|
-
if (!gateResult.allowed) {
|
|
353
|
-
const reasons = gateResult.findings.map(f => f.reason).join(', ');
|
|
354
|
-
console.error(`[zernio:publisher] BLOCKED by quality gate: ${reasons}`);
|
|
355
|
-
return { blocked: true, reasons: gateResult.findings };
|
|
356
|
-
}
|
|
357
|
-
|
|
358
|
-
// Dedup: filter out platforms where identical content was posted in last 24h
|
|
359
|
-
const dedupedPlatforms = normalizedPlatforms.filter((p) => {
|
|
360
|
-
if (isDuplicate(content, p.platform)) {
|
|
361
|
-
console.log(`[zernio:publisher] SKIPPED ${p.platform} — duplicate content within 24h`);
|
|
362
|
-
return false;
|
|
363
|
-
}
|
|
364
|
-
return true;
|
|
365
|
-
});
|
|
366
|
-
|
|
367
|
-
if (dedupedPlatforms.length === 0) {
|
|
368
|
-
console.log('[zernio:publisher] All platforms skipped (duplicate content)');
|
|
369
|
-
return { blocked: true, reasons: [{ reason: 'duplicate_content_all_platforms' }] };
|
|
370
|
-
}
|
|
371
|
-
|
|
372
|
-
console.log(`[zernio:publisher] Publishing to ${dedupedPlatforms.length} platform(s): ${dedupedPlatforms.map((p) => p.platform).join(', ')}`);
|
|
373
|
-
|
|
374
|
-
const json = await zernioFetch('POST', '/posts', {
|
|
375
|
-
content,
|
|
376
|
-
firstComment: options.firstComment,
|
|
377
|
-
mediaItems: options.mediaItems,
|
|
378
|
-
publishNow: true,
|
|
379
|
-
platforms: dedupedPlatforms,
|
|
380
|
-
});
|
|
381
|
-
|
|
382
|
-
const data = normalizePostResult(json);
|
|
383
|
-
// Record each platform to prevent future dupes
|
|
384
|
-
for (const p of dedupedPlatforms) {
|
|
385
|
-
recordPost(content, p.platform);
|
|
386
|
-
}
|
|
387
|
-
console.log(`[zernio:publisher] Post published. id=${data.id ?? 'unknown'}`);
|
|
388
|
-
return data;
|
|
389
|
-
}
|
|
390
|
-
|
|
391
|
-
/**
|
|
392
|
-
* Schedules a post for future publication.
|
|
393
|
-
* @param {string} content
|
|
394
|
-
* @param {Array<{platform: string, accountId: string}>} platforms
|
|
395
|
-
* @param {string} scheduledFor ISO 8601 datetime
|
|
396
|
-
* @param {string} timezone IANA timezone string
|
|
397
|
-
* @returns {Promise<object>}
|
|
398
|
-
*/
|
|
399
|
-
async function schedulePost(content, platforms, scheduledFor, timezone, options = {}) {
|
|
400
|
-
if (!content) throw new Error('schedulePost: content is required');
|
|
401
|
-
if (!Array.isArray(platforms) || platforms.length === 0) {
|
|
402
|
-
throw new Error('schedulePost: platforms must be a non-empty array');
|
|
403
|
-
}
|
|
404
|
-
if (!scheduledFor) throw new Error('schedulePost: scheduledFor is required');
|
|
405
|
-
if (!timezone) throw new Error('schedulePost: timezone is required');
|
|
406
|
-
|
|
407
|
-
const normalizedPlatforms = normalizePlatforms(platforms);
|
|
408
|
-
if (normalizedPlatforms.length === 0 || normalizedPlatforms.some((entry) => !entry.platform || !entry.accountId)) {
|
|
409
|
-
throw new Error('schedulePost: each platform entry requires platform and accountId');
|
|
410
|
-
}
|
|
411
|
-
|
|
412
|
-
content = tagUrlsInText(content, options.utm || ZERNIO_UTM);
|
|
413
|
-
|
|
414
|
-
// Dedup: filter out platforms where identical content was scheduled in last 24h
|
|
415
|
-
const dedupedPlatforms = normalizedPlatforms.filter((p) => {
|
|
416
|
-
if (isDuplicate(content, p.platform)) {
|
|
417
|
-
console.log(`[zernio:publisher] SKIPPED ${p.platform} schedule — duplicate content within 24h`);
|
|
418
|
-
return false;
|
|
419
|
-
}
|
|
420
|
-
return true;
|
|
421
|
-
});
|
|
422
|
-
|
|
423
|
-
if (dedupedPlatforms.length === 0) {
|
|
424
|
-
console.log('[zernio:publisher] All platforms skipped (duplicate content)');
|
|
425
|
-
return { blocked: true, reasons: [{ reason: 'duplicate_content_all_platforms' }] };
|
|
426
|
-
}
|
|
427
|
-
|
|
428
|
-
console.log(`[zernio:publisher] Scheduling post for ${scheduledFor} (${timezone}) to ${dedupedPlatforms.length} platform(s)`);
|
|
429
|
-
|
|
430
|
-
const json = await zernioFetch('POST', '/posts', {
|
|
431
|
-
content,
|
|
432
|
-
firstComment: options.firstComment,
|
|
433
|
-
mediaItems: options.mediaItems,
|
|
434
|
-
publishNow: false,
|
|
435
|
-
platforms: dedupedPlatforms,
|
|
436
|
-
scheduledFor,
|
|
437
|
-
timezone,
|
|
438
|
-
});
|
|
439
|
-
|
|
440
|
-
const data = normalizePostResult(json);
|
|
441
|
-
for (const p of dedupedPlatforms) {
|
|
442
|
-
recordPost(content, p.platform);
|
|
443
|
-
}
|
|
444
|
-
console.log(`[zernio:publisher] Post scheduled. id=${data.id ?? 'unknown'}`);
|
|
445
|
-
return data;
|
|
446
|
-
}
|
|
447
|
-
|
|
448
|
-
/**
|
|
449
|
-
* Fetches all connected platform accounts from Zernio.
|
|
450
|
-
* @returns {Promise<Array<{platform: string, accountId: string, name: string}>>}
|
|
451
|
-
*/
|
|
452
|
-
async function getConnectedAccounts() {
|
|
453
|
-
console.log('[zernio:publisher] Fetching connected accounts');
|
|
454
|
-
|
|
455
|
-
const json = await zernioFetch('GET', '/accounts');
|
|
456
|
-
const accounts = (Array.isArray(json) ? json : (json.data ?? json.accounts ?? []))
|
|
457
|
-
.map(normalizeAccount)
|
|
458
|
-
.filter((account) => account && account.platform && account.accountId);
|
|
459
|
-
|
|
460
|
-
console.log(`[zernio:publisher] ${accounts.length} connected account(s) found`);
|
|
461
|
-
return accounts;
|
|
462
|
-
}
|
|
463
|
-
|
|
464
|
-
/**
|
|
465
|
-
* Publishes a post to all connected Zernio accounts in one call.
|
|
466
|
-
* @param {string} content
|
|
467
|
-
* @returns {Promise<{ published: object[], errors: object[] }>}
|
|
468
|
-
*/
|
|
469
|
-
async function publishToAllPlatforms(content, options = {}) {
|
|
470
|
-
if (!content) throw new Error('publishToAllPlatforms: content is required');
|
|
471
|
-
|
|
472
|
-
console.log('[zernio:publisher] Fetching all connected accounts for bulk publish');
|
|
473
|
-
const accounts = await getConnectedAccounts();
|
|
474
|
-
|
|
475
|
-
if (accounts.length === 0) {
|
|
476
|
-
console.warn('[zernio:publisher] No connected accounts found — nothing to publish');
|
|
477
|
-
return { published: [], errors: [] };
|
|
478
|
-
}
|
|
479
|
-
|
|
480
|
-
const published = [];
|
|
481
|
-
const errors = [];
|
|
482
|
-
const requestedPlatforms = Array.isArray(options.platforms) && options.platforms.length > 0
|
|
483
|
-
? new Set(options.platforms.map((platform) => String(platform || '').trim()).filter(Boolean))
|
|
484
|
-
: null;
|
|
485
|
-
const groupedAccounts = groupAccountsByPlatform(accounts);
|
|
486
|
-
|
|
487
|
-
for (const [platform, platformAccounts] of groupedAccounts.entries()) {
|
|
488
|
-
if (requestedPlatforms && !requestedPlatforms.has(platform)) {
|
|
489
|
-
continue;
|
|
490
|
-
}
|
|
491
|
-
|
|
492
|
-
try {
|
|
493
|
-
const result = await publishPost(content, platformAccounts, {
|
|
494
|
-
utm: {
|
|
495
|
-
source: platform,
|
|
496
|
-
medium: options.medium || ZERNIO_UTM.medium,
|
|
497
|
-
campaign: options.campaign || ZERNIO_UTM.campaign,
|
|
498
|
-
},
|
|
499
|
-
});
|
|
500
|
-
published.push({ platform, result });
|
|
501
|
-
} catch (err) {
|
|
502
|
-
console.error(`[zernio:publisher] Bulk publish failed for ${platform}: ${err.message}`);
|
|
503
|
-
errors.push({ error: err.message, platform });
|
|
504
|
-
}
|
|
505
|
-
}
|
|
506
|
-
|
|
507
|
-
console.log(`[zernio:publisher] Bulk publish complete. published=${published.length} errors=${errors.length}`);
|
|
508
|
-
return { published, errors };
|
|
509
|
-
}
|
|
510
|
-
|
|
511
|
-
module.exports = {
|
|
512
|
-
buildDedupKey,
|
|
513
|
-
deletePost,
|
|
514
|
-
isDuplicate,
|
|
515
|
-
isZernioQuotaError,
|
|
516
|
-
listPosts,
|
|
517
|
-
ZernioQuotaError,
|
|
518
|
-
publishPost,
|
|
519
|
-
recordPost,
|
|
520
|
-
schedulePost,
|
|
521
|
-
publishToAllPlatforms,
|
|
522
|
-
getConnectedAccounts,
|
|
523
|
-
groupAccountsByPlatform,
|
|
524
|
-
inferContentType,
|
|
525
|
-
inferMediaType,
|
|
526
|
-
normalizeAccount,
|
|
527
|
-
normalizePlatforms,
|
|
528
|
-
normalizePostResult,
|
|
529
|
-
requestMediaPresign,
|
|
530
|
-
resolveAccountId,
|
|
531
|
-
uploadLocalMedia,
|
|
532
|
-
};
|
|
533
|
-
|
|
534
|
-
if (require.main === module) {
|
|
535
|
-
const args = process.argv.slice(2);
|
|
536
|
-
|
|
537
|
-
function getArg(flag) {
|
|
538
|
-
const prefix = `${flag}=`;
|
|
539
|
-
const entry = args.find((a) => a.startsWith(prefix));
|
|
540
|
-
return entry ? entry.slice(prefix.length) : null;
|
|
541
|
-
}
|
|
542
|
-
|
|
543
|
-
const text = getArg('--text');
|
|
544
|
-
const schedule = getArg('--schedule');
|
|
545
|
-
const timezone = getArg('--timezone') || 'UTC';
|
|
546
|
-
|
|
547
|
-
if (!text) {
|
|
548
|
-
console.error('Usage: node zernio.js --text="..." [--schedule="2026-04-01T10:00:00Z" --timezone="America/New_York"]');
|
|
549
|
-
process.exit(1);
|
|
550
|
-
}
|
|
551
|
-
|
|
552
|
-
(async () => {
|
|
553
|
-
try {
|
|
554
|
-
if (schedule) {
|
|
555
|
-
const accounts = await getConnectedAccounts();
|
|
556
|
-
const platforms = accounts.map((a) => ({ platform: a.platform, accountId: a.accountId }));
|
|
557
|
-
const result = await schedulePost(text, platforms, schedule, timezone);
|
|
558
|
-
console.log(`[zernio:publisher] Scheduled. id=${result.id ?? 'unknown'}`);
|
|
559
|
-
} else {
|
|
560
|
-
const result = await publishToAllPlatforms(text);
|
|
561
|
-
console.log(`[zernio:publisher] Done. published=${result.published.length} errors=${result.errors.length}`);
|
|
562
|
-
}
|
|
563
|
-
} catch (err) {
|
|
564
|
-
console.error('[zernio:publisher] Failed:', err.message);
|
|
565
|
-
process.exit(1);
|
|
566
|
-
}
|
|
567
|
-
})();
|
|
568
|
-
}
|