@riocrypto/common-server 1.0.1006 → 1.0.1007
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.
|
@@ -3,8 +3,8 @@ declare class GoogleSheetsAPIClient {
|
|
|
3
3
|
private env;
|
|
4
4
|
googleAuth: any;
|
|
5
5
|
constructor(env: RioEnv);
|
|
6
|
-
getSheetValues(sheetId: string, range: string): Promise<any[][] | null | undefined>;
|
|
7
6
|
getNextAvailableRow(sheetId: string): Promise<number>;
|
|
7
|
+
getSheetValues(sheetId: string, rowData: string[]): Promise<void>;
|
|
8
8
|
}
|
|
9
9
|
export declare const googleSheetsAPIClient: GoogleSheetsAPIClient;
|
|
10
10
|
export {};
|
|
@@ -19,33 +19,28 @@ class GoogleSheetsAPIClient {
|
|
|
19
19
|
scopes: ["https://www.googleapis.com/auth/spreadsheets"],
|
|
20
20
|
});
|
|
21
21
|
}
|
|
22
|
-
getSheetValues(sheetId, range) {
|
|
23
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
24
|
-
const authClientObject = yield this.googleAuth.getClient();
|
|
25
|
-
const sheets = googleapis_1.google.sheets({ version: "v4", auth: authClientObject });
|
|
26
|
-
const response = yield sheets.spreadsheets.values.get({
|
|
27
|
-
spreadsheetId: sheetId,
|
|
28
|
-
range,
|
|
29
|
-
});
|
|
30
|
-
return response.data.values;
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
22
|
getNextAvailableRow(sheetId) {
|
|
34
23
|
return __awaiter(this, void 0, void 0, function* () {
|
|
35
24
|
const authClientObject = yield this.googleAuth.getClient();
|
|
36
25
|
const sheets = googleapis_1.google.sheets({ version: "v4", auth: authClientObject });
|
|
37
26
|
const response = yield sheets.spreadsheets.values.get({
|
|
38
27
|
spreadsheetId: sheetId,
|
|
39
|
-
range: "A:
|
|
28
|
+
range: "A:Z", // Adjust the range based on the columns you want to check (e.g., A:Z for columns A to Z)
|
|
40
29
|
});
|
|
41
30
|
const data = response.data.values;
|
|
42
31
|
if (!data || data.length === 0) {
|
|
43
32
|
// If the sheet is completely empty, return the first row (1)
|
|
44
33
|
return 1;
|
|
45
34
|
}
|
|
46
|
-
// Find the first empty
|
|
35
|
+
// Find the first row with empty cells after column A
|
|
47
36
|
for (let i = 0; i < data.length; i++) {
|
|
48
|
-
|
|
37
|
+
const row = data[i];
|
|
38
|
+
if (row.length > 1) {
|
|
39
|
+
// If any cell after column A has a value, move to the next row
|
|
40
|
+
continue;
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
// If all cells after column A are empty, return the row number
|
|
49
44
|
return i + 1;
|
|
50
45
|
}
|
|
51
46
|
}
|
|
@@ -53,5 +48,24 @@ class GoogleSheetsAPIClient {
|
|
|
53
48
|
return data.length + 1;
|
|
54
49
|
});
|
|
55
50
|
}
|
|
51
|
+
getSheetValues(sheetId, rowData) {
|
|
52
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
53
|
+
const authClientObject = yield this.googleAuth.getClient();
|
|
54
|
+
const sheets = googleapis_1.google.sheets({ version: "v4", auth: authClientObject });
|
|
55
|
+
const nextAvailableRow = yield this.getNextAvailableRow(sheetId);
|
|
56
|
+
if (nextAvailableRow === -1) {
|
|
57
|
+
throw new Error("Failed to find the next available row.");
|
|
58
|
+
}
|
|
59
|
+
const range = `A${nextAvailableRow}`;
|
|
60
|
+
yield sheets.spreadsheets.values.append({
|
|
61
|
+
spreadsheetId: sheetId,
|
|
62
|
+
range,
|
|
63
|
+
valueInputOption: "USER_ENTERED",
|
|
64
|
+
requestBody: {
|
|
65
|
+
values: [rowData],
|
|
66
|
+
},
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
}
|
|
56
70
|
}
|
|
57
71
|
exports.googleSheetsAPIClient = new GoogleSheetsAPIClient(process.env.RIO_ENV || process.env.NEXT_PUBLIC_RIO_ENV);
|