@tinycloud/sdk-services 3.2.5 → 3.2.6-beta.4
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/{BaseService-4wwJq1Gn.d.cts → BaseService-1Ug6y7DC.d.cts} +1 -1
- package/dist/{BaseService-BGr2slUz.d.ts → BaseService-Bn07Vudy.d.ts} +1 -1
- package/dist/encryption/index.cjs +2 -0
- package/dist/encryption/index.cjs.map +1 -1
- package/dist/encryption/index.d.cts +2 -2
- package/dist/encryption/index.d.ts +2 -2
- package/dist/encryption/index.js +2 -0
- package/dist/encryption/index.js.map +1 -1
- package/dist/index.cjs +16 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +14 -11
- package/dist/index.d.ts +14 -11
- package/dist/index.js +16 -8
- package/dist/index.js.map +1 -1
- package/dist/internal/decrypt-transport-response-error.d.cts +1 -1
- package/dist/internal/decrypt-transport-response-error.d.ts +1 -1
- package/dist/kv/index.cjs +2 -0
- package/dist/kv/index.cjs.map +1 -1
- package/dist/kv/index.d.cts +7 -4
- package/dist/kv/index.d.ts +7 -4
- package/dist/kv/index.js +2 -0
- package/dist/kv/index.js.map +1 -1
- package/dist/kv/replication/contractConstants.cjs +115 -0
- package/dist/kv/replication/contractConstants.cjs.map +1 -0
- package/dist/kv/replication/contractConstants.d.cts +77 -0
- package/dist/kv/replication/contractConstants.d.ts +77 -0
- package/dist/kv/replication/contractConstants.js +75 -0
- package/dist/kv/replication/contractConstants.js.map +1 -0
- package/dist/kv/replication/grantPolicyConstants.cjs +42 -0
- package/dist/kv/replication/grantPolicyConstants.cjs.map +1 -0
- package/dist/kv/replication/grantPolicyConstants.d.cts +10 -0
- package/dist/kv/replication/grantPolicyConstants.d.ts +10 -0
- package/dist/kv/replication/grantPolicyConstants.js +14 -0
- package/dist/kv/replication/grantPolicyConstants.js.map +1 -0
- package/dist/kv/replication/grantPolicyTypes.cjs +19 -0
- package/dist/kv/replication/grantPolicyTypes.cjs.map +1 -0
- package/dist/kv/replication/grantPolicyTypes.d.cts +87 -0
- package/dist/kv/replication/grantPolicyTypes.d.ts +87 -0
- package/dist/kv/replication/grantPolicyTypes.js +1 -0
- package/dist/kv/replication/grantPolicyTypes.js.map +1 -0
- package/dist/kv/replication/index.cjs +5 -4
- package/dist/kv/replication/index.cjs.map +1 -1
- package/dist/kv/replication/index.d.cts +6 -3
- package/dist/kv/replication/index.d.ts +6 -3
- package/dist/kv/replication/index.js +5 -4
- package/dist/kv/replication/index.js.map +1 -1
- package/dist/scope-BnyVPZ5E.d.ts +1659 -0
- package/dist/scope-CQ5kmHlt.d.cts +1659 -0
- package/dist/sql/index.cjs +2 -0
- package/dist/sql/index.cjs.map +1 -1
- package/dist/sql/index.d.cts +2 -2
- package/dist/sql/index.d.ts +2 -2
- package/dist/sql/index.js +2 -0
- package/dist/sql/index.js.map +1 -1
- package/dist/{types-D-9A3Sut.d.cts → types-gmdUiorz.d.cts} +2 -0
- package/dist/{types-D-9A3Sut.d.ts → types-gmdUiorz.d.ts} +2 -0
- package/package.json +40 -1
- package/dist/scope-CoKKmMiI.d.ts +0 -957
- package/dist/scope-D7wmjbMH.d.cts +0 -957
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Grant lifetime and renewal contract (TC-858 Phase 2, CONTRACT.md §3). Types only; S4 implements
|
|
3
|
+
* these signatures in `grantPolicy.ts` using the constants in `contractConstants.ts`.
|
|
4
|
+
* All instants are milliseconds since epoch; all durations are milliseconds.
|
|
5
|
+
*/
|
|
6
|
+
/** Verified source selected by session form; `first_install` is expiry-only. */
|
|
7
|
+
type ReplicaConsentSource =
|
|
8
|
+
/** Verified owner SIWE `issuedAt` with finite signed expiration and exact-space KV witness. */
|
|
9
|
+
"siwe"
|
|
10
|
+
/** `iat` of the oldest independently verified owner-authorizing proof, never a child leaf. */
|
|
11
|
+
| "delegation_iat"
|
|
12
|
+
/** `nbf` of that same oldest owner proof; a leaf signature alone is insufficient. */
|
|
13
|
+
| "delegation_nbf"
|
|
14
|
+
/** Neither: persisted first grant install time, for expiry only; never session establishment. */
|
|
15
|
+
| "first_install";
|
|
16
|
+
/**
|
|
17
|
+
* Invariants: `at` is finite milliseconds and clamped to ≤ now by `clampConsentAnchor`. Second-based
|
|
18
|
+
* sources (UCAN `iat`/`nbf`) are converted ×1000 exactly once, at the authority; SIWE `issuedAt`
|
|
19
|
+
* is parsed as an ISO date. Renewals never re-anchor: only a fresh sign-in yields a new anchor.
|
|
20
|
+
*/
|
|
21
|
+
interface ReplicaConsentAnchor {
|
|
22
|
+
at: number;
|
|
23
|
+
source: ReplicaConsentSource;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Returns the eligible anchor with `at` clamped to ≤ now, or null when it is not finite.
|
|
27
|
+
* A full SIWE session with missing/invalid signed expiration or issuedAt remains unanchored;
|
|
28
|
+
* never fall through to a compact leaf or first-install timestamp. Compact-only sessions
|
|
29
|
+
* may try the same independently verified oldest owner proof's `nbf` after invalid `iat`.
|
|
30
|
+
* S4 implements this as `clampConsentAnchor` in `grantPolicy.ts`.
|
|
31
|
+
*/
|
|
32
|
+
type ClampConsentAnchor = (anchor: ReplicaConsentAnchor, now: number) => ReplicaConsentAnchor | null;
|
|
33
|
+
/**
|
|
34
|
+
* Policy the controller passes to storage in `KVReplicaSpec.grantPolicy`. Storage stores the
|
|
35
|
+
* resulting effective expiry with the installed grant and recomputes it at open.
|
|
36
|
+
*/
|
|
37
|
+
interface ReplicaGrantPolicy {
|
|
38
|
+
/** Validated: 0 < grantTtlMs ≤ MAX_GRANT_TTL_MS. */
|
|
39
|
+
grantTtlMs: number;
|
|
40
|
+
/**
|
|
41
|
+
* From `ReplicationAuthority.consentAnchor()`: a full SIWE session requires an
|
|
42
|
+
* independently verified signed owner `issuedAt`, finite signed expiration and
|
|
43
|
+
* exact-space KV get+sync witness. A compact-only session instead needs the oldest
|
|
44
|
+
* independently verified owner-authorizing proof's `iat`, then its `nbf` (never a
|
|
45
|
+
* fresh child leaf minted under an old owner grant). Invalid SIWE does not fall
|
|
46
|
+
* through to compact/first-install sources.
|
|
47
|
+
* Null means no verified source; storage uses its persisted first-install time only
|
|
48
|
+
* to bound grant expiry, never as freshness proof for a session stamp. That anchor
|
|
49
|
+
* survives partition reset, purge and reinstall, and is cleared only by `deny`.
|
|
50
|
+
*/
|
|
51
|
+
consentAnchor: ReplicaConsentAnchor | null;
|
|
52
|
+
}
|
|
53
|
+
interface EffectiveGrantExpiryInput {
|
|
54
|
+
/** The grant's signed `exp` in ms; null when it has none. */
|
|
55
|
+
signedExpiresAt: number | null;
|
|
56
|
+
installedAt: number;
|
|
57
|
+
grantTtlMs: number;
|
|
58
|
+
/** `min(consentDeadlineMs(policyAnchor), durableGateDeadline)` when browser gate is active. */
|
|
59
|
+
consentDeadline: number;
|
|
60
|
+
}
|
|
61
|
+
/** effective expiry = min(signed exp, installedAt + grantTtlMs, consentDeadline). */
|
|
62
|
+
type EffectiveGrantExpiry = (input: EffectiveGrantExpiryInput) => number;
|
|
63
|
+
/** anchor.at + CONSENT_WINDOW_MS. */
|
|
64
|
+
type ConsentDeadlineMs = (anchor: ReplicaConsentAnchor) => number;
|
|
65
|
+
/**
|
|
66
|
+
* Duration passed to `ReplicationAuthority.mint` as `expiryMs`:
|
|
67
|
+
* min(grantTtlMs, consentDeadline − now). The caller MUST NOT mint when the result is ≤ 0.
|
|
68
|
+
*/
|
|
69
|
+
type MintRemainingMs = (input: {
|
|
70
|
+
now: number;
|
|
71
|
+
grantTtlMs: number;
|
|
72
|
+
consentDeadline: number;
|
|
73
|
+
}) => number;
|
|
74
|
+
/**
|
|
75
|
+
* True when online-renewal should run: remaining = effectiveExpiresAt − now is STRICTLY below
|
|
76
|
+
* RENEW_BELOW_FRACTION × (effectiveExpiresAt − installedAt) (exactly 25% remaining does not
|
|
77
|
+
* renew), and now < consentDeadline. All inputs finite; otherwise false.
|
|
78
|
+
* Checked on a timer, before each sync, and at open.
|
|
79
|
+
*/
|
|
80
|
+
type NeedsSilentRenewal = (input: {
|
|
81
|
+
now: number;
|
|
82
|
+
installedAt: number;
|
|
83
|
+
effectiveExpiresAt: number;
|
|
84
|
+
consentDeadline: number;
|
|
85
|
+
}) => boolean;
|
|
86
|
+
|
|
87
|
+
export type { ClampConsentAnchor, ConsentDeadlineMs, EffectiveGrantExpiry, EffectiveGrantExpiryInput, MintRemainingMs, NeedsSilentRenewal, ReplicaConsentAnchor, ReplicaConsentSource, ReplicaGrantPolicy };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=grantPolicyTypes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -1201,23 +1201,24 @@ function createKVReplication(deps) {
|
|
|
1201
1201
|
if (!local && !opened?.opening && !opened?.authorityRevoked) inspected = await inspectPersistedStatus(prefix);
|
|
1202
1202
|
local ?? (local = inspected.local);
|
|
1203
1203
|
if (inspected.missing && !opened?.reason && !opened?.authorityRevoked && !opened?.opening && !isClosed) return void 0;
|
|
1204
|
-
const
|
|
1204
|
+
const full = local && !("redacted" in local) ? local : void 0;
|
|
1205
|
+
const revoked = opened?.authorityRevoked === true || full?.authority.state === "revoked";
|
|
1205
1206
|
const rootUnsupported = opened?.lastError === "REPLICATION_ROOT_UNSUPPORTED";
|
|
1206
|
-
const state = isClosed ? "closed" : revoked ? "revoked" : rootUnsupported ? "unavailable" : opened?.reason === "grant_missing" ? "grant_missing" :
|
|
1207
|
+
const state = isClosed ? "closed" : revoked ? "revoked" : rootUnsupported ? "unavailable" : opened?.reason === "grant_missing" ? "grant_missing" : full?.coverage === "complete" && full.authority.state === "valid" ? "ready" : opened?.reason || inspected.errorCode ? "unavailable" : "idle";
|
|
1207
1208
|
return {
|
|
1208
1209
|
prefix,
|
|
1209
1210
|
state,
|
|
1210
1211
|
...opened?.reason ? { reason: opened.reason } : inspected.errorCode ? { reason: "replica_unavailable" } : {},
|
|
1211
1212
|
...inspected.errorCode ?? opened?.lastError ? { errorCode: inspected.errorCode ?? opened?.lastError } : {},
|
|
1212
1213
|
...local ?? {},
|
|
1213
|
-
...revoked ? { authority: { state: "revoked", expiresAt:
|
|
1214
|
+
...revoked ? { authority: { state: "revoked", expiresAt: full?.authority.expiresAt ?? null } } : {},
|
|
1214
1215
|
pending: {
|
|
1215
1216
|
inFlight: records.filter((r) => r.state === "in_flight").length,
|
|
1216
1217
|
committed: records.filter((r) => r.state === "committed").length,
|
|
1217
1218
|
ambiguous: records.filter((r) => r.state === "ambiguous").length
|
|
1218
1219
|
},
|
|
1219
1220
|
pinned: pinnedKeys(snapshot, prefix, scheduler.now()),
|
|
1220
|
-
lagMs:
|
|
1221
|
+
lagMs: full?.lastSyncAt ? scheduler.now() - Date.parse(full.lastSyncAt) : null
|
|
1221
1222
|
};
|
|
1222
1223
|
}));
|
|
1223
1224
|
return entries.filter((entry) => entry !== void 0);
|