notusci 0.1.10 → 0.1.11
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/package.json +1 -1
- package/src/cli.mjs +6 -2
- package/src/core.mjs +12 -3
package/package.json
CHANGED
package/src/cli.mjs
CHANGED
|
@@ -63,12 +63,16 @@ async function api(s, path, { method = "GET", query = {}, body, bearer = s.token
|
|
|
63
63
|
if (body !== undefined) headers["content-type"] = "application/json";
|
|
64
64
|
let response;
|
|
65
65
|
let text = "";
|
|
66
|
+
let waited = false;
|
|
66
67
|
for (let attempt = 0; ; attempt++) {
|
|
67
68
|
const timeoutMs = Math.max(1000, Math.min(timeoutSeconds * 1000, deadline - Date.now()));
|
|
68
69
|
try {
|
|
69
70
|
response = await fetch(url, { method, headers, body: typeof body === "string" || body === undefined ? body : JSON.stringify(body),
|
|
70
71
|
signal: AbortSignal.timeout(timeoutMs) });
|
|
71
72
|
text = await response.text();
|
|
73
|
+
// Rate limited: wait once as told, then report (spec 071).
|
|
74
|
+
const wait = Math.min(60, Number(response.headers.get("retry-after")) || 60) * 1000;
|
|
75
|
+
if (response.status === 429 && !waited && Date.now() + wait < deadline) { waited = true; await sleep(wait); continue; }
|
|
72
76
|
if (response.status < 500 || attempt === 2) break;
|
|
73
77
|
} catch {
|
|
74
78
|
if (attempt === 2 || Date.now() >= deadline) throw new CliError({ code: "network", error: `Cannot reach NotusCI at ${s.url}`, next: "Retry the same command." });
|
|
@@ -221,7 +225,7 @@ async function init(s, input) {
|
|
|
221
225
|
print({ status: "ready", user: me.user, repo: listed(me, repo).repo, scopes: me.scopes, workflow, mcp, next: `${NPX} verify` });
|
|
222
226
|
}
|
|
223
227
|
|
|
224
|
-
/** @param {Session} s @param {{repo?: string, timeoutSeconds: number}} input */
|
|
228
|
+
/** @param {Session} s @param {{repo?: string, timeoutSeconds: number, interval?: "month" | "year"}} input */
|
|
225
229
|
async function billing(s, input) {
|
|
226
230
|
const repo = repoOrOrigin(input.repo);
|
|
227
231
|
const deadline = Date.now() + input.timeoutSeconds * 1000;
|
|
@@ -232,7 +236,7 @@ async function billing(s, input) {
|
|
|
232
236
|
}
|
|
233
237
|
let action = s.state.billing;
|
|
234
238
|
if (!action || action.repo.toLowerCase() !== repo.toLowerCase() || new Date(action.expiresAt).getTime() <= Date.now()) {
|
|
235
|
-
action = { ...await api(s, "/api/billing/checkouts", { method: "POST", body: { repo }, deadline }), repo };
|
|
239
|
+
action = { ...await api(s, "/api/billing/checkouts", { method: "POST", body: { repo, ...(input.interval ? { interval: input.interval } : {}) }, deadline }), repo };
|
|
236
240
|
save(s, { token: s.state.token, pending: s.state.pending, billing: action });
|
|
237
241
|
}
|
|
238
242
|
while (Date.now() + 2_000 <= deadline) {
|
package/src/core.mjs
CHANGED
|
@@ -43,14 +43,14 @@ const OPTIONS = {
|
|
|
43
43
|
approve: { repo: { type: "string" } },
|
|
44
44
|
repo: { repo: { type: "string" }, settings: { type: "string" }, "push-workflow": { type: "string" }, off: { type: "boolean" }, "image-from-workspace": { type: "string" }, "image-from-dockerfile": { type: "boolean" } },
|
|
45
45
|
migrations: { repo: { type: "string" }, push: { type: "string" }, reason: { type: "string" }, "force-destructive": { type: "boolean" } },
|
|
46
|
-
billing: { repo: { type: "string" }, timeout: { type: "string" } },
|
|
46
|
+
billing: { repo: { type: "string" }, timeout: { type: "string" }, yearly: { type: "boolean" } },
|
|
47
47
|
usage: { repo: { type: "string" }, cap: { type: "string" } },
|
|
48
48
|
api: { data: { type: "string" } },
|
|
49
49
|
};
|
|
50
50
|
|
|
51
51
|
export const HELP = {
|
|
52
52
|
commands: [
|
|
53
|
-
"init [--scope SCOPES] [--no-mcp] [--billing]", "billing [--repo OWNER/REPO] [--timeout SECONDS]", "usage [--repo OWNER/REPO] [--cap USD]", "doctor",
|
|
53
|
+
"init [--scope SCOPES] [--no-mcp] [--billing]", "billing [--repo OWNER/REPO] [--yearly] [--timeout SECONDS]", "usage [--repo OWNER/REPO] [--cap USD]", "doctor",
|
|
54
54
|
"login [--scope SCOPES]", "logout", "whoami", "repos", "token list", "token revoke ID",
|
|
55
55
|
"target set [--repo OWNER/REPO] [--file TARGET.json] [--auto-promote on|off] [--auto-release on|off]",
|
|
56
56
|
"secret set NAME [--repo OWNER/REPO] (value on stdin)", "secret list [--repo OWNER/REPO]", "secret rm NAME [--repo OWNER/REPO]",
|
|
@@ -179,7 +179,7 @@ export function parseCommand(args) {
|
|
|
179
179
|
if (values.workflow === "") throw usage("--workflow must not be empty");
|
|
180
180
|
return { command, workflow: values.workflow, timeoutSeconds: timeoutSeconds ?? 540, ...(values["no-reuse"] ? { reuse: false } : {}) };
|
|
181
181
|
}
|
|
182
|
-
if (command === "billing") { expect(); return { command, repo: values.repo, timeoutSeconds: timeoutSeconds ?? 90 }; }
|
|
182
|
+
if (command === "billing") { expect(); return { command, repo: values.repo, timeoutSeconds: timeoutSeconds ?? 90, ...(values.yearly ? { interval: "year" } : {}) }; }
|
|
183
183
|
if (command === "usage") {
|
|
184
184
|
expect(); const capUsd = values.cap === undefined ? undefined : Number(values.cap);
|
|
185
185
|
if (capUsd !== undefined && !(capUsd >= 0)) throw usage("--cap must be a number of dollars, 0 or more");
|
|
@@ -245,6 +245,15 @@ export function renderError({ error = "", code, next, ...extra }, now = Date.now
|
|
|
245
245
|
return { error: "This account's NotusCI minutes are used up (Free: 1,000 a month; the Pro trial: 3,000). Upgrade to Pro to continue.", code,
|
|
246
246
|
next: `${NPX} billing`, ...extra };
|
|
247
247
|
}
|
|
248
|
+
if (code === "card_required") {
|
|
249
|
+
return { error: "This is the GitHub user's third or later free NotusCI account, so it has no free minutes until a card is on file.", code,
|
|
250
|
+
next: `${NPX} billing`, ...extra };
|
|
251
|
+
}
|
|
252
|
+
if (code === "account_suspended") {
|
|
253
|
+
return { error: error || "This NotusCI account is suspended for review.", code,
|
|
254
|
+
next: "Stop. Tell the human the account is suspended and to write to binh@notusworks.com.", ...extra };
|
|
255
|
+
}
|
|
256
|
+
if (code === "rate_limited") return { error, code, next: "Wait a minute before the next call; tell the human if it repeats.", ...extra };
|
|
248
257
|
if (code === "missing_scope") return { error, code, next: `${NPX} login --scope ${String(extra.scopes)}`, ...extra };
|
|
249
258
|
/** @type {Record<string, string>} */
|
|
250
259
|
const defaults = {
|