@terminal3/t3n-sdk 4.8.0 → 4.10.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
@@ -3205,6 +3205,92 @@ declare function formatTokens(baseUnits: number | bigint): string;
3205
3205
  */
3206
3206
  declare function toBaseUnits(tokens: number): number;
3207
3207
 
3208
+ /**
3209
+ * SessionUsageReportClient — typed wrapper over the authenticated
3210
+ * `/api/rpc` + `action.execute` pipeline for the per-organisation usage
3211
+ * report served by `tee:admin/contracts#org-usage-report`.
3212
+ *
3213
+ * Unlike the cluster-admin `metering.usage-report` action (reached over
3214
+ * `POST /api/admin` with an EIP-191 cluster-admin signature), this export
3215
+ * is authenticated on the caller's ordinary session DID: the node stamps
3216
+ * the proven `authenticated_did` into the contract context, and the
3217
+ * contract returns the signed report ONLY when that DID is in the
3218
+ * requested org's admin set. An org admin can therefore fetch **only their
3219
+ * own org's** usage.
3220
+ *
3221
+ * Mirrors {@link SessionOrgDataClient}: it accepts a caller-owned
3222
+ * {@link T3nClient} that the caller has already driven through
3223
+ * `handshake()` and `authenticate()` (e.g. the SIWE flow the orgs admin UI
3224
+ * uses). The constructor performs no auth lifecycle of its own.
3225
+ */
3226
+
3227
+ interface OrgUsageReportInput {
3228
+ /**
3229
+ * Owning organisation DID (`did:t3n:<40hex>` or bare 40-hex). The
3230
+ * authenticated caller MUST be an admin of this org, else the contract
3231
+ * refuses with a `not_org_admin:` error.
3232
+ */
3233
+ orgDid: string;
3234
+ /** Inclusive window start (cluster-timestamp ms). */
3235
+ fromMs: number;
3236
+ /** Exclusive window end (cluster-timestamp ms). Must be > `fromMs`. */
3237
+ toMs: number;
3238
+ /** Optional cap on rows scanned; `truncated` is set on the reply when hit. */
3239
+ maxScan?: number;
3240
+ }
3241
+ /** Signature envelope on the signed report (secp256k1 cluster key). */
3242
+ interface UsageReportSignature {
3243
+ alg: string;
3244
+ /** Signer eth address, derived from the returned pubkey (never the request). */
3245
+ node_id: string;
3246
+ payload_hash: string;
3247
+ sig: unknown;
3248
+ pub_key: unknown;
3249
+ }
3250
+ /**
3251
+ * The `completed` envelope returned by `org-usage-report`. Identical shape
3252
+ * to the cluster-admin `metering.usage-report` reply. The signed report
3253
+ * body itself is the base64 `report_b64` (JCS-canonical bytes the
3254
+ * `signature` attests to).
3255
+ */
3256
+ interface OrgUsageReport {
3257
+ status: string;
3258
+ report_id: string;
3259
+ org_did: string;
3260
+ from_ms: number;
3261
+ to_ms: number;
3262
+ report_b64: string;
3263
+ signature: UsageReportSignature;
3264
+ truncated: boolean;
3265
+ }
3266
+ declare function isOrgUsageReport(v: unknown): v is OrgUsageReport;
3267
+ /**
3268
+ * Session-authenticated client for the per-org usage report.
3269
+ *
3270
+ * @see SessionOrgDataClient for the precondition contract — the supplied
3271
+ * {@link T3nClient} must already be handshaken + authenticated; the
3272
+ * runtime guard only catches the no-handshake case.
3273
+ */
3274
+ declare class SessionUsageReportClient {
3275
+ private readonly t3n;
3276
+ private readonly baseUrl;
3277
+ constructor(t3n: T3nClient, baseUrl: string);
3278
+ /**
3279
+ * Fetch the signed usage report for an org the caller administers.
3280
+ *
3281
+ * Refuses with `not_org_admin: ...` when the authenticated session DID
3282
+ * is not in the org's admin set — an org admin can only read their own
3283
+ * org's usage.
3284
+ */
3285
+ getOrgUsageReport(input: OrgUsageReportInput): Promise<OrgUsageReport>;
3286
+ }
3287
+ /**
3288
+ * Construct a {@link SessionUsageReportClient} from a caller-owned
3289
+ * {@link T3nClient} that has already been driven through `handshake()` and
3290
+ * `authenticate()`.
3291
+ */
3292
+ declare function createUsageReportClientFromSession(t3n: T3nClient, baseUrl: string): SessionUsageReportClient;
3293
+
3208
3294
  /** Closed-vocabulary serialisation annotations for a contract function's body. */
