sim 2.1.3 → 2.1.4-dev.57.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 +38 -10
  2. package/package.json +7 -1
package/dist/index.js CHANGED
@@ -2314,6 +2314,23 @@ function credentialsPath() {
2314
2314
  import { chmodSync, existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
2315
2315
  import { dirname } from "node:path";
2316
2316
 
2317
+ // src/embed-context.ts
2318
+ import { AsyncLocalStorage } from "node:async_hooks";
2319
+ var embedStore = new AsyncLocalStorage;
2320
+ function embeddedProfile() {
2321
+ const ctx = embedStore.getStore();
2322
+ if (!ctx)
2323
+ return null;
2324
+ return {
2325
+ name: "embedded",
2326
+ endpoint: ctx.identity.endpoint,
2327
+ apiKey: ctx.identity.apiKey,
2328
+ workspaceId: ctx.identity.workspaceId ?? null,
2329
+ output: "json",
2330
+ sources: { endpoint: "flag", apiKey: "flag", workspaceId: "flag", output: "flag" }
2331
+ };
2332
+ }
2333
+
2317
2334
  // src/config/ini.ts
2318
2335
  class ProfileConfigError extends Error {
2319
2336
  constructor(message) {
@@ -2629,6 +2646,9 @@ function refuseBlankOverrides(overrides) {
2629
2646
  }
2630
2647
  }
2631
2648
  function resolveProfile(overrides = {}) {
2649
+ const embedded = embeddedProfile();
2650
+ if (embedded)
2651
+ return embedded;
2632
2652
  refuseBlankOverrides(overrides);
2633
2653
  const named = overrides.profile || process.env.SIM_PROFILE;
2634
2654
  const name = named || DEFAULT_PROFILE;
@@ -2681,14 +2701,22 @@ function resolveProfile(overrides = {}) {
2681
2701
  // src/version.ts
2682
2702
  import { readFileSync as readFileSync2 } from "node:fs";
2683
2703
  function readPackageVersion() {
2684
- const metadata = JSON.parse(readFileSync2(new URL("../package.json", import.meta.url), "utf8"));
2685
- if (typeof metadata !== "object" || metadata === null || !("version" in metadata) || typeof metadata.version !== "string") {
2686
- throw new Error("CLI package metadata is missing a valid version");
2687
- }
2688
- return metadata.version;
2704
+ try {
2705
+ const metadata = JSON.parse(readFileSync2(new URL("../package.json", import.meta.url), "utf8"));
2706
+ if (typeof metadata === "object" && metadata !== null && "version" in metadata && typeof metadata.version === "string") {
2707
+ return metadata.version;
2708
+ }
2709
+ } catch {}
2710
+ return "0.0.0-embedded";
2711
+ }
2712
+ var cachedVersion = null;
2713
+ function cliVersion() {
2714
+ cachedVersion ??= readPackageVersion();
2715
+ return cachedVersion;
2716
+ }
2717
+ function userAgent() {
2718
+ return `sim-cli/${cliVersion()} node/${process.versions.node} (${process.platform}; ${process.arch})`;
2689
2719
  }
2690
- var CLI_VERSION = readPackageVersion();
2691
- var USER_AGENT = `sim-cli/${CLI_VERSION} node/${process.versions.node} (${process.platform}; ${process.arch})`;
2692
2720
 
2693
2721
  // src/http/environment.ts
2694
2722
  var reported = new Set;
@@ -2971,7 +2999,7 @@ class SimClient {
2971
2999
  headers: {
2972
3000
  ...apiKey ? { "x-api-key": apiKey } : {},
2973
3001
  accept: "application/json",
2974
- "user-agent": USER_AGENT,
3002
+ "user-agent": userAgent(),
2975
3003
  ...hasBody ? { "content-type": "application/json" } : {},
2976
3004
  ...options.headers
2977
3005
  },
@@ -6470,7 +6498,7 @@ async function pollForKey(endpoint, auth, signal) {
6470
6498
  headers: {
6471
6499
  "content-type": "application/json",
6472
6500
  accept: "application/json",
6473
- "user-agent": USER_AGENT
6501
+ "user-agent": userAgent()
6474
6502
  },
6475
6503
  body: JSON.stringify({ request: auth.request, verifier: auth.pollSecret }),
6476
6504
  signal,
@@ -16341,7 +16369,7 @@ function addVersionOption(program2) {
16341
16369
  }
16342
16370
  program2.error("error: --version reports the Sim CLI version and takes no value. A command that acts on a deployment version reads it from --to-version.");
16343
16371
  });
16344
- program2.version(CLI_VERSION, "-V, --version [none]", "output the version number (takes no value)");
16372
+ program2.version(cliVersion(), "-V, --version [none]", "output the version number (takes no value)");
16345
16373
  }
16346
16374
  function buildProgram(options = {}) {
16347
16375
  const program2 = new Command;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sim",
3
- "version": "2.1.3",
3
+ "version": "2.1.4-dev.57.1",
4
4
  "description": "Sim CLI - talk to the Sim API from your terminal",
5
5
  "type": "module",
6
6
  "bin": {
@@ -56,5 +56,11 @@
56
56
  "js-yaml": "4.3.1",
57
57
  "typescript": "^7.0.2",
58
58
  "vitest": "^4.1.0"
59
+ },
60
+ "exports": {
61
+ "./embed": {
62
+ "types": "./src/embed.ts",
63
+ "default": "./src/embed.ts"
64
+ }
59
65
  }
60
66
  }