kitty-agent 9.0.0 → 9.0.1
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/out/agent.d.ts +206 -0
- package/out/agent.d.ts.map +1 -0
- package/out/agent.js +329 -0
- package/out/agent.js.map +1 -0
- package/out/cid.d.ts +5 -0
- package/out/cid.d.ts.map +1 -0
- package/out/cid.js +38 -0
- package/out/cid.js.map +1 -0
- package/out/handles/did-document.d.ts +41 -0
- package/out/handles/did-document.d.ts.map +1 -0
- package/out/handles/did-document.js +101 -0
- package/out/handles/did-document.js.map +1 -0
- package/out/handles/doh.d.ts +3 -0
- package/out/handles/doh.d.ts.map +1 -0
- package/out/handles/doh.js +77 -0
- package/out/handles/doh.js.map +1 -0
- package/out/handles/http.d.ts +3 -0
- package/out/handles/http.d.ts.map +1 -0
- package/out/handles/http.js +15 -0
- package/out/handles/http.js.map +1 -0
- package/out/handles/index.d.ts +3 -0
- package/out/handles/index.d.ts.map +1 -0
- package/out/handles/index.js +4 -0
- package/out/handles/index.js.map +1 -0
- package/out/handles/resolve.d.ts +2 -0
- package/out/handles/resolve.d.ts.map +1 -0
- package/out/handles/resolve.js +24 -0
- package/out/handles/resolve.js.map +1 -0
- package/out/index.d.ts +8 -0
- package/out/index.d.ts.map +1 -0
- package/out/index.js +8 -0
- package/out/index.js.map +1 -0
- package/out/oauth-nanostores.d.ts +309 -0
- package/out/oauth-nanostores.d.ts.map +1 -0
- package/out/oauth-nanostores.js +44 -0
- package/out/oauth-nanostores.js.map +1 -0
- package/out/oauth-solidjs.d.ts +74 -0
- package/out/oauth-solidjs.d.ts.map +1 -0
- package/out/oauth-solidjs.js +57 -0
- package/out/oauth-solidjs.js.map +1 -0
- package/out/oauth-stateful-base.d.ts +47 -0
- package/out/oauth-stateful-base.d.ts.map +1 -0
- package/out/oauth-stateful-base.js +58 -0
- package/out/oauth-stateful-base.js.map +1 -0
- package/out/oauth-svelte.d.ts +79 -0
- package/out/oauth-svelte.d.ts.map +1 -0
- package/out/oauth-svelte.js +102 -0
- package/out/oauth-svelte.js.map +1 -0
- package/out/oauth.d.ts +13 -0
- package/out/oauth.d.ts.map +1 -0
- package/out/oauth.js +79 -0
- package/out/oauth.js.map +1 -0
- package/out/pds-helpers.d.ts +8 -0
- package/out/pds-helpers.d.ts.map +1 -0
- package/out/pds-helpers.js +16 -0
- package/out/pds-helpers.js.map +1 -0
- package/out/rkey.d.ts +5 -0
- package/out/rkey.d.ts.map +1 -0
- package/out/rkey.js +10 -0
- package/out/rkey.js.map +1 -0
- package/out/sample-authenticated-client.d.ts +19 -0
- package/out/sample-authenticated-client.d.ts.map +1 -0
- package/out/sample-authenticated-client.js +13 -0
- package/out/sample-authenticated-client.js.map +1 -0
- package/out/shortid.d.ts +22 -0
- package/out/shortid.d.ts.map +1 -0
- package/out/shortid.js +50 -0
- package/out/shortid.js.map +1 -0
- package/out/type-helpers.d.ts +8 -0
- package/out/type-helpers.d.ts.map +1 -0
- package/out/type-helpers.js +3 -0
- package/out/type-helpers.js.map +1 -0
- package/package.json +3 -11
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
https://github.com/mary-ext/atcute
|
|
3
|
+
|
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
6
|
+
in the Software without restriction, including without limitation the rights
|
|
7
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
9
|
+
furnished to do so, subject to the following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be included in all
|
|
12
|
+
copies or substantial portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
20
|
+
SOFTWARE.
|
|
21
|
+
*/
|
|
22
|
+
/**
|
|
23
|
+
* Retrieves AT Protocol PDS endpoint from the DID document, if available
|
|
24
|
+
* @param doc DID document
|
|
25
|
+
* @returns The PDS endpoint, if available
|
|
26
|
+
*/
|
|
27
|
+
export function getPdsEndpoint(doc) {
|
|
28
|
+
return getServiceEndpoint(doc, '#atproto_pds', 'AtprotoPersonalDataServer');
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Retrieve a service endpoint from the DID document, if available
|
|
32
|
+
* @param doc DID document
|
|
33
|
+
* @param serviceId Service ID
|
|
34
|
+
* @param serviceType Service type
|
|
35
|
+
* @returns The requested service endpoint, if available
|
|
36
|
+
*/
|
|
37
|
+
export function getServiceEndpoint(doc, serviceId, serviceType) {
|
|
38
|
+
const did = doc.id;
|
|
39
|
+
const didServiceId = did + serviceId;
|
|
40
|
+
const found = doc.service?.find((service) => service.id === serviceId || service.id === didServiceId);
|
|
41
|
+
if (!found || found.type !== serviceType || typeof found.serviceEndpoint !== 'string') {
|
|
42
|
+
return undefined;
|
|
43
|
+
}
|
|
44
|
+
return validateUrl(found.serviceEndpoint);
|
|
45
|
+
}
|
|
46
|
+
function validateUrl(urlStr) {
|
|
47
|
+
let url;
|
|
48
|
+
try {
|
|
49
|
+
url = new URL(urlStr);
|
|
50
|
+
}
|
|
51
|
+
catch {
|
|
52
|
+
return undefined;
|
|
53
|
+
}
|
|
54
|
+
const proto = url.protocol;
|
|
55
|
+
if (url.hostname && (proto === 'http:' || proto === 'https:')) {
|
|
56
|
+
return urlStr;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
export async function getDidDocument(did) {
|
|
60
|
+
const colon_index = did.indexOf(':', 4);
|
|
61
|
+
const type = did.slice(4, colon_index);
|
|
62
|
+
const ident = did.slice(colon_index + 1);
|
|
63
|
+
// 2. retrieve their DID documents
|
|
64
|
+
let doc;
|
|
65
|
+
if (type === 'plc') {
|
|
66
|
+
const response = await fetch(`https://plc.directory/${did}`);
|
|
67
|
+
if (response.status === 404) {
|
|
68
|
+
throw new Error('did not found in directory');
|
|
69
|
+
}
|
|
70
|
+
if (!response.ok) {
|
|
71
|
+
throw new Error('directory is unreachable');
|
|
72
|
+
}
|
|
73
|
+
const json = await response.json();
|
|
74
|
+
doc = json;
|
|
75
|
+
}
|
|
76
|
+
else if (type === 'web') {
|
|
77
|
+
const DID_WEB_RE = /^([a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*(?:\.[a-zA-Z]{2,}))$/;
|
|
78
|
+
if (!DID_WEB_RE.test(ident)) {
|
|
79
|
+
throw new Error('invalid identifier');
|
|
80
|
+
}
|
|
81
|
+
const response = await fetch(`https://${ident}/.well-known/did.json`);
|
|
82
|
+
if (!response.ok) {
|
|
83
|
+
throw new Error('did document is unreachable');
|
|
84
|
+
}
|
|
85
|
+
const json = await response.json();
|
|
86
|
+
doc = json;
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
throw new Error('unsupported did method');
|
|
90
|
+
}
|
|
91
|
+
return doc;
|
|
92
|
+
}
|
|
93
|
+
export function getDid(didDoc) {
|
|
94
|
+
return didDoc.id;
|
|
95
|
+
}
|
|
96
|
+
export function getHandle(didDoc) {
|
|
97
|
+
return didDoc.alsoKnownAs
|
|
98
|
+
?.find(handle => handle.startsWith('at://'))
|
|
99
|
+
?.slice('at://'.length);
|
|
100
|
+
}
|
|
101
|
+
//# sourceMappingURL=did-document.js.map
|
|
@@ -0,0 +1 @@
|
|
|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IAAmB,CAAC;IAC9B,CAAC;SAAM,CAAC;QACJ,MAAM,IAAI,KAAK,CAAC,wBAAwB,CAAC,CAAC;IAC9C,CAAC;IAED,OAAO,GAAG,CAAC;AACf,CAAC;AAED,MAAM,UAAU,MAAM,CAAC,MAAmB;IACtC,OAAO,MAAM,CAAC,EAAS,CAAC;AAC5B,CAAC;AAED,MAAM,UAAU,SAAS,CAAC,MAAmB;IACzC,OAAO,MAAM,CAAC,WAAW;QACrB,EAAE,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,MAAM,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;QAC5C,EAAE,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;AAChC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"doh.d.ts","sourceRoot":"","sources":["../../src/handles/doh.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAC;AAM5C,eAAO,MAAM,mBAAmB,GAAU,QAAQ,MAAM,KAAG,OAAO,CAAC,GAAG,CAiDrE,CAAC"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { isDid } from "./index.js";
|
|
2
|
+
const SUBDOMAIN = '_atproto';
|
|
3
|
+
const PREFIX = 'did=';
|
|
4
|
+
export const resolveHandleViaDoH = async (handle) => {
|
|
5
|
+
const url = new URL('https://mozilla.cloudflare-dns.com/dns-query');
|
|
6
|
+
url.searchParams.set('type', 'TXT');
|
|
7
|
+
url.searchParams.set('name', `${SUBDOMAIN}.${handle}`);
|
|
8
|
+
const response = await fetch(url, {
|
|
9
|
+
method: 'GET',
|
|
10
|
+
headers: { accept: 'application/dns-json' },
|
|
11
|
+
redirect: 'follow',
|
|
12
|
+
});
|
|
13
|
+
const type = response.headers.get('content-type')?.trim();
|
|
14
|
+
if (!response.ok) {
|
|
15
|
+
const message = type?.startsWith('text/plain')
|
|
16
|
+
? await response.text()
|
|
17
|
+
: `failed to resolve ${handle}`;
|
|
18
|
+
throw new Error(message);
|
|
19
|
+
}
|
|
20
|
+
if (type !== 'application/dns-json') {
|
|
21
|
+
throw new Error('unexpected response from DoH server');
|
|
22
|
+
}
|
|
23
|
+
const result = asResult(await response.json());
|
|
24
|
+
const answers = result.Answer?.filter(isAnswerTxt).map(extractTxtData) ?? [];
|
|
25
|
+
for (let i = 0; i < answers.length; i++) {
|
|
26
|
+
// skip if the line does not start with "did="
|
|
27
|
+
if (!answers[i].startsWith(PREFIX)) {
|
|
28
|
+
continue;
|
|
29
|
+
}
|
|
30
|
+
// ensure there is no other entry starting with "did="
|
|
31
|
+
for (let j = i + 1; j < answers.length; j++) {
|
|
32
|
+
if (answers[j].startsWith(PREFIX)) {
|
|
33
|
+
break;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
const did = answers[i].slice(PREFIX.length);
|
|
37
|
+
if (isDid(did)) {
|
|
38
|
+
return did;
|
|
39
|
+
}
|
|
40
|
+
break;
|
|
41
|
+
}
|
|
42
|
+
throw new Error(`failed to resolve ${handle}`);
|
|
43
|
+
};
|
|
44
|
+
const isResult = (result) => {
|
|
45
|
+
if (result === null || typeof result !== 'object') {
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
return ('Status' in result &&
|
|
49
|
+
typeof result.Status === 'number' &&
|
|
50
|
+
(!('Answer' in result) || (Array.isArray(result.Answer) && result.Answer.every(isAnswer))));
|
|
51
|
+
};
|
|
52
|
+
const asResult = (result) => {
|
|
53
|
+
if (!isResult(result)) {
|
|
54
|
+
throw new TypeError('unexpected DoH response');
|
|
55
|
+
}
|
|
56
|
+
return result;
|
|
57
|
+
};
|
|
58
|
+
const isAnswer = (answer) => {
|
|
59
|
+
if (answer === null || typeof answer !== 'object') {
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
return ('name' in answer &&
|
|
63
|
+
typeof answer.name === 'string' &&
|
|
64
|
+
'type' in answer &&
|
|
65
|
+
typeof answer.type === 'number' &&
|
|
66
|
+
'data' in answer &&
|
|
67
|
+
typeof answer.data === 'string' &&
|
|
68
|
+
'TTL' in answer &&
|
|
69
|
+
typeof answer.TTL === 'number');
|
|
70
|
+
};
|
|
71
|
+
const isAnswerTxt = (answer) => {
|
|
72
|
+
return answer.type === 16;
|
|
73
|
+
};
|
|
74
|
+
const extractTxtData = (answer) => {
|
|
75
|
+
return answer.data.replace(/^"|"$/g, '').replace(/\\"/g, '"');
|
|
76
|
+
};
|
|
77
|
+
//# sourceMappingURL=doh.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"doh.js","sourceRoot":"","sources":["../../src/handles/doh.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAEnC,MAAM,SAAS,GAAG,UAAU,CAAC;AAC7B,MAAM,MAAM,GAAG,MAAM,CAAC;AAEtB,MAAM,CAAC,MAAM,mBAAmB,GAAG,KAAK,EAAE,MAAc,EAAgB,EAAE;IACzE,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,8CAA8C,CAAC,CAAC;IACpE,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;IACpC,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,MAAM,EAAE,GAAG,SAAS,IAAI,MAAM,EAAE,CAAC,CAAC;IAEvD,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,EAAE;QACjC,MAAM,EAAE,KAAK;QACb,OAAO,EAAE,EAAE,MAAM,EAAE,sBAAsB,EAAE;QAC3C,QAAQ,EAAE,QAAQ;KAClB,CAAC,CAAC;IAEH,MAAM,IAAI,GAAG,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,EAAE,IAAI,EAAE,CAAC;IAC1D,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;QAClB,MAAM,OAAO,GAAG,IAAI,EAAE,UAAU,CAAC,YAAY,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,MAAM,cAAc,GAAG,CAAC,MAAiB,EAAU,EAAE;IACpD,OAAO,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;AAC/D,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../src/handles/http.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAC;AAG5C,eAAO,MAAM,oBAAoB,GAAU,QAAQ,MAAM,KAAG,OAAO,CAAC,GAAG,CAgBtE,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { isDid } from "./index.js";
|
|
2
|
+
export const resolveHandleViaHttp = async (handle) => {
|
|
3
|
+
const url = new URL('/.well-known/atproto-did', `https://${handle}`);
|
|
4
|
+
const response = await fetch(url, { redirect: 'error' });
|
|
5
|
+
if (!response.ok) {
|
|
6
|
+
throw new Error('domain is unreachable');
|
|
7
|
+
}
|
|
8
|
+
const text = await response.text();
|
|
9
|
+
const did = text.split('\n')[0].trim();
|
|
10
|
+
if (isDid(did)) {
|
|
11
|
+
return did;
|
|
12
|
+
}
|
|
13
|
+
throw new Error(`failed to resolve ${handle}`);
|
|
14
|
+
};
|
|
15
|
+
//# sourceMappingURL=http.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http.js","sourceRoot":"","sources":["../../src/handles/http.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAEnC,MAAM,CAAC,MAAM,oBAAoB,GAAG,KAAK,EAAE,MAAc,EAAgB,EAAE;IAC1E,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,0BAA0B,EAAE,WAAW,MAAM,EAAE,CAAC,CAAC;IAErE,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,EAAE,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC,CAAC;IACzD,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;QAClB,MAAM,IAAI,KAAK,CAAC,uBAAuB,CAAC,CAAC;IAC1C,CAAC;IAED,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;IAEnC,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAE,CAAC,IAAI,EAAE,CAAC;IACxC,IAAI,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC;QAChB,OAAO,GAAG,CAAC;IACZ,CAAC;IAED,MAAM,IAAI,KAAK,CAAC,qBAAqB,MAAM,EAAE,CAAC,CAAC;AAChD,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/handles/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAC;AAE5C,eAAO,MAAM,KAAK,GAAI,KAAK,MAAM,KAAG,GAAG,IAAI,GAE1C,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/handles/index.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,KAAK,GAAG,CAAC,GAAW,EAAc,EAAE;IAChD,OAAO,kDAAkD,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AACrE,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolve.d.ts","sourceRoot":"","sources":["../../src/handles/resolve.ts"],"names":[],"mappings":"AAMA,wBAAsB,wBAAwB,CAAC,MAAM,EAAE,MAAM,sCAsB5D"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { isDid } from "./index.js";
|
|
2
|
+
import { resolveHandleViaDoH } from "./doh.js";
|
|
3
|
+
import { resolveHandleViaHttp } from "./http.js";
|
|
4
|
+
const didCache = new Map();
|
|
5
|
+
export async function resolveHandleAnonymously(handle) {
|
|
6
|
+
if (isDid(handle))
|
|
7
|
+
return handle;
|
|
8
|
+
if (didCache.has(handle)) {
|
|
9
|
+
return didCache.get(handle);
|
|
10
|
+
}
|
|
11
|
+
const results = await Promise.allSettled([
|
|
12
|
+
resolveHandleViaHttp(handle),
|
|
13
|
+
resolveHandleViaDoH(handle),
|
|
14
|
+
]);
|
|
15
|
+
const did = results
|
|
16
|
+
.find(p => p.status === 'fulfilled')
|
|
17
|
+
?.value;
|
|
18
|
+
if (did === undefined) {
|
|
19
|
+
throw results;
|
|
20
|
+
}
|
|
21
|
+
didCache.set(handle, did);
|
|
22
|
+
return did;
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=resolve.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolve.js","sourceRoot":"","sources":["../../src/handles/resolve.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAC/C,OAAO,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAC;AAEjD,MAAM,QAAQ,GAAG,IAAI,GAAG,EAAe,CAAC;AACxC,MAAM,CAAC,KAAK,UAAU,wBAAwB,CAAC,MAAc;IACzD,IAAI,KAAK,CAAC,MAAM,CAAC;QAAE,OAAO,MAAM,CAAC;IACjC,IAAI,QAAQ,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC;QACvB,OAAO,QAAQ,CAAC,GAAG,CAAC,MAAM,CAAE,CAAC;IACjC,CAAC;IAED,MAAM,OAAO,GAAG,MAAM,OAAO,CAAC,UAAU,CAAC;QACrC,oBAAoB,CAAC,MAAM,CAAC;QAC5B,mBAAmB,CAAC,MAAM,CAAC;KAC9B,CAAC,CAAC;IAEH,MAAM,GAAG,GAAG,OAAO;SACd,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,KAAK,WAAW,CAAC;QACpC,EAAE,KAAK,CAAC;IAEZ,IAAI,GAAG,KAAK,SAAS,EAAE,CAAC;QACpB,MAAM,OAAO,CAAC;IAClB,CAAC;IAED,QAAQ,CAAC,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAE1B,OAAO,GAAG,CAAC;AACf,CAAC"}
|
package/out/index.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export * from './agent.js';
|
|
2
|
+
export * from './cid.js';
|
|
3
|
+
export * from './rkey.js';
|
|
4
|
+
export * from './pds-helpers.js';
|
|
5
|
+
export * from './shortid.js';
|
|
6
|
+
export * from './sample-authenticated-client.js';
|
|
7
|
+
export { resolveHandleAnonymously } from './handles/resolve.js';
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,kBAAkB,CAAC;AACjC,cAAc,cAAc,CAAC;AAC7B,cAAc,kCAAkC,CAAC;AACjD,OAAO,EAAE,wBAAwB,EAAE,MAAM,sBAAsB,CAAC"}
|
package/out/index.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export * from './agent.js';
|
|
2
|
+
export * from './cid.js';
|
|
3
|
+
export * from './rkey.js';
|
|
4
|
+
export * from './pds-helpers.js';
|
|
5
|
+
export * from './shortid.js';
|
|
6
|
+
export * from './sample-authenticated-client.js';
|
|
7
|
+
export { resolveHandleAnonymously } from './handles/resolve.js';
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
package/out/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,kBAAkB,CAAC;AACjC,cAAc,cAAc,CAAC;AAC7B,cAAc,kCAAkC,CAAC;AACjD,OAAO,EAAE,wBAAwB,EAAE,MAAM,sBAAsB,CAAC"}
|
|
@@ -0,0 +1,309 @@
|
|
|
1
|
+
import type { Did } from "@atcute/lexicons";
|
|
2
|
+
import type { KittyAgent } from "./agent.js";
|
|
3
|
+
import { BaseStatefulOAuthClient, type Account, type LoginState } from "./oauth-stateful-base.js";
|
|
4
|
+
export declare namespace Nanostores {
|
|
5
|
+
namespace Atom {
|
|
6
|
+
export type AllKeys<T> = T extends any ? keyof T : never;
|
|
7
|
+
type Primitive = boolean | number | string;
|
|
8
|
+
export type ReadonlyIfObject<Value> = Value extends undefined ? Value : Value extends (...args: any) => any ? Value : Value extends Primitive ? Value : Value extends object ? Readonly<Value> : Value;
|
|
9
|
+
/**
|
|
10
|
+
* Store object.
|
|
11
|
+
*/
|
|
12
|
+
export interface ReadableAtom<Value = any> {
|
|
13
|
+
/**
|
|
14
|
+
* Get store value.
|
|
15
|
+
*
|
|
16
|
+
* In contrast with {@link ReadableAtom#value} this value will be always
|
|
17
|
+
* initialized even if store had no listeners.
|
|
18
|
+
*
|
|
19
|
+
* ```js
|
|
20
|
+
* $store.get()
|
|
21
|
+
* ```
|
|
22
|
+
*
|
|
23
|
+
* @returns Store value.
|
|
24
|
+
*/
|
|
25
|
+
get(): Value;
|
|
26
|
+
/**
|
|
27
|
+
* Listeners count.
|
|
28
|
+
*/
|
|
29
|
+
readonly lc: number;
|
|
30
|
+
/**
|
|
31
|
+
* Subscribe to store changes.
|
|
32
|
+
*
|
|
33
|
+
* In contrast with {@link Store#subscribe} it do not call listener
|
|
34
|
+
* immediately.
|
|
35
|
+
*
|
|
36
|
+
* @param listener Callback with store value and old value.
|
|
37
|
+
* @returns Function to remove listener.
|
|
38
|
+
*/
|
|
39
|
+
listen(listener: (value: ReadonlyIfObject<Value>, oldValue: ReadonlyIfObject<Value>) => void): () => void;
|
|
40
|
+
/**
|
|
41
|
+
* Low-level method to notify listeners about changes in the store.
|
|
42
|
+
*
|
|
43
|
+
* Can cause unexpected behaviour when combined with frontend frameworks
|
|
44
|
+
* that perform equality checks for values, such as React.
|
|
45
|
+
*/
|
|
46
|
+
notify(oldValue?: ReadonlyIfObject<Value>): void;
|
|
47
|
+
/**
|
|
48
|
+
* Unbind all listeners.
|
|
49
|
+
*/
|
|
50
|
+
off(): void;
|
|
51
|
+
/**
|
|
52
|
+
* Subscribe to store changes and call listener immediately.
|
|
53
|
+
*
|
|
54
|
+
* ```
|
|
55
|
+
* import { $router } from '../store'
|
|
56
|
+
*
|
|
57
|
+
* $router.subscribe(page => {
|
|
58
|
+
* console.log(page)
|
|
59
|
+
* })
|
|
60
|
+
* ```
|
|
61
|
+
*
|
|
62
|
+
* @param listener Callback with store value and old value.
|
|
63
|
+
* @returns Function to remove listener.
|
|
64
|
+
*/
|
|
65
|
+
subscribe(listener: (value: ReadonlyIfObject<Value>, oldValue?: ReadonlyIfObject<Value>) => void): () => void;
|
|
66
|
+
/**
|
|
67
|
+
* Low-level method to read store’s value without calling `onStart`.
|
|
68
|
+
*
|
|
69
|
+
* Try to use only {@link ReadableAtom#get}.
|
|
70
|
+
* Without subscribers, value can be undefined.
|
|
71
|
+
*/
|
|
72
|
+
readonly value: undefined | Value;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Store with a way to manually change the value.
|
|
76
|
+
*/
|
|
77
|
+
export interface WritableAtom<Value = any> extends ReadableAtom<Value> {
|
|
78
|
+
/**
|
|
79
|
+
* Change store value.
|
|
80
|
+
*
|
|
81
|
+
* ```js
|
|
82
|
+
* $router.set({ path: location.pathname, page: parse(location.pathname) })
|
|
83
|
+
* ```
|
|
84
|
+
*
|
|
85
|
+
* @param newValue New store value.
|
|
86
|
+
*/
|
|
87
|
+
set(newValue: Value): void;
|
|
88
|
+
}
|
|
89
|
+
export interface PreinitializedWritableAtom<Value extends any> extends WritableAtom<Value> {
|
|
90
|
+
readonly value: Value;
|
|
91
|
+
}
|
|
92
|
+
export type Atom<Value = any> = ReadableAtom<Value> | WritableAtom<Value>;
|
|
93
|
+
/**
|
|
94
|
+
* Create store with atomic value. It could be a string or an object, which you
|
|
95
|
+
* will replace completely.
|
|
96
|
+
*
|
|
97
|
+
* If you want to change keys in the object inside store, use {@link map}.
|
|
98
|
+
*
|
|
99
|
+
* ```js
|
|
100
|
+
* import { atom, onMount } from 'nanostores'
|
|
101
|
+
*
|
|
102
|
+
* // Initial value
|
|
103
|
+
* export const $router = atom({ path: '', page: 'home' })
|
|
104
|
+
*
|
|
105
|
+
* function parse () {
|
|
106
|
+
* $router.set({ path: location.pathname, page: parse(location.pathname) })
|
|
107
|
+
* }
|
|
108
|
+
*
|
|
109
|
+
* // Listen for URL changes on first store’s listener.
|
|
110
|
+
* onMount($router, () => {
|
|
111
|
+
* parse()
|
|
112
|
+
* window.addEventListener('popstate', parse)
|
|
113
|
+
* return () => {
|
|
114
|
+
* window.removeEventListener('popstate', parse)
|
|
115
|
+
* }
|
|
116
|
+
* })
|
|
117
|
+
* ```
|
|
118
|
+
*
|
|
119
|
+
* @param initialValue Initial value of the store.
|
|
120
|
+
* @returns The store object with methods to subscribe.
|
|
121
|
+
*/
|
|
122
|
+
export type atom = <Value, StoreExt = {}>(...args: undefined extends Value ? [] | [Value] : [Value]) => PreinitializedWritableAtom<Value> & StoreExt;
|
|
123
|
+
export {};
|
|
124
|
+
}
|
|
125
|
+
namespace Map {
|
|
126
|
+
type AllKeys<T> = Nanostores.Atom.AllKeys<T>;
|
|
127
|
+
type ReadableAtom<Value = any> = Nanostores.Atom.ReadableAtom<Value>;
|
|
128
|
+
type ReadonlyIfObject<Value> = Nanostores.Atom.ReadonlyIfObject<Value>;
|
|
129
|
+
type WritableAtom<Value = any> = Nanostores.Atom.WritableAtom<Value>;
|
|
130
|
+
type KeyofBase = keyof any;
|
|
131
|
+
type Get<T, K extends KeyofBase> = Extract<T, {
|
|
132
|
+
[K1 in K]: any;
|
|
133
|
+
}>[K];
|
|
134
|
+
export type WritableStore<Value = any> = (Value extends object ? MapStore<Value> : never) | WritableAtom<Value>;
|
|
135
|
+
export type Store<Value = any> = ReadableAtom<Value> | WritableStore<Value>;
|
|
136
|
+
export type AnyStore<Value = any> = {
|
|
137
|
+
get(): Value;
|
|
138
|
+
readonly value: undefined | Value;
|
|
139
|
+
};
|
|
140
|
+
export type StoreValue<SomeStore> = SomeStore extends {
|
|
141
|
+
get(): infer Value;
|
|
142
|
+
} ? Value : any;
|
|
143
|
+
export type BaseMapStore<Value = any> = {
|
|
144
|
+
setKey: (key: any, value: any) => any;
|
|
145
|
+
} & WritableAtom<Value>;
|
|
146
|
+
export type MapStoreKeys<SomeStore> = SomeStore extends {
|
|
147
|
+
setKey: (key: infer K, ...args: any[]) => any;
|
|
148
|
+
} ? K : AllKeys<StoreValue<SomeStore>>;
|
|
149
|
+
export interface MapStore<Value extends object = any> extends WritableAtom<Value> {
|
|
150
|
+
/**
|
|
151
|
+
* Subscribe to store changes.
|
|
152
|
+
*
|
|
153
|
+
* In contrast with {@link Store#subscribe} it do not call listener
|
|
154
|
+
* immediately.
|
|
155
|
+
*
|
|
156
|
+
* @param listener Callback with store value and old value.
|
|
157
|
+
* @param changedKey Key that was changed. Will present only if `setKey`
|
|
158
|
+
* has been used to change a store.
|
|
159
|
+
* @returns Function to remove listener.
|
|
160
|
+
*/
|
|
161
|
+
listen(listener: (value: ReadonlyIfObject<Value>, oldValue: ReadonlyIfObject<Value>, changedKey: AllKeys<Value>) => void): () => void;
|
|
162
|
+
/**
|
|
163
|
+
* Low-level method to notify listeners about changes in the store.
|
|
164
|
+
*
|
|
165
|
+
* Can cause unexpected behaviour when combined with frontend frameworks
|
|
166
|
+
* that perform equality checks for values, such as React.
|
|
167
|
+
*/
|
|
168
|
+
notify(oldValue?: ReadonlyIfObject<Value>, changedKey?: AllKeys<Value>): void;
|
|
169
|
+
/**
|
|
170
|
+
* Change store value.
|
|
171
|
+
*
|
|
172
|
+
* ```js
|
|
173
|
+
* $settings.set({ theme: 'dark' })
|
|
174
|
+
* ```
|
|
175
|
+
*
|
|
176
|
+
* Operation is atomic, subscribers will be notified once with the new value.
|
|
177
|
+
* `changedKey` will be undefined
|
|
178
|
+
*
|
|
179
|
+
* @param newValue New store value.
|
|
180
|
+
*/
|
|
181
|
+
set(newValue: Value): void;
|
|
182
|
+
/**
|
|
183
|
+
* Change key in store value.
|
|
184
|
+
*
|
|
185
|
+
* ```js
|
|
186
|
+
* $settings.setKey('theme', 'dark')
|
|
187
|
+
* ```
|
|
188
|
+
*
|
|
189
|
+
* To delete key set `undefined`.
|
|
190
|
+
*
|
|
191
|
+
* ```js
|
|
192
|
+
* $settings.setKey('theme', undefined)
|
|
193
|
+
* ```
|
|
194
|
+
*
|
|
195
|
+
* @param key The key name.
|
|
196
|
+
* @param value New value.
|
|
197
|
+
*/
|
|
198
|
+
setKey<Key extends AllKeys<Value>>(key: Key, value: Get<Value, Key> | Value[Key]): void;
|
|
199
|
+
/**
|
|
200
|
+
* Subscribe to store changes and call listener immediately.
|
|
201
|
+
*
|
|
202
|
+
* ```
|
|
203
|
+
* import { $router } from '../store'
|
|
204
|
+
*
|
|
205
|
+
* $router.subscribe(page => {
|
|
206
|
+
* console.log(page)
|
|
207
|
+
* })
|
|
208
|
+
* ```
|
|
209
|
+
*
|
|
210
|
+
* @param listener Callback with store value and old value.
|
|
211
|
+
* @param changedKey Key that was changed. Will present only
|
|
212
|
+
* if `setKey` has been used to change a store.
|
|
213
|
+
* @returns Function to remove listener.
|
|
214
|
+
*/
|
|
215
|
+
subscribe(listener: (value: ReadonlyIfObject<Value>, oldValue: ReadonlyIfObject<Value> | undefined, changedKey: AllKeys<Value> | undefined) => void): () => void;
|
|
216
|
+
}
|
|
217
|
+
export interface PreinitializedMapStore<Value extends object = any> extends MapStore<Value> {
|
|
218
|
+
readonly value: Value;
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Create map store. Map store is a store with key-value object
|
|
222
|
+
* as a store value.
|
|
223
|
+
*
|
|
224
|
+
* @param init Initialize store and return store destructor.
|
|
225
|
+
* @returns The store object with methods to subscribe.
|
|
226
|
+
*/
|
|
227
|
+
export type map = <Value extends object, StoreExt extends object = {}>(value?: Value) => PreinitializedMapStore<Value> & StoreExt;
|
|
228
|
+
export {};
|
|
229
|
+
}
|
|
230
|
+
namespace Task {
|
|
231
|
+
interface Task<Value> extends Promise<Value> {
|
|
232
|
+
t: true;
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
namespace Computed {
|
|
236
|
+
type ReadableAtom<Value = any> = Nanostores.Atom.ReadableAtom<Value>;
|
|
237
|
+
type AnyStore<Value = any> = Nanostores.Map.AnyStore<Value>;
|
|
238
|
+
type Store<Value = any> = Nanostores.Map.Store<Value>;
|
|
239
|
+
type StoreValue<SomeStore> = Nanostores.Map.StoreValue<SomeStore>;
|
|
240
|
+
type Task<Value> = Nanostores.Task.Task<Value>;
|
|
241
|
+
export type StoreValues<Stores extends AnyStore[]> = {
|
|
242
|
+
[Index in keyof Stores]: StoreValue<Stores[Index]>;
|
|
243
|
+
};
|
|
244
|
+
export interface computed {
|
|
245
|
+
<Value extends any, OriginStore extends Store>(stores: OriginStore, cb: (value: StoreValue<OriginStore>) => Task<Value>): ReadableAtom<undefined | Value>;
|
|
246
|
+
<Value extends any, OriginStores extends AnyStore[]>(stores: [...OriginStores], cb: (...values: StoreValues<OriginStores>) => Task<Value>): ReadableAtom<undefined | Value>;
|
|
247
|
+
<Value extends any, OriginStore extends Store>(stores: OriginStore, cb: (value: StoreValue<OriginStore>) => Value): ReadableAtom<Value>;
|
|
248
|
+
/**
|
|
249
|
+
* Create derived store, which use generates value from another stores.
|
|
250
|
+
*
|
|
251
|
+
* ```js
|
|
252
|
+
* import { computed } from 'nanostores'
|
|
253
|
+
*
|
|
254
|
+
* import { $users } from './users.js'
|
|
255
|
+
*
|
|
256
|
+
* export const $admins = computed($users, users => {
|
|
257
|
+
* return users.filter(user => user.isAdmin)
|
|
258
|
+
* })
|
|
259
|
+
* ```
|
|
260
|
+
*
|
|
261
|
+
* An async function can be evaluated by using {@link task}.
|
|
262
|
+
*
|
|
263
|
+
* ```js
|
|
264
|
+
* import { computed, task } from 'nanostores'
|
|
265
|
+
*
|
|
266
|
+
* import { $userId } from './users.js'
|
|
267
|
+
*
|
|
268
|
+
* export const $user = computed($userId, userId => task(async () => {
|
|
269
|
+
* const response = await fetch(`https://my-api/users/${userId}`)
|
|
270
|
+
* return response.json()
|
|
271
|
+
* }))
|
|
272
|
+
* ```
|
|
273
|
+
*/
|
|
274
|
+
<Value extends any, OriginStores extends AnyStore[]>(stores: [...OriginStores], cb: (...values: StoreValues<OriginStores>) => Task<Value> | Value): ReadableAtom<Value>;
|
|
275
|
+
}
|
|
276
|
+
export {};
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
export declare class StatefulSvelteOAuthClient<TClient> extends BaseStatefulOAuthClient<TClient> {
|
|
280
|
+
private _account;
|
|
281
|
+
private _agent;
|
|
282
|
+
private _client;
|
|
283
|
+
get account(): Nanostores.Atom.ReadableAtom<Account | undefined>;
|
|
284
|
+
readonly user: Nanostores.Atom.ReadableAtom<LoginState<TClient> | undefined>;
|
|
285
|
+
readonly handle: Nanostores.Atom.ReadableAtom<string | undefined>;
|
|
286
|
+
readonly did: Nanostores.Atom.ReadableAtom<Did | undefined>;
|
|
287
|
+
readonly pds: Nanostores.Atom.ReadableAtom<string | undefined>;
|
|
288
|
+
protected get internal_account(): Account | undefined;
|
|
289
|
+
protected get internal_user(): LoginState<TClient> | undefined;
|
|
290
|
+
protected get internal_agent(): KittyAgent | undefined;
|
|
291
|
+
protected get internal_client(): TClient | undefined;
|
|
292
|
+
protected set internal_account(value: Account | undefined);
|
|
293
|
+
protected set internal_agent(value: KittyAgent | undefined);
|
|
294
|
+
protected set internal_client(value: TClient | undefined);
|
|
295
|
+
constructor(options: {
|
|
296
|
+
clientId: string;
|
|
297
|
+
redirectUri: string;
|
|
298
|
+
scope: string;
|
|
299
|
+
}, nanostores: {
|
|
300
|
+
atom: Nanostores.Atom.atom;
|
|
301
|
+
computed: Nanostores.Computed.computed;
|
|
302
|
+
}, createClient: (loginState: {
|
|
303
|
+
readonly handle: string;
|
|
304
|
+
readonly did: Did;
|
|
305
|
+
readonly pds: string;
|
|
306
|
+
readonly agent: KittyAgent;
|
|
307
|
+
}) => TClient);
|
|
308
|
+
}
|
|
309
|
+
//# sourceMappingURL=oauth-nanostores.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"oauth-nanostores.d.ts","sourceRoot":"","sources":["../src/oauth-nanostores.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,EAAE,uBAAuB,EAAkB,KAAK,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAGlH,yBAAiB,UAAU,CAAC;IACxB,UAAiB,IAAI,CAAC;QAClB,MAAM,MAAM,OAAO,CAAC,CAAC,IAAI,CAAC,SAAS,GAAG,GAAG,MAAM,CAAC,GAAG,KAAK,CAAC;QAEzD,KAAK,SAAS,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,CAAC;QAE3C,MAAM,MAAM,gBAAgB,CAAC,KAAK,IAAI,KAAK,SAAS,SAAS,GACvD,KAAK,GACL,KAAK,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,KAAK,GAAG,GACnC,KAAK,GACL,KAAK,SAAS,SAAS,GACvB,KAAK,GACL,KAAK,SAAS,MAAM,GACpB,QAAQ,CAAC,KAAK,CAAC,GACf,KAAK,CAAC;QAEZ;;WAEG;QACH,MAAM,WA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