@squadbase/vite-server 0.1.3-dev.8 → 0.1.3
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 +14229 -29321
- package/dist/connectors/airtable-oauth.js +43 -6
- package/dist/connectors/airtable.js +43 -6
- package/dist/connectors/amplitude.js +43 -6
- package/dist/connectors/anthropic.js +43 -6
- package/dist/connectors/asana.js +43 -6
- package/dist/connectors/attio.js +43 -6
- package/dist/connectors/{google-ads-oauth.d.ts → backlog-api-key.d.ts} +1 -1
- package/dist/connectors/backlog-api-key.js +629 -0
- package/dist/connectors/customerio.js +43 -6
- package/dist/connectors/dbt.js +43 -6
- package/dist/connectors/{google-sheets-oauth.d.ts → gamma.d.ts} +1 -1
- package/dist/connectors/gamma.js +866 -0
- package/dist/connectors/gemini.js +43 -6
- package/dist/connectors/gmail-oauth.js +65 -8
- package/dist/connectors/gmail.js +104 -44
- package/dist/connectors/google-ads.d.ts +1 -1
- package/dist/connectors/google-ads.js +410 -332
- package/dist/connectors/google-analytics-oauth.js +61 -8
- package/dist/connectors/google-analytics.js +107 -292
- package/dist/connectors/google-calendar-oauth.js +61 -8
- package/dist/connectors/google-calendar.js +111 -58
- package/dist/connectors/{linkedin-ads-oauth.d.ts → google-docs.d.ts} +1 -1
- package/dist/connectors/google-docs.js +631 -0
- package/dist/connectors/google-drive.d.ts +5 -0
- package/dist/connectors/google-drive.js +875 -0
- package/dist/connectors/google-sheets.d.ts +1 -1
- package/dist/connectors/google-sheets.js +267 -285
- package/dist/connectors/google-slides.d.ts +5 -0
- package/dist/connectors/google-slides.js +663 -0
- package/dist/connectors/grafana.js +43 -6
- package/dist/connectors/hubspot-oauth.js +43 -6
- package/dist/connectors/hubspot.js +43 -6
- package/dist/connectors/intercom-oauth.js +43 -6
- package/dist/connectors/intercom.js +43 -6
- package/dist/connectors/jira-api-key.js +43 -6
- package/dist/connectors/kintone-api-token.js +256 -82
- package/dist/connectors/kintone.js +43 -6
- package/dist/connectors/linkedin-ads.js +188 -168
- package/dist/connectors/mailchimp-oauth.js +43 -6
- package/dist/connectors/mailchimp.js +43 -6
- package/dist/connectors/mixpanel.d.ts +5 -0
- package/dist/connectors/mixpanel.js +779 -0
- package/dist/connectors/notion-oauth.js +43 -6
- package/dist/connectors/notion.js +43 -6
- package/dist/connectors/openai.js +43 -6
- package/dist/connectors/sentry.d.ts +5 -0
- package/dist/connectors/sentry.js +761 -0
- package/dist/connectors/shopify-oauth.js +43 -6
- package/dist/connectors/shopify.js +43 -6
- package/dist/connectors/stripe-api-key.js +46 -7
- package/dist/connectors/stripe-oauth.js +43 -6
- package/dist/connectors/wix-store.js +43 -6
- package/dist/connectors/zendesk-oauth.js +43 -6
- package/dist/connectors/zendesk.js +43 -6
- package/dist/index.d.ts +1 -1
- package/dist/index.js +4419 -3855
- package/dist/main.js +5481 -4918
- package/dist/vite-plugin.js +4474 -3948
- package/package.json +30 -12
- package/dist/connectors/google-ads-oauth.js +0 -890
- package/dist/connectors/google-sheets-oauth.js +0 -718
- package/dist/connectors/linkedin-ads-oauth.js +0 -848
|
@@ -1,890 +0,0 @@
|
|
|
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/google-ads-oauth/parameters.ts
|
|
46
|
-
var parameters = {
|
|
47
|
-
customerId: new ParameterDefinition({
|
|
48
|
-
slug: "customer-id",
|
|
49
|
-
name: "Google Ads Customer ID",
|
|
50
|
-
description: "The Google Ads customer ID (e.g., 123-456-7890 or 1234567890). Can be found in the top-right corner of your Google Ads account.",
|
|
51
|
-
envVarBaseKey: "GOOGLE_ADS_OAUTH_CUSTOMER_ID",
|
|
52
|
-
type: "text",
|
|
53
|
-
secret: false,
|
|
54
|
-
required: false
|
|
55
|
-
}),
|
|
56
|
-
developerToken: new ParameterDefinition({
|
|
57
|
-
slug: "developer-token",
|
|
58
|
-
name: "Google Ads Developer Token",
|
|
59
|
-
description: "The developer token for accessing the Google Ads API. Required for all API requests.",
|
|
60
|
-
envVarBaseKey: "GOOGLE_ADS_DEVELOPER_TOKEN",
|
|
61
|
-
type: "text",
|
|
62
|
-
secret: true,
|
|
63
|
-
required: true
|
|
64
|
-
})
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
// ../connectors/src/connectors/google-ads-oauth/sdk/index.ts
|
|
68
|
-
var BASE_URL = "https://googleads.googleapis.com/v18/";
|
|
69
|
-
function createClient(params, fetchFn = fetch) {
|
|
70
|
-
const rawCustomerId = params[parameters.customerId.slug];
|
|
71
|
-
const defaultCustomerId = rawCustomerId?.replace(/-/g, "") ?? "";
|
|
72
|
-
const developerToken = params[parameters.developerToken.slug];
|
|
73
|
-
if (!developerToken) {
|
|
74
|
-
throw new Error(
|
|
75
|
-
`google-ads: missing required parameter: ${parameters.developerToken.slug}`
|
|
76
|
-
);
|
|
77
|
-
}
|
|
78
|
-
function resolveCustomerId(override) {
|
|
79
|
-
const id = override?.replace(/-/g, "") ?? defaultCustomerId;
|
|
80
|
-
if (!id) {
|
|
81
|
-
throw new Error(
|
|
82
|
-
"google-ads: customerId is required. Either configure a default or pass it explicitly."
|
|
83
|
-
);
|
|
84
|
-
}
|
|
85
|
-
return id;
|
|
86
|
-
}
|
|
87
|
-
function request(path2, init) {
|
|
88
|
-
const resolvedPath = defaultCustomerId ? path2.replace(/\{customerId\}/g, defaultCustomerId) : path2;
|
|
89
|
-
const url = `${BASE_URL}${resolvedPath}`;
|
|
90
|
-
const headers = new Headers(init?.headers);
|
|
91
|
-
headers.set("developer-token", developerToken);
|
|
92
|
-
if (defaultCustomerId) {
|
|
93
|
-
headers.set("login-customer-id", defaultCustomerId);
|
|
94
|
-
}
|
|
95
|
-
return fetchFn(url, { ...init, headers });
|
|
96
|
-
}
|
|
97
|
-
async function search(query, customerId) {
|
|
98
|
-
const cid = resolveCustomerId(customerId);
|
|
99
|
-
const url = `${BASE_URL}customers/${cid}/googleAds:searchStream`;
|
|
100
|
-
const headers = new Headers();
|
|
101
|
-
headers.set("Content-Type", "application/json");
|
|
102
|
-
headers.set("developer-token", developerToken);
|
|
103
|
-
headers.set("login-customer-id", cid);
|
|
104
|
-
const response = await fetchFn(url, {
|
|
105
|
-
method: "POST",
|
|
106
|
-
headers,
|
|
107
|
-
body: JSON.stringify({ query })
|
|
108
|
-
});
|
|
109
|
-
if (!response.ok) {
|
|
110
|
-
const body = await response.text();
|
|
111
|
-
throw new Error(
|
|
112
|
-
`google-ads: search failed (${response.status}): ${body}`
|
|
113
|
-
);
|
|
114
|
-
}
|
|
115
|
-
const data = await response.json();
|
|
116
|
-
return data.flatMap((chunk) => chunk.results ?? []);
|
|
117
|
-
}
|
|
118
|
-
async function listAccessibleCustomers() {
|
|
119
|
-
const url = `${BASE_URL}customers:listAccessibleCustomers`;
|
|
120
|
-
const headers = new Headers();
|
|
121
|
-
headers.set("developer-token", developerToken);
|
|
122
|
-
const response = await fetchFn(url, { method: "GET", headers });
|
|
123
|
-
if (!response.ok) {
|
|
124
|
-
const body = await response.text();
|
|
125
|
-
throw new Error(
|
|
126
|
-
`google-ads: listAccessibleCustomers failed (${response.status}): ${body}`
|
|
127
|
-
);
|
|
128
|
-
}
|
|
129
|
-
const data = await response.json();
|
|
130
|
-
return (data.resourceNames ?? []).map(
|
|
131
|
-
(rn) => rn.replace(/^customers\//, "")
|
|
132
|
-
);
|
|
133
|
-
}
|
|
134
|
-
return {
|
|
135
|
-
request,
|
|
136
|
-
search,
|
|
137
|
-
listAccessibleCustomers
|
|
138
|
-
};
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
// ../connectors/src/connector-onboarding.ts
|
|
142
|
-
var ConnectorOnboarding = class {
|
|
143
|
-
/** Phase 1: Connection setup instructions (optional — some connectors don't need this) */
|
|
144
|
-
connectionSetupInstructions;
|
|
145
|
-
/** Phase 2: Data overview instructions */
|
|
146
|
-
dataOverviewInstructions;
|
|
147
|
-
constructor(config) {
|
|
148
|
-
this.connectionSetupInstructions = config.connectionSetupInstructions;
|
|
149
|
-
this.dataOverviewInstructions = config.dataOverviewInstructions;
|
|
150
|
-
}
|
|
151
|
-
getConnectionSetupPrompt(language) {
|
|
152
|
-
return this.connectionSetupInstructions?.[language] ?? null;
|
|
153
|
-
}
|
|
154
|
-
getDataOverviewInstructions(language) {
|
|
155
|
-
return this.dataOverviewInstructions[language];
|
|
156
|
-
}
|
|
157
|
-
};
|
|
158
|
-
|
|
159
|
-
// ../connectors/src/connector-tool.ts
|
|
160
|
-
var ConnectorTool = class {
|
|
161
|
-
name;
|
|
162
|
-
description;
|
|
163
|
-
inputSchema;
|
|
164
|
-
outputSchema;
|
|
165
|
-
_execute;
|
|
166
|
-
constructor(config) {
|
|
167
|
-
this.name = config.name;
|
|
168
|
-
this.description = config.description;
|
|
169
|
-
this.inputSchema = config.inputSchema;
|
|
170
|
-
this.outputSchema = config.outputSchema;
|
|
171
|
-
this._execute = config.execute;
|
|
172
|
-
}
|
|
173
|
-
createTool(connections, config) {
|
|
174
|
-
return {
|
|
175
|
-
description: this.description,
|
|
176
|
-
inputSchema: this.inputSchema,
|
|
177
|
-
outputSchema: this.outputSchema,
|
|
178
|
-
execute: (input) => this._execute(input, connections, config)
|
|
179
|
-
};
|
|
180
|
-
}
|
|
181
|
-
};
|
|
182
|
-
|
|
183
|
-
// ../connectors/src/connector-plugin.ts
|
|
184
|
-
var ConnectorPlugin = class _ConnectorPlugin {
|
|
185
|
-
slug;
|
|
186
|
-
authType;
|
|
187
|
-
name;
|
|
188
|
-
description;
|
|
189
|
-
iconUrl;
|
|
190
|
-
parameters;
|
|
191
|
-
releaseFlag;
|
|
192
|
-
proxyPolicy;
|
|
193
|
-
experimentalAttributes;
|
|
194
|
-
onboarding;
|
|
195
|
-
systemPrompt;
|
|
196
|
-
tools;
|
|
197
|
-
query;
|
|
198
|
-
checkConnection;
|
|
199
|
-
constructor(config) {
|
|
200
|
-
this.slug = config.slug;
|
|
201
|
-
this.authType = config.authType;
|
|
202
|
-
this.name = config.name;
|
|
203
|
-
this.description = config.description;
|
|
204
|
-
this.iconUrl = config.iconUrl;
|
|
205
|
-
this.parameters = config.parameters;
|
|
206
|
-
this.releaseFlag = config.releaseFlag;
|
|
207
|
-
this.proxyPolicy = config.proxyPolicy;
|
|
208
|
-
this.experimentalAttributes = config.experimentalAttributes;
|
|
209
|
-
this.onboarding = config.onboarding;
|
|
210
|
-
this.systemPrompt = config.systemPrompt;
|
|
211
|
-
this.tools = config.tools;
|
|
212
|
-
this.query = config.query;
|
|
213
|
-
this.checkConnection = config.checkConnection;
|
|
214
|
-
}
|
|
215
|
-
get connectorKey() {
|
|
216
|
-
return _ConnectorPlugin.deriveKey(this.slug, this.authType);
|
|
217
|
-
}
|
|
218
|
-
/**
|
|
219
|
-
* Create tools for connections that belong to this connector.
|
|
220
|
-
* Filters connections by connectorKey internally.
|
|
221
|
-
* Returns tools keyed as `${connectorKey}_${toolName}`.
|
|
222
|
-
*/
|
|
223
|
-
createTools(connections, config) {
|
|
224
|
-
const myConnections = connections.filter(
|
|
225
|
-
(c) => _ConnectorPlugin.deriveKey(c.connector.slug, c.connector.authType) === this.connectorKey
|
|
226
|
-
);
|
|
227
|
-
const result = {};
|
|
228
|
-
for (const t of Object.values(this.tools)) {
|
|
229
|
-
result[`${this.connectorKey}_${t.name}`] = t.createTool(
|
|
230
|
-
myConnections,
|
|
231
|
-
config
|
|
232
|
-
);
|
|
233
|
-
}
|
|
234
|
-
return result;
|
|
235
|
-
}
|
|
236
|
-
static deriveKey(slug, authType) {
|
|
237
|
-
return authType ? `${slug}-${authType}` : slug;
|
|
238
|
-
}
|
|
239
|
-
};
|
|
240
|
-
|
|
241
|
-
// ../connectors/src/auth-types.ts
|
|
242
|
-
var AUTH_TYPES = {
|
|
243
|
-
OAUTH: "oauth",
|
|
244
|
-
API_KEY: "api-key",
|
|
245
|
-
JWT: "jwt",
|
|
246
|
-
SERVICE_ACCOUNT: "service-account",
|
|
247
|
-
PAT: "pat",
|
|
248
|
-
USER_PASSWORD: "user-password"
|
|
249
|
-
};
|
|
250
|
-
|
|
251
|
-
// ../connectors/src/connectors/google-ads-oauth/tools/list-customers.ts
|
|
252
|
-
import { z } from "zod";
|
|
253
|
-
var BASE_URL2 = "https://googleads.googleapis.com/v18/";
|
|
254
|
-
var REQUEST_TIMEOUT_MS = 6e4;
|
|
255
|
-
var cachedToken = null;
|
|
256
|
-
async function getProxyToken(config) {
|
|
257
|
-
if (cachedToken && cachedToken.expiresAt > Date.now() + 6e4) {
|
|
258
|
-
return cachedToken.token;
|
|
259
|
-
}
|
|
260
|
-
const url = `${config.appApiBaseUrl}/v0/database/${config.projectId}/environment/${config.environmentId}/oauth-request-proxy-token`;
|
|
261
|
-
const res = await fetch(url, {
|
|
262
|
-
method: "POST",
|
|
263
|
-
headers: {
|
|
264
|
-
"Content-Type": "application/json",
|
|
265
|
-
"x-api-key": config.appApiKey,
|
|
266
|
-
"project-id": config.projectId
|
|
267
|
-
},
|
|
268
|
-
body: JSON.stringify({
|
|
269
|
-
sandboxId: config.sandboxId,
|
|
270
|
-
issuedBy: "coding-agent"
|
|
271
|
-
})
|
|
272
|
-
});
|
|
273
|
-
if (!res.ok) {
|
|
274
|
-
const errorText = await res.text().catch(() => res.statusText);
|
|
275
|
-
throw new Error(
|
|
276
|
-
`Failed to get proxy token: HTTP ${res.status} ${errorText}`
|
|
277
|
-
);
|
|
278
|
-
}
|
|
279
|
-
const data = await res.json();
|
|
280
|
-
cachedToken = {
|
|
281
|
-
token: data.token,
|
|
282
|
-
expiresAt: new Date(data.expiresAt).getTime()
|
|
283
|
-
};
|
|
284
|
-
return data.token;
|
|
285
|
-
}
|
|
286
|
-
var inputSchema = z.object({
|
|
287
|
-
toolUseIntent: z.string().optional().describe(
|
|
288
|
-
"Brief description of what you intend to accomplish with this tool call"
|
|
289
|
-
),
|
|
290
|
-
connectionId: z.string().describe("ID of the Google Ads OAuth connection to use")
|
|
291
|
-
});
|
|
292
|
-
var outputSchema = z.discriminatedUnion("success", [
|
|
293
|
-
z.object({
|
|
294
|
-
success: z.literal(true),
|
|
295
|
-
customers: z.array(
|
|
296
|
-
z.object({
|
|
297
|
-
customerId: z.string(),
|
|
298
|
-
descriptiveName: z.string()
|
|
299
|
-
})
|
|
300
|
-
)
|
|
301
|
-
}),
|
|
302
|
-
z.object({
|
|
303
|
-
success: z.literal(false),
|
|
304
|
-
error: z.string()
|
|
305
|
-
})
|
|
306
|
-
]);
|
|
307
|
-
var listCustomersTool = new ConnectorTool({
|
|
308
|
-
name: "listCustomers",
|
|
309
|
-
description: "List Google Ads customer accounts accessible with the current OAuth credentials.",
|
|
310
|
-
inputSchema,
|
|
311
|
-
outputSchema,
|
|
312
|
-
async execute({ connectionId }, connections, config) {
|
|
313
|
-
const connection2 = connections.find((c) => c.id === connectionId);
|
|
314
|
-
if (!connection2) {
|
|
315
|
-
return {
|
|
316
|
-
success: false,
|
|
317
|
-
error: `Connection ${connectionId} not found`
|
|
318
|
-
};
|
|
319
|
-
}
|
|
320
|
-
console.log(
|
|
321
|
-
`[connector-request] google-ads-oauth/${connection2.name}: listCustomers`
|
|
322
|
-
);
|
|
323
|
-
try {
|
|
324
|
-
const developerToken = parameters.developerToken.getValue(connection2);
|
|
325
|
-
const token = await getProxyToken(config.oauthProxy);
|
|
326
|
-
const proxyUrl = `https://${config.oauthProxy.sandboxId}.${config.oauthProxy.previewBaseDomain}/_sqcore/connections/${connectionId}/request`;
|
|
327
|
-
const controller = new AbortController();
|
|
328
|
-
const timeout = setTimeout(() => controller.abort(), REQUEST_TIMEOUT_MS);
|
|
329
|
-
try {
|
|
330
|
-
const response = await fetch(proxyUrl, {
|
|
331
|
-
method: "POST",
|
|
332
|
-
headers: {
|
|
333
|
-
"Content-Type": "application/json",
|
|
334
|
-
Authorization: `Bearer ${token}`
|
|
335
|
-
},
|
|
336
|
-
body: JSON.stringify({
|
|
337
|
-
url: `${BASE_URL2}customers:listAccessibleCustomers`,
|
|
338
|
-
method: "GET",
|
|
339
|
-
headers: {
|
|
340
|
-
"developer-token": developerToken
|
|
341
|
-
}
|
|
342
|
-
}),
|
|
343
|
-
signal: controller.signal
|
|
344
|
-
});
|
|
345
|
-
const data = await response.json();
|
|
346
|
-
if (!response.ok) {
|
|
347
|
-
const errorMessage = typeof data?.error === "string" ? data.error : typeof data?.message === "string" ? data.message : `HTTP ${response.status} ${response.statusText}`;
|
|
348
|
-
return { success: false, error: errorMessage };
|
|
349
|
-
}
|
|
350
|
-
const customerIds = (data.resourceNames ?? []).map(
|
|
351
|
-
(rn) => rn.replace(/^customers\//, "")
|
|
352
|
-
);
|
|
353
|
-
const customers = [];
|
|
354
|
-
for (const cid of customerIds) {
|
|
355
|
-
try {
|
|
356
|
-
const detailResponse = await fetch(proxyUrl, {
|
|
357
|
-
method: "POST",
|
|
358
|
-
headers: {
|
|
359
|
-
"Content-Type": "application/json",
|
|
360
|
-
Authorization: `Bearer ${token}`
|
|
361
|
-
},
|
|
362
|
-
body: JSON.stringify({
|
|
363
|
-
url: `${BASE_URL2}customers/${cid}/googleAds:searchStream`,
|
|
364
|
-
method: "POST",
|
|
365
|
-
headers: {
|
|
366
|
-
"Content-Type": "application/json",
|
|
367
|
-
"developer-token": developerToken,
|
|
368
|
-
"login-customer-id": cid
|
|
369
|
-
},
|
|
370
|
-
body: JSON.stringify({
|
|
371
|
-
query: "SELECT customer.id, customer.descriptive_name FROM customer LIMIT 1"
|
|
372
|
-
})
|
|
373
|
-
}),
|
|
374
|
-
signal: controller.signal
|
|
375
|
-
});
|
|
376
|
-
if (detailResponse.ok) {
|
|
377
|
-
const detailData = await detailResponse.json();
|
|
378
|
-
const customer = detailData?.[0]?.results?.[0]?.customer;
|
|
379
|
-
customers.push({
|
|
380
|
-
customerId: cid,
|
|
381
|
-
descriptiveName: customer?.descriptiveName ?? cid
|
|
382
|
-
});
|
|
383
|
-
} else {
|
|
384
|
-
customers.push({
|
|
385
|
-
customerId: cid,
|
|
386
|
-
descriptiveName: cid
|
|
387
|
-
});
|
|
388
|
-
}
|
|
389
|
-
} catch {
|
|
390
|
-
customers.push({
|
|
391
|
-
customerId: cid,
|
|
392
|
-
descriptiveName: cid
|
|
393
|
-
});
|
|
394
|
-
}
|
|
395
|
-
}
|
|
396
|
-
return { success: true, customers };
|
|
397
|
-
} finally {
|
|
398
|
-
clearTimeout(timeout);
|
|
399
|
-
}
|
|
400
|
-
} catch (err) {
|
|
401
|
-
const msg = err instanceof Error ? err.message : String(err);
|
|
402
|
-
return { success: false, error: msg };
|
|
403
|
-
}
|
|
404
|
-
}
|
|
405
|
-
});
|
|
406
|
-
|
|
407
|
-
// ../connectors/src/connectors/google-ads-oauth/setup.ts
|
|
408
|
-
var listCustomersToolName = `google-ads-oauth_${listCustomersTool.name}`;
|
|
409
|
-
var googleAdsOnboarding = new ConnectorOnboarding({
|
|
410
|
-
connectionSetupInstructions: {
|
|
411
|
-
ja: `\u4EE5\u4E0B\u306E\u624B\u9806\u3067Google Ads (OAuth) \u30B3\u30CD\u30AF\u30B7\u30E7\u30F3\u306E\u30BB\u30C3\u30C8\u30A2\u30C3\u30D7\u3092\u884C\u3063\u3066\u304F\u3060\u3055\u3044\u3002
|
|
412
|
-
|
|
413
|
-
1. \u30E6\u30FC\u30B6\u30FC\u306B\u300CGoogle Ads API \u306E Developer Token \u3092\u5165\u529B\u3057\u3066\u304F\u3060\u3055\u3044\uFF08Google Ads \u7BA1\u7406\u753B\u9762 > \u30C4\u30FC\u30EB\u3068\u8A2D\u5B9A > API \u30BB\u30F3\u30BF\u30FC\u3067\u53D6\u5F97\u3067\u304D\u307E\u3059\uFF09\u300D\u3068\u4F1D\u3048\u308B
|
|
414
|
-
2. \`updateConnectionParameters\` \u3092\u547C\u3073\u51FA\u3059:
|
|
415
|
-
- \`parameterSlug\`: \`"developer-token"\`
|
|
416
|
-
- \`value\`: \u30E6\u30FC\u30B6\u30FC\u304C\u63D0\u4F9B\u3057\u305F Developer Token
|
|
417
|
-
3. \`${listCustomersToolName}\` \u3092\u547C\u3073\u51FA\u3057\u3066\u3001OAuth\u3067\u30A2\u30AF\u30BB\u30B9\u53EF\u80FD\u306AGoogle Ads\u30AB\u30B9\u30BF\u30DE\u30FC\u30A2\u30AB\u30A6\u30F3\u30C8\u4E00\u89A7\u3092\u53D6\u5F97\u3059\u308B
|
|
418
|
-
4. \`updateConnectionParameters\` \u3092\u547C\u3073\u51FA\u3059:
|
|
419
|
-
- \`parameterSlug\`: \`"customer-id"\`
|
|
420
|
-
- \`options\`: \u30AB\u30B9\u30BF\u30DE\u30FC\u4E00\u89A7\u3002\u5404 option \u306E \`label\` \u306F \`\u30A2\u30AB\u30A6\u30F3\u30C8\u540D (id: \u30AB\u30B9\u30BF\u30DE\u30FCID)\` \u306E\u5F62\u5F0F\u3001\`value\` \u306F\u30AB\u30B9\u30BF\u30DE\u30FCID
|
|
421
|
-
5. \u30E6\u30FC\u30B6\u30FC\u304C\u9078\u629E\u3057\u305F\u30AB\u30B9\u30BF\u30DE\u30FC\u306E \`label\` \u304C\u30E1\u30C3\u30BB\u30FC\u30B8\u3068\u3057\u3066\u5C4A\u304F\u306E\u3067\u3001\u6B21\u306E\u30B9\u30C6\u30C3\u30D7\u306B\u9032\u3080
|
|
422
|
-
6. \`updateConnectionContext\` \u3092\u547C\u3073\u51FA\u3059:
|
|
423
|
-
- \`customer\`: \u9078\u629E\u3055\u308C\u305F\u30AB\u30B9\u30BF\u30DE\u30FC\u306E\u8868\u793A\u540D
|
|
424
|
-
- \`customerId\`: \u9078\u629E\u3055\u308C\u305F\u30AB\u30B9\u30BF\u30DE\u30FCID
|
|
425
|
-
- \`note\`: \u30BB\u30C3\u30C8\u30A2\u30C3\u30D7\u5185\u5BB9\u306E\u7C21\u5358\u306A\u8AAC\u660E
|
|
426
|
-
|
|
427
|
-
#### \u5236\u7D04
|
|
428
|
-
- **\u30BB\u30C3\u30C8\u30A2\u30C3\u30D7\u4E2D\u306B\u30EC\u30DD\u30FC\u30C8\u30C7\u30FC\u30BF\u3092\u53D6\u5F97\u3057\u306A\u3044\u3053\u3068**\u3002\u5B9F\u884C\u3057\u3066\u3088\u3044\u306E\u306F\u4E0A\u8A18\u624B\u9806\u3067\u6307\u5B9A\u3055\u308C\u305F\u30E1\u30BF\u30C7\u30FC\u30BF\u53D6\u5F97\u306E\u307F
|
|
429
|
-
- \u30C4\u30FC\u30EB\u9593\u306F1\u6587\u3060\u3051\u66F8\u3044\u3066\u5373\u6B21\u306E\u30C4\u30FC\u30EB\u547C\u3073\u51FA\u3057\u3002\u4E0D\u8981\u306A\u8AAC\u660E\u306F\u7701\u7565\u3057\u3001\u52B9\u7387\u7684\u306B\u9032\u3081\u308B`,
|
|
430
|
-
en: `Follow these steps to set up the Google Ads (OAuth) connection.
|
|
431
|
-
|
|
432
|
-
1. Ask the user to provide their Google Ads API Developer Token (available in Google Ads UI > Tools & Settings > API Center)
|
|
433
|
-
2. Call \`updateConnectionParameters\`:
|
|
434
|
-
- \`parameterSlug\`: \`"developer-token"\`
|
|
435
|
-
- \`value\`: The Developer Token provided by the user
|
|
436
|
-
3. Call \`${listCustomersToolName}\` to get the list of Google Ads customer accounts accessible with the OAuth credentials
|
|
437
|
-
4. Call \`updateConnectionParameters\`:
|
|
438
|
-
- \`parameterSlug\`: \`"customer-id"\`
|
|
439
|
-
- \`options\`: The customer list. Each option's \`label\` should be \`Account Name (id: customerId)\`, \`value\` should be the customer ID
|
|
440
|
-
5. The \`label\` of the user's selected customer will arrive as a message. Proceed to the next step
|
|
441
|
-
6. Call \`updateConnectionContext\`:
|
|
442
|
-
- \`customer\`: The selected customer's display name
|
|
443
|
-
- \`customerId\`: The selected customer ID
|
|
444
|
-
- \`note\`: Brief description of the setup
|
|
445
|
-
|
|
446
|
-
#### Constraints
|
|
447
|
-
- **Do NOT fetch report data during setup**. Only the metadata requests specified in the steps above are allowed
|
|
448
|
-
- Write only 1 sentence between tool calls, then immediately call the next tool. Skip unnecessary explanations and proceed efficiently`
|
|
449
|
-
},
|
|
450
|
-
dataOverviewInstructions: {
|
|
451
|
-
en: `1. Call google-ads-oauth_request with POST customers/{customerId}/googleAds:searchStream to explore available campaign data using GAQL: SELECT campaign.id, campaign.name, campaign.status FROM campaign LIMIT 10
|
|
452
|
-
2. Explore ad group and keyword data as needed to understand the data structure`,
|
|
453
|
-
ja: `1. google-ads-oauth_request \u3067 POST customers/{customerId}/googleAds:searchStream \u3092\u547C\u3073\u51FA\u3057\u3001GAQL\u3067\u30AD\u30E3\u30F3\u30DA\u30FC\u30F3\u30C7\u30FC\u30BF\u3092\u63A2\u7D22: SELECT campaign.id, campaign.name, campaign.status FROM campaign LIMIT 10
|
|
454
|
-
2. \u5FC5\u8981\u306B\u5FDC\u3058\u3066\u5E83\u544A\u30B0\u30EB\u30FC\u30D7\u3084\u30AD\u30FC\u30EF\u30FC\u30C9\u30C7\u30FC\u30BF\u3092\u63A2\u7D22\u3057\u3001\u30C7\u30FC\u30BF\u69CB\u9020\u3092\u628A\u63E1`
|
|
455
|
-
}
|
|
456
|
-
});
|
|
457
|
-
|
|
458
|
-
// ../connectors/src/connectors/google-ads-oauth/tools/request.ts
|
|
459
|
-
import { z as z2 } from "zod";
|
|
460
|
-
var BASE_URL3 = "https://googleads.googleapis.com/v18/";
|
|
461
|
-
var REQUEST_TIMEOUT_MS2 = 6e4;
|
|
462
|
-
var cachedToken2 = null;
|
|
463
|
-
async function getProxyToken2(config) {
|
|
464
|
-
if (cachedToken2 && cachedToken2.expiresAt > Date.now() + 6e4) {
|
|
465
|
-
return cachedToken2.token;
|
|
466
|
-
}
|
|
467
|
-
const url = `${config.appApiBaseUrl}/v0/database/${config.projectId}/environment/${config.environmentId}/oauth-request-proxy-token`;
|
|
468
|
-
const res = await fetch(url, {
|
|
469
|
-
method: "POST",
|
|
470
|
-
headers: {
|
|
471
|
-
"Content-Type": "application/json",
|
|
472
|
-
"x-api-key": config.appApiKey,
|
|
473
|
-
"project-id": config.projectId
|
|
474
|
-
},
|
|
475
|
-
body: JSON.stringify({
|
|
476
|
-
sandboxId: config.sandboxId,
|
|
477
|
-
issuedBy: "coding-agent"
|
|
478
|
-
})
|
|
479
|
-
});
|
|
480
|
-
if (!res.ok) {
|
|
481
|
-
const errorText = await res.text().catch(() => res.statusText);
|
|
482
|
-
throw new Error(
|
|
483
|
-
`Failed to get proxy token: HTTP ${res.status} ${errorText}`
|
|
484
|
-
);
|
|
485
|
-
}
|
|
486
|
-
const data = await res.json();
|
|
487
|
-
cachedToken2 = {
|
|
488
|
-
token: data.token,
|
|
489
|
-
expiresAt: new Date(data.expiresAt).getTime()
|
|
490
|
-
};
|
|
491
|
-
return data.token;
|
|
492
|
-
}
|
|
493
|
-
var inputSchema2 = z2.object({
|
|
494
|
-
toolUseIntent: z2.string().optional().describe(
|
|
495
|
-
"Brief description of what you intend to accomplish with this tool call"
|
|
496
|
-
),
|
|
497
|
-
connectionId: z2.string().describe("ID of the Google Ads OAuth connection to use"),
|
|
498
|
-
method: z2.enum(["GET", "POST"]).describe("HTTP method"),
|
|
499
|
-
path: z2.string().describe(
|
|
500
|
-
"API path appended to https://googleads.googleapis.com/v18/ (e.g., 'customers/{customerId}/googleAds:searchStream'). {customerId} is automatically replaced."
|
|
501
|
-
),
|
|
502
|
-
body: z2.record(z2.string(), z2.unknown()).optional().describe("POST request body (JSON)")
|
|
503
|
-
});
|
|
504
|
-
var outputSchema2 = z2.discriminatedUnion("success", [
|
|
505
|
-
z2.object({
|
|
506
|
-
success: z2.literal(true),
|
|
507
|
-
status: z2.number(),
|
|
508
|
-
data: z2.unknown()
|
|
509
|
-
}),
|
|
510
|
-
z2.object({
|
|
511
|
-
success: z2.literal(false),
|
|
512
|
-
error: z2.string()
|
|
513
|
-
})
|
|
514
|
-
]);
|
|
515
|
-
var requestTool = new ConnectorTool({
|
|
516
|
-
name: "request",
|
|
517
|
-
description: `Send authenticated requests to the Google Ads API v18.
|
|
518
|
-
Authentication is handled automatically via OAuth proxy.
|
|
519
|
-
{customerId} in the path is automatically replaced with the connection's customer ID (hyphens removed).`,
|
|
520
|
-
inputSchema: inputSchema2,
|
|
521
|
-
outputSchema: outputSchema2,
|
|
522
|
-
async execute({ connectionId, method, path: path2, body }, connections, config) {
|
|
523
|
-
const connection2 = connections.find((c) => c.id === connectionId);
|
|
524
|
-
if (!connection2) {
|
|
525
|
-
return {
|
|
526
|
-
success: false,
|
|
527
|
-
error: `Connection ${connectionId} not found`
|
|
528
|
-
};
|
|
529
|
-
}
|
|
530
|
-
console.log(
|
|
531
|
-
`[connector-request] google-ads-oauth/${connection2.name}: ${method} ${path2}`
|
|
532
|
-
);
|
|
533
|
-
try {
|
|
534
|
-
const rawCustomerId = parameters.customerId.tryGetValue(connection2);
|
|
535
|
-
const customerId = rawCustomerId?.replace(/-/g, "") ?? "";
|
|
536
|
-
const resolvedPath = customerId ? path2.replace(/\{customerId\}/g, customerId) : path2;
|
|
537
|
-
const url = `${BASE_URL3}${resolvedPath}`;
|
|
538
|
-
const token = await getProxyToken2(config.oauthProxy);
|
|
539
|
-
const proxyUrl = `https://${config.oauthProxy.sandboxId}.${config.oauthProxy.previewBaseDomain}/_sqcore/connections/${connectionId}/request`;
|
|
540
|
-
const controller = new AbortController();
|
|
541
|
-
const timeout = setTimeout(() => controller.abort(), REQUEST_TIMEOUT_MS2);
|
|
542
|
-
try {
|
|
543
|
-
const developerToken = parameters.developerToken.getValue(connection2);
|
|
544
|
-
const response = await fetch(proxyUrl, {
|
|
545
|
-
method: "POST",
|
|
546
|
-
headers: {
|
|
547
|
-
"Content-Type": "application/json",
|
|
548
|
-
Authorization: `Bearer ${token}`
|
|
549
|
-
},
|
|
550
|
-
body: JSON.stringify({
|
|
551
|
-
url,
|
|
552
|
-
method,
|
|
553
|
-
headers: {
|
|
554
|
-
"Content-Type": "application/json",
|
|
555
|
-
"developer-token": developerToken,
|
|
556
|
-
...customerId ? { "login-customer-id": customerId } : {}
|
|
557
|
-
},
|
|
558
|
-
...method === "POST" && body ? { body: JSON.stringify(body) } : {}
|
|
559
|
-
}),
|
|
560
|
-
signal: controller.signal
|
|
561
|
-
});
|
|
562
|
-
const data = await response.json();
|
|
563
|
-
if (!response.ok) {
|
|
564
|
-
const dataObj = data;
|
|
565
|
-
const errorMessage = typeof dataObj?.error === "string" ? dataObj.error : typeof dataObj?.message === "string" ? dataObj.message : `HTTP ${response.status} ${response.statusText}`;
|
|
566
|
-
return { success: false, error: errorMessage };
|
|
567
|
-
}
|
|
568
|
-
return { success: true, status: response.status, data };
|
|
569
|
-
} finally {
|
|
570
|
-
clearTimeout(timeout);
|
|
571
|
-
}
|
|
572
|
-
} catch (err) {
|
|
573
|
-
const msg = err instanceof Error ? err.message : String(err);
|
|
574
|
-
return { success: false, error: msg };
|
|
575
|
-
}
|
|
576
|
-
}
|
|
577
|
-
});
|
|
578
|
-
|
|
579
|
-
// ../connectors/src/connectors/google-ads-oauth/index.ts
|
|
580
|
-
var tools = {
|
|
581
|
-
request: requestTool,
|
|
582
|
-
listCustomers: listCustomersTool
|
|
583
|
-
};
|
|
584
|
-
var googleAdsOauthConnector = new ConnectorPlugin({
|
|
585
|
-
slug: "google-ads",
|
|
586
|
-
authType: AUTH_TYPES.OAUTH,
|
|
587
|
-
name: "Google Ads",
|
|
588
|
-
description: "Connect to Google Ads for advertising campaign data and reporting using OAuth.",
|
|
589
|
-
iconUrl: "https://images.ctfassets.net/9ncizv60xc5y/1NGvmgvCxX7Tn11EST2N3N/a745fe7c63d360ed40a27ddaad3af168/google-ads.svg",
|
|
590
|
-
parameters,
|
|
591
|
-
releaseFlag: { dev1: true, dev2: false, prod: false },
|
|
592
|
-
onboarding: googleAdsOnboarding,
|
|
593
|
-
proxyPolicy: {
|
|
594
|
-
allowlist: [
|
|
595
|
-
{
|
|
596
|
-
host: "googleads.googleapis.com",
|
|
597
|
-
methods: ["GET", "POST"]
|
|
598
|
-
}
|
|
599
|
-
]
|
|
600
|
-
},
|
|
601
|
-
systemPrompt: {
|
|
602
|
-
en: `### Tools
|
|
603
|
-
|
|
604
|
-
- \`google-ads-oauth_request\`: Send authenticated requests to the Google Ads API. Use it for GAQL queries via searchStream. The {customerId} placeholder in paths is automatically replaced (hyphens removed). Authentication and developer token are configured automatically.
|
|
605
|
-
- \`google-ads-oauth_listCustomers\`: List accessible Google Ads customer accounts. Use this during setup to discover available accounts.
|
|
606
|
-
|
|
607
|
-
### Google Ads API Reference
|
|
608
|
-
|
|
609
|
-
#### Query Data (searchStream)
|
|
610
|
-
- POST customers/{customerId}/googleAds:searchStream
|
|
611
|
-
- Body: { "query": "SELECT campaign.id, campaign.name, metrics.impressions FROM campaign WHERE segments.date DURING LAST_30_DAYS" }
|
|
612
|
-
|
|
613
|
-
### Common GAQL Resources
|
|
614
|
-
- \`campaign\`: Campaign data (campaign.id, campaign.name, campaign.status)
|
|
615
|
-
- \`ad_group\`: Ad group data (ad_group.id, ad_group.name, ad_group.status)
|
|
616
|
-
- \`ad_group_ad\`: Ad data (ad_group_ad.ad.id, ad_group_ad.status)
|
|
617
|
-
- \`keyword_view\`: Keyword performance data
|
|
618
|
-
|
|
619
|
-
### Common Metrics
|
|
620
|
-
metrics.impressions, metrics.clicks, metrics.cost_micros, metrics.conversions,
|
|
621
|
-
metrics.ctr, metrics.average_cpc, metrics.conversions_value
|
|
622
|
-
|
|
623
|
-
### Common Segments
|
|
624
|
-
segments.date, segments.device, segments.ad_network_type
|
|
625
|
-
|
|
626
|
-
### Date Filters
|
|
627
|
-
- \`DURING LAST_7_DAYS\`, \`DURING LAST_30_DAYS\`, \`DURING THIS_MONTH\`
|
|
628
|
-
- \`WHERE segments.date BETWEEN '2024-01-01' AND '2024-01-31'\`
|
|
629
|
-
|
|
630
|
-
### Tips
|
|
631
|
-
- cost_micros is in micros (divide by 1,000,000 for actual currency)
|
|
632
|
-
- Use LIMIT to restrict result count
|
|
633
|
-
- Always include relevant WHERE clauses to filter data
|
|
634
|
-
|
|
635
|
-
### Business Logic
|
|
636
|
-
|
|
637
|
-
The business logic type for this connector is "typescript". Write handler code using the connector SDK shown below. Do NOT access credentials directly from environment variables.
|
|
638
|
-
|
|
639
|
-
#### Example
|
|
640
|
-
|
|
641
|
-
\`\`\`ts
|
|
642
|
-
import { connection } from "@squadbase/vite-server/connectors/google-ads-oauth";
|
|
643
|
-
|
|
644
|
-
const ads = connection("<connectionId>");
|
|
645
|
-
|
|
646
|
-
// Execute a GAQL query
|
|
647
|
-
const rows = await ads.search(
|
|
648
|
-
"SELECT campaign.name, metrics.impressions, metrics.clicks FROM campaign WHERE segments.date DURING LAST_7_DAYS"
|
|
649
|
-
);
|
|
650
|
-
rows.forEach(row => console.log(row));
|
|
651
|
-
|
|
652
|
-
// List accessible customer accounts
|
|
653
|
-
const customerIds = await ads.listAccessibleCustomers();
|
|
654
|
-
\`\`\``,
|
|
655
|
-
ja: `### \u30C4\u30FC\u30EB
|
|
656
|
-
|
|
657
|
-
- \`google-ads-oauth_request\`: Google Ads API\u3078\u8A8D\u8A3C\u6E08\u307F\u30EA\u30AF\u30A8\u30B9\u30C8\u3092\u9001\u4FE1\u3057\u307E\u3059\u3002searchStream\u3092\u4F7F\u3063\u305FGAQL\u30AF\u30A8\u30EA\u306B\u4F7F\u7528\u3057\u307E\u3059\u3002\u30D1\u30B9\u5185\u306E{customerId}\u30D7\u30EC\u30FC\u30B9\u30DB\u30EB\u30C0\u30FC\u306F\u81EA\u52D5\u7684\u306B\u7F6E\u63DB\u3055\u308C\u307E\u3059\uFF08\u30CF\u30A4\u30D5\u30F3\u306F\u9664\u53BB\uFF09\u3002\u8A8D\u8A3C\u3068\u30C7\u30D9\u30ED\u30C3\u30D1\u30FC\u30C8\u30FC\u30AF\u30F3\u306F\u81EA\u52D5\u8A2D\u5B9A\u3055\u308C\u307E\u3059\u3002
|
|
658
|
-
- \`google-ads-oauth_listCustomers\`: \u30A2\u30AF\u30BB\u30B9\u53EF\u80FD\u306AGoogle Ads\u9867\u5BA2\u30A2\u30AB\u30A6\u30F3\u30C8\u306E\u4E00\u89A7\u3092\u53D6\u5F97\u3057\u307E\u3059\u3002\u30BB\u30C3\u30C8\u30A2\u30C3\u30D7\u6642\u306B\u5229\u7528\u53EF\u80FD\u306A\u30A2\u30AB\u30A6\u30F3\u30C8\u3092\u78BA\u8A8D\u3059\u308B\u305F\u3081\u306B\u4F7F\u7528\u3057\u307E\u3059\u3002
|
|
659
|
-
|
|
660
|
-
### Google Ads API \u30EA\u30D5\u30A1\u30EC\u30F3\u30B9
|
|
661
|
-
|
|
662
|
-
#### \u30C7\u30FC\u30BF\u306E\u30AF\u30A8\u30EA (searchStream)
|
|
663
|
-
- POST customers/{customerId}/googleAds:searchStream
|
|
664
|
-
- Body: { "query": "SELECT campaign.id, campaign.name, metrics.impressions FROM campaign WHERE segments.date DURING LAST_30_DAYS" }
|
|
665
|
-
|
|
666
|
-
### \u4E3B\u8981\u306AGAQL\u30EA\u30BD\u30FC\u30B9
|
|
667
|
-
- \`campaign\`: \u30AD\u30E3\u30F3\u30DA\u30FC\u30F3\u30C7\u30FC\u30BF (campaign.id, campaign.name, campaign.status)
|
|
668
|
-
- \`ad_group\`: \u5E83\u544A\u30B0\u30EB\u30FC\u30D7\u30C7\u30FC\u30BF (ad_group.id, ad_group.name, ad_group.status)
|
|
669
|
-
- \`ad_group_ad\`: \u5E83\u544A\u30C7\u30FC\u30BF (ad_group_ad.ad.id, ad_group_ad.status)
|
|
670
|
-
- \`keyword_view\`: \u30AD\u30FC\u30EF\u30FC\u30C9\u30D1\u30D5\u30A9\u30FC\u30DE\u30F3\u30B9\u30C7\u30FC\u30BF
|
|
671
|
-
|
|
672
|
-
### \u4E3B\u8981\u306A\u30E1\u30C8\u30EA\u30AF\u30B9
|
|
673
|
-
metrics.impressions, metrics.clicks, metrics.cost_micros, metrics.conversions,
|
|
674
|
-
metrics.ctr, metrics.average_cpc, metrics.conversions_value
|
|
675
|
-
|
|
676
|
-
### \u4E3B\u8981\u306A\u30BB\u30B0\u30E1\u30F3\u30C8
|
|
677
|
-
segments.date, segments.device, segments.ad_network_type
|
|
678
|
-
|
|
679
|
-
### \u65E5\u4ED8\u30D5\u30A3\u30EB\u30BF
|
|
680
|
-
- \`DURING LAST_7_DAYS\`, \`DURING LAST_30_DAYS\`, \`DURING THIS_MONTH\`
|
|
681
|
-
- \`WHERE segments.date BETWEEN '2024-01-01' AND '2024-01-31'\`
|
|
682
|
-
|
|
683
|
-
### \u30D2\u30F3\u30C8
|
|
684
|
-
- cost_micros \u306F\u30DE\u30A4\u30AF\u30ED\u5358\u4F4D\u3067\u3059\uFF08\u5B9F\u969B\u306E\u901A\u8CA8\u984D\u306B\u3059\u308B\u306B\u306F1,000,000\u3067\u5272\u308A\u307E\u3059\uFF09
|
|
685
|
-
- LIMIT \u3092\u4F7F\u7528\u3057\u3066\u7D50\u679C\u6570\u3092\u5236\u9650\u3057\u307E\u3059
|
|
686
|
-
- \u30C7\u30FC\u30BF\u3092\u30D5\u30A3\u30EB\u30BF\u3059\u308B\u305F\u3081\u306B\u5E38\u306B\u9069\u5207\u306AWHERE\u53E5\u3092\u542B\u3081\u3066\u304F\u3060\u3055\u3044
|
|
687
|
-
|
|
688
|
-
### Business Logic
|
|
689
|
-
|
|
690
|
-
\u3053\u306E\u30B3\u30CD\u30AF\u30BF\u306E\u30D3\u30B8\u30CD\u30B9\u30ED\u30B8\u30C3\u30AF\u30BF\u30A4\u30D7\u306F "typescript" \u3067\u3059\u3002\u4EE5\u4E0B\u306B\u793A\u3059\u30B3\u30CD\u30AF\u30BFSDK\u3092\u4F7F\u7528\u3057\u3066\u30CF\u30F3\u30C9\u30E9\u30B3\u30FC\u30C9\u3092\u8A18\u8FF0\u3057\u3066\u304F\u3060\u3055\u3044\u3002\u74B0\u5883\u5909\u6570\u304B\u3089\u76F4\u63A5\u8A8D\u8A3C\u60C5\u5831\u306B\u30A2\u30AF\u30BB\u30B9\u3057\u306A\u3044\u3067\u304F\u3060\u3055\u3044\u3002
|
|
691
|
-
|
|
692
|
-
#### Example
|
|
693
|
-
|
|
694
|
-
\`\`\`ts
|
|
695
|
-
import { connection } from "@squadbase/vite-server/connectors/google-ads-oauth";
|
|
696
|
-
|
|
697
|
-
const ads = connection("<connectionId>");
|
|
698
|
-
|
|
699
|
-
// Execute a GAQL query
|
|
700
|
-
const rows = await ads.search(
|
|
701
|
-
"SELECT campaign.name, metrics.impressions, metrics.clicks FROM campaign WHERE segments.date DURING LAST_7_DAYS"
|
|
702
|
-
);
|
|
703
|
-
rows.forEach(row => console.log(row));
|
|
704
|
-
|
|
705
|
-
// List accessible customer accounts
|
|
706
|
-
const customerIds = await ads.listAccessibleCustomers();
|
|
707
|
-
\`\`\``
|
|
708
|
-
},
|
|
709
|
-
tools,
|
|
710
|
-
async checkConnection(params, config) {
|
|
711
|
-
const { proxyFetch } = config;
|
|
712
|
-
const rawCustomerId = params[parameters.customerId.slug];
|
|
713
|
-
const customerId = rawCustomerId?.replace(/-/g, "");
|
|
714
|
-
if (!customerId) {
|
|
715
|
-
return { success: true };
|
|
716
|
-
}
|
|
717
|
-
const developerToken = params[parameters.developerToken.slug];
|
|
718
|
-
if (!developerToken) {
|
|
719
|
-
return {
|
|
720
|
-
success: false,
|
|
721
|
-
error: "Developer token is required"
|
|
722
|
-
};
|
|
723
|
-
}
|
|
724
|
-
const url = `https://googleads.googleapis.com/v18/customers/${customerId}/googleAds:searchStream`;
|
|
725
|
-
try {
|
|
726
|
-
const res = await proxyFetch(url, {
|
|
727
|
-
method: "POST",
|
|
728
|
-
headers: {
|
|
729
|
-
"Content-Type": "application/json",
|
|
730
|
-
"developer-token": developerToken,
|
|
731
|
-
"login-customer-id": customerId
|
|
732
|
-
},
|
|
733
|
-
body: JSON.stringify({
|
|
734
|
-
query: "SELECT customer.id FROM customer LIMIT 1"
|
|
735
|
-
})
|
|
736
|
-
});
|
|
737
|
-
if (!res.ok) {
|
|
738
|
-
const errorText = await res.text().catch(() => res.statusText);
|
|
739
|
-
return {
|
|
740
|
-
success: false,
|
|
741
|
-
error: `Google Ads API failed: HTTP ${res.status} ${errorText}`
|
|
742
|
-
};
|
|
743
|
-
}
|
|
744
|
-
return { success: true };
|
|
745
|
-
} catch (error) {
|
|
746
|
-
return {
|
|
747
|
-
success: false,
|
|
748
|
-
error: error instanceof Error ? error.message : String(error)
|
|
749
|
-
};
|
|
750
|
-
}
|
|
751
|
-
}
|
|
752
|
-
});
|
|
753
|
-
|
|
754
|
-
// src/connectors/create-connector-sdk.ts
|
|
755
|
-
import { readFileSync } from "fs";
|
|
756
|
-
import path from "path";
|
|
757
|
-
|
|
758
|
-
// src/connector-client/env.ts
|
|
759
|
-
function resolveEnvVar(entry, key, connectionId) {
|
|
760
|
-
const envVarName = entry.envVars[key];
|
|
761
|
-
if (!envVarName) {
|
|
762
|
-
throw new Error(`Connection "${connectionId}" is missing envVars mapping for key "${key}"`);
|
|
763
|
-
}
|
|
764
|
-
const value = process.env[envVarName];
|
|
765
|
-
if (!value) {
|
|
766
|
-
throw new Error(`Environment variable "${envVarName}" (for connection "${connectionId}", key "${key}") is not set`);
|
|
767
|
-
}
|
|
768
|
-
return value;
|
|
769
|
-
}
|
|
770
|
-
function resolveEnvVarOptional(entry, key) {
|
|
771
|
-
const envVarName = entry.envVars[key];
|
|
772
|
-
if (!envVarName) return void 0;
|
|
773
|
-
return process.env[envVarName] || void 0;
|
|
774
|
-
}
|
|
775
|
-
|
|
776
|
-
// src/connector-client/proxy-fetch.ts
|
|
777
|
-
import { getContext } from "hono/context-storage";
|
|
778
|
-
import { getCookie } from "hono/cookie";
|
|
779
|
-
var APP_SESSION_COOKIE_NAME = "__Host-squadbase-session";
|
|
780
|
-
function createSandboxProxyFetch(connectionId) {
|
|
781
|
-
return async (input, init) => {
|
|
782
|
-
const token = process.env.INTERNAL_SQUADBASE_OAUTH_MACHINE_CREDENTIAL;
|
|
783
|
-
const sandboxId = process.env.INTERNAL_SQUADBASE_SANDBOX_ID;
|
|
784
|
-
if (!token || !sandboxId) {
|
|
785
|
-
throw new Error(
|
|
786
|
-
"Connection proxy is not configured. Please check your deployment settings."
|
|
787
|
-
);
|
|
788
|
-
}
|
|
789
|
-
const originalUrl = typeof input === "string" ? input : input instanceof URL ? input.href : input.url;
|
|
790
|
-
const originalMethod = init?.method ?? "GET";
|
|
791
|
-
const originalBody = init?.body ? JSON.parse(init.body) : void 0;
|
|
792
|
-
const baseDomain = process.env["SQUADBASE_PREVIEW_BASE_DOMAIN"] ?? "preview.app.squadbase.dev";
|
|
793
|
-
const proxyUrl = `https://${sandboxId}.${baseDomain}/_sqcore/connections/${connectionId}/request`;
|
|
794
|
-
return fetch(proxyUrl, {
|
|
795
|
-
method: "POST",
|
|
796
|
-
headers: {
|
|
797
|
-
"Content-Type": "application/json",
|
|
798
|
-
Authorization: `Bearer ${token}`
|
|
799
|
-
},
|
|
800
|
-
body: JSON.stringify({
|
|
801
|
-
url: originalUrl,
|
|
802
|
-
method: originalMethod,
|
|
803
|
-
body: originalBody
|
|
804
|
-
})
|
|
805
|
-
});
|
|
806
|
-
};
|
|
807
|
-
}
|
|
808
|
-
function createDeployedAppProxyFetch(connectionId) {
|
|
809
|
-
const projectId = process.env["SQUADBASE_PROJECT_ID"];
|
|
810
|
-
if (!projectId) {
|
|
811
|
-
throw new Error(
|
|
812
|
-
"Connection proxy is not configured. Please check your deployment settings."
|
|
813
|
-
);
|
|
814
|
-
}
|
|
815
|
-
const baseDomain = process.env["SQUADBASE_APP_BASE_DOMAIN"] ?? "squadbase.app";
|
|
816
|
-
const proxyUrl = `https://${projectId}.${baseDomain}/_sqcore/connections/${connectionId}/request`;
|
|
817
|
-
return async (input, init) => {
|
|
818
|
-
const originalUrl = typeof input === "string" ? input : input instanceof URL ? input.href : input.url;
|
|
819
|
-
const originalMethod = init?.method ?? "GET";
|
|
820
|
-
const originalBody = init?.body ? JSON.parse(init.body) : void 0;
|
|
821
|
-
const c = getContext();
|
|
822
|
-
const appSession = getCookie(c, APP_SESSION_COOKIE_NAME);
|
|
823
|
-
if (!appSession) {
|
|
824
|
-
throw new Error(
|
|
825
|
-
"No authentication method available for connection proxy."
|
|
826
|
-
);
|
|
827
|
-
}
|
|
828
|
-
return fetch(proxyUrl, {
|
|
829
|
-
method: "POST",
|
|
830
|
-
headers: {
|
|
831
|
-
"Content-Type": "application/json",
|
|
832
|
-
Authorization: `Bearer ${appSession}`
|
|
833
|
-
},
|
|
834
|
-
body: JSON.stringify({
|
|
835
|
-
url: originalUrl,
|
|
836
|
-
method: originalMethod,
|
|
837
|
-
body: originalBody
|
|
838
|
-
})
|
|
839
|
-
});
|
|
840
|
-
};
|
|
841
|
-
}
|
|
842
|
-
function createProxyFetch(connectionId) {
|
|
843
|
-
if (process.env.INTERNAL_SQUADBASE_SANDBOX_ID) {
|
|
844
|
-
return createSandboxProxyFetch(connectionId);
|
|
845
|
-
}
|
|
846
|
-
return createDeployedAppProxyFetch(connectionId);
|
|
847
|
-
}
|
|
848
|
-
|
|
849
|
-
// src/connectors/create-connector-sdk.ts
|
|
850
|
-
function loadConnectionsSync() {
|
|
851
|
-
const filePath = process.env.CONNECTIONS_PATH ?? path.join(process.cwd(), ".squadbase/connections.json");
|
|
852
|
-
try {
|
|
853
|
-
const raw = readFileSync(filePath, "utf-8");
|
|
854
|
-
return JSON.parse(raw);
|
|
855
|
-
} catch {
|
|
856
|
-
return {};
|
|
857
|
-
}
|
|
858
|
-
}
|
|
859
|
-
function createConnectorSdk(plugin, createClient2) {
|
|
860
|
-
return (connectionId) => {
|
|
861
|
-
const connections = loadConnectionsSync();
|
|
862
|
-
const entry = connections[connectionId];
|
|
863
|
-
if (!entry) {
|
|
864
|
-
throw new Error(
|
|
865
|
-
`Connection "${connectionId}" not found in .squadbase/connections.json`
|
|
866
|
-
);
|
|
867
|
-
}
|
|
868
|
-
if (entry.connector.slug !== plugin.slug) {
|
|
869
|
-
throw new Error(
|
|
870
|
-
`Connection "${connectionId}" is not a ${plugin.slug} connection (got "${entry.connector.slug}")`
|
|
871
|
-
);
|
|
872
|
-
}
|
|
873
|
-
const params = {};
|
|
874
|
-
for (const param of Object.values(plugin.parameters)) {
|
|
875
|
-
if (param.required) {
|
|
876
|
-
params[param.slug] = resolveEnvVar(entry, param.slug, connectionId);
|
|
877
|
-
} else {
|
|
878
|
-
const val = resolveEnvVarOptional(entry, param.slug);
|
|
879
|
-
if (val !== void 0) params[param.slug] = val;
|
|
880
|
-
}
|
|
881
|
-
}
|
|
882
|
-
return createClient2(params, createProxyFetch(connectionId));
|
|
883
|
-
};
|
|
884
|
-
}
|
|
885
|
-
|
|
886
|
-
// src/connectors/entries/google-ads-oauth.ts
|
|
887
|
-
var connection = createConnectorSdk(googleAdsOauthConnector, createClient);
|
|
888
|
-
export {
|
|
889
|
-
connection
|
|
890
|
-
};
|