sim 2.0.0-preview.13.1 → 2.0.0-preview.15.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/dist/index.js +40 -29
- 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
|
|
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
|
|
2587
|
-
if (error.code ===
|
|
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
|
-
|
|
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 (
|
|
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 {
|
|
@@ -6128,6 +6142,8 @@ function sleep(ms) {
|
|
|
6128
6142
|
var PAIRING_ALPHABET = "ABCDEFGHJKLMNPQRSTUVWXYZ23456789";
|
|
6129
6143
|
var POLL_INTERVAL_MS = 2000;
|
|
6130
6144
|
var POLL_TIMEOUT_MS = 15 * 60 * 1000;
|
|
6145
|
+
var APPROVAL_PATH = "/cli/auth";
|
|
6146
|
+
var POLL_PATH = "/api/cli/auth/poll";
|
|
6131
6147
|
var RETRYABLE_POLL_STATUSES = new Set([409, 429, 500, 502, 503, 504]);
|
|
6132
6148
|
function token() {
|
|
6133
6149
|
return randomBytes(32).toString("base64url");
|
|
@@ -6146,16 +6162,14 @@ function createAuthRequest() {
|
|
|
6146
6162
|
};
|
|
6147
6163
|
}
|
|
6148
6164
|
function buildApprovalUrl(endpoint, auth, scope, workspaceId) {
|
|
6149
|
-
|
|
6150
|
-
|
|
6151
|
-
|
|
6152
|
-
|
|
6153
|
-
|
|
6154
|
-
|
|
6155
|
-
|
|
6156
|
-
return url.toString();
|
|
6165
|
+
return buildUrl(endpoint, APPROVAL_PATH, {
|
|
6166
|
+
request: auth.request,
|
|
6167
|
+
challenge: auth.challenge,
|
|
6168
|
+
pairing: auth.pairing,
|
|
6169
|
+
scope,
|
|
6170
|
+
workspace: workspaceId
|
|
6171
|
+
});
|
|
6157
6172
|
}
|
|
6158
|
-
var POLL_PATH = "/api/cli/auth/poll";
|
|
6159
6173
|
function toRedirectError(endpoint, response) {
|
|
6160
6174
|
const location = response.headers.get("location")?.trim();
|
|
6161
6175
|
let target = null;
|
|
@@ -6180,9 +6194,13 @@ async function pollForKey(endpoint, auth, signal) {
|
|
|
6180
6194
|
throw new SimApiError("Login cancelled.", 0);
|
|
6181
6195
|
let response = null;
|
|
6182
6196
|
try {
|
|
6183
|
-
response = await fetch(
|
|
6197
|
+
response = await fetch(buildUrl(endpoint, POLL_PATH), {
|
|
6184
6198
|
method: "POST",
|
|
6185
|
-
headers: {
|
|
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
|
|
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:
|
|
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(
|
|
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());
|