@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,122 @@
1
+ import { Command } from "commander";
2
+ import * as sdk from "../lib/sdk.js";
3
+ import { registerCommand, withProfile } from "../lib/scaffold.js";
4
+ /** `ptkl sandbox` — Sandbox / Spark (RFC §4.2 "Sandbox / Spark", §6 target surface):
5
+ * - `spark list|deploy|release|cancel|exec|logs` -> listSparks/deploySpark/releaseSpark/
6
+ * cancelSpark/execSpark/sparkLogs
7
+ * - `runtime list|deploy|restart|logs` -> listRuntimes/deployRuntime/restartRuntime/
8
+ * runtimeLogs
9
+ * - `tier` -> sparkTier
10
+ * Maps 1:1 onto the SDK `Sandbox` client (@ptkl/sdk/beta). */
11
+ function parseJSON(label, raw) {
12
+ try {
13
+ return JSON.parse(raw);
14
+ }
15
+ catch {
16
+ console.error(`${label} must be valid JSON`);
17
+ process.exit(1);
18
+ }
19
+ }
20
+ class SandboxCommand {
21
+ register() {
22
+ const cmd = new Command("sandbox").description("Manage Sandbox sparks and runtimes");
23
+ cmd.addCommand(this.registerSpark());
24
+ cmd.addCommand(this.registerRuntime());
25
+ cmd.addCommand(registerCommand(new Command("tier").description("Get the current project's spark tier (plan/quota)")).action(withProfile(async (profile) => {
26
+ const res = await sdk.sandbox(profile).sparkTier();
27
+ return res.data;
28
+ })));
29
+ return cmd;
30
+ }
31
+ registerSpark() {
32
+ const spark = new Command("spark").description("Manage Spark (FaaS) functions and apps");
33
+ spark.addCommand(registerCommand(new Command("list").description("List all sparks for the current project")).action(withProfile(async (profile) => {
34
+ const res = await sdk.sandbox(profile).listSparks();
35
+ return res.data;
36
+ })));
37
+ spark.addCommand(registerCommand(new Command("deploy")
38
+ .description("Deploy a specific spark version to the dev environment")
39
+ .requiredOption("-i, --id <uuid>", "Spark uuid")
40
+ .requiredOption("-v, --version <version>", "Version to deploy")).action(withProfile(async (profile, opts) => {
41
+ const res = await sdk.sandbox(profile).deploySpark(opts.id, opts.version);
42
+ return res.data;
43
+ })));
44
+ spark.addCommand(registerCommand(new Command("release")
45
+ .description("Release a deployed spark version to the live/public environment")
46
+ .requiredOption("-i, --id <uuid>", "Spark uuid")
47
+ .requiredOption("-v, --version <version>", "Version to release")).action(withProfile(async (profile, opts) => {
48
+ const res = await sdk.sandbox(profile).releaseSpark(opts.id, opts.version);
49
+ return res.data;
50
+ })));
51
+ spark.addCommand(registerCommand(new Command("cancel")
52
+ .description("Cancel an in-progress spark deployment")
53
+ .requiredOption("-i, --id <uuid>", "Spark uuid")
54
+ .option("--spark-env <env>", "Spark environment: dev | live (defaults to dev on the server)")).action(withProfile(async (profile, opts) => {
55
+ const res = await sdk.sandbox(profile).cancelSpark(opts.id, opts.sparkEnv);
56
+ return res.data;
57
+ })));
58
+ spark.addCommand(registerCommand(new Command("exec")
59
+ .description("Execute a deployed spark by name")
60
+ .requiredOption("-n, --name <name>", "Spark name")
61
+ .option("-d, --data <json>", "Request body as a JSON string")
62
+ .option("-m, --method <method>", "HTTP method: GET | POST | PATCH | PUT | DELETE", "POST")
63
+ .option("-q, --query <json>", "Query params as a JSON object string")
64
+ .option("-H, --headers <json>", "Request headers as a JSON object string")).action(withProfile(async (profile, opts) => {
65
+ const data = opts.data !== undefined ? parseJSON("--data", opts.data) : undefined;
66
+ const query = opts.query !== undefined ? parseJSON("--query", opts.query) : undefined;
67
+ const headers = opts.headers !== undefined ? parseJSON("--headers", opts.headers) : undefined;
68
+ const res = await sdk.sandbox(profile).execSpark(opts.name, data, {
69
+ method: opts.method,
70
+ query,
71
+ headers,
72
+ });
73
+ return res.data;
74
+ })));
75
+ spark.addCommand(registerCommand(new Command("logs")
76
+ .description("Fetch logs for a spark")
77
+ .requiredOption("-i, --id <uuid>", "Spark uuid")
78
+ .option("--spark-env <env>", "Spark environment: dev | live")
79
+ .option("-l, --limit <limit>", "Number of log lines to fetch")
80
+ .option("--level <level>", "Filter by log level")
81
+ .option("--since <since>", "Only fetch logs since this timestamp")).action(withProfile(async (profile, opts) => {
82
+ const res = await sdk.sandbox(profile).sparkLogs(opts.id, {
83
+ env: opts.sparkEnv,
84
+ limit: opts.limit !== undefined ? Number(opts.limit) : undefined,
85
+ level: opts.level,
86
+ since: opts.since,
87
+ });
88
+ return res.data;
89
+ })));
90
+ return spark;
91
+ }
92
+ registerRuntime() {
93
+ const runtime = new Command("runtime").description("Manage Sandbox runtimes (long-running user API deployments)");
94
+ runtime.addCommand(registerCommand(new Command("list").description("List all runtimes for the current project")).action(withProfile(async (profile) => {
95
+ const res = await sdk.sandbox(profile).listRuntimes();
96
+ return res.data;
97
+ })));
98
+ runtime.addCommand(registerCommand(new Command("deploy")
99
+ .description("(Re)deploy a runtime")
100
+ .requiredOption("-r, --ref <ref>", "Runtime name/uuid")).action(withProfile(async (profile, opts) => {
101
+ const res = await sdk.sandbox(profile).deployRuntime(opts.ref);
102
+ return res.data;
103
+ })));
104
+ runtime.addCommand(registerCommand(new Command("restart")
105
+ .description("Restart a running runtime")
106
+ .requiredOption("-r, --ref <ref>", "Runtime name/uuid")).action(withProfile(async (profile, opts) => {
107
+ const res = await sdk.sandbox(profile).restartRuntime(opts.ref);
108
+ return res.data;
109
+ })));
110
+ runtime.addCommand(registerCommand(new Command("logs")
111
+ .description("Fetch logs for a runtime")
112
+ .requiredOption("-r, --ref <ref>", "Runtime name/uuid")
113
+ .option("--lines <lines>", "Number of log lines to fetch")).action(withProfile(async (profile, opts) => {
114
+ const res = await sdk.sandbox(profile).runtimeLogs(opts.ref, {
115
+ lines: opts.lines !== undefined ? Number(opts.lines) : undefined,
116
+ });
117
+ return res.data;
118
+ })));
119
+ return runtime;
120
+ }
121
+ }
122
+ export default new SandboxCommand();
@@ -0,0 +1,111 @@
1
+ import { Command } from "commander";
2
+ import { Satellites } from "@ptkl/sdk/beta";
3
+ import * as sdk from "../lib/sdk.js";
4
+ import { registerCommand, withProfile } from "../lib/scaffold.js";
5
+ /** `ptkl satellite` — Satellites: custom JSON-RPC integrations (RFC §4.3 "Satellites (custom
6
+ * JSON-RPC integrations)", §6 target surface: `satellite templates versions deploy rollback
7
+ * permissions logs execute`). Maps 1:1 onto the SDK `Satellites` client (@ptkl/sdk/beta), which
8
+ * talks to the integrations gateway (`profile.host/luma/integrations`).
9
+ *
10
+ * `satellite execute` is the same door as `ptkl integration run` (RFC §6.2 "generic
11
+ * passthrough") — both hit `satellites/{id}/commands/{method}/execute` (JSON-RPC 2.0). This file
12
+ * builds its own `Satellites` client (mirroring src/commands/integration.ts's local `satellites()`
13
+ * helper) rather than adding an accessor to src/lib/sdk.ts, which is outside this WP's sanctioned
14
+ * paths. */
15
+ function parseJSON(label, raw) {
16
+ try {
17
+ return JSON.parse(raw);
18
+ }
19
+ catch {
20
+ console.error(`${label} must be valid JSON`);
21
+ process.exit(1);
22
+ }
23
+ }
24
+ function satellites(profile) {
25
+ return new Satellites(sdk.integrationsOptions(profile));
26
+ }
27
+ class SatelliteCommand {
28
+ register() {
29
+ const cmd = new Command("satellite").description("Manage Satellites (custom JSON-RPC integrations)");
30
+ cmd.addCommand(this.registerTemplates());
31
+ cmd.addCommand(this.registerVersions());
32
+ cmd.addCommand(registerCommand(new Command("deploy")
33
+ .description("Deploy a satellite template's schema version to an environment")
34
+ .argument("<id>", "Satellite template id")
35
+ .requiredOption("-s, --schema-version <version>", "Schema version to deploy")
36
+ .requiredOption("--target-env <env>", "Environment to deploy to: dev | live")).action(withProfile(async (profile, id, opts) => {
37
+ return await satellites(profile).deploy(id, {
38
+ schema_version: opts.schemaVersion,
39
+ env: opts.targetEnv,
40
+ });
41
+ })));
42
+ cmd.addCommand(registerCommand(new Command("rollback")
43
+ .description("Roll a satellite template back to a previous schema version in an environment")
44
+ .argument("<id>", "Satellite template id")
45
+ .requiredOption("-s, --schema-version <version>", "Schema version to roll back to")
46
+ .requiredOption("--target-env <env>", "Environment to roll back: dev | live")).action(withProfile(async (profile, id, opts) => {
47
+ return await satellites(profile).rollback(id, {
48
+ schema_version: opts.schemaVersion,
49
+ env: opts.targetEnv,
50
+ });
51
+ })));
52
+ cmd.addCommand(registerCommand(new Command("permissions")
53
+ .description("List the permission exports declared by a satellite template's active schema")
54
+ .argument("<id>", "Satellite template id")).action(withProfile(async (profile, id) => {
55
+ return await satellites(profile).permissions(id);
56
+ })));
57
+ cmd.addCommand(registerCommand(new Command("logs")
58
+ .description("Fetch logs for a satellite template")
59
+ .argument("<id>", "Satellite template id")
60
+ .option("--since <since>", "Only fetch logs since this timestamp")).action(withProfile(async (profile, id, opts) => {
61
+ return await satellites(profile).logs(id, { since: opts.since });
62
+ })));
63
+ cmd.addCommand(registerCommand(new Command("execute")
64
+ .description("Invoke a JSON-RPC command on a satellite (same door as `ptkl integration run`)")
65
+ .argument("<id>", "Satellite template id")
66
+ .argument("<command>", "Command name to execute")
67
+ .option("-p, --params <json>", "Execute payload as a JSON string ({ inputs, context, session, caller_prn }), defaults to {}")).action(withProfile(async (profile, id, command, opts) => {
68
+ const payload = opts.params ? parseJSON("--params", opts.params) : {};
69
+ return await satellites(profile).execute(id, command, payload);
70
+ })));
71
+ return cmd;
72
+ }
73
+ registerTemplates() {
74
+ const templates = new Command("templates").description("Manage satellite templates (CRUD)");
75
+ templates.addCommand(registerCommand(new Command("list").description("List all satellite templates for the current project")).action(withProfile(async (profile) => {
76
+ return await satellites(profile).list();
77
+ })));
78
+ templates.addCommand(registerCommand(new Command("create")
79
+ .description("Create a satellite template, optionally with an initial schema version")
80
+ .requiredOption("-d, --data <json>", 'Create payload as a JSON string: { "template": {...}, "schema"?: {...} }')).action(withProfile(async (profile, opts) => {
81
+ const payload = parseJSON("--data", opts.data);
82
+ return await satellites(profile).create(payload);
83
+ })));
84
+ templates.addCommand(registerCommand(new Command("get").description("Get a satellite template by id").argument("<id>", "Satellite template id")).action(withProfile(async (profile, id) => {
85
+ return await satellites(profile).get(id);
86
+ })));
87
+ templates.addCommand(registerCommand(new Command("delete")
88
+ .description("Delete a satellite template")
89
+ .argument("<id>", "Satellite template id")).action(withProfile(async (profile, id) => {
90
+ return await satellites(profile).delete(id);
91
+ })));
92
+ return templates;
93
+ }
94
+ registerVersions() {
95
+ const versions = new Command("versions").description("Manage satellite template schema versions");
96
+ versions.addCommand(registerCommand(new Command("list")
97
+ .description("List all schema versions for a satellite template")
98
+ .argument("<id>", "Satellite template id")).action(withProfile(async (profile, id) => {
99
+ return await satellites(profile).versions(id);
100
+ })));
101
+ versions.addCommand(registerCommand(new Command("create")
102
+ .description("Create a new schema version for a satellite template")
103
+ .argument("<id>", "Satellite template id")
104
+ .requiredOption("-d, --data <json>", 'Schema payload as a JSON string: { "schema_version", "schema"?, "permissions"?, "jsonrpc_commands"?, "workflownodes"? }')).action(withProfile(async (profile, id, opts) => {
105
+ const payload = parseJSON("--data", opts.data);
106
+ return await satellites(profile).createVersion(id, payload);
107
+ })));
108
+ return versions;
109
+ }
110
+ }
111
+ export default new SatelliteCommand();
@@ -0,0 +1,96 @@
1
+ import { Command } from "commander";
2
+ import * as sdk from "../lib/sdk.js";
3
+ import { registerCommand, withProfile } from "../lib/scaffold.js";
4
+ /** `ptkl template` — project template & marketplace management (RFC §6, "Templates & marketplace").
5
+ * `search`/`available`/`install`/`upgrade`/`uninstall` map 1:1 onto the SDK `Project` client's
6
+ * template methods (@ptkl/sdk/beta).
7
+ *
8
+ * `activation-code redeem|list` do NOT map onto `Project.getTemplateByCode` — that method wraps
9
+ * `GET /v1/project/template/activationCode/{code}` (platform-api
10
+ * internal/project/controllers/template_activation_code.go), a public read-only lookup that
11
+ * resolves a code to its template's install instructions without redeeming anything. The actual
12
+ * redemption is a *different* platform subsystem — activation codes with `product_type: template`
13
+ * (also `account`/`app`/`integration`) redeemed via `POST /v1/project/codes/{code}/redeem` and
14
+ * listed via `GET /v1/project/codes/redeemed` (internal/project/controllers/code_redeem.go,
15
+ * internal/project/domain/code/service.go). The v0.10 `Project` client has no typed method for
16
+ * either route yet, so — same stopgap already used in `project.ts` for `billing-modes`/
17
+ * `auto-topup` — these two subcommands go through the authenticated client instance's public
18
+ * `.client` (an AxiosInstance, see @ptkl/sdk/beta BaseClient) rather than a named method, pending
19
+ * a follow-up SDK WP to give `Project` `redeemCode()`/`listRedeemedCodes()`. */
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
+ class TemplateCommand {
30
+ register() {
31
+ const cmd = new Command("template").description("Search, install and manage project templates");
32
+ cmd.addCommand(registerCommand(new Command("search")
33
+ .description("Search available templates")
34
+ .option("-q, --query <json>", "Search query, as a JSON object string", "{}")).action(withProfile(async (profile, opts) => {
35
+ const query = parseJSON("--query", opts.query);
36
+ const res = await sdk.project(profile).searchTemplates(query);
37
+ return res.data;
38
+ })));
39
+ cmd.addCommand(registerCommand(new Command("available").description("List templates available to the current project")).action(withProfile(async (profile) => {
40
+ const res = await sdk.project(profile).getAvailableTemplates();
41
+ return res.data;
42
+ })));
43
+ cmd.addCommand(registerCommand(new Command("install")
44
+ .description("Install a template into a workspace")
45
+ .requiredOption("-t, --template-id <uuid>", "Template UUID")
46
+ .requiredOption("-w, --workspace-uuid <uuid>", "Workspace UUID")
47
+ .option("-d, --data <json>", "Additional install options, as a JSON object string")).action(withProfile(async (profile, opts) => {
48
+ const extra = opts.data ? parseJSON("--data", opts.data) : {};
49
+ const res = await sdk
50
+ .project(profile)
51
+ .installTemplate({ template_id: opts.templateId, workspace_uuid: opts.workspaceUuid, ...extra });
52
+ return res.data;
53
+ })));
54
+ cmd.addCommand(registerCommand(new Command("upgrade")
55
+ .description("Upgrade an installed template")
56
+ .requiredOption("-t, --template-id <uuid>", "Template UUID")
57
+ .requiredOption("-w, --workspace-uuid <uuid>", "Workspace UUID")
58
+ .option("-d, --data <json>", "Additional upgrade options, as a JSON object string")).action(withProfile(async (profile, opts) => {
59
+ const extra = opts.data ? parseJSON("--data", opts.data) : {};
60
+ const res = await sdk
61
+ .project(profile)
62
+ .upgradeTemplate({ template_id: opts.templateId, workspace_uuid: opts.workspaceUuid, ...extra });
63
+ return res.data;
64
+ })));
65
+ cmd.addCommand(registerCommand(new Command("uninstall")
66
+ .description("Uninstall a template from a workspace")
67
+ .requiredOption("-t, --template-id <uuid>", "Template UUID")
68
+ .requiredOption("-w, --workspace-uuid <uuid>", "Workspace UUID")
69
+ .option("-d, --data <json>", "Additional uninstall options, as a JSON object string")).action(withProfile(async (profile, opts) => {
70
+ const extra = opts.data ? parseJSON("--data", opts.data) : {};
71
+ const res = await sdk
72
+ .project(profile)
73
+ .uninstallTemplate({ template_id: opts.templateId, workspace_uuid: opts.workspaceUuid, ...extra });
74
+ return res.data;
75
+ })));
76
+ cmd.addCommand(this.registerActivationCode());
77
+ return cmd;
78
+ }
79
+ registerActivationCode() {
80
+ const activationCode = new Command("activation-code").description("Redeem and list activation codes (account/app/integration/template benefits)");
81
+ activationCode.addCommand(registerCommand(new Command("redeem")
82
+ .description("Redeem an activation code for the current user and project")
83
+ .argument("<code>", "Activation code")).action(withProfile(async (profile, code, opts) => {
84
+ const client = sdk.project(profile);
85
+ const res = await client.client.post(`/v1/project/codes/${encodeURIComponent(code)}/redeem`);
86
+ return res.data;
87
+ })));
88
+ activationCode.addCommand(registerCommand(new Command("list").description("List activation codes redeemed by the current user")).action(withProfile(async (profile) => {
89
+ const client = sdk.project(profile);
90
+ const res = await client.client.get("/v1/project/codes/redeemed");
91
+ return res.data;
92
+ })));
93
+ return activationCode;
94
+ }
95
+ }
96
+ export default new TemplateCommand();
@@ -0,0 +1,123 @@
1
+ import { resolve } from "path";
2
+ import { readFileSync } from "fs";
3
+ import { Command } from "commander";
4
+ import * as sdk from "../lib/sdk.js";
5
+ import { registerCommand, withProfile } from "../lib/scaffold.js";
6
+ /** `ptkl thunder` — Thunder generic entity engine (RFC §4.1 "Thunder (generic entity + realtime
7
+ * cfg)": `system/thunder` read/write). Maps onto the SDK `Thunder` client (@ptkl/sdk/beta), which
8
+ * wraps the two underlying HTTP verbs (`read`/`write`) plus the typed convenience methods layered
9
+ * on top of them (`find`/`findOne`/`paginate`/`upsert`/`insertOne`/`updateOne`/`delete`). */
10
+ function parseJSON(label, raw) {
11
+ try {
12
+ return JSON.parse(raw);
13
+ }
14
+ catch {
15
+ console.error(`${label} must be valid JSON`);
16
+ process.exit(1);
17
+ }
18
+ }
19
+ /** Resolve a JSON payload from either an inline string or a file path, favoring the file when both
20
+ * are given a value. Mirrors the `-d/--data` + `-i/--file` pattern used by `component models`. */
21
+ function loadJSON(label, raw, file, fallback) {
22
+ if (file) {
23
+ return JSON.parse(readFileSync(resolve(file), "utf-8"));
24
+ }
25
+ if (raw !== undefined) {
26
+ return parseJSON(label, raw);
27
+ }
28
+ return fallback;
29
+ }
30
+ function readOptions(opts) {
31
+ const only = opts.only ? String(opts.only).split(",").map((s) => s.trim()).filter(Boolean) : undefined;
32
+ const cacheTTL = opts.cacheTtl !== undefined ? Number(opts.cacheTtl) : undefined;
33
+ if (only === undefined && cacheTTL === undefined)
34
+ return undefined;
35
+ return { ...(only ? { only } : {}), ...(cacheTTL !== undefined ? { cacheTTL } : {}) };
36
+ }
37
+ function withFilterAndReadOptions(cmd) {
38
+ return cmd
39
+ .requiredOption("-t, --type <type>", "Thunder entity type name")
40
+ .option("--filters <json>", "Filters object as a JSON string", "{}")
41
+ .option("--only <fields>", "Comma-separated list of fields to project")
42
+ .option("--cache-ttl <seconds>", "Cache TTL in seconds");
43
+ }
44
+ class ThunderCommand {
45
+ register() {
46
+ const cmd = new Command("thunder").description("Query and mutate Thunder generic entities (system/thunder)");
47
+ cmd.addCommand(registerCommand(withFilterAndReadOptions(new Command("find")).description("Find entities matching filters")).action(withProfile(async (profile, opts) => {
48
+ const filters = parseJSON("--filters", opts.filters);
49
+ const res = await sdk.thunder(profile).find(opts.type, filters, readOptions(opts));
50
+ return res.data;
51
+ })));
52
+ cmd.addCommand(registerCommand(withFilterAndReadOptions(new Command("find-one")).description("Find a single entity matching filters")).action(withProfile(async (profile, opts) => {
53
+ const filters = parseJSON("--filters", opts.filters);
54
+ const res = await sdk.thunder(profile).findOne(opts.type, filters, readOptions(opts));
55
+ return res.data;
56
+ })));
57
+ cmd.addCommand(registerCommand(withFilterAndReadOptions(new Command("paginate")).description("Paginate entities matching filters")).action(withProfile(async (profile, opts) => {
58
+ const filters = parseJSON("--filters", opts.filters);
59
+ const res = await sdk.thunder(profile).paginate(opts.type, filters, readOptions(opts));
60
+ return res.data;
61
+ })));
62
+ cmd.addCommand(registerCommand(withFilterAndReadOptions(new Command("read"))
63
+ .description("Low-level read: send a raw Thunder read flag (Find | FindOne | Paginate)")
64
+ .requiredOption("--flag <flag>", "Thunder read flag: Find | FindOne | Paginate")).action(withProfile(async (profile, opts) => {
65
+ const filters = parseJSON("--filters", opts.filters);
66
+ const res = await sdk.thunder(profile).read(opts.type, filters, opts.flag, readOptions(opts));
67
+ return res.data;
68
+ })));
69
+ cmd.addCommand(registerCommand(new Command("write")
70
+ .description("Low-level write: send a raw Thunder write flag (Upsert | InsertOne | UpdateOne | Delete | Operation)")
71
+ .requiredOption("-t, --type <type>", "Thunder entity type name")
72
+ .requiredOption("--flag <flag>", "Thunder write flag: Upsert | InsertOne | UpdateOne | Delete | Operation")
73
+ .option("--filters <json>", "Filters object as a JSON string", "{}")
74
+ .option("-d, --data <json>", "Data payload as a JSON string")
75
+ .option("-i, --file <file>", "Path to a JSON file containing the data payload")).action(withProfile(async (profile, opts) => {
76
+ const filters = parseJSON("--filters", opts.filters);
77
+ const data = loadJSON("--data", opts.data, opts.file, {});
78
+ const res = await sdk.thunder(profile).write(opts.type, filters, data, opts.flag);
79
+ return res.data;
80
+ })));
81
+ cmd.addCommand(registerCommand(new Command("upsert")
82
+ .description("Upsert an entity: update if it matches filters, otherwise insert")
83
+ .requiredOption("-t, --type <type>", "Thunder entity type name")
84
+ .option("--filters <json>", "Filters object as a JSON string", "{}")
85
+ .option("-d, --data <json>", "Data payload as a JSON string")
86
+ .option("-i, --file <file>", "Path to a JSON file containing the data payload")).action(withProfile(async (profile, opts) => {
87
+ const filters = parseJSON("--filters", opts.filters);
88
+ const data = loadJSON("--data", opts.data, opts.file, {});
89
+ const res = await sdk.thunder(profile).upsert(opts.type, filters, data);
90
+ return res.data;
91
+ })));
92
+ cmd.addCommand(registerCommand(new Command("insert-one")
93
+ .description("Insert a single entity")
94
+ .requiredOption("-t, --type <type>", "Thunder entity type name")
95
+ .option("-d, --data <json>", "Data payload as a JSON string")
96
+ .option("-i, --file <file>", "Path to a JSON file containing the data payload")).action(withProfile(async (profile, opts) => {
97
+ const data = loadJSON("--data", opts.data, opts.file, {});
98
+ const res = await sdk.thunder(profile).insertOne(opts.type, data);
99
+ return res.data;
100
+ })));
101
+ cmd.addCommand(registerCommand(new Command("update-one")
102
+ .description("Update a single entity matching filters")
103
+ .requiredOption("-t, --type <type>", "Thunder entity type name")
104
+ .option("--filters <json>", "Filters object as a JSON string", "{}")
105
+ .option("-d, --data <json>", "Data payload as a JSON string")
106
+ .option("-i, --file <file>", "Path to a JSON file containing the data payload")).action(withProfile(async (profile, opts) => {
107
+ const filters = parseJSON("--filters", opts.filters);
108
+ const data = loadJSON("--data", opts.data, opts.file, {});
109
+ const res = await sdk.thunder(profile).updateOne(opts.type, filters, data);
110
+ return res.data;
111
+ })));
112
+ cmd.addCommand(registerCommand(new Command("delete")
113
+ .description("Delete entities matching filters")
114
+ .requiredOption("-t, --type <type>", "Thunder entity type name")
115
+ .option("--filters <json>", "Filters object as a JSON string", "{}")).action(withProfile(async (profile, opts) => {
116
+ const filters = parseJSON("--filters", opts.filters);
117
+ const res = await sdk.thunder(profile).delete(opts.type, filters);
118
+ return res.data;
119
+ })));
120
+ return cmd;
121
+ }
122
+ }
123
+ export default new ThunderCommand();
@@ -1,34 +1,46 @@
1
1
  import { Command } from "commander";
