@trillboards/api-client 3.2.45 → 3.3.9

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/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
- import { __require } from './chunk-VMTPZ35B.mjs';
2
- export { generatedTypes } from './chunk-VMTPZ35B.mjs';
1
+ import { advertiserBuyingRoutes, __require } from './chunk-HYA2ZRAK.mjs';
2
+ export { generatedTypes } from './chunk-HYA2ZRAK.mjs';
3
3
  import { createParser } from 'eventsource-parser';
4
4
  import { Client } from '@modelcontextprotocol/sdk/client/index.js';
5
5
  import { StreamableHTTPClientTransport } from '@modelcontextprotocol/sdk/client/streamableHttp.js';
@@ -18,6 +18,8 @@ var TrillboardsError = class _TrillboardsError extends Error {
18
18
  this.docsUrl = opts.docsUrl ?? `https://api.trillboards.com/docs/errors#${opts.code}`;
19
19
  this.details = opts.details ?? [];
20
20
  this.help = opts.help ?? null;
21
+ this.recovery = opts.recovery ?? null;
22
+ this.wwwAuthenticate = opts.wwwAuthenticate ?? null;
21
23
  this._retryAfterSeconds = opts.retryAfterSeconds ?? null;
22
24
  }
23
25
  /**
@@ -26,8 +28,8 @@ var TrillboardsError = class _TrillboardsError extends Error {
26
28
  * The API wraps errors in { error: { ... } }. We unwrap and map to class fields.
27
29
  */
28
30
  static fromResponse(body, response) {
29
- const errorObj = body?.error ?? body;
30
- const errData = errorObj;
31
+ const root2 = body && typeof body === "object" ? body : {};
32
+ const errData = root2.error && typeof root2.error === "object" ? root2.error : root2;
31
33
  const retryAfterHeader = response.headers.get("retry-after");
32
34
  let retryAfterSeconds = null;
33
35
  if (retryAfterHeader) {
@@ -38,15 +40,17 @@ var TrillboardsError = class _TrillboardsError extends Error {
38
40
  }
39
41
  return new _TrillboardsError({
40
42
  type: errData.type ?? "api_error",
41
- code: errData.code ?? "unknown_error",
42
- message: errData.message ?? "An unknown error occurred.",
43
+ code: errData.error_code ?? errData.code ?? "unknown_error",
44
+ message: errData.message ?? (typeof root2.error === "string" ? root2.error : "An unknown error occurred."),
43
45
  statusCode: response.status,
44
46
  param: errData.param ?? null,
45
- requestId: errData.request_id ?? "",
47
+ requestId: errData.request_id ?? response.headers.get("x-request-id") ?? "",
46
48
  docsUrl: errData.doc_url ?? void 0,
47
49
  details: errData.details ?? [],
48
50
  help: errData.help ?? null,
49
- retryAfterSeconds
51
+ retryAfterSeconds,
52
+ recovery: errData.recovery ?? null,
53
+ wwwAuthenticate: response.headers.get("www-authenticate")
50
54
  });
51
55
  }
52
56
  /** True if this is a 429 rate limit response. */
@@ -75,7 +79,7 @@ var TrillboardsError = class _TrillboardsError extends Error {
75
79
  };
76
80
 
77
81
  // src/version.ts
78
- var VERSION = "3.2.45";
82
+ var VERSION = "3.3.9";
79
83
 
80
84
  // src/http.ts
81
85
  var PUBLIC_PATHS = ["/v1/errors", "/v1/changelog", "/api/discover", "/v1/health"];
@@ -161,12 +165,11 @@ var HttpClient = class {
161
165
  try {
162
166
  return await response.json();
163
167
  } catch {
164
- throw new TrillboardsError({
168
+ throw TrillboardsError.fromResponse({ error: {
165
169
  type: "api_error",
166
170
  code: "invalid_response",
167
- message: `Invalid JSON response from API (HTTP ${response.status}).`,
168
- statusCode: response.status
169
- });
171
+ message: `Invalid JSON response from API (HTTP ${response.status}).`
172
+ } }, response);
170
173
  }
171
174
  }
172
175
  /** Open one authenticated live tail. The native endpoint has no replay cursor. */
@@ -228,6 +231,86 @@ var HttpClient = class {
228
231
  }
229
232
  };
230
233
 
