@smartlyqofficial/cli 0.1.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,90 @@
1
+ import { Command } from 'commander';
2
+ import { ClientOptions } from '@smartlyqofficial/node';
3
+
4
+ /** One CLI command: `smartlyq <resource> <kebabMethod> [pathArgs...]` -> SDK `sq[resourceKey][methodName](...)`. */
5
+ interface CommandDescriptor {
6
+ resourceKey: string;
7
+ methodName: string;
8
+ kebabMethod: string;
9
+ /** camelCase path parameter names, in call order. */
10
+ pathParams: string[];
11
+ hasBody: boolean;
12
+ bodyRequired: boolean;
13
+ hasQuery: boolean;
14
+ summary: string;
15
+ httpMethod: string;
16
+ path: string;
17
+ }
18
+ declare const commands: CommandDescriptor[];
19
+
20
+ type OutputMode = 'json' | 'pretty';
21
+ /**
22
+ * Parses a `--data` value into a request body.
23
+ * Accepts inline JSON, `@file.json` to read a file, or `-` to read stdin.
24
+ */
25
+ declare function parseData(raw: string, readStdin?: () => string): unknown;
26
+ /**
27
+ * Parses a `--query` value: either `k=v&k2=v2` pairs or a raw JSON object.
28
+ * Repeated keys in pair form become arrays.
29
+ */
30
+ declare function parseQuery(raw: string): Record<string, unknown>;
31
+ /** Renders a successful result. `pretty` (default) is colorless indented JSON. */
32
+ declare function formatOutput(result: unknown, mode?: OutputMode): string;
33
+ /** Renders any thrown error as a single stderr line. */
34
+ declare function formatError(err: unknown): string;
35
+
36
+ /** Config directory (`~/.smartlyq`, overridable via SMARTLYQ_CONFIG_DIR for tests). */
37
+ declare function configDir(): string;
38
+ declare function configPath(): string;
39
+ /** The API key stored by `smartlyq login`, if any. */
40
+ declare function readStoredApiKey(): string | undefined;
41
+ /** Persists the API key with owner-only permissions. */
42
+ declare function storeApiKey(apiKey: string): string;
43
+ /** Deletes the stored config. Returns true if a file was removed. */
44
+ declare function deleteStoredApiKey(): boolean;
45
+ /** Resolves the API key: flag > SMARTLYQ_API_KEY env > config file. */
46
+ declare function resolveApiKey(flagValue?: string): string | undefined;
47
+
48
+ /** Prompts on the terminal without echoing the typed characters. */
49
+ declare function promptHidden(prompt: string): Promise<string>;
50
+ declare function runLogin(): Promise<void>;
51
+ declare function runLogout(): void;
52
+
53
+ /** Shared naming helpers for the CLI and its generators. */
54
+ /** Renders a camelCase SDK name as the kebab-case CLI name (createPost -> create-post). */
55
+ declare function kebabCase(name: string): string;
56
+ /** Error for user-facing CLI failures (bad input, missing key). Always exits 1. */
57
+ declare class CliError extends Error {
58
+ constructor(message: string);
59
+ }
60
+
61
+ /**
62
+ * SmartlyQ CLI: builds the commander tree from the generated command
63
+ * descriptors and dispatches through the official Node.js SDK.
64
+ *
65
+ * smartlyq <resource> <method> [pathArgs...] [flags]
66
+ * smartlyq social create-post --data '{"text":"hi","account_ids":["acc_1"]}'
67
+ */
68
+
69
+ /** Flag values collected by commander for a resource/method command. */
70
+ interface DispatchFlags {
71
+ data?: string;
72
+ query?: string;
73
+ profile?: string;
74
+ idempotencyKey?: string;
75
+ apiKey?: string;
76
+ baseUrl?: string;
77
+ timeout?: string | number;
78
+ output?: OutputMode;
79
+ }
80
+ /**
81
+ * Executes one command descriptor against the SDK and returns the API result.
82
+ * `overrides` lets tests inject a fake fetch via the SDK's ClientOptions.
83
+ */
84
+ declare function dispatch(desc: CommandDescriptor, pathArgs: string[], flags?: DispatchFlags, overrides?: Partial<ClientOptions>): Promise<unknown>;
85
+ /** Builds the full commander program from the generated descriptors. */
86
+ declare function buildProgram(): Command;
87
+ /** CLI entry point. */
88
+ declare function main(argv?: string[]): Promise<void>;
89
+
90
+ export { CliError, type CommandDescriptor, type DispatchFlags, type OutputMode, buildProgram, commands, configDir, configPath, deleteStoredApiKey, dispatch, formatError, formatOutput, kebabCase, main, parseData, parseQuery, promptHidden, readStoredApiKey, resolveApiKey, runLogin, runLogout, storeApiKey };
@@ -0,0 +1,90 @@
1
+ import { Command } from 'commander';
2
+ import { ClientOptions } from '@smartlyqofficial/node';
3
+
4
+ /** One CLI command: `smartlyq <resource> <kebabMethod> [pathArgs...]` -> SDK `sq[resourceKey][methodName](...)`. */
5
+ interface CommandDescriptor {
6
+ resourceKey: string;
7
+ methodName: string;
8
+ kebabMethod: string;
9
+ /** camelCase path parameter names, in call order. */
10
+ pathParams: string[];
11
+ hasBody: boolean;
12
+ bodyRequired: boolean;
13
+ hasQuery: boolean;
14
+ summary: string;
15
+ httpMethod: string;
16
+ path: string;
17
+ }
18
+ declare const commands: CommandDescriptor[];
19
+
20
+ type OutputMode = 'json' | 'pretty';
21
+ /**
22
+ * Parses a `--data` value into a request body.
23
+ * Accepts inline JSON, `@file.json` to read a file, or `-` to read stdin.
24
+ */
25
+ declare function parseData(raw: string, readStdin?: () => string): unknown;
26
+ /**
27
+ * Parses a `--query` value: either `k=v&k2=v2` pairs or a raw JSON object.
28
+ * Repeated keys in pair form become arrays.
29
+ */
30
+ declare function parseQuery(raw: string): Record<string, unknown>;
31
+ /** Renders a successful result. `pretty` (default) is colorless indented JSON. */
32
+ declare function formatOutput(result: unknown, mode?: OutputMode): string;
33
+ /** Renders any thrown error as a single stderr line. */
34
+ declare function formatError(err: unknown): string;
35
+
36
+ /** Config directory (`~/.smartlyq`, overridable via SMARTLYQ_CONFIG_DIR for tests). */
37
+ declare function configDir(): string;
38
+ declare function configPath(): string;
39
+ /** The API key stored by `smartlyq login`, if any. */
40
+ declare function readStoredApiKey(): string | undefined;
41
+ /** Persists the API key with owner-only permissions. */
42
+ declare function storeApiKey(apiKey: string): string;
43
+ /** Deletes the stored config. Returns true if a file was removed. */
44
+ declare function deleteStoredApiKey(): boolean;
45
+ /** Resolves the API key: flag > SMARTLYQ_API_KEY env > config file. */
46
+ declare function resolveApiKey(flagValue?: string): string | undefined;
47
+
48
+ /** Prompts on the terminal without echoing the typed characters. */
49
+ declare function promptHidden(prompt: string): Promise<string>;
50
+ declare function runLogin(): Promise<void>;
51
+ declare function runLogout(): void;
52
+
53
+ /** Shared naming helpers for the CLI and its generators. */
54
+ /** Renders a camelCase SDK name as the kebab-case CLI name (createPost -> create-post). */
55
+ declare function kebabCase(name: string): string;
56
+ /** Error for user-facing CLI failures (bad input, missing key). Always exits 1. */
57
+ declare class CliError extends Error {
58
+ constructor(message: string);
59
+ }
60
+
61
+ /**
62
+ * SmartlyQ CLI: builds the commander tree from the generated command
63
+ * descriptors and dispatches through the official Node.js SDK.
64
+ *
65
+ * smartlyq <resource> <method> [pathArgs...] [flags]
66
+ * smartlyq social create-post --data '{"text":"hi","account_ids":["acc_1"]}'
67
+ */
68
+
69
+ /** Flag values collected by commander for a resource/method command. */
70
+ interface DispatchFlags {
71
+ data?: string;
72
+ query?: string;
73
+ profile?: string;
74
+ idempotencyKey?: string;
75
+ apiKey?: string;
76
+ baseUrl?: string;
77
+ timeout?: string | number;
78
+ output?: OutputMode;
79
+ }
80
+ /**
81
+ * Executes one command descriptor against the SDK and returns the API result.
82
+ * `overrides` lets tests inject a fake fetch via the SDK's ClientOptions.
83
+ */
84
+ declare function dispatch(desc: CommandDescriptor, pathArgs: string[], flags?: DispatchFlags, overrides?: Partial<ClientOptions>): Promise<unknown>;
85
+ /** Builds the full commander program from the generated descriptors. */
86
+ declare function buildProgram(): Command;
87
+ /** CLI entry point. */
88
+ declare function main(argv?: string[]): Promise<void>;
89
+
90
+ export { CliError, type CommandDescriptor, type DispatchFlags, type OutputMode, buildProgram, commands, configDir, configPath, deleteStoredApiKey, dispatch, formatError, formatOutput, kebabCase, main, parseData, parseQuery, promptHidden, readStoredApiKey, resolveApiKey, runLogin, runLogout, storeApiKey };