@enlitt/cli 0.1.0 → 0.1.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/CHANGELOG.md +11 -0
- package/dist/bin.js +118 -9
- package/package.json +11 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.1.1
|
|
4
|
+
|
|
5
|
+
- `enlitt app premium [<id>] (--on | --off) [--confirm]` turns an application's premium credit on or
|
|
6
|
+
off (`--off` on a live application needs `--confirm`); `app show` prints `premium_enabled`; a
|
|
7
|
+
`premium_not_enabled` refusal prints its next step.
|
|
8
|
+
|
|
9
|
+
- `setup` detects the project's language from its root (`package.json` → Node,
|
|
10
|
+
`pyproject.toml` or `requirements.txt` → Python, `*.csproj` or `*.sln` → .NET) and uses it to
|
|
11
|
+
pick the default env file (`.env.local` for Node, `.env` otherwise) and the docs page it points to.
|
|
12
|
+
An explicit `--env-file` or a linked project still wins.
|
|
13
|
+
|
|
3
14
|
## 0.1.0
|
|
4
15
|
|
|
5
16
|
- First public release: device-flow sign-in and step-up approval, business and traffic reads,
|
package/dist/bin.js
CHANGED
|
@@ -67,6 +67,7 @@ var ERROR_ACTIONS = {
|
|
|
67
67
|
env_key_exists: "The file already holds this key. Rerun with `--replace` only if the developer wants it overwritten.",
|
|
68
68
|
insecure_credential_file: "Run `chmod 600 <path>`, then retry.",
|
|
69
69
|
project_not_linked: "Run `enlitt setup` or pass `--app <id>`.",
|
|
70
|
+
premium_not_enabled: "Premium credit is off for this app. An owner or admin can run `enlitt app premium <id> --on`.",
|
|
70
71
|
network_error: "Check the network and retry."
|
|
71
72
|
};
|
|
72
73
|
var PERMISSION_REFUSALS = {
|
|
@@ -77,6 +78,10 @@ var PERMISSION_REFUSALS = {
|
|
|
77
78
|
"apps.manage": (role, business) => ({
|
|
78
79
|
message: `Your role (${role}) in ${business} can't create or change apps.`,
|
|
79
80
|
action: "Ask the business owner or an admin to make you a developer or admin, or to run this command."
|
|
81
|
+
}),
|
|
82
|
+
"premium.manage": (role, business) => ({
|
|
83
|
+
message: `Your role (${role}) in ${business} can't turn premium credit on or off.`,
|
|
84
|
+
action: "Ask the business owner or an admin to run this command, or to change it on the app's dashboard page."
|
|
80
85
|
})
|
|
81
86
|
};
|
|
82
87
|
function permissionRefusal(permission, role, business) {
|
|
@@ -414,6 +419,12 @@ var ENLITT_ERROR_CODES = Object.freeze({
|
|
|
414
419
|
...forbidden
|
|
415
420
|
}),
|
|
416
421
|
insufficient_permissions: definition({ type: "permission_error", status: 403, retryable: false, ...forbidden }),
|
|
422
|
+
// The application's premium switch (`applications.premium_enabled`) refuses
|
|
423
|
+
// premium: a premium start while it is off, or a terminal report for an
|
|
424
|
+
// operation that started before the switch last changed. It is the
|
|
425
|
+
// business's configuration to fix, never a credit refusal, so it carries no
|
|
426
|
+
// `authorize_url` and no other extension field (owner decision 2026-10-25).
|
|
427
|
+
premium_not_enabled: definition({ type: "permission_error", status: 403, retryable: false, ...forbidden }),
|
|
417
428
|
not_found: definition({ type: "invalid_request_error", status: 404, retryable: false, ...forbidden }),
|
|
418
429
|
request_too_large: definition({ type: "invalid_request_error", status: 413, retryable: false, ...forbidden }),
|
|
419
430
|
server_error: definition({ type: "server_error", status: 500, retryable: true, ...forbidden }),
|
|
@@ -1884,6 +1895,7 @@ var BUSINESS_PERMISSIONS = [
|
|
|
1884
1895
|
"payouts.manage",
|
|
1885
1896
|
"payout_billing.manage",
|
|
1886
1897
|
"members.manage",
|
|
1898
|
+
"premium.manage",
|
|
1887
1899
|
"ownership.transfer"
|
|
1888
1900
|
];
|
|
1889
1901
|
var BUSINESS_ROLE_NAMES = ["owner", "admin", "developer", "viewer"];
|
|
@@ -2238,6 +2250,8 @@ function validateBusinessApplicationDetailShape(value) {
|
|
|
2238
2250
|
if (!environment.ok) return environment;
|
|
2239
2251
|
const status = expectLiteral(value.status, APPLICATION_STATUSES, "status");
|
|
2240
2252
|
if (!status.ok) return status;
|
|
2253
|
+
const premiumEnabled = expectBoolean(value.premium_enabled, "premium_enabled");
|
|
2254
|
+
if (!premiumEnabled.ok) return premiumEnabled;
|
|
2241
2255
|
const info = validateBusinessApplicationInfoShape(value.info, "info");
|
|
2242
2256
|
if (!info.ok) return info;
|
|
2243
2257
|
const redirectUris = validateUniqueStringList(
|
|
@@ -2264,6 +2278,7 @@ function validateBusinessApplicationDetailShape(value) {
|
|
|
2264
2278
|
name: name.value,
|
|
2265
2279
|
environment: environment.value,
|
|
2266
2280
|
status: status.value,
|
|
2281
|
+
premium_enabled: premiumEnabled.value,
|
|
2267
2282
|
info: info.value,
|
|
2268
2283
|
redirect_uris: redirectUris.value,
|
|
2269
2284
|
allowed_origins: allowedOrigins.value,
|
|
@@ -2272,6 +2287,15 @@ function validateBusinessApplicationDetailShape(value) {
|
|
|
2272
2287
|
api_keys: apiKeys.value
|
|
2273
2288
|
});
|
|
2274
2289
|
}
|
|
2290
|
+
function validateBusinessApplicationPremiumRequest(value) {
|
|
2291
|
+
if (!isPlainObject4(value)) return invalidValue3("body", "must be an object");
|
|
2292
|
+
for (const key of Object.keys(value)) {
|
|
2293
|
+
if (key !== "enabled") return invalidValue3(key, "is not accepted");
|
|
2294
|
+
}
|
|
2295
|
+
const enabled = expectBoolean(value.enabled, "enabled");
|
|
2296
|
+
if (!enabled.ok) return enabled;
|
|
2297
|
+
return ok3({ enabled: enabled.value });
|
|
2298
|
+
}
|
|
2275
2299
|
function validateCreateBusinessKeyRequest(value) {
|
|
2276
2300
|
if (!isPlainObject4(value)) return invalidValue3("body", "must be an object");
|
|
2277
2301
|
const rejected = rejectUnknownKeys(value, ["scope", "name", "application_id", "expires_at"]);
|
|
@@ -2902,7 +2926,7 @@ var RESULT_CHECKS = {
|
|
|
2902
2926
|
};
|
|
2903
2927
|
|
|
2904
2928
|
// src/version.ts
|
|
2905
|
-
var CLI_VERSION = "0.1.
|
|
2929
|
+
var CLI_VERSION = "0.1.1";
|
|
2906
2930
|
|
|
2907
2931
|
// src/client.ts
|
|
2908
2932
|
var EnlittDashboardError = class extends CliError {
|
|
@@ -3099,6 +3123,13 @@ function createDashboardClient(ctx, credential) {
|
|
|
3099
3123
|
authenticated: true,
|
|
3100
3124
|
parse: (value) => validateBusinessApplicationDetail(value, tolerant)
|
|
3101
3125
|
}),
|
|
3126
|
+
setApplicationPremium: async (id, input) => request({
|
|
3127
|
+
method: "PUT",
|
|
3128
|
+
path: `/v1/dashboard/business/applications/${encodeURIComponent(id)}/premium`,
|
|
3129
|
+
body: checked(validateBusinessApplicationPremiumRequest(input)),
|
|
3130
|
+
authenticated: true,
|
|
3131
|
+
parse: (value) => validateBusinessApplicationDetail(value, tolerant)
|
|
3132
|
+
}),
|
|
3102
3133
|
listKeys: async (query) => {
|
|
3103
3134
|
const valid = checked(validateBusinessKeyListQuery(query));
|
|
3104
3135
|
return request({
|
|
@@ -3385,7 +3416,7 @@ import { basename, dirname as dirname2, isAbsolute, join as join3, relative, res
|
|
|
3385
3416
|
|
|
3386
3417
|
// src/project.ts
|
|
3387
3418
|
import { randomBytes as randomBytes2 } from "crypto";
|
|
3388
|
-
import { access, readFile as readFile3, rename as rename2, rm as rm3, writeFile as writeFile2 } from "fs/promises";
|
|
3419
|
+
import { access, readdir, readFile as readFile3, rename as rename2, rm as rm3, writeFile as writeFile2 } from "fs/promises";
|
|
3389
3420
|
import { dirname, join as join2, parse } from "path";
|
|
3390
3421
|
var PROJECT_FILE_NAME = "enlitt.json";
|
|
3391
3422
|
var DEFAULT_ENV_FILE = ".env.local";
|
|
@@ -3397,17 +3428,40 @@ async function exists(path) {
|
|
|
3397
3428
|
return false;
|
|
3398
3429
|
}
|
|
3399
3430
|
}
|
|
3431
|
+
async function hasDotnetFile(directory) {
|
|
3432
|
+
try {
|
|
3433
|
+
const names = await readdir(directory);
|
|
3434
|
+
return names.some((name) => name.endsWith(".csproj") || name.endsWith(".sln"));
|
|
3435
|
+
} catch {
|
|
3436
|
+
return false;
|
|
3437
|
+
}
|
|
3438
|
+
}
|
|
3439
|
+
async function hasRootMarker(directory) {
|
|
3440
|
+
for (const marker of ["package.json", "pyproject.toml", "requirements.txt", ".git"]) {
|
|
3441
|
+
if (await exists(join2(directory, marker))) return true;
|
|
3442
|
+
}
|
|
3443
|
+
return hasDotnetFile(directory);
|
|
3444
|
+
}
|
|
3400
3445
|
async function findProjectRoot(ctx) {
|
|
3401
3446
|
let directory = ctx.deps.cwd;
|
|
3402
3447
|
for (; ; ) {
|
|
3403
|
-
if (await
|
|
3404
|
-
return directory;
|
|
3405
|
-
}
|
|
3448
|
+
if (await hasRootMarker(directory)) return directory;
|
|
3406
3449
|
if (dirname(directory) === directory || directory === parse(directory).root) break;
|
|
3407
3450
|
directory = dirname(directory);
|
|
3408
3451
|
}
|
|
3409
3452
|
return ctx.deps.cwd;
|
|
3410
3453
|
}
|
|
3454
|
+
async function detectLanguage(root) {
|
|
3455
|
+
if (await exists(join2(root, "package.json"))) return "node";
|
|
3456
|
+
if (await exists(join2(root, "pyproject.toml")) || await exists(join2(root, "requirements.txt"))) {
|
|
3457
|
+
return "python";
|
|
3458
|
+
}
|
|
3459
|
+
if (await hasDotnetFile(root)) return "dotnet";
|
|
3460
|
+
return "node";
|
|
3461
|
+
}
|
|
3462
|
+
function defaultEnvFileFor(language) {
|
|
3463
|
+
return language === "node" ? DEFAULT_ENV_FILE : ".env";
|
|
3464
|
+
}
|
|
3411
3465
|
function invalid3(field, problem) {
|
|
3412
3466
|
return new CliError("invalid_project_file", `${PROJECT_FILE_NAME}: ${field} ${problem}.`, {
|
|
3413
3467
|
action: `Fix or delete ${PROJECT_FILE_NAME}, or rerun \`enlitt setup\`.`
|
|
@@ -3433,8 +3487,10 @@ function validateProject(value) {
|
|
|
3433
3487
|
if (typeof applicationId !== "string" || applicationId === "") {
|
|
3434
3488
|
throw invalid3("applicationId", "must be a non-empty string");
|
|
3435
3489
|
}
|
|
3436
|
-
if (environment !== "test" && environment !== "live")
|
|
3437
|
-
|
|
3490
|
+
if (environment !== "test" && environment !== "live")
|
|
3491
|
+
throw invalid3("environment", 'must be "test" or "live"');
|
|
3492
|
+
if (typeof envFile !== "string" || envFile === "")
|
|
3493
|
+
throw invalid3("envFile", "must be a non-empty string");
|
|
3438
3494
|
return {
|
|
3439
3495
|
applicationId,
|
|
3440
3496
|
environment,
|
|
@@ -3949,6 +4005,7 @@ var COMMAND_PERMISSIONS = {
|
|
|
3949
4005
|
"key list": "stats.view",
|
|
3950
4006
|
"app create": "apps.manage",
|
|
3951
4007
|
"app update": "apps.manage",
|
|
4008
|
+
"app premium": "premium.manage",
|
|
3952
4009
|
"key create": "keys.manage",
|
|
3953
4010
|
"key rotate": "keys.manage",
|
|
3954
4011
|
"key revoke": "keys.manage",
|
|
@@ -4350,6 +4407,7 @@ function applicationText(detail) {
|
|
|
4350
4407
|
["client id", detail.client_id],
|
|
4351
4408
|
["redirect URIs", detail.redirect_uris.join(", ") || "(none)"],
|
|
4352
4409
|
["origins", detail.allowed_origins.join(", ") || "(none)"],
|
|
4410
|
+
["premium credit", detail.premium_enabled ? "on" : "off"],
|
|
4353
4411
|
["keys", `${activeKeyCount(detail.api_keys)} active of ${detail.api_keys.length}`]
|
|
4354
4412
|
]);
|
|
4355
4413
|
}
|
|
@@ -4479,6 +4537,36 @@ async function runAppUpdate(args, ctx) {
|
|
|
4479
4537
|
ctx.out.result(withoutAnalytics(detail), applicationText(detail));
|
|
4480
4538
|
return 0;
|
|
4481
4539
|
}
|
|
4540
|
+
async function runAppPremium(args, ctx) {
|
|
4541
|
+
const on = args.bool("on");
|
|
4542
|
+
const off = args.bool("off");
|
|
4543
|
+
if (on === off) throw usageError("pass exactly one of --on and --off");
|
|
4544
|
+
const id = await applicationIdOrLinked(ctx, args.positionals[0]);
|
|
4545
|
+
const { client } = await session(ctx, "premium.manage");
|
|
4546
|
+
const before = await client.application(id);
|
|
4547
|
+
if (off && before.environment === "live") {
|
|
4548
|
+
requireConfirm(args, "Turning off premium credit on a live application");
|
|
4549
|
+
}
|
|
4550
|
+
const detail = await client.setApplicationPremium(id, { enabled: on });
|
|
4551
|
+
const changed = before.premium_enabled !== detail.premium_enabled;
|
|
4552
|
+
const application = {
|
|
4553
|
+
id: detail.id,
|
|
4554
|
+
name: detail.name,
|
|
4555
|
+
environment: detail.environment,
|
|
4556
|
+
premium_enabled: detail.premium_enabled
|
|
4557
|
+
};
|
|
4558
|
+
const state = detail.premium_enabled ? "on" : "off";
|
|
4559
|
+
const lines = [
|
|
4560
|
+
changed ? `Premium credit is now ${state} for ${detail.name} (${detail.id}).` : `Premium credit was already ${state} for ${detail.name} (${detail.id}).`
|
|
4561
|
+
];
|
|
4562
|
+
if (detail.premium_enabled) {
|
|
4563
|
+
lines.push("Each user's premium limit starts at zero until the user raises it.");
|
|
4564
|
+
} else {
|
|
4565
|
+
lines.push("Premium calls are refused, and none of them is charged.");
|
|
4566
|
+
}
|
|
4567
|
+
ctx.out.result({ application, changed }, lines.join("\n"));
|
|
4568
|
+
return 0;
|
|
4569
|
+
}
|
|
4482
4570
|
function planDestination(args, ctx, defaultVariable, replaceByDefault) {
|
|
4483
4571
|
const file = args.value("write-env");
|
|
4484
4572
|
const reveal = args.bool("reveal");
|
|
@@ -4676,7 +4764,8 @@ async function runKeyRevoke(args, ctx) {
|
|
|
4676
4764
|
}
|
|
4677
4765
|
async function runSetup(args, ctx) {
|
|
4678
4766
|
const project = await readProject(ctx);
|
|
4679
|
-
const
|
|
4767
|
+
const language = await detectLanguage(await findProjectRoot(ctx));
|
|
4768
|
+
const envFile = args.value("env-file") ?? project?.envFile ?? defaultEnvFileFor(language);
|
|
4680
4769
|
const replaceSecret = args.bool("replace-secret");
|
|
4681
4770
|
const present = await readEnvPresence(ctx, envFile, [SECRET_KEY_VARIABLE]);
|
|
4682
4771
|
const needSecret = present[SECRET_KEY_VARIABLE] !== true || replaceSecret;
|
|
@@ -4750,7 +4839,8 @@ async function runSetup(args, ctx) {
|
|
|
4750
4839
|
const written = delivery.extra.gitignored;
|
|
4751
4840
|
gitignored ||= written === true;
|
|
4752
4841
|
}
|
|
4753
|
-
const
|
|
4842
|
+
const docsPage = { node: "authentication", python: "python", dotnet: "dotnet" }[language];
|
|
4843
|
+
const next = `Read ${siteOrigin(ctx.env)}/docs/${docsPage}.md to add sign-in to your app.`;
|
|
4754
4844
|
ctx.out.result(
|
|
4755
4845
|
{
|
|
4756
4846
|
application: {
|
|
@@ -4763,6 +4853,7 @@ async function runSetup(args, ctx) {
|
|
|
4763
4853
|
wrote,
|
|
4764
4854
|
gitignored,
|
|
4765
4855
|
project_file: PROJECT_FILE_NAME,
|
|
4856
|
+
language,
|
|
4766
4857
|
missing: missing2,
|
|
4767
4858
|
next
|
|
4768
4859
|
},
|
|
@@ -5046,6 +5137,24 @@ var COMMAND_DEFINITIONS = [
|
|
|
5046
5137
|
requiredPositionals: 0,
|
|
5047
5138
|
run: runAppUpdate
|
|
5048
5139
|
},
|
|
5140
|
+
{
|
|
5141
|
+
name: ["app", "premium"],
|
|
5142
|
+
summary: "Turn an application's premium credit on or off",
|
|
5143
|
+
usage: "app premium [<id>] (--on | --off) [--confirm]",
|
|
5144
|
+
flags: { on: "bool", off: "bool", confirm: "bool" },
|
|
5145
|
+
flagDocs: {
|
|
5146
|
+
on: {
|
|
5147
|
+
description: "charge premium credit; each user's premium limit starts at zero until the user raises it"
|
|
5148
|
+
},
|
|
5149
|
+
off: {
|
|
5150
|
+
description: "refuse premium calls at once, in-flight ones included, and charge none of them (live needs --confirm)"
|
|
5151
|
+
},
|
|
5152
|
+
confirm: FLAG_CONFIRM
|
|
5153
|
+
},
|
|
5154
|
+
positionals: ["id"],
|
|
5155
|
+
requiredPositionals: 0,
|
|
5156
|
+
run: runAppPremium
|
|
5157
|
+
},
|
|
5049
5158
|
{
|
|
5050
5159
|
name: ["key", "list"],
|
|
5051
5160
|
summary: "List API keys (metadata only)",
|
package/package.json
CHANGED
|
@@ -1,7 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@enlitt/cli",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "Terminal client for an Enlitt business account, built to be driven by a coding agent",
|
|
5
|
+
"homepage": "https://enlitt.com/docs",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/enlitt/sdk.git",
|
|
9
|
+
"directory": "packages/cli"
|
|
10
|
+
},
|
|
11
|
+
"bugs": {
|
|
12
|
+
"url": "https://github.com/enlitt/sdk/issues"
|
|
13
|
+
},
|
|
5
14
|
"license": "MIT",
|
|
6
15
|
"type": "module",
|
|
7
16
|
"bin": {
|
|
@@ -20,7 +29,7 @@
|
|
|
20
29
|
"tsup": "^8.5.1",
|
|
21
30
|
"typescript": "^7.0.2",
|
|
22
31
|
"vitest": "^4.1.11",
|
|
23
|
-
"@enlitt/protocol": "0.1.
|
|
32
|
+
"@enlitt/protocol": "0.1.1"
|
|
24
33
|
},
|
|
25
34
|
"publishConfig": {
|
|
26
35
|
"access": "public"
|