sim 2.0.0-preview.13.1 → 2.0.0-preview.14.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.
Files changed (2) hide show
  1. package/dist/index.js +30 -19
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -2527,6 +2527,18 @@ function resolveProfile(overrides = {}) {
2527
2527
  }
2528
2528
  };
2529
2529
  }
2530
+ // src/version.ts
2531
+ import { readFileSync as readFileSync2 } from "node:fs";
2532
+ function readPackageVersion() {
2533
+ const metadata = JSON.parse(readFileSync2(new URL("../package.json", import.meta.url), "utf8"));
2534
+ if (typeof metadata !== "object" || metadata === null || !("version" in metadata) || typeof metadata.version !== "string") {
2535
+ throw new Error("CLI package metadata is missing a valid version");
2536
+ }
2537
+ return metadata.version;
2538
+ }
2539
+ var CLI_VERSION = readPackageVersion();
2540
+ var USER_AGENT = `sim-cli/${CLI_VERSION} node/${process.versions.node} (${process.platform}; ${process.arch})`;
2541
+
2530
2542
  // src/http/client.ts
2531
2543
  class SimApiError extends Error {
2532
2544
  status;
@@ -2551,7 +2563,10 @@ function buildUrl(endpoint, path, query) {
2551
2563
  }
2552
2564
  var REDIRECT_STATUSES = new Set([301, 302, 303, 307, 308]);
2553
2565
  var MARKUP_PREFIX = /^\s*<(?:!doctype|html|\?xml)/i;
2554
- var WORKSPACE_KEY_REFUSAL = "WORKSPACE_KEY_OPERATION_NOT_PERMITTED";
2566
+ var KEY_SCOPE_REFUSALS = new Set([
2567
+ "WORKSPACE_KEY_OPERATION_NOT_PERMITTED",
2568
+ "PRINCIPAL_KIND_NOT_PERMITTED"
2569
+ ]);
2555
2570
  function toNonJsonError(url, status, contentType, raw) {
2556
2571
  const type = contentType?.split(";")[0]?.trim().toLowerCase();
2557
2572
  const isMarkup = type === "text/html" || type === "application/xhtml+xml" || MARKUP_PREFIX.test(raw);
@@ -2583,13 +2598,14 @@ function toApiError(url, status, contentType, raw) {
2583
2598
  function truncate(value, max) {
2584
2599
  return value.length <= max ? value : `${value.slice(0, max)}…`;
2585
2600
  }
2586
- function namesWorkspaceKeyRefusal(error) {
2587
- if (error.code === WORKSPACE_KEY_REFUSAL)
2601
+ function namesKeyScopeRefusal(error) {
2602
+ if (typeof error.code === "string" && KEY_SCOPE_REFUSALS.has(error.code))
2588
2603
  return true;
2589
2604
  const details = error.details;
2590
2605
  if (!details || typeof details !== "object")
2591
2606
  return false;
2592
- return details.code === WORKSPACE_KEY_REFUSAL;
2607
+ const code = details.code;
2608
+ return typeof code === "string" && KEY_SCOPE_REFUSALS.has(code);
2593
2609
  }
2594
2610
  function isStrictPrefix(path, other) {
2595
2611
  if (path.length >= other.length)
@@ -2697,6 +2713,7 @@ class SimClient {
2697
2713
  headers: {
2698
2714
  ...apiKey ? { "x-api-key": apiKey } : {},
2699
2715
  accept: "application/json",
2716
+ "user-agent": USER_AGENT,
2700
2717
  ...hasBody ? { "content-type": "application/json" } : {},
2701
2718
  ...options.headers
2702
2719
  },
@@ -2718,7 +2735,7 @@ class SimClient {
2718
2735
  if (response.status === 401) {
2719
2736
  error.message = `${error.message} — run: sim login --profile ${this.profile.name}`;
2720
2737
  }
2721
- if (namesWorkspaceKeyRefusal(error)) {
2738
+ if (namesKeyScopeRefusal(error)) {
2722
2739
  error.message = `${error.message} — this operation needs a personal API key: sim login --profile ${this.profile.name}`;
2723
2740
  }
2724
2741
  throw error;
@@ -6093,9 +6110,6 @@ function printRecord(format, fields, raw) {
6093
6110
  }
6094
6111
  }
6095
6112
 
6096
- // src/program.ts
6097
- import { readFileSync as readFileSync3 } from "node:fs";
6098
-
6099
6113
  // ../../node_modules/commander/esm.mjs
6100
6114
  var import__ = __toESM(require_commander(), 1);
6101
6115
  var {
@@ -6182,7 +6196,11 @@ async function pollForKey(endpoint, auth, signal) {
6182
6196
  try {
6183
6197
  response = await fetch(new URL(POLL_PATH, endpoint), {
6184
6198
  method: "POST",
6185
- headers: { "content-type": "application/json", accept: "application/json" },
6199
+ headers: {
6200
+ "content-type": "application/json",
6201
+ accept: "application/json",
6202
+ "user-agent": USER_AGENT
6203
+ },
6186
6204
  body: JSON.stringify({ request: auth.request, verifier: auth.pollSecret }),
6187
6205
  signal,
6188
6206
  redirect: "manual"
@@ -9589,7 +9607,7 @@ function configureCommand() {
9589
9607
  }
9590
9608
 
9591
9609
  // src/runtime/request.ts
9592
- import { existsSync as existsSync2, readFileSync as readFileSync2, readSync } from "node:fs";
9610
+ import { existsSync as existsSync2, readFileSync as readFileSync3, readSync } from "node:fs";
9593
9611
 
9594
9612
  // src/contract/commands.ts
9595
9613
  var TABLE_NAME_HELP = "Identifier: letters, numbers, and underscores; cannot start with a number";
@@ -10465,7 +10483,7 @@ function readArgumentSource(raw, flagName) {
10465
10483
  }
10466
10484
  }
10467
10485
  try {
10468
- return { text: readFileSync2(path, "utf8"), from: ` (read from ${path})` };
10486
+ return { text: readFileSync3(path, "utf8"), from: ` (read from ${path})` };
10469
10487
  } catch (error) {
10470
10488
  throw new SimApiError(`--${flagName} cannot read ${path}: ${error.message}`, 0);
10471
10489
  }
@@ -12181,18 +12199,11 @@ Examples:
12181
12199
  $ sim workflows import --workflow @wf.json
12182
12200
  $ sim whoami --profile dev
12183
12201
  `;
12184
- function readPackageVersion() {
12185
- const metadata = JSON.parse(readFileSync3(new URL("../package.json", import.meta.url), "utf8"));
12186
- if (typeof metadata !== "object" || metadata === null || !("version" in metadata) || typeof metadata.version !== "string") {
12187
- throw new Error("CLI package metadata is missing a valid version");
12188
- }
12189
- return metadata.version;
12190
- }
12191
12202
  function buildProgram(options = {}) {
12192
12203
  const program2 = new Command;
12193
12204
  program2.name("sim").description(PROGRAM_DESCRIPTION);
12194
12205
  if (options.version !== false)
12195
- program2.version(readPackageVersion());
12206
+ program2.version(CLI_VERSION);
12196
12207
  program2.option("-P, --profile <name>", "Profile to use (env: SIM_PROFILE)").option("--endpoint <url>", "Sim deployment to talk to (env: SIM_ENDPOINT)").option("-w, --workspace <id>", "Workspace to target (env: SIM_WORKSPACE)").addOption(new Option("--output <format>", "Output format for this command").choices([...OUTPUT_FORMATS]));
12197
12208
  program2.addCommand(loginCommand());
12198
12209
  program2.addCommand(logoutCommand());
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sim",
3
- "version": "2.0.0-preview.13.1",
3
+ "version": "2.0.0-preview.14.1",
4
4
  "description": "Sim CLI - talk to the Sim API from your terminal",
5
5
  "type": "module",
6
6
  "bin": {