@kelviq/cli 0.1.1

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.
Files changed (99) hide show
  1. package/README.md +313 -0
  2. package/dist/cli-ui/auth-hint.d.ts +6 -0
  3. package/dist/cli-ui/auth-hint.js +34 -0
  4. package/dist/cli-ui/auth-hint.js.map +1 -0
  5. package/dist/cli-ui/hints.d.ts +5 -0
  6. package/dist/cli-ui/hints.js +19 -0
  7. package/dist/cli-ui/hints.js.map +1 -0
  8. package/dist/cli-ui/spinner.d.ts +7 -0
  9. package/dist/cli-ui/spinner.js +61 -0
  10. package/dist/cli-ui/spinner.js.map +1 -0
  11. package/dist/cli-ui/style.d.ts +47 -0
  12. package/dist/cli-ui/style.js +71 -0
  13. package/dist/cli-ui/style.js.map +1 -0
  14. package/dist/cli-ui/tty.d.ts +1 -0
  15. package/dist/cli-ui/tty.js +13 -0
  16. package/dist/cli-ui/tty.js.map +1 -0
  17. package/dist/cli.d.ts +2 -0
  18. package/dist/cli.js +51 -0
  19. package/dist/cli.js.map +1 -0
  20. package/dist/commands/env.d.ts +34 -0
  21. package/dist/commands/env.js +52 -0
  22. package/dist/commands/env.js.map +1 -0
  23. package/dist/commands/init.d.ts +15 -0
  24. package/dist/commands/init.js +70 -0
  25. package/dist/commands/init.js.map +1 -0
  26. package/dist/commands/login.d.ts +22 -0
  27. package/dist/commands/login.js +205 -0
  28. package/dist/commands/login.js.map +1 -0
  29. package/dist/commands/logout.d.ts +13 -0
  30. package/dist/commands/logout.js +39 -0
  31. package/dist/commands/logout.js.map +1 -0
  32. package/dist/commands/promote.d.ts +42 -0
  33. package/dist/commands/promote.js +243 -0
  34. package/dist/commands/promote.js.map +1 -0
  35. package/dist/commands/pull.d.ts +31 -0
  36. package/dist/commands/pull.js +108 -0
  37. package/dist/commands/pull.js.map +1 -0
  38. package/dist/commands/push-shared.d.ts +97 -0
  39. package/dist/commands/push-shared.js +283 -0
  40. package/dist/commands/push-shared.js.map +1 -0
  41. package/dist/commands/push.d.ts +42 -0
  42. package/dist/commands/push.js +268 -0
  43. package/dist/commands/push.js.map +1 -0
  44. package/dist/config-format/builders.d.ts +10 -0
  45. package/dist/config-format/builders.js +46 -0
  46. package/dist/config-format/builders.js.map +1 -0
  47. package/dist/config-format/index.d.ts +4 -0
  48. package/dist/config-format/index.js +9 -0
  49. package/dist/config-format/index.js.map +1 -0
  50. package/dist/config-format/load.d.ts +23 -0
  51. package/dist/config-format/load.js +82 -0
  52. package/dist/config-format/load.js.map +1 -0
  53. package/dist/config-format/schema.d.ts +423 -0
  54. package/dist/config-format/schema.js +105 -0
  55. package/dist/config-format/schema.js.map +1 -0
  56. package/dist/core/config.d.ts +48 -0
  57. package/dist/core/config.js +128 -0
  58. package/dist/core/config.js.map +1 -0
  59. package/dist/core/errors.d.ts +20 -0
  60. package/dist/core/errors.js +58 -0
  61. package/dist/core/errors.js.map +1 -0
  62. package/dist/core/http.d.ts +39 -0
  63. package/dist/core/http.js +104 -0
  64. package/dist/core/http.js.map +1 -0
  65. package/dist/core/version.d.ts +1 -0
  66. package/dist/core/version.js +14 -0
  67. package/dist/core/version.js.map +1 -0
  68. package/dist/generated/openapi.json +6635 -0
  69. package/dist/sync/apply.d.ts +38 -0
  70. package/dist/sync/apply.js +234 -0
  71. package/dist/sync/apply.js.map +1 -0
  72. package/dist/sync/diff.d.ts +186 -0
  73. package/dist/sync/diff.js +402 -0
  74. package/dist/sync/diff.js.map +1 -0
  75. package/dist/sync/fetch-catalog.d.ts +105 -0
  76. package/dist/sync/fetch-catalog.js +100 -0
  77. package/dist/sync/fetch-catalog.js.map +1 -0
  78. package/dist/sync/price-filter.d.ts +37 -0
  79. package/dist/sync/price-filter.js +195 -0
  80. package/dist/sync/price-filter.js.map +1 -0
  81. package/dist/sync/prune.d.ts +77 -0
  82. package/dist/sync/prune.js +112 -0
  83. package/dist/sync/prune.js.map +1 -0
  84. package/dist/sync/publish.d.ts +75 -0
  85. package/dist/sync/publish.js +126 -0
  86. package/dist/sync/publish.js.map +1 -0
  87. package/dist/sync/push-plan-json.d.ts +79 -0
  88. package/dist/sync/push-plan-json.js +70 -0
  89. package/dist/sync/push-plan-json.js.map +1 -0
  90. package/dist/sync/render-plan.d.ts +83 -0
  91. package/dist/sync/render-plan.js +358 -0
  92. package/dist/sync/render-plan.js.map +1 -0
  93. package/dist/sync/serialize.d.ts +18 -0
  94. package/dist/sync/serialize.js +108 -0
  95. package/dist/sync/serialize.js.map +1 -0
  96. package/dist/sync/to-config.d.ts +9 -0
  97. package/dist/sync/to-config.js +191 -0
  98. package/dist/sync/to-config.js.map +1 -0
  99. package/package.json +68 -0
