@squadbase/vite-server 0.1.3-dev.0 → 0.1.3-dev.2

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