@coloop-ai/openai-ads-sdk 0.1.0

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 ADDED
@@ -0,0 +1,996 @@
1
+ import { $ as listBusinessAgentsMethod, A as deleteLeadSyncSubscriptionMethod, At as updateBusinessAgentMethod, B as getCampaignInsightsMethod, C as createCustomAudienceMethod, Ct as removeCustomAudienceMembersMethod, D as createProductFeedMethod, Dt as updateAdAccountSpendLimitWindowMethod, E as createPartnerDataUploadMethod, Et as updateAdAccountNegativeKeywordsMethod, F as getAdGroupMethod, Ft as createClient, G as getLeadFormMethod, H as getCustomAudienceMethod, I as getAdInsightsMethod, J as getProductFeedSftpAccessMethod, K as getLeadSyncSubscriptionMethod, L as getAdMethod, M as getAdAccountMethod, Mt as updateLeadFormMethod, N as getAdAccountSpendLimitWindowsMethod, Nt as uploadBlobMethod, O as createTestLeadSubmissionMethod, Ot as updateAdGroupMethod, P as getAdGroupInsightsMethod, Pt as uploadImageMethod, Q as listBusinessAgentToolsMethod, R as getAdsOAuthMeMethod, Rt as formDataBodySerializer, S as createConversionSourceMethod, St as queryProductFeedProductsMethod, T as createLeadSyncSubscriptionMethod, Tt as updateAdAccountMethod, U as getCustomAudienceOperationMethod, V as getCampaignMethod, W as getGeoLookupMethod, X as listAdGroupsMethod, Y as listAdAccountsMethod, Z as listAdsMethod, _ as createApiKeyMethod, _t as postProductFeedSftpAccessMethod, a as addCustomAudienceMembersMethod, at as listLeadFormsMethod, b as createConversionApiKeyMethod, bt as publishBusinessAgentMethod, c as archiveCampaignMethod, ct as listProductFeedsMethod, d as archiveProductFeedMethod, dt as pauseAdAccountMethod, et as listCampaignsMethod, f as createAdAccountCreationSessionMethod, ft as pauseAdGroupMethod, g as createAdPreviewMethod, gt as postProductFeedSftpAccessActivateMethod, h as createAdMethod, ht as postConversionInsightsMethod, i as activateCampaignMethod, it as listCustomAudiencesMethod, j as getAdAccountInsightsMethod, jt as updateCampaignMethod, k as deleteAdAccountSpendLimitWindowMethod, kt as updateAdMethod, l as archiveCustomAudienceMethod, lt as mergeCustomAudiencesMethod, m as createAdGroupMethod, mt as pauseCampaignMethod, n as activateAdGroupMethod, nt as listConversionEventsMethod, o as archiveAdGroupMethod, ot as listLeadSyncSubscriptionsMethod, p as createAdAccountSpendLimitWindowMethod, pt as pauseAdMethod, q as getPartnerDataUploadMethod, r as activateAdMethod, rt as listConversionSourcesMethod, s as archiveAdMethod, st as listProductFeedUploadsMethod, t as activateAdAccountMethod, tt as listConversionEventSettingsMethod, u as archiveLeadFormMethod, ut as patchProductFeedProductsMethod, v as createBusinessAgentMethod, vt as postProductFeedSftpAccessPauseMethod, w as createLeadFormMethod, wt as replaceCustomAudienceMembersMethod, x as createConversionEventSettingMethod, xt as publishLeadFormMethod, y as createCampaignMethod, yt as previewBusinessAgentMethod, z as getBusinessAgentMethod } from "./sdk.gen-BZw2JSrr.mjs";
2
+ //#region src/errors.ts
3
+ var OpenAIAdsApiError = class extends Error {
4
+ code;
5
+ param;
6
+ payload;
7
+ request;
8
+ response;
9
+ status;
10
+ statusText;
11
+ type;
12
+ constructor(options) {
13
+ super(options.message);
14
+ this.name = "OpenAIAdsApiError";
15
+ this.code = options.code;
16
+ this.param = options.param;
17
+ this.payload = options.payload;
18
+ this.request = options.request;
19
+ this.response = options.response;
20
+ this.status = options.status;
21
+ this.statusText = options.statusText;
22
+ this.type = options.type;
23
+ }
24
+ };
25
+ var OpenAIAdsTimeoutError = class extends Error {
26
+ request;
27
+ timeoutMs;
28
+ constructor(timeoutMs, request) {
29
+ super(`OpenAI Ads API request timed out after ${String(timeoutMs)} ms`);
30
+ this.name = "OpenAIAdsTimeoutError";
31
+ this.request = request;
32
+ this.timeoutMs = timeoutMs;
33
+ }
34
+ };
35
+ var OpenAIAdsConfigurationError = class extends Error {
36
+ constructor(message) {
37
+ super(message);
38
+ this.name = "OpenAIAdsConfigurationError";
39
+ }
40
+ };
41
+ //#endregion
42
+ //#region src/rest-operations.ts
43
+ const REST_OPERATIONS = {
44
+ "campaigns.list": rest("ListCampaignsMethod", "GET", "/campaigns"),
45
+ "campaigns.create": rest("CreateCampaignMethod", "POST", "/campaigns", { idempotency: "optional" }),
46
+ "campaigns.get": rest("GetCampaignMethod", "GET", "/campaigns/{campaign_id}"),
47
+ "campaigns.update": rest("UpdateCampaignMethod", "POST", "/campaigns/{campaign_id}"),
48
+ "campaigns.activate": rest("ActivateCampaignMethod", "POST", "/campaigns/{campaign_id}/activate"),
49
+ "campaigns.pause": rest("PauseCampaignMethod", "POST", "/campaigns/{campaign_id}/pause"),
50
+ "campaigns.archive": rest("ArchiveCampaignMethod", "POST", "/campaigns/{campaign_id}/archive"),
51
+ "customAudiences.list": rest("ListCustomAudiencesMethod", "GET", "/custom_audiences"),
52
+ "customAudiences.create": rest("CreateCustomAudienceMethod", "POST", "/custom_audiences"),
53
+ "customAudiences.get": rest("GetCustomAudienceMethod", "GET", "/custom_audiences/{custom_audience_id}"),
54
+ "customAudiences.archive": rest("ArchiveCustomAudienceMethod", "POST", "/custom_audiences/{custom_audience_id}/archive"),
55
+ "customAudiences.addMembers": rest("AddCustomAudienceMembersMethod", "POST", "/custom_audiences/{custom_audience_id}/add", { idempotency: "required" }),
56
+ "customAudiences.removeMembers": rest("RemoveCustomAudienceMembersMethod", "POST", "/custom_audiences/{custom_audience_id}/remove", { idempotency: "required" }),
57
+ "customAudiences.replaceMembers": rest("ReplaceCustomAudienceMembersMethod", "POST", "/custom_audiences/{custom_audience_id}/replace", { idempotency: "required" }),
58
+ "customAudiences.merge": rest("MergeCustomAudiencesMethod", "POST", "/custom_audiences/merge", { idempotency: "required" }),
59
+ "customAudiences.operations.get": rest("GetCustomAudienceOperationMethod", "GET", "/custom_audiences/{custom_audience_id}/operations/{operation_id}"),
60
+ "businessAgentTools.list": rest("ListBusinessAgentToolsMethod", "GET", "/business_agent_tools", {
61
+ accountHeader: false,
62
+ auth: "apiKey"
63
+ }),
64
+ "businessAgents.list": rest("ListBusinessAgentsMethod", "GET", "/business_agents"),
65
+ "businessAgents.create": rest("CreateBusinessAgentMethod", "POST", "/business_agents"),
66
+ "leadForms.list": rest("ListLeadFormsMethod", "GET", "/lead_forms"),
67
+ "leadForms.create": rest("CreateLeadFormMethod", "POST", "/lead_forms"),
68
+ "leadForms.get": rest("GetLeadFormMethod", "GET", "/lead_forms/{lead_form_id}"),
69
+ "leadForms.update": rest("UpdateLeadFormMethod", "POST", "/lead_forms/{lead_form_id}"),
70
+ "leadForms.publish": rest("PublishLeadFormMethod", "POST", "/lead_forms/{lead_form_id}/publish"),
71
+ "leadForms.archive": rest("ArchiveLeadFormMethod", "POST", "/lead_forms/{lead_form_id}/archive"),
72
+ "leadForms.testSubmissions.create": rest("CreateTestLeadSubmissionMethod", "POST", "/lead_forms/{lead_form_id}/test_submissions", { idempotency: "required" }),
73
+ "businessAgents.get": rest("GetBusinessAgentMethod", "GET", "/business_agents/{business_agent_id}"),
74
+ "businessAgents.update": rest("UpdateBusinessAgentMethod", "POST", "/business_agents/{business_agent_id}"),
75
+ "businessAgents.preview": rest("PreviewBusinessAgentMethod", "POST", "/business_agents/{business_agent_id}/preview"),
76
+ "businessAgents.publish": rest("PublishBusinessAgentMethod", "POST", "/business_agents/{business_agent_id}/publish"),
77
+ "apiKeys.create": rest("CreateApiKeyMethod", "POST", "/api_keys", {
78
+ accountHeader: false,
79
+ auth: "apiKey"
80
+ }),
81
+ "adAccount.updateBrand": rest("UpdateAdAccountMethod", "POST", "/ad_account/brand"),
82
+ "adAccount.updateNegativeKeywords": rest("UpdateAdAccountNegativeKeywordsMethod", "POST", "/ad_account/negative_keywords"),
83
+ "adAccount.activate": rest("ActivateAdAccountMethod", "POST", "/ad_account/activate"),
84
+ "adAccount.pause": rest("PauseAdAccountMethod", "POST", "/ad_account/pause"),
85
+ "adAccounts.list": rest("ListAdAccountsMethod", "GET", "/ad_accounts", { accountHeader: false }),
86
+ "adAccountCreationSessions.create": rest("CreateAdAccountCreationSessionMethod", "POST", "/ad_account_creation_sessions", {
87
+ accountHeader: false,
88
+ auth: "accessToken",
89
+ idempotency: "required"
90
+ }),
91
+ "oauth.getMe": rest("GetAdsOAuthMeMethod", "GET", "/me", {
92
+ accountHeader: false,
93
+ auth: "accessToken"
94
+ }),
95
+ "adAccount.get": rest("GetAdAccountMethod", "GET", "/ad_account"),
96
+ "adAccount.spendLimitWindows.list": rest("GetAdAccountSpendLimitWindowsMethod", "GET", "/ad_account/spend_limit_windows"),
97
+ "adAccount.spendLimitWindows.create": rest("CreateAdAccountSpendLimitWindowMethod", "POST", "/ad_account/spend_limit_windows"),
98
+ "adAccount.spendLimitWindows.update": rest("UpdateAdAccountSpendLimitWindowMethod", "POST", "/ad_account/spend_limit_windows/{window_id}"),
99
+ "adAccount.spendLimitWindows.delete": rest("DeleteAdAccountSpendLimitWindowMethod", "POST", "/ad_account/spend_limit_windows/{window_id}/delete"),
100
+ "insights.adAccount": rest("GetAdAccountInsightsMethod", "GET", "/ad_account/insights"),
101
+ "insights.campaign": rest("GetCampaignInsightsMethod", "GET", "/campaigns/{campaign_id}/insights"),
102
+ "insights.adGroup": rest("GetAdGroupInsightsMethod", "GET", "/ad_groups/{ad_group_id}/insights"),
103
+ "insights.ad": rest("GetAdInsightsMethod", "GET", "/ads/{ad_id}/insights"),
104
+ "geo.search": rest("GetGeoLookupMethod", "GET", "/geo_lookup/search"),
105
+ "leadSync.subscriptions.create": rest("CreateLeadSyncSubscriptionMethod", "POST", "/lead_sync_subscriptions", { idempotency: "required" }),
106
+ "leadSync.subscriptions.list": rest("ListLeadSyncSubscriptionsMethod", "GET", "/lead_sync_subscriptions"),
107
+ "leadSync.subscriptions.get": rest("GetLeadSyncSubscriptionMethod", "GET", "/lead_sync_subscriptions/{subscription_id}"),
108
+ "leadSync.subscriptions.delete": rest("DeleteLeadSyncSubscriptionMethod", "DELETE", "/lead_sync_subscriptions/{subscription_id}"),
109
+ "conversions.apiKeys.create": rest("CreateConversionApiKeyMethod", "POST", "/conversions/api_keys", {
110
+ accountHeader: false,
111
+ auth: "apiKey"
112
+ }),
113
+ "conversions.eventSettings.create": rest("CreateConversionEventSettingMethod", "POST", "/conversions/event_settings"),
114
+ "conversions.eventSettings.list": rest("ListConversionEventSettingsMethod", "GET", "/conversions/event_settings"),
115
+ "conversions.pixels.create": rest("CreateConversionSourceMethod", "POST", "/conversions/pixels"),
116
+ "conversions.pixels.list": rest("ListConversionSourcesMethod", "GET", "/conversions/pixels"),
117
+ "conversions.events.list": rest("ListConversionEventsMethod", "GET", "/conversions/events", {
118
+ accountHeader: false,
119
+ auth: "apiKey"
120
+ }),
121
+ "conversions.insights.query": rest("PostConversionInsightsMethod", "POST", "/conversions/insights"),
122
+ "adGroups.list": rest("ListAdGroupsMethod", "GET", "/ad_groups"),
123
+ "adGroups.create": rest("CreateAdGroupMethod", "POST", "/ad_groups", { idempotency: "optional" }),
124
+ "adGroups.get": rest("GetAdGroupMethod", "GET", "/ad_groups/{ad_group_id}"),
125
+ "adGroups.update": rest("UpdateAdGroupMethod", "POST", "/ad_groups/{ad_group_id}"),
126
+ "adGroups.activate": rest("ActivateAdGroupMethod", "POST", "/ad_groups/{ad_group_id}/activate"),
127
+ "adGroups.pause": rest("PauseAdGroupMethod", "POST", "/ad_groups/{ad_group_id}/pause"),
128
+ "adGroups.archive": rest("ArchiveAdGroupMethod", "POST", "/ad_groups/{ad_group_id}/archive"),
129
+ "ads.list": rest("ListAdsMethod", "GET", "/ads"),
130
+ "ads.create": rest("CreateAdMethod", "POST", "/ads", { idempotency: "optional" }),
131
+ "ads.get": rest("GetAdMethod", "GET", "/ads/{ad_id}"),
132
+ "ads.update": rest("UpdateAdMethod", "POST", "/ads/{ad_id}"),
133
+ "ads.preview": rest("CreateAdPreviewMethod", "POST", "/ads/{ad_id}/preview"),
134
+ "ads.activate": rest("ActivateAdMethod", "POST", "/ads/{ad_id}/activate"),
135
+ "ads.pause": rest("PauseAdMethod", "POST", "/ads/{ad_id}/pause"),
136
+ "ads.archive": rest("ArchiveAdMethod", "POST", "/ads/{ad_id}/archive"),
137
+ "files.uploadBlob": rest("UploadBlobMethod", "POST", "/uploads"),
138
+ "files.uploadImage": rest("UploadImageMethod", "POST", "/upload"),
139
+ "productFeeds.archive": rest("ArchiveProductFeedMethod", "POST", "/feeds/{feed_id}/archive"),
140
+ "productFeeds.create": rest("CreateProductFeedMethod", "POST", "/feeds"),
141
+ "productFeeds.list": rest("ListProductFeedsMethod", "GET", "/feeds"),
142
+ "productFeeds.uploads.list": rest("ListProductFeedUploadsMethod", "GET", "/feeds/uploads"),
143
+ "productFeeds.products.query": rest("QueryProductFeedProductsMethod", "POST", "/feeds/{feed_id}/products/query"),
144
+ "productFeeds.products.patch": rest("PatchProductFeedProductsMethod", "PATCH", "/feeds/{feed_id}/products"),
145
+ "productFeeds.sftpAccess.get": rest("GetProductFeedSftpAccessMethod", "GET", "/feeds/{feed_id}/sftp_access"),
146
+ "productFeeds.sftpAccess.createOrReplace": rest("PostProductFeedSftpAccessMethod", "POST", "/feeds/{feed_id}/sftp_access"),
147
+ "productFeeds.sftpAccess.activate": rest("PostProductFeedSftpAccessActivateMethod", "POST", "/feeds/{feed_id}/sftp_access/activate"),
148
+ "productFeeds.sftpAccess.pause": rest("PostProductFeedSftpAccessPauseMethod", "POST", "/feeds/{feed_id}/sftp_access/pause"),
149
+ "partnerData.uploads.create": rest("CreatePartnerDataUploadMethod", "POST", "/partner_data/uploads", {
150
+ accountHeader: false,
151
+ auth: "apiKey"
152
+ }),
153
+ "partnerData.uploads.get": rest("GetPartnerDataUploadMethod", "GET", "/partner_data/uploads/{upload_id}", {
154
+ accountHeader: false,
155
+ auth: "apiKey"
156
+ })
157
+ };
158
+ function rest(operationId, method, path, overrides = {}) {
159
+ return {
160
+ accountHeader: overrides.accountHeader ?? true,
161
+ auth: overrides.auth ?? "either",
162
+ idempotency: overrides.idempotency ?? "none",
163
+ method,
164
+ operationId,
165
+ path
166
+ };
167
+ }
168
+ //#endregion
169
+ //#region src/openai-ads.ts
170
+ const DEFAULT_BASE_URL = "https://api.ads.openai.com/v1";
171
+ var OpenAIAds = class {
172
+ campaigns = {
173
+ list: (query = {}, options = {}) => this.run(REST_OPERATIONS["campaigns.list"], options, {}, (signal) => listCampaignsMethod({
174
+ client: this.client,
175
+ headers: this.accountHeaders(options),
176
+ query,
177
+ signal,
178
+ throwOnError: true
179
+ }).then(({ data }) => data)),
180
+ create: (body, options = {}) => this.run(REST_OPERATIONS["campaigns.create"], options, {}, (signal) => createCampaignMethod({
181
+ body,
182
+ client: this.client,
183
+ headers: this.optionalIdempotencyHeaders(options),
184
+ signal,
185
+ throwOnError: true
186
+ }).then(({ data }) => data)),
187
+ get: (campaignId, query = {}, options = {}) => this.run(REST_OPERATIONS["campaigns.get"], options, { campaign_id: campaignId }, (signal) => getCampaignMethod({
188
+ client: this.client,
189
+ headers: this.accountHeaders(options),
190
+ path: { campaign_id: campaignId },
191
+ query,
192
+ signal,
193
+ throwOnError: true
194
+ }).then(({ data }) => data)),
195
+ update: (campaignId, body, options = {}) => this.run(REST_OPERATIONS["campaigns.update"], options, { campaign_id: campaignId }, (signal) => updateCampaignMethod({
196
+ body,
197
+ client: this.client,
198
+ headers: this.accountHeaders(options),
199
+ path: { campaign_id: campaignId },
200
+ signal,
201
+ throwOnError: true
202
+ }).then(({ data }) => data)),
203
+ activate: (campaignId, options = {}) => this.run(REST_OPERATIONS["campaigns.activate"], options, { campaign_id: campaignId }, (signal) => activateCampaignMethod({
204
+ client: this.client,
205
+ headers: this.accountHeaders(options),
206
+ path: { campaign_id: campaignId },
207
+ signal,
208
+ throwOnError: true
209
+ }).then(({ data }) => data)),
210
+ pause: (campaignId, options = {}) => this.run(REST_OPERATIONS["campaigns.pause"], options, { campaign_id: campaignId }, (signal) => pauseCampaignMethod({
211
+ client: this.client,
212
+ headers: this.accountHeaders(options),
213
+ path: { campaign_id: campaignId },
214
+ signal,
215
+ throwOnError: true
216
+ }).then(({ data }) => data)),
217
+ archive: (campaignId, options = {}) => this.run(REST_OPERATIONS["campaigns.archive"], options, { campaign_id: campaignId }, (signal) => archiveCampaignMethod({
218
+ client: this.client,
219
+ headers: this.accountHeaders(options),
220
+ path: { campaign_id: campaignId },
221
+ signal,
222
+ throwOnError: true
223
+ }).then(({ data }) => data))
224
+ };
225
+ customAudiences = {
226
+ list: (query = {}, options = {}) => this.run(REST_OPERATIONS["customAudiences.list"], options, {}, (signal) => listCustomAudiencesMethod({
227
+ client: this.client,
228
+ headers: this.accountHeaders(options),
229
+ query,
230
+ signal,
231
+ throwOnError: true
232
+ }).then(({ data }) => data)),
233
+ create: (body, options = {}) => this.run(REST_OPERATIONS["customAudiences.create"], options, {}, (signal) => createCustomAudienceMethod({
234
+ body,
235
+ client: this.client,
236
+ headers: this.accountHeaders(options),
237
+ signal,
238
+ throwOnError: true
239
+ }).then(({ data }) => data)),
240
+ get: (customAudienceId, query = {}, options = {}) => this.run(REST_OPERATIONS["customAudiences.get"], options, { custom_audience_id: customAudienceId }, (signal) => getCustomAudienceMethod({
241
+ client: this.client,
242
+ headers: this.accountHeaders(options),
243
+ path: { custom_audience_id: customAudienceId },
244
+ query,
245
+ signal,
246
+ throwOnError: true
247
+ }).then(({ data }) => data)),
248
+ archive: (customAudienceId, options = {}) => this.run(REST_OPERATIONS["customAudiences.archive"], options, { custom_audience_id: customAudienceId }, (signal) => archiveCustomAudienceMethod({
249
+ client: this.client,
250
+ headers: this.accountHeaders(options),
251
+ path: { custom_audience_id: customAudienceId },
252
+ signal,
253
+ throwOnError: true
254
+ }).then(({ data }) => data)),
255
+ addMembers: (customAudienceId, body, options) => this.run(REST_OPERATIONS["customAudiences.addMembers"], options, { custom_audience_id: customAudienceId }, (signal) => addCustomAudienceMembersMethod({
256
+ body,
257
+ client: this.client,
258
+ headers: this.requiredIdempotencyHeaders(options),
259
+ path: { custom_audience_id: customAudienceId },
260
+ signal,
261
+ throwOnError: true
262
+ }).then(({ data }) => data)),
263
+ removeMembers: (customAudienceId, body, options) => this.run(REST_OPERATIONS["customAudiences.removeMembers"], options, { custom_audience_id: customAudienceId }, (signal) => removeCustomAudienceMembersMethod({
264
+ body,
265
+ client: this.client,
266
+ headers: this.requiredIdempotencyHeaders(options),
267
+ path: { custom_audience_id: customAudienceId },
268
+ signal,
269
+ throwOnError: true
270
+ }).then(({ data }) => data)),
271
+ replaceMembers: (customAudienceId, body, options) => this.run(REST_OPERATIONS["customAudiences.replaceMembers"], options, { custom_audience_id: customAudienceId }, (signal) => replaceCustomAudienceMembersMethod({
272
+ body,
273
+ client: this.client,
274
+ headers: this.requiredIdempotencyHeaders(options),
275
+ path: { custom_audience_id: customAudienceId },
276
+ signal,
277
+ throwOnError: true
278
+ }).then(({ data }) => data)),
279
+ merge: (body, options) => this.run(REST_OPERATIONS["customAudiences.merge"], options, {}, (signal) => mergeCustomAudiencesMethod({
280
+ body,
281
+ client: this.client,
282
+ headers: this.requiredIdempotencyHeaders(options),
283
+ signal,
284
+ throwOnError: true
285
+ }).then(({ data }) => data)),
286
+ operations: { get: (customAudienceId, operationId, options = {}) => this.run(REST_OPERATIONS["customAudiences.operations.get"], options, {
287
+ custom_audience_id: customAudienceId,
288
+ operation_id: operationId
289
+ }, (signal) => getCustomAudienceOperationMethod({
290
+ client: this.client,
291
+ headers: this.accountHeaders(options),
292
+ path: {
293
+ custom_audience_id: customAudienceId,
294
+ operation_id: operationId
295
+ },
296
+ signal,
297
+ throwOnError: true
298
+ }).then(({ data }) => data)) }
299
+ };
300
+ businessAgentTools = { list: (options = {}) => this.run(REST_OPERATIONS["businessAgentTools.list"], options, {}, (signal) => listBusinessAgentToolsMethod({
301
+ client: this.client,
302
+ signal,
303
+ throwOnError: true
304
+ }).then(({ data }) => data)) };
305
+ businessAgents = {
306
+ list: (options = {}) => this.run(REST_OPERATIONS["businessAgents.list"], options, {}, (signal) => listBusinessAgentsMethod({
307
+ client: this.client,
308
+ headers: this.accountHeaders(options),
309
+ signal,
310
+ throwOnError: true
311
+ }).then(({ data }) => data)),
312
+ create: (body, options = {}) => this.run(REST_OPERATIONS["businessAgents.create"], options, {}, (signal) => createBusinessAgentMethod({
313
+ body,
314
+ client: this.client,
315
+ headers: this.accountHeaders(options),
316
+ signal,
317
+ throwOnError: true
318
+ }).then(({ data }) => data)),
319
+ get: (businessAgentId, options = {}) => this.run(REST_OPERATIONS["businessAgents.get"], options, { business_agent_id: businessAgentId }, (signal) => getBusinessAgentMethod({
320
+ client: this.client,
321
+ headers: this.accountHeaders(options),
322
+ path: { business_agent_id: businessAgentId },
323
+ signal,
324
+ throwOnError: true
325
+ }).then(({ data }) => data)),
326
+ update: (businessAgentId, body, options = {}) => this.run(REST_OPERATIONS["businessAgents.update"], options, { business_agent_id: businessAgentId }, (signal) => updateBusinessAgentMethod({
327
+ body,
328
+ client: this.client,
329
+ headers: this.accountHeaders(options),
330
+ path: { business_agent_id: businessAgentId },
331
+ signal,
332
+ throwOnError: true
333
+ }).then(({ data }) => data)),
334
+ preview: (businessAgentId, body, options = {}) => this.run(REST_OPERATIONS["businessAgents.preview"], options, { business_agent_id: businessAgentId }, (signal) => previewBusinessAgentMethod({
335
+ body,
336
+ client: this.client,
337
+ headers: this.accountHeaders(options),
338
+ path: { business_agent_id: businessAgentId },
339
+ signal,
340
+ throwOnError: true
341
+ }).then(({ data }) => data)),
342
+ publish: (businessAgentId, options = {}) => this.run(REST_OPERATIONS["businessAgents.publish"], options, { business_agent_id: businessAgentId }, (signal) => publishBusinessAgentMethod({
343
+ client: this.client,
344
+ headers: this.accountHeaders(options),
345
+ path: { business_agent_id: businessAgentId },
346
+ signal,
347
+ throwOnError: true
348
+ }).then(({ data }) => data))
349
+ };
350
+ leadForms = {
351
+ list: (options = {}) => this.run(REST_OPERATIONS["leadForms.list"], options, {}, (signal) => listLeadFormsMethod({
352
+ client: this.client,
353
+ headers: this.accountHeaders(options),
354
+ signal,
355
+ throwOnError: true
356
+ }).then(({ data }) => data)),
357
+ create: (body, options = {}) => this.run(REST_OPERATIONS["leadForms.create"], options, {}, (signal) => createLeadFormMethod({
358
+ body,
359
+ client: this.client,
360
+ headers: this.accountHeaders(options),
361
+ signal,
362
+ throwOnError: true
363
+ }).then(({ data }) => data)),
364
+ get: (leadFormId, query = {}, options = {}) => this.run(REST_OPERATIONS["leadForms.get"], options, { lead_form_id: leadFormId }, (signal) => getLeadFormMethod({
365
+ client: this.client,
366
+ headers: this.accountHeaders(options),
367
+ path: { lead_form_id: leadFormId },
368
+ query,
369
+ signal,
370
+ throwOnError: true
371
+ }).then(({ data }) => data)),
372
+ update: (leadFormId, body, options = {}) => this.run(REST_OPERATIONS["leadForms.update"], options, { lead_form_id: leadFormId }, (signal) => updateLeadFormMethod({
373
+ body,
374
+ client: this.client,
375
+ headers: this.accountHeaders(options),
376
+ path: { lead_form_id: leadFormId },
377
+ signal,
378
+ throwOnError: true
379
+ }).then(({ data }) => data)),
380
+ publish: (leadFormId, body, options = {}) => this.run(REST_OPERATIONS["leadForms.publish"], options, { lead_form_id: leadFormId }, (signal) => publishLeadFormMethod({
381
+ body,
382
+ client: this.client,
383
+ headers: this.accountHeaders(options),
384
+ path: { lead_form_id: leadFormId },
385
+ signal,
386
+ throwOnError: true
387
+ }).then(({ data }) => data)),
388
+ archive: (leadFormId, options = {}) => this.run(REST_OPERATIONS["leadForms.archive"], options, { lead_form_id: leadFormId }, (signal) => archiveLeadFormMethod({
389
+ client: this.client,
390
+ headers: this.accountHeaders(options),
391
+ path: { lead_form_id: leadFormId },
392
+ signal,
393
+ throwOnError: true
394
+ }).then(({ data }) => data)),
395
+ testSubmissions: { create: (leadFormId, body, options) => this.run(REST_OPERATIONS["leadForms.testSubmissions.create"], options, { lead_form_id: leadFormId }, (signal) => createTestLeadSubmissionMethod({
396
+ body,
397
+ client: this.client,
398
+ headers: this.requiredIdempotencyHeaders(options),
399
+ path: { lead_form_id: leadFormId },
400
+ signal,
401
+ throwOnError: true
402
+ }).then(({ data }) => data)) }
403
+ };
404
+ apiKeys = { create: (body, options = {}) => this.run(REST_OPERATIONS["apiKeys.create"], options, {}, (signal) => createApiKeyMethod({
405
+ body,
406
+ client: this.client,
407
+ signal,
408
+ throwOnError: true
409
+ }).then(({ data }) => data)) };
410
+ adAccount = {
411
+ updateBrand: (body, options = {}) => this.run(REST_OPERATIONS["adAccount.updateBrand"], options, {}, (signal) => updateAdAccountMethod({
412
+ body,
413
+ client: this.client,
414
+ headers: this.accountHeaders(options),
415
+ signal,
416
+ throwOnError: true
417
+ }).then(({ data }) => data)),
418
+ updateNegativeKeywords: (body, options = {}) => this.run(REST_OPERATIONS["adAccount.updateNegativeKeywords"], options, {}, (signal) => updateAdAccountNegativeKeywordsMethod({
419
+ body,
420
+ client: this.client,
421
+ headers: this.accountHeaders(options),
422
+ signal,
423
+ throwOnError: true
424
+ }).then(({ data }) => data)),
425
+ activate: (options = {}) => this.run(REST_OPERATIONS["adAccount.activate"], options, {}, (signal) => activateAdAccountMethod({
426
+ client: this.client,
427
+ headers: this.accountHeaders(options),
428
+ signal,
429
+ throwOnError: true
430
+ }).then(({ data }) => data)),
431
+ pause: (options = {}) => this.run(REST_OPERATIONS["adAccount.pause"], options, {}, (signal) => pauseAdAccountMethod({
432
+ client: this.client,
433
+ headers: this.accountHeaders(options),
434
+ signal,
435
+ throwOnError: true
436
+ }).then(({ data }) => data)),
437
+ get: (options = {}) => this.run(REST_OPERATIONS["adAccount.get"], options, {}, (signal) => getAdAccountMethod({
438
+ client: this.client,
439
+ headers: this.accountHeaders(options),
440
+ signal,
441
+ throwOnError: true
442
+ }).then(({ data }) => data)),
443
+ spendLimitWindows: {
444
+ list: (options = {}) => this.run(REST_OPERATIONS["adAccount.spendLimitWindows.list"], options, {}, (signal) => getAdAccountSpendLimitWindowsMethod({
445
+ client: this.client,
446
+ headers: this.accountHeaders(options),
447
+ signal,
448
+ throwOnError: true
449
+ }).then(({ data }) => data)),
450
+ create: (body, options = {}) => this.run(REST_OPERATIONS["adAccount.spendLimitWindows.create"], options, {}, (signal) => createAdAccountSpendLimitWindowMethod({
451
+ body,
452
+ client: this.client,
453
+ headers: this.accountHeaders(options),
454
+ signal,
455
+ throwOnError: true
456
+ }).then(({ data }) => data)),
457
+ update: (windowId, body, options = {}) => this.run(REST_OPERATIONS["adAccount.spendLimitWindows.update"], options, { window_id: windowId }, (signal) => updateAdAccountSpendLimitWindowMethod({
458
+ body,
459
+ client: this.client,
460
+ headers: this.accountHeaders(options),
461
+ path: { window_id: windowId },
462
+ signal,
463
+ throwOnError: true
464
+ }).then(({ data }) => data)),
465
+ delete: (windowId, options = {}) => this.run(REST_OPERATIONS["adAccount.spendLimitWindows.delete"], options, { window_id: windowId }, (signal) => deleteAdAccountSpendLimitWindowMethod({
466
+ client: this.client,
467
+ headers: this.accountHeaders(options),
468
+ path: { window_id: windowId },
469
+ signal,
470
+ throwOnError: true
471
+ }).then(({ data }) => data))
472
+ }
473
+ };
474
+ adAccounts = { list: (query = {}, options = {}) => this.run(REST_OPERATIONS["adAccounts.list"], options, {}, (signal) => listAdAccountsMethod({
475
+ client: this.client,
476
+ query,
477
+ signal,
478
+ throwOnError: true
479
+ }).then(({ data }) => data)) };
480
+ adAccountCreationSessions = { create: (body, options) => this.run(REST_OPERATIONS["adAccountCreationSessions.create"], options, {}, (signal) => createAdAccountCreationSessionMethod({
481
+ body,
482
+ client: this.client,
483
+ headers: { "Idempotency-Key": options.idempotencyKey },
484
+ signal,
485
+ throwOnError: true
486
+ }).then(({ data }) => data)) };
487
+ oauth = { getMe: (options = {}) => this.run(REST_OPERATIONS["oauth.getMe"], options, {}, (signal) => getAdsOAuthMeMethod({
488
+ client: this.client,
489
+ signal,
490
+ throwOnError: true
491
+ }).then(({ data }) => data)) };
492
+ insights = {
493
+ adAccount: (query = {}, options = {}) => this.run(REST_OPERATIONS["insights.adAccount"], options, {}, (signal) => getAdAccountInsightsMethod({
494
+ client: this.client,
495
+ headers: this.accountHeaders(options),
496
+ query,
497
+ signal,
498
+ throwOnError: true
499
+ }).then(({ data }) => data)),
500
+ campaign: (campaignId, query = {}, options = {}) => this.run(REST_OPERATIONS["insights.campaign"], options, { campaign_id: campaignId }, (signal) => getCampaignInsightsMethod({
501
+ client: this.client,
502
+ headers: this.accountHeaders(options),
503
+ path: { campaign_id: campaignId },
504
+ query,
505
+ signal,
506
+ throwOnError: true
507
+ }).then(({ data }) => data)),
508
+ adGroup: (adGroupId, query = {}, options = {}) => this.run(REST_OPERATIONS["insights.adGroup"], options, { ad_group_id: adGroupId }, (signal) => getAdGroupInsightsMethod({
509
+ client: this.client,
510
+ headers: this.accountHeaders(options),
511
+ path: { ad_group_id: adGroupId },
512
+ query,
513
+ signal,
514
+ throwOnError: true
515
+ }).then(({ data }) => data)),
516
+ ad: (adId, query = {}, options = {}) => this.run(REST_OPERATIONS["insights.ad"], options, { ad_id: adId }, (signal) => getAdInsightsMethod({
517
+ client: this.client,
518
+ headers: this.accountHeaders(options),
519
+ path: { ad_id: adId },
520
+ query,
521
+ signal,
522
+ throwOnError: true
523
+ }).then(({ data }) => data))
524
+ };
525
+ geo = { search: (query, options = {}) => this.run(REST_OPERATIONS["geo.search"], options, {}, (signal) => getGeoLookupMethod({
526
+ client: this.client,
527
+ headers: this.accountHeaders(options),
528
+ query,
529
+ signal,
530
+ throwOnError: true
531
+ }).then(({ data }) => data)) };
532
+ leadSync = { subscriptions: {
533
+ create: (body, options) => this.run(REST_OPERATIONS["leadSync.subscriptions.create"], options, {}, (signal) => createLeadSyncSubscriptionMethod({
534
+ body,
535
+ client: this.client,
536
+ headers: this.requiredIdempotencyHeaders(options),
537
+ signal,
538
+ throwOnError: true
539
+ }).then(({ data }) => data)),
540
+ list: (query, options = {}) => this.run(REST_OPERATIONS["leadSync.subscriptions.list"], options, {}, (signal) => listLeadSyncSubscriptionsMethod({
541
+ client: this.client,
542
+ headers: this.accountHeaders(options),
543
+ query,
544
+ signal,
545
+ throwOnError: true
546
+ }).then(({ data }) => data)),
547
+ get: (subscriptionId, options = {}) => this.run(REST_OPERATIONS["leadSync.subscriptions.get"], options, { subscription_id: subscriptionId }, (signal) => getLeadSyncSubscriptionMethod({
548
+ client: this.client,
549
+ headers: this.accountHeaders(options),
550
+ path: { subscription_id: subscriptionId },
551
+ signal,
552
+ throwOnError: true
553
+ }).then(({ data }) => data)),
554
+ delete: (subscriptionId, options = {}) => this.run(REST_OPERATIONS["leadSync.subscriptions.delete"], options, { subscription_id: subscriptionId }, (signal) => deleteLeadSyncSubscriptionMethod({
555
+ client: this.client,
556
+ headers: this.accountHeaders(options),
557
+ path: { subscription_id: subscriptionId },
558
+ signal,
559
+ throwOnError: true
560
+ }).then(({ data }) => data))
561
+ } };
562
+ conversions = {
563
+ apiKeys: { create: (body, options = {}) => this.run(REST_OPERATIONS["conversions.apiKeys.create"], options, {}, (signal) => createConversionApiKeyMethod({
564
+ body,
565
+ client: this.client,
566
+ signal,
567
+ throwOnError: true
568
+ }).then(({ data }) => data)) },
569
+ eventSettings: {
570
+ create: (body, options = {}) => this.run(REST_OPERATIONS["conversions.eventSettings.create"], options, {}, (signal) => createConversionEventSettingMethod({
571
+ body,
572
+ client: this.client,
573
+ headers: this.accountHeaders(options),
574
+ signal,
575
+ throwOnError: true
576
+ }).then(({ data }) => data)),
577
+ list: (query = {}, options = {}) => this.run(REST_OPERATIONS["conversions.eventSettings.list"], options, {}, (signal) => listConversionEventSettingsMethod({
578
+ client: this.client,
579
+ headers: this.accountHeaders(options),
580
+ query,
581
+ signal,
582
+ throwOnError: true
583
+ }).then(({ data }) => data))
584
+ },
585
+ pixels: {
586
+ create: (body, options = {}) => this.run(REST_OPERATIONS["conversions.pixels.create"], options, {}, (signal) => createConversionSourceMethod({
587
+ body,
588
+ client: this.client,
589
+ headers: this.accountHeaders(options),
590
+ signal,
591
+ throwOnError: true
592
+ }).then(({ data }) => data)),
593
+ list: (query = {}, options = {}) => this.run(REST_OPERATIONS["conversions.pixels.list"], options, {}, (signal) => listConversionSourcesMethod({
594
+ client: this.client,
595
+ headers: this.accountHeaders(options),
596
+ query,
597
+ signal,
598
+ throwOnError: true
599
+ }).then(({ data }) => data))
600
+ },
601
+ events: { list: (query, options = {}) => this.run(REST_OPERATIONS["conversions.events.list"], options, {}, (signal) => listConversionEventsMethod({
602
+ client: this.client,
603
+ query,
604
+ signal,
605
+ throwOnError: true
606
+ }).then(({ data }) => data)) },
607
+ insights: { query: (body, options = {}) => this.run(REST_OPERATIONS["conversions.insights.query"], options, {}, (signal) => postConversionInsightsMethod({
608
+ body,
609
+ client: this.client,
610
+ headers: this.accountHeaders(options),
611
+ signal,
612
+ throwOnError: true
613
+ }).then(({ data }) => data)) }
614
+ };
615
+ adGroups = {
616
+ list: (query = {}, options = {}) => this.run(REST_OPERATIONS["adGroups.list"], options, {}, (signal) => listAdGroupsMethod({
617
+ client: this.client,
618
+ headers: this.accountHeaders(options),
619
+ query,
620
+ signal,
621
+ throwOnError: true
622
+ }).then(({ data }) => data)),
623
+ create: (body, options = {}) => this.run(REST_OPERATIONS["adGroups.create"], options, {}, (signal) => createAdGroupMethod({
624
+ body,
625
+ client: this.client,
626
+ headers: this.optionalIdempotencyHeaders(options),
627
+ signal,
628
+ throwOnError: true
629
+ }).then(({ data }) => data)),
630
+ get: (adGroupId, query = {}, options = {}) => this.run(REST_OPERATIONS["adGroups.get"], options, { ad_group_id: adGroupId }, (signal) => getAdGroupMethod({
631
+ client: this.client,
632
+ headers: this.accountHeaders(options),
633
+ path: { ad_group_id: adGroupId },
634
+ query,
635
+ signal,
636
+ throwOnError: true
637
+ }).then(({ data }) => data)),
638
+ update: (adGroupId, body, options = {}) => this.run(REST_OPERATIONS["adGroups.update"], options, { ad_group_id: adGroupId }, (signal) => updateAdGroupMethod({
639
+ body,
640
+ client: this.client,
641
+ headers: this.accountHeaders(options),
642
+ path: { ad_group_id: adGroupId },
643
+ signal,
644
+ throwOnError: true
645
+ }).then(({ data }) => data)),
646
+ activate: (adGroupId, options = {}) => this.run(REST_OPERATIONS["adGroups.activate"], options, { ad_group_id: adGroupId }, (signal) => activateAdGroupMethod({
647
+ client: this.client,
648
+ headers: this.accountHeaders(options),
649
+ path: { ad_group_id: adGroupId },
650
+ signal,
651
+ throwOnError: true
652
+ }).then(({ data }) => data)),
653
+ pause: (adGroupId, options = {}) => this.run(REST_OPERATIONS["adGroups.pause"], options, { ad_group_id: adGroupId }, (signal) => pauseAdGroupMethod({
654
+ client: this.client,
655
+ headers: this.accountHeaders(options),
656
+ path: { ad_group_id: adGroupId },
657
+ signal,
658
+ throwOnError: true
659
+ }).then(({ data }) => data)),
660
+ archive: (adGroupId, options = {}) => this.run(REST_OPERATIONS["adGroups.archive"], options, { ad_group_id: adGroupId }, (signal) => archiveAdGroupMethod({
661
+ client: this.client,
662
+ headers: this.accountHeaders(options),
663
+ path: { ad_group_id: adGroupId },
664
+ signal,
665
+ throwOnError: true
666
+ }).then(({ data }) => data))
667
+ };
668
+ ads = {
669
+ list: (query = {}, options = {}) => this.run(REST_OPERATIONS["ads.list"], options, {}, (signal) => listAdsMethod({
670
+ client: this.client,
671
+ headers: this.accountHeaders(options),
672
+ query,
673
+ signal,
674
+ throwOnError: true
675
+ }).then(({ data }) => data)),
676
+ create: (body, options = {}) => this.run(REST_OPERATIONS["ads.create"], options, {}, (signal) => createAdMethod({
677
+ body,
678
+ client: this.client,
679
+ headers: this.optionalIdempotencyHeaders(options),
680
+ signal,
681
+ throwOnError: true
682
+ }).then(({ data }) => data)),
683
+ get: (adId, query = {}, options = {}) => this.run(REST_OPERATIONS["ads.get"], options, { ad_id: adId }, (signal) => getAdMethod({
684
+ client: this.client,
685
+ headers: this.accountHeaders(options),
686
+ path: { ad_id: adId },
687
+ query,
688
+ signal,
689
+ throwOnError: true
690
+ }).then(({ data }) => data)),
691
+ update: (adId, body, options = {}) => this.run(REST_OPERATIONS["ads.update"], options, { ad_id: adId }, (signal) => updateAdMethod({
692
+ body,
693
+ client: this.client,
694
+ headers: this.accountHeaders(options),
695
+ path: { ad_id: adId },
696
+ signal,
697
+ throwOnError: true
698
+ }).then(({ data }) => data)),
699
+ preview: (adId, options = {}) => this.run(REST_OPERATIONS["ads.preview"], options, { ad_id: adId }, (signal) => createAdPreviewMethod({
700
+ client: this.client,
701
+ headers: this.accountHeaders(options),
702
+ path: { ad_id: adId },
703
+ signal,
704
+ throwOnError: true
705
+ }).then(({ data }) => data)),
706
+ activate: (adId, options = {}) => this.run(REST_OPERATIONS["ads.activate"], options, { ad_id: adId }, (signal) => activateAdMethod({
707
+ client: this.client,
708
+ headers: this.accountHeaders(options),
709
+ path: { ad_id: adId },
710
+ signal,
711
+ throwOnError: true
712
+ }).then(({ data }) => data)),
713
+ pause: (adId, options = {}) => this.run(REST_OPERATIONS["ads.pause"], options, { ad_id: adId }, (signal) => pauseAdMethod({
714
+ client: this.client,
715
+ headers: this.accountHeaders(options),
716
+ path: { ad_id: adId },
717
+ signal,
718
+ throwOnError: true
719
+ }).then(({ data }) => data)),
720
+ archive: (adId, options = {}) => this.run(REST_OPERATIONS["ads.archive"], options, { ad_id: adId }, (signal) => archiveAdMethod({
721
+ client: this.client,
722
+ headers: this.accountHeaders(options),
723
+ path: { ad_id: adId },
724
+ signal,
725
+ throwOnError: true
726
+ }).then(({ data }) => data))
727
+ };
728
+ files = {
729
+ uploadBlob: (body, options = {}) => this.run(REST_OPERATIONS["files.uploadBlob"], options, {}, (signal) => uploadBlobMethod({
730
+ body,
731
+ client: this.client,
732
+ headers: this.accountHeaders(options),
733
+ signal,
734
+ throwOnError: true
735
+ }).then(({ data }) => data)),
736
+ uploadImage: (body, options = {}) => this.run(REST_OPERATIONS["files.uploadImage"], options, {}, (signal) => {
737
+ const multipart = "file" in body;
738
+ const headers = this.accountHeaders(options);
739
+ if (multipart) headers["Content-Type"] = null;
740
+ return uploadImageMethod({
741
+ ...multipart ? formDataBodySerializer : {},
742
+ body,
743
+ client: this.client,
744
+ headers,
745
+ signal,
746
+ throwOnError: true
747
+ }).then(({ data }) => data);
748
+ })
749
+ };
750
+ productFeeds = {
751
+ archive: (feedId, options = {}) => this.run(REST_OPERATIONS["productFeeds.archive"], options, { feed_id: feedId }, (signal) => archiveProductFeedMethod({
752
+ client: this.client,
753
+ headers: this.accountHeaders(options),
754
+ path: { feed_id: feedId },
755
+ signal,
756
+ throwOnError: true
757
+ }).then(({ data }) => data)),
758
+ create: (body, options = {}) => this.run(REST_OPERATIONS["productFeeds.create"], options, {}, (signal) => createProductFeedMethod({
759
+ body,
760
+ client: this.client,
761
+ headers: this.accountHeaders(options),
762
+ signal,
763
+ throwOnError: true
764
+ }).then(({ data }) => data)),
765
+ list: (query = {}, options = {}) => this.run(REST_OPERATIONS["productFeeds.list"], options, {}, (signal) => listProductFeedsMethod({
766
+ client: this.client,
767
+ headers: this.accountHeaders(options),
768
+ query,
769
+ signal,
770
+ throwOnError: true
771
+ }).then(({ data }) => data)),
772
+ uploads: { list: (query = {}, options = {}) => this.run(REST_OPERATIONS["productFeeds.uploads.list"], options, {}, (signal) => listProductFeedUploadsMethod({
773
+ client: this.client,
774
+ headers: this.accountHeaders(options),
775
+ query,
776
+ signal,
777
+ throwOnError: true
778
+ }).then(({ data }) => data)) },
779
+ products: {
780
+ query: (feedId, body, options = {}) => this.run(REST_OPERATIONS["productFeeds.products.query"], options, { feed_id: feedId }, (signal) => queryProductFeedProductsMethod({
781
+ body,
782
+ client: this.client,
783
+ headers: this.accountHeaders(options),
784
+ path: { feed_id: feedId },
785
+ signal,
786
+ throwOnError: true
787
+ }).then(({ data }) => data)),
788
+ patch: (feedId, body, options = {}) => this.run(REST_OPERATIONS["productFeeds.products.patch"], options, { feed_id: feedId }, (signal) => patchProductFeedProductsMethod({
789
+ body,
790
+ client: this.client,
791
+ headers: this.accountHeaders(options),
792
+ path: { feed_id: feedId },
793
+ signal,
794
+ throwOnError: true
795
+ }).then(({ data }) => data))
796
+ },
797
+ sftpAccess: {
798
+ get: (feedId, options = {}) => this.run(REST_OPERATIONS["productFeeds.sftpAccess.get"], options, { feed_id: feedId }, (signal) => getProductFeedSftpAccessMethod({
799
+ client: this.client,
800
+ headers: this.accountHeaders(options),
801
+ path: { feed_id: feedId },
802
+ signal,
803
+ throwOnError: true
804
+ }).then(({ data }) => data)),
805
+ createOrReplace: (feedId, body, options = {}) => this.run(REST_OPERATIONS["productFeeds.sftpAccess.createOrReplace"], options, { feed_id: feedId }, (signal) => postProductFeedSftpAccessMethod({
806
+ body,
807
+ client: this.client,
808
+ headers: this.accountHeaders(options),
809
+ path: { feed_id: feedId },
810
+ signal,
811
+ throwOnError: true
812
+ }).then(({ data }) => data)),
813
+ activate: (feedId, options = {}) => this.run(REST_OPERATIONS["productFeeds.sftpAccess.activate"], options, { feed_id: feedId }, (signal) => postProductFeedSftpAccessActivateMethod({
814
+ client: this.client,
815
+ headers: this.accountHeaders(options),
816
+ path: { feed_id: feedId },
817
+ signal,
818
+ throwOnError: true
819
+ }).then(({ data }) => data)),
820
+ pause: (feedId, options = {}) => this.run(REST_OPERATIONS["productFeeds.sftpAccess.pause"], options, { feed_id: feedId }, (signal) => postProductFeedSftpAccessPauseMethod({
821
+ client: this.client,
822
+ headers: this.accountHeaders(options),
823
+ path: { feed_id: feedId },
824
+ signal,
825
+ throwOnError: true
826
+ }).then(({ data }) => data))
827
+ }
828
+ };
829
+ partnerData = { uploads: {
830
+ create: (body, options = {}) => this.run(REST_OPERATIONS["partnerData.uploads.create"], options, {}, (signal) => createPartnerDataUploadMethod({
831
+ body,
832
+ client: this.client,
833
+ signal,
834
+ throwOnError: true
835
+ }).then(({ data }) => data)),
836
+ get: (uploadId, options = {}) => this.run(REST_OPERATIONS["partnerData.uploads.get"], options, { upload_id: uploadId }, (signal) => getPartnerDataUploadMethod({
837
+ client: this.client,
838
+ path: { upload_id: uploadId },
839
+ signal,
840
+ throwOnError: true
841
+ }).then(({ data }) => data))
842
+ } };
843
+ baseUrl;
844
+ client;
845
+ credential;
846
+ credentialMode;
847
+ defaultAdAccountId;
848
+ defaultTimeoutMs;
849
+ constructor(options) {
850
+ this.baseUrl = normalizeBaseUrl(options.baseUrl ?? DEFAULT_BASE_URL);
851
+ this.defaultAdAccountId = options.adAccountId;
852
+ this.defaultTimeoutMs = validateTimeout(options.timeoutMs);
853
+ if (options.apiKey === void 0 === (options.accessToken === void 0)) throw new OpenAIAdsConfigurationError("Provide exactly one of apiKey or accessToken");
854
+ if (options.apiKey !== void 0) {
855
+ this.credential = options.apiKey;
856
+ this.credentialMode = "apiKey";
857
+ } else {
858
+ this.credential = options.accessToken;
859
+ this.credentialMode = "accessToken";
860
+ }
861
+ validateStaticCredential(this.credential);
862
+ const baseFetch = options.fetch ?? globalThis.fetch;
863
+ if (typeof baseFetch !== "function") throw new OpenAIAdsConfigurationError("A Fetch API implementation is required");
864
+ this.client = createClient({
865
+ baseUrl: this.baseUrl,
866
+ fetch: this.authenticatedFetch(baseFetch),
867
+ responseStyle: "fields",
868
+ throwOnError: true
869
+ });
870
+ }
871
+ accountHeaders(options) {
872
+ const adAccountId = options.adAccountId ?? this.defaultAdAccountId;
873
+ return adAccountId ? { "OpenAI-Ad-Account": adAccountId } : {};
874
+ }
875
+ optionalIdempotencyHeaders(options) {
876
+ return {
877
+ ...this.accountHeaders(options),
878
+ ...options.idempotencyKey ? { "Idempotency-Key": options.idempotencyKey } : {}
879
+ };
880
+ }
881
+ requiredIdempotencyHeaders(options) {
882
+ return {
883
+ ...this.accountHeaders(options),
884
+ "Idempotency-Key": options.idempotencyKey
885
+ };
886
+ }
887
+ assertAuthentication(requirement) {
888
+ if (requirement !== "either" && requirement !== this.credentialMode) throw new OpenAIAdsConfigurationError(requirement === "apiKey" ? "This operation requires an Ads API key" : "This operation requires an Ads OAuth access token");
889
+ }
890
+ authenticatedFetch(baseFetch) {
891
+ return async (input, init) => {
892
+ const request = new Request(input, init);
893
+ const credential = await resolveCredential(this.credential);
894
+ const headers = new Headers(request.headers);
895
+ headers.set("Authorization", `Bearer ${credential}`);
896
+ const authenticatedRequest = new Request(request, { headers });
897
+ const response = await baseFetch(authenticatedRequest);
898
+ if (!response.ok) throw await createApiError(response, authenticatedRequest);
899
+ return response;
900
+ };
901
+ }
902
+ async run(operation, options, pathValues, request) {
903
+ this.assertAuthentication(operation.auth);
904
+ const timeoutMs = options.timeoutMs === void 0 ? this.defaultTimeoutMs : validateTimeout(options.timeoutMs);
905
+ if (timeoutMs === void 0) return request(options.signal);
906
+ const controller = new AbortController();
907
+ const removeAbortForwarder = forwardAbort(options.signal, controller);
908
+ const timeoutError = new OpenAIAdsTimeoutError(timeoutMs, {
909
+ method: operation.method,
910
+ url: this.operationUrl(operation, pathValues)
911
+ });
912
+ let rejectTimeout;
913
+ const timeout = new Promise((_resolve, reject) => {
914
+ rejectTimeout = reject;
915
+ });
916
+ const timer = setTimeout(() => {
917
+ controller.abort(timeoutError);
918
+ rejectTimeout(timeoutError);
919
+ }, timeoutMs);
920
+ try {
921
+ return await Promise.race([request(controller.signal), timeout]);
922
+ } finally {
923
+ clearTimeout(timer);
924
+ removeAbortForwarder();
925
+ }
926
+ }
927
+ operationUrl(operation, pathValues) {
928
+ const path = operation.path.replaceAll(/\{([^}]+)\}/g, (_match, key) => encodeURIComponent(String(pathValues[key])));
929
+ return `${this.baseUrl}${path}`;
930
+ }
931
+ };
932
+ function normalizeBaseUrl(baseUrl) {
933
+ const normalized = baseUrl.replace(/\/+$/, "");
934
+ if (!normalized) throw new OpenAIAdsConfigurationError("baseUrl must not be empty");
935
+ return normalized;
936
+ }
937
+ function validateStaticCredential(credential) {
938
+ if (typeof credential === "string" && credential.trim().length === 0) throw new OpenAIAdsConfigurationError("The credential must not be empty");
939
+ }
940
+ async function resolveCredential(credential) {
941
+ const value = typeof credential === "function" ? await credential() : credential;
942
+ if (value.trim().length === 0) throw new OpenAIAdsConfigurationError("The credential must not be empty");
943
+ return value;
944
+ }
945
+ function validateTimeout(timeoutMs) {
946
+ if (timeoutMs === void 0) return;
947
+ if (!Number.isFinite(timeoutMs) || !Number.isInteger(timeoutMs) || timeoutMs <= 0) throw new OpenAIAdsConfigurationError("timeoutMs must be a positive finite integer");
948
+ return timeoutMs;
949
+ }
950
+ function forwardAbort(signal, controller) {
951
+ if (signal === void 0) return () => {};
952
+ const abort = () => {
953
+ controller.abort(signal.reason);
954
+ };
955
+ if (signal.aborted) {
956
+ abort();
957
+ return () => {};
958
+ }
959
+ signal.addEventListener("abort", abort, { once: true });
960
+ return () => {
961
+ signal.removeEventListener("abort", abort);
962
+ };
963
+ }
964
+ async function createApiError(response, request) {
965
+ const text = await response.clone().text();
966
+ let payload = text;
967
+ if (text) try {
968
+ payload = JSON.parse(text);
969
+ } catch {
970
+ payload = text;
971
+ }
972
+ const envelope = isRecord(payload) ? payload["error"] : void 0;
973
+ const details = isRecord(envelope) ? envelope : void 0;
974
+ const message = typeof details?.["message"] === "string" ? details["message"] : `OpenAI Ads API request failed with status ${String(response.status)}`;
975
+ return new OpenAIAdsApiError({
976
+ ...typeof details?.["code"] === "string" ? { code: details["code"] } : {},
977
+ message,
978
+ ...details?.["param"] === null || typeof details?.["param"] === "string" ? { param: details["param"] } : {},
979
+ payload,
980
+ request: {
981
+ method: request.method,
982
+ url: request.url
983
+ },
984
+ response,
985
+ status: response.status,
986
+ statusText: response.statusText,
987
+ ...typeof details?.["type"] === "string" ? { type: details["type"] } : {}
988
+ });
989
+ }
990
+ function isRecord(value) {
991
+ return typeof value === "object" && value !== null;
992
+ }
993
+ //#endregion
994
+ export { OpenAIAds, OpenAIAdsApiError, OpenAIAdsConfigurationError, OpenAIAdsTimeoutError };
995
+
996
+ //# sourceMappingURL=index.mjs.map