this repo has no description
1import { AppBskyLabelerService, AtpAgent } from '@atproto/api';
2
3import logger from './logger.js';
4
5const IDENTIFIER = process.env.BSKY_IDENTIFIER;
6const PASSWORD = process.env.BSKY_PASSWORD;
7const SERVICE = process.env.PDS_URL ?? 'https://bsky.social';
8
9async function updateReasonTypes() {
10 if (!IDENTIFIER || !PASSWORD) {
11 throw new Error('Missing BSKY_IDENTIFIER or BSKY_PASSWORD environment variables.');
12 }
13
14 const agent = new AtpAgent({ service: SERVICE });
15 await agent.login({ identifier: IDENTIFIER, password: PASSWORD });
16
17 const repo = agent.session?.did;
18
19 if (!repo) {
20 throw new Error('Could not resolve DID for the labeler account.');
21 }
22
23 const recordResponse = await agent.com.atproto.repo
24 .getRecord({ collection: 'app.bsky.labeler.service', rkey: 'self', repo })
25 .catch(() => null);
26
27 if (!recordResponse?.data?.value) {
28 logger.info('No labeler service record found; nothing to update.');
29 return;
30 }
31
32 const currentRecord = recordResponse.data.value as AppBskyLabelerService.Record;
33
34 if (Array.isArray(currentRecord.reasonTypes) && currentRecord.reasonTypes.length === 0) {
35 logger.info('reasonTypes is already an empty array; no changes applied.');
36 return;
37 }
38
39 const updatedRecord: AppBskyLabelerService.Record = {
40 ...currentRecord,
41 reasonTypes: [],
42 };
43
44 await agent.com.atproto.repo.putRecord({
45 collection: 'app.bsky.labeler.service',
46 rkey: 'self',
47 repo,
48 record: updatedRecord,
49 swapRecord: recordResponse.data.cid,
50 });
51
52 logger.info('Successfully updated reasonTypes to an empty array.');
53}
54
55updateReasonTypes().catch((error) => {
56 logger.error(`Failed to clear reasonTypes: ${error instanceof Error ? error.message : String(error)}`);
57 process.exitCode = 1;
58});