@open-neko/connector-google-workspace 0.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/LICENSE +202 -0
- package/README.md +89 -0
- package/dist/google-client.d.ts +96 -0
- package/dist/google-client.d.ts.map +1 -0
- package/dist/google-client.js +155 -0
- package/dist/google-client.js.map +1 -0
- package/dist/plugin.d.ts +51 -0
- package/dist/plugin.d.ts.map +1 -0
- package/dist/plugin.js +248 -0
- package/dist/plugin.js.map +1 -0
- package/dist/run.d.ts +2 -0
- package/dist/run.d.ts.map +1 -0
- package/dist/run.js +15372 -0
- package/dist/run.js.map +1 -0
- package/package.json +111 -0
- package/skill/SKILL.md +96 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for describing the origin of the Work and
|
|
141
|
+
reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Support. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or support.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of the work is included on the
|
|
186
|
+
same line as the file name.
|
|
187
|
+
|
|
188
|
+
Copyright 2026 Amit Deshmukh
|
|
189
|
+
|
|
190
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
191
|
+
you may not use this file except in compliance with the License.
|
|
192
|
+
You may obtain a copy of the License at
|
|
193
|
+
|
|
194
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
195
|
+
|
|
196
|
+
Unless required by applicable law or agreed to in writing, software
|
|
197
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
198
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
199
|
+
implied, including, without limitation, any warranties or conditions
|
|
200
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
201
|
+
PARTICULAR PURPOSE. See the License for the specific language governing
|
|
202
|
+
permissions and limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
# @open-neko/connector-google-workspace
|
|
2
|
+
|
|
3
|
+
Per-operator Google Workspace connector for OpenNeko. Each operator on
|
|
4
|
+
your deployment authorizes their own Google account via PKCE OAuth2;
|
|
5
|
+
OpenNeko persists their refresh token in the per-operator section of
|
|
6
|
+
the secrets file, rotates the access token on demand, and exposes
|
|
7
|
+
Gmail / Calendar / Sheets actions back into the agent.
|
|
8
|
+
|
|
9
|
+
## Setup
|
|
10
|
+
|
|
11
|
+
1. **Create an OAuth client in Google Cloud Console** at
|
|
12
|
+
<https://console.cloud.google.com/apis/credentials> → **+ Create
|
|
13
|
+
credentials** → **OAuth client ID** → **Web application**.
|
|
14
|
+
|
|
15
|
+
2. Set the **Authorized redirect URI** to your deployment's callback:
|
|
16
|
+
|
|
17
|
+
```
|
|
18
|
+
https://<your-deployment>/api/integrations/connect/%40open-neko%2Fconnector-google-workspace/callback
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
(The `%40` / `%2F` come from URL-encoding the npm scoped name.)
|
|
22
|
+
|
|
23
|
+
3. Enable the APIs you intend to use: Gmail API, Google Calendar API,
|
|
24
|
+
Google Sheets API, Google Docs API.
|
|
25
|
+
|
|
26
|
+
4. Install the connector:
|
|
27
|
+
|
|
28
|
+
```sh
|
|
29
|
+
openneko install @open-neko/connector-google-workspace
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
The CLI will prompt for `GOOGLE_CLIENT_ID` and
|
|
33
|
+
`GOOGLE_CLIENT_SECRET` — paste them from the Cloud Console.
|
|
34
|
+
|
|
35
|
+
5. Each operator on the deployment then visits **Settings →
|
|
36
|
+
Integrations** in the OpenNeko web app and clicks **Connect Google
|
|
37
|
+
Workspace** on their own. The OAuth dance happens in their browser;
|
|
38
|
+
OpenNeko persists their tokens privately.
|
|
39
|
+
|
|
40
|
+
## Actions
|
|
41
|
+
|
|
42
|
+
| Action | Default mode | Notes |
|
|
43
|
+
|---|---|---|
|
|
44
|
+
| `send_gmail` | `ask` | Sends as the connected operator. `to`, `subject`, `body`, optional `cc`. |
|
|
45
|
+
| `list_calendar_events` | `auto` | Returns up to `maxResults` upcoming events on the primary calendar. |
|
|
46
|
+
| `append_sheet_row` | `ask` | Append one row to a Sheet the operator can edit. `spreadsheetId`, `range`, `values[]`. |
|
|
47
|
+
|
|
48
|
+
## Token lifecycle
|
|
49
|
+
|
|
50
|
+
- **Access tokens** expire after ~1 hour. The connector's
|
|
51
|
+
`refresh_connect` handler exchanges the refresh token for a fresh
|
|
52
|
+
pair on demand.
|
|
53
|
+
- **Refresh tokens** are long-lived but can be revoked by the operator
|
|
54
|
+
at any time via <https://myaccount.google.com/permissions>. A revoked
|
|
55
|
+
refresh token surfaces as `invalid_grant` on the next action call —
|
|
56
|
+
the operator must reconnect via /integrations.
|
|
57
|
+
- Tokens never leave the worker's microsandbox VM except via the
|
|
58
|
+
worker-mediated writeback path. The plugin does not persist anything
|
|
59
|
+
to disk.
|
|
60
|
+
|
|
61
|
+
## Scopes
|
|
62
|
+
|
|
63
|
+
Default scope set (declared in the manifest):
|
|
64
|
+
|
|
65
|
+
- `openid`, `userinfo.email` — basic identity
|
|
66
|
+
- `gmail.send` — send email as the operator
|
|
67
|
+
- `calendar.events.readonly` — read upcoming events
|
|
68
|
+
- `spreadsheets` — read + write Sheets
|
|
69
|
+
- `documents` — read + write Docs (no action handler ships yet)
|
|
70
|
+
|
|
71
|
+
Operators can opt into a narrower subset on the OAuth consent screen;
|
|
72
|
+
actions whose scope wasn't granted will return
|
|
73
|
+
`insufficient_authentication_scopes` at call time.
|
|
74
|
+
|
|
75
|
+
## Sandbox
|
|
76
|
+
|
|
77
|
+
Network egress is limited to:
|
|
78
|
+
|
|
79
|
+
- `accounts.google.com` (OAuth consent screen)
|
|
80
|
+
- `oauth2.googleapis.com` (token exchange + refresh)
|
|
81
|
+
- `gmail.googleapis.com`, `www.googleapis.com`, `sheets.googleapis.com`,
|
|
82
|
+
`docs.googleapis.com` (action APIs)
|
|
83
|
+
|
|
84
|
+
The microsandbox VM enforces this at the network boundary; the plugin
|
|
85
|
+
cannot reach any other host even if instructed.
|
|
86
|
+
|
|
87
|
+
## License
|
|
88
|
+
|
|
89
|
+
Apache-2.0.
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Thin HTTP client for Google's OAuth + Workspace APIs. All network
|
|
3
|
+
* calls go through `fetchImpl` so tests can inject a fake without
|
|
4
|
+
* touching real Google endpoints.
|
|
5
|
+
*/
|
|
6
|
+
export interface GoogleClientConfig {
|
|
7
|
+
clientId: string;
|
|
8
|
+
clientSecret: string;
|
|
9
|
+
fetchImpl?: typeof fetch;
|
|
10
|
+
}
|
|
11
|
+
export interface GoogleTokens {
|
|
12
|
+
/** Bearer token for API calls. */
|
|
13
|
+
access_token: string;
|
|
14
|
+
/** Long-lived rotation token. Absent when Google didn't return one
|
|
15
|
+
* (e.g. follow-up consent without offline access). Treat as optional
|
|
16
|
+
* in callers; the absence of a refresh token means the credential
|
|
17
|
+
* will eventually expire and the operator has to reconnect. */
|
|
18
|
+
refresh_token?: string;
|
|
19
|
+
/** Seconds until access_token expires. */
|
|
20
|
+
expires_in?: number;
|
|
21
|
+
/** OAuth scopes ultimately granted (may be narrower than requested). */
|
|
22
|
+
scope?: string;
|
|
23
|
+
/** Always "Bearer" for Google. */
|
|
24
|
+
token_type?: string;
|
|
25
|
+
/** OIDC ID token when scope includes openid. */
|
|
26
|
+
id_token?: string;
|
|
27
|
+
}
|
|
28
|
+
export declare class GoogleClient {
|
|
29
|
+
private readonly cfg;
|
|
30
|
+
private readonly fetchImpl;
|
|
31
|
+
constructor(cfg: GoogleClientConfig);
|
|
32
|
+
/**
|
|
33
|
+
* Build the full authorization URL the operator's browser should
|
|
34
|
+
* follow. The plugin returns this string from runBeginConnect; the
|
|
35
|
+
* web app redirects the operator to it.
|
|
36
|
+
*
|
|
37
|
+
* PKCE: the worker mints the code_verifier and passes it through.
|
|
38
|
+
* The plugin computes the S256 challenge and includes it on the URL.
|
|
39
|
+
* The matching code_verifier comes back through runCompleteConnect
|
|
40
|
+
* for the token exchange.
|
|
41
|
+
*/
|
|
42
|
+
buildAuthorizationUrl(params: {
|
|
43
|
+
redirectUri: string;
|
|
44
|
+
state: string;
|
|
45
|
+
scopes: string[];
|
|
46
|
+
codeChallenge: string;
|
|
47
|
+
/** Email hint to pre-select an account. */
|
|
48
|
+
loginHint?: string | null;
|
|
49
|
+
}): string;
|
|
50
|
+
/** Exchange an authorization code for a token set. */
|
|
51
|
+
exchangeCode(params: {
|
|
52
|
+
code: string;
|
|
53
|
+
redirectUri: string;
|
|
54
|
+
codeVerifier: string;
|
|
55
|
+
}): Promise<GoogleTokens>;
|
|
56
|
+
/** Rotate the access token using a stored refresh token. */
|
|
57
|
+
refreshTokens(refreshToken: string): Promise<GoogleTokens>;
|
|
58
|
+
sendGmail(accessToken: string, message: {
|
|
59
|
+
to: string;
|
|
60
|
+
subject: string;
|
|
61
|
+
body: string;
|
|
62
|
+
cc?: string;
|
|
63
|
+
}): Promise<{
|
|
64
|
+
id: string;
|
|
65
|
+
threadId: string;
|
|
66
|
+
}>;
|
|
67
|
+
listCalendarEvents(accessToken: string, params?: {
|
|
68
|
+
maxResults?: number;
|
|
69
|
+
timeMin?: string;
|
|
70
|
+
}): Promise<{
|
|
71
|
+
items: Array<{
|
|
72
|
+
id: string;
|
|
73
|
+
summary?: string;
|
|
74
|
+
start: {
|
|
75
|
+
dateTime?: string;
|
|
76
|
+
date?: string;
|
|
77
|
+
};
|
|
78
|
+
end: {
|
|
79
|
+
dateTime?: string;
|
|
80
|
+
date?: string;
|
|
81
|
+
};
|
|
82
|
+
htmlLink?: string;
|
|
83
|
+
}>;
|
|
84
|
+
}>;
|
|
85
|
+
appendSheetRow(accessToken: string, params: {
|
|
86
|
+
spreadsheetId: string;
|
|
87
|
+
range: string;
|
|
88
|
+
values: string[];
|
|
89
|
+
}): Promise<{
|
|
90
|
+
updates: {
|
|
91
|
+
updatedRange: string;
|
|
92
|
+
updatedRows: number;
|
|
93
|
+
};
|
|
94
|
+
}>;
|
|
95
|
+
}
|
|
96
|
+
//# sourceMappingURL=google-client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"google-client.d.ts","sourceRoot":"","sources":["../src/google-client.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,MAAM,WAAW,kBAAkB;IACjC,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;IACrB,SAAS,CAAC,EAAE,OAAO,KAAK,CAAC;CAC1B;AAED,MAAM,WAAW,YAAY;IAC3B,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C,kBAAkB,CACtB,WAAW,EAAE,MAAM,EACnB,MAAM,GAAE;QAAE,UAAU,CAAC,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,CAAA;KAAO,GACrD,OAAO,CAAC;QACT,KAAK,EAAE,KAAK,CAAC;YACX,EAAE,EAAE,MAAM,CAAC;YACX,OAAO,CAAC,EAAE,MAAM,CAAC;YACjB,KAAK,EAAE;gBAAE,QAAQ,CAAC,EAAE,MAAM,CAAC;gBAAC,IAAI,CAAC,EAAE,MAAM,CAAA;aAAE,CAAC;YAC5C,GAAG,EAAE;gBAAE,QAAQ,CAAC,EAAE,MAAM,CAAC;gBAAC,IAAI,CAAC,EAAE,MAAM,CAAA;aAAE,CAAC;YAC1C,QAAQ,CAAC,EAAE,MAAM,CAAC;SACnB,CAAC,CAAC;KACJ,CAAC;IAgBI,cAAc,CAClB,WAAW,EAAE,MAAM,EACnB,MAAM,EAAE;QAAE,aAAa,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,EAAE,CAAA;KAAE,GACjE,OAAO,CAAC;QAAE,OAAO,EAAE;YAAE,YAAY,EAAE,MAAM,CAAC;YAAC,WAAW,EAAE,MAAM,CAAA;SAAE,CAAA;KAAE,CAAC;CAkBvE"}
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Thin HTTP client for Google's OAuth + Workspace APIs. All network
|
|
3
|
+
* calls go through `fetchImpl` so tests can inject a fake without
|
|
4
|
+
* touching real Google endpoints.
|
|
5
|
+
*/
|
|
6
|
+
const ACCOUNTS_ORIGIN = "https://accounts.google.com";
|
|
7
|
+
const OAUTH_TOKEN_URL = "https://oauth2.googleapis.com/token";
|
|
8
|
+
const GMAIL_SEND_URL = "https://gmail.googleapis.com/gmail/v1/users/me/messages/send";
|
|
9
|
+
const CALENDAR_LIST_EVENTS_URL = "https://www.googleapis.com/calendar/v3/calendars/primary/events";
|
|
10
|
+
const SHEETS_APPEND_URL = (sheetId, range) => `https://sheets.googleapis.com/v4/spreadsheets/${encodeURIComponent(sheetId)}/values/${encodeURIComponent(range)}:append?valueInputOption=USER_ENTERED&insertDataOption=INSERT_ROWS`;
|
|
11
|
+
export class GoogleClient {
|
|
12
|
+
cfg;
|
|
13
|
+
fetchImpl;
|
|
14
|
+
constructor(cfg) {
|
|
15
|
+
this.cfg = cfg;
|
|
16
|
+
this.fetchImpl = cfg.fetchImpl ?? globalThis.fetch;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Build the full authorization URL the operator's browser should
|
|
20
|
+
* follow. The plugin returns this string from runBeginConnect; the
|
|
21
|
+
* web app redirects the operator to it.
|
|
22
|
+
*
|
|
23
|
+
* PKCE: the worker mints the code_verifier and passes it through.
|
|
24
|
+
* The plugin computes the S256 challenge and includes it on the URL.
|
|
25
|
+
* The matching code_verifier comes back through runCompleteConnect
|
|
26
|
+
* for the token exchange.
|
|
27
|
+
*/
|
|
28
|
+
buildAuthorizationUrl(params) {
|
|
29
|
+
const url = new URL(`${ACCOUNTS_ORIGIN}/o/oauth2/v2/auth`);
|
|
30
|
+
url.searchParams.set("client_id", this.cfg.clientId);
|
|
31
|
+
url.searchParams.set("redirect_uri", params.redirectUri);
|
|
32
|
+
url.searchParams.set("response_type", "code");
|
|
33
|
+
url.searchParams.set("scope", params.scopes.join(" "));
|
|
34
|
+
url.searchParams.set("state", params.state);
|
|
35
|
+
url.searchParams.set("code_challenge", params.codeChallenge);
|
|
36
|
+
url.searchParams.set("code_challenge_method", "S256");
|
|
37
|
+
// access_type=offline + prompt=consent are the two parameters that
|
|
38
|
+
// make Google return a refresh_token. Without both, subsequent
|
|
39
|
+
// re-authorizations sometimes silently omit the refresh_token and
|
|
40
|
+
// the connector stops working after the first hour.
|
|
41
|
+
url.searchParams.set("access_type", "offline");
|
|
42
|
+
url.searchParams.set("prompt", "consent");
|
|
43
|
+
if (params.loginHint)
|
|
44
|
+
url.searchParams.set("login_hint", params.loginHint);
|
|
45
|
+
return url.toString();
|
|
46
|
+
}
|
|
47
|
+
/** Exchange an authorization code for a token set. */
|
|
48
|
+
async exchangeCode(params) {
|
|
49
|
+
const body = new URLSearchParams({
|
|
50
|
+
client_id: this.cfg.clientId,
|
|
51
|
+
client_secret: this.cfg.clientSecret,
|
|
52
|
+
code: params.code,
|
|
53
|
+
code_verifier: params.codeVerifier,
|
|
54
|
+
grant_type: "authorization_code",
|
|
55
|
+
redirect_uri: params.redirectUri,
|
|
56
|
+
});
|
|
57
|
+
const res = await this.fetchImpl(OAUTH_TOKEN_URL, {
|
|
58
|
+
method: "POST",
|
|
59
|
+
headers: { "Content-Type": "application/x-www-form-urlencoded" },
|
|
60
|
+
body: body.toString(),
|
|
61
|
+
});
|
|
62
|
+
if (!res.ok) {
|
|
63
|
+
const text = await safeText(res);
|
|
64
|
+
throw new Error(`google oauth code exchange failed (HTTP ${res.status}): ${text}`);
|
|
65
|
+
}
|
|
66
|
+
return (await res.json());
|
|
67
|
+
}
|
|
68
|
+
/** Rotate the access token using a stored refresh token. */
|
|
69
|
+
async refreshTokens(refreshToken) {
|
|
70
|
+
const body = new URLSearchParams({
|
|
71
|
+
client_id: this.cfg.clientId,
|
|
72
|
+
client_secret: this.cfg.clientSecret,
|
|
73
|
+
grant_type: "refresh_token",
|
|
74
|
+
refresh_token: refreshToken,
|
|
75
|
+
});
|
|
76
|
+
const res = await this.fetchImpl(OAUTH_TOKEN_URL, {
|
|
77
|
+
method: "POST",
|
|
78
|
+
headers: { "Content-Type": "application/x-www-form-urlencoded" },
|
|
79
|
+
body: body.toString(),
|
|
80
|
+
});
|
|
81
|
+
if (!res.ok) {
|
|
82
|
+
const text = await safeText(res);
|
|
83
|
+
throw new Error(`google oauth refresh failed (HTTP ${res.status}): ${text}`);
|
|
84
|
+
}
|
|
85
|
+
// Google omits refresh_token from the response when rotating a
|
|
86
|
+
// long-lived one — the operator's existing refresh_token is still
|
|
87
|
+
// valid. Callers must merge: keep the old refresh_token if the new
|
|
88
|
+
// payload omits it.
|
|
89
|
+
return (await res.json());
|
|
90
|
+
}
|
|
91
|
+
// ─── Action APIs ───────────────────────────────────────────────────
|
|
92
|
+
async sendGmail(accessToken, message) {
|
|
93
|
+
const headers = [`To: ${message.to}`, `Subject: ${message.subject}`];
|
|
94
|
+
if (message.cc)
|
|
95
|
+
headers.push(`Cc: ${message.cc}`);
|
|
96
|
+
headers.push("MIME-Version: 1.0", "Content-Type: text/plain; charset=UTF-8", "");
|
|
97
|
+
const raw = Buffer.from([...headers, message.body].join("\r\n"), "utf8")
|
|
98
|
+
.toString("base64")
|
|
99
|
+
.replace(/\+/g, "-")
|
|
100
|
+
.replace(/\//g, "_")
|
|
101
|
+
.replace(/=+$/, "");
|
|
102
|
+
const res = await this.fetchImpl(GMAIL_SEND_URL, {
|
|
103
|
+
method: "POST",
|
|
104
|
+
headers: {
|
|
105
|
+
Authorization: `Bearer ${accessToken}`,
|
|
106
|
+
"Content-Type": "application/json",
|
|
107
|
+
},
|
|
108
|
+
body: JSON.stringify({ raw }),
|
|
109
|
+
});
|
|
110
|
+
if (!res.ok) {
|
|
111
|
+
const text = await safeText(res);
|
|
112
|
+
throw new Error(`gmail send failed (HTTP ${res.status}): ${text}`);
|
|
113
|
+
}
|
|
114
|
+
return (await res.json());
|
|
115
|
+
}
|
|
116
|
+
async listCalendarEvents(accessToken, params = {}) {
|
|
117
|
+
const url = new URL(CALENDAR_LIST_EVENTS_URL);
|
|
118
|
+
url.searchParams.set("maxResults", String(params.maxResults ?? 10));
|
|
119
|
+
url.searchParams.set("singleEvents", "true");
|
|
120
|
+
url.searchParams.set("orderBy", "startTime");
|
|
121
|
+
url.searchParams.set("timeMin", params.timeMin ?? new Date().toISOString());
|
|
122
|
+
const res = await this.fetchImpl(url.toString(), {
|
|
123
|
+
headers: { Authorization: `Bearer ${accessToken}` },
|
|
124
|
+
});
|
|
125
|
+
if (!res.ok) {
|
|
126
|
+
const text = await safeText(res);
|
|
127
|
+
throw new Error(`calendar list failed (HTTP ${res.status}): ${text}`);
|
|
128
|
+
}
|
|
129
|
+
return (await res.json());
|
|
130
|
+
}
|
|
131
|
+
async appendSheetRow(accessToken, params) {
|
|
132
|
+
const res = await this.fetchImpl(SHEETS_APPEND_URL(params.spreadsheetId, params.range), {
|
|
133
|
+
method: "POST",
|
|
134
|
+
headers: {
|
|
135
|
+
Authorization: `Bearer ${accessToken}`,
|
|
136
|
+
"Content-Type": "application/json",
|
|
137
|
+
},
|
|
138
|
+
body: JSON.stringify({ values: [params.values] }),
|
|
139
|
+
});
|
|
140
|
+
if (!res.ok) {
|
|
141
|
+
const text = await safeText(res);
|
|
142
|
+
throw new Error(`sheets append failed (HTTP ${res.status}): ${text}`);
|
|
143
|
+
}
|
|
144
|
+
return (await res.json());
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
async function safeText(res) {
|
|
148
|
+
try {
|
|
149
|
+
return await res.text();
|
|
150
|
+
}
|
|
151
|
+
catch {
|
|
152
|
+
return "<unreadable>";
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
//# sourceMappingURL=google-client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"google-client.js","sourceRoot":"","sources":["../src/google-client.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AA0BH,MAAM,eAAe,GAAG,6BAA6B,CAAC;AACtD,MAAM,eAAe,GAAG,qCAAqC,CAAC;AAC9D,MAAM,cAAc,GAClB,8DAA8D,CAAC;AACjE,MAAM,wBAAwB,GAC5B,iEAAiE,CAAC;AACpE,MAAM,iBAAiB,GAAG,CAAC,OAAe,EAAE,KAAa,EAAE,EAAE,CAC3D,iDAAiD,kBAAkB,CAAC,OAAO,CAAC,WAAW,kBAAkB,CAAC,KAAK,CAAC,oEAAoE,CAAC;AAEvL,MAAM,OAAO,YAAY;IAGM;IAFZ,SAAS,CAAe;IAEzC,YAA6B,GAAuB;QAAvB,QAAG,GAAH,GAAG,CAAoB;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CAAC,MAAM,GAAG,CAAC,IAAI,EAAE,CAA4D,CAAC;IACvF,CAAC;IAED,KAAK,CAAC,cAAc,CAClB,WAAmB,EACnB,MAAkE;QAElE,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,SAAS,CAC9B,iBAAiB,CAAC,MAAM,CAAC,aAAa,EAAE,MAAM,CAAC,KAAK,CAAC,EACrD;YACE,MAAM,EAAE,MAAM;YACd,OAAO,EAAE;gBACP,aAAa,EAAE,UAAU,WAAW,EAAE;gBACtC,cAAc,EAAE,kBAAkB;aACnC;YACD,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC;SAClD,CACF,CAAC;QACF,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC;YACZ,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,GAAG,CAAC,CAAC;YACjC,MAAM,IAAI,KAAK,CAAC,8BAA8B,GAAG,CAAC,MAAM,MAAM,IAAI,EAAE,CAAC,CAAC;QACxE,CAAC;QACD,OAAO,CAAC,MAAM,GAAG,CAAC,IAAI,EAAE,CAAwD,CAAC;IACnF,CAAC;CACF;AAED,KAAK,UAAU,QAAQ,CAAC,GAAa;IACnC,IAAI,CAAC;QACH,OAAO,MAAM,GAAG,CAAC,IAAI,EAAE,CAAC;IAC1B,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,cAAc,CAAC;IACxB,CAAC;AACH,CAAC"}
|
package/dist/plugin.d.ts
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Google Workspace connector plugin.
|
|
3
|
+
*
|
|
4
|
+
* Two surfaces:
|
|
5
|
+
*
|
|
6
|
+
* 1. `connect` — per-operator OAuth2 + PKCE flow against the
|
|
7
|
+
* operator's own Google Cloud OAuth client. Each operator on
|
|
8
|
+
* this deployment authorises independently; the worker
|
|
9
|
+
* persists the resulting credentials in the per-operator
|
|
10
|
+
* section of the secrets store.
|
|
11
|
+
*
|
|
12
|
+
* 2. `action` — Gmail / Calendar / Sheets actions backed by the
|
|
13
|
+
* connected operator's account. At action-execution time the
|
|
14
|
+
* worker injects the operator's credential as the
|
|
15
|
+
* OPENNEKO_CONNECTOR_CREDENTIAL_TOKENS env var (JSON-encoded
|
|
16
|
+
* access_token + refresh_token); the action handler reads it,
|
|
17
|
+
* makes the API call, and returns the outcome.
|
|
18
|
+
*
|
|
19
|
+
* No tokens cross the sandbox boundary except via this env-var
|
|
20
|
+
* injection — the plugin never persists anything to disk; the
|
|
21
|
+
* worker is the only writer to secrets.json.
|
|
22
|
+
*/
|
|
23
|
+
import { type BeginConnectParams, type BeginConnectResult, type CompleteConnectParams, type CompleteConnectResult, type PluginActionOutcome, type PluginActionRequest, type RefreshConnectParams, type RefreshConnectResult } from "@open-neko/plugin-types";
|
|
24
|
+
import { GoogleClient } from "./google-client.js";
|
|
25
|
+
export declare class GoogleWorkspaceError extends Error {
|
|
26
|
+
readonly cause?: unknown | undefined;
|
|
27
|
+
constructor(message: string, cause?: unknown | undefined);
|
|
28
|
+
}
|
|
29
|
+
interface ResolvedClientEnv {
|
|
30
|
+
clientId: string;
|
|
31
|
+
clientSecret: string;
|
|
32
|
+
}
|
|
33
|
+
/** Test seam: inject a fake GoogleClient. */
|
|
34
|
+
export interface InvokeOptions {
|
|
35
|
+
createClient?: (env: ResolvedClientEnv) => GoogleClient;
|
|
36
|
+
}
|
|
37
|
+
export declare function runBeginConnect(params: BeginConnectParams, options?: InvokeOptions): Promise<BeginConnectResult>;
|
|
38
|
+
export declare function runCompleteConnect(params: CompleteConnectParams, options?: InvokeOptions): Promise<CompleteConnectResult>;
|
|
39
|
+
export declare function runRefreshConnect(params: RefreshConnectParams, options?: InvokeOptions): Promise<RefreshConnectResult>;
|
|
40
|
+
interface ActionInvokeOptions extends InvokeOptions {
|
|
41
|
+
/** Test seam: override the env-injected tokens. */
|
|
42
|
+
readTokens?: () => {
|
|
43
|
+
access_token: string;
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
export declare function runSendGmail(request: PluginActionRequest, options?: ActionInvokeOptions): Promise<PluginActionOutcome>;
|
|
47
|
+
export declare function runListCalendarEvents(request: PluginActionRequest, options?: ActionInvokeOptions): Promise<PluginActionOutcome>;
|
|
48
|
+
export declare function runAppendSheetRow(request: PluginActionRequest, options?: ActionInvokeOptions): Promise<PluginActionOutcome>;
|
|
49
|
+
declare const _default: import("@open-neko/plugin-types").PluginDefinition;
|
|
50
|
+
export default _default;
|
|
51
|
+
//# sourceMappingURL=plugin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAGH,OAAO,EAEL,KAAK,kBAAkB,EACvB,KAAK,kBAAkB,EACvB,KAAK,qBAAqB,EAC1B,KAAK,qBAAqB,EAE1B,KAAK,mBAAmB,EACxB,KAAK,mBAAmB,EACxB,KAAK,oBAAoB,EACzB,KAAK,oBAAoB,EAC1B,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,YAAY,EAA2B,MAAM,oBAAoB,CAAC;AAE3E,qBAAa,oBAAqB,SAAQ,KAAK;aACS,KAAK,CAAC,EAAE,OAAO;gBAAzD,OAAO,EAAE,MAAM,EAA2B,KAAK,CAAC,EAAE,OAAO,YAAA;CAItE;AAED,UAAU,iBAAiB;IACzB,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;CACtB;AAED,6CAA6C;AAC7C,MAAM,WAAW,aAAa;IAC5B,YAAY,CAAC,EAAE,CAAC,GAAG,EAAE,iBAAiB,KAAK,YAAY,CAAC;CACzD;AAgCD,wBAAsB,eAAe,CACnC,MAAM,EAAE,kBAAkB,EAC1B,OAAO,GAAE,aAAkB,GAC1B,OAAO,CAAC,kBAAkB,CAAC,CAiB7B;AAED,wBAAsB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