@miradorlabs/parallax-web 1.0.8 → 2.0.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
@@ -1,63 +1,22 @@
1
+ import * as mirador_gateway_parallax_web_proto_gateway_parallax_v1_parallax_gateway_pb from 'mirador-gateway-parallax-web/proto/gateway/parallax/v1/parallax_gateway_pb';
1
2
  import { CreateTraceRequest, CreateTraceResponse } from 'mirador-gateway-parallax-web/proto/gateway/parallax/v1/parallax_gateway_pb';
2
3
  export { CreateTraceRequest, CreateTraceResponse } from 'mirador-gateway-parallax-web/proto/gateway/parallax/v1/parallax_gateway_pb';
3
- import { Observable } from 'rxjs';
4
4
 
5
- declare class ParallaxClient {
6
- apiKey?: string | undefined;
7
- apiUrl: string;
8
- private client;
9
- constructor(apiKey?: string | undefined, apiUrl?: string);
10
- /**
11
- * Gather client metadata for traces/spans
12
- * Returns a metadata object with client environment details
13
- * This includes browser, OS, screen size, IP address, and more
14
- * @returns metadata
15
- */
16
- getClientMetadata(): Promise<{
17
- [key: string]: string;
18
- }>;
19
- /**
20
- * Creates a CreateTraceRequest with optional attributes and client metadata
21
- * @param name name of the trace
22
- * @param tags optional tags for trace
23
- * @param attr optional attributes for trace
24
- * @param includeClientMeta optional flag to include client metadata (ip, browser, os, etc)
25
- * @returns a CreateTraceRequest object to be used for the createTrace request
26
- */
27
- createTraceRequest({ name, tags, attr, includeClientMeta }: {
28
- name: string;
29
- tags?: string[];
30
- attr?: {
31
- [key: string]: string;
32
- };
33
- includeClientMeta?: boolean;
34
- }): Promise<CreateTraceRequest>;
35
- /**
36
- * Create a new trace
37
- * @param params Parameters to create a new trace
38
- * @returns Response from the create trace operation
39
- */
40
- createTrace(params: CreateTraceRequest): Promise<CreateTraceResponse>;
41
- /**
42
- * Create a new trace builder
43
- *
44
- * Example usage:
45
- * ```typescript
46
- * const response = await client.trace("swap_execution")
47
- * .addAttribute("user", "0xabc...")
48
- * .addAttribute("slippage_bps", 25)
49
- * .addTag("dex")
50
- * .addTag("swap")
51
- * .addEvent("wallet_connected", { wallet: "MetaMask" })
52
- * .addEvent("quote_received")
53
- * .submit("0x123...", "ethereum");
54
- * ```
55
- *
56
- * @param name The name of the trace
57
- * @param includeClientMeta Optional flag to automatically include client metadata
58
- * @returns A ParallaxTrace builder instance
59
- */
60
- trace(name: string, includeClientMeta?: boolean): ParallaxTrace;
5
+ /**
6
+ * Supported chain names (maps to Chain enum in proto)
7
+ */
8
+ type ChainName = 'ethereum' | 'polygon' | 'arbitrum' | 'base' | 'optimism' | 'bsc';
9
+
10
+ /**
11
+ * ParallaxTrace builder class for constructing traces with method chaining
12
+ */
13
+
14
+ /**
15
+ * Interface for the client that ParallaxTrace uses to submit traces
16
+ * @internal
17
+ */
18
+ interface TraceSubmitter {
19
+ _sendTrace(request: CreateTraceRequest): Promise<CreateTraceResponse>;
61
20
  }
62
21
  /**
63
22
  * Builder class for constructing traces with method chaining
@@ -71,21 +30,21 @@ declare class ParallaxTrace {
71
30
  private txHashHint?;
72
31
  private client;
73
32
  private includeClientMeta;
74
- constructor(client: ParallaxClient, name: string, includeClientMeta?: boolean);
33
+ constructor(client: TraceSubmitter, name?: string, includeClientMeta?: boolean);
75
34
  /**
76
35
  * Add an attribute to the trace
77
36
  * @param key Attribute key
78
- * @param value Attribute value (will be converted to string)
37
+ * @param value Attribute value (objects are stringified, primitives converted to string)
79
38
  * @returns This trace builder for chaining
80
39
  */
81
- addAttribute(key: string, value: string | number | boolean): this;
40
+ addAttribute(key: string, value: string | number | boolean | object): this;
82
41
  /**
83
42
  * Add multiple attributes to the trace
84
- * @param attributes Object containing key-value pairs
43
+ * @param attributes Object containing key-value pairs (objects are stringified)
85
44
  * @returns This trace builder for chaining
86
45
  */
87
46
  addAttributes(attributes: {
88
- [key: string]: string | number | boolean;
47
+ [key: string]: string | number | boolean | object;
89
48
  }): this;
90
49
  /**
91
50
  * Add a tag to the trace
@@ -108,176 +67,59 @@ declare class ParallaxTrace {
108
67
  */
109
68
  addEvent(eventName: string, details?: string | object, timestamp?: Date): this;
110
69
  /**
111
- * Set or update the transaction hash hint
70
+ * Set the transaction hash hint for blockchain correlation
112
71
  * @param txHash Transaction hash
113
- * @param chainId Chain ID (e.g., "ethereum", "polygon")
72
+ * @param chain Chain name (e.g., "ethereum", "polygon", "base")
114
73
  * @param details Optional details about the transaction
115
- * @param timestamp Optional timestamp (defaults to current time)
116
74
  * @returns This trace builder for chaining
117
75
  */
118
- setTxHash(txHash: string, chainId: string, details?: string, timestamp?: Date): this;
119
- /**
120
- * Submit the trace without a transaction hash hint (if not already set via setTxHash)
121
- * @returns Response from the create trace operation
122
- */
123
- submit(): Promise<CreateTraceResponse>;
76
+ setTxHint(txHash: string, chain: ChainName, details?: string): this;
124
77
  /**
125
- * Submit the trace with a transaction hash hint (overrides any previously set via setTxHash)
126
- * @param txHash Transaction hash
127
- * @param chainId Chain ID (e.g., "ethereum", "polygon")
128
- * @param details Optional details about the transaction
129
- * @returns Response from the create trace operation
78
+ * Create and submit the trace to the gateway
79
+ * @returns The trace ID if successful, undefined if failed
130
80
  */
131
- submit(txHash: string, chainId: string, details?: string): Promise<CreateTraceResponse>;
132
- }
133
-
134
- interface Metadata {
135
- [key: string]: string;
136
- }
137
- interface Rpc {
138
- request(service: string, method: string, data: Uint8Array, metadata?: Metadata): Promise<Uint8Array>;
139
- clientStreamingRequest(service: string, method: string, data: Observable<Uint8Array>): Promise<Uint8Array>;
140
- serverStreamingRequest(service: string, method: string, data: Uint8Array): Observable<Uint8Array>;
141
- bidirectionalStreamingRequest(service: string, method: string, data: Observable<Uint8Array>): Observable<Uint8Array>;
142
- }
143
- declare class GrpcWebRpc implements Rpc {
144
- private url;
145
- private apiKey?;
146
- constructor(url: string, apiKey?: string);
147
- request(service: string, method: string, data: Uint8Array, metadata?: Metadata): Promise<Uint8Array>;
148
- clientStreamingRequest(): Promise<Uint8Array>;
149
- serverStreamingRequest(service: string, method: string, data: Uint8Array): Observable<Uint8Array>;
150
- bidirectionalStreamingRequest(): Observable<Uint8Array>;
81
+ create(): Promise<string | undefined>;
151
82
  }
