pups-client 0.0.0-stage → 0.2.0
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/LICENSE +21 -0
- package/README.md +163 -2
- package/dist/cli/bin.d.ts +3 -0
- package/dist/cli/bin.d.ts.map +1 -0
- package/dist/cli/bin.js +4 -0
- package/dist/cli/bin.js.map +1 -0
- package/dist/cli/file-store.d.ts +21 -0
- package/dist/cli/file-store.d.ts.map +1 -0
- package/dist/cli/file-store.js +59 -0
- package/dist/cli/file-store.js.map +1 -0
- package/dist/cli/loopback.d.ts +28 -0
- package/dist/cli/loopback.d.ts.map +1 -0
- package/dist/cli/loopback.js +82 -0
- package/dist/cli/loopback.js.map +1 -0
- package/dist/cli/main.d.ts +16 -0
- package/dist/cli/main.d.ts.map +1 -0
- package/dist/cli/main.js +337 -0
- package/dist/cli/main.js.map +1 -0
- package/dist/client.d.ts +151 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +427 -0
- package/dist/client.js.map +1 -0
- package/dist/discovery.d.ts +58 -0
- package/dist/discovery.d.ts.map +1 -0
- package/dist/discovery.js +138 -0
- package/dist/discovery.js.map +1 -0
- package/dist/errors.d.ts +77 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +59 -0
- package/dist/errors.js.map +1 -0
- package/dist/feed.d.ts +314 -0
- package/dist/feed.d.ts.map +1 -0
- package/dist/feed.js +805 -0
- package/dist/feed.js.map +1 -0
- package/dist/file-types.d.ts +30 -0
- package/dist/file-types.d.ts.map +1 -0
- package/dist/file-types.js +67 -0
- package/dist/file-types.js.map +1 -0
- package/dist/host-meta.d.ts +71 -0
- package/dist/host-meta.d.ts.map +1 -0
- package/dist/host-meta.js +122 -0
- package/dist/host-meta.js.map +1 -0
- package/dist/index.d.ts +25 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +16 -0
- package/dist/index.js.map +1 -0
- package/dist/oauth.d.ts +54 -0
- package/dist/oauth.d.ts.map +1 -0
- package/dist/oauth.js +124 -0
- package/dist/oauth.js.map +1 -0
- package/dist/paths.d.ts +32 -0
- package/dist/paths.d.ts.map +1 -0
- package/dist/paths.js +91 -0
- package/dist/paths.js.map +1 -0
- package/dist/scopes.d.ts +28 -0
- package/dist/scopes.d.ts.map +1 -0
- package/dist/scopes.js +56 -0
- package/dist/scopes.js.map +1 -0
- package/dist/session.d.ts +194 -0
- package/dist/session.d.ts.map +1 -0
- package/dist/session.js +317 -0
- package/dist/session.js.map +1 -0
- package/dist/store/indexeddb-store.d.ts +23 -0
- package/dist/store/indexeddb-store.d.ts.map +1 -0
- package/dist/store/indexeddb-store.js +116 -0
- package/dist/store/indexeddb-store.js.map +1 -0
- package/dist/store/memory-store.d.ts +13 -0
- package/dist/store/memory-store.d.ts.map +1 -0
- package/dist/store/memory-store.js +22 -0
- package/dist/store/memory-store.js.map +1 -0
- package/dist/store/token-store.d.ts +35 -0
- package/dist/store/token-store.d.ts.map +1 -0
- package/dist/store/token-store.js +2 -0
- package/dist/store/token-store.js.map +1 -0
- package/dist/tabs.d.ts +29 -0
- package/dist/tabs.d.ts.map +1 -0
- package/dist/tabs.js +51 -0
- package/dist/tabs.js.map +1 -0
- package/dist/tokens.d.ts +59 -0
- package/dist/tokens.d.ts.map +1 -0
- package/dist/tokens.js +200 -0
- package/dist/tokens.js.map +1 -0
- package/dist/util.d.ts +23 -0
- package/dist/util.d.ts.map +1 -0
- package/dist/util.js +109 -0
- package/dist/util.js.map +1 -0
- package/dist/version.d.ts +2 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +2 -0
- package/dist/version.js.map +1 -0
- package/package.json +55 -4
- package/src/cli/bin.ts +4 -0
- package/src/cli/file-store.ts +66 -0
- package/src/cli/loopback.ts +103 -0
- package/src/cli/main.ts +329 -0
- package/src/client.ts +496 -0
- package/src/discovery.ts +178 -0
- package/src/errors.ts +136 -0
- package/src/feed.ts +1007 -0
- package/src/file-types.ts +80 -0
- package/src/host-meta.ts +148 -0
- package/src/index.ts +49 -0
- package/src/oauth.ts +163 -0
- package/src/paths.ts +92 -0
- package/src/scopes.ts +68 -0
- package/src/session.ts +396 -0
- package/src/store/indexeddb-store.ts +140 -0
- package/src/store/memory-store.ts +28 -0
- package/src/store/token-store.ts +36 -0
- package/src/tabs.ts +61 -0
- package/src/tokens.ts +208 -0
- package/src/util.ts +118 -0
- package/src/version.ts +1 -0
package/dist/oauth.js
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { discover, normalizeDomain } from './discovery.js';
|
|
2
|
+
import { PupsError } from './errors.js';
|
|
3
|
+
import { fetchWithTimeout, parseUrl, randomString, sha256Base64url } from './util.js';
|
|
4
|
+
const tokenTimeoutMs = 10_000;
|
|
5
|
+
/** PKCE (RFC 7636) with S256, the only method RFC-6 accepts. */
|
|
6
|
+
export async function createPkce() {
|
|
7
|
+
// 48 random bytes give a 64-character verifier, within the 43–128 RFC 7636 allows.
|
|
8
|
+
const verifier = randomString(48);
|
|
9
|
+
return { verifier, challenge: await sha256Base64url(verifier) };
|
|
10
|
+
}
|
|
11
|
+
/** The URL of the authorization endpoint for a request (RFC-6 "Authorization", "Request"). */
|
|
12
|
+
export function authorizationUrl(server, request) {
|
|
13
|
+
const url = new URL(server.authorizationEndpoint);
|
|
14
|
+
url.searchParams.set('response_type', 'code');
|
|
15
|
+
url.searchParams.set('client_id', request.clientId);
|
|
16
|
+
url.searchParams.set('redirect_uri', request.redirectUri);
|
|
17
|
+
url.searchParams.set('scope', request.scopes.join(' '));
|
|
18
|
+
url.searchParams.set('state', request.state);
|
|
19
|
+
url.searchParams.set('code_challenge', request.codeChallenge);
|
|
20
|
+
url.searchParams.set('code_challenge_method', 'S256');
|
|
21
|
+
return url.href;
|
|
22
|
+
}
|
|
23
|
+
/** The query parameters an authorization response may carry; removed from the address bar after reading. */
|
|
24
|
+
export const callbackParamNames = ['code', 'state', 'iss', 'error', 'error_description', 'error_uri'];
|
|
25
|
+
/**
|
|
26
|
+
* Reads an authorization response from a URL. Returns undefined unless the URL carries a `state` created by this
|
|
27
|
+
* library (prefixed `r.` or `p.`) together with `code` or `error`, so apps can call it on every page load.
|
|
28
|
+
*/
|
|
29
|
+
export function parseCallback(url) {
|
|
30
|
+
const params = parseUrl(url)?.searchParams;
|
|
31
|
+
const state = params?.get('state');
|
|
32
|
+
if (!params || !state || !/^[rp]\./.test(state) || (!params.has('code') && !params.has('error')))
|
|
33
|
+
return;
|
|
34
|
+
const get = (name) => params.get(name) ?? undefined;
|
|
35
|
+
return { state, code: get('code'), iss: get('iss'), error: get('error'), errorDescription: get('error_description') };
|
|
36
|
+
}
|
|
37
|
+
function parseTokenResponse(json) {
|
|
38
|
+
const { access_token, token_type, expires_in, refresh_token, scope, me } = json;
|
|
39
|
+
if (typeof access_token != 'string' || !access_token || typeof token_type != 'string' || token_type.toLowerCase() != 'bearer')
|
|
40
|
+
throw new PupsError('authorization_failed', 'The token response has no bearer access token.');
|
|
41
|
+
if (typeof me != 'string')
|
|
42
|
+
throw new PupsError('authorization_failed', 'The token response has no "me".');
|
|
43
|
+
return {
|
|
44
|
+
accessToken: access_token,
|
|
45
|
+
expiresIn: typeof expires_in == 'number' && expires_in > 0 ? expires_in : 3600,
|
|
46
|
+
refreshToken: typeof refresh_token == 'string' && refresh_token ? refresh_token : undefined,
|
|
47
|
+
scopes: typeof scope == 'string' ? scope.split(' ').filter(Boolean) : undefined,
|
|
48
|
+
me,
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Sends a request to the token endpoint. Failures are mapped for the caller's situation:
|
|
53
|
+
* for a code exchange every OAuth error is `authorization_failed`; for a refresh, `invalid_grant` and other
|
|
54
|
+
* `4xx` answers end the session (`session_expired`), while network problems, `429` and `5xx` stay retryable.
|
|
55
|
+
*/
|
|
56
|
+
export async function tokenRequest(fetchFn, server, params, kind, signal) {
|
|
57
|
+
const response = await fetchWithTimeout(fetchFn, server.tokenEndpoint, {
|
|
58
|
+
method: 'POST',
|
|
59
|
+
headers: { 'Content-Type': 'application/x-www-form-urlencoded', Accept: 'application/json' },
|
|
60
|
+
body: new URLSearchParams(params).toString(),
|
|
61
|
+
credentials: 'omit',
|
|
62
|
+
cache: 'no-store',
|
|
63
|
+
}, tokenTimeoutMs, signal);
|
|
64
|
+
let json = {};
|
|
65
|
+
try {
|
|
66
|
+
json = await response.json();
|
|
67
|
+
}
|
|
68
|
+
catch {
|
|
69
|
+
// Handled below by status.
|
|
70
|
+
}
|
|
71
|
+
if (response.ok)
|
|
72
|
+
return parseTokenResponse(json);
|
|
73
|
+
const status = response.status;
|
|
74
|
+
const error = typeof json.error == 'string' ? json.error : undefined;
|
|
75
|
+
const serverMessage = typeof json.error_description == 'string' ? json.error_description : undefined;
|
|
76
|
+
const detail = `${error ?? `HTTP ${status}`}${serverMessage ? `: ${serverMessage}` : ''}`;
|
|
77
|
+
if (status == 429 || status >= 500)
|
|
78
|
+
throw new PupsError(status == 429 ? 'rate_limited' : 'server_error', `The token endpoint failed (${detail}).`, { status, serverMessage });
|
|
79
|
+
throw kind == 'refresh'
|
|
80
|
+
? new PupsError('session_expired', `The session can't be renewed (${detail}). Log in again.`, { status, serverMessage })
|
|
81
|
+
: new PupsError('authorization_failed', `The code exchange failed (${detail}).`, { status, serverMessage });
|
|
82
|
+
}
|
|
83
|
+
/** Revokes a token (RFC 7009). Returns whether the server confirmed it; never throws. */
|
|
84
|
+
export async function revokeToken(fetchFn, server, clientId, token, hint) {
|
|
85
|
+
try {
|
|
86
|
+
const response = await fetchWithTimeout(fetchFn, server.revocationEndpoint, {
|
|
87
|
+
method: 'POST',
|
|
88
|
+
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
|
89
|
+
body: new URLSearchParams({ token, token_type_hint: hint, client_id: clientId }).toString(),
|
|
90
|
+
credentials: 'omit',
|
|
91
|
+
cache: 'no-store',
|
|
92
|
+
}, tokenTimeoutMs);
|
|
93
|
+
return response.ok;
|
|
94
|
+
}
|
|
95
|
+
catch {
|
|
96
|
+
return false;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Verifies `me` from a token response (RFC-6 "What apps must do", step 2) and returns it normalized.
|
|
101
|
+
* `me` must name one of the server's identity hosts; otherwise discovery on `me` must lead to the same issuer.
|
|
102
|
+
* @throws {PupsError} `identity_mismatch`
|
|
103
|
+
*/
|
|
104
|
+
export async function verifyMe(fetchFn, me, server) {
|
|
105
|
+
const mismatch = (why) => new PupsError('identity_mismatch', `The server named "${me}" as the user's identity, but ${why}.`);
|
|
106
|
+
const url = parseUrl(me);
|
|
107
|
+
if (!url || url.protocol != 'https:' || url.pathname != '/' || url.search || url.hash || url.port)
|
|
108
|
+
throw mismatch('that is not of the form https://<host>/');
|
|
109
|
+
const normalized = normalizeDomain(me);
|
|
110
|
+
const host = new URL(normalized).hostname;
|
|
111
|
+
if (server.identityHosts.includes(host))
|
|
112
|
+
return normalized;
|
|
113
|
+
let other;
|
|
114
|
+
try {
|
|
115
|
+
other = await discover(normalized, fetchFn);
|
|
116
|
+
}
|
|
117
|
+
catch (e) {
|
|
118
|
+
throw mismatch(`discovery on it failed: ${e.message}`);
|
|
119
|
+
}
|
|
120
|
+
if (other.issuer != server.issuer)
|
|
121
|
+
throw mismatch(`it leads to another issuer (${other.issuer}, not ${server.issuer})`);
|
|
122
|
+
return normalized;
|
|
123
|
+
}
|
|
124
|
+
//# sourceMappingURL=oauth.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"oauth.js","sourceRoot":"","sources":["../src/oauth.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,eAAe,EAAmB,MAAM,gBAAgB,CAAA;AAC3E,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AACvC,OAAO,EAAE,gBAAgB,EAAE,QAAQ,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,WAAW,CAAA;AAErF,MAAM,cAAc,GAAG,MAAM,CAAA;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;AACnB,CAAC"}
|
package/dist/paths.d.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { PupsServer, WellKnownPath } from './discovery.js';
|
|
2
|
+
/**
|
|
3
|
+
* Turns a path as apps pass it into an absolute path below `storage_base`.
|
|
4
|
+
* A path that starts with `/` is absolute; any other path is relative to the app's own directory.
|
|
5
|
+
*/
|
|
6
|
+
export declare const resolvePath: (path: string, appDataPath: string) => string;
|
|
7
|
+
/**
|
|
8
|
+
* Applies the path rules of RFC-6 to an absolute, unencoded path. The server applies them too, and stays
|
|
9
|
+
* authoritative; checking here gives immediate, explained errors. Rejecting dot segments here also means that
|
|
10
|
+
* the URL the library sends always names exactly this path, because nothing is left for `fetch` to resolve.
|
|
11
|
+
* @throws {PupsError} `invalid_path`
|
|
12
|
+
*/
|
|
13
|
+
export declare function validatePath(path: string, wellKnownPaths: readonly WellKnownPath[]): void;
|
|
14
|
+
/** Percent-encodes each segment of an absolute path, keeping the slashes. */
|
|
15
|
+
export declare const encodePath: (path: string) => string;
|
|
16
|
+
/**
|
|
17
|
+
* Whether the scope path (of a `write:` scope) covers `path`. A scope path ending in `/` covers its subtree,
|
|
18
|
+
* any other covers exactly one file. Comparison is segment by segment, because directory scopes end with `/`.
|
|
19
|
+
*/
|
|
20
|
+
export declare const scopeCovers: (scopePath: string, path: string) => boolean;
|
|
21
|
+
/** The declared well-known entry that covers `path`, the most specific one if several do. */
|
|
22
|
+
export declare function wellKnownEntryFor(path: string, wellKnownPaths: readonly WellKnownPath[]): WellKnownPath | undefined;
|
|
23
|
+
/** The URL where `path` is written (RFC-6 "Upload API"). */
|
|
24
|
+
export declare const storageUrl: (server: PupsServer, path: string) => string;
|
|
25
|
+
/**
|
|
26
|
+
* The URL where readers find `path` (RFC-6 "Public URLs"): `public_base` + path, or, for a file under a
|
|
27
|
+
* well-known entry with a `url`, that `url` plus the rest of the path.
|
|
28
|
+
*/
|
|
29
|
+
export declare function publicUrl(server: PupsServer, path: string): string;
|
|
30
|
+
/** The path of a public URL, the reverse of {@link publicUrl}, or undefined if the URL is not a file of this server. */
|
|
31
|
+
export declare function pathFromPublicUrl(server: PupsServer, url: string): string | undefined;
|
|
32
|
+
//# sourceMappingURL=paths.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"paths.d.ts","sourceRoot":"","sources":["../src/paths.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA;AAQ/D;;;GAGG;AACH,eAAO,MAAM,WAAW,GAAI,MAAM,MAAM,EAAE,aAAa,MAAM,WAAqD,CAAA;AAMlH;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,cAAc,EAAE,SAAS,aAAa,EAAE,GAAG,IAAI,CAkBzF;AAED,6EAA6E;AAC7E,eAAO,MAAM,UAAU,GAAI,MAAM,MAAM,WAAsD,CAAA;AAK7F;;;GAGG;AACH,eAAO,MAAM,WAAW,GAAI,WAAW,MAAM,EAAE,MAAM,MAAM,YACe,CAAA;AAE1E,6FAA6F;AAC7F,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,EAAE,cAAc,EAAE,SAAS,aAAa,EAAE,GAAG,aAAa,GAAG,SAAS,CAKnH;AAED,4DAA4D;AAC5D,eAAO,MAAM,UAAU,GAAI,QAAQ,UAAU,EAAE,MAAM,MAAM,WAAmD,CAAA;AAE9G;;;GAGG;AACH,wBAAgB,SAAS,CAAC,MAAM,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAIlE;AAED,wHAAwH;AACxH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,UAAU,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAWrF"}
|
package/dist/paths.js
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { PupsError } from './errors.js';
|
|
2
|
+
import { controlChars } from './util.js';
|
|
3
|
+
const maxPathBytes = 512;
|
|
4
|
+
const invalid = (path, reason) => new PupsError('invalid_path', `Invalid path "${path}": ${reason} (RFC-6, Paths).`);
|
|
5
|
+
/**
|
|
6
|
+
* Turns a path as apps pass it into an absolute path below `storage_base`.
|
|
7
|
+
* A path that starts with `/` is absolute; any other path is relative to the app's own directory.
|
|
8
|
+
*/
|
|
9
|
+
export const resolvePath = (path, appDataPath) => path.startsWith('/') ? path : appDataPath + path;
|
|
10
|
+
/** Whether `path` is a single file declared in `well_known_paths` under `/.well-known/`. */
|
|
11
|
+
const isDeclaredWellKnownFile = (path, wellKnownPaths) => path.startsWith('/.well-known/') && wellKnownPaths.some(w => w.path == path);
|
|
12
|
+
/**
|
|
13
|
+
* Applies the path rules of RFC-6 to an absolute, unencoded path. The server applies them too, and stays
|
|
14
|
+
* authoritative; checking here gives immediate, explained errors. Rejecting dot segments here also means that
|
|
15
|
+
* the URL the library sends always names exactly this path, because nothing is left for `fetch` to resolve.
|
|
16
|
+
* @throws {PupsError} `invalid_path`
|
|
17
|
+
*/
|
|
18
|
+
export function validatePath(path, wellKnownPaths) {
|
|
19
|
+
if (!path.startsWith('/'))
|
|
20
|
+
throw invalid(path, 'it must start with "/"');
|
|
21
|
+
try {
|
|
22
|
+
encodeURIComponent(path);
|
|
23
|
+
}
|
|
24
|
+
catch {
|
|
25
|
+
throw invalid(path, 'it is not valid UTF-8');
|
|
26
|
+
}
|
|
27
|
+
if (new TextEncoder().encode(path).length > maxPathBytes)
|
|
28
|
+
throw invalid(path, `it is longer than ${maxPathBytes} bytes`);
|
|
29
|
+
if (path.endsWith('/'))
|
|
30
|
+
throw invalid(path, 'it ends with "/"; directories can\'t be written');
|
|
31
|
+
if (controlChars.test(path))
|
|
32
|
+
throw invalid(path, 'it contains a control character');
|
|
33
|
+
if (/[\\:]/.test(path))
|
|
34
|
+
throw invalid(path, 'it contains "\\" or ":"');
|
|
35
|
+
const wellKnownFile = isDeclaredWellKnownFile(path, wellKnownPaths);
|
|
36
|
+
for (const segment of path.slice(1).split('/')) {
|
|
37
|
+
if (!segment)
|
|
38
|
+
throw invalid(path, 'it has an empty segment');
|
|
39
|
+
if (segment == '.' || segment == '..')
|
|
40
|
+
throw invalid(path, `it has a "${segment}" segment`);
|
|
41
|
+
if (segment.startsWith('.') && !wellKnownFile)
|
|
42
|
+
throw invalid(path, `segment "${segment}" starts with a dot`);
|
|
43
|
+
if (/[. ]$/.test(segment))
|
|
44
|
+
throw invalid(path, `segment "${segment}" ends with a dot or a space`);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
/** Percent-encodes each segment of an absolute path, keeping the slashes. */
|
|
48
|
+
export const encodePath = (path) => path.split('/').map(encodeURIComponent).join('/');
|
|
49
|
+
/** Decodes each segment of an encoded path. */
|
|
50
|
+
const decodePath = (path) => path.split('/').map(decodeURIComponent).join('/');
|
|
51
|
+
/**
|
|
52
|
+
* Whether the scope path (of a `write:` scope) covers `path`. A scope path ending in `/` covers its subtree,
|
|
53
|
+
* any other covers exactly one file. Comparison is segment by segment, because directory scopes end with `/`.
|
|
54
|
+
*/
|
|
55
|
+
export const scopeCovers = (scopePath, path) => scopePath.endsWith('/') ? path.startsWith(scopePath) : path == scopePath;
|
|
56
|
+
/** The declared well-known entry that covers `path`, the most specific one if several do. */
|
|
57
|
+
export function wellKnownEntryFor(path, wellKnownPaths) {
|
|
58
|
+
let best;
|
|
59
|
+
for (const entry of wellKnownPaths)
|
|
60
|
+
if (scopeCovers(entry.path, path) && (!best || entry.path.length > best.path.length))
|
|
61
|
+
best = entry;
|
|
62
|
+
return best;
|
|
63
|
+
}
|
|
64
|
+
/** The URL where `path` is written (RFC-6 "Upload API"). */
|
|
65
|
+
export const storageUrl = (server, path) => server.storageBase + encodePath(path).slice(1);
|
|
66
|
+
/**
|
|
67
|
+
* The URL where readers find `path` (RFC-6 "Public URLs"): `public_base` + path, or, for a file under a
|
|
68
|
+
* well-known entry with a `url`, that `url` plus the rest of the path.
|
|
69
|
+
*/
|
|
70
|
+
export function publicUrl(server, path) {
|
|
71
|
+
const entry = wellKnownEntryFor(path, server.wellKnownPaths);
|
|
72
|
+
if (entry?.url)
|
|
73
|
+
return entry.url + encodePath(path.slice(entry.path.length));
|
|
74
|
+
return server.publicBase + encodePath(path).slice(1);
|
|
75
|
+
}
|
|
76
|
+
/** The path of a public URL, the reverse of {@link publicUrl}, or undefined if the URL is not a file of this server. */
|
|
77
|
+
export function pathFromPublicUrl(server, url) {
|
|
78
|
+
try {
|
|
79
|
+
const entries = server.wellKnownPaths.filter(w => w.url).sort((a, b) => b.url.length - a.url.length);
|
|
80
|
+
for (const entry of entries)
|
|
81
|
+
if (entry.path.endsWith('/') ? url.startsWith(entry.url) : url == entry.url)
|
|
82
|
+
return entry.path + decodePath(url.slice(entry.url.length));
|
|
83
|
+
if (url.startsWith(server.publicBase))
|
|
84
|
+
return '/' + decodePath(url.slice(server.publicBase.length));
|
|
85
|
+
}
|
|
86
|
+
catch {
|
|
87
|
+
// Malformed percent-encoding: not one of our URLs.
|
|
88
|
+
}
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
//# sourceMappingURL=paths.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"paths.js","sourceRoot":"","sources":["../src/paths.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAEvC,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAA;AAExC,MAAM,YAAY,GAAG,GAAG,CAAA;AAExB,MAAM,OAAO,GAAG,CAAC,IAAY,EAAE,MAAc,EAAE,EAAE,CAC/C,IAAI,SAAS,CAAC,cAAc,EAAE,iBAAiB,IAAI,MAAM,MAAM,kBAAkB,CAAC,CAAA;AAEpF;;;GAGG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,IAAY,EAAE,WAAmB,EAAE,EAAE,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,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AC,GAAG,CAAC,UAAU,CAAC,KAAK,CAAC,GAAI,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,KAAK,CAAC,GAAG;gBAC1E,OAAO,KAAK,CAAC,IAAI,GAAG,UAAU,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,GAAI,CAAC,MAAM,CAAC,CAAC,CAAA;QAChE,IAAI,GAAG,CAAC,UAAU,CAAC,MAAM,CAAC,UAAU,CAAC;YAAE,OAAO,GAAG,GAAG,UAAU,CAAC,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,CAAA;IACrG,CAAC;IAAC,MAAM,CAAC;QACP,mDAAmD;IACrD,CAAC;IACD,OAAM;AACR,CAAC"}
|
package/dist/scopes.d.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { PupsServer } from './discovery.js';
|
|
2
|
+
/**
|
|
3
|
+
* A scope an app can request (RFC-6 "Scopes"):
|
|
4
|
+
* - `'identify'`: sign-in only; the session can't write.
|
|
5
|
+
* - `'appdata'`: shorthand for `write:/appdata/<client-host>/`, the app's own directory.
|
|
6
|
+
* - `` `write:/${string}` ``: a well-known path declared by the server, or a file or directory inside a declared directory.
|
|
7
|
+
*/
|
|
8
|
+
export type Scope = 'identify' | 'appdata' | `write:/${string}`;
|
|
9
|
+
/** The host of the `client_id`, which names the app's own directory. */
|
|
10
|
+
export declare const clientHostOf: (clientId: string) => string;
|
|
11
|
+
/** The app's own directory, `/appdata/<client-host>/`. */
|
|
12
|
+
export declare const appDataPathOf: (clientId: string) => string;
|
|
13
|
+
/** Expands `'appdata'` and removes duplicates. */
|
|
14
|
+
export declare function expandScopes(scopes: readonly Scope[], clientId: string): string[];
|
|
15
|
+
/** The decoded path of a `write:` scope, or undefined for other scopes and malformed ones. */
|
|
16
|
+
export declare function writeScopePath(scope: string): string | undefined;
|
|
17
|
+
/** The decoded paths of all `write:` scopes in a granted scope list. */
|
|
18
|
+
export declare const writeScopePaths: (scopes: readonly string[]) => string[];
|
|
19
|
+
/**
|
|
20
|
+
* Checks requested scopes against the server before the redirect, so that problems surface immediately instead of
|
|
21
|
+
* as an OAuth error after a round trip. Only two kinds of write scope exist: the app's own directory, and declared
|
|
22
|
+
* well-known paths (or paths inside declared directories).
|
|
23
|
+
* @throws {PupsError} `invalid_scope`
|
|
24
|
+
*/
|
|
25
|
+
export declare function validateScopes(scopes: readonly string[], server: PupsServer, clientId: string): void;
|
|
26
|
+
/** Whether the granted scopes allow writing the absolute path `path`. */
|
|
27
|
+
export declare const scopesCoverPath: (scopes: readonly string[], path: string) => boolean;
|
|
28
|
+
//# sourceMappingURL=scopes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scopes.d.ts","sourceRoot":"","sources":["../src/scopes.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAGhD;;;;;GAKG;AACH,MAAM,MAAM,KAAK,GAAG,UAAU,GAAG,SAAS,GAAG,UAAU,MAAM,EAAE,CAAA;AAE/D,wEAAwE;AACxE,eAAO,MAAM,YAAY,GAAI,UAAU,MAAM,WAA+B,CAAA;AAE5E,0DAA0D;AAC1D,eAAO,MAAM,aAAa,GAAI,UAAU,MAAM,WAA0C,CAAA;AAExF,kDAAkD;AAClD,wBAAgB,YAAY,CAAC,MAAM,EAAE,SAAS,KAAK,EAAE,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,EAAE,CAGjF;AAID,8FAA8F;AAC9F,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAShE;AAED,wEAAwE;AACxE,eAAO,MAAM,eAAe,GAAI,QAAQ,SAAS,MAAM,EAAE,aACe,CAAA;AAExE;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,EAAE,MAAM,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,GAAG,IAAI,CAepG;AAED,yEAAyE;AACzE,eAAO,MAAM,eAAe,GAAI,QAAQ,SAAS,MAAM,EAAE,EAAE,MAAM,MAAM,YACE,CAAA"}
|
package/dist/scopes.js
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { PupsError } from './errors.js';
|
|
2
|
+
import { scopeCovers } from './paths.js';
|
|
3
|
+
/** The host of the `client_id`, which names the app's own directory. */
|
|
4
|
+
export const clientHostOf = (clientId) => new URL(clientId).hostname;
|
|
5
|
+
/** The app's own directory, `/appdata/<client-host>/`. */
|
|
6
|
+
export const appDataPathOf = (clientId) => `/appdata/${clientHostOf(clientId)}/`;
|
|
7
|
+
/** Expands `'appdata'` and removes duplicates. */
|
|
8
|
+
export function expandScopes(scopes, clientId) {
|
|
9
|
+
const expanded = scopes.map(s => s == 'appdata' ? `write:${appDataPathOf(clientId)}` : s);
|
|
10
|
+
return [...new Set(expanded)];
|
|
11
|
+
}
|
|
12
|
+
const scopePathSyntax = /^\/(?:[A-Za-z0-9\-._~/]|%[0-9A-Fa-f]{2})*$/;
|
|
13
|
+
/** The decoded path of a `write:` scope, or undefined for other scopes and malformed ones. */
|
|
14
|
+
export function writeScopePath(scope) {
|
|
15
|
+
if (!scope.startsWith('write:'))
|
|
16
|
+
return;
|
|
17
|
+
const encoded = scope.slice('write:'.length);
|
|
18
|
+
if (!scopePathSyntax.test(encoded))
|
|
19
|
+
return;
|
|
20
|
+
try {
|
|
21
|
+
return decodeURIComponent(encoded);
|
|
22
|
+
}
|
|
23
|
+
catch {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
/** The decoded paths of all `write:` scopes in a granted scope list. */
|
|
28
|
+
export const writeScopePaths = (scopes) => scopes.map(writeScopePath).filter((p) => p !== undefined);
|
|
29
|
+
/**
|
|
30
|
+
* Checks requested scopes against the server before the redirect, so that problems surface immediately instead of
|
|
31
|
+
* as an OAuth error after a round trip. Only two kinds of write scope exist: the app's own directory, and declared
|
|
32
|
+
* well-known paths (or paths inside declared directories).
|
|
33
|
+
* @throws {PupsError} `invalid_scope`
|
|
34
|
+
*/
|
|
35
|
+
export function validateScopes(scopes, server, clientId) {
|
|
36
|
+
if (!scopes.length)
|
|
37
|
+
throw new PupsError('invalid_scope', 'Request at least one scope.');
|
|
38
|
+
const appDataPath = appDataPathOf(clientId);
|
|
39
|
+
for (const scope of scopes) {
|
|
40
|
+
if (scope == 'identify')
|
|
41
|
+
continue;
|
|
42
|
+
const path = writeScopePath(scope);
|
|
43
|
+
if (path === undefined)
|
|
44
|
+
throw new PupsError('invalid_scope', `"${scope}" is not a PUPS scope. Use 'identify', 'appdata' or 'write:/<path>' (RFC-6, Scopes).`);
|
|
45
|
+
if (path == appDataPath)
|
|
46
|
+
continue;
|
|
47
|
+
if (path.startsWith('/appdata/'))
|
|
48
|
+
throw new PupsError('invalid_scope', `"${scope}": an app may only ask for its own directory, ${appDataPath}. Use the 'appdata' shorthand (RFC-6, Scopes).`);
|
|
49
|
+
const declared = server.wellKnownPaths.some(w => w.path == path || (w.path.endsWith('/') && path.startsWith(w.path)));
|
|
50
|
+
if (!declared)
|
|
51
|
+
throw new PupsError('invalid_scope', `"${scope}": ${path} is not a well-known path declared by ${new URL(server.domain).host}. Check server.wellKnownPaths before asking (RFC-6, Well-known paths).`);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
/** Whether the granted scopes allow writing the absolute path `path`. */
|
|
55
|
+
export const scopesCoverPath = (scopes, path) => writeScopePaths(scopes).some(scopePath => scopeCovers(scopePath, path));
|
|
56
|
+
//# sourceMappingURL=scopes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scopes.js","sourceRoot":"","sources":["../src/scopes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAEvC,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AAUxC,wEAAwE;AACxE,MAAM,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AAW,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC,CAAA"}
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
import { type PupsServer } from './discovery.js';
|
|
2
|
+
import { PupsError } from './errors.js';
|
|
3
|
+
import { PupsFeed, type FeedLink, type FeedOptions } from './feed.js';
|
|
4
|
+
import { HostMetaEditor } from './host-meta.js';
|
|
5
|
+
import { type Scope } from './scopes.js';
|
|
6
|
+
import type { SessionRecord, TokenStore } from './store/token-store.js';
|
|
7
|
+
import type { TabChannel } from './tabs.js';
|
|
8
|
+
import { TokenManager } from './tokens.js';
|
|
9
|
+
/** A JSON value that the library serializes with `JSON.stringify`, allowed only for `.json` paths. */
|
|
10
|
+
export type JsonBody = object | number | boolean | null;
|
|
11
|
+
/**
|
|
12
|
+
* A file body. Strings are sent as UTF-8; objects, arrays, numbers, booleans and `null` as JSON (`.json` only);
|
|
13
|
+
* `Blob`, `ArrayBuffer` and typed arrays as they are. Streams are not accepted, because a body must be replayable:
|
|
14
|
+
* the library repeats a request once after renewing an expired token.
|
|
15
|
+
*/
|
|
16
|
+
export type Body = string | Blob | ArrayBuffer | ArrayBufferView | JsonBody;
|
|
17
|
+
export interface WriteOptions {
|
|
18
|
+
/**
|
|
19
|
+
* The `Content-Type` to upload with. It must be accepted for the file's extension, e.g. `application/feed+json`
|
|
20
|
+
* for `.json`. Default: the type the extension is served as.
|
|
21
|
+
*/
|
|
22
|
+
contentType?: string;
|
|
23
|
+
signal?: AbortSignal;
|
|
24
|
+
}
|
|
25
|
+
export interface WriteResult {
|
|
26
|
+
/** The absolute, normalized path. */
|
|
27
|
+
path: string;
|
|
28
|
+
/** The new ETag, for a later `replace()` or `delete()`. */
|
|
29
|
+
etag: string;
|
|
30
|
+
/** The public URL readers use. */
|
|
31
|
+
url: string;
|
|
32
|
+
/** Whether the file was created (`201`) rather than replaced (`200`). */
|
|
33
|
+
created: boolean;
|
|
34
|
+
}
|
|
35
|
+
/** A file read from `storage_base`. */
|
|
36
|
+
export interface StoredFile {
|
|
37
|
+
path: string;
|
|
38
|
+
/** The ETag to pass to `replace()`; empty if the server doesn't expose it. */
|
|
39
|
+
etag: string;
|
|
40
|
+
contentType: string;
|
|
41
|
+
size: number;
|
|
42
|
+
lastModified?: Date;
|
|
43
|
+
blob(): Promise<Blob>;
|
|
44
|
+
/** The content decoded as UTF-8. */
|
|
45
|
+
text(): Promise<string>;
|
|
46
|
+
json<T = unknown>(): Promise<T>;
|
|
47
|
+
}
|
|
48
|
+
export type SessionChangeEvent = {
|
|
49
|
+
type: 'login';
|
|
50
|
+
me: string;
|
|
51
|
+
} | {
|
|
52
|
+
type: 'logout';
|
|
53
|
+
me: string;
|
|
54
|
+
}
|
|
55
|
+
/** The session ended without logout: the grant was revoked, or the refresh token expired. */
|
|
56
|
+
| {
|
|
57
|
+
type: 'expired';
|
|
58
|
+
me: string;
|
|
59
|
+
error: PupsError;
|
|
60
|
+
};
|
|
61
|
+
/** @internal */
|
|
62
|
+
export interface SessionContext {
|
|
63
|
+
fetch: typeof fetch;
|
|
64
|
+
store: TokenStore;
|
|
65
|
+
channel: TabChannel;
|
|
66
|
+
ended(session: PupsSession, event: SessionChangeEvent): void;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* A connection to one owner's PUPS server, with the granted scopes. Get one from `PupsClient.init()`, `login()`,
|
|
70
|
+
* `loginWithPopup()` or `restore()`; don't construct it yourself.
|
|
71
|
+
*
|
|
72
|
+
* Paths: a path starting with `/` is absolute, relative to `storage_base`. Any other path is relative to the app's
|
|
73
|
+
* own directory: `put('comments.json', …)` writes `/appdata/<client-host>/comments.json`.
|
|
74
|
+
*/
|
|
75
|
+
export declare class PupsSession {
|
|
76
|
+
#private;
|
|
77
|
+
/** The verified identity of the owner, `https://<host>/`. Key accounts on this. */
|
|
78
|
+
readonly me: string;
|
|
79
|
+
/** The `client_id` of the app. */
|
|
80
|
+
readonly clientId: string;
|
|
81
|
+
/** The host of the `client_id`. */
|
|
82
|
+
readonly clientHost: string;
|
|
83
|
+
/** The app's own directory, `/appdata/<client-host>/`. */
|
|
84
|
+
readonly appDataPath: string;
|
|
85
|
+
/** Edits `host-meta.json` through the server's host-meta endpoint. */
|
|
86
|
+
readonly hostMeta: HostMetaEditor;
|
|
87
|
+
/** @internal */
|
|
88
|
+
readonly _tokens: TokenManager;
|
|
89
|
+
/** @internal */
|
|
90
|
+
constructor(record: SessionRecord, persistent: boolean, ctx: SessionContext);
|
|
91
|
+
/** The server configuration, pinned at login. */
|
|
92
|
+
get server(): PupsServer;
|
|
93
|
+
/** The issuer of the server. */
|
|
94
|
+
get issuer(): string;
|
|
95
|
+
/** The granted scopes. The owner may have granted fewer than requested. */
|
|
96
|
+
get scopes(): readonly string[];
|
|
97
|
+
/** Whether the session survives a reload (stored), or lives only in this tab's memory. */
|
|
98
|
+
get persistent(): boolean;
|
|
99
|
+
/** False after logout, expiry, or logout in another tab. */
|
|
100
|
+
get active(): boolean;
|
|
101
|
+
/** Whether a scope was granted. A `write:` directory scope also counts as granted if a parent directory was granted. */
|
|
102
|
+
hasScope(scope: Scope): boolean;
|
|
103
|
+
/** Whether the granted scopes allow writing `path` (relative paths are in the app's own directory). */
|
|
104
|
+
canWrite(path: string): boolean;
|
|
105
|
+
/** The absolute path for `path`: unchanged if it starts with `/`, otherwise inside the app's own directory. */
|
|
106
|
+
resolve(path: string): string;
|
|
107
|
+
/** The public URL of `path`, as readers see it. Use it whenever you link to a file, e.g. as a webmention source. */
|
|
108
|
+
publicUrl(path: string): string;
|
|
109
|
+
/** The URL of `path` below `storage_base`, where it is written and where its ETag is valid. */
|
|
110
|
+
storageUrl(path: string): string;
|
|
111
|
+
/**
|
|
112
|
+
* Reads a file from `storage_base`, without a token (everything stored is public). Use the ETag of the result
|
|
113
|
+
* for `replace()`; ETags from `public_base` may come from a CDN.
|
|
114
|
+
* @returns undefined if the file doesn't exist.
|
|
115
|
+
*/
|
|
116
|
+
get(path: string, options?: {
|
|
117
|
+
signal?: AbortSignal;
|
|
118
|
+
}): Promise<StoredFile | undefined>;
|
|
119
|
+
/**
|
|
120
|
+
* Writes a file unconditionally: the last write wins, and changes others made in between are lost.
|
|
121
|
+
* Prefer `update()` for files the owner or other apps may change, and `create()` for new files.
|
|
122
|
+
*/
|
|
123
|
+
put(path: string, body: Body, options?: WriteOptions): Promise<WriteResult>;
|
|
124
|
+
/**
|
|
125
|
+
* Creates a file that must not exist yet (`If-None-Match: *`).
|
|
126
|
+
* @throws {PupsError} `precondition_failed` if the file exists.
|
|
127
|
+
*/
|
|
128
|
+
create(path: string, body: Body, options?: WriteOptions): Promise<WriteResult>;
|
|
129
|
+
/**
|
|
130
|
+
* Replaces a file only if it is unchanged since `etag` was read (`If-Match`).
|
|
131
|
+
* @throws {PupsError} `precondition_failed` if the file changed or was deleted.
|
|
132
|
+
*/
|
|
133
|
+
replace(path: string, body: Body, etag: string, options?: WriteOptions): Promise<WriteResult>;
|
|
134
|
+
/**
|
|
135
|
+
* Changes a file safely when others may change it too (RFC-6 "Concurrency"): reads it, passes it to `change`,
|
|
136
|
+
* and writes the result with `If-Match` (or `If-None-Match: *` if there was no file). If someone else wrote in
|
|
137
|
+
* between, it starts again, up to `maxAttempts` times (default 5).
|
|
138
|
+
*
|
|
139
|
+
* `change` gets the current file, or undefined if there is none, and returns the new body, or `undefined` to
|
|
140
|
+
* leave the file as it is. It may run more than once, so it must not have side effects.
|
|
141
|
+
* @returns undefined if `change` returned undefined.
|
|
142
|
+
*/
|
|
143
|
+
update(path: string, change: (current: StoredFile | undefined) => Body | undefined | Promise<Body | undefined>, options?: WriteOptions & {
|
|
144
|
+
maxAttempts?: number;
|
|
145
|
+
}): Promise<WriteResult | undefined>;
|
|
146
|
+
/**
|
|
147
|
+
* Deletes a file, if `ifMatch` is given only if it is unchanged since that ETag.
|
|
148
|
+
* @throws {PupsError} `not_found` if the file doesn't exist; `precondition_failed` if it changed.
|
|
149
|
+
*/
|
|
150
|
+
delete(path: string, options?: {
|
|
151
|
+
ifMatch?: string;
|
|
152
|
+
signal?: AbortSignal;
|
|
153
|
+
}): Promise<void>;
|
|
154
|
+
/**
|
|
155
|
+
* A feed on the owner's domain, maintained according to RFC-7: the main feed `/feed.json` without a name, or the
|
|
156
|
+
* named feed `/feed/<name>.json`. The session needs the feed's scopes, see `feedScopes()`.
|
|
157
|
+
* @throws {PupsError} `invalid_request` for an invalid name.
|
|
158
|
+
*/
|
|
159
|
+
feed(name?: string, options?: FeedOptions): PupsFeed;
|
|
160
|
+
/** The feeds registered in the owner's `host-meta.json`, e.g. to let the owner choose one to post to. */
|
|
161
|
+
listFeeds(options?: {
|
|
162
|
+
signal?: AbortSignal;
|
|
163
|
+
} & FeedOptions): Promise<FeedLink[]>;
|
|
164
|
+
/**
|
|
165
|
+
* Fetches the configuration document again, e.g. after the owner changed allowed paths. Accepted only if the
|
|
166
|
+
* issuer is unchanged; a different issuer means the user has to connect again.
|
|
167
|
+
* @throws {PupsError} `issuer_mismatch`
|
|
168
|
+
*/
|
|
169
|
+
refreshServer(options?: {
|
|
170
|
+
signal?: AbortSignal;
|
|
171
|
+
}): Promise<PupsServer>;
|
|
172
|
+
/**
|
|
173
|
+
* Disconnects: deletes the credentials in this browser first, so a failing network never leaves the user
|
|
174
|
+
* logged in, then (with `revoke`, the default) revokes the tokens at the server, ending the grant.
|
|
175
|
+
*
|
|
176
|
+
* `revoke: false` only forgets the credentials here; the owner still sees the app as connected.
|
|
177
|
+
* Logout doesn't delete files the app wrote, and doesn't end the app's own login session.
|
|
178
|
+
* @returns whether the server confirmed the revocation. Revocation is best-effort and never throws.
|
|
179
|
+
*/
|
|
180
|
+
logout(options?: {
|
|
181
|
+
revoke?: boolean;
|
|
182
|
+
}): Promise<{
|
|
183
|
+
revoked: boolean;
|
|
184
|
+
}>;
|
|
185
|
+
/**
|
|
186
|
+
* Sends an authenticated request. Renews the token and repeats the request once if the server answers `401`.
|
|
187
|
+
* The token is sent only to the server's write endpoints.
|
|
188
|
+
* @internal
|
|
189
|
+
*/
|
|
190
|
+
_authorized(url: string, init: RequestInit & {
|
|
191
|
+
headers?: Record<string, string>;
|
|
192
|
+
}, signal?: AbortSignal): Promise<Response>;
|
|
193
|
+
}
|
|
194
|
+
//# sourceMappingURL=session.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session.d.ts","sourceRoot":"","sources":["../src/session.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,KAAK,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAC1D,OAAO,EAAkC,SAAS,EAAE,MAAM,aAAa,CAAA;AACvE,OAAO,EAAa,QAAQ,EAAE,KAAK,QAAQ,EAAE,KAAK,WAAW,EAAE,MAAM,WAAW,CAAA;AAEhF,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAG/C,OAAO,EAA+F,KAAK,KAAK,EAAE,MAAM,aAAa,CAAA;AACrI,OAAO,KAAK,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAA;AACvE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,WAAW,CAAA;AAC3C,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAM1C,sGAAsG;AACtG,MAAM,MAAM,QAAQ,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,CAAA;AAEvD;;;;GAIG;AACH,MAAM,MAAM,IAAI,GAAG,MAAM,GAAG,IAAI,GAAG,WAAW,GAAG,eAAe,GAAG,QAAQ,CAAA;AAE3E,MAAM,WAAW,YAAY;IAC3B;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,MAAM,CAAC,EAAE,WAAW,CAAA;CACrB;AAED,MAAM,WAAW,WAAW;IAC1B,qCAAqC;IACrC,IAAI,EAAE,MAAM,CAAA;IACZ,2DAA2D;IAC3D,IAAI,EAAE,MAAM,CAAA;IACZ,kCAAkC;IAClC,GAAG,EAAE,MAAM,CAAA;IACX,yEAAyE;IACzE,OAAO,EAA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