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