@kolatts/pncli 1.26.0 → 2.0.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.
@@ -1,141 +1,14 @@
1
1
  #!/usr/bin/env node
2
+ import {
3
+ ExitCode,
4
+ PncliError,
5
+ debug,
6
+ isDebugEnabled,
7
+ log
8
+ } from "./chunk-HZF6WQPU.js";
2
9
 
3
10
  // src/lib/http.ts
4
- import fs2 from "fs";
5
-
6
- // src/lib/errors.ts
7
- var PncliError = class extends Error {
8
- status;
9
- url;
10
- constructor(message, status = 1, url) {
11
- super(message);
12
- this.name = "PncliError";
13
- this.status = status;
14
- this.url = url;
15
- }
16
- };
17
-
18
- // src/lib/exitCodes.ts
19
- var ExitCode = {
20
- SUCCESS: 0,
21
- GENERAL_ERROR: 1,
22
- USAGE_ERROR: 2,
23
- NETWORK_ERROR: 69,
24
- // EX_UNAVAILABLE from sysexits.h
25
- AUTH_ERROR: 77,
26
- // EX_NOPERM from sysexits.h
27
- CONFIG_ERROR: 78
28
- // EX_CONFIG from sysexits.h
29
- };
30
- function exitCodeFromStatus(httpStatus) {
31
- if (httpStatus === 401 || httpStatus === 403) return ExitCode.AUTH_ERROR;
32
- if (httpStatus === 0) return ExitCode.NETWORK_ERROR;
33
- return ExitCode.GENERAL_ERROR;
34
- }
35
-
36
- // src/lib/output.ts
37
11
  import fs from "fs";
38
- import chalk from "chalk";
39
- var globalOptions = { pretty: false, verbose: false, debug: false };
40
- var globalUser = { email: void 0, userId: void 0 };
41
- var outputFile;
42
- function setGlobalOptions(opts) {
43
- globalOptions = { pretty: opts.pretty, verbose: opts.verbose, debug: opts.debug ?? false };
44
- outputFile = opts.outputFile;
45
- }
46
- function isDebugEnabled() {
47
- return globalOptions.debug;
48
- }
49
- function setGlobalUser(user) {
50
- globalUser = user;
51
- }
52
- function buildMeta(service, action, startTime, overrides) {
53
- return {
54
- service,
55
- action,
56
- timestamp: (/* @__PURE__ */ new Date()).toISOString(),
57
- duration_ms: Date.now() - startTime,
58
- user: globalUser.email ?? globalUser.userId ? globalUser : void 0,
59
- overrides: overrides && overrides.length > 0 ? overrides : void 0
60
- };
61
- }
62
- function writeToFile(filePath, content) {
63
- try {
64
- fs.writeFileSync(filePath, content, "utf8");
65
- } catch (writeErr) {
66
- process.stderr.write(
67
- `Warning: could not write to output file "${filePath}": ${writeErr.message}
68
- `
69
- );
70
- process.exitCode = ExitCode.GENERAL_ERROR;
71
- }
72
- }
73
- function success(data, service, action, startTime, overrides) {
74
- const envelope = {
75
- ok: true,
76
- data,
77
- meta: buildMeta(service, action, startTime, overrides)
78
- };
79
- const out = (globalOptions.pretty ? JSON.stringify(envelope, null, 2) : JSON.stringify(envelope)) + "\n";
80
- if (outputFile) {
81
- writeToFile(outputFile, out);
82
- } else {
83
- process.stdout.write(out);
84
- }
85
- }
86
- function fail(err, service, action, startTime) {
87
- const errorDetail = {
88
- status: err instanceof PncliError ? err.status : 1,
89
- message: err instanceof Error ? err.message : String(err),
90
- url: err instanceof PncliError ? err.url ?? null : null
91
- };
92
- const envelope = {
93
- ok: false,
94
- error: errorDetail,
95
- meta: buildMeta(service, action, startTime)
96
- };
97
- const msg = globalOptions.pretty ? chalk.red("\u2717 Error: ") + errorDetail.message : null;
98
- if (msg) process.stderr.write(msg + "\n");
99
- const output = (globalOptions.pretty ? JSON.stringify(envelope, null, 2) : JSON.stringify(envelope)) + "\n";
100
- const exitCode = err instanceof PncliError ? exitCodeFromStatus(err.status) : ExitCode.GENERAL_ERROR;
101
- if (outputFile) {
102
- writeToFile(outputFile, output);
103
- } else {
104
- try {
105
- fs.writeSync(process.stdout.fd, output);
106
- } catch (writeErr) {
107
- if (writeErr.code !== "EPIPE") throw writeErr;
108
- }
109
- }
110
- process.exitCode = exitCode;
111
- throw new PncliError(errorDetail.message, errorDetail.status);
112
- }
113
- function writeRawOutput(content) {
114
- if (outputFile) {
115
- writeToFile(outputFile, content);
116
- } else {
117
- process.stdout.write(content);
118
- }
119
- }
120
- function log(message) {
121
- if (globalOptions.verbose) {
122
- process.stderr.write(
123
- (globalOptions.pretty ? chalk.gray("\u25B8 ") : "") + message + "\n"
124
- );
125
- }
126
- }
127
- function debug(message) {
128
- if (globalOptions.debug) {
129
- process.stderr.write(
130
- (globalOptions.pretty ? chalk.cyan("\u2B21 ") : "") + message + "\n"
131
- );
132
- }
133
- }
134
- function warn(message) {
135
- process.stderr.write(
136
- (globalOptions.pretty ? chalk.yellow("\u26A0 ") : "") + message + "\n"
137
- );
138
- }
139
12
 
