@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.js CHANGED
@@ -52,10 +52,14 @@ var FonderieApiError = class extends Error {
52
52
  details;
53
53
  requestId;
54
54
  };
55
- function newRequestId() {
55
+ function randHex(bytes) {
56
56
  const c = globalThis.crypto;
57
- if (c?.randomUUID) return c.randomUUID();
58
- return `r-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 10)}`;
57
+ const arr = new Uint8Array(bytes);
58
+ if (c?.getRandomValues) c.getRandomValues(arr);
59
+ else for (let i = 0; i < bytes; i++) arr[i] = Math.floor(Math.random() * 256);
60
+ let out = "";
61
+ for (const b of arr) out += b.toString(16).padStart(2, "0");
62
+ return out;
59
63
  }
60
64
  var HttpClient = class {
61
65
  constructor(baseUrl, deps = {}) {
@@ -104,9 +108,11 @@ var HttpClient = class {
104
108
  return data;
105
109
  }
106
110
  async exec(opts, retried = false) {
107
- const requestId = newRequestId();
111
+ const traceId = randHex(16);
112
+ const requestId = traceId;
108
113
  const headers = {
109
114
  "Content-Type": "application/json",
115
+ traceparent: `00-${traceId}-${randHex(8)}-01`,
110
116
  "X-Request-ID": requestId
111
117
  };
112
118
  if (opts.token) headers["Authorization"] = `Bearer ${opts.token}`;