@noy-db/to-webdav 0.1.0-pre.3
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 +33 -0
- package/dist/index.cjs +190 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +67 -0
- package/dist/index.d.ts +67 -0
- package/dist/index.js +165 -0
- package/dist/index.js.map +1 -0
- package/package.json +66 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 vLannaAi
|
|
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
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# @noy-db/to-webdav
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@noy-db/to-webdav)
|
|
4
|
+
|
|
5
|
+
> WebDAV adapter for noy-db
|
|
6
|
+
|
|
7
|
+
Part of [**`@noy-db/hub`**](https://www.npmjs.com/package/@noy-db/hub) — the zero-knowledge, offline-first, encrypted document store.
|
|
8
|
+
|
|
9
|
+
## Install
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
pnpm add @noy-db/hub @noy-db/to-webdav
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## What it is
|
|
16
|
+
|
|
17
|
+
WebDAV adapter for noy-db — encrypted object storage over the WebDAV protocol. Works with Nextcloud, ownCloud, Apache mod_dav, and any RFC 4918 server. Pure fetch()-based, zero dependencies.
|
|
18
|
+
|
|
19
|
+
## Status
|
|
20
|
+
|
|
21
|
+
**Pre-release** (`0.1.0-pre.1`). API may change before `1.0`.
|
|
22
|
+
|
|
23
|
+
## Documentation
|
|
24
|
+
|
|
25
|
+
See the [main repository](https://github.com/vLannaAi/noy-db#readme) for setup, examples, and the full subsystem catalog.
|
|
26
|
+
|
|
27
|
+
- Source — [`packages/to-webdav`](https://github.com/vLannaAi/noy-db/tree/main/packages/to-webdav)
|
|
28
|
+
- Issues — [github.com/vLannaAi/noy-db/issues](https://github.com/vLannaAi/noy-db/issues)
|
|
29
|
+
- Spec — [`SPEC.md`](https://github.com/vLannaAi/noy-db/blob/main/SPEC.md)
|
|
30
|
+
|
|
31
|
+
## License
|
|
32
|
+
|
|
33
|
+
[MIT](./LICENSE) © vLannaAi
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
webdav: () => webdav
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(index_exports);
|
|
26
|
+
function webdav(options) {
|
|
27
|
+
const {
|
|
28
|
+
baseUrl: rawBase,
|
|
29
|
+
prefix = "",
|
|
30
|
+
headers: baseHeaders = {},
|
|
31
|
+
fetch: fetchImpl = globalThis.fetch.bind(globalThis),
|
|
32
|
+
autoMkcol = true,
|
|
33
|
+
eagerMkcol = false
|
|
34
|
+
} = options;
|
|
35
|
+
const baseUrl = rawBase.endsWith("/") ? rawBase.slice(0, -1) : rawBase;
|
|
36
|
+
function urlFor(vault, collection, id) {
|
|
37
|
+
const segments = [prefix, vault, collection, `${id}.json`].filter(Boolean).map(encodeURIComponent);
|
|
38
|
+
return `${baseUrl}/${segments.join("/")}`;
|
|
39
|
+
}
|
|
40
|
+
function collectionUrl(vault, collection) {
|
|
41
|
+
const segments = [prefix, vault, collection].filter(Boolean).map(encodeURIComponent);
|
|
42
|
+
return `${baseUrl}/${segments.join("/")}/`;
|
|
43
|
+
}
|
|
44
|
+
async function mkcolRecursive(vault, collection) {
|
|
45
|
+
const parts = [prefix, vault, ...collection ? [collection] : []].filter(Boolean);
|
|
46
|
+
let url = baseUrl;
|
|
47
|
+
for (const part of parts) {
|
|
48
|
+
url += `/${encodeURIComponent(part)}`;
|
|
49
|
+
const res = await fetchImpl(url + "/", { method: "MKCOL", headers: baseHeaders });
|
|
50
|
+
if (res.status >= 500) {
|
|
51
|
+
throw new Error(`WebDAV MKCOL failed at ${url}: ${res.status}`);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
async function putOnce(vault, collection, id, body) {
|
|
56
|
+
return fetchImpl(urlFor(vault, collection, id), {
|
|
57
|
+
method: "PUT",
|
|
58
|
+
headers: {
|
|
59
|
+
...baseHeaders,
|
|
60
|
+
"Content-Type": "application/json"
|
|
61
|
+
},
|
|
62
|
+
body
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
const PROPFIND_BODY = `<?xml version="1.0" encoding="utf-8"?>
|
|
66
|
+
<d:propfind xmlns:d="DAV:"><d:prop><d:resourcetype/></d:prop></d:propfind>`;
|
|
67
|
+
async function listChildren(vault, collection) {
|
|
68
|
+
const url = collectionUrl(vault, collection);
|
|
69
|
+
const res = await fetchImpl(url, {
|
|
70
|
+
method: "PROPFIND",
|
|
71
|
+
headers: {
|
|
72
|
+
...baseHeaders,
|
|
73
|
+
Depth: "1",
|
|
74
|
+
"Content-Type": "application/xml"
|
|
75
|
+
},
|
|
76
|
+
body: PROPFIND_BODY
|
|
77
|
+
});
|
|
78
|
+
if (res.status === 404) return [];
|
|
79
|
+
if (!res.ok && res.status !== 207) {
|
|
80
|
+
throw new Error(`WebDAV PROPFIND failed: ${res.status}`);
|
|
81
|
+
}
|
|
82
|
+
const xml = await res.text();
|
|
83
|
+
const hrefs = Array.from(xml.matchAll(/<(?:\w+:)?href>([^<]+)<\/(?:\w+:)?href>/g)).map((m) => decodeURIComponent(m[1]));
|
|
84
|
+
const selfPath = new URL(url).pathname.replace(/\/+$/, "");
|
|
85
|
+
const ids = [];
|
|
86
|
+
for (const href of hrefs) {
|
|
87
|
+
const hrefPath = href.replace(/\/+$/, "");
|
|
88
|
+
if (hrefPath === selfPath) continue;
|
|
89
|
+
const filename = hrefPath.split("/").pop();
|
|
90
|
+
if (!filename.endsWith(".json")) continue;
|
|
91
|
+
ids.push(filename.slice(0, -".json".length));
|
|
92
|
+
}
|
|
93
|
+
return ids.sort();
|
|
94
|
+
}
|
|
95
|
+
const store = {
|
|
96
|
+
name: "webdav",
|
|
97
|
+
async get(vault, collection, id) {
|
|
98
|
+
const res = await fetchImpl(urlFor(vault, collection, id), {
|
|
99
|
+
method: "GET",
|
|
100
|
+
headers: baseHeaders
|
|
101
|
+
});
|
|
102
|
+
if (res.status === 404) return null;
|
|
103
|
+
if (!res.ok) throw new Error(`WebDAV GET failed: ${res.status}`);
|
|
104
|
+
const text = await res.text();
|
|
105
|
+
return JSON.parse(text);
|
|
106
|
+
},
|
|
107
|
+
async put(vault, collection, id, envelope) {
|
|
108
|
+
const body = JSON.stringify(envelope);
|
|
109
|
+
if (eagerMkcol) {
|
|
110
|
+
await mkcolRecursive(vault, collection);
|
|
111
|
+
}
|
|
112
|
+
let res = await putOnce(vault, collection, id, body);
|
|
113
|
+
if ((res.status === 404 || res.status === 409) && autoMkcol) {
|
|
114
|
+
await mkcolRecursive(vault, collection);
|
|
115
|
+
res = await putOnce(vault, collection, id, body);
|
|
116
|
+
}
|
|
117
|
+
if (!res.ok) throw new Error(`WebDAV PUT failed: ${res.status}`);
|
|
118
|
+
},
|
|
119
|
+
async delete(vault, collection, id) {
|
|
120
|
+
const res = await fetchImpl(urlFor(vault, collection, id), {
|
|
121
|
+
method: "DELETE",
|
|
122
|
+
headers: baseHeaders
|
|
123
|
+
});
|
|
124
|
+
if (res.status !== 204 && res.status !== 404 && !res.ok) {
|
|
125
|
+
throw new Error(`WebDAV DELETE failed: ${res.status}`);
|
|
126
|
+
}
|
|
127
|
+
},
|
|
128
|
+
async list(vault, collection) {
|
|
129
|
+
return listChildren(vault, collection);
|
|
130
|
+
},
|
|
131
|
+
async loadAll(vault) {
|
|
132
|
+
const rootUrl = `${baseUrl}/${[prefix, vault].filter(Boolean).map(encodeURIComponent).join("/")}/`;
|
|
133
|
+
const res = await fetchImpl(rootUrl, {
|
|
134
|
+
method: "PROPFIND",
|
|
135
|
+
headers: { ...baseHeaders, Depth: "1", "Content-Type": "application/xml" },
|
|
136
|
+
body: PROPFIND_BODY
|
|
137
|
+
});
|
|
138
|
+
if (res.status === 404) return {};
|
|
139
|
+
if (!res.ok && res.status !== 207) {
|
|
140
|
+
throw new Error(`WebDAV PROPFIND (loadAll) failed: ${res.status}`);
|
|
141
|
+
}
|
|
142
|
+
const xml = await res.text();
|
|
143
|
+
const hrefs = Array.from(xml.matchAll(/<(?:\w+:)?href>([^<]+)<\/(?:\w+:)?href>/g)).map((m) => decodeURIComponent(m[1]));
|
|
144
|
+
const selfPath = new URL(rootUrl).pathname.replace(/\/+$/, "");
|
|
145
|
+
const collections = /* @__PURE__ */ new Set();
|
|
146
|
+
for (const href of hrefs) {
|
|
147
|
+
const hrefPath = href.replace(/\/+$/, "");
|
|
148
|
+
if (hrefPath === selfPath) continue;
|
|
149
|
+
const segment = hrefPath.slice(selfPath.length + 1).split("/")[0];
|
|
150
|
+
if (segment) collections.add(decodeURIComponent(segment));
|
|
151
|
+
}
|
|
152
|
+
const snap = {};
|
|
153
|
+
for (const collection of collections) {
|
|
154
|
+
const ids = await listChildren(vault, collection);
|
|
155
|
+
const bucket = {};
|
|
156
|
+
for (const id of ids) {
|
|
157
|
+
const env = await store.get(vault, collection, id);
|
|
158
|
+
if (env) bucket[id] = env;
|
|
159
|
+
}
|
|
160
|
+
snap[collection] = bucket;
|
|
161
|
+
}
|
|
162
|
+
return snap;
|
|
163
|
+
},
|
|
164
|
+
async saveAll(vault, data) {
|
|
165
|
+
for (const [collection, recs] of Object.entries(data)) {
|
|
166
|
+
await mkcolRecursive(vault, collection);
|
|
167
|
+
for (const [id, envelope] of Object.entries(recs)) {
|
|
168
|
+
await store.put(vault, collection, id, envelope);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
},
|
|
172
|
+
async ping() {
|
|
173
|
+
try {
|
|
174
|
+
const res = await fetchImpl(baseUrl + "/", {
|
|
175
|
+
method: "PROPFIND",
|
|
176
|
+
headers: { ...baseHeaders, Depth: "0" }
|
|
177
|
+
});
|
|
178
|
+
return res.ok || res.status === 207;
|
|
179
|
+
} catch {
|
|
180
|
+
return false;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
};
|
|
184
|
+
return store;
|
|
185
|
+
}
|
|
186
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
187
|
+
0 && (module.exports = {
|
|
188
|
+
webdav
|
|
189
|
+
});
|
|
190
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["/**\n * **@noy-db/to-webdav** — WebDAV-backed noy-db store.\n *\n * Per-record JSON objects over the WebDAV protocol (RFC 4918). Works\n * against Nextcloud, ownCloud, Apache `mod_dav`, nginx WebDAV, or any\n * compliant server. Pure `fetch()` — zero dependencies.\n *\n * Key path:\n * `{baseUrl}/{prefix}/{vault}/{collection}/{id}.json`\n *\n * ## Capabilities\n *\n * | Capability | Value |\n * |-------------|-------|\n * | `casAtomic` | `false` — WebDAV has no atomic CAS; last-write-wins |\n * | `listPage` | ✗ — `PROPFIND` Depth:1 returns the whole collection |\n * | `ping` | ✓ — `PROPFIND Depth:0` on the root |\n *\n * For conflict-safe writes pair with `@noy-db/to-aws-dynamo` or\n * `@noy-db/to-postgres` as the primary and use WebDAV as a\n * `backup`/`archive` target in `routeStore`.\n *\n * ## Authentication\n *\n * WebDAV commonly uses Basic Auth. Pass an `Authorization` header via\n * `headers`, or override `fetch` with a wrapper that injects your\n * credentials (session token, app password, OAuth token).\n *\n * @packageDocumentation\n */\n\nimport type { NoydbStore, EncryptedEnvelope, VaultSnapshot } from '@noy-db/hub'\n\nexport interface WebDAVStoreOptions {\n /** Base URL of the WebDAV endpoint (with trailing slash optional). */\n readonly baseUrl: string\n /** Path prefix within the endpoint. Default `''`. */\n readonly prefix?: string\n /** Default headers sent with every request (e.g. Authorization). */\n readonly headers?: Record<string, string>\n /** Custom fetch — defaults to `globalThis.fetch`. */\n readonly fetch?: typeof fetch\n /**\n * When `true` (default), PUT errors from missing parent collections\n * are recovered by MKCOL'ing the path and retrying once. Set to\n * `false` if the server already has the tree provisioned.\n */\n readonly autoMkcol?: boolean\n /**\n * When `true`, MKCOL the full path tree before EVERY put — not just\n * as a 404/409 fallback. Default `false`.\n *\n * Required for non-RFC-compliant servers (notably DriveHQ free tier\n * and some embedded NAS firmwares) that return `204 No Content` on a\n * PUT to a non-existent path AND silently flatten the file to the\n * server root instead of preserving the requested path. Without\n * eager MKCOL, the package's lazy fallback never fires (no 4xx to\n * trigger it) and writes silently land at the wrong location.\n *\n * Adds one extra round-trip per put; only enable when you've\n * confirmed your server has this quirk.\n */\n readonly eagerMkcol?: boolean\n}\n\nexport function webdav(options: WebDAVStoreOptions): NoydbStore {\n const {\n baseUrl: rawBase,\n prefix = '',\n headers: baseHeaders = {},\n fetch: fetchImpl = globalThis.fetch.bind(globalThis),\n autoMkcol = true,\n eagerMkcol = false,\n } = options\n\n const baseUrl = rawBase.endsWith('/') ? rawBase.slice(0, -1) : rawBase\n\n function urlFor(vault: string, collection: string, id: string): string {\n const segments = [prefix, vault, collection, `${id}.json`]\n .filter(Boolean)\n .map(encodeURIComponent)\n return `${baseUrl}/${segments.join('/')}`\n }\n\n function collectionUrl(vault: string, collection: string): string {\n const segments = [prefix, vault, collection].filter(Boolean).map(encodeURIComponent)\n return `${baseUrl}/${segments.join('/')}/`\n }\n\n async function mkcolRecursive(vault: string, collection?: string): Promise<void> {\n const parts = [prefix, vault, ...(collection ? [collection] : [])].filter(Boolean)\n let url = baseUrl\n for (const part of parts) {\n url += `/${encodeURIComponent(part)}`\n const res = await fetchImpl(url + '/', { method: 'MKCOL', headers: baseHeaders })\n // 201 Created, 405 Method Not Allowed (exists), and 409 Conflict are all\n // acceptable — we only fail on transport-level errors.\n if (res.status >= 500) {\n throw new Error(`WebDAV MKCOL failed at ${url}: ${res.status}`)\n }\n }\n }\n\n async function putOnce(vault: string, collection: string, id: string, body: string): Promise<Response> {\n return fetchImpl(urlFor(vault, collection, id), {\n method: 'PUT',\n headers: {\n ...baseHeaders,\n 'Content-Type': 'application/json',\n },\n body,\n })\n }\n\n // Very small PROPFIND XML body — we only need child hrefs.\n const PROPFIND_BODY = `<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<d:propfind xmlns:d=\"DAV:\"><d:prop><d:resourcetype/></d:prop></d:propfind>`\n\n async function listChildren(vault: string, collection: string): Promise<string[]> {\n const url = collectionUrl(vault, collection)\n const res = await fetchImpl(url, {\n method: 'PROPFIND',\n headers: {\n ...baseHeaders,\n Depth: '1',\n 'Content-Type': 'application/xml',\n },\n body: PROPFIND_BODY,\n })\n if (res.status === 404) return []\n if (!res.ok && res.status !== 207) {\n throw new Error(`WebDAV PROPFIND failed: ${res.status}`)\n }\n const xml = await res.text()\n // Extract <d:href>...</d:href> entries, drop the collection self-ref,\n // keep only .json leaves, and return the id portion.\n const hrefs = Array.from(xml.matchAll(/<(?:\\w+:)?href>([^<]+)<\\/(?:\\w+:)?href>/g))\n .map(m => decodeURIComponent(m[1]!))\n const selfPath = new URL(url).pathname.replace(/\\/+$/, '')\n const ids: string[] = []\n for (const href of hrefs) {\n const hrefPath = href.replace(/\\/+$/, '')\n if (hrefPath === selfPath) continue\n const filename = hrefPath.split('/').pop()!\n if (!filename.endsWith('.json')) continue\n ids.push(filename.slice(0, -'.json'.length))\n }\n return ids.sort()\n }\n\n const store: NoydbStore = {\n name: 'webdav',\n\n async get(vault, collection, id) {\n const res = await fetchImpl(urlFor(vault, collection, id), {\n method: 'GET',\n headers: baseHeaders,\n })\n if (res.status === 404) return null\n if (!res.ok) throw new Error(`WebDAV GET failed: ${res.status}`)\n const text = await res.text()\n return JSON.parse(text) as EncryptedEnvelope\n },\n\n async put(vault, collection, id, envelope) {\n // Note: casAtomic:false — expectedVersion is IGNORED. WebDAV\n // lacks server-side conditional metadata writes.\n const body = JSON.stringify(envelope)\n // Eager MKCOL: required for non-RFC servers (DriveHQ etc.) that\n // accept PUT-to-nonexistent with 204 and silently flatten.\n if (eagerMkcol) {\n await mkcolRecursive(vault, collection)\n }\n let res = await putOnce(vault, collection, id, body)\n if ((res.status === 404 || res.status === 409) && autoMkcol) {\n await mkcolRecursive(vault, collection)\n res = await putOnce(vault, collection, id, body)\n }\n if (!res.ok) throw new Error(`WebDAV PUT failed: ${res.status}`)\n },\n\n async delete(vault, collection, id) {\n const res = await fetchImpl(urlFor(vault, collection, id), {\n method: 'DELETE',\n headers: baseHeaders,\n })\n if (res.status !== 204 && res.status !== 404 && !res.ok) {\n throw new Error(`WebDAV DELETE failed: ${res.status}`)\n }\n },\n\n async list(vault, collection) {\n return listChildren(vault, collection)\n },\n\n async loadAll(vault) {\n const rootUrl = `${baseUrl}/${[prefix, vault].filter(Boolean).map(encodeURIComponent).join('/')}/`\n const res = await fetchImpl(rootUrl, {\n method: 'PROPFIND',\n headers: { ...baseHeaders, Depth: '1', 'Content-Type': 'application/xml' },\n body: PROPFIND_BODY,\n })\n if (res.status === 404) return {}\n if (!res.ok && res.status !== 207) {\n throw new Error(`WebDAV PROPFIND (loadAll) failed: ${res.status}`)\n }\n const xml = await res.text()\n const hrefs = Array.from(xml.matchAll(/<(?:\\w+:)?href>([^<]+)<\\/(?:\\w+:)?href>/g))\n .map(m => decodeURIComponent(m[1]!))\n const selfPath = new URL(rootUrl).pathname.replace(/\\/+$/, '')\n const collections = new Set<string>()\n for (const href of hrefs) {\n const hrefPath = href.replace(/\\/+$/, '')\n if (hrefPath === selfPath) continue\n const segment = hrefPath.slice(selfPath.length + 1).split('/')[0]\n if (segment) collections.add(decodeURIComponent(segment))\n }\n const snap: VaultSnapshot = {}\n for (const collection of collections) {\n const ids = await listChildren(vault, collection)\n const bucket: Record<string, EncryptedEnvelope> = {}\n for (const id of ids) {\n const env = await store.get(vault, collection, id)\n if (env) bucket[id] = env\n }\n snap[collection] = bucket\n }\n return snap\n },\n\n async saveAll(vault, data) {\n for (const [collection, recs] of Object.entries(data)) {\n await mkcolRecursive(vault, collection)\n for (const [id, envelope] of Object.entries(recs)) {\n await store.put(vault, collection, id, envelope)\n }\n }\n },\n\n async ping() {\n try {\n const res = await fetchImpl(baseUrl + '/', {\n method: 'PROPFIND',\n headers: { ...baseHeaders, Depth: '0' },\n })\n return res.ok || res.status === 207\n } catch {\n return false\n }\n },\n }\n\n return store\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAiEO,SAAS,OAAO,SAAyC;AAC9D,QAAM;AAAA,IACJ,SAAS;AAAA,IACT,SAAS;AAAA,IACT,SAAS,cAAc,CAAC;AAAA,IACxB,OAAO,YAAY,WAAW,MAAM,KAAK,UAAU;AAAA,IACnD,YAAY;AAAA,IACZ,aAAa;AAAA,EACf,IAAI;AAEJ,QAAM,UAAU,QAAQ,SAAS,GAAG,IAAI,QAAQ,MAAM,GAAG,EAAE,IAAI;AAE/D,WAAS,OAAO,OAAe,YAAoB,IAAoB;AACrE,UAAM,WAAW,CAAC,QAAQ,OAAO,YAAY,GAAG,EAAE,OAAO,EACtD,OAAO,OAAO,EACd,IAAI,kBAAkB;AACzB,WAAO,GAAG,OAAO,IAAI,SAAS,KAAK,GAAG,CAAC;AAAA,EACzC;AAEA,WAAS,cAAc,OAAe,YAA4B;AAChE,UAAM,WAAW,CAAC,QAAQ,OAAO,UAAU,EAAE,OAAO,OAAO,EAAE,IAAI,kBAAkB;AACnF,WAAO,GAAG,OAAO,IAAI,SAAS,KAAK,GAAG,CAAC;AAAA,EACzC;AAEA,iBAAe,eAAe,OAAe,YAAoC;AAC/E,UAAM,QAAQ,CAAC,QAAQ,OAAO,GAAI,aAAa,CAAC,UAAU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AAM,MAAM,aAAa,OAAO,UAAU;AAChD,cAAM,SAA4C,CAAC;AACnD,mBAAW,MAAM,KAAK;AACpB,gBAAM,MAAM,MAAM,MAAM,IAAI,OAAO,YAAY,EAAE;AACjD,cAAI,IAAK,QAAO,EAAE,IAAI;AAAA,QACxB;AACA,aAAK,UAAU,IAAI;AAAA,MACrB;AACA,aAAO;AAAA,IACT;AAAA,IAEA,MAAM,QAAQ,OAAO,MAAM;AACzB,iBAAW,CAAC,YAAY,IAAI,KAAK,OAAO,QAAQ,IAAI,GAAG;AACrD,cAAM,eAAe,OAAO,UAAU;AACtC,mBAAW,CAAC,IAAI,QAAQ,KAAK,OAAO,QAAQ,IAAI,GAAG;AACjD,gBAAM,MAAM,IAAI,OAAO,YAAY,IAAI,QAAQ;AAAA,QACjD;AAAA,MACF;AAAA,IACF;AAAA,IAEA,MAAM,OAAO;AACX,UAAI;AACF,cAAM,MAAM,MAAM,UAAU,UAAU,KAAK;AAAA,UACzC,QAAQ;AAAA,UACR,SAAS,EAAE,GAAG,aAAa,OAAO,IAAI;AAAA,QACxC,CAAC;AACD,eAAO,IAAI,MAAM,IAAI,WAAW;AAAA,MAClC,QAAQ;AACN,eAAO;AAAA,MACT;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AACT;","names":[]}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { NoydbStore } from '@noy-db/hub';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* **@noy-db/to-webdav** — WebDAV-backed noy-db store.
|
|
5
|
+
*
|
|
6
|
+
* Per-record JSON objects over the WebDAV protocol (RFC 4918). Works
|
|
7
|
+
* against Nextcloud, ownCloud, Apache `mod_dav`, nginx WebDAV, or any
|
|
8
|
+
* compliant server. Pure `fetch()` — zero dependencies.
|
|
9
|
+
*
|
|
10
|
+
* Key path:
|
|
11
|
+
* `{baseUrl}/{prefix}/{vault}/{collection}/{id}.json`
|
|
12
|
+
*
|
|
13
|
+
* ## Capabilities
|
|
14
|
+
*
|
|
15
|
+
* | Capability | Value |
|
|
16
|
+
* |-------------|-------|
|
|
17
|
+
* | `casAtomic` | `false` — WebDAV has no atomic CAS; last-write-wins |
|
|
18
|
+
* | `listPage` | ✗ — `PROPFIND` Depth:1 returns the whole collection |
|
|
19
|
+
* | `ping` | ✓ — `PROPFIND Depth:0` on the root |
|
|
20
|
+
*
|
|
21
|
+
* For conflict-safe writes pair with `@noy-db/to-aws-dynamo` or
|
|
22
|
+
* `@noy-db/to-postgres` as the primary and use WebDAV as a
|
|
23
|
+
* `backup`/`archive` target in `routeStore`.
|
|
24
|
+
*
|
|
25
|
+
* ## Authentication
|
|
26
|
+
*
|
|
27
|
+
* WebDAV commonly uses Basic Auth. Pass an `Authorization` header via
|
|
28
|
+
* `headers`, or override `fetch` with a wrapper that injects your
|
|
29
|
+
* credentials (session token, app password, OAuth token).
|
|
30
|
+
*
|
|
31
|
+
* @packageDocumentation
|
|
32
|
+
*/
|
|
33
|
+
|
|
34
|
+
interface WebDAVStoreOptions {
|
|
35
|
+
/** Base URL of the WebDAV endpoint (with trailing slash optional). */
|
|
36
|
+
readonly baseUrl: string;
|
|
37
|
+
/** Path prefix within the endpoint. Default `''`. */
|
|
38
|
+
readonly prefix?: string;
|
|
39
|
+
/** Default headers sent with every request (e.g. Authorization). */
|
|
40
|
+
readonly headers?: Record<string, string>;
|
|
41
|
+
/** Custom fetch — defaults to `globalThis.fetch`. */
|
|
42
|
+
readonly fetch?: typeof fetch;
|
|
43
|
+
/**
|
|
44
|
+
* When `true` (default), PUT errors from missing parent collections
|
|
45
|
+
* are recovered by MKCOL'ing the path and retrying once. Set to
|
|
46
|
+
* `false` if the server already has the tree provisioned.
|
|
47
|
+
*/
|
|
48
|
+
readonly autoMkcol?: boolean;
|
|
49
|
+
/**
|
|
50
|
+
* When `true`, MKCOL the full path tree before EVERY put — not just
|
|
51
|
+
* as a 404/409 fallback. Default `false`.
|
|
52
|
+
*
|
|
53
|
+
* Required for non-RFC-compliant servers (notably DriveHQ free tier
|
|
54
|
+
* and some embedded NAS firmwares) that return `204 No Content` on a
|
|
55
|
+
* PUT to a non-existent path AND silently flatten the file to the
|
|
56
|
+
* server root instead of preserving the requested path. Without
|
|
57
|
+
* eager MKCOL, the package's lazy fallback never fires (no 4xx to
|
|
58
|
+
* trigger it) and writes silently land at the wrong location.
|
|
59
|
+
*
|
|
60
|
+
* Adds one extra round-trip per put; only enable when you've
|
|
61
|
+
* confirmed your server has this quirk.
|
|
62
|
+
*/
|
|
63
|
+
readonly eagerMkcol?: boolean;
|
|
64
|
+
}
|
|
65
|
+
declare function webdav(options: WebDAVStoreOptions): NoydbStore;
|
|
66
|
+
|
|
67
|
+
export { type WebDAVStoreOptions, webdav };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { NoydbStore } from '@noy-db/hub';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* **@noy-db/to-webdav** — WebDAV-backed noy-db store.
|
|
5
|
+
*
|
|
6
|
+
* Per-record JSON objects over the WebDAV protocol (RFC 4918). Works
|
|
7
|
+
* against Nextcloud, ownCloud, Apache `mod_dav`, nginx WebDAV, or any
|
|
8
|
+
* compliant server. Pure `fetch()` — zero dependencies.
|
|
9
|
+
*
|
|
10
|
+
* Key path:
|
|
11
|
+
* `{baseUrl}/{prefix}/{vault}/{collection}/{id}.json`
|
|
12
|
+
*
|
|
13
|
+
* ## Capabilities
|
|
14
|
+
*
|
|
15
|
+
* | Capability | Value |
|
|
16
|
+
* |-------------|-------|
|
|
17
|
+
* | `casAtomic` | `false` — WebDAV has no atomic CAS; last-write-wins |
|
|
18
|
+
* | `listPage` | ✗ — `PROPFIND` Depth:1 returns the whole collection |
|
|
19
|
+
* | `ping` | ✓ — `PROPFIND Depth:0` on the root |
|
|
20
|
+
*
|
|
21
|
+
* For conflict-safe writes pair with `@noy-db/to-aws-dynamo` or
|
|
22
|
+
* `@noy-db/to-postgres` as the primary and use WebDAV as a
|
|
23
|
+
* `backup`/`archive` target in `routeStore`.
|
|
24
|
+
*
|
|
25
|
+
* ## Authentication
|
|
26
|
+
*
|
|
27
|
+
* WebDAV commonly uses Basic Auth. Pass an `Authorization` header via
|
|
28
|
+
* `headers`, or override `fetch` with a wrapper that injects your
|
|
29
|
+
* credentials (session token, app password, OAuth token).
|
|
30
|
+
*
|
|
31
|
+
* @packageDocumentation
|
|
32
|
+
*/
|
|
33
|
+
|
|
34
|
+
interface WebDAVStoreOptions {
|
|
35
|
+
/** Base URL of the WebDAV endpoint (with trailing slash optional). */
|
|
36
|
+
readonly baseUrl: string;
|
|
37
|
+
/** Path prefix within the endpoint. Default `''`. */
|
|
38
|
+
readonly prefix?: string;
|
|
39
|
+
/** Default headers sent with every request (e.g. Authorization). */
|
|
40
|
+
readonly headers?: Record<string, string>;
|
|
41
|
+
/** Custom fetch — defaults to `globalThis.fetch`. */
|
|
42
|
+
readonly fetch?: typeof fetch;
|
|
43
|
+
/**
|
|
44
|
+
* When `true` (default), PUT errors from missing parent collections
|
|
45
|
+
* are recovered by MKCOL'ing the path and retrying once. Set to
|
|
46
|
+
* `false` if the server already has the tree provisioned.
|
|
47
|
+
*/
|
|
48
|
+
readonly autoMkcol?: boolean;
|
|
49
|
+
/**
|
|
50
|
+
* When `true`, MKCOL the full path tree before EVERY put — not just
|
|
51
|
+
* as a 404/409 fallback. Default `false`.
|
|
52
|
+
*
|
|
53
|
+
* Required for non-RFC-compliant servers (notably DriveHQ free tier
|
|
54
|
+
* and some embedded NAS firmwares) that return `204 No Content` on a
|
|
55
|
+
* PUT to a non-existent path AND silently flatten the file to the
|
|
56
|
+
* server root instead of preserving the requested path. Without
|
|
57
|
+
* eager MKCOL, the package's lazy fallback never fires (no 4xx to
|
|
58
|
+
* trigger it) and writes silently land at the wrong location.
|
|
59
|
+
*
|
|
60
|
+
* Adds one extra round-trip per put; only enable when you've
|
|
61
|
+
* confirmed your server has this quirk.
|
|
62
|
+
*/
|
|
63
|
+
readonly eagerMkcol?: boolean;
|
|
64
|
+
}
|
|
65
|
+
declare function webdav(options: WebDAVStoreOptions): NoydbStore;
|
|
66
|
+
|
|
67
|
+
export { type WebDAVStoreOptions, webdav };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
function webdav(options) {
|
|
3
|
+
const {
|
|
4
|
+
baseUrl: rawBase,
|
|
5
|
+
prefix = "",
|
|
6
|
+
headers: baseHeaders = {},
|
|
7
|
+
fetch: fetchImpl = globalThis.fetch.bind(globalThis),
|
|
8
|
+
autoMkcol = true,
|
|
9
|
+
eagerMkcol = false
|
|
10
|
+
} = options;
|
|
11
|
+
const baseUrl = rawBase.endsWith("/") ? rawBase.slice(0, -1) : rawBase;
|
|
12
|
+
function urlFor(vault, collection, id) {
|
|
13
|
+
const segments = [prefix, vault, collection, `${id}.json`].filter(Boolean).map(encodeURIComponent);
|
|
14
|
+
return `${baseUrl}/${segments.join("/")}`;
|
|
15
|
+
}
|
|
16
|
+
function collectionUrl(vault, collection) {
|
|
17
|
+
const segments = [prefix, vault, collection].filter(Boolean).map(encodeURIComponent);
|
|
18
|
+
return `${baseUrl}/${segments.join("/")}/`;
|
|
19
|
+
}
|
|
20
|
+
async function mkcolRecursive(vault, collection) {
|
|
21
|
+
const parts = [prefix, vault, ...collection ? [collection] : []].filter(Boolean);
|
|
22
|
+
let url = baseUrl;
|
|
23
|
+
for (const part of parts) {
|
|
24
|
+
url += `/${encodeURIComponent(part)}`;
|
|
25
|
+
const res = await fetchImpl(url + "/", { method: "MKCOL", headers: baseHeaders });
|
|
26
|
+
if (res.status >= 500) {
|
|
27
|
+
throw new Error(`WebDAV MKCOL failed at ${url}: ${res.status}`);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
async function putOnce(vault, collection, id, body) {
|
|
32
|
+
return fetchImpl(urlFor(vault, collection, id), {
|
|
33
|
+
method: "PUT",
|
|
34
|
+
headers: {
|
|
35
|
+
...baseHeaders,
|
|
36
|
+
"Content-Type": "application/json"
|
|
37
|
+
},
|
|
38
|
+
body
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
const PROPFIND_BODY = `<?xml version="1.0" encoding="utf-8"?>
|
|
42
|
+
<d:propfind xmlns:d="DAV:"><d:prop><d:resourcetype/></d:prop></d:propfind>`;
|
|
43
|
+
async function listChildren(vault, collection) {
|
|
44
|
+
const url = collectionUrl(vault, collection);
|
|
45
|
+
const res = await fetchImpl(url, {
|
|
46
|
+
method: "PROPFIND",
|
|
47
|
+
headers: {
|
|
48
|
+
...baseHeaders,
|
|
49
|
+
Depth: "1",
|
|
50
|
+
"Content-Type": "application/xml"
|
|
51
|
+
},
|
|
52
|
+
body: PROPFIND_BODY
|
|
53
|
+
});
|
|
54
|
+
if (res.status === 404) return [];
|
|
55
|
+
if (!res.ok && res.status !== 207) {
|
|
56
|
+
throw new Error(`WebDAV PROPFIND failed: ${res.status}`);
|
|
57
|
+
}
|
|
58
|
+
const xml = await res.text();
|
|
59
|
+
const hrefs = Array.from(xml.matchAll(/<(?:\w+:)?href>([^<]+)<\/(?:\w+:)?href>/g)).map((m) => decodeURIComponent(m[1]));
|
|
60
|
+
const selfPath = new URL(url).pathname.replace(/\/+$/, "");
|
|
61
|
+
const ids = [];
|
|
62
|
+
for (const href of hrefs) {
|
|
63
|
+
const hrefPath = href.replace(/\/+$/, "");
|
|
64
|
+
if (hrefPath === selfPath) continue;
|
|
65
|
+
const filename = hrefPath.split("/").pop();
|
|
66
|
+
if (!filename.endsWith(".json")) continue;
|
|
67
|
+
ids.push(filename.slice(0, -".json".length));
|
|
68
|
+
}
|
|
69
|
+
return ids.sort();
|
|
70
|
+
}
|
|
71
|
+
const store = {
|
|
72
|
+
name: "webdav",
|
|
73
|
+
async get(vault, collection, id) {
|
|
74
|
+
const res = await fetchImpl(urlFor(vault, collection, id), {
|
|
75
|
+
method: "GET",
|
|
76
|
+
headers: baseHeaders
|
|
77
|
+
});
|
|
78
|
+
if (res.status === 404) return null;
|
|
79
|
+
if (!res.ok) throw new Error(`WebDAV GET failed: ${res.status}`);
|
|
80
|
+
const text = await res.text();
|
|
81
|
+
return JSON.parse(text);
|
|
82
|
+
},
|
|
83
|
+
async put(vault, collection, id, envelope) {
|
|
84
|
+
const body = JSON.stringify(envelope);
|
|
85
|
+
if (eagerMkcol) {
|
|
86
|
+
await mkcolRecursive(vault, collection);
|
|
87
|
+
}
|
|
88
|
+
let res = await putOnce(vault, collection, id, body);
|
|
89
|
+
if ((res.status === 404 || res.status === 409) && autoMkcol) {
|
|
90
|
+
await mkcolRecursive(vault, collection);
|
|
91
|
+
res = await putOnce(vault, collection, id, body);
|
|
92
|
+
}
|
|
93
|
+
if (!res.ok) throw new Error(`WebDAV PUT failed: ${res.status}`);
|
|
94
|
+
},
|
|
95
|
+
async delete(vault, collection, id) {
|
|
96
|
+
const res = await fetchImpl(urlFor(vault, collection, id), {
|
|
97
|
+
method: "DELETE",
|
|
98
|
+
headers: baseHeaders
|
|
99
|
+
});
|
|
100
|
+
if (res.status !== 204 && res.status !== 404 && !res.ok) {
|
|
101
|
+
throw new Error(`WebDAV DELETE failed: ${res.status}`);
|
|
102
|
+
}
|
|
103
|
+
},
|
|
104
|
+
async list(vault, collection) {
|
|
105
|
+
return listChildren(vault, collection);
|
|
106
|
+
},
|
|
107
|
+
async loadAll(vault) {
|
|
108
|
+
const rootUrl = `${baseUrl}/${[prefix, vault].filter(Boolean).map(encodeURIComponent).join("/")}/`;
|
|
109
|
+
const res = await fetchImpl(rootUrl, {
|
|
110
|
+
method: "PROPFIND",
|
|
111
|
+
headers: { ...baseHeaders, Depth: "1", "Content-Type": "application/xml" },
|
|
112
|
+
body: PROPFIND_BODY
|
|
113
|
+
});
|
|
114
|
+
if (res.status === 404) return {};
|
|
115
|
+
if (!res.ok && res.status !== 207) {
|
|
116
|
+
throw new Error(`WebDAV PROPFIND (loadAll) failed: ${res.status}`);
|
|
117
|
+
}
|
|
118
|
+
const xml = await res.text();
|
|
119
|
+
const hrefs = Array.from(xml.matchAll(/<(?:\w+:)?href>([^<]+)<\/(?:\w+:)?href>/g)).map((m) => decodeURIComponent(m[1]));
|
|
120
|
+
const selfPath = new URL(rootUrl).pathname.replace(/\/+$/, "");
|
|
121
|
+
const collections = /* @__PURE__ */ new Set();
|
|
122
|
+
for (const href of hrefs) {
|
|
123
|
+
const hrefPath = href.replace(/\/+$/, "");
|
|
124
|
+
if (hrefPath === selfPath) continue;
|
|
125
|
+
const segment = hrefPath.slice(selfPath.length + 1).split("/")[0];
|
|
126
|
+
if (segment) collections.add(decodeURIComponent(segment));
|
|
127
|
+
}
|
|
128
|
+
const snap = {};
|
|
129
|
+
for (const collection of collections) {
|
|
130
|
+
const ids = await listChildren(vault, collection);
|
|
131
|
+
const bucket = {};
|
|
132
|
+
for (const id of ids) {
|
|
133
|
+
const env = await store.get(vault, collection, id);
|
|
134
|
+
if (env) bucket[id] = env;
|
|
135
|
+
}
|
|
136
|
+
snap[collection] = bucket;
|
|
137
|
+
}
|
|
138
|
+
return snap;
|
|
139
|
+
},
|
|
140
|
+
async saveAll(vault, data) {
|
|
141
|
+
for (const [collection, recs] of Object.entries(data)) {
|
|
142
|
+
await mkcolRecursive(vault, collection);
|
|
143
|
+
for (const [id, envelope] of Object.entries(recs)) {
|
|
144
|
+
await store.put(vault, collection, id, envelope);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
},
|
|
148
|
+
async ping() {
|
|
149
|
+
try {
|
|
150
|
+
const res = await fetchImpl(baseUrl + "/", {
|
|
151
|
+
method: "PROPFIND",
|
|
152
|
+
headers: { ...baseHeaders, Depth: "0" }
|
|
153
|
+
});
|
|
154
|
+
return res.ok || res.status === 207;
|
|
155
|
+
} catch {
|
|
156
|
+
return false;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
};
|
|
160
|
+
return store;
|
|
161
|
+
}
|
|
162
|
+
export {
|
|
163
|
+
webdav
|
|
164
|
+
};
|
|
165
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["/**\n * **@noy-db/to-webdav** — WebDAV-backed noy-db store.\n *\n * Per-record JSON objects over the WebDAV protocol (RFC 4918). Works\n * against Nextcloud, ownCloud, Apache `mod_dav`, nginx WebDAV, or any\n * compliant server. Pure `fetch()` — zero dependencies.\n *\n * Key path:\n * `{baseUrl}/{prefix}/{vault}/{collection}/{id}.json`\n *\n * ## Capabilities\n *\n * | Capability | Value |\n * |-------------|-------|\n * | `casAtomic` | `false` — WebDAV has no atomic CAS; last-write-wins |\n * | `listPage` | ✗ — `PROPFIND` Depth:1 returns the whole collection |\n * | `ping` | ✓ — `PROPFIND Depth:0` on the root |\n *\n * For conflict-safe writes pair with `@noy-db/to-aws-dynamo` or\n * `@noy-db/to-postgres` as the primary and use WebDAV as a\n * `backup`/`archive` target in `routeStore`.\n *\n * ## Authentication\n *\n * WebDAV commonly uses Basic Auth. Pass an `Authorization` header via\n * `headers`, or override `fetch` with a wrapper that injects your\n * credentials (session token, app password, OAuth token).\n *\n * @packageDocumentation\n */\n\nimport type { NoydbStore, EncryptedEnvelope, VaultSnapshot } from '@noy-db/hub'\n\nexport interface WebDAVStoreOptions {\n /** Base URL of the WebDAV endpoint (with trailing slash optional). */\n readonly baseUrl: string\n /** Path prefix within the endpoint. Default `''`. */\n readonly prefix?: string\n /** Default headers sent with every request (e.g. Authorization). */\n readonly headers?: Record<string, string>\n /** Custom fetch — defaults to `globalThis.fetch`. */\n readonly fetch?: typeof fetch\n /**\n * When `true` (default), PUT errors from missing parent collections\n * are recovered by MKCOL'ing the path and retrying once. Set to\n * `false` if the server already has the tree provisioned.\n */\n readonly autoMkcol?: boolean\n /**\n * When `true`, MKCOL the full path tree before EVERY put — not just\n * as a 404/409 fallback. Default `false`.\n *\n * Required for non-RFC-compliant servers (notably DriveHQ free tier\n * and some embedded NAS firmwares) that return `204 No Content` on a\n * PUT to a non-existent path AND silently flatten the file to the\n * server root instead of preserving the requested path. Without\n * eager MKCOL, the package's lazy fallback never fires (no 4xx to\n * trigger it) and writes silently land at the wrong location.\n *\n * Adds one extra round-trip per put; only enable when you've\n * confirmed your server has this quirk.\n */\n readonly eagerMkcol?: boolean\n}\n\nexport function webdav(options: WebDAVStoreOptions): NoydbStore {\n const {\n baseUrl: rawBase,\n prefix = '',\n headers: baseHeaders = {},\n fetch: fetchImpl = globalThis.fetch.bind(globalThis),\n autoMkcol = true,\n eagerMkcol = false,\n } = options\n\n const baseUrl = rawBase.endsWith('/') ? rawBase.slice(0, -1) : rawBase\n\n function urlFor(vault: string, collection: string, id: string): string {\n const segments = [prefix, vault, collection, `${id}.json`]\n .filter(Boolean)\n .map(encodeURIComponent)\n return `${baseUrl}/${segments.join('/')}`\n }\n\n function collectionUrl(vault: string, collection: string): string {\n const segments = [prefix, vault, collection].filter(Boolean).map(encodeURIComponent)\n return `${baseUrl}/${segments.join('/')}/`\n }\n\n async function mkcolRecursive(vault: string, collection?: string): Promise<void> {\n const parts = [prefix, vault, ...(collection ? [collection] : [])].filter(Boolean)\n let url = baseUrl\n for (const part of parts) {\n url += `/${encodeURIComponent(part)}`\n const res = await fetchImpl(url + '/', { method: 'MKCOL', headers: baseHeaders })\n // 201 Created, 405 Method Not Allowed (exists), and 409 Conflict are all\n // acceptable — we only fail on transport-level errors.\n if (res.status >= 500) {\n throw new Error(`WebDAV MKCOL failed at ${url}: ${res.status}`)\n }\n }\n }\n\n async function putOnce(vault: string, collection: string, id: string, body: string): Promise<Response> {\n return fetchImpl(urlFor(vault, collection, id), {\n method: 'PUT',\n headers: {\n ...baseHeaders,\n 'Content-Type': 'application/json',\n },\n body,\n })\n }\n\n // Very small PROPFIND XML body — we only need child hrefs.\n const PROPFIND_BODY = `<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<d:propfind xmlns:d=\"DAV:\"><d:prop><d:resourcetype/></d:prop></d:propfind>`\n\n async function listChildren(vault: string, collection: string): Promise<string[]> {\n const url = collectionUrl(vault, collection)\n const res = await fetchImpl(url, {\n method: 'PROPFIND',\n headers: {\n ...baseHeaders,\n Depth: '1',\n 'Content-Type': 'application/xml',\n },\n body: PROPFIND_BODY,\n })\n if (res.status === 404) return []\n if (!res.ok && res.status !== 207) {\n throw new Error(`WebDAV PROPFIND failed: ${res.status}`)\n }\n const xml = await res.text()\n // Extract <d:href>...</d:href> entries, drop the collection self-ref,\n // keep only .json leaves, and return the id portion.\n const hrefs = Array.from(xml.matchAll(/<(?:\\w+:)?href>([^<]+)<\\/(?:\\w+:)?href>/g))\n .map(m => decodeURIComponent(m[1]!))\n const selfPath = new URL(url).pathname.replace(/\\/+$/, '')\n const ids: string[] = []\n for (const href of hrefs) {\n const hrefPath = href.replace(/\\/+$/, '')\n if (hrefPath === selfPath) continue\n const filename = hrefPath.split('/').pop()!\n if (!filename.endsWith('.json')) continue\n ids.push(filename.slice(0, -'.json'.length))\n }\n return ids.sort()\n }\n\n const store: NoydbStore = {\n name: 'webdav',\n\n async get(vault, collection, id) {\n const res = await fetchImpl(urlFor(vault, collection, id), {\n method: 'GET',\n headers: baseHeaders,\n })\n if (res.status === 404) return null\n if (!res.ok) throw new Error(`WebDAV GET failed: ${res.status}`)\n const text = await res.text()\n return JSON.parse(text) as EncryptedEnvelope\n },\n\n async put(vault, collection, id, envelope) {\n // Note: casAtomic:false — expectedVersion is IGNORED. WebDAV\n // lacks server-side conditional metadata writes.\n const body = JSON.stringify(envelope)\n // Eager MKCOL: required for non-RFC servers (DriveHQ etc.) that\n // accept PUT-to-nonexistent with 204 and silently flatten.\n if (eagerMkcol) {\n await mkcolRecursive(vault, collection)\n }\n let res = await putOnce(vault, collection, id, body)\n if ((res.status === 404 || res.status === 409) && autoMkcol) {\n await mkcolRecursive(vault, collection)\n res = await putOnce(vault, collection, id, body)\n }\n if (!res.ok) throw new Error(`WebDAV PUT failed: ${res.status}`)\n },\n\n async delete(vault, collection, id) {\n const res = await fetchImpl(urlFor(vault, collection, id), {\n method: 'DELETE',\n headers: baseHeaders,\n })\n if (res.status !== 204 && res.status !== 404 && !res.ok) {\n throw new Error(`WebDAV DELETE failed: ${res.status}`)\n }\n },\n\n async list(vault, collection) {\n return listChildren(vault, collection)\n },\n\n async loadAll(vault) {\n const rootUrl = `${baseUrl}/${[prefix, vault].filter(Boolean).map(encodeURIComponent).join('/')}/`\n const res = await fetchImpl(rootUrl, {\n method: 'PROPFIND',\n headers: { ...baseHeaders, Depth: '1', 'Content-Type': 'application/xml' },\n body: PROPFIND_BODY,\n })\n if (res.status === 404) return {}\n if (!res.ok && res.status !== 207) {\n throw new Error(`WebDAV PROPFIND (loadAll) failed: ${res.status}`)\n }\n const xml = await res.text()\n const hrefs = Array.from(xml.matchAll(/<(?:\\w+:)?href>([^<]+)<\\/(?:\\w+:)?href>/g))\n .map(m => decodeURIComponent(m[1]!))\n const selfPath = new URL(rootUrl).pathname.replace(/\\/+$/, '')\n const collections = new Set<string>()\n for (const href of hrefs) {\n const hrefPath = href.replace(/\\/+$/, '')\n if (hrefPath === selfPath) continue\n const segment = hrefPath.slice(selfPath.length + 1).split('/')[0]\n if (segment) collections.add(decodeURIComponent(segment))\n }\n const snap: VaultSnapshot = {}\n for (const collection of collections) {\n const ids = await listChildren(vault, collection)\n const bucket: Record<string, EncryptedEnvelope> = {}\n for (const id of ids) {\n const env = await store.get(vault, collection, id)\n if (env) bucket[id] = env\n }\n snap[collection] = bucket\n }\n return snap\n },\n\n async saveAll(vault, data) {\n for (const [collection, recs] of Object.entries(data)) {\n await mkcolRecursive(vault, collection)\n for (const [id, envelope] of Object.entries(recs)) {\n await store.put(vault, collection, id, envelope)\n }\n }\n },\n\n async ping() {\n try {\n const res = await fetchImpl(baseUrl + '/', {\n method: 'PROPFIND',\n headers: { ...baseHeaders, Depth: '0' },\n })\n return res.ok || res.status === 207\n } catch {\n return false\n }\n },\n }\n\n return store\n}\n"],"mappings":";AAiEO,S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;AAAA,QACjD;AAAA,MACF;AAAA,IACF;AAAA,IAEA,MAAM,OAAO;AACX,UAAI;AACF,cAAM,MAAM,MAAM,UAAU,UAAU,KAAK;AAAA,UACzC,QAAQ;AAAA,UACR,SAAS,EAAE,GAAG,aAAa,OAAO,IAAI;AAAA,QACxC,CAAC;AACD,eAAO,IAAI,MAAM,IAAI,WAAW;AAAA,MAClC,QAAQ;AACN,eAAO;AAAA,MACT;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AACT;","names":[]}
|
package/package.json
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@noy-db/to-webdav",
|
|
3
|
+
"version": "0.1.0-pre.3",
|
|
4
|
+
"description": "WebDAV adapter for noy-db — encrypted object storage over the WebDAV protocol. Works with Nextcloud, ownCloud, Apache mod_dav, and any RFC 4918 server. Pure fetch()-based, zero dependencies.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "vLannaAi <vicio@lanna.ai>",
|
|
7
|
+
"homepage": "https://github.com/vLannaAi/noy-db/tree/main/packages/to-webdav#readme",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/vLannaAi/noy-db.git",
|
|
11
|
+
"directory": "packages/to-webdav"
|
|
12
|
+
},
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/vLannaAi/noy-db/issues"
|
|
15
|
+
},
|
|
16
|
+
"type": "module",
|
|
17
|
+
"sideEffects": false,
|
|
18
|
+
"exports": {
|
|
19
|
+
".": {
|
|
20
|
+
"import": {
|
|
21
|
+
"types": "./dist/index.d.ts",
|
|
22
|
+
"default": "./dist/index.js"
|
|
23
|
+
},
|
|
24
|
+
"require": {
|
|
25
|
+
"types": "./dist/index.d.cts",
|
|
26
|
+
"default": "./dist/index.cjs"
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
"main": "./dist/index.cjs",
|
|
31
|
+
"module": "./dist/index.js",
|
|
32
|
+
"types": "./dist/index.d.ts",
|
|
33
|
+
"files": [
|
|
34
|
+
"dist",
|
|
35
|
+
"README.md",
|
|
36
|
+
"LICENSE"
|
|
37
|
+
],
|
|
38
|
+
"engines": {
|
|
39
|
+
"node": ">=18.0.0"
|
|
40
|
+
},
|
|
41
|
+
"peerDependencies": {
|
|
42
|
+
"@noy-db/hub": "0.1.0-pre.3"
|
|
43
|
+
},
|
|
44
|
+
"devDependencies": {
|
|
45
|
+
"@types/node": "^22.0.0",
|
|
46
|
+
"@noy-db/hub": "0.1.0-pre.3"
|
|
47
|
+
},
|
|
48
|
+
"keywords": [
|
|
49
|
+
"noy-db",
|
|
50
|
+
"to-webdav",
|
|
51
|
+
"webdav",
|
|
52
|
+
"nextcloud",
|
|
53
|
+
"owncloud",
|
|
54
|
+
"storage"
|
|
55
|
+
],
|
|
56
|
+
"publishConfig": {
|
|
57
|
+
"access": "public",
|
|
58
|
+
"tag": "latest"
|
|
59
|
+
},
|
|
60
|
+
"scripts": {
|
|
61
|
+
"build": "tsup",
|
|
62
|
+
"test": "vitest run",
|
|
63
|
+
"lint": "eslint src/",
|
|
64
|
+
"typecheck": "tsc --noEmit"
|
|
65
|
+
}
|
|
66
|
+
}
|