140
13
  // src/lib/adoFetch.ts
141
14
  async function buildAdoFetcher(config) {
@@ -237,7 +110,7 @@ function getApiKeyClientId(apiKey) {
237
110
  }
238
111
 
239
112
  // src/lib/http.ts
240
- var SENSITIVE_HEADERS = /* @__PURE__ */ new Set(["authorization", "api-key"]);
113
+ var SENSITIVE_HEADERS = /* @__PURE__ */ new Set(["authorization", "api-key", "x-figma-token"]);
241
114
  function redactHeaders(headers) {
242
115
  if (!headers) return {};
243
116
  let entries;
@@ -407,7 +280,7 @@ var HttpClient = class {
407
280
  Headers: ${JSON.stringify(safeHeaders, null, 2)}
408
281
  ` + (opts.body ? `Body: ${JSON.stringify(opts.body, null, 2)}
409
282
  ` : "");
410
- fs2.writeSync(process.stderr.fd, msg);
283
+ fs.writeSync(process.stderr.fd, msg);
411
284
  process.exitCode = ExitCode.SUCCESS;
412
285
  throw new PncliError("dry-run", 0);
413
286
  }
@@ -423,7 +296,7 @@ Headers: ${JSON.stringify(safeHeaders, null, 2)}
423
296
  const msg = `DRY RUN: GET ${absoluteUrl}
424
297
  Headers: ${JSON.stringify(safeHeaders, null, 2)}
425
298
  `;
426
- fs2.writeSync(process.stderr.fd, msg);
299
+ fs.writeSync(process.stderr.fd, msg);
427
300
  process.exitCode = ExitCode.SUCCESS;
428
301
  throw new PncliError("dry-run", 0);
429
302
  }
@@ -438,7 +311,7 @@ Headers: ${JSON.stringify(safeHeaders, null, 2)}
438
311
  if (!baseUrl) throw new PncliError("Azure DevOps baseUrl not configured. Run: pncli config init");
439
312
  const url = buildUrl(baseUrl, path);
440
313
  if (this.dryRun) {
441
- fs2.writeSync(process.stderr.fd, `DRY RUN: POST ${url}
314
+ fs.writeSync(process.stderr.fd, `DRY RUN: POST ${url}
442
315
  Body: <binary ${buffer.length} bytes>
443
316
  `);
444
317
  process.exitCode = ExitCode.SUCCESS;
@@ -453,7 +326,7 @@ Body: <binary ${buffer.length} bytes>
453
326
  }
454
327
  async adoBuffer(absoluteUrl, opts = {}) {
455
328
  if (this.dryRun) {
456
- fs2.writeSync(process.stderr.fd, `DRY RUN: GET ${absoluteUrl}
329
+ fs.writeSync(process.stderr.fd, `DRY RUN: GET ${absoluteUrl}
457
330
  `);
458
331
  process.exitCode = ExitCode.SUCCESS;
459
332
  throw new PncliError("dry-run", 0);
@@ -486,7 +359,7 @@ Body: <binary ${buffer.length} bytes>
486
359
  Headers: ${JSON.stringify(safeHeaders, null, 2)}
487
360
  Body: <multipart/form-data>
488
361
  `;
489
- fs2.writeSync(process.stderr.fd, msg);
362
+ fs.writeSync(process.stderr.fd, msg);
490
363
  process.exitCode = ExitCode.SUCCESS;
491
364
  throw new PncliError("dry-run", 0);
492
365
  }
@@ -508,7 +381,7 @@ Body: <multipart/form-data>
508
381
  Headers: ${JSON.stringify(safeHeaders, null, 2)}
509
382
  ` + (opts.body ? `Body: ${JSON.stringify(opts.body, null, 2)}
510
383
  ` : "");
511
- fs2.writeSync(process.stderr.fd, msg);
384
+ fs.writeSync(process.stderr.fd, msg);
512
385
  process.exitCode = ExitCode.SUCCESS;
513
386
  throw new PncliError("dry-run", 0);
514
387
  }
@@ -524,7 +397,7 @@ Headers: ${JSON.stringify(safeHeaders, null, 2)}
524
397
  };
525
398
  if (this.dryRun) {
526
399
  const safeHeaders = { ...headers, Authorization: "[REDACTED]" };
527
- fs2.writeSync(process.stderr.fd, `DRY RUN: ${opts.method ?? "GET"} ${url}
400
+ fs.writeSync(process.stderr.fd, `DRY RUN: ${opts.method ?? "GET"} ${url}
528
401
  Headers: ${JSON.stringify(safeHeaders, null, 2)}
529
402
  `);
530
403
  process.exitCode = ExitCode.SUCCESS;
@@ -558,7 +431,7 @@ Headers: ${JSON.stringify(safeHeaders, null, 2)}
558
431
  Headers: ${JSON.stringify(safeHeaders, null, 2)}
559
432
  Body: ${JSON.stringify({ query, variables }, null, 2)}
560
433
  `;
561
- fs2.writeSync(process.stderr.fd, msg);
434
+ fs.writeSync(process.stderr.fd, msg);
562
435
  process.exitCode = ExitCode.SUCCESS;
563
436
  throw new PncliError("dry-run", 0);
564
437
  }
@@ -607,7 +480,7 @@ Body: ${JSON.stringify({ query, variables }, null, 2)}
607
480
  Headers: ${JSON.stringify(safeHeaders, null, 2)}
608
481
  ` + (opts.body ? `Body: ${JSON.stringify(opts.body, null, 2)}
609
482
  ` : "");
610
- fs2.writeSync(process.stderr.fd, msg);
483
+ fs.writeSync(process.stderr.fd, msg);
611
484
  process.exitCode = ExitCode.SUCCESS;
612
485
  throw new PncliError("dry-run", 0);
613
486
  }
@@ -634,7 +507,7 @@ Headers: ${JSON.stringify(safeHeaders, null, 2)}
634
507
  Headers: ${JSON.stringify(safeHeaders, null, 2)}
635
508
  ` + (opts.body ? `Body: ${JSON.stringify(opts.body, null, 2)}
636
509
  ` : "");
637
- fs2.writeSync(process.stderr.fd, msg);
510
+ fs.writeSync(process.stderr.fd, msg);
638
511
  process.exitCode = ExitCode.SUCCESS;
639
512
  throw new PncliError("dry-run", 0);
640
513
  }
@@ -669,7 +542,7 @@ Headers: ${JSON.stringify(safeHeaders, null, 2)}
669
542
  Headers: ${JSON.stringify(safeHeaders, null, 2)}
670
543
  ` + (opts.body ? `Body: ${JSON.stringify(opts.body, null, 2)}
671
544
  ` : "");
672
- fs2.writeSync(process.stderr.fd, msg);
545
+ fs.writeSync(process.stderr.fd, msg);
673
546
  process.exitCode = ExitCode.SUCCESS;
674
547
  throw new PncliError("dry-run", 0);
675
548
  }
@@ -701,7 +574,7 @@ Headers: ${JSON.stringify(safeHeaders, null, 2)}
701
574
  Headers: ${JSON.stringify(safeHeaders, null, 2)}
702
575
  ` + (opts.body ? `Body: ${JSON.stringify(opts.body, null, 2)}
703
576
  ` : "");
704
- fs2.writeSync(process.stderr.fd, msg);
577
+ fs.writeSync(process.stderr.fd, msg);
705
578
  process.exitCode = ExitCode.SUCCESS;
706
579
  throw new PncliError("dry-run", 0);
707
580
  }
@@ -733,7 +606,7 @@ Headers: ${JSON.stringify(safeHeaders, null, 2)}
733
606
  const msg = `DRY RUN: ${opts.method ?? "GET"} ${url}
734
607
  ` + (opts.body ? `Body: ${JSON.stringify(opts.body, null, 2)}
735
608
  ` : "");
736
- fs2.writeSync(process.stderr.fd, msg);
609
+ fs.writeSync(process.stderr.fd, msg);
737
610
  process.exitCode = ExitCode.SUCCESS;
738
611
  throw new PncliError("dry-run", 0);
739
612
  }
@@ -755,7 +628,7 @@ Headers: ${JSON.stringify(safeHeaders, null, 2)}
755
628
  if (!baseUrl) throw new PncliError("Azure DevOps baseUrl not configured. Run: pncli config init");
756
629
  const url = buildUrl(baseUrl, path, opts.params);
757
630
  if (this.dryRun) {
758
- fs2.writeSync(process.stderr.fd, `DRY RUN: ${opts.method ?? "GET"} ${url}
631
+ fs.writeSync(process.stderr.fd, `DRY RUN: ${opts.method ?? "GET"} ${url}
759
632
  `);
760
633
  process.exitCode = ExitCode.SUCCESS;
761
634
  throw new PncliError("dry-run", 0);
@@ -781,7 +654,7 @@ Headers: ${JSON.stringify(safeHeaders, null, 2)}
781
654
  if (!baseUrl) throw new PncliError("Azure DevOps baseUrl not configured. Run: pncli config init");
782
655
  const url = buildUrl(baseUrl, path, opts.params);
783
656
  if (this.dryRun) {
784
- fs2.writeSync(process.stderr.fd, `DRY RUN: ${opts.method ?? "GET"} ${url}
657
+ fs.writeSync(process.stderr.fd, `DRY RUN: ${opts.method ?? "GET"} ${url}
785
658
  `);
786
659
  process.exitCode = ExitCode.SUCCESS;
787
660
  throw new PncliError("dry-run", 0);
@@ -846,25 +719,6 @@ Headers: ${JSON.stringify(safeHeaders, null, 2)}
846
719
  "Connection": "close"
847
720
  };
848
721
  }
849
- udeployHeaders() {
850
- const { pat, username, password } = this.config.udeploy;
851
- let encoded;
852
- if (username && password) {
853
- encoded = Buffer.from(`${username}:${password}`).toString("base64");
854
- } else if (username && pat) {
855
- encoded = Buffer.from(`${username}:${pat}`).toString("base64");
856
- } else if (pat) {
857
- encoded = Buffer.from(`PasswordIsAuthToken:${JSON.stringify({ token: pat })}`).toString("base64");
858
- } else {
859
- throw new PncliError("UDeploy credentials not configured. Run: pncli config init");
860
- }
861
- return {
862
- "Authorization": `Basic ${encoded}`,
863
- "Content-Type": "application/json",
864
- "Accept": "application/json",
865
- "Connection": "close"
866
- };
867
- }
868
722
  async jenkins(path, opts = {}) {
869
723
  const baseUrl = this.config.jenkins.baseUrl;
870
724
  if (!baseUrl) throw new PncliError("Jenkins baseUrl not configured. Run: pncli config init");
@@ -881,7 +735,7 @@ Headers: ${JSON.stringify(safeHeaders, null, 2)}
881
735
  Headers: ${JSON.stringify(safeHeaders, null, 2)}
882
736
  ` + (opts.body ? `Body: ${JSON.stringify(opts.body, null, 2)}
883
737
  ` : "");
884
- fs2.writeSync(process.stderr.fd, msg);
738
+ fs.writeSync(process.stderr.fd, msg);
885
739
  process.exitCode = ExitCode.SUCCESS;
886
740
  throw new PncliError("dry-run", 0);
887
741
  }
@@ -898,7 +752,7 @@ Headers: ${JSON.stringify(safeHeaders, null, 2)}
898
752
  Headers: ${JSON.stringify(safeHeaders, null, 2)}
899
753
  ` + (opts.body ? `Body: ${JSON.stringify(opts.body, null, 2)}
900
754
  ` : "");
901
- fs2.writeSync(process.stderr.fd, msg);
755
+ fs.writeSync(process.stderr.fd, msg);
902
756
  process.exitCode = ExitCode.SUCCESS;
903
757
  throw new PncliError("dry-run", 0);
904
758
  }
@@ -935,29 +789,7 @@ Headers: ${JSON.stringify(safeHeaders, null, 2)}
935
789
  Headers: ${JSON.stringify(safeHeaders, null, 2)}
936
790
  ` + (opts.body ? `Body: ${typeof opts.body === "string" ? opts.body : JSON.stringify(opts.body, null, 2)}
937
791
  ` : "");
938
- fs2.writeSync(process.stderr.fd, msg);
939
- process.exitCode = ExitCode.SUCCESS;
940
- throw new PncliError("dry-run", 0);
941
- }
942
- return request(url, init, opts.timeoutMs ?? 3e4);
943
- }
944
- async udeploy(path, opts = {}) {
945
- const baseUrl = this.config.udeploy.baseUrl;
946
- if (!baseUrl) throw new PncliError("UDeploy baseUrl not configured. Run: pncli config init");
947
- const url = buildUrl(baseUrl, path, opts.params);
948
- const headers = this.udeployHeaders();
949
- const init = {
950
- method: opts.method ?? "GET",
951
- headers,
952
- body: opts.body !== void 0 ? JSON.stringify(opts.body) : void 0
953
- };
954
- if (this.dryRun) {
955
- const safeHeaders = { ...headers, Authorization: "[REDACTED]" };
956
- const msg = `DRY RUN: ${init.method} ${url}
957
- Headers: ${JSON.stringify(safeHeaders, null, 2)}
958
- ` + (opts.body ? `Body: ${JSON.stringify(opts.body, null, 2)}
959
- ` : "");
960
- fs2.writeSync(process.stderr.fd, msg);
792
+ fs.writeSync(process.stderr.fd, msg);
961
793
  process.exitCode = ExitCode.SUCCESS;
962
794
  throw new PncliError("dry-run", 0);
963
795
  }
@@ -970,7 +802,7 @@ Headers: ${JSON.stringify(safeHeaders, null, 2)}
970
802
  const headers = { ...this.artifactoryHeaders(), Accept: "text/plain", ...opts.headers };
971
803
  if (this.dryRun) {
972
804
  const safeHeaders = { ...headers, Authorization: "[REDACTED]" };
973
- fs2.writeSync(process.stderr.fd, `DRY RUN: ${opts.method ?? "GET"} ${url}
805
+ fs.writeSync(process.stderr.fd, `DRY RUN: ${opts.method ?? "GET"} ${url}
974
806
  Headers: ${JSON.stringify(safeHeaders, null, 2)}
975
807
  `);
976
808
  process.exitCode = ExitCode.SUCCESS;
@@ -1017,7 +849,7 @@ Headers: ${JSON.stringify(safeHeaders, null, 2)}
1017
849
  Headers: ${JSON.stringify(safeHeaders, null, 2)}
1018
850
  ` + (opts.body ? `Body: ${JSON.stringify(opts.body, null, 2)}
1019
851
  ` : "");
1020
- fs2.writeSync(process.stderr.fd, msg);
852
+ fs.writeSync(process.stderr.fd, msg);
1021
853
  process.exitCode = ExitCode.SUCCESS;
1022
854
  throw new PncliError("dry-run", 0);
1023
855
  }
@@ -1048,7 +880,7 @@ Headers: ${JSON.stringify(safeHeaders, null, 2)}
1048
880
  const msg = `DRY RUN: GET ${url}
1049
881
  Headers: ${JSON.stringify(safeHeaders, null, 2)}
1050
882
  `;
1051
- fs2.writeSync(process.stderr.fd, msg);
883
+ fs.writeSync(process.stderr.fd, msg);
1052
884
  process.exitCode = ExitCode.SUCCESS;
1053
885
  throw new PncliError("dry-run", 0);
1054
886
  }
@@ -1074,7 +906,7 @@ Headers: ${JSON.stringify(safeHeaders, null, 2)}
1074
906
  Headers: ${JSON.stringify(safeHeaders, null, 2)}
1075
907
  Body: <multipart/form-data>
1076
908
  `;
1077
- fs2.writeSync(process.stderr.fd, msg);
909
+ fs.writeSync(process.stderr.fd, msg);
1078
910
  process.exitCode = ExitCode.SUCCESS;
1079
911
  throw new PncliError("dry-run", 0);
1080
912
  }
@@ -1158,7 +990,7 @@ Body: <multipart/form-data>
1158
990
  Headers: ${JSON.stringify(safeHeaders, null, 2)}
1159
991
  ` + (opts.body ? `Body: ${JSON.stringify(opts.body, null, 2)}
1160
992
  ` : "");
1161
- fs2.writeSync(process.stderr.fd, msg);
993
+ fs.writeSync(process.stderr.fd, msg);
1162
994
  process.exitCode = ExitCode.SUCCESS;
1163
995
  throw new PncliError("dry-run", 0);
1164
996
  }
@@ -1194,7 +1026,7 @@ Headers: ${JSON.stringify(safeHeaders, null, 2)}
1194
1026
  Headers: ${JSON.stringify(safeHeaders, null, 2)}
1195
1027
  ` + (opts.body ? `Body: ${JSON.stringify(opts.body, null, 2)}
1196
1028
  ` : "");
1197
- fs2.writeSync(process.stderr.fd, msg);
1029
+ fs.writeSync(process.stderr.fd, msg);
1198
1030
  process.exitCode = ExitCode.SUCCESS;
1199
1031
  throw new PncliError("dry-run", 0);
1200
1032
  }
@@ -1227,7 +1059,7 @@ Headers: ${JSON.stringify(safeHeaders, null, 2)}
1227
1059
  Headers: ${JSON.stringify(safeHeaders, null, 2)}
1228
1060
  ` + (opts.body ? `Body: ${JSON.stringify(opts.body, null, 2)}
1229
1061
  ` : "");
1230
- fs2.writeSync(process.stderr.fd, msg);
1062
+ fs.writeSync(process.stderr.fd, msg);
1231
1063
  process.exitCode = ExitCode.SUCCESS;
1232
1064
  throw new PncliError("dry-run", 0);
1233
1065
  }
