bodevops-features 1.0.0 → 1.0.8
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/README.md +699 -10
- package/dist/cjs/index.js +1702 -5
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/index.js +1681 -5
- package/dist/esm/index.js.map +1 -1
- package/dist/types/gg-drive/config.d.ts +66 -0
- package/dist/types/gg-drive/google-drive.d.ts +214 -0
- package/dist/types/gg-drive/index.d.ts +29 -1
- package/dist/types/gg-drive/types.d.ts +176 -0
- package/dist/types/gg-drive/utils.d.ts +111 -0
- package/dist/types/gg-sheet/config.d.ts +65 -0
- package/dist/types/gg-sheet/google-sheet.d.ts +255 -0
- package/dist/types/gg-sheet/index.d.ts +35 -0
- package/dist/types/gg-sheet/types.d.ts +250 -0
- package/dist/types/gg-sheet/utils.d.ts +172 -0
- package/dist/types/index.d.ts +21 -0
- package/package.json +50 -44
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Google Drive Feature Library - Type Definitions
|
|
3
|
+
* @description Type definitions for Google Drive operations including file upload, download, sharing, and storage management.
|
|
4
|
+
* @module gg-drive/types
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Configuration options for Google Drive client initialization.
|
|
8
|
+
* Supports either a path to a service account key file or a direct credentials object.
|
|
9
|
+
*/
|
|
10
|
+
export interface IGoogleDriveConfig {
|
|
11
|
+
/** Path to the service account JSON key file */
|
|
12
|
+
keyFilePath?: string;
|
|
13
|
+
/** Service account credentials object (alternative to keyFilePath) */
|
|
14
|
+
credentials?: IGoogleServiceAccountCredentials;
|
|
15
|
+
/** OAuth scopes for Google Drive API access */
|
|
16
|
+
scopes?: string[];
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Google Service Account credentials structure.
|
|
20
|
+
* This matches the structure of the downloaded JSON key file from Google Cloud Console.
|
|
21
|
+
*/
|
|
22
|
+
export interface IGoogleServiceAccountCredentials {
|
|
23
|
+
/** The type of account, typically "service_account" */
|
|
24
|
+
type: string;
|
|
25
|
+
/** The unique identifier for the project */
|
|
26
|
+
project_id: string;
|
|
27
|
+
/** The private key identifier */
|
|
28
|
+
private_key_id: string;
|
|
29
|
+
/** The private key in PEM format */
|
|
30
|
+
private_key: string;
|
|
31
|
+
/** The service account email address */
|
|
32
|
+
client_email: string;
|
|
33
|
+
/** The unique client identifier */
|
|
34
|
+
client_id: string;
|
|
35
|
+
/** The authentication URI */
|
|
36
|
+
auth_uri: string;
|
|
37
|
+
/** The token URI for obtaining access tokens */
|
|
38
|
+
token_uri: string;
|
|
39
|
+
/** The authentication provider certificate URL */
|
|
40
|
+
auth_provider_x509_cert_url: string;
|
|
41
|
+
/** The client certificate URL */
|
|
42
|
+
client_x509_cert_url: string;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Result returned after successfully uploading a file to Google Drive.
|
|
46
|
+
*/
|
|
47
|
+
export interface IUploadFileResult {
|
|
48
|
+
/** The unique identifier of the uploaded file in Google Drive */
|
|
49
|
+
id: string;
|
|
50
|
+
/** The name of the file as stored in Google Drive */
|
|
51
|
+
name: string;
|
|
52
|
+
/** URL to view the file in a web browser (optional) */
|
|
53
|
+
webViewLink?: string;
|
|
54
|
+
/** URL to directly download the file content (optional) */
|
|
55
|
+
webContentLink?: string;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Information about a file or folder in Google Drive.
|
|
59
|
+
*/
|
|
60
|
+
export interface IFileInfo {
|
|
61
|
+
/** The unique identifier of the file */
|
|
62
|
+
id: string;
|
|
63
|
+
/** The name of the file */
|
|
64
|
+
name: string;
|
|
65
|
+
/** The MIME type of the file (e.g., "application/pdf", "application/vnd.google-apps.folder") */
|
|
66
|
+
mimeType: string;
|
|
67
|
+
/** URL to view the file in a web browser (optional) */
|
|
68
|
+
webViewLink?: string;
|
|
69
|
+
/** Array of parent folder IDs (optional) */
|
|
70
|
+
parents?: string[];
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Storage quota information for Google Drive account.
|
|
74
|
+
*/
|
|
75
|
+
export interface IStorageInfo {
|
|
76
|
+
/** Total storage used in bytes */
|
|
77
|
+
used: number;
|
|
78
|
+
/** Total storage limit in bytes */
|
|
79
|
+
total: number;
|
|
80
|
+
/** Storage used specifically by Drive files in bytes */
|
|
81
|
+
usedInDrive: number;
|
|
82
|
+
/** Percentage of storage used (0-100) */
|
|
83
|
+
percentage: number;
|
|
84
|
+
/** Human-readable format of used storage (e.g., "1.5 GB") */
|
|
85
|
+
formattedUsed: string;
|
|
86
|
+
/** Human-readable format of total storage (e.g., "15 GB") */
|
|
87
|
+
formattedTotal: string;
|
|
88
|
+
/** Human-readable format of storage used in Drive (e.g., "500 MB") */
|
|
89
|
+
formattedUsedInDrive: string;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Available permission roles for sharing files and folders.
|
|
93
|
+
* - 'reader': Can view files
|
|
94
|
+
* - 'writer': Can view and edit files
|
|
95
|
+
* - 'owner': Full ownership with all permissions
|
|
96
|
+
*/
|
|
97
|
+
export type TRoleShare = 'reader' | 'writer' | 'owner';
|
|
98
|
+
/**
|
|
99
|
+
* Parameters for uploading a file to Google Drive.
|
|
100
|
+
*/
|
|
101
|
+
export interface IUploadFileParams {
|
|
102
|
+
/** Absolute path to the local file to upload */
|
|
103
|
+
localFilePath: string;
|
|
104
|
+
/** Target folder path in Google Drive (e.g., "MyFolder/SubFolder"). Use empty string or "/" for root. */
|
|
105
|
+
driveFolder: string;
|
|
106
|
+
/** Optional custom file name. If not provided, the original file name is used. */
|
|
107
|
+
fileName?: string;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Parameters for uploading a file and sharing it with another user.
|
|
111
|
+
*/
|
|
112
|
+
export interface IUploadFileAndShareParams extends IUploadFileParams {
|
|
113
|
+
/** Email address to share the file with */
|
|
114
|
+
shareWithEmail: string;
|
|
115
|
+
/** Permission role for the shared user (default: 'reader') */
|
|
116
|
+
role?: TRoleShare;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Parameters for listing files in a folder.
|
|
120
|
+
*/
|
|
121
|
+
export interface IListFilesParams {
|
|
122
|
+
/** The folder ID to list files from. Use 'root' for the root folder. Default: 'root' */
|
|
123
|
+
folderId?: string;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Parameters for deleting a file from Google Drive.
|
|
127
|
+
*/
|
|
128
|
+
export interface IDeleteFileParams {
|
|
129
|
+
/** The unique identifier of the file to delete */
|
|
130
|
+
fileId: string;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Parameters for making a file publicly accessible.
|
|
134
|
+
*/
|
|
135
|
+
export interface IMakeFilePublicParams {
|
|
136
|
+
/** The unique identifier of the file to make public */
|
|
137
|
+
fileId: string;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Parameters for transferring file ownership to another user.
|
|
141
|
+
*/
|
|
142
|
+
export interface ITransferOwnershipParams {
|
|
143
|
+
/** The unique identifier of the file */
|
|
144
|
+
fileId: string;
|
|
145
|
+
/** Email address of the new owner */
|
|
146
|
+
newOwnerEmail: string;
|
|
147
|
+
/** Permission role to assign (default: 'reader') */
|
|
148
|
+
role?: TRoleShare;
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Parameters for sharing a folder with another user.
|
|
152
|
+
*/
|
|
153
|
+
export interface IShareFolderParams {
|
|
154
|
+
/** The unique identifier of the folder */
|
|
155
|
+
folderId: string;
|
|
156
|
+
/** Email address to share the folder with */
|
|
157
|
+
emailAddress: string;
|
|
158
|
+
/** Permission role for the shared user (default: 'writer') */
|
|
159
|
+
role?: TRoleShare;
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Parameters for getting folder ID by path.
|
|
163
|
+
*/
|
|
164
|
+
export interface IGetFolderIdParams {
|
|
165
|
+
/** Folder path (e.g., "folder1/folder2/folder3") */
|
|
166
|
+
folderPath: string;
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Parameters for checking if a file exists in a folder.
|
|
170
|
+
*/
|
|
171
|
+
export interface IFileExistsParams {
|
|
172
|
+
/** The name of the file to check */
|
|
173
|
+
fileName: string;
|
|
174
|
+
/** The folder ID to search in. Default: 'root' */
|
|
175
|
+
folderId?: string;
|
|
176
|
+
}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Google Drive Feature Library - Utility Functions
|
|
3
|
+
* @description Helper functions for file handling, formatting, and validation in Google Drive operations.
|
|
4
|
+
* @module gg-drive/utils
|
|
5
|
+
*/
|
|
6
|
+
import * as fs from 'fs';
|
|
7
|
+
/**
|
|
8
|
+
* Converts a byte count into a human-readable string format.
|
|
9
|
+
*
|
|
10
|
+
* @param bytes - The number of bytes to format
|
|
11
|
+
* @returns A human-readable string representation (e.g., "1.5 GB")
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* formatBytes(0); // "0 Bytes"
|
|
16
|
+
* formatBytes(1024); // "1 KB"
|
|
17
|
+
* formatBytes(1536); // "1.5 KB"
|
|
18
|
+
* formatBytes(1073741824); // "1 GB"
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export declare function formatBytes({ bytes }: {
|
|
22
|
+
bytes: number;
|
|
23
|
+
}): string;
|
|
24
|
+
/**
|
|
25
|
+
* Normalizes a file path to use the correct path separators for the current OS.
|
|
26
|
+
* Also resolves relative paths to absolute paths.
|
|
27
|
+
*
|
|
28
|
+
* @param filePath - The file path to normalize
|
|
29
|
+
* @returns The normalized absolute file path
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```typescript
|
|
33
|
+
* normalizeFilePath({ filePath: './documents/file.pdf' });
|
|
34
|
+
* // Returns: "D:\\MyFolder\\documents\\file.pdf" (on Windows)
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
export declare function normalizeFilePath({ filePath }: {
|
|
38
|
+
filePath: string;
|
|
39
|
+
}): string;
|
|
40
|
+
/**
|
|
41
|
+
* Validates that a file exists at the specified path.
|
|
42
|
+
*
|
|
43
|
+
* @param filePath - The absolute path to the file to validate
|
|
44
|
+
* @returns True if the file exists, false otherwise
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* ```typescript
|
|
48
|
+
* const exists = validateFileExists({ filePath: 'D:\\MyFolder\\file.pdf' });
|
|
49
|
+
* if (!exists) {
|
|
50
|
+
* console.log('File not found!');
|
|
51
|
+
* }
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
export declare function validateFileExists({ filePath }: {
|
|
55
|
+
filePath: string;
|
|
56
|
+
}): boolean;
|
|
57
|
+
/**
|
|
58
|
+
* Gets detailed information about a local file.
|
|
59
|
+
*
|
|
60
|
+
* @param filePath - The absolute path to the file
|
|
61
|
+
* @returns File information object or null if file doesn't exist
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* ```typescript
|
|
65
|
+
* const info = getFileInfo({ filePath: './document.pdf' });
|
|
66
|
+
* if (info) {
|
|
67
|
+
* console.log(`File size: ${info.sizeFormatted}`);
|
|
68
|
+
* }
|
|
69
|
+
* ```
|
|
70
|
+
*/
|
|
71
|
+
export declare function getFileInfo({ filePath }: {
|
|
72
|
+
filePath: string;
|
|
73
|
+
}): {
|
|
74
|
+
name: string;
|
|
75
|
+
extension: string;
|
|
76
|
+
directory: string;
|
|
77
|
+
size: number;
|
|
78
|
+
sizeFormatted: string;
|
|
79
|
+
} | null;
|
|
80
|
+
/**
|
|
81
|
+
* Parses a folder path string into an array of folder names.
|
|
82
|
+
*
|
|
83
|
+
* @param folderPath - The folder path to parse (e.g., "folder1/folder2/folder3")
|
|
84
|
+
* @returns An array of folder names
|
|
85
|
+
*
|
|
86
|
+
* @example
|
|
87
|
+
* ```typescript
|
|
88
|
+
* parseFolderPath({ folderPath: 'a/b/c' }); // ['a', 'b', 'c']
|
|
89
|
+
* parseFolderPath({ folderPath: '/' }); // []
|
|
90
|
+
* parseFolderPath({ folderPath: '' }); // []
|
|
91
|
+
* ```
|
|
92
|
+
*/
|
|
93
|
+
export declare function parseFolderPath({ folderPath }: {
|
|
94
|
+
folderPath: string;
|
|
95
|
+
}): string[];
|
|
96
|
+
/**
|
|
97
|
+
* Creates a readable stream for a local file.
|
|
98
|
+
*
|
|
99
|
+
* @param filePath - The absolute path to the file
|
|
100
|
+
* @returns A readable stream for the file
|
|
101
|
+
* @throws Error if the file doesn't exist
|
|
102
|
+
*
|
|
103
|
+
* @example
|
|
104
|
+
* ```typescript
|
|
105
|
+
* const stream = createFileReadStream({ filePath: './document.pdf' });
|
|
106
|
+
* // Use stream for upload
|
|
107
|
+
* ```
|
|
108
|
+
*/
|
|
109
|
+
export declare function createFileReadStream({ filePath }: {
|
|
110
|
+
filePath: string;
|
|
111
|
+
}): fs.ReadStream;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Google Sheet Feature Library - Configuration Module
|
|
3
|
+
* @description Configuration management for Google Sheet client initialization and authentication.
|
|
4
|
+
* @module gg-sheet/config
|
|
5
|
+
*/
|
|
6
|
+
import { IGoogleSheetConfig, IGoogleServiceAccountCredentials } from './types';
|
|
7
|
+
/**
|
|
8
|
+
* Default OAuth scope required for Google Sheets operations.
|
|
9
|
+
*/
|
|
10
|
+
export declare const DEFAULT_SHEET_SCOPES: string[];
|
|
11
|
+
/**
|
|
12
|
+
* Google Sheet Configuration Manager.
|
|
13
|
+
* Handles validation and normalization of configuration options for the Google Sheet client.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```typescript
|
|
17
|
+
* // Using key file path
|
|
18
|
+
* const config = new GoogleSheetConfig({
|
|
19
|
+
* keyFilePath: './service-account.json'
|
|
20
|
+
* });
|
|
21
|
+
*
|
|
22
|
+
* // Using credentials object
|
|
23
|
+
* const config = new GoogleSheetConfig({
|
|
24
|
+
* credentials: {
|
|
25
|
+
* type: 'service_account',
|
|
26
|
+
* project_id: 'my-project',
|
|
27
|
+
* private_key: '-----BEGIN PRIVATE KEY-----\n...',
|
|
28
|
+
* client_email: 'service-account@my-project.iam.gserviceaccount.com',
|
|
29
|
+
* // ... other fields
|
|
30
|
+
* }
|
|
31
|
+
* });
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
export declare class GoogleSheetConfig {
|
|
35
|
+
/** Path to the service account key file */
|
|
36
|
+
readonly keyFilePath?: string;
|
|
37
|
+
/** Service account credentials object */
|
|
38
|
+
readonly credentials?: IGoogleServiceAccountCredentials;
|
|
39
|
+
/** OAuth scopes for Google Sheets API */
|
|
40
|
+
readonly scopes: string[];
|
|
41
|
+
/**
|
|
42
|
+
* Creates a new GoogleSheetConfig instance.
|
|
43
|
+
*
|
|
44
|
+
* @param config - Configuration options for Google Sheet client
|
|
45
|
+
* @throws Error if neither keyFilePath nor credentials is provided
|
|
46
|
+
*/
|
|
47
|
+
constructor({ keyFilePath, credentials, scopes }: IGoogleSheetConfig);
|
|
48
|
+
/**
|
|
49
|
+
* Validates that the credentials object contains all required fields.
|
|
50
|
+
*
|
|
51
|
+
* @param credentials - The credentials object to validate
|
|
52
|
+
* @throws Error if required fields are missing
|
|
53
|
+
*/
|
|
54
|
+
private validateCredentials;
|
|
55
|
+
/**
|
|
56
|
+
* Returns the authentication configuration object suitable for googleapis.
|
|
57
|
+
*
|
|
58
|
+
* @returns Authentication options for Google Auth
|
|
59
|
+
*/
|
|
60
|
+
getAuthOptions(): {
|
|
61
|
+
keyFile?: string;
|
|
62
|
+
credentials?: IGoogleServiceAccountCredentials;
|
|
63
|
+
scopes: string[];
|
|
64
|
+
};
|
|
65
|
+
}
|
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Google Sheet Feature Library - Main Client Class
|
|
3
|
+
* @description A framework-agnostic client for interacting with Google Sheets API.
|
|
4
|
+
* Provides methods for reading, writing, and managing spreadsheet data.
|
|
5
|
+
* @module gg-sheet/google-sheet
|
|
6
|
+
*/
|
|
7
|
+
import { IGoogleSheetConfig, ISpreadsheetInfo, IGetSheetInfoParams, IGetValuesParams, IGetIdxRowParams, IExportParams, IUpdateMultiCellsParams, IUpdateMultiColsByRowParams, IUpdateMultiRowsByColParams, IUpdateMultiRowsMultiColsParams, IDeleteRowParams } from './types';
|
|
8
|
+
/**
|
|
9
|
+
* Google Sheet Client for managing spreadsheet data.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* import { GoogleSheetClient } from 'bodevops-features/gg-sheet';
|
|
14
|
+
*
|
|
15
|
+
* const client = new GoogleSheetClient({
|
|
16
|
+
* keyFilePath: './service-account.json'
|
|
17
|
+
* });
|
|
18
|
+
*
|
|
19
|
+
* // Read data from a sheet
|
|
20
|
+
* const data = await client.getValues({
|
|
21
|
+
* sheetUrl: 'https://docs.google.com/spreadsheets/d/...',
|
|
22
|
+
* sheetName: 'Sheet1'
|
|
23
|
+
* });
|
|
24
|
+
*
|
|
25
|
+
* // Update specific cells
|
|
26
|
+
* await client.updateValuesMultiCells({
|
|
27
|
+
* sheetUrl: 'https://docs.google.com/spreadsheets/d/...',
|
|
28
|
+
* sheetName: 'Sheet1',
|
|
29
|
+
* cells: [
|
|
30
|
+
* { row: 0, col: 0, content: 'Hello' },
|
|
31
|
+
* { row: 0, col: 1, content: 'World' }
|
|
32
|
+
* ]
|
|
33
|
+
* });
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
export declare class GoogleSheetClient {
|
|
37
|
+
private readonly config;
|
|
38
|
+
/**
|
|
39
|
+
* Creates a new GoogleSheetClient instance.
|
|
40
|
+
*
|
|
41
|
+
* @param configOptions - Configuration options for the Google Sheet client
|
|
42
|
+
*/
|
|
43
|
+
constructor(configOptions: IGoogleSheetConfig);
|
|
44
|
+
/**
|
|
45
|
+
* Creates and returns an authenticated Google Sheets API client.
|
|
46
|
+
*
|
|
47
|
+
* @returns A Promise that resolves to an authenticated Sheets API client
|
|
48
|
+
*/
|
|
49
|
+
private getSheetsClient;
|
|
50
|
+
/**
|
|
51
|
+
* Extracts the spreadsheet ID from a URL and validates it.
|
|
52
|
+
*
|
|
53
|
+
* @param sheetUrl - The Google Sheets URL
|
|
54
|
+
* @returns The spreadsheet ID
|
|
55
|
+
* @throws Error if the URL is invalid
|
|
56
|
+
*/
|
|
57
|
+
private extractSheetId;
|
|
58
|
+
/**
|
|
59
|
+
* Retrieves information about a Google Spreadsheet, including all sheet tabs.
|
|
60
|
+
*
|
|
61
|
+
* @param params - Parameters including the sheet URL
|
|
62
|
+
* @returns A Promise that resolves to spreadsheet information
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* ```typescript
|
|
66
|
+
* const info = await client.getSheetInfo({
|
|
67
|
+
* sheetUrl: 'https://docs.google.com/spreadsheets/d/...'
|
|
68
|
+
* });
|
|
69
|
+
* console.log(`Spreadsheet: ${info.spreadsheetTitle}`);
|
|
70
|
+
* console.log(`Sheets: ${info.sheets.map(s => s.title).join(', ')}`);
|
|
71
|
+
* ```
|
|
72
|
+
*/
|
|
73
|
+
getSheetInfo({ sheetUrl }: IGetSheetInfoParams): Promise<ISpreadsheetInfo>;
|
|
74
|
+
/**
|
|
75
|
+
* Reads all values from a specific sheet tab.
|
|
76
|
+
*
|
|
77
|
+
* @param params - Parameters including sheet URL, sheet name, and optional row limit
|
|
78
|
+
* @returns A Promise that resolves to a 2D array of string values
|
|
79
|
+
*
|
|
80
|
+
* @example
|
|
81
|
+
* ```typescript
|
|
82
|
+
* const data = await client.getValues({
|
|
83
|
+
* sheetUrl: 'https://docs.google.com/spreadsheets/d/...',
|
|
84
|
+
* sheetName: 'Sheet1',
|
|
85
|
+
* endRow: 100 // Optional: limit to first 100 rows
|
|
86
|
+
* });
|
|
87
|
+
*
|
|
88
|
+
* for (const row of data) {
|
|
89
|
+
* console.log(row.join(', '));
|
|
90
|
+
* }
|
|
91
|
+
* ```
|
|
92
|
+
*/
|
|
93
|
+
getValues({ sheetUrl, sheetName, endRow }: IGetValuesParams): Promise<string[][]>;
|
|
94
|
+
/**
|
|
95
|
+
* Finds the row index (0-based) where a specific value appears in a column.
|
|
96
|
+
*
|
|
97
|
+
* @param params - Parameters including sheet URL, sheet name, column name, and value to find
|
|
98
|
+
* @returns A Promise that resolves to the row index (0-based), or -1 if not found
|
|
99
|
+
*
|
|
100
|
+
* @example
|
|
101
|
+
* ```typescript
|
|
102
|
+
* const rowIndex = await client.getIdxRow({
|
|
103
|
+
* sheetUrl: 'https://docs.google.com/spreadsheets/d/...',
|
|
104
|
+
* sheetName: 'Sheet1',
|
|
105
|
+
* colName: 'A',
|
|
106
|
+
* value: 'John Doe'
|
|
107
|
+
* });
|
|
108
|
+
*
|
|
109
|
+
* if (rowIndex >= 0) {
|
|
110
|
+
* console.log(`Found at row index: ${rowIndex}`);
|
|
111
|
+
* }
|
|
112
|
+
* ```
|
|
113
|
+
*/
|
|
114
|
+
getIdxRow({ sheetUrl, sheetName, colName, value, }: IGetIdxRowParams): Promise<number>;
|
|
115
|
+
/**
|
|
116
|
+
* Exports data to a Google Sheet with either Append or Overwrite mode.
|
|
117
|
+
*
|
|
118
|
+
* @param params - Export parameters including data and export type
|
|
119
|
+
* @returns A Promise that resolves to true if successful
|
|
120
|
+
*
|
|
121
|
+
* @example
|
|
122
|
+
* ```typescript
|
|
123
|
+
* // Overwrite existing data
|
|
124
|
+
* await client.export({
|
|
125
|
+
* sheetUrl: 'https://docs.google.com/spreadsheets/d/...',
|
|
126
|
+
* sheetName: 'Sheet1',
|
|
127
|
+
* listCols: ['Name', 'Email', 'Age'],
|
|
128
|
+
* valsExport: [
|
|
129
|
+
* ['John', 'john@example.com', '30'],
|
|
130
|
+
* ['Jane', 'jane@example.com', '25']
|
|
131
|
+
* ],
|
|
132
|
+
* typeExport: ETypeExport.Overwrite
|
|
133
|
+
* });
|
|
134
|
+
*
|
|
135
|
+
* // Append to existing data
|
|
136
|
+
* await client.export({
|
|
137
|
+
* sheetUrl: 'https://docs.google.com/spreadsheets/d/...',
|
|
138
|
+
* sheetName: 'Sheet1',
|
|
139
|
+
* listCols: ['Name', 'Email', 'Age'],
|
|
140
|
+
* valsExport: [['New User', 'new@example.com', '28']],
|
|
141
|
+
* typeExport: ETypeExport.Append
|
|
142
|
+
* });
|
|
143
|
+
* ```
|
|
144
|
+
*/
|
|
145
|
+
export({ sheetUrl, sheetName, listCols, valsExport, typeExport, }: IExportParams): Promise<boolean>;
|
|
146
|
+
/**
|
|
147
|
+
* Executes an overwrite export - writes headers and data from row 1.
|
|
148
|
+
*/
|
|
149
|
+
private executeOverwriteExport;
|
|
150
|
+
/**
|
|
151
|
+
* Executes an append export - finds empty rows and appends data.
|
|
152
|
+
*/
|
|
153
|
+
private executeAppendExport;
|
|
154
|
+
/**
|
|
155
|
+
* Updates multiple cells at specific row and column positions.
|
|
156
|
+
*
|
|
157
|
+
* @param params - Update parameters including cells to update
|
|
158
|
+
* @returns A Promise that resolves to true if successful
|
|
159
|
+
*
|
|
160
|
+
* @example
|
|
161
|
+
* ```typescript
|
|
162
|
+
* await client.updateValuesMultiCells({
|
|
163
|
+
* sheetUrl: 'https://docs.google.com/spreadsheets/d/...',
|
|
164
|
+
* sheetName: 'Sheet1',
|
|
165
|
+
* cells: [
|
|
166
|
+
* { row: 0, col: 0, content: 'Updated A2' },
|
|
167
|
+
* { row: 1, col: 1, content: 'Updated B3' },
|
|
168
|
+
* { row: 2, col: 2, content: 'Updated C4' }
|
|
169
|
+
* ],
|
|
170
|
+
* rowOffset: 0 // Header at row 1, data starts at row 2
|
|
171
|
+
* });
|
|
172
|
+
* ```
|
|
173
|
+
*/
|
|
174
|
+
updateValuesMultiCells({ sheetUrl, sheetName, cells, rowOffset, }: IUpdateMultiCellsParams): Promise<boolean>;
|
|
175
|
+
/**
|
|
176
|
+
* Updates multiple columns in a single row.
|
|
177
|
+
*
|
|
178
|
+
* @param params - Update parameters including row and column values
|
|
179
|
+
* @returns A Promise that resolves to true if successful
|
|
180
|
+
*
|
|
181
|
+
* @example
|
|
182
|
+
* ```typescript
|
|
183
|
+
* await client.updateValuesMultiColsByRow({
|
|
184
|
+
* sheetUrl: 'https://docs.google.com/spreadsheets/d/...',
|
|
185
|
+
* sheetName: 'Sheet1',
|
|
186
|
+
* row: 5,
|
|
187
|
+
* values: [
|
|
188
|
+
* { col: 0, content: 'Value for A7' },
|
|
189
|
+
* { col: 1, content: 'Value for B7' },
|
|
190
|
+
* { col: 2, content: 'Value for C7' }
|
|
191
|
+
* ]
|
|
192
|
+
* });
|
|
193
|
+
* ```
|
|
194
|
+
*/
|
|
195
|
+
updateValuesMultiColsByRow({ sheetUrl, sheetName, row, values, rowOffset, }: IUpdateMultiColsByRowParams): Promise<boolean>;
|
|
196
|
+
/**
|
|
197
|
+
* Updates multiple rows in a single column.
|
|
198
|
+
*
|
|
199
|
+
* @param params - Update parameters including column and row values
|
|
200
|
+
* @returns A Promise that resolves to true if successful
|
|
201
|
+
*
|
|
202
|
+
* @example
|
|
203
|
+
* ```typescript
|
|
204
|
+
* await client.updateValuesMultiRowsByCol({
|
|
205
|
+
* sheetUrl: 'https://docs.google.com/spreadsheets/d/...',
|
|
206
|
+
* sheetName: 'Sheet1',
|
|
207
|
+
* col: 2,
|
|
208
|
+
* values: [
|
|
209
|
+
* { row: 0, content: 'Row 1 Col C' },
|
|
210
|
+
* { row: 1, content: 'Row 2 Col C' },
|
|
211
|
+
* { row: 2, content: 'Row 3 Col C' }
|
|
212
|
+
* ]
|
|
213
|
+
* });
|
|
214
|
+
* ```
|
|
215
|
+
*/
|
|
216
|
+
updateValuesMultiRowsByCol({ sheetUrl, sheetName, col, values, rowOffset, }: IUpdateMultiRowsByColParams): Promise<boolean>;
|
|
217
|
+
/**
|
|
218
|
+
* Updates a range of multiple rows and columns at once.
|
|
219
|
+
*
|
|
220
|
+
* @param params - Update parameters including value matrix
|
|
221
|
+
* @returns A Promise that resolves to true if successful
|
|
222
|
+
*
|
|
223
|
+
* @example
|
|
224
|
+
* ```typescript
|
|
225
|
+
* await client.updateValuesMultiRowsMultiCols({
|
|
226
|
+
* sheetUrl: 'https://docs.google.com/spreadsheets/d/...',
|
|
227
|
+
* sheetName: 'Sheet1',
|
|
228
|
+
* values: [
|
|
229
|
+
* ['A1', 'B1', 'C1'],
|
|
230
|
+
* ['A2', 'B2', 'C2'],
|
|
231
|
+
* ['A3', 'B3', 'C3']
|
|
232
|
+
* ],
|
|
233
|
+
* startRow: 0,
|
|
234
|
+
* startCol: 0
|
|
235
|
+
* });
|
|
236
|
+
* ```
|
|
237
|
+
*/
|
|
238
|
+
updateValuesMultiRowsMultiCols({ sheetUrl, sheetName, values, startRow, endRow, startCol, rowOffset, }: IUpdateMultiRowsMultiColsParams): Promise<boolean>;
|
|
239
|
+
/**
|
|
240
|
+
* Deletes a row from a sheet.
|
|
241
|
+
*
|
|
242
|
+
* @param params - Delete parameters including row index
|
|
243
|
+
* @returns A Promise that resolves to true if successful
|
|
244
|
+
*
|
|
245
|
+
* @example
|
|
246
|
+
* ```typescript
|
|
247
|
+
* await client.deleteRowSheet({
|
|
248
|
+
* sheetUrl: 'https://docs.google.com/spreadsheets/d/...',
|
|
249
|
+
* sheetName: 'Sheet1',
|
|
250
|
+
* row: 5 // Delete data row at index 5
|
|
251
|
+
* });
|
|
252
|
+
* ```
|
|
253
|
+
*/
|
|
254
|
+
deleteRowSheet({ sheetUrl, sheetName, row, rowOffset, }: IDeleteRowParams): Promise<boolean>;
|
|
255
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Google Sheet Feature Library
|
|
3
|
+
* @description A framework-agnostic library for interacting with Google Sheets API.
|
|
4
|
+
* Provides easy-to-use methods for reading, writing, and managing spreadsheet data.
|
|
5
|
+
* @module gg-sheet
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* import { GoogleSheetClient, ETypeExport } from 'bodevops-features/gg-sheet';
|
|
10
|
+
*
|
|
11
|
+
* const client = new GoogleSheetClient({
|
|
12
|
+
* keyFilePath: './service-account.json'
|
|
13
|
+
* });
|
|
14
|
+
*
|
|
15
|
+
* // Read data from a sheet
|
|
16
|
+
* const data = await client.getValues({
|
|
17
|
+
* sheetUrl: 'https://docs.google.com/spreadsheets/d/...',
|
|
18
|
+
* sheetName: 'Sheet1'
|
|
19
|
+
* });
|
|
20
|
+
*
|
|
21
|
+
* // Export data
|
|
22
|
+
* await client.export({
|
|
23
|
+
* sheetUrl: 'https://docs.google.com/spreadsheets/d/...',
|
|
24
|
+
* sheetName: 'Sheet1',
|
|
25
|
+
* listCols: ['Name', 'Email'],
|
|
26
|
+
* valsExport: [['John', 'john@example.com']],
|
|
27
|
+
* typeExport: ETypeExport.Append
|
|
28
|
+
* });
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export { GoogleSheetClient } from './google-sheet';
|
|
32
|
+
export { GoogleSheetConfig, DEFAULT_SHEET_SCOPES } from './config';
|
|
33
|
+
export type { IGoogleSheetConfig, IGoogleServiceAccountCredentials, ISheetChildrenInfo, ISheetValUpdateCell, ISpreadsheetInfo, IGetSheetInfoParams, IGetValuesParams, IGetIdxRowParams, IExportParams, IUpdateMultiCellsParams, IColValuePair, IUpdateMultiColsByRowParams, IRowValuePair, IUpdateMultiRowsByColParams, IUpdateMultiRowsMultiColsParams, IDeleteRowParams, IConvertValueSheetParams, IListColsAndValsExport, } from './types';
|
|
34
|
+
export { ETypeExport } from './types';
|
|
35
|
+
export { getSheetIdFromUrl, convertIndexToColumnName, convertColumnNameToIndex, convertValueSheet, getIndexCol, getListColsAndValsExport, isValidSheetUrl, calculateActualRow, } from './utils';
|