CLI tool to sync your Markdown to Leaflet
leafletpub atproto cli markdown

Use @atcute/microcosm

+3
bun.lock
··· 28 28 "devDependencies": { 29 29 "@atcute/atproto": "^3.1.9", 30 30 "@atcute/leaflet": "^1.0.12", 31 + "@atcute/microcosm": "^1.0.0", 31 32 "@types/bun": "1.3.2", 32 33 "@types/mdast": "^4.0.4", 33 34 "tsdown": "^0.16.5", ··· 55 56 "@atcute/leaflet": ["@atcute/leaflet@1.0.12", "", { "dependencies": { "@atcute/atproto": "^3.1.9", "@atcute/lexicons": "^1.2.2" } }, "sha512-T5laBTl8vwzy0eZXBy07IQSjsLqhbZmRJsffnNQ6XMSc+lnCZ/NHfuKy8TNJbDU6dc26Z7o5l0ELfWz5QESo+w=="], 56 57 57 58 "@atcute/lexicons": ["@atcute/lexicons@1.2.3", "", { "dependencies": { "@standard-schema/spec": "^1.0.0", "esm-env": "^1.2.2" } }, "sha512-ZNfNWS4jaR8VgWSSBaWRSSmwFeP134BmvpTt9JmM2x5vRoXeIFthxU9USY8ZV4vm0GPoxEMgkDin8HIlnFTg2w=="], 59 + 60 + "@atcute/microcosm": ["@atcute/microcosm@1.0.0", "", { "dependencies": { "@atcute/lexicons": "^1.2.3" } }, "sha512-XJW+TMvdktH2maTkVcNU6wKmnHpmNwhmg0Xj4ZY36plHpqNHfxR4kAAcXGSJcjH9CS8I1+cTHiyUQykdeOPeGg=="], 58 61 59 62 "@atcute/mst": ["@atcute/mst@0.1.0", "", { "dependencies": { "@atcute/cbor": "^2.2.7", "@atcute/cid": "^2.2.6", "@atcute/uint8array": "^1.0.5" } }, "sha512-h+iDToKEnBpigk2DOHjSqY63vJtjYKUIztqu1CZ0P+I54wV2SrgoqAXAT1xrW6A1Iup8cjTv+U2H5WVG4KxPLw=="], 60 63
+1
package.json
··· 26 26 "devDependencies": { 27 27 "@atcute/atproto": "^3.1.9", 28 28 "@atcute/leaflet": "^1.0.12", 29 + "@atcute/microcosm": "^1.0.0", 29 30 "@types/bun": "1.3.2", 30 31 "@types/mdast": "^4.0.4", 31 32 "tsdown": "^0.16.5"
+11 -3
src/commands/config-cmd.ts
··· 2 2 import { consola } from "consola"; 3 3 import { colorize, leftAlign, type ColorName } from "consola/utils"; 4 4 import { exists, loadConfig } from "../utils.ts"; 5 + import { Client, simpleFetchHandler } from "@atcute/client"; 6 + import type { ActorIdentifier } from "@atcute/lexicons/syntax"; 5 7 6 8 export const configCmd = defineCommand({ 7 9 async run(context) { ··· 21 23 const wrap = (str: string, wrapper: string) => { 22 24 return wrapper + str + wrapper; 23 25 }; 26 + 27 + const slingshot = new Client({ handler: simpleFetchHandler({ service: "https://slingshot.microcosm.blue" }) }); 24 28 25 29 process.env.BSKY_HANDLE 26 30 ? consola.success(colorize("green", "BSKY_HANDLE provided")) ··· 42 46 43 47 const rkey = config.publicationUri.split("/").at(-1) as string; 44 48 45 - const recordRes = await fetch( 46 - `https://slingshot.microcosm.blue/xrpc/com.atproto.repo.getRecord?repo=${encodeURIComponent(process.env.BSKY_HANDLE)}&collection=pub.leaflet.publication&rkey=${rkey}` 47 - ); 49 + const recordRes = await slingshot.get("com.atproto.repo.getRecord", { 50 + params: { 51 + repo: process.env.BSKY_HANDLE as ActorIdentifier, 52 + collection: "pub.leaflet.publication", 53 + rkey: rkey, 54 + }, 55 + }); 48 56 49 57 if (recordRes.status == 400) { 50 58 publicationStatus = "NotFound";
+7 -9
src/commands/sync-cmd.ts
··· 1 1 import { defineCommand } from "citty"; 2 - import { Client, CredentialManager, ok } from "@atcute/client"; 2 + import { Client, CredentialManager, ok, simpleFetchHandler } from "@atcute/client"; 3 3 import type { PubLeafletDocument, PubLeafletPagesLinearDocument, PubLeafletPublication } from "@atcute/leaflet"; 4 4 import * as TID from "@atcute/tid"; 5 5 import { unified } from "unified"; ··· 21 21 import { consola } from "consola"; 22 22 import { exists, readJson, loadConfig } from "../utils.ts"; 23 23 import { parse } from "yaml"; 24 - import type { AtprotoDid, Handle } from "@atcute/lexicons/syntax"; 24 + import type { ActorIdentifier } from "@atcute/lexicons/syntax"; 25 25 26 26 export const syncCmd = defineCommand({ 27 27 async run({ cmd, args }) { ··· 37 37 throw new Error("BSKY_HANDLE not provided in .env"); 38 38 } 39 39 40 - const miniDocRes = await fetch( 41 - `https://slingshot.microcosm.blue/xrpc/com.bad-example.identity.resolveMiniDoc?identifier=${encodeURIComponent(process.env.BSKY_HANDLE)}` 40 + const slingshot = new Client({ handler: simpleFetchHandler({ service: "https://slingshot.microcosm.blue" }) }); 41 + const miniDoc = ok( 42 + await slingshot.get("com.bad-example.identity.resolveMiniDoc", { 43 + params: { identifier: process.env.BSKY_HANDLE as ActorIdentifier }, 44 + }) 42 45 ); 43 - if (!miniDocRes.ok) 44 - throw new Error( 45 - `Slingshot status: ${miniDocRes.status} - ${miniDocRes.statusText}\n${((await miniDocRes.json()) as any).message}` 46 - ); 47 - const miniDoc = (await miniDocRes.json()) as { did: AtprotoDid; handle: Handle; pds: string; signing_key: string }; 48 46 49 47 const handler = new CredentialManager({ service: miniDoc.pds }); 50 48 const client = new Client({ handler: handler });
+1
tsconfig.json
··· 27 27 "types": [ 28 28 "@atcute/leaflet", 29 29 "@atcute/atproto", 30 + "@atcute/microcosm", 30 31 "@types/bun" 31 32 ] 32 33 }