@terminal3/t3n-sdk 4.8.0 → 4.9.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
  /**
@@ -3805,5 +3891,5 @@ declare function tenantDidHex(tenantDid: string): string;
3805
3891
  declare function validateTail(tail: string): string;
3806
3892
  declare function canonicalTenantName(tenantDid: string, tail: string): string;
3807
3893
 
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 };
3894
+ 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 };
3895
+ 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, 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 };