@vol-a/core 0.0.0-stage → 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (63) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +34 -2
  3. package/dist/apikey.d.ts +175 -0
  4. package/dist/apikey.d.ts.map +1 -0
  5. package/dist/apikey.js +117 -0
  6. package/dist/apikey.js.map +1 -0
  7. package/dist/errors.d.ts +25 -0
  8. package/dist/errors.d.ts.map +1 -0
  9. package/dist/errors.js +19 -0
  10. package/dist/errors.js.map +1 -0
  11. package/dist/files.d.ts +265 -0
  12. package/dist/files.d.ts.map +1 -0
  13. package/dist/files.js +124 -0
  14. package/dist/files.js.map +1 -0
  15. package/dist/folders.d.ts +248 -0
  16. package/dist/folders.d.ts.map +1 -0
  17. package/dist/folders.js +157 -0
  18. package/dist/folders.js.map +1 -0
  19. package/dist/health.d.ts +33 -0
  20. package/dist/health.d.ts.map +1 -0
  21. package/dist/health.js +16 -0
  22. package/dist/health.js.map +1 -0
  23. package/dist/index.d.ts +15 -0
  24. package/dist/index.d.ts.map +1 -0
  25. package/dist/index.js +15 -0
  26. package/dist/index.js.map +1 -0
  27. package/dist/keyrings.d.ts +116 -0
  28. package/dist/keyrings.d.ts.map +1 -0
  29. package/dist/keyrings.js +103 -0
  30. package/dist/keyrings.js.map +1 -0
  31. package/dist/lookups.d.ts +62 -0
  32. package/dist/lookups.d.ts.map +1 -0
  33. package/dist/lookups.js +48 -0
  34. package/dist/lookups.js.map +1 -0
  35. package/dist/processing.d.ts +122 -0
  36. package/dist/processing.d.ts.map +1 -0
  37. package/dist/processing.js +142 -0
  38. package/dist/processing.js.map +1 -0
  39. package/dist/scopes.d.ts +40 -0
  40. package/dist/scopes.d.ts.map +1 -0
  41. package/dist/scopes.js +50 -0
  42. package/dist/scopes.js.map +1 -0
  43. package/dist/shares.d.ts +229 -0
  44. package/dist/shares.d.ts.map +1 -0
  45. package/dist/shares.js +153 -0
  46. package/dist/shares.js.map +1 -0
  47. package/dist/stats.d.ts +88 -0
  48. package/dist/stats.d.ts.map +1 -0
  49. package/dist/stats.js +61 -0
  50. package/dist/stats.js.map +1 -0
  51. package/dist/subscribe.d.ts +222 -0
  52. package/dist/subscribe.d.ts.map +1 -0
  53. package/dist/subscribe.js +118 -0
  54. package/dist/subscribe.js.map +1 -0
  55. package/dist/transfer.d.ts +50 -0
  56. package/dist/transfer.d.ts.map +1 -0
  57. package/dist/transfer.js +54 -0
  58. package/dist/transfer.js.map +1 -0
  59. package/dist/uploads.d.ts +56 -0
  60. package/dist/uploads.d.ts.map +1 -0
  61. package/dist/uploads.js +97 -0
  62. package/dist/uploads.js.map +1 -0
  63. 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
