@recur-tw/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.
- package/AGENT.md +268 -0
- package/LICENSE +21 -0
- package/README.md +368 -0
- package/dist/cli.d.mts +1 -0
- package/dist/cli.mjs +2552 -0
- package/dist/index.d.mts +196 -0
- package/dist/index.mjs +1095 -0
- package/package.json +71 -0
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
//#region src/client.d.ts
|
|
2
|
+
interface ClientOptions {
|
|
3
|
+
baseUrl: string;
|
|
4
|
+
secretKey: string;
|
|
5
|
+
}
|
|
6
|
+
interface ApiResponse<T = unknown> {
|
|
7
|
+
ok: boolean;
|
|
8
|
+
status: number;
|
|
9
|
+
data: T;
|
|
10
|
+
}
|
|
11
|
+
declare class RecurClient {
|
|
12
|
+
private baseUrl;
|
|
13
|
+
private secretKey;
|
|
14
|
+
constructor(opts: ClientOptions);
|
|
15
|
+
request<T = unknown>(method: string, path: string, opts?: {
|
|
16
|
+
body?: unknown;
|
|
17
|
+
params?: Record<string, string | undefined>;
|
|
18
|
+
}): Promise<T>;
|
|
19
|
+
get<T = unknown>(path: string, params?: Record<string, string | undefined>): Promise<T>;
|
|
20
|
+
post<T = unknown>(path: string, body?: unknown): Promise<T>;
|
|
21
|
+
patch<T = unknown>(path: string, body?: unknown): Promise<T>;
|
|
22
|
+
delete<T = unknown>(path: string): Promise<T>;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Strip a single string of dangerous characters:
|
|
26
|
+
* - ASCII control chars (0x00-0x08, 0x0B, 0x0C, 0x0E-0x1F) — keep \t \n \r
|
|
27
|
+
* - DEL (0x7F)
|
|
28
|
+
* - Zero-width / invisible Unicode (U+200B-200F, U+FEFF)
|
|
29
|
+
* - Line/paragraph separators (U+2028-2029)
|
|
30
|
+
* - ANSI escape sequences (CSI + OSC patterns)
|
|
31
|
+
*/
|
|
32
|
+
declare function sanitizeString(str: string): string;
|
|
33
|
+
//#endregion
|
|
34
|
+
//#region src/config.d.ts
|
|
35
|
+
interface Profile {
|
|
36
|
+
secretKey: string;
|
|
37
|
+
environment: 'sandbox' | 'production';
|
|
38
|
+
baseUrl?: string;
|
|
39
|
+
}
|
|
40
|
+
declare function getProfile(profileName?: string): Profile | null;
|
|
41
|
+
declare function saveProfile(name: string, profile: Profile): void;
|
|
42
|
+
/**
|
|
43
|
+
* Resolve the secret key from (in priority order):
|
|
44
|
+
* 1. --key flag
|
|
45
|
+
* 2. RECUR_SECRET_KEY env var
|
|
46
|
+
* 3. Active profile in ~/.recur/credentials.json
|
|
47
|
+
*
|
|
48
|
+
* Validates format before returning.
|
|
49
|
+
*/
|
|
50
|
+
declare function resolveSecretKey(opts: {
|
|
51
|
+
key?: string;
|
|
52
|
+
profile?: string;
|
|
53
|
+
}): string;
|
|
54
|
+
/**
|
|
55
|
+
* Validate a URL uses HTTPS (or HTTP for localhost in development).
|
|
56
|
+
* Rejects non-http(s) schemes like file://, javascript://, data://.
|
|
57
|
+
*/
|
|
58
|
+
declare function validateUrl(url: string, label: string): string;
|
|
59
|
+
/**
|
|
60
|
+
* Resolve the base URL for API calls.
|
|
61
|
+
*/
|
|
62
|
+
declare function resolveBaseUrl(opts: {
|
|
63
|
+
baseUrl?: string;
|
|
64
|
+
profile?: string;
|
|
65
|
+
}): string;
|
|
66
|
+
//#endregion
|
|
67
|
+
//#region src/output.d.ts
|
|
68
|
+
type OutputFormat = 'json' | 'table' | 'csv' | 'ndjson';
|
|
69
|
+
interface OutputOptions {
|
|
70
|
+
format: OutputFormat;
|
|
71
|
+
fields?: string[];
|
|
72
|
+
noHeaders?: boolean;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Render data in the specified format.
|
|
76
|
+
* Agent-optimized: --output json produces clean, parseable JSON to stdout.
|
|
77
|
+
* Human-optimized: table format with colors to stderr-safe stdout.
|
|
78
|
+
*/
|
|
79
|
+
declare function render(data: unknown, opts?: OutputOptions): void;
|
|
80
|
+
/**
|
|
81
|
+
* Pick specific fields from data (for --fields flag).
|
|
82
|
+
*/
|
|
83
|
+
declare function pickFields<T extends Record<string, unknown>>(data: T | T[], fields: string[]): Partial<T> | Partial<T>[];
|
|
84
|
+
//#endregion
|
|
85
|
+
//#region src/validator.d.ts
|
|
86
|
+
/**
|
|
87
|
+
* Validate a resource ID or slug against dangerous input patterns.
|
|
88
|
+
* Rejects path traversals, embedded query params, control chars.
|
|
89
|
+
*
|
|
90
|
+
* Does NOT enforce ID prefixes — Recur uses CUID-format IDs (e.g.
|
|
91
|
+
* "ro91zsticf41uwq8bungmklk") without a prefix like "cus_".
|
|
92
|
+
*/
|
|
93
|
+
declare function validateResourceId(id: string): string;
|
|
94
|
+
/**
|
|
95
|
+
* Parse and validate a raw JSON payload from --json flag.
|
|
96
|
+
*/
|
|
97
|
+
declare function parseJsonPayload(raw: string): Record<string, unknown>;
|
|
98
|
+
/**
|
|
99
|
+
* Validate that a string looks like a valid API key.
|
|
100
|
+
*/
|
|
101
|
+
declare function validateApiKey(key: string): string;
|
|
102
|
+
//#endregion
|
|
103
|
+
//#region ../core/src/api/resources.d.ts
|
|
104
|
+
/**
|
|
105
|
+
* Canonical API resource definitions — single source of truth.
|
|
106
|
+
*
|
|
107
|
+
* Consumed by:
|
|
108
|
+
* - CLI (`packages/cli`) — schema introspection, --fields validation, --dry-run
|
|
109
|
+
* - MCP (`apps/mcp`) — tool descriptions, enum values, field names
|
|
110
|
+
*
|
|
111
|
+
* ⚠️ ZERO DEPENDENCIES — no Prisma, no zod, no workspace imports.
|
|
112
|
+
* This file is bundled into the standalone CLI npm package.
|
|
113
|
+
*/
|
|
114
|
+
type FieldType = 'string' | 'number' | 'boolean' | 'datetime' | 'object' | 'array';
|
|
115
|
+
interface ResponseFieldDef {
|
|
116
|
+
name: string;
|
|
117
|
+
type: FieldType;
|
|
118
|
+
description?: string;
|
|
119
|
+
nullable?: boolean;
|
|
120
|
+
}
|
|
121
|
+
interface ParamDef {
|
|
122
|
+
type: 'string' | 'number' | 'boolean';
|
|
123
|
+
description: string;
|
|
124
|
+
required?: boolean;
|
|
125
|
+
enum?: readonly string[];
|
|
126
|
+
default?: string | number | boolean;
|
|
127
|
+
/** CLI flag name when different from API field (e.g. --product-id for productId) */
|
|
128
|
+
cliFlag?: string;
|
|
129
|
+
}
|
|
130
|
+
interface PaginationDef {
|
|
131
|
+
/** Query param name for cursor (e.g. 'starting_after') */
|
|
132
|
+
cursor: string;
|
|
133
|
+
defaultLimit: number;
|
|
134
|
+
maxLimit: number;
|
|
135
|
+
}
|
|
136
|
+
interface ActionDef {
|
|
137
|
+
method: string;
|
|
138
|
+
path: string;
|
|
139
|
+
description: string;
|
|
140
|
+
params?: Record<string, ParamDef>;
|
|
141
|
+
bodySchema?: Record<string, ParamDef>;
|
|
142
|
+
responseFields: readonly ResponseFieldDef[];
|
|
143
|
+
supportsDryRun?: boolean;
|
|
144
|
+
pagination?: PaginationDef;
|
|
145
|
+
}
|
|
146
|
+
interface ResourceDef {
|
|
147
|
+
resource: string;
|
|
148
|
+
description: string;
|
|
149
|
+
actions: Record<string, ActionDef>;
|
|
150
|
+
}
|
|
151
|
+
/** Extract field names from ResponseFieldDef[] (for --fields validation) */
|
|
152
|
+
declare function fieldNames(fields: readonly ResponseFieldDef[]): string[];
|
|
153
|
+
//#endregion
|
|
154
|
+
//#region src/schema.d.ts
|
|
155
|
+
declare function getResource(name: string): ResourceDef | undefined;
|
|
156
|
+
declare function getAllResources(): ResourceDef[];
|
|
157
|
+
declare function getAction(resourceAction: string): ActionDef | undefined;
|
|
158
|
+
/**
|
|
159
|
+
* Dump schema as machine-readable JSON for agents.
|
|
160
|
+
* Throws CLIError for unknown resources/actions (non-zero exit).
|
|
161
|
+
*/
|
|
162
|
+
declare function dumpSchema(resourceAction?: string): unknown;
|
|
163
|
+
//#endregion
|
|
164
|
+
//#region src/extract.d.ts
|
|
165
|
+
/**
|
|
166
|
+
* Extract list data from API responses.
|
|
167
|
+
*
|
|
168
|
+
* All list endpoints return a standard envelope: { object: 'list', data: [...] }.
|
|
169
|
+
* This function also handles legacy shapes and direct arrays as fallback.
|
|
170
|
+
*/
|
|
171
|
+
declare function extractList(response: unknown): unknown[];
|
|
172
|
+
/**
|
|
173
|
+
* Result of extracting a paginated list response.
|
|
174
|
+
*/
|
|
175
|
+
interface PaginatedListResult {
|
|
176
|
+
data: unknown[];
|
|
177
|
+
hasMore: boolean;
|
|
178
|
+
nextCursor: string | null;
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Extract list data with pagination metadata.
|
|
182
|
+
*
|
|
183
|
+
* API responses include:
|
|
184
|
+
* - has_more: boolean — whether more pages exist
|
|
185
|
+
* - next_cursor: string | null — ID to pass as starting_after for next page
|
|
186
|
+
*/
|
|
187
|
+
declare function extractPaginatedList(response: unknown): PaginatedListResult;
|
|
188
|
+
//#endregion
|
|
189
|
+
//#region src/errors.d.ts
|
|
190
|
+
declare class CLIError extends Error {
|
|
191
|
+
readonly statusCode?: number | undefined;
|
|
192
|
+
constructor(message: string, statusCode?: number | undefined);
|
|
193
|
+
}
|
|
194
|
+
//#endregion
|
|
195
|
+
export { type ActionDef, type ApiResponse, CLIError, type ClientOptions, type FieldType, type OutputFormat, type OutputOptions, type PaginatedListResult, type PaginationDef, type ParamDef, type Profile, RecurClient, type ResourceDef, type ResponseFieldDef, dumpSchema, extractList, extractPaginatedList, fieldNames, getAction, getAllResources, getProfile, getResource, parseJsonPayload, pickFields, render, resolveBaseUrl, resolveSecretKey, sanitizeString, saveProfile, validateApiKey, validateResourceId, validateUrl };
|
|
196
|
+
//# sourceMappingURL=index.d.mts.map
|