@displaydev/cli 0.20.0 → 0.21.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.
@@ -312,27 +312,33 @@ export var ApiClient = /*#__PURE__*/ function() {
312
312
  "use strict";
313
313
  function ApiClient(config) {
314
314
  _class_call_check(this, ApiClient);
315
- var _config_clientType, _config_version;
315
+ var _config_clientType, _config_version, _config_clientSource;
316
316
  _define_property(this, "baseUrl", void 0);
317
317
  _define_property(this, "apiKey", void 0);
318
318
  _define_property(this, "clientType", void 0);
319
319
  _define_property(this, "version", void 0);
320
+ _define_property(this, "clientSource", void 0);
320
321
  this.baseUrl = config.baseUrl.replace(/\/$/, '');
321
322
  this.apiKey = config.apiKey;
322
323
  this.clientType = (_config_clientType = config.clientType) !== null && _config_clientType !== void 0 ? _config_clientType : 'mcp-stdio';
323
324
  this.version = (_config_version = config.version) !== null && _config_version !== void 0 ? _config_version : '';
325
+ this.clientSource = (_config_clientSource = config.clientSource) !== null && _config_clientSource !== void 0 ? _config_clientSource : '';
324
326
  }
325
327
  _create_class(ApiClient, [
326
328
  {
327
329
  key: "clientHeaders",
328
330
  value: /**
329
331
  * Build the request-side header set. Always carries `X-Client-Type`;
330
- * adds `X-Client-Version` when the client was constructed with one.
332
+ * adds `X-Client-Version` when the client was constructed with one;
333
+ * adds `X-Client-Source` when a distribution-channel attribution was
334
+ * configured.
331
335
  */ function clientHeaders(extra) {
332
336
  var headers = _object_spread({
333
337
  'X-Client-Type': this.clientType
334
338
  }, this.version ? {
335
339
  'X-Client-Version': this.version
340
+ } : {}, this.clientSource ? {
341
+ 'X-Client-Source': this.clientSource
336
342
  } : {}, extra);
337
343
  return headers;
338
344
  }
package/dist/main.js CHANGED
@@ -273,12 +273,50 @@ function resolvePublicApiUrl() {
273
273
  var _process_env_DISPLAYDEV_API_URL;
274
274
  return (_process_env_DISPLAYDEV_API_URL = process.env.DISPLAYDEV_API_URL) !== null && _process_env_DISPLAYDEV_API_URL !== void 0 ? _process_env_DISPLAYDEV_API_URL : DEFAULT_API_URL;
275
275
  }
276
+ /**
277
+ * Distribution-channel attribution stash. `--client-source <name>` is
278
+ * registered on `program` and on every subcommand in the tree (see
279
+ * `addClientSourceOptionRecursive` at the bottom of this file) and a
280
+ * `preAction` hook stashes the parsed value before any action runs.
281
+ * `createClient` and the two unauthenticated `new ApiClient(...)` sites
282
+ * then read the stash via `resolveClientSource()`.
283
+ *
284
+ * Why a global stash instead of threading through every action: there
285
+ * are ~20 direct-HTTP subcommands and a single resolution path; passing
286
+ * the value down through each action's opts type would touch every
287
+ * action handler for a flag that is structurally cross-cutting.
288
+ *
289
+ * The flag is also registered on `mcp` so `dsp mcp --client-source foo`
290
+ * is silently accepted (per spec §1 out-of-scope). The stash gets
291
+ * populated, but the mcp action builds its `ApiClient` without reading
292
+ * the stash, so the value never reaches the spawned MCP server's
293
+ * outgoing requests.
294
+ *
295
+ * Precedence: flag > `DISPLAYDEV_CLIENT_SOURCE` env > omitted. An
296
+ * explicitly empty flag (`--client-source=`) is treated as the user
297
+ * suppressing attribution: the env fallback is skipped and the header
298
+ * is omitted. The header is analytics-only; it does not affect audit /
299
+ * share-notification source normalization (which keys off
300
+ * `X-Client-Type`).
301
+ */ var clientSourceFromFlag;
302
+ var clientSourceFlagPassed = false;
303
+ function resolveClientSource() {
304
+ if (clientSourceFlagPassed) {
305
+ return clientSourceFromFlag;
306
+ }
307
+ var env = process.env.DISPLAYDEV_CLIENT_SOURCE;
308
+ if (typeof env === 'string' && env.length > 0) {
309
+ return env;
310
+ }
311
+ return undefined;
312
+ }
276
313
  function createClient(auth) {
277
314
  return new ApiClient({
278
315
  baseUrl: auth.apiUrl,
279
316
  apiKey: auth.apiKey,
280
317
  clientType: 'cli',
281
- version: version
318
+ version: version,
319
+ clientSource: resolveClientSource()
282
320
  });
283
321
  }
284
322
  var program = new Command().name('dsp').description('display.dev CLI — publish artifacts behind company auth').version(version);
@@ -426,7 +464,8 @@ program.command('publish <path>').description('Publish an HTML or Markdown file.
426
464
  baseUrl: resolvePublicApiUrl(),
427
465
  apiKey: '',
428
466
  clientType: 'cli',
429
- version: version
467
+ version: version,
468
+ clientSource: resolveClientSource()
430
469
  });
431
470
  _state.label = 10;
432
471
  case 10:
@@ -1094,7 +1133,8 @@ program.command('login').description('Authenticate with display.dev').option('--
1094
1133
  baseUrl: apiUrl,
1095
1134
  apiKey: '',
1096
1135
  clientType: 'cli',
1097
- version: version
1136
+ version: version,
1137
+ clientSource: resolveClientSource()
1098
1138
  });
1099
1139
  if (!(opts.apiKey !== undefined)) return [
1100
1140
  3,
@@ -2314,4 +2354,61 @@ program.command('mcp').description('Start MCP server over stdin/stdout').action(
2314
2354
  });
2315
2355
  })();
