@elisym/cli 0.37.0 → 0.38.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 +84 -10
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -487,7 +487,10 @@ function awaitingPlanOf(view) {
|
|
|
487
487
|
return view.status === "pending" && view.tier === null;
|
|
488
488
|
}
|
|
489
489
|
function planHintOf(view) {
|
|
490
|
-
|
|
490
|
+
if (!awaitingPlanOf(view)) {
|
|
491
|
+
return CONTACT_HINT;
|
|
492
|
+
}
|
|
493
|
+
return view.billing?.checkoutAvailable === true ? CHOOSE_PLAN_BILLING_HINT : CHOOSE_PLAN_HINT;
|
|
491
494
|
}
|
|
492
495
|
function inactiveExit(view, exitCode = EXIT.LIMIT) {
|
|
493
496
|
return new AskrExit(exitCode, "inactive", {
|
|
@@ -570,13 +573,14 @@ async function waitPublished(session, first, onStopped) {
|
|
|
570
573
|
function stoppedKinds(view) {
|
|
571
574
|
return view.events.failing.filter((event) => event.stopped).map((event) => event.kind);
|
|
572
575
|
}
|
|
573
|
-
var CHOOSE_PLAN_HINT, CONTACT_HINT, INIT_FIRST_HINT, CLOCK_HINT, UNAUTHORIZED_HINTS, MOVED_HINT;
|
|
576
|
+
var CHOOSE_PLAN_HINT, CHOOSE_PLAN_BILLING_HINT, CONTACT_HINT, INIT_FIRST_HINT, CLOCK_HINT, UNAUTHORIZED_HINTS, MOVED_HINT;
|
|
574
577
|
var init_store = __esm({
|
|
575
578
|
"src/commands/askr/store.ts"() {
|
|
576
579
|
init_constants();
|
|
577
580
|
init_errors();
|
|
578
581
|
init_owner_key();
|
|
579
582
|
CHOOSE_PLAN_HINT = "choose a plan: askr plan free (only if the human chose Free), or message us with your Store ID for a paid plan";
|
|
583
|
+
CHOOSE_PLAN_BILLING_HINT = "choose a plan: askr plan free (only if the human chose Free), or askr plan <starter|growth|pro|scale> [--yearly] for the paid plan the human chose, then give them its checkoutUrl to pay";
|
|
580
584
|
CONTACT_HINT = `message us with your Store ID: ${CONTACT_URL}`;
|
|
581
585
|
INIT_FIRST_HINT = "run askr init first";
|
|
582
586
|
CLOCK_HINT = "check this computer's clock: it is off by more than a minute";
|
|
@@ -1299,13 +1303,62 @@ var plan_exports = {};
|
|
|
1299
1303
|
__export(plan_exports, {
|
|
1300
1304
|
runPlan: () => runPlan
|
|
1301
1305
|
});
|
|
1302
|
-
async function
|
|
1306
|
+
async function runCheckout(session, plan, options) {
|
|
1307
|
+
const key = await useOwnerKey(session);
|
|
1308
|
+
const interval = options.yearly === true ? "year" : "month";
|
|
1309
|
+
const result = await session.call("POST", "/v1/admin/billing/checkout", {
|
|
1310
|
+
plan,
|
|
1311
|
+
interval
|
|
1312
|
+
});
|
|
1313
|
+
if (!result.ok) {
|
|
1314
|
+
switch (result.code) {
|
|
1315
|
+
case "billing_unavailable":
|
|
1316
|
+
case "plan_unavailable":
|
|
1317
|
+
throw new AskrExit(EXIT.LIMIT, result.code, {
|
|
1318
|
+
hint: `this plan cannot be bought here right now: ${PAID_HINT}`,
|
|
1319
|
+
fields: { upgrade: UPGRADE }
|
|
1320
|
+
});
|
|
1321
|
+
case "subscription_exists":
|
|
1322
|
+
throw new AskrExit(EXIT.REFUSED, "subscription_exists", {
|
|
1323
|
+
hint: `the store already has a paid plan: change it under Manage billing in the admin (${session.adminUrl})`
|
|
1324
|
+
});
|
|
1325
|
+
case "suspended":
|
|
1326
|
+
throw new AskrExit(EXIT.REFUSED, "suspended", {
|
|
1327
|
+
hint: `the store is suspended: ${CONTACT_HINT}`
|
|
1328
|
+
});
|
|
1329
|
+
case "operator_managed":
|
|
1330
|
+
throw new AskrExit(EXIT.REFUSED, "operator_managed", {
|
|
1331
|
+
hint: `we manage this store's plan: ${CONTACT_HINT}`
|
|
1332
|
+
});
|
|
1333
|
+
default:
|
|
1334
|
+
throw refusalExit(session, result);
|
|
1335
|
+
}
|
|
1336
|
+
}
|
|
1337
|
+
return {
|
|
1338
|
+
exitCode: EXIT.OK,
|
|
1339
|
+
output: {
|
|
1340
|
+
ok: true,
|
|
1341
|
+
storeId: key.storeId,
|
|
1342
|
+
plan,
|
|
1343
|
+
interval,
|
|
1344
|
+
checkoutUrl: result.body.url,
|
|
1345
|
+
hint: "give the human this checkoutUrl to open and pay (never open it yourself); the store goes live once the payment went through: check with askr status"
|
|
1346
|
+
}
|
|
1347
|
+
};
|
|
1348
|
+
}
|
|
1349
|
+
async function runPlan(session, plan, options = {}) {
|
|
1350
|
+
if (PAID_PLANS.includes(plan)) {
|
|
1351
|
+
return runCheckout(session, plan, options);
|
|
1352
|
+
}
|
|
1303
1353
|
if (plan !== FREE) {
|
|
1304
|
-
throw new AskrExit(EXIT.BAD_INPUT, "
|
|
1305
|
-
hint: "
|
|
1354
|
+
throw new AskrExit(EXIT.BAD_INPUT, "unknown_plan", {
|
|
1355
|
+
hint: "plans: free, starter, growth, pro, scale (Enterprise: message us with your Store ID)",
|
|
1306
1356
|
fields: { upgrade: UPGRADE }
|
|
1307
1357
|
});
|
|
1308
1358
|
}
|
|
1359
|
+
if (options.yearly === true) {
|
|
1360
|
+
throw new AskrExit(EXIT.BAD_INPUT, "bad_flag", { hint: "--yearly is for a paid plan" });
|
|
1361
|
+
}
|
|
1309
1362
|
const key = await useOwnerKey(session);
|
|
1310
1363
|
const result = await session.call(
|
|
1311
1364
|
"POST",
|
|
@@ -1370,13 +1423,15 @@ async function runPlan(session, plan) {
|
|
|
1370
1423
|
}
|
|
1371
1424
|
};
|
|
1372
1425
|
}
|
|
1373
|
-
var FREE;
|
|
1426
|
+
var FREE, PAID_PLANS, PAID_HINT;
|
|
1374
1427
|
var init_plan = __esm({
|
|
1375
1428
|
"src/commands/askr/plan.ts"() {
|
|
1376
1429
|
init_constants();
|
|
1377
1430
|
init_errors();
|
|
1378
1431
|
init_store();
|
|
1379
1432
|
FREE = "free";
|
|
1433
|
+
PAID_PLANS = ["starter", "growth", "pro", "scale"];
|
|
1434
|
+
PAID_HINT = "paid plans: message us with your Store ID";
|
|
1380
1435
|
}
|
|
1381
1436
|
});
|
|
1382
1437
|
|
|
@@ -2096,6 +2151,21 @@ function money(value) {
|
|
|
2096
2151
|
return "0";
|
|
2097
2152
|
}
|
|
2098
2153
|
}
|
|
2154
|
+
function billingOf(view) {
|
|
2155
|
+
const billing = view.billing;
|
|
2156
|
+
if (billing === void 0) {
|
|
2157
|
+
return null;
|
|
2158
|
+
}
|
|
2159
|
+
return {
|
|
2160
|
+
enabled: billing.enabled,
|
|
2161
|
+
plan: billing.plan,
|
|
2162
|
+
interval: billing.interval,
|
|
2163
|
+
status: billing.status,
|
|
2164
|
+
currentPeriodEnd: billing.currentPeriodEnd,
|
|
2165
|
+
cancelAtPeriodEnd: billing.cancelAtPeriodEnd,
|
|
2166
|
+
checkoutAvailable: billing.checkoutAvailable
|
|
2167
|
+
};
|
|
2168
|
+
}
|
|
2099
2169
|
function connectorOf(view) {
|
|
2100
2170
|
const connector = view.connector;
|
|
2101
2171
|
if (connector === null) {
|
|
@@ -2245,6 +2315,7 @@ async function runStatus(session, options) {
|
|
|
2245
2315
|
todaySpentUsd: money(view.usage.today.spent),
|
|
2246
2316
|
monthSpentUsd: money(view.usage.month.spent)
|
|
2247
2317
|
},
|
|
2318
|
+
billing: billingOf(view),
|
|
2248
2319
|
ownerKeyFile: key.path,
|
|
2249
2320
|
adminUrl: session.adminUrl,
|
|
2250
2321
|
upgrade: UPGRADE
|
|
@@ -4118,9 +4189,12 @@ function registerAskr(program2, run, args, jsonErrors) {
|
|
|
4118
4189
|
(options) => run({ command: "init", options }, context(options))
|
|
4119
4190
|
);
|
|
4120
4191
|
askr.command("plan <plan>").description(
|
|
4121
|
-
"Choose a plan:
|
|
4122
|
-
).option(PROFILE_FLAG, PROFILE_HELP).action(
|
|
4123
|
-
(plan, options) => run(
|
|
4192
|
+
"Choose a plan: free starts at once; starter, growth, pro or scale prints a checkout link for the human to pay at. Run it only on the human's explicit choice"
|
|
4193
|
+
).option("--yearly", "a paid plan billed yearly instead of monthly").option(PROFILE_FLAG, PROFILE_HELP).action(
|
|
4194
|
+
(plan, options) => run(
|
|
4195
|
+
{ command: "plan", plan, options: options.yearly === true ? { yearly: true } : {} },
|
|
4196
|
+
context(options)
|
|
4197
|
+
)
|
|
4124
4198
|
);
|
|
4125
4199
|
askr.command("products").description("Publish products from a JSON or CSV file (source admin)").requiredOption("--file <path>", "products.json or products.csv").option(
|
|
4126
4200
|
"--replace",
|
|
@@ -4439,7 +4513,7 @@ async function dispatch(session, invocation) {
|
|
|
4439
4513
|
}
|
|
4440
4514
|
case "plan": {
|
|
4441
4515
|
const { runPlan: runPlan2 } = await Promise.resolve().then(() => (init_plan(), plan_exports));
|
|
4442
|
-
return runPlan2(session, invocation.plan);
|
|
4516
|
+
return runPlan2(session, invocation.plan, invocation.options);
|
|
4443
4517
|
}
|
|
4444
4518
|
case "products": {
|
|
4445
4519
|
const { runProducts: runProducts2 } = await Promise.resolve().then(() => (init_products(), products_exports));
|