@softure-ai/files 0.0.0-stage → 0.1.2
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 +26 -0
- package/LICENSE +21 -0
- package/README.md +213 -2
- package/dist/contract.d.ts +51 -0
- package/dist/contract.d.ts.map +1 -0
- package/dist/contract.js +4 -0
- package/dist/contract.js.map +1 -0
- package/dist/index.d.ts +45 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +49 -0
- package/dist/index.js.map +1 -0
- package/dist/jobs/index.d.ts +12 -0
- package/dist/jobs/index.d.ts.map +1 -0
- package/dist/jobs/index.js +22 -0
- package/dist/jobs/index.js.map +1 -0
- package/dist/messages/en.d.ts +17 -0
- package/dist/messages/en.d.ts.map +1 -0
- package/dist/messages/en.js +17 -0
- package/dist/messages/en.js.map +1 -0
- package/dist/messages/index.d.ts +24 -0
- package/dist/messages/index.d.ts.map +1 -0
- package/dist/messages/index.js +10 -0
- package/dist/messages/index.js.map +1 -0
- package/dist/next/context.d.ts +4 -0
- package/dist/next/context.d.ts.map +1 -0
- package/dist/next/context.js +13 -0
- package/dist/next/context.js.map +1 -0
- package/dist/next/index.d.ts +3 -0
- package/dist/next/index.d.ts.map +1 -0
- package/dist/next/index.js +5 -0
- package/dist/next/index.js.map +1 -0
- package/dist/next/route.d.ts +3 -0
- package/dist/next/route.d.ts.map +1 -0
- package/dist/next/route.js +11 -0
- package/dist/next/route.js.map +1 -0
- package/dist/options.d.ts +26 -0
- package/dist/options.d.ts.map +1 -0
- package/dist/options.js +59 -0
- package/dist/options.js.map +1 -0
- package/dist/schema.d.ts +214 -0
- package/dist/schema.d.ts.map +1 -0
- package/dist/schema.js +19 -0
- package/dist/schema.js.map +1 -0
- package/dist/server/context.d.ts +13 -0
- package/dist/server/context.d.ts.map +1 -0
- package/dist/server/context.js +19 -0
- package/dist/server/context.js.map +1 -0
- package/dist/server/files.d.ts +48 -0
- package/dist/server/files.d.ts.map +1 -0
- package/dist/server/files.js +104 -0
- package/dist/server/files.js.map +1 -0
- package/dist/server/health.d.ts +4 -0
- package/dist/server/health.d.ts.map +1 -0
- package/dist/server/health.js +20 -0
- package/dist/server/health.js.map +1 -0
- package/dist/server/index.d.ts +15 -0
- package/dist/server/index.d.ts.map +1 -0
- package/dist/server/index.js +17 -0
- package/dist/server/index.js.map +1 -0
- package/dist/server/keys.d.ts +14 -0
- package/dist/server/keys.d.ts.map +1 -0
- package/dist/server/keys.js +47 -0
- package/dist/server/keys.js.map +1 -0
- package/dist/server/links.d.ts +30 -0
- package/dist/server/links.d.ts.map +1 -0
- package/dist/server/links.js +122 -0
- package/dist/server/links.js.map +1 -0
- package/dist/server/local-storage.d.ts +7 -0
- package/dist/server/local-storage.d.ts.map +1 -0
- package/dist/server/local-storage.js +83 -0
- package/dist/server/local-storage.js.map +1 -0
- package/dist/server/names.d.ts +11 -0
- package/dist/server/names.d.ts.map +1 -0
- package/dist/server/names.js +32 -0
- package/dist/server/names.js.map +1 -0
- package/dist/server/options.d.ts +8 -0
- package/dist/server/options.d.ts.map +1 -0
- package/dist/server/options.js +31 -0
- package/dist/server/options.js.map +1 -0
- package/dist/server/privacy.d.ts +16 -0
- package/dist/server/privacy.d.ts.map +1 -0
- package/dist/server/privacy.js +39 -0
- package/dist/server/privacy.js.map +1 -0
- package/dist/server/prune.d.ts +13 -0
- package/dist/server/prune.d.ts.map +1 -0
- package/dist/server/prune.js +34 -0
- package/dist/server/prune.js.map +1 -0
- package/dist/server/queries.d.ts +7 -0
- package/dist/server/queries.d.ts.map +1 -0
- package/dist/server/queries.js +17 -0
- package/dist/server/queries.js.map +1 -0
- package/dist/server/s3-storage.d.ts +33 -0
- package/dist/server/s3-storage.d.ts.map +1 -0
- package/dist/server/s3-storage.js +223 -0
- package/dist/server/s3-storage.js.map +1 -0
- package/dist/server/save.d.ts +29 -0
- package/dist/server/save.d.ts.map +1 -0
- package/dist/server/save.js +141 -0
- package/dist/server/save.js.map +1 -0
- package/dist/server/serve.d.ts +11 -0
- package/dist/server/serve.d.ts.map +1 -0
- package/dist/server/serve.js +108 -0
- package/dist/server/serve.js.map +1 -0
- package/dist/server/sigv4.d.ts +23 -0
- package/dist/server/sigv4.d.ts.map +1 -0
- package/dist/server/sigv4.js +57 -0
- package/dist/server/sigv4.js.map +1 -0
- package/dist/storage.d.ts +32 -0
- package/dist/storage.d.ts.map +1 -0
- package/dist/storage.js +10 -0
- package/dist/storage.js.map +1 -0
- package/dist/testing/index.d.ts +3 -0
- package/dist/testing/index.d.ts.map +1 -0
- package/dist/testing/index.js +4 -0
- package/dist/testing/index.js.map +1 -0
- package/dist/testing/links.d.ts +22 -0
- package/dist/testing/links.d.ts.map +1 -0
- package/dist/testing/links.js +30 -0
- package/dist/testing/links.js.map +1 -0
- package/dist/testing/memory-storage.d.ts +11 -0
- package/dist/testing/memory-storage.d.ts.map +1 -0
- package/dist/testing/memory-storage.js +52 -0
- package/dist/testing/memory-storage.js.map +1 -0
- package/migrations/0001_create_files.sql +32 -0
- package/module.json +24 -0
- package/package.json +72 -4
- package/src/contract.ts +59 -0
- package/src/index.ts +53 -0
- package/src/jobs/index.ts +23 -0
- package/src/messages/en.ts +16 -0
- package/src/messages/index.ts +13 -0
- package/src/next/context.ts +14 -0
- package/src/next/index.ts +4 -0
- package/src/next/route.ts +11 -0
- package/src/options.ts +64 -0
- package/src/schema.ts +22 -0
- package/src/server/context.ts +32 -0
- package/src/server/files.ts +133 -0
- package/src/server/health.ts +20 -0
- package/src/server/index.ts +45 -0
- package/src/server/keys.ts +56 -0
- package/src/server/links.ts +152 -0
- package/src/server/local-storage.ts +87 -0
- package/src/server/names.ts +35 -0
- package/src/server/options.ts +34 -0
- package/src/server/privacy.ts +53 -0
- package/src/server/prune.ts +46 -0
- package/src/server/queries.ts +19 -0
- package/src/server/s3-storage.ts +255 -0
- package/src/server/save.ts +167 -0
- package/src/server/serve.ts +106 -0
- package/src/server/sigv4.ts +82 -0
- package/src/storage.ts +43 -0
- package/src/testing/index.ts +3 -0
- package/src/testing/links.ts +47 -0
- package/src/testing/memory-storage.ts +64 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
Newest first. Each version lists what changed for an app that uses `@softure-ai/files`. When an app has run a version
|
|
4
|
+
in production, the version gets a line `verified in: <app>@<commit>` ([docs/05](../../docs/05-adoption-playbook.md),
|
|
5
|
+
"Definition of done").
|
|
6
|
+
|
|
7
|
+
## 0.1.2
|
|
8
|
+
|
|
9
|
+
- No code change: the first release through the package's npm trusted publisher (OIDC), without `NPM_TOKEN`.
|
|
10
|
+
|
|
11
|
+
## 0.1.1
|
|
12
|
+
|
|
13
|
+
- The content of 0.1.0, which was never published: its release stopped at the gates (ESLint ran out of memory in
|
|
14
|
+
`release.yml`) before publishing, and a tag is never moved.
|
|
15
|
+
|
|
16
|
+
## 0.1.0
|
|
17
|
+
|
|
18
|
+
- First version (#888): the module `files` with the table `files.files` (owner, SHA-256, size, content type,
|
|
19
|
+
sanitised name, kind, expiry, soft delete, link generation); `saveFile` from a stream or a path, hashed and counted
|
|
20
|
+
while written, never buffered, with `maxFileBytes`, a per-owner quota under an advisory lock and opt-in dedupe;
|
|
21
|
+
`findFile`, `openFile` (byte ranges), `listFiles`, `deleteFile`, `getOwnerUsage`; storage drivers
|
|
22
|
+
`createLocalStorage` (atomic rename, free space for the health check) and `createS3Storage` (SigV4, multipart
|
|
23
|
+
uploads; R2, MinIO, Garage, AWS); public links `createFileLink` / `revokeFileLinks` signed with
|
|
24
|
+
`SOFTURE_FILES_LINK_KEYS`, served by `serveFileLinkRoute` (`GET`, `HEAD`, `206` and `416`, `Content-Disposition`,
|
|
25
|
+
`Cache-Control: private, no-store`, one `404` for every dead link); `pruneFiles` and the hourly `files.prune` job;
|
|
26
|
+
a privacy contributor; a health check; `/testing` with an in-memory driver and link checks.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 SOFTURE
|
|
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,214 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @softure-ai/files
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Stored files for a Next.js app that takes uploads or produces media (rendered videos, exports, reports), and public
|
|
4
|
+
links that hand one of them to a third party: a social media scheduler that fetches media from a URL, a mail with a
|
|
5
|
+
large download, a webhook consumer. The module keeps one table, puts the bytes on a storage driver (a folder on a
|
|
6
|
+
volume, or an S3-compatible bucket), and serves links that work without the app's session, serve byte ranges for
|
|
7
|
+
video and stop working after their time.
|
|
8
|
+
|
|
9
|
+
## 1. What it provides
|
|
10
|
+
|
|
11
|
+
- **A table of files** (`files.files`): owner, SHA-256, size, content type, sanitised original name, kind (the app's
|
|
12
|
+
own category, e.g. `input`, `output`), expiry, soft delete.
|
|
13
|
+
- **`saveFile(ctx, { ownerId, body | path, name, contentType?, kind?, expiresAt? | ttlSeconds? })`**: the body is
|
|
14
|
+
hashed and counted while it streams into storage, one chunk in memory at a time; `maxFileBytes` stops it at the
|
|
15
|
+
first chunk over, a per-owner quota (`quotaBytesPerOwner`) is checked before and again under a per-owner lock
|
|
16
|
+
after, and with `dedupe` an owner's second copy of the same content answers the first file. A refused or failed
|
|
17
|
+
save leaves no bytes and no row.
|
|
18
|
+
- **`findFile`, `openFile` (a byte range or the whole file), `listFiles`, `deleteFile`, `getOwnerUsage`**: live files
|
|
19
|
+
only (neither deleted nor expired); an `ownerId` filter makes another owner's file read as missing.
|
|
20
|
+
- **Storage drivers** behind one interface (`put`, `get` with a range, `head`, `delete`, an optional `check`):
|
|
21
|
+
`createLocalStorage({ dir })` (partial file renamed into place, keys fanned out by file id) and
|
|
22
|
+
`createS3Storage({ endpoint, bucket, ... })` for Cloudflare R2, MinIO, Garage or AWS S3 (SigV4 with `node:crypto`,
|
|
23
|
+
single `PUT` or a multipart upload that holds one part in memory). Write your own for anything else.
|
|
24
|
+
- **Public links**: `createFileLink(ctx, fileId, { ttlSeconds, downloadName? })` answers
|
|
25
|
+
`https://<app>/f/<id>/<expiry>/<generation>.<mac>/<name>`, an HMAC-SHA256 over every part. The route
|
|
26
|
+
(`serveFileLinkRoute`) checks the MAC and the expiry before any database read, answers `GET` and `HEAD` with
|
|
27
|
+
`Content-Length`, `Accept-Ranges`, `206` for a range, `416` past the end, `Content-Disposition`, and
|
|
28
|
+
`Cache-Control: private, no-store` (no CDN keeps a copy), and the same `404` for an expired, revoked, deleted or
|
|
29
|
+
forged link. `revokeFileLinks(ctx, fileId)` stops every link made so far.
|
|
30
|
+
- **Retention**: `pruneFiles(ctx)` removes expired and deleted files from storage and the table; the `files.prune`
|
|
31
|
+
job (`@softure-ai/files/jobs`) runs it hourly.
|
|
32
|
+
- **A privacy contributor** (the export lists the owner's files, the deletion removes them) and **a health check**
|
|
33
|
+
(the table answers, storage takes a write, free space above `health.minFreeBytes`).
|
|
34
|
+
- **`/testing`**: an in-memory driver, a fixed link keyring, `fetchFileLink` (status, headers and bytes of a link,
|
|
35
|
+
with a range or `HEAD`) and `readFileLinkExpiry`.
|
|
36
|
+
|
|
37
|
+
## 2. Installation
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
npm install @softure-ai/files
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
`@softure-ai/jobs` is an optional peer, needed only for the prune schedule.
|
|
44
|
+
|
|
45
|
+
## 3. Configuration
|
|
46
|
+
|
|
47
|
+
```ts
|
|
48
|
+
// softure.config.ts
|
|
49
|
+
import { files } from "@softure-ai/files";
|
|
50
|
+
import { createLocalStorage } from "@softure-ai/files/server";
|
|
51
|
+
|
|
52
|
+
files({
|
|
53
|
+
storage: createLocalStorage({ dir: "/data/files" }),
|
|
54
|
+
maxFileBytes: 500 * 1024 ** 2,
|
|
55
|
+
quotaBytesPerOwner: 5 * 1024 ** 3,
|
|
56
|
+
dedupe: true,
|
|
57
|
+
});
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
| Option | Default | Meaning |
|
|
61
|
+
| --- | --- | --- |
|
|
62
|
+
| `storage` | (required) | the driver: `createLocalStorage`, `createS3Storage`, `createMemoryStorage` (tests) or your own `FileStorage` |
|
|
63
|
+
| `maxFileBytes` | 100 MiB | the largest file `saveFile` accepts (`files.too_large` above it) |
|
|
64
|
+
| `quotaBytesPerOwner` | `null` (none) | the bytes one owner may keep in live files (`files.quota_exceeded`) |
|
|
65
|
+
| `dedupe` | `false` | an owner's save of content they already have (same SHA-256) answers the existing file |
|
|
66
|
+
| `defaultTtlSeconds` | `null` (kept) | the lifetime of a file saved without `expiresAt` or `ttlSeconds` |
|
|
67
|
+
| `links.maxTtlSeconds` | 7 days | the longest lifetime `createFileLink` grants |
|
|
68
|
+
| `links.disposition` | `attachment` | `attachment` (a download) or `inline` (shown by the browser) |
|
|
69
|
+
| `health.minFreeBytes` | 1 GiB | the health check fails below this many free bytes (local disk only) |
|
|
70
|
+
| `routes.links` | `/f` | the link route's prefix; mount the route under the same folder |
|
|
71
|
+
|
|
72
|
+
Building a driver touches neither the disk nor the network, so `next build` runs without the folder or the bucket's
|
|
73
|
+
keys.
|
|
74
|
+
|
|
75
|
+
An S3-compatible bucket instead of the disk:
|
|
76
|
+
|
|
77
|
+
```ts
|
|
78
|
+
import { createS3Storage } from "@softure-ai/files/server";
|
|
79
|
+
|
|
80
|
+
files({
|
|
81
|
+
storage: createS3Storage({
|
|
82
|
+
endpoint: "https://<account>.r2.cloudflarestorage.com", // http://localhost:9000 for MinIO in development
|
|
83
|
+
bucket: "app-files",
|
|
84
|
+
region: "auto", // R2; the bucket's region elsewhere (MinIO and Garage default to us-east-1)
|
|
85
|
+
prefix: "files/", // optional folder in the bucket
|
|
86
|
+
// accessKeyIdEnv / secretAccessKeyEnv rename the two variables of §6.
|
|
87
|
+
}),
|
|
88
|
+
});
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
A multipart upload left behind by a crashed process is aborted by the driver when it can; give the bucket a lifecycle
|
|
92
|
+
rule that aborts incomplete multipart uploads after a day for the rest.
|
|
93
|
+
|
|
94
|
+
## 4. Mounting
|
|
95
|
+
|
|
96
|
+
One route handler, the public links:
|
|
97
|
+
|
|
98
|
+
```ts
|
|
99
|
+
// app/f/[...link]/route.ts
|
|
100
|
+
export { serveFileLinkRoute as GET, serveFileLinkRoute as HEAD } from "@softure-ai/files/next";
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
**The route has no session and must stay reachable without one.** A link is protected by its signature, so:
|
|
104
|
+
|
|
105
|
+
- keep `/f` out of the app's own sign-in guard (`createAuthGuard(config, { protect: [...] })` of `@softure-ai/auth`
|
|
106
|
+
guards only the prefixes it lists; do not list `/f` or `/`);
|
|
107
|
+
- behind an edge sign-in such as **Cloudflare Access** on every path, add a bypass for the prefix: with
|
|
108
|
+
`@softure-ai/host`, `apps[].access.bypassPaths: [/f]` creates the Access application `<slug> bypass /f`; by hand,
|
|
109
|
+
a second Access application for `<host>/f` with a Bypass policy for everyone;
|
|
110
|
+
- never cache it at the edge: the answer says `private, no-store`, and a cache rule that overrides origin headers
|
|
111
|
+
must exclude `/f`.
|
|
112
|
+
|
|
113
|
+
Server code calls the functions with a context: `getFilesContext()` from `/next` in a route or action, or any
|
|
114
|
+
`{ db, clock, config }` in a worker.
|
|
115
|
+
|
|
116
|
+
```ts
|
|
117
|
+
import { getFilesContext } from "@softure-ai/files/next";
|
|
118
|
+
import { createFileLink, saveFile } from "@softure-ai/files/server";
|
|
119
|
+
|
|
120
|
+
const ctx = await getFilesContext();
|
|
121
|
+
const saved = await saveFile(ctx, { ownerId: user.id, path: renderedPath, name: "promo.mp4", contentType: "video/mp4", kind: "output", ttlSeconds: 7 * 86_400 });
|
|
122
|
+
if (!saved.ok) return saved; // files.too_large, files.quota_exceeded, files.invalid_input
|
|
123
|
+
const link = await createFileLink(ctx, saved.value.id, { ttlSeconds: 86_400 });
|
|
124
|
+
// link.value.url goes to the scheduler; link.value.expiresAt says until when it works.
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
A request body streams in directly: `saveFile(ctx, { ownerId, body: request.body, name, contentType })` (a web
|
|
128
|
+
`ReadableStream` is an async iterable in Node 22).
|
|
129
|
+
|
|
130
|
+
## 5. Migrations and tables
|
|
131
|
+
|
|
132
|
+
Schema `files`, migration `0001_create_files.sql`, table `files`:
|
|
133
|
+
|
|
134
|
+
| Column | Meaning |
|
|
135
|
+
| --- | --- |
|
|
136
|
+
| `id` | uuid, made by `saveFile` (the storage key is derived from it: `ab/cd/<uuid>`) |
|
|
137
|
+
| `owner_id` | the owner's account id, 1 to 200 characters, no foreign key |
|
|
138
|
+
| `sha256`, `size` | lowercase hex SHA-256 and byte count of the content |
|
|
139
|
+
| `content_type` | a media type with optional parameters, type and subtype lowercased |
|
|
140
|
+
| `original_name` | the sanitised name: last path part, no control characters, at most 255 characters |
|
|
141
|
+
| `kind` | the app's category, `^[a-z][a-z0-9_-]{0,31}$`, `file` by default |
|
|
142
|
+
| `storage_key` | where the bytes are, unique |
|
|
143
|
+
| `link_generation` | bumped by `revokeFileLinks`; a link carries the generation it was made for |
|
|
144
|
+
| `expires_at`, `deleted_at`, `created_at` | a file is live while `deleted_at` is null and `expires_at` is null or ahead |
|
|
145
|
+
|
|
146
|
+
A deleted or expired file keeps its row until `pruneFiles` has removed its bytes. Rollback: drop the table and its
|
|
147
|
+
`softure.migrations` row (the migration's header has the statements); the objects in storage stay.
|
|
148
|
+
|
|
149
|
+
## 6. Environment variables
|
|
150
|
+
|
|
151
|
+
| Variable | Required | Meaning |
|
|
152
|
+
| --- | --- | --- |
|
|
153
|
+
| `SOFTURE_FILES_LINK_KEYS` | for links | the signing keyring, `<id>:<base64 of 32 bytes>[,<id>:<key>…]`: the first key signs, every key verifies. `generateFilesLinkKey()` (from `/server`) prints a new entry. Rotate by putting a new key first and dropping the old one after `links.maxTtlSeconds`. Without it, `createFileLink` answers `files.link_key_missing` and the route answers `404` (and logs the code). |
|
|
154
|
+
| `SOFTURE_FILES_S3_ACCESS_KEY_ID`, `SOFTURE_FILES_S3_SECRET_ACCESS_KEY` | with `createS3Storage` | the bucket's access keys, read on each request (renamed with `accessKeyIdEnv` / `secretAccessKeyEnv`) |
|
|
155
|
+
|
|
156
|
+
## 7. Switches
|
|
157
|
+
|
|
158
|
+
None.
|
|
159
|
+
|
|
160
|
+
## 8. Appearance
|
|
161
|
+
|
|
162
|
+
None: the module has no UI. A file browser is out of scope.
|
|
163
|
+
|
|
164
|
+
## 9. Copy
|
|
165
|
+
|
|
166
|
+
`filesMessages.en.errors.files.*` has a sentence per error code (`too_large`, `quota_exceeded`, `not_found`, ...);
|
|
167
|
+
`getFilesErrorMessage(messages, code)` picks one, falling back to the generic failure. The link route's `404` body
|
|
168
|
+
is a fixed `Not found` for machines, not copy.
|
|
169
|
+
|
|
170
|
+
## 10. Hooks
|
|
171
|
+
|
|
172
|
+
None. A driver is the extension point: any object with `kind`, `put(body, key)`, `get(key, range?)`, `head(key)`,
|
|
173
|
+
`delete(key)` and optionally `check()` (`FileStorage`) works.
|
|
174
|
+
|
|
175
|
+
## 11. GDPR
|
|
176
|
+
|
|
177
|
+
`exportUserData` lists the user's live files (id, name, kind, content type, size, SHA-256, created and expiry
|
|
178
|
+
times), never the bytes or the storage key; an app that wants the bytes in the export adds links itself.
|
|
179
|
+
`deleteUserData` marks every file of the user deleted (nothing of theirs is served from that moment), removes the
|
|
180
|
+
bytes from storage and then the rows; a file whose storage delete fails keeps its marked row until `pruneFiles`
|
|
181
|
+
removes it.
|
|
182
|
+
|
|
183
|
+
## 12. Limitations
|
|
184
|
+
|
|
185
|
+
- No uploads from clients: no signed upload URLs, no chunked or resumable transfer. The app streams the request body
|
|
186
|
+
into `saveFile` itself. No image transforms, no virus scanning, no file browser UI.
|
|
187
|
+
- A link serves one range per request; a request for several ranges gets the whole file (`200`), as RFC 9110 allows.
|
|
188
|
+
No `If-Range` or `ETag`.
|
|
189
|
+
- Links are `attachment` with `nosniff` and a sandboxing `Content-Security-Policy` by default, so an uploaded HTML or
|
|
190
|
+
SVG never runs on the app's origin; `inline` keeps those headers.
|
|
191
|
+
- The quota counts live files of one owner; it is not a global storage limit. Dedupe works per owner and only when
|
|
192
|
+
enabled; two owners' copies of one file are two objects.
|
|
193
|
+
- The local driver needs one filesystem for the folder (the rename is atomic only there); the free-space check reads
|
|
194
|
+
that filesystem. The S3 driver reports no free space.
|
|
195
|
+
- A storage key comes from the file id, not the hash: the hash is known only after the write, and S3 has no rename.
|
|
196
|
+
|
|
197
|
+
## Testing an app with it
|
|
198
|
+
|
|
199
|
+
```ts
|
|
200
|
+
import { createMemoryStorage, createTestLinkKeys, fetchFileLink, readFileLinkExpiry } from "@softure-ai/files/testing";
|
|
201
|
+
|
|
202
|
+
const storage = createMemoryStorage(); // files({ storage }); storage.objects(), setFailing(), setCheck()
|
|
203
|
+
const ctx = { db, clock, config, env: createTestLinkKeys() };
|
|
204
|
+
const answer = await fetchFileLink(ctx, link.url, { range: "bytes=0-99" }); // { status: 206, headers, body }
|
|
205
|
+
expect(readFileLinkExpiry(link.url)).toEqual(expectedExpiry);
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
`fetchFileLink` runs the same code as the route, at the context's clock, so advancing a test clock past the expiry
|
|
209
|
+
gives the `404`.
|
|
210
|
+
|
|
211
|
+
## Build
|
|
212
|
+
|
|
213
|
+
`npm run build -w modules/files` runs `tsc -p tsconfig.build.json`: ESM and `.d.ts` per source file in `dist/`.
|
|
214
|
+
Releasing: [scripts/release/README.md](../../scripts/release/README.md).
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/** The link keyring cannot sign: a configuration problem, never fixed by retrying. */
|
|
2
|
+
export type FilesKeyErrorCode =
|
|
3
|
+
/** `SOFTURE_FILES_LINK_KEYS` is not set. */
|
|
4
|
+
"files.link_key_missing"
|
|
5
|
+
/** `SOFTURE_FILES_LINK_KEYS` is set but is not a list of `<id>:<base64 32 bytes>`. */
|
|
6
|
+
| "files.link_key_invalid";
|
|
7
|
+
/** Why `saveFile` refused a file. */
|
|
8
|
+
export type FilesSaveErrorCode =
|
|
9
|
+
/** The input breaks a rule: an empty owner, a malformed kind or content type, an expiry in the past. */
|
|
10
|
+
"files.invalid_input"
|
|
11
|
+
/** The file is larger than `maxFileBytes`. */
|
|
12
|
+
| "files.too_large"
|
|
13
|
+
/** Saving it would take the owner above `quotaBytesPerOwner`. */
|
|
14
|
+
| "files.quota_exceeded";
|
|
15
|
+
/** Why a file could not be read, deleted or linked. */
|
|
16
|
+
export type FilesLookupErrorCode =
|
|
17
|
+
/** No live file has this id (unknown, another owner's, deleted or expired). */
|
|
18
|
+
"files.not_found"
|
|
19
|
+
/** The asked range starts at or after the end of the file. */
|
|
20
|
+
| "files.range_not_satisfiable";
|
|
21
|
+
export type FilesErrorCode = FilesKeyErrorCode | FilesSaveErrorCode | FilesLookupErrorCode;
|
|
22
|
+
/** A stored file as the app sees it. Never carries the storage key. */
|
|
23
|
+
export interface StoredFile {
|
|
24
|
+
readonly id: string;
|
|
25
|
+
/** The account the file belongs to (an auth user id, or any id the app keeps). */
|
|
26
|
+
readonly ownerId: string;
|
|
27
|
+
/** Lowercase hex SHA-256 of the content. */
|
|
28
|
+
readonly sha256: string;
|
|
29
|
+
readonly size: number;
|
|
30
|
+
readonly contentType: string;
|
|
31
|
+
/** The name it was saved under, sanitised: no folders, no control characters, at most 255 characters. */
|
|
32
|
+
readonly name: string;
|
|
33
|
+
/** The app's own category (`input`, `output`, `export`). */
|
|
34
|
+
readonly kind: string;
|
|
35
|
+
readonly expiresAt: Date | null;
|
|
36
|
+
readonly createdAt: Date;
|
|
37
|
+
}
|
|
38
|
+
/** An inclusive byte range, both ends within the file. */
|
|
39
|
+
export interface ByteRange {
|
|
40
|
+
readonly start: number;
|
|
41
|
+
readonly end: number;
|
|
42
|
+
}
|
|
43
|
+
/** A public link to a file. */
|
|
44
|
+
export interface FileLink {
|
|
45
|
+
/** The absolute URL on the app's origin. */
|
|
46
|
+
readonly url: string;
|
|
47
|
+
/** The path part, `/f/<id>/<expiry>/<signature>/<name>`. */
|
|
48
|
+
readonly path: string;
|
|
49
|
+
readonly expiresAt: Date;
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=contract.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contract.d.ts","sourceRoot":"","sources":["../src/contract.ts"],"names":[],"mappings":"AAGA,sFAAsF;AACtF,MAAM,MAAM,iBAAiB;AAC3B,4CAA4C;AAC1C,wBAAwB;AAC1B,sFAAsF;GACpF,wBAAwB,CAAC;AAE7B,qCAAqC;AACrC,MAAM,MAAM,kBAAkB;AAC5B,wGAAwG;AACtG,qBAAqB;AACvB,8CAA8C;GAC5C,iBAAiB;AACnB,iEAAiE;GAC/D,sBAAsB,CAAC;AAE3B,uDAAuD;AACvD,MAAM,MAAM,oBAAoB;AAC9B,+EAA+E;AAC7E,iBAAiB;AACnB,8DAA8D;GAC5D,6BAA6B,CAAC;AAElC,MAAM,MAAM,cAAc,GAAG,iBAAiB,GAAG,kBAAkB,GAAG,oBAAoB,CAAC;AAE3F,uEAAuE;AACvE,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,kFAAkF;IAClF,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,4CAA4C;IAC5C,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,yGAAyG;IACzG,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,4DAA4D;IAC5D,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,SAAS,EAAE,IAAI,GAAG,IAAI,CAAC;IAChC,QAAQ,CAAC,SAAS,EAAE,IAAI,CAAC;CAC1B;AAED,0DAA0D;AAC1D,MAAM,WAAW,SAAS;IACxB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;CACtB;AAED,+BAA+B;AAC/B,MAAM,WAAW,QAAQ;IACvB,4CAA4C;IAC5C,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,4DAA4D;IAC5D,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,SAAS,EAAE,IAAI,CAAC;CAC1B"}
|
package/dist/contract.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contract.js","sourceRoot":"","sources":["../src/contract.ts"],"names":[],"mappings":"AAAA,8GAA8G;AAC9G,8CAA8C"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
export declare const MODULE_ID = "files";
|
|
2
|
+
/**
|
|
3
|
+
* Enables stored files in `softure.config.ts`:
|
|
4
|
+
* `files({ storage: createLocalStorage({ dir: "/data/files" }), quotaBytesPerOwner: 2 * 1024 ** 3 })`.
|
|
5
|
+
*/
|
|
6
|
+
export declare const files: import("@softure-ai/core").ModuleFactory<{
|
|
7
|
+
links: string;
|
|
8
|
+
}, {
|
|
9
|
+
errors: {
|
|
10
|
+
files: {
|
|
11
|
+
link_key_missing: string;
|
|
12
|
+
link_key_invalid: string;
|
|
13
|
+
invalid_input: string;
|
|
14
|
+
too_large: string;
|
|
15
|
+
quota_exceeded: string;
|
|
16
|
+
not_found: string;
|
|
17
|
+
range_not_satisfiable: string;
|
|
18
|
+
};
|
|
19
|
+
core: {
|
|
20
|
+
unexpected: string;
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
}, import("zod").ZodObject<{
|
|
24
|
+
storage: import("zod").ZodCustom<import("./storage.js").FileStorage, import("./storage.js").FileStorage>;
|
|
25
|
+
maxFileBytes: import("zod").ZodDefault<import("zod").ZodNumber>;
|
|
26
|
+
quotaBytesPerOwner: import("zod").ZodDefault<import("zod").ZodNullable<import("zod").ZodNumber>>;
|
|
27
|
+
dedupe: import("zod").ZodDefault<import("zod").ZodBoolean>;
|
|
28
|
+
defaultTtlSeconds: import("zod").ZodDefault<import("zod").ZodNullable<import("zod").ZodNumber>>;
|
|
29
|
+
links: import("zod").ZodDefault<import("zod").ZodObject<{
|
|
30
|
+
maxTtlSeconds: import("zod").ZodDefault<import("zod").ZodNumber>;
|
|
31
|
+
disposition: import("zod").ZodDefault<import("zod").ZodEnum<{
|
|
32
|
+
attachment: "attachment";
|
|
33
|
+
inline: "inline";
|
|
34
|
+
}>>;
|
|
35
|
+
}, import("zod/v4/core").$strict>>;
|
|
36
|
+
health: import("zod").ZodDefault<import("zod").ZodObject<{
|
|
37
|
+
minFreeBytes: import("zod").ZodDefault<import("zod").ZodNumber>;
|
|
38
|
+
}, import("zod/v4/core").$strict>>;
|
|
39
|
+
}, import("zod/v4/core").$strict>>;
|
|
40
|
+
export type { ByteRange, FileLink, FilesErrorCode, FilesKeyErrorCode, FilesLookupErrorCode, FilesSaveErrorCode, StoredFile } from "./contract.js";
|
|
41
|
+
export { filesMessages, getFilesErrorMessage, type FilesMessages } from "./messages/index.js";
|
|
42
|
+
export { DEFAULT_FILE_KIND, FILE_KIND_PATTERN, type FilesOptions, type FilesOptionsInput } from "./options.js";
|
|
43
|
+
export { files as filesTable } from "./schema.js";
|
|
44
|
+
export { isFileStorage, type FileBody, type FileStorage, type StorageCheck } from "./storage.js";
|
|
45
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AASA,eAAO,MAAM,SAAS,UAAU,CAAC;AAEjC;;;GAGG;AACH,eAAO,MAAM,KAAK;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;kCA+BhB,CAAC;AAEH,YAAY,EAAE,SAAS,EAAE,QAAQ,EAAE,cAAc,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,kBAAkB,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAClJ,OAAO,EAAE,aAAa,EAAE,oBAAoB,EAAE,KAAK,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAC9F,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,KAAK,YAAY,EAAE,KAAK,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAC/G,OAAO,EAAE,KAAK,IAAI,UAAU,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,EAAE,aAAa,EAAE,KAAK,QAAQ,EAAE,KAAK,WAAW,EAAE,KAAK,YAAY,EAAE,MAAM,cAAc,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
// Public API of @softure-ai/files: the module factory for softure.config.ts, its types, messages and table. The
|
|
2
|
+
// storage drivers and every database function are in `@softure-ai/files/server`, the link route in `/next`, the
|
|
3
|
+
// prune job in `/jobs` and the test helpers (an in-memory driver, link checks) in `/testing`.
|
|
4
|
+
import { defineModule, resolveMigrationsDir } from "@softure-ai/core";
|
|
5
|
+
import { filesMessages } from "./messages/index.js";
|
|
6
|
+
import { filesOptionsSchema } from "./options.js";
|
|
7
|
+
import { checkFilesHealth } from "./server/health.js";
|
|
8
|
+
import { filesPrivacyContributor } from "./server/privacy.js";
|
|
9
|
+
export const MODULE_ID = "files";
|
|
10
|
+
/**
|
|
11
|
+
* Enables stored files in `softure.config.ts`:
|
|
12
|
+
* `files({ storage: createLocalStorage({ dir: "/data/files" }), quotaBytesPerOwner: 2 * 1024 ** 3 })`.
|
|
13
|
+
*/
|
|
14
|
+
export const files = defineModule({
|
|
15
|
+
manifest: {
|
|
16
|
+
id: MODULE_ID,
|
|
17
|
+
version: "0.1.2",
|
|
18
|
+
dependsOn: { jobs: "^0.1.6?" },
|
|
19
|
+
dbSchema: "files",
|
|
20
|
+
tables: ["files"],
|
|
21
|
+
env: [
|
|
22
|
+
{
|
|
23
|
+
name: "SOFTURE_FILES_LINK_KEYS",
|
|
24
|
+
required: false,
|
|
25
|
+
description: "Signing keyring for public file links: <id>:<base64 32 bytes>[,<id>:<key>...], the first one signs; needed only by createFileLink and the link route",
|
|
26
|
+
},
|
|
27
|
+
],
|
|
28
|
+
switches: [],
|
|
29
|
+
routes: { links: "/f" },
|
|
30
|
+
mount: [
|
|
31
|
+
{
|
|
32
|
+
kind: "route-handler",
|
|
33
|
+
path: "app/f/[...link]/route.ts",
|
|
34
|
+
export: "serveFileLinkRoute",
|
|
35
|
+
},
|
|
36
|
+
],
|
|
37
|
+
privacy: { exports: true, deletes: true },
|
|
38
|
+
},
|
|
39
|
+
messages: filesMessages,
|
|
40
|
+
options: filesOptionsSchema,
|
|
41
|
+
migrations: { dir: resolveMigrationsDir(import.meta.url, "../migrations/") },
|
|
42
|
+
privacy: filesPrivacyContributor,
|
|
43
|
+
health: checkFilesHealth,
|
|
44
|
+
});
|
|
45
|
+
export { filesMessages, getFilesErrorMessage } from "./messages/index.js";
|
|
46
|
+
export { DEFAULT_FILE_KIND, FILE_KIND_PATTERN } from "./options.js";
|
|
47
|
+
export { files as filesTable } from "./schema.js";
|
|
48
|
+
export { isFileStorage } from "./storage.js";
|
|
49
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,gHAAgH;AAChH,gHAAgH;AAChH,8FAA8F;AAC9F,OAAO,EAAE,YAAY,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AACtE,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,uBAAuB,EAAE,MAAM,qBAAqB,CAAC;AAE9D,MAAM,CAAC,MAAM,SAAS,GAAG,OAAO,CAAC;AAEjC;;;GAGG;AACH,MAAM,CAAC,MAAM,KAAK,GAAG,YAAY,CAAC;IAChC,QAAQ,EAAE;QACR,EAAE,EAAE,SAAS;QACb,OAAO,EAAE,OAAO;QAChB,SAAS,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE;QAC9B,QAAQ,EAAE,OAAO;QACjB,MAAM,EAAE,CAAC,OAAO,CAAC;QACjB,GAAG,EAAE;YACH;gBACE,IAAI,EAAE,yBAAyB;gBAC/B,QAAQ,EAAE,KAAK;gBACf,WAAW,EACT,sJAAsJ;aACzJ;SACF;QACD,QAAQ,EAAE,EAAE;QACZ,MAAM,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE;QACvB,KAAK,EAAE;YACL;gBACE,IAAI,EAAE,eAAe;gBACrB,IAAI,EAAE,0BAA0B;gBAChC,MAAM,EAAE,oBAAoB;aAC7B;SACF;QACD,OAAO,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE;KAC1C;IACD,QAAQ,EAAE,aAAa;IACvB,OAAO,EAAE,kBAAkB;IAC3B,UAAU,EAAE,EAAE,GAAG,EAAE,oBAAoB,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,gBAAgB,CAAC,EAAE;IAC5E,OAAO,EAAE,uBAAuB;IAChC,MAAM,EAAE,gBAAgB;CACzB,CAAC,CAAC;AAGH,OAAO,EAAE,aAAa,EAAE,oBAAoB,EAAsB,MAAM,qBAAqB,CAAC;AAC9F,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAA6C,MAAM,cAAc,CAAC;AAC/G,OAAO,EAAE,KAAK,IAAI,UAAU,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,EAAE,aAAa,EAAsD,MAAM,cAAc,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/** Handlers for the worker: `handlers: { ...filesJobHandlers }`. */
|
|
2
|
+
export declare const filesJobHandlers: {
|
|
3
|
+
/** Removes expired and deleted files from storage and the table (`pruneFiles`). */
|
|
4
|
+
"files.prune": import("@softure-ai/jobs").JobHandler<Record<string, never>>;
|
|
5
|
+
};
|
|
6
|
+
/** Schedules for `jobs({ schedules: { ...filesJobSchedules } })`: hourly. */
|
|
7
|
+
export declare const filesJobSchedules: {
|
|
8
|
+
"files.prune": {
|
|
9
|
+
every: string;
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/jobs/index.ts"],"names":[],"mappings":"AAOA,oEAAoE;AACpE,eAAO,MAAM,gBAAgB;IAC3B,mFAAmF;;CAQ9D,CAAC;AAExB,6EAA6E;AAC7E,eAAO,MAAM,iBAAiB;;;;CAED,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// The jobs adapter of @softure-ai/files: the prune as a `@softure-ai/jobs` handler and schedule (an optional peer
|
|
2
|
+
// dependency; only apps that import this entry need it).
|
|
3
|
+
import { ok } from "@softure-ai/core";
|
|
4
|
+
import { defineJobHandler } from "@softure-ai/jobs";
|
|
5
|
+
import { z } from "zod";
|
|
6
|
+
import { pruneFiles } from "../server/prune.js";
|
|
7
|
+
/** Handlers for the worker: `handlers: { ...filesJobHandlers }`. */
|
|
8
|
+
export const filesJobHandlers = {
|
|
9
|
+
/** Removes expired and deleted files from storage and the table (`pruneFiles`). */
|
|
10
|
+
"files.prune": defineJobHandler({
|
|
11
|
+
payload: z.object({}),
|
|
12
|
+
run: async (_payload, ctx) => {
|
|
13
|
+
await pruneFiles(ctx);
|
|
14
|
+
return ok();
|
|
15
|
+
},
|
|
16
|
+
}),
|
|
17
|
+
};
|
|
18
|
+
/** Schedules for `jobs({ schedules: { ...filesJobSchedules } })`: hourly. */
|
|
19
|
+
export const filesJobSchedules = {
|
|
20
|
+
"files.prune": { every: "1h" },
|
|
21
|
+
};
|
|
22
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/jobs/index.ts"],"names":[],"mappings":"AAAA,kHAAkH;AAClH,yDAAyD;AACzD,OAAO,EAAE,EAAE,EAAE,MAAM,kBAAkB,CAAC;AACtC,OAAO,EAAE,gBAAgB,EAA4C,MAAM,kBAAkB,CAAC;AAC9F,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAEhD,oEAAoE;AACpE,MAAM,CAAC,MAAM,gBAAgB,GAAG;IAC9B,mFAAmF;IACnF,aAAa,EAAE,gBAAgB,CAAC;QAC9B,OAAO,EAAE,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC;QACrB,GAAG,EAAE,KAAK,EAAE,QAAQ,EAAE,GAAG,EAAE,EAAE;YAC3B,MAAM,UAAU,CAAC,GAAG,CAAC,CAAC;YACtB,OAAO,EAAE,EAAE,CAAC;QACd,CAAC;KACF,CAAC;CACmB,CAAC;AAExB,6EAA6E;AAC7E,MAAM,CAAC,MAAM,iBAAiB,GAAG;IAC/B,aAAa,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE;CACH,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export declare const en: {
|
|
2
|
+
errors: {
|
|
3
|
+
files: {
|
|
4
|
+
link_key_missing: string;
|
|
5
|
+
link_key_invalid: string;
|
|
6
|
+
invalid_input: string;
|
|
7
|
+
too_large: string;
|
|
8
|
+
quota_exceeded: string;
|
|
9
|
+
not_found: string;
|
|
10
|
+
range_not_satisfiable: string;
|
|
11
|
+
};
|
|
12
|
+
core: {
|
|
13
|
+
unexpected: string;
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
//# sourceMappingURL=en.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"en.d.ts","sourceRoot":"","sources":["../../src/messages/en.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,EAAE;;;;;;;;;;;;;;;CAed,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export const en = {
|
|
2
|
+
errors: {
|
|
3
|
+
files: {
|
|
4
|
+
link_key_missing: "Links cannot be made: the link signing key is not configured.",
|
|
5
|
+
link_key_invalid: "Links cannot be made: the link signing key is malformed.",
|
|
6
|
+
invalid_input: "The file details are not valid.",
|
|
7
|
+
too_large: "The file is too large.",
|
|
8
|
+
quota_exceeded: "There is no space left for this file.",
|
|
9
|
+
not_found: "The file was not found.",
|
|
10
|
+
range_not_satisfiable: "The requested part of the file is outside it.",
|
|
11
|
+
},
|
|
12
|
+
core: {
|
|
13
|
+
unexpected: "Something went wrong. Try again.",
|
|
14
|
+
},
|
|
15
|
+
},
|
|
16
|
+
};
|
|
17
|
+
//# sourceMappingURL=en.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"en.js","sourceRoot":"","sources":["../../src/messages/en.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,EAAE,GAAG;IAChB,MAAM,EAAE;QACN,KAAK,EAAE;YACL,gBAAgB,EAAE,+DAA+D;YACjF,gBAAgB,EAAE,0DAA0D;YAC5E,aAAa,EAAE,iCAAiC;YAChD,SAAS,EAAE,wBAAwB;YACnC,cAAc,EAAE,uCAAuC;YACvD,SAAS,EAAE,yBAAyB;YACpC,qBAAqB,EAAE,+CAA+C;SACvE;QACD,IAAI,EAAE;YACJ,UAAU,EAAE,kCAAkC;SAC/C;KACF;CACF,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { en } from "./en.js";
|
|
2
|
+
/** The built-in English dictionary; an app passes partial overrides or its own translation per locale. */
|
|
3
|
+
export declare const filesMessages: {
|
|
4
|
+
en: {
|
|
5
|
+
errors: {
|
|
6
|
+
files: {
|
|
7
|
+
link_key_missing: string;
|
|
8
|
+
link_key_invalid: string;
|
|
9
|
+
invalid_input: string;
|
|
10
|
+
too_large: string;
|
|
11
|
+
quota_exceeded: string;
|
|
12
|
+
not_found: string;
|
|
13
|
+
range_not_satisfiable: string;
|
|
14
|
+
};
|
|
15
|
+
core: {
|
|
16
|
+
unexpected: string;
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
export type FilesMessages = typeof en;
|
|
22
|
+
/** The copy for an error code (`files.*`); an unknown code gets the generic failure. */
|
|
23
|
+
export declare function getFilesErrorMessage(messages: FilesMessages, code: string): string;
|
|
24
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/messages/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,SAAS,CAAC;AAE7B,0GAA0G;AAC1G,eAAO,MAAM,aAAa;;;;;;;;;;;;;;;;;CAAS,CAAC;AAEpC,MAAM,MAAM,aAAa,GAAG,OAAO,EAAE,CAAC;AAEtC,wFAAwF;AACxF,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,aAAa,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAIlF"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { en } from "./en.js";
|
|
2
|
+
/** The built-in English dictionary; an app passes partial overrides or its own translation per locale. */
|
|
3
|
+
export const filesMessages = { en };
|
|
4
|
+
/** The copy for an error code (`files.*`); an unknown code gets the generic failure. */
|
|
5
|
+
export function getFilesErrorMessage(messages, code) {
|
|
6
|
+
const name = code.startsWith("files.") ? code.slice("files.".length) : "";
|
|
7
|
+
const group = messages.errors.files;
|
|
8
|
+
return (Object.hasOwn(group, name) ? group[name] : undefined) ?? messages.errors.core.unexpected;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/messages/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,SAAS,CAAC;AAE7B,0GAA0G;AAC1G,MAAM,CAAC,MAAM,aAAa,GAAG,EAAE,EAAE,EAAE,CAAC;AAIpC,wFAAwF;AACxF,MAAM,UAAU,oBAAoB,CAAC,QAAuB,EAAE,IAAY;IACxE,MAAM,IAAI,GAAG,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;IAC1E,MAAM,KAAK,GAAqC,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC;IACtE,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,IAAI,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC;AACnG,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../src/next/context.ts"],"names":[],"mappings":"AAEA,OAAO,EAAe,KAAK,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAGnE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAEzD,wBAAsB,eAAe,CAAC,MAAM,GAAE,aAAkC,GAAG,OAAO,CAAC,YAAY,CAAC,CAMvG"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// What the adapter hands the server functions: the registered config, the process-wide database handle and the
|
|
2
|
+
// wall clock. The link keyring comes from `process.env`.
|
|
3
|
+
import { systemClock } from "@softure-ai/core";
|
|
4
|
+
import { getSoftureConfig } from "@softure-ai/core/next";
|
|
5
|
+
import { getConfiguredDatabase } from "@softure-ai/db";
|
|
6
|
+
export async function getFilesContext(config = getSoftureConfig()) {
|
|
7
|
+
if (config.database === null) {
|
|
8
|
+
throw new Error("@softure-ai/files: softure.config.ts has no database; files needs one");
|
|
9
|
+
}
|
|
10
|
+
const { db } = await getConfiguredDatabase(config.database);
|
|
11
|
+
return { db, clock: systemClock, config };
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.js","sourceRoot":"","sources":["../../src/next/context.ts"],"names":[],"mappings":"AAAA,+GAA+G;AAC/G,yDAAyD;AACzD,OAAO,EAAE,WAAW,EAAsB,MAAM,kBAAkB,CAAC;AACnE,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,qBAAqB,EAAE,MAAM,gBAAgB,CAAC;AAGvD,MAAM,CAAC,KAAK,UAAU,eAAe,CAAC,SAAwB,gBAAgB,EAAE;IAC9E,IAAI,MAAM,CAAC,QAAQ,KAAK,IAAI,EAAE,CAAC;QAC7B,MAAM,IAAI,KAAK,CAAC,uEAAuE,CAAC,CAAC;IAC3F,CAAC;IACD,MAAM,EAAE,EAAE,EAAE,GAAG,MAAM,qBAAqB,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;IAC5D,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,EAAE,CAAC;AAC5C,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/next/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/next/index.ts"],"names":[],"mappings":"AAAA,+FAA+F;AAC/F,mCAAmC;AACnC,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"route.d.ts","sourceRoot":"","sources":["../../src/next/route.ts"],"names":[],"mappings":"AAOA,4DAA4D;AAC5D,wBAAsB,kBAAkB,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CAE5E"}
|