@drakkar.software/starfish-client 3.0.0-alpha.0 → 3.0.0-alpha.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.
Files changed (56) hide show
  1. package/dist/append.d.ts +50 -0
  2. package/dist/background-sync.js +29 -0
  3. package/dist/bindings/broadcast.d.ts +19 -0
  4. package/dist/bindings/broadcast.js +65 -0
  5. package/dist/bindings/react.d.ts +12 -0
  6. package/dist/bindings/react.js +25 -0
  7. package/dist/bindings/suspense.js +49 -0
  8. package/dist/bindings/zustand.js +40 -2
  9. package/dist/bindings/zustand.js.map +2 -2
  10. package/dist/client.d.ts +20 -0
  11. package/dist/client.js +112 -0
  12. package/dist/config.d.ts +2 -2
  13. package/dist/config.js +18 -0
  14. package/dist/crypto.js +49 -0
  15. package/dist/debounced-sync.js +120 -0
  16. package/dist/dedup.js +35 -0
  17. package/dist/entitlements.js +41 -0
  18. package/dist/export.js +115 -0
  19. package/dist/group-crypto.d.ts +111 -0
  20. package/dist/group-crypto.js +205 -0
  21. package/dist/group-crypto.js.map +7 -0
  22. package/dist/history.js +61 -0
  23. package/dist/identity.d.ts +82 -4
  24. package/dist/identity.js +354 -2
  25. package/dist/identity.js.map +4 -4
  26. package/dist/index.js +40 -2
  27. package/dist/index.js.map +2 -2
  28. package/dist/logger.js +80 -0
  29. package/dist/migrate.js +38 -0
  30. package/dist/mobile-lifecycle.js +55 -0
  31. package/dist/multi-store.js +92 -0
  32. package/dist/polling.js +52 -0
  33. package/dist/resolvers.js +223 -0
  34. package/dist/service-worker.js +55 -0
  35. package/dist/storage/indexeddb.js +59 -0
  36. package/dist/sync.js +127 -0
  37. package/dist/types.d.ts +7 -0
  38. package/dist/types.js +18 -0
  39. package/dist/validate.js +28 -0
  40. package/package.json +2 -2
  41. package/dist/_crypto_helpers.d.ts +0 -4
  42. package/dist/cap-mint.d.ts +0 -20
  43. package/dist/cap-mint.js +0 -12
  44. package/dist/cap-mint.js.map +0 -7
  45. package/dist/directory.d.ts +0 -9
  46. package/dist/directory.js +0 -24
  47. package/dist/directory.js.map +0 -7
  48. package/dist/keyring.d.ts +0 -6
  49. package/dist/keyring.js +0 -26
  50. package/dist/keyring.js.map +0 -7
  51. package/dist/pairing.d.ts +0 -6
  52. package/dist/pairing.js +0 -26
  53. package/dist/pairing.js.map +0 -7
  54. package/dist/recipients.d.ts +0 -6
  55. package/dist/recipients.js +0 -16
  56. package/dist/recipients.js.map +0 -7
package/dist/index.js CHANGED
@@ -82,7 +82,7 @@ var StarfishClient = class {
82
82
  */
83
83
  async buildAuthHeaders(method, pathAndQuery, body) {
84
84
  if (this.capProvider) {
85
- const { cap, devEdPrivHex } = await this.capProvider.getCap();
85
+ const { cap, devEdPrivHex, pubHex } = await this.capProvider.getCap();
86
86
  const req = {
87
87
  method,
88
88
  pathAndQuery,
@@ -90,12 +90,14 @@ var StarfishClient = class {
90
90
  host: this.signingHost()
91
91
  };
92
92
  const { sig, ts, nonce } = await signRequest(req, devEdPrivHex);
93
- return {
93
+ const headers = {
94
94
  Authorization: `Cap ${encodeCapAuth(cap)}`,
95
95
  "X-Starfish-Sig": sig,
96
96
  "X-Starfish-Ts": String(ts),
97
97
  "X-Starfish-Nonce": nonce
98
98
  };
99
+ if (pubHex !== void 0) headers["X-Starfish-Pub"] = pubHex;
100
+ return headers;
99
101
  }
100
102
  return {};
101
103
  }
@@ -177,6 +179,42 @@ var StarfishClient = class {
177
179
  }
178
180
  return res.json();
179
181
  }
182
+ /**
183
+ * Append an element to an appendOnly (`by_timestamp`) collection.
184
+ *
185
+ * Unlike {@link push}, appendOnly writes carry no hash/conflict check — an
186
+ * authorized append is always accepted. Each element is stored server-side as
187
+ * `{ts, data}` and pulls can filter by `ts` via `since`/`checkpoint`.
188
+ *
189
+ * @param path - the push endpoint (e.g. "/push/events")
190
+ * @param data - the element payload. For a `delegated` collection, encrypt it
191
+ * first (e.g. `createKeyringEncryptor(keyring, kem).encrypt(data)`); the
192
+ * server stores it opaquely and never reads it.
193
+ * @param opts.ts - optional client-supplied element timestamp (ms). Must be a
194
+ * non-negative integer strictly greater than the latest stored element's ts
195
+ * (else the server responds 409). Omit to let the server assign one.
196
+ * @throws {StarfishHttpError} on a non-2xx response (e.g. 409 for a
197
+ * non-monotonic timestamp).
198
+ */
199
+ async append(path, data, opts = {}) {
200
+ const bodyObj = { data };
201
+ if (opts.ts !== void 0) bodyObj["ts"] = opts.ts;
202
+ const body = JSON.stringify(bodyObj);
203
+ const authHeaders = await this.buildAuthHeaders("POST", path, body);
204
+ const res = await this.fetch(`${this.baseUrl}${path}`, {
205
+ method: "POST",
206
+ headers: {
207
+ "Content-Type": "application/json",
208
+ Accept: "application/json",
209
+ ...authHeaders
210
+ },
211
+ body
212
+ });
213
+ if (!res.ok) {
214
+ throw new StarfishHttpError(res.status, await res.text());
215
+ }
216
+ return res.json();
217
+ }
180
218
  /**
181
219
  * Pull binary data from a blob collection.
182
220
  * Returns raw bytes with the content hash from the ETag header.