@qodalis/cli-scp 2.0.0-beta.12 → 2.0.0-beta.14

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/public-api.mjs CHANGED
@@ -1,9 +1,9 @@
1
- import { DefaultLibraryAuthor, ICliFileTransferService_TOKEN } from '@qodalis/cli-core';
1
+ import { DefaultLibraryAuthor, resolveServerHeaders, ICliFileTransferService_TOKEN, resolveHeaders } from '@qodalis/cli-core';
2
2
 
3
3
  // src/lib/processors/cli-scp-command-processor.ts
4
4
 
5
5
  // src/lib/version.ts
6
- var LIBRARY_VERSION = "2.0.0-beta.12";
6
+ var LIBRARY_VERSION = "2.0.0-beta.14";
7
7
  var API_VERSION = 2;
8
8
 
9
9
  // src/lib/interfaces/index.ts
@@ -62,8 +62,6 @@ function parseServerAndPath(value, context, args) {
62
62
  }
63
63
  return [parts[0], parts.slice(1).join(" ")];
64
64
  }
65
-
66
- // src/lib/processors/cli-scp-ls-processor.ts
67
65
  var CliScpLsProcessor = class {
68
66
  constructor() {
69
67
  this.command = "ls";
@@ -94,7 +92,7 @@ var CliScpLsProcessor = class {
94
92
  const [serverName, path] = parsed;
95
93
  const server = resolveServer(serverName, context);
96
94
  if (!server) return;
97
- const transferService = context.services.get(
95
+ const transferService = context.services.getRequired(
98
96
  IScpTransferService_TOKEN
99
97
  );
100
98
  if (!transferService) {
@@ -106,7 +104,7 @@ var CliScpLsProcessor = class {
106
104
  const entries = await transferService.ls(
107
105
  serverUrl(server),
108
106
  path,
109
- server.headers
107
+ resolveServerHeaders(context.services, server.name, server.headers)
110
108
  );
111
109
  context.spinner?.hide();
112
110
  if (entries.length === 0) {
@@ -131,8 +129,6 @@ var CliScpLsProcessor = class {
131
129
  context.writer.writeln("List files and directories on a remote server.");
132
130
  }
133
131
  };
134
-
135
- // src/lib/processors/cli-scp-cat-processor.ts
136
132
  var CliScpCatProcessor = class {
137
133
  constructor() {
138
134
  this.command = "cat";
@@ -163,7 +159,7 @@ var CliScpCatProcessor = class {
163
159
  const [serverName, path] = parsed;
164
160
  const server = resolveServer(serverName, context);
165
161
  if (!server) return;
166
- const transferService = context.services.get(
162
+ const transferService = context.services.getRequired(
167
163
  IScpTransferService_TOKEN
168
164
  );
169
165
  if (!transferService) {
@@ -175,7 +171,7 @@ var CliScpCatProcessor = class {
175
171
  const content = await transferService.cat(
176
172
  serverUrl(server),
177
173
  path,
178
- server.headers
174
+ resolveServerHeaders(context.services, server.name, server.headers)
179
175
  );
180
176
  context.spinner?.hide();
181
177
  context.writer.writeln(content);
@@ -254,7 +250,7 @@ var CliScpDownloadProcessor = class {
254
250
  localPath = localPath || remotePath.split("/").pop() || "download";
255
251
  const server = resolveServer(serverName, context);
256
252
  if (!server) return;
257
- const transferService = context.services.get(
253
+ const transferService = context.services.getRequired(
258
254
  IScpTransferService_TOKEN
259
255
  );
260
256
  if (!transferService) {
@@ -263,7 +259,7 @@ var CliScpDownloadProcessor = class {
263
259
  }
264
260
  const useBrowserDownload = command.args?.["save"] === true;
265
261
  context.spinner?.show(`Downloading ${remotePath} from ${server.name}...`);
266
- context.setStatusText(`scp: downloading from ${server.name}`);
262
+ context.notifier.info(`scp: downloading from ${server.name}`);
267
263
  const abortController = new AbortController();
268
264
  const abortSub = context.onAbort.subscribe(() => abortController.abort());
269
265
  try {
@@ -271,7 +267,7 @@ var CliScpDownloadProcessor = class {
271
267
  const { content, size } = await transferService.download(
272
268
  serverUrl(server),
273
269
  remotePath,
274
- server.headers,
270
+ resolveServerHeaders(context.services, server.name, server.headers),
275
271
  (received, total) => {
276
272
  const now = Date.now();
277
273
  if (now - lastProgressUpdate < 200) return;
@@ -281,19 +277,19 @@ var CliScpDownloadProcessor = class {
281
277
  context.spinner?.show(
282
278
  `Downloading ${remotePath}... ${pct}% (${formatBytes(received)}/${formatBytes(total)})`
283
279
  );
284
- context.setStatusText(`scp: download ${pct}%`);
280
+ context.notifier.info(`scp: download ${pct}%`);
285
281
  } else {
286
282
  context.spinner?.show(
287
283
  `Downloading ${remotePath}... ${formatBytes(received)}`
288
284
  );
289
- context.setStatusText(`scp: download ${formatBytes(received)}`);
285
+ context.notifier.info(`scp: download ${formatBytes(received)}`);
290
286
  }
291
287
  },
292
288
  abortController.signal
293
289
  );
294
290
  context.spinner?.hide();
295
291
  if (useBrowserDownload) {
296
- const fileService = context.services.get(
292
+ const fileService = context.services.getRequired(
297
293
  ICliFileTransferService_TOKEN
298
294
  );
299
295
  if (fileService) {
@@ -305,7 +301,7 @@ var CliScpDownloadProcessor = class {
305
301
  context.writer.writeError("File transfer service not available for browser download.");
306
302
  }
307
303
  } else {
308
- const fileService = context.services.get(
304
+ const fileService = context.services.getRequired(
309
305
  ICliFileTransferService_TOKEN
310
306
  );
311
307
  if (fileService) {
@@ -408,14 +404,14 @@ var CliScpUploadProcessor = class {
408
404
  }
409
405
  const server = resolveServer(serverName, context);
410
406
  if (!server) return;
411
- const fileService = context.services.get(
407
+ const fileService = context.services.getRequired(
412
408
  ICliFileTransferService_TOKEN
413
409
  );
414
410
  if (!fileService) {
415
411
  context.writer.writeError("File transfer service not available.");
416
412
  return;
417
413
  }
418
- const transferService = context.services.get(
414
+ const transferService = context.services.getRequired(
419
415
  IScpTransferService_TOKEN
420
416
  );
421
417
  if (!transferService) {
@@ -445,14 +441,14 @@ var CliScpUploadProcessor = class {
445
441
  context.spinner?.show(
446
442
  `Uploading "${filename}" (${formatBytes(content.length)}) to ${server.name}:${remotePath}...`
447
443
  );
448
- context.setStatusText(`scp: uploading to ${server.name}`);
444
+ context.notifier.info(`scp: uploading to ${server.name}`);
449
445
  try {
450
446
  await transferService.upload(
451
447
  serverUrl(server),
452
448
  remotePath,
453
449
  content,
454
450
  filename,
455
- server.headers
451
+ resolveServerHeaders(context.services, server.name, server.headers)
456
452
  );
457
453
  context.spinner?.hide();
458
454
  context.writer.writeSuccess(
@@ -471,8 +467,6 @@ var CliScpUploadProcessor = class {
471
467
  context.writer.writeln(" scp upload --local <server> <remote-path> Pick from your machine via browser");
472
468
  }
473
469
  };
474
-
475
- // src/lib/processors/cli-scp-rm-processor.ts
476
470
  var CliScpRmProcessor = class {
477
471
  constructor() {
478
472
  this.command = "rm";
@@ -503,7 +497,7 @@ var CliScpRmProcessor = class {
503
497
  const [serverName, path] = parsed;
504
498
  const server = resolveServer(serverName, context);
505
499
  if (!server) return;
506
- const transferService = context.services.get(
500
+ const transferService = context.services.getRequired(
507
501
  IScpTransferService_TOKEN
508
502
  );
509
503
  if (!transferService) {
@@ -515,7 +509,7 @@ var CliScpRmProcessor = class {
515
509
  await transferService.rm(
516
510
  serverUrl(server),
517
511
  path,
518
- server.headers
512
+ resolveServerHeaders(context.services, server.name, server.headers)
519
513
  );
520
514
  context.spinner?.hide();
521
515
  context.writer.writeSuccess(`Deleted: ${server.name}:${path}`);
@@ -528,8 +522,6 @@ var CliScpRmProcessor = class {
528
522
  context.writer.writeln("Delete a file on a remote server.");
529
523
  }
530
524
  };
531
-
532
- // src/lib/processors/cli-scp-mkdir-processor.ts
533
525
  var CliScpMkdirProcessor = class {
534
526
  constructor() {
535
527
  this.command = "mkdir";
@@ -560,7 +552,7 @@ var CliScpMkdirProcessor = class {
560
552
  const [serverName, path] = parsed;
561
553
  const server = resolveServer(serverName, context);
562
554
  if (!server) return;
563
- const transferService = context.services.get(
555
+ const transferService = context.services.getRequired(
564
556
  IScpTransferService_TOKEN
565
557
  );
566
558
  if (!transferService) {
@@ -572,7 +564,7 @@ var CliScpMkdirProcessor = class {
572
564
  await transferService.mkdir(
573
565
  serverUrl(server),
574
566
  path,
575
- server.headers
567
+ resolveServerHeaders(context.services, server.name, server.headers)
576
568
  );
577
569
  context.spinner?.hide();
578
570
  context.writer.writeSuccess(`Created directory: ${server.name}:${path}`);
@@ -585,8 +577,6 @@ var CliScpMkdirProcessor = class {
585
577
  context.writer.writeln("Create a directory on a remote server.");
586
578
  }
587
579
  };
588
-
589
- // src/lib/processors/cli-scp-stat-processor.ts
590
580
  var CliScpStatProcessor = class {
591
581
  constructor() {
592
582
  this.command = "stat";
@@ -617,7 +607,7 @@ var CliScpStatProcessor = class {
617
607
  const [serverName, path] = parsed;
618
608
  const server = resolveServer(serverName, context);
619
609
  if (!server) return;
620
- const transferService = context.services.get(
610
+ const transferService = context.services.getRequired(
621
611
  IScpTransferService_TOKEN
622
612
  );
623
613
  if (!transferService) {
@@ -629,7 +619,7 @@ var CliScpStatProcessor = class {
629
619
  const stat = await transferService.stat(
630
620
  serverUrl(server),
631
621
  path,
632
- server.headers
622
+ resolveServerHeaders(context.services, server.name, server.headers)
633
623
  );
634
624
  context.spinner?.hide();
635
625
  const entries = {
@@ -711,7 +701,7 @@ var CliScpCommandCommandProcessor = class {
711
701
  async doDownload(serverName, remotePath, localPath, command, context) {
712
702
  const server = resolveServer(serverName, context);
713
703
  if (!server) return;
714
- const transferService = context.services.get(
704
+ const transferService = context.services.getRequired(
715
705
  IScpTransferService_TOKEN
716
706
  );
717
707
  if (!transferService) {
@@ -720,13 +710,13 @@ var CliScpCommandCommandProcessor = class {
720
710
  }
721
711
  const useBrowserDownload = command.args?.["save"] === true;
722
712
  context.spinner?.show(`Downloading ${remotePath} from ${server.name}...`);
723
- context.setStatusText(`scp: downloading from ${server.name}`);
713
+ context.notifier.info(`scp: downloading from ${server.name}`);
724
714
  try {
725
715
  let lastProgressUpdate = 0;
726
716
  const { content, size } = await transferService.download(
727
717
  serverUrl(server),
728
718
  remotePath,
729
- server.headers,
719
+ resolveServerHeaders(context.services, server.name, server.headers),
730
720
  (received, total) => {
731
721
  const now = Date.now();
732
722
  if (now - lastProgressUpdate < 200) return;
@@ -736,17 +726,17 @@ var CliScpCommandCommandProcessor = class {
736
726
  context.spinner?.show(
737
727
  `Downloading ${remotePath}... ${pct}% (${formatBytes(received)}/${formatBytes(total)})`
738
728
  );
739
- context.setStatusText(`scp: download ${pct}%`);
729
+ context.notifier.info(`scp: download ${pct}%`);
740
730
  } else {
741
731
  context.spinner?.show(
742
732
  `Downloading ${remotePath}... ${formatBytes(received)}`
743
733
  );
744
- context.setStatusText(`scp: download ${formatBytes(received)}`);
734
+ context.notifier.info(`scp: download ${formatBytes(received)}`);
745
735
  }
746
736
  }
747
737
  );
748
738
  context.spinner?.hide();
749
- const fileService = context.services.get(
739
+ const fileService = context.services.getRequired(
750
740
  ICliFileTransferService_TOKEN
751
741
  );
752
742
  if (!fileService) {
@@ -772,14 +762,14 @@ var CliScpCommandCommandProcessor = class {
772
762
  async doUpload(serverName, localPath, remotePath, context) {
773
763
  const server = resolveServer(serverName, context);
774
764
  if (!server) return;
775
- const fileService = context.services.get(
765
+ const fileService = context.services.getRequired(
776
766
  ICliFileTransferService_TOKEN
777
767
  );
778
768
  if (!fileService) {
779
769
  context.writer.writeError("File transfer service not available.");
780
770
  return;
781
771
  }
782
- const transferService = context.services.get(
772
+ const transferService = context.services.getRequired(
783
773
  IScpTransferService_TOKEN
784
774
  );
785
775
  if (!transferService) {
@@ -787,7 +777,7 @@ var CliScpCommandCommandProcessor = class {
787
777
  return;
788
778
  }
789
779
  context.spinner?.show(`Reading local file "${localPath}"...`);
790
- context.setStatusText(`scp: reading ${localPath}`);
780
+ context.notifier.info(`scp: reading ${localPath}`);
791
781
  try {
792
782
  const content = await fileService.readFile(localPath);
793
783
  if (content === null) {
@@ -799,13 +789,13 @@ var CliScpCommandCommandProcessor = class {
799
789
  context.spinner?.show(
800
790
  `Uploading "${filename}" (${formatBytes(content.length)}) to ${server.name}:${remotePath}...`
801
791
  );
802
- context.setStatusText(`scp: uploading to ${server.name}`);
792
+ context.notifier.info(`scp: uploading to ${server.name}`);
803
793
  await transferService.upload(
804
794
  serverUrl(server),
805
795
  remotePath,
806
796
  content,
807
797
  filename,
808
- server.headers
798
+ resolveServerHeaders(context.services, server.name, server.headers)
809
799
  );
810
800
  context.spinner?.hide();
811
801
  context.writer.writeSuccess(
@@ -817,32 +807,30 @@ var CliScpCommandCommandProcessor = class {
817
807
  }
818
808
  }
819
809
  };
820
-
821
- // src/lib/services/scp-transfer.service.ts
822
810
  var ScpTransferService = class {
823
811
  async ls(serverUrl2, path, headers) {
824
812
  const res = await this._fetch(`${serverUrl2}/api/qcli/fs/ls?path=${encodeURIComponent(path)}`, {
825
- headers
813
+ headers: resolveHeaders(headers)
826
814
  });
827
815
  const data = await res.json();
828
816
  return data.entries;
829
817
  }
830
818
  async cat(serverUrl2, path, headers) {
831
819
  const res = await this._fetch(`${serverUrl2}/api/qcli/fs/cat?path=${encodeURIComponent(path)}`, {
832
- headers
820
+ headers: resolveHeaders(headers)
833
821
  });
834
822
  const data = await res.json();
835
823
  return data.content;
836
824
  }
837
825
  async stat(serverUrl2, path, headers) {
838
826
  const res = await this._fetch(`${serverUrl2}/api/qcli/fs/stat?path=${encodeURIComponent(path)}`, {
839
- headers
827
+ headers: resolveHeaders(headers)
840
828
  });
841
829
  return await res.json();
842
830
  }
843
831
  async download(serverUrl2, path, headers, onProgress, signal) {
844
832
  const res = await this._fetch(`${serverUrl2}/api/qcli/fs/download?path=${encodeURIComponent(path)}`, {
845
- headers,
833
+ headers: resolveHeaders(headers),
846
834
  signal
847
835
  });
848
836
  const contentLength = parseInt(res.headers.get("content-length") || "0", 10);
@@ -878,20 +866,20 @@ var ScpTransferService = class {
878
866
  await this._fetch(`${serverUrl2}/api/qcli/fs/upload`, {
879
867
  method: "POST",
880
868
  body: formData,
881
- headers
869
+ headers: resolveHeaders(headers)
882
870
  });
883
871
  }
884
872
  async mkdir(serverUrl2, path, headers) {
885
873
  await this._fetch(`${serverUrl2}/api/qcli/fs/mkdir`, {
886
874
  method: "POST",
887
- headers: { "Content-Type": "application/json", ...headers },
875
+ headers: { "Content-Type": "application/json", ...resolveHeaders(headers) },
888
876
  body: JSON.stringify({ path })
889
877
  });
890
878
  }
891
879
  async rm(serverUrl2, path, headers) {
892
880
  await this._fetch(`${serverUrl2}/api/qcli/fs/rm?path=${encodeURIComponent(path)}`, {
893
881
  method: "DELETE",
894
- headers
882
+ headers: resolveHeaders(headers)
895
883
  });
896
884
  }
897
885
  async _fetch(url, init) {