@ptkl/toolkit 0.14.0 → 1.0.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.
@@ -0,0 +1,111 @@
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();
@@ -0,0 +1,33 @@
1
+ import { Command } from "commander";
2
+ import * as sdk from "../lib/sdk.js";
3
+ import { registerCommand, withProfile } from "../lib/scaffold.js";
4
+ /** `ptkl config` — per-user configuration (RFC §4.1 "Config": `GET/PUT config/user`).
5
+ * Maps 1:1 onto the SDK `Config` client (@ptkl/sdk/beta). */
6
+ function parseJSON(label, raw) {
7
+ try {
8
+ return JSON.parse(raw);
9
+ }
10
+ catch {
11
+ console.error(`${label} must be valid JSON`);
12
+ process.exit(1);
13
+ }
14
+ }
15
+ class ConfigCommand {
16
+ register() {
17
+ const cmd = new Command("config").description("Get or set the current user's configuration");
18
+ cmd.addCommand(registerCommand(new Command("get").description("Get the current user's configuration")).action(withProfile(async (profile) => {
19
+ const res = await sdk.config(profile).getUserConfig();
20
+ return res.data;
21
+ })));
22
+ cmd.addCommand(registerCommand(new Command("set")
23
+ .description("Update the current user's configuration")
24
+ .requiredOption("-p, --path <path>", "Config path to write")
25
+ .requiredOption("-d, --data <json>", "Config data as a JSON string")).action(withProfile(async (profile, opts) => {
26
+ const data = parseJSON("--data", opts.data);
27
+ const res = await sdk.config(profile).updateUserConfig({ path: opts.path, data });
28
+ return res.data;
29
+ })));
30
+ return cmd;
31
+ }
32
+ }
33
+ export default new ConfigCommand();
@@ -8,6 +8,17 @@ import axios from 'axios';
8
8
  import Util from "../lib/util.js";
9
9
  import { dirname, extname, isAbsolute, join } from 'path';
10
10
  import { forgeDevKernelPlugin } from '../lib/forgeDevKernelPlugin.js';
