@vol-a/client 0.0.0-stage → 1.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 +284 -2
- package/dist/access-tokens.d.ts +21 -0
- package/dist/access-tokens.d.ts.map +1 -0
- package/dist/access-tokens.js +34 -0
- package/dist/access-tokens.js.map +1 -0
- package/dist/body.d.ts +40 -0
- package/dist/body.d.ts.map +1 -0
- package/dist/body.js +112 -0
- package/dist/body.js.map +1 -0
- package/dist/client.d.ts +185 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +311 -0
- package/dist/client.js.map +1 -0
- package/dist/env.d.ts +19 -0
- package/dist/env.d.ts.map +1 -0
- package/dist/env.js +52 -0
- package/dist/env.js.map +1 -0
- package/dist/errors.d.ts +43 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +93 -0
- package/dist/errors.js.map +1 -0
- package/dist/files.d.ts +144 -0
- package/dist/files.d.ts.map +1 -0
- package/dist/files.js +239 -0
- package/dist/files.js.map +1 -0
- package/dist/folders.d.ts +35 -0
- package/dist/folders.d.ts.map +1 -0
- package/dist/folders.js +62 -0
- package/dist/folders.js.map +1 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +12 -0
- package/dist/index.js.map +1 -0
- package/dist/keyrings.d.ts +44 -0
- package/dist/keyrings.d.ts.map +1 -0
- package/dist/keyrings.js +111 -0
- package/dist/keyrings.js.map +1 -0
- package/dist/management.d.ts +47 -0
- package/dist/management.d.ts.map +1 -0
- package/dist/management.js +65 -0
- package/dist/management.js.map +1 -0
- package/dist/shares.d.ts +87 -0
- package/dist/shares.d.ts.map +1 -0
- package/dist/shares.js +144 -0
- package/dist/shares.js.map +1 -0
- package/dist/uploads.d.ts +112 -0
- package/dist/uploads.d.ts.map +1 -0
- package/dist/uploads.js +290 -0
- package/dist/uploads.js.map +1 -0
- package/package.json +48 -3
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
import { UdcClient } from "@jsudc/core/client";
|
|
2
|
+
import { type InstanceTypesResponse, type LiveResponse, type LookupLocale, type LookupsResponse, type ReadyResponse } from "@vol-a/core";
|
|
3
|
+
import { AccessTokensApi } from "./access-tokens.js";
|
|
4
|
+
import { FilesApi } from "./files.js";
|
|
5
|
+
import { FoldersApi } from "./folders.js";
|
|
6
|
+
import { KeyringsApi } from "./keyrings.js";
|
|
7
|
+
import { AdminApi, KeysApi, StatsApi } from "./management.js";
|
|
8
|
+
import { type OpenShareOptions, SharesApi } from "./shares.js";
|
|
9
|
+
import { UploadsApi } from "./uploads.js";
|
|
10
|
+
/** The `caller` content key: 32 bytes, or their base64. Node only (see `VolaClientOptions`). */
|
|
11
|
+
export type ContentKey = string | Uint8Array;
|
|
12
|
+
export interface VolaClientOptions {
|
|
13
|
+
/** API base URL including the mount prefix, e.g. `https://files.example.com/vola`. */
|
|
14
|
+
baseUrl: string;
|
|
15
|
+
/** API key, sent as `Authorization: Bearer …`. Optional only for the public routes (`health`, `lookups`, `/s/…`, `/public/…`). */
|
|
16
|
+
apiKey?: string | undefined;
|
|
17
|
+
/**
|
|
18
|
+
* An ACCESS TOKEN (`vola_at_…`, 1.2) instead of an API key — what a browser holds: issued
|
|
19
|
+
* by the host's backend (`accessTokens.create`) for the rows its user may read. It reads
|
|
20
|
+
* `files.download` / `files.thumb` of those rows and nothing else (every other route is
|
|
21
|
+
* `401`). Give `apiKey` OR a token (`accessToken` and/or `getAccessToken`), never both.
|
|
22
|
+
*/
|
|
23
|
+
accessToken?: string | undefined;
|
|
24
|
+
/**
|
|
25
|
+
* Called for a fresh token when the server answers `401` to a request made with a token
|
|
26
|
+
* (it expired, or was revoked), and before the first request when no `accessToken` was
|
|
27
|
+
* given; the request is then sent ONCE more. Concurrent `401`s share one call.
|
|
28
|
+
*/
|
|
29
|
+
getAccessToken?: (() => string | Promise<string>) | undefined;
|
|
30
|
+
/** `fetch` to use; default: the global one. Tests inject a fake; a host may inject one with retries or a proxy. */
|
|
31
|
+
fetch?: typeof fetch | undefined;
|
|
32
|
+
/** `X-User-Id`: the principal of the host application — attribution, and the owner of a keyring. */
|
|
33
|
+
userId?: string | undefined;
|
|
34
|
+
/** `X-Tenant-Slug`: the tenant an ADMIN key acts on (a tenant key already has one). */
|
|
35
|
+
tenantSlug?: string | undefined;
|
|
36
|
+
/** Validate every JSON answer against its `@vol-a/core` schema (`invalid_response` on a mismatch). Default `false`: the types are trusted. */
|
|
37
|
+
validate?: boolean | undefined;
|
|
38
|
+
/** An unlock token to start with (`withUnlock` sets it). Held in memory only. */
|
|
39
|
+
unlock?: string | undefined;
|
|
40
|
+
/** Extra headers on every request (a correlation id, a proxy token). */
|
|
41
|
+
headers?: Record<string, string> | undefined;
|
|
42
|
+
}
|
|
43
|
+
/** Options every call accepts. */
|
|
44
|
+
export interface CallOptions {
|
|
45
|
+
signal?: AbortSignal | undefined;
|
|
46
|
+
/** `X-Vola-Unlock` for this call only; default: the token the instance holds. */
|
|
47
|
+
unlock?: string | undefined;
|
|
48
|
+
/**
|
|
49
|
+
* `X-Vola-Content-Key`, the `caller` encryption key (32 bytes or their base64). Refused in a
|
|
50
|
+
* browser: the server rejects any request with an `Origin`, and the key would sit in the page.
|
|
51
|
+
*/
|
|
52
|
+
contentKey?: ContentKey | undefined;
|
|
53
|
+
}
|
|
54
|
+
export type QueryValue = string | number | boolean | null | undefined;
|
|
55
|
+
/** What `VolaClient.request` takes: the escape hatch every group is built on. */
|
|
56
|
+
export interface RequestOptions extends CallOptions {
|
|
57
|
+
method?: string | undefined;
|
|
58
|
+
/** Query parameters; `undefined`/`null`/`false` are dropped, `true` is sent as `1` (the server's flag form). */
|
|
59
|
+
query?: Record<string, QueryValue> | undefined;
|
|
60
|
+
headers?: Record<string, string | undefined> | undefined;
|
|
61
|
+
body?: BodyInit | null | undefined;
|
|
62
|
+
/** A JSON body (`content-type: application/json`). */
|
|
63
|
+
json?: unknown;
|
|
64
|
+
/** Which statuses are an answer, not an error. Default: `2xx`. */
|
|
65
|
+
ok?: ((status: number) => boolean) | undefined;
|
|
66
|
+
/** No API key on this request (the public routes). */
|
|
67
|
+
anonymous?: boolean | undefined;
|
|
68
|
+
/** The body is a stream (`duplex: "half"` is needed). */
|
|
69
|
+
streaming?: boolean | undefined;
|
|
70
|
+
/** Validate the answer against its schema for this call (default: the instance setting). */
|
|
71
|
+
validate?: boolean | undefined;
|
|
72
|
+
}
|
|
73
|
+
export interface LockOnUnloadOptions {
|
|
74
|
+
/** The event the beacon goes on. Default `pagehide` (fires on every navigation and tab close, `beforeunload` does not on mobile). */
|
|
75
|
+
event?: "pagehide" | "beforeunload" | "visibilitychange" | undefined;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* What `json()` needs of a schema: the `safeParse` of a `@vol-a/core` Zod schema. Declared
|
|
79
|
+
* structurally so the SDK depends on `@vol-a/core` alone (Zod comes with it).
|
|
80
|
+
*/
|
|
81
|
+
export interface ResponseSchema<T> {
|
|
82
|
+
safeParse(data: unknown): {
|
|
83
|
+
success: true;
|
|
84
|
+
data: T;
|
|
85
|
+
} | {
|
|
86
|
+
success: false;
|
|
87
|
+
error: {
|
|
88
|
+
issues: readonly {
|
|
89
|
+
path: PropertyKey[];
|
|
90
|
+
message: string;
|
|
91
|
+
}[];
|
|
92
|
+
};
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
/** `true` for a `2xx`. */
|
|
96
|
+
export declare const ok2xx: (status: number) => boolean;
|
|
97
|
+
/**
|
|
98
|
+
* The SDK: one instance per API key (and per principal) — or per ACCESS TOKEN, in a browser
|
|
99
|
+
* that reads the rows its host granted. Groups mirror the routes — `files`, `folders`,
|
|
100
|
+
* `uploads`, `shares`, `keyrings`, `stats`, `keys`, `accessTokens`, `admin`, `udc` —
|
|
101
|
+
* and `request()` / `json()` are the escape hatch they are built on.
|
|
102
|
+
*
|
|
103
|
+
* Secrets: the API key, the unlock token, the content key, a share secret and a PIN travel
|
|
104
|
+
* in headers or bodies only — never in a URL, never in an error message, never logged.
|
|
105
|
+
*/
|
|
106
|
+
export declare class VolaClient {
|
|
107
|
+
readonly baseUrl: string;
|
|
108
|
+
readonly files: FilesApi;
|
|
109
|
+
readonly folders: FoldersApi;
|
|
110
|
+
readonly uploads: UploadsApi;
|
|
111
|
+
readonly shares: SharesApi;
|
|
112
|
+
readonly keyrings: KeyringsApi;
|
|
113
|
+
readonly stats: StatsApi;
|
|
114
|
+
readonly keys: KeysApi;
|
|
115
|
+
readonly admin: AdminApi;
|
|
116
|
+
readonly accessTokens: AccessTokensApi;
|
|
117
|
+
/** The options the instance was made with (neither the unlock token nor the access token is in here). */
|
|
118
|
+
readonly options: Readonly<Omit<VolaClientOptions, "unlock" | "accessToken">>;
|
|
119
|
+
private readonly fetchImpl;
|
|
120
|
+
private readonly validate;
|
|
121
|
+
private unlockToken;
|
|
122
|
+
private udcClient;
|
|
123
|
+
private token;
|
|
124
|
+
private refreshing;
|
|
125
|
+
constructor(options: VolaClientOptions);
|
|
126
|
+
/** The access token the instance sends (`null`: none yet, or an API-key client). */
|
|
127
|
+
get accessToken(): string | null;
|
|
128
|
+
/** Replaces the access token the instance sends (a host that refreshes on its own schedule). */
|
|
129
|
+
setAccessToken(token: string | null): void;
|
|
130
|
+
/** `getAccessToken()` once for every caller waiting at the same time. */
|
|
131
|
+
private refreshAccessToken;
|
|
132
|
+
/** A client with the same options that sends `token` as `X-Vola-Unlock` (this instance is unchanged). */
|
|
133
|
+
withUnlock(token: string): VolaClient;
|
|
134
|
+
/** `true` while the instance holds an unlock token (it may still have expired on the server). */
|
|
135
|
+
get unlocked(): boolean;
|
|
136
|
+
/** Sets (or clears, with `null`) the unlock token the instance sends. `keyrings.unlock()` calls it. */
|
|
137
|
+
setUnlock(token: string | null): void;
|
|
138
|
+
/** Ends the unlock on the server (`DELETE /keyrings/me/unlock`) and forgets the token. Idempotent. */
|
|
139
|
+
lock(): Promise<void>;
|
|
140
|
+
/**
|
|
141
|
+
* Browser only: on `pagehide` (default) a `navigator.sendBeacon` to `/keyrings/me/unlock/close`
|
|
142
|
+
* ends the unlock the instance holds, so a closed tab leaves no live token behind. The token
|
|
143
|
+
* goes in the beacon's body (`text/plain`), never in the URL. Returns the function that
|
|
144
|
+
* removes the listener. A no-op outside a browser.
|
|
145
|
+
*/
|
|
146
|
+
lockOnUnload(options?: LockOnUnloadOptions): () => void;
|
|
147
|
+
/** `baseUrl + path + ?query`. `path` starts with `/` and is already encoded. */
|
|
148
|
+
url(path: string, query?: Record<string, QueryValue>): string;
|
|
149
|
+
/** The headers of a request: auth, principal, tenant, unlock, content key, extras, then `options.headers`. */
|
|
150
|
+
headers(options?: RequestOptions): Headers;
|
|
151
|
+
/**
|
|
152
|
+
* One request to `path` (already encoded, starting with `/`). Resolves with the `Response`
|
|
153
|
+
* for every status `options.ok` accepts (default `2xx`) and throws the `VolaError` of any
|
|
154
|
+
* other. Transport failures (no network, a refused connection) throw what `fetch` throws.
|
|
155
|
+
*/
|
|
156
|
+
request(path: string, options?: RequestOptions): Promise<Response>;
|
|
157
|
+
/** `request()` for a JSON answer, typed by (and, with `validate`, checked against) its `@vol-a/core` schema. */
|
|
158
|
+
json<T>(path: string, schema: ResponseSchema<T>, options?: RequestOptions): Promise<T>;
|
|
159
|
+
/** The `fetch` this instance was given (or the global one), without any header of its own: for the anonymous routes. */
|
|
160
|
+
get rawFetch(): typeof fetch;
|
|
161
|
+
/** Internal: `fetch` with this instance's headers merged in (what `udc` uses). */
|
|
162
|
+
fetchWithAuth(input: RequestInfo | URL, init?: RequestInit): Promise<Response>;
|
|
163
|
+
/** `GET /health/live`. No key needed (one is sent when the instance has it). */
|
|
164
|
+
live(): Promise<LiveResponse>;
|
|
165
|
+
/** `GET /health/ready`; a `503` resolves too (`status: "fail"`) — it is a valid answer. */
|
|
166
|
+
ready(): Promise<ReadyResponse>;
|
|
167
|
+
/** `GET /lookups[?locale=]`: the vocabulary of `lookups.yaml`, labelled in `locale`. No key needed. */
|
|
168
|
+
lookups(locale?: LookupLocale | string): Promise<LookupsResponse>;
|
|
169
|
+
/** `GET /instance-types`: the tenant's instance types with live files, with their counts. */
|
|
170
|
+
instanceTypes(options?: CallOptions): Promise<InstanceTypesResponse>;
|
|
171
|
+
/**
|
|
172
|
+
* The UDC collections of the server (`POST /udc/<action>`) through `@jsudc/core`'s
|
|
173
|
+
* `UdcClient`, with this instance's auth (key, principal, tenant, unlock token) on every call.
|
|
174
|
+
*/
|
|
175
|
+
get udc(): UdcClient;
|
|
176
|
+
/**
|
|
177
|
+
* Follows a share link (`…/s/<token>[#<secret>]`) anonymously: the fragment, when there is
|
|
178
|
+
* one, goes as `X-Share-Secret`; a password as `X-Share-Password`; `range` as `Range`. The
|
|
179
|
+
* `Response` streams the file (a folder share answers its JSON listing). Throws the
|
|
180
|
+
* `VolaError` of a refusal (`410 share_gone`, `401 share_password_required`, `401
|
|
181
|
+
* share_secret_required`, `409 vola_integrity`…).
|
|
182
|
+
*/
|
|
183
|
+
static openShare(url: string, options?: OpenShareOptions): Promise<Response>;
|
|
184
|
+
}
|
|
185
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC/C,OAAO,EAIL,KAAK,qBAAqB,EAE1B,KAAK,YAAY,EAGjB,KAAK,YAAY,EACjB,KAAK,eAAe,EAEpB,KAAK,aAAa,EAKnB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAGrD,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,E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MAAM,CAAC,SAAS,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,GAAE,gBAAqB,GAAG,OAAO,CAAC,QAAQ,CAAC;CAOjF"}
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,311 @@
|
|
|
1
|
+
import { UdcClient } from "@jsudc/core/client";
|
|
2
|
+
import { CALLER_KEY_FROM_BROWSER_CODE, CONTENT_KEY_BYTES, CONTENT_KEY_HEADER, InstanceTypesResponseSchema, LiveResponseSchema, LOCALE_QUERY, LookupsResponseSchema, ReadyResponseSchema, TENANT_SLUG_HEADER, UNLOCK_HEADER, USER_ID_HEADER, } from "@vol-a/core";
|
|
3
|
+
import { AccessTokensApi } from "./access-tokens.js";
|
|
4
|
+
import { bytesToBase64, isBrowser } from "./env.js";
|
|
5
|
+
import { errorFromResponse, VolaError } from "./errors.js";
|
|
6
|
+
import { FilesApi } from "./files.js";
|
|
7
|
+
import { FoldersApi } from "./folders.js";
|
|
8
|
+
import { KeyringsApi } from "./keyrings.js";
|
|
9
|
+
import { AdminApi, KeysApi, StatsApi } from "./management.js";
|
|
10
|
+
import { openShareUrl, SharesApi } from "./shares.js";
|
|
11
|
+
import { UploadsApi } from "./uploads.js";
|
|
12
|
+
/** `GET|HEAD /files/:type/:id/:fileId[/thumb/:size]`: the only routes an access token reads. */
|
|
13
|
+
const TOKEN_ROUTE = /^\/files\/[^/]+\/[^/]+\/[^/]+(\/thumb\/[^/]+)?$/;
|
|
14
|
+
const tokenReadable = (method, path) => (method === "GET" || method === "HEAD") && TOKEN_ROUTE.test(path.split("?")[0] ?? path);
|
|
15
|
+
/** `true` for a body that can be sent only once. */
|
|
16
|
+
const isStream = (body) => typeof ReadableStream !== "undefined" && body instanceof ReadableStream;
|
|
17
|
+
/** `true` for a `2xx`. */
|
|
18
|
+
export const ok2xx = (status) => status >= 200 && status < 300;
|
|
19
|
+
function contentKeyHeader(key) {
|
|
20
|
+
if (typeof key === "string")
|
|
21
|
+
return key;
|
|
22
|
+
if (key.byteLength !== CONTENT_KEY_BYTES) {
|
|
23
|
+
throw new VolaError({
|
|
24
|
+
status: 0,
|
|
25
|
+
code: "bad_request",
|
|
26
|
+
message: `contentKey: ${CONTENT_KEY_BYTES} bytes are required (got ${key.byteLength})`,
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
return bytesToBase64(key);
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* The SDK: one instance per API key (and per principal) — or per ACCESS TOKEN, in a browser
|
|
33
|
+
* that reads the rows its host granted. Groups mirror the routes — `files`, `folders`,
|
|
34
|
+
* `uploads`, `shares`, `keyrings`, `stats`, `keys`, `accessTokens`, `admin`, `udc` —
|
|
35
|
+
* and `request()` / `json()` are the escape hatch they are built on.
|
|
36
|
+
*
|
|
37
|
+
* Secrets: the API key, the unlock token, the content key, a share secret and a PIN travel
|
|
38
|
+
* in headers or bodies only — never in a URL, never in an error message, never logged.
|
|
39
|
+
*/
|
|
40
|
+
export class VolaClient {
|
|
41
|
+
baseUrl;
|
|
42
|
+
files;
|
|
43
|
+
folders;
|
|
44
|
+
uploads;
|
|
45
|
+
shares;
|
|
46
|
+
keyrings;
|
|
47
|
+
stats;
|
|
48
|
+
keys;
|
|
49
|
+
admin;
|
|
50
|
+
accessTokens;
|
|
51
|
+
/** The options the instance was made with (neither the unlock token nor the access token is in here). */
|
|
52
|
+
options;
|
|
53
|
+
fetchImpl;
|
|
54
|
+
validate;
|
|
55
|
+
unlockToken;
|
|
56
|
+
udcClient;
|
|
57
|
+
token;
|
|
58
|
+
refreshing = null;
|
|
59
|
+
constructor(options) {
|
|
60
|
+
const { unlock, accessToken, ...rest } = options;
|
|
61
|
+
if (options.apiKey && (accessToken || options.getAccessToken)) {
|
|
62
|
+
throw new VolaError({
|
|
63
|
+
status: 0,
|
|
64
|
+
code: "bad_request",
|
|
65
|
+
message: "VolaClient: give apiKey or an access token (accessToken / getAccessToken), not both",
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
this.token = accessToken ?? null;
|
|
69
|
+
this.options = Object.freeze({ ...rest });
|
|
70
|
+
this.baseUrl = options.baseUrl.replace(/\/+$/, "");
|
|
71
|
+
this.fetchImpl = options.fetch ?? ((input, init) => globalThis.fetch(input, init));
|
|
72
|
+
this.validate = options.validate ?? false;
|
|
73
|
+
this.unlockToken = unlock ?? null;
|
|
74
|
+
this.files = new FilesApi(this);
|
|
75
|
+
this.folders = new FoldersApi(this);
|
|
76
|
+
this.uploads = new UploadsApi(this);
|
|
77
|
+
this.shares = new SharesApi(this);
|
|
78
|
+
this.keyrings = new KeyringsApi(this);
|
|
79
|
+
this.stats = new StatsApi(this);
|
|
80
|
+
this.keys = new KeysApi(this);
|
|
81
|
+
this.admin = new AdminApi(this);
|
|
82
|
+
this.accessTokens = new AccessTokensApi(this);
|
|
83
|
+
}
|
|
84
|
+
// --- access token state -----------------------------------------------------------------------
|
|
85
|
+
/** The access token the instance sends (`null`: none yet, or an API-key client). */
|
|
86
|
+
get accessToken() {
|
|
87
|
+
return this.token;
|
|
88
|
+
}
|
|
89
|
+
/** Replaces the access token the instance sends (a host that refreshes on its own schedule). */
|
|
90
|
+
setAccessToken(token) {
|
|
91
|
+
this.token = token;
|
|
92
|
+
}
|
|
93
|
+
/** `getAccessToken()` once for every caller waiting at the same time. */
|
|
94
|
+
refreshAccessToken() {
|
|
95
|
+
const get = this.options.getAccessToken;
|
|
96
|
+
if (!get)
|
|
97
|
+
return Promise.reject(new Error("no getAccessToken"));
|
|
98
|
+
this.refreshing ??= (async () => {
|
|
99
|
+
try {
|
|
100
|
+
const token = await get();
|
|
101
|
+
this.token = token;
|
|
102
|
+
return token;
|
|
103
|
+
}
|
|
104
|
+
finally {
|
|
105
|
+
this.refreshing = null;
|
|
106
|
+
}
|
|
107
|
+
})();
|
|
108
|
+
return this.refreshing;
|
|
109
|
+
}
|
|
110
|
+
// --- unlock state -------------------------------------------------------------------------
|
|
111
|
+
/** A client with the same options that sends `token` as `X-Vola-Unlock` (this instance is unchanged). */
|
|
112
|
+
withUnlock(token) {
|
|
113
|
+
return new VolaClient({
|
|
114
|
+
...this.options,
|
|
115
|
+
...(this.token ? { accessToken: this.token } : {}),
|
|
116
|
+
unlock: token,
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
/** `true` while the instance holds an unlock token (it may still have expired on the server). */
|
|
120
|
+
get unlocked() {
|
|
121
|
+
return this.unlockToken !== null;
|
|
122
|
+
}
|
|
123
|
+
/** Sets (or clears, with `null`) the unlock token the instance sends. `keyrings.unlock()` calls it. */
|
|
124
|
+
setUnlock(token) {
|
|
125
|
+
this.unlockToken = token;
|
|
126
|
+
}
|
|
127
|
+
/** Ends the unlock on the server (`DELETE /keyrings/me/unlock`) and forgets the token. Idempotent. */
|
|
128
|
+
lock() {
|
|
129
|
+
return this.keyrings.lock();
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Browser only: on `pagehide` (default) a `navigator.sendBeacon` to `/keyrings/me/unlock/close`
|
|
133
|
+
* ends the unlock the instance holds, so a closed tab leaves no live token behind. The token
|
|
134
|
+
* goes in the beacon's body (`text/plain`), never in the URL. Returns the function that
|
|
135
|
+
* removes the listener. A no-op outside a browser.
|
|
136
|
+
*/
|
|
137
|
+
lockOnUnload(options = {}) {
|
|
138
|
+
if (!isBrowser() || typeof navigator === "undefined" || !navigator.sendBeacon) {
|
|
139
|
+
return () => undefined;
|
|
140
|
+
}
|
|
141
|
+
const event = options.event ?? "pagehide";
|
|
142
|
+
const handler = () => {
|
|
143
|
+
if (event === "visibilitychange" && document.visibilityState !== "hidden")
|
|
144
|
+
return;
|
|
145
|
+
const token = this.unlockToken;
|
|
146
|
+
if (!token)
|
|
147
|
+
return;
|
|
148
|
+
this.unlockToken = null;
|
|
149
|
+
navigator.sendBeacon(`${this.baseUrl}/keyrings/me/unlock/close`, new Blob([token], { type: "text/plain" }));
|
|
150
|
+
};
|
|
151
|
+
window.addEventListener(event, handler);
|
|
152
|
+
return () => window.removeEventListener(event, handler);
|
|
153
|
+
}
|
|
154
|
+
// --- transport ----------------------------------------------------------------------------
|
|
155
|
+
/** `baseUrl + path + ?query`. `path` starts with `/` and is already encoded. */
|
|
156
|
+
url(path, query) {
|
|
157
|
+
const params = new URLSearchParams();
|
|
158
|
+
for (const [key, value] of Object.entries(query ?? {})) {
|
|
159
|
+
if (value === undefined || value === null || value === false)
|
|
160
|
+
continue;
|
|
161
|
+
params.set(key, value === true ? "1" : String(value));
|
|
162
|
+
}
|
|
163
|
+
const qs = params.toString();
|
|
164
|
+
return `${this.baseUrl}${path}${qs ? `?${qs}` : ""}`;
|
|
165
|
+
}
|
|
166
|
+
/** The headers of a request: auth, principal, tenant, unlock, content key, extras, then `options.headers`. */
|
|
167
|
+
headers(options = {}) {
|
|
168
|
+
const headers = new Headers();
|
|
169
|
+
for (const [name, value] of Object.entries(this.options.headers ?? {}))
|
|
170
|
+
headers.set(name, value);
|
|
171
|
+
const credential = this.options.apiKey ?? this.token;
|
|
172
|
+
if (credential && !options.anonymous)
|
|
173
|
+
headers.set("authorization", `Bearer ${credential}`);
|
|
174
|
+
if (this.options.userId)
|
|
175
|
+
headers.set(USER_ID_HEADER, this.options.userId);
|
|
176
|
+
if (this.options.tenantSlug)
|
|
177
|
+
headers.set(TENANT_SLUG_HEADER, this.options.tenantSlug);
|
|
178
|
+
const unlock = options.unlock ?? this.unlockToken;
|
|
179
|
+
if (unlock)
|
|
180
|
+
headers.set(UNLOCK_HEADER, unlock);
|
|
181
|
+
if (options.contentKey !== undefined) {
|
|
182
|
+
if (isBrowser()) {
|
|
183
|
+
throw new VolaError({
|
|
184
|
+
status: 0,
|
|
185
|
+
code: CALLER_KEY_FROM_BROWSER_CODE,
|
|
186
|
+
message: "contentKey (the caller encryption key) cannot be used from a browser: the server refuses every browser request that carries one, and the key would live in the page. Use keyring encryption in the browser, or make this call from your server.",
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
headers.set(CONTENT_KEY_HEADER, contentKeyHeader(options.contentKey));
|
|
190
|
+
}
|
|
191
|
+
for (const [name, value] of Object.entries(options.headers ?? {})) {
|
|
192
|
+
if (value !== undefined)
|
|
193
|
+
headers.set(name, value);
|
|
194
|
+
}
|
|
195
|
+
return headers;
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* One request to `path` (already encoded, starting with `/`). Resolves with the `Response`
|
|
199
|
+
* for every status `options.ok` accepts (default `2xx`) and throws the `VolaError` of any
|
|
200
|
+
* other. Transport failures (no network, a refused connection) throw what `fetch` throws.
|
|
201
|
+
*/
|
|
202
|
+
async request(path, options = {}) {
|
|
203
|
+
const refreshes = Boolean(this.options.getAccessToken) && !options.anonymous;
|
|
204
|
+
if (refreshes && this.token === null)
|
|
205
|
+
await this.refreshAccessToken();
|
|
206
|
+
const send = () => {
|
|
207
|
+
const headers = this.headers(options);
|
|
208
|
+
let body = options.body ?? null;
|
|
209
|
+
if (options.json !== undefined) {
|
|
210
|
+
headers.set("content-type", "application/json");
|
|
211
|
+
body = JSON.stringify(options.json);
|
|
212
|
+
}
|
|
213
|
+
const init = {
|
|
214
|
+
method: options.method ?? "GET",
|
|
215
|
+
headers,
|
|
216
|
+
body,
|
|
217
|
+
...(options.signal ? { signal: options.signal } : {}),
|
|
218
|
+
...(options.streaming ? { duplex: "half" } : {}),
|
|
219
|
+
};
|
|
220
|
+
return this.fetchImpl(this.url(path, options.query), init);
|
|
221
|
+
};
|
|
222
|
+
let response = await send();
|
|
223
|
+
// A token that expired or was revoked: one fresh token, one more try — only on the four
|
|
224
|
+
// routes a token reads (anywhere else the 401 is the route's answer to any token).
|
|
225
|
+
if (response.status === 401 &&
|
|
226
|
+
refreshes &&
|
|
227
|
+
tokenReadable(options.method ?? "GET", path) &&
|
|
228
|
+
!options.streaming &&
|
|
229
|
+
!isStream(options.body)) {
|
|
230
|
+
await response.body?.cancel().catch(() => undefined);
|
|
231
|
+
await this.refreshAccessToken();
|
|
232
|
+
response = await send();
|
|
233
|
+
}
|
|
234
|
+
const accepted = options.ok ?? ok2xx;
|
|
235
|
+
if (!accepted(response.status))
|
|
236
|
+
throw await errorFromResponse(response);
|
|
237
|
+
return response;
|
|
238
|
+
}
|
|
239
|
+
/** `request()` for a JSON answer, typed by (and, with `validate`, checked against) its `@vol-a/core` schema. */
|
|
240
|
+
async json(path, schema, options = {}) {
|
|
241
|
+
const response = await this.request(path, {
|
|
242
|
+
...options,
|
|
243
|
+
headers: { accept: "application/json", ...options.headers },
|
|
244
|
+
});
|
|
245
|
+
const body = response.status === 204 ? undefined : await response.json();
|
|
246
|
+
if (!(options.validate ?? this.validate))
|
|
247
|
+
return body;
|
|
248
|
+
const parsed = schema.safeParse(body);
|
|
249
|
+
if (!parsed.success) {
|
|
250
|
+
const issue = parsed.error.issues[0];
|
|
251
|
+
throw new VolaError({
|
|
252
|
+
status: response.status,
|
|
253
|
+
code: "invalid_response",
|
|
254
|
+
message: `${options.method ?? "GET"} ${path}: the answer does not match its schema (${issue?.path.map(String).join(".") || "body"}: ${issue?.message ?? "invalid"})`,
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
return parsed.data;
|
|
258
|
+
}
|
|
259
|
+
/** The `fetch` this instance was given (or the global one), without any header of its own: for the anonymous routes. */
|
|
260
|
+
get rawFetch() {
|
|
261
|
+
return this.fetchImpl;
|
|
262
|
+
}
|
|
263
|
+
/** Internal: `fetch` with this instance's headers merged in (what `udc` uses). */
|
|
264
|
+
fetchWithAuth(input, init) {
|
|
265
|
+
const headers = this.headers();
|
|
266
|
+
for (const [name, value] of new Headers(init?.headers))
|
|
267
|
+
headers.set(name, value);
|
|
268
|
+
return this.fetchImpl(input, { ...init, headers });
|
|
269
|
+
}
|
|
270
|
+
// --- groups without a class of their own ----------------------------------------------------
|
|
271
|
+
/** `GET /health/live`. No key needed (one is sent when the instance has it). */
|
|
272
|
+
live() {
|
|
273
|
+
return this.json("/health/live", LiveResponseSchema);
|
|
274
|
+
}
|
|
275
|
+
/** `GET /health/ready`; a `503` resolves too (`status: "fail"`) — it is a valid answer. */
|
|
276
|
+
ready() {
|
|
277
|
+
return this.json("/health/ready", ReadyResponseSchema, {
|
|
278
|
+
ok: (status) => ok2xx(status) || status === 503,
|
|
279
|
+
});
|
|
280
|
+
}
|
|
281
|
+
/** `GET /lookups[?locale=]`: the vocabulary of `lookups.yaml`, labelled in `locale`. No key needed. */
|
|
282
|
+
lookups(locale) {
|
|
283
|
+
return this.json("/lookups", LookupsResponseSchema, { query: { [LOCALE_QUERY]: locale } });
|
|
284
|
+
}
|
|
285
|
+
/** `GET /instance-types`: the tenant's instance types with live files, with their counts. */
|
|
286
|
+
instanceTypes(options = {}) {
|
|
287
|
+
return this.json("/instance-types", InstanceTypesResponseSchema, options);
|
|
288
|
+
}
|
|
289
|
+
/**
|
|
290
|
+
* The UDC collections of the server (`POST /udc/<action>`) through `@jsudc/core`'s
|
|
291
|
+
* `UdcClient`, with this instance's auth (key, principal, tenant, unlock token) on every call.
|
|
292
|
+
*/
|
|
293
|
+
get udc() {
|
|
294
|
+
this.udcClient ??= new UdcClient({
|
|
295
|
+
httpUrl: this.baseUrl,
|
|
296
|
+
fetch: (input, init) => this.fetchWithAuth(input, init),
|
|
297
|
+
});
|
|
298
|
+
return this.udcClient;
|
|
299
|
+
}
|
|
300
|
+
/**
|
|
301
|
+
* Follows a share link (`…/s/<token>[#<secret>]`) anonymously: the fragment, when there is
|
|
302
|
+
* one, goes as `X-Share-Secret`; a password as `X-Share-Password`; `range` as `Range`. The
|
|
303
|
+
* `Response` streams the file (a folder share answers its JSON listing). Throws the
|
|
304
|
+
* `VolaError` of a refusal (`410 share_gone`, `401 share_password_required`, `401
|
|
305
|
+
* share_secret_required`, `409 vola_integrity`…).
|
|
306
|
+
*/
|
|
307
|
+
static openShare(url, options = {}) {
|
|
308
|
+
return openShareUrl(options.fetch ?? ((input, init) => globalThis.fetch(input, init)), url, options);
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1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CACjB,OAAO,CAAC,KAAK,IAAI,CAAC,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE,CAAC,UAAU,CAAC,KAAK,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC,EACjE,GAAG,EACH,OAAO,CACR,CAAC;IACJ,CAAC;CACF"}
|
package/dist/env.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The little the SDK needs to know about where it runs. It targets Node 24+ and browsers
|
|
3
|
+
* alike, through the web APIs they share (`fetch`, `Blob`, `ReadableStream`, `crypto`).
|
|
4
|
+
*/
|
|
5
|
+
/** `true` in a browser page (a `window` with a `document`); `false` in Node, a worker, a test. */
|
|
6
|
+
export declare function isBrowser(): boolean;
|
|
7
|
+
/** Bytes → base64 (standard alphabet, padded). */
|
|
8
|
+
export declare function bytesToBase64(bytes: Uint8Array): string;
|
|
9
|
+
/** Bytes → base64url (no padding): the form of a share secret in a URL fragment. */
|
|
10
|
+
export declare function bytesToBase64Url(bytes: Uint8Array): string;
|
|
11
|
+
/** base64 or base64url → bytes. Throws a `TypeError` on malformed input. */
|
|
12
|
+
export declare function base64ToBytes(value: string): Uint8Array;
|
|
13
|
+
/** `n` random bytes from the platform's CSPRNG. */
|
|
14
|
+
export declare function randomBytes(n: number): Uint8Array<ArrayBuffer>;
|
|
15
|
+
/** A random hex string (a multipart boundary, a fingerprint salt). */
|
|
16
|
+
export declare function randomHex(bytes?: number): string;
|
|
17
|
+
/** `encodeURIComponent` of every segment of `a/b/c`, keeping the slashes; leading and trailing slashes dropped. */
|
|
18
|
+
export declare function encodePath(path: string): string;
|
|
19
|
+
//# sourceMappingURL=env.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"env.d.ts","sourceRoot":"","sources":["../src/env.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,kGAAkG;AAClG,wBAAgB,SAAS,IAAI,OAAO,CAEnC;AAED,kDAAkD;AAClD,wBAAgB,aAAa,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAIvD;AAED,oFAAoF;AACpF,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAE1D;AAED,4EAA4E;AAC5E,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,UAAU,CAYvD;AAED,mDAAmD;AACnD,wBAAgB,WAAW,CAAC,CAAC,EAAE,MAAM,GAAG,UAAU,CAAC,WAAW,CAAC,CAE9D;AAED,sEAAsE;AACtE,wBAAgB,SAAS,CAAC,KAAK,SAAK,GAAG,MAAM,CAE5C;AAED,mHAAmH;AACnH,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAM/C"}
|
package/dist/env.js
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The little the SDK needs to know about where it runs. It targets Node 24+ and browsers
|
|
3
|
+
* alike, through the web APIs they share (`fetch`, `Blob`, `ReadableStream`, `crypto`).
|
|
4
|
+
*/
|
|
5
|
+
/** `true` in a browser page (a `window` with a `document`); `false` in Node, a worker, a test. */
|
|
6
|
+
export function isBrowser() {
|
|
7
|
+
return typeof window !== "undefined" && typeof window.document !== "undefined";
|
|
8
|
+
}
|
|
9
|
+
/** Bytes → base64 (standard alphabet, padded). */
|
|
10
|
+
export function bytesToBase64(bytes) {
|
|
11
|
+
let binary = "";
|
|
12
|
+
for (const byte of bytes)
|
|
13
|
+
binary += String.fromCharCode(byte);
|
|
14
|
+
return btoa(binary);
|
|
15
|
+
}
|
|
16
|
+
/** Bytes → base64url (no padding): the form of a share secret in a URL fragment. */
|
|
17
|
+
export function bytesToBase64Url(bytes) {
|
|
18
|
+
return bytesToBase64(bytes).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
|
|
19
|
+
}
|
|
20
|
+
/** base64 or base64url → bytes. Throws a `TypeError` on malformed input. */
|
|
21
|
+
export function base64ToBytes(value) {
|
|
22
|
+
const normalised = value.replace(/-/g, "+").replace(/_/g, "/");
|
|
23
|
+
const padded = normalised + "=".repeat((4 - (normalised.length % 4)) % 4);
|
|
24
|
+
let binary;
|
|
25
|
+
try {
|
|
26
|
+
binary = atob(padded);
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
throw new TypeError("not base64");
|
|
30
|
+
}
|
|
31
|
+
const bytes = new Uint8Array(binary.length);
|
|
32
|
+
for (let i = 0; i < binary.length; i++)
|
|
33
|
+
bytes[i] = binary.charCodeAt(i);
|
|
34
|
+
return bytes;
|
|
35
|
+
}
|
|
36
|
+
/** `n` random bytes from the platform's CSPRNG. */
|
|
37
|
+
export function randomBytes(n) {
|
|
38
|
+
return crypto.getRandomValues(new Uint8Array(n));
|
|
39
|
+
}
|
|
40
|
+
/** A random hex string (a multipart boundary, a fingerprint salt). */
|
|
41
|
+
export function randomHex(bytes = 16) {
|
|
42
|
+
return Array.from(randomBytes(bytes), (b) => b.toString(16).padStart(2, "0")).join("");
|
|
43
|
+
}
|
|
44
|
+
/** `encodeURIComponent` of every segment of `a/b/c`, keeping the slashes; leading and trailing slashes dropped. */
|
|
45
|
+
export function encodePath(path) {
|
|
46
|
+
return path
|
|
47
|
+
.split("/")
|
|
48
|
+
.filter((segment) => segment !== "")
|
|
49
|
+
.map((segment) => encodeURIComponent(segment))
|
|
50
|
+
.join("/");
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=env.js.map
|
package/dist/env.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"env.js","sourceRoot":"","sources":["../src/env.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,kGAAkG;AAClG,MAAM,UAAU,SAAS;IACvB,OAAO,OAAO,MAAM,KAAK,WAAW,IAAI,OAAO,MAAM,CAAC,QAAQ,KAAK,WAAW,CAAC;AACjF,CAAC;AAED,kDAAkD;AAClD,MAAM,UAAU,aAAa,CAAC,KAAiB;IAC7C,IAAI,MAAM,GAAG,EAAE,CAA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CAAC,eAAe,CAAC,IAAI,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC;AACnD,CAAC;AAED,sEAAsE;AACtE,MAAM,UAAU,SAAS,CAAC,KAAK,GAAG,EAAE;IAClC,OAAO,KAAK,CAAC,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AACzF,CAAC;AAED,mHAAmH;AACnH,MAAM,UAAU,UAAU,CAAC,IAAY;IACrC,OAAO,IAAI;SACR,KAAK,CAAC,GAAG,CAAC;SACV,MAAM,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,KAAK,EAAE,CAAC;SACnC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,kBAAkB,CAAC,OAAO,CAAC,CAAC;SAC7C,IAAI,CAAC,GAAG,CAAC,CAAC;AACf,CAAC"}
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
export interface VolaErrorInit {
|
|
2
|
+
/** The HTTP status; `0` for an error raised by the SDK itself (before any request went out). */
|
|
3
|
+
status: number;
|
|
4
|
+
/** The server's snake_case code (`file_not_found`, `vola_locked`, …) or an SDK code (`invalid_response`). */
|
|
5
|
+
code: string;
|
|
6
|
+
message: string;
|
|
7
|
+
/** Seconds to wait before trying again (`Retry-After`, or `retry_after` of the body), when the server said so. */
|
|
8
|
+
retryAfter?: number | undefined;
|
|
9
|
+
/** Everything else the error envelope carried (`required` scopes, `attempts`, `reason`, …). */
|
|
10
|
+
details?: Record<string, unknown> | undefined;
|
|
11
|
+
/** `X-Request-Id` of the answer, for a support ticket. */
|
|
12
|
+
requestId?: string | null | undefined;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* A non-2xx answer of the server, carrying its `{ error: { code, message, … } }` envelope —
|
|
16
|
+
* or an error the SDK raised itself (`status: 0`). Never a secret: no key, token, PIN or
|
|
17
|
+
* share secret is ever part of the message or the details.
|
|
18
|
+
*/
|
|
19
|
+
export declare class VolaError extends Error {
|
|
20
|
+
readonly status: number;
|
|
21
|
+
readonly code: string;
|
|
22
|
+
readonly retryAfter: number | undefined;
|
|
23
|
+
readonly details: Record<string, unknown>;
|
|
24
|
+
readonly requestId: string | null;
|
|
25
|
+
constructor(init: VolaErrorInit);
|
|
26
|
+
}
|
|
27
|
+
/** `423 vola_locked`: the request needs an unlock token (keyring) or a content key (caller) it did not carry, or the one it carried is dead. */
|
|
28
|
+
export declare class VolaLockedError extends VolaError {
|
|
29
|
+
constructor(init: VolaErrorInit);
|
|
30
|
+
}
|
|
31
|
+
/** `409 vola_integrity`: the file (or a share grant) could not be decrypted — a wrong key, a wrong secret, or damaged bytes. */
|
|
32
|
+
export declare class VolaIntegrityError extends VolaError {
|
|
33
|
+
constructor(init: VolaErrorInit);
|
|
34
|
+
}
|
|
35
|
+
/** @deprecated The name of the health-only client's error; `VolaError` is the same class. */
|
|
36
|
+
export declare const VolaApiError: typeof VolaError;
|
|
37
|
+
/**
|
|
38
|
+
* The `VolaError` of a non-2xx `response`: the envelope when the body is one, `unknown_error`
|
|
39
|
+
* with `HTTP <status>` otherwise. `423` is a `VolaLockedError`, `409 vola_integrity` a
|
|
40
|
+
* `VolaIntegrityError`. Consumes the body.
|
|
41
|
+
*/
|
|
42
|
+
export declare function errorFromResponse(response: Response): Promise<VolaError>;
|
|
43
|
+
//# sourceMappingURL=errors.d.ts.map
|