@squadbase/vite-server 0.1.9-dev.87dd3f7 → 0.1.9-dev.a57a0ac
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 +74937 -61829
- package/dist/connectors/asana.js +15 -2
- package/dist/connectors/aws-billing.d.ts +5 -0
- package/dist/connectors/aws-billing.js +29843 -0
- package/dist/connectors/azure-sql.d.ts +5 -0
- package/dist/connectors/azure-sql.js +657 -0
- package/dist/connectors/clickup.d.ts +5 -0
- package/dist/connectors/clickup.js +850 -0
- package/dist/connectors/freshdesk.d.ts +5 -0
- package/dist/connectors/freshdesk.js +842 -0
- package/dist/connectors/freshsales.d.ts +5 -0
- package/dist/connectors/freshsales.js +867 -0
- package/dist/connectors/freshservice.d.ts +5 -0
- package/dist/connectors/freshservice.js +813 -0
- package/dist/connectors/github.d.ts +5 -0
- package/dist/connectors/github.js +963 -0
- package/dist/connectors/gmail-oauth.js +15 -2
- package/dist/connectors/gmail.js +23 -14
- package/dist/connectors/google-audit-log.js +25 -14
- package/dist/connectors/google-calendar-oauth.js +18 -2
- package/dist/connectors/google-calendar.js +40 -26
- package/dist/connectors/google-docs.js +18 -2
- package/dist/connectors/google-drive.js +15 -2
- package/dist/connectors/google-search-console-oauth.d.ts +5 -0
- package/dist/connectors/google-search-console-oauth.js +954 -0
- package/dist/connectors/google-sheets.js +18 -2
- package/dist/connectors/google-slides.js +18 -2
- package/dist/connectors/jdbc.d.ts +5 -0
- package/dist/connectors/jdbc.js +21097 -0
- package/dist/connectors/monday.d.ts +5 -0
- package/dist/connectors/monday.js +853 -0
- package/dist/connectors/oracle.d.ts +5 -0
- package/dist/connectors/oracle.js +665 -0
- package/dist/connectors/semrush.d.ts +5 -0
- package/dist/connectors/semrush.js +812 -0
- package/dist/connectors/sqlserver.d.ts +5 -0
- package/dist/connectors/sqlserver.js +656 -0
- package/dist/connectors/supabase.d.ts +5 -0
- package/dist/connectors/supabase.js +582 -0
- package/dist/connectors/tiktok-ads.js +15 -2
- package/dist/index.js +73506 -60398
- package/dist/main.js +73500 -60392
- package/dist/vite-plugin.js +73405 -60297
- package/package.json +60 -2
|
@@ -0,0 +1,813 @@
|
|
|
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/freshservice/parameters.ts
|
|
46
|
+
var parameters = {
|
|
47
|
+
domain: new ParameterDefinition({
|
|
48
|
+
slug: "domain",
|
|
49
|
+
name: "Freshservice Domain",
|
|
50
|
+
description: "Your Freshservice subdomain (e.g. `acme` for `https://acme.freshservice.com`). Provide just the subdomain without `https://` or the rest of the URL.",
|
|
51
|
+
envVarBaseKey: "FRESHSERVICE_DOMAIN",
|
|
52
|
+
type: "text",
|
|
53
|
+
secret: false,
|
|
54
|
+
required: true
|
|
55
|
+
}),
|
|
56
|
+
apiKey: new ParameterDefinition({
|
|
57
|
+
slug: "api-key",
|
|
58
|
+
name: "Freshservice API Key",
|
|
59
|
+
description: "API key for Freshservice. Generate one in Freshservice \u2192 Profile (top-right) \u2192 Profile Settings \u2192 API Key. The key is sent via HTTP Basic Auth (api-key as username, any value as password).",
|
|
60
|
+
envVarBaseKey: "FRESHSERVICE_API_KEY",
|
|
61
|
+
type: "text",
|
|
62
|
+
secret: true,
|
|
63
|
+
required: true
|
|
64
|
+
})
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
// ../connectors/src/connectors/freshservice/sdk/index.ts
|
|
68
|
+
function buildBaseUrl(domain) {
|
|
69
|
+
const trimmed = domain.trim().replace(/^https?:\/\//, "").replace(/\/+$/, "");
|
|
70
|
+
const subdomain = trimmed.split(".")[0];
|
|
71
|
+
return `https://${subdomain}.freshservice.com/api/v2`;
|
|
72
|
+
}
|
|
73
|
+
function basicAuthHeader(apiKey) {
|
|
74
|
+
return `Basic ${Buffer.from(`${apiKey}:X`).toString("base64")}`;
|
|
75
|
+
}
|
|
76
|
+
function createClient(params) {
|
|
77
|
+
const apiKey = params[parameters.apiKey.slug];
|
|
78
|
+
const domain = params[parameters.domain.slug];
|
|
79
|
+
if (!apiKey) {
|
|
80
|
+
throw new Error(
|
|
81
|
+
`freshservice: missing required parameter: ${parameters.apiKey.slug}`
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
if (!domain) {
|
|
85
|
+
throw new Error(
|
|
86
|
+
`freshservice: missing required parameter: ${parameters.domain.slug}`
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
const baseUrl = buildBaseUrl(domain);
|
|
90
|
+
const auth = basicAuthHeader(apiKey);
|
|
91
|
+
function authHeaders(extra) {
|
|
92
|
+
const headers = new Headers(extra);
|
|
93
|
+
headers.set("Authorization", auth);
|
|
94
|
+
headers.set("Content-Type", "application/json");
|
|
95
|
+
headers.set("Accept", "application/json");
|
|
96
|
+
return headers;
|
|
97
|
+
}
|
|
98
|
+
async function assertOk(res, label) {
|
|
99
|
+
if (!res.ok) {
|
|
100
|
+
const body = await res.text().catch(() => "(unreadable body)");
|
|
101
|
+
throw new Error(
|
|
102
|
+
`freshservice ${label}: ${res.status} ${res.statusText} \u2014 ${body}`
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
function buildQuery(base) {
|
|
107
|
+
const search = new URLSearchParams();
|
|
108
|
+
for (const [key, value] of Object.entries(base)) {
|
|
109
|
+
if (value !== void 0) search.set(key, String(value));
|
|
110
|
+
}
|
|
111
|
+
const qs = search.toString();
|
|
112
|
+
return qs ? `?${qs}` : "";
|
|
113
|
+
}
|
|
114
|
+
return {
|
|
115
|
+
request(path2, init) {
|
|
116
|
+
const headers = new Headers(init?.headers);
|
|
117
|
+
headers.set("Authorization", auth);
|
|
118
|
+
if (!headers.has("Content-Type")) {
|
|
119
|
+
headers.set("Content-Type", "application/json");
|
|
120
|
+
}
|
|
121
|
+
if (!headers.has("Accept")) {
|
|
122
|
+
headers.set("Accept", "application/json");
|
|
123
|
+
}
|
|
124
|
+
return fetch(`${baseUrl}${path2}`, { ...init, headers });
|
|
125
|
+
},
|
|
126
|
+
async listTickets(options) {
|
|
127
|
+
const qs = buildQuery({
|
|
128
|
+
page: options?.page,
|
|
129
|
+
per_page: options?.per_page,
|
|
130
|
+
include: options?.include,
|
|
131
|
+
updated_since: options?.updated_since,
|
|
132
|
+
filter: options?.filter
|
|
133
|
+
});
|
|
134
|
+
const res = await fetch(`${baseUrl}/tickets${qs}`, {
|
|
135
|
+
method: "GET",
|
|
136
|
+
headers: authHeaders()
|
|
137
|
+
});
|
|
138
|
+
await assertOk(res, "listTickets");
|
|
139
|
+
return await res.json();
|
|
140
|
+
},
|
|
141
|
+
async getTicket(ticketId, options) {
|
|
142
|
+
const qs = buildQuery({ include: options?.include });
|
|
143
|
+
const res = await fetch(
|
|
144
|
+
`${baseUrl}/tickets/${encodeURIComponent(String(ticketId))}${qs}`,
|
|
145
|
+
{ method: "GET", headers: authHeaders() }
|
|
146
|
+
);
|
|
147
|
+
await assertOk(res, "getTicket");
|
|
148
|
+
return await res.json();
|
|
149
|
+
},
|
|
150
|
+
async createTicket(ticketData) {
|
|
151
|
+
const res = await fetch(`${baseUrl}/tickets`, {
|
|
152
|
+
method: "POST",
|
|
153
|
+
headers: authHeaders(),
|
|
154
|
+
body: JSON.stringify(ticketData)
|
|
155
|
+
});
|
|
156
|
+
await assertOk(res, "createTicket");
|
|
157
|
+
return await res.json();
|
|
158
|
+
},
|
|
159
|
+
async updateTicket(ticketId, ticketData) {
|
|
160
|
+
const res = await fetch(
|
|
161
|
+
`${baseUrl}/tickets/${encodeURIComponent(String(ticketId))}`,
|
|
162
|
+
{
|
|
163
|
+
method: "PUT",
|
|
164
|
+
headers: authHeaders(),
|
|
165
|
+
body: JSON.stringify(ticketData)
|
|
166
|
+
}
|
|
167
|
+
);
|
|
168
|
+
await assertOk(res, "updateTicket");
|
|
169
|
+
return await res.json();
|
|
170
|
+
},
|
|
171
|
+
async listAgents(options) {
|
|
172
|
+
const qs = buildQuery({
|
|
173
|
+
page: options?.page,
|
|
174
|
+
per_page: options?.per_page
|
|
175
|
+
});
|
|
176
|
+
const res = await fetch(`${baseUrl}/agents${qs}`, {
|
|
177
|
+
method: "GET",
|
|
178
|
+
headers: authHeaders()
|
|
179
|
+
});
|
|
180
|
+
await assertOk(res, "listAgents");
|
|
181
|
+
return await res.json();
|
|
182
|
+
},
|
|
183
|
+
async listRequesters(options) {
|
|
184
|
+
const qs = buildQuery({
|
|
185
|
+
page: options?.page,
|
|
186
|
+
per_page: options?.per_page
|
|
187
|
+
});
|
|
188
|
+
const res = await fetch(`${baseUrl}/requesters${qs}`, {
|
|
189
|
+
method: "GET",
|
|
190
|
+
headers: authHeaders()
|
|
191
|
+
});
|
|
192
|
+
await assertOk(res, "listRequesters");
|
|
193
|
+
return await res.json();
|
|
194
|
+
}
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
// ../connectors/src/connector-onboarding.ts
|
|
199
|
+
var ConnectorOnboarding = class {
|
|
200
|
+
/** Phase 1: Connection setup instructions (optional — some connectors don't need this) */
|
|
201
|
+
connectionSetupInstructions;
|
|
202
|
+
/** Phase 2: Data overview instructions */
|
|
203
|
+
dataOverviewInstructions;
|
|
204
|
+
constructor(config) {
|
|
205
|
+
this.connectionSetupInstructions = config.connectionSetupInstructions;
|
|
206
|
+
this.dataOverviewInstructions = config.dataOverviewInstructions;
|
|
207
|
+
}
|
|
208
|
+
getConnectionSetupPrompt(language) {
|
|
209
|
+
return this.connectionSetupInstructions?.[language] ?? null;
|
|
210
|
+
}
|
|
211
|
+
getDataOverviewInstructions(language) {
|
|
212
|
+
return this.dataOverviewInstructions[language];
|
|
213
|
+
}
|
|
214
|
+
};
|
|
215
|
+
|
|
216
|
+
// ../connectors/src/connector-tool.ts
|
|
217
|
+
var ConnectorTool = class {
|
|
218
|
+
name;
|
|
219
|
+
description;
|
|
220
|
+
inputSchema;
|
|
221
|
+
outputSchema;
|
|
222
|
+
_execute;
|
|
223
|
+
constructor(config) {
|
|
224
|
+
this.name = config.name;
|
|
225
|
+
this.description = config.description;
|
|
226
|
+
this.inputSchema = config.inputSchema;
|
|
227
|
+
this.outputSchema = config.outputSchema;
|
|
228
|
+
this._execute = config.execute;
|
|
229
|
+
}
|
|
230
|
+
createTool(connections, config) {
|
|
231
|
+
return {
|
|
232
|
+
description: this.description,
|
|
233
|
+
inputSchema: this.inputSchema,
|
|
234
|
+
outputSchema: this.outputSchema,
|
|
235
|
+
execute: (input) => this._execute(input, connections, config)
|
|
236
|
+
};
|
|
237
|
+
}
|
|
238
|
+
};
|
|
239
|
+
|
|
240
|
+
// ../connectors/src/connector-plugin.ts
|
|
241
|
+
var ConnectorPlugin = class _ConnectorPlugin {
|
|
242
|
+
slug;
|
|
243
|
+
authType;
|
|
244
|
+
name;
|
|
245
|
+
description;
|
|
246
|
+
iconUrl;
|
|
247
|
+
parameters;
|
|
248
|
+
releaseFlag;
|
|
249
|
+
proxyPolicy;
|
|
250
|
+
experimentalAttributes;
|
|
251
|
+
categories;
|
|
252
|
+
onboarding;
|
|
253
|
+
systemPrompt;
|
|
254
|
+
tools;
|
|
255
|
+
query;
|
|
256
|
+
checkConnection;
|
|
257
|
+
constructor(config) {
|
|
258
|
+
this.slug = config.slug;
|
|
259
|
+
this.authType = config.authType;
|
|
260
|
+
this.name = config.name;
|
|
261
|
+
this.description = config.description;
|
|
262
|
+
this.iconUrl = config.iconUrl;
|
|
263
|
+
this.parameters = config.parameters;
|
|
264
|
+
this.releaseFlag = config.releaseFlag;
|
|
265
|
+
this.proxyPolicy = config.proxyPolicy;
|
|
266
|
+
this.experimentalAttributes = config.experimentalAttributes;
|
|
267
|
+
this.categories = config.categories ?? [];
|
|
268
|
+
this.onboarding = config.onboarding;
|
|
269
|
+
this.systemPrompt = config.systemPrompt;
|
|
270
|
+
this.tools = config.tools;
|
|
271
|
+
this.query = config.query;
|
|
272
|
+
this.checkConnection = config.checkConnection;
|
|
273
|
+
}
|
|
274
|
+
get connectorKey() {
|
|
275
|
+
return _ConnectorPlugin.deriveKey(this.slug, this.authType);
|
|
276
|
+
}
|
|
277
|
+
/**
|
|
278
|
+
* Create tools for connections that belong to this connector.
|
|
279
|
+
* Filters connections by connectorKey internally.
|
|
280
|
+
* Returns tools keyed as `${connectorKey}_${toolName}`.
|
|
281
|
+
*/
|
|
282
|
+
createTools(connections, config, opts) {
|
|
283
|
+
const myConnections = connections.filter(
|
|
284
|
+
(c) => _ConnectorPlugin.deriveKey(c.connector.slug, c.connector.authType) === this.connectorKey
|
|
285
|
+
);
|
|
286
|
+
const result = {};
|
|
287
|
+
for (const t of Object.values(this.tools)) {
|
|
288
|
+
const tool = t.createTool(myConnections, config);
|
|
289
|
+
const originalToModelOutput = tool.toModelOutput;
|
|
290
|
+
result[`${this.connectorKey}_${t.name}`] = {
|
|
291
|
+
...tool,
|
|
292
|
+
toModelOutput: async (options) => {
|
|
293
|
+
if (!originalToModelOutput) {
|
|
294
|
+
return opts.truncateOutput(options.output);
|
|
295
|
+
}
|
|
296
|
+
const modelOutput = await originalToModelOutput(options);
|
|
297
|
+
if (modelOutput.type === "text" || modelOutput.type === "json") {
|
|
298
|
+
return opts.truncateOutput(modelOutput.value);
|
|
299
|
+
}
|
|
300
|
+
return modelOutput;
|
|
301
|
+
}
|
|
302
|
+
};
|
|
303
|
+
}
|
|
304
|
+
return result;
|
|
305
|
+
}
|
|
306
|
+
static deriveKey(slug, authType) {
|
|
307
|
+
if (authType) return `${slug}-${authType}`;
|
|
308
|
+
const LEGACY_NULL_AUTH_TYPE_MAP = {
|
|
309
|
+
// user-password
|
|
310
|
+
"postgresql": "user-password",
|
|
311
|
+
"mysql": "user-password",
|
|
312
|
+
"clickhouse": "user-password",
|
|
313
|
+
"kintone": "user-password",
|
|
314
|
+
"squadbase-db": "user-password",
|
|
315
|
+
// service-account
|
|
316
|
+
"snowflake": "service-account",
|
|
317
|
+
"bigquery": "service-account",
|
|
318
|
+
"google-analytics": "service-account",
|
|
319
|
+
"google-calendar": "service-account",
|
|
320
|
+
"aws-athena": "service-account",
|
|
321
|
+
"redshift": "service-account",
|
|
322
|
+
// api-key
|
|
323
|
+
"databricks": "api-key",
|
|
324
|
+
"dbt": "api-key",
|
|
325
|
+
"airtable": "api-key",
|
|
326
|
+
"openai": "api-key",
|
|
327
|
+
"gemini": "api-key",
|
|
328
|
+
"anthropic": "api-key",
|
|
329
|
+
"wix-store": "api-key"
|
|
330
|
+
};
|
|
331
|
+
const fallbackAuthType = LEGACY_NULL_AUTH_TYPE_MAP[slug];
|
|
332
|
+
if (fallbackAuthType) return `${slug}-${fallbackAuthType}`;
|
|
333
|
+
return slug;
|
|
334
|
+
}
|
|
335
|
+
};
|
|
336
|
+
|
|
337
|
+
// ../connectors/src/auth-types.ts
|
|
338
|
+
var AUTH_TYPES = {
|
|
339
|
+
OAUTH: "oauth",
|
|
340
|
+
API_KEY: "api-key",
|
|
341
|
+
JWT: "jwt",
|
|
342
|
+
SERVICE_ACCOUNT: "service-account",
|
|
343
|
+
PAT: "pat",
|
|
344
|
+
USER_PASSWORD: "user-password"
|
|
345
|
+
};
|
|
346
|
+
|
|
347
|
+
// ../connectors/src/lib/normalize-path.ts
|
|
348
|
+
function normalizeRequestPath(path2, basePathSegment) {
|
|
349
|
+
let p = path2.trim();
|
|
350
|
+
if (!p.startsWith("/")) p = "/" + p;
|
|
351
|
+
if (p === basePathSegment || p.startsWith(basePathSegment + "/")) {
|
|
352
|
+
p = p.slice(basePathSegment.length) || "/";
|
|
353
|
+
}
|
|
354
|
+
return p;
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
// ../connectors/src/connectors/freshservice/setup.ts
|
|
358
|
+
var freshserviceOnboarding = new ConnectorOnboarding({
|
|
359
|
+
dataOverviewInstructions: {
|
|
360
|
+
en: `1. Call freshservice_request with GET /agents to confirm credentials and view available agents.
|
|
361
|
+
2. Call freshservice_request with GET /tickets?per_page=10 to sample recent tickets. Each ticket has \`status\`, \`priority\`, \`source\`, \`responder_id\`, \`requester_id\`, and \`created_at\`.
|
|
362
|
+
3. To enumerate organisational structure, call GET /departments and GET /locations.
|
|
363
|
+
4. For asset inventory, call GET /assets?per_page=10 \u2014 note that ITAM endpoints require the asset module to be enabled.
|
|
364
|
+
5. Pagination is page-based with \`page\` (1-indexed) and \`per_page\` (max 100). The \`Link\` response header carries the next-page URL when more results exist.`,
|
|
365
|
+
ja: `1. freshservice_request \u3067 GET /agents \u3092\u547C\u3073\u51FA\u3057\u3001\u8A8D\u8A3C\u60C5\u5831\u306E\u78BA\u8A8D\u3068\u5229\u7528\u53EF\u80FD\u306A\u30A8\u30FC\u30B8\u30A7\u30F3\u30C8\u4E00\u89A7\u3092\u53D6\u5F97\u3057\u307E\u3059\u3002
|
|
366
|
+
2. freshservice_request \u3067 GET /tickets?per_page=10 \u3092\u547C\u3073\u51FA\u3057\u3066\u6700\u8FD1\u306E\u30C1\u30B1\u30C3\u30C8\u3092\u30B5\u30F3\u30D7\u30EA\u30F3\u30B0\u3057\u307E\u3059\u3002\u5404\u30C1\u30B1\u30C3\u30C8\u306B\u306F \`status\`, \`priority\`, \`source\`, \`responder_id\`, \`requester_id\`, \`created_at\` \u306A\u3069\u304C\u542B\u307E\u308C\u307E\u3059\u3002
|
|
367
|
+
3. \u7D44\u7E54\u69CB\u9020\u3092\u628A\u63E1\u3059\u308B\u306B\u306F GET /departments \u304A\u3088\u3073 GET /locations \u3092\u547C\u3073\u51FA\u3057\u307E\u3059\u3002
|
|
368
|
+
4. \u8CC7\u7523\u30A4\u30F3\u30D9\u30F3\u30C8\u30EA\u306F GET /assets?per_page=10 \u3067\u53D6\u5F97\u3067\u304D\u307E\u3059\uFF08ITAM \u30E2\u30B8\u30E5\u30FC\u30EB\u304C\u6709\u52B9\u3067\u3042\u308B\u5FC5\u8981\u304C\u3042\u308A\u307E\u3059\uFF09\u3002
|
|
369
|
+
5. \u30DA\u30FC\u30B8\u30CD\u30FC\u30B7\u30E7\u30F3\u306F1\u59CB\u307E\u308A\u306E \`page\` \u3068 \`per_page\`\uFF08\u6700\u5927100\uFF09\u3002\u6B21\u30DA\u30FC\u30B8\u304C\u5B58\u5728\u3059\u308B\u5834\u5408\u306F \`Link\` \u30EC\u30B9\u30DD\u30F3\u30B9\u30D8\u30C3\u30C0\u306B\u6B21URL\u304C\u542B\u307E\u308C\u307E\u3059\u3002`
|
|
370
|
+
}
|
|
371
|
+
});
|
|
372
|
+
|
|
373
|
+
// ../connectors/src/connectors/freshservice/tools/request.ts
|
|
374
|
+
import { z } from "zod";
|
|
375
|
+
var BASE_PATH_SEGMENT = "/api/v2";
|
|
376
|
+
var REQUEST_TIMEOUT_MS = 6e4;
|
|
377
|
+
function buildBaseUrl2(domain) {
|
|
378
|
+
const trimmed = domain.trim().replace(/^https?:\/\//, "").replace(/\/+$/, "");
|
|
379
|
+
const subdomain = trimmed.split(".")[0];
|
|
380
|
+
return `https://${subdomain}.freshservice.com${BASE_PATH_SEGMENT}`;
|
|
381
|
+
}
|
|
382
|
+
function basicAuthHeader2(apiKey) {
|
|
383
|
+
return `Basic ${Buffer.from(`${apiKey}:X`).toString("base64")}`;
|
|
384
|
+
}
|
|
385
|
+
var inputSchema = z.object({
|
|
386
|
+
toolUseIntent: z.string().optional().describe(
|
|
387
|
+
"Brief description of what you intend to accomplish with this tool call"
|
|
388
|
+
),
|
|
389
|
+
connectionId: z.string().describe("ID of the Freshservice connection to use"),
|
|
390
|
+
method: z.enum(["GET", "POST", "PUT", "DELETE"]).describe(
|
|
391
|
+
"HTTP method. GET for reading resources, POST for creating, PUT for updating, DELETE for removing."
|
|
392
|
+
),
|
|
393
|
+
path: z.string().describe(
|
|
394
|
+
"API path (e.g., '/tickets', '/tickets/123', '/agents'). Append query parameters such as '?per_page=100&page=1' for pagination."
|
|
395
|
+
),
|
|
396
|
+
body: z.record(z.string(), z.unknown()).optional().describe(
|
|
397
|
+
'Request body (JSON) for POST/PUT requests. Example: { "subject": "...", "description": "...", "email": "...", "priority": 2, "status": 2, "source": 2 }.'
|
|
398
|
+
)
|
|
399
|
+
});
|
|
400
|
+
var outputSchema = z.discriminatedUnion("success", [
|
|
401
|
+
z.object({
|
|
402
|
+
success: z.literal(true),
|
|
403
|
+
status: z.number(),
|
|
404
|
+
data: z.union([
|
|
405
|
+
z.record(z.string(), z.unknown()),
|
|
406
|
+
z.array(z.unknown())
|
|
407
|
+
])
|
|
408
|
+
}),
|
|
409
|
+
z.object({
|
|
410
|
+
success: z.literal(false),
|
|
411
|
+
error: z.string()
|
|
412
|
+
})
|
|
413
|
+
]);
|
|
414
|
+
var requestTool = new ConnectorTool({
|
|
415
|
+
name: "request",
|
|
416
|
+
description: `Send authenticated requests to the Freshservice REST API v2.
|
|
417
|
+
Authentication is HTTP Basic Auth using the API key as the username (handled automatically).
|
|
418
|
+
Provide the API path relative to the base URL (https://<domain>.freshservice.com/api/v2).
|
|
419
|
+
|
|
420
|
+
Common endpoints:
|
|
421
|
+
- GET /tickets \u2014 List tickets (paginated). Use ?include=requester,stats to enrich responses.
|
|
422
|
+
- GET /tickets/{id} \u2014 Get a ticket
|
|
423
|
+
- POST /tickets \u2014 Create a ticket (body: { subject, description, email, priority, status, source })
|
|
424
|
+
- PUT /tickets/{id} \u2014 Update a ticket
|
|
425
|
+
- GET /tickets/{id}/conversations \u2014 Replies and notes on a ticket
|
|
426
|
+
- GET /agents \u2014 List agents
|
|
427
|
+
- GET /requesters \u2014 List requesters (end users)
|
|
428
|
+
- GET /groups \u2014 List agent groups
|
|
429
|
+
- GET /departments \u2014 List departments
|
|
430
|
+
- GET /locations \u2014 List locations
|
|
431
|
+
- GET /assets \u2014 List assets (requires the ITAM module)
|
|
432
|
+
- GET /products \u2014 List products
|
|
433
|
+
- GET /service_catalog/items \u2014 List service catalog items
|
|
434
|
+
- GET /problems / GET /changes / GET /releases \u2014 ITIL: problems, changes, releases
|
|
435
|
+
|
|
436
|
+
Pagination: ?page=1&per_page=100 (per_page max 100). Inspect the \`Link\` response header for the next-page URL.
|
|
437
|
+
|
|
438
|
+
Field codes:
|
|
439
|
+
- ticket priority: 1 Low, 2 Medium, 3 High, 4 Urgent
|
|
440
|
+
- ticket status: 2 Open, 3 Pending, 4 Resolved, 5 Closed
|
|
441
|
+
- ticket source: 1 Email, 2 Portal, 3 Phone, 4 Chat, 5 Feedback widget, 7 Yammer, 8 AwsCloudwatch, 9 Pagerduty, 10 Walkup, 11 Slack`,
|
|
442
|
+
inputSchema,
|
|
443
|
+
outputSchema,
|
|
444
|
+
async execute({ connectionId, method, path: path2, body }, connections) {
|
|
445
|
+
const connection2 = connections.find((c) => c.id === connectionId);
|
|
446
|
+
if (!connection2) {
|
|
447
|
+
return {
|
|
448
|
+
success: false,
|
|
449
|
+
error: `Connection ${connectionId} not found`
|
|
450
|
+
};
|
|
451
|
+
}
|
|
452
|
+
console.log(
|
|
453
|
+
`[connector-request] freshservice/${connection2.name}: ${method} ${path2}`
|
|
454
|
+
);
|
|
455
|
+
try {
|
|
456
|
+
const apiKey = parameters.apiKey.getValue(connection2);
|
|
457
|
+
const domain = parameters.domain.getValue(connection2);
|
|
458
|
+
const baseUrl = buildBaseUrl2(domain);
|
|
459
|
+
const normalizedPath = normalizeRequestPath(path2, BASE_PATH_SEGMENT);
|
|
460
|
+
const url = `${baseUrl}${normalizedPath}`;
|
|
461
|
+
const controller = new AbortController();
|
|
462
|
+
const timeout = setTimeout(() => controller.abort(), REQUEST_TIMEOUT_MS);
|
|
463
|
+
try {
|
|
464
|
+
const response = await fetch(url, {
|
|
465
|
+
method,
|
|
466
|
+
headers: {
|
|
467
|
+
Authorization: basicAuthHeader2(apiKey),
|
|
468
|
+
"Content-Type": "application/json",
|
|
469
|
+
Accept: "application/json"
|
|
470
|
+
},
|
|
471
|
+
body: body ? JSON.stringify(body) : void 0,
|
|
472
|
+
signal: controller.signal
|
|
473
|
+
});
|
|
474
|
+
const text = await response.text();
|
|
475
|
+
const data = text ? JSON.parse(text) : {};
|
|
476
|
+
if (!response.ok) {
|
|
477
|
+
const errObj = !Array.isArray(data) ? data : {};
|
|
478
|
+
const description = typeof errObj.description === "string" && errObj.description || typeof errObj.message === "string" && errObj.message;
|
|
479
|
+
const errors = errObj.errors;
|
|
480
|
+
const fieldDetail = Array.isArray(errors) && errors.length > 0 ? ` \u2014 ${errors[0]?.message ?? ""}` : "";
|
|
481
|
+
const errorMessage = description ? `${description}${fieldDetail}` : `HTTP ${response.status} ${response.statusText}`;
|
|
482
|
+
return { success: false, error: String(errorMessage) };
|
|
483
|
+
}
|
|
484
|
+
return { success: true, status: response.status, data };
|
|
485
|
+
} finally {
|
|
486
|
+
clearTimeout(timeout);
|
|
487
|
+
}
|
|
488
|
+
} catch (err) {
|
|
489
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
490
|
+
return { success: false, error: msg };
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
});
|
|
494
|
+
|
|
495
|
+
// ../connectors/src/connectors/freshservice/index.ts
|
|
496
|
+
var tools = { request: requestTool };
|
|
497
|
+
var freshserviceConnector = new ConnectorPlugin({
|
|
498
|
+
slug: "freshservice",
|
|
499
|
+
authType: AUTH_TYPES.API_KEY,
|
|
500
|
+
name: "Freshservice",
|
|
501
|
+
description: "Connect to Freshservice (ITSM) for ticket, agent, asset, and ITIL workflow data via API key.",
|
|
502
|
+
iconUrl: "https://images.ctfassets.net/9ncizv60xc5y/6Tj64HZOoIrGgQYDayBosY/3f45b29d3479726b5d245ac38d5a7036/freshservice-icon.svg",
|
|
503
|
+
parameters,
|
|
504
|
+
releaseFlag: { dev1: true, dev2: true, prod: true },
|
|
505
|
+
categories: ["productivity"],
|
|
506
|
+
onboarding: freshserviceOnboarding,
|
|
507
|
+
systemPrompt: {
|
|
508
|
+
en: `### Tools
|
|
509
|
+
|
|
510
|
+
- \`freshservice_request\`: The only way to call the Freshservice REST API v2. Use it to list tickets, agents, requesters, departments, locations, assets, problems, changes, releases, and more. Authentication (HTTP Basic Auth using the API key as username) and the base URL (https://<domain>.freshservice.com/api/v2) are configured automatically.
|
|
511
|
+
|
|
512
|
+
### Business Logic
|
|
513
|
+
|
|
514
|
+
The business logic type for this connector is "typescript". Use the connector SDK in your handler. Do NOT read credentials from environment variables.
|
|
515
|
+
|
|
516
|
+
SDK methods (client created via \`connection(connectionId)\`):
|
|
517
|
+
- \`client.request(path, init?)\` \u2014 low-level authenticated fetch
|
|
518
|
+
- \`client.listTickets(options?)\` \u2014 list tickets (paginated)
|
|
519
|
+
- \`client.getTicket(ticketId, options?)\` \u2014 get a single ticket
|
|
520
|
+
- \`client.createTicket(ticketData)\` \u2014 create a ticket
|
|
521
|
+
- \`client.updateTicket(ticketId, ticketData)\` \u2014 update a ticket
|
|
522
|
+
- \`client.listAgents(options?)\` \u2014 list agents
|
|
523
|
+
- \`client.listRequesters(options?)\` \u2014 list requesters
|
|
524
|
+
|
|
525
|
+
\`\`\`ts
|
|
526
|
+
import type { Context } from "hono";
|
|
527
|
+
import { connection } from "@squadbase/vite-server/connectors/freshservice";
|
|
528
|
+
|
|
529
|
+
const fs = connection("<connectionId>");
|
|
530
|
+
|
|
531
|
+
export default async function handler(c: Context) {
|
|
532
|
+
const { tickets } = await fs.listTickets({
|
|
533
|
+
per_page: 100,
|
|
534
|
+
include: "requester,stats",
|
|
535
|
+
});
|
|
536
|
+
return c.json({ tickets });
|
|
537
|
+
}
|
|
538
|
+
\`\`\`
|
|
539
|
+
|
|
540
|
+
### Freshservice REST API v2 Reference
|
|
541
|
+
|
|
542
|
+
- Base URL: \`https://<domain>.freshservice.com/api/v2\`
|
|
543
|
+
- Authentication: HTTP Basic Auth (\`<API_KEY>:X\`, base64-encoded; the password is ignored).
|
|
544
|
+
- Pagination: 1-indexed \`page\` + \`per_page\` (max 100). Inspect the \`Link\` response header for the next-page URL.
|
|
545
|
+
|
|
546
|
+
#### Resource Endpoints
|
|
547
|
+
|
|
548
|
+
**Tickets**
|
|
549
|
+
- GET \`/tickets\` \u2014 List tickets (use \`include=requester,stats\` to enrich)
|
|
550
|
+
- GET \`/tickets/{id}\` \u2014 Get a ticket
|
|
551
|
+
- POST \`/tickets\` \u2014 Create a ticket
|
|
552
|
+
- PUT \`/tickets/{id}\` \u2014 Update a ticket
|
|
553
|
+
- DELETE \`/tickets/{id}\` \u2014 Delete a ticket
|
|
554
|
+
- GET \`/tickets/{id}/conversations\` \u2014 Replies and notes on a ticket
|
|
555
|
+
- POST \`/tickets/{id}/reply\` \u2014 Reply to a ticket
|
|
556
|
+
- POST \`/tickets/{id}/notes\` \u2014 Add a private note
|
|
557
|
+
|
|
558
|
+
**Users**
|
|
559
|
+
- GET \`/agents\` \u2014 List agents
|
|
560
|
+
- GET \`/requesters\` \u2014 List requesters (end users)
|
|
561
|
+
- GET \`/groups\` \u2014 List agent groups
|
|
562
|
+
|
|
563
|
+
**Org structure**
|
|
564
|
+
- GET \`/departments\` \u2014 List departments
|
|
565
|
+
- GET \`/locations\` \u2014 List locations
|
|
566
|
+
|
|
567
|
+
**ITAM (requires asset module)**
|
|
568
|
+
- GET \`/assets\` \u2014 List assets (paginated)
|
|
569
|
+
- GET \`/assets/{display_id}\` \u2014 Get an asset
|
|
570
|
+
- GET \`/asset_types\` \u2014 List asset types
|
|
571
|
+
- GET \`/products\` \u2014 List products
|
|
572
|
+
|
|
573
|
+
**Service Catalog & ITIL**
|
|
574
|
+
- GET \`/service_catalog/items\` \u2014 List catalog items
|
|
575
|
+
- GET \`/problems\` \u2014 Problems
|
|
576
|
+
- GET \`/changes\` \u2014 Changes
|
|
577
|
+
- GET \`/releases\` \u2014 Releases
|
|
578
|
+
|
|
579
|
+
#### Field codes (tickets)
|
|
580
|
+
|
|
581
|
+
- \`priority\`: 1=Low, 2=Medium, 3=High, 4=Urgent
|
|
582
|
+
- \`status\`: 2=Open, 3=Pending, 4=Resolved, 5=Closed
|
|
583
|
+
- \`source\`: 1=Email, 2=Portal, 3=Phone, 4=Chat, 5=Feedback widget, 7=Yammer, 8=AwsCloudwatch, 9=Pagerduty, 10=Walkup, 11=Slack`,
|
|
584
|
+
ja: `### \u30C4\u30FC\u30EB
|
|
585
|
+
|
|
586
|
+
- \`freshservice_request\`: Freshservice REST API v2 \u3092\u547C\u3073\u51FA\u3059\u552F\u4E00\u306E\u624B\u6BB5\u3067\u3059\u3002\u30C1\u30B1\u30C3\u30C8\u3001\u30A8\u30FC\u30B8\u30A7\u30F3\u30C8\u3001\u8981\u6C42\u8005\u3001\u90E8\u7F72\u3001\u30ED\u30B1\u30FC\u30B7\u30E7\u30F3\u3001\u8CC7\u7523\u3001\u554F\u984C\u7BA1\u7406\u3001\u5909\u66F4\u7BA1\u7406\u3001\u30EA\u30EA\u30FC\u30B9\u306A\u3069\u306E\u53D6\u5F97\u30FB\u66F4\u65B0\u306B\u4F7F\u7528\u3057\u307E\u3059\u3002\u8A8D\u8A3C\uFF08API \u30AD\u30FC\u3092\u30E6\u30FC\u30B6\u30FC\u540D\u3068\u3057\u305F HTTP Basic Auth\uFF09\u3068\u30D9\u30FC\u30B9URL\uFF08https://<\u30C9\u30E1\u30A4\u30F3>.freshservice.com/api/v2\uFF09\u306F\u81EA\u52D5\u3067\u8A2D\u5B9A\u3055\u308C\u307E\u3059\u3002
|
|
587
|
+
|
|
588
|
+
### Business Logic
|
|
589
|
+
|
|
590
|
+
\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
|
|
591
|
+
|
|
592
|
+
SDK\u30E1\u30BD\u30C3\u30C9 (\`connection(connectionId)\` \u3067\u4F5C\u6210\u3057\u305F\u30AF\u30E9\u30A4\u30A2\u30F3\u30C8):
|
|
593
|
+
- \`client.request(path, init?)\` \u2014 \u4F4E\u30EC\u30D9\u30EB\u306E\u8A8D\u8A3C\u4ED8\u304Dfetch
|
|
594
|
+
- \`client.listTickets(options?)\` \u2014 \u30C1\u30B1\u30C3\u30C8\u4E00\u89A7\uFF08\u30DA\u30FC\u30B8\u30F3\u30B0\uFF09
|
|
595
|
+
- \`client.getTicket(ticketId, options?)\` \u2014 \u5358\u4E00\u30C1\u30B1\u30C3\u30C8\u306E\u53D6\u5F97
|
|
596
|
+
- \`client.createTicket(ticketData)\` \u2014 \u30C1\u30B1\u30C3\u30C8\u306E\u4F5C\u6210
|
|
597
|
+
- \`client.updateTicket(ticketId, ticketData)\` \u2014 \u30C1\u30B1\u30C3\u30C8\u306E\u66F4\u65B0
|
|
598
|
+
- \`client.listAgents(options?)\` \u2014 \u30A8\u30FC\u30B8\u30A7\u30F3\u30C8\u4E00\u89A7
|
|
599
|
+
- \`client.listRequesters(options?)\` \u2014 \u8981\u6C42\u8005\u4E00\u89A7
|
|
600
|
+
|
|
601
|
+
\`\`\`ts
|
|
602
|
+
import type { Context } from "hono";
|
|
603
|
+
import { connection } from "@squadbase/vite-server/connectors/freshservice";
|
|
604
|
+
|
|
605
|
+
const fs = connection("<connectionId>");
|
|
606
|
+
|
|
607
|
+
export default async function handler(c: Context) {
|
|
608
|
+
const { tickets } = await fs.listTickets({
|
|
609
|
+
per_page: 100,
|
|
610
|
+
include: "requester,stats",
|
|
611
|
+
});
|
|
612
|
+
return c.json({ tickets });
|
|
613
|
+
}
|
|
614
|
+
\`\`\`
|
|
615
|
+
|
|
616
|
+
### Freshservice REST API v2 \u30EA\u30D5\u30A1\u30EC\u30F3\u30B9
|
|
617
|
+
|
|
618
|
+
- \u30D9\u30FC\u30B9URL: \`https://<\u30C9\u30E1\u30A4\u30F3>.freshservice.com/api/v2\`
|
|
619
|
+
- \u8A8D\u8A3C: HTTP Basic Auth\uFF08\`<API_KEY>:X\` \u3092 base64 \u30A8\u30F3\u30B3\u30FC\u30C9\u3001\u30D1\u30B9\u30EF\u30FC\u30C9\u90E8\u306F\u7121\u8996\u3055\u308C\u307E\u3059\uFF09
|
|
620
|
+
- \u30DA\u30FC\u30B8\u30CD\u30FC\u30B7\u30E7\u30F3: 1\u59CB\u307E\u308A\u306E \`page\` \u3068 \`per_page\`\uFF08\u6700\u5927100\uFF09\u3002\u6B21\u30DA\u30FC\u30B8\u304C\u5B58\u5728\u3059\u308B\u5834\u5408\u306F \`Link\` \u30EC\u30B9\u30DD\u30F3\u30B9\u30D8\u30C3\u30C0\u306B\u6B21URL\u304C\u542B\u307E\u308C\u307E\u3059\u3002
|
|
621
|
+
|
|
622
|
+
#### \u30EA\u30BD\u30FC\u30B9\u30A8\u30F3\u30C9\u30DD\u30A4\u30F3\u30C8
|
|
623
|
+
|
|
624
|
+
**\u30C1\u30B1\u30C3\u30C8**
|
|
625
|
+
- GET \`/tickets\` \u2014 \u30C1\u30B1\u30C3\u30C8\u4E00\u89A7\uFF08\`include=requester,stats\` \u3067\u95A2\u9023\u60C5\u5831\u3092\u5C55\u958B\u53EF\u80FD\uFF09
|
|
626
|
+
- GET \`/tickets/{id}\` \u2014 \u30C1\u30B1\u30C3\u30C8\u306E\u53D6\u5F97
|
|
627
|
+
- POST \`/tickets\` \u2014 \u30C1\u30B1\u30C3\u30C8\u306E\u4F5C\u6210
|
|
628
|
+
- PUT \`/tickets/{id}\` \u2014 \u30C1\u30B1\u30C3\u30C8\u306E\u66F4\u65B0
|
|
629
|
+
- DELETE \`/tickets/{id}\` \u2014 \u30C1\u30B1\u30C3\u30C8\u306E\u524A\u9664
|
|
630
|
+
- GET \`/tickets/{id}/conversations\` \u2014 \u30C1\u30B1\u30C3\u30C8\u306E\u8FD4\u4FE1\u30FB\u30CE\u30FC\u30C8\u4E00\u89A7
|
|
631
|
+
- POST \`/tickets/{id}/reply\` \u2014 \u30C1\u30B1\u30C3\u30C8\u3078\u306E\u8FD4\u4FE1
|
|
632
|
+
- POST \`/tickets/{id}/notes\` \u2014 \u30D7\u30E9\u30A4\u30D9\u30FC\u30C8\u30CE\u30FC\u30C8\u306E\u8FFD\u52A0
|
|
633
|
+
|
|
634
|
+
**\u30E6\u30FC\u30B6\u30FC**
|
|
635
|
+
- GET \`/agents\` \u2014 \u30A8\u30FC\u30B8\u30A7\u30F3\u30C8\u4E00\u89A7
|
|
636
|
+
- GET \`/requesters\` \u2014 \u8981\u6C42\u8005\uFF08\u30A8\u30F3\u30C9\u30E6\u30FC\u30B6\u30FC\uFF09\u4E00\u89A7
|
|
637
|
+
- GET \`/groups\` \u2014 \u30A8\u30FC\u30B8\u30A7\u30F3\u30C8\u30B0\u30EB\u30FC\u30D7\u4E00\u89A7
|
|
638
|
+
|
|
639
|
+
**\u7D44\u7E54\u69CB\u9020**
|
|
640
|
+
- GET \`/departments\` \u2014 \u90E8\u7F72\u4E00\u89A7
|
|
641
|
+
- GET \`/locations\` \u2014 \u30ED\u30B1\u30FC\u30B7\u30E7\u30F3\u4E00\u89A7
|
|
642
|
+
|
|
643
|
+
**ITAM\uFF08\u8CC7\u7523\u30E2\u30B8\u30E5\u30FC\u30EB\u5FC5\u9808\uFF09**
|
|
644
|
+
- GET \`/assets\` \u2014 \u8CC7\u7523\u4E00\u89A7\uFF08\u30DA\u30FC\u30B8\u30F3\u30B0\uFF09
|
|
645
|
+
- GET \`/assets/{display_id}\` \u2014 \u8CC7\u7523\u306E\u53D6\u5F97
|
|
646
|
+
- GET \`/asset_types\` \u2014 \u8CC7\u7523\u30BF\u30A4\u30D7\u4E00\u89A7
|
|
647
|
+
- GET \`/products\` \u2014 \u88FD\u54C1\u4E00\u89A7
|
|
648
|
+
|
|
649
|
+
**\u30B5\u30FC\u30D3\u30B9\u30AB\u30BF\u30ED\u30B0 & ITIL**
|
|
650
|
+
- GET \`/service_catalog/items\` \u2014 \u30AB\u30BF\u30ED\u30B0\u30A2\u30A4\u30C6\u30E0\u4E00\u89A7
|
|
651
|
+
- GET \`/problems\` \u2014 \u554F\u984C\u7BA1\u7406
|
|
652
|
+
- GET \`/changes\` \u2014 \u5909\u66F4\u7BA1\u7406
|
|
653
|
+
- GET \`/releases\` \u2014 \u30EA\u30EA\u30FC\u30B9\u7BA1\u7406
|
|
654
|
+
|
|
655
|
+
#### \u30D5\u30A3\u30FC\u30EB\u30C9\u30B3\u30FC\u30C9\uFF08\u30C1\u30B1\u30C3\u30C8\uFF09
|
|
656
|
+
|
|
657
|
+
- \`priority\`: 1=Low, 2=Medium, 3=High, 4=Urgent
|
|
658
|
+
- \`status\`: 2=Open, 3=Pending, 4=Resolved, 5=Closed
|
|
659
|
+
- \`source\`: 1=Email, 2=Portal, 3=Phone, 4=Chat, 5=Feedback widget, 7=Yammer, 8=AwsCloudwatch, 9=Pagerduty, 10=Walkup, 11=Slack`
|
|
660
|
+
},
|
|
661
|
+
tools
|
|
662
|
+
});
|
|
663
|
+
|
|
664
|
+
// src/connectors/create-connector-sdk.ts
|
|
665
|
+
import { readFileSync } from "fs";
|
|
666
|
+
import path from "path";
|
|
667
|
+
|
|
668
|
+
// src/connector-client/env.ts
|
|
669
|
+
function resolveEnvVar(entry, key, connectionId) {
|
|
670
|
+
const envVarName = entry.envVars[key];
|
|
671
|
+
if (!envVarName) {
|
|
672
|
+
throw new Error(`Connection "${connectionId}" is missing envVars mapping for key "${key}"`);
|
|
673
|
+
}
|
|
674
|
+
const value = process.env[envVarName];
|
|
675
|
+
if (!value) {
|
|
676
|
+
throw new Error(`Environment variable "${envVarName}" (for connection "${connectionId}", key "${key}") is not set`);
|
|
677
|
+
}
|
|
678
|
+
return value;
|
|
679
|
+
}
|
|
680
|
+
function resolveEnvVarOptional(entry, key) {
|
|
681
|
+
const envVarName = entry.envVars[key];
|
|
682
|
+
if (!envVarName) return void 0;
|
|
683
|
+
return process.env[envVarName] || void 0;
|
|
684
|
+
}
|
|
685
|
+
|
|
686
|
+
// src/connector-client/proxy-fetch.ts
|
|
687
|
+
import { getContext } from "hono/context-storage";
|
|
688
|
+
import { getCookie } from "hono/cookie";
|
|
689
|
+
var APP_SESSION_COOKIE_NAME = "__Host-squadbase-session";
|
|
690
|
+
function normalizeHeaders(input) {
|
|
691
|
+
const out = {};
|
|
692
|
+
if (!input) return out;
|
|
693
|
+
new Headers(input).forEach((value, key) => {
|
|
694
|
+
out[key] = value;
|
|
695
|
+
});
|
|
696
|
+
return out;
|
|
697
|
+
}
|
|
698
|
+
function createSandboxProxyFetch(connectionId) {
|
|
699
|
+
return async (input, init) => {
|
|
700
|
+
const token = process.env.INTERNAL_SQUADBASE_OAUTH_MACHINE_CREDENTIAL;
|
|
701
|
+
const sandboxId = process.env.INTERNAL_SQUADBASE_SANDBOX_ID;
|
|
702
|
+
if (!token || !sandboxId) {
|
|
703
|
+
throw new Error(
|
|
704
|
+
"Connection proxy is not configured. Please check your deployment settings."
|
|
705
|
+
);
|
|
706
|
+
}
|
|
707
|
+
const originalUrl = typeof input === "string" ? input : input instanceof URL ? input.href : input.url;
|
|
708
|
+
const originalMethod = init?.method ?? "GET";
|
|
709
|
+
const originalBody = init?.body ? JSON.parse(init.body) : void 0;
|
|
710
|
+
const baseDomain = process.env["SQUADBASE_PREVIEW_BASE_DOMAIN"] ?? "preview.app.squadbase.dev";
|
|
711
|
+
const proxyUrl = `https://${sandboxId}.${baseDomain}/_sqcore/connections/${connectionId}/request`;
|
|
712
|
+
return fetch(proxyUrl, {
|
|
713
|
+
method: "POST",
|
|
714
|
+
headers: {
|
|
715
|
+
"Content-Type": "application/json",
|
|
716
|
+
Authorization: `Bearer ${token}`
|
|
717
|
+
},
|
|
718
|
+
body: JSON.stringify({
|
|
719
|
+
url: originalUrl,
|
|
720
|
+
method: originalMethod,
|
|
721
|
+
headers: normalizeHeaders(init?.headers),
|
|
722
|
+
body: originalBody
|
|
723
|
+
})
|
|
724
|
+
});
|
|
725
|
+
};
|
|
726
|
+
}
|
|
727
|
+
function createDeployedAppProxyFetch(connectionId) {
|
|
728
|
+
const projectId = process.env["SQUADBASE_PROJECT_ID"];
|
|
729
|
+
if (!projectId) {
|
|
730
|
+
throw new Error(
|
|
731
|
+
"Connection proxy is not configured. Please check your deployment settings."
|
|
732
|
+
);
|
|
733
|
+
}
|
|
734
|
+
const baseDomain = process.env["SQUADBASE_APP_BASE_DOMAIN"] ?? "squadbase.app";
|
|
735
|
+
const proxyUrl = `https://${projectId}.${baseDomain}/_sqcore/connections/${connectionId}/request`;
|
|
736
|
+
return async (input, init) => {
|
|
737
|
+
const originalUrl = typeof input === "string" ? input : input instanceof URL ? input.href : input.url;
|
|
738
|
+
const originalMethod = init?.method ?? "GET";
|
|
739
|
+
const originalBody = init?.body ? JSON.parse(init.body) : void 0;
|
|
740
|
+
const c = getContext();
|
|
741
|
+
const appSession = getCookie(c, APP_SESSION_COOKIE_NAME);
|
|
742
|
+
if (!appSession) {
|
|
743
|
+
throw new Error(
|
|
744
|
+
"No authentication method available for connection proxy."
|
|
745
|
+
);
|
|
746
|
+
}
|
|
747
|
+
return fetch(proxyUrl, {
|
|
748
|
+
method: "POST",
|
|
749
|
+
headers: {
|
|
750
|
+
"Content-Type": "application/json",
|
|
751
|
+
Authorization: `Bearer ${appSession}`
|
|
752
|
+
},
|
|
753
|
+
body: JSON.stringify({
|
|
754
|
+
url: originalUrl,
|
|
755
|
+
method: originalMethod,
|
|
756
|
+
headers: normalizeHeaders(init?.headers),
|
|
757
|
+
body: originalBody
|
|
758
|
+
})
|
|
759
|
+
});
|
|
760
|
+
};
|
|
761
|
+
}
|
|
762
|
+
function createProxyFetch(connectionId) {
|
|
763
|
+
if (process.env.INTERNAL_SQUADBASE_SANDBOX_ID) {
|
|
764
|
+
return createSandboxProxyFetch(connectionId);
|
|
765
|
+
}
|
|
766
|
+
return createDeployedAppProxyFetch(connectionId);
|
|
767
|
+
}
|
|
768
|
+
|
|
769
|
+
// src/connectors/create-connector-sdk.ts
|
|
770
|
+
function loadConnectionsSync() {
|
|
771
|
+
const filePath = process.env.CONNECTIONS_PATH ?? path.join(process.cwd(), ".squadbase/connections.json");
|
|
772
|
+
try {
|
|
773
|
+
const raw = readFileSync(filePath, "utf-8");
|
|
774
|
+
return JSON.parse(raw);
|
|
775
|
+
} catch {
|
|
776
|
+
return {};
|
|
777
|
+
}
|
|
778
|
+
}
|
|
779
|
+
function createConnectorSdk(plugin, createClient2) {
|
|
780
|
+
return (connectionId) => {
|
|
781
|
+
const connections = loadConnectionsSync();
|
|
782
|
+
const entry = connections[connectionId];
|
|
783
|
+
if (!entry) {
|
|
784
|
+
throw new Error(
|
|
785
|
+
`Connection "${connectionId}" not found in .squadbase/connections.json`
|
|
786
|
+
);
|
|
787
|
+
}
|
|
788
|
+
if (entry.connector.slug !== plugin.slug) {
|
|
789
|
+
throw new Error(
|
|
790
|
+
`Connection "${connectionId}" is not a ${plugin.slug} connection (got "${entry.connector.slug}")`
|
|
791
|
+
);
|
|
792
|
+
}
|
|
793
|
+
const params = {};
|
|
794
|
+
for (const param of Object.values(plugin.parameters)) {
|
|
795
|
+
if (param.required) {
|
|
796
|
+
params[param.slug] = resolveEnvVar(entry, param.slug, connectionId);
|
|
797
|
+
} else {
|
|
798
|
+
const val = resolveEnvVarOptional(entry, param.slug);
|
|
799
|
+
if (val !== void 0) params[param.slug] = val;
|
|
800
|
+
}
|
|
801
|
+
}
|
|
802
|
+
return createClient2(params, createProxyFetch(connectionId));
|
|
803
|
+
};
|
|
804
|
+
}
|
|
805
|
+
|
|
806
|
+
// src/connectors/entries/freshservice.ts
|
|
807
|
+
var connection = createConnectorSdk(
|
|
808
|
+
freshserviceConnector,
|
|
809
|
+
createClient
|
|
810
|
+
);
|
|
811
|
+
export {
|
|
812
|
+
connection
|
|
813
|
+
};
|