- # Temporary Holding Version
1
+ # @vol-a/core
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
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,175 @@
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
+ admin: "admin";
67
+ }>>;
68
+ is_admin: z.ZodBoolean;
69
+ created_at: z.ZodISODateTime;
70
+ last_used_at: z.ZodNullable<z.ZodISODateTime>;
71
+ expires_at: z.ZodNullable<z.ZodISODateTime>;
72
+ revoked_at: z.ZodNullable<z.ZodISODateTime>;
73
+ created_by: z.ZodNullable<z.ZodString>;
74
+ }, z.core.$strip>;
75
+ export type ApiKey = z.infer<typeof ApiKeySchema>;
76
+ /** `POST /keys`: a tenant key with a subset of the caller's scopes; the plaintext comes back once. */
77
+ export declare const ApiKeyCreateSchema: z.ZodObject<{
78
+ name: z.ZodString;
79
+ scopes: z.ZodArray<z.ZodEnum<{
80
+ "files:read": "files:read";
81
+ "files:write": "files:write";
82
+ "folders:read": "folders:read";
83
+ "folders:write": "folders:write";
84
+ "shares:write": "shares:write";
85
+ "keys:write": "keys:write";
86
+ "keyrings:write": "keyrings:write";
87
+ "encryption:caller": "encryption:caller";
88
+ admin: "admin";
89
+ }>>;
90
+ env: z.ZodEnum<{
91
+ live: "live";
92
+ test: "test";
93
+ }>;
94
+ expires_at: z.ZodOptional<z.ZodISODateTime>;
95
+ }, z.core.$strict>;
96
+ export type ApiKeyCreate = z.infer<typeof ApiKeyCreateSchema>;
97
+ /** `201` of `POST /keys`: the stored key plus its plaintext, this once. */
98
+ export declare const ApiKeyCreatedSchema: z.ZodObject<{
99
+ id: z.ZodUUID;
100
+ tenant_id: z.ZodNullable<z.ZodUUID>;
101
+ name: z.ZodString;
102
+ prefix: z.ZodEnum<{
103
+ vola_live: "vola_live";
104
+ vola_test: "vola_test";
105
+ vola_admin: "vola_admin";
106
+ }>;
107
+ last4: z.ZodString;
108
+ scopes: z.ZodArray<z.ZodEnum<{
109
+ "files:read": "files:read";
110
+ "files:write": "files:write";
111
+ "folders:read": "folders:read";
112
+ "folders:write": "folders:write";
113
+ "shares:write": "shares:write";
114
+ "keys:write": "keys:write";
115
+ "keyrings:write": "keyrings:write";
116
+ "encryption:caller": "encryption:caller";
117
+ admin: "admin";
118
+ }>>;
119
+ is_admin: z.ZodBoolean;
120
+ created_at: z.ZodISODateTime;
121
+ last_used_at: z.ZodNullable<z.ZodISODateTime>;
122
+ expires_at: z.ZodNullable<z.ZodISODateTime>;
123
+ revoked_at: z.ZodNullable<z.ZodISODateTime>;
124
+ created_by: z.ZodNullable<z.ZodString>;
125
+ key: z.ZodString;
126
+ }, z.core.$strip>;
127
+ export type ApiKeyCreated = z.infer<typeof ApiKeyCreatedSchema>;
128
+ /** `GET /keys`. */
129
+ export declare const ApiKeyListSchema: z.ZodObject<{
130
+ keys: z.ZodArray<z.ZodObject<{
131
+ id: z.ZodUUID;
132
+ tenant_id: z.ZodNullable<z.ZodUUID>;
133
+ name: z.ZodString;
134
+ prefix: z.ZodEnum<{
135
+ vola_live: "vola_live";
136
+ vola_test: "vola_test";
137
+ vola_admin: "vola_admin";
138
+ }>;
139
+ last4: z.ZodString;
140
+ scopes: z.ZodArray<z.ZodEnum<{
141
+ "files:read": "files:read";
142
+ "files:write": "files:write";
143
+ "folders:read": "folders:read";
144
+ "folders:write": "folders:write";
145
+ "shares:write": "shares:write";
146
+ "keys:write": "keys:write";
147
+ "keyrings:write": "keyrings:write";
148
+ "encryption:caller": "encryption:caller";
149
+ admin: "admin";
150
+ }>>;
151
+ is_admin: z.ZodBoolean;
152
+ created_at: z.ZodISODateTime;
153
+ last_used_at: z.ZodNullable<z.ZodISODateTime>;
154
+ expires_at: z.ZodNullable<z.ZodISODateTime>;
155
+ revoked_at: z.ZodNullable<z.ZodISODateTime>;
156
+ created_by: z.ZodNullable<z.ZodString>;
157
+ }, z.core.$strip>>;
158
+ }, z.core.$strip>;
159
+ export type ApiKeyList = z.infer<typeof ApiKeyListSchema>;
160
+ /** Public view of a tenant. */
161
+ export declare const TenantSchema: z.ZodObject<{
162
+ id: z.ZodUUID;
163
+ slug: z.ZodString;
164
+ name: z.ZodString;
165
+ is_active: z.ZodBoolean;
166
+ default_encryption: z.ZodEnum<{
167
+ none: "none";
168
+ tenant: "tenant";
169
+ keyring: "keyring";
170
+ caller: "caller";
171
+ }>;
172
+ created_at: z.ZodISODateTime;
173
+ }, z.core.$strip>;
174
+ export type Tenant = z.infer<typeof TenantSchema>;
175
+ //# 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,GAAG,CAAC,OAAO,YAAY,CAAC,CAAC,MAAM,CAAC,CAAC;AAEtD,kDAAkD;AAClD,eAAO,MAAM,iBAAiB,KAAK,CAAC;AAIpC,kGAAkG;AAClG,wBAAgB,WAAW,CACzB,GAAG,EAAE,MAAM,GACV;IAAE,MAAM,EAAE,SAAS,CAAC;IAAC,GAAG,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CAU1E;AAED,+DAA+D;AAC/D,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAEnE;AAED,8EAA8E;AAC9E,wBAAgB,aAAa,CAC3B,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,SAAS,CAAC,GACrD,MAAM,GAAG,IAAI,CASf;AAED;;;;GAIG;AACH,eAAO,MAAM,yBAAyB,YAAY,CAAC;AACnD,eAAO,MAAM,gBAAgB,YAAY,CAAC;AAE1C,wFAAwF;AACxF,w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AAM,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,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAE7D,+EAA+E;AAC/E,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAU,CAAC;AAC3D,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;AAG7C,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,WAAW,EAAE,WAAW,EA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AY,CAAC;IAC/C,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC;IACvC,MAAM,EAAE,CAAC,CAAC,KAAK,CAAC,iBAAiB,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;IACzC,GAAG,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC7B,UAAU,EAAE,eAAe,CAAC,QAAQ,EAAE;CACvC,CAAC,CAAC;AAGH,2EAA2E;AAC3E,MAAM,CAAC,MAAM,mBAAmB,GAAG,YAAY,CAAC,MAAM,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;AAG5E,mBAAmB;AACnB,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,KAAK,CAAC,YAAY,CAAC,EAAE,CAAC,CAAC;AAG1E,+BAA+B;AAC/B,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,CAAC,MAAM,CAAC;IACnC,EAAE,EAAE,CAAC,CAAC,IAAI,EAAE;IACZ,IAAI,EAAE,UAAU;IAChB,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC;IAChC,SAAS,EAAE,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"}
@@ -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"}