@elisym/cli 0.35.0 → 0.36.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 +68 -11
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -493,8 +493,11 @@ function inactiveExit(view, exitCode = EXIT.LIMIT) {
|
|
|
493
493
|
fields: { status: view.status, awaitingPlan: awaitingPlanOf(view), upgrade: UPGRADE }
|
|
494
494
|
});
|
|
495
495
|
}
|
|
496
|
-
function movedExit() {
|
|
497
|
-
return new AskrExit(EXIT.REFUSED, "moved_store", {
|
|
496
|
+
function movedExit(fields) {
|
|
497
|
+
return new AskrExit(EXIT.REFUSED, "moved_store", {
|
|
498
|
+
hint: MOVED_HINT,
|
|
499
|
+
...fields === void 0 ? {} : { fields }
|
|
500
|
+
});
|
|
498
501
|
}
|
|
499
502
|
function serverMessage(result) {
|
|
500
503
|
if (result.ok) {
|
|
@@ -1261,6 +1264,7 @@ async function runInit(session, options) {
|
|
|
1261
1264
|
};
|
|
1262
1265
|
if (awaitingPlan) {
|
|
1263
1266
|
output.next = NEXT_PLAN;
|
|
1267
|
+
output.upgrade = UPGRADE;
|
|
1264
1268
|
} else if (view.status !== "active") {
|
|
1265
1269
|
output.hint = CONTACT_HINT;
|
|
1266
1270
|
}
|
|
@@ -1269,6 +1273,7 @@ async function runInit(session, options) {
|
|
|
1269
1273
|
var DEFAULT_LANGUAGE, DEFAULT_CURRENCY, LANGUAGE_RE, CURRENCY_RE, SCHEME_RE, BARE_HOST_RE, MAX_URL_CHARS, NEXT_PLAN, STOPPED_HINT;
|
|
1270
1274
|
var init_init = __esm({
|
|
1271
1275
|
"src/commands/askr/init.ts"() {
|
|
1276
|
+
init_constants();
|
|
1272
1277
|
init_errors();
|
|
1273
1278
|
init_files();
|
|
1274
1279
|
init_owner_key();
|
|
@@ -1282,7 +1287,7 @@ var init_init = __esm({
|
|
|
1282
1287
|
SCHEME_RE = /^[a-z][a-z0-9+.-]*:\/\//iu;
|
|
1283
1288
|
BARE_HOST_RE = /^[^\s/:]+\.[^\s/:]+(?::\d+)?(?:\/.*)?$/u;
|
|
1284
1289
|
MAX_URL_CHARS = 2048;
|
|
1285
|
-
NEXT_PLAN =
|
|
1290
|
+
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`;
|
|
1286
1291
|
STOPPED_HINT = "report this to us with your Store ID";
|
|
1287
1292
|
}
|
|
1288
1293
|
});
|
|
@@ -1446,8 +1451,25 @@ async function readProductsFile(session, path) {
|
|
|
1446
1451
|
if (issues.length > 0) {
|
|
1447
1452
|
throw invalidFile("fix these products and run again", { issues: issues.slice(0, MAX_ISSUES) });
|
|
1448
1453
|
}
|
|
1454
|
+
const repeated = repeatedIds(items);
|
|
1455
|
+
if (repeated.length > 0) {
|
|
1456
|
+
throw invalidFile("each product needs its own d: these ids are used more than once", {
|
|
1457
|
+
repeated: repeated.slice(0, MAX_ISSUES)
|
|
1458
|
+
});
|
|
1459
|
+
}
|
|
1449
1460
|
return { format: "json", items };
|
|
1450
1461
|
}
|
|
1462
|
+
function repeatedIds(items) {
|
|
1463
|
+
const seen = /* @__PURE__ */ new Set();
|
|
1464
|
+
const repeated = /* @__PURE__ */ new Set();
|
|
1465
|
+
for (const item of items) {
|
|
1466
|
+
if (seen.has(item.d)) {
|
|
1467
|
+
repeated.add(item.d);
|
|
1468
|
+
}
|
|
1469
|
+
seen.add(item.d);
|
|
1470
|
+
}
|
|
1471
|
+
return [...repeated];
|
|
1472
|
+
}
|
|
1451
1473
|
function itemsOfCsv(session, text, currency) {
|
|
1452
1474
|
const imported = session.askr.productsFromCsv(text, currency);
|
|
1453
1475
|
if (imported.fileErrors.length > 0) {
|
|
@@ -1493,7 +1515,8 @@ async function runProducts(session, options) {
|
|
|
1493
1515
|
const file = await readProductsFile(session, options.file);
|
|
1494
1516
|
const key = await useOwnerKey(session);
|
|
1495
1517
|
const view = await readView(session);
|
|
1496
|
-
|
|
1518
|
+
const localDryRun = options.dryRun === true && view.status === "pending";
|
|
1519
|
+
if (view.status !== "active" && !localDryRun) {
|
|
1497
1520
|
throw inactiveExit(view);
|
|
1498
1521
|
}
|
|
1499
1522
|
const { config } = await readSigned(session, key.owner, key.secretKey);
|
|
@@ -1523,6 +1546,10 @@ async function runProducts(session, options) {
|
|
|
1523
1546
|
if (linkWarnings.length > 0) {
|
|
1524
1547
|
extra.urlWarnings = linkWarnings.slice(0, SAMPLE_SIZE);
|
|
1525
1548
|
}
|
|
1549
|
+
if (localDryRun) {
|
|
1550
|
+
const local = await localDiff(session, view.catalogKey, items, mode);
|
|
1551
|
+
return { exitCode: EXIT.OK, output: { ...summary, ...local, ...extra } };
|
|
1552
|
+
}
|
|
1526
1553
|
for (; ; ) {
|
|
1527
1554
|
const diff = await flow.dryRun();
|
|
1528
1555
|
if (mode === "upsert" && extra.warning === void 0) {
|
|
@@ -1566,6 +1593,22 @@ async function runProducts(session, options) {
|
|
|
1566
1593
|
};
|
|
1567
1594
|
}
|
|
1568
1595
|
}
|
|
1596
|
+
async function localDiff(session, catalogKey, items, mode) {
|
|
1597
|
+
const { listed } = await readListings(session, catalogKey);
|
|
1598
|
+
const inFile = new Set(items.map((item) => item.d));
|
|
1599
|
+
const listedIds = new Set(listed);
|
|
1600
|
+
const created = items.filter((item) => !listedIds.has(item.d)).map((item) => item.d);
|
|
1601
|
+
const hidden = mode === "replace" ? listed.filter((d) => !inFile.has(d)) : [];
|
|
1602
|
+
return {
|
|
1603
|
+
checked: "local",
|
|
1604
|
+
published: false,
|
|
1605
|
+
created: created.length,
|
|
1606
|
+
alreadyListed: items.length - created.length,
|
|
1607
|
+
hidden: hidden.length,
|
|
1608
|
+
sample: { created: created.slice(0, SAMPLE_SIZE), hidden: hidden.slice(0, SAMPLE_SIZE) },
|
|
1609
|
+
note: "the store is pending: the file is valid and nothing was published; once the plan is active, run this line again without --dry-run (the server then also checks the plan's product limit)"
|
|
1610
|
+
};
|
|
1611
|
+
}
|
|
1569
1612
|
function countsOf(diff) {
|
|
1570
1613
|
return {
|
|
1571
1614
|
created: diff.created.length,
|
|
@@ -2041,6 +2084,7 @@ var init_connector = __esm({
|
|
|
2041
2084
|
// src/commands/askr/status.ts
|
|
2042
2085
|
var status_exports = {};
|
|
2043
2086
|
__export(status_exports, {
|
|
2087
|
+
BUDGET_HINT: () => BUDGET_HINT,
|
|
2044
2088
|
runStatus: () => runStatus
|
|
2045
2089
|
});
|
|
2046
2090
|
function money(value) {
|
|
@@ -2106,8 +2150,8 @@ async function probe(session, view, origin) {
|
|
|
2106
2150
|
await session.sleep(PROBE_RETRY_MS);
|
|
2107
2151
|
}
|
|
2108
2152
|
}
|
|
2109
|
-
function probeExit(session, view, probed,
|
|
2110
|
-
const fields = {
|
|
2153
|
+
function probeExit(session, view, probed, status) {
|
|
2154
|
+
const fields = { ...status, probe: probed };
|
|
2111
2155
|
switch (probed.result) {
|
|
2112
2156
|
case "ok":
|
|
2113
2157
|
return void 0;
|
|
@@ -2130,15 +2174,21 @@ function probeExit(session, view, probed, storeId) {
|
|
|
2130
2174
|
return new AskrExit(EXIT.REFUSED, "inactive", { hint: planHintOf(view), fields });
|
|
2131
2175
|
case "budget":
|
|
2132
2176
|
return new AskrExit(EXIT.LIMIT, "budget", {
|
|
2133
|
-
hint:
|
|
2134
|
-
fields
|
|
2177
|
+
hint: BUDGET_HINT,
|
|
2178
|
+
fields
|
|
2135
2179
|
});
|
|
2136
2180
|
case "moved":
|
|
2137
|
-
return movedExit();
|
|
2181
|
+
return movedExit(fields);
|
|
2138
2182
|
default:
|
|
2139
2183
|
return new AskrExit(EXIT.REFUSED, "probe_failed", { fields });
|
|
2140
2184
|
}
|
|
2141
2185
|
}
|
|
2186
|
+
function skippedProbe(view) {
|
|
2187
|
+
return view.status === "pending" ? {
|
|
2188
|
+
result: "skipped",
|
|
2189
|
+
reason: "the store is pending: the chat is not served until its plan is active"
|
|
2190
|
+
} : { result: "skipped", reason: "the store lists no origin" };
|
|
2191
|
+
}
|
|
2142
2192
|
async function runStatus(session, options) {
|
|
2143
2193
|
const key = await readOwnerKey(session.deps.home, session.profile);
|
|
2144
2194
|
if (key === void 0) {
|
|
@@ -2200,18 +2250,24 @@ async function runStatus(session, options) {
|
|
|
2200
2250
|
if (view.status !== "active") {
|
|
2201
2251
|
output.hint = planHintOf(view);
|
|
2202
2252
|
}
|
|
2253
|
+
if (options.probe !== true) {
|
|
2254
|
+
return { exitCode: EXIT.OK, output };
|
|
2255
|
+
}
|
|
2203
2256
|
const origin = config?.origins[0];
|
|
2204
|
-
if (
|
|
2257
|
+
if (view.status === "pending" || origin === void 0) {
|
|
2258
|
+
output.probe = skippedProbe(view);
|
|
2205
2259
|
return { exitCode: EXIT.OK, output };
|
|
2206
2260
|
}
|
|
2207
2261
|
const probed = await probe(session, view, origin);
|
|
2208
2262
|
output.probe = probed;
|
|
2209
|
-
const
|
|
2263
|
+
const status = Object.fromEntries(Object.entries(output).filter(([name]) => name !== "ok"));
|
|
2264
|
+
const failed = probeExit(session, view, probed, status);
|
|
2210
2265
|
if (failed !== void 0) {
|
|
2211
2266
|
throw failed;
|
|
2212
2267
|
}
|
|
2213
2268
|
return { exitCode: EXIT.OK, output };
|
|
2214
2269
|
}
|
|
2270
|
+
var BUDGET_HINT;
|
|
2215
2271
|
var init_status = __esm({
|
|
2216
2272
|
"src/commands/askr/status.ts"() {
|
|
2217
2273
|
init_connector_run();
|
|
@@ -2220,6 +2276,7 @@ var init_status = __esm({
|
|
|
2220
2276
|
init_owner_key();
|
|
2221
2277
|
init_read();
|
|
2222
2278
|
init_store();
|
|
2279
|
+
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, message us with your Store ID (upgrade.contact)";
|
|
2223
2280
|
}
|
|
2224
2281
|
});
|
|
2225
2282
|
|