@miradorlabs/parallax-web 1.0.3 → 1.0.6

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
@@ -7,32 +7,124 @@ declare class ParallaxClient {
7
7
  apiUrl: string;
8
8
  private client;
9
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>;
10
35
  /**
11
36
  * Create a new trace
12
37
  * @param params Parameters to create a new trace
13
38
  * @returns Response from the create trace operation
14
39
  */
15
40
  createTrace(params: CreateTraceRequest): Promise<CreateTraceResponse>;
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>;
16
59
  /**
17
60
  * Start a new span within a trace
18
61
  * @param params Parameters to start a new span
19
62
  */
20
63
  startSpan(params: StartSpanRequest): Promise<StartSpanResponse>;
64
+ /**
65
+ * Create a FinishSpanRequest
66
+ * @param params Parameters to finish a span - traceId, spanId, status (optional) (success, errorMessage)
67
+ * @returns FinishSpanRequest
68
+ */
69
+ createFinishSpanRequest({ traceId, spanId, status }: {
70
+ traceId: string;
71
+ spanId: string;
72
+ status?: {
73
+ success: boolean;
74
+ errorMessage: string;
75
+ };
76
+ }): FinishSpanRequest;
21
77
  /**
22
78
  * Finish a span within a trace
23
79
  * @param params Parameters to finish a span
24
80
  */
25
81
  finishSpan(params: FinishSpanRequest): Promise<FinishSpanResponse>;
82
+ /**
83
+ * Creates the add span event request
84
+ * @param params - Parameters to create an AddSpanEventRequest - traceId, spanId, eventName, attr (optional)
85
+ * @returns AddSpanEventRequest
86
+ */
87
+ createAddSpanEventRequest({ traceId, spanId, eventName, attr }: {
88
+ traceId: string;
89
+ spanId: string;
90
+ eventName: string;
91
+ attr?: {
92
+ [key: string]: string;
93
+ };
94
+ }): AddSpanEventRequest;
26
95
  /**
27
96
  * Add an event to a span
28
97
  * @param params Parameters to add an event to a span
29
98
  */
30
99
  addSpanEvent(params: AddSpanEventRequest): Promise<AddSpanEventResponse>;
100
+ /**
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
104
+ */
105
+ createAddSpanErrorRequest({ traceId, spanId, errorMessage, errorType, stackTrace }: {
106
+ traceId: string;
107
+ spanId: string;
108
+ errorMessage: string;
109
+ errorType?: string;
110
+ stackTrace?: string;
111
+ }): AddSpanErrorRequest;
31
112
  /**
32
113
  * Add an error to a span
33
114
  * @param params Parameters to add an error to a span
34
115
  */
35
116
  addSpanError(params: AddSpanErrorRequest): Promise<AddSpanErrorResponse>;
117
+ /**
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
121
+ */
122
+ createAddSpanHintRequest({ traceId, parentSpanId, txHash, chainId }: {
123
+ traceId: string;
124
+ parentSpanId: string;
125
+ txHash?: string;
126
+ chainId?: number;
127
+ }): AddSpanHintRequest;
36
128
  /**
37
129
  * Add a hint to a span
38
130
  * @param params Parameters to add a hint to a span
@@ -59,4 +151,123 @@ declare class GrpcWebRpc implements Rpc {
59
151
  bidirectionalStreamingRequest(): Observable<Uint8Array>;
60
152
  }
61
153
 
62
- export { GrpcWebRpc, ParallaxClient };
154
+ /**
155
+ * Parallax Service - Transaction Tracing for Web Applications
156
+ * Creates individual traces for each transaction and tracks them through their lifecycle
157
+ *
158
+ * This service provides a simplified interface for tracking transactions with automatic
159
+ * client metadata collection and lifecycle management.
160
+ */
161
+
162
+ interface TransactionInfo {
163
+ traceId: string;
164
+ rootSpanId: string;
165
+ spanId: string | null;
166
+ timestamp: string;
167
+ txHash: string | null;
168
+ from?: string;
169
+ to?: string;
170
+ network?: string;
171
+ }
172
+ interface TransactionData {
173
+ from: string;
174
+ to: string;
175
+ value: string;
176
+ network?: string;
177
+ walletAddress?: string;
178
+ additionalData?: Record<string, any>;
179
+ }
180
+ interface FinishOptions {
181
+ success: boolean;
182
+ error?: string;
183
+ }
184
+ declare class ParallaxService {
185
+ private client;
186
+ private activeTransactions;
187
+ constructor();
188
+ /**
189
+ * Initialize the Parallax client (lazy initialization)
190
+ * @param apiKey - Optional API key for authentication
191
+ * @param gatewayUrl - Optional custom gateway URL
192
+ */
193
+ private _ensureClient;
194
+ /**
195
+ * Start a new transaction trace
196
+ * Called when user initiates a transaction
197
+ *
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.
200
+ *
201
+ * @param txData - Transaction data
202
+ * @param name - Name for the trace (e.g., 'SendingTrace', 'SwappingTrace')
203
+ * @param options - Optional configuration (apiKey, gatewayUrl, includeClientMeta)
204
+ * @returns Promise with traceId, rootSpanId, and txId
205
+ */
206
+ startTransactionTrace(txData: TransactionData, name?: string, options?: {
207
+ apiKey?: string;
208
+ gatewayUrl?: string;
209
+ includeClientMeta?: boolean;
210
+ }): Promise<{
211
+ traceId: string;
212
+ rootSpanId: string;
213
+ txId: string;
214
+ }>;
215
+ /**
216
+ * Associate a transaction hash with an existing trace
217
+ * Called when the transaction hash is available after signing/sending
218
+ *
219
+ * @param txId - Transaction identifier returned from startTransactionTrace
220
+ * @param txHash - Blockchain transaction hash
221
+ * @param chainId - Chain ID
222
+ */
223
+ associateTransactionHash(txId: string, txHash: string, chainId: number): Promise<void>;
224
+ /**
225
+ * Add an event to a transaction trace
226
+ *
227
+ * @param txId - Transaction identifier
228
+ * @param eventName - Event name
229
+ * @param attributes - Event attributes
230
+ */
231
+ addTransactionEvent(txId: string, eventName: string, attributes?: Record<string, any>): Promise<void>;
232
+ /**
233
+ * Add an error to a transaction trace
234
+ * Creates a proper span error event in Parallax
235
+ *
236
+ * @param txId - Transaction identifier
237
+ * @param error - Error object or message
238
+ * @param errorType - Type/category of error (e.g., 'TransactionError', 'NetworkError', 'UserRejection')
239
+ */
240
+ addTransactionError(txId: string, error: Error | string, errorType?: string): Promise<void>;
241
+ /**
242
+ * Finish a transaction trace
243
+ * Called when transaction is confirmed or permanently failed
244
+ *
245
+ * @param txId - Transaction identifier
246
+ * @param options - Finish options (success, error message)
247
+ */
248
+ finishTransactionTrace(txId: string, options?: FinishOptions): Promise<void>;
249
+ /**
250
+ * Get info about an active transaction
251
+ *
252
+ * @param txId - Transaction identifier
253
+ * @returns Transaction info or null if not found
254
+ */
255
+ getTransactionInfo(txId: string): TransactionInfo | null;
256
+ /**
257
+ * Get all active transactions
258
+ *
259
+ * @returns Array of active transaction info
260
+ */
261
+ getAllActiveTransactions(): Array<TransactionInfo & {
262
+ txId: string;
263
+ }>;
264
+ /**
265
+ * Get the ParallaxClient instance for advanced usage
266
+ * @param apiKey - Optional API key
267
+ * @param gatewayUrl - Optional gateway URL
268
+ */
269
+ getClient(apiKey?: string, gatewayUrl?: string): ParallaxClient;
270
+ }
271
+ declare const parallaxService: ParallaxService;
272
+
273
+ export { GrpcWebRpc, ParallaxClient, ParallaxService, parallaxService };