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

Use @atcute/microcosm

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