152
83
 
153
84
  /**
154
- * Parallax Service - Transaction Tracing for Web Applications
155
- * Creates individual traces for each transaction and tracks them through their lifecycle
156
- *
157
- * This service provides a simplified interface for tracking transactions with automatic
158
- * client metadata collection and lifecycle management.
85
+ * Main client for interacting with the Parallax Gateway API
159
86
  */
160
-
161
- interface TransactionInfo {
162
- traceId: string;
163
- timestamp: string;
164
- txHash: string | null;
165
- from?: string;
166
- to?: string;
167
- network?: string;
168
- }
169
- interface TransactionData {
170
- from: string;
171
- to: string;
172
- value: string;
173
- network?: string;
174
- walletAddress?: string;
175
- additionalData?: Record<string, any>;
176
- }
177
- interface FinishOptions {
178
- success: boolean;
179
- error?: string;
180
- }
181
- declare class ParallaxService {
87
+ declare class ParallaxClient {
88
+ apiUrl: string;
89
+ apiKey: string;
182
90
  private client;
183
- private activeTransactions;
184
- constructor();
185
- /**
186
- * Initialize the Parallax client (lazy initialization)
187
- * @param apiKey - Optional API key for authentication
188
- * @param gatewayUrl - Optional custom gateway URL
189
- */
190
- private _ensureClient;
191
- /**
192
- * Start a new transaction trace
193
- * Called when user initiates a transaction
194
- *
195
- * Uses the builder pattern to create a trace with events
196
- *
197
- * @param txData - Transaction data
198
- * @param name - Name for the trace (e.g., 'SendingTrace', 'SwappingTrace')
199
- * @param options - Optional configuration (apiKey, gatewayUrl, includeClientMeta)
200
- * @returns Promise with traceId, rootSpanId, and txId
201
- */
202
- startTransactionTrace(txData: TransactionData, name?: string, options?: {
203
- apiKey?: string;
204
- gatewayUrl?: string;
205
- includeClientMeta?: boolean;
206
- }): Promise<{
207
- traceId: string;
208
- rootSpanId: string;
209
- txId: string;
210
- }>;
211
- /**
212
- * Associate a transaction hash with an existing trace
213
- * Called when the transaction hash is available after signing/sending
214
- *
215
- * NOTE: This method is deprecated as the new API does not support adding hints to existing traces.
216
- * Transaction hashes should be provided at trace creation time via the builder's submit(txHash, chainId) method.
217
- *
218
- * @param txId - Transaction identifier returned from startTransactionTrace
219
- * @param txHash - Blockchain transaction hash
220
- * @param chainId - Chain ID
221
- * @deprecated Use submit(txHash, chainId) when creating the trace instead
222
- */
223
- associateTransactionHash(txId: string, txHash: string, chainId: number): Promise<void>;
224
- /**
225
- * Add an event to a transaction trace
226
- *
227
- * NOTE: This method is deprecated as the new API does not support adding events to existing traces.
228
- * Events should be added to the trace builder before calling submit().
229
- *
230
- * @param txId - Transaction identifier
231
- * @param eventName - Event name
232
- * @param attributes - Event attributes
233
- * @deprecated Use the trace builder's addEvent() method before calling submit() instead
234
- */
235
- addTransactionEvent(txId: string, eventName: string, attributes?: Record<string, any>): Promise<void>;
236
91
  /**
237
- * Add an error to a transaction trace
238
- *
239
- * NOTE: This method is deprecated as the new API does not support adding errors to existing traces.
240
- * Errors should be added as events to the trace builder before calling submit().
241
- *
242
- * @param txId - Transaction identifier
243
- * @param error - Error object or message
244
- * @param errorType - Type/category of error (e.g., 'TransactionError', 'NetworkError', 'UserRejection')
245
- * @deprecated Use the trace builder's addEvent() method to add error events before calling submit() instead
92
+ * Create a new ParallaxClient instance
93
+ * @param apiKey Required API key for authentication (sent as x-parallax-api-key header)
94
+ * @param apiUrl Optional gateway URL (defaults to parallax-gateway.dev.mirador.org:443)
246
95
  */
247
- addTransactionError(txId: string, error: Error | string, errorType?: string): Promise<void>;
96
+ constructor(apiKey: string, apiUrl?: string);
248
97
  /**
249
- * Finish a transaction trace
250
- *
251
- * NOTE: This method is deprecated as the new API does not support span lifecycle management.
252
- * Traces are completed when submit() is called on the builder.
253
- *
254
- * @param txId - Transaction identifier
255
- * @param options - Finish options (success, error message)
256
- * @deprecated Traces are automatically completed when submit() is called
98
+ * Internal method to send trace to gateway
99
+ * @internal
257
100
  */
258
- finishTransactionTrace(txId: string, options?: FinishOptions): Promise<void>;
101
+ _sendTrace(request: CreateTraceRequest): Promise<mirador_gateway_parallax_web_proto_gateway_parallax_v1_parallax_gateway_pb.CreateTraceResponse>;
259
102
  /**
260
- * Get info about an active transaction
103
+ * Create a new trace builder
261
104
  *
262
- * @param txId - Transaction identifier
263
- * @returns Transaction info or null if not found
264
- */
265
- getTransactionInfo(txId: string): TransactionInfo | null;
266
- /**
267
- * Get all active transactions
105
+ * Example usage:
106
+ * ```typescript
107
+ * const response = await client.trace("swap_execution")
108
+ * .addAttribute("user", "0xabc...")
109
+ * .addAttribute("slippage_bps", 25)
110
+ * .addTag("dex")
111
+ * .addTag("swap")
112
+ * .addEvent("wallet_connected", { wallet: "MetaMask" })
113
+ * .addEvent("quote_received")
114
+ * .setTxHint("0x123...", "ethereum")
115
+ * .create();
116
+ * ```
268
117
  *
269
- * @returns Array of active transaction info
270
- */
271
- getAllActiveTransactions(): Array<TransactionInfo & {
272
- txId: string;
273
- }>;
274
- /**
275
- * Get the ParallaxClient instance for advanced usage
276
- * @param apiKey - Optional API key
277
- * @param gatewayUrl - Optional gateway URL
118
+ * @param name Optional name of the trace (defaults to empty string)
119
+ * @param includeClientMeta Optional flag to automatically include client metadata
120
+ * @returns A ParallaxTrace builder instance
278
121
  */
279
- getClient(apiKey?: string, gatewayUrl?: string): ParallaxClient;
122
+ trace(name?: string, includeClientMeta?: boolean): ParallaxTrace;
280
123
  }
281
- declare const parallaxService: ParallaxService;
282
124
 
283
- export { GrpcWebRpc, ParallaxClient, ParallaxService, ParallaxTrace, parallaxService };
125
+ export { ParallaxClient, ParallaxTrace };