@terminal3/t3n-sdk 3.4.4 → 3.5.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/index.d.ts CHANGED
@@ -953,6 +953,79 @@ interface GetUsageOptions {
953
953
  kinds?: TokenTxKind[];
954
954
  }
955
955
 
956
+ /**
957
+ * Tenant audit-event wire shapes.
958
+ *
959
+ * Mirrors `tenant_types::AuditEvent` and the `audit.get-mine` response
960
+ * (`service::tenant_logs::{AuditBatch, AuditPage}`). A tenant contract
961
+ * emits an audit event via the `logging::audit` host call; the host
962
+ * stamps the identity fields (`subject` / `actor` / `vc_id`) from the
963
+ * verified dispatch context, so a contract can never forge who acted or
964
+ * on whom. Events are permanent (encrypted, append-only) and scoped to a
965
+ * user — distinct from the evicting debug ring read via `getContractLogs`.
966
+ */
967
+ /**
968
+ * One host-stamped audit event. `subject` / `actor` are canonical DID
969
+ * strings. On a self-call `actor === subject` and `vc_id` is `null`; on a
970
+ * delegated call `actor` is the agent and `vc_id` is the delegation
971
+ * credential. The remaining fields are supplied verbatim by the contract.
972
+ */
973
+ interface AuditEvent {
974
+ /** Cluster-deterministic flush timestamp (ms). */
975
+ ts_ms: number;
976
+ /** The user whose data the call touched (host-stamped `pii_did`). */
977
+ subject: string;
978
+ /** The agent (delegated) or user (self-call) who acted (host-stamped). */
979
+ actor: string;
980
+ /** Delegation credential id on a delegated call; `null` on a self-call. */
981
+ vc_id?: string | null;
982
+ /** Contract-supplied: what happened, e.g. `"kyc.approve"`. */
983
+ action: string;
984
+ /** Contract-supplied: what it acted on, e.g. `"user-profile"`. */
985
+ target: string;
986
+ /** Contract-supplied: the result, e.g. `"success"` / `"denied"`. */
987
+ outcome: string;
988
+ /** Contract-supplied: optional free-text / JSON detail. */
989
+ details?: string | null;
990
+ }
991
+ /**
992
+ * One archived batch — the events committed in a single tenant dispatch.
993
+ * Every event in a batch shares the same `subject` / `actor` / `vc_id`.
994
+ */
995
+ interface AuditBatch {
996
+ /** Hex of the archive key — usable directly as `cursor` for the next page. */
997
+ key: string;
998
+ /**
999
+ * Host-stamped: did the emitting dispatch's contract transaction
1000
+ * commit? `false` means the call rolled back or trapped, so an event's
1001
+ * `outcome: "success"` in this batch is the contract's *claim*, not a
1002
+ * committed fact — filter on this when you need only durable events.
1003
+ */
1004
+ committed: boolean;
1005
+ events: AuditEvent[];
1006
+ }
1007
+ /**
1008
+ * `audit.get-mine` response — a page of audit batches, newest scan order.
1009
+ * `next_cursor` is present (a key hex) when more batches remain; `null`
1010
+ * once the scan reaches the end.
1011
+ */
1012
+ interface AuditPage {
1013
+ batches: AuditBatch[];
1014
+ next_cursor?: string | null;
1015
+ }
1016
+ /**
1017
+ * Request shape for {@link T3nClient.getAuditEvents} — all fields
1018
+ * optional. Omit `pii_did` to read your own trail (all actors); set it to
1019
+ * another user's DID to read, as a delegated agent, the events you
1020
+ * performed for them — admitted only while that user's agent-auth grant
1021
+ * to you is live. `cursor` is the `next_cursor` from a prior page.
1022
+ */
1023
+ interface GetAuditEventsOptions {
1024
+ pii_did?: string;
1025
+ limit?: number;
1026
+ cursor?: string;
1027
+ }
1028
+
956
1029
  /**
957
1030
  * Public types export for T3n SDK
958
1031
  */
