google-sheets-automation 0.1.2 → 1.0.0
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 +44 -5
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
|
|
2
|
+
|
|
2
3
|
<div align="center">
|
|
3
|
-
<img src="
|
|
4
|
+
<img src="docs/sheets-logo.png" width="64" alt="Google Sheets Logo" />
|
|
4
5
|
<h1>google-sheets-automation</h1>
|
|
5
6
|
<p>Automate Google Sheets from Node.js: add, update, and read rows with a simple API.</p>
|
|
6
7
|
</div>
|
|
7
8
|
|
|
9
|
+
<p align="center" style="font-size:smaller;">
|
|
10
|
+
<em>Google Sheets and the Google Sheets logo are trademarks of Google LLC. This project is not affiliated with or endorsed by Google.</em>
|
|
11
|
+
</p>
|
|
12
|
+
|
|
8
13
|
---
|
|
9
14
|
|
|
10
15
|
## Overview
|
|
@@ -31,10 +36,8 @@ npm install google-sheets-automation
|
|
|
31
36
|
import { GoogleSheetProvider } from 'google-sheets-automation';
|
|
32
37
|
|
|
33
38
|
const provider = new GoogleSheetProvider({
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
private_key: '-----BEGIN PRIVATE KEY-----\n...\n-----END PRIVATE KEY-----\n',
|
|
37
|
-
},
|
|
39
|
+
client_email: 'your-service-account-email@project.iam.gserviceaccount.com',
|
|
40
|
+
private_key: '-----BEGIN PRIVATE KEY-----\n...\n-----END PRIVATE KEY-----\n',
|
|
38
41
|
sheetId: 'your-google-sheet-id',
|
|
39
42
|
});
|
|
40
43
|
|
|
@@ -52,6 +55,42 @@ const rows = [
|
|
|
52
55
|
await provider.addRows({ spreadsheetId: 'your-google-sheet-id', sheetName: 'Sheet1', headerMap }, rows);
|
|
53
56
|
```
|
|
54
57
|
|
|
58
|
+
# React/NextJS Serverside form example
|
|
59
|
+
|
|
60
|
+
```js
|
|
61
|
+
import type { NextApiRequest, NextApiResponse } from 'next';
|
|
62
|
+
import { GoogleSheetProvider } from 'google-sheets-automation';
|
|
63
|
+
|
|
64
|
+
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
|
|
65
|
+
if (req.method !== 'POST') return res.status(405).end();
|
|
66
|
+
|
|
67
|
+
const { name, email, message } = req.body;
|
|
68
|
+
if (!name || !email || !message) {
|
|
69
|
+
return res.status(400).json({ error: 'Missing required fields' });
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const credentials = {
|
|
73
|
+
private_key: process.env.GOOGLE_PRIVATE_KEY?.replace(/\\n/g, '\n'),
|
|
74
|
+
client_email: process.env.GOOGLE_CLIENT_EMAIL,
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
const client = new GoogleSheetProvider(credentials);
|
|
78
|
+
|
|
79
|
+
const options = {
|
|
80
|
+
spreadsheetId: process.env.GOOGLE_SHEET_ID,
|
|
81
|
+
sheetName: 'Sheet1',
|
|
82
|
+
headerMap: { name: 'Name', email: 'Email', message: 'Message' }
|
|
83
|
+
};
|
|
84
|
+
const rows = [{ name, email, message }];
|
|
85
|
+
|
|
86
|
+
try {
|
|
87
|
+
await client.addRows(options, rows);
|
|
88
|
+
res.status(200).json({ success: true });
|
|
89
|
+
} catch (err: any) {
|
|
90
|
+
res.status(500).json({ error: err.message });
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
```
|
|
55
94
|
## Environment Setup
|
|
56
95
|
|
|
57
96
|
1. **Create a Google Cloud project** and enable the Google Sheets API.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "google-sheets-automation",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"description": "Automate Google Sheets from Node.js: add, update, and read rows with simple API. Supports service accounts, header mapping, and batch operations.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -34,17 +34,17 @@
|
|
|
34
34
|
"url": "https://github.com/CaesarSage"
|
|
35
35
|
},
|
|
36
36
|
"license": "MIT",
|
|
37
|
-
"homepage": "https://github.com/
|
|
37
|
+
"homepage": "https://github.com/Caesarsage/googlesheet-automation#readme",
|
|
38
38
|
"bugs": {
|
|
39
|
-
"url": "https://github.com/
|
|
39
|
+
"url": "https://github.com/Caesarsage/googlesheet-automation/issues"
|
|
40
40
|
},
|
|
41
41
|
"funding": {
|
|
42
42
|
"type": "github",
|
|
43
|
-
"url": "https://github.com/sponsors/
|
|
43
|
+
"url": "https://github.com/sponsors/Caesarsage"
|
|
44
44
|
},
|
|
45
45
|
"repository": {
|
|
46
46
|
"type": "git",
|
|
47
|
-
"url": "git+https://github.com/
|
|
47
|
+
"url": "git+https://github.com/Caesarsage/googlesheet-automation.git"
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
50
|
"@types/jest": "^30.0.0",
|