@qooal/vault 0.0.0-stage → 0.1.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/CHANGELOG.md +28 -0
- package/LICENSE +21 -0
- package/README.md +270 -2
- package/dist/chunks/chunk-2AAWIHQO.js +1028 -0
- package/dist/chunks/chunk-MKUYQFGG.js +90 -0
- package/dist/chunks/chunk-PEWIUW3U.js +484 -0
- package/dist/chunks/chunk-Z5XT6XS2.js +115 -0
- package/dist/index.js +24 -0
- package/dist/next.js +65 -0
- package/dist/react.js +259 -0
- package/dist/server.js +357 -0
- package/dist/sign.js +20 -0
- package/dist/types/http.d.ts +49 -0
- package/dist/types/index.d.ts +8 -0
- package/dist/types/next.d.ts +39 -0
- package/dist/types/react/index.d.ts +93 -0
- package/dist/types/react/props.d.ts +56 -0
- package/dist/types/server/client.d.ts +160 -0
- package/dist/types/server/index.d.ts +16 -0
- package/dist/types/server/sign-url.d.ts +28 -0
- package/dist/types/server/webhook.d.ts +31 -0
- package/dist/types/sign.d.ts +48 -0
- package/dist/types/types.d.ts +415 -0
- package/dist/types/upload/element.d.ts +45 -0
- package/dist/types/upload/index.d.ts +14 -0
- package/dist/types/upload/perform.d.ts +66 -0
- package/dist/types/upload/uploader.d.ts +62 -0
- package/dist/types/url.d.ts +163 -0
- package/dist/upload.js +28 -0
- package/dist/widget.js +34 -0
- package/package.json +82 -4
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.1.0 - 2026-12-06
|
|
4
|
+
|
|
5
|
+
First public release on npm.
|
|
6
|
+
|
|
7
|
+
- Entry points: `@qooal/vault` (delivery URLs and the wire types), `@qooal/vault/upload` (browser uploads and the
|
|
8
|
+
`<qooal-vault-uploader>` element), `@qooal/vault/react` (`VaultImage`, `VaultVideo`, `VaultUploader`),
|
|
9
|
+
`@qooal/vault/next` (a `next/image` loader), `@qooal/vault/server` (the API client, upload tickets, download links,
|
|
10
|
+
URL signing, webhook verification), `@qooal/vault/sign` (the signing functions) and `@qooal/vault/widget.js` (the
|
|
11
|
+
upload widget as a file).
|
|
12
|
+
- ESM builds with TypeScript declarations; `react` (19) and `hls.js` are optional peer dependencies.
|
|
13
|
+
|
|
14
|
+
Type fixes to match what the API sends:
|
|
15
|
+
|
|
16
|
+
- `importFromUrl` resolves to the upload instructions the API answers (202, `method: "url"`, the new type
|
|
17
|
+
`VaultUrlImportInstructions`), not a `VaultAsset`.
|
|
18
|
+
- `VaultUploadTicket` has the ticket's `id` (`vtkt_…`), for revoking it.
|
|
19
|
+
- A console test delivery marks the webhook event with `data.test`; `VaultWebhookEvent` no longer has a top-level
|
|
20
|
+
`test`.
|
|
21
|
+
- `VaultAsset.createdBy.kind` includes `"system"`.
|
|
22
|
+
- Webhook events carry a shortened asset, the new type `VaultWebhookAsset`; quota events also carry `percent` and
|
|
23
|
+
`cycleStart`.
|
|
24
|
+
- `VaultTransformPresetInput.eager` is required, as the API requires it; `updateTransformPreset` takes the new
|
|
25
|
+
`VaultTransformPresetPatch` (no `name`, which the API refuses).
|
|
26
|
+
- `VaultAssetPatch` drops `null` for `folderId`, `title` and `altText` (the API reads `null` as "no change"); `""`
|
|
27
|
+
moves to the root or clears.
|
|
28
|
+
- `VaultUploadPresetInput` has `allowedOrigins`, `ratePerMinute`, `monthlyCap`, `turnstile` and `moderation`.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Qooal
|
|
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,271 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @qooal/vault
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The JavaScript SDK for **Qooal Vault**: store the files a business has (product images, videos, PDFs, documents, archives, audio, 3D models, fonts, downloadable products) and deliver them from your own website. It builds delivery URLs with image transformations, signs private URLs, uploads from the browser (with a ready-made upload widget), renders images and video in React, plugs into `next/image`, and wraps the Vault API for your server.
|
|
4
|
+
|
|
5
|
+
Documentation: [qooal.com/docs/vault](https://qooal.com/docs/vault) · [Quickstart](https://qooal.com/docs/vault/quickstart) · [SDK guide](https://qooal.com/docs/vault/sdk) · [API reference](https://qooal.com/docs/vault/api)
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @qooal/vault
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
If you import `@qooal/vault/react`, also install `hls.js`:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npm install hls.js
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
`VaultVideo` loads it only when a browser has no native HLS (Safari plays HLS natively), but bundlers resolve that import at build time, so a React app that imports `@qooal/vault/react` without `hls.js` installed fails to build. `react` (19) and `hls.js` are optional peer dependencies: the other entry points need neither.
|
|
20
|
+
|
|
21
|
+
## Runtime support
|
|
22
|
+
|
|
23
|
+
- **Server:** Node 20 or later, and edge runtimes with WebCrypto and `fetch`.
|
|
24
|
+
- **Browser:** the upload widget (`widget.js`) is built for Chrome 111, Firefox 111 and Safari 16.4 or later. The ESM entry points are compiled to ES2023; bundle them for older targets.
|
|
25
|
+
- **ESM only.** Every import below except the widget ships with TypeScript declarations.
|
|
26
|
+
|
|
27
|
+
| Import | Runs in | What |
|
|
28
|
+
| ------------------------------------------ | ----------------------- | ---------------------------------------------------------------------------------------------------------- |
|
|
29
|
+
| `@qooal/vault` | anywhere | `vaultUrl`, `srcSet`, `parseTransformation`, `canonicalTransformation`, `parseVaultPath`, the wire types |
|
|
30
|
+
| `@qooal/vault/upload` | browser | `createUploader`, `performUpload`, `defineVaultUploader` (`<qooal-vault-uploader>`) |
|
|
31
|
+
| `@qooal/vault/react` | React 19 client | `VaultImage`, `VaultVideo`, `VaultUploader`, `vaultImageProps` |
|
|
32
|
+
| `@qooal/vault/next` | Next.js 16 | `vaultLoader`, `createVaultLoader` for `next/image` |
|
|
33
|
+
| `@qooal/vault/server` | Node 20+, edge runtimes | `createVaultClient`, `createUploadTicket`, `createDownloadLink`, `signVaultUrl`, `verifyWebhook` |
|
|
34
|
+
| `@qooal/vault/sign` | Node 20+, edge runtimes | the low-level signing functions (`signPath`, `verifyPath`, `signDownload`); also re-exported by `./server` |
|
|
35
|
+
| `@qooal/vault/widget.js` | any web page | the upload widget as a file in this package, for self-hosting or pinning a version |
|
|
36
|
+
| `https://upload.qooalcdn.com/v1/widget.js` | any web page | the upload widget, served by Vault: no build step |
|
|
37
|
+
|
|
38
|
+
Every key, ticket, token and secret below is a fake example. Never put an API key, a signing key or a webhook secret in a browser or in a repository.
|
|
39
|
+
|
|
40
|
+
## Delivery URLs
|
|
41
|
+
|
|
42
|
+
Every file has a URL; images take transformations in the path:
|
|
43
|
+
|
|
44
|
+
```text
|
|
45
|
+
https://media.qooalcdn.com/acme-shop/image/upload/c_fill,w_400,h_400,f_auto/products/mug
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
Build them in code. The result is always canonical:
|
|
49
|
+
|
|
50
|
+
```ts
|
|
51
|
+
import { vaultUrl } from "@qooal/vault";
|
|
52
|
+
|
|
53
|
+
const lib = "https://media.qooalcdn.com/acme-shop"; // a base URL including your library's slug
|
|
54
|
+
vaultUrl(lib, "products/mug", { transformation: "c_fill,w_400,h_400,f_auto" });
|
|
55
|
+
// → https://media.qooalcdn.com/acme-shop/image/upload/c_fill,w_400,h_400,f_auto/products/mug
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
Your library's base URLs are in the console and in `library.urls` from the API. Pass that object instead of a string and `vaultUrl` picks the right host for each kind of file:
|
|
59
|
+
|
|
60
|
+
```ts
|
|
61
|
+
vaultUrl(library, "launch/teaser", { resourceType: "video", format: "m3u8" });
|
|
62
|
+
vaultUrl(library, "downloads/lookbook", { resourceType: "raw", format: "pdf" });
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## Quickstart: the upload widget (script tag)
|
|
66
|
+
|
|
67
|
+
No build step: load the script and use the element. Files go straight from the browser to Vault, never through your server. The page gets an upload ticket from your backend (see [Server](#server)): give the element a `ticket-endpoint`, a URL on your site that answers a `POST` with `{"ticket": "vtk_…"}`.
|
|
68
|
+
|
|
69
|
+
```html
|
|
70
|
+
<script src="https://upload.qooalcdn.com/v1/widget.js" defer></script>
|
|
71
|
+
|
|
72
|
+
<qooal-vault-uploader library="acme-shop" ticket-endpoint="/api/vault-ticket" accept="image/*" multiple>
|
|
73
|
+
</qooal-vault-uploader>
|
|
74
|
+
|
|
75
|
+
<script>
|
|
76
|
+
document.querySelector("qooal-vault-uploader").addEventListener("vault-upload", (e) => {
|
|
77
|
+
console.log("uploaded", e.detail.asset.publicId);
|
|
78
|
+
});
|
|
79
|
+
</script>
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
`library` here is your library's slug. The element also takes `ticket`, or `preset` with `turnstile-sitekey` for an unsigned upload preset, plus `accept`, `multiple`, `max-files`, `max-bytes`, `folder-id`, `public-id`, `tags`, `theme`, `label`, `name`, `disabled`, `paste="global"`, `camera="off"` and `api-base`. Events: `vault-start`, `vault-progress`, `vault-upload`, `vault-error`, `vault-complete`. Style it with `--qv-accent`, `--qv-bg`, `--qv-fg`, `--qv-border`, `--qv-radius` (and more) or `::part(dropzone)`, `::part(button)`, `::part(list)`, `::part(item)`. A ticket's own folder and public ID win over the element's, its tags are added to them, and access is always the ticket's: set it with `createUploadTicket({ access })`. Details: [qooal.com/docs/vault/upload-widget](https://qooal.com/docs/vault/upload-widget).
|
|
83
|
+
|
|
84
|
+
In code, without the element:
|
|
85
|
+
|
|
86
|
+
```ts
|
|
87
|
+
import { createUploader } from "@qooal/vault/upload";
|
|
88
|
+
|
|
89
|
+
const uploader = createUploader({
|
|
90
|
+
library: "acme-shop",
|
|
91
|
+
ticket: async () => (await (await fetch("/api/vault-ticket", { method: "POST" })).json()).ticket,
|
|
92
|
+
});
|
|
93
|
+
const asset = await uploader.upload(file, { onProgress: ({ loaded, total }) => console.log(loaded / total) });
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
Large files go up in parts, each retried, and resume after a reload.
|
|
97
|
+
|
|
98
|
+
**Content Security Policy.** Direct uploads (single and in parts) go straight to your library's storage origin, `library.urls.storage` in the API, and some deliveries come from it too. If your site sends a `Content-Security-Policy`, allow that origin (for example `https://storage.example.com`; use your library's value) in `connect-src`, `media-src`, `font-src` and `frame-src`, besides the Vault hosts.
|
|
99
|
+
|
|
100
|
+
## Quickstart: React
|
|
101
|
+
|
|
102
|
+
```tsx
|
|
103
|
+
"use client";
|
|
104
|
+
import { VaultImage, VaultUploader, VaultVideo } from "@qooal/vault/react";
|
|
105
|
+
|
|
106
|
+
const lib = "https://media.qooalcdn.com/acme-shop";
|
|
107
|
+
|
|
108
|
+
export function Product() {
|
|
109
|
+
return (
|
|
110
|
+
<>
|
|
111
|
+
{/* a 1x and 2x srcset, lazy loading, a dominant-colour placeholder */}
|
|
112
|
+
<VaultImage
|
|
113
|
+
library={lib}
|
|
114
|
+
publicId="products/mug"
|
|
115
|
+
transformation="c_fill,ar_1:1"
|
|
116
|
+
width={400}
|
|
117
|
+
height={400}
|
|
118
|
+
alt="Speckled stoneware mug"
|
|
119
|
+
/>
|
|
120
|
+
|
|
121
|
+
{/* native HLS on Safari, hls.js elsewhere, the MP4 as a last resort */}
|
|
122
|
+
<VaultVideo
|
|
123
|
+
library={{ urls: { media: lib, video: "https://video.qooalcdn.com/acme-shop" } }}
|
|
124
|
+
publicId="launch/teaser"
|
|
125
|
+
/>
|
|
126
|
+
|
|
127
|
+
{/* the upload widget; your backend route answers {"ticket": "vtk_…"} */}
|
|
128
|
+
<VaultUploader
|
|
129
|
+
library="acme-shop"
|
|
130
|
+
ticketEndpoint="/api/vault-ticket"
|
|
131
|
+
accept="image/*"
|
|
132
|
+
multiple
|
|
133
|
+
onUpload={(asset) => console.log("uploaded", asset.publicId)}
|
|
134
|
+
/>
|
|
135
|
+
</>
|
|
136
|
+
);
|
|
137
|
+
}
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
`library` on `VaultImage` and `VaultVideo` is a base URL including the slug, or `library.urls` from the API; on `VaultUploader` it is the slug. `VaultImage` also takes an `asset` from the API (it fills the public ID, version, colour, alt text and the aspect ratio); pass `priority` for an image above the fold.
|
|
141
|
+
|
|
142
|
+
## Quickstart: Next.js
|
|
143
|
+
|
|
144
|
+
Let Vault resize images for `next/image`:
|
|
145
|
+
|
|
146
|
+
```ts
|
|
147
|
+
// next.config.ts
|
|
148
|
+
import type { NextConfig } from "next";
|
|
149
|
+
|
|
150
|
+
const config: NextConfig = {
|
|
151
|
+
images: { loader: "custom", loaderFile: "./vault-loader.ts" },
|
|
152
|
+
};
|
|
153
|
+
export default config;
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
```ts
|
|
157
|
+
// vault-loader.ts
|
|
158
|
+
export { vaultLoader as default } from "@qooal/vault/next";
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
```tsx
|
|
162
|
+
<Image
|
|
163
|
+
src="https://media.qooalcdn.com/acme-shop/image/upload/products/mug"
|
|
164
|
+
width={800}
|
|
165
|
+
height={800}
|
|
166
|
+
alt="Speckled stoneware mug"
|
|
167
|
+
/>;
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
The loader sets the width Next asks for, adds `f_auto` unless a format is fixed, and maps `quality` to `q_<n>` (Next's default 75 keeps `q_auto`). For bare public IDs (`src="products/mug"`), export `createVaultLoader({ library: "https://media.qooalcdn.com/acme-shop" })` instead.
|
|
171
|
+
|
|
172
|
+
The upload ticket route the widget calls:
|
|
173
|
+
|
|
174
|
+
```ts
|
|
175
|
+
// app/api/vault-ticket/route.ts
|
|
176
|
+
import { createUploadTicket } from "@qooal/vault/server";
|
|
177
|
+
|
|
178
|
+
export async function POST() {
|
|
179
|
+
// Check your own session first: hand tickets only to signed-in users.
|
|
180
|
+
const { ticket, expiresAt } = await createUploadTicket(process.env.QOOAL_API_KEY ?? "", "acme-shop", {
|
|
181
|
+
allowedClasses: ["image"],
|
|
182
|
+
maxFiles: 10,
|
|
183
|
+
expiresInSeconds: 900,
|
|
184
|
+
});
|
|
185
|
+
return Response.json({ ticket, expiresAt });
|
|
186
|
+
}
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
`QOOAL_API_KEY` is a Qooal API key with `vault:write`; it never leaves your server.
|
|
190
|
+
|
|
191
|
+
## Server
|
|
192
|
+
|
|
193
|
+
The API client covers the public Vault API:
|
|
194
|
+
|
|
195
|
+
```ts
|
|
196
|
+
import { createVaultClient } from "@qooal/vault/server";
|
|
197
|
+
|
|
198
|
+
const vault = createVaultClient({ apiKey: process.env.QOOAL_API_KEY ?? "" });
|
|
199
|
+
const page = await vault.listAssets("acme-shop", { q: "mug", type: ["image"], limit: 20 });
|
|
200
|
+
const asset = await vault.lookupAsset("acme-shop", "image", "products/mug");
|
|
201
|
+
await vault.updateAsset("acme-shop", asset.id, { altText: "Speckled stoneware mug", tags: ["kitchen"] });
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
Every call the API requires an `Idempotency-Key` on (most creates and actions) sends one, generated unless you pass `idempotencyKey`, so retries are safe; `signUrl` and `allowTransform` take none.
|
|
205
|
+
|
|
206
|
+
Sign a URL for a `private` or `authenticated` file with the library's signing key (shown once in the console):
|
|
207
|
+
|
|
208
|
+
```ts
|
|
209
|
+
import { signVaultUrl } from "@qooal/vault/server";
|
|
210
|
+
|
|
211
|
+
const key = { version: 1, key: process.env.QOOAL_VAULT_SIGNING_KEY ?? "" }; // base64url, 32 bytes
|
|
212
|
+
const url = await signVaultUrl(
|
|
213
|
+
"https://media.qooalcdn.com/acme-shop/image/authenticated/c_fill,w_800,h_800/v3/members/poster.jpg",
|
|
214
|
+
key,
|
|
215
|
+
{ expiresAt: new Date(Date.now() + 60 * 60 * 1000) }, // one hour
|
|
216
|
+
);
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
Verify a webhook against the raw body:
|
|
220
|
+
|
|
221
|
+
```ts
|
|
222
|
+
import { verifyWebhook } from "@qooal/vault/server";
|
|
223
|
+
|
|
224
|
+
// app/api/vault-webhook/route.ts
|
|
225
|
+
export async function POST(req: Request) {
|
|
226
|
+
const body = await req.text(); // the raw body, before any JSON parsing
|
|
227
|
+
try {
|
|
228
|
+
const event = await verifyWebhook(body, req.headers, process.env.QOOAL_VAULT_WEBHOOK_SECRET ?? "");
|
|
229
|
+
if (event.type === "vault.asset.ready") {
|
|
230
|
+
// event.data.asset is a shortened asset (VaultWebhookAsset); req.headers.get("webhook-id") identifies the event across retries
|
|
231
|
+
}
|
|
232
|
+
return new Response(null, { status: 204 });
|
|
233
|
+
} catch {
|
|
234
|
+
return new Response("invalid signature", { status: 400 });
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
Sell a digital download with an expiring link:
|
|
240
|
+
|
|
241
|
+
```ts
|
|
242
|
+
import { createDownloadLink } from "@qooal/vault/server";
|
|
243
|
+
|
|
244
|
+
const { url } = await createDownloadLink(
|
|
245
|
+
process.env.QOOAL_API_KEY ?? "",
|
|
246
|
+
"acme-shop",
|
|
247
|
+
"vast_01jt8x5e2q9c6w3k7m4n5p6r7s",
|
|
248
|
+
{ expiresInSeconds: 7 * 24 * 3600, maxDownloads: 3, label: "Order 1042" },
|
|
249
|
+
{ idempotencyKey: "order-1042" },
|
|
250
|
+
);
|
|
251
|
+
// `url` is shown once: email it to the buyer.
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
## Errors
|
|
255
|
+
|
|
256
|
+
API calls reject with `VaultApiError`:
|
|
257
|
+
|
|
258
|
+
| Field | Meaning |
|
|
259
|
+
| ------------ | --------------------------------------------------------------------------------------------------------- |
|
|
260
|
+
| `status` | the HTTP status; `0` when no answer arrived (network failure) |
|
|
261
|
+
| `code` | the problem's `code`, for example `forbidden` |
|
|
262
|
+
| `reason` | Vault's finer reason, for example `storage_quota_exceeded`, or `null` |
|
|
263
|
+
| `errors` | field errors `{ pointer, code, message? }`: `message` is the API's `detail`; `code` is always `"invalid"` |
|
|
264
|
+
| `requestId` | the request's ID, or `null`; quote it when you contact support |
|
|
265
|
+
| `retryAfter` | seconds from `Retry-After`, or `null` |
|
|
266
|
+
|
|
267
|
+
URL helpers throw `VaultGrammarError` (with a `code`, from `@qooal/vault`) for a URL Vault would refuse, and `verifyWebhook` throws `VaultWebhookError`. Error reference: [qooal.com/docs/vault/errors](https://qooal.com/docs/vault/errors).
|
|
268
|
+
|
|
269
|
+
## License
|
|
270
|
+
|
|
271
|
+
[MIT](./LICENSE)
|