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.
@@ -0,0 +1,250 @@
1
+ /**
2
+ * Google Sheet Feature Library - Type Definitions
3
+ * @description Type definitions for Google Sheet operations including reading, writing, and exporting data.
4
+ * @module gg-sheet/types
5
+ */
6
+ /**
7
+ * Configuration options for Google Sheet client initialization.
8
+ * Supports either a path to a service account key file or a direct credentials object.
9
+ */
10
+ export interface IGoogleSheetConfig {
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 Sheets 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
+ * Information about a sheet (tab) within a Google Spreadsheet.
46
+ */
47
+ export interface ISheetChildrenInfo {
48
+ /** The title/name of the sheet tab */
49
+ title: string;
50
+ /** The unique identifier of the sheet within the spreadsheet */
51
+ sheetId: number;
52
+ /** The total number of rows in the sheet */
53
+ rowCount: number;
54
+ /** The total number of columns in the sheet */
55
+ columnCount: number;
56
+ }
57
+ /**
58
+ * Structure for updating a single cell in a sheet.
59
+ */
60
+ export interface ISheetValUpdateCell {
61
+ /** Row index (0-based) */
62
+ row: number;
63
+ /** Column index (0-based) */
64
+ col: number;
65
+ /** The content to write to the cell */
66
+ content: string;
67
+ }
68
+ /**
69
+ * Export type enumeration for sheet export operations.
70
+ */
71
+ export declare enum ETypeExport {
72
+ /** Append data to the end of existing data */
73
+ Append = "Append",
74
+ /** Overwrite all existing data starting from row 1 */
75
+ Overwrite = "Overwrite"
76
+ }
77
+ /**
78
+ * Information about a Google Spreadsheet.
79
+ */
80
+ export interface ISpreadsheetInfo {
81
+ /** The title of the spreadsheet */
82
+ spreadsheetTitle: string;
83
+ /** Array of sheet tabs within the spreadsheet */
84
+ sheets: ISheetChildrenInfo[];
85
+ }
86
+ /**
87
+ * Parameters for getting sheet information.
88
+ */
89
+ export interface IGetSheetInfoParams {
90
+ /** The URL of the Google Spreadsheet */
91
+ sheetUrl: string;
92
+ }
93
+ /**
94
+ * Parameters for reading values from a sheet.
95
+ */
96
+ export interface IGetValuesParams {
97
+ /** The URL of the Google Spreadsheet */
98
+ sheetUrl: string;
99
+ /** The name of the specific sheet tab to read from */
100
+ sheetName: string;
101
+ /** Optional limit on the number of rows to read */
102
+ endRow?: number;
103
+ }
104
+ /**
105
+ * Parameters for finding a row index by column value.
106
+ */
107
+ export interface IGetIdxRowParams {
108
+ /** The URL of the Google Spreadsheet */
109
+ sheetUrl: string;
110
+ /** The name of the specific sheet tab */
111
+ sheetName: string;
112
+ /** The column name to search in (e.g., "A", "B", "AB") */
113
+ colName: string;
114
+ /** The value to search for */
115
+ value: string;
116
+ }
117
+ /**
118
+ * Parameters for exporting data to a sheet.
119
+ */
120
+ export interface IExportParams {
121
+ /** The URL of the Google Spreadsheet */
122
+ sheetUrl: string;
123
+ /** The name of the specific sheet tab to write to */
124
+ sheetName: string;
125
+ /** Array of column headers */
126
+ listCols: string[];
127
+ /** Matrix of data values to export (each inner array is a row) */
128
+ valsExport: string[][];
129
+ /** Export type: Append or Overwrite */
130
+ typeExport: ETypeExport;
131
+ }
132
+ /**
133
+ * Parameters for updating multiple cells at specific positions.
134
+ */
135
+ export interface IUpdateMultiCellsParams {
136
+ /** The URL of the Google Spreadsheet */
137
+ sheetUrl: string;
138
+ /** The name of the specific sheet tab */
139
+ sheetName: string;
140
+ /** Array of cell updates with row, column, and content */
141
+ cells: ISheetValUpdateCell[];
142
+ /**
143
+ * Row offset for data rows.
144
+ * - 0: Header at row 1, data starts at row 2 (default)
145
+ * - 1: Header at row 1, skip row 2, data starts at row 3
146
+ */
147
+ rowOffset?: number;
148
+ }
149
+ /**
150
+ * Structure for column-value pair when updating multiple columns in a row.
151
+ */
152
+ export interface IColValuePair {
153
+ /** The content to write */
154
+ content: string;
155
+ /** Column index (0-based) */
156
+ col: number;
157
+ }
158
+ /**
159
+ * Parameters for updating multiple columns in a single row.
160
+ */
161
+ export interface IUpdateMultiColsByRowParams {
162
+ /** The URL of the Google Spreadsheet */
163
+ sheetUrl: string;
164
+ /** The name of the specific sheet tab */
165
+ sheetName: string;
166
+ /** The row index to update (0-based) */
167
+ row: number;
168
+ /** Array of column-value pairs to update */
169
+ values: IColValuePair[];
170
+ /** Row offset for data rows (default: 0) */
171
+ rowOffset?: number;
172
+ }
173
+ /**
174
+ * Structure for row-value pair when updating multiple rows in a column.
175
+ */
176
+ export interface IRowValuePair {
177
+ /** The content to write */
178
+ content: string;
179
+ /** Row index (0-based) */
180
+ row: number;
181
+ }
182
+ /**
183
+ * Parameters for updating multiple rows in a single column.
184
+ */
185
+ export interface IUpdateMultiRowsByColParams {
186
+ /** The URL of the Google Spreadsheet */
187
+ sheetUrl: string;
188
+ /** The name of the specific sheet tab */
189
+ sheetName: string;
190
+ /** The column index to update (0-based) */
191
+ col: number;
192
+ /** Array of row-value pairs to update */
193
+ values: IRowValuePair[];
194
+ /** Row offset for data rows (default: 0) */
195
+ rowOffset?: number;
196
+ }
197
+ /**
198
+ * Parameters for updating a range of rows and columns.
199
+ */
200
+ export interface IUpdateMultiRowsMultiColsParams {
201
+ /** The URL of the Google Spreadsheet */
202
+ sheetUrl: string;
203
+ /** The name of the specific sheet tab */
204
+ sheetName: string;
205
+ /** Matrix of values to write (rows x columns) */
206
+ values: string[][];
207
+ /** Starting row index (0-based, default: 0) */
208
+ startRow?: number;
209
+ /** Ending row index (0-based, optional) */
210
+ endRow?: number;
211
+ /** Starting column index (0-based, default: 0) */
212
+ startCol?: number;
213
+ /** Row offset for data rows (default: 0) */
214
+ rowOffset?: number;
215
+ }
216
+ /**
217
+ * Parameters for deleting a row from a sheet.
218
+ */
219
+ export interface IDeleteRowParams {
220
+ /** The URL of the Google Spreadsheet */
221
+ sheetUrl: string;
222
+ /** The name of the specific sheet tab */
223
+ sheetName: string;
224
+ /** The row index to delete (0-based) */
225
+ row: number;
226
+ /** Row offset for data rows (default: 0) */
227
+ rowOffset?: number;
228
+ }
229
+ /**
230
+ * Parameters for converting raw sheet values to typed objects.
231
+ */
232
+ export interface IConvertValueSheetParams<T> {
233
+ /** Raw values from the sheet (2D array) */
234
+ values: string[][] | null | undefined;
235
+ /**
236
+ * Row offset to skip before the header row.
237
+ * - 0: First row is the header (default)
238
+ * - 1: First row is skipped, second row is header
239
+ */
240
+ rowOffset?: number;
241
+ }
242
+ /**
243
+ * Result structure for column and value extraction.
244
+ */
245
+ export interface IListColsAndValsExport {
246
+ /** Array of column headers */
247
+ listCols: string[];
248
+ /** Matrix of data values */
249
+ valsExport: string[][];
250
+ }
@@ -0,0 +1,172 @@
1
+ /**
2
+ * Google Sheet Feature Library - Utility Functions
3
+ * @description Helper functions for sheet operations, column conversion, and data transformation.
4
+ * @module gg-sheet/utils
5
+ */
6
+ import { IListColsAndValsExport } from './types';
7
+ /**
8
+ * Extracts the spreadsheet ID from a Google Sheets URL.
9
+ *
10
+ * @param sheetUrl - The full URL of the Google Spreadsheet
11
+ * @returns The spreadsheet ID or null if not found
12
+ *
13
+ * @example
14
+ * ```typescript
15
+ * const id = getSheetIdFromUrl({
16
+ * sheetUrl: 'https://docs.google.com/spreadsheets/d/1abc123def/edit'
17
+ * });
18
+ * // Returns: '1abc123def'
19
+ * ```
20
+ */
21
+ export declare function getSheetIdFromUrl({ sheetUrl }: {
22
+ sheetUrl: string;
23
+ }): string | null;
24
+ /**
25
+ * Converts a 0-based column index to a column letter (e.g., 0 → A, 25 → Z, 26 → AA).
26
+ *
27
+ * @param columnIndex - The 0-based column index
28
+ * @returns The column letter(s) (e.g., "A", "B", "AA", "AB")
29
+ *
30
+ * @example
31
+ * ```typescript
32
+ * convertIndexToColumnName({ columnIndex: 0 }); // "A"
33
+ * convertIndexToColumnName({ columnIndex: 25 }); // "Z"
34
+ * convertIndexToColumnName({ columnIndex: 26 }); // "AA"
35
+ * convertIndexToColumnName({ columnIndex: 701 }); // "ZZ"
36
+ * ```
37
+ */
38
+ export declare function convertIndexToColumnName({ columnIndex }: {
39
+ columnIndex: number;
40
+ }): string;
41
+ /**
42
+ * Converts a column letter to a 0-based column index (e.g., A → 0, Z → 25, AA → 26).
43
+ *
44
+ * @param columnName - The column letter(s) (e.g., "A", "B", "AA")
45
+ * @returns The 0-based column index
46
+ * @throws Error if the column name contains invalid characters
47
+ *
48
+ * @example
49
+ * ```typescript
50
+ * convertColumnNameToIndex({ columnName: 'A' }); // 0
51
+ * convertColumnNameToIndex({ columnName: 'Z' }); // 25
52
+ * convertColumnNameToIndex({ columnName: 'AA' }); // 26
53
+ * convertColumnNameToIndex({ columnName: 'ZZ' }); // 701
54
+ * ```
55
+ */
56
+ export declare function convertColumnNameToIndex({ columnName }: {
57
+ columnName: string;
58
+ }): number;
59
+ /**
60
+ * Converts raw sheet values (2D array) into an array of typed objects.
61
+ * Uses the first row (or row at rowOffset) as keys for the objects.
62
+ *
63
+ * @param values - Raw 2D array from sheet
64
+ * @param rowOffset - Number of rows to skip before the header row (default: 0)
65
+ * @returns Array of typed objects, or null if values is null/undefined
66
+ *
67
+ * @example
68
+ * ```typescript
69
+ * const rawData = [
70
+ * ['name', 'age', 'email'],
71
+ * ['John', '30', 'john@example.com'],
72
+ * ['Jane', '25', 'jane@example.com']
73
+ * ];
74
+ *
75
+ * interface Person { name: string; age: string; email: string; }
76
+ *
77
+ * const people = convertValueSheet<Person>({ values: rawData });
78
+ * // Returns: [
79
+ * // { name: 'John', age: '30', email: 'john@example.com' },
80
+ * // { name: 'Jane', age: '25', email: 'jane@example.com' }
81
+ * // ]
82
+ * ```
83
+ */
84
+ export declare function convertValueSheet<T>({ values, rowOffset, }: {
85
+ values: string[][] | null | undefined;
86
+ rowOffset?: number;
87
+ }): T[] | null;
88
+ /**
89
+ * Gets the index of a column key in the list of keys.
90
+ *
91
+ * @param key - The key to find
92
+ * @param listKeys - Array of all keys
93
+ * @returns The index of the key, or -1 if not found
94
+ *
95
+ * @example
96
+ * ```typescript
97
+ * interface Person { id: string; name: string; email: string; }
98
+ * const keys: (keyof Person)[] = ['id', 'name', 'email'];
99
+ *
100
+ * getIndexCol({ key: 'name', listKeys: keys }); // 1
101
+ * getIndexCol({ key: 'email', listKeys: keys }); // 2
102
+ * ```
103
+ */
104
+ export declare function getIndexCol<T>({ key, listKeys }: {
105
+ key: keyof T;
106
+ listKeys: (keyof T)[];
107
+ }): number;
108
+ /**
109
+ * Extracts column headers and data values from a result set for export.
110
+ * Takes an object mapping field keys to column names and an array of items.
111
+ *
112
+ * @param colsForSheet - Object mapping field keys to column header names
113
+ * @param resultItems - Array of items to export
114
+ * @returns Object containing listCols (headers) and valsExport (data matrix)
115
+ *
116
+ * @example
117
+ * ```typescript
118
+ * const colsMapping = { id: 'ID', name: 'Full Name', email: 'Email Address' };
119
+ * const items = [
120
+ * { id: '1', name: 'John Doe', email: 'john@example.com' },
121
+ * { id: '2', name: 'Jane Doe', email: 'jane@example.com' }
122
+ * ];
123
+ *
124
+ * const { listCols, valsExport } = getListColsAndValsExport({
125
+ * colsForSheet: colsMapping,
126
+ * resultItems: items
127
+ * });
128
+ * // listCols: ['ID', 'Full Name', 'Email Address']
129
+ * // valsExport: [['1', 'John Doe', 'john@example.com'], ['2', 'Jane Doe', 'jane@example.com']]
130
+ * ```
131
+ */
132
+ export declare function getListColsAndValsExport<T extends Record<string, unknown>>({ colsForSheet, resultItems, }: {
133
+ colsForSheet: Record<keyof T, string>;
134
+ resultItems: T[];
135
+ }): IListColsAndValsExport;
136
+ /**
137
+ * Validates that a sheet URL is in the correct format.
138
+ *
139
+ * @param sheetUrl - The URL to validate
140
+ * @returns True if the URL is valid, false otherwise
141
+ *
142
+ * @example
143
+ * ```typescript
144
+ * isValidSheetUrl({ sheetUrl: 'https://docs.google.com/spreadsheets/d/1abc123/edit' }); // true
145
+ * isValidSheetUrl({ sheetUrl: 'https://example.com/sheet' }); // false
146
+ * ```
147
+ */
148
+ export declare function isValidSheetUrl({ sheetUrl }: {
149
+ sheetUrl: string;
150
+ }): boolean;
151
+ /**
152
+ * Calculates the actual row index in the sheet based on the data row index and offset.
153
+ * This accounts for header row(s) and any additional offset rows.
154
+ *
155
+ * @param dataRowIndex - The 0-based index in the data (not counting headers)
156
+ * @param rowOffset - Additional rows to skip after the header (default: 0)
157
+ * @returns The 1-based row number in the actual sheet
158
+ *
159
+ * @example
160
+ * ```typescript
161
+ * // With rowOffset=0: header at row 1, data starts at row 2
162
+ * calculateActualRow({ dataRowIndex: 0, rowOffset: 0 }); // 2 (first data row)
163
+ * calculateActualRow({ dataRowIndex: 5, rowOffset: 0 }); // 7 (sixth data row)
164
+ *
165
+ * // With rowOffset=1: header at row 1, skip row 2, data starts at row 3
166
+ * calculateActualRow({ dataRowIndex: 0, rowOffset: 1 }); // 3 (first data row)
167
+ * ```
168
+ */
169
+ export declare function calculateActualRow({ dataRowIndex, rowOffset, }: {
170
+ dataRowIndex: number;
171
+ rowOffset?: number;
172
+ }): number;
@@ -1 +1,22 @@
1
+ /**
2
+ * BoDevOps Features Library
3
+ * @description A collection of framework-agnostic utilities for Google Drive, Google Sheets, and iDrive e2.
4
+ * @module bodevops-features
5
+ *
6
+ * @example
7
+ * ```typescript
8
+ * import { GGDrive, GGSheet } from 'bodevops-features';
9
+ *
10
+ * // Google Drive operations
11
+ * const driveClient = new GGDrive.GoogleDriveClient({
12
+ * keyFilePath: './service-account.json'
13
+ * });
14
+ *
15
+ * // Google Sheet operations
16
+ * const sheetClient = new GGSheet.GoogleSheetClient({
17
+ * keyFilePath: './service-account.json'
18
+ * });
19
+ * ```
20
+ */
1
21
  export * as GGDrive from './gg-drive';
22
+ export * as GGSheet from './gg-sheet';
package/package.json CHANGED
@@ -1,44 +1,50 @@
1
- {
2
- "name": "bodevops-features",
3
- "version": "1.0.0",
4
- "description": "BoDevOps features library - utilities for Google Drive, Google Sheets, and iDrive e2",
5
- "main": "dist/cjs/index.js",
6
- "module": "dist/esm/index.js",
7
- "types": "dist/types/index.d.ts",
8
- "repository": {
9
- "type": "git",
10
- "url": "https://github.com/HaiSonMin"
11
- },
12
- "exports": {
13
- ".": {
14
- "require": "./dist/cjs/index.js",
15
- "import": "./dist/esm/index.js",
16
- "types": "./dist/types/index.d.ts"
17
- }
18
- },
19
- "files": [
20
- "dist"
21
- ],
22
- "scripts": {
23
- "build": "rollup -c && tsc --emitDeclarationOnly --outDir dist/types",
24
- "prepublishOnly": "npm run build"
25
- },
26
- "publishConfig": {
27
- "access": "public"
28
- },
29
- "keywords": [
30
- "gg-drive",
31
- "gg-sheet",
32
- "idrive-e2"
33
- ],
34
- "author": "BoDevOps",
35
- "license": "MIT",
36
- "devDependencies": {
37
- "@rollup/plugin-commonjs": "^25.0.7",
38
- "@rollup/plugin-node-resolve": "^15.2.3",
39
- "@rollup/plugin-typescript": "^11.1.6",
40
- "rollup": "^4.9.6",
41
- "tslib": "^2.6.2",
42
- "typescript": "^5.3.3"
43
- }
44
- }
1
+ {
2
+ "name": "bodevops-features",
3
+ "version": "1.0.8",
4
+ "description": "BoDevOps features library - utilities for Google Drive, Google Sheets, and iDrive e2",
5
+ "main": "dist/cjs/index.js",
6
+ "module": "dist/esm/index.js",
7
+ "types": "dist/types/index.d.ts",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "https://github.com/HaiSonMin"
11
+ },
12
+ "exports": {
13
+ ".": {
14
+ "require": "./dist/cjs/index.js",
15
+ "import": "./dist/esm/index.js",
16
+ "types": "./dist/types/index.d.ts"
17
+ }
18
+ },
19
+ "files": [
20
+ "dist"
21
+ ],
22
+ "scripts": {
23
+ "build": "rollup -c && tsc --emitDeclarationOnly --outDir dist/types",
24
+ "pub": "npm run build && npm publish",
25
+ "check": "tsc --noEmit",
26
+ "check:watch": "tsc --noEmit --watch"
27
+ },
28
+ "publishConfig": {
29
+ "access": "public"
30
+ },
31
+ "keywords": [
32
+ "gg-drive",
33
+ "gg-sheet",
34
+ "idrive-e2"
35
+ ],
36
+ "author": "BoDevOps",
37
+ "license": "MIT",
38
+ "dependencies": {
39
+ "googleapis": "^130.0.0"
40
+ },
41
+ "devDependencies": {
42
+ "@types/node": "^20.10.0",
43
+ "@rollup/plugin-commonjs": "^25.0.7",
44
+ "@rollup/plugin-node-resolve": "^15.2.3",
45
+ "@rollup/plugin-typescript": "^11.1.6",
46
+ "rollup": "^4.9.6",
47
+ "tslib": "^2.6.2",
48
+ "typescript": "^5.3.3"
49
+ }
50
+ }