nuxt-atproto 0.0.1 → 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 +24 -13
- package/dist/module.d.mts +1 -1
- package/dist/module.json +1 -1
- package/dist/module.mjs +13 -16
- package/dist/runtime/composables/useAgent.d.ts +8 -0
- package/dist/runtime/composables/useAgent.js +23 -0
- package/dist/runtime/composables/useAtproto.d.ts +8 -0
- package/dist/runtime/composables/useAtproto.js +1 -17
- package/dist/runtime/utils/utilActor.d.ts +2 -0
- package/dist/runtime/utils/utilActor.js +16 -0
- package/package.json +1 -1
- /package/dist/runtime/{plugin.client.d.ts → plugin.d.ts} +0 -0
- /package/dist/runtime/{plugin.client.js → plugin.js} +0 -0
package/README.md
CHANGED
|
@@ -59,16 +59,16 @@ defineNuxtConfig({
|
|
|
59
59
|
remote: '',
|
|
60
60
|
// configuration for the local client_metadata.json
|
|
61
61
|
local: {
|
|
62
|
-
client_id: '',
|
|
63
|
-
client_name: '',
|
|
64
|
-
client_uri: '',
|
|
65
|
-
logo_uri: '',
|
|
66
|
-
tos_uri: '',
|
|
67
|
-
policy_uri: '',
|
|
68
|
-
redirect_uris: [''],
|
|
69
|
-
scope:
|
|
70
|
-
grant_types: [],
|
|
71
|
-
response_types: [],
|
|
62
|
+
client_id: 'https://nuxt-atproto.pages.dev/client-metadata.json',
|
|
63
|
+
client_name: 'nuxt-atproto',
|
|
64
|
+
client_uri: 'https://nuxt-atproto.pages.dev',
|
|
65
|
+
logo_uri: 'https://nuxt-atproto.pages.dev/logo.png',
|
|
66
|
+
tos_uri: 'https://nuxt-atproto.pages.dev',
|
|
67
|
+
policy_uri: 'https://nuxt-atproto.pages.dev',
|
|
68
|
+
redirect_uris: ['https://nuxt-atproto.pages.dev'],
|
|
69
|
+
scope: "atproto transition:generic",
|
|
70
|
+
grant_types: ["authorization_code", "refresh_token"],
|
|
71
|
+
response_types: ["code"],
|
|
72
72
|
token_endpoint_auth_method: 'none',
|
|
73
73
|
application_type: 'web',
|
|
74
74
|
dpop_bound_access_tokens: true
|
|
@@ -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):
|
|
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.d.mts
CHANGED
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { mkdirSync, writeFileSync
|
|
1
|
+
import { mkdirSync, writeFileSync } from 'node:fs';
|
|
2
2
|
import { defineNuxtModule, createResolver, addImportsDir, addPlugin } from '@nuxt/kit';
|
|
3
3
|
|
|
4
4
|
const module = defineNuxtModule({
|
|
@@ -23,7 +23,7 @@ const module = defineNuxtModule({
|
|
|
23
23
|
logo_uri: "",
|
|
24
24
|
tos_uri: "",
|
|
25
25
|
policy_uri: "",
|
|
26
|
-
redirect_uris: [
|
|
26
|
+
redirect_uris: [],
|
|
27
27
|
scope: "atproto",
|
|
28
28
|
grant_types: [],
|
|
29
29
|
response_types: [],
|
|
@@ -54,22 +54,19 @@ const module = defineNuxtModule({
|
|
|
54
54
|
config.optimizeDeps.include.push("@atproto/oauth-client-browser");
|
|
55
55
|
config.optimizeDeps.include.push("@atproto/api");
|
|
56
56
|
});
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
return;
|
|
63
|
-
}
|
|
64
|
-
writeFileSync(
|
|
65
|
-
publicDir + "/client-metadata.json",
|
|
66
|
-
JSON.stringify(_options.oauth.clientMetadata.local, null, 2)
|
|
67
|
-
);
|
|
68
|
-
} else {
|
|
69
|
-
rmSync(publicDir + "/client-metadata.json");
|
|
57
|
+
try {
|
|
58
|
+
mkdirSync(publicDir, { recursive: true });
|
|
59
|
+
} catch (error) {
|
|
60
|
+
console.error("Failed creating /public/client-metadata.json", error);
|
|
61
|
+
return;
|
|
70
62
|
}
|
|
63
|
+
writeFileSync(
|
|
64
|
+
publicDir + "/client-metadata.json",
|
|
65
|
+
JSON.stringify(_options.oauth.clientMetadata.local, null, 2)
|
|
66
|
+
);
|
|
71
67
|
addImportsDir(resolve("./runtime/composables"));
|
|
72
|
-
|
|
68
|
+
addImportsDir(resolve("./runtime/utils"));
|
|
69
|
+
addPlugin(resolve("./runtime/plugin"));
|
|
73
70
|
}
|
|
74
71
|
});
|
|
75
72
|
|
|
@@ -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 {
|
|
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,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
|
File without changes
|
|
File without changes
|