@ariadng/sheets 0.4.0 → 0.4.2

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 (47) hide show
  1. package/dist/cli.cjs +1610 -0
  2. package/dist/cli.cjs.map +1 -0
  3. package/dist/cli.d.cts +1 -0
  4. package/dist/cli.d.ts +0 -6
  5. package/dist/cli.js +1318 -595
  6. package/dist/cli.js.map +1 -1
  7. package/dist/index.cjs +858 -0
  8. package/dist/index.cjs.map +1 -0
  9. package/dist/index.d.cts +356 -0
  10. package/dist/index.d.ts +355 -10
  11. package/dist/index.js +810 -11
  12. package/dist/index.js.map +1 -1
  13. package/package.json +5 -3
  14. package/dist/api/index.d.ts +0 -60
  15. package/dist/api/index.d.ts.map +0 -1
  16. package/dist/api/index.js +0 -347
  17. package/dist/api/index.js.map +0 -1
  18. package/dist/auth/constants.d.ts +0 -13
  19. package/dist/auth/constants.d.ts.map +0 -1
  20. package/dist/auth/constants.js +0 -21
  21. package/dist/auth/constants.js.map +0 -1
  22. package/dist/auth/index.d.ts +0 -13
  23. package/dist/auth/index.d.ts.map +0 -1
  24. package/dist/auth/index.js +0 -22
  25. package/dist/auth/index.js.map +0 -1
  26. package/dist/auth/oauth.d.ts +0 -32
  27. package/dist/auth/oauth.d.ts.map +0 -1
  28. package/dist/auth/oauth.js +0 -80
  29. package/dist/auth/oauth.js.map +0 -1
  30. package/dist/auth/service-account.d.ts +0 -18
  31. package/dist/auth/service-account.d.ts.map +0 -1
  32. package/dist/auth/service-account.js +0 -92
  33. package/dist/auth/service-account.js.map +0 -1
  34. package/dist/auth/user-auth.d.ts +0 -24
  35. package/dist/auth/user-auth.d.ts.map +0 -1
  36. package/dist/auth/user-auth.js +0 -230
  37. package/dist/auth/user-auth.js.map +0 -1
  38. package/dist/cli.d.ts.map +0 -1
  39. package/dist/http/index.d.ts +0 -19
  40. package/dist/http/index.d.ts.map +0 -1
  41. package/dist/http/index.js +0 -68
  42. package/dist/http/index.js.map +0 -1
  43. package/dist/index.d.ts.map +0 -1
  44. package/dist/types/index.d.ts +0 -200
  45. package/dist/types/index.d.ts.map +0 -1
  46. package/dist/types/index.js +0 -16
  47. package/dist/types/index.js.map +0 -1
