@flung.dev/sdk

中文文档
0.10.0发布于 2026/11/12MITTypeScriptES Module零依赖构建来源已验证近 30 天下载 2566

The typed TypeScript client for the Flung API: schedule and publish social media posts, connect accounts, and verify webhooks.

原始使用文档
文档目录10 节
  1. Behaviour
  2. Time zones
  3. Images and video
  4. Connecting accounts without a UI
  5. Letting people connect from your page
  6. One profile per customer
  7. Plotwork diagrams
  8. Webhooks
  9. Standards
  10. Contents

@flung.dev/sdk

The typed TypeScript client for the Flung API: schedule and publish social media posts, connect accounts, manage webhook endpoints and API keys, and verify the webhooks Flung sends. It runs anywhere with fetch and WebCrypto: Node 20+, Cloudflare Workers, Deno, Bun.

import { Flung } from '@flung.dev/sdk'

const flung = new Flung({ apiKey: process.env.FLUNG_API_KEY! })

const { data: accounts } = await flung.accounts.list()
const post = await flung.posts.create({
  content: 'Launching today.',
  accountIds: accounts.map((account) => account.id),
  publishAt: '2026-11-01T09:00:00.000Z',
})

Keep the key on a server. The SDK talks to https://api.flung.dev; pass baseUrl: 'https://api-preview.flung.dev' to test against preview.

Behaviour

  • Errors. A failed call throws FlungError with status, a stable code (unknown_accounts, account_needs_reconnect, network_error, ...) and details. Branch on code; messages may change.
  • Retries. Network failures, timeouts, 408, 409, 429 and 5xx are retried twice by default with jittered backoff, honouring Retry-After. Set maxRetries and timeoutMs on the constructor.
  • Idempotency. Every POST carries an Idempotency-Key, generated unless you pass 'idempotency-key', so a retry never schedules a post twice. Pass your own key, such as an order id, to make your own retries safe too.
  • Pagination. for await (const post of flung.paginate((page) => flung.posts.list(page), { limit: 100 })) walks every page.

Time zones

Flung stores every time in UTC. Give publishAt either as an instant with Z or an offset, or as the local time a person said, without an offset, and Flung converts it on the server:

// 9am in Athens on 3 November, whatever zone this code runs in.
const post = await flung.posts.create({
  content: 'Kalimera.',
  accountIds,
  publishAt: '2026-11-03T09:00',
  timeZone: 'Europe/Athens',
})
post.publishAt // '2026-11-03T07:00:00.000Z', in UTC
post.publishAtLocal // '2026-11-03T09:00:00+02:00'
post.timeZone // 'Europe/Athens'

Without timeZone, a local time is read in the zone of the person behind an OAuth token, else the workspace's default zone (as for an API key), else UTC. flung.me.get() says which: timeZone, timeZoneSource (user, workspace or default) and the time there now as nowLocal. A local time the clocks skip in spring moves forward by the gap, and one they pass twice in autumn takes the earlier instant; either adds an entry to post.warnings (local_time_skipped, local_time_ambiguous). A zone that is not an IANA name is refused with the code invalid_time_zone. Times with Z or an offset work exactly as before.

Images and video

const photo = await flung.uploadMedia(await readFile('launch.png'), { contentType: 'image/png' })
await flung.posts.create({ content: 'Launching today.', accountIds, mediaIds: [photo.id] })
// Or let Flung fetch a file that is already online:
const clip = await flung.media.import({ url: 'https://example.com/launch.mp4' })

JPEG, PNG and WebP up to 20 MB, GIF 15 MB, MP4 and QuickTime 1 GB; uploadMedia sends anything over 100 MB in parts by itself. Flung checks the real type from the file.

PlatformTakes
Instagram10 images, or a Reel up to 300 MB
Threads20 images, or a video
Facebook10 photos, or a video
X4 images up to 5 MB, or a GIF or a video up to 512 MB
LinkedIn9 images, or a video up to 200 MB
Mastodon4 images, or a video up to 40 MB
Discord10 files up to 10 MB
Bluesky4 images up to 1 MB, or a video up to 100 MB
Pinterest5 images, or a video up to 1 GB, pinned to the post's board or the account's default
Farcaster2 images, or a video up to 100 MB, embedded by a permanent link
YouTube, TikTokOne video

A post a platform cannot carry is refused when it is created, not when it fails to publish.

Connecting accounts without a UI

// A new account, or flung.accounts.reconnect({ id }) for one that needs it.
const session = await flung.accounts.connect({ platform: 'linkedin' })
console.warn(`Open ${session.authorizationUrl}`)
const done = await flung.waitForConnection(session.id)
if (done.status === 'connected') console.warn('Connected', done.accountIds)

Without a redirectUrl the person ends on Flung's own "you can close this tab" page. Pass one to bring them back into your app instead.

LinkedIn company pages connect through their own app: flung.accounts.connect({ platform: 'linkedin', variant: 'pages' }) connects every page the person administers, one account per page. flung.platforms.list() gives each platform's variants, ['pages'] for LinkedIn once the pages app is set up.

