@harborclient/sdk 1.0.32 → 1.0.33

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,9 +1,16 @@
1
+ /**
2
+ * Runtime context for the sign CLI.
3
+ */
4
+ export interface RunSignCliOptions {
5
+ cwd?: string;
6
+ }
1
7
  /**
2
8
  * Runs the plugin sign CLI and returns a process exit code.
3
9
  *
4
10
  * @param argv - Raw process argv including node and script paths.
11
+ * @param options - Runtime context for path resolution.
5
12
  */
6
- export declare function runSignCli(argv: string[]): Promise<number>;
13
+ export declare function runSignCli(argv: string[], options?: RunSignCliOptions): Promise<number>;
7
14
  /**
8
15
  * Runs the plugin verify CLI and returns a process exit code.
9
16
  *
@@ -1 +1 @@
1
- {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../../src/signing/cli.ts"],"names":[],"mappings":"AAwFA;;;;GAIG;AACH,wBAAsB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC,CA8BhE;AAED;;;;GAIG;AACH,wBAAsB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC,CAyClE"}
1
+ {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../../src/signing/cli.ts"],"names":[],"mappings":"AAuBA;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AA+ED;;;;;GAKG;AACH,wBAAsB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,OAAO,GAAE,iBAAsB,GAAG,OAAO,CAAC,MAAM,CAAC,CAkCjG;AAED;;;;GAIG;AACH,wBAAsB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC,CAyClE"}
@@ -2,8 +2,9 @@ import { readFileSync } from 'node:fs';
2
2
  import { resolve } from 'node:path';
3
3
  import { signPlugin } from './sign.js';
4
4
  import { verifyPlugin } from './verify.js';
5
- const SIGN_USAGE = 'Usage: hc-plugin-sign --dir <pluginDir> --private-key <path> [--key-id <id>] [--signature <path>]';
5
+ const SIGN_USAGE = 'Usage: hc-plugin-sign [--dir <pluginDir>] [--private-key <path>] [--key-id <id>] [--signature <path>]';
6
6
  const VERIFY_USAGE = 'Usage: hc-plugin-verify --dir <pluginDir> --public-key <path> [--public-key <path> ...] [--signature <path>] [--allow-unsigned]';
7
+ const PLUGIN_SIGNING_KEY_ENV = 'HARBORCLIENT_PLUGIN_SIGNING_KEY';
7
8
  /**
8
9
  * Parses supported CLI flags from process argv.
9
10
  *
@@ -58,20 +59,31 @@ function parseCliArgs(argv) {
58
59
  }
59
60
  return parsed;
60
61
  }
62
+ /**
63
+ * Resolves the private key path from the environment or CLI fallback.
64
+ *
65
+ * @param parsed - Parsed CLI arguments.
66
+ */
67
+ function resolvePrivateKeyPath(parsed) {
68
+ const fromEnv = process.env[PLUGIN_SIGNING_KEY_ENV]?.trim();
69
+ return fromEnv || parsed.privateKeyPath;
70
+ }
61
71
  /**
62
72
  * Reads a PEM key file from disk.
63
73
  *
64
74
  * @param path - Absolute or relative key file path.
75
+ * @param cwd - Directory used to resolve relative paths.
65
76
  */
66
- function readKeyFile(path) {
67
- return readFileSync(resolve(path), 'utf8');
77
+ function readKeyFile(path, cwd = process.cwd()) {
78
+ return readFileSync(resolve(cwd, path), 'utf8');
68
79
  }
69
80
  /**
70
81
  * Runs the plugin sign CLI and returns a process exit code.
71
82
  *
72
83
  * @param argv - Raw process argv including node and script paths.
84
+ * @param options - Runtime context for path resolution.
73
85
  */
74
- export async function runSignCli(argv) {
86
+ export async function runSignCli(argv, options = {}) {
75
87
  let parsed;
76
88
  try {
77
89
  parsed = parseCliArgs(argv);
@@ -82,16 +94,19 @@ export async function runSignCli(argv) {
82
94
  console.error(SIGN_USAGE);
83
95
  return 1;
84
96
  }
85
- if (!parsed.dir || !parsed.privateKeyPath) {
97
+ const cwd = options.cwd ?? process.cwd();
98
+ const pluginDir = resolve(cwd, parsed.dir ?? '.');
99
+ const privateKeyPath = resolvePrivateKeyPath(parsed);
100
+ if (!privateKeyPath) {
86
101
  console.error(SIGN_USAGE);
87
102
  return 1;
88
103
  }
89
104
  try {
90
105
  const result = await signPlugin({
91
- pluginDir: parsed.dir,
92
- privateKeyPem: readKeyFile(parsed.privateKeyPath),
106
+ pluginDir,
107
+ privateKeyPem: readKeyFile(privateKeyPath, cwd),
93
108
  keyId: parsed.keyId,
94
- signaturePath: parsed.signaturePath
109
+ signaturePath: parsed.signaturePath ? resolve(cwd, parsed.signaturePath) : undefined
95
110
  });
96
111
  console.log(`Wrote ${result.signaturePath}`);
97
112
  return 0;
@@ -125,7 +140,7 @@ export async function runVerifyCli(argv) {
125
140
  try {
126
141
  const result = await verifyPlugin({
127
142
  pluginDir: parsed.dir,
128
- trustedPublicKeysPem: parsed.publicKeyPaths.map(readKeyFile),
143
+ trustedPublicKeysPem: parsed.publicKeyPaths.map((path) => readKeyFile(path)),
129
144
  signaturePath: parsed.signaturePath
130
145
  });
131
146
  if (result.status === 'valid') {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@harborclient/sdk",
3
- "version": "1.0.32",
3
+ "version": "1.0.33",
4
4
  "description": "TypeScript SDK for HarborClient development.",
5
5
  "keywords": [
6
6
  "harborclient",