package/dist/index.d.ts CHANGED
@@ -1,11 +1,356 @@
1
1
  /**
2
- * @ariadng/google-sheets
3
- * Google Sheets API interface and CLI tool
4
- */
5
- export { SheetsClient, createClient } from './api/index.js';
6
- export { createAuthProvider, OAuthAuth, ServiceAccountAuth, UserAuth, login, loadStoredTokens, deleteTokens } from './auth/index.js';
7
- export type { AuthProvider } from './auth/index.js';
8
- export { HttpClient } from './http/index.js';
9
- export type { GridProperties, SheetProperties, Spreadsheet, SpreadsheetProperties, CellValue, CellFormat, Color, TextFormat, ValueRange, GetValuesOptions, BatchGetValuesResponse, ClearValuesResponse, BatchClearValuesResponse, ValueRenderOption, DateTimeRenderOption, MajorDimension, ValueInputOption, InsertDataOption, RawCellValue, UpdateValuesOptions, AppendValuesOptions, UpdateValuesResponse, BatchUpdateValuesResponse, AppendValuesResponse, SearchMatch, SearchOptions, SearchResult, AuthConfig, OAuthConfig, ServiceAccountConfig, ServiceAccountCredentials, UserAuthConfig, StoredTokens, SheetsClientOptions, SheetsApiError, SheetsApiErrorDetail, } from './types/index.js';
10
- export { SheetsError } from './types/index.js';
11
- //# sourceMappingURL=index.d.ts.map
2
+ * Google Sheets API Type Definitions
3
+ */
4
+ interface GridProperties {
5
+ rowCount: number;
6
+ columnCount: number;
7
+ frozenRowCount?: number;
8
+ frozenColumnCount?: number;
9
+ hideGridlines?: boolean;
10
+ }
11
+ interface SheetProperties {
12
+ sheetId: number;
13
+ title: string;
14
+ index: number;
15
+ sheetType?: 'GRID' | 'OBJECT' | 'DATA_SOURCE';
16
+ gridProperties?: GridProperties;
17
+ hidden?: boolean;
18
+ rightToLeft?: boolean;
19
+ }
20
+ interface SpreadsheetProperties {
21
+ title: string;
22
+ locale?: string;
23
+ timeZone?: string;
24
+ autoRecalc?: 'ON_CHANGE' | 'MINUTE' | 'HOUR';
25
+ defaultFormat?: CellFormat;
26
+ }
27
+ interface Spreadsheet {
28
+ spreadsheetId: string;
29
+ properties: SpreadsheetProperties;
30
+ sheets: {
31
+ properties: SheetProperties;
32
+ }[];
33
+ spreadsheetUrl?: string;
34
+ }
35
+ interface CellFormat {
36
+ numberFormat?: {
37
+ type: string;
38
+ pattern?: string;
39
+ };
40
+ backgroundColor?: Color;
41
+ textFormat?: TextFormat;
42
+ }
43
+ interface Color {
44
+ red?: number;
45
+ green?: number;
46
+ blue?: number;
47
+ alpha?: number;
48
+ }
49
+ interface TextFormat {
50
+ foregroundColor?: Color;
51
+ fontFamily?: string;
52
+ fontSize?: number;
53
+ bold?: boolean;
54
+ italic?: boolean;
55
+ strikethrough?: boolean;
56
+ underline?: boolean;
57
+ }
58
+ interface CellValue {
59
+ value: string | number | boolean | null;
60
+ formula?: string;
61
+ formattedValue?: string;
62
+ }
63
+ type ValueRenderOption = 'FORMATTED_VALUE' | 'UNFORMATTED_VALUE' | 'FORMULA';
64
+ type DateTimeRenderOption = 'SERIAL_NUMBER' | 'FORMATTED_STRING';
65
+ type MajorDimension = 'ROWS' | 'COLUMNS';
66
+ interface ValueRange {
67
+ range: string;
68
+ majorDimension: MajorDimension;
69
+ values: CellValue[][];
70
+ }
71
+ interface GetValuesOptions {
72
+ valueRenderOption?: ValueRenderOption;
73
+ dateTimeRenderOption?: DateTimeRenderOption;
74
+ majorDimension?: MajorDimension;
75
+ }
76
+ interface BatchGetValuesResponse {
77
+ spreadsheetId: string;
78
+ valueRanges: ValueRange[];
79
+ }
80
+ interface ClearValuesResponse {
81
+ spreadsheetId: string;
82
+ clearedRange: string;
83
+ }
84
+ interface BatchClearValuesResponse {
85
+ spreadsheetId: string;
86
+ clearedRanges: string[];
87
+ }
88
+ type ValueInputOption = 'RAW' | 'USER_ENTERED';
89
+ type InsertDataOption = 'OVERWRITE' | 'INSERT_ROWS';
90
+ type RawCellValue = string | number | boolean | null;
91
+ interface UpdateValuesOptions {
92
+ valueInputOption?: ValueInputOption;
93
+ majorDimension?: MajorDimension;
94
+ includeValuesInResponse?: boolean;
95
+ responseValueRenderOption?: ValueRenderOption;
96
+ responseDateTimeRenderOption?: DateTimeRenderOption;
97
+ }
98
+ interface AppendValuesOptions extends UpdateValuesOptions {
99
+ insertDataOption?: InsertDataOption;
100
+ }
101
+ interface UpdateValuesResponse {
102
+ spreadsheetId: string;
103
+ updatedRange: string;
104
+ updatedRows: number;
105
+ updatedColumns: number;
106
+ updatedCells: number;
107
+ updatedData?: ValueRange;
108
+ }
109
+ interface BatchUpdateValuesResponse {
110
+ spreadsheetId: string;
111
+ totalUpdatedRows: number;
112
+ totalUpdatedColumns: number;
113
+ totalUpdatedCells: number;
114
+ totalUpdatedSheets: number;
115
+ responses: UpdateValuesResponse[];
116
+ }
117
+ interface AppendValuesResponse {
118
+ spreadsheetId: string;
119
+ tableRange?: string;
120
+ updates: UpdateValuesResponse;
121
+ }
122
+ interface SearchMatch {
123
+ sheet: string;
124
+ sheetId: number;
125
+ address: string;
126
+ row: number;
127
+ column: number;
128
+ value: string | number | boolean | null;
129
+ }
130
+ interface SearchOptions {
131
+ range?: string;
132
+ sheetIndex?: number;
133
+ gid?: number;
134
+ caseSensitive?: boolean;
135
+ exactMatch?: boolean;
136
+ regex?: boolean;
137
+ limit?: number;
138
+ }
139
+ interface SearchResult {
140
+ query: string;
141
+ matchType: 'contains' | 'exact' | 'regex';
142
+ caseSensitive: boolean;
143
+ totalMatches: number;
144
+ matches: SearchMatch[];
145
+ }
146
+ interface OAuthConfig {
147
+ type: 'oauth';
148
+ accessToken: string;
149
+ refreshToken?: string;
150
+ clientId?: string;
151
+ clientSecret?: string;
152
+ expiresAt?: number;
153
+ }
154
+ interface ServiceAccountConfig {
155
+ type: 'service-account';
156
+ credentialsPath?: string;
157
+ credentials?: ServiceAccountCredentials;
158
+ }
159
+ interface ServiceAccountCredentials {
160
+ type: 'service_account';
161
+ project_id: string;
162
+ private_key_id: string;
163
+ private_key: string;
164
+ client_email: string;
165
+ client_id: string;
166
+ auth_uri: string;
167
+ token_uri: string;
168
+ }
169
+ interface UserAuthConfig {
170
+ type: 'user';
171
+ }
172
+ interface StoredTokens {
173
+ accessToken: string;
174
+ refreshToken: string;
175
+ expiresAt: number;
176
+ email?: string;
177
+ }
178
+ type AuthConfig = OAuthConfig | ServiceAccountConfig | UserAuthConfig;
179
+ interface SheetsClientOptions {
180
+ auth: AuthConfig;
181
+ }
182
+ interface SheetsApiErrorDetail {
183
+ '@type'?: string;
184
+ reason?: string;
185
+ domain?: string;
186
+ metadata?: Record<string, string>;
187
+ }
188
+ interface SheetsApiError {
189
+ code: number;
190
+ message: string;
191
+ status: string;
192
+ details?: SheetsApiErrorDetail[];
193
+ }
194
+ declare class SheetsError extends Error {
195
+ code: number;
196
+ status: string;
197
+ details?: SheetsApiErrorDetail[];
198
+ constructor(error: SheetsApiError);
199
+ }
200
+
201
+ /**
202
+ * Google Sheets API Client
203
+ */
204
+
205
+ declare class SheetsClient {
206
+ private http;
207
+ constructor(options: SheetsClientOptions);
208
+ /**
209
+ * Get a spreadsheet by ID
210
+ */
211
+ getSpreadsheet(spreadsheetId: string): Promise<Spreadsheet>;
212
+ /**
213
+ * Get list of sheets in a spreadsheet
214
+ */
215
+ getSheets(spreadsheetId: string): Promise<SheetProperties[]>;
216
+ /**
217
+ * Read cell values from a range
218
+ */
219
+ getValues(spreadsheetId: string, range: string, options?: GetValuesOptions): Promise<ValueRange>;
220
+ /**
221
+ * Read cell formulas from a range
222
+ */
223
+ getFormulas(spreadsheetId: string, range: string): Promise<ValueRange>;
224
+ /**
225
+ * Read multiple ranges at once
226
+ */
227
+ batchGetValues(spreadsheetId: string, ranges: string[], options?: GetValuesOptions): Promise<BatchGetValuesResponse>;
228
+ /**
229
+ * Clear values from a single range
230
+ */
231
+ clearValues(spreadsheetId: string, range: string): Promise<ClearValuesResponse>;
232
+ /**
233
+ * Clear values from multiple ranges
234
+ */
235
+ batchClearValues(spreadsheetId: string, ranges: string[]): Promise<BatchClearValuesResponse>;
236
+ /**
237
+ * Write values to a range (or starting cell)
238
+ * Range can be "A1" or "A1:D10" - data array determines actual extent
239
+ */
240
+ updateValues(spreadsheetId: string, range: string, values: RawCellValue[][], options?: UpdateValuesOptions): Promise<UpdateValuesResponse>;
241
+ /**
242
+ * Write to multiple ranges in one request
243
+ */
244
+ batchUpdateValues(spreadsheetId: string, data: {
245
+ range: string;
246
+ values: RawCellValue[][];
247
+ }[], options?: UpdateValuesOptions): Promise<BatchUpdateValuesResponse>;
248
+ /**
249
+ * Append rows after the last row of detected table
250
+ */
251
+ appendValues(spreadsheetId: string, range: string, values: RawCellValue[][], options?: AppendValuesOptions): Promise<AppendValuesResponse>;
252
+ /**
253
+ * Search for values matching a query across sheets
254
+ */
255
+ searchValues(spreadsheetId: string, query: string, options?: SearchOptions): Promise<SearchResult>;
256
+ private collectMatches;
257
+ private normalizeValueRange;
258
+ }
259
+ declare function createClient(options: SheetsClientOptions): SheetsClient;
260
+
261
+ /**
262
+ * OAuth 2.0 Authentication
263
+ * Supports pre-obtained access tokens with optional auto-refresh
264
+ *
265
+ * For automation (e.g., n8n), provide:
266
+ * - accessToken: Current access token
267
+ * - refreshToken: For obtaining new tokens when expired
268
+ * - clientId: OAuth client ID
269
+ * - clientSecret: OAuth client secret
270
+ * - expiresAt: When the access token expires (Unix timestamp in ms)
271
+ */
272
+
273
+ declare class OAuthAuth {
274
+ private config;
275
+ private cachedToken;
276
+ private expiresAt;
277
+ constructor(config: OAuthConfig);
278
+ getAccessToken(): Promise<string>;
279
+ private canRefresh;
280
+ private isExpired;
281
+ private refreshToken;
282
+ /**
283
+ * Get current token state for persistence in automation tools
284
+ * Returns updated tokens after any refresh operations
285
+ */
286
+ getTokenState(): {
287
+ accessToken: string;
288
+ refreshToken?: string;
289
+ expiresAt: number;
290
+ };
291
+ }
292
+
293
+ /**
294
+ * Service Account JWT Authentication
295
+ * Uses RS256 signing to exchange JWT for access token
296
+ */
297
+
298
+ declare class ServiceAccountAuth {
299
+ private config;
300
+ private credentials;
301
+ private cachedToken;
302
+ private tokenExpiresAt;
303
+ constructor(config: ServiceAccountConfig);
304
+ getAccessToken(): Promise<string>;
305
+ private loadCredentials;
306
+ private createJwt;
307
+ private base64UrlEncode;
308
+ private exchangeJwtForToken;
309
+ }
310
+
311
+ /**
312
+ * User OAuth Authentication
313
+ * OAuth 2.0 Authorization Code flow with PKCE for personal Google accounts
314
+ */
315
+
316
+ interface OAuthClientCredentials {
317
+ clientId: string;
318
+ clientSecret: string;
319
+ }
320
+ declare function loadStoredTokens(): Promise<StoredTokens | null>;
321
+ declare function deleteTokens(): Promise<void>;
322
+ declare function login(credentials?: OAuthClientCredentials): Promise<StoredTokens>;
323
+ declare class UserAuth {
324
+ private tokens;
325
+ getAccessToken(): Promise<string>;
326
+ }
327
+
328
+ /**
329
+ * Authentication Module Exports
330
+ */
331
+
332
+ interface AuthProvider {
333
+ getAccessToken(): Promise<string>;
334
+ }
335
+ declare function createAuthProvider(config: AuthConfig): AuthProvider;
336
+
337
+ /**
338
+ * HTTP Client for Google Sheets API
339
+ * Uses native Node.js fetch (Node 18+)
340
+ */
341
+ interface HttpClientOptions {
342
+ getAccessToken: () => Promise<string>;
343
+ }
344
+ interface RequestOptions {
345
+ method?: 'GET' | 'POST' | 'PUT' | 'DELETE';
346
+ body?: unknown;
347
+ params?: Record<string, string>;
348
+ }
349
+ declare class HttpClient {
350
+ private getAccessToken;
351
+ constructor(options: HttpClientOptions);
352
+ request<T>(path: string, options?: RequestOptions): Promise<T>;
353
+ private sleep;
354
+ }
355
+
356
+ export { type AppendValuesOptions, type AppendValuesResponse, type AuthConfig, type AuthProvider, type BatchClearValuesResponse, type BatchGetValuesResponse, type BatchUpdateValuesResponse, type CellFormat, type CellValue, type ClearValuesResponse, type Color, type DateTimeRenderOption, type GetValuesOptions, type GridProperties, HttpClient, type InsertDataOption, type MajorDimension, OAuthAuth, type OAuthConfig, type RawCellValue, type SearchMatch, type SearchOptions, type SearchResult, ServiceAccountAuth, type ServiceAccountConfig, type ServiceAccountCredentials, type SheetProperties, type SheetsApiError, type SheetsApiErrorDetail, SheetsClient, type SheetsClientOptions, SheetsError, type Spreadsheet, type SpreadsheetProperties, type StoredTokens, type TextFormat, type UpdateValuesOptions, type UpdateValuesResponse, UserAuth, type UserAuthConfig, type ValueInputOption, type ValueRange, type ValueRenderOption, createAuthProvider, createClient, deleteTokens, loadStoredTokens, login };