@@ -1259,7 +1091,7 @@ Headers: ${JSON.stringify(safeHeaders, null, 2)}
1259
1091
  Headers: ${JSON.stringify(safeHeaders, null, 2)}
1260
1092
  ` + (opts.body ? `Body: ${JSON.stringify(opts.body, null, 2)}
1261
1093
  ` : "");
1262
- fs2.writeSync(process.stderr.fd, msg);
1094
+ fs.writeSync(process.stderr.fd, msg);
1263
1095
  process.exitCode = ExitCode.SUCCESS;
1264
1096
  throw new PncliError("dry-run", 0);
1265
1097
  }
@@ -1305,7 +1137,7 @@ Headers: ${JSON.stringify(safeHeaders, null, 2)}
1305
1137
  Headers: ${JSON.stringify(safeHeaders, null, 2)}
1306
1138
  ` + (opts.body ? `Body: ${JSON.stringify(opts.body, null, 2)}
1307
1139
  ` : "");
1308
- fs2.writeSync(process.stderr.fd, msg);
1140
+ fs.writeSync(process.stderr.fd, msg);
1309
1141
  process.exitCode = ExitCode.SUCCESS;
1310
1142
  throw new PncliError("dry-run", 0);
1311
1143
  }
@@ -1337,7 +1169,39 @@ Headers: ${JSON.stringify(safeHeaders, null, 2)}
1337
1169
  Headers: ${JSON.stringify(safeHeaders, null, 2)}
