@squadbase/vite-server 0.1.3-dev.1 → 0.1.3-dev.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.
Files changed (58) hide show
  1. package/dist/cli/index.js +71446 -6941
  2. package/dist/connectors/airtable-oauth.js +77 -3
  3. package/dist/connectors/airtable.js +85 -2
  4. package/dist/connectors/amplitude.js +85 -2
  5. package/dist/connectors/anthropic.js +85 -2
  6. package/dist/connectors/asana.js +86 -3
  7. package/dist/connectors/attio.js +85 -2
  8. package/dist/connectors/{microsoft-teams.d.ts → backlog-api-key.d.ts} +1 -1
  9. package/dist/connectors/backlog-api-key.js +592 -0
  10. package/dist/connectors/customerio.js +86 -3
  11. package/dist/connectors/dbt.js +85 -2
  12. package/dist/connectors/gemini.js +86 -3
  13. package/dist/connectors/gmail-oauth.js +78 -4
  14. package/dist/connectors/gmail.d.ts +5 -0
  15. package/dist/connectors/gmail.js +875 -0
  16. package/dist/connectors/google-ads-oauth.js +78 -4
  17. package/dist/connectors/google-ads.js +85 -2
  18. package/dist/connectors/google-analytics-oauth.js +90 -8
  19. package/dist/connectors/google-analytics.js +85 -2
  20. package/dist/connectors/google-calendar-oauth.d.ts +5 -0
  21. package/dist/connectors/google-calendar-oauth.js +817 -0
  22. package/dist/connectors/google-calendar.d.ts +5 -0
  23. package/dist/connectors/google-calendar.js +991 -0
  24. package/dist/connectors/google-sheets-oauth.js +144 -33
  25. package/dist/connectors/google-sheets.js +119 -10
  26. package/dist/connectors/{microsoft-teams-oauth.d.ts → grafana.d.ts} +1 -1
  27. package/dist/connectors/grafana.js +638 -0
  28. package/dist/connectors/hubspot-oauth.js +77 -3
  29. package/dist/connectors/hubspot.js +79 -5
  30. package/dist/connectors/intercom-oauth.js +78 -4
  31. package/dist/connectors/intercom.js +86 -3
  32. package/dist/connectors/jira-api-key.js +84 -9
  33. package/dist/connectors/kintone-api-token.js +77 -3
  34. package/dist/connectors/kintone.js +86 -3
  35. package/dist/connectors/linkedin-ads-oauth.js +78 -4
  36. package/dist/connectors/linkedin-ads.js +86 -3
  37. package/dist/connectors/mailchimp-oauth.js +77 -3
  38. package/dist/connectors/mailchimp.js +86 -3
  39. package/dist/connectors/notion-oauth.d.ts +5 -0
  40. package/dist/connectors/notion-oauth.js +567 -0
  41. package/dist/connectors/{slack.d.ts → notion.d.ts} +1 -1
  42. package/dist/connectors/notion.js +663 -0
  43. package/dist/connectors/openai.js +85 -2
  44. package/dist/connectors/shopify-oauth.js +77 -3
  45. package/dist/connectors/shopify.js +85 -2
  46. package/dist/connectors/stripe-api-key.d.ts +5 -0
  47. package/dist/connectors/stripe-api-key.js +600 -0
  48. package/dist/connectors/stripe-oauth.js +77 -3
  49. package/dist/connectors/wix-store.js +85 -2
  50. package/dist/connectors/zendesk-oauth.js +78 -4
  51. package/dist/connectors/zendesk.js +86 -3
  52. package/dist/index.js +75463 -8247
  53. package/dist/main.js +75191 -7975
  54. package/dist/vite-plugin.js +75300 -8121
  55. package/package.json +50 -2
  56. package/dist/connectors/microsoft-teams-oauth.js +0 -479
  57. package/dist/connectors/microsoft-teams.js +0 -381
  58. package/dist/connectors/slack.js +0 -362
