gsheet-lvt 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/LICENSE +21 -0
- package/README.md +163 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +3140 -0
- package/dist/cli.js.map +1 -0
- package/dist/index.d.ts +276 -0
- package/dist/index.js +1246 -0
- package/dist/index.js.map +1 -0
- package/package.json +78 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,276 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
declare const oauthCredentialsSchema: z.ZodObject<{
|
|
4
|
+
client_id: z.ZodString;
|
|
5
|
+
client_secret: z.ZodString;
|
|
6
|
+
refresh_token: z.ZodString;
|
|
7
|
+
access_token: z.ZodOptional<z.ZodString>;
|
|
8
|
+
expiry_date: z.ZodOptional<z.ZodNumber>;
|
|
9
|
+
}, z.core.$strip>;
|
|
10
|
+
declare const spreadsheetConfigSchema: z.ZodObject<{
|
|
11
|
+
spreadsheet_id: z.ZodString;
|
|
12
|
+
activeSheet: z.ZodOptional<z.ZodString>;
|
|
13
|
+
}, z.core.$strip>;
|
|
14
|
+
declare const accountSchema: z.ZodObject<{
|
|
15
|
+
email: z.ZodString;
|
|
16
|
+
oauth: z.ZodObject<{
|
|
17
|
+
client_id: z.ZodString;
|
|
18
|
+
client_secret: z.ZodString;
|
|
19
|
+
refresh_token: z.ZodString;
|
|
20
|
+
access_token: z.ZodOptional<z.ZodString>;
|
|
21
|
+
expiry_date: z.ZodOptional<z.ZodNumber>;
|
|
22
|
+
}, z.core.$strip>;
|
|
23
|
+
activeSpreadsheet: z.ZodOptional<z.ZodString>;
|
|
24
|
+
spreadsheets: z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
25
|
+
spreadsheet_id: z.ZodString;
|
|
26
|
+
activeSheet: z.ZodOptional<z.ZodString>;
|
|
27
|
+
}, z.core.$strip>>;
|
|
28
|
+
}, z.core.$strip>;
|
|
29
|
+
declare const userMetadataSchema: z.ZodObject<{
|
|
30
|
+
config_path: z.ZodString;
|
|
31
|
+
activeAccount: z.ZodOptional<z.ZodString>;
|
|
32
|
+
accounts: z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
33
|
+
email: z.ZodString;
|
|
34
|
+
oauth: z.ZodObject<{
|
|
35
|
+
client_id: z.ZodString;
|
|
36
|
+
client_secret: z.ZodString;
|
|
37
|
+
refresh_token: z.ZodString;
|
|
38
|
+
access_token: z.ZodOptional<z.ZodString>;
|
|
39
|
+
expiry_date: z.ZodOptional<z.ZodNumber>;
|
|
40
|
+
}, z.core.$strip>;
|
|
41
|
+
activeSpreadsheet: z.ZodOptional<z.ZodString>;
|
|
42
|
+
spreadsheets: z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
43
|
+
spreadsheet_id: z.ZodString;
|
|
44
|
+
activeSheet: z.ZodOptional<z.ZodString>;
|
|
45
|
+
}, z.core.$strip>>;
|
|
46
|
+
}, z.core.$strip>>;
|
|
47
|
+
}, z.core.$strip>;
|
|
48
|
+
declare const sheetsConfigSchema: z.ZodObject<{
|
|
49
|
+
$schema: z.ZodOptional<z.ZodString>;
|
|
50
|
+
settings: z.ZodOptional<z.ZodObject<{
|
|
51
|
+
max_results: z.ZodDefault<z.ZodNumber>;
|
|
52
|
+
default_columns: z.ZodDefault<z.ZodString>;
|
|
53
|
+
completion_installed: z.ZodOptional<z.ZodBoolean>;
|
|
54
|
+
}, z.core.$strip>>;
|
|
55
|
+
}, z.core.$strip>;
|
|
56
|
+
declare const sheetDataSchema: z.ZodObject<{
|
|
57
|
+
title: z.ZodString;
|
|
58
|
+
index: z.ZodNumber;
|
|
59
|
+
}, z.core.$strip>;
|
|
60
|
+
type OAuthCredentials = z.infer<typeof oauthCredentialsSchema>;
|
|
61
|
+
type SpreadsheetConfig = z.infer<typeof spreadsheetConfigSchema>;
|
|
62
|
+
type Account = z.infer<typeof accountSchema>;
|
|
63
|
+
type UserMetadata = z.infer<typeof userMetadataSchema>;
|
|
64
|
+
type SheetsConfig = z.infer<typeof sheetsConfigSchema>;
|
|
65
|
+
type SheetData = z.infer<typeof sheetDataSchema>;
|
|
66
|
+
|
|
67
|
+
interface OAuthFlowResult {
|
|
68
|
+
email: string;
|
|
69
|
+
credentials: OAuthCredentials;
|
|
70
|
+
}
|
|
71
|
+
interface OAuthFlowOptions {
|
|
72
|
+
loginHint?: string;
|
|
73
|
+
onAuthUrl?: (url: string) => void;
|
|
74
|
+
}
|
|
75
|
+
declare function performOAuthFlow(clientId: string, clientSecret: string, options?: OAuthFlowOptions): Promise<OAuthFlowResult>;
|
|
76
|
+
|
|
77
|
+
declare function assertRequiredOAuthScopes(grantedScopes: string[]): void;
|
|
78
|
+
|
|
79
|
+
declare function refreshTokenIfNeeded(credentials: OAuthCredentials): Promise<OAuthCredentials>;
|
|
80
|
+
declare function refreshToken(credentials: OAuthCredentials): Promise<OAuthCredentials>;
|
|
81
|
+
|
|
82
|
+
declare class ConfigManager {
|
|
83
|
+
private userMetadata;
|
|
84
|
+
private config;
|
|
85
|
+
constructor();
|
|
86
|
+
private ensureConfigDirectory;
|
|
87
|
+
private initializeUserMetadata;
|
|
88
|
+
private createDefaultUserMetadata;
|
|
89
|
+
private loadUserMetadata;
|
|
90
|
+
private saveUserMetadata;
|
|
91
|
+
private getConfigPath;
|
|
92
|
+
private loadConfig;
|
|
93
|
+
private createDefaultConfig;
|
|
94
|
+
private saveConfig;
|
|
95
|
+
addAccount(email: string, credentials: OAuthCredentials): Promise<void>;
|
|
96
|
+
removeAccount(email: string): Promise<void>;
|
|
97
|
+
getAllAccounts(): Account[];
|
|
98
|
+
getAccount(email: string): Account | null;
|
|
99
|
+
setActiveAccount(email: string): void;
|
|
100
|
+
getActiveAccount(): Account | null;
|
|
101
|
+
getActiveAccountEmail(): string | null;
|
|
102
|
+
updateAccountCredentials(email: string, credentials: OAuthCredentials): Promise<void>;
|
|
103
|
+
getRefreshedCredentials(email: string): Promise<OAuthCredentials>;
|
|
104
|
+
addSpreadsheet(email: string, name: string, spreadsheetId: string): Promise<void>;
|
|
105
|
+
removeSpreadsheet(email: string, name: string): Promise<void>;
|
|
106
|
+
listSpreadsheets(email: string): Array<{
|
|
107
|
+
name: string;
|
|
108
|
+
spreadsheetId: string;
|
|
109
|
+
activeSheet?: string;
|
|
110
|
+
}>;
|
|
111
|
+
getSpreadsheet(email: string, name: string): SpreadsheetConfig | null;
|
|
112
|
+
getSpreadsheetById(email: string, id: string): SpreadsheetConfig | null;
|
|
113
|
+
setActiveSpreadsheet(email: string, name: string): void;
|
|
114
|
+
getActiveSpreadsheet(email: string): SpreadsheetConfig | null;
|
|
115
|
+
getActiveSpreadsheetName(email: string): string | null;
|
|
116
|
+
setActiveSheet(email: string, spreadsheetName: string, sheetName: string): void;
|
|
117
|
+
getActiveSheetName(email: string, spreadsheetName: string): string | null;
|
|
118
|
+
markCompletionInstalled(): void;
|
|
119
|
+
isCompletionInstalled(): boolean;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
interface DriveSpreadsheet {
|
|
123
|
+
id: string;
|
|
124
|
+
name: string;
|
|
125
|
+
modifiedTime: string;
|
|
126
|
+
webViewLink: string;
|
|
127
|
+
}
|
|
128
|
+
declare class GoogleDriveService {
|
|
129
|
+
private credentials;
|
|
130
|
+
constructor(oauthCredentials: OAuthCredentials);
|
|
131
|
+
listSpreadsheets(): Promise<DriveSpreadsheet[]>;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
interface GoogleSheetsConfig {
|
|
135
|
+
spreadsheetId: string;
|
|
136
|
+
oauthCredentials: OAuthCredentials;
|
|
137
|
+
}
|
|
138
|
+
declare class GoogleSheetsService {
|
|
139
|
+
private config;
|
|
140
|
+
private doc;
|
|
141
|
+
private auth;
|
|
142
|
+
constructor(config: GoogleSheetsConfig);
|
|
143
|
+
private ensureConnection;
|
|
144
|
+
getSheetInfo(): Promise<{
|
|
145
|
+
title: string;
|
|
146
|
+
sheets: Array<{
|
|
147
|
+
title: string;
|
|
148
|
+
index: number;
|
|
149
|
+
sheetId: number;
|
|
150
|
+
}>;
|
|
151
|
+
}>;
|
|
152
|
+
getSheetData(sheetName: string, includeFormulas?: boolean): Promise<string[][]>;
|
|
153
|
+
addSheet(sheetName: string): Promise<void>;
|
|
154
|
+
removeSheet(sheetName: string): Promise<void>;
|
|
155
|
+
renameSheet(oldName: string, newName: string): Promise<void>;
|
|
156
|
+
copySheet(sheetName: string, newSheetName: string): Promise<void>;
|
|
157
|
+
writeCell(sheetName: string, cell: string, value: string): Promise<void>;
|
|
158
|
+
writeCellRange(sheetName: string, range: string, values: (string | number)[][], noPreserve?: boolean): Promise<void>;
|
|
159
|
+
appendRow(sheetName: string, values: string[]): Promise<void>;
|
|
160
|
+
getSheetDataRange(sheetName: string, range: string, includeFormulas?: boolean): Promise<string[][]>;
|
|
161
|
+
insertRows(sheetName: string, range: {
|
|
162
|
+
startIndex: number;
|
|
163
|
+
endIndex: number;
|
|
164
|
+
}, inheritFromBefore?: boolean): Promise<void>;
|
|
165
|
+
deleteRows(sheetName: string, range: {
|
|
166
|
+
startIndex: number;
|
|
167
|
+
endIndex: number;
|
|
168
|
+
}): Promise<void>;
|
|
169
|
+
getRowFormulas(sheetName: string, rowIndex: number): Promise<Map<number, string>>;
|
|
170
|
+
copyRowFormulas(sheetName: string, sourceRowIndex: number, targetRowIndex: number): Promise<void>;
|
|
171
|
+
copyRowFormulasBulk(sheetName: string, sourceRowIndex: number, startTargetRowIndex: number, count: number): Promise<void>;
|
|
172
|
+
private adjustFormulaReferences;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
interface SheetCmdClientOptions {
|
|
176
|
+
configManager?: ConfigManager;
|
|
177
|
+
}
|
|
178
|
+
interface LoginOptions {
|
|
179
|
+
clientId: string;
|
|
180
|
+
clientSecret: string;
|
|
181
|
+
loginHint?: string;
|
|
182
|
+
onAuthUrl?: (url: string) => void;
|
|
183
|
+
setActive?: boolean;
|
|
184
|
+
}
|
|
185
|
+
interface ReauthOptions {
|
|
186
|
+
email?: string;
|
|
187
|
+
loginHint?: string;
|
|
188
|
+
onAuthUrl?: (url: string) => void;
|
|
189
|
+
}
|
|
190
|
+
interface SheetServiceOptions {
|
|
191
|
+
accountEmail?: string;
|
|
192
|
+
spreadsheetName?: string;
|
|
193
|
+
}
|
|
194
|
+
interface DriveServiceOptions {
|
|
195
|
+
accountEmail?: string;
|
|
196
|
+
}
|
|
197
|
+
declare function createSheetsService(config: GoogleSheetsConfig): GoogleSheetsService;
|
|
198
|
+
declare function createDriveService(oauthCredentials: OAuthCredentials): GoogleDriveService;
|
|
199
|
+
declare class SheetCmdClient {
|
|
200
|
+
private configManager;
|
|
201
|
+
constructor(options?: SheetCmdClientOptions);
|
|
202
|
+
login(options: LoginOptions): Promise<Account>;
|
|
203
|
+
reauth(options?: ReauthOptions): Promise<Account>;
|
|
204
|
+
listAccounts(): Account[];
|
|
205
|
+
getAccount(email: string): Account | null;
|
|
206
|
+
getActiveAccount(): Account | null;
|
|
207
|
+
selectAccount(email: string): void;
|
|
208
|
+
removeAccount(email: string): Promise<void>;
|
|
209
|
+
addSpreadsheet(email: string, name: string, spreadsheetId: string): Promise<void>;
|
|
210
|
+
removeSpreadsheet(email: string, name: string): Promise<void>;
|
|
211
|
+
listSpreadsheets(email?: string): Array<{
|
|
212
|
+
name: string;
|
|
213
|
+
spreadsheetId: string;
|
|
214
|
+
activeSheet?: string;
|
|
215
|
+
}>;
|
|
216
|
+
getSpreadsheet(email: string, name: string): SpreadsheetConfig | null;
|
|
217
|
+
selectSpreadsheet(email: string, name: string): void;
|
|
218
|
+
getActiveSpreadsheet(email?: string): SpreadsheetConfig | null;
|
|
219
|
+
getActiveSpreadsheetName(email?: string): string | null;
|
|
220
|
+
selectSheet(email: string, spreadsheetName: string, sheetName: string): void;
|
|
221
|
+
getActiveSheetName(email?: string, spreadsheetName?: string): string | null;
|
|
222
|
+
getSheetsService(options?: SheetServiceOptions): Promise<GoogleSheetsService>;
|
|
223
|
+
getDriveService(options?: DriveServiceOptions): Promise<GoogleDriveService>;
|
|
224
|
+
refreshAccountCredentials(email: string): Promise<OAuthCredentials>;
|
|
225
|
+
private requireActiveAccount;
|
|
226
|
+
private requireAccount;
|
|
227
|
+
private requireActiveSpreadsheetName;
|
|
228
|
+
private requireSpreadsheet;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
declare const APP_INFO: {
|
|
232
|
+
name: string;
|
|
233
|
+
packageName: any;
|
|
234
|
+
display_name: string;
|
|
235
|
+
version: any;
|
|
236
|
+
};
|
|
237
|
+
declare enum SupportedOS {
|
|
238
|
+
Linux = "linux",
|
|
239
|
+
Mac = "mac",
|
|
240
|
+
Windows = "windows",
|
|
241
|
+
Wsl = "wsl"
|
|
242
|
+
}
|
|
243
|
+
declare function getUserOS(): SupportedOS;
|
|
244
|
+
declare function getConfigDirectory(): string;
|
|
245
|
+
declare const CONFIG_PATHS: {
|
|
246
|
+
configDir: string;
|
|
247
|
+
userMetadataFile: string;
|
|
248
|
+
defaultConfigFile: string;
|
|
249
|
+
};
|
|
250
|
+
declare const OAUTH_SCOPES: {
|
|
251
|
+
SPREADSHEETS: string;
|
|
252
|
+
DRIVE_READONLY: string;
|
|
253
|
+
USERINFO_EMAIL: string;
|
|
254
|
+
};
|
|
255
|
+
declare const GOOGLE_API_URLS: {
|
|
256
|
+
USERINFO: string;
|
|
257
|
+
SHEETS_CREATE: string;
|
|
258
|
+
};
|
|
259
|
+
declare const OAUTH_CONFIG: {
|
|
260
|
+
REDIRECT_HOST: string;
|
|
261
|
+
REDIRECT_PATH: string;
|
|
262
|
+
ACCESS_TYPE: "offline";
|
|
263
|
+
PROMPT: "consent";
|
|
264
|
+
};
|
|
265
|
+
declare const TOKEN_REFRESH_THRESHOLD_MS: number;
|
|
266
|
+
|
|
267
|
+
declare function parseCSV(content: string): string[][];
|
|
268
|
+
|
|
269
|
+
declare function formatAsMarkdown(data: string[][]): string;
|
|
270
|
+
declare function formatAsCSV(data: string[][]): string;
|
|
271
|
+
declare function formatAsJSON(data: string[][]): string;
|
|
272
|
+
|
|
273
|
+
declare function readJson<T = Record<string, unknown>>(filePath: string): T;
|
|
274
|
+
declare function writeJson<T>(filePath: string, data: T, pretty?: boolean): void;
|
|
275
|
+
|
|
276
|
+
export { APP_INFO, type Account, CONFIG_PATHS, ConfigManager, type DriveServiceOptions, type DriveSpreadsheet, GOOGLE_API_URLS, GoogleDriveService, type GoogleSheetsConfig, GoogleSheetsService, type LoginOptions, OAUTH_CONFIG, OAUTH_SCOPES, type OAuthCredentials, type OAuthFlowOptions, type OAuthFlowResult, type ReauthOptions, SheetCmdClient, type SheetCmdClientOptions, type SheetData, type SheetServiceOptions, type SheetsConfig, type SpreadsheetConfig, TOKEN_REFRESH_THRESHOLD_MS, type UserMetadata, accountSchema, assertRequiredOAuthScopes, createDriveService, createSheetsService, formatAsCSV, formatAsJSON, formatAsMarkdown, getConfigDirectory, getUserOS, oauthCredentialsSchema, parseCSV, performOAuthFlow, readJson, refreshToken, refreshTokenIfNeeded, sheetDataSchema, sheetsConfigSchema, spreadsheetConfigSchema, userMetadataSchema, writeJson };
|