@edel-finance/sdk 0.1.4-alpha → 0.1.5-alpha
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 +6 -0
- package/dist/index.js +27 -3
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -167,3 +167,9 @@ export declare class EdelRealtimeClient {
|
|
|
167
167
|
private startHeartbeat;
|
|
168
168
|
private stopHeartbeat;
|
|
169
169
|
}
|
|
170
|
+
/**
|
|
171
|
+
* Generate an RFC 4122 v4 UUID safely across secure HTTPS contexts,
|
|
172
|
+
* non-HTTPS HTTP origins (such as LAN/Tailscale previews), and embedded WebViews
|
|
173
|
+
* where `crypto.randomUUID` may be undefined.
|
|
174
|
+
*/
|
|
175
|
+
export declare function generateUuidV4(): string;
|
package/dist/index.js
CHANGED
|
@@ -81,7 +81,7 @@ export class EdelClient {
|
|
|
81
81
|
serializedBody = JSON.stringify(options.body);
|
|
82
82
|
}
|
|
83
83
|
if (MUTATING_METHODS.has(method)) {
|
|
84
|
-
headers["Idempotency-Key"] = options.idempotencyKey ??
|
|
84
|
+
headers["Idempotency-Key"] = options.idempotencyKey ?? generateUuidV4();
|
|
85
85
|
}
|
|
86
86
|
let lastError;
|
|
87
87
|
for (let attempt = 0; attempt <= this.maxRetries; attempt++) {
|
|
@@ -345,7 +345,7 @@ export class EdelRealtimeClient {
|
|
|
345
345
|
this.ws.send(JSON.stringify({
|
|
346
346
|
type: "unsubscribe",
|
|
347
347
|
version: "realtime-contract/v1",
|
|
348
|
-
request_id:
|
|
348
|
+
request_id: generateUuidV4(),
|
|
349
349
|
channel: sub.channel,
|
|
350
350
|
market_id: sub.marketId,
|
|
351
351
|
account_id: sub.accountId,
|
|
@@ -431,7 +431,7 @@ export class EdelRealtimeClient {
|
|
|
431
431
|
this.ws.send(JSON.stringify({
|
|
432
432
|
type: "subscribe",
|
|
433
433
|
version: "realtime-contract/v1",
|
|
434
|
-
request_id:
|
|
434
|
+
request_id: generateUuidV4(),
|
|
435
435
|
channel: sub.channel,
|
|
436
436
|
market_id: sub.marketId,
|
|
437
437
|
account_id: sub.accountId,
|
|
@@ -476,3 +476,27 @@ function safeJsonParse(raw) {
|
|
|
476
476
|
return raw;
|
|
477
477
|
}
|
|
478
478
|
}
|
|
479
|
+
/**
|
|
480
|
+
* Generate an RFC 4122 v4 UUID safely across secure HTTPS contexts,
|
|
481
|
+
* non-HTTPS HTTP origins (such as LAN/Tailscale previews), and embedded WebViews
|
|
482
|
+
* where `crypto.randomUUID` may be undefined.
|
|
483
|
+
*/
|
|
484
|
+
export function generateUuidV4() {
|
|
485
|
+
const cryptoObj = globalThis.crypto;
|
|
486
|
+
if (typeof cryptoObj?.randomUUID === "function") {
|
|
487
|
+
return cryptoObj.randomUUID();
|
|
488
|
+
}
|
|
489
|
+
if (typeof cryptoObj?.getRandomValues === "function") {
|
|
490
|
+
const bytes = new Uint8Array(16);
|
|
491
|
+
cryptoObj.getRandomValues(bytes);
|
|
492
|
+
bytes[6] = ((bytes[6] ?? 0) & 0x0f) | 0x40;
|
|
493
|
+
bytes[8] = ((bytes[8] ?? 0) & 0x3f) | 0x80;
|
|
494
|
+
const hex = Array.from(bytes, (b) => b.toString(16).padStart(2, "0")).join("");
|
|
495
|
+
return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20, 32)}`;
|
|
496
|
+
}
|
|
497
|
+
const ts = Date.now().toString(16).padStart(12, "0");
|
|
498
|
+
const randHex = () => Math.floor(Math.random() * 0x10000)
|
|
499
|
+
.toString(16)
|
|
500
|
+
.padStart(4, "0");
|
|
501
|
+
return `${ts.slice(0, 8)}-${ts.slice(8, 12)}-4${randHex().slice(1)}-${(8 + Math.floor(Math.random() * 4)).toString(16)}${randHex().slice(1)}-${randHex()}${randHex()}${randHex()}`;
|
|
502
|
+
}
|