slates 1.0.0-rc.1 → 1.0.0-rc.10
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.cjs +24 -0
- package/dist/index.d.cts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.module.js +2 -0
- package/package.json +15 -7
- package/example/google-sheets/auth.ts +0 -317
- package/example/google-sheets/config.ts +0 -9
- package/example/google-sheets/docs/abc.md +0 -1
- package/example/google-sheets/docs/readme.md +0 -1
- package/example/google-sheets/index.ts +0 -42
- package/example/google-sheets/lib/client.ts +0 -717
- package/example/google-sheets/lib/types.ts +0 -1674
- package/example/google-sheets/readme.md +0 -1
- package/example/google-sheets/slate.json +0 -4
- package/example/google-sheets/spec.ts +0 -13
- package/example/google-sheets/tools/append-values.ts +0 -74
- package/example/google-sheets/tools/clear-values.ts +0 -45
- package/example/google-sheets/tools/copy-paste.ts +0 -99
- package/example/google-sheets/tools/create-spreadsheet.ts +0 -72
- package/example/google-sheets/tools/find-replace.ts +0 -68
- package/example/google-sheets/tools/format-cells.ts +0 -137
- package/example/google-sheets/tools/get-spreadsheet.ts +0 -108
- package/example/google-sheets/tools/index.ts +0 -15
- package/example/google-sheets/tools/manage-rows-columns.ts +0 -160
- package/example/google-sheets/tools/manage-sheets.ts +0 -183
- package/example/google-sheets/tools/merge-cells.ts +0 -76
- package/example/google-sheets/tools/named-ranges.ts +0 -82
- package/example/google-sheets/tools/protect-range.ts +0 -100
- package/example/google-sheets/tools/read-values.ts +0 -94
- package/example/google-sheets/tools/sort-range.ts +0 -78
- package/example/google-sheets/tools/write-values.ts +0 -91
- package/example/google-sheets/triggers/index.ts +0 -1
- package/example/google-sheets/triggers/spreadsheet-changed.ts +0 -108
- package/example/out.zip.b64 +0 -1
- package/tsconfig.json +0 -8
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
15
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
16
|
+
|
|
17
|
+
// src/index.ts
|
|
18
|
+
var index_exports = {};
|
|
19
|
+
module.exports = __toCommonJS(index_exports);
|
|
20
|
+
__reExport(index_exports, require("@slates/provider"), module.exports);
|
|
21
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
22
|
+
0 && (module.exports = {
|
|
23
|
+
...require("@slates/provider")
|
|
24
|
+
});
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@slates/provider';
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@slates/provider';
|
package/package.json
CHANGED
|
@@ -1,14 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "slates",
|
|
3
|
-
"version": "1.0.0-rc.
|
|
3
|
+
"version": "1.0.0-rc.10",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
7
7
|
"author": "Tobias Herber",
|
|
8
|
-
"license": "
|
|
8
|
+
"license": "FSL 1.1",
|
|
9
9
|
"type": "module",
|
|
10
10
|
"source": "src/index.ts",
|
|
11
|
+
"files": [
|
|
12
|
+
"src/**",
|
|
13
|
+
"dist/**",
|
|
14
|
+
"README.md",
|
|
15
|
+
"package.json"
|
|
16
|
+
],
|
|
11
17
|
"exports": {
|
|
18
|
+
"bun": "./src/index.ts",
|
|
12
19
|
"types": "./dist/index.d.ts",
|
|
13
20
|
"require": "./dist/index.cjs",
|
|
14
21
|
"import": "./dist/index.module.js",
|
|
@@ -17,19 +24,20 @@
|
|
|
17
24
|
"main": "./dist/index.cjs",
|
|
18
25
|
"module": "./dist/index.module.js",
|
|
19
26
|
"types": "dist/index.d.ts",
|
|
20
|
-
"unpkg": "./dist/index.
|
|
27
|
+
"unpkg": "./dist/index.module.js",
|
|
21
28
|
"scripts": {
|
|
22
29
|
"test": "vitest run --passWithNoTests",
|
|
23
30
|
"lint": "prettier src/**/*.ts --check",
|
|
24
|
-
"build": "
|
|
31
|
+
"build": "tsup --config ../../tsup.packages.config.ts",
|
|
32
|
+
"typecheck": "tsc --noEmit"
|
|
25
33
|
},
|
|
26
34
|
"dependencies": {
|
|
27
|
-
"@slates/provider": "
|
|
35
|
+
"@slates/provider": "1.0.0-rc.11"
|
|
28
36
|
},
|
|
29
37
|
"devDependencies": {
|
|
30
38
|
"microbundle": "^0.15.1",
|
|
31
|
-
"@slates/tsconfig": "
|
|
39
|
+
"@slates/tsconfig": "1.0.0-rc.1",
|
|
32
40
|
"typescript": "5.8.2",
|
|
33
41
|
"vitest": "^3.1.2"
|
|
34
42
|
}
|
|
35
|
-
}
|
|
43
|
+
}
|
|
@@ -1,317 +0,0 @@
|
|
|
1
|
-
import { SlateAuth, createAxios } from 'slates';
|
|
2
|
-
import { z } from 'zod';
|
|
3
|
-
|
|
4
|
-
let axios = createAxios({
|
|
5
|
-
baseURL: 'https://oauth2.googleapis.com'
|
|
6
|
-
});
|
|
7
|
-
|
|
8
|
-
export let auth = SlateAuth.create()
|
|
9
|
-
.output(
|
|
10
|
-
z.object({
|
|
11
|
-
token: z.string(),
|
|
12
|
-
refreshToken: z.string().optional(),
|
|
13
|
-
expiresAt: z.date().optional()
|
|
14
|
-
})
|
|
15
|
-
)
|
|
16
|
-
.addOauth({
|
|
17
|
-
type: 'auth.oauth',
|
|
18
|
-
name: 'Google OAuth2',
|
|
19
|
-
key: 'google_oauth2',
|
|
20
|
-
|
|
21
|
-
scopes: [
|
|
22
|
-
{
|
|
23
|
-
title: 'Google Sheets - Full Access',
|
|
24
|
-
description: 'Full read and write access to Google Sheets',
|
|
25
|
-
scope: 'https://www.googleapis.com/auth/spreadsheets'
|
|
26
|
-
},
|
|
27
|
-
{
|
|
28
|
-
title: 'Google Drive - File Access',
|
|
29
|
-
description: 'Access to files created or opened by the app',
|
|
30
|
-
scope: 'https://www.googleapis.com/auth/drive.file'
|
|
31
|
-
}
|
|
32
|
-
],
|
|
33
|
-
|
|
34
|
-
inputSchema: z.object({}),
|
|
35
|
-
|
|
36
|
-
getAuthorizationUrl: async ctx => {
|
|
37
|
-
let params = new URLSearchParams({
|
|
38
|
-
client_id: ctx.clientId,
|
|
39
|
-
redirect_uri: ctx.redirectUri,
|
|
40
|
-
response_type: 'code',
|
|
41
|
-
scope: ctx.scopes.join(' '),
|
|
42
|
-
state: ctx.state,
|
|
43
|
-
access_type: 'offline',
|
|
44
|
-
prompt: 'consent'
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
return {
|
|
48
|
-
url: `https://accounts.google.com/o/oauth2/v2/auth?${params.toString()}`,
|
|
49
|
-
input: ctx.input
|
|
50
|
-
};
|
|
51
|
-
},
|
|
52
|
-
|
|
53
|
-
handleCallback: async ctx => {
|
|
54
|
-
let response = await axios.post(
|
|
55
|
-
'/token',
|
|
56
|
-
new URLSearchParams({
|
|
57
|
-
client_id: ctx.clientId,
|
|
58
|
-
client_secret: ctx.clientSecret,
|
|
59
|
-
code: ctx.code,
|
|
60
|
-
grant_type: 'authorization_code',
|
|
61
|
-
redirect_uri: ctx.redirectUri
|
|
62
|
-
}).toString(),
|
|
63
|
-
{
|
|
64
|
-
headers: {
|
|
65
|
-
'Content-Type': 'application/x-www-form-urlencoded'
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
);
|
|
69
|
-
|
|
70
|
-
let data = response.data as {
|
|
71
|
-
access_token: string;
|
|
72
|
-
refresh_token?: string;
|
|
73
|
-
expires_in?: number;
|
|
74
|
-
};
|
|
75
|
-
|
|
76
|
-
return {
|
|
77
|
-
output: {
|
|
78
|
-
token: data.access_token,
|
|
79
|
-
refreshToken: data.refresh_token,
|
|
80
|
-
expiresAt: data.expires_in
|
|
81
|
-
? new Date(Date.now() + data.expires_in * 1000)
|
|
82
|
-
: undefined
|
|
83
|
-
},
|
|
84
|
-
input: ctx.input
|
|
85
|
-
};
|
|
86
|
-
},
|
|
87
|
-
|
|
88
|
-
handleTokenRefresh: async ctx => {
|
|
89
|
-
if (!ctx.output.refreshToken) {
|
|
90
|
-
throw new Error('No refresh token available');
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
let response = await axios.post(
|
|
94
|
-
'/token',
|
|
95
|
-
new URLSearchParams({
|
|
96
|
-
client_id: ctx.clientId,
|
|
97
|
-
client_secret: ctx.clientSecret,
|
|
98
|
-
refresh_token: ctx.output.refreshToken,
|
|
99
|
-
grant_type: 'refresh_token'
|
|
100
|
-
}).toString(),
|
|
101
|
-
{
|
|
102
|
-
headers: {
|
|
103
|
-
'Content-Type': 'application/x-www-form-urlencoded'
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
);
|
|
107
|
-
|
|
108
|
-
let data = response.data as {
|
|
109
|
-
access_token: string;
|
|
110
|
-
refresh_token?: string;
|
|
111
|
-
expires_in?: number;
|
|
112
|
-
};
|
|
113
|
-
|
|
114
|
-
return {
|
|
115
|
-
output: {
|
|
116
|
-
token: data.access_token,
|
|
117
|
-
refreshToken: data.refresh_token || ctx.output.refreshToken,
|
|
118
|
-
expiresAt: data.expires_in
|
|
119
|
-
? new Date(Date.now() + data.expires_in * 1000)
|
|
120
|
-
: undefined
|
|
121
|
-
},
|
|
122
|
-
input: ctx.input
|
|
123
|
-
};
|
|
124
|
-
},
|
|
125
|
-
|
|
126
|
-
getProfile: async (ctx: { output: { token: string }; input: Record<string, never> }) => {
|
|
127
|
-
let profileAxios = createAxios({
|
|
128
|
-
baseURL: 'https://www.googleapis.com'
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
let response = await profileAxios.get('/oauth2/v2/userinfo', {
|
|
132
|
-
headers: {
|
|
133
|
-
Authorization: `Bearer ${ctx.output.token}`
|
|
134
|
-
}
|
|
135
|
-
});
|
|
136
|
-
|
|
137
|
-
let data = response.data as {
|
|
138
|
-
id?: string;
|
|
139
|
-
email?: string;
|
|
140
|
-
name?: string;
|
|
141
|
-
picture?: string;
|
|
142
|
-
};
|
|
143
|
-
|
|
144
|
-
return {
|
|
145
|
-
profile: {
|
|
146
|
-
id: data.id,
|
|
147
|
-
email: data.email,
|
|
148
|
-
name: data.name,
|
|
149
|
-
imageUrl: data.picture
|
|
150
|
-
}
|
|
151
|
-
};
|
|
152
|
-
}
|
|
153
|
-
})
|
|
154
|
-
.addServiceAccountAuth({
|
|
155
|
-
type: 'auth.service_account',
|
|
156
|
-
name: 'Service Account',
|
|
157
|
-
key: 'service_account',
|
|
158
|
-
|
|
159
|
-
inputSchema: z.object({
|
|
160
|
-
serviceAccountJson: z.string().describe('JSON key file contents for the service account')
|
|
161
|
-
}),
|
|
162
|
-
|
|
163
|
-
getOutput: async ctx => {
|
|
164
|
-
let serviceAccount: {
|
|
165
|
-
client_email: string;
|
|
166
|
-
private_key: string;
|
|
167
|
-
token_uri?: string;
|
|
168
|
-
};
|
|
169
|
-
|
|
170
|
-
try {
|
|
171
|
-
serviceAccount = JSON.parse(ctx.input.serviceAccountJson);
|
|
172
|
-
} catch {
|
|
173
|
-
throw new Error('Invalid service account JSON');
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
if (!serviceAccount.client_email || !serviceAccount.private_key) {
|
|
177
|
-
throw new Error('Service account JSON must contain client_email and private_key');
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
let token = await generateServiceAccountToken(serviceAccount, [
|
|
181
|
-
'https://www.googleapis.com/auth/spreadsheets',
|
|
182
|
-
'https://www.googleapis.com/auth/drive.file'
|
|
183
|
-
]);
|
|
184
|
-
|
|
185
|
-
return {
|
|
186
|
-
output: {
|
|
187
|
-
token: token.accessToken,
|
|
188
|
-
expiresAt: token.expiresAt
|
|
189
|
-
}
|
|
190
|
-
};
|
|
191
|
-
},
|
|
192
|
-
|
|
193
|
-
getProfile: async (ctx: {
|
|
194
|
-
output: { token: string };
|
|
195
|
-
input: { serviceAccountJson: string };
|
|
196
|
-
}) => {
|
|
197
|
-
let serviceAccount: { client_email: string };
|
|
198
|
-
|
|
199
|
-
try {
|
|
200
|
-
serviceAccount = JSON.parse(ctx.input.serviceAccountJson);
|
|
201
|
-
} catch {
|
|
202
|
-
throw new Error('Invalid service account JSON');
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
return {
|
|
206
|
-
profile: {
|
|
207
|
-
email: serviceAccount.client_email,
|
|
208
|
-
name: 'Service Account'
|
|
209
|
-
}
|
|
210
|
-
};
|
|
211
|
-
}
|
|
212
|
-
})
|
|
213
|
-
.addTokenAuth({
|
|
214
|
-
type: 'auth.token',
|
|
215
|
-
name: 'API Key',
|
|
216
|
-
key: 'api_key',
|
|
217
|
-
|
|
218
|
-
inputSchema: z.object({
|
|
219
|
-
token: z
|
|
220
|
-
.string()
|
|
221
|
-
.describe('Google Cloud API Key (read-only access to public spreadsheets only)')
|
|
222
|
-
}),
|
|
223
|
-
|
|
224
|
-
getOutput: async ctx => {
|
|
225
|
-
return {
|
|
226
|
-
output: {
|
|
227
|
-
token: ctx.input.token
|
|
228
|
-
}
|
|
229
|
-
};
|
|
230
|
-
}
|
|
231
|
-
});
|
|
232
|
-
|
|
233
|
-
let generateServiceAccountToken = async (
|
|
234
|
-
serviceAccount: {
|
|
235
|
-
client_email: string;
|
|
236
|
-
private_key: string;
|
|
237
|
-
token_uri?: string;
|
|
238
|
-
},
|
|
239
|
-
scopes: string[]
|
|
240
|
-
): Promise<{ accessToken: string; expiresAt: Date }> => {
|
|
241
|
-
let now = Math.floor(Date.now() / 1000);
|
|
242
|
-
let exp = now + 3600;
|
|
243
|
-
|
|
244
|
-
let header = {
|
|
245
|
-
alg: 'RS256',
|
|
246
|
-
typ: 'JWT'
|
|
247
|
-
};
|
|
248
|
-
|
|
249
|
-
let payload = {
|
|
250
|
-
iss: serviceAccount.client_email,
|
|
251
|
-
scope: scopes.join(' '),
|
|
252
|
-
aud: 'https://oauth2.googleapis.com/token',
|
|
253
|
-
iat: now,
|
|
254
|
-
exp: exp
|
|
255
|
-
};
|
|
256
|
-
|
|
257
|
-
let jwt = await signJwt(header, payload, serviceAccount.private_key);
|
|
258
|
-
|
|
259
|
-
let response = await axios.post(
|
|
260
|
-
'/token',
|
|
261
|
-
new URLSearchParams({
|
|
262
|
-
grant_type: 'urn:ietf:params:oauth:grant-type:jwt-bearer',
|
|
263
|
-
assertion: jwt
|
|
264
|
-
}).toString(),
|
|
265
|
-
{
|
|
266
|
-
headers: {
|
|
267
|
-
'Content-Type': 'application/x-www-form-urlencoded'
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
);
|
|
271
|
-
|
|
272
|
-
let data = response.data as {
|
|
273
|
-
access_token: string;
|
|
274
|
-
expires_in: number;
|
|
275
|
-
};
|
|
276
|
-
|
|
277
|
-
return {
|
|
278
|
-
accessToken: data.access_token,
|
|
279
|
-
expiresAt: new Date(Date.now() + data.expires_in * 1000)
|
|
280
|
-
};
|
|
281
|
-
};
|
|
282
|
-
|
|
283
|
-
let signJwt = async (header: object, payload: object, privateKey: string): Promise<string> => {
|
|
284
|
-
let base64UrlEncode = (data: Uint8Array): string => {
|
|
285
|
-
let base64 = btoa(String.fromCharCode(...data));
|
|
286
|
-
return base64.replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '');
|
|
287
|
-
};
|
|
288
|
-
|
|
289
|
-
let textEncoder = new TextEncoder();
|
|
290
|
-
let headerB64 = base64UrlEncode(textEncoder.encode(JSON.stringify(header)));
|
|
291
|
-
let payloadB64 = base64UrlEncode(textEncoder.encode(JSON.stringify(payload)));
|
|
292
|
-
let signingInput = `${headerB64}.${payloadB64}`;
|
|
293
|
-
|
|
294
|
-
let pemContents = privateKey
|
|
295
|
-
.replace(/-----BEGIN PRIVATE KEY-----/g, '')
|
|
296
|
-
.replace(/-----END PRIVATE KEY-----/g, '')
|
|
297
|
-
.replace(/\s/g, '');
|
|
298
|
-
let binaryKey = Uint8Array.from(atob(pemContents), c => c.charCodeAt(0));
|
|
299
|
-
|
|
300
|
-
let cryptoKey = await crypto.subtle.importKey(
|
|
301
|
-
'pkcs8',
|
|
302
|
-
binaryKey,
|
|
303
|
-
{ name: 'RSASSA-PKCS1-v1_5', hash: 'SHA-256' },
|
|
304
|
-
false,
|
|
305
|
-
['sign']
|
|
306
|
-
);
|
|
307
|
-
|
|
308
|
-
let signature = await crypto.subtle.sign(
|
|
309
|
-
'RSASSA-PKCS1-v1_5',
|
|
310
|
-
cryptoKey,
|
|
311
|
-
textEncoder.encode(signingInput)
|
|
312
|
-
);
|
|
313
|
-
|
|
314
|
-
let signatureB64 = base64UrlEncode(new Uint8Array(signature));
|
|
315
|
-
|
|
316
|
-
return `${signingInput}.${signatureB64}`;
|
|
317
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
ABC
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
please do read me
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { Slate } from 'slates';
|
|
2
|
-
import { spec } from './spec';
|
|
3
|
-
import {
|
|
4
|
-
appendValuesTool,
|
|
5
|
-
clearValuesTool,
|
|
6
|
-
copyPasteTool,
|
|
7
|
-
createSpreadsheetTool,
|
|
8
|
-
findReplaceTool,
|
|
9
|
-
formatCellsTool,
|
|
10
|
-
getSpreadsheetTool,
|
|
11
|
-
manageRowsColumnsTool,
|
|
12
|
-
manageSheetsTool,
|
|
13
|
-
mergeCellsTool,
|
|
14
|
-
namedRangesTool,
|
|
15
|
-
protectRangeTool,
|
|
16
|
-
readValuesTool,
|
|
17
|
-
sortRangeTool,
|
|
18
|
-
writeValuesTool
|
|
19
|
-
} from './tools';
|
|
20
|
-
import { spreadsheetChangedTrigger } from './triggers';
|
|
21
|
-
|
|
22
|
-
export let provider = Slate.create({
|
|
23
|
-
spec,
|
|
24
|
-
tools: [
|
|
25
|
-
createSpreadsheetTool,
|
|
26
|
-
getSpreadsheetTool,
|
|
27
|
-
readValuesTool,
|
|
28
|
-
writeValuesTool,
|
|
29
|
-
appendValuesTool,
|
|
30
|
-
clearValuesTool,
|
|
31
|
-
manageSheetsTool,
|
|
32
|
-
formatCellsTool,
|
|
33
|
-
findReplaceTool,
|
|
34
|
-
manageRowsColumnsTool,
|
|
35
|
-
sortRangeTool,
|
|
36
|
-
mergeCellsTool,
|
|
37
|
-
protectRangeTool,
|
|
38
|
-
namedRangesTool,
|
|
39
|
-
copyPasteTool
|
|
40
|
-
],
|
|
41
|
-
triggers: [spreadsheetChangedTrigger]
|
|
42
|
-
});
|