@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,710 @@
|
|
|
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/intercom/parameters.ts
|
|
46
|
+
var parameters = {
|
|
47
|
+
accessToken: new ParameterDefinition({
|
|
48
|
+
slug: "access-token",
|
|
49
|
+
name: "Access Token",
|
|
50
|
+
description: "Your Intercom Access Token (found in Developer Hub > Your App > Authentication).",
|
|
51
|
+
envVarBaseKey: "INTERCOM_ACCESS_TOKEN",
|
|
52
|
+
type: "text",
|
|
53
|
+
secret: true,
|
|
54
|
+
required: true
|
|
55
|
+
})
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
// ../connectors/src/connectors/intercom/sdk/index.ts
|
|
59
|
+
var BASE_URL = "https://api.intercom.io";
|
|
60
|
+
var API_VERSION = "2.11";
|
|
61
|
+
function createClient(params) {
|
|
62
|
+
const accessToken = params[parameters.accessToken.slug];
|
|
63
|
+
if (!accessToken) {
|
|
64
|
+
throw new Error(
|
|
65
|
+
`intercom: missing required parameter: ${parameters.accessToken.slug}`
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
function authHeaders(extra) {
|
|
69
|
+
const headers = new Headers(extra);
|
|
70
|
+
headers.set("Authorization", `Bearer ${accessToken}`);
|
|
71
|
+
headers.set("Content-Type", "application/json");
|
|
72
|
+
headers.set("Accept", "application/json");
|
|
73
|
+
headers.set("Intercom-Version", API_VERSION);
|
|
74
|
+
return headers;
|
|
75
|
+
}
|
|
76
|
+
async function assertOk(res, label) {
|
|
77
|
+
if (!res.ok) {
|
|
78
|
+
const body = await res.text().catch(() => "(unreadable body)");
|
|
79
|
+
throw new Error(
|
|
80
|
+
`intercom ${label}: ${res.status} ${res.statusText} \u2014 ${body}`
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return {
|
|
85
|
+
request(path2, init) {
|
|
86
|
+
const url = `${BASE_URL}${path2.startsWith("/") ? "" : "/"}${path2}`;
|
|
87
|
+
const headers = new Headers(init?.headers);
|
|
88
|
+
headers.set("Authorization", `Bearer ${accessToken}`);
|
|
89
|
+
headers.set("Content-Type", "application/json");
|
|
90
|
+
headers.set("Accept", "application/json");
|
|
91
|
+
headers.set("Intercom-Version", API_VERSION);
|
|
92
|
+
return fetch(url, { ...init, headers });
|
|
93
|
+
},
|
|
94
|
+
async listContacts(options) {
|
|
95
|
+
const searchParams = new URLSearchParams();
|
|
96
|
+
if (options?.per_page) searchParams.set("per_page", String(options.per_page));
|
|
97
|
+
if (options?.starting_after) searchParams.set("starting_after", options.starting_after);
|
|
98
|
+
const qs = searchParams.toString();
|
|
99
|
+
const res = await fetch(
|
|
100
|
+
`${BASE_URL}/contacts${qs ? `?${qs}` : ""}`,
|
|
101
|
+
{ method: "GET", headers: authHeaders() }
|
|
102
|
+
);
|
|
103
|
+
await assertOk(res, "listContacts");
|
|
104
|
+
return await res.json();
|
|
105
|
+
},
|
|
106
|
+
async getContact(contactId) {
|
|
107
|
+
const res = await fetch(
|
|
108
|
+
`${BASE_URL}/contacts/${encodeURIComponent(contactId)}`,
|
|
109
|
+
{ method: "GET", headers: authHeaders() }
|
|
110
|
+
);
|
|
111
|
+
await assertOk(res, "getContact");
|
|
112
|
+
return await res.json();
|
|
113
|
+
},
|
|
114
|
+
async searchContacts(query) {
|
|
115
|
+
const res = await fetch(`${BASE_URL}/contacts/search`, {
|
|
116
|
+
method: "POST",
|
|
117
|
+
headers: authHeaders(),
|
|
118
|
+
body: JSON.stringify({ query })
|
|
119
|
+
});
|
|
120
|
+
await assertOk(res, "searchContacts");
|
|
121
|
+
return await res.json();
|
|
122
|
+
},
|
|
123
|
+
async listConversations(options) {
|
|
124
|
+
const searchParams = new URLSearchParams();
|
|
125
|
+
if (options?.per_page) searchParams.set("per_page", String(options.per_page));
|
|
126
|
+
if (options?.starting_after) searchParams.set("starting_after", options.starting_after);
|
|
127
|
+
const qs = searchParams.toString();
|
|
128
|
+
const res = await fetch(
|
|
129
|
+
`${BASE_URL}/conversations${qs ? `?${qs}` : ""}`,
|
|
130
|
+
{ method: "GET", headers: authHeaders() }
|
|
131
|
+
);
|
|
132
|
+
await assertOk(res, "listConversations");
|
|
133
|
+
return await res.json();
|
|
134
|
+
},
|
|
135
|
+
async getConversation(conversationId) {
|
|
136
|
+
const res = await fetch(
|
|
137
|
+
`${BASE_URL}/conversations/${encodeURIComponent(conversationId)}`,
|
|
138
|
+
{ method: "GET", headers: authHeaders() }
|
|
139
|
+
);
|
|
140
|
+
await assertOk(res, "getConversation");
|
|
141
|
+
return await res.json();
|
|
142
|
+
},
|
|
143
|
+
async listCompanies(options) {
|
|
144
|
+
const searchParams = new URLSearchParams();
|
|
145
|
+
if (options?.per_page) searchParams.set("per_page", String(options.per_page));
|
|
146
|
+
if (options?.page) searchParams.set("page", String(options.page));
|
|
147
|
+
const qs = searchParams.toString();
|
|
148
|
+
const res = await fetch(
|
|
149
|
+
`${BASE_URL}/companies${qs ? `?${qs}` : ""}`,
|
|
150
|
+
{ method: "GET", headers: authHeaders() }
|
|
151
|
+
);
|
|
152
|
+
await assertOk(res, "listCompanies");
|
|
153
|
+
return await res.json();
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
// ../connectors/src/connector-onboarding.ts
|
|
159
|
+
var ConnectorOnboarding = class {
|
|
160
|
+
/** Phase 1: Connection setup instructions (optional — some connectors don't need this) */
|
|
161
|
+
connectionSetupInstructions;
|
|
162
|
+
/** Phase 2: Data overview instructions */
|
|
163
|
+
dataOverviewInstructions;
|
|
164
|
+
constructor(config) {
|
|
165
|
+
this.connectionSetupInstructions = config.connectionSetupInstructions;
|
|
166
|
+
this.dataOverviewInstructions = config.dataOverviewInstructions;
|
|
167
|
+
}
|
|
168
|
+
getConnectionSetupPrompt(language) {
|
|
169
|
+
return this.connectionSetupInstructions?.[language] ?? null;
|
|
170
|
+
}
|
|
171
|
+
getDataOverviewInstructions(language) {
|
|
172
|
+
return this.dataOverviewInstructions[language];
|
|
173
|
+
}
|
|
174
|
+
};
|
|
175
|
+
|
|
176
|
+
// ../connectors/src/connector-tool.ts
|
|
177
|
+
var ConnectorTool = class {
|
|
178
|
+
name;
|
|
179
|
+
description;
|
|
180
|
+
inputSchema;
|
|
181
|
+
outputSchema;
|
|
182
|
+
_execute;
|
|
183
|
+
constructor(config) {
|
|
184
|
+
this.name = config.name;
|
|
185
|
+
this.description = config.description;
|
|
186
|
+
this.inputSchema = config.inputSchema;
|
|
187
|
+
this.outputSchema = config.outputSchema;
|
|
188
|
+
this._execute = config.execute;
|
|
189
|
+
}
|
|
190
|
+
createTool(connections, config) {
|
|
191
|
+
return {
|
|
192
|
+
description: this.description,
|
|
193
|
+
inputSchema: this.inputSchema,
|
|
194
|
+
outputSchema: this.outputSchema,
|
|
195
|
+
execute: (input) => this._execute(input, connections, config)
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
};
|
|
199
|
+
|
|
200
|
+
// ../connectors/src/connector-plugin.ts
|
|
201
|
+
var ConnectorPlugin = class _ConnectorPlugin {
|
|
202
|
+
slug;
|
|
203
|
+
authType;
|
|
204
|
+
name;
|
|
205
|
+
description;
|
|
206
|
+
iconUrl;
|
|
207
|
+
parameters;
|
|
208
|
+
releaseFlag;
|
|
209
|
+
proxyPolicy;
|
|
210
|
+
experimentalAttributes;
|
|
211
|
+
onboarding;
|
|
212
|
+
systemPrompt;
|
|
213
|
+
tools;
|
|
214
|
+
query;
|
|
215
|
+
checkConnection;
|
|
216
|
+
constructor(config) {
|
|
217
|
+
this.slug = config.slug;
|
|
218
|
+
this.authType = config.authType;
|
|
219
|
+
this.name = config.name;
|
|
220
|
+
this.description = config.description;
|
|
221
|
+
this.iconUrl = config.iconUrl;
|
|
222
|
+
this.parameters = config.parameters;
|
|
223
|
+
this.releaseFlag = config.releaseFlag;
|
|
224
|
+
this.proxyPolicy = config.proxyPolicy;
|
|
225
|
+
this.experimentalAttributes = config.experimentalAttributes;
|
|
226
|
+
this.onboarding = config.onboarding;
|
|
227
|
+
this.systemPrompt = config.systemPrompt;
|
|
228
|
+
this.tools = config.tools;
|
|
229
|
+
this.query = config.query;
|
|
230
|
+
this.checkConnection = config.checkConnection;
|
|
231
|
+
}
|
|
232
|
+
get connectorKey() {
|
|
233
|
+
return _ConnectorPlugin.deriveKey(this.slug, this.authType);
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* Create tools for connections that belong to this connector.
|
|
237
|
+
* Filters connections by connectorKey internally.
|
|
238
|
+
* Returns tools keyed as `${connectorKey}_${toolName}`.
|
|
239
|
+
*/
|
|
240
|
+
createTools(connections, config) {
|
|
241
|
+
const myConnections = connections.filter(
|
|
242
|
+
(c) => _ConnectorPlugin.deriveKey(c.connector.slug, c.connector.authType) === this.connectorKey
|
|
243
|
+
);
|
|
244
|
+
const result = {};
|
|
245
|
+
for (const t of Object.values(this.tools)) {
|
|
246
|
+
result[`${this.connectorKey}_${t.name}`] = t.createTool(
|
|
247
|
+
myConnections,
|
|
248
|
+
config
|
|
249
|
+
);
|
|
250
|
+
}
|
|
251
|
+
return result;
|
|
252
|
+
}
|
|
253
|
+
static deriveKey(slug, authType) {
|
|
254
|
+
return authType ? `${slug}-${authType}` : slug;
|
|
255
|
+
}
|
|
256
|
+
};
|
|
257
|
+
|
|
258
|
+
// ../connectors/src/auth-types.ts
|
|
259
|
+
var AUTH_TYPES = {
|
|
260
|
+
OAUTH: "oauth",
|
|
261
|
+
API_KEY: "api-key",
|
|
262
|
+
JWT: "jwt",
|
|
263
|
+
SERVICE_ACCOUNT: "service-account",
|
|
264
|
+
PAT: "pat",
|
|
265
|
+
USER_PASSWORD: "user-password"
|
|
266
|
+
};
|
|
267
|
+
|
|
268
|
+
// ../connectors/src/connectors/intercom/setup.ts
|
|
269
|
+
var intercomOnboarding = new ConnectorOnboarding({
|
|
270
|
+
dataOverviewInstructions: {
|
|
271
|
+
en: `1. Call intercom_request with GET /contacts?per_page=5 to explore contacts structure
|
|
272
|
+
2. Call intercom_request with GET /conversations?per_page=5 to explore conversations structure
|
|
273
|
+
3. Call intercom_request with GET /data_attributes?model=contact to list contact data attributes
|
|
274
|
+
4. Call intercom_request with GET /companies?per_page=5 to explore company structure`,
|
|
275
|
+
ja: `1. intercom_request \u3067 GET /contacts?per_page=5 \u3092\u547C\u3073\u51FA\u3057\u3001\u30B3\u30F3\u30BF\u30AF\u30C8\u306E\u69CB\u9020\u3092\u78BA\u8A8D
|
|
276
|
+
2. intercom_request \u3067 GET /conversations?per_page=5 \u3092\u547C\u3073\u51FA\u3057\u3001\u4F1A\u8A71\u306E\u69CB\u9020\u3092\u78BA\u8A8D
|
|
277
|
+
3. intercom_request \u3067 GET /data_attributes?model=contact \u3092\u547C\u3073\u51FA\u3057\u3001\u30B3\u30F3\u30BF\u30AF\u30C8\u306E\u30C7\u30FC\u30BF\u5C5E\u6027\u3092\u78BA\u8A8D
|
|
278
|
+
4. intercom_request \u3067 GET /companies?per_page=5 \u3092\u547C\u3073\u51FA\u3057\u3001\u4F01\u696D\u306E\u69CB\u9020\u3092\u78BA\u8A8D`
|
|
279
|
+
}
|
|
280
|
+
});
|
|
281
|
+
|
|
282
|
+
// ../connectors/src/connectors/intercom/tools/request.ts
|
|
283
|
+
import { z } from "zod";
|
|
284
|
+
var BASE_URL2 = "https://api.intercom.io";
|
|
285
|
+
var API_VERSION2 = "2.11";
|
|
286
|
+
var REQUEST_TIMEOUT_MS = 6e4;
|
|
287
|
+
var inputSchema = z.object({
|
|
288
|
+
toolUseIntent: z.string().optional().describe(
|
|
289
|
+
"Brief description of what you intend to accomplish with this tool call"
|
|
290
|
+
),
|
|
291
|
+
connectionId: z.string().describe("ID of the Intercom connection to use"),
|
|
292
|
+
method: z.enum(["GET", "POST", "PUT", "DELETE"]).describe(
|
|
293
|
+
"HTTP method. GET for reading, POST for creating/searching, PUT for updating, DELETE for removing."
|
|
294
|
+
),
|
|
295
|
+
path: z.string().describe(
|
|
296
|
+
"API path appended to https://api.intercom.io (e.g., '/contacts', '/conversations', '/contacts/search')"
|
|
297
|
+
),
|
|
298
|
+
body: z.record(z.string(), z.unknown()).optional().describe("Request body (JSON) for POST/PUT requests")
|
|
299
|
+
});
|
|
300
|
+
var outputSchema = z.discriminatedUnion("success", [
|
|
301
|
+
z.object({
|
|
302
|
+
success: z.literal(true),
|
|
303
|
+
status: z.number(),
|
|
304
|
+
data: z.record(z.string(), z.unknown())
|
|
305
|
+
}),
|
|
306
|
+
z.object({
|
|
307
|
+
success: z.literal(false),
|
|
308
|
+
error: z.string()
|
|
309
|
+
})
|
|
310
|
+
]);
|
|
311
|
+
var requestTool = new ConnectorTool({
|
|
312
|
+
name: "request",
|
|
313
|
+
description: `Send authenticated requests to the Intercom API.
|
|
314
|
+
Authentication is handled automatically using the Access Token (Bearer token).
|
|
315
|
+
Use this tool for all Intercom API interactions: querying contacts, conversations, companies, articles, tags, and segments.
|
|
316
|
+
Intercom uses cursor-based pagination with the starting_after parameter from pages.next.starting_after in the response.
|
|
317
|
+
Search endpoints (contacts/search, conversations/search) use POST with a query object in the body.
|
|
318
|
+
The Intercom-Version header is set to 2.11 automatically.`,
|
|
319
|
+
inputSchema,
|
|
320
|
+
outputSchema,
|
|
321
|
+
async execute({ connectionId, method, path: path2, body }, connections) {
|
|
322
|
+
const connection2 = connections.find((c) => c.id === connectionId);
|
|
323
|
+
if (!connection2) {
|
|
324
|
+
return {
|
|
325
|
+
success: false,
|
|
326
|
+
error: `Connection ${connectionId} not found`
|
|
327
|
+
};
|
|
328
|
+
}
|
|
329
|
+
console.log(
|
|
330
|
+
`[connector-request] intercom/${connection2.name}: ${method} ${path2}`
|
|
331
|
+
);
|
|
332
|
+
try {
|
|
333
|
+
const accessToken = parameters.accessToken.getValue(connection2);
|
|
334
|
+
const url = `${BASE_URL2}${path2.startsWith("/") ? "" : "/"}${path2}`;
|
|
335
|
+
const controller = new AbortController();
|
|
336
|
+
const timeout = setTimeout(() => controller.abort(), REQUEST_TIMEOUT_MS);
|
|
337
|
+
try {
|
|
338
|
+
const response = await fetch(url, {
|
|
339
|
+
method,
|
|
340
|
+
headers: {
|
|
341
|
+
Authorization: `Bearer ${accessToken}`,
|
|
342
|
+
"Content-Type": "application/json",
|
|
343
|
+
Accept: "application/json",
|
|
344
|
+
"Intercom-Version": API_VERSION2
|
|
345
|
+
},
|
|
346
|
+
body: body ? JSON.stringify(body) : void 0,
|
|
347
|
+
signal: controller.signal
|
|
348
|
+
});
|
|
349
|
+
const data = await response.json();
|
|
350
|
+
if (!response.ok) {
|
|
351
|
+
const errors = data?.errors;
|
|
352
|
+
const errorMessage = errors?.[0]?.message ?? (typeof data?.message === "string" ? data.message : null) ?? `HTTP ${response.status} ${response.statusText}`;
|
|
353
|
+
return { success: false, error: errorMessage };
|
|
354
|
+
}
|
|
355
|
+
return { success: true, status: response.status, data };
|
|
356
|
+
} finally {
|
|
357
|
+
clearTimeout(timeout);
|
|
358
|
+
}
|
|
359
|
+
} catch (err) {
|
|
360
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
361
|
+
return { success: false, error: msg };
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
});
|
|
365
|
+
|
|
366
|
+
// ../connectors/src/connectors/intercom/index.ts
|
|
367
|
+
var tools = { request: requestTool };
|
|
368
|
+
var intercomConnector = new ConnectorPlugin({
|
|
369
|
+
slug: "intercom",
|
|
370
|
+
authType: AUTH_TYPES.API_KEY,
|
|
371
|
+
name: "Intercom",
|
|
372
|
+
description: "Connect to Intercom for contacts, conversations, companies, and customer engagement data using an Access Token.",
|
|
373
|
+
iconUrl: "https://images.ctfassets.net/9ncizv60xc5y/sb2cRMGClpId0LKiSqsok/ae90a0849f21ffe3faf73e04a5676b45/intercom.svg",
|
|
374
|
+
parameters,
|
|
375
|
+
releaseFlag: { dev1: true, dev2: false, prod: false },
|
|
376
|
+
onboarding: intercomOnboarding,
|
|
377
|
+
systemPrompt: {
|
|
378
|
+
en: `### Tools
|
|
379
|
+
|
|
380
|
+
- \`intercom_request\`: The only way to call the Intercom API. Use it to query contacts, conversations, companies, articles, tags, segments, and more. Authentication (Bearer token) and API version header (Intercom-Version: 2.11) are configured automatically. Intercom uses cursor-based pagination with the \`starting_after\` parameter from \`pages.next.starting_after\` in the response. Use search endpoints (POST) for complex queries with filters.
|
|
381
|
+
|
|
382
|
+
### Business Logic
|
|
383
|
+
|
|
384
|
+
The business logic type for this connector is "typescript". Use the connector SDK in your handler. Do NOT read credentials from environment variables.
|
|
385
|
+
|
|
386
|
+
SDK methods (client created via \`connection(connectionId)\`):
|
|
387
|
+
- \`client.request(path, init?)\` \u2014 low-level authenticated fetch
|
|
388
|
+
- \`client.listContacts(options?)\` \u2014 list contacts with pagination (per_page, starting_after)
|
|
389
|
+
- \`client.getContact(contactId)\` \u2014 fetch a single contact
|
|
390
|
+
- \`client.searchContacts(query)\` \u2014 search contacts with field/operator/value filter
|
|
391
|
+
- \`client.listConversations(options?)\` \u2014 list conversations with pagination
|
|
392
|
+
- \`client.getConversation(conversationId)\` \u2014 fetch a single conversation
|
|
393
|
+
- \`client.listCompanies(options?)\` \u2014 list companies with pagination
|
|
394
|
+
|
|
395
|
+
\`\`\`ts
|
|
396
|
+
import type { Context } from "hono";
|
|
397
|
+
import { connection } from "@squadbase/vite-server/connectors/intercom";
|
|
398
|
+
|
|
399
|
+
const intercom = connection("<connectionId>");
|
|
400
|
+
|
|
401
|
+
export default async function handler(c: Context) {
|
|
402
|
+
const { data: contacts, total_count } = await intercom.listContacts({
|
|
403
|
+
per_page: 50,
|
|
404
|
+
});
|
|
405
|
+
|
|
406
|
+
return c.json({ contacts, total_count });
|
|
407
|
+
}
|
|
408
|
+
\`\`\`
|
|
409
|
+
|
|
410
|
+
### Intercom API Reference
|
|
411
|
+
|
|
412
|
+
- Base URL: \`https://api.intercom.io\`
|
|
413
|
+
- Authentication: Bearer token (handled automatically)
|
|
414
|
+
- API Version: 2.11 (set via Intercom-Version header automatically)
|
|
415
|
+
- Pagination: Cursor-based with \`starting_after\` parameter from \`pages.next.starting_after\`
|
|
416
|
+
|
|
417
|
+
#### Contacts
|
|
418
|
+
- GET \`/contacts\` \u2014 List contacts (query params: per_page, starting_after)
|
|
419
|
+
- GET \`/contacts/{id}\` \u2014 Get a contact
|
|
420
|
+
- POST \`/contacts\` \u2014 Create a contact (body: \`{ "role": "user", "email": "..." }\`)
|
|
421
|
+
- PUT \`/contacts/{id}\` \u2014 Update a contact
|
|
422
|
+
- DELETE \`/contacts/{id}\` \u2014 Delete a contact (archive)
|
|
423
|
+
- POST \`/contacts/search\` \u2014 Search contacts (body: \`{ "query": { "field": "email", "operator": "=", "value": "..." } }\`)
|
|
424
|
+
- POST \`/contacts/merge\` \u2014 Merge contacts
|
|
425
|
+
|
|
426
|
+
#### Conversations
|
|
427
|
+
- GET \`/conversations\` \u2014 List conversations (query params: per_page, starting_after)
|
|
428
|
+
- GET \`/conversations/{id}\` \u2014 Get a conversation
|
|
429
|
+
- POST \`/conversations\` \u2014 Create a conversation
|
|
430
|
+
- PUT \`/conversations/{id}\` \u2014 Update a conversation
|
|
431
|
+
- POST \`/conversations/search\` \u2014 Search conversations
|
|
432
|
+
- POST \`/conversations/{id}/reply\` \u2014 Reply to a conversation
|
|
433
|
+
- POST \`/conversations/{id}/parts\` \u2014 Add a conversation part (note, assignment, etc.)
|
|
434
|
+
|
|
435
|
+
#### Companies
|
|
436
|
+
- GET \`/companies\` \u2014 List companies (query params: per_page, page)
|
|
437
|
+
- GET \`/companies/{id}\` \u2014 Get a company
|
|
438
|
+
- POST \`/companies\` \u2014 Create or update a company
|
|
439
|
+
- GET \`/companies/{id}/segments\` \u2014 List segments for a company
|
|
440
|
+
|
|
441
|
+
#### Articles
|
|
442
|
+
- GET \`/articles\` \u2014 List articles
|
|
443
|
+
- GET \`/articles/{id}\` \u2014 Get an article
|
|
444
|
+
- POST \`/articles\` \u2014 Create an article
|
|
445
|
+
- PUT \`/articles/{id}\` \u2014 Update an article
|
|
446
|
+
- DELETE \`/articles/{id}\` \u2014 Delete an article
|
|
447
|
+
|
|
448
|
+
#### Other Resources
|
|
449
|
+
- GET \`/tags\` \u2014 List tags
|
|
450
|
+
- GET \`/segments\` \u2014 List segments
|
|
451
|
+
- GET \`/admins\` \u2014 List admins
|
|
452
|
+
- GET \`/teams\` \u2014 List teams
|
|
453
|
+
- GET \`/data_attributes?model={model}\` \u2014 List data attributes (model: contact, company, conversation)
|
|
454
|
+
- GET \`/counts\` \u2014 App-wide counts
|
|
455
|
+
- GET \`/subscription_types\` \u2014 List subscription types
|
|
456
|
+
- GET \`/contacts/{id}/notes\` \u2014 List notes for a contact
|
|
457
|
+
- POST \`/contacts/{id}/notes\` \u2014 Create a note for a contact
|
|
458
|
+
|
|
459
|
+
#### Search Query Syntax (POST /contacts/search, /conversations/search)
|
|
460
|
+
\`\`\`json
|
|
461
|
+
{
|
|
462
|
+
"query": {
|
|
463
|
+
"operator": "AND",
|
|
464
|
+
"value": [
|
|
465
|
+
{ "field": "email", "operator": "=", "value": "user@example.com" },
|
|
466
|
+
{ "field": "created_at", "operator": ">", "value": 1672531200 }
|
|
467
|
+
]
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
\`\`\`
|
|
471
|
+
- Operators: \`=\`, \`!=\`, \`>\`, \`<\`, \`~\` (contains), \`!~\` (not contains), \`IN\`, \`NIN\`
|
|
472
|
+
- Logical: \`AND\`, \`OR\` (combine multiple filters)
|
|
473
|
+
- Date fields use Unix timestamps`,
|
|
474
|
+
ja: `### \u30C4\u30FC\u30EB
|
|
475
|
+
|
|
476
|
+
- \`intercom_request\`: Intercom API\u3092\u547C\u3073\u51FA\u3059\u552F\u4E00\u306E\u624B\u6BB5\u3067\u3059\u3002\u30B3\u30F3\u30BF\u30AF\u30C8\u3001\u4F1A\u8A71\u3001\u4F01\u696D\u3001\u8A18\u4E8B\u3001\u30BF\u30B0\u3001\u30BB\u30B0\u30E1\u30F3\u30C8\u306A\u3069\u306E\u30AF\u30A8\u30EA\u306B\u4F7F\u7528\u3057\u307E\u3059\u3002\u8A8D\u8A3C\uFF08Bearer\u30C8\u30FC\u30AF\u30F3\uFF09\u3068API\u30D0\u30FC\u30B8\u30E7\u30F3\u30D8\u30C3\u30C0\u30FC\uFF08Intercom-Version: 2.11\uFF09\u306F\u81EA\u52D5\u7684\u306B\u8A2D\u5B9A\u3055\u308C\u307E\u3059\u3002Intercom\u306F\u30EC\u30B9\u30DD\u30F3\u30B9\u306E \`pages.next.starting_after\` \u304B\u3089\u306E \`starting_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\u8907\u96D1\u306A\u30AF\u30A8\u30EA\u306B\u306Fsearch\u30A8\u30F3\u30C9\u30DD\u30A4\u30F3\u30C8\uFF08POST\uFF09\u3092\u4F7F\u7528\u3057\u307E\u3059\u3002
|
|
477
|
+
|
|
478
|
+
### Business Logic
|
|
479
|
+
|
|
480
|
+
\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
|
|
481
|
+
|
|
482
|
+
SDK\u30E1\u30BD\u30C3\u30C9 (\`connection(connectionId)\` \u3067\u4F5C\u6210\u3057\u305F\u30AF\u30E9\u30A4\u30A2\u30F3\u30C8):
|
|
483
|
+
- \`client.request(path, init?)\` \u2014 \u4F4E\u30EC\u30D9\u30EB\u306E\u8A8D\u8A3C\u4ED8\u304Dfetch
|
|
484
|
+
- \`client.listContacts(options?)\` \u2014 \u30DA\u30FC\u30B8\u30CD\u30FC\u30B7\u30E7\u30F3\u4ED8\u304D\u3067\u30B3\u30F3\u30BF\u30AF\u30C8\u3092\u4E00\u89A7\u53D6\u5F97\uFF08per_page, starting_after\uFF09
|
|
485
|
+
- \`client.getContact(contactId)\` \u2014 \u5358\u4E00\u30B3\u30F3\u30BF\u30AF\u30C8\u3092\u53D6\u5F97
|
|
486
|
+
- \`client.searchContacts(query)\` \u2014 field/operator/value\u30D5\u30A3\u30EB\u30BF\u3067\u30B3\u30F3\u30BF\u30AF\u30C8\u3092\u691C\u7D22
|
|
487
|
+
- \`client.listConversations(options?)\` \u2014 \u30DA\u30FC\u30B8\u30CD\u30FC\u30B7\u30E7\u30F3\u4ED8\u304D\u3067\u4F1A\u8A71\u3092\u4E00\u89A7\u53D6\u5F97
|
|
488
|
+
- \`client.getConversation(conversationId)\` \u2014 \u5358\u4E00\u4F1A\u8A71\u3092\u53D6\u5F97
|
|
489
|
+
- \`client.listCompanies(options?)\` \u2014 \u30DA\u30FC\u30B8\u30CD\u30FC\u30B7\u30E7\u30F3\u4ED8\u304D\u3067\u4F01\u696D\u3092\u4E00\u89A7\u53D6\u5F97
|
|
490
|
+
|
|
491
|
+
\`\`\`ts
|
|
492
|
+
import type { Context } from "hono";
|
|
493
|
+
import { connection } from "@squadbase/vite-server/connectors/intercom";
|
|
494
|
+
|
|
495
|
+
const intercom = connection("<connectionId>");
|
|
496
|
+
|
|
497
|
+
export default async function handler(c: Context) {
|
|
498
|
+
const { data: contacts, total_count } = await intercom.listContacts({
|
|
499
|
+
per_page: 50,
|
|
500
|
+
});
|
|
501
|
+
|
|
502
|
+
return c.json({ contacts, total_count });
|
|
503
|
+
}
|
|
504
|
+
\`\`\`
|
|
505
|
+
|
|
506
|
+
### Intercom API \u30EA\u30D5\u30A1\u30EC\u30F3\u30B9
|
|
507
|
+
|
|
508
|
+
- \u30D9\u30FC\u30B9URL: \`https://api.intercom.io\`
|
|
509
|
+
- \u8A8D\u8A3C: Bearer\u30C8\u30FC\u30AF\u30F3\uFF08\u81EA\u52D5\u8A2D\u5B9A\uFF09
|
|
510
|
+
- API\u30D0\u30FC\u30B8\u30E7\u30F3: 2.11\uFF08Intercom-Version\u30D8\u30C3\u30C0\u30FC\u3067\u81EA\u52D5\u8A2D\u5B9A\uFF09
|
|
511
|
+
- \u30DA\u30FC\u30B8\u30CD\u30FC\u30B7\u30E7\u30F3: \`pages.next.starting_after\` \u304B\u3089\u306E \`starting_after\` \u30D1\u30E9\u30E1\u30FC\u30BF\u306B\u3088\u308B\u30AB\u30FC\u30BD\u30EB\u30D9\u30FC\u30B9
|
|
512
|
+
|
|
513
|
+
#### \u30B3\u30F3\u30BF\u30AF\u30C8
|
|
514
|
+
- GET \`/contacts\` \u2014 \u30B3\u30F3\u30BF\u30AF\u30C8\u4E00\u89A7\u3092\u53D6\u5F97\uFF08\u30AF\u30A8\u30EA\u30D1\u30E9\u30E1\u30FC\u30BF: per_page, starting_after\uFF09
|
|
515
|
+
- GET \`/contacts/{id}\` \u2014 \u30B3\u30F3\u30BF\u30AF\u30C8\u3092\u53D6\u5F97
|
|
516
|
+
- POST \`/contacts\` \u2014 \u30B3\u30F3\u30BF\u30AF\u30C8\u3092\u4F5C\u6210\uFF08body: \`{ "role": "user", "email": "..." }\`\uFF09
|
|
517
|
+
- PUT \`/contacts/{id}\` \u2014 \u30B3\u30F3\u30BF\u30AF\u30C8\u3092\u66F4\u65B0
|
|
518
|
+
- DELETE \`/contacts/{id}\` \u2014 \u30B3\u30F3\u30BF\u30AF\u30C8\u3092\u524A\u9664\uFF08\u30A2\u30FC\u30AB\u30A4\u30D6\uFF09
|
|
519
|
+
- POST \`/contacts/search\` \u2014 \u30B3\u30F3\u30BF\u30AF\u30C8\u3092\u691C\u7D22\uFF08body: \`{ "query": { "field": "email", "operator": "=", "value": "..." } }\`\uFF09
|
|
520
|
+
- POST \`/contacts/merge\` \u2014 \u30B3\u30F3\u30BF\u30AF\u30C8\u3092\u30DE\u30FC\u30B8
|
|
521
|
+
|
|
522
|
+
#### \u4F1A\u8A71
|
|
523
|
+
- GET \`/conversations\` \u2014 \u4F1A\u8A71\u4E00\u89A7\u3092\u53D6\u5F97\uFF08\u30AF\u30A8\u30EA\u30D1\u30E9\u30E1\u30FC\u30BF: per_page, starting_after\uFF09
|
|
524
|
+
- GET \`/conversations/{id}\` \u2014 \u4F1A\u8A71\u3092\u53D6\u5F97
|
|
525
|
+
- POST \`/conversations\` \u2014 \u4F1A\u8A71\u3092\u4F5C\u6210
|
|
526
|
+
- PUT \`/conversations/{id}\` \u2014 \u4F1A\u8A71\u3092\u66F4\u65B0
|
|
527
|
+
- POST \`/conversations/search\` \u2014 \u4F1A\u8A71\u3092\u691C\u7D22
|
|
528
|
+
- POST \`/conversations/{id}/reply\` \u2014 \u4F1A\u8A71\u306B\u8FD4\u4FE1
|
|
529
|
+
- POST \`/conversations/{id}/parts\` \u2014 \u4F1A\u8A71\u30D1\u30FC\u30C4\u3092\u8FFD\u52A0\uFF08\u30E1\u30E2\u3001\u30A2\u30B5\u30A4\u30F3\u306A\u3069\uFF09
|
|
530
|
+
|
|
531
|
+
#### \u4F01\u696D
|
|
532
|
+
- GET \`/companies\` \u2014 \u4F01\u696D\u4E00\u89A7\u3092\u53D6\u5F97\uFF08\u30AF\u30A8\u30EA\u30D1\u30E9\u30E1\u30FC\u30BF: per_page, page\uFF09
|
|
533
|
+
- GET \`/companies/{id}\` \u2014 \u4F01\u696D\u3092\u53D6\u5F97
|
|
534
|
+
- POST \`/companies\` \u2014 \u4F01\u696D\u3092\u4F5C\u6210\u30FB\u66F4\u65B0
|
|
535
|
+
- GET \`/companies/{id}/segments\` \u2014 \u4F01\u696D\u306E\u30BB\u30B0\u30E1\u30F3\u30C8\u4E00\u89A7\u3092\u53D6\u5F97
|
|
536
|
+
|
|
537
|
+
#### \u8A18\u4E8B
|
|
538
|
+
- GET \`/articles\` \u2014 \u8A18\u4E8B\u4E00\u89A7\u3092\u53D6\u5F97
|
|
539
|
+
- GET \`/articles/{id}\` \u2014 \u8A18\u4E8B\u3092\u53D6\u5F97
|
|
540
|
+
- POST \`/articles\` \u2014 \u8A18\u4E8B\u3092\u4F5C\u6210
|
|
541
|
+
- PUT \`/articles/{id}\` \u2014 \u8A18\u4E8B\u3092\u66F4\u65B0
|
|
542
|
+
- DELETE \`/articles/{id}\` \u2014 \u8A18\u4E8B\u3092\u524A\u9664
|
|
543
|
+
|
|
544
|
+
#### \u305D\u306E\u4ED6\u306E\u30EA\u30BD\u30FC\u30B9
|
|
545
|
+
- GET \`/tags\` \u2014 \u30BF\u30B0\u4E00\u89A7\u3092\u53D6\u5F97
|
|
546
|
+
- GET \`/segments\` \u2014 \u30BB\u30B0\u30E1\u30F3\u30C8\u4E00\u89A7\u3092\u53D6\u5F97
|
|
547
|
+
- GET \`/admins\` \u2014 \u7BA1\u7406\u8005\u4E00\u89A7\u3092\u53D6\u5F97
|
|
548
|
+
- GET \`/teams\` \u2014 \u30C1\u30FC\u30E0\u4E00\u89A7\u3092\u53D6\u5F97
|
|
549
|
+
- GET \`/data_attributes?model={model}\` \u2014 \u30C7\u30FC\u30BF\u5C5E\u6027\u4E00\u89A7\u3092\u53D6\u5F97\uFF08model: contact, company, conversation\uFF09
|
|
550
|
+
- GET \`/counts\` \u2014 \u30A2\u30D7\u30EA\u5168\u4F53\u306E\u30AB\u30A6\u30F3\u30C8
|
|
551
|
+
- GET \`/subscription_types\` \u2014 \u30B5\u30D6\u30B9\u30AF\u30EA\u30D7\u30B7\u30E7\u30F3\u30BF\u30A4\u30D7\u4E00\u89A7\u3092\u53D6\u5F97
|
|
552
|
+
- GET \`/contacts/{id}/notes\` \u2014 \u30B3\u30F3\u30BF\u30AF\u30C8\u306E\u30E1\u30E2\u4E00\u89A7\u3092\u53D6\u5F97
|
|
553
|
+
- POST \`/contacts/{id}/notes\` \u2014 \u30B3\u30F3\u30BF\u30AF\u30C8\u306B\u30E1\u30E2\u3092\u4F5C\u6210
|
|
554
|
+
|
|
555
|
+
#### \u691C\u7D22\u30AF\u30A8\u30EA\u69CB\u6587 (POST /contacts/search, /conversations/search)
|
|
556
|
+
\`\`\`json
|
|
557
|
+
{
|
|
558
|
+
"query": {
|
|
559
|
+
"operator": "AND",
|
|
560
|
+
"value": [
|
|
561
|
+
{ "field": "email", "operator": "=", "value": "user@example.com" },
|
|
562
|
+
{ "field": "created_at", "operator": ">", "value": 1672531200 }
|
|
563
|
+
]
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
\`\`\`
|
|
567
|
+
- \u6F14\u7B97\u5B50: \`=\`, \`!=\`, \`>\`, \`<\`, \`~\`\uFF08\u542B\u3080\uFF09, \`!~\`\uFF08\u542B\u307E\u306A\u3044\uFF09, \`IN\`, \`NIN\`
|
|
568
|
+
- \u8AD6\u7406\u6F14\u7B97\u5B50: \`AND\`, \`OR\`\uFF08\u8907\u6570\u30D5\u30A3\u30EB\u30BF\u306E\u7D50\u5408\uFF09
|
|
569
|
+
- \u65E5\u4ED8\u30D5\u30A3\u30FC\u30EB\u30C9\u306FUnix\u30BF\u30A4\u30E0\u30B9\u30BF\u30F3\u30D7\u3092\u4F7F\u7528`
|
|
570
|
+
},
|
|
571
|
+
tools
|
|
572
|
+
});
|
|
573
|
+
|
|
574
|
+
// src/connectors/create-connector-sdk.ts
|
|
575
|
+
import { readFileSync } from "fs";
|
|
576
|
+
import path from "path";
|
|
577
|
+
|
|
578
|
+
// src/connector-client/env.ts
|
|
579
|
+
function resolveEnvVar(entry, key, connectionId) {
|
|
580
|
+
const envVarName = entry.envVars[key];
|
|
581
|
+
if (!envVarName) {
|
|
582
|
+
throw new Error(`Connection "${connectionId}" is missing envVars mapping for key "${key}"`);
|
|
583
|
+
}
|
|
584
|
+
const value = process.env[envVarName];
|
|
585
|
+
if (!value) {
|
|
586
|
+
throw new Error(`Environment variable "${envVarName}" (for connection "${connectionId}", key "${key}") is not set`);
|
|
587
|
+
}
|
|
588
|
+
return value;
|
|
589
|
+
}
|
|
590
|
+
function resolveEnvVarOptional(entry, key) {
|
|
591
|
+
const envVarName = entry.envVars[key];
|
|
592
|
+
if (!envVarName) return void 0;
|
|
593
|
+
return process.env[envVarName] || void 0;
|
|
594
|
+
}
|
|
595
|
+
|
|
596
|
+
// src/connector-client/proxy-fetch.ts
|
|
597
|
+
import { getContext } from "hono/context-storage";
|
|
598
|
+
import { getCookie } from "hono/cookie";
|
|
599
|
+
var APP_SESSION_COOKIE_NAME = "__Host-squadbase-session";
|
|
600
|
+
function createSandboxProxyFetch(connectionId) {
|
|
601
|
+
return async (input, init) => {
|
|
602
|
+
const token = process.env.INTERNAL_SQUADBASE_OAUTH_MACHINE_CREDENTIAL;
|
|
603
|
+
const sandboxId = process.env.INTERNAL_SQUADBASE_SANDBOX_ID;
|
|
604
|
+
if (!token || !sandboxId) {
|
|
605
|
+
throw new Error(
|
|
606
|
+
"Connection proxy is not configured. Please check your deployment settings."
|
|
607
|
+
);
|
|
608
|
+
}
|
|
609
|
+
const originalUrl = typeof input === "string" ? input : input instanceof URL ? input.href : input.url;
|
|
610
|
+
const originalMethod = init?.method ?? "GET";
|
|
611
|
+
const originalBody = init?.body ? JSON.parse(init.body) : void 0;
|
|
612
|
+
const baseDomain = process.env["SQUADBASE_PREVIEW_BASE_DOMAIN"] ?? "preview.app.squadbase.dev";
|
|
613
|
+
const proxyUrl = `https://${sandboxId}.${baseDomain}/_sqcore/connections/${connectionId}/request`;
|
|
614
|
+
return fetch(proxyUrl, {
|
|
615
|
+
method: "POST",
|
|
616
|
+
headers: {
|
|
617
|
+
"Content-Type": "application/json",
|
|
618
|
+
Authorization: `Bearer ${token}`
|
|
619
|
+
},
|
|
620
|
+
body: JSON.stringify({
|
|
621
|
+
url: originalUrl,
|
|
622
|
+
method: originalMethod,
|
|
623
|
+
body: originalBody
|
|
624
|
+
})
|
|
625
|
+
});
|
|
626
|
+
};
|
|
627
|
+
}
|
|
628
|
+
function createDeployedAppProxyFetch(connectionId) {
|
|
629
|
+
const projectId = process.env["SQUADBASE_PROJECT_ID"];
|
|
630
|
+
if (!projectId) {
|
|
631
|
+
throw new Error(
|
|
632
|
+
"Connection proxy is not configured. Please check your deployment settings."
|
|
633
|
+
);
|
|
634
|
+
}
|
|
635
|
+
const baseDomain = process.env["SQUADBASE_APP_BASE_DOMAIN"] ?? "squadbase.app";
|
|
636
|
+
const proxyUrl = `https://${projectId}.${baseDomain}/_sqcore/connections/${connectionId}/request`;
|
|
637
|
+
return async (input, init) => {
|
|
638
|
+
const originalUrl = typeof input === "string" ? input : input instanceof URL ? input.href : input.url;
|
|
639
|
+
const originalMethod = init?.method ?? "GET";
|
|
640
|
+
const originalBody = init?.body ? JSON.parse(init.body) : void 0;
|
|
641
|
+
const c = getContext();
|
|
642
|
+
const appSession = getCookie(c, APP_SESSION_COOKIE_NAME);
|
|
643
|
+
if (!appSession) {
|
|
644
|
+
throw new Error(
|
|
645
|
+
"No authentication method available for connection proxy."
|
|
646
|
+
);
|
|
647
|
+
}
|
|
648
|
+
return fetch(proxyUrl, {
|
|
649
|
+
method: "POST",
|
|
650
|
+
headers: {
|
|
651
|
+
"Content-Type": "application/json",
|
|
652
|
+
Authorization: `Bearer ${appSession}`
|
|
653
|
+
},
|
|
654
|
+
body: JSON.stringify({
|
|
655
|
+
url: originalUrl,
|
|
656
|
+
method: originalMethod,
|
|
657
|
+
body: originalBody
|
|
658
|
+
})
|
|
659
|
+
});
|
|
660
|
+
};
|
|
661
|
+
}
|
|
662
|
+
function createProxyFetch(connectionId) {
|
|
663
|
+
if (process.env.INTERNAL_SQUADBASE_SANDBOX_ID) {
|
|
664
|
+
return createSandboxProxyFetch(connectionId);
|
|
665
|
+
}
|
|
666
|
+
return createDeployedAppProxyFetch(connectionId);
|
|
667
|
+
}
|
|
668
|
+
|
|
669
|
+
// src/connectors/create-connector-sdk.ts
|
|
670
|
+
function loadConnectionsSync() {
|
|
671
|
+
const filePath = process.env.CONNECTIONS_PATH ?? path.join(process.cwd(), ".squadbase/connections.json");
|
|
672
|
+
try {
|
|
673
|
+
const raw = readFileSync(filePath, "utf-8");
|
|
674
|
+
return JSON.parse(raw);
|
|
675
|
+
} catch {
|
|
676
|
+
return {};
|
|
677
|
+
}
|
|
678
|
+
}
|
|
679
|
+
function createConnectorSdk(plugin, createClient2) {
|
|
680
|
+
return (connectionId) => {
|
|
681
|
+
const connections = loadConnectionsSync();
|
|
682
|
+
const entry = connections[connectionId];
|
|
683
|
+
if (!entry) {
|
|
684
|
+
throw new Error(
|
|
685
|
+
`Connection "${connectionId}" not found in .squadbase/connections.json`
|
|
686
|
+
);
|
|
687
|
+
}
|
|
688
|
+
if (entry.connector.slug !== plugin.slug) {
|
|
689
|
+
throw new Error(
|
|
690
|
+
`Connection "${connectionId}" is not a ${plugin.slug} connection (got "${entry.connector.slug}")`
|
|
691
|
+
);
|
|
692
|
+
}
|
|
693
|
+
const params = {};
|
|
694
|
+
for (const param of Object.values(plugin.parameters)) {
|
|
695
|
+
if (param.required) {
|
|
696
|
+
params[param.slug] = resolveEnvVar(entry, param.slug, connectionId);
|
|
697
|
+
} else {
|
|
698
|
+
const val = resolveEnvVarOptional(entry, param.slug);
|
|
699
|
+
if (val !== void 0) params[param.slug] = val;
|
|
700
|
+
}
|
|
701
|
+
}
|
|
702
|
+
return createClient2(params, createProxyFetch(connectionId));
|
|
703
|
+
};
|
|
704
|
+
}
|
|
705
|
+
|
|
706
|
+
// src/connectors/entries/intercom.ts
|
|
707
|
+
var connection = createConnectorSdk(intercomConnector, createClient);
|
|
708
|
+
export {
|
|
709
|
+
connection
|
|
710
|
+
};
|