11
+ import * as sdk from "../lib/sdk.js";
12
+ import { registerCommand, withProfile } from "../lib/scaffold.js";
13
+ function parseJSON(label, raw) {
14
+ try {
15
+ return JSON.parse(raw);
16
+ }
17
+ catch {
18
+ console.error(`${label} must be valid JSON`);
19
+ process.exit(1);
20
+ }
21
+ }
11
22
  function formatBuildError(reason) {
12
23
  const lines = [];
13
24
  if (reason.id || reason.loc) {
@@ -106,7 +117,110 @@ class ForgeCommand {
106
117
  .requiredOption("-p, --path <path>", "Path to the app directory (where ptkl.config.js is located)")
107
118
  .option("--env <env>", "Run for a specific env only (dev or live). Omit to run for both.")
108
119
  .option("-b, --bundle", "Build the bundle before running the uninstall script")
109
- .action((options) => this.uninstall(options)));
120
+ .action((options) => this.uninstall(options)))
121
+ // --- Deployed-app management (appservice) -------------------------------------------
122
+ // These subcommands use the shared scaffold (src/lib/sdk.ts + src/lib/scaffold.ts) and
123
+ // the SDK `Forge` client (@ptkl/sdk/beta), unlike bundle/dev/setup/list/install/uninstall
124
+ // above, which predate that scaffold and talk to a v0.9 client via Util.getClientForProfile().
125
+ // `services`/`variables`/`run` are wrapped named methods on the v0.10 `Forge` client;
126
+ // `domains` has no named methods yet, so it goes through the client's underlying
127
+ // authenticated AxiosInstance (`.client`, a public property on every SDK client) — the same
128
+ // stopgap pattern used by `ptkl functions create` / `ptkl project billing-modes`.
129
+ .addCommand(registerCommand(new Command("services")
130
+ .description("List services declared by a Forge app")
131
+ .argument("<ref>", "App reference (uuid or name)")).action(withProfile(async (profile, ref) => {
132
+ const res = await sdk.platform(profile).forge().listServices(ref);
133
+ return res.data;
134
+ })))
135
+ .addCommand(this.registerVariables())
136
+ .addCommand(this.registerDomains())
137
+ .addCommand(registerCommand(new Command("run")
138
+ .description("Invoke a deployed Forge service app. A bare name runs the CURRENT app's service; " +
139
+ "a PRN (prn:forge:{ref}:service/{name}) runs another app's service, where ref is an app name or uuid.")
140
+ .argument("<service>", "Service name (current app) or PRN: prn:forge:{ref}:service/{name}")
141
+ .option("-b, --body <json>", "Request body as a JSON string, sent as the POST payload")
142
+ .option("-q, --query <json>", "Query params as a JSON object string")
143
+ .option("-H, --headers <json>", "Extra request headers as a JSON object string")).action(withProfile(async (profile, service, opts) => {
144
+ const body = opts.body ? parseJSON("--body", opts.body) : undefined;
145
+ const query = opts.query ? parseJSON("--query", opts.query) : undefined;
146
+ const headers = opts.headers ? parseJSON("--headers", opts.headers) : undefined;
147
+ const res = await sdk.platform(profile).forge().runService(service, body, { query, headers });
148
+ return res.data;
149
+ })));
150
+ }
151
+ /** `forge variables get|set|add <ref>` — get/replace/merge a Forge app's variables
152
+ * (getVariables/updateVariables/addVariable on the SDK `Forge` client). */
153
+ registerVariables() {
154
+ const variables = new Command("variables").description("Manage a Forge app's variables");
155
+ variables.addCommand(registerCommand(new Command("get")
156
+ .description("Get all variables for a Forge app")
157
+ .argument("<ref>", "App reference (uuid or name)")).action(withProfile(async (profile, ref) => {
158
+ const res = await sdk.platform(profile).forge().getVariables(ref);
159
+ return res.data;
160
+ })));
161
+ variables.addCommand(registerCommand(new Command("set")
162
+ .description("Replace ALL variables for a Forge app (full overwrite, not a merge)")
163
+ .argument("<ref>", "App reference (uuid or name)")
164
+ .requiredOption("-d, --data <json>", "Full variables object as a JSON string (replaces all existing variables)")).action(withProfile(async (profile, ref, opts) => {
165
+ const payload = parseJSON("--data", opts.data);
166
+ const res = await sdk.platform(profile).forge().updateVariables(ref, payload);
167
+ return res.data;
168
+ })));
169
+ variables.addCommand(registerCommand(new Command("add")
170
+ .description("Add or update a single variable on a Forge app (merges into existing variables)")
171
+ .argument("<ref>", "App reference (uuid or name)")
172
+ .argument("<key>", "Variable key")
173
+ .argument("<value>", "Variable value (parsed as JSON if it's valid JSON, otherwise kept as a string)")).action(withProfile(async (profile, ref, key, value) => {
174
+ let parsedValue = value;
175
+ try {
176
+ parsedValue = JSON.parse(value);
177
+ }
178
+ catch { /* not JSON — keep the raw string */ }
179
+ const res = await sdk.platform(profile).forge().addVariable(ref, key, parsedValue);
180
+ return res.data;
181
+ })));
182
+ return variables;
183
+ }
184
+ /** `forge domains add|verify|refresh|remove <ref> <domain>` — custom-domain lifecycle for
185
+ * public Forge apps (appservice `POST/DELETE /luma/appservice/v1/forge/:ref/domain[/verify|/refresh]`,
186
+ * see platform-docs/docs/forge/custom-domains.md). No named SDK method exists yet, so this calls
187
+ * the SDK `Forge` client's underlying authenticated AxiosInstance directly (`.client`, see the
188
+ * stopgap-pattern note above `services`). */
189
+ registerDomains() {
190
+ const domains = new Command("domains").description("Manage custom domains for a public Forge app");
191
+ domains.addCommand(registerCommand(new Command("add")
192
+ .description("Register a custom domain (returns a DNS TXT validationKey to prove ownership)")
193
+ .argument("<ref>", "App reference (uuid or name)")
194
+ .argument("<domain>", "Custom domain, e.g. app.example.com")).action(withProfile(async (profile, ref, domain) => {
195
+ const client = sdk.platform(profile).forge();
196
+ const res = await client.client.post(`/luma/appservice/v1/forge/${ref}/domain`, { domain });
197
+ return res.data;
198
+ })));
199
+ domains.addCommand(registerCommand(new Command("verify")
200
+ .description("Verify a custom domain's DNS TXT record against its validation key")
201
+ .argument("<ref>", "App reference (uuid or name)")
202
+ .argument("<domain>", "Custom domain to verify")).action(withProfile(async (profile, ref, domain) => {
203
+ const client = sdk.platform(profile).forge();
204
+ const res = await client.client.post(`/luma/appservice/v1/forge/${ref}/domain/verify`, { domain });
205
+ return res.data;
206
+ })));
207
+ domains.addCommand(registerCommand(new Command("refresh")
208
+ .description("Refresh an expired validation key for an unvalidated custom domain")
209
+ .argument("<ref>", "App reference (uuid or name)")
210
+ .argument("<domain>", "Custom domain")).action(withProfile(async (profile, ref, domain) => {
211
+ const client = sdk.platform(profile).forge();
212
+ const res = await client.client.post(`/luma/appservice/v1/forge/${ref}/domain/refresh`, { domain });
213
+ return res.data;
214
+ })));
215
+ domains.addCommand(registerCommand(new Command("remove")
216
+ .description("Remove a custom domain")
217
+ .argument("<ref>", "App reference (uuid or name)")
218
+ .argument("<domain>", "Custom domain to remove")).action(withProfile(async (profile, ref, domain) => {
219
+ const client = sdk.platform(profile).forge();
220
+ const res = await client.client.delete(`/luma/appservice/v1/forge/${ref}/domain`, { data: { domain } });
221
+ return res.data;
222
+ })));
223
+ return domains;
110
224
  }