2
2
  import util from "../lib/util.js";
3
- import { Platform as Api } from "@ptkl/sdk";
4
- class ApiUsersCommand {
3
+ import { project } from "../lib/sdk.js";
4
+ import OutputFormatCommand from "./outputCommand.js";
5
+ class UsersCommand {
5
6
  register() {
6
7
  return new Command("users")
7
- .description("Manage users")
8
+ .description("Manage users in the current project")
8
9
  .version("0.1.0")
9
- .addCommand(new Command("invite")
10
- .description("Invite a new user")
11
- .requiredOption("-e, --email <email>", "user email ")
12
- .requiredOption("-r, --roles <roles...>", "uuids of role separated by space")
13
- .action(this.invite))
14
- .addCommand(new Command("delete")
15
- .description("Remove user from project")
16
- .requiredOption("-u, --uuid <uuid>", "UUID of the existing user")
17
- .action(this.delete));
10
+ .addCommand(new OutputFormatCommand(new Command("invite")
11
+ .description("Invite a user to the current project")
12
+ .requiredOption("-e, --email <email>", "Email address to invite")
13
+ .requiredOption("-r, --roles <roles...>", "UUIDs of roles to grant, space separated")).action(this.invite))
14
+ .addCommand(new OutputFormatCommand(new Command("delete")
15
+ .description("Remove a user from the current project")
16
+ .requiredOption("-u, --uuid <uuid>", "UUID of the user to remove")).action(this.delete))
17
+ .addCommand(new OutputFormatCommand(new Command("list").description("List users in the current project")).action(this.list))
18
+ .addCommand(new OutputFormatCommand(new Command("get")
19
+ .description("Get a project user by UUID")
20
+ .requiredOption("-u, --uuid <uuid>", "UUID of the user")).action(this.get));
18
21
  }
19
22
  async invite(opts) {
20
23
  const { email, roles } = opts;
21
24
  const profile = util.getCurrentProfile();
22
- const client = new Api({ token: profile.token, host: profile.host }).user();
23
- const secret = await client.invite(email, roles);
24
- console.table([secret]);
25
+ const resp = await project(profile).invite([email], roles);
26
+ return resp.data;
25
27
  }
26
28
  async delete(opts) {
27
29
  const { uuid } = opts;
28
30
  const profile = util.getCurrentProfile();
29
- const client = new Api({ token: profile.token, host: profile.host }).user();
30
- const status = await client.delete(uuid);
31
- console.table([status]);
31
+ const resp = await project(profile).deleteUser(uuid);
32
+ return resp.data;
33
+ }
34
+ async list() {
35
+ const profile = util.getCurrentProfile();
36
+ const resp = await project(profile).getUsers();
37
+ return resp.data;
38
+ }
39
+ async get(opts) {
40
+ const { uuid } = opts;
41
+ const profile = util.getCurrentProfile();
42
+ const resp = await project(profile).getUser(uuid);
43
+ return resp.data;
32
44
  }
33
45
  }
34
- export default new ApiUsersCommand();
46
+ export default new UsersCommand();