@fonderie/client 0.19.0 → 0.20.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.cjs CHANGED
@@ -90,10 +90,14 @@ var FonderieApiError = class extends Error {
90
90
  details;
91
91
  requestId;
92
92
  };
93
- function newRequestId() {
93
+ function randHex(bytes) {
94
94
  const c = globalThis.crypto;
95
- if (c?.randomUUID) return c.randomUUID();
96
- return `r-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 10)}`;
95
+ const arr = new Uint8Array(bytes);
96
+ if (c?.getRandomValues) c.getRandomValues(arr);
97
+ else for (let i = 0; i < bytes; i++) arr[i] = Math.floor(Math.random() * 256);
98
+ let out = "";
99
+ for (const b of arr) out += b.toString(16).padStart(2, "0");
100
+ return out;
97
101
  }
98
102
  var HttpClient = class {
99
103
  constructor(baseUrl, deps = {}) {
@@ -142,9 +146,11 @@ var HttpClient = class {
142
146
  return data;
143
147
  }
144
148
  async exec(opts, retried = false) {
145
- const requestId = newRequestId();
149
+ const traceId = randHex(16);
150
+ const requestId = traceId;
146
151
  const headers = {
147
152
  "Content-Type": "application/json",
153
+ traceparent: `00-${traceId}-${randHex(8)}-01`,
148
154
  "X-Request-ID": requestId
149
155
  };
150
156
  if (opts.token) headers["Authorization"] = `Bearer ${opts.token}`;