2316
2356
  });
2357
+ /**
2358
+ * Register `--client-source <name>` on `program` AND every command in
2359
+ * the tree (top-level + nested under `comment` / `thread` + `mcp`).
2360
+ * This makes the flag parseable at any level — `dsp --client-source
2361
+ * foo publish ...`, `dsp publish --client-source foo ...`,
2362
+ * `dsp comment --client-source foo add ...`, etc. — so the skill
2363
+ * helpers (per spec §4.2 / §4.3 / §4.4) which exec `dsp publish
2364
+ * --client-source … "$@"` work without per-command duplication of
2365
+ * the action signature.
2366
+ *
2367
+ * `mcp` is included so the flag is silently accepted there too. The
2368
+ * mcp action does not call `resolveClientSource()`, so the stashed
2369
+ * value never reaches the spawned MCP server's `ApiClient` (spec §1
2370
+ * out-of-scope).
2371
+ */ function addClientSourceOptionRecursive(cmd) {
2372
+ cmd.option('--client-source <name>', 'Distribution channel attribution (sent as X-Client-Source header for funnel analytics)');
2373
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
2374
+ try {
2375
+ for(var _iterator = cmd.commands[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
2376
+ var child = _step.value;
2377
+ addClientSourceOptionRecursive(child);
2378
+ }
2379
+ } catch (err) {
2380
+ _didIteratorError = true;
2381
+ _iteratorError = err;
2382
+ } finally{
2383
+ try {
2384
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
2385
+ _iterator.return();
2386
+ }
2387
+ } finally{
2388
+ if (_didIteratorError) {
2389
+ throw _iteratorError;
2390
+ }
2391
+ }
2392
+ }
2393
+ }
2394
+ addClientSourceOptionRecursive(program);
2395
+ /**
2396
+ * Resolve the parsed flag value before each action. Program-level
2397
+ * `preAction` hooks fire ahead of every subcommand action, so a single
2398
+ * registration is enough — the callback walks the active command up
2399
+ * through its parents and stops at the first command whose `opts()`
2400
+ * has a string-typed `clientSource` (distinguishing "not passed"
2401
+ * `undefined` from "explicit blank" `''`).
2402
+ */ program.hook('preAction', function(_thisCommand, actionCommand) {
2403
+ var cursor = actionCommand;
2404
+ while(cursor){
2405
+ var val = cursor.opts().clientSource;
2406
+ if (typeof val === 'string') {
2407
+ clientSourceFlagPassed = true;
2408
+ clientSourceFromFlag = val.length > 0 ? val : undefined;
2409
+ return;
2410
+ }
2411
+ cursor = cursor.parent;
2412
+ }
2413
+ });
2317
2414
  program.parse();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@displaydev/cli",
3
- "version": "0.20.0",
3
+ "version": "0.21.0",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "dsp": "dist/main.js"