@drakkar.software/starfish-client 1.19.2 → 2.0.0
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/dist/append.d.ts +50 -0
- package/dist/bindings/broadcast.d.ts +19 -0
- package/dist/bindings/broadcast.js +65 -0
- package/dist/bindings/react.d.ts +12 -0
- package/dist/bindings/react.js +25 -0
- package/dist/bindings/zustand.js +25 -8
- package/dist/bindings/zustand.js.map +2 -2
- package/dist/client.d.ts +12 -5
- package/dist/config.d.ts +10 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +25 -8
- package/dist/index.js.map +2 -2
- package/dist/mobile-lifecycle.js +2 -2
- package/dist/polling.js +2 -2
- package/package.json +2 -2
- package/dist/hash.d.ts +0 -10
- package/dist/hash.js +0 -34
- package/dist/platform.d.ts +0 -52
- package/dist/platform.js +0 -62
package/dist/config.d.ts
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
/** Encryption modes supported by the Starfish server. */
|
|
2
2
|
export type EncryptionMode = "none" | "identity" | "server" | "delegated";
|
|
3
|
+
/** Append-only configuration exposed via GET /config. */
|
|
4
|
+
export interface AppendOnlyClientInfo {
|
|
5
|
+
/** Array field name in the stored document. Defaults to "items". */
|
|
6
|
+
field?: string;
|
|
7
|
+
/** false = no storage write (replaces queueOnly). true/absent = append to array. */
|
|
8
|
+
persist?: boolean;
|
|
9
|
+
/** When true, server validates client's baseHash against hash(lastItem). */
|
|
10
|
+
checkLastItem?: boolean;
|
|
11
|
+
}
|
|
3
12
|
/** Per-collection metadata returned by GET /config. */
|
|
4
13
|
export interface CollectionClientInfo {
|
|
5
14
|
name: string;
|
|
@@ -8,7 +17,7 @@ export interface CollectionClientInfo {
|
|
|
8
17
|
allowedMimeTypes: string[];
|
|
9
18
|
pullOnly?: boolean;
|
|
10
19
|
pushOnly?: boolean;
|
|
11
|
-
|
|
20
|
+
appendOnly?: AppendOnlyClientInfo;
|
|
12
21
|
clientEncrypted?: boolean;
|
|
13
22
|
/** Base64-encoded public key for client-side encryption, if configured on the server. */
|
|
14
23
|
publicKey?: string;
|
package/dist/index.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ export type { CryptoProvider, Base64Provider, PlatformConfig } from "@drakkar.so
|
|
|
3
3
|
export { stableStringify, computeHash } from "@drakkar.software/starfish-protocol";
|
|
4
4
|
export type { PullResult, PushSuccess } from "@drakkar.software/starfish-protocol";
|
|
5
5
|
export { StarfishClient } from "./client.js";
|
|
6
|
-
export type { BlobPullResult, BlobPushResult } from "./client.js";
|
|
6
|
+
export type { BlobPullResult, BlobPushResult, AppendPullOptions } from "./client.js";
|
|
7
7
|
export { SyncManager } from "./sync.js";
|
|
8
8
|
export type { SyncManagerOptions } from "./sync.js";
|
|
9
9
|
export { createEncryptor, ENCRYPTED_KEY } from "./crypto.js";
|
|
@@ -46,3 +46,4 @@ export { deriveGroupKeyPair, generateGroupKey, wrapGroupKey, unwrapGroupKey, cre
|
|
|
46
46
|
export type { GroupKeyPair, EpochKeyring, GroupKeyring } from "./group-crypto.js";
|
|
47
47
|
export { pullEntitlements } from "./entitlements.js";
|
|
48
48
|
export type { PullEntitlementsOptions } from "./entitlements.js";
|
|
49
|
+
export type { AppendOnlyClientInfo } from "./config.js";
|
package/dist/index.js
CHANGED
|
@@ -19,6 +19,7 @@ var StarfishHttpError = class extends Error {
|
|
|
19
19
|
};
|
|
20
20
|
|
|
21
21
|
// src/client.ts
|
|
22
|
+
var APPEND_DEFAULT_FIELD = "items";
|
|
22
23
|
var StarfishClient = class {
|
|
23
24
|
baseUrl;
|
|
24
25
|
auth;
|
|
@@ -28,13 +29,24 @@ var StarfishClient = class {
|
|
|
28
29
|
this.auth = options.auth;
|
|
29
30
|
this.fetch = options.fetch ?? globalThis.fetch.bind(globalThis);
|
|
30
31
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
32
|
+
async pull(path, checkpointOrOptions) {
|
|
33
|
+
let url = `${this.baseUrl}${path}`;
|
|
34
|
+
let appendField;
|
|
35
|
+
if (typeof checkpointOrOptions === "number") {
|
|
36
|
+
if (checkpointOrOptions) url += `?checkpoint=${checkpointOrOptions}`;
|
|
37
|
+
} else if (checkpointOrOptions != null) {
|
|
38
|
+
appendField = checkpointOrOptions.appendField ?? APPEND_DEFAULT_FIELD;
|
|
39
|
+
const params = new URLSearchParams();
|
|
40
|
+
if (checkpointOrOptions.since != null) {
|
|
41
|
+
if (checkpointOrOptions.since < 0) throw new Error("since must be non-negative");
|
|
42
|
+
params.set("checkpoint", String(checkpointOrOptions.since));
|
|
43
|
+
}
|
|
44
|
+
if (checkpointOrOptions.last != null) {
|
|
45
|
+
if (checkpointOrOptions.last < 0) throw new Error("last must be non-negative");
|
|
46
|
+
params.set("last", String(checkpointOrOptions.last));
|
|
47
|
+
}
|
|
48
|
+
if (params.size > 0) url += `?${params.toString()}`;
|
|
49
|
+
}
|
|
38
50
|
const authHeaders = this.auth ? await this.auth({ method: "GET", path, body: null }) : {};
|
|
39
51
|
const res = await this.fetch(url, {
|
|
40
52
|
method: "GET",
|
|
@@ -43,7 +55,12 @@ var StarfishClient = class {
|
|
|
43
55
|
if (!res.ok) {
|
|
44
56
|
throw new StarfishHttpError(res.status, await res.text());
|
|
45
57
|
}
|
|
46
|
-
|
|
58
|
+
const result = await res.json();
|
|
59
|
+
if (appendField !== void 0) {
|
|
60
|
+
const list = result.data?.[appendField];
|
|
61
|
+
return Array.isArray(list) ? list : [];
|
|
62
|
+
}
|
|
63
|
+
return result;
|
|
47
64
|
}
|
|
48
65
|
/**
|
|
49
66
|
* Push synced data to the server.
|