@myfield/sdk 0.9.1 → 0.9.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 +20 -0
- package/README.md +34 -54
- package/dist/index.js +1768 -648
- package/docs/API.md +143 -56
- package/docs/BUCKET-SPEC.md +5 -0
- package/package.json +4 -2
- package/src/auth/authorization.ts +254 -0
- package/src/auth/flow.ts +93 -0
- package/src/auth/identifiers.ts +46 -0
- package/src/auth/instance.ts +33 -514
- package/src/auth/keys.ts +73 -0
- package/src/auth/proof.ts +26 -0
- package/src/auth/session.ts +16 -0
- package/src/auth/store.ts +90 -0
- package/src/auth/types.ts +47 -0
- package/src/bucket/client.ts +6 -1
- package/src/bucket/store.ts +31 -0
- package/src/bucket/transport.ts +28 -6
- package/src/errors.ts +31 -0
- package/src/facade.ts +248 -323
- package/src/index.ts +6 -0
- package/src/remote/bucket.ts +180 -0
- package/src/remote/client.ts +38 -0
- package/src/remote/connection.ts +529 -0
- package/src/remote/feed.ts +80 -0
- package/src/remote/http.ts +78 -0
- package/src/remote/session.ts +31 -0
- package/types/index.d.ts +85 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,25 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.9.2
|
|
4
|
+
|
|
5
|
+
### Added
|
|
6
|
+
- Unified Instance APIs for connection, state events and Local bucket access,
|
|
7
|
+
with optional automatic sync.
|
|
8
|
+
- Remote APIs for object reads, CAS commits, version history and feed notifications,
|
|
9
|
+
including bucket-key access for app-managed encryption.
|
|
10
|
+
- Instance key creation, retrieval, import and removal.
|
|
11
|
+
|
|
12
|
+
### Fixed
|
|
13
|
+
- Connection races during startup and incorrect upload-success handling.
|
|
14
|
+
|
|
15
|
+
### Compatibility
|
|
16
|
+
- String initialization now means `appId`; use `namespace` to preserve an existing
|
|
17
|
+
storage scope.
|
|
18
|
+
- Configure authorization with `createInstance({ authUrl })` instead of
|
|
19
|
+
`bucket.connect({ authBase })`.
|
|
20
|
+
- `bucket.ready()` is now a deprecated no-op. Existing stored keys and Local data
|
|
21
|
+
formats remain supported.
|
|
22
|
+
|
|
3
23
|
## 0.9.1
|
|
4
24
|
|
|
5
25
|
- Sync uses the relay's object index; `~index` is no longer pushed.
|
package/README.md
CHANGED
|
@@ -3,29 +3,18 @@
|
|
|
3
3
|
Myfield SDK for third-party web apps: local-first object storage,
|
|
4
4
|
end-to-end-encrypted sync, and internal Myfield authorization.
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
uploads may transiently fail (rate limits), and local storage is the source
|
|
11
|
-
of truth.
|
|
12
|
-
|
|
13
|
-
Status: 1.0 preview. `0.9.0` reflects our assessment that the SDK design has
|
|
14
|
-
reached its baseline shape; minor adjustments — including to the public API
|
|
15
|
-
— are still possible before 1.0 based on community feedback and real-world
|
|
16
|
-
use, and 1.0 will freeze the API/protocol, with later versions extending it
|
|
17
|
-
while keeping compatibility. License: Apache-2.0.
|
|
6
|
+
A bucket is a local-first **end-to-end-encrypted object KV with CAS-backed sync**.
|
|
7
|
+
Local CRUD works without an account or network; `connect()` authorizes cloud access.
|
|
8
|
+
|
|
9
|
+
Status: pre-1.0 preview; public APIs may change before 1.0. License: Apache-2.0.
|
|
18
10
|
|
|
19
11
|
## Quickstart
|
|
20
12
|
|
|
21
13
|
```ts
|
|
22
14
|
import { createInstance } from "@myfield/sdk";
|
|
23
15
|
|
|
24
|
-
const instance = createInstance();
|
|
25
|
-
const bucket = instance.
|
|
26
|
-
|
|
27
|
-
// On startup: resume an existing authorization / handle an auth callback.
|
|
28
|
-
await bucket.resume();
|
|
16
|
+
const instance = createInstance("notes.example.com");
|
|
17
|
+
const bucket = instance.getBucket();
|
|
29
18
|
|
|
30
19
|
// Local-first object CRUD works before authorization.
|
|
31
20
|
await bucket.put("note:1", { title: "hello", body: "world" });
|
|
@@ -33,39 +22,44 @@ const note = await bucket.get("note:1");
|
|
|
33
22
|
await bucket.update("note:1", { body: undefined }); // deletes the field
|
|
34
23
|
const entries = await bucket.list({ prefix: "note:" });
|
|
35
24
|
|
|
25
|
+
// Restore access in the background after loading local data.
|
|
26
|
+
void instance.resume().catch(error => console.error("Connection failed:", error));
|
|
27
|
+
|
|
36
28
|
// On the user's "Connect" click: run the authorization flow (popup, or
|
|
37
29
|
// same-tab on iOS).
|
|
38
|
-
await
|
|
30
|
+
await instance.connect(); // defaults to https://myfield.one/auth/
|
|
39
31
|
```
|
|
40
32
|
|
|
33
|
+
Full API reference: [`docs/API.md`](docs/API.md).
|
|
34
|
+
|
|
35
|
+
## Remote object access
|
|
36
|
+
|
|
37
|
+
`instance.remote.getBucket()` provides object reads, CAS commits, version history and
|
|
38
|
+
change notifications with the instance's authorization; the app owns payload encryption
|
|
39
|
+
and local storage, encrypting with `getBucketKey()`. See
|
|
40
|
+
[Remote Object API](docs/API.md#remote-object-api).
|
|
41
|
+
|
|
41
42
|
## What the SDK handles
|
|
42
43
|
|
|
43
44
|
- **Auth**: instance keygen, the `https://myfield.one/auth/` authorization
|
|
44
45
|
flow (popup / same-tab), callback decryption, bearer session refresh, and
|
|
45
|
-
the unauthorized → disconnected transition. Apps
|
|
46
|
+
the unauthorized → disconnected transition. Apps use Instance
|
|
46
47
|
`connect()` / `disconnect()` / state events only.
|
|
47
|
-
- **Pairwise identity**:
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
- **Encryption**: payloads are encrypted client-side; the platform stores
|
|
48
|
+
- **Pairwise identity**: apps receive app-specific aliases rather than the user's
|
|
49
|
+
primary Myfield identity.
|
|
50
|
+
- **Encryption**: Local payloads are encrypted client-side; the platform stores
|
|
51
51
|
ciphertext only. Object ids are blinded — your semantic ids
|
|
52
|
-
(`note:1`, `note:list`) never reach the wire.
|
|
53
|
-
- **Merge**: objects
|
|
54
|
-
|
|
55
|
-
surfacing to the app. Custom merge strategies (e.g. Yjs documents) can be
|
|
56
|
-
plugged per object.
|
|
52
|
+
(`note:1`, `note:list`) never reach the wire. Remote apps encrypt their own payloads.
|
|
53
|
+
- **Merge**: Local objects use last-write-wins per top-level field to merge
|
|
54
|
+
changes across devices.
|
|
57
55
|
- **Sync triggers**: launch/resume, post-write debounce, and a timer
|
|
58
56
|
fallback. Browser lifecycle triggers such as focus/visibility are app
|
|
59
57
|
choices: call `bucket.sync()` from those handlers when that fits your UI.
|
|
60
|
-
No server push in v1.
|
|
61
58
|
|
|
62
59
|
## Honest boundaries
|
|
63
60
|
|
|
64
|
-
- **
|
|
65
|
-
|
|
66
|
-
device holding the data re-uploads it automatically (self-healing), but if
|
|
67
|
-
every local copy is gone, rotated cloud data is not recoverable. Data
|
|
68
|
-
durability is owned by the app and the user.
|
|
61
|
+
- **Recovery** depends on the cloud service's durability, retention and backup
|
|
62
|
+
guarantees, and on retaining access to decryption keys.
|
|
69
63
|
- **Privacy boundary**: id blinding and encryption hide semantics, not
|
|
70
64
|
traffic patterns — the platform still observes opaque-object write timing,
|
|
71
65
|
sizes, and counts. Authorization revocation revokes access; it does not
|
|
@@ -78,25 +72,11 @@ await bucket.connect(); // defaults to https://myfield.one/auth/
|
|
|
78
72
|
single-user multi-device freshness, not millisecond multi-user
|
|
79
73
|
collaboration or presence.
|
|
80
74
|
|
|
81
|
-
## Current service status
|
|
82
|
-
|
|
83
|
-
The public SDK facade no longer exposes `apiBase`. The auth service returns
|
|
84
|
-
`resourceApiUrl` in the encrypted callback result, so SDKs do not encode
|
|
85
|
-
deployment host rules. The SDK uses `bucketAccessGrant.resourceId` as the
|
|
86
|
-
remote sync resource id, with `envelope.bucketId` treated as optional
|
|
87
|
-
compatibility metadata.
|
|
88
|
-
|
|
89
|
-
Deferred service work after this preview release:
|
|
90
|
-
|
|
91
|
-
- A bucket-scoped hibernatable WebSocket feed under the resource API root.
|
|
92
|
-
SSE remains compatibility/development-only; SDK fallback is timer
|
|
93
|
-
sync over the object index and feed.
|
|
94
|
-
|
|
95
75
|
## Public entry
|
|
96
76
|
|
|
97
77
|
| Entry | Contents |
|
|
98
78
|
| --- | --- |
|
|
99
|
-
| `@myfield/sdk` | `createInstance`
|
|
79
|
+
| `@myfield/sdk` | `createInstance`, `instance.remote.getBucket`, public types and error classes |
|
|
100
80
|
|
|
101
81
|
Local persistence defaults to IndexedDB. A memory backend is available for
|
|
102
82
|
tests and ephemeral clients; custom storage factories are lower-level
|
|
@@ -111,15 +91,15 @@ ports (payload layout, merge rules, id derivation): see
|
|
|
111
91
|
|
|
112
92
|
## Development
|
|
113
93
|
|
|
114
|
-
This package
|
|
115
|
-
monorepo workspace (standalone lockfile) so it can be extracted cleanly.
|
|
94
|
+
This package has no runtime dependencies and uses a standalone pnpm lockfile.
|
|
116
95
|
|
|
117
96
|
```sh
|
|
118
|
-
pnpm install
|
|
97
|
+
pnpm install
|
|
119
98
|
npm run build
|
|
120
99
|
npm test # node --test (contract layer, mocked relay/auth)
|
|
121
100
|
npm run typecheck # tsc --noEmit
|
|
101
|
+
npm run typecheck:api # public declarations
|
|
102
|
+
MYFIELD_TEST_AUTH_URL="https://your-test-host/auth/" npm run verify:remote
|
|
122
103
|
```
|
|
123
104
|
|
|
124
|
-
|
|
125
|
-
run from the workspace root with `pnpm run test:sdk:e2e`.
|
|
105
|
+
`verify:remote` is the SDK's standalone Remote API smoke check against a test service.
|