@miradorlabs/parallax-web 1.0.6 → 1.0.7

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,5 +1,5 @@
1
- import { CreateTraceRequest, CreateTraceResponse, StartSpanRequest, StartSpanResponse, FinishSpanRequest, FinishSpanResponse, AddSpanEventRequest, AddSpanEventResponse, AddSpanErrorRequest, AddSpanErrorResponse, AddSpanHintRequest, AddSpanHintResponse } from 'mirador-gateway-parallax-web/proto/gateway/parallax/v1/parallax_gateway_pb';
2
- export { AddSpanErrorRequest, AddSpanErrorResponse, AddSpanEventRequest, AddSpanEventResponse, AddSpanHintRequest, AddSpanHintResponse, CreateTraceRequest, CreateTraceResponse, FinishSpanRequest, FinishSpanResponse, StartSpanRequest, StartSpanResponse } from 'mirador-gateway-parallax-web/proto/gateway/parallax/v1/parallax_gateway_pb';
1
+ import { CreateTraceRequest, CreateTraceResponse } from 'mirador-gateway-parallax-web/proto/gateway/parallax/v1/parallax_gateway_pb';
2
+ export { CreateTraceRequest, CreateTraceResponse } from 'mirador-gateway-parallax-web/proto/gateway/parallax/v1/parallax_gateway_pb';
3
3
  import { Observable } from 'rxjs';
4
4
 
