@getdial/cli 0.33.2 → 0.33.4

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/lib/api.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import { request, fetch as undiciFetch, FormData as UndiciFormData, setGlobalDispatcher, EnvHttpProxyAgent, } from "undici";
2
2
  import { logger } from "./log.js";
3
3
  import { VERSION } from "./version.js";
4
+ import { refParamsHeader } from "./ref-params.js";
4
5
  // Route this package's undici requests through HTTP(S)_PROXY when one is set.
5
6
  // The `undici` npm package keeps its OWN global dispatcher, which — unlike
6
7
  // Node's built-in fetch (wired by NODE_USE_ENV_PROXY) — ignores the proxy env
@@ -24,6 +25,15 @@ const USER_AGENT = `@getdial/cli/${VERSION}`;
24
25
  export function baseUrl() {
25
26
  return process.env.DIAL_API_URL ?? DEFAULT_BASE;
26
27
  }
28
+ // Attach the attribution ref params (base64 of the install-time ref-params.txt)
29
+ // so the server can tie this machine's requests to how the user originally
30
+ // arrived. No-op when the user never went through an attributed install.
31
+ export function applyRefParamsHeader(headers) {
32
+ const ref = refParamsHeader();
33
+ if (ref)
34
+ headers["x-dial-ref-params"] = ref;
35
+ return headers;
36
+ }
27
37
  export async function apiPost(path, body, apiKey, extraHeaders) {
28
38
  return apiRequest("POST", path, body, apiKey, extraHeaders);
29
39
  }
@@ -57,11 +67,11 @@ function toResult(statusCode, text) {
57
67
  }
58
68
  async function apiRequest(method, path, body, apiKey, extraHeaders) {
59
69
  const url = `${baseUrl()}${path}`;
60
- const headers = {
70
+ const headers = applyRefParamsHeader({
61
71
  "content-type": "application/json",
62
72
  "user-agent": USER_AGENT,
63
73
  ...(extraHeaders ?? {}),
64
- };
74
+ });
65
75
  if (apiKey)
66
76
  headers.authorization = `Bearer ${apiKey}`;
67
77
  try {
@@ -79,7 +89,7 @@ async function apiRequest(method, path, body, apiKey, extraHeaders) {
79
89
  /** POST a multipart/form-data body (file uploads). fetch sets the boundary header itself. */
80
90
  export async function apiPostMultipart(path, form, apiKey) {
81
91
  const url = `${baseUrl()}${path}`;
82
- const headers = {};
92
+ const headers = applyRefParamsHeader({ "user-agent": USER_AGENT });
83
93
  if (apiKey)
84
94
  headers.authorization = `Bearer ${apiKey}`;
85
95
  try {
@@ -0,0 +1,37 @@
1
+ import { readFileSync } from "node:fs";
2
+ import { join } from "node:path";
3
+ import { paths } from "./paths.js";
4
+ import { logger } from "./log.js";
5
+ // Reads the attribution ref params the install script persisted to
6
+ // ${dataDir}/ref-params.txt and returns them base64-encoded for the
7
+ // X-Dial-Ref-Params header. The CLI forwards the file verbatim — no parsing, no
8
+ // allowlist here; the server decodes + validates. Cached per process (the file is
9
+ // write-once and stable for the CLI's lifetime).
10
+ let cache;
11
+ function compute() {
12
+ const file = join(paths().dataDir, "ref-params.txt");
13
+ try {
14
+ const text = readFileSync(file, "utf8");
15
+ if (!text.trim())
16
+ return null;
17
+ return Buffer.from(text, "utf8").toString("base64");
18
+ }
19
+ catch (err) {
20
+ // No file is the normal case (the user never went through an attributed
21
+ // install) — not an error worth logging. Anything else is unexpected.
22
+ if (err?.code === "ENOENT")
23
+ return null;
24
+ logger.warn({ err }, "failed to read ref-params.txt");
25
+ return null;
26
+ }
27
+ }
28
+ /** Base64 of ref-params.txt for the X-Dial-Ref-Params header, or null if absent. */
29
+ export function refParamsHeader() {
30
+ if (!cache)
31
+ cache = { value: compute() };
32
+ return cache.value;
33
+ }
34
+ /** Test-only: clear the per-process cache. */
35
+ export function resetRefParamsCache() {
36
+ cache = undefined;
37
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@getdial/cli",
3
- "version": "0.33.2",
3
+ "version": "0.33.4",
4
4
  "description": "Dial CLI — install, sign up, and run the local listen service.",
5
5
  "license": "MIT",
6
6
  "repository": {
package/skills.tar.gz CHANGED
Binary file