@zernio/node 0.1.58

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/src/client.ts ADDED
@@ -0,0 +1,674 @@
1
+ import {
2
+ client,
3
+ addWhatsAppBroadcastRecipients,
4
+ bookmarkPost,
5
+ bulkDeleteWhatsAppContacts,
6
+ bulkUpdateWhatsAppContacts,
7
+ bulkUploadPosts,
8
+ cancelWhatsAppBroadcastSchedule,
9
+ checkInstagramHashtags,
10
+ completeTelegramConnect,
11
+ connectBlueskyCredentials,
12
+ connectWhatsAppCredentials,
13
+ createAccountGroup,
14
+ createApiKey,
15
+ createGoogleBusinessMedia,
16
+ createGoogleBusinessPlaceAction,
17
+ createInviteToken,
18
+ createPost,
19
+ createProfile,
20
+ createQueueSlot,
21
+ createWebhookSettings,
22
+ createWhatsAppBroadcast,
23
+ createWhatsAppContact,
24
+ createWhatsAppTemplate,
25
+ deleteAccount,
26
+ deleteAccountGroup,
27
+ deleteApiKey,
28
+ deleteGoogleBusinessMedia,
29
+ deleteGoogleBusinessPlaceAction,
30
+ deleteInboxComment,
31
+ deleteInboxReviewReply,
32
+ deleteInstagramIceBreakers,
33
+ deleteMessengerMenu,
34
+ deletePost,
35
+ deleteProfile,
36
+ deleteQueueSlot,
37
+ deleteTelegramCommands,
38
+ deleteWebhookSettings,
39
+ deleteWhatsAppBroadcast,
40
+ deleteWhatsAppContact,
41
+ deleteWhatsAppGroup,
42
+ deleteWhatsAppTemplate,
43
+ downloadBlueskyMedia,
44
+ downloadFacebookVideo,
45
+ downloadInstagramMedia,
46
+ downloadLinkedInVideo,
47
+ downloadTikTokVideo,
48
+ downloadTwitterMedia,
49
+ downloadYouTubeVideo,
50
+ editInboxMessage,
51
+ followUser,
52
+ getAccountHealth,
53
+ getAllAccountsHealth,
54
+ getAnalytics,
55
+ getBestTimeToPost,
56
+ getConnectUrl,
57
+ getContentDecay,
58
+ getDailyMetrics,
59
+ getFacebookPages,
60
+ getFollowerStats,
61
+ getGmbLocations,
62
+ getGoogleBusinessAttributes,
63
+ getGoogleBusinessFoodMenus,
64
+ getGoogleBusinessLocationDetails,
65
+ getGoogleBusinessReviews,
66
+ getInboxConversation,
67
+ getInboxConversationMessages,
68
+ getInboxPostComments,
69
+ getInstagramIceBreakers,
70
+ getLinkedInAggregateAnalytics,
71
+ getLinkedInMentions,
72
+ getLinkedInOrganizations,
73
+ getLinkedInPostAnalytics,
74
+ getLinkedInPostReactions,
75
+ getMediaPresignedUrl,
76
+ getMessengerMenu,
77
+ getNextQueueSlot,
78
+ getPendingOAuthData,
79
+ getPinterestBoards,
80
+ getPost,
81
+ getPostLogs,
82
+ getPostTimeline,
83
+ getPostingFrequency,
84
+ getProfile,
85
+ getRedditFeed,
86
+ getRedditFlairs,
87
+ getRedditSubreddits,
88
+ getTelegramCommands,
89
+ getTelegramConnectStatus,
90
+ getUsageStats,
91
+ getUser,
92
+ getWebhookLogs,
93
+ getWebhookSettings,
94
+ getWhatsAppBroadcast,
95
+ getWhatsAppBroadcastRecipients,
96
+ getWhatsAppBroadcasts,
97
+ getWhatsAppBusinessProfile,
98
+ getWhatsAppContact,
99
+ getWhatsAppContacts,
100
+ getWhatsAppDisplayName,
101
+ getWhatsAppGroups,
102
+ getWhatsAppPhoneNumber,
103
+ getWhatsAppPhoneNumbers,
104
+ getWhatsAppTemplate,
105
+ getWhatsAppTemplates,
106
+ getYouTubeDailyViews,
107
+ getYouTubeTranscript,
108
+ handleOAuthCallback,
109
+ hideInboxComment,
110
+ importWhatsAppContacts,
111
+ initiateTelegramConnect,
112
+ likeInboxComment,
113
+ listAccountGroups,
114
+ listAccounts,
115
+ listApiKeys,
116
+ listConnectionLogs,
117
+ listFacebookPages,
118
+ listGoogleBusinessLocations,
119
+ listGoogleBusinessMedia,
120
+ listGoogleBusinessPlaceActions,
121
+ listInboxComments,
122
+ listInboxConversations,
123
+ listInboxReviews,
124
+ listLinkedInOrganizations,
125
+ listPinterestBoardsForSelection,
126
+ listPosts,
127
+ listPostsLogs,
128
+ listProfiles,
129
+ listQueueSlots,
130
+ listSnapchatProfiles,
131
+ listUsers,
132
+ previewQueue,
133
+ purchaseWhatsAppPhoneNumber,
134
+ releaseWhatsAppPhoneNumber,
135
+ removeBookmark,
136
+ removeWhatsAppBroadcastRecipients,
137
+ renameWhatsAppGroup,
138
+ replyToInboxPost,
139
+ replyToInboxReview,
140
+ retryPost,
141
+ retweetPost,
142
+ scheduleWhatsAppBroadcast,
143
+ searchReddit,
144
+ selectFacebookPage,
145
+ selectGoogleBusinessLocation,
146
+ selectLinkedInOrganization,
147
+ selectPinterestBoard,
148
+ selectSnapchatProfile,
149
+ sendInboxMessage,
150
+ sendPrivateReplyToComment,
151
+ sendWhatsAppBroadcast,
152
+ sendWhatsAppBulk,
153
+ setInstagramIceBreakers,
154
+ setMessengerMenu,
155
+ setTelegramCommands,
156
+ testWebhook,
157
+ undoRetweet,
158
+ unfollowUser,
159
+ unhideInboxComment,
160
+ unlikeInboxComment,
161
+ unpublishPost,
162
+ updateAccount,
163
+ updateAccountGroup,
164
+ updateFacebookPage,
165
+ updateGmbLocation,
166
+ updateGoogleBusinessAttributes,
167
+ updateGoogleBusinessFoodMenus,
168
+ updateGoogleBusinessLocationDetails,
169
+ updateInboxConversation,
170
+ updateLinkedInOrganization,
171
+ updatePinterestBoards,
172
+ updatePost,
173
+ updateProfile,
174
+ updateQueueSlot,
175
+ updateRedditSubreddits,
176
+ updateWebhookSettings,
177
+ updateWhatsAppBusinessProfile,
178
+ updateWhatsAppContact,
179
+ updateWhatsAppDisplayName,
180
+ updateWhatsAppTemplate,
181
+ uploadWhatsAppProfilePhoto,
182
+ validateMedia,
183
+ validatePost,
184
+ validatePostLength,
185
+ validateSubreddit,
186
+ } from './generated/sdk.gen';
187
+
188
+ import { LateApiError, parseApiError } from './errors';
189
+ export interface ClientOptions {
190
+ /**
191
+ * API key for authentication. Defaults to process.env['LATE_API_KEY'].
192
+ */
193
+ apiKey?: string | undefined;
194
+
195
+ /**
196
+ * Override the default base URL for the API.
197
+ * @default "https://getlate.dev/api"
198
+ */
199
+ baseURL?: string | null | undefined;
200
+
201
+ /**
202
+ * The maximum amount of time (in milliseconds) that the client should wait for a response.
203
+ * @default 60000
204
+ */
205
+ timeout?: number;
206
+
207
+ /**
208
+ * Default headers to include with every request.
209
+ */
210
+ defaultHeaders?: Record<string, string>;
211
+ }
212
+ /**
213
+ * API Client for the Late API.
214
+ *
215
+ * @example
216
+ * ```typescript
217
+ * import Late from '@getlatedev/node';
218
+ *
219
+ * const late = new Late({
220
+ * apiKey: process.env['LATE_API_KEY'], // This is the default and can be omitted
221
+ * });
222
+ *
223
+ * async function main() {
224
+ * const post = await late.posts.create({
225
+ * body: {
226
+ * content: 'Hello from the Late SDK!',
227
+ * platforms: [{ platform: 'twitter', accountId: 'acc_123' }],
228
+ * publishNow: true,
229
+ * },
230
+ * });
231
+ * console.log(post.data);
232
+ * }
233
+ *
234
+ * main();
235
+ * ```
236
+ */
237
+ export class Late {
238
+ private _options: ClientOptions;
239
+
240
+ /**
241
+ * API key used for authentication.
242
+ */
243
+ apiKey: string;
244
+
245
+ /**
246
+ * Base URL for API requests.
247
+ */
248
+ baseURL: string;
249
+
250
+ /**
251
+ * Tools API - Media download and utilities
252
+ */
253
+ tools = {
254
+ downloadYouTubeVideo: downloadYouTubeVideo,
255
+ getYouTubeTranscript: getYouTubeTranscript,
256
+ downloadInstagramMedia: downloadInstagramMedia,
257
+ checkInstagramHashtags: checkInstagramHashtags,
258
+ downloadTikTokVideo: downloadTikTokVideo,
259
+ downloadTwitterMedia: downloadTwitterMedia,
260
+ downloadFacebookVideo: downloadFacebookVideo,
261
+ downloadLinkedInVideo: downloadLinkedInVideo,
262
+ downloadBlueskyMedia: downloadBlueskyMedia,
263
+ };
264
+
265
+ /**
266
+ * validate API
267
+ */
268
+ validate = {
269
+ validatePostLength: validatePostLength,
270
+ validatePost: validatePost,
271
+ validateMedia: validateMedia,
272
+ validateSubreddit: validateSubreddit,
273
+ };
274
+
275
+ /**
276
+ * Analytics API - Get performance metrics
277
+ */
278
+ analytics = {
279
+ getAnalytics: getAnalytics,
280
+ getYouTubeDailyViews: getYouTubeDailyViews,
281
+ getDailyMetrics: getDailyMetrics,
282
+ getBestTimeToPost: getBestTimeToPost,
283
+ getContentDecay: getContentDecay,
284
+ getPostingFrequency: getPostingFrequency,
285
+ getPostTimeline: getPostTimeline,
286
+ getLinkedInAggregateAnalytics: getLinkedInAggregateAnalytics,
287
+ getLinkedInPostAnalytics: getLinkedInPostAnalytics,
288
+ getLinkedInPostReactions: getLinkedInPostReactions,
289
+ };
290
+
291
+ /**
292
+ * Account Groups API - Organize accounts into groups
293
+ */
294
+ accountGroups = {
295
+ listAccountGroups: listAccountGroups,
296
+ createAccountGroup: createAccountGroup,
297
+ updateAccountGroup: updateAccountGroup,
298
+ deleteAccountGroup: deleteAccountGroup,
299
+ };
300
+
301
+ /**
302
+ * Media API - Upload and manage media files
303
+ */
304
+ media = {
305
+ getMediaPresignedUrl: getMediaPresignedUrl,
306
+ };
307
+
308
+ /**
309
+ * Reddit API - Search and feed
310
+ */
311
+ reddit = {
312
+ searchReddit: searchReddit,
313
+ getRedditFeed: getRedditFeed,
314
+ };
315
+
316
+ /**
317
+ * Usage API - Get usage statistics
318
+ */
319
+ usage = {
320
+ getUsageStats: getUsageStats,
321
+ };
322
+
323
+ /**
324
+ * Posts API - Create, schedule, and manage social media posts
325
+ */
326
+ posts = {
327
+ listPosts: listPosts,
328
+ createPost: createPost,
329
+ getPost: getPost,
330
+ updatePost: updatePost,
331
+ deletePost: deletePost,
332
+ bulkUploadPosts: bulkUploadPosts,
333
+ retryPost: retryPost,
334
+ unpublishPost: unpublishPost,
335
+ };
336
+
337
+ /**
338
+ * Users API - User management
339
+ */
340
+ users = {
341
+ listUsers: listUsers,
342
+ getUser: getUser,
343
+ };
344
+
345
+ /**
346
+ * Profiles API - Manage workspace profiles
347
+ */
348
+ profiles = {
349
+ listProfiles: listProfiles,
350
+ createProfile: createProfile,
351
+ getProfile: getProfile,
352
+ updateProfile: updateProfile,
353
+ deleteProfile: deleteProfile,
354
+ };
355
+
356
+ /**
357
+ * Accounts API - Manage connected social media accounts
358
+ */
359
+ accounts = {
360
+ listAccounts: listAccounts,
361
+ getFollowerStats: getFollowerStats,
362
+ updateAccount: updateAccount,
363
+ deleteAccount: deleteAccount,
364
+ getAllAccountsHealth: getAllAccountsHealth,
365
+ getAccountHealth: getAccountHealth,
366
+ getGoogleBusinessReviews: getGoogleBusinessReviews,
367
+ getLinkedInMentions: getLinkedInMentions,
368
+ };
369
+
370
+ /**
371
+ * API Keys API - Manage API keys
372
+ */
373
+ apiKeys = {
374
+ listApiKeys: listApiKeys,
375
+ createApiKey: createApiKey,
376
+ deleteApiKey: deleteApiKey,
377
+ };
378
+
379
+ /**
380
+ * Invites API - Team invitations
381
+ */
382
+ invites = {
383
+ createInviteToken: createInviteToken,
384
+ };
385
+
386
+ /**
387
+ * Connect API - OAuth connection flows
388
+ */
389
+ connect = {
390
+ getConnectUrl: getConnectUrl,
391
+ handleOAuthCallback: handleOAuthCallback,
392
+ getPendingOAuthData: getPendingOAuthData,
393
+ connectWhatsAppCredentials: connectWhatsAppCredentials,
394
+ getFacebookPages: getFacebookPages,
395
+ updateFacebookPage: updateFacebookPage,
396
+ getLinkedInOrganizations: getLinkedInOrganizations,
397
+ updateLinkedInOrganization: updateLinkedInOrganization,
398
+ getPinterestBoards: getPinterestBoards,
399
+ updatePinterestBoards: updatePinterestBoards,
400
+ getGmbLocations: getGmbLocations,
401
+ updateGmbLocation: updateGmbLocation,
402
+ getRedditSubreddits: getRedditSubreddits,
403
+ updateRedditSubreddits: updateRedditSubreddits,
404
+ getRedditFlairs: getRedditFlairs,
405
+ facebook: {
406
+ listFacebookPages: listFacebookPages,
407
+ selectFacebookPage: selectFacebookPage,
408
+ },
409
+ googleBusiness: {
410
+ listGoogleBusinessLocations: listGoogleBusinessLocations,
411
+ selectGoogleBusinessLocation: selectGoogleBusinessLocation,
412
+ },
413
+ linkedin: {
414
+ listLinkedInOrganizations: listLinkedInOrganizations,
415
+ selectLinkedInOrganization: selectLinkedInOrganization,
416
+ },
417
+ pinterest: {
418
+ listPinterestBoardsForSelection: listPinterestBoardsForSelection,
419
+ selectPinterestBoard: selectPinterestBoard,
420
+ },
421
+ snapchat: {
422
+ listSnapchatProfiles: listSnapchatProfiles,
423
+ selectSnapchatProfile: selectSnapchatProfile,
424
+ },
425
+ bluesky: {
426
+ connectBlueskyCredentials: connectBlueskyCredentials,
427
+ },
428
+ telegram: {
429
+ getTelegramConnectStatus: getTelegramConnectStatus,
430
+ initiateTelegramConnect: initiateTelegramConnect,
431
+ completeTelegramConnect: completeTelegramConnect,
432
+ },
433
+ };
434
+
435
+ /**
436
+ * gmbfoodmenus API
437
+ */
438
+ gmbfoodmenus = {
439
+ getGoogleBusinessFoodMenus: getGoogleBusinessFoodMenus,
440
+ updateGoogleBusinessFoodMenus: updateGoogleBusinessFoodMenus,
441
+ };
442
+
443
+ /**
444
+ * gmblocationdetails API
445
+ */
446
+ gmblocationdetails = {
447
+ getGoogleBusinessLocationDetails: getGoogleBusinessLocationDetails,
448
+ updateGoogleBusinessLocationDetails: updateGoogleBusinessLocationDetails,
449
+ };
450
+
451
+ /**
452
+ * gmbmedia API
453
+ */
454
+ gmbmedia = {
455
+ listGoogleBusinessMedia: listGoogleBusinessMedia,
456
+ createGoogleBusinessMedia: createGoogleBusinessMedia,
457
+ deleteGoogleBusinessMedia: deleteGoogleBusinessMedia,
458
+ };
459
+
460
+ /**
461
+ * gmbattributes API
462
+ */
463
+ gmbattributes = {
464
+ getGoogleBusinessAttributes: getGoogleBusinessAttributes,
465
+ updateGoogleBusinessAttributes: updateGoogleBusinessAttributes,
466
+ };
467
+
468
+ /**
469
+ * gmbplaceactions API
470
+ */
471
+ gmbplaceactions = {
472
+ listGoogleBusinessPlaceActions: listGoogleBusinessPlaceActions,
473
+ createGoogleBusinessPlaceAction: createGoogleBusinessPlaceAction,
474
+ deleteGoogleBusinessPlaceAction: deleteGoogleBusinessPlaceAction,
475
+ };
476
+
477
+ /**
478
+ * Queue API - Manage posting queue
479
+ */
480
+ queue = {
481
+ listQueueSlots: listQueueSlots,
482
+ createQueueSlot: createQueueSlot,
483
+ updateQueueSlot: updateQueueSlot,
484
+ deleteQueueSlot: deleteQueueSlot,
485
+ previewQueue: previewQueue,
486
+ getNextQueueSlot: getNextQueueSlot,
487
+ };
488
+
489
+ /**
490
+ * Webhooks API - Configure event webhooks
491
+ */
492
+ webhooks = {
493
+ getWebhookSettings: getWebhookSettings,
494
+ createWebhookSettings: createWebhookSettings,
495
+ updateWebhookSettings: updateWebhookSettings,
496
+ deleteWebhookSettings: deleteWebhookSettings,
497
+ testWebhook: testWebhook,
498
+ getWebhookLogs: getWebhookLogs,
499
+ };
500
+
501
+ /**
502
+ * Logs API - Publishing logs
503
+ */
504
+ logs = {
505
+ listPostsLogs: listPostsLogs,
506
+ listConnectionLogs: listConnectionLogs,
507
+ getPostLogs: getPostLogs,
508
+ };
509
+
510
+ /**
511
+ * messages API
512
+ */
513
+ messages = {
514
+ listInboxConversations: listInboxConversations,
515
+ getInboxConversation: getInboxConversation,
516
+ updateInboxConversation: updateInboxConversation,
517
+ getInboxConversationMessages: getInboxConversationMessages,
518
+ sendInboxMessage: sendInboxMessage,
519
+ editInboxMessage: editInboxMessage,
520
+ };
521
+
522
+ /**
523
+ * accountsettings API
524
+ */
525
+ accountsettings = {
526
+ getMessengerMenu: getMessengerMenu,
527
+ setMessengerMenu: setMessengerMenu,
528
+ deleteMessengerMenu: deleteMessengerMenu,
529
+ getInstagramIceBreakers: getInstagramIceBreakers,
530
+ setInstagramIceBreakers: setInstagramIceBreakers,
531
+ deleteInstagramIceBreakers: deleteInstagramIceBreakers,
532
+ getTelegramCommands: getTelegramCommands,
533
+ setTelegramCommands: setTelegramCommands,
534
+ deleteTelegramCommands: deleteTelegramCommands,
535
+ };
536
+
537
+ /**
538
+ * comments API
539
+ */
540
+ comments = {
541
+ listInboxComments: listInboxComments,
542
+ getInboxPostComments: getInboxPostComments,
543
+ replyToInboxPost: replyToInboxPost,
544
+ deleteInboxComment: deleteInboxComment,
545
+ hideInboxComment: hideInboxComment,
546
+ unhideInboxComment: unhideInboxComment,
547
+ likeInboxComment: likeInboxComment,
548
+ unlikeInboxComment: unlikeInboxComment,
549
+ sendPrivateReplyToComment: sendPrivateReplyToComment,
550
+ };
551
+
552
+ /**
553
+ * twitterengagement API
554
+ */
555
+ twitterengagement = {
556
+ retweetPost: retweetPost,
557
+ undoRetweet: undoRetweet,
558
+ bookmarkPost: bookmarkPost,
559
+ removeBookmark: removeBookmark,
560
+ followUser: followUser,
561
+ unfollowUser: unfollowUser,
562
+ };
563
+
564
+ /**
565
+ * reviews API
566
+ */
567
+ reviews = {
568
+ listInboxReviews: listInboxReviews,
569
+ replyToInboxReview: replyToInboxReview,
570
+ deleteInboxReviewReply: deleteInboxReviewReply,
571
+ };
572
+
573
+ /**
574
+ * whatsapp API
575
+ */
576
+ whatsapp = {
577
+ sendWhatsAppBulk: sendWhatsAppBulk,
578
+ getWhatsAppContacts: getWhatsAppContacts,
579
+ createWhatsAppContact: createWhatsAppContact,
580
+ getWhatsAppContact: getWhatsAppContact,
581
+ updateWhatsAppContact: updateWhatsAppContact,
582
+ deleteWhatsAppContact: deleteWhatsAppContact,
583
+ importWhatsAppContacts: importWhatsAppContacts,
584
+ bulkUpdateWhatsAppContacts: bulkUpdateWhatsAppContacts,
585
+ bulkDeleteWhatsAppContacts: bulkDeleteWhatsAppContacts,
586
+ getWhatsAppGroups: getWhatsAppGroups,
587
+ renameWhatsAppGroup: renameWhatsAppGroup,
588
+ deleteWhatsAppGroup: deleteWhatsAppGroup,
589
+ getWhatsAppTemplates: getWhatsAppTemplates,
590
+ createWhatsAppTemplate: createWhatsAppTemplate,
591
+ getWhatsAppTemplate: getWhatsAppTemplate,
592
+ updateWhatsAppTemplate: updateWhatsAppTemplate,
593
+ deleteWhatsAppTemplate: deleteWhatsAppTemplate,
594
+ getWhatsAppBroadcasts: getWhatsAppBroadcasts,
595
+ createWhatsAppBroadcast: createWhatsAppBroadcast,
596
+ getWhatsAppBroadcast: getWhatsAppBroadcast,
597
+ deleteWhatsAppBroadcast: deleteWhatsAppBroadcast,
598
+ sendWhatsAppBroadcast: sendWhatsAppBroadcast,
599
+ scheduleWhatsAppBroadcast: scheduleWhatsAppBroadcast,
600
+ cancelWhatsAppBroadcastSchedule: cancelWhatsAppBroadcastSchedule,
601
+ getWhatsAppBroadcastRecipients: getWhatsAppBroadcastRecipients,
602
+ addWhatsAppBroadcastRecipients: addWhatsAppBroadcastRecipients,
603
+ removeWhatsAppBroadcastRecipients: removeWhatsAppBroadcastRecipients,
604
+ getWhatsAppBusinessProfile: getWhatsAppBusinessProfile,
605
+ updateWhatsAppBusinessProfile: updateWhatsAppBusinessProfile,
606
+ uploadWhatsAppProfilePhoto: uploadWhatsAppProfilePhoto,
607
+ getWhatsAppDisplayName: getWhatsAppDisplayName,
608
+ updateWhatsAppDisplayName: updateWhatsAppDisplayName,
609
+ };
610
+
611
+ /**
612
+ * whatsappphonenumbers API
613
+ */
614
+ whatsappphonenumbers = {
615
+ getWhatsAppPhoneNumbers: getWhatsAppPhoneNumbers,
616
+ purchaseWhatsAppPhoneNumber: purchaseWhatsAppPhoneNumber,
617
+ getWhatsAppPhoneNumber: getWhatsAppPhoneNumber,
618
+ releaseWhatsAppPhoneNumber: releaseWhatsAppPhoneNumber,
619
+ };
620
+
621
+ /**
622
+ * Create a new Late API client.
623
+ *
624
+ * @param options - Configuration options for the client
625
+ */
626
+ constructor(options: ClientOptions = {}) {
627
+ const apiKey = options.apiKey ?? process.env['LATE_API_KEY'];
628
+
629
+ if (!apiKey) {
630
+ throw new LateApiError(
631
+ "The LATE_API_KEY environment variable is missing or empty; either provide it, or instantiate the Late client with an apiKey option, like new Late({ apiKey: 'sk_...' }).",
632
+ 401,
633
+ 'missing_api_key'
634
+ );
635
+ }
636
+
637
+ this.apiKey = apiKey;
638
+ this.baseURL = options.baseURL ?? 'https://getlate.dev/api';
639
+ this._options = options;
640
+
641
+ // Configure the generated client
642
+ client.setConfig({
643
+ baseUrl: this.baseURL,
644
+ });
645
+
646
+ // Add auth interceptor
647
+ client.interceptors.request.use((request) => {
648
+ request.headers.set('Authorization', `Bearer ${this.apiKey}`);
649
+ if (options.defaultHeaders) {
650
+ for (const [key, value] of Object.entries(options.defaultHeaders)) {
651
+ request.headers.set(key, value);
652
+ }
653
+ }
654
+ return request;
655
+ });
656
+
657
+ // Add error handling interceptor
658
+ client.interceptors.response.use(async (response) => {
659
+ if (!response.ok) {
660
+ let body: Record<string, unknown> | undefined;
661
+ try {
662
+ body = (await response.clone().json()) as Record<string, unknown>;
663
+ } catch {
664
+ // Ignore JSON parse errors
665
+ }
666
+ throw parseApiError(response, body);
667
+ }
668
+ return response;
669
+ });
670
+ }
671
+ }
672
+
673
+ // Default export for convenient usage
674
+ export default Late;