forked from Txio-labs/txio
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.ts
More file actions
357 lines (307 loc) · 8.7 KB
/
Copy pathindex.ts
File metadata and controls
357 lines (307 loc) · 8.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
// Canonical network identifiers. These lowercase strings are the wire
// contract shared with the backend `Network` enum (see
// backend/api/src/model/network.rs) and the CLI. Keep this union,
// `ALL_NETWORKS`, and `isNetwork` in sync — they are the frontend's single
// source of truth.
export type Network = 'mainnet' | 'testnet' | 'devnet' | 'localnet';
// Every supported network, in canonical order. Iterate this instead of
// hardcoding string arrays so new networks flow through the UI automatically.
export const ALL_NETWORKS: readonly Network[] = [
'mainnet',
'testnet',
'devnet',
'localnet'
];
// Runtime guard that narrows an untrusted string to `Network`. Used at the
// API boundary so unknown values are rejected rather than silently accepted.
export const isNetwork = (
value: string | null | undefined
): value is Network =>
typeof value === 'string' &&
(ALL_NETWORKS as readonly string[]).includes(value);
// Chains the RPC Method Builder can target. Kept in sync with
// `WalletChainFamily` (wallet/types.ts), which the wallet layer already uses.
export type ChainId = 'sui' | 'evm' | 'stellar';
export type FeatureId = 'dashboard' | 'rpc' | 'ptb' | 'move' | 'playground' | 'history' | 'settings' | 'new_request' | 'new_collection' | 'profile' | 'ai_chat' | 'runner' | 'docs' | 'ecosystem' | 'features' | 'integrations' | 'infrastructure' | 'partners';
export interface TabItem {
id: string;
type: FeatureId;
title: string;
data?: any;
isDirty?: boolean;
workspaceId?: string; // Added for workspace persistence
}
export interface Workspace {
id: string;
name: string;
type: 'Personal' | 'Team';
activeEnvId: string;
}
export interface EnvironmentVariable {
key: string;
value: string;
enabled: boolean;
network?: Network | 'all'; // Extended for network scope
workspaceId?: string; // Added for workspace isolation
}
export interface Environment {
id: string;
name: string;
variables: Record<string, string>;
}
export type SuiExplorer = 'suiscan' | 'suiexplorer' | 'suivision';
export type EvmExplorer = 'family' | 'blockscout';
export type StellarExplorer = 'stellarexpert' | 'stellarchain';
export interface AppSettings {
theme: 'dark' | 'light';
showLineNumbers: boolean;
autoSave: boolean;
telemetry: boolean;
customRpc: Record<Network, string>;
/** Preferred Sui block explorer. */
explorer: SuiExplorer;
/** Preferred EVM explorer family: chain-native (Etherscan-family) or Blockscout. */
evmExplorer: EvmExplorer;
/** Preferred Stellar block explorer. */
stellarExplorer: StellarExplorer;
}
export interface Notification {
id: string;
message: string;
type: 'info' | 'success' | 'error';
}
// --- Assertions & Hooks ---
export type TestCategory = 'response' | 'transaction' | 'object' | 'event';
export type TestOperator = 'equals' | 'not_equals' | 'contains' | 'greater_than' | 'less_than' | 'exists' | 'not_exists';
export interface Assertion {
id: string;
category: TestCategory;
target: string; // specific field: 'http_status', 'json_path', 'gas_used', 'abort_code', etc.
operator: TestOperator;
value?: string;
enabled: boolean;
}
// Result of evaluating a single Assertion against a request/response cycle.
export interface AssertionResult {
id: string;
category: TestCategory;
target: string;
operator: TestOperator;
expected?: string;
actual: string;
passed: boolean;
message: string;
}
export interface Hook {
id: string;
type: 'pre' | 'post';
action: 'fetch_object' | 'set_env' | 'cleanup';
key?: string;
value?: string;
enabled: boolean;
}
// --- RPC & Request Types ---
export interface SuiRpcResponse {
jsonrpc: string;
id: number;
result?: any;
error?: any;
}
export enum RequestType {
RPC = 'RPC',
TRANSACTION = 'TRANSACTION'
}
export type TransactionKind = 'MoveCall' | 'TransferSui' | 'TransferObject';
export type MoveParamType = 'u8' | 'u16' | 'u32' | 'u64' | 'u128' | 'u256' | 'bool' | 'address' | 'string' | 'object' | 'vector<u8>' | 'vector<address>';
export interface BuilderArg {
id: string;
type: MoveParamType;
value: string;
}
export interface MoveCallParams {
packageId: string;
module: string;
function: string;
typeArguments: string[];
arguments: BuilderArg[];
gasBudget: string;
gasPrice?: string;
}
export interface TransferParams {
recipient: string;
amount?: string;
objectId?: string;
}
export interface RequestItem {
id: string;
type: RequestType;
name: string;
network?: Network;
rpcParams: {
method: string;
params: any[];
chain?: ChainId; // Defaults to 'sui' when absent (pre-multi-chain requests).
};
txType?: TransactionKind;
moveParams: MoveCallParams;
transferParams?: TransferParams;
isLoading?: boolean;
status?: number;
timestamp?: number;
localVars?: EnvironmentVariable[];
tests?: Assertion[]; // Added
hooks?: Hook[]; // Added
}
export interface HistoryItem extends RequestItem {
timestamp: number;
status: number;
duration: number;
network: Network;
userInitials?: string;
workspaceId?: string; // Added for workspace filtering
}
export interface RequestHistoryItem {
id: string;
method: string;
url: string;
status: number;
duration: number;
timestamp: number;
}
export interface CollectionNode {
id: string;
type: 'collection' | 'folder' | 'request';
name: string;
description?: string;
isExpanded?: boolean;
children?: CollectionNode[];
isShared?: boolean;
requestData?: RequestItem;
workspaceId?: string; // Added for workspace filtering
}
// A user-created transaction recipe template (Recipes page). `id` is a real
// Mongo id for persisted templates, or a `local-*` id for built-in seed
// templates that only exist client-side and cannot be deleted via the API.
export interface RecipeTemplate {
id: string;
title: string;
type: string;
description?: string;
payload?: Record<string, unknown>;
isBuiltIn?: boolean;
}
// --- PTB Visualizer Types ---
export type NodeType = 'transaction' | 'transfer' | 'splitCoins' | 'mergeCoins' | 'moveCall' | 'object';
export interface PTBNode {
id: string;
type: NodeType;
position: { x: number; y: number };
data: Record<string, any>;
inputs: string[]; // Connection IDs
outputs: string[]; // Connection IDs
}
export interface PTBConnection {
id: string;
sourceId: string; // Node ID
targetId: string; // Node ID
sourceHandle?: string;
targetHandle?: string;
}
export interface PTBGraph {
nodes: PTBNode[];
connections: PTBConnection[];
}
// --- Dashboard Types ---
export interface RPCHealthMetric {
endpoint: string;
latency: number[]; // History of latency
successRate: number;
status: 'healthy' | 'degraded' | 'down';
blockHeight: number;
}
export interface DashboardTransaction {
id: string;
digest: string;
sender: string;
type: 'MoveCall' | 'Transfer' | 'Publish';
gas: string;
timestamp: number;
}
export interface ObjectSnapshot {
id: string;
type: string;
version: string;
owner: string;
}
// --- Team & Recipes ---
export interface Recipe {
id: string;
name: string;
description: string;
tags: string[];
template: string; // JSON template
}
export interface TeamUser {
id: string;
name: string;
avatar: string;
status: 'online' | 'offline' | 'busy';
}
export interface NotificationPreferences {
emailDigests: boolean;
emailSecurityAlerts: boolean;
inAppActivityAlerts: boolean;
inAppProductUpdates: boolean;
}
export interface GitHubAccount {
id: string;
login: string;
}
export interface UserProfile {
id: string;
name: string;
email: string;
avatarUrl?: string;
bannerUrl?: string;
notificationPreferences?: NotificationPreferences;
githubAccount?: GitHubAccount;
}
export interface TeamMember {
id: string;
name: string;
email: string;
role: string;
status: string;
avatarColor?: string;
}
export interface ActivityLog {
id: string;
type: 'request' | 'team' | 'system' | 'error';
userName: string;
action: string;
target: string;
timestamp: number;
}
export interface Comment {
id: string;
userName: string;
userAvatarColor?: string;
content: string;
timestamp: number;
}
// --- Session Tracking ---
/** A live sign-in session returned by GET /auth/sessions. */
export interface ActiveSession {
/** MongoDB ObjectId of the session document — used as the revocation key. */
id: string;
/** Human-readable device label, e.g. "Chrome on macOS". */
device_label: string;
/** IP address recorded at sign-in time. */
ip_address: string;
/** ISO-8601 timestamp of when the session was created. */
created_at: string;
/** ISO-8601 timestamp of the last known activity. */
last_active_at: string;
/** True when this entry corresponds to the currently active JWT. */
is_current: boolean;
}