@@ -0,0 +1,105 @@
1
+ // The `kelviq.config.ts` format — zod schemas for pricing-as-code.
2
+ //
3
+ // IDENTITY RULE (load-bearing, see CLI plan 004 maintenance notes): every
4
+ // cross-reference in this format (plan.product, entitlement.feature) is a
5
+ // stable `identifier` slug, never a UUID. The API sometimes wants UUIDs
6
+ // (plan creation takes a product UUID; entitlement attachment takes feature
7
+ // UUIDs) — that resolution happens at push/pull time (plans 005/006), not
8
+ // here. Do not add a UUID field to this format.
9
+ //
10
+ // The plan lifecycle (DRAFT -> publish) is deliberately absent: this format
11
+ // describes desired state; lifecycle is push's concern.
12
+ import { z } from 'zod';
13
+ /** URL-safe slug used as the sole cross-reference key throughout the config. */
14
+ export const identifierSchema = z
15
+ .string()
16
+ .regex(/^[a-z0-9][a-z0-9-_]*$/, 'must be a lowercase, URL-safe slug starting with a letter or digit (e.g. "my-plan")');
17
+ // Sourced from src/generated/openapi.json:
18
+ // components.schemas.ProductCreateRequest.properties.taxCode.enum
19
+ // Hardcoded (not read at runtime) per CLI plan 004 Step 1 — re-verify against
20
+ // a fresh `npm run snapshot` if the API starts rejecting a previously-valid
21
+ // taxCode.
22
+ export const taxCodeSchema = z.enum([
23
+ 'saas',
24
+ 'saas_business',
25
+ 'software',
26
+ 'videocontent',
27
+ 'informationservice',
28
+ 'ebook',
29
+ 'digitalgraphic',
30
+ 'videogame',
31
+ 'eservice',
32
+ 'training',
33
+ ]);
34
+ export const featureTypeSchema = z.enum(['BOOLEAN', 'CUSTOMIZABLE', 'METER']);
35
+ export const resetSchema = z.enum(['NEVER', 'EVERY_DAY', 'EVERY_MONTH', 'EVERY_QUARTER', 'EVERY_YEAR']);
36
+ export const taxBehaviorSchema = z.enum(['INCLUSIVE', 'EXCLUSIVE', 'UNSPECIFIED']);
37
+ export const priceTypeSchema = z.enum(['FREE', 'PAID', 'CUSTOM']);
38
+ export const featureDefSchema = z.object({
39
+ identifier: identifierSchema,
40
+ name: z.string().min(1),
41
+ type: featureTypeSchema,
42
+ description: z.string().optional(),
43
+ featureDetails: z.record(z.unknown()).optional(),
44
+ meter: z.record(z.unknown()).optional(),
45
+ metadata: z.record(z.unknown()).optional(),
46
+ });
47
+ // Entitlement shape varies by featureType and the API accepts extra keys —
48
+ // `.passthrough()` so callers can pass forward whatever the API needs
49
+ // without this format having to track every field.
50
+ export const entitlementDefSchema = z
51
+ .object({
52
+ feature: identifierSchema,
53
+ value: z.union([z.boolean(), z.number()]).optional(),
54
+ hasUnlimitedUsage: z.boolean().optional(),
55
+ reset: resetSchema.optional(),
56
+ // boolean, not number — confirmed by src/generated/openapi.json (e.g.
57
+ // the entitlement-details schema's `hardLimit: { "type": "boolean" }`)
58
+ // and by live `kelviq pull` behavior (plan 005) rejecting real API
59
+ // responses that return `hardLimit: false`/`true`.
60
+ hardLimit: z.boolean().optional(),
61
+ usageAlerts: z.record(z.unknown()).optional(),
62
+ })
63
+ .passthrough();
64
+ // Prices nest deeply and vary per charge type (chargeCatalogPrice). This is
65
+ // deliberately loose: validate the envelope, pass the depths through
66
+ // untouched. Do NOT enumerate charge shapes here — see CLI plan 004 STOP
67
+ // conditions.
68
+ export const priceDefSchema = z
69
+ .object({
70
+ priceType: priceTypeSchema,
71
+ currency: z.string().optional(),
72
+ // Documented as boolean/int respectively in the API's own request
73
+ // schemas — tightened from z.unknown() (which overshoots the
74
+ // loose-envelope intent) per CLI plan 004 review. Loosening a field
75
+ // later is safe; tightening later is a breaking change, so these two
76
+ // stay typed even though the rest of the price envelope is deliberately
77
+ // loose.
78
+ freeTrial: z.boolean().optional(),
79
+ trialPeriod: z.number().optional(),
80
+ taxBehavior: taxBehaviorSchema.optional(),
81
+ chargeCatalogPrice: z.array(z.record(z.unknown())).optional(),
82
+ })
83
+ .passthrough();
84
+ export const planDefSchema = z.object({
85
+ identifier: identifierSchema,
86
+ name: z.string().min(1),
87
+ product: identifierSchema,
88
+ description: z.string().optional(),
89
+ isVisible: z.boolean().optional(),
90
+ entitlements: z.array(entitlementDefSchema).optional(),
91
+ prices: z.array(priceDefSchema).optional(),
92
+ metadata: z.record(z.unknown()).optional(),
93
+ });
94
+ export const productDefSchema = z.object({
95
+ identifier: identifierSchema,
96
+ name: z.string().min(1),
97
+ taxCode: taxCodeSchema,
98
+ description: z.string().optional(),
99
+ });
100
+ export const kelviqConfigSchema = z.object({
101
+ products: z.array(productDefSchema),
102
+ features: z.array(featureDefSchema),
103
+ plans: z.array(planDefSchema),
104
+ });
105
+ //# sourceMappingURL=schema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema.js","sourceRoot":"","sources":["../../src/config-format/schema.ts"],"names":[],"mappings":"AAAA,mEAAmE;AACnE,EAAE;AACF,0EAA0E;AAC1E,0EAA0E;AAC1E,wEAAwE;AACxE,4EAA4E;AAC5E,0EAA0E;AAC1E,gDAAgD;AAChD,EAAE;AACF,4EAA4E;AAC5E,wDAAwD;AACxD,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,gFAAgF;AAChF,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC;KAC9B,MAAM,EAAE;KACR,KAAK,CAAC,uBAAuB,EAAE,qFAAqF,CAAC,CAAC;AAEzH,2CAA2C;AAC3C,oEAAoE;AACpE,8EAA8E;AAC9E,4EAA4E;AAC5E,WAAW;AACX,MAAM,CAAC,MAAM,aAA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AM,aAAa,GAAG,CAAC,CAAC,MAAM,CAAC;IACpC,UAAU,EAAE,gBAAgB;IAC5B,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IACvB,OAAO,EAAE,gBAAgB;IACzB,WAAW,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAClC,SAAS,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,QAAQ,EAAE;IACjC,YAAY,EAAE,CAAC,CAAC,KAAK,CAAC,oBAAoB,CAAC,CAAC,QAAQ,EAAE;IACtD,MAAM,EAAE,CAAC,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC,QAAQ,EAAE;IAC1C,QAAQ,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,QAAQ,EAAE;CAC3C,CAAC,CAAC;AAGH,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,CAAC,MAAM,CAAC;IACvC,UAAU,EAAE,gBAAgB;IAC5B,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IACvB,OAAO,EAAE,aAAa;IACtB,WAAW,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;CACnC,CAAC,CAAC;AAGH,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,CAAC,MAAM,CAAC;IACzC,QAAQ,EAAE,CAAC,CAAC,KAAK,CAAC,gBAAgB,CAAC;IACnC,QAAQ,EAAE,CAAC,CAAC,KAAK,CAAC,gBAAgB,CAAC;IACnC,KAAK,EAAE,CAAC,CAAC,KAAK,CAAC,aAAa,CAAC;CAC9B,CAAC,CAAC"}
@@ -0,0 +1,48 @@
1
+ export interface CliConfig {
2
+ prodServerApiKey?: string;
3
+ sandboxServerApiKey?: string;
4
+ /** Production API host (`https://api.kelviq.com/api/v1` by default). */
5
+ baseUrl: string;
6
+ /** Sandbox API host (`https://sandboxapi.kelviq.com/api/v1` by default). */
7
+ sandboxBaseUrl: string;
8
+ edgeUrl: string;
9
+ userAgent: string;
10
+ }
11
+ /** Shape of the on-disk user config file (~/.config/kelviq/config.json). */
12
+ export interface UserConfigFile {
13
+ prodServerApiKey?: string;
14
+ sandboxServerApiKey?: string;
15
+ }
16
+ /**
17
+ * Loads the layered CLI config: env vars win over the user config file.
18
+ * Command-line flag overrides are applied by callers on top of this result
19
+ * (flags are the highest-priority layer but aren't known here).
20
+ *
21
+ * `env` and `configDir` are injectable for tests; `process.env` is never
22
+ * mutated.
23
+ */
24
+ export declare function loadCliConfig(env?: NodeJS.ProcessEnv, configDir?: string): CliConfig;
25
+ /**
26
+ * Read-modify-write patch of the user config file. Creates the directory
27
+ * (mode 0700) and file (mode 0600) if missing — the file holds API keys, so
28
+ * permissions are tightened explicitly rather than trusting umask.
29
+ */
30
+ export declare function writeUserConfig(patch: Partial<UserConfigFile>, configDir?: string): void;
31
+ /** Removes a single key from the user config file, if present. */
32
+ export declare function deleteUserConfigKey(key: keyof UserConfigFile, configDir?: string): void;
33
+ export interface ResolvedEnv {
34
+ key: string;
35
+ baseUrl: string;
36
+ envName: 'sandbox' | 'production';
37
+ }
38
+ /**
39
+ * Picks the sandbox key by default; the production key when `prod` is true.
40
+ * Throws when the relevant key isn't configured, naming the missing env var,
41
+ * the dashboard URL, and the fix.
42
+ */
43
+ export declare function resolveEnv(config: CliConfig, prod: boolean): ResolvedEnv;
44
+ export declare class MissingKeyError extends Error {
45
+ readonly envVar: string;
46
+ readonly envName: 'sandbox' | 'production';
47
+ constructor(envVar: string, envName: 'sandbox' | 'production');
48
+ }
@@ -0,0 +1,128 @@
1
+ // Ported from kelviq-mcp-server src/config.ts @ e680c70 — keep in sync manually.
2
+ // Extended for CLI needs beyond the source: a layered config (flags > env >
3
+ // user config file) and sandbox-by-default environment resolution
4
+ // (resolveEnv). The source's single `serverApiKey` becomes two keys here
5
+ // (`prodServerApiKey` / `sandboxServerApiKey`) because the CLI must pick
6
+ // between a sandbox and a production environment per invocation — every
7
+ // Kelviq org has a sandbox environment, and the CLI targets it unless
8
+ // `--prod` is passed.
9
+ //
10
+ // NOTE: the env var names below (KELVIQ_SERVER_API_KEY /
11
+ // KELVIQ_SANDBOX_SERVER_API_KEY) are PROVISIONAL, per the platform maintainer
12
+ // (2026-07-08) — not yet documented anywhere else. They're isolated here so a
13
+ // rename is a one-file change.
14
+ import { chmodSync, existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
15
+ import { homedir } from 'node:os';
16
+ import { join } from 'node:path';
17
+ import { getPackageVersion } from './version.js';
18
+ const DEFAULT_BASE_URL = 'https://api.kelviq.com/api/v1';
19
+ const DEFAULT_SANDBOX_BASE_URL = 'https://sandboxapi.kelviq.com/api/v1';
20
+ const DEFAULT_EDGE_URL = 'https://edge.api.kelviq.com/api/v1';
21
+ const CONFIG_FILE_NAME = 'config.json';
22
+ function defaultConfigDir(env) {
23
+ const xdg = env.XDG_CONFIG_HOME?.trim();
24
+ const base = xdg || join(homedir(), '.config');
25
+ return join(base, 'kelviq');
26
+ }
27
+ function configFilePath(dir) {
28
+ return join(dir, CONFIG_FILE_NAME);
29
+ }
30
+ function readUserConfig(dir) {
31
+ const path = configFilePath(dir);
32
+ if (!existsSync(path))
33
+ return {};
34
+ try {
35
+ const raw = readFileSync(path, 'utf8');
36
+ const parsed = JSON.parse(raw);
37
+ return typeof parsed === 'object' && parsed !== null ? parsed : {};
38
+ }
39
+ catch {
40
+ return {};
41
+ }
42
+ }
43
+ /**
44
+ * Loads the layered CLI config: env vars win over the user config file.
45
+ * Command-line flag overrides are applied by callers on top of this result
46
+ * (flags are the highest-priority layer but aren't known here).
47
+ *
48
+ * `env` and `configDir` are injectable for tests; `process.env` is never
49
+ * mutated.
50
+ */
51
+ export function loadCliConfig(env = process.env, configDir) {
52
+ const stripSlash = (u) => u.replace(/\/+$/, '');
53
+ const dir = configDir ?? defaultConfigDir(env);
54
+ const fileConfig = readUserConfig(dir);
55
+ const prodServerApiKey = env.KELVIQ_SERVER_API_KEY?.trim() || fileConfig.prodServerApiKey || undefined;
56
+ const sandboxServerApiKey = env.KELVIQ_SANDBOX_SERVER_API_KEY?.trim() || fileConfig.sandboxServerApiKey || undefined;
57
+ const baseUrl = stripSlash(env.KELVIQ_BASE_URL?.trim() || DEFAULT_BASE_URL);
58
+ const sandboxBaseUrl = stripSlash(env.KELVIQ_SANDBOX_BASE_URL?.trim() || DEFAULT_SANDBOX_BASE_URL);
59
+ const edgeUrl = stripSlash(env.KELVIQ_EDGE_URL?.trim() || DEFAULT_EDGE_URL);
60
+ return {
61
+ prodServerApiKey,
62
+ sandboxServerApiKey,
63
+ baseUrl,
64
+ sandboxBaseUrl,
65
+ edgeUrl,
66
+ userAgent: `kelviq-cli/${getPackageVersion()} (+https://kelviq.com)`,
67
+ };
68
+ }
69
+ /**
70
+ * Read-modify-write patch of the user config file. Creates the directory
71
+ * (mode 0700) and file (mode 0600) if missing — the file holds API keys, so
72
+ * permissions are tightened explicitly rather than trusting umask.
73
+ */
74
+ export function writeUserConfig(patch, configDir) {
75
+ const dir = configDir ?? defaultConfigDir(process.env);
76
+ if (!existsSync(dir)) {
77
+ mkdirSync(dir, { recursive: true, mode: 0o700 });
78
+ }
79
+ const current = readUserConfig(dir);
80
+ const next = { ...current, ...patch };
81
+ const path = configFilePath(dir);
82
+ writeFileSync(path, JSON.stringify(next, null, 2) + '\n', { mode: 0o600 });
83
+ // writeFileSync's `mode` only applies when the file is newly created; force
84
+ // it explicitly so a pre-existing, more permissive file also gets tightened.
85
+ chmodSync(path, 0o600);
86
+ }
87
+ /** Removes a single key from the user config file, if present. */
88
+ export function deleteUserConfigKey(key, configDir) {
89
+ const dir = configDir ?? defaultConfigDir(process.env);
90
+ const current = readUserConfig(dir);
91
+ if (!(key in current))
92
+ return;
93
+ delete current[key];
94
+ const path = configFilePath(dir);
95
+ writeFileSync(path, JSON.stringify(current, null, 2) + '\n', { mode: 0o600 });
96
+ chmodSync(path, 0o600);
97
+ }
98
+ /**
99
+ * Picks the sandbox key by default; the production key when `prod` is true.
100
+ * Throws when the relevant key isn't configured, naming the missing env var,
101
+ * the dashboard URL, and the fix.
102
+ */
103
+ export function resolveEnv(config, prod) {
104
+ const envName = prod ? 'production' : 'sandbox';
105
+ const key = prod ? config.prodServerApiKey : config.sandboxServerApiKey;
106
+ if (!key) {
107
+ const envVar = prod ? 'KELVIQ_SERVER_API_KEY' : 'KELVIQ_SANDBOX_SERVER_API_KEY';
108
+ throw new MissingKeyError(envVar, envName);
109
+ }
110
+ const baseUrl = prod ? config.baseUrl : config.sandboxBaseUrl;
111
+ return { key, baseUrl, envName };
112
+ }
113
+ export class MissingKeyError extends Error {
114
+ envVar;
115
+ envName;
116
+ constructor(envVar, envName) {
117
+ // Naming asymmetry: the CLI/API call this "production", but the
118
+ // dashboard's query param calls it `live` — that spelling stays
119
+ // confined to the URL and never leaks into this message's wording.
120
+ const mode = envName === 'production' ? 'live' : 'sandbox';
121
+ super(`Missing ${envVar}. Run \`kelviq login\` or set ${envVar} to use the ${envName} environment. ` +
122
+ `Get keys at https://app.kelviq.com/settings/api-keys?mode=${mode}.`);
123
+ this.envVar = envVar;
124
+ this.envName = envName;
125
+ this.name = 'MissingKeyError';
126
+ }
127
+ }
128
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/core/config.ts"],"names":[],"mappings":"AAAA,iFAAiF;AACjF,4EAA4E;AAC5E,kEAAkE;AAClE,yEAAyE;AACzE,yEAAyE;AACzE,wEAAwE;AACxE,sEAAsE;AACtE,sBAAsB;AACtB,EAAE;AACF,yDAAyD;AACzD,8EAA8E;AAC9E,8EAA8E;AAC9E,+BAA+B;AAC/B,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,SAAS,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACxF,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC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T,MAAM,MAAM,GAAG,IAAI,CAAC,CAAC,CAAC,uBAAuB,CAAC,CAAC,CAAC,+BAA+B,CAAC;QAChF,MAAM,IAAI,eAAe,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC7C,CAAC;IACD,MAAM,OAAO,GAAG,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,cAAc,CAAC;IAC9D,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC;AACnC,CAAC;AAED,MAAM,OAAO,eAAgB,SAAQ,KAAK;IACZ;IAAgC;IAA5D,YAA4B,MAAc,EAAkB,OAAiC;QAC3F,gEAAgE;QAChE,gEAAgE;QAChE,mEAAmE;QACnE,MAAM,IAAI,GAAG,OAAO,KAAK,YAAY,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC;QAC3D,KAAK,CACH,WAAW,MAAM,iCAAiC,MAAM,eAAe,OAAO,gBAAgB;YAC5F,6DAA6D,IAAI,GAAG,CACvE,CAAC;QARwB,WAAM,GAAN,MAAM,CAAQ;QAAkB,YAAO,GAAP,OAAO,CAA0B;QAS3F,IAAI,CAAC,IAAI,GAAG,iBAAiB,CAAC;IAChC,CAAC;CACF"}
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Normalized error shape returned to CLI callers.
3
+ *
4
+ * Kelviq returns two error shapes in the wild:
5
+ * - { status, message } (ErrorResponse)
6
+ * - { detail } (DetailErrorResponse)
7
+ * Plus the usual network / serialization failures. We collapse all of these
8
+ * into KelviqAPIError so command implementations don't have to branch.
9
+ */
10
+ export interface KelviqAPIError {
11
+ error: {
12
+ status: string;
13
+ message: string;
14
+ httpStatus?: number;
15
+ raw?: unknown;
16
+ };
17
+ }
18
+ export declare function isKelviqAPIError(value: unknown): value is KelviqAPIError;
19
+ export declare function fromHttpResponse(httpStatus: number, body: unknown): KelviqAPIError;
20
+ export declare function fromException(err: unknown): KelviqAPIError;
@@ -0,0 +1,58 @@
1
+ export function isKelviqAPIError(value) {
2
+ return (typeof value === 'object' &&
3
+ value !== null &&
4
+ 'error' in value &&
5
+ typeof value.error === 'object');
6
+ }
7
+ export function fromHttpResponse(httpStatus, body) {
8
+ if (typeof body === 'object' && body !== null) {
9
+ const obj = body;
10
+ if (typeof obj.message === 'string' || typeof obj.status === 'string') {
11
+ return {
12
+ error: {
13
+ status: typeof obj.status === 'string' ? obj.status : `HTTP ${httpStatus}`,
14
+ message: typeof obj.message === 'string' ? obj.message : `Request failed with HTTP ${httpStatus}`,
15
+ httpStatus,
16
+ raw: body,
17
+ },
18
+ };
19
+ }
20
+ if (typeof obj.detail === 'string') {
21
+ return {
22
+ error: {
23
+ status: `HTTP ${httpStatus}`,
24
+ message: obj.detail,
25
+ httpStatus,
26
+ raw: body,
27
+ },
28
+ };
29
+ }
30
+ }
31
+ return {
32
+ error: {
33
+ status: `HTTP ${httpStatus}`,
34
+ message: typeof body === 'string' && body.length < 500
35
+ ? body
36
+ : `Request failed with HTTP ${httpStatus}`,
37
+ httpStatus,
38
+ raw: body,
39
+ },
40
+ };
41
+ }
42
+ export function fromException(err) {
43
+ if (err instanceof Error) {
44
+ return {
45
+ error: {
46
+ status: err.name || 'Error',
47
+ message: err.message,
48
+ },
49
+ };
50
+ }
51
+ return {
52
+ error: {
53
+ status: 'Error',
54
+ message: String(err),
55
+ },
56
+ };
57
+ }
58
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/core/errors.ts"],"names":[],"mappings":"AAmBA,MAAM,UAAU,gBAAgB,CAAC,KAAc;IAC7C,OAAO,CACL,OAAO,KAAK,KAAK,QAAQ;QACzB,KAAK,KAAK,IAAI;QACd,OAAO,IAAI,KAAK;QAChB,OAAQ,KAA4B,CAAC,KAAK,KAAK,QAAQ,CACxD,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,UAAkB,EA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AC,IAAI,IAAI,OAAO;gBAC3B,OAAO,EAAE,GAAG,CAAC,OAAO;aACrB;SACF,CAAC;IACJ,CAAC;IACD,OAAO;QACL,KAAK,EAAE;YACL,MAAM,EAAE,OAAO;YACf,OAAO,EAAE,MAAM,CAAC,GAAG,CAAC;SACrB;KACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,39 @@
1
+ import { type KelviqAPIError } from './errors.js';
2
+ export type AuthScope = 'server';
3
+ export interface ResolvedHttpConfig {
4
+ serverApiKey: string | undefined;
5
+ baseUrl: string;
6
+ edgeUrl: string;
7
+ userAgent: string;
8
+ }
9
+ export type RequestInit = {
10
+ method: 'GET' | 'POST' | 'PATCH' | 'PUT' | 'DELETE';
11
+ /** Path beneath the host root, e.g. '/customers/'. */
12
+ path: string;
13
+ /** JSON body, if any. */
14
+ body?: unknown;
15
+ /** Query string params. Skipped when value is null/undefined. */
16
+ query?: Record<string, string | number | boolean | null | undefined>;
17
+ /** Which API host to call. Defaults to 'base'. */
18
+ host?: 'base' | 'edge';
19
+ /** Which API key to send. */
20
+ auth: AuthScope;
21
+ };
22
+ export type Result<T> = {
23
+ ok: true;
24
+ data: T;
25
+ } | ({
26
+ ok: false;
27
+ } & KelviqAPIError);
28
+ export declare class MissingKeyError extends Error {
29
+ readonly scope: AuthScope;
30
+ constructor(scope: AuthScope);
31
+ }
32
+ export declare class KelviqHttpClient {
33
+ private readonly config;
34
+ constructor(config: ResolvedHttpConfig);
35
+ request<T = unknown>(init: RequestInit): Promise<Result<T>>;
36
+ private requireKey;
37
+ private buildUrl;
38
+ private missingKeyError;
39
+ }
@@ -0,0 +1,104 @@
1
+ // Ported from kelviq-mcp-server src/http/client.ts @ e680c70 — keep in sync manually.
2
+ //
3
+ // Adapted for the CLI's layered config: the source client took a
4
+ // KelviqConfig with two parallel keys (server/client scope, same
5
+ // environment) and resolved which to use via requireKey(config, scope). The
6
+ // CLI's config.ts instead resolves *environment* (sandbox vs production) via
7
+ // resolveEnv() before a client is ever constructed — see CliConfig /
8
+ // resolveEnv in ./config.ts. So this client takes an already
9
+ // environment-resolved config (ResolvedHttpConfig) with a single
10
+ // `serverApiKey`, and keeps its own local missing-key short-circuit for
11
+ // parity with the source's behavior (and so callers that skip resolveEnv
12
+ // still fail safely without ever calling fetch).
13
+ //
14
+ // `AuthScope` is kept (rather than dropped) so the per-request `auth` field
15
+ // mechanism matches the source shape; only 'server' scope exists for the CLI
16
+ // today. A 'client' (publishable-key) scope may be added later.
17
+ import { fromException, fromHttpResponse } from './errors.js';
18
+ export class MissingKeyError extends Error {
19
+ scope;
20
+ constructor(scope) {
21
+ super(`No API key configured for this request (scope: ${scope}). ` +
22
+ 'Run `kelviq login` or set the appropriate KELVIQ_*_SERVER_API_KEY env var. ' +
23
+ 'Get keys at https://app.kelviq.com/settings/api-keys.');
24
+ this.scope = scope;
25
+ this.name = 'MissingKeyError';
26
+ }
27
+ }
28
+ export class KelviqHttpClient {
29
+ config;
30
+ constructor(config) {
31
+ this.config = config;
32
+ }
33
+ async request(init) {
34
+ let key;
35
+ try {
36
+ key = this.requireKey(init.auth);
37
+ }
38
+ catch (err) {
39
+ if (err instanceof MissingKeyError) {
40
+ return { ok: false, ...this.missingKeyError(err) };
41
+ }
42
+ return { ok: false, ...fromException(err) };
43
+ }
44
+ const host = init.host === 'edge' ? this.config.edgeUrl : this.config.baseUrl;
45
+ const url = this.buildUrl(host, init.path, init.query);
46
+ let response;
47
+ try {
48
+ response = await fetch(url, {
49
+ method: init.method,
50
+ headers: {
51
+ Authorization: `Bearer ${key}`,
52
+ 'User-Agent': this.config.userAgent,
53
+ Accept: 'application/json',
54
+ ...(init.body !== undefined ? { 'Content-Type': 'application/json' } : {}),
55
+ },
56
+ body: init.body !== undefined ? JSON.stringify(init.body) : undefined,
57
+ });
58
+ }
59
+ catch (err) {
60
+ return { ok: false, ...fromException(err) };
61
+ }
62
+ const raw = await response.text();
63
+ let parsed = raw;
64
+ if (raw.length > 0) {
65
+ try {
66
+ parsed = JSON.parse(raw);
67
+ }
68
+ catch {
69
+ // leave as text
70
+ }
71
+ }
72
+ if (!response.ok) {
73
+ return { ok: false, ...fromHttpResponse(response.status, parsed) };
74
+ }
75
+ return { ok: true, data: parsed };
76
+ }
77
+ requireKey(scope) {
78
+ const key = this.config.serverApiKey;
79
+ if (!key) {
80
+ throw new MissingKeyError(scope);
81
+ }
82
+ return key;
83
+ }
84
+ buildUrl(host, path, query) {
85
+ const url = new URL(host.replace(/\/+$/, '') + (path.startsWith('/') ? path : `/${path}`));
86
+ if (query) {
87
+ for (const [k, v] of Object.entries(query)) {
88
+ if (v === null || v === undefined)
89
+ continue;
90
+ url.searchParams.set(k, String(v));
91
+ }
92
+ }
93
+ return url.toString();
94
+ }
95
+ missingKeyError(err) {
96
+ return {
97
+ error: {
98
+ status: 'Configuration error',
99
+ message: err.message,
100
+ },
101
+ };
102
+ }
103
+ }
104
+ //# sourceMappingURL=http.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"http.js","sourceRoot":"","sources":["../../src/core/http.ts"],"names":[],"mappings":"AAAA,sFAAsF;AACtF,EAAE;AACF,iEAAiE;AACjE,iEAAiE;AACjE,4EAA4E;AAC5E,6EAA6E;AAC7E,qEAAqE;AACrE,6DAA6D;AAC7D,iEAAiE;AACjE,wEAAwE;AACxE,yEAAyE;AACzE,iDAAiD;AACjD,EAAE;AACF,4EAA4E;AAC5E,6EAA6E;AAC7E,gEAAgE;AAChE,OAAO,EAAuB,aAAa,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AA2BnF,MAAM,OAAO,eAAgB,SAAQ,KAAK;IACZ;IAA5B,YAA4B,KAAgB;QAC1C,KAAK,CACH,kDAAkD,KAAK,KAAK;YAC1D,6EAA6E;YAC7E,uDAAuD,CAC1D,CAAC;QALwB,UAAK,GAAL,KAAK,CAAW;QAM1C,IAAI,CAAC,IAAI,GAAG,iBAAiB,CAAC;IAChC,CAAC;CACF;AAED,MAAM,OAAO,gBAAgB;IACE;IAA7B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CAAC,IAAI,IAAI,EAAE,CAAC,CAAC,CAAC;QAC3F,IAAI,KAAK,EAAE,CAAC;YACV,KAAK,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;gBAC3C,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,KAAK,SAAS;oBAAE,SAAS;gBAC5C,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;YACrC,CAAC;QACH,CAAC;QACD,OAAO,GAAG,CAAC,QAAQ,EAAE,CAAC;IACxB,CAAC;IAEO,eAAe,CAAC,GAAoB;QAC1C,OAAO;YACL,KAAK,EAAE;gBACL,MAAM,EAAE,qBAAqB;gBAC7B,OAAO,EAAE,GAAG,CAAC,OAAO;aACrB;SACF,CAAC;IACJ,CAAC;CACF"}
@@ -0,0 +1 @@
1
+ export declare function getPackageVersion(): string;
@@ -0,0 +1,14 @@
1
+ // Extracted from src/cli.ts's inline copy so both the CLI entrypoint and
2
+ // src/core/config.ts (for the User-Agent header) can share one implementation.
3
+ import { createRequire } from 'node:module';
4
+ export function getPackageVersion() {
5
+ try {
6
+ const require = createRequire(import.meta.url);
7
+ const pkg = require('../../package.json');
8
+ return pkg.version ?? 'dev';
9
+ }
10
+ catch {
11
+ return 'dev';
12
+ }
13
+ }
14
+ //# sourceMappingURL=version.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/core/version.ts"],"names":[],"mappings":"AAAA,yEAAyE;AACzE,+EAA+E;AAC/E,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE5C,MAAM,UAAU,iBAAiB;IAC/B,IAAI,CAAC;QACH,MAAM,OAAO,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAC/C,MAAM,GAAG,GAAG,OAAO,CAAC,oBAAoB,CAAyB,CAAC;QAClE,OAAO,GAAG,CAAC,OAAO,IAAI,KAAK,CAAC;IAC9B,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC"}