Move from GitHub to Tangled
1import { AtpAgent } from "@atproto/api";
2import dotenv from "dotenv";
3
4dotenv.config({ path: "./src/.env" });
5
6async function testAtProtoConnection() {
7 console.log("Testing AT Proto Connection...\n");
8
9 const service = process.env.BLUESKY_PDS || "https://bsky.social";
10 const username = process.env.BLUESKY_USERNAME;
11 const password = process.env.BLUESKY_PASSWORD;
12 const atprotoDid = process.env.ATPROTO_DID;
13
14 console.log(`Service: ${service}`);
15 console.log(`Username: ${username}`);
16 console.log(`Expected DID: ${atprotoDid}\n`);
17
18 if (!username || !password) {
19 console.error("ERROR: Missing BLUESKY_USERNAME or BLUESKY_PASSWORD");
20 process.exit(1);
21 }
22
23 const agent = new AtpAgent({ service });
24
25 try {
26 console.log("Attempting login...");
27 const loginResponse = await agent.login({
28 identifier: username,
29 password
30 });
31
32 console.log("✓ Login successful!");
33 console.log(` DID: ${loginResponse.data.did}`);
34 console.log(` Handle: ${loginResponse.data.handle}`);
35 console.log(` Email: ${loginResponse.data.email || "N/A"}`);
36
37 if (loginResponse.data.did !== atprotoDid) {
38 console.warn(`\n⚠ WARNING: Logged in DID (${loginResponse.data.did}) does not match ATPROTO_DID in .env (${atprotoDid})`);
39 console.warn(" Please update your ATPROTO_DID in src/.env");
40 }
41
42 // Test fetching existing records
43 console.log("\nFetching existing sh.tangled.repo records...");
44 const records = await agent.api.com.atproto.repo.listRecords({
45 repo: loginResponse.data.did,
46 collection: "sh.tangled.repo",
47 limit: 10,
48 });
49
50 console.log(`✓ Found ${records.data.records.length} existing Tangled repo records`);
51
52 if (records.data.records.length > 0) {
53 console.log("\nSample records:");
54 records.data.records.slice(0, 3).forEach((record: any) => {
55 console.log(` - ${record.value.name} (${record.uri})`);
56 });
57 }
58
59 console.log("\n✓ AT Proto connection test completed successfully!");
60
61 } catch (error: any) {
62 console.error("\n✗ AT Proto connection test failed!");
63 console.error(`Error: ${error.message}`);
64 if (error.status) {
65 console.error(`HTTP Status: ${error.status}`);
66 }
67 process.exit(1);
68 }
69}
70
71testAtProtoConnection();