@freeticket/cli 0.13.1 → 0.14.0
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 +22 -5
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// package.json
|
|
4
4
|
var package_default = {
|
|
5
5
|
name: "@freeticket/cli",
|
|
6
|
-
version: "0.
|
|
6
|
+
version: "0.14.0",
|
|
7
7
|
description: "Official FreeTicket CLI \u2014 consumes the B2B REST API for events, sales, tickets, memberships, venues, staff, and reports.",
|
|
8
8
|
keywords: [
|
|
9
9
|
"freeticket",
|
|
@@ -2064,9 +2064,12 @@ function registerAuth(program2) {
|
|
|
2064
2064
|
).option(
|
|
2065
2065
|
"--workspace <id>",
|
|
2066
2066
|
"pin this login to one workspace (default: every workspace the account reaches)"
|
|
2067
|
+
).option(
|
|
2068
|
+
"--read-only",
|
|
2069
|
+
"ask for a read-only key (GET only; any write answers 403) and refuse to save one that is not. Not a sandbox: the real gate is the person approving in the browser"
|
|
2067
2070
|
).option("--json", "raw JSON output (confirmation goes to stderr)").action(async (opts) => {
|
|
2068
2071
|
const apiUrl = opts.url ?? process.env.FT_API_URL ?? readConfig().apiUrl ?? DEFAULT_API_URL;
|
|
2069
|
-
const apiKey = opts.key ?? await deviceLogin(apiUrl);
|
|
2072
|
+
const apiKey = opts.key ?? await deviceLogin(apiUrl, opts.readOnly);
|
|
2070
2073
|
const workspaceId = opts.workspace;
|
|
2071
2074
|
configureClient(workspaceId, {
|
|
2072
2075
|
name: opts.account ?? LEGACY_ACCOUNT,
|
|
@@ -2075,6 +2078,8 @@ function registerAuth(program2) {
|
|
|
2075
2078
|
workspaceId
|
|
2076
2079
|
});
|
|
2077
2080
|
const me = unwrap(await getMe({})).data;
|
|
2081
|
+
const refusal = readOnlyRefusal(opts.readOnly, me.scope);
|
|
2082
|
+
if (refusal) fail(refusal);
|
|
2078
2083
|
const { name, replaces } = loginTarget(
|
|
2079
2084
|
readConfig(),
|
|
2080
2085
|
me.email,
|
|
@@ -2091,7 +2096,7 @@ function registerAuth(program2) {
|
|
|
2091
2096
|
replaces
|
|
2092
2097
|
);
|
|
2093
2098
|
console.error(
|
|
2094
|
-
`${chalk3.green("\u2713")} Account ${chalk3.bold(name)} saved in ${chalk3.dim(CONFIG_PATH)}`
|
|
2099
|
+
`${chalk3.green("\u2713")} Account ${chalk3.bold(name)} saved in ${chalk3.dim(CONFIG_PATH)}` + (me.scope === "read" ? chalk3.yellow(" (read-only)") : "")
|
|
2095
2100
|
);
|
|
2096
2101
|
const { activeAccount, accounts } = readConfig();
|
|
2097
2102
|
if (activeAccount && activeAccount !== name) {
|
|
@@ -2165,6 +2170,7 @@ function registerAuth(program2) {
|
|
|
2165
2170
|
account: m.account,
|
|
2166
2171
|
email: m.email,
|
|
2167
2172
|
name: m.name,
|
|
2173
|
+
scope: m.scope,
|
|
2168
2174
|
workspaces: m.workspaces.map((w) => w.slug).join(", ")
|
|
2169
2175
|
}))
|
|
2170
2176
|
);
|
|
@@ -2223,6 +2229,15 @@ function registerAuth(program2) {
|
|
|
2223
2229
|
);
|
|
2224
2230
|
});
|
|
2225
2231
|
}
|
|
2232
|
+
function withQuery(url, key, value) {
|
|
2233
|
+
const u = new URL(url);
|
|
2234
|
+
u.searchParams.set(key, value);
|
|
2235
|
+
return u.toString();
|
|
2236
|
+
}
|
|
2237
|
+
function readOnlyRefusal(readOnly, scope) {
|
|
2238
|
+
if (!readOnly || scope === "read") return null;
|
|
2239
|
+
return "That key can write (the read-only box was unticked, or --key is a write key). Nothing was saved.";
|
|
2240
|
+
}
|
|
2226
2241
|
function mask(secret) {
|
|
2227
2242
|
return `${secret.slice(0, 12)}\u2026`;
|
|
2228
2243
|
}
|
|
@@ -2234,7 +2249,7 @@ function openBrowser(url) {
|
|
|
2234
2249
|
} catch {
|
|
2235
2250
|
}
|
|
2236
2251
|
}
|
|
2237
|
-
async function deviceLogin(baseUrl) {
|
|
2252
|
+
async function deviceLogin(baseUrl, readOnly = false) {
|
|
2238
2253
|
const apiUrl = baseUrl.replace(/\/$/, "");
|
|
2239
2254
|
client.setConfig({ baseUrl: `${apiUrl}/api/v1` });
|
|
2240
2255
|
const start = unwrap(await postAuthDeviceCode({}));
|
|
@@ -2247,7 +2262,9 @@ Open ${chalk3.cyan(start.verification_uri)} and enter the code:
|
|
|
2247
2262
|
${chalk3.dim("Opening your browser\u2026 (Ctrl+C to cancel)")}
|
|
2248
2263
|
`
|
|
2249
2264
|
);
|
|
2250
|
-
openBrowser(
|
|
2265
|
+
openBrowser(
|
|
2266
|
+
readOnly ? withQuery(start.verification_uri_complete, "scope", "read") : start.verification_uri_complete
|
|
2267
|
+
);
|
|
2251
2268
|
const deadline = Date.now() + start.expires_in * 1e3;
|
|
2252
2269
|
let interval = start.interval;
|
|
2253
2270
|
while (Date.now() < deadline) {
|
package/package.json
CHANGED