@vol-a/core 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 +34 -2
- package/dist/access-tokens.d.ts +56 -0
- package/dist/access-tokens.d.ts.map +1 -0
- package/dist/access-tokens.js +59 -0
- package/dist/access-tokens.js.map +1 -0
- package/dist/apikey.d.ts +179 -0
- package/dist/apikey.d.ts.map +1 -0
- package/dist/apikey.js +117 -0
- package/dist/apikey.js.map +1 -0
- package/dist/errors.d.ts +25 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +19 -0
- package/dist/errors.js.map +1 -0
- package/dist/files.d.ts +265 -0
- package/dist/files.d.ts.map +1 -0
- package/dist/files.js +124 -0
- package/dist/files.js.map +1 -0
- package/dist/folders.d.ts +248 -0
- package/dist/folders.d.ts.map +1 -0
- package/dist/folders.js +157 -0
- package/dist/folders.js.map +1 -0
- package/dist/health.d.ts +33 -0
- package/dist/health.d.ts.map +1 -0
- package/dist/health.js +16 -0
- package/dist/health.js.map +1 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +16 -0
- package/dist/index.js.map +1 -0
- package/dist/keyrings.d.ts +116 -0
- package/dist/keyrings.d.ts.map +1 -0
- package/dist/keyrings.js +103 -0
- package/dist/keyrings.js.map +1 -0
- package/dist/lookups.d.ts +62 -0
- package/dist/lookups.d.ts.map +1 -0
- package/dist/lookups.js +48 -0
- package/dist/lookups.js.map +1 -0
- package/dist/processing.d.ts +122 -0
- package/dist/processing.d.ts.map +1 -0
- package/dist/processing.js +142 -0
- package/dist/processing.js.map +1 -0
- package/dist/scopes.d.ts +43 -0
- package/dist/scopes.d.ts.map +1 -0
- package/dist/scopes.js +52 -0
- package/dist/scopes.js.map +1 -0
- package/dist/shares.d.ts +229 -0
- package/dist/shares.d.ts.map +1 -0
- package/dist/shares.js +153 -0
- package/dist/shares.js.map +1 -0
- package/dist/stats.d.ts +88 -0
- package/dist/stats.d.ts.map +1 -0
- package/dist/stats.js +61 -0
- package/dist/stats.js.map +1 -0
- package/dist/subscribe.d.ts +222 -0
- package/dist/subscribe.d.ts.map +1 -0
- package/dist/subscribe.js +118 -0
- package/dist/subscribe.js.map +1 -0
- package/dist/transfer.d.ts +50 -0
- package/dist/transfer.d.ts.map +1 -0
- package/dist/transfer.js +54 -0
- package/dist/transfer.js.map +1 -0
- package/dist/uploads.d.ts +56 -0
- package/dist/uploads.d.ts.map +1 -0
- package/dist/uploads.js +97 -0
- package/dist/uploads.js.map +1 -0
- package/package.json +45 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Digital Cube
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,35 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @vol-a/core
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The JSVola protocol as code: the Zod schemas and inferred TypeScript types of every request body
|
|
4
|
+
and answer of [`@vol-a/server`](https://github.com/digital-cube/jsvola/tree/main/packages/server),
|
|
5
|
+
the header, query-parameter and error-code constants both sides agree on, the scopes, and the
|
|
6
|
+
helpers the server, the CLI and the clients share. No Node-only API — it runs in browsers too.
|
|
7
|
+
|
|
8
|
+
```sh
|
|
9
|
+
pnpm add @vol-a/core
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
```ts
|
|
13
|
+
import { FileInfoSchema, type FileInfo, ShareCreateSchema, UNLOCK_HEADER, LOCKED_CODE, SCOPES } from "@vol-a/core";
|
|
14
|
+
|
|
15
|
+
const info: FileInfo = FileInfoSchema.parse(await response.json());
|
|
16
|
+
ShareCreateSchema.parse({ file_id: info.id, max_downloads: 3 });
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
| area | schemas (each with its inferred type) |
|
|
20
|
+
|---|---|
|
|
21
|
+
| files | `FileInfoSchema`, `FileDetailSchema` (+ `ocr`), `FileListSchema`, `FileVersionsSchema`, `FilePatchSchema`, `PurgeResultSchema`, `FileKindSchema`, `FileEncryptionSchema`, `ThumbnailSizeSchema`, `ThumbnailCropSchema`, `InstanceTypeSchema`, `FileSlugSchema`, `UserIdSchema` |
|
|
22
|
+
| folders | `FolderInfoSchema`, `FolderListingSchema`, `FolderPatchSchema`, `FolderDeleteResultSchema`, `FolderPathSchema` |
|
|
23
|
+
| uploads (tus) | the `UPLOAD_*` header and metadata constants, `UPLOAD_META_KEYS` |
|
|
24
|
+
| shares | `ShareCreateSchema`, `ShareCreatedSchema`, `ShareInfoSchema`, `ShareListSchema`, `SharedFolderListingSchema`, `callerGrantAad` |
|
|
25
|
+
| keyrings | `KeyringCreateSchema`, `KeyringCreatedSchema`, `KeyringStatusSchema`, `UnlockSchema`, `UnlockedSchema`, `PinChangeSchema`, `RecoverSchema`, `RecoveredSchema`, `KeyringResetSchema`, `KeyringDeletePreviewSchema`, `PIN_LENGTH` |
|
|
26
|
+
| stats, transfer | `TenantStatsSchema`, `StorageStatsSchema`, `TransferRequestSchema`, `TransferResultSchema`, `TRANSFER_MAX_INSTANCES` |
|
|
27
|
+
| keys, tenants | `ApiKeyCreateSchema`, `ApiKeyCreatedSchema`, `ApiKeyListSchema`, `TenantSchema`, `SCOPES`, `parseApiKey`, `displayApiKey`, `missingScopes` |
|
|
28
|
+
| real-time | `ClientMessageSchema`, `ServerMessageSchema`, `SubscribePayloadSchema`, `VOLA_SUBPROTOCOL`, `BEARER_SUBPROTOCOL_PREFIX` |
|
|
29
|
+
| lookups, health, errors | `LookupsResponseSchema`, `InstanceTypesResponseSchema`, `LiveResponseSchema`, `ReadyResponseSchema`, `ErrorResponseSchema`, the `*_CODE` constants |
|
|
30
|
+
|
|
31
|
+
The route reference that these schemas describe:
|
|
32
|
+
[docs/API.md](https://github.com/digital-cube/jsvola/blob/main/docs/API.md). A ready-made client
|
|
33
|
+
over them: [`@vol-a/client`](https://www.npmjs.com/package/@vol-a/client).
|
|
34
|
+
|
|
35
|
+
MIT.
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/**
|
|
3
|
+
* Access tokens (1.2): a short-lived, read-only credential the HOST application issues to its
|
|
4
|
+
* own user for named ROWS of `vola_file` (`file_ids`) or for one instance — never for content
|
|
5
|
+
* as such. A token reads only `GET|HEAD /files/:type/:id/:fileId` and `…/thumb/:size`; another
|
|
6
|
+
* row, even one sharing the blob, is `404`. Sent as `Authorization: Bearer vola_at_…`.
|
|
7
|
+
*/
|
|
8
|
+
/** The prefix of every access token: never mistaken for an API key (`vola_live_…`). */
|
|
9
|
+
export declare const ACCESS_TOKEN_PREFIX = "vola_at_";
|
|
10
|
+
/** Length of the random, base62 part of a token. */
|
|
11
|
+
export declare const ACCESS_TOKEN_SECRET_LENGTH = 40;
|
|
12
|
+
/** `expires_in` when the request names none: five minutes. */
|
|
13
|
+
export declare const DEFAULT_ACCESS_TOKEN_TTL_S = 300;
|
|
14
|
+
/** `VOLA_ACCESS_TOKEN_MAX_TTL_S` when unset: one hour. */
|
|
15
|
+
export declare const DEFAULT_ACCESS_TOKEN_MAX_TTL_S = 3600;
|
|
16
|
+
/** The most rows one token may name. */
|
|
17
|
+
export declare const ACCESS_TOKEN_MAX_FILES = 100;
|
|
18
|
+
/**
|
|
19
|
+
* The code of a `keyring`, `caller` or `client` file read with an access token (`409`): the
|
|
20
|
+
* token carries no unlock and no content key, and this version serves only `none` and
|
|
21
|
+
* `tenant` files through it.
|
|
22
|
+
*/
|
|
23
|
+
export declare const ACCESS_TOKEN_ENCRYPTION_UNSUPPORTED_CODE = "access_token_encryption_unsupported";
|
|
24
|
+
/** The encryption modes a token may read. */
|
|
25
|
+
export declare const ACCESS_TOKEN_READABLE_ENCRYPTIONS: readonly ["none", "tenant"];
|
|
26
|
+
/** `true` for a well-formed access token (`vola_at_<40 base62>`). */
|
|
27
|
+
export declare function isAccessToken(value: string): boolean;
|
|
28
|
+
/** The instance a token covers: every live row of it at the time of each request. */
|
|
29
|
+
export declare const AccessTokenInstanceSchema: z.ZodObject<{
|
|
30
|
+
instance_type: z.ZodString;
|
|
31
|
+
instance_id: z.ZodUUID;
|
|
32
|
+
}, z.core.$strict>;
|
|
33
|
+
export type AccessTokenInstance = z.infer<typeof AccessTokenInstanceSchema>;
|
|
34
|
+
/**
|
|
35
|
+
* `POST /access-tokens`: exactly one of `file_ids` (1–100 rows of the caller's tenant) or
|
|
36
|
+
* `instance`; `principal` (the host's user, the rules of `X-User-Id`); `expires_in` seconds
|
|
37
|
+
* (default 300; above `VOLA_ACCESS_TOKEN_MAX_TTL_S` the server answers `422`).
|
|
38
|
+
*/
|
|
39
|
+
export declare const AccessTokenCreateSchema: z.ZodObject<{
|
|
40
|
+
file_ids: z.ZodOptional<z.ZodArray<z.ZodUUID>>;
|
|
41
|
+
instance: z.ZodOptional<z.ZodObject<{
|
|
42
|
+
instance_type: z.ZodString;
|
|
43
|
+
instance_id: z.ZodUUID;
|
|
44
|
+
}, z.core.$strict>>;
|
|
45
|
+
principal: z.ZodString;
|
|
46
|
+
expires_in: z.ZodOptional<z.ZodNumber>;
|
|
47
|
+
}, z.core.$strict>;
|
|
48
|
+
export type AccessTokenCreate = z.infer<typeof AccessTokenCreateSchema>;
|
|
49
|
+
/** The `201` of `POST /access-tokens`: the token in plain text, this once. */
|
|
50
|
+
export declare const AccessTokenCreatedSchema: z.ZodObject<{
|
|
51
|
+
id: z.ZodUUID;
|
|
52
|
+
token: z.ZodString;
|
|
53
|
+
expires_at: z.ZodISODateTime;
|
|
54
|
+
}, z.core.$strip>;
|
|
55
|
+
export type AccessTokenCreated = z.infer<typeof AccessTokenCreatedSchema>;
|
|
56
|
+
//# sourceMappingURL=access-tokens.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"access-tokens.d.ts","sourceRoot":"","sources":["../src/access-tokens.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAIxB;;;;;GAKG;AAEH,uFAAuF;AACvF,eAAO,MAAM,mBAAmB,aAAa,CAAC;AAC9C,oDAAoD;AACpD,eAAO,MAAM,0BAA0B,KAAK,CAAC;AAC7C,8DAA8D;AAC9D,eAAO,MAAM,0BAA0B,MAAM,CAAC;AAC9C,0DAA0D;AAC1D,eAAO,MAAM,8BAA8B,OAAO,CAAC;AACnD,wCAAwC;AACxC,eAAO,MAAM,sBAAsB,MAAM,CAAC;AAC1C;;;;GAIG;AACH,eAAO,MAAM,wCAAwC,wCAAwC,CAAC;AAC9F,6CAA6C;AAC7C,eAAO,MAAM,iCAAiC,6BAA8B,CAAC;AAI7E,qEAAqE;AACrE,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAEpD;AAED,qFAAqF;AACrF,eAAO,MAAM,yBAAyB;;;kBAGpC,CAAC;AACH,MAAM,MAAM,mBAAmB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,yBAAyB,CAAC,CAAC;AAE5E;;;;GAIG;AACH,eAAO,MAAM,uBAAuB;;;;;;;;kBAShC,CAAC;AACL,MAAM,MAAM,iBAAiB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,uBAAuB,CAAC,CAAC;AAExE,8EAA8E;AAC9E,eAAO,MAAM,wBAAwB;;;;iBAInC,CAAC;AACH,MAAM,MAAM,kBAAkB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,wBAAwB,CAAC,CAAC"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { TimestampSchema, UserIdSchema } from "./apikey.js";
|
|
3
|
+
import { InstanceTypeSchema } from "./files.js";
|
|
4
|
+
/**
|
|
5
|
+
* Access tokens (1.2): a short-lived, read-only credential the HOST application issues to its
|
|
6
|
+
* own user for named ROWS of `vola_file` (`file_ids`) or for one instance — never for content
|
|
7
|
+
* as such. A token reads only `GET|HEAD /files/:type/:id/:fileId` and `…/thumb/:size`; another
|
|
8
|
+
* row, even one sharing the blob, is `404`. Sent as `Authorization: Bearer vola_at_…`.
|
|
9
|
+
*/
|
|
10
|
+
/** The prefix of every access token: never mistaken for an API key (`vola_live_…`). */
|
|
11
|
+
export const ACCESS_TOKEN_PREFIX = "vola_at_";
|
|
12
|
+
/** Length of the random, base62 part of a token. */
|
|
13
|
+
export const ACCESS_TOKEN_SECRET_LENGTH = 40;
|
|
14
|
+
/** `expires_in` when the request names none: five minutes. */
|
|
15
|
+
export const DEFAULT_ACCESS_TOKEN_TTL_S = 300;
|
|
16
|
+
/** `VOLA_ACCESS_TOKEN_MAX_TTL_S` when unset: one hour. */
|
|
17
|
+
export const DEFAULT_ACCESS_TOKEN_MAX_TTL_S = 3600;
|
|
18
|
+
/** The most rows one token may name. */
|
|
19
|
+
export const ACCESS_TOKEN_MAX_FILES = 100;
|
|
20
|
+
/**
|
|
21
|
+
* The code of a `keyring`, `caller` or `client` file read with an access token (`409`): the
|
|
22
|
+
* token carries no unlock and no content key, and this version serves only `none` and
|
|
23
|
+
* `tenant` files through it.
|
|
24
|
+
*/
|
|
25
|
+
export const ACCESS_TOKEN_ENCRYPTION_UNSUPPORTED_CODE = "access_token_encryption_unsupported";
|
|
26
|
+
/** The encryption modes a token may read. */
|
|
27
|
+
export const ACCESS_TOKEN_READABLE_ENCRYPTIONS = ["none", "tenant"];
|
|
28
|
+
const ACCESS_TOKEN_RE = /^vola_at_[A-Za-z0-9]{40}$/;
|
|
29
|
+
/** `true` for a well-formed access token (`vola_at_<40 base62>`). */
|
|
30
|
+
export function isAccessToken(value) {
|
|
31
|
+
return ACCESS_TOKEN_RE.test(value);
|
|
32
|
+
}
|
|
33
|
+
/** The instance a token covers: every live row of it at the time of each request. */
|
|
34
|
+
export const AccessTokenInstanceSchema = z.strictObject({
|
|
35
|
+
instance_type: InstanceTypeSchema,
|
|
36
|
+
instance_id: z.uuid(),
|
|
37
|
+
});
|
|
38
|
+
/**
|
|
39
|
+
* `POST /access-tokens`: exactly one of `file_ids` (1–100 rows of the caller's tenant) or
|
|
40
|
+
* `instance`; `principal` (the host's user, the rules of `X-User-Id`); `expires_in` seconds
|
|
41
|
+
* (default 300; above `VOLA_ACCESS_TOKEN_MAX_TTL_S` the server answers `422`).
|
|
42
|
+
*/
|
|
43
|
+
export const AccessTokenCreateSchema = z
|
|
44
|
+
.strictObject({
|
|
45
|
+
file_ids: z.array(z.uuid()).min(1).max(ACCESS_TOKEN_MAX_FILES).optional(),
|
|
46
|
+
instance: AccessTokenInstanceSchema.optional(),
|
|
47
|
+
principal: UserIdSchema,
|
|
48
|
+
expires_in: z.number().int().positive().optional(),
|
|
49
|
+
})
|
|
50
|
+
.refine((body) => (body.file_ids === undefined) !== (body.instance === undefined), {
|
|
51
|
+
message: "exactly one of file_ids or instance is required",
|
|
52
|
+
});
|
|
53
|
+
/** The `201` of `POST /access-tokens`: the token in plain text, this once. */
|
|
54
|
+
export const AccessTokenCreatedSchema = z.object({
|
|
55
|
+
id: z.uuid(),
|
|
56
|
+
token: z.string().regex(ACCESS_TOKEN_RE),
|
|
57
|
+
expires_at: TimestampSchema,
|
|
58
|
+
});
|
|
59
|
+
//# sourceMappingURL=access-tokens.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"access-tokens.js","sourceRoot":"","sources":["../src/access-tokens.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC5D,OAAO,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAEhD;;;;;GAKG;AAEH,uFAAuF;AACvF,MAAM,CAAC,MAAM,mBAAmB,GAAG,UAAU,CAAC;AAC9C,oDAAoD;AACpD,MAAM,CAAC,MAAM,0BAA0B,GAAG,EAAE,CAAC;AAC7C,8DAA8D;AAC9D,MAAM,CAAC,MAAM,0BAA0B,GAAG,GAAG,CAAC;AAC9C,0DAA0D;AAC1D,MAAM,CAAC,MAAM,8BAA8B,GAAG,IAAI,CAAC;AACnD,wCAAwC;AACxC,MAAM,CAAC,MAAM,sBAAsB,GAAG,GAAG,CAAC;AAC1C;;;;GAIG;AACH,MAAM,CAAC,MAAM,wCAAwC,GAAG,qCAAqC,CAAC;AAC9F,6CAA6C;AAC7C,MAAM,CAAC,MAAM,iCAAiC,GAAG,CAAC,MAAM,EAAE,QAAQ,CAAU,CAAC;AAE7E,MAAM,eAAe,GAAG,2BAA2B,CAAC;AAEpD,qEAAqE;AACrE,MAAM,UAAU,aAAa,CAAC,KAAa;IACzC,OAAO,eAAe,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;AACrC,CAAC;AAED,qFAAqF;AACrF,MAAM,CAAC,MAAM,yBAAyB,GAAG,CAAC,CAAC,YAAY,CAAC;IACtD,aAAa,EAAE,kBAAkB;IACjC,WAAW,EAAE,CAAC,CAAC,IAAI,EAAE;CACtB,CAAC,CAAC;AAGH;;;;GAIG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAAC;KACrC,YAAY,CAAC;IACZ,QAAQ,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,sBAAsB,CAAC,CAAC,QAAQ,EAAE;IACzE,QAAQ,EAAE,yBAAyB,CAAC,QAAQ,EAAE;IAC9C,SAAS,EAAE,YAAY;IACvB,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,EAAE;CACnD,CAAC;KACD,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,QAAQ,KAAK,SAAS,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,KAAK,SAAS,CAAC,EAAE;IACjF,OAAO,EAAE,iDAAiD;CAC3D,CAAC,CAAC;AAGL,8EAA8E;AAC9E,MAAM,CAAC,MAAM,wBAAwB,GAAG,CAAC,CAAC,MAAM,CAAC;IAC/C,EAAE,EAAE,CAAC,CAAC,IAAI,EAAE;IACZ,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,eAAe,CAAC;IACxC,UAAU,EAAE,eAAe;CAC5B,CAAC,CAAC"}
|
package/dist/apikey.d.ts
ADDED
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/** Environments a key is minted for; the prefix of the key is `vola_<env>`. */
|
|
3
|
+
export declare const KEY_ENVS: readonly ["live", "test", "admin"];
|
|
4
|
+
export declare const KeyEnvSchema: z.ZodEnum<{
|
|
5
|
+
admin: "admin";
|
|
6
|
+
live: "live";
|
|
7
|
+
test: "test";
|
|
8
|
+
}>;
|
|
9
|
+
export type KeyEnv = z.infer<typeof KeyEnvSchema>;
|
|
10
|
+
export declare const KEY_PREFIXES: readonly ["vola_live", "vola_test", "vola_admin"];
|
|
11
|
+
export type KeyPrefix = (typeof KEY_PREFIXES)[number];
|
|
12
|
+
/** Length of the random, base62 part of a key. */
|
|
13
|
+
export declare const KEY_SECRET_LENGTH = 32;
|
|
14
|
+
/** Splits a well-formed key `vola_<env>_<32 base62>` into its parts; `null` for anything else. */
|
|
15
|
+
export declare function parseApiKey(key: string): {
|
|
16
|
+
prefix: KeyPrefix;
|
|
17
|
+
env: KeyEnv;
|
|
18
|
+
secret: string;
|
|
19
|
+
last4: string;
|
|
20
|
+
} | null;
|
|
21
|
+
/** How a stored key is shown to a person: `vola_live…k3Qz`. */
|
|
22
|
+
export declare function displayApiKey(prefix: string, last4: string): string;
|
|
23
|
+
/** Reads the key from `Authorization: Bearer <key>` or `X-Api-Key: <key>`. */
|
|
24
|
+
export declare function extractApiKey(headers: Record<string, string | string[] | undefined>): string | null;
|
|
25
|
+
/**
|
|
26
|
+
* Browsers cannot set headers on a WebSocket, so the key travels as a subprotocol:
|
|
27
|
+
* `bearer.<key>`. Offer `vola.v1` next to it and the server selects that one, so the key is
|
|
28
|
+
* never echoed back.
|
|
29
|
+
*/
|
|
30
|
+
export declare const BEARER_SUBPROTOCOL_PREFIX = "bearer.";
|
|
31
|
+
export declare const VOLA_SUBPROTOCOL = "vola.v1";
|
|
32
|
+
/** The subprotocols a WebSocket client offers: `[VOLA_SUBPROTOCOL, "bearer.<key>"]`. */
|
|
33
|
+
export declare function bearerSubprotocols(apiKey: string): string[];
|
|
34
|
+
/** The API key in a `Sec-WebSocket-Protocol` header (`…, bearer.<key>, …`), or `null`. */
|
|
35
|
+
export declare function extractSubprotocolKey(header: string | string[] | undefined): string | null;
|
|
36
|
+
/** Headers of the auth contract. */
|
|
37
|
+
export declare const API_KEY_HEADER = "x-api-key";
|
|
38
|
+
export declare const TENANT_SLUG_HEADER = "x-tenant-slug";
|
|
39
|
+
export declare const USER_ID_HEADER = "x-user-id";
|
|
40
|
+
/** A tenant slug: lowercase letters, digits and dashes, 2–63 characters, not starting with `-`. */
|
|
41
|
+
export declare const SlugSchema: z.ZodString;
|
|
42
|
+
export type Slug = z.infer<typeof SlugSchema>;
|
|
43
|
+
/** `X-User-Id`: an opaque principal of the host application; ≤ 255 characters, none of them control characters. */
|
|
44
|
+
export declare const UserIdSchema: z.ZodString;
|
|
45
|
+
export declare const TimestampSchema: z.ZodISODateTime;
|
|
46
|
+
/** Public view of a stored key: never the plaintext, never the hash. */
|
|
47
|
+
export declare const ApiKeySchema: z.ZodObject<{
|
|
48
|
+
id: z.ZodUUID;
|
|
49
|
+
tenant_id: z.ZodNullable<z.ZodUUID>;
|
|
50
|
+
name: z.ZodString;
|
|
51
|
+
prefix: z.ZodEnum<{
|
|
52
|
+
vola_live: "vola_live";
|
|
53
|
+
vola_test: "vola_test";
|
|
54
|
+
vola_admin: "vola_admin";
|
|
55
|
+
}>;
|
|
56
|
+
last4: z.ZodString;
|
|
57
|
+
scopes: z.ZodArray<z.ZodEnum<{
|
|
58
|
+
"files:read": "files:read";
|
|
59
|
+
"files:write": "files:write";
|
|
60
|
+
"folders:read": "folders:read";
|
|
61
|
+
"folders:write": "folders:write";
|
|
62
|
+
"shares:write": "shares:write";
|
|
63
|
+
"keys:write": "keys:write";
|
|
64
|
+
"keyrings:write": "keyrings:write";
|
|
65
|
+
"encryption:caller": "encryption:caller";
|
|
66
|
+
"access:grant": "access:grant";
|
|
67
|
+
admin: "admin";
|
|
68
|
+
}>>;
|
|
69
|
+
is_admin: z.ZodBoolean;
|
|
70
|
+
created_at: z.ZodISODateTime;
|
|
71
|
+
last_used_at: z.ZodNullable<z.ZodISODateTime>;
|
|
72
|
+
expires_at: z.ZodNullable<z.ZodISODateTime>;
|
|
73
|
+
revoked_at: z.ZodNullable<z.ZodISODateTime>;
|
|
74
|
+
created_by: z.ZodNullable<z.ZodString>;
|
|
75
|
+
}, z.core.$strip>;
|
|
76
|
+
export type ApiKey = z.infer<typeof ApiKeySchema>;
|
|
77
|
+
/** `POST /keys`: a tenant key with a subset of the caller's scopes; the plaintext comes back once. */
|
|
78
|
+
export declare const ApiKeyCreateSchema: z.ZodObject<{
|
|
79
|
+
name: z.ZodString;
|
|
80
|
+
scopes: z.ZodArray<z.ZodEnum<{
|
|
81
|
+
"files:read": "files:read";
|
|
82
|
+
"files:write": "files:write";
|
|
83
|
+
"folders:read": "folders:read";
|
|
84
|
+
"folders:write": "folders:write";
|
|
85
|
+
"shares:write": "shares:write";
|
|
86
|
+
"keys:write": "keys:write";
|
|
87
|
+
"keyrings:write": "keyrings:write";
|
|
88
|
+
"encryption:caller": "encryption:caller";
|
|
89
|
+
"access:grant": "access:grant";
|
|
90
|
+
admin: "admin";
|
|
91
|
+
}>>;
|
|
92
|
+
env: z.ZodEnum<{
|
|
93
|
+
live: "live";
|
|
94
|
+
test: "test";
|
|
95
|
+
}>;
|
|
96
|
+
expires_at: z.ZodOptional<z.ZodISODateTime>;
|
|
97
|
+
}, z.core.$strict>;
|
|
98
|
+
export type ApiKeyCreate = z.infer<typeof ApiKeyCreateSchema>;
|
|
99
|
+
/** `201` of `POST /keys`: the stored key plus its plaintext, this once. */
|
|
100
|
+
export declare const ApiKeyCreatedSchema: z.ZodObject<{
|
|
101
|
+
id: z.ZodUUID;
|
|
102
|
+
tenant_id: z.ZodNullable<z.ZodUUID>;
|
|
103
|
+
name: z.ZodString;
|
|
104
|
+
prefix: z.ZodEnum<{
|
|
105
|
+
vola_live: "vola_live";
|
|
106
|
+
vola_test: "vola_test";
|
|
107
|
+
vola_admin: "vola_admin";
|
|
108
|
+
}>;
|
|
109
|
+
last4: z.ZodString;
|
|
110
|
+
scopes: z.ZodArray<z.ZodEnum<{
|
|
111
|
+
"files:read": "files:read";
|
|
112
|
+
"files:write": "files:write";
|
|
113
|
+
"folders:read": "folders:read";
|
|
114
|
+
"folders:write": "folders:write";
|
|
115
|
+
"shares:write": "shares:write";
|
|
116
|
+
"keys:write": "keys:write";
|
|
117
|
+
"keyrings:write": "keyrings:write";
|
|
118
|
+
"encryption:caller": "encryption:caller";
|
|
119
|
+
"access:grant": "access:grant";
|
|
120
|
+
admin: "admin";
|
|
121
|
+
}>>;
|
|
122
|
+
is_admin: z.ZodBoolean;
|
|
123
|
+
created_at: z.ZodISODateTime;
|
|
124
|
+
last_used_at: z.ZodNullable<z.ZodISODateTime>;
|
|
125
|
+
expires_at: z.ZodNullable<z.ZodISODateTime>;
|
|
126
|
+
revoked_at: z.ZodNullable<z.ZodISODateTime>;
|
|
127
|
+
created_by: z.ZodNullable<z.ZodString>;
|
|
128
|
+
key: z.ZodString;
|
|
129
|
+
}, z.core.$strip>;
|
|
130
|
+
export type ApiKeyCreated = z.infer<typeof ApiKeyCreatedSchema>;
|
|
131
|
+
/** `GET /keys`. */
|
|
132
|
+
export declare const ApiKeyListSchema: z.ZodObject<{
|
|
133
|
+
keys: z.ZodArray<z.ZodObject<{
|
|
134
|
+
id: z.ZodUUID;
|
|
135
|
+
tenant_id: z.ZodNullable<z.ZodUUID>;
|
|
136
|
+
name: z.ZodString;
|
|
137
|
+
prefix: z.ZodEnum<{
|
|
138
|
+
vola_live: "vola_live";
|
|
139
|
+
vola_test: "vola_test";
|
|
140
|
+
vola_admin: "vola_admin";
|
|
141
|
+
}>;
|
|
142
|
+
last4: z.ZodString;
|
|
143
|
+
scopes: z.ZodArray<z.ZodEnum<{
|
|
144
|
+
"files:read": "files:read";
|
|
145
|
+
"files:write": "files:write";
|
|
146
|
+
"folders:read": "folders:read";
|
|
147
|
+
"folders:write": "folders:write";
|
|
148
|
+
"shares:write": "shares:write";
|
|
149
|
+
"keys:write": "keys:write";
|
|
150
|
+
"keyrings:write": "keyrings:write";
|
|
151
|
+
"encryption:caller": "encryption:caller";
|
|
152
|
+
"access:grant": "access:grant";
|
|
153
|
+
admin: "admin";
|
|
154
|
+
}>>;
|
|
155
|
+
is_admin: z.ZodBoolean;
|
|
156
|
+
created_at: z.ZodISODateTime;
|
|
157
|
+
last_used_at: z.ZodNullable<z.ZodISODateTime>;
|
|
158
|
+
expires_at: z.ZodNullable<z.ZodISODateTime>;
|
|
159
|
+
revoked_at: z.ZodNullable<z.ZodISODateTime>;
|
|
160
|
+
created_by: z.ZodNullable<z.ZodString>;
|
|
161
|
+
}, z.core.$strip>>;
|
|
162
|
+
}, z.core.$strip>;
|
|
163
|
+
export type ApiKeyList = z.infer<typeof ApiKeyListSchema>;
|
|
164
|
+
/** Public view of a tenant. */
|
|
165
|
+
export declare const TenantSchema: z.ZodObject<{
|
|
166
|
+
id: z.ZodUUID;
|
|
167
|
+
slug: z.ZodString;
|
|
168
|
+
name: z.ZodString;
|
|
169
|
+
is_active: z.ZodBoolean;
|
|
170
|
+
default_encryption: z.ZodEnum<{
|
|
171
|
+
none: "none";
|
|
172
|
+
tenant: "tenant";
|
|
173
|
+
keyring: "keyring";
|
|
174
|
+
caller: "caller";
|
|
175
|
+
}>;
|
|
176
|
+
created_at: z.ZodISODateTime;
|
|
177
|
+
}, z.core.$strip>;
|
|
178
|
+
export type Tenant = z.infer<typeof TenantSchema>;
|
|
179
|
+
//# sourceMappingURL=apikey.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"apikey.d.ts","sourceRoot":"","sources":["../src/apikey.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB,+EAA+E;AAC/E,eAAO,MAAM,QAAQ,oCAAqC,CAAC;AAC3D,eAAO,MAAM,YAAY;;;;EAAmB,CAAC;AAC7C,MAAM,MAAM,MAAM,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,YAAY,CAAC,CAAC;AAElD,eAAO,MAAM,YAAY,mDAAoD,CAAC;AAC9E,MAAM,MAAM,SAAS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wEAAwE;AACxE,eAAO,MAAM,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAcvB,CAAC;AACH,MAAM,MAAM,MAAM,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,YAAY,CAAC,CAAC;AAElD,sGAAsG;AACtG,eAAO,MAAM,kBAAkB;;;;;;;;;;;;;;;;;;;kBAK7B,CAAC;AACH,MAAM,MAAM,YAAY,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,kBAAkB,CAAC,CAAC;AAE9D,2EAA2E;AAC3E,eAAO,MAAM,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAA2C,CAAC;AAC5E,MAAM,MAAM,aAAa,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,mBAAmB,CAAC,CAAC;AAEhE,mBAAmB;AACnB,eAAO,MAAM,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAA4C,CAAC;AAC1E,MAAM,MAAM,UAAU,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,gBAAgB,CAAC,CAAC;AAE1D,+BAA+B;AAC/B,eAAO,MAAM,YAAY;;;;;;;;;;;;iBAQvB,CAAC;AACH,MAAM,MAAM,MAAM,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,YAAY,CAAC,CAAC"}
|
package/dist/apikey.js
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { ScopeSchema, TenantScopeSchema } from "./scopes.js";
|
|
3
|
+
/** Environments a key is minted for; the prefix of the key is `vola_<env>`. */
|
|
4
|
+
export const KEY_ENVS = ["live", "test", "admin"];
|
|
5
|
+
export const KeyEnvSchema = z.enum(KEY_ENVS);
|
|
6
|
+
export const KEY_PREFIXES = ["vola_live", "vola_test", "vola_admin"];
|
|
7
|
+
/** Length of the random, base62 part of a key. */
|
|
8
|
+
export const KEY_SECRET_LENGTH = 32;
|
|
9
|
+
const KEY_RE = /^(vola_(live|test|admin))_([A-Za-z0-9]{32})$/;
|
|
10
|
+
/** Splits a well-formed key `vola_<env>_<32 base62>` into its parts; `null` for anything else. */
|
|
11
|
+
export function parseApiKey(key) {
|
|
12
|
+
const match = KEY_RE.exec(key);
|
|
13
|
+
if (!match)
|
|
14
|
+
return null;
|
|
15
|
+
const secret = match[3];
|
|
16
|
+
return {
|
|
17
|
+
prefix: match[1],
|
|
18
|
+
env: match[2],
|
|
19
|
+
secret,
|
|
20
|
+
last4: secret.slice(-4),
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
/** How a stored key is shown to a person: `vola_live…k3Qz`. */
|
|
24
|
+
export function displayApiKey(prefix, last4) {
|
|
25
|
+
return `${prefix}…${last4}`;
|
|
26
|
+
}
|
|
27
|
+
/** Reads the key from `Authorization: Bearer <key>` or `X-Api-Key: <key>`. */
|
|
28
|
+
export function extractApiKey(headers) {
|
|
29
|
+
const first = (value) => (Array.isArray(value) ? value[0] : value);
|
|
30
|
+
const authorization = first(headers.authorization);
|
|
31
|
+
if (authorization) {
|
|
32
|
+
const match = /^Bearer\s+(\S+)\s*$/i.exec(authorization);
|
|
33
|
+
if (match)
|
|
34
|
+
return match[1];
|
|
35
|
+
}
|
|
36
|
+
const header = first(headers["x-api-key"])?.trim();
|
|
37
|
+
return header ? header : null;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Browsers cannot set headers on a WebSocket, so the key travels as a subprotocol:
|
|
41
|
+
* `bearer.<key>`. Offer `vola.v1` next to it and the server selects that one, so the key is
|
|
42
|
+
* never echoed back.
|
|
43
|
+
*/
|
|
44
|
+
export const BEARER_SUBPROTOCOL_PREFIX = "bearer.";
|
|
45
|
+
export const VOLA_SUBPROTOCOL = "vola.v1";
|
|
46
|
+
/** The subprotocols a WebSocket client offers: `[VOLA_SUBPROTOCOL, "bearer.<key>"]`. */
|
|
47
|
+
export function bearerSubprotocols(apiKey) {
|
|
48
|
+
return [VOLA_SUBPROTOCOL, `${BEARER_SUBPROTOCOL_PREFIX}${apiKey}`];
|
|
49
|
+
}
|
|
50
|
+
/** The API key in a `Sec-WebSocket-Protocol` header (`…, bearer.<key>, …`), or `null`. */
|
|
51
|
+
export function extractSubprotocolKey(header) {
|
|
52
|
+
const value = Array.isArray(header) ? header.join(",") : header;
|
|
53
|
+
if (!value)
|
|
54
|
+
return null;
|
|
55
|
+
for (const protocol of value.split(",")) {
|
|
56
|
+
const trimmed = protocol.trim();
|
|
57
|
+
if (trimmed.startsWith(BEARER_SUBPROTOCOL_PREFIX)) {
|
|
58
|
+
const key = trimmed.slice(BEARER_SUBPROTOCOL_PREFIX.length);
|
|
59
|
+
if (key)
|
|
60
|
+
return key;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
65
|
+
/** Headers of the auth contract. */
|
|
66
|
+
export const API_KEY_HEADER = "x-api-key";
|
|
67
|
+
export const TENANT_SLUG_HEADER = "x-tenant-slug";
|
|
68
|
+
export const USER_ID_HEADER = "x-user-id";
|
|
69
|
+
/** A tenant slug: lowercase letters, digits and dashes, 2–63 characters, not starting with `-`. */
|
|
70
|
+
export const SlugSchema = z
|
|
71
|
+
.string()
|
|
72
|
+
.regex(/^[a-z0-9][a-z0-9-]{1,62}$/, "2–63 lowercase letters, digits and dashes, e.g. acme");
|
|
73
|
+
/** `X-User-Id`: an opaque principal of the host application; ≤ 255 characters, none of them control characters. */
|
|
74
|
+
export const UserIdSchema = z
|
|
75
|
+
.string()
|
|
76
|
+
.min(1)
|
|
77
|
+
.max(255)
|
|
78
|
+
.refine((value) => !/\p{Cc}/u.test(value), { message: "must not contain control characters" });
|
|
79
|
+
export const TimestampSchema = z.iso.datetime({ offset: true });
|
|
80
|
+
/** Public view of a stored key: never the plaintext, never the hash. */
|
|
81
|
+
export const ApiKeySchema = z.object({
|
|
82
|
+
id: z.uuid(),
|
|
83
|
+
/** `null` for an admin key. */
|
|
84
|
+
tenant_id: z.uuid().nullable(),
|
|
85
|
+
name: z.string().min(1).max(200),
|
|
86
|
+
prefix: z.enum(KEY_PREFIXES),
|
|
87
|
+
last4: z.string().length(4),
|
|
88
|
+
scopes: z.array(ScopeSchema),
|
|
89
|
+
is_admin: z.boolean(),
|
|
90
|
+
created_at: TimestampSchema,
|
|
91
|
+
last_used_at: TimestampSchema.nullable(),
|
|
92
|
+
expires_at: TimestampSchema.nullable(),
|
|
93
|
+
revoked_at: TimestampSchema.nullable(),
|
|
94
|
+
created_by: z.string().nullable(),
|
|
95
|
+
});
|
|
96
|
+
/** `POST /keys`: a tenant key with a subset of the caller's scopes; the plaintext comes back once. */
|
|
97
|
+
export const ApiKeyCreateSchema = z.strictObject({
|
|
98
|
+
name: z.string().trim().min(1).max(200),
|
|
99
|
+
scopes: z.array(TenantScopeSchema).min(1),
|
|
100
|
+
env: z.enum(["live", "test"]),
|
|
101
|
+
expires_at: TimestampSchema.optional(),
|
|
102
|
+
});
|
|
103
|
+
/** `201` of `POST /keys`: the stored key plus its plaintext, this once. */
|
|
104
|
+
export const ApiKeyCreatedSchema = ApiKeySchema.extend({ key: z.string() });
|
|
105
|
+
/** `GET /keys`. */
|
|
106
|
+
export const ApiKeyListSchema = z.object({ keys: z.array(ApiKeySchema) });
|
|
107
|
+
/** Public view of a tenant. */
|
|
108
|
+
export const TenantSchema = z.object({
|
|
109
|
+
id: z.uuid(),
|
|
110
|
+
slug: SlugSchema,
|
|
111
|
+
name: z.string().min(1).max(200),
|
|
112
|
+
is_active: z.boolean(),
|
|
113
|
+
/** How an upload without an explicit `encryption` is stored: `none` (default), `tenant`, `keyring` or `caller`. */
|
|
114
|
+
default_encryption: z.enum(["none", "tenant", "keyring", "caller"]),
|
|
115
|
+
created_at: TimestampSchema,
|
|
116
|
+
});
|
|
117
|
+
//# sourceMappingURL=apikey.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"apikey.js","sourceRoot":"","sources":["../src/apikey.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,M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AAE,CAAC,CAAC,OAAO,EAAE;IACtB,mHAAmH;IACnH,kBAAkB,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,QAAQ,CAAC,CAAC;IACnE,UAAU,EAAE,eAAe;CAC5B,CAAC,CAAC"}
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/**
|
|
3
|
+
* The error envelope every vola route answers with: `{ error: { code, message, …details } }`.
|
|
4
|
+
* Codes are snake_case and stable (`not_found`, `unauthorized`, `forbidden`, …). A `forbidden`
|
|
5
|
+
* for a missing scope carries `required`: the scopes the key lacks.
|
|
6
|
+
*/
|
|
7
|
+
export declare const ErrorBodySchema: z.ZodObject<{
|
|
8
|
+
code: z.ZodString;
|
|
9
|
+
message: z.ZodString;
|
|
10
|
+
required: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
11
|
+
}, z.core.$strip>;
|
|
12
|
+
export declare const ErrorResponseSchema: z.ZodObject<{
|
|
13
|
+
error: z.ZodObject<{
|
|
14
|
+
code: z.ZodString;
|
|
15
|
+
message: z.ZodString;
|
|
16
|
+
required: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
17
|
+
}, z.core.$strip>;
|
|
18
|
+
}, z.core.$strip>;
|
|
19
|
+
export type ErrorBody = z.infer<typeof ErrorBodySchema>;
|
|
20
|
+
export type ErrorResponse = z.infer<typeof ErrorResponseSchema>;
|
|
21
|
+
/** Builds the error envelope; `details` are merged into `error` (`required`, …). */
|
|
22
|
+
export declare function errorResponse(code: string, message: string, details?: Record<string, unknown>): ErrorResponse;
|
|
23
|
+
/** Header a caller may set to correlate requests; the server echoes it (or its own UUID). */
|
|
24
|
+
export declare const REQUEST_ID_HEADER = "x-request-id";
|
|
25
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB;;;;GAIG;AACH,eAAO,MAAM,eAAe;;;;iBAI1B,CAAC;AAEH,eAAO,MAAM,mBAAmB;;;;;;iBAAuC,CAAC;AAExE,MAAM,MAAM,SAAS,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,eAAe,CAAC,CAAC;AACxD,MAAM,MAAM,aAAa,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,mBAAmB,CAAC,CAAC;AAEhE,oFAAoF;AACpF,wBAAgB,aAAa,CAC3B,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,EACf,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAChC,aAAa,CAEf;AAED,6FAA6F;AAC7F,eAAO,MAAM,iBAAiB,iBAAiB,CAAC"}
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/**
|
|
3
|
+
* The error envelope every vola route answers with: `{ error: { code, message, …details } }`.
|
|
4
|
+
* Codes are snake_case and stable (`not_found`, `unauthorized`, `forbidden`, …). A `forbidden`
|
|
5
|
+
* for a missing scope carries `required`: the scopes the key lacks.
|
|
6
|
+
*/
|
|
7
|
+
export const ErrorBodySchema = z.object({
|
|
8
|
+
code: z.string().regex(/^[a-z][a-z0-9_]*$/),
|
|
9
|
+
message: z.string(),
|
|
10
|
+
required: z.array(z.string()).optional(),
|
|
11
|
+
});
|
|
12
|
+
export const ErrorResponseSchema = z.object({ error: ErrorBodySchema });
|
|
13
|
+
/** Builds the error envelope; `details` are merged into `error` (`required`, …). */
|
|
14
|
+
export function errorResponse(code, message, details) {
|
|
15
|
+
return { error: { code, message, ...details } };
|
|
16
|
+
}
|
|
17
|
+
/** Header a caller may set to correlate requests; the server echoes it (or its own UUID). */
|
|
18
|
+
export const REQUEST_ID_HEADER = "x-request-id";
|
|
19
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB;;;;GAIG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,CAAC,MAAM,CAAC;IACtC,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,mBAAmB,CAAC;IAC3C,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE;IACnB,QAAQ,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,QAAQ,EAAE;CACzC,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,CAAC,MAAM,CAAC,EAAE,KAAK,EAAE,eAAe,EAAE,CAAC,CAAC;AAKxE,oFAAoF;AACpF,MAAM,UAAU,aAAa,CAC3B,IAAY,EACZ,OAAe,EACf,OAAiC;IAEjC,OAAO,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,OAAO,EAAE,EAAE,CAAC;AAClD,CAAC;AAED,6FAA6F;AAC7F,MAAM,CAAC,MAAM,iBAAiB,GAAG,cAAc,CAAC"}
|