@squadbase/vite-server 0.1.3-dev.1 → 0.1.3-dev.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.
Files changed (56) hide show
  1. package/dist/cli/index.js +71031 -6800
  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/customerio.js +86 -3
  9. package/dist/connectors/dbt.js +85 -2
  10. package/dist/connectors/gemini.js +86 -3
  11. package/dist/connectors/gmail-oauth.js +78 -4
  12. package/dist/connectors/gmail.d.ts +5 -0
  13. package/dist/connectors/gmail.js +875 -0
  14. package/dist/connectors/google-ads-oauth.js +78 -4
  15. package/dist/connectors/google-ads.js +85 -2
  16. package/dist/connectors/google-analytics-oauth.js +90 -8
  17. package/dist/connectors/google-analytics.js +85 -2
  18. package/dist/connectors/google-calendar-oauth.d.ts +5 -0
  19. package/dist/connectors/google-calendar-oauth.js +817 -0
  20. package/dist/connectors/google-calendar.d.ts +5 -0
  21. package/dist/connectors/google-calendar.js +991 -0
  22. package/dist/connectors/google-sheets-oauth.js +144 -33
  23. package/dist/connectors/google-sheets.js +119 -10
  24. package/dist/connectors/{microsoft-teams.d.ts → grafana.d.ts} +1 -1
  25. package/dist/connectors/grafana.js +638 -0
  26. package/dist/connectors/hubspot-oauth.js +77 -3
  27. package/dist/connectors/hubspot.js +79 -5
  28. package/dist/connectors/intercom-oauth.js +78 -4
  29. package/dist/connectors/intercom.js +86 -3
  30. package/dist/connectors/jira-api-key.js +84 -9
  31. package/dist/connectors/kintone-api-token.js +77 -3
  32. package/dist/connectors/kintone.js +86 -3
  33. package/dist/connectors/linkedin-ads-oauth.js +78 -4
  34. package/dist/connectors/linkedin-ads.js +86 -3
  35. package/dist/connectors/mailchimp-oauth.js +77 -3
  36. package/dist/connectors/mailchimp.js +86 -3
  37. package/dist/connectors/{microsoft-teams-oauth.d.ts → notion-oauth.d.ts} +1 -1
  38. package/dist/connectors/notion-oauth.js +567 -0
  39. package/dist/connectors/{slack.d.ts → notion.d.ts} +1 -1
  40. package/dist/connectors/notion.js +663 -0
  41. package/dist/connectors/openai.js +85 -2
  42. package/dist/connectors/shopify-oauth.js +77 -3
  43. package/dist/connectors/shopify.js +85 -2
  44. package/dist/connectors/stripe-api-key.d.ts +5 -0
  45. package/dist/connectors/stripe-api-key.js +600 -0
  46. package/dist/connectors/stripe-oauth.js +77 -3
  47. package/dist/connectors/wix-store.js +85 -2
  48. package/dist/connectors/zendesk-oauth.js +78 -4
  49. package/dist/connectors/zendesk.js +86 -3
  50. package/dist/index.js +75373 -8431
  51. package/dist/main.js +75359 -8417
  52. package/dist/vite-plugin.js +75210 -8305
  53. package/package.json +46 -2
  54. package/dist/connectors/microsoft-teams-oauth.js +0 -479
  55. package/dist/connectors/microsoft-teams.js +0 -381
  56. package/dist/connectors/slack.js +0 -362