@@ -1521,6 +1594,21 @@ declare class T3nClient {
1521
1594
  * server-side handler does not run the encryption layer.
1522
1595
  */
1523
1596
  getUsage(opts?: GetUsageOptions): Promise<UsagePage>;
1597
+ /**
1598
+ * Fetch a page of audit events. With no `pii_did`, returns
1599
+ * the caller's own audit trail (every actor). With a `pii_did` set to
1600
+ * another user's DID, returns — as a delegated agent — the events the
1601
+ * caller performed for that user; admitted ONLY while that user's
1602
+ * `agent-auth` grant to the caller is live (revocable). `cursor` is the
1603
+ * `next_cursor` from a prior page; `limit` clamps server-side.
1604
+ *
1605
+ * Unlike {@link getUsage}, this runs the SAME session-payload
1606
+ * encryption as {@link executeAction}: audit events carry PII
1607
+ * (`action`/`target`/`details`), so the request and response are
1608
+ * sealed to the session key rather than sent plaintext over TLS. The
1609
+ * caller DID is bound from the session, never the body.
1610
+ */
1611
+ getAuditEvents(opts?: GetAuditEventsOptions): Promise<AuditPage>;
1524
1612
  /**
1525
1613
  * Execute an action with an attached binary blob using multipart RPC.
1526
1614
  */
@@ -1883,6 +1971,19 @@ declare class T3nClient {
1883
1971
  * caller will narrow to the endpoint's response type.
1884
1972
  */
1885
1973
  private sendUnencryptedSessionRpc;
1974
+ /**
1975
+ * Send a session-authenticated JSON-RPC request whose params/result
1976
+ * are sealed with the same {@link SessionEncryption} layer
1977
+ * `action.execute` uses — for read endpoints that return PII
1978
+ * (`audit.get-mine`) and therefore must not travel plaintext over
1979
+ * TLS. Unlike {@link sendRpcRequest}, this is not tied to the WASM
1980
+ * client `Method` state machine: it takes the raw RPC method string
1981
+ * and only does encrypt → send → decrypt.
1982
+ *
1983
+ * Requires an established (>= Encrypted) session; returns the
1984
+ * decrypted plaintext response string for the caller to `JSON.parse`.
1985
+ */
1986
+ private sendEncryptedSessionRpc;
1886
1987
  /**
1887
1988
  * Inspect a JSON-RPC response for an `error` field and throw the
1888
1989
  * appropriate typed exception. No-op when `response.error` is
@@ -3013,6 +3114,29 @@ declare class TenantContractsNamespace {
3013
3114
  disable(tail: string): Promise<unknown>;
3014
3115
  enable(tail: string): Promise<unknown>;
3015
3116
  unregister(tail: string): Promise<unknown>;
3117
+ /**
3118
+ * Read back debug log entries the tenant's own contract emitted via
3119
+ * `logging::info/debug/error`. Scans the per-(tenant, contract) ring written
3120
+ * by the Trinity host's post-execution flush path and returns the entries in
3121
+ * seq order, newest paging via `next_seq`. Requires the tenant's
3122
+ * `log_max_entries` quota to be non-zero (the master enable; logs are off
3123
+ * by default); returns an empty `entries` array when the feature is
3124
+ * disabled or no logs have been emitted yet.
3125
+ */
3126
+ logs(tail: string, options?: {
3127
+ sinceSeq?: number;
3128
+ limit?: number;
3129
+ minLevel?: "info" | "debug" | "error";
3130
+ }): Promise<{
3131
+ entries: Array<{
3132
+ ts_ms: number;
3133
+ level: "info" | "debug" | "error";
3134
+ message: string;
3135
+ span_id: number | null;
3136
+ }>;
3137
+ next_seq: number | null;
3138
+ truncated: boolean;
3139
+ }>;
3016
3140
  execute(tail: string, input: ContractExecuteInput): Promise<unknown>;
3017
3141
  private contractStateChange;
3018
3142
  }