@myfield/sdk 0.9.1 → 0.9.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/CHANGELOG.md +27 -0
- package/README.md +59 -58
- package/dist/index.js +1886 -665
- package/package.json +17 -8
- package/types/index.d.ts +389 -47
- package/docs/API.md +0 -211
- package/docs/BUCKET-SPEC.md +0 -168
- package/src/auth/index.ts +0 -17
- package/src/auth/instance.ts +0 -876
- package/src/bucket/binary.ts +0 -253
- package/src/bucket/client.ts +0 -421
- package/src/bucket/crypto.ts +0 -58
- package/src/bucket/format.ts +0 -324
- package/src/bucket/index.ts +0 -40
- package/src/bucket/keys.ts +0 -104
- package/src/bucket/store.ts +0 -159
- package/src/bucket/transport.ts +0 -227
- package/src/errors.ts +0 -9
- package/src/facade.ts +0 -773
- package/src/index.ts +0 -23
- package/src/internal/encoding.ts +0 -95
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,32 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.9.3
|
|
4
|
+
|
|
5
|
+
- Use HTTP polling for `watchFeed()` with the existing hint format.
|
|
6
|
+
- Restore a saved bucket grant when importing its device key with `importKey()`.
|
|
7
|
+
- Generate public declarations, API review reports and the API Reference from source.
|
|
8
|
+
- Clarify the existing binary payload format in the Specification.
|
|
9
|
+
|
|
10
|
+
## 0.9.2
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
- Unified Instance APIs for connection, state events and Local bucket access,
|
|
14
|
+
with optional automatic sync.
|
|
15
|
+
- Remote APIs for object reads, CAS commits, version history and feed notifications,
|
|
16
|
+
including bucket-key access for app-managed encryption.
|
|
17
|
+
- Instance key creation, retrieval, import and removal.
|
|
18
|
+
|
|
19
|
+
### Fixed
|
|
20
|
+
- Connection races during startup and incorrect upload-success handling.
|
|
21
|
+
|
|
22
|
+
### Compatibility
|
|
23
|
+
- String initialization now means `appId`; use `namespace` to preserve an existing
|
|
24
|
+
storage scope.
|
|
25
|
+
- Configure authorization with `createInstance({ authUrl })` instead of
|
|
26
|
+
`bucket.connect({ authBase })`.
|
|
27
|
+
- `bucket.ready()` is now a deprecated no-op. Existing stored keys and Local data
|
|
28
|
+
formats remain supported.
|
|
29
|
+
|
|
3
30
|
## 0.9.1
|
|
4
31
|
|
|
5
32
|
- Sync uses the relay's object index; `~index` is no longer pushed.
|
package/README.md
CHANGED
|
@@ -1,31 +1,26 @@
|
|
|
1
1
|
# @myfield/sdk
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
end-to-end-encrypted sync, and internal
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
use, and 1.0 will freeze the API/protocol, with later versions extending it
|
|
17
|
-
while keeping compatibility. License: Apache-2.0.
|
|
3
|
+
MyField SDK for third-party web apps: local-first object storage,
|
|
4
|
+
end-to-end-encrypted sync, and internal MyField authorization.
|
|
5
|
+
|
|
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: 1.0 preview; public APIs may change during preview. License: Apache-2.0.
|
|
10
|
+
|
|
11
|
+
## Install
|
|
12
|
+
|
|
13
|
+
```sh
|
|
14
|
+
npm install @myfield/sdk
|
|
15
|
+
```
|
|
18
16
|
|
|
19
17
|
## Quickstart
|
|
20
18
|
|
|
21
19
|
```ts
|
|
22
20
|
import { createInstance } from "@myfield/sdk";
|
|
23
21
|
|
|
24
|
-
const instance = createInstance();
|
|
25
|
-
const bucket = instance.
|
|
26
|
-
|
|
27
|
-
// On startup: resume an existing authorization / handle an auth callback.
|
|
28
|
-
await bucket.resume();
|
|
22
|
+
const instance = createInstance("notes.example.com");
|
|
23
|
+
const bucket = instance.getBucket();
|
|
29
24
|
|
|
30
25
|
// Local-first object CRUD works before authorization.
|
|
31
26
|
await bucket.put("note:1", { title: "hello", body: "world" });
|
|
@@ -33,39 +28,49 @@ const note = await bucket.get("note:1");
|
|
|
33
28
|
await bucket.update("note:1", { body: undefined }); // deletes the field
|
|
34
29
|
const entries = await bucket.list({ prefix: "note:" });
|
|
35
30
|
|
|
31
|
+
// Restore access in the background after loading local data.
|
|
32
|
+
void instance.resume().catch(error => console.error("Connection failed:", error));
|
|
33
|
+
|
|
36
34
|
// On the user's "Connect" click: run the authorization flow (popup, or
|
|
37
35
|
// same-tab on iOS).
|
|
38
|
-
await
|
|
36
|
+
await instance.connect(); // defaults to https://myfield.one/auth/
|
|
39
37
|
```
|
|
40
38
|
|
|
39
|
+
## Documentation
|
|
40
|
+
|
|
41
|
+
- [API guide](docs/api.md): Local/Remote usage and behavioral semantics.
|
|
42
|
+
- [API Reference](docs/api/index.md): generated public types, options and methods.
|
|
43
|
+
- [Specification](docs/spec/bucket.md): encoding, encryption, merge and compatibility.
|
|
44
|
+
- [Documentation index](docs/README.md).
|
|
45
|
+
|
|
46
|
+
## Remote object access
|
|
47
|
+
|
|
48
|
+
`instance.remote.getBucket()` provides object reads, CAS commits, version history and
|
|
49
|
+
change notifications with the instance's authorization; the app owns payload encryption
|
|
50
|
+
and local storage, encrypting with `getBucketKey()`. See
|
|
51
|
+
[Remote Object API](docs/api.md#remote-object-api).
|
|
52
|
+
|
|
41
53
|
## What the SDK handles
|
|
42
54
|
|
|
43
55
|
- **Auth**: instance keygen, the `https://myfield.one/auth/` authorization
|
|
44
56
|
flow (popup / same-tab), callback decryption, bearer session refresh, and
|
|
45
|
-
the unauthorized → disconnected transition. Apps
|
|
57
|
+
the unauthorized → disconnected transition. Apps use Instance
|
|
46
58
|
`connect()` / `disconnect()` / state events only.
|
|
47
|
-
- **Pairwise identity**:
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
- **Encryption**: payloads are encrypted client-side; the platform stores
|
|
59
|
+
- **Pairwise identity**: apps receive app-specific aliases rather than the user's
|
|
60
|
+
primary MyField identity.
|
|
61
|
+
- **Encryption**: Local payloads are encrypted client-side; the platform stores
|
|
51
62
|
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.
|
|
63
|
+
(`note:1`, `note:list`) never reach the wire. Remote apps encrypt their own payloads.
|
|
64
|
+
- **Merge**: Local objects use last-write-wins per top-level field to merge
|
|
65
|
+
changes across devices.
|
|
57
66
|
- **Sync triggers**: launch/resume, post-write debounce, and a timer
|
|
58
67
|
fallback. Browser lifecycle triggers such as focus/visibility are app
|
|
59
68
|
choices: call `bucket.sync()` from those handlers when that fits your UI.
|
|
60
|
-
No server push in v1.
|
|
61
69
|
|
|
62
70
|
## Honest boundaries
|
|
63
71
|
|
|
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.
|
|
72
|
+
- **Recovery** depends on the cloud service's durability, retention and backup
|
|
73
|
+
guarantees, and on retaining access to decryption keys.
|
|
69
74
|
- **Privacy boundary**: id blinding and encryption hide semantics, not
|
|
70
75
|
traffic patterns — the platform still observes opaque-object write timing,
|
|
71
76
|
sizes, and counts. Authorization revocation revokes access; it does not
|
|
@@ -78,25 +83,11 @@ await bucket.connect(); // defaults to https://myfield.one/auth/
|
|
|
78
83
|
single-user multi-device freshness, not millisecond multi-user
|
|
79
84
|
collaboration or presence.
|
|
80
85
|
|
|
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
86
|
## Public entry
|
|
96
87
|
|
|
97
88
|
| Entry | Contents |
|
|
98
89
|
| --- | --- |
|
|
99
|
-
| `@myfield/sdk` | `createInstance`
|
|
90
|
+
| `@myfield/sdk` | `createInstance`, `instance.remote.getBucket`, public types and error classes |
|
|
100
91
|
|
|
101
92
|
Local persistence defaults to IndexedDB. A memory backend is available for
|
|
102
93
|
tests and ephemeral clients; custom storage factories are lower-level
|
|
@@ -107,19 +98,29 @@ implementation and tests, but are not exported package subpaths in v1.
|
|
|
107
98
|
|
|
108
99
|
Compatible implementation details for SDK maintainers and future language
|
|
109
100
|
ports (payload layout, merge rules, id derivation): see
|
|
110
|
-
[
|
|
101
|
+
[Local bucket specification](docs/spec/bucket.md).
|
|
111
102
|
|
|
112
103
|
## Development
|
|
113
104
|
|
|
114
|
-
This package
|
|
115
|
-
|
|
105
|
+
This package has no runtime dependencies and uses a standalone pnpm lockfile.
|
|
106
|
+
Use Node.js 24 in CI (minimum 22.18) and pnpm 9.15.0 for development.
|
|
116
107
|
|
|
117
108
|
```sh
|
|
118
|
-
pnpm install --
|
|
109
|
+
pnpm install --frozen-lockfile
|
|
110
|
+
npm run api:check
|
|
119
111
|
npm run build
|
|
120
112
|
npm test # node --test (contract layer, mocked relay/auth)
|
|
121
113
|
npm run typecheck # tsc --noEmit
|
|
114
|
+
npm run typecheck:api # public declarations and documentation examples
|
|
115
|
+
npm run test:docs
|
|
116
|
+
npm run test:package
|
|
117
|
+
MYFIELD_TEST_AUTH_URL="https://your-test-host/auth/" npm run verify:remote
|
|
122
118
|
```
|
|
123
119
|
|
|
124
|
-
|
|
125
|
-
|
|
120
|
+
`verify:remote` is the SDK's standalone Remote API smoke check against a test service.
|
|
121
|
+
|
|
122
|
+
Public declarations and API reference documentation are generated from source
|
|
123
|
+
and TSDoc. After an intentional change, run `npm run api:update` and review
|
|
124
|
+
`etc/sdk.api.md`, `types/` and `docs/api/`. Build and CI check these artifacts
|
|
125
|
+
without accepting baseline changes; do not hand-edit generated files.
|
|
126
|
+
API reports are review snapshots, not new release compatibility commitments.
|