@elisym/cli 0.37.0 → 0.38.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 +128 -28
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -487,12 +487,35 @@ 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;
|
|
494
|
+
}
|
|
495
|
+
function upgradeOf(billing, adminUrl) {
|
|
496
|
+
if (billing?.enabled !== true || billing.operatorManaged === true) {
|
|
497
|
+
return UPGRADE;
|
|
498
|
+
}
|
|
499
|
+
if (billing.checkoutAvailable) {
|
|
500
|
+
return { ...UPGRADE, howTo: `Run ${PAID_CHECKOUT}` };
|
|
501
|
+
}
|
|
502
|
+
if (billing.manageable) {
|
|
503
|
+
return {
|
|
504
|
+
...UPGRADE,
|
|
505
|
+
howTo: "Change the paid plan under Manage billing in the admin",
|
|
506
|
+
admin: adminUrl
|
|
507
|
+
};
|
|
508
|
+
}
|
|
509
|
+
return UPGRADE;
|
|
491
510
|
}
|
|
492
|
-
function inactiveExit(view, exitCode = EXIT.LIMIT) {
|
|
511
|
+
function inactiveExit(view, adminUrl, exitCode = EXIT.LIMIT) {
|
|
493
512
|
return new AskrExit(exitCode, "inactive", {
|
|
494
513
|
hint: `the store is ${view.status}, not active: ${planHintOf(view)}`,
|
|
495
|
-
fields: {
|
|
514
|
+
fields: {
|
|
515
|
+
status: view.status,
|
|
516
|
+
awaitingPlan: awaitingPlanOf(view),
|
|
517
|
+
upgrade: upgradeOf(view.billing, adminUrl)
|
|
518
|
+
}
|
|
496
519
|
});
|
|
497
520
|
}
|
|
498
521
|
function movedExit(fields) {
|
|
@@ -570,13 +593,15 @@ async function waitPublished(session, first, onStopped) {
|
|
|
570
593
|
function stoppedKinds(view) {
|
|
571
594
|
return view.events.failing.filter((event) => event.stopped).map((event) => event.kind);
|
|
572
595
|
}
|
|
573
|
-
var CHOOSE_PLAN_HINT, CONTACT_HINT, INIT_FIRST_HINT, CLOCK_HINT, UNAUTHORIZED_HINTS, MOVED_HINT;
|
|
596
|
+
var CHOOSE_PLAN_HINT, PAID_CHECKOUT, CHOOSE_PLAN_BILLING_HINT, CONTACT_HINT, INIT_FIRST_HINT, CLOCK_HINT, UNAUTHORIZED_HINTS, MOVED_HINT;
|
|
574
597
|
var init_store = __esm({
|
|
575
598
|
"src/commands/askr/store.ts"() {
|
|
576
599
|
init_constants();
|
|
577
600
|
init_errors();
|
|
578
601
|
init_owner_key();
|
|
579
602
|
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";
|
|
603
|
+
PAID_CHECKOUT = "askr plan <starter|growth|pro|scale> [--yearly] for the paid plan the human chose, then give them its checkoutUrl to pay";
|
|
604
|
+
CHOOSE_PLAN_BILLING_HINT = `choose a plan: askr plan free (only if the human chose Free), or ${PAID_CHECKOUT}`;
|
|
580
605
|
CONTACT_HINT = `message us with your Store ID: ${CONTACT_URL}`;
|
|
581
606
|
INIT_FIRST_HINT = "run askr init first";
|
|
582
607
|
CLOCK_HINT = "check this computer's clock: it is off by more than a minute";
|
|
@@ -1265,14 +1290,14 @@ async function runInit(session, options) {
|
|
|
1265
1290
|
adminUrl: session.adminUrl
|
|
1266
1291
|
};
|
|
1267
1292
|
if (awaitingPlan) {
|
|
1268
|
-
output.next = NEXT_PLAN;
|
|
1269
|
-
output.upgrade =
|
|
1293
|
+
output.next = view.billing?.checkoutAvailable === true ? NEXT_PLAN_BILLING : NEXT_PLAN;
|
|
1294
|
+
output.upgrade = upgradeOf(view.billing, session.adminUrl);
|
|
1270
1295
|
} else if (view.status !== "active") {
|
|
1271
1296
|
output.hint = CONTACT_HINT;
|
|
1272
1297
|
}
|
|
1273
1298
|
return { exitCode: EXIT.OK, output };
|
|
1274
1299
|
}
|
|
1275
|
-
var DEFAULT_LANGUAGE, DEFAULT_CURRENCY, LANGUAGE_RE, CURRENCY_RE, SCHEME_RE, BARE_HOST_RE, MAX_URL_CHARS, NEXT_PLAN, STOPPED_HINT;
|
|
1300
|
+
var DEFAULT_LANGUAGE, DEFAULT_CURRENCY, LANGUAGE_RE, CURRENCY_RE, SCHEME_RE, BARE_HOST_RE, MAX_URL_CHARS, NEXT_PLAN, NEXT_PLAN_BILLING, STOPPED_HINT;
|
|
1276
1301
|
var init_init = __esm({
|
|
1277
1302
|
"src/commands/askr/init.ts"() {
|
|
1278
1303
|
init_constants();
|
|
@@ -1290,6 +1315,7 @@ var init_init = __esm({
|
|
|
1290
1315
|
BARE_HOST_RE = /^[^\s/:]+\.[^\s/:]+(?::\d+)?(?:\/.*)?$/u;
|
|
1291
1316
|
MAX_URL_CHARS = 2048;
|
|
1292
1317
|
NEXT_PLAN = `choose a plan: Free via askr plan free, only if the human chose Free; a paid plan: message us at ${CONTACT_URL} with your Store ID and the name of the plan the human chose`;
|
|
1318
|
+
NEXT_PLAN_BILLING = `choose a plan: Free via askr plan free, only if the human chose Free; a paid plan: ${PAID_CHECKOUT}`;
|
|
1293
1319
|
STOPPED_HINT = "report this to us with your Store ID";
|
|
1294
1320
|
}
|
|
1295
1321
|
});
|
|
@@ -1299,13 +1325,62 @@ var plan_exports = {};
|
|
|
1299
1325
|
__export(plan_exports, {
|
|
1300
1326
|
runPlan: () => runPlan
|
|
1301
1327
|
});
|
|
1302
|
-
async function
|
|
1328
|
+
async function runCheckout(session, plan, options) {
|
|
1329
|
+
const key = await useOwnerKey(session);
|
|
1330
|
+
const interval = options.yearly === true ? "year" : "month";
|
|
1331
|
+
const result = await session.call("POST", "/v1/admin/billing/checkout", {
|
|
1332
|
+
plan,
|
|
1333
|
+
interval
|
|
1334
|
+
});
|
|
1335
|
+
if (!result.ok) {
|
|
1336
|
+
switch (result.code) {
|
|
1337
|
+
case "billing_unavailable":
|
|
1338
|
+
case "plan_unavailable":
|
|
1339
|
+
throw new AskrExit(EXIT.LIMIT, result.code, {
|
|
1340
|
+
hint: `this plan cannot be bought here right now: ${PAID_HINT}`,
|
|
1341
|
+
fields: { upgrade: UPGRADE }
|
|
1342
|
+
});
|
|
1343
|
+
case "subscription_exists":
|
|
1344
|
+
throw new AskrExit(EXIT.REFUSED, "subscription_exists", {
|
|
1345
|
+
hint: `the store already has a paid plan: change it under Manage billing in the admin (${session.adminUrl})`
|
|
1346
|
+
});
|
|
1347
|
+
case "suspended":
|
|
1348
|
+
throw new AskrExit(EXIT.REFUSED, "suspended", {
|
|
1349
|
+
hint: `the store is suspended: ${CONTACT_HINT}`
|
|
1350
|
+
});
|
|
1351
|
+
case "operator_managed":
|
|
1352
|
+
throw new AskrExit(EXIT.REFUSED, "operator_managed", {
|
|
1353
|
+
hint: `we manage this store's plan: ${CONTACT_HINT}`
|
|
1354
|
+
});
|
|
1355
|
+
default:
|
|
1356
|
+
throw refusalExit(session, result);
|
|
1357
|
+
}
|
|
1358
|
+
}
|
|
1359
|
+
return {
|
|
1360
|
+
exitCode: EXIT.OK,
|
|
1361
|
+
output: {
|
|
1362
|
+
ok: true,
|
|
1363
|
+
storeId: key.storeId,
|
|
1364
|
+
plan,
|
|
1365
|
+
interval,
|
|
1366
|
+
checkoutUrl: result.body.url,
|
|
1367
|
+
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"
|
|
1368
|
+
}
|
|
1369
|
+
};
|
|
1370
|
+
}
|
|
1371
|
+
async function runPlan(session, plan, options = {}) {
|
|
1372
|
+
if (PAID_PLANS.includes(plan)) {
|
|
1373
|
+
return runCheckout(session, plan, options);
|
|
1374
|
+
}
|
|
1303
1375
|
if (plan !== FREE) {
|
|
1304
|
-
throw new AskrExit(EXIT.BAD_INPUT, "
|
|
1305
|
-
hint: "
|
|
1376
|
+
throw new AskrExit(EXIT.BAD_INPUT, "unknown_plan", {
|
|
1377
|
+
hint: "plans: free, starter, growth, pro, scale (Enterprise: message us with your Store ID)",
|
|
1306
1378
|
fields: { upgrade: UPGRADE }
|
|
1307
1379
|
});
|
|
1308
1380
|
}
|
|
1381
|
+
if (options.yearly === true) {
|
|
1382
|
+
throw new AskrExit(EXIT.BAD_INPUT, "bad_flag", { hint: "--yearly is for a paid plan" });
|
|
1383
|
+
}
|
|
1309
1384
|
const key = await useOwnerKey(session);
|
|
1310
1385
|
const result = await session.call(
|
|
1311
1386
|
"POST",
|
|
@@ -1370,13 +1445,15 @@ async function runPlan(session, plan) {
|
|
|
1370
1445
|
}
|
|
1371
1446
|
};
|
|
1372
1447
|
}
|
|
1373
|
-
var FREE;
|
|
1448
|
+
var FREE, PAID_PLANS, PAID_HINT;
|
|
1374
1449
|
var init_plan = __esm({
|
|
1375
1450
|
"src/commands/askr/plan.ts"() {
|
|
1376
1451
|
init_constants();
|
|
1377
1452
|
init_errors();
|
|
1378
1453
|
init_store();
|
|
1379
1454
|
FREE = "free";
|
|
1455
|
+
PAID_PLANS = ["starter", "growth", "pro", "scale"];
|
|
1456
|
+
PAID_HINT = "paid plans: message us with your Store ID";
|
|
1380
1457
|
}
|
|
1381
1458
|
});
|
|
1382
1459
|
|
|
@@ -1519,7 +1596,7 @@ async function runProducts(session, options) {
|
|
|
1519
1596
|
const view = await readView(session);
|
|
1520
1597
|
const localDryRun = options.dryRun === true && view.status === "pending";
|
|
1521
1598
|
if (view.status !== "active" && !localDryRun) {
|
|
1522
|
-
throw inactiveExit(view);
|
|
1599
|
+
throw inactiveExit(view, session.adminUrl);
|
|
1523
1600
|
}
|
|
1524
1601
|
const { config } = await readSigned(session, key.owner, key.secretKey);
|
|
1525
1602
|
if (config === void 0) {
|
|
@@ -1686,7 +1763,10 @@ var init_products = __esm({
|
|
|
1686
1763
|
case "too_many_products":
|
|
1687
1764
|
return new AskrExit(EXIT.LIMIT, "too_many_products", {
|
|
1688
1765
|
hint: "more products than the store's plan allows",
|
|
1689
|
-
fields: {
|
|
1766
|
+
fields: {
|
|
1767
|
+
max: result.detail.max,
|
|
1768
|
+
upgrade: upgradeOf(this.view.billing, this.session.adminUrl)
|
|
1769
|
+
}
|
|
1690
1770
|
});
|
|
1691
1771
|
case "invalid_items":
|
|
1692
1772
|
return new AskrExit(EXIT.BAD_INPUT, "invalid_items", {
|
|
@@ -1695,7 +1775,7 @@ var init_products = __esm({
|
|
|
1695
1775
|
}
|
|
1696
1776
|
});
|
|
1697
1777
|
case "inactive":
|
|
1698
|
-
return inactiveExit(this.view);
|
|
1778
|
+
return inactiveExit(this.view, this.session.adminUrl);
|
|
1699
1779
|
case "bad_request":
|
|
1700
1780
|
return new AskrExit(EXIT.BAD_INPUT, "bad_request", {
|
|
1701
1781
|
...typeof result.detail.message === "string" ? { message: result.detail.message } : {}
|
|
@@ -1792,7 +1872,7 @@ async function runPolicy(session, options) {
|
|
|
1792
1872
|
const key = await useOwnerKey(session);
|
|
1793
1873
|
const view = await readView(session);
|
|
1794
1874
|
if (view.status !== "active") {
|
|
1795
|
-
throw inactiveExit(view);
|
|
1875
|
+
throw inactiveExit(view, session.adminUrl);
|
|
1796
1876
|
}
|
|
1797
1877
|
const { config } = await readSigned(session, key.owner, key.secretKey);
|
|
1798
1878
|
if (config === void 0) {
|
|
@@ -1842,7 +1922,7 @@ async function runPolicy(session, options) {
|
|
|
1842
1922
|
hint: "a store has at most 50 policies: remove one in the admin"
|
|
1843
1923
|
});
|
|
1844
1924
|
case "inactive":
|
|
1845
|
-
throw inactiveExit(view);
|
|
1925
|
+
throw inactiveExit(view, session.adminUrl);
|
|
1846
1926
|
case "bad_request":
|
|
1847
1927
|
throw new AskrExit(EXIT.BAD_INPUT, "bad_request");
|
|
1848
1928
|
default:
|
|
@@ -1907,7 +1987,7 @@ var connector_exports = {};
|
|
|
1907
1987
|
__export(connector_exports, {
|
|
1908
1988
|
runConnector: () => runConnector
|
|
1909
1989
|
});
|
|
1910
|
-
function resultExit(summary, detail) {
|
|
1990
|
+
function resultExit(summary, detail, upgrade) {
|
|
1911
1991
|
if (summary.status === "ok") {
|
|
1912
1992
|
return void 0;
|
|
1913
1993
|
}
|
|
@@ -1920,7 +2000,7 @@ function resultExit(summary, detail) {
|
|
|
1920
2000
|
if (summary.reason === "too_many_products") {
|
|
1921
2001
|
return new AskrExit(EXIT.LIMIT, "too_many_products", {
|
|
1922
2002
|
hint: "the shop has more products than the store's plan allows",
|
|
1923
|
-
fields: { count: summary.count, max: summary.max, upgrade
|
|
2003
|
+
fields: { count: summary.count, max: summary.max, upgrade }
|
|
1924
2004
|
});
|
|
1925
2005
|
}
|
|
1926
2006
|
if (summary.status === "source_closed") {
|
|
@@ -1972,7 +2052,7 @@ function noConnectorExit() {
|
|
|
1972
2052
|
}
|
|
1973
2053
|
function actionRefusal(session, view, result) {
|
|
1974
2054
|
if (!result.ok && result.code === "inactive") {
|
|
1975
|
-
return inactiveExit(view);
|
|
2055
|
+
return inactiveExit(view, session.adminUrl);
|
|
1976
2056
|
}
|
|
1977
2057
|
if (!result.ok && result.code === "no_connector") {
|
|
1978
2058
|
return noConnectorExit();
|
|
@@ -1983,7 +2063,7 @@ async function runConnector(session) {
|
|
|
1983
2063
|
const key = await useOwnerKey(session);
|
|
1984
2064
|
const view = await readView(session);
|
|
1985
2065
|
if (view.status !== "active" || view.tier === null) {
|
|
1986
|
-
throw inactiveExit(view);
|
|
2066
|
+
throw inactiveExit(view, session.adminUrl);
|
|
1987
2067
|
}
|
|
1988
2068
|
const connector = view.connector;
|
|
1989
2069
|
if (connector === null) {
|
|
@@ -2013,7 +2093,8 @@ async function runConnector(session) {
|
|
|
2013
2093
|
if (previewed === null) {
|
|
2014
2094
|
throw new AskrExit(EXIT.REFUSED, "unexpected");
|
|
2015
2095
|
}
|
|
2016
|
-
const
|
|
2096
|
+
const upgrade = upgradeOf(view.billing, session.adminUrl);
|
|
2097
|
+
const previewExit = resultExit(previewed, failuresOf(preview.body.result), upgrade);
|
|
2017
2098
|
if (previewExit !== void 0) {
|
|
2018
2099
|
throw previewExit;
|
|
2019
2100
|
}
|
|
@@ -2044,7 +2125,7 @@ async function runConnector(session) {
|
|
|
2044
2125
|
fields: { retryAfterSeconds: 60 }
|
|
2045
2126
|
});
|
|
2046
2127
|
}
|
|
2047
|
-
const runExit = run === null ? void 0 : resultExit(run, failuresOf(current.lastStatus));
|
|
2128
|
+
const runExit = run === null ? void 0 : resultExit(run, failuresOf(current.lastStatus), upgrade);
|
|
2048
2129
|
if (runExit !== void 0) {
|
|
2049
2130
|
throw runExit;
|
|
2050
2131
|
}
|
|
@@ -2096,6 +2177,21 @@ function money(value) {
|
|
|
2096
2177
|
return "0";
|
|
2097
2178
|
}
|
|
2098
2179
|
}
|
|
2180
|
+
function billingOf(view) {
|
|
2181
|
+
const billing = view.billing;
|
|
2182
|
+
if (billing === void 0) {
|
|
2183
|
+
return null;
|
|
2184
|
+
}
|
|
2185
|
+
return {
|
|
2186
|
+
enabled: billing.enabled,
|
|
2187
|
+
plan: billing.plan,
|
|
2188
|
+
interval: billing.interval,
|
|
2189
|
+
status: billing.status,
|
|
2190
|
+
currentPeriodEnd: billing.currentPeriodEnd,
|
|
2191
|
+
cancelAtPeriodEnd: billing.cancelAtPeriodEnd,
|
|
2192
|
+
checkoutAvailable: billing.checkoutAvailable
|
|
2193
|
+
};
|
|
2194
|
+
}
|
|
2099
2195
|
function connectorOf(view) {
|
|
2100
2196
|
const connector = view.connector;
|
|
2101
2197
|
if (connector === null) {
|
|
@@ -2245,9 +2341,10 @@ async function runStatus(session, options) {
|
|
|
2245
2341
|
todaySpentUsd: money(view.usage.today.spent),
|
|
2246
2342
|
monthSpentUsd: money(view.usage.month.spent)
|
|
2247
2343
|
},
|
|
2344
|
+
billing: billingOf(view),
|
|
2248
2345
|
ownerKeyFile: key.path,
|
|
2249
2346
|
adminUrl: session.adminUrl,
|
|
2250
|
-
upgrade:
|
|
2347
|
+
upgrade: upgradeOf(view.billing, session.adminUrl)
|
|
2251
2348
|
};
|
|
2252
2349
|
if (view.status !== "active") {
|
|
2253
2350
|
output.hint = planHintOf(view);
|
|
@@ -2278,7 +2375,7 @@ var init_status = __esm({
|
|
|
2278
2375
|
init_owner_key();
|
|
2279
2376
|
init_read();
|
|
2280
2377
|
init_store();
|
|
2281
|
-
BUDGET_HINT = "the store reached its plan's monthly limit, so the chat does not answer until the plan is upgraded or the next month starts: to upgrade,
|
|
2378
|
+
BUDGET_HINT = "the store reached its plan's monthly limit, so the chat does not answer until the plan is upgraded or the next month starts: to upgrade, follow upgrade.howTo";
|
|
2282
2379
|
}
|
|
2283
2380
|
});
|
|
2284
2381
|
function storeLlmsTxtUrl(npub) {
|
|
@@ -4118,9 +4215,12 @@ function registerAskr(program2, run, args, jsonErrors) {
|
|
|
4118
4215
|
(options) => run({ command: "init", options }, context(options))
|
|
4119
4216
|
);
|
|
4120
4217
|
askr.command("plan <plan>").description(
|
|
4121
|
-
"Choose a plan:
|
|
4122
|
-
).option(PROFILE_FLAG, PROFILE_HELP).action(
|
|
4123
|
-
(plan, options) => run(
|
|
4218
|
+
"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"
|
|
4219
|
+
).option("--yearly", "a paid plan billed yearly instead of monthly").option(PROFILE_FLAG, PROFILE_HELP).action(
|
|
4220
|
+
(plan, options) => run(
|
|
4221
|
+
{ command: "plan", plan, options: options.yearly === true ? { yearly: true } : {} },
|
|
4222
|
+
context(options)
|
|
4223
|
+
)
|
|
4124
4224
|
);
|
|
4125
4225
|
askr.command("products").description("Publish products from a JSON or CSV file (source admin)").requiredOption("--file <path>", "products.json or products.csv").option(
|
|
4126
4226
|
"--replace",
|
|
@@ -4439,7 +4539,7 @@ async function dispatch(session, invocation) {
|
|
|
4439
4539
|
}
|
|
4440
4540
|
case "plan": {
|
|
4441
4541
|
const { runPlan: runPlan2 } = await Promise.resolve().then(() => (init_plan(), plan_exports));
|
|
4442
|
-
return runPlan2(session, invocation.plan);
|
|
4542
|
+
return runPlan2(session, invocation.plan, invocation.options);
|
|
4443
4543
|
}
|
|
4444
4544
|
case "products": {
|
|
4445
4545
|
const { runProducts: runProducts2 } = await Promise.resolve().then(() => (init_products(), products_exports));
|