@r4-sdk/cli 1.0.0 → 1.0.1
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/README.md +1 -1
- package/lib/index.js +57 -40
- package/lib/index.js.map +1 -1
- package/package.json +10 -10
package/README.md
CHANGED
|
@@ -196,7 +196,7 @@ The CLI now keeps profile state under one consistent root:
|
|
|
196
196
|
|
|
197
197
|
## Dependencies
|
|
198
198
|
|
|
199
|
-
Uses the published `@r4-sdk/
|
|
199
|
+
Uses the published `@r4-sdk/node` package under the hood for API communication. Built with Commander, Chalk, ora, and cli-table3.
|
|
200
200
|
|
|
201
201
|
## Development
|
|
202
202
|
|
package/lib/index.js
CHANGED
|
@@ -303,12 +303,12 @@ function withErrorHandler(fn) {
|
|
|
303
303
|
}
|
|
304
304
|
|
|
305
305
|
// src/lib/config.ts
|
|
306
|
-
import fs2 from "
|
|
306
|
+
import fs2 from "fs";
|
|
307
307
|
|
|
308
308
|
// src/lib/profile-paths.ts
|
|
309
|
-
import fs from "
|
|
310
|
-
import os from "
|
|
311
|
-
import path from "
|
|
309
|
+
import fs from "fs";
|
|
310
|
+
import os from "os";
|
|
311
|
+
import path from "path";
|
|
312
312
|
function sanitizeProfileName(profileName) {
|
|
313
313
|
const sanitized = profileName.trim().toLowerCase().replace(/[^a-z0-9._-]+/g, "-").replace(/^-+|-+$/g, "");
|
|
314
314
|
return sanitized || "default";
|
|
@@ -539,7 +539,7 @@ function clearManagedProfileDirectory(profileName) {
|
|
|
539
539
|
}
|
|
540
540
|
|
|
541
541
|
// src/lib/credentials-store.ts
|
|
542
|
-
import fs3 from "
|
|
542
|
+
import fs3 from "fs";
|
|
543
543
|
function buildApiKeyFromParts(accessKey, secretKey) {
|
|
544
544
|
if (!accessKey || !secretKey) {
|
|
545
545
|
return void 0;
|
|
@@ -604,9 +604,9 @@ function clearProfileCredentials(profileName) {
|
|
|
604
604
|
}
|
|
605
605
|
|
|
606
606
|
// src/lib/private-key.ts
|
|
607
|
-
import crypto from "
|
|
608
|
-
import fs4 from "
|
|
609
|
-
import path2 from "
|
|
607
|
+
import crypto from "crypto";
|
|
608
|
+
import fs4 from "fs";
|
|
609
|
+
import path2 from "path";
|
|
610
610
|
function getDefaultPrivateKeyPath(profileName) {
|
|
611
611
|
return getManagedPrivateKeyPath(profileName);
|
|
612
612
|
}
|
|
@@ -1000,13 +1000,13 @@ import chalk3 from "chalk";
|
|
|
1000
1000
|
import ora4 from "ora";
|
|
1001
1001
|
|
|
1002
1002
|
// ../node/lib/index.js
|
|
1003
|
-
import { randomUUID } from "
|
|
1004
|
-
import path3 from "
|
|
1005
|
-
import crypto2 from "
|
|
1006
|
-
import fs5 from "
|
|
1007
|
-
import path4 from "
|
|
1008
|
-
import fs22 from "
|
|
1009
|
-
import path22 from "
|
|
1003
|
+
import { randomUUID } from "crypto";
|
|
1004
|
+
import path3 from "path";
|
|
1005
|
+
import crypto2 from "crypto";
|
|
1006
|
+
import fs5 from "fs";
|
|
1007
|
+
import path4 from "path";
|
|
1008
|
+
import fs22 from "fs";
|
|
1009
|
+
import path22 from "path";
|
|
1010
1010
|
var R4Client = class {
|
|
1011
1011
|
apiKey;
|
|
1012
1012
|
baseUrl;
|
|
@@ -1037,8 +1037,10 @@ var R4Client = class {
|
|
|
1037
1037
|
});
|
|
1038
1038
|
if (!response.ok) {
|
|
1039
1039
|
const errorBody = await response.json().catch(() => ({}));
|
|
1040
|
-
const
|
|
1041
|
-
const
|
|
1040
|
+
const nestedError = typeof errorBody.error === "object" && errorBody.error !== null ? errorBody.error : null;
|
|
1041
|
+
const topLevelMessage = Array.isArray(errorBody.message) ? errorBody.message.filter((item) => typeof item === "string").join("; ") : typeof errorBody.message === "string" ? errorBody.message : null;
|
|
1042
|
+
const errorMessage = typeof nestedError?.message === "string" ? nestedError.message : topLevelMessage || (typeof errorBody.error === "string" ? errorBody.error : null) || `HTTP ${response.status}: ${response.statusText}`;
|
|
1043
|
+
const errorCode = typeof nestedError?.code === "string" ? ` [${nestedError.code}]` : "";
|
|
1042
1044
|
throw new Error(`R4 API Error${errorCode}: ${errorMessage}`);
|
|
1043
1045
|
}
|
|
1044
1046
|
if (response.status === 204) {
|
|
@@ -1179,7 +1181,8 @@ var R4Client = class {
|
|
|
1179
1181
|
}
|
|
1180
1182
|
};
|
|
1181
1183
|
var TRANSPARENCY_WITNESS_PAYLOAD_PREFIX = "r4-transparency-witness-v1";
|
|
1182
|
-
var DEFAULT_TRANSPARENCY_WITNESS_URL = "https://transparency.r4.dev";
|
|
1184
|
+
var DEFAULT_TRANSPARENCY_WITNESS_URL = "https://transparency-prod.r4.dev";
|
|
1185
|
+
var DEV_TRANSPARENCY_WITNESS_URL = "https://transparency-dev.r4.dev";
|
|
1183
1186
|
var TRANSPARENCY_WITNESS_ROOT_PUBLIC_KEY_PEM = `-----BEGIN PUBLIC KEY-----
|
|
1184
1187
|
MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEA18JhILFiS/BOWR9laubW
|
|
1185
1188
|
g2vepQy26BXAlnrscZZVQUzBBaCM4hWobpt3Nh77vxP0gqVAJXP1hVhPPwxGQnOF
|
|
@@ -1223,16 +1226,22 @@ function parseHostname(apiBaseUrl) {
|
|
|
1223
1226
|
return null;
|
|
1224
1227
|
}
|
|
1225
1228
|
}
|
|
1226
|
-
var
|
|
1229
|
+
var resolveDefaultTransparencyWitnessBaseUrl = (apiBaseUrl) => {
|
|
1227
1230
|
const hostname = parseHostname(apiBaseUrl);
|
|
1228
|
-
|
|
1231
|
+
if (hostname === "r4.dev" || hostname === "api.r4.dev") {
|
|
1232
|
+
return DEFAULT_TRANSPARENCY_WITNESS_URL;
|
|
1233
|
+
}
|
|
1234
|
+
if (hostname === "dev.r4.dev") {
|
|
1235
|
+
return DEV_TRANSPARENCY_WITNESS_URL;
|
|
1236
|
+
}
|
|
1237
|
+
return null;
|
|
1229
1238
|
};
|
|
1230
1239
|
var resolveTransparencyWitnessBaseUrl = (params) => {
|
|
1231
1240
|
const configuredBaseUrl = params.configuredBaseUrl?.trim();
|
|
1232
1241
|
if (configuredBaseUrl) {
|
|
1233
1242
|
return configuredBaseUrl;
|
|
1234
1243
|
}
|
|
1235
|
-
return
|
|
1244
|
+
return resolveDefaultTransparencyWitnessBaseUrl(params.apiBaseUrl);
|
|
1236
1245
|
};
|
|
1237
1246
|
var RSA_OAEP_CONFIG = {
|
|
1238
1247
|
padding: crypto2.constants.RSA_PKCS1_OAEP_PADDING,
|
|
@@ -1521,7 +1530,13 @@ function verifyUserKeyDirectoryTransparencyProof(params) {
|
|
|
1521
1530
|
return false;
|
|
1522
1531
|
}
|
|
1523
1532
|
if (params.currentEntry.version === params.previousHead.version) {
|
|
1524
|
-
|
|
1533
|
+
if (params.currentEntry.entryHash !== params.previousHead.hash) {
|
|
1534
|
+
return false;
|
|
1535
|
+
}
|
|
1536
|
+
if (params.proof.entries.length === 0) {
|
|
1537
|
+
return true;
|
|
1538
|
+
}
|
|
1539
|
+
return params.proof.entries.length === 1 && params.proof.entries[0]?.entryHash === params.currentEntry.entryHash && params.proof.entries[0]?.version === params.currentEntry.version;
|
|
1525
1540
|
}
|
|
1526
1541
|
if (params.proof.entries.length === 0) {
|
|
1527
1542
|
return false;
|
|
@@ -1727,12 +1742,14 @@ function getPinStorageKey(orgId, orgUserId) {
|
|
|
1727
1742
|
return `${orgId}:${orgUserId}`;
|
|
1728
1743
|
}
|
|
1729
1744
|
function getAgentPinStorageKey(orgId, agentId) {
|
|
1745
|
+
void orgId;
|
|
1730
1746
|
return `agent:${agentId}`;
|
|
1731
1747
|
}
|
|
1732
1748
|
function getDirectoryPinStorageKey(orgId) {
|
|
1733
1749
|
return `org:${orgId}`;
|
|
1734
1750
|
}
|
|
1735
1751
|
function getAgentTransparencyPinStorageKey(orgId, agentId) {
|
|
1752
|
+
void orgId;
|
|
1736
1753
|
return `agent-head:${agentId}`;
|
|
1737
1754
|
}
|
|
1738
1755
|
async function fetchWitnessArtifact(witnessBaseUrl, pathName) {
|
|
@@ -2656,7 +2673,7 @@ var R4 = class _R4 {
|
|
|
2656
2673
|
return 0;
|
|
2657
2674
|
}
|
|
2658
2675
|
};
|
|
2659
|
-
var
|
|
2676
|
+
var index_default = R4;
|
|
2660
2677
|
|
|
2661
2678
|
// src/lib/doctor.ts
|
|
2662
2679
|
function getAgentIdFromRegistration(registration) {
|
|
@@ -2932,7 +2949,7 @@ async function runDoctorChecks(connection) {
|
|
|
2932
2949
|
return report;
|
|
2933
2950
|
}
|
|
2934
2951
|
try {
|
|
2935
|
-
const r4 = await
|
|
2952
|
+
const r4 = await index_default.create({
|
|
2936
2953
|
apiKey: connection.apiKey,
|
|
2937
2954
|
baseUrl: connection.baseUrl,
|
|
2938
2955
|
dev: connection.dev,
|
|
@@ -3048,8 +3065,8 @@ function doctorCommand(commandName = "doctor", description = "Verify CLI auth, r
|
|
|
3048
3065
|
}
|
|
3049
3066
|
|
|
3050
3067
|
// src/lib/credentials-file.ts
|
|
3051
|
-
import fs6 from "
|
|
3052
|
-
import path5 from "
|
|
3068
|
+
import fs6 from "fs";
|
|
3069
|
+
import path5 from "path";
|
|
3053
3070
|
function normalizeFieldName(fieldName) {
|
|
3054
3071
|
return fieldName.trim().toLowerCase().replace(/[^a-z0-9]+/g, "");
|
|
3055
3072
|
}
|
|
@@ -3380,8 +3397,8 @@ function cacheProfileIdentity(profileName, identity) {
|
|
|
3380
3397
|
}
|
|
3381
3398
|
|
|
3382
3399
|
// src/lib/prompt.ts
|
|
3383
|
-
import readline from "
|
|
3384
|
-
import { Writable } from "
|
|
3400
|
+
import readline from "readline";
|
|
3401
|
+
import { Writable } from "stream";
|
|
3385
3402
|
var MutableOutput = class extends Writable {
|
|
3386
3403
|
muted = false;
|
|
3387
3404
|
_write(chunk, _encoding, callback) {
|
|
@@ -3860,7 +3877,7 @@ function logoutCommand() {
|
|
|
3860
3877
|
import { Command as Command11 } from "commander";
|
|
3861
3878
|
|
|
3862
3879
|
// src/lib/public-auth-client.ts
|
|
3863
|
-
import crypto3 from "
|
|
3880
|
+
import crypto3 from "crypto";
|
|
3864
3881
|
var PublicAuthClient = class {
|
|
3865
3882
|
baseUrl;
|
|
3866
3883
|
constructor(baseUrl) {
|
|
@@ -4273,8 +4290,8 @@ import { Command as Command16 } from "commander";
|
|
|
4273
4290
|
import ora10 from "ora";
|
|
4274
4291
|
|
|
4275
4292
|
// src/lib/json-input.ts
|
|
4276
|
-
import fs7 from "
|
|
4277
|
-
import path6 from "
|
|
4293
|
+
import fs7 from "fs";
|
|
4294
|
+
import path6 from "path";
|
|
4278
4295
|
function parseJsonInput(params) {
|
|
4279
4296
|
const bodyFlagName = params.bodyFlagName ?? "--body";
|
|
4280
4297
|
const bodyFileFlagName = params.bodyFileFlagName ?? "--body-file";
|
|
@@ -4385,7 +4402,7 @@ function registerBudgetCommands(program2) {
|
|
|
4385
4402
|
|
|
4386
4403
|
// src/commands/configure.ts
|
|
4387
4404
|
import { Command as Command18 } from "commander";
|
|
4388
|
-
import fs8 from "
|
|
4405
|
+
import fs8 from "fs";
|
|
4389
4406
|
async function promptRuntimeTarget(existingProfile) {
|
|
4390
4407
|
const defaultTarget = existingProfile.baseUrl ? "custom" : existingProfile.dev ? "dev" : "prod";
|
|
4391
4408
|
const runtimeTarget = await promptChoice(
|
|
@@ -5035,7 +5052,7 @@ function createItemCommand() {
|
|
|
5035
5052
|
// src/commands/vault/list.ts
|
|
5036
5053
|
import { Command as Command32 } from "commander";
|
|
5037
5054
|
import ora21 from "ora";
|
|
5038
|
-
import R42 from "@r4-sdk/
|
|
5055
|
+
import R42 from "@r4-sdk/node";
|
|
5039
5056
|
function listCommand5() {
|
|
5040
5057
|
return new Command32("list").description("List all locally decrypted environment variables").action(
|
|
5041
5058
|
withErrorHandler(async (_opts, cmd) => {
|
|
@@ -5068,7 +5085,7 @@ import { Command as Command34 } from "commander";
|
|
|
5068
5085
|
// src/commands/vault/items.ts
|
|
5069
5086
|
import { Command as Command33 } from "commander";
|
|
5070
5087
|
import ora22 from "ora";
|
|
5071
|
-
import R43 from "@r4-sdk/
|
|
5088
|
+
import R43 from "@r4-sdk/node";
|
|
5072
5089
|
function deriveItems(env) {
|
|
5073
5090
|
const keys = Object.keys(env).sort();
|
|
5074
5091
|
return keys.map((key) => ({
|
|
@@ -5215,7 +5232,7 @@ function listVaultsCommand() {
|
|
|
5215
5232
|
// src/commands/vault/get.ts
|
|
5216
5233
|
import { Command as Command36 } from "commander";
|
|
5217
5234
|
import ora24 from "ora";
|
|
5218
|
-
import R44 from "@r4-sdk/
|
|
5235
|
+
import R44 from "@r4-sdk/node";
|
|
5219
5236
|
function getCommand2() {
|
|
5220
5237
|
return new Command36("get").description("Get a specific locally decrypted environment variable value").argument("<key>", "Environment variable key (SCREAMING_SNAKE_CASE)").action(
|
|
5221
5238
|
withErrorHandler(
|
|
@@ -5245,7 +5262,7 @@ function getCommand2() {
|
|
|
5245
5262
|
// src/commands/vault/search.ts
|
|
5246
5263
|
import { Command as Command37 } from "commander";
|
|
5247
5264
|
import ora25 from "ora";
|
|
5248
|
-
import R45 from "@r4-sdk/
|
|
5265
|
+
import R45 from "@r4-sdk/node";
|
|
5249
5266
|
function searchCommand() {
|
|
5250
5267
|
return new Command37("search").description("Search vault items by name").argument("<query>", "Search query (case-insensitive match against key names)").action(
|
|
5251
5268
|
withErrorHandler(
|
|
@@ -5418,7 +5435,7 @@ function getCommand3() {
|
|
|
5418
5435
|
|
|
5419
5436
|
// src/commands/project/create.ts
|
|
5420
5437
|
import { Command as Command41 } from "commander";
|
|
5421
|
-
import readline2 from "
|
|
5438
|
+
import readline2 from "readline";
|
|
5422
5439
|
import ora29 from "ora";
|
|
5423
5440
|
function prompt(question) {
|
|
5424
5441
|
const rl = readline2.createInterface({ input: process.stdin, output: process.stdout });
|
|
@@ -5499,9 +5516,9 @@ function registerProjectCommands(program2) {
|
|
|
5499
5516
|
}
|
|
5500
5517
|
|
|
5501
5518
|
// src/commands/run/index.ts
|
|
5502
|
-
import { spawn } from "
|
|
5519
|
+
import { spawn } from "child_process";
|
|
5503
5520
|
import ora31 from "ora";
|
|
5504
|
-
import R46 from "@r4-sdk/
|
|
5521
|
+
import R46 from "@r4-sdk/node";
|
|
5505
5522
|
function registerRunCommand(program2) {
|
|
5506
5523
|
program2.command("run").description("Run a command with vault secrets injected as environment variables").argument("<command...>", "Command and arguments to execute").option("--prefix <prefix>", "Add prefix to all injected env var names").action(
|
|
5507
5524
|
withErrorHandler(
|
|
@@ -5586,7 +5603,7 @@ function registerSecurityGroupCommands(program2) {
|
|
|
5586
5603
|
|
|
5587
5604
|
// src/index.ts
|
|
5588
5605
|
var program = new Command44();
|
|
5589
|
-
program.name("r4").description("R4 CLI \u2014 manage vaults, projects, and secrets from the terminal").version("1.0.
|
|
5606
|
+
program.name("r4").description("R4 CLI \u2014 manage vaults, projects, and secrets from the terminal").version("1.0.1").option("--api-key <key>", "API key (overrides R4_API_KEY env var and config file)").option("--profile <name>", "CLI profile name (overrides R4_PROFILE and the saved current profile)").option("--project-id <id>", "Optional project ID filter (overrides R4_PROJECT_ID env var and config file)").option("--dev", "Use https://dev.r4.dev unless an explicit base URL override is set").option("--base-url <url>", "API base URL (default: https://r4.dev)").option("--private-key-path <path>", "Path to the agent private key PEM (overrides R4_PRIVATE_KEY_PATH env var and config file)").option("--trust-store-path <path>", "Path to the local signer trust-store JSON (overrides R4_TRUST_STORE_PATH env var and config file)").option("--json", "Output as JSON for scripting and piping", false);
|
|
5590
5607
|
registerAgentCommands(program);
|
|
5591
5608
|
registerAuthCommands(program);
|
|
5592
5609
|
registerBillingCommands(program);
|