this repo has no description
0
fork

Configure Feed

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

Implement labeler deletion scripts

futur 0758428d c77eb5d0

+90 -4
+1 -3
src/index.ts
··· 1 1 export { LabelerServer, type LabelerOptions } from "./LabelerServer.js"; 2 2 export type { SignedLabel } from "./util/types.js"; 3 - export { formatLabel, signLabel, labelIsSigned } from "./util/labels.js"; 4 - 5 - export * as scripts from "./scripts/index.js"; 3 + export { formatLabel, signLabel, labelIsSigned } from "./util/labels.js";
+21
src/scripts/declareLabeler.ts
··· 71 71 }); 72 72 return policies.labelValueDefinitions; 73 73 } 74 + 75 + /** 76 + * Delete the labeler declaration for this account, removing all label definitions. 77 + * @param credentials The credentials of the labeler account. 78 + */ 79 + export async function deleteLabelerDeclaration( 80 + credentials: { pds?: string; identifier: string; password: string }, 81 + ): Promise<void>; 82 + /** 83 + * Delete the labeler declaration for this account, removing all label definitions. 84 + * @param agent The agent logged into the labeler account. 85 + */ 86 + export async function deleteLabelerDeclaration( 87 + agent: AtpAgent, 88 + ): Promise<void>; 89 + export async function deleteLabelerDeclaration( 90 + agentOrCredentials: AtpAgent | { pds?: string; identifier: string; password: string }, 91 + ) { 92 + const agent = await loginAgentOrCredentials(agentOrCredentials); 93 + await agent.app.bsky.labeler.service.delete({ repo: agent.accountDid }); 94 + }
+1 -1
src/scripts/index.ts
··· 1 1 export * from "./declareLabeler.js"; 2 2 export * from "./plc.js"; 3 - export { LoginCredentials } from "./util.js"; 3 + export type { LoginCredentials } from "./util.js";
+67
src/scripts/plc.ts
··· 32 32 overwriteExistingKey?: boolean; 33 33 } 34 34 35 + /** Options for the {@link plcClearLabeler} function. */ 36 + export interface PlcClearLabelerOptions { 37 + /** 38 + * The token to use to sign the PLC operation. 39 + * If you don't have a token, first call {@link plcRequestToken} to receive one via email. 40 + */ 41 + plcToken: string; 42 + 43 + /** The URL of the PDS where the labeler account is located, if different from bsky.social. */ 44 + pds?: string; 45 + /** The DID of the labeler account. */ 46 + did: string; 47 + /** The password of the labeler account. You must provide either `password` or `agent`. */ 48 + password?: string; 49 + /** An agent logged into the labeler account. You must provide either `password` or `agent`. */ 50 + agent?: AtpAgent; 51 + } 52 + 35 53 /** 36 54 * This function will update the labeler account's DID document to include the 37 55 * provided labeler endpoint and signing key. If no private key is provided, a 38 56 * new keypair will be generated, and the private key will be printed to the 39 57 * console. This private key will be needed to sign any labels created. 58 + * To set up a labeler, call this function followed by {@link declareLabeler}. 40 59 * @param options Options for the function. 41 60 */ 42 61 export async function plcSetupLabeler(options: PlcSetupLabelerOptions) { ··· 114 133 ); 115 134 console.log("Signing key:", privateKey); 116 135 } 136 + } 137 + 138 + /** 139 + * This function will remove the labeler endpoint and signing key from the labeler account's DID document. 140 + * To restore a labeler to a regular account, call this function followed by {@link deleteLabelerDeclaration}. 141 + * @param options Options for the function. 142 + */ 143 + export async function plcClearLabeler(options: PlcClearLabelerOptions) { 144 + if (!options.agent && !options.password) { 145 + throw new Error( 146 + "Either a logged-in agent or a password must be provided for the labeler account.", 147 + ); 148 + } 149 + 150 + const agent = options.agent ?? new AtpAgent({ service: options.pds || "https://bsky.social" }); 151 + if (!agent.hasSession) { 152 + if (!options.password) { 153 + throw new Error("A password must be provided to log in to the labeler account."); 154 + } 155 + await agent.login({ identifier: options.did, password: options.password }); 156 + } 157 + 158 + const credentials = await agent.com.atproto.identity.getRecommendedDidCredentials(); 159 + if (!credentials.success) { 160 + throw new Error("Failed to fetch DID document."); 161 + } 162 + 163 + if ( 164 + credentials.data.verificationMethods 165 + && "atproto_label" in credentials.data.verificationMethods 166 + ) { 167 + delete credentials.data.verificationMethods.atproto_label; 168 + } 169 + 170 + if ( 171 + credentials.data.services 172 + && "atproto_label" in credentials.data.services 173 + && credentials.data.services["atproto_label"] 174 + ) { 175 + delete credentials.data.services.atproto_label; 176 + } 177 + 178 + const plcOp = await agent.com.atproto.identity.signPlcOperation({ 179 + token: options.plcToken, 180 + ...credentials.data, 181 + }); 182 + 183 + await agent.com.atproto.identity.submitPlcOperation({ operation: plcOp.data.operation }); 117 184 } 118 185 119 186 /**