3209
3295
  interface WireBlock {
3210
3296
  /**
@@ -3631,6 +3717,18 @@ type TenantMapUpdatePatch = MapUpdateInput;
3631
3717
  type TenantContractPublishInput = ContractPublishInput;
3632
3718
  type TenantContractSetDescriptorInput = ContractSetDescriptorInput;
3633
3719
  type TenantContractExecuteInput = ContractExecuteInput;
3720
+ /**
3721
+ * Coarse lifecycle state of a tenant map, mirroring the contract's
3722
+ * `MapLifecycleStatus` enum on the `tee:tenant/contracts::map-get-status` op.
3723
+ * Exported from the SDK public barrel so FE code has a single source of truth
3724
+ * for the union instead of re-declaring it.
3725
+ *
3726
+ * - `"active"` — a live map (`Private`/`Public`) exists at this name.
3727
+ * - `"deleting"` — deleted, host sweeper still draining. Poll until `"absent"`.
3728
+ * - `"absent"` — no row (never created, or deletion fully settled); name is
3729
+ * free to (re-)create.
3730
+ */
3731
+ type MapLifecycleStatus = "active" | "deleting" | "absent";
3634
3732
  /**
3635
3733
  * Options shared by the `tee:tenant` management calls that accept an optional
3636
3734
  * `tenant` target argument.
@@ -3683,6 +3781,45 @@ declare class TenantMapsNamespace {
3683
3781
  create(input: MapCreateInput, opts?: TenantTargetOptions): Promise<unknown>;
3684
3782
  update(tail: string, patch: MapUpdateInput, opts?: TenantTargetOptions): Promise<unknown>;
3685
3783
  delete(tail: string, opts?: TenantTargetOptions): Promise<unknown>;
3784
+ /**
3785
+ * Write a UTF-8 key/value entry into an owned map via the tenant management
3786
+ * surface (`map-entry-set`). Mirrors the `.delete` shape: canonical name is
3787
+ * always rooted at the target tenant, and `payload.tenant` is included only
3788
+ * when `opts.tenantTarget` is supplied (`exactOptionalPropertyTypes` — never
3789
+ * pass a stringified `null`, the contract's `deny_unknown_fields` accepts an
3790
+ * absent field, not a literal `null`).
3791
+ *
3792
+ * SDK-only addition: the `map-entry-set` contract op
3793
+ * has always accepted the optional `tenant` field and routed through
3794
+ * `resolve_tenant_did` — this helper simply completes the SDK's map-entry
3795
+ * surface so `set` / `get` / `getStatus` are all first-class alongside the
3796
+ * lifecycle trio.
3797
+ */
3798
+ entrySet(tail: string, key: string, value: string, opts?: TenantTargetOptions): Promise<void>;
3799
+ /**
3800
+ * Read back a UTF-8 key/value entry from an owned map via the tenant
3801
+ * management surface (`map-entry-get`). Requires the paired contract-side
3802
+ * 1.24.0-or-later registration for the `tenant` argument to be accepted —
3803
+ * a node on an earlier contract rejects `tenant`-bearing requests with
3804
+ * `deny_unknown_fields`.
3805
+ *
3806
+ * Unwraps the contract's `{ value: string | null }` envelope to
3807
+ * `string | null` for caller ergonomics; `null` is the deliberate
3808
+ * "key absent" signal, not an error.
3809
+ */
3810
+ entryGet(tail: string, key: string, opts?: TenantTargetOptions): Promise<string | null>;
3811
+ /**
3812
+ * Report the lifecycle status of an owned map (`map-get-status`),
3813
+ * so a client can poll a delete → recreate cycle instead of guessing.
3814
+ * Requires the paired contract-side 1.24.0-or-later registration for the
3815
+ * `tenant` argument to be accepted.
3816
+ *
3817
+ * `"absent"` (never created, or deletion fully settled) is a *success*
3818
+ * answer meaning the name is free to (re-)create; it is not an error.
3819
+ * `"deleting"` means the host sweeper is still draining the map — poll
3820
+ * again until `"absent"`.
3821
+ */
3822
+ getStatus(tail: string, opts?: TenantTargetOptions): Promise<MapLifecycleStatus>;
3686
3823
  }