5
5
  declare class ParallaxClient {
@@ -39,97 +39,96 @@ declare class ParallaxClient {
39
39
  */
40
40
  createTrace(params: CreateTraceRequest): Promise<CreateTraceResponse>;
41
41
  /**
42
- * Create a StartSpanRequest with optional attributes and client metadata
43
- * @param traceId trace id to associate the span with
44
- * @param name name of the span
45
- * @param parentSpanId (optional) create a span off a parent span id
46
- * @param attr (optional) attributes to add to the span
47
- * @param includeClientMeta (optional) flag to include client metadata (ip, browser, os, etc)
48
- * @returns
49
- */
50
- createStartSpanRequest({ traceId, name, parentSpanId, attr, includeClientMeta }: {
51
- traceId: string;
52
- name: string;
53
- parentSpanId?: string;
54
- attr?: {
55
- [key: string]: string;
56
- };
57
- includeClientMeta?: boolean;
58
- }): Promise<StartSpanRequest>;
59
- /**
60
- * Start a new span within a trace
61
- * @param params Parameters to start a new span
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
62
59
  */
63
- startSpan(params: StartSpanRequest): Promise<StartSpanResponse>;
60
+ trace(name: string, includeClientMeta?: boolean): ParallaxTrace;
61
+ }
62
+ /**
63
+ * Builder class for constructing traces with method chaining
64
+ * Automatically handles web-specific features like client metadata
65
+ */
66
+ declare class ParallaxTrace {
67
+ private name;
68
+ private attributes;
69
+ private tags;
70
+ private events;
71
+ private txHashHint?;
72
+ private client;
73
+ private includeClientMeta;
74
+ constructor(client: ParallaxClient, name: string, includeClientMeta?: boolean);
64
75
  /**
65
- * Create a FinishSpanRequest
66
- * @param params Parameters to finish a span - traceId, spanId, status (optional) (success, errorMessage)
67
- * @returns FinishSpanRequest
76
+ * Add an attribute to the trace
77
+ * @param key Attribute key
78
+ * @param value Attribute value (will be converted to string)
79
+ * @returns This trace builder for chaining
68
80
  */
69
- createFinishSpanRequest({ traceId, spanId, status }: {
70
- traceId: string;
71
- spanId: string;
72
- status?: {
73
- success: boolean;
74
- errorMessage: string;
75
- };
76
- }): FinishSpanRequest;
81
+ addAttribute(key: string, value: string | number | boolean): this;
77
82
  /**
78
- * Finish a span within a trace
79
- * @param params Parameters to finish a span
83
+ * Add multiple attributes to the trace
84
+ * @param attributes Object containing key-value pairs
85
+ * @returns This trace builder for chaining
80
86
  */
81
- finishSpan(params: FinishSpanRequest): Promise<FinishSpanResponse>;
87
+ addAttributes(attributes: {
88
+ [key: string]: string | number | boolean;
89
+ }): this;
82
90
  /**
83
- * Creates the add span event request
84
- * @param params - Parameters to create an AddSpanEventRequest - traceId, spanId, eventName, attr (optional)
85
- * @returns AddSpanEventRequest
91
+ * Add a tag to the trace
92
+ * @param tag Tag to add
93
+ * @returns This trace builder for chaining
86
94
  */
87
- createAddSpanEventRequest({ traceId, spanId, eventName, attr }: {
88
- traceId: string;
89
- spanId: string;
90
- eventName: string;
91
- attr?: {
92
- [key: string]: string;
93
- };
94
- }): AddSpanEventRequest;
95
+ addTag(tag: string): this;
95
96
  /**
96
- * Add an event to a span
97
- * @param params Parameters to add an event to a span
97
+ * Add multiple tags to the trace
98
+ * @param tags Array of tags to add
99
+ * @returns This trace builder for chaining
98
100
  */
99
- addSpanEvent(params: AddSpanEventRequest): Promise<AddSpanEventResponse>;
101
+ addTags(tags: string[]): this;
100
102
  /**
101
- * Creates the add span error request
102
- * @param params - params used to generate the error request ( traceid, span id, error message, error type, stack trace)
103
- * @returns AddSpanErrorRequest
103
+ * Add an event to the trace
104
+ * @param eventName Name of the event
105
+ * @param details Optional details (can be a JSON string or object that will be stringified)
106
+ * @param timestamp Optional timestamp (defaults to current time)
107
+ * @returns This trace builder for chaining
104
108
  */
105
- createAddSpanErrorRequest({ traceId, spanId, errorMessage, errorType, stackTrace }: {
106
- traceId: string;
107
- spanId: string;
108
- errorMessage: string;
109
- errorType?: string;
110
- stackTrace?: string;
111
- }): AddSpanErrorRequest;
109
+ addEvent(eventName: string, details?: string | object, timestamp?: Date): this;
112
110
  /**
113
- * Add an error to a span
114
- * @param params Parameters to add an error to a span
111
+ * Set or update the transaction hash hint
112
+ * @param txHash Transaction hash
113
+ * @param chainId Chain ID (e.g., "ethereum", "polygon")
114
+ * @param details Optional details about the transaction
115
+ * @param timestamp Optional timestamp (defaults to current time)
116
+ * @returns This trace builder for chaining
115
117
  */
116
- addSpanError(params: AddSpanErrorRequest): Promise<AddSpanErrorResponse>;
118
+ setTxHash(txHash: string, chainId: string, details?: string, timestamp?: Date): this;
117
119
  /**
118
- * Creates the add span hint request
119
- * @param params - params used to generate the span hint (trace id, parentSpanId, txHash and chainId)
120
- * @returns AddSpanHintRequest
120
+ * Submit the trace without a transaction hash hint (if not already set via setTxHash)
121
+ * @returns Response from the create trace operation
121
122
  */
122
- createAddSpanHintRequest({ traceId, parentSpanId, txHash, chainId }: {
123
- traceId: string;
124
- parentSpanId: string;
125
- txHash?: string;
126
- chainId?: number;
127
- }): AddSpanHintRequest;
123
+ submit(): Promise<CreateTraceResponse>;
128
124
  /**
129
- * Add a hint to a span
130
- * @param params Parameters to add a hint to a span
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
131
130
  */
132
- addSpanHint(params: AddSpanHintRequest): Promise<AddSpanHintResponse>;
131
+ submit(txHash: string, chainId: string, details?: string): Promise<CreateTraceResponse>;
133
132
  }
134
133
 
135
134
  interface Metadata {
@@ -161,8 +160,6 @@ declare class GrpcWebRpc implements Rpc {
161
160
 
162
161
  interface TransactionInfo {
163
162
  traceId: string;
164
- rootSpanId: string;
165
- spanId: string | null;
166
163
  timestamp: string;
167
164
  txHash: string | null;
168
165
  from?: string;
@@ -195,8 +192,7 @@ declare class ParallaxService {
195
192
  * Start a new transaction trace
196
193
  * Called when user initiates a transaction
197
194
  *
198
- * Note: Since createTrace now automatically creates a root span, we don't need
199
- * to call startSpan separately. The rootSpanId from the response is the parent span.
195
+ * Uses the builder pattern to create a trace with events
200
196
  *
201
197
  * @param txData - Transaction data
202
198
  * @param name - Name for the trace (e.g., 'SendingTrace', 'SwappingTrace')
@@ -216,34 +212,48 @@ declare class ParallaxService {
216
212
  * Associate a transaction hash with an existing trace
217
213
  * Called when the transaction hash is available after signing/sending
218
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
+ *
219
218
  * @param txId - Transaction identifier returned from startTransactionTrace
220
219
  * @param txHash - Blockchain transaction hash
221
220
  * @param chainId - Chain ID
221
+ * @deprecated Use submit(txHash, chainId) when creating the trace instead
222
222
  */
223
223
  associateTransactionHash(txId: string, txHash: string, chainId: number): Promise<void>;
224
224
  /**
225
225
  * Add an event to a transaction trace
226
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
+ *
227
230
  * @param txId - Transaction identifier
228
231
  * @param eventName - Event name
229
232
  * @param attributes - Event attributes
233
+ * @deprecated Use the trace builder's addEvent() method before calling submit() instead
230
234
  */
231
235
  addTransactionEvent(txId: string, eventName: string, attributes?: Record<string, any>): Promise<void>;
232
236
  /**
233
237
  * Add an error to a transaction trace
234
- * Creates a proper span error event in Parallax
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().
235
241
  *
236
242
  * @param txId - Transaction identifier
237
243
  * @param error - Error object or message
238
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
239
246
  */
240
247
  addTransactionError(txId: string, error: Error | string, errorType?: string): Promise<void>;
241
248
  /**
242
249
  * Finish a transaction trace
243
- * Called when transaction is confirmed or permanently failed
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.
244
253
  *
245
254
  * @param txId - Transaction identifier
246
255
  * @param options - Finish options (success, error message)
256
+ * @deprecated Traces are automatically completed when submit() is called
247
257
  */
248
258
  finishTransactionTrace(txId: string, options?: FinishOptions): Promise<void>;
249
259
  /**
@@ -270,4 +280,4 @@ declare class ParallaxService {
270
280
  }
271
281
  declare const parallaxService: ParallaxService;
272
282
 
273
- export { GrpcWebRpc, ParallaxClient, ParallaxService, parallaxService };
283
+ export { GrpcWebRpc, ParallaxClient, ParallaxService, ParallaxTrace, parallaxService };