234
+ // src/advertiser-buying.ts
235
+ var ADVERTISER_BUYING_RESOURCE = "https://api.trillboards.com/openrtb/v2/buying";
236
+ var AdvertiserBuyingClient = class {
237
+ constructor(options) {
238
+ if (!options?.oauth || typeof options.oauth.accessToken !== "string" || !options.oauth.accessToken.trim())
239
+ throw new Error("AdvertiserBuyingClient requires an OAuth accessToken.");
240
+ if (options.oauth.resource !== ADVERTISER_BUYING_RESOURCE)
241
+ throw new Error("AdvertiserBuyingClient requires the exact advertiser buying OAuth resource.");
242
+ this.authorization = "Bearer " + options.oauth.accessToken.trim();
243
+ this.http = new HttpClient({ baseUrl: (options.baseUrl ?? "https://api.trillboards.com").replace(/\/+$/, ""), version: options.version });
244
+ }
245
+ target(id) {
246
+ if (typeof id !== "string" || !id.trim()) throw new Error("An original campaign ID is required.");
247
+ return encodeURIComponent(id);
248
+ }
249
+ call(name, id, body, query, options) {
250
+ const route = advertiserBuyingRoutes[name];
251
+ const requestBody = body === void 0 ? void 0 : JSON.parse(JSON.stringify(body));
252
+ const path2 = id === void 0 ? route.path : route.path.replace("{advertisementId}", this.target(id));
253
+ const headers = { ...options?.headers };
254
+ for (const [header, value] of Object.entries(headers)) {
255
+ if (header.toLowerCase() === "authorization") {
256
+ if (value !== this.authorization) throw new Error("Buyer OAuth Authorization cannot use a different credential.");
257
+ delete headers[header];
258
+ }
259
+ }
260
+ headers.Authorization = this.authorization;
261
+ if (route.requiresIdempotencyKey) {
262
+ const key = options?.idempotencyKey;
263
+ if (typeof key !== "string" || !key.trim() || key.trim().length > 200) throw new Error("A caller idempotencyKey is required for this action.");
264
+ const original = key.trim();
265
+ for (const [header, value] of Object.entries(headers)) if (header.toLowerCase() === "idempotency-key") {
266
+ if (value !== original) throw new Error("Idempotency header conflicts with the original action key.");
267
+ delete headers[header];
268
+ }
269
+ if (requestBody && typeof requestBody === "object" && "idempotency_key" in requestBody && requestBody.idempotency_key !== original)
270
+ throw new Error("Idempotency body conflicts with the original action key.");
271
+ headers["Idempotency-Key"] = original;
272
+ }
273
+ const request = () => this.http.request(route.method, path2, { body: requestBody, params: query, headers });
274
+ return route.requiresIdempotencyKey ? retryWithBackoff(request, options?.retry) : request();
275
+ }
276
+ searchInventory(input) {
277
+ return this.call("buyingSearchInventory", void 0, input);
278
+ }
279
+ previewPlan(input) {
280
+ return this.call("buyingPreviewPlan", void 0, input);
281
+ }
282
+ saveCampaign(input, options) {
283
+ return this.call("buyingSaveCampaign", void 0, input, void 0, options);
284
+ }
285
+ attachCreative(id, input, options) {
286
+ return this.call("buyingAttachCreative", id, input, void 0, options);
287
+ }
288
+ prepareBooking(id, input = {}) {
289
+ return this.call("buyingPrepareBooking", id, input);
290
+ }
291
+ createCheckout(id, input, options) {
292
+ return this.call("buyingCreateCheckout", id, input, void 0, options);
293
+ }
294
+ getCampaign(id) {
295
+ return this.call("buyingGetCampaign", id);
296
+ }
297
+ getDelivery(id, query = {}) {
298
+ return this.call("buyingGetDelivery", id, void 0, query);
299
+ }
300
+ rebookCampaign(id, input, options) {
301
+ return this.call("buyingRebookCampaign", id, input, void 0, options);
302
+ }
303
+ stopCampaign(id, options) {
304
+ return this.call("buyingStopCampaign", id, {}, void 0, options);
305
+ }
306
+ amendFlight(id, input, options) {
307
+ return this.call("buyingAmendFlight", id, input, void 0, options);
308
+ }
309
+ updateMetadata(id, input, options) {
310
+ return this.call("buyingUpdateMetadata", id, input, void 0, options);
311
+ }
312
+ };
313
+
231
314
  // src/resources/screens.ts