@@ -0,0 +1,567 @@
1
+ // ../connectors/src/connectors/notion-oauth/sdk/index.ts
2
+ var BASE_URL = "https://api.notion.com/v1";
3
+ var NOTION_VERSION = "2022-06-28";
4
+ function createClient(_params, fetchFn = fetch) {
5
+ function request(path2, init) {
6
+ const url = `${BASE_URL}${path2.startsWith("/") ? "" : "/"}${path2}`;
7
+ const headers = new Headers(init?.headers);
8
+ headers.set("Notion-Version", NOTION_VERSION);
9
+ headers.set("Content-Type", "application/json");
10
+ return fetchFn(url, { ...init, headers });
11
+ }
12
+ return { request };
13
+ }
14
+
15
+ // ../connectors/src/connector-onboarding.ts
16
+ var ConnectorOnboarding = class {
17
+ /** Phase 1: Connection setup instructions (optional — some connectors don't need this) */
18
+ connectionSetupInstructions;
19
+ /** Phase 2: Data overview instructions */
20
+ dataOverviewInstructions;
21
+ constructor(config) {
22
+ this.connectionSetupInstructions = config.connectionSetupInstructions;
23
+ this.dataOverviewInstructions = config.dataOverviewInstructions;
24
+ }
25
+ getConnectionSetupPrompt(language) {
26
+ return this.connectionSetupInstructions?.[language] ?? null;
27
+ }
28
+ getDataOverviewInstructions(language) {
29
+ return this.dataOverviewInstructions[language];
30
+ }
31
+ };
32
+
33
+ // ../connectors/src/connector-tool.ts
34
+ var ConnectorTool = class {
35
+ name;
36
+ description;
37
+ inputSchema;
38
+ outputSchema;
39
+ _execute;
40
+ constructor(config) {
41
+ this.name = config.name;
42
+ this.description = config.description;
43
+ this.inputSchema = config.inputSchema;
44
+ this.outputSchema = config.outputSchema;
45
+ this._execute = config.execute;
46
+ }
47
+ createTool(connections, config) {
48
+ return {
49
+ description: this.description,
50
+ inputSchema: this.inputSchema,
51
+ outputSchema: this.outputSchema,
52
+ execute: (input) => this._execute(input, connections, config)
53
+ };
54
+ }
55
+ };
56
+
57
+ // ../connectors/src/connector-plugin.ts
58
+ var ConnectorPlugin = class _ConnectorPlugin {
59
+ slug;
60
+ authType;
61
+ name;
62
+ description;
63
+ iconUrl;
64
+ parameters;
65
+ releaseFlag;
66
+ proxyPolicy;
67
+ experimentalAttributes;
68
+ onboarding;
69
+ systemPrompt;
70
+ tools;
71
+ query;
72
+ checkConnection;
73
+ constructor(config) {
74
+ this.slug = config.slug;
75
+ this.authType = config.authType;
76
+ this.name = config.name;
77
+ this.description = config.description;
78
+ this.iconUrl = config.iconUrl;
79
+ this.parameters = config.parameters;
80
+ this.releaseFlag = config.releaseFlag;
81
+ this.proxyPolicy = config.proxyPolicy;
82
+ this.experimentalAttributes = config.experimentalAttributes;
83
+ this.onboarding = config.onboarding;
84
+ this.systemPrompt = config.systemPrompt;
85
+ this.tools = config.tools;
86
+ this.query = config.query;
87
+ this.checkConnection = config.checkConnection;
88
+ }
89
+ get connectorKey() {
90
+ return _ConnectorPlugin.deriveKey(this.slug, this.authType);
91
+ }
92
+ /**
93
+ * Create tools for connections that belong to this connector.
94
+ * Filters connections by connectorKey internally.
95
+ * Returns tools keyed as `${connectorKey}_${toolName}`.
96
+ */
97
+ createTools(connections, config) {
98
+ const myConnections = connections.filter(
99
+ (c) => _ConnectorPlugin.deriveKey(c.connector.slug, c.connector.authType) === this.connectorKey
100
+ );
101
+ const result = {};
102
+ for (const t of Object.values(this.tools)) {
103
+ result[`${this.connectorKey}_${t.name}`] = t.createTool(
104
+ myConnections,
105
+ config
106
+ );
107
+ }
108
+ return result;
109
+ }
110
+ static deriveKey(slug, authType) {
111
+ return authType ? `${slug}-${authType}` : slug;
112
+ }
113
+ };
114
+
115
+ // ../connectors/src/auth-types.ts
116
+ var AUTH_TYPES = {
117
+ OAUTH: "oauth",
118
+ API_KEY: "api-key",
119
+ JWT: "jwt",
120
+ SERVICE_ACCOUNT: "service-account",
121
+ PAT: "pat",
122
+ USER_PASSWORD: "user-password"
123
+ };
124
+
125
+ // ../connectors/src/connectors/notion-oauth/tools/request.ts
126
+ import { z } from "zod";
127
+ var BASE_URL2 = "https://api.notion.com/v1";
128
+ var NOTION_VERSION2 = "2022-06-28";
129
+ var REQUEST_TIMEOUT_MS = 6e4;
130
+ var cachedToken = null;
131
+ async function getProxyToken(config) {
132
+ if (cachedToken && cachedToken.expiresAt > Date.now() + 6e4) {
133
+ return cachedToken.token;
134
+ }
135
+ const url = `${config.appApiBaseUrl}/v0/database/${config.projectId}/environment/${config.environmentId}/oauth-request-proxy-token`;
136
+ const res = await fetch(url, {
137
+ method: "POST",
138
+ headers: {
139
+ "Content-Type": "application/json",
140
+ "x-api-key": config.appApiKey,
141
+ "project-id": config.projectId
142
+ },
143
+ body: JSON.stringify({
144
+ sandboxId: config.sandboxId,
145
+ issuedBy: "coding-agent"
146
+ })
147
+ });
148
+ if (!res.ok) {
149
+ const errorText = await res.text().catch(() => res.statusText);
150
+ throw new Error(
151
+ `Failed to get proxy token: HTTP ${res.status} ${errorText}`
152
+ );
153
+ }
154
+ const data = await res.json();
155
+ cachedToken = {
156
+ token: data.token,
157
+ expiresAt: new Date(data.expiresAt).getTime()
158
+ };
159
+ return data.token;
160
+ }
161
+ var inputSchema = z.object({
162
+ toolUseIntent: z.string().optional().describe(
163
+ "Brief description of what you intend to accomplish with this tool call"
164
+ ),
165
+ connectionId: z.string().describe("ID of the Notion OAuth connection to use"),
166
+ method: z.enum(["GET", "POST", "PATCH", "DELETE"]).describe("HTTP method"),
167
+ path: z.string().describe(
168
+ "API path appended to https://api.notion.com/v1 (e.g., '/search', '/databases/{id}/query', '/pages/{id}')"
169
+ ),
170
+ body: z.record(z.string(), z.unknown()).optional().describe("Request body (JSON) for POST/PATCH requests")
171
+ });
172
+ var outputSchema = z.discriminatedUnion("success", [
173
+ z.object({
174
+ success: z.literal(true),
175
+ status: z.number(),
176
+ data: z.record(z.string(), z.unknown())
177
+ }),
178
+ z.object({
179
+ success: z.literal(false),
180
+ error: z.string()
181
+ })
182
+ ]);
183
+ var requestTool = new ConnectorTool({
184
+ name: "request",
185
+ description: `Send authenticated requests to the Notion API.
186
+ Authentication is handled automatically via OAuth proxy. Notion-Version header is set automatically.
187
+ Use this tool for all Notion API interactions: searching pages/databases, querying databases, retrieving pages and blocks, managing content.
188
+ Pagination uses cursor-based start_cursor and page_size (max 100).`,
189
+ inputSchema,
190
+ outputSchema,
191
+ async execute({ connectionId, method, path: path2, body }, connections, config) {
192
+ const connection2 = connections.find((c) => c.id === connectionId);
193
+ if (!connection2) {
194
+ return {
195
+ success: false,
196
+ error: `Connection ${connectionId} not found`
197
+ };
198
+ }
199
+ console.log(
200
+ `[connector-request] notion-oauth/${connection2.name}: ${method} ${path2}`
201
+ );
202
+ try {
203
+ const url = `${BASE_URL2}${path2.startsWith("/") ? "" : "/"}${path2}`;
204
+ const token = await getProxyToken(config.oauthProxy);
205
+ const proxyUrl = `https://${config.oauthProxy.sandboxId}.${config.oauthProxy.previewBaseDomain}/_sqcore/connections/${connectionId}/request`;
206
+ const controller = new AbortController();
207
+ const timeout = setTimeout(() => controller.abort(), REQUEST_TIMEOUT_MS);
208
+ try {
209
+ const response = await fetch(proxyUrl, {
210
+ method: "POST",
211
+ headers: {
212
+ "Content-Type": "application/json",
213
+ Authorization: `Bearer ${token}`
214
+ },
215
+ body: JSON.stringify({
216
+ url,
217
+ method,
218
+ headers: { "Notion-Version": NOTION_VERSION2 },
219
+ body: body ? JSON.stringify(body) : void 0
220
+ }),
221
+ signal: controller.signal
222
+ });
223
+ const data = await response.json();
224
+ if (!response.ok) {
225
+ const errorMessage = typeof data?.message === "string" ? data.message : typeof data?.code === "string" ? data.code : typeof data?.error === "string" ? data.error : `HTTP ${response.status} ${response.statusText}`;
226
+ return { success: false, error: errorMessage };
227
+ }
228
+ return { success: true, status: response.status, data };
229
+ } finally {
230
+ clearTimeout(timeout);
231
+ }
232
+ } catch (err) {
233
+ const msg = err instanceof Error ? err.message : String(err);
234
+ return { success: false, error: msg };
235
+ }
236
+ }
237
+ });
238
+
239
+ // ../connectors/src/connectors/notion-oauth/setup.ts
240
+ var requestToolName = `notion-oauth_${requestTool.name}`;
241
+ var notionOauthOnboarding = new ConnectorOnboarding({
242
+ connectionSetupInstructions: {
243
+ ja: `\u4EE5\u4E0B\u306E\u624B\u9806\u3067Notion\u30B3\u30CD\u30AF\u30B7\u30E7\u30F3\u306E\u30BB\u30C3\u30C8\u30A2\u30C3\u30D7\u3092\u884C\u3063\u3066\u304F\u3060\u3055\u3044\u3002
244
+
245
+ 1. \`${requestToolName}\` \u3092\u547C\u3073\u51FA\u3057\u3066\u3001\u30DC\u30C3\u30C8\u30E6\u30FC\u30B6\u30FC\u60C5\u5831\u3092\u53D6\u5F97\u3059\u308B:
246
+ - \`method\`: \`"GET"\`
247
+ - \`path\`: \`"/users/me"\`
248
+ 2. \u30A8\u30E9\u30FC\u304C\u8FD4\u3055\u308C\u305F\u5834\u5408\u3001\u30E6\u30FC\u30B6\u30FC\u306BOAuth\u63A5\u7D9A\u306E\u8A2D\u5B9A\u3092\u78BA\u8A8D\u3059\u308B\u3088\u3046\u4F1D\u3048\u308B
249
+ 3. \`updateConnectionContext\` \u3092\u547C\u3073\u51FA\u3059:
250
+ - \`account\`: Notion\u30EF\u30FC\u30AF\u30B9\u30DA\u30FC\u30B9\u540D\u307E\u305F\u306F\u30DC\u30C3\u30C8\u540D
251
+ - \`note\`: \u30BB\u30C3\u30C8\u30A2\u30C3\u30D7\u5185\u5BB9\u306E\u7C21\u5358\u306A\u8AAC\u660E
252
+
253
+ #### \u5236\u7D04
254
+ - **\u30BB\u30C3\u30C8\u30A2\u30C3\u30D7\u4E2D\u306B\u30D3\u30B8\u30CD\u30B9\u30C7\u30FC\u30BF\u3092\u8AAD\u307F\u53D6\u3089\u306A\u3044\u3053\u3068**\u3002\u5B9F\u884C\u3057\u3066\u3088\u3044\u306E\u306F\u4E0A\u8A18\u624B\u9806\u3067\u6307\u5B9A\u3055\u308C\u305F\u30E1\u30BF\u30C7\u30FC\u30BF\u53D6\u5F97\u30EA\u30AF\u30A8\u30B9\u30C8\u306E\u307F
255
+ - \u30C4\u30FC\u30EB\u9593\u306F1\u6587\u3060\u3051\u66F8\u3044\u3066\u5373\u6B21\u306E\u30C4\u30FC\u30EB\u547C\u3073\u51FA\u3057\u3002\u4E0D\u8981\u306A\u8AAC\u660E\u306F\u7701\u7565\u3057\u3001\u52B9\u7387\u7684\u306B\u9032\u3081\u308B`,
256
+ en: `Follow these steps to set up the Notion connection.
257
+
258
+ 1. Call \`${requestToolName}\` to fetch bot user info:
259
+ - \`method\`: \`"GET"\`
260
+ - \`path\`: \`"/users/me"\`
261
+ 2. If an error is returned, ask the user to check the OAuth connection settings
262
+ 3. Call \`updateConnectionContext\`:
263
+ - \`account\`: Notion workspace name or bot name
264
+ - \`note\`: Brief description of the setup
265
+
266
+ #### Constraints
267
+ - **Do NOT read business data during setup**. Only the metadata request specified in the steps above is allowed
268
+ - Write only 1 sentence between tool calls, then immediately call the next tool. Skip unnecessary explanations and proceed efficiently`
269
+ },
270
+ dataOverviewInstructions: {
271
+ en: `1. Call notion-oauth_request with POST /search and { "page_size": 5 } to discover available pages and databases
272
+ 2. For each database found, call notion-oauth_request with POST /databases/{database_id}/query and { "page_size": 5 } to sample records
273
+ 3. Call notion-oauth_request with GET /users to list workspace members
274
+ 4. Explore page content with GET /blocks/{page_id}/children as needed`,
275
+ ja: `1. notion-oauth_request \u3067 POST /search \u3092 { "page_size": 5 } \u3067\u547C\u3073\u51FA\u3057\u3001\u5229\u7528\u53EF\u80FD\u306A\u30DA\u30FC\u30B8\u3068\u30C7\u30FC\u30BF\u30D9\u30FC\u30B9\u3092\u691C\u51FA
276
+ 2. \u898B\u3064\u304B\u3063\u305F\u5404\u30C7\u30FC\u30BF\u30D9\u30FC\u30B9\u306B\u3064\u3044\u3066\u3001notion-oauth_request \u3067 POST /databases/{database_id}/query \u3092 { "page_size": 5 } \u3067\u547C\u3073\u51FA\u3057\u3001\u30EC\u30B3\u30FC\u30C9\u3092\u30B5\u30F3\u30D7\u30EA\u30F3\u30B0
277
+ 3. notion-oauth_request \u3067 GET /users \u3092\u547C\u3073\u51FA\u3057\u3001\u30EF\u30FC\u30AF\u30B9\u30DA\u30FC\u30B9\u30E1\u30F3\u30D0\u30FC\u3092\u4E00\u89A7\u8868\u793A
278
+ 4. \u5FC5\u8981\u306B\u5FDC\u3058\u3066 GET /blocks/{page_id}/children \u3067\u30DA\u30FC\u30B8\u30B3\u30F3\u30C6\u30F3\u30C4\u3092\u63A2\u7D22`
279
+ }
280
+ });
281
+
282
+ // ../connectors/src/connectors/notion-oauth/parameters.ts
283
+ var parameters = {};
284
+
285
+ // ../connectors/src/connectors/notion-oauth/index.ts
286
+ var tools = { request: requestTool };
287
+ var notionOauthConnector = new ConnectorPlugin({
288
+ slug: "notion",
289
+ authType: AUTH_TYPES.OAUTH,
290
+ name: "Notion",
291
+ description: "Connect to Notion to query databases, pages, and workspace content using OAuth.",
292
+ iconUrl: "https://images.ctfassets.net/9ncizv60xc5y/797V5GDDTA8bsfKUHBCoQO/290ec49b70b68ddb4acd3bf0a6ab8bda/notion-icon.webp",
293
+ parameters,
294
+ releaseFlag: { dev1: true, dev2: false, prod: false },
295
+ onboarding: notionOauthOnboarding,
296
+ proxyPolicy: {
297
+ allowlist: [
298
+ {
299
+ host: "api.notion.com",
300
+ methods: ["GET", "POST", "PATCH", "DELETE"]
301
+ }
302
+ ]
303
+ },
304
+ systemPrompt: {
305
+ en: `### Tools
306
+
307
+ - \`notion-oauth_request\`: The only way to call the Notion API. Use it to search pages and databases, query database records, retrieve page content and blocks, and manage workspace data. Authentication is configured automatically via OAuth. Notion-Version header is set automatically. Pagination uses cursor-based \`start_cursor\` and \`page_size\` (max 100) with \`has_more\` and \`next_cursor\` in the response.
308
+
309
+ ### Notion API Reference
310
+
311
+ #### Available Endpoints
312
+ - POST \`/search\` \u2014 Search pages and databases by title. Body: \`{ query, filter: { property: "object", value: "page"|"database" }, sort, start_cursor, page_size }\`
313
+ - GET \`/databases/{id}\` \u2014 Retrieve a database (schema, properties)
314
+ - POST \`/databases/{id}/query\` \u2014 Query a database. Body: \`{ filter, sorts, start_cursor, page_size }\`
315
+ - GET \`/pages/{id}\` \u2014 Retrieve a page (properties, metadata)
316
+ - GET \`/pages/{id}/properties/{property_id}\` \u2014 Retrieve a specific page property
317
+ - GET \`/blocks/{id}/children\` \u2014 List child blocks (page content). Query: \`start_cursor\`, \`page_size\`
318
+ - GET \`/blocks/{id}\` \u2014 Retrieve a single block
319
+ - PATCH \`/blocks/{id}/children\` \u2014 Append block children
320
+ - GET \`/users\` \u2014 List workspace users
321
+ - GET \`/users/{id}\` \u2014 Retrieve a user
322
+ - GET \`/users/me\` \u2014 Get the bot user
323
+ - POST \`/pages\` \u2014 Create a page
324
+ - PATCH \`/pages/{id}\` \u2014 Update page properties
325
+ - POST \`/databases\` \u2014 Create a database
326
+ - PATCH \`/databases/{id}\` \u2014 Update a database
327
+ - DELETE \`/blocks/{id}\` \u2014 Delete a block
328
+ - GET \`/comments?block_id={id}\` \u2014 Retrieve comments
329
+ - POST \`/comments\` \u2014 Create a comment
330
+
331
+ ### Tips
332
+ - Use POST /search to discover databases and pages accessible via OAuth
333
+ - Database queries return page objects with properties matching the database schema
334
+ - Block children are only first-level; recurse for nested content
335
+ - Pagination: max page_size is 100, use start_cursor from next_cursor for subsequent pages
336
+
337
+ ### Business Logic
338
+
339
+ The business logic type for this connector is "typescript". Write handler code using the connector SDK shown below. Do NOT access credentials directly from environment variables.
340
+
341
+ #### Example
342
+
343
+ \`\`\`ts
344
+ import { connection } from "@squadbase/vite-server/connectors/notion-oauth";
345
+
346
+ const notion = connection("<connectionId>");
347
+
348
+ // Authenticated fetch (returns standard Response)
349
+ const res = await notion.request("/search", {
350
+ method: "POST",
351
+ body: JSON.stringify({ query: "Project", page_size: 10 }),
352
+ });
353
+ const data = await res.json();
354
+ \`\`\``,
355
+ ja: `### \u30C4\u30FC\u30EB
356
+
357
+ - \`notion-oauth_request\`: Notion API\u3092\u547C\u3073\u51FA\u3059\u552F\u4E00\u306E\u624B\u6BB5\u3067\u3059\u3002\u30DA\u30FC\u30B8\u3084\u30C7\u30FC\u30BF\u30D9\u30FC\u30B9\u306E\u691C\u7D22\u3001\u30C7\u30FC\u30BF\u30D9\u30FC\u30B9\u30EC\u30B3\u30FC\u30C9\u306E\u30AF\u30A8\u30EA\u3001\u30DA\u30FC\u30B8\u30B3\u30F3\u30C6\u30F3\u30C4\u3084\u30D6\u30ED\u30C3\u30AF\u306E\u53D6\u5F97\u3001\u30EF\u30FC\u30AF\u30B9\u30DA\u30FC\u30B9\u30C7\u30FC\u30BF\u306E\u7BA1\u7406\u306B\u4F7F\u7528\u3057\u307E\u3059\u3002OAuth\u7D4C\u7531\u3067\u8A8D\u8A3C\u306F\u81EA\u52D5\u8A2D\u5B9A\u3055\u308C\u307E\u3059\u3002Notion-Version\u30D8\u30C3\u30C0\u30FC\u3082\u81EA\u52D5\u8A2D\u5B9A\u3055\u308C\u307E\u3059\u3002\u30DA\u30FC\u30B8\u30CD\u30FC\u30B7\u30E7\u30F3\u306F\u30EC\u30B9\u30DD\u30F3\u30B9\u306E \`has_more\` \u3068 \`next_cursor\` \u306B\u3088\u308B\u30AB\u30FC\u30BD\u30EB\u30D9\u30FC\u30B9\u3067\u3001\`start_cursor\` \u3068 \`page_size\`\uFF08\u6700\u5927100\uFF09\u3092\u4F7F\u7528\u3057\u307E\u3059\u3002
358
+
359
+ ### Notion API \u30EA\u30D5\u30A1\u30EC\u30F3\u30B9
360
+
361
+ #### \u5229\u7528\u53EF\u80FD\u306A\u30A8\u30F3\u30C9\u30DD\u30A4\u30F3\u30C8
362
+ - POST \`/search\` \u2014 \u30DA\u30FC\u30B8\u3068\u30C7\u30FC\u30BF\u30D9\u30FC\u30B9\u3092\u30BF\u30A4\u30C8\u30EB\u3067\u691C\u7D22\u3002Body: \`{ query, filter: { property: "object", value: "page"|"database" }, sort, start_cursor, page_size }\`
363
+ - GET \`/databases/{id}\` \u2014 \u30C7\u30FC\u30BF\u30D9\u30FC\u30B9\u3092\u53D6\u5F97\uFF08\u30B9\u30AD\u30FC\u30DE\u3001\u30D7\u30ED\u30D1\u30C6\u30A3\uFF09
364
+ - POST \`/databases/{id}/query\` \u2014 \u30C7\u30FC\u30BF\u30D9\u30FC\u30B9\u3092\u30AF\u30A8\u30EA\u3002Body: \`{ filter, sorts, start_cursor, page_size }\`
365
+ - GET \`/pages/{id}\` \u2014 \u30DA\u30FC\u30B8\u3092\u53D6\u5F97\uFF08\u30D7\u30ED\u30D1\u30C6\u30A3\u3001\u30E1\u30BF\u30C7\u30FC\u30BF\uFF09
366
+ - GET \`/pages/{id}/properties/{property_id}\` \u2014 \u7279\u5B9A\u306E\u30DA\u30FC\u30B8\u30D7\u30ED\u30D1\u30C6\u30A3\u3092\u53D6\u5F97
367
+ - GET \`/blocks/{id}/children\` \u2014 \u5B50\u30D6\u30ED\u30C3\u30AF\u3092\u4E00\u89A7\u8868\u793A\uFF08\u30DA\u30FC\u30B8\u30B3\u30F3\u30C6\u30F3\u30C4\uFF09\u3002Query: \`start_cursor\`, \`page_size\`
368
+ - GET \`/blocks/{id}\` \u2014 \u5358\u4E00\u30D6\u30ED\u30C3\u30AF\u3092\u53D6\u5F97
369
+ - PATCH \`/blocks/{id}/children\` \u2014 \u5B50\u30D6\u30ED\u30C3\u30AF\u3092\u8FFD\u52A0
370
+ - GET \`/users\` \u2014 \u30EF\u30FC\u30AF\u30B9\u30DA\u30FC\u30B9\u30E6\u30FC\u30B6\u30FC\u3092\u4E00\u89A7\u8868\u793A
371
+ - GET \`/users/{id}\` \u2014 \u30E6\u30FC\u30B6\u30FC\u3092\u53D6\u5F97
372
+ - GET \`/users/me\` \u2014 \u30DC\u30C3\u30C8\u30E6\u30FC\u30B6\u30FC\u3092\u53D6\u5F97
373
+ - POST \`/pages\` \u2014 \u30DA\u30FC\u30B8\u3092\u4F5C\u6210
374
+ - PATCH \`/pages/{id}\` \u2014 \u30DA\u30FC\u30B8\u30D7\u30ED\u30D1\u30C6\u30A3\u3092\u66F4\u65B0
375
+ - POST \`/databases\` \u2014 \u30C7\u30FC\u30BF\u30D9\u30FC\u30B9\u3092\u4F5C\u6210
376
+ - PATCH \`/databases/{id}\` \u2014 \u30C7\u30FC\u30BF\u30D9\u30FC\u30B9\u3092\u66F4\u65B0
377
+ - DELETE \`/blocks/{id}\` \u2014 \u30D6\u30ED\u30C3\u30AF\u3092\u524A\u9664
378
+ - GET \`/comments?block_id={id}\` \u2014 \u30B3\u30E1\u30F3\u30C8\u3092\u53D6\u5F97
379
+ - POST \`/comments\` \u2014 \u30B3\u30E1\u30F3\u30C8\u3092\u4F5C\u6210
380
+
381
+ ### \u30D2\u30F3\u30C8
382
+ - POST /search \u3092\u4F7F\u7528\u3057\u3066OAuth\u7D4C\u7531\u3067\u30A2\u30AF\u30BB\u30B9\u53EF\u80FD\u306A\u30C7\u30FC\u30BF\u30D9\u30FC\u30B9\u3084\u30DA\u30FC\u30B8\u3092\u691C\u51FA\u3057\u307E\u3059
383
+ - \u30C7\u30FC\u30BF\u30D9\u30FC\u30B9\u30AF\u30A8\u30EA\u306F\u30C7\u30FC\u30BF\u30D9\u30FC\u30B9\u30B9\u30AD\u30FC\u30DE\u306B\u4E00\u81F4\u3059\u308B\u30D7\u30ED\u30D1\u30C6\u30A3\u3092\u6301\u3064\u30DA\u30FC\u30B8\u30AA\u30D6\u30B8\u30A7\u30AF\u30C8\u3092\u8FD4\u3057\u307E\u3059
384
+ - \u30D6\u30ED\u30C3\u30AF\u306E\u5B50\u306F\u6700\u521D\u306E\u30EC\u30D9\u30EB\u306E\u307F\u3067\u3059\u3002\u30CD\u30B9\u30C8\u3055\u308C\u305F\u30B3\u30F3\u30C6\u30F3\u30C4\u306B\u306F\u518D\u5E30\u304C\u5FC5\u8981\u3067\u3059
385
+ - \u30DA\u30FC\u30B8\u30CD\u30FC\u30B7\u30E7\u30F3: \u6700\u5927page_size\u306F100\u3001\u5F8C\u7D9A\u30DA\u30FC\u30B8\u306B\u306Fnext_cursor\u304B\u3089start_cursor\u3092\u4F7F\u7528\u3057\u307E\u3059
386
+
387
+ ### Business Logic
388
+
389
+ \u3053\u306E\u30B3\u30CD\u30AF\u30BF\u306E\u30D3\u30B8\u30CD\u30B9\u30ED\u30B8\u30C3\u30AF\u30BF\u30A4\u30D7\u306F "typescript" \u3067\u3059\u3002\u4EE5\u4E0B\u306B\u793A\u3059\u30B3\u30CD\u30AF\u30BFSDK\u3092\u4F7F\u7528\u3057\u3066\u30CF\u30F3\u30C9\u30E9\u30B3\u30FC\u30C9\u3092\u8A18\u8FF0\u3057\u3066\u304F\u3060\u3055\u3044\u3002\u74B0\u5883\u5909\u6570\u304B\u3089\u76F4\u63A5\u8A8D\u8A3C\u60C5\u5831\u306B\u30A2\u30AF\u30BB\u30B9\u3057\u306A\u3044\u3067\u304F\u3060\u3055\u3044\u3002
390
+
391
+ #### Example
392
+
393
+ \`\`\`ts
394
+ import { connection } from "@squadbase/vite-server/connectors/notion-oauth";
395
+
396
+ const notion = connection("<connectionId>");
397
+
398
+ // Authenticated fetch (returns standard Response)
399
+ const res = await notion.request("/search", {
400
+ method: "POST",
401
+ body: JSON.stringify({ query: "Project", page_size: 10 }),
402
+ });
403
+ const data = await res.json();
404
+ \`\`\``
405
+ },
406
+ tools,
407
+ async checkConnection(_params, config) {
408
+ const { proxyFetch } = config;
409
+ try {
410
+ const res = await proxyFetch("https://api.notion.com/v1/users/me", {
411
+ method: "GET",
412
+ headers: { "Notion-Version": "2022-06-28" }
413
+ });
414
+ if (!res.ok) {
415
+ const errorText = await res.text().catch(() => res.statusText);
416
+ return {
417
+ success: false,
418
+ error: `Notion API failed: HTTP ${res.status} ${errorText}`
419
+ };
420
+ }
421
+ return { success: true };
422
+ } catch (error) {
423
+ return {
424
+ success: false,
425
+ error: error instanceof Error ? error.message : String(error)
426
+ };
427
+ }
428
+ }
429
+ });
430
+
431
+ // src/connectors/create-connector-sdk.ts
432
+ import { readFileSync } from "fs";
433
+ import path from "path";
434
+
435
+ // src/connector-client/env.ts
436
+ function resolveEnvVar(entry, key, connectionId) {
437
+ const envVarName = entry.envVars[key];
438
+ if (!envVarName) {
439
+ throw new Error(`Connection "${connectionId}" is missing envVars mapping for key "${key}"`);
440
+ }
441
+ const value = process.env[envVarName];
442
+ if (!value) {
443
+ throw new Error(`Environment variable "${envVarName}" (for connection "${connectionId}", key "${key}") is not set`);
444
+ }
445
+ return value;
446
+ }
447
+ function resolveEnvVarOptional(entry, key) {
448
+ const envVarName = entry.envVars[key];
449
+ if (!envVarName) return void 0;
450
+ return process.env[envVarName] || void 0;
451
+ }
452
+
453
+ // src/connector-client/proxy-fetch.ts
454
+ import { getContext } from "hono/context-storage";
455
+ import { getCookie } from "hono/cookie";
456
+ var APP_SESSION_COOKIE_NAME = "__Host-squadbase-session";
457
+ function createSandboxProxyFetch(connectionId) {
458
+ return async (input, init) => {
459
+ const token = process.env.INTERNAL_SQUADBASE_OAUTH_MACHINE_CREDENTIAL;
460
+ const sandboxId = process.env.INTERNAL_SQUADBASE_SANDBOX_ID;
461
+ if (!token || !sandboxId) {
462
+ throw new Error(
463
+ "Connection proxy is not configured. Please check your deployment settings."
464
+ );
465
+ }
466
+ const originalUrl = typeof input === "string" ? input : input instanceof URL ? input.href : input.url;
467
+ const originalMethod = init?.method ?? "GET";
468
+ const originalBody = init?.body ? JSON.parse(init.body) : void 0;
469
+ const baseDomain = process.env["SQUADBASE_PREVIEW_BASE_DOMAIN"] ?? "preview.app.squadbase.dev";
470
+ const proxyUrl = `https://${sandboxId}.${baseDomain}/_sqcore/connections/${connectionId}/request`;
471
+ return fetch(proxyUrl, {
472
+ method: "POST",
473
+ headers: {
474
+ "Content-Type": "application/json",
475
+ Authorization: `Bearer ${token}`
476
+ },
477
+ body: JSON.stringify({
478
+ url: originalUrl,
479
+ method: originalMethod,
480
+ body: originalBody
481
+ })
482
+ });
483
+ };
484
+ }
485
+ function createDeployedAppProxyFetch(connectionId) {
486
+ const projectId = process.env["SQUADBASE_PROJECT_ID"];
487
+ if (!projectId) {
488
+ throw new Error(
489
+ "Connection proxy is not configured. Please check your deployment settings."
490
+ );
491
+ }
492
+ const baseDomain = process.env["SQUADBASE_APP_BASE_DOMAIN"] ?? "squadbase.app";
493
+ const proxyUrl = `https://${projectId}.${baseDomain}/_sqcore/connections/${connectionId}/request`;
494
+ return async (input, init) => {
495
+ const originalUrl = typeof input === "string" ? input : input instanceof URL ? input.href : input.url;
496
+ const originalMethod = init?.method ?? "GET";
497
+ const originalBody = init?.body ? JSON.parse(init.body) : void 0;
498
+ const c = getContext();
499
+ const appSession = getCookie(c, APP_SESSION_COOKIE_NAME);
500
+ if (!appSession) {
501
+ throw new Error(
502
+ "No authentication method available for connection proxy."
503
+ );
504
+ }
505
+ return fetch(proxyUrl, {
506
+ method: "POST",
507
+ headers: {
508
+ "Content-Type": "application/json",
509
+ Authorization: `Bearer ${appSession}`
510
+ },
511
+ body: JSON.stringify({
512
+ url: originalUrl,
513
+ method: originalMethod,
514
+ body: originalBody
515
+ })
516
+ });
517
+ };
518
+ }
519
+ function createProxyFetch(connectionId) {
520
+ if (process.env.INTERNAL_SQUADBASE_SANDBOX_ID) {
521
+ return createSandboxProxyFetch(connectionId);
522
+ }
523
+ return createDeployedAppProxyFetch(connectionId);
524
+ }
525
+
526
+ // src/connectors/create-connector-sdk.ts
527
+ function loadConnectionsSync() {
528
+ const filePath = process.env.CONNECTIONS_PATH ?? path.join(process.cwd(), ".squadbase/connections.json");
529
+ try {
530
+ const raw = readFileSync(filePath, "utf-8");
531
+ return JSON.parse(raw);
532
+ } catch {
533
+ return {};
534
+ }
535
+ }
536
+ function createConnectorSdk(plugin, createClient2) {
537
+ return (connectionId) => {
538
+ const connections = loadConnectionsSync();
539
+ const entry = connections[connectionId];
540
+ if (!entry) {
541
+ throw new Error(
542
+ `Connection "${connectionId}" not found in .squadbase/connections.json`
543
+ );
544
+ }
545
+ if (entry.connector.slug !== plugin.slug) {
546
+ throw new Error(
547
+ `Connection "${connectionId}" is not a ${plugin.slug} connection (got "${entry.connector.slug}")`
548
+ );
549
+ }
550
+ const params = {};
551
+ for (const param of Object.values(plugin.parameters)) {
552
+ if (param.required) {
553
+ params[param.slug] = resolveEnvVar(entry, param.slug, connectionId);
554
+ } else {
555
+ const val = resolveEnvVarOptional(entry, param.slug);
556
+ if (val !== void 0) params[param.slug] = val;
557
+ }
558
+ }
559
+ return createClient2(params, createProxyFetch(connectionId));
560
+ };
561
+ }
562
+
563
+ // src/connectors/entries/notion-oauth.ts
564
+ var connection = createConnectorSdk(notionOauthConnector, createClient);
565
+ export {
566
+ connection
567
+ };
@@ -1,5 +1,5 @@
1
1
  import * as _squadbase_connectors_sdk from '@squadbase/connectors/sdk';
2
2
 
3
- declare const connection: (connectionId: string) => _squadbase_connectors_sdk.SlackConnectorSdk;
3
+ declare const connection: (connectionId: string) => _squadbase_connectors_sdk.NotionConnectorSdk;
4
4
 
5
5
  export { connection };