111
225
  async bundle(options) {
112
226
  const { path: rawPath, upload, mode } = options;
@@ -244,10 +358,26 @@ class ForgeCommand {
244
358
  manifest.views[view] = `${view}.bundle.js`;
245
359
  }
246
360
  try {
361
+ const bundleMode = mode ?? 'production';
247
362
  const result = await build({
248
363
  root: path,
249
- mode: mode ?? 'production',
364
+ mode: bundleMode,
250
365
  base: bundleBasePath,
366
+ // Keep the JSX transform and React runtime on the same side even if
367
+ // the invoking shell exports NODE_ENV=development (Vite derives
368
+ // isProduction from NODE_ENV, not from mode). A split ships jsxDEV()
369
+ // calls against production React → "jsxDEV is not a function".
370
+ esbuild: {
371
+ jsxDev: bundleMode !== 'production',
372
+ },
373
+ define: {
374
+ 'process.env.NODE_ENV': JSON.stringify(bundleMode),
375
+ },
376
+ resolve: {
377
+ // One React copy even when @ptkl/components is npm-linked (the
378
+ // linked repo carries its own node_modules/react).
379
+ dedupe: ['react', 'react-dom', 'react/jsx-runtime', 'react/jsx-dev-runtime'],
380
+ },
251
381
  build: {
252
382
  outDir: distPath,
253
383
  emptyOutDir: false,
@@ -255,10 +385,13 @@ class ForgeCommand {
255
385
  input: viewDef.entry,
256
386
  output: {
257
387
  format: 'esm',
388
+ // Name outputs by the view KEY, not the entry file's basename —
389
+ // the manifest and AppView resolve `${view}.bundle.js` / `${view}.css`,
390
+ // so an entry named index.tsx must still emit `${view}.*`.
391
+ // Other assets keep a hashed name: all views share distPath, so
392
+ // entry-derived names (e.g. index.css from two views) collide.
258
393
  entryFileNames: `${view}.bundle.js`,
259
- assetFileNames: (assetInfo) => {
260
- return '[name].[ext]'; // Example: Customize the output file name format
261
- },
394
+ assetFileNames: (assetInfo) => assetInfo.name?.endsWith('.css') ? `${view}.css` : `[name]-[hash].[ext]`,
262
395
  manualChunks: undefined,
263
396
  inlineDynamicImports: true,
264
397
  }
@@ -564,7 +697,7 @@ class ForgeCommand {
564
697
  DEV_HUB_PORT
565
698
  },
566
699
  plugins: [
567
- forgeDevKernelPlugin(appName, platformUrl),
700
+ forgeDevKernelPlugin(appName, platformUrl, DEV_HUB_PORT),
568
701
  {
569
702
  // Console bridge (dev only): when the app runs EMBEDDED (e.g. the
570
703
  // Studio's Preview iframe), forward console output + uncaught errors
@@ -659,9 +792,17 @@ class ForgeCommand {
659
792
  mode: 'production',
660
793
  logLevel: 'silent',
661
794
  plugins: [],
662
- // Explicitly define NODE_ENV for this build so esbuild strips dev-only
663
- // code paths (e.g. React dev warnings) in the view bundle, regardless
664
- // of what process.env.NODE_ENV is set to in the surrounding process.
795
+ // The dev hub serves PRODUCTION builds of views. The dev server created
796
+ // above set process.env.NODE_ENV=development for this whole process, and
797
+ // Vite derives isProduction from NODE_ENV (not from mode) — so both the
798
+ // JSX transform and React's runtime must be forced to production TOGETHER:
799
+ // - jsxDev:false → esbuild emits jsx() from react/jsx-runtime
800
+ // - define → React resolves its production runtime
801
+ // Forcing only the define ships dev jsxDEV() calls against production
802
+ // React, where jsxDEV is undefined → "_a.jsxDEV is not a function".
803
+ esbuild: {
804
+ jsxDev: false,
805
+ },
665
806
  define: {
666
807
  'process.env.NODE_ENV': '"production"',
667
808
  },
@@ -1,27 +1,92 @@
1
1
  import { Command } from "commander";
2
- import util from "../lib/util.js";
3
- import { Platform as Api } from "@ptkl/sdk";
4
- import OutputFormatCommand from "./outputCommand.js";
5
- class FunctionsCommand {
6
- register() {
7
- return new Command('functions')
8
- .description('Manage functions')
9
- .version('0.1.0')
10
- .addCommand(new OutputFormatCommand(new Command('list')
11
- .description('List functions')).action(this.list))
12
- .addCommand(new OutputFormatCommand(new Command('get')
13
- .description('Get function')
14
- .argument("<reference>", "Reference to the function which can be name, tag or uuid")).action(this.get));
2
+ import { readFileSync } from "fs";
3
+ import { resolve } from "path";
4
+ import * as sdk from "../lib/sdk.js";
5
+ import { registerCommand, withProfile } from "../lib/scaffold.js";
6
+ /** `ptkl functions` — platform function CRUD + invocation (RFC §6, "Functions").
7
+ * Maps onto the SDK `Functions` client (@ptkl/sdk/beta) for `list`/`get`/`update`/`run`/
8
+ * `signature` (`generateSignature`). The platform's `system/function` collection endpoint also
9
+ * supports POST for creation, but the v0.10 `Functions` client does not yet wrap that in a named
10
+ * method — `create` goes through the same authenticated client instance's underlying `.client`
11
+ * (a public AxiosInstance, see @ptkl/sdk/beta BaseClient) rather than a named method, the same
12
+ * stopgap pattern used by `ptkl project billing-modes`/`auto-topup`, pending a follow-up SDK WP
13
+ * to give `Functions` a `create()` method.
14
+ *
15
+ * Return-shape contract: every subcommand here resolves to the *payload*, never a raw
16
+ * AxiosResponse. `Functions.run()` already unwraps `.data` in the SDK; `list`/`get`/`update`/
17
+ * `generateSignature` do not (they resolve to the AxiosResponse), so this command layer unwraps
18
+ * `.data` itself for those — matching `create`, which reads `.data` off the raw axios call. This
19
+ * keeps `-f json`/`-f jsonpath`/`-f template` consistent across all six subcommands. */
20
+ function parseJSON(label, raw) {
21
+ try {
22
+ return JSON.parse(raw);
23
+ }
24
+ catch {
25
+ console.error(`${label} must be valid JSON`);
26
+ process.exit(1);
27
+ }
28
+ }
29
+ function readPayload(label, dataStr, file) {
30
+ if (file) {
31
+ return JSON.parse(readFileSync(resolve(file), "utf-8"));
15
32
  }
16
- async list() {
17
- const profile = util.getCurrentProfile();
18
- const client = new Api({ token: profile.token, host: profile.host }).function();
19
- return await client.list();
33
+ if (dataStr) {
34
+ return parseJSON(label, dataStr);
20
35
  }
21
- async get(reference) {
22
- const profile = util.getCurrentProfile();
23
- const client = new Api({ token: profile.token, host: profile.host }).function();
24
- return await client.get(reference);
36
+ console.error("Error: either --data or --file must be provided");
37
+ process.exit(1);
38
+ }
39
+ class FunctionsCommand {
40
+ register() {
41
+ const cmd = new Command("functions").description("Manage functions").version("0.1.0");
42
+ cmd.addCommand(registerCommand(new Command("list").description("List functions")).action(withProfile(async (profile) => {
43
+ const res = await sdk.platform(profile).function().list();
44
+ return res.data;
45
+ })));
46
+ cmd.addCommand(registerCommand(new Command("get")
47
+ .description("Get function")
48
+ .argument("<reference>", "Reference to the function which can be name, tag or uuid")).action(withProfile(async (profile, reference) => {
49
+ const res = await sdk.platform(profile).function().get(reference);
50
+ return res.data;
51
+ })));
52
+ cmd.addCommand(registerCommand(new Command("run")
53
+ .description("Run a platform function")
54
+ .argument("<reference>", "Reference to the function which can be name, tag or uuid")
55
+ .option("-i, --input <json>", "Input payload as a JSON string")
56
+ .option("-q, --query <json>", "Query params as a JSON object string")).action(withProfile(async (profile, reference, opts) => {
57
+ const { input: inputStr, query: queryStr } = opts;
58
+ const input = inputStr ? parseJSON("--input", inputStr) : undefined;
59
+ const query = queryStr ? parseJSON("--query", queryStr) : undefined;
60
+ return await sdk.platform(profile).function().run(reference, { input, query });
61
+ })));
62
+ cmd.addCommand(registerCommand(new Command("create")
63
+ .description("Create a new function")
64
+ .option("-d, --data <data>", "Full create payload as JSON string (overrides --file)")
65
+ .option("-i, --file <file>", "Path to a JSON file containing the full create payload")).action(withProfile(async (profile, opts) => {
66
+ const { data: dataStr, file } = opts;
67
+ const payload = readPayload("--data", dataStr, file);
68
+ const client = sdk.platform(profile).function();
69
+ const res = await client.client.post("/v1/system/function", payload);
70
+ return res.data;
71
+ })));
72
+ cmd.addCommand(registerCommand(new Command("update")
73
+ .description("Update an existing function")
74
+ .argument("<uuid>", "UUID of the function to update")
75
+ .option("-d, --data <data>", "Fields to update, as a JSON object string (overrides --file)")
76
+ .option("-i, --file <file>", "Path to a JSON file containing the fields to update")).action(withProfile(async (profile, uuid, opts) => {
77
+ const { data: dataStr, file } = opts;
78
+ const payload = readPayload("--data", dataStr, file);
79
+ const res = await sdk.platform(profile).function().update(uuid, payload);
80
+ return res.data;
81
+ })));
82
+ cmd.addCommand(registerCommand(new Command("signature")
83
+ .description("Generate the IDL signature for a function in a given environment")
84
+ .argument("<env>", "Environment to resolve the signature against, e.g. dev | live")
85
+ .argument("<reference>", "Reference to the function which can be name, tag or uuid")).action(withProfile(async (profile, env, reference) => {
86
+ const res = await sdk.platform(profile).function().generateSignature(reference, env);
87
+ return res.data;
88
+ })));
89
+ return cmd;
25
90
  }
26
91
  }
27
- export default new FunctionsCommand;
92
+ export default new FunctionsCommand();
@@ -2,7 +2,8 @@ import { Command } from "commander";
2
2
  // commands
3
3
  import profile from "./profile.js";
4
4
  import Util from "../lib/util.js";
5
- import users from "./apiUsers.js";
5
+ import apiUsers from "./apiUsers.js";
6
+ import users from "./users.js";
6
7
  import functions from "./functions.js";
7
8
  import apps from "./apps.js";
8
9
  import role from "./role.js";
@@ -13,8 +14,18 @@ import generateTypes from "./generate-types.js";
13
14
  import validateIDL from "./validate-idl.js";
14
15
  import kortex from "./kortex.js";
15
16
  import logs from "./logs.js";
17
+ import project from "./project.js";
18
+ import template from "./template.js";
19
+ import config from "./config.js";
20
+ import ratchet from "./ratchet.js";
21
+ import thunder from "./thunder.js";
22
+ import sandbox from "./sandbox.js";
23
+ import billing from "./billing.js";
24
+ import integration from "./integration.js";
25
+ import satellite from "./satellite.js";
16
26
  export const commands = [
17
27
  profile.register(),
28
+ apiUsers.register(),
18
29
  users.register(),
19
30
  functions.register(),
20
31
  apps.register(),
@@ -25,6 +36,15 @@ export const commands = [
25
36
  generateTypes.register(),
26
37
  validateIDL.register(),
27
38
  logs.register(),
39
+ project.register(),
40
+ template.register(),
41
+ config.register(),
42
+ ratchet.register(),
43
+ thunder.register(),
44
+ sandbox.register(),
45
+ billing.register(),
46
+ integration.register(),
47
+ satellite.register(),
28
48
  kortex.register(),
29
49
  new Command('init')
30
50
  .description("Init protokol toolkit")