1338
1170
  ` + (opts.body ? `Body: ${JSON.stringify(opts.body, null, 2)}
1339
1171
  ` : "");
1340
- fs2.writeSync(process.stderr.fd, msg);
1172
+ fs.writeSync(process.stderr.fd, msg);
1173
+ process.exitCode = ExitCode.SUCCESS;
1174
+ throw new PncliError("dry-run", 0);
1175
+ }
1176
+ return request(url, init, opts.timeoutMs ?? 3e4);
1177
+ }
1178
+ splitioHeaders() {
1179
+ const { adminApiKey } = this.config.splitio;
1180
+ if (!adminApiKey) throw new PncliError("Split.IO credentials not configured. Run: pncli config init");
1181
+ return {
1182
+ "Authorization": `Bearer ${adminApiKey}`,
1183
+ "Content-Type": "application/json",
1184
+ "Accept": "application/json",
1185
+ "Connection": "close"
1186
+ };
1187
+ }
1188
+ async splitio(path, opts = {}) {
1189
+ const baseUrl = this.config.splitio.baseUrl;
1190
+ if (!baseUrl) throw new PncliError("Split.IO baseUrl not configured. Run: pncli config init");
1191
+ const url = buildUrl(baseUrl, path, opts.params);
1192
+ const headers = this.splitioHeaders();
1193
+ const init = {
1194
+ method: opts.method ?? "GET",
1195
+ headers,
1196
+ body: opts.body !== void 0 ? JSON.stringify(opts.body) : void 0
1197
+ };
1198
+ if (this.dryRun) {
1199
+ const safeHeaders = { ...headers, Authorization: "[REDACTED]" };
1200
+ const msg = `DRY RUN: ${init.method} ${url}
1201
+ Headers: ${JSON.stringify(safeHeaders, null, 2)}
1202
+ ` + (opts.body ? `Body: ${JSON.stringify(opts.body, null, 2)}
1203
+ ` : "");
1204
+ fs.writeSync(process.stderr.fd, msg);
1341
1205
  process.exitCode = ExitCode.SUCCESS;
1342
1206
  throw new PncliError("dry-run", 0);
1343
1207
  }
@@ -1356,7 +1220,7 @@ Headers: ${JSON.stringify(safeHeaders, null, 2)}
1356
1220
  };
1357
1221
  if (this.dryRun) {
1358
1222
  const safeHeaders = { ...headers, Authorization: "[REDACTED]" };
1359
- fs2.writeSync(process.stderr.fd, `DRY RUN: GET ${url}
1223
+ fs.writeSync(process.stderr.fd, `DRY RUN: GET ${url}
1360
1224
  Headers: ${JSON.stringify(safeHeaders, null, 2)}
1361
1225
  `);
