@squadbase/vite-server 0.1.3-dev.0 → 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.
- package/dist/cli/index.js +82859 -9645
- package/dist/connectors/airtable-oauth.js +77 -3
- package/dist/connectors/airtable.js +85 -2
- package/dist/connectors/amplitude.js +85 -2
- package/dist/connectors/anthropic.js +85 -2
- package/dist/connectors/{slack.d.ts → asana.d.ts} +1 -1
- package/dist/connectors/asana.js +744 -0
- package/dist/connectors/attio.js +85 -2
- package/dist/connectors/{microsoft-teams-oauth.d.ts → customerio.d.ts} +1 -1
- package/dist/connectors/customerio.js +716 -0
- package/dist/connectors/dbt.js +85 -2
- package/dist/connectors/gemini.js +86 -3
- package/dist/connectors/{microsoft-teams.d.ts → gmail-oauth.d.ts} +1 -1
- package/dist/connectors/gmail-oauth.js +713 -0
- package/dist/connectors/gmail.d.ts +5 -0
- package/dist/connectors/gmail.js +875 -0
- package/dist/connectors/google-ads-oauth.js +78 -4
- package/dist/connectors/google-ads.d.ts +5 -0
- package/dist/connectors/google-ads.js +867 -0
- package/dist/connectors/google-analytics-oauth.js +90 -8
- package/dist/connectors/google-analytics.js +85 -2
- package/dist/connectors/google-calendar-oauth.d.ts +5 -0
- package/dist/connectors/google-calendar-oauth.js +817 -0
- package/dist/connectors/google-calendar.d.ts +5 -0
- package/dist/connectors/google-calendar.js +991 -0
- package/dist/connectors/google-sheets-oauth.js +144 -33
- package/dist/connectors/google-sheets.d.ts +5 -0
- package/dist/connectors/google-sheets.js +707 -0
- package/dist/connectors/grafana.d.ts +5 -0
- package/dist/connectors/grafana.js +638 -0
- package/dist/connectors/hubspot-oauth.js +77 -3
- package/dist/connectors/hubspot.js +89 -6
- package/dist/connectors/intercom-oauth.d.ts +5 -0
- package/dist/connectors/intercom-oauth.js +584 -0
- package/dist/connectors/intercom.d.ts +5 -0
- package/dist/connectors/intercom.js +710 -0
- package/dist/connectors/jira-api-key.d.ts +5 -0
- package/dist/connectors/jira-api-key.js +598 -0
- package/dist/connectors/kintone-api-token.js +77 -3
- package/dist/connectors/kintone.js +86 -3
- package/dist/connectors/linkedin-ads-oauth.d.ts +5 -0
- package/dist/connectors/linkedin-ads-oauth.js +848 -0
- package/dist/connectors/linkedin-ads.d.ts +5 -0
- package/dist/connectors/linkedin-ads.js +865 -0
- package/dist/connectors/mailchimp-oauth.d.ts +5 -0
- package/dist/connectors/mailchimp-oauth.js +613 -0
- package/dist/connectors/mailchimp.d.ts +5 -0
- package/dist/connectors/mailchimp.js +729 -0
- package/dist/connectors/notion-oauth.d.ts +5 -0
- package/dist/connectors/notion-oauth.js +567 -0
- package/dist/connectors/notion.d.ts +5 -0
- package/dist/connectors/notion.js +663 -0
- package/dist/connectors/openai.js +85 -2
- package/dist/connectors/shopify-oauth.js +77 -3
- package/dist/connectors/shopify.js +85 -2
- package/dist/connectors/stripe-api-key.d.ts +5 -0
- package/dist/connectors/stripe-api-key.js +600 -0
- package/dist/connectors/stripe-oauth.js +77 -3
- package/dist/connectors/wix-store.js +85 -2
- package/dist/connectors/zendesk-oauth.d.ts +5 -0
- package/dist/connectors/zendesk-oauth.js +579 -0
- package/dist/connectors/zendesk.d.ts +5 -0
- package/dist/connectors/zendesk.js +714 -0
- package/dist/index.js +83024 -7099
- package/dist/main.js +82988 -7063
- package/dist/vite-plugin.js +82862 -6974
- package/package.json +86 -2
- package/dist/connectors/microsoft-teams-oauth.js +0 -479
- package/dist/connectors/microsoft-teams.js +0 -381
- package/dist/connectors/slack.js +0 -362
|
@@ -0,0 +1,714 @@
|
|
|
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/zendesk/parameters.ts
|
|
46
|
+
var parameters = {
|
|
47
|
+
subdomain: new ParameterDefinition({
|
|
48
|
+
slug: "subdomain",
|
|
49
|
+
name: "Zendesk Subdomain",
|
|
50
|
+
description: 'Your Zendesk subdomain (e.g., "mycompany" for mycompany.zendesk.com).',
|
|
51
|
+
envVarBaseKey: "ZENDESK_SUBDOMAIN",
|
|
52
|
+
type: "text",
|
|
53
|
+
secret: false,
|
|
54
|
+
required: true
|
|
55
|
+
}),
|
|
56
|
+
email: new ParameterDefinition({
|
|
57
|
+
slug: "email",
|
|
58
|
+
name: "Email Address",
|
|
59
|
+
description: "The email address of the Zendesk agent used for API token authentication.",
|
|
60
|
+
envVarBaseKey: "ZENDESK_EMAIL",
|
|
61
|
+
type: "text",
|
|
62
|
+
secret: false,
|
|
63
|
+
required: true
|
|
64
|
+
}),
|
|
65
|
+
apiToken: new ParameterDefinition({
|
|
66
|
+
slug: "api-token",
|
|
67
|
+
name: "API Token",
|
|
68
|
+
description: "Your Zendesk API token (found in Admin > Apps and integrations > Zendesk API > Settings).",
|
|
69
|
+
envVarBaseKey: "ZENDESK_API_TOKEN",
|
|
70
|
+
type: "text",
|
|
71
|
+
secret: true,
|
|
72
|
+
required: true
|
|
73
|
+
})
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
// ../connectors/src/connectors/zendesk/sdk/index.ts
|
|
77
|
+
var API_VERSION = "v2";
|
|
78
|
+
function createClient(params) {
|
|
79
|
+
const subdomain = params[parameters.subdomain.slug];
|
|
80
|
+
const email = params[parameters.email.slug];
|
|
81
|
+
const apiToken = params[parameters.apiToken.slug];
|
|
82
|
+
if (!subdomain || !email || !apiToken) {
|
|
83
|
+
throw new Error("zendesk: missing required parameters (subdomain, email, api-token)");
|
|
84
|
+
}
|
|
85
|
+
const baseUrl = `https://${subdomain}.zendesk.com/api/${API_VERSION}`;
|
|
86
|
+
const authToken = Buffer.from(`${email}/token:${apiToken}`).toString("base64");
|
|
87
|
+
function authHeaders(extra) {
|
|
88
|
+
const headers = new Headers(extra);
|
|
89
|
+
headers.set("Authorization", `Basic ${authToken}`);
|
|
90
|
+
headers.set("Content-Type", "application/json");
|
|
91
|
+
return headers;
|
|
92
|
+
}
|
|
93
|
+
async function assertOk(res, label) {
|
|
94
|
+
if (!res.ok) {
|
|
95
|
+
const body = await res.text().catch(() => "(unreadable body)");
|
|
96
|
+
throw new Error(
|
|
97
|
+
`zendesk ${label}: ${res.status} ${res.statusText} \u2014 ${body}`
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return {
|
|
102
|
+
request(path2, init) {
|
|
103
|
+
const resolvedPath = path2.replace(/\{subdomain\}/g, subdomain);
|
|
104
|
+
const url = resolvedPath.startsWith("http") ? resolvedPath : `https://${subdomain}.zendesk.com${resolvedPath.startsWith("/") ? "" : "/"}${resolvedPath}`;
|
|
105
|
+
const headers = new Headers(init?.headers);
|
|
106
|
+
headers.set("Authorization", `Basic ${authToken}`);
|
|
107
|
+
headers.set("Content-Type", "application/json");
|
|
108
|
+
return fetch(url, { ...init, headers });
|
|
109
|
+
},
|
|
110
|
+
async listTickets(options) {
|
|
111
|
+
const searchParams = new URLSearchParams();
|
|
112
|
+
if (options?.status) searchParams.set("status", options.status);
|
|
113
|
+
if (options?.sort_by) searchParams.set("sort_by", options.sort_by);
|
|
114
|
+
if (options?.sort_order) searchParams.set("sort_order", options.sort_order);
|
|
115
|
+
if (options?.per_page) searchParams.set("page[size]", String(options.per_page));
|
|
116
|
+
if (options?.page_after) searchParams.set("page[after]", options.page_after);
|
|
117
|
+
const qs = searchParams.toString();
|
|
118
|
+
const res = await fetch(
|
|
119
|
+
`${baseUrl}/tickets.json${qs ? `?${qs}` : ""}`,
|
|
120
|
+
{ method: "GET", headers: authHeaders() }
|
|
121
|
+
);
|
|
122
|
+
await assertOk(res, "listTickets");
|
|
123
|
+
return await res.json();
|
|
124
|
+
},
|
|
125
|
+
async getTicket(ticketId) {
|
|
126
|
+
const res = await fetch(
|
|
127
|
+
`${baseUrl}/tickets/${encodeURIComponent(String(ticketId))}.json`,
|
|
128
|
+
{ method: "GET", headers: authHeaders() }
|
|
129
|
+
);
|
|
130
|
+
await assertOk(res, "getTicket");
|
|
131
|
+
return await res.json();
|
|
132
|
+
},
|
|
133
|
+
async listUsers(options) {
|
|
134
|
+
const searchParams = new URLSearchParams();
|
|
135
|
+
if (options?.role) searchParams.set("role", options.role);
|
|
136
|
+
if (options?.per_page) searchParams.set("page[size]", String(options.per_page));
|
|
137
|
+
if (options?.page_after) searchParams.set("page[after]", options.page_after);
|
|
138
|
+
const qs = searchParams.toString();
|
|
139
|
+
const res = await fetch(
|
|
140
|
+
`${baseUrl}/users.json${qs ? `?${qs}` : ""}`,
|
|
141
|
+
{ method: "GET", headers: authHeaders() }
|
|
142
|
+
);
|
|
143
|
+
await assertOk(res, "listUsers");
|
|
144
|
+
return await res.json();
|
|
145
|
+
},
|
|
146
|
+
async getUser(userId) {
|
|
147
|
+
const res = await fetch(
|
|
148
|
+
`${baseUrl}/users/${encodeURIComponent(String(userId))}.json`,
|
|
149
|
+
{ method: "GET", headers: authHeaders() }
|
|
150
|
+
);
|
|
151
|
+
await assertOk(res, "getUser");
|
|
152
|
+
return await res.json();
|
|
153
|
+
},
|
|
154
|
+
async search(query, options) {
|
|
155
|
+
const searchParams = new URLSearchParams();
|
|
156
|
+
searchParams.set("query", query);
|
|
157
|
+
if (options?.sort_by) searchParams.set("sort_by", options.sort_by);
|
|
158
|
+
if (options?.sort_order) searchParams.set("sort_order", options.sort_order);
|
|
159
|
+
if (options?.per_page) searchParams.set("per_page", String(options.per_page));
|
|
160
|
+
if (options?.page) searchParams.set("page", String(options.page));
|
|
161
|
+
const qs = searchParams.toString();
|
|
162
|
+
const res = await fetch(
|
|
163
|
+
`${baseUrl}/search.json?${qs}`,
|
|
164
|
+
{ method: "GET", headers: authHeaders() }
|
|
165
|
+
);
|
|
166
|
+
await assertOk(res, "search");
|
|
167
|
+
return await res.json();
|
|
168
|
+
},
|
|
169
|
+
async listOrganizations(options) {
|
|
170
|
+
const searchParams = new URLSearchParams();
|
|
171
|
+
if (options?.per_page) searchParams.set("page[size]", String(options.per_page));
|
|
172
|
+
if (options?.page_after) searchParams.set("page[after]", options.page_after);
|
|
173
|
+
const qs = searchParams.toString();
|
|
174
|
+
const res = await fetch(
|
|
175
|
+
`${baseUrl}/organizations.json${qs ? `?${qs}` : ""}`,
|
|
176
|
+
{ method: "GET", headers: authHeaders() }
|
|
177
|
+
);
|
|
178
|
+
await assertOk(res, "listOrganizations");
|
|
179
|
+
return await res.json();
|
|
180
|
+
}
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
// ../connectors/src/connector-onboarding.ts
|
|
185
|
+
var ConnectorOnboarding = class {
|
|
186
|
+
/** Phase 1: Connection setup instructions (optional — some connectors don't need this) */
|
|
187
|
+
connectionSetupInstructions;
|
|
188
|
+
/** Phase 2: Data overview instructions */
|
|
189
|
+
dataOverviewInstructions;
|
|
190
|
+
constructor(config) {
|
|
191
|
+
this.connectionSetupInstructions = config.connectionSetupInstructions;
|
|
192
|
+
this.dataOverviewInstructions = config.dataOverviewInstructions;
|
|
193
|
+
}
|
|
194
|
+
getConnectionSetupPrompt(language) {
|
|
195
|
+
return this.connectionSetupInstructions?.[language] ?? null;
|
|
196
|
+
}
|
|
197
|
+
getDataOverviewInstructions(language) {
|
|
198
|
+
return this.dataOverviewInstructions[language];
|
|
199
|
+
}
|
|
200
|
+
};
|
|
201
|
+
|
|
202
|
+
// ../connectors/src/connector-tool.ts
|
|
203
|
+
var ConnectorTool = class {
|
|
204
|
+
name;
|
|
205
|
+
description;
|
|
206
|
+
inputSchema;
|
|
207
|
+
outputSchema;
|
|
208
|
+
_execute;
|
|
209
|
+
constructor(config) {
|
|
210
|
+
this.name = config.name;
|
|
211
|
+
this.description = config.description;
|
|
212
|
+
this.inputSchema = config.inputSchema;
|
|
213
|
+
this.outputSchema = config.outputSchema;
|
|
214
|
+
this._execute = config.execute;
|
|
215
|
+
}
|
|
216
|
+
createTool(connections, config) {
|
|
217
|
+
return {
|
|
218
|
+
description: this.description,
|
|
219
|
+
inputSchema: this.inputSchema,
|
|
220
|
+
outputSchema: this.outputSchema,
|
|
221
|
+
execute: (input) => this._execute(input, connections, config)
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
};
|
|
225
|
+
|
|
226
|
+
// ../connectors/src/connector-plugin.ts
|
|
227
|
+
var ConnectorPlugin = class _ConnectorPlugin {
|
|
228
|
+
slug;
|
|
229
|
+
authType;
|
|
230
|
+
name;
|
|
231
|
+
description;
|
|
232
|
+
iconUrl;
|
|
233
|
+
parameters;
|
|
234
|
+
releaseFlag;
|
|
235
|
+
proxyPolicy;
|
|
236
|
+
experimentalAttributes;
|
|
237
|
+
onboarding;
|
|
238
|
+
systemPrompt;
|
|
239
|
+
tools;
|
|
240
|
+
query;
|
|
241
|
+
checkConnection;
|
|
242
|
+
constructor(config) {
|
|
243
|
+
this.slug = config.slug;
|
|
244
|
+
this.authType = config.authType;
|
|
245
|
+
this.name = config.name;
|
|
246
|
+
this.description = config.description;
|
|
247
|
+
this.iconUrl = config.iconUrl;
|
|
248
|
+
this.parameters = config.parameters;
|
|
249
|
+
this.releaseFlag = config.releaseFlag;
|
|
250
|
+
this.proxyPolicy = config.proxyPolicy;
|
|
251
|
+
this.experimentalAttributes = config.experimentalAttributes;
|
|
252
|
+
this.onboarding = config.onboarding;
|
|
253
|
+
this.systemPrompt = config.systemPrompt;
|
|
254
|
+
this.tools = config.tools;
|
|
255
|
+
this.query = config.query;
|
|
256
|
+
this.checkConnection = config.checkConnection;
|
|
257
|
+
}
|
|
258
|
+
get connectorKey() {
|
|
259
|
+
return _ConnectorPlugin.deriveKey(this.slug, this.authType);
|
|
260
|
+
}
|
|
261
|
+
/**
|
|
262
|
+
* Create tools for connections that belong to this connector.
|
|
263
|
+
* Filters connections by connectorKey internally.
|
|
264
|
+
* Returns tools keyed as `${connectorKey}_${toolName}`.
|
|
265
|
+
*/
|
|
266
|
+
createTools(connections, config) {
|
|
267
|
+
const myConnections = connections.filter(
|
|
268
|
+
(c) => _ConnectorPlugin.deriveKey(c.connector.slug, c.connector.authType) === this.connectorKey
|
|
269
|
+
);
|
|
270
|
+
const result = {};
|
|
271
|
+
for (const t of Object.values(this.tools)) {
|
|
272
|
+
result[`${this.connectorKey}_${t.name}`] = t.createTool(
|
|
273
|
+
myConnections,
|
|
274
|
+
config
|
|
275
|
+
);
|
|
276
|
+
}
|
|
277
|
+
return result;
|
|
278
|
+
}
|
|
279
|
+
static deriveKey(slug, authType) {
|
|
280
|
+
return authType ? `${slug}-${authType}` : slug;
|
|
281
|
+
}
|
|
282
|
+
};
|
|
283
|
+
|
|
284
|
+
// ../connectors/src/auth-types.ts
|
|
285
|
+
var AUTH_TYPES = {
|
|
286
|
+
OAUTH: "oauth",
|
|
287
|
+
API_KEY: "api-key",
|
|
288
|
+
JWT: "jwt",
|
|
289
|
+
SERVICE_ACCOUNT: "service-account",
|
|
290
|
+
PAT: "pat",
|
|
291
|
+
USER_PASSWORD: "user-password"
|
|
292
|
+
};
|
|
293
|
+
|
|
294
|
+
// ../connectors/src/connectors/zendesk/setup.ts
|
|
295
|
+
var zendeskOnboarding = new ConnectorOnboarding({
|
|
296
|
+
dataOverviewInstructions: {
|
|
297
|
+
en: `1. Call zendesk_request with GET /api/v2/ticket_fields.json to list available ticket fields
|
|
298
|
+
2. Call zendesk_request with GET /api/v2/tickets.json?page[size]=5 to explore ticket structure
|
|
299
|
+
3. Call zendesk_request with GET /api/v2/users.json?page[size]=5 to explore user structure
|
|
300
|
+
4. Call zendesk_request with GET /api/v2/organizations.json?page[size]=5 to explore organization structure`,
|
|
301
|
+
ja: `1. zendesk_request \u3067 GET /api/v2/ticket_fields.json \u3092\u547C\u3073\u51FA\u3057\u3001\u5229\u7528\u53EF\u80FD\u306A\u30C1\u30B1\u30C3\u30C8\u30D5\u30A3\u30FC\u30EB\u30C9\u3092\u78BA\u8A8D
|
|
302
|
+
2. zendesk_request \u3067 GET /api/v2/tickets.json?page[size]=5 \u3092\u547C\u3073\u51FA\u3057\u3001\u30C1\u30B1\u30C3\u30C8\u306E\u69CB\u9020\u3092\u78BA\u8A8D
|
|
303
|
+
3. zendesk_request \u3067 GET /api/v2/users.json?page[size]=5 \u3092\u547C\u3073\u51FA\u3057\u3001\u30E6\u30FC\u30B6\u30FC\u306E\u69CB\u9020\u3092\u78BA\u8A8D
|
|
304
|
+
4. zendesk_request \u3067 GET /api/v2/organizations.json?page[size]=5 \u3092\u547C\u3073\u51FA\u3057\u3001\u7D44\u7E54\u306E\u69CB\u9020\u3092\u78BA\u8A8D`
|
|
305
|
+
}
|
|
306
|
+
});
|
|
307
|
+
|
|
308
|
+
// ../connectors/src/connectors/zendesk/tools/request.ts
|
|
309
|
+
import { z } from "zod";
|
|
310
|
+
var REQUEST_TIMEOUT_MS = 6e4;
|
|
311
|
+
var inputSchema = z.object({
|
|
312
|
+
toolUseIntent: z.string().optional().describe(
|
|
313
|
+
"Brief description of what you intend to accomplish with this tool call"
|
|
314
|
+
),
|
|
315
|
+
connectionId: z.string().describe("ID of the Zendesk connection to use"),
|
|
316
|
+
method: z.enum(["GET", "POST", "PUT", "DELETE"]).describe(
|
|
317
|
+
"HTTP method. GET for reading, POST for creating/searching, PUT for updating, DELETE for removing."
|
|
318
|
+
),
|
|
319
|
+
path: z.string().describe(
|
|
320
|
+
"API path appended to https://{subdomain}.zendesk.com (e.g., '/api/v2/tickets.json', '/api/v2/search.json?query=status:open')"
|
|
321
|
+
),
|
|
322
|
+
body: z.record(z.string(), z.unknown()).optional().describe("Request body (JSON) for POST/PUT requests")
|
|
323
|
+
});
|
|
324
|
+
var outputSchema = z.discriminatedUnion("success", [
|
|
325
|
+
z.object({
|
|
326
|
+
success: z.literal(true),
|
|
327
|
+
status: z.number(),
|
|
328
|
+
data: z.record(z.string(), z.unknown())
|
|
329
|
+
}),
|
|
330
|
+
z.object({
|
|
331
|
+
success: z.literal(false),
|
|
332
|
+
error: z.string()
|
|
333
|
+
})
|
|
334
|
+
]);
|
|
335
|
+
var requestTool = new ConnectorTool({
|
|
336
|
+
name: "request",
|
|
337
|
+
description: `Send authenticated requests to the Zendesk Support API.
|
|
338
|
+
Authentication is handled automatically using email/token Basic auth.
|
|
339
|
+
Use this tool for all Zendesk API interactions: querying tickets, users, organizations, groups, and searching.
|
|
340
|
+
Zendesk uses cursor-based pagination with page[size] and page[after] parameters. All endpoints return .json suffix.`,
|
|
341
|
+
inputSchema,
|
|
342
|
+
outputSchema,
|
|
343
|
+
async execute({ connectionId, method, path: path2, body }, connections) {
|
|
344
|
+
const connection2 = connections.find((c) => c.id === connectionId);
|
|
345
|
+
if (!connection2) {
|
|
346
|
+
return {
|
|
347
|
+
success: false,
|
|
348
|
+
error: `Connection ${connectionId} not found`
|
|
349
|
+
};
|
|
350
|
+
}
|
|
351
|
+
console.log(
|
|
352
|
+
`[connector-request] zendesk/${connection2.name}: ${method} ${path2}`
|
|
353
|
+
);
|
|
354
|
+
try {
|
|
355
|
+
const subdomain = parameters.subdomain.getValue(connection2);
|
|
356
|
+
const email = parameters.email.getValue(connection2);
|
|
357
|
+
const apiToken = parameters.apiToken.getValue(connection2);
|
|
358
|
+
const authToken = Buffer.from(`${email}/token:${apiToken}`).toString(
|
|
359
|
+
"base64"
|
|
360
|
+
);
|
|
361
|
+
const url = `https://${subdomain}.zendesk.com${path2.startsWith("/") ? "" : "/"}${path2}`;
|
|
362
|
+
const controller = new AbortController();
|
|
363
|
+
const timeout = setTimeout(() => controller.abort(), REQUEST_TIMEOUT_MS);
|
|
364
|
+
try {
|
|
365
|
+
const response = await fetch(url, {
|
|
366
|
+
method,
|
|
367
|
+
headers: {
|
|
368
|
+
Authorization: `Basic ${authToken}`,
|
|
369
|
+
"Content-Type": "application/json"
|
|
370
|
+
},
|
|
371
|
+
body: body ? JSON.stringify(body) : void 0,
|
|
372
|
+
signal: controller.signal
|
|
373
|
+
});
|
|
374
|
+
const data = await response.json();
|
|
375
|
+
if (!response.ok) {
|
|
376
|
+
const errorMessage = typeof data?.error === "string" ? data.error : typeof data?.description === "string" ? data.description : `HTTP ${response.status} ${response.statusText}`;
|
|
377
|
+
return { success: false, error: errorMessage };
|
|
378
|
+
}
|
|
379
|
+
return { success: true, status: response.status, data };
|
|
380
|
+
} finally {
|
|
381
|
+
clearTimeout(timeout);
|
|
382
|
+
}
|
|
383
|
+
} catch (err) {
|
|
384
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
385
|
+
return { success: false, error: msg };
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
});
|
|
389
|
+
|
|
390
|
+
// ../connectors/src/connectors/zendesk/index.ts
|
|
391
|
+
var tools = { request: requestTool };
|
|
392
|
+
var zendeskConnector = new ConnectorPlugin({
|
|
393
|
+
slug: "zendesk",
|
|
394
|
+
authType: AUTH_TYPES.API_KEY,
|
|
395
|
+
name: "Zendesk",
|
|
396
|
+
description: "Connect to Zendesk Support for tickets, users, organizations, and customer service data using an API token.",
|
|
397
|
+
iconUrl: "https://images.ctfassets.net/9ncizv60xc5y/7e9Q7PwV6MJRJMj543m2gl/55385fae903ccfa1599e35be9d3516aa/zendesk-icon.svg",
|
|
398
|
+
parameters,
|
|
399
|
+
releaseFlag: { dev1: true, dev2: false, prod: false },
|
|
400
|
+
onboarding: zendeskOnboarding,
|
|
401
|
+
systemPrompt: {
|
|
402
|
+
en: `### Tools
|
|
403
|
+
|
|
404
|
+
- \`zendesk_request\`: The only way to call the Zendesk Support API. Use it to query tickets, users, organizations, groups, and perform searches. Authentication (Basic auth with email/token) is configured automatically. Zendesk uses cursor-based pagination with \`page[size]\` and \`page[after]\` parameters. All endpoint paths end with \`.json\`.
|
|
405
|
+
|
|
406
|
+
### Business Logic
|
|
407
|
+
|
|
408
|
+
The business logic type for this connector is "typescript". Use the connector SDK in your handler. Do NOT read credentials from environment variables.
|
|
409
|
+
|
|
410
|
+
SDK methods (client created via \`connection(connectionId)\`):
|
|
411
|
+
- \`client.request(path, init?)\` \u2014 low-level authenticated fetch
|
|
412
|
+
- \`client.listTickets(options?)\` \u2014 list tickets with pagination (status, sort_by, sort_order, per_page, page_after)
|
|
413
|
+
- \`client.getTicket(ticketId)\` \u2014 fetch a single ticket
|
|
414
|
+
- \`client.listUsers(options?)\` \u2014 list users with pagination (role, per_page, page_after)
|
|
415
|
+
- \`client.getUser(userId)\` \u2014 fetch a single user
|
|
416
|
+
- \`client.search(query, options?)\` \u2014 search using Zendesk query syntax
|
|
417
|
+
- \`client.listOrganizations(options?)\` \u2014 list organizations with pagination
|
|
418
|
+
|
|
419
|
+
\`\`\`ts
|
|
420
|
+
import type { Context } from "hono";
|
|
421
|
+
import { connection } from "@squadbase/vite-server/connectors/zendesk";
|
|
422
|
+
|
|
423
|
+
const zendesk = connection("<connectionId>");
|
|
424
|
+
|
|
425
|
+
export default async function handler(c: Context) {
|
|
426
|
+
const { tickets, meta } = await zendesk.listTickets({
|
|
427
|
+
status: "open",
|
|
428
|
+
sort_by: "updated_at",
|
|
429
|
+
sort_order: "desc",
|
|
430
|
+
per_page: 100,
|
|
431
|
+
});
|
|
432
|
+
|
|
433
|
+
return c.json({ tickets, hasMore: meta?.has_more });
|
|
434
|
+
}
|
|
435
|
+
\`\`\`
|
|
436
|
+
|
|
437
|
+
### Zendesk API Reference
|
|
438
|
+
|
|
439
|
+
- Base URL: \`https://{subdomain}.zendesk.com\`
|
|
440
|
+
- Authentication: Basic auth with \`{email}/token:{api_token}\` (handled automatically)
|
|
441
|
+
- Pagination: Cursor-based with \`page[size]\` (max 100) and \`page[after]\` parameters
|
|
442
|
+
|
|
443
|
+
#### Tickets
|
|
444
|
+
- GET \`/api/v2/tickets.json\` \u2014 List tickets
|
|
445
|
+
- GET \`/api/v2/tickets/{id}.json\` \u2014 Get a ticket
|
|
446
|
+
- POST \`/api/v2/tickets.json\` \u2014 Create a ticket (body: \`{ "ticket": { "subject": "...", "comment": { "body": "..." } } }\`)
|
|
447
|
+
- PUT \`/api/v2/tickets/{id}.json\` \u2014 Update a ticket
|
|
448
|
+
- DELETE \`/api/v2/tickets/{id}.json\` \u2014 Delete a ticket
|
|
449
|
+
- GET \`/api/v2/tickets/{id}/comments.json\` \u2014 List ticket comments
|
|
450
|
+
|
|
451
|
+
#### Users
|
|
452
|
+
- GET \`/api/v2/users.json\` \u2014 List users
|
|
453
|
+
- GET \`/api/v2/users/{id}.json\` \u2014 Get a user
|
|
454
|
+
- POST \`/api/v2/users.json\` \u2014 Create a user
|
|
455
|
+
- GET \`/api/v2/users/{id}/identities.json\` \u2014 List user identities
|
|
456
|
+
|
|
457
|
+
#### Organizations
|
|
458
|
+
- GET \`/api/v2/organizations.json\` \u2014 List organizations
|
|
459
|
+
- GET \`/api/v2/organizations/{id}.json\` \u2014 Get an organization
|
|
460
|
+
- GET \`/api/v2/organizations/{id}/tickets.json\` \u2014 List organization tickets
|
|
461
|
+
|
|
462
|
+
#### Groups
|
|
463
|
+
- GET \`/api/v2/groups.json\` \u2014 List groups
|
|
464
|
+
- GET \`/api/v2/groups/{id}.json\` \u2014 Get a group
|
|
465
|
+
|
|
466
|
+
#### Search
|
|
467
|
+
- GET \`/api/v2/search.json?query={query}\` \u2014 Search tickets, users, organizations
|
|
468
|
+
- Query params: \`sort_by\` (updated_at, created_at, priority, status), \`sort_order\` (asc, desc)
|
|
469
|
+
|
|
470
|
+
#### Ticket Fields & Forms
|
|
471
|
+
- GET \`/api/v2/ticket_fields.json\` \u2014 List ticket fields
|
|
472
|
+
- GET \`/api/v2/ticket_forms.json\` \u2014 List ticket forms
|
|
473
|
+
|
|
474
|
+
#### Views
|
|
475
|
+
- GET \`/api/v2/views.json\` \u2014 List views
|
|
476
|
+
- GET \`/api/v2/views/{id}/tickets.json\` \u2014 List tickets in a view
|
|
477
|
+
|
|
478
|
+
#### Tags
|
|
479
|
+
- GET \`/api/v2/tags.json\` \u2014 List tags
|
|
480
|
+
|
|
481
|
+
#### Common Search Queries
|
|
482
|
+
- \`type:ticket status:open\` \u2014 Open tickets
|
|
483
|
+
- \`type:ticket priority:high\` \u2014 High priority tickets
|
|
484
|
+
- \`type:ticket assignee:{name}\` \u2014 Tickets assigned to a user
|
|
485
|
+
- \`type:ticket created>{date}\` \u2014 Tickets created after a date
|
|
486
|
+
- \`type:user role:agent\` \u2014 Agent users
|
|
487
|
+
- \`type:organization {name}\` \u2014 Organizations matching a name`,
|
|
488
|
+
ja: `### \u30C4\u30FC\u30EB
|
|
489
|
+
|
|
490
|
+
- \`zendesk_request\`: Zendesk Support API\u3092\u547C\u3073\u51FA\u3059\u552F\u4E00\u306E\u624B\u6BB5\u3067\u3059\u3002\u30C1\u30B1\u30C3\u30C8\u3001\u30E6\u30FC\u30B6\u30FC\u3001\u7D44\u7E54\u3001\u30B0\u30EB\u30FC\u30D7\u306E\u30AF\u30A8\u30EA\u3084\u691C\u7D22\u306B\u4F7F\u7528\u3057\u307E\u3059\u3002\u8A8D\u8A3C\uFF08\u30E1\u30FC\u30EB/\u30C8\u30FC\u30AF\u30F3\u306B\u3088\u308BBasic\u8A8D\u8A3C\uFF09\u306F\u81EA\u52D5\u7684\u306B\u8A2D\u5B9A\u3055\u308C\u307E\u3059\u3002Zendesk\u306F \`page[size]\` \u3068 \`page[after]\` \u30D1\u30E9\u30E1\u30FC\u30BF\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\u5168\u3066\u306E\u30A8\u30F3\u30C9\u30DD\u30A4\u30F3\u30C8\u30D1\u30B9\u306F \`.json\` \u3067\u7D42\u308F\u308A\u307E\u3059\u3002
|
|
491
|
+
|
|
492
|
+
### Business Logic
|
|
493
|
+
|
|
494
|
+
\u3053\u306E\u30B3\u30CD\u30AF\u30BF\u306E\u30D3\u30B8\u30CD\u30B9\u30ED\u30B8\u30C3\u30AF\u30BF\u30A4\u30D7\u306F "typescript" \u3067\u3059\u3002\u30CF\u30F3\u30C9\u30E9\u5185\u3067\u306F\u30B3\u30CD\u30AF\u30BFSDK\u3092\u4F7F\u7528\u3057\u3066\u304F\u3060\u3055\u3044\u3002\u74B0\u5883\u5909\u6570\u304B\u3089\u8A8D\u8A3C\u60C5\u5831\u3092\u8AAD\u307F\u53D6\u3089\u306A\u3044\u3067\u304F\u3060\u3055\u3044\u3002
|
|
495
|
+
|
|
496
|
+
SDK\u30E1\u30BD\u30C3\u30C9 (\`connection(connectionId)\` \u3067\u4F5C\u6210\u3057\u305F\u30AF\u30E9\u30A4\u30A2\u30F3\u30C8):
|
|
497
|
+
- \`client.request(path, init?)\` \u2014 \u4F4E\u30EC\u30D9\u30EB\u306E\u8A8D\u8A3C\u4ED8\u304Dfetch
|
|
498
|
+
- \`client.listTickets(options?)\` \u2014 \u30DA\u30FC\u30B8\u30CD\u30FC\u30B7\u30E7\u30F3\u4ED8\u304D\u3067\u30C1\u30B1\u30C3\u30C8\u3092\u4E00\u89A7\u53D6\u5F97\uFF08status, sort_by, sort_order, per_page, page_after\uFF09
|
|
499
|
+
- \`client.getTicket(ticketId)\` \u2014 \u5358\u4E00\u30C1\u30B1\u30C3\u30C8\u3092\u53D6\u5F97
|
|
500
|
+
- \`client.listUsers(options?)\` \u2014 \u30DA\u30FC\u30B8\u30CD\u30FC\u30B7\u30E7\u30F3\u4ED8\u304D\u3067\u30E6\u30FC\u30B6\u30FC\u3092\u4E00\u89A7\u53D6\u5F97\uFF08role, per_page, page_after\uFF09
|
|
501
|
+
- \`client.getUser(userId)\` \u2014 \u5358\u4E00\u30E6\u30FC\u30B6\u30FC\u3092\u53D6\u5F97
|
|
502
|
+
- \`client.search(query, options?)\` \u2014 Zendesk\u691C\u7D22\u69CB\u6587\u3067\u691C\u7D22
|
|
503
|
+
- \`client.listOrganizations(options?)\` \u2014 \u30DA\u30FC\u30B8\u30CD\u30FC\u30B7\u30E7\u30F3\u4ED8\u304D\u3067\u7D44\u7E54\u3092\u4E00\u89A7\u53D6\u5F97
|
|
504
|
+
|
|
505
|
+
\`\`\`ts
|
|
506
|
+
import type { Context } from "hono";
|
|
507
|
+
import { connection } from "@squadbase/vite-server/connectors/zendesk";
|
|
508
|
+
|
|
509
|
+
const zendesk = connection("<connectionId>");
|
|
510
|
+
|
|
511
|
+
export default async function handler(c: Context) {
|
|
512
|
+
const { tickets, meta } = await zendesk.listTickets({
|
|
513
|
+
status: "open",
|
|
514
|
+
sort_by: "updated_at",
|
|
515
|
+
sort_order: "desc",
|
|
516
|
+
per_page: 100,
|
|
517
|
+
});
|
|
518
|
+
|
|
519
|
+
return c.json({ tickets, hasMore: meta?.has_more });
|
|
520
|
+
}
|
|
521
|
+
\`\`\`
|
|
522
|
+
|
|
523
|
+
### Zendesk API \u30EA\u30D5\u30A1\u30EC\u30F3\u30B9
|
|
524
|
+
|
|
525
|
+
- \u30D9\u30FC\u30B9URL: \`https://{subdomain}.zendesk.com\`
|
|
526
|
+
- \u8A8D\u8A3C: \`{email}/token:{api_token}\` \u306B\u3088\u308BBasic\u8A8D\u8A3C\uFF08\u81EA\u52D5\u8A2D\u5B9A\uFF09
|
|
527
|
+
- \u30DA\u30FC\u30B8\u30CD\u30FC\u30B7\u30E7\u30F3: \`page[size]\`\uFF08\u6700\u5927100\uFF09\u3068 \`page[after]\` \u30D1\u30E9\u30E1\u30FC\u30BF\u306B\u3088\u308B\u30AB\u30FC\u30BD\u30EB\u30D9\u30FC\u30B9
|
|
528
|
+
|
|
529
|
+
#### \u30C1\u30B1\u30C3\u30C8
|
|
530
|
+
- GET \`/api/v2/tickets.json\` \u2014 \u30C1\u30B1\u30C3\u30C8\u4E00\u89A7\u3092\u53D6\u5F97
|
|
531
|
+
- GET \`/api/v2/tickets/{id}.json\` \u2014 \u30C1\u30B1\u30C3\u30C8\u3092\u53D6\u5F97
|
|
532
|
+
- POST \`/api/v2/tickets.json\` \u2014 \u30C1\u30B1\u30C3\u30C8\u3092\u4F5C\u6210\uFF08body: \`{ "ticket": { "subject": "...", "comment": { "body": "..." } } }\`\uFF09
|
|
533
|
+
- PUT \`/api/v2/tickets/{id}.json\` \u2014 \u30C1\u30B1\u30C3\u30C8\u3092\u66F4\u65B0
|
|
534
|
+
- DELETE \`/api/v2/tickets/{id}.json\` \u2014 \u30C1\u30B1\u30C3\u30C8\u3092\u524A\u9664
|
|
535
|
+
- GET \`/api/v2/tickets/{id}/comments.json\` \u2014 \u30C1\u30B1\u30C3\u30C8\u30B3\u30E1\u30F3\u30C8\u4E00\u89A7\u3092\u53D6\u5F97
|
|
536
|
+
|
|
537
|
+
#### \u30E6\u30FC\u30B6\u30FC
|
|
538
|
+
- GET \`/api/v2/users.json\` \u2014 \u30E6\u30FC\u30B6\u30FC\u4E00\u89A7\u3092\u53D6\u5F97
|
|
539
|
+
- GET \`/api/v2/users/{id}.json\` \u2014 \u30E6\u30FC\u30B6\u30FC\u3092\u53D6\u5F97
|
|
540
|
+
- POST \`/api/v2/users.json\` \u2014 \u30E6\u30FC\u30B6\u30FC\u3092\u4F5C\u6210
|
|
541
|
+
- GET \`/api/v2/users/{id}/identities.json\` \u2014 \u30E6\u30FC\u30B6\u30FCID\u3092\u4E00\u89A7\u53D6\u5F97
|
|
542
|
+
|
|
543
|
+
#### \u7D44\u7E54
|
|
544
|
+
- GET \`/api/v2/organizations.json\` \u2014 \u7D44\u7E54\u4E00\u89A7\u3092\u53D6\u5F97
|
|
545
|
+
- GET \`/api/v2/organizations/{id}.json\` \u2014 \u7D44\u7E54\u3092\u53D6\u5F97
|
|
546
|
+
- GET \`/api/v2/organizations/{id}/tickets.json\` \u2014 \u7D44\u7E54\u306E\u30C1\u30B1\u30C3\u30C8\u4E00\u89A7\u3092\u53D6\u5F97
|
|
547
|
+
|
|
548
|
+
#### \u30B0\u30EB\u30FC\u30D7
|
|
549
|
+
- GET \`/api/v2/groups.json\` \u2014 \u30B0\u30EB\u30FC\u30D7\u4E00\u89A7\u3092\u53D6\u5F97
|
|
550
|
+
- GET \`/api/v2/groups/{id}.json\` \u2014 \u30B0\u30EB\u30FC\u30D7\u3092\u53D6\u5F97
|
|
551
|
+
|
|
552
|
+
#### \u691C\u7D22
|
|
553
|
+
- GET \`/api/v2/search.json?query={query}\` \u2014 \u30C1\u30B1\u30C3\u30C8\u3001\u30E6\u30FC\u30B6\u30FC\u3001\u7D44\u7E54\u3092\u691C\u7D22
|
|
554
|
+
- \u30AF\u30A8\u30EA\u30D1\u30E9\u30E1\u30FC\u30BF: \`sort_by\`\uFF08updated_at, created_at, priority, status\uFF09\u3001\`sort_order\`\uFF08asc, desc\uFF09
|
|
555
|
+
|
|
556
|
+
#### \u30C1\u30B1\u30C3\u30C8\u30D5\u30A3\u30FC\u30EB\u30C9\u30FB\u30D5\u30A9\u30FC\u30E0
|
|
557
|
+
- GET \`/api/v2/ticket_fields.json\` \u2014 \u30C1\u30B1\u30C3\u30C8\u30D5\u30A3\u30FC\u30EB\u30C9\u4E00\u89A7\u3092\u53D6\u5F97
|
|
558
|
+
- GET \`/api/v2/ticket_forms.json\` \u2014 \u30C1\u30B1\u30C3\u30C8\u30D5\u30A9\u30FC\u30E0\u4E00\u89A7\u3092\u53D6\u5F97
|
|
559
|
+
|
|
560
|
+
#### \u30D3\u30E5\u30FC
|
|
561
|
+
- GET \`/api/v2/views.json\` \u2014 \u30D3\u30E5\u30FC\u4E00\u89A7\u3092\u53D6\u5F97
|
|
562
|
+
- GET \`/api/v2/views/{id}/tickets.json\` \u2014 \u30D3\u30E5\u30FC\u5185\u306E\u30C1\u30B1\u30C3\u30C8\u4E00\u89A7\u3092\u53D6\u5F97
|
|
563
|
+
|
|
564
|
+
#### \u30BF\u30B0
|
|
565
|
+
- GET \`/api/v2/tags.json\` \u2014 \u30BF\u30B0\u4E00\u89A7\u3092\u53D6\u5F97
|
|
566
|
+
|
|
567
|
+
#### \u3088\u304F\u4F7F\u3046\u691C\u7D22\u30AF\u30A8\u30EA
|
|
568
|
+
- \`type:ticket status:open\` \u2014 \u672A\u89E3\u6C7A\u30C1\u30B1\u30C3\u30C8
|
|
569
|
+
- \`type:ticket priority:high\` \u2014 \u9AD8\u512A\u5148\u5EA6\u30C1\u30B1\u30C3\u30C8
|
|
570
|
+
- \`type:ticket assignee:{name}\` \u2014 \u7279\u5B9A\u30E6\u30FC\u30B6\u30FC\u306B\u5272\u308A\u5F53\u3066\u3089\u308C\u305F\u30C1\u30B1\u30C3\u30C8
|
|
571
|
+
- \`type:ticket created>{date}\` \u2014 \u7279\u5B9A\u65E5\u4EE5\u964D\u306B\u4F5C\u6210\u3055\u308C\u305F\u30C1\u30B1\u30C3\u30C8
|
|
572
|
+
- \`type:user role:agent\` \u2014 \u30A8\u30FC\u30B8\u30A7\u30F3\u30C8\u30E6\u30FC\u30B6\u30FC
|
|
573
|
+
- \`type:organization {name}\` \u2014 \u540D\u524D\u304C\u4E00\u81F4\u3059\u308B\u7D44\u7E54`
|
|
574
|
+
},
|
|
575
|
+
tools
|
|
576
|
+
});
|
|
577
|
+
|
|
578
|
+
// src/connectors/create-connector-sdk.ts
|
|
579
|
+
import { readFileSync } from "fs";
|
|
580
|
+
import path from "path";
|
|
581
|
+
|
|
582
|
+
// src/connector-client/env.ts
|
|
583
|
+
function resolveEnvVar(entry, key, connectionId) {
|
|
584
|
+
const envVarName = entry.envVars[key];
|
|
585
|
+
if (!envVarName) {
|
|
586
|
+
throw new Error(`Connection "${connectionId}" is missing envVars mapping for key "${key}"`);
|
|
587
|
+
}
|
|
588
|
+
const value = process.env[envVarName];
|
|
589
|
+
if (!value) {
|
|
590
|
+
throw new Error(`Environment variable "${envVarName}" (for connection "${connectionId}", key "${key}") is not set`);
|
|
591
|
+
}
|
|
592
|
+
return value;
|
|
593
|
+
}
|
|
594
|
+
function resolveEnvVarOptional(entry, key) {
|
|
595
|
+
const envVarName = entry.envVars[key];
|
|
596
|
+
if (!envVarName) return void 0;
|
|
597
|
+
return process.env[envVarName] || void 0;
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
// src/connector-client/proxy-fetch.ts
|
|
601
|
+
import { getContext } from "hono/context-storage";
|
|
602
|
+
import { getCookie } from "hono/cookie";
|
|
603
|
+
var APP_SESSION_COOKIE_NAME = "__Host-squadbase-session";
|
|
604
|
+
function createSandboxProxyFetch(connectionId) {
|
|
605
|
+
return async (input, init) => {
|
|
606
|
+
const token = process.env.INTERNAL_SQUADBASE_OAUTH_MACHINE_CREDENTIAL;
|
|
607
|
+
const sandboxId = process.env.INTERNAL_SQUADBASE_SANDBOX_ID;
|
|
608
|
+
if (!token || !sandboxId) {
|
|
609
|
+
throw new Error(
|
|
610
|
+
"Connection proxy is not configured. Please check your deployment settings."
|
|
611
|
+
);
|
|
612
|
+
}
|
|
613
|
+
const originalUrl = typeof input === "string" ? input : input instanceof URL ? input.href : input.url;
|
|
614
|
+
const originalMethod = init?.method ?? "GET";
|
|
615
|
+
const originalBody = init?.body ? JSON.parse(init.body) : void 0;
|
|
616
|
+
const baseDomain = process.env["SQUADBASE_PREVIEW_BASE_DOMAIN"] ?? "preview.app.squadbase.dev";
|
|
617
|
+
const proxyUrl = `https://${sandboxId}.${baseDomain}/_sqcore/connections/${connectionId}/request`;
|
|
618
|
+
return fetch(proxyUrl, {
|
|
619
|
+
method: "POST",
|
|
620
|
+
headers: {
|
|
621
|
+
"Content-Type": "application/json",
|
|
622
|
+
Authorization: `Bearer ${token}`
|
|
623
|
+
},
|
|
624
|
+
body: JSON.stringify({
|
|
625
|
+
url: originalUrl,
|
|
626
|
+
method: originalMethod,
|
|
627
|
+
body: originalBody
|
|
628
|
+
})
|
|
629
|
+
});
|
|
630
|
+
};
|
|
631
|
+
}
|
|
632
|
+
function createDeployedAppProxyFetch(connectionId) {
|
|
633
|
+
const projectId = process.env["SQUADBASE_PROJECT_ID"];
|
|
634
|
+
if (!projectId) {
|
|
635
|
+
throw new Error(
|
|
636
|
+
"Connection proxy is not configured. Please check your deployment settings."
|
|
637
|
+
);
|
|
638
|
+
}
|
|
639
|
+
const baseDomain = process.env["SQUADBASE_APP_BASE_DOMAIN"] ?? "squadbase.app";
|
|
640
|
+
const proxyUrl = `https://${projectId}.${baseDomain}/_sqcore/connections/${connectionId}/request`;
|
|
641
|
+
return async (input, init) => {
|
|
642
|
+
const originalUrl = typeof input === "string" ? input : input instanceof URL ? input.href : input.url;
|
|
643
|
+
const originalMethod = init?.method ?? "GET";
|
|
644
|
+
const originalBody = init?.body ? JSON.parse(init.body) : void 0;
|
|
645
|
+
const c = getContext();
|
|
646
|
+
const appSession = getCookie(c, APP_SESSION_COOKIE_NAME);
|
|
647
|
+
if (!appSession) {
|
|
648
|
+
throw new Error(
|
|
649
|
+
"No authentication method available for connection proxy."
|
|
650
|
+
);
|
|
651
|
+
}
|
|
652
|
+
return fetch(proxyUrl, {
|
|
653
|
+
method: "POST",
|
|
654
|
+
headers: {
|
|
655
|
+
"Content-Type": "application/json",
|
|
656
|
+
Authorization: `Bearer ${appSession}`
|
|
657
|
+
},
|
|
658
|
+
body: JSON.stringify({
|
|
659
|
+
url: originalUrl,
|
|
660
|
+
method: originalMethod,
|
|
661
|
+
body: originalBody
|
|
662
|
+
})
|
|
663
|
+
});
|
|
664
|
+
};
|
|
665
|
+
}
|
|
666
|
+
function createProxyFetch(connectionId) {
|
|
667
|
+
if (process.env.INTERNAL_SQUADBASE_SANDBOX_ID) {
|
|
668
|
+
return createSandboxProxyFetch(connectionId);
|
|
669
|
+
}
|
|
670
|
+
return createDeployedAppProxyFetch(connectionId);
|
|
671
|
+
}
|
|
672
|
+
|
|
673
|
+
// src/connectors/create-connector-sdk.ts
|
|
674
|
+
function loadConnectionsSync() {
|
|
675
|
+
const filePath = process.env.CONNECTIONS_PATH ?? path.join(process.cwd(), ".squadbase/connections.json");
|
|
676
|
+
try {
|
|
677
|
+
const raw = readFileSync(filePath, "utf-8");
|
|
678
|
+
return JSON.parse(raw);
|
|
679
|
+
} catch {
|
|
680
|
+
return {};
|
|
681
|
+
}
|
|
682
|
+
}
|
|
683
|
+
function createConnectorSdk(plugin, createClient2) {
|
|
684
|
+
return (connectionId) => {
|
|
685
|
+
const connections = loadConnectionsSync();
|
|
686
|
+
const entry = connections[connectionId];
|
|
687
|
+
if (!entry) {
|
|
688
|
+
throw new Error(
|
|
689
|
+
`Connection "${connectionId}" not found in .squadbase/connections.json`
|
|
690
|
+
);
|
|
691
|
+
}
|
|
692
|
+
if (entry.connector.slug !== plugin.slug) {
|
|
693
|
+
throw new Error(
|
|
694
|
+
`Connection "${connectionId}" is not a ${plugin.slug} connection (got "${entry.connector.slug}")`
|
|
695
|
+
);
|
|
696
|
+
}
|
|
697
|
+
const params = {};
|
|
698
|
+
for (const param of Object.values(plugin.parameters)) {
|
|
699
|
+
if (param.required) {
|
|
700
|
+
params[param.slug] = resolveEnvVar(entry, param.slug, connectionId);
|
|
701
|
+
} else {
|
|
702
|
+
const val = resolveEnvVarOptional(entry, param.slug);
|
|
703
|
+
if (val !== void 0) params[param.slug] = val;
|
|
704
|
+
}
|
|
705
|
+
}
|
|
706
|
+
return createClient2(params, createProxyFetch(connectionId));
|
|
707
|
+
};
|
|
708
|
+
}
|
|
709
|
+
|
|
710
|
+
// src/connectors/entries/zendesk.ts
|
|
711
|
+
var connection = createConnectorSdk(zendeskConnector, createClient);
|
|
712
|
+
export {
|
|
713
|
+
connection
|
|
714
|
+
};
|