@miradorlabs/parallax-web 1.0.4 → 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/README.md +300 -134
- package/dist/index.d.ts +206 -77
- package/dist/index.esm.js +770 -2828
- package/dist/index.esm.js.map +1 -1
- package/dist/index.umd.js +772 -2827
- package/dist/index.umd.js.map +1 -1
- package/example/README.md +257 -0
- package/example/app.js +411 -0
- package/example/index.html +469 -0
- package/example/package-lock.json +1877 -0
- package/example/package.json +33 -0
- package/example/proxy-server.js +86 -0
- package/example/rollup.config.js +16 -0
- package/index.ts +3 -10
- package/package.json +3 -2
- package/src/parallax/ParallaxService.ts +296 -0
- package/src/parallax/index.ts +168 -155
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { CreateTraceRequest, CreateTraceResponse
|
|
2
|
-
export {
|
|
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
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
*
|
|
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
|
|
49
59
|
*/
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
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);
|
|
59
75
|
/**
|
|
60
|
-
*
|
|
61
|
-
* @param
|
|
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
|
|
62
80
|
*/
|
|
63
|
-
|
|
81
|
+
addAttribute(key: string, value: string | number | boolean): this;
|
|
64
82
|
/**
|
|
65
|
-
*
|
|
66
|
-
* @param
|
|
67
|
-
* @returns
|
|
83
|
+
* Add multiple attributes to the trace
|
|
84
|
+
* @param attributes Object containing key-value pairs
|
|
85
|
+
* @returns This trace builder for chaining
|
|
68
86
|
*/
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
status?: {
|
|
73
|
-
success: boolean;
|
|
74
|
-
errorMessage: string;
|
|
75
|
-
};
|
|
76
|
-
}): FinishSpanRequest;
|
|
87
|
+
addAttributes(attributes: {
|
|
88
|
+
[key: string]: string | number | boolean;
|
|
89
|
+
}): this;
|
|
77
90
|
/**
|
|
78
|
-
*
|
|
79
|
-
* @param
|
|
91
|
+
* Add a tag to the trace
|
|
92
|
+
* @param tag Tag to add
|
|
93
|
+
* @returns This trace builder for chaining
|
|
80
94
|
*/
|
|
81
|
-
|
|
95
|
+
addTag(tag: string): this;
|
|
82
96
|
/**
|
|
83
|
-
*
|
|
84
|
-
* @param
|
|
85
|
-
* @returns
|
|
97
|
+
* Add multiple tags to the trace
|
|
98
|
+
* @param tags Array of tags to add
|
|
99
|
+
* @returns This trace builder for chaining
|
|
86
100
|
*/
|
|
87
|
-
|
|
88
|
-
traceId: string;
|
|
89
|
-
spanId: string;
|
|
90
|
-
eventName: string;
|
|
91
|
-
attr?: {
|
|
92
|
-
[key: string]: string;
|
|
93
|
-
};
|
|
94
|
-
}): AddSpanEventRequest;
|
|
95
|
-
/**
|
|
96
|
-
* Add an event to a span
|
|
97
|
-
* @param params Parameters to add an event to a span
|
|
98
|
-
*/
|
|
99
|
-
addSpanEvent(params: AddSpanEventRequest): Promise<AddSpanEventResponse>;
|
|
101
|
+
addTags(tags: string[]): this;
|
|
100
102
|
/**
|
|
101
|
-
*
|
|
102
|
-
* @param
|
|
103
|
-
* @
|
|
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
|
-
|
|
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
|
-
*
|
|
114
|
-
* @param
|
|
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
|
-
|
|
118
|
+
setTxHash(txHash: string, chainId: string, details?: string, timestamp?: Date): this;
|
|
117
119
|
/**
|
|
118
|
-
*
|
|
119
|
-
* @
|
|
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
|
-
|
|
123
|
-
traceId: string;
|
|
124
|
-
parentSpanId: string;
|
|
125
|
-
txHash?: string;
|
|
126
|
-
chainId?: number;
|
|
127
|
-
}): AddSpanHintRequest;
|
|
123
|
+
submit(): Promise<CreateTraceResponse>;
|
|
128
124
|
/**
|
|
129
|
-
*
|
|
130
|
-
* @param
|
|
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
|
-
|
|
131
|
+
submit(txHash: string, chainId: string, details?: string): Promise<CreateTraceResponse>;
|
|
133
132
|
}
|
|
134
133
|
|
|
135
134
|
interface Metadata {
|
|
@@ -151,4 +150,134 @@ declare class GrpcWebRpc implements Rpc {
|
|
|
151
150
|
bidirectionalStreamingRequest(): Observable<Uint8Array>;
|
|
152
151
|
}
|
|
153
152
|
|
|
154
|
-
|
|
153
|
+
/**
|
|
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.
|
|
159
|
+
*/
|
|
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 {
|
|
182
|
+
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
|
+
/**
|
|
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
|
|
246
|
+
*/
|
|
247
|
+
addTransactionError(txId: string, error: Error | string, errorType?: string): Promise<void>;
|
|
248
|
+
/**
|
|
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
|
|
257
|
+
*/
|
|
258
|
+
finishTransactionTrace(txId: string, options?: FinishOptions): Promise<void>;
|
|
259
|
+
/**
|
|
260
|
+
* Get info about an active transaction
|
|
261
|
+
*
|
|
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
|
|
268
|
+
*
|
|
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
|
|
278
|
+
*/
|
|
279
|
+
getClient(apiKey?: string, gatewayUrl?: string): ParallaxClient;
|
|
280
|
+
}
|
|
281
|
+
declare const parallaxService: ParallaxService;
|
|
282
|
+
|
|
283
|
+
export { GrpcWebRpc, ParallaxClient, ParallaxService, ParallaxTrace, parallaxService };
|