1362
1226
  process.exitCode = ExitCode.SUCCESS;
@@ -1382,7 +1246,7 @@ Headers: ${JSON.stringify(safeHeaders, null, 2)}
1382
1246
  const msg = `DRY RUN: ${opts.method ?? "GET"} ${url}
1383
1247
  ` + (opts.body ? `Body: ${JSON.stringify(opts.body, null, 2)}
1384
1248
  ` : "");
1385
- fs2.writeSync(process.stderr.fd, msg);
1249
+ fs.writeSync(process.stderr.fd, msg);
1386
1250
  process.exitCode = ExitCode.SUCCESS;
1387
1251
  throw new PncliError("dry-run", 0);
1388
1252
  }
@@ -1394,22 +1258,45 @@ Headers: ${JSON.stringify(safeHeaders, null, 2)}
1394
1258
  };
1395
1259
  return request(url, init, opts.timeoutMs ?? 3e4, fetcher);
1396
1260
  }
1261
+ figmaHeaders() {
1262
+ const { token } = this.config.figma;
1263
+ if (!token) throw new PncliError("Figma credentials not configured. Run: pncli config set figma.token <token>");
1264
+ return {
1265
+ "X-Figma-Token": token,
1266
+ "Content-Type": "application/json",
1267
+ "Accept": "application/json",
1268
+ "Connection": "close"
1269
+ };
1270
+ }
1271
+ async figma(path, opts = {}) {
1272
+ const baseUrl = this.config.figma.baseUrl;
1273
+ if (!baseUrl) throw new PncliError("Figma baseUrl not configured. Run: pncli config set figma.baseUrl https://api.figma.com");
1274
+ const url = buildUrl(baseUrl, path, opts.params);
1275
+ const headers = this.figmaHeaders();
1276
+ const init = {
1277
+ method: opts.method ?? "GET",
1278
+ headers,
1279
+ body: opts.body !== void 0 ? JSON.stringify(opts.body) : void 0
1280
+ };
1281
+ if (this.dryRun) {
1282
+ const safeHeaders = { ...headers, "X-Figma-Token": "[REDACTED]" };
1283
+ const msg = `DRY RUN: ${init.method} ${url}
1284
+ Headers: ${JSON.stringify(safeHeaders, null, 2)}
1285
+ ` + (opts.body ? `Body: ${JSON.stringify(opts.body, null, 2)}
1286
+ ` : "");
1287
+ fs.writeSync(process.stderr.fd, msg);
1288
+ process.exitCode = ExitCode.SUCCESS;
1289
+ throw new PncliError("dry-run", 0);
1290
+ }
1291
+ return request(url, init, opts.timeoutMs ?? 3e4);
1292
+ }
1397
1293
  };
1398
1294
  function createHttpClient(config, dryRun = false) {
1399
1295
  return new HttpClient(config, dryRun);
1400
1296
  }
1401
1297
 
1402
1298
  export {
1403
- PncliError,
1404
- ExitCode,
1405
- setGlobalOptions,
1406
- setGlobalUser,
1407
- success,
1408
- fail,
1409
- writeRawOutput,
1410
- log,
1411
- warn,
1412
1299
  HttpClient,
1413
1300
  createHttpClient
1414
1301
  };
1415
- //# sourceMappingURL=chunk-AGELHQKO.js.map
1302
+ //# sourceMappingURL=chunk-ZDJYOI3W.js.map