@squadbase/vite-server 0.1.3-dev.0 → 0.1.3-dev.1
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 +13282 -4299
- package/dist/connectors/asana.d.ts +5 -0
- package/dist/connectors/asana.js +661 -0
- package/dist/connectors/customerio.d.ts +5 -0
- package/dist/connectors/customerio.js +633 -0
- package/dist/connectors/gmail-oauth.d.ts +5 -0
- package/dist/connectors/gmail-oauth.js +639 -0
- package/dist/connectors/google-ads.d.ts +5 -0
- package/dist/connectors/google-ads.js +784 -0
- package/dist/connectors/google-sheets.d.ts +5 -0
- package/dist/connectors/google-sheets.js +598 -0
- package/dist/connectors/hubspot.js +14 -5
- package/dist/connectors/intercom-oauth.d.ts +5 -0
- package/dist/connectors/intercom-oauth.js +510 -0
- package/dist/connectors/intercom.d.ts +5 -0
- package/dist/connectors/intercom.js +627 -0
- package/dist/connectors/jira-api-key.d.ts +5 -0
- package/dist/connectors/jira-api-key.js +523 -0
- package/dist/connectors/linkedin-ads-oauth.d.ts +5 -0
- package/dist/connectors/linkedin-ads-oauth.js +774 -0
- package/dist/connectors/linkedin-ads.d.ts +5 -0
- package/dist/connectors/linkedin-ads.js +782 -0
- package/dist/connectors/mailchimp-oauth.d.ts +5 -0
- package/dist/connectors/mailchimp-oauth.js +539 -0
- package/dist/connectors/mailchimp.d.ts +5 -0
- package/dist/connectors/mailchimp.js +646 -0
- package/dist/connectors/zendesk-oauth.d.ts +5 -0
- package/dist/connectors/zendesk-oauth.js +505 -0
- package/dist/connectors/zendesk.d.ts +5 -0
- package/dist/connectors/zendesk.js +631 -0
- package/dist/index.js +13238 -4255
- package/dist/main.js +13240 -4257
- package/dist/vite-plugin.js +13240 -4257
- package/package.json +42 -2
|
@@ -0,0 +1,774 @@
|
|
|
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/linkedin-ads-oauth/sdk/index.ts
|
|
46
|
+
var BASE_URL = "https://api.linkedin.com/rest/";
|
|
47
|
+
function createClient(_params, fetchFn = fetch) {
|
|
48
|
+
function request(path2, init) {
|
|
49
|
+
const url = `${BASE_URL}${path2}`;
|
|
50
|
+
return fetchFn(url, init);
|
|
51
|
+
}
|
|
52
|
+
return { request };
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// ../connectors/src/connector-onboarding.ts
|
|
56
|
+
var ConnectorOnboarding = class {
|
|
57
|
+
/** Phase 1: Connection setup instructions (optional — some connectors don't need this) */
|
|
58
|
+
connectionSetupInstructions;
|
|
59
|
+
/** Phase 2: Data overview instructions */
|
|
60
|
+
dataOverviewInstructions;
|
|
61
|
+
constructor(config) {
|
|
62
|
+
this.connectionSetupInstructions = config.connectionSetupInstructions;
|
|
63
|
+
this.dataOverviewInstructions = config.dataOverviewInstructions;
|
|
64
|
+
}
|
|
65
|
+
getConnectionSetupPrompt(language) {
|
|
66
|
+
return this.connectionSetupInstructions?.[language] ?? null;
|
|
67
|
+
}
|
|
68
|
+
getDataOverviewInstructions(language) {
|
|
69
|
+
return this.dataOverviewInstructions[language];
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
// ../connectors/src/connector-tool.ts
|
|
74
|
+
var ConnectorTool = class {
|
|
75
|
+
name;
|
|
76
|
+
description;
|
|
77
|
+
inputSchema;
|
|
78
|
+
outputSchema;
|
|
79
|
+
_execute;
|
|
80
|
+
constructor(config) {
|
|
81
|
+
this.name = config.name;
|
|
82
|
+
this.description = config.description;
|
|
83
|
+
this.inputSchema = config.inputSchema;
|
|
84
|
+
this.outputSchema = config.outputSchema;
|
|
85
|
+
this._execute = config.execute;
|
|
86
|
+
}
|
|
87
|
+
createTool(connections, config) {
|
|
88
|
+
return {
|
|
89
|
+
description: this.description,
|
|
90
|
+
inputSchema: this.inputSchema,
|
|
91
|
+
outputSchema: this.outputSchema,
|
|
92
|
+
execute: (input) => this._execute(input, connections, config)
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
// ../connectors/src/connector-plugin.ts
|
|
98
|
+
var ConnectorPlugin = class _ConnectorPlugin {
|
|
99
|
+
slug;
|
|
100
|
+
authType;
|
|
101
|
+
name;
|
|
102
|
+
description;
|
|
103
|
+
iconUrl;
|
|
104
|
+
parameters;
|
|
105
|
+
releaseFlag;
|
|
106
|
+
proxyPolicy;
|
|
107
|
+
experimentalAttributes;
|
|
108
|
+
onboarding;
|
|
109
|
+
systemPrompt;
|
|
110
|
+
tools;
|
|
111
|
+
query;
|
|
112
|
+
checkConnection;
|
|
113
|
+
constructor(config) {
|
|
114
|
+
this.slug = config.slug;
|
|
115
|
+
this.authType = config.authType;
|
|
116
|
+
this.name = config.name;
|
|
117
|
+
this.description = config.description;
|
|
118
|
+
this.iconUrl = config.iconUrl;
|
|
119
|
+
this.parameters = config.parameters;
|
|
120
|
+
this.releaseFlag = config.releaseFlag;
|
|
121
|
+
this.proxyPolicy = config.proxyPolicy;
|
|
122
|
+
this.experimentalAttributes = config.experimentalAttributes;
|
|
123
|
+
this.onboarding = config.onboarding;
|
|
124
|
+
this.systemPrompt = config.systemPrompt;
|
|
125
|
+
this.tools = config.tools;
|
|
126
|
+
this.query = config.query;
|
|
127
|
+
this.checkConnection = config.checkConnection;
|
|
128
|
+
}
|
|
129
|
+
get connectorKey() {
|
|
130
|
+
return _ConnectorPlugin.deriveKey(this.slug, this.authType);
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Create tools for connections that belong to this connector.
|
|
134
|
+
* Filters connections by connectorKey internally.
|
|
135
|
+
* Returns tools keyed as `${connectorKey}_${toolName}`.
|
|
136
|
+
*/
|
|
137
|
+
createTools(connections, config) {
|
|
138
|
+
const myConnections = connections.filter(
|
|
139
|
+
(c) => _ConnectorPlugin.deriveKey(c.connector.slug, c.connector.authType) === this.connectorKey
|
|
140
|
+
);
|
|
141
|
+
const result = {};
|
|
142
|
+
for (const t of Object.values(this.tools)) {
|
|
143
|
+
result[`${this.connectorKey}_${t.name}`] = t.createTool(
|
|
144
|
+
myConnections,
|
|
145
|
+
config
|
|
146
|
+
);
|
|
147
|
+
}
|
|
148
|
+
return result;
|
|
149
|
+
}
|
|
150
|
+
static deriveKey(slug, authType) {
|
|
151
|
+
return authType ? `${slug}-${authType}` : slug;
|
|
152
|
+
}
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
// ../connectors/src/auth-types.ts
|
|
156
|
+
var AUTH_TYPES = {
|
|
157
|
+
OAUTH: "oauth",
|
|
158
|
+
API_KEY: "api-key",
|
|
159
|
+
JWT: "jwt",
|
|
160
|
+
SERVICE_ACCOUNT: "service-account",
|
|
161
|
+
PAT: "pat"
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
// ../connectors/src/connectors/linkedin-ads-oauth/tools/list-ad-accounts.ts
|
|
165
|
+
import { z } from "zod";
|
|
166
|
+
var BASE_URL2 = "https://api.linkedin.com/rest/";
|
|
167
|
+
var LINKEDIN_VERSION = "202603";
|
|
168
|
+
var REQUEST_TIMEOUT_MS = 6e4;
|
|
169
|
+
var cachedToken = null;
|
|
170
|
+
async function getProxyToken(config) {
|
|
171
|
+
if (cachedToken && cachedToken.expiresAt > Date.now() + 6e4) {
|
|
172
|
+
return cachedToken.token;
|
|
173
|
+
}
|
|
174
|
+
const url = `${config.appApiBaseUrl}/v0/database/${config.projectId}/environment/${config.environmentId}/oauth-request-proxy-token`;
|
|
175
|
+
const res = await fetch(url, {
|
|
176
|
+
method: "POST",
|
|
177
|
+
headers: {
|
|
178
|
+
"Content-Type": "application/json",
|
|
179
|
+
"x-api-key": config.appApiKey,
|
|
180
|
+
"project-id": config.projectId
|
|
181
|
+
},
|
|
182
|
+
body: JSON.stringify({
|
|
183
|
+
sandboxId: config.sandboxId,
|
|
184
|
+
issuedBy: "coding-agent"
|
|
185
|
+
})
|
|
186
|
+
});
|
|
187
|
+
if (!res.ok) {
|
|
188
|
+
const errorText = await res.text().catch(() => res.statusText);
|
|
189
|
+
throw new Error(
|
|
190
|
+
`Failed to get proxy token: HTTP ${res.status} ${errorText}`
|
|
191
|
+
);
|
|
192
|
+
}
|
|
193
|
+
const data = await res.json();
|
|
194
|
+
cachedToken = {
|
|
195
|
+
token: data.token,
|
|
196
|
+
expiresAt: new Date(data.expiresAt).getTime()
|
|
197
|
+
};
|
|
198
|
+
return data.token;
|
|
199
|
+
}
|
|
200
|
+
var inputSchema = z.object({
|
|
201
|
+
toolUseIntent: z.string().optional().describe(
|
|
202
|
+
"Brief description of what you intend to accomplish with this tool call"
|
|
203
|
+
),
|
|
204
|
+
connectionId: z.string().describe("ID of the LinkedIn Ads OAuth connection to use")
|
|
205
|
+
});
|
|
206
|
+
var outputSchema = z.discriminatedUnion("success", [
|
|
207
|
+
z.object({
|
|
208
|
+
success: z.literal(true),
|
|
209
|
+
adAccounts: z.array(
|
|
210
|
+
z.object({
|
|
211
|
+
adAccountId: z.string(),
|
|
212
|
+
name: z.string()
|
|
213
|
+
})
|
|
214
|
+
)
|
|
215
|
+
}),
|
|
216
|
+
z.object({
|
|
217
|
+
success: z.literal(false),
|
|
218
|
+
error: z.string()
|
|
219
|
+
})
|
|
220
|
+
]);
|
|
221
|
+
var listAdAccountsTool = new ConnectorTool({
|
|
222
|
+
name: "listAdAccounts",
|
|
223
|
+
description: "List LinkedIn ad accounts accessible with the current OAuth credentials.",
|
|
224
|
+
inputSchema,
|
|
225
|
+
outputSchema,
|
|
226
|
+
async execute({ connectionId }, connections, config) {
|
|
227
|
+
const connection2 = connections.find((c) => c.id === connectionId);
|
|
228
|
+
if (!connection2) {
|
|
229
|
+
return {
|
|
230
|
+
success: false,
|
|
231
|
+
error: `Connection ${connectionId} not found`
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
console.log(
|
|
235
|
+
`[connector-request] linkedin-ads-oauth/${connection2.name}: listAdAccounts`
|
|
236
|
+
);
|
|
237
|
+
try {
|
|
238
|
+
const token = await getProxyToken(config.oauthProxy);
|
|
239
|
+
const proxyUrl = `https://${config.oauthProxy.sandboxId}.${config.oauthProxy.previewBaseDomain}/_sqcore/connections/${connectionId}/request`;
|
|
240
|
+
const controller = new AbortController();
|
|
241
|
+
const timeout = setTimeout(() => controller.abort(), REQUEST_TIMEOUT_MS);
|
|
242
|
+
try {
|
|
243
|
+
const response = await fetch(proxyUrl, {
|
|
244
|
+
method: "POST",
|
|
245
|
+
headers: {
|
|
246
|
+
"Content-Type": "application/json",
|
|
247
|
+
Authorization: `Bearer ${token}`
|
|
248
|
+
},
|
|
249
|
+
body: JSON.stringify({
|
|
250
|
+
url: `${BASE_URL2}adAccounts?q=search&search=(status:(values:List(ACTIVE)))&pageSize=100`,
|
|
251
|
+
method: "GET",
|
|
252
|
+
headers: {
|
|
253
|
+
"LinkedIn-Version": LINKEDIN_VERSION,
|
|
254
|
+
"X-Restli-Protocol-Version": "2.0.0"
|
|
255
|
+
}
|
|
256
|
+
}),
|
|
257
|
+
signal: controller.signal
|
|
258
|
+
});
|
|
259
|
+
const data = await response.json();
|
|
260
|
+
if (!response.ok) {
|
|
261
|
+
const errorMessage = data?.message ?? `HTTP ${response.status} ${response.statusText}`;
|
|
262
|
+
return { success: false, error: errorMessage };
|
|
263
|
+
}
|
|
264
|
+
const adAccounts = (data.elements ?? []).map((account) => ({
|
|
265
|
+
adAccountId: String(account.id ?? ""),
|
|
266
|
+
name: account.name ?? String(account.id ?? "")
|
|
267
|
+
}));
|
|
268
|
+
return { success: true, adAccounts };
|
|
269
|
+
} finally {
|
|
270
|
+
clearTimeout(timeout);
|
|
271
|
+
}
|
|
272
|
+
} catch (err) {
|
|
273
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
274
|
+
return { success: false, error: msg };
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
});
|
|
278
|
+
|
|
279
|
+
// ../connectors/src/connectors/linkedin-ads-oauth/setup.ts
|
|
280
|
+
var listAdAccountsToolName = `linkedin-ads-oauth_${listAdAccountsTool.name}`;
|
|
281
|
+
var linkedinAdsOauthOnboarding = new ConnectorOnboarding({
|
|
282
|
+
connectionSetupInstructions: {
|
|
283
|
+
ja: `\u4EE5\u4E0B\u306E\u624B\u9806\u3067LinkedIn\u5E83\u544A (OAuth) \u30B3\u30CD\u30AF\u30B7\u30E7\u30F3\u306E\u30BB\u30C3\u30C8\u30A2\u30C3\u30D7\u3092\u884C\u3063\u3066\u304F\u3060\u3055\u3044\u3002
|
|
284
|
+
|
|
285
|
+
1. \`${listAdAccountsToolName}\` \u3092\u547C\u3073\u51FA\u3057\u3066\u3001OAuth\u3067\u30A2\u30AF\u30BB\u30B9\u53EF\u80FD\u306A\u5E83\u544A\u30A2\u30AB\u30A6\u30F3\u30C8\u4E00\u89A7\u3092\u53D6\u5F97\u3059\u308B
|
|
286
|
+
2. \u30A8\u30E9\u30FC\u304C\u767A\u751F\u3057\u305F\u5834\u5408\u306F\u30E6\u30FC\u30B6\u30FC\u306BOAuth\u63A5\u7D9A\u306E\u78BA\u8A8D\u3092\u4F9D\u983C\u3059\u308B
|
|
287
|
+
3. \`updateConnectionParameters\` \u3092\u547C\u3073\u51FA\u3059:
|
|
288
|
+
- \`parameterSlug\`: \`"ad-account-id"\`
|
|
289
|
+
- \`options\`: \u5E83\u544A\u30A2\u30AB\u30A6\u30F3\u30C8\u4E00\u89A7\u3002\u5404 option \u306E \`label\` \u306F \`\u30A2\u30AB\u30A6\u30F3\u30C8\u540D (id: \u30A2\u30AB\u30A6\u30F3\u30C8ID)\` \u306E\u5F62\u5F0F\u3001\`value\` \u306F\u30A2\u30AB\u30A6\u30F3\u30C8ID
|
|
290
|
+
4. \u30E6\u30FC\u30B6\u30FC\u304C\u9078\u629E\u3057\u305F\u30A2\u30AB\u30A6\u30F3\u30C8\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
|
|
291
|
+
5. \`updateConnectionContext\` \u3092\u547C\u3073\u51FA\u3059:
|
|
292
|
+
- \`adAccount\`: \u9078\u629E\u3055\u308C\u305F\u30A2\u30AB\u30A6\u30F3\u30C8\u306E\u8868\u793A\u540D
|
|
293
|
+
- \`adAccountId\`: \u9078\u629E\u3055\u308C\u305F\u30A2\u30AB\u30A6\u30F3\u30C8ID
|
|
294
|
+
- \`note\`: \u30BB\u30C3\u30C8\u30A2\u30C3\u30D7\u5185\u5BB9\u306E\u7C21\u5358\u306A\u8AAC\u660E
|
|
295
|
+
|
|
296
|
+
#### \u5236\u7D04
|
|
297
|
+
- **\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
|
|
298
|
+
- \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`,
|
|
299
|
+
en: `Follow these steps to set up the LinkedIn Ads (OAuth) connection.
|
|
300
|
+
|
|
301
|
+
1. Call \`${listAdAccountsToolName}\` to get the list of ad accounts accessible with the OAuth credentials
|
|
302
|
+
2. If an error occurs, ask the user to verify their OAuth connection
|
|
303
|
+
3. Call \`updateConnectionParameters\`:
|
|
304
|
+
- \`parameterSlug\`: \`"ad-account-id"\`
|
|
305
|
+
- \`options\`: The ad account list. Each option's \`label\` should be \`Account Name (id: accountId)\`, \`value\` should be the account ID
|
|
306
|
+
4. The \`label\` of the user's selected account will arrive as a message. Proceed to the next step
|
|
307
|
+
5. Call \`updateConnectionContext\`:
|
|
308
|
+
- \`adAccount\`: The selected account's display name
|
|
309
|
+
- \`adAccountId\`: The selected account ID
|
|
310
|
+
- \`note\`: Brief description of the setup
|
|
311
|
+
|
|
312
|
+
#### Constraints
|
|
313
|
+
- **Do NOT fetch report data during setup**. Only the metadata requests specified in the steps above are allowed
|
|
314
|
+
- Write only 1 sentence between tool calls, then immediately call the next tool. Skip unnecessary explanations and proceed efficiently`
|
|
315
|
+
},
|
|
316
|
+
dataOverviewInstructions: {
|
|
317
|
+
en: `1. Call linkedin-ads-oauth_request with GET adAccounts/{adAccountId}/adCampaigns?q=search&search=(status:(values:List(ACTIVE)))&pageSize=10 to explore campaigns
|
|
318
|
+
2. Call linkedin-ads-oauth_request with GET adAnalytics?q=analytics&pivot=CAMPAIGN&timeGranularity=MONTHLY&dateRange=(start:(year:2025,month:1,day:1))&accounts=List(urn%3Ali%3AsponsoredAccount%3A{adAccountId})&fields=impressions,clicks,costInLocalCurrency,dateRange,pivotValues to check recent performance
|
|
319
|
+
3. Explore campaign groups and creatives as needed to understand the data structure`,
|
|
320
|
+
ja: `1. linkedin-ads-oauth_request \u3067 GET adAccounts/{adAccountId}/adCampaigns?q=search&search=(status:(values:List(ACTIVE)))&pageSize=10 \u3092\u547C\u3073\u51FA\u3057\u3066\u30AD\u30E3\u30F3\u30DA\u30FC\u30F3\u30C7\u30FC\u30BF\u3092\u63A2\u7D22
|
|
321
|
+
2. linkedin-ads-oauth_request \u3067 GET adAnalytics?q=analytics&pivot=CAMPAIGN&timeGranularity=MONTHLY&dateRange=(start:(year:2025,month:1,day:1))&accounts=List(urn%3Ali%3AsponsoredAccount%3A{adAccountId})&fields=impressions,clicks,costInLocalCurrency,dateRange,pivotValues \u3092\u547C\u3073\u51FA\u3057\u3066\u76F4\u8FD1\u306E\u30D1\u30D5\u30A9\u30FC\u30DE\u30F3\u30B9\u3092\u78BA\u8A8D
|
|
322
|
+
3. \u5FC5\u8981\u306B\u5FDC\u3058\u3066\u30AD\u30E3\u30F3\u30DA\u30FC\u30F3\u30B0\u30EB\u30FC\u30D7\u3084\u30AF\u30EA\u30A8\u30A4\u30C6\u30A3\u30D6\u3092\u63A2\u7D22\u3057\u3001\u30C7\u30FC\u30BF\u69CB\u9020\u3092\u628A\u63E1`
|
|
323
|
+
}
|
|
324
|
+
});
|
|
325
|
+
|
|
326
|
+
// ../connectors/src/connectors/linkedin-ads-oauth/parameters.ts
|
|
327
|
+
var parameters = {
|
|
328
|
+
adAccountId: new ParameterDefinition({
|
|
329
|
+
slug: "ad-account-id",
|
|
330
|
+
name: "Ad Account ID",
|
|
331
|
+
description: "The LinkedIn ad account ID (numeric). Found in Campaign Manager under Account Assets. The URN format urn:li:sponsoredAccount:{id} is constructed automatically.",
|
|
332
|
+
envVarBaseKey: "LINKEDIN_ADS_OAUTH_AD_ACCOUNT_ID",
|
|
333
|
+
type: "text",
|
|
334
|
+
secret: false,
|
|
335
|
+
required: false
|
|
336
|
+
})
|
|
337
|
+
};
|
|
338
|
+
|
|
339
|
+
// ../connectors/src/connectors/linkedin-ads-oauth/tools/request.ts
|
|
340
|
+
import { z as z2 } from "zod";
|
|
341
|
+
var BASE_URL3 = "https://api.linkedin.com/rest/";
|
|
342
|
+
var LINKEDIN_VERSION2 = "202603";
|
|
343
|
+
var REQUEST_TIMEOUT_MS2 = 6e4;
|
|
344
|
+
var cachedToken2 = null;
|
|
345
|
+
async function getProxyToken2(config) {
|
|
346
|
+
if (cachedToken2 && cachedToken2.expiresAt > Date.now() + 6e4) {
|
|
347
|
+
return cachedToken2.token;
|
|
348
|
+
}
|
|
349
|
+
const url = `${config.appApiBaseUrl}/v0/database/${config.projectId}/environment/${config.environmentId}/oauth-request-proxy-token`;
|
|
350
|
+
const res = await fetch(url, {
|
|
351
|
+
method: "POST",
|
|
352
|
+
headers: {
|
|
353
|
+
"Content-Type": "application/json",
|
|
354
|
+
"x-api-key": config.appApiKey,
|
|
355
|
+
"project-id": config.projectId
|
|
356
|
+
},
|
|
357
|
+
body: JSON.stringify({
|
|
358
|
+
sandboxId: config.sandboxId,
|
|
359
|
+
issuedBy: "coding-agent"
|
|
360
|
+
})
|
|
361
|
+
});
|
|
362
|
+
if (!res.ok) {
|
|
363
|
+
const errorText = await res.text().catch(() => res.statusText);
|
|
364
|
+
throw new Error(
|
|
365
|
+
`Failed to get proxy token: HTTP ${res.status} ${errorText}`
|
|
366
|
+
);
|
|
367
|
+
}
|
|
368
|
+
const data = await res.json();
|
|
369
|
+
cachedToken2 = {
|
|
370
|
+
token: data.token,
|
|
371
|
+
expiresAt: new Date(data.expiresAt).getTime()
|
|
372
|
+
};
|
|
373
|
+
return data.token;
|
|
374
|
+
}
|
|
375
|
+
var inputSchema2 = z2.object({
|
|
376
|
+
toolUseIntent: z2.string().optional().describe(
|
|
377
|
+
"Brief description of what you intend to accomplish with this tool call"
|
|
378
|
+
),
|
|
379
|
+
connectionId: z2.string().describe("ID of the LinkedIn Ads OAuth connection to use"),
|
|
380
|
+
method: z2.enum(["GET", "POST", "DELETE"]).describe("HTTP method"),
|
|
381
|
+
path: z2.string().describe(
|
|
382
|
+
"API path appended to https://api.linkedin.com/rest/ (e.g., 'adAccounts/{adAccountId}/adCampaigns'). {adAccountId} is automatically replaced with the connection's ad account ID."
|
|
383
|
+
),
|
|
384
|
+
queryParams: z2.record(z2.string(), z2.string()).optional().describe("Query parameters to append to the URL"),
|
|
385
|
+
body: z2.record(z2.string(), z2.unknown()).optional().describe("Request body (JSON). For partial updates, use the patch format: { patch: { $set: { ... } } }")
|
|
386
|
+
});
|
|
387
|
+
var outputSchema2 = z2.discriminatedUnion("success", [
|
|
388
|
+
z2.object({
|
|
389
|
+
success: z2.literal(true),
|
|
390
|
+
status: z2.number(),
|
|
391
|
+
data: z2.unknown()
|
|
392
|
+
}),
|
|
393
|
+
z2.object({
|
|
394
|
+
success: z2.literal(false),
|
|
395
|
+
error: z2.string()
|
|
396
|
+
})
|
|
397
|
+
]);
|
|
398
|
+
var requestTool = new ConnectorTool({
|
|
399
|
+
name: "request",
|
|
400
|
+
description: `Send authenticated requests to the LinkedIn Marketing API (REST).
|
|
401
|
+
Authentication is handled automatically via OAuth proxy.
|
|
402
|
+
{adAccountId} in the path is automatically replaced with the connection's ad account ID.
|
|
403
|
+
Required headers (LinkedIn-Version, X-Restli-Protocol-Version) are set automatically.`,
|
|
404
|
+
inputSchema: inputSchema2,
|
|
405
|
+
outputSchema: outputSchema2,
|
|
406
|
+
async execute({ connectionId, method, path: path2, queryParams, body }, connections, config) {
|
|
407
|
+
const connection2 = connections.find((c) => c.id === connectionId);
|
|
408
|
+
if (!connection2) {
|
|
409
|
+
return {
|
|
410
|
+
success: false,
|
|
411
|
+
error: `Connection ${connectionId} not found`
|
|
412
|
+
};
|
|
413
|
+
}
|
|
414
|
+
console.log(
|
|
415
|
+
`[connector-request] linkedin-ads-oauth/${connection2.name}: ${method} ${path2}`
|
|
416
|
+
);
|
|
417
|
+
try {
|
|
418
|
+
const adAccountId = parameters.adAccountId.tryGetValue(connection2) ?? "";
|
|
419
|
+
const resolvedPath = adAccountId ? path2.replace(/\{adAccountId\}/g, adAccountId) : path2;
|
|
420
|
+
let url = `${BASE_URL3}${resolvedPath}`;
|
|
421
|
+
if (queryParams && Object.keys(queryParams).length > 0) {
|
|
422
|
+
const params = new URLSearchParams(queryParams);
|
|
423
|
+
const separator = url.includes("?") ? "&" : "?";
|
|
424
|
+
url = `${url}${separator}${params.toString()}`;
|
|
425
|
+
}
|
|
426
|
+
const token = await getProxyToken2(config.oauthProxy);
|
|
427
|
+
const proxyUrl = `https://${config.oauthProxy.sandboxId}.${config.oauthProxy.previewBaseDomain}/_sqcore/connections/${connectionId}/request`;
|
|
428
|
+
const controller = new AbortController();
|
|
429
|
+
const timeout = setTimeout(() => controller.abort(), REQUEST_TIMEOUT_MS2);
|
|
430
|
+
try {
|
|
431
|
+
const additionalHeaders = {
|
|
432
|
+
"LinkedIn-Version": LINKEDIN_VERSION2,
|
|
433
|
+
"X-Restli-Protocol-Version": "2.0.0"
|
|
434
|
+
};
|
|
435
|
+
if (body && "patch" in body) {
|
|
436
|
+
additionalHeaders["X-RestLi-Method"] = "PARTIAL_UPDATE";
|
|
437
|
+
}
|
|
438
|
+
const response = await fetch(proxyUrl, {
|
|
439
|
+
method: "POST",
|
|
440
|
+
headers: {
|
|
441
|
+
"Content-Type": "application/json",
|
|
442
|
+
Authorization: `Bearer ${token}`
|
|
443
|
+
},
|
|
444
|
+
body: JSON.stringify({
|
|
445
|
+
url,
|
|
446
|
+
method,
|
|
447
|
+
headers: additionalHeaders,
|
|
448
|
+
...(method === "POST" || method === "DELETE") && body ? { body: JSON.stringify(body) } : {}
|
|
449
|
+
}),
|
|
450
|
+
signal: controller.signal
|
|
451
|
+
});
|
|
452
|
+
if (response.status === 204) {
|
|
453
|
+
return { success: true, status: 204, data: {} };
|
|
454
|
+
}
|
|
455
|
+
const data = await response.json();
|
|
456
|
+
if (!response.ok) {
|
|
457
|
+
const dataObj = data;
|
|
458
|
+
const errorMessage = typeof dataObj?.message === "string" ? dataObj.message : typeof dataObj?.error === "string" ? dataObj.error : `HTTP ${response.status} ${response.statusText}`;
|
|
459
|
+
return { success: false, error: errorMessage };
|
|
460
|
+
}
|
|
461
|
+
return { success: true, status: response.status, data };
|
|
462
|
+
} finally {
|
|
463
|
+
clearTimeout(timeout);
|
|
464
|
+
}
|
|
465
|
+
} catch (err) {
|
|
466
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
467
|
+
return { success: false, error: msg };
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
});
|
|
471
|
+
|
|
472
|
+
// ../connectors/src/connectors/linkedin-ads-oauth/index.ts
|
|
473
|
+
var tools = {
|
|
474
|
+
request: requestTool,
|
|
475
|
+
listAdAccounts: listAdAccountsTool
|
|
476
|
+
};
|
|
477
|
+
var linkedinAdsOauthConnector = new ConnectorPlugin({
|
|
478
|
+
slug: "linkedin-ads",
|
|
479
|
+
authType: AUTH_TYPES.OAUTH,
|
|
480
|
+
name: "LinkedIn Ads (OAuth)",
|
|
481
|
+
description: "Connect to LinkedIn Ads (Marketing API) for advertising campaign data and reporting using OAuth.",
|
|
482
|
+
iconUrl: "https://images.ctfassets.net/9ncizv60xc5y/1iC2kfONR1oFOqR9mISS08/2e5baeab83fe51067044d9df2d17df02/linkedin.svg",
|
|
483
|
+
parameters,
|
|
484
|
+
releaseFlag: { dev1: true, dev2: false, prod: false },
|
|
485
|
+
onboarding: linkedinAdsOauthOnboarding,
|
|
486
|
+
proxyPolicy: {
|
|
487
|
+
allowlist: [
|
|
488
|
+
{
|
|
489
|
+
host: "api.linkedin.com",
|
|
490
|
+
methods: ["GET", "POST", "DELETE"]
|
|
491
|
+
}
|
|
492
|
+
]
|
|
493
|
+
},
|
|
494
|
+
systemPrompt: {
|
|
495
|
+
en: `### Tools
|
|
496
|
+
|
|
497
|
+
- \`linkedin-ads-oauth_request\`: Send authenticated requests to the LinkedIn Marketing API (REST). The {adAccountId} placeholder in paths is automatically replaced. Authentication is handled automatically via OAuth proxy. Required headers (LinkedIn-Version, X-Restli-Protocol-Version) are set automatically.
|
|
498
|
+
- \`linkedin-ads-oauth_listAdAccounts\`: List accessible LinkedIn ad accounts. Use this during setup to discover available accounts.
|
|
499
|
+
|
|
500
|
+
### LinkedIn Marketing API Reference
|
|
501
|
+
|
|
502
|
+
Base URL: https://api.linkedin.com/rest/
|
|
503
|
+
API Version: 202603 (set automatically via LinkedIn-Version header)
|
|
504
|
+
|
|
505
|
+
#### Account Hierarchy
|
|
506
|
+
Ad Account (sponsoredAccount) > Campaign Group (sponsoredCampaignGroup) > Campaign (adCampaign) > Creative
|
|
507
|
+
|
|
508
|
+
#### Search Ad Accounts
|
|
509
|
+
- GET adAccounts?q=search&search=(status:(values:List(ACTIVE)))
|
|
510
|
+
|
|
511
|
+
#### Search Campaigns
|
|
512
|
+
- GET adAccounts/{adAccountId}/adCampaigns?q=search&search=(status:(values:List(ACTIVE)))&pageSize=100
|
|
513
|
+
- Search params: search.status.values, search.type.values, search.name.values, search.campaignGroup.values
|
|
514
|
+
|
|
515
|
+
#### Search Campaign Groups
|
|
516
|
+
- GET adAccounts/{adAccountId}/adCampaignGroups?q=search&search=(status:(values:List(ACTIVE)))
|
|
517
|
+
|
|
518
|
+
#### Search Creatives
|
|
519
|
+
- GET adAccounts/{adAccountId}/adCreatives?q=search&search=(status:(values:List(ACTIVE)))
|
|
520
|
+
|
|
521
|
+
#### Get Ad Analytics (Analytics Finder - single pivot)
|
|
522
|
+
- GET adAnalytics?q=analytics&pivot=CAMPAIGN&timeGranularity=DAILY&dateRange=(start:(year:2025,month:1,day:1))&accounts=List(urn%3Ali%3AsponsoredAccount%3A{adAccountId})&fields=impressions,clicks,costInLocalCurrency,dateRange,pivotValues
|
|
523
|
+
|
|
524
|
+
#### Get Ad Analytics (Statistics Finder - up to 3 pivots)
|
|
525
|
+
- GET adAnalytics?q=statistics&pivots=List(CAMPAIGN,CREATIVE)&timeGranularity=DAILY&dateRange=(start:(year:2025,month:1,day:1))&accounts=List(urn%3Ali%3AsponsoredAccount%3A{adAccountId})&fields=impressions,clicks,costInLocalCurrency,dateRange,pivotValues
|
|
526
|
+
|
|
527
|
+
### Analytics Pivots
|
|
528
|
+
ACCOUNT, CAMPAIGN_GROUP, CAMPAIGN, CREATIVE, COMPANY, CONVERSION,
|
|
529
|
+
MEMBER_COMPANY, MEMBER_COMPANY_SIZE, MEMBER_COUNTRY_V2, MEMBER_REGION_V2,
|
|
530
|
+
MEMBER_JOB_FUNCTION, MEMBER_JOB_TITLE, MEMBER_INDUSTRY, MEMBER_SENIORITY
|
|
531
|
+
|
|
532
|
+
### Analytics Time Granularity
|
|
533
|
+
DAILY, MONTHLY, YEARLY, ALL
|
|
534
|
+
|
|
535
|
+
### Key Analytics Metrics (specify via fields parameter)
|
|
536
|
+
impressions, clicks, costInLocalCurrency, costInUsd, landingPageClicks,
|
|
537
|
+
totalEngagements, likes, comments, shares, follows, reactions,
|
|
538
|
+
externalWebsiteConversions, conversionValueInLocalCurrency,
|
|
539
|
+
oneClickLeads, oneClickLeadFormOpens, videoViews, videoCompletions,
|
|
540
|
+
videoStarts, sends, opens, approximateMemberReach, dateRange, pivotValues
|
|
541
|
+
|
|
542
|
+
### Analytics Facets (filters)
|
|
543
|
+
- \`accounts\`: List of account URNs \u2014 accounts=List(urn%3Ali%3AsponsoredAccount%3A123)
|
|
544
|
+
- \`campaigns\`: List of campaign URNs \u2014 campaigns=List(urn%3Ali%3AsponsoredCampaign%3A456)
|
|
545
|
+
- \`campaignGroups\`: List of campaign group URNs
|
|
546
|
+
- \`creatives\`: List of creative URNs
|
|
547
|
+
|
|
548
|
+
### Date Range Format
|
|
549
|
+
dateRange=(start:(year:2025,month:1,day:1),end:(year:2025,month:12,day:31))
|
|
550
|
+
End date is optional (defaults to today).
|
|
551
|
+
|
|
552
|
+
### URN Formats
|
|
553
|
+
- Ad Account: urn:li:sponsoredAccount:{id}
|
|
554
|
+
- Campaign Group: urn:li:sponsoredCampaignGroup:{id}
|
|
555
|
+
- Campaign: urn:li:sponsoredCampaign:{id}
|
|
556
|
+
- Creative: urn:li:sponsoredCreative:{id}
|
|
557
|
+
|
|
558
|
+
### Pagination
|
|
559
|
+
Search APIs use cursor-based pagination with pageSize (max 1000) and pageToken.
|
|
560
|
+
Response includes metadata.nextPageToken for fetching next page.
|
|
561
|
+
|
|
562
|
+
### Partial Updates
|
|
563
|
+
Use POST with X-RestLi-Method: PARTIAL_UPDATE header (set automatically when body contains "patch").
|
|
564
|
+
Body format: { "patch": { "$set": { "field": "value" } } }
|
|
565
|
+
|
|
566
|
+
### Tips
|
|
567
|
+
- Always URL-encode URNs in query parameters (: \u2192 %3A)
|
|
568
|
+
- Use fields parameter in adAnalytics to request specific metrics (default: only impressions and clicks)
|
|
569
|
+
- Request up to 20 metrics per analytics call
|
|
570
|
+
- adAnalytics does not support pagination \u2014 response is limited to 15,000 elements
|
|
571
|
+
- Professional demographic pivots (MEMBER_*) may have 12-24h delay
|
|
572
|
+
|
|
573
|
+
### Business Logic
|
|
574
|
+
|
|
575
|
+
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.
|
|
576
|
+
|
|
577
|
+
#### Example
|
|
578
|
+
|
|
579
|
+
\`\`\`ts
|
|
580
|
+
import { connection } from "@squadbase/vite-server/connectors/linkedin-ads-oauth";
|
|
581
|
+
|
|
582
|
+
const linkedin = connection("<connectionId>");
|
|
583
|
+
|
|
584
|
+
// Get campaigns
|
|
585
|
+
const res = await linkedin.request("adAccounts/{adAccountId}/adCampaigns?q=search&search=(status:(values:List(ACTIVE)))");
|
|
586
|
+
const data = await res.json();
|
|
587
|
+
\`\`\``,
|
|
588
|
+
ja: `### \u30C4\u30FC\u30EB
|
|
589
|
+
|
|
590
|
+
- \`linkedin-ads-oauth_request\`: LinkedIn Marketing API\uFF08REST\uFF09\u3078\u8A8D\u8A3C\u6E08\u307F\u30EA\u30AF\u30A8\u30B9\u30C8\u3092\u9001\u4FE1\u3057\u307E\u3059\u3002\u30D1\u30B9\u5185\u306E{adAccountId}\u30D7\u30EC\u30FC\u30B9\u30DB\u30EB\u30C0\u30FC\u306F\u81EA\u52D5\u7684\u306B\u7F6E\u63DB\u3055\u308C\u307E\u3059\u3002\u8A8D\u8A3C\u306FOAuth\u30D7\u30ED\u30AD\u30B7\u7D4C\u7531\u3067\u81EA\u52D5\u7684\u306B\u51E6\u7406\u3055\u308C\u307E\u3059\u3002\u5FC5\u9808\u30D8\u30C3\u30C0\u30FC\uFF08LinkedIn-Version\u3001X-Restli-Protocol-Version\uFF09\u306F\u81EA\u52D5\u8A2D\u5B9A\u3055\u308C\u307E\u3059\u3002
|
|
591
|
+
- \`linkedin-ads-oauth_listAdAccounts\`: \u30A2\u30AF\u30BB\u30B9\u53EF\u80FD\u306ALinkedIn\u5E83\u544A\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
|
|
592
|
+
|
|
593
|
+
### LinkedIn Marketing API \u30EA\u30D5\u30A1\u30EC\u30F3\u30B9
|
|
594
|
+
|
|
595
|
+
\u30D9\u30FC\u30B9URL: https://api.linkedin.com/rest/
|
|
596
|
+
API\u30D0\u30FC\u30B8\u30E7\u30F3: 202603\uFF08LinkedIn-Version\u30D8\u30C3\u30C0\u30FC\u3067\u81EA\u52D5\u8A2D\u5B9A\uFF09
|
|
597
|
+
|
|
598
|
+
#### \u30A2\u30AB\u30A6\u30F3\u30C8\u968E\u5C64
|
|
599
|
+
\u5E83\u544A\u30A2\u30AB\u30A6\u30F3\u30C8 (sponsoredAccount) > \u30AD\u30E3\u30F3\u30DA\u30FC\u30F3\u30B0\u30EB\u30FC\u30D7 (sponsoredCampaignGroup) > \u30AD\u30E3\u30F3\u30DA\u30FC\u30F3 (adCampaign) > \u30AF\u30EA\u30A8\u30A4\u30C6\u30A3\u30D6
|
|
600
|
+
|
|
601
|
+
#### \u5E83\u544A\u30A2\u30AB\u30A6\u30F3\u30C8\u691C\u7D22
|
|
602
|
+
- GET adAccounts?q=search&search=(status:(values:List(ACTIVE)))
|
|
603
|
+
|
|
604
|
+
#### \u30AD\u30E3\u30F3\u30DA\u30FC\u30F3\u691C\u7D22
|
|
605
|
+
- GET adAccounts/{adAccountId}/adCampaigns?q=search&search=(status:(values:List(ACTIVE)))&pageSize=100
|
|
606
|
+
- \u691C\u7D22\u30D1\u30E9\u30E1\u30FC\u30BF: search.status.values, search.type.values, search.name.values, search.campaignGroup.values
|
|
607
|
+
|
|
608
|
+
#### \u30AD\u30E3\u30F3\u30DA\u30FC\u30F3\u30B0\u30EB\u30FC\u30D7\u691C\u7D22
|
|
609
|
+
- GET adAccounts/{adAccountId}/adCampaignGroups?q=search&search=(status:(values:List(ACTIVE)))
|
|
610
|
+
|
|
611
|
+
#### \u30AF\u30EA\u30A8\u30A4\u30C6\u30A3\u30D6\u691C\u7D22
|
|
612
|
+
- GET adAccounts/{adAccountId}/adCreatives?q=search&search=(status:(values:List(ACTIVE)))
|
|
613
|
+
|
|
614
|
+
#### \u5E83\u544A\u30A2\u30CA\u30EA\u30C6\u30A3\u30AF\u30B9\u53D6\u5F97\uFF08Analytics Finder - \u5358\u4E00\u30D4\u30DC\u30C3\u30C8\uFF09
|
|
615
|
+
- GET adAnalytics?q=analytics&pivot=CAMPAIGN&timeGranularity=DAILY&dateRange=(start:(year:2025,month:1,day:1))&accounts=List(urn%3Ali%3AsponsoredAccount%3A{adAccountId})&fields=impressions,clicks,costInLocalCurrency,dateRange,pivotValues
|
|
616
|
+
|
|
617
|
+
#### \u5E83\u544A\u30A2\u30CA\u30EA\u30C6\u30A3\u30AF\u30B9\u53D6\u5F97\uFF08Statistics Finder - \u6700\u59273\u30D4\u30DC\u30C3\u30C8\uFF09
|
|
618
|
+
- GET adAnalytics?q=statistics&pivots=List(CAMPAIGN,CREATIVE)&timeGranularity=DAILY&dateRange=(start:(year:2025,month:1,day:1))&accounts=List(urn%3Ali%3AsponsoredAccount%3A{adAccountId})&fields=impressions,clicks,costInLocalCurrency,dateRange,pivotValues
|
|
619
|
+
|
|
620
|
+
### \u30A2\u30CA\u30EA\u30C6\u30A3\u30AF\u30B9\u306E\u30D4\u30DC\u30C3\u30C8
|
|
621
|
+
ACCOUNT, CAMPAIGN_GROUP, CAMPAIGN, CREATIVE, COMPANY, CONVERSION,
|
|
622
|
+
MEMBER_COMPANY, MEMBER_COMPANY_SIZE, MEMBER_COUNTRY_V2, MEMBER_REGION_V2,
|
|
623
|
+
MEMBER_JOB_FUNCTION, MEMBER_JOB_TITLE, MEMBER_INDUSTRY, MEMBER_SENIORITY
|
|
624
|
+
|
|
625
|
+
### \u6642\u9593\u7C92\u5EA6
|
|
626
|
+
DAILY, MONTHLY, YEARLY, ALL
|
|
627
|
+
|
|
628
|
+
### \u4E3B\u8981\u30A2\u30CA\u30EA\u30C6\u30A3\u30AF\u30B9\u30E1\u30C8\u30EA\u30AF\u30B9\uFF08fields\u30D1\u30E9\u30E1\u30FC\u30BF\u3067\u6307\u5B9A\uFF09
|
|
629
|
+
impressions, clicks, costInLocalCurrency, costInUsd, landingPageClicks,
|
|
630
|
+
totalEngagements, likes, comments, shares, follows, reactions,
|
|
631
|
+
externalWebsiteConversions, conversionValueInLocalCurrency,
|
|
632
|
+
oneClickLeads, oneClickLeadFormOpens, videoViews, videoCompletions,
|
|
633
|
+
videoStarts, sends, opens, approximateMemberReach, dateRange, pivotValues
|
|
634
|
+
|
|
635
|
+
### \u30A2\u30CA\u30EA\u30C6\u30A3\u30AF\u30B9\u306E\u30D5\u30A1\u30BB\u30C3\u30C8\uFF08\u30D5\u30A3\u30EB\u30BF\uFF09
|
|
636
|
+
- \`accounts\`: \u30A2\u30AB\u30A6\u30F3\u30C8URN\u306E\u30EA\u30B9\u30C8 \u2014 accounts=List(urn%3Ali%3AsponsoredAccount%3A123)
|
|
637
|
+
- \`campaigns\`: \u30AD\u30E3\u30F3\u30DA\u30FC\u30F3URN\u306E\u30EA\u30B9\u30C8 \u2014 campaigns=List(urn%3Ali%3AsponsoredCampaign%3A456)
|
|
638
|
+
- \`campaignGroups\`: \u30AD\u30E3\u30F3\u30DA\u30FC\u30F3\u30B0\u30EB\u30FC\u30D7URN\u306E\u30EA\u30B9\u30C8
|
|
639
|
+
- \`creatives\`: \u30AF\u30EA\u30A8\u30A4\u30C6\u30A3\u30D6URN\u306E\u30EA\u30B9\u30C8
|
|
640
|
+
|
|
641
|
+
### \u65E5\u4ED8\u7BC4\u56F2\u30D5\u30A9\u30FC\u30DE\u30C3\u30C8
|
|
642
|
+
dateRange=(start:(year:2025,month:1,day:1),end:(year:2025,month:12,day:31))
|
|
643
|
+
\u7D42\u4E86\u65E5\u306F\u30AA\u30D7\u30B7\u30E7\u30F3\uFF08\u30C7\u30D5\u30A9\u30EB\u30C8\u306F\u4ECA\u65E5\uFF09\u3002
|
|
644
|
+
|
|
645
|
+
### URN\u30D5\u30A9\u30FC\u30DE\u30C3\u30C8
|
|
646
|
+
- \u5E83\u544A\u30A2\u30AB\u30A6\u30F3\u30C8: urn:li:sponsoredAccount:{id}
|
|
647
|
+
- \u30AD\u30E3\u30F3\u30DA\u30FC\u30F3\u30B0\u30EB\u30FC\u30D7: urn:li:sponsoredCampaignGroup:{id}
|
|
648
|
+
- \u30AD\u30E3\u30F3\u30DA\u30FC\u30F3: urn:li:sponsoredCampaign:{id}
|
|
649
|
+
- \u30AF\u30EA\u30A8\u30A4\u30C6\u30A3\u30D6: urn:li:sponsoredCreative:{id}
|
|
650
|
+
|
|
651
|
+
### \u30DA\u30FC\u30B8\u30CD\u30FC\u30B7\u30E7\u30F3
|
|
652
|
+
\u691C\u7D22API\u306F\u30AB\u30FC\u30BD\u30EB\u30D9\u30FC\u30B9\u306E\u30DA\u30FC\u30B8\u30CD\u30FC\u30B7\u30E7\u30F3\u3092\u4F7F\u7528\uFF08pageSize\u6700\u59271000\u3001pageToken\uFF09\u3002
|
|
653
|
+
\u30EC\u30B9\u30DD\u30F3\u30B9\u306Emetadata.nextPageToken\u3067\u6B21\u30DA\u30FC\u30B8\u3092\u53D6\u5F97\u3002
|
|
654
|
+
|
|
655
|
+
### \u90E8\u5206\u66F4\u65B0
|
|
656
|
+
POST\u3067X-RestLi-Method: PARTIAL_UPDATE\u30D8\u30C3\u30C0\u30FC\u3092\u4F7F\u7528\uFF08body\u306B"patch"\u304C\u542B\u307E\u308C\u308B\u5834\u5408\u81EA\u52D5\u8A2D\u5B9A\uFF09\u3002
|
|
657
|
+
\u30DC\u30C7\u30A3\u5F62\u5F0F: { "patch": { "$set": { "field": "value" } } }
|
|
658
|
+
|
|
659
|
+
### \u30D2\u30F3\u30C8
|
|
660
|
+
- \u30AF\u30A8\u30EA\u30D1\u30E9\u30E1\u30FC\u30BF\u5185\u306EURN\u306F\u5FC5\u305AURL\u30A8\u30F3\u30B3\u30FC\u30C9\uFF08: \u2192 %3A\uFF09
|
|
661
|
+
- adAnalytics\u3067\u306Ffields\u30D1\u30E9\u30E1\u30FC\u30BF\u3067\u53D6\u5F97\u3059\u308B\u30E1\u30C8\u30EA\u30AF\u30B9\u3092\u6307\u5B9A\uFF08\u30C7\u30D5\u30A9\u30EB\u30C8: impressions\u3068clicks\u306E\u307F\uFF09
|
|
662
|
+
- \u30A2\u30CA\u30EA\u30C6\u30A3\u30AF\u30B9\u30B3\u30FC\u30EB\u3054\u3068\u306B\u6700\u592720\u30E1\u30C8\u30EA\u30AF\u30B9\u3092\u30EA\u30AF\u30A8\u30B9\u30C8\u53EF\u80FD
|
|
663
|
+
- adAnalytics\u306F\u30DA\u30FC\u30B8\u30CD\u30FC\u30B7\u30E7\u30F3\u975E\u5BFE\u5FDC \u2014 \u30EC\u30B9\u30DD\u30F3\u30B9\u306F15,000\u8981\u7D20\u307E\u3067
|
|
664
|
+
- \u30D7\u30ED\u30D5\u30A7\u30C3\u30B7\u30E7\u30CA\u30EB\u30C7\u30E2\u30B0\u30E9\u30D5\u30A3\u30C3\u30AF\u30D4\u30DC\u30C3\u30C8\uFF08MEMBER_*\uFF09\u306F12-24\u6642\u9593\u306E\u9045\u5EF6\u3042\u308A
|
|
665
|
+
|
|
666
|
+
### Business Logic
|
|
667
|
+
|
|
668
|
+
\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
|
|
669
|
+
|
|
670
|
+
#### Example
|
|
671
|
+
|
|
672
|
+
\`\`\`ts
|
|
673
|
+
import { connection } from "@squadbase/vite-server/connectors/linkedin-ads-oauth";
|
|
674
|
+
|
|
675
|
+
const linkedin = connection("<connectionId>");
|
|
676
|
+
|
|
677
|
+
// \u30AD\u30E3\u30F3\u30DA\u30FC\u30F3\u3092\u53D6\u5F97
|
|
678
|
+
const res = await linkedin.request("adAccounts/{adAccountId}/adCampaigns?q=search&search=(status:(values:List(ACTIVE)))");
|
|
679
|
+
const data = await res.json();
|
|
680
|
+
\`\`\``
|
|
681
|
+
},
|
|
682
|
+
tools,
|
|
683
|
+
async checkConnection(_params, config) {
|
|
684
|
+
const { proxyFetch } = config;
|
|
685
|
+
try {
|
|
686
|
+
const url = "https://api.linkedin.com/rest/adAccounts?q=search&search=(status:(values:List(ACTIVE)))&pageSize=1";
|
|
687
|
+
const res = await proxyFetch(url, {
|
|
688
|
+
method: "GET",
|
|
689
|
+
headers: {
|
|
690
|
+
"LinkedIn-Version": "202603",
|
|
691
|
+
"X-Restli-Protocol-Version": "2.0.0"
|
|
692
|
+
}
|
|
693
|
+
});
|
|
694
|
+
if (!res.ok) {
|
|
695
|
+
const data = await res.json().catch(() => ({}));
|
|
696
|
+
return {
|
|
697
|
+
success: false,
|
|
698
|
+
error: data?.message ?? `LinkedIn API failed: HTTP ${res.status}`
|
|
699
|
+
};
|
|
700
|
+
}
|
|
701
|
+
return { success: true };
|
|
702
|
+
} catch (error) {
|
|
703
|
+
return {
|
|
704
|
+
success: false,
|
|
705
|
+
error: error instanceof Error ? error.message : String(error)
|
|
706
|
+
};
|
|
707
|
+
}
|
|
708
|
+
}
|
|
709
|
+
});
|
|
710
|
+
|
|
711
|
+
// src/connectors/create-connector-sdk.ts
|
|
712
|
+
import { readFileSync } from "fs";
|
|
713
|
+
import path from "path";
|
|
714
|
+
|
|
715
|
+
// src/connector-client/env.ts
|
|
716
|
+
function resolveEnvVar(entry, key, connectionId) {
|
|
717
|
+
const envVarName = entry.envVars[key];
|
|
718
|
+
if (!envVarName) {
|
|
719
|
+
throw new Error(`Connection "${connectionId}" is missing envVars mapping for key "${key}"`);
|
|
720
|
+
}
|
|
721
|
+
const value = process.env[envVarName];
|
|
722
|
+
if (!value) {
|
|
723
|
+
throw new Error(`Environment variable "${envVarName}" (for connection "${connectionId}", key "${key}") is not set`);
|
|
724
|
+
}
|
|
725
|
+
return value;
|
|
726
|
+
}
|
|
727
|
+
function resolveEnvVarOptional(entry, key) {
|
|
728
|
+
const envVarName = entry.envVars[key];
|
|
729
|
+
if (!envVarName) return void 0;
|
|
730
|
+
return process.env[envVarName] || void 0;
|
|
731
|
+
}
|
|
732
|
+
|
|
733
|
+
// src/connectors/create-connector-sdk.ts
|
|
734
|
+
function loadConnectionsSync() {
|
|
735
|
+
const filePath = process.env.CONNECTIONS_PATH ?? path.join(process.cwd(), ".squadbase/connections.json");
|
|
736
|
+
try {
|
|
737
|
+
const raw = readFileSync(filePath, "utf-8");
|
|
738
|
+
return JSON.parse(raw);
|
|
739
|
+
} catch {
|
|
740
|
+
return {};
|
|
741
|
+
}
|
|
742
|
+
}
|
|
743
|
+
function createConnectorSdk(plugin, createClient2) {
|
|
744
|
+
return (connectionId) => {
|
|
745
|
+
const connections = loadConnectionsSync();
|
|
746
|
+
const entry = connections[connectionId];
|
|
747
|
+
if (!entry) {
|
|
748
|
+
throw new Error(
|
|
749
|
+
`Connection "${connectionId}" not found in .squadbase/connections.json`
|
|
750
|
+
);
|
|
751
|
+
}
|
|
752
|
+
if (entry.connector.slug !== plugin.slug) {
|
|
753
|
+
throw new Error(
|
|
754
|
+
`Connection "${connectionId}" is not a ${plugin.slug} connection (got "${entry.connector.slug}")`
|
|
755
|
+
);
|
|
756
|
+
}
|
|
757
|
+
const params = {};
|
|
758
|
+
for (const param of Object.values(plugin.parameters)) {
|
|
759
|
+
if (param.required) {
|
|
760
|
+
params[param.slug] = resolveEnvVar(entry, param.slug, connectionId);
|
|
761
|
+
} else {
|
|
762
|
+
const val = resolveEnvVarOptional(entry, param.slug);
|
|
763
|
+
if (val !== void 0) params[param.slug] = val;
|
|
764
|
+
}
|
|
765
|
+
}
|
|
766
|
+
return createClient2(params);
|
|
767
|
+
};
|
|
768
|
+
}
|
|
769
|
+
|
|
770
|
+
// src/connectors/entries/linkedin-ads-oauth.ts
|
|
771
|
+
var connection = createConnectorSdk(linkedinAdsOauthConnector, createClient);
|
|
772
|
+
export {
|
|
773
|
+
connection
|
|
774
|
+
};
|