Most platforms connect by consent: the person signs in at authorizationUrl and lands back on a page. Farcaster connects by approval instead: flung.platforms.list() gives it connectFlow: 'approval', authorizationUrl opens Warpcast (show it as a link or a QR code, as approval usually happens on a phone), and nothing redirects back, so waitForConnection is how you learn it finished. A session nobody approves ends expired.

Each account says how it stays connected: renewal is automatic (Flung refreshes it), manual (only a reconnect renews it) or not_needed, with tokenExpiresAt and reconnectBy. flung.accounts.list({ reconnectBefore }) finds the ones a person must reconnect soon, account.reconnect_required_soon arrives a week ahead, and flung.accounts.refresh({ id }) renews a token now.

Letting people connect from your page

Your server makes a connect token, and <flung-connect> from @flung.dev/connect uses it in the browser. The token can only list, connect, reconnect and disconnect accounts, from the origins you name, until it expires.

const { token } = await flung.connectTokens.create({ origins: ['https://app.example.com'], expiresIn: 900 })

One profile per customer

When your product's users each connect their own accounts, give each a profile, with your own user id as externalId. A connect token made with its profileId connects into it and sees only its accounts.

const profile = await flung.profiles.create({ name: 'Acme Studio', externalId: 'user_8412' })
const { token } = await flung.connectTokens.create({ origins: ['https://app.example.com'], profileId: profile.id })
const { data: accounts } = await flung.accounts.list({ profileId: profile.id })
await flung.posts.create({ content: 'Hello', accountIds: accounts.map((account) => account.id), profileId: profile.id })

flung.profiles.list({ externalId }) finds a profile again. flung.profiles.delete({ id }) disconnects its accounts and cancels its scheduled posts.

A profile (a brand, in the Flung portal) holds at most one account on each platform; a LinkedIn page counts apart from a personal profile. flung.billing.get() gives the limit as limits.accountsPerPlatformPerProfile, and how many profiles the plan allows. Connecting a second account of a platform into the same profile throws FlungError with the code platform_limit_reached, whose details name the platform, the profile and upgradeUrl. Reconnecting an account it already holds is never refused.

Plotwork diagrams

When a workspace has connected Plotwork, its diagrams can go straight into a post: importDiagram has Plotwork paint the diagram as a PNG and keeps it as a media file with alt text.

const { data: diagrams } = await flung.plotwork.listDiagrams({ q: 'architecture' })
const media = await flung.plotwork.importDiagram({ id: diagrams[0].id, width: 1600, scheme: 'light' })
await flung.posts.create({ content: 'How it fits together', accountIds, mediaIds: [media.id] })

flung.plotwork.get() says whether Plotwork is connected and by whom.

Webhooks

import { verifyWebhook } from '@flung.dev/sdk'

const event = await verifyWebhook({ body: rawBody, headers: request.headers, secret: process.env.FLUNG_WEBHOOK_SECRET! })
if (event.type === 'post.published') console.warn(event.data.post.id)

Pass the raw body, not a re-serialised one. During a secret rotation Flung signs with the old and the new secret for 24 hours, and secret also takes both while you switch. Events follow the Standard Webhooks spec, so any Standard Webhooks library verifies them too.

Standards

Code here follows:

Contents

PathPurpose
openapi-ts.config.tshey-api settings: one FlungApi class nested by operation id, flat parameters, throw on error. Reads ../../spec/openapi.json.
src/generated/The generated client. Not committed; generate rebuilds it before every typecheck, test and build.
src/client.tsFlung: the configured client, retries, idempotency keys, paginate, uploadMedia, waitForConnection. Kept equal to flung-app's packages/sdk/src/client.ts, whose contract tests run it against the API itself.
src/errors.tsFlungError.
src/webhooks.tsverifyWebhook and the typed FlungWebhookEvent.
src/__tests__/The client against scripted answers, and webhooks signed as the jobs Worker signs them.
tsdown.config.tsBundles dist/index.js and dist/index.d.ts for npm. Built with TypeScript 6: hey-api needs the compiler API TypeScript 7 no longer ships.

版本与发布记录

@flung.dev/sdk 共发布 14 个版本,首次发布于 2026/10/29;过去 12 个月发布了 14 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.10.0latest2026/11/123 天前
0.9.02026/11/069 天前
0.8.02026/11/069 天前
0.7.02026/11/0510 天前
0.6.02026/11/0114 天前
0.5.02026/10/3115 天前

关于 @flung.dev/sdk 的常见问题

@flung.dev/sdk 是什么?

The typed TypeScript client for the Flung API: schedule and publish social media posts, connect accounts, and verify webhooks.

如何安装 @flung.dev/sdk?

在项目目录运行 npm install @flung.dev/sdk,或使用 pnpm add / yarn add / bun add。

@flung.dev/sdk 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@flung.dev/sdk 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@flung.dev/sdk 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=20。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@flung.dev/sdk 可以商用吗?

@flung.dev/sdk 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@flung.dev/sdk 的下载量有多少?

根据 npm 官方下载统计,@flung.dev/sdk 在 2026/10/15 – 2026/11/13 这 30 天内被下载 2,566 次,日均约 86 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@flung.dev/sdk 还在维护吗?

最新版本 0.10.0 发布于 2026/11/12(3 天前);至今共发布 14 个版本,其中过去 12 个月发布了 14 个;首次发布于 2026/10/29。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。