@@ -0,0 +1,600 @@
1
+ // ../connectors/src/parameter-definition.ts
2
+ var ParameterDefinition = class {
3
+ slug;
4
+ name;
5
+ description;
6
+ envVarBaseKey;
7
+ type;
8
+ secret;
9
+ required;
10
+ constructor(config) {
11
+ this.slug = config.slug;
12
+ this.name = config.name;
13
+ this.description = config.description;
14
+ this.envVarBaseKey = config.envVarBaseKey;
15
+ this.type = config.type;
16
+ this.secret = config.secret;
17
+ this.required = config.required;
18
+ }
19
+ /**
20
+ * Get the parameter value from a ConnectorConnectionObject.
21
+ */
22
+ getValue(connection2) {
23
+ const param = connection2.parameters.find(
24
+ (p) => p.parameterSlug === this.slug
25
+ );
26
+ if (!param || param.value == null) {
27
+ throw new Error(
28
+ `Parameter "${this.slug}" not found or has no value in connection "${connection2.id}"`
29
+ );
30
+ }
31
+ return param.value;
32
+ }
33
+ /**
34
+ * Try to get the parameter value. Returns undefined if not found (for optional params).
35
+ */
36
+ tryGetValue(connection2) {
37
+ const param = connection2.parameters.find(
38
+ (p) => p.parameterSlug === this.slug
39
+ );
40
+ if (!param || param.value == null) return void 0;
41
+ return param.value;
42
+ }
43
+ };
44
+
45
+ // ../connectors/src/connectors/stripe-api-key/parameters.ts
46
+ var parameters = {
47
+ apiKey: new ParameterDefinition({
48
+ slug: "api-key",
49
+ name: "Stripe API Key",
50
+ description: "Your Stripe Secret API Key (sk_live_... / sk_test_...) or Restricted API Key (rk_live_... / rk_test_...).",
51
+ envVarBaseKey: "STRIPE_API_KEY",
52
+ type: "text",
53
+ secret: true,
54
+ required: true
55
+ })
56
+ };
57
+
58
+ // ../connectors/src/connectors/stripe-api-key/sdk/index.ts
59
+ var BASE_URL = "https://api.stripe.com";
60
+ function createClient(params) {
61
+ const apiKey = params[parameters.apiKey.slug];
62
+ if (!apiKey) {
63
+ throw new Error(
64
+ `stripe-api-key: missing required parameter: ${parameters.apiKey.slug}`
65
+ );
66
+ }
67
+ return {
68
+ request(path2, init) {
69
+ const url = `${BASE_URL}${path2.startsWith("/") ? "" : "/"}${path2}`;
70
+ const headers = new Headers(init?.headers);
71
+ headers.set("Authorization", `Bearer ${apiKey}`);
72
+ return fetch(url, { ...init, headers });
73
+ }
74
+ };
75
+ }
76
+
77
+ // ../connectors/src/connector-onboarding.ts
78
+ var ConnectorOnboarding = class {
79
+ /** Phase 1: Connection setup instructions (optional — some connectors don't need this) */
80
+ connectionSetupInstructions;
81
+ /** Phase 2: Data overview instructions */
82
+ dataOverviewInstructions;
83
+ constructor(config) {
84
+ this.connectionSetupInstructions = config.connectionSetupInstructions;
85
+ this.dataOverviewInstructions = config.dataOverviewInstructions;
86
+ }
87
+ getConnectionSetupPrompt(language) {
88
+ return this.connectionSetupInstructions?.[language] ?? null;
89
+ }
90
+ getDataOverviewInstructions(language) {
91
+ return this.dataOverviewInstructions[language];
92
+ }
93
+ };
94
+
95
+ // ../connectors/src/connector-tool.ts
96
+ var ConnectorTool = class {
97
+ name;
98
+ description;
99
+ inputSchema;
100
+ outputSchema;
101
+ _execute;
102
+ constructor(config) {
103
+ this.name = config.name;
104
+ this.description = config.description;
105
+ this.inputSchema = config.inputSchema;
106
+ this.outputSchema = config.outputSchema;
107
+ this._execute = config.execute;
108
+ }
109
+ createTool(connections, config) {
110
+ return {
111
+ description: this.description,
112
+ inputSchema: this.inputSchema,
113
+ outputSchema: this.outputSchema,
114
+ execute: (input) => this._execute(input, connections, config)
115
+ };
116
+ }
117
+ };
118
+
119
+ // ../connectors/src/connector-plugin.ts
120
+ var ConnectorPlugin = class _ConnectorPlugin {
121
+ slug;
122
+ authType;
123
+ name;
124
+ description;
125
+ iconUrl;
126
+ parameters;
127
+ releaseFlag;
128
+ proxyPolicy;
129
+ experimentalAttributes;
130
+ onboarding;
131
+ systemPrompt;
132
+ tools;
133
+ query;
134
+ checkConnection;
135
+ constructor(config) {
136
+ this.slug = config.slug;
137
+ this.authType = config.authType;
138
+ this.name = config.name;
139
+ this.description = config.description;
140
+ this.iconUrl = config.iconUrl;
141
+ this.parameters = config.parameters;
142
+ this.releaseFlag = config.releaseFlag;
143
+ this.proxyPolicy = config.proxyPolicy;
144
+ this.experimentalAttributes = config.experimentalAttributes;
145
+ this.onboarding = config.onboarding;
146
+ this.systemPrompt = config.systemPrompt;
147
+ this.tools = config.tools;
148
+ this.query = config.query;
149
+ this.checkConnection = config.checkConnection;
150
+ }
151
+ get connectorKey() {
152
+ return _ConnectorPlugin.deriveKey(this.slug, this.authType);
153
+ }
154
+ /**
155
+ * Create tools for connections that belong to this connector.
156
+ * Filters connections by connectorKey internally.
157
+ * Returns tools keyed as `${connectorKey}_${toolName}`.
158
+ */
159
+ createTools(connections, config) {
160
+ const myConnections = connections.filter(
161
+ (c) => _ConnectorPlugin.deriveKey(c.connector.slug, c.connector.authType) === this.connectorKey
162
+ );
163
+ const result = {};
164
+ for (const t of Object.values(this.tools)) {
165
+ result[`${this.connectorKey}_${t.name}`] = t.createTool(
166
+ myConnections,
167
+ config
168
+ );
169
+ }
170
+ return result;
171
+ }
172
+ static deriveKey(slug, authType) {
173
+ return authType ? `${slug}-${authType}` : slug;
174
+ }
175
+ };
176
+
177
+ // ../connectors/src/auth-types.ts
178
+ var AUTH_TYPES = {
179
+ OAUTH: "oauth",
180
+ API_KEY: "api-key",
181
+ JWT: "jwt",
182
+ SERVICE_ACCOUNT: "service-account",
183
+ PAT: "pat",
184
+ USER_PASSWORD: "user-password"
185
+ };
186
+
187
+ // ../connectors/src/connectors/stripe-api-key/tools/request.ts
188
+ import { z } from "zod";
189
+ var BASE_URL2 = "https://api.stripe.com";
190
+ var REQUEST_TIMEOUT_MS = 6e4;
191
+ var inputSchema = z.object({
192
+ toolUseIntent: z.string().optional().describe(
193
+ "Brief description of what you intend to accomplish with this tool call"
194
+ ),
195
+ connectionId: z.string().describe("ID of the Stripe API Key connection to use"),
196
+ method: z.enum(["GET", "POST", "DELETE"]).describe(
197
+ "HTTP method. GET for reading resources, POST for creating or updating, DELETE for removing."
198
+ ),
199
+ path: z.string().describe(
200
+ "API path appended to https://api.stripe.com (e.g., '/v1/charges', '/v1/customers', '/v1/invoices')"
201
+ ),
202
+ queryParams: z.record(z.string(), z.string()).optional().describe("Query parameters to append to the URL"),
203
+ body: z.record(z.string(), z.unknown()).optional().describe(
204
+ "Request body for POST requests. Stripe uses form-encoded bodies \u2014 pass a flat key-value object and it will be encoded automatically."
205
+ )
206
+ });
207
+ var outputSchema = z.discriminatedUnion("success", [
208
+ z.object({
209
+ success: z.literal(true),
210
+ status: z.number(),
211
+ data: z.record(z.string(), z.unknown())
212
+ }),
213
+ z.object({
214
+ success: z.literal(false),
215
+ error: z.string()
216
+ })
217
+ ]);
218
+ var requestTool = new ConnectorTool({
219
+ name: "request",
220
+ description: `Send authenticated requests to the Stripe API.
221
+ Authentication is handled automatically using the configured API Key (Bearer token).
222
+ Use this tool for all Stripe API interactions: querying charges, customers, invoices, subscriptions, products, prices, payment intents, balances, and more.`,
223
+ inputSchema,
224
+ outputSchema,
225
+ async execute({ connectionId, method, path: path2, queryParams, body }, connections) {
226
+ const connection2 = connections.find((c) => c.id === connectionId);
227
+ if (!connection2) {
228
+ return {
229
+ success: false,
230
+ error: `Connection ${connectionId} not found`
231
+ };
232
+ }
233
+ console.log(
234
+ `[connector-request] stripe-api-key/${connection2.name}: ${method} ${path2}`
235
+ );
236
+ try {
237
+ const apiKey = parameters.apiKey.getValue(connection2);
238
+ let url = `${BASE_URL2}${path2.startsWith("/") ? "" : "/"}${path2}`;
239
+ if (queryParams) {
240
+ const searchParams = new URLSearchParams(queryParams);
241
+ url += `?${searchParams.toString()}`;
242
+ }
243
+ const controller = new AbortController();
244
+ const timeout = setTimeout(() => controller.abort(), REQUEST_TIMEOUT_MS);
245
+ try {
246
+ const headers = {
247
+ Authorization: `Bearer ${apiKey}`
248
+ };
249
+ let requestBody;
250
+ if (body) {
251
+ headers["Content-Type"] = "application/x-www-form-urlencoded";
252
+ requestBody = new URLSearchParams(
253
+ Object.entries(body).map(([k, v]) => [k, String(v)])
254
+ ).toString();
255
+ }
256
+ const response = await fetch(url, {
257
+ method,
258
+ headers,
259
+ body: requestBody,
260
+ signal: controller.signal
261
+ });
262
+ const data = await response.json();
263
+ if (!response.ok) {
264
+ const errorObj = data?.error;
265
+ const errorMessage = typeof errorObj === "object" && errorObj !== null && "message" in errorObj ? String(errorObj.message) : typeof data?.message === "string" ? data.message : `HTTP ${response.status} ${response.statusText}`;
266
+ return { success: false, error: errorMessage };
267
+ }
268
+ return { success: true, status: response.status, data };
269
+ } finally {
270
+ clearTimeout(timeout);
271
+ }
272
+ } catch (err) {
273
+ const msg = err instanceof Error ? err.message : String(err);
274
+ return { success: false, error: msg };
275
+ }
276
+ }
277
+ });
278
+
279
+ // ../connectors/src/connectors/stripe-api-key/setup.ts
280
+ var requestToolName = `stripe-api-key_${requestTool.name}`;
281
+ var stripeApiKeyOnboarding = new ConnectorOnboarding({
282
+ connectionSetupInstructions: {
283
+ ja: `\u4EE5\u4E0B\u306E\u624B\u9806\u3067Stripe\u30B3\u30CD\u30AF\u30B7\u30E7\u30F3\u306E\u30BB\u30C3\u30C8\u30A2\u30C3\u30D7\u3092\u884C\u3063\u3066\u304F\u3060\u3055\u3044\u3002
284
+
285
+ 1. \`${requestToolName}\` \u3092\u547C\u3073\u51FA\u3057\u3066\u3001\u30A2\u30AB\u30A6\u30F3\u30C8\u6B8B\u9AD8\u3092\u53D6\u5F97\u3059\u308B:
286
+ - \`method\`: \`"GET"\`
287
+ - \`path\`: \`"/v1/balance"\`
288
+ 2. \u30A8\u30E9\u30FC\u304C\u8FD4\u3055\u308C\u305F\u5834\u5408\u3001\u30E6\u30FC\u30B6\u30FC\u306BAPI\u30AD\u30FC\u306E\u8A2D\u5B9A\u3092\u78BA\u8A8D\u3059\u308B\u3088\u3046\u4F1D\u3048\u308B\uFF08Secret API Key\u307E\u305F\u306FRestricted API Key\u304C\u6B63\u3057\u304F\u8A2D\u5B9A\u3055\u308C\u3066\u3044\u308B\u304B\uFF09
289
+ 3. \`updateConnectionContext\` \u3092\u547C\u3073\u51FA\u3059:
290
+ - \`note\`: \u30BB\u30C3\u30C8\u30A2\u30C3\u30D7\u5185\u5BB9\u306E\u7C21\u5358\u306A\u8AAC\u660E
291
+
292
+ #### \u5236\u7D04
293
+ - **\u30BB\u30C3\u30C8\u30A2\u30C3\u30D7\u4E2D\u306B\u6C7A\u6E08\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
294
+ - \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`,
295
+ en: `Follow these steps to set up the Stripe connection.
296
+
297
+ 1. Call \`${requestToolName}\` to fetch account balance:
298
+ - \`method\`: \`"GET"\`
299
+ - \`path\`: \`"/v1/balance"\`
300
+ 2. If an error is returned, ask the user to check the API key settings (verify that the Secret API Key or Restricted API Key is configured correctly)
301
+ 3. Call \`updateConnectionContext\`:
302
+ - \`note\`: Brief description of the setup
303
+
304
+ #### Constraints
305
+ - **Do NOT read payment data during setup**. Only the metadata request specified in the steps above is allowed
306
+ - Write only 1 sentence between tool calls, then immediately call the next tool. Skip unnecessary explanations and proceed efficiently`
307
+ },
308
+ dataOverviewInstructions: {
309
+ en: `1. Call ${requestToolName} with GET /v1/customers?limit=5 to explore customers structure
310
+ 2. Call ${requestToolName} with GET /v1/charges?limit=5 to explore charges structure
311
+ 3. Explore other endpoints (invoices, subscriptions, products) as needed`,
312
+ ja: `1. ${requestToolName} \u3067 GET /v1/customers?limit=5 \u3092\u547C\u3073\u51FA\u3057\u3001\u9867\u5BA2\u306E\u69CB\u9020\u3092\u78BA\u8A8D
313
+ 2. ${requestToolName} \u3067 GET /v1/charges?limit=5 \u3092\u547C\u3073\u51FA\u3057\u3001\u8AB2\u91D1\u306E\u69CB\u9020\u3092\u78BA\u8A8D
314
+ 3. \u5FC5\u8981\u306B\u5FDC\u3058\u3066\u4ED6\u306E\u30A8\u30F3\u30C9\u30DD\u30A4\u30F3\u30C8\uFF08\u8ACB\u6C42\u66F8\u3001\u30B5\u30D6\u30B9\u30AF\u30EA\u30D7\u30B7\u30E7\u30F3\u3001\u5546\u54C1\uFF09\u3092\u63A2\u7D22`
315
+ }
316
+ });
317
+
318
+ // ../connectors/src/connectors/stripe-api-key/index.ts
319
+ var tools = { request: requestTool };
320
+ var stripeApiKeyConnector = new ConnectorPlugin({
321
+ slug: "stripe",
322
+ authType: AUTH_TYPES.API_KEY,
323
+ name: "Stripe",
324
+ description: "Connect to Stripe for payment, customer, and subscription data using a Secret API Key or Restricted API Key.",
325
+ iconUrl: "https://images.ctfassets.net/9ncizv60xc5y/2QNK0u2doqp41uL0POS4Ks/7a92367e2388ec77c7f4ada143606f9a/stripe.jpeg",
326
+ parameters,
327
+ releaseFlag: { dev1: true, dev2: false, prod: false },
328
+ onboarding: stripeApiKeyOnboarding,
329
+ systemPrompt: {
330
+ en: `### Tools
331
+
332
+ - \`stripe-api-key_request\`: The only way to call the Stripe API. Use it to query charges, customers, invoices, subscriptions, products, prices, payment intents, balances, and more. Authentication is configured automatically using the API Key (Bearer token). Stripe uses cursor-based pagination with \`starting_after\` and \`has_more\`.
333
+
334
+ ### Stripe API Reference
335
+
336
+ #### Available Endpoints
337
+ - GET \`/v1/charges\` \u2014 List charges
338
+ - GET \`/v1/charges/{chargeId}\` \u2014 Get a charge
339
+ - GET \`/v1/customers\` \u2014 List customers
340
+ - GET \`/v1/customers/{customerId}\` \u2014 Get a customer
341
+ - GET \`/v1/invoices\` \u2014 List invoices
342
+ - GET \`/v1/invoices/{invoiceId}\` \u2014 Get an invoice
343
+ - GET \`/v1/subscriptions\` \u2014 List subscriptions
344
+ - GET \`/v1/subscriptions/{subscriptionId}\` \u2014 Get a subscription
345
+ - GET \`/v1/products\` \u2014 List products
346
+ - GET \`/v1/prices\` \u2014 List prices
347
+ - GET \`/v1/payment_intents\` \u2014 List payment intents
348
+ - GET \`/v1/balance\` \u2014 Get account balance
349
+ - GET \`/v1/balance_transactions\` \u2014 List balance transactions
350
+
351
+ ### Query Parameters
352
+ - \`limit\` \u2014 Number of results per page (max 100, default 10)
353
+ - \`starting_after\` \u2014 Pagination cursor (object ID)
354
+ - \`ending_before\` \u2014 Reverse pagination cursor
355
+ - \`created[gte]\`, \`created[lte]\` \u2014 Filter by creation date (Unix timestamp)
356
+ - \`status\` \u2014 Filter by status (varies by resource)
357
+
358
+ ### Tips
359
+ - Stripe uses cursor-based pagination with \`starting_after\` and \`has_more\`
360
+ - All timestamps are Unix timestamps in seconds
361
+ - Use \`expand[]\` query parameter to include related objects inline
362
+ - List responses have \`data\` array and \`has_more\` boolean
363
+ - POST request bodies are form-encoded (pass a flat key-value object)
364
+ - If using a Restricted API Key, some endpoints may return 403 depending on the key's permissions
365
+
366
+ ### Business Logic
367
+
368
+ 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.
369
+
370
+ #### Example
371
+
372
+ \`\`\`ts
373
+ import { connection } from "@squadbase/vite-server/connectors/stripe-api-key";
374
+
375
+ const stripe = connection("<connectionId>");
376
+
377
+ // Authenticated fetch (returns standard Response)
378
+ const res = await stripe.request("/v1/customers?limit=10");
379
+ const data = await res.json();
380
+ \`\`\``,
381
+ ja: `### \u30C4\u30FC\u30EB
382
+
383
+ - \`stripe-api-key_request\`: Stripe API\u3092\u547C\u3073\u51FA\u3059\u552F\u4E00\u306E\u624B\u6BB5\u3067\u3059\u3002\u8ACB\u6C42\u3001\u9867\u5BA2\u3001\u8ACB\u6C42\u66F8\u3001\u30B5\u30D6\u30B9\u30AF\u30EA\u30D7\u30B7\u30E7\u30F3\u3001\u5546\u54C1\u3001\u4FA1\u683C\u3001\u652F\u6255\u3044\u30A4\u30F3\u30C6\u30F3\u30C8\u3001\u6B8B\u9AD8\u306A\u3069\u306E\u30AF\u30A8\u30EA\u306B\u4F7F\u7528\u3057\u307E\u3059\u3002API\u30AD\u30FC\uFF08Bearer\u30C8\u30FC\u30AF\u30F3\uFF09\u3067\u8A8D\u8A3C\u306F\u81EA\u52D5\u8A2D\u5B9A\u3055\u308C\u307E\u3059\u3002Stripe\u306F \`starting_after\` \u3068 \`has_more\` \u306B\u3088\u308B\u30AB\u30FC\u30BD\u30EB\u30D9\u30FC\u30B9\u306E\u30DA\u30FC\u30B8\u30CD\u30FC\u30B7\u30E7\u30F3\u3092\u4F7F\u7528\u3057\u307E\u3059\u3002
384
+
385
+ ### Stripe API \u30EA\u30D5\u30A1\u30EC\u30F3\u30B9
386
+
387
+ #### \u5229\u7528\u53EF\u80FD\u306A\u30A8\u30F3\u30C9\u30DD\u30A4\u30F3\u30C8
388
+ - GET \`/v1/charges\` \u2014 \u8ACB\u6C42\u4E00\u89A7\u3092\u53D6\u5F97
389
+ - GET \`/v1/charges/{chargeId}\` \u2014 \u8ACB\u6C42\u3092\u53D6\u5F97
390
+ - GET \`/v1/customers\` \u2014 \u9867\u5BA2\u4E00\u89A7\u3092\u53D6\u5F97
391
+ - GET \`/v1/customers/{customerId}\` \u2014 \u9867\u5BA2\u3092\u53D6\u5F97
392
+ - GET \`/v1/invoices\` \u2014 \u8ACB\u6C42\u66F8\u4E00\u89A7\u3092\u53D6\u5F97
393
+ - GET \`/v1/invoices/{invoiceId}\` \u2014 \u8ACB\u6C42\u66F8\u3092\u53D6\u5F97
394
+ - GET \`/v1/subscriptions\` \u2014 \u30B5\u30D6\u30B9\u30AF\u30EA\u30D7\u30B7\u30E7\u30F3\u4E00\u89A7\u3092\u53D6\u5F97
395
+ - GET \`/v1/subscriptions/{subscriptionId}\` \u2014 \u30B5\u30D6\u30B9\u30AF\u30EA\u30D7\u30B7\u30E7\u30F3\u3092\u53D6\u5F97
396
+ - GET \`/v1/products\` \u2014 \u5546\u54C1\u4E00\u89A7\u3092\u53D6\u5F97
397
+ - GET \`/v1/prices\` \u2014 \u4FA1\u683C\u4E00\u89A7\u3092\u53D6\u5F97
398
+ - GET \`/v1/payment_intents\` \u2014 \u652F\u6255\u3044\u30A4\u30F3\u30C6\u30F3\u30C8\u4E00\u89A7\u3092\u53D6\u5F97
399
+ - GET \`/v1/balance\` \u2014 \u30A2\u30AB\u30A6\u30F3\u30C8\u6B8B\u9AD8\u3092\u53D6\u5F97
400
+ - GET \`/v1/balance_transactions\` \u2014 \u6B8B\u9AD8\u30C8\u30E9\u30F3\u30B6\u30AF\u30B7\u30E7\u30F3\u4E00\u89A7\u3092\u53D6\u5F97
401
+
402
+ ### \u30AF\u30A8\u30EA\u30D1\u30E9\u30E1\u30FC\u30BF
403
+ - \`limit\` \u2014 \u30DA\u30FC\u30B8\u3042\u305F\u308A\u306E\u7D50\u679C\u6570\uFF08\u6700\u5927100\u3001\u30C7\u30D5\u30A9\u30EB\u30C810\uFF09
404
+ - \`starting_after\` \u2014 \u30DA\u30FC\u30B8\u30CD\u30FC\u30B7\u30E7\u30F3\u30AB\u30FC\u30BD\u30EB\uFF08\u30AA\u30D6\u30B8\u30A7\u30AF\u30C8ID\uFF09
405
+ - \`ending_before\` \u2014 \u9006\u65B9\u5411\u30DA\u30FC\u30B8\u30CD\u30FC\u30B7\u30E7\u30F3\u30AB\u30FC\u30BD\u30EB
406
+ - \`created[gte]\`, \`created[lte]\` \u2014 \u4F5C\u6210\u65E5\u3067\u30D5\u30A3\u30EB\u30BF\uFF08Unix\u30BF\u30A4\u30E0\u30B9\u30BF\u30F3\u30D7\uFF09
407
+ - \`status\` \u2014 \u30B9\u30C6\u30FC\u30BF\u30B9\u3067\u30D5\u30A3\u30EB\u30BF\uFF08\u30EA\u30BD\u30FC\u30B9\u306B\u3088\u308A\u7570\u306A\u308B\uFF09
408
+
409
+ ### \u30D2\u30F3\u30C8
410
+ - Stripe\u306F \`starting_after\` \u3068 \`has_more\` \u306B\u3088\u308B\u30AB\u30FC\u30BD\u30EB\u30D9\u30FC\u30B9\u306E\u30DA\u30FC\u30B8\u30CD\u30FC\u30B7\u30E7\u30F3\u3092\u4F7F\u7528\u3057\u307E\u3059
411
+ - \u3059\u3079\u3066\u306E\u30BF\u30A4\u30E0\u30B9\u30BF\u30F3\u30D7\u306F\u79D2\u5358\u4F4D\u306EUnix\u30BF\u30A4\u30E0\u30B9\u30BF\u30F3\u30D7\u3067\u3059
412
+ - \u95A2\u9023\u30AA\u30D6\u30B8\u30A7\u30AF\u30C8\u3092\u30A4\u30F3\u30E9\u30A4\u30F3\u3067\u542B\u3081\u308B\u306B\u306F \`expand[]\` \u30AF\u30A8\u30EA\u30D1\u30E9\u30E1\u30FC\u30BF\u3092\u4F7F\u7528\u3057\u307E\u3059
413
+ - \u4E00\u89A7\u30EC\u30B9\u30DD\u30F3\u30B9\u306B\u306F \`data\` \u914D\u5217\u3068 \`has_more\` \u30D6\u30FC\u30EB\u5024\u304C\u542B\u307E\u308C\u307E\u3059
414
+ - POST\u30EA\u30AF\u30A8\u30B9\u30C8\u306E\u30DC\u30C7\u30A3\u306F\u30D5\u30A9\u30FC\u30E0\u30A8\u30F3\u30B3\u30FC\u30C9\u3067\u3059\uFF08\u30D5\u30E9\u30C3\u30C8\u306A\u30AD\u30FC\u30FB\u30D0\u30EA\u30E5\u30FC\u30AA\u30D6\u30B8\u30A7\u30AF\u30C8\u3092\u6E21\u3057\u3066\u304F\u3060\u3055\u3044\uFF09
415
+ - Restricted API Key\u3092\u4F7F\u7528\u3057\u3066\u3044\u308B\u5834\u5408\u3001\u30AD\u30FC\u306E\u6A29\u9650\u306B\u3088\u3063\u3066\u306F\u4E00\u90E8\u306E\u30A8\u30F3\u30C9\u30DD\u30A4\u30F3\u30C8\u3067403\u304C\u8FD4\u308B\u3053\u3068\u304C\u3042\u308A\u307E\u3059
416
+
417
+ ### Business Logic
418
+
419
+ \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
420
+
421
+ #### Example
422
+
423
+ \`\`\`ts
424
+ import { connection } from "@squadbase/vite-server/connectors/stripe-api-key";
425
+
426
+ const stripe = connection("<connectionId>");
427
+
428
+ // Authenticated fetch (returns standard Response)
429
+ const res = await stripe.request("/v1/customers?limit=10");
430
+ const data = await res.json();
431
+ \`\`\``
432
+ },
433
+ tools,
434
+ async checkConnection(params) {
435
+ try {
436
+ const apiKey = params["api-key"];
437
+ if (!apiKey) {
438
+ return {
439
+ success: false,
440
+ error: "API Key is not configured"
441
+ };
442
+ }
443
+ const res = await fetch("https://api.stripe.com/v1/balance", {
444
+ method: "GET",
445
+ headers: { Authorization: `Bearer ${apiKey}` }
446
+ });
447
+ if (!res.ok) {
448
+ const errorText = await res.text().catch(() => res.statusText);
449
+ return {
450
+ success: false,
451
+ error: `Stripe API failed: HTTP ${res.status} ${errorText}`
452
+ };
453
+ }
454
+ return { success: true };
455
+ } catch (error) {
456
+ return {
457
+ success: false,
458
+ error: error instanceof Error ? error.message : String(error)
459
+ };
460
+ }
461
+ }
462
+ });
463
+
464
+ // src/connectors/create-connector-sdk.ts
465
+ import { readFileSync } from "fs";
466
+ import path from "path";
467
+
468
+ // src/connector-client/env.ts
469
+ function resolveEnvVar(entry, key, connectionId) {
470
+ const envVarName = entry.envVars[key];
471
+ if (!envVarName) {
472
+ throw new Error(`Connection "${connectionId}" is missing envVars mapping for key "${key}"`);
473
+ }
474
+ const value = process.env[envVarName];
475
+ if (!value) {
476
+ throw new Error(`Environment variable "${envVarName}" (for connection "${connectionId}", key "${key}") is not set`);
477
+ }
478
+ return value;
479
+ }
480
+ function resolveEnvVarOptional(entry, key) {
481
+ const envVarName = entry.envVars[key];
482
+ if (!envVarName) return void 0;
483
+ return process.env[envVarName] || void 0;
484
+ }
485
+
486
+ // src/connector-client/proxy-fetch.ts
487
+ import { getContext } from "hono/context-storage";
488
+ import { getCookie } from "hono/cookie";
489
+ var APP_SESSION_COOKIE_NAME = "__Host-squadbase-session";
490
+ function createSandboxProxyFetch(connectionId) {
491
+ return async (input, init) => {
492
+ const token = process.env.INTERNAL_SQUADBASE_OAUTH_MACHINE_CREDENTIAL;
493
+ const sandboxId = process.env.INTERNAL_SQUADBASE_SANDBOX_ID;
494
+ if (!token || !sandboxId) {
495
+ throw new Error(
496
+ "Connection proxy is not configured. Please check your deployment settings."
497
+ );
498
+ }
499
+ const originalUrl = typeof input === "string" ? input : input instanceof URL ? input.href : input.url;
500
+ const originalMethod = init?.method ?? "GET";
501
+ const originalBody = init?.body ? JSON.parse(init.body) : void 0;
502
+ const baseDomain = process.env["SQUADBASE_PREVIEW_BASE_DOMAIN"] ?? "preview.app.squadbase.dev";
503
+ const proxyUrl = `https://${sandboxId}.${baseDomain}/_sqcore/connections/${connectionId}/request`;
504
+ return fetch(proxyUrl, {
505
+ method: "POST",
506
+ headers: {
507
+ "Content-Type": "application/json",
508
+ Authorization: `Bearer ${token}`
509
+ },
510
+ body: JSON.stringify({
511
+ url: originalUrl,
512
+ method: originalMethod,
513
+ body: originalBody
514
+ })
515
+ });
516
+ };
517
+ }
518
+ function createDeployedAppProxyFetch(connectionId) {
519
+ const projectId = process.env["SQUADBASE_PROJECT_ID"];
520
+ if (!projectId) {
521
+ throw new Error(
522
+ "Connection proxy is not configured. Please check your deployment settings."
523
+ );
524
+ }
525
+ const baseDomain = process.env["SQUADBASE_APP_BASE_DOMAIN"] ?? "squadbase.app";
526
+ const proxyUrl = `https://${projectId}.${baseDomain}/_sqcore/connections/${connectionId}/request`;
527
+ return async (input, init) => {
528
+ const originalUrl = typeof input === "string" ? input : input instanceof URL ? input.href : input.url;
529
+ const originalMethod = init?.method ?? "GET";
530
+ const originalBody = init?.body ? JSON.parse(init.body) : void 0;
531
+ const c = getContext();
532
+ const appSession = getCookie(c, APP_SESSION_COOKIE_NAME);
533
+ if (!appSession) {
534
+ throw new Error(
535
+ "No authentication method available for connection proxy."
536
+ );
537
+ }
538
+ return fetch(proxyUrl, {
539
+ method: "POST",
540
+ headers: {
541
+ "Content-Type": "application/json",
542
+ Authorization: `Bearer ${appSession}`
543
+ },
544
+ body: JSON.stringify({
545
+ url: originalUrl,
546
+ method: originalMethod,
547
+ body: originalBody
548
+ })
549
+ });
550
+ };
551
+ }
552
+ function createProxyFetch(connectionId) {
553
+ if (process.env.INTERNAL_SQUADBASE_SANDBOX_ID) {
554
+ return createSandboxProxyFetch(connectionId);
555
+ }
556
+ return createDeployedAppProxyFetch(connectionId);
557
+ }
558
+
559
+ // src/connectors/create-connector-sdk.ts
560
+ function loadConnectionsSync() {
561
+ const filePath = process.env.CONNECTIONS_PATH ?? path.join(process.cwd(), ".squadbase/connections.json");
562
+ try {
563
+ const raw = readFileSync(filePath, "utf-8");
564
+ return JSON.parse(raw);
565
+ } catch {
566
+ return {};
567
+ }
568
+ }
569
+ function createConnectorSdk(plugin, createClient2) {
570
+ return (connectionId) => {
571
+ const connections = loadConnectionsSync();
572
+ const entry = connections[connectionId];
573
+ if (!entry) {
574
+ throw new Error(
575
+ `Connection "${connectionId}" not found in .squadbase/connections.json`
576
+ );
577
+ }
578
+ if (entry.connector.slug !== plugin.slug) {
579
+ throw new Error(
580
+ `Connection "${connectionId}" is not a ${plugin.slug} connection (got "${entry.connector.slug}")`
581
+ );
582
+ }
583
+ const params = {};
584
+ for (const param of Object.values(plugin.parameters)) {
585
+ if (param.required) {
586
+ params[param.slug] = resolveEnvVar(entry, param.slug, connectionId);
587
+ } else {
588
+ const val = resolveEnvVarOptional(entry, param.slug);
589
+ if (val !== void 0) params[param.slug] = val;
590
+ }
591
+ }
592
+ return createClient2(params, createProxyFetch(connectionId));
593
+ };
594
+ }
595
+
596
+ // src/connectors/entries/stripe-api-key.ts
597
+ var connection = createConnectorSdk(stripeApiKeyConnector, createClient);
598
+ export {
599
+ connection
600
+ };