232
315
  var ScreensClient = class {
233
316
  constructor(http) {
@@ -623,6 +706,59 @@ var CreativeExperimentsClient = class {
623
706
  return this.http.post(path(id) + "/stop", body);
624
707
  }
625
708
  };
709
+
710
+ // src/resources/reactive.ts
711
+ var root = "/v1/partner";
712
+ var screen = (id) => root + "/screens/" + encodeURIComponent(id) + "/reactive-settings";
713
+ var group = (id) => root + "/screen-groups/" + encodeURIComponent(id);
714
+ var campaign = (id) => root + "/ads/" + encodeURIComponent(id) + "/reactive";
715
+ var ReactiveClient = class {
716
+ constructor(http) {
717
+ this.http = http;
718
+ }
719
+ getBrand(id) {
720
+ return this.http.get(campaign(id) + "/brand");
721
+ }
722
+ updateBrand(id, body) {
723
+ return this.http.put(campaign(id) + "/brand", body);
724
+ }
725
+ importCreative(id, body) {
726
+ return this.http.post(campaign(id) + "/creatives/import", body);
727
+ }
728
+ generateCreative(id, body) {
729
+ return this.http.post(campaign(id) + "/creatives/generate", body);
730
+ }
731
+ reviewCreative(id, body) {
732
+ return this.http.post(campaign(id) + "/creatives/review", body);
733
+ }
734
+ listCreatives(id) {
735
+ return this.http.get(campaign(id) + "/creatives");
736
+ }
737
+ getScreenSettings(id) {
738
+ return this.http.get(screen(id));
739
+ }
740
+ updateScreenSettings(id, body) {
741
+ return this.http.patch(screen(id), body);
742
+ }
743
+ getGroupSettings(id) {
744
+ return this.http.get(group(id) + "/reactive-settings");
745
+ }
746
+ updateGroupSettings(id, body) {
747
+ return this.http.patch(group(id) + "/reactive-settings", body);
748
+ }
749
+ getCampaign(id) {
750
+ return this.http.get(campaign(id));
751
+ }
752
+ updateCampaign(id, body) {
753
+ return this.http.patch(campaign(id), body);
754
+ }
755
+ getGroupSensingConfig(id) {
756
+ return this.http.get(group(id) + "/sensing-config");
757
+ }
758
+ updateGroupSensingConfig(id, body) {
759
+ return this.http.put(group(id) + "/sensing-config", body);
760
+ }
761
+ };
626
762
  var McpToolError = class extends Error {
627
763
  constructor(tool, result) {
628
764
  super("Native MCP tool failed: " + tool);
@@ -742,6 +878,7 @@ var TrillboardsClient = class {
742
878
  this.billing = new BillingClient(this._http);
743
879
  this.routes = new RoutesClient(this._http);
744
880
  this.creativeExperiments = new CreativeExperimentsClient(this._http);
881
+ this.reactive = new ReactiveClient(this._http);
745
882
  this.mediaBuys = new MediaBuysClient({ apiKey: options.apiKey, baseUrl, version: options.version });
746
883
  }
747
884
  };
@@ -1038,6 +1175,6 @@ var Webhooks = {
1038
1175
  verifyAdcpWebhook
1039
1176
  };
1040
1177
 
1041
- export { ADCP_WEBHOOK_SIGNING_TAG, AnalyticsClient, AudienceClient, BillingClient, CreativeExperimentsClient, DataClient, DevicesClient, EarningsClient, ErrorsClient, FleetClient, ImpressionsClient, McpToolError, MediaBuysClient, RoutesClient, ScreensClient, TrillboardsClient, TrillboardsError, VERSION, Webhooks, WebhooksClient, constructEvent, constructEventLegacy, parseSignatureHeader, retryWithBackoff, verifyAdcpWebhook };
1178
+ export { ADCP_WEBHOOK_SIGNING_TAG, ADVERTISER_BUYING_RESOURCE, AdvertiserBuyingClient, AnalyticsClient, AudienceClient, BillingClient, CreativeExperimentsClient, DataClient, DevicesClient, EarningsClient, ErrorsClient, FleetClient, ImpressionsClient, McpToolError, MediaBuysClient, ReactiveClient, RoutesClient, ScreensClient, TrillboardsClient, TrillboardsError, VERSION, Webhooks, WebhooksClient, constructEvent, constructEventLegacy, parseSignatureHeader, retryWithBackoff, verifyAdcpWebhook };
1042
1179
  //# sourceMappingURL=index.mjs.map
1043
1180
  //# sourceMappingURL=index.mjs.map