forked from
baileytownsend.dev/atproto-sveltekit-template
A build your own ATProto adventure, OAuth already figured out for you.
1// This wrappers around https://tangled.org/mary.my.id/atcute packages that call https://constellation.microcosm.blue
2// Constellation is a great way to get how records are connected without an appview, like seeing who and how many people has poked you!
3import { Client, ok, simpleFetchHandler } from '@atcute/client';
4import { env } from '$env/dynamic/public';
5import type {} from '@atcute/microcosm';
6import type { Did } from '@atproto/api';
7
8//Loads who has poked you using https://constellation.microcosm.blue
9export const getPokes = async (did: string, count: number = 10, cursor: string | undefined = undefined) => {
10 const constellation = new Client({
11 handler: simpleFetchHandler({ service: env.PUBLIC_CONSTELLATION_ENDPOINT ?? 'https://constellation.microcosm.blue' }),
12 });
13 const backlinks = await ok(
14 constellation.get('blue.microcosm.links.getBacklinks', {
15 params: {
16 subject: did as Did,
17 source: 'xyz.atpoke.graph.poke:subject',
18 limit: count,
19 cursor
20 },
21 }),
22 );
23
24 return backlinks;
25};
26
27//Gets the users handle via https://slingshot.microcosm.blue
28//You will want to somewhat cache the results from this. I am on the front end so if someone pokes someone 10 times it only resolves the handle once
29export const getHandle = async (did: string) => {
30 const slingshot = new Client({
31 handler: simpleFetchHandler({ service: env.PUBLIC_SLINGSHOT_ENDPOINT ?? 'https://slingshot.microcosm.blue' }),
32 });
33
34 const resolved = await ok(
35 slingshot.get('com.bad-example.identity.resolveMiniDoc', {
36 params: {
37 identifier: did as Did,
38 },
39 }),
40 );
41
42 return resolved.handle;
43};