@openfn/language-googlesheets 5.0.0 → 5.1.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 +47 -0
- package/configuration-schema.json +16 -2
- package/dist/index.cjs +28 -5
- package/dist/index.js +28 -5
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -12,6 +12,53 @@ official
|
|
|
12
12
|
[configuration-schema](https://docs.openfn.org/adaptors/packages/googlesheets-configuration-schema/)
|
|
13
13
|
definition.
|
|
14
14
|
|
|
15
|
+
This adaptor supports two authentication methods: **OAuth2** and **Service Account**.
|
|
16
|
+
|
|
17
|
+
#### OAuth2
|
|
18
|
+
|
|
19
|
+
**On app.openfn.org:** Click **Sign in with Google Sheets** in the credential setup form. Authentication is handled for you and no manual token management is needed.
|
|
20
|
+
|
|
21
|
+
**Using the OpenFn CLI locally:** Use the [gcloud CLI](https://cloud.google.com/sdk/docs/install) to print a temporary access token and provide it in your configuration:
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
gcloud auth print-access-token
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
```json
|
|
28
|
+
{
|
|
29
|
+
"configuration": {
|
|
30
|
+
"access_token": "ya29.A0..."
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
#### Service Account
|
|
36
|
+
|
|
37
|
+
Service accounts are ideal for server-to-server integrations that run without
|
|
38
|
+
user interaction. Use a service account when you need reliable, long-running
|
|
39
|
+
access without managing OAuth2 token refresh.
|
|
40
|
+
|
|
41
|
+
To create a service account and obtain a JSON key file, follow the
|
|
42
|
+
[Google Cloud service account documentation](https://cloud.google.com/iam/docs/service-accounts-create).
|
|
43
|
+
Your OpenFn credential requires the `client_email` and `private_key` fields
|
|
44
|
+
from the downloaded JSON key file.
|
|
45
|
+
|
|
46
|
+
**Share the spreadsheet with the service account**
|
|
47
|
+
|
|
48
|
+
A service account does not have access to any spreadsheet by default. You must
|
|
49
|
+
share each spreadsheet the adaptor needs to access, just like you would share
|
|
50
|
+
with any other Google user.
|
|
51
|
+
|
|
52
|
+
1. Open the spreadsheet in Google Sheets.
|
|
53
|
+
2. Click **Share** (top-right corner).
|
|
54
|
+
3. Enter the service account's `client_email` address.
|
|
55
|
+
4. Grant at least **Editor** access (or **Viewer** if read-only is sufficient).
|
|
56
|
+
5. Click **Send**.
|
|
57
|
+
|
|
58
|
+
> **Note:** The service account email looks like
|
|
59
|
+
> `name@project-id.iam.gserviceaccount.com`. If you see a "This person may not
|
|
60
|
+
> be a Google user" warning, you can safely ignore it and proceed.
|
|
61
|
+
|
|
15
62
|
### appendValues()
|
|
16
63
|
|
|
17
64
|
Add rows to an existing sheet:
|
|
@@ -11,9 +11,23 @@
|
|
|
11
11
|
"examples": [
|
|
12
12
|
"eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsIng1dCI6IjlGWERwYmZNRlQyU3ZRdVhoODQ2WVR3RUlCdyIsI"
|
|
13
13
|
]
|
|
14
|
+
},
|
|
15
|
+
"private_key": {
|
|
16
|
+
"title": "Private Key",
|
|
17
|
+
"type": "string",
|
|
18
|
+
"description": "RSA private key from the Google service account JSON key file. Required for service accounts",
|
|
19
|
+
"writeOnly": true,
|
|
20
|
+
"minLength": 1,
|
|
21
|
+
"examples": ["-----BEGIN RSA PRIVATE KEY-----\nMIIEow..."]
|
|
22
|
+
},
|
|
23
|
+
"client_email": {
|
|
24
|
+
"title": "Client Email",
|
|
25
|
+
"type": "string",
|
|
26
|
+
"description": "Service account email address (e.g. my-app@project-id.iam.gserviceaccount.com). Required for service accounts",
|
|
27
|
+
"minLength": 1,
|
|
28
|
+
"examples": ["my-app@project-id.iam.gserviceaccount.com"]
|
|
14
29
|
}
|
|
15
30
|
},
|
|
16
31
|
"type": "object",
|
|
17
|
-
"additionalProperties": true
|
|
18
|
-
"required": ["access_token"]
|
|
32
|
+
"additionalProperties": true
|
|
19
33
|
}
|
package/dist/index.cjs
CHANGED
|
@@ -68,10 +68,31 @@ var import_util = require("@openfn/language-common/util");
|
|
|
68
68
|
var import_googleapis = require("googleapis");
|
|
69
69
|
var import_language_common2 = require("@openfn/language-common");
|
|
70
70
|
var client = void 0;
|
|
71
|
-
function createConnection(state) {
|
|
72
|
-
const {
|
|
73
|
-
|
|
74
|
-
|
|
71
|
+
async function createConnection(state) {
|
|
72
|
+
const {
|
|
73
|
+
accessToken,
|
|
74
|
+
private_key,
|
|
75
|
+
client_email,
|
|
76
|
+
scopes = []
|
|
77
|
+
} = state.configuration;
|
|
78
|
+
const mandatoryScopes = [
|
|
79
|
+
"https://www.googleapis.com/auth/spreadsheets",
|
|
80
|
+
"https://www.googleapis.com/auth/userinfo.email",
|
|
81
|
+
"https://www.googleapis.com/auth/userinfo.profile",
|
|
82
|
+
"openid"
|
|
83
|
+
];
|
|
84
|
+
let auth;
|
|
85
|
+
if (private_key && client_email) {
|
|
86
|
+
auth = new import_googleapis.google.auth.JWT({
|
|
87
|
+
email: client_email,
|
|
88
|
+
key: private_key,
|
|
89
|
+
scopes: [...mandatoryScopes, ...scopes]
|
|
90
|
+
});
|
|
91
|
+
await auth.authorize();
|
|
92
|
+
} else {
|
|
93
|
+
auth = new import_googleapis.google.auth.OAuth2();
|
|
94
|
+
auth.credentials = { access_token: accessToken };
|
|
95
|
+
}
|
|
75
96
|
client = import_googleapis.google.sheets({ version: "v4", auth });
|
|
76
97
|
return state;
|
|
77
98
|
}
|
|
@@ -96,6 +117,8 @@ function execute(...operations) {
|
|
|
96
117
|
data: null
|
|
97
118
|
};
|
|
98
119
|
return (state) => {
|
|
120
|
+
var _a, _b;
|
|
121
|
+
const isServiceAccount = ((_a = state.configuration) == null ? void 0 : _a.private_key) && ((_b = state.configuration) == null ? void 0 : _b.client_email);
|
|
99
122
|
return (0, import_language_common.execute)(
|
|
100
123
|
createConnection,
|
|
101
124
|
...operations,
|
|
@@ -103,7 +126,7 @@ function execute(...operations) {
|
|
|
103
126
|
)({
|
|
104
127
|
...initialState,
|
|
105
128
|
...state,
|
|
106
|
-
configuration: (0, import_util.normalizeOauthConfig)(state.configuration)
|
|
129
|
+
configuration: isServiceAccount ? state.configuration : (0, import_util.normalizeOauthConfig)(state.configuration)
|
|
107
130
|
});
|
|
108
131
|
};
|
|
109
132
|
}
|
package/dist/index.js
CHANGED
|
@@ -52,10 +52,31 @@ import {
|
|
|
52
52
|
sourceValue
|
|
53
53
|
} from "@openfn/language-common";
|
|
54
54
|
var client = void 0;
|
|
55
|
-
function createConnection(state) {
|
|
56
|
-
const {
|
|
57
|
-
|
|
58
|
-
|
|
55
|
+
async function createConnection(state) {
|
|
56
|
+
const {
|
|
57
|
+
accessToken,
|
|
58
|
+
private_key,
|
|
59
|
+
client_email,
|
|
60
|
+
scopes = []
|
|
61
|
+
} = state.configuration;
|
|
62
|
+
const mandatoryScopes = [
|
|
63
|
+
"https://www.googleapis.com/auth/spreadsheets",
|
|
64
|
+
"https://www.googleapis.com/auth/userinfo.email",
|
|
65
|
+
"https://www.googleapis.com/auth/userinfo.profile",
|
|
66
|
+
"openid"
|
|
67
|
+
];
|
|
68
|
+
let auth;
|
|
69
|
+
if (private_key && client_email) {
|
|
70
|
+
auth = new google.auth.JWT({
|
|
71
|
+
email: client_email,
|
|
72
|
+
key: private_key,
|
|
73
|
+
scopes: [...mandatoryScopes, ...scopes]
|
|
74
|
+
});
|
|
75
|
+
await auth.authorize();
|
|
76
|
+
} else {
|
|
77
|
+
auth = new google.auth.OAuth2();
|
|
78
|
+
auth.credentials = { access_token: accessToken };
|
|
79
|
+
}
|
|
59
80
|
client = google.sheets({ version: "v4", auth });
|
|
60
81
|
return state;
|
|
61
82
|
}
|
|
@@ -80,6 +101,8 @@ function execute(...operations) {
|
|
|
80
101
|
data: null
|
|
81
102
|
};
|
|
82
103
|
return (state) => {
|
|
104
|
+
var _a, _b;
|
|
105
|
+
const isServiceAccount = ((_a = state.configuration) == null ? void 0 : _a.private_key) && ((_b = state.configuration) == null ? void 0 : _b.client_email);
|
|
83
106
|
return commonExecute(
|
|
84
107
|
createConnection,
|
|
85
108
|
...operations,
|
|
@@ -87,7 +110,7 @@ function execute(...operations) {
|
|
|
87
110
|
)({
|
|
88
111
|
...initialState,
|
|
89
112
|
...state,
|
|
90
|
-
configuration: normalizeOauthConfig(state.configuration)
|
|
113
|
+
configuration: isServiceAccount ? state.configuration : normalizeOauthConfig(state.configuration)
|
|
91
114
|
});
|
|
92
115
|
};
|
|
93
116
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openfn/language-googlesheets",
|
|
3
3
|
"label": "Google Sheets",
|
|
4
|
-
"version": "5.
|
|
4
|
+
"version": "5.1.0",
|
|
5
5
|
"description": "A Google Sheets Language Pack for OpenFn",
|
|
6
6
|
"homepage": "https://docs.openfn.org",
|
|
7
7
|
"repository": {
|
|
@@ -32,6 +32,7 @@
|
|
|
32
32
|
"assertion-error": "1.1.0",
|
|
33
33
|
"chai": "4.3.6",
|
|
34
34
|
"deep-eql": "4.1.1",
|
|
35
|
+
"mocha": "^10.7.3",
|
|
35
36
|
"nock": "13.2.9",
|
|
36
37
|
"rimraf": "3.0.2",
|
|
37
38
|
"sinon": "^21.1.2"
|