open source is social v-it.org
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge branch 'hopper-uuamvude-pds-record-json-output'

+25 -27
+25 -27
src/cmd/pds-record.js
··· 10 10 program 11 11 .command('pds-record') 12 12 .description('Write and read a custom org.v-it.hello record on the authenticated PDS') 13 - .option('-v, --verbose', 'Show full API responses') 14 13 .option('--did <did>', 'DID to use (overrides saved credentials)') 15 14 .option('--message <msg>', 'Message to write', 'hello world') 16 15 .action(async (opts) => { ··· 30 29 ); 31 30 } 32 31 33 - if (opts.verbose) { 34 - console.log(`[verbose] Restoring session for ${did}`); 35 - } 36 - 37 32 const client = createOAuthClient({ 38 33 stateStore: { 39 34 set: async () => {}, ··· 46 41 47 42 const session = await client.restore(did); 48 43 const agent = new Agent(session); 49 - 50 - if (opts.verbose) { 51 - console.log('[verbose] Session restored, agent ready'); 52 - } 44 + const pds = (await session.getTokenInfo(false)).aud; 53 45 54 46 const record = { 55 47 $type: 'org.v-it.hello', ··· 57 49 createdAt: new Date().toISOString(), 58 50 }; 59 51 60 - if (opts.verbose) { 61 - console.log('[verbose] Writing record:'); 62 - console.log(JSON.stringify(record, null, 2)); 63 - } 64 - 65 - const putResult = await agent.com.atproto.repo.putRecord({ 52 + const putArgs = { 66 53 repo: did, 67 54 collection: 'org.v-it.hello', 68 55 rkey: 'self', 69 56 record, 70 57 validate: false, 71 - }); 72 - 73 - console.log(`Record written: ${putResult.data.uri}`); 58 + }; 59 + const putResult = await agent.com.atproto.repo.putRecord(putArgs); 60 + console.log( 61 + JSON.stringify({ 62 + ts: new Date().toISOString(), 63 + pds, 64 + xrpc: 'com.atproto.repo.putRecord', 65 + request: putArgs, 66 + response: putResult.data, 67 + }), 68 + ); 74 69 75 - const getResult = await agent.com.atproto.repo.getRecord({ 70 + const getArgs = { 76 71 repo: did, 77 72 collection: 'org.v-it.hello', 78 73 rkey: 'self', 79 - }); 80 - 81 - if (opts.verbose) { 82 - console.log('[verbose] Read-back result:'); 83 - console.log(JSON.stringify(getResult.data, null, 2)); 84 - } 85 - 86 - console.log(`Record value: ${JSON.stringify(getResult.data.value)}`); 74 + }; 75 + const getResult = await agent.com.atproto.repo.getRecord(getArgs); 76 + console.log( 77 + JSON.stringify({ 78 + ts: new Date().toISOString(), 79 + pds, 80 + xrpc: 'com.atproto.repo.getRecord', 81 + request: getArgs, 82 + response: getResult.data, 83 + }), 84 + ); 87 85 } catch (err) { 88 86 console.error(err instanceof Error ? err.message : String(err)); 89 87 process.exitCode = 1;