@ptkl/toolkit 1.4.1 → 1.4.2
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/README.md +1 -1
- package/dist/commands/forge.js +1 -1
- package/dist/commands/functions.js +1 -2
- package/dist/commands/index.js +0 -2
- package/dist/commands/kortex.js +1 -1
- package/dist/commands/project.js +1 -32
- package/dist/commands/template.js +1 -2
- package/package.json +1 -1
- package/dist/commands/billing.js +0 -111
package/README.md
CHANGED
|
@@ -121,7 +121,7 @@ Default scope is a least-privilege toolkit preset (`src/lib/oauth/ScopePreset.ts
|
|
|
121
121
|
|
|
122
122
|
Access tokens (15 min) refresh transparently when a command starts, serialized across processes by a per-profile lock in `~/.ptkl` (the rotated refresh token is saved); long-running commands such as watch modes refresh only at start. If the session expired or was revoked you are asked to log in again. `profile inspect` masks tokens.
|
|
123
123
|
|
|
124
|
-
Not available with OAuth profiles (routes OAuth does not admit; the CLI says so on a 403): workflow, sandbox, kortex, integration(s), satellite,
|
|
124
|
+
Not available with OAuth profiles (routes OAuth does not admit; the CLI says so on a 403): workflow, sandbox, kortex, integration(s), satellite, logs, forge, project administration, and user and role changes unless you `--add-scope "edit base_users"`. Use a `--legacy` profile for these.
|
|
125
125
|
|
|
126
126
|
## Using the --profile Flag
|
|
127
127
|
|
package/dist/commands/forge.js
CHANGED
|
@@ -279,7 +279,7 @@ class ForgeCommand {
|
|
|
279
279
|
// `services`/`variables`/`run` are wrapped named methods on the v0.10 `Forge` client;
|
|
280
280
|
// `domains` has no named methods yet, so it goes through the client's underlying
|
|
281
281
|
// authenticated AxiosInstance (`.client`, a public property on every SDK client) — the same
|
|
282
|
-
// stopgap pattern used by `ptkl functions create
|
|
282
|
+
// stopgap pattern used by `ptkl functions create`.
|
|
283
283
|
.addCommand(registerCommand(new Command("services")
|
|
284
284
|
.description("List services declared by a Forge app")
|
|
285
285
|
.argument("<ref>", "App reference (uuid or name)")).action(withProfile(async (profile, ref) => {
|
|
@@ -9,8 +9,7 @@ import { registerCommand, withProfile } from "../lib/scaffold.js";
|
|
|
9
9
|
* supports POST for creation, but the v0.10 `Functions` client does not yet wrap that in a named
|
|
10
10
|
* method — `create` goes through the same authenticated client instance's underlying `.client`
|
|
11
11
|
* (a public AxiosInstance, see @ptkl/sdk/beta BaseClient) rather than a named method, the same
|
|
12
|
-
* stopgap pattern
|
|
13
|
-
* to give `Functions` a `create()` method.
|
|
12
|
+
* stopgap pattern, pending a follow-up SDK WP to give `Functions` a `create()` method.
|
|
14
13
|
*
|
|
15
14
|
* Return-shape contract: every subcommand here resolves to the *payload*, never a raw
|
|
16
15
|
* AxiosResponse. `Functions.run()` already unwraps `.data` in the SDK; `list`/`get`/`update`/
|
package/dist/commands/index.js
CHANGED
|
@@ -20,7 +20,6 @@ import config from "./config.js";
|
|
|
20
20
|
import ratchet from "./ratchet.js";
|
|
21
21
|
import thunder from "./thunder.js";
|
|
22
22
|
import sandbox from "./sandbox.js";
|
|
23
|
-
import billing from "./billing.js";
|
|
24
23
|
import integration from "./integration.js";
|
|
25
24
|
import satellite from "./satellite.js";
|
|
26
25
|
export const commands = [
|
|
@@ -42,7 +41,6 @@ export const commands = [
|
|
|
42
41
|
ratchet.register(),
|
|
43
42
|
thunder.register(),
|
|
44
43
|
sandbox.register(),
|
|
45
|
-
billing.register(),
|
|
46
44
|
integration.register(),
|
|
47
45
|
satellite.register(),
|
|
48
46
|
kortex.register(),
|
package/dist/commands/kortex.js
CHANGED
|
@@ -74,7 +74,7 @@ class KortexCommand {
|
|
|
74
74
|
.requiredOption('--amount <amount>', 'Amount of credits to add')
|
|
75
75
|
.option('-r, --reason <reason>', 'Reason for the top-up')).action(withProfile(async (profile, opts) => {
|
|
76
76
|
// No dedicated `topUp` method exists on the SDK `Kortex` client yet — reuse its
|
|
77
|
-
// authenticated axios instance
|
|
77
|
+
// authenticated axios instance
|
|
78
78
|
// instead of hand-rolling a raw axios call.
|
|
79
79
|
const client = kortexClient(profile);
|
|
80
80
|
const res = await client.client.post(`/luma/kortex/v1/user-access/${opts.uuid}/top-up`, {
|
package/dist/commands/project.js
CHANGED
|
@@ -2,12 +2,7 @@ import { Command } from "commander";
|
|
|
2
2
|
import * as sdk from "../lib/sdk.js";
|
|
3
3
|
import { registerCommand, withProfile } from "../lib/scaffold.js";
|
|
4
4
|
/** `ptkl project` — project/workspace/invite/user control-plane (RFC §6, "Project control-plane").
|
|
5
|
-
* Maps 1:1 onto the SDK `Project` client (@ptkl/sdk/beta)
|
|
6
|
-
* which the platform exposes (platform-api/internal/project/controllers/{billing_modes,edit_auto_topup_settings}.go)
|
|
7
|
-
* but the v0.10 `Project` client does not yet wrap in typed methods. Those two subcommands go
|
|
8
|
-
* through the same authenticated client instance's underlying `.client` (a public AxiosInstance,
|
|
9
|
-
* see @ptkl/sdk/beta BaseClient) rather than a named method — a stopgap for a follow-up SDK WP to
|
|
10
|
-
* give `Project` `getBillingModes()/updateBillingModes()/updateAutoTopupSettings()` methods. */
|
|
5
|
+
* Maps 1:1 onto the SDK `Project` client (@ptkl/sdk/beta). */
|
|
11
6
|
function parseJSON(label, raw) {
|
|
12
7
|
try {
|
|
13
8
|
return JSON.parse(raw);
|
|
@@ -67,32 +62,6 @@ class ProjectCommand {
|
|
|
67
62
|
return res.data;
|
|
68
63
|
})));
|
|
69
64
|
cmd.addCommand(this.registerUsers());
|
|
70
|
-
cmd.addCommand(registerCommand(new Command("billing-modes")
|
|
71
|
-
.description("Get or update the project's per-service usage billing mode overrides")
|
|
72
|
-
.option("-s, --set <json>", "Usage billing modes to set, as a JSON object string (e.g. '{\"kortex\":\"credits\"}'); omit to read the current modes")).action(withProfile(async (profile, opts) => {
|
|
73
|
-
const client = sdk.project(profile);
|
|
74
|
-
if (opts.set) {
|
|
75
|
-
const usage_billing_modes = parseJSON("--set", opts.set);
|
|
76
|
-
const res = await client.client.put("/v1/project/billing-modes", { usage_billing_modes });
|
|
77
|
-
return res.data;
|
|
78
|
-
}
|
|
79
|
-
const res = await client.client.get("/v1/project/billing-modes");
|
|
80
|
-
return res.data;
|
|
81
|
-
})));
|
|
82
|
-
cmd.addCommand(registerCommand(new Command("auto-topup")
|
|
83
|
-
.description("Configure automatic balance top-up for the current project")
|
|
84
|
-
.requiredOption("--enabled <enabled>", "Enable or disable auto top-up: true | false")
|
|
85
|
-
.option("--threshold <threshold>", "Balance threshold (in cents) that triggers a top-up", "0")
|
|
86
|
-
.option("--amount <amount>", "Amount (in cents) to top up when triggered", "0")).action(withProfile(async (profile, opts) => {
|
|
87
|
-
const client = sdk.project(profile);
|
|
88
|
-
const body = {
|
|
89
|
-
auto_topup_enabled: opts.enabled === "true",
|
|
90
|
-
auto_topup_threshold: Number(opts.threshold),
|
|
91
|
-
auto_topup_amount: Number(opts.amount),
|
|
92
|
-
};
|
|
93
|
-
const res = await client.client.put("/v1/project/auto-topup-settings", body);
|
|
94
|
-
return res.data;
|
|
95
|
-
})));
|
|
96
65
|
return cmd;
|
|
97
66
|
}
|
|
98
67
|
registerWorkspace() {
|
|
@@ -13,8 +13,7 @@ import { registerCommand, withProfile } from "../lib/scaffold.js";
|
|
|
13
13
|
* (also `account`/`app`/`integration`) redeemed via `POST /v1/project/codes/{code}/redeem` and
|
|
14
14
|
* listed via `GET /v1/project/codes/redeemed` (internal/project/controllers/code_redeem.go,
|
|
15
15
|
* internal/project/domain/code/service.go). The v0.10 `Project` client has no typed method for
|
|
16
|
-
* either route yet, so
|
|
17
|
-
* `auto-topup` — these two subcommands go through the authenticated client instance's public
|
|
16
|
+
* either route yet, so these two subcommands go through the authenticated client instance's public
|
|
18
17
|
* `.client` (an AxiosInstance, see @ptkl/sdk/beta BaseClient) rather than a named method, pending
|
|
19
18
|
* a follow-up SDK WP to give `Project` `redeemCode()`/`listRedeemedCodes()`. */
|
|
20
19
|
function parseJSON(label, raw) {
|
package/package.json
CHANGED
package/dist/commands/billing.js
DELETED
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
import { resolve } from "path";
|
|
2
|
-
import { writeFileSync } from "fs";
|
|
3
|
-
import { Command } from "commander";
|
|
4
|
-
import * as sdk from "../lib/sdk.js";
|
|
5
|
-
import { registerCommand, withEnvOption, withProfile } from "../lib/scaffold.js";
|
|
6
|
-
/** `ptkl billing` — subscriptions, invoices, credits/balance, usage pricing and per-project
|
|
7
|
-
* billing-mode overrides (RFC §6 "Billing": `subscriptions invoices invoice-pdf balance topup
|
|
8
|
-
* credits prices billing-modes`). Maps onto the SDK `Transactions` client (@ptkl/sdk/beta),
|
|
9
|
-
* reached via `platform.billing()` (an alias of `platform.transactions()`) — the
|
|
10
|
-
* `transactions/…` gateway prefix. This is the **billing** service, not distributed/database
|
|
11
|
-
* transactions (see RFC §5(c)). */
|
|
12
|
-
function parseJSON(label, raw) {
|
|
13
|
-
try {
|
|
14
|
-
return JSON.parse(raw);
|
|
15
|
-
}
|
|
16
|
-
catch {
|
|
17
|
-
console.error(`${label} must be valid JSON`);
|
|
18
|
-
process.exit(1);
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
class BillingCommand {
|
|
22
|
-
register() {
|
|
23
|
-
const cmd = new Command("billing").description("Manage billing: subscriptions, invoices, balance/credits and pricing");
|
|
24
|
-
cmd.addCommand(registerCommand(new Command("subscriptions").description("List all subscriptions (including expired) for the current project")).action(withProfile(async (profile) => {
|
|
25
|
-
const res = await sdk.platform(profile).billing().getSubscriptions();
|
|
26
|
-
return res.data;
|
|
27
|
-
})));
|
|
28
|
-
cmd.addCommand(registerCommand(new Command("invoices")
|
|
29
|
-
.description("List invoices for the current project, or get a single invoice by uuid")
|
|
30
|
-
.argument("[uuid]", "Invoice uuid — omit to list all invoices")).action(withProfile(async (profile, uuid) => {
|
|
31
|
-
const client = sdk.platform(profile).billing();
|
|
32
|
-
const res = uuid ? await client.getInvoice(uuid) : await client.getInvoices();
|
|
33
|
-
return res.data;
|
|
34
|
-
})));
|
|
35
|
-
cmd.addCommand(this.registerInvoicePdf());
|
|
36
|
-
cmd.addCommand(registerCommand(new Command("balance").description("Get the current project's credit balance")).action(withProfile(async (profile) => {
|
|
37
|
-
const res = await sdk.platform(profile).billing().getBalance();
|
|
38
|
-
return res.data;
|
|
39
|
-
})));
|
|
40
|
-
cmd.addCommand(registerCommand(new Command("topup")
|
|
41
|
-
.description("Generate a checkout link to top up the project's credit balance")
|
|
42
|
-
.requiredOption("-a, --amount-cents <cents>", "Purchase amount in USD cents (e.g. 1000 = $10.00)")
|
|
43
|
-
.option("-c, --currency <currency>", "ISO 4217 currency code (defaults to USD server-side)")).action(withProfile(async (profile, opts) => {
|
|
44
|
-
const res = await sdk.platform(profile).billing().topUp({
|
|
45
|
-
amount_cents: Number(opts.amountCents),
|
|
46
|
-
...(opts.currency ? { currency: opts.currency } : {}),
|
|
47
|
-
});
|
|
48
|
-
return res.data;
|
|
49
|
-
})));
|
|
50
|
-
cmd.addCommand(registerCommand(new Command("credits")
|
|
51
|
-
.description("Get the project's credit activity (deductions/top-ups) history")
|
|
52
|
-
.option("-l, --limit <n>", "Max rows to return (server default 50, capped at 200)")
|
|
53
|
-
.option("--offset <n>", "Row offset for pagination")
|
|
54
|
-
.option("-t, --type <type>", "Filter by entry type (e.g. deduction | topup)")
|
|
55
|
-
.option("-y, --year <year>", "Filter by year")
|
|
56
|
-
.option("-m, --month <month>", "Filter by month")).action(withProfile(async (profile, opts) => {
|
|
57
|
-
const query = {
|
|
58
|
-
...(opts.limit !== undefined ? { limit: Number(opts.limit) } : {}),
|
|
59
|
-
...(opts.offset !== undefined ? { offset: Number(opts.offset) } : {}),
|
|
60
|
-
...(opts.type ? { type: opts.type } : {}),
|
|
61
|
-
...(opts.year !== undefined ? { year: Number(opts.year) } : {}),
|
|
62
|
-
...(opts.month !== undefined ? { month: Number(opts.month) } : {}),
|
|
63
|
-
};
|
|
64
|
-
const res = await sdk.platform(profile).billing().getCreditsHistory(query);
|
|
65
|
-
return res.data;
|
|
66
|
-
})));
|
|
67
|
-
cmd.addCommand(registerCommand(new Command("prices")
|
|
68
|
-
.description("Get the usage-based pricing table for a given currency")
|
|
69
|
-
.requiredOption("-c, --currency <currency>", "ISO 4217 currency code, e.g. USD or RSD")).action(withProfile(async (profile, opts) => {
|
|
70
|
-
const res = await sdk.platform(profile).billing().getPrices(opts.currency);
|
|
71
|
-
return res.data;
|
|
72
|
-
})));
|
|
73
|
-
cmd.addCommand(registerCommand(new Command("billing-modes")
|
|
74
|
-
.description("Get the project's usage-billing-mode overrides, or set one with --option-code/--mode/--data")
|
|
75
|
-
.option("--option-code <code>", "Usage option code to update (requires --mode, or use --data)")
|
|
76
|
-
.option("--mode <mode>", "Billing mode to set: credits | hybrid | invoice (requires --option-code)")
|
|
77
|
-
.option("-d, --data <json>", "Update payload as a JSON string ({ option_code, mode }) — alternative to --option-code/--mode")).action(withProfile(async (profile, opts) => {
|
|
78
|
-
const client = sdk.platform(profile).billing();
|
|
79
|
-
if (opts.data) {
|
|
80
|
-
const payload = parseJSON("--data", opts.data);
|
|
81
|
-
const res = await client.updateBillingModes(payload);
|
|
82
|
-
return res.data;
|
|
83
|
-
}
|
|
84
|
-
if (opts.optionCode || opts.mode) {
|
|
85
|
-
if (!opts.optionCode || !opts.mode) {
|
|
86
|
-
console.error("--option-code and --mode must be provided together");
|
|
87
|
-
process.exit(1);
|
|
88
|
-
}
|
|
89
|
-
const res = await client.updateBillingModes({ option_code: opts.optionCode, mode: opts.mode });
|
|
90
|
-
return res.data;
|
|
91
|
-
}
|
|
92
|
-
const res = await client.getBillingModes();
|
|
93
|
-
return res.data;
|
|
94
|
-
})));
|
|
95
|
-
return cmd;
|
|
96
|
-
}
|
|
97
|
-
registerInvoicePdf() {
|
|
98
|
-
const pdfCmd = withEnvOption(new Command("invoice-pdf")
|
|
99
|
-
.description("Download an invoice as a PDF")
|
|
100
|
-
.argument("<uuid>", "Invoice uuid")
|
|
101
|
-
.requiredOption("-o, --out <file>", "File path to write the PDF to"));
|
|
102
|
-
pdfCmd.action(withProfile(async (profile, uuid, opts) => {
|
|
103
|
-
const res = await sdk.platform(profile).billing().getInvoicePdf(uuid);
|
|
104
|
-
const outPath = resolve(opts.out);
|
|
105
|
-
writeFileSync(outPath, Buffer.from(res.data));
|
|
106
|
-
console.log(`Invoice PDF written to ${outPath}`);
|
|
107
|
-
}));
|
|
108
|
-
return pdfCmd;
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
export default new BillingCommand();
|