@trillboards/api-client 3.3.9 → 3.4.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +21 -1
- package/dist/chunk-LFNHGVB3.mjs +20 -0
- package/dist/chunk-LFNHGVB3.mjs.map +1 -0
- package/dist/generated.d.mts +31409 -18601
- package/dist/generated.d.ts +31409 -18601
- package/dist/generated.js +6 -4
- package/dist/generated.js.map +1 -1
- package/dist/generated.mjs +1 -1
- package/dist/index.d.mts +39 -7
- package/dist/index.d.ts +39 -7
- package/dist/index.js +84 -19
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +80 -18
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
- package/dist/chunk-HYA2ZRAK.mjs +0 -19
- package/dist/chunk-HYA2ZRAK.mjs.map +0 -1
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { advertiserBuyingRoutes, __require } from './chunk-
|
|
2
|
-
export { generatedTypes } from './chunk-
|
|
1
|
+
import { advertiserBuyingRoutes, advertiserRoutes, __require } from './chunk-LFNHGVB3.mjs';
|
|
2
|
+
export { advertiserRoutes, generatedTypes } from './chunk-LFNHGVB3.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';
|
|
@@ -79,7 +79,7 @@ var TrillboardsError = class _TrillboardsError extends Error {
|
|
|
79
79
|
};
|
|
80
80
|
|
|
81
81
|
// src/version.ts
|
|
82
|
-
var VERSION = "3.3
|
|
82
|
+
var VERSION = "3.4.3";
|
|
83
83
|
|
|
84
84
|
// src/http.ts
|
|
85
85
|
var PUBLIC_PATHS = ["/v1/errors", "/v1/changelog", "/api/discover", "/v1/health"];
|
|
@@ -131,14 +131,19 @@ var HttpClient = class {
|
|
|
131
131
|
async request(method, path2, options) {
|
|
132
132
|
const response = await this.requestResponse(method, path2, options);
|
|
133
133
|
if (response.status === 204) return void 0;
|
|
134
|
-
|
|
135
|
-
if (
|
|
136
|
-
|
|
134
|
+
if (!response.ok) throw TrillboardsError.fromResponse(await this.readJson(response), response);
|
|
135
|
+
if (options?.responseType === "auto") {
|
|
136
|
+
const media = (response.headers.get("content-type") || "").split(";")[0].toLowerCase();
|
|
137
|
+
if (media.startsWith("text/")) return await response.text();
|
|
138
|
+
if (media && media !== "application/json" && !media.endsWith("+json")) return await response.blob();
|
|
139
|
+
}
|
|
140
|
+
return await this.readJson(response);
|
|
137
141
|
}
|
|
138
142
|
async requestResponse(method, path2, options) {
|
|
139
143
|
const url = this.buildUrl(path2, options?.params);
|
|
144
|
+
const nativeBody = options?.body instanceof FormData || options?.body instanceof Blob || options?.body instanceof URLSearchParams;
|
|
140
145
|
const headers = {
|
|
141
|
-
"Content-Type": "application/json",
|
|
146
|
+
...nativeBody ? {} : { "Content-Type": "application/json" },
|
|
142
147
|
"X-Trillboards-Client": `typescript-sdk/${VERSION}`,
|
|
143
148
|
"User-Agent": `trillboards-typescript/${VERSION}`,
|
|
144
149
|
...options?.headers ?? {}
|
|
@@ -156,7 +161,7 @@ var HttpClient = class {
|
|
|
156
161
|
headers
|
|
157
162
|
};
|
|
158
163
|
if (options?.body !== void 0 && options.body !== null) {
|
|
159
|
-
fetchOptions.body = JSON.stringify(options.body);
|
|
164
|
+
fetchOptions.body = nativeBody ? options.body : JSON.stringify(options.body);
|
|
160
165
|
}
|
|
161
166
|
fetchOptions.signal = options?.signal;
|
|
162
167
|
return fetch(url, fetchOptions);
|
|
@@ -217,17 +222,15 @@ var HttpClient = class {
|
|
|
217
222
|
return retryWithBackoff(() => this.request("DELETE", path2, { headers: opts?.headers }), opts?.retry);
|
|
218
223
|
}
|
|
219
224
|
buildUrl(path2, params) {
|
|
220
|
-
const
|
|
221
|
-
if (
|
|
222
|
-
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
if (value !== void 0 && value !== null) {
|
|
227
|
-
searchParams.set(key, String(value));
|
|
225
|
+
const url = new URL(`${this.config.baseUrl}${path2}`);
|
|
226
|
+
if (params instanceof URLSearchParams) {
|
|
227
|
+
for (const [key, value] of params) url.searchParams.append(key, value);
|
|
228
|
+
} else {
|
|
229
|
+
for (const [key, value] of Object.entries(params || {})) {
|
|
230
|
+
if (value !== void 0 && value !== null) url.searchParams.set(key, String(value));
|
|
228
231
|
}
|
|
229
232
|
}
|
|
230
|
-
return
|
|
233
|
+
return url.toString();
|
|
231
234
|
}
|
|
232
235
|
};
|
|
233
236
|
|
|
@@ -882,6 +885,65 @@ var TrillboardsClient = class {
|
|
|
882
885
|
this.mediaBuys = new MediaBuysClient({ apiKey: options.apiKey, baseUrl, version: options.version });
|
|
883
886
|
}
|
|
884
887
|
};
|
|
888
|
+
|
|
889
|
+
// src/advertiser.ts
|
|
890
|
+
var AdvertiserClient = class {
|
|
891
|
+
constructor(options = {}) {
|
|
892
|
+
this.token = options.token?.trim();
|
|
893
|
+
this.http = new HttpClient({ baseUrl: options.baseUrl || "https://api.trillboards.com", version: options.version });
|
|
894
|
+
}
|
|
895
|
+
async request(operationId, ...args) {
|
|
896
|
+
const route = advertiserRoutes[operationId];
|
|
897
|
+
if (!route) throw new Error("Unknown native advertiser operation.");
|
|
898
|
+
const input = args[0] || {};
|
|
899
|
+
const acceptsCredential = route.security.some((requirement) => Object.keys(requirement).length > 0);
|
|
900
|
+
const requiresCredential = acceptsCredential && !route.security.some((requirement) => Object.keys(requirement).length === 0);
|
|
901
|
+
if (requiresCredential && !this.token) throw new Error("A portal user JWT is required for this native operation.");
|
|
902
|
+
const headers = {};
|
|
903
|
+
for (const [name, value] of Object.entries(input.headers || {})) {
|
|
904
|
+
if (value === void 0 || value === null) continue;
|
|
905
|
+
if (["x-api-key", "x-trillboards-api-key"].includes(name.toLowerCase())) throw new Error("Native user JWT mode cannot be combined with API-key headers.");
|
|
906
|
+
if (name.toLowerCase() === "authorization") {
|
|
907
|
+
if (!acceptsCredential || !this.token || value !== `Bearer ${this.token}`) throw new Error("Authorization conflicts with the native user JWT.");
|
|
908
|
+
continue;
|
|
909
|
+
}
|
|
910
|
+
headers[name] = String(value);
|
|
911
|
+
}
|
|
912
|
+
if (acceptsCredential && this.token) headers.Authorization = `Bearer ${this.token}`;
|
|
913
|
+
const path2 = route.path.replace(/\{([^}]+)\}/g, (_match, name) => {
|
|
914
|
+
const value = input.params?.[name];
|
|
915
|
+
if (value === void 0 || value === null) throw new Error("Missing native path parameter: " + name);
|
|
916
|
+
if (value === "." || value === "..") throw new Error("Invalid native path parameter: " + name);
|
|
917
|
+
return encodeURIComponent(String(value));
|
|
918
|
+
});
|
|
919
|
+
const params = new URLSearchParams();
|
|
920
|
+
const query = route.query;
|
|
921
|
+
for (const [name, value] of Object.entries(input.query || {})) {
|
|
922
|
+
if (value === void 0 || value === null) continue;
|
|
923
|
+
const definition = query.find((parameter) => parameter.name === name);
|
|
924
|
+
if (Array.isArray(value)) {
|
|
925
|
+
const style = definition?.style || "form";
|
|
926
|
+
if (style === "form" && definition?.explode !== false) value.forEach((item) => params.append(name, String(item)));
|
|
927
|
+
else params.append(name, value.map(String).join(style === "spaceDelimited" ? " " : style === "pipeDelimited" ? "|" : ","));
|
|
928
|
+
} else {
|
|
929
|
+
params.append(name, String(value));
|
|
930
|
+
}
|
|
931
|
+
}
|
|
932
|
+
let body = input.body;
|
|
933
|
+
if (route.contentType === "multipart/form-data" && body !== void 0 && !(body instanceof FormData)) {
|
|
934
|
+
const form = new FormData();
|
|
935
|
+
for (const [name, value] of Object.entries(body)) {
|
|
936
|
+
if (value === void 0 || value === null) continue;
|
|
937
|
+
for (const item of Array.isArray(value) ? value : [value]) {
|
|
938
|
+
if (item instanceof Blob) form.append(name, item);
|
|
939
|
+
else form.append(name, typeof item === "object" ? JSON.stringify(item) : String(item));
|
|
940
|
+
}
|
|
941
|
+
}
|
|
942
|
+
body = form;
|
|
943
|
+
}
|
|
944
|
+
return this.http.request(route.method, path2, { params, headers, body, responseType: "auto" });
|
|
945
|
+
}
|
|
946
|
+
};
|
|
885
947
|
var DEFAULT_TOLERANCE_SECONDS = 300;
|
|
886
948
|
function parseSignatureHeader(rawSig) {
|
|
887
949
|
const versions = /* @__PURE__ */ new Map();
|
|
@@ -1175,6 +1237,6 @@ var Webhooks = {
|
|
|
1175
1237
|
verifyAdcpWebhook
|
|
1176
1238
|
};
|
|
1177
1239
|
|
|
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 };
|
|
1240
|
+
export { ADCP_WEBHOOK_SIGNING_TAG, ADVERTISER_BUYING_RESOURCE, AdvertiserBuyingClient, AdvertiserClient, 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 };
|
|
1179
1241
|
//# sourceMappingURL=index.mjs.map
|
|
1180
1242
|
//# sourceMappingURL=index.mjs.map
|