3687
3824
  declare class TenantContractsNamespace {
3688
3825
  private readonly client;
@@ -3805,5 +3942,5 @@ declare function tenantDidHex(tenantDid: string): string;
3805
3942
  declare function validateTail(tail: string): string;
3806
3943
  declare function canonicalTenantName(tenantDid: string, tail: string): string;
3807
3944
 
3808
- export { AuthMethod, AuthenticationError, BASE_UNITS_PER_TOKEN, ContractResponseError, DEFAULT_ENVIRONMENT, DEFAULT_INDIVIDUAL_THRESHOLD_CENTS, DEFAULT_KYC_POLL_CADENCE, HandshakeError, HttpTransport, KycStatusTimeoutError, LogLevel, MockTransport, NODE_URLS, OrgDataClient, OtpRateLimitedError, RpcError, SessionExpiredError, SessionOrgDataClient, SessionStateError, SessionStatus, T3nClient, T3nError, TERMINAL_KYC_STATUSES, TOKEN_DECIMALS, TenantClient, TenantContractsNamespace, TenantMapsNamespace, TenantNamespace, TenantSdkValidationError, TenantTokenNamespace, UnsupportedTenantSdkOperationError, UserUpsertError, WasmError, WireEncodingError, Z_PAYROLL_AUDIT_READ_FUNCTIONS, Z_PAYROLL_RUN_FUNCTIONS, _b64uEncode, assertShape, b64uDecodeStrict, b64uEncodeBytes, bytesToString, canonicalTenantName, clearKeyCache, compactDidFromBytes, createDefaultHandlers, createEmailOtpAuthInput, createEthAuthInput, createLogger, createMlKemPublicKeyHandler, createOidcAuthInput, createOrgDataClientFromSession, createRandomHandler, createWorkloadAuthInput, decodeWasmErrorMessage, eth_get_address, extractWasmError, fetchDkgAttestation, fetchMlKemPublicKey, formatTokens, generateRandomString, generateUUID, getEnvironment, getEnvironmentName, getGlobalLogLevel, getLogger, getNodeUrl, getScriptVersion, isDataGetResponse, isDataListResponse, isMutationResponse, isObject, isOrgContractGrants, isOrgPolicyMeta, isOrgPolicyView, isOrgWriters, isUnsafeTrustServer, loadConfig, loadWasmComponent, maskKeyMaterial, mergeAgentAuthEntries, mergeDiscoverDids, metamask_get_address, metamask_sign, parseAgentAuthGet, parseAgentAuthPolicy, parseContractResponse, redactSecrets, redactSecretsFromJson, requestToWire, setEnvironment, setGlobalLogLevel, setNodeUrl, stringToBytes, tenantDidHex, toAgentAuthUpdateWire, toBaseUnits, validateConfig, validateTail, verifyDkgAttestation, verifyTdxQuote };
3809
- export type { AdmitForOrgOptions, AgentAuthEntry, AgentAuthMergeResult, AgentAuthPolicy, AgentAuthScriptGrant, AgentAuthUpdateInput, AuthInput, BalanceRow, ChargeReason, ClientAuth, ClientHandshake, ConfigValidationResult, ContractExecuteInput, ContractKind, ContractPublishInput, ContractRegisterResult, ContractResponseSchema, ContractSetDescriptorInput, CreatePolicyInput, DataGetInput, DataGetResponse, DataListInput, DataListResponse, DelegationGrantKind, DelegationGrantRef, DeleteDataInput, DeleteGrantsInput, DeleteScopeInput, Did, Direction, DkgAttestation, DkgVerifyResult, EmailOtpAuthInput, EmailOtpCredentials, Environment, EthAuthInput, ExecuteBusinessContractOptions, ExecuteOrgDataActionOptions, GetUsageOptions, GrantCheckParams, GrantCheckResult, GrantsGetInput, GuestToHostHandler, GuestToHostHandlers, HandshakeResult, JsonRpcRequest, JsonRpcResponse, KycPollCadence, KycPollOptions, KycStatus, KycStatusKind, ListContractsParams, ListContractsResult, ListContractsScope, ListedContract, Logger, MapCreateInput, MapResponse, MapUpdateInput, MapVisibility, MutationResponse, OidcAuthInput, OidcCredentials, OrgContractGrants, OrgDataActionWire, OrgDataClientOptions, OrgPolicyMeta, OrgPolicyView, OrgWriters, OtpChannel, OtpMergeSuggestion, OtpRequestInput, OtpRequestResult, OtpVerifyInput, OtpVerifyResult, PayrollRunRequest, PeerQuoteResult, PolicyGetInput, QuoteVerifyResult, ReaderSet, SdkConfig, SessionCrypto, SessionId, SetGrantsInput, SetWritersInput, StringEncoding, SubmitUserInputArgs, SubmitUserInputResult, T3nClientConfig, TenantAdmitProjection, TenantAdmitStatus, TenantBaseClient, TenantClientConfig, TenantContractExecuteInput, TenantContractPublishInput, TenantContractSetDescriptorInput, TenantExecutionSession, TenantMapCreateInput, TenantMapUpdatePatch, TenantMeResponse, TenantSdkEnvironment, TenantSelfAdmitResult, TenantStatus, TenantTargetOptions, TokenTxKind, Transport, TrustAnchor, TrustAnchorOrUnsafe, UnsafeTrustServer, UpdateMetaInput, UsageEntry, UsagePage, UserGrant, UserInputProfile, UserUpsertErrorKind, WasmComponent, WasmNextResult, WireBlock, WorkloadAuthInput, WriteDataInput, WriterSet, WritersGetInput };
3945
+ export { AuthMethod, AuthenticationError, BASE_UNITS_PER_TOKEN, ContractResponseError, DEFAULT_ENVIRONMENT, DEFAULT_INDIVIDUAL_THRESHOLD_CENTS, DEFAULT_KYC_POLL_CADENCE, HandshakeError, HttpTransport, KycStatusTimeoutError, LogLevel, MockTransport, NODE_URLS, OrgDataClient, OtpRateLimitedError, RpcError, SessionExpiredError, SessionOrgDataClient, SessionStateError, SessionStatus, SessionUsageReportClient, T3nClient, T3nError, TERMINAL_KYC_STATUSES, TOKEN_DECIMALS, TenantClient, TenantContractsNamespace, TenantMapsNamespace, TenantNamespace, TenantSdkValidationError, TenantTokenNamespace, UnsupportedTenantSdkOperationError, UserUpsertError, WasmError, WireEncodingError, Z_PAYROLL_AUDIT_READ_FUNCTIONS, Z_PAYROLL_RUN_FUNCTIONS, _b64uEncode, assertShape, b64uDecodeStrict, b64uEncodeBytes, bytesToString, canonicalTenantName, clearKeyCache, compactDidFromBytes, createDefaultHandlers, createEmailOtpAuthInput, createEthAuthInput, createLogger, createMlKemPublicKeyHandler, createOidcAuthInput, createOrgDataClientFromSession, createRandomHandler, createUsageReportClientFromSession, createWorkloadAuthInput, decodeWasmErrorMessage, eth_get_address, extractWasmError, fetchDkgAttestation, fetchMlKemPublicKey, formatTokens, generateRandomString, generateUUID, getEnvironment, getEnvironmentName, getGlobalLogLevel, getLogger, getNodeUrl, getScriptVersion, isDataGetResponse, isDataListResponse, isMutationResponse, isObject, isOrgContractGrants, isOrgPolicyMeta, isOrgPolicyView, isOrgUsageReport, isOrgWriters, isUnsafeTrustServer, loadConfig, loadWasmComponent, maskKeyMaterial, mergeAgentAuthEntries, mergeDiscoverDids, metamask_get_address, metamask_sign, parseAgentAuthGet, parseAgentAuthPolicy, parseContractResponse, redactSecrets, redactSecretsFromJson, requestToWire, setEnvironment, setGlobalLogLevel, setNodeUrl, stringToBytes, tenantDidHex, toAgentAuthUpdateWire, toBaseUnits, validateConfig, validateTail, verifyDkgAttestation, verifyTdxQuote };
3946
+ export type { AdmitForOrgOptions, AgentAuthEntry, AgentAuthMergeResult, AgentAuthPolicy, AgentAuthScriptGrant, AgentAuthUpdateInput, AuthInput, BalanceRow, ChargeReason, ClientAuth, ClientHandshake, ConfigValidationResult, ContractExecuteInput, ContractKind, ContractPublishInput, ContractRegisterResult, ContractResponseSchema, ContractSetDescriptorInput, CreatePolicyInput, DataGetInput, DataGetResponse, DataListInput, DataListResponse, DelegationGrantKind, DelegationGrantRef, DeleteDataInput, DeleteGrantsInput, DeleteScopeInput, Did, Direction, DkgAttestation, DkgVerifyResult, EmailOtpAuthInput, EmailOtpCredentials, Environment, EthAuthInput, ExecuteBusinessContractOptions, ExecuteOrgDataActionOptions, GetUsageOptions, GrantCheckParams, GrantCheckResult, GrantsGetInput, GuestToHostHandler, GuestToHostHandlers, HandshakeResult, JsonRpcRequest, JsonRpcResponse, KycPollCadence, KycPollOptions, KycStatus, KycStatusKind, ListContractsParams, ListContractsResult, ListContractsScope, ListedContract, Logger, MapCreateInput, MapLifecycleStatus, MapResponse, MapUpdateInput, MapVisibility, MutationResponse, OidcAuthInput, OidcCredentials, OrgContractGrants, OrgDataActionWire, OrgDataClientOptions, OrgPolicyMeta, OrgPolicyView, OrgUsageReport, OrgUsageReportInput, OrgWriters, OtpChannel, OtpMergeSuggestion, OtpRequestInput, OtpRequestResult, OtpVerifyInput, OtpVerifyResult, PayrollRunRequest, PeerQuoteResult, PolicyGetInput, QuoteVerifyResult, ReaderSet, SdkConfig, SessionCrypto, SessionId, SetGrantsInput, SetWritersInput, StringEncoding, SubmitUserInputArgs, SubmitUserInputResult, T3nClientConfig, TenantAdmitProjection, TenantAdmitStatus, TenantBaseClient, TenantClientConfig, TenantContractExecuteInput, TenantContractPublishInput, TenantContractSetDescriptorInput, TenantExecutionSession, TenantMapCreateInput, TenantMapUpdatePatch, TenantMeResponse, TenantSdkEnvironment, TenantSelfAdmitResult, TenantStatus, TenantTargetOptions, TokenTxKind, Transport, TrustAnchor, TrustAnchorOrUnsafe, UnsafeTrustServer, UpdateMetaInput, UsageEntry, UsagePage, UsageReportSignature, UserGrant, UserInputProfile, UserUpsertErrorKind, WasmComponent, WasmNextResult, WireBlock, WorkloadAuthInput, WriteDataInput, WriterSet, WritersGetInput };