@theholocron/google-client 1.58.0-alpha.1 → 1.58.0-alpha.11
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/dist/index.d.mts +6 -0
- package/dist/index.mjs +11 -2
- package/package.json +14 -14
package/dist/index.d.mts
CHANGED
|
@@ -1,11 +1,17 @@
|
|
|
1
1
|
import { JWT, OAuth2Client } from "google-auth-library";
|
|
2
|
+
/** The result of a Google call as a tuple of error, value and elapsed milliseconds: `[Error, null, ms]` on failure, `[null, T, ms]` on success. */
|
|
2
3
|
type Return<T> = [Error, null, number] | [null, T, number];
|
|
4
|
+
/** Signs in with Google OAuth: opens the consent page, waits on a local callback and resolves with the client holding the tokens. */
|
|
3
5
|
export declare const oauth: (scopes: string[]) => Promise<OAuth2Client | null>;
|
|
6
|
+
/** Authenticates as the service account from `loadServiceAccountKey()` for the given scopes and resolves with its JWT client. */
|
|
4
7
|
export declare function googleAuth(scopes: string[]): Promise<JWT>;
|
|
8
|
+
/** Read-only Google Docs and Sheets helpers, each authenticated with the service account. */
|
|
5
9
|
export declare const google: {
|
|
10
|
+
/** Google Docs helpers. */
|
|
6
11
|
documents: {
|
|
7
12
|
get: (id: string) => Promise<Return<import("googleapis").docs_v1.Schema$Document>>;
|
|
8
13
|
};
|
|
14
|
+
/** Google Sheets helpers. */
|
|
9
15
|
spreadsheets: {
|
|
10
16
|
get: (id: string) => Promise<Return<import("googleapis").sheets_v4.Schema$Spreadsheet>>;
|
|
11
17
|
};
|
package/dist/index.mjs
CHANGED
|
@@ -42,6 +42,7 @@ function buildOAuth2Client() {
|
|
|
42
42
|
if (!clientID || !clientSecret) throw new Error("GOOGLE_CLIENT_ID and GOOGLE_CLIENT_SECRET environment variables are required for OAuth");
|
|
43
43
|
return new google$1.auth.OAuth2(clientID, clientSecret, redirectURI);
|
|
44
44
|
}
|
|
45
|
+
/** Signs in with Google OAuth: opens the consent page, waits on a local callback and resolves with the client holding the tokens. */
|
|
45
46
|
const oauth = async (scopes) => {
|
|
46
47
|
const oauth2Client = buildOAuth2Client();
|
|
47
48
|
const port = parseInt(process.env.GOOGLE_REDIRECT_PORT ?? "4000", 10);
|
|
@@ -69,6 +70,7 @@ const oauth = async (scopes) => {
|
|
|
69
70
|
destroyer(server);
|
|
70
71
|
});
|
|
71
72
|
};
|
|
73
|
+
/** Authenticates as the service account from `loadServiceAccountKey()` for the given scopes and resolves with its JWT client. */
|
|
72
74
|
async function googleAuth(scopes) {
|
|
73
75
|
return await new google$1.auth.GoogleAuth({
|
|
74
76
|
credentials: loadServiceAccountKey(),
|
|
@@ -102,7 +104,9 @@ async function getDocument(id) {
|
|
|
102
104
|
];
|
|
103
105
|
}
|
|
104
106
|
}
|
|
105
|
-
const documents = {
|
|
107
|
+
const documents = {
|
|
108
|
+
/** Reads a Google Doc by id; resolves with a `Return` tuple of error, document and elapsed milliseconds. */
|
|
109
|
+
get: getDocument };
|
|
106
110
|
// src/spreadsheets.ts
|
|
107
111
|
const sheets = google$1.sheets("v4");
|
|
108
112
|
async function getSpreadsheet(id) {
|
|
@@ -132,8 +136,13 @@ async function getSpreadsheet(id) {
|
|
|
132
136
|
}
|
|
133
137
|
}
|
|
134
138
|
// src/index.ts
|
|
139
|
+
/** Read-only Google Docs and Sheets helpers, each authenticated with the service account. */
|
|
135
140
|
const google = {
|
|
141
|
+
/** Google Docs helpers. */
|
|
136
142
|
documents,
|
|
137
|
-
|
|
143
|
+
/** Google Sheets helpers. */
|
|
144
|
+
spreadsheets: {
|
|
145
|
+
/** Reads a spreadsheet by id, grid data included; resolves with a `Return` tuple of error, spreadsheet and elapsed ms. */
|
|
146
|
+
get: getSpreadsheet }
|
|
138
147
|
};
|
|
139
148
|
export { google, googleAuth, oauth };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@theholocron/google-client",
|
|
3
|
-
"version": "1.58.0-alpha.
|
|
3
|
+
"version": "1.58.0-alpha.11",
|
|
4
4
|
"description": "A TypeScript client for Google Workspace APIs (Docs, Sheets)",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"google",
|
|
@@ -41,17 +41,17 @@
|
|
|
41
41
|
"@types/node": "^26",
|
|
42
42
|
"@types/server-destroy": "^1.0.4",
|
|
43
43
|
"@vitest/coverage-v8": "^5.0.5",
|
|
44
|
-
"@vitest/eslint-plugin": "^1.6.
|
|
45
|
-
"eslint": "^10.
|
|
46
|
-
"eslint-plugin-n": "^18.
|
|
47
|
-
"globals": "^17.
|
|
48
|
-
"tsdown": "^0.23.
|
|
44
|
+
"@vitest/eslint-plugin": "^1.6.28",
|
|
45
|
+
"eslint": "^10.14.0",
|
|
46
|
+
"eslint-plugin-n": "^18.5.0",
|
|
47
|
+
"globals": "^17.14.0",
|
|
48
|
+
"tsdown": "^0.23.4",
|
|
49
49
|
"typescript": "^5.9.3",
|
|
50
50
|
"vitest": "^5.0.5",
|
|
51
|
-
"@theholocron/
|
|
52
|
-
"@theholocron/
|
|
53
|
-
"@theholocron/tsdown-config": "^8.9.0-alpha.
|
|
54
|
-
"@theholocron/vitest-config": "^8.9.0-alpha.
|
|
51
|
+
"@theholocron/tsconfig": "^8.9.0-alpha.8",
|
|
52
|
+
"@theholocron/eslint-config": "^8.9.0-alpha.8",
|
|
53
|
+
"@theholocron/tsdown-config": "^8.9.0-alpha.8",
|
|
54
|
+
"@theholocron/vitest-config": "^8.9.0-alpha.8"
|
|
55
55
|
},
|
|
56
56
|
"engines": {
|
|
57
57
|
"node": ">=22.0.0"
|
|
@@ -60,10 +60,10 @@
|
|
|
60
60
|
"access": "public"
|
|
61
61
|
},
|
|
62
62
|
"scripts": {
|
|
63
|
-
"
|
|
64
|
-
"
|
|
63
|
+
"build": "tsdown && node ../scripts/check-bundle-size.mjs",
|
|
64
|
+
"lint:code": "eslint .",
|
|
65
|
+
"test:unit": "vitest run --coverage",
|
|
65
66
|
"test:watch": "vitest",
|
|
66
|
-
"
|
|
67
|
-
"verification.unitTests": "vitest run"
|
|
67
|
+
"typecheck": "tsc --noEmit"
|
|
68
68
|
}
|
|
69
69
|
}
|