bodevops-features 1.0.0 → 1.0.3
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 +388 -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
package/README.md
CHANGED
|
@@ -1,6 +1,17 @@
|
|
|
1
|
-
#
|
|
1
|
+
# BoDevOps Features
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A collection of framework-agnostic TypeScript utilities for Google Drive, Google Sheets, and iDrive e2 operations.
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/bodevops-features)
|
|
6
|
+
[](https://opensource.org/licenses/MIT)
|
|
7
|
+
|
|
8
|
+
## Features
|
|
9
|
+
|
|
10
|
+
- 🚀 **Framework-agnostic** - Works with any TypeScript/JavaScript project
|
|
11
|
+
- 📦 **Tree-shakeable** - Import only what you need
|
|
12
|
+
- 🔒 **Type-safe** - Full TypeScript support with no `any` types
|
|
13
|
+
- 📚 **Well-documented** - Comprehensive JSDoc comments in English
|
|
14
|
+
- ✨ **Easy to use** - Clean, intuitive API design
|
|
4
15
|
|
|
5
16
|
## Installation
|
|
6
17
|
|
|
@@ -8,21 +19,388 @@ BoDevOps features library - a collection of utilities for Google Drive, Google S
|
|
|
8
19
|
npm install bodevops-features
|
|
9
20
|
```
|
|
10
21
|
|
|
11
|
-
##
|
|
22
|
+
## Modules
|
|
23
|
+
|
|
24
|
+
### 🗂️ Google Drive (`GGDrive`)
|
|
25
|
+
|
|
26
|
+
Manage files and folders in Google Drive with ease.
|
|
27
|
+
|
|
28
|
+
**Features:**
|
|
29
|
+
|
|
30
|
+
- Upload files to Drive
|
|
31
|
+
- Create folder hierarchies
|
|
32
|
+
- Share files and folders
|
|
33
|
+
- Transfer ownership
|
|
34
|
+
- Get storage quota information
|
|
35
|
+
- List files in folders
|
|
36
|
+
- Delete files
|
|
37
|
+
|
|
38
|
+
### 📊 Google Sheets (`GGSheet`)
|
|
39
|
+
|
|
40
|
+
Read, write, and manage Google Spreadsheet data.
|
|
41
|
+
|
|
42
|
+
**Features:**
|
|
43
|
+
|
|
44
|
+
- Read sheet data
|
|
45
|
+
- Export data (Append/Overwrite modes)
|
|
46
|
+
- Update cells, rows, and columns
|
|
47
|
+
- Find row by value
|
|
48
|
+
- Delete rows
|
|
49
|
+
- Convert sheet data to typed objects
|
|
50
|
+
- Column name/index conversion utilities
|
|
51
|
+
|
|
52
|
+
---
|
|
53
|
+
|
|
54
|
+
## Quick Start
|
|
55
|
+
|
|
56
|
+
### Google Drive
|
|
12
57
|
|
|
13
58
|
```typescript
|
|
14
59
|
import { GGDrive } from 'bodevops-features';
|
|
15
60
|
|
|
16
|
-
//
|
|
17
|
-
GGDrive.
|
|
61
|
+
// Initialize client
|
|
62
|
+
const driveClient = new GGDrive.GoogleDriveClient({
|
|
63
|
+
keyFilePath: './service-account.json',
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
// Get storage information
|
|
67
|
+
const storage = await driveClient.getStorageInfo();
|
|
68
|
+
console.log(`Used: ${storage.formattedUsed} / ${storage.formattedTotal}`);
|
|
69
|
+
|
|
70
|
+
// Upload a file
|
|
71
|
+
const result = await driveClient.uploadFile({
|
|
72
|
+
localFilePath: './document.pdf',
|
|
73
|
+
driveFolder: 'MyFolder/SubFolder',
|
|
74
|
+
fileName: 'uploaded-document.pdf',
|
|
75
|
+
});
|
|
76
|
+
console.log(`View at: ${result.webViewLink}`);
|
|
77
|
+
|
|
78
|
+
// Upload and share with someone
|
|
79
|
+
const sharedResult = await driveClient.uploadFileAndShare({
|
|
80
|
+
localFilePath: './report.pdf',
|
|
81
|
+
driveFolder: 'SharedReports',
|
|
82
|
+
shareWithEmail: 'colleague@example.com',
|
|
83
|
+
role: 'writer',
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
// List files in a folder
|
|
87
|
+
const files = await driveClient.listFilesInFolder({ folderId: 'root' });
|
|
88
|
+
for (const file of files) {
|
|
89
|
+
console.log(`${file.name} (${file.mimeType})`);
|
|
90
|
+
}
|
|
18
91
|
```
|
|
19
92
|
|
|
20
|
-
|
|
93
|
+
### Google Sheets
|
|
94
|
+
|
|
95
|
+
```typescript
|
|
96
|
+
import { GGSheet } from 'bodevops-features';
|
|
97
|
+
|
|
98
|
+
// Initialize client
|
|
99
|
+
const sheetClient = new GGSheet.GoogleSheetClient({
|
|
100
|
+
keyFilePath: './service-account.json',
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
// Read data from a sheet
|
|
104
|
+
const data = await sheetClient.getValues({
|
|
105
|
+
sheetUrl: 'https://docs.google.com/spreadsheets/d/1abc123...',
|
|
106
|
+
sheetName: 'Sheet1',
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
// Convert to typed objects
|
|
110
|
+
interface Person {
|
|
111
|
+
name: string;
|
|
112
|
+
email: string;
|
|
113
|
+
age: string;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
const people = GGSheet.convertValueSheet<Person>({
|
|
117
|
+
values: data,
|
|
118
|
+
rowOffset: 0, // First row is header
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
// Export data (Overwrite mode)
|
|
122
|
+
await sheetClient.export({
|
|
123
|
+
sheetUrl: 'https://docs.google.com/spreadsheets/d/1abc123...',
|
|
124
|
+
sheetName: 'Sheet1',
|
|
125
|
+
listCols: ['Name', 'Email', 'Age'],
|
|
126
|
+
valsExport: [
|
|
127
|
+
['John Doe', 'john@example.com', '30'],
|
|
128
|
+
['Jane Smith', 'jane@example.com', '25'],
|
|
129
|
+
],
|
|
130
|
+
typeExport: GGSheet.ETypeExport.Overwrite,
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
// Update specific cells
|
|
134
|
+
await sheetClient.updateValuesMultiCells({
|
|
135
|
+
sheetUrl: 'https://docs.google.com/spreadsheets/d/1abc123...',
|
|
136
|
+
sheetName: 'Sheet1',
|
|
137
|
+
cells: [
|
|
138
|
+
{ row: 0, col: 0, content: 'Updated Value' },
|
|
139
|
+
{ row: 1, col: 1, content: 'Another Update' },
|
|
140
|
+
],
|
|
141
|
+
rowOffset: 0,
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
// Find a row by value
|
|
145
|
+
const rowIndex = await sheetClient.getIdxRow({
|
|
146
|
+
sheetUrl: 'https://docs.google.com/spreadsheets/d/1abc123...',
|
|
147
|
+
sheetName: 'Sheet1',
|
|
148
|
+
colName: 'A',
|
|
149
|
+
value: 'John Doe',
|
|
150
|
+
});
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
---
|
|
154
|
+
|
|
155
|
+
## Authentication
|
|
156
|
+
|
|
157
|
+
Both Google Drive and Google Sheets require a Google Service Account for authentication.
|
|
158
|
+
|
|
159
|
+
### Creating a Service Account
|
|
160
|
+
|
|
161
|
+
1. Go to [Google Cloud Console](https://console.cloud.google.com/)
|
|
162
|
+
2. Create a new project or select an existing one
|
|
163
|
+
3. Enable the Google Drive API and Google Sheets API
|
|
164
|
+
4. Create a Service Account:
|
|
165
|
+
- Go to "IAM & Admin" → "Service Accounts"
|
|
166
|
+
- Click "Create Service Account"
|
|
167
|
+
- Fill in the details and create
|
|
168
|
+
5. Create a JSON key:
|
|
169
|
+
- Click on the created service account
|
|
170
|
+
- Go to "Keys" tab
|
|
171
|
+
- Click "Add Key" → "Create new key"
|
|
172
|
+
- Select "JSON" and download
|
|
173
|
+
|
|
174
|
+
### Using Credentials
|
|
175
|
+
|
|
176
|
+
```typescript
|
|
177
|
+
// Option 1: Using key file path
|
|
178
|
+
const client = new GGDrive.GoogleDriveClient({
|
|
179
|
+
keyFilePath: './service-account.json',
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
// Option 2: Using credentials object
|
|
183
|
+
const client = new GGDrive.GoogleDriveClient({
|
|
184
|
+
credentials: {
|
|
185
|
+
type: 'service_account',
|
|
186
|
+
project_id: 'your-project-id',
|
|
187
|
+
private_key: '-----BEGIN PRIVATE KEY-----\n...',
|
|
188
|
+
client_email: 'service-account@project.iam.gserviceaccount.com',
|
|
189
|
+
// ... other fields
|
|
190
|
+
},
|
|
191
|
+
});
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
---
|
|
195
|
+
|
|
196
|
+
## API Reference
|
|
197
|
+
|
|
198
|
+
### Google Drive
|
|
199
|
+
|
|
200
|
+
#### `GoogleDriveClient`
|
|
201
|
+
|
|
202
|
+
**Constructor:**
|
|
203
|
+
|
|
204
|
+
```typescript
|
|
205
|
+
new GoogleDriveClient(config: IGoogleDriveConfig)
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
**Methods:**
|
|
209
|
+
|
|
210
|
+
| Method | Description |
|
|
211
|
+
| ------------------------------- | ----------------------------------- |
|
|
212
|
+
| `getStorageInfo()` | Get Drive storage quota information |
|
|
213
|
+
| `uploadFile(params)` | Upload a file to Drive |
|
|
214
|
+
| `uploadFileAndShare(params)` | Upload and share with email |
|
|
215
|
+
| `deleteFile(params)` | Delete a file from Drive |
|
|
216
|
+
| `listFilesInFolder(params)` | List files in a folder |
|
|
217
|
+
| `makeFilePublic(params)` | Make file accessible via link |
|
|
218
|
+
| `transferFileOwnership(params)` | Transfer file to another user |
|
|
219
|
+
| `shareFolderWithEmail(params)` | Share folder with permissions |
|
|
220
|
+
| `getFolderIdByPath(params)` | Get folder ID from path string |
|
|
221
|
+
| `fileExistsInFolder(params)` | Check if file exists |
|
|
222
|
+
|
|
223
|
+
**Utility Functions:**
|
|
224
|
+
|
|
225
|
+
- `formatBytes({ bytes })` - Convert bytes to human-readable format
|
|
226
|
+
- `normalizeFilePath({ filePath })` - Normalize file path
|
|
227
|
+
- `validateFileExists({ filePath })` - Check if file exists
|
|
228
|
+
- `getFileInfo({ filePath })` - Get file metadata
|
|
229
|
+
|
|
230
|
+
---
|
|
231
|
+
|
|
232
|
+
### Google Sheets
|
|
21
233
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
234
|
+
#### `GoogleSheetClient`
|
|
235
|
+
|
|
236
|
+
**Constructor:**
|
|
237
|
+
|
|
238
|
+
```typescript
|
|
239
|
+
new GoogleSheetClient(config: IGoogleSheetConfig)
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
**Methods:**
|
|
243
|
+
|
|
244
|
+
| Method | Description |
|
|
245
|
+
| ---------------------------------------- | ------------------------------ |
|
|
246
|
+
| `getSheetInfo(params)` | Get spreadsheet metadata |
|
|
247
|
+
| `getValues(params)` | Read all values from sheet |
|
|
248
|
+
| `getIdxRow(params)` | Find row index by value |
|
|
249
|
+
| `export(params)` | Export data (Append/Overwrite) |
|
|
250
|
+
| `updateValuesMultiCells(params)` | Update specific cells |
|
|
251
|
+
| `updateValuesMultiColsByRow(params)` | Update columns in a row |
|
|
252
|
+
| `updateValuesMultiRowsByCol(params)` | Update rows in a column |
|
|
253
|
+
| `updateValuesMultiRowsMultiCols(params)` | Batch update range |
|
|
254
|
+
| `deleteRowSheet(params)` | Delete a row |
|
|
255
|
+
|
|
256
|
+
**Utility Functions:**
|
|
257
|
+
|
|
258
|
+
- `convertIndexToColumnName({ columnIndex })` - Convert 0 → "A", 26 → "AA"
|
|
259
|
+
- `convertColumnNameToIndex({ columnName })` - Convert "A" → 0, "AA" → 26
|
|
260
|
+
- `convertValueSheet({ values, rowOffset })` - Parse sheet to typed objects
|
|
261
|
+
- `getSheetIdFromUrl({ sheetUrl })` - Extract spreadsheet ID
|
|
262
|
+
- `calculateActualRow({ dataRowIndex, rowOffset })` - Calculate sheet row number
|
|
263
|
+
|
|
264
|
+
**Enums:**
|
|
265
|
+
|
|
266
|
+
- `ETypeExport.Append` - Append data to existing
|
|
267
|
+
- `ETypeExport.Overwrite` - Replace all data
|
|
268
|
+
|
|
269
|
+
---
|
|
270
|
+
|
|
271
|
+
## Advanced Examples
|
|
272
|
+
|
|
273
|
+
### Google Drive: Batch Upload with Progress
|
|
274
|
+
|
|
275
|
+
```typescript
|
|
276
|
+
const files = ['file1.pdf', 'file2.pdf', 'file3.pdf'];
|
|
277
|
+
|
|
278
|
+
for (const file of files) {
|
|
279
|
+
const result = await driveClient.uploadFile({
|
|
280
|
+
localFilePath: `./documents/${file}`,
|
|
281
|
+
driveFolder: 'Uploads/2024',
|
|
282
|
+
fileName: file,
|
|
283
|
+
});
|
|
284
|
+
console.log(`✓ Uploaded: ${result.name}`);
|
|
285
|
+
}
|
|
286
|
+
```
|
|
287
|
+
|
|
288
|
+
### Google Sheets: Export Database Query Results
|
|
289
|
+
|
|
290
|
+
```typescript
|
|
291
|
+
import { GGSheet } from 'bodevops-features';
|
|
292
|
+
|
|
293
|
+
// Assume you have query results
|
|
294
|
+
const users = await database.query('SELECT name, email, created_at FROM users');
|
|
295
|
+
|
|
296
|
+
// Map to column definitions
|
|
297
|
+
const colsMapping = {
|
|
298
|
+
name: 'Full Name',
|
|
299
|
+
email: 'Email Address',
|
|
300
|
+
created_at: 'Registration Date',
|
|
301
|
+
};
|
|
302
|
+
|
|
303
|
+
// Extract columns and values
|
|
304
|
+
const { listCols, valsExport } = GGSheet.getListColsAndValsExport({
|
|
305
|
+
colsForSheet: colsMapping,
|
|
306
|
+
resultItems: users,
|
|
307
|
+
});
|
|
308
|
+
|
|
309
|
+
// Export to sheet
|
|
310
|
+
await sheetClient.export({
|
|
311
|
+
sheetUrl: 'https://docs.google.com/spreadsheets/d/...',
|
|
312
|
+
sheetName: 'Users',
|
|
313
|
+
listCols,
|
|
314
|
+
valsExport,
|
|
315
|
+
typeExport: GGSheet.ETypeExport.Overwrite,
|
|
316
|
+
});
|
|
317
|
+
```
|
|
318
|
+
|
|
319
|
+
### Google Sheets: Update Multiple Rows
|
|
320
|
+
|
|
321
|
+
```typescript
|
|
322
|
+
// Update column C for rows 0-4
|
|
323
|
+
await sheetClient.updateValuesMultiRowsByCol({
|
|
324
|
+
sheetUrl: 'https://docs.google.com/spreadsheets/d/...',
|
|
325
|
+
sheetName: 'Sheet1',
|
|
326
|
+
col: 2, // Column C (0-based)
|
|
327
|
+
values: [
|
|
328
|
+
{ row: 0, content: 'Status: Complete' },
|
|
329
|
+
{ row: 1, content: 'Status: Pending' },
|
|
330
|
+
{ row: 2, content: 'Status: Complete' },
|
|
331
|
+
{ row: 3, content: 'Status: Failed' },
|
|
332
|
+
{ row: 4, content: 'Status: Complete' },
|
|
333
|
+
],
|
|
334
|
+
});
|
|
335
|
+
```
|
|
336
|
+
|
|
337
|
+
---
|
|
338
|
+
|
|
339
|
+
## TypeScript Support
|
|
340
|
+
|
|
341
|
+
This library is written in TypeScript and provides full type definitions.
|
|
342
|
+
|
|
343
|
+
```typescript
|
|
344
|
+
import { GGDrive, GGSheet } from 'bodevops-features';
|
|
345
|
+
|
|
346
|
+
// All types are exported
|
|
347
|
+
type UploadResult = GGDrive.IUploadFileResult;
|
|
348
|
+
type SheetInfo = GGSheet.ISpreadsheetInfo;
|
|
349
|
+
type ExportMode = GGSheet.ETypeExport;
|
|
350
|
+
```
|
|
351
|
+
|
|
352
|
+
---
|
|
353
|
+
|
|
354
|
+
## Error Handling
|
|
355
|
+
|
|
356
|
+
All methods throw descriptive errors. Wrap calls in try-catch:
|
|
357
|
+
|
|
358
|
+
```typescript
|
|
359
|
+
try {
|
|
360
|
+
const result = await driveClient.uploadFile({
|
|
361
|
+
localFilePath: './document.pdf',
|
|
362
|
+
driveFolder: 'MyFolder',
|
|
363
|
+
});
|
|
364
|
+
} catch (error) {
|
|
365
|
+
console.error('Upload failed:', error.message);
|
|
366
|
+
// Handle error appropriately
|
|
367
|
+
}
|
|
368
|
+
```
|
|
369
|
+
|
|
370
|
+
---
|
|
371
|
+
|
|
372
|
+
## Contributing
|
|
373
|
+
|
|
374
|
+
Contributions are welcome! Please follow these guidelines:
|
|
375
|
+
|
|
376
|
+
1. Fork the repository
|
|
377
|
+
2. Create a feature branch
|
|
378
|
+
3. Write clean, documented code
|
|
379
|
+
4. Add tests if applicable
|
|
380
|
+
5. Submit a pull request
|
|
381
|
+
|
|
382
|
+
---
|
|
25
383
|
|
|
26
384
|
## License
|
|
27
385
|
|
|
28
|
-
MIT
|
|
386
|
+
MIT © [BoDevOps](https://github.com/HaiSonMin)
|
|
387
|
+
|
|
388
|
+
---
|
|
389
|
+
|
|
390
|
+
## Support
|
|
391
|
+
|
|
392
|
+
- 📧 Email: support@bodevops.com
|
|
393
|
+
- 🐛 Issues: [GitHub Issues](https://github.com/HaiSonMin/BoDevOpsFeature/issues)
|
|
394
|
+
- 📖 Documentation: [Full API Docs](https://github.com/HaiSonMin/BoDevOpsFeature#readme)
|
|
395
|
+
|
|
396
|
+
---
|
|
397
|
+
|
|
398
|
+
## Changelog
|
|
399
|
+
|
|
400
|
+
### v1.0.0 (2026-01-07)
|
|
401
|
+
|
|
402
|
+
- ✨ Initial release
|
|
403
|
+
- 🗂️ Google Drive module
|
|
404
|
+
- 📊 Google Sheets module
|
|
405
|
+
- 📚 Full TypeScript support
|
|
406
|
+
- 📝 Comprehensive documentation
|