@adeli/sdk 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +30 -2
- package/dist/comments-C_vDnwix.d.cts +8268 -0
- package/dist/comments-Dx3195Ty.d.ts +8268 -0
- package/dist/helpers/index.cjs +482 -0
- package/dist/helpers/index.cjs.map +1 -0
- package/dist/helpers/index.d.cts +207 -0
- package/dist/helpers/index.d.ts +207 -0
- package/dist/helpers/index.js +471 -0
- package/dist/helpers/index.js.map +1 -0
- package/dist/index.cjs +878 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +360 -0
- package/dist/index.d.ts +360 -0
- package/dist/index.js +860 -0
- package/dist/index.js.map +1 -0
- package/dist/uploads-MGVSU99R.d.cts +100 -0
- package/dist/uploads-MGVSU99R.d.ts +100 -0
- package/dist/uploads.cjs +45 -0
- package/dist/uploads.cjs.map +1 -0
- package/dist/uploads.d.cts +1 -0
- package/dist/uploads.d.ts +1 -0
- package/dist/uploads.js +41 -0
- package/dist/uploads.js.map +1 -0
- package/docs/api-reference.md +72 -0
- package/docs/availability.md +26 -0
- package/docs/client.md +72 -0
- package/docs/maintenance.md +28 -0
- package/docs/publishing.md +39 -0
- package/docs/releasing.md +73 -0
- package/openapi/adeli.openapi.json +20505 -0
- package/openapi/docs-links.json +71 -0
- package/openapi/provenance.json +8 -0
- package/package.json +85 -4
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,878 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var path = require('path');
|
|
4
|
+
var fs = require('fs');
|
|
5
|
+
|
|
6
|
+
// src/core/duration.ts
|
|
7
|
+
var MAX_TIMER_DURATION_MS = 2147483647;
|
|
8
|
+
function isRepresentableTimerDuration(value) {
|
|
9
|
+
return Number.isFinite(value) && value > 0 && value <= MAX_TIMER_DURATION_MS;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
// src/core/errors.ts
|
|
13
|
+
var permissionProviders = /* @__PURE__ */ new Set(["instagram", "tiktok", "facebook", "whatsapp", "youtube", "x", "bluesky"]);
|
|
14
|
+
var permissionLists = ["requiredPermissions", "missingPermissions", "requiredResources", "missingResources"];
|
|
15
|
+
function record(value) {
|
|
16
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
17
|
+
}
|
|
18
|
+
function provider(value) {
|
|
19
|
+
return typeof value === "string" && permissionProviders.has(value);
|
|
20
|
+
}
|
|
21
|
+
function descriptor(value) {
|
|
22
|
+
return record(value) && typeof value.code === "string" && typeof value.label === "string";
|
|
23
|
+
}
|
|
24
|
+
function isPermissionRequiredDetails(value) {
|
|
25
|
+
try {
|
|
26
|
+
if (!record(value)) return false;
|
|
27
|
+
const known = /* @__PURE__ */ new Set(["provider", "accountId", "profileId", "capability", "reconnect", ...permissionLists]);
|
|
28
|
+
if (!Object.keys(value).some((key) => known.has(key))) return false;
|
|
29
|
+
for (const key of ["accountId", "profileId", "capability"]) if (key in value && typeof value[key] !== "string") return false;
|
|
30
|
+
if ("provider" in value && !provider(value.provider)) return false;
|
|
31
|
+
for (const key of permissionLists) {
|
|
32
|
+
if (key in value) {
|
|
33
|
+
const entries = value[key];
|
|
34
|
+
if (!Array.isArray(entries)) return false;
|
|
35
|
+
for (const entry of entries) if (!descriptor(entry)) return false;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
if ("reconnect" in value) {
|
|
39
|
+
const reconnect = value.reconnect;
|
|
40
|
+
if (!record(reconnect) || reconnect.action !== "restart_oauth") return false;
|
|
41
|
+
if ("method" in reconnect && reconnect.method !== "POST") return false;
|
|
42
|
+
if ("href" in reconnect && reconnect.href !== null && typeof reconnect.href !== "string") return false;
|
|
43
|
+
if ("provider" in reconnect && !provider(reconnect.provider)) return false;
|
|
44
|
+
if ("message" in reconnect && typeof reconnect.message !== "string") return false;
|
|
45
|
+
}
|
|
46
|
+
return true;
|
|
47
|
+
} catch {
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
var AdeliError = class extends Error {
|
|
52
|
+
name = "AdeliError";
|
|
53
|
+
constructor(message) {
|
|
54
|
+
super(message);
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
var ConfigurationError = class extends AdeliError {
|
|
58
|
+
name = "ConfigurationError";
|
|
59
|
+
};
|
|
60
|
+
var NetworkError = class extends AdeliError {
|
|
61
|
+
name = "NetworkError";
|
|
62
|
+
};
|
|
63
|
+
var RedirectError = class extends NetworkError {
|
|
64
|
+
name = "RedirectError";
|
|
65
|
+
};
|
|
66
|
+
var TimeoutError = class extends AdeliError {
|
|
67
|
+
name = "TimeoutError";
|
|
68
|
+
};
|
|
69
|
+
var CancellationError = class extends AdeliError {
|
|
70
|
+
name = "CancellationError";
|
|
71
|
+
};
|
|
72
|
+
var MalformedResponseError = class extends AdeliError {
|
|
73
|
+
name = "MalformedResponseError";
|
|
74
|
+
};
|
|
75
|
+
var AdeliApiError = class extends AdeliError {
|
|
76
|
+
name = "AdeliApiError";
|
|
77
|
+
status;
|
|
78
|
+
code;
|
|
79
|
+
details;
|
|
80
|
+
headers;
|
|
81
|
+
constructor(message, options) {
|
|
82
|
+
super(message);
|
|
83
|
+
this.status = options.status;
|
|
84
|
+
this.code = options.code ?? "api_error";
|
|
85
|
+
this.details = options.details;
|
|
86
|
+
this.headers = options.headers ?? new Headers();
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
var AuthenticationError = class extends AdeliApiError {
|
|
90
|
+
name = "AuthenticationError";
|
|
91
|
+
};
|
|
92
|
+
var ValidationError = class extends AdeliApiError {
|
|
93
|
+
name = "ValidationError";
|
|
94
|
+
};
|
|
95
|
+
var RateLimitError = class extends AdeliApiError {
|
|
96
|
+
name = "RateLimitError";
|
|
97
|
+
};
|
|
98
|
+
var PermissionRequiredError = class extends AdeliApiError {
|
|
99
|
+
name = "PermissionRequiredError";
|
|
100
|
+
};
|
|
101
|
+
function isAdeliApiError(error) {
|
|
102
|
+
return error instanceof AdeliApiError;
|
|
103
|
+
}
|
|
104
|
+
var VALIDATION_CODES = /* @__PURE__ */ new Set(["invalid_request", "invalid_profile", "invalid_redirect_uri"]);
|
|
105
|
+
var PERMISSION_CODES = /* @__PURE__ */ new Set(["permission_required"]);
|
|
106
|
+
var RATE_LIMIT_CODES = /* @__PURE__ */ new Set(["rate_limited", "rate_limit_exceeded", "quota_exhausted", "daily_quota_exceeded"]);
|
|
107
|
+
function apiError(message, options) {
|
|
108
|
+
if (options.status === 401 || options.code === "unauthorized") return new AuthenticationError(message, options);
|
|
109
|
+
if (options.status === 429 || options.code !== void 0 && RATE_LIMIT_CODES.has(options.code)) return new RateLimitError(message, options);
|
|
110
|
+
if (options.code !== void 0 && PERMISSION_CODES.has(options.code)) return new PermissionRequiredError(message, options);
|
|
111
|
+
if (options.code !== void 0 && VALIDATION_CODES.has(options.code)) return new ValidationError(message, options);
|
|
112
|
+
return new AdeliApiError(message, options);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// src/core/config.ts
|
|
116
|
+
var DEFAULT_BASE_URL = "https://app.tryadeli.com";
|
|
117
|
+
var LOCAL_HOSTS = /* @__PURE__ */ new Set(["localhost", "127.0.0.1", "[::1]", "::1"]);
|
|
118
|
+
function resolveConfig(options = {}) {
|
|
119
|
+
if (typeof window !== "undefined") throw new ConfigurationError("Adeli is a server-side SDK and cannot run in a browser");
|
|
120
|
+
const apiKey = options.apiKey ?? process.env.ADELI_API_KEY;
|
|
121
|
+
if (!apiKey || apiKey.trim() === "") throw new ConfigurationError("An Adeli API key is required (pass apiKey or set ADELI_API_KEY)");
|
|
122
|
+
if (/[\u0000-\u001f\u007f]/.test(apiKey)) throw new ConfigurationError("The Adeli API key must not contain control characters");
|
|
123
|
+
try {
|
|
124
|
+
new Headers({ authorization: `Bearer ${apiKey}` });
|
|
125
|
+
} catch {
|
|
126
|
+
throw new ConfigurationError("The Adeli API key must be a valid HTTP header value");
|
|
127
|
+
}
|
|
128
|
+
const baseURL = validateBaseURL(options.baseURL ?? DEFAULT_BASE_URL);
|
|
129
|
+
const timeoutMs = options.timeoutMs;
|
|
130
|
+
const maxRetries = options.maxRetries ?? 0;
|
|
131
|
+
if (timeoutMs !== void 0 && !isRepresentableTimerDuration(timeoutMs)) throw new ConfigurationError(`timeoutMs must be a positive finite number no greater than ${MAX_TIMER_DURATION_MS}ms`);
|
|
132
|
+
if (!Number.isInteger(maxRetries) || maxRetries < 0) throw new ConfigurationError("maxRetries must be a non-negative integer");
|
|
133
|
+
const fetchImpl = options.fetch ?? globalThis.fetch;
|
|
134
|
+
if (!fetchImpl) throw new ConfigurationError("A fetch implementation is required");
|
|
135
|
+
return { apiKey, baseURL, timeoutMs, maxRetries, fetch: fetchImpl };
|
|
136
|
+
}
|
|
137
|
+
function validateBaseURL(input) {
|
|
138
|
+
let url;
|
|
139
|
+
try {
|
|
140
|
+
url = new URL(input);
|
|
141
|
+
} catch {
|
|
142
|
+
throw new ConfigurationError("baseURL must be an absolute URL origin");
|
|
143
|
+
}
|
|
144
|
+
if (!["http:", "https:"].includes(url.protocol)) throw new ConfigurationError("baseURL must use http or https");
|
|
145
|
+
if (url.protocol !== "https:" && !LOCAL_HOSTS.has(url.hostname)) throw new ConfigurationError("HTTPS is required except for local development");
|
|
146
|
+
if (url.username || url.password || url.search || url.hash || url.pathname !== "/" && url.pathname !== "") throw new ConfigurationError("baseURL must be an origin without a path, query, fragment, or credentials");
|
|
147
|
+
return url.origin;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
// src/core/retry.ts
|
|
151
|
+
var TRANSIENT_STATUSES = /* @__PURE__ */ new Set([408, 429, 500, 502, 503, 504]);
|
|
152
|
+
function isRetryableStatus(status) {
|
|
153
|
+
return TRANSIENT_STATUSES.has(status);
|
|
154
|
+
}
|
|
155
|
+
function parseRetryAfter(value, now = Date.now()) {
|
|
156
|
+
if (!value) return void 0;
|
|
157
|
+
const seconds = Number(value);
|
|
158
|
+
if (Number.isFinite(seconds) && seconds >= 0) return seconds * 1e3;
|
|
159
|
+
const date = Date.parse(value);
|
|
160
|
+
return Number.isFinite(date) ? Math.max(0, date - now) : void 0;
|
|
161
|
+
}
|
|
162
|
+
function canRetry(operation, idempotencyKey) {
|
|
163
|
+
return operation.retry === "safe-read" || operation.retry === "profile-create" && idempotencyKey !== void 0 && idempotencyKey.trim() !== "";
|
|
164
|
+
}
|
|
165
|
+
function backoffMs(attempt, retryAfter, random = Math.random()) {
|
|
166
|
+
if (retryAfter !== void 0) return retryAfter;
|
|
167
|
+
return Math.min(3e4, 250 * 2 ** attempt) + Math.floor(random * 100);
|
|
168
|
+
}
|
|
169
|
+
async function sleepWithSignal(ms, signal) {
|
|
170
|
+
if (signal.aborted) throw new CancellationError("The Adeli request was cancelled");
|
|
171
|
+
await new Promise((resolve, reject) => {
|
|
172
|
+
let settled = false;
|
|
173
|
+
const finish = (callback) => {
|
|
174
|
+
if (settled) return;
|
|
175
|
+
settled = true;
|
|
176
|
+
clearTimeout(timer);
|
|
177
|
+
signal.removeEventListener("abort", onAbort);
|
|
178
|
+
callback();
|
|
179
|
+
};
|
|
180
|
+
const onAbort = () => finish(() => reject(new CancellationError("The Adeli request was cancelled")));
|
|
181
|
+
const timer = setTimeout(() => finish(resolve), ms);
|
|
182
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
function retryableNetworkError(error) {
|
|
186
|
+
return error instanceof NetworkError && !(error instanceof RedirectError);
|
|
187
|
+
}
|
|
188
|
+
function isDailyQuotaExhausted(code) {
|
|
189
|
+
const normalized = code.toLowerCase().replace(/[-\s]/g, "_");
|
|
190
|
+
return normalized === "quota_exhausted" || normalized === "daily_quota_exceeded" || normalized.includes("daily") && normalized.includes("quota");
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
// src/core/transport.ts
|
|
194
|
+
function isMultipartBody(value) {
|
|
195
|
+
return value !== null && typeof value === "object" && "stream" in value && "contentType" in value && typeof value.stream === "object" && typeof value.contentType === "string";
|
|
196
|
+
}
|
|
197
|
+
function pathSegment(value, name) {
|
|
198
|
+
const segment = String(value);
|
|
199
|
+
let decoded = segment;
|
|
200
|
+
try {
|
|
201
|
+
decoded = decodeURIComponent(segment);
|
|
202
|
+
} catch {
|
|
203
|
+
}
|
|
204
|
+
if (decoded === "." || decoded === "..") throw new TypeError(`Invalid path parameter ${name}: dot segments are not allowed`);
|
|
205
|
+
return encodeURIComponent(segment);
|
|
206
|
+
}
|
|
207
|
+
function buildURL(baseURL, template, path, query) {
|
|
208
|
+
const pathValues = path;
|
|
209
|
+
const rendered = template.replace(/\{([^}]+)\}/g, (_whole, name) => {
|
|
210
|
+
const value = pathValues?.[name];
|
|
211
|
+
if (value === void 0) throw new TypeError(`Missing path parameter: ${name}`);
|
|
212
|
+
return pathSegment(value, name);
|
|
213
|
+
});
|
|
214
|
+
const url = new URL(`/api/v1${rendered.startsWith("/") ? rendered : `/${rendered}`}`, `${baseURL}/`);
|
|
215
|
+
if (query) for (const [key, value] of Object.entries(query)) {
|
|
216
|
+
if (value === void 0 || value === null) continue;
|
|
217
|
+
if (/\u0000|\r|\n/.test(key)) throw new TypeError("Invalid query parameter name");
|
|
218
|
+
for (const item of Array.isArray(value) ? value : [value]) url.searchParams.append(key, String(item));
|
|
219
|
+
}
|
|
220
|
+
return url;
|
|
221
|
+
}
|
|
222
|
+
function redact(value, secret) {
|
|
223
|
+
if (typeof value === "string") return value.split(secret).join("[REDACTED]");
|
|
224
|
+
if (Array.isArray(value)) return value.map((item) => redact(item, secret));
|
|
225
|
+
if (value !== null && typeof value === "object") {
|
|
226
|
+
return Object.fromEntries(Object.entries(value).map(([key, item]) => [key.split(secret).join("[REDACTED]"), redact(item, secret)]));
|
|
227
|
+
}
|
|
228
|
+
return value;
|
|
229
|
+
}
|
|
230
|
+
async function readResponseText(response, signal) {
|
|
231
|
+
if (response.status === 204) return "";
|
|
232
|
+
if (signal.aborted) throw new DOMException("aborted", "AbortError");
|
|
233
|
+
const body = response.body;
|
|
234
|
+
if (!body) return "";
|
|
235
|
+
const reader = body.getReader();
|
|
236
|
+
const decoder = new TextDecoder();
|
|
237
|
+
return new Promise((resolve, reject) => {
|
|
238
|
+
let settled = false;
|
|
239
|
+
const chunks = [];
|
|
240
|
+
const finish = (callback) => {
|
|
241
|
+
if (settled) return;
|
|
242
|
+
settled = true;
|
|
243
|
+
signal.removeEventListener("abort", onAbort);
|
|
244
|
+
callback();
|
|
245
|
+
};
|
|
246
|
+
const onAbort = () => {
|
|
247
|
+
void reader.cancel().catch(() => void 0);
|
|
248
|
+
finish(() => reject(new DOMException("aborted", "AbortError")));
|
|
249
|
+
};
|
|
250
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
251
|
+
const read = async () => {
|
|
252
|
+
try {
|
|
253
|
+
while (!settled) {
|
|
254
|
+
const chunk = await reader.read();
|
|
255
|
+
if (settled) return;
|
|
256
|
+
if (chunk.done) {
|
|
257
|
+
finish(() => resolve(chunks.join("") + decoder.decode()));
|
|
258
|
+
return;
|
|
259
|
+
}
|
|
260
|
+
chunks.push(decoder.decode(chunk.value, { stream: true }));
|
|
261
|
+
}
|
|
262
|
+
} catch (error) {
|
|
263
|
+
finish(() => reject(error));
|
|
264
|
+
}
|
|
265
|
+
};
|
|
266
|
+
void read();
|
|
267
|
+
});
|
|
268
|
+
}
|
|
269
|
+
var Transport = class {
|
|
270
|
+
constructor(config) {
|
|
271
|
+
this.config = config;
|
|
272
|
+
}
|
|
273
|
+
/** Prevent client configuration, especially apiKey, from leaking through JSON serialization. */
|
|
274
|
+
toJSON() {
|
|
275
|
+
return {};
|
|
276
|
+
}
|
|
277
|
+
/** Send raw bytes to a one-object presigned URL without leaking the Adeli API key. */
|
|
278
|
+
async upload(url, method, headers, body, options = {}) {
|
|
279
|
+
const timeoutMs = options.timeoutMs ?? this.config.timeoutMs ?? 6e4;
|
|
280
|
+
if (!isRepresentableTimerDuration(timeoutMs)) throw new TypeError(`timeoutMs must be a positive finite number no greater than ${MAX_TIMER_DURATION_MS}ms`);
|
|
281
|
+
if (options.signal?.aborted) throw new CancellationError("The media upload was cancelled");
|
|
282
|
+
const controller = new AbortController();
|
|
283
|
+
let timedOut = false;
|
|
284
|
+
let cancelled = false;
|
|
285
|
+
const onAbort = () => {
|
|
286
|
+
cancelled = true;
|
|
287
|
+
controller.abort();
|
|
288
|
+
};
|
|
289
|
+
options.signal?.addEventListener("abort", onAbort, { once: true });
|
|
290
|
+
const timer = setTimeout(() => {
|
|
291
|
+
timedOut = true;
|
|
292
|
+
controller.abort();
|
|
293
|
+
}, timeoutMs);
|
|
294
|
+
try {
|
|
295
|
+
for (let attempt = 0; ; attempt += 1) {
|
|
296
|
+
try {
|
|
297
|
+
const response = await this.config.fetch(url, { method, headers: new Headers(headers), body, signal: controller.signal, redirect: "error" });
|
|
298
|
+
if (response.redirected) throw new RedirectError("Adeli refused a media upload redirect");
|
|
299
|
+
if (response.ok) return;
|
|
300
|
+
if (attempt < this.config.maxRetries && response.status >= 500) {
|
|
301
|
+
await sleepWithSignal(backoffMs(attempt, parseRetryAfter(response.headers.get("retry-after"))), controller.signal);
|
|
302
|
+
continue;
|
|
303
|
+
}
|
|
304
|
+
throw new NetworkError(`Direct media upload failed with status ${response.status}`);
|
|
305
|
+
} catch (error) {
|
|
306
|
+
if (timedOut) throw new TimeoutError(`Media upload exceeded its ${timeoutMs}ms deadline`);
|
|
307
|
+
if (cancelled || error instanceof Error && error.name === "AbortError") throw new CancellationError("The media upload was cancelled");
|
|
308
|
+
if (attempt < this.config.maxRetries && retryableNetworkError(error)) {
|
|
309
|
+
await sleepWithSignal(backoffMs(attempt), controller.signal);
|
|
310
|
+
continue;
|
|
311
|
+
}
|
|
312
|
+
throw error;
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
} finally {
|
|
316
|
+
clearTimeout(timer);
|
|
317
|
+
options.signal?.removeEventListener("abort", onAbort);
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
async request(request) {
|
|
321
|
+
const timeoutMs = request.timeoutMs ?? this.config.timeoutMs ?? request.operation.defaultTimeoutMs ?? 6e4;
|
|
322
|
+
if (!isRepresentableTimerDuration(timeoutMs)) throw new TypeError(`timeoutMs must be a positive finite number no greater than ${MAX_TIMER_DURATION_MS}ms`);
|
|
323
|
+
if (request.idempotencyKey !== void 0 && (request.idempotencyKey.trim() === "" || /[\u0000-\u001f\u007f\r\n]/.test(request.idempotencyKey))) {
|
|
324
|
+
throw new TypeError("idempotencyKey must be a nonblank valid HTTP header value");
|
|
325
|
+
}
|
|
326
|
+
if (request.signal?.aborted) throw new CancellationError("The Adeli request was cancelled");
|
|
327
|
+
const deadline = Date.now() + timeoutMs;
|
|
328
|
+
const controller = new AbortController();
|
|
329
|
+
let timedOut = false;
|
|
330
|
+
let cancelled = false;
|
|
331
|
+
const onAbort = () => {
|
|
332
|
+
cancelled = true;
|
|
333
|
+
controller.abort();
|
|
334
|
+
};
|
|
335
|
+
request.signal?.addEventListener("abort", onAbort, { once: true });
|
|
336
|
+
const timer = setTimeout(() => {
|
|
337
|
+
timedOut = true;
|
|
338
|
+
controller.abort();
|
|
339
|
+
}, timeoutMs);
|
|
340
|
+
try {
|
|
341
|
+
const maxAttempts = canRetry(request.operation, request.idempotencyKey) ? this.config.maxRetries + 1 : 1;
|
|
342
|
+
let attempt = 0;
|
|
343
|
+
while (true) {
|
|
344
|
+
try {
|
|
345
|
+
const response = await this.perform(request, controller.signal);
|
|
346
|
+
if (response.ok) return { data: response.data, status: response.status, headers: response.headers };
|
|
347
|
+
if (attempt + 1 < maxAttempts && isRetryableStatus(response.status) && !isDailyQuotaExhausted(response.error.code) && Date.now() < deadline) {
|
|
348
|
+
const delay = backoffMs(attempt, parseRetryAfter(response.headers.get("retry-after")));
|
|
349
|
+
if (Date.now() + delay >= deadline) throw response.error;
|
|
350
|
+
await sleepWithSignal(delay, controller.signal);
|
|
351
|
+
attempt++;
|
|
352
|
+
continue;
|
|
353
|
+
}
|
|
354
|
+
throw response.error;
|
|
355
|
+
} catch (error) {
|
|
356
|
+
if (timedOut) throw new TimeoutError(`Adeli request exceeded its ${timeoutMs}ms deadline; the remote write outcome may be unknown`);
|
|
357
|
+
if (cancelled) throw new CancellationError("The Adeli request was cancelled");
|
|
358
|
+
if (error instanceof Error && error.name === "AbortError") throw new CancellationError("The Adeli request was cancelled");
|
|
359
|
+
if (attempt + 1 < maxAttempts && retryableNetworkError(error) && Date.now() < deadline) {
|
|
360
|
+
const delay = backoffMs(attempt);
|
|
361
|
+
if (Date.now() + delay >= deadline) throw error;
|
|
362
|
+
await sleepWithSignal(delay, controller.signal);
|
|
363
|
+
attempt++;
|
|
364
|
+
continue;
|
|
365
|
+
}
|
|
366
|
+
throw error;
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
} finally {
|
|
370
|
+
clearTimeout(timer);
|
|
371
|
+
request.signal?.removeEventListener("abort", onAbort);
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
async perform(request, signal) {
|
|
375
|
+
const url = buildURL(this.config.baseURL, request.operation.path, request.path, request.query);
|
|
376
|
+
const headers = new Headers({ authorization: `Bearer ${this.config.apiKey}`, accept: "application/json" });
|
|
377
|
+
let encodedBody;
|
|
378
|
+
let duplex;
|
|
379
|
+
if (request.body !== void 0) {
|
|
380
|
+
if (isMultipartBody(request.body)) {
|
|
381
|
+
encodedBody = request.body.stream;
|
|
382
|
+
headers.set("content-type", request.body.contentType);
|
|
383
|
+
duplex = "half";
|
|
384
|
+
} else if (typeof FormData !== "undefined" && request.body instanceof FormData) encodedBody = request.body;
|
|
385
|
+
else if (typeof Blob !== "undefined" && request.body instanceof Blob) encodedBody = request.body;
|
|
386
|
+
else {
|
|
387
|
+
headers.set("content-type", "application/json");
|
|
388
|
+
encodedBody = JSON.stringify(request.body);
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
if (request.idempotencyKey !== void 0) headers.set("idempotency-key", request.idempotencyKey);
|
|
392
|
+
let response;
|
|
393
|
+
try {
|
|
394
|
+
response = await this.config.fetch(url, { method: request.operation.method, headers, signal, redirect: "error", ...encodedBody === void 0 ? {} : { body: encodedBody }, ...duplex === void 0 ? {} : { duplex } });
|
|
395
|
+
} catch (error) {
|
|
396
|
+
if (signal.aborted || error instanceof Error && error.name === "AbortError") throw error;
|
|
397
|
+
throw new NetworkError("Unable to connect to Adeli");
|
|
398
|
+
}
|
|
399
|
+
if (response.redirected) throw new RedirectError("Adeli refused a redirect");
|
|
400
|
+
let text;
|
|
401
|
+
try {
|
|
402
|
+
text = await readResponseText(response, signal);
|
|
403
|
+
} catch (error) {
|
|
404
|
+
if (signal.aborted || error instanceof Error && error.name === "AbortError") throw error;
|
|
405
|
+
throw new NetworkError("Unable to read the Adeli response");
|
|
406
|
+
}
|
|
407
|
+
let data;
|
|
408
|
+
if (response.status !== 204) {
|
|
409
|
+
if (text === "") {
|
|
410
|
+
if (response.ok) throw new MalformedResponseError("Adeli returned an empty response where JSON was required");
|
|
411
|
+
} else {
|
|
412
|
+
try {
|
|
413
|
+
data = JSON.parse(text);
|
|
414
|
+
} catch {
|
|
415
|
+
if (response.ok) throw new MalformedResponseError("Adeli returned malformed JSON");
|
|
416
|
+
data = text;
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
if (!response.ok) {
|
|
421
|
+
const envelope = data !== null && typeof data === "object" && !Array.isArray(data) ? data.error : void 0;
|
|
422
|
+
const errorBody = envelope !== null && typeof envelope === "object" && !Array.isArray(envelope) ? envelope : void 0;
|
|
423
|
+
const code = typeof errorBody?.code === "string" ? errorBody.code : void 0;
|
|
424
|
+
const redactedCode = code === void 0 ? void 0 : String(redact(code, this.config.apiKey));
|
|
425
|
+
const message = typeof errorBody?.message === "string" ? errorBody.message : `Adeli request failed with status ${response.status}`;
|
|
426
|
+
const hasDetails = errorBody !== void 0 && Object.prototype.hasOwnProperty.call(errorBody, "details");
|
|
427
|
+
const details = hasDetails ? errorBody.details : redact(data, this.config.apiKey);
|
|
428
|
+
return {
|
|
429
|
+
ok: false,
|
|
430
|
+
data: void 0,
|
|
431
|
+
status: response.status,
|
|
432
|
+
headers: response.headers,
|
|
433
|
+
error: apiError(String(redact(message, this.config.apiKey)), { status: response.status, details: redact(details, this.config.apiKey), headers: response.headers, ...redactedCode === void 0 ? {} : { code: redactedCode } })
|
|
434
|
+
};
|
|
435
|
+
}
|
|
436
|
+
return { ok: true, data: response.status === 204 ? void 0 : data, status: response.status, headers: response.headers };
|
|
437
|
+
}
|
|
438
|
+
};
|
|
439
|
+
|
|
440
|
+
// src/operations.ts
|
|
441
|
+
var operations = {
|
|
442
|
+
getMe: { operationId: "getMe", method: "GET", path: "/me", retry: "safe-read" },
|
|
443
|
+
listProfiles: { operationId: "listProfiles", method: "GET", path: "/profiles", retry: "safe-read" },
|
|
444
|
+
createProfile: { operationId: "createProfile", method: "POST", path: "/profiles", retry: "profile-create" },
|
|
445
|
+
getProfile: { operationId: "getProfile", method: "GET", path: "/profiles/{profileId}", retry: "safe-read" },
|
|
446
|
+
updateProfile: { operationId: "updateProfile", method: "PUT", path: "/profiles/{profileId}", retry: "never" },
|
|
447
|
+
deleteProfile: { operationId: "deleteProfile", method: "DELETE", path: "/profiles/{profileId}", retry: "never" },
|
|
448
|
+
startConnection: { operationId: "startConnection", method: "POST", path: "/profiles/{profileId}/connect", retry: "never" },
|
|
449
|
+
getConnection: { operationId: "getConnection", method: "GET", path: "/profiles/{profileId}/connect/{connectionSessionId}", retry: "safe-read" },
|
|
450
|
+
listAccounts: { operationId: "listAccounts", method: "GET", path: "/accounts", retry: "safe-read" },
|
|
451
|
+
listProfileAccounts: { operationId: "listProfileAccounts", method: "GET", path: "/profiles/{profileId}/accounts", retry: "safe-read" },
|
|
452
|
+
getAccount: { operationId: "getAccount", method: "GET", path: "/profiles/{profileId}/accounts/{accountId}", retry: "safe-read" },
|
|
453
|
+
updateAccount: { operationId: "updateAccount", method: "PATCH", path: "/profiles/{profileId}/accounts/{accountId}", retry: "never" },
|
|
454
|
+
disconnectAccount: { operationId: "disconnectAccount", method: "DELETE", path: "/profiles/{profileId}/accounts/{accountId}", retry: "never" },
|
|
455
|
+
refreshAccounts: { operationId: "refreshAccounts", method: "POST", path: "/profiles/{profileId}/accounts/refresh", retry: "never" },
|
|
456
|
+
listPosts: { operationId: "listPosts", method: "GET", path: "/posts", retry: "never" },
|
|
457
|
+
createMediaUploads: { operationId: "createMediaUploads", method: "POST", path: "/media/uploads", retry: "never" },
|
|
458
|
+
createPost: { operationId: "createPost", method: "POST", path: "/posts", retry: "never", defaultTimeoutMs: 3e5 },
|
|
459
|
+
uploadYouTubeVideo: { operationId: "uploadYouTubeVideo", method: "POST", path: "/posts/youtube", retry: "never", defaultTimeoutMs: 3e5 },
|
|
460
|
+
deleteXPost: { operationId: "deleteXPost", method: "DELETE", path: "/posts/x/{postId}", retry: "never" },
|
|
461
|
+
deleteBlueskyPost: { operationId: "deleteBlueskyPost", method: "DELETE", path: "/posts/bluesky/{postId}", retry: "never" },
|
|
462
|
+
getInstagramPostStatus: { operationId: "getInstagramPostStatus", method: "GET", path: "/posts/instagram/status", retry: "safe-read" },
|
|
463
|
+
getFacebookPostStatus: { operationId: "getFacebookPostStatus", method: "GET", path: "/posts/facebook/status", retry: "safe-read" },
|
|
464
|
+
getTikTokPostStatus: { operationId: "getTikTokPostStatus", method: "GET", path: "/posts/tiktok/status", retry: "safe-read" },
|
|
465
|
+
getTikTokCreatorInfo: { operationId: "getTikTokCreatorInfo", method: "GET", path: "/posts/tiktok/creator-info", retry: "safe-read" },
|
|
466
|
+
getYouTubeVideoStatus: { operationId: "getYouTubeVideoStatus", method: "GET", path: "/posts/youtube/status", retry: "safe-read" },
|
|
467
|
+
listComments: { operationId: "listComments", method: "GET", path: "/comments", retry: "safe-read" },
|
|
468
|
+
createComment: { operationId: "createComment", method: "POST", path: "/comments", retry: "never" },
|
|
469
|
+
updateComment: { operationId: "updateComment", method: "PATCH", path: "/comments/{commentId}", retry: "never" },
|
|
470
|
+
deleteComment: { operationId: "deleteComment", method: "DELETE", path: "/comments/{commentId}", retry: "never" },
|
|
471
|
+
listMessages: { operationId: "listMessages", method: "GET", path: "/messages", retry: "safe-read" },
|
|
472
|
+
sendMessage: { operationId: "sendMessage", method: "POST", path: "/messages", retry: "never" },
|
|
473
|
+
sendInstagramMessage: { operationId: "sendInstagramMessage", method: "POST", path: "/messages/instagram", retry: "never" },
|
|
474
|
+
getInstagramAccountInsights: { operationId: "getInstagramAccountInsights", method: "GET", path: "/analytics/instagram/account-insights", retry: "safe-read" },
|
|
475
|
+
getFacebookPageMetrics: { operationId: "getFacebookPageMetrics", method: "GET", path: "/analytics/facebook/page-metrics", retry: "safe-read" },
|
|
476
|
+
getTikTokAccountAnalytics: { operationId: "getTikTokAccountAnalytics", method: "GET", path: "/analytics/tiktok/account-analytics", retry: "safe-read" },
|
|
477
|
+
getTikTokAccountInsights: { operationId: "getTikTokAccountInsights", method: "GET", path: "/analytics/tiktok/account-insights", retry: "safe-read" },
|
|
478
|
+
getTikTokVideoInsights: { operationId: "getTikTokVideoInsights", method: "GET", path: "/analytics/tiktok/video-insights", retry: "safe-read" },
|
|
479
|
+
getYouTubeChannelInsights: { operationId: "getYouTubeChannelInsights", method: "GET", path: "/analytics/youtube/channel-insights", retry: "safe-read" },
|
|
480
|
+
getYouTubeVideoInsights: { operationId: "getYouTubeVideoInsights", method: "GET", path: "/analytics/youtube/video-insights", retry: "safe-read" },
|
|
481
|
+
listAdBusinesses: { operationId: "listAdBusinesses", method: "GET", path: "/ads/businesses", retry: "safe-read" },
|
|
482
|
+
listAdAccounts: { operationId: "listAdAccounts", method: "GET", path: "/ads/accounts", retry: "safe-read" },
|
|
483
|
+
createAdAccount: { operationId: "createAdAccount", method: "POST", path: "/ads/accounts", retry: "never" },
|
|
484
|
+
getAdAccount: { operationId: "getAdAccount", method: "GET", path: "/ads/accounts/{adAccountId}", retry: "safe-read" },
|
|
485
|
+
updateAdAccount: { operationId: "updateAdAccount", method: "PATCH", path: "/ads/accounts/{adAccountId}", retry: "never" },
|
|
486
|
+
getAdTree: { operationId: "getAdTree", method: "GET", path: "/ads/tree", retry: "safe-read" },
|
|
487
|
+
getAdInsights: { operationId: "getAdInsights", method: "GET", path: "/ads/insights", retry: "safe-read" },
|
|
488
|
+
listAdLeads: { operationId: "listAdLeads", method: "GET", path: "/ads/leads", retry: "safe-read" },
|
|
489
|
+
createCampaign: { operationId: "createCampaign", method: "POST", path: "/ads/campaigns", retry: "never" },
|
|
490
|
+
deleteCampaign: { operationId: "deleteCampaign", method: "DELETE", path: "/ads/campaigns/{campaignId}", retry: "never" },
|
|
491
|
+
setAdStatus: { operationId: "setAdStatus", method: "PUT", path: "/ads/status", retry: "never" },
|
|
492
|
+
updateAdGroup: { operationId: "updateAdGroup", method: "PATCH", path: "/ads/ad-groups/{adGroupId}", retry: "never" },
|
|
493
|
+
listAdTargeting: { operationId: "listAdTargeting", method: "GET", path: "/ads/targeting", retry: "safe-read" },
|
|
494
|
+
listAdIdentities: { operationId: "listAdIdentities", method: "GET", path: "/ads/identities", retry: "safe-read" },
|
|
495
|
+
createAdIdentity: { operationId: "createAdIdentity", method: "POST", path: "/ads/identities", retry: "never" },
|
|
496
|
+
getXUsage: { operationId: "getXUsage", method: "GET", path: "/usage/x", retry: "safe-read" },
|
|
497
|
+
listWebhooks: { operationId: "listWebhooks", method: "GET", path: "/webhooks", retry: "safe-read" },
|
|
498
|
+
createWebhook: { operationId: "createWebhook", method: "POST", path: "/webhooks", retry: "never" },
|
|
499
|
+
deleteWebhook: { operationId: "deleteWebhook", method: "DELETE", path: "/webhooks/{webhookId}", retry: "never" }
|
|
500
|
+
};
|
|
501
|
+
|
|
502
|
+
// src/resources/accounts.ts
|
|
503
|
+
var AccountsResource = class {
|
|
504
|
+
constructor(transport) {
|
|
505
|
+
this.transport = transport;
|
|
506
|
+
}
|
|
507
|
+
listAccounts(args = {}, options = {}) {
|
|
508
|
+
return this.transport.request({ operation: operations.listAccounts, query: args.query, signal: options.signal, timeoutMs: options.timeoutMs });
|
|
509
|
+
}
|
|
510
|
+
listProfileAccounts(args, options = {}) {
|
|
511
|
+
return this.transport.request({ operation: operations.listProfileAccounts, path: args.path, signal: options.signal, timeoutMs: options.timeoutMs });
|
|
512
|
+
}
|
|
513
|
+
getAccount(args, options = {}) {
|
|
514
|
+
return this.transport.request({ operation: operations.getAccount, path: args.path, signal: options.signal, timeoutMs: options.timeoutMs });
|
|
515
|
+
}
|
|
516
|
+
updateAccount(args, options = {}) {
|
|
517
|
+
return this.transport.request({ operation: operations.updateAccount, path: args.path, body: args.body, signal: options.signal, timeoutMs: options.timeoutMs });
|
|
518
|
+
}
|
|
519
|
+
disconnectAccount(args, options = {}) {
|
|
520
|
+
return this.transport.request({ operation: operations.disconnectAccount, path: args.path, signal: options.signal, timeoutMs: options.timeoutMs });
|
|
521
|
+
}
|
|
522
|
+
refreshAccounts(args, options = {}) {
|
|
523
|
+
return this.transport.request({ operation: operations.refreshAccounts, path: args.path, signal: options.signal, timeoutMs: options.timeoutMs });
|
|
524
|
+
}
|
|
525
|
+
};
|
|
526
|
+
|
|
527
|
+
// src/resources/profiles.ts
|
|
528
|
+
var ProfilesResource = class {
|
|
529
|
+
constructor(transport) {
|
|
530
|
+
this.transport = transport;
|
|
531
|
+
}
|
|
532
|
+
listProfiles(_args = {}, options = {}) {
|
|
533
|
+
return this.transport.request({ operation: operations.listProfiles, signal: options.signal, timeoutMs: options.timeoutMs });
|
|
534
|
+
}
|
|
535
|
+
createProfile(args, options = {}) {
|
|
536
|
+
return this.transport.request({ operation: operations.createProfile, body: args.body, idempotencyKey: options.idempotencyKey, signal: options.signal, timeoutMs: options.timeoutMs });
|
|
537
|
+
}
|
|
538
|
+
getProfile(args, options = {}) {
|
|
539
|
+
return this.transport.request({ operation: operations.getProfile, path: args.path, signal: options.signal, timeoutMs: options.timeoutMs });
|
|
540
|
+
}
|
|
541
|
+
updateProfile(args, options = {}) {
|
|
542
|
+
return this.transport.request({ operation: operations.updateProfile, path: args.path, body: args.body, signal: options.signal, timeoutMs: options.timeoutMs });
|
|
543
|
+
}
|
|
544
|
+
deleteProfile(args, options = {}) {
|
|
545
|
+
return this.transport.request({ operation: operations.deleteProfile, path: args.path, signal: options.signal, timeoutMs: options.timeoutMs });
|
|
546
|
+
}
|
|
547
|
+
startConnection(args, options = {}) {
|
|
548
|
+
return this.transport.request({ operation: operations.startConnection, path: args.path, body: args.body, signal: options.signal, timeoutMs: options.timeoutMs });
|
|
549
|
+
}
|
|
550
|
+
getConnection(args, options = {}) {
|
|
551
|
+
return this.transport.request({ operation: operations.getConnection, path: args.path, signal: options.signal, timeoutMs: options.timeoutMs });
|
|
552
|
+
}
|
|
553
|
+
};
|
|
554
|
+
async function blobFromPath(path, options = {}) {
|
|
555
|
+
return fs.openAsBlob(path, options.contentType === void 0 ? void 0 : { type: options.contentType });
|
|
556
|
+
}
|
|
557
|
+
async function putDirectUploads(transport, descriptors, files, options = {}) {
|
|
558
|
+
if (descriptors.length !== files.length) throw new TypeError("The media upload manifest was incomplete");
|
|
559
|
+
const byId = new Map(descriptors.map((descriptor2) => [descriptor2.clientId, descriptor2]));
|
|
560
|
+
const concurrency = options.concurrency ?? 3;
|
|
561
|
+
if (!Number.isSafeInteger(concurrency) || concurrency < 1 || concurrency > 10) throw new TypeError("concurrency must be an integer between 1 and 10");
|
|
562
|
+
const total = files.reduce((sum, file) => sum + file.size, 0);
|
|
563
|
+
let completedBytes = 0;
|
|
564
|
+
let completedFiles = 0;
|
|
565
|
+
const result = new Array(files.length);
|
|
566
|
+
let next = 0;
|
|
567
|
+
const worker = async () => {
|
|
568
|
+
while (next < files.length) {
|
|
569
|
+
const index = next++;
|
|
570
|
+
const descriptor2 = byId.get(String(index));
|
|
571
|
+
const file = files[index];
|
|
572
|
+
if (!descriptor2 || !file) throw new TypeError("The media upload manifest was incomplete");
|
|
573
|
+
await transport.upload(descriptor2.url, descriptor2.method, descriptor2.headers, file, options);
|
|
574
|
+
completedBytes += file.size;
|
|
575
|
+
completedFiles += 1;
|
|
576
|
+
options.onProgress?.({ loaded: completedBytes, total, completedFiles, totalFiles: files.length });
|
|
577
|
+
result[index] = descriptor2.uploadId;
|
|
578
|
+
}
|
|
579
|
+
};
|
|
580
|
+
await Promise.all(Array.from({ length: Math.min(concurrency, files.length) }, () => worker()));
|
|
581
|
+
return result;
|
|
582
|
+
}
|
|
583
|
+
async function fileFromPath(path$1, options = {}) {
|
|
584
|
+
const blob = await blobFromPath(path$1, options);
|
|
585
|
+
return new File([blob], options.name ?? path.basename(path$1), options.contentType === void 0 ? void 0 : { type: options.contentType });
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
// src/resources/posts.ts
|
|
589
|
+
function isBlob(value) {
|
|
590
|
+
return typeof Blob !== "undefined" && value instanceof Blob;
|
|
591
|
+
}
|
|
592
|
+
function collectFiles(value, key, collected) {
|
|
593
|
+
if (isBlob(value)) {
|
|
594
|
+
const reference = { upload_id: "" };
|
|
595
|
+
collected.push({ file: value, reference, purpose: key === "thumbnail" ? "youtube_thumbnail" : "post_media" });
|
|
596
|
+
return reference;
|
|
597
|
+
}
|
|
598
|
+
if (Array.isArray(value)) return value.map((item) => collectFiles(item, key, collected));
|
|
599
|
+
if (value !== null && typeof value === "object") {
|
|
600
|
+
const record2 = value;
|
|
601
|
+
if (isBlob(record2.file)) {
|
|
602
|
+
const reference = { upload_id: "" };
|
|
603
|
+
collected.push({ file: record2.file, reference, purpose: key === "thumbnail" ? "youtube_thumbnail" : "post_media" });
|
|
604
|
+
const metadata = Object.fromEntries(Object.entries(record2).filter(([name]) => name !== "file"));
|
|
605
|
+
return Object.assign(reference, metadata);
|
|
606
|
+
}
|
|
607
|
+
return Object.fromEntries(Object.entries(record2).map(([name, item]) => [name, collectFiles(item, name, collected)]));
|
|
608
|
+
}
|
|
609
|
+
return value;
|
|
610
|
+
}
|
|
611
|
+
var PostsResource = class {
|
|
612
|
+
constructor(transport) {
|
|
613
|
+
this.transport = transport;
|
|
614
|
+
}
|
|
615
|
+
listPosts(args = {}, options = {}) {
|
|
616
|
+
return this.transport.request({ operation: operations.listPosts, query: args.query, signal: options.signal, timeoutMs: options.timeoutMs });
|
|
617
|
+
}
|
|
618
|
+
createMediaUploads(args, options = {}) {
|
|
619
|
+
return this.transport.request({ operation: operations.createMediaUploads, body: args.body, signal: options.signal, timeoutMs: options.timeoutMs });
|
|
620
|
+
}
|
|
621
|
+
async profileIdFor(accountId, explicit, options) {
|
|
622
|
+
if (explicit) return explicit;
|
|
623
|
+
const response = await this.transport.request({ operation: operations.listAccounts, query: { accountId }, signal: options.signal, timeoutMs: options.timeoutMs });
|
|
624
|
+
const account = response.data.accounts?.[0];
|
|
625
|
+
if (!account?.profileId) throw new TypeError("A profileId is required to upload media for this account");
|
|
626
|
+
return account.profileId;
|
|
627
|
+
}
|
|
628
|
+
async stageBody(body, options) {
|
|
629
|
+
const files = [];
|
|
630
|
+
const stagedBody = collectFiles(body, void 0, files);
|
|
631
|
+
if (!files.length) return stagedBody;
|
|
632
|
+
const platform = body.platform;
|
|
633
|
+
if (!["instagram", "facebook", "tiktok", "youtube", "x", "bluesky"].includes(platform)) throw new TypeError("A supported platform is required for media upload");
|
|
634
|
+
const accountId = body.accountId;
|
|
635
|
+
if (typeof accountId !== "string") throw new TypeError("accountId is required for media upload");
|
|
636
|
+
const profileId = await this.profileIdFor(accountId, typeof body.profileId === "string" ? body.profileId : void 0, options);
|
|
637
|
+
const declaration = files.map(({ file, purpose }, index) => {
|
|
638
|
+
if (!file.type) throw new TypeError("Every uploaded Blob needs a content type");
|
|
639
|
+
return { clientId: String(index), purpose, contentType: file.type, size: file.size, ..."name" in file && typeof file.name === "string" ? { filename: file.name } : {} };
|
|
640
|
+
});
|
|
641
|
+
const initiated = await this.createMediaUploads({ body: { profileId, platform, files: declaration } }, options);
|
|
642
|
+
const uploadIds = await putDirectUploads(this.transport, initiated.data.uploads, files.map(({ file }) => file), options);
|
|
643
|
+
uploadIds.forEach((uploadId, index) => {
|
|
644
|
+
files[index].reference.upload_id = uploadId;
|
|
645
|
+
});
|
|
646
|
+
return stagedBody;
|
|
647
|
+
}
|
|
648
|
+
async createPost(args, options = {}) {
|
|
649
|
+
const body = await this.stageBody(args.body, options);
|
|
650
|
+
return this.transport.request({ operation: operations.createPost, body, signal: options.signal, timeoutMs: options.timeoutMs });
|
|
651
|
+
}
|
|
652
|
+
async uploadYouTubeVideo(args, options = {}) {
|
|
653
|
+
const body = await this.stageBody({ ...args.body, platform: "youtube" }, options);
|
|
654
|
+
return this.transport.request({ operation: operations.uploadYouTubeVideo, body, signal: options.signal, timeoutMs: options.timeoutMs });
|
|
655
|
+
}
|
|
656
|
+
deleteXPost(args, options = {}) {
|
|
657
|
+
return this.transport.request({ operation: operations.deleteXPost, path: args.path, query: args.query, signal: options.signal, timeoutMs: options.timeoutMs });
|
|
658
|
+
}
|
|
659
|
+
deleteBlueskyPost(args, options = {}) {
|
|
660
|
+
return this.transport.request({ operation: operations.deleteBlueskyPost, path: args.path, query: args.query, signal: options.signal, timeoutMs: options.timeoutMs });
|
|
661
|
+
}
|
|
662
|
+
getInstagramPostStatus(args, options = {}) {
|
|
663
|
+
return this.transport.request({ operation: operations.getInstagramPostStatus, query: args.query, signal: options.signal, timeoutMs: options.timeoutMs });
|
|
664
|
+
}
|
|
665
|
+
getFacebookPostStatus(args, options = {}) {
|
|
666
|
+
return this.transport.request({ operation: operations.getFacebookPostStatus, query: args.query, signal: options.signal, timeoutMs: options.timeoutMs });
|
|
667
|
+
}
|
|
668
|
+
getTikTokPostStatus(args, options = {}) {
|
|
669
|
+
return this.transport.request({ operation: operations.getTikTokPostStatus, query: args.query, signal: options.signal, timeoutMs: options.timeoutMs });
|
|
670
|
+
}
|
|
671
|
+
getTikTokCreatorInfo(args, options = {}) {
|
|
672
|
+
return this.transport.request({ operation: operations.getTikTokCreatorInfo, query: args.query, signal: options.signal, timeoutMs: options.timeoutMs });
|
|
673
|
+
}
|
|
674
|
+
getYouTubeVideoStatus(args, options = {}) {
|
|
675
|
+
return this.transport.request({ operation: operations.getYouTubeVideoStatus, query: args.query, signal: options.signal, timeoutMs: options.timeoutMs });
|
|
676
|
+
}
|
|
677
|
+
};
|
|
678
|
+
|
|
679
|
+
// src/resources/comments.ts
|
|
680
|
+
var CommentsResource = class {
|
|
681
|
+
constructor(transport) {
|
|
682
|
+
this.transport = transport;
|
|
683
|
+
}
|
|
684
|
+
listComments(args, options = {}) {
|
|
685
|
+
return this.transport.request({ operation: operations.listComments, query: args.query, signal: options.signal, timeoutMs: options.timeoutMs });
|
|
686
|
+
}
|
|
687
|
+
createComment(args, options = {}) {
|
|
688
|
+
return this.transport.request({ operation: operations.createComment, body: args.body, signal: options.signal, timeoutMs: options.timeoutMs });
|
|
689
|
+
}
|
|
690
|
+
updateComment(args, options = {}) {
|
|
691
|
+
return this.transport.request({ operation: operations.updateComment, path: args.path, body: args.body, signal: options.signal, timeoutMs: options.timeoutMs });
|
|
692
|
+
}
|
|
693
|
+
deleteComment(args, options = {}) {
|
|
694
|
+
return this.transport.request({ operation: operations.deleteComment, path: args.path, query: args.query, signal: options.signal, timeoutMs: options.timeoutMs });
|
|
695
|
+
}
|
|
696
|
+
};
|
|
697
|
+
|
|
698
|
+
// src/resources/messages.ts
|
|
699
|
+
var MessagesResource = class {
|
|
700
|
+
constructor(transport) {
|
|
701
|
+
this.transport = transport;
|
|
702
|
+
}
|
|
703
|
+
listMessages(args = {}, options = {}) {
|
|
704
|
+
return this.transport.request({ operation: operations.listMessages, query: args.query, signal: options.signal, timeoutMs: options.timeoutMs });
|
|
705
|
+
}
|
|
706
|
+
sendMessage(args, options = {}) {
|
|
707
|
+
return this.transport.request({ operation: operations.sendMessage, body: args.body, signal: options.signal, timeoutMs: options.timeoutMs });
|
|
708
|
+
}
|
|
709
|
+
sendInstagramMessage(args, options = {}) {
|
|
710
|
+
return this.transport.request({ operation: operations.sendInstagramMessage, body: args.body, signal: options.signal, timeoutMs: options.timeoutMs });
|
|
711
|
+
}
|
|
712
|
+
};
|
|
713
|
+
|
|
714
|
+
// src/resources/analytics.ts
|
|
715
|
+
var AnalyticsResource = class {
|
|
716
|
+
constructor(transport) {
|
|
717
|
+
this.transport = transport;
|
|
718
|
+
}
|
|
719
|
+
getInstagramAccountInsights(args, options = {}) {
|
|
720
|
+
return this.transport.request({ operation: operations.getInstagramAccountInsights, query: args.query, signal: options.signal, timeoutMs: options.timeoutMs });
|
|
721
|
+
}
|
|
722
|
+
getFacebookPageMetrics(args, options = {}) {
|
|
723
|
+
return this.transport.request({ operation: operations.getFacebookPageMetrics, query: args.query, signal: options.signal, timeoutMs: options.timeoutMs });
|
|
724
|
+
}
|
|
725
|
+
getTikTokAccountAnalytics(args, options = {}) {
|
|
726
|
+
return this.transport.request({ operation: operations.getTikTokAccountAnalytics, query: args.query, signal: options.signal, timeoutMs: options.timeoutMs });
|
|
727
|
+
}
|
|
728
|
+
getTikTokAccountInsights(args, options = {}) {
|
|
729
|
+
return this.transport.request({ operation: operations.getTikTokAccountInsights, query: args.query, signal: options.signal, timeoutMs: options.timeoutMs });
|
|
730
|
+
}
|
|
731
|
+
getTikTokVideoInsights(args, options = {}) {
|
|
732
|
+
return this.transport.request({ operation: operations.getTikTokVideoInsights, query: args.query, signal: options.signal, timeoutMs: options.timeoutMs });
|
|
733
|
+
}
|
|
734
|
+
getYouTubeChannelInsights(args, options = {}) {
|
|
735
|
+
return this.transport.request({ operation: operations.getYouTubeChannelInsights, query: args.query, signal: options.signal, timeoutMs: options.timeoutMs });
|
|
736
|
+
}
|
|
737
|
+
getYouTubeVideoInsights(args, options = {}) {
|
|
738
|
+
return this.transport.request({ operation: operations.getYouTubeVideoInsights, query: args.query, signal: options.signal, timeoutMs: options.timeoutMs });
|
|
739
|
+
}
|
|
740
|
+
};
|
|
741
|
+
|
|
742
|
+
// src/resources/ads.ts
|
|
743
|
+
function requiredIdempotency(options) {
|
|
744
|
+
const key = options?.idempotencyKey;
|
|
745
|
+
if (typeof key !== "string" || key.trim() === "" || /[\u0000-\u001f\u007f\r\n]/.test(key)) throw new TypeError("idempotencyKey must be a nonblank valid HTTP header value");
|
|
746
|
+
return key;
|
|
747
|
+
}
|
|
748
|
+
var AdsResource = class {
|
|
749
|
+
constructor(transport) {
|
|
750
|
+
this.transport = transport;
|
|
751
|
+
}
|
|
752
|
+
listAdBusinesses(args = {}, options = {}) {
|
|
753
|
+
return this.transport.request({ operation: operations.listAdBusinesses, query: args.query, signal: options.signal, timeoutMs: options.timeoutMs });
|
|
754
|
+
}
|
|
755
|
+
listAdAccounts(args = {}, options = {}) {
|
|
756
|
+
return this.transport.request({ operation: operations.listAdAccounts, query: args.query, signal: options.signal, timeoutMs: options.timeoutMs });
|
|
757
|
+
}
|
|
758
|
+
createAdAccount(args, options) {
|
|
759
|
+
const idempotencyKey = requiredIdempotency(options);
|
|
760
|
+
return this.transport.request({ operation: operations.createAdAccount, query: args.query, body: args.body, idempotencyKey, signal: options?.signal, timeoutMs: options?.timeoutMs });
|
|
761
|
+
}
|
|
762
|
+
getAdAccount(args, options = {}) {
|
|
763
|
+
return this.transport.request({ operation: operations.getAdAccount, path: args.path, query: args.query, signal: options.signal, timeoutMs: options.timeoutMs });
|
|
764
|
+
}
|
|
765
|
+
updateAdAccount(args, options = {}) {
|
|
766
|
+
return this.transport.request({ operation: operations.updateAdAccount, path: args.path, query: args.query, body: args.body, signal: options.signal, timeoutMs: options.timeoutMs });
|
|
767
|
+
}
|
|
768
|
+
getAdTree(args, options = {}) {
|
|
769
|
+
return this.transport.request({ operation: operations.getAdTree, query: args.query, signal: options.signal, timeoutMs: options.timeoutMs });
|
|
770
|
+
}
|
|
771
|
+
getAdInsights(args, options = {}) {
|
|
772
|
+
return this.transport.request({ operation: operations.getAdInsights, query: args.query, signal: options.signal, timeoutMs: options.timeoutMs });
|
|
773
|
+
}
|
|
774
|
+
listAdLeads(args = {}, options = {}) {
|
|
775
|
+
return this.transport.request({ operation: operations.listAdLeads, query: args.query, signal: options.signal, timeoutMs: options.timeoutMs });
|
|
776
|
+
}
|
|
777
|
+
createCampaign(args, options) {
|
|
778
|
+
const idempotencyKey = requiredIdempotency(options);
|
|
779
|
+
return this.transport.request({ operation: operations.createCampaign, query: args.query, body: args.body, idempotencyKey, signal: options?.signal, timeoutMs: options?.timeoutMs });
|
|
780
|
+
}
|
|
781
|
+
deleteCampaign(args, options = {}) {
|
|
782
|
+
return this.transport.request({ operation: operations.deleteCampaign, path: args.path, query: args.query, signal: options.signal, timeoutMs: options.timeoutMs });
|
|
783
|
+
}
|
|
784
|
+
setAdStatus(args, options = {}) {
|
|
785
|
+
return this.transport.request({ operation: operations.setAdStatus, query: args.query, body: args.body, signal: options.signal, timeoutMs: options.timeoutMs });
|
|
786
|
+
}
|
|
787
|
+
updateAdGroup(args, options = {}) {
|
|
788
|
+
return this.transport.request({ operation: operations.updateAdGroup, path: args.path, query: args.query, body: args.body, signal: options.signal, timeoutMs: options.timeoutMs });
|
|
789
|
+
}
|
|
790
|
+
listAdTargeting(args, options = {}) {
|
|
791
|
+
return this.transport.request({ operation: operations.listAdTargeting, query: args.query, signal: options.signal, timeoutMs: options.timeoutMs });
|
|
792
|
+
}
|
|
793
|
+
listAdIdentities(args, options = {}) {
|
|
794
|
+
return this.transport.request({ operation: operations.listAdIdentities, query: args.query, signal: options.signal, timeoutMs: options.timeoutMs });
|
|
795
|
+
}
|
|
796
|
+
createAdIdentity(args, options = {}) {
|
|
797
|
+
return this.transport.request({ operation: operations.createAdIdentity, query: args.query, body: args.body, signal: options.signal, timeoutMs: options.timeoutMs });
|
|
798
|
+
}
|
|
799
|
+
};
|
|
800
|
+
|
|
801
|
+
// src/resources/usage.ts
|
|
802
|
+
var UsageResource = class {
|
|
803
|
+
constructor(transport) {
|
|
804
|
+
this.transport = transport;
|
|
805
|
+
}
|
|
806
|
+
getXUsage(_args = {}, options = {}) {
|
|
807
|
+
return this.transport.request({ operation: operations.getXUsage, signal: options.signal, timeoutMs: options.timeoutMs });
|
|
808
|
+
}
|
|
809
|
+
};
|
|
810
|
+
|
|
811
|
+
// src/resources/webhooks.ts
|
|
812
|
+
var WebhooksResource = class {
|
|
813
|
+
constructor(transport) {
|
|
814
|
+
this.transport = transport;
|
|
815
|
+
}
|
|
816
|
+
listWebhooks(args, options = {}) {
|
|
817
|
+
return this.transport.request({ operation: operations.listWebhooks, query: args.query, signal: options.signal, timeoutMs: options.timeoutMs });
|
|
818
|
+
}
|
|
819
|
+
createWebhook(args, options = {}) {
|
|
820
|
+
return this.transport.request({ operation: operations.createWebhook, body: args.body, signal: options.signal, timeoutMs: options.timeoutMs });
|
|
821
|
+
}
|
|
822
|
+
deleteWebhook(args, options = {}) {
|
|
823
|
+
return this.transport.request({ operation: operations.deleteWebhook, path: args.path, signal: options.signal, timeoutMs: options.timeoutMs });
|
|
824
|
+
}
|
|
825
|
+
};
|
|
826
|
+
|
|
827
|
+
// src/client.ts
|
|
828
|
+
var Adeli = class {
|
|
829
|
+
profiles;
|
|
830
|
+
accounts;
|
|
831
|
+
posts;
|
|
832
|
+
comments;
|
|
833
|
+
messages;
|
|
834
|
+
analytics;
|
|
835
|
+
ads;
|
|
836
|
+
usage;
|
|
837
|
+
webhooks;
|
|
838
|
+
transport;
|
|
839
|
+
constructor(options = {}) {
|
|
840
|
+
this.transport = new Transport(resolveConfig(options));
|
|
841
|
+
this.profiles = new ProfilesResource(this.transport);
|
|
842
|
+
this.accounts = new AccountsResource(this.transport);
|
|
843
|
+
this.posts = new PostsResource(this.transport);
|
|
844
|
+
this.comments = new CommentsResource(this.transport);
|
|
845
|
+
this.messages = new MessagesResource(this.transport);
|
|
846
|
+
this.analytics = new AnalyticsResource(this.transport);
|
|
847
|
+
this.ads = new AdsResource(this.transport);
|
|
848
|
+
this.usage = new UsageResource(this.transport);
|
|
849
|
+
this.webhooks = new WebhooksResource(this.transport);
|
|
850
|
+
}
|
|
851
|
+
/** Do not serialize client internals or its API key. */
|
|
852
|
+
toJSON() {
|
|
853
|
+
return {};
|
|
854
|
+
}
|
|
855
|
+
getMe(args = {}, options = {}) {
|
|
856
|
+
return this.transport.request({ operation: operations.getMe, query: args.query, signal: options.signal, timeoutMs: options.timeoutMs });
|
|
857
|
+
}
|
|
858
|
+
};
|
|
859
|
+
|
|
860
|
+
exports.Adeli = Adeli;
|
|
861
|
+
exports.AdeliApiError = AdeliApiError;
|
|
862
|
+
exports.AdeliError = AdeliError;
|
|
863
|
+
exports.AuthenticationError = AuthenticationError;
|
|
864
|
+
exports.CancellationError = CancellationError;
|
|
865
|
+
exports.ConfigurationError = ConfigurationError;
|
|
866
|
+
exports.MalformedResponseError = MalformedResponseError;
|
|
867
|
+
exports.NetworkError = NetworkError;
|
|
868
|
+
exports.PermissionRequiredError = PermissionRequiredError;
|
|
869
|
+
exports.RateLimitError = RateLimitError;
|
|
870
|
+
exports.RedirectError = RedirectError;
|
|
871
|
+
exports.TimeoutError = TimeoutError;
|
|
872
|
+
exports.ValidationError = ValidationError;
|
|
873
|
+
exports.blobFromPath = blobFromPath;
|
|
874
|
+
exports.fileFromPath = fileFromPath;
|
|
875
|
+
exports.isAdeliApiError = isAdeliApiError;
|
|
876
|
+
exports.isPermissionRequiredDetails = isPermissionRequiredDetails;
|
|
877
|
+
//# sourceMappingURL=index.cjs.map
|
|
878
|
+
//# sourceMappingURL=index.cjs.map
|