nuxt-atproto 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -244,13 +244,24 @@ const likedPost = await atproto.agent.account.likePost({cid, uri})
244
244
  console.log(likedPost.data)
245
245
  ```
246
246
 
247
+ <br />
248
+
249
+ ## 🧩 useAgent(service?: string, fetch?: any)
250
+
251
+ A composable provided by `nuxt-atproto` that offers methods for user authentication and session management, including authenticating, signing out and session restore.
252
+
253
+ ```html
254
+
255
+ <script setup lang="ts">
256
+ const agent = useAgent('public')
257
+ </script>
258
+ ```
259
+
247
260
  **Parameters:**
248
261
 
249
- - `service` (optional): The base URL of the ATProto service.
262
+ - `service` (optional): Choose between `public`, `private` or a custom service endpoint.
250
263
  - `fetch` (optional): A custom fetch implementation.
251
264
 
252
- **Returns:** An object with both public AtpAgent or authenticated account Agent.
253
-
254
265
  <br />
255
266
 
256
267
  ## License
package/dist/module.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "nuxt-atproto",
3
3
  "configKey": "atproto",
4
- "version": "0.0.2",
4
+ "version": "0.0.3",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "1.0.1",
7
7
  "unbuild": "3.5.0"
package/dist/module.mjs CHANGED
@@ -65,7 +65,8 @@ const module = defineNuxtModule({
65
65
  JSON.stringify(_options.oauth.clientMetadata.local, null, 2)
66
66
  );
67
67
  addImportsDir(resolve("./runtime/composables"));
68
- addPlugin(resolve("./runtime/plugin.client"));
68
+ addImportsDir(resolve("./runtime/utils"));
69
+ addPlugin(resolve("./runtime/plugin"));
69
70
  }
70
71
  });
71
72
 
@@ -0,0 +1,8 @@
1
+ import { Agent } from "@atproto/api";
2
+ /**
3
+ * Provide AT Protocol agent
4
+ *
5
+ * @param service
6
+ * @param fetch
7
+ */
8
+ export declare function useAgent(service: string, fetch?: any): Agent;
@@ -0,0 +1,23 @@
1
+ import { useNuxtApp, useRuntimeConfig } from "#app";
2
+ import { Agent, AtpAgent } from "@atproto/api";
3
+ export function useAgent(service, fetch) {
4
+ const runtimeConfig = useRuntimeConfig();
5
+ const { $atproto } = useNuxtApp();
6
+ switch (service) {
7
+ case "private":
8
+ if (!$atproto.session.value) {
9
+ throw new Error("Not authenticated");
10
+ }
11
+ return new Agent($atproto.session.value);
12
+ case "public":
13
+ return new AtpAgent({
14
+ service: runtimeConfig.public.atproto.serviceEndpoint.public,
15
+ fetch
16
+ });
17
+ default:
18
+ return new AtpAgent({
19
+ service,
20
+ fetch
21
+ });
22
+ }
23
+ }
@@ -0,0 +1,8 @@
1
+ import type { OAuthSession } from '@atproto/oauth-client';
2
+ export declare function useAtproto(service?: string, fetch?: any): {
3
+ signIn: (serviceEndpoint?: string, options?: any) => Promise<void>;
4
+ signInWithHandle: (handle?: string, options?: any) => Promise<void>;
5
+ signOut: () => Promise<void>;
6
+ restore: (did: string) => Promise<OAuthSession>;
7
+ agent: import("@atproto/api").Agent;
8
+ };
@@ -1,6 +1,5 @@
1
- import { Agent, AtpAgent } from "@atproto/api";
2
1
  import { useRuntimeConfig, useNuxtApp } from "nuxt/app";
3
- import { reactive } from "vue";
2
+ import { useAgent } from "./useAgent.js";
4
3
  export function useAtproto(service, fetch) {
5
4
  const runtimeConfig = useRuntimeConfig();
6
5
  async function signIn(serviceEndpoint = runtimeConfig.public.atproto.serviceEndpoint.private, options = runtimeConfig.public.atproto.oauth.signInOptions) {
@@ -48,21 +47,6 @@ export function useAtproto(service, fetch) {
48
47
  console.log("User signed out");
49
48
  }
50
49
  }
51
- function useAgent(service2, fetch2) {
52
- const { $atproto } = useNuxtApp();
53
- const runtimeConfig2 = useRuntimeConfig();
54
- if (!service2) {
55
- service2 = runtimeConfig2.public.atproto.serviceEndpoint.public;
56
- }
57
- let accountAgent;
58
- if ($atproto && $atproto.session.value) {
59
- accountAgent = new Agent($atproto.session.value);
60
- }
61
- return reactive({
62
- public: new AtpAgent({ service: service2, fetch: fetch2 }),
63
- account: accountAgent
64
- });
65
- }
66
50
  const agent = useAgent(service, fetch);
67
51
  return {
68
52
  signIn,
@@ -0,0 +1,2 @@
1
+ export declare function resolveActorDid(handle: string): Promise<string>;
2
+ export declare function resolveActorServiceEndpoint(did: string): Promise<string>;
@@ -0,0 +1,16 @@
1
+ import { useAgent } from "../composables/useAgent.js";
2
+ export async function resolveActorDid(handle) {
3
+ const agent = useAgent("public");
4
+ const { did } = await agent.com.atproto.identity.resolveHandle({
5
+ handle
6
+ }).then((result) => result.data);
7
+ return did;
8
+ }
9
+ export async function resolveActorServiceEndpoint(did) {
10
+ const response = await fetch(`https://plc.directory/${did}`);
11
+ if (!response.ok) {
12
+ throw new Error("Failed to fetch profile service endpoint");
13
+ }
14
+ const data = await response.json();
15
+ return data.service[0].serviceEndpoint;
16
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nuxt-atproto",
3
- "version": "0.0.2",
3
+ "version": "0.0.3",
4
4
  "description": "Interact with AT Protocol and Bluesky in your Nuxt.js application",
5
5
  "keywords": [